semiotic 3.13.1 → 3.13.3

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 (276) hide show
  1. package/README.md +48 -48
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/dist/mcp-server.js +4 -4
  4. package/ai/reference.md +23 -12
  5. package/ai/schema.json +258 -96
  6. package/ai/surface-manifest.json +1 -1
  7. package/ai/task-packets/compare-category-totals.json +5 -5
  8. package/ai/task-packets/compare-category-totals.md +2 -2
  9. package/ai/task-packets/correct-published-chart.json +5 -5
  10. package/ai/task-packets/correct-published-chart.md +2 -2
  11. package/ai/task-packets/index.json +6 -6
  12. package/ai/task-packets/update-live-chart.json +5 -5
  13. package/ai/task-packets/update-live-chart.md +2 -2
  14. package/dist/c-2YFVDRU4.min.js +1 -0
  15. package/dist/c-4OVDIXAR.min.js +1 -0
  16. package/dist/c-57IIWW46.min.js +1 -0
  17. package/dist/c-5HTUQRJT.min.js +1 -0
  18. package/dist/c-5NAU4JAY.min.js +1 -0
  19. package/dist/c-62UTMRQE.min.js +1 -0
  20. package/dist/c-6QV6F3U7.min.js +1 -0
  21. package/dist/c-73ORHEHO.min.js +1 -0
  22. package/dist/c-7S46KBYD.min.js +2 -0
  23. package/dist/c-AJSS332Z.min.js +2 -0
  24. package/dist/{c-ZWJDTDEV.min.js → c-AMQAAW7G.min.js} +1 -1
  25. package/dist/c-B3X2IJRQ.min.js +1 -0
  26. package/dist/c-BLLDBVFK.min.js +38 -0
  27. package/dist/c-BQWX6NBX.min.js +1 -0
  28. package/dist/c-C7TT4J7K.min.js +1 -0
  29. package/dist/c-CJ5GA7DM.min.js +1 -0
  30. package/dist/c-D7YDFHLY.min.js +1 -0
  31. package/dist/c-DHNROAXY.min.js +1 -0
  32. package/dist/c-DMDFJQU4.min.js +1 -0
  33. package/dist/{c-RAIBDXDV.min.js → c-FRVHZIGR.min.js} +1 -1
  34. package/dist/{c-I54V24WG.min.js → c-HAZCVHI7.min.js} +1 -1
  35. package/dist/c-HN5U72U7.min.js +1 -0
  36. package/dist/c-JA5F7ITS.min.js +1 -0
  37. package/dist/{c-VZNIIKL6.min.js → c-JDI7HKEM.min.js} +1 -1
  38. package/dist/{c-ISHYKYII.min.js → c-JVZRD4GL.min.js} +1 -1
  39. package/dist/{c-HGWITEJI.min.js → c-KJGJEOSV.min.js} +1 -1
  40. package/dist/c-LDGV6TDQ.min.js +1 -0
  41. package/dist/c-LW3GP7RY.min.js +1 -0
  42. package/dist/c-M2TPZE7P.min.js +1 -0
  43. package/dist/{c-XOGN3524.min.js → c-NBBYSAQY.min.js} +2 -2
  44. package/dist/c-OA6RJZ7S.min.js +1 -0
  45. package/dist/c-OBBSIOYU.min.js +1 -0
  46. package/dist/c-OMTJIC3P.min.js +1 -0
  47. package/dist/{c-SQQZPFVY.min.js → c-QPHM7AWW.min.js} +1 -1
  48. package/dist/{c-XZJWL7UL.min.js → c-QSEAAHEU.min.js} +1 -1
  49. package/dist/c-RQWI623R.min.js +1 -0
  50. package/dist/{c-62JIVHK5.min.js → c-RWFADOKS.min.js} +1 -1
  51. package/dist/c-TFESQSWE.min.js +1 -0
  52. package/dist/{c-SDGGMIYI.min.js → c-TJGC5JEM.min.js} +1 -1
  53. package/dist/{c-4P2EM44G.min.js → c-TOXWQRXS.min.js} +3 -3
  54. package/dist/c-TX53234M.min.js +1 -0
  55. package/dist/c-TZBEQ5UY.min.js +1 -0
  56. package/dist/c-UALVQIIJ.min.js +1 -0
  57. package/dist/c-VBDWHTC7.min.js +1 -0
  58. package/dist/c-VBIPDCE7.min.js +1 -0
  59. package/dist/c-WTNRBWZZ.min.js +51 -0
  60. package/dist/{c-3GIPT46Z.min.js → c-XG4LL2VI.min.js} +1 -1
  61. package/dist/c-XPNBS3W2.min.js +1 -0
  62. package/dist/c-XT3G3YWU.min.js +1 -0
  63. package/dist/c-YCBCZFOC.min.js +1 -0
  64. package/dist/c-ZBSL4Y32.min.js +1 -0
  65. package/dist/c-ZP6O6UHV.min.js +1 -0
  66. package/dist/c-ZVL7ULNH.min.js +1 -0
  67. package/dist/components/ChartErrorBoundary.d.ts +5 -1
  68. package/dist/components/ai/intentWeights.d.ts +22 -0
  69. package/dist/components/ai/streamSchema.d.ts +98 -0
  70. package/dist/components/ai/streamingTypes.d.ts +27 -4
  71. package/dist/components/ai/suggestCharts.d.ts +10 -2
  72. package/dist/components/ai/suggestStreamCharts.d.ts +60 -13
  73. package/dist/components/ai/suggestStreamDashboard.d.ts +9 -1
  74. package/dist/components/charts/network/processSankey/frameMargins.d.ts +1 -1
  75. package/dist/components/charts/network/processSankey/labelPlacement.d.ts +1 -1
  76. package/dist/components/charts/physics/physicsHocUtils.d.ts +1 -1
  77. package/dist/components/charts/realtime/RealtimeAccumulator.d.ts +7 -0
  78. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +9 -2
  79. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +13 -1
  80. package/dist/components/charts/realtime/RealtimeLineChart.types.d.ts +5 -1
  81. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +5 -1
  82. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +7 -1
  83. package/dist/components/charts/realtime/TemporalHistogram.capability.d.ts +5 -3
  84. package/dist/components/charts/realtime/aggregate.d.ts +11 -12
  85. package/dist/components/charts/realtime/defaultRealtimeTooltip.d.ts +9 -0
  86. package/dist/components/charts/realtime/eventTime.d.ts +7 -1
  87. package/dist/components/charts/realtime/useRealtimeLineIngestion.d.ts +13 -0
  88. package/dist/components/charts/shared/ChartError.d.ts +4 -6
  89. package/dist/components/charts/shared/GaugeReadout.d.ts +39 -4
  90. package/dist/components/charts/shared/axisExtent.d.ts +2 -1
  91. package/dist/components/charts/shared/chartMode.d.ts +2 -2
  92. package/dist/components/charts/shared/gaugeLayout.d.ts +69 -0
  93. package/dist/components/charts/shared/types.d.ts +4 -1
  94. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +3 -0
  95. package/dist/components/charts/shared/useStreamStatus.d.ts +2 -2
  96. package/dist/components/charts/shared/withChartErrorBoundary.d.ts +14 -0
  97. package/dist/components/charts/xy/Scatterplot.streamCapability.d.ts +2 -0
  98. package/dist/components/charts/xy/WaterfallChart.d.ts +2 -0
  99. package/dist/components/charts/xy/WaterfallIndex.d.ts +12 -0
  100. package/dist/components/charts/xy/lineGapStrategy.d.ts +15 -3
  101. package/dist/components/legendGeometry.d.ts +148 -0
  102. package/dist/components/legendLayout.d.ts +20 -38
  103. package/dist/components/realtime/ReorderBuffer.d.ts +14 -0
  104. package/dist/components/realtime/SlidingExtent.d.ts +18 -0
  105. package/dist/components/realtime/WindowAccumulator.d.ts +5 -1
  106. package/dist/components/realtime/renderers/types.d.ts +1 -0
  107. package/dist/components/realtime/renderers/waterfallRenderer.d.ts +1 -1
  108. package/dist/components/recipes/atlas/resolution/appearance.d.ts +1 -1
  109. package/dist/components/recipes/atlas/resolution/scene.d.ts +1 -1
  110. package/dist/components/recipes/compositional/edgeRouting.d.ts +9 -0
  111. package/dist/components/recipes/compositional/metrics.d.ts +2 -2
  112. package/dist/components/recipes/compositional/projection.d.ts +3 -1
  113. package/dist/components/recipes/compositional/routing.d.ts +3 -1
  114. package/dist/components/recipes/compositional/testFixtures.d.ts +4 -0
  115. package/dist/components/recipes/compositional/topology.d.ts +2 -0
  116. package/dist/components/recipes/compositional/types.d.ts +10 -1
  117. package/dist/components/recipes/compositional/useCompositionalInterfaces.d.ts +20 -0
  118. package/dist/components/semiotic-ai-core.d.ts +3 -2
  119. package/dist/components/semiotic-ai-stream.d.ts +3 -2
  120. package/dist/components/semiotic-network-zoom.d.ts +1 -1
  121. package/dist/components/semiotic-recipes-react.d.ts +2 -0
  122. package/dist/components/semiotic-utils-core.d.ts +2 -0
  123. package/dist/components/server/serverChartConfigHeatmap.d.ts +13 -0
  124. package/dist/components/server/staticLegend.d.ts +5 -0
  125. package/dist/components/server/staticLegendText.d.ts +13 -0
  126. package/dist/components/server/staticSVGChrome.d.ts +2 -2
  127. package/dist/components/store/ThemeStore.d.ts +4 -1
  128. package/dist/components/store/themeCore.d.ts +2 -0
  129. package/dist/components/stream/DataSourceAdapter.d.ts +15 -62
  130. package/dist/components/stream/FrameRuntime.d.ts +3 -0
  131. package/dist/components/stream/GeoPipelineStore.d.ts +2 -0
  132. package/dist/components/stream/IngestActivity.d.ts +9 -0
  133. package/dist/components/stream/NetworkPipelineStore.d.ts +3 -1
  134. package/dist/components/stream/OrdinalPipelineStore.d.ts +5 -2
  135. package/dist/components/stream/OrdinalSVGOverlay.d.ts +1 -1
  136. package/dist/components/stream/PipelineStore.d.ts +8 -3
  137. package/dist/components/stream/accessibleDataRows.d.ts +1 -0
  138. package/dist/components/stream/axisTickUtils.d.ts +25 -5
  139. package/dist/components/stream/frameDefaultMargins.d.ts +26 -4
  140. package/dist/components/stream/frameKeyboardNavigation.d.ts +8 -1
  141. package/dist/components/stream/geoTypes.d.ts +2 -0
  142. package/dist/components/stream/graphKeyboardNavigation.d.ts +4 -2
  143. package/dist/components/stream/hitTestUtils.d.ts +7 -0
  144. package/dist/components/stream/keyboardNav.d.ts +3 -1
  145. package/dist/components/stream/mediaQuery.d.ts +2 -0
  146. package/dist/components/stream/navigationGraph.d.ts +10 -3
  147. package/dist/components/stream/networkEdgeHitIndex.d.ts +6 -2
  148. package/dist/components/stream/networkFrameKeyboardNavigation.d.ts +2 -0
  149. package/dist/components/stream/networkNavGroups.d.ts +3 -0
  150. package/dist/components/stream/networkPipelineConfig.d.ts +1 -0
  151. package/dist/components/stream/networkSceneTypes.d.ts +10 -0
  152. package/dist/components/stream/networkSpatialNavigation.d.ts +3 -0
  153. package/dist/components/stream/networkTypes.d.ts +2 -0
  154. package/dist/components/stream/networkZoom/ZoomableNetworkCustomChart.d.ts +6 -4
  155. package/dist/components/stream/networkZoom/gestures.d.ts +5 -0
  156. package/dist/components/stream/networkZoom/types.d.ts +10 -0
  157. package/dist/components/stream/ordinalAxisTicks.d.ts +27 -0
  158. package/dist/components/stream/ordinalSceneBuilders/pieScene.d.ts +10 -0
  159. package/dist/components/stream/ordinalSceneBuilders/types.d.ts +2 -0
  160. package/dist/components/stream/ordinalTypes.d.ts +11 -2
  161. package/dist/components/stream/pipelineBufferUtils.d.ts +9 -0
  162. package/dist/components/stream/pipelineConfig.d.ts +7 -0
  163. package/dist/components/stream/pipelineDomainResolution.d.ts +3 -2
  164. package/dist/components/stream/pipelineTransitionTypes.d.ts +3 -5
  165. package/dist/components/stream/pipelineTransitionUtils.d.ts +4 -0
  166. package/dist/components/stream/pipelineTransitions.d.ts +1 -13
  167. package/dist/components/stream/renderers/networkArcRenderer.d.ts +1 -3
  168. package/dist/components/stream/renderers/networkCircleRenderer.d.ts +1 -3
  169. package/dist/components/stream/renderers/networkPrimitiveRenderer.d.ts +5 -0
  170. package/dist/components/stream/renderers/networkRectRenderer.d.ts +1 -3
  171. package/dist/components/stream/renderers/renderPulse.d.ts +8 -14
  172. package/dist/components/stream/roundScaleDomain.d.ts +9 -0
  173. package/dist/components/stream/sceneToSVGShared.d.ts +9 -0
  174. package/dist/components/stream/shallowEqual.d.ts +2 -0
  175. package/dist/components/stream/stalenessBands.d.ts +1 -1
  176. package/dist/components/stream/svgOverlayUtils.d.ts +12 -0
  177. package/dist/components/stream/types.d.ts +10 -2
  178. package/dist/components/stream/useFrame.d.ts +7 -4
  179. package/dist/components/stream/useMediaPreferences.d.ts +1 -4
  180. package/dist/components/stream/useOrdinalFrameHandle.d.ts +4 -14
  181. package/dist/components/stream/useStalenessCheck.d.ts +5 -3
  182. package/dist/components/stream/useStreamingDataHandle.d.ts +24 -0
  183. package/dist/components/stream/useXYFrameHandle.d.ts +4 -14
  184. package/dist/components/stream/xyDateTicks.d.ts +33 -4
  185. package/dist/components/stream/xyFrameAxisTypes.d.ts +2 -0
  186. package/dist/components/stream/xyPlugins/registry.d.ts +7 -0
  187. package/dist/components/stream/xySceneBuilders/heatmapScene.d.ts +11 -2
  188. package/dist/components/stream/xySceneBuilders/types.d.ts +4 -0
  189. package/dist/components/types/legendTypes.d.ts +12 -1
  190. package/dist/geo.min.js +155 -152
  191. package/dist/geo.module.min.js +1 -1
  192. package/dist/network.module.min.js +1 -1
  193. package/dist/ordinal.module.min.js +1 -1
  194. package/dist/physics.module.min.js +1 -1
  195. package/dist/processSankeyLayoutWorker.js +1 -1
  196. package/dist/semiotic-ai-core.d.ts +3 -2
  197. package/dist/semiotic-ai-core.min.js +5 -5
  198. package/dist/semiotic-ai-core.module.min.js +4 -4
  199. package/dist/semiotic-ai.module.min.js +2 -2
  200. package/dist/semiotic-artifact.min.js +6 -6
  201. package/dist/semiotic-artifact.module.min.js +5 -5
  202. package/dist/semiotic-atlas-selection.module.min.js +1 -1
  203. package/dist/semiotic-atlas.module.min.js +1 -1
  204. package/dist/semiotic-client-cjs-shared.min.js +1021 -1024
  205. package/dist/semiotic-client-compositional.module.min.js +1 -1
  206. package/dist/semiotic-client-shared.module.min.js +1 -1
  207. package/dist/semiotic-experimental-auxiliary.module.min.js +2 -2
  208. package/dist/semiotic-experimental-network-resolution-react.module.min.js +1 -1
  209. package/dist/semiotic-experimental-node-auxiliary.module.min.js +3 -3
  210. package/dist/semiotic-line.module.min.js +1 -1
  211. package/dist/semiotic-network-zoom.d.ts +1 -1
  212. package/dist/semiotic-network-zoom.min.js +7 -7
  213. package/dist/semiotic-network-zoom.module.min.js +1 -1
  214. package/dist/semiotic-realtime-core.module.min.js +1 -1
  215. package/dist/semiotic-realtime-react.module.min.js +1 -1
  216. package/dist/semiotic-recipes-core-cjs-base.min.js +101 -101
  217. package/dist/semiotic-recipes-core.module.min.js +1 -1
  218. package/dist/semiotic-recipes-react.d.ts +2 -0
  219. package/dist/semiotic-recipes-react.min.js +8 -8
  220. package/dist/semiotic-server-edge-node.module.min.js +3 -3
  221. package/dist/semiotic-server-edge.min.js +399 -397
  222. package/dist/semiotic-server-edge.module.min.js +3 -3
  223. package/dist/semiotic-server-node.min.js +399 -397
  224. package/dist/semiotic-themes-core.min.js +2 -2
  225. package/dist/semiotic-themes-core.module.min.js +1 -1
  226. package/dist/semiotic-themes.min.js +2 -2
  227. package/dist/semiotic-themes.module.min.js +1 -1
  228. package/dist/semiotic-utils-core.d.ts +2 -0
  229. package/dist/semiotic-utils-core.min.js +11 -11
  230. package/dist/semiotic-utils-core.module.min.js +3 -3
  231. package/dist/semiotic-value.module.min.js +1 -1
  232. package/dist/semiotic.module.min.js +1 -1
  233. package/dist/server.min.js +399 -397
  234. package/dist/server.module.min.js +3 -3
  235. package/dist/xy.module.min.js +1 -1
  236. package/package.json +11 -11
  237. package/dist/c-2M2OPWVA.min.js +0 -37
  238. package/dist/c-2N7IU2NY.min.js +0 -1
  239. package/dist/c-3UXQGCQT.min.js +0 -1
  240. package/dist/c-4RVDKSMQ.min.js +0 -1
  241. package/dist/c-4YPPVFZH.min.js +0 -1
  242. package/dist/c-6WJKNYIG.min.js +0 -1
  243. package/dist/c-7UN2WUMI.min.js +0 -1
  244. package/dist/c-AQUX6L2O.min.js +0 -1
  245. package/dist/c-BR5QDUCR.min.js +0 -1
  246. package/dist/c-C3YQVUB6.min.js +0 -1
  247. package/dist/c-COP4OISO.min.js +0 -1
  248. package/dist/c-ENRZPF5E.min.js +0 -1
  249. package/dist/c-FAOZZE77.min.js +0 -1
  250. package/dist/c-HBLICBM6.min.js +0 -1
  251. package/dist/c-I4BEWAKT.min.js +0 -1
  252. package/dist/c-IDCFMBA4.min.js +0 -2
  253. package/dist/c-KLJDKRD5.min.js +0 -1
  254. package/dist/c-LEICSI5V.min.js +0 -1
  255. package/dist/c-MOK4RWNO.min.js +0 -1
  256. package/dist/c-N2TVSOYL.min.js +0 -2
  257. package/dist/c-NHZ2E3CI.min.js +0 -1
  258. package/dist/c-OIJL2WZH.min.js +0 -1
  259. package/dist/c-OSLNYZ3Q.min.js +0 -51
  260. package/dist/c-OWRVBUSL.min.js +0 -1
  261. package/dist/c-QIVKWHDL.min.js +0 -1
  262. package/dist/c-QUAEYF34.min.js +0 -1
  263. package/dist/c-RDFFLRKC.min.js +0 -1
  264. package/dist/c-RTU5425Z.min.js +0 -1
  265. package/dist/c-SIQVOV6A.min.js +0 -1
  266. package/dist/c-SU6Z75M2.min.js +0 -1
  267. package/dist/c-SWVXFUDL.min.js +0 -1
  268. package/dist/c-TC47SNSI.min.js +0 -1
  269. package/dist/c-VLWWXOM5.min.js +0 -1
  270. package/dist/c-VNFIRKU5.min.js +0 -1
  271. package/dist/c-W5ATXREF.min.js +0 -1
  272. package/dist/c-WFX456JK.min.js +0 -5
  273. package/dist/c-WSWMQDFZ.min.js +0 -1
  274. package/dist/c-XORVM6C5.min.js +0 -1
  275. package/dist/c-YGTMWEEF.min.js +0 -1
  276. package/dist/c-ZDCTFRA6.min.js +0 -1
@@ -1 +1 @@
1
- var s,d,c,u,h,p,M,_e,We,Ge,Ye;import{c as ot}from"./c-BOA4LTOM.min.js";import{a as at,b as lt,c as st,d as dt}from"./c-2CKIGFD2.min.js";import{a as ct,b as ut,c as ht,e as pt,f as ft}from"./c-JL224XKG.min.js";import{interpolateLab as mt}from"d3-interpolate";function gt(e,t,n){return Math.max(t,Math.min(n,e))}function yt(e){return"function"==typeof e?e:t=>t[e]}function xt(e,t,n){let r=e?.data,i=r?r[t]:void 0;if(null!=i)return i;let o=e?.[t];return o??n}function bt(e){if(null==e)return null;let t=e;return t.data??t.datum??e}function wt(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function Mt(e){let t=Object.create(null);return e((e,n)=>{t[e]=n}),t}function vt(e,t){if(!t)return!0;let n=Array.isArray(t)?t:[t],r=e;for(let e of n)if(null!=e.value&&String(r[e.field])!==String(e.value))return!1;return!0}function kt(e,t={}){let n=t.baseOpacity??1;return t.highlight||t.predicate?!vt(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,n+(t.brighten??0)):n}function It(e){return e.join("|")}function $t(e){return mt(e,e)(0)===mt(e,"white")(0)?e:null}function St(e,t=.72){let n=$t(e),r=null===n,i=null===n?null:mt(n,"#ffffff"),o=null===n?null:mt(n,"#000000"),a=null===n?e:i(0),l=gt(t,0,1);return t=>{let n=gt(t,0,1);if(.5===n)return a;let s=2*Math.abs(n-.5)*l;return s?r?`color-mix(in lab, ${e} ${100*(1-s)}%, ${n<.5?"white":"black"})`:n<.5?i(s):o(s):a}}function Nt(e,t,n=.72){return St(e,n)(t)}function At(e){return Mt(t=>{for(let[n,r]of Object.entries(e))t(n,r)})}function Et(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"item"}function Ct(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):0}function Ot(e){if(0===e.length)return 0;let t=0;for(let n of e)t+=n;return t/e.length}function Tt(e,t){let n=Number.isFinite(t)?gt(t,0,1):1,r=$t(e);if(null===r)return 1===n?e:`color-mix(in srgb, ${e} ${100*n}%, transparent)`;let[i,o,a,l=1]=mt(r,r)(0).split(/[(),]/).slice(1,-1).map(Number);return`rgba(${i}, ${o}, ${a}, ${l*n})`}function Rt(e,t){return e<t?-1:e>t?1:0}var e=class{constructor(e=12){this.maxSize=e,this.store=new Map}get(e){return this.store.get(e)}set(e,t){this.store.size>=this.maxSize&&this.store.clear(),this.store.set(e,t)}getOrCompute(e,t){let n=this.store.get(e);if(void 0!==n)return n;let r=t();return this.set(e,r),r}clear(){this.store.clear()}get size(){return this.store.size}};import{createElement as Lt}from"react";function Ft(e,t,n,r,i,{force:o=!1}={}){if(t===n&&!o)return null;let a=`${t} of ${n} ${r} shown`;return Lt("text",{key:"recipe-notice",x:e.x,y:e.y+e.height-4,fontSize:11,fill:"var(--semiotic-text, currentColor)",pointerEvents:"none",role:"img","aria-label":`${a}. ${i}`},Lt("title",null,i),a)}function Pt(e,t,n){return zt(e,t,n)}function zt(e,t,n,r=!1){let i=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,o=e=>Number.isFinite(e)?Math.max(0,e):0,a=e.reduce((e,t)=>e+(o(t.weight)>0?1:0),0),l=Math.max(0,Math.floor(n?.minPerCategory??0)),s=a>0?Math.min(l,Math.floor(i/a)):0,d=e.reduce((e,t)=>e+o(t.weight),0);if(i<=0||d<=0)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));let c=e.map(e=>{let t=o(e.weight),n=t/d*i;return{...e,exact:n,cells:t>0?Math.max(s,Math.floor(n)):0,remainder:n-Math.floor(n)}}),u=c.reduce((e,t)=>e+t.cells,0);for(;u>i;){let e=c.filter(e=>e.cells>s).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,u--}let h=c.filter(e=>o(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||(r?0:o(t.weight)-o(e.weight)||e.key.localeCompare(t.key)));for(let e=0;u<i;e++)h[e%h.length].cells++,u++;return c}function Dt(e,t,n,r){let i=new Set;return e.map((e,o)=>{let a=String(t(e,o)),l=Number(n(e,o));if(!a)throw new Error(`${r} snapshot contains an empty id at index ${o}.`);if(i.has(a))throw new Error(`${r} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(l)||l<0)throw new Error(`${r} snapshot value for "${a}" must be a finite non-negative number.`);return i.add(a),{id:a,value:l}})}function jt(e,t,n){let r=n.afterId??n.beforeId,i=n.afterValue??n.beforeValue,o=null!=n.epsilon&&n.epsilon>=0?n.epsilon:1e-9,a=Dt(e,n.beforeId,n.beforeValue,"Before"),l=Dt(t,r,i,"After"),s=new Map(a.map(e=>[e.id,e.value])),d=new Map(l.map(e=>[e.id,e.value])),c=a.reduce((e,t)=>e+t.value,0),u=l.reduce((e,t)=>e+t.value,0),h=Math.abs(c-u)<=o;if(!h&&!n.allowImbalance)throw new Error(`Snapshot totals must match (before ${c}, after ${u}). Pass allowImbalance to inspect residuals.`);let p=[],f=[...a.map(e=>e.id),...l.map(e=>e.id).filter(e=>!s.has(e))];for(let e of f){let t=Math.min(s.get(e)??0,d.get(e)??0);t>o&&p.push({sourceId:e,targetId:e,value:t,kind:"stay"})}let m=a.map(e=>({id:e.id,value:e.value-(d.get(e.id)??0)})).filter(e=>e.value>o),g=l.map(e=>({id:e.id,value:e.value-(s.get(e.id)??0)})).filter(e=>e.value>o),y=0,x=0;for(;y<m.length&&x<g.length;){let e=m[y],t=g[x],n=Math.min(e.value,t.value);n>o&&p.push({sourceId:e.id,targetId:t.id,value:n,kind:"move"}),e.value-=n,t.value-=n,e.value<=o&&(y+=1),t.value<=o&&(x+=1)}return{flows:p,beforeTotal:c,afterTotal:u,balanced:h,unmatchedBefore:m.slice(y).filter(e=>e.value>o).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:g.slice(x).filter(e=>e.value>o).map(({id:e,value:t})=>({id:e,value:t}))}}function _t(e){return Number.isFinite(e)?Math.max(0,e):0}function Wt(e,t){let n=Number(t.unit),r=_t(e),i=t.maxUnits??1/0,o=t.minFraction??0;if(!(n>0)||!(i>0)||r<=0)return{units:[],unit:n>0?n:0,total:r,shown:0,overflow:r>0&&!(i>0)};let a=r/n,l=Math.ceil(a-1e-6),s=Math.min(i,l),d=l>i,c=[];for(let e=0;e<s;e+=1){let t=e*n,i=Math.min(r,t+n),o=Math.min(1,Math.max(0,(i-t)/n));1-o<1e-6&&(o=1),c.push({index:e,fraction:o,start:t,end:t+o*n,value:o*n})}let u=c[c.length-1];u&&u.fraction<o&&u.fraction<1&&c.pop();let h=c.reduce((e,t)=>e+t.value,0);return{units:c,unit:n,total:r,shown:h,overflow:d}}function Gt(e,t,n){let r=Wt(e,n),i=Math.max(_t(t),r.total);if(i<=r.total)return{...r,rangeUnits:[],rangeTotal:r.total};let o=Wt(i,{unit:n.unit,maxUnits:n.maxUnits}),a=o.unit>0?r.total/o.unit:0,l=Math.floor(a+1e-6),s=Math.min(1,Math.max(0,a-l));s<1e-6&&(s=0);let d=[];for(let e of o.units)if(!(e.index<l)){if(e.index===l&&s>0){e.fraction-s>1e-6&&d.push({...e,startFraction:s,start:e.index*o.unit+s*o.unit,value:(e.fraction-s)*o.unit});continue}d.push({...e,startFraction:0})}return{...r,overflow:r.overflow||o.overflow,rangeUnits:d,rangeTotal:i}}var t=e=>{let t=e.config,n=t.rows??10,r=t.columns??10,i=t.gutter??2,{plot:o}=e.dimensions;if(o.width<=0||o.height<=0)return{nodes:[]};let a=()=>({nodes:[],overlays:Ft(o,0,e.data.length,"rows","The grid needs positive integer dimensions and enough space for its gutters.",{force:!0})}),l=n*r;if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||!Number.isSafeInteger(l)||n<=0||r<=0||!Number.isFinite(i)||i<0)return a();let s=(o.width-i*(r-1))/r;if(s<=0||o.height<=i*(n-1))return a();let d=null==t.categoryAccessor?()=>"_default":yt(t.categoryAccessor),c=null==t.valueAccessor?()=>1:yt(t.valueAccessor),u=new Map;for(let t of e.data){let e=String(d(t)),n=Ct(Number(c(t)));u.set(e,(u.get(e)??0)+n)}let h=Array.from(u.values()).reduce((e,t)=>e+t,0);if(!(h>0&&Number.isFinite(h)))return{nodes:[],overlays:Ft(o,0,u.size,"categories","Category values must have a finite positive total.")};let p=[...new Set([...t.categoryOrder??[],...u.keys()])].filter(e=>u.has(e)),f=zt(p.map(e=>({key:e,weight:u.get(e)??0})),l,void 0,!0),m=f.filter(e=>e.cells>0).length,g=Ft(o,m,p.length,"categories","Zero-valued categories and categories rounded to zero cells are omitted."),y=(o.height-(g?18:0)-i*(n-1))/n;if(y<=0)return a();let x="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",b="string"==typeof t.valueAccessor?t.valueAccessor:"value",w=(e,t,n)=>Mt(r=>{r("category",e),r("value",u.get(e)??0),r("share",(u.get(e)??0)/h),"category"!==x&&r(x,e),"value"!==b&&r(b,u.get(e)??0),r("cells",n),r("_waffleCategory",e),r("_waffleIndex",t)}),M=[],v=0;for(let t of f){let a=e.resolveColor(t.key);for(let e=0;e<t.cells;e++){let l=v%r,d=n-1-Math.floor(v/r);M.push({type:"rect",x:o.x+l*(s+i),y:o.y+d*(y+i),w:s,h:y,style:{fill:a,stroke:"none"},datum:w(t.key,v,t.cells),group:t.key,_transitionKey:`waffle-${t.key}-${e}`}),v++}}return{nodes:M,overlays:g}};import{forceCenter as Yt,forceCollide as Bt,forceLink as qt,forceManyBody as Vt,forceSimulation as Ht,forceX as Ut,forceY as Xt}from"d3-force";function Kt(e){let t=e>>>0;function n(){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}return n.getState=()=>t>>>0,n}function Jt(e,t,n={}){let r=n.seed??1,i=n.iterations??260,o=n.repulsion??5200,a=n.linkDistance??165,l=n.linkStrength??.045,s=n.centerStrength??.018,d=n.damping??.84,c=n.nodeRadius??12,u=n.nodePadding??3,h=n.inset??.06,p=Kt(r),f=new Map;for(let t of e)f.set(t.id,0);for(let e of t)f.set(e.source,(f.get(e.source)??0)+1),f.set(e.target,(f.get(e.target)??0)+1);let m=500,g=e.map(e=>({id:e.id,data:e,x:200+600*p(),y:200+600*p()})),y=new Set(e.map(e=>e.id)),x=t.filter(e=>y.has(e.source)&&y.has(e.target)).map(e=>({source:e.source,target:e.target}));if(i>0){let e=Ht(g).randomSource(p).alphaDecay(1-Math.pow(.001,1/i)).velocityDecay(Math.max(0,Math.min(1,1-d))).force("charge",Vt().strength(e=>{let t=f.get(e.id)??0;return 2.5*-Math.sqrt(o)*Math.sqrt(t+1)})).force("collide",Bt(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Yt(m,m).strength(.8)).force("x",Ut(m).strength(s)).force("y",Xt(m).strength(s));x.length>0&&e.force("link",qt(x).id(e=>e.id).distance(a).strength(e=>{let t="string"==typeof e.source?e.source:e.source.id,n="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(f.get(t)??1,f.get(n)??1));return l/.045/r})),e.stop();for(let t=0;t<i;t+=1)e.tick()}let b=1/0,w=1/0,M=-1/0,v=-1/0;for(let e of g){let t=e.x??m,n=e.y??m;t<b&&(b=t),n<w&&(w=n),t>M&&(M=t),n>v&&(v=n)}let k=M-b,I=v-w,$={};for(let e of g){let t={x:0===k?.5:h+((e.x??m)-b)/k*(1-2*h),y:0===I?.5:h+((e.y??m)-w)/I*(1-2*h)};Object.defineProperty($,e.id,{value:t,enumerable:!0,configurable:!0,writable:!0})}return $}function Zt(e){return e?e.map(Number).filter(Number.isFinite):[]}function Qt(e){if("fixed-denominator"===e.countStrategy)return 1/0;let t=e.maxTokens??1/0;return t>0?Math.floor(t):0}function en(e){let t=e.unitValue??e.unit,n=e.icon??e.token;return{...e,...null!=t&&{unitValue:t},...null!=n&&{icon:n}}}function tn(e){if(e.samples)return Zt(e.samples);if(!e.data||!e.valueAccessor)return[];let t=e.valueAccessor;return e.data.map(e=>"function"==typeof t?t(e):Number(e[t])).filter(Number.isFinite)}function nn(e,t,n,r={}){return{index:t,tokenType:e.tokenType,tokenSemantics:e.tokenSemantics,countStrategy:e.countStrategy,fraction:1,startFraction:0,value:n,start:t,end:t+n,unitValue:e.unitValue,unitMeaning:e.unitMeaning,...r}}function rn(e,t){let n,r,i,o,a,l,s,d=en(t),c=function(e){return"number"==typeof e?{value:e}:Array.isArray(e)?{samples:Zt(e),data:e}:e}(e),u=0,h=!1;if("unitized"===d.countStrategy){a=d.unitValue??1;let e={unit:a,maxUnits:d.maxTokens,minFraction:d.minFraction},t=null==c.rangeValue?Wt(Ct(c.value),e):Gt(Ct(c.value),Ct(c.rangeValue),e);if(n=t.units.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:t.unit})),r=t.total,u=t.shown,h=t.overflow,null!=c.rangeValue){let e=t;l=e.rangeTotal,s=e.rangeUnits.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,startFraction:e.startFraction,start:e.start,end:e.end,unitValue:t.unit,range:"scenario"}))}}else if("fixed-denominator"===d.countStrategy){o=Math.floor(Ct(c.denominator??d.denominator)),i=Ct(c.numerator??d.numerator??c.value);let e=Math.min(o,Math.max(0,Math.round(i)));n=Array.from({length:o},(t,n)=>nn(d,n,1,{highlighted:n<e,start:n,end:n+1})),r=o,u=n.length,h=!1}else if("quantile"===d.countStrategy){let e=tn(c).sort((e,t)=>e-t),t=Math.max(0,Math.floor(d.tokenCount??50)),i=e.length>0?Math.min(t,Qt(d)):0;n=Array.from({length:i},(t,n)=>{let r=(n+.5)/i,o=function(e,t){let n=e.length;if(0===n)return 0;if(1===n)return e[0];let r=(n-1)*Math.min(1,Math.max(0,t)),i=Math.floor(r),o=Math.ceil(r),a=r-i;return e[i]*(1-a)+e[o]*a}(e,r);return nn(d,n,o,{sample:o,quantile:r,start:o,end:o})}),r=e.length,u=n.length,h=e.length>0&&t>n.length}else if("sample"===d.countStrategy||"posterior-sample"===d.countStrategy||"random-sample"===d.countStrategy){let e=tn(c),t=Math.min(e.length,Math.max(0,Math.floor(d.tokenCount??e.length))),i=Math.min(t,Qt(d));n=("random-sample"===d.countStrategy?function(e,t=1){let n=Array.from({length:e},(e,t)=>t),r=Kt(Math.floor(t)||1);for(let e=n.length-1;e>0;e-=1){let t=Math.floor(r()*(e+1)),i=n[e];n[e]=n[t],n[t]=i}return n}(e.length,d.seed).slice(0,i):Array.from({length:i},(t,n)=>Math.floor(n/Math.max(1,i-1)*(e.length-1)))).map((t,n)=>{let r=e[t];return nn(d,n,r,{sample:r,start:r,end:r})}),r=e.length,u=n.length,h=t>n.length}else{let e=c.data;if(e&&null==c.value)n=e.map((e,t)=>nn(d,t,1,{datum:e})),r=e.length;else{let e=Wt(Ct(c.value),{unit:1,maxUnits:d.maxTokens,minFraction:d.minFraction});n=e.units.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:1})),r=e.total,u=e.shown,h=e.overflow}if(e&&null==c.value){let e=function(e,t){let n=Qt(t);return e.length<=n?{tokens:e,overflow:!1}:{tokens:e.slice(0,n),overflow:!0}}(n,d);n=e.tokens,u=n.length,h=e.overflow}}return{tokens:n,encoding:d,total:r,shown:u,overflow:h,numerator:i,denominator:o,unitValue:a,rangeTotal:l,rangeTokens:s,diagnostics:an(d,{visibleTokens:n.length+(s?.length??0)})}}function on(e,t={}){let n=function(e){return Array.isArray(e)}(e)?e:e.tokens,r=n.length;if(0===r)return[];let i=t.flow??"row",o=t.cellWidth??16,a=t.cellHeight??o,l=t.gutter??2,s=t.anchor??[.5,.5],d=Math.max(1,Math.floor(t.columns??(t.rows?Math.ceil(r/t.rows):Math.ceil(Math.sqrt(r))))),c=Math.max(1,Math.floor(t.rows??Math.ceil(r/d))),u="row"===i?Math.max(c,Math.ceil(r/d)):c,h="column"===i?Math.max(d,Math.ceil(r/c)):d,p=t.x??0,f=t.y??0;return n.map((e,n)=>{let r,m;return"column"===i?(m=Math.floor(n/c),r=n%c):(r=Math.floor(n/d),m=n%d),"left"===t.columnDirection&&(m=h-1-m),"up"===t.rowDirection&&(r=u-1-r),{...e,row:r,column:m,x:p+m*(o+l)+s[0]*o,y:f+r*(a+l)+s[1]*a}})}function an(e,t={}){let n=[],r=e.tokenSemantics,i=e.countStrategy,o=t.maxRecommendedTokens??("fixed-denominator"===i&&Ct(e.denominator)<=100?100:80);return r||n.push({code:"TOKEN_SEMANTICS_UNCLEAR",severity:"warning",message:"Every tokenized encoding should state what one token represents."}),i||n.push({code:"MISSING_COUNT_STRATEGY",severity:"warning",message:"Every tokenized encoding should state how token counts are produced."}),("icon"===e.tokenType||"glyph"===e.tokenType)&&("icon-only"===e.labelPolicy||"token-only"===e.labelPolicy)&&n.push({code:"ICON_ONLY_LABELS",severity:"warning",message:"Icons should supplement text labels, not replace them."}),null!=t.visibleTokens&&t.visibleTokens>o&&n.push({code:"TOO_MANY_VISIBLE_TOKENS",severity:"warning",message:`This encoding renders ${t.visibleTokens} visible tokens. Consider unitizing, sampling, or a hybrid bar/token view.`}),"decorative"===r&&("icon"===e.tokenType||"glyph"===e.tokenType)&&n.push({code:"DECORATIVE_PICTOGRAPHS",severity:"warning",message:"Decorative pictographs can harm recall and speed when they do not clarify the data."}),"unitized-measure"===r&&i&&"unitized"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Unitized measures should use the unitized count strategy so each token has a stable value."}),"risk-case"===r&&i&&"fixed-denominator"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Risk cases are usually clearest as a fixed-denominator natural frequency."}),("possible-outcome"===r||"posterior-sample"===r||"hypothetical-case"===r)&&i&&"quantile"!==i&&"sample"!==i&&"posterior-sample"!==i&&"random-sample"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Outcome/sample tokens should come from quantiles or samples, not from a unitized magnitude."}),"unitized-measure"===r&&"unitized"===i&&null==e.unitValue&&null==e.unit&&n.push({code:"MISSING_UNIT_VALUE",severity:"warning",message:"Unitized measures should set unitValue so each token has a declared value."}),"unitized-measure"===r&&"unitized"===i&&!e.unitMeaning&&n.push({code:"MISSING_UNIT_MEANING",severity:"info",message:"Add unitMeaning so readers know what one full token represents."}),n}function ln(e){return"measure"===e?"precise-comparison":"estimate probability"===e?"probability-estimation":"understand risk"===e?"risk-communication":"remember"===e?"memory":"decide"===e?"support-decision":e}function sn(e){let t=ln(e);return"precise-comparison"===t?["compare-categories","rank"]:"probability-estimation"===t?["distribution"]:"risk-communication"===t?["part-to-whole","distribution"]:"frequency-reasoning"===t?["distribution","compare-categories"]:"memory"===t||"editorial-engagement"===t?["compare-categories"]:"public-explanation"===t||"support-decision"===t?["distribution","compare-categories"]:["compare-categories"]}function dn(e){let t=ln(e.taskIntent),n=function(e){return"small"===e?25:"large"===e?100:50}(e.availableSpace);if("precise-comparison"===t)return{recommendedEncoding:"bar-or-line",rationale:"Use continuous position/length encodings when precise magnitude comparison is the primary task.",warnings:[],alternatives:["hybrid-bar-token","unitized-measure"]};if("probability-estimation"===t){let e={tokenType:"dot",tokenSemantics:"possible-outcome",countStrategy:"quantile",tokenCount:n,layout:"dotplot",labelPolicy:"text-plus-token"};return{recommendedEncoding:"quantile-dotplot",tokenEncoding:e,rationale:"This task asks readers to estimate probability from a distribution. Quantile tokens turn probability mass into countable possible outcomes.",warnings:an(e),alternatives:["cdf-with-threshold","density-with-threshold"]}}if("risk-communication"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"risk-case",countStrategy:"fixed-denominator",denominator:100,layout:"waffle",labelPolicy:"text-plus-token"};return{recommendedEncoding:"fixed-denominator-icon-array",tokenEncoding:t,rationale:"Risk is often clearer as natural frequency: highlighted cases out of a fixed denominator.",warnings:an(t,{visibleTokens:100,maxRecommendedTokens:100}),alternatives:["labeled-percent","bar-with-risk-threshold"]}}if("memory"===t||"editorial-engagement"===t){let t={tokenType:e.concreteEntity?"glyph":"icon",icon:e.concreteEntity,tokenSemantics:"unitized-measure",countStrategy:"unitized",unitValue:1,layout:"grid",labelPolicy:"text-plus-token",unitMeaning:e.concreteEntity?`one token represents a unit of ${e.concreteEntity}`:"one token represents one unit"};return{recommendedEncoding:"semantic-isotype",tokenEncoding:t,rationale:"Semantic tokens are useful when the chart needs to make a topic concrete and memorable.",warnings:an(t),alternatives:["labeled-bar","hybrid-bar-token"]}}if("frequency-reasoning"===t||"public-explanation"===t||"support-decision"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"distribution"===e.dataType?"possible-outcome":"unitized-measure",countStrategy:"distribution"===e.dataType?"quantile":"unitized",unitValue:"distribution"===e.dataType?void 0:1,tokenCount:n,layout:"distribution"===e.dataType?"dotplot":"bar-segment",labelPolicy:"text-plus-token",unitMeaning:"distribution"===e.dataType?void 0:"one token represents one unit interval"};return{recommendedEncoding:"hybrid-continuous-token",tokenEncoding:t,rationale:"A hybrid view preserves measurement while adding countable tokens for explanation and decisions.",warnings:an(t),alternatives:["bar-or-line","quantile-dotplot","fixed-denominator-icon-array"]}}return{recommendedEncoding:"bar-or-line",rationale:"Use continuous encodings unless the task needs frequency, risk, memory, or outcome reasoning.",warnings:[],alternatives:["unitized-measure","quantile-dotplot","fixed-denominator-icon-array"]}}import{symbol as cn,symbolCircle as un,symbolCross as hn,symbolDiamond as pn,symbolSquare as fn,symbolStar as mn,symbolTriangle as gn,symbolWye as yn}from"d3-shape";function xn(e,t,r){if(r)return r;let i=e??"circle";if("chevron"===i)return function(e){let t=1.5*bn(e),n=.92*t;return`M0,${-t}L${n},${(.78*t).toFixed(3)}L0,${(.28*t).toFixed(3)}L${-n},${(.78*t).toFixed(3)}Z`}(t);let o=Object.prototype.hasOwnProperty.call(n,i)?n[i]:un;return cn(o,Math.max(1,t))()??""}function bn(e){return Math.sqrt(Math.max(1,e)/Math.PI)}function wn(e,t,n){if(!n&&"circle"===(e??"circle"))return bn(t);let r=n?`p:${n}`:`s:${e??"circle"}:${t}`,o=i.get(r);if(null!=o)return o;let a=xn(e,t,n).match(/-?\d*\.?\d+(?:e-?\d+)?/gi),l=0;if(a)for(let e=0;e+1<a.length;e+=2){let t=+a[e],n=+a[e+1],r=Math.sqrt(t*t+n*n);r>l&&(l=r)}return l>0?(i.size>512&&i.clear(),i.set(r,l),l):bn(t)}function Mn(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function vn(e,t,n){return"function"==typeof e?e(t)??n:e??n}function kn(e,t){return"function"==typeof e?e(t):e}function In(e){return e.sample??e.value??e.index}function $n(e,t){return void 0!==t.datum?vn(t.datum,e,null):e.datum??null}function Sn(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?vn(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):vn(t.color,e,m):vn(t.inactiveColor,e,g),stroke:"none",...kn(t.style,e)??{}}}function Nn(e,t){let n=kn(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:$n(e,t),accessibleDatum:kn(t.accessibleDatum,e),accessibility:kn(t.accessibility,e),pointId:n,_transitionKey:n}}function An({input:e,encoding:t,options:n={}}){if(!Mn(e)&&!t)throw new Error("tokenLayer requires an encoding when input is not a TokenSet.");let r=Mn(e)?{...e,encoding:en(e.encoding)}:rn(e,t),i=function(e,t){let n=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){let n=t.positionToken;return n?e.map((t,r)=>{let i=n(t,r,e);return{...t,x:i.x,y:i.y,row:i.row??r,column:i.column??0}}):[]}(n,t);let r=t.layout??e.encoding.layout??"grid";if("quantile-strip"===r||"dotplot"===r)return function(e,t,n){if(0===e.length)return[];let r=t.x??0,i=t.y??0,o=n?"number"==typeof t.tokenSize?t.tokenSize:12:0,a=n?0:t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),l=t.gutter??2,s=n?t.cellWidth??o+l:12,d=n?t.cellHeight??o+l:a+l,c=n?1:Math.max(1,Math.floor(t.rows??1)),[u,h]=ct(e,In),p=h-u||1,f=n?new Map:null;return e.map((o,a)=>{let l=In(o),h=a%c,m=a,g=t.valueToX?t.valueToX(l,o):r+(l-u)/p*(t.width??Math.max(1,e.length-1)*s);n&&(m=Math.round((g-r)/Math.max(1,s)),h=f.get(m)??0,f.set(m,h+1),g=r+m*s);let y=t.valueToY?t.valueToY(l,o):i+h*d;return{...o,x:g,y:y,row:h,column:m}})}(n,t,"dotplot"===r);if("bar-segment"===r){if(!t.valueToX)throw new Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];let n=t.y??0,r=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.anchor??[.5,.5];return e.map((e,o)=>{let a=Number.isFinite(e.start)?e.start:In(e),l=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,s=t.valueToY?t.valueToY(l,e):n+i[1]*r;return{...e,x:t.valueToX(l,e),y:s,row:0,column:o}})}(n,t)}if("beeswarm"===r||"small-multiple"===r)throw new Error(`tokenLayer layout "${r}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);let i="number"==typeof t.tokenSize?t.tokenSize:void 0,o=t.cellWidth??i??12,a=t.cellHeight??i??o,l="row"===r?Math.max(1,n.length):"column"===r||"stack"===r?1:"waffle"===r&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,n){if(t.columns)return t.columns;if(t.width&&n>0){let e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(n+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(n,t,o);return on(n,{...t,columns:l,cellWidth:o,cellHeight:a})}(r,n).filter(e=>!n.include||n.include(e));return{tokenSet:r,positionedTokens:i,nodes:i.map(e=>function(e,t,n){if("dot"===n.tokenType)return function(e,t){let n=vn(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:vn(t.radius,e,n/2),style:Sn(e,t),...Nn(e,t)}}(e,t);let r=kn(t.glyph,e)??function(e){if(e)return f[e]}(n.icon);if(r)return function(e,t,n){let r=Sn(e,n),i=vn(n.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:i,glyph:t,color:String(r.fill??m),accent:vn(n.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:e.fraction<1?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:vn(n.fractionDirection,e,"horizontal"),ghostColor:e.fraction<1?kn(n.ghostColor,e)??g:void 0,rotation:kn(n.rotation,e),style:r,...Nn(e,n)}}(e,r,t);let i=function(e){return e&&y.has(e)?e:void 0}(n.icon);return function(e,t){let n=vn(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,n/2)**2,symbolType:vn(t.symbolType,e,"circle"),path:kn(t.symbolPath,e),rotation:kn(t.rotation,e),style:Sn(e,t),...Nn(e,t)}}(e,i&&null==t.symbolType?{...t,symbolType:i}:t)}(e,n,r.encoding))}}var n={circle:un,square:fn,triangle:gn,diamond:pn,star:mn,cross:hn,wye:yn},r=["circle","triangle","diamond","star","square","chevron","cross","wye"],i=/*#__PURE__*/new Map,o="#334155",a="#f8fafc",l="#cbd5e1",f={server:s={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},chip:d={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},bolt:c={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},bus:u={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},person:p={viewBox:[18,40],anchor:[.5,1],parts:[{d:h="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",fill:"color",stroke:"color",strokeWidth:1.4}]}},m="var(--semiotic-primary, #4e79a7)",g="var(--semiotic-border, #d1d5db)",y=/*#__PURE__*/new Set(r);import{interpolateRgb as En}from"d3-interpolate";function Cn(e){return e<10?`0${e}`:String(e)}function On(e,t){return e<t?-1:e>t?1:0}function Tn(e,t){if("function"==typeof e)return e;let n=e??t;return e=>e[n]}function Rn(e,t,n){let r=(t+n.lat)/2*(Math.PI/180);return[111.32*(e-n.lon)*Math.cos(r),110.574*(t-n.lat)]}function Ln(e){let t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function Fn(e){return w.has(e)?e:"monument"}function Pn(e,t){let n=Ln(t.gridSize),r=Math.max(1,t.gridRadiusKm??75),i=2*r/n,o=Math.floor(n/2),a=Tn(t.idAccessor,"id"),l=Tn(t.nameAccessor,"name"),s=Tn(t.longitudeAccessor,"lon"),d=Tn(t.latitudeAccessor,"lat"),c=Tn(t.kindAccessor,"kind"),u=t.candidatePriorityAccessor?Tn(t.candidatePriorityAccessor,"priority"):()=>0,h=Array.from({length:n*n},(e,t)=>{let o=Math.floor(t/n),a=t%n;return{id:`tile-${o}-${a}`,row:o,column:a,centerXKm:(a+.5)*i-r,centerYKm:r-(o+.5)*i,terrainIndex:(17*o+31*a)%b.length,landmark:null,landmarks:[]}}),p=[];for(let o of e){let e=Number(s(o)),f=Number(d(o));if(!Number.isFinite(e)||!Number.isFinite(f))continue;let m=String(a(o)??`${e},${f}`),g=String(l(o)??m),y=Fn(c(o)),[x,b]=Rn(e,f,t.center);if(Math.abs(x)>r||Math.abs(b)>r)continue;let w=Math.min(n-1,Math.floor((x+r)/i)),M=Math.min(n-1,Math.floor((r-b)/i)),v=h[M*n+w],k=Number(u(o)),I={...o,id:m,name:g,kind:y,lon:e,lat:f,distanceKm:Math.sqrt(x*x+b*b),row:M,column:w,cellDistanceSq:(x-v.centerXKm)**2+(b-v.centerYKm)**2,candidatePriority:Number.isFinite(k)?k:0};v.landmarks.push(I),m===t.centerId&&p.push(I)}let f=(e,t)=>On(e.name,t.name)||On(e.id,t.id)||e.lon-t.lon||e.lat-t.lat||On(e.kind,t.kind),m=(e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||f(e,t),g=h[o*n+o],y=p.sort(m)[0]??[...g.landmarks].sort((e,t)=>e.candidatePriority-t.candidatePriority||+("city"===t.kind)-+("city"===e.kind)||e.distanceKm-t.distanceKm||f(e,t))[0],x=new Map;y&&x.set(y.kind,1);let w=e=>e.cellDistanceSq+(x.get(e.kind)??0)*i*i*.35,M=(e,t)=>e.candidatePriority-t.candidatePriority||w(e)-w(t)||f(e,t);for(let e of h){let t=e===g;if(e.landmarks=e.landmarks.filter(e=>e!==y).sort(t?m:M),t&&y&&e.landmarks.unshift(y),e.landmark=e.landmarks[0]??null,e.landmark&&e.landmark!==y){let t=e.landmark.kind;x.set(t,(x.get(t)??0)+1)}}return h}var x=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0)return{nodes:[]};let r="utc"===t.timeZone,i=(e,t,n)=>{let i=new Date(0);return r?(i.setUTCFullYear(e,t,n),i.setUTCHours(0,0,0,0)):(i.setFullYear(e,t,n),i.setHours(0,0,0,0)),i},o=e=>r?e.getUTCFullYear():e.getFullYear(),a=e=>`${o(e)}-${Cn(r?e.getUTCMonth()+1:e.getMonth()+1)}-${Cn(r?e.getUTCDate():e.getDate())}`,l=e=>{let n="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];if(n instanceof Date)return n;if("string"==typeof n&&/^\d{4}-\d{2}-\d{2}$/.test(n)){let[e,t,r]=n.split("-").map(Number);return i(e,t-1,r)}return new Date(n)},s=e=>{let n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return null==n?NaN:Number(n)},d=new Map,c=null;for(let t of e.data){let e=l(t);if(!isFinite(e.getTime()))continue;null==c&&(c=o(e));let n=a(e),r=s(t);Number.isFinite(r)&&d.set(n,(d.get(n)??0)+r)}let u=t.year??c??o(new Date),h=1/0,p=-1/0;for(let[e,t]of d)e.startsWith(`${u}-`)&&(t<h&&(h=t),t>p&&(p=t));h===1/0&&(h=0,p=0);let[f,m]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],g=t.missingColor??e.theme.semantic.grid??"#d1d5db",y=e=>{if(p===h)return f;let t=(e-h)/(p-h);return En(f,m)(t)},x=t.gutter??2,b=t.labelInset??0,w=n.width-b,M=n.height,v=Math.min((w-53*x)/54,(M-6*x)/7);if(v<=0)return{nodes:[]};let k=i(u,0,1),I=((r?k.getUTCDay():k.getDay())-(t.weekStart??0)+7)%7,$=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let r=i(u,0,1-I+7*e+t);if(o(r)!==u)continue;let l=a(r),s=d.get(l),c=null==s?g:y(s);$.push({type:"rect",x:n.x+b+e*(v+x),y:n.y+t*(v+x),w:v,h:v,style:{fill:c,stroke:"none"},datum:{date:r,value:s??null,missing:null==s}})}return{nodes:$}},b=["#739b58","#83a964","#668d52","#8baa68"],w=/*#__PURE__*/new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]);import*as zn from"react";import{jsx as Dn}from"react/jsx-runtime";function jn(){let e=(M??(M=zn.createContext(null)),M);return zn.useContext(e)??v}var v={isActive:!1,predicate:()=>!0};import{jsx as _n,jsxs as Wn}from"react/jsx-runtime";function Gn(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Yn(e,t){let n=Gn(e,t);return"string"==typeof n&&n.length>0?n:void 0}function Bn(e){return Yn($,e)??$.land}function qn(e,t,n,r){return[`M${e},${t-r/2}`,`L${e+n/2},${t}`,`L${e},${t+r/2}`,`L${e-n/2},${t}`,"Z"].join("")}function Vn({tiles:e,tileWidth:t,tileHeight:n,sprites:r,resourceSize:i,citySize:o,showCityLabel:a}){let l=jn(),s=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return Wn("g",{"aria-hidden":"true",pointerEvents:"none",children:[s.map(e=>{let a=e.landmark,s="city"===a.kind?o:i,d=e.y+n/2,c=l.isActive&&!l.predicate(a)?.28:1;return Wn("g",{opacity:c,children:[_n("ellipse",{cx:e.x,cy:e.y+.15*n,rx:.28*s,ry:.1*s,fill:"#17251d",opacity:.32}),_n(Un,{kind:a.kind,href:Yn(r,a.kind),x:e.x-s/2,y:d-s,size:s}),e.landmarks.length>1&&_n(Hn,{x:e.x+.3*t,y:e.y-.19*n,count:e.landmarks.length-1,tileHeight:n})]},e.id)}),a&&s.filter(e=>"city"===e.landmark?.kind).map(e=>{let t=e.landmark.name.toUpperCase(),r=Math.max(56,6.4*t.length+14);return Wn("g",{transform:`translate(${e.x},${e.y+.72*n})`,children:[_n("rect",{x:-r/2,y:-7,width:r,height:14,rx:1,fill:"#17251d",opacity:.92}),_n("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},`${e.landmark.id}-label`)})]})}function Hn({x:e,y:t,count:n,tileHeight:r}){let i=Math.max(10,Math.min(15,.34*r)),o=`+${n}`,a=Math.max(i,o.length*i*.58);return Wn("g",{transform:`translate(${e},${t})`,children:[_n("rect",{x:-a/2,y:-i/2,width:a,height:i,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),_n("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*i),fontWeight:700,children:o})]})}function Un({kind:e,href:t,x:n,y:r,size:i}){if(t)return _n("image",{href:t,x:n,y:r,width:i,height:i,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});let o=A[e],a=E[e];return _n("svg",{x:n,y:r,width:i,height:i,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:o.flatMap((e,t)=>[...e].map((e,n)=>"."===e?null:_n("rect",{x:n,y:t,width:1,height:1,fill:a[e]},`${t}-${n}`)))})}var k={resource:32,city:64},I={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},$={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},S=/*#__PURE__*/new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]),N=e=>{let t=Ln(e.config.gridSize),n=Math.max(20,e.config.tileWidth??80),r=Math.max(10,e.config.tileHeight??40),i=e.config.terrainColors?.length?e.config.terrainColors:b,o=t*r,a=e.dimensions.width/2,l=(e.dimensions.height-o)/2+r/2,s=Pn(e.points,e.config).map(e=>({...e,x:a+(e.column-e.row)*(n/2),y:l+(e.column+e.row)*(r/2)}));return{nodes:s.map(t=>{let o=function(e,t){let n=Gn(e,t),r=function(e){return S.has(e)?e:void 0}("string"==typeof n?n:Gn(n,"kind"));if(!r)return;if("string"==typeof n)return{kind:r};let i=Gn(n,"coverage"),o="number"==typeof i&&Number.isFinite(i)?Math.max(0,Math.min(1,i)):void 0,a=Yn(n,"fill");return{kind:r,...null==o?{}:{coverage:o},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":o?.kind??"land",l=o?.fill??Yn(e.config.terrainPalette,a)??function(e){return Yn(I,e)??I.land}(a),s=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:o?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:Bn(a),kind:"terrain",terrainKind:a,terrainCoverage:o?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};return{type:"geoarea",pathData:qn(t.x,t.y,n,r),centroid:[t.x,t.y],bounds:[[t.x-n/2,t.y-r/2],[t.x+n/2,t.y+r/2]],screenArea:n*r/2,style:{fill:o||"urban"===a?l:i[t.terrainIndex%i.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:s,group:t.landmark?.kind??a,interactive:!0}}),overlays:_n(Vn,{tiles:s,tileWidth:n,tileHeight:r,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??k.resource,citySize:e.config.citySpriteSize??k.city,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}},A={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},E={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};import{jsx as Xn}from"react/jsx-runtime";function Kn(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function Jn(e){let t=1/0,n=-1/0;for(let r of e)Number.isFinite(r)&&(r<t&&(t=r),r>n&&(n=r));return t===1/0?[0,0]:[t,n]}function Zn(e,t){let n=t[1]-t[0];return 0===n?.5:(e-t[0])/n}function Qn(e,t={}){let n=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===n.length)return[];let r=gt(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),i=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8,o=Kn(t.columns)??Math.max(1,Math.ceil(Math.sqrt(n.length*i/r))),a=Kn(t.rows)??Math.max(1,Math.ceil(n.length/(o*r)));o*a<n.length&&(null!=t.columns&&null==t.rows?a=Math.ceil(n.length/o):null!=t.rows&&null==t.columns?o=Math.ceil(n.length/a):a=Math.ceil(n.length/o));let l=Jn(n.map(e=>e.x)),s=Jn(n.map(e=>e.y)),d=n.map(e=>({...e,desiredColumn:Zn(e.x,l)*Math.max(0,o-1),desiredRow:Zn(e.y,s)*Math.max(0,a-1)})),c=(o-1)/2,u=(a-1)/2;d.sort((e,t)=>{let n=(e.desiredColumn-c)**2+(e.desiredRow-u)**2;return(t.desiredColumn-c)**2+(t.desiredRow-u)**2-n||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index});let h=new Set;for(let e=0;e<a;e+=1)for(let t=0;t<o;t+=1)h.add(e*o+t);let p=[];for(let e of d){let t=-1,n=1/0;for(let r of h){let i=Math.floor(r/o),a=(r%o-e.desiredColumn)**2+(i-e.desiredRow)**2;(a<n||a===n&&r<t)&&(t=r,n=a)}t<0||(h.delete(t),p.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/o),column:t%o,index:e.index}))}return p.sort((e,t)=>e.index-t.index),p.map(({index:e,...t})=>t)}function er(e,t,n=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(let t of n)if(null!=e[t])return e[t]}function tr(e){return`${e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")}Z`}function nr(e,t,n){return tr([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}function rr(e,t,n){let r=[];for(let i=0;i<6;i+=1){let o=-Math.PI/2+i*(Math.PI/3);r.push([e+Math.cos(o)*n,t+Math.sin(o)*n])}return tr(r)}function ir({marks:e,color:t,fontSize:n,fontFamily:r,fontWeight:i}){let o=jn();return Xn("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{let a=!o.isActive||o.predicate(e.datum);return Xn("text",{x:e.x,y:e.y,fill:t,fontFamily:r,fontSize:n,fontWeight:i,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}var C=e=>{let t=e.config,n=t.source??"auto",r="areas"===n||"auto"===n&&e.areas.length>0,i=(r?function(e){return e.areas.map((t,n)=>{let r=function(e,t){let n=e.properties&&"object"==typeof e.properties?e.properties:{},r=e.id??n.id??n.name??`area-${t}`;return{...n,id:String(r)}}(t,n),i=e.scales.geoPath.centroid(t),o=Number.isFinite(i[0])&&Number.isFinite(i[1])?e.scales.invertedPoint(i[0],i[1]):null;return{datum:{...r,gridLongitude:o?.[0],gridLatitude:o?.[1]},x:i[0],y:i[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t}))).filter((e,n)=>!t.filter||t.filter(e.datum,n)),o=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;let n=e.map(e=>({datum:e,x:Number(er(e,t.columnAccessor)),y:Number(er(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return n.length!==e.length?null:n.map(e=>({...e,row:e.y,column:e.x}))}(i.map(e=>e.datum),t),a=r?i:function(e){return e.points.map(t=>{let n=Number(er(t,e.config.longitudeAccessor,["lon","longitude"])),r=Number(er(t,e.config.latitudeAccessor,["lat","latitude"])),i=Number.isFinite(n)&&Number.isFinite(r)?e.scales.projectedPoint(n,r):null;return{datum:t,x:i?.[0]??NaN,y:i?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:i.map(e=>e.datum)}),l=o??Qn(a,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===l.length)return{nodes:[]};let s=Jn(l.map(e=>e.row)),d=Jn(l.map(e=>e.column)),c=Math.max(1,Math.round(s[1]-s[0])+1),u=Math.max(1,Math.round(d[1]-d[0])+1),h=Math.max(0,t.layoutPadding??8),p=Math.max(1,e.dimensions.width-2*h),f=Math.max(1,e.dimensions.height-2*h),m=p/u,g=f/c,y=m*u,x=g*c,b=(e.dimensions.width-y)/2,w=(e.dimensions.height-x)/2,M=gt(t.cellPadding??.12,0,.8),v=Math.max(1,.5*Math.min(m,g)*(1-M)),k=t.sizeAccessor?l.map(e=>Number(er(e.datum,t.sizeAccessor))):[],I=t.sizeDomain??Jn(k),$=t.sizeRange??[.36,1],S=gt(Math.min($[0],$[1]),.05,1),N=gt(Math.max($[0],$[1]),S,1),A=l.map((n,r)=>{let i={...n.datum,gridRow:n.row,gridColumn:n.column},o=String(er(i,t.idAccessor,["id","key","name"])??`grid-${r}`),a=String(er(i,t.labelAccessor,["abbr","code","label","name","id"])??o),l=Math.max(1,t.maxLabelLength??4),c=a.length>l?a.slice(0,l):a,u=er(i,t.categoryAccessor),h=null==u?void 0:String(u),p=er(i,t.fillAccessor),f=null!=p?String(p):h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",y=t.sizeAccessor?Number(er(i,t.sizeAccessor)):NaN,x=t.sizeAccessor&&Number.isFinite(y)?Math.sqrt(gt(Zn(y,I),0,1)):1,M=v*(S+x*(N-S)),k="function"==typeof t.markStyle?t.markStyle(i,r):t.markStyle;return{datum:i,id:o,label:c,category:h,row:n.row,column:n.column,x:b+(n.column-d[0]+.5)*m,y:w+(n.row-s[0]+.5)*g,radius:M,style:{fill:f,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...k}}}),E=t.shape??"circle";return{nodes:A.map(e=>"circle"===E?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===E?rr(e.x,e.y,e.radius):nr(e.x,e.y,e.radius),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===E?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0}),overlays:!1===t.showLabels?null:Xn(ir,{marks:A,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??gt(.23*Math.min(m,g),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};import{geoBounds as or,geoContains as ar}from"d3-geo";import{jsx as lr}from"react/jsx-runtime";function sr(e){if(Number.isFinite(e)&&!(Number(e)<=0))return Number(e)}function dr(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function cr(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function ur(e,t){let n=cr(e);return String(e.id??n.id??n.name??`feature-${t}`)}function hr(e,t,n,r){return[Math.ceil((e-n)/r-.5),Math.floor((t-n)/r-.5)]}function pr(e){if(!e)return 0;let t=R.get(e);if(t)return t;let n=L;return L+=1,R.set(e,n),n}function fr(e,t){return!t||e[1]>=t[0][1]&&e[1]<=t[1][1]&&function(e,t,n){return t<=n?e>=t&&e<=n:e>=t||e<=n}(e[0],t[0][0],t[1][0])}function mr(e,t){for(let n of e){let{feature:e,index:r}=n;if(e.geometry&&fr(t,n.bounds))try{if(ar(e,t))return{feature:e,index:r}}catch{}}return null}function gr(e,t,n,r={}){let i=e.filter((e,t)=>e.geometry&&(!r.featureFilter||r.featureFilter(e,t))),o=function(e,t){if(0===e.length)return null;let n={type:"FeatureCollection",features:e},r=t.bounds(n);return Number.isFinite(r[0][0])&&Number.isFinite(r[0][1])&&Number.isFinite(r[1][0])&&Number.isFinite(r[1][1])?r:null}(i,t.geoPath);if(!o)return{dots:[],cellSize:10,features:i};let a=Math.max(0,r.layoutPadding??0),l=[[gt(o[0][0],a,Math.max(a,n.width-a)),gt(o[0][1],a,Math.max(a,n.height-a))],[gt(o[1][0],a,Math.max(a,n.width-a)),gt(o[1][1],a,Math.max(a,n.height-a))]],s=Math.max(0,l[1][0]-l[0][0]),d=Math.max(0,l[1][1]-l[0][1]);if(0===s||0===d)return{dots:[],cellSize:10,features:i};let c=sr(r.columns),u=Math.max(2,c?s/c:sr(r.cellSize)??10),h=Math.max(100,Math.round(sr(r.maxSamples)??25e3)),p=Math.ceil(s/u)*Math.ceil(d/u);p>h&&(u*=Math.sqrt(p/h));let f=r.gridOrigin?.[0]??0,m=r.gridOrigin?.[1]??0,[g,y]=hr(l[0][0],l[1][0],f,u),[x,b]=hr(l[0][1],l[1][1],m,u),w=[],M=function(e){return e.map((e,t)=>{if(T.has(e))return{feature:e,index:t,bounds:T.get(e)??null};try{let n=or(e);return T.set(e,n),{feature:e,index:t,bounds:n}}catch{return T.set(e,null),{feature:e,index:t,bounds:null}}})}(i);for(let e=x;e<=b;e+=1){let n=m+(e+.5)*u;for(let i=g;i<=y;i+=1){let o=f+(i+.5)*u,a=t.invertedPoint(o,n);if(!a||!Number.isFinite(a[0])||!Number.isFinite(a[1]))continue;let l=mr(M,a);if(!l)continue;let s={...cr(l.feature),featureId:ur(l.feature,l.index),featureIndex:l.index,gridRow:e,gridColumn:i,longitude:a[0],latitude:a[1],dotIndex:w.length};r.dotFilter&&!r.dotFilter(s,w.length)||w.push(s)}}return{dots:w,cellSize:u,features:i}}function yr(e){return Math.round(1e4*e)/1e4}function xr(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${yr(Number(e[0]))},${yr(Number(e[1]))}`:"null"}function br(e,t){let n=e[t];return"function"==typeof n?n.call(e):void 0}function wr(e){return"number"==typeof e&&Number.isFinite(e)?String(yr(e)):null===e?"null":"unavailable"}function Mr(e){return Array.isArray(e)&&e.every(Number.isFinite)?e.map(e=>yr(Number(e))).join(","):"unavailable"}function vr(e){let t=e.scales.projection;return[wr(br(t,"scale")),xr(br(t,"translate")),xr(br(t,"center")),Mr(br(t,"rotate")),wr(br(t,"clipAngle")),wr(br(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,n])=>xr(e.scales.projectedPoint(t,n)))].join("|")}function kr(e){return`${e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")}Z`}function Ir(e,t,n){return kr([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}function $r(e,t,n){return kr(Array.from({length:6},(r,i)=>{let o=-Math.PI/2+i*(Math.PI/3);return[e+Math.cos(o)*n,t+Math.sin(o)*n]}))}function Sr(e,t,n){let r=e.data??e,i=r.x??e.x,o=r.y??e.y,a=e.createdByFrame&&0===e.width?void 0:e.width,l=e.createdByFrame&&0===e.height?void 0:e.height,s=r.width??a??t,d=r.height??l??n;if(!("number"!=typeof i||"number"!=typeof o||"number"!=typeof s||"number"!=typeof d||![i,o,s,d].every(Number.isFinite)||s<=0||d<=0))return{x:i,y:o,w:s,h:d}}function Nr(e,t,n){let{nodeWidth:r,nodeHeight:i,waypoints:o=[]}=n,a="none"===n.fit?"none":"contain",l=1/0,s=1/0,d=-1/0,c=-1/0,u=(e,t)=>{l=Math.min(l,e),s=Math.min(s,t),d=Math.max(d,e),c=Math.max(c,t)},h=!1;for(let t of e){let e=Sr(t,r,i);e&&(h=!0,u(e.x-e.w/2,e.y-e.h/2),u(e.x+e.w/2,e.y+e.h/2))}for(let e of o)u(e.x,e.y);let p=1,f=0,m=0;if("contain"===a&&h){let e=d-l,n=c-s;if(![e,n,t.x,t.y,t.width,t.height].every(Number.isFinite)||e<=0||n<=0||t.width<=0||t.height<=0)h=!1;else{let r=Math.min(1,t.width/4,t.height/4);p=Math.min(1,(t.width-2*r)/e,(t.height-2*r)/n),f=t.x+(t.width-e*p)/2-l*p,m=t.y+(t.height-n*p)/2-s*p}}let g=({x:e,y:t})=>({x:e*p+f,y:t*p+m});return{fit:a,scale:p,dx:f,dy:m,bounds:h?{x:l,y:s,width:d-l,height:c-s}:null,project:g,invert:({x:e,y:t})=>({x:(e-f)/p,y:(t-m)/p}),nodeBounds:e=>{let t=h?Sr(e,r,i):void 0;if(!t)return;let{x:n,y:o}=g(t),a=t.w*p,l=t.h*p;return{x:n-a/2,y:o-l/2,width:a,height:l,cx:n,cy:o}}}}function Ar(e,t,n,r=[]){let i=Nr(e.nodes,e.dimensions.plot,{nodeWidth:t.nodeWidth,nodeHeight:t.nodeHeight,fit:t.fit,waypoints:r}),o=new Map,a=[],l=[];for(let r of e.nodes){let s=i.nodeBounds(r);if(!s)continue;let{cx:d,cy:c,width:u,height:h}=s;o.set(r.id,{x:d,y:c,w:u,h:h});let p=r.data??r,f=t.labelAccessor??"id",m=String("function"==typeof f?f(p):p[f]??r.id);a.push({type:"rect",x:s.x,y:s.y,w:u,h:h,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:n,strokeWidth:Math.min(1.5,u/2,h/2)},datum:p,id:r.id,label:m}),!1!==t.showLabels&&l.push({x:d,y:c,text:m,anchor:"middle",baseline:"middle",fontSize:11*i.scale})}return{positions:o,sceneNodes:a,labels:l,project:i.project}}function Er(e,t,n={}){return Nr(e,t,{nodeWidth:n.nodeWidth??80,nodeHeight:n.nodeHeight??30,fit:n.fit})}var O=/*#__PURE__*/new WeakMap,T=/*#__PURE__*/new WeakMap,R=/*#__PURE__*/new WeakMap,L=1,F=e=>{let t=function(e){let t=O.get(e.areas);t||(t=new Map,O.set(e.areas,t));let n=function(e){let t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",pr(t.featureFilter),pr(t.dotFilter),vr(e)].join("::")}(e),r=t.get(n);if(r)return r;let i=gr(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){let e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(n,i),i}(e),n=e.config,r=n.shape??"circle",i=Math.max(.5,sr(n.dotRadius)??t.cellSize*gt(n.radiusRatio??.24,.05,.5)),o=n.gridOrigin?.[0]??0,a=n.gridOrigin?.[1]??0;return{nodes:t.dots.map((l,s)=>{let d=o+(l.gridColumn+.5)*t.cellSize,c=a+(l.gridRow+.5)*t.cellSize,u=dr(l,n.categoryAccessor),h=dr(l,n.fillAccessor),p={fill:null!=h?String(h):null!=u?e.resolveColor(String(u)):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof n.markStyle?n.markStyle(l,s):n.markStyle},f=`dot-${l.gridRow}-${l.gridColumn}`;return"circle"===r?{type:"point",x:d,y:c,r:i,style:p,datum:l,interactive:!1,pointId:f,_transitionKey:f}:{type:"geoarea",pathData:"hexagon"===r?$r(d,c,i):Ir(d,c,i),centroid:[d,c],bounds:[[d-i,c-i],[d+i,c+i]],screenArea:"hexagon"===r?3*Math.sqrt(3)*i*i/2:(2*i)**2,style:p,datum:l,group:l.featureId,interactive:!1}}),overlays:n.showOutline?lr("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,r)=>{let i=e.scales.geoPath(t);return i?lr("path",{d:i,fill:"none",stroke:n.outlineStyle?.stroke??"currentColor",strokeOpacity:n.outlineStyle?.opacity??n.outlineStyle?.fillOpacity??.22,strokeWidth:n.outlineStyle?.strokeWidth??.7,strokeDasharray:n.outlineStyle?.strokeDasharray,strokeLinecap:n.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},ur(t,r)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},P=e=>{let t=e.config??{},n=t.orientation??"vertical",r=t.edgeCurve??"curved",{positions:i,sceneNodes:o,labels:a}=Ar(e,{...t,nodeWidth:t.nodeWidth??80,nodeHeight:t.nodeHeight??30},`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`),l=[];for(let t of e.edges){let o="string"==typeof t.source?t.source:t.source.id,a="string"==typeof t.target?t.target:t.target.id,s=i.get(o),d=i.get(a);if(!s||!d)continue;let c="vertical"===n?{x:s.x,y:s.y+s.h/2}:{x:s.x+s.w/2,y:s.y},u="vertical"===n?{x:d.x,y:d.y-d.h/2}:{x:d.x-d.w/2,y:d.y};if("line"===r)l.push({type:"line",x1:c.x,y1:c.y,x2:u.x,y2:u.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t.data??t});else{let r=(c.y+u.y)/2,i=(c.x+u.x)/2,o="vertical"===n?`M${c.x},${c.y} C${c.x},${r} ${u.x},${r} ${u.x},${u.y}`:`M${c.x},${c.y} C${i},${c.y} ${i},${u.y} ${u.x},${u.y}`;l.push({type:"curved",pathD:o,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t.data??t})}}return{sceneNodes:o,sceneEdges:l,labels:a}};import{createElement as Cr}from"react";import{createElement as Or}from"react";function Tr(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.min(0===n?1/0:e.w/2/Math.abs(n),0===r?1/0:e.h/2/Math.abs(r));return Number.isFinite(i)?{x:e.x+n*i,y:e.y+r*i}:{x:e.x,y:e.y}}function Rr(e,t,n,r,i,o=1){let a=t.x-n.x,l=t.y-n.y,s=Math.hypot(a,l);if(0===s||i<=0)return null;let d=Math.min(i,s)/s,c=a*d,u=l*d;return Or("polygon",{key:e,className:"recipe-edge-arrow",points:`${t.x},${t.y} ${t.x-c-u/2},${t.y-u+c/2} ${t.x-c+u/2},${t.y-u-c/2}`,fill:r,opacity:o,"aria-hidden":!0,style:{pointerEvents:"none"}})}import{NetworkPerspectiveGround as Lr}from"./semiotic-network-placement.module.min.js";function Fr(e){let t=e.data??e,n=Array.isArray(t.points)?t.points:e.points;return Array.isArray(n)&&n.length>=2&&n.every(e=>e&&Number.isFinite(e.x)&&Number.isFinite(e.y))?n:[]}function Pr(e,t,n,r={}){return Nr(e,n,{nodeWidth:r.nodeWidth??100,nodeHeight:r.nodeHeight??36,fit:r.fit,waypoints:t.flatMap(Fr)})}var z=e=>{let t=e.config??{},n=t.edgeStyle??"polyline",r=new Map(e.edges.map(e=>[e,Fr(e)])),{positions:i,sceneNodes:o,labels:a,project:l}=Ar(e,{...t,nodeWidth:t.nodeWidth??100,nodeHeight:t.nodeHeight??36,labelAccessor:t.labelAccessor??"label"},`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,[...r.values()].flat()),s=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`;for(let e=0;e<a.length;e++){let t=a[e],n=i.get(o[e].id);if(!n)continue;let r=Math.max(1,Math.floor(n.w/(.6*(t.fontSize??11))-2));t.text.length>r&&(t.text=t.text.slice(0,r-1)+"…")}let d=[],c=[];for(let t of e.edges){let e="string"==typeof t.source?t.source:t.source.id,o="string"==typeof t.target?t.target:t.target.id,a=i.get(e),u=i.get(o);if(!a||!u)continue;let h=r.get(t).map(l);if(h.length<2){let e=Tr(a,u),n=Tr(u,a);d.push(Rr(d.length,n,e,s,Math.min(7,u.w/4,u.h/3))),c.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:s,strokeWidth:1},datum:t.data??t});continue}let p=h[h.length-1],f=h.slice(0,-1).reverse().find(e=>e.x!==p.x||e.y!==p.y);if(f&&d.push(Rr(d.length,p,f,s,Math.min(7,u.w/4,u.h/3))),"smooth"===n&&h.length>=3){let e=`M${h[0].x},${h[0].y}`;for(let t=1;t<h.length-1;t++){let n=(h[t].x+h[t+1].x)/2,r=(h[t].y+h[t+1].y)/2;e+=` Q${h[t].x},${h[t].y} ${n},${r}`}let n=h[h.length-1];e+=` T${n.x},${n.y}`,c.push({type:"curved",pathD:e,style:{stroke:s,strokeWidth:1,fill:"none"},datum:t.data??t})}else{let e="M"+h.map(e=>`${e.x},${e.y}`).join(" L ");c.push({type:"curved",pathD:e,style:{stroke:s,strokeWidth:1,fill:"none"},datum:t.data??t})}}return{sceneNodes:o,sceneEdges:c,labels:a,overlays:d.length?Cr("g",null,Cr(Lr,{z:"top"},d)):null,perspective:"manual"}};import{createElement as zr}from"react";import{NetworkPerspectiveBillboard as Dr,NetworkPerspectiveGround as jr}from"./semiotic-network-placement.module.min.js";function _r(e,t){let n="function"==typeof t?t(e):e[t];return D(n)?n:void 0}function Wr(e){return[...e].sort((e,t)=>Rt(e,t))}function Gr(e,t,n){let r=new Map([[e,0]]),i=[e];for(let e=0;e<i.length;e++){let o=i[e],a=r.get(o);for(let e of Wr(n.get(o)??[]))!t.has(e)||r.has(e)||(r.set(e,a+1),i.push(e))}return r}function Yr(e,t,n){let r=Gr(e,t,n),i=e,o=-1;for(let[e,t]of r)(t>o||t===o&&Rt(e,i)<0)&&(i=e,o=t);return i}function Br(e,t,n){let r=new Set(e),i=e.filter(e=>(t.get(e)?.size??0)<=1)[0]??e[0],o=Gr(n&&r.has(n)?n:Yr(Yr(i,r,t),r,t),r,t),a=0;for(let e of o.values())a=Math.max(a,e);let l=Array.from({length:a+1},()=>[]);for(let t of e)l[o.get(t)??0].push(t);l.forEach(e=>e.sort((e,t)=>Rt(e,t)));let s=(e,n)=>{let r=new Map(l[n].map((e,t)=>[e,t])),i=e=>{let n=[...t.get(e)??[]].map(e=>r.get(e)).filter(e=>null!=e);return 0===n.length?Number.POSITIVE_INFINITY:n.reduce((e,t)=>e+t,0)/n.length},o=new Map(l[e].map(e=>[e,i(e)]));l[e].sort((e,t)=>o.get(e)-o.get(t)||Rt(e,t))};for(let e=0;e<4;e+=1){for(let e=1;e<l.length;e+=1)s(e,e-1);for(let e=l.length-2;e>=0;e-=1)s(e,e+1)}return l}function qr(e,t,n,r={}){let i=Math.max(0,r.padding??36),o=Math.max(0,r.componentGap??26),a=r.xAccessor??"x",l=r.yAccessor??"y",s=e.map(e=>({...e,authoredX:_r(e.data,a),authoredY:_r(e.data,l)})),d=s.length>0&&s.every(e=>D(e.authoredX)&&D(e.authoredY)),c="authored"===r.layoutMode||"automatic"!==r.layoutMode&&d,u=[];if(c&&!d&&u.push("Authored transit layout requested, but at least one station has no finite x/y position; using automatic topology layout."),!c||!d){!d&&"automatic"!==r.layoutMode&&u.push("Complete station positions were not supplied; using the deterministic automatic topology layout.");let a=function(e,t,n,r,i,o){let a=function(e,t){let n=new Map(e.map(e=>[e,new Set]));for(let e of t)!n.has(e.source)||!n.has(e.target)||(n.get(e.source)?.add(e.target),n.get(e.target)?.add(e.source));return n}(e.map(e=>e.id),t),l=function(e){let t=new Set(e.keys()),n=[];for(let r of Wr(t)){if(!t.has(r))continue;let i=[r],o=[];t.delete(r);for(let n=0;n<i.length;n++){let r=i[n];o.push(r);for(let n of Wr(e.get(r)??[]))t.has(n)&&(t.delete(n),i.push(n))}n.push(o.sort((e,t)=>Rt(e,t)))}return n.sort((e,t)=>t.length-e.length||Rt(e[0],t[0]))}(a),s=new Map(e.map(e=>[e.id,e.data])),d=new Map,c=Math.max(0,n.width),u=Math.max(0,n.height),h=Math.min(r,c/2),p=Math.min(r,u/2),f=Math.max(0,u-2*p),m=l.length>1?Math.min(i,f/l.length):0,g=Math.max(0,f-m*Math.max(0,l.length-1)),y=l.reduce((e,t)=>e+Math.sqrt(t.length),0),x=p;for(let e of l){let t=g*(Math.sqrt(e.length)/y),n=Br(e,a,o),r=Math.max(0,c-2*h);n.forEach((e,i)=>{let o=1===n.length?c/2:h+i/(n.length-1)*r;e.forEach((n,r)=>{let i=1===e.length?x+t/2:x+r/(e.length-1)*t;d.set(n,{id:n,x:o,y:i,data:s.get(n)})})}),x+=t+m}return d}(e,t,n,i,o,r.rootId);if("right-to-left"===r.direction)for(let e of a.values())e.x=n.width-e.x;return{positions:a,mode:"automatic",warnings:u,projectAuthoredPoint:e=>e}}let h=1/0,p=-1/0,f=1/0,m=-1/0;for(let e of s)h=Math.min(h,e.authoredX),p=Math.max(p,e.authoredX),f=Math.min(f,e.authoredY),m=Math.max(m,e.authoredY);let g=Math.max(1,n.width-2*i),y=Math.max(1,n.height-2*i),x=e=>({x:p===h?n.width/2:i+(e.x-h)/(p-h)*g,y:m===f?n.height/2:i+(e.y-f)/(m-f)*y}),b=new Map;for(let e of s){let t=x({x:e.authoredX,y:e.authoredY});b.set(e.id,{id:e.id,...t,data:e.data})}return{positions:b,mode:"authored",warnings:u,projectAuthoredPoint:x}}function Vr(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.abs(n),o=Math.abs(r);if(i<.001||o<.001||Math.abs(i-o)<.001)return[e,t];let a=Math.sign(n),l=Math.sign(r);if(i>o){let n=(i-o)/2;return[e,{x:e.x+a*n,y:e.y},{x:t.x-a*n,y:t.y},t]}let s=(o-i)/2;return[e,{x:e.x,y:e.y+l*s},{x:t.x,y:t.y-l*s},t]}function Hr(e,t){if(0===t||e.length<2)return e.map(e=>({...e}));let n=(e,t)=>{let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r)||1;return{x:-r/i,y:n/i}};return e.map((r,i)=>{let o=i>0?n(e[i-1],r):null,a=i<e.length-1?n(r,e[i+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 l=o.x+a.x,s=o.y+a.y,d=Math.hypot(l,s);if(d<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};l/=d,s/=d;let c=l*a.x+s*a.y;if(Math.abs(c)<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};let u=4*Math.abs(t),h=t/c,p=Math.max(-u,Math.min(u,h));return{x:r.x+l*p,y:r.y+s*p}})}function Ur(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let n=Math.max(0,t),r=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let i=e[t-1],o=e[t],a=e[t+1],l=Math.hypot(o.x-i.x,o.y-i.y),s=Math.hypot(a.x-o.x,a.y-o.y),d=Math.min(n,l/2,s/2);if(d<=.001){r+=` L${o.x},${o.y}`;continue}let c={x:o.x+(i.x-o.x)/l*d,y:o.y+(i.y-o.y)/l*d},u={x:o.x+(a.x-o.x)/s*d,y:o.y+(a.y-o.y)/s*d};r+=` L${c.x},${c.y} Q${o.x},${o.y} ${u.x},${u.y}`}let i=e[e.length-1];return`${r} L${i.x},${i.y}`}function Xr(e,t){return"function"==typeof t.labelAccessor?t.labelAccessor(e.data):xt(e.data,t.labelAccessor??"label",e.id)}function Kr(e){return"string"==typeof e?e:e.id}function Jr(e,t){let n,r=t.lineAccessor;return n="function"==typeof r?r(e.data):"string"==typeof r?e.data[r]:e.data.lines??e.data.line??e.data.route??e.data.group,function(e){let t=(Array.isArray(e)?e:null==e?[]:[e]).map(e=>"object"==typeof e?{...e,id:String(e.id)}:{id:String(e)});return t.length>0?t:[{id:"network"}]}(n)}function Zr(e,t,n){let r=t.sourceColorAccessor,i="function"==typeof r?r(e.data):"string"==typeof r?e.data[r]:e.data.color;return"string"==typeof i&&i?i:n(e.id)}function Qr(e,t,n,r){if(e.color)return e.color;let i=n.lineColors&&Object.prototype.hasOwnProperty.call(n.lineColors,e.id)?n.lineColors[e.id]:void 0;if("string"==typeof i&&i)return i;let o=n.lineColorAccessor,a="function"==typeof o?o(t.data):"string"==typeof o?t.data[o]:t.data.color;return"string"==typeof a?a:r(e.id)}function ei(e,t){let n=new Map((t.lineOrder??[]).map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e)??Number.POSITIVE_INFINITY)-(n.get(t)??Number.POSITIVE_INFINITY)||Rt(e,t))}function ti(e,t){let n=e.authoredOrder??t.lineOrder??[],r=new Map(n.map((e,t)=>[e,t]));return[...e.lines.values()].sort((e,t)=>(r.get(e.descriptor.id)??Number.POSITIVE_INFINITY)-(r.get(t.descriptor.id)??Number.POSITIVE_INFINITY)||Rt(e.descriptor.id,t.descriptor.id))}function ni(e,t,n,r){if("authored"!==t.mode)return null;let i=e.data[n.pointsAccessor??"points"];if(!Array.isArray(i))return null;let o=i.map(e=>{let n=e;return"number"==typeof n.x&&"number"==typeof n.y?t.projectAuthoredPoint({x:n.x,y:n.y}):null}).filter(e=>null!=e);return 0===o.length?null:r?o.reverse():o}function ri(e,t){return Mt(n=>{for(let[t,r]of Object.entries(e.data))n(t,r);n("source",e.source),n("target",e.target),n("lineId",t.id),n("lineLabel",t.label??t.id)})}function ii(e,t){return e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top}function oi(e,t,n,r,i,o){if(!1===o.showLabels)return[];let a=o.labelFontSize??11,l=[],s=[],d=[...e].sort((e,t)=>(n.get(t.id)?.size??0)-(n.get(e.id)?.size??0)||Rt(e.id,t.id));for(let e of d){let n=t.get(e.id);if(!n)continue;let d=("function"==typeof o.labelAccessor?o.labelAccessor(e.data):String(xt(e.data,o.labelAccessor??"label",e.id)))||e.id,c=Math.max(2*a,d.length*a*.58),u=1.25*a,h=Math.max(o.interchangeRadius??7,r.get(e.id)??o.stationRadius??4)+5,p=[{x:n.x+h,y:n.y,anchor:"start",left:n.x+h},{x:n.x-h,y:n.y,anchor:"end",left:n.x-h-c},{x:n.x,y:n.y-h,anchor:"middle",left:n.x-c/2},{x:n.x,y:n.y+h,anchor:"middle",left:n.x-c/2}].map((e,t)=>{let n={left:e.left,right:e.left+c,top:e.y-u/2,bottom:e.y+u/2},r=l.filter(e=>ii(n,e)).length,o=Math.max(0,-n.left)+Math.max(0,n.right-i.width)+Math.max(0,-n.top)+Math.max(0,n.bottom-i.height);return{candidate:e,box:n,score:1e4*r+10*o+t}}).sort((e,t)=>e.score-t.score)[0];l.push(p.box),s.push({x:p.candidate.x,y:p.candidate.y,anchorPoint:[n.x,n.y],text:d,anchor:p.candidate.anchor,baseline:"middle",fontSize:a,fill:o.labelColor??"var(--semiotic-text, #222)",stroke:"var(--semiotic-bg, white)",strokeWidth:3,paintOrder:"stroke"})}return s}var D=e=>"number"==typeof e&&Number.isFinite(e),j=e=>{let t=e.config??{},n=t.mode??"primary",r=t.dimOpacity??.14,i=(t,n=e.selection)=>n?.isActive&&!n.predicate(t)?r:1,o=e.nodes.map(e=>({id:e.id,data:bt(e),wrapper:e})).sort((e,t)=>Rt(e.id,t.id)),a=e.edges.map(e=>({source:Kr(e.source),target:Kr(e.target),data:bt(e),wrapper:e})).sort((e,t)=>Rt(e.source,t.source)||Rt(e.target,t.target)),l=qr(o,a,e.dimensions.plot,t),s="source-rooted"===t.lineMode?function(e,t,n,r){let i=new Set(e.map(e=>e.id)),o=new Map(e.map(e=>[e.id,0])),a=new Map(e.map(e=>[e.id,[]]));for(let e of t)!i.has(e.source)||!i.has(e.target)||(o.set(e.target,(o.get(e.target)??0)+1),a.get(e.source)?.push(e));let l=e.filter(e=>0===(o.get(e.id)??0)),s=new Map,d=new Map(e.map(e=>[e.id,new Map]));for(let e of l){let t={id:e.id,label:String(Xr(e,n)),color:Zr(e,n,r)},i=new Set,o=[e.id];for(;o.length>0;){let e=o.shift();if(!i.has(e)){i.add(e),d.get(e)?.set(t.id,t);for(let n of a.get(e)??[]){let e=s.get(n);e||(e=new Map,s.set(n,e)),e.set(t.id,t),i.has(n.target)||o.push(n.target)}}}}let c=e=>[...e].sort((e,t)=>Rt(e.id,t.id));return{byEdge:new Map(t.map(e=>[e,c(s.get(e)?.values()??[])])),byNode:new Map(e.map(e=>[e.id,c(d.get(e.id)?.values()??[])]))}}(o,a,t,e.resolveColor):void 0,d=function(e,t,n){let r=new Map;for(let i of e){let e=i.source<i.target?`${i.source}\0${i.target}`:`${i.target}\0${i.source}`,o=r.get(e);o||(o={key:e,source:i.source,target:i.target,lines:new Map},r.set(e,o));let a=i.data.lineOrder;Array.isArray(a)&&(o.authoredOrder=a.map(String));let l=n?.byEdge.get(i)??Jr(i,t);for(let e of l)o.lines.has(e.id)||o.lines.set(e.id,{descriptor:e,edge:i})}return[...r.values()].sort((e,t)=>Rt(e.key,t.key))}(a,t,s),c=new Map(o.map(e=>[e.id,new Set])),u=new Map;if(s)for(let[e,t]of s.byNode)for(let n of t)c.get(e)?.add(n.id),n.color&&u.set(n.id,n.color);let h=Math.max(1,t.lineWidth??("primary"===n?6:"compact"===n?3.5:2)),p=Math.max(0,t.lineGap??("primary"===n?2:"compact"===n?1:.5)),f=new Map,m=[];for(let n of d){let r=l.positions.get(n.source),o=l.positions.get(n.target);if(!r||!o)continue;let a=ti(n,t),s=(a.length-1)/2*(h+p)+h/2;for(let e of[n.source,n.target])f.set(e,Math.max(f.get(e)??0,s));a.forEach((s,d)=>{c.get(n.source)?.add(s.descriptor.id),c.get(n.target)?.add(s.descriptor.id);let f=ni(s.edge,l,t,s.edge.source!==n.source),g=Hr(f?[r,...f,o]:Vr(r,o),(d-(a.length-1)/2)*(h+p)),y=ri(s.edge,s.descriptor),x=Qr(s.descriptor,s.edge,t,e.resolveColor);u.has(s.descriptor.id)||u.set(s.descriptor.id,x),m.push({type:"curved",id:`${n.key}:${s.descriptor.id}`,label:`${s.descriptor.label??s.descriptor.id}: ${s.edge.source} to ${s.edge.target}`,pathD:Ur(g,t.cornerRadius??10),style:{fill:"none",stroke:x,strokeWidth:h,strokeLinecap:"round",opacity:i(y)},datum:y,accessibleDatum:y,accessibility:{label:`${s.descriptor.label??s.descriptor.id}, ${s.edge.source} to ${s.edge.target}`,tableFields:{line:s.descriptor.label??s.descriptor.id,source:s.edge.source,target:s.edge.target}}})})}let g=new Map,y=[],x=[],b=[],w=e=>String(Xr(e,t)||e.id);if("minimap"===n){let n=new Map;for(let e of o){let t=l.positions.get(e.id);if(!t)continue;let r=`${t.x}\0${t.y}`,i=n.get(r);i||(i={x:t.x,y:t.y,nodes:[],lineIds:new Set,bundleRadius:0},n.set(r,i)),i.nodes.push(e);for(let t of c.get(e.id)??[])i.lineIds.add(t);i.bundleRadius=Math.max(i.bundleRadius,f.get(e.id)??0)}let r=[...n.values()].sort((e,t)=>e.x-t.x||e.y-t.y||Rt(e.nodes[0].id,t.nodes[0].id));for(let n of r){let r=ei(n.lineIds,t),o=r.length>1||n.nodes.length>1||n.nodes.some(e=>!0===e.data.interchange||!0===e.data.transfer),a=o?t.interchangeRadius??Math.max(5,n.bundleRadius):t.stationRadius??Math.max(3.5,n.bundleRadius);for(let e of n.nodes)g.set(e.id,a);let l=n.nodes.map(w).join(" / "),s=n.nodes.map(e=>e.id).join("--"),d=1===n.nodes.length?n.nodes[0].data:Mt(e=>{e("id",s),e("label",l),e("stationIds",n.nodes.map(e=>e.id)),e("stations",n.nodes.map(e=>e.data)),e("lineIds",r),e("interchange",o)}),c={label:`${l}${o?", interchange":""}`,tableFields:{station:l,lines:r.join(", ")}};r.length<=1?y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:(r[0]&&u.get(r[0]))??t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:i(d)},datum:d,accessibleDatum:d,accessibility:c,id:s,label:l}):(r.forEach((t,o)=>{let l=-Math.PI/2+o/r.length*Math.PI*2,c=-Math.PI/2+(o+1)/r.length*Math.PI*2,h={type:"arc",cx:n.x,cy:n.y,innerR:0,outerR:a,startAngle:l,endAngle:c,style:{fill:u.get(t)??e.resolveColor(t),stroke:"none",opacity:i(d)},datum:null,id:`${s}:${t}`};y.push(h)}),y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:"transparent",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:i(d)},datum:d,accessibleDatum:d,accessibility:c,id:s,label:l}))}}else for(let r of o){let o=l.positions.get(r.id);if(!o)continue;let a=ei(c.get(r.id)??[],t),s=a.length>1||!0===r.data.interchange||!0===r.data.transfer,d=s?t.interchangeRadius??Math.max("primary"===n?7:5,f.get(r.id)??0):t.stationRadius??("primary"===n?4:2.75);g.set(r.id,d);let u=w(r),h=null!=t.renderStation;if(y.push({type:"circle",cx:o.x,cy:o.y,r:d,style:h?{fill:"transparent",stroke:"transparent"}:{fill:t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:s?"primary"===n?3:2:1.5,opacity:i(r.data)},datum:r.data,accessibleDatum:r.data,accessibility:{label:`${u}${s?", interchange":""}`,tableFields:{station:u,lines:a.join(", ")}},id:r.id,label:u}),t.renderStation){let l={station:r.data,x:o.x,y:o.y,radius:d,lineIds:a,interchange:s,mode:n},c=t.renderStation(l);if(null!=c){if(e.perspective){let[e,n,r,i]=t.stationBounds?.(l)??[d,d,d,d];b.push("ground"===t.chromePlacement?{x:o.x-e,y:o.y-r,width:e+n,height:r+i,z:"top"}:{x:o.x,y:o.y,extent:[e,n,r,i]})}x.push(zr("ground"===t.chromePlacement?jr:Dr,{key:r.id,x:o.x,y:o.y,z:"top"},zr("g",{opacity:i(r.data),style:{pointerEvents:"none"}},c)))}}}let M=x.length>0?zr("g",{className:"transit-diagram-stations"},...x):void 0,v={sceneEdges:m,sceneNodes:y,overlays:M,perspective:"manual",...b.length?{perspectiveBounds:b}:{},labels:oi(o,l.positions,c,g,e.dimensions.plot,"primary"===n?t:{...t,showLabels:!1})};if(x.length>0||"minimap"===n)return v;let k=(e,t)=>({opacity:i(e.datum,t)});return{...v,restyle:k,restyleEdge:k}};import{NetworkPerspectiveBillboard as ai,NetworkPerspectiveGround as li}from"./semiotic-network-placement.module.min.js";function si(e,t,n={}){let r=n.layerAccessor??"x",i=n.rowAccessor??"y",o=1/0,a=-1/0,l=1/0,s=-1/0;for(let t of e){let e=Number(xt(t,r,0)),n=Number(xt(t,i,0));!Number.isFinite(e)||!Number.isFinite(n)||(o=Math.min(o,e),a=Math.max(a,e),l=Math.min(l,n),s=Math.max(s,n))}if(o===1/0&&(o=a=l=s=0),Number.isFinite(n.layerCount)&&n.layerCount>0&&(o=Math.min(o,0),a=Math.max(a,n.layerCount-1)),Number.isFinite(n.maxLayerSize)&&n.maxLayerSize>0){let e=Math.max(0,n.maxLayerSize-1)/2;l=Math.min(l,-e),s=Math.max(s,e)}let d=a-o,c=Math.max(1,s-l),u=(l+s-c)/2,h=d+1,p=s-l+1,f=t.width/Math.max(1,h),m=t.height/Math.max(1,p),g=Math.min(n.nodeWidth??172,Math.max(8,f-(n.minGapX??26))),y=Math.min(n.nodeHeight??54,Math.max(8,m-(n.minGapY??18))),x=n.lod&&"auto"!==n.lod?n.lod:g<16?"dot":g<48?"icon":g<108?"compact":"full";if("dot"===x){let e=Math.min(g,y,11);g=e,y=e}let b=Math.max(1,t.width-g),w=Math.max(1,t.height-y),{x:M,y:v}=t,k=(e,t)=>({x:M+g/2+(d>0?(e-o)/d:.5)*b,y:v+y/2+(t-u)/c*w});return{layerCount:h,maxLayerSize:p,nodeWidth:g,nodeHeight:y,lod:x,project:k,invert:(e,t)=>({layer:d>0?o+(e-M-g/2)/b*d:null,row:(t-v-y/2)/w*c+u}),nodeBounds:e=>{let t=k(Number(xt(e,r,0)),Number(xt(e,i,0)));return{x:t.x-g/2,y:t.y-y/2,width:g,height:y,cx:t.x,cy:t.y}}}}import{NetworkPerspectiveBillboard as di,NetworkPerspectiveGround as ci}from"./semiotic-network-placement.module.min.js";import{jsx as ui,jsxs as hi}from"react/jsx-runtime";function pi(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function fi(e){let t=e.slice().sort((e,t)=>e.x-t.x||e.y-t.y).filter((e,t,n)=>0===t||e.x!==n[t-1].x||e.y!==n[t-1].y);if(t.length<=2)return t;let n=[];for(let e of t){for(;n.length>=2&&pi(n[n.length-2],n[n.length-1],e)<=0;)n.pop();n.push(e)}let r=[];for(let e=t.length-1;e>=0;e--){let n=t[e];for(;r.length>=2&&pi(r[r.length-2],r[r.length-1],n)<=0;)r.pop();r.push(n)}return n.pop(),r.pop(),n.concat(r)}function mi(e,t){if(0===t||e.length<3)return e;let n=e.reduce((t,n,r)=>{let i=e[(r+1)%e.length];return t+n.x*i.y-i.x*n.y},0)>=0?1:-1;return e.map((r,i)=>{let o=e[(i-1+e.length)%e.length],a=e[(i+1)%e.length],l=Math.hypot(r.x-o.x,r.y-o.y)||1,s=Math.hypot(a.x-r.x,a.y-r.y)||1,d=n>0?{x:(r.y-o.y)/l,y:-(r.x-o.x)/l}:{x:-(r.y-o.y)/l,y:(r.x-o.x)/l},c=n>0?{x:(a.y-r.y)/s,y:-(a.x-r.x)/s}:{x:-(a.y-r.y)/s,y:(a.x-r.x)/s},u={x:d.x+c.x,y:d.y+c.y},h=Math.hypot(u.x,u.y);if(h<1e-9)return{x:r.x+c.x*t,y:r.y+c.y*t};let p=u.x/h,f=u.y/h,m=Math.max(1e-6,p*c.x+f*c.y),g=t/m;return{x:r.x+p*g,y:r.y+f*g}})}function gi(e){return String(Math.abs(e)<1e-12?0:e)}function yi(e,t){let n=[];for(let[r,i]of e){let e=mi(fi(i.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding);if(!e.length)continue;let[o,a]=ct(e,e=>e.x),[l,s]=ct(e,e=>e.y);n.push({x:o,y:l,width:a-o,height:s-l});let d=t.label?.(r);d&&n.push({x:o+8,y:l+14,z:0,extent:[0,6.6*d.length,12,3]})}return n}import{jsx as xi,jsxs as bi}from"react/jsx-runtime";function wi(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:String(e.storeName??""),slotIndex:e.slotIndex??t}):[]}function Mi(e,t){return Number.isFinite(e)?gt(e,0,1):t}function vi(e,t){let{w:n,h:r,lod:i}=t,o="icon"===i?Math.min(n,r):Math.min(r-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",l="icon"===i?0:8+o+8,s=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:o,color:a,node:e.node}):function(e,t,n){let r=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return bi("g",{children:[xi("rect",{width:n,height:n,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),xi("text",{x:n/2,y:n/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*n,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:r})]})}(e.semantic,e.partition,o),d="full"===i,c="icon"!==i,u="full"===i&&t.showChips&&e.stores.length>0;return bi("g",{transform:`translate(${e.cx-n/2}, ${e.cy-r/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[xi("g",{transform:`translate(${"icon"===i?(n-o)/2:8}, ${(r-o)/2})`,children:s}),c&&xi("foreignObject",{x:l,y:d?r/2-12:r/2-9,width:Math.max(8,n-l-8),height:18,style:{pointerEvents:"none"},children:xi("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===i?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),d&&xi("text",{x:l,y:r/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),u&&e.stores.map((e,n)=>xi("rect",{x:l+15*n,y:r-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:xi("title",{children:e.storeName})},e.storeName+n))]},e.id)}async function ki(e,t,n={}){let{prepareNetworkAtlas:r}=await(import("./c-XM76UG3P.min.js"));return r(e,t,n)}async function Ii(e){let{prepareMotifBraid:t}=await(import("./c-OBA7XSLH.min.js"));return t(e)}function $i(e,t,n){if(e.length<2)return"";let r=function(e){let t=[e[0]];for(let n=1;n<e.length-1;n++){let r=e[n-1],i=e[n],o=e[n+1],a=B(r,i),l=B(i,o),s=Math.min(8,a/2,l/2);if(0===s)continue;let d=Y(i,r,s/a),c=Y(i,o,s/l);t.push(d);for(let e=1;e<=12;e++){let n=e/12;t.push(Y(Y(d,i,n),Y(i,c,n),n))}}return t.push(e[e.length-1]),t.filter((e,n)=>0===n||B(t[n-1],e)>1e-8)}(e);if(r.length<2)return"";let i=[0];for(let e=1;e<r.length;e++)i.push(i[e-1]+B(r[e-1],r[e]));let o=i[i.length-1],a=Hr(r,1),l=[1,-1].map(e=>r.map((r,l)=>{let s=t+(n-t)*i[l]/o;return Y(r,a[l],e*s/2)}));return[...l[0],...l[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function Si(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let n=t+e/2;return t+=e+3,n})}function Ni(e){let t="";return e.split(">").map((e,n)=>t=n?`${t}>${e}`:e)}var _={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},W={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"},G=e=>{let t=e.config||{},n=e.dimensions.plot,r=t.partitionAccessor??"partition",i=t.semanticAccessor??"semantic",o=t.labelAccessor??"label",a=t.storesAccessor??"stores",l=t.backEdgeAccessor??"isBackEdge",s=t.edgeTypeAccessor??"edgeType",d={..._,...t.partitionColors},c=t.partitionStrokeColors??{},u=t.dotStrokeWidth??1,h={...W,...t.edgeColors},p=t.accentColor??"var(--semiotic-focus, #ffcc33)",f=t.borderColor??"var(--semiotic-border, #555)",m=t.dimOpacity??.14,g=t.edgeOpacity??.5,y=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,w=t.storeChipColor??"var(--semiotic-info, #6a8caf)",M=t.hullGroupAccessor,v=si(e.nodes,n,t),{nodeWidth:k,nodeHeight:I,lod:$}=v,S=t.reachableIds?new Set(t.reachableIds):null,N=t.selectedId??null,A=e.selection,E=null!==S||!0===A?.isActive,C=new Map,O=new Map,T=[],R=null==M?null:new Map,L=[];for(let t of e.nodes){let e=t.id,n=String(xt(t,r,"processor")),l=String(xt(t,i,"processor")),s=String(xt(t,o,e)),h=wi(xt(t,a,[])),g=t.data??t,{cx:y,cy:x}=v.nodeBounds(t);if(!Number.isFinite(y)||!Number.isFinite(x))continue;C.set(e,{cx:y,cy:x});let b=S?S.has(e):null,w=A?.isActive?A.predicate(g):null,E=null!==b?!b:null!==w&&!w;O.set(e,E);let F=null!=N&&e===N,P=E&&!F?m:1,z=Object.prototype.hasOwnProperty.call(d,n)?d[n]:d.unknown,D=Object.prototype.hasOwnProperty.call(c,n)?c[n]:void 0;if("dot"===$){let t={type:"circle",cx:y,cy:x,r:k/2,style:{fill:z,opacity:P,stroke:F?p:D??"transparent",strokeWidth:F?2:D?u:0},datum:g,id:e,label:s};T.push(t)}else{let t={type:"rect",x:y-k/2,y:x-I/2,w:k,h:I,style:{fill:z,opacity:P,stroke:F?p:D??f,strokeWidth:F?3:1},datum:g,id:e,label:s};T.push(t),L.push({id:e,cx:y,cy:x,partition:n,semantic:l,label:s,stores:h,opacity:P,selected:F,node:g})}if(R&&null!=M){let n=xt(t,M,null);if(null!=n){let t=String(n),r=R.get(t)??[];r.push({id:e,x:y-k/2,y:x-I/2,w:k,h:I}),R.set(t,r)}}}let F=[],P=[];for(let r of e.edges){let e="string"==typeof r.source?r.source:r.source.id,i="string"==typeof r.target?r.target:r.target.id,o=C.get(e),a=C.get(i);if(!o||!a)continue;let d,c,u,p=!!(xt(r,l,null)??o.cx>=a.cx),f=String(xt(r,s,"internal")),b=O.get(e)||O.get(i),w=E&&!b,M=b?Math.min(g,1.4*m):w?t.highlightEdgeOpacity??g:g,v=w&&null!=t.highlightEdgeWidth?t.highlightEdgeWidth:p?x:y,S=p?h.back:Object.prototype.hasOwnProperty.call(h,f)?h[f]:h.internal;if(p){let t=Math.min(o.cy,a.cy)-I/2-n.y,r=n.y+n.height-Math.max(o.cy,a.cy)-I/2,l=(o.cy+a.cy)/2>n.y+n.height/2?t>8?-1:r>8?1:0:r>8?1:t>8?-1:0,s=Math.max(48,.28*Math.abs(o.cx-a.cx))+I,h=l<0?Math.max(n.y+1,Math.min(o.cy,a.cy)-I/2-s):l>0?Math.min(n.y+n.height-1,Math.max(o.cy,a.cy)+I/2+s):(o.cy+a.cy)/2,p=e===i,f=p?k/4:0,m=p&&"dot"===$?Math.sqrt((I/2)**2-f**2):I/2,g=o.cx-f,y=o.cy+Math.sign(h-o.cy)*m;c={x:a.cx+f,y:a.cy+Math.sign(h-a.cy)*m},u={x:c.x,y:h},d=`M${g},${y} C${g},${h} ${u.x},${u.y} ${c.x},${c.y}`}else{let e=Math.sign(a.cx-o.cx)||1,t=o.cx+e*k/2;c={x:a.cx-e*k/2,y:a.cy};let n=(t+c.x)/2;u={x:n,y:c.y},d=`M${t},${o.cy} C${n},${o.cy} ${n},${c.y} ${c.x},${c.y}`}!1!==t.showArrowheads&&P.push(Rr(P.length,c,u,S,Math.min(7,k/4,I/3),M));let N={type:"curved",pathD:d,style:{stroke:S,strokeWidth:v,fill:"none",opacity:M,...p?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:r.data??r};F.push(N)}let z="ground"===t.chromePlacement?li:ai,D=0===L.length&&0===P.length?null:bi("g",{children:[P.length>0&&xi(li,{z:"top",children:P}),L.length>0&&xi("g",{className:"lineage-dag-glyphs",children:L.map(e=>xi(z,{x:e.cx,y:e.cy,z:"top",children:vi(e,{w:k,h:I,lod:$,partColors:d,chipColor:w,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel})},e.id))})]}),j=R&&R.size>0?function(e,t){let n=Array.from(e.entries()).sort(([e],[t])=>e<t?-1:e>t?1:0);return ui("g",{className:"lineage-dag-hulls","aria-hidden":"true",style:{pointerEvents:"none"},children:n.map(([e,n])=>{let r=mi(fi(n.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding),i=function(e,t){if(0===e.length)return"";if(e.length<3||0===t)return`${e.map((e,t)=>`${0===t?"M":"L"}${gi(e.x)},${gi(e.y)}`).join(" ")} Z`;let n=e.map((n,r)=>{let i=e[(r-1+e.length)%e.length],o=e[(r+1)%e.length],a=Math.hypot(i.x-n.x,i.y-n.y)||1,l=Math.hypot(o.x-n.x,o.y-n.y)||1,s=Math.min(t,a/2,l/2);return{point:n,incoming:{x:n.x+(i.x-n.x)/a*s,y:n.y+(i.y-n.y)/a*s},outgoing:{x:n.x+(o.x-n.x)/l*s,y:n.y+(o.y-n.y)/l*s}}}),r=n[0].outgoing,i=`M${gi(r.x)},${gi(r.y)}`;for(let e=1;e<n.length;e++){let t=n[e];i+=` L${gi(t.incoming.x)},${gi(t.incoming.y)}`,i+=` Q${gi(t.point.x)},${gi(t.point.y)} ${gi(t.outgoing.x)},${gi(t.outgoing.y)}`}let o=n[0];return i+=` L${gi(o.incoming.x)},${gi(o.incoming.y)}`,i+=` Q${gi(o.point.x)},${gi(o.point.y)} ${gi(o.outgoing.x)},${gi(o.outgoing.y)} Z`,i}(r,t.radius),o=Object.prototype.hasOwnProperty.call(t.colors??{},e)?t.colors?.[e]??t.resolveColor(e):t.resolveColor(e),a=n.every(e=>!0===t.dimById.get(e.id)&&e.id!==t.selectedId),l=ut(r.map(e=>e.x)),s=ut(r.map(e=>e.y)),d=t.label?.(e);return hi("g",{"data-lineage-hull":e,opacity:a?t.dimOpacity:void 0,children:[ui(ci,{children:ui("path",{className:"lineage-dag-hull",d:i,fill:o,fillOpacity:t.fillOpacity,stroke:o,strokeOpacity:t.strokeOpacity,strokeWidth:1,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"none"}})}),d?ui(di,{x:l+8,y:s+14,z:0,children:ui("text",{className:"lineage-dag-hull-label",x:l+8,y:s+14,fill:o,fillOpacity:Math.max(t.strokeOpacity,.7),fontSize:11,fontWeight:600,style:{pointerEvents:"none"},children:d})}):null]},e)})})}(R,{colors:t.hullColors,padding:null==t.hullPadding?16:Ct(t.hullPadding),radius:null==t.hullRadius?12:Ct(t.hullRadius),fillOpacity:Mi(t.hullFillOpacity,.08),strokeOpacity:Mi(t.hullStrokeOpacity,.4),label:t.hullLabel,resolveColor:e.resolveColor,dimById:O,selectedId:N,dimOpacity:m}):null,G=e.perspective?[...L.map(e=>"ground"===t.chromePlacement?{x:e.cx-k/2,y:e.cy-I/2,width:k,height:I,z:"top"}:{x:e.cx,y:e.cy,extent:[k/2,k/2,I/2,I/2]}),...R?yi(R,{padding:null==t.hullPadding?16:Ct(t.hullPadding),label:t.hullLabel}):[]]:void 0,Y=j?{sceneNodes:T,sceneEdges:F,backgrounds:j,overlays:D,perspective:"manual"}:{sceneNodes:T,sceneEdges:F,overlays:D,perspective:"manual"};return G?{...Y,perspectiveBounds:G}:Y},Y=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}),B=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),q={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"}]},V=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,H=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),U=e=>{let t=e.config.braid,n=e.dimensions.plot,r=t.atlas.spec.comparison?.partitions??[...new Set(t.groups.map(e=>e.partition))],i=t.groups.filter(e=>r.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],l=[];if(0===i.length)return{sceneNodes:a,sceneEdges:o,labels:l};let s=new Set(i.map(e=>e.signature)),d=[...t.signatureOrder.filter(e=>s.delete(e)),...s],c=new Map(d.map((e,t)=>[e,t])),u=[...i].sort((e,t)=>c.get(e.signature)-c.get(t.signature)),h=r.map(e=>u.filter(t=>t.partition===e)),p=function(e){let t=new Map;for(let n of e){let e=Ni(n.signature);n.nodePath.forEach((r,i)=>{let o=e[i],a=t.get(o);a||(a={id:o,state:r,depth:i+1,signatures:new Set},t.set(o,a)),a.signatures.add(n.signature)})}return[...t.values()]}(u),f=ht(p.map(e=>e.depth)),m=i.map(e=>ht(e.stepEntityCounts??[e.entityCount])),g=ht(m),y=e=>e<=0?0:Math.max(1,10*e/g),x=new Map(i.map((e,t)=>[e.id,y(m[t])])),b=n.height/r.length,{semantic:w}=e.theme,M=(e,t,n,r={})=>l.push({x:e,y:t,text:n,fill:w.text??"#333",fontSize:10,anchor:"middle",...r}),v={sourceRevision:t.atlas.provenance.sourceRevision,analysisRevision:t.atlas.analysisRevision,relationScopeId:"directed-admitted"},k=new Map(p.map(e=>{let t=h.map(t=>t.reduce((t,n)=>t+(e.signatures.has(n.signature)?x.get(n.id)+3:0),5));return[e.id,ht(t,24)]})),I=ht([...k.values()],24),$=Math.min(n.width/4,I/2+16),S=(n.width-2*$)/Math.max(f-1,1),N=e=>n.x+$+(e-1)*S,A=48+I/2,E=22+I/2,C=(e,t)=>e+A+(c.get(t)+.5)*Math.max(0,b-A-E)/d.length,O=(t,n,r,i,a)=>{let l=V(n,i),s=V(n,a),d=y(l),c=y(s);if(0===d&&0===c)return;let u=d!==c,h=e.resolveColor(n.signature);o.push({type:"curved",id:r,pathD:u?$i(t,d,c):Ur(t,8),style:{fill:u?h:"none",fillOpacity:1,stroke:u?"none":h,strokeWidth:u?0:d},datum:{...v,id:r,kind:"braid-track",nodeId:n.nodePath[a],fromNodeId:n.nodePath[i],groupId:n.id,signature:n.signature,partition:n.partition,entityCount:n.entityCount,fromStep:i,toStep:a,fromCount:l,toCount:s,falseRoot:!1},accessibleDatum:{journey:n.nodePath.join(" → "),partition:n.partition??"all",fromStep:i+1,toStep:a+1,fromCount:l,toCount:s}})};return r.forEach((e,t)=>{let r=n.y+t*b,i=h[t];if(e&&M(n.x+8,r+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===i.length)return;for(let e=1;e<=f;e++)M(N(e),r+34,`Step ${e}`);let o=new Map;for(let t of p){let n=i.filter(e=>t.signatures.has(e.signature));if(0===n.length)continue;let l=N(t.depth),s=Ot([...t.signatures].map(e=>C(r,e))),d=Si(n.map(e=>x.get(e.id)));o.set(t.id,new Map(n.map((e,t)=>[e.id,{x:l,y:s+d[t],offset:d[t]}])));let c=k.get(t.id),u={state:t.state,step:t.depth,partition:e??"all"},h=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:h,cx:l,cy:s,size:c,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:q,accent:w.border??"#888",style:{fill:w.surface??"#fff"},datum:{...v,id:h,nodeId:t.state,kind:"braid-step",prefixId:t.id,...u},accessibleDatum:u}),M(l,s+c/2+12,t.state,{anchorPoint:[l,s]})}for(let t of i){let n=Ni(t.signature);for(let r=1;r<n.length;r++){let i=o.get(n[r-1]).get(t.id),a=o.get(n[r]).get(t.id),l=(i.x+a.x)/2-Math.sign(a.y-i.y)*a.offset,s=Math.abs(i.y-a.y)<1e-8?[i,a]:[i,{x:l,y:i.y},{x:l,y:a.y},a];O(s,t,`step:${e??"all"}:${n[r]}:${t.id}`,r-1,r)}}}),{sceneNodes:a,sceneEdges:o,labels:l,restyle:H,restyleEdge:H}};import{NetworkPerspectiveBillboard as Ai,NetworkPerspectiveGround as Ei}from"./semiotic-network-placement.module.min.js";import{jsx as Ci,jsxs as Oi}from"react/jsx-runtime";function Ti(e,t){return e.length>t?`${e.slice(0,Math.max(1,t-1))}…`:e}function Ri(e,t,n,r,i,o,a,l){let s=t-r/2,d=n-i/2,c={fill:o,stroke:a,strokeWidth:l};switch(e){case"diamond":return Ci("polygon",{points:`${t},${d} ${t+r/2},${n} ${t},${n+i/2} ${s},${n}`,...c});case"circle":return Ci("circle",{cx:t,cy:n,r:Math.min(r,i)/2,...c});case"stadium":case"round":return Ci("rect",{x:s,y:d,width:r,height:i,rx:"stadium"===e?i/2:8,ry:"stadium"===e?i/2:8,...c});case"hexagon":{let e=Math.min(.18*r,16);return Ci("polygon",{points:`${s+e},${d} ${t+r/2-e},${d} ${t+r/2},${n} ${t+r/2-e},${n+i/2} ${s+e},${n+i/2} ${s},${n}`,...c})}case"cylinder":{let e=Math.min(.16*i,8),t=`M${s},${d+e} a${r/2},${e} 0 0 1 ${r},0`;return Oi("g",{children:[Ci("path",{d:`M${s},${d+e} a${r/2},${e} 0 0 0 ${r},0 v${i-2*e} a${r/2},${e} 0 0 1 ${-r},0 z`,...c}),Ci("path",{d:t,fill:"none",stroke:a,strokeWidth:l})]})}case"subroutine":{let e=Math.min(8,.08*r);return Oi("g",{children:[Ci("rect",{x:s,y:d,width:r,height:i,rx:3,...c}),Ci("line",{x1:s+e,y1:d,x2:s+e,y2:d+i,stroke:a,strokeWidth:l}),Ci("line",{x1:s+r-e,y1:d,x2:s+r-e,y2:d+i,stroke:a,strokeWidth:l})]})}default:return Ci("rect",{x:s,y:d,width:r,height:i,rx:4,...c})}}function Li(e,t,n,r,i){let o=Math.max(0,Math.min(i,n/2,r/2)),a=e+n,l=t+r;return`M${e+o},${t} H${a-o} A${o},${o} 0 0 1 ${a},${t+o} V${l-o} A${o},${o} 0 0 1 ${a-o},${l} H${e+o} A${o},${o} 0 0 1 ${e},${l-o} V${t+o} A${o},${o} 0 0 1 ${e+o},${t} Z`}function Fi(e,t,n,r,i){let o=t-r/2,a=n-i/2;switch(e){case"diamond":return`M${t},${a} L${t+r/2},${n} L${t},${n+i/2} L${o},${n} Z`;case"circle":{let e=Math.min(r,i)/2;return`M${t-e},${n} A${e},${e} 0 1 1 ${t+e},${n} A${e},${e} 0 1 1 ${t-e},${n} Z`}case"stadium":case"round":return Li(o,a,r,i,"stadium"===e?i/2:8);case"hexagon":{let e=Math.min(.18*r,16);return`M${o+e},${a} L${t+r/2-e},${a} L${t+r/2},${n} L${t+r/2-e},${n+i/2} L${o+e},${n+i/2} L${o},${n} Z`}case"cylinder":{let e=Math.min(.16*i,8);return`M${o},${a+e} A${r/2},${e} 0 0 1 ${o+r},${a+e} V${a+i-e} A${r/2},${e} 0 0 1 ${o},${a+i-e} Z`}case"subroutine":return Li(o,a,r,i,3);default:return Li(o,a,r,i,4)}}function Pi(e,t,n,r,i,o){let a=t-r/2,l=n-i/2;if("cylinder"===e){let e=Math.min(.16*i,8);return Ci("path",{d:`M${a},${l+e} a${r/2},${e} 0 0 0 ${r},0`,fill:"none",stroke:o,strokeWidth:1.5})}if("subroutine"===e){let e=Math.min(8,.08*r);return Ci("path",{d:`M${a+e},${l} V${l+i} M${a+r-e},${l} V${l+i}`,fill:"none",stroke:o,strokeWidth:1.5})}return null}function zi(e,t){let n=ot({nodes:e.map(e=>({id:e})),edges:e.flatMap(e=>[...t.get(e)].map(t=>({source:e,target:t})))}),r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));let i=n.length,o=Array.from({length:i},()=>new Set),a=Array.from({length:i},()=>new Set);for(let n of e){let e=r.get(n);for(let i of t.get(n)){let t=r.get(i);e!==t&&(a[e].add(t),o[t].add(e))}}let l=a.map(e=>e.size),s=l.flatMap((e,t)=>0===e?[t]:[]),d=s.length,c=o.filter(e=>0===e.size).length,u=new Int32Array(i),h=0;for(let e=0;e<s.length;e++){let t=s[e];for(let e of o[t])u[e]=Math.max(u[e],u[t]+1),h=Math.max(h,u[e]),0===--l[e]&&s.push(e)}return{sinkCount:d,sourceCount:c,layerCount:h+1,layer:new Map(e.map(e=>[e,h-u[r.get(e)]]))}}function Di(e,t=2166136261){let n=t;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return n>>>0}function ji(e){return Di(e)/4294967295}var X={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"},K=e=>{let t=e.config||{},n=e.dimensions.plot,r=t.direction??"TD",i="LR"===r||"RL"===r,o="BT"===r||"RL"===r,a=t.layerAccessor??"layer",l=t.rowAccessor??"row",s=t.labelAccessor??"label",d=t.shapeAccessor??"shape",c=t.edgeLabelAccessor??"label",u=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",p=t.textColor??"var(--semiotic-text, #e6e6e6)",f=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",m=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};let g=new Map,y=0;for(let t of e.nodes){let e=Math.round(Number(xt(t,a,0)));y=Math.max(y,e);let n=g.get(e)||[];n.push(t),g.set(e,n)}let x=y+1,b=1;for(let e of g.values())e.sort((e,t)=>Number(xt(e,l,0))-Number(xt(t,l,0))),b=Math.max(b,e.length);let w=i?n.width:n.height,M=i?n.height:n.width,v=w/x,k=M/(b+1),I=Math.max(44,Math.min(t.nodeWidth??150,i?v-36:.92*k)),$=Math.max(26,Math.min(t.nodeHeight??46,i?.7*k:.5*v)),S=(i?I:$)/2+6,N=Math.max(1,w-2*S),A=e=>{let t=x>1?(o?x-1-e:e)/(x-1)*N:N/2;return(i?n.x:n.y)+S+t},E=(e,t)=>(i?n.y:n.x)+(e+1)/(t+1)*M,C=new Map,O=null!=e.perspective,T=[],R=[],L=[],F=[];for(let[e,t]of g)t.forEach((n,r)=>{let o=A(e),a=E(r,t.length),l=i?o:a,c=i?a:o,f=String(xt(n,d,"rect")),g=String(xt(n,s,n.id));C.set(n.id,{cx:l,cy:c,shape:f});let y={id:n.id,name:g,type:X[f]??"process",shape:f},x=Ti(g,Math.max(4,Math.floor((I-12)/7)));if(O){let e="diamond"===f?m:h;T.push({type:"rect",x:l-I/2,y:c-$/2,w:I,h:$,style:{fill:u,stroke:e,strokeWidth:1.5},_hitPath:{pathD:Fi(f,l,c,I,$),transform:[0,0,1,1],fill:!0,strokeWidth:0},datum:y,id:n.id,label:g}),L.push({x:l,y:c,text:x,anchor:"middle",baseline:"middle",fontSize:13,fill:p,anchorPoint:[l,c]});let t=Pi(f,l,c,I,$,e);return void(t&&F.push(Ci("g",{children:t},`n-${n.id}`)))}T.push({type:"rect",x:l-I/2,y:c-$/2,w:I,h:$,style:{fill:"transparent",stroke:"transparent"},datum:y,id:n.id,label:g}),F.push(Oi("g",{children:[Ri(f,l,c,I,$,u,"diamond"===f?m:h,1.5),Ci("text",{x:l,y:c,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:p,style:{pointerEvents:"none"},children:x})]},`n-${n.id}`))});let P=[];e.edges.forEach((e,t)=>{let n="string"==typeof e.source?e.source:e.source.id,r="string"==typeof e.target?e.target:e.target.id,o=C.get(n),a=C.get(r);if(!o||!a)return;let l=i?o.cx+I/2:o.cx,s=i?o.cy:o.cy+$/2,d=i?a.cx-I/2:a.cx,u=i?a.cy:a.cy-$/2,m=i?`M${l},${s} C${(l+d)/2},${s} ${(l+d)/2},${u} ${d},${u}`:`M${l},${s} C${l},${(s+u)/2} ${d},${(s+u)/2} ${d},${u}`,g=Math.atan2(u-s,d-l),y=d-9*Math.cos(g),x=u-9*Math.sin(g),b=4.5*-Math.sin(g),w=4.5*Math.cos(g),M=`${d},${u} ${y+b},${x+w} ${y-b},${x-w}`,v=xt(e,c,void 0),k=(l+d)/2,S=(s+u)/2;O&&R.push({type:"curved",pathD:m,style:{stroke:f,strokeWidth:1.4,fill:"none"},datum:e.data??e}),P.push(Oi("g",{children:[!O&&Ci("path",{d:m,fill:"none",stroke:f,strokeWidth:1.4}),Ci(Ei,{z:"top",children:Ci("polygon",{points:M,fill:f})}),"string"==typeof v&&v.length>0&&Ci(Ai,{x:k,y:S,children:Oi("g",{children:[Ci("rect",{x:k-6.5*v.length/2-4,y:S-9,width:6.5*v.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),Ci("text",{x:k,y:S,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:p,style:{pointerEvents:"none"},children:v})]})})]},`e-${t}`))});let z=Oi("g",{className:"mermaid-dag",children:[P,O?Ci(Ei,{z:"top",children:F}):F]});return O?{sceneNodes:T,sceneEdges:R,labels:L,overlays:z,perspective:"manual"}:{sceneNodes:T,overlays:z}};import{NetworkPerspectiveBillboard as _i,NetworkPerspectiveGround as Wi}from"./semiotic-network-placement.module.min.js";import{jsx as Gi,jsxs as Yi}from"react/jsx-runtime";function Bi(e){return Gi("rect",{className:e.className,x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height),rx:e.radius??10,ry:e.radius??10,fill:e.fill??"none",stroke:e.stroke,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray,opacity:e.opacity??.6,style:{pointerEvents:"none"}},e.keyId)}function qi(e,t=0){let n=1/0,r=1/0,i=-1/0,o=-1/0;for(let t of e){let e=t.r??0;t.x-e<n&&(n=t.x-e),t.x+e>i&&(i=t.x+e),t.y-e<r&&(r=t.y-e),t.y+e>o&&(o=t.y+e)}return Number.isFinite(n)?{x:n-t,y:r-t,width:i-n+2*t,height:o-r+2*t}:null}function Vi(e,t=0){if(!e.length)return null;let n="number"==typeof t?t:t.x??0,r="number"==typeof t?t:t.y??0,i=1/0,o=1/0,a=-1/0,l=-1/0;for(let t of e){if(!(Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)))continue;let e=Math.max(0,t.width),n=Math.max(0,t.height);t.x<i&&(i=t.x),t.y<o&&(o=t.y),t.x+e>a&&(a=t.x+e),t.y+n>l&&(l=t.y+n)}return Number.isFinite(i)?{x:i-n,y:o-r,width:a-i+2*n,height:l-o+2*r}:null}function Hi(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:Gi("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)}function Ui(e){let t=e.spacing??8,n=e.color??"currentColor";return{def:Gi("pattern",{id:e.id,width:t,height:t,patternUnits:"userSpaceOnUse",patternTransform:`rotate(${e.angle??45})`,children:Gi("line",{x1:0,y1:0,x2:0,y2:t,stroke:n,strokeWidth:e.strokeWidth??1,opacity:e.opacity??.5})},e.id),fill:`url(#${e.id})`}}function Xi(e){let t=e.orient??"bottom",n="bottom"===t||"top"===t,r=e.offset??0,i=e.tickLength??6,o=e.gridLength??0,a=e.labelGap??4,l=e.fontSize??11,s=e.color??"var(--semiotic-text-secondary, #888)",d=e.gridColor??s,c=e.format??(e=>String(e)),u="top"===t||"left"===t?-1:1,h=e.ticks.length-1,p=e.ticks.map((p,f)=>{let m,g=e.scale(p),y=r+u*i,x=r-u*o,b=y+u*a;m=e.labelAnchor?e.labelAnchor:n?e.edgeAnchor&&0===f?"start":e.edgeAnchor&&f===h?"end":"middle":"left"===t?"end":"start";let w=n?"top"===t?"auto":"hanging":"middle",M=n?{x:g,y:b}:{x:b,y:g};return Yi("g",{children:[(i>0||o>0)&&Gi("line",{...n?{x1:g,x2:g,y1:y,y2:x}:{x1:y,x2:x,y1:g,y2:g},stroke:o>0?d:s,strokeWidth:1,strokeDasharray:o>0?e.gridDasharray:void 0,opacity:o>0?.7:1}),Gi("text",{x:M.x,y:M.y,textAnchor:m,dominantBaseline:w,fontSize:l,fontWeight:e.fontWeight,fill:s,children:c(p)})]},`tick-${p}-${f}`)});return Gi("g",{className:e.className,style:{pointerEvents:"none"},children:p},e.keyId)}function Ki(e){let t,n=e.stroke??"var(--semiotic-text, #f4f4f8)",r=e.strokeWidth??1,i=e.markRadius??0,o=e.labelX-e.markX,a=e.labelY-e.markY,l=Math.hypot(o,a)||1,s=e.markX+o/l*i,d=e.markY+a/l*i;return t="elbow"===e.connector?`M${s},${d} L${s},${e.labelY} L${e.labelX},${e.labelY}`:"curve"===e.connector?`M${s},${d} Q${(s+e.labelX)/2},${d} ${e.labelX},${e.labelY}`:`M${s},${d} L${e.labelX},${e.labelY}`,Yi("g",{className:e.className,style:{pointerEvents:"none"},children:[i>0&&Gi("circle",{cx:e.markX,cy:e.markY,r:i,fill:"none",stroke:n,strokeWidth:r}),Gi("path",{d:t,fill:"none",stroke:n,strokeWidth:r}),Gi("text",{x:e.labelX,y:e.labelY,textAnchor:e.labelAnchor??"middle",dominantBaseline:e.labelBaseline??"hanging",fontSize:e.fontSize??11,fontWeight:e.fontWeight,fill:e.color??n,children:e.label})]},e.keyId)}import{jsx as Ji,jsxs as Zi}from"react/jsx-runtime";function Qi(e,t,n){return`M${e},${t-n} L${e+n},${t} L${e},${t+n} L${e-n},${t} Z`}function eo(e,t,n={}){let r=n.fingerprintRounds??3,i=[],o=new Set;for(let t of e)null==t.id||o.has(t.id)||(o.add(t.id),i.push(t.id));let{components:a}=lo(i,t,r),l=a.map(e=>({ids:[...e.ids],nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:oo(e)})),s=new Map;for(let e of l){let t=s.get(e.motif);t?t.count+=1:s.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:l,motifs:[...s.values()].sort((e,t)=>t.count-e.count),directedCount:l.filter(e=>e.directed).length,branchingCount:l.filter(e=>!e.directed).length}}function to(e){return Di(e).toString(36)}function no(e){return"string"==typeof e?e:e?.id}function ro(e,t,n,r,i){let o=new Set(e),a=new Map;for(let r of e){let e=0,i=0;for(let e of t.get(r)??[])o.has(e)&&(i+=1);for(let t of n.get(r)??[])o.has(t)&&(e+=1);a.set(r,`${e}:${i}`)}for(let r=0;r<i;r+=1){let r=new Map;for(let i of e){let e=[];for(let n of t.get(i)??[])o.has(n)&&e.push(a.get(n));let l=[];for(let e of n.get(i)??[])o.has(e)&&l.push(a.get(e));e.sort(),l.sort(),r.set(i,to(`${a.get(i)}>${e.join(",")}<${l.join(",")}`))}a=r}let l=e.map(e=>a.get(e)).sort();return to(`${e.length}#${r}#${l.join(";")}`)}function io(e,t,n,r,i){let{layer:o,layerCount:a}=e,l=Array.from({length:a},()=>[]);for(let t of e.ids)l[o.get(t)].push(t);let s=.14*Math.min(r.width,r.height),d=Math.max(1,r.width-2*s),c=Math.max(1,r.height-2*s),u=new Map,h=new Set(e.ids);for(let e=0;e<a;e+=1){let t=l[e];e>0&&(t=[...t].sort((e,t)=>p(e)-p(t)));let n=t.length,i=r.y+s+(1===a?.5:e/(a-1))*c;t.forEach((e,t)=>{let o=r.x+s+(1===n?.5:t/(n-1))*d;u.set(e,{x:o,y:i})})}function p(e){let t=0,i=0;for(let r of n.get(e)??[]){let e=u.get(r);h.has(r)&&e&&(t+=e.x,i+=1)}return i>0?t/i:r.x+d/2}let f=l.reduce((e,t)=>Math.max(e,t.length),1),m=gt(Math.min(i,d/(2.4*f),c/(2.4*a)),1.4,i),g=e.ids.map(e=>{let t=u.get(e);return{id:e,cx:t.x,cy:t.y,r:m,datum:At({id:e}),category:""}}),y=[];for(let n of e.ids){let e=u.get(n);for(let r of t.get(n)??[]){if(!h.has(r))continue;let t=u.get(r);y.push({source:n,target:r,x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:g,edges:y}}function oo(e){let{nodeCount:t,edgeCount:n,sinkCount:r,sourceCount:i}=e;return 1===t?"isolate":2===t&&1===n?"pair":1===i&&1===r&&n===t-1?`chain of ${t}`:e.directed&&1===i&&n>t-1?"diamond / mesh":e.directed?`converging (${t})`:`branching → ${r}`}function ao(e,t,n,r,i){let o=new Set,a=[];for(let l of e){if(o.has(l))continue;let e=[l];o.add(l);let s=[];for(;e.length;){let t=e.pop();s.push(t);for(let n of r.get(t)??[])o.has(n)||(o.add(n),e.push(n))}s.sort();let d=zi(s,t),{sinkCount:c,sourceCount:u}=d,h=0;for(let e of s)h+=t.get(e).size;a.push({...d,ids:s,nodeCount:s.length,edgeCount:h,sinkCount:c,sourceCount:u,directed:1===c,motif:ro(s,t,n,h,i)})}return a}function lo(e,t,n){let r=[...e].sort(),i=t.map(e=>[e.source,e.target]).sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:e[1]<t[1]?-1:e[1]>t[1]?1:0),o=JSON.stringify([n,r,i]);return J.getOrCompute(o,()=>{let{outAdj:e,inAdj:t,undirected:a}=function(e,t){let n=new Set(e),r=new Map,i=new Map,o=new Map;for(let t of e)r.set(t,new Set),i.set(t,new Set),o.set(t,new Set);for(let e of t){let t=e.source,a=e.target;!n.has(t)||!n.has(a)||t===a||r.get(t).has(a)||(r.get(t).add(a),i.get(a).add(t),o.get(t).add(a),o.get(a).add(t))}return{outAdj:r,inAdj:i,undirected:o}}(r,i.map(([e,t])=>({source:e,target:t})));return{key:o,outAdj:e,inAdj:t,components:ao(r,e,t,a,n)}})}function so(e,t,n){return e?io(e,t.outAdj,t.inAdj,n,3):null}var J=/*#__PURE__*/new e(8),Z=/*#__PURE__*/new e(8),Q=e=>{let t=e.config||{},n=e.dimensions.plot;if(!e.nodes.length||n.width<=0||n.height<=0)return{sceneNodes:[]};let r=t.sourceAccessor??"source",i=t.targetAccessor??"target",o=t.labelAccessor??"label",a=t.categoryAccessor??"category",l=t.nodeRadius??4,s=t.cellGap??16,d=t.bandGap??22,c=t.headerHeight??34,u=t.minCellForFull??38,h=t.maxCellSize??120,p=t.minCellSize??12,f=t.fingerprintRounds??3,m=!1!==t.groupByMotif,g=t.sort??"frequency",y=new Map,x=new Map,b=[];for(let t of e.nodes){let e=t.id;null==e||y.has(e)||(b.push(e),y.set(e,t.data??t),x.set(e,String(xt(t,a,""))))}let w=[];for(let t of e.edges){let e=no(t.source??xt(t,r,void 0)),n=no(t.target??xt(t,i,void 0));null==e||null==n||w.push({source:e,target:n})}let{outAdj:M,inAdj:v,components:k,key:I}=lo(b,w,f),$=new Map;if(m)for(let e of k){let t=$.get(e.motif);t?t.push(e):$.set(e.motif,[e])}else $.set("all",[...k].sort((e,t)=>t.nodeCount-e.nodeCount));let S=[...$.entries()];S.sort((e,t)=>"size"===g?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===g?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);let N=It([n.x,n.y,n.width,n.height,s,d,c,u,h,p,f,m,g,l,S.map(([e,t])=>e+":"+t.length).join(","),I]),A=Z.getOrCompute(N,()=>function(e,t){let{plot:n}=t,r=n.width,i=(()=>{for(let i=Math.min(t.maxCellSize,r);i>=Math.max(1,t.minCellSize);i-=2){let o=Math.max(1,Math.floor((r+t.cellGap)/(i+t.cellGap))),a=0;for(let[,n]of e){let e=Math.ceil(n.length/o);a+=t.headerHeight+e*(i+t.cellGap)+t.bandGap}if(a<=n.height)return{cell:i,cols:o}}return null})();if(!i){let t=e.flatMap(([,e])=>e),r=Math.max(1,Math.ceil(Math.sqrt(t.length*n.width/n.height))),i=Math.ceil(t.length/r),o=n.width/r,a=n.height/i;return{bands:[],cells:t.map((e,t)=>({component:e,lod:"glyph",cx:n.x+(t%r+.5)*o,cy:n.y+(Math.floor(t/r)+.5)*a,glyphR:Math.min(o,a)*(e.directed?.36:.28),nodes:[],edges:[]}))}}let{cell:o,cols:a}=i,l=[],s=[],d=n.y;for(let[i,c]of e){let e=Math.ceil(c.length/a),u=d,h=u+t.headerHeight,p=o>=t.minCellForFull;c.forEach((e,r)=>{let i=r%a,s=Math.floor(r/a),d=n.x+i*(o+t.cellGap),c=h+s*(o+t.cellGap),u={x:d,y:c,width:o,height:o};if(p){let n=io(e,t.outAdj,t.inAdj,u,t.nodeRadius);l.push({component:e,lod:"full",cx:d+o/2,cy:c+o/2,glyphR:0,nodes:n.nodes,edges:n.edges})}else l.push({component:e,lod:"glyph",cx:d+o/2,cy:c+o/2,glyphR:Math.max(2.5,.36*o),nodes:[],edges:[]})});let f=so(c[0],t,{x:n.x,y:u+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});s.push({motif:i,descriptor:oo(c[0]),count:c.length,directed:c[0].directed,x:n.x,y:u,width:r,height:t.headerHeight+e*(o+t.cellGap),contentWidth:Math.min(c.length,a)*(o+t.cellGap)-t.cellGap,exemplar:f}),d=h+e*(o+t.cellGap)+t.bandGap}return{cells:l,bands:s}}(S,{plot:n,cellGap:s,bandGap:d,headerHeight:c,minCellForFull:u,maxCellSize:h,minCellSize:p,nodeRadius:l,outAdj:M,inAdj:v})),E=e.theme.semantic||{},C=t.convergeColor??E.info??"#4c78a8",O=t.branchColor??E.warning??"#e8853a",T=t.edgeColor??E.border??"#9aa0aa",R=t.colorMode??"directedness",L={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},F=t=>"motif"===R?e.resolveColor(t.motif):"category"===R||t.directed?C:O,P=[],z=[];for(let t of A.cells){let n=t.component,r=F(n);if("full"===t.lod){for(let e of t.edges){let t={type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:T,strokeWidth:1,opacity:.5*Math.max(kt(y.get(e.source),L),kt(y.get(e.target),L))},datum:null};z.push(t)}for(let n of t.nodes){let t=y.get(n.id),i=x.get(n.id),a="category"===R&&i?e.resolveColor(i):r,l={type:"symbol",cx:n.cx,cy:n.cy,size:Math.PI*n.r*n.r,symbolType:"circle",style:{fill:a,opacity:kt(t,L)},datum:t,id:n.id,label:String(xt(t,o,n.id))};P.push(l)}}else{let e=At({id:`component-${JSON.stringify(n.ids)}`,motif:n.motif,shape:oo(n),nodes:n.nodeCount,edges:n.edgeCount,sinks:n.sinkCount,sources:n.sourceCount,directedness:n.directed?"converging":"branching"}),i={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:n.directed?"circle":"diamond",style:{fill:r,opacity:n.ids.some(e=>1===kt(y.get(e),L))?1:.14,stroke:T,strokeWidth:.75},datum:e,id:String(e.id),label:oo(n)};P.push(i)}}let D=!1!==t.showExemplars,j=!1!==t.showBandLabels,_=function(e,t,n,r){if(!t)return{bands:e};let i=e=>r?(n?48:4)+Math.max(13*e.descriptor.length*.6,11*`×${e.count} · ${e.directed?"converges to 1 sink":"branches to ≥2 sinks"}`.length*.56):n?44:0,o=e.map(e=>({...e,width:Math.min(e.width,Math.max(e.contentWidth??e.width,i(e)))}));return{bands:o,bounds:o.flatMap(e=>[{x:e.x-6,y:e.y-4,width:e.width+12,height:e.height+4},{x:e.x,y:e.y,z:0,extent:[0,i(e),2,32]}])}}(A.bands,!!e.perspective,D,j),W=function(e,t){let n=[];for(let r of e){let e=r.directed?t.convergeColor:t.branchColor,i=[];if(n.push(Ji(Wi,{children:Bi({keyId:`band-${r.motif}`,x:r.x-6,y:r.y-4,width:r.width+12,height:r.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})},`ground-${r.motif}`)),t.showExemplars&&r.exemplar){let n=r.exemplar;i.push(Zi("g",{style:{pointerEvents:"none"},children:[n.edges.map((e,n)=>Ji("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},`exe-${n}`)),n.nodes.map(t=>Ji("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},`exn-${t.id}`))]},`ex-${r.motif}`))}if(t.showBandLabels){let e=r.x+(t.showExemplars?48:4);i.push(Ji("text",{x:e,y:r.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:r.descriptor},`bl-${r.motif}`)),i.push(Ji("text",{x:e,y:r.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${r.count} · ${r.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},`bc-${r.motif}`))}i.length&&n.push(Ji(_i,{x:r.x,y:r.y,z:0,children:i},`header-${r.motif}`))}if(t.showLegend){let e=t.plot.x+t.plot.width-168,r=t.plot.y-2;n.push(Zi("g",{style:{pointerEvents:"none"},children:[Ji("circle",{cx:e,cy:r,r:5,fill:t.convergeColor}),Ji("text",{x:e+10,y:r+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),Ji("path",{d:Qi(e,r+18,5),fill:t.branchColor}),Ji("text",{x:e+10,y:r+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}return Ji("g",{className:"net-ensemble-overlays",children:n})}(_.bands,{convergeColor:C,branchColor:O,edgeColor:T,plot:n,showBandLabels:j,showExemplars:D,showLegend:!1!==t.showLegend&&"directedness"===R,textColor:E.text??"var(--semiotic-text, #1a1a1a)",subText:E.textSecondary??"var(--semiotic-text-secondary, #888)"});return{sceneNodes:P,sceneEdges:z,overlays:W,perspective:"manual",..._.bounds?{perspectiveBounds:_.bounds}:{}}};import*as co from"react";import{NetworkPerspectiveGround as uo}from"./semiotic-network-placement.module.min.js";function ho(e){return bt(e)??e}function po(e){return"string"==typeof e?e:e.id}function fo(e,t){let n=Number(e);return Number.isFinite(n)&&n>0?n:t}function mo(e){return String(Math.round(100*e)/100)}function go(e,t){if(e.length<2)return"";let n=`M${mo(e[0][0])},${mo(e[0][1])}`;for(let r=1;r<e.length-1;r+=1){let i=e[r-1],o=e[r],a=e[r+1],l=Math.hypot(o[0]-i[0],o[1]-i[1]),s=Math.hypot(a[0]-o[0],a[1]-o[1]),d=Math.min(t,l/2,s/2);if(d<=0){n+=`L${mo(o[0])},${mo(o[1])}`;continue}let c=[(o[0]-i[0])/l,(o[1]-i[1])/l],u=[(a[0]-o[0])/s,(a[1]-o[1])/s],h=[o[0]-c[0]*d,o[1]-c[1]*d],p=[o[0]+u[0]*d,o[1]+u[1]*d];n+=`L${mo(h[0])},${mo(h[1])}Q${mo(o[0])},${mo(o[1])} ${mo(p[0])},${mo(p[1])}`}let r=e[e.length-1];return`${n}L${mo(r[0])},${mo(r[1])}`}function yo(e,t,n,r,i=.92*r){let o=Math.cos(n),a=Math.sin(n),l=-a,s=[e+o*r*.56,t+a*r*.56],d=e-o*r*.44,c=t-a*r*.44,u=[d+l*i*.5,c+o*i*.5],h=[d-l*i*.5,c-o*i*.5];return`M${mo(s[0])},${mo(s[1])}L${mo(u[0])},${mo(u[1])}L${mo(h[0])},${mo(h[1])}Z`}function xo(e,t){return e.length<=t?e:`${e.slice(0,Math.max(1,t-1))}…`}function bo(e,t){return`${t}\0${e}`}function wo(e,t){return Math.max(1,e-2*Math.max(0,t.portPadding??4))}function Mo(e,t,n){if(e<=1)return 0;let r=Math.max(0,n.flowGap??.75),i=wo(t,n),o=Math.min(.1,i);return Math.min(r,Math.max(0,(i-o)/(e-1)))}function vo(e,t,n){let r="function"==typeof t?t(e):xt(e,t,n);return null==r||""===r?n:String(r)}function ko(e,t){let n="function"==typeof t?t(e):xt(e,t,void 0);if(null!=n){if("object"==typeof n){let e=n.id;return null==e?void 0:String(e)}return String(n)}}function Io(e,t){let n="function"==typeof t?t(e):xt(e,t,1);return Number(n)}function $o(e,t){if(!t.has(e))return t.add(e),e;let n=2;for(;t.has(`${e}-${n}`);)n+=1;let r=`${e}-${n}`;return t.add(r),r}function So(e,t,n={}){let r=n.nodeIdAccessor??"id",i=n.groupAccessor??"group",o=n.labelAccessor??"label",a=n.sourceAccessor??"source",l=n.targetAccessor??"target",s=n.valueAccessor??"value",d=new Set(n.expandedGroups??[]),c=n.includeInternalFlows??!0,u=[],h=new Map,p=new Map;for(let t of e){let e=vo(t,r,String(u.length));if(h.has(e))continue;let n=vo(t,o,e),a=vo(t,i,e),l={id:e,label:n,group:a,datum:t};u.push(l),h.set(e,l);let s=p.get(a);s?s.push(l):p.set(a,[l])}let f=new Set(u.map(e=>e.id)),m=[],g=new Map,y=new Map,x=[];for(let[e,t]of p){if(!d.has(e)&&(!0===n.collapseSingletons||t.length>1)){let r=$o(`${n.groupIdPrefix??"group:"}${e}`,f),i={id:r,label:e,group:e,aggregate:!0,memberIds:t.map(e=>e.id),memberCount:t.length,internalValue:0,incomingValue:0,outgoingValue:0};m.push(i),g.set(r,i);for(let e of t)y.set(e.id,r);x.push({group:e,nodeId:r,label:e,collapsed:!0,memberIds:[...i.memberIds],internalValue:0,incomingValue:0,outgoingValue:0});continue}for(let n of t){let t={...n.datum,id:n.id,label:n.label,group:e,aggregate:!1,memberIds:[n.id],memberCount:1,internalValue:0,incomingValue:0,outgoingValue:0};m.push(t),g.set(t.id,t),y.set(n.id,t.id)}x.push({group:e,nodeId:null,label:e,collapsed:!1,memberIds:t.map(e=>e.id),internalValue:0,incomingValue:0,outgoingValue:0})}let b=new Map(x.map(e=>[e.group,e])),w=new Map,M=0;for(let e of t){let t=ko(e,a),n=ko(e,l),r=Io(e,s),i=null==t?void 0:y.get(t),o=null==n?void 0:y.get(n);if(!i||!o||!Number.isFinite(r)||r<=0){M+=1;continue}let d=h.get(t)?.group,c=h.get(n)?.group;if(d&&c&&d===c){let e=b.get(d);e&&(e.internalValue+=r)}else{if(d){let e=b.get(d);e&&(e.outgoingValue+=r)}if(c){let e=b.get(c);e&&(e.incomingValue+=r)}}let u=w.get(i);u||(u=new Map,w.set(i,u));let p=u.get(o);p?(p.value+=r,p.edgeCount+=1,p.memberEdges.push(e)):u.set(o,{source:i,target:o,value:r,edgeCount:1,internal:i===o,memberEdges:[e]})}let v=[...w.values()].flatMap(e=>[...e.values()]);for(let e of v){let t=g.get(e.source),n=g.get(e.target);e.internal?t&&(t.internalValue+=e.value):(t&&(t.outgoingValue+=e.value),n&&(n.incomingValue+=e.value))}return{nodes:m,edges:c?v:v.filter(e=>!e.internal),groups:x,omittedEdgeCount:M}}var ee=e=>{let t=e.config??{},n=e.dimensions.plot,r=e.nodes.map((e,t)=>({id:e.id,datum:ho(e),inputIndex:t})),i=new Map(r.map(e=>[e.id,e.inputIndex])),o=new Map((t.order??[]).map((e,t)=>[String(e),t]));if(r.sort((e,t)=>{let n=o.get(e.id),r=o.get(t.id);return null!=n&&null!=r?n-r:null!=n?-1:null!=r?1:(i.get(e.id)??0)-(i.get(t.id)??0)}),0===r.length)return{sceneNodes:[],sceneEdges:[],labels:[]};let a=Math.max(0,t.padding??18),l=Math.max(1,Math.min(n.width,n.height)-2*a),s=Math.min(Math.max(1,t.maxCellSize??120),l/r.length),d=s*r.length,c=n.x+(n.width-d)/2,u=n.y+(n.height-d)/2,h=Math.max(4,Math.min(.76*s,t.nodeSize??.56*s)),p=h/2,f=r.map((e,n)=>{let r="function"==typeof t.labelAccessor?t.labelAccessor(e.datum):String(xt(e.datum,t.labelAccessor??"label",e.id));return{id:e.id,label:r,datum:e.datum,index:n,cx:c+(n+.5)*s,cy:u+(n+.5)*s}}),m=new Map(f.map(e=>[e.id,e])),g=new Map(f.map(e=>[e.id,e.index])),y=function(e,t,n){let r=new Map;for(let i of e){let e=po(i.source),o=po(i.target),a=t.get(e),l=t.get(o);if(null==a||null==l)continue;let s=ho(i),d=fo("function"==typeof n.valueAccessor?n.valueAccessor(s):xt(s,n.valueAccessor??"value",i.value??1),0);if(d<=0)continue;let c=r.get(e);c||(c=new Map,r.set(e,c));let u=c.get(o);u?(u.value+=d,u.edgeCount+=1,u.memberEdges.push(s)):c.set(o,{key:`${a}-${l}`,source:e,target:o,sourceIndex:a,targetIndex:l,value:d,edgeCount:1,memberEdges:[s],datum:s,width:1,color:""})}let i=[...r.values()].flatMap(e=>[...e.values()]);for(let e of i)e.datum=Mt(t=>{for(let[n,r]of Object.entries(e.memberEdges[0]??{}))t(n,r);t("source",e.source),t("target",e.target),t("value",e.value),t("edgeCount",e.edgeCount),t("internal",e.source===e.target),t("memberEdges",e.memberEdges)});return i}(e.edges,g,t),x=function(e,t,n){let r=new Map,i=(e,t)=>{let n=r.get(e);n?n.push(t):r.set(e,[t])};for(let t of e)i(bo(t.source,t.targetIndex>=t.sourceIndex?"out-right":"out-left"),t),i(bo(t.target,t.sourceIndex<t.targetIndex?"in-top":"in-bottom"),t);for(let[e,t]of r){let n=e.startsWith("out-");t.sort((e,t)=>(n?e.targetIndex:e.sourceIndex)-(n?t.targetIndex:t.sourceIndex)||e.key.localeCompare(t.key))}let o=wo(t,n),a=null==n.flowScale?Number.POSITIVE_INFINITY:Math.max(0,n.flowScale);if(null==n.flowScale){for(let e of r.values()){let r=e.reduce((e,t)=>e+t.value,0),i=Mo(e.length,t,n),l=Math.max(.1,o-i*Math.max(0,e.length-1));r>0&&(a=Math.min(a,l/r))}Number.isFinite(a)||(a=1)}let l=Math.max(0,n.minFlowWidth??1.25),s=Math.max(l,n.maxFlowWidth??Number.POSITIVE_INFINITY);for(let t of e)t.width=Math.min(s,Math.max(l,t.value*a));let d=1;for(let e of r.values()){let r=e.reduce((e,t)=>e+t.width,0),i=Mo(e.length,t,n),a=Math.max(.1,o-i*Math.max(0,e.length-1));r>0&&(d=Math.min(d,a/r))}if(d<1)for(let t of e)t.width*=d;return r}(y,h,t),b=function(e,t,n,r){let i=new Map;for(let[o,a]of e){let e=o.slice(o.indexOf("\0")+1),l=t.get(e);if(!l)continue;let s=o.startsWith("out-")?l.cy:l.cx,d=Mo(a.length,n,r),c=s-(a.reduce((e,t)=>e+t.width,0)+d*Math.max(0,a.length-1))/2;for(let e of a){let t=c+e.width/2,n=o.startsWith("out-");i.set(`${e.key}:${n?"source":"target"}`,t),c+=e.width+d}}return i}(x,m,h,t),w=e.theme.semantic.info??e.theme.semantic.primary??e.resolveColor("adjacency-flow"),M=e.theme.semantic.text??"var(--semiotic-text, currentColor)",v=e.theme.semantic.surface??"var(--semiotic-bg, white)",k=e.theme.semantic.border??"var(--semiotic-border, currentColor)",I=e.theme.semantic.grid??k,$=e.theme.semantic.primary??e.resolveColor("adjacency-flow-node"),S=t.valueFormat??(e=>String(Math.round(100*e)/100)),N=Math.max(0,Math.min(t.cornerRadius??10,.22*s)),A=new Map(f.map(e=>[e.id,0])),E=new Map(f.map(e=>[e.id,0])),C=[],O=[],T=[];for(let n of y){let r=m.get(n.source),i=m.get(n.target);if(!r||!i)continue;A.set(r.id,(A.get(r.id)??0)+n.value),E.set(i.id,(E.get(i.id)??0)+n.value);let o=t.colorMode??"single",a="function"==typeof t.edgeColor?t.edgeColor(n.datum):void 0;n.color=a??("string"==typeof t.edgeColor?t.edgeColor:void 0)??("source"===o?e.resolveColor(n.source):"target"===o?e.resolveColor(n.target):"edge"===o?e.resolveColor(`${n.source}→${n.target}`):w);let l,d,h,f,g,y,x,k=b.get(`${n.key}:source`)??r.cy,I=b.get(`${n.key}:target`)??i.cx;if(n.sourceIndex<n.targetIndex){let e=[r.cx+p,k],t=[I,i.cy-p];l=[e,[t[0],e[1]],t],d=t[0],h=e[1]+.68*(t[1]-e[1]),f=Math.PI/2,g=t[0]-N-4,y=e[1]-n.width/2-3,x="end"}else if(n.sourceIndex>n.targetIndex){let e=[r.cx-p,k],o=[I,i.cy+p];l=[e,[o[0],e[1]],o],d=o[0],h=e[1]+.68*(o[1]-e[1]),f=-Math.PI/2,g=o[0]+N+4,y=e[1]+n.width/2+(t.valueFontSize??10),x="start"}else{let e=c+(r.index+1)*s,t=u+(r.index+1)*s,o=Math.max(2,Math.min(6,.07*s)),a=Math.max(r.cx+p+2,e-o),m=Math.max(r.cy+p+2,t-o),b=[r.cx+p,k],w=[I,i.cy+p];l=[b,[a,b[1]],[a,m],[w[0],m],w],d=(a+w[0])/2,h=m,f=Math.PI,g=a-3,y=m-n.width/2-3,x="end"}let $=go(l,N);if(T.push({type:"curved",id:`adjacency-flow-${n.key}`,label:`${r.label} to ${i.label}: ${S(n.value,n.datum)}`,pathD:$,style:{fill:"none",stroke:n.color,strokeWidth:n.width,opacity:.82,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${r.label} to ${i.label}, ${S(n.value,n.datum)}`,tableFields:{source:r.label,target:i.label,value:n.value,edges:n.edgeCount}}}),(t.showValues??!0)&&O.push({x:g,y:y,text:S(n.value,n.datum),anchor:x,fontSize:t.valueFontSize??Math.max(7,Math.min(10,.14*s)),fontWeight:650,fill:M,stroke:v,strokeWidth:3,paintOrder:"stroke"}),t.showArrows??!0){let e=Math.min(Math.max(0,t.arrowSize??14),Math.max(0,n.width-2));if(e<=2)continue;let r=Math.max(3,1.08*e);C.push(co.createElement("path",{key:`arrow-${n.key}`,className:"semiotic-adjacency-flow-arrow",d:yo(d,h,f,r,e),fill:t.arrowColor??"var(--semiotic-adjacency-flow-arrow-fill, rgba(255, 255, 255, 0.72))",stroke:"none","data-edge-width":n.width,"data-arrow-width":e,"aria-hidden":!0,focusable:!1,pointerEvents:"none",opacity:1}))}}let R=f.map(n=>{let r=("function"==typeof t.nodeColor?t.nodeColor(n.datum,n.index):void 0)??("string"==typeof t.nodeColor?t.nodeColor:"source"===(t.colorMode??"single")?e.resolveColor(n.id):$);return{type:"rect",id:n.id,label:n.label,x:n.cx-p,y:n.cy-p,w:h,h:h,style:{fill:r,stroke:t.nodeStroke??k,strokeWidth:1.25,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${n.label}, step ${n.index+1}`,tableFields:{step:n.index+1,node:n.label,incoming:E.get(n.id)??0,outgoing:A.get(n.id)??0}}}}),L=Math.max(2,t.maxLabelLength??14),F=f.map(e=>({x:e.cx,y:e.cy,text:xo(e.label,L),anchor:"middle",baseline:"middle",fontSize:t.labelFontSize??Math.max(6,Math.min(15,.34*h,h/Math.max(1.8,.62*e.label.length))),fontWeight:750,fill:t.nodeTextColor??v})),P=null;if(t.showGrid??!0){let e=[];for(let t=0;t<=f.length;t+=1){let n=c+t*s,r=u+t*s;e.push(co.createElement("line",{key:`grid-v-${t}`,x1:n,y1:u,x2:n,y2:u+d,stroke:I,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}),co.createElement("line",{key:`grid-h-${t}`,x1:c,y1:r,x2:c+d,y2:r,stroke:I,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}))}P=co.createElement(uo,null,...e)}return{sceneEdges:T,sceneNodes:R,labels:[...O,...F],backgrounds:P,overlays:co.createElement(uo,{z:"top"},...C),perspective:"manual",...e.perspective&&P?{perspectiveBounds:[{x:c,y:u,width:d,height:d}]}:{}}};import{NetworkPerspectiveBillboard as No,NetworkPerspectiveGround as Ao}from"./semiotic-network-placement.module.min.js";function Eo(e,t){let n=t.showEnclosures?e.enclosures.map(e=>({x:e.x,y:e.y,width:e.w,height:e.h})):[];if(t.showColumnHeaders)for(let r of e.colBands){let e=te((t.columnLabel??String)(r.col),t.headerFontSize)/2;n.push({x:r.x+r.w/2,y:t.headerY,z:0,extent:[e,e,t.headerFontSize,4]})}if(t.showRowLabels)for(let[r,i]of e.rowLabelY){let e=te((t.rowLabel??String)(r),t.labelFontSize);n.push({x:t.labelX,y:i,z:0,extent:[e,0,t.labelFontSize,t.labelFontSize]})}for(let e of t.callouts){let t=te("string"==typeof e.label?e.label:"",e.fontSize??11)/2,r=e.labelX-e.markX,i=e.labelY-e.markY;n.push({x:e.markX,y:e.markY,extent:[Math.max(0,t-r),Math.max(0,r+t),Math.max(0,14-i),Math.max(0,i)]})}return n}var te=(e,t)=>e.length*t*.6;import{jsx as Co,jsxs as Oo}from"react/jsx-runtime";function To(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();let t=String(e),n=Number(t);if(!Number.isNaN(n)&&""!==t.trim())return n;let r=Date.parse(t);return Number.isNaN(r)?NaN:r}function Ro(e,t,n){return e<t?t:e>n?n:e}function Lo(e){let t=2166136261;for(let n of e)t=Di(n.row,Di(n.col,Di(n.id,t))),t^=Math.round(8*n.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}var ne=/*#__PURE__*/new e(12),re=e=>{let t=e.config||{},n=e.dimensions.plot,i=t.columnAccessor??"column",o=t.rowAccessor??"row",a=t.sizeAccessor,l=t.colorAccessor,s=t.symbolAccessor,d=t.shadeAccessor,c=t.markerAccessor,u=t.iconAccessor,h=t.defaultSymbol??"circle",[p,f]=t.sizeRange??[2,8],m=t.shadeStrength??.72,g=t.shadeReverse??!1,y=t.rowMode??"banded",x=t.cellSizing??"proportional",b=t.proportionExponent??1,w=t.columnGap??16,M=t.rowGap??12,v=t.packPadding??1,k=t.iterations??12,I=!1!==t.showEnclosures,$=!1!==t.showColumnHeaders,S=!1!==t.showRowLabels,N=$?t.headerHeight??26:0,A=S?t.labelWidth??66:0,E=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,C=n.x+A,O=n.y+N,T=Math.max(1,n.width-A),R=Math.max(1,n.height-N-E),L=[];for(let t of e.nodes){let e=t.data??t;L.push({id:t.id,col:String(xt(t,i,"—")),row:String(xt(t,o,"—")),sizeVal:a?Number(xt(t,a,1)):1,colorKey:l?String(xt(t,l,"")):"",symVal:s?String(xt(t,s,"")):"",shadeVal:d?To(xt(t,d,null)):NaN,marker:!!c&&!!xt(t,c,!1),iconVal:u?String(xt(t,u,"")):"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===L.length)return{sceneNodes:[]};let F=1/0,P=-1/0;if(a)for(let e of L)Number.isFinite(e.sizeVal)&&(e.sizeVal<F&&(F=e.sizeVal),e.sizeVal>P&&(P=e.sizeVal));t.sizeDomain&&([F,P]=t.sizeDomain),(!Number.isFinite(F)||!Number.isFinite(P))&&(F=0,P=1);let z=e=>{if(P<=F)return(p+f)/2;let t=Math.sqrt(Ro((e-F)/(P-F),0,1));return p+t*(f-p)},D=1/0,j=-1/0;if(d)for(let e of L)Number.isFinite(e.shadeVal)&&(e.shadeVal<D&&(D=e.shadeVal),e.shadeVal>j&&(j=e.shadeVal));t.shadeDomain&&([D,j]=t.shadeDomain);let _=e=>{if(!d||!Number.isFinite(e)||j<=D)return.5;let t=Ro((e-D)/(j-D),0,1);return g?1-t:t},W=t.colorMap,G=new Map,Y=(t,n)=>{let r=G.get(t);return r||(r=St(W&&Object.prototype.hasOwnProperty.call(W,t)&&"string"==typeof W[t]&&W[t]?W[t]:e.resolveColor(t),m),G.set(t,r)),r(n)},B=new Map;if(t.symbolMap)for(let[e,n]of Object.entries(t.symbolMap))B.set(e,n);let q=0,V=t.iconMap,H=e=>u&&V&&Object.prototype.hasOwnProperty.call(V,e)?V[e]??null:null,U=e=>u?"circle":(e=>{if(!s)return h;let t=B.get(e);return t||(t=r[q%r.length],q++,B.set(e,t)),t})(e.symVal),X=t.maxAreaFraction??.4,K=0,J=new Array(L.length),Z=new Array(L.length);for(let e=0;e<L.length;e++){let t=L[e],n=z(t.sizeVal);J[e]=n,t.baseShape=U(t),t.iconShape=H(t.iconVal);let r=wn(t.baseShape,Math.PI*n*n);Z[e]=r,K+=Math.PI*r*r}let Q=X*T*R,ee=K>Q?Math.sqrt(Q/K):1;for(let e=0;e<L.length;e++){let t=L[e],n=J[e]*ee;t.size=Math.PI*n*n,t.packR=Z[e]*ee}let te=new Map,re=new Map;for(let e of L)te.set(e.col,(te.get(e.col)??0)+1),re.set(e.row,(re.get(e.row)??0)+1);let oe=t.columnOrder?.filter(e=>te.has(e))??[...te.keys()].sort((e,t)=>(te.get(t)??0)-(te.get(e)??0)),ae=t.rowOrder?.filter(e=>re.has(e))??[...re.keys()].sort((e,t)=>(re.get(t)??0)-(re.get(e)??0)),le=It([Math.round(n.x),Math.round(n.y),Math.round(n.width),Math.round(n.height),N,A,E,y,x,b,w,M,v,k,p,f,F,P,X,oe.join(","),ae.join(","),L.length,Lo(L)]),se=ne.getOrCompute(le,()=>function(e,t){let n=new Map;for(let t of e){let e=n.get(t.col);e||(e=[],n.set(t.col,e)),e.push(t)}let r=t.columnOrder.filter(e=>n.has(e)),i=t.columnGap*Math.max(0,r.length-1),o=Math.max(1,t.innerW-i),a=t.proportionExponent,l=r.map(e=>Math.pow(n.get(e).length,a)),s=l.reduce((e,t)=>e+t,0)||1,d=e=>"uniform"===t.cellSizing?o/r.length:l[e]/s*o,c=new Map,u=[],h=t.innerX;for(let e=0;e<r.length;e++)u.push({col:r[e],x:h,w:d(e)}),h+=d(e)+t.columnGap;let p=1,f=new Map,m=[],g=(e,t,n,r)=>{let i=f.get(e);i||(i={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,i)),t-r<i.minX&&(i.minX=t-r),t+r>i.maxX&&(i.maxX=t+r),n-r<i.minY&&(i.minY=n-r),n+r>i.maxY&&(i.maxY=n+r)},y=(e,n,r,i,o,a)=>{let l=e.map(e=>({id:e.id,r:e.packR})),s=function(e,t,n,r,i,o,a,l){let s=t+r/2,d=n+i/2,c=new Map,u=e.length;if(0===u)return c;if(1===u)return c.set(e[0].id,{px:s,py:d}),c;let h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(l),p=new Float64Array(u),f=0;for(let t=0;t<u;t++)p[t]=e[t].r+o,p[t]>f&&(f=p[t]);let m=Math.max(1,Math.round(Math.sqrt(u*r/Math.max(1,i)))),g=new Float64Array(u),y=new Float64Array(u),x=r/m,b=i/Math.ceil(u/m);for(let e=0;e<u;e++){let r=e%m,i=Math.floor(e/m);g[e]=t+(r+.3+.4*h())*x,y[e]=n+(i+.3+.4*h())*b}let w=Math.max(0,Math.min(a,14)),M=Math.max(1,2*f),v=new Map,k=Math.max(1,Math.ceil(r/M)+3),I=(e,t)=>(t+1)*k+(e+1);for(let e=0;e<w;e++){v.clear();for(let e=0;e<u;e++){let r=I(Math.floor((g[e]-t)/M),Math.floor((y[e]-n)/M)),i=v.get(r);i?i.push(e):v.set(r,[e])}for(let e=0;e<u;e++){let r=Math.floor((g[e]-t)/M),i=Math.floor((y[e]-n)/M);for(let t=-1;t<=1;t++)for(let n=-1;n<=1;n++){let o=v.get(I(r+t,i+n));if(o)for(let t=0;t<o.length;t++){let n=o[t];if(n<=e)continue;let r=g[n]-g[e],i=y[n]-y[e],a=p[e]+p[n],l=r*r+i*i;if(!(l>=a*a))if(l>1e-9){let t=Math.sqrt(l),o=(a-t)/2;r/=t,i/=t,g[e]-=r*o,y[e]-=i*o,g[n]+=r*o,y[n]+=i*o}else{let t=2.39996323*e;g[e]+=Math.cos(t)*p[e],y[e]+=Math.sin(t)*p[e]}}}}for(let e=0;e<u;e++){let o=p[e],a=t+o,l=t+r-o,c=n+o,u=n+i-o;g[e]=l>a?Ro(g[e],a,l):s,y[e]=u>c?Ro(y[e],c,u):d}}for(let t=0;t<u;t++)c.set(e[t].id,{px:g[t],py:y[t]});return c}(l,n,r,i,o,t.packPadding,t.iterations,p++),d=1/0,u=1/0,h=-1/0,f=-1/0;for(let e of l){let t=s.get(e.id);c.set(e.id,{px:t.px,py:t.py}),g(a,t.px,t.py,e.r),t.px-e.r<d&&(d=t.px-e.r),t.px+e.r>h&&(h=t.px+e.r),t.py-e.r<u&&(u=t.py-e.r),t.py+e.r>f&&(f=t.py+e.r)}return Number.isFinite(d)?{x:d-ie,y:u-ie,w:h-d+2*ie,h:f-u+2*ie}:null};if("banded"===t.rowMode){let i=new Map;for(let t of e)i.set(t.row,(i.get(t.row)??0)+1);let o=t.rowOrder.filter(e=>i.has(e)),l=t.rowGap*Math.max(0,o.length-1),s=Math.max(1,t.innerH-l),d=o.map(e=>Math.pow(i.get(e),a)),h=d.reduce((e,t)=>e+t,0)||1,p=new Map,m=t.innerY+t.innerH;for(let e=0;e<o.length;e++){let n="uniform"===t.cellSizing?s/o.length:d[e]/h*s,r=m-n;p.set(o[e],{y:r,h:n}),m=r-t.rowGap}r.forEach((e,t)=>{let r=wt(n.get(e),e=>e.row);for(let e of o){let n=r.get(e),i=p.get(e);!n||!i||y(n,u[t].x,i.y,u[t].w,i.h,e)}});let g=[],x=new Map;for(let e of o){let t=p.get(e);x.set(e,t.y+t.h/2);let n=f.get(e);n&&Number.isFinite(n.minX)&&g.push({x:n.minX-ie,y:n.minY-ie,w:n.maxX-n.minX+2*ie,h:n.maxY-n.minY+2*ie})}return{positions:c,enclosures:g,colBands:u,rowLabelY:x}}let x=new Map;r.forEach((e,r)=>{let i=wt(n.get(e),e=>e.row),o=t.rowOrder.filter(e=>i.has(e)),l=t.rowGap*Math.max(0,o.length-1),s=Math.max(1,t.innerH-l),d=o.map(e=>Math.pow(i.get(e).length,a)),c=d.reduce((e,t)=>e+t,0)||1,h=t.innerY+t.innerH;o.forEach((e,n)=>{let a="uniform"===t.cellSizing?s/o.length:d[n]/c*s,l=h-a,p=y(i.get(e),u[r].x,l,u[r].w,a,e);if(p){m.push(p);let t=x.get(e)??{sum:0,n:0};t.sum+=p.y+p.h/2,t.n+=1,x.set(e,t)}h=l-t.rowGap})});let b=new Map;for(let[e,t]of x)b.set(e,t.sum/t.n);return{positions:c,enclosures:m,colBands:u,rowLabelY:b}}(L,{columnOrder:oe,rowOrder:ae,innerX:C,innerY:O,innerW:T,innerH:R,rowMode:y,cellSizing:x,proportionExponent:b,columnGap:w,rowGap:M,packPadding:v,iterations:k})),de=e.selection,ce=de?.isActive?de.predicate:null,ue=t.highlight??null,he=t.dimOpacity??.16,pe=t.markStroke,fe=t.markStrokeWidth??0,me=t.markerColor??"#ffffff",ge=t.iconColor??"rgba(255,255,255,0.92)",ye=t.iconStrokeWidth??1,xe=t.iconScale??.72,be=[],we=[],Me=[];for(let e of L){let t=se.positions.get(e.id);if(!t)continue;let n=kt(e.datum,{highlight:ue,predicate:ce,dimOpacity:he}),r={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:Y(e.colorKey,_(e.shadeVal)),opacity:n,...pe?{stroke:pe,strokeWidth:fe}:{}},datum:e.datum,id:e.id,label:String(e.id)};if(be.push(r),e.iconShape){let r=Math.sqrt(e.size/Math.PI)*xe,i=wn(e.iconShape,100),o=i>0?r/i*100*(r/i):Math.PI*r*r;Me.push({x:t.px,y:t.py,size:o,shape:e.iconShape,opacity:n})}e.marker&&n>he+.001&&we.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}let ve=[];if(t.callouts&&t.callouts.length>0){let e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",r=n.y+n.height-(E>0?.45*E:9),i=[];for(let e=0;e<t.callouts.length;e++){let n=t.callouts[e],r=L.find(e=>String(e.datum[n.field])===String(n.value));if(!r)continue;let o=se.positions.get(r.id);o&&i.push({c:n,ci:e,px:o.px,py:o.py,markR:Math.sqrt(r.size/Math.PI)})}let o=i.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;o.forEach((e,t)=>{a.set(e.ci,C+(t+.5)/o.length*T)});for(let t of i){let i=t.c,o=a.get(t.ci)??t.px,l=r,s=i.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof i.at&&i.at?(o=i.at.x,l=i.at.y):"number"==typeof i.at&&(l=n.y+i.at*n.height),ve.push({keyId:`callout-${t.ci}`,markX:t.px,markY:t.py,labelX:o,labelY:l,label:i.label,connector:s,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}let ke={markerDots:we,markerColor:me,iconMarks:Me,iconColor:ge,iconStrokeWidth:ye,callouts:ve,plot:n,showEnclosures:I,showColumnHeaders:$,showRowLabels:S,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:n.y+.62*N,labelX:n.x+A-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel},Ie=function(e,t){let n=t.columnLabel??(e=>e),r=t.rowLabel??(e=>e),i=(e,t,n,r)=>Co(No,{x:t,y:n,onGround:!0,children:r},e),o=(e,t,n,r,i)=>Co(No,{x:t,y:n,z:r,children:i},e);return Oo("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[Co(Ao,{children:t.showEnclosures&&e.enclosures.map((e,n)=>Bi({keyId:`enc-${n}`,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity}))}),t.iconMarks.length>0&&Co("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,n)=>i(`ic-${n}`,e.x,e.y,Co("path",{d:xn(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity})))}),t.markerDots.length>0&&Co("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,n)=>i(`mk-${n}`,e.x,e.y,Co("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor})))}),t.showColumnHeaders&&e.colBands.map((e,r)=>o(`col-${r}`,e.x+e.w/2,t.headerY,0,Hi({keyId:`col-${r}`,text:n(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor}))),t.showRowLabels&&[...e.rowLabelY].map(([e,n])=>o(`row-${e}`,t.labelX,n,0,Hi({keyId:`row-${e}`,text:r(e),x:t.labelX,y:n,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor}))),t.callouts.map(e=>o(String(e.keyId),e.markX,e.markY,"top",Ki(e)))]})}(se,ke);return{sceneNodes:be,overlays:Ie,perspective:"manual",...e.perspective?{perspectiveBounds:Eo(se,ke)}:{}}},ie=4;import*as Fo from"react";function Po(e,t,n){let r=new Set,i=[];for(let t of e)n(t)&&!r.has(t)&&(r.add(t),i.push(t));for(let e of t)r.has(e)||i.push(e);return i}var oe=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0)return{nodes:[]};let r=yt(t.categoryAccessor),i=yt(t.stackBy),o=e=>{let n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],r=Number(n);return Number.isFinite(r)&&r>0?r:0},a=t.gutter??2,l="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",s="string"==typeof t.stackBy?t.stackBy:"stack",d="string"==typeof t.valueAccessor?t.valueAccessor:"value",c=(e,t,n)=>Mt(r=>{r("category",e),r("stack",t),r("value",n),"category"!==l&&r(l,e),"stack"!==s&&r(s,t),"value"!==d&&r(d,n)}),u=!1!==t.showCategoryLabels,h=t.labelPadding??(u?22:0),p=Math.max(0,n.height-h),f=[],m=new Map,g=[],y=new Set,x=new Map;for(let t of e.data){let e=String(r(t)),n=String(i(t)),a=o(t);m.has(e)||(f.push(e),m.set(e,0),x.set(e,new Map)),y.has(n)||(y.add(n),g.push(n)),m.set(e,(m.get(e)??0)+a);let l=x.get(e);l.set(n,(l.get(n)??0)+a)}let b=t.categoryOrder?Po(t.categoryOrder,f,e=>m.has(e)):f,w=t.stackOrder?Po(t.stackOrder,g,()=>!0):g,M=b.reduce((e,t)=>e+(m.get(t)??0),0);if(M<=0)return{nodes:[]};let v=a*Math.max(0,b.length-1),k=Math.max(0,n.width-v),I=[],$=[],S=n.x;for(let t of b){let r=m.get(t)??0,i=r/M*k;if(i<=0)continue;$.push({cat:t,x:S,w:i});let o=x.get(t),l=n.y;for(let n of w){let a=o.get(n)??0;if(a<=0)continue;let s=a/r*p;I.push({type:"rect",x:S,y:l,w:i,h:s,style:{fill:e.resolveColor(n),stroke:"none"},datum:c(t,n,a),group:n}),l+=s}S+=i+a}let N=u&&$.length>0?function(e,t,n){let r=e.map((e,r)=>Hi({keyId:`marimekko-label-${r}`,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:n}));return Fo.createElement(Fo.Fragment,null,...r)}($,n.y+p+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null;return{nodes:I,overlays:N}};import*as zo from"react";var ae=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0||0===e.data.length)return{nodes:[]};let r=Math.max(1,Ct(t.rowHeight??28)),i=Ct(t.rowGap??12),o=!1!==t.showLabels,a=o?Ct(t.labelWidth??120):0,l=!1!==t.showTicks,s=l?14:0,d=t.tickFormat??(e=>e.toLocaleString()),c=n.x+a,u=Math.max(0,n.width-a),h=yt(t.categoryAccessor),p=yt(t.valueAccessor),f=yt(t.targetAccessor),m=yt(t.rangesAccessor),g="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",y="string"==typeof t.valueAccessor?t.valueAccessor:"value",x="string"==typeof t.targetAccessor?t.targetAccessor:"target",b=t.actualColor??e.theme.semantic.primary??"#3b6cb1",w=e.theme.semantic.text??"currentColor",M=e.theme.semantic.textSecondary??"#888",v=e.theme.semantic.surface??"#e8eaed",k=e.theme.semantic.grid??"#cdd1d6",I=e.theme.semantic.border??"#a3a8af",$=t.targetColor??`var(--semiotic-text, ${w})`,S=[`var(--semiotic-surface, ${v})`,`var(--semiotic-grid, ${k})`,`var(--semiotic-border, ${I})`],N=`var(--semiotic-text, ${w})`,A=`var(--semiotic-text-secondary, ${M})`,E=[],C=e.data.map(e=>{let t=m(e),n=Array.isArray(t)?t.map(Ct).sort((e,t)=>e-t):[],r=Ct(p(e)),i=Ct(f(e));return{label:h(e),ranges:n,actual:r,target:i,maxVal:Math.max(r,i,ht(n))}}).filter(e=>e.maxVal>0),O=e=>u>0?Math.max(0,Math.floor((e+i)/(r+i+s))):0,T=Math.min(C.length,O(n.height))<e.data.length,R=C.slice(0,O(n.height-(T?18:0))).map((e,t)=>({...e,yTop:n.y+t*(r+i+s)}));for(let{yTop:e,label:t,ranges:n,actual:i,target:o,maxVal:a}of R){let l=e=>c+e/a*u,s=e=>Mt(n=>{n("metric",t),"metric"!==g&&n(g,t),e(n)}),d=c;for(let t=0;t<n.length;t++){let i=l(n[t]),o=i-d;o>0&&E.push({type:"rect",x:d,y:e,w:o,h:r,style:{fill:S[Math.min(t,S.length-1)],stroke:"none"},datum:s(e=>{e("range",t),e("rangeValue",n[t]),e("kind","range")}),group:`range-${t}`}),d=i}let h=Math.min(r,Math.max(6,Math.floor(.45*r)));E.push({type:"rect",x:c,y:e+(r-h)/2,w:l(i)-c,h:h,style:{fill:b,stroke:"none"},datum:s(e=>{e("value",i),e("kind","actual"),"value"!==y&&e(y,i)}),group:"actual"});let p=3,f=.8*r;E.push({type:"rect",x:l(o)-p/2,y:e+(r-f)/2,w:p,h:f,style:{fill:$,stroke:"none"},datum:s(e=>{e("target",o),e("kind","target"),"target"!==x&&e(x,o)}),group:"target"})}let L=[],F=Ft(n,R.length,e.data.length,"rows","Rows without positive values or enough plot space are omitted.");F&&L.push(F);for(let e=0;e<R.length;e++){let t=R[e],i=t.yTop+r/2;if(o&&L.push(Hi({keyId:`bullet-label-${e}`,text:t.label,x:n.x+a-8,y:i,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:N})),l){let n=t.yTop+r+2;for(let r=0;r<5;r++){let i=t.maxVal*r/4,o=c+i/t.maxVal*u;L.push(zo.createElement("line",{key:`bullet-tick-${e}-${r}`,x1:o,x2:o,y1:n,y2:n+3,stroke:A,strokeWidth:1}),Hi({keyId:`bullet-ticktext-${e}-${r}`,text:d(i),x:o,y:n+12,anchor:0===r?"start":4===r?"end":"middle",baseline:"auto",fontSize:10,color:A}))}}}return{nodes:E,overlays:L.length>0?zo.createElement(zo.Fragment,null,...L):null}};import{createElement as Do,Fragment as jo}from"react";import{scaleLinear as _o}from"d3-scale";var le=e=>{let t=e.config,{plot:n}=e.dimensions,r=t.fields??[];if(r.length<2||n.width<=0||n.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let i=Object.create(null);for(let n of r){let r=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,n)?t.domains[n]: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])){i[n]=[r[0],r[1]];continue}let o=1/0,a=-1/0;for(let t of e.data){let e=Number(t[n]);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);i[n]=[o-e,a+e]}else i[n]=[o,a];else i[n]=[0,1]}let o=!1!==t.showAxes,a=o?t.axisLabelPadding??24:8,l=o?18:8,s=r.map(e=>_o().domain(i[e]).range([n.y+n.height-l,n.y+a])),d=r.map((e,t)=>1===r.length?n.x+n.width/2:n.x+t/(r.length-1)*n.width),c=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,u=t.opacity??.45,h=t.strokeWidth??1.25,p=e.theme.semantic.primary??"#3b6cb1",f=t.dimmedOpacity??.08,m=t.highlightFn,g=[],y=[];for(let n of e.data){let i=c?e.resolveColor(String(c(n))):p,o=!m||m(n),a=kt(n,{predicate:m,baseOpacity:u,dimOpacity:f,brighten:.4}),l=o?y:g;for(let e=0;e<r.length-1;e++){let t=Number(n[r[e]]),c=Number(n[r[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(c))continue;let u={type:"connector",x1:d[e],y1:s[e](t),x2:d[e+1],y2:s[e+1](c),style:{stroke:i,strokeWidth:m&&o?h+.75:h,opacity:a,fill:"none"},datum:n};l.push(u)}if(t.showPoints)for(let e=0;e<r.length;e++){let t=Number(n[r[e]]);if(!Number.isFinite(t))continue;let o={type:"point",x:d[e],y:s[e](t),r:2.5,style:{fill:i,stroke:"none",opacity:Math.min(1,a+.3)},datum:n};l.push(o)}}let x=null;if(o){let o=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,c=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,u=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=n.y+a,p=n.y+n.height-l,f=[];for(let e=0;e<r.length;e++){let l=r[e],m=d[e],g=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,l)?t.tickFormat[l]:void 0,y="function"==typeof g?g:e=>e.toLocaleString();f.push(Do("line",{key:`pc-axis-line-${e}`,x1:m,x2:m,y1:h,y2:p,stroke:o,strokeWidth:1})),f.push(Hi({keyId:`pc-axis-label-${e}`,text:l,x:m,y:n.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:c}));let[x,b]=i[l],w=5;for(let t=0;t<w;t++){let n=x+(b-x)*t/(w-1),r=s[e](n);f.push(Do("line",{key:`pc-tick-${e}-${t}`,x1:m-3,x2:m+3,y1:r,y2:r,stroke:o,strokeWidth:1}),Hi({keyId:`pc-ticktext-${e}-${t}`,text:y(n),x:m+6,y:r+3,anchor:"start",baseline:"auto",fontSize:10,color:u}))}}x=Do(jo,null,...f)}return{nodes:g.concat(y),overlays:x}};import{jsx as Wo,jsxs as Go}from"react/jsx-runtime";function Yo(e,t){let n=Math.min(1,Math.max(0,t/e.height));return e.bottomRadius*(1-n)+e.topRadius*n}function Bo(e,t){return function(e,t,n){return Math.PI*n/3*(e*e+e*t+t*t)}(Yo(e,t),e.bottomRadius,t)}function qo(e,t){if(t<=0)return 0;if(t>=Bo(e,e.height))return e.height;let n=0,r=e.height;for(let i=0;i<60;i++){let i=n+(r-n)/2;Bo(e,i)<t?n=i:r=i}return n+(r-n)/2}function Vo(e,t){let n=43758.5453*Math.sin(12.9898*e+78.233);return 2*(n-Math.floor(n)-.5)*t}function Ho(e,t){if(!(t>0)||!Number.isFinite(e)||t>e)return[];if(e<2*t)return[{x:0,y:0}];let n=[],r=e-t;for(;n.length<ue;){let e=Math.min(ue,Math.floor(Math.PI*r/t));e<1&&(e=1);let i=r*Math.cos(0),o=r*Math.sin(0),a=r*Math.cos(2*Math.PI/e),l=r*Math.sin(2*Math.PI/e);Math.hypot(i-a,o-l)<2*t&&e>1&&e--;for(let t=0;t<e&&n.length<ue;t++)n.push({x:r*Math.cos(2*t*Math.PI/e),y:r*Math.sin(2*t*Math.PI/e)});let s=r-2*t;if(!(s>=t)){r>2*t&&n.length<ue&&n.push({x:0,y:0});break}r=s}return n}function Uo(e,t,n){let r=[],i=Math.min(n,ue),o=0;for(;i>0&&o<60;){let n=t*(1+2*o);if(n+t>e.height)break;let a=Ho(Yo(e,n),t),l=a.length-i,s=l>0?a.slice(Math.floor(l/2),Math.floor(l/2)+i):a,d=e.height-n;if(s.forEach((e,t)=>{r.push({x:e.x+Vo(97*o+t,.15),z:d+Vo(31*o+t,.05)})}),i-=s.length,o++,0===s.length)break}return{pearls:r,layers:o}}function Xo(e,t,n,r){if(r<=0)return[];let i=function(e,t,n){let r=n,i=0;for(;r>0&&i<60;){let n=t+se/2*(1+2*i);if(n+se/2>e.height)break;let o=Yo(e,n);if(2*o<se)break;r-=Math.max(1,Math.floor(2*o/se)),i++}return i}(e,t,r=Math.min(r,ue)),o=i*se,a=Math.max(t,n-o)+se/2,l=[],s=0;for(let t=0;t<i&&s<r;t++){let n=a+se*t,i=Yo(e,n),o=Math.max(1,Math.floor(2*i/se)),d=(2*i-o*se)/(o+1),c=-i+d,u=e.height-n-se/2-.1;for(let e=0;e<o&&s<r;e++){let n=c+(d+se)*e;l.push({cx:n+se/2,cy:u+se/2,rotation:Vo(53*t+e,10)}),s++}}return l}function Ko(e,t){let n=Number(e);return Number.isFinite(n)?n:t}function Jo(e,t){let n=Ko(e,t);return n>0?n:t}var se=1.75,de=.635,ce="#222222",ue=2e3,he={height:15.5,topRadius:4.75,bottomRadius:3.75},pe=e=>{let t=e.config,{plot:n}=e.dimensions;if(!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<=0||n.height<=0)return{nodes:[]};let r=yt(t.categoryAccessor??"name"),i=yt(t.teaVolumeAccessor??"teaVolume"),o=yt(t.bobaVolumeAccessor??"bobaVolume"),a=yt(t.iceVolumeAccessor??"iceVolume"),l=yt(t.cupHeightAccessor??"cupHeight"),s=yt(t.cupTopRadiusAccessor??"cupTopRadius"),d=yt(t.cupBottomRadiusAccessor??"cupBottomRadius"),c=yt(t.bobaRadiusAccessor??"bobaRadius"),u=Jo(t.cupWidthRatio,.82),h=e.scales.o,p=h.bandwidth(),f=Math.max(1,n.height-26-8),m=n.y+8,g=[],y=[];for(let t of e.data){let n=String(r(t)),x=h(n);if(null==x)continue;let b={height:Jo(l(t),he.height),topRadius:Jo(s(t),he.topRadius),bottomRadius:Jo(d(t),he.bottomRadius)},w=Bo(b,b.height);(!Number.isFinite(w)||w<=0)&&(b=he);let M=Jo(c(t),.6),v=Math.max(0,Ko(i(t),450)),k=Math.max(0,Ko(o(t),110)),I=Math.max(0,Ko(a(t),135)),$=Math.PI*M*M;(!Number.isFinite($)||$<=0||!Number.isFinite(k/$))&&(M=.6,$=Math.PI*M*M);let S=Math.floor(k/$),N=Math.min(k,S*$),A=Math.floor(I/5.359375),E=Math.min(I,A*se*se*se),C=v+N+E;if(!Number.isFinite(C))throw new RangeError("Boba total volume exceeds the finite numeric range");let O=qo(b,C),T=Math.min(b.height,Math.max(0,O)),R=Yo(b,T),{pearls:L,layers:F}=Uo(b,M,S),P=T,z=Xo(b,F*M*2,P,A),D=b.height-20.32,j=Math.min(0,D),_=b.height-j,W=2*(b.topRadius+1),G=Math.min(p*u/W,f/_),Y=x+p/2,B=e=>Y+e*G,q=e=>m+(e-j)*G,V=B(-(b.topRadius+1)),H=B(b.topRadius+1),U=q(j),X=q(b.height),K=At({name:n,teaVolume:v,bobaVolume:Math.round(N),iceVolume:Math.round(E),totalVolume:Math.round(C),numBobas:S,numIce:A,renderedBobas:L.length,renderedIce:z.length,kind:"boba cup"});g.push({type:"rect",x:V,y:U,w:Math.max(1,H-V),h:Math.max(1,X-U),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:K,group:n,_transitionKey:`boba-${Et(n)}`});let J=b.height-P,Z=Et(n),Q=e.resolveColor(n);y.push(Go("g",{children:[v>0?Wo("path",{d:`M${B(-R)},${q(J)} L${B(-b.bottomRadius)},${q(b.height)} L${B(b.bottomRadius)},${q(b.height)} L${B(R)},${q(J)} z`,fill:"#D2B799"}):null,L.map((e,t)=>Wo("circle",{cx:B(e.x),cy:q(e.z),r:M*G,fill:"#222222",opacity:.5},`p-${t}`)),z.map((e,t)=>Wo("rect",{x:B(e.cx)-.95*se*G/2,y:q(e.cy)-.95*se*G/2,width:.95*se*G,height:.95*se*G,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${B(e.cx)} ${q(e.cy)})`},`i-${t}`)),Wo("path",{d:`M${B(-b.topRadius)},${q(0)} L${B(-b.bottomRadius)},${q(b.height)} L${B(b.bottomRadius)},${q(b.height)} L${B(b.topRadius)},${q(0)}`,fill:"none",stroke:ce,strokeWidth:2.5}),Wo("line",{x1:B(-(b.topRadius+1)),y1:q(0),x2:B(b.topRadius+1),y2:q(0),stroke:ce,strokeWidth:3,strokeLinecap:"round"}),v>0?Wo("path",{d:`M${B(-de)},${q(D)} L${B(-de)},${q(b.height-.4)} L${B(de)},${q(b.height-1.27-.4)} L${B(de)},${q(D)} z`,fill:"#4F91CB",stroke:ce,strokeWidth:1,opacity:.78}):null,Wo("text",{x:Y,y:X+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:n}),Wo("text",{x:Y,y:X+30,textAnchor:"middle",fontSize:10,fill:Q,children:`${S} pearls${L.length<S?` (${L.length} shown)`:""}${z.length<A?` · ${z.length}/${A} ice shown`:""} · ${Math.round(C)} cm³`})]},`boba-${Z}`))}return{nodes:g,overlays:Wo("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:y})}};import{scaleLinear as Zo}from"d3-scale";function Qo(e,t){if(!e)return null;let n=function(e){if(!e)return null;let t=e[fe];return t&&t.length>0?t:null}(e);if(!n)return e(t);let r=function(e,t){if(t instanceof Date){let n=t.getTime();return Number.isFinite(n)?e.find(e=>e.label instanceof Date&&e.label.getTime()===n)?.value??null:null}if("number"==typeof t&&Number.isFinite(t)){let n=e.find(e=>"number"==typeof e.label&&e.label===t);return n?n.value:e.find(e=>e.label instanceof Date&&e.label.getTime()===t)?.value??null}return"string"==typeof t?e.find(e=>"string"==typeof e.label&&e.label===t)?.value??null:null}(n,t);return null==r?null:e(r)}function ea(e,t){let n=t.scales?.x??t.scales?.time;return n?null!=e.x?Qo(n,e.x):t.xAccessor&&null!=e[t.xAccessor]?Qo(n,e[t.xAccessor]):null:null}function ta(e,t){let n=t.scales?.y??t.scales?.value;return n?null!=e.y?Qo(n,e.y):t.yAccessor&&null!=e[t.yAccessor]?Qo(n,e[t.yAccessor]):null:null}function na(e){return null==e?null:String(e)}function ra(e,t,n){return t.stickyPositionCache?.set(e,n),n}function ia(e){return!!e&&"object"==typeof e&&me.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function oa(e,t,n){if(!e)return[];let r=Math.max(1,Math.floor(t/n)),i=[],o="";for(let t of e.split(/\s+/))t&&(o&&o.length+1+t.length>r?(i.push(o),o=t):o=o?`${o} ${t}`:t);return o&&i.push(o),i}function aa(e){return ia(e)}function la(e){return"primary"===e?.emphasis||!0===e?.defensive}function sa(e,t,n={}){if("number"==typeof n.maxAnnotations&&Number.isFinite(n.maxAnnotations))return Math.max(0,Math.floor(n.maxAnnotations));if(!(e>0&&t>0))return 1/0;let r=n.areaPerAnnotation&&n.areaPerAnnotation>0?n.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/r))}function da(e){let t,n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;let r=e?.provenance?.confidence;switch("number"==typeof r&&Number.isFinite(r)&&(t+=15*gt(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 ca(e){let{annotations:t,width:n,height:r}=e,i=Math.max(0,e.minVisible??1),o=sa(n,r,e),a=t.map((e,t)=>({annotation:e,index:t,note:aa(e)})),l=a.filter(e=>e.note);if(0===l.length||l.length<=o)return{visible:t.slice(),deferred:[],budget:o};let s=l.filter(e=>la(e.annotation)),d=l.filter(e=>!la(e.annotation)).sort((e,t)=>da(t.annotation)-da(e.annotation)||e.index-t.index),c=Math.max(0,o-s.length),u=Math.max(0,i-s.length),h=Math.min(d.length,Math.max(c,u)),p=new Set([...s.map(e=>e.index),...d.slice(0,h).map(e=>e.index)]),f=[],m=[];for(let{annotation:e,index:t,note:n}of a)!n||p.has(t)?f.push(e):m.push(e);return{visible:f,deferred:m,budget:o}}function ua(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let n="string"==typeof t.source?Object.prototype.hasOwnProperty.call(ve,t.source)?ve[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(!n&&!r||null!=e.label&&"string"!=typeof e.label)return e;let i=[n,r].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${i})`)?e:{...e,label:o?`${o} (${i})`:`(${i})`}}function ha(e){if(!pa(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,n="string"==typeof e.shortText?e.shortText:void 0,r=t??n;return!r||"string"!=typeof e.label&&null!=e.label?e:{...e,label:r}}function pa(e){return ia(e)}function fa(e,t,n,r,i){let o=e+n,a=t+r;return Math.abs(n)>Math.abs(r)?{x:n>=0?o+4:o-i.width-4,y:r<0?a-i.height:a,width:i.width,height:i.height}:{x:n>=0?o:o-i.width,y:r<0?a-i.height-4:a+4,width:i.width,height:i.height}}function ma(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function ga(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 ya(e,t,n,r,i,o,a,l){let s=ma(e,a),d=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,r){let i=Math.max(0,r-e.x),o=Math.max(0,r-e.y),a=Math.max(0,e.x+e.width-(t-r)),l=Math.max(0,e.y+e.height-(n-r));return(i+a)*e.height+(o+l)*e.width}(s,i,o,l);for(let e of n)d+=12*ga(s,e);for(let e of r)d+=4*ga(s,e);return d}function xa(e){let{annotations:t,context:n,defaultOffset:r=ye,notePadding:i=xe,markPadding:o=be,edgePadding:a=we,preserveManualOffsets:l=!0,routeLongConnectors:s=!0,connectorThreshold:d=Me,density:c,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:m,audience:g}=e,y=n.width||0,x=n.height||0,b="object"==typeof f?f:{},w=b.breakpoint??480,M=!!f&&y<=w,v=M&&!1!==b.preferShortText?t.map(ha):t,k=M&&!c?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:c,I=u||M&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),$=M&&!p?b.responsive??{minWidth:w}:p,S=M&&!m?b.cohesion:m;if(0===v.length||y<=0||x<=0)return v.slice();let N=[],A=function(e,t){return(e.pointNodes||[]).map(e=>{let n=Math.max(1,e.r||1)+t;return{x:e.x-n,y:e.y-n,width:2*n,height:2*n}})}(n,o),E=!1,C=v.map((e,t)=>{if(!pa(e))return e;let o=function(e,t,n){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&&n.pointNodes){let e=n.pointNodes.find(e=>e.pointId===r);if(e)return{x:e.x,y:e.y}}let i=e.coordinates,o=n.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&o){let e=i[0],t=i[1];if("number"==typeof e&&"number"==typeof t){let n=o([e,t]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof e.x||"number"!=typeof e.y?function(e,t,n){let r=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===r){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let r=n.pointNodes.length-1;r>=0;r--){let i=n.pointNodes[r];if(i.pointId===e.pointId)return ra(t,n,{x:i.x,y:i.y})}let r=function(e){let t=e.data;if(!t||0===t.length)return null;let n=t[t.length-1],r=e.scales?.x??e.scales?.time,i=e.scales?.y??e.scales?.value;if(!r||!i)return null;let o=e.xAccessor||"x",a=e.yAccessor||"y",l=n[o],s=n[a];if(null==l||null==s)return null;let d=Qo(r,l),c=Qo(i,s);return null==d||null==c?null:{x:d,y:c}}(n);return r?ra(t,n,r):null}if("semantic"===r){let r=function(e,t,n){let r=function(e){return na(e.provenance?.stableId??e.stableId)}(e);if(!r)return null;let i=n.pointNodes?.find(e=>na(e.pointId)===r);if(i)return ra(t,n,{x:i.x,y:i.y});let o=n.data?.find(e=>function(e){return na(e.stableId??e.id??e.provenance?.stableId)}(e)===r);if(!o)return null;let a=ea(o,n),l=ta(o,n);return null==a||null==l?null:ra(t,n,{x:a,y:l})}(e,t,n);if(r)return r}let i=null,o=null;if(null!=e.pointId&&n.pointNodes){let t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(i=t.x,o=t.y)}if((null==i||null==o)&&(i=ea(e,n),o=ta(e,n)),null!=i&&null!=o)return ra(t,n,{x:i,y:o});if("sticky"===r){let e=n.stickyPositionCache?.get(t);if(e)return e}return null}(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!o)return e;let c=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=function(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let n="number"==typeof e.wrap?e.wrap:120,r=[...oa("string"==typeof e.title?e.title:void 0,n,7),...oa("string"==typeof e.label?e.label:void 0,n,7)],i=r.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(n,7*i)+10),height:Math.max(18,16*r.length+6)}}(!0===e.defensive?ua(e):e);if(l&&function(e){return"number"==typeof e.dx||"number"==typeof e.dy}(e)){let t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e),n="number"==typeof e.dx?e.dx:t.dx,r="number"==typeof e.dy?e.dy:t.dy;return N.push(ma(fa(o.x,o.y,n,r,c),i)),e}let u=null,h=1/0;for(let e of function(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}]}(r)){let t=ya(fa(o.x,o.y,e.dx,e.dy,c),e,N,A,y,x,i,a);t<h&&(u=e,h=t)}if(!u)return e;let p=ma(fa(o.x,o.y,u.dx,u.dy,c),i);N.push(p);let f=Math.hypot(u.dx,u.dy),m=s&&f>=d&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return E=!0,{...e,dx:u.dx,dy:u.dy,...m?{connector:m}:{}}}),O=E?C:v.slice(),T=O;if(h){let e=!1,t=O.map(t=>{let n=function(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,n="number"==typeof e.dy?e.dy:0;return Math.hypot(t,n)<8?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});T=e?t:O}{let e=!1,t=T.map(t=>{if(!0!==t?.defensive)return t;let n=ua(t);return n!==t&&(e=!0),n});T=e?t:T}let R,L=new Set;if(k){let e="object"==typeof k?k:{},t=function(e){if(!e)return 1;let t=function(e){let t=e?.familiarity;if(!t)return 3;let n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?3:n.reduce((e,t)=>e+t,0)/n.length}(e);return t<=2?1.5:t>=4?.6:1}(g),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??sa(y,x,e))*t))},{deferred:r}=ca({annotations:T,width:y,height:x,...n});for(let e of r)L.add(e)}if($){let e="object"==typeof $&&"number"==typeof $.minWidth?$.minWidth:480;if(y<=e)for(let e of T)pa(e)&&"secondary"===e.emphasis&&L.add(e)}if(L.size>0)for(let e of T)!0===e?.defensive&&L.delete(e);return R=0===L.size?T:I?T.map(e=>L.has(e)?{...e,_annotationDeferred:!0}:e):T.filter(e=>!L.has(e)),S?function(e,t){let n=!1,r=e.map(e=>pa(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(n=!0,{...e,cohesion:t}):e);return n?r:e}(R,S):R}function ba(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function wa(e){let t=ba(e.tight,5),n=Math.max(t,ba(e.watch,12));return{tight:t,watch:n,comfortable:Math.max(n,ba(e.comfortable,20))}}function Ma(e={}){let{tight:t,watch:n,comfortable:r}=wa(e);return[{id:"tight",name:"Tight",label:`Tight (< ${t}%)`,max:t,color:$e.tight},{id:"watch",name:"Watch",label:`Watch (${t}% to < ${n}%)`,min:t,max:n,color:$e.watch},{id:"moderate",name:"Moderate",label:`Moderate (${n}% to < ${r}%)`,min:n,max:r,color:$e.moderate},{id:"comfortable",name:"Comfortable",label:`Comfortable (≥ ${r}%)`,min:r,color:$e.comfortable}].filter(e=>null==e.min||null==e.max||e.max>e.min)}function va(e,t={}){return Number.isFinite(e)?Ma(t).find(t=>(null==t.min||e>=t.min)&&(null==t.max||e<t.max))??null:null}function ka(e,t={}){let n=t.fuels??ke,r=!0===t.includeZero,i=[];for(let t of e)if(t&&"number"==typeof t.t)for(let e of n){let n=ba(t.fuels?.[e]);!r&&n<=0||i.push({t:t.t,fuel:e,fuelLabel:Ie[e],mw:n,ba:t.ba})}return i}function Ia(e){let t=[];for(let n of e){if(!n||"number"!=typeof n.t)continue;let e=ba(n.demandMw),r=n.forecastMw;"number"!=typeof r||!Number.isFinite(r)||t.push({t:n.t,a:e,b:r,demandMw:e,forecastMw:r,errorMw:e-r,ba:n.ba})}return t}function $a(e){let t=ba(e.demand);if(t<=0)return 0;let n=ba(e.capacityOrNetGen),r=ba(e.interchange);return(n+(r<0?-r:0)-t)/t*100}function Sa(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{let t=ba(e.demandMw),n=ba(e.netGenMw),r=$a({demand:t,capacityOrNetGen:n,interchange:e.interchangeMw}),i=Math.max(0,ba(e.fuels?.wind))+Math.max(0,ba(e.fuels?.solar));return{t:e.t,ba:e.ba,reserveMarginPct:r,netLoadMw:t-i,demandMw:t,netGenMw:n}})}function Na(e={},t={}){let n=t.field,r=n?{field:n}:{},i=t.tightHatch??{type:"hatch",background:$e.tight,stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9},o={comfortable:{fill:t.comfortableFill??$e.comfortable,fillOpacity:.85},moderate:{fill:t.moderateFill??$e.moderate,fillOpacity:.85},watch:{fill:t.watchFill??$e.watch,fillOpacity:.9},tight:{fill:i,stroke:t.tightFill??$e.tight,strokeWidth:1,fillOpacity:1}};return Ma(e).reverse().map(e=>({id:`reserve-${e.id}`,label:e.label,when:{...r,...null!=e.min?{gte:e.min}:{},...null!=e.max?{lt:e.max}:{}},style:o[e.id]}))}function Aa(e={},t={}){let{tight:n,comfortable:r}=wa(e),[i,o]=t.extent??[],a=Math.min(n,ba(i,-50)),l=Math.max(r,ba(o,Math.max(r+30,40))),s={tight:.12,watch:.1,moderate:.08,comfortable:.06};return Ma(e).map(e=>({type:"band",y0:e.min??a,y1:e.max??l,label:e.name,color:e.color,fillOpacity:s[e.id],emphasis:"secondary"}))}function Ea(e,t){if(!e.length)return null;let n=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!n.length)return null;let r=n[n.length-1];if("number"==typeof t&&Number.isFinite(t)){let e=n.filter(e=>e.t<=t);r=e.length?e[e.length-1]:n[0]}let i=ba(r.demandMw),o=ba(r.netGenMw),a="number"==typeof r.forecastMw&&Number.isFinite(r.forecastMw)?r.forecastMw:null,l=$a({demand:i,capacityOrNetGen:o,interchange:r.interchangeMw}),s={},d=null,c=0,u=0;for(let e of ke){let t=ba(r.fuels?.[e]);t<=0||(u+=t,s[e]=t,t>c&&(c=t,d=e))}if(u>0)for(let e of Object.keys(s))s[e]=s[e]/u;return{t:r.t,ba:r.ba,demandMw:i,forecastMw:a,forecastErrorMw:null==a?null:i-a,netGenMw:o,reserveMarginPct:l,topFuel:d,topFuelShare:u>0?c/u:0,topFuelMw:c,fuelShares:s}}function Ca(e,t={}){let n=t.now??Date.now(),r=t.author??"system",i=t.source??"authored-scenario";return e.map(e=>{let o=(e.start+e.end)/2,a=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:o,y:e.y??e.value,note:e.note,provenance:{author:r,authorKind:"system",source:i,basis:"rule",..."number"==typeof t.confidence&&Number.isFinite(t.confidence)?{confidence:Math.min(1,Math.max(0,t.confidence))}:{},createdAt:a,stableId:e.id,dataVersion:String(e.start)},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:n}})}function Oa(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function Ta(e,t=0){return Number.isFinite(e)?`${e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})} MW`:"—"}function Ra(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}var fe=/*#__PURE__*/Symbol.for("semiotic.heatmapBandTicks"),me=/*#__PURE__*/new Set(["label","callout","callout-circle","callout-rect","text","widget"]),ge=2e4,ye=32,xe=6,be=4,we=8,Me=72,ve={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"},ke=["naturalGas","coal","nuclear","hydro","wind","solar","other"],Ie={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},$e={tight:"var(--semiotic-danger, #c2410c)",watch:"var(--semiotic-warning, #d97706)",moderate:"var(--semiotic-info, #0891b2)",comfortable:"var(--semiotic-success, #16a34a)"};import*as La from"react";import{ticks as Fa}from"d3-array";function Pa(e,t){if("function"==typeof e)return e;let n=e??t;return e=>Number(e[n])}function za(e,t={}){let n=Pa(t.start,"start"),r=Pa(t.end,"end"),i=!1===t.sort?e.slice():e.slice().sort((e,t)=>n(e)-n(t)||r(t)-r(e)),o=new Se;return{packed:i.map(e=>({item:e,track:o.assign(n(e),r(e))})),trackCount:Math.max(1,o.count)}}function Da(e,t){let n=Pa(t.start,"start"),r=Pa(t.end,"end"),[i,o]=t.domain,a=t.step??1,l="half-open"===t.bounds;if(!Number.isFinite(i)||!Number.isFinite(o)||i>o||!Number.isFinite(a)||a<=0)return[];let s=(o-i)/a;if(s>=Number.MAX_SAFE_INTEGER||i<o&&(i+a<=i||o-a>=o))return[];let d=Math.min(.25,4*Number.EPSILON*Math.max(1,s)),c=Math.floor(s+d),u=s>Math.log2(e.length+1),h=[],p=[];if(u){for(let t of e){let e=n(t),i=r(t);e<=i&&(h.push(e),p.push(i))}h.sort((e,t)=>e-t),p.sort((e,t)=>e-t)}let f=0,m=0,g=[];for(let t=0;t<=c;t++){let y=t>0&&t===c&&Math.abs(t-s)<=d?o:i+t*a,x=0;if(u){for(;f<h.length&&h[f]<=y;)f++;for(;m<p.length&&(l?p[m]<=y:p[m]<y);)m++;x=f-m}else for(let t of e){let e=n(t),i=r(t);e<=y&&(l?y<i:y<=i)&&x++}g.push({value:y,count:x})}return g}function ja(e,t,n){let r="x"===t?"width":"height",i=new Float64Array(e.length),o=new Float64Array(e.length),a=Array.from({length:e.length},(e,t)=>t),l=0,s=()=>{for(let a=0;a<e.length;a++){let l=(e[a][r]+Math.max(0,n))/2;i[a]=e[a][t]-l,o[a]=e[a][t]+l}a.sort((e,t)=>i[e]-i[t]||e-t),l=0;for(let e=0;e<a.length;e++){let t=e+1,n=a.length;for(;t<n;){let r=t+n>>>1;i[a[r]]<=o[a[e]]?t=r+1:n=r}l+=t-e-1}};return s(),{lower:i,upper:o,order:a,update:s,get pairs(){return l}}}function _a(e,t,n,r,i=!1){let o="x"===t?"y":"x",a="x"===t?"width":"height",l="x"===t?"height":"width",s=ja(e,t,n),d=ja(e,o,n),c=new Float64Array(e.length);return()=>{c.fill(0),s.update(),i||d.update();let{order:u,lower:h,upper:p}=s.pairs<d.pairs?s:d;for(let i=0;i<u.length;i++){let s=u[i],d=e[s];for(let f=i+1;f<u.length&&h[u[f]]<=p[s];f++){let i=u[f],h=e[i];if(Math.abs(d[o]-h[o])>(d[l]+h[l])/2+n)continue;let p=h[t]-d[t]||(d.id<h.id?-.5:.5),m=(d[a]+h[a])/2+n-Math.abs(p);if(m<=0)continue;let g=m*r*Math.sign(p);c[s]-=g,c[i]+=g}}return c}}function Wa(e,t,n){let r=n?.orientation??"vertical",i=n?.bend??0,o=n?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===r){if(Math.abs(t.y-e.y)<o){let n=e.x<=t.x?1:-1,r=a(e.x,t.x)+n*(22+Math.abs(i));return`M${e.x},${e.y} Q${r},${a(e.y,t.y)} ${t.x},${t.y}`}let n=a(e.y,t.y)+i;return`M${e.x},${e.y} C${e.x},${n} ${t.x},${n} ${t.x},${t.y}`}if(Math.abs(t.x-e.x)<o){let n=e.y<=t.y?1:-1,r=a(e.y,t.y)+n*(22+Math.abs(i));return`M${e.x},${e.y} Q${a(e.x,t.x)},${r} ${t.x},${t.y}`}let l=a(e.x,t.x)+i;return`M${e.x},${e.y} C${l},${e.y} ${l},${t.y} ${t.x},${t.y}`}function Ga(e,t,n){if("vertical"===(n?.orientation??"vertical")){let n=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${n} L${t.x},${n} L${t.x},${t.y}`}let r=(e.x+t.x)/2;return`M${e.x},${e.y} L${r},${e.y} L${r},${t.y} L${t.x},${t.y}`}function Ya(e,t,n){if("vertical"===(n?.orientation??"vertical")){let n=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(n?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(n?-t.height/2:t.height/2)}}}let r=t.cx>=e.cx;return{from:{x:e.cx+(r?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(r?-t.width/2:t.width/2),y:t.cy}}}function Ba(e,t){let n=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*n:(e-((t?.count??1)-1)/2)*n}function qa(e,t){let n=1-t,r=n*n*n,i=3*n*n*t,o=3*n*t*t,a=t*t*t;return{x:r*e.p0.x+i*e.p1.x+o*e.p2.x+a*e.p3.x,y:r*e.p0.y+i*e.p1.y+o*e.p2.y+a*e.p3.y}}function Va(e,t){let n=1-t,r=3*n*n,i=6*n*t,o=3*t*t;return{x:r*(e.p1.x-e.p0.x)+i*(e.p2.x-e.p1.x)+o*(e.p3.x-e.p2.x),y:r*(e.p1.y-e.p0.y)+i*(e.p2.y-e.p1.y)+o*(e.p3.y-e.p2.y)}}function Ha(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function Ua(e,t){let n=_a(e,t?.axis??"x",t?.padding??0,t?.strength??.5)(),r=new Map;return e.forEach((e,t)=>r.set(e.id,(r.get(e.id)??0)+n[t])),r}function Xa(e,t,n=!1){if("function"==typeof e)return n?t=>e(bt(t)??t):e;let r=e??t;return e=>xt(e,r,void 0)}function Ka(e,t,n,r){return Ja(e,t,n,r,!1)}function Ja(e,t,n,r,i){let o=r.fixedAxis??"y",a=Xa(r.fixedAccessor,"fixed",i),l=e=>String(Xa(r.sourceAccessor,"source",i)(e)),s=e=>String(Xa(r.targetAccessor,"target",i)(e)),d=r.size??(()=>Ae),c=r.iterations??180,u=r.attraction??.012,h=r.anchorStrength??.003,p=r.collisionStrength??.12,f=r.collisionPadding??15,m=r.edgePadding??42,g=r.fixedPadding??16,y=r.damping??.72,x=r.spread??1,[b,w]=r.fixedDomain;if(![b,w,n.x,n.y,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return{positioned:[],byId:new Map};let M=w-b||1,v=("y"===o?n.y:n.x)+g,k=("y"===o?n.y+n.height:n.x+n.width)-g,I=("y"===o?n.x:n.y)+m,$=("y"===o?n.x+n.width:n.y+n.height)-m,S=Math.max(1,$-I),N=e.flatMap(e=>{let t=a(e);if("number"!=typeof t&&("string"!=typeof t||!t.trim()))return[];let n=Number(t),o=(e=>v+(e-b)/M*(k-v))(n);if(!Number.isFinite(n)||!Number.isFinite(o))return[];let l=bt(e)??e,s=(e=>String(Xa(r.idAccessor,"id",i)(e)))(e),{width:c,height:u}=d(l);if(![c,u].every(e=>Number.isFinite(e)&&e>0))return[];let h=I+ji(s)*S;return[{data:l,id:s,width:c,height:u,fixedValue:n,fixed:o,free:h,anchor:h}]}),A=e=>"y"===o?e.width:e.height,E=new Map(N.map((e,t)=>[e.id,t])),C=[];for(let e of t){let t=E.get(l(e)),n=E.get(s(e));void 0!==t&&void 0!==n&&C.push([t,n])}let O=N.map(e=>({id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height})),T="y"===o?"x":"y",R=_a(O,T,f,p,!0),L=new Float64Array(N.length);for(let e=0;e<c;e++){L.fill(0);for(let[e,t]of C){let n=(N[t].free-N[e].free)*u;L[e]+=n,L[t]-=n}for(let e=0;e<N.length;e++){let t=N[e];L[e]+=(t.anchor-t.free)*h,O[e][T]=t.free}let e=R();for(let t=0;t<N.length;t++){let n=N[t];n.free+=(L[t]+e[t])*y;let r=A(n)/2;n.free=Math.max(I+r,Math.min($-r,n.free))}}if(1!==x){let e=(I+$)/2;for(let t of N){let n=A(t)/2;t.free=Math.max(I+n,Math.min($-n,e+(t.free-e)*x))}}let F=N.map(e=>({data:e.data,id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:F,byId:new Map(F.map(e=>[e.id,e]))}}function Za(e){let t=0;for(let n of e)t+=Oe[n]??(n>="0"&&n<="9"?.556:(n.codePointAt(0)??0)>=11904?1:.65);return t}function Qa(e,t){return Math.max(8,Za(e)*t*1.05+1)}function el(e,t,n){if(!n)return{w:e,h:t};let r=Math.abs(n)*Math.PI/180,i=Math.cos(r),o=Math.sin(r);return{w:e*i+t*o,h:e*o+t*i}}function tl(e,t){let n=t>>>0;for(let t of e){n=Di(t.col,n);for(let e of t.rows)n=Di(`${e.text}␟${e.weight}␟${e.segment}`,n)}return(n>>>0).toString(36)}function nl(e){let t=Number(e.segmentDomain?.[0]),n=Number(e.segmentDomain?.[1]),r=Number.isFinite(t)?t:0,i=Number.isFinite(n)?n:r,o=i<r?-1:1,a=Math.abs(i-r),l=Number(e.currentSegment),s=Number.isFinite(l)?gt((l-r)*o,0,a):0,d=(e,t)=>{let n=Number(e);return Number.isFinite(n)?gt(n,0,1):t},c=d(e.oldestOpacity,.25),u=d(e.currentOpacity,1),h=d(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{let t=Number(e);if(!Number.isFinite(t))return h;let n=(t-r)*o;if(n>s)return h;if(0===s)return u;let i=gt(n/s,0,1);return c+(u-c)*i}}}var Se=class{constructor(){this.count=0,this.capacity=1,this.tree=new Float64Array(2).fill(NaN)}assign(e,t){let n;if(this.tree[1]<=e){let t=1;for(;t<this.capacity;)t*=2,this.tree[t]<=e||t++;n=t-this.capacity}else n=this.count++,n===this.capacity&&this.grow();let r=this.capacity+n;for(this.tree[r]=t;r>1;){r=Math.floor(r/2);let e=this.minimum(r);if(this.tree[r]===e)break;this.tree[r]=e}return n}minimum(e){let t=this.tree[2*e],n=this.tree[2*e+1];return t<=n||Number.isNaN(n)?t:n}grow(){let e=this.tree,t=this.capacity;this.capacity*=2,this.tree=new Float64Array(2*this.capacity).fill(NaN),this.tree.set(e.subarray(t),this.capacity);for(let e=this.capacity-1;e>0;e--)this.tree[e]=this.minimum(e)}},Ne=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0||0===e.data.length||!t?.domain)return{nodes:[]};let r=yt(t.laneAccessor),i=yt(t.startAccessor),o=yt(t.endAccessor),a=t.idAccessor?yt(t.idAccessor):null,l=t.unit??0,s=Ct(t.barGap??1.5),d=Math.max(0,t.minBarWidth??2),c=Ct(t.minBarHeight??3.5)||3.5,u=Ct(t.maxBarHeight??10)||10,h=t.cornerRadius??2,p=Ct(t.bottomInset??0),f=t.color??((t,n)=>e.resolveColor(n)),[m,g]=t.domain;if(!Number.isFinite(m)||!Number.isFinite(g)||m>g||!Number.isFinite(g-m))return{nodes:[]};let y=g-m||1,x=e=>n.x+(e-m)/y*n.width,b=e.scales?.o?.domain?.()??[],w=t.lanes??(b.length>0?b:[...new Set(e.data.map(r))]),M=Math.max(0,n.height-p)/Math.max(1,w.length);if(M<=0)return{nodes:[]};let v=Math.min(M/4,Ct(t.lanePadding??7)),k=e=>x(i(e)),I=e=>Math.max(k(e)+d,x(o(e)+l)),$=[];w.forEach((t,i)=>{let o=n.y+i*M,l=e.data.filter(e=>r(e)===t);if(0===l.length)return;let{packed:d,trackCount:p}=za(l,{start:k,end:I}),m=new Map,g=new Map;for(let{item:e,track:t}of d){let n=g.get(t);n&&m.set(n,k(e)),g.set(t,e)}let y=(M-2*v)/p,x=Math.min(u,y,Math.max(c,y-s));for(let{item:e,track:n}of d){let r=k(e),i=m.get(e),l=I(e)-r,s=void 0!==i&&r+l>i-1?Math.max(1,i-1-r):l,d=o+v+n*y;$.push({type:"rect",x:r,y:d,w:s,h:x,cornerRadii:h>0?{tl:h,tr:h,br:h,bl:h}:void 0,style:{fill:f(e,t),stroke:"none"},datum:e,group:t,_transitionKey:a?String(a(e)):void 0})}});let S=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,N=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,A=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,E=[];(t.periods??[]).forEach((e,t)=>{let r=x(e.start),i=Math.max(1,x(e.end+l)-r);E.push(La.createElement("rect",{key:`period-${t}`,x:r,y:n.y,width:i,height:n.height,fill:A,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&E.push(Hi({keyId:`period-label-${t}`,text:e.name,x:r+4,y:n.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:N}))});let C=!1!==t.showLaneLabels,O=t.laneLabelGap??12;if(w.forEach((e,t)=>{let r=n.y+t*M;E.push(La.createElement("line",{key:`lane-sep-${t}`,x1:n.x,x2:n.x+n.width,y1:r,y2:r,stroke:A,opacity:.45})),C&&E.push(Hi({keyId:`lane-label-${t}`,text:e,x:n.x-O,y:r+M/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:S}))}),!1!==t.showAxis){let e=t.axisTicks??Fa(m,g,7);E.push(Xi({keyId:"interval-axis",scale:x,ticks:e,orient:"top",offset:n.y,tickLength:0,gridLength:n.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:N}))}return{nodes:$,overlays:La.createElement(La.Fragment,null,...E)}},Ae={width:60,height:34},Ee=e=>{let{plot:t}=e.dimensions;if(t.width<=0||t.height<=0||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};let n=e.config.fixedAxis??"y",{positioned:r,byId:i}=Ja(e.nodes,e.edges,t,e.config,!0),o=r.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[],l=Xa(e.config.sourceAccessor,"source",!0),s=Xa(e.config.targetAccessor,"target",!0);e.edges.forEach((e,t)=>{let r=i.get((e=>String(l(e)))(e)),o=i.get((e=>String(s(e)))(e));if(!r||!o)return;let{from:d,to:c}=Ya({cx:r.x,cy:r.y,width:r.width,height:r.height},{cx:o.x,cy:o.y,width:o.width,height:o.height},{orientation:"y"===n?"vertical":"horizontal"});a.push({type:"curved",pathD:Wa(d,c,{orientation:"y"===n?"vertical":"horizontal",bend:Ba(t,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:bt(e)??e})});let d=r.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:o,sceneEdges:a,labels:d}},Ce=1.15,Oe={a:.556,b:.611,c:.556,d:.611,e:.556,f:.333,g:.611,h:.611,i:.278,j:.278,k:.556,l:.278,m:.889,n:.611,o:.611,p:.611,q:.611,r:.389,s:.556,t:.333,u:.611,v:.556,w:.778,x:.556,y:.556,z:.5,A:.722,B:.722,C:.722,D:.722,E:.667,F:.611,G:.778,H:.722,I:.278,J:.556,K:.722,L:.611,M:.833,N:.722,O:.778,P:.667,Q:.778,R:.722,S:.667,T:.611,U:.722,V:.667,W:.944,X:.667,Y:.667,Z:.611,"'":.278,"’":.278,"-":.333,".":.278,",":.278," ":.278},Te=class e{constructor(e){this.cell=e,this.cells=new Map}span(e,t){return[Math.floor(e/this.cell),Math.floor(t/this.cell)]}static key(e,t){return 65536*(e+32768)+(t+32768)}insert(t){let[n,r]=this.span(t.x-t.w/2,t.x+t.w/2),[i,o]=this.span(t.y-t.h/2,t.y+t.h/2);for(let a=n;a<=r;a++)for(let n=i;n<=o;n++){let r=e.key(a,n),i=this.cells.get(r);i?i.push(t):this.cells.set(r,[t])}}collides(t,n){let[r,i]=this.span(t.x-t.w/2-n,t.x+t.w/2+n),[o,a]=this.span(t.y-t.h/2-n,t.y+t.h/2+n);for(let l=r;l<=i;l++)for(let r=o;r<=a;r++){let i=this.cells.get(e.key(l,r));if(i)for(let e of i)if(Math.abs(t.x-e.x)<(t.w+e.w)/2+n&&Math.abs(t.y-e.y)<(t.h+e.h)/2+n)return!0}return!1}};import{jsx as rl,jsxs as il}from"react/jsx-runtime";function ol(e){let t=e.config,{plot:n}=e.dimensions,r={nodes:[],unplaced:[],sizeFloored:[]};if(n.width<=0||n.height<=0||0===e.data.length)return r;let i=yt(t.textAccessor),o=e=>{let n=Number(yt(t.weightAccessor)(e));return Number.isFinite(n)&&n>0?n:0},a=yt(t.columnAccessor),l=e=>Number(yt(t.segmentAccessor)(e)),s=t.minFontSize??11,d=t.maxFontSize??42,c=t.columnGutter??18,u=t.collisionPadding??2,h=!1!==t.showColumnLabels,p=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>String(Math.round(e))),g=t.rotate??0,y=!0===t.repeatWords,x=!1!==t.scaleToFit,b=t.packingDensity??.6,w="string"==typeof t.textAccessor?t.textAccessor:"word",M="string"==typeof t.weightAccessor?t.weightAccessor:"weight",v="string"==typeof t.columnAccessor?t.columnAccessor:"column",k="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",I=[],$=new Map,S=1/0,N=-1/0;for(let t=0;t<e.data.length;t++){let n=e.data[t],r=String(a(n)),s=String(i(n)),d=o(n),c=l(n);!s||!Number.isFinite(c)||($.has(r)||(I.push(r),$.set(r,[])),$.get(r).push({col:r,text:s,weight:d,segment:c,datum:n,dataIndex:t}),c<S&&(S=c),c>N&&(N=c))}if(0===I.length)return r;if(!y)for(let[e,t]of $){let n=new Map;for(let e of t){let t=n.get(e.text);(!t||e.weight>t.weight)&&n.set(e.text,e)}$.set(e,[...n.values()])}let A=1/0,E=-1/0;for(let e of $.values())for(let t of e)t.weight<A&&(A=t.weight),t.weight>E&&(E=t.weight);if(!Number.isFinite(A))return r;let C=t.columnOrder?[...t.columnOrder.filter(e=>$.has(e)),...I.filter(e=>!t.columnOrder.includes(e))]:I,O=new Map(C.map(n=>[n,t.columnColor?.(n)||e.resolveColor(n)])),[T,R]=t.segmentDomain??[S,N],L=R-T||1,F=E-A||1,P=h?22:0,z=p?52:0,D=n.x+z,j=n.y+P,_=Math.max(0,n.width-z),W=Math.max(0,n.height-P),G=C.length,Y=Math.max(0,_-c*Math.max(0,G-1)),B=G>0?Y/G:0,q=j+14,V=j+W-14,H=e=>q+(e-T)/L*(V-q),U=C.map((e,n)=>{let r=O.get(e),i=($.get(e)??[]).map((i,o)=>{let a={word:i.text,column:i.col,weight:i.weight,segment:i.segment,datum:i.datum,dataIndex:i.dataIndex,columnIndex:n,resolvedColumnColor:r},l=t.wordOpacity?Number(t.wordOpacity(a)):1,c=t.wordColor?.(a),u=`${e}::${i.text}::${o}`,h=(e=>E>0?d*Math.sqrt(e/E):0)(i.weight);return{id:u,text:i.text,weight:i.weight,segment:i.segment,baseFont:Math.max(s,h),floored:h<s,rotation:g>0?2*(ji(u+"r")-.5)*g:0,opacity:Number.isFinite(l)?gt(l,0,1):0,color:c||r,info:a}});return 0===i.length?null:{col:e,colLeft:D+n*(B+c),center:D+n*(B+c)+B/2,rows:i}}).filter(e=>null!==e),X=It([n.x,n.y,n.width,n.height,P,z,c,u,s,d,g,x,b,T,R,U.length,tl(U,2166136261),tl(U,16777619)]),K=Re.getOrCompute(X,()=>function(e){let{plans:t,colW:n,bodyH:r,yTop:i,yBot:o,segToY:a,collisionPadding:l}=e,s=n*r,d=1/0,c=1/0;for(let r of t){let t=0;for(let e of r.rows){let r=1.05*Za(e.text);t+=r*Ce*e.baseFont*e.baseFont;let i=el(r,Ce,e.rotation);c=Math.min(c,(n-8-1)/(i.w*e.baseFont))}t>0&&(d=Math.min(d,Math.sqrt(e.packingDensity*s/t)))}let u=e=>{let r=[],s=[];return t.forEach((t,d)=>{if(n<=0)return;let c=t.colLeft+4,u=t.colLeft+n-4,h=t.rows.map((t,r)=>{let i=e*t.baseFont,o=Math.max(5,i),l=el(Qa(t.text,o),o*Ce+2,t.rotation);return{rowIndex:r,id:t.id,font:o,floored:t.floored||i<5,rotation:t.rotation,w:l.w,h:l.h,anchorY:a(t.segment),seed:(ji(t.id)-.5)*Math.min(.5*n,80)}}).sort((e,t)=>t.font-e.font||(e.id<t.id?-1:1)),p=new Te(32);for(let e of h){let n=e.w/2,a=e.h/2,h=gt(t.center+e.seed,c+n,u-n),f=e.anchorY,m=null;for(let t=0;t<2600;t++){let r=3.2*Math.sqrt(t),s=2.399963229728653*t,d={x:gt(h+r*Math.cos(s),c+n,u-n),y:gt(f+r*Math.sin(s),i+a,o-a),w:e.w,h:e.h};if(!p.collides(d,l)){m=d;break}}m?(p.insert(m),r.push({planIndex:d,rowIndex:e.rowIndex,id:e.id,x:m.x,y:m.y,fontSize:e.font,rotation:e.rotation,w:e.w,h:e.h,floored:e.floored})):s.push({planIndex:d,rowIndex:e.rowIndex})}}),{placements:r,unplaced:s}},h=e.scaleToFit?Math.min(1,d,c):Math.min(1,c),p=u(h);if(e.scaleToFit)for(let e=0;e<6&&p.unplaced.length>0&&h>.1;e++)h*=.88,p=u(h);return p}({plans:U,colW:B,bodyH:W,yTop:q,yBot:V,segToY:H,collisionPadding:u,packingDensity:b,scaleToFit:x})),J=(e,t)=>U[e].rows[t],Z=K.unplaced.map(({planIndex:e,rowIndex:t})=>J(e,t).info),Q=K.placements.map(e=>{let t=J(e.planIndex,e.rowIndex),n=U[e.planIndex].col,r=Math.sqrt((t.weight-A)/F);return{id:e.id,text:t.text,x:e.x,y:e.y,w:e.w,h:e.h,fontSize:e.fontSize,rotation:e.rotation,floored:e.floored,color:t.color,opacity:t.opacity,info:t.info,datum:Mt(e=>{for(let n of Object.keys(t.info.datum))e(n,t.info.datum[n]);e("word",t.text),e("weight",t.weight),e("column",n),e("segment",t.segment),"word"!==w&&e(w,t.text),"weight"!==M&&e(M,t.weight),"column"!==v&&e(v,n),"segment"!==k&&e(k,t.segment),e("__strength",.5+.5*r)})}}),ee=Q.filter(e=>e.opacity>0);return{nodes:ee.map(e=>{let t=e.rotation?e.w:Qa(e.text,e.fontSize),n=e.rotation?e.h:e.fontSize*Ce;return{type:"rect",x:e.x-t/2,y:e.y-n/2,w:t,h:n,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:String(e.datum.column),_transitionKey:e.id}}),overlays:il("g",{className:"semiotic-word-trails","data-unplaced-count":Z.length||void 0,children:[p&&al({x:n.x+z-10,yTop:q,yBot:V,segLo:T,segHi:R,segToY:H,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:n.x}),h&&C.map((e,t)=>B<=0?null:rl("text",{x:D+t*(B+c)+B/2,y:n.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:O.get(e),style:{pointerEvents:"none"},children:e},`wt-col-${t}`)),ee.map(e=>rl("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},`wt-${e.id}`))]}),restyle:()=>{},unplaced:Z,sizeFloored:Q.filter(e=>e.floored).map(e=>e.info)}}function al(e){let t=[],n=e.segHi-e.segLo||1;for(let r=0;r<e.tickCount;r++)t.push(e.segLo+n*r/Math.max(1,e.tickCount-1));return il("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[rl("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,n)=>{let r=e.segToY(t);return il("g",{children:[rl("line",{x1:e.x-4,y1:r,x2:e.x,y2:r,stroke:e.color,strokeWidth:1,opacity:.6}),rl("text",{x:e.x-7,y:r,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},`wt-tick-${n}`)}),e.label&&rl("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}function ll(e){return null==e?void 0:String(e)}function sl(e){let t=ll(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...Le,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function dl(e){return sl(e)}function cl(e){let[[t,n],[r,i]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((r-t)*(i-n)),style:{...Le,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function ul(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Le,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:ll(e.id)}}function hl(e){let t=ll(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Le,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...Le,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function pl(e){let t={style:{...Le,cursor:e.cursor},datum:e.datum,id:ll(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?((!e.type||"curved"===e.type)&&(t.style.fill="none"),{type:e.type??"curved",pathD:e.pathD,...t}):{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function fl(e,t,n={}){let{coord:r,step:i=1,equals:o=Object.is,truthyOnly:a=!1}=n,l=[],s=t=>r?r(e[t],t):t,d=(e,t,n)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=r?null!=n&&s(n)-s(t)<=i?s(n):s(t)+i:t+1,l.push(e)},c=null;for(let n=0;n<e.length;n++){let l=t(e[n],n);if(a&&!l){c&&(d(c,c.endIndex,n),c=null);continue}let u=!(r&&n>0)||s(n)-s(n-1)<=i;c&&u&&o(c.value,l)?c.endIndex=n:(c&&d(c,c.endIndex,n),c={value:l,start:s(n),end:s(n),count:1,startIndex:n,endIndex:n})}return c&&d(c,c.endIndex,null),l}function ml(e,t,n=0){return t<=0?e:((e-n)%t+t)%t+n}function gl(e,t,n){if(n<=0)return t-e;let r=(t-e)%n;return r>n/2?r-=n:r<=-n/2&&(r+=n),r}function yl(e,t,n){return t<=n?e>=t&&e<=n:e>=t||e<=n}function xl(e,t,n,r){return n<=r?e.filter(e=>yl(t(e),n,r)):[...e.filter(e=>t(e)>=n),...e.filter(e=>t(e)<=r)]}function bl(e){let{desired:t,minGaps:n,weights:r}=e,i=t.length;if(0===i)return[];if(n.length!==Math.max(0,i-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let o=new Array(i).fill(0);for(let e=1;e<i;e++)o[e]=o[e-1]+Math.max(0,Number.isFinite(n[e-1])?n[e-1]:0);let a=[];for(let e=0;e<i;e++){let n=Math.max(Number.EPSILON,Number.isFinite(r?.[e])?r[e]:1),i=(Number.isFinite(t[e])?t[e]:0)-o[e];for(a.push({start:e,end:e,weight:n,mean:i});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.mean<=e.mean)break;let n=t.weight+e.weight;a.splice(a.length-2,2,{start:t.start,end:e.end,weight:n,mean:(t.mean*t.weight+e.mean*e.weight)/n})}}let l=Number.isFinite(e.min)?e.min:-1/0,s=Number.isFinite(e.max)?e.max-o[i-1]:1/0,d=s<l?l:s,c=new Array(i);for(let e of a){let t=Math.max(l,Math.min(d,e.mean));for(let n=e.start;n<=e.end;n++)c[n]=t+o[n]}return c}function wl(e,t){let n=0,r=e.length-1,i=-1;for(;n<=r;){let o=n+r>>>1;e[o].at<=t?(i=o,n=o+1):r=o-1}return i<0?{at:t,before:0,after:0}:e[i]}function Ml(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let n=[],r=[0];for(let i=0;i<e.length-1;i++){let o=e[i],a=e[i+1],l=[...new Set([...o.map(e=>e.at),...a.map(e=>e.at)])].sort((e,t)=>e-t),s=0;for(let e of l){let t=wl(o,e),n=wl(a,e);s=Math.max(s,t.after+n.before)}n.push(s),r.push(r[r.length-1]+s+t)}return{adjacentClearance:n,positions:r}}function vl(e,t,n,r={}){let i=[...e];if(i.length<=1)return i;let o=[...i],a=n(i),l=1,s=Math.max(0,r.passes??6),d=Math.max(1,r.maxEvaluations??1/0);for(let e=0;e<s&&l<d;e++){let e=new Map(i.map((e,t)=>[e,t])),s=new Map,d=new Map;for(let n of t){let t=e.get(n.source),r=e.get(n.target);if(null==t||null==r)continue;let i=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;s.set(n.source,(s.get(n.source)??0)+r*i),d.set(n.source,(d.get(n.source)??0)+i),s.set(n.target,(s.get(n.target)??0)+t*i),d.set(n.target,(d.get(n.target)??0)+i)}i=i.map((e,t)=>({item:e,index:t,barycenter:(s.get(e)??t)/(d.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 c=n(i);if(l++,c<a)a=c,o=[...i];else if(c===a)break}return o}function kl(e,t,n={}){let r=[...e];if(r.length<=1)return r;let i=t(r),o=1,a=Math.max(0,n.passes??6),l=Math.max(1,n.maxEvaluations??1/0);for(let e=0;e<a&&o<l;e++){let e=!1;for(let n=0;n<r.length-1&&o<l;n++){[r[n],r[n+1]]=[r[n+1],r[n]];let a=t(r);o++,a<i?(i=a,e=!0):[r[n],r[n+1]]=[r[n+1],r[n]]}if(!e)break}return r}function Il(e,t,n={}){let r=[...e],i=r.length;if(i<=1||i>(n.maxItems??8))return r;let o=Math.max(1,n.maxEvaluations??1/0),a=0,l=[...r],s=1/0,d=()=>{if(a>=o)return;let e=t(r);a++,e<s&&(s=e,l=[...r])};d();let c=new Array(i).fill(0),u=0;for(;u<i&&a<o;)if(c[u]<u){let e=u%2==0?0:c[u];[r[e],r[u]]=[r[u],r[e]],d(),c[u]++,u=0}else c[u]=0,u++;return l}function $l(e,t,n=()=>!0){let r=0;for(let i=0;i<e.length;i++){let[o,a]=t(e[i]);for(let l=i+1;l<e.length;l++){if(!n(e[i],e[l]))continue;let[s,d]=t(e[l]);(o-s)*(a-d)<0&&r++}}return r}function Sl(e,t){let n=Math.max(0,t.width),r=t.y,i=Math.min(74,Math.max(34,.08*n)),o=t.paddingLeft??i,a=t.paddingRight??i,l=Math.max(0,n-o-a),s=e.length>1?l/(e.length-1):0,d=new Map;return e.forEach((e,t)=>{d.set(e.id,{id:e.id,x:o+s*t,y:r,index:t})}),d}function Nl(e,t){let n=Math.max(0,t.width),r=t.y,i=Math.min(74,Math.max(34,.08*n)),o=t.paddingLeft??i,a=t.paddingRight??i,l=t.gap??8,s=!1!==t.distribute,d=t.estimateWidth??(e=>Al(e.label??e.id)),c=e.map((e,t)=>Math.max(1,d(e,t))),u=c.reduce((e,t)=>e+t,0)+l*Math.max(0,e.length-1),h=Math.max(0,n-o-a),p=Math.max(0,h-u),f=s&&e.length>1?p/(e.length-1):0,m=new Map,g=o;return!s&&1===e.length&&(g=o+Math.max(0,(h-c[0])/2)),e.forEach((e,t)=>{let n=c[t];m.set(e.id,{id:e.id,x:g+n/2,y:r,index:t,width:n}),g+=n+l+f}),m}function Al(e,t=38,n=7.4,r=20){return Math.max(t,String(e??"").length*n+r)}function El(e){let t=e.map(e=>{let t=Math.min(e.a,e.b),n=Math.max(e.a,e.b);return{span:e,a:t,b:n,width:n-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),n=new Se,r=t.map(e=>{let t=n.assign(e.a,e.b);return{span:e.span,level:t}}),i=Math.max(0,n.count-1);return{packed:r,maxLevel:i,levelCount:r.length?i+1:1}}function Cl(e){let t=e.labelRoom??18,n=Math.max(48,e.baselineY-e.ceilingY-28),r=Math.max(1,e.levelCount),i=Math.min(42,Math.max(26,.18*n)),o=Math.max(24,n-i-t),a=r<=1?o:o/Math.max(1,r-1);return{arcLift:i,levelStep:Math.min(72,Math.max(28,a))}}function Ol(e,t,n,r,i={}){let o=n-(i.footLift??26);return`M${e} ${o}Q${(e+t)/2} ${r} ${t} ${o}`}function Tl(e,t,n){return e-n.arcLift-t*n.levelStep}function Rl(e,t=Ll){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};let n=e.map(e=>new Set(e.map(e=>t(e)))),r=new Set;for(let e of n[0])n.every(t=>t.has(e))&&r.add(e);let i=[],o=new Set;for(let n of e[0]){let e=t(n);r.has(e)&&!o.has(e)&&(i.push(n),o.add(e))}return{shared:i,exclusive:e.map(e=>e.filter(e=>!r.has(t(e))))}}function Ll(e){if(null==e||"object"!=typeof e)return String(e);let t=e;if(null!=t.id)return String(t.id);let n=t.sourceTokenId??t.source,r=t.targetTokenId??t.target,i=t.relation??t.label??"";return`${String(n)}|${String(r)}|${String(i)}`}function Fl(e,t,n){let r=n?.center?.x??0,i=n?.center?.y??0;return{x:r+Math.sin(e)*t,y:i-Math.cos(e)*t}}function Pl(e,t,n){let r=n?.center?.x??0,i=n?.center?.y??0;return(Math.atan2(e-r,-(t-i))+ze)%ze}function zl(e,t){let[n,r]=e,i=r-n||1,o=t?.startAngle??0,a=t?.endAngle??ze;return e=>o+(e-n)/i*(a-o)}function Dl(e,t){let[n,r]=e,[i,o]=t,a=r-n||1;return e=>i+(e-n)/a*(o-i)}function jl(e,t,n,r,i){let o=i?.center,a=(e,t)=>{let{x:n,y:r}=Fl(e,t,{center:o});return`${_l(n)},${_l(r)}`},l=Math.max(0,n),s=Math.max(l,r),d=Math.abs(t-e),c=t>=e?1:0;if(d>=ze-1e-6){let e=o?.x??0,t=o?.y??0,n=`${_l(e)},${_l(t-s)}`,r=`${_l(e)},${_l(t+s)}`,i=`M${n} A${_l(s)},${_l(s)} 0 1 1 ${r} A${_l(s)},${_l(s)} 0 1 1 ${n} Z`;if(l>0){let n=`${_l(e)},${_l(t-l)}`,r=`${_l(e)},${_l(t+l)}`;i+=` M${n} A${_l(l)},${_l(l)} 0 1 0 ${r} A${_l(l)},${_l(l)} 0 1 0 ${n} Z`}return i}let u=d>Math.PI?1:0,h=a(e,s),p=a(t,s);if(l<=0){let e=o?.x??0,t=o?.y??0;return`M${_l(e)},${_l(t)} L${h} A${_l(s)},${_l(s)} 0 ${u} ${c} ${p} Z`}let f=a(t,l),m=a(e,l);return`M${h} A${_l(s)},${_l(s)} 0 ${u} ${c} ${p} L${f} A${_l(l)},${_l(l)} 0 ${u} ${1===c?0:1} ${m} Z`}function _l(e){return Math.round(1e3*e)/1e3}function Wl(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Gl(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Yl(e,t){return{x:e.x*t,y:e.y*t}}function Bl(e){return Math.hypot(e.x,e.y)}function ql(e){let t=Bl(e)||1;return{x:e.x/t,y:e.y/t}}function Vl(e,t){let[n,r]=e.viewBox??De,[i,o]=e.anchor??je,a=r>0?r:1,l=Math.max(0,t)/a,s=(n>0?n:a)*l,d=a*l;return{width:s,height:d,scale:l,offsetX:-i*s,offsetY:-o*d}}function Hl(e,t){let n=Vl(e,t),r=[[n.offsetX,n.offsetY],[n.offsetX+n.width,n.offsetY],[n.offsetX,n.offsetY+n.height],[n.offsetX+n.width,n.offsetY+n.height]],i=0;for(let[e,t]of r){let n=Math.sqrt(e*e+t*t);n>i&&(i=n)}return i}function Ul(e,t,n=0,r="horizontal"){let[i,o]=e.viewBox??De,a=Math.min(1,Math.max(0,n)),l=Math.min(1,Math.max(0,t));return l<=a?{x:0,y:0,width:0,height:0}:a<=0&&l>=1?null:"vertical"===r?{x:0,y:o*(1-l),width:i,height:o*(l-a)}:{x:i*a,y:0,width:i*(l-a),height:o}}var Re=/*#__PURE__*/new e(12),Le={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},Fe=8,Pe=fl,ze=2*Math.PI,De=[40,40],je=[.5,.5];import{jsx as Xl,jsxs as Kl}from"react/jsx-runtime";function Jl(e,t){let n=wn(e,100);return n>0?t/n*100*(t/n):Math.PI*t*t}function Zl(e){let t=[],n=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(n.length>0){let r=e.colorType??"fill",i=n.map(([e,t])=>({label:e,color:t})),o="line"===r?e=>({stroke:e.color??_e,strokeWidth:2,fill:"none"}):e=>({fill:e.color??_e,stroke:e.color??_e});t.push({type:r,label:e.colorLabel??"",items:i,styleFn:o})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){let n=e.symbolColor??_e,r=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:n}));t.push({label:e.symbolLabel??"",items:r,styleFn:()=>({}),type:e=>{let t=e.shape;return Xl("path",{d:xn(t,Jl(t,7)),transform:"translate(8,8)",fill:e.color??n})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){let n=e.sizeRadius,r=e.sizeFormat??(e=>String(e)),i=e.sizeColor??_e,o=e.sizeStops.map(e=>({label:r(e),r:Math.max(.5,n(e)),color:i}));t.push({label:e.sizeLabel??"",items:o,styleFn:()=>({}),type:e=>Xl("circle",{cx:8,cy:8,r:e.r,fill:e.color??i})})}return t}function Ql(e){let t=e.orientation??"vertical",n=e.swatchSize??14,r=e.gap??8,i=e.labelGap??6,o=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",l=n+r,s=0,d=[];return e.entries.forEach((e,c)=>{let u="vertical"===t?0:s,h="vertical"===t?s:0,p=e.color??e.line??a;d.push(Kl("g",{transform:`translate(${u},${h})`,children:[es(e,n,p,a),Xl("text",{x:n+i,y:n/2,dominantBaseline:"middle",fontSize:o,fill:a,children:e.label})]},`legend-${c}`)),s+="vertical"===t?l:n+i+e.label.length*o*.58+r+8}),Xl("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:d},e.keyId)}function es(e,t,n,r){if(e.shape){let r=Jl(e.shape,t/2-1);return Xl("path",{d:xn(e.shape,r),transform:`translate(${t/2},${t/2})`,fill:n})}if(e.hatch){let n=e.color??r;return Kl("g",{children:[Xl("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,r)=>Xl("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:n,strokeWidth:1,opacity:.7},r))}),Xl("rect",{width:t,height:t,fill:"none",stroke:n,strokeWidth:1,opacity:.5,rx:2})]})}return e.line?Xl("rect",{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}):Xl("rect",{width:t,height:t,rx:2,fill:n})}function ts(e){let t=e,n=[os(t,["datum","data"]),os(t,["datum"]),os(t,["data","data"]),os(t,["data"]),os(t,["node","datum","data"]),os(t,["node","datum"]),e];for(let e of n){if(!as(e))continue;let t={};for(let[n,r]of Object.entries(e))n.startsWith("_")||"function"==typeof r||(t[n]=r);if(Object.keys(t).length>0)return t}return null}function ns(e,t={}){let n=ts(e);if(!n)return[];let r=new Set(We);if(t.excludeKeys)for(let e of t.excludeKeys)r.add(e);let i=[];for(let[e,o]of Object.entries(n))if((t.includeInternal||!e.startsWith("_"))&&!r.has(e)&&(t.includeEmpty||null!=o&&""!==o)&&"function"!=typeof o&&(i.push({key:e,label:is(e,t.labels),value:o,formatted:t.valueFormat?t.valueFormat(o,e,n):rs(o)}),i.length>=(t.maxEntries??8)))break;return i}function rs(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?String(e):e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return`${e.length} items`;if("object"==typeof e)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}function is(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){let n=t[e];if("string"==typeof n&&n.length>0)return n}return e}function os(e,t){let n=e;for(let e of t){if(!as(n))return;n=n[e]}return n}function as(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ls(e,t){let n=new Map;for(let t of e)n.set(t.id,new Set);for(let e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target),n.get(e.target).add(e.source);return n}function ss(e,t){let n={};for(let t of e)st(n,t.id,0);for(let e of t)st(n,e.source,(lt(n,e.source)??0)+1),st(n,e.target,(lt(n,e.target)??0)+1);return n}function ds(e,t){let n={};st(n,t,0);let r=[t],i=0;for(;i<r.length;){let t=r[i];i+=1;for(let i of e.get(t)||[])at(n,i)||(st(n,i,n[t]+1),r.push(i))}return n}function cs(e,t,n,r){if(n===r)return n?[n]:[];let i=ls(e,t),o=dt();o[n]=null;let a=[n],l=0;for(;l<a.length;){let e=a[l];if(l+=1,e===r)break;for(let t of i.get(e)||[])at(o,t)||(o[t]=e,a.push(t))}if(!at(o,r))return[];let s=[],d=r;for(;null!=d;)s.unshift(d),d=o[d];return s}function us(e,t,n,r=1){let i=ls(e,t);if(!i.has(n))return new Set;let o=ds(i,n),a=new Set;for(let e of Object.keys(o))o[e]<=r&&a.add(e);return a}function hs(e,t){let n=ls(e,t),r={};for(let t of e)st(r,t.id,0);for(let t of e.map(e=>e.id)){let i=[],o=dt(),a=dt(),l=dt();for(let t of e)o[t.id]=[],a[t.id]=0,l[t.id]=-1;a[t]=1,l[t]=0;let s=[t],d=0;for(;d<s.length;){let e=s[d];d+=1,i.push(e);for(let t of n.get(e)||[])l[t]<0&&(l[t]=l[e]+1,s.push(t)),l[t]===l[e]+1&&(a[t]+=a[e],o[t].push(e))}let c=dt();for(let t of e)c[t.id]=0;for(;i.length;){let e=i.pop();for(let t of o[e])c[t]+=a[t]/a[e]*(1+c[e]);e!==t&&st(r,e,(lt(r,e)??0)+c[e])}}for(let e of Object.keys(r))st(r,e,r[e]/2);return r}function ps(e,t){let n=ls(e,t),r={};for(let t of e){let e=ds(n,t.id),i=0,o=0;for(let t of Object.keys(e))i+=e[t],o+=1;st(r,t.id,i>0?(o-1)/i:0)}return r}function fs(e,t){let n=ls(e,t),r={};for(let t of e){let e=[...n.get(t.id)||[]],i=e.length;if(i<2){st(r,t.id,0);continue}let o=0;for(let t=0;t<e.length;t+=1)for(let r=t+1;r<e.length;r+=1)n.get(e[t])?.has(e[r])&&(o+=1);st(r,t.id,2*o/(i*(i-1)))}return r}function ms(e){let t=0;for(let n of Object.keys(e))e[n]>t&&(t=e[n]);let n={};for(let r of Object.keys(e))st(n,r,t>0?e[r]/t:0);return n}function gs(e,t,n,r={}){let i=ls(e,t),o=dt();for(let t of e)o[t.id]=ds(i,t.id);let a=r.minHops??4,l=r.startThreshold??.08,s=r.maxThreshold??.2,d=new Set,c=0;for(;0===d.size&&c<40;){for(let t=0;t<e.length;t+=1)for(let r=t+1;r<e.length;r+=1){let i=e[t].id,s=e[r].id,c=lt(n,i),u=lt(n,s);if(!c||!u)continue;let h=void 0===o[i][s]?1/0:o[i][s],p=c.x-u.x,f=c.y-u.y,m=Math.sqrt(p*p+f*f);h>=a&&m<l&&(d.add(i),d.add(s))}0===d.size&&(l+=.02,l>s&&(l=r.startThreshold??.08,a=Math.max(2,a-1))),c+=1}return{problemIds:d,threshold:l,minHops:a}}async function ys(e,t,n={}){let{execution:r="auto",signal:i,workerThreshold:o,nodeRadius:a,...l}=n,s=l.iterations??260;if(!ft()||!pt(r,e.length,t.length,s,o))return Jt(e,t,{...l,nodeRadius:a});let d={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:l,nodeRadii:"function"==typeof a?Object.fromEntries(e.map(e=>[e.id,a(e)])):null==a?void 0:Object.fromEntries(e.map(e=>[e.id,a]))};try{let{runForceLayoutWorker:e}=await(import("./c-GTKZNWCF.min.js"));return(await e(d,i)).positions}catch(n){if("AbortError"===n?.name)throw n;return Jt(e,t,{...l,nodeRadius:a})}}function xs(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function bs(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&(null==t.label||"string"==typeof t.label)&&"number"==typeof t.count&&Number.isFinite(t.count)&&Array.isArray(t.bodyIds)&&t.bodyIds.every(e=>"string"==typeof e)}function ws(e,t){if("region-enter"!==t.type)return e;let n=t.region.id,r=xs(e,n),i=bs(r)?r:{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;let o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function Ms(e,t){return(t??Object.keys(e)).map(t=>xs(e,t)).filter(bs).map(e=>({label:e.label??e.id,value:e.count}))}function vs(e,t){let n=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],r=t.filter(e=>!n.has(e)),i=t.length-r.length,o=e.completion?.mode??"allMembersAbsorbed",a=e.completion?.valueByBodyId,l=e=>{let t=a?xs(a,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},s=t.reduce((e,t)=>e+l(t),0),d=t.reduce((e,t)=>e+(n.has(t)?l(t):0),0),c=e.completion?.threshold,u="threshold"===o?Number.isFinite(c)&&Number(c)>=0?Number(c):s:void 0,h=t.length>0&&("anyAbsorbed"===o?i>0:"threshold"===o?d>=(u??s):0===r.length);return{id:e.id,label:e.label??e.id,mode:o,complete:h,absorbed:i,total:t.length,absorbedValue:d,totalValue:s,threshold:u,missing:r}})}function ks(e,t,n,r,i,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:r,y2:i,thickness:o.thickness??8}}}function Is(e,t,n,r){return{type:"aabb",x:e,y:t,width:n,height:r}}function $s(e){let t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),r=Math.max(1,Math.round(e.height)),i=e.padX??46,o=e.padY??72,a=i,l=n-i,s=o,d=r-Math.max(24,Math.round(.45*o)),c=(s+d)/2,u=Math.max(1,d-s),h=gt(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,m=gt(u*h+f,.06*u,.5*u),g=m/2,y=c-g,x=c+g,b=e.idPrefix??"process",w=e.friction??.58,M=e.restitution??.18,v=e.wallThickness??8,k=e.stages;if(!k.length)throw new Error("processStageLayout requires at least one stage");let I=gt(e.centerStageIndex??Math.floor(k.length/2),0,k.length-1),$=function(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(k),S=l-a,N=a,A=k.map((e,t)=>{let n=(e.share??1)/$*S,r=N,i=t===k.length-1?l:N+n;return N=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:r,x1:i,x:(r+i)/2,width:i-r,y:c,height:u}}),E=A[I],C=E.x0,O=E.x1,T=(e,n)=>{if("lane"===t)return"top"===n?s:d;if("funnel"===t){let t=gt((e-a)/Math.max(1,l-a),0,1);return"top"===n?s+(y-s)*t:d+(x-d)*t}if(e<=C){let t=gt((e-a)/Math.max(1,C-a),0,1);return"top"===n?s+(y-s)*t:d+(x-d)*t}if(e<=O)return"top"===n?y:x;let r=gt((e-O)/Math.max(1,l-O),0,1);return"top"===n?y+(s-y)*r:x+(d-x)*r},R=A.map(e=>{let t=Math.min(T(e.x0,"top"),T(e.x1,"top")),n=Math.max(T(e.x0,"bottom"),T(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),L={thickness:v,friction:w,restitution:M},F=[];"lane"===t?F.push(ks(`${b}-top`,a,s,l,s,L),ks(`${b}-bottom`,a,d,l,d,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,s,l,d,{...L,thickness:Math.max(6,v)})):"funnel"===t?F.push(ks(`${b}-top`,a,s,l,y,L),ks(`${b}-bottom`,a,d,l,x,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,y,l,x,{...L,thickness:Math.max(6,v)})):F.push(ks(`${b}-left-top`,a,s,C,y,L),ks(`${b}-left-bottom`,a,d,C,x,L),ks(`${b}-center-top`,C,y,O,y,L),ks(`${b}-center-bottom`,C,x,O,x,L),ks(`${b}-right-top`,O,y,l,s,L),ks(`${b}-right-bottom`,O,x,l,d,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,s,l,d,{...L,thickness:Math.max(6,v)}));let P=e.membraneDampingScale??.5,z=a,D=Math.max(1,("bowtie"===t?C:l)-z),j=(e.membranes??[]).map(e=>{let t=z+gt(e.offset,0,1)*D,n=e.width??18+18*e.cost,r=u-16,i=c+.25*(e.wobble??0);return{...e,x:t,y:i,width:n,height:r}}),_=!1===e.includeMembraneRegions?[]:j.map(e=>Es({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??P,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:r,padX:i,padY:o,left:a,right:l,topY:s,bottomY:d,midY:c,centerLeft:C,centerRight:O,pinchHeight:m,pinchTop:y,pinchBottom:x,stages:R,membranes:j,colliders:F,regionEffects:_,boundaryY:T}}function Ss(e,t,n){return"function"==typeof t?r=>({...n,...t(r),primitive:e}):{...n,...t,primitive:e}}function Ns(e,t,n,r){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:Is(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:n?Ss(n,e.attributes,r):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function As(e,t={}){let n=t.idPrefix??"stage",r=Math.max(0,t.insetX??0),i=Math.max(0,t.insetY??1);return e.stages.map(e=>{let o="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...Ns({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*r),height:Math.max(1,e.height-2*i),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...o,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function Es(e){let t=e.dampingScale??.5,n=e.energyScale??1,r=gt(e.cost,0,2);return{...Ns(e,"membrane","membrane",{membraneCost:r}),damping:r*t,energyDelta:-r*n}}function Cs(e){return{...Ns(e,"charge-gate","chargeGate"),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function Os(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...Ns(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function Ts(e){let t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,r=e.dampingPerUnit??.12,i=e.energyPerUnit??0;return{...Ns(e,"membrane","pressureField",{pressure:t}),damping:n+t*r,energyDelta:i?-t*i:void 0,force:e.force}}function Rs(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...Ns(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function Ls(e){return{...Ns(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function Fs(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...Ns(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function Ps(e){return{...Ns(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function zs(e){let t=e.x??e.anchor?.x??0,n=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:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function Ds(e){let t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},r=[ks(`${t}-top`,e.left,e.top,e.right,e.top,n),ks(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||r.push(ks(`${t}-left`,e.left,e.top,e.left,e.bottom,n),ks(`${t}-right`,e.right,e.top,e.right,e.bottom,n)),r}function js(e,t,n={}){let r=n.random??Math.random,i=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],o=gt(n.along??.5,.05,.95),a=n.jitterX??0,l=n.padY??20,s=i.x0+(i.x1-i.x0)*o+(2*r()-1)*a,d=Math.min(1,i.width/2),c=gt(s,i.x0+d,i.x1-d),u=e.boundaryY(c,"top")+l,h=e.boundaryY(c,"bottom")-l;return{x:c,y:h<=u?e.midY:u+r()*Math.max(1,h-u)}}function _s(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function Ws(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Gs(e,t,n,r,i){return"function"==typeof r?r(e,t,n):function(e,t){let n=e;for(let e of t.split(".")){if(null==n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}(e,r??i)}function Ys(e){let t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Bs(e,t,n,r){let i=e.flatMap((e,i)=>{let o=Ws(Gs(e,i,t,n,"time")),a=Ws(Gs(e,i,t,r,"value"));return null==o||null==a?[]:[{time:Ys(o),value:a,index:i}]});i.sort((e,t)=>e.time-t.time||e.index-t.index);let o=[];for(let e of i){let t=o[o.length-1];t?.time===e.time?t.value=e.value:o.push({time:e.time,value:e.value})}return o}function qs(e,t,n,r){if(!e.length)return null;let i=e[0],o=e[e.length-1];if(t<i.time)return"clamp"===r?i.value:null;if(t>o.time)return"clamp"===r?o.value:null;let a=function(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i].time<t?n=i+1:r=i}return n}(e,t),l=e[a];if(l?.time===t)return l.value;let s=e[Math.max(0,a-1)];if("step"===n||!l||l.time===s.time)return s.value;let d=(t-s.time)/(l.time-s.time);return s.value+(l.value-s.value)*d}function Vs(e,t){if(1===e.length)return e[0];let n=(e.length-1)*t,r=Math.floor(n),i=Math.ceil(n);if(r===i)return e[r];let o=n-r;return e[r]+(e[i]-e[r])*o}function Hs(e){let t=e.interpolation??"step",n=e.outsideDomain??"omit",r=function(e){let t=(e??Ge).map(e=>{let t=Ws(e);if(null==t||t<0||t>1)throw new RangeError(`physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received ${String(e)}`);return Ys(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),i=function(e){if(Array.isArray(e)){if(e.length>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);return Array.from(new Set(e.map(Ws).filter(e=>null!=e).map(Ys))).sort((e,t)=>e-t)}let t=e,n=Ws(t.start),r=Ws(t.end),i=Ws(t.step);if(null==n||null==r||null==i||i<=0||r<n)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");let o=Math.floor((r-n)/i)+1;if(o>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);let a=[],l=1e-10*Math.max(1,Math.abs(r),Math.abs(n));for(let e=0;e<o;e+=1){let t=n+e*i;if(t>r+l)break;a.push(Ys(Math.min(t,r)))}if((!a.length||Math.abs(a[a.length-1]-r)>l)&&a.push(Ys(r)),a.length>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),o=e.runs.map(t=>Bs(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:i.map(e=>{let i=o.map(r=>qs(r,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(let e of r)a[e]=i.length?Vs(i,e):null;return{time:e,count:i.length,min:i.length?i[0]:null,max:i.length?i[i.length-1]:null,median:i.length?Vs(i,.5):null,quantiles:a}}),quantiles:r,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Us(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function Xs(e,t){if("min"===t||"median"===t||"max"===t)return e[t];let n=Ws(t);if(null==n||n<0||n>1)throw new RangeError(`comparePhysicsTrace quantile selectors must be from 0 to 1; received ${String(t)}`);let r=Ys(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,r))throw new Error(`comparePhysicsTrace could not find quantile ${r} in the reference envelope`);return e.quantiles[r]??null}function Ks(e,t,n){return e<t?"below":e>n?"above":"inside"}function Js(e,t){let n=Math.max(0,t.time-e.time);if(!(n>0)||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};let r=e.value-e.lower,i=t.value-t.lower,o=e.value-e.upper,a=t.value-t.upper,l=[0,1];for(let[e,t]of[[r,i],[o,a]])(e<0&&t>0||e>0&&t<0)&&l.push(-e/(t-e));l.sort((e,t)=>e-t);let s=0,d=0,c=0;for(let r=0;r<l.length-1;r+=1){let i=l[r],o=l[r+1];if(!(o>i))continue;let a=(i+o)/2,u=(o-i)*n,h=Ks(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?s+=u:"above"===h?c+=u:d+=u}return{below:s,inside:d,above:c,observed:n}}function Zs(e,t,n={}){let r=n.interpolation??t.interpolation,i=n.outsideDomain??t.outsideDomain,o=Bs(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),a=n.lower??Us(t,"lower"),l=n.upper??Us(t,"upper"),s=t.points.map(e=>{let t=qs(o,e.time,r,i),n=Xs(e,a),s=Xs(e,l);if(null!=n&&null!=s&&n>s)throw new RangeError(`comparePhysicsTrace lower band exceeds upper band at time ${e.time}`);return{time:e.time,value:t,lower:n,upper:s,status:null==t||null==n||null==s?"unobserved":Ks(t,n,s)}}),d=0,c=0,u=0,h=0,p=null,f=0,m=null;for(let e of s){if("below"===e.status?d+=1:"inside"===e.status?c+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;let t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,p=e.time),n>f&&(f=n,m=e.time)}let g=0,y=0,x=0,b=0;for(let e=0;e<s.length-1;e+=1){let t=s[e],n=s[e+1],i=Math.max(0,n.time-t.time);if(i>0){if("linear"===r){let e=Js(t,n);g+=e.below,y+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=i,"below"===t.status?g+=i:"above"===t.status?x+=i:y+=i)}}let w=s[0]?.time,M=s[s.length-1]?.time,v=null==w||null==M?0:Math.max(0,M-w),k=d+c+u;return{points:s,sampleCount:s.length,observedSamples:k,belowSamples:d,insideSamples:c,aboveSamples:u,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:g,insideDuration:y,aboveDuration:x,peakExcess:h,peakExcessAt:p,peakDeficit:f,peakDeficitAt:m}}function Qs(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function ed(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function td(e){return!!ed(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&ed(e.visitsByStage)&&ed(e.firstEnteredAt)&&ed(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function nd(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function rd(e){let t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,nd(e)]))}}function id(e,t,n={}){if("region-enter"!==t.type)return e;let r=function(e,t){let n=t.stageId?.(e);if(n)return n;let r=e.region.metadata;if(r&&"object"==typeof r&&Object.prototype.hasOwnProperty.call(r,"stageId")){let e=r.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),i=e.stages.findIndex(e=>e.id===r);if(i<0)return e;let o=n.entityId?.(t)??t.bodyId;if(!o)return e;let a=Qs(e.entities,o),l=td(a)?a:nd(o),s=l.currentStageId?e.stages.findIndex(e=>e.id===l.currentStageId):-1,d=!l.visitedStageIds.includes(r),c=Number(t.observation.timestamp),u=Number.isFinite(c)?c:0,h=Qs(l.visitsByStage,r),p="number"==typeof h&&Number.isFinite(h)?h:0,f={...l,currentStageId:r,furthestStageId:i>l.furthestStageIndex?r:l.furthestStageId,furthestStageIndex:Math.max(l.furthestStageIndex,i),visitedStageIds:d?[...l.visitedStageIds,r]:l.visitedStageIds,visitsByStage:{...l.visitsByStage,[r]:p+1},firstEnteredAt:d?{...l.firstEnteredAt,[r]:u}:l.firstEnteredAt,lastEnteredAt:{...l.lastEnteredAt,[r]:u},regressionCount:s>=0&&i<s?l.regressionCount+1:l.regressionCount};return{...e,bodyIds:e.bodyIds.includes(o)?e.bodyIds:[...e.bodyIds,o],entities:{...e.entities,[o]:f}}}function od(e){let t=e.bodyIds.map(t=>{let n=Qs(e.entities,t);return td(n)?n:nd(t)}),n=t.length,r=n;return e.stages.map((e,i)=>{let o=t.filter(e=>e.furthestStageIndex>=i).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,l=t.reduce((t,n)=>{let r=Qs(n.visitsByStage,e.id);return t+("number"==typeof r&&Number.isFinite(r)?r:0)},0),s={id:e.id,label:e.label??e.id,reached:o,entered:a,total:n,conversion:n>0?o/n:0,fromPrevious:r>0?o/r:0,dropoff:Math.max(0,r-o),visits:l,repeatVisits:Math.max(0,l-a)};return r=o,s})}function ad(e,t){if(!t)return;let n=e;for(let e of t.split(".")){if(null==n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}function ld(e,t){return!!t?.some(t=>Object.is(e,t))}function sd(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let n=ad(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!ld(n,t.oneOf)||t.notOneOf&&ld(n,t.notOneOf))}function dd(e,t){if("function"==typeof t){let n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}let n=e.datum;if(t&&n&&"object"==typeof n){let e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}let r=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(r)&&r>0?r:1}function cd(e,t){if("function"==typeof t){let n=t(e);if(null!=n&&String(n).length>0)return String(n)}else if(t){let n=ad(e.datum,t),r=ad(e,t),i=n??r;if(null!=i&&String(i).length>0)return String(i)}return e.id}function ud(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.floor(n),i=Math.ceil(n),o=n-r;return e[r]+(e[i]-e[r])*o}function hd(e){let t=e.regionId,n=Math.max(0,e.unitsPerSecond),r=e.queueLayout??"lane",i=e.queueSlotSpacing??14,o=e.queueStiffness??.35,a=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):Number.POSITIVE_INFINITY,l=Math.max(.25,e.metricWindowSeconds??30),s=Math.max(1/60,e.snapshotIntervalSeconds??.25),d=e.releaseImpulse??{x:90,y:0},c=new Map,u=new Map,h=new Map,p=new Map,f=new Map,m=new Map,g=new Map,y=[],x=0,b=new Map,w=new Map,M=0,v=0,k=0,I=null,$=0,S=0,N=0,A=0,E=0,C=0,O=0,T=0,R=0,L=0,F=0,P=0,z=-1,D=!1;function j(e,n){let r=n(e);return!!r&&r.activeRegionIds.includes(t)}function _(){P+=1}function W(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function G(n,r,i,o){let a={bodyId:n.id,jobId:r.jobId,visitId:r.visitId,visit:r.visit,remaining:r.work,total:r.work,queuedAt:r.queuedAt,sequence:o};return c.set(r.jobId,a),g.delete(n.id),m.set(n.id,r.jobId),S+=1,N+=r.work,_(),function(n,r,i){let o=W(r);e.onQueued?.(n,o),i.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:r.total,jobId:r.jobId,visitId:r.visitId,visit:r.visit,queuedAt:r.queuedAt,queueDepth:c.size})}(n,a,i),a}function Y(e){if(c.size>=a||0===u.size)return;let t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(let n of t){if(c.size>=a)break;let t=f.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),g.delete(n.bodyId),G(t,n,e,n.sequence)):u.delete(n.jobId)}}function B(){let e=0;for(let t of c.values())e+=t.remaining;return e}function q(){R=Math.max(R,c.size),L=Math.max(L,B())}function V(){let e=k-l,t=Math.max(0,Math.min(l,k-(I??k))),r=0,i=0,o=0,a=0,s=0;for(let t of y){if(t.end<e)continue;r+=t.arrivals,i+=t.arrivalWork,o+=t.completions,a+=t.completedWork;let n=t.end-t.start;if(n<=0||t.start>=e)s+=t.processedWork;else{let r=Math.max(0,t.end-e);s+=t.processedWork*Math.min(1,r/n)}}let d=t>0?i/t:0;return{seconds:t,arrivals:r,arrivalWork:i,completions:o,completedWork:a,processedWork:s,arrivalsPerSecond:t>0?r/t:0,throughputPerSecond:t>0?o/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,s/(n*t))):0,pressure:n>0?d/n:0}}return{id:e.id??`capacity-queue:${t}`,continuous:!1!==e.continuous,tick:r=>{let i=r.controls.readBodies(),o=new Map,S=new Map;for(let t of i){if(o.set(t.id,t),!j(t.id,r.getRegionState)||!sd(t,e.bodyFilter))continue;let n=cd(t,e.jobKey),i=S.get(n)??[];i.push(t),S.set(n,i)}let N=Number.isFinite(r.dt)?Math.max(0,r.dt):0;if(!D){let e=Number.isFinite(r.elapsed)?Math.max(0,r.elapsed):N;k=Math.max(0,e-N),D=!0}let R=k,L=R+N;k=L,I=null==I?R:Math.min(I,R);let P={start:R,end:L,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},B=new Map;for(let[e,t]of S){let n=h.get(e)?.bodyId,r=t.find(e=>e.id===n)??t[0];B.set(e,r),f.set(e,r)}for(let[n,i]of h){if(B.has(n))continue;let a=c.get(n),l=o.get(i.bodyId)??f.get(n);if(a){c.delete(n),m.delete(a.bodyId),O+=1,T+=a.remaining,_();let o={...W(a),abandonedAt:k,remainingWork:a.remaining,queueSeconds:Math.max(0,k-a.queuedAt)};l&&e.onAbandoned?.(l,o),r.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:i.bodyId,datum:l?.datum,x:l?.x,y:l?.y,regionId:t,work:a.total,remainingWork:a.remaining,jobId:n,visitId:a.visitId,visit:a.visit,queuedAt:a.queuedAt,abandonedAt:k,queueSeconds:o.queueSeconds,queueDepth:c.size})}u.delete(n),g.delete(i.bodyId),h.delete(n),f.delete(n)}for(let[n,i]of B){if(h.has(n))continue;let o=(p.get(n)??0)+1;p.set(n,o);let l=dd(i,e.unitAccessor),s={bodyId:i.id,jobId:n,visitId:`${t}:${n}:${o}`,visit:o,regionId:t,work:l,queuedAt:k};h.set(n,s),$+=1,P.arrivals+=1,P.arrivalWork+=l;let d=x++;if(c.size<a)G(i,s,r,d);else{let a={...s,blockedAt:k,sequence:d};u.set(n,a),g.set(i.id,n),C+=1,_(),e.onBlocked?.(i,a),r.controls.recordObservation({type:"physics-capacity-blocked",bodyId:i.id,datum:i.datum,x:i.x,y:i.y,regionId:t,work:l,jobId:n,visitId:s.visitId,visit:o,queuedAt:k,blockedAt:k,queueDepth:c.size,blockedDepth:u.size})}}Y(r),q();let V=Array.from(c.values()).sort((e,t)=>e.sequence-t.sequence),H=n*N;for(let n of V){if(!(H>0))break;let i=Math.min(n.remaining,H);if(n.remaining-=i,H-=i,A+=i,P.processedWork+=i,n.remaining>1e-6)continue;c.delete(n.jobId),m.delete(n.bodyId),v+=1,E+=n.total,P.completions+=1,P.completedWork+=n.total;let a=Math.max(0,k-n.queuedAt);F+=a,_();let l=o.get(n.bodyId);if(!l)continue;r.controls.applyImpulse(n.bodyId,d.x??0,d.y??0);let s={...W(n),completedAt:k,queueSeconds:a};e.onProcessed?.(l,s),r.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:l.datum,x:l.x,y:l.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:k,queueSeconds:a,queueDepth:c.size})}Y(r),q(),function(){let e=Array.from(c.values()).sort((e,t)=>e.sequence-t.sequence);b=new Map(e.map((e,t)=>[e.bodyId,t]));let t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);w=new Map(t.map((e,t)=>[e.bodyId,t])),M=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&y.push(e);let t=k-l;for(;y.length>0&&y[0].end<t;)y.shift()}(P);let U=Math.floor(k/s);U!==z&&(z=U,_())},getSnapshot:()=>{let e=B(),r=function(){let e=0;for(let t of u.values())e+=t.work;return e}(),i=c.size,o=Array.from(c.values()).map(e=>Math.max(0,k-e.queuedAt)).sort((e,t)=>e-t),a=o.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:i,processedCount:v,unitsPerSecond:n,remainingWork:e,meanRemainingWork:i>0?e/i:0,waitingWork:e+r,blockedDepth:u.size,blockedWork:r,arrivalCount:$,admittedCount:S,admittedWork:N,processedWork:A,completedWork:E,blockedCount:C,abandonedCount:O,abandonedWork:T,peakQueueDepth:R,peakRemainingWork:L,queueAge:{count:o.length,meanSeconds:o.length>0?a/o.length:0,p50Seconds:ud(o,.5),p95Seconds:ud(o,.95),oldestSeconds:o.at(-1)??0},meanCompletedQueueSeconds:v>0?F/v:0,window:V(),simulatedAt:k,metricRevision:P}},bodyForce:e=>{if("none"===r)return null;let n=m.get(e.body.id),a=g.get(e.body.id),l=n?c.get(n):void 0,s=a?u.get(a):void 0;if(!l&&!s)return null;let d=l?b.get(e.body.id):w.get(e.body.id);if(null==d)return null;let h,p=e.regions;if(p)for(let e=0;e<p.length;e+=1)if(p[e].id===t){let t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}if(!h)return{x:8*-Math.sign(e.body.vx||1),y:0};let f=s?h.x-.44*h.width:h.x-.22*h.width-d*(.15*i),y=h.y-(d-((s?u.size:M)-1)/2)*i/Math.max(1,Math.sqrt(s?u.size:M)),x=f-e.body.x,v=y-e.body.y;return{x:x*o,y:v*o*.85}}}}function pd(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function fd(e){if(!e?.length)return null;let t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,r)=>{let i={result:e,controls:n,dt:r.dt,elapsed:r.elapsed,getRegionState:r.getRegionState};for(let e of t)e.tick(i)},bodyForce:e=>{let n=null;for(let r of t)r.bodyForce&&(n=pd(n,r.bodyForce(e)));return n}}}function md(e){let t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??`portal:${e.fromRegionId}`,continuous:!0===e.continuous,tick:r=>{let i=r.controls.readBodies();for(let o of i)r.getRegionState(o.id)?.activeRegionIds.includes(e.fromRegionId)?t.has(o.id)||(t.add(o.id),r.controls.applyImpulse(o.id,n.x??0,n.y??0),e.onPortal?.(o)):t.delete(o.id)}}}function gd(e){let t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),r=new Map,i=new Map,o=e.assignmentForce??.45,a=e.returnForce??.35,l=e.caseAttraction??.08,s=e.assignmentOffset??{x:0,y:0},d=new Map,c=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{let n=r.get(e);if(n)return n;let o=t.find(e=>!i.has(e.id));if(!o)return null;let a={resourceId:o.id,resourceBodyId:o.bodyId,caseBodyId:e,assignedAt:c};return r.set(e,a),i.set(o.id,a),u+=1,a},release:e=>{let t=r.get(e);return!!t&&(r.delete(e),i.delete(t.resourceId),u+=1,!0)},getAssignment:e=>r.get(e),tick:e=>{c=Math.max(c,e.elapsed),d=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(let[e,t]of r)d.has(e)&&d.has(t.resourceBodyId)||(r.delete(e),i.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-i.size,assigned:i.size,assignments:Array.from(r.values()),simulatedAt:c,metricRevision:u}),bodyForce:e=>{let t=n.get(e.body.id);if(t){let n=i.get(t.id),r=n?d.get(n.caseBodyId):void 0,l=r?r.x+(s.x??0):t.home.x,c=r?r.y+(s.y??0):t.home.y,u=n?o:a;return{x:(l-e.body.x)*u,y:(c-e.body.y)*u}}let c=r.get(e.body.id);if(!c||l<=0)return null;let u=d.get(c.resourceBodyId);return u?{x:(u.x-e.body.x)*l,y:(u.y-e.body.y)*l}:null}}}function yd(e,t){let n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):ad(e.datum,t.deadlineAccessor)??ad(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function xd(e){let t=new Map,n=0,r=0;function i(n){t.set(n.bodyId,n),r+=1,e.onStateChange?.({...n})}function o(e){let r=t.get(e);return!(!r||null!=r.completedAt||(i({...r,completedAt:n,state:"unhappy"===r.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{let r=t.get(e);return!(!r||null!=r.completedAt||"unhappy"===r.state||(i({...r,state:"protected",protectedAt:n}),0))},complete:o,getCase:e=>t.get(e),tick:r=>{n=Math.max(n,r.elapsed);for(let a of r.controls.readBodies()){if(!sd(a,e.bodyFilter))continue;if(!t.has(a.id)){let t=yd(a,e);i({bodyId:a.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}let l=t.get(a.id);l&&null==l.completedAt&&(e.completionRegionId&&r.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?o(a.id):"waiting"===l.state&&n>=l.deadlineAt&&i({...l,state:"unhappy"}))}},getSnapshot:()=>{let e=Array.from(t.values()),i=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:i("waiting"),protected:i("protected"),unhappy:i("unhappy"),resolved:i("resolved"),resolvedUnhappy:i("resolved-unhappy"),simulatedAt:n,metricRevision:r}}}}function bd(e){let t=new Set,n=0,r=0,i=0,o=!1;return{id:e.id??`dependency-gate:${e.regionId}`,continuous:!0,tick:a=>{n=Math.max(n,a.elapsed);let l=o;o=function(t){return e.isOpen?e.isOpen(t):null!=e.opensAt&&t>=e.opensAt}(n);let s=a.controls.readBodies(),d=new Map(s.map(e=>[e.id,e]));for(let n of s)!a.getRegionState(n.id)?.activeRegionIds.includes(e.regionId)||!sd(n,e.bodyFilter)||!o&&!t.has(n.id)&&(t.add(n.id),i+=1,e.onHeld?.(n));if(o&&!l){for(let n of t){let t=d.get(n);t&&(a.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),r+=1,e.onReleased?.(t))}t.clear(),i+=1}for(let e of t)d.has(e)||(t.delete(e),i+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:o,blocked:t.size,released:r,simulatedAt:n,metricRevision:i}),bodyForce:n=>{if(o||!t.has(n.body.id))return null;let r=n.regions?.find(t=>t.id===e.regionId)?.shape;if(!r||"aabb"!==r.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};let i=e.holdForce??.4;return{x:(r.x-n.body.x)*i-.45*n.body.vx,y:(r.y-n.body.y)*i-.45*n.body.vy}}}}_e="var(--semiotic-text, currentColor)",We=/*#__PURE__*/new Set(["rows"]),Number.POSITIVE_INFINITY,Ge=[.1,.5,.9],Ye=1e6;import{createElement as wd}from"react";import{Children as Md,cloneElement as vd,isValidElement as kd,useId as Id}from"react";function $d(e,t,n,r){let i=e=>n.get(e)??e;return"id"===e?i(t):/^(?:xlink:?)?href$/i.test(e)?"#"===t[0]?`#${i(t.slice(1))}`:t:/^(?:aria-(?:labelledby|describedby|controls|owns|activedescendant|details|errormessage)|for|htmlFor|list|form|headers|itemref|popovertarget)$/.test(e)?t.replace(/\S+/g,i):/^(?:fill|stroke|clip-?path|mask|filter|marker-?(?:start|mid|end)|style|cursor)$/i.test(e)?r?r(t,n):t.replace(/url\(\s*(["']?)#([^\s"')]+)\1\s*\)/g,(e,t,n)=>{let r=i(n);return r===n?e:`url(#${r})`}):t}function Sd({children:e}){let t=Id().replace(/[^\w-]/g,"_"),n=new Map,r=(e,t=!1)=>{let o={...e};for(let[e,a]of Object.entries(o))o[e]="children"!==e||t?"style"===e&&!t&&a&&"object"==typeof a?r(a,!0):"string"==typeof a?$d(t?"style":e,a,n):a:i(a);return o},i=(e,o=!1)=>"object"!=typeof e?e:Md.map(e,e=>kd(e)?o?("string"==typeof e.props.id&&n.set(e.props.id,`${t}-${e.props.id}`),i(e.props.children,!0),e):vd(e,r(e.props)):e);return i(e,!0),i(e)}import{Fragment as Nd,jsx as Ad,jsxs as Ed}from"react/jsx-runtime";function Cd(e){return 6.2*e.length}function Od(e,t){let n=e.trim();if(n.length<=t)return n;if(t<=1)return n.slice(0,1);let r=n.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return r.length>1&&r.length<=t?r:t<=3?n.slice(0,t).toUpperCase():`${n.slice(0,Math.max(1,t-2))}..`}function Td(e,t,n="auto"){let r=Math.max(1,Math.floor(t/6.2)),i="compact"===n?Od(e,r):"full"===n||Cd(e)<=t?e:Od(e,r);return{text:i,textLength:Cd(i)>t?Math.max(4,t):void 0}}function Rd(e,t={}){let{showFlowSpine:n=!0,showStageCounts:r=!0,showCapacityBadges:i=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:l=!1,testId:s="process-flow-chrome"}=t,{width:d,height:c,left:u,right:h,topY:p,bottomY:f,midY:m,stages:g,groups:y=[]}=e,x=f-p;return wd(Sd,null,Ed("svg",{"aria-hidden":"true","data-testid":s,"data-outline-stages":l?"true":void 0,width:d,height:c,viewBox:`0 0 ${d} ${c}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",l?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Ad("defs",{children:Ed("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Ad("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Ad("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Ad("rect",{x:0,y:0,width:d,height:c,fill:"url(#semiotic-process-floor)"}),Ad("rect",{x:u-6,y:p-8,width:h-u+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}),n?Ad("line",{x1:u+8,x2:h-8,y1:m,y2:m,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,g.map((e,t)=>{let n=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),o=Be[n],s=Math.max(12,e.width-8),d=gt(s-8,22,88),u=Math.max(8,d-10),h=Td(e.label,u,a),y="none"!==a&&s-8>=22,b=function(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"}(e),w=Td(b,Math.max(16,s-10),"auto"),M=i&&!1!==e.showBadge&&s>=32,v=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",k=Td(v,Math.max(16,s-8),"auto"),I=Math.max(30,p-15),$=I-13;return Ed("g",{"data-stage":e.id,"data-role":n,children:[Ad("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:s,height:x-12,rx:10,fill:l?"none":o.fill,stroke:o.stroke,strokeWidth:l?1.85:"flow"===n?1:1.6}),t<g.length-1?Ad("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:o.accent,opacity:.85}):null,y?Ed(Nd,{children:[Ad("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-d/2,y:$,width:d,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),Ed("text",{x:e.x,y:I,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:[Ad("title",{children:e.label}),h.text]})]}):null,M?Ed("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:w.textLength,lengthAdjust:w.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:b}),w.text]}):null,r&&null!=e.count?Ed("text",{x:e.x,y:Math.min(c-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:v}),k.text]}):null]},e.id)}),o?y.map((e,t)=>{let n=e.total??0,r=e.absorbed??0,i=e.complete??(n>0&&r>=n),o=!i&&n>0&&r/n>=.75,a=i?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",l=i?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",s=n>0?`${r}/${n}${i?" shipped":o?" almost":""}`:`feature ${t+1}`,d=gt(Math.max(54,Cd(e.label)+18,Cd(s)+16),54,104),c=Td(e.label,d-12,"auto"),u=Td(s,d-12,"auto");return Ed("g",{"data-group":e.id,children:[Ad("rect",{x:e.x-d/2,y:e.y-22,width:d,height:44,rx:10,fill:a,stroke:l,strokeWidth:1.5}),Ed("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:c.textLength,lengthAdjust:c.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:e.label}),c.text]}),Ed("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:l,fontSize:9,fontWeight:700,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:s}),u.text]})]},e.id)}):null]}))}function Ld(e){let[t,n]=e.size,r=e.flow??"down",i=function(e){return null==e?{top:24,right:24,bottom:24,left:24}:"number"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}(e.padding),o=Math.max(.05,Math.min(1,e.channelRatio??1)),a={x:i.left,y:i.top,width:Math.max(1,t-i.left-i.right),height:Math.max(1,n-i.top-i.bottom)},l="down"===r?a.height:a.width,s=l*Math.max(0,e.chargeExtent??.12),d=l*Math.max(0,e.projectionExtent??0),c=l*Math.max(0,e.destinationExtent??.55),u=Math.max(0,l-s-c-d),h=function(e){if("number"==typeof e){let t=Math.max(1,Math.round(e));return Array.from({length:t},(e,t)=>({id:`bin-${t}`,label:String(t)}))}return 0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??String(t)}))}(e.destinations),p=("down"===r?a.width:a.height)/h.length,f="down"===r?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),m=f(0,s),g=f(s,u),y=s+u,x=f(y,c),b=f(y+c,d),w=h.map((e,t)=>{let n=t*p,i=p*o,l=(p-i)/2;if("down"===r){let r=a.x+n+l;return{id:e.id,label:e.label,order:t,x:r,y:x.y,width:i,height:x.height,centerX:a.x+(t+.5)*p,centerY:x.y+x.height/2}}let s=a.y+n+l;return{id:e.id,label:e.label,order:t,x:x.x,y:s,width:x.width,height:i,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*p}});return{width:t,height:n,flow:r,charge:m,apparatus:g,destinations:w,projection:b}}function Fd(e,t){return e.destinations.find(e=>e.id===t)}function Pd(e,t,n){let{charge:r,flow:i}=e,o=Math.max(1,n),a=(t%o+.5)/o;return"down"===i?{x:r.x+r.width*a,y:r.y+r.height/2}:{x:r.x+r.width/2,y:r.y+r.height*a}}function zd(e,t={}){let n=t.thickness??4,r=t.idPrefix??"stage",{destinations:i,flow:o,width:a,height:l}=e,s=[];if(i.length>0){let t=i[0];if("down"===o){let o=t.y+t.height;s.push({id:`${r}-floor`,shape:{type:"segment",x1:e.charge.x,y1:o,x2:e.charge.x+e.charge.width,y2:o,thickness:n}});for(let e=1;e<i.length;e+=1){let a=i[e].centerX-(i[e].centerX-i[e-1].centerX)/2;s.push({id:`${r}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:o,thickness:n}})}}else{let o=t.x+t.width;s.push({id:`${r}-floor`,shape:{type:"segment",x1:o,y1:e.charge.y,x2:o,y2:e.charge.y+e.charge.height,thickness:n}});for(let e=1;e<i.length;e+=1){let a=i[e].centerY-(i[e].centerY-i[e-1].centerY)/2;s.push({id:`${r}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:o,y2:a,thickness:n}})}}}return!1!==t.walls&&s.push({id:`${r}-wall-left`,shape:{type:"segment",x1:1,y1:0,x2:1,y2:l,thickness:n}},{id:`${r}-wall-right`,shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:l,thickness:n}}),s}function Dd(e,t={}){let n=t.charge??"bodies",r=t.apparatus??"the apparatus",i=t.destination??"destinations",o=e.destinations.length,a="down"===e.flow?"downward":"left to right";return`${n} enter at the ${"down"===e.flow?"top":"left"}, travel ${a} through ${r}, and come to rest in ${o} ${i}: ${e.destinations.map(e=>e.label).join(", ")}.`}function jd(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function _d(e,t,n,r){let i="function"==typeof e?e(t,n):e;return Number.isFinite(i)?Number(i):r}function Wd(e,t,n){return jd(e[t])??n}function Gd(e,t){return"number"==typeof e?e:e?.[t]??0}function Yd(e){let{band:t,idPrefix:n,plot:r,projection:i}=e,{includeBoundaryWalls:o=!0,includeInteriorWalls:a=!0,wallThickness:l=4}=t,s=function(e){let t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(let r of e.values){let i=e.scale(r);Number.isFinite(i)&&(n.add(Number(i)),n.add(Number(i)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(s.length<2)return[];let d=o?0:1,c=o?s.length-1:s.length-2,u=[];for(let e=d;e<=c;e+=1){if(!a&&e>0&&e<s.length-1)continue;let t=s[e];u.push({id:`${n}-wall-${e}`,shape:"x"===i?{type:"aabb",x:t,y:r.y+r.height/2,width:l,height:r.height}:{type:"aabb",x:r.x+r.width/2,y:t,width:r.width,height:l}})}return u}function Bd(e){let{plot:t,idPrefix:n="physics-scale",bounds:r={},xBins:i,xBands:o,yBands:a}=e,l=[];if(!1!==r&&l.push(...function(e,t={}){let{idPrefix:n="plot",includeFloor:r=!0,includeCeiling:i=!1,includeLeftWall:o=!0,includeRightWall:a=!0,wallThickness:l=20,floorThickness:s=l}=t,d=[],c=e.x+e.width/2,u=e.y+e.height/2,h=(e,t,r,i,o)=>{d.push({id:`${n}-${e}`,shape:{type:"aabb",x:t,y:r,width:i,height:o}})};return r&&h("floor",c,e.y+e.height+s/2,e.width+2*l,s),i&&h("ceiling",c,e.y-s/2,e.width+2*l,s),o&&h("left-wall",e.x-l/2,u,l,e.height+2*s),a&&h("right-wall",e.x+e.width+l/2,u,l,e.height+2*s),d}(t,{idPrefix:n,...r})),i){let{idPrefix:e,yTop:r,yBottom:o,...a}=i;l.push(...function(e){let{idPrefix:t="bin",count:n,domainStart:r,domainStep:i,xScale:o,yTop:a,yBottom:l,wallThickness:s=4,includeBoundaryWalls:d=!0,includeInteriorWalls:c=!0,closedBefore:u,lidY:h=a,lidThickness:p=Math.max(2,s)}=e,f=[],m=a+(l-a)/2,g=Math.abs(l-a),y=d?n:n-1;if(c||d)for(let e=d?0:1;e<=y;e+=1){if(!c&&e>0&&e<n)continue;let a=o(r+e*i);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:a,y:m,width:s,height:g}})}if(null!=u)for(let e=0;e<n;e+=1){let n=r+e*i,a=n+i;if(a>=u)continue;let l=o(n),d=o(a);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(l,d)+s/2,y1:h,x2:Math.max(l,d)-s/2,y2:h,thickness:p}})}return f}({...a,idPrefix:e??`${n}-xbin`,yTop:r??t.y,yBottom:o??t.y+t.height}))}return o&&l.push(...Yd({band:o,idPrefix:o.idPrefix??`${n}-xband`,plot:t,projection:"x"})),a&&l.push(...Yd({band:a,idPrefix:a.idPrefix??`${n}-yband`,plot:t,projection:"y"})),l}function qd(e){let{plot:t,rows:n,columns:r=n+1,pegRadius:i=3,idPrefix:o="galton-peg",yStart:a=t.y+.18*t.height,yEnd:l=t.y+.58*t.height,stagger:s=!0,restitution:d=.2,friction:c=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(r));if(0===u)return[];let p=u<=1?0:(l-a)/(u-1),f=t.width/h,m=[];for(let e=0;e<u;e+=1){let n=s&&e%2==1?f/2:0;for(let r=0;r<h;r+=1){let l=t.x+f*(r+.5)+n;l<t.x+i||l>t.x+t.width-i||m.push({id:`${o}-${e}-${r}`,shape:{type:"aabb",x:l,y:a+e*p,width:2*i,height:2*i},restitution:d,friction:c})}}return m}function Vd(e,t={}){let{idPrefix:n="physics-token",radius:r=5,shape:i,mass:o,vx:a,vy:l,spawnAt:s,seed:d=1,jitter:c,datum:u}=t,h=Kt(d),p=Gd(c,"x"),f=Gd(c,"y");return e.map((e,d)=>{let c=_d(t.x,e,d,Wd(e,"x",0)),m=_d(t.y,e,d,Wd(e,"y",0)),g=_d(r,e,d,5),y="function"==typeof i?i(e,d):i??{type:"circle",radius:g};return{id:`${n}-${e.index??d}`,x:c+(h()-.5)*p,y:m+(h()-.5)*f,vx:_d(a,e,d,0),vy:_d(l,e,d,0),mass:_d(o,e,d,1),spawnAt:_d(s,e,d,void 0),shape:y,datum:u?u(e,d):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;let{spawnAt:t,...n}=e;return n})}function Hd(e,t={}){let{idPrefix:n="sediment",collider:r=!0,colliderThickness:i=1,restitution:o=.05,friction:a=.2,...l}=t,s=function(e,t={}){let{baselineY:n=0,binWidth:r=24,gap:i=2,maxHeight:o=80,value:a="count",x:l}=t,s=e.reduce((e,t)=>Math.max(e,t[a]),1);return e.map((e,t)=>{let d=Math.max(0,e[a]/s*o),c=l?.(e,t)??t*(r+i);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:c,y:n-d,width:r,height:d,meanX:e.x.mean,meanY:e.y.mean}})}(e,l),d=r?s.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+i/2,width:e.width,height:i},restitution:o,friction:a})):[];return{columns:s,colliders:d}}function Ud(e,t={}){let{timeAccessor:n="arrivalTime",timeScale:r=1,startAt:i=0,rebase:o=!0,sort:a=!0}=t,l=e.map((e,t)=>{let r=function(e,t,n){return jd("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t;return{spawn:e,time:r}}),s=l.length?ut(l.map(e=>e.time)):0;return{initialSpawns:l.map(({spawn:e,time:t})=>({...e,spawnAt:i+(o?t-s:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:i,timeAccessor:"spawnAt",timeScale:r}}}function Xd(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function Kd(e,t,n="group"){let r=ss(e,t),i=e=>"function"==typeof n?n(e):e[n]??0;return e.slice().sort((e,t)=>{let n=i(e),o=i(t);return n<o?-1:n>o?1:(r[t.id]||0)-(r[e.id]||0)}).map(e=>e.id)}function Jd(e,t={}){let n=t.baseline??.62,r=t.inset??.06,i={},o=e.length;return e.forEach((e,t)=>{Xd(i,e,{x:o>1?r+t/(o-1)*(1-2*r):.5,y:n})}),i}function Zd(e,t,n=.55){let r=Math.abs(t.x-e.x),i=(e.x+t.x)/2,o=e.y-r*n;return`M${e.x},${e.y} Q${i},${o} ${t.x},${t.y}`}function Qd(e,t={}){let n=t.radius??.42,r=t.center?.x??.5,i=t.center?.y??.5,o=t.startAngle??0,a={},l=e.length;return e.forEach((e,t)=>{let s=o+t/l*Math.PI*2-Math.PI/2;Xd(a,e,{x:r+Math.cos(s)*n,y:i+Math.sin(s)*n})}),a}function ec(e,t,n={}){let r=(n.order??Kd(e,t,n.groupAccessor??"group")).slice(),i=new Map(r.map((e,t)=>[e,t])),o=new Map;for(let e of t){if(!i.has(e.source)||!i.has(e.target)||e.source===e.target)continue;let t=e.source<e.target?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;o.set(t,(o.get(t)||0)+(e.value??1))}let a=[],l=0;for(let[e,t]of o){let[n,r]=e.split("\0"),o=i.get(n),s=i.get(r);t>l&&(l=t),a.push({row:o,col:s,source:n,target:r,value:t}),a.push({row:s,col:o,source:r,target:n,value:t})}return{order:r,cells:a,size:r.length,maxValue:l}}function tc(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function nc(e){if("string"!=typeof e)return;let t=e.trim();return t.length?t:void 0}function rc(e,t){let n=tc(e.note)?e.note:void 0;return t?nc(e.mobileText)||nc(e.shortText)||nc(e.label)||nc(n?.mobileText)||nc(n?.shortText)||nc(n?.label)||nc(n?.title):nc(e.label)||nc(e.mobileText)||nc(e.shortText)||nc(n?.label)||nc(n?.title)}function ic(e,t,n){let r=function(e,t,n){if(!n)return;let r="function"==typeof n?n(e,t):e[n];return"number"==typeof r&&Number.isFinite(r)?r:void 0}(e,t,n.priorityAccessor);if(void 0!==r)return r;let i=1e3-t,o=String(e.emphasis??"").toLowerCase();("primary"===o||"critical"===o)&&(i+=1e4),"secondary"===o&&(i-=1e3),"high"===e.priority&&(i+=5e3),"low"===e.priority&&(i-=1500),"number"==typeof e.priority&&(i+=100*e.priority);let a=tc(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(i+=100*a.confidence);let l=tc(e.lifecycle)?e.lifecycle:void 0,s=String(l?.freshness??"").toLowerCase();return("expired"===s||"stale"===s)&&(i-=3e3),i}function oc(e,t){if(!t)return e;let n=rc(e,!0);return n&&"string"==typeof e.label?{...e,label:n}:e}function ac(e,t={}){let n=Array.isArray(e)?e.filter(tc):[],r=t.breakpoint??480,i=t.active??(null==t.width||t.width<=r),o=t.strategy??"hybrid",a=!1!==t.preferShortText,l=!1!==t.preservePrimary,s=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===o?1:2)),d=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!i||"plot"===o)return{active:i,strategy:o,budget:n.length,visible:a?n.map(e=>oc(e,a)):n,deferred:[],calloutList:[],hidden:[]};let c=[],u=n.map((e,n)=>({annotation:e,index:n,priority:ic(e,n,t)})).filter(e=>!!ia(e.annotation)||(c.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),h=l?u.filter(e=>"primary"===String(e.annotation.emphasis??"").toLowerCase()):[],p=new Set(h.map(e=>e.index)),f=u.filter(e=>!p.has(e.index)),m=[...h,...f].slice(0,Math.max(s,d)),g=new Set(m.map(e=>e.index)),y=u.filter(e=>!g.has(e.index)),x=[...c,...m.sort((e,t)=>e.index-t.index).map(e=>oc(e.annotation,a))],b=y.sort((e,t)=>e.index-t.index).map(e=>e.annotation),w=Math.max(0,t.maxCalloutItems??6),M=y.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,n,r){let i=rc(e,r);if(!i)return null;let o=nc(e.id)||nc(e.key)||nc(e.pointId)||`annotation-${t+1}`,a=tc(e.provenance)?nc(e.provenance.source)||nc(e.provenance.authorKind):void 0;return{id:o,label:i,shortLabel:nc(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:n,annotation:e}}(e.annotation,e.index,e.priority,a)).filter(e=>!!e).slice(0,w),v=new Set(M.map(e=>e.annotation)),k=b.filter(e=>!v.has(e));return{active:i,strategy:o,budget:s,visible:x,deferred:b,calloutList:M,hidden:k}}function lc(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function sc(e,t){let n=!1!==t.keepAxes,r=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:r,bottom:n?44:12,left:n?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:r,bottom:n?42:14,left:n?44:14}}function dc(e,t,n,r={}){let i={...n},o={mode:!1===t.mode?void 0:"mobile",...i,margin:sc(e,t),...r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),l=Object.fromEntries(Object.entries(o).filter(([,e])=>void 0!==e)),s=function(e,t){let n=t.targetSize??44,r=[],i=t.standardControls,o=e=>!0===i||"all"===i||i===e||Array.isArray(i)&&i.includes(e);return o("brush")&&r.push("range-inputs","clear-brush"),o("zoom")&&r.push("zoom-buttons","reset-view"),o("legend")&&r.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:n,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:n,...r.length>0&&{alternatives:r}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),d=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:`${e}-mobile`,description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...l,mobileInteraction:d,mobileSemantics:s}}],mobileInteraction:d,mobileSemantics:s}}function cc(e={}){let t=lc(e);return dc("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function uc(e={}){let t=lc(e);return dc("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function hc(e={}){return dc("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function pc(e={}){let t=lc(e);return dc("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function fc(e={}){let t=lc(e);return dc("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function mc(e={}){return dc("geo",e,{showLegend:e.showLegend??!1})}function gc(e={}){return dc("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function yc(e,t={}){switch(e){case"line":return cc(t);case"area":return uc(t);case"ordinal":return hc(t);case"scatter":return pc(t);case"network":return fc(t);case"geo":return mc(t);case"small-multiple":return gc(t)}}function xc(e={}){let t=e.targetSize??44,n=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:t,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:n,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:n}}function bc(e){return JSON.stringify([e.nodeId,e.endpoint.kind,"part"===e.endpoint.kind?e.endpoint.partId:null,e.endpoint.portId??null])}function wc(e,t=qe){return{nodeId:e,endpoint:t}}function Mc(e,t){return e<t?-1:e>t?1:0}function vc(e){return Array.isArray(e)?`[${e.map(vc).join(",")}]`:e&&"object"==typeof e?`{${Object.entries(e).filter(([,e])=>void 0!==e).sort(([e],[t])=>Mc(e,t)).map(([e,t])=>`${JSON.stringify(e)}:${vc(t)}`).join(",")}}`:JSON.stringify(e)??"null"}function kc(e){if(e&&"object"==typeof e&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))kc(t)}return e}function Ic(e,t,n={}){throw new Ve([{code:e,message:t,severity:"error",...n}])}function $c(e,t){let n=new Map;for(let r of e)("string"!=typeof r.id||!r.id||n.has(r.id))&&Ic("IDENTITY_DUPLICATE_OR_EMPTY",`IDs must be nonempty and unique in ${t}.`),n.set(r.id,r);return n}function Sc(e,t){let n=new Set;for(let r of e.keys()){let i=new Set,o=r;for(;void 0!==o&&!n.has(o);){i.has(o)&&Ic("IDENTITY_CONTAINMENT_CYCLE","Containment must be acyclic.");let n=e.get(o);n||Ic("IDENTITY_UNKNOWN_PARENT","Containment references an unknown parent."),i.add(o),o=t(n)}i.forEach(e=>n.add(e))}}function Nc(e,t,n){let r=e.get(t.nodeId);r||Ic("ENDPOINT_UNKNOWN_OWNER","Endpoint owner does not exist.",{endpointRefs:[t]});let i=t.endpoint;"node"!==i.kind&&"part"!==i.kind&&Ic("ENDPOINT_KIND","Unknown endpoint kind.");let o="part"===i.kind?r.parts?.find(e=>e.id===i.partId):void 0;if("part"===i.kind&&!o&&Ic("ENDPOINT_UNKNOWN_PART","Endpoint part does not exist.",{endpointRefs:[t]}),void 0===i.portId)return;let a=(o?o.ports:r.ports)?.find(e=>e.id===i.portId);a||Ic("ENDPOINT_UNKNOWN_PORT","Endpoint port does not exist.",{endpointRefs:[t]});let l="source"===n||"transfer-target"===n?"out":"in";return n&&a.direction!==l&&"inout"!==a.direction&&Ic("ENDPOINT_DIRECTION","Port direction is incompatible with its use.",{endpointRefs:[t]}),a}function Ac(e,t,n){let r=e.get(t)??[];r.push(n),e.set(t,r)}function Ec(e){let t=He.get(e);if(t)return t;let n=e.graph,r={nodes:new Map(n.nodes.map(e=>[e.id,e])),endpoints:new Map,ownerEndpoints:new Map,tracePolicies:new Map,incoming:new Map,outgoing:new Map,transferIn:new Map,transferOut:new Map},i=e=>{let t=bc(e);return r.endpoints.has(t)||Ac(r.ownerEndpoints,e.nodeId,e),r.endpoints.set(t,e),t},o=new Set(n.transfers?.map(e=>e.nodeId));for(let e of[...n.nodes].sort((e,t)=>Mc(e.id,t.id))){r.tracePolicies.set(e.id,e.tracePolicy??(e.parts?.length||e.ports?.length||o.has(e.id)?"explicit":"atomic")),i(wc(e.id));for(let t of e.ports??[])i(wc(e.id,{kind:"node",portId:t.id}));for(let t of e.parts??[]){i(wc(e.id,{kind:"part",partId:t.id}));for(let n of t.ports??[])i(wc(e.id,{kind:"part",partId:t.id,portId:n.id}))}}for(let e of[...n.edges].sort((e,t)=>Mc(e.id,t.id)))Ac(r.outgoing,i(wc(e.source,e.sourceEndpoint)),e),Ac(r.incoming,i(wc(e.target,e.targetEndpoint)),e);for(let e of[...n.transfers??[]].sort((e,t)=>Mc(e.id,t.id))){Ac(r.transferIn,i(wc(e.nodeId,e.target)),e);for(let t of e.sources)Ac(r.transferOut,i(wc(e.nodeId,t)),e)}for(let e of r.ownerEndpoints.values())e.sort((e,t)=>Mc(bc(e),bc(t)));return He.set(e,r),r}function Cc(e){"semiotic.compositional-graph.v0.1"!==e.schemaVersion&&Ic("IDENTITY_SCHEMA","Unknown graph schema."),("string"!=typeof e.graphId||!e.graphId||"string"!=typeof e.revision||!e.revision)&&Ic("IDENTITY_REVISION","Graph ID and revision are required.");let t=$c(e.nodes,"nodes");$c(e.edges,"edges"),$c(e.transfers??[],"transfers"),Sc(t,e=>e.parentId);let n,r=(e=[])=>{$c(e,"ports");for(let t of e)["in","out","inout"].includes(t.direction)||Ic("ENDPOINT_DIRECTION","Unknown port direction.")};for(let e of t.values()){e.tracePolicy&&!["atomic","explicit","opaque"].includes(e.tracePolicy)&&Ic("TRACE_POLICY","Unknown trace policy."),r(e.ports);let t=$c(e.parts??[],"owner parts");Sc(t,e=>e.parentPartId);for(let e of t.values())r(e.ports)}for(let n of e.edges)Nc(t,wc(n.source,n.sourceEndpoint),"source"),Nc(t,wc(n.target,n.targetEndpoint),"target");for(let n of e.transfers??[])(!n.sources.length||!["identity","all","any","unspecified"].includes(n.combination)||"identity"===n.combination&&1!==n.sources.length)&&Ic("ENDPOINT_TRANSFER","Transfers need inputs and a valid combination; identity needs one input."),new Set(n.sources.map(e=>bc(wc(n.nodeId,e)))).size!==n.sources.length&&Ic("ENDPOINT_TRANSFER","Transfer inputs must be distinct."),n.sources.forEach(e=>Nc(t,wc(n.nodeId,e),"transfer-source")),Nc(t,wc(n.nodeId,n.target),"transfer-target");try{n=JSON.parse(JSON.stringify(e,(e,t)=>{if("function"==typeof t||"symbol"==typeof t||"bigint"==typeof t||"number"==typeof t&&!Number.isFinite(t))throw new Error("Non-JSON value");return t}))}catch{Ic("IDENTITY_NONPORTABLE","Graph must be serializable JSON.")}let i=e=>[...e].sort((e,t)=>Mc(e.id,t.id)),o=kc({schemaVersion:"semiotic.prepared-compositional-graph.v0.1",graph:n,semanticHash:vc({graphId:n.graphId,nodes:i(n.nodes).map(({id:e,parentId:t,tracePolicy:n,ports:r,parts:o})=>({id:e,parentId:t,tracePolicy:n,ports:i(r??[]).map(({id:e,direction:t})=>({id:e,direction:t})),parts:i(o??[]).map(({id:e,parentPartId:t,ports:n})=>({id:e,parentPartId:t,ports:i(n??[]).map(({id:e,direction:t})=>({id:e,direction:t}))}))})),edges:i(n.edges).map(({data:e,...t})=>t),transfers:i(n.transfers??[])}),diagnostics:[]});return Ec(o),o}function Oc(e,t){(t.baseRevision!==e.graph.revision||t.revision===t.baseRevision)&&Ic("REVISION_PATCH_BASE","Patch requires the current base and a new revision.");let n=(e,t=[],n=[])=>{$c(n,"patch upserts");let r=new Map(e.map(e=>[e.id,e]));return t.forEach(e=>r.delete(e)),n.forEach(e=>r.set(e.id,e)),[...r.values()]};return Cc({...e.graph,revision:t.revision,nodes:n(e.graph.nodes,t.removeNodeIds,t.upsertNodes),edges:n(e.graph.edges,t.removeEdgeIds,t.upsertEdges),transfers:n(e.graph.transfers??[],t.removeTransferIds,t.upsertTransfers)})}function Tc(e,t){(!Number.isInteger(t.maxVisited)||t.maxVisited<1||!Number.isInteger(t.maxDepth)||t.maxDepth<0)&&Ic("TRACE_BUDGET","Trace budgets must be finite nonnegative integers, with at least one visit.");let n=Ec(e);Nc(n.nodes,t.start);let r="upstream"===t.direction,i=[{ref:t.start,depth:0}],o=new Set([bc(t.start)]),a=new Map,l=new Map,s=new Set,d=new Set,c=[],u="complete",h=e=>!t.kinds||t.kinds.includes(e??"unspecified"),p=(e,t,n)=>{l.has(bc(e))||c.push({code:t,severity:"warning",message:n,endpointRefs:[e]}),l.set(bc(e),e),"TRACE_BUDGET"===t?u="partial":"complete"===u&&(u="unknown")};for(let e=0;e<i.length;e++){let{ref:l,depth:c}=i[e];a.set(bc(l),l);let u=n.tracePolicies.get(l.nodeId),f="node"===l.endpoint.kind&&!l.endpoint.portId&&"atomic"!==u,m=f&&c>0&&"conservative-node"!==t.boundaryPolicy;f&&p(l,"TRACE_COARSE_BOUNDARY","Whole-node boundary does not establish exact interface provenance.");let g=e=>{let n=bc(e);return!!o.has(n)||(c>=t.maxDepth||o.size>=t.maxVisited?(p(l,"TRACE_BUDGET","Trace is partial within the supplied graph: visit or depth budget reached."),!1):(o.add(n),i.push({ref:e,depth:c+1}),!0))};if(!m)for(let e of(r?n.incoming:n.outgoing).get(bc(l))??[])h(e.kind)&&g(r?wc(e.source,e.sourceEndpoint):wc(e.target,e.targetEndpoint))&&s.add(e.id);for(let e of(r?n.transferIn:n.transferOut).get(bc(l))??[])if(h(e.kind)){d.add(e.id);for(let t of r?e.sources:[e.target])g(wc(e.nodeId,t))}if(f&&"conservative-node"===t.boundaryPolicy)for(let e of n.ownerEndpoints.get(l.nodeId)??[])g(e)}return kc({endpoints:[...a.values()],edgeIds:[...s].sort(Mc),transferIds:[...d].sort(Mc),completeness:u,boundaryRefs:[...l.values()],diagnostics:c})}function Rc(e,t,n=!0){return(!Number.isFinite(e)||n&&e<0)&&Ic("GEOMETRY_NUMBER",`${t} must be finite${n?" and nonnegative":""}.`),e}function Lc(e){Rc(e.x,"x",!1),Rc(e.y,"y",!1),Rc(e.width,"width"),Rc(e.height,"height")}function Fc(e){return[..."within-groups"===e.mode?e.groups.flatMap(e=>[...e.ids]):"optimize"===e.mode?e.initialIds:e.ids]}function Pc(e,t){let n=Fc(e);(n.length!==t.length||new Set(n).size!==n.length||t.some(e=>!n.includes(e)))&&Ic("ORDER_MEMBERS","An order must contain every participating member exactly once."),"within-groups"===e.mode&&new Set(e.groups.map(e=>e.id)).size!==e.groups.length&&Ic("ORDER_GROUPS","Order group IDs must be unique.")}function zc(e,t,n){return"optimize"===e.mode||"within-groups"===e.mode&&e.groups.some(e=>!e.fixed&&e.ids.includes(t)&&e.ids.includes(n))}function Dc(e,t,n,r=Fc(t.order)){let i="LR"===n||"RL"===n,o=t.padding;Object.entries(o).forEach(([e,t])=>Rc(t,e)),Rc(t.headerHeight,"headerHeight"),Rc(t.rowGap,"rowGap"),Rc(t.defaultRowHeight,"defaultRowHeight");let a=new Map;for(let e of t.rowHeights??[])(a.has(e.partId)||!r.includes(e.partId))&&Ic("ORDER_ROW_HEIGHT","Row size IDs must be unique participating parts."),a.set(e.partId,Rc(e.height,"rowHeight"));let l=t.headerHeight+(i?o.top:o.left),s=i?e.width-o.left-o.right:e.height-o.top-o.bottom;Rc(s,"available row breadth");let d=r.map(e=>{let n=a.get(e)??t.defaultRowHeight,r=i?{x:o.left,y:l,width:s,height:n}:{x:l,y:o.top,width:n,height:s};return l+=n+t.rowGap,{partId:e,rect:r}});return l-(d.length?t.rowGap:0)+(i?o.bottom:o.right)>(i?e.height:e.width)+1e-8&&Ic("GEOMETRY_FOOTPRINT","Rows exceed the supplied node footprint.",{nodeIds:[e.nodeId]}),{...e,parts:d,actualPartOrder:r}}function jc(e,t,n=.5){switch((!Number.isFinite(n)||n<0||n>1)&&Ic("GEOMETRY_FRACTION","Anchor fraction must be in [0,1]."),t){case"north":return{point:{x:e.x+e.width*n,y:e.y},normal:{x:0,y:-1}};case"south":return{point:{x:e.x+e.width*n,y:e.y+e.height},normal:{x:0,y:1}};case"east":return{point:{x:e.x+e.width,y:e.y+e.height*n},normal:{x:1,y:0}};case"west":return{point:{x:e.x,y:e.y+e.height*n},normal:{x:-1,y:0}};default:return Ic("GEOMETRY_SIDE","Unknown anchor side.")}}function _c(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let o of e)t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),i=Math.max(i,o.y+o.height);return{x:t,y:n,width:r-t,height:i-n}}function Wc(e){return _c(e.map(e=>({...e,width:0,height:0})))}function Gc(e,t){return e.x<t.x+t.width-1e-8&&e.x+e.width>t.x+1e-8&&e.y<t.y+t.height-1e-8&&e.y+e.height>t.y+1e-8}function Yc(e,t){return t.x>=e.x-1e-8&&t.x<=e.x+e.width+1e-8&&t.y>=e.y-1e-8&&t.y<=e.y+e.height+1e-8}function Bc(e){let t=new Map;for(let n of e.nodes){t.has(n.nodeId)&&Ic("GEOMETRY_DUPLICATE","Duplicate node measurement."),Rc(n.width,"width"),Rc(n.height,"height");let e=new Set;for(let t of n.parts)e.has(t.partId)&&Ic("GEOMETRY_DUPLICATE","Duplicate part measurement."),e.add(t.partId),Lc(t.rect),(!Yc({x:0,y:0,width:n.width,height:n.height},t.rect)||!Yc({x:0,y:0,width:n.width,height:n.height},{x:t.rect.x+t.rect.width,y:t.rect.y+t.rect.height}))&&Ic("GEOMETRY_PART_BOUNDS","Part measurement exceeds its owner.");let r=new Set;for(let e of[...(n.markAnchors??[]).map(e=>({...e,key:JSON.stringify(["mark",e.markId,e.anchorName])})),...(n.slotAnchors??[]).map(e=>({...e,key:JSON.stringify(["slot",e.groupId,e.slotId])}))])r.has(e.key)&&Ic("GEOMETRY_DUPLICATE","Duplicate named anchor."),r.add(e.key),Rc(e.point.x,"anchor x",!1),Rc(e.point.y,"anchor y",!1),Rc(e.normal.x,"normal x",!1),Rc(e.normal.y,"normal y",!1);for(let e of[...n.routingChannels??[],...n.obstacleRects??[]])Lc(e);t.set(n.nodeId,n)}return t}function qc(e,t){return JSON.stringify([bc(e),t])}function Vc(e,t,n){return n.some(n=>Math.abs(e.x-t.x)<Ue?e.x>n.x+Ue&&e.x<n.x+n.width-Ue&&Math.max(e.y,t.y)>n.y+Ue&&Math.min(e.y,t.y)<n.y+n.height-Ue:!(Math.abs(e.y-t.y)<Ue)||e.y>n.y+Ue&&e.y<n.y+n.height-Ue&&Math.max(e.x,t.x)>n.x+Ue&&Math.min(e.x,t.x)<n.x+n.width-Ue)}function Hc(e){let t=[];for(let n of e)t.length&&Xe(t[t.length-1],n)<Ue||t.push(n);return t}function Uc(e,t,n,r,i,o=4e4){let a=e=>e.every((t,r)=>0===r||!Vc(e[r-1],t,n)),l=i?(e.x+t.x)/2+r:(e.y+t.y)/2+r,s=i?[e,{x:l,y:e.y},{x:l,y:t.y},t]:[e,{x:e.x,y:l},{x:t.x,y:l},t];if(a(s))return Hc(s);let d=[],c=[...new Set([e.x,t.x,...n.flatMap(e=>[e.x,e.x+e.width])])].sort((e,t)=>e-t),u=[...new Set([e.y,t.y,...n.flatMap(e=>[e.y,e.y+e.height])])].sort((e,t)=>e-t);for(let n of c)d.push([e,{x:n,y:e.y},{x:n,y:t.y},t]);for(let n of u)d.push([e,{x:e.x,y:n},{x:t.x,y:n},t]);let h=d.filter(a).sort((e,t)=>Ke(e)-Ke(t));if(h.length)return Hc(h[0]);if(c.length*u.length>o)return null;let p=c.length,f=p*u.length,m=u.indexOf(e.y)*p+c.indexOf(e.x),g=u.indexOf(t.y)*p+c.indexOf(t.x),y=new Float64Array(f).fill(1/0),x=new Int32Array(f).fill(-1),b=e=>({x:c[e%p],y:u[Math.floor(e/p)]}),w=[],M=(e,n)=>{let r={id:e,cost:n,priority:n+Xe(b(e),t)};w.push(r);let i=w.length-1;for(;i>0;){let e=i-1>>1;if(w[e].priority<=r.priority)break;w[i]=w[e],i=e}w[i]=r},v=()=>{let e=w[0],t=w.pop();if(w.length){let e=0;for(;2*e+1<w.length;){let n=2*e+1;if(n+1<w.length&&w[n+1].priority<w[n].priority&&n++,w[n].priority>=t.priority)break;w[e]=w[n],e=n}w[e]=t}return e};y[m]=0,M(m,0);let k=0;for(;w.length&&k++<o;){let{id:e,cost:t}=v();if(t!==y[e])continue;if(e===g){let e=[];for(let t=g;t>=0;t=x[t])e.push(b(t));return Hc(e.reverse())}let r=e%p,i=Math.floor(e/p),o=[r>0?e-1:-1,r+1<p?e+1:-1,i>0?e-p:-1,i+1<u.length?e+p:-1];for(let r of o){if(r<0||Vc(b(e),b(r),n))continue;let i=t+Xe(b(e),b(r));i+Ue<y[r]&&(y[r]=i,x[r]=e,M(r,i))}}return null}function Xc(e,t,n,r){let i=[{kind:"M",point:t[0]}];for(let e=1;e<t.length-1;e++){let o=t[e],a=t[e-1],l=t[e+1],s=Math.min(4,Xe(a,o)/3,Xe(l,o)/3),d=e=>({x:o.x+(e.x-o.x)*s/Xe(o,e),y:o.y+(e.y-o.y)*s/Xe(o,e)}),c=d(a),u=d(l),h=Wc([c,o,u]),p=r.some(e=>h.x<e.x+e.width&&h.x+h.width>e.x&&h.y<e.y+e.height&&h.y+h.height>e.y);n&&s>Ue&&e>1&&e<t.length-2&&!p?i.push({kind:"L",point:c},{kind:"C",control1:o,control2:o,point:u}):i.push({kind:"L",point:o})}return i.push({kind:"L",point:t[t.length-1]}),{id:e,points:t,commands:i,bounds:Wc(i.flatMap(e=>"C"===e.kind?[e.control1,e.control2,e.point]:[e.point]))}}function Kc(e){return(e.commands?.length?e.commands:e.points.map((e,t)=>({kind:t?"L":"M",point:e}))).map(e=>"C"===e.kind?`C${e.control1.x},${e.control1.y} ${e.control2.x},${e.control2.y} ${e.point.x},${e.point.y}`:`${e.kind}${e.point.x},${e.point.y}`).join(" ")}function Jc(e){let t=[];for(let n of e.commands??[]){if("C"!==n.kind){t.push(n.point);continue}let e=t[t.length-1],r=n.control1,i=n.control2,o=n.point;for(let n=1;n<=24;n++){let a=n/24,l=1-a;t.push({x:l**3*e.x+3*l**2*a*r.x+3*l*a**2*i.x+a**3*o.x,y:l**3*e.y+3*l**2*a*r.y+3*l*a**2*i.y+a**3*o.y})}}return t.length?t:[...e.points]}function Zc(e,t,n,r){let i=t.x-e.x,o=t.y-e.y,a=r.x-n.x,l=r.y-n.y,s=i*l-o*a;if(Math.abs(s)<1e-8)return null;let d=((n.x-e.x)*l-(n.y-e.y)*a)/s,c=((n.x-e.x)*o-(n.y-e.y)*i)/s;return d>=0&&d<=1&&c>=0&&c<=1?{x:e.x+d*i,y:e.y+d*o}:null}function Qc(e,t,n){let r=0,i=0,o=0,a=0,l=0,s=0,d=e.map(e=>e.sections.flatMap(Jc));for(let a=0;a<e.length;a++){let l=e[a],s=d[a];n.has(l.edgeId)&&(o+=Math.abs(t?l.source.anchor.y-l.target.anchor.y:l.source.anchor.x-l.target.anchor.x));for(let e=1;e<s.length;e++)r+=Xe(s[e-1],s[e]),e>1&&Math.abs((s[e-1].x-s[e-2].x)*(s[e].y-s[e-1].y)-(s[e-1].y-s[e-2].y)*(s[e].x-s[e-1].x))>1e-8&&i++}let c=t=>{let n=1/0,r=-1/0;for(let i of e)n=Math.min(n,i.bounds[t]),r=Math.max(r,i.bounds[t]);return e.length?r-n:0},u=c("x")>=c("y")?"x":"y",h="x"===u?"width":"height",p="x"===u?"y":"x",f="x"===u?"height":"width",m=e.map((e,t)=>({e:e,i:t})).sort((e,t)=>e.e.bounds[u]-t.e.bounds[u]),g=!1;e:for(let e=0;e<m.length;e++)for(let t=e+1;t<m.length;t++){let n=m[e],r=m[t];if(r.e.bounds[u]>n.e.bounds[u]+n.e.bounds[h])break;if(n.e.bounds[p]>r.e.bounds[p]+r.e.bounds[f]||r.e.bounds[p]>n.e.bounds[p]+n.e.bounds[f])continue;let i=new Set,o=d[n.i],c=d[r.i],y=[n.e.source,n.e.target].flatMap(e=>[r.e.source,r.e.target].filter(t=>Xe(e.anchor,t.anchor)<1e-8&&Xe(e.escape,t.escape)<1e-8).map(()=>[e.anchor,e.escape])),x=e=>y.some(([t,n])=>Math.abs(Xe(t,e)+Xe(e,n)-Xe(t,n))<1e-7);for(let e=1;e<o.length;e++)for(let t=1;t<c.length;t++){if(++l>2e6){g=!0;break e}let n=Zc(o[e-1],o[e],c[t-1],c[t]);n&&!x(n)&&i.add(`${n.x.toFixed(6)},${n.y.toFixed(6)}`);let r=o[e-1],a=o[e],d=c[t-1],u=c[t],h=Math.abs(r.x-a.x)<1e-8&&Math.abs(r.x-d.x)<1e-8&&Math.abs(r.x-u.x)<1e-8,p=Math.abs(r.y-a.y)<1e-8&&Math.abs(r.y-d.y)<1e-8&&Math.abs(r.y-u.y)<1e-8;if(h||p){let e=h?"y":"x",t=Math.max(Math.min(r[e],a[e]),Math.min(d[e],u[e])),n=Math.min(Math.max(r[e],a[e]),Math.max(d[e],u[e]));n>t&&!x(h?{x:r.x,y:(t+n)/2}:{x:(t+n)/2,y:r.y})&&(s+=n-t)}}a+=i.size}return{metrics:{crossings:a,channelCongestion:s,alignmentError:o,totalRouteLength:r,bendCount:i,nodeDisplacement:0,reorderedParts:0,hardConstraintViolations:0,routedEdgeCount:e.length,omittedEdgeCount:0,completedSweeps:0},partial:g}}function eu(e,t){let n=new Map;for(let r of e??[]){let e=t(r);n.has(e)||n.set(e,r)}return n}function tu(e){let{graph:t}=e.prepared,n=new Map(t.nodes.map(e=>[e.id,e])),r=new Map(e.view.nodes.map(e=>[e.nodeId,e]));r.size!==e.view.nodes.length&&Ic("IDENTITY_VIEW","Duplicate node presentations.");for(let e of r.keys())n.has(e)||Ic("IDENTITY_VIEW","Unknown presentation owner.");let i=new Map;for(let e of t.nodes){let t=e.parentId;for(;t;)"summary"===r.get(t)?.mode&&i.set(e.id,t),t=n.get(t)?.parentId}return{semantics:n,views:r,hidden:i}}function nu(e,t,n,r,i){let{view:o}=e,{semantics:a}=t,l=t.hidden.get(r.nodeId),s=l??r.nodeId,d=t.bySemantic.get(s),c=t.measures.get(s),u=t.presentations.get(s),h="summary"===u?.mode&&("part"===r.endpoint.kind||!!r.endpoint.portId),p=l||h?t.exposures.get(Je(s,qc(r,i))):void 0;(l||h)&&!p&&Ic("ENDPOINT_MISSING_EXPOSURE","Collapsed endpoints need explicit boundary exposures.",{endpointRefs:[r]});let f=t.anchors.get(qc(r,i)),m=p?.binding??f?.binding,g=function(e,t){return{LR:["east","west"],RL:["west","east"],TB:["south","north"],BT:["north","south"]}[e]["source"===t?0:1]}(o.direction,i);if(!m){let e={x:0,y:0,width:d.rect.width,height:d.rect.height};if("part"===r.endpoint.kind){let n=r.endpoint.partId,i=d.parts?.find(e=>e.partId===n);i||Ic("GEOMETRY_MISSING_PART","Endpoint has no solved part geometry.",{endpointRefs:[r]}),e=i.rect,"exploded"===u?.mode&&(d=t.byId.get(JSON.stringify(["part",s,n])),e={...e,x:0,y:0})}let n=.5;if(r.endpoint.portId){let e=a.get(r.nodeId),o="part"===r.endpoint.kind?r.endpoint.partId:void 0,l=((o?e.parts?.find(e=>e.id===o)?.ports:e.ports)??[]).filter(e=>"inout"===e.direction||e.direction===("source"===i?"out":"in")).map(e=>e.id).sort(Mc),s=t.portOrders.get(Ze(r.nodeId,o,i,g));s&&Pc(s.order,l);let d=s?Fc(s.order):l;n=(d.indexOf(r.endpoint.portId)+1)/(d.length+1)}let o=jc(e,g,n).point;n="west"===g||"east"===g?o.y/(d.rect.height||1):o.x/(d.rect.width||1),m={kind:"node-side",side:g,fraction:n}}let y=function(e,t,n){switch(e.kind){case"node-side":return jc({x:0,y:0,width:t.rect.width,height:t.rect.height},e.side,e.fraction);case"part-side":{let n=t.parts?.find(t=>t.partId===e.partId);return n?jc(n.rect,e.side,e.fraction):Ic("GEOMETRY_UNKNOWN_PART","Anchor has no solved part rectangle.")}case"point":return e;case"named-mark":{let t=n.markAnchors?.find(t=>t.markId===e.markId&&t.anchorName===e.anchorName);return t||Ic("GEOMETRY_UNKNOWN_MARK","Named mark anchor is unresolved.")}case"slot":{let t=n.slotAnchors?.find(t=>t.groupId===e.groupId&&t.slotId===e.slotId);return t||Ic("GEOMETRY_UNKNOWN_SLOT","Named slot is unresolved.")}}}(m,d,c);Rc(y.point.x,"anchor x",!1),Rc(y.point.y,"anchor y",!1);let x={x:y.normal.x,y:y.normal.y};1===Math.abs(x.x)&&0===x.y||1===Math.abs(x.y)&&0===x.x||Ic("CAPABILITY_NORMAL","The built-in orthogonal adapter requires cardinal unit normals.");let b={x:0,y:0,width:d.rect.width,height:d.rect.height};Yc(b,y.point)||Ic("GEOMETRY_ANCHOR_BOUNDS","Anchor is outside the display node.");let w={x:x.x>0?b.width:x.x<0?0:y.point.x,y:x.y>0?b.height:x.y<0?0:y.point.y};if(!("point"!==m.kind&&"named-mark"!==m.kind&&"slot"!==m.kind||w.x===y.point.x&&w.y===y.point.y)){let e=c.routingChannels??[],t=[0,1,...e.flatMap(e=>x.x?[(e.x-y.point.x)/(w.x-y.point.x),(e.x+e.width-y.point.x)/(w.x-y.point.x)]:[(e.y-y.point.y)/(w.y-y.point.y),(e.y+e.height-y.point.y)/(w.y-y.point.y)])].filter(e=>e>=0&&e<=1).sort((e,t)=>e-t);t.slice(1).some((n,r)=>!e.some(e=>Yc(e,{x:y.point.x+(w.x-y.point.x)*(n+t[r])/2,y:y.point.y+(w.y-y.point.y)*(n+t[r])/2})))&&Ic("CONSTRAINT_INTERIOR_ESCAPE","Interior mark needs a declared straight escape corridor.",{edgeIds:[n]})}let M=(d.parts??[]).filter(e=>"part-side"!==m.kind||e.partId!==m.partId).map(e=>e.rect);Vc(y.point,w,[...c.obstacleRects??[],..."part-side"===m.kind?M:[]])&&Ic("CONSTRAINT_INTERIOR_ESCAPE","Terminal escape intersects an obstacle.",{edgeIds:[n]});let v=Math.max(e.options.terminalStub,e.options.obstaclePadding);return{edgeId:n,end:i,semantic:r,displayNodeId:d.id,anchor:{x:d.rect.x+y.point.x,y:d.rect.y+y.point.y},escape:{x:d.rect.x+w.x+x.x*v,y:d.rect.y+w.y+x.y*v},normal:x,precision:p?"proxy":"exact",exposureId:p?.id}}function ru(e,t){let n=new Map(e.map(e=>[e,0])),r=new Map;for(let[e,i]of t){let t=r.get(e)??new Set;t.has(i)||(t.add(i),n.set(i,(n.get(i)??0)+1)),r.set(e,t)}let i=e.filter(e=>!n.get(e)).sort(Mc),o=new Map(e.map(e=>[e,0])),a=0;for(let e=0;e<i.length;e++){let t=i[e];a++;for(let e of[...r.get(t)??[]].sort(Mc))o.set(e,Math.max(o.get(e)??0,o.get(t)+1)),n.set(e,n.get(e)-1),n.get(e)||i.push(e)}return a===e.length?o:null}function iu(e,t){let n=e.previous;if(!n)return;let r=et.get(n);return r||(r=new Map(n.nodes.map(e=>[e.id,e])),et.set(n,r)),r.get(t)}function ou(e){return{topology:"strict-dag",routing:"orthogonal",bundles:"none",rankGap:96,nodeGap:32,laneGap:6,terminalStub:12,obstaclePadding:6,maxSweeps:8,seed:0,...e,weights:{crossings:8,alignment:2,length:1,bends:1,congestion:4,displacement:4,reorder:3,...e.weights}}}function au(e){return{schemaVersion:"semiotic.compositional-layout.v0.1",requestId:e.requestId,semanticHash:e.prepared.semanticHash,graphRevision:e.prepared.graph.revision,viewRevision:e.view.revision,geometryRevision:e.geometry.revision,engineId:"semiotic-compositional",engineVersion:"0.1.0",optionsHash:vc(e.options),status:"complete",nodes:[],edges:[],bundles:[],bounds:{x:0,y:0,width:0,height:0},metrics:{crossings:0,channelCongestion:0,alignmentError:0,totalRouteLength:0,bendCount:0,nodeDisplacement:0,reorderedParts:0,hardConstraintViolations:0,routedEdgeCount:0,omittedEdgeCount:e.prepared.graph.edges.length,completedSweeps:0},diagnostics:[]}}function lu(e,t,n,r){let i=function(e,t,n,r){let{graph:i}=e.prepared,{semantics:o,views:a,hidden:l}=tu(e),s=[],d=new Map,c=new Map;for(let u of[...i.nodes].sort((e,t)=>Mc(e.id,t.id))){if(l.has(u.id))continue;let i=t.get(u.id);i||Ic("GEOMETRY_MISSING","Every visible owner needs geometry.",{nodeIds:[u.id]});let h=a.get(u.id),p=h?.partLayout;if("rows"===p?.kind){Pc(p.order,(u.parts??[]).map(e=>e.id));let t=r.get(u.id)??Fc(p.order);"fixed"!==p.order.mode&&(i.markAnchors?.length||i.slotAnchors?.length||e.view.anchors?.some(e=>e.ref.nodeId===u.id&&["point","named-mark","slot"].includes(e.binding.kind)))&&Ic("CONSTRAINT_ABSOLUTE_REORDER","Absolute anchors require fixed row order or a custom reflow adapter.",{nodeIds:[u.id]}),i=Dc(i,p,e.view.direction,t)}"summary"!==h?.mode&&(u.parts??[]).some(e=>!i.parts.some(t=>t.partId===e.id))&&Ic("GEOMETRY_MISSING_PART","Every visible part needs a rectangle.",{nodeIds:[u.id]}),i.parts.some(e=>!u.parts?.some(t=>t.id===e.partId))&&Ic("GEOMETRY_UNKNOWN_PART","Measured part does not exist.");let f=n.get(u.id),m={id:u.id,semantic:wc(u.id),rect:{...f,width:i.width,height:i.height},parts:i.parts.map(e=>({...e,rect:{...e.rect},semantic:wc(u.id,{kind:"part",partId:e.partId})})),partOrder:i.actualPartOrder&&[...i.actualPartOrder],markAnchors:i.markAnchors?.map(Qe),slotAnchors:i.slotAnchors?.map(Qe)};if(s.push(m),d.set(u.id,m),c.set(u.id,i),"exploded"===h?.mode)for(let e of m.parts??[]){let t=JSON.stringify(["part",u.id,e.partId]);o.has(t)&&Ic("IDENTITY_PROJECTION_COLLISION","A semantic ID collides with an exploded display ID."),s.push({id:t,semantic:e.semantic,rect:{...e.rect,x:f.x+e.rect.x,y:f.y+e.rect.y}})}}for(let e=0;e<s.length;e++)for(let t=e+1;t<s.length;t++){let n=s[e],r=s[t];if("part"===n.semantic.endpoint.kind||"part"===r.semantic.endpoint.kind)continue;let i=(e,t)=>{let n=e.parentId;for(;n;){if(n===t)return!0;n=o.get(n)?.parentId}return!1},a=i(o.get(n.id),r.id),l=i(o.get(r.id),n.id);if(a||l){let e=a?n:r,t=a?r:n;(!Yc(t.rect,e.rect)||!Yc(t.rect,{x:e.rect.x+e.rect.width,y:e.rect.y+e.rect.height}))&&Ic("CONSTRAINT_CONTAINMENT","Authored child bounds exceed the containing owner.",{nodeIds:[e.id,t.id]})}else Gc(n.rect,r.rect)&&Ic("CONSTRAINT_OVERLAP","Node boxes overlap.",{nodeIds:[n.id,r.id]})}let{view:u}=e;return{nodes:s,hidden:l,bySemantic:d,measures:c,semantics:o,presentations:a,anchors:eu(u.anchors,e=>qc(e.ref,e.use)),exposures:eu(u.boundaryExposures,e=>Je(e.containerNodeId,qc(e.inner,e.use))),portOrders:eu(u.portOrders,e=>Ze(e.nodeId,e.partId,e.use,e.side)),byId:new Map(s.map(e=>[e.id,e]))}}(e,t,n,r),o=function(e,t){let n=t.nodes.filter(e=>"node"===e.semantic.endpoint.kind).map(e=>e.id),r=e=>t.hidden.get(e)??e,i=ru(n,e.prepared.graph.edges.filter(e=>r(e.source)!==r(e.target)).map(e=>[r(e.source),r(e.target)]));return!i&&"strict-dag"===e.options.topology&&Ic("TOPOLOGY_PROJECTION_CYCLE","The display quotient is cyclic; expand the group or explicitly select feedback mode."),i??new Map(n.sort(Mc).map((e,t)=>[e,t]))}(e,i),a="LR"===e.view.direction||"RL"===e.view.direction,l=[],s=[],d=new Map(e.view.edgeHints?.map(e=>[e.edgeId,e])),c=[...e.prepared.graph.edges].sort((e,t)=>Mc(d.get(e.id)?.laneId??"",d.get(t.id)?.laneId??"")||Mc(e.id,t.id)),u=e=>JSON.stringify([bc(wc(e.source,e.sourceEndpoint)),bc(wc(e.target,e.targetEndpoint))]),h=new Map;for(let e of c){let t=u(e),n=h.get(t)??[];n.push(e.id),h.set(t,n)}let p=new Map;for(let e of c){let t=JSON.stringify([e.source,e.target]),n=p.get(t)??[];n.push(e.id),p.set(t,n)}let f=i.nodes.filter(e=>"node"===e.semantic.endpoint.kind),m=e.options.obstaclePadding,g=f.map(e=>({x:e.rect.x-m,y:e.rect.y-m,width:e.rect.width+2*m,height:e.rect.height+2*m})),y=e.prepared.graph.nodes.some(e=>e.parentId);for(let t of c){let n=nu(e,i,t.id,wc(t.source,t.sourceEndpoint),"source"),r=nu(e,i,t.id,wc(t.target,t.targetEndpoint),"target"),l=h.get(u(t)),d=(l.indexOf(t.id)-(l.length-1)/2)*e.options.laneGap;l.length>1&&0===e.options.laneGap&&"none"===e.options.bundles&&Ic("ROUTING_COINCIDENT","Exact duplicates require lane space or an explicit bundle.",{edgeIds:l});let c=(e,t)=>({x:e.x-t.y*d,y:e.y+t.x*d}),m=c(n.escape,n.normal),x=c(r.escape,{x:-r.normal.x,y:-r.normal.y});y&&f.some(e=>e.id!==n.displayNodeId&&e.id!==r.displayNodeId&&e.id!==t.source&&e.id!==t.target&&[n.anchor,r.anchor].some(t=>t.x>e.rect.x&&t.x<e.rect.x+e.rect.width&&t.y>e.rect.y&&t.y<e.rect.y+e.rect.height))&&Ic("CAPABILITY_COMPOUND_ROUTING","Cross-hierarchy routing needs collapsed authored boundary exposures.",{edgeIds:[t.id]});let b=n.displayNodeId!==t.source||r.displayNodeId!==t.target?g.filter((e,i)=>!(n.displayNodeId!==t.source&&f[i].id===t.source||r.displayNodeId!==t.target&&f[i].id===t.target)):g;(Vc(n.escape,m,b)||Vc(x,r.escape,b))&&Ic("ROUTING_LANE_SPACE","Pinned terminal lanes have insufficient clearance.",{edgeIds:[t.id]});let w=p.get(JSON.stringify([t.source,t.target])),M=Uc(m,x,b,(w.indexOf(t.id)-(w.length-1)/2)*e.options.laneGap,a);M||Ic("ROUTING_NO_PATH","No route found within the adapter's visibility-grid budget.",{edgeIds:[t.id]});let v=Hc([n.anchor,n.escape,...M,r.escape,r.anchor]),k=Xc(JSON.stringify([t.id,"route"]),v,"smooth"===e.options.routing,b),I=e=>i.hidden.get(e)??e,$=I(t.source)!==I(t.target)&&o.get(I(t.source))>=o.get(I(t.target));s.push({edgeId:t.id,source:n,target:r,sections:[k],bounds:k.bounds,feedback:$})}let x=new Set(c.filter(e=>"none"!==d.get(e.id)?.alignment).map(e=>e.id)),{metrics:b,partial:w}=Qc(s,a,x);b.channelCongestion>1e-8&&l.push({code:"ROUTING_CONGESTION",severity:"warning",message:"Some routes share undeclared segments. Every edge is retained; use the connection table to disambiguate.",edgeIds:s.map(e=>e.edgeId)}),w&&l.push({code:"ROUTING_METRIC_BUDGET",severity:"warning",message:"Crossing count is a lower bound after two million segment comparisons."}),"estimated"===e.geometry.basis&&l.push({code:"GEOMETRY_ESTIMATED",severity:"warning",message:"Attachment geometry is provisional."}),"smooth"===e.options.routing&&l.push({code:"ROUTING_CURVE_METRICS",severity:"info",message:"Curve length and crossings use 24 samples per corner; bounds use conservative control envelopes."});let M=[];if("none"!==e.options.bundles){let t=new Map;for(let e of s){let n=c.find(t=>t.id===e.edgeId),r=JSON.stringify(["bundle",e.source.displayNodeId,e.target.displayNodeId,e.source.exposureId??bc(e.source.semantic),e.target.exposureId??bc(e.target.semantic),n.kind??"unspecified",d.get(n.id)?.bundleGroup??null]),i=t.get(r)??[];i.push(e),t.set(r,i)}for(let[n,r]of t)r.length>1&&M.push({id:n,kind:e.options.bundles,memberEdgeIds:r.map(e=>e.edgeId),path:r[0].sections,count:r.length,countStatus:"exact",semanticKind:c.find(e=>e.id===r[0].edgeId)?.kind??"unspecified"})}return{...au(e),status:w||b.channelCongestion>1e-8||"estimated"===e.geometry.basis?"degraded":"complete",nodes:i.nodes,edges:s,bundles:M,bounds:_c([...i.nodes.map(e=>e.rect),...s.map(e=>e.bounds)]),metrics:b,diagnostics:l}}function su(e,t,n){let r=e.metrics,i=ou(t.options).weights,o=Math.max(1,t.options.rankGap),a=t.view.nodes.reduce((e,t)=>"rows"===t.partLayout?.kind?e+Fc(t.partLayout.order).filter((e,r)=>n.get(t.nodeId)?.[r]!==e).length:e,0),l=e.nodes.filter(e=>"node"===e.semantic.endpoint.kind),s=l.reduce((e,n)=>{let r=iu(t,n.id);return e+(r?Xe(r.rect,n.rect):0)},0);return i.crossings*r.crossings+i.alignment*r.alignmentError/o+i.length*r.totalRouteLength/o+i.bends*r.bendCount+i.congestion*r.channelCongestion/o+i.reorder*a/Math.max(1,l.length)+i.displacement*s/o}function du(e){let t={...e,options:ou(e.options)};try{(function(e){let t=e.options;(!["route-only","optimize"].includes(t.mode)||!["strict-dag","feedback"].includes(t.topology)||!["orthogonal","polyline","smooth"].includes(t.routing)||!["none","parallel","overview"].includes(t.bundles)||!["LR","RL","TB","BT"].includes(e.view.direction))&&Ic("CAPABILITY_OPTIONS","Unknown layout mode, direction, routing or topology.");for(let e of["rankGap","nodeGap","laneGap","terminalStub","obstaclePadding","maxSweeps"])Rc(t[e],e);(!Number.isInteger(t.maxSweeps)||t.maxSweeps>100)&&Ic("CONSTRAINT_BUDGET","maxSweeps must be an integer in [0,100]."),Number.isSafeInteger(t.seed)||Ic("CONSTRAINT_SEED","Seed must be a safe integer."),Object.entries(t.weights??{}).forEach(([e,t])=>Rc(t,e)),"optimize"===t.mode&&e.prepared.graph.nodes.some(e=>e.parentId)&&Ic("CAPABILITY_COMPOUND_OPTIMIZE","Compound graphs require authored positions in this adapter.");let n=new Set;for(let t of e.view.edgeHints??[])(n.has(t.edgeId)||!e.prepared.graph.edges.some(e=>e.id===t.edgeId))&&Ic("IDENTITY_EDGE_HINT","Edge hints must refer to unique existing edges."),n.add(t.edgeId),void 0!==t.priority&&Rc(t.priority,"priority")})(t),function(e){[e.requestId,e.view.revision,e.geometry.revision].every(e=>"string"==typeof e&&e.length>0)||Ic("REVISION_REQUIRED","Request, view and geometry revisions must be nonempty strings.");let t=new Map(e.prepared.graph.nodes.map(e=>[e.id,e])),n=new Set;for(let r of e.view.anchors??[]){Nc(t,r.ref,r.use);let e=qc(r.ref,r.use);n.has(e)&&Ic("IDENTITY_ANCHOR","Duplicate endpoint/use anchor."),n.add(e)}let r=new Set,i=new Set;for(let n of e.view.boundaryExposures??[]){Nc(t,n.inner,n.use);let e=n.inner.nodeId;for(;e&&e!==n.containerNodeId;)e=t.get(e)?.parentId;e||Ic("ENDPOINT_EXPOSURE_OWNER","Exposure must refer to an endpoint inside its container.");let o=JSON.stringify([n.containerNodeId,qc(n.inner,n.use)]);(r.has(n.id)||i.has(o))&&Ic("IDENTITY_EXPOSURE","Duplicate boundary exposure."),r.add(n.id),i.add(o)}let o=new Set;for(let n of e.view.portOrders??[]){let e=n.partId?{kind:"part",partId:n.partId}:{kind:"node"};Nc(t,wc(n.nodeId,e));let r=t.get(n.nodeId),i=((n.partId?r.parts?.find(e=>e.id===n.partId)?.ports:r.ports)??[]).filter(e=>"inout"===e.direction||e.direction===("source"===n.use?"out":"in"));Pc(n.order,i.map(e=>e.id));let a=JSON.stringify([n.nodeId,n.partId??null,n.side,n.use]);o.has(a)&&Ic("ORDER_PORT_DUPLICATE","Repeated port order constraint."),o.add(a),"fixed"!==n.order.mode&&Ic("CAPABILITY_PORT_ORDER","This adapter supports fixed port order; port permutation needs another adapter.")}}(t),function(e){let t=new Set,n=[],r=(e,r)=>{t.add(e),t.add(r),n.push([e,r])};for(let t of e.prepared.graph.edges)r(bc(wc(t.source,t.sourceEndpoint)),bc(wc(t.target,t.targetEndpoint)));for(let t of e.prepared.graph.transfers??[])for(let e of t.sources)r(bc(wc(t.nodeId,e)),bc(wc(t.nodeId,t.target)));!ru([...t],n)&&"strict-dag"===e.options.topology&&Ic("TOPOLOGY_SEMANTIC_CYCLE","Connections and transfers contain a semantic cycle.")}(t);let e=Bc(t.geometry),n=function(e){let t=new Map(e.view.constraints?.map(e=>[e.nodeId,e]));t.size!==(e.view.constraints?.length??0)&&Ic("CONSTRAINT_DUPLICATE","Duplicate node constraints.");for(let n of t.values())e.prepared.graph.nodes.some(e=>e.id===n.nodeId)||Ic("CONSTRAINT_OWNER","Unknown constrained node."),n.position&&(!Number.isFinite(n.position.x)||!Number.isFinite(n.position.y))&&Ic("GEOMETRY_POSITION","Positions must be finite."),n.pin&&!n.position&&Ic("CONSTRAINT_PIN","Pinned nodes need a position."),void 0!==n.rank&&(!Number.isInteger(n.rank)||n.rank<0)&&Ic("CONSTRAINT_RANK","Ranks must be nonnegative integers.");let n=new Map;for(let r of e.prepared.graph.nodes){let i=t.get(r.id);"route-only"===e.options.mode&&!i?.position&&Ic("CONSTRAINT_POSITION","Route-only mode requires authored positions for every owner.",{nodeIds:[r.id]}),n.set(r.id,i?.position??{x:0,y:0})}return n}(t),r=new Map;for(let e of t.view.nodes)"rows"===e.partLayout?.kind&&r.set(e.nodeId,Fc(e.partLayout.order));if("optimize"===t.options.mode){let e=t.prepared.graph,r=ru(e.nodes.map(e=>e.id),e.edges.filter(e=>e.source!==e.target).map(e=>[e.source,e.target]));!r&&"strict-dag"===t.options.topology&&Ic("TOPOLOGY_PROJECTION_CYCLE","Owner projection is cyclic."),function(e,t,n){let r="LR"===e.view.direction||"RL"===e.view.direction,i="RL"===e.view.direction||"BT"===e.view.direction,o=new Map(e.view.constraints?.map(e=>[e.nodeId,e])),a=new Map(e.geometry.nodes.map(e=>[e.nodeId,e]));for(let[e,n]of t){let r=o.get(e)?.rank;void 0!==r?t.set(e,r):t.set(e,n)}if("strict-dag"===e.options.topology)for(let n of e.prepared.graph.edges)n.source!==n.target&&t.has(n.source)&&t.has(n.target)&&t.get(n.source)>=t.get(n.target)&&Ic("CONSTRAINT_RANK","Authored ranks conflict with graph direction.",{edgeIds:[n.id]});let l=0;for(let s of[...new Set(t.values())].sort((e,t)=>e-t)){let d=[...t].filter(([,e])=>e===s).map(([e])=>e).sort(Mc),c=0,u=0;for(let t of d){let s=a.get(t);s||Ic("GEOMETRY_MISSING","Missing node measurement.",{nodeIds:[t]});let d=r?s.width:s.height,h=r?s.height:s.width;u=Math.max(u,d);let p=i?-l-d:l,f=r?{x:p,y:c}:{x:c,y:p},m=o.get(t);n.set(t,{x:"x"===m?.pin||"both"===m?.pin?m.position.x:f.x,y:"y"===m?.pin||"both"===m?.pin?m.position.y:f.y}),c+=h+e.options.nodeGap}l+=u+e.options.rankGap}}(t,r??new Map([...e.nodes].sort((e,t)=>Mc(e.id,t.id)).map((e,t)=>[e.id,t])),n)}let i=lu(t,e,n,r),o=su(i,t,r),a=0,l=0,s=()=>{l++;try{let a=lu(t,e,n,r),l=su(a,t,r);if(l+1e-8<o)return i=a,o=l,!0}catch(e){if(!(e instanceof Ve))throw e}return!1};if("optimize"===t.options.mode)for(let e=0;e<t.options.maxSweeps&&l<256;e++){let e=!1;for(let n of[...t.view.nodes].sort((e,t)=>Mc(e.nodeId,t.nodeId))){if("rows"!==n.partLayout?.kind)continue;let t=r.get(n.nodeId);e:for(let i=0;i<t.length-1&&l<256;i++)for(let o=i+1;o<t.length&&l<256;o++){if(!zc(n.partLayout.order,t[i],t[o]))continue;let a=[...t];if([a[i],a[o]]=[a[o],a[i]],r.set(n.nodeId,a),s()){e=!0;break e}r.set(n.nodeId,t)}}let o="LR"===t.view.direction||"RL"===t.view.direction,d=new Map(i.nodes.map(e=>[e.id,e.semantic.nodeId]));for(let r of i.nodes){if(l>=256)break;if("node"!==r.semantic.endpoint.kind)continue;let a=t.view.constraints?.find(e=>e.nodeId===r.id);if("both"===a?.pin||a?.pin===(o?"y":"x"))continue;let c=i.edges.filter(e=>"none"!==t.view.edgeHints?.find(t=>t.edgeId===e.edgeId)?.alignment).flatMap(e=>d.get(e.source.displayNodeId)===r.id?[o?e.target.anchor.y-e.source.anchor.y:e.target.anchor.x-e.source.anchor.x]:d.get(e.target.displayNodeId)===r.id?[o?e.source.anchor.y-e.target.anchor.y:e.source.anchor.x-e.target.anchor.x]:[]).sort((e,t)=>e-t);if(!c.length)continue;let u=c[Math.floor(c.length/2)],h=n.get(r.id);Math.abs(u)<1e-8||(n.set(r.id,{x:h.x+(o?0:u),y:h.y+(o?u:0)}),s()?e=!0:n.set(r.id,h))}if(a++,!e)break}let d=t.view.nodes.reduce((e,t)=>"rows"===t.partLayout?.kind?e+Fc(t.partLayout.order).filter((e,n)=>r.get(t.nodeId)?.[n]!==e).length:e,0),c=[...i.diagnostics,{code:"LAYOUT_TERMINATION",severity:"info",message:"route-only"===t.options.mode?"Authored positions and order retained.":`Bounded local optimization completed ${a} sweeps and ${l} candidate evaluations${l>=256?" (candidate budget reached)":""}.`}];return kc({...i,metrics:{...i.metrics,completedSweeps:a,reorderedParts:d,nodeDisplacement:i.nodes.reduce((e,n)=>{if("node"!==n.semantic.endpoint.kind)return e;let r=iu(t,n.id);return e+(r?Xe(r.rect,n.rect):0)},0)},diagnostics:c})}catch(e){if(!(e instanceof Ve))throw e;return kc({...au(t),status:"infeasible",diagnostics:e.diagnostics,metrics:{...au(t).metrics,hardConstraintViolations:1}})}}async function cu(e,t,n){let r={...e,options:ou(e.options)};n?.aborted&&Ic("REVISION_CANCELLED","Layout request was cancelled.");let i=t.capabilities,o=[["route-only"===r.options.mode||!!e.view.constraints?.some(e=>!!e.pin),i.fixedPositions,"fixed positions"],[!!e.view.anchors?.length,i.fixedPortPositions,"exact anchors"],[!!e.view.nodes.some(e=>"rows"===e.partLayout?.kind),i.constrainedPartOrder,"part order"],[e.prepared.graph.edges.length>new Set(e.prepared.graph.edges.map(e=>JSON.stringify([e.source,e.target]))).size,i.multiedges,"multiedges"],["orthogonal"===r.options.routing,i.orthogonalRouting,"orthogonal routing"]];for(let[e,t,n]of o)e&&!t&&Ic("CAPABILITY_ENGINE",`Engine does not support ${n}.`);let a=await t.layout(r,n);return n?.aborted&&Ic("REVISION_CANCELLED","Layout request was cancelled."),(a.requestId!==e.requestId||a.semanticHash!==e.prepared.semanticHash||a.graphRevision!==e.prepared.graph.revision||a.viewRevision!==e.view.revision||a.geometryRevision!==e.geometry.revision||a.optionsHash!==vc(r.options)||a.engineId!==t.id||a.engineVersion!==t.version)&&Ic("REVISION_RESPONSE","Engine response does not match the requested revision tuple."),function(e,t){if(["complete","degraded","infeasible"].includes(t.status)||Ic("REVISION_STATUS","Unknown layout status."),"infeasible"===t.status)return;let n=new Map(t.nodes.map(e=>[e.id,e])),{hidden:r}=tu(e);n.size!==t.nodes.length&&Ic("IDENTITY_SOLVED_NODE","Duplicate display node ID."),function(e,t){let{semantics:n,views:r,hidden:i}=tu(e),o=new Set;for(let e of n.values())if(!i.has(e.id)&&(o.add(bc(wc(e.id))),"exploded"===r.get(e.id)?.mode))for(let t of e.parts??[])o.add(bc(wc(e.id,{kind:"part",partId:t.id})));for(let e of t.nodes){let t=bc(e.semantic);o.delete(t)||Ic("IDENTITY_SOLVED_NODE","Unknown, hidden or repeated display-node semantics."),Lc(e.rect);let i=n.get(e.semantic.nodeId),a="node"===e.semantic.endpoint.kind,l=new Set;for(let t of e.parts??[])(!a||l.has(t.partId)||!i.parts?.some(e=>e.id===t.partId)||bc(t.semantic)!==bc(wc(i.id,{kind:"part",partId:t.partId})))&&Ic("IDENTITY_SOLVED_PART","Solved parts must retain unique owner-local semantic identities."),l.add(t.partId),Lc(t.rect);a&&"summary"!==r.get(i.id)?.mode&&(i.parts??[]).some(e=>!l.has(e.id))&&Ic("IDENTITY_SOLVED_PART","A visible owner is missing solved parts.")}o.size&&Ic("IDENTITY_SOLVED_NODE","A feasible solution must cover the requested visible projection.")}(e,t),Lc(t.bounds);let i=new Map(e.prepared.graph.edges.map(e=>[e.id,e])),o=new Set;for(let e of t.edges){let a=i.get(e.edgeId);(!a||o.has(e.edgeId))&&Ic("IDENTITY_SOLVED_EDGE","Unknown or repeated solved edge ID."),o.add(e.edgeId),(bc(e.source.semantic)!==bc(wc(a.source,a.sourceEndpoint))||bc(e.target.semantic)!==bc(wc(a.target,a.targetEndpoint)))&&Ic("ENDPOINT_SOLVED_RETARGET","An engine changed the semantic endpoint.",{edgeIds:[e.edgeId]}),Lc(e.bounds),(!n.has(e.source.displayNodeId)||!n.has(e.target.displayNodeId)||!e.sections.length)&&Ic("GEOMETRY_SOLVED_ROUTE","A route needs display owners and path sections.");for(let t of[e.source,e.target]){let i=n.get(t.displayNodeId),o=r.get(t.semantic.nodeId)??t.semantic.nodeId;(i.semantic.nodeId!==o||!Yc(i.rect,t.anchor))&&Ic("GEOMETRY_TERMINAL_OWNER","A terminal must attach to its own display node.",{edgeIds:[e.edgeId]})}let l=e.source.anchor;for(let n of e.sections){Lc(n.bounds),(n.points.length<2||Xe(l,n.points[0])>1e-7)&&Ic("GEOMETRY_ROUTE_CONTINUITY","Route skeleton does not meet its terminal or preceding section.");let r=n.commands;r?.length&&("M"!==r[0].kind||Xe(l,r[0].point)>1e-7||Xe(r[r.length-1].point,n.points[n.points.length-1])>1e-7)&&Ic("GEOMETRY_ROUTE_COMMANDS","Final commands and skeleton disagree at terminals.");let i=[...n.points,...(r??[]).flatMap(e=>"C"===e.kind?[e.point,e.control1,e.control2]:[e.point])];for(let r of i)(!Number.isFinite(r.x)||!Number.isFinite(r.y)||!Yc(n.bounds,r)||!Yc(e.bounds,r)||!Yc(t.bounds,r))&&Ic("GEOMETRY_ROUTE_BOUNDS","Route geometry must be finite and within its conservative bounds.");l=n.points[n.points.length-1]}Xe(l,e.target.anchor)>1e-7&&Ic("GEOMETRY_ROUTE_TERMINAL","Route misses its target anchor.")}(o.size!==i.size||t.metrics.routedEdgeCount!==o.size||0!==t.metrics.omittedEdgeCount)&&Ic("ROUTING_OMITTED_EDGE","A feasible transaction must represent every requested connection."),"complete"===t.status&&0!==t.metrics.hardConstraintViolations&&Ic("CONSTRAINT_SOLVED","A complete result cannot contain hard constraint violations.");for(let e of t.bundles)(new Set(e.memberEdgeIds).size!==e.memberEdgeIds.length||e.count!==e.memberEdgeIds.length||e.memberEdgeIds.some(e=>!i.has(e)))&&Ic("IDENTITY_BUNDLE","Bundle counts and memberships must match materialized edges.")}(r,a),kc(a)}function uu(e){let{prepared:t,solved:n}=e;("infeasible"===n.status||n.semanticHash!==t.semanticHash||n.graphRevision!==t.graph.revision)&&Ic("REVISION_SCENE","Scene needs a feasible solution matching the semantic revision.");let r=new Map(t.graph.nodes.map(e=>[e.id,e])),i=new Map(t.graph.edges.map(e=>[e.id,e]));return{sceneNodes:n.nodes.flatMap(t=>{let n=r.get(t.semantic.nodeId),i="node"===t.semantic.endpoint.kind,o={type:"rect",id:t.id,x:t.rect.x,y:t.rect.y,w:t.rect.width,h:t.rect.height,label:n.label??n.id,datum:{...n,semantic:t.semantic},style:{fill:i?e.nodeFill??"#edf2f7":e.partFill??"#c9dce8",stroke:"#556779",strokeWidth:1}};return e.showParts&&i?[o,...(t.parts??[]).filter(e=>!e.clipped).map(r=>({type:"rect",id:JSON.stringify(["part-hit",t.id,r.partId]),x:t.rect.x+r.rect.x,y:t.rect.y+r.rect.y,w:r.rect.width,h:r.rect.height,label:n.parts?.find(e=>e.id===r.partId)?.label??r.partId,datum:{id:r.partId,ownerId:n.id,semantic:r.semantic},style:{fill:e.partFill??"#c9dce8"}}))]:[o]}),sceneEdges:n.edges.map(t=>({type:"curved",id:t.edgeId,pathD:t.sections.map(Kc).join(" "),datum:{...i.get(t.edgeId),sourceTerminal:t.source,targetTerminal:t.target},label:t.edgeId,style:{fill:"none",stroke:e.edgeStroke??"#467895",strokeWidth:1.5}}))}}function hu(e,t=tt){let n=new Map,r=new Set,i=!1,o=t=>{try{e.postMessage({type:"cancel",requestId:t})}catch{}},a=({data:e})=>{if("result"!==e.type&&"error"!==e.type)return;let t=n.get(e.requestId);t&&(t.clean(),n.delete(e.requestId),"result"===e.type?t.resolve(e.solved):t.reject(new Error(e.message)))},l=e=>{for(let t of n.values())t.clean(),t.reject(new Error(`REVISION_WORKER_FAILED: ${e}`));n.clear()},s=e=>{"messageerror"===e?.type?l("A worker message could not be deserialized."):"error"===e?.type&&l(e.message||"The worker reported an error.")},d=e;return e.addEventListener("message",a),d.addEventListener?.("error",s),d.addEventListener?.("messageerror",s),{...t,layout:(t,a)=>new Promise((l,s)=>{if(i||a?.aborted)return void s(new Error("REVISION_CANCELLED"));if(r.has(t.requestId))return void s(new Error("REVISION_REQUEST_ID: request IDs must be unique for the engine's lifetime."));r.add(t.requestId);let d=()=>{n.delete(t.requestId),a?.removeEventListener("abort",d),s(new Error("REVISION_CANCELLED")),o(t.requestId)};n.set(t.requestId,{resolve:l,reject:s,clean:()=>a?.removeEventListener("abort",d)}),a?.addEventListener("abort",d,{once:!0});try{e.postMessage({type:"solve",request:t})}catch(e){n.delete(t.requestId),a?.removeEventListener("abort",d),s(e)}}),dispose(){i=!0,e.removeEventListener("message",a),d.removeEventListener?.("error",s),d.removeEventListener?.("messageerror",s);for(let[e,t]of n)t.clean(),t.reject(new Error("REVISION_CANCELLED")),o(e);n.clear(),r.clear()}}}function pu(e,t=tt){let n=new Map,r=({data:r})=>{if("cancel"===r.type)return void n.get(r.requestId)?.abort();if("solve"!==r.type)return;let i=r.request,o=new AbortController;n.get(i.requestId)?.abort(),n.set(i.requestId,o),Promise.resolve().then(()=>t.layout(i,o.signal)).then(t=>{o.signal.aborted||e.postMessage({type:"result",requestId:i.requestId,solved:t})}).catch(t=>{if(!o.signal.aborted)try{e.postMessage({type:"error",requestId:i.requestId,message:t instanceof Error?t.message:"Worker layout failed."})}catch{}}).finally(()=>{n.get(i.requestId)===o&&n.delete(i.requestId)})};return e.addEventListener("message",r),()=>{e.removeEventListener("message",r),n.forEach(e=>e.abort()),n.clear()}}function fu(e,t){let n=e.nodes.find(e=>e.id===t.nodeId);(!n||"infeasible"===e.status)&&Ic("GEOMETRY_SCROLL_OWNER","Scroll projection requires a feasible visible owner."),Lc(t.viewport),Rc(t.offsetY,"offsetY");let r=t.viewport;(r.x<0||r.y<0||r.x+r.width>n.rect.width||r.y+r.height>n.rect.height)&&Ic("GEOMETRY_SCROLL_VIEWPORT","Row viewport must be inside the owner.");let i=n.rect.y+r.y,o=i+r.height,a=e=>{if(e.displayNodeId!==n.id||"part"!==e.semantic.endpoint.kind)return e;(0!==e.normal.y||Math.abs(e.anchor.x-n.rect.x)>1e-7&&Math.abs(e.anchor.x-n.rect.x-n.rect.width)>1e-7)&&Ic("CAPABILITY_SCROLL_ANCHOR","This scroll projection requires horizontal boundary row slots.");let r=e.anchor.y-t.offsetY,a=r>=i&&r<=o,l=Math.max(i,Math.min(o,r));return{...e,anchor:{...e.anchor,y:l},escape:{...e.escape,y:l},precision:a?e.precision:"proxy",exposureId:a?e.exposureId:JSON.stringify(["scroll",bc(e.semantic),e.end])}},l=e.nodes.map(e=>e.id!==n.id?e:{...e,parts:e.parts?.map(e=>{let n={...e.rect,y:e.rect.y-t.offsetY};return{...e,rect:n,clipped:n.y<r.y||n.y+n.height>r.y+r.height}})}),s=e.edges.map(e=>{let t=a(e.source),n=a(e.target);if(t===e.source&&n===e.target)return e;1!==e.sections.length&&Ic("CAPABILITY_SCROLL_SECTIONS","The built-in scroll repair requires a single route section.");let r=e.sections[0],i=r.points.slice(1,-1),o=Hc([t.anchor,t.escape,...i,n.escape,n.anchor]),l=Xc(r.id,o,!1,[]);return{...e,source:t,target:n,sections:[l],bounds:l.bounds}}),d=Qc(s,!0,new Set(s.map(e=>e.edgeId)));return kc({...e,viewRevision:t.viewRevision,nodes:l,edges:s,bundles:[],bounds:_c([...l.map(e=>e.rect),...s.map(e=>e.bounds)]),metrics:{...e.metrics,...d.metrics,completedSweeps:0},status:"degraded",diagnostics:[...e.diagnostics,{code:"GEOMETRY_SCROLL_PROXIES",severity:"info",message:"Clipped row endpoints use disclosed continuation proxies; terminal routes were locally repaired without a global solve.",nodeIds:[n.id]}]})}var Be={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"}},qe=Object.freeze({kind:"node"}),Ve=class extends Error{constructor(e){super(e.map(e=>`${e.code}: ${e.message}`).join("\n")),this.diagnostics=e,this.name="CompositionalGraphError"}},He=/*#__PURE__*/new WeakMap,Ue=1e-8,Xe=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),Ke=e=>e.slice(1).reduce((t,n,r)=>t+Xe(e[r],n),0),Je=(e,t)=>JSON.stringify([e,t]),Ze=(e,t,n,r)=>JSON.stringify([e,t??null,n,r]),Qe=e=>({...e,point:{...e.point},normal:{...e.normal}}),et=/*#__PURE__*/new WeakMap,tt={id:"semiotic-compositional",version:"0.1.0",capabilities:{fixedPositions:!0,fixedPortPositions:!0,constrainedPartOrder:!0,multiedges:!0,compoundCrossHierarchy:!1,orthogonalRouting:!0,deterministicSeed:!0},async layout(e,t){if(t?.aborted)throw new Error("REVISION_CANCELLED");return du(e)}},nt=class{constructor(){this.generation=0,this.currentDiagnostics=[],this.updating=!1}get solution(){return this.accepted}get diagnostics(){return this.currentDiagnostics}async solve(e,t=tt){this.abort?.abort();let n=new AbortController,r=++this.generation;this.abort=n,this.updating=!0;try{let i=await cu(e,t,n.signal);return r===this.generation&&(this.currentDiagnostics=i.diagnostics,"infeasible"!==i.status)&&(this.accepted=i,!0)}catch(e){return r===this.generation&&(this.currentDiagnostics=[{code:"REVISION_SOLVE_FAILED",severity:"error",message:e instanceof Error?e.message:"Layout failed."}]),!1}finally{r===this.generation&&(this.updating=!1)}}cancel(){this.generation++,this.abort?.abort(),this.updating=!1}dispose(){this.cancel(),this.accepted=void 0,this.currentDiagnostics=[]}},rt=e=>uu(e.config),it=class{constructor(e,t){this.current=e,this.accepted=t,this.passes=0}get solution(){return this.accepted}update(e){if(Bc(e),e.basis===this.current.geometry.basis&&vc(e.nodes)===vc(this.current.geometry.nodes))return this.accepted;if(this.passes>=2)return kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,{code:"GEOMETRY_UNSTABLE_MEASUREMENT",severity:"warning",message:"Measurement did not converge after two corrections; retaining the last valid scene."}]});if(e.revision===this.current.geometry.revision)return kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,{code:"REVISION_GEOMETRY",severity:"warning",message:"Changed geometry requires a new revision; retaining the last valid scene."}]});this.passes++;let t={...this.current,requestId:`${this.current.requestId}:measure:${this.passes}`,geometry:e,previous:this.accepted},n=du(t);return"infeasible"!==n.status&&(this.accepted=n,this.current=t),"infeasible"===n.status?kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,...n.diagnostics]}):this.accepted}};export{Ve as CompositionalGraphError,nt as CompositionalLayoutController,it as CompositionalMeasurementTransaction,ge as DEFAULT_AREA_PER_ANNOTATION,je as DEFAULT_GLYPH_ANCHOR,De as DEFAULT_GLYPH_VIEWBOX,Fe as DEFAULT_HIT_RADIUS,k as DEFAULT_ISOMETRIC_SPRITE_SIZES,ke as GRID_FUEL_KEYS,Ie as GRID_FUEL_LABELS,e as LayoutCache,r as SYMBOL_SEQUENCE,ze as TAU,Fs as absorbRegion,Da as activeCountOverDomain,Wl as addPoints,ee as adjacencyFlowLayout,ec as adjacencyMatrix,So as aggregateAdjacencyFlow,ws as aggregateRegionCounts,Pt as allocateCells,eo as analyzeNetEnsemble,zl as angleScale,sa as annotationBudget,ca as annotationDensity,xa as annotationLayout,Jd as arcLayout,Zd as arcPath,Ud as arrivalReplay,Ee as axisFixedForceLayout,Ka as axisFixedForcePositions,jt as balanceSnapshotsToFlows,Hi as bandLabel,hs as betweenness,ds as bfsDistances,pe as bobaLayout,zs as bodyGroupSpec,qi as boundsOf,Ya as boxEdgeAnchors,ls as buildAdjacency,ns as buildTooltipEntries,ae as bulletLayout,x as calendarLayout,Rs as capacitatedRegion,Cs as chargeGateRegion,Qd as circularLayout,gt as clamp,va as classifyReserve,ps as closeness,fs as clustering,Bd as collidersFromScales,Zs as comparePhysicsTrace,fd as composePhysicsControllers,tt as compositionalDagEngine,rt as compositionalDagLayout,bc as compositionalEndpointKey,ou as compositionalLayoutOptions,Kc as compositionalPath,Dc as compositionalRowGeometry,qr as computeTransitDiagramPositions,$l as countPairwiseCrossings,hd as createCapacityQueueController,hu as createCompositionalWorkerEngine,Pr as createDagreFit,bd as createDependencyGateController,Er as createFlextreeFit,si as createLineageDagFit,md as createPortalController,rd as createProcessJourneyLedger,xd as createServiceLevelController,gd as createServiceResourcePoolController,Ha as cubicPath,qa as cubicPoint,Va as cubicTangent,Wa as curvedEdgePath,yl as cyclicRangeContains,z as dagreLayout,ss as degree,Ia as demandForecastRows,Dd as describePhysicsStageGeography,an as diagnoseTokenEncoding,kt as dimFor,us as egoNetwork,uu as emitCompositionalScene,Al as estimateLabelWidth,ts as extractTooltipDatum,Ba as fanOutBend,P as flextreeLayout,Ps as forceFieldRegion,Jt as forceLayout,ys as forceLayoutAsync,Ta as formatMw,Ra as formatReservePct,rs as formatTooltipValue,qd as galtonPegs,rn as generateTokens,cl as geoAreaHitTarget,dl as geoHitTarget,F as geographicDotGridLayout,C as geographicGridLayout,Hl as glyphExtent,Ul as glyphFractionClipRect,Vl as glyphPlacement,Ca as gridEventAnnotations,Qn as gridifyGeographicPoints,wt as groupBy,vs as groupCompletionRows,Ui as hatchFill,sl as hitTargetPoint,ul as hitTargetRect,Vi as hullFromBoxes,pu as installCompositionalWorker,Ne as intervalLanesLayout,N as isometricLandmarkLayout,c as isotypeBoltGlyph,u as isotypeBusGlyph,d as isotypeChipGlyph,l as isotypeGhost,o as isotypeInk,f as isotypeNetworkGlyphs,a as isotypePaper,p as isotypePersonGlyph,h as isotypePersonPath,s as isotypeServerGlyph,Nl as layoutChipStrip,cu as layoutCompositionalGraph,Sl as layoutSequence,on as layoutTokenGrid,Zl as legendGroupsFrom,Ql as legendSwatches,G as lineageDagLayout,Xi as linearAxis,St as makeShade,oe as marimekkoLayout,Ki as markCallout,vt as matchesHighlight,Ot as mean,Es as membraneRegion,K as mermaidDagLayout,ac as mobileAnnotationStrategy,uc as mobileAreaChartRecipe,xc as mobileBrushAlternatives,yc as mobileChartFamilyRecipe,mc as mobileGeoChartRecipe,cc as mobileLineChartRecipe,fc as mobileNetworkChartRecipe,hc as mobileOrdinalChartRecipe,pc as mobileScatterplotRecipe,gc as mobileSmallMultipleRecipe,U as motifBraidLayout,Kt as mulberry32,Q as netEnsembleLayout,pl as networkEdgeHitTarget,hl as networkHitTarget,Ct as nonNegativeFinite,ql as normalizePoint,ms as normalizeScores,en as normalizeTokenEncoding,Vr as octilinearRoute,Hr as offsetTransitPath,vl as orderByBarycenter,Kd as orderByGroupDegree,Il as orderExactSmall,Ga as orthogonalEdgePath,Ml as packBandsBySilhouette,za as packIntervals,El as packSpanLevels,re as packedClusterMatrix,le as parallelCoordinatesLayout,Rl as partitionSharedEdges,Oc as patchCompositionalGraph,Pd as physicsChargePoint,Fd as physicsDestination,Hs as physicsReferenceEnvelope,zd as physicsStageColliders,Ld as physicsStageGeography,bl as placeWithMinGap,Bl as pointMagnitude,Fl as polarToXY,Ls as portalRegion,Cc as prepareCompositionalGraph,Ii as prepareMotifBraid,ki as prepareNetworkAtlasAsync,Ts as pressureFieldRegion,Rd as processChrome,od as processJourneyRows,Ds as processLaneWalls,$s as processStageLayout,As as processStageRegions,_s as processVolumePolygons,fu as projectCompositionalScroll,gs as proximityProblem,Dl as radiusScale,xt as readField,Ua as rectCollide,kl as refineByAdjacentSwaps,Ms as regionCountsToProjectionRows,Aa as reserveAnnotationBands,Ma as reserveClasses,$a as reserveMarginPct,Sa as reserveSeries,jl as ringArcPath,Bi as roundedEnclosure,Ur as roundedTransitPath,du as routeCompositionalGraph,Os as routeSurfaceRegion,Pe as runLengthEncode,fl as runs,gr as sampleGeographicDotGrid,Cl as scaleArcBand,Yl as scalePoint,Hd as sedimentBake,xl as selectCyclicRange,Pn as selectIsometricLandmarks,Nt as shade,gl as shortestArcDelta,cs as shortestPath,It as signatureKey,Ol as spanArcPath,Tl as spanArcPeakY,Vd as spawnFromTokens,ka as stackFuelSeries,js as stageTargetInVolume,Gl as subtractPoints,dn as suggestTokenEncoding,Ea as summarizeOperatingPoint,wn as symbolExtent,xn as symbolPathString,bn as symbolRadius,Na as thresholdBandsForReserve,Oa as tightestHours,An as tokenLayer,sn as tokenTaskIntentToCapabilityIntents,Tc as traceCompositionalGraph,j as transitDiagramLayout,Wt as unitize,Gt as unitizeRange,bt as unwrapDatum,id as updateProcessJourney,t as waffleLayout,Tt as withAlpha,ol as wordTrailsLayout,nl as wordTrailsProgressiveReveal,ml as wrapValue,Pl as xyToAngle};
1
+ var s,d,c,u,h,p,M,_e,We,Ge,Ye;import{c as ot}from"./c-BOA4LTOM.min.js";import{a as at,b as lt,c as st,d as dt}from"./c-2CKIGFD2.min.js";import{a as ct,b as ut,c as ht,e as pt,f as ft}from"./c-JL224XKG.min.js";import{interpolateLab as mt}from"d3-interpolate";function gt(e,t,n){return Math.max(t,Math.min(n,e))}function yt(e){return"function"==typeof e?e:t=>t[e]}function xt(e,t,n){let r=e?.data,i=r?r[t]:void 0;if(null!=i)return i;let o=e?.[t];return o??n}function bt(e){if(null==e)return null;let t=e;return t.data??t.datum??e}function wt(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function Mt(e){let t=Object.create(null);return e((e,n)=>{t[e]=n}),t}function vt(e,t){if(!t)return!0;let n=Array.isArray(t)?t:[t],r=e;for(let e of n)if(null!=e.value&&String(r[e.field])!==String(e.value))return!1;return!0}function kt(e,t={}){let n=t.baseOpacity??1;return t.highlight||t.predicate?!vt(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,n+(t.brighten??0)):n}function It(e){return e.join("|")}function St(e){return mt(e,e)(0)===mt(e,"white")(0)?e:null}function $t(e,t=.72){let n=St(e),r=null===n,i=null===n?null:mt(n,"#ffffff"),o=null===n?null:mt(n,"#000000"),a=null===n?e:i(0),l=gt(t,0,1);return t=>{let n=gt(t,0,1);if(.5===n)return a;let s=2*Math.abs(n-.5)*l;return s?r?`color-mix(in lab, ${e} ${100*(1-s)}%, ${n<.5?"white":"black"})`:n<.5?i(s):o(s):a}}function Nt(e,t,n=.72){return $t(e,n)(t)}function At(e){return Mt(t=>{for(let[n,r]of Object.entries(e))t(n,r)})}function Et(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"item"}function Ct(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):0}function Ot(e){if(0===e.length)return 0;let t=0;for(let n of e)t+=n;return t/e.length}function Tt(e,t){let n=Number.isFinite(t)?gt(t,0,1):1,r=St(e);if(null===r)return 1===n?e:`color-mix(in srgb, ${e} ${100*n}%, transparent)`;let[i,o,a,l=1]=mt(r,r)(0).split(/[(),]/).slice(1,-1).map(Number);return`rgba(${i}, ${o}, ${a}, ${l*n})`}function Rt(e,t){return e<t?-1:e>t?1:0}var e=class{constructor(e=12){this.maxSize=e,this.store=new Map}get(e){return this.store.get(e)}set(e,t){this.store.size>=this.maxSize&&this.store.clear(),this.store.set(e,t)}getOrCompute(e,t){let n=this.store.get(e);if(void 0!==n)return n;let r=t();return this.set(e,r),r}clear(){this.store.clear()}get size(){return this.store.size}};import{createElement as Lt}from"react";function Ft(e,t,n,r,i,{force:o=!1}={}){if(t===n&&!o)return null;let a=`${t} of ${n} ${r} shown`;return Lt("text",{key:"recipe-notice",x:e.x,y:e.y+e.height-4,fontSize:11,fill:"var(--semiotic-text, currentColor)",pointerEvents:"none",role:"img","aria-label":`${a}. ${i}`},Lt("title",null,i),a)}function Pt(e,t,n){return zt(e,t,n)}function zt(e,t,n,r=!1){let i=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,o=e=>Number.isFinite(e)?Math.max(0,e):0,a=e.reduce((e,t)=>e+(o(t.weight)>0?1:0),0),l=Math.max(0,Math.floor(n?.minPerCategory??0)),s=a>0?Math.min(l,Math.floor(i/a)):0,d=e.reduce((e,t)=>e+o(t.weight),0);if(i<=0||d<=0)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));let c=e.map(e=>{let t=o(e.weight),n=t/d*i;return{...e,exact:n,cells:t>0?Math.max(s,Math.floor(n)):0,remainder:n-Math.floor(n)}}),u=c.reduce((e,t)=>e+t.cells,0);for(;u>i;){let e=c.filter(e=>e.cells>s).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,u--}let h=c.filter(e=>o(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||(r?0:o(t.weight)-o(e.weight)||e.key.localeCompare(t.key)));for(let e=0;u<i;e++)h[e%h.length].cells++,u++;return c}function Dt(e,t,n,r){let i=new Set;return e.map((e,o)=>{let a=String(t(e,o)),l=Number(n(e,o));if(!a)throw new Error(`${r} snapshot contains an empty id at index ${o}.`);if(i.has(a))throw new Error(`${r} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(l)||l<0)throw new Error(`${r} snapshot value for "${a}" must be a finite non-negative number.`);return i.add(a),{id:a,value:l}})}function jt(e,t,n){let r=n.afterId??n.beforeId,i=n.afterValue??n.beforeValue,o=null!=n.epsilon&&n.epsilon>=0?n.epsilon:1e-9,a=Dt(e,n.beforeId,n.beforeValue,"Before"),l=Dt(t,r,i,"After"),s=new Map(a.map(e=>[e.id,e.value])),d=new Map(l.map(e=>[e.id,e.value])),c=a.reduce((e,t)=>e+t.value,0),u=l.reduce((e,t)=>e+t.value,0),h=Math.abs(c-u)<=o;if(!h&&!n.allowImbalance)throw new Error(`Snapshot totals must match (before ${c}, after ${u}). Pass allowImbalance to inspect residuals.`);let p=[],f=[...a.map(e=>e.id),...l.map(e=>e.id).filter(e=>!s.has(e))];for(let e of f){let t=Math.min(s.get(e)??0,d.get(e)??0);t>o&&p.push({sourceId:e,targetId:e,value:t,kind:"stay"})}let m=a.map(e=>({id:e.id,value:e.value-(d.get(e.id)??0)})).filter(e=>e.value>o),g=l.map(e=>({id:e.id,value:e.value-(s.get(e.id)??0)})).filter(e=>e.value>o),y=0,x=0;for(;y<m.length&&x<g.length;){let e=m[y],t=g[x],n=Math.min(e.value,t.value);n>o&&p.push({sourceId:e.id,targetId:t.id,value:n,kind:"move"}),e.value-=n,t.value-=n,e.value<=o&&(y+=1),t.value<=o&&(x+=1)}return{flows:p,beforeTotal:c,afterTotal:u,balanced:h,unmatchedBefore:m.slice(y).filter(e=>e.value>o).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:g.slice(x).filter(e=>e.value>o).map(({id:e,value:t})=>({id:e,value:t}))}}function _t(e){return Number.isFinite(e)?Math.max(0,e):0}function Wt(e,t){let n=Number(t.unit),r=_t(e),i=t.maxUnits??1/0,o=t.minFraction??0;if(!(n>0)||!(i>0)||r<=0)return{units:[],unit:n>0?n:0,total:r,shown:0,overflow:r>0&&!(i>0)};let a=r/n,l=Math.ceil(a-1e-6),s=Math.min(i,l),d=l>i,c=[];for(let e=0;e<s;e+=1){let t=e*n,i=Math.min(r,t+n),o=Math.min(1,Math.max(0,(i-t)/n));1-o<1e-6&&(o=1),c.push({index:e,fraction:o,start:t,end:t+o*n,value:o*n})}let u=c[c.length-1];u&&u.fraction<o&&u.fraction<1&&c.pop();let h=c.reduce((e,t)=>e+t.value,0);return{units:c,unit:n,total:r,shown:h,overflow:d}}function Gt(e,t,n){let r=Wt(e,n),i=Math.max(_t(t),r.total);if(i<=r.total)return{...r,rangeUnits:[],rangeTotal:r.total};let o=Wt(i,{unit:n.unit,maxUnits:n.maxUnits}),a=o.unit>0?r.total/o.unit:0,l=Math.floor(a+1e-6),s=Math.min(1,Math.max(0,a-l));s<1e-6&&(s=0);let d=[];for(let e of o.units)if(!(e.index<l)){if(e.index===l&&s>0){e.fraction-s>1e-6&&d.push({...e,startFraction:s,start:e.index*o.unit+s*o.unit,value:(e.fraction-s)*o.unit});continue}d.push({...e,startFraction:0})}return{...r,overflow:r.overflow||o.overflow,rangeUnits:d,rangeTotal:i}}var t=e=>{let t=e.config,n=t.rows??10,r=t.columns??10,i=t.gutter??2,{plot:o}=e.dimensions;if(o.width<=0||o.height<=0)return{nodes:[]};let a=()=>({nodes:[],overlays:Ft(o,0,e.data.length,"rows","The grid needs positive integer dimensions and enough space for its gutters.",{force:!0})}),l=n*r;if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||!Number.isSafeInteger(l)||n<=0||r<=0||!Number.isFinite(i)||i<0)return a();let s=(o.width-i*(r-1))/r;if(s<=0||o.height<=i*(n-1))return a();let d=null==t.categoryAccessor?()=>"_default":yt(t.categoryAccessor),c=null==t.valueAccessor?()=>1:yt(t.valueAccessor),u=new Map;for(let t of e.data){let e=String(d(t)),n=Ct(Number(c(t)));u.set(e,(u.get(e)??0)+n)}let h=Array.from(u.values()).reduce((e,t)=>e+t,0);if(!(h>0&&Number.isFinite(h)))return{nodes:[],overlays:Ft(o,0,u.size,"categories","Category values must have a finite positive total.")};let p=[...new Set([...t.categoryOrder??[],...u.keys()])].filter(e=>u.has(e)),f=zt(p.map(e=>({key:e,weight:u.get(e)??0})),l,void 0,!0),m=f.filter(e=>e.cells>0).length,g=Ft(o,m,p.length,"categories","Zero-valued categories and categories rounded to zero cells are omitted."),y=(o.height-(g?18:0)-i*(n-1))/n;if(y<=0)return a();let x="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",b="string"==typeof t.valueAccessor?t.valueAccessor:"value",w=(e,t,n)=>Mt(r=>{r("category",e),r("value",u.get(e)??0),r("share",(u.get(e)??0)/h),"category"!==x&&r(x,e),"value"!==b&&r(b,u.get(e)??0),r("cells",n),r("_waffleCategory",e),r("_waffleIndex",t)}),M=[],v=0;for(let t of f){let a=e.resolveColor(t.key);for(let e=0;e<t.cells;e++){let l=v%r,d=n-1-Math.floor(v/r);M.push({type:"rect",x:o.x+l*(s+i),y:o.y+d*(y+i),w:s,h:y,style:{fill:a,stroke:"none"},datum:w(t.key,v,t.cells),group:t.key,_transitionKey:`waffle-${t.key}-${e}`}),v++}}return{nodes:M,overlays:g}};import{forceCenter as Yt,forceCollide as Bt,forceLink as qt,forceManyBody as Vt,forceSimulation as Ht,forceX as Ut,forceY as Xt}from"d3-force";function Kt(e){let t=e>>>0;function n(){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}return n.getState=()=>t>>>0,n}function Jt(e,t,n={}){let r=n.seed??1,i=n.iterations??260,o=n.repulsion??5200,a=n.linkDistance??165,l=n.linkStrength??.045,s=n.centerStrength??.018,d=n.damping??.84,c=n.nodeRadius??12,u=n.nodePadding??3,h=n.inset??.06,p=Kt(r),f=new Map;for(let t of e)f.set(t.id,0);for(let e of t)f.set(e.source,(f.get(e.source)??0)+1),f.set(e.target,(f.get(e.target)??0)+1);let m=500,g=e.map(e=>({id:e.id,data:e,x:200+600*p(),y:200+600*p()})),y=new Set(e.map(e=>e.id)),x=t.filter(e=>y.has(e.source)&&y.has(e.target)).map(e=>({source:e.source,target:e.target}));if(i>0){let e=Ht(g).randomSource(p).alphaDecay(1-Math.pow(.001,1/i)).velocityDecay(Math.max(0,Math.min(1,1-d))).force("charge",Vt().strength(e=>{let t=f.get(e.id)??0;return 2.5*-Math.sqrt(o)*Math.sqrt(t+1)})).force("collide",Bt(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Yt(m,m).strength(.8)).force("x",Ut(m).strength(s)).force("y",Xt(m).strength(s));x.length>0&&e.force("link",qt(x).id(e=>e.id).distance(a).strength(e=>{let t="string"==typeof e.source?e.source:e.source.id,n="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(f.get(t)??1,f.get(n)??1));return l/.045/r})),e.stop();for(let t=0;t<i;t+=1)e.tick()}let b=1/0,w=1/0,M=-1/0,v=-1/0;for(let e of g){let t=e.x??m,n=e.y??m;t<b&&(b=t),n<w&&(w=n),t>M&&(M=t),n>v&&(v=n)}let k=M-b,I=v-w,S={};for(let e of g){let t={x:0===k?.5:h+((e.x??m)-b)/k*(1-2*h),y:0===I?.5:h+((e.y??m)-w)/I*(1-2*h)};Object.defineProperty(S,e.id,{value:t,enumerable:!0,configurable:!0,writable:!0})}return S}function Zt(e){return e?e.map(Number).filter(Number.isFinite):[]}function Qt(e){if("fixed-denominator"===e.countStrategy)return 1/0;let t=e.maxTokens??1/0;return t>0?Math.floor(t):0}function en(e){let t=e.unitValue??e.unit,n=e.icon??e.token;return{...e,...null!=t&&{unitValue:t},...null!=n&&{icon:n}}}function tn(e){if(e.samples)return Zt(e.samples);if(!e.data||!e.valueAccessor)return[];let t=e.valueAccessor;return e.data.map(e=>"function"==typeof t?t(e):Number(e[t])).filter(Number.isFinite)}function nn(e,t,n,r={}){return{index:t,tokenType:e.tokenType,tokenSemantics:e.tokenSemantics,countStrategy:e.countStrategy,fraction:1,startFraction:0,value:n,start:t,end:t+n,unitValue:e.unitValue,unitMeaning:e.unitMeaning,...r}}function rn(e,t){let n,r,i,o,a,l,s,d=en(t),c=function(e){return"number"==typeof e?{value:e}:Array.isArray(e)?{samples:Zt(e),data:e}:e}(e),u=0,h=!1;if("unitized"===d.countStrategy){a=d.unitValue??1;let e={unit:a,maxUnits:d.maxTokens,minFraction:d.minFraction},t=null==c.rangeValue?Wt(Ct(c.value),e):Gt(Ct(c.value),Ct(c.rangeValue),e);if(n=t.units.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:t.unit})),r=t.total,u=t.shown,h=t.overflow,null!=c.rangeValue){let e=t;l=e.rangeTotal,s=e.rangeUnits.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,startFraction:e.startFraction,start:e.start,end:e.end,unitValue:t.unit,range:"scenario"}))}}else if("fixed-denominator"===d.countStrategy){o=Math.floor(Ct(c.denominator??d.denominator)),i=Ct(c.numerator??d.numerator??c.value);let e=Math.min(o,Math.max(0,Math.round(i)));n=Array.from({length:o},(t,n)=>nn(d,n,1,{highlighted:n<e,start:n,end:n+1})),r=o,u=n.length,h=!1}else if("quantile"===d.countStrategy){let e=tn(c).sort((e,t)=>e-t),t=Math.max(0,Math.floor(d.tokenCount??50)),i=e.length>0?Math.min(t,Qt(d)):0;n=Array.from({length:i},(t,n)=>{let r=(n+.5)/i,o=function(e,t){let n=e.length;if(0===n)return 0;if(1===n)return e[0];let r=(n-1)*Math.min(1,Math.max(0,t)),i=Math.floor(r),o=Math.ceil(r),a=r-i;return e[i]*(1-a)+e[o]*a}(e,r);return nn(d,n,o,{sample:o,quantile:r,start:o,end:o})}),r=e.length,u=n.length,h=e.length>0&&t>n.length}else if("sample"===d.countStrategy||"posterior-sample"===d.countStrategy||"random-sample"===d.countStrategy){let e=tn(c),t=Math.min(e.length,Math.max(0,Math.floor(d.tokenCount??e.length))),i=Math.min(t,Qt(d));n=("random-sample"===d.countStrategy?function(e,t=1){let n=Array.from({length:e},(e,t)=>t),r=Kt(Math.floor(t)||1);for(let e=n.length-1;e>0;e-=1){let t=Math.floor(r()*(e+1)),i=n[e];n[e]=n[t],n[t]=i}return n}(e.length,d.seed).slice(0,i):Array.from({length:i},(t,n)=>Math.floor(n/Math.max(1,i-1)*(e.length-1)))).map((t,n)=>{let r=e[t];return nn(d,n,r,{sample:r,start:r,end:r})}),r=e.length,u=n.length,h=t>n.length}else{let e=c.data;if(e&&null==c.value)n=e.map((e,t)=>nn(d,t,1,{datum:e})),r=e.length;else{let e=Wt(Ct(c.value),{unit:1,maxUnits:d.maxTokens,minFraction:d.minFraction});n=e.units.map(e=>nn(d,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:1})),r=e.total,u=e.shown,h=e.overflow}if(e&&null==c.value){let e=function(e,t){let n=Qt(t);return e.length<=n?{tokens:e,overflow:!1}:{tokens:e.slice(0,n),overflow:!0}}(n,d);n=e.tokens,u=n.length,h=e.overflow}}return{tokens:n,encoding:d,total:r,shown:u,overflow:h,numerator:i,denominator:o,unitValue:a,rangeTotal:l,rangeTokens:s,diagnostics:an(d,{visibleTokens:n.length+(s?.length??0)})}}function on(e,t={}){let n=function(e){return Array.isArray(e)}(e)?e:e.tokens,r=n.length;if(0===r)return[];let i=t.flow??"row",o=t.cellWidth??16,a=t.cellHeight??o,l=t.gutter??2,s=t.anchor??[.5,.5],d=Math.max(1,Math.floor(t.columns??(t.rows?Math.ceil(r/t.rows):Math.ceil(Math.sqrt(r))))),c=Math.max(1,Math.floor(t.rows??Math.ceil(r/d))),u="row"===i?Math.max(c,Math.ceil(r/d)):c,h="column"===i?Math.max(d,Math.ceil(r/c)):d,p=t.x??0,f=t.y??0;return n.map((e,n)=>{let r,m;return"column"===i?(m=Math.floor(n/c),r=n%c):(r=Math.floor(n/d),m=n%d),"left"===t.columnDirection&&(m=h-1-m),"up"===t.rowDirection&&(r=u-1-r),{...e,row:r,column:m,x:p+m*(o+l)+s[0]*o,y:f+r*(a+l)+s[1]*a}})}function an(e,t={}){let n=[],r=e.tokenSemantics,i=e.countStrategy,o=t.maxRecommendedTokens??("fixed-denominator"===i&&Ct(e.denominator)<=100?100:80);return r||n.push({code:"TOKEN_SEMANTICS_UNCLEAR",severity:"warning",message:"Every tokenized encoding should state what one token represents."}),i||n.push({code:"MISSING_COUNT_STRATEGY",severity:"warning",message:"Every tokenized encoding should state how token counts are produced."}),("icon"===e.tokenType||"glyph"===e.tokenType)&&("icon-only"===e.labelPolicy||"token-only"===e.labelPolicy)&&n.push({code:"ICON_ONLY_LABELS",severity:"warning",message:"Icons should supplement text labels, not replace them."}),null!=t.visibleTokens&&t.visibleTokens>o&&n.push({code:"TOO_MANY_VISIBLE_TOKENS",severity:"warning",message:`This encoding renders ${t.visibleTokens} visible tokens. Consider unitizing, sampling, or a hybrid bar/token view.`}),"decorative"===r&&("icon"===e.tokenType||"glyph"===e.tokenType)&&n.push({code:"DECORATIVE_PICTOGRAPHS",severity:"warning",message:"Decorative pictographs can harm recall and speed when they do not clarify the data."}),"unitized-measure"===r&&i&&"unitized"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Unitized measures should use the unitized count strategy so each token has a stable value."}),"risk-case"===r&&i&&"fixed-denominator"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Risk cases are usually clearest as a fixed-denominator natural frequency."}),("possible-outcome"===r||"posterior-sample"===r||"hypothetical-case"===r)&&i&&"quantile"!==i&&"sample"!==i&&"posterior-sample"!==i&&"random-sample"!==i&&n.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Outcome/sample tokens should come from quantiles or samples, not from a unitized magnitude."}),"unitized-measure"===r&&"unitized"===i&&null==e.unitValue&&null==e.unit&&n.push({code:"MISSING_UNIT_VALUE",severity:"warning",message:"Unitized measures should set unitValue so each token has a declared value."}),"unitized-measure"===r&&"unitized"===i&&!e.unitMeaning&&n.push({code:"MISSING_UNIT_MEANING",severity:"info",message:"Add unitMeaning so readers know what one full token represents."}),n}function ln(e){return"measure"===e?"precise-comparison":"estimate probability"===e?"probability-estimation":"understand risk"===e?"risk-communication":"remember"===e?"memory":"decide"===e?"support-decision":e}function sn(e){let t=ln(e);return"precise-comparison"===t?["compare-categories","rank"]:"probability-estimation"===t?["distribution"]:"risk-communication"===t?["part-to-whole","distribution"]:"frequency-reasoning"===t?["distribution","compare-categories"]:"memory"===t||"editorial-engagement"===t?["compare-categories"]:"public-explanation"===t||"support-decision"===t?["distribution","compare-categories"]:["compare-categories"]}function dn(e){let t=ln(e.taskIntent),n=function(e){return"small"===e?25:"large"===e?100:50}(e.availableSpace);if("precise-comparison"===t)return{recommendedEncoding:"bar-or-line",rationale:"Use continuous position/length encodings when precise magnitude comparison is the primary task.",warnings:[],alternatives:["hybrid-bar-token","unitized-measure"]};if("probability-estimation"===t){let e={tokenType:"dot",tokenSemantics:"possible-outcome",countStrategy:"quantile",tokenCount:n,layout:"dotplot",labelPolicy:"text-plus-token"};return{recommendedEncoding:"quantile-dotplot",tokenEncoding:e,rationale:"This task asks readers to estimate probability from a distribution. Quantile tokens turn probability mass into countable possible outcomes.",warnings:an(e),alternatives:["cdf-with-threshold","density-with-threshold"]}}if("risk-communication"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"risk-case",countStrategy:"fixed-denominator",denominator:100,layout:"waffle",labelPolicy:"text-plus-token"};return{recommendedEncoding:"fixed-denominator-icon-array",tokenEncoding:t,rationale:"Risk is often clearer as natural frequency: highlighted cases out of a fixed denominator.",warnings:an(t,{visibleTokens:100,maxRecommendedTokens:100}),alternatives:["labeled-percent","bar-with-risk-threshold"]}}if("memory"===t||"editorial-engagement"===t){let t={tokenType:e.concreteEntity?"glyph":"icon",icon:e.concreteEntity,tokenSemantics:"unitized-measure",countStrategy:"unitized",unitValue:1,layout:"grid",labelPolicy:"text-plus-token",unitMeaning:e.concreteEntity?`one token represents a unit of ${e.concreteEntity}`:"one token represents one unit"};return{recommendedEncoding:"semantic-isotype",tokenEncoding:t,rationale:"Semantic tokens are useful when the chart needs to make a topic concrete and memorable.",warnings:an(t),alternatives:["labeled-bar","hybrid-bar-token"]}}if("frequency-reasoning"===t||"public-explanation"===t||"support-decision"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"distribution"===e.dataType?"possible-outcome":"unitized-measure",countStrategy:"distribution"===e.dataType?"quantile":"unitized",unitValue:"distribution"===e.dataType?void 0:1,tokenCount:n,layout:"distribution"===e.dataType?"dotplot":"bar-segment",labelPolicy:"text-plus-token",unitMeaning:"distribution"===e.dataType?void 0:"one token represents one unit interval"};return{recommendedEncoding:"hybrid-continuous-token",tokenEncoding:t,rationale:"A hybrid view preserves measurement while adding countable tokens for explanation and decisions.",warnings:an(t),alternatives:["bar-or-line","quantile-dotplot","fixed-denominator-icon-array"]}}return{recommendedEncoding:"bar-or-line",rationale:"Use continuous encodings unless the task needs frequency, risk, memory, or outcome reasoning.",warnings:[],alternatives:["unitized-measure","quantile-dotplot","fixed-denominator-icon-array"]}}import{symbol as cn,symbolCircle as un,symbolCross as hn,symbolDiamond as pn,symbolSquare as fn,symbolStar as mn,symbolTriangle as gn,symbolWye as yn}from"d3-shape";function xn(e,t,r){if(r)return r;let i=e??"circle";if("chevron"===i)return function(e){let t=1.5*bn(e),n=.92*t;return`M0,${-t}L${n},${(.78*t).toFixed(3)}L0,${(.28*t).toFixed(3)}L${-n},${(.78*t).toFixed(3)}Z`}(t);let o=Object.prototype.hasOwnProperty.call(n,i)?n[i]:un;return cn(o,Math.max(1,t))()??""}function bn(e){return Math.sqrt(Math.max(1,e)/Math.PI)}function wn(e,t,n){if(!n&&"circle"===(e??"circle"))return bn(t);let r=n?`p:${n}`:`s:${e??"circle"}:${t}`,o=i.get(r);if(null!=o)return o;let a=xn(e,t,n).match(/-?\d*\.?\d+(?:e-?\d+)?/gi),l=0;if(a)for(let e=0;e+1<a.length;e+=2){let t=+a[e],n=+a[e+1],r=Math.sqrt(t*t+n*n);r>l&&(l=r)}return l>0?(i.size>512&&i.clear(),i.set(r,l),l):bn(t)}function Mn(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function vn(e,t,n){return"function"==typeof e?e(t)??n:e??n}function kn(e,t){return"function"==typeof e?e(t):e}function In(e){return e.sample??e.value??e.index}function Sn(e,t){return void 0!==t.datum?vn(t.datum,e,null):e.datum??null}function $n(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?vn(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):vn(t.color,e,m):vn(t.inactiveColor,e,g),stroke:"none",...kn(t.style,e)??{}}}function Nn(e,t){let n=kn(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:Sn(e,t),accessibleDatum:kn(t.accessibleDatum,e),accessibility:kn(t.accessibility,e),pointId:n,_transitionKey:n}}function An({input:e,encoding:t,options:n={}}){if(!Mn(e)&&!t)throw new Error("tokenLayer requires an encoding when input is not a TokenSet.");let r=Mn(e)?{...e,encoding:en(e.encoding)}:rn(e,t),i=function(e,t){let n=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){let n=t.positionToken;return n?e.map((t,r)=>{let i=n(t,r,e);return{...t,x:i.x,y:i.y,row:i.row??r,column:i.column??0}}):[]}(n,t);let r=t.layout??e.encoding.layout??"grid";if("quantile-strip"===r||"dotplot"===r)return function(e,t,n){if(0===e.length)return[];let r=t.x??0,i=t.y??0,o=n?"number"==typeof t.tokenSize?t.tokenSize:12:0,a=n?0:t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),l=t.gutter??2,s=n?t.cellWidth??o+l:12,d=n?t.cellHeight??o+l:a+l,c=n?1:Math.max(1,Math.floor(t.rows??1)),[u,h]=ct(e,In),p=h-u||1,f=n?new Map:null;return e.map((o,a)=>{let l=In(o),h=a%c,m=a,g=t.valueToX?t.valueToX(l,o):r+(l-u)/p*(t.width??Math.max(1,e.length-1)*s);n&&(m=Math.round((g-r)/Math.max(1,s)),h=f.get(m)??0,f.set(m,h+1),g=r+m*s);let y=t.valueToY?t.valueToY(l,o):i+h*d;return{...o,x:g,y:y,row:h,column:m}})}(n,t,"dotplot"===r);if("bar-segment"===r){if(!t.valueToX)throw new Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];let n=t.y??0,r=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.anchor??[.5,.5];return e.map((e,o)=>{let a=Number.isFinite(e.start)?e.start:In(e),l=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,s=t.valueToY?t.valueToY(l,e):n+i[1]*r;return{...e,x:t.valueToX(l,e),y:s,row:0,column:o}})}(n,t)}if("beeswarm"===r||"small-multiple"===r)throw new Error(`tokenLayer layout "${r}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);let i="number"==typeof t.tokenSize?t.tokenSize:void 0,o=t.cellWidth??i??12,a=t.cellHeight??i??o,l="row"===r?Math.max(1,n.length):"column"===r||"stack"===r?1:"waffle"===r&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,n){if(t.columns)return t.columns;if(t.width&&n>0){let e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(n+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(n,t,o);return on(n,{...t,columns:l,cellWidth:o,cellHeight:a})}(r,n).filter(e=>!n.include||n.include(e));return{tokenSet:r,positionedTokens:i,nodes:i.map(e=>function(e,t,n){if("dot"===n.tokenType)return function(e,t){let n=vn(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:vn(t.radius,e,n/2),style:$n(e,t),...Nn(e,t)}}(e,t);let r=kn(t.glyph,e)??function(e){if(e)return f[e]}(n.icon);if(r)return function(e,t,n){let r=$n(e,n),i=vn(n.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:i,glyph:t,color:String(r.fill??m),accent:vn(n.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:e.fraction<1?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:vn(n.fractionDirection,e,"horizontal"),ghostColor:e.fraction<1?kn(n.ghostColor,e)??g:void 0,rotation:kn(n.rotation,e),style:r,...Nn(e,n)}}(e,r,t);let i=function(e){return e&&y.has(e)?e:void 0}(n.icon);return function(e,t){let n=vn(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,n/2)**2,symbolType:vn(t.symbolType,e,"circle"),path:kn(t.symbolPath,e),rotation:kn(t.rotation,e),style:$n(e,t),...Nn(e,t)}}(e,i&&null==t.symbolType?{...t,symbolType:i}:t)}(e,n,r.encoding))}}var n={circle:un,square:fn,triangle:gn,diamond:pn,star:mn,cross:hn,wye:yn},r=["circle","triangle","diamond","star","square","chevron","cross","wye"],i=/*#__PURE__*/new Map,o="#334155",a="#f8fafc",l="#cbd5e1",f={server:s={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},chip:d={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},bolt:c={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},bus:u={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},person:p={viewBox:[18,40],anchor:[.5,1],parts:[{d:h="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",fill:"color",stroke:"color",strokeWidth:1.4}]}},m="var(--semiotic-primary, #4e79a7)",g="var(--semiotic-border, #d1d5db)",y=/*#__PURE__*/new Set(r);import{interpolateRgb as En}from"d3-interpolate";function Cn(e){return e<10?`0${e}`:String(e)}function On(e,t){return e<t?-1:e>t?1:0}function Tn(e,t){if("function"==typeof e)return e;let n=e??t;return e=>e[n]}function Rn(e,t,n){let r=(t+n.lat)/2*(Math.PI/180);return[111.32*(e-n.lon)*Math.cos(r),110.574*(t-n.lat)]}function Ln(e){let t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function Fn(e){return w.has(e)?e:"monument"}function Pn(e,t){let n=Ln(t.gridSize),r=Math.max(1,t.gridRadiusKm??75),i=2*r/n,o=Math.floor(n/2),a=Tn(t.idAccessor,"id"),l=Tn(t.nameAccessor,"name"),s=Tn(t.longitudeAccessor,"lon"),d=Tn(t.latitudeAccessor,"lat"),c=Tn(t.kindAccessor,"kind"),u=t.candidatePriorityAccessor?Tn(t.candidatePriorityAccessor,"priority"):()=>0,h=Array.from({length:n*n},(e,t)=>{let o=Math.floor(t/n),a=t%n;return{id:`tile-${o}-${a}`,row:o,column:a,centerXKm:(a+.5)*i-r,centerYKm:r-(o+.5)*i,terrainIndex:(17*o+31*a)%b.length,landmark:null,landmarks:[]}}),p=[];for(let o of e){let e=Number(s(o)),f=Number(d(o));if(!Number.isFinite(e)||!Number.isFinite(f))continue;let m=String(a(o)??`${e},${f}`),g=String(l(o)??m),y=Fn(c(o)),[x,b]=Rn(e,f,t.center);if(Math.abs(x)>r||Math.abs(b)>r)continue;let w=Math.min(n-1,Math.floor((x+r)/i)),M=Math.min(n-1,Math.floor((r-b)/i)),v=h[M*n+w],k=Number(u(o)),I={...o,id:m,name:g,kind:y,lon:e,lat:f,distanceKm:Math.sqrt(x*x+b*b),row:M,column:w,cellDistanceSq:(x-v.centerXKm)**2+(b-v.centerYKm)**2,candidatePriority:Number.isFinite(k)?k:0};v.landmarks.push(I),m===t.centerId&&p.push(I)}let f=(e,t)=>On(e.name,t.name)||On(e.id,t.id)||e.lon-t.lon||e.lat-t.lat||On(e.kind,t.kind),m=(e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||f(e,t),g=h[o*n+o],y=p.sort(m)[0]??[...g.landmarks].sort((e,t)=>e.candidatePriority-t.candidatePriority||+("city"===t.kind)-+("city"===e.kind)||e.distanceKm-t.distanceKm||f(e,t))[0],x=new Map;y&&x.set(y.kind,1);let w=e=>e.cellDistanceSq+(x.get(e.kind)??0)*i*i*.35,M=(e,t)=>e.candidatePriority-t.candidatePriority||w(e)-w(t)||f(e,t);for(let e of h){let t=e===g;if(e.landmarks=e.landmarks.filter(e=>e!==y).sort(t?m:M),t&&y&&e.landmarks.unshift(y),e.landmark=e.landmarks[0]??null,e.landmark&&e.landmark!==y){let t=e.landmark.kind;x.set(t,(x.get(t)??0)+1)}}return h}var x=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0)return{nodes:[]};let r="utc"===t.timeZone,i=(e,t,n)=>{let i=new Date(0);return r?(i.setUTCFullYear(e,t,n),i.setUTCHours(0,0,0,0)):(i.setFullYear(e,t,n),i.setHours(0,0,0,0)),i},o=e=>r?e.getUTCFullYear():e.getFullYear(),a=e=>`${o(e)}-${Cn(r?e.getUTCMonth()+1:e.getMonth()+1)}-${Cn(r?e.getUTCDate():e.getDate())}`,l=e=>{let n="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];if(n instanceof Date)return n;if("string"==typeof n&&/^\d{4}-\d{2}-\d{2}$/.test(n)){let[e,t,r]=n.split("-").map(Number);return i(e,t-1,r)}return new Date(n)},s=e=>{let n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return null==n?NaN:Number(n)},d=new Map,c=null;for(let t of e.data){let e=l(t);if(!isFinite(e.getTime()))continue;null==c&&(c=o(e));let n=a(e),r=s(t);Number.isFinite(r)&&d.set(n,(d.get(n)??0)+r)}let u=t.year??c??o(new Date),h=1/0,p=-1/0;for(let[e,t]of d)e.startsWith(`${u}-`)&&(t<h&&(h=t),t>p&&(p=t));h===1/0&&(h=0,p=0);let[f,m]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],g=t.missingColor??e.theme.semantic.grid??"#d1d5db",y=e=>{if(p===h)return f;let t=(e-h)/(p-h);return En(f,m)(t)},x=t.gutter??2,b=t.labelInset??0,w=n.width-b,M=n.height,v=Math.min((w-53*x)/54,(M-6*x)/7);if(v<=0)return{nodes:[]};let k=i(u,0,1),I=((r?k.getUTCDay():k.getDay())-(t.weekStart??0)+7)%7,S=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let r=i(u,0,1-I+7*e+t);if(o(r)!==u)continue;let l=a(r),s=d.get(l),c=null==s?g:y(s);S.push({type:"rect",x:n.x+b+e*(v+x),y:n.y+t*(v+x),w:v,h:v,style:{fill:c,stroke:"none"},datum:{date:r,value:s??null,missing:null==s}})}return{nodes:S}},b=["#739b58","#83a964","#668d52","#8baa68"],w=/*#__PURE__*/new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]);import*as zn from"react";import{jsx as Dn}from"react/jsx-runtime";function jn(){let e=(M??(M=zn.createContext(null)),M);return zn.useContext(e)??v}var v={isActive:!1,predicate:()=>!0};import{jsx as _n,jsxs as Wn}from"react/jsx-runtime";function Gn(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Yn(e,t){let n=Gn(e,t);return"string"==typeof n&&n.length>0?n:void 0}function Bn(e){return Yn(S,e)??S.land}function qn(e,t,n,r){return[`M${e},${t-r/2}`,`L${e+n/2},${t}`,`L${e},${t+r/2}`,`L${e-n/2},${t}`,"Z"].join("")}function Vn({tiles:e,tileWidth:t,tileHeight:n,sprites:r,resourceSize:i,citySize:o,showCityLabel:a}){let l=jn(),s=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return Wn("g",{"aria-hidden":"true",pointerEvents:"none",children:[s.map(e=>{let a=e.landmark,s="city"===a.kind?o:i,d=e.y+n/2,c=l.isActive&&!l.predicate(a)?.28:1;return Wn("g",{opacity:c,children:[_n("ellipse",{cx:e.x,cy:e.y+.15*n,rx:.28*s,ry:.1*s,fill:"#17251d",opacity:.32}),_n(Un,{kind:a.kind,href:Yn(r,a.kind),x:e.x-s/2,y:d-s,size:s}),e.landmarks.length>1&&_n(Hn,{x:e.x+.3*t,y:e.y-.19*n,count:e.landmarks.length-1,tileHeight:n})]},e.id)}),a&&s.filter(e=>"city"===e.landmark?.kind).map(e=>{let t=e.landmark.name.toUpperCase(),r=Math.max(56,6.4*t.length+14);return Wn("g",{transform:`translate(${e.x},${e.y+.72*n})`,children:[_n("rect",{x:-r/2,y:-7,width:r,height:14,rx:1,fill:"#17251d",opacity:.92}),_n("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},`${e.landmark.id}-label`)})]})}function Hn({x:e,y:t,count:n,tileHeight:r}){let i=Math.max(10,Math.min(15,.34*r)),o=`+${n}`,a=Math.max(i,o.length*i*.58);return Wn("g",{transform:`translate(${e},${t})`,children:[_n("rect",{x:-a/2,y:-i/2,width:a,height:i,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),_n("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*i),fontWeight:700,children:o})]})}function Un({kind:e,href:t,x:n,y:r,size:i}){if(t)return _n("image",{href:t,x:n,y:r,width:i,height:i,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});let o=A[e],a=E[e];return _n("svg",{x:n,y:r,width:i,height:i,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:o.flatMap((e,t)=>[...e].map((e,n)=>"."===e?null:_n("rect",{x:n,y:t,width:1,height:1,fill:a[e]},`${t}-${n}`)))})}var k={resource:32,city:64},I={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},S={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},$=/*#__PURE__*/new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]),N=e=>{let t=Ln(e.config.gridSize),n=Math.max(20,e.config.tileWidth??80),r=Math.max(10,e.config.tileHeight??40),i=e.config.terrainColors?.length?e.config.terrainColors:b,o=t*r,a=e.dimensions.width/2,l=(e.dimensions.height-o)/2+r/2,s=Pn(e.points,e.config).map(e=>({...e,x:a+(e.column-e.row)*(n/2),y:l+(e.column+e.row)*(r/2)}));return{nodes:s.map(t=>{let o=function(e,t){let n=Gn(e,t),r=function(e){return $.has(e)?e:void 0}("string"==typeof n?n:Gn(n,"kind"));if(!r)return;if("string"==typeof n)return{kind:r};let i=Gn(n,"coverage"),o="number"==typeof i&&Number.isFinite(i)?Math.max(0,Math.min(1,i)):void 0,a=Yn(n,"fill");return{kind:r,...null==o?{}:{coverage:o},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":o?.kind??"land",l=o?.fill??Yn(e.config.terrainPalette,a)??function(e){return Yn(I,e)??I.land}(a),s=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:o?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:Bn(a),kind:"terrain",terrainKind:a,terrainCoverage:o?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};return{type:"geoarea",pathData:qn(t.x,t.y,n,r),centroid:[t.x,t.y],bounds:[[t.x-n/2,t.y-r/2],[t.x+n/2,t.y+r/2]],screenArea:n*r/2,style:{fill:o||"urban"===a?l:i[t.terrainIndex%i.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:s,group:t.landmark?.kind??a,interactive:!0}}),overlays:_n(Vn,{tiles:s,tileWidth:n,tileHeight:r,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??k.resource,citySize:e.config.citySpriteSize??k.city,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}},A={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},E={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};import{jsx as Xn}from"react/jsx-runtime";function Kn(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function Jn(e){let t=1/0,n=-1/0;for(let r of e)Number.isFinite(r)&&(r<t&&(t=r),r>n&&(n=r));return t===1/0?[0,0]:[t,n]}function Zn(e,t){let n=t[1]-t[0];return 0===n?.5:(e-t[0])/n}function Qn(e,t={}){let n=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===n.length)return[];let r=gt(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),i=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8,o=Kn(t.columns)??Math.max(1,Math.ceil(Math.sqrt(n.length*i/r))),a=Kn(t.rows)??Math.max(1,Math.ceil(n.length/(o*r)));o*a<n.length&&(null!=t.columns&&null==t.rows?a=Math.ceil(n.length/o):null!=t.rows&&null==t.columns?o=Math.ceil(n.length/a):a=Math.ceil(n.length/o));let l=Jn(n.map(e=>e.x)),s=Jn(n.map(e=>e.y)),d=n.map(e=>({...e,desiredColumn:Zn(e.x,l)*Math.max(0,o-1),desiredRow:Zn(e.y,s)*Math.max(0,a-1)})),c=(o-1)/2,u=(a-1)/2;d.sort((e,t)=>{let n=(e.desiredColumn-c)**2+(e.desiredRow-u)**2;return(t.desiredColumn-c)**2+(t.desiredRow-u)**2-n||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index});let h=new Set;for(let e=0;e<a;e+=1)for(let t=0;t<o;t+=1)h.add(e*o+t);let p=[];for(let e of d){let t=-1,n=1/0;for(let r of h){let i=Math.floor(r/o),a=(r%o-e.desiredColumn)**2+(i-e.desiredRow)**2;(a<n||a===n&&r<t)&&(t=r,n=a)}t<0||(h.delete(t),p.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/o),column:t%o,index:e.index}))}return p.sort((e,t)=>e.index-t.index),p.map(({index:e,...t})=>t)}function er(e,t,n=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(let t of n)if(null!=e[t])return e[t]}function tr(e){return`${e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")}Z`}function nr(e,t,n){return tr([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}function rr(e,t,n){let r=[];for(let i=0;i<6;i+=1){let o=-Math.PI/2+i*(Math.PI/3);r.push([e+Math.cos(o)*n,t+Math.sin(o)*n])}return tr(r)}function ir({marks:e,color:t,fontSize:n,fontFamily:r,fontWeight:i}){let o=jn();return Xn("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{let a=!o.isActive||o.predicate(e.datum);return Xn("text",{x:e.x,y:e.y,fill:t,fontFamily:r,fontSize:n,fontWeight:i,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}var C=e=>{let t=e.config,n=t.source??"auto",r="areas"===n||"auto"===n&&e.areas.length>0,i=(r?function(e){return e.areas.map((t,n)=>{let r=function(e,t){let n=e.properties&&"object"==typeof e.properties?e.properties:{},r=e.id??n.id??n.name??`area-${t}`;return{...n,id:String(r)}}(t,n),i=e.scales.geoPath.centroid(t),o=Number.isFinite(i[0])&&Number.isFinite(i[1])?e.scales.invertedPoint(i[0],i[1]):null;return{datum:{...r,gridLongitude:o?.[0],gridLatitude:o?.[1]},x:i[0],y:i[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t}))).filter((e,n)=>!t.filter||t.filter(e.datum,n)),o=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;let n=e.map(e=>({datum:e,x:Number(er(e,t.columnAccessor)),y:Number(er(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return n.length!==e.length?null:n.map(e=>({...e,row:e.y,column:e.x}))}(i.map(e=>e.datum),t),a=r?i:function(e){return e.points.map(t=>{let n=Number(er(t,e.config.longitudeAccessor,["lon","longitude"])),r=Number(er(t,e.config.latitudeAccessor,["lat","latitude"])),i=Number.isFinite(n)&&Number.isFinite(r)?e.scales.projectedPoint(n,r):null;return{datum:t,x:i?.[0]??NaN,y:i?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:i.map(e=>e.datum)}),l=o??Qn(a,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===l.length)return{nodes:[]};let s=Jn(l.map(e=>e.row)),d=Jn(l.map(e=>e.column)),c=Math.max(1,Math.round(s[1]-s[0])+1),u=Math.max(1,Math.round(d[1]-d[0])+1),h=Math.max(0,t.layoutPadding??8),p=Math.max(1,e.dimensions.width-2*h),f=Math.max(1,e.dimensions.height-2*h),m=p/u,g=f/c,y=m*u,x=g*c,b=(e.dimensions.width-y)/2,w=(e.dimensions.height-x)/2,M=gt(t.cellPadding??.12,0,.8),v=Math.max(1,.5*Math.min(m,g)*(1-M)),k=t.sizeAccessor?l.map(e=>Number(er(e.datum,t.sizeAccessor))):[],I=t.sizeDomain??Jn(k),S=t.sizeRange??[.36,1],$=gt(Math.min(S[0],S[1]),.05,1),N=gt(Math.max(S[0],S[1]),$,1),A=l.map((n,r)=>{let i={...n.datum,gridRow:n.row,gridColumn:n.column},o=String(er(i,t.idAccessor,["id","key","name"])??`grid-${r}`),a=String(er(i,t.labelAccessor,["abbr","code","label","name","id"])??o),l=Math.max(1,t.maxLabelLength??4),c=a.length>l?a.slice(0,l):a,u=er(i,t.categoryAccessor),h=null==u?void 0:String(u),p=er(i,t.fillAccessor),f=null!=p?String(p):h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",y=t.sizeAccessor?Number(er(i,t.sizeAccessor)):NaN,x=t.sizeAccessor&&Number.isFinite(y)?Math.sqrt(gt(Zn(y,I),0,1)):1,M=v*($+x*(N-$)),k="function"==typeof t.markStyle?t.markStyle(i,r):t.markStyle;return{datum:i,id:o,label:c,category:h,row:n.row,column:n.column,x:b+(n.column-d[0]+.5)*m,y:w+(n.row-s[0]+.5)*g,radius:M,style:{fill:f,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...k}}}),E=t.shape??"circle";return{nodes:A.map(e=>"circle"===E?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===E?rr(e.x,e.y,e.radius):nr(e.x,e.y,e.radius),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===E?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0}),overlays:!1===t.showLabels?null:Xn(ir,{marks:A,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??gt(.23*Math.min(m,g),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};import{geoBounds as or,geoContains as ar}from"d3-geo";import{jsx as lr}from"react/jsx-runtime";function sr(e){if(Number.isFinite(e)&&!(Number(e)<=0))return Number(e)}function dr(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function cr(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function ur(e,t){let n=cr(e);return String(e.id??n.id??n.name??`feature-${t}`)}function hr(e,t,n,r){return[Math.ceil((e-n)/r-.5),Math.floor((t-n)/r-.5)]}function pr(e){if(!e)return 0;let t=R.get(e);if(t)return t;let n=L;return L+=1,R.set(e,n),n}function fr(e,t){return!t||e[1]>=t[0][1]&&e[1]<=t[1][1]&&function(e,t,n){return t<=n?e>=t&&e<=n:e>=t||e<=n}(e[0],t[0][0],t[1][0])}function mr(e,t){for(let n of e){let{feature:e,index:r}=n;if(e.geometry&&fr(t,n.bounds))try{if(ar(e,t))return{feature:e,index:r}}catch{}}return null}function gr(e,t,n,r={}){let i=e.filter((e,t)=>e.geometry&&(!r.featureFilter||r.featureFilter(e,t))),o=function(e,t){if(0===e.length)return null;let n={type:"FeatureCollection",features:e},r=t.bounds(n);return Number.isFinite(r[0][0])&&Number.isFinite(r[0][1])&&Number.isFinite(r[1][0])&&Number.isFinite(r[1][1])?r:null}(i,t.geoPath);if(!o)return{dots:[],cellSize:10,features:i};let a=Math.max(0,r.layoutPadding??0),l=[[gt(o[0][0],a,Math.max(a,n.width-a)),gt(o[0][1],a,Math.max(a,n.height-a))],[gt(o[1][0],a,Math.max(a,n.width-a)),gt(o[1][1],a,Math.max(a,n.height-a))]],s=Math.max(0,l[1][0]-l[0][0]),d=Math.max(0,l[1][1]-l[0][1]);if(0===s||0===d)return{dots:[],cellSize:10,features:i};let c=sr(r.columns),u=Math.max(2,c?s/c:sr(r.cellSize)??10),h=Math.max(100,Math.round(sr(r.maxSamples)??25e3)),p=Math.ceil(s/u)*Math.ceil(d/u);p>h&&(u*=Math.sqrt(p/h));let f=r.gridOrigin?.[0]??0,m=r.gridOrigin?.[1]??0,[g,y]=hr(l[0][0],l[1][0],f,u),[x,b]=hr(l[0][1],l[1][1],m,u),w=[],M=function(e){return e.map((e,t)=>{if(T.has(e))return{feature:e,index:t,bounds:T.get(e)??null};try{let n=or(e);return T.set(e,n),{feature:e,index:t,bounds:n}}catch{return T.set(e,null),{feature:e,index:t,bounds:null}}})}(i);for(let e=x;e<=b;e+=1){let n=m+(e+.5)*u;for(let i=g;i<=y;i+=1){let o=f+(i+.5)*u,a=t.invertedPoint(o,n);if(!a||!Number.isFinite(a[0])||!Number.isFinite(a[1]))continue;let l=mr(M,a);if(!l)continue;let s={...cr(l.feature),featureId:ur(l.feature,l.index),featureIndex:l.index,gridRow:e,gridColumn:i,longitude:a[0],latitude:a[1],dotIndex:w.length};r.dotFilter&&!r.dotFilter(s,w.length)||w.push(s)}}return{dots:w,cellSize:u,features:i}}function yr(e){return Math.round(1e4*e)/1e4}function xr(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${yr(Number(e[0]))},${yr(Number(e[1]))}`:"null"}function br(e,t){let n=e[t];return"function"==typeof n?n.call(e):void 0}function wr(e){return"number"==typeof e&&Number.isFinite(e)?String(yr(e)):null===e?"null":"unavailable"}function Mr(e){return Array.isArray(e)&&e.every(Number.isFinite)?e.map(e=>yr(Number(e))).join(","):"unavailable"}function vr(e){let t=e.scales.projection;return[wr(br(t,"scale")),xr(br(t,"translate")),xr(br(t,"center")),Mr(br(t,"rotate")),wr(br(t,"clipAngle")),wr(br(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,n])=>xr(e.scales.projectedPoint(t,n)))].join("|")}function kr(e){return`${e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")}Z`}function Ir(e,t,n){return kr([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}function Sr(e,t,n){return kr(Array.from({length:6},(r,i)=>{let o=-Math.PI/2+i*(Math.PI/3);return[e+Math.cos(o)*n,t+Math.sin(o)*n]}))}function $r(e,t,n){let r=e.data??e,i=r.x??e.x,o=r.y??e.y,a=e.createdByFrame&&0===e.width?void 0:e.width,l=e.createdByFrame&&0===e.height?void 0:e.height,s=r.width??a??t,d=r.height??l??n;if(!("number"!=typeof i||"number"!=typeof o||"number"!=typeof s||"number"!=typeof d||![i,o,s,d].every(Number.isFinite)||s<=0||d<=0))return{x:i,y:o,w:s,h:d}}function Nr(e,t,n){let{nodeWidth:r,nodeHeight:i,waypoints:o=[]}=n,a="none"===n.fit?"none":"contain",l=1/0,s=1/0,d=-1/0,c=-1/0,u=(e,t)=>{l=Math.min(l,e),s=Math.min(s,t),d=Math.max(d,e),c=Math.max(c,t)},h=!1;for(let t of e){let e=$r(t,r,i);e&&(h=!0,u(e.x-e.w/2,e.y-e.h/2),u(e.x+e.w/2,e.y+e.h/2))}for(let e of o)u(e.x,e.y);let p=1,f=0,m=0;if("contain"===a&&h){let e=d-l,n=c-s;if(![e,n,t.x,t.y,t.width,t.height].every(Number.isFinite)||e<=0||n<=0||t.width<=0||t.height<=0)h=!1;else{let r=Math.min(1,t.width/4,t.height/4);p=Math.min(1,(t.width-2*r)/e,(t.height-2*r)/n),f=t.x+(t.width-e*p)/2-l*p,m=t.y+(t.height-n*p)/2-s*p}}let g=({x:e,y:t})=>({x:e*p+f,y:t*p+m});return{fit:a,scale:p,dx:f,dy:m,bounds:h?{x:l,y:s,width:d-l,height:c-s}:null,project:g,invert:({x:e,y:t})=>({x:(e-f)/p,y:(t-m)/p}),nodeBounds:e=>{let t=h?$r(e,r,i):void 0;if(!t)return;let{x:n,y:o}=g(t),a=t.w*p,l=t.h*p;return{x:n-a/2,y:o-l/2,width:a,height:l,cx:n,cy:o}}}}function Ar(e,t,n,r=[]){let i=Nr(e.nodes,e.dimensions.plot,{nodeWidth:t.nodeWidth,nodeHeight:t.nodeHeight,fit:t.fit,waypoints:r}),o=new Map,a=[],l=[];for(let r of e.nodes){let s=i.nodeBounds(r);if(!s)continue;let{cx:d,cy:c,width:u,height:h}=s;o.set(r.id,{x:d,y:c,w:u,h:h});let p=r.data??r,f=t.labelAccessor??"id",m=String("function"==typeof f?f(p):p[f]??r.id);a.push({type:"rect",x:s.x,y:s.y,w:u,h:h,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:n,strokeWidth:Math.min(1.5,u/2,h/2)},datum:p,id:r.id,label:m}),!1!==t.showLabels&&l.push({x:d,y:c,text:m,anchor:"middle",baseline:"middle",fontSize:11*i.scale})}return{positions:o,sceneNodes:a,labels:l,project:i.project}}function Er(e,t,n={}){return Nr(e,t,{nodeWidth:n.nodeWidth??80,nodeHeight:n.nodeHeight??30,fit:n.fit})}var O=/*#__PURE__*/new WeakMap,T=/*#__PURE__*/new WeakMap,R=/*#__PURE__*/new WeakMap,L=1,F=e=>{let t=function(e){let t=O.get(e.areas);t||(t=new Map,O.set(e.areas,t));let n=function(e){let t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",pr(t.featureFilter),pr(t.dotFilter),vr(e)].join("::")}(e),r=t.get(n);if(r)return r;let i=gr(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){let e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(n,i),i}(e),n=e.config,r=n.shape??"circle",i=Math.max(.5,sr(n.dotRadius)??t.cellSize*gt(n.radiusRatio??.24,.05,.5)),o=n.gridOrigin?.[0]??0,a=n.gridOrigin?.[1]??0;return{nodes:t.dots.map((l,s)=>{let d=o+(l.gridColumn+.5)*t.cellSize,c=a+(l.gridRow+.5)*t.cellSize,u=dr(l,n.categoryAccessor),h=dr(l,n.fillAccessor),p={fill:null!=h?String(h):null!=u?e.resolveColor(String(u)):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof n.markStyle?n.markStyle(l,s):n.markStyle},f=`dot-${l.gridRow}-${l.gridColumn}`;return"circle"===r?{type:"point",x:d,y:c,r:i,style:p,datum:l,interactive:!1,pointId:f,_transitionKey:f}:{type:"geoarea",pathData:"hexagon"===r?Sr(d,c,i):Ir(d,c,i),centroid:[d,c],bounds:[[d-i,c-i],[d+i,c+i]],screenArea:"hexagon"===r?3*Math.sqrt(3)*i*i/2:(2*i)**2,style:p,datum:l,group:l.featureId,interactive:!1}}),overlays:n.showOutline?lr("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,r)=>{let i=e.scales.geoPath(t);return i?lr("path",{d:i,fill:"none",stroke:n.outlineStyle?.stroke??"currentColor",strokeOpacity:n.outlineStyle?.opacity??n.outlineStyle?.fillOpacity??.22,strokeWidth:n.outlineStyle?.strokeWidth??.7,strokeDasharray:n.outlineStyle?.strokeDasharray,strokeLinecap:n.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},ur(t,r)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},P=e=>{let t=e.config??{},n=t.orientation??"vertical",r=t.edgeCurve??"curved",{positions:i,sceneNodes:o,labels:a}=Ar(e,{...t,nodeWidth:t.nodeWidth??80,nodeHeight:t.nodeHeight??30},`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`),l=[];for(let t of e.edges){let o="string"==typeof t.source?t.source:t.source.id,a="string"==typeof t.target?t.target:t.target.id,s=i.get(o),d=i.get(a);if(!s||!d)continue;let c="vertical"===n?{x:s.x,y:s.y+s.h/2}:{x:s.x+s.w/2,y:s.y},u="vertical"===n?{x:d.x,y:d.y-d.h/2}:{x:d.x-d.w/2,y:d.y};if("line"===r)l.push({type:"line",x1:c.x,y1:c.y,x2:u.x,y2:u.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t.data??t});else{let r=(c.y+u.y)/2,i=(c.x+u.x)/2,o="vertical"===n?`M${c.x},${c.y} C${c.x},${r} ${u.x},${r} ${u.x},${u.y}`:`M${c.x},${c.y} C${i},${c.y} ${i},${u.y} ${u.x},${u.y}`;l.push({type:"curved",pathD:o,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t.data??t})}}return{sceneNodes:o,sceneEdges:l,labels:a}};import{createElement as Cr}from"react";import{createElement as Or}from"react";function Tr(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.min(0===n?1/0:e.w/2/Math.abs(n),0===r?1/0:e.h/2/Math.abs(r));return Number.isFinite(i)?{x:e.x+n*i,y:e.y+r*i}:{x:e.x,y:e.y}}function Rr(e,t,n,r,i,o=1){let a=t.x-n.x,l=t.y-n.y,s=Math.hypot(a,l);if(0===s||i<=0)return null;let d=Math.min(i,s)/s,c=a*d,u=l*d;return Or("polygon",{key:e,className:"recipe-edge-arrow",points:`${t.x},${t.y} ${t.x-c-u/2},${t.y-u+c/2} ${t.x-c+u/2},${t.y-u-c/2}`,fill:r,opacity:o,"aria-hidden":!0,style:{pointerEvents:"none"}})}import{NetworkPerspectiveGround as Lr}from"./semiotic-network-placement.module.min.js";function Fr(e){let t=e.data??e,n=Array.isArray(t.points)?t.points:e.points;return Array.isArray(n)&&n.length>=2&&n.every(e=>e&&Number.isFinite(e.x)&&Number.isFinite(e.y))?n:[]}function Pr(e,t,n,r={}){return Nr(e,n,{nodeWidth:r.nodeWidth??100,nodeHeight:r.nodeHeight??36,fit:r.fit,waypoints:t.flatMap(Fr)})}var z=e=>{let t=e.config??{},n=t.edgeStyle??"polyline",r=new Map(e.edges.map(e=>[e,Fr(e)])),{positions:i,sceneNodes:o,labels:a,project:l}=Ar(e,{...t,nodeWidth:t.nodeWidth??100,nodeHeight:t.nodeHeight??36,labelAccessor:t.labelAccessor??"label"},`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,[...r.values()].flat()),s=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`;for(let e=0;e<a.length;e++){let t=a[e],n=i.get(o[e].id);if(!n)continue;let r=Math.max(1,Math.floor(n.w/(.6*(t.fontSize??11))-2));t.text.length>r&&(t.text=t.text.slice(0,r-1)+"…")}let d=[],c=[];for(let t of e.edges){let e="string"==typeof t.source?t.source:t.source.id,o="string"==typeof t.target?t.target:t.target.id,a=i.get(e),u=i.get(o);if(!a||!u)continue;let h=r.get(t).map(l);if(h.length<2){let e=Tr(a,u),n=Tr(u,a);d.push(Rr(d.length,n,e,s,Math.min(7,u.w/4,u.h/3))),c.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:s,strokeWidth:1},datum:t.data??t});continue}let p=h[h.length-1],f=h.slice(0,-1).reverse().find(e=>e.x!==p.x||e.y!==p.y);if(f&&d.push(Rr(d.length,p,f,s,Math.min(7,u.w/4,u.h/3))),"smooth"===n&&h.length>=3){let e=`M${h[0].x},${h[0].y}`;for(let t=1;t<h.length-1;t++){let n=(h[t].x+h[t+1].x)/2,r=(h[t].y+h[t+1].y)/2;e+=` Q${h[t].x},${h[t].y} ${n},${r}`}let n=h[h.length-1];e+=` T${n.x},${n.y}`,c.push({type:"curved",pathD:e,style:{stroke:s,strokeWidth:1,fill:"none"},datum:t.data??t})}else{let e="M"+h.map(e=>`${e.x},${e.y}`).join(" L ");c.push({type:"curved",pathD:e,style:{stroke:s,strokeWidth:1,fill:"none"},datum:t.data??t})}}return{sceneNodes:o,sceneEdges:c,labels:a,overlays:d.length?Cr("g",null,Cr(Lr,{z:"top"},d)):null,perspective:"manual"}};import{createElement as zr}from"react";import{NetworkPerspectiveBillboard as Dr,NetworkPerspectiveGround as jr}from"./semiotic-network-placement.module.min.js";function _r(e,t){let n="function"==typeof t?t(e):e[t];return D(n)?n:void 0}function Wr(e){return[...e].sort((e,t)=>Rt(e,t))}function Gr(e,t,n){let r=new Map([[e,0]]),i=[e];for(let e=0;e<i.length;e++){let o=i[e],a=r.get(o);for(let e of Wr(n.get(o)??[]))!t.has(e)||r.has(e)||(r.set(e,a+1),i.push(e))}return r}function Yr(e,t,n){let r=Gr(e,t,n),i=e,o=-1;for(let[e,t]of r)(t>o||t===o&&Rt(e,i)<0)&&(i=e,o=t);return i}function Br(e,t,n){let r=new Set(e),i=e.filter(e=>(t.get(e)?.size??0)<=1)[0]??e[0],o=Gr(n&&r.has(n)?n:Yr(Yr(i,r,t),r,t),r,t),a=0;for(let e of o.values())a=Math.max(a,e);let l=Array.from({length:a+1},()=>[]);for(let t of e)l[o.get(t)??0].push(t);l.forEach(e=>e.sort((e,t)=>Rt(e,t)));let s=(e,n)=>{let r=new Map(l[n].map((e,t)=>[e,t])),i=e=>{let n=[...t.get(e)??[]].map(e=>r.get(e)).filter(e=>null!=e);return 0===n.length?Number.POSITIVE_INFINITY:n.reduce((e,t)=>e+t,0)/n.length},o=new Map(l[e].map(e=>[e,i(e)]));l[e].sort((e,t)=>o.get(e)-o.get(t)||Rt(e,t))};for(let e=0;e<4;e+=1){for(let e=1;e<l.length;e+=1)s(e,e-1);for(let e=l.length-2;e>=0;e-=1)s(e,e+1)}return l}function qr(e,t,n,r={}){let i=Math.max(0,r.padding??36),o=Math.max(0,r.componentGap??26),a=r.xAccessor??"x",l=r.yAccessor??"y",s=e.map(e=>({...e,authoredX:_r(e.data,a),authoredY:_r(e.data,l)})),d=s.length>0&&s.every(e=>D(e.authoredX)&&D(e.authoredY)),c="authored"===r.layoutMode||"automatic"!==r.layoutMode&&d,u=[];if(c&&!d&&u.push("Authored transit layout requested, but at least one station has no finite x/y position; using automatic topology layout."),!c||!d){!d&&"automatic"!==r.layoutMode&&u.push("Complete station positions were not supplied; using the deterministic automatic topology layout.");let a=function(e,t,n,r,i,o){let a=function(e,t){let n=new Map(e.map(e=>[e,new Set]));for(let e of t)!n.has(e.source)||!n.has(e.target)||(n.get(e.source)?.add(e.target),n.get(e.target)?.add(e.source));return n}(e.map(e=>e.id),t),l=function(e){let t=new Set(e.keys()),n=[];for(let r of Wr(t)){if(!t.has(r))continue;let i=[r],o=[];t.delete(r);for(let n=0;n<i.length;n++){let r=i[n];o.push(r);for(let n of Wr(e.get(r)??[]))t.has(n)&&(t.delete(n),i.push(n))}n.push(o.sort((e,t)=>Rt(e,t)))}return n.sort((e,t)=>t.length-e.length||Rt(e[0],t[0]))}(a),s=new Map(e.map(e=>[e.id,e.data])),d=new Map,c=Math.max(0,n.width),u=Math.max(0,n.height),h=Math.min(r,c/2),p=Math.min(r,u/2),f=Math.max(0,u-2*p),m=l.length>1?Math.min(i,f/l.length):0,g=Math.max(0,f-m*Math.max(0,l.length-1)),y=l.reduce((e,t)=>e+Math.sqrt(t.length),0),x=p;for(let e of l){let t=g*(Math.sqrt(e.length)/y),n=Br(e,a,o),r=Math.max(0,c-2*h);n.forEach((e,i)=>{let o=1===n.length?c/2:h+i/(n.length-1)*r;e.forEach((n,r)=>{let i=1===e.length?x+t/2:x+r/(e.length-1)*t;d.set(n,{id:n,x:o,y:i,data:s.get(n)})})}),x+=t+m}return d}(e,t,n,i,o,r.rootId);if("right-to-left"===r.direction)for(let e of a.values())e.x=n.width-e.x;return{positions:a,mode:"automatic",warnings:u,projectAuthoredPoint:e=>e}}let h=1/0,p=-1/0,f=1/0,m=-1/0;for(let e of s)h=Math.min(h,e.authoredX),p=Math.max(p,e.authoredX),f=Math.min(f,e.authoredY),m=Math.max(m,e.authoredY);let g=Math.max(1,n.width-2*i),y=Math.max(1,n.height-2*i),x=e=>({x:p===h?n.width/2:i+(e.x-h)/(p-h)*g,y:m===f?n.height/2:i+(e.y-f)/(m-f)*y}),b=new Map;for(let e of s){let t=x({x:e.authoredX,y:e.authoredY});b.set(e.id,{id:e.id,...t,data:e.data})}return{positions:b,mode:"authored",warnings:u,projectAuthoredPoint:x}}function Vr(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.abs(n),o=Math.abs(r);if(i<.001||o<.001||Math.abs(i-o)<.001)return[e,t];let a=Math.sign(n),l=Math.sign(r);if(i>o){let n=(i-o)/2;return[e,{x:e.x+a*n,y:e.y},{x:t.x-a*n,y:t.y},t]}let s=(o-i)/2;return[e,{x:e.x,y:e.y+l*s},{x:t.x,y:t.y-l*s},t]}function Hr(e,t){if(0===t||e.length<2)return e.map(e=>({...e}));let n=(e,t)=>{let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r)||1;return{x:-r/i,y:n/i}};return e.map((r,i)=>{let o=i>0?n(e[i-1],r):null,a=i<e.length-1?n(r,e[i+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 l=o.x+a.x,s=o.y+a.y,d=Math.hypot(l,s);if(d<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};l/=d,s/=d;let c=l*a.x+s*a.y;if(Math.abs(c)<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};let u=4*Math.abs(t),h=t/c,p=Math.max(-u,Math.min(u,h));return{x:r.x+l*p,y:r.y+s*p}})}function Ur(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let n=Math.max(0,t),r=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let i=e[t-1],o=e[t],a=e[t+1],l=Math.hypot(o.x-i.x,o.y-i.y),s=Math.hypot(a.x-o.x,a.y-o.y),d=Math.min(n,l/2,s/2);if(d<=.001){r+=` L${o.x},${o.y}`;continue}let c={x:o.x+(i.x-o.x)/l*d,y:o.y+(i.y-o.y)/l*d},u={x:o.x+(a.x-o.x)/s*d,y:o.y+(a.y-o.y)/s*d};r+=` L${c.x},${c.y} Q${o.x},${o.y} ${u.x},${u.y}`}let i=e[e.length-1];return`${r} L${i.x},${i.y}`}function Xr(e,t){return"function"==typeof t.labelAccessor?t.labelAccessor(e.data):xt(e.data,t.labelAccessor??"label",e.id)}function Kr(e){return"string"==typeof e?e:e.id}function Jr(e,t){let n,r=t.lineAccessor;return n="function"==typeof r?r(e.data):"string"==typeof r?e.data[r]:e.data.lines??e.data.line??e.data.route??e.data.group,function(e){let t=(Array.isArray(e)?e:null==e?[]:[e]).map(e=>"object"==typeof e?{...e,id:String(e.id)}:{id:String(e)});return t.length>0?t:[{id:"network"}]}(n)}function Zr(e,t,n){let r=t.sourceColorAccessor,i="function"==typeof r?r(e.data):"string"==typeof r?e.data[r]:e.data.color;return"string"==typeof i&&i?i:n(e.id)}function Qr(e,t,n,r){if(e.color)return e.color;let i=n.lineColors&&Object.prototype.hasOwnProperty.call(n.lineColors,e.id)?n.lineColors[e.id]:void 0;if("string"==typeof i&&i)return i;let o=n.lineColorAccessor,a="function"==typeof o?o(t.data):"string"==typeof o?t.data[o]:t.data.color;return"string"==typeof a?a:r(e.id)}function ei(e,t){let n=new Map((t.lineOrder??[]).map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e)??Number.POSITIVE_INFINITY)-(n.get(t)??Number.POSITIVE_INFINITY)||Rt(e,t))}function ti(e,t){let n=e.authoredOrder??t.lineOrder??[],r=new Map(n.map((e,t)=>[e,t]));return[...e.lines.values()].sort((e,t)=>(r.get(e.descriptor.id)??Number.POSITIVE_INFINITY)-(r.get(t.descriptor.id)??Number.POSITIVE_INFINITY)||Rt(e.descriptor.id,t.descriptor.id))}function ni(e,t,n,r){if("authored"!==t.mode)return null;let i=e.data[n.pointsAccessor??"points"];if(!Array.isArray(i))return null;let o=i.map(e=>{let n=e;return"number"==typeof n.x&&"number"==typeof n.y?t.projectAuthoredPoint({x:n.x,y:n.y}):null}).filter(e=>null!=e);return 0===o.length?null:r?o.reverse():o}function ri(e,t){return Mt(n=>{for(let[t,r]of Object.entries(e.data))n(t,r);n("source",e.source),n("target",e.target),n("lineId",t.id),n("lineLabel",t.label??t.id)})}function ii(e,t){return e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top}function oi(e,t,n,r,i,o){if(!1===o.showLabels)return[];let a=o.labelFontSize??11,l=[],s=[],d=[...e].sort((e,t)=>(n.get(t.id)?.size??0)-(n.get(e.id)?.size??0)||Rt(e.id,t.id));for(let e of d){let n=t.get(e.id);if(!n)continue;let d=("function"==typeof o.labelAccessor?o.labelAccessor(e.data):String(xt(e.data,o.labelAccessor??"label",e.id)))||e.id,c=Math.max(2*a,d.length*a*.58),u=1.25*a,h=Math.max(o.interchangeRadius??7,r.get(e.id)??o.stationRadius??4)+5,p=[{x:n.x+h,y:n.y,anchor:"start",left:n.x+h},{x:n.x-h,y:n.y,anchor:"end",left:n.x-h-c},{x:n.x,y:n.y-h,anchor:"middle",left:n.x-c/2},{x:n.x,y:n.y+h,anchor:"middle",left:n.x-c/2}].map((e,t)=>{let n={left:e.left,right:e.left+c,top:e.y-u/2,bottom:e.y+u/2},r=l.filter(e=>ii(n,e)).length,o=Math.max(0,-n.left)+Math.max(0,n.right-i.width)+Math.max(0,-n.top)+Math.max(0,n.bottom-i.height);return{candidate:e,box:n,score:1e4*r+10*o+t}}).sort((e,t)=>e.score-t.score)[0];l.push(p.box),s.push({x:p.candidate.x,y:p.candidate.y,anchorPoint:[n.x,n.y],text:d,anchor:p.candidate.anchor,baseline:"middle",fontSize:a,fill:o.labelColor??"var(--semiotic-text, #222)",stroke:"var(--semiotic-bg, white)",strokeWidth:3,paintOrder:"stroke"})}return s}var D=e=>"number"==typeof e&&Number.isFinite(e),j=e=>{let t=e.config??{},n=t.mode??"primary",r=t.dimOpacity??.14,i=(t,n=e.selection)=>n?.isActive&&!n.predicate(t)?r:1,o=e.nodes.map(e=>({id:e.id,data:bt(e),wrapper:e})).sort((e,t)=>Rt(e.id,t.id)),a=e.edges.map(e=>({source:Kr(e.source),target:Kr(e.target),data:bt(e),wrapper:e})).sort((e,t)=>Rt(e.source,t.source)||Rt(e.target,t.target)),l=qr(o,a,e.dimensions.plot,t),s="source-rooted"===t.lineMode?function(e,t,n,r){let i=new Set(e.map(e=>e.id)),o=new Map(e.map(e=>[e.id,0])),a=new Map(e.map(e=>[e.id,[]]));for(let e of t)!i.has(e.source)||!i.has(e.target)||(o.set(e.target,(o.get(e.target)??0)+1),a.get(e.source)?.push(e));let l=e.filter(e=>0===(o.get(e.id)??0)),s=new Map,d=new Map(e.map(e=>[e.id,new Map]));for(let e of l){let t={id:e.id,label:String(Xr(e,n)),color:Zr(e,n,r)},i=new Set,o=[e.id];for(;o.length>0;){let e=o.shift();if(!i.has(e)){i.add(e),d.get(e)?.set(t.id,t);for(let n of a.get(e)??[]){let e=s.get(n);e||(e=new Map,s.set(n,e)),e.set(t.id,t),i.has(n.target)||o.push(n.target)}}}}let c=e=>[...e].sort((e,t)=>Rt(e.id,t.id));return{byEdge:new Map(t.map(e=>[e,c(s.get(e)?.values()??[])])),byNode:new Map(e.map(e=>[e.id,c(d.get(e.id)?.values()??[])]))}}(o,a,t,e.resolveColor):void 0,d=function(e,t,n){let r=new Map;for(let i of e){let e=i.source<i.target?`${i.source}\0${i.target}`:`${i.target}\0${i.source}`,o=r.get(e);o||(o={key:e,source:i.source,target:i.target,lines:new Map},r.set(e,o));let a=i.data.lineOrder;Array.isArray(a)&&(o.authoredOrder=a.map(String));let l=n?.byEdge.get(i)??Jr(i,t);for(let e of l)o.lines.has(e.id)||o.lines.set(e.id,{descriptor:e,edge:i})}return[...r.values()].sort((e,t)=>Rt(e.key,t.key))}(a,t,s),c=new Map(o.map(e=>[e.id,new Set])),u=new Map;if(s)for(let[e,t]of s.byNode)for(let n of t)c.get(e)?.add(n.id),n.color&&u.set(n.id,n.color);let h=Math.max(1,t.lineWidth??("primary"===n?6:"compact"===n?3.5:2)),p=Math.max(0,t.lineGap??("primary"===n?2:"compact"===n?1:.5)),f=new Map,m=[];for(let n of d){let r=l.positions.get(n.source),o=l.positions.get(n.target);if(!r||!o)continue;let a=ti(n,t),s=(a.length-1)/2*(h+p)+h/2;for(let e of[n.source,n.target])f.set(e,Math.max(f.get(e)??0,s));a.forEach((s,d)=>{c.get(n.source)?.add(s.descriptor.id),c.get(n.target)?.add(s.descriptor.id);let f=ni(s.edge,l,t,s.edge.source!==n.source),g=Hr(f?[r,...f,o]:Vr(r,o),(d-(a.length-1)/2)*(h+p)),y=ri(s.edge,s.descriptor),x=Qr(s.descriptor,s.edge,t,e.resolveColor);u.has(s.descriptor.id)||u.set(s.descriptor.id,x),m.push({type:"curved",id:`${n.key}:${s.descriptor.id}`,label:`${s.descriptor.label??s.descriptor.id}: ${s.edge.source} to ${s.edge.target}`,pathD:Ur(g,t.cornerRadius??10),style:{fill:"none",stroke:x,strokeWidth:h,strokeLinecap:"round",opacity:i(y)},datum:y,accessibleDatum:y,accessibility:{label:`${s.descriptor.label??s.descriptor.id}, ${s.edge.source} to ${s.edge.target}`,tableFields:{line:s.descriptor.label??s.descriptor.id,source:s.edge.source,target:s.edge.target}}})})}let g=new Map,y=[],x=[],b=[],w=e=>String(Xr(e,t)||e.id);if("minimap"===n){let n=new Map;for(let e of o){let t=l.positions.get(e.id);if(!t)continue;let r=`${t.x}\0${t.y}`,i=n.get(r);i||(i={x:t.x,y:t.y,nodes:[],lineIds:new Set,bundleRadius:0},n.set(r,i)),i.nodes.push(e);for(let t of c.get(e.id)??[])i.lineIds.add(t);i.bundleRadius=Math.max(i.bundleRadius,f.get(e.id)??0)}let r=[...n.values()].sort((e,t)=>e.x-t.x||e.y-t.y||Rt(e.nodes[0].id,t.nodes[0].id));for(let n of r){let r=ei(n.lineIds,t),o=r.length>1||n.nodes.length>1||n.nodes.some(e=>!0===e.data.interchange||!0===e.data.transfer),a=o?t.interchangeRadius??Math.max(5,n.bundleRadius):t.stationRadius??Math.max(3.5,n.bundleRadius);for(let e of n.nodes)g.set(e.id,a);let l=n.nodes.map(w).join(" / "),s=n.nodes.map(e=>e.id).join("--"),d=1===n.nodes.length?n.nodes[0].data:Mt(e=>{e("id",s),e("label",l),e("stationIds",n.nodes.map(e=>e.id)),e("stations",n.nodes.map(e=>e.data)),e("lineIds",r),e("interchange",o)}),c={label:`${l}${o?", interchange":""}`,tableFields:{station:l,lines:r.join(", ")}};r.length<=1?y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:(r[0]&&u.get(r[0]))??t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:i(d)},datum:d,accessibleDatum:d,accessibility:c,id:s,label:l}):(r.forEach((t,o)=>{let l=-Math.PI/2+o/r.length*Math.PI*2,c=-Math.PI/2+(o+1)/r.length*Math.PI*2,h={type:"arc",cx:n.x,cy:n.y,innerR:0,outerR:a,startAngle:l,endAngle:c,style:{fill:u.get(t)??e.resolveColor(t),stroke:"none",opacity:i(d)},datum:null,id:`${s}:${t}`};y.push(h)}),y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:"transparent",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:i(d)},datum:d,accessibleDatum:d,accessibility:c,id:s,label:l}))}}else for(let r of o){let o=l.positions.get(r.id);if(!o)continue;let a=ei(c.get(r.id)??[],t),s=a.length>1||!0===r.data.interchange||!0===r.data.transfer,d=s?t.interchangeRadius??Math.max("primary"===n?7:5,f.get(r.id)??0):t.stationRadius??("primary"===n?4:2.75);g.set(r.id,d);let u=w(r),h=null!=t.renderStation;if(y.push({type:"circle",cx:o.x,cy:o.y,r:d,style:h?{fill:"transparent",stroke:"transparent"}:{fill:t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:s?"primary"===n?3:2:1.5,opacity:i(r.data)},datum:r.data,accessibleDatum:r.data,accessibility:{label:`${u}${s?", interchange":""}`,tableFields:{station:u,lines:a.join(", ")}},id:r.id,label:u}),t.renderStation){let l={station:r.data,x:o.x,y:o.y,radius:d,lineIds:a,interchange:s,mode:n},c=t.renderStation(l);if(null!=c){if(e.perspective){let[e,n,r,i]=t.stationBounds?.(l)??[d,d,d,d];b.push("ground"===t.chromePlacement?{x:o.x-e,y:o.y-r,width:e+n,height:r+i,z:"top"}:{x:o.x,y:o.y,extent:[e,n,r,i]})}x.push(zr("ground"===t.chromePlacement?jr:Dr,{key:r.id,x:o.x,y:o.y,z:"top"},zr("g",{opacity:i(r.data),style:{pointerEvents:"none"}},c)))}}}let M=x.length>0?zr("g",{className:"transit-diagram-stations"},...x):void 0,v={sceneEdges:m,sceneNodes:y,overlays:M,perspective:"manual",...b.length?{perspectiveBounds:b}:{},labels:oi(o,l.positions,c,g,e.dimensions.plot,"primary"===n?t:{...t,showLabels:!1})};if(x.length>0||"minimap"===n)return v;let k=(e,t)=>({opacity:i(e.datum,t)});return{...v,restyle:k,restyleEdge:k}};import{NetworkPerspectiveBillboard as ai,NetworkPerspectiveGround as li}from"./semiotic-network-placement.module.min.js";function si(e,t,n={}){let r=n.layerAccessor??"x",i=n.rowAccessor??"y",o=1/0,a=-1/0,l=1/0,s=-1/0;for(let t of e){let e=Number(xt(t,r,0)),n=Number(xt(t,i,0));!Number.isFinite(e)||!Number.isFinite(n)||(o=Math.min(o,e),a=Math.max(a,e),l=Math.min(l,n),s=Math.max(s,n))}if(o===1/0&&(o=a=l=s=0),Number.isFinite(n.layerCount)&&n.layerCount>0&&(o=Math.min(o,0),a=Math.max(a,n.layerCount-1)),Number.isFinite(n.maxLayerSize)&&n.maxLayerSize>0){let e=Math.max(0,n.maxLayerSize-1)/2;l=Math.min(l,-e),s=Math.max(s,e)}let d=a-o,c=Math.max(1,s-l),u=(l+s-c)/2,h=d+1,p=s-l+1,f=t.width/Math.max(1,h),m=t.height/Math.max(1,p),g=Math.min(n.nodeWidth??172,Math.max(8,f-(n.minGapX??26))),y=Math.min(n.nodeHeight??54,Math.max(8,m-(n.minGapY??18))),x=n.lod&&"auto"!==n.lod?n.lod:g<16?"dot":g<48?"icon":g<108?"compact":"full";if("dot"===x){let e=Math.min(g,y,11);g=e,y=e}let b=Math.max(1,t.width-g),w=Math.max(1,t.height-y),{x:M,y:v}=t,k=(e,t)=>({x:M+g/2+(d>0?(e-o)/d:.5)*b,y:v+y/2+(t-u)/c*w});return{layerCount:h,maxLayerSize:p,nodeWidth:g,nodeHeight:y,lod:x,project:k,invert:(e,t)=>({layer:d>0?o+(e-M-g/2)/b*d:null,row:(t-v-y/2)/w*c+u}),nodeBounds:e=>{let t=k(Number(xt(e,r,0)),Number(xt(e,i,0)));return{x:t.x-g/2,y:t.y-y/2,width:g,height:y,cx:t.x,cy:t.y}}}}import{NetworkPerspectiveBillboard as di,NetworkPerspectiveGround as ci}from"./semiotic-network-placement.module.min.js";import{jsx as ui,jsxs as hi}from"react/jsx-runtime";function pi(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function fi(e){let t=e.slice().sort((e,t)=>e.x-t.x||e.y-t.y).filter((e,t,n)=>0===t||e.x!==n[t-1].x||e.y!==n[t-1].y);if(t.length<=2)return t;let n=[];for(let e of t){for(;n.length>=2&&pi(n[n.length-2],n[n.length-1],e)<=0;)n.pop();n.push(e)}let r=[];for(let e=t.length-1;e>=0;e--){let n=t[e];for(;r.length>=2&&pi(r[r.length-2],r[r.length-1],n)<=0;)r.pop();r.push(n)}return n.pop(),r.pop(),n.concat(r)}function mi(e,t){if(0===t||e.length<3)return e;let n=e.reduce((t,n,r)=>{let i=e[(r+1)%e.length];return t+n.x*i.y-i.x*n.y},0)>=0?1:-1;return e.map((r,i)=>{let o=e[(i-1+e.length)%e.length],a=e[(i+1)%e.length],l=Math.hypot(r.x-o.x,r.y-o.y)||1,s=Math.hypot(a.x-r.x,a.y-r.y)||1,d=n>0?{x:(r.y-o.y)/l,y:-(r.x-o.x)/l}:{x:-(r.y-o.y)/l,y:(r.x-o.x)/l},c=n>0?{x:(a.y-r.y)/s,y:-(a.x-r.x)/s}:{x:-(a.y-r.y)/s,y:(a.x-r.x)/s},u={x:d.x+c.x,y:d.y+c.y},h=Math.hypot(u.x,u.y);if(h<1e-9)return{x:r.x+c.x*t,y:r.y+c.y*t};let p=u.x/h,f=u.y/h,m=Math.max(1e-6,p*c.x+f*c.y),g=t/m;return{x:r.x+p*g,y:r.y+f*g}})}function gi(e){return String(Math.abs(e)<1e-12?0:e)}function yi(e,t){let n=[];for(let[r,i]of e){let e=mi(fi(i.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding);if(!e.length)continue;let[o,a]=ct(e,e=>e.x),[l,s]=ct(e,e=>e.y);n.push({x:o,y:l,width:a-o,height:s-l});let d=t.label?.(r);d&&n.push({x:o+8,y:l+14,z:0,extent:[0,6.6*d.length,12,3]})}return n}import{jsx as xi,jsxs as bi}from"react/jsx-runtime";function wi(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:String(e.storeName??""),slotIndex:e.slotIndex??t}):[]}function Mi(e,t){return Number.isFinite(e)?gt(e,0,1):t}function vi(e,t){let{w:n,h:r,lod:i}=t,o="icon"===i?Math.min(n,r):Math.min(r-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",l="icon"===i?0:8+o+8,s=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:o,color:a,node:e.node}):function(e,t,n){let r=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return bi("g",{children:[xi("rect",{width:n,height:n,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),xi("text",{x:n/2,y:n/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*n,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:r})]})}(e.semantic,e.partition,o),d="full"===i,c="icon"!==i,u="full"===i&&t.showChips&&e.stores.length>0;return bi("g",{transform:`translate(${e.cx-n/2}, ${e.cy-r/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[xi("g",{transform:`translate(${"icon"===i?(n-o)/2:8}, ${(r-o)/2})`,children:s}),c&&xi("foreignObject",{x:l,y:d?r/2-12:r/2-9,width:Math.max(8,n-l-8),height:18,style:{pointerEvents:"none"},children:xi("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===i?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),d&&xi("text",{x:l,y:r/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),u&&e.stores.map((e,n)=>xi("rect",{x:l+15*n,y:r-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:xi("title",{children:e.storeName})},e.storeName+n))]},e.id)}async function ki(e,t,n={}){let{prepareNetworkAtlas:r}=await(import("./c-XM76UG3P.min.js"));return r(e,t,n)}async function Ii(e){let{prepareMotifBraid:t}=await(import("./c-OBA7XSLH.min.js"));return t(e)}function Si(e,t,n){if(e.length<2)return"";let r=function(e){let t=[e[0]];for(let n=1;n<e.length-1;n++){let r=e[n-1],i=e[n],o=e[n+1],a=B(r,i),l=B(i,o),s=Math.min(8,a/2,l/2);if(0===s)continue;let d=Y(i,r,s/a),c=Y(i,o,s/l);t.push(d);for(let e=1;e<=12;e++){let n=e/12;t.push(Y(Y(d,i,n),Y(i,c,n),n))}}return t.push(e[e.length-1]),t.filter((e,n)=>0===n||B(t[n-1],e)>1e-8)}(e);if(r.length<2)return"";let i=[0];for(let e=1;e<r.length;e++)i.push(i[e-1]+B(r[e-1],r[e]));let o=i[i.length-1],a=Hr(r,1),l=[1,-1].map(e=>r.map((r,l)=>{let s=t+(n-t)*i[l]/o;return Y(r,a[l],e*s/2)}));return[...l[0],...l[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function $i(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let n=t+e/2;return t+=e+3,n})}function Ni(e){let t="";return e.split(">").map((e,n)=>t=n?`${t}>${e}`:e)}var _={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},W={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"},G=e=>{let t=e.config||{},n=e.dimensions.plot,r=t.partitionAccessor??"partition",i=t.semanticAccessor??"semantic",o=t.labelAccessor??"label",a=t.storesAccessor??"stores",l=t.backEdgeAccessor??"isBackEdge",s=t.edgeTypeAccessor??"edgeType",d={..._,...t.partitionColors},c=t.partitionStrokeColors??{},u=t.dotStrokeWidth??1,h={...W,...t.edgeColors},p=t.accentColor??"var(--semiotic-focus, #ffcc33)",f=t.borderColor??"var(--semiotic-border, #555)",m=t.dimOpacity??.14,g=t.edgeOpacity??.5,y=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,w=t.storeChipColor??"var(--semiotic-info, #6a8caf)",M=t.hullGroupAccessor,v=si(e.nodes,n,t),{nodeWidth:k,nodeHeight:I,lod:S}=v,$=t.reachableIds?new Set(t.reachableIds):null,N=t.selectedId??null,A=e.selection,E=null!==$||!0===A?.isActive,C=new Map,O=new Map,T=[],R=null==M?null:new Map,L=[];for(let t of e.nodes){let e=t.id,n=String(xt(t,r,"processor")),l=String(xt(t,i,"processor")),s=String(xt(t,o,e)),h=wi(xt(t,a,[])),g=t.data??t,{cx:y,cy:x}=v.nodeBounds(t);if(!Number.isFinite(y)||!Number.isFinite(x))continue;C.set(e,{cx:y,cy:x});let b=$?$.has(e):null,w=A?.isActive?A.predicate(g):null,E=null!==b?!b:null!==w&&!w;O.set(e,E);let F=null!=N&&e===N,P=E&&!F?m:1,z=Object.prototype.hasOwnProperty.call(d,n)?d[n]:d.unknown,D=Object.prototype.hasOwnProperty.call(c,n)?c[n]:void 0;if("dot"===S){let t={type:"circle",cx:y,cy:x,r:k/2,style:{fill:z,opacity:P,stroke:F?p:D??"transparent",strokeWidth:F?2:D?u:0},datum:g,id:e,label:s};T.push(t)}else{let t={type:"rect",x:y-k/2,y:x-I/2,w:k,h:I,style:{fill:z,opacity:P,stroke:F?p:D??f,strokeWidth:F?3:1},datum:g,id:e,label:s};T.push(t),L.push({id:e,cx:y,cy:x,partition:n,semantic:l,label:s,stores:h,opacity:P,selected:F,node:g})}if(R&&null!=M){let n=xt(t,M,null);if(null!=n){let t=String(n),r=R.get(t)??[];r.push({id:e,x:y-k/2,y:x-I/2,w:k,h:I}),R.set(t,r)}}}let F=[],P=[];for(let r of e.edges){let e="string"==typeof r.source?r.source:r.source.id,i="string"==typeof r.target?r.target:r.target.id,o=C.get(e),a=C.get(i);if(!o||!a)continue;let d,c,u,p=!!(xt(r,l,null)??o.cx>=a.cx),f=String(xt(r,s,"internal")),b=O.get(e)||O.get(i),w=E&&!b,M=b?Math.min(g,1.4*m):w?t.highlightEdgeOpacity??g:g,v=w&&null!=t.highlightEdgeWidth?t.highlightEdgeWidth:p?x:y,$=p?h.back:Object.prototype.hasOwnProperty.call(h,f)?h[f]:h.internal;if(p){let t=Math.min(o.cy,a.cy)-I/2-n.y,r=n.y+n.height-Math.max(o.cy,a.cy)-I/2,l=(o.cy+a.cy)/2>n.y+n.height/2?t>8?-1:r>8?1:0:r>8?1:t>8?-1:0,s=Math.max(48,.28*Math.abs(o.cx-a.cx))+I,h=l<0?Math.max(n.y+1,Math.min(o.cy,a.cy)-I/2-s):l>0?Math.min(n.y+n.height-1,Math.max(o.cy,a.cy)+I/2+s):(o.cy+a.cy)/2,p=e===i,f=p?k/4:0,m=p&&"dot"===S?Math.sqrt((I/2)**2-f**2):I/2,g=o.cx-f,y=o.cy+Math.sign(h-o.cy)*m;c={x:a.cx+f,y:a.cy+Math.sign(h-a.cy)*m},u={x:c.x,y:h},d=`M${g},${y} C${g},${h} ${u.x},${u.y} ${c.x},${c.y}`}else{let e=Math.sign(a.cx-o.cx)||1,t=o.cx+e*k/2;c={x:a.cx-e*k/2,y:a.cy};let n=(t+c.x)/2;u={x:n,y:c.y},d=`M${t},${o.cy} C${n},${o.cy} ${n},${c.y} ${c.x},${c.y}`}!1!==t.showArrowheads&&P.push(Rr(P.length,c,u,$,Math.min(7,k/4,I/3),M));let N={type:"curved",pathD:d,style:{stroke:$,strokeWidth:v,fill:"none",opacity:M,...p?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:r.data??r};F.push(N)}let z="ground"===t.chromePlacement?li:ai,D=0===L.length&&0===P.length?null:bi("g",{children:[P.length>0&&xi(li,{z:"top",children:P}),L.length>0&&xi("g",{className:"lineage-dag-glyphs",children:L.map(e=>xi(z,{x:e.cx,y:e.cy,z:"top",children:vi(e,{w:k,h:I,lod:S,partColors:d,chipColor:w,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel})},e.id))})]}),j=R&&R.size>0?function(e,t){let n=Array.from(e.entries()).sort(([e],[t])=>e<t?-1:e>t?1:0);return ui("g",{className:"lineage-dag-hulls","aria-hidden":"true",style:{pointerEvents:"none"},children:n.map(([e,n])=>{let r=mi(fi(n.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding),i=function(e,t){if(0===e.length)return"";if(e.length<3||0===t)return`${e.map((e,t)=>`${0===t?"M":"L"}${gi(e.x)},${gi(e.y)}`).join(" ")} Z`;let n=e.map((n,r)=>{let i=e[(r-1+e.length)%e.length],o=e[(r+1)%e.length],a=Math.hypot(i.x-n.x,i.y-n.y)||1,l=Math.hypot(o.x-n.x,o.y-n.y)||1,s=Math.min(t,a/2,l/2);return{point:n,incoming:{x:n.x+(i.x-n.x)/a*s,y:n.y+(i.y-n.y)/a*s},outgoing:{x:n.x+(o.x-n.x)/l*s,y:n.y+(o.y-n.y)/l*s}}}),r=n[0].outgoing,i=`M${gi(r.x)},${gi(r.y)}`;for(let e=1;e<n.length;e++){let t=n[e];i+=` L${gi(t.incoming.x)},${gi(t.incoming.y)}`,i+=` Q${gi(t.point.x)},${gi(t.point.y)} ${gi(t.outgoing.x)},${gi(t.outgoing.y)}`}let o=n[0];return i+=` L${gi(o.incoming.x)},${gi(o.incoming.y)}`,i+=` Q${gi(o.point.x)},${gi(o.point.y)} ${gi(o.outgoing.x)},${gi(o.outgoing.y)} Z`,i}(r,t.radius),o=Object.prototype.hasOwnProperty.call(t.colors??{},e)?t.colors?.[e]??t.resolveColor(e):t.resolveColor(e),a=n.every(e=>!0===t.dimById.get(e.id)&&e.id!==t.selectedId),l=ut(r.map(e=>e.x)),s=ut(r.map(e=>e.y)),d=t.label?.(e);return hi("g",{"data-lineage-hull":e,opacity:a?t.dimOpacity:void 0,children:[ui(ci,{children:ui("path",{className:"lineage-dag-hull",d:i,fill:o,fillOpacity:t.fillOpacity,stroke:o,strokeOpacity:t.strokeOpacity,strokeWidth:1,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"none"}})}),d?ui(di,{x:l+8,y:s+14,z:0,children:ui("text",{className:"lineage-dag-hull-label",x:l+8,y:s+14,fill:o,fillOpacity:Math.max(t.strokeOpacity,.7),fontSize:11,fontWeight:600,style:{pointerEvents:"none"},children:d})}):null]},e)})})}(R,{colors:t.hullColors,padding:null==t.hullPadding?16:Ct(t.hullPadding),radius:null==t.hullRadius?12:Ct(t.hullRadius),fillOpacity:Mi(t.hullFillOpacity,.08),strokeOpacity:Mi(t.hullStrokeOpacity,.4),label:t.hullLabel,resolveColor:e.resolveColor,dimById:O,selectedId:N,dimOpacity:m}):null,G=e.perspective?[...L.map(e=>"ground"===t.chromePlacement?{x:e.cx-k/2,y:e.cy-I/2,width:k,height:I,z:"top"}:{x:e.cx,y:e.cy,extent:[k/2,k/2,I/2,I/2]}),...R?yi(R,{padding:null==t.hullPadding?16:Ct(t.hullPadding),label:t.hullLabel}):[]]:void 0,Y=j?{sceneNodes:T,sceneEdges:F,backgrounds:j,overlays:D,perspective:"manual"}:{sceneNodes:T,sceneEdges:F,overlays:D,perspective:"manual"};return G?{...Y,perspectiveBounds:G}:Y},Y=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}),B=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),q={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"}]},V=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,H=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),U=e=>{let t=e.config.braid,n=e.dimensions.plot,r=t.atlas.spec.comparison?.partitions??[...new Set(t.groups.map(e=>e.partition))],i=t.groups.filter(e=>r.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],l=[];if(0===i.length)return{sceneNodes:a,sceneEdges:o,labels:l};let s=new Set(i.map(e=>e.signature)),d=[...t.signatureOrder.filter(e=>s.delete(e)),...s],c=new Map(d.map((e,t)=>[e,t])),u=[...i].sort((e,t)=>c.get(e.signature)-c.get(t.signature)),h=r.map(e=>u.filter(t=>t.partition===e)),p=function(e){let t=new Map;for(let n of e){let e=Ni(n.signature);n.nodePath.forEach((r,i)=>{let o=e[i],a=t.get(o);a||(a={id:o,state:r,depth:i+1,signatures:new Set},t.set(o,a)),a.signatures.add(n.signature)})}return[...t.values()]}(u),f=ht(p.map(e=>e.depth)),m=i.map(e=>ht(e.stepEntityCounts??[e.entityCount])),g=ht(m),y=e=>e<=0?0:Math.max(1,10*e/g),x=new Map(i.map((e,t)=>[e.id,y(m[t])])),b=n.height/r.length,{semantic:w}=e.theme,M=(e,t,n,r={})=>l.push({x:e,y:t,text:n,fill:w.text??"#333",fontSize:10,anchor:"middle",...r}),v={sourceRevision:t.atlas.provenance.sourceRevision,analysisRevision:t.atlas.analysisRevision,relationScopeId:"directed-admitted"},k=new Map(p.map(e=>{let t=h.map(t=>t.reduce((t,n)=>t+(e.signatures.has(n.signature)?x.get(n.id)+3:0),5));return[e.id,ht(t,24)]})),I=ht([...k.values()],24),S=Math.min(n.width/4,I/2+16),$=(n.width-2*S)/Math.max(f-1,1),N=e=>n.x+S+(e-1)*$,A=48+I/2,E=22+I/2,C=(e,t)=>e+A+(c.get(t)+.5)*Math.max(0,b-A-E)/d.length,O=(t,n,r,i,a)=>{let l=V(n,i),s=V(n,a),d=y(l),c=y(s);if(0===d&&0===c)return;let u=d!==c,h=e.resolveColor(n.signature);o.push({type:"curved",id:r,pathD:u?Si(t,d,c):Ur(t,8),style:{fill:u?h:"none",fillOpacity:1,stroke:u?"none":h,strokeWidth:u?0:d},datum:{...v,id:r,kind:"braid-track",nodeId:n.nodePath[a],fromNodeId:n.nodePath[i],groupId:n.id,signature:n.signature,partition:n.partition,entityCount:n.entityCount,fromStep:i,toStep:a,fromCount:l,toCount:s,falseRoot:!1},accessibleDatum:{journey:n.nodePath.join(" → "),partition:n.partition??"all",fromStep:i+1,toStep:a+1,fromCount:l,toCount:s}})};return r.forEach((e,t)=>{let r=n.y+t*b,i=h[t];if(e&&M(n.x+8,r+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===i.length)return;for(let e=1;e<=f;e++)M(N(e),r+34,`Step ${e}`);let o=new Map;for(let t of p){let n=i.filter(e=>t.signatures.has(e.signature));if(0===n.length)continue;let l=N(t.depth),s=Ot([...t.signatures].map(e=>C(r,e))),d=$i(n.map(e=>x.get(e.id)));o.set(t.id,new Map(n.map((e,t)=>[e.id,{x:l,y:s+d[t],offset:d[t]}])));let c=k.get(t.id),u={state:t.state,step:t.depth,partition:e??"all"},h=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:h,cx:l,cy:s,size:c,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:q,accent:w.border??"#888",style:{fill:w.surface??"#fff"},datum:{...v,id:h,nodeId:t.state,kind:"braid-step",prefixId:t.id,...u},accessibleDatum:u}),M(l,s+c/2+12,t.state,{anchorPoint:[l,s]})}for(let t of i){let n=Ni(t.signature);for(let r=1;r<n.length;r++){let i=o.get(n[r-1]).get(t.id),a=o.get(n[r]).get(t.id),l=(i.x+a.x)/2-Math.sign(a.y-i.y)*a.offset,s=Math.abs(i.y-a.y)<1e-8?[i,a]:[i,{x:l,y:i.y},{x:l,y:a.y},a];O(s,t,`step:${e??"all"}:${n[r]}:${t.id}`,r-1,r)}}}),{sceneNodes:a,sceneEdges:o,labels:l,restyle:H,restyleEdge:H}};import{NetworkPerspectiveBillboard as Ai,NetworkPerspectiveGround as Ei}from"./semiotic-network-placement.module.min.js";import{jsx as Ci,jsxs as Oi}from"react/jsx-runtime";function Ti(e,t){return e.length>t?`${e.slice(0,Math.max(1,t-1))}…`:e}function Ri(e,t,n,r,i,o,a,l){let s=t-r/2,d=n-i/2,c={fill:o,stroke:a,strokeWidth:l};switch(e){case"diamond":return Ci("polygon",{points:`${t},${d} ${t+r/2},${n} ${t},${n+i/2} ${s},${n}`,...c});case"circle":return Ci("circle",{cx:t,cy:n,r:Math.min(r,i)/2,...c});case"stadium":case"round":return Ci("rect",{x:s,y:d,width:r,height:i,rx:"stadium"===e?i/2:8,ry:"stadium"===e?i/2:8,...c});case"hexagon":{let e=Math.min(.18*r,16);return Ci("polygon",{points:`${s+e},${d} ${t+r/2-e},${d} ${t+r/2},${n} ${t+r/2-e},${n+i/2} ${s+e},${n+i/2} ${s},${n}`,...c})}case"cylinder":{let e=Math.min(.16*i,8),t=`M${s},${d+e} a${r/2},${e} 0 0 1 ${r},0`;return Oi("g",{children:[Ci("path",{d:`M${s},${d+e} a${r/2},${e} 0 0 0 ${r},0 v${i-2*e} a${r/2},${e} 0 0 1 ${-r},0 z`,...c}),Ci("path",{d:t,fill:"none",stroke:a,strokeWidth:l})]})}case"subroutine":{let e=Math.min(8,.08*r);return Oi("g",{children:[Ci("rect",{x:s,y:d,width:r,height:i,rx:3,...c}),Ci("line",{x1:s+e,y1:d,x2:s+e,y2:d+i,stroke:a,strokeWidth:l}),Ci("line",{x1:s+r-e,y1:d,x2:s+r-e,y2:d+i,stroke:a,strokeWidth:l})]})}default:return Ci("rect",{x:s,y:d,width:r,height:i,rx:4,...c})}}function Li(e,t,n,r,i){let o=Math.max(0,Math.min(i,n/2,r/2)),a=e+n,l=t+r;return`M${e+o},${t} H${a-o} A${o},${o} 0 0 1 ${a},${t+o} V${l-o} A${o},${o} 0 0 1 ${a-o},${l} H${e+o} A${o},${o} 0 0 1 ${e},${l-o} V${t+o} A${o},${o} 0 0 1 ${e+o},${t} Z`}function Fi(e,t,n,r,i){let o=t-r/2,a=n-i/2;switch(e){case"diamond":return`M${t},${a} L${t+r/2},${n} L${t},${n+i/2} L${o},${n} Z`;case"circle":{let e=Math.min(r,i)/2;return`M${t-e},${n} A${e},${e} 0 1 1 ${t+e},${n} A${e},${e} 0 1 1 ${t-e},${n} Z`}case"stadium":case"round":return Li(o,a,r,i,"stadium"===e?i/2:8);case"hexagon":{let e=Math.min(.18*r,16);return`M${o+e},${a} L${t+r/2-e},${a} L${t+r/2},${n} L${t+r/2-e},${n+i/2} L${o+e},${n+i/2} L${o},${n} Z`}case"cylinder":{let e=Math.min(.16*i,8);return`M${o},${a+e} A${r/2},${e} 0 0 1 ${o+r},${a+e} V${a+i-e} A${r/2},${e} 0 0 1 ${o},${a+i-e} Z`}case"subroutine":return Li(o,a,r,i,3);default:return Li(o,a,r,i,4)}}function Pi(e,t,n,r,i,o){let a=t-r/2,l=n-i/2;if("cylinder"===e){let e=Math.min(.16*i,8);return Ci("path",{d:`M${a},${l+e} a${r/2},${e} 0 0 0 ${r},0`,fill:"none",stroke:o,strokeWidth:1.5})}if("subroutine"===e){let e=Math.min(8,.08*r);return Ci("path",{d:`M${a+e},${l} V${l+i} M${a+r-e},${l} V${l+i}`,fill:"none",stroke:o,strokeWidth:1.5})}return null}function zi(e,t){let n=ot({nodes:e.map(e=>({id:e})),edges:e.flatMap(e=>[...t.get(e)].map(t=>({source:e,target:t})))}),r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));let i=n.length,o=Array.from({length:i},()=>new Set),a=Array.from({length:i},()=>new Set);for(let n of e){let e=r.get(n);for(let i of t.get(n)){let t=r.get(i);e!==t&&(a[e].add(t),o[t].add(e))}}let l=a.map(e=>e.size),s=l.flatMap((e,t)=>0===e?[t]:[]),d=s.length,c=o.filter(e=>0===e.size).length,u=new Int32Array(i),h=0;for(let e=0;e<s.length;e++){let t=s[e];for(let e of o[t])u[e]=Math.max(u[e],u[t]+1),h=Math.max(h,u[e]),0===--l[e]&&s.push(e)}return{sinkCount:d,sourceCount:c,layerCount:h+1,layer:new Map(e.map(e=>[e,h-u[r.get(e)]]))}}function Di(e,t=2166136261){let n=t;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return n>>>0}function ji(e){return Di(e)/4294967295}var X={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"},K=e=>{let t=e.config||{},n=e.dimensions.plot,r=t.direction??"TD",i="LR"===r||"RL"===r,o="BT"===r||"RL"===r,a=t.layerAccessor??"layer",l=t.rowAccessor??"row",s=t.labelAccessor??"label",d=t.shapeAccessor??"shape",c=t.edgeLabelAccessor??"label",u=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",p=t.textColor??"var(--semiotic-text, #e6e6e6)",f=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",m=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};let g=new Map,y=0;for(let t of e.nodes){let e=Math.round(Number(xt(t,a,0)));y=Math.max(y,e);let n=g.get(e)||[];n.push(t),g.set(e,n)}let x=y+1,b=1;for(let e of g.values())e.sort((e,t)=>Number(xt(e,l,0))-Number(xt(t,l,0))),b=Math.max(b,e.length);let w=i?n.width:n.height,M=i?n.height:n.width,v=w/x,k=M/(b+1),I=Math.max(44,Math.min(t.nodeWidth??150,i?v-36:.92*k)),S=Math.max(26,Math.min(t.nodeHeight??46,i?.7*k:.5*v)),$=(i?I:S)/2+6,N=Math.max(1,w-2*$),A=e=>{let t=x>1?(o?x-1-e:e)/(x-1)*N:N/2;return(i?n.x:n.y)+$+t},E=(e,t)=>(i?n.y:n.x)+(e+1)/(t+1)*M,C=new Map,O=null!=e.perspective,T=[],R=[],L=[],F=[];for(let[e,t]of g)t.forEach((n,r)=>{let o=A(e),a=E(r,t.length),l=i?o:a,c=i?a:o,f=String(xt(n,d,"rect")),g=String(xt(n,s,n.id));C.set(n.id,{cx:l,cy:c,shape:f});let y={id:n.id,name:g,type:X[f]??"process",shape:f},x=Ti(g,Math.max(4,Math.floor((I-12)/7)));if(O){let e="diamond"===f?m:h;T.push({type:"rect",x:l-I/2,y:c-S/2,w:I,h:S,style:{fill:u,stroke:e,strokeWidth:1.5},_hitPath:{pathD:Fi(f,l,c,I,S),transform:[0,0,1,1],fill:!0,strokeWidth:0},datum:y,id:n.id,label:g}),L.push({x:l,y:c,text:x,anchor:"middle",baseline:"middle",fontSize:13,fill:p,anchorPoint:[l,c]});let t=Pi(f,l,c,I,S,e);return void(t&&F.push(Ci("g",{children:t},`n-${n.id}`)))}T.push({type:"rect",x:l-I/2,y:c-S/2,w:I,h:S,style:{fill:"transparent",stroke:"transparent"},datum:y,id:n.id,label:g}),F.push(Oi("g",{children:[Ri(f,l,c,I,S,u,"diamond"===f?m:h,1.5),Ci("text",{x:l,y:c,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:p,style:{pointerEvents:"none"},children:x})]},`n-${n.id}`))});let P=[];e.edges.forEach((e,t)=>{let n="string"==typeof e.source?e.source:e.source.id,r="string"==typeof e.target?e.target:e.target.id,o=C.get(n),a=C.get(r);if(!o||!a)return;let l=i?o.cx+I/2:o.cx,s=i?o.cy:o.cy+S/2,d=i?a.cx-I/2:a.cx,u=i?a.cy:a.cy-S/2,m=i?`M${l},${s} C${(l+d)/2},${s} ${(l+d)/2},${u} ${d},${u}`:`M${l},${s} C${l},${(s+u)/2} ${d},${(s+u)/2} ${d},${u}`,g=Math.atan2(u-s,d-l),y=d-9*Math.cos(g),x=u-9*Math.sin(g),b=4.5*-Math.sin(g),w=4.5*Math.cos(g),M=`${d},${u} ${y+b},${x+w} ${y-b},${x-w}`,v=xt(e,c,void 0),k=(l+d)/2,$=(s+u)/2;O&&R.push({type:"curved",pathD:m,style:{stroke:f,strokeWidth:1.4,fill:"none"},datum:e.data??e}),P.push(Oi("g",{children:[!O&&Ci("path",{d:m,fill:"none",stroke:f,strokeWidth:1.4}),Ci(Ei,{z:"top",children:Ci("polygon",{points:M,fill:f})}),"string"==typeof v&&v.length>0&&Ci(Ai,{x:k,y:$,children:Oi("g",{children:[Ci("rect",{x:k-6.5*v.length/2-4,y:$-9,width:6.5*v.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),Ci("text",{x:k,y:$,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:p,style:{pointerEvents:"none"},children:v})]})})]},`e-${t}`))});let z=Oi("g",{className:"mermaid-dag",children:[P,O?Ci(Ei,{z:"top",children:F}):F]});return O?{sceneNodes:T,sceneEdges:R,labels:L,overlays:z,perspective:"manual"}:{sceneNodes:T,overlays:z}};import{NetworkPerspectiveBillboard as _i,NetworkPerspectiveGround as Wi}from"./semiotic-network-placement.module.min.js";import{jsx as Gi,jsxs as Yi}from"react/jsx-runtime";function Bi(e){return Gi("rect",{className:e.className,x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height),rx:e.radius??10,ry:e.radius??10,fill:e.fill??"none",stroke:e.stroke,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray,opacity:e.opacity??.6,style:{pointerEvents:"none"}},e.keyId)}function qi(e,t=0){let n=1/0,r=1/0,i=-1/0,o=-1/0;for(let t of e){let e=t.r??0;t.x-e<n&&(n=t.x-e),t.x+e>i&&(i=t.x+e),t.y-e<r&&(r=t.y-e),t.y+e>o&&(o=t.y+e)}return Number.isFinite(n)?{x:n-t,y:r-t,width:i-n+2*t,height:o-r+2*t}:null}function Vi(e,t=0){if(!e.length)return null;let n="number"==typeof t?t:t.x??0,r="number"==typeof t?t:t.y??0,i=1/0,o=1/0,a=-1/0,l=-1/0;for(let t of e){if(!(Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)))continue;let e=Math.max(0,t.width),n=Math.max(0,t.height);t.x<i&&(i=t.x),t.y<o&&(o=t.y),t.x+e>a&&(a=t.x+e),t.y+n>l&&(l=t.y+n)}return Number.isFinite(i)?{x:i-n,y:o-r,width:a-i+2*n,height:l-o+2*r}:null}function Hi(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:Gi("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)}function Ui(e){let t=e.spacing??8,n=e.color??"currentColor";return{def:Gi("pattern",{id:e.id,width:t,height:t,patternUnits:"userSpaceOnUse",patternTransform:`rotate(${e.angle??45})`,children:Gi("line",{x1:0,y1:0,x2:0,y2:t,stroke:n,strokeWidth:e.strokeWidth??1,opacity:e.opacity??.5})},e.id),fill:`url(#${e.id})`}}function Xi(e){let t=e.orient??"bottom",n="bottom"===t||"top"===t,r=e.offset??0,i=e.tickLength??6,o=e.gridLength??0,a=e.labelGap??4,l=e.fontSize??11,s=e.color??"var(--semiotic-text-secondary, #888)",d=e.gridColor??s,c=e.format??(e=>String(e)),u="top"===t||"left"===t?-1:1,h=e.ticks.length-1,p=e.ticks.map((p,f)=>{let m,g=e.scale(p),y=r+u*i,x=r-u*o,b=y+u*a;m=e.labelAnchor?e.labelAnchor:n?e.edgeAnchor&&0===f?"start":e.edgeAnchor&&f===h?"end":"middle":"left"===t?"end":"start";let w=n?"top"===t?"auto":"hanging":"middle",M=n?{x:g,y:b}:{x:b,y:g};return Yi("g",{children:[(i>0||o>0)&&Gi("line",{...n?{x1:g,x2:g,y1:y,y2:x}:{x1:y,x2:x,y1:g,y2:g},stroke:o>0?d:s,strokeWidth:1,strokeDasharray:o>0?e.gridDasharray:void 0,opacity:o>0?.7:1}),Gi("text",{x:M.x,y:M.y,textAnchor:m,dominantBaseline:w,fontSize:l,fontWeight:e.fontWeight,fill:s,children:c(p)})]},`tick-${p}-${f}`)});return Gi("g",{className:e.className,style:{pointerEvents:"none"},children:p},e.keyId)}function Ki(e){let t,n=e.stroke??"var(--semiotic-text, #f4f4f8)",r=e.strokeWidth??1,i=e.markRadius??0,o=e.labelX-e.markX,a=e.labelY-e.markY,l=Math.hypot(o,a)||1,s=e.markX+o/l*i,d=e.markY+a/l*i;return t="elbow"===e.connector?`M${s},${d} L${s},${e.labelY} L${e.labelX},${e.labelY}`:"curve"===e.connector?`M${s},${d} Q${(s+e.labelX)/2},${d} ${e.labelX},${e.labelY}`:`M${s},${d} L${e.labelX},${e.labelY}`,Yi("g",{className:e.className,style:{pointerEvents:"none"},children:[i>0&&Gi("circle",{cx:e.markX,cy:e.markY,r:i,fill:"none",stroke:n,strokeWidth:r}),Gi("path",{d:t,fill:"none",stroke:n,strokeWidth:r}),Gi("text",{x:e.labelX,y:e.labelY,textAnchor:e.labelAnchor??"middle",dominantBaseline:e.labelBaseline??"hanging",fontSize:e.fontSize??11,fontWeight:e.fontWeight,fill:e.color??n,children:e.label})]},e.keyId)}import{jsx as Ji,jsxs as Zi}from"react/jsx-runtime";function Qi(e,t,n){return`M${e},${t-n} L${e+n},${t} L${e},${t+n} L${e-n},${t} Z`}function eo(e,t,n={}){let r=n.fingerprintRounds??3,i=[],o=new Set;for(let t of e)null==t.id||o.has(t.id)||(o.add(t.id),i.push(t.id));let{components:a}=lo(i,t,r),l=a.map(e=>({ids:[...e.ids],nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:oo(e)})),s=new Map;for(let e of l){let t=s.get(e.motif);t?t.count+=1:s.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:l,motifs:[...s.values()].sort((e,t)=>t.count-e.count),directedCount:l.filter(e=>e.directed).length,branchingCount:l.filter(e=>!e.directed).length}}function to(e){return Di(e).toString(36)}function no(e){return"string"==typeof e?e:e?.id}function ro(e,t,n,r,i){let o=new Set(e),a=new Map;for(let r of e){let e=0,i=0;for(let e of t.get(r)??[])o.has(e)&&(i+=1);for(let t of n.get(r)??[])o.has(t)&&(e+=1);a.set(r,`${e}:${i}`)}for(let r=0;r<i;r+=1){let r=new Map;for(let i of e){let e=[];for(let n of t.get(i)??[])o.has(n)&&e.push(a.get(n));let l=[];for(let e of n.get(i)??[])o.has(e)&&l.push(a.get(e));e.sort(),l.sort(),r.set(i,to(`${a.get(i)}>${e.join(",")}<${l.join(",")}`))}a=r}let l=e.map(e=>a.get(e)).sort();return to(`${e.length}#${r}#${l.join(";")}`)}function io(e,t,n,r,i){let{layer:o,layerCount:a}=e,l=Array.from({length:a},()=>[]);for(let t of e.ids)l[o.get(t)].push(t);let s=.14*Math.min(r.width,r.height),d=Math.max(1,r.width-2*s),c=Math.max(1,r.height-2*s),u=new Map,h=new Set(e.ids);for(let e=0;e<a;e+=1){let t=l[e];e>0&&(t=[...t].sort((e,t)=>p(e)-p(t)));let n=t.length,i=r.y+s+(1===a?.5:e/(a-1))*c;t.forEach((e,t)=>{let o=r.x+s+(1===n?.5:t/(n-1))*d;u.set(e,{x:o,y:i})})}function p(e){let t=0,i=0;for(let r of n.get(e)??[]){let e=u.get(r);h.has(r)&&e&&(t+=e.x,i+=1)}return i>0?t/i:r.x+d/2}let f=l.reduce((e,t)=>Math.max(e,t.length),1),m=gt(Math.min(i,d/(2.4*f),c/(2.4*a)),1.4,i),g=e.ids.map(e=>{let t=u.get(e);return{id:e,cx:t.x,cy:t.y,r:m,datum:At({id:e}),category:""}}),y=[];for(let n of e.ids){let e=u.get(n);for(let r of t.get(n)??[]){if(!h.has(r))continue;let t=u.get(r);y.push({source:n,target:r,x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:g,edges:y}}function oo(e){let{nodeCount:t,edgeCount:n,sinkCount:r,sourceCount:i}=e;return 1===t?"isolate":2===t&&1===n?"pair":1===i&&1===r&&n===t-1?`chain of ${t}`:e.directed&&1===i&&n>t-1?"diamond / mesh":e.directed?`converging (${t})`:`branching → ${r}`}function ao(e,t,n,r,i){let o=new Set,a=[];for(let l of e){if(o.has(l))continue;let e=[l];o.add(l);let s=[];for(;e.length;){let t=e.pop();s.push(t);for(let n of r.get(t)??[])o.has(n)||(o.add(n),e.push(n))}s.sort();let d=zi(s,t),{sinkCount:c,sourceCount:u}=d,h=0;for(let e of s)h+=t.get(e).size;a.push({...d,ids:s,nodeCount:s.length,edgeCount:h,sinkCount:c,sourceCount:u,directed:1===c,motif:ro(s,t,n,h,i)})}return a}function lo(e,t,n){let r=[...e].sort(),i=t.map(e=>[e.source,e.target]).sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:e[1]<t[1]?-1:e[1]>t[1]?1:0),o=JSON.stringify([n,r,i]);return J.getOrCompute(o,()=>{let{outAdj:e,inAdj:t,undirected:a}=function(e,t){let n=new Set(e),r=new Map,i=new Map,o=new Map;for(let t of e)r.set(t,new Set),i.set(t,new Set),o.set(t,new Set);for(let e of t){let t=e.source,a=e.target;!n.has(t)||!n.has(a)||t===a||r.get(t).has(a)||(r.get(t).add(a),i.get(a).add(t),o.get(t).add(a),o.get(a).add(t))}return{outAdj:r,inAdj:i,undirected:o}}(r,i.map(([e,t])=>({source:e,target:t})));return{key:o,outAdj:e,inAdj:t,components:ao(r,e,t,a,n)}})}function so(e,t,n){return e?io(e,t.outAdj,t.inAdj,n,3):null}var J=/*#__PURE__*/new e(8),Z=/*#__PURE__*/new e(8),Q=e=>{let t=e.config||{},n=e.dimensions.plot;if(!e.nodes.length||n.width<=0||n.height<=0)return{sceneNodes:[]};let r=t.sourceAccessor??"source",i=t.targetAccessor??"target",o=t.labelAccessor??"label",a=t.categoryAccessor??"category",l=t.nodeRadius??4,s=t.cellGap??16,d=t.bandGap??22,c=t.headerHeight??34,u=t.minCellForFull??38,h=t.maxCellSize??120,p=t.minCellSize??12,f=t.fingerprintRounds??3,m=!1!==t.groupByMotif,g=t.sort??"frequency",y=new Map,x=new Map,b=[];for(let t of e.nodes){let e=t.id;null==e||y.has(e)||(b.push(e),y.set(e,t.data??t),x.set(e,String(xt(t,a,""))))}let w=[];for(let t of e.edges){let e=no(t.source??xt(t,r,void 0)),n=no(t.target??xt(t,i,void 0));null==e||null==n||w.push({source:e,target:n})}let{outAdj:M,inAdj:v,components:k,key:I}=lo(b,w,f),S=new Map;if(m)for(let e of k){let t=S.get(e.motif);t?t.push(e):S.set(e.motif,[e])}else S.set("all",[...k].sort((e,t)=>t.nodeCount-e.nodeCount));let $=[...S.entries()];$.sort((e,t)=>"size"===g?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===g?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);let N=It([n.x,n.y,n.width,n.height,s,d,c,u,h,p,f,m,g,l,$.map(([e,t])=>e+":"+t.length).join(","),I]),A=Z.getOrCompute(N,()=>function(e,t){let{plot:n}=t,r=n.width,i=(()=>{for(let i=Math.min(t.maxCellSize,r);i>=Math.max(1,t.minCellSize);i-=2){let o=Math.max(1,Math.floor((r+t.cellGap)/(i+t.cellGap))),a=0;for(let[,n]of e){let e=Math.ceil(n.length/o);a+=t.headerHeight+e*(i+t.cellGap)+t.bandGap}if(a<=n.height)return{cell:i,cols:o}}return null})();if(!i){let t=e.flatMap(([,e])=>e),r=Math.max(1,Math.ceil(Math.sqrt(t.length*n.width/n.height))),i=Math.ceil(t.length/r),o=n.width/r,a=n.height/i;return{bands:[],cells:t.map((e,t)=>({component:e,lod:"glyph",cx:n.x+(t%r+.5)*o,cy:n.y+(Math.floor(t/r)+.5)*a,glyphR:Math.min(o,a)*(e.directed?.36:.28),nodes:[],edges:[]}))}}let{cell:o,cols:a}=i,l=[],s=[],d=n.y;for(let[i,c]of e){let e=Math.ceil(c.length/a),u=d,h=u+t.headerHeight,p=o>=t.minCellForFull;c.forEach((e,r)=>{let i=r%a,s=Math.floor(r/a),d=n.x+i*(o+t.cellGap),c=h+s*(o+t.cellGap),u={x:d,y:c,width:o,height:o};if(p){let n=io(e,t.outAdj,t.inAdj,u,t.nodeRadius);l.push({component:e,lod:"full",cx:d+o/2,cy:c+o/2,glyphR:0,nodes:n.nodes,edges:n.edges})}else l.push({component:e,lod:"glyph",cx:d+o/2,cy:c+o/2,glyphR:Math.max(2.5,.36*o),nodes:[],edges:[]})});let f=so(c[0],t,{x:n.x,y:u+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});s.push({motif:i,descriptor:oo(c[0]),count:c.length,directed:c[0].directed,x:n.x,y:u,width:r,height:t.headerHeight+e*(o+t.cellGap),contentWidth:Math.min(c.length,a)*(o+t.cellGap)-t.cellGap,exemplar:f}),d=h+e*(o+t.cellGap)+t.bandGap}return{cells:l,bands:s}}($,{plot:n,cellGap:s,bandGap:d,headerHeight:c,minCellForFull:u,maxCellSize:h,minCellSize:p,nodeRadius:l,outAdj:M,inAdj:v})),E=e.theme.semantic||{},C=t.convergeColor??E.info??"#4c78a8",O=t.branchColor??E.warning??"#e8853a",T=t.edgeColor??E.border??"#9aa0aa",R=t.colorMode??"directedness",L={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},F=t=>"motif"===R?e.resolveColor(t.motif):"category"===R||t.directed?C:O,P=[],z=[];for(let t of A.cells){let n=t.component,r=F(n);if("full"===t.lod){for(let e of t.edges){let t={type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:T,strokeWidth:1,opacity:.5*Math.max(kt(y.get(e.source),L),kt(y.get(e.target),L))},datum:null};z.push(t)}for(let n of t.nodes){let t=y.get(n.id),i=x.get(n.id),a="category"===R&&i?e.resolveColor(i):r,l={type:"symbol",cx:n.cx,cy:n.cy,size:Math.PI*n.r*n.r,symbolType:"circle",style:{fill:a,opacity:kt(t,L)},datum:t,id:n.id,label:String(xt(t,o,n.id))};P.push(l)}}else{let e=At({id:`component-${JSON.stringify(n.ids)}`,motif:n.motif,shape:oo(n),nodes:n.nodeCount,edges:n.edgeCount,sinks:n.sinkCount,sources:n.sourceCount,directedness:n.directed?"converging":"branching"}),i={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:n.directed?"circle":"diamond",style:{fill:r,opacity:n.ids.some(e=>1===kt(y.get(e),L))?1:.14,stroke:T,strokeWidth:.75},datum:e,id:String(e.id),label:oo(n)};P.push(i)}}let D=!1!==t.showExemplars,j=!1!==t.showBandLabels,_=function(e,t,n,r){if(!t)return{bands:e};let i=e=>r?(n?48:4)+Math.max(13*e.descriptor.length*.6,11*`×${e.count} · ${e.directed?"converges to 1 sink":"branches to ≥2 sinks"}`.length*.56):n?44:0,o=e.map(e=>({...e,width:Math.min(e.width,Math.max(e.contentWidth??e.width,i(e)))}));return{bands:o,bounds:o.flatMap(e=>[{x:e.x-6,y:e.y-4,width:e.width+12,height:e.height+4},{x:e.x,y:e.y,z:0,extent:[0,i(e),2,32]}])}}(A.bands,!!e.perspective,D,j),W=function(e,t){let n=[];for(let r of e){let e=r.directed?t.convergeColor:t.branchColor,i=[];if(n.push(Ji(Wi,{children:Bi({keyId:`band-${r.motif}`,x:r.x-6,y:r.y-4,width:r.width+12,height:r.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})},`ground-${r.motif}`)),t.showExemplars&&r.exemplar){let n=r.exemplar;i.push(Zi("g",{style:{pointerEvents:"none"},children:[n.edges.map((e,n)=>Ji("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},`exe-${n}`)),n.nodes.map(t=>Ji("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},`exn-${t.id}`))]},`ex-${r.motif}`))}if(t.showBandLabels){let e=r.x+(t.showExemplars?48:4);i.push(Ji("text",{x:e,y:r.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:r.descriptor},`bl-${r.motif}`)),i.push(Ji("text",{x:e,y:r.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${r.count} · ${r.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},`bc-${r.motif}`))}i.length&&n.push(Ji(_i,{x:r.x,y:r.y,z:0,children:i},`header-${r.motif}`))}if(t.showLegend){let e=t.plot.x+t.plot.width-168,r=t.plot.y-2;n.push(Zi("g",{style:{pointerEvents:"none"},children:[Ji("circle",{cx:e,cy:r,r:5,fill:t.convergeColor}),Ji("text",{x:e+10,y:r+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),Ji("path",{d:Qi(e,r+18,5),fill:t.branchColor}),Ji("text",{x:e+10,y:r+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}return Ji("g",{className:"net-ensemble-overlays",children:n})}(_.bands,{convergeColor:C,branchColor:O,edgeColor:T,plot:n,showBandLabels:j,showExemplars:D,showLegend:!1!==t.showLegend&&"directedness"===R,textColor:E.text??"var(--semiotic-text, #1a1a1a)",subText:E.textSecondary??"var(--semiotic-text-secondary, #888)"});return{sceneNodes:P,sceneEdges:z,overlays:W,perspective:"manual",..._.bounds?{perspectiveBounds:_.bounds}:{}}};import*as co from"react";import{NetworkPerspectiveGround as uo}from"./semiotic-network-placement.module.min.js";function ho(e){return bt(e)??e}function po(e){return"string"==typeof e?e:e.id}function fo(e,t){let n=Number(e);return Number.isFinite(n)&&n>0?n:t}function mo(e){return String(Math.round(100*e)/100)}function go(e,t){if(e.length<2)return"";let n=`M${mo(e[0][0])},${mo(e[0][1])}`;for(let r=1;r<e.length-1;r+=1){let i=e[r-1],o=e[r],a=e[r+1],l=Math.hypot(o[0]-i[0],o[1]-i[1]),s=Math.hypot(a[0]-o[0],a[1]-o[1]),d=Math.min(t,l/2,s/2);if(d<=0){n+=`L${mo(o[0])},${mo(o[1])}`;continue}let c=[(o[0]-i[0])/l,(o[1]-i[1])/l],u=[(a[0]-o[0])/s,(a[1]-o[1])/s],h=[o[0]-c[0]*d,o[1]-c[1]*d],p=[o[0]+u[0]*d,o[1]+u[1]*d];n+=`L${mo(h[0])},${mo(h[1])}Q${mo(o[0])},${mo(o[1])} ${mo(p[0])},${mo(p[1])}`}let r=e[e.length-1];return`${n}L${mo(r[0])},${mo(r[1])}`}function yo(e,t,n,r,i=.92*r){let o=Math.cos(n),a=Math.sin(n),l=-a,s=[e+o*r*.56,t+a*r*.56],d=e-o*r*.44,c=t-a*r*.44,u=[d+l*i*.5,c+o*i*.5],h=[d-l*i*.5,c-o*i*.5];return`M${mo(s[0])},${mo(s[1])}L${mo(u[0])},${mo(u[1])}L${mo(h[0])},${mo(h[1])}Z`}function xo(e,t){return e.length<=t?e:`${e.slice(0,Math.max(1,t-1))}…`}function bo(e,t){return`${t}\0${e}`}function wo(e,t){return Math.max(1,e-2*Math.max(0,t.portPadding??4))}function Mo(e,t,n){if(e<=1)return 0;let r=Math.max(0,n.flowGap??.75),i=wo(t,n),o=Math.min(.1,i);return Math.min(r,Math.max(0,(i-o)/(e-1)))}function vo(e,t,n){let r="function"==typeof t?t(e):xt(e,t,n);return null==r||""===r?n:String(r)}function ko(e,t){let n="function"==typeof t?t(e):xt(e,t,void 0);if(null!=n){if("object"==typeof n){let e=n.id;return null==e?void 0:String(e)}return String(n)}}function Io(e,t){let n="function"==typeof t?t(e):xt(e,t,1);return Number(n)}function So(e,t){if(!t.has(e))return t.add(e),e;let n=2;for(;t.has(`${e}-${n}`);)n+=1;let r=`${e}-${n}`;return t.add(r),r}function $o(e,t,n={}){let r=n.nodeIdAccessor??"id",i=n.groupAccessor??"group",o=n.labelAccessor??"label",a=n.sourceAccessor??"source",l=n.targetAccessor??"target",s=n.valueAccessor??"value",d=new Set(n.expandedGroups??[]),c=n.includeInternalFlows??!0,u=[],h=new Map,p=new Map;for(let t of e){let e=vo(t,r,String(u.length));if(h.has(e))continue;let n=vo(t,o,e),a=vo(t,i,e),l={id:e,label:n,group:a,datum:t};u.push(l),h.set(e,l);let s=p.get(a);s?s.push(l):p.set(a,[l])}let f=new Set(u.map(e=>e.id)),m=[],g=new Map,y=new Map,x=[];for(let[e,t]of p){if(!d.has(e)&&(!0===n.collapseSingletons||t.length>1)){let r=So(`${n.groupIdPrefix??"group:"}${e}`,f),i={id:r,label:e,group:e,aggregate:!0,memberIds:t.map(e=>e.id),memberCount:t.length,internalValue:0,incomingValue:0,outgoingValue:0};m.push(i),g.set(r,i);for(let e of t)y.set(e.id,r);x.push({group:e,nodeId:r,label:e,collapsed:!0,memberIds:[...i.memberIds],internalValue:0,incomingValue:0,outgoingValue:0});continue}for(let n of t){let t={...n.datum,id:n.id,label:n.label,group:e,aggregate:!1,memberIds:[n.id],memberCount:1,internalValue:0,incomingValue:0,outgoingValue:0};m.push(t),g.set(t.id,t),y.set(n.id,t.id)}x.push({group:e,nodeId:null,label:e,collapsed:!1,memberIds:t.map(e=>e.id),internalValue:0,incomingValue:0,outgoingValue:0})}let b=new Map(x.map(e=>[e.group,e])),w=new Map,M=0;for(let e of t){let t=ko(e,a),n=ko(e,l),r=Io(e,s),i=null==t?void 0:y.get(t),o=null==n?void 0:y.get(n);if(!i||!o||!Number.isFinite(r)||r<=0){M+=1;continue}let d=h.get(t)?.group,c=h.get(n)?.group;if(d&&c&&d===c){let e=b.get(d);e&&(e.internalValue+=r)}else{if(d){let e=b.get(d);e&&(e.outgoingValue+=r)}if(c){let e=b.get(c);e&&(e.incomingValue+=r)}}let u=w.get(i);u||(u=new Map,w.set(i,u));let p=u.get(o);p?(p.value+=r,p.edgeCount+=1,p.memberEdges.push(e)):u.set(o,{source:i,target:o,value:r,edgeCount:1,internal:i===o,memberEdges:[e]})}let v=[...w.values()].flatMap(e=>[...e.values()]);for(let e of v){let t=g.get(e.source),n=g.get(e.target);e.internal?t&&(t.internalValue+=e.value):(t&&(t.outgoingValue+=e.value),n&&(n.incomingValue+=e.value))}return{nodes:m,edges:c?v:v.filter(e=>!e.internal),groups:x,omittedEdgeCount:M}}var ee=e=>{let t=e.config??{},n=e.dimensions.plot,r=e.nodes.map((e,t)=>({id:e.id,datum:ho(e),inputIndex:t})),i=new Map(r.map(e=>[e.id,e.inputIndex])),o=new Map((t.order??[]).map((e,t)=>[String(e),t]));if(r.sort((e,t)=>{let n=o.get(e.id),r=o.get(t.id);return null!=n&&null!=r?n-r:null!=n?-1:null!=r?1:(i.get(e.id)??0)-(i.get(t.id)??0)}),0===r.length)return{sceneNodes:[],sceneEdges:[],labels:[]};let a=Math.max(0,t.padding??18),l=Math.max(1,Math.min(n.width,n.height)-2*a),s=Math.min(Math.max(1,t.maxCellSize??120),l/r.length),d=s*r.length,c=n.x+(n.width-d)/2,u=n.y+(n.height-d)/2,h=Math.max(4,Math.min(.76*s,t.nodeSize??.56*s)),p=h/2,f=r.map((e,n)=>{let r="function"==typeof t.labelAccessor?t.labelAccessor(e.datum):String(xt(e.datum,t.labelAccessor??"label",e.id));return{id:e.id,label:r,datum:e.datum,index:n,cx:c+(n+.5)*s,cy:u+(n+.5)*s}}),m=new Map(f.map(e=>[e.id,e])),g=new Map(f.map(e=>[e.id,e.index])),y=function(e,t,n){let r=new Map;for(let i of e){let e=po(i.source),o=po(i.target),a=t.get(e),l=t.get(o);if(null==a||null==l)continue;let s=ho(i),d=fo("function"==typeof n.valueAccessor?n.valueAccessor(s):xt(s,n.valueAccessor??"value",i.value??1),0);if(d<=0)continue;let c=r.get(e);c||(c=new Map,r.set(e,c));let u=c.get(o);u?(u.value+=d,u.edgeCount+=1,u.memberEdges.push(s)):c.set(o,{key:`${a}-${l}`,source:e,target:o,sourceIndex:a,targetIndex:l,value:d,edgeCount:1,memberEdges:[s],datum:s,width:1,color:""})}let i=[...r.values()].flatMap(e=>[...e.values()]);for(let e of i)e.datum=Mt(t=>{for(let[n,r]of Object.entries(e.memberEdges[0]??{}))t(n,r);t("source",e.source),t("target",e.target),t("value",e.value),t("edgeCount",e.edgeCount),t("internal",e.source===e.target),t("memberEdges",e.memberEdges)});return i}(e.edges,g,t),x=function(e,t,n){let r=new Map,i=(e,t)=>{let n=r.get(e);n?n.push(t):r.set(e,[t])};for(let t of e)i(bo(t.source,t.targetIndex>=t.sourceIndex?"out-right":"out-left"),t),i(bo(t.target,t.sourceIndex<t.targetIndex?"in-top":"in-bottom"),t);for(let[e,t]of r){let n=e.startsWith("out-");t.sort((e,t)=>(n?e.targetIndex:e.sourceIndex)-(n?t.targetIndex:t.sourceIndex)||e.key.localeCompare(t.key))}let o=wo(t,n),a=null==n.flowScale?Number.POSITIVE_INFINITY:Math.max(0,n.flowScale);if(null==n.flowScale){for(let e of r.values()){let r=e.reduce((e,t)=>e+t.value,0),i=Mo(e.length,t,n),l=Math.max(.1,o-i*Math.max(0,e.length-1));r>0&&(a=Math.min(a,l/r))}Number.isFinite(a)||(a=1)}let l=Math.max(0,n.minFlowWidth??1.25),s=Math.max(l,n.maxFlowWidth??Number.POSITIVE_INFINITY);for(let t of e)t.width=Math.min(s,Math.max(l,t.value*a));let d=1;for(let e of r.values()){let r=e.reduce((e,t)=>e+t.width,0),i=Mo(e.length,t,n),a=Math.max(.1,o-i*Math.max(0,e.length-1));r>0&&(d=Math.min(d,a/r))}if(d<1)for(let t of e)t.width*=d;return r}(y,h,t),b=function(e,t,n,r){let i=new Map;for(let[o,a]of e){let e=o.slice(o.indexOf("\0")+1),l=t.get(e);if(!l)continue;let s=o.startsWith("out-")?l.cy:l.cx,d=Mo(a.length,n,r),c=s-(a.reduce((e,t)=>e+t.width,0)+d*Math.max(0,a.length-1))/2;for(let e of a){let t=c+e.width/2,n=o.startsWith("out-");i.set(`${e.key}:${n?"source":"target"}`,t),c+=e.width+d}}return i}(x,m,h,t),w=e.theme.semantic.info??e.theme.semantic.primary??e.resolveColor("adjacency-flow"),M=e.theme.semantic.text??"var(--semiotic-text, currentColor)",v=e.theme.semantic.surface??"var(--semiotic-bg, white)",k=e.theme.semantic.border??"var(--semiotic-border, currentColor)",I=e.theme.semantic.grid??k,S=e.theme.semantic.primary??e.resolveColor("adjacency-flow-node"),$=t.valueFormat??(e=>String(Math.round(100*e)/100)),N=Math.max(0,Math.min(t.cornerRadius??10,.22*s)),A=new Map(f.map(e=>[e.id,0])),E=new Map(f.map(e=>[e.id,0])),C=[],O=[],T=[];for(let n of y){let r=m.get(n.source),i=m.get(n.target);if(!r||!i)continue;A.set(r.id,(A.get(r.id)??0)+n.value),E.set(i.id,(E.get(i.id)??0)+n.value);let o=t.colorMode??"single",a="function"==typeof t.edgeColor?t.edgeColor(n.datum):void 0;n.color=a??("string"==typeof t.edgeColor?t.edgeColor:void 0)??("source"===o?e.resolveColor(n.source):"target"===o?e.resolveColor(n.target):"edge"===o?e.resolveColor(`${n.source}→${n.target}`):w);let l,d,h,f,g,y,x,k=b.get(`${n.key}:source`)??r.cy,I=b.get(`${n.key}:target`)??i.cx;if(n.sourceIndex<n.targetIndex){let e=[r.cx+p,k],t=[I,i.cy-p];l=[e,[t[0],e[1]],t],d=t[0],h=e[1]+.68*(t[1]-e[1]),f=Math.PI/2,g=t[0]-N-4,y=e[1]-n.width/2-3,x="end"}else if(n.sourceIndex>n.targetIndex){let e=[r.cx-p,k],o=[I,i.cy+p];l=[e,[o[0],e[1]],o],d=o[0],h=e[1]+.68*(o[1]-e[1]),f=-Math.PI/2,g=o[0]+N+4,y=e[1]+n.width/2+(t.valueFontSize??10),x="start"}else{let e=c+(r.index+1)*s,t=u+(r.index+1)*s,o=Math.max(2,Math.min(6,.07*s)),a=Math.max(r.cx+p+2,e-o),m=Math.max(r.cy+p+2,t-o),b=[r.cx+p,k],w=[I,i.cy+p];l=[b,[a,b[1]],[a,m],[w[0],m],w],d=(a+w[0])/2,h=m,f=Math.PI,g=a-3,y=m-n.width/2-3,x="end"}let S=go(l,N);if(T.push({type:"curved",id:`adjacency-flow-${n.key}`,label:`${r.label} to ${i.label}: ${$(n.value,n.datum)}`,pathD:S,style:{fill:"none",stroke:n.color,strokeWidth:n.width,opacity:.82,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${r.label} to ${i.label}, ${$(n.value,n.datum)}`,tableFields:{source:r.label,target:i.label,value:n.value,edges:n.edgeCount}}}),(t.showValues??!0)&&O.push({x:g,y:y,text:$(n.value,n.datum),anchor:x,fontSize:t.valueFontSize??Math.max(7,Math.min(10,.14*s)),fontWeight:650,fill:M,stroke:v,strokeWidth:3,paintOrder:"stroke"}),t.showArrows??!0){let e=Math.min(Math.max(0,t.arrowSize??14),Math.max(0,n.width-2));if(e<=2)continue;let r=Math.max(3,1.08*e);C.push(co.createElement("path",{key:`arrow-${n.key}`,className:"semiotic-adjacency-flow-arrow",d:yo(d,h,f,r,e),fill:t.arrowColor??"var(--semiotic-adjacency-flow-arrow-fill, rgba(255, 255, 255, 0.72))",stroke:"none","data-edge-width":n.width,"data-arrow-width":e,"aria-hidden":!0,focusable:!1,pointerEvents:"none",opacity:1}))}}let R=f.map(n=>{let r=("function"==typeof t.nodeColor?t.nodeColor(n.datum,n.index):void 0)??("string"==typeof t.nodeColor?t.nodeColor:"source"===(t.colorMode??"single")?e.resolveColor(n.id):S);return{type:"rect",id:n.id,label:n.label,x:n.cx-p,y:n.cy-p,w:h,h:h,style:{fill:r,stroke:t.nodeStroke??k,strokeWidth:1.25,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${n.label}, step ${n.index+1}`,tableFields:{step:n.index+1,node:n.label,incoming:E.get(n.id)??0,outgoing:A.get(n.id)??0}}}}),L=Math.max(2,t.maxLabelLength??14),F=f.map(e=>({x:e.cx,y:e.cy,text:xo(e.label,L),anchor:"middle",baseline:"middle",fontSize:t.labelFontSize??Math.max(6,Math.min(15,.34*h,h/Math.max(1.8,.62*e.label.length))),fontWeight:750,fill:t.nodeTextColor??v})),P=null;if(t.showGrid??!0){let e=[];for(let t=0;t<=f.length;t+=1){let n=c+t*s,r=u+t*s;e.push(co.createElement("line",{key:`grid-v-${t}`,x1:n,y1:u,x2:n,y2:u+d,stroke:I,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}),co.createElement("line",{key:`grid-h-${t}`,x1:c,y1:r,x2:c+d,y2:r,stroke:I,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}))}P=co.createElement(uo,null,...e)}return{sceneEdges:T,sceneNodes:R,labels:[...O,...F],backgrounds:P,overlays:co.createElement(uo,{z:"top"},...C),perspective:"manual",...e.perspective&&P?{perspectiveBounds:[{x:c,y:u,width:d,height:d}]}:{}}};import{NetworkPerspectiveBillboard as No,NetworkPerspectiveGround as Ao}from"./semiotic-network-placement.module.min.js";function Eo(e,t){let n=t.showEnclosures?e.enclosures.map(e=>({x:e.x,y:e.y,width:e.w,height:e.h})):[];if(t.showColumnHeaders)for(let r of e.colBands){let e=te((t.columnLabel??String)(r.col),t.headerFontSize)/2;n.push({x:r.x+r.w/2,y:t.headerY,z:0,extent:[e,e,t.headerFontSize,4]})}if(t.showRowLabels)for(let[r,i]of e.rowLabelY){let e=te((t.rowLabel??String)(r),t.labelFontSize);n.push({x:t.labelX,y:i,z:0,extent:[e,0,t.labelFontSize,t.labelFontSize]})}for(let e of t.callouts){let t=te("string"==typeof e.label?e.label:"",e.fontSize??11)/2,r=e.labelX-e.markX,i=e.labelY-e.markY;n.push({x:e.markX,y:e.markY,extent:[Math.max(0,t-r),Math.max(0,r+t),Math.max(0,14-i),Math.max(0,i)]})}return n}var te=(e,t)=>e.length*t*.6;import{jsx as Co,jsxs as Oo}from"react/jsx-runtime";function To(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();let t=String(e),n=Number(t);if(!Number.isNaN(n)&&""!==t.trim())return n;let r=Date.parse(t);return Number.isNaN(r)?NaN:r}function Ro(e,t,n){return e<t?t:e>n?n:e}function Lo(e){let t=2166136261;for(let n of e)t=Di(n.row,Di(n.col,Di(n.id,t))),t^=Math.round(8*n.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}var ne=/*#__PURE__*/new e(12),re=e=>{let t=e.config||{},n=e.dimensions.plot,i=t.columnAccessor??"column",o=t.rowAccessor??"row",a=t.sizeAccessor,l=t.colorAccessor,s=t.symbolAccessor,d=t.shadeAccessor,c=t.markerAccessor,u=t.iconAccessor,h=t.defaultSymbol??"circle",[p,f]=t.sizeRange??[2,8],m=t.shadeStrength??.72,g=t.shadeReverse??!1,y=t.rowMode??"banded",x=t.cellSizing??"proportional",b=t.proportionExponent??1,w=t.columnGap??16,M=t.rowGap??12,v=t.packPadding??1,k=t.iterations??12,I=!1!==t.showEnclosures,S=!1!==t.showColumnHeaders,$=!1!==t.showRowLabels,N=S?t.headerHeight??26:0,A=$?t.labelWidth??66:0,E=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,C=n.x+A,O=n.y+N,T=Math.max(1,n.width-A),R=Math.max(1,n.height-N-E),L=[];for(let t of e.nodes){let e=t.data??t;L.push({id:t.id,col:String(xt(t,i,"—")),row:String(xt(t,o,"—")),sizeVal:a?Number(xt(t,a,1)):1,colorKey:l?String(xt(t,l,"")):"",symVal:s?String(xt(t,s,"")):"",shadeVal:d?To(xt(t,d,null)):NaN,marker:!!c&&!!xt(t,c,!1),iconVal:u?String(xt(t,u,"")):"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===L.length)return{sceneNodes:[]};let F=1/0,P=-1/0;if(a)for(let e of L)Number.isFinite(e.sizeVal)&&(e.sizeVal<F&&(F=e.sizeVal),e.sizeVal>P&&(P=e.sizeVal));t.sizeDomain&&([F,P]=t.sizeDomain),(!Number.isFinite(F)||!Number.isFinite(P))&&(F=0,P=1);let z=e=>{if(P<=F)return(p+f)/2;let t=Math.sqrt(Ro((e-F)/(P-F),0,1));return p+t*(f-p)},D=1/0,j=-1/0;if(d)for(let e of L)Number.isFinite(e.shadeVal)&&(e.shadeVal<D&&(D=e.shadeVal),e.shadeVal>j&&(j=e.shadeVal));t.shadeDomain&&([D,j]=t.shadeDomain);let _=e=>{if(!d||!Number.isFinite(e)||j<=D)return.5;let t=Ro((e-D)/(j-D),0,1);return g?1-t:t},W=t.colorMap,G=new Map,Y=(t,n)=>{let r=G.get(t);return r||(r=$t(W&&Object.prototype.hasOwnProperty.call(W,t)&&"string"==typeof W[t]&&W[t]?W[t]:e.resolveColor(t),m),G.set(t,r)),r(n)},B=new Map;if(t.symbolMap)for(let[e,n]of Object.entries(t.symbolMap))B.set(e,n);let q=0,V=t.iconMap,H=e=>u&&V&&Object.prototype.hasOwnProperty.call(V,e)?V[e]??null:null,U=e=>u?"circle":(e=>{if(!s)return h;let t=B.get(e);return t||(t=r[q%r.length],q++,B.set(e,t)),t})(e.symVal),X=t.maxAreaFraction??.4,K=0,J=new Array(L.length),Z=new Array(L.length);for(let e=0;e<L.length;e++){let t=L[e],n=z(t.sizeVal);J[e]=n,t.baseShape=U(t),t.iconShape=H(t.iconVal);let r=wn(t.baseShape,Math.PI*n*n);Z[e]=r,K+=Math.PI*r*r}let Q=X*T*R,ee=K>Q?Math.sqrt(Q/K):1;for(let e=0;e<L.length;e++){let t=L[e],n=J[e]*ee;t.size=Math.PI*n*n,t.packR=Z[e]*ee}let te=new Map,re=new Map;for(let e of L)te.set(e.col,(te.get(e.col)??0)+1),re.set(e.row,(re.get(e.row)??0)+1);let oe=t.columnOrder?.filter(e=>te.has(e))??[...te.keys()].sort((e,t)=>(te.get(t)??0)-(te.get(e)??0)),ae=t.rowOrder?.filter(e=>re.has(e))??[...re.keys()].sort((e,t)=>(re.get(t)??0)-(re.get(e)??0)),le=It([Math.round(n.x),Math.round(n.y),Math.round(n.width),Math.round(n.height),N,A,E,y,x,b,w,M,v,k,p,f,F,P,X,oe.join(","),ae.join(","),L.length,Lo(L)]),se=ne.getOrCompute(le,()=>function(e,t){let n=new Map;for(let t of e){let e=n.get(t.col);e||(e=[],n.set(t.col,e)),e.push(t)}let r=t.columnOrder.filter(e=>n.has(e)),i=t.columnGap*Math.max(0,r.length-1),o=Math.max(1,t.innerW-i),a=t.proportionExponent,l=r.map(e=>Math.pow(n.get(e).length,a)),s=l.reduce((e,t)=>e+t,0)||1,d=e=>"uniform"===t.cellSizing?o/r.length:l[e]/s*o,c=new Map,u=[],h=t.innerX;for(let e=0;e<r.length;e++)u.push({col:r[e],x:h,w:d(e)}),h+=d(e)+t.columnGap;let p=1,f=new Map,m=[],g=(e,t,n,r)=>{let i=f.get(e);i||(i={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,i)),t-r<i.minX&&(i.minX=t-r),t+r>i.maxX&&(i.maxX=t+r),n-r<i.minY&&(i.minY=n-r),n+r>i.maxY&&(i.maxY=n+r)},y=(e,n,r,i,o,a)=>{let l=e.map(e=>({id:e.id,r:e.packR})),s=function(e,t,n,r,i,o,a,l){let s=t+r/2,d=n+i/2,c=new Map,u=e.length;if(0===u)return c;if(1===u)return c.set(e[0].id,{px:s,py:d}),c;let h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(l),p=new Float64Array(u),f=0;for(let t=0;t<u;t++)p[t]=e[t].r+o,p[t]>f&&(f=p[t]);let m=Math.max(1,Math.round(Math.sqrt(u*r/Math.max(1,i)))),g=new Float64Array(u),y=new Float64Array(u),x=r/m,b=i/Math.ceil(u/m);for(let e=0;e<u;e++){let r=e%m,i=Math.floor(e/m);g[e]=t+(r+.3+.4*h())*x,y[e]=n+(i+.3+.4*h())*b}let w=Math.max(0,Math.min(a,14)),M=Math.max(1,2*f),v=new Map,k=Math.max(1,Math.ceil(r/M)+3),I=(e,t)=>(t+1)*k+(e+1);for(let e=0;e<w;e++){v.clear();for(let e=0;e<u;e++){let r=I(Math.floor((g[e]-t)/M),Math.floor((y[e]-n)/M)),i=v.get(r);i?i.push(e):v.set(r,[e])}for(let e=0;e<u;e++){let r=Math.floor((g[e]-t)/M),i=Math.floor((y[e]-n)/M);for(let t=-1;t<=1;t++)for(let n=-1;n<=1;n++){let o=v.get(I(r+t,i+n));if(o)for(let t=0;t<o.length;t++){let n=o[t];if(n<=e)continue;let r=g[n]-g[e],i=y[n]-y[e],a=p[e]+p[n],l=r*r+i*i;if(!(l>=a*a))if(l>1e-9){let t=Math.sqrt(l),o=(a-t)/2;r/=t,i/=t,g[e]-=r*o,y[e]-=i*o,g[n]+=r*o,y[n]+=i*o}else{let t=2.39996323*e;g[e]+=Math.cos(t)*p[e],y[e]+=Math.sin(t)*p[e]}}}}for(let e=0;e<u;e++){let o=p[e],a=t+o,l=t+r-o,c=n+o,u=n+i-o;g[e]=l>a?Ro(g[e],a,l):s,y[e]=u>c?Ro(y[e],c,u):d}}for(let t=0;t<u;t++)c.set(e[t].id,{px:g[t],py:y[t]});return c}(l,n,r,i,o,t.packPadding,t.iterations,p++),d=1/0,u=1/0,h=-1/0,f=-1/0;for(let e of l){let t=s.get(e.id);c.set(e.id,{px:t.px,py:t.py}),g(a,t.px,t.py,e.r),t.px-e.r<d&&(d=t.px-e.r),t.px+e.r>h&&(h=t.px+e.r),t.py-e.r<u&&(u=t.py-e.r),t.py+e.r>f&&(f=t.py+e.r)}return Number.isFinite(d)?{x:d-ie,y:u-ie,w:h-d+2*ie,h:f-u+2*ie}:null};if("banded"===t.rowMode){let i=new Map;for(let t of e)i.set(t.row,(i.get(t.row)??0)+1);let o=t.rowOrder.filter(e=>i.has(e)),l=t.rowGap*Math.max(0,o.length-1),s=Math.max(1,t.innerH-l),d=o.map(e=>Math.pow(i.get(e),a)),h=d.reduce((e,t)=>e+t,0)||1,p=new Map,m=t.innerY+t.innerH;for(let e=0;e<o.length;e++){let n="uniform"===t.cellSizing?s/o.length:d[e]/h*s,r=m-n;p.set(o[e],{y:r,h:n}),m=r-t.rowGap}r.forEach((e,t)=>{let r=wt(n.get(e),e=>e.row);for(let e of o){let n=r.get(e),i=p.get(e);!n||!i||y(n,u[t].x,i.y,u[t].w,i.h,e)}});let g=[],x=new Map;for(let e of o){let t=p.get(e);x.set(e,t.y+t.h/2);let n=f.get(e);n&&Number.isFinite(n.minX)&&g.push({x:n.minX-ie,y:n.minY-ie,w:n.maxX-n.minX+2*ie,h:n.maxY-n.minY+2*ie})}return{positions:c,enclosures:g,colBands:u,rowLabelY:x}}let x=new Map;r.forEach((e,r)=>{let i=wt(n.get(e),e=>e.row),o=t.rowOrder.filter(e=>i.has(e)),l=t.rowGap*Math.max(0,o.length-1),s=Math.max(1,t.innerH-l),d=o.map(e=>Math.pow(i.get(e).length,a)),c=d.reduce((e,t)=>e+t,0)||1,h=t.innerY+t.innerH;o.forEach((e,n)=>{let a="uniform"===t.cellSizing?s/o.length:d[n]/c*s,l=h-a,p=y(i.get(e),u[r].x,l,u[r].w,a,e);if(p){m.push(p);let t=x.get(e)??{sum:0,n:0};t.sum+=p.y+p.h/2,t.n+=1,x.set(e,t)}h=l-t.rowGap})});let b=new Map;for(let[e,t]of x)b.set(e,t.sum/t.n);return{positions:c,enclosures:m,colBands:u,rowLabelY:b}}(L,{columnOrder:oe,rowOrder:ae,innerX:C,innerY:O,innerW:T,innerH:R,rowMode:y,cellSizing:x,proportionExponent:b,columnGap:w,rowGap:M,packPadding:v,iterations:k})),de=e.selection,ce=de?.isActive?de.predicate:null,ue=t.highlight??null,he=t.dimOpacity??.16,pe=t.markStroke,fe=t.markStrokeWidth??0,me=t.markerColor??"#ffffff",ge=t.iconColor??"rgba(255,255,255,0.92)",ye=t.iconStrokeWidth??1,xe=t.iconScale??.72,be=[],we=[],Me=[];for(let e of L){let t=se.positions.get(e.id);if(!t)continue;let n=kt(e.datum,{highlight:ue,predicate:ce,dimOpacity:he}),r={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:Y(e.colorKey,_(e.shadeVal)),opacity:n,...pe?{stroke:pe,strokeWidth:fe}:{}},datum:e.datum,id:e.id,label:String(e.id)};if(be.push(r),e.iconShape){let r=Math.sqrt(e.size/Math.PI)*xe,i=wn(e.iconShape,100),o=i>0?r/i*100*(r/i):Math.PI*r*r;Me.push({x:t.px,y:t.py,size:o,shape:e.iconShape,opacity:n})}e.marker&&n>he+.001&&we.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}let ve=[];if(t.callouts&&t.callouts.length>0){let e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",r=n.y+n.height-(E>0?.45*E:9),i=[];for(let e=0;e<t.callouts.length;e++){let n=t.callouts[e],r=L.find(e=>String(e.datum[n.field])===String(n.value));if(!r)continue;let o=se.positions.get(r.id);o&&i.push({c:n,ci:e,px:o.px,py:o.py,markR:Math.sqrt(r.size/Math.PI)})}let o=i.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;o.forEach((e,t)=>{a.set(e.ci,C+(t+.5)/o.length*T)});for(let t of i){let i=t.c,o=a.get(t.ci)??t.px,l=r,s=i.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof i.at&&i.at?(o=i.at.x,l=i.at.y):"number"==typeof i.at&&(l=n.y+i.at*n.height),ve.push({keyId:`callout-${t.ci}`,markX:t.px,markY:t.py,labelX:o,labelY:l,label:i.label,connector:s,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}let ke={markerDots:we,markerColor:me,iconMarks:Me,iconColor:ge,iconStrokeWidth:ye,callouts:ve,plot:n,showEnclosures:I,showColumnHeaders:S,showRowLabels:$,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:n.y+.62*N,labelX:n.x+A-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel},Ie=function(e,t){let n=t.columnLabel??(e=>e),r=t.rowLabel??(e=>e),i=(e,t,n,r)=>Co(No,{x:t,y:n,onGround:!0,children:r},e),o=(e,t,n,r,i)=>Co(No,{x:t,y:n,z:r,children:i},e);return Oo("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[Co(Ao,{children:t.showEnclosures&&e.enclosures.map((e,n)=>Bi({keyId:`enc-${n}`,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity}))}),t.iconMarks.length>0&&Co("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,n)=>i(`ic-${n}`,e.x,e.y,Co("path",{d:xn(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity})))}),t.markerDots.length>0&&Co("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,n)=>i(`mk-${n}`,e.x,e.y,Co("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor})))}),t.showColumnHeaders&&e.colBands.map((e,r)=>o(`col-${r}`,e.x+e.w/2,t.headerY,0,Hi({keyId:`col-${r}`,text:n(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor}))),t.showRowLabels&&[...e.rowLabelY].map(([e,n])=>o(`row-${e}`,t.labelX,n,0,Hi({keyId:`row-${e}`,text:r(e),x:t.labelX,y:n,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor}))),t.callouts.map(e=>o(String(e.keyId),e.markX,e.markY,"top",Ki(e)))]})}(se,ke);return{sceneNodes:be,overlays:Ie,perspective:"manual",...e.perspective?{perspectiveBounds:Eo(se,ke)}:{}}},ie=4;import*as Fo from"react";function Po(e,t,n){let r=new Set,i=[];for(let t of e)n(t)&&!r.has(t)&&(r.add(t),i.push(t));for(let e of t)r.has(e)||i.push(e);return i}var oe=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0)return{nodes:[]};let r=yt(t.categoryAccessor),i=yt(t.stackBy),o=e=>{let n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],r=Number(n);return Number.isFinite(r)&&r>0?r:0},a=t.gutter??2,l="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",s="string"==typeof t.stackBy?t.stackBy:"stack",d="string"==typeof t.valueAccessor?t.valueAccessor:"value",c=(e,t,n)=>Mt(r=>{r("category",e),r("stack",t),r("value",n),"category"!==l&&r(l,e),"stack"!==s&&r(s,t),"value"!==d&&r(d,n)}),u=!1!==t.showCategoryLabels,h=t.labelPadding??(u?22:0),p=Math.max(0,n.height-h),f=[],m=new Map,g=[],y=new Set,x=new Map;for(let t of e.data){let e=String(r(t)),n=String(i(t)),a=o(t);m.has(e)||(f.push(e),m.set(e,0),x.set(e,new Map)),y.has(n)||(y.add(n),g.push(n)),m.set(e,(m.get(e)??0)+a);let l=x.get(e);l.set(n,(l.get(n)??0)+a)}let b=t.categoryOrder?Po(t.categoryOrder,f,e=>m.has(e)):f,w=t.stackOrder?Po(t.stackOrder,g,()=>!0):g,M=b.reduce((e,t)=>e+(m.get(t)??0),0);if(M<=0)return{nodes:[]};let v=a*Math.max(0,b.length-1),k=Math.max(0,n.width-v),I=[],S=[],$=n.x;for(let t of b){let r=m.get(t)??0,i=r/M*k;if(i<=0)continue;S.push({cat:t,x:$,w:i});let o=x.get(t),l=n.y;for(let n of w){let a=o.get(n)??0;if(a<=0)continue;let s=a/r*p;I.push({type:"rect",x:$,y:l,w:i,h:s,style:{fill:e.resolveColor(n),stroke:"none"},datum:c(t,n,a),group:n}),l+=s}$+=i+a}let N=u&&S.length>0?function(e,t,n){let r=e.map((e,r)=>Hi({keyId:`marimekko-label-${r}`,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:n}));return Fo.createElement(Fo.Fragment,null,...r)}(S,n.y+p+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null;return{nodes:I,overlays:N}};import*as zo from"react";var ae=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0||0===e.data.length)return{nodes:[]};let r=Math.max(1,Ct(t.rowHeight??28)),i=Ct(t.rowGap??12),o=!1!==t.showLabels,a=o?Ct(t.labelWidth??120):0,l=!1!==t.showTicks,s=l?14:0,d=t.tickFormat??(e=>e.toLocaleString()),c=n.x+a,u=Math.max(0,n.width-a),h=yt(t.categoryAccessor),p=yt(t.valueAccessor),f=yt(t.targetAccessor),m=yt(t.rangesAccessor),g="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",y="string"==typeof t.valueAccessor?t.valueAccessor:"value",x="string"==typeof t.targetAccessor?t.targetAccessor:"target",b=t.actualColor??e.theme.semantic.primary??"#3b6cb1",w=e.theme.semantic.text??"currentColor",M=e.theme.semantic.textSecondary??"#888",v=e.theme.semantic.surface??"#e8eaed",k=e.theme.semantic.grid??"#cdd1d6",I=e.theme.semantic.border??"#a3a8af",S=t.targetColor??`var(--semiotic-text, ${w})`,$=[`var(--semiotic-surface, ${v})`,`var(--semiotic-grid, ${k})`,`var(--semiotic-border, ${I})`],N=`var(--semiotic-text, ${w})`,A=`var(--semiotic-text-secondary, ${M})`,E=[],C=e.data.map(e=>{let t=m(e),n=Array.isArray(t)?t.map(Ct).sort((e,t)=>e-t):[],r=Ct(p(e)),i=Ct(f(e));return{label:h(e),ranges:n,actual:r,target:i,maxVal:Math.max(r,i,ht(n))}}).filter(e=>e.maxVal>0),O=e=>u>0?Math.max(0,Math.floor((e+i)/(r+i+s))):0,T=Math.min(C.length,O(n.height))<e.data.length,R=C.slice(0,O(n.height-(T?18:0))).map((e,t)=>({...e,yTop:n.y+t*(r+i+s)}));for(let{yTop:e,label:t,ranges:n,actual:i,target:o,maxVal:a}of R){let l=e=>c+e/a*u,s=e=>Mt(n=>{n("metric",t),"metric"!==g&&n(g,t),e(n)}),d=c;for(let t=0;t<n.length;t++){let i=l(n[t]),o=i-d;o>0&&E.push({type:"rect",x:d,y:e,w:o,h:r,style:{fill:$[Math.min(t,$.length-1)],stroke:"none"},datum:s(e=>{e("range",t),e("rangeValue",n[t]),e("kind","range")}),group:`range-${t}`}),d=i}let h=Math.min(r,Math.max(6,Math.floor(.45*r)));E.push({type:"rect",x:c,y:e+(r-h)/2,w:l(i)-c,h:h,style:{fill:b,stroke:"none"},datum:s(e=>{e("value",i),e("kind","actual"),"value"!==y&&e(y,i)}),group:"actual"});let p=3,f=.8*r;E.push({type:"rect",x:l(o)-p/2,y:e+(r-f)/2,w:p,h:f,style:{fill:S,stroke:"none"},datum:s(e=>{e("target",o),e("kind","target"),"target"!==x&&e(x,o)}),group:"target"})}let L=[],F=Ft(n,R.length,e.data.length,"rows","Rows without positive values or enough plot space are omitted.");F&&L.push(F);for(let e=0;e<R.length;e++){let t=R[e],i=t.yTop+r/2;if(o&&L.push(Hi({keyId:`bullet-label-${e}`,text:t.label,x:n.x+a-8,y:i,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:N})),l){let n=t.yTop+r+2;for(let r=0;r<5;r++){let i=t.maxVal*r/4,o=c+i/t.maxVal*u;L.push(zo.createElement("line",{key:`bullet-tick-${e}-${r}`,x1:o,x2:o,y1:n,y2:n+3,stroke:A,strokeWidth:1}),Hi({keyId:`bullet-ticktext-${e}-${r}`,text:d(i),x:o,y:n+12,anchor:0===r?"start":4===r?"end":"middle",baseline:"auto",fontSize:10,color:A}))}}}return{nodes:E,overlays:L.length>0?zo.createElement(zo.Fragment,null,...L):null}};import{createElement as Do,Fragment as jo}from"react";import{scaleLinear as _o}from"d3-scale";var le=e=>{let t=e.config,{plot:n}=e.dimensions,r=t.fields??[];if(r.length<2||n.width<=0||n.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let i=Object.create(null);for(let n of r){let r=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,n)?t.domains[n]: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])){i[n]=[r[0],r[1]];continue}let o=1/0,a=-1/0;for(let t of e.data){let e=Number(t[n]);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);i[n]=[o-e,a+e]}else i[n]=[o,a];else i[n]=[0,1]}let o=!1!==t.showAxes,a=o?t.axisLabelPadding??24:8,l=o?18:8,s=r.map(e=>_o().domain(i[e]).range([n.y+n.height-l,n.y+a])),d=r.map((e,t)=>1===r.length?n.x+n.width/2:n.x+t/(r.length-1)*n.width),c=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,u=t.opacity??.45,h=t.strokeWidth??1.25,p=e.theme.semantic.primary??"#3b6cb1",f=t.dimmedOpacity??.08,m=t.highlightFn,g=[],y=[];for(let n of e.data){let i=c?e.resolveColor(String(c(n))):p,o=!m||m(n),a=kt(n,{predicate:m,baseOpacity:u,dimOpacity:f,brighten:.4}),l=o?y:g;for(let e=0;e<r.length-1;e++){let t=Number(n[r[e]]),c=Number(n[r[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(c))continue;let u={type:"connector",x1:d[e],y1:s[e](t),x2:d[e+1],y2:s[e+1](c),style:{stroke:i,strokeWidth:m&&o?h+.75:h,opacity:a,fill:"none"},datum:n};l.push(u)}if(t.showPoints)for(let e=0;e<r.length;e++){let t=Number(n[r[e]]);if(!Number.isFinite(t))continue;let o={type:"point",x:d[e],y:s[e](t),r:2.5,style:{fill:i,stroke:"none",opacity:Math.min(1,a+.3)},datum:n};l.push(o)}}let x=null;if(o){let o=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,c=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,u=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=n.y+a,p=n.y+n.height-l,f=[];for(let e=0;e<r.length;e++){let l=r[e],m=d[e],g=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,l)?t.tickFormat[l]:void 0,y="function"==typeof g?g:e=>e.toLocaleString();f.push(Do("line",{key:`pc-axis-line-${e}`,x1:m,x2:m,y1:h,y2:p,stroke:o,strokeWidth:1})),f.push(Hi({keyId:`pc-axis-label-${e}`,text:l,x:m,y:n.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:c}));let[x,b]=i[l],w=5;for(let t=0;t<w;t++){let n=x+(b-x)*t/(w-1),r=s[e](n);f.push(Do("line",{key:`pc-tick-${e}-${t}`,x1:m-3,x2:m+3,y1:r,y2:r,stroke:o,strokeWidth:1}),Hi({keyId:`pc-ticktext-${e}-${t}`,text:y(n),x:m+6,y:r+3,anchor:"start",baseline:"auto",fontSize:10,color:u}))}}x=Do(jo,null,...f)}return{nodes:g.concat(y),overlays:x}};import{jsx as Wo,jsxs as Go}from"react/jsx-runtime";function Yo(e,t){let n=Math.min(1,Math.max(0,t/e.height));return e.bottomRadius*(1-n)+e.topRadius*n}function Bo(e,t){return function(e,t,n){return Math.PI*n/3*(e*e+e*t+t*t)}(Yo(e,t),e.bottomRadius,t)}function qo(e,t){if(t<=0)return 0;if(t>=Bo(e,e.height))return e.height;let n=0,r=e.height;for(let i=0;i<60;i++){let i=n+(r-n)/2;Bo(e,i)<t?n=i:r=i}return n+(r-n)/2}function Vo(e,t){let n=43758.5453*Math.sin(12.9898*e+78.233);return 2*(n-Math.floor(n)-.5)*t}function Ho(e,t){if(!(t>0)||!Number.isFinite(e)||t>e)return[];if(e<2*t)return[{x:0,y:0}];let n=[],r=e-t;for(;n.length<ue;){let e=Math.min(ue,Math.floor(Math.PI*r/t));e<1&&(e=1);let i=r*Math.cos(0),o=r*Math.sin(0),a=r*Math.cos(2*Math.PI/e),l=r*Math.sin(2*Math.PI/e);Math.hypot(i-a,o-l)<2*t&&e>1&&e--;for(let t=0;t<e&&n.length<ue;t++)n.push({x:r*Math.cos(2*t*Math.PI/e),y:r*Math.sin(2*t*Math.PI/e)});let s=r-2*t;if(!(s>=t)){r>2*t&&n.length<ue&&n.push({x:0,y:0});break}r=s}return n}function Uo(e,t,n){let r=[],i=Math.min(n,ue),o=0;for(;i>0&&o<60;){let n=t*(1+2*o);if(n+t>e.height)break;let a=Ho(Yo(e,n),t),l=a.length-i,s=l>0?a.slice(Math.floor(l/2),Math.floor(l/2)+i):a,d=e.height-n;if(s.forEach((e,t)=>{r.push({x:e.x+Vo(97*o+t,.15),z:d+Vo(31*o+t,.05)})}),i-=s.length,o++,0===s.length)break}return{pearls:r,layers:o}}function Xo(e,t,n,r){if(r<=0)return[];let i=function(e,t,n){let r=n,i=0;for(;r>0&&i<60;){let n=t+se/2*(1+2*i);if(n+se/2>e.height)break;let o=Yo(e,n);if(2*o<se)break;r-=Math.max(1,Math.floor(2*o/se)),i++}return i}(e,t,r=Math.min(r,ue)),o=i*se,a=Math.max(t,n-o)+se/2,l=[],s=0;for(let t=0;t<i&&s<r;t++){let n=a+se*t,i=Yo(e,n),o=Math.max(1,Math.floor(2*i/se)),d=(2*i-o*se)/(o+1),c=-i+d,u=e.height-n-se/2-.1;for(let e=0;e<o&&s<r;e++){let n=c+(d+se)*e;l.push({cx:n+se/2,cy:u+se/2,rotation:Vo(53*t+e,10)}),s++}}return l}function Ko(e,t){let n=Number(e);return Number.isFinite(n)?n:t}function Jo(e,t){let n=Ko(e,t);return n>0?n:t}var se=1.75,de=.635,ce="#222222",ue=2e3,he={height:15.5,topRadius:4.75,bottomRadius:3.75},pe=e=>{let t=e.config,{plot:n}=e.dimensions;if(!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<=0||n.height<=0)return{nodes:[]};let r=yt(t.categoryAccessor??"name"),i=yt(t.teaVolumeAccessor??"teaVolume"),o=yt(t.bobaVolumeAccessor??"bobaVolume"),a=yt(t.iceVolumeAccessor??"iceVolume"),l=yt(t.cupHeightAccessor??"cupHeight"),s=yt(t.cupTopRadiusAccessor??"cupTopRadius"),d=yt(t.cupBottomRadiusAccessor??"cupBottomRadius"),c=yt(t.bobaRadiusAccessor??"bobaRadius"),u=Jo(t.cupWidthRatio,.82),h=e.scales.o,p=h.bandwidth(),f=Math.max(1,n.height-26-8),m=n.y+8,g=[],y=[];for(let t of e.data){let n=String(r(t)),x=h(n);if(null==x)continue;let b={height:Jo(l(t),he.height),topRadius:Jo(s(t),he.topRadius),bottomRadius:Jo(d(t),he.bottomRadius)},w=Bo(b,b.height);(!Number.isFinite(w)||w<=0)&&(b=he);let M=Jo(c(t),.6),v=Math.max(0,Ko(i(t),450)),k=Math.max(0,Ko(o(t),110)),I=Math.max(0,Ko(a(t),135)),S=Math.PI*M*M;(!Number.isFinite(S)||S<=0||!Number.isFinite(k/S))&&(M=.6,S=Math.PI*M*M);let $=Math.floor(k/S),N=Math.min(k,$*S),A=Math.floor(I/5.359375),E=Math.min(I,A*se*se*se),C=v+N+E;if(!Number.isFinite(C))throw new RangeError("Boba total volume exceeds the finite numeric range");let O=qo(b,C),T=Math.min(b.height,Math.max(0,O)),R=Yo(b,T),{pearls:L,layers:F}=Uo(b,M,$),P=T,z=Xo(b,F*M*2,P,A),D=b.height-20.32,j=Math.min(0,D),_=b.height-j,W=2*(b.topRadius+1),G=Math.min(p*u/W,f/_),Y=x+p/2,B=e=>Y+e*G,q=e=>m+(e-j)*G,V=B(-(b.topRadius+1)),H=B(b.topRadius+1),U=q(j),X=q(b.height),K=At({name:n,teaVolume:v,bobaVolume:Math.round(N),iceVolume:Math.round(E),totalVolume:Math.round(C),numBobas:$,numIce:A,renderedBobas:L.length,renderedIce:z.length,kind:"boba cup"});g.push({type:"rect",x:V,y:U,w:Math.max(1,H-V),h:Math.max(1,X-U),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:K,group:n,_transitionKey:`boba-${Et(n)}`});let J=b.height-P,Z=Et(n),Q=e.resolveColor(n);y.push(Go("g",{children:[v>0?Wo("path",{d:`M${B(-R)},${q(J)} L${B(-b.bottomRadius)},${q(b.height)} L${B(b.bottomRadius)},${q(b.height)} L${B(R)},${q(J)} z`,fill:"#D2B799"}):null,L.map((e,t)=>Wo("circle",{cx:B(e.x),cy:q(e.z),r:M*G,fill:"#222222",opacity:.5},`p-${t}`)),z.map((e,t)=>Wo("rect",{x:B(e.cx)-.95*se*G/2,y:q(e.cy)-.95*se*G/2,width:.95*se*G,height:.95*se*G,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${B(e.cx)} ${q(e.cy)})`},`i-${t}`)),Wo("path",{d:`M${B(-b.topRadius)},${q(0)} L${B(-b.bottomRadius)},${q(b.height)} L${B(b.bottomRadius)},${q(b.height)} L${B(b.topRadius)},${q(0)}`,fill:"none",stroke:ce,strokeWidth:2.5}),Wo("line",{x1:B(-(b.topRadius+1)),y1:q(0),x2:B(b.topRadius+1),y2:q(0),stroke:ce,strokeWidth:3,strokeLinecap:"round"}),v>0?Wo("path",{d:`M${B(-de)},${q(D)} L${B(-de)},${q(b.height-.4)} L${B(de)},${q(b.height-1.27-.4)} L${B(de)},${q(D)} z`,fill:"#4F91CB",stroke:ce,strokeWidth:1,opacity:.78}):null,Wo("text",{x:Y,y:X+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:n}),Wo("text",{x:Y,y:X+30,textAnchor:"middle",fontSize:10,fill:Q,children:`${$} pearls${L.length<$?` (${L.length} shown)`:""}${z.length<A?` · ${z.length}/${A} ice shown`:""} · ${Math.round(C)} cm³`})]},`boba-${Z}`))}return{nodes:g,overlays:Wo("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:y})}};import{scaleLinear as Zo}from"d3-scale";function Qo(e,t){if(!e)return null;let n=function(e){if(!e)return null;let t=e[fe];return t&&t.length>0?t:null}(e);if(!n)return e(t);let r=function(e,t){if(t instanceof Date){let n=t.getTime();return Number.isFinite(n)?e.find(e=>e.label instanceof Date&&e.label.getTime()===n)?.value??null:null}if("number"==typeof t&&Number.isFinite(t)){let n=e.find(e=>"number"==typeof e.label&&e.label===t);return n?n.value:e.find(e=>e.label instanceof Date&&e.label.getTime()===t)?.value??null}return"string"==typeof t?e.find(e=>"string"==typeof e.label&&e.label===t)?.value??null:null}(n,t);return null==r?null:e(r)}function ea(e,t){let n=t.scales?.x??t.scales?.time;return n?null!=e.x?Qo(n,e.x):t.xAccessor&&null!=e[t.xAccessor]?Qo(n,e[t.xAccessor]):null:null}function ta(e,t){let n=t.scales?.y??t.scales?.value;return n?null!=e.y?Qo(n,e.y):t.yAccessor&&null!=e[t.yAccessor]?Qo(n,e[t.yAccessor]):null:null}function na(e){return null==e?null:String(e)}function ra(e,t,n){return t.stickyPositionCache?.set(e,n),n}function ia(e){return!!e&&"object"==typeof e&&me.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function oa(e,t,n){if(!e)return[];let r=Math.max(1,Math.floor(t/n)),i=[],o="";for(let t of e.split(/\s+/))t&&(o&&o.length+1+t.length>r?(i.push(o),o=t):o=o?`${o} ${t}`:t);return o&&i.push(o),i}function aa(e){return ia(e)}function la(e){return"primary"===e?.emphasis||!0===e?.defensive}function sa(e,t,n={}){if("number"==typeof n.maxAnnotations&&Number.isFinite(n.maxAnnotations))return Math.max(0,Math.floor(n.maxAnnotations));if(!(e>0&&t>0))return 1/0;let r=n.areaPerAnnotation&&n.areaPerAnnotation>0?n.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/r))}function da(e){let t,n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;let r=e?.provenance?.confidence;switch("number"==typeof r&&Number.isFinite(r)&&(t+=15*gt(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 ca(e){let{annotations:t,width:n,height:r}=e,i=Math.max(0,e.minVisible??1),o=sa(n,r,e),a=t.map((e,t)=>({annotation:e,index:t,note:aa(e)})),l=a.filter(e=>e.note);if(0===l.length||l.length<=o)return{visible:t.slice(),deferred:[],budget:o};let s=l.filter(e=>la(e.annotation)),d=l.filter(e=>!la(e.annotation)).sort((e,t)=>da(t.annotation)-da(e.annotation)||e.index-t.index),c=Math.max(0,o-s.length),u=Math.max(0,i-s.length),h=Math.min(d.length,Math.max(c,u)),p=new Set([...s.map(e=>e.index),...d.slice(0,h).map(e=>e.index)]),f=[],m=[];for(let{annotation:e,index:t,note:n}of a)!n||p.has(t)?f.push(e):m.push(e);return{visible:f,deferred:m,budget:o}}function ua(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let n="string"==typeof t.source?Object.prototype.hasOwnProperty.call(ve,t.source)?ve[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(!n&&!r||null!=e.label&&"string"!=typeof e.label)return e;let i=[n,r].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${i})`)?e:{...e,label:o?`${o} (${i})`:`(${i})`}}function ha(e){if(!pa(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,n="string"==typeof e.shortText?e.shortText:void 0,r=t??n;return!r||"string"!=typeof e.label&&null!=e.label?e:{...e,label:r}}function pa(e){return ia(e)}function fa(e,t,n,r,i){let o=e+n,a=t+r;return Math.abs(n)>Math.abs(r)?{x:n>=0?o+4:o-i.width-4,y:r<0?a-i.height:a,width:i.width,height:i.height}:{x:n>=0?o:o-i.width,y:r<0?a-i.height-4:a+4,width:i.width,height:i.height}}function ma(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function ga(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 ya(e,t,n,r,i,o,a,l){let s=ma(e,a),d=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,r){let i=Math.max(0,r-e.x),o=Math.max(0,r-e.y),a=Math.max(0,e.x+e.width-(t-r)),l=Math.max(0,e.y+e.height-(n-r));return(i+a)*e.height+(o+l)*e.width}(s,i,o,l);for(let e of n)d+=12*ga(s,e);for(let e of r)d+=4*ga(s,e);return d}function xa(e){let{annotations:t,context:n,defaultOffset:r=ye,notePadding:i=xe,markPadding:o=be,edgePadding:a=we,preserveManualOffsets:l=!0,routeLongConnectors:s=!0,connectorThreshold:d=Me,density:c,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:m,audience:g}=e,y=n.width||0,x=n.height||0,b="object"==typeof f?f:{},w=b.breakpoint??480,M=!!f&&y<=w,v=M&&!1!==b.preferShortText?t.map(ha):t,k=M&&!c?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:c,I=u||M&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),S=M&&!p?b.responsive??{minWidth:w}:p,$=M&&!m?b.cohesion:m;if(0===v.length||y<=0||x<=0)return v.slice();let N=[],A=function(e,t){return(e.pointNodes||[]).map(e=>{let n=Math.max(1,e.r||1)+t;return{x:e.x-n,y:e.y-n,width:2*n,height:2*n}})}(n,o),E=!1,C=v.map((e,t)=>{if(!pa(e))return e;let o=function(e,t,n){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&&n.pointNodes){let e=n.pointNodes.find(e=>e.pointId===r);if(e)return{x:e.x,y:e.y}}let i=e.coordinates,o=n.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&o){let e=i[0],t=i[1];if("number"==typeof e&&"number"==typeof t){let n=o([e,t]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof e.x||"number"!=typeof e.y?function(e,t,n){let r=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===r){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let r=n.pointNodes.length-1;r>=0;r--){let i=n.pointNodes[r];if(i.pointId===e.pointId)return ra(t,n,{x:i.x,y:i.y})}let r=function(e){let t=e.data;if(!t||0===t.length)return null;let n=t[t.length-1],r=e.scales?.x??e.scales?.time,i=e.scales?.y??e.scales?.value;if(!r||!i)return null;let o=e.xAccessor||"x",a=e.yAccessor||"y",l=n[o],s=n[a];if(null==l||null==s)return null;let d=Qo(r,l),c=Qo(i,s);return null==d||null==c?null:{x:d,y:c}}(n);return r?ra(t,n,r):null}if("semantic"===r){let r=function(e,t,n){let r=function(e){return na(e.provenance?.stableId??e.stableId)}(e);if(!r)return null;let i=n.pointNodes?.find(e=>na(e.pointId)===r);if(i)return ra(t,n,{x:i.x,y:i.y});let o=n.data?.find(e=>function(e){return na(e.stableId??e.id??e.provenance?.stableId)}(e)===r);if(!o)return null;let a=ea(o,n),l=ta(o,n);return null==a||null==l?null:ra(t,n,{x:a,y:l})}(e,t,n);if(r)return r}let i=null,o=null;if(null!=e.pointId&&n.pointNodes){let t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(i=t.x,o=t.y)}if((null==i||null==o)&&(i=ea(e,n),o=ta(e,n)),null!=i&&null!=o)return ra(t,n,{x:i,y:o});if("sticky"===r){let e=n.stickyPositionCache?.get(t);if(e)return e}return null}(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!o)return e;let c=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=function(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let n="number"==typeof e.wrap?e.wrap:120,r=[...oa("string"==typeof e.title?e.title:void 0,n,7),...oa("string"==typeof e.label?e.label:void 0,n,7)],i=r.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(n,7*i)+10),height:Math.max(18,16*r.length+6)}}(!0===e.defensive?ua(e):e);if(l&&function(e){return"number"==typeof e.dx||"number"==typeof e.dy}(e)){let t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e),n="number"==typeof e.dx?e.dx:t.dx,r="number"==typeof e.dy?e.dy:t.dy;return N.push(ma(fa(o.x,o.y,n,r,c),i)),e}let u=null,h=1/0;for(let e of function(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}]}(r)){let t=ya(fa(o.x,o.y,e.dx,e.dy,c),e,N,A,y,x,i,a);t<h&&(u=e,h=t)}if(!u)return e;let p=ma(fa(o.x,o.y,u.dx,u.dy,c),i);N.push(p);let f=Math.hypot(u.dx,u.dy),m=s&&f>=d&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return E=!0,{...e,dx:u.dx,dy:u.dy,...m?{connector:m}:{}}}),O=E?C:v.slice(),T=O;if(h){let e=!1,t=O.map(t=>{let n=function(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,n="number"==typeof e.dy?e.dy:0;return Math.hypot(t,n)<8?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});T=e?t:O}{let e=!1,t=T.map(t=>{if(!0!==t?.defensive)return t;let n=ua(t);return n!==t&&(e=!0),n});T=e?t:T}let R,L=new Set;if(k){let e="object"==typeof k?k:{},t=function(e){if(!e)return 1;let t=function(e){let t=e?.familiarity;if(!t)return 3;let n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?3:n.reduce((e,t)=>e+t,0)/n.length}(e);return t<=2?1.5:t>=4?.6:1}(g),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??sa(y,x,e))*t))},{deferred:r}=ca({annotations:T,width:y,height:x,...n});for(let e of r)L.add(e)}if(S){let e="object"==typeof S&&"number"==typeof S.minWidth?S.minWidth:480;if(y<=e)for(let e of T)pa(e)&&"secondary"===e.emphasis&&L.add(e)}if(L.size>0)for(let e of T)!0===e?.defensive&&L.delete(e);return R=0===L.size?T:I?T.map(e=>L.has(e)?{...e,_annotationDeferred:!0}:e):T.filter(e=>!L.has(e)),$?function(e,t){let n=!1,r=e.map(e=>pa(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(n=!0,{...e,cohesion:t}):e);return n?r:e}(R,$):R}function ba(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function wa(e){let t=ba(e.tight,5),n=Math.max(t,ba(e.watch,12));return{tight:t,watch:n,comfortable:Math.max(n,ba(e.comfortable,20))}}function Ma(e={}){let{tight:t,watch:n,comfortable:r}=wa(e);return[{id:"tight",name:"Tight",label:`Tight (< ${t}%)`,max:t,color:Se.tight},{id:"watch",name:"Watch",label:`Watch (${t}% to < ${n}%)`,min:t,max:n,color:Se.watch},{id:"moderate",name:"Moderate",label:`Moderate (${n}% to < ${r}%)`,min:n,max:r,color:Se.moderate},{id:"comfortable",name:"Comfortable",label:`Comfortable (≥ ${r}%)`,min:r,color:Se.comfortable}].filter(e=>null==e.min||null==e.max||e.max>e.min)}function va(e,t={}){return Number.isFinite(e)?Ma(t).find(t=>(null==t.min||e>=t.min)&&(null==t.max||e<t.max))??null:null}function ka(e,t={}){let n=t.fuels??ke,r=!0===t.includeZero,i=[];for(let t of e)if(t&&"number"==typeof t.t)for(let e of n){let n=ba(t.fuels?.[e]);!r&&n<=0||i.push({t:t.t,fuel:e,fuelLabel:Ie[e],mw:n,ba:t.ba})}return i}function Ia(e){let t=[];for(let n of e){if(!n||"number"!=typeof n.t)continue;let e=ba(n.demandMw),r=n.forecastMw;"number"!=typeof r||!Number.isFinite(r)||t.push({t:n.t,a:e,b:r,demandMw:e,forecastMw:r,errorMw:e-r,ba:n.ba})}return t}function Sa(e){let t=ba(e.demand);if(t<=0)return 0;let n=ba(e.capacityOrNetGen),r=ba(e.interchange);return(n+(r<0?-r:0)-t)/t*100}function $a(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{let t=ba(e.demandMw),n=ba(e.netGenMw),r=Sa({demand:t,capacityOrNetGen:n,interchange:e.interchangeMw}),i=Math.max(0,ba(e.fuels?.wind))+Math.max(0,ba(e.fuels?.solar));return{t:e.t,ba:e.ba,reserveMarginPct:r,netLoadMw:t-i,demandMw:t,netGenMw:n}})}function Na(e={},t={}){let n=t.field,r=n?{field:n}:{},i=t.tightHatch??{type:"hatch",background:Se.tight,stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9},o={comfortable:{fill:t.comfortableFill??Se.comfortable,fillOpacity:.85},moderate:{fill:t.moderateFill??Se.moderate,fillOpacity:.85},watch:{fill:t.watchFill??Se.watch,fillOpacity:.9},tight:{fill:i,stroke:t.tightFill??Se.tight,strokeWidth:1,fillOpacity:1}};return Ma(e).reverse().map(e=>({id:`reserve-${e.id}`,label:e.label,when:{...r,...null!=e.min?{gte:e.min}:{},...null!=e.max?{lt:e.max}:{}},style:o[e.id]}))}function Aa(e={},t={}){let{tight:n,comfortable:r}=wa(e),[i,o]=t.extent??[],a=Math.min(n,ba(i,-50)),l=Math.max(r,ba(o,Math.max(r+30,40))),s={tight:.12,watch:.1,moderate:.08,comfortable:.06};return Ma(e).map(e=>({type:"band",y0:e.min??a,y1:e.max??l,label:e.name,color:e.color,fillOpacity:s[e.id],emphasis:"secondary"}))}function Ea(e,t){if(!e.length)return null;let n=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!n.length)return null;let r=n[n.length-1];if("number"==typeof t&&Number.isFinite(t)){let e=n.filter(e=>e.t<=t);r=e.length?e[e.length-1]:n[0]}let i=ba(r.demandMw),o=ba(r.netGenMw),a="number"==typeof r.forecastMw&&Number.isFinite(r.forecastMw)?r.forecastMw:null,l=Sa({demand:i,capacityOrNetGen:o,interchange:r.interchangeMw}),s={},d=null,c=0,u=0;for(let e of ke){let t=ba(r.fuels?.[e]);t<=0||(u+=t,s[e]=t,t>c&&(c=t,d=e))}if(u>0)for(let e of Object.keys(s))s[e]=s[e]/u;return{t:r.t,ba:r.ba,demandMw:i,forecastMw:a,forecastErrorMw:null==a?null:i-a,netGenMw:o,reserveMarginPct:l,topFuel:d,topFuelShare:u>0?c/u:0,topFuelMw:c,fuelShares:s}}function Ca(e,t={}){let n=t.now??Date.now(),r=t.author??"system",i=t.source??"authored-scenario";return e.map(e=>{let o=(e.start+e.end)/2,a=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:o,y:e.y??e.value,note:e.note,provenance:{author:r,authorKind:"system",source:i,basis:"rule",..."number"==typeof t.confidence&&Number.isFinite(t.confidence)?{confidence:Math.min(1,Math.max(0,t.confidence))}:{},createdAt:a,stableId:e.id,dataVersion:String(e.start)},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:n}})}function Oa(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function Ta(e,t=0){return Number.isFinite(e)?`${e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})} MW`:"—"}function Ra(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}var fe=/*#__PURE__*/Symbol.for("semiotic.heatmapBandTicks"),me=/*#__PURE__*/new Set(["label","callout","callout-circle","callout-rect","text","widget"]),ge=2e4,ye=32,xe=6,be=4,we=8,Me=72,ve={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"},ke=["naturalGas","coal","nuclear","hydro","wind","solar","other"],Ie={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},Se={tight:"var(--semiotic-danger, #c2410c)",watch:"var(--semiotic-warning, #d97706)",moderate:"var(--semiotic-info, #0891b2)",comfortable:"var(--semiotic-success, #16a34a)"};import*as La from"react";import{ticks as Fa}from"d3-array";function Pa(e,t){if("function"==typeof e)return e;let n=e??t;return e=>Number(e[n])}function za(e,t={}){let n=Pa(t.start,"start"),r=Pa(t.end,"end"),i=!1===t.sort?e.slice():e.slice().sort((e,t)=>n(e)-n(t)||r(t)-r(e)),o=new $e;return{packed:i.map(e=>({item:e,track:o.assign(n(e),r(e))})),trackCount:Math.max(1,o.count)}}function Da(e,t){let n=Pa(t.start,"start"),r=Pa(t.end,"end"),[i,o]=t.domain,a=t.step??1,l="half-open"===t.bounds;if(!Number.isFinite(i)||!Number.isFinite(o)||i>o||!Number.isFinite(a)||a<=0)return[];let s=(o-i)/a;if(s>=Number.MAX_SAFE_INTEGER||i<o&&(i+a<=i||o-a>=o))return[];let d=Math.min(.25,4*Number.EPSILON*Math.max(1,s)),c=Math.floor(s+d),u=s>Math.log2(e.length+1),h=[],p=[];if(u){for(let t of e){let e=n(t),i=r(t);e<=i&&(h.push(e),p.push(i))}h.sort((e,t)=>e-t),p.sort((e,t)=>e-t)}let f=0,m=0,g=[];for(let t=0;t<=c;t++){let y=t>0&&t===c&&Math.abs(t-s)<=d?o:i+t*a,x=0;if(u){for(;f<h.length&&h[f]<=y;)f++;for(;m<p.length&&(l?p[m]<=y:p[m]<y);)m++;x=f-m}else for(let t of e){let e=n(t),i=r(t);e<=y&&(l?y<i:y<=i)&&x++}g.push({value:y,count:x})}return g}function ja(e,t,n){let r="x"===t?"width":"height",i=new Float64Array(e.length),o=new Float64Array(e.length),a=Array.from({length:e.length},(e,t)=>t),l=0,s=()=>{for(let a=0;a<e.length;a++){let l=(e[a][r]+Math.max(0,n))/2;i[a]=e[a][t]-l,o[a]=e[a][t]+l}a.sort((e,t)=>i[e]-i[t]||e-t),l=0;for(let e=0;e<a.length;e++){let t=e+1,n=a.length;for(;t<n;){let r=t+n>>>1;i[a[r]]<=o[a[e]]?t=r+1:n=r}l+=t-e-1}};return s(),{lower:i,upper:o,order:a,update:s,get pairs(){return l}}}function _a(e,t,n,r,i=!1){let o="x"===t?"y":"x",a="x"===t?"width":"height",l="x"===t?"height":"width",s=ja(e,t,n),d=ja(e,o,n),c=new Float64Array(e.length);return()=>{c.fill(0),s.update(),i||d.update();let{order:u,lower:h,upper:p}=s.pairs<d.pairs?s:d;for(let i=0;i<u.length;i++){let s=u[i],d=e[s];for(let f=i+1;f<u.length&&h[u[f]]<=p[s];f++){let i=u[f],h=e[i];if(Math.abs(d[o]-h[o])>(d[l]+h[l])/2+n)continue;let p=h[t]-d[t]||(d.id<h.id?-.5:.5),m=(d[a]+h[a])/2+n-Math.abs(p);if(m<=0)continue;let g=m*r*Math.sign(p);c[s]-=g,c[i]+=g}}return c}}function Wa(e,t,n){let r=n?.orientation??"vertical",i=n?.bend??0,o=n?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===r){if(Math.abs(t.y-e.y)<o){let n=e.x<=t.x?1:-1,r=a(e.x,t.x)+n*(22+Math.abs(i));return`M${e.x},${e.y} Q${r},${a(e.y,t.y)} ${t.x},${t.y}`}let n=a(e.y,t.y)+i;return`M${e.x},${e.y} C${e.x},${n} ${t.x},${n} ${t.x},${t.y}`}if(Math.abs(t.x-e.x)<o){let n=e.y<=t.y?1:-1,r=a(e.y,t.y)+n*(22+Math.abs(i));return`M${e.x},${e.y} Q${a(e.x,t.x)},${r} ${t.x},${t.y}`}let l=a(e.x,t.x)+i;return`M${e.x},${e.y} C${l},${e.y} ${l},${t.y} ${t.x},${t.y}`}function Ga(e,t,n){if("vertical"===(n?.orientation??"vertical")){let n=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${n} L${t.x},${n} L${t.x},${t.y}`}let r=(e.x+t.x)/2;return`M${e.x},${e.y} L${r},${e.y} L${r},${t.y} L${t.x},${t.y}`}function Ya(e,t,n){if("vertical"===(n?.orientation??"vertical")){let n=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(n?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(n?-t.height/2:t.height/2)}}}let r=t.cx>=e.cx;return{from:{x:e.cx+(r?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(r?-t.width/2:t.width/2),y:t.cy}}}function Ba(e,t){let n=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*n:(e-((t?.count??1)-1)/2)*n}function qa(e,t){let n=1-t,r=n*n*n,i=3*n*n*t,o=3*n*t*t,a=t*t*t;return{x:r*e.p0.x+i*e.p1.x+o*e.p2.x+a*e.p3.x,y:r*e.p0.y+i*e.p1.y+o*e.p2.y+a*e.p3.y}}function Va(e,t){let n=1-t,r=3*n*n,i=6*n*t,o=3*t*t;return{x:r*(e.p1.x-e.p0.x)+i*(e.p2.x-e.p1.x)+o*(e.p3.x-e.p2.x),y:r*(e.p1.y-e.p0.y)+i*(e.p2.y-e.p1.y)+o*(e.p3.y-e.p2.y)}}function Ha(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function Ua(e,t){let n=_a(e,t?.axis??"x",t?.padding??0,t?.strength??.5)(),r=new Map;return e.forEach((e,t)=>r.set(e.id,(r.get(e.id)??0)+n[t])),r}function Xa(e,t,n=!1){if("function"==typeof e)return n?t=>e(bt(t)??t):e;let r=e??t;return e=>xt(e,r,void 0)}function Ka(e,t,n,r){return Ja(e,t,n,r,!1)}function Ja(e,t,n,r,i){let o=r.fixedAxis??"y",a=Xa(r.fixedAccessor,"fixed",i),l=e=>String(Xa(r.sourceAccessor,"source",i)(e)),s=e=>String(Xa(r.targetAccessor,"target",i)(e)),d=r.size??(()=>Ae),c=r.iterations??180,u=r.attraction??.012,h=r.anchorStrength??.003,p=r.collisionStrength??.12,f=r.collisionPadding??15,m=r.edgePadding??42,g=r.fixedPadding??16,y=r.damping??.72,x=r.spread??1,[b,w]=r.fixedDomain;if(![b,w,n.x,n.y,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return{positioned:[],byId:new Map};let M=w-b||1,v=("y"===o?n.y:n.x)+g,k=("y"===o?n.y+n.height:n.x+n.width)-g,I=("y"===o?n.x:n.y)+m,S=("y"===o?n.x+n.width:n.y+n.height)-m,$=Math.max(1,S-I),N=e.flatMap(e=>{let t=a(e);if("number"!=typeof t&&("string"!=typeof t||!t.trim()))return[];let n=Number(t),o=(e=>v+(e-b)/M*(k-v))(n);if(!Number.isFinite(n)||!Number.isFinite(o))return[];let l=bt(e)??e,s=(e=>String(Xa(r.idAccessor,"id",i)(e)))(e),{width:c,height:u}=d(l);if(![c,u].every(e=>Number.isFinite(e)&&e>0))return[];let h=I+ji(s)*$;return[{data:l,id:s,width:c,height:u,fixedValue:n,fixed:o,free:h,anchor:h}]}),A=e=>"y"===o?e.width:e.height,E=new Map(N.map((e,t)=>[e.id,t])),C=[];for(let e of t){let t=E.get(l(e)),n=E.get(s(e));void 0!==t&&void 0!==n&&C.push([t,n])}let O=N.map(e=>({id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height})),T="y"===o?"x":"y",R=_a(O,T,f,p,!0),L=new Float64Array(N.length);for(let e=0;e<c;e++){L.fill(0);for(let[e,t]of C){let n=(N[t].free-N[e].free)*u;L[e]+=n,L[t]-=n}for(let e=0;e<N.length;e++){let t=N[e];L[e]+=(t.anchor-t.free)*h,O[e][T]=t.free}let e=R();for(let t=0;t<N.length;t++){let n=N[t];n.free+=(L[t]+e[t])*y;let r=A(n)/2;n.free=Math.max(I+r,Math.min(S-r,n.free))}}if(1!==x){let e=(I+S)/2;for(let t of N){let n=A(t)/2;t.free=Math.max(I+n,Math.min(S-n,e+(t.free-e)*x))}}let F=N.map(e=>({data:e.data,id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:F,byId:new Map(F.map(e=>[e.id,e]))}}function Za(e){let t=0;for(let n of e)t+=Oe[n]??(n>="0"&&n<="9"?.556:(n.codePointAt(0)??0)>=11904?1:.65);return t}function Qa(e,t){return Math.max(8,Za(e)*t*1.05+1)}function el(e,t,n){if(!n)return{w:e,h:t};let r=Math.abs(n)*Math.PI/180,i=Math.cos(r),o=Math.sin(r);return{w:e*i+t*o,h:e*o+t*i}}function tl(e,t){let n=t>>>0;for(let t of e){n=Di(t.col,n);for(let e of t.rows)n=Di(`${e.text}␟${e.weight}␟${e.segment}`,n)}return(n>>>0).toString(36)}function nl(e){let t=Number(e.segmentDomain?.[0]),n=Number(e.segmentDomain?.[1]),r=Number.isFinite(t)?t:0,i=Number.isFinite(n)?n:r,o=i<r?-1:1,a=Math.abs(i-r),l=Number(e.currentSegment),s=Number.isFinite(l)?gt((l-r)*o,0,a):0,d=(e,t)=>{let n=Number(e);return Number.isFinite(n)?gt(n,0,1):t},c=d(e.oldestOpacity,.25),u=d(e.currentOpacity,1),h=d(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{let t=Number(e);if(!Number.isFinite(t))return h;let n=(t-r)*o;if(n>s)return h;if(0===s)return u;let i=gt(n/s,0,1);return c+(u-c)*i}}}var $e=class{constructor(){this.count=0,this.capacity=1,this.tree=new Float64Array(2).fill(NaN)}assign(e,t){let n;if(this.tree[1]<=e){let t=1;for(;t<this.capacity;)t*=2,this.tree[t]<=e||t++;n=t-this.capacity}else n=this.count++,n===this.capacity&&this.grow();let r=this.capacity+n;for(this.tree[r]=t;r>1;){r=Math.floor(r/2);let e=this.minimum(r);if(this.tree[r]===e)break;this.tree[r]=e}return n}minimum(e){let t=this.tree[2*e],n=this.tree[2*e+1];return t<=n||Number.isNaN(n)?t:n}grow(){let e=this.tree,t=this.capacity;this.capacity*=2,this.tree=new Float64Array(2*this.capacity).fill(NaN),this.tree.set(e.subarray(t),this.capacity);for(let e=this.capacity-1;e>0;e--)this.tree[e]=this.minimum(e)}},Ne=e=>{let t=e.config,{plot:n}=e.dimensions;if(n.width<=0||n.height<=0||0===e.data.length||!t?.domain)return{nodes:[]};let r=yt(t.laneAccessor),i=yt(t.startAccessor),o=yt(t.endAccessor),a=t.idAccessor?yt(t.idAccessor):null,l=t.unit??0,s=Ct(t.barGap??1.5),d=Math.max(0,t.minBarWidth??2),c=Ct(t.minBarHeight??3.5)||3.5,u=Ct(t.maxBarHeight??10)||10,h=t.cornerRadius??2,p=Ct(t.bottomInset??0),f=t.color??((t,n)=>e.resolveColor(n)),[m,g]=t.domain;if(!Number.isFinite(m)||!Number.isFinite(g)||m>g||!Number.isFinite(g-m))return{nodes:[]};let y=g-m||1,x=e=>n.x+(e-m)/y*n.width,b=e.scales?.o?.domain?.()??[],w=t.lanes??(b.length>0?b:[...new Set(e.data.map(r))]),M=Math.max(0,n.height-p)/Math.max(1,w.length);if(M<=0)return{nodes:[]};let v=Math.min(M/4,Ct(t.lanePadding??7)),k=e=>x(i(e)),I=e=>Math.max(k(e)+d,x(o(e)+l)),S=[];w.forEach((t,i)=>{let o=n.y+i*M,l=e.data.filter(e=>r(e)===t);if(0===l.length)return;let{packed:d,trackCount:p}=za(l,{start:k,end:I}),m=new Map,g=new Map;for(let{item:e,track:t}of d){let n=g.get(t);n&&m.set(n,k(e)),g.set(t,e)}let y=(M-2*v)/p,x=Math.min(u,y,Math.max(c,y-s));for(let{item:e,track:n}of d){let r=k(e),i=m.get(e),l=I(e)-r,s=void 0!==i&&r+l>i-1?Math.max(1,i-1-r):l,d=o+v+n*y;S.push({type:"rect",x:r,y:d,w:s,h:x,cornerRadii:h>0?{tl:h,tr:h,br:h,bl:h}:void 0,style:{fill:f(e,t),stroke:"none"},datum:e,group:t,_transitionKey:a?String(a(e)):void 0})}});let $=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,N=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,A=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,E=[];(t.periods??[]).forEach((e,t)=>{let r=x(e.start),i=Math.max(1,x(e.end+l)-r);E.push(La.createElement("rect",{key:`period-${t}`,x:r,y:n.y,width:i,height:n.height,fill:A,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&E.push(Hi({keyId:`period-label-${t}`,text:e.name,x:r+4,y:n.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:N}))});let C=!1!==t.showLaneLabels,O=t.laneLabelGap??12;if(w.forEach((e,t)=>{let r=n.y+t*M;E.push(La.createElement("line",{key:`lane-sep-${t}`,x1:n.x,x2:n.x+n.width,y1:r,y2:r,stroke:A,opacity:.45})),C&&E.push(Hi({keyId:`lane-label-${t}`,text:e,x:n.x-O,y:r+M/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:$}))}),!1!==t.showAxis){let e=t.axisTicks??Fa(m,g,7);E.push(Xi({keyId:"interval-axis",scale:x,ticks:e,orient:"top",offset:n.y,tickLength:0,gridLength:n.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:N}))}return{nodes:S,overlays:La.createElement(La.Fragment,null,...E)}},Ae={width:60,height:34},Ee=e=>{let{plot:t}=e.dimensions;if(t.width<=0||t.height<=0||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};let n=e.config.fixedAxis??"y",{positioned:r,byId:i}=Ja(e.nodes,e.edges,t,e.config,!0),o=r.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[],l=Xa(e.config.sourceAccessor,"source",!0),s=Xa(e.config.targetAccessor,"target",!0);e.edges.forEach((e,t)=>{let r=i.get((e=>String(l(e)))(e)),o=i.get((e=>String(s(e)))(e));if(!r||!o)return;let{from:d,to:c}=Ya({cx:r.x,cy:r.y,width:r.width,height:r.height},{cx:o.x,cy:o.y,width:o.width,height:o.height},{orientation:"y"===n?"vertical":"horizontal"});a.push({type:"curved",pathD:Wa(d,c,{orientation:"y"===n?"vertical":"horizontal",bend:Ba(t,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:bt(e)??e})});let d=r.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:o,sceneEdges:a,labels:d}},Ce=1.15,Oe={a:.556,b:.611,c:.556,d:.611,e:.556,f:.333,g:.611,h:.611,i:.278,j:.278,k:.556,l:.278,m:.889,n:.611,o:.611,p:.611,q:.611,r:.389,s:.556,t:.333,u:.611,v:.556,w:.778,x:.556,y:.556,z:.5,A:.722,B:.722,C:.722,D:.722,E:.667,F:.611,G:.778,H:.722,I:.278,J:.556,K:.722,L:.611,M:.833,N:.722,O:.778,P:.667,Q:.778,R:.722,S:.667,T:.611,U:.722,V:.667,W:.944,X:.667,Y:.667,Z:.611,"'":.278,"’":.278,"-":.333,".":.278,",":.278," ":.278},Te=class e{constructor(e){this.cell=e,this.cells=new Map}span(e,t){return[Math.floor(e/this.cell),Math.floor(t/this.cell)]}static key(e,t){return 65536*(e+32768)+(t+32768)}insert(t){let[n,r]=this.span(t.x-t.w/2,t.x+t.w/2),[i,o]=this.span(t.y-t.h/2,t.y+t.h/2);for(let a=n;a<=r;a++)for(let n=i;n<=o;n++){let r=e.key(a,n),i=this.cells.get(r);i?i.push(t):this.cells.set(r,[t])}}collides(t,n){let[r,i]=this.span(t.x-t.w/2-n,t.x+t.w/2+n),[o,a]=this.span(t.y-t.h/2-n,t.y+t.h/2+n);for(let l=r;l<=i;l++)for(let r=o;r<=a;r++){let i=this.cells.get(e.key(l,r));if(i)for(let e of i)if(Math.abs(t.x-e.x)<(t.w+e.w)/2+n&&Math.abs(t.y-e.y)<(t.h+e.h)/2+n)return!0}return!1}};import{jsx as rl,jsxs as il}from"react/jsx-runtime";function ol(e){let t=e.config,{plot:n}=e.dimensions,r={nodes:[],unplaced:[],sizeFloored:[]};if(n.width<=0||n.height<=0||0===e.data.length)return r;let i=yt(t.textAccessor),o=e=>{let n=Number(yt(t.weightAccessor)(e));return Number.isFinite(n)&&n>0?n:0},a=yt(t.columnAccessor),l=e=>Number(yt(t.segmentAccessor)(e)),s=t.minFontSize??11,d=t.maxFontSize??42,c=t.columnGutter??18,u=t.collisionPadding??2,h=!1!==t.showColumnLabels,p=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>String(Math.round(e))),g=t.rotate??0,y=!0===t.repeatWords,x=!1!==t.scaleToFit,b=t.packingDensity??.6,w="string"==typeof t.textAccessor?t.textAccessor:"word",M="string"==typeof t.weightAccessor?t.weightAccessor:"weight",v="string"==typeof t.columnAccessor?t.columnAccessor:"column",k="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",I=[],S=new Map,$=1/0,N=-1/0;for(let t=0;t<e.data.length;t++){let n=e.data[t],r=String(a(n)),s=String(i(n)),d=o(n),c=l(n);!s||!Number.isFinite(c)||(S.has(r)||(I.push(r),S.set(r,[])),S.get(r).push({col:r,text:s,weight:d,segment:c,datum:n,dataIndex:t}),c<$&&($=c),c>N&&(N=c))}if(0===I.length)return r;if(!y)for(let[e,t]of S){let n=new Map;for(let e of t){let t=n.get(e.text);(!t||e.weight>t.weight)&&n.set(e.text,e)}S.set(e,[...n.values()])}let A=1/0,E=-1/0;for(let e of S.values())for(let t of e)t.weight<A&&(A=t.weight),t.weight>E&&(E=t.weight);if(!Number.isFinite(A))return r;let C=t.columnOrder?[...t.columnOrder.filter(e=>S.has(e)),...I.filter(e=>!t.columnOrder.includes(e))]:I,O=new Map(C.map(n=>[n,t.columnColor?.(n)||e.resolveColor(n)])),[T,R]=t.segmentDomain??[$,N],L=R-T||1,F=E-A||1,P=h?22:0,z=p?52:0,D=n.x+z,j=n.y+P,_=Math.max(0,n.width-z),W=Math.max(0,n.height-P),G=C.length,Y=Math.max(0,_-c*Math.max(0,G-1)),B=G>0?Y/G:0,q=j+14,V=j+W-14,H=e=>q+(e-T)/L*(V-q),U=C.map((e,n)=>{let r=O.get(e),i=(S.get(e)??[]).map((i,o)=>{let a={word:i.text,column:i.col,weight:i.weight,segment:i.segment,datum:i.datum,dataIndex:i.dataIndex,columnIndex:n,resolvedColumnColor:r},l=t.wordOpacity?Number(t.wordOpacity(a)):1,c=t.wordColor?.(a),u=`${e}::${i.text}::${o}`,h=(e=>E>0?d*Math.sqrt(e/E):0)(i.weight);return{id:u,text:i.text,weight:i.weight,segment:i.segment,baseFont:Math.max(s,h),floored:h<s,rotation:g>0?2*(ji(u+"r")-.5)*g:0,opacity:Number.isFinite(l)?gt(l,0,1):0,color:c||r,info:a}});return 0===i.length?null:{col:e,colLeft:D+n*(B+c),center:D+n*(B+c)+B/2,rows:i}}).filter(e=>null!==e),X=It([n.x,n.y,n.width,n.height,P,z,c,u,s,d,g,x,b,T,R,U.length,tl(U,2166136261),tl(U,16777619)]),K=Re.getOrCompute(X,()=>function(e){let{plans:t,colW:n,bodyH:r,yTop:i,yBot:o,segToY:a,collisionPadding:l}=e,s=n*r,d=1/0,c=1/0;for(let r of t){let t=0;for(let e of r.rows){let r=1.05*Za(e.text);t+=r*Ce*e.baseFont*e.baseFont;let i=el(r,Ce,e.rotation);c=Math.min(c,(n-8-1)/(i.w*e.baseFont))}t>0&&(d=Math.min(d,Math.sqrt(e.packingDensity*s/t)))}let u=e=>{let r=[],s=[];return t.forEach((t,d)=>{if(n<=0)return;let c=t.colLeft+4,u=t.colLeft+n-4,h=t.rows.map((t,r)=>{let i=e*t.baseFont,o=Math.max(5,i),l=el(Qa(t.text,o),o*Ce+2,t.rotation);return{rowIndex:r,id:t.id,font:o,floored:t.floored||i<5,rotation:t.rotation,w:l.w,h:l.h,anchorY:a(t.segment),seed:(ji(t.id)-.5)*Math.min(.5*n,80)}}).sort((e,t)=>t.font-e.font||(e.id<t.id?-1:1)),p=new Te(32);for(let e of h){let n=e.w/2,a=e.h/2,h=gt(t.center+e.seed,c+n,u-n),f=e.anchorY,m=null;for(let t=0;t<2600;t++){let r=3.2*Math.sqrt(t),s=2.399963229728653*t,d={x:gt(h+r*Math.cos(s),c+n,u-n),y:gt(f+r*Math.sin(s),i+a,o-a),w:e.w,h:e.h};if(!p.collides(d,l)){m=d;break}}m?(p.insert(m),r.push({planIndex:d,rowIndex:e.rowIndex,id:e.id,x:m.x,y:m.y,fontSize:e.font,rotation:e.rotation,w:e.w,h:e.h,floored:e.floored})):s.push({planIndex:d,rowIndex:e.rowIndex})}}),{placements:r,unplaced:s}},h=e.scaleToFit?Math.min(1,d,c):Math.min(1,c),p=u(h);if(e.scaleToFit)for(let e=0;e<6&&p.unplaced.length>0&&h>.1;e++)h*=.88,p=u(h);return p}({plans:U,colW:B,bodyH:W,yTop:q,yBot:V,segToY:H,collisionPadding:u,packingDensity:b,scaleToFit:x})),J=(e,t)=>U[e].rows[t],Z=K.unplaced.map(({planIndex:e,rowIndex:t})=>J(e,t).info),Q=K.placements.map(e=>{let t=J(e.planIndex,e.rowIndex),n=U[e.planIndex].col,r=Math.sqrt((t.weight-A)/F);return{id:e.id,text:t.text,x:e.x,y:e.y,w:e.w,h:e.h,fontSize:e.fontSize,rotation:e.rotation,floored:e.floored,color:t.color,opacity:t.opacity,info:t.info,datum:Mt(e=>{for(let n of Object.keys(t.info.datum))e(n,t.info.datum[n]);e("word",t.text),e("weight",t.weight),e("column",n),e("segment",t.segment),"word"!==w&&e(w,t.text),"weight"!==M&&e(M,t.weight),"column"!==v&&e(v,n),"segment"!==k&&e(k,t.segment),e("__strength",.5+.5*r)})}}),ee=Q.filter(e=>e.opacity>0);return{nodes:ee.map(e=>{let t=e.rotation?e.w:Qa(e.text,e.fontSize),n=e.rotation?e.h:e.fontSize*Ce;return{type:"rect",x:e.x-t/2,y:e.y-n/2,w:t,h:n,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:String(e.datum.column),_transitionKey:e.id}}),overlays:il("g",{className:"semiotic-word-trails","data-unplaced-count":Z.length||void 0,children:[p&&al({x:n.x+z-10,yTop:q,yBot:V,segLo:T,segHi:R,segToY:H,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:n.x}),h&&C.map((e,t)=>B<=0?null:rl("text",{x:D+t*(B+c)+B/2,y:n.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:O.get(e),style:{pointerEvents:"none"},children:e},`wt-col-${t}`)),ee.map(e=>rl("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},`wt-${e.id}`))]}),restyle:()=>{},unplaced:Z,sizeFloored:Q.filter(e=>e.floored).map(e=>e.info)}}function al(e){let t=[],n=e.segHi-e.segLo||1;for(let r=0;r<e.tickCount;r++)t.push(e.segLo+n*r/Math.max(1,e.tickCount-1));return il("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[rl("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,n)=>{let r=e.segToY(t);return il("g",{children:[rl("line",{x1:e.x-4,y1:r,x2:e.x,y2:r,stroke:e.color,strokeWidth:1,opacity:.6}),rl("text",{x:e.x-7,y:r,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},`wt-tick-${n}`)}),e.label&&rl("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}function ll(e){return null==e?void 0:String(e)}function sl(e){let t=ll(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...Le,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function dl(e){return sl(e)}function cl(e){let[[t,n],[r,i]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((r-t)*(i-n)),style:{...Le,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function ul(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Le,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:ll(e.id)}}function hl(e){let t=ll(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Le,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...Le,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function pl(e){let t={style:{...Le,cursor:e.cursor},datum:e.datum,id:ll(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?((!e.type||"curved"===e.type)&&(t.style.fill="none"),{type:e.type??"curved",pathD:e.pathD,...t}):{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function fl(e,t,n={}){let{coord:r,step:i=1,equals:o=Object.is,truthyOnly:a=!1}=n,l=[],s=t=>r?r(e[t],t):t,d=(e,t,n)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=r?null!=n&&s(n)-s(t)<=i?s(n):s(t)+i:t+1,l.push(e)},c=null;for(let n=0;n<e.length;n++){let l=t(e[n],n);if(a&&!l){c&&(d(c,c.endIndex,n),c=null);continue}let u=!(r&&n>0)||s(n)-s(n-1)<=i;c&&u&&o(c.value,l)?c.endIndex=n:(c&&d(c,c.endIndex,n),c={value:l,start:s(n),end:s(n),count:1,startIndex:n,endIndex:n})}return c&&d(c,c.endIndex,null),l}function ml(e,t,n=0){return t<=0?e:((e-n)%t+t)%t+n}function gl(e,t,n){if(n<=0)return t-e;let r=(t-e)%n;return r>n/2?r-=n:r<=-n/2&&(r+=n),r}function yl(e,t,n){return t<=n?e>=t&&e<=n:e>=t||e<=n}function xl(e,t,n,r){return n<=r?e.filter(e=>yl(t(e),n,r)):[...e.filter(e=>t(e)>=n),...e.filter(e=>t(e)<=r)]}function bl(e){let{desired:t,minGaps:n,weights:r}=e,i=t.length;if(0===i)return[];if(n.length!==Math.max(0,i-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let o=new Array(i).fill(0);for(let e=1;e<i;e++)o[e]=o[e-1]+Math.max(0,Number.isFinite(n[e-1])?n[e-1]:0);let a=[];for(let e=0;e<i;e++){let n=Math.max(Number.EPSILON,Number.isFinite(r?.[e])?r[e]:1),i=(Number.isFinite(t[e])?t[e]:0)-o[e];for(a.push({start:e,end:e,weight:n,mean:i});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.mean<=e.mean)break;let n=t.weight+e.weight;a.splice(a.length-2,2,{start:t.start,end:e.end,weight:n,mean:(t.mean*t.weight+e.mean*e.weight)/n})}}let l=Number.isFinite(e.min)?e.min:-1/0,s=Number.isFinite(e.max)?e.max-o[i-1]:1/0,d=s<l?l:s,c=new Array(i);for(let e of a){let t=Math.max(l,Math.min(d,e.mean));for(let n=e.start;n<=e.end;n++)c[n]=t+o[n]}return c}function wl(e,t){let n=0,r=e.length-1,i=-1;for(;n<=r;){let o=n+r>>>1;e[o].at<=t?(i=o,n=o+1):r=o-1}return i<0?{at:t,before:0,after:0}:e[i]}function Ml(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let n=[],r=[0];for(let i=0;i<e.length-1;i++){let o=e[i],a=e[i+1],l=[...new Set([...o.map(e=>e.at),...a.map(e=>e.at)])].sort((e,t)=>e-t),s=0;for(let e of l){let t=wl(o,e),n=wl(a,e);s=Math.max(s,t.after+n.before)}n.push(s),r.push(r[r.length-1]+s+t)}return{adjacentClearance:n,positions:r}}function vl(e,t,n,r={}){let i=[...e];if(i.length<=1)return i;let o=[...i],a=n(i),l=1,s=Math.max(0,r.passes??6),d=Math.max(1,r.maxEvaluations??1/0);for(let e=0;e<s&&l<d;e++){let e=new Map(i.map((e,t)=>[e,t])),s=new Map,d=new Map;for(let n of t){let t=e.get(n.source),r=e.get(n.target);if(null==t||null==r)continue;let i=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;s.set(n.source,(s.get(n.source)??0)+r*i),d.set(n.source,(d.get(n.source)??0)+i),s.set(n.target,(s.get(n.target)??0)+t*i),d.set(n.target,(d.get(n.target)??0)+i)}i=i.map((e,t)=>({item:e,index:t,barycenter:(s.get(e)??t)/(d.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 c=n(i);if(l++,c<a)a=c,o=[...i];else if(c===a)break}return o}function kl(e,t,n={}){let r=[...e];if(r.length<=1)return r;let i=t(r),o=1,a=Math.max(0,n.passes??6),l=Math.max(1,n.maxEvaluations??1/0);for(let e=0;e<a&&o<l;e++){let e=!1;for(let n=0;n<r.length-1&&o<l;n++){[r[n],r[n+1]]=[r[n+1],r[n]];let a=t(r);o++,a<i?(i=a,e=!0):[r[n],r[n+1]]=[r[n+1],r[n]]}if(!e)break}return r}function Il(e,t,n={}){let r=[...e],i=r.length;if(i<=1||i>(n.maxItems??8))return r;let o=Math.max(1,n.maxEvaluations??1/0),a=0,l=[...r],s=1/0,d=()=>{if(a>=o)return;let e=t(r);a++,e<s&&(s=e,l=[...r])};d();let c=new Array(i).fill(0),u=0;for(;u<i&&a<o;)if(c[u]<u){let e=u%2==0?0:c[u];[r[e],r[u]]=[r[u],r[e]],d(),c[u]++,u=0}else c[u]=0,u++;return l}function Sl(e,t,n=()=>!0){let r=0;for(let i=0;i<e.length;i++){let[o,a]=t(e[i]);for(let l=i+1;l<e.length;l++){if(!n(e[i],e[l]))continue;let[s,d]=t(e[l]);(o-s)*(a-d)<0&&r++}}return r}function $l(e,t){let n=Math.max(0,t.width),r=t.y,i=Math.min(74,Math.max(34,.08*n)),o=t.paddingLeft??i,a=t.paddingRight??i,l=Math.max(0,n-o-a),s=e.length>1?l/(e.length-1):0,d=new Map;return e.forEach((e,t)=>{d.set(e.id,{id:e.id,x:o+s*t,y:r,index:t})}),d}function Nl(e,t){let n=Math.max(0,t.width),r=t.y,i=Math.min(74,Math.max(34,.08*n)),o=t.paddingLeft??i,a=t.paddingRight??i,l=t.gap??8,s=!1!==t.distribute,d=t.estimateWidth??(e=>Al(e.label??e.id)),c=e.map((e,t)=>Math.max(1,d(e,t))),u=c.reduce((e,t)=>e+t,0)+l*Math.max(0,e.length-1),h=Math.max(0,n-o-a),p=Math.max(0,h-u),f=s&&e.length>1?p/(e.length-1):0,m=new Map,g=o;return!s&&1===e.length&&(g=o+Math.max(0,(h-c[0])/2)),e.forEach((e,t)=>{let n=c[t];m.set(e.id,{id:e.id,x:g+n/2,y:r,index:t,width:n}),g+=n+l+f}),m}function Al(e,t=38,n=7.4,r=20){return Math.max(t,String(e??"").length*n+r)}function El(e){let t=e.map(e=>{let t=Math.min(e.a,e.b),n=Math.max(e.a,e.b);return{span:e,a:t,b:n,width:n-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),n=new $e,r=t.map(e=>{let t=n.assign(e.a,e.b);return{span:e.span,level:t}}),i=Math.max(0,n.count-1);return{packed:r,maxLevel:i,levelCount:r.length?i+1:1}}function Cl(e){let t=e.labelRoom??18,n=Math.max(48,e.baselineY-e.ceilingY-28),r=Math.max(1,e.levelCount),i=Math.min(42,Math.max(26,.18*n)),o=Math.max(24,n-i-t),a=r<=1?o:o/Math.max(1,r-1);return{arcLift:i,levelStep:Math.min(72,Math.max(28,a))}}function Ol(e,t,n,r,i={}){let o=n-(i.footLift??26);return`M${e} ${o}Q${(e+t)/2} ${r} ${t} ${o}`}function Tl(e,t,n){return e-n.arcLift-t*n.levelStep}function Rl(e,t=Ll){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};let n=e.map(e=>new Set(e.map(e=>t(e)))),r=new Set;for(let e of n[0])n.every(t=>t.has(e))&&r.add(e);let i=[],o=new Set;for(let n of e[0]){let e=t(n);r.has(e)&&!o.has(e)&&(i.push(n),o.add(e))}return{shared:i,exclusive:e.map(e=>e.filter(e=>!r.has(t(e))))}}function Ll(e){if(null==e||"object"!=typeof e)return String(e);let t=e;if(null!=t.id)return String(t.id);let n=t.sourceTokenId??t.source,r=t.targetTokenId??t.target,i=t.relation??t.label??"";return`${String(n)}|${String(r)}|${String(i)}`}function Fl(e,t,n){let r=n?.center?.x??0,i=n?.center?.y??0;return{x:r+Math.sin(e)*t,y:i-Math.cos(e)*t}}function Pl(e,t,n){let r=n?.center?.x??0,i=n?.center?.y??0;return(Math.atan2(e-r,-(t-i))+ze)%ze}function zl(e,t){let[n,r]=e,i=r-n||1,o=t?.startAngle??0,a=t?.endAngle??ze;return e=>o+(e-n)/i*(a-o)}function Dl(e,t){let[n,r]=e,[i,o]=t,a=r-n||1;return e=>i+(e-n)/a*(o-i)}function jl(e,t,n,r,i){let o=i?.center,a=(e,t)=>{let{x:n,y:r}=Fl(e,t,{center:o});return`${_l(n)},${_l(r)}`},l=Math.max(0,n),s=Math.max(l,r),d=Math.abs(t-e),c=t>=e?1:0;if(d>=ze-1e-6){let e=o?.x??0,t=o?.y??0,n=`${_l(e)},${_l(t-s)}`,r=`${_l(e)},${_l(t+s)}`,i=`M${n} A${_l(s)},${_l(s)} 0 1 1 ${r} A${_l(s)},${_l(s)} 0 1 1 ${n} Z`;if(l>0){let n=`${_l(e)},${_l(t-l)}`,r=`${_l(e)},${_l(t+l)}`;i+=` M${n} A${_l(l)},${_l(l)} 0 1 0 ${r} A${_l(l)},${_l(l)} 0 1 0 ${n} Z`}return i}let u=d>Math.PI?1:0,h=a(e,s),p=a(t,s);if(l<=0){let e=o?.x??0,t=o?.y??0;return`M${_l(e)},${_l(t)} L${h} A${_l(s)},${_l(s)} 0 ${u} ${c} ${p} Z`}let f=a(t,l),m=a(e,l);return`M${h} A${_l(s)},${_l(s)} 0 ${u} ${c} ${p} L${f} A${_l(l)},${_l(l)} 0 ${u} ${1===c?0:1} ${m} Z`}function _l(e){return Math.round(1e3*e)/1e3}function Wl(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Gl(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Yl(e,t){return{x:e.x*t,y:e.y*t}}function Bl(e){return Math.hypot(e.x,e.y)}function ql(e){let t=Bl(e)||1;return{x:e.x/t,y:e.y/t}}function Vl(e,t){let[n,r]=e.viewBox??De,[i,o]=e.anchor??je,a=r>0?r:1,l=Math.max(0,t)/a,s=(n>0?n:a)*l,d=a*l;return{width:s,height:d,scale:l,offsetX:-i*s,offsetY:-o*d}}function Hl(e,t){let n=Vl(e,t),r=[[n.offsetX,n.offsetY],[n.offsetX+n.width,n.offsetY],[n.offsetX,n.offsetY+n.height],[n.offsetX+n.width,n.offsetY+n.height]],i=0;for(let[e,t]of r){let n=Math.sqrt(e*e+t*t);n>i&&(i=n)}return i}function Ul(e,t,n=0,r="horizontal"){let[i,o]=e.viewBox??De,a=Math.min(1,Math.max(0,n)),l=Math.min(1,Math.max(0,t));return l<=a?{x:0,y:0,width:0,height:0}:a<=0&&l>=1?null:"vertical"===r?{x:0,y:o*(1-l),width:i,height:o*(l-a)}:{x:i*a,y:0,width:i*(l-a),height:o}}var Re=/*#__PURE__*/new e(12),Le={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},Fe=8,Pe=fl,ze=2*Math.PI,De=[40,40],je=[.5,.5];import{jsx as Xl,jsxs as Kl}from"react/jsx-runtime";function Jl(e,t){let n=wn(e,100);return n>0?t/n*100*(t/n):Math.PI*t*t}function Zl(e){let t=[],n=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(n.length>0){let r=e.colorType??"fill",i=n.map(([e,t])=>({label:e,color:t})),o="line"===r?e=>({stroke:e.color??_e,strokeWidth:2,fill:"none"}):e=>({fill:e.color??_e,stroke:e.color??_e});t.push({type:r,label:e.colorLabel??"",items:i,styleFn:o})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){let n=e.symbolColor??_e,r=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:n}));t.push({label:e.symbolLabel??"",items:r,styleFn:()=>({}),type:e=>{let t=e.shape;return Xl("path",{d:xn(t,Jl(t,7)),transform:"translate(8,8)",fill:e.color??n})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){let n=e.sizeRadius,r=e.sizeFormat??(e=>String(e)),i=e.sizeColor??_e,o=e.sizeStops.map(e=>({label:r(e),r:Math.max(.5,n(e)),color:i}));t.push({label:e.sizeLabel??"",items:o,styleFn:()=>({}),type:e=>Xl("circle",{cx:8,cy:8,r:e.r,fill:e.color??i})})}return t}function Ql(e){let t=e.orientation??"vertical",n=e.swatchSize??14,r=e.gap??8,i=e.labelGap??6,o=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",l=n+r,s=0,d=[];return e.entries.forEach((e,c)=>{let u="vertical"===t?0:s,h="vertical"===t?s:0,p=e.color??e.line??a;d.push(Kl("g",{transform:`translate(${u},${h})`,children:[es(e,n,p,a),Xl("text",{x:n+i,y:n/2,dominantBaseline:"middle",fontSize:o,fill:a,children:e.label})]},`legend-${c}`)),s+="vertical"===t?l:n+i+e.label.length*o*.58+r+8}),Xl("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:d},e.keyId)}function es(e,t,n,r){if(e.shape){let r=Jl(e.shape,t/2-1);return Xl("path",{d:xn(e.shape,r),transform:`translate(${t/2},${t/2})`,fill:n})}if(e.hatch){let n=e.color??r;return Kl("g",{children:[Xl("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,r)=>Xl("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:n,strokeWidth:1,opacity:.7},r))}),Xl("rect",{width:t,height:t,fill:"none",stroke:n,strokeWidth:1,opacity:.5,rx:2})]})}return e.line?Xl("rect",{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}):Xl("rect",{width:t,height:t,rx:2,fill:n})}function ts(e){let t=e,n=[os(t,["datum","data"]),os(t,["datum"]),os(t,["data","data"]),os(t,["data"]),os(t,["node","datum","data"]),os(t,["node","datum"]),e];for(let e of n){if(!as(e))continue;let t={};for(let[n,r]of Object.entries(e))n.startsWith("_")||"function"==typeof r||(t[n]=r);if(Object.keys(t).length>0)return t}return null}function ns(e,t={}){let n=ts(e);if(!n)return[];let r=new Set(We);if(t.excludeKeys)for(let e of t.excludeKeys)r.add(e);let i=[];for(let[e,o]of Object.entries(n))if((t.includeInternal||!e.startsWith("_"))&&!r.has(e)&&(t.includeEmpty||null!=o&&""!==o)&&"function"!=typeof o&&(i.push({key:e,label:is(e,t.labels),value:o,formatted:t.valueFormat?t.valueFormat(o,e,n):rs(o)}),i.length>=(t.maxEntries??8)))break;return i}function rs(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?String(e):e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return`${e.length} items`;if("object"==typeof e)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}function is(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){let n=t[e];if("string"==typeof n&&n.length>0)return n}return e}function os(e,t){let n=e;for(let e of t){if(!as(n))return;n=n[e]}return n}function as(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ls(e,t){let n=new Map;for(let t of e)n.set(t.id,new Set);for(let e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target),n.get(e.target).add(e.source);return n}function ss(e,t){let n={};for(let t of e)st(n,t.id,0);for(let e of t)st(n,e.source,(lt(n,e.source)??0)+1),st(n,e.target,(lt(n,e.target)??0)+1);return n}function ds(e,t){let n={};st(n,t,0);let r=[t],i=0;for(;i<r.length;){let t=r[i];i+=1;for(let i of e.get(t)||[])at(n,i)||(st(n,i,n[t]+1),r.push(i))}return n}function cs(e,t,n,r){if(n===r)return n?[n]:[];let i=ls(e,t),o=dt();o[n]=null;let a=[n],l=0;for(;l<a.length;){let e=a[l];if(l+=1,e===r)break;for(let t of i.get(e)||[])at(o,t)||(o[t]=e,a.push(t))}if(!at(o,r))return[];let s=[],d=r;for(;null!=d;)s.unshift(d),d=o[d];return s}function us(e,t,n,r=1){let i=ls(e,t);if(!i.has(n))return new Set;let o=ds(i,n),a=new Set;for(let e of Object.keys(o))o[e]<=r&&a.add(e);return a}function hs(e,t){let n=ls(e,t),r={};for(let t of e)st(r,t.id,0);for(let t of e.map(e=>e.id)){let i=[],o=dt(),a=dt(),l=dt();for(let t of e)o[t.id]=[],a[t.id]=0,l[t.id]=-1;a[t]=1,l[t]=0;let s=[t],d=0;for(;d<s.length;){let e=s[d];d+=1,i.push(e);for(let t of n.get(e)||[])l[t]<0&&(l[t]=l[e]+1,s.push(t)),l[t]===l[e]+1&&(a[t]+=a[e],o[t].push(e))}let c=dt();for(let t of e)c[t.id]=0;for(;i.length;){let e=i.pop();for(let t of o[e])c[t]+=a[t]/a[e]*(1+c[e]);e!==t&&st(r,e,(lt(r,e)??0)+c[e])}}for(let e of Object.keys(r))st(r,e,r[e]/2);return r}function ps(e,t){let n=ls(e,t),r={};for(let t of e){let e=ds(n,t.id),i=0,o=0;for(let t of Object.keys(e))i+=e[t],o+=1;st(r,t.id,i>0?(o-1)/i:0)}return r}function fs(e,t){let n=ls(e,t),r={};for(let t of e){let e=[...n.get(t.id)||[]],i=e.length;if(i<2){st(r,t.id,0);continue}let o=0;for(let t=0;t<e.length;t+=1)for(let r=t+1;r<e.length;r+=1)n.get(e[t])?.has(e[r])&&(o+=1);st(r,t.id,2*o/(i*(i-1)))}return r}function ms(e){let t=0;for(let n of Object.keys(e))e[n]>t&&(t=e[n]);let n={};for(let r of Object.keys(e))st(n,r,t>0?e[r]/t:0);return n}function gs(e,t,n,r={}){let i=ls(e,t),o=dt();for(let t of e)o[t.id]=ds(i,t.id);let a=r.minHops??4,l=r.startThreshold??.08,s=r.maxThreshold??.2,d=new Set,c=0;for(;0===d.size&&c<40;){for(let t=0;t<e.length;t+=1)for(let r=t+1;r<e.length;r+=1){let i=e[t].id,s=e[r].id,c=lt(n,i),u=lt(n,s);if(!c||!u)continue;let h=void 0===o[i][s]?1/0:o[i][s],p=c.x-u.x,f=c.y-u.y,m=Math.sqrt(p*p+f*f);h>=a&&m<l&&(d.add(i),d.add(s))}0===d.size&&(l+=.02,l>s&&(l=r.startThreshold??.08,a=Math.max(2,a-1))),c+=1}return{problemIds:d,threshold:l,minHops:a}}async function ys(e,t,n={}){let{execution:r="auto",signal:i,workerThreshold:o,nodeRadius:a,...l}=n,s=l.iterations??260;if(!ft()||!pt(r,e.length,t.length,s,o))return Jt(e,t,{...l,nodeRadius:a});let d={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:l,nodeRadii:"function"==typeof a?Object.fromEntries(e.map(e=>[e.id,a(e)])):null==a?void 0:Object.fromEntries(e.map(e=>[e.id,a]))};try{let{runForceLayoutWorker:e}=await(import("./c-GTKZNWCF.min.js"));return(await e(d,i)).positions}catch(n){if("AbortError"===n?.name)throw n;return Jt(e,t,{...l,nodeRadius:a})}}function xs(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function bs(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&(null==t.label||"string"==typeof t.label)&&"number"==typeof t.count&&Number.isFinite(t.count)&&Array.isArray(t.bodyIds)&&t.bodyIds.every(e=>"string"==typeof e)}function ws(e,t){if("region-enter"!==t.type)return e;let n=t.region.id,r=xs(e,n),i=bs(r)?r:{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;let o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function Ms(e,t){return(t??Object.keys(e)).map(t=>xs(e,t)).filter(bs).map(e=>({label:e.label??e.id,value:e.count}))}function vs(e,t){let n=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],r=t.filter(e=>!n.has(e)),i=t.length-r.length,o=e.completion?.mode??"allMembersAbsorbed",a=e.completion?.valueByBodyId,l=e=>{let t=a?xs(a,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},s=t.reduce((e,t)=>e+l(t),0),d=t.reduce((e,t)=>e+(n.has(t)?l(t):0),0),c=e.completion?.threshold,u="threshold"===o?Number.isFinite(c)&&Number(c)>=0?Number(c):s:void 0,h=t.length>0&&("anyAbsorbed"===o?i>0:"threshold"===o?d>=(u??s):0===r.length);return{id:e.id,label:e.label??e.id,mode:o,complete:h,absorbed:i,total:t.length,absorbedValue:d,totalValue:s,threshold:u,missing:r}})}function ks(e,t,n,r,i,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:r,y2:i,thickness:o.thickness??8}}}function Is(e,t,n,r){return{type:"aabb",x:e,y:t,width:n,height:r}}function Ss(e){let t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),r=Math.max(1,Math.round(e.height)),i=e.padX??46,o=e.padY??72,a=i,l=n-i,s=o,d=r-Math.max(24,Math.round(.45*o)),c=(s+d)/2,u=Math.max(1,d-s),h=gt(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,m=gt(u*h+f,.06*u,.5*u),g=m/2,y=c-g,x=c+g,b=e.idPrefix??"process",w=e.friction??.58,M=e.restitution??.18,v=e.wallThickness??8,k=e.stages;if(!k.length)throw new Error("processStageLayout requires at least one stage");let I=gt(e.centerStageIndex??Math.floor(k.length/2),0,k.length-1),S=function(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(k),$=l-a,N=a,A=k.map((e,t)=>{let n=(e.share??1)/S*$,r=N,i=t===k.length-1?l:N+n;return N=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:r,x1:i,x:(r+i)/2,width:i-r,y:c,height:u}}),E=A[I],C=E.x0,O=E.x1,T=(e,n)=>{if("lane"===t)return"top"===n?s:d;if("funnel"===t){let t=gt((e-a)/Math.max(1,l-a),0,1);return"top"===n?s+(y-s)*t:d+(x-d)*t}if(e<=C){let t=gt((e-a)/Math.max(1,C-a),0,1);return"top"===n?s+(y-s)*t:d+(x-d)*t}if(e<=O)return"top"===n?y:x;let r=gt((e-O)/Math.max(1,l-O),0,1);return"top"===n?y+(s-y)*r:x+(d-x)*r},R=A.map(e=>{let t=Math.min(T(e.x0,"top"),T(e.x1,"top")),n=Math.max(T(e.x0,"bottom"),T(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),L={thickness:v,friction:w,restitution:M},F=[];"lane"===t?F.push(ks(`${b}-top`,a,s,l,s,L),ks(`${b}-bottom`,a,d,l,d,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,s,l,d,{...L,thickness:Math.max(6,v)})):"funnel"===t?F.push(ks(`${b}-top`,a,s,l,y,L),ks(`${b}-bottom`,a,d,l,x,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,y,l,x,{...L,thickness:Math.max(6,v)})):F.push(ks(`${b}-left-top`,a,s,C,y,L),ks(`${b}-left-bottom`,a,d,C,x,L),ks(`${b}-center-top`,C,y,O,y,L),ks(`${b}-center-bottom`,C,x,O,x,L),ks(`${b}-right-top`,O,y,l,s,L),ks(`${b}-right-bottom`,O,x,l,d,L),ks(`${b}-left`,a,s,a,d,{...L,thickness:Math.max(6,v-2)}),ks(`${b}-right`,l,s,l,d,{...L,thickness:Math.max(6,v)}));let P=e.membraneDampingScale??.5,z=a,D=Math.max(1,("bowtie"===t?C:l)-z),j=(e.membranes??[]).map(e=>{let t=z+gt(e.offset,0,1)*D,n=e.width??18+18*e.cost,r=u-16,i=c+.25*(e.wobble??0);return{...e,x:t,y:i,width:n,height:r}}),_=!1===e.includeMembraneRegions?[]:j.map(e=>Es({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??P,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:r,padX:i,padY:o,left:a,right:l,topY:s,bottomY:d,midY:c,centerLeft:C,centerRight:O,pinchHeight:m,pinchTop:y,pinchBottom:x,stages:R,membranes:j,colliders:F,regionEffects:_,boundaryY:T}}function $s(e,t,n){return"function"==typeof t?r=>({...n,...t(r),primitive:e}):{...n,...t,primitive:e}}function Ns(e,t,n,r){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:Is(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:n?$s(n,e.attributes,r):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function As(e,t={}){let n=t.idPrefix??"stage",r=Math.max(0,t.insetX??0),i=Math.max(0,t.insetY??1);return e.stages.map(e=>{let o="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...Ns({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*r),height:Math.max(1,e.height-2*i),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...o,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function Es(e){let t=e.dampingScale??.5,n=e.energyScale??1,r=gt(e.cost,0,2);return{...Ns(e,"membrane","membrane",{membraneCost:r}),damping:r*t,energyDelta:-r*n}}function Cs(e){return{...Ns(e,"charge-gate","chargeGate"),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function Os(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...Ns(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function Ts(e){let t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,r=e.dampingPerUnit??.12,i=e.energyPerUnit??0;return{...Ns(e,"membrane","pressureField",{pressure:t}),damping:n+t*r,energyDelta:i?-t*i:void 0,force:e.force}}function Rs(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...Ns(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function Ls(e){return{...Ns(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function Fs(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...Ns(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function Ps(e){return{...Ns(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function zs(e){let t=e.x??e.anchor?.x??0,n=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:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function Ds(e){let t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},r=[ks(`${t}-top`,e.left,e.top,e.right,e.top,n),ks(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||r.push(ks(`${t}-left`,e.left,e.top,e.left,e.bottom,n),ks(`${t}-right`,e.right,e.top,e.right,e.bottom,n)),r}function js(e,t,n={}){let r=n.random??Math.random,i=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],o=gt(n.along??.5,.05,.95),a=n.jitterX??0,l=n.padY??20,s=i.x0+(i.x1-i.x0)*o+(2*r()-1)*a,d=Math.min(1,i.width/2),c=gt(s,i.x0+d,i.x1-d),u=e.boundaryY(c,"top")+l,h=e.boundaryY(c,"bottom")-l;return{x:c,y:h<=u?e.midY:u+r()*Math.max(1,h-u)}}function _s(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function Ws(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Gs(e,t,n,r,i){return"function"==typeof r?r(e,t,n):function(e,t){let n=e;for(let e of t.split(".")){if(null==n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}(e,r??i)}function Ys(e){let t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Bs(e,t,n,r){let i=e.flatMap((e,i)=>{let o=Ws(Gs(e,i,t,n,"time")),a=Ws(Gs(e,i,t,r,"value"));return null==o||null==a?[]:[{time:Ys(o),value:a,index:i}]});i.sort((e,t)=>e.time-t.time||e.index-t.index);let o=[];for(let e of i){let t=o[o.length-1];t?.time===e.time?t.value=e.value:o.push({time:e.time,value:e.value})}return o}function qs(e,t,n,r){if(!e.length)return null;let i=e[0],o=e[e.length-1];if(t<i.time)return"clamp"===r?i.value:null;if(t>o.time)return"clamp"===r?o.value:null;let a=function(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i].time<t?n=i+1:r=i}return n}(e,t),l=e[a];if(l?.time===t)return l.value;let s=e[Math.max(0,a-1)];if("step"===n||!l||l.time===s.time)return s.value;let d=(t-s.time)/(l.time-s.time);return s.value+(l.value-s.value)*d}function Vs(e,t){if(1===e.length)return e[0];let n=(e.length-1)*t,r=Math.floor(n),i=Math.ceil(n);if(r===i)return e[r];let o=n-r;return e[r]+(e[i]-e[r])*o}function Hs(e){let t=e.interpolation??"step",n=e.outsideDomain??"omit",r=function(e){let t=(e??Ge).map(e=>{let t=Ws(e);if(null==t||t<0||t>1)throw new RangeError(`physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received ${String(e)}`);return Ys(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),i=function(e){if(Array.isArray(e)){if(e.length>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);return Array.from(new Set(e.map(Ws).filter(e=>null!=e).map(Ys))).sort((e,t)=>e-t)}let t=e,n=Ws(t.start),r=Ws(t.end),i=Ws(t.step);if(null==n||null==r||null==i||i<=0||r<n)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");let o=Math.floor((r-n)/i)+1;if(o>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);let a=[],l=1e-10*Math.max(1,Math.abs(r),Math.abs(n));for(let e=0;e<o;e+=1){let t=n+e*i;if(t>r+l)break;a.push(Ys(Math.min(t,r)))}if((!a.length||Math.abs(a[a.length-1]-r)>l)&&a.push(Ys(r)),a.length>Ye)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ye} points`);return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),o=e.runs.map(t=>Bs(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:i.map(e=>{let i=o.map(r=>qs(r,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(let e of r)a[e]=i.length?Vs(i,e):null;return{time:e,count:i.length,min:i.length?i[0]:null,max:i.length?i[i.length-1]:null,median:i.length?Vs(i,.5):null,quantiles:a}}),quantiles:r,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Us(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function Xs(e,t){if("min"===t||"median"===t||"max"===t)return e[t];let n=Ws(t);if(null==n||n<0||n>1)throw new RangeError(`comparePhysicsTrace quantile selectors must be from 0 to 1; received ${String(t)}`);let r=Ys(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,r))throw new Error(`comparePhysicsTrace could not find quantile ${r} in the reference envelope`);return e.quantiles[r]??null}function Ks(e,t,n){return e<t?"below":e>n?"above":"inside"}function Js(e,t){let n=Math.max(0,t.time-e.time);if(!(n>0)||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};let r=e.value-e.lower,i=t.value-t.lower,o=e.value-e.upper,a=t.value-t.upper,l=[0,1];for(let[e,t]of[[r,i],[o,a]])(e<0&&t>0||e>0&&t<0)&&l.push(-e/(t-e));l.sort((e,t)=>e-t);let s=0,d=0,c=0;for(let r=0;r<l.length-1;r+=1){let i=l[r],o=l[r+1];if(!(o>i))continue;let a=(i+o)/2,u=(o-i)*n,h=Ks(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?s+=u:"above"===h?c+=u:d+=u}return{below:s,inside:d,above:c,observed:n}}function Zs(e,t,n={}){let r=n.interpolation??t.interpolation,i=n.outsideDomain??t.outsideDomain,o=Bs(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),a=n.lower??Us(t,"lower"),l=n.upper??Us(t,"upper"),s=t.points.map(e=>{let t=qs(o,e.time,r,i),n=Xs(e,a),s=Xs(e,l);if(null!=n&&null!=s&&n>s)throw new RangeError(`comparePhysicsTrace lower band exceeds upper band at time ${e.time}`);return{time:e.time,value:t,lower:n,upper:s,status:null==t||null==n||null==s?"unobserved":Ks(t,n,s)}}),d=0,c=0,u=0,h=0,p=null,f=0,m=null;for(let e of s){if("below"===e.status?d+=1:"inside"===e.status?c+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;let t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,p=e.time),n>f&&(f=n,m=e.time)}let g=0,y=0,x=0,b=0;for(let e=0;e<s.length-1;e+=1){let t=s[e],n=s[e+1],i=Math.max(0,n.time-t.time);if(i>0){if("linear"===r){let e=Js(t,n);g+=e.below,y+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=i,"below"===t.status?g+=i:"above"===t.status?x+=i:y+=i)}}let w=s[0]?.time,M=s[s.length-1]?.time,v=null==w||null==M?0:Math.max(0,M-w),k=d+c+u;return{points:s,sampleCount:s.length,observedSamples:k,belowSamples:d,insideSamples:c,aboveSamples:u,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:g,insideDuration:y,aboveDuration:x,peakExcess:h,peakExcessAt:p,peakDeficit:f,peakDeficitAt:m}}function Qs(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function ed(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function td(e){return!!ed(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&ed(e.visitsByStage)&&ed(e.firstEnteredAt)&&ed(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function nd(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function rd(e){let t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,nd(e)]))}}function id(e,t,n={}){if("region-enter"!==t.type)return e;let r=function(e,t){let n=t.stageId?.(e);if(n)return n;let r=e.region.metadata;if(r&&"object"==typeof r&&Object.prototype.hasOwnProperty.call(r,"stageId")){let e=r.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),i=e.stages.findIndex(e=>e.id===r);if(i<0)return e;let o=n.entityId?.(t)??t.bodyId;if(!o)return e;let a=Qs(e.entities,o),l=td(a)?a:nd(o),s=l.currentStageId?e.stages.findIndex(e=>e.id===l.currentStageId):-1,d=!l.visitedStageIds.includes(r),c=Number(t.observation.timestamp),u=Number.isFinite(c)?c:0,h=Qs(l.visitsByStage,r),p="number"==typeof h&&Number.isFinite(h)?h:0,f={...l,currentStageId:r,furthestStageId:i>l.furthestStageIndex?r:l.furthestStageId,furthestStageIndex:Math.max(l.furthestStageIndex,i),visitedStageIds:d?[...l.visitedStageIds,r]:l.visitedStageIds,visitsByStage:{...l.visitsByStage,[r]:p+1},firstEnteredAt:d?{...l.firstEnteredAt,[r]:u}:l.firstEnteredAt,lastEnteredAt:{...l.lastEnteredAt,[r]:u},regressionCount:s>=0&&i<s?l.regressionCount+1:l.regressionCount};return{...e,bodyIds:e.bodyIds.includes(o)?e.bodyIds:[...e.bodyIds,o],entities:{...e.entities,[o]:f}}}function od(e){let t=e.bodyIds.map(t=>{let n=Qs(e.entities,t);return td(n)?n:nd(t)}),n=t.length,r=n;return e.stages.map((e,i)=>{let o=t.filter(e=>e.furthestStageIndex>=i).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,l=t.reduce((t,n)=>{let r=Qs(n.visitsByStage,e.id);return t+("number"==typeof r&&Number.isFinite(r)?r:0)},0),s={id:e.id,label:e.label??e.id,reached:o,entered:a,total:n,conversion:n>0?o/n:0,fromPrevious:r>0?o/r:0,dropoff:Math.max(0,r-o),visits:l,repeatVisits:Math.max(0,l-a)};return r=o,s})}function ad(e,t){if(!t)return;let n=e;for(let e of t.split(".")){if(null==n||"object"!=typeof n||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}function ld(e,t){return!!t?.some(t=>Object.is(e,t))}function sd(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let n=ad(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!ld(n,t.oneOf)||t.notOneOf&&ld(n,t.notOneOf))}function dd(e,t){if("function"==typeof t){let n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}let n=e.datum;if(t&&n&&"object"==typeof n){let e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}let r=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(r)&&r>0?r:1}function cd(e,t){if("function"==typeof t){let n=t(e);if(null!=n&&String(n).length>0)return String(n)}else if(t){let n=ad(e.datum,t),r=ad(e,t),i=n??r;if(null!=i&&String(i).length>0)return String(i)}return e.id}function ud(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.floor(n),i=Math.ceil(n),o=n-r;return e[r]+(e[i]-e[r])*o}function hd(e){let t=e.regionId,n=Math.max(0,e.unitsPerSecond),r=e.queueLayout??"lane",i=e.queueSlotSpacing??14,o=e.queueStiffness??.35,a=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):Number.POSITIVE_INFINITY,l=Math.max(.25,e.metricWindowSeconds??30),s=Math.max(1/60,e.snapshotIntervalSeconds??.25),d=e.releaseImpulse??{x:90,y:0},c=new Map,u=new Map,h=new Map,p=new Map,f=new Map,m=new Map,g=new Map,y=[],x=0,b=new Map,w=new Map,M=0,v=0,k=0,I=null,S=0,$=0,N=0,A=0,E=0,C=0,O=0,T=0,R=0,L=0,F=0,P=0,z=-1,D=!1;function j(e,n){let r=n(e);return!!r&&r.activeRegionIds.includes(t)}function _(){P+=1}function W(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function G(n,r,i,o){let a={bodyId:n.id,jobId:r.jobId,visitId:r.visitId,visit:r.visit,remaining:r.work,total:r.work,queuedAt:r.queuedAt,sequence:o};return c.set(r.jobId,a),g.delete(n.id),m.set(n.id,r.jobId),$+=1,N+=r.work,_(),function(n,r,i){let o=W(r);e.onQueued?.(n,o),i.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:r.total,jobId:r.jobId,visitId:r.visitId,visit:r.visit,queuedAt:r.queuedAt,queueDepth:c.size})}(n,a,i),a}function Y(e){if(c.size>=a||0===u.size)return;let t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(let n of t){if(c.size>=a)break;let t=f.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),g.delete(n.bodyId),G(t,n,e,n.sequence)):u.delete(n.jobId)}}function B(){let e=0;for(let t of c.values())e+=t.remaining;return e}function q(){R=Math.max(R,c.size),L=Math.max(L,B())}function V(){let e=k-l,t=Math.max(0,Math.min(l,k-(I??k))),r=0,i=0,o=0,a=0,s=0;for(let t of y){if(t.end<e)continue;r+=t.arrivals,i+=t.arrivalWork,o+=t.completions,a+=t.completedWork;let n=t.end-t.start;if(n<=0||t.start>=e)s+=t.processedWork;else{let r=Math.max(0,t.end-e);s+=t.processedWork*Math.min(1,r/n)}}let d=t>0?i/t:0;return{seconds:t,arrivals:r,arrivalWork:i,completions:o,completedWork:a,processedWork:s,arrivalsPerSecond:t>0?r/t:0,throughputPerSecond:t>0?o/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,s/(n*t))):0,pressure:n>0?d/n:0}}return{id:e.id??`capacity-queue:${t}`,continuous:!1!==e.continuous,tick:r=>{let i=r.controls.readBodies(),o=new Map,$=new Map;for(let t of i){if(o.set(t.id,t),!j(t.id,r.getRegionState)||!sd(t,e.bodyFilter))continue;let n=cd(t,e.jobKey),i=$.get(n)??[];i.push(t),$.set(n,i)}let N=Number.isFinite(r.dt)?Math.max(0,r.dt):0;if(!D){let e=Number.isFinite(r.elapsed)?Math.max(0,r.elapsed):N;k=Math.max(0,e-N),D=!0}let R=k,L=R+N;k=L,I=null==I?R:Math.min(I,R);let P={start:R,end:L,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},B=new Map;for(let[e,t]of $){let n=h.get(e)?.bodyId,r=t.find(e=>e.id===n)??t[0];B.set(e,r),f.set(e,r)}for(let[n,i]of h){if(B.has(n))continue;let a=c.get(n),l=o.get(i.bodyId)??f.get(n);if(a){c.delete(n),m.delete(a.bodyId),O+=1,T+=a.remaining,_();let o={...W(a),abandonedAt:k,remainingWork:a.remaining,queueSeconds:Math.max(0,k-a.queuedAt)};l&&e.onAbandoned?.(l,o),r.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:i.bodyId,datum:l?.datum,x:l?.x,y:l?.y,regionId:t,work:a.total,remainingWork:a.remaining,jobId:n,visitId:a.visitId,visit:a.visit,queuedAt:a.queuedAt,abandonedAt:k,queueSeconds:o.queueSeconds,queueDepth:c.size})}u.delete(n),g.delete(i.bodyId),h.delete(n),f.delete(n)}for(let[n,i]of B){if(h.has(n))continue;let o=(p.get(n)??0)+1;p.set(n,o);let l=dd(i,e.unitAccessor),s={bodyId:i.id,jobId:n,visitId:`${t}:${n}:${o}`,visit:o,regionId:t,work:l,queuedAt:k};h.set(n,s),S+=1,P.arrivals+=1,P.arrivalWork+=l;let d=x++;if(c.size<a)G(i,s,r,d);else{let a={...s,blockedAt:k,sequence:d};u.set(n,a),g.set(i.id,n),C+=1,_(),e.onBlocked?.(i,a),r.controls.recordObservation({type:"physics-capacity-blocked",bodyId:i.id,datum:i.datum,x:i.x,y:i.y,regionId:t,work:l,jobId:n,visitId:s.visitId,visit:o,queuedAt:k,blockedAt:k,queueDepth:c.size,blockedDepth:u.size})}}Y(r),q();let V=Array.from(c.values()).sort((e,t)=>e.sequence-t.sequence),H=n*N;for(let n of V){if(!(H>0))break;let i=Math.min(n.remaining,H);if(n.remaining-=i,H-=i,A+=i,P.processedWork+=i,n.remaining>1e-6)continue;c.delete(n.jobId),m.delete(n.bodyId),v+=1,E+=n.total,P.completions+=1,P.completedWork+=n.total;let a=Math.max(0,k-n.queuedAt);F+=a,_();let l=o.get(n.bodyId);if(!l)continue;r.controls.applyImpulse(n.bodyId,d.x??0,d.y??0);let s={...W(n),completedAt:k,queueSeconds:a};e.onProcessed?.(l,s),r.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:l.datum,x:l.x,y:l.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:k,queueSeconds:a,queueDepth:c.size})}Y(r),q(),function(){let e=Array.from(c.values()).sort((e,t)=>e.sequence-t.sequence);b=new Map(e.map((e,t)=>[e.bodyId,t]));let t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);w=new Map(t.map((e,t)=>[e.bodyId,t])),M=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&y.push(e);let t=k-l;for(;y.length>0&&y[0].end<t;)y.shift()}(P);let U=Math.floor(k/s);U!==z&&(z=U,_())},getSnapshot:()=>{let e=B(),r=function(){let e=0;for(let t of u.values())e+=t.work;return e}(),i=c.size,o=Array.from(c.values()).map(e=>Math.max(0,k-e.queuedAt)).sort((e,t)=>e-t),a=o.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:i,processedCount:v,unitsPerSecond:n,remainingWork:e,meanRemainingWork:i>0?e/i:0,waitingWork:e+r,blockedDepth:u.size,blockedWork:r,arrivalCount:S,admittedCount:$,admittedWork:N,processedWork:A,completedWork:E,blockedCount:C,abandonedCount:O,abandonedWork:T,peakQueueDepth:R,peakRemainingWork:L,queueAge:{count:o.length,meanSeconds:o.length>0?a/o.length:0,p50Seconds:ud(o,.5),p95Seconds:ud(o,.95),oldestSeconds:o.at(-1)??0},meanCompletedQueueSeconds:v>0?F/v:0,window:V(),simulatedAt:k,metricRevision:P}},bodyForce:e=>{if("none"===r)return null;let n=m.get(e.body.id),a=g.get(e.body.id),l=n?c.get(n):void 0,s=a?u.get(a):void 0;if(!l&&!s)return null;let d=l?b.get(e.body.id):w.get(e.body.id);if(null==d)return null;let h,p=e.regions;if(p)for(let e=0;e<p.length;e+=1)if(p[e].id===t){let t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}if(!h)return{x:8*-Math.sign(e.body.vx||1),y:0};let f=s?h.x-.44*h.width:h.x-.22*h.width-d*(.15*i),y=h.y-(d-((s?u.size:M)-1)/2)*i/Math.max(1,Math.sqrt(s?u.size:M)),x=f-e.body.x,v=y-e.body.y;return{x:x*o,y:v*o*.85}}}}function pd(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function fd(e){if(!e?.length)return null;let t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,r)=>{let i={result:e,controls:n,dt:r.dt,elapsed:r.elapsed,getRegionState:r.getRegionState};for(let e of t)e.tick(i)},bodyForce:e=>{let n=null;for(let r of t)r.bodyForce&&(n=pd(n,r.bodyForce(e)));return n}}}function md(e){let t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??`portal:${e.fromRegionId}`,continuous:!0===e.continuous,tick:r=>{let i=r.controls.readBodies();for(let o of i)r.getRegionState(o.id)?.activeRegionIds.includes(e.fromRegionId)?t.has(o.id)||(t.add(o.id),r.controls.applyImpulse(o.id,n.x??0,n.y??0),e.onPortal?.(o)):t.delete(o.id)}}}function gd(e){let t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),r=new Map,i=new Map,o=e.assignmentForce??.45,a=e.returnForce??.35,l=e.caseAttraction??.08,s=e.assignmentOffset??{x:0,y:0},d=new Map,c=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{let n=r.get(e);if(n)return n;let o=t.find(e=>!i.has(e.id));if(!o)return null;let a={resourceId:o.id,resourceBodyId:o.bodyId,caseBodyId:e,assignedAt:c};return r.set(e,a),i.set(o.id,a),u+=1,a},release:e=>{let t=r.get(e);return!!t&&(r.delete(e),i.delete(t.resourceId),u+=1,!0)},getAssignment:e=>r.get(e),tick:e=>{c=Math.max(c,e.elapsed),d=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(let[e,t]of r)d.has(e)&&d.has(t.resourceBodyId)||(r.delete(e),i.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-i.size,assigned:i.size,assignments:Array.from(r.values()),simulatedAt:c,metricRevision:u}),bodyForce:e=>{let t=n.get(e.body.id);if(t){let n=i.get(t.id),r=n?d.get(n.caseBodyId):void 0,l=r?r.x+(s.x??0):t.home.x,c=r?r.y+(s.y??0):t.home.y,u=n?o:a;return{x:(l-e.body.x)*u,y:(c-e.body.y)*u}}let c=r.get(e.body.id);if(!c||l<=0)return null;let u=d.get(c.resourceBodyId);return u?{x:(u.x-e.body.x)*l,y:(u.y-e.body.y)*l}:null}}}function yd(e,t){let n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):ad(e.datum,t.deadlineAccessor)??ad(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function xd(e){let t=new Map,n=0,r=0;function i(n){t.set(n.bodyId,n),r+=1,e.onStateChange?.({...n})}function o(e){let r=t.get(e);return!(!r||null!=r.completedAt||(i({...r,completedAt:n,state:"unhappy"===r.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{let r=t.get(e);return!(!r||null!=r.completedAt||"unhappy"===r.state||(i({...r,state:"protected",protectedAt:n}),0))},complete:o,getCase:e=>t.get(e),tick:r=>{n=Math.max(n,r.elapsed);for(let a of r.controls.readBodies()){if(!sd(a,e.bodyFilter))continue;if(!t.has(a.id)){let t=yd(a,e);i({bodyId:a.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}let l=t.get(a.id);l&&null==l.completedAt&&(e.completionRegionId&&r.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?o(a.id):"waiting"===l.state&&n>=l.deadlineAt&&i({...l,state:"unhappy"}))}},getSnapshot:()=>{let e=Array.from(t.values()),i=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:i("waiting"),protected:i("protected"),unhappy:i("unhappy"),resolved:i("resolved"),resolvedUnhappy:i("resolved-unhappy"),simulatedAt:n,metricRevision:r}}}}function bd(e){let t=new Set,n=0,r=0,i=0,o=!1;return{id:e.id??`dependency-gate:${e.regionId}`,continuous:!0,tick:a=>{n=Math.max(n,a.elapsed);let l=o;o=function(t){return e.isOpen?e.isOpen(t):null!=e.opensAt&&t>=e.opensAt}(n);let s=a.controls.readBodies(),d=new Map(s.map(e=>[e.id,e]));for(let n of s)!a.getRegionState(n.id)?.activeRegionIds.includes(e.regionId)||!sd(n,e.bodyFilter)||!o&&!t.has(n.id)&&(t.add(n.id),i+=1,e.onHeld?.(n));if(o&&!l){for(let n of t){let t=d.get(n);t&&(a.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),r+=1,e.onReleased?.(t))}t.clear(),i+=1}for(let e of t)d.has(e)||(t.delete(e),i+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:o,blocked:t.size,released:r,simulatedAt:n,metricRevision:i}),bodyForce:n=>{if(o||!t.has(n.body.id))return null;let r=n.regions?.find(t=>t.id===e.regionId)?.shape;if(!r||"aabb"!==r.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};let i=e.holdForce??.4;return{x:(r.x-n.body.x)*i-.45*n.body.vx,y:(r.y-n.body.y)*i-.45*n.body.vy}}}}_e="var(--semiotic-text, currentColor)",We=/*#__PURE__*/new Set(["rows"]),Number.POSITIVE_INFINITY,Ge=[.1,.5,.9],Ye=1e6;import{createElement as wd}from"react";import{Children as Md,cloneElement as vd,isValidElement as kd,useId as Id}from"react";function Sd(e,t,n,r){let i=e=>n.get(e)??e;return"id"===e?i(t):/^(?:xlink:?)?href$/i.test(e)?"#"===t[0]?`#${i(t.slice(1))}`:t:/^(?:aria-(?:labelledby|describedby|controls|owns|activedescendant|details|errormessage)|for|htmlFor|list|form|headers|itemref|popovertarget)$/.test(e)?t.replace(/\S+/g,i):/^(?:fill|stroke|clip-?path|mask|filter|marker-?(?:start|mid|end)|style|cursor)$/i.test(e)?r?r(t,n):t.replace(/url\(\s*(["']?)#([^\s"')]+)\1\s*\)/g,(e,t,n)=>{let r=i(n);return r===n?e:`url(#${r})`}):t}function $d({children:e}){let t=Id().replace(/[^\w-]/g,"_"),n=new Map,r=(e,t=!1)=>{let o={...e};for(let[e,a]of Object.entries(o))o[e]="children"!==e||t?"style"===e&&!t&&a&&"object"==typeof a?r(a,!0):"string"==typeof a?Sd(t?"style":e,a,n):a:i(a);return o},i=(e,o=!1)=>"object"!=typeof e?e:Md.map(e,e=>kd(e)?o?("string"==typeof e.props.id&&n.set(e.props.id,`${t}-${e.props.id}`),i(e.props.children,!0),e):vd(e,r(e.props)):e);return i(e,!0),i(e)}import{Fragment as Nd,jsx as Ad,jsxs as Ed}from"react/jsx-runtime";function Cd(e){return 6.2*e.length}function Od(e,t){let n=e.trim();if(n.length<=t)return n;if(t<=1)return n.slice(0,1);let r=n.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return r.length>1&&r.length<=t?r:t<=3?n.slice(0,t).toUpperCase():`${n.slice(0,Math.max(1,t-2))}..`}function Td(e,t,n="auto"){let r=Math.max(1,Math.floor(t/6.2)),i="compact"===n?Od(e,r):"full"===n||Cd(e)<=t?e:Od(e,r);return{text:i,textLength:Cd(i)>t?Math.max(4,t):void 0}}function Rd(e,t={}){let{showFlowSpine:n=!0,showStageCounts:r=!0,showCapacityBadges:i=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:l=!1,testId:s="process-flow-chrome"}=t,{width:d,height:c,left:u,right:h,topY:p,bottomY:f,midY:m,stages:g,groups:y=[]}=e,x=f-p;return wd($d,null,Ed("svg",{"aria-hidden":"true","data-testid":s,"data-outline-stages":l?"true":void 0,width:d,height:c,viewBox:`0 0 ${d} ${c}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",l?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Ad("defs",{children:Ed("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Ad("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Ad("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Ad("rect",{x:0,y:0,width:d,height:c,fill:"url(#semiotic-process-floor)"}),Ad("rect",{x:u-6,y:p-8,width:h-u+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}),n?Ad("line",{x1:u+8,x2:h-8,y1:m,y2:m,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,g.map((e,t)=>{let n=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),o=Be[n],s=Math.max(12,e.width-8),d=gt(s-8,22,88),u=Math.max(8,d-10),h=Td(e.label,u,a),y="none"!==a&&s-8>=22,b=function(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"}(e),w=Td(b,Math.max(16,s-10),"auto"),M=i&&!1!==e.showBadge&&s>=32,v=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",k=Td(v,Math.max(16,s-8),"auto"),I=Math.max(30,p-15),S=I-13;return Ed("g",{"data-stage":e.id,"data-role":n,children:[Ad("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:s,height:x-12,rx:10,fill:l?"none":o.fill,stroke:o.stroke,strokeWidth:l?1.85:"flow"===n?1:1.6}),t<g.length-1?Ad("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:o.accent,opacity:.85}):null,y?Ed(Nd,{children:[Ad("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-d/2,y:S,width:d,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),Ed("text",{x:e.x,y:I,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:[Ad("title",{children:e.label}),h.text]})]}):null,M?Ed("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:w.textLength,lengthAdjust:w.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:b}),w.text]}):null,r&&null!=e.count?Ed("text",{x:e.x,y:Math.min(c-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:v}),k.text]}):null]},e.id)}),o?y.map((e,t)=>{let n=e.total??0,r=e.absorbed??0,i=e.complete??(n>0&&r>=n),o=!i&&n>0&&r/n>=.75,a=i?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",l=i?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",s=n>0?`${r}/${n}${i?" shipped":o?" almost":""}`:`feature ${t+1}`,d=gt(Math.max(54,Cd(e.label)+18,Cd(s)+16),54,104),c=Td(e.label,d-12,"auto"),u=Td(s,d-12,"auto");return Ed("g",{"data-group":e.id,children:[Ad("rect",{x:e.x-d/2,y:e.y-22,width:d,height:44,rx:10,fill:a,stroke:l,strokeWidth:1.5}),Ed("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:c.textLength,lengthAdjust:c.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:e.label}),c.text]}),Ed("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:l,fontSize:9,fontWeight:700,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Ad("title",{children:s}),u.text]})]},e.id)}):null]}))}function Ld(e){let[t,n]=e.size,r=e.flow??"down",i=function(e){return null==e?{top:24,right:24,bottom:24,left:24}:"number"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}(e.padding),o=Math.max(.05,Math.min(1,e.channelRatio??1)),a={x:i.left,y:i.top,width:Math.max(1,t-i.left-i.right),height:Math.max(1,n-i.top-i.bottom)},l="down"===r?a.height:a.width,s=l*Math.max(0,e.chargeExtent??.12),d=l*Math.max(0,e.projectionExtent??0),c=l*Math.max(0,e.destinationExtent??.55),u=Math.max(0,l-s-c-d),h=function(e){if("number"==typeof e){let t=Math.max(1,Math.round(e));return Array.from({length:t},(e,t)=>({id:`bin-${t}`,label:String(t)}))}return 0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??String(t)}))}(e.destinations),p=("down"===r?a.width:a.height)/h.length,f="down"===r?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),m=f(0,s),g=f(s,u),y=s+u,x=f(y,c),b=f(y+c,d),w=h.map((e,t)=>{let n=t*p,i=p*o,l=(p-i)/2;if("down"===r){let r=a.x+n+l;return{id:e.id,label:e.label,order:t,x:r,y:x.y,width:i,height:x.height,centerX:a.x+(t+.5)*p,centerY:x.y+x.height/2}}let s=a.y+n+l;return{id:e.id,label:e.label,order:t,x:x.x,y:s,width:x.width,height:i,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*p}});return{width:t,height:n,flow:r,charge:m,apparatus:g,destinations:w,projection:b}}function Fd(e,t){return e.destinations.find(e=>e.id===t)}function Pd(e,t,n){let{charge:r,flow:i}=e,o=Math.max(1,n),a=(t%o+.5)/o;return"down"===i?{x:r.x+r.width*a,y:r.y+r.height/2}:{x:r.x+r.width/2,y:r.y+r.height*a}}function zd(e,t={}){let n=t.thickness??4,r=t.idPrefix??"stage",{destinations:i,flow:o,width:a,height:l}=e,s=[];if(i.length>0){let t=i[0];if("down"===o){let o=t.y+t.height;s.push({id:`${r}-floor`,shape:{type:"segment",x1:e.charge.x,y1:o,x2:e.charge.x+e.charge.width,y2:o,thickness:n}});for(let e=1;e<i.length;e+=1){let a=i[e].centerX-(i[e].centerX-i[e-1].centerX)/2;s.push({id:`${r}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:o,thickness:n}})}}else{let o=t.x+t.width;s.push({id:`${r}-floor`,shape:{type:"segment",x1:o,y1:e.charge.y,x2:o,y2:e.charge.y+e.charge.height,thickness:n}});for(let e=1;e<i.length;e+=1){let a=i[e].centerY-(i[e].centerY-i[e-1].centerY)/2;s.push({id:`${r}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:o,y2:a,thickness:n}})}}}return!1!==t.walls&&s.push({id:`${r}-wall-left`,shape:{type:"segment",x1:1,y1:0,x2:1,y2:l,thickness:n}},{id:`${r}-wall-right`,shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:l,thickness:n}}),s}function Dd(e,t={}){let n=t.charge??"bodies",r=t.apparatus??"the apparatus",i=t.destination??"destinations",o=e.destinations.length,a="down"===e.flow?"downward":"left to right";return`${n} enter at the ${"down"===e.flow?"top":"left"}, travel ${a} through ${r}, and come to rest in ${o} ${i}: ${e.destinations.map(e=>e.label).join(", ")}.`}function jd(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function _d(e,t,n,r){let i="function"==typeof e?e(t,n):e;return Number.isFinite(i)?Number(i):r}function Wd(e,t,n){return jd(e[t])??n}function Gd(e,t){return"number"==typeof e?e:e?.[t]??0}function Yd(e){let{band:t,idPrefix:n,plot:r,projection:i}=e,{includeBoundaryWalls:o=!0,includeInteriorWalls:a=!0,wallThickness:l=4}=t,s=function(e){let t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(let r of e.values){let i=e.scale(r);Number.isFinite(i)&&(n.add(Number(i)),n.add(Number(i)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(s.length<2)return[];let d=o?0:1,c=o?s.length-1:s.length-2,u=[];for(let e=d;e<=c;e+=1){if(!a&&e>0&&e<s.length-1)continue;let t=s[e];u.push({id:`${n}-wall-${e}`,shape:"x"===i?{type:"aabb",x:t,y:r.y+r.height/2,width:l,height:r.height}:{type:"aabb",x:r.x+r.width/2,y:t,width:r.width,height:l}})}return u}function Bd(e){let{plot:t,idPrefix:n="physics-scale",bounds:r={},xBins:i,xBands:o,yBands:a}=e,l=[];if(!1!==r&&l.push(...function(e,t={}){let{idPrefix:n="plot",includeFloor:r=!0,includeCeiling:i=!1,includeLeftWall:o=!0,includeRightWall:a=!0,wallThickness:l=20,floorThickness:s=l}=t,d=[],c=e.x+e.width/2,u=e.y+e.height/2,h=(e,t,r,i,o)=>{d.push({id:`${n}-${e}`,shape:{type:"aabb",x:t,y:r,width:i,height:o}})};return r&&h("floor",c,e.y+e.height+s/2,e.width+2*l,s),i&&h("ceiling",c,e.y-s/2,e.width+2*l,s),o&&h("left-wall",e.x-l/2,u,l,e.height+2*s),a&&h("right-wall",e.x+e.width+l/2,u,l,e.height+2*s),d}(t,{idPrefix:n,...r})),i){let{idPrefix:e,yTop:r,yBottom:o,...a}=i;l.push(...function(e){let{idPrefix:t="bin",count:n,domainStart:r,domainStep:i,xScale:o,yTop:a,yBottom:l,wallThickness:s=4,includeBoundaryWalls:d=!0,includeInteriorWalls:c=!0,closedBefore:u,lidY:h=a,lidThickness:p=Math.max(2,s)}=e,f=[],m=a+(l-a)/2,g=Math.abs(l-a),y=d?n:n-1;if(c||d)for(let e=d?0:1;e<=y;e+=1){if(!c&&e>0&&e<n)continue;let a=o(r+e*i);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:a,y:m,width:s,height:g}})}if(null!=u)for(let e=0;e<n;e+=1){let n=r+e*i,a=n+i;if(a>=u)continue;let l=o(n),d=o(a);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(l,d)+s/2,y1:h,x2:Math.max(l,d)-s/2,y2:h,thickness:p}})}return f}({...a,idPrefix:e??`${n}-xbin`,yTop:r??t.y,yBottom:o??t.y+t.height}))}return o&&l.push(...Yd({band:o,idPrefix:o.idPrefix??`${n}-xband`,plot:t,projection:"x"})),a&&l.push(...Yd({band:a,idPrefix:a.idPrefix??`${n}-yband`,plot:t,projection:"y"})),l}function qd(e){let{plot:t,rows:n,columns:r=n+1,pegRadius:i=3,idPrefix:o="galton-peg",yStart:a=t.y+.18*t.height,yEnd:l=t.y+.58*t.height,stagger:s=!0,restitution:d=.2,friction:c=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(r));if(0===u)return[];let p=u<=1?0:(l-a)/(u-1),f=t.width/h,m=[];for(let e=0;e<u;e+=1){let n=s&&e%2==1?f/2:0;for(let r=0;r<h;r+=1){let l=t.x+f*(r+.5)+n;l<t.x+i||l>t.x+t.width-i||m.push({id:`${o}-${e}-${r}`,shape:{type:"aabb",x:l,y:a+e*p,width:2*i,height:2*i},restitution:d,friction:c})}}return m}function Vd(e,t={}){let{idPrefix:n="physics-token",radius:r=5,shape:i,mass:o,vx:a,vy:l,spawnAt:s,seed:d=1,jitter:c,datum:u}=t,h=Kt(d),p=Gd(c,"x"),f=Gd(c,"y");return e.map((e,d)=>{let c=_d(t.x,e,d,Wd(e,"x",0)),m=_d(t.y,e,d,Wd(e,"y",0)),g=_d(r,e,d,5),y="function"==typeof i?i(e,d):i??{type:"circle",radius:g};return{id:`${n}-${e.index??d}`,x:c+(h()-.5)*p,y:m+(h()-.5)*f,vx:_d(a,e,d,0),vy:_d(l,e,d,0),mass:_d(o,e,d,1),spawnAt:_d(s,e,d,void 0),shape:y,datum:u?u(e,d):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;let{spawnAt:t,...n}=e;return n})}function Hd(e,t={}){let{idPrefix:n="sediment",collider:r=!0,colliderThickness:i=1,restitution:o=.05,friction:a=.2,...l}=t,s=function(e,t={}){let{baselineY:n=0,binWidth:r=24,gap:i=2,maxHeight:o=80,value:a="count",x:l}=t,s=e.reduce((e,t)=>Math.max(e,t[a]),1);return e.map((e,t)=>{let d=Math.max(0,e[a]/s*o),c=l?.(e,t)??t*(r+i);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:c,y:n-d,width:r,height:d,meanX:e.x.mean,meanY:e.y.mean}})}(e,l),d=r?s.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+i/2,width:e.width,height:i},restitution:o,friction:a})):[];return{columns:s,colliders:d}}function Ud(e,t={}){let{timeAccessor:n="arrivalTime",timeScale:r=1,startAt:i=0,rebase:o=!0,sort:a=!0}=t,l=e.map((e,t)=>{let r=function(e,t,n){return jd("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t;return{spawn:e,time:r}}),s=l.length?ut(l.map(e=>e.time)):0;return{initialSpawns:l.map(({spawn:e,time:t})=>({...e,spawnAt:i+(o?t-s:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:i,timeAccessor:"spawnAt",timeScale:r}}}function Xd(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function Kd(e,t,n="group"){let r=ss(e,t),i=e=>"function"==typeof n?n(e):e[n]??0;return e.slice().sort((e,t)=>{let n=i(e),o=i(t);return n<o?-1:n>o?1:(r[t.id]||0)-(r[e.id]||0)}).map(e=>e.id)}function Jd(e,t={}){let n=t.baseline??.62,r=t.inset??.06,i={},o=e.length;return e.forEach((e,t)=>{Xd(i,e,{x:o>1?r+t/(o-1)*(1-2*r):.5,y:n})}),i}function Zd(e,t,n=.55){let r=Math.abs(t.x-e.x),i=(e.x+t.x)/2,o=e.y-r*n;return`M${e.x},${e.y} Q${i},${o} ${t.x},${t.y}`}function Qd(e,t={}){let n=t.radius??.42,r=t.center?.x??.5,i=t.center?.y??.5,o=t.startAngle??0,a={},l=e.length;return e.forEach((e,t)=>{let s=o+t/l*Math.PI*2-Math.PI/2;Xd(a,e,{x:r+Math.cos(s)*n,y:i+Math.sin(s)*n})}),a}function ec(e,t,n={}){let r=(n.order??Kd(e,t,n.groupAccessor??"group")).slice(),i=new Map(r.map((e,t)=>[e,t])),o=new Map;for(let e of t){if(!i.has(e.source)||!i.has(e.target)||e.source===e.target)continue;let t=e.source<e.target?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;o.set(t,(o.get(t)||0)+(e.value??1))}let a=[],l=0;for(let[e,t]of o){let[n,r]=e.split("\0"),o=i.get(n),s=i.get(r);t>l&&(l=t),a.push({row:o,col:s,source:n,target:r,value:t}),a.push({row:s,col:o,source:r,target:n,value:t})}return{order:r,cells:a,size:r.length,maxValue:l}}function tc(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function nc(e){if("string"!=typeof e)return;let t=e.trim();return t.length?t:void 0}function rc(e,t){let n=tc(e.note)?e.note:void 0;return t?nc(e.mobileText)||nc(e.shortText)||nc(e.label)||nc(n?.mobileText)||nc(n?.shortText)||nc(n?.label)||nc(n?.title):nc(e.label)||nc(e.mobileText)||nc(e.shortText)||nc(n?.label)||nc(n?.title)}function ic(e,t,n){let r=function(e,t,n){if(!n)return;let r="function"==typeof n?n(e,t):e[n];return"number"==typeof r&&Number.isFinite(r)?r:void 0}(e,t,n.priorityAccessor);if(void 0!==r)return r;let i=1e3-t,o=String(e.emphasis??"").toLowerCase();("primary"===o||"critical"===o)&&(i+=1e4),"secondary"===o&&(i-=1e3),"high"===e.priority&&(i+=5e3),"low"===e.priority&&(i-=1500),"number"==typeof e.priority&&(i+=100*e.priority);let a=tc(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(i+=100*a.confidence);let l=tc(e.lifecycle)?e.lifecycle:void 0,s=String(l?.freshness??"").toLowerCase();return("expired"===s||"stale"===s)&&(i-=3e3),i}function oc(e,t){if(!t)return e;let n=rc(e,!0);return n&&"string"==typeof e.label?{...e,label:n}:e}function ac(e,t={}){let n=Array.isArray(e)?e.filter(tc):[],r=t.breakpoint??480,i=t.active??(null==t.width||t.width<=r),o=t.strategy??"hybrid",a=!1!==t.preferShortText,l=!1!==t.preservePrimary,s=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===o?1:2)),d=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!i||"plot"===o)return{active:i,strategy:o,budget:n.length,visible:a?n.map(e=>oc(e,a)):n,deferred:[],calloutList:[],hidden:[]};let c=[],u=n.map((e,n)=>({annotation:e,index:n,priority:ic(e,n,t)})).filter(e=>!!ia(e.annotation)||(c.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),h=l?u.filter(e=>"primary"===String(e.annotation.emphasis??"").toLowerCase()):[],p=new Set(h.map(e=>e.index)),f=u.filter(e=>!p.has(e.index)),m=[...h,...f].slice(0,Math.max(s,d)),g=new Set(m.map(e=>e.index)),y=u.filter(e=>!g.has(e.index)),x=[...c,...m.sort((e,t)=>e.index-t.index).map(e=>oc(e.annotation,a))],b=y.sort((e,t)=>e.index-t.index).map(e=>e.annotation),w=Math.max(0,t.maxCalloutItems??6),M=y.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,n,r){let i=rc(e,r);if(!i)return null;let o=nc(e.id)||nc(e.key)||nc(e.pointId)||`annotation-${t+1}`,a=tc(e.provenance)?nc(e.provenance.source)||nc(e.provenance.authorKind):void 0;return{id:o,label:i,shortLabel:nc(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:n,annotation:e}}(e.annotation,e.index,e.priority,a)).filter(e=>!!e).slice(0,w),v=new Set(M.map(e=>e.annotation)),k=b.filter(e=>!v.has(e));return{active:i,strategy:o,budget:s,visible:x,deferred:b,calloutList:M,hidden:k}}function lc(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function sc(e,t){let n=!1!==t.keepAxes,r=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:r,bottom:n?44:12,left:n?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:r,bottom:n?42:14,left:n?44:14}}function dc(e,t,n,r={}){let i={...n},o={mode:!1===t.mode?void 0:"mobile",...i,margin:sc(e,t),...r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),l=Object.fromEntries(Object.entries(o).filter(([,e])=>void 0!==e)),s=function(e,t){let n=t.targetSize??44,r=[],i=t.standardControls,o=e=>!0===i||"all"===i||i===e||Array.isArray(i)&&i.includes(e);return o("brush")&&r.push("range-inputs","clear-brush"),o("zoom")&&r.push("zoom-buttons","reset-view"),o("legend")&&r.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:n,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:n,...r.length>0&&{alternatives:r}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),d=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:`${e}-mobile`,description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...l,mobileInteraction:d,mobileSemantics:s}}],mobileInteraction:d,mobileSemantics:s}}function cc(e={}){let t=lc(e);return dc("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function uc(e={}){let t=lc(e);return dc("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function hc(e={}){return dc("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function pc(e={}){let t=lc(e);return dc("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function fc(e={}){let t=lc(e);return dc("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function mc(e={}){return dc("geo",e,{showLegend:e.showLegend??!1})}function gc(e={}){return dc("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function yc(e,t={}){switch(e){case"line":return cc(t);case"area":return uc(t);case"ordinal":return hc(t);case"scatter":return pc(t);case"network":return fc(t);case"geo":return mc(t);case"small-multiple":return gc(t)}}function xc(e={}){let t=e.targetSize??44,n=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:t,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:n,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:n}}function bc(e){return JSON.stringify([e.nodeId,e.endpoint.kind,"part"===e.endpoint.kind?e.endpoint.partId:null,e.endpoint.portId??null])}function wc(e,t=qe){return{nodeId:e,endpoint:t}}function Mc(e,t){return e<t?-1:e>t?1:0}function vc(e){return Array.isArray(e)?`[${e.map(vc).join(",")}]`:e&&"object"==typeof e?`{${Object.entries(e).filter(([,e])=>void 0!==e).sort(([e],[t])=>Mc(e,t)).map(([e,t])=>`${JSON.stringify(e)}:${vc(t)}`).join(",")}}`:JSON.stringify(e)??"null"}function kc(e){if(e&&"object"==typeof e&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))kc(t)}return e}function Ic(e,t,n={}){throw new Ve([{code:e,message:t,severity:"error",...n}])}function Sc(e,t){let n=new Map;for(let r of e)("string"!=typeof r.id||!r.id||n.has(r.id))&&Ic("IDENTITY_DUPLICATE_OR_EMPTY",`IDs must be nonempty and unique in ${t}.`),n.set(r.id,r);return n}function $c(e,t){let n=new Set;for(let r of e.keys()){let i=new Set,o=r;for(;void 0!==o&&!n.has(o);){i.has(o)&&Ic("IDENTITY_CONTAINMENT_CYCLE","Containment must be acyclic.");let n=e.get(o);n||Ic("IDENTITY_UNKNOWN_PARENT","Containment references an unknown parent."),i.add(o),o=t(n)}i.forEach(e=>n.add(e))}}function Nc(e,t,n){let r=e.get(t.nodeId);r||Ic("ENDPOINT_UNKNOWN_OWNER","Endpoint owner does not exist.",{endpointRefs:[t]});let i=t.endpoint;"node"!==i.kind&&"part"!==i.kind&&Ic("ENDPOINT_KIND","Unknown endpoint kind.");let o="part"===i.kind?r.parts?.find(e=>e.id===i.partId):void 0;if("part"===i.kind&&!o&&Ic("ENDPOINT_UNKNOWN_PART","Endpoint part does not exist.",{endpointRefs:[t]}),void 0===i.portId)return;let a=(o?o.ports:r.ports)?.find(e=>e.id===i.portId);a||Ic("ENDPOINT_UNKNOWN_PORT","Endpoint port does not exist.",{endpointRefs:[t]});let l="source"===n||"transfer-target"===n?"out":"in";return n&&a.direction!==l&&"inout"!==a.direction&&Ic("ENDPOINT_DIRECTION","Port direction is incompatible with its use.",{endpointRefs:[t]}),a}function Ac(e,t,n){let r=e.get(t)??[];r.push(n),e.set(t,r)}function Ec(e){let t=He.get(e);if(t)return t;let n=e.graph,r={nodes:new Map(n.nodes.map(e=>[e.id,e])),endpoints:new Map,ownerEndpoints:new Map,tracePolicies:new Map,incoming:new Map,outgoing:new Map,transferIn:new Map,transferOut:new Map},i=e=>{let t=bc(e);return r.endpoints.has(t)||Ac(r.ownerEndpoints,e.nodeId,e),r.endpoints.set(t,e),t},o=new Set(n.transfers?.map(e=>e.nodeId));for(let e of[...n.nodes].sort((e,t)=>Mc(e.id,t.id))){r.tracePolicies.set(e.id,e.tracePolicy??(e.parts?.length||e.ports?.length||o.has(e.id)?"explicit":"atomic")),i(wc(e.id));for(let t of e.ports??[])i(wc(e.id,{kind:"node",portId:t.id}));for(let t of e.parts??[]){i(wc(e.id,{kind:"part",partId:t.id}));for(let n of t.ports??[])i(wc(e.id,{kind:"part",partId:t.id,portId:n.id}))}}for(let e of[...n.edges].sort((e,t)=>Mc(e.id,t.id)))Ac(r.outgoing,i(wc(e.source,e.sourceEndpoint)),e),Ac(r.incoming,i(wc(e.target,e.targetEndpoint)),e);for(let e of[...n.transfers??[]].sort((e,t)=>Mc(e.id,t.id))){Ac(r.transferIn,i(wc(e.nodeId,e.target)),e);for(let t of e.sources)Ac(r.transferOut,i(wc(e.nodeId,t)),e)}for(let e of r.ownerEndpoints.values())e.sort((e,t)=>Mc(bc(e),bc(t)));return He.set(e,r),r}function Cc(e){"semiotic.compositional-graph.v0.1"!==e.schemaVersion&&Ic("IDENTITY_SCHEMA","Unknown graph schema."),("string"!=typeof e.graphId||!e.graphId||"string"!=typeof e.revision||!e.revision)&&Ic("IDENTITY_REVISION","Graph ID and revision are required.");let t=Sc(e.nodes,"nodes");Sc(e.edges,"edges"),Sc(e.transfers??[],"transfers"),$c(t,e=>e.parentId);let n,r=(e=[])=>{Sc(e,"ports");for(let t of e)["in","out","inout"].includes(t.direction)||Ic("ENDPOINT_DIRECTION","Unknown port direction.")};for(let e of t.values()){e.tracePolicy&&!["atomic","explicit","opaque"].includes(e.tracePolicy)&&Ic("TRACE_POLICY","Unknown trace policy."),r(e.ports);let t=Sc(e.parts??[],"owner parts");$c(t,e=>e.parentPartId);for(let e of t.values())r(e.ports)}for(let n of e.edges)Nc(t,wc(n.source,n.sourceEndpoint),"source"),Nc(t,wc(n.target,n.targetEndpoint),"target");for(let n of e.transfers??[])(!n.sources.length||!["identity","all","any","unspecified"].includes(n.combination)||"identity"===n.combination&&1!==n.sources.length)&&Ic("ENDPOINT_TRANSFER","Transfers need inputs and a valid combination; identity needs one input."),new Set(n.sources.map(e=>bc(wc(n.nodeId,e)))).size!==n.sources.length&&Ic("ENDPOINT_TRANSFER","Transfer inputs must be distinct."),n.sources.forEach(e=>Nc(t,wc(n.nodeId,e),"transfer-source")),Nc(t,wc(n.nodeId,n.target),"transfer-target");try{n=JSON.parse(JSON.stringify(e,(e,t)=>{if("function"==typeof t||"symbol"==typeof t||"bigint"==typeof t||"number"==typeof t&&!Number.isFinite(t))throw new Error("Non-JSON value");return t}))}catch{Ic("IDENTITY_NONPORTABLE","Graph must be serializable JSON.")}let i=e=>[...e].sort((e,t)=>Mc(e.id,t.id)),o=kc({schemaVersion:"semiotic.prepared-compositional-graph.v0.1",graph:n,semanticHash:vc({graphId:n.graphId,nodes:i(n.nodes).map(({id:e,parentId:t,tracePolicy:n,ports:r,parts:o})=>({id:e,parentId:t,tracePolicy:n,ports:i(r??[]).map(({id:e,direction:t})=>({id:e,direction:t})),parts:i(o??[]).map(({id:e,parentPartId:t,ports:n})=>({id:e,parentPartId:t,ports:i(n??[]).map(({id:e,direction:t})=>({id:e,direction:t}))}))})),edges:i(n.edges).map(({data:e,...t})=>t),transfers:i(n.transfers??[])}),diagnostics:[]});return Ec(o),o}function Oc(e,t){(t.baseRevision!==e.graph.revision||t.revision===t.baseRevision)&&Ic("REVISION_PATCH_BASE","Patch requires the current base and a new revision.");let n=(e,t=[],n=[])=>{Sc(n,"patch upserts");let r=new Map(e.map(e=>[e.id,e]));return t.forEach(e=>r.delete(e)),n.forEach(e=>r.set(e.id,e)),[...r.values()]};return Cc({...e.graph,revision:t.revision,nodes:n(e.graph.nodes,t.removeNodeIds,t.upsertNodes),edges:n(e.graph.edges,t.removeEdgeIds,t.upsertEdges),transfers:n(e.graph.transfers??[],t.removeTransferIds,t.upsertTransfers)})}function Tc(e,t){(!Number.isInteger(t.maxVisited)||t.maxVisited<1||!Number.isInteger(t.maxDepth)||t.maxDepth<0)&&Ic("TRACE_BUDGET","Trace budgets must be finite nonnegative integers, with at least one visit.");let n=Ec(e);Nc(n.nodes,t.start);let r="upstream"===t.direction,i=[{ref:t.start,depth:0}],o=new Set([bc(t.start)]),a=new Map,l=new Map,s=new Set,d=new Set,c=[],u="complete",h=e=>!t.kinds||t.kinds.includes(e??"unspecified"),p=(e,t,n)=>{l.has(bc(e))||c.push({code:t,severity:"warning",message:n,endpointRefs:[e]}),l.set(bc(e),e),"TRACE_BUDGET"===t?u="partial":"complete"===u&&(u="unknown")};for(let e=0;e<i.length;e++){let{ref:l,depth:c}=i[e];a.set(bc(l),l);let u=n.tracePolicies.get(l.nodeId),f="node"===l.endpoint.kind&&!l.endpoint.portId&&"atomic"!==u,m=f&&c>0&&"conservative-node"!==t.boundaryPolicy;f&&p(l,"TRACE_COARSE_BOUNDARY","Whole-node boundary does not establish exact interface provenance.");let g=e=>{let n=bc(e);return!!o.has(n)||(c>=t.maxDepth||o.size>=t.maxVisited?(p(l,"TRACE_BUDGET","Trace is partial within the supplied graph: visit or depth budget reached."),!1):(o.add(n),i.push({ref:e,depth:c+1}),!0))};if(!m)for(let e of(r?n.incoming:n.outgoing).get(bc(l))??[])h(e.kind)&&g(r?wc(e.source,e.sourceEndpoint):wc(e.target,e.targetEndpoint))&&s.add(e.id);for(let e of(r?n.transferIn:n.transferOut).get(bc(l))??[])if(h(e.kind)){d.add(e.id);for(let t of r?e.sources:[e.target])g(wc(e.nodeId,t))}if(f&&"conservative-node"===t.boundaryPolicy)for(let e of n.ownerEndpoints.get(l.nodeId)??[])g(e)}return kc({endpoints:[...a.values()],edgeIds:[...s].sort(Mc),transferIds:[...d].sort(Mc),completeness:u,boundaryRefs:[...l.values()],diagnostics:c})}function Rc(e,t,n=!0){return(!Number.isFinite(e)||n&&e<0)&&Ic("GEOMETRY_NUMBER",`${t} must be finite${n?" and nonnegative":""}.`),e}function Lc(e){Rc(e.x,"x",!1),Rc(e.y,"y",!1),Rc(e.width,"width"),Rc(e.height,"height")}function Fc(e){return[..."within-groups"===e.mode?e.groups.flatMap(e=>[...e.ids]):"optimize"===e.mode?e.initialIds:e.ids]}function Pc(e,t){let n=Fc(e);(n.length!==t.length||new Set(n).size!==n.length||t.some(e=>!n.includes(e)))&&Ic("ORDER_MEMBERS","An order must contain every participating member exactly once."),"within-groups"===e.mode&&new Set(e.groups.map(e=>e.id)).size!==e.groups.length&&Ic("ORDER_GROUPS","Order group IDs must be unique.")}function zc(e,t,n){return"optimize"===e.mode||"within-groups"===e.mode&&e.groups.some(e=>!e.fixed&&e.ids.includes(t)&&e.ids.includes(n))}function Dc(e,t,n,r=Fc(t.order)){let i="LR"===n||"RL"===n,o=t.padding;Object.entries(o).forEach(([e,t])=>Rc(t,e)),Rc(t.headerHeight,"headerHeight"),Rc(t.rowGap,"rowGap"),Rc(t.defaultRowHeight,"defaultRowHeight");let a=new Map;for(let e of t.rowHeights??[])(a.has(e.partId)||!r.includes(e.partId))&&Ic("ORDER_ROW_HEIGHT","Row size IDs must be unique participating parts."),a.set(e.partId,Rc(e.height,"rowHeight"));let l=t.headerHeight+(i?o.top:o.left),s=i?e.width-o.left-o.right:e.height-o.top-o.bottom;Rc(s,"available row breadth");let d=r.map(e=>{let n=a.get(e)??t.defaultRowHeight,r=i?{x:o.left,y:l,width:s,height:n}:{x:l,y:o.top,width:n,height:s};return l+=n+t.rowGap,{partId:e,rect:r}});return l-(d.length?t.rowGap:0)+(i?o.bottom:o.right)>(i?e.height:e.width)+1e-8&&Ic("GEOMETRY_FOOTPRINT","Rows exceed the supplied node footprint.",{nodeIds:[e.nodeId]}),{...e,parts:d,actualPartOrder:r}}function jc(e,t,n=.5){switch((!Number.isFinite(n)||n<0||n>1)&&Ic("GEOMETRY_FRACTION","Anchor fraction must be in [0,1]."),t){case"north":return{point:{x:e.x+e.width*n,y:e.y},normal:{x:0,y:-1}};case"south":return{point:{x:e.x+e.width*n,y:e.y+e.height},normal:{x:0,y:1}};case"east":return{point:{x:e.x+e.width,y:e.y+e.height*n},normal:{x:1,y:0}};case"west":return{point:{x:e.x,y:e.y+e.height*n},normal:{x:-1,y:0}};default:return Ic("GEOMETRY_SIDE","Unknown anchor side.")}}function _c(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let o of e)t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),i=Math.max(i,o.y+o.height);return{x:t,y:n,width:r-t,height:i-n}}function Wc(e){return _c(e.map(e=>({...e,width:0,height:0})))}function Gc(e,t){return e.x<t.x+t.width-1e-8&&e.x+e.width>t.x+1e-8&&e.y<t.y+t.height-1e-8&&e.y+e.height>t.y+1e-8}function Yc(e,t){return t.x>=e.x-1e-8&&t.x<=e.x+e.width+1e-8&&t.y>=e.y-1e-8&&t.y<=e.y+e.height+1e-8}function Bc(e){let t=new Map;for(let n of e.nodes){t.has(n.nodeId)&&Ic("GEOMETRY_DUPLICATE","Duplicate node measurement."),Rc(n.width,"width"),Rc(n.height,"height");let e=new Set;for(let t of n.parts)e.has(t.partId)&&Ic("GEOMETRY_DUPLICATE","Duplicate part measurement."),e.add(t.partId),Lc(t.rect),(!Yc({x:0,y:0,width:n.width,height:n.height},t.rect)||!Yc({x:0,y:0,width:n.width,height:n.height},{x:t.rect.x+t.rect.width,y:t.rect.y+t.rect.height}))&&Ic("GEOMETRY_PART_BOUNDS","Part measurement exceeds its owner.");let r=new Set;for(let e of[...(n.markAnchors??[]).map(e=>({...e,key:JSON.stringify(["mark",e.markId,e.anchorName])})),...(n.slotAnchors??[]).map(e=>({...e,key:JSON.stringify(["slot",e.groupId,e.slotId])}))])r.has(e.key)&&Ic("GEOMETRY_DUPLICATE","Duplicate named anchor."),r.add(e.key),Rc(e.point.x,"anchor x",!1),Rc(e.point.y,"anchor y",!1),Rc(e.normal.x,"normal x",!1),Rc(e.normal.y,"normal y",!1);for(let e of[...n.routingChannels??[],...n.obstacleRects??[]])Lc(e);t.set(n.nodeId,n)}return t}function qc(e,t){return JSON.stringify([bc(e),t])}function Vc(e,t,n){return n.some(n=>Math.abs(e.x-t.x)<Ue?e.x>n.x+Ue&&e.x<n.x+n.width-Ue&&Math.max(e.y,t.y)>n.y+Ue&&Math.min(e.y,t.y)<n.y+n.height-Ue:!(Math.abs(e.y-t.y)<Ue)||e.y>n.y+Ue&&e.y<n.y+n.height-Ue&&Math.max(e.x,t.x)>n.x+Ue&&Math.min(e.x,t.x)<n.x+n.width-Ue)}function Hc(e){let t=[];for(let n of e)t.length&&Xe(t[t.length-1],n)<Ue||t.push(n);return t}function Uc(e,t,n,r,i,o=4e4){let a=e=>e.every((t,r)=>0===r||!Vc(e[r-1],t,n)),l=i?(e.x+t.x)/2+r:(e.y+t.y)/2+r,s=i?[e,{x:l,y:e.y},{x:l,y:t.y},t]:[e,{x:e.x,y:l},{x:t.x,y:l},t];if(a(s))return Hc(s);let d=[],c=[...new Set([e.x,t.x,...n.flatMap(e=>[e.x,e.x+e.width])])].sort((e,t)=>e-t),u=[...new Set([e.y,t.y,...n.flatMap(e=>[e.y,e.y+e.height])])].sort((e,t)=>e-t);for(let n of c)d.push([e,{x:n,y:e.y},{x:n,y:t.y},t]);for(let n of u)d.push([e,{x:e.x,y:n},{x:t.x,y:n},t]);let h=d.filter(a).sort((e,t)=>Ke(e)-Ke(t));if(h.length)return Hc(h[0]);if(c.length*u.length>o)return null;let p=c.length,f=p*u.length,m=u.indexOf(e.y)*p+c.indexOf(e.x),g=u.indexOf(t.y)*p+c.indexOf(t.x),y=new Float64Array(f).fill(1/0),x=new Int32Array(f).fill(-1),b=e=>({x:c[e%p],y:u[Math.floor(e/p)]}),w=[],M=(e,n)=>{let r={id:e,cost:n,priority:n+Xe(b(e),t)};w.push(r);let i=w.length-1;for(;i>0;){let e=i-1>>1;if(w[e].priority<=r.priority)break;w[i]=w[e],i=e}w[i]=r},v=()=>{let e=w[0],t=w.pop();if(w.length){let e=0;for(;2*e+1<w.length;){let n=2*e+1;if(n+1<w.length&&w[n+1].priority<w[n].priority&&n++,w[n].priority>=t.priority)break;w[e]=w[n],e=n}w[e]=t}return e};y[m]=0,M(m,0);let k=0;for(;w.length&&k++<o;){let{id:e,cost:t}=v();if(t!==y[e])continue;if(e===g){let e=[];for(let t=g;t>=0;t=x[t])e.push(b(t));return Hc(e.reverse())}let r=e%p,i=Math.floor(e/p),o=[r>0?e-1:-1,r+1<p?e+1:-1,i>0?e-p:-1,i+1<u.length?e+p:-1];for(let r of o){if(r<0||Vc(b(e),b(r),n))continue;let i=t+Xe(b(e),b(r));i+Ue<y[r]&&(y[r]=i,x[r]=e,M(r,i))}}return null}function Xc(e,t,n,r){let i=[{kind:"M",point:t[0]}];for(let e=1;e<t.length-1;e++){let o=t[e],a=t[e-1],l=t[e+1],s=Math.min(4,Xe(a,o)/3,Xe(l,o)/3),d=e=>({x:o.x+(e.x-o.x)*s/Xe(o,e),y:o.y+(e.y-o.y)*s/Xe(o,e)}),c=d(a),u=d(l),h=Wc([c,o,u]),p=r.some(e=>h.x<e.x+e.width&&h.x+h.width>e.x&&h.y<e.y+e.height&&h.y+h.height>e.y);n&&s>Ue&&e>1&&e<t.length-2&&!p?i.push({kind:"L",point:c},{kind:"C",control1:o,control2:o,point:u}):i.push({kind:"L",point:o})}return i.push({kind:"L",point:t[t.length-1]}),{id:e,points:t,commands:i,bounds:Wc(i.flatMap(e=>"C"===e.kind?[e.control1,e.control2,e.point]:[e.point]))}}function Kc(e){return(e.commands?.length?e.commands:e.points.map((e,t)=>({kind:t?"L":"M",point:e}))).map(e=>"C"===e.kind?`C${e.control1.x},${e.control1.y} ${e.control2.x},${e.control2.y} ${e.point.x},${e.point.y}`:`${e.kind}${e.point.x},${e.point.y}`).join(" ")}function Jc(e){let t=[];for(let n of e.commands??[]){if("C"!==n.kind){t.push(n.point);continue}let e=t[t.length-1],r=n.control1,i=n.control2,o=n.point;for(let n=1;n<=24;n++){let a=n/24,l=1-a;t.push({x:l**3*e.x+3*l**2*a*r.x+3*l*a**2*i.x+a**3*o.x,y:l**3*e.y+3*l**2*a*r.y+3*l*a**2*i.y+a**3*o.y})}}return t.length?t:[...e.points]}function Zc(e,t,n,r=t.escape,i=n.escape,o=!1,a=!0){let l=[t.anchor,t.escape,...Xe(r,t.escape)?[r]:[],...Xe(i,n.escape)?[i]:[],n.escape,n.anchor];if(!o)return{id:e,points:l,bounds:Wc(l)};let s=a?(r.x+i.x)/2:(r.y+i.y)/2,d=a?{x:s,y:r.y}:{x:r.x,y:s},c=a?{x:s,y:i.y}:{x:i.x,y:s};return{id:e,points:l,commands:[{kind:"M",point:t.anchor},{kind:"L",point:t.escape},...Xe(r,t.escape)?[{kind:"L",point:r}]:[],{kind:"C",control1:d,control2:c,point:i},...Xe(i,n.escape)?[{kind:"L",point:n.escape}]:[],{kind:"L",point:n.anchor}],bounds:Wc([...l,d,c])}}function Qc(e,t,n,r){let i=t.x-e.x,o=t.y-e.y,a=r.x-n.x,l=r.y-n.y,s=i*l-o*a;if(Math.abs(s)<1e-8)return null;let d=((n.x-e.x)*l-(n.y-e.y)*a)/s,c=((n.x-e.x)*o-(n.y-e.y)*i)/s;return d>=0&&d<=1&&c>=0&&c<=1?{x:e.x+d*i,y:e.y+d*o}:null}function eu(e,t,n,r="orthogonal",i=/*#__PURE__*/new Set){let o=e.filter(e=>!i.has(e.edgeId)),a="terminals"===r,l=0,s=0,d=0,c=0,u=0,h=0,p=o.map(e=>a?[e.source.escape,e.target.escape]:e.sections.flatMap(Jc));for(let e=0;e<o.length;e++){let r=o[e],i=a?r.sections.flatMap(e=>e.points):p[e];n.has(r.edgeId)&&(d+=Math.abs(t?r.source.anchor.y-r.target.anchor.y:r.source.anchor.x-r.target.anchor.x));for(let e=1;e<i.length;e++)l+=Xe(i[e-1],i[e]),!a&&e>1&&Math.abs((i[e-1].x-i[e-2].x)*(i[e].y-i[e-1].y)-(i[e-1].y-i[e-2].y)*(i[e].x-i[e-1].x))>1e-8&&s++}let f=e=>{let t=1/0,n=-1/0;for(let r of o)t=Math.min(t,r.bounds[e]),n=Math.max(n,r.bounds[e]);return o.length?n-t:0},m=f("x")>=f("y")?"x":"y",g="x"===m?"width":"height",y="x"===m?"y":"x",x="x"===m?"height":"width",b=o.map((e,t)=>({e:e,i:t})).sort((e,t)=>e.e.bounds[m]-t.e.bounds[m]),w=!1;e:for(let e=0;e<b.length;e++)for(let t=e+1;t<b.length;t++){let n=b[e],r=b[t];if(r.e.bounds[m]>n.e.bounds[m]+n.e.bounds[g])break;if(n.e.bounds[y]>r.e.bounds[y]+r.e.bounds[x]||r.e.bounds[y]>n.e.bounds[y]+n.e.bounds[x])continue;if(a){if(++u>2e6){w=!0;break e}let[e,t]=p[n.i],[i,o]=p[r.i],a=Qc(e,t,i,o),l=a&&[e,t].some(e=>Math.abs(e.x-a.x)<1e-8&&Math.abs(e.y-a.y)<1e-8&&[i,o].some(t=>Math.abs(t.x-e.x)<1e-8&&Math.abs(t.y-e.y)<1e-8));a&&!l&&c++;continue}let i=new Set,o=p[n.i],l=p[r.i],s=[n.e.source,n.e.target].flatMap(e=>[r.e.source,r.e.target].filter(t=>Xe(e.anchor,t.anchor)<1e-8&&Xe(e.escape,t.escape)<1e-8).map(()=>[e.anchor,e.escape])),d=e=>s.some(([t,n])=>Math.abs(Xe(t,e)+Xe(e,n)-Xe(t,n))<1e-7);for(let e=1;e<o.length;e++)for(let t=1;t<l.length;t++){if(++u>2e6){w=!0;break e}let n=Qc(o[e-1],o[e],l[t-1],l[t]);n&&!d(n)&&i.add(`${n.x.toFixed(6)},${n.y.toFixed(6)}`);let r=o[e-1],s=o[e],c=l[t-1],p=l[t],f=Math.abs(r.x-s.x)<1e-8&&Math.abs(r.x-c.x)<1e-8&&Math.abs(r.x-p.x)<1e-8,m=Math.abs(r.y-s.y)<1e-8&&Math.abs(r.y-c.y)<1e-8&&Math.abs(r.y-p.y)<1e-8;if(!a&&(f||m)){let e=f?"y":"x",t=Math.max(Math.min(r[e],s[e]),Math.min(c[e],p[e])),n=Math.min(Math.max(r[e],s[e]),Math.max(c[e],p[e]));n>t&&!d(f?{x:r.x,y:(t+n)/2}:{x:(t+n)/2,y:r.y})&&(h+=n-t)}}c+=i.size}return{metrics:{crossings:c,channelCongestion:h,alignmentError:d,totalRouteLength:l,bendCount:s,nodeDisplacement:0,reorderedParts:0,hardConstraintViolations:0,routedEdgeCount:e.length,omittedEdgeCount:0,completedSweeps:0},partial:w}}function tu(e,t){let n=new Map;for(let r of e??[]){let e=t(r);n.has(e)||n.set(e,r)}return n}function nu(e){let{graph:t}=e.prepared,n=new Map(t.nodes.map(e=>[e.id,e])),r=new Map(e.view.nodes.map(e=>[e.nodeId,e]));r.size!==e.view.nodes.length&&Ic("IDENTITY_VIEW","Duplicate node presentations.");for(let e of r.keys())n.has(e)||Ic("IDENTITY_VIEW","Unknown presentation owner.");let i=new Map;for(let e of t.nodes){let t=e.parentId;for(;t;)"summary"===r.get(t)?.mode&&i.set(e.id,t),t=n.get(t)?.parentId}return{semantics:n,views:r,hidden:i}}function ru(e,t,n,r,i){let{view:o}=e,{semantics:a}=t,l=t.hidden.get(r.nodeId),s=l??r.nodeId,d=t.bySemantic.get(s),c=t.measures.get(s),u=t.presentations.get(s),h="summary"===u?.mode&&("part"===r.endpoint.kind||!!r.endpoint.portId),p=l||h?t.exposures.get(Je(s,qc(r,i))):void 0;(l||h)&&!p&&Ic("ENDPOINT_MISSING_EXPOSURE","Collapsed endpoints need explicit boundary exposures.",{endpointRefs:[r]});let f=t.anchors.get(qc(r,i)),m=p?.binding??f?.binding,g=function(e,t){return{LR:["east","west"],RL:["west","east"],TB:["south","north"],BT:["north","south"]}[e]["source"===t?0:1]}(o.direction,i);if(!m){let e={x:0,y:0,width:d.rect.width,height:d.rect.height};if("part"===r.endpoint.kind){let n=r.endpoint.partId,i=d.parts?.find(e=>e.partId===n);i||Ic("GEOMETRY_MISSING_PART","Endpoint has no solved part geometry.",{endpointRefs:[r]}),e=i.rect,"exploded"===u?.mode&&(d=t.byId.get(JSON.stringify(["part",s,n])),e={...e,x:0,y:0})}let n=.5;if(r.endpoint.portId){let e=a.get(r.nodeId),o="part"===r.endpoint.kind?r.endpoint.partId:void 0,l=((o?e.parts?.find(e=>e.id===o)?.ports:e.ports)??[]).filter(e=>"inout"===e.direction||e.direction===("source"===i?"out":"in")).map(e=>e.id).sort(Mc),s=t.portOrders.get(Ze(r.nodeId,o,i,g));s&&Pc(s.order,l);let d=s?Fc(s.order):l;n=(d.indexOf(r.endpoint.portId)+1)/(d.length+1)}let o=jc(e,g,n).point;n="west"===g||"east"===g?o.y/(d.rect.height||1):o.x/(d.rect.width||1),m={kind:"node-side",side:g,fraction:n}}let y=function(e,t,n){switch(e.kind){case"node-side":return jc({x:0,y:0,width:t.rect.width,height:t.rect.height},e.side,e.fraction);case"part-side":{let n=t.parts?.find(t=>t.partId===e.partId);return n?jc(n.rect,e.side,e.fraction):Ic("GEOMETRY_UNKNOWN_PART","Anchor has no solved part rectangle.")}case"point":return e;case"named-mark":{let t=n.markAnchors?.find(t=>t.markId===e.markId&&t.anchorName===e.anchorName);return t||Ic("GEOMETRY_UNKNOWN_MARK","Named mark anchor is unresolved.")}case"slot":{let t=n.slotAnchors?.find(t=>t.groupId===e.groupId&&t.slotId===e.slotId);return t||Ic("GEOMETRY_UNKNOWN_SLOT","Named slot is unresolved.")}}}(m,d,c);Rc(y.point.x,"anchor x",!1),Rc(y.point.y,"anchor y",!1);let x={x:y.normal.x,y:y.normal.y};1===Math.abs(x.x)&&0===x.y||1===Math.abs(x.y)&&0===x.x||Ic("CAPABILITY_NORMAL","The built-in orthogonal adapter requires cardinal unit normals.");let b={x:0,y:0,width:d.rect.width,height:d.rect.height};Yc(b,y.point)||Ic("GEOMETRY_ANCHOR_BOUNDS","Anchor is outside the display node.");let w={x:x.x>0?b.width:x.x<0?0:y.point.x,y:x.y>0?b.height:x.y<0?0:y.point.y};if(!("point"!==m.kind&&"named-mark"!==m.kind&&"slot"!==m.kind||w.x===y.point.x&&w.y===y.point.y)){let e=c.routingChannels??[],t=[0,1,...e.flatMap(e=>x.x?[(e.x-y.point.x)/(w.x-y.point.x),(e.x+e.width-y.point.x)/(w.x-y.point.x)]:[(e.y-y.point.y)/(w.y-y.point.y),(e.y+e.height-y.point.y)/(w.y-y.point.y)])].filter(e=>e>=0&&e<=1).sort((e,t)=>e-t);t.slice(1).some((n,r)=>!e.some(e=>Yc(e,{x:y.point.x+(w.x-y.point.x)*(n+t[r])/2,y:y.point.y+(w.y-y.point.y)*(n+t[r])/2})))&&Ic("CONSTRAINT_INTERIOR_ESCAPE","Interior mark needs a declared straight escape corridor.",{edgeIds:[n]})}let M=(d.parts??[]).filter(e=>"part-side"!==m.kind||e.partId!==m.partId).map(e=>e.rect);Vc(y.point,w,[...c.obstacleRects??[],..."part-side"===m.kind?M:[]])&&Ic("CONSTRAINT_INTERIOR_ESCAPE","Terminal escape intersects an obstacle.",{edgeIds:[n]});let v=Math.max(e.options.terminalStub,e.options.obstaclePadding);return{edgeId:n,end:i,semantic:r,displayNodeId:d.id,anchor:{x:d.rect.x+y.point.x,y:d.rect.y+y.point.y},escape:{x:d.rect.x+w.x+x.x*v,y:d.rect.y+w.y+x.y*v},normal:x,precision:p?"proxy":"exact",exposureId:p?.id}}function iu(e){let t="LR"===e.view.direction||"RL"===e.view.direction,n=new Map(e.view.edgeHints?.map(e=>[e.edgeId,e])),r=[...e.prepared.graph.edges].sort((e,t)=>Mc(n.get(e.id)?.laneId??"",n.get(t.id)?.laneId??"")||Mc(e.id,t.id)),i=new Set(r.filter(e=>"none"===(n.get(e.id)?.route??(e.source===e.target?"none":"auto"))).map(e=>e.id)),o=new Map(r.map(e=>[e.id,JSON.stringify([bc(wc(e.source,e.sourceEndpoint)),bc(wc(e.target,e.targetEndpoint))])])),a=new Map(r.map(e=>[e.id,JSON.stringify([e.source,e.target])])),l=new Map;for(let e of r){if(i.has(e.id))continue;let t=o.get(e.id),n=l.get(t)??[];n.push(e.id),l.set(t,n)}let s,d=new Map;for(let e of r){if(i.has(e.id))continue;let t=a.get(e.id),n=d.get(t)??[];n.push(e.id),d.set(t,n)}return(c,u)=>{let h=[],p=c.nodes.filter(e=>"node"===e.semantic.endpoint.kind),f=e.options.obstaclePadding,m=p.map(e=>({x:e.rect.x-f,y:e.rect.y-f,width:e.rect.width+2*f,height:e.rect.height+2*f})),g=e.prepared.graph.nodes.some(e=>e.parentId),y=s&&c.nodes.every(e=>{let t=s.projection.byId.get(e.id)?.rect;return t&&t.x===e.rect.x&&t.y===e.rect.y&&t.width===e.rect.width&&t.height===e.rect.height});for(let n of r){let r=s?.edges.get(n.id);if("terminals"===e.options.routing&&r&&c.byId.get(r.source.displayNodeId)===s.projection.byId.get(r.source.displayNodeId)&&c.byId.get(r.target.displayNodeId)===s.projection.byId.get(r.target.displayNodeId)&&y){h.push(r);continue}let f=ru(e,c,n.id,wc(n.source,n.sourceEndpoint),"source"),x=ru(e,c,n.id,wc(n.target,n.targetEndpoint),"target"),b=i.has(n.id),w=b||"terminals"===e.options.routing||"bump"===e.options.routing,M=b?[n.id]:l.get(o.get(n.id)),v=(M.indexOf(n.id)-(M.length-1)/2)*e.options.laneGap;M.length>1&&0===e.options.laneGap&&"none"===e.options.bundles&&Ic("ROUTING_COINCIDENT","Exact duplicates require lane space or an explicit bundle.",{edgeIds:M});let k=(e,t)=>({x:e.x-t.y*v,y:e.y+t.x*v}),I=k(f.escape,f.normal),S=k(x.escape,{x:-x.normal.x,y:-x.normal.y});!w&&g&&p.some(e=>e.id!==f.displayNodeId&&e.id!==x.displayNodeId&&e.id!==n.source&&e.id!==n.target&&[f.anchor,x.anchor].some(t=>t.x>e.rect.x&&t.x<e.rect.x+e.rect.width&&t.y>e.rect.y&&t.y<e.rect.y+e.rect.height))&&Ic("CAPABILITY_COMPOUND_ROUTING","Cross-hierarchy routing needs collapsed authored boundary exposures.",{edgeIds:[n.id]});let $=f.displayNodeId!==n.source||x.displayNodeId!==n.target?m.filter((e,t)=>!(f.displayNodeId!==n.source&&p[t].id===n.source||x.displayNodeId!==n.target&&p[t].id===n.target)):m;(!w||M.length>1)&&(Vc(f.escape,I,$)||Vc(S,x.escape,$))&&Ic("ROUTING_LANE_SPACE","Pinned terminal lanes have insufficient clearance.",{edgeIds:[n.id]});let N=b?[n.id]:d.get(a.get(n.id)),A=(N.indexOf(n.id)-(N.length-1)/2)*e.options.laneGap,E=w?[I,S]:Uc(I,S,$,A,t);E||Ic("ROUTING_NO_PATH","No route found within the adapter's visibility-grid budget.",{edgeIds:[n.id]});let C=Hc([f.anchor,f.escape,...E,x.escape,x.anchor]),O=w?Zc(JSON.stringify([n.id,"route"]),f,x,I,S,!b&&"bump"===e.options.routing,t):Xc(JSON.stringify([n.id,"route"]),C,"smooth"===e.options.routing,$),T=e=>c.hidden.get(e)??e,R=T(n.source)!==T(n.target)&&u.get(T(n.source))>=u.get(T(n.target));h.push({routing:b?"none":e.options.routing,edgeId:n.id,source:f,target:x,sections:[O],bounds:O.bounds,feedback:R})}return s={projection:c,edges:new Map(h.map(e=>[e.edgeId,e]))},{edges:h,hints:n,sorted:r,excluded:i}}}function ou(e,t){let n=new Map(e.map(e=>[e,0])),r=new Map;for(let[e,i]of t){let t=r.get(e)??new Set;t.has(i)||(t.add(i),n.set(i,(n.get(i)??0)+1)),r.set(e,t)}let i=e.filter(e=>!n.get(e)).sort(Mc),o=new Map(e.map(e=>[e,0])),a=0;for(let e=0;e<i.length;e++){let t=i[e];a++;for(let e of[...r.get(t)??[]].sort(Mc))o.set(e,Math.max(o.get(e)??0,o.get(t)+1)),n.set(e,n.get(e)-1),n.get(e)||i.push(e)}return a===e.length?o:null}function au(e){let t=new Set(e.view.constraints?.filter(e=>"both"===e.pin&&e.position).map(e=>e.nodeId));return e.prepared.graph.nodes.every(e=>t.has(e.id))}function lu(e,t){let n=e.previous;if(!n)return;let r=et.get(n);return r||(r=new Map(n.nodes.map(e=>[e.id,e])),et.set(n,r)),r.get(t)}function su(e){return{topology:"strict-dag",routing:"orthogonal",bundles:"none",rankGap:96,nodeGap:32,laneGap:6,terminalStub:12,obstaclePadding:6,maxSweeps:8,seed:0,...e,weights:{crossings:8,alignment:2,length:1,bends:1,congestion:4,displacement:4,reorder:3,...e.weights}}}function du(e){return{schemaVersion:"semiotic.compositional-layout.v0.1",direction:e.view.direction,requestId:e.requestId,semanticHash:e.prepared.semanticHash,graphRevision:e.prepared.graph.revision,viewRevision:e.view.revision,geometryRevision:e.geometry.revision,engineId:"semiotic-compositional",engineVersion:"0.1.0",optionsHash:vc(e.options),status:"complete",nodes:[],edges:[],bundles:[],bounds:{x:0,y:0,width:0,height:0},metrics:{crossings:0,channelCongestion:0,alignmentError:0,totalRouteLength:0,bendCount:0,nodeDisplacement:0,reorderedParts:0,hardConstraintViolations:0,routedEdgeCount:0,omittedEdgeCount:e.prepared.graph.edges.length,completedSweeps:0},diagnostics:[]}}function cu(e,t,n,r,i){let o=function(e,t,n,r,i){let{graph:o}=e.prepared,{semantics:a,views:l,hidden:s}=nu(e),d=[],c=new Map,u=new Map;for(let h of[...o.nodes].sort((e,t)=>Mc(e.id,t.id))){if(s.has(h.id))continue;if(i&&i.positions.get(h.id)===n.get(h.id)&&i.orders.get(h.id)===r.get(h.id)){let e=i.bySemantic.get(h.id);if(d.push(e),"exploded"===l.get(h.id)?.mode)for(let t of e.parts??[])d.push(i.byId.get(JSON.stringify(["part",h.id,t.partId])));c.set(h.id,e),u.set(h.id,i.measures.get(h.id));continue}let o=t.get(h.id);o||Ic("GEOMETRY_MISSING","Every visible owner needs geometry.",{nodeIds:[h.id]});let p=l.get(h.id),f=p?.partLayout;if("rows"===f?.kind){Pc(f.order,(h.parts??[]).map(e=>e.id));let t=r.get(h.id)??Fc(f.order);"fixed"!==f.order.mode&&(o.markAnchors?.length||o.slotAnchors?.length||e.view.anchors?.some(e=>e.ref.nodeId===h.id&&["point","named-mark","slot"].includes(e.binding.kind)))&&Ic("CONSTRAINT_ABSOLUTE_REORDER","Absolute anchors require fixed row order or a custom reflow adapter.",{nodeIds:[h.id]}),o=Dc(o,f,e.view.direction,t)}"summary"!==p?.mode&&(h.parts??[]).some(e=>!o.parts.some(t=>t.partId===e.id))&&Ic("GEOMETRY_MISSING_PART","Every visible part needs a rectangle.",{nodeIds:[h.id]}),o.parts.some(e=>!h.parts?.some(t=>t.id===e.partId))&&Ic("GEOMETRY_UNKNOWN_PART","Measured part does not exist.");let m=n.get(h.id),g={id:h.id,semantic:wc(h.id),rect:{...m,width:o.width,height:o.height},parts:o.parts.map(e=>({...e,rect:{...e.rect},semantic:wc(h.id,{kind:"part",partId:e.partId})})),partOrder:o.actualPartOrder&&[...o.actualPartOrder],markAnchors:o.markAnchors?.map(Qe),slotAnchors:o.slotAnchors?.map(Qe)};if(d.push(g),c.set(h.id,g),u.set(h.id,o),"exploded"===p?.mode)for(let e of g.parts??[]){let t=JSON.stringify(["part",h.id,e.partId]);a.has(t)&&Ic("IDENTITY_PROJECTION_COLLISION","A semantic ID collides with an exploded display ID."),d.push({id:t,semantic:e.semantic,rect:{...e.rect,x:m.x+e.rect.x,y:m.y+e.rect.y}})}}let h=o.nodes.some(e=>e.parentId),p=d.filter(e=>"node"===e.semantic.endpoint.kind).sort((e,t)=>e.rect.y-t.rect.y),f=i&&d.length===i.nodes.length&&d.every(e=>{let t=i.byId.get(e.id)?.rect;return t&&t.x===e.rect.x&&t.y===e.rect.y&&t.width===e.rect.width&&t.height===e.rect.height});for(let e=0;!f&&e<p.length;e++)for(let t=e+1;t<p.length;t++){let n=p[e],r=p[t];if(r.rect.y>n.rect.y+n.rect.height&&!h)break;let i=(e,t)=>{let n=e.parentId;for(;n;){if(n===t)return!0;n=a.get(n)?.parentId}return!1},o=i(a.get(n.id),r.id),l=i(a.get(r.id),n.id);if(o||l){let e=o?n:r,t=o?r:n;(!Yc(t.rect,e.rect)||!Yc(t.rect,{x:e.rect.x+e.rect.width,y:e.rect.y+e.rect.height}))&&Ic("CONSTRAINT_CONTAINMENT","Authored child bounds exceed the containing owner.",{nodeIds:[e.id,t.id]})}else Gc(n.rect,r.rect)&&Ic("CONSTRAINT_OVERLAP","Node boxes overlap.",{nodeIds:[n.id,r.id]})}let{view:m}=e;return{nodes:d,positions:new Map(n),orders:new Map(r),hidden:s,bySemantic:c,measures:u,semantics:a,presentations:l,anchors:tu(m.anchors,e=>qc(e.ref,e.use)),exposures:tu(m.boundaryExposures,e=>Je(e.containerNodeId,qc(e.inner,e.use))),portOrders:tu(m.portOrders,e=>Ze(e.nodeId,e.partId,e.use,e.side)),byId:new Map(d.map(e=>[e.id,e]))}}(e,t,n,r,i.projection);i.projection=o;let a=i.ranks??(i.ranks=function(e,t){let n=t.nodes.filter(e=>"node"===e.semantic.endpoint.kind).map(e=>e.id),r=e=>t.hidden.get(e)??e,i=ou(n,e.prepared.graph.edges.filter(e=>r(e.source)!==r(e.target)).map(e=>[r(e.source),r(e.target)]));return!i&&"strict-dag"===e.options.topology&&!au(e)&&Ic("TOPOLOGY_PROJECTION_CYCLE","The display quotient is cyclic; expand the group or explicitly select feedback mode."),i??new Map(n.sort(Mc).map((e,t)=>[e,t]))}(e,o)),l="LR"===e.view.direction||"RL"===e.view.direction,s=[],{edges:d,hints:c,sorted:u,excluded:h}=i.routeEdges(o,a),p=new Set(u.filter(e=>"none"!==c.get(e.id)?.alignment).map(e=>e.id)),{metrics:f,partial:m}=eu(d,l,p,e.options.routing,h);f.channelCongestion>1e-8&&s.push({code:"ROUTING_CONGESTION",severity:"warning",message:"Some routes share undeclared segments. Every edge is retained; use the connection table to disambiguate.",edgeIds:d.map(e=>e.edgeId)}),m&&s.push({code:"ROUTING_METRIC_BUDGET",severity:"warning",message:"Crossing count is a lower bound after two million segment comparisons."}),"estimated"===e.geometry.basis&&s.push({code:"GEOMETRY_ESTIMATED",severity:"warning",message:"Attachment geometry is provisional."}),("smooth"===e.options.routing||"bump"===e.options.routing)&&s.push({code:"ROUTING_CURVE_METRICS",severity:"info",message:"Curve length and crossings use 24 samples per cubic; bounds use conservative control envelopes."});let g=new Map(u.map(e=>[e.id,e])),y=[];if("none"!==e.options.bundles){let t=new Map;for(let e of d){if(h.has(e.edgeId))continue;let n=g.get(e.edgeId),r=JSON.stringify(["bundle",e.source.displayNodeId,e.target.displayNodeId,e.source.exposureId??bc(e.source.semantic),e.target.exposureId??bc(e.target.semantic),n.kind??"unspecified",c.get(n.id)?.bundleGroup??null]),i=t.get(r)??[];i.push(e),t.set(r,i)}for(let[n,r]of t)r.length>1&&y.push({id:n,kind:e.options.bundles,memberEdgeIds:r.map(e=>e.edgeId),path:r[0].sections,count:r.length,countStatus:"exact",semanticKind:g.get(r[0].edgeId)?.kind??"unspecified"})}return{...du(e),status:m&&"terminals"!==e.options.routing||f.channelCongestion>1e-8||"estimated"===e.geometry.basis?"degraded":"complete",nodes:o.nodes,edges:d,bundles:y,bounds:_c([...o.nodes.map(e=>e.rect),...d.map(e=>e.bounds)]),metrics:f,diagnostics:s}}function uu(e,t,n){let r=e.metrics,i=su(t.options).weights,o=Math.max(1,t.options.rankGap),a=t.view.nodes.reduce((e,t)=>"rows"===t.partLayout?.kind?e+Fc(t.partLayout.order).filter((e,r)=>n.get(t.nodeId)?.[r]!==e).length:e,0),l=e.nodes.filter(e=>"node"===e.semantic.endpoint.kind),s=l.reduce((e,n)=>{let r=lu(t,n.id);return e+(r?Xe(r.rect,n.rect):0)},0);return i.crossings*r.crossings+i.alignment*r.alignmentError/o+i.length*r.totalRouteLength/o+i.bends*r.bendCount+i.congestion*r.channelCongestion/o+i.reorder*a/Math.max(1,l.length)+i.displacement*s/o}function hu(e){let t={...e,options:su(e.options)};try{(function(e){let t=e.options;(!["route-only","optimize"].includes(t.mode)||!["strict-dag","feedback"].includes(t.topology)||!["orthogonal","polyline","smooth","terminals","bump"].includes(t.routing)||!["none","parallel","overview"].includes(t.bundles)||!["LR","RL","TB","BT"].includes(e.view.direction))&&Ic("CAPABILITY_OPTIONS","Unknown layout mode, direction, routing or topology.");for(let e of["rankGap","nodeGap","laneGap","terminalStub","obstaclePadding","maxSweeps"])Rc(t[e],e);(!Number.isInteger(t.maxSweeps)||t.maxSweeps>100)&&Ic("CONSTRAINT_BUDGET","maxSweeps must be an integer in [0,100]."),Number.isSafeInteger(t.seed)||Ic("CONSTRAINT_SEED","Seed must be a safe integer."),Object.entries(t.weights??{}).forEach(([e,t])=>Rc(t,e)),"optimize"===t.mode&&!au(e)&&e.prepared.graph.nodes.some(e=>e.parentId)&&Ic("CAPABILITY_COMPOUND_OPTIMIZE","Compound graphs require authored positions in this adapter.");let n=new Set,r=new Set(e.prepared.graph.edges.map(e=>e.id));for(let t of e.view.edgeHints??[])(n.has(t.edgeId)||!r.has(t.edgeId))&&Ic("IDENTITY_EDGE_HINT","Edge hints must refer to unique existing edges."),n.add(t.edgeId),void 0!==t.route&&!["auto","none"].includes(t.route)&&Ic("CAPABILITY_OPTIONS","Unknown edge routing hint."),void 0!==t.priority&&Rc(t.priority,"priority")})(t),function(e){[e.requestId,e.view.revision,e.geometry.revision].every(e=>"string"==typeof e&&e.length>0)||Ic("REVISION_REQUIRED","Request, view and geometry revisions must be nonempty strings.");let t=new Map(e.prepared.graph.nodes.map(e=>[e.id,e])),n=new Set;for(let r of e.view.anchors??[]){Nc(t,r.ref,r.use);let e=qc(r.ref,r.use);n.has(e)&&Ic("IDENTITY_ANCHOR","Duplicate endpoint/use anchor."),n.add(e)}let r=new Set,i=new Set;for(let n of e.view.boundaryExposures??[]){Nc(t,n.inner,n.use);let e=n.inner.nodeId;for(;e&&e!==n.containerNodeId;)e=t.get(e)?.parentId;e||Ic("ENDPOINT_EXPOSURE_OWNER","Exposure must refer to an endpoint inside its container.");let o=JSON.stringify([n.containerNodeId,qc(n.inner,n.use)]);(r.has(n.id)||i.has(o))&&Ic("IDENTITY_EXPOSURE","Duplicate boundary exposure."),r.add(n.id),i.add(o)}let o=new Set;for(let n of e.view.portOrders??[]){let e=n.partId?{kind:"part",partId:n.partId}:{kind:"node"};Nc(t,wc(n.nodeId,e));let r=t.get(n.nodeId),i=((n.partId?r.parts?.find(e=>e.id===n.partId)?.ports:r.ports)??[]).filter(e=>"inout"===e.direction||e.direction===("source"===n.use?"out":"in"));Pc(n.order,i.map(e=>e.id));let a=JSON.stringify([n.nodeId,n.partId??null,n.side,n.use]);o.has(a)&&Ic("ORDER_PORT_DUPLICATE","Repeated port order constraint."),o.add(a),"fixed"!==n.order.mode&&Ic("CAPABILITY_PORT_ORDER","This adapter supports fixed port order; port permutation needs another adapter.")}}(t),function(e){let t=new Set,n=[],r=(e,r)=>{t.add(e),t.add(r),n.push([e,r])};for(let t of e.prepared.graph.edges)r(bc(wc(t.source,t.sourceEndpoint)),bc(wc(t.target,t.targetEndpoint)));for(let t of e.prepared.graph.transfers??[])for(let e of t.sources)r(bc(wc(t.nodeId,e)),bc(wc(t.nodeId,t.target)));!ou([...t],n)&&"strict-dag"===e.options.topology&&Ic("TOPOLOGY_SEMANTIC_CYCLE","Connections and transfers contain a semantic cycle.")}(t);let e=Bc(t.geometry),n=function(e){let t=new Map(e.view.constraints?.map(e=>[e.nodeId,e]));t.size!==(e.view.constraints?.length??0)&&Ic("CONSTRAINT_DUPLICATE","Duplicate node constraints.");let n=new Set(e.prepared.graph.nodes.map(e=>e.id));for(let e of t.values())n.has(e.nodeId)||Ic("CONSTRAINT_OWNER","Unknown constrained node."),e.position&&(!Number.isFinite(e.position.x)||!Number.isFinite(e.position.y))&&Ic("GEOMETRY_POSITION","Positions must be finite."),e.pin&&!e.position&&Ic("CONSTRAINT_PIN","Pinned nodes need a position."),void 0!==e.rank&&(!Number.isInteger(e.rank)||e.rank<0)&&Ic("CONSTRAINT_RANK","Ranks must be nonnegative integers.");let r=new Map;for(let n of e.prepared.graph.nodes){let i=t.get(n.id);"route-only"===e.options.mode&&!i?.position&&Ic("CONSTRAINT_POSITION","Route-only mode requires authored positions for every owner.",{nodeIds:[n.id]}),r.set(n.id,i?.position??{x:0,y:0})}return r}(t),r=new Map;for(let e of t.view.nodes)"rows"===e.partLayout?.kind&&r.set(e.nodeId,Fc(e.partLayout.order));if("optimize"===t.options.mode&&!au(t)){let e=t.prepared.graph,r=ou(e.nodes.map(e=>e.id),e.edges.filter(e=>e.source!==e.target).map(e=>[e.source,e.target]));!r&&"strict-dag"===t.options.topology&&Ic("TOPOLOGY_PROJECTION_CYCLE","Owner projection is cyclic."),function(e,t,n){let r="LR"===e.view.direction||"RL"===e.view.direction,i="RL"===e.view.direction||"BT"===e.view.direction,o=new Map(e.view.constraints?.map(e=>[e.nodeId,e])),a=new Map(e.geometry.nodes.map(e=>[e.nodeId,e]));for(let[e,n]of t){let r=o.get(e)?.rank;void 0!==r?t.set(e,r):t.set(e,n)}if("strict-dag"===e.options.topology)for(let n of e.prepared.graph.edges)n.source!==n.target&&t.has(n.source)&&t.has(n.target)&&t.get(n.source)>=t.get(n.target)&&Ic("CONSTRAINT_RANK","Authored ranks conflict with graph direction.",{edgeIds:[n.id]});let l=0;for(let s of[...new Set(t.values())].sort((e,t)=>e-t)){let d=[...t].filter(([,e])=>e===s).map(([e])=>e).sort(Mc),c=0,u=0;for(let t of d){let s=a.get(t);s||Ic("GEOMETRY_MISSING","Missing node measurement.",{nodeIds:[t]});let d=r?s.width:s.height,h=r?s.height:s.width;u=Math.max(u,d);let p=i?-l-d:l,f=r?{x:p,y:c}:{x:c,y:p},m=o.get(t);n.set(t,{x:"x"===m?.pin||"both"===m?.pin?m.position.x:f.x,y:"y"===m?.pin||"both"===m?.pin?m.position.y:f.y}),c+=h+e.options.nodeGap}l+=u+e.options.rankGap}}(t,r??new Map([...e.nodes].sort((e,t)=>Mc(e.id,t.id)).map((e,t)=>[e.id,t])),n)}let i={routeEdges:iu(t)},o=new Map(t.view.edgeHints?.map(e=>[e.edgeId,e])),a=new Set(t.prepared.graph.edges.filter(e=>"none"!==o.get(e.id)?.alignment&&"none"!==(o.get(e.id)?.route??(e.source===e.target?"none":"auto"))).map(e=>e.id)),l=cu(t,e,n,r,i),s=uu(l,t,r),d=0,c=0,u=()=>{c++;try{let o=cu(t,e,n,r,i),a=uu(o,t,r);if(a+1e-8<s)return l=o,s=a,!0}catch(e){if(!(e instanceof Ve))throw e}return!1};if("optimize"===t.options.mode)for(let e=0;e<t.options.maxSweeps&&c<256;e++){let e=!1;for(let n of[...t.view.nodes].sort((e,t)=>Mc(e.nodeId,t.nodeId))){if("rows"!==n.partLayout?.kind)continue;let t=r.get(n.nodeId);e:for(let i=0;i<t.length-1&&c<256;i++)for(let o=i+1;o<t.length&&c<256;o++){if(!zc(n.partLayout.order,t[i],t[o]))continue;let a=[...t];if([a[i],a[o]]=[a[o],a[i]],r.set(n.nodeId,a),u()){e=!0;break e}r.set(n.nodeId,t)}}let i="LR"===t.view.direction||"RL"===t.view.direction,o=new Map(l.nodes.map(e=>[e.id,e.semantic.nodeId]));for(let r of l.nodes){if(c>=256)break;if("node"!==r.semantic.endpoint.kind)continue;let s=t.view.constraints?.find(e=>e.nodeId===r.id);if("both"===s?.pin||s?.pin===(i?"y":"x"))continue;let d=l.edges.filter(e=>a.has(e.edgeId)).flatMap(e=>o.get(e.source.displayNodeId)===r.id?[i?e.target.anchor.y-e.source.anchor.y:e.target.anchor.x-e.source.anchor.x]:o.get(e.target.displayNodeId)===r.id?[i?e.source.anchor.y-e.target.anchor.y:e.source.anchor.x-e.target.anchor.x]:[]).sort((e,t)=>e-t);if(!d.length)continue;let h=d[Math.floor(d.length/2)],p=n.get(r.id);Math.abs(h)<1e-8||(n.set(r.id,{x:p.x+(i?0:h),y:p.y+(i?h:0)}),u()?e=!0:n.set(r.id,p))}if(d++,!e)break}let h=t.view.nodes.reduce((e,t)=>"rows"===t.partLayout?.kind?e+Fc(t.partLayout.order).filter((e,n)=>r.get(t.nodeId)?.[n]!==e).length:e,0),p=[...l.diagnostics,{code:"LAYOUT_TERMINATION",severity:"info",message:"route-only"===t.options.mode?"Authored positions and order retained.":`Bounded local optimization completed ${d} sweeps and ${c} candidate evaluations${c>=256?" (candidate budget reached)":""}.`}];return kc({...l,metrics:{...l.metrics,completedSweeps:d,reorderedParts:h,nodeDisplacement:l.nodes.reduce((e,n)=>{if("node"!==n.semantic.endpoint.kind)return e;let r=lu(t,n.id);return e+(r?Xe(r.rect,n.rect):0)},0)},diagnostics:p})}catch(e){if(!(e instanceof Ve))throw e;return kc({...du(t),status:"infeasible",diagnostics:e.diagnostics,metrics:{...du(t).metrics,hardConstraintViolations:1}})}}async function pu(e,t,n){let r={...e,options:su(e.options)};n?.aborted&&Ic("REVISION_CANCELLED","Layout request was cancelled.");let i=t.capabilities,o=[["route-only"===r.options.mode||!!e.view.constraints?.some(e=>!!e.pin),i.fixedPositions,"fixed positions"],[!!e.view.anchors?.length,i.fixedPortPositions,"exact anchors"],[!!e.view.nodes.some(e=>"rows"===e.partLayout?.kind),i.constrainedPartOrder,"part order"],[e.prepared.graph.edges.length>new Set(e.prepared.graph.edges.map(e=>JSON.stringify([e.source,e.target]))).size,i.multiedges,"multiedges"],["orthogonal"===r.options.routing,i.orthogonalRouting,"orthogonal routing"],["terminals"===r.options.routing,!!i.terminalRouting,"terminal routing"],["bump"===r.options.routing,!!i.bumpRouting,"bump routing"]];for(let[e,t,n]of o)e&&!t&&Ic("CAPABILITY_ENGINE",`Engine does not support ${n}.`);let a=await t.layout(r,n);return n?.aborted&&Ic("REVISION_CANCELLED","Layout request was cancelled."),(a.requestId!==e.requestId||a.semanticHash!==e.prepared.semanticHash||a.graphRevision!==e.prepared.graph.revision||a.viewRevision!==e.view.revision||a.geometryRevision!==e.geometry.revision||a.optionsHash!==vc(r.options)||a.engineId!==t.id||a.engineVersion!==t.version)&&Ic("REVISION_RESPONSE","Engine response does not match the requested revision tuple."),function(e,t){if(["complete","degraded","infeasible"].includes(t.status)||Ic("REVISION_STATUS","Unknown layout status."),"infeasible"===t.status)return;let n=new Map(t.nodes.map(e=>[e.id,e])),{hidden:r}=nu(e);n.size!==t.nodes.length&&Ic("IDENTITY_SOLVED_NODE","Duplicate display node ID."),function(e,t){let{semantics:n,views:r,hidden:i}=nu(e),o=new Set;for(let e of n.values())if(!i.has(e.id)&&(o.add(bc(wc(e.id))),"exploded"===r.get(e.id)?.mode))for(let t of e.parts??[])o.add(bc(wc(e.id,{kind:"part",partId:t.id})));for(let e of t.nodes){let t=bc(e.semantic);o.delete(t)||Ic("IDENTITY_SOLVED_NODE","Unknown, hidden or repeated display-node semantics."),Lc(e.rect);let i=n.get(e.semantic.nodeId),a="node"===e.semantic.endpoint.kind,l=new Set;for(let t of e.parts??[])(!a||l.has(t.partId)||!i.parts?.some(e=>e.id===t.partId)||bc(t.semantic)!==bc(wc(i.id,{kind:"part",partId:t.partId})))&&Ic("IDENTITY_SOLVED_PART","Solved parts must retain unique owner-local semantic identities."),l.add(t.partId),Lc(t.rect);a&&"summary"!==r.get(i.id)?.mode&&(i.parts??[]).some(e=>!l.has(e.id))&&Ic("IDENTITY_SOLVED_PART","A visible owner is missing solved parts.")}o.size&&Ic("IDENTITY_SOLVED_NODE","A feasible solution must cover the requested visible projection.")}(e,t),Lc(t.bounds);let i=new Map(e.prepared.graph.edges.map(e=>[e.id,e])),o=new Set;for(let e of t.edges){let a=i.get(e.edgeId);(!a||o.has(e.edgeId))&&Ic("IDENTITY_SOLVED_EDGE","Unknown or repeated solved edge ID."),o.add(e.edgeId),(bc(e.source.semantic)!==bc(wc(a.source,a.sourceEndpoint))||bc(e.target.semantic)!==bc(wc(a.target,a.targetEndpoint)))&&Ic("ENDPOINT_SOLVED_RETARGET","An engine changed the semantic endpoint.",{edgeIds:[e.edgeId]}),Lc(e.bounds),(!n.has(e.source.displayNodeId)||!n.has(e.target.displayNodeId)||!e.sections.length)&&Ic("GEOMETRY_SOLVED_ROUTE","A route needs display owners and path sections.");for(let t of[e.source,e.target]){let i=n.get(t.displayNodeId),o=r.get(t.semantic.nodeId)??t.semantic.nodeId;(i.semantic.nodeId!==o||!Yc(i.rect,t.anchor))&&Ic("GEOMETRY_TERMINAL_OWNER","A terminal must attach to its own display node.",{edgeIds:[e.edgeId]})}let l=e.source.anchor;for(let n of e.sections){Lc(n.bounds),(n.points.length<2||Xe(l,n.points[0])>1e-7)&&Ic("GEOMETRY_ROUTE_CONTINUITY","Route skeleton does not meet its terminal or preceding section.");let r=n.commands;r?.length&&("M"!==r[0].kind||Xe(l,r[0].point)>1e-7||Xe(r[r.length-1].point,n.points[n.points.length-1])>1e-7)&&Ic("GEOMETRY_ROUTE_COMMANDS","Final commands and skeleton disagree at terminals.");let i=[...n.points,...(r??[]).flatMap(e=>"C"===e.kind?[e.point,e.control1,e.control2]:[e.point])];for(let r of i)(!Number.isFinite(r.x)||!Number.isFinite(r.y)||!Yc(n.bounds,r)||!Yc(e.bounds,r)||!Yc(t.bounds,r))&&Ic("GEOMETRY_ROUTE_BOUNDS","Route geometry must be finite and within its conservative bounds.");l=n.points[n.points.length-1]}Xe(l,e.target.anchor)>1e-7&&Ic("GEOMETRY_ROUTE_TERMINAL","Route misses its target anchor.")}(o.size!==i.size||t.metrics.routedEdgeCount!==o.size||0!==t.metrics.omittedEdgeCount)&&Ic("ROUTING_OMITTED_EDGE","A feasible transaction must represent every requested connection."),"complete"===t.status&&0!==t.metrics.hardConstraintViolations&&Ic("CONSTRAINT_SOLVED","A complete result cannot contain hard constraint violations.");for(let e of t.bundles)(new Set(e.memberEdgeIds).size!==e.memberEdgeIds.length||e.count!==e.memberEdgeIds.length||e.memberEdgeIds.some(e=>!i.has(e)))&&Ic("IDENTITY_BUNDLE","Bundle counts and memberships must match materialized edges.")}(r,a),kc(a)}function fu(e){let{prepared:t,solved:n}=e;("infeasible"===n.status||n.semanticHash!==t.semanticHash||n.graphRevision!==t.graph.revision)&&Ic("REVISION_SCENE","Scene needs a feasible solution matching the semantic revision.");let r=new Map(t.graph.nodes.map(e=>[e.id,e])),i=new Map(t.graph.edges.map(e=>[e.id,e])),o=new Map(n.nodes.filter(e=>"node"===e.semantic.endpoint.kind).map(e=>[e.semantic.nodeId,e.id])),a=new Set(n.nodes.filter(e=>"part"===e.semantic.endpoint.kind).map(e=>bc(e.semantic)));return{sceneNodes:n.nodes.flatMap(t=>{let n=r.get(t.semantic.nodeId),i="node"===t.semantic.endpoint.kind,l="part"===t.semantic.endpoint.kind?t.semantic.endpoint.partId:void 0,s=n.parts?.find(e=>e.id===l),d={type:"rect",id:t.id,navParentId:i?void 0:o.get(n.id),x:t.rect.x,y:t.rect.y,w:t.rect.width,h:t.rect.height,label:i?n.label??n.id:s?.label??l,datum:i?{...n,semantic:t.semantic}:{id:l,ownerId:n.id,semantic:t.semantic},style:{fill:i?e.nodeFill??"#edf2f7":e.partFill??"#c9dce8",stroke:"#556779",strokeWidth:1}};return e.showParts&&i?[d,...(t.parts??[]).filter(e=>!e.clipped&&!a.has(bc(e.semantic))).map(r=>({type:"rect",id:JSON.stringify(["part-hit",t.id,r.partId]),navParentId:t.id,x:t.rect.x+r.rect.x,y:t.rect.y+r.rect.y,w:r.rect.width,h:r.rect.height,label:n.parts?.find(e=>e.id===r.partId)?.label??r.partId,datum:{id:r.partId,ownerId:n.id,semantic:r.semantic},style:{fill:e.partFill??"#c9dce8"}}))]:[d]}),sceneEdges:n.edges.map(t=>({type:"curved",id:t.edgeId,pathD:t.sections.map(Kc).join(" "),datum:{...i.get(t.edgeId),sourceTerminal:t.source,targetTerminal:t.target},label:t.edgeId,style:{fill:"none",stroke:e.edgeStroke??"#467895",strokeWidth:1.5}}))}}function mu(e,t=tt){let n=new Map,r=new Set,i=!1,o=t=>{try{e.postMessage({type:"cancel",requestId:t})}catch{}},a=({data:e})=>{if("result"!==e.type&&"error"!==e.type)return;let t=n.get(e.requestId);t&&(t.clean(),n.delete(e.requestId),"result"===e.type?t.resolve(e.solved):t.reject(new Error(e.message)))},l=e=>{for(let t of n.values())t.clean(),t.reject(new Error(`REVISION_WORKER_FAILED: ${e}`));n.clear()},s=e=>{"messageerror"===e?.type?l("A worker message could not be deserialized."):"error"===e?.type&&l(e.message||"The worker reported an error.")},d=e;return e.addEventListener("message",a),d.addEventListener?.("error",s),d.addEventListener?.("messageerror",s),{...t,layout:(t,a)=>new Promise((l,s)=>{if(i||a?.aborted)return void s(new Error("REVISION_CANCELLED"));if(r.has(t.requestId))return void s(new Error("REVISION_REQUEST_ID: request IDs must be unique for the engine's lifetime."));r.add(t.requestId);let d=()=>{n.delete(t.requestId),a?.removeEventListener("abort",d),s(new Error("REVISION_CANCELLED")),o(t.requestId)};n.set(t.requestId,{resolve:l,reject:s,clean:()=>a?.removeEventListener("abort",d)}),a?.addEventListener("abort",d,{once:!0});try{e.postMessage({type:"solve",request:t})}catch(e){n.delete(t.requestId),a?.removeEventListener("abort",d),s(e)}}),dispose(){i=!0,e.removeEventListener("message",a),d.removeEventListener?.("error",s),d.removeEventListener?.("messageerror",s);for(let[e,t]of n)t.clean(),t.reject(new Error("REVISION_CANCELLED")),o(e);n.clear(),r.clear()}}}function gu(e,t=tt){let n=new Map,r=({data:r})=>{if("cancel"===r.type)return void n.get(r.requestId)?.abort();if("solve"!==r.type)return;let i=r.request,o=new AbortController;n.get(i.requestId)?.abort(),n.set(i.requestId,o),Promise.resolve().then(()=>t.layout(i,o.signal)).then(t=>{o.signal.aborted||e.postMessage({type:"result",requestId:i.requestId,solved:t})}).catch(t=>{if(!o.signal.aborted)try{e.postMessage({type:"error",requestId:i.requestId,message:t instanceof Error?t.message:"Worker layout failed."})}catch{}}).finally(()=>{n.get(i.requestId)===o&&n.delete(i.requestId)})};return e.addEventListener("message",r),()=>{e.removeEventListener("message",r),n.forEach(e=>e.abort()),n.clear()}}function yu(e,t){let n="TB"!==e.direction&&"BT"!==e.direction,r=e.nodes.find(e=>e.id===t.nodeId);(!r||"infeasible"===e.status)&&Ic("GEOMETRY_SCROLL_OWNER","Scroll projection requires a feasible visible owner."),Lc(t.viewport),Rc(t.offsetY,"offsetY");let i=t.viewport;(i.x<0||i.y<0||i.x+i.width>r.rect.width||i.y+i.height>r.rect.height)&&Ic("GEOMETRY_SCROLL_VIEWPORT","Row viewport must be inside the owner.");let o=r.rect.y+i.y,a=o+i.height,l=e=>{if(e.displayNodeId!==r.id||"part"!==e.semantic.endpoint.kind)return e;(0!==e.normal.y||Math.abs(e.anchor.x-r.rect.x)>1e-7&&Math.abs(e.anchor.x-r.rect.x-r.rect.width)>1e-7)&&Ic("CAPABILITY_SCROLL_ANCHOR","This scroll projection requires horizontal boundary row slots.");let n=e.anchor.y-t.offsetY,i=n>=o&&n<=a,l=Math.max(o,Math.min(a,n));return{...e,anchor:{...e.anchor,y:l},escape:{...e.escape,y:l},precision:i?e.precision:"proxy",exposureId:i?e.exposureId:JSON.stringify(["scroll",bc(e.semantic),e.end])}},s=e.nodes.map(e=>e.id!==r.id?e:{...e,parts:e.parts?.map(e=>{let n={...e.rect,y:e.rect.y-t.offsetY};return{...e,rect:n,clipped:n.y<i.y||n.y+n.height>i.y+i.height}})}),d=e.edges.map(e=>{let t=l(e.source),r=l(e.target);if(t===e.source&&r===e.target)return e;1!==e.sections.length&&Ic("CAPABILITY_SCROLL_SECTIONS","The built-in scroll repair requires a single route section.");let i=e.sections[0],o=i.points.slice(1,-1),a=Hc([t.anchor,t.escape,...o,r.escape,r.anchor]),s=(e,t,n)=>({x:e.x+n.escape.x-t.escape.x,y:e.y+n.escape.y-t.escape.y}),d="none"===e.routing||"terminals"===e.routing||"bump"===e.routing?Zc(i.id,t,r,i.points.length>4?s(i.points[2],e.source,t):t.escape,i.points.length>4?s(i.points[i.points.length-3],e.target,r):r.escape,"bump"===e.routing,n):Xc(i.id,a,!1,[]);return{...e,source:t,target:r,sections:[d],bounds:d.bounds}}),c=d.find(e=>"none"!==e.routing)?.routing,u=eu(d,n,new Set(d.map(e=>e.edgeId)),"none"===c?"orthogonal":c,new Set(d.filter(e=>"none"===e.routing).map(e=>e.edgeId)));return kc({...e,viewRevision:t.viewRevision,nodes:s,edges:d,bundles:[],bounds:_c([...s.map(e=>e.rect),...d.map(e=>e.bounds)]),metrics:{...e.metrics,...u.metrics,completedSweeps:0},status:"degraded",diagnostics:[...e.diagnostics,{code:"GEOMETRY_SCROLL_PROXIES",severity:"info",message:"Clipped row endpoints use disclosed continuation proxies; terminal routes were locally repaired without a global solve.",nodeIds:[r.id]}]})}var Be={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"}},qe=Object.freeze({kind:"node"}),Ve=class extends Error{constructor(e){super(e.map(e=>`${e.code}: ${e.message}`).join("\n")),this.diagnostics=e,this.name="CompositionalGraphError"}},He=/*#__PURE__*/new WeakMap,Ue=1e-8,Xe=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),Ke=e=>e.slice(1).reduce((t,n,r)=>t+Xe(e[r],n),0),Je=(e,t)=>JSON.stringify([e,t]),Ze=(e,t,n,r)=>JSON.stringify([e,t??null,n,r]),Qe=e=>({...e,point:{...e.point},normal:{...e.normal}}),et=/*#__PURE__*/new WeakMap,tt={id:"semiotic-compositional",version:"0.1.0",capabilities:{fixedPositions:!0,fixedPortPositions:!0,constrainedPartOrder:!0,multiedges:!0,compoundCrossHierarchy:!1,orthogonalRouting:!0,terminalRouting:!0,bumpRouting:!0,deterministicSeed:!0},async layout(e,t){if(t?.aborted)throw new Error("REVISION_CANCELLED");return hu(e)}},nt=class{constructor(){this.generation=0,this.currentDiagnostics=[],this.updating=!1}get solution(){return this.accepted}get diagnostics(){return this.currentDiagnostics}async solve(e,t=tt){this.abort?.abort();let n=new AbortController,r=++this.generation;this.abort=n,this.updating=!0;try{let i=await pu(e,t,n.signal);return r===this.generation&&(this.currentDiagnostics=i.diagnostics,"infeasible"!==i.status)&&(this.accepted=i,!0)}catch(e){return r===this.generation&&(this.currentDiagnostics=[{code:"REVISION_SOLVE_FAILED",severity:"error",message:e instanceof Error?e.message:"Layout failed."}]),!1}finally{r===this.generation&&(this.updating=!1)}}cancel(){this.generation++,this.abort?.abort(),this.updating=!1}dispose(){this.cancel(),this.accepted=void 0,this.currentDiagnostics=[]}},rt=e=>fu(e.config),it=class{constructor(e,t){this.current=e,this.accepted=t,this.passes=0}get solution(){return this.accepted}update(e){if(Bc(e),e.basis===this.current.geometry.basis&&vc(e.nodes)===vc(this.current.geometry.nodes))return this.accepted;if(this.passes>=2)return kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,{code:"GEOMETRY_UNSTABLE_MEASUREMENT",severity:"warning",message:"Measurement did not converge after two corrections; retaining the last valid scene."}]});if(e.revision===this.current.geometry.revision)return kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,{code:"REVISION_GEOMETRY",severity:"warning",message:"Changed geometry requires a new revision; retaining the last valid scene."}]});this.passes++;let t={...this.current,requestId:`${this.current.requestId}:measure:${this.passes}`,geometry:e,previous:this.accepted},n=hu(t);return"infeasible"!==n.status&&(this.accepted=n,this.current=t),"infeasible"===n.status?kc({...this.accepted,status:"degraded",diagnostics:[...this.accepted.diagnostics,...n.diagnostics]}):this.accepted}};export{Ve as CompositionalGraphError,nt as CompositionalLayoutController,it as CompositionalMeasurementTransaction,ge as DEFAULT_AREA_PER_ANNOTATION,je as DEFAULT_GLYPH_ANCHOR,De as DEFAULT_GLYPH_VIEWBOX,Fe as DEFAULT_HIT_RADIUS,k as DEFAULT_ISOMETRIC_SPRITE_SIZES,ke as GRID_FUEL_KEYS,Ie as GRID_FUEL_LABELS,e as LayoutCache,r as SYMBOL_SEQUENCE,ze as TAU,Fs as absorbRegion,Da as activeCountOverDomain,Wl as addPoints,ee as adjacencyFlowLayout,ec as adjacencyMatrix,$o as aggregateAdjacencyFlow,ws as aggregateRegionCounts,Pt as allocateCells,eo as analyzeNetEnsemble,zl as angleScale,sa as annotationBudget,ca as annotationDensity,xa as annotationLayout,Jd as arcLayout,Zd as arcPath,Ud as arrivalReplay,Ee as axisFixedForceLayout,Ka as axisFixedForcePositions,jt as balanceSnapshotsToFlows,Hi as bandLabel,hs as betweenness,ds as bfsDistances,pe as bobaLayout,zs as bodyGroupSpec,qi as boundsOf,Ya as boxEdgeAnchors,ls as buildAdjacency,ns as buildTooltipEntries,ae as bulletLayout,x as calendarLayout,Rs as capacitatedRegion,Cs as chargeGateRegion,Qd as circularLayout,gt as clamp,va as classifyReserve,ps as closeness,fs as clustering,Bd as collidersFromScales,Zs as comparePhysicsTrace,fd as composePhysicsControllers,tt as compositionalDagEngine,rt as compositionalDagLayout,bc as compositionalEndpointKey,su as compositionalLayoutOptions,Kc as compositionalPath,Dc as compositionalRowGeometry,qr as computeTransitDiagramPositions,Sl as countPairwiseCrossings,hd as createCapacityQueueController,mu as createCompositionalWorkerEngine,Pr as createDagreFit,bd as createDependencyGateController,Er as createFlextreeFit,si as createLineageDagFit,md as createPortalController,rd as createProcessJourneyLedger,xd as createServiceLevelController,gd as createServiceResourcePoolController,Ha as cubicPath,qa as cubicPoint,Va as cubicTangent,Wa as curvedEdgePath,yl as cyclicRangeContains,z as dagreLayout,ss as degree,Ia as demandForecastRows,Dd as describePhysicsStageGeography,an as diagnoseTokenEncoding,kt as dimFor,us as egoNetwork,fu as emitCompositionalScene,Al as estimateLabelWidth,ts as extractTooltipDatum,Ba as fanOutBend,P as flextreeLayout,Ps as forceFieldRegion,Jt as forceLayout,ys as forceLayoutAsync,Ta as formatMw,Ra as formatReservePct,rs as formatTooltipValue,qd as galtonPegs,rn as generateTokens,cl as geoAreaHitTarget,dl as geoHitTarget,F as geographicDotGridLayout,C as geographicGridLayout,Hl as glyphExtent,Ul as glyphFractionClipRect,Vl as glyphPlacement,Ca as gridEventAnnotations,Qn as gridifyGeographicPoints,wt as groupBy,vs as groupCompletionRows,Ui as hatchFill,sl as hitTargetPoint,ul as hitTargetRect,Vi as hullFromBoxes,gu as installCompositionalWorker,Ne as intervalLanesLayout,N as isometricLandmarkLayout,c as isotypeBoltGlyph,u as isotypeBusGlyph,d as isotypeChipGlyph,l as isotypeGhost,o as isotypeInk,f as isotypeNetworkGlyphs,a as isotypePaper,p as isotypePersonGlyph,h as isotypePersonPath,s as isotypeServerGlyph,Nl as layoutChipStrip,pu as layoutCompositionalGraph,$l as layoutSequence,on as layoutTokenGrid,Zl as legendGroupsFrom,Ql as legendSwatches,G as lineageDagLayout,Xi as linearAxis,$t as makeShade,oe as marimekkoLayout,Ki as markCallout,vt as matchesHighlight,Ot as mean,Es as membraneRegion,K as mermaidDagLayout,ac as mobileAnnotationStrategy,uc as mobileAreaChartRecipe,xc as mobileBrushAlternatives,yc as mobileChartFamilyRecipe,mc as mobileGeoChartRecipe,cc as mobileLineChartRecipe,fc as mobileNetworkChartRecipe,hc as mobileOrdinalChartRecipe,pc as mobileScatterplotRecipe,gc as mobileSmallMultipleRecipe,U as motifBraidLayout,Kt as mulberry32,Q as netEnsembleLayout,pl as networkEdgeHitTarget,hl as networkHitTarget,Ct as nonNegativeFinite,ql as normalizePoint,ms as normalizeScores,en as normalizeTokenEncoding,Vr as octilinearRoute,Hr as offsetTransitPath,vl as orderByBarycenter,Kd as orderByGroupDegree,Il as orderExactSmall,Ga as orthogonalEdgePath,Ml as packBandsBySilhouette,za as packIntervals,El as packSpanLevels,re as packedClusterMatrix,le as parallelCoordinatesLayout,Rl as partitionSharedEdges,Oc as patchCompositionalGraph,Pd as physicsChargePoint,Fd as physicsDestination,Hs as physicsReferenceEnvelope,zd as physicsStageColliders,Ld as physicsStageGeography,bl as placeWithMinGap,Bl as pointMagnitude,Fl as polarToXY,Ls as portalRegion,Cc as prepareCompositionalGraph,Ii as prepareMotifBraid,ki as prepareNetworkAtlasAsync,Ts as pressureFieldRegion,Rd as processChrome,od as processJourneyRows,Ds as processLaneWalls,Ss as processStageLayout,As as processStageRegions,_s as processVolumePolygons,yu as projectCompositionalScroll,gs as proximityProblem,Dl as radiusScale,xt as readField,Ua as rectCollide,kl as refineByAdjacentSwaps,Ms as regionCountsToProjectionRows,Aa as reserveAnnotationBands,Ma as reserveClasses,Sa as reserveMarginPct,$a as reserveSeries,jl as ringArcPath,Bi as roundedEnclosure,Ur as roundedTransitPath,hu as routeCompositionalGraph,Os as routeSurfaceRegion,Pe as runLengthEncode,fl as runs,gr as sampleGeographicDotGrid,Cl as scaleArcBand,Yl as scalePoint,Hd as sedimentBake,xl as selectCyclicRange,Pn as selectIsometricLandmarks,Nt as shade,gl as shortestArcDelta,cs as shortestPath,It as signatureKey,Ol as spanArcPath,Tl as spanArcPeakY,Vd as spawnFromTokens,ka as stackFuelSeries,js as stageTargetInVolume,Gl as subtractPoints,dn as suggestTokenEncoding,Ea as summarizeOperatingPoint,wn as symbolExtent,xn as symbolPathString,bn as symbolRadius,Na as thresholdBandsForReserve,Oa as tightestHours,An as tokenLayer,sn as tokenTaskIntentToCapabilityIntents,Tc as traceCompositionalGraph,j as transitDiagramLayout,Wt as unitize,Gt as unitizeRange,bt as unwrapDatum,id as updateProcessJourney,t as waffleLayout,Tt as withAlpha,ol as wordTrailsLayout,nl as wordTrailsProgressiveReveal,ml as wrapValue,Pl as xyToAngle};