semiotic 3.8.2 → 3.8.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 (113) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +34 -33
  3. package/ai/schema.json +1 -1
  4. package/ai/surface-manifest.json +1 -1
  5. package/ai/system-prompt.md +1 -1
  6. package/dist/{chunk-chunk-C6EJ4IOD.module.min.js → chunk-chunk-2CCFBTQC.module.min.js} +1 -1
  7. package/dist/chunk-chunk-2RXP3FS3.module.min.js +1 -0
  8. package/dist/chunk-chunk-4TMZXLCR.module.min.js +1 -0
  9. package/dist/{chunk-chunk-H4PPRW6N.module.min.js → chunk-chunk-5APBQXZA.module.min.js} +1 -1
  10. package/dist/{chunk-chunk-NO4MCQVD.module.min.js → chunk-chunk-5RKXZQ2P.module.min.js} +1 -1
  11. package/dist/chunk-chunk-6HSGDMTA.module.min.js +2 -0
  12. package/dist/{chunk-chunk-7LHMKRKE.module.min.js → chunk-chunk-7FW6EGLP.module.min.js} +1 -1
  13. package/dist/{chunk-chunk-RH5TSQPH.module.min.js → chunk-chunk-7OEOSCBP.module.min.js} +1 -1
  14. package/dist/{chunk-chunk-FAKO3RGQ.module.min.js → chunk-chunk-A63CTACR.module.min.js} +1 -1
  15. package/dist/chunk-chunk-ANYDWOZF.module.min.js +1 -0
  16. package/dist/{chunk-chunk-ZLKRTF5N.module.min.js → chunk-chunk-AZJUDQRM.module.min.js} +1 -1
  17. package/dist/{chunk-chunk-W3DB2MN4.module.min.js → chunk-chunk-B6V35LMY.module.min.js} +1 -1
  18. package/dist/chunk-chunk-BOSVL645.module.min.js +2 -0
  19. package/dist/chunk-chunk-EMO5NUGE.module.min.js +1 -0
  20. package/dist/chunk-chunk-F25UA5HT.module.min.js +1 -0
  21. package/dist/chunk-chunk-FRIO6MCV.module.min.js +1 -0
  22. package/dist/{chunk-chunk-T27ZEV6A.module.min.js → chunk-chunk-GWSWSPXN.module.min.js} +1 -1
  23. package/dist/chunk-chunk-I6C3KR5H.module.min.js +2 -0
  24. package/dist/chunk-chunk-IP2UE74X.module.min.js +1 -0
  25. package/dist/chunk-chunk-J5RL6GXU.module.min.js +2 -0
  26. package/dist/chunk-chunk-JNCHKRIR.module.min.js +2 -0
  27. package/dist/{chunk-chunk-Z5KXAVQD.module.min.js → chunk-chunk-L3H6DQCR.module.min.js} +1 -1
  28. package/dist/{chunk-chunk-5WEFWNUW.module.min.js → chunk-chunk-M7VYYHCE.module.min.js} +1 -1
  29. package/dist/chunk-chunk-MC35ILYP.module.min.js +2 -0
  30. package/dist/{chunk-chunk-2VUEY5TH.module.min.js → chunk-chunk-N72SWNBV.module.min.js} +1 -1
  31. package/dist/chunk-chunk-OBQRFTIL.module.min.js +2 -0
  32. package/dist/chunk-chunk-OQTLSTGI.module.min.js +2 -0
  33. package/dist/{chunk-chunk-2UN3ANRN.module.min.js → chunk-chunk-SA3D43RA.module.min.js} +1 -1
  34. package/dist/chunk-chunk-SANERMIZ.module.min.js +2 -0
  35. package/dist/{chunk-chunk-DNY43POY.module.min.js → chunk-chunk-UHSZEB74.module.min.js} +1 -1
  36. package/dist/{chunk-chunk-CYIML3AV.module.min.js → chunk-chunk-XQYVEKEJ.module.min.js} +1 -1
  37. package/dist/{chunk-chunk-27HVVXS6.module.min.js → chunk-chunk-Y6AXCRVO.module.min.js} +1 -1
  38. package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
  39. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +5 -6
  40. package/dist/components/charts/realtime/temporalHistogramConfig.d.ts +11 -0
  41. package/dist/components/charts/shared/areaSeriesData.d.ts +15 -0
  42. package/dist/components/charts/shared/chartMode.d.ts +67 -0
  43. package/dist/components/charts/shared/colorUtils.d.ts +8 -0
  44. package/dist/components/charts/shared/geoStyleDefaults.d.ts +3 -0
  45. package/dist/components/charts/shared/hooks.d.ts +13 -80
  46. package/dist/components/charts/shared/useChartSetup.d.ts +3 -0
  47. package/dist/components/charts/shared/useCustomChartSetup.d.ts +3 -0
  48. package/dist/components/charts/shared/useXYLineStyle.d.ts +3 -2
  49. package/dist/components/charts/shared/xyLineStyle.d.ts +21 -0
  50. package/dist/components/charts/xy/LineChart.d.ts +3 -0
  51. package/dist/components/legendLayout.d.ts +31 -0
  52. package/dist/components/server/serverChartConfigShared.d.ts +29 -0
  53. package/dist/components/server/serverChartConfigs.d.ts +2 -13
  54. package/dist/components/server/serverChartConfigsXY.d.ts +3 -0
  55. package/dist/components/server/serverGaugeOverlay.d.ts +28 -0
  56. package/dist/components/server/staticLegend.d.ts +7 -1
  57. package/dist/components/server/staticSVGChrome.d.ts +57 -0
  58. package/dist/components/stream/GeoPipelineStore.d.ts +2 -0
  59. package/dist/components/stream/GeoSVGOverlay.d.ts +2 -0
  60. package/dist/components/stream/SceneToSVG.d.ts +8 -6
  61. package/dist/components/stream/SceneToSVGGeo.d.ts +10 -0
  62. package/dist/components/stream/SceneToSVGNetwork.d.ts +12 -0
  63. package/dist/components/stream/canvasBackground.d.ts +7 -0
  64. package/dist/components/stream/networkTypes.d.ts +2 -4
  65. package/dist/components/stream/renderBackend.d.ts +14 -0
  66. package/dist/components/stream/sceneToSVGShared.d.ts +51 -0
  67. package/dist/components/types/legendTypes.d.ts +16 -3
  68. package/dist/geo.min.js +1 -1
  69. package/dist/geo.module.min.js +1 -1
  70. package/dist/network.min.js +1 -1
  71. package/dist/network.module.min.js +1 -1
  72. package/dist/ordinal.min.js +1 -1
  73. package/dist/ordinal.module.min.js +1 -1
  74. package/dist/physics.min.js +1 -1
  75. package/dist/physics.module.min.js +1 -1
  76. package/dist/realtime.min.js +1 -1
  77. package/dist/realtime.module.min.js +1 -1
  78. package/dist/semiotic-ai-core.min.js +1 -1
  79. package/dist/semiotic-ai-core.module.min.js +1 -1
  80. package/dist/semiotic-ai.min.js +1 -1
  81. package/dist/semiotic-ai.module.min.js +1 -1
  82. package/dist/semiotic-experimental.min.js +1 -1
  83. package/dist/semiotic-experimental.module.min.js +1 -1
  84. package/dist/semiotic-realtime-core.min.js +1 -1
  85. package/dist/semiotic-realtime-core.module.min.js +1 -1
  86. package/dist/semiotic-recipes-core.module.min.js +1 -1
  87. package/dist/semiotic-recipes.module.min.js +1 -1
  88. package/dist/semiotic-server-edge.min.js +1 -1
  89. package/dist/semiotic-server-edge.module.min.js +1 -1
  90. package/dist/semiotic-server-node.min.js +1 -1
  91. package/dist/semiotic-server-node.module.min.js +1 -1
  92. package/dist/semiotic-utils-core.module.min.js +1 -1
  93. package/dist/semiotic-utils.module.min.js +1 -1
  94. package/dist/semiotic.min.js +1 -1
  95. package/dist/semiotic.module.min.js +1 -1
  96. package/dist/server.min.js +1 -1
  97. package/dist/server.module.min.js +1 -1
  98. package/dist/xy.min.js +1 -1
  99. package/dist/xy.module.min.js +1 -1
  100. package/package.json +1 -1
  101. package/dist/chunk-chunk-6F6GEAQU.module.min.js +0 -1
  102. package/dist/chunk-chunk-BHYTYMY2.module.min.js +0 -2
  103. package/dist/chunk-chunk-E7MIQX7D.module.min.js +0 -2
  104. package/dist/chunk-chunk-ES4DCG3L.module.min.js +0 -1
  105. package/dist/chunk-chunk-IFYPMWKY.module.min.js +0 -1
  106. package/dist/chunk-chunk-L6D3I3V7.module.min.js +0 -2
  107. package/dist/chunk-chunk-ODUZEEBH.module.min.js +0 -2
  108. package/dist/chunk-chunk-P6UBCMSQ.module.min.js +0 -2
  109. package/dist/chunk-chunk-STZFFTAN.module.min.js +0 -2
  110. package/dist/chunk-chunk-U3AGQ5EF.module.min.js +0 -2
  111. package/dist/chunk-chunk-WDIN4LRC.module.min.js +0 -1
  112. package/dist/chunk-chunk-XOYX77KF.module.min.js +0 -2
  113. package/dist/chunk-chunk-ZTNVDWAK.module.min.js +0 -2
@@ -1 +0,0 @@
1
- import{accessorsEquivalent as t,annotationBudget as e,annotationDensity as i,isNoteAnnotation as o,mulberry32 as n,resolveAccessor as r,resolveRawAccessor as s,resolveStringAccessor as a}from"./chunk-chunk-J3ELI22J.module.min.js";import{createContext as c,useCallback as l,useContext as u,useMemo as h,useRef as d,useSyncExternalStore as f}from"react";import{jsx as p}from"react/jsx-runtime";function y(t,e){const i=new Set;let o={...t(function(t){const e=t(o);if(function(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1}(e)){o={...o,...e};for(const t of i)t()}}),...e??{}};return{getState:()=>o,subscribe:function(t){return i.add(t),()=>{i.delete(t)}}}}function g(t){if(!t?.colors)return;const e=t.colors;return{primary:e.primary,secondary:e.secondary||e.primary,surface:e.surface||e.background,success:e.success,danger:e.danger,warning:e.warning,error:e.error,info:e.info,text:e.text,textSecondary:e.textSecondary,border:e.border,grid:e.grid}}function m(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:x}}),t.accessibility.highContrast){const t="dark"===e.mode;e={...e,colors:{...e.colors,text:t?"#ffffff":"#000000",textSecondary:t?"#cccccc":"#333333",grid:t?"#666666":"#999999",border:t?"#888888":"#000000"}}}return e}var x=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],b={mode:"light",colors:{primary:"#00a2ce",secondary:"#6c757d",categorical:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],sequential:"blues",diverging:"RdBu",background:"transparent",surface:"#ffffff",text:"#333",textSecondary:"#666",grid:"#e0e0e0",border:"#ccc",selection:"#00a2ce",selectionOpacity:.15,success:"#2ca02c",danger:"#d62728",warning:"#f0ad4e",error:"#b4181b",info:"#00a2ce"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},v={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},w={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:x,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function k(t,e){if("light"===e)return b;if("dark"===e)return v;if("high-contrast"===e)return w;if("string"==typeof e)return void 0!==console&&console.warn(`[ThemeStore] Unknown theme preset "${e}". Keeping current theme.`),t;if(e.mode&&"auto"!==e.mode){const t="dark"===e.mode?v:b;return m({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}return m({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}var[S,A]=function(t){let e=null;const i=()=>(e||(e=c(null)),e),o=y(t);return[function({children:e,initialState:o}){const n=d(o),r=h(()=>y(t,n.current),[]),s=i();return p(s.Provider,{value:r,children:e})},(t,e)=>{const n=i(),r=u(n)??o,s=d(t);s.current=t;const a=d({hasValue:!1,value:void 0}),c=l(()=>{const t=s.current(r.getState()),i=a.current;return i.hasValue&&e&&e(i.value,t)?i.value:(a.current={hasValue:!0,value:t},t)},[r,e]),h=l(()=>s.current(r.getState()),[r]);return f(r.subscribe,c,h)}]}(t=>({theme:b,setTheme(e){t(t=>({theme:k(t.theme,e)}))}})),M={light:b,dark:v,"high-contrast":w,pastels:{mode:"light",colors:{primary:"#c9a0dc",secondary:"#b8a8c8",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#fdf6f0",surface:"#fff5ee",text:"#4a3728",textSecondary:"#7a644a",grid:"#e8d5c4",border:"#e8d5c4",focus:"#8a5fae",annotation:"#8a5fae",success:"#9ad4a3",danger:"#e8869a",warning:"#f0c888",error:"#c86070",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#fff5ee",text:"#4a3728",borderRadius:"8px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"10px"},"pastels-dark":{mode:"dark",colors:{primary:"#c9a0dc",secondary:"#a899c0",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#1a1525",surface:"#251e35",text:"#e8ddf0",textSecondary:"#a899c0",grid:"#3d3455",border:"#3d3455",focus:"#c9a0dc",annotation:"#c9a0dc",success:"#88d4ab",danger:"#f0a0c0",warning:"#f0c888",error:"#e87690",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#251e35",text:"#e8ddf0",borderRadius:"8px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"10px"},"bi-tool":{mode:"light",colors:{primary:"#2563eb",secondary:"#6b7280",categorical:["#2563eb","#0d9488","#ea580c","#6b7280"],sequential:"blues",background:"#f5f6f8",surface:"#ffffff",text:"#2c3e50",textSecondary:"#64717f",grid:"#d8dce3",border:"#d8dce3",focus:"#2563eb",annotation:"#2563eb",success:"#10b981",danger:"#ef4444",warning:"#f59e0b",error:"#dc2626",info:"#2563eb"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2c3e50",borderRadius:"6px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"8px"},"bi-tool-dark":{mode:"dark",colors:{primary:"#3b82f6",secondary:"#9ca3af",categorical:["#3b82f6","#14b8a6","#f97316","#9ca3af"],sequential:"blues",background:"#111827",surface:"#1f2937",text:"#f3f4f6",textSecondary:"#9ca3af",grid:"#374151",border:"#374151",focus:"#3b82f6",annotation:"#3b82f6",success:"#34d399",danger:"#f87171",warning:"#fbbf24",error:"#ef4444",info:"#60a5fa"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f2937",text:"#f3f4f6",borderRadius:"6px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"8px"},italian:{mode:"light",colors:{primary:"#cc0000",secondary:"#666666",categorical:["#cc0000","#333333","#c8a415","#4682b4"],sequential:"reds",background:"#fafafa",surface:"#ffffff",text:"#1a1a1a",textSecondary:"#666666",grid:"#e0e0e0",border:"#e0e0e0",focus:"#cc0000",annotation:"#cc0000",success:"#556b2f",danger:"#cc0000",warning:"#c8a415",error:"#8b0000",info:"#4682b4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#1a1a1a",borderRadius:"2px",shadow:"0 2px 4px rgba(0, 0, 0, 0.15)"},borderRadius:"2px"},"italian-dark":{mode:"dark",colors:{primary:"#ff3333",secondary:"#aaaaaa",categorical:["#ff3333","#aaaaaa","#d4a843","#6aa4d4"],sequential:"reds",background:"#0a0a0a",surface:"#1a1a1a",text:"#f5f5f5",textSecondary:"#aaaaaa",grid:"#333333",border:"#333333",focus:"#ff3333",annotation:"#ff3333",success:"#7a8b5a",danger:"#ff3333",warning:"#d4a843",error:"#cc0000",info:"#6aa4d4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1a1a1a",text:"#f5f5f5",borderRadius:"2px",shadow:"0 2px 8px rgba(0, 0, 0, 0.5)"},borderRadius:"2px"},tufte:{mode:"light",colors:{primary:"#8b0000",secondary:"#555555",categorical:["#8b4513","#556b2f","#4a5568","#800020"],sequential:"oranges",background:"#fffff8",surface:"#fffff8",text:"#111111",textSecondary:"#555555",grid:"#e0ddd0",border:"#e0ddd0",focus:"#8b0000",annotation:"#8b0000",success:"#556b2f",danger:"#8b0000",warning:"#b88700",error:"#6b0000",info:"#4a5568"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#fffff8",text:"#111111",borderRadius:"2px",shadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},borderRadius:"0px"},"tufte-dark":{mode:"dark",colors:{primary:"#c05050",secondary:"#a09880",categorical:["#c08050","#7a8b5a","#8090a0","#a05060"],sequential:"oranges",background:"#1c1b18",surface:"#262520",text:"#e8e4d8",textSecondary:"#a09880",grid:"#3d3c35",border:"#3d3c35",focus:"#c05050",annotation:"#d06a6a",success:"#7a8b5a",danger:"#c05050",warning:"#c8a060",error:"#a04040",info:"#8090a0"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262520",text:"#e8e4d8",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.4)"},borderRadius:"0px"},journalist:{mode:"light",colors:{primary:"#e45050",secondary:"#666666",categorical:["#3a86c8","#e45050","#d4a843","#888888"],sequential:"blues",background:"#ffffff",surface:"#f8f8f8",text:"#222222",textSecondary:"#666666",grid:"#d4d4d4",border:"#d4d4d4",focus:"#e45050",annotation:"#c63b3b",success:"#2d7a3d",danger:"#c8303a",warning:"#d4a843",error:"#a02028",info:"#3a86c8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:18,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#f8f8f8",text:"#222222",borderRadius:"4px",shadow:"0 2px 6px rgba(0, 0, 0, 0.12)"},borderRadius:"4px"},"journalist-dark":{mode:"dark",colors:{primary:"#ff6b6b",secondary:"#a0a0a0",categorical:["#5a9fd8","#ff6b6b","#e0c060","#aaaaaa"],sequential:"blues",background:"#141414",surface:"#1e1e1e",text:"#ededed",textSecondary:"#a0a0a0",grid:"#383838",border:"#383838",focus:"#ff6b6b",annotation:"#ff6b6b",success:"#6fba78",danger:"#ff6b6b",warning:"#e0c060",error:"#d04040",info:"#5a9fd8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1e1e1e",text:"#ededed",borderRadius:"4px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"4px"},playful:{mode:"light",colors:{primary:"#8b5cf6",secondary:"#7c5a9e",categorical:["#8b5cf6","#ec4899","#06b6d4","#84cc16"],sequential:"viridis",background:"#fdf8ff",surface:"#ffffff",text:"#2d1b4e",textSecondary:"#7c5a9e",grid:"#e8d0f8",border:"#e8d0f8",focus:"#8b5cf6",annotation:"#7a47e8",success:"#10d870",danger:"#ff4b6e",warning:"#ffaa33",error:"#e11d48",info:"#06b6d4"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2d1b4e",borderRadius:"12px",shadow:"0 4px 12px rgba(139, 92, 246, 0.15)"},borderRadius:"12px"},"playful-dark":{mode:"dark",colors:{primary:"#a78bfa",secondary:"#b8a0d8",categorical:["#a78bfa","#f472b6","#22d3ee","#a3e635"],sequential:"viridis",background:"#150a28",surface:"#1f1138",text:"#f0e8ff",textSecondary:"#b8a0d8",grid:"#3a2560",border:"#3a2560",focus:"#a78bfa",annotation:"#a78bfa",success:"#4ade80",danger:"#fb7185",warning:"#fbbf24",error:"#f43f5e",info:"#22d3ee"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f1138",text:"#f0e8ff",borderRadius:"12px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"12px"},carbon:{mode:"light",colors:{primary:"#0f62fe",secondary:"#525252",categorical:["#6929c4","#1192e8","#005d5d","#9f1853"],sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#161616",textSecondary:"#525252",grid:"#e0e0e0",border:"#e0e0e0",focus:"#0f62fe",annotation:"#0f62fe",success:"#24a148",danger:"#da1e28",warning:"#f1c21b",error:"#a2191f",info:"#0043ce"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#161616",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.2)"},borderRadius:"0px"},"carbon-dark":{mode:"dark",colors:{primary:"#4589ff",secondary:"#a8a8a8",categorical:["#a56eff","#33b1ff","#08bdba","#ff7eb6"],sequential:"blues",diverging:"RdBu",background:"#161616",surface:"#262626",text:"#f4f4f4",textSecondary:"#a8a8a8",grid:"#393939",border:"#393939",focus:"#4589ff",annotation:"#4589ff",success:"#42be65",danger:"#fa4d56",warning:"#f1c21b",error:"#da1e28",info:"#4589ff"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262626",text:"#f4f4f4",borderRadius:"2px",shadow:"0 4px 12px rgba(0, 0, 0, 0.5)"},borderRadius:"0px"}};function _(t){if(!t)return b;if("string"==typeof t){if("light"===t)return b;if("dark"===t)return v;if("high-contrast"===t)return w;return M[t]||b}const e="dark"===t.mode?v:b;return m({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}})}function P(t){return{background:t.colors.background,text:t.colors.text,textSecondary:t.colors.textSecondary,grid:t.colors.grid,border:t.colors.border,primary:t.colors.primary,fontFamily:t.typography.fontFamily,titleSize:t.typography.titleSize,labelSize:t.typography.labelSize,tickSize:t.typography.tickSize,categorical:t.colors.categorical,annotation:t.colors.annotation??t.colors.text,legendSize:t.typography.legendSize??t.typography.labelSize,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}import*as R from"react-dom/server";import*as T from"react";import{scaleOrdinal as L}from"d3-scale";function C(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function $(t,e,i){const o=t=>t.toString(16).padStart(2,"0");return`#${o(t)}${o(e)}${o(i)}`}function z(t){const e=t.map(C),i=e.length-1;return t=>{if(0>=t){const[t,i,o]=e[0];return $(t,i,o)}if(t>=1){const[t,o,n]=e[i];return $(t,o,n)}const o=t*i,n=Math.floor(o),r=o-n,[s,a,c]=e[n],[l,u,h]=e[n+1];return $(Math.round(s+(l-s)*r),Math.round(a+(u-a)*r),Math.round(c+(h-c)*r))}}var D=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],E=z(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),I=z(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),F=z(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),N=z(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),B=z(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),O=z(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),W=z(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),j=z(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),Y=z(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),X=z(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),q=z(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),G=z(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),V={blues:E,reds:I,greens:F,viridis:W,oranges:N,purples:B,greys:O,plasma:j,inferno:Y,magma:X,cividis:q,turbo:G};function H(t){return t&&V[t]||E}z(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),z(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),z(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),z(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),z(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),z(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),z(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]);var Z={category10:D,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...V},K=D,U=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Q=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function J(t,e,i){if("function"==typeof e){const o=e(t);return i&&o&&"string"==typeof o&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||Q.has(e)}(o)?i(o):o}const o=t?.[e]+"";return i?i(o):K[Math.abs(function(t){let e=0;for(let i=0;t.length>i;i++)e=(e<<5)-e+t.charCodeAt(i),e&=e;return Math.abs(e)}(o))%K.length]}function tt(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const i=t[e];return"string"==typeof i&&i.length>0?i:void 0}function et(t,e,i="category10"){if(i&&"object"==typeof i&&!Array.isArray(i)){const t=i;return e=>tt(t,e)??"#999"}const o=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),n=o.every(t=>!isNaN(Number(t)));if(Array.isArray(i))return L().domain(o).range(i).unknown("#999");const r=Z[i]||Z.category10;if(n&&"function"==typeof r){let t=-1/0;for(const e of o){const i=Number(e);i>t&&(t=i)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:K;return L().domain(o).range(t).unknown("#999")}}function it(t,e,i=[3,20],o){let n;if(n="function"==typeof e?e(t):t?.[e],!o)return n;const[r,s]=o,[a,c]=i;if(s===r)return(a+c)/2;let l=(n-r)/(s-r);return 0>l?l=0:l>1&&(l=1),a+l*(c-a)}function ot(t,e,i){return"function"==typeof t?t(i):i[t||e]}function nt(t){return t instanceof Date?t.getTime():Number(t)}function rt(t,e){return W(1===e?.5:t/(e-1))}function st(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>ct(e(t))}function at(t,e){const i=st(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:i(t),category:null==e?void 0:e+""}}}function ct(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function lt(t,e,i){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,i):function(t,e,i){const o=null!=t.axis?i[t.axis]:null!=t.field?e[t.field]:i.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const n=ct(o);if(void 0===n)return!1;if(void 0!==t.gt&&t.gt>=n)return!1;if(void 0!==t.gte&&t.gte>n)return!1;if(void 0!==t.lt&&n>=t.lt)return!1;if(void 0!==t.lte&&n>t.lte)return!1;if(void 0!==t.within){const[e,i]=t.within;if(e>n||n>i)return!1}if(void 0!==t.outside){const[e,i]=t.outside;if(n>=e&&i>=n)return!1}return!0}(o,e,i))}function ut(t,e,i){if(!e||0===e.length)return{};let o={};for(const n of e){if(!lt(n,t,i))continue;const e="function"==typeof n.style?n.style(t,i):n.style;e&&(o={...o,...e})}return o}function ht(t,e,i,o=t=>t){const n=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=o(t),a={...n(t,r)};return Object.assign(a,ut(s,e,i(s,r))),a}:n}function dt(t,e,i){return t&&0!==t.length?(o,n)=>{const r=ut(o,t,e(o,n)),s=i?i(o,n):void 0;return s?{...r,...s}:r}:i}function ft(t,e,i,o){if(!t||0===t.length)return o;const n=at(e,i);return(e,i)=>{const r=e&&e.data||e,s=ut(r,t,n(r)),a=o?o(e,i):void 0;return a?{...s,...a}:s}}function pt(t,e,i,o){return dt(t,function(t,e){const i=st(t),o=st(e);return(t,e)=>{const n=o(t);return{value:n,x:i(t),y:n,category:e}}}(e,i),o)}function yt(t,e,i){const o=st(e);return dt(t,(t,e)=>({value:o(t),category:e}),i)}var gt={frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"line",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||e,colorAccessor:e,colorScheme:i,lineStyle:n.lineStyle,...o,...n.styleRules&&{lineStyle:pt(n.styleRules,n.xAccessor||"x",n.yAccessor||"y",o.lineStyle||n.lineStyle)}})},mt={frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"area",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||e,colorAccessor:e,colorScheme:i,...o,...n.styleRules&&{lineStyle:pt(n.styleRules,n.xAccessor||"x",n.yAccessor||"y",o.lineStyle)}})},xt={frameType:"xy",buildProps:(t,e,i,o,n)=>{const r=n.xAccessor||"x",s=n.seriesAAccessor||"a",a=n.seriesBAccessor||"b",c=t=>nt(ot(r,"x",t)),l=t=>nt(ot(s,"a",t)),u=t=>nt(ot(a,"b",t)),h=n.seriesAColor||"var(--semiotic-danger, #dc2626)",d=n.seriesBColor||"var(--semiotic-info, #2563eb)",f=n.areaOpacity??.6,p=n.lineWidth??1.5,y=!1!==n.showLines,g=function(t,e,i,o){if(!t.length)return[];const n=t.filter(t=>Number.isFinite(e(t))).sort((t,i)=>e(t)-e(i)),r=[];let s=0,a=null,c=null,l=[];const u=(t,e)=>t>e?"A":e>t?"B":null,h=t=>`seg-${s}-${t}`,d=t=>r.push(t),f=(t,e)=>{d({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:h(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;n.length>t;t++){const r=n[t],p=e(r),y=i(r),g=o(r);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;const m=u(y,g);if(null!==m)if(null!=a){if(c&&c.w!==m){let t,e;if(l.length>0)t=l[0].x,e=l[0].y;else{const i=y-c.a-(g-c.b);if(0!==i){const o=Math.max(0,Math.min(1,(c.b-c.a)/i));t=c.x+o*(p-c.x),e=c.a+o*(y-c.a)}else t=c.x,e=c.a}d({__x:t,__y:e,__y0:e,__diffSegment:h(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,d({__x:t,__y:e,__y0:e,__diffSegment:h(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;l.length>t;t++)f(l[t],a)}else for(const t of l)f(t,a);l=[],d({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:h(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else{a=m;for(const t of l)f(t,a);l=[],d({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:h(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else l.push({x:p,y:y,datum:r})}for(const t of l)f(t,a??"A");return r}(Array.isArray(t)?t:[],c,l,u),m=[];if(y&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(c(t))).sort((t,e)=>c(t)-c(e));for(const t of e){const e=c(t),i=l(t),o=u(t);Number.isFinite(i)&&m.push({__x:e,__y:i,__diffSegment:"line-A"}),Number.isFinite(o)&&m.push({__x:e,__y:o,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...g,...m],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(g.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?h:d,stroke:"none",fillOpacity:f}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?h:d,strokeWidth:p,fill:"none"}),curve:n.curve||"linear",...o}}},bt={frameType:"xy",buildProps:(t,e,i,o,n)=>{const r=e||n.areaBy,s="string"==typeof r&&Array.isArray(t)?et(t,r,i):void 0;return{chartType:"stackedarea",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:r,colorScheme:i,normalize:n.normalize,stackOrder:n.stackOrder,lineStyle:null==n.areaOpacity?void 0:t=>{const e=null==r?void 0:J(t,r,s),i=n.showLine??!0;return{fill:n.color??e,stroke:i?n.stroke??e:"none",...i?{strokeWidth:n.strokeWidth??n.lineWidth??2}:{},fillOpacity:n.areaOpacity,...null==n.opacity?{}:{opacity:n.opacity}}},...o}}},vt={frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...o,...n.styleRules&&{pointStyle:pt(n.styleRules,n.xAccessor||"x",n.yAccessor||"y",o.pointStyle)}})},wt={frameType:"xy",buildProps:(t,e,i,o,n)=>{const r=n.xCenter,s=n.yCenter,a=n.quadrants,c=n.centerlineStyle||{},l=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,h=c.stroke||"#999",d=c.strokeWidth??1,f=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,p=T.createElement,y=a?[(t,e,i)=>{if(!e?.x||!e?.y)return null;const o=i.width,n=i.height,c=null!=r?e.x(r):o/2,y=null!=s?e.y(s):n/2;if(null!=r&&!Number.isFinite(c))return null;if(null!=s&&!Number.isFinite(y))return null;const g=Math.max(0,Math.min(o,c)),m=Math.max(0,Math.min(n,y)),x=[{c:a.topLeft,x:0,y:0,w:g,h:m},{c:a.topRight,x:g,y:0,w:o-g,h:m},{c:a.bottomLeft,x:0,y:m,w:g,h:n-m},{c:a.bottomRight,x:g,y:m,w:o-g,h:n-m}],b=l?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:o-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:n-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:o-8,y:n-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(T.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?p("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),p("line",{key:"vc",x1:g,y1:0,x2:g,y2:n,stroke:h,strokeWidth:d,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:o,y2:m,stroke:h,strokeWidth:d,strokeDasharray:f}),...b)}]:void 0;return{chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange,colorScheme:i,pointStyle:n.pointStyle,...o,...y&&{svgPreRenderers:y}}}},kt={frameType:"xy",buildProps:(t,e,i,o,n)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const i=e.xAccessor||"x",o=e.yAccessor||"y",n=e.orderAccessor?[...t].sort((t,i)=>null==t||"object"!=typeof t?1:null==i||"object"!=typeof i?-1:nt(ot(e.orderAccessor,"order",t))-nt(ot(e.orderAccessor,"order",i))):t,r=new WeakMap;let s=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=nt(ot(i,"x",t)),n=nt(ot(o,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&s++}let a=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=nt(ot(i,"x",t)),n=nt(ot(o,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&r.set(t,{idx:a++,total:s})}return{data:n,orderMap:r}}(t,n),s=n.pointRadius??4;return{chartType:"line",data:r.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,colorScheme:i,lineStyle:n.lineStyle||{stroke:n.stroke||"#6366f1",strokeWidth:n.strokeWidth??s,opacity:n.opacity},pointStyle:t=>{const e=r.orderMap.get(t),i=e?.idx??0,o=e?.total??1;return{fill:o>0?rt(i,o):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},...o}}};function St(t){return Math.max(0,Math.min(1,t))}function At(t){const e=t.trim();if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t.split("").map(t=>t+t).join("")),6===t.length&&/^[0-9a-f]{6}$/i.test(t))return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const i=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i){const t=[Number(i[1]),Number(i[2]),Number(i[3])];if(t.every(Number.isFinite))return t}return null}function Mt(t,e,i){const o=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${o(t)}${o(e)}${o(i)}`}function _t(t,e){const i=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:St(t.offset),color:t.color})).sort((t,e)=>t.offset-e.offset);if(0===i.length)return"#999999";if(1===i.length)return i[0].color;const o=St(e);if(i[0].offset>=o)return i[0].color;if(o>=i[i.length-1].offset)return i[i.length-1].color;for(let t=0;i.length-1>t;t++){const e=i[t],n=i[t+1];if(e.offset>o||o>n.offset)continue;const r=n.offset-e.offset,s=r>0?(o-e.offset)/r:0,a=At(e.color),c=At(n.color);if(!a||!c)return.5>s?e.color:n.color;const[l,u,h]=a,[d,f,p]=c;return Mt(l+(d-l)*s,u+(f-u)*s,h+(p-h)*s)}return i[i.length-1].color}function Pt(t,e,i){return null==i?`${t}-${e}`:`${t}-${e}-${i}`}function Rt(t){return!0===t?{topOpacity:.8,bottomOpacity:.05}:!1===t?void 0:t}var Tt={frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,colorAccessor:e,colorScheme:i,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...o,gradientFill:Rt(o.gradientFill),...n.styleRules&&{pieceStyle:yt(n.styleRules,n.valueAccessor||"value",o.pieceStyle)}})},Lt={frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:e||n.stackBy,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...o,gradientFill:Rt(o.gradientFill),...n.styleRules&&{pieceStyle:yt(n.styleRules,n.valueAccessor||"value",o.pieceStyle)}})},Ct={frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"clusterbar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:e||n.groupBy,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...o,gradientFill:Rt(o.gradientFill),...n.styleRules&&{pieceStyle:yt(n.styleRules,n.valueAccessor||"value",o.pieceStyle)}})},$t={frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"swimlane",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:e||n.subcategoryAccessor,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...null!=n.trackFill&&{trackFill:n.trackFill},...o,gradientFill:Rt(o.gradientFill)})},zt={frameType:"ordinal",buildProps:(t,e,i,o,n)=>{const r=n.min??0,s=n.max??100,a=n.sweep??240,c=n.arcWidth??.3,l=180+(360-a)/2,u=n.thresholds||[{value:s,color:n.color||"#4e79a7"}],h=o.gradientFill,d=function(t){const{min:e,max:i,value:o,thresholds:n,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=t,h=i-e||1,d=(Math.max(e,Math.min(i,o))-e)/h;let f=n&&n.length>0?[...n].sort((t,e)=>t.value-e.value):[{value:i,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(i,t.value))})),i>f[f.length-1].value&&f.push({value:i,color:f[f.length-1].color});const p=!!l&&l.colorStops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?d:1,e=Pt("bg",0);if(y.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),i=Math.max(1,Math.min(e,Math.round(t*e))),o=[];for(let e=0;i>e;e++)o.push(_t(l.colorStops,t*(e+.5)/i));const n=Pt("fill",0);y.push({category:n,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:o}}),g.set(n,{fill:o[0]||s})}}else{let t=e;for(let i=0;f.length>i;i++){const o=f[i],n=(o.value-t)/h,r=(t-e)/h,c=(o.value-e)/h,l=Math.max(0,(a?Math.min(d,c):c)-r),u=a?Math.max(0,n-l):0;if(l>0){const t=Pt("fill",i);y.push({category:t,value:l,_zone:o.label||"Zone "+(i+1),_isFill:!0}),g.set(t,{fill:o.color})}if(u>0){const t=Pt("bg",i);y.push({category:t,value:u,_zone:o.label||"Zone "+(i+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=o.value}}if(c&&n&&n.length>0)for(const t of n)t.value>e&&i>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:y,pieceStyle:(t,e)=>g.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:n.value,thresholds:u,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:!1!==n.fillZones,showScaleLabels:!1!==n.showScaleLabels,gradientFill:h&&"object"==typeof h&&"colorStops"in h?h:void 0}),f=o.margin||{top:20,right:20,bottom:30,left:40},[p,y]=o.size||[300,300];return{chartType:"donut",data:d.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:Math.max(10,Math.min(p-(f.left||0)-(f.right||0),y-(f.top||0)-(f.bottom||0))/2*(1-c)),sweepAngle:a,startAngle:l,oSort:!1,pieceStyle:d.pieceStyle,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...o,showAxes:!1,annotations:[...Array.isArray(o.annotations)?o.annotations:[],...d.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:c,value:n.value,startAngleDeg:l,thresholds:u}}}};import{scaleTime as Dt}from"d3-scale";function Et(t){let e=1/0,i=-1/0;for(const o of t)e>o&&(e=o),o>i&&(i=o);return[e,i]}function It(t,e=-1/0){let i=e;for(const e of t)e>i&&(i=e);return i}function Ft(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:t.kind}function Nt(t,e,i){const o=e.incoming[t.id],n=e.outgoing[t.id],r=[];for(const t of o)r.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:i.get(t.id).targetSide});for(const t of n)r.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:i.get(t.id).sourceSide});const s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},a=()=>{r.sort((t,e)=>t.time-e.time||(s[t.kind]??99)-(s[e.kind]??99))},c=r.length?function(t,e=1/0){let i=e;for(const e of t)i>e&&(i=e);return i}(r.map(t=>t.time)):null,l=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,u=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,h=[...new Set(r.map(t=>t.time))].sort((t,e)=>t-e),d=new Map;for(let t=1;h.length>t;t++)d.set(h[t],h[t-1]);const f=t=>{const e=d.get(t);return null!=e?(e+t)/2:null!=u?u:t};a();const p=[];let y=0,g=0;for(const t of r)if("out"===t.kind){const e=Math.abs(t.delta);let i=e-("top"===t.side?y:g);if(i>0){const e="top"===t.side?"bot":"top",o=Math.min(i,"top"===e?y:g);if(o>0){const n=f(t.time);p.push({time:n,delta:-o,kind:"transfer-out",side:e}),p.push({time:n,delta:+o,kind:"transfer-in",side:t.side}),"top"===e?y-=o:g-=o,"top"===t.side?y+=o:g+=o,i-=o}i>0&&null!==u&&(p.push({time:u,delta:+i,kind:"create",side:t.side}),"top"===t.side?y+=i:g+=i)}"top"===t.side?y-=e:g-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?y+=e:g+=e}r.push(...p),a();let m=0,x=0,b=0,v=0,w=0;const k=[],S=new Map;for(const t of r){if(k.push({t:t.time,topMass:m,botMass:x}),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?m:x;S.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta)})}"top"===t.side?m+=t.delta:x+=t.delta,m+x>b&&(b=m+x),m>v&&(v=m),x>w&&(w=x),k.push({t:t.time,topMass:m,botMass:x})}const A=[];let M=0;for(;k.length>M;){let t=M;for(;k.length>t+1&&k[t+1].t===k[M].t;)t++;A.push(k[M]);for(let e=M+1;t>=e;e++){const t=A[A.length-1];k[e].topMass===t.topMass&&k[e].botMass===t.botMass||A.push(k[e])}M=t+1}const _=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let P=null;for(const t of n)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===P||P>t.systemInTime)&&(P=t.systemInTime);let R=null;for(const t of o)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===R||t.systemOutTime>R)&&(R=t.systemOutTime);if(A.length>0){const t=A[A.length-1],e=Math.max(null!=_?_:-1/0,null!=R?R:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&A.push({t:e,topMass:t.topMass,botMass:t.botMass});const i=A[0],o=Math.min(null!=l?l:1/0,null!=P?P:1/0);Number.isFinite(o)&&i.t>o&&i.topMass+i.botMass>0&&A.unshift({t:o,topMass:i.topMass,botMass:i.botMass})}return{samples:A,peak:b,topPeak:v,botPeak:w,localAttachments:S}}function Bt(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function Ot(t,e){return t.map(t=>({t:Bt(t.t,e),topMass:t.topMass,botMass:t.botMass}))}function Wt(t,e,i){const o=t.value*i;if("out"===t.kind){const n=t.sideMassBefore*i;if("top"===t.side){const t=e-n;return[t,t+o]}const r=e+n;return[r-o,r]}const n=t.sideMassAfter*i;if("top"===t.side){const t=e-n;return[t,t+o]}const r=e+n;return[r-o,r]}function jt(t,e){let i=0;for(let o=0;e.length>o;o++)for(let n=o+1;e.length>n;n++){const r=e[o],s=e[n];r.source!==s.source&&r.target!==s.target&&r.source!==s.target&&r.target!==s.source&&(Math.min(r.endTime,s.endTime)>Math.max(r.startTime,s.startTime)&&t[s.source]>t[r.source]!=t[s.target]>t[r.target]&&i++)}return i}function Yt(t,e){let i=0;for(const o of e)i+=Math.abs(t[o.source]-t[o.target])*(o.value||1);return i}function Xt(t,e){return 1e3*jt(t,e)+Yt(t,e)}function qt(t,e){return{slots:t.map(t=>({peak:{...t.peak},occupants:t.occupants.slice()})),map:{...e}}}function Gt(t,e,i){t.length>8||i.length>40?(function(t,e,i,o=6){const n=t.length;if(1>=n)return;let r=qt(t,e),s=Xt(e,i);for(let a=0;o>a;a++){const o=Array(n).fill(0),a=Array(n).fill(0);for(const t of i){const i=e[t.source],n=e[t.target];o[i]+=n*(t.value||1),a[i]+=t.value||1,o[n]+=i*(t.value||1),a[n]+=t.value||1}const c=Array.from({length:n},(t,e)=>e).sort((t,e)=>(a[t]>0?o[t]/a[t]:t)-(a[e]>0?o[e]/a[e]:e)),l=c.map(e=>t[e]),u=new Map;c.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of l)t.push(e);const h=Xt(e,i);if(s>h)s=h,r=qt(t,e);else if(h===s)break}!function(t,e,i){t.length=0;for(const e of i.slots)t.push(e);for(const t of Object.keys(e))delete e[t];for(const t of Object.keys(i.map))e[t]=i.map[t]}(t,e,r)}(t,e,i,6),function(t,e,i,o=6){const n=t.length;if(1>=n)return;let r=Xt(e,i);for(let s=0;o>s;s++){let o=!1;for(let s=0;n-1>s;s++){const n=t[s];t[s]=t[s+1],t[s+1]=n;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s);const a=Xt(e,i);if(r>a)r=a,o=!0;else{const i=t[s];t[s]=t[s+1],t[s+1]=i;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s)}}if(!o)break}}(t,e,i,6)):function(t,e,i){const o=t.length;if(1>=o)return;const n={...e},r=Object.keys(n),s=Array.from({length:o},(t,e)=>e),a=s.slice(),c={...n};let l=s.slice(),u=1/0;const h=()=>{for(const t of r)c[t]=a[n[t]];const t=Xt(c,i);u>t&&(u=t,l=s.slice())},d=(t,e)=>{const i=s[t],o=s[e];s[t]=o,s[e]=i,a[i]=e,a[o]=t};h();const f=Array(o).fill(0);let p=0;for(;o>p;)p>f[p]?(d(p%2==0?0:f[p],p),h(),f[p]++,p=0):(f[p]=0,p++);const y=l.map(e=>t[e]),g=new Map;l.forEach((t,e)=>g.set(t,e));for(const t of Object.keys(e))e[t]=g.get(e[t]);t.length=0;for(const e of y)t.push(e)}(t,e,i)}function Vt(t,e,i,o,n){const{plotH:r,padding:s,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="full"}=n,h={},d={};for(const e of t)h[e.id]=i[e.id].topPeak||0,d[e.id]=i[e.id].botPeak||0;const f="half"===u,p={};for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,i=Array.isArray(e.xExtent)?e.xExtent[1]:null;let n=null!=t&&Number.isFinite(t)?t:1/0,r=null!=i&&Number.isFinite(i)?i:-1/0;for(const t of o.outgoing[e.id]){n>t.startTime&&(n=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&n>t.systemInTime&&(n=t.systemInTime);const e=f?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of o.incoming[e.id]){const e=f?(t.startTime+t.endTime)/2:t.startTime;n>e&&(n=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}p[e.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(r)?r:null}}const y={},g=[];if("reuse"===c){const i=new Map;for(const e of t)i.set(e.id,0);const n=new Map;for(const e of t)n.set(e.id,0);for(const t of e)n.set(t.target,(n.get(t.target)??0)+1);const r=[];for(const e of t)0===(n.get(e.id)??0)&&r.push(e.id);for(;r.length;){const t=r.shift();for(const e of o.outgoing[t]??[]){const o=(i.get(t)??0)+1;o>(i.get(e.target)??0)&&i.set(e.target,o),n.set(e.target,n.get(e.target)-1),0===n.get(e.target)&&r.push(e.target)}}const s=[...t].filter(t=>null!==p[t.id].start).sort((t,e)=>{const o=i.get(t.id)??0,n=i.get(e.id)??0;return o!==n?o-n:p[t.id].start-p[e.id].start}),a=t.filter(t=>null===p[t.id].start);for(const t of[...s,...a]){const e=p[t.id];let i=-1;for(let t=0;g.length>t;t++){const o=g[t].occupants[g[t].occupants.length-1];if(null===e.start||void 0===o||e.start>=o.end){i=t;break}}-1===i&&(g.push({occupants:[],peak:{topPeak:0,botPeak:0}}),i=g.length-1),g[i].occupants.push({id:t.id,end:e?.end??-1/0}),g[i].peak.topPeak=Math.max(g[i].peak.topPeak,h[t.id]),g[i].peak.botPeak=Math.max(g[i].peak.botPeak,d[t.id]),y[t.id]=i}}else t.forEach((t,e)=>{g.push({occupants:[{id:t.id,end:p[t.id]?.end??-1/0}],peak:{topPeak:h[t.id],botPeak:d[t.id]}}),y[t.id]=e});let m=null,x=null,b=null,v=null;const w=()=>{m=jt(y,e),b=Yt(y,e)},k=()=>{x=jt(y,e),v=Yt(y,e)};"crossing-min"===l?(w(),Gt(g,y,e),k()):"inside-out"===l?(w(),function(t,e){const i=t.length;if(1>=i)return;const o=t=>t.peak.topPeak+t.peak.botPeak,n=t.map((t,e)=>({slot:t,idx:e})).sort((t,e)=>o(e.slot)-o(t.slot)),r=Array(i),s=Math.floor((i-1)/2);r[s]=n[0].idx;let a=s-1,c=s+1;for(let t=1;n.length>t;t++)t%2==1&&i>c||0>a?r[c++]=n[t].idx:r[a--]=n[t].idx;const l=r.map(e=>t[e]),u=new Map;r.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of l)t.push(e)}(g,y),k()):"crossing-min+inside-out"===l&&(w(),Gt(g,y,e),function(t,e,i){const o=t.length;if(1>=o)return;const n=t.map(t=>{return{slot:t,size:(e=t,e.peak.topPeak+e.peak.botPeak)};var e}).sort((t,e)=>e.size-t.size),r=Math.floor((o-1)/2);let s=Xt(e,i);for(const{slot:a}of n){const n=t.indexOf(a);if(0>n)continue;const c=r;if(n===c)continue;const l=t[n];t.splice(n,1),t.splice(c,0,l);const u=new Map;for(let t=0;o>t;t++)u.set(t,t);if(c>n){for(let t=n+1;c>=t;t++)u.set(t,t-1);u.set(n,c)}else{for(let t=c;n>t;t++)u.set(t,t+1);u.set(n,c)}for(const t of Object.keys(e))e[t]=u.get(e[t]);const h=Xt(e,i);if(h>s){const i=t[c];t.splice(c,1),t.splice(n,0,i);const r=new Map;for(let t=0;o>t;t++)r.set(t,t);if(n>c){for(let t=c+1;n>=t;t++)r.set(t,t-1);r.set(c,n)}else{for(let t=n;c>t;t++)r.set(t,t+1);r.set(c,n)}for(const t of Object.keys(e))e[t]=r.get(e[t])}else s=h}}(g,y,e),k());const S=g.map(t=>{const e=new Map;for(const o of t.occupants){const t=i[o.id];if(t)for(const i of t.samples){const t=e.get(i.t)||{top:0,bot:0};e.set(i.t,{top:Math.max(t.top,i.topMass),bot:Math.max(t.bot,i.botMass)})}}return[...e.entries()].sort((t,e)=>t[0]-e[0])}),A=(t,e)=>{let i={top:0,bot:0};for(const[o,n]of t){if(o>e)break;i=n}return i},M=[];for(let t=0;g.length-1>t;t++){const e=S[t],i=S[t+1],o=new Set([...e.map(t=>t[0]),...i.map(t=>t[0])]);let n=0;for(const t of o){const o=A(e,t),r=A(i,t);o.bot+r.top>n&&(n=o.bot+r.top)}M.push(n)}const _=[];let P=s+(g[0]?.peak.topPeak??0)*a;g.length>0&&_.push(P);for(let t=1;g.length>t;t++)P+=M[t-1]*a+s,_.push(P);if(g.length>0&&(P+=g[g.length-1].peak.botPeak*a+s),P>r){const t=r/P;for(let e=0;_.length>e;e++)_[e]*=t}const R=0===g.length?0:g[0].peak.topPeak+M.reduce((t,e)=>t+e,0)+g[g.length-1].peak.botPeak,T={};for(const e of t)T[e.id]=_[y[e.id]];return{effectiveSlotsHeight:R,centerlines:T,laneLifetime:p,slots:g,slotByNode:y,slotCenter:_,crossingsBefore:m,crossingsAfter:x,lengthBefore:b,lengthAfter:v}}function Ht(t){const{sx:e,sTop:i,sBot:o,tx:n,tTop:r,tBot:s,cp1X:a,cp2X:c}=t,l=(i+o)/2,u=(r+s)/2;return{pathD:[`M${e},${i}`,`C${a},${i} ${c},${r} ${n},${r}`,`L${n},${s}`,`C${c},${s} ${a},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:l},{x:a,y:l},{x:c,y:u},{x:n,y:u}],halfWidth:(o-i)/2}}}function Zt(t){const{nodes:e,edges:i,domain:o,plotW:n,plotH:r,ribbonLane:s,edgeOpacity:a,colorOf:c,layoutOpts:l}=t,u=function(t,e,i){const o=[],n=new Set(t.map(t=>t.id)),r=Array.isArray(i)&&2===i.length,s=r&&Number.isFinite(i[0])&&Number.isFinite(i[1]);r&&s&&s&&i[1]>=i[0]||o.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||o.push({kind:"invalid-node-time",id:e.id}));for(const t of e)n.has(t.source)||o.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),n.has(t.target)||o.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?(Number.isFinite(t.value)&&t.value>0||o.push({kind:"invalid-value",id:t.id}),t.endTime>t.startTime||o.push({kind:"backward-edge",id:t.id,source:t.source,target:t.target})):o.push({kind:"invalid-edge-time",id:t.id});return o}(e,i,o),h=Dt().domain(o).range([0,n]);if(u.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:u,xScale:h};const d=function(t,e,i){const{plotH:o,pairing:n="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half"}=i,c=function(t,e){const i={},o={};for(const e of t)i[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),i[t.target]&&i[t.target].push(t);return{incoming:i,outgoing:o}}(t,e),l=function(t,e,i,o="value"){const n="temporal"===o?(t,e)=>t.endTime-e.endTime:(t,e)=>e.value-t.value,r="temporal"===o?(t,e)=>t.startTime-e.startTime:(t,e)=>e.value-t.value,s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const i=new Map;for(const o of t){const t=o[e];i.has(t)||i.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const n=i.get(t);n.edges.push(o),n.total+=o.value,n.earliestStart=Math.min(n.earliestStart,o.startTime),n.latestEnd=Math.max(n.latestEnd,o.endTime)}const s=[...i.values()];s.sort("temporal"===o?(t,i)=>"target"===e?t.earliestStart-i.earliestStart:t.latestEnd-i.latestEnd:(t,e)=>e.total-t.total);for(const t of s)t.edges.sort("target"===e?r:n);return s};for(const e of t){const t=i.outgoing[e.id],o=i.incoming[e.id];if(0===o.length)a(t,"target").forEach((t,e)=>{const i=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=i});else if(0===t.length)a(o,"source").forEach((t,e)=>{const i=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=i});else{const e=a(o,"source"),i=a(t,"target"),n=Math.max(e.length,i.length);for(let t=0;n>t;t++){const o=t%2==0?"top":"bot";if(e[t])for(const i of e[t].edges)s.get(i.id).targetSide=o;if(i[t])for(const e of i[t].edges)s.get(e.id).sourceSide=o}}}return s}(t,e,c,n);let u={};for(const e of t)u[e.id]=Nt(e,c,l);const h=Vt(t,e,u,c,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),d=new Set;for(const t of e){const e=h.slotByNode[t.source],i=h.slotByNode[t.target];if(void 0===e||void 0===i)continue;const o=l.get(t.id);e!==i?e>i?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(d.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=c.outgoing[e.id],i=c.incoming[e.id],o=new Set(t.map(t=>l.get(t.id).sourceSide)),n=new Set(i.map(t=>l.get(t.id).targetSide));if(1===o.size&&i.length>0){const t=[...o][0];for(const e of i)h.slotByNode[e.source]===h.slotByNode[e.target]&&(l.get(e.id).targetSide=t)}if(1===n.size&&t.length>0){const e=[...n][0];for(const i of t)h.slotByNode[i.source]===h.slotByNode[i.target]&&(l.get(i.id).sourceSide=e)}}for(const e of t){const t=c.incoming[e.id],i=c.outgoing[e.id];if(0===t.length||0===i.length)continue;const o=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const i of t)"top"===l.get(i.id).targetSide?e.inTop+=i.value:e.inBot+=i.value;for(const t of i)"top"===l.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},n=(t,e)=>{const n=o(),r="top"===t?n.outTop-n.inTop:n.outBot-n.inBot,s="top"===e?n.inTop-n.outTop:n.inBot-n.outBot;if(0>=r||0>=s)return!1;const a=Math.min(r,s),c=i.filter(e=>!d.has(e.id)&&l.get(e.id).sourceSide===t&&a>=e.value).sort((t,e)=>e.value-t.value);return 0!==c.length&&(l.get(c[0].id).sourceSide=e,!0)};let r=i.length+1;for(;r-- >0&&(n("top","bot")||n("bot","top")););}u={};for(const e of t)u[e.id]=Nt(e,c,l);const f=Vt(t,e,u,c,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),p=f.effectiveSlotsHeight??f.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),y=Math.min(12,.35*o/Math.max(f.slots.length+1,1)),g=p>0?Math.max(0,(o-y*(f.slots.length+1))/p):1,m=Vt(t,e,u,c,{plotH:o,padding:y,valueScale:g,packing:r,laneOrder:s,lifetimeMode:a});return{nodeData:u,sides:l,valueScale:g,padding:y,compressedPadding:12>y,centerlines:m.centerlines,laneLifetime:m.laneLifetime,slots:m.slots,slotByNode:m.slotByNode,crossingsBefore:m.crossingsBefore,crossingsAfter:m.crossingsAfter,lengthBefore:m.lengthBefore,lengthAfter:m.lengthAfter}}(e,i,{plotH:r,...l}),{centerlines:f,nodeData:p,valueScale:y}=d,g=[],m=[];e.forEach((t,e)=>{const n=p[t.id];if(!n||0===n.samples.length)return;const r=function(t,e,i,o,n){if(0===t.length)return null;const r=Ot(t,n),s=t=>e-r[t].topMass*i,a=t=>e+r[t].botMass*i;let c=`M${o(r[0].t)},${s(0)}`;for(let t=1;r.length>t;t++)c+=` L${o(r[t].t)},${s(t)}`;c+=` L${o(r[r.length-1].t)},${a(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${o(r[t].t)},${a(t)}`;return c+" Z"}(n.samples,f[t.id],y,h,o);if(!r)return;const s=Ot(n.samples,o),a=s.find(t=>t.topMass+t.botMass>0)||s[0],l=f[t.id]+(a.botMass-a.topMass)*y/2,u=c(t.id,e),m=function(t,e,i,o,n){const r=i.nodeData[t];if(!r||0===r.samples.length)return[];const s=i.valueScale,a=i.centerlines[t],c=Ot(r.samples,n),l=c.find(t=>t.topMass+t.botMass>0)||c[0],u=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=o(l.t),d=o(u.t),f=t=>o(Bt(t,n)),p=[],y=(t,e,i,o)=>`M${t},${e} L${i},${e} L${i},${o} L${t},${o} Z`;for(const i of e){if(i.source===t&&null!=i.systemInTime&&Number.isFinite(i.systemInTime)){const t=r.localAttachments.get(i.id);if(t&&"out"===t.kind&&i.startTime>i.systemInTime){const e=f(i.systemInTime),o=f(i.startTime),n=e-20,r=Math.max(h,n);if(o>r){const[i,c]=Wt(t,a,s);p.push({pathD:y(r,i,o,c),x0:n,x1:e,from:0,to:1})}}}if(i.target===t&&null!=i.systemOutTime&&Number.isFinite(i.systemOutTime)){const t=r.localAttachments.get(i.id);if(t&&"in"===t.kind&&i.systemOutTime>i.endTime){const e=f(i.systemOutTime),o=f(i.endTime),n=e+20,r=Math.min(d,n);if(r>o){const[i,c]=Wt(t,a,s);p.push({pathD:y(o,i,r,c),x0:e,x1:n,from:1,to:0})}}}}return p}(t.id,i,d,h,o);g.push({id:t.id,pathD:r,fill:u,stroke:u,strokeWidth:.5,...m.length>0&&{gradientStubs:m},rawDatum:t.__raw??t,labelX:h(a.t)-4,labelY:l,labelText:t.id})});const x=new Map;return e.forEach((t,e)=>x.set(t.id,e)),i.forEach(t=>{const e=p[t.source]?.localAttachments.get(t.id),i=p[t.target]?.localAttachments.get(t.id);if(!e||!i)return;const n=x.get(t.source)??0,r=c(t.source,n),l=function(t,e,i,o,n,r,s,a){const c=n,l=t=>a?Math.max(a[0],Math.min(a[1],t)):t,u=r(l(t.time)),h=r(l(i.time)),d=t.value*c,f=i.value*c,p=t.sideMassBefore*c,y=i.sideMassAfter*c;let g,m,x,b;"top"===t.side?(g=e-p,m=g+d):(m=e+p,g=m-d),"top"===i.side?(x=o-y,b=x+f):(b=o+y,x=b-f);const v="source"===s?u+.85*(h-u):"target"===s?u+.15*(h-u):(u+h)/2;return{sx:u,sTop:g,sBot:m,tx:h,tTop:x,tBot:b,cp1X:v,cp2X:v}}(e,f[t.source],i,f[t.target],y,h,s,o),{pathD:u,bezier:d}=Ht(l);m.push({id:t.id,pathD:u,fill:r,opacity:a,rawDatum:t.__raw??t,bezier:d})}),{layout:d,layoutConfig:{bands:g,ribbons:m,showLabels:!0},issues:[],xScale:h}}var Kt=t=>{const{bands:e=[],ribbons:i=[],showLabels:o=!0}=t.config,n=[];for(const t of i)n.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:t.opacity,stroke:"none"},datum:{__kind:"ribbon",data:t.rawDatum,id:t.id}});for(const t of e)if(t.gradientStubs)for(let e=0;t.gradientStubs.length>e;e++){const i=t.gradientStubs[e];n.push({type:"bezier",pathD:i.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:.86,stroke:"none"},_gradient:{x0:i.x0,x1:i.x1,from:i.from,to:i.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${e}`}})}for(const t of e)n.push({type:"bezier",pathD:t.pathD,style:{...t.gradientStubs&&t.gradientStubs.length>0?{fill:"none"}:{fill:t.fill,fillOpacity:.86},stroke:t.stroke??t.fill,strokeWidth:t.strokeWidth??.5},datum:{__kind:"band",data:t.rawDatum,id:t.id}});const r=o?e.map(t=>({x:t.labelX,y:t.labelY,text:t.labelText,anchor:"end",baseline:"middle",fontSize:11,fontWeight:600})):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:n,labels:r}},Ut={frameType:"network",buildProps:(t,e,i,o,n)=>{const{edgeWidth:r,edgeColor:s,edgeOpacity:a}=n,c=n.edgeStyle??(void 0!==r||void 0!==s||void 0!==a?t=>{const e=t?.data||t;let i=1;if("number"==typeof r)i=r;else if("function"==typeof r)i=r(e);else if("string"==typeof r){const t=e?.[r],o="number"==typeof t?t:Number(t);i=Number.isFinite(o)&&o>0?o:1}return{stroke:s??"#999",strokeWidth:i,opacity:a??.6}}:void 0);return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:e,colorScheme:i,iterations:n.iterations,forceStrength:n.forceStrength,showLabels:n.showLabels,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize,nodeSizeRange:n.nodeSizeRange,nodeStyle:ft(n.styleRules,e,"number"==typeof n.nodeSize?void 0:n.nodeSize,n.nodeStyle)??n.nodeStyle,edgeStyle:c,...o}}},Qt={frameType:"network",buildProps:(t,e,i,o,n)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=n.sourceAccessor||"source",a=n.targetAccessor||"target",c=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",u=n.startTimeAccessor||"startTime",h=n.endTimeAccessor||"endTime",d=n.systemInTimeAccessor,f=n.systemOutTimeAccessor,p=n.xExtentAccessor||"xExtent",y=n.edgeIdAccessor||"id",g=(t,e)=>"function"==typeof t?t(e):e[t],m=Array.isArray(n.edges)?n.edges:[],x=Array.isArray(n.nodes)?n.nodes:[],b=x.length>0?x:function(t,e,i,o){const n=new Set;return e.forEach(t=>{const e="function"==typeof i?i(t):t[i],r="function"==typeof o?o(t):t[o];n.add(e),n.add(r)}),Array.from(n).map(t=>({id:t}))}(0,m,s,a),v=[r(n.domain?.[0]),r(n.domain?.[1])],w=b.map(t=>{const e=g(l,t)+"",i=g(p,t),o={id:e,__raw:t};if(Array.isArray(i)&&2===i.length){const t=r(i[0]),e=r(i[1]);Number.isFinite(t)&&Number.isFinite(e)&&(o.xExtent=[t,e])}return o}),k=m.map((t,e)=>{const i=g(y,t),o={id:null!=i?i+"":`${g(s,t)}-${g(a,t)}-${e}`,source:g(s,t)+"",target:g(a,t)+"",value:Number(g(c,t)),startTime:r(g(u,t)),endTime:r(g(h,t)),__raw:t};if(d){const e=r(g(d,t));Number.isFinite(e)&&(o.systemInTime=e)}if(f){const e=r(g(f,t));Number.isFinite(e)&&(o.systemOutTime=e)}return o}),[S,A]=o.size??[600,400],M={top:20,right:20,bottom:20,left:20,...o.margin},_=o.legendPosition??"right";o.showLegend&&("right"===_?M.right=Math.max(M.right,100):"left"===_?M.left=Math.max(M.left,100):"bottom"===_?M.bottom=Math.max(M.bottom,70):"top"===_&&(M.top=Math.max(M.top,40)));const P=M,R=S-P.left-P.right,T=A-P.top-P.bottom,L=Array.isArray(i)?i:null,C=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],$="function"==typeof e?e:null,z=$?b.map(t=>({_cat:$(t)})):b,D=$?"_cat":"string"==typeof e?e:void 0,E=D?et(z,D,i):null,I=new Map;for(const t of w)I.set(t.id,t.__raw);const{layoutConfig:F,issues:N}=Zt({nodes:w,edges:k,domain:v,plotW:R,plotH:T,ribbonLane:n.ribbonLane||"both",edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:(t,i)=>{if(e&&I.has(t)){const i=I.get(t);return $?J({_cat:$(i)},"_cat",E??void 0):J(i,"string"==typeof e?e:"id",E??void 0)}const o=L||C;return o[i%o.length]},layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half"}});if(N.length>0){const t=N.map(Ft).join("; ");throw Error("ProcessSankey: data invalid — "+t)}return{chartType:"force",nodes:b,edges:m,customNetworkLayout:Kt,layoutConfig:F,sourceAccessor:s,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:e,colorScheme:i,...o,margin:P}}};import{useMemo as Jt,useCallback as te,useState as ee,useId as ie,useEffect as oe,useRef as ne}from"react";import{scaleSequential as re}from"d3-scale";function se(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var ae={frameType:"geo",buildProps:(t,e,i,o,n)=>{const r="string"==typeof i?i:"blues",s=n.areaStyle??function(t,e,i,o){if(!Array.isArray(t))return;const n=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let r=1/0,s=-1/0;for(const e of t){const t=n(e);null!=t&&isFinite(t)&&(r>t&&(r=t),t>s&&(s=t))}const a=re(H(i)).domain([Number.isFinite(r)?r:0,Number.isFinite(s)?s:1]);return t=>{const e=n(t);return{fill:null!=e&&isFinite(e)?a(e):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:o}}}(n.areas,n.valueAccessor,r,n.areaOpacity??1),a=n.styleRules?ht(s,n.styleRules,t=>{return{value:(e=t,"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0)};var e},se):s;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:a,valueAccessor:n.valueAccessor,colorScheme:r,graticule:n.graticule,fitPadding:n.fitPadding,...o}}},ce={frameType:"geo",buildProps:(t,e,i,o,n)=>{const r=t||n.points,s=n.pointStyle??function(t,e,i,o){const n=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",o="string"==typeof e?n:n.map(t=>({...t,__geoColorBy:e(t)}));r=et(o,t,i)}if(o.sizeBy){const t=n.map("function"==typeof o.sizeBy?o.sizeBy:t=>t?.[o.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=Et(t))}return t=>({fill:e&&r?J(t,e,r):"#007bff",fillOpacity:o.fillOpacity,stroke:"#fff",strokeWidth:o.strokeWidth,r:o.sizeBy?it(t,o.sizeBy,o.sizeRange,s):o.pointRadius??6})}(r,e,i,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=n.styleRules?ht(s,n.styleRules,at(e,n.sizeBy)):s;return{points:r,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle,pointStyle:a,sizeBy:n.sizeBy,colorBy:e,colorScheme:i,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...o}}},le={frameType:"geo",buildProps:(t,e,i,o,n)=>{const r=(Array.isArray(t)?t:null)||n.flows||[],s=n.nodeIdAccessor||"id",a=n.valueAccessor||"value",c=n.xAccessor||"lon",l=n.yAccessor||"lat",u="function"==typeof c?c:t=>t[c],h="function"==typeof l?l:t=>t[l],d=(n.nodes||[]).map(t=>({...t,x:u(t),y:h(t)})),f=new Map;for(const t of d)f.set(t[s]+"",t);const p=n.edgeColorBy??e,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),i=f.get(t.target+"");return e&&i?{...t,coordinates:[{x:e.x,y:e.y},{x:i.x,y:i.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=p?y?et(g.map(t=>({[m]:p(t)})),m,i||"category10"):et(g,p,i||"category10"):null,b=t=>p&&x?J(t,p,x):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[S,A]=n.edgeWidthRange??[1,8],M=A-S,_=n.edgeOpacity??.6,P=n.edgeLinecap??"round";return{lines:g,points:d,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:i,lineStyle:t=>{const e=Number(t?.[a]),i=Number.isFinite(e)?e:v,o=S+Math.max(0,Math.min(1,k>0?(i-v)/k:0))*M;return{stroke:b(t),strokeWidth:o,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...o}}};function ue(t){const[e,i]=t;return{width:e,height:i,plot:{x:32,y:24,width:Math.max(80,e-64),height:Math.max(80,i-58)}}}function he(t){const e=(t??"")+"";if(!e)return"#4e79a7";const i=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let o=0;for(let t=0;e.length>t;t+=1)o=31*o+e.charCodeAt(t)>>>0;return i[o%i.length]}function de(t,e="#4e79a7",i){const o=i?.styleRules,n=!!o&&o.length>0,r=n?st(i?.valueAccessor):void 0;return i=>{const s=i.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,c={fill:null==a?e:he(a),stroke:"#111827",strokeWidth:1,opacity:.9};return n&&s&&Object.assign(c,ut(s,o,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function fe(t,e,i,o){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:i},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...o}}}function pe(t,e,i){return"function"==typeof i?i(t,e):t[i]}function ye(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:null}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:null}function ge(t,e,i){return Math.max(e,Math.min(i,t))}function me(t,e){const i=ye(t);return null!=i&&i>0?i:e}function xe(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function be(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}import{scaleLinear as ve}from"d3-scale";var we={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},ke=1e-9,Se=.005;function Ae(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function Me(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function _e(t,e,i){return Math.max(e,Math.min(i,t))}function Pe(t){return 0>t?-1:1}function Re(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,i=t.shape.height/2;return{minX:t.x-e,minY:t.y-i,maxX:t.x+e,maxY:t.y+i}}function Te(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,i=e.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}const i=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-i,minY:Math.min(e.y1,e.y2)-i,maxX:Math.max(e.x1,e.x2)+i,maxY:Math.max(e.y1,e.y2)+i}}function Le(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function Ce(t,e,i,o,n,r,s,a){const c=n-t,l=(i+s)/2-Math.abs(c);if(0>=l)return null;const u=r-e,h=(o+a)/2-Math.abs(u);return h>0?h>l?{nx:Pe(c),ny:0,penetration:l}:{nx:0,ny:Pe(u),penetration:h}:null}function $e(t,e,i,o,n,r,s){const a=r/2,c=s/2;let l=t-_e(t,o-a,o+a),u=e-_e(e,n-c,n+c);const h=l*l+u*u;if(h>i*i)return null;if(ke>=h){const r=Math.abs(t-(o-a)),s=Math.abs(t-(o+a)),h=Math.abs(e-(n-c)),d=Math.abs(e-(n+c)),f=Math.min(r,s,h,d);return f===r?(l=-1,u=0,{nx:l,ny:u,penetration:i+r}):f===s?(l=1,u=0,{nx:l,ny:u,penetration:i+s}):f===h?(l=0,u=-1,{nx:l,ny:u,penetration:i+h}):(l=0,u=1,{nx:l,ny:u,penetration:i+d})}const d=Math.sqrt(h);return{nx:l/d,ny:u/d,penetration:i-d}}function ze(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,i,o,n,r){const s=o-t,a=n-e,c=i+r,l=s*s+a*a;if(l>=c*c)return null;if(ke>=l)return{nx:1,ny:0,penetration:c};const u=Math.sqrt(l);return{nx:s/u,ny:a/u,penetration:c-u}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return Ce(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const i=$e(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return i?{nx:-i.nx,ny:-i.ny,penetration:i.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?$e(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function De(t,e){const i=e.shape;return"aabb"===i.type?"circle"===t.shape.type?$e(t.x,t.y,t.shape.radius,i.x,i.y,i.width,i.height):Ce(i.x,i.y,i.width,i.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,i,o,n,r,s,a=0){const c=r-o,l=s-n,u=c*c+l*l,h=u>ke?_e(((t-o)*c+(e-n)*l)/u,0,1):0,d=i+a/2,f=t-(o+c*h),p=e-(n+l*h),y=f*f+p*p;if(y>=d*d)return null;if(ke>=y){const t=Math.sqrt(u);return t>ke?{nx:-l/t,ny:c/t,penetration:d}:{nx:1,ny:0,penetration:d}}const g=Math.sqrt(y);return{nx:f/g,ny:p/g,penetration:d-g}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,i.x1,i.y1,i.x2,i.y2,i.thickness??0)}function Ee(t,e){return`${t}\0${e}`}function Ie(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Fe(t){return{id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,bodyCollisions:t.bodyCollisions,shape:Ae(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function Ne(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function Be(t){return{id:t.id,shape:Me(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:Ne(t.bodyFilter),index:t.index}}function Oe(t,e){return!!e?.some(e=>Object.is(t,e))}function We(t,e){const i=t.bodyFilter;if(!i)return!0;if("function"==typeof i)return i(e);const o=function(t,e){if(!e)return;let i=t;for(const t of e.split(".")){if(null==i||"object"!=typeof i)return;i=i[t]}return i}(e,i.property);return!("equals"in i&&!Object.is(o,i.equals)||"notEquals"in i&&Object.is(o,i.notEquals)||i.oneOf&&!Oe(o,i.oneOf)||i.notOneOf&&Oe(o,i.notOneOf))}var je=class{constructor(t={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...we,...t},this.random=n(this.options.seed)}init(t={}){this.options={...we,...t},this.random=n(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(ke,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:Ae(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))Ie(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:Me(e.shape),bodyFilter:Ne(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,i){const o=this.bodies.get(t);o&&(o.vx+=e/o.mass,o.vy+=i/o.mass,this.wake(o))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const i=this.sortedBodies();for(const t of i)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const o=this.options.maxVelocity;for(const t of i)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,o>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>o){const i=o/e;t.vx*=i,t.vy*=i}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const n=this.bodyPairKeys(i),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(i,n,0===t),this.resolveColliders(i,r,0===t);this.updateSensors(i),this.updateSleeping(i,e)}settle(t=1200,e=this.options.fixedDt){let i=0;for(;t>i&&!this.allSleeping();)this.step(e),i+=1;return i}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:Ae(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Ie)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Fe),colliders:this.sortedColliders().map(Be),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(t){this.options={...t.options,gravity:{...t.options.gravity}},this.random=n(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(t.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const e of t.bodies){const t=Fe(e);this.bodies.set(t.id,t),this.nextBodyIndex=Math.max(this.nextBodyIndex,t.index+1)}this.nextColliderIndex=0;for(const e of t.colliders){const t=Be(e);this.colliders.set(t.id,t),this.nextColliderIndex=Math.max(this.nextColliderIndex,t.index+1)}this.nextSpringIndex=0;for(const e of t.springs){this.springs.set(e.id,{...e,target:{...e.target}});const t=/^spring-(\d+)$/.exec(e.id);t&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(t[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const i=this.bodies.get(e.bodyId);if(!i||i.sleeping)continue;const o="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!o)continue;const n=o.x-i.x,r=o.y-i.y,s=Math.sqrt(n*n+r*r);if(ke>=s)continue;const a=n/s,c=r/s,l=(s-e.restLength)*e.stiffness+((("vx"in o?o.vx:0)-i.vx)*a+(("vy"in o?o.vy:0)-i.vy)*c)*e.damping;i.vx+=l*a*t/i.mass,i.vy+=l*c*t/i.mass}}resolveBodyPairs(t,e,i){for(const o of e){const[e,n]=o.split(":").map(Number),r=t[e],s=t[n];if(!r||!s)continue;const a=ze(r,s);a&&(this.resolveDynamicCollision(r,s,a),i&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),i=new Map;for(let o=0;t.length>o;o+=1){if(!1===t[o].bodyCollisions)continue;const n=Re(t[o]),r=Math.floor(n.minX/e),s=Math.floor(n.maxX/e),a=Math.floor(n.minY/e),c=Math.floor(n.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;c>=e;e+=1){const n=`${t}:${e}`,r=i.get(n);r?r.push(o):i.set(n,[o])}}const o=new Set;for(const e of Array.from(i.keys()).sort()){const n=i.get(e)??[];n.sort((t,e)=>t-e);for(let e=0;n.length>e;e+=1)for(let i=e+1;n.length>i;i+=1){const r=n[e],s=n[i];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&Le(Re(t[r]),Re(t[s]))&&o.add(`${r}:${s}`)}}return Array.from(o).sort((t,e)=>{const[i,o]=t.split(":").map(Number),[n,r]=e.split(":").map(Number);return i===n?o-r:i-n})}resolveDynamicCollision(t,e,i){t.sleeping&&this.supportedThisStep.add(e.id),e.sleeping&&this.supportedThisStep.add(t.id);const o=t.sleeping?0:1/t.mass,n=e.sleeping?0:1/e.mass,r=o+n;if(ke>=r)return;const s=Math.max(0,i.penetration-Se)/r;t.x-=i.nx*s*o,t.y-=i.ny*s*o,e.x+=i.nx*s*n,e.y+=i.ny*s*n;const a=(e.vx-t.vx)*i.nx+(e.vy-t.vy)*i.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution))*a/r,u=l*i.nx,h=l*i.ny;t.vx-=u*o,t.vy-=h*o,e.vx+=u*n,e.vy+=h*n,this.applyFriction(t,e,i,l,o,n),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,i,o,n,r){const s=-i.ny,a=i.nx,c=(e.vx-t.vx)*s+(e.vy-t.vy)*a,l=n+r;if(ke>=Math.abs(c)||ke>=l)return;const u=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction))),h=_e(-c/l,-o*u,o*u),d=h*s,f=h*a;t.vx-=d*n,t.vy-=f*n,e.vx+=d*r,e.vy+=f*r}resolveColliders(t,e,i){for(const o of t)for(const t of e){if(!We(t,o))continue;if(!Le(Re(o),Te(t)))continue;const e=De(o,t);e&&(this.resolveStaticCollision(o,t,e),this.supportedThisStep.add(o.id),i&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,i){t.x+=i.nx*Math.max(0,i.penetration-Se),t.y+=i.ny*Math.max(0,i.penetration-Se);const o=t.vx*i.nx+t.vy*i.ny;if(0>o){const n=Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution);t.vx-=(1+n)*o*i.nx,t.vy-=(1+n)*o*i.ny;const r=-i.ny,s=i.nx,a=t.vx*r+t.vy*s,c=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction)));t.vx-=a*r*c,t.vy-=a*s*c}}updateSensors(t){const e=new Set,i=this.sortedColliders().filter(t=>t.sensor);for(const o of t){const t=Re(o);for(const n of i){if(!We(n,o))continue;if(!Le(t,Te(n)))continue;if(!De(o,n))continue;const i=Ee(n.id,o.id);e.add(i),this.activeSensors.has(i)||this.lastEvents.push({type:"sensor-enter",bodyId:o.id,sensorId:n.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:i,bodyId:o}=Ie(t);this.lastEvents.push({type:"sensor-exit",bodyId:o,sensorId:i})}this.activeSensors=e}updateSleeping(t,e){const i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const o of t)Math.sqrt(o.vx*o.vx+o.vy*o.vy)>=this.options.sleepSpeed||Math.sqrt((o.x-o.prevX)*(o.x-o.prevX)+(o.y-o.prevY)*(o.y-o.prevY))>=this.options.sleepSpeed*e||i&&!this.supportedThisStep.has(o.id)?o.sleeping?this.wake(o):o.sleepTime=0:(o.sleepTime+=e,o.sleeping||this.options.sleepAfter>o.sleepTime||(o.sleeping=!0,o.vx=0,o.vy=0,this.lastEvents.push({type:"sleep",bodyId:o.id})))}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},Ye=class{constructor(t={}){this.id="builtin",this.capabilities={...(new je).capabilities,engine:"builtin"},this.world=new je(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Xe(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new Ye(t)}(e)}var qe=["binId","targetBin","category","windowIndex","lane","group"];function Ge(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const i=e-t.mean;t.mean+=i/t.count,t.m2+=i*(e-t.mean)}function Ve(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function He(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function Ze(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function Ke(t,e,i){return"function"==typeof t?t(e,i):"string"==typeof t?Ze(e,t):void 0}function Ue(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function Qe(t){const e=Ve(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Ve(t.x),y:Ve(t.y),value:e}}var Je=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const i=Ue(Ke(this.config.binAccessor,t,e))??function(t){for(const e of qe){const i=Ue(Ze(t,e));if(i)return i}return"sediment"}(t),o=Ue(Ke(this.config.labelAccessor,t,e))??i,n=function(t,e,i){if("number"==typeof t)return t;const o="function"==typeof t?t(e,i):"string"==typeof t?Ze(e,t):1,n="number"==typeof o?o:Number(o);return Number.isFinite(n)?n:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(i);return s||(s={id:i,label:o,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(i,s)),s.label=o,s.lastBodyId=t.id,s.lastDatum=t.datum,Ge(s.x,t.x),Ge(s.y,t.y),Ge(s.value,n),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Qe(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Qe)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:He(e.x),y:He(e.y),value:He(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function ti(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var ei={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},ii={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function oi(t={},e=ii){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function ni(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function ri(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function si(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function ai(t){return{...ni(t),sequence:t.sequence,spawnAt:t.spawnAt}}function ci(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function li(t){return!1!==t&&{...t}}function ui(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function hi(t){return{...t,gravity:{...t.gravity}}}function di(t,e,i,o){if("circle"===t.shape.type){const n=t.x-e,r=t.y-i,s=t.shape.radius+o,a=n*n+r*r;return a>s*s?null:a}const n=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(i-t.y)-t.shape.height/2,0),s=n*n+r*r;return s>o*o?null:s}function fi(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function pi(t,e={}){const{idPrefix:i="plot",includeFloor:o=!0,includeCeiling:n=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=e,l=[],u=t.x+t.width/2,h=t.y+t.height/2;return o&&l.push({id:i+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+c/2,width:t.width+2*a,height:c}}),n&&l.push({id:i+"-ceiling",shape:{type:"aabb",x:u,y:t.y-c/2,width:t.width+2*a,height:c}}),r&&l.push({id:i+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:h,width:a,height:t.height+2*c}}),s&&l.push({id:i+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:h,width:a,height:t.height+2*c}}),l}function yi(t){const{idPrefix:e="bin",count:i,domainStart:o,domainStep:n,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:u=!0,closedBefore:h,lidY:d=s,lidThickness:f=Math.max(2,c)}=t,p=[],y=s+(a-s)/2,g=Math.abs(a-s),m=l?i:i-1;if(u||l)for(let t=l?0:1;m>=t;t+=1){if(!u&&t>0&&i>t)continue;const s=r(o+t*n);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:y,width:c,height:g}})}if(null!=h)for(let t=0;i>t;t+=1){const i=o+t*n,s=i+n;if(s>=h)continue;const a=r(i),l=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:d,x2:Math.max(a,l)-c/2,y2:d,thickness:f}})}return p}var gi={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function mi(t,e){const i={...t};for(const t of e)i[gi[t]]++;return i}function xi(t,e,i){const o=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:o,revisions:mi(i,o)}}var bi=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=xi({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}record(t,e){const i=xi(t,e,this.revisions);this.revisions=i.revisions,this.latest=i;for(const t of[...this.listeners])t();return i}};import{quadtree as vi}from"d3-quadtree";var wi=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,i,o,n,r=0){const s=this.ensure(t,e);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,u=o-l,h=o+l,d=n-l,f=n+l;return s.visit((t,e,s,l,p)=>{if(u>l||e>h||d>p||s>f)return!0;if(t.length)return!1;let y=t;for(;y;){const t=y.data;if(t){const e=di(t,o,n,Math.max(0,r));null!=e&&(c>e||e===c&&i.indexOf(t.id)>i.indexOf(a?.id??""))&&(a=t,c=e)}y=y.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const i=t.readState();return 0===i.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=i.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=vi().x(t=>t.x).y(t=>t.y).addAll(i),this.revision=e,this.tree)}},ki=["data","scene-geometry","data-paint","accessibility","evidence"],Si=["scene-geometry","data-paint","accessibility","evidence"],Ai=["overlay","accessibility","evidence"],Mi=(t,e)=>({retainedData:t,invalidations:e}),_i=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Pi=["scene-geometry","data-paint","accessibility","evidence"],Ri=[],Ti={engine:Mi("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:Mi("preserve",Pi),colliders:Mi("preserve",Pi),sediment:Mi("preserve",Pi),bodyBudget:Mi("preserve",_i),bodyLimit:Mi("preserve",_i),eviction:Mi("preserve",_i),fixedDt:Mi("preserve",Ri),maxDeltaSeconds:Mi("preserve",Ri),maxSubsteps:Mi("preserve",Ri),settleStepLimit:Mi("preserve",Ri),timeScale:Mi("preserve",Ri),observation:Mi("preserve",Ri)},Li=Mi("preserve",_i);function Ci(t){let e="preserve";const i=new Set;for(const o of t){const t=Ti[o]??Li;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}var $i=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function zi(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&$i.every(i=>t[i]===e[i])}function Di(t,e,i,o){return t||!e?"paused":i||!o?"running":"settled"}var Ei=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new wi,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new bi,this.simulationState="settled",this.visible=!0;const{bodyBudget:e,colliders:i,engine:o,kernel:n,observation:r,sediment:s,...a}=t;this.config={...ei,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=o,this.observation=oi(r),this.sediment=new Je(s??!1),this.world=Xe(o,{fixedDt:this.config.fixedDt,...n}),i&&this.world.setColliders(ci(i))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(i=>"kernel"===i?!zi(t.kernel,e.kernel):t[i]!==e[i])}(t,this.configInput),{colliders:i,bodyBudget:o,engine:n,kernel:r,observation:s,sediment:a,...c}=t;if(this.config={...this.config,...c},void 0!==o&&(this.bodyBudget=o,!1===o&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=Xe(n,t.options),this.world.restore(t),this.revision+=1}if(r&&!zi(r,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...r,gravity:{...t.options.gravity,...r.gravity}};this.world.restore({...t,options:e}),this.revision+=1}s&&(this.observation=oi(s,this.observation)),this.sediment.updateConfig(a),i&&(this.world.setColliders(ci(i)),this.revision+=1),this.configInput={...this.configInput,...t};const l=Ci(e);this.updateResults.record({kind:"config",keys:e},l.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(ci(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Ci(["colliders"]).invalidations)}enqueue(t,e){const i=Array.isArray(t)?t:[t],o=e?function(t,e={}){const i=ri(e.startAt)??0,o=e.pacing??"immediate";if("arrival"===o){const o=t.map((t,i)=>function(t,e,i){return"function"==typeof i?ri(i(t,e)):"string"==typeof i?ri(si(t,i)):ri(t.spawnAt)??ri(si(t,"arrivalTime"))??ri(si(t,"timestamp"))??ri(si(t,"time"))??ri(si(t,"eventTime"))}(t,i,e.timeAccessor)),n=o.filter(t=>null!=t),r=n.length>0?Math.min(...n):0,s=ri(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const n=o[e],s=null==n?0:Math.max(0,n-r);return{...ni(t),spawnAt:i+s/a}})}if("object"==typeof o){const e=ri(o.ratePerSec);if(e&&e>0)return t.map((t,o)=>({...ni(t),spawnAt:i+o/e}))}return t.map(t=>({...ni(t),spawnAt:i}))}(i,{...e,startAt:e.startAt??this.elapsedSeconds}):i;for(const t of o)this.queue.push({...ni(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(ui),o.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:o.length},o.length?ki:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(ni(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},ki)}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},ki)}tick(t){const e=this.revision,i=[],o=[],n=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,i,o,n,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(i,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);o.push(...l.evicted),n.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(u>0||i.length>0||o.length>0||n.length>0||r.length>0)&&(this.revision+=1);const h=this.result(u,i,o,n,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?i.length||o.length||n.length?ki:Si:[]),h}settle(t=this.config.settleStepLimit){const e=this.revision;this.spawnDue([],[]);const i=this.world.settle(t,this.config.fixedDt);return i>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:i},this.revision!==e?Si:[]),i}settleWithObservations(t=this.config.settleStepLimit){const e=this.revision,i=[],o=[],n=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,i,o,n,r,s,!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(i,s);const a=this.observeBodyBudget(s),c=this.evictOverflow(s);o.push(...c.evicted),n.push(...c.sedimented),this.syncSimulationState(s);let l=0;for(;t>l&&!this.world.allSleeping();){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),l+=1}(l>0||i.length>0||o.length>0||n.length>0||r.length>0)&&(this.revision+=1);const u=this.result(l,i,o,n,r,s,void 0,a);return this.updateResults.record({kind:"settle",count:l},this.revision!==e?i.length||o.length||n.length?ki:Si:[]),u}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:i=0,binWidth:o=24,gap:n=2,maxHeight:r=80,value:s="count",x:a}=e,c=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const l=Math.max(0,t[s]/c*r),u=a?.(t,e)??e*(o+n);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:i-l,width:o,height:l,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,i=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,i)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}hasPendingWork(){return this.queue.length>0||!this.world.allSleeping()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:i,chartId:o,...n}=t,r={...n,timestamp:e??this.elapsedSeconds,chartType:i??this.observation.chartType,chartId:o??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?Ai:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?Ai:[])}remove(t){const e=new Set(t),i=new Set(this.liveBodyOrder),o=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const n=t.filter(t=>i.has(t)||o.has(t));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?ki:[]),n}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Si),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Si)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},Si)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,i,o)=>t.applyImpulse(e,i,o),clear:()=>t.clear(),hitTest:(e,i,o)=>t.hitTest(e,i,o),pause:()=>t.setPaused(!0),push:(e,i)=>t.enqueue(e,i),pushMany:(e,i)=>t.enqueue(e,i),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:li(this.bodyBudget),config:{...this.config,kernel:hi(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(ai),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:li(t.bodyBudget??{}),kernel:hi(t.world.options)},this.bodyBudget=li(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(ai).sort(ui),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??Di(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},ki)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const i=this.queue.shift();if(!i)return;this.spawnOne(i,e),t.push(i.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const i=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:i?.datum??t.datum,x:i?.x??t.x,y:i?.y??t.y},e)}result(t,e,i,o,n,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!c),sleeping:c,sedimented:o,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,i){if(0===e.length)return;const o=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=o.get(t.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,i){const o=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===o.size&&0===e.size)return o;const n=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:o,bodyId:r}=fi(e),s=i.observation.sensors[o],a=n.get(r);i.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:o,binId:s?.binId??o})};for(const t of Array.from(o).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())o.has(t)||r("exit",t);return o}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const i of t)e.has(fi(i).bodyId)&&t.delete(i)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return function(t){const e=Math.max(0,Math.floor(t.liveBodies)),i=Math.max(0,Math.floor(t.queuedBodies??0)),o=e+i,n=ti(t.bodyLimit),r=ti(t.engineMaxBodiesHint),s=function(t,e,i){if(!1===i)return;const o=ti(i?.warnAt);return null!=o?o:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(n,r,t.options),a=null==n?0:Math.max(0,e-n),c=a>0?"overflow":null==s||s>o?"ok":"warning";return{action:"overflow"!==c?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:o,queuedBodies:i,state:c,warnAt:s}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const i=`${e.state}:${e.action}`;return i===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=i,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=Di(this.paused,this.visible,this.queue.length>0,this.world.allSleeping());if(e===this.simulationState)return;const i=this.simulationState;this.simulationState=e,function(t,e,i){i.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||i.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:e,previousSimulationState:t})}(i,e,this.observationContext(t))}evictOverflow(t){if(!1===this.config.eviction)return{evicted:[],sedimented:[]};const e=Math.max(0,Math.floor(this.config.bodyLimit));if(!Number.isFinite(e))return{evicted:[],sedimented:[]};const i=this.liveBodyOrder.length-e;if(0>=i)return{evicted:[],sedimented:[]};const o=("sleeping-first"===this.config.eviction?this.sleepingFirstEvictionOrder():this.liveBodyOrder.slice()).slice(0,i);if(0===o.length)return{evicted:[],sedimented:[]};const n=this.absorbSediment(o,t);this.world.remove(o);const r=new Set(o);return this.liveBodyOrder=this.liveBodyOrder.filter(t=>!r.has(t)),this.removeActiveSensorPairsForBodies(r),{evicted:o,sedimented:n}}absorbSediment(t,e){const i=new Map(this.world.readState().map(t=>[t.id,t])),o=[];for(const n of t){const t=i.get(n);if(!t)continue;const r=this.sediment.add(t);r&&(o.push(n),this.emitObservation({type:"physics-sediment",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:n,datum:t.datum,x:t.x,y:t.y,binId:r.id,count:r.count,total:r.total},e))}return o}sleepingFirstEvictionOrder(){const t=new Map(this.world.readState().map(t=>[t.id,t.sleeping])),e=[],i=[];for(const o of this.liveBodyOrder)t.get(o)?e.push(o):i.push(o);return[...e,...i]}};import{scaleLinear as Ii}from"d3-scale";function Fi(t){const{count:e,idPrefix:i,wallThickness:o,xScale:n,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const c=Math.min(r-1,a?.(e)??s),l=Math.max(1,r-c);return{id:`${i}-wall-${e}`,shape:{type:"aabb",x:n(e),y:c+l/2,width:o,height:l}}})}import{scaleLinear as Ni}from"d3-scale";function Bi(t){if(Array.isArray(t)&&t.length>=2){const e=ye(t[0]),i=ye(t[1]);return null!=e&&null!=i?{x:e,y:i}:null}if(t&&"object"==typeof t){const e=t,i=ye(e.x),o=ye(e.y);return null!=i&&null!=o?{x:i,y:o}:null}return null}function Oi(t){return Array.isArray(t)?t.map(Bi).filter(t=>null!=t):[]}function Wi(t,e,i){return"normalized"===i?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:ge(t.x,e.plot.x,e.plot.x+e.plot.width),y:ge(t.y,e.plot.y,e.plot.y+e.plot.height)}}function ji(t){let e=0;for(let i=1;t.length>i;i+=1)e+=Math.hypot(t[i].x-t[i-1].x,t[i].y-t[i-1].y);return e}function Yi(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const i=ge(e,0,1)*ji(t);let o=0;for(let e=1;t.length>e;e+=1){const n=t[e-1],r=t[e],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(o+s>=i){const t=(i-o)/s;return{x:n.x+(r.x-n.x)*t,y:n.y+(r.y-n.y)*t}}o+=s}}return{...t[t.length-1]}}function Xi(t,e){const i=Yi(t,Math.max(0,e-.02)),o=Yi(t,Math.min(1,e+.02)),n=o.x-i.x,r=o.y-i.y,s=Math.hypot(n,r)||1;return{x:n/s,y:r/s}}function qi(t,e,i){return Math.max(e,Math.min(i,t))}function Gi(t,e,i,o,n,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:i,x2:o,y2:n,thickness:r.thickness??8}}}function Vi(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,i=t.y,o=t.width,n=t.height,{type:"aabb",x:e,y:i,width:o,height:n}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,i,o,n}function Hi(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...Vi({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function Zi(t,e=12){return"number"==typeof t?{x:t,y:0}:t&&"object"==typeof t?{x:Number.isFinite(t.x)?Number(t.x):e,y:Number.isFinite(t.y)?Number(t.y):0}:{x:e,y:0}}function Ki(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const i=t.size,o=ue(i),n=ge(t.ballRadius??6,2,18),r=t.seed??1,s=be(r),a=t.idAccessor,c=t.stageAccessor??"stage",l=t.groupBy,u=t.groupLabelAccessor,h=t.workAccessor,d=t.radiusAccessor,f=t.groupCompletion??(l?"allAbsorbed":"none"),p=t.springStiffness??.28,y=t.springDamping??.72,g=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),x=function(t){const e=t.shape??"lane",i=Math.max(1,Math.round(t.width)),o=Math.max(1,Math.round(t.height)),n=t.padX??46,r=t.padY??72,s=n,a=i-n,c=r,l=o-Math.max(24,Math.round(.45*r)),u=(c+l)/2,h=Math.max(1,l-c),d=qi(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=qi(h*d+p,.06*h,.5*h),g=y/2,m=u-g,x=u+g,b=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,S=t.stages;if(!S.length)throw Error("processStageLayout requires at least one stage");const A=qi(t.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(S),_=a-s;let P=s;const R=S.map((t,e)=>{const i=P,o=e===S.length-1?a:P+(t.share??1)/M*_;return P=o,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:i,x1:o,x:(i+o)/2,width:o-i,y:u,height:h}}),T=R[A],L=T.x0,C=T.x1,$=(t,i)=>{if("lane"===e)return"top"===i?c:l;if("funnel"===e){const e=qi((t-s)/Math.max(1,a-s),0,1);return"top"===i?c+(m-c)*e:l+(x-l)*e}if(L>=t){const e=qi((t-s)/Math.max(1,L-s),0,1);return"top"===i?c+(m-c)*e:l+(x-l)*e}if(C>=t)return"top"===i?m:x;const o=qi((t-C)/Math.max(1,a-C),0,1);return"top"===i?m+(c-m)*o:x+(l-x)*o},z=R.map(t=>{const e=Math.min($(t.x0,"top"),$(t.x1,"top")),i=Math.max($(t.x0,"bottom"),$(t.x1,"bottom"));return{...t,y:(e+i)/2,height:Math.max(1,i-e)}}),D={thickness:k,friction:v,restitution:w},E=[];"lane"===e?E.push(Gi(b+"-top",s,c,a,c,D),Gi(b+"-bottom",s,l,a,l,D),Gi(b+"-left",s,c,s,l,{...D,thickness:Math.max(6,k-2)}),Gi(b+"-right",a,c,a,l,{...D,thickness:Math.max(6,k)})):"funnel"===e?E.push(Gi(b+"-top",s,c,a,m,D),Gi(b+"-bottom",s,l,a,x,D),Gi(b+"-left",s,c,s,l,{...D,thickness:Math.max(6,k-2)}),Gi(b+"-right",a,m,a,x,{...D,thickness:Math.max(6,k)})):E.push(Gi(b+"-left-top",s,c,L,m,D),Gi(b+"-left-bottom",s,l,L,x,D),Gi(b+"-center-top",L,m,C,m,D),Gi(b+"-center-bottom",L,x,C,x,D),Gi(b+"-right-top",C,m,a,c,D),Gi(b+"-right-bottom",C,x,a,l,D),Gi(b+"-left",s,c,s,l,{...D,thickness:Math.max(6,k-2)}),Gi(b+"-right",a,c,a,l,{...D,thickness:Math.max(6,k)}));const I=t.membraneDampingScale??.5,F=s,N=Math.max(1,("bowtie"===e?L:a)-F),B=(t.membranes??[]).map(t=>{const e=F+qi(t.offset,0,1)*N,i=t.width??18+18*t.cost,o=h-16,n=u+.25*(t.wobble??0);return{...t,x:e,y:n,width:i,height:o}}),O=!1===t.includeMembraneRegions?[]:B.map(t=>function(t){const e=t.dampingScale??.5,i=t.energyScale??1,o=qi(t.cost,0,2);return{...Vi({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:o,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o*e,energyDelta:-o*i}}({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??I,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:i,height:o,padX:n,padY:r,left:s,right:a,topY:c,bottomY:l,midY:u,centerLeft:L,centerRight:C,pinchHeight:y,pinchTop:m,pinchBottom:x,stages:z,membranes:B,colliders:E,regionEffects:O,boundaryY:$}}({width:i[0],height:i[1],shape:"lane",padX:Math.max(28,o.plot.x),padY:Math.max(36,o.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((t,e)=>[t.id,e])),v=new Map(x.stages.map(t=>[t.id,t])),w=x.stages[0].id,k=x.stages[0],S=new Set(e.filter(t=>t.absorb).map(t=>t.id)),A=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const i={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...Vi({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}({...i,kind:t.kind??"sink",force:Zi(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...i.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return o={...i,kind:t.kind??"force-field",force:Zi(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...i.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...Vi({...o,kind:o.kind??"force-field",attributes:{primitive:"portal",targetStage:o.targetStage,..."object"==typeof o.attributes&&o.attributes?o.attributes:{}}}),force:o.force,impulseOnEnter:o.impulseOnEnter,damping:o.damping??.08}}var o;if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...Vi({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}({...i,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Zi(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...i.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return function(t){const e=t.pressure??t.occupancy??0,i=t.baseDamping??.08,o=t.dampingPerUnit??.12,n=t.energyPerUnit??0;return{...Vi({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:i+e*o,energyDelta:n?-e*n:void 0,force:t.force}}({...i,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:Zi(t.force,8),attributes:{...i.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?Hi({...i,kind:t.kind??"force-field",force:Zi(t.force,14),damping:t.damping??.02,attributes:{...i.attributes,primitive:"routeSurface"}}):function(t){return{...Vi({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}({...i,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...i.attributes,primitive:"forceField"}})}(t,{x:e.x,y:x.midY,width:e.width,height:x.bottomY-x.topY})});A.unshift(Hi({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));const M=new Map;for(const t of x.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const i=(a?pe(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",o=(pe(t,e,c)??w)+"",r=b.has(o)?o:w;M.set(r,(M.get(r)??0)+1);const s=l?(pe(t,e,l)??"")+"":void 0,f=s&&u?(pe(t,e,u)??s)+"":s,p=h?ye(pe(t,e,h))??1:1,y=d?ye(pe(t,e,d)):null,g=ge(null!=y&&y>0?y:n,2,18);_.push({datum:t,id:i,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:g,index:e})});const P=new Map,R=new Map;for(const t of _){if(!t.groupId)continue;const e=P.get(t.groupId)??[];e.push(t.id),P.set(t.groupId,e),t.groupLabel&&R.set(t.groupId,t.groupLabel)}const T=ge(t.groupAnchorAlong??.55,.15,.9),L=x.left+(x.right-x.left)*T,C=Array.from(P.keys()),$=C.map((t,i)=>{const o=P.get(t)??[],n=C.length>1?x.topY+28+i/Math.max(1,C.length-1)*(x.bottomY-x.topY-56):x.midY;return function(t){const e=t.x??t.anchor?.x??0,i=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:i,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:i},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:R.get(t)??t,bodyIds:o,anchor:{x:L,y:n},x:L,y:n,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),z=function(t,e){const i=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],o=e.filter(t=>!i.has(t)),n=e.length-o.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s?.[t];return Number.isFinite(e)&&Number(e)>=0?Number(e):1},c=e.reduce((t,e)=>t+a(e),0),l=e.reduce((t,e)=>t+(i.has(e)?a(e):0),0),u=t.completion?.threshold,h="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):c:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?n>0:"threshold"===r?l>=(h??c):0===o.length),absorbed:n,total:e.length,absorbedValue:l,totalValue:c,threshold:h,missing:o}})}($,_.filter(t=>S.has(t.stageId)).map(t=>t.id)),D=new Map($.map(t=>[t.id,t])),E=_.map((t,e)=>{const i=v.get(t.stageId)??k,o=i.x+(s()-.5)*Math.min(24,.2*i.width),n=x.boundaryY(o,"top")+t.radius+10,r=x.boundaryY(o,"bottom")-t.radius-10,a=r>n?n+s()*Math.max(1,r-n):x.midY,c=g?o:x.left+18+e%7*4,l=g?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:o,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=D.get(t.groupId);e?.anchor&&!S.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:c,y:l,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),I={kernel:{seed:r,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},F=x.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),N=e.map(t=>{const e=v.get(t.id)??k;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:M.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:I,initialSpawns:E,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:F,metadata:{kind:"process-flow",plot:o.plot,volume:x,stages:N,groups:$,groupCompletion:z,regionEffects:A}}}import{scaleLinear as Ui}from"d3-scale";function Qi(t,e,i){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=Object.values(t).filter(t=>"string"==typeof t&&t.length>0);if(e.length>0)return e}if(Array.isArray(t)&&t.length>0)return t;if("string"==typeof t){const e=Z[t];if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:i}function Ji(t,e){const i=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>i&&tt(i,t)||"#4e79a7":e=>{if(i){const t=tt(i,e);if(t)return t}let o=0;for(let t=0;e.length>t;t++)o=31*o+e.charCodeAt(t)|0;return t[Math.abs(o)%t.length]??"#4e79a7"}}function to(t,e){const i=e.config??{},o=(e.sensors??[]).map(t=>({...t,sensor:!0})),n=[...e.colliders??[],...o],r=[...t.colliders??[],...i.colliders??[],...n];return{...t,...i,observation:{...t.observation,...i.observation},...r.length>0&&{colliders:r}}}function eo(t){return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:28,y2:t.floorY,thickness:8}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:t.width-30,y2:76,thickness:8}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:t.floorY,x2:t.width-30,y2:t.floorY,thickness:8}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-30,y1:76,x2:t.width-30,y2:t.floorY,thickness:8}}]}function io(t,e,i,o){return i?"function"==typeof i?i(t,e):t[i]??o:o}function oo(t){return`gauntlet:${t}:core`}function no(t,e){return`gauntlet:${t}:positive:${e}`}function ro(t,e,i){return`gauntlet:${t}:negative:${e}:${i}`}function so(t,e,i,o){const n=Math.max(2,i+2),r=80+n,s=o.floorY-n;return{x:Math.max(32+n,Math.min(o.width-30-4-n,t)),y:Math.max(r,Math.min(s,e))}}function ao(t,e){const i=[...t].sort((t,e)=>t.localeCompare(e)),o=Math.max(0,i.indexOf(e));return{angle:.82*-Math.PI+(i.length>1?o/(i.length-1):.5)*Math.PI*.64,index:o,radius:48+o%2*6}}function co(t,e,i){const o=t.activePositiveIds.reduce((t,i)=>t+(e.get(i)?.value??1),0),n=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(i.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*o-8*r-1.2*t.delay-5*n))}function lo(t){const e=function(t,e,i){const[o,n]=t,r=Math.round(.48*n),s=n-36,a=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,a.length),l=.22*o,u=c>1?(.78*o-l)/(c-1):0,h=Math.max(Math.round(.14*o),110);return{crashY:s-i,floorY:s,gates:a.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(l+e*u),width:t.width??Math.max(54,Math.round(.07*o))})),graveyardX:Math.round(.84*o),graveyardY:s-4,height:n,routeY:r,socketX:Math.round(.92*o),startX:h,width:o}}(t.size??[900,520],t.gates,t.crashOffset??30),i=t.positiveProperties??[],o=new Map(i.map(t=>[t.id,t])),n=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,i,o,n){const r=io(t,e,i.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=o.map(t=>t.id),a=[...io(t,e,i.positiveAccessor,s)],c=[...io(t,e,i.negativeAccessor,[])].filter(t=>n.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...io(t,e,i.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(io(t,e,i.startTimeAccessor,0))||0),stage:"project filed",viability:io(t,e,i.initialViability,100)}}(e,s,r,i,n);return{...a,viability:t.viability?.(a,{negativeProperties:n,positiveProperties:o})??co(a,o,n)}}),a=s.flatMap((i,r)=>{const s=function(t,e,i,o){const n=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(i),r=o?.(t,e,i)??{};return{...n,...r,startY:r.startY??r.routeY??n.startY,socketY:r.socketY??r.routeY??n.socketY,graveyardY:r.graveyardY??n.graveyardY}}(i,r,e,t.projectPlacement);return function(t,e,i,o,n,r,s){const a=o.startX,c=o.startY+(o.startY===i.routeY?38*e:0),l=s?.(t,e,i,o)??{},u={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},h=[{...l,id:oo(t.id),x:l.x??a,y:l.y??c,vx:l.vx??42,vy:l.vy??0,mass:l.mass??7,bodyCollisions:l.bodyCollisions??!0,shape:l.shape??{type:"circle",radius:28},spawnAt:l.spawnAt??t.startedAt,datum:u}],d=so(a,c,l.shape&&"radius"in l.shape&&Number(l.shape.radius)||28,i);h[0].x=d.x,h[0].y=d.y;for(const e of t.activePositiveIds){const o=n.get(e);if(!o)continue;const r=ao(t.activePositiveIds,e),s=o.radius??10,a=so(d.x+Math.cos(r.angle)*r.radius,d.y+Math.sin(r.angle)*r.radius,s,i);h.push({id:no(t.id,e),x:a.x,y:a.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:o.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:l.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:o,sourceDatum:t.datum},springs:!1===o.spring?[]:[{target:{type:"body",bodyId:oo(t.id)},stiffness:.56,damping:.9,restLength:52+r.index%2*4,...o.spring??{}}]})}return t.negativeIds.forEach((e,o)=>{const n=r.get(e);n&&h.push(function(t,e,i,o,n,r,s){const a=e.radius??7.2,c=so(o-12+i%4*12,n+54+12*Math.floor(i/4),a,r);return{id:ro(t.id,e.id,i),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:oo(t.id)},stiffness:.62,damping:.92,restLength:52+i%4*3,...e.spring??{}}]}}(t,n,o,d.x,d.y,i,l.spawnAt??t.startedAt))}),h}(i,r,e,s,o,n,t.coreBody)});return{layout:e,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:eo(e)}}}function uo(t){return t.map(t=>({...t,spawnAt:void 0}))}var ho={Sparkline:{frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"line",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||e,colorAccessor:e,...o,showAxes:!1,margin:o.margin||{top:2,right:2,bottom:2,left:2},showLegend:!1,showGrid:!1,title:void 0})},LineChart:gt,AreaChart:mt,DifferenceChart:xt,StackedAreaChart:bt,Scatterplot:vt,CandlestickChart:{frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"candlestick",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...o})},BubbleChart:{frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:i,...o})},ConnectedScatterplot:kt,QuadrantChart:wt,Heatmap:{frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"heatmap",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,colorScheme:i||n.colorScheme||"blues",showValues:n.showValues,cellBorderColor:n.cellBorderColor,...o})},XYCustomChart:{frameType:"xy",buildProps:(t,e,i,o,n)=>({chartType:"custom",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...o,showAxes:o.showAxes??!1})},BarChart:Tt,StackedBarChart:Lt,GroupedBarChart:Ct,PieChart:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"pie",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:e||n.categoryAccessor,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...o})},DonutChart:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"donut",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",innerRadius:n.innerRadius||60,colorAccessor:e||n.categoryAccessor,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...o})},Histogram:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"histogram",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal",bins:n.bins,colorAccessor:e,colorScheme:i,...o})},BoxPlot:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"boxplot",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorScheme:i,...o})},ViolinPlot:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"violin",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",bins:n.bins,colorScheme:i,...o})},SwarmPlot:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"swarm",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...o})},DotPlot:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"point",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:i,...o,showGrid:o.showGrid??!0})},SwimlaneChart:$t,RidgelinePlot:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"ridgeline",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",bins:n.bins,amplitude:n.amplitude,...o})},LikertChart:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.levelAccessor||"level",colorAccessor:e||n.levelAccessor||"level",colorScheme:i,normalize:!0,projection:"vertical"===n.orientation?"vertical":"horizontal",...o})},FunnelChart:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>{const r="vertical"===n.orientation;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:e||n.categoryAccessor,categoryAccessor:n.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!r&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:r?40:0,showAxes:r,showGrid:r,colorScheme:i,...o}}},GaugeChart:zt,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,i,o,n)=>({chartType:"custom",data:t,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:e,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...o,showAxes:o.showAxes??!1})},ForceDirectedGraph:Ut,NetworkCustomChart:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"force",nodes:n.nodes||t||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:e,colorScheme:i,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...o})},SankeyDiagram:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:e,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:n.nodeStyle,edgeStyle:n.edgeStyle,colorScheme:i,...o})},ProcessSankey:Qt,ChordDiagram:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,showLabels:n.showLabels,colorBy:e,edgeColorBy:n.edgeColorBy,colorScheme:i,...o})},TreeDiagram:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"cluster"===n.layout?"cluster":"tree",data:t,childrenAccessor:n.childrenAccessor,colorBy:e,colorByDepth:n.colorByDepth,orientation:n.orientation,showLabels:n.showLabels,colorScheme:i,...o})},Treemap:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"treemap",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,showLabels:n.showLabels,colorScheme:i,...o})},CirclePack:{frameType:"network",buildProps:(t,e,i,o,n)=>({chartType:"circlepack",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,colorScheme:i,...o})},ChoroplethMap:ae,ProportionalSymbolMap:ce,FlowMap:le,GeoCustomChart:{frameType:"geo",buildProps:(t,e,i,o,n)=>({points:n.points||t||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:e,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...o})},GaltonBoardChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[600,400],s=n.bins??21,a=n.seed??1,c=Math.max(1,Math.round(n.pegRows??s-1)),l="mechanical"===n.mode,u=l?function(t){const e=Math.max(2,Math.round(t.bins)),i=Math.max(1,Math.round(t.pegRows??e-1)),o=Math.max(1,Math.round(t.count??Math.max(64,4*e))),n=ge(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=be(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:o},(t,e)=>{let o=0;for(let t=0;i>t;t+=1)r()<n&&(o+=1);const a=i/2;return{id:`${s}-${e}`,value:o,mechanical:!0,pegRows:i,branchProbability:n,pathRights:o,side:a>o?"left":o>a?"right":"center"}})}({bins:s,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:c,seed:a}):Array.isArray(t)?t:[],h=function(t){const{data:e,valueAccessor:i,bins:o,ballRadius:n,seed:r,size:s,valueExtent:a}=t,c=ue(s),l=e.map((t,e)=>ye(pe(t,e,i))).filter(t=>null!=t),u=function(t){if(!t)return;const e=ye(t[0]),i=ye(t[1]);return null!=e&&null!=i?e>i?[i,e]:[e,i]:void 0}(a),h=u?.[0]??(l.length?Math.min(...l):0),d=u?.[1]??(l.length?Math.max(...l):1),f=d===h?1:d-h,p=ve().domain([0,o]).range([c.plot.x,c.plot.x+c.plot.width]),y=Array.from({length:o},()=>0),g=[];e.forEach((t,e)=>{const r=ye(pe(t,e,i));if(null==r)return;const s=Math.max(0,Math.min(o-1,Math.floor((r-h)/f*o)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:c.plot.y+n+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:n},datum:{...t,value:r,bin:s}})});const m=c.plot.y+c.plot.height;return{config:fe(r,[...pi({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...yi({idPrefix:"galton-bin",count:o,domainStart:0,domainStep:1,xScale:p,yTop:c.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:g,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:o,plot:c.plot,valueExtent:[h,d]}}}({data:u,valueAccessor:n.valueAccessor||"value",bins:s,ballRadius:n.ballRadius??4,seed:a,size:r,valueExtent:l?[0,c]:void 0});return{...o,config:h.config,initialSpawns:uo(h.initialSpawns),projectionRows:h.projectionRows,bodyStyle:de(e||n.colorBy||(l?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[600,400],s=function(t){const{data:e,timeAccessor:i,arrivalAccessor:o,windows:n,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:u=1}=t,h=ue(c),d=e.map((t,e)=>ye(pe(t,e,i))).filter(t=>null!=t),f=ye(l?.[0]),p=ye(l?.[1]),y=d.length?Math.min(...d):0,g=d.length?Math.max(...d):y+n.size,m=Math.min(f??y,y),x=Math.max(p??g,g),b=Math.floor(m/n.size)*n.size,v=Math.max(1,Math.ceil((x-b+n.size)/n.size)),w=d.length?Math.max(...d):0,k="function"==typeof r?r(w):ye(r?.value)??w-(r?.delay??n.size),S=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>b+(e+1)*n.size>k?t:t+1,0))),A=function(t,e){const i=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:i,height:t.plot.height},windowPlot:{x:t.plot.x+i,y:t.plot.y,width:Math.max(40,t.plot.width-i),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(h,s),M=b+v*n.size,_=Ii().domain([b,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),R=[];e.forEach((t,e)=>{const r=ye(pe(t,e,i));if(null==r)return;const a=ye(pe(t,e,o))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-b)/n.size))),l=k>=b+(c+1)*n.size;P[c].value+=l?0:1,P[c].secondary+=l?1:0,R.push({id:(t.id??"event-"+e)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:h.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const T=h.plot.y+h.plot.height,L=function(t,e){const i=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!i)return[];const o=t.windowStart,n=t.windowStart+t.windowCount*t.windowSize,r=Ii().domain([o,n]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+i*t.windowSize),a=t.windowPlot.x,c=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),l=t=>s===a?e:c+(t-a)/(s-a)*(e-c),u=[];for(let e=0;i>e;e+=1){const i=t.windowStart+e*t.windowSize,o=i+t.windowSize,n=r(i),s=r(o);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:n,y1:l(n),x2:s,y2:l(s)})}return u}({closedWindowCount:S,gutter:A.gutter,plot:h.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:n.size,windowStart:b},h.plot.y+.28*h.plot.height);return{config:fe(a,[...pi({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Fi({idPrefix:"eventdrop-window",count:v,xScale:t=>_(b+t*n.size),yTop:A.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?L[0]?.y1:L[t-1]?.y2??L[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?A.wallTop:e+1.25*s},yBottom:T,wallThickness:6}),...L.map(t=>({id:t.id,shape:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:R,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${b+e*n.size}-${b+(e+1)*n.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:L,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:h.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:n.size,windowStart:b}}}({data:Array.isArray(t)?t:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r,timeExtent:n.timeExtent,timeScale:n.timeScale??1});return{...o,config:s.config,initialSpawns:uo(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:de(e||n.colorBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},PhysicsPileChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[600,400],s="mechanical"===n.mode,a=function(t){const{data:e,categoryAccessor:i,valueAccessor:o,unitValue:n,ballRadius:r,seed:s,size:a}=t,c=me(n,1),l=ue(a),u=[],h=new Map,d=new Map,f=[];function p(t){let e=h.get(t);return null==e&&(e=u.length,u.push(t),h.set(t,e)),e}e.forEach((t,e)=>{p((pe(t,e,i)??"unknown")+"")});const y=Math.max(1,u.length),g=function(t,e,i){const o=t.width/Math.max(1,e),n=Math.max(2,2*i),r=Math.min(.7*o,Math.max(3.2*n,n+8)),s=Math.max(1,Math.floor(r/n));return{laneWidth:o,tubeWidth:r,ballDiameter:n,perRow:s,centerX:e=>t.x+(e+.5)*o,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*n}}(l.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),x=u.map(()=>[]);e.forEach((t,e)=>{const n=(pe(t,e,i)??"unknown")+"",s=p(n),a=o?ye(pe(t,e,o)):1,u=Math.max(0,Math.round((a??0)/c)),h=g.centerX(s);for(let i=0;u>i;i+=1){const o=d.get(n)??0,a=g.perRow>1?((g.perRow>1?o%g.perRow:0)/(g.perRow-1)*2-1)*m:0;d.set(n,o+1),x[s].push({id:`${(t.id??"pile-"+e)+""}-${i}`,x:h+a,y:l.plot.y+r+2,vx:(i%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:n,unitIndex:i}})}});const b=x.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;b>t;t+=1)for(const e of x)e.length>t&&f.push(e[t]);const v=l.plot.y+l.plot.height,w=[...pi({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=l.plot.y-400;for(let t=0;y>t;t+=1){const e=g.centerX(t);for(const i of[-1,1])w.push({id:`pile-tube-${t}-${0>i?"l":"r"}`,shape:{type:"aabb",x:e+i*g.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:fe(s,w,"PhysicsPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:d.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),i=e.length?e:["Intake"],o=Math.max(i.length,Math.round(t.count??Math.max(48,12*i.length))),n=me(t.unitValue,1),r=be(t.seed??1),s=t.idPrefix??"mechanical-pile",a=i.map(()=>.65+.9*r()),c=a.reduce((t,e)=>t+e,0)||1,l=o-i.length,u=a.map(t=>t/c*l),h=u.map(t=>1+Math.floor(t));let d=o-h.reduce((t,e)=>t+e,0);const f=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;d>0;t=(t+1)%f.length)h[f[t].index]+=1,d-=1;return i.map((t,e)=>({id:`${s}-${e}`,category:t,value:h[e]*n,mechanical:!0,unitCount:h[e],unitValue:n,share:h[e]/o}))}({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(s?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r});return{...o,config:a.config,initialSpawns:uo(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:de(e||n.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[600,360],s=function(t){const{data:e,xAccessor:i,groupAccessor:o,radiusAccessor:n,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:u}=t,h=ue(a),d=be(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=ye(pe(t,e,i));if(null==s)return;const a=o?(pe(t,e,o)??"All")+"":"All",c=n?ye(pe(t,e,n)):null,l=ge(null!=c&&c>0?c:r,2,18);!function(t){let e=y.get(t);null==e&&(e=p.length,p.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:l})});const g=f.map(t=>t.value),m=c?ye(c[0]):null,x=c?ye(c[1]):null,b=g.length?Math.min(...g):0,v=g.length?Math.max(...g):1;let w=m??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const t=k;k=w,w=t}const S=Math.max(r,...f.map(t=>t.radius)),A=h.plot.x+S+8,M=h.plot.x+h.plot.width-S-8,_=Ni().domain([w,k]).range([A,M]),P=Math.max(1,p.length),R=h.plot.y+Math.max(28,3*S),T=Math.max(0,h.plot.y+h.plot.height-Math.max(28,3*S)-R),L=t=>{const e=y.get(t)??0;return 1===P?h.plot.y+.54*h.plot.height:R+e/(P-1)*T},C=new Map,$=f.map((t,e)=>{C.set(t.group,(C.get(t.group)??0)+1);const i=_(t.value),o=L(t.group),n=(d()-.5)*t.radius*1.6,r=(d()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?i+n:ge(i+(e%9-4)*t.radius*2.5,A,M),y:u?o+r:h.plot.y-18-e%12*t.radius,vx:u?0:22*(d()-.5),vy:u?0:24+18*d(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:i,targetY:o},springs:[{target:{type:"point",x:i,y:o},restLength:0,stiffness:34,damping:5.5}]}});return{config:fe(s,pi({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:$,projectionRows:p.map(t=>({label:t,value:C.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(t=>({label:t,y:L(t),count:C.get(t)??0})),plot:h.plot}}}({data:Array.isArray(t)?t:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:r,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...o,config:s.config,initialSpawns:uo(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:de(e||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[900,420],s=Array.isArray(n.stages)?n.stages:[],a=Ki({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),c=a.metadata;return{...o,config:a.config,initialSpawns:uo(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,bodyStyle:de(e||n.colorBy||n.groupBy)}}},GauntletChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[900,520],s=lo({data:Array.isArray(t)?t:[],size:r,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...o,config:s.config,initialSpawns:uo(s.initialSpawns),projectionRows:[],bodyStyle:de(e||n.colorBy)}}},PhysicalFlowChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:i,links:o,maxParticles:n,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:u,pathAccessor:h,pathConstraint:d="path",reducedMotion:f,seed:p,size:y,sourceAccessor:g,targetAccessor:m,throughputAccessor:x}=t,b=ue(y),v=be(p),w=new Map,k=new Map,S=[];function A(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const i=(pe(t,e,r)??t.id??e)+"",o=ye(pe(t,e,s)),n=ye(pe(t,e,a));if(null!=o&&null!=n){const t={x:o,y:n};w.set(i,t),S.push(t)}k.set(i,(t.label??t.name??i)+"")});const M=[];o.forEach((t,e)=>{const i=A(pe(t,e,g)),o=A(pe(t,e,m)),n=Math.max(0,ye(pe(t,e,x))??0),r=Oi(h?pe(t,e,h):void 0),s=r.length?r:Oi(t.path??t.points??t.route);s.forEach(t=>S.push(t)),M.push({id:(t.id??`physical-flow-${i}-${o}-${e}`)+"",link:t,index:e,source:i,target:o,throughput:n,rawPath:s})});const _=(R=S,"normalized"===(P=e)||"pixels"===P?P:R.length>0&&R.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,R;const T=new Map;for(const[t,e]of w)T.set(t,Wi(e,b,_));const L=[];for(const t of M){let e=t.rawPath.map(t=>Wi(t,b,_));if(2>e.length){const i=T.get(t.source),o=T.get(t.target);i&&o&&(e=[i,o])}else T.has(t.source)||T.set(t.source,e[0]),T.has(t.target)||T.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(k.has(t.source)||k.set(t.source,t.source),k.has(t.target)||k.set(t.target,t.target),L.push({...t,path:e,packetCount:0}))}const C=me(u,.12),$=Math.max(1,Math.round(n)),z=L.map(t=>Math.max(1,Math.round(t.throughput*C))),D=z.reduce((t,e)=>t+e,0),E=D>$?$/D:1;L.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(z[e]*E))});let I=L.reduce((t,e)=>t+e.packetCount,0);for(;I>$;){const t=L.reduce((t,e,i)=>e.packetCount>1&&(-1===t||e.packetCount>L[t].packetCount)?i:t,-1);if(-1===t)break;L[t].packetCount-=1,I-=1}const F=new Map,N=new Map,B=[],O=me(i,90),W=me(l,4);L.forEach((t,e)=>{F.set(t.target,(F.get(t.target)??0)+t.throughput),N.set(t.source,(N.get(t.source)??0)+t.throughput);const i=ji(t.path);for(let o=0;t.packetCount>o;o+=1){const n=(o+.5)/t.packetCount,r=f?n:ge(.12+.84*n+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=Yi(t.path,s),c=Yi(t.path,r),l=Xi(t.path,s),u={x:-l.y,y:l.x},h=(v()-.5)*W*1.5;B.push({id:`${t.id}-packet-${o}`,x:a.x+u.x*h,y:a.y+u.y*h,vx:f?0:l.x*O+10*(v()-.5),vy:f?0:l.y*O+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+o/32,shape:{type:"circle",radius:W},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:o,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:i,flowRouteId:t.id,flowSpeed:O,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==d&&f?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from(T,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+xe(t),point:e})),X=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:j,height:j}})),q=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=fe(p,[...pi({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],"PhysicalFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=$,G.eviction="oldest",G.observation={...G.observation,sensors:q};const V=Array.from(T,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+xe(t),incoming:F.get(t)??0,outgoing:N.get(t)??0})),H=L.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:G,initialSpawns:B,projectionRows:V.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:B.length,totalThroughput:L.reduce((t,e)=>t+e.throughput,0),plot:b.plot,nodes:V,links:H}}}({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(t)?t:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:r});return{...o,config:s.config,initialSpawns:uo(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:de(e||n.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(t,e,i,o,n)=>{const r=o.size??[700,380],s=function(t){const e=function(t,e,i){const o=t?.observation;return{...t,observation:{...o,chartId:e??o?.chartId??"physics-custom",chartType:o?.chartType??"PhysicsCustomChart",onObservation:i??o?.onObservation}}}(t.config,t.chartId,t.onObservation),i=Qi(t.colorScheme,t.themeCategorical,D),o=ue(t.size),n={data:t.data,scales:{x:Ui().domain(t.xExtent??[0,1]).range([o.plot.x,o.plot.x+o.plot.width]),y:Ui().domain(t.yExtent??[0,1]).range([o.plot.y+o.plot.height,o.plot.y])},dimensions:o,theme:{semantic:t.semantic,categorical:[...i]},resolveColor:Ji(i,t.colorScheme),config:t.layoutConfig??{},world:new Ei(e)},r=t.skipLayout?{}:t.layout(n)??{},s=function(t,e){if(!e?.length)return t;const i=new Map;for(const t of e){const{bodyId:e,...o}=t,n=i.get(e)??[];n.push(o),i.set(e,n)}return t.map(t=>{const e=i.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:to(e,r),context:n,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:n.chartId,colorScheme:i,config:n.config,data:Array.isArray(t)?t:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:g(b)??{},size:r,themeCategorical:b.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...o,config:s.config,initialSpawns:uo(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??de(e||n.colorBy)}}}};function fo(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function po(t){if(!t||2>t.length)return;const e=fo(t[0]),i=fo(t[t.length-1]);return null!==e&&null!==i?[e,i]:void 0}function yo(t){const{count:e,byType:i}=function(t){const e={};for(const i of t){const t="string"==typeof i?.type&&i.type.length>0?i.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),o=0===e,n=[...t.extraWarnings??[]];return o&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),{component:"",frameType:t.frameType,status:o?"empty":"ok",empty:o,markCount:e,markCountByType:i,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:Array.isArray(t.annotations)?t.annotations.length:0,ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:n}}function go(t){return"object"==typeof t&&null!==t&&"legendGroups"in t}function mo(t){return"object"==typeof t&&null!==t&&"gradient"in t}var xo=Object.freeze([]);function bo(t){if(!t)return xo;let e=!1;for(let i=0;t.length>i;i++){const o=t[i];if(null==o||"object"!=typeof o){e=!0;break}}if(!e)return t;const i=[];for(const e of t)null!=e&&"object"==typeof e&&i.push(e);return i}import*as vo from"react";import*as wo from"react-dom/server";var ko=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const i of t){const t=this.push(i);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)t(this.buffer[(e+i)%this._capacity],i)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)t[i]=this.buffer[(e+i)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let i=0,o=[];e.length>t&&(i=e.length-t,o=e.slice(0,i)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=i;e.length>t;t++)this.push(e[t]);return o}update(t,e){const i=[],o=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++){const r=(o+n)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},i.push(t),this.buffer[r]=e(s)}}return i}remove(t){const e=[],i=[];if(this.forEach(o=>{t(o)?i.push(o):e.push(o)}),0===i.length)return i;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return i}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},So=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(t){Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}evict(t){t!==this._min&&t!==this._max||(this._dirty=!0)}recalculate(t,e){this._min=1/0,this._max=-1/0;for(const i of t){const t=e?e(i):i;Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}},Ao=/^\d{4}-\d{1,2}$/;function Mo(t){const e=t.trim();if(!e||!Number.isNaN(Number(e)))return NaN;const i=Ao.test(e)?e+"-01":e;if(i===e&&10>e.length)return NaN;const o=Date.parse(i);return Number.isFinite(o)?o:NaN}function _o(t){return t instanceof Date?t.getTime():"string"==typeof t?Mo(t):+t}function Po(t){return new Set(Array.isArray(t)?t:[t])}function Ro(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function To(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Lo(t,e,i){return t+(e-t)*i}function Co(){return"undefined"!=typeof performance?performance.now():Date.now()}function $o(t,e,i){if(1>=i)return 1;const o=i-1;return function(t){const e=Math.max(0,Math.min(1,t.minOpacity??.1));if(Number.isNaN(t.age))return 1;if(t.age===1/0)return e;if(!Number.isFinite(t.extent)||0>=t.extent)return 1;const i=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>i?1:e;if("exponential"===t.type){const o=t.halfLife??t.extent/2;return e+Math.pow(.5,i/(o>0?o:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-i/t.extent))*(1-e)}({age:o-e,extent:o,type:t.type,halfLife:t.halfLife??i/2,threshold:t.stepThreshold??.5*i,minOpacity:t.minOpacity??.1})}function zo(t){const e=new Map;for(let i=0;t.length>i;i++)e.set(t[i],i);return e}function Do(t,e,i){const o=t.duration??500,n=i-e;return o>n?1-n/o:0}function Eo(t,e,i,o){let n=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,n=!0),t._pulseColor!==i&&(t._pulseColor=i,n=!0),t._pulseGlowRadius!==o&&(t._pulseGlowRadius=o,n=!0),n):(0!==t._pulseIntensity&&(t._pulseIntensity=0,n=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,n=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,n=!0),n)}function Io(t,e,i=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const o=t.duration??500,n=e.peek();return null!=n&&o>i-n}function Fo(t,e,i){if(e._transitionKey)return e._transitionKey;switch(e.type){case"point":if(e.pointId)return"p:"+e.pointId;if("streaming"===t.runtimeMode&&e.datum){const i=t.getX(e.datum),o=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${i}:${o}`;if(null!=i&&null!=o)return`p:${i}:${o}`}return"p:"+i;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+i;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??i}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+i:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function No(t,e,i,o,n,r){const s=[];for(const n of t){const t=i(n),r=o(n);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:n})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),c=Array(s.length),l=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],c[t]=e.rawY,l[t]=e.d}return{type:"line",path:a,rawValues:c,style:n,datum:l,group:r}}function Bo(t,e,i,o,n,r,s,a){const c=[];for(const r of t){const t=i(r),s=o(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const l=e.x(t),u=a?a(r):n;c.push({px:l,topY:e.y(s),botY:e.y(u)})}c.sort((t,e)=>t.px-e.px);const l=Array(c.length),u=Array(c.length);for(let t=0;c.length>t;t++){const e=c[t];l[t]=[e.px,e.topY],u[t]=[e.px,e.botY]}return{type:"area",topPath:l,bottomPath:u,style:r,datum:t,group:s}}function Oo(t,e,i,o){const n=new Map;if("silhouette"===o)for(const o of t){let t=0;for(const n of e)t+=i(n,o)||0;n.set(o,-t/2)}else if("wiggle"===o){t.length>0&&n.set(t[0],0);for(let o=1;t.length>o;o++){const r=t[o-1],s=t[o];let a=0,c=0,l=0;for(const t of e){const e=i(t,s)||0;a+=(2*l+e)*(e-(i(t,r)||0)),c+=e,l+=e}const u=n.get(r)??0;n.set(s,u-(c>0?a/(2*c):0))}if(t.length>0){let o=0;for(const r of t){let t=0;for(const o of e)t+=i(o,r)||0;o+=(n.get(r)??0)+t/2}const r=o/t.length;for(const e of t)n.set(e,(n.get(e)??0)-r)}}else for(const e of t)n.set(e,0);return n}function Wo(t,e,i,o,n,r,s){const a=i(t),c=o(t);if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l={type:"point",x:e.x(a),y:e.y(c),r:n,style:r,datum:t};return void 0!==s&&(l.pointId=s),l}function jo(t,e,i,o,n,r,s,a){const c=i(t),l=o(t);if(!Number.isFinite(c)||!Number.isFinite(l))return null;const u={type:"symbol",x:e.x(c),y:e.y(l),size:n,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function Yo(t,e,i,o,n,r,s){return{type:"rect",x:t,y:e,w:i,h:o,style:n,datum:r,group:s}}function Xo(t,e,i,o,n,r,s){const a={type:"heatcell",x:t,y:e,w:i,h:o,fill:n,datum:r};return s?.showValues&&(a.showValues=!0,a.value=s.value,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function qo(t,e,i,o){return"function"==typeof e.style?e.style(o||{},i):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(i,o)}function Go(t,e,i,o){if(!t.scales)return null;const n=[],r=[];for(const i of e){const e=t.getX(i);if(!Number.isFinite(e))continue;const s=o.getTop(i),a=o.getBottom(i);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const c=t.scales.x(e),l=t.scales.y(s),u=t.scales.y(a);Number.isFinite(c)&&Number.isFinite(l)&&Number.isFinite(u)&&(n.push([c,l]),r.push([c,u]))}return 2>n.length?null:{type:"area",topPath:n,bottomPath:r,style:qo(t,o,i,e[0]),datum:e,group:i,interactive:o.interactive}}function Vo(t){const e=[],i=[];if(!t)return{perSeries:e,aggregate:i};for(const o of t)o.perSeries?e.push(o):i.push(o);return{perSeries:e,aggregate:i}}function Ho(t,e,i){const o=[];for(const n of i){const i=Go(t,e,"__ribbon_aggregate",n);i&&o.push(i)}return o}function Zo(t,e,i,o){const n=[];for(const r of o){const o=Go(t,e,i,r);o&&n.push(o)}return n}function Ko(t,e,i,o){if(!t.config.pointStyle)return;const n=o??t.getY;for(const o of e){const e=t.resolveGroupColor(o.key);for(const r of o.data){let o=t.config.pointStyle(r);!o.fill&&e&&(o={...o,fill:e});const s=o.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,c=Wo(r,t.scales,t.getX,n,s,o,a);c&&i.push(c)}}}function Uo(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}var Qo={topOpacity:.8,bottomOpacity:.05};function Jo(t){if(t)return!0===t?Qo:"colorStops"in t?t:{topOpacity:t.topOpacity??Qo.topOpacity,bottomOpacity:t.bottomOpacity??Qo.bottomOpacity}}import{symbol as tn,symbolCircle as en,symbolCross as on,symbolDiamond as nn,symbolSquare as rn,symbolStar as sn,symbolTriangle as an,symbolWye as cn}from"d3-shape";var ln={circle:en,square:rn,triangle:an,diamond:nn,star:sn,cross:on,wye:cn},un=["circle","triangle","diamond","star","square","chevron","cross","wye"];function hn(t,e,i){if(i)return i;const o=t??"circle";return"chevron"===o?function(t){const e=1.5*function(t){return Math.sqrt(Math.max(1,t)/Math.PI)}(t),i=.92*e;return`M0,${-e}L${i},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-i},${(.78*e).toFixed(3)}Z`}(e):tn(ln[o]??en,Math.max(1,e))()??""}var dn=new Map;function fn(t,e,i,o,n){const r=new Map;for(const s of t){const t=e(s),a=i(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const c=Math.floor(t/o)*o;let l=r.get(c);if(l||(l={start:c,end:c+o,total:0,categories:new Map},r.set(c,l)),l.total+=a,n){const t=n(s);l.categories.set(t,(l.categories.get(t)||0)+a)}}return r}function pn(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:i,overlays:o,warned:n}=t;yn(o)&&0===i.length&&gn(n,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),i.length>0&&i.every(t=>null==t.datum)&&gn(n,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function yn(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(yn))}function gn(t,e,i){t.has(e)||(t.add(e),console.warn(i))}function mn(t,e,i,o){const n=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${n.message}`,error:n,recovery:i?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:i,affectedRevision:o}}function xn(t,e){const i="function"==typeof t?t:i=>i[t||e];return t=>{const e=i(t);return null==e?NaN:+e}}function bn(t){const e=[],i=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,o=xn(i&&t.valueAccessor||t.yAccessor,i?"value":"y");if(t.boundsAccessor){const i=r(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=o(t);if(!Number.isFinite(e))return NaN;const n=i(t);return Number.isFinite(n)&&0!==n?e+n:e},getBottom:t=>{const e=o(t);if(!Number.isFinite(e))return NaN;const n=i(t);return Number.isFinite(n)&&0!==n?e-n:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const i=Array.isArray(t.band)?t.band:[t.band];for(const t of i)e.push({kind:"band",getTop:xn(t.y1Accessor,"y1"),getBottom:xn(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as vn,scaleLog as wn,scaleSymlog as kn,scaleTime as Sn}from"d3-scale";function An(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Mn(t,e,i){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return wn().domain(t).range(i).clamp(!0)}return"symlog"===t?kn().domain(e).range(i):"time"===t?Sn().domain([new Date(e[0]),new Date(e[1])]).range(i):vn().domain(e).range(i)}function _n(t,e,i){e>t.capacity&&(t.resize(e),i&&e>i.capacity&&i.resize(e))}function Pn(t,e){const i=new ko(t.capacity);return t.forEach(()=>i.push(e)),i}function Rn(t,e,i,o){const n=t.push(e);return i&&i.push(o),n}function Tn(t,e,i){if(!e||0===e.size)return;const o=new Set;if(t.forEach((t,e)=>{i(t)&&o.add(e)}),0===o.size)return;const n=e.toArray();e.clear();for(let t=0;n.length>t;t++)o.has(t)||e.push(n[t])}var Ln=new WeakMap;function Cn(){return this.updateResults.last}function $n(){return this.updateResults.last}function zn(t){return this.updateResults.subscribe(t)}function Dn(t){this.config.layoutSelection=t}function En(){Ln.set(this,!0)}function In(){const t=!0===Ln.get(this);return Ln.delete(this),t}function Fn(t){Object.assign(t.prototype,{getLastUpdateResult:Cn,getUpdateSnapshot:$n,subscribeUpdateResult:zn,setLayoutSelection:Dn,markStylePaintPending:En,consumeStylePaintPending:In})}var Nn=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Bn=["scene-style","data-paint","accessibility","evidence"],On=(t,e)=>({retainedData:t,invalidations:e}),Wn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],jn=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Yn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Xn=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],qn=["scene-geometry","data-paint","accessibility","evidence"],Gn=["scene-style","data-paint","accessibility","evidence"],Vn=[],Hn={chartType:On("rebuild",Wn),runtimeMode:On("rebuild",Wn),xAccessor:On("rebuild",Wn),yAccessor:On("rebuild",Wn),timeAccessor:On("rebuild",Wn),valueAccessor:On("rebuild",Wn),y0Accessor:On("rebuild",Wn),boundsAccessor:On("rebuild",Wn),band:On("rebuild",Wn),openAccessor:On("rebuild",Wn),highAccessor:On("rebuild",Wn),lowAccessor:On("rebuild",Wn),closeAccessor:On("rebuild",Wn),candlestickRangeMode:On("rebuild",Wn),accessorRevision:On("rebuild",Wn),groupAccessor:On("rebuild",jn),categoryAccessor:On("rebuild",jn),lineDataAccessor:On("rebuild",jn),colorAccessor:On("rebuild",Gn),sizeAccessor:On("rebuild",qn),symbolAccessor:On("rebuild",qn),pointIdAccessor:On("rebuild",qn),xScaleType:On("preserve",Yn),yScaleType:On("preserve",Yn),xExtent:On("preserve",Yn),yExtent:On("preserve",Yn),extentPadding:On("preserve",Yn),scalePadding:On("preserve",Yn),axisExtent:On("preserve",Yn),binSize:On("preserve",Yn),normalize:On("preserve",Yn),heatmapAggregation:On("preserve",Yn),heatmapXBins:On("preserve",Yn),heatmapYBins:On("preserve",Yn),arrowOfTime:On("preserve",Xn),baseline:On("preserve",Xn),stackOrder:On("preserve",Xn),sizeRange:On("preserve",Xn),curve:On("preserve",Xn),areaGroups:On("preserve",Xn),customLayout:On("preserve",Xn),layoutConfig:On("preserve",Xn),layoutMargin:On("preserve",Xn),symbolMap:On("preserve",qn),showValues:On("preserve",qn),heatmapValueFormat:On("preserve",qn),lineStyle:On("preserve",Gn),pointStyle:On("preserve",Gn),areaStyle:On("preserve",Gn),barStyle:On("preserve",Gn),swarmStyle:On("preserve",Gn),waterfallStyle:On("preserve",Gn),candlestickStyle:On("preserve",Gn),boundsStyle:On("preserve",Gn),gradientFill:On("preserve",Gn),lineGradient:On("preserve",Gn),colorScheme:On("preserve",Gn),themeCategorical:On("preserve",Gn),themeSemantic:On("preserve",Gn),themeSequential:On("preserve",Gn),themeDiverging:On("preserve",Gn),barColors:On("preserve",Gn),decay:On("preserve",Gn),pulse:On("preserve",Gn),staleness:On("preserve",Gn),layoutSelection:On("preserve",Gn),annotations:On("preserve",["overlay","accessibility","evidence"]),windowSize:On("preserve",Vn),windowMode:On("preserve",Vn),maxCapacity:On("preserve",Vn),clock:On("preserve",Vn),transition:On("preserve",Vn),introAnimation:On("preserve",Vn),onLayoutError:On("preserve",Vn)},Zn=On("preserve",Xn),Kn=class{constructor(){this.tracker=new bi}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Nn)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Bn):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const i=new Set;for(const o of t){const t=Hn[o]??Zn;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as Un}from"d3-quadtree";var Qn=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(t,e){if("scatter"!==t&&"bubble"!==t&&"custom"!==t)return void this.clear();let i=0,o=0;for(const t of e)"point"===t.type&&(i++,t.r>o&&(o=t.r));if(this.maxRadius=o,500>=i)return void(this.tree=null);const n=Array(i);let r=0;for(const t of e)"point"===t.type&&(n[r++]=t);this.tree=Un().x(t=>t.x).y(t=>t.y).addAll(n)}},Jn=class e{constructor(t){if(this.xExtent=new So,this.yExtent=new So,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new Kn,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.spatialIndex=new Qn,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,i)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,i,o,n,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;const l=n??(()=>{const t=new Map;for(let e=0;i.length>e;e++)t.set(i[e],e);return t})();for(const i of e){if("line"===i.type)continue;if("area"===i.type){const e=Array.isArray(i.datum)?i.datum:[i.datum];let n=0,a=!1;for(const i of e){const e=l.get(i);if(null==e)continue;a=!0;const s=o.get(e);if(null==s)continue;const c=Do(t,s,r);c>n&&(n=c)}a&&(c=Eo(i,n,s)||c);continue}const e=l.get(i.datum);if(null==e)continue;const n=o.get(e);c=Eo(i,null==n?0:Do(t,n,r),s,a)||c}return c}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),i),this.config=t,this.buffer=new ko(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=r(t.timeAccessor||t.xAccessor,"time"),this.getY=r(t.valueAccessor||t.yAccessor,"value")):(this.getX=r(t.xAccessor,"x"),this.getY=r(t.yAccessor,"y")),this.getGroup=a(t.groupAccessor),this.getCategory=a(t.categoryAccessor),this.getSize=t.sizeAccessor?r(t.sizeAccessor,"size"):void 0,this.getColor=a(t.colorAccessor),this.getSymbol=a(t.symbolAccessor),this.getY0=t.y0Accessor?r(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=bn(t),this.getPointId=a(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,i=null!=t.closeAccessor;this.getOpen=e?r(t.openAccessor,"open"):void 0,this.getHigh=r(t.highAccessor,"high"),this.getLow=r(t.lowAccessor,"low"),this.getClose=i?r(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!i}t.pulse&&(this.timestampBuffer=new ko(t.windowSize))}currentTime(){return this.config.clock?.()??Co()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Pn(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(t)),void this.yExtent.push(this.getLow(t));this.yExtent.push(this.getY(t)),this.getY0&&this.yExtent.push(this.getY0(t));for(const e of this.resolvedRibbons){const i=e.getTop(t),o=e.getBottom(t);Number.isFinite(i)&&this.yExtent.push(i),Number.isFinite(o)&&this.yExtent.push(o)}}evictDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(t)),void this.yExtent.evict(this.getLow(t));this.yExtent.evict(this.getY(t)),this.getY0&&this.yExtent.evict(this.getY0(t));for(const e of this.resolvedRibbons){const i=e.getTop(t),o=e.getBottom(t);Number.isFinite(i)&&this.yExtent.evict(i),Number.isFinite(o)&&this.yExtent.evict(o)}}rebuildYExtent(){this.yExtent.clear();for(const t of this.buffer)this.pushDatumYExtent(t)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const t of this.buffer)this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t)}ingest(t){if(t.bounded&&this._lastBoundedInsertsRef===t.inserts)return this.updateResults.recordNoop("replace"),!1;const e=this.currentTime();if(this.lastIngestTime=e,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,t.bounded){this._lastBoundedInsertsRef=t.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const i=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=i?r(this.config.timeAccessor||this.config.xAccessor,"time"):r(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],i=this.config.xAccessor,o="function"==typeof i?i(e):e[i||"x"],n=o instanceof Date,r="string"==typeof o&&Number.isFinite(Mo(o));if(this.xIsDate=n||r,r){const t="string"==typeof i?i:void 0;this.getX=t?e=>_o(e[t]):t=>_o(i(t))}}_n(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const i of t.inserts)Rn(this.buffer,i,this.timestampBuffer,e),this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i)}else for(const i of t.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const t=this.config.maxCapacity??1e5;t>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,t),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${t}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const t=Rn(this.buffer,i,this.timestampBuffer,e);this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i),null!=t&&(this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t))}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}computeScene(t){const{config:e,buffer:i}=this,o=this.scales,n=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(i,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=An(this.xExtent.extent,e.xExtent),c=An(s,e.yExtent);const l=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const h="exact"===e.axisExtent;if("stackedarea"===e.chartType&&!l&&i.size>0){const t=function(t){const{config:e,groups:i,getX:o,getY:n}=t,r="exact"===e.axisExtent;if(e.normalize){const i=[0,r?1:1+e.extentPadding];return{yDomain:i,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:i}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,c=new Set;let l=0;const u=new Map,h=new Map;for(const t of i){const e=new Map;let i=0;for(const r of t.data){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),c.add(t),i+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>l&&(l=a)}a.set(t.key,e),h.set(t.key,i)}const d=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,y;if("input"===d)p=i.map(t=>t.key);else if("insideOut"===d){const t=[...i].map(t=>t.key).sort((t,e)=>{const i=(h.get(e)??0)-(h.get(t)??0);return 0!==i?i:f(t,e)}),e=[],o=[];let n=0,r=0;for(const i of t)r>n?(e.push(i),n+=h.get(i)??0):(o.push(i),r+=h.get(i)??0);p=[...o.reverse(),...e]}else p="asc"===d?i.map(t=>t.key).sort((t,e)=>{const i=(h.get(t)??0)-(h.get(e)??0);return 0!==i?i:f(t,e)}):"desc"===d?i.map(t=>t.key).sort((t,e)=>{const i=(h.get(e)??0)-(h.get(t)??0);return 0!==i?i:f(t,e)}):i.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),i=Oo(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let o=1/0,n=-1/0;for(const e of t){const t=i.get(e)??0,r=u.get(e)??0;o>t&&(o=t),t+r>n&&(n=t+r)}Number.isFinite(o)&&Number.isFinite(n)||(o=0,n=0);const s=n-o,l=r?0:s>0?s*e.extentPadding:1;y=[o-l,n+l]}else if("diverging"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),[i,o]=function(t,e,i){let o=0,n=0;for(const r of t){let t=0,s=0;for(const o of e){const e=i(o,r)||0;0>e?s+=e:t+=e}o>s&&(o=s),t>n&&(n=t)}return[o,n]}(t,p,(t,e)=>a.get(t)?.get(e)||0),n=o-i,s=r?0:n>0?n*e.extentPadding:1;y=[i-s,o+s]}else y=[0,l+(r?0:l>0?l*e.extentPadding:1)];return{yDomain:y,stackExtentCache:{key:s,yDomain:y}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:i.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!l&&i.size>0?c=function(t,e,i,o,n,r,s){const[,a]=function(t,e,i,o,n){const r=fn(t,e,i,o,n);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,i,o,n);return[0,s?a:a+a*r]}(i,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,h):"waterfall"===e.chartType&&!l&&i.size>0?c=function(t,e,i,o){const[n,r]=function(t,e){let i=0,o=0,n=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(n+=t,i>n&&(i=n),n>o&&(o=n))}return[i,o]}(t,e),s=r-n,a=o?0:s>0?s*i:1;return[Math.min(0,n-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(i,this.getY,e.extentPadding,h):l||c[0]===1/0||(c=function(t,e,i){if(!i.length)return t;let[o,n]=t;for(const t of e)for(const e of i){const i=e.getTop(t),r=e.getBottom(t);Number.isFinite(i)&&(o>i&&(o=i),i>n&&(n=i)),Number.isFinite(r)&&(o>r&&(o=r),r>n&&(n=r))}return[o,n]}(c,r,this.resolvedRibbons),c=function(t,e){const i=t[1]-t[0],o=e.exactMode?0:i>0?i*e.extentPadding:1,n=[null!=e.userMin?t[0]:t[0]-o,null!=e.userMax?t[1]:t[1]+o];return"log"!==e.yScaleType||n[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(n[0]=e.dataYDomain[0]/(1+e.extentPadding)),n}(c,{exactMode:h,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));c=function(t,e,i){if(!e||i)return t;const o=e[0],n=e[1];return null==o&&null==n?t:[null!=o?o:t[0],null!=n?n:t[1]]}(c,e.yExtent,!!l),({xDomain:a,yDomain:c}=function(t,e,i){let o=t,n=e;if(o[0]===1/0||o[1]===-1/0)if("time"===i){const t=Date.now();o=[t-864e5,t]}else o=[0,1];return n[0]!==1/0&&n[1]!==-1/0||(n=[0,1]),{xDomain:o,yDomain:n}}(a,c,e.xScaleType)),this.scales=function(t){const{config:e,layout:i,xDomain:o,yDomain:n}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(i.width,i.height)/2-1));if(r){if("x"==("up"===(a=e.arrowOfTime)||"down"===a?"y":"x")){const t="right"===e.arrowOfTime?[s,i.width-s]:[i.width-s,s];return{x:vn().domain(o).range(t),y:Mn(e.yScaleType,n,[i.height-s,s])}}const t="down"===e.arrowOfTime?[s,i.height-s]:[i.height-s,s];return{x:Mn(e.yScaleType,n,[s,i.width-s]),y:vn().domain(o).range(t)}}var a;return{x:Mn(e.xScaleType,o,[s,i.width-s]),y:Mn(e.yScaleType,n,[i.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:c}),this._customLayoutFailedThisBuild=!1;const d=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=d,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,i=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const o of t.path)o[0]*=e,o[1]*=i;break;case"area":for(const o of t.topPath)o[0]*=e,o[1]*=i;for(const o of t.bottomPath)o[0]*=e,o[1]*=i;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*i,width:t.clipRect.width*e,height:t.clipRect.height*i});break;case"point":case"glyph":t.x*=e,t.y*=i;break;case"rect":case"heatcell":t.x*=e,t.y*=i,t.w*=e,t.h*=i;break;case"candlestick":t.x*=e,t.openY*=i,t.closeY*=i,t.highY*=i,t.lowY*=i}const o=this.scales.x.domain(),n=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Mn,c=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),l=s[1]>s[0];this.scales={x:a(this.config.xScaleType,o,r[0]>r[1]?[t.width-c,c]:[c,t.width-c]),y:a(this.config.yScaleType,n,l?[c,t.height-c]:[t.height-c,c])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:i,scales:o}=this;if(!o)return[];if(i.customLayout){const n={data:e,scales:o,dimensions:{width:t.width,height:t.height,margin:i.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:i.themeSemantic??{},categorical:i.themeCategorical??U},resolveColor:(t,e)=>{const o=this.resolveGroupColor(t);if(o)return o;const n=this.resolveLineStyle(t,e);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:i.themeSemantic?.primary??"#4e79a7"},config:i.layoutConfig??{},selection:i.layoutSelection??null};let r;try{r=i.customLayout(n)}catch(t){const e=null!==this.lastCustomLayoutResult,o=mn("xy",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{i.onLayoutError?.(o)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null;const s=r.nodes??[];if(this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of s)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(s,i.layoutSelection??null)}return pn({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const n={scales:o,config:i,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(t,e)=>this.resolveLineStyle(t,e),resolveAreaStyle:(t,e)=>this.resolveAreaStyle(t,e),resolveBoundsStyle:(t,e)=>this.resolveBoundsStyle(t,e),resolveColorMap:t=>this.resolveColorMap(t),resolveGroupColor:t=>this.resolveGroupColor(t),groupData:t=>this.groupData(t),barCategoryCache:this._barCategoryCache};switch(i.chartType){case"line":return function(t,e){const i=t.groupData(e),o=[],n=t.config.annotations?.filter(Uo).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Vo(t.ribbons);if(r.length>0&&o.push(...Ho(t,e,r)),n.length>0)for(const e of i)o.push(...Zo(t,e.data,e.key,n))}for(const e of i){const i=t.resolveLineStyle(e.key,e.data[0]),r=No(e.data,t.scales,t.getX,t.getY,i,e.key);n&&n.length>0&&(r.colorThresholds=n),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),o.push(r)}return Ko(t,i,o),o}(n,e);case"area":return function(t,e){const i=t.groupData(e),o=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Vo(t.ribbons);if(r.length>0&&o.push(...Ho(t,e,r)),n.length>0)for(const e of i)o.push(...Zo(t,e.data,e.key,n))}const n=t.scales.y.domain()[0],r=t.getY0?e=>{const i=t.getY0(e);return null==i?n:i}:void 0;for(const e of i){const i=t.resolveAreaStyle(e.key,e.data[0]),s=Bo(e.data,t.scales,t.getX,t.getY,n,i,e.key,r),a=Jo(t.config.gradientFill);a&&(s.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(s.curve=t.config.curve),t.config.lineGradient&&(s.strokeGradient=t.config.lineGradient),o.push(s)}return Ko(t,i,o),o}(n,e);case"mixed":return function(t,e){const i=t.groupData(e),o=[],n=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Vo(t.ribbons);if(r.length>0&&o.push(...Ho(t,e,r)),n.length>0)for(const e of i)o.push(...Zo(t,e.data,e.key,n))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const i=t.getY0(e);return null==i?r:i}:void 0;for(const e of i)if(n.has(e.key)){const i=t.resolveAreaStyle(e.key,e.data[0]),n=Bo(e.data,t.scales,t.getX,t.getY,r,i,e.key,s),a=Jo(t.config.gradientFill);a&&(n.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),o.push(n)}else{const i=t.resolveLineStyle(e.key,e.data[0]),n=No(e.data,t.scales,t.getX,t.getY,i,e.key);t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),o.push(n)}return Ko(t,i,o),o}(n,e);case"stackedarea":return function(t,e){const i=t.groupData(e),o=t.config.stackOrder??"key",n=()=>i.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===o);else if("key"===o)n();else if("asc"===o||"desc"===o||"insideOut"===o){const e=new Map;for(const o of i){let i=0;for(const e of o.data){const o=t.getX(e),n=t.getY(e);Number.isFinite(o)&&Number.isFinite(n)&&(i+=n)}e.set(o.key,i)}const n=(t,e)=>e>t?-1:t>e?1:0;if("asc"===o)i.sort((t,i)=>{const o=(e.get(t.key)??0)-(e.get(i.key)??0);return 0!==o?o:n(t.key,i.key)});else if("desc"===o)i.sort((t,i)=>{const o=(e.get(i.key)??0)-(e.get(t.key)??0);return 0!==o?o:n(t.key,i.key)});else{const t=[...i].sort((t,i)=>{const o=(e.get(i.key)??0)-(e.get(t.key)??0);return 0!==o?o:n(t.key,i.key)}),o=[],r=[];let s=0,a=0;for(const i of t)a>s?(o.push(i),s+=e.get(i.key)??0):(r.push(i),a+=e.get(i.key)??0);i.length=0,i.push(...r.reverse(),...o)}}else n();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:c}=function(t,e,i,o,n,r,s,a="zero"){const c=new Set;for(const e of t)for(const t of e.data){const e=i(t);Number.isFinite(e)&&c.add(e)}const l=Array.from(c).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const n of e.data){const e=i(n),r=o(n);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let h;if(r){h=new Map;for(const e of l){let i=0;for(const o of t)i+=u.get(o.key)?.get(e)||0;h.set(e,i||1)}}const d=Oo(l,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,x=new Map;for(const t of l)g.set(t,d.get(t)??0),m.set(t,0),x.set(t,0);for(const i of t){const t=u.get(i.key),o=new Map;let a=[],c=[];const d=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:c,style:n(i.key,i.data[0]),datum:i.data,group:i.key};s&&(t.curve=s),p.push(t)}a=[],c=[]};for(const i of l){const n=t.has(i);let s,l,u=n?t.get(i):0;if(r&&n&&(u/=h.get(i)),!n||!Number.isFinite(u)||0===u){d();continue}f?u>0?(s=m.get(i),l=s+u,m.set(i,l)):(s=x.get(i),l=s+u,x.set(i,l)):(s=g.get(i),l=s+u,g.set(i,l));const p=e.x(i);c.push([p,e.y(s)]),a.push([p,e.y(l)]),o.set(i,l)}d(),y.set(i.key,o)}return{nodes:p,stackedTops:y}}(i,t.scales,t.getX,t.getY,(e,i)=>t.resolveAreaStyle(e,i),t.config.normalize,r,s),l=a;if(t.config.pointStyle){const e=new WeakMap;for(const o of i){const i=c.get(o.key);if(i)for(const n of o.data){const o=t.getX(n),r=t.getY(n);null==o||Number.isNaN(o)||null==r||Number.isNaN(r)||!i.has(o)||e.set(n,i.get(o))}}const o=i=>e.get(i)??t.getY(i);Ko(t,i,l,o)}return l}(n,e);case"scatter":case"bubble":return function(t,e){const i=[],o="bubble"===t.config.chartType?10:5,n=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const i=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(i.length>0){let t=1/0,e=-1/0;for(const o of i)t>o&&(t=o),o>e&&(e=o);r=i=>t===e?(n[0]+n[1])/2:n[0]+(i-t)/(e-t)*(n[1]-n[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",c=t.getSymbol,l=t.config.symbolMap,u=new Map;let h=0;const d=t=>{const e=l?.[t];if(e)return e;let i=u.get(t);return i||(i=un[h%un.length],h++,u.set(t,i)),i};for(const n of e){let e=t.config.pointStyle?t.config.pointStyle(n):{fill:a,opacity:.8},l=e.r||o;if(r&&t.getSize){const e=t.getSize(n);null==e||Number.isNaN(e)||(l=r(e))}if(s&&t.getColor&&!e.fill){const i=t.getColor(n);i&&s.has(i)&&(e={...e,fill:s.get(i)})}const u=t.getPointId?t.getPointId(n)+"":void 0;if(c){const o=d(c(n)+""),r=jo(n,t.scales,t.getX,t.getY,Math.PI*l*l,o,e,u);r&&i.push(r)}else{const o=Wo(n,t.scales,t.getX,t.getY,l,e,u);o&&i.push(o)}}return i}(n,e);case"heatmap":return function(t,e,i){if(t.config.heatmapAggregation)return function(t,e,i){const o=Math.max(1,Math.floor(t.config.heatmapXBins??20)),n=Math.max(1,Math.floor(t.config.heatmapYBins??20)),s=t.config.heatmapAggregation??"count",a=r(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[c,l]=t.scales.x.domain(),[u,h]=t.scales.y.domain(),d=(l-c||1)/o,f=(h-u||1)/n,p=o*n;if(p>1e6)return[];const y=new Int32Array(p),g=new Float64Array(p);for(let i=0;e.length>i;i++){const r=e[i],s=t.getX(r),l=t.getY(r);if(!isFinite(s)||!isFinite(l))continue;const h=Math.min(Math.floor((s-c)/d),o-1),p=Math.min(Math.floor((l-u)/f),n-1);if(0>h||0>p)continue;const m=p*o+h;y[m]++;const x=a(r);g[m]+=isFinite(x)?x:0}let m=1/0,x=-1/0;for(let t=0;p>t;t++){if(0===y[t])continue;let e;switch(s){case"sum":e=g[t];break;case"mean":e=g[t]/y[t];break;default:e=y[t]}m>e&&(m=e),e>x&&(x=e)}if(!isFinite(m))return[];const b=x-m||1,v=i.width/o,w=i.height/n,k=t.config.showValues,S=t.config.heatmapValueFormat,A=[];for(let t=0;n>t;t++){const e=t*o;for(let i=0;o>i;i++){const o=e+i;if(0===y[o])continue;let r;switch(s){case"sum":r=g[o];break;case"mean":r=g[o]/y[o];break;default:r=y[o]}const a=(r-m)/b;A.push(Xo(i*v,(n-1-t)*w,v,w,`rgb(${220-(180*a+.5)|0},${220-(100*a+.5)|0},${255-(50*a+.5)|0})`,{xi:i,yi:t,value:r,count:y[o],sum:g[o],xCenter:c+(i+.5)*d,yCenter:u+(t+.5)*f,agg:s},k?{value:r,showValues:!0,valueFormat:S}:void 0))}}return A}(t,e,i);if(0===e.length)return[];const o=r(t.config.valueAccessor,"value"),n=s(t.config.xAccessor,"x"),a=s(t.config.yAccessor,"y"),c=new Map,l=new Map,u=Array(e.length),h=Array(e.length);for(let t=0;e.length>t;t++){const i=e[t],o=n(i),r=a(i);u[t]=o,h[t]=r,c.has(o)||c.set(o,c.size),l.has(r)||l.set(r,l.size)}const d=c.size,f=l.size;if(0===d||0===f)return[];const p=Array.from(c.keys()),y=Array.from(l.keys()),g=p.every(t=>"number"==typeof t&&!isNaN(t)),m=y.every(t=>"number"==typeof t&&!isNaN(t));if(g){p.sort((t,e)=>Number(t)-Number(e)),c.clear();for(let t=0;p.length>t;t++)c.set(p[t],t)}if(m){y.sort((t,e)=>Number(t)-Number(e)),l.clear();for(let t=0;y.length>t;t++)l.set(y[t],t)}const x=new Float64Array(e.length),b=new Float64Array(e.length),v=Array(e.length),w=new Map;let k=0;for(let t=0;e.length>t;t++){const i=e[t],n=c.get(u[t]),r=l.get(h[t]);if(void 0===n||void 0===r)continue;const s=o(i),a=r*d+n,f=w.get(a);let p;void 0!==f?p=f:(p=k++,w.set(a,p)),x[p]=a,b[p]=s,v[p]=i}let S=1/0,A=-1/0;for(let t=0;k>t;t++){const e=b[t];isFinite(e)&&(S>e&&(S=e),e>A&&(A=e))}if(!isFinite(S)||!isFinite(A))return[];const M=function(t){const e=t in V?t:"blues";let i=dn.get(e);if(i)return i;i=Array(256);const o=H(e);for(let t=0;256>t;t++)i[t]=o(t/255);return dn.set(e,i),i}("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),_=255/(A-S||1),P=i.width/d,R=i.height/f,T=t.config.showValues,L=t.config.heatmapValueFormat,C=[];for(let t=0;k>t;t++){const e=b[t];if(!isFinite(e))continue;const i=x[t],o=i%d;C.push(Xo(o*P,(f-1-(i-o)/d)*R,P,R,M[Math.min((e-S)*_+.5|0,255)],v[t],T?{value:e,showValues:!0,valueFormat:L}:void 0))}return C}(n,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const i=fn(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===i.size)return{nodes:[],binBoundaries:[]};let o=null;if(t.getCategory){const e=new Set;for(const t of i.values())for(const i of t.categories.keys())e.add(i);const n=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(n),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=n.filter(t=>e.has(t)),c=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===c?o=t.barCategoryCache.order:(o=[...a,...s],t.barCategoryCache={key:c,order:o})}const n=[],r=t.scales,[s,a]=r.x.domain(),c=t.config.barStyle,l=t.config.themeSemantic?.primary,u=c?.gap,h="number"!=typeof u||0>u?1:u,d={};c?.stroke&&(d.stroke=c.stroke),"number"==typeof c?.strokeWidth&&(d.strokeWidth=c.strokeWidth),"number"==typeof c?.opacity&&(d.opacity=c.opacity);for(const e of i.values()){const i=Math.max(e.start,s),u=Math.min(e.end,a);if(i>=u)continue;const f=r.x(i),p=r.x(u),y=Math.abs(p-f),g=y>h+1?h:0,m=Math.min(f,p)+g/2,x=Math.max(y-g,1);if(x>0)if(o&&e.categories.size>0){let i=0;for(const s of o){const o=e.categories.get(s)||0;if(0===o)continue;const a=r.y(i),u=r.y(i+o);n.push(Yo(m,Math.min(a,u),x,Math.abs(a-u),{fill:t.config.barColors?.[s]||c?.fill||l||"#4e79a7",...d},{binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:o},s)),i+=o}}else{const t=r.y(0),i=r.y(e.total);n.push(Yo(m,Math.min(t,i),x,Math.abs(t-i),{fill:c?.fill||l||"#007bff",...d},{binStart:e.start,binEnd:e.end,total:e.total}))}}const f=new Set;for(const t of i.values())f.add(t.start),f.add(t.end);return{nodes:n,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(n,e);return this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const i=[],o=t.config.swarmStyle||{},n=o.radius??3,r=o.fill??t.config.themeSemantic?.primary??"#007bff",s=o.opacity??.7,a=o.stroke,c=o.strokeWidth;for(const o of e){const e=t.getX(o),l=t.getY(o);if(null==l||Number.isNaN(l))continue;const u=t.scales.x(e),h=t.scales.y(l);let d=r;if(t.getCategory){const e=t.getCategory(o);d=t.config.barColors?.[e]||d}const{r:f,...p}=t.config.pointStyle?.(o)??{},y={type:"point",x:u,y:h,r:f??n,style:{fill:d,opacity:s,stroke:a,strokeWidth:c,...p},datum:o};t.getPointId&&(y.pointId=t.getPointId(o)+""),i.push(y)}return i}(n,e);case"waterfall":return function(t,e,i){const o=[],n=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const i=t.getY(e),o=t.getX(e);return null!=i&&!Number.isNaN(i)&&null!=o&&isFinite(o)});if(0===s.length)return o;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",c=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",l=r?.gap??1,u=r?.stroke,h=r?.strokeWidth,d=r?.opacity;let f=0;for(let e=0;s.length>e;e++){const p=s[e],y=t.getX(p),g=t.getY(p),m=f+g;let x;x=s.length-1>e?t.getX(s[e+1])-y:e>0?y-t.getX(s[e-1]):0;const b=n.x(y),v=0!==x?n.x(y+x):b+i.width/10,w=Math.min(b,v)+l/2,k=Math.max(b,v)-l/2-w;if(0>=k){f=m;continue}const S=n.y(f),A=n.y(m),M=Math.min(S,A),_=Math.abs(S-A),P={fill:0>g?c:a,stroke:u,strokeWidth:h};null!=d&&(P.opacity=d),o.push(Yo(w,M,k,_,P,{...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth})),f=m}return o}(n,e,t);case"candlestick":return function(t,e){if(!t.getHigh||!t.getLow||!t.scales)return[];const i=t.config.candlestickRangeMode??!1;if(!(i||t.getOpen&&t.getClose))return[];const o=[],n=t.config.candlestickStyle||{},r=n.rangeColor||"#6366f1",s=i?r:n.upColor||"#28a745",a=i?r:n.downColor||"#dc3545",c=i?r:n.wickColor||"#333",l=n.wickWidth||(i?2:1),u=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=n.bodyWidth??0;if(null==n.bodyWidth)if(u.length>1){let e=1/0;for(let i=1;u.length>i;i++){const o=Math.abs(t.scales.x(u[i])-t.scales.x(u[i-1]));o>0&&e>o&&(e=o)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const n of e){const e=t.getX(n);if(null==e||Number.isNaN(e))continue;const r=t.getHigh(n),u=t.getLow(n);if(null==r||Number.isNaN(r)||null==u||Number.isNaN(u))continue;const d=i?r:t.getOpen(n),f=i?u:t.getClose(n);if(!i&&[d,f].some(t=>null==t||Number.isNaN(t)))continue;const p=f>=d,y={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(d),closeY:t.scales.y(f),highY:t.scales.y(r),lowY:t.scales.y(u),bodyWidth:h,upColor:s,downColor:a,wickColor:c,wickWidth:l,isUp:p,datum:n};i&&(y.isRange=!0),o.push(y)}return o}(n,e);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,i,o){const n=t.boundsStyle;return"function"==typeof n?n(i||{},e):n&&"object"==typeof n?n:{fill:o(e,i).stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none"}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const i=this.config.decay;return i&&e>1?$o(i,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=zo(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,i,o=zo(i)){const n=i.length;if(n>1)for(const i of e){if("line"===i.type){const e=Array.isArray(i.datum)?i.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let i=0;e.length>i;i++){const a=o.get(e[i]);null!=a?(r[i]=$o(t,a,n),1>r[i]&&(s=!0)):r[i]=1}s&&(i._decayOpacities=r);continue}if("area"===i.type){const e=Array.isArray(i.datum)?i.datum:[],r=i.topPath?i.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let i=0;e.length>i;i++){const r=o.get(e[i]);null!=r?(s[i]=$o(t,r,n),1>s[i]&&(a=!0)):s[i]=1}a&&(i._decayOpacities=s)}else{let s=1;for(const i of e){const e=o.get(i);if(null!=e){const i=$o(t,e,n);s>i&&(s=i)}}if(1>s){const t=Array(r);t.fill(s),i._decayOpacities=t}}continue}const e=o.get(i.datum);if(null==e)continue;const r=$o(t,e,n);"heatcell"===i.type?i.style={opacity:r}:"candlestick"===i.type?i._decayOpacity=r:i.style={...i.style,opacity:(i.style?.opacity??1)*r}}}(this.config.decay,t,e,this.getDatumIndexMap(e))}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Io(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(t,e,i,o){i.clear(),o.clear();for(let n=0;e.length>n;n++){const r=e[n],s=Fo(t,r,n);s&&("point"===r.type?i.set(s,{x:r.x,y:r.y,r:r.r,opacity:r.style.opacity}):"glyph"===r.type?i.set(s,{x:r.x,y:r.y,r:r.size,opacity:r.style.opacity,glyph:r.glyph}):"rect"===r.type?i.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style.opacity}):"heatcell"===r.type?i.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style?.opacity}):"candlestick"===r.type?i.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:r.style?.opacity}):"line"===r.type?o.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&o.set(s,{topPath:r.topPath.map(t=>[t[0],t[1]]),bottomPath:r.bottomPath.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const t=this.scales?.y(0)??0;for(let e=0;this.scene.length>e;e++){const i=this.scene[e],o=Fo(this.transitionContext,i,e);o&&("point"===i.type?this.prevPositionMap.set(o,{x:i.x,y:i.y,r:0,opacity:0}):"rect"===i.type?this.prevPositionMap.set(o,{x:i.x,y:t,w:i.w,h:0,opacity:i.style.opacity??1}):"heatcell"===i.type?this.prevPositionMap.set(o,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:0}):"line"===i.type?(i._introClipFraction=0,this.prevPathMap.set(o,{path:i.path.map(t=>[t[0],t[1]]),opacity:i.style.opacity})):"area"===i.type&&(i._introClipFraction=0,this.prevPathMap.set(o,{topPath:i.topPath.map(t=>[t[0],t[1]]),bottomPath:i.bottomPath.map(t=>[t[0],t[1]]),opacity:i.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,i,o,n,r=Co()){if(0===o.size&&0===n.size)return i;const s=e.duration??300;if(i.exitNodes.length>0){const t=new Set(i.exitNodes);i.scene=i.scene.filter(e=>!t.has(e)),i.exitNodes=[]}let a=!1;const c=new Set,l=new Set;for(let e=0;i.scene.length>e;e++){const r=i.scene[e],s=Fo(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=n.get(s);if(t){if(l.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=o.get(s);if("point"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=r.style?.opacity??1,u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=r.style?.opacity??1,r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){c.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=r.style?.opacity??1,(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=r.style?.opacity??1,r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of n)if(!l.has(t))if(t.startsWith("l:")&&e.path){const o={type:"line",path:e.path.map(t=>[t[0],t[1]]),group:t.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};i.exitNodes.push(o),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const o={type:"area",topPath:e.topPath.map(t=>[t[0],t[1]]),bottomPath:e.bottomPath.map(t=>[t[0],t[1]]),group:t.slice(2),style:{fill:"#999",opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};i.exitNodes.push(o),a=!0}for(const[t,e]of o)if(!c.has(t)){if(t.startsWith("p:"))i.exitNodes.push({type:"point",x:e.x,y:e.y,r:e.r??3,style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("g:")&&e.glyph)i.exitNodes.push({type:"glyph",x:e.x,y:e.y,size:e.r??12,glyph:e.glyph,color:"#999",accent:"#999",style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))i.exitNodes.push({type:"rect",x:e.x,y:e.y,w:e.w??0,h:e.h??0,style:{opacity:e.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("h:"))i.exitNodes.push({type:"heatcell",x:e.x,y:e.y,w:e.w??0,h:e.h??0,fill:"#999",datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t});else if(t.startsWith("c:")){const o=e.openY??e.y;i.exitNodes.push({type:"candlestick",x:e.x,openY:o,closeY:e.closeY??o,highY:e.highY??o,lowY:e.lowY??o,bodyWidth:e.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t})}a=!0}return i.exitNodes.length>0&&(i.scene=[...i.scene,...i.exitNodes]),a&&(i.activeTransition={startTime:r,duration:s}),i}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(t){if(!this.activeTransition||!this.config.transition)return!1;const e={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},i=function(t,e,i,o){if(!i.activeTransition)return!1;const n=To(t,i.activeTransition),r=Ro(n,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of i.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const i=e?o.get(e):void 0;t.style.opacity=Lo(i?i.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const i=o.get(e);if(!i)continue;t.x=Lo(i.x,t._targetX,r),t.y=Lo(i.y,t._targetY,r),void 0!==t._targetR&&void 0!==i.r&&(t.r=Lo(i.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const i=e?o.get(e):void 0;t.style.opacity=Lo(i?i.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const i=o.get(e);if(!i)continue;t.x=Lo(i.x,t._targetX,r),t.y=Lo(i.y,t._targetY,r),void 0!==t._targetR&&void 0!==i.r&&(t.size=Lo(i.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const i=e?o.get(e):void 0;t.style.opacity=Lo(i?i.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const i=o.get(e);if(!i)continue;t.x=Lo(i.x,t._targetX,r),t.y=Lo(i.y,t._targetY,r),void 0!==i.w&&(t.w=Lo(i.w,t._targetW,r)),void 0!==i.h&&(t.h=Lo(i.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const i=e?o.get(e):void 0;t.style={...t.style||{},opacity:Lo(i?i.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const i=o.get(e);if(!i)continue;t.x=Lo(i.x,t._targetX,r),t.y=Lo(i.y,t._targetY,r),void 0!==i.w&&(t.w=Lo(i.w,t._targetW,r)),void 0!==i.h&&(t.h=Lo(i.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const i=e?o.get(e):void 0;t.style={...t.style||{},opacity:Lo(i?i.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const i=o.get(e);if(!i)continue;t.x=Lo(i.x,t._targetX,r),void 0!==i.openY&&(t.openY=Lo(i.openY,t._targetOpenY,r)),void 0!==i.closeY&&(t.closeY=Lo(i.closeY,t._targetCloseY,r)),void 0!==i.highY&&(t.highY=Lo(i.highY,t._targetHighY,r)),void 0!==i.lowY&&(t.lowY=Lo(i.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Lo(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,i=t._targetPath;if(e&&i&&e.length===t.path.length)for(let o=0;t.path.length>o;o++)t.path[o][0]=Lo(e[o][0],i[o][0],r),t.path[o][1]=Lo(e[o][1],i[o][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Lo(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,i=t._prevBottomPath,o=t._targetTopPath,n=t._targetBottomPath;if(e&&o&&e.length===t.topPath.length)for(let i=0;t.topPath.length>i;i++)t.topPath[i][0]=Lo(e[i][0],o[i][0],r),t.topPath[i][1]=Lo(e[i][1],o[i][1],r);if(i&&n&&i.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Lo(i[e][0],n[e][0],r),t.bottomPath[e][1]=Lo(i[e][1],n[e][1],r)}}if(n>=1){for(const t of i.scene){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style="line"===t.type||"area"===t.type?{...t.style,opacity:0===e?0:e}:{...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("glyph"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("heatcell"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("candlestick"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0}else if("line"===t.type){const e=t._targetPath;if(e)for(let i=0;t.path.length>i;i++)t.path[i]=e[i];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,i=t._targetBottomPath;if(e)for(let i=0;t.topPath.length>i;i++)t.topPath[i]=e[i];if(i)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=i[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(i.exitNodes.length>0){const t=new Set(i.exitNodes);i.scene=i.scene.filter(e=>!t.has(e)),i.exitNodes=[]}return i.activeTransition=null,!1}return!0}(t,this.config.transition,e,this.prevPositionMap);return this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition,i}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null;for(const t of this.scene)"line"!==t.type&&"area"!==t.type||(t._introClipFraction=void 0)}groupData(t){const{result:e,cache:i}=function(t,e,i,o){if(o&&o.version===i&&o.group===e&&o.data===t)return{result:o.result,cache:o};let n;if(e){const i=new Map;for(const o of t){const t=e(o);i.has(t)||i.set(t,[]),i.get(t).push(o)}n=Array.from(i.entries()).map(([t,e])=>({key:t,data:e}))}else n=[{key:"_default",data:t}];return{result:n,cache:{version:i,group:e,data:t,result:n}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=i,e}resolveColorMap(t){const{map:e,cache:i}=function(t,e,i,o,n){if(n&&n.version===o)return{map:n.map,cache:n};const r=new Set;if(e)for(const i of t){const t=e(i);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(n&&n.key===a){const t={...n,version:o};return{map:t.map,cache:t}}const c=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical||U,l=new Map;for(let t=0;s.length>t;t++)l.set(s[t],c[t%c.length]);return{map:l,cache:{key:a,map:l,version:o}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=i,e}resolveLineStyle(t,e){return function(t,e,i,o){const n=t.lineStyle;if("function"==typeof n){const t=n(i||{},e);if(t&&!t.stroke&&e){const i=o(e);if(i)return{...t,stroke:i}}return t}const r=t.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||r||"#007bff",strokeWidth:n.strokeWidth||2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity}:{stroke:o(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,i,o){if(t.areaStyle){const n=t.areaStyle(i||{});if(n&&!n.fill&&e){const t=o(e);if(t)return{...n,fill:t,stroke:n.stroke||t}}return n}const n=t.lineStyle;if("function"==typeof n){const t=n(i||{},e);if(t&&!t.fill&&e){const i=o(e);if(i)return{...t,fill:i,stroke:t.stroke||i}}return t}const r=t.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||r||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||r||"#4e79a7",strokeWidth:n.strokeWidth||2};const s=o(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(t){const{color:i,groupColorCounter:o}=function(t){const{group:e,colorMapCache:i,groupColorMap:o,groupColorMapCap:n,config:r}=t;let{groupColorCounter:s}=t;if(i){const t=i.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=o.get(e);if(a)return{color:a,groupColorCounter:s};const c=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||U;if(0===c.length)return{color:null,groupColorCounter:s};const l=c[s%c.length];if(s++,o.set(e,l),o.size>n){const t=o.keys().next().value;void 0!==t&&o.delete(t)}return{color:l,groupColorCounter:s}}({group:t,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:e.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=o,i}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(t){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Po(t),i=this.getPointId,o=t=>e.has(i(t));Tn(this.buffer,this.timestampBuffer,o);const n=this.buffer.remove(o);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const i=Po(t),o=this.getPointId,n=new Set;this.buffer.forEach((t,e)=>{i.has(o(t))&&n.add(e)});const r=this.buffer.update(t=>i.has(o(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{n.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const i=this._customRestyle;if(i)for(const o of t){const t=this._baseStyles.get(o)??o.style??{},n=i(o,e);o.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){const i={...this.config},o=Object.keys(e).filter(t=>e[t]!==i[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==i.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${i.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in e||"colorScheme"in e)&&(this._barCategoryCache=null),("normalize"in e||"extentPadding"in e||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e||"boundsAccessor"in e||"band"in e||"y0Accessor"in e||"openAccessor"in e||"highAccessor"in e||"lowAccessor"in e||"closeAccessor"in e||"groupAccessor"in e||"categoryAccessor"in e||"chartType"in e||"runtimeMode"in e)&&(this._stackExtentCache=null);let n=!1,s=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();const c="chartType"in e&&e.chartType!==i.chartType||"runtimeMode"in e&&e.runtimeMode!==i.runtimeMode;if(c||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){const e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=e&&this.config.valueAccessor||this.config.yAccessor,a=e&&i.valueAccessor||i.yAccessor,l=c||!t(e&&this.config.timeAccessor||this.config.xAccessor,e&&i.timeAccessor||i.xAccessor),u=c||!t(o,a);(l||u)&&(e?(this.getX=r(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=r(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=r(this.config.xAccessor,"x"),this.getY=r(this.config.yAccessor,"y")),u&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=bn(this.config)),n=!0,s=!0)}if("groupAccessor"in e&&!t(e.groupAccessor,i.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?a(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in e&&!t(e.categoryAccessor,i.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?a(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in e&&!t(e.sizeAccessor,i.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?r(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in e&&!t(e.symbolAccessor,i.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?a(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in e&&!t(e.colorAccessor,i.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?a(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in e&&!t(e.y0Accessor,i.y0Accessor)&&(this.getY0=this.config.y0Accessor?r(this.config.y0Accessor,"y0"):void 0,n=!0,s=!0),("boundsAccessor"in e&&!t(e.boundsAccessor,i.boundsAccessor)||"band"in e&&e.band!==i.band||"boundsStyle"in e&&e.boundsStyle!==i.boundsStyle)&&(this.resolvedRibbons=bn(this.config),n=!0,s=!0),"pointIdAccessor"in e&&!t(e.pointIdAccessor,i.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?a(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(c||"openAccessor"in e&&!t(e.openAccessor,i.openAccessor)||"closeAccessor"in e&&!t(e.closeAccessor,i.closeAccessor)||"highAccessor"in e&&!t(e.highAccessor,i.highAccessor)||"lowAccessor"in e&&!t(e.lowAccessor,i.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?r(this.config.openAccessor,"open"):void 0,this.getHigh=r(this.config.highAccessor,"high"),this.getLow=r(this.config.lowAccessor,"low"),this.getClose=e?r(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,n=!0,s=!0}if("accessorRevision"in e&&e.accessorRevision!==i.accessorRevision&&(n=!0,s=!0),!n){const t=Object.keys(e).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const o of t)if(e[o]!==i[o]){n=!0;break}}n&&(s&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Jn.GROUP_COLOR_MAP_CAP=1e3;var tr=Jn;Fn(tr);import*as er from"react";import{arc as ir}from"d3-shape";import{jsx as or,jsxs as nr}from"react/jsx-runtime";function rr(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function sr(t,e){const{background:i="transparent",stroke:o="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,c=Math.max(8,Math.ceil(2*r));return nr("pattern",{id:e,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[i&&"transparent"!==i&&or("rect",{width:c,height:c,fill:i}),or("line",{x1:0,y1:0,x2:0,y2:c,stroke:o,strokeWidth:n,strokeOpacity:a}),or("line",{x1:r,y1:0,x2:r,y2:c,stroke:o,strokeWidth:n,strokeOpacity:a})]},e)}function ar(t,e,i="#4e79a7"){if(rr(t)){const i=function(t,e){let i=2166136261;const o=function(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}(e);for(let t=0;o.length>t;t++)i^=o.charCodeAt(t),i=Math.imul(i,16777619);return`${t}-hatch-${(i>>>0).toString(36)}`}(e,t);return{fill:`url(#${i})`,def:sr(t,i)}}return t&&"string"==typeof t?{fill:t}:{fill:i}}var cr=[40,40],lr=[.5,.5];function ur(t,e,i,o){if("none"!==t)return"color"===t||null==t?e??o:"accent"===t?i:t}var hr=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function dr(t){const{innerRadius:e,outerRadius:i,startAngle:o,endAngle:n}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=hr(i,o),e=hr(i,n);return`M0,0 L${t.x},${t.y} A${i},${i} 0 ${n-o>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=hr(i,o),s=hr(i,n),a=hr(e,n),c=hr(e,o),l=n-o>Math.PI?1:0;return`M${t.x},${t.y} A${i},${i} 0 ${l} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${l} 0 ${c.x},${c.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(i-e)/2));if(0===s)return dr({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,i-s))),c=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),l=n-o,u=t.roundStart&&t.roundEnd?l/2:l,h=!!t.roundStart&&u>a,d=!!t.roundEnd&&u>a;if(!h&&!d)return dr({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=o+(h?a:0),p=n-(d?a:0),y=o+(h?c:0),g=n-(d?c:0),m=hr(i,f),x=hr(i,p),b=(i-s)*Math.cos(a),v=hr(b,o),w=hr(b,n),k=r?null:hr(e,g),S=r?null:hr(e,y),A=r?0:(e+s)*Math.cos(c),M=r?null:hr(A,o),_=r?null:hr(A,n),P=p-f>Math.PI?1:0,R=r?0:g-y>Math.PI?1:0;let T="";if(h)T+=`M${v.x},${v.y}`,T+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=hr(i,o);T+=`M${t.x},${t.y}`}if(d)T+=` A${i},${i} 0 ${P} 1 ${x.x},${x.y}`,T+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=hr(i,n);T+=` A${i},${i} 0 ${P} 1 ${t.x},${t.y}`}if(r)T+=" L0,0";else{if(d)T+=` L${_.x},${_.y}`,T+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=hr(e,n);T+=` L${t.x},${t.y}`}if(h)T+=` A${e},${e} 0 ${R} 0 ${S.x},${S.y}`,T+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=hr(e,o);T+=` A${e},${e} 0 ${R} 0 ${t.x},${t.y}`}}return T+=" Z",T}import{jsx as fr,jsxs as pr}from"react/jsx-runtime";var yr={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function gr(t,e="#4e79a7"){return rr(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function mr(t,e,i){const o=hn(t.symbolType,t.size,t.path);return fr("path",{d:o,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?gr(t.style.fill):"none",opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${i??""}symbol-${e}`)}function xr(t,e,i,o){const n=t.glyph;if(!n?.parts?.length||0>=t.size)return null;const r=function(t,e){const[i,o]=t.viewBox??cr,[n,r]=t.anchor??lr,s=o>0?o:1,a=Math.max(0,e)/s,c=(i>0?i:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-n*c,offsetY:-r*l}}(n,t.size);if(0>=r.scale)return null;const s=`translate(${e},${i})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),c=function(t,e,i=0,o="horizontal"){const[n,r]=t.viewBox??cr,s=Math.min(1,Math.max(0,i)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===o?{x:0,y:r*(1-a),width:n,height:r*(a-s)}:{x:n*s,y:0,width:n*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(n,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),l=c?br(o+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),h=e=>n.parts.map((i,o)=>{const n=e?"none"===i.fill?void 0:e:ur(i.fill,a,t.accent),r=e?i.stroke&&"none"!==i.stroke?e:void 0:ur(i.stroke??"none",a,t.accent);return n||r?fr("path",{d:i.d,fill:n??"none",stroke:r,strokeWidth:r?i.strokeWidth??1:void 0,strokeLinecap:i.strokeLinecap,strokeLinejoin:i.strokeLinejoin,opacity:i.opacity},o):null});return pr("g",{transform:s,opacity:1===u?void 0:u,children:[c&&l&&fr("clipPath",{id:l,children:fr("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&t.ghostColor?fr("g",{children:h(t.ghostColor)}):null,c&&l?fr("g",{clipPath:`url(#${l})`,children:h()}):h()]},o)}function br(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function vr(t,e,i){switch(t.type){case"line":{const i=t;if(0===i.path.length)return null;const o="M"+i.path.map(([t,e])=>`${t},${e}`).join("L");return fr("path",{d:o,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth||2,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity},"line-"+e)}case"area":{const o=t;if(0===o.topPath.length)return null;const n=`M${o.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...o.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`,r=`${i?i+"-":""}area-${e}-hatch`,s=rr(o.style.fill)?sr(o.style.fill,r):void 0,a=s?`url(#${r})`:gr(o.style.fill);if(o.clipRect){const t=`${i?i+"-":""}area-clip-${e}`;return pr("g",{children:[pr("defs",{children:[s,fr("clipPath",{id:t,children:fr("rect",{x:o.clipRect.x,y:o.clipRect.y,width:o.clipRect.width,height:o.clipRect.height})})]}),fr("path",{d:n,fill:a,fillOpacity:o.style.fillOpacity??o.style.opacity??.7,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,clipPath:`url(#${t})`})]},"area-"+e)}return pr(er.Fragment,{children:[s&&fr("defs",{children:s}),fr("path",{d:n,fill:a,fillOpacity:o.style.fillOpacity??o.style.opacity??.7,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"area-"+e)}case"point":{const o=t,n=`${i?i+"-":""}point-${e}-hatch`,r=rr(o.style.fill)?sr(o.style.fill,n):void 0;return pr(er.Fragment,{children:[r&&fr("defs",{children:r}),fr("circle",{cx:o.x,cy:o.y,r:o.r,fill:r?`url(#${n})`:gr(o.style.fill),opacity:o.style.opacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"point-"+e)}case"symbol":return mr(t,e);case"glyph":return xr(t,t.x,t.y,`${i??""}glyph-${t.pointId??e}`);case"rect":{const o=t,n=`${i?i+"-":""}xyrect-${e}-hatch`,r=rr(o.style.fill)?sr(o.style.fill,n):void 0;return pr(er.Fragment,{children:[r&&fr("defs",{children:r}),fr("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:r?`url(#${n})`:gr(o.style.fill),opacity:o.style.opacity,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const i=t;if(i.showValues&&null!=i.value&&i.w>=20&&i.h>=20){const t=i.valueFormat?i.valueFormat(i.value):Number.isInteger(i.value)?i.value+"":100>Math.abs(i.value)?1>Math.abs(i.value)?i.value.toPrecision(3):i.value.toFixed(1):i.value.toFixed(0),[o,n,r]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(i.fill),s=.299*o+.587*n+.114*r>128?"#000":"#fff",a=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h)));return pr("g",{children:[fr("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill}),fr("text",{x:i.x+i.w/2,y:i.y+i.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:a+"px",children:t})]},"heatcell-"+e)}return fr("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill},"heatcell-"+e)}case"candlestick":{const i=t,o=Math.min(i.openY,i.closeY),n=Math.max(Math.abs(i.openY-i.closeY),1),r=i.isUp?i.upColor:i.downColor;return pr("g",{children:[fr("line",{x1:i.x,y1:i.highY,x2:i.x,y2:i.lowY,stroke:i.wickColor,strokeWidth:i.wickWidth}),fr("rect",{x:i.x-i.bodyWidth/2,y:o,width:i.bodyWidth,height:n,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}function wr(t,e,i){const o=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",n=i=>`ord-${t.type}-${o}-${e}-${i}`,r=`ord-${t.type}-${o}-${e}`;switch(t.type){case"rect":{const e=t,i=br(r)+"-grad",o=function(t,e){const i=t.fillGradient;if(!i||"object"!=typeof i)return null;let o=t.x,n=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(n=t.y+t.h,s=t.y):"right"===t.roundedEdge?(o=t.x+t.w,n=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(o=t.x,n=t.y,r=t.x+t.w,s=t.y);const a=[];if("colorStops"in i){const t=i.colorStops.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color}));if(2>t.length)return null;for(let e=0;t.length>e;e++)a.push(fr("stop",{offset:t[e].offset,stopColor:t[e].color},e))}else{const e=gr(t.style.fill);a.push(fr("stop",{offset:0,stopColor:e,stopOpacity:i.topOpacity},"0")),a.push(fr("stop",{offset:1,stopColor:e,stopOpacity:i.bottomOpacity},"1"))}return fr("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:o,y1:n,x2:r,y2:s,children:a})}(e,i);let n,a;if(o)a=`url(#${i})`;else if(rr(e.style.fill)){const t=br(r)+"-hatch";n=sr(e.style.fill,t),a=`url(#${t})`}else a=gr(e.style.fill);const c=o||n?pr("defs",{children:[o,n]}):null;if(e.cornerRadii&&(((s=e.cornerRadii).tl??0)>0||(s.tr??0)>0||(s.br??0)>0||(s.bl??0)>0)){const t=function(t){const{x:e,y:i,w:o,h:n}=t,{tl:r,tr:s,br:a,bl:c}=function(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const i=Math.min(t.w,t.h)/2,o=t=>Math.max(0,Math.min(t??0,i));return{tl:o(e.tl),tr:o(e.tr),br:o(e.br),bl:o(e.bl)}}(t);let l=`M${e+r},${i}`;return l+=` L${e+o-s},${i}`,s>0&&(l+=` A${s},${s} 0 0 1 ${e+o},${i+s}`),l+=` L${e+o},${i+n-a}`,a>0&&(l+=` A${a},${a} 0 0 1 ${e+o-a},${i+n}`),l+=` L${e+c},${i+n}`,c>0&&(l+=` A${c},${c} 0 0 1 ${e},${i+n-c}`),l+=` L${e},${i+r}`,r>0&&(l+=` A${r},${r} 0 0 1 ${e+r},${i}`),l+=" Z",l}(e);return pr(er.Fragment,{children:[c,fr("path",{d:t,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:i,y:o,w:n,h:s}=e;let l;switch(e.roundedEdge){case"right":l=`M${i},${o} L${i+n-t},${o} A${t},${t} 0 0 1 ${i+n},${o+t} L${i+n},${o+s-t} A${t},${t} 0 0 1 ${i+n-t},${o+s} L${i},${o+s} Z`;break;case"left":l=`M${i+n},${o} L${i+t},${o} A${t},${t} 0 0 0 ${i},${o+t} L${i},${o+s-t} A${t},${t} 0 0 0 ${i+t},${o+s} L${i+n},${o+s} Z`;break;case"bottom":l=`M${i},${o} L${i+n},${o} L${i+n},${o+s-t} A${t},${t} 0 0 1 ${i+n-t},${o+s} L${i+t},${o+s} A${t},${t} 0 0 1 ${i},${o+s-t} Z`;break;default:l=`M${i},${o+s} L${i},${o+t} A${t},${t} 0 0 1 ${i+t},${o} L${i+n-t},${o} A${t},${t} 0 0 1 ${i+n},${o+t} L${i+n},${o+s} Z`}return pr(er.Fragment,{children:[c,fr("path",{d:l,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return pr(er.Fragment,{children:[c,fr("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}case"point":{const e=t;return fr("circle",{cx:e.x,cy:e.y,r:e.r,fill:gr(e.style.fill),opacity:e.style.opacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return mr(t,e,i);case"glyph":return xr(t,t.x,t.y,`${i??""}ord-glyph-${t.pointId??e}`);case"wedge":{const o=t;if(o._gradientBand&&o._gradientBand.colors.length>0){const t=br(`${i?i+"-":""}gauge-grad-${o.category||r}-${e}`),{clipPath:n,slices:s}=function(t){const e=dr({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),i=[],o=t.colors;if(o.length>0){const e=(t.endAngle-t.startAngle)/o.length;for(let n=0;o.length>n;n++)i.push({d:dr({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+n*e,endAngle:t.endAngle}),color:o[n]})}return{clipPath:e,slices:i}}({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds?.start??!0,roundEnd:o.roundedEnds?.end??!0,colors:o._gradientBand.colors});return pr("g",{transform:`translate(${o.cx},${o.cy})`,opacity:o.style.opacity,fillOpacity:o.style.fillOpacity,children:[fr("defs",{children:fr("clipPath",{id:t,children:fr("path",{d:n})})}),fr("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>fr("path",{d:t.d,fill:gr(t.color)},e))}),o.style.stroke&&"none"!==o.style.stroke&&fr("path",{d:n,fill:"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},r)}let n;if(o.roundedEnds)n=dr({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds.start,roundEnd:o.roundedEnds.end});else{const t=ir().innerRadius(o.innerRadius).outerRadius(o.outerRadius).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2);o.cornerRadius&&t.cornerRadius(o.cornerRadius),n=t(yr)||""}return fr("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:gr(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},r)}case"boxplot":{const e=t,i=e.columnWidth/2;return pr("g","vertical"===e.projection?{children:[fr("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("rect",{x:e.x-i,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:gr(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("line",{x1:e.x-i,y1:e.medianPos,x2:e.x+i,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2}),fr("line",{x1:e.x-.5*i,y1:e.minPos,x2:e.x+.5*i,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("line",{x1:e.x-.5*i,y1:e.maxPos,x2:e.x+.5*i,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1})]}:{children:[fr("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-i,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:gr(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("line",{x1:e.medianPos,y1:e.y-i,x2:e.medianPos,y2:e.y+i,stroke:e.style.stroke||"#333",strokeWidth:2}),fr("line",{x1:e.minPos,y1:e.y-.5*i,x2:e.minPos,y2:e.y+.5*i,stroke:e.style.stroke||"#333",strokeWidth:1}),fr("line",{x1:e.maxPos,y1:e.y-.5*i,x2:e.maxPos,y2:e.y+.5*i,stroke:e.style.stroke||"#333",strokeWidth:1})]},r)}case"violin":{const e=t,i=[fr("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:gr(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth||1},n("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,o=t.x+t.width/2,r=t.y+t.height/2;t.height>t.width?i.push(fr("line",{x1:o,y1:e.iqrLine.q1Pos,x2:o,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),fr("circle",{cx:o,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med"))):i.push(fr("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),fr("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med")))}return fr("g",{children:i},r)}case"connector":return fr("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth||1,opacity:t.style.opacity??.5},r);case"trapezoid":{const e=t,i=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return fr("polygon",{points:i,fill:gr(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}var s}var kr=new Set;function Sr(t){const{node:e,index:i,renderMode:o,fallback:n}=t,r=function(t,e){const i="function"==typeof t?t(e.datum??null,e):t;return(o=i)&&"object"==typeof o&&"string"==typeof o.id&&"function"==typeof o.cacheKey&&"function"==typeof o.drawCanvas&&"function"==typeof o.renderStaticSVG?i:void 0;var o}(o,e);if(!r)return n();const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${i}`});return null!=s?s:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const i=`${t}:${e}`;kr.has(i)||(kr.add(i),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),n())}import{scaleOrdinal as Ar}from"d3-scale";import{jsx as Mr,jsxs as _r}from"react/jsx-runtime";function Pr(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Rr(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function Tr(t,e,i,o){const n=Rr(o);return e+i+Math.ceil(t.length*n*.58)}function Lr(t){const{categories:e,theme:i,position:o="right",totalWidth:n,totalHeight:r,margin:s,legendLayout:a}=t,c=Math.max(1,a?.swatchSize??14),l=Math.max(0,a?.labelGap??6),u=Math.max(0,a?.itemGap??8),h=Math.max(c,a?.rowHeight??20),d=c+l,f=Math.min(2,c/2),p="top"===o||"bottom"===o,y=Math.max(c,n-s.left-s.right),g=Math.max(h,r-s.top-s.bottom),m=e.map(t=>Tr(t,c,l,i));if(p){const t=Math.max(c,a?.maxWidth??y),i=[];let o=0,n=0;m.forEach((e,r)=>{const s=0===n?e:n+u+e;n>0&&s>t?(i.push({start:o,end:r,width:n}),o=r,n=e):n=s}),e.length>0&&i.push({start:o,end:e.length,width:n});const r=Pr(a?.align),s=[];return i.forEach((i,o)=>{let n="center"===r?Math.max(0,(t-i.width)/2):"end"===r?Math.max(0,t-i.width):0;for(let t=i.start;i.end>t;t++)s.push({category:e[t],width:m[t],x:n,y:o*h}),n+=m[t]+u}),{items:s,width:Math.max(0,...i.map(t=>t.width)),height:i.length*h,swatchSize:c,labelOffset:d,swatchRadius:f}}const x=Math.max(0,...m),b=Math.max(1,Math.floor(g/h)),v=Math.max(1,Math.ceil(e.length/b));return{items:e.map((t,e)=>({category:t,width:m[e],x:Math.floor(e/b)*(x+u),y:e%b*h})),width:v*x+Math.max(0,v-1)*u,height:Math.min(e.length,b)*h,swatchSize:c,labelOffset:d,swatchRadius:f}}function Cr(t){const{legendGroups:e,theme:i,position:o="right",totalWidth:n,totalHeight:r,margin:s,legendLayout:a}=t,c=Math.max(1,a?.swatchSize??14),l=Math.max(0,a?.labelGap??6),u=Math.max(0,a?.itemGap??8),h=Math.max(c,a?.rowHeight??20),d=c+l,f=Math.min(2,c/2),p=Math.max(12,Rr(i)),y="top"===o||"bottom"===o,g=Math.max(c,n-s.left-s.right),m=Math.max(h,r-s.top-s.bottom);if(y){const o=Math.max(c,a?.maxWidth??g),n=Pr(a?.align);let r=0,s=0;const l=[];for(const n of e){const e=n.items.map(t=>t.label),u=Lr({...t,categories:e,legendLayout:{...a,maxWidth:Math.max(c,o-p-8),align:"start"}}),h=n.label?p:0,d=n.label?Tr(n.label,0,0,i):0,f=h>0?h+8:0,y=f+u.width,g=Math.max(u.height,d);l.push({group:n,x:r,y:0,itemOffsetX:f,itemOffsetY:0,width:y,height:g,items:u.items}),r+=y+12,s=Math.max(s,g)}const u=l.length>0?r-12:0,h=u>o?0:"center"===n?Math.max(0,(o-u)/2):"end"===n?Math.max(0,o-u):0;return{groups:l.map(t=>({...t,x:t.x+h})),width:u,height:s,swatchSize:c,labelOffset:d,swatchRadius:f}}let x=0,b=0;const v=[];for(const t of e){const e=t.items.map(t=>t.label).map(t=>Tr(t,c,l,i)),o=Math.max(0,...e),n=Math.max(1,Math.min(t.items.length||1,Math.max(1,Math.floor(Math.max(h,m-x)/h)))),r=Math.max(1,Math.ceil(t.items.length/n)),s=t.items.map((t,i)=>({category:t.label,width:e[i],x:Math.floor(i/n)*(o+u),y:i%n*h})),a=r*o+Math.max(0,r-1)*u,d=Math.min(t.items.length,n)*h,f=t.label?Tr(t.label,0,0,i):0,y=t.label?p+8:0,g=y+d+12,w=Math.max(a,f);v.push({group:t,x:0,y:x,itemOffsetX:0,itemOffsetY:y,width:w,height:g,items:s}),b=Math.max(b,w),x+=g}return{groups:v,width:b,height:Math.max(0,x),swatchSize:c,labelOffset:d,swatchRadius:f}}function $r(t){const e="top"===t.position||"bottom"===t.position,i=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??i,200),height:t.gradient.label?34:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?124:108,swatchSize:14}}function zr(t){const{categories:e,colorScheme:i,theme:o,position:n="right",totalWidth:r,totalHeight:s,margin:a,hasTitle:c=!1}=t;if(!e||0===e.length)return null;const l=function(t,e,i){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>tt(t,e)??"#999"}const o=Array.isArray(e)?e:i.colors.categorical.length>0?i.colors.categorical:D;return Ar().domain(t).range(o)}(e,i,o),u="top"===n||"bottom"===n,h=Lr(t);let d,f;if("left"===n?(d=Math.max(4,a.left-h.width-10),f=a.top):"top"===n?(d=a.left,f=c?32:8):"bottom"===n?(d=a.left,f=Math.min(s-a.bottom+38,s-h.height-2)):(d=Math.min(r-h.width-4,r-a.right+10),f=a.top),u){const t=h.items.map((t,e)=>_r("g",{transform:`translate(${t.x},${t.y})`,children:[Mr("rect",{width:h.swatchSize,height:h.swatchSize,fill:l(t.category),rx:h.swatchRadius}),Mr("text",{x:h.labelOffset,y:h.swatchSize/2,dominantBaseline:"central",fontSize:Rr(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:t.category})]},"legend-"+e));return Mr("g",{className:"semiotic-legend",transform:`translate(${d},${f})`,children:t})}const p=h.items.map((t,e)=>_r("g",{transform:`translate(${t.x},${t.y})`,children:[Mr("rect",{width:h.swatchSize,height:h.swatchSize,fill:l(t.category),rx:h.swatchRadius}),Mr("text",{x:h.labelOffset,y:h.swatchSize/2,dominantBaseline:"central",fontSize:Rr(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:t.category})]},"legend-"+e));return Mr("g",{className:"semiotic-legend",transform:`translate(${d},${f})`,children:p})}function Dr(t,e){if(!e||!t||0===t.length)return[];const i="function"==typeof e?e:t=>t[e],o=new Set;for(const e of t){const t=i(e);null!=t&&o.add(t+"")}return Array.from(o)}import{jsx as Er,jsxs as Ir}from"react/jsx-runtime";function Fr(t,e=120,i=8){if(!t)return[];const o=Math.max(1,Math.floor(e/i)),n=t.split(/\s+/),r=[];let s="";for(const t of n)s&&s.length+1+t.length>o?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function Nr(t,e,i,o){return"curly"===t?o?`M0,0 C${.6*i},0 ${.4*i},${e/2} ${i},${e/2} C${.4*i},${e/2} ${.6*i},${e} 0,${e}`:`M0,0 C0,${.6*i} ${e/2},${.4*i} ${e/2},${i} C${e/2},${.4*i} ${e},${.6*i} ${e},0`:o?`M0,0 L${i},0 L${i},${e} L0,${e}`:`M0,0 L0,${i} L${e},${i} L${e},0`}function Br(t,e,i,o){if(!t)return Er("g",{className:"annotation-note"});const{label:n,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=t;if(!n&&!r)return Er("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(i)?"leftRight":"topBottom");let h=a;h&&"dynamic"!==h||(h="topBottom"===u?0>e?"right":"left":0>i?"bottom":"top");let d="start";"topBottom"===u?"right"===h?d="end":"middle"===h&&(d="middle"):d=0>e?"end":"start";const f=16,p=r?l?[r]:Fr(r,c):[],y=n?l?[n]:Fr(n,c):[],g="leftRight"===u?"end"===d?-4:4:0;let m=0;const x=[],b=o||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push(Er("foreignObject",{className:"annotation-note-html",x:"end"===d?g-c:"middle"===d?g-c/2:g,y:-16,width:c,height:Math.max(f,(p.length+y.length)*f+(r&&n?2:0))+f,style:{overflow:"visible"},children:Ir("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===d?"right":"middle"===d?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&Er("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),n&&Er("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html")):(p.length>0&&(x.push(Er("text",{className:"annotation-note-title",fill:b,textAnchor:d,fontWeight:"bold",children:p.map((t,e)=>Er("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&x.push(Er("text",{className:"annotation-note-label",fill:b,textAnchor:d,y:m,children:y.map((t,e)=>Er("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||n)&&(0!==e||0!==i))if("topBottom"===u){const t=Math.min(c,120);let e=0,i=t;"end"===d?(e=-t,i=0):"middle"===d&&(e=-t/2,i=t/2),v=Er("line",{className:"note-line",x1:e,x2:i,y1:0,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+y.length)*f+(y.length>0?f:0);let e=0,i=t;"bottom"===h?(e=-t,i=0):"middle"===h&&(e=-t/2,i=t/2),v=Er("line",{className:"note-line",x1:0,x2:0,y1:e,y2:i,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+y.length-1)*f;let k=0;return"topBottom"===u?k=0>i?-(w+2):18:"leftRight"===u&&(k="middle"===h?-(w+f+(y.length>0&&p.length>0?2:0))/2+8:"bottom"===h||0>i?-(w+2):18),Ir("g",{className:"annotation-note",transform:`translate(${e},${i})`,children:[Er("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function Or(t,e,i,o,n){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(Er("circle",{r:t,fill:"none",stroke:i||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,o=e?.height||0;(t>0||o>0)&&r.push(Er("rect",{width:t,height:o,fill:"none",stroke:i||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":e?.custom&&r.push(...Array.isArray(e.custom)?e.custom:[e.custom]);break;case"xy-threshold":{const t=o||0,s=n||0;if(void 0!==e?.x){const o=(e.x||0)-t;r.push(Er("line",{x1:o,y1:(e.y1||0)-s,x2:o,y2:(e.y2||0)-s,stroke:i||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const o=(e.y||0)-s;r.push(Er("line",{x1:(e.x1||0)-t,y1:o,x2:(e.x2||0)-t,y2:o,stroke:i||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(Er("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(Er("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:i||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",o=e?.width??e?.height;void 0!==o&&r.push(Er("path",{d:Nr(t,o,e?.depth||30,void 0===e?.width),fill:"none",stroke:i||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return Er("g",{className:"annotation-subject",children:r})}function Wr(t,e,i,o,n,r){const s=[];let a=0,c=0;if("callout-circle"!==n&&"label"!==n||!r?.radius){if("callout-rect"===n&&r){const i=r.width||0,o=r.height||0;if(i>0||o>0){const n=i/2,r=o/2,s=t-n,l=e-r;if(0!==s||0!==l){const t=Math.abs(s),e=Math.abs(l),u=i/2,h=o/2,d=t*h>e*u?u/t:h/e;a=n+s*d,c=r+l*d}}}else if("bracket"===n&&r){const t=r.width,e=r.height,i=r.depth||30;void 0!==t?(a=t/2,c=i):void 0!==e&&(a=i,c=e/2)}}else{const i=(r.radius||0)+(r.radiusPadding||0);if(i>0&&(0!==t||0!==e)){const o=Math.atan2(e,t);a=Math.cos(o)*i,c=Math.sin(o)*i}}const l=Math.sqrt((t-a)**2+(e-c)**2);if(l>.5){const n=o||"var(--semiotic-text-secondary, currentColor)",r="curve"===i?.type;let u=Math.atan2(e-c,t-a);if(r){const o=(a+t)/2,r=(c+e)/2,h=-(e-c)/l,d=(t-a)/l,f=(i?.curve??.25)*l,p=o+h*f,y=r+d*f;s.push(Er("path",{className:"connector-curve",d:`M${a},${c}Q${p},${y} ${t},${e}`,fill:"none",stroke:n},"connector-line")),u=Math.atan2(y-c,p-a)}else s.push(Er("line",{x1:a,y1:c,x2:t,y2:e,stroke:n},"connector-line"));if("arrow"===i?.end){const t=10,e=16/180*Math.PI;s.push(Er("path",{d:`M${a},${c}L${a+t*Math.cos(u+e)},${c+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${c+t*Math.sin(u-e)}Z`,fill:n,stroke:"none"},"connector-arrow"))}}return Er("g",{className:"annotation-connector",children:s})}function jr(t){const{x:e=0,y:i=0,dx:o,dy:n,nx:r,ny:s,note:a,connector:c,subject:l,type:u,color:h,className:d,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=t,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(i)?i[0]??0:i,v=new Set(Array.isArray(f)?f:[]);let w=o||0,k=n||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const S="string"==typeof u?u:"label";if("bracket"===S&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const t=l.depth||30;k=t+(0>t?-5:5)}else if(void 0!==l.height){const t=l.depth||30;w=t+(0>t?-5:5),k=l.height/2}return Ir("g",{className:("annotation "+(d||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&Wr(w,k,c,h,S,l),!v.has("subject")&&Or(S,l,h,x,b),!v.has("note")&&Br(a,w,k,h)]})}function Yr(t){const{noteData:e}=t,{screenCoordinates:i}=e,o="string"==typeof e.type?e.type:"label",n=e.eventListeners||e.events||{};if(e.coordinates&&i){const t=e.nx||i[0][0]+(e.dx??0),n=e.ny||i[0][1]+(e.dy??0),r=i.map((i,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:i[0],y:i[1],nx:t,ny:n});return Er(jr,{"data-testid":"semiotic-annotation",...s,type:o},"multi-annotation-"+r)});return Er("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return Er(jr,{"data-testid":"semiotic-annotation",events:n,...e,type:o},s)}import{jsx as Xr}from"react/jsx-runtime";var qr={secondary:0,primary:3};function Gr(t){return!0===t?._annotationDeferred}function Vr(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Hr(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Zr(t){return Math.max(.72,.95-.06*t)}function Kr(t,e){const i=e.scales?.x??e.scales?.time;return i?null!=t.x?i(t.x):e.xAccessor&&null!=t[e.xAccessor]?i(t[e.xAccessor]):null:null}function Ur(t,e){const i=e.scales?.y??e.scales?.value;return i?null!=t.y?i(t.y):e.yAccessor&&null!=t[e.yAccessor]?i(t[e.yAccessor]):null:null}function Qr(t){return null==t?null:t+""}function Jr(t,e,i){return e.stickyPositionCache?.set(t,i),i}var ts=32,es=6,is=4,os=8,ns=72;var rs={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function ss(t){if(!as(t))return t;const e=("string"==typeof t.mobileText?t.mobileText:void 0)??("string"==typeof t.shortText?t.shortText:void 0);return!e||"string"!=typeof t.label&&null!=t.label?t:{...t,label:e}}function as(t){return o(t)}function cs(t,e){if(!t)return[];const i=Math.max(1,Math.floor(e/7)),o=t.split(/\s+/).filter(Boolean),n=[];let r="";for(const t of o)r&&r.length+t.length+1>i?(n.push(r),r=t):r=r?`${r} ${t}`:t;return r&&n.push(r),n}function ls(t,e,i,o,n){const r=t+i,s=e+o;return Math.abs(i)>Math.abs(o)?{x:0>i?r-n.width-4:r+4,y:0>o?s-n.height:s,width:n.width,height:n.height}:{x:0>i?r-n.width:r,y:0>o?s-n.height-4:s+4,width:n.width,height:n.height}}function us(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function hs(t,e){return Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x))*Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y))}function ds(t,e,i,o,n,r,s,a){const c=us(t,s);let l=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,i,o){const n=Math.max(0,o-t.x),r=Math.max(0,o-t.y);return(n+Math.max(0,t.x+t.width-(e-o)))*t.height+(r+Math.max(0,t.y+t.height-(i-o)))*t.width}(c,n,r,a);for(const t of i)l+=12*hs(c,t);for(const t of o)l+=4*hs(c,t);return l}function fs(t,e,i){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const o=t.pointId??t.nodeId;if(null!=o&&i.pointNodes){const t=i.pointNodes.find(t=>t.pointId===o);if(t)return{x:t.x,y:t.y}}const n=t.coordinates,r=i.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&r){const t=n[0],e=n[1];if("number"==typeof t&&"number"==typeof e){const i=r([t,e]);if(i&&"number"==typeof i[0]&&"number"==typeof i[1])return{x:i[0],y:i[1]}}}return i.scales||"number"!=typeof t.x||"number"!=typeof t.y?function(t,e,i){const o=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===o){if(null!=t.pointId&&i.pointNodes&&i.pointNodes.length>0)for(let o=i.pointNodes.length-1;o>=0;o--){const n=i.pointNodes[o];if(n.pointId===t.pointId)return Jr(e,i,{x:n.x,y:n.y})}const o=function(t){const e=t.data;if(!e||0===e.length)return null;const i=e[e.length-1],o=t.scales?.x??t.scales?.time,n=t.scales?.y??t.scales?.value;if(!o||!n)return null;const r=i[t.xAccessor||"x"],s=i[t.yAccessor||"y"];return null==r||null==s?null:{x:o(r),y:n(s)}}(i);return o?Jr(e,i,o):null}if("semantic"===o){const o=function(t,e,i){const o=function(t){return Qr(t.provenance?.stableId??t.stableId)}(t);if(!o)return null;const n=i.pointNodes?.find(t=>Qr(t.pointId)===o);if(n)return Jr(e,i,{x:n.x,y:n.y});const r=i.data?.find(t=>function(t){return Qr(t.stableId??t.id??t.provenance?.stableId)}(t)===o);if(!r)return null;const s=Kr(r,i),a=Ur(r,i);return null==s||null==a?null:Jr(e,i,{x:s,y:a})}(t,e,i);if(o)return o}let n=null,r=null;if(null!=t.pointId&&i.pointNodes){const e=i.pointNodes.find(e=>e.pointId===t.pointId);e&&(n=e.x,r=e.y)}if(null!=n&&null!=r||(n=Kr(t,i),r=Ur(t,i)),null!=n&&null!=r)return Jr(e,i,{x:n,y:r});if("sticky"===o){const t=i.stickyPositionCache?.get(e);if(t)return t}return null}(t,e,i):{x:t.x,y:t.y}}function ps(t){const{annotations:o,context:n,defaultOffset:r=ts,notePadding:s=es,markPadding:a=is,edgePadding:c=os,preserveManualOffsets:l=!0,routeLongConnectors:u=!0,connectorThreshold:h=ns,density:d,progressiveDisclosure:f=!1,redundantCues:p=!1,responsive:y,mobile:g,cohesion:m,audience:x}=t,b=n.width||0,v=n.height||0,w="object"==typeof g?g:{},k=w.breakpoint??480,S=!!g&&k>=b,A=S&&!1!==w.preferShortText?o.map(ss):o,M=S&&!d?{maxAnnotations:w.maxAnnotations??("callout-list"===w.strategy?1:2),minVisible:w.minVisible??1}:d,_=f||S&&(!1!==w.progressiveDisclosure||"callout-list"===w.strategy),P=S&&!y?w.responsive??{minWidth:k}:y,R=S&&!m?w.cohesion:m;if(0===A.length||0>=b||0>=v)return A.slice();const T=[],L=function(t,e){return(t.pointNodes||[]).map(t=>{const i=Math.max(1,t.r||1)+e;return{x:t.x-i,y:t.y-i,width:2*i,height:2*i}})}(n,a);let C=!1;const $=A.map((t,e)=>{if(!as(t))return t;const i=fs(t,e,n);if(!i)return t;const o=function(t){if("widget"===t.type)return{width:"number"==typeof t.width?t.width:32,height:"number"==typeof t.height?t.height:32};const e="number"==typeof t.wrap?t.wrap:120,i=[...cs("string"==typeof t.title?t.title:void 0,e),...cs("string"==typeof t.label?t.label:void 0,e)],o=i.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*o)+10),height:Math.max(18,16*i.length+6)}}(t);if(l&&("number"==typeof(a=t).dx||"number"==typeof a.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:30,dy:-30}}(t);return T.push(us(ls(i.x,i.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,o),s)),t}var a;let d=null,f=1/0;for(const t of function(t){const e=1.6*t;return[{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t},{dx:t,dy:0},{dx:-t,dy:0},{dx:0,dy:-t},{dx:0,dy:t},{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e}]}(r)){const e=ds(ls(i.x,i.y,t.dx,t.dy,o),t,T,L,b,v,s,c);f>e&&(d=t,f=e)}if(!d)return t;const p=us(ls(i.x,i.y,d.dx,d.dy,o),s);T.push(p);const y=Math.hypot(d.dx,d.dy),g=u&&y>=h&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return C=!0,{...t,dx:d.dx,dy:d.dy,...g?{connector:g}:{}}}),z=C?$:A.slice();let D=z;if(p){let t=!1;const e=z.map(e=>{const i=function(t){return"text"!==t.type||"string"!=typeof t.color||8>Math.hypot("number"==typeof t.dx?t.dx:0,"number"==typeof t.dy?t.dy:0)?t:{...t,_redundantConnector:!0}}(e);return i!==e&&(t=!0),i});D=t?e:z}{let t=!1;const e=D.map(e=>{if(!0!==e?.defensive)return e;const i=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const i="string"==typeof e.source?rs[e.source]??e.source:null,o="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!i&&!o)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const n=[i,o].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${n})`)?t:{...t,label:r?`${r} (${n})`:`(${n})`}}(e);return i!==e&&(t=!0),i});D=t?e:D}const E=new Set;if(M){const t="object"==typeof M?M:{},o=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return 3;const i=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===i.length?3:i.reduce((t,e)=>t+e,0)/i.length}(t);return e>2?4>e?1:.6:1.5}(x),n=1===o?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??e(b,v,t))*o))},{deferred:r}=i({annotations:D,width:b,height:v,...n});for(const t of r)E.add(t)}if(P&&("object"==typeof P&&"number"==typeof P.minWidth?P.minWidth:480)>=b)for(const t of D)as(t)&&"secondary"===t.emphasis&&E.add(t);if(E.size>0)for(const t of D)!0===t?.defensive&&E.delete(t);let I;return I=0===E.size?D:_?D.map(t=>E.has(t)?{...t,_annotationDeferred:!0}:t):D.filter(t=>!E.has(t)),R?function(t,e){let i=!1;const o=t.map(t=>as(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(i=!0,{...t,cohesion:e}):t);return i?o:t}(I,R):I}import{jsx as ys,jsxs as gs}from"react/jsx-runtime";var ms="var(--semiotic-bg, #ffffff)";function xs(t){const{x:e,y:i,text:o,fill:n,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,background:u,className:h}=t,d=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),f=t=>ys("text",{x:e,y:i,textAnchor:c,dominantBaseline:l,fill:n,fontSize:r,fontWeight:s,fontFamily:a,className:h,...t?{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}:{},children:o});if(!d)return f();if("halo"===d.type)return f({stroke:d.fill??ms,strokeWidth:d.haloWidth??3});const p=d.padding??{x:6,y:3},y="number"==typeof p?p:p.x,g="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(o,r),x=r+2*g;let b,v;return b="middle"===c?e-m/2-y:"end"===c?e-m-y:e-y,v="middle"===l||"central"===l?i-x/2:"hanging"===l||"text-before-edge"===l?i-g:i-.8*r-g,gs("g",{className:h,children:[ys("rect",{x:b,y:v,width:m+2*y,height:x,rx:d.radius??3,ry:d.radius??3,fill:d.fill??ms,fillOpacity:d.opacity??.85,stroke:d.stroke,strokeWidth:d.strokeWidth}),f()]})}import{jsx as bs,jsxs as vs}from"react/jsx-runtime";var ws=16;function ks(t,e){return t.color||e.colors.annotation||e.colors.text}function Ss(t,e,i){const o=t.labelBackground,n=e.colors.background;return void 0===o?"none"===i?"none":{type:"halo",fill:n}:!1===o||"none"===o?"none":!0===o||"halo"===o?{type:"halo",fill:n}:"box"===o?{type:"box",fill:n}:{fill:n,...o}}function As(t,e,i){return null!=t.x&&e.x?e.x(t.x):i&&null!=t[i]&&e.x?e.x(t[i]):"number"==typeof t.x?t.x:null}function Ms(t,e,i){return null!=t.y&&e.y?e.y(t.y):i&&null!=t[i]&&e.y?e.y(t[i]):"number"==typeof t.y?t.y:null}function _s(t){const{annotations:e}=t;if(!e||0===e.length)return null;const i=t.autoPlaceAnnotations?ps({annotations:e,context:{scales:{x:t.scales.x,y:t.scales.y,time:t.scales.x,value:t.scales.y,o:t.scales.o,geoProjection:t.scales.geoProjection},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,frameType:t.projection?"ordinal":"xy",projection:"horizontal"===t.projection?"horizontal":"vertical"},..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):e,o=[];for(let e=0;i.length>e;e++){const n=Ps(i[e],e,t);n&&o.push({node:n,annotation:i[e]})}const n=function(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(i=t.annotation,"primary"===i?.emphasis||"secondary"===i?.emphasis?i.emphasis:null),confidence:Hr(t.annotation),readingOrder:null,rank:1};var i}),i=e.some(t=>null!=t.emphasis||null!=t.confidence),o=t.some(t=>Gr(t.annotation)),n=t.some(t=>null!=Vr(t.annotation)),r=t.some(t=>"layer"===Vr(t.annotation));if(!i&&!o&&!n)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=qr[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:i,emphasis:o,readingOrder:n}=t,r=Gr(e.annotation);let s=e.node;if("primary"===o||"secondary"===o||null!=n){const t=null==o&&null!=n;s=Xr("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+o,..."secondary"===o?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:Zr(n),"data-annotation-reading-order":n}:{},children:e.node},"annotation-emphasis-"+i)}const a=Vr(e.annotation);return a&&(s=Xr("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+i)),r&&(s=Xr("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+i)),s});return o&&a.unshift(Xr("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),r&&a.unshift(Xr("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}(o);return n.length>0?bs("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:n}):null}function Ps(t,e,i){const{scales:o,layout:n,theme:r,xAccessor:s,yAccessor:a}=i;switch(t.type){case"y-threshold":{const s=t.value;if(null==s)return null;const a=ks(t,r),c=t.label,l=t.labelPosition||"right",u=t.strokeDasharray||"6,4",h=t.strokeWidth??1.5;if("horizontal"===i.projection&&o.r){const i=o.r(s);return null==i?null:vs("g",{opacity:t.opacity,children:[bs("line",{x1:i,y1:0,x2:i,y2:n.height,stroke:a,strokeWidth:h,strokeDasharray:u}),c&&bs(xs,{x:i+4,y:ws,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ss(t,r,"halo")})]},"ann-ythresh-"+e)}const d=o.y?o.y(s):o.r?o.r(s):null;return null==d?null:vs("g",{children:[bs("line",{x1:0,y1:d,x2:n.width,y2:d,stroke:a,strokeWidth:h,strokeDasharray:u}),c&&bs(xs,{x:"left"===l?4:"center"===l?n.width/2:n.width-4,y:20>d?Math.min(n.height-4,d+ws):d-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ss(t,r,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const i=t.value;if(null==i||!o.x)return null;const s=o.x(i);if(null==s)return null;const a=ks(t,r),c=t.label,l=t.labelPosition||"top";return vs("g",{opacity:t.opacity,children:[bs("line",{x1:s,y1:0,x2:s,y2:n.height,stroke:a,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&bs(xs,{x:s>.6*n.width?s-4:s+4,y:"bottom"===l?n.height-4:"center"===l?n.height/2:ws,textAnchor:s>.6*n.width?"end":"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ss(t,r,"halo")})]},"ann-xthresh-"+e)}case"band":{const i=null!=t.y0&&o.y?o.y(t.y0):null,s=null!=t.y1&&o.y?o.y(t.y1):null;if(null==i||null==s)return null;const a=Math.min(i,s),c=Math.abs(s-i),l=ar(t.fill||ks(t,r),"ssr-band-"+e),u=t.fillOpacity??.1;return vs("g",{opacity:t.opacity,children:[l.def&&bs("defs",{children:l.def}),bs("rect",{x:0,y:a,width:n.width,height:c,fill:l.fill,fillOpacity:u}),t.label&&bs(xs,{x:n.width-4,y:Math.max(a,0)+ws,textAnchor:"end",fontSize:r.typography.tickSize,fill:t.color||ks(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Ss(t,r,"halo")})]},"ann-band-"+e)}case"x-band":{const i=null!=t.x0&&o.x?o.x(t.x0):null,s=null!=t.x1&&o.x?o.x(t.x1):null;if(null==i||null==s)return null;const a=Math.min(i,s),c=Math.abs(s-i),l=ar(t.fill||ks(t,r),"ssr-xband-"+e),u=t.fillOpacity??.1;return vs("g",{opacity:t.opacity,children:[l.def&&bs("defs",{children:l.def}),bs("rect",{x:a,y:0,width:c,height:n.height,fill:l.fill,fillOpacity:u}),t.label&&bs(xs,{x:a+4,y:ws,textAnchor:"start",fontSize:r.typography.tickSize,fill:t.color||ks(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Ss(t,r,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!o.o)return null;const s=o.o(t.category+"");if(null==s)return null;const a=o.o.bandwidth?o.o.bandwidth():40,c=ks(t,r),l=t.opacity??.1,u=t.label;return vs("g","horizontal"===i.projection?{children:[bs("rect",{x:0,y:s,width:n.width,height:a,fill:c,opacity:l}),u&&bs(xs,{x:12,y:s+a/2,dominantBaseline:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Ss(t,r,"none")})]}:{children:[bs("rect",{x:s,y:0,width:a,height:n.height,fill:c,opacity:l}),u&&bs(xs,{x:s+a/2,y:ws,textAnchor:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Ss(t,r,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:i,y:n}=function(t,e,i,o){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const i=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(i)return{x:i[0],y:i[1]}}return{x:As(t,e,i),y:Ms(t,e,o)}}(t,o,s,a);if(null==i||null==n)return null;const c="text"===t.type,l=t.dx??(c?0:30),u=t.dy??(c?0:-30),h=t.color||r.colors.text;if(!c){const o="callout"===t.type?"callout-circle":t.type,r="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return bs(Yr,{noteData:{x:i,y:n,dx:l,dy:u,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...r?{subject:r}:{},connector:t.connector||{end:"arrow"},color:h,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return bs("g",{children:bs("text",{x:i+l,y:n+u,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||r.typography.labelSize,fill:h,fontFamily:r.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}function Rs(t){return"string"==typeof t&&t.length>0}function Ts(t,e){return function(t,e,i=!1){const o=i?e?58:34:e?36:0;return o>t.top?{...t,top:o}:t}(t,Rs(e))}function Ls(t,e,i){return"exact"===i?function(t,e){const i=t.domain(),o=i[0],n=i[i.length-1],r=o instanceof Date,s=o instanceof Date?o.getTime():o,a=n instanceof Date?n.getTime():n;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const c=(a-s)/(e-1),l=Array(e);for(let t=0;e>t;t++){const i=t===e-1?a:s+t*c;l[t]=r?new Date(i):i}return l}(t,e):t.ticks(e)}import{jsx as Cs,jsxs as $s}from"react/jsx-runtime";function zs(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function Ds(t,e){if(0===e.categories.length)return;const i=e.position||"right",o=function(t){const{width:e,height:i,swatchSize:o}=Lr(t);return{width:e,height:i,swatchSize:o}}({categories:e.categories,colorScheme:e.colorScheme,theme:e.theme,position:i,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout});"right"===i?t.right=Math.max(t.right,o.width+14):"left"===i?t.left=Math.max(t.left,o.width+14):"top"===i?t.top=Math.max(t.top,(e.hasTitle?32:8)+o.height+4):t.bottom=Math.max(t.bottom,38+o.height+4)}function Es(t,e){const i=e.position||"right",o={theme:e.theme,position:i,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout},n=go(e.legend)?function(t){const{width:e,height:i,swatchSize:o}=Cr(t);return{width:e,height:i,swatchSize:o}}({...o,legendGroups:e.legend.legendGroups}):mo(e.legend)?$r({...o,gradient:e.legend.gradient}):null;n&&("right"===i?t.right=Math.max(t.right,n.width+14):"left"===i?t.left=Math.max(t.left,n.width+14):"top"===i?t.top=Math.max(t.top,(e.hasTitle?32:8)+n.height+4):t.bottom=Math.max(t.bottom,38+n.height+4))}function Is(t,e){const i={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix};return go(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,i)=>({group:t,item:e,itemIndex:i,label:e.label})))).length)return null;var e;const i=Cr(t),o="top"===t.position||"bottom"===t.position,n=t.theme.colors.grid||t.theme.colors.textSecondary;let r,s;"left"===t.position?(r=Math.max(4,t.margin.left-i.width-10),s=t.margin.top):"top"===t.position?(r=t.margin.left,s=t.hasTitle?32:8):"bottom"===t.position?(r=t.margin.left,s=Math.min(t.totalHeight-t.margin.bottom+38,t.totalHeight-i.height-2)):(r=Math.min(t.totalWidth-i.width-4,t.totalWidth-t.margin.right+10),s=t.margin.top);const a=i.groups.flatMap((e,r)=>{const{group:s}=e,a=s.type??"fill",c=[];if(s.label&&c.push(Mr("text",o?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Rr(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:s.label}:{x:e.x,y:e.y+Rr(t.theme),fontSize:Rr(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:s.label},"legend-group-label-"+r)),c.push(...e.items.map((o,n)=>{const c=s.items[n],l=s.styleFn(c,n),u="function"==typeof a?a(c):"line"===a?Mr("line",{x1:0,y1:0,x2:i.swatchSize,y2:i.swatchSize,style:l}):Mr("rect",{width:i.swatchSize,height:i.swatchSize,rx:i.swatchRadius,style:l});return _r("g",{transform:`translate(${e.x+e.itemOffsetX+o.x},${e.y+e.itemOffsetY+o.y})`,children:[u,Mr("text",{x:i.labelOffset,y:i.swatchSize/2,dominantBaseline:"central",fontSize:Rr(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:o.category})]},`legend-${r}-${n}`)})),!o&&i.groups.length-1>r)c.push(Mr("line",{x1:0,y1:e.y+e.height-6,x2:i.width,y2:e.y+e.height-6,stroke:n},"legend-group-separator-"+r));else if(o&&i.groups.length-1>r){const t=e.x+e.width+6;c.push(Mr("line",{x1:t,y1:0,x2:t,y2:i.height,stroke:n},"legend-group-separator-"+r))}return c});return Mr("g",{className:"semiotic-legend",transform:`translate(${r},${s})`,"data-orientation":o?"horizontal":"vertical",children:a})}({...i,legendGroups:t.legendGroups}):mo(t)?function(t){const e=$r(t),i="top"===t.position||"bottom"===t.position,o=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",n=t.gradient.format||(t=>Math.round(100*t)/100+"");let r,s;"left"===t.position?(r=Math.max(4,t.margin.left-e.width-10),s=t.margin.top):"top"===t.position?(r=t.margin.left,s=t.hasTitle?32:8):"bottom"===t.position?(r=t.margin.left,s=Math.min(t.totalHeight-t.margin.bottom+38,t.totalHeight-e.height-2)):(r=Math.min(t.totalWidth-e.width-4,t.totalWidth-t.margin.right+10),s=t.margin.top);const a=Array.from({length:17},(e,o)=>{const n=o/16;return Mr("stop",{offset:100*n+"%",stopColor:t.gradient.colorFn(i?t.gradient.domain[0]+n*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-n*(t.gradient.domain[1]-t.gradient.domain[0]))},o)});if(i){const i=12,c=t.gradient.label?0:void 0,l=t.gradient.label?8:0;return _r("g",{className:"semiotic-legend",transform:`translate(${r},${s})`,children:[Mr("defs",{children:Mr("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:a})}),t.gradient.label&&Mr("text",{x:e.width/2,y:c,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),Mr("rect",{x:0,y:l,width:e.width,height:i,fill:`url(#${o})`,rx:2}),Mr("text",{x:0,y:l+i+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:n(t.gradient.domain[0])}),Mr("text",{x:e.width,y:l+i+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:n(t.gradient.domain[1])})]})}const c=t.gradient.label?-6:void 0;return _r("g",{className:"semiotic-legend",transform:`translate(${r},${s+(t.gradient.label?12:0)})`,children:[Mr("defs",{children:Mr("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:a})}),t.gradient.label&&Mr("text",{x:7,y:c,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),Mr("rect",{x:0,y:0,width:14,height:100,fill:`url(#${o})`,rx:2}),Mr("text",{x:19,y:10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:n(t.gradient.domain[1])}),Mr("text",{x:19,y:100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:n(t.gradient.domain[0])})]})}({...i,gradient:t.gradient}):null}function Fs(t){return Math.round(100*t)/100+""}function Ns(t,e){const i=P(e.theme),o=e.idPrefix?e.idPrefix+"-":"",n="string"==typeof e.title?e.title:void 0,r=n?o+"semiotic-title":void 0,s=e.description?o+"semiotic-desc":void 0,a=[r,s].filter(Boolean).join(" ")||void 0;return $s("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":a,style:{fontFamily:i.fontFamily},children:[n&&Cs("title",{id:r,children:n}),e.description&&Cs("desc",{id:s,children:e.description}),e.defs&&Cs("defs",{children:e.defs}),e.background&&"transparent"!==e.background&&Cs("rect",{x:0,y:0,width:e.width,height:e.height,fill:e.background}),Cs("g",{id:o+"data-area",transform:e.innerTransform,children:t}),n&&Cs("text",{id:o+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:i.titleSize,fontWeight:"bold",fill:i.text,fontFamily:i.fontFamily,children:n}),e.legend&&Cs("g",{id:o+"legend",children:e.legend}),e.outerElements]})}import{Fragment as Bs,jsx as Os,jsxs as Ws}from"react/jsx-runtime";function js(t,e){const i=_(t.theme),o=t.size||[500,300],n=Ts({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Rs(t.title),s=bo(t.data),a=t.showLegend?Dr(s,t.colorAccessor||t.groupAccessor):[],c=t.legendPosition;go(t.legend)||mo(t.legend)?Es(n,{legend:t.legend,theme:i,position:c||"right",size:o,hasTitle:r,legendLayout:t.legendLayout}):t.showLegend&&a.length>0&&Ds(n,{categories:a,colorScheme:t.colorScheme,theme:i,position:c||"right",size:o,hasTitle:r,legendLayout:t.legendLayout});const l=o[0]-n.left-n.right,u=o[1]-n.top-n.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),d=t.colorScheme||i.colors.categorical,f={chartType:t.chartType,windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:h?void 0:t.xAccessor,yAccessor:h?void 0:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor,categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,sizeRange:t.sizeRange,xScaleType:t.xScaleType,yScaleType:t.yScaleType,scalePadding:t.scalePadding,binSize:t.binSize,normalize:t.normalize,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:!0===t.gradientFill?{topOpacity:.8,bottomOpacity:.05}:!1===t.gradientFill?void 0:t.gradientFill,lineGradient:t.lineGradient,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:d,themeCategorical:i.colors.categorical,themeSemantic:g(i),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors},p=new tr(f);if(t.data&&p.ingest({inserts:s,bounded:!0}),p.computeScene({width:l,height:u}),!p.scales||0===p.scene.length)return e&&(e.evidence=yo({frameType:"xy",width:o[0],height:o[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:p.scales?[]:["NO_SCALES"]})),wo.renderToStaticMarkup(Ns(null,{width:o[0],height:o[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:t._idPrefix}));e&&(e.evidence=yo({frameType:"xy",width:o[0],height:o[1],marks:p.scene,title:t.title,description:t.description,annotations:t.annotations,xDomain:po(p.scales.x?.domain?.()),yDomain:po(p.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0}));const y=t._idPrefix,m=t.showGrid?function(t,e,i,o,n){const{grid:r}=P(i),s=o?o+"-":"",a=Ls(t.x,5,n),c=Ls(t.y,5,n);return $s("g",{id:s+"grid",className:"semiotic-grid",opacity:.8,children:[a.map((i,o)=>{const n=t.x(i);return Cs("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:r,strokeWidth:.5},"gx-"+o)}),c.map((i,o)=>{const n=t.y(i);return Cs("line",{x1:0,y1:n,x2:e.width,y2:n,stroke:r,strokeWidth:.5},"gy-"+o)})]})}(p.scales,{width:l,height:u},i,y,t.axisExtent):null,x=p.scene.map((e,i)=>Sr({node:e,index:i,renderMode:t.renderMode,fallback:()=>vr(e,i,y)})).filter(Boolean),b=!1!==t.showAxes?function(t,e,i,o,n){const r=P(o),s=Ls(t.x,5,i.axisExtent).map(e=>({pixel:t.x(e),label:(i.xFormat||i.tickFormatTime||Fs)(e)})),a=Ls(t.y,5,i.axisExtent).map(e=>({pixel:t.y(e),label:(i.yFormat||i.tickFormatValue||Fs)(e)}));return $s("g",{id:(n?n+"-":"")+"axes",className:"stream-axes",children:[Cs("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:r.border,strokeWidth:1}),s.map((t,i)=>$s("g",{transform:`translate(${t.pixel},${e.height})`,children:[Cs("line",{y2:5,stroke:r.border,strokeWidth:1}),Cs("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"xtick-"+i)),i.xLabel&&Cs("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:i.xLabel}),Cs("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:r.border,strokeWidth:1}),a.map((t,e)=>$s("g",{transform:`translate(0,${t.pixel})`,children:[Cs("line",{x2:-5,stroke:r.border,strokeWidth:1}),Cs("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"ytick-"+e)),i.yLabel&&Cs("text",{x:15-(i.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-(i.margin?.left??40)}, ${e.height/2})`,children:i.yLabel})]})}(p.scales,{width:l,height:u},t,i,y):null,v=t.annotations?_s({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{x:p.scales.x,y:p.scales.y},layout:{width:l,height:u},theme:i,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:y}):null,w=t.svgPreRenderers&&p.scales?t.svgPreRenderers.map((t,e)=>{try{return Os(vo.Fragment,{children:t(p.scene,p.scales,{width:l,height:u})},"pre-"+e)}catch{return null}}).filter(Boolean):null,k=t.showLegend?0===a.length?null:zr({categories:a,colorScheme:t.colorScheme,theme:i,position:t.legendPosition||"right",totalWidth:o[0],totalHeight:o[1],margin:n,hasTitle:r,legendLayout:t.legendLayout}):null,S=vo.isValidElement(t.legend)?t.legend:Is(t.legend,{theme:i,position:t.legendPosition||"right",size:o,margin:n,hasTitle:r,legendLayout:t.legendLayout,idPrefix:t._idPrefix})||k;return wo.renderToStaticMarkup(Ns(Ws(Bs,{children:[t.backgroundGraphics,w,m,x,b,v,t.foregroundGraphics,p.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,legend:S,idPrefix:t._idPrefix}))}import*as Ys from"react";import*as Xs from"react-dom/server";import{scaleBand as qs,scaleLinear as Gs}from"d3-scale";var Vs=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,i){if(e&&"function"==typeof t.pieceStyle){const o=t.pieceStyle(e,i);return o&&!o.fill&&i?{...o,fill:this.getColorFromScheme(t,i)}:o}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&i?{fill:t.barColors[i]||"#007bff"}:{fill:i?this.getColorFromScheme(t,i):"#007bff"}}resolveSummaryStyle(t,e,i){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,i):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const i=this.colorSchemeMap.get(e);if(i)return i;const o=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||U,n=o[this.colorSchemeIndex%o.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,n),n}};function Hs(t){const e=t.getSymbol;if(!e)return null;const i=t.config.symbolMap,o=new Map;let n=0;return t=>{const r=e(t)+"",s=i?.[r];if(s)return s;let a=o.get(r);return a||(a=un[n%un.length],n++,o.set(r,a)),a}}function Zs(t,e,i,o,n,r,s){t.push(e?{type:"symbol",x:o,y:n,size:Math.PI*r*r,symbolType:e(i),style:s,datum:i}:{type:"point",x:o,y:n,r:r,style:s,datum:i})}function Ks(t,e){const{columns:i,config:o,resolvePieceStyle:n}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===o.chartType?o.innerRadius||60:0,c=-Math.PI/2+(o.startAngle||0)*Math.PI/180,l=null!=o.sweepAngle?o.sweepAngle*Math.PI/180:2*Math.PI,u=null!=o.sweepAngle&&360>o.sweepAngle,h=Object.values(i),d=h.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),f=u&&!d&&h.length>1&&(o.cornerRadius??0)>0;for(let t=0;h.length>t;t++){const e=h[t],i=e.pieceData[0],u="number"==typeof i?._pctStart?i._pctStart:e.pctStart,d=c+u*l,p=c+(u+("number"==typeof i?._pct?i._pct:e.pct))*l,y=n(e.pieceData[0],e.name),g=0===t,m=t===h.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:d,endAngle:p,...o.cornerRadius&&{cornerRadius:o.cornerRadius},style:y,datum:i?._nonInteractive?null:e.pieceData,category:e.name};i?._roundedEnds?x.roundedEnds=i._roundedEnds:f&&(x.roundedEnds={start:g,end:m}),i?._gradientBand&&(x._gradientBand=i._gradientBand),r.push(x)}return r}import{quantile as Us}from"d3-array";function Qs(t){const e=t.length,i=t[0],o=t[e-1];return{n:e,min:i,q1:Us(t,.25)??i,median:Us(t,.5)??(i+o)/2,q3:Us(t,.75)??o,max:o,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as Js}from"d3-scale";var ta={bar:function(t,e){const{scales:i,columns:o,config:n,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:c,projection:l}=i,u=[],h="vertical"===l,d="horizontal"===l,f=n.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(o))for(const i of e.pieceData){const e=s(i);t.has(e)||(t.add(e),p.push(e))}}else p.push("_default");for(const t of Object.values(o)){const e=new Map;for(const i of t.pieceData){const t=s?s(i):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const o=e.get(t);o.total+=r(i),o.pieces.push(i)}let i=0;if(f)for(const t of e.values())i+=Math.abs(t.total);let o=0,n=0;for(const r of p){const l=e.get(r);if(!l)continue;let p=l.total;f&&i>0&&(p/=i);const y=a(l.pieces[0],s?r:t.name),g={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:t.name};if(h){const e=c(0>p?n:o+p),i=0>p?c(n+p)-c(n):c(o)-c(o+p);u.push(Yo(t.x,e,t.width,Math.abs(i),y,g,r)),0>p?n+=p:o+=p}else if(d){const e=c(0>p?n+p:o),i=0>p?c(n)-c(n+p):c(o+p)-c(o);u.push(Yo(e,t.x,Math.abs(i),t.width,y,g,r)),0>p?n+=p:o+=p}}}const y="vertical"===l,g=n.roundedTop&&n.roundedTop>0?Math.max(0,n.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=y?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}if(g>0){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const i=e.datum?.category||"";t.has(i)||t.set(i,[]),t.get(i).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),i=e.filter(t=>0>(t.datum?.__aggregateValue??0));t.length>0&&(t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e).roundedTop=g),i.length>0&&(i.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e).roundedTop=g)}}return u},clusterbar:function(t,e){const{scales:i,columns:o,config:n,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:c,projection:l}=i,u=[],h="vertical"===l,d=[],f=new Set;for(const t of Object.values(o))for(const e of t.pieceData){const t=s?s(e):"_default";f.has(t)||(f.add(t),d.push(t))}const p=d.length||1;for(const t of Object.values(o)){const e=t.width/p,i=.2*e,o=e-i,n=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";n.has(t)||n.set(t,[]),n.get(t).push(e)}for(let s=0;d.length>s;s++){const l=n.get(d[s])||[];for(const n of l){const l=r(n),f=a(n,d[s]);if(h){const r=t.x+s*e+i/2,a=c(0),h=c(l);u.push(Yo(r,Math.min(a,h),o,Math.abs(a-h),f,n,d[s]))}else{const r=t.x+s*e+i/2,a=c(0),h=c(l);u.push(Yo(Math.min(a,h),r,Math.abs(h-a),o,f,n,d[s]))}}}}const y=n.roundedTop&&n.roundedTop>0?Math.max(0,n.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum);y>0&&(t.roundedTop=y),t.roundedEdge=h?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}return u},point:function(t,e){const{scales:i,columns:o,getR:n,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:c}=i,l=[],u="vertical"===c,h="radial"===c,d=r.length>0,f=Hs(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(o))for(const e of t.pieceData){const i=e.__rIndex??0,o=e.__rValue??n(e),c=d&&r[i]||a,g=s(e,t.name),m=g.r||5;let x,b;if(h){const e=y+(t.pctStart+t.pct/2)*p,i=c(o);x=Math.cos(e)*i,b=Math.sin(e)*i}else u?(x=t.middle,b=c(o)):(x=c(o),b=t.middle);Zs(l,f,e,x,b,m,g)}return l},swarm:function(t,e){const{scales:i,columns:o,getR:n,resolvePieceStyle:r}=t,{r:s,projection:a}=i,c=[],l="vertical"===a,u=Hs(t);for(const t of Object.values(o)){const e=t.width/2;for(let i=0;t.pieceData.length>i;i++){const o=t.pieceData[i],a=n(o),h=r(o,t.name),d=h.r||4,f=(7919*i%100/100-.5)*e*.8;Zs(c,u,o,l?t.middle+f:s(a),l?s(a):t.middle+f,d,h)}}return c},pie:Ks,donut:Ks,boxplot:function(t,e){const{scales:i,columns:o,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=i,l=[],u="vertical"===c,h=!1!==n.showOutliers;for(const e of Object.values(o)){const i=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===i.length)continue;const o=i[0],n=i[i.length-1],c=Us(i,.25)??o,d=Us(i,.5)??(o+n)/2,f=Us(i,.75)??n,p=f-c,y=c-1.5*p,g=f+1.5*p,m=i.find(t=>t>=y)??o,x=[...i].reverse().find(t=>g>=t)??n,b=s(e.pieceData[0],e.name),v=[];if(h)for(const t of e.pieceData){const i=r(t);if(y>i||i>g){const o=u?e.middle:a(i),n=u?a(i):e.middle;v.push({px:o,py:n,value:i,datum:t})}}if(l.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(c),medianPos:a(d),q3Pos:a(f),maxPos:a(x),stats:{n:i.length,min:m,q1:c,median:d,q3:f,max:x,mean:i.reduce((t,e)=>t+e,0)/i.length},style:b,datum:e.pieceData,category:e.name,outliers:v}),h)for(const e of v)l.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:b.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6},datum:e.datum})}return l},violin:function(t,e){const{scales:i,columns:o,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=i,l=[],u="vertical"===c,h=n.bins||20,d=!1!==n.showIQR;for(const t of Object.values(o)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const i=e[0],o=e[e.length-1],n=(o-i)/h||1,c=Array(h).fill(0);for(const t of e)c[Math.min(Math.floor((t-i)/n),h-1)]++;const f=It(c,1),p=t.width/2*.9;let y;if(u){y=`M ${t.middle} ${a(i)}`;for(let e=0;h>e;e++){const o=a(i+(e+.5)*n);y+=` L ${t.middle+c[e]/f*p} ${o}`}y+=` L ${t.middle} ${a(o)}`;for(let e=h-1;e>=0;e--){const o=a(i+(e+.5)*n);y+=` L ${t.middle-c[e]/f*p} ${o}`}y+=" Z"}else{y=`M ${a(i)} ${t.middle}`;for(let e=0;h>e;e++)y+=` L ${a(i+(e+.5)*n)} ${t.middle-c[e]/f*p}`;y+=` L ${a(o)} ${t.middle}`;for(let e=h-1;e>=0;e--)y+=` L ${a(i+(e+.5)*n)} ${t.middle+c[e]/f*p}`;y+=" Z"}const g=s(t.pieceData[0],t.name);let m;if(d&&e.length>=4){const n=Us(e,.25)??i,r=Us(e,.5)??(i+o)/2,s=Us(e,.75)??o;m={q1Pos:a(n),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=u?{x:t.x,y:Math.min(a(o),a(i)),width:t.width,height:Math.abs(a(o)-a(i))}:{x:Math.min(a(i),a(o)),y:t.x,width:Math.abs(a(o)-a(i)),height:t.width};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:Qs(e),style:g,datum:t.pieceData,category:t.name})}return l},histogram:function(t,e){const{scales:i,columns:o,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a}=i,c=[],l=n.bins||25,u=n.normalize,h=a.domain?.(),d=h?+h[0]:void 0,f=h?+h[1]:void 0;for(const t of Object.values(o)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[i,o]=Et(e),n=null!=d&&isFinite(d)?d:i,h=null!=f&&isFinite(f)?f:o,p=(h-n)/l||1,y=Array(l).fill(0);for(const t of e)n>t||t>h||y[Math.min(Math.floor((t-n)/p),l-1)]++;const g=e.length,m=It(y,1),x=s(t.pieceData[0],t.name);for(let e=0;l>e;e++){if(0===y[e])continue;const i=(u?y[e]/g:y[e]/m)*t.width*.9,o=a(n+e*p),r=a(n+(e+1)*p);c.push(Yo(Math.min(o,r),t.x+t.width-i,Math.abs(r-o),i,x,{bin:e,count:y[e],range:[n+e*p,n+(e+1)*p],category:t.name},t.name))}}return c},ridgeline:function(t,e){const{scales:i,columns:o,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=i,l=[],u=n.bins||20,h="horizontal"===c,d=n.amplitude||1.5;for(const t of Object.values(o)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const i=e[0],o=e[e.length-1],n=(o-i)/u||1,c=Array(u).fill(0);for(const t of e)i>t||t>o||c[Math.min(Math.floor((t-i)/n),u-1)]++;const f=It(c,1),p=s(t.pieceData[0],t.name),y=t.width*d;let g;if(h){const e=t.x+t.width;g=`M ${a(i)} ${e}`;for(let t=0;u>t;t++)g+=` L ${a(i+(t+.5)*n)} ${e-c[t]/f*y}`;g+=` L ${a(o)} ${e} Z`}else{const e=t.x;g=`M ${e} ${a(i)}`;for(let t=0;u>t;t++){const o=a(i+(t+.5)*n);g+=` L ${e+c[t]/f*y} ${o}`}g+=` L ${e} ${a(o)} Z`}const m=h?{x:Math.min(a(i),a(o)),y:t.x,width:Math.abs(a(o)-a(i)),height:t.width}:{x:t.x,y:Math.min(a(o),a(i)),width:t.width,height:Math.abs(a(o)-a(i))};l.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:m,stats:Qs(e),style:{...p,fillOpacity:p.fillOpacity??.5},datum:t.pieceData,category:t.name})}return l},timeline:function(t,e){const{scales:i,columns:o,getRawRange:n,resolvePieceStyle:r}=t,{r:s,projection:a}=i,c=[],l="horizontal"===a;for(const t of Object.values(o))for(const e of t.pieceData){const i=n(e);if(!i)continue;const[o,a]=i,u=r(e,t.name);if(l){const i=s(Math.min(o,a)),n=s(Math.max(o,a));c.push(Yo(i,t.x,n-i,t.width,u,e,t.name))}else{const i=s(Math.max(o,a)),n=s(Math.min(o,a));c.push(Yo(t.x,i,t.width,n-i,u,e,t.name))}}return c},funnel:function(t,e){const{columns:i,getR:o,getStack:n,resolvePieceStyle:r}=t,s=[],a=e.width/2,c=!1!==t.config.showLabels,l=t.scales.o.domain().map(t=>i[t]).filter(Boolean);if(0===l.length)return s;const u=[],h=new Set;for(const t of l)for(const e of t.pieceData){const t=n?n(e):"_default";h.has(t)||(h.add(t),u.push(t))}const d=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const t of l){const e=new Map;let i=0;for(const r of t.pieceData){const t=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=o(r);s.total+=a,s.pieces.push(r),i+=a}f.push({col:t,groups:e,stepTotal:i}),d||i>p&&(p=i)}if(d)for(const t of f){let e=0,i=0;for(let o=0;u.length>o;o++){const n=t.groups.get(u[o]);n&&(o%2==0?e+=n.total:i+=n.total)}const o=Math.max(e,i);o>p&&(p=o)}if(0===p)return s;const y=new Map;for(const t of u){const e=f[0].groups.get(t);y.set(t,e?.total??0)}const g=f[0].stepTotal,m=d?.95*a:.9*e.width,x=Js().domain([0,p]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const i=f[e],o=i.col,n=0===e,l=o.width,h=.55*l,p=o.x+(l-h)/2,m=new Map;if(d){let t=0;for(const e of u){const o=i.groups.get(e);o&&(t+=x(o.total))}let e=a,l=a;for(let d=0;u.length>d;d++){const f=u[d],g=i.groups.get(f);if(!g)continue;const b=x(g.total),v=d%2==0,w=v?e:l-b;v?e+=b:l-=b;const k=r(g.pieces[0],f),S=y.get(f)??g.total,A={...g.pieces[0],__funnelValue:g.total,__funnelPercent:S>0?g.total/S*100:0,__funnelStep:o.name,__funnelIsFirstStep:n,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};c&&(0===d&&(A.__funnelStepLabel=o.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=t),A.__funnelValueLabelX=w+b/2,A.__funnelValueLabelY=p,A.__funnelBarW=b),s.push(Yo(w,p,b,h,k,A,f)),m.set(f,{x:w,y:p,w:b,h:h})}}else{const t=i.stepTotal,e=x(t),l=a-e/2,d=u[0],f="_default"!==d,y=i.groups.get(d)?.pieces[0]??o.pieceData[0],b=f?d:o.name,v=r(y,b),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:o.name,__funnelIsFirstStep:n,category:f?d:o.name};c&&(k.__funnelStepLabel=o.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(Yo(l,p,e,h,v,k,b)),m.set(d,{x:l,y:p,w:e,h:h})}if(e>0&&v.size>0){const e=d?u:[u[0]];for(const n of e){const e=v.get(n),a=m.get(n);if(!e||!a)continue;const c=(()=>{const t=i.groups.get(n);return r(t?t.pieces[0]:o.pieceData[0],"_default"===n?o.name:n)})(),l={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||t.config.themeSemantic?.secondary||"#999",opacity:b},datum:i.groups.get(n)?.pieces[0]??o.pieceData[0],category:"_default"===n?o.name:n};s.push(l)}}v=m}return s},"bar-funnel":function(t,e){const{columns:i,getR:o,getStack:n,resolvePieceStyle:r,scales:s}=t,a=[],c=s.o.domain().map(t=>i[t]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const t of c)for(const e of t.pieceData){const t=n?n(e):"_default";u.has(t)||(u.add(t),l.push(t))}const h=l.length>1&&"_default"!==l[0],d=[];for(const t of c){const e=new Map;let i=0;for(const r of t.pieceData){const t=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=o(r);s.total+=a,s.pieces.push(r),i+=a}d.push({col:t,groups:e,stepTotal:i})}const f=new Map;for(const t of l){const e=d[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,y=h?l.length:1,g=h?.15:0;for(let t=0;d.length>t;t++){const e=d[t],i=e.col,o=0===t,n=t>0?d[t-1]:null,s=i.width/y,c=s*g,u=s-c;for(let t=0;l.length>t;t++){const d=l[t],y=e.groups.get(d);if(!y)continue;const g=y.total,m=f.get(d)??g,x=m>0?g/m*100:0,b=n?.groups.get(d),v=o?0:Math.max(0,(b?.total??g)-g),w=i.x+t*s+c/2,k=p(g),S=p(0)-k,A=r(y.pieces[0],h?d:i.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:x,__barFunnelIsFirstStep:o,__barFunnelIsDropoff:!1,__barFunnelStep:i.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===d?void 0:d,category:h?d:i.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(g+v)};if(a.push(Yo(w,k,u,S,A,M,h?d:i.name)),v>0){const t=p(g+v),e=k-t,o={...A},n={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:i.name,__barFunnelCategory:"_default"===d?void 0:d,category:h?d:i.name};a.push(Yo(w,t,u,e,o,n,h?d:i.name))}}}return a},swimlane:function(t,e){const{scales:i,columns:o,getR:n,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:c}=i,l=[],u="horizontal"===c,h=t.config.gradientFill,d=u?"left":"bottom",f=t.config.trackFill;if(f){const t="string"==typeof f?f:f.color,e="string"==typeof f?1:f.opacity??1,[i,n]=a.range(),r=Math.min(i,n),s=Math.abs(n-i);for(const i of Object.values(o)){const o={fill:t,opacity:e},n=u?Yo(r,i.x,s,i.width,o,null,"__track__"):Yo(i.x,r,i.width,s,o,null,"__track__");l.push(n)}}const p=t.config.roundedTop&&t.config.roundedTop>0?Math.max(0,t.config.roundedTop):0;for(const t of Object.values(o)){let e=0;const i=l.length;for(const i of t.pieceData){const o=Math.abs(n(i));if(0===o)continue;const c=r?r(i):t.name,f=s(i,c);let p;if(u){const n=a(e),r=a(e+o);p=Yo(n,t.x,r-n,t.width,f,i,c)}else{const n=a(e+o),r=a(e);p=Yo(t.x,n,t.width,r-n,f,i,c)}h&&(p.fillGradient=h,p.roundedEdge=d),l.push(p),e+=o}if(p>0&&l.length>i){const t=l.slice(i),e=t[0],o=t[t.length-1];1===t.length?e.cornerRadii={tl:p,tr:p,br:p,bl:p}:u?(e.cornerRadii={tl:p,bl:p},o.cornerRadii={tr:p,br:p}):(e.cornerRadii={bl:p,br:p},o.cornerRadii={tl:p,tr:p})}}return l}},ea=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ia=["scene-style","data-paint","accessibility","evidence"],oa=(t,e)=>({retainedData:t,invalidations:e}),na=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ra=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sa=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],aa=["scene-geometry","data-paint","accessibility","evidence"],ca=["scene-style","data-paint","accessibility","evidence"],la=[],ua={chartType:oa("rebuild",na),runtimeMode:oa("rebuild",na),categoryAccessor:oa("rebuild",na),valueAccessor:oa("rebuild",na),oAccessor:oa("rebuild",na),rAccessor:oa("rebuild",na),stackBy:oa("rebuild",na),groupBy:oa("rebuild",na),timeAccessor:oa("rebuild",na),accessorRevision:oa("rebuild",na),colorAccessor:oa("rebuild",ca),symbolAccessor:oa("rebuild",aa),connectorAccessor:oa("rebuild",aa),dataIdAccessor:oa("rebuild",aa),projection:oa("preserve",ra),extentPadding:oa("preserve",ra),axisExtent:oa("preserve",ra),rExtent:oa("preserve",ra),oExtent:oa("preserve",ra),multiAxis:oa("preserve",ra),normalize:oa("preserve",ra),bins:oa("preserve",ra),oSort:oa("preserve",sa),barPadding:oa("preserve",sa),roundedTop:oa("preserve",sa),baselinePadding:oa("preserve",sa),innerRadius:oa("preserve",sa),cornerRadius:oa("preserve",sa),startAngle:oa("preserve",sa),sweepAngle:oa("preserve",sa),trackFill:oa("preserve",sa),showOutliers:oa("preserve",sa),showIQR:oa("preserve",sa),amplitude:oa("preserve",sa),connectorOpacity:oa("preserve",sa),showLabels:oa("preserve",sa),dynamicColumnWidth:oa("rebuild",sa),customLayout:oa("preserve",sa),layoutConfig:oa("preserve",sa),layoutMargin:oa("preserve",sa),symbolMap:oa("preserve",aa),pieceStyle:oa("preserve",ca),summaryStyle:oa("preserve",ca),connectorStyle:oa("preserve",ca),gradientFill:oa("preserve",ca),colorScheme:oa("preserve",ca),themeCategorical:oa("preserve",ca),themeSemantic:oa("preserve",ca),themeSequential:oa("preserve",ca),themeDiverging:oa("preserve",ca),barColors:oa("preserve",ca),decay:oa("preserve",ca),pulse:oa("preserve",ca),staleness:oa("preserve",ca),layoutSelection:oa("preserve",ca),windowSize:oa("preserve",la),windowMode:oa("preserve",la),clock:oa("preserve",la),transition:oa("preserve",la),introAnimation:oa("preserve",la),onLayoutError:oa("preserve",la)},ha=oa("preserve",sa),da=class{constructor(){this.tracker=new bi}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ea)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},ia):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const i=new Set;for(const o of t){const t=ua[o]??ha;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as fa}from"d3-quadtree";var pa=class{constructor(t){this.rExtent=new So,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new da,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Vs,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=t,this.buffer=new ko(t.windowSize),this.getO=a(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>r(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new So)):(this.getR=r(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=a(t.stackBy),this.getGroup=a(t.groupBy),this.getColor=a(t.colorAccessor),this.getSymbol=a(t.symbolAccessor),this.getConnector=a(t.connectorAccessor),this.getDataId=a(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new ko(t.windowSize))}syncPulseTimestampBuffer(){var t,e,i,o;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,i=this.timestampBuffer,o=this.currentTime(),t?null!=i&&i.capacity===e.capacity&&i.size===e.size?i:Pn(e,o):null)}currentTime(){return this.config.clock?.()??Co()}ingest(t){const e=this.currentTime();if(this.lastIngestTime=e,this._dataVersion++,t.bounded){this.buffer.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();t.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),_n(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const i of t.inserts)Rn(this.buffer,i,this.timestampBuffer,e),this.categories.add(this.getO(i)),this.pushValueExtent(i)}else{this._hasStreamingData=!0;for(const i of t.inserts){const t=Rn(this.buffer,i,this.timestampBuffer,e);this.categories.add(this.getO(i)),this.pushValueExtent(i),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const i="function"==typeof e?e(t):t[e];return Array.isArray(i)&&i.length>=2?[+i[0],+i[1]]:null}computeScene(t){const{config:e,buffer:i}=this,o=this.scales,n=this.multiScales,r=this.columns;if(0===i.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(i,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",c=e.oExtent||this.resolveCategories(s),l=this.computeValueDomain(s,c),u="horizontal"===a,h="radial"===a,d=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let f,p;if(h){f=qs().domain(c).range([0,1]).padding(0);const i=Math.min(t.width,t.height)/2,o=e.innerRadius||0;p=Gs().domain(l).range([o,i])}else u?(f=qs().domain(c).range([0,t.height]).padding(d),p=Gs().domain(l).range([0,t.width])):(f=qs().domain(c).range([0,t.width]).padding(d),p=Gs().domain(l).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((o,n)=>{const r=this.rExtents[n];r.dirty&&r.recalculate(i,o);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const c=a-s,l=c>0?c*(e.extentPadding??.05):1;return s-=l,a+=l,s>0&&(s=0),u?Gs().domain([s,a]).range([0,t.width]):Gs().domain([s,a]).range([t.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(t=>this.rAccessors.map((e,i)=>({...t,__rIndex:i,__rValue:e(t),__rName:this.resolveRAccessorName(i)})))),this.columns=this.buildColumns(y,c,f,a,t),this._customLayoutFailedThisBuild=!1;const g=this.buildSceneNodes(y,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.multiScales=n,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,i=Array.isArray(e)?e[t]:e;return"string"==typeof i?i:"value"+t}resolveCategories(t){const e=this.config.oSort,i="streaming"===this.config.runtimeMode||this._hasStreamingData,o="auto"===e?void 0:e;let n=null;if(i){n=new Set;for(const e of t)n.add(this.getO(e))}const r=n?Array.from(this.categories).filter(t=>n.has(t)):Array.from(this.categories);if(i&&void 0===o){const t=Math.max(50,3*n.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;n.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===o)return r;if("function"==typeof o)return r.sort(o);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===o?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:i,projection:o,normalize:n,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:h,rawRExtent:d}=t,f=s;if("radial"===o&&("pie"===i||"donut"===i))return[0,1];let p=0,y=0;if("bar"===i&&h&&n)p=0,y=1;else if("bar"===i&&h){const t=new Map,i=new Map;for(const o of e){const e=l(o),n=u(o);0>n?i.set(e,(i.get(e)||0)+n):t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e);for(const t of i.values())p>t&&(p=t)}else if("bar"===i){const t=new Map;for(const i of e){const e=l(i),o=u(i);t.set(e,(t.get(e)||0)+o)}for(const e of t.values())e>y&&(y=e),p>e&&(p=e)}else if("swimlane"===i){const t=new Map;for(const i of e){const e=l(i),o=Math.abs(u(i));t.set(e,(t.get(e)||0)+o)}for(const e of t.values())e>y&&(y=e)}else if("clusterbar"===i||"bar-funnel"===i)for(const t of e){const e=u(t);e>y&&(y=e),p>e&&(p=e)}else{const t=d[0],e=d[1];t!==1/0&&(p=t),e!==-1/0&&(y=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(y=r[1]));const g="bar"===i||"clusterbar"===i||"bar-funnel"===i||"swimlane"===i;if(g&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>y&&(y=0)),"bar-funnel"!==i&&"exact"!==c){const t=y-p,e=t>0?t*f:1,o=g&&!a&&0===p,n=g&&!a&&0===y||"swimlane"===i;null!=r?.[0]||o||(p-=e),null!=r?.[1]||n||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,i,o,n){return function(t){const{data:e,oExtent:i,oScale:o,projection:n,layout:r,dynamicColumnWidth:s,getO:a,getR:c}=t,l={},u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let h=0;if("radial"===n)for(const t of e)h+=Math.abs(c(t));let d=null;if(s&&"radial"!==n){d=new Map;let t=0;for(const e of i){const i=u.get(e)||[];let o;o="string"==typeof s?i.reduce((t,e)=>t+(Number(e[s])||0),0):s(i),d.set(e,o),t+=o}const e=("horizontal"===n?r.height:r.width)-o.padding()*o.step()*i.length;if(t>0)for(const[i,o]of d)d.set(i,o/t*e)}let f=0,p=0;for(const t of i){const e=u.get(t)||[],i=e.reduce((t,e)=>t+Math.abs(c(e)),0),n=h>0?i/h:0;let r,s;d?(r=p,s=d.get(t)||o.bandwidth(),p+=s+o.padding()*o.step()):(r=o(t)??0,s=o.bandwidth()),l[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:o.padding()*o.step(),pieceData:e,pct:n,pctStart:f},f+=n}return l}({data:t,oExtent:e,oScale:i,projection:o,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const i=this.buildLayoutContext(t,e);let o;try{o=this.config.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,i=mn("ordinal",t,e,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.onLayoutError?.(i)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=o.overlays??null,this.lastCustomLayoutResult=o,this.lastCustomLayoutFailure=null;const n=o.nodes??[];if(this._customRestyle=o.restyle,this.hasCustomRestyle=!!o.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of n)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(n,this.config.layoutSelection??null)}return pn({label:"ordinal customLayout",nodes:n,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),n}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const i=this.getSceneContext(),o=ta[this.config.chartType];let n=o?o(i,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:i,config:o,getConnector:n,getO:r}=t;if(!n||!i)return[];const s=[],{projection:a}=i,c=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const i=n(e);if(!i)continue;let o,s;"point"===t.type?(o=t.x,s=t.y):(o=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),c.has(i)||c.set(i,[]),c.get(i).push({x:o,y:s,datum:e,category:r(e)})}const l=i.o.domain(),u=o.connectorStyle;for(const[e,i]of c)if(i.length>=2){i.sort((t,e)=>l.indexOf(t.category)-l.indexOf(e.category));for(let o=0;i.length-1>o;o++){const n=i[o],r=i[o+1],a="function"==typeof u?u(n.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:n.x,y1:n.y,x2:r.x,y2:r.y,style:a,datum:n.datum,group:e})}}return s}(i,n);n=[...t,...n]}return n}buildLayoutContext(t,e){const i=this.config,o=i.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Qi(i.colorScheme,i.themeCategorical,U),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:o,plot:"radial"===r.projection?{x:-e.width/2,y:-e.height/2,width:e.width,height:e.height}:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:i.themeSemantic??{},categorical:[...n]},resolveColor:Ji(n,i.colorScheme),config:i.layoutConfig??{},selection:i.layoutSelection??null}}computeDecayOpacity(t,e){const i=this.config.decay;return i&&e>1?$o(i,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=zo(t);return this._datumIndexCache={version:this._dataVersion,map:e},e}getCategoryIndexMap(t){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const e=function(t,e){const i="function"==typeof e,o=i?null:e||"category",n=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=i?e(s):s[o],c=n.get(a);c?c.push(r):n.set(a,[r])}return n}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,i=0;for(const o of t)"point"===o.type&&(e++,o.r>i&&(i=o.r));if(500>=e)return{quadtree:null,maxRadius:i};const o=Array(e);let n=0;for(const e of t)"point"===e.type&&(o[n++]=e);return{maxRadius:i,quadtree:fa().x(t=>t.x).y(t=>t.y).addAll(o)}}(this.scene);this._pointQuadtree=t.quadtree,this._maxPointRadius=t.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(t,e){if(!this.config.decay)return;const i=e.length;if(1>=i)return;const o=this.getDatumIndexMap(e);for(const e of t){if("connector"===e.type||"violin"===e.type||"boxplot"===e.type||"wedge"===e.type)continue;if(!e.datum)continue;const t=o.get(e.datum);if(null==t)continue;const n=this.computeDecayOpacity(t,i);e.style={...e.style,opacity:(e.style?.opacity??1)*n}}}applyPulse(t,e,i=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,i,o,n,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;for(const l of e){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const e=l.category;if(!e)continue;let o=0;for(const s of n(e)??[]){const e=i.get(s);null!=e&&(o=Math.max(o,Do(t,e,r)))}c=Eo(l,o,s)||c;continue}if(null==l.datum)continue;const e=o.get(l.datum);if(null==e)continue;const u=i.get(e);c=Eo(l,null==u?0:Do(t,u,r),s,a)||c}return c}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),i)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Io(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const t=new Map,e=this.scales?.r(0)??0,i="horizontal"!==this.scales?.projection;let o;for(let n=0;this.scene.length>n;n++){const r=this.scene[n],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,i?{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}:{x:e,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===o&&(o=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:o,endAngle:o,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const i=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,o=e.get(i)||0;return e.set(i,o+1),`${i}:${o}`}return"rect"===t.type?`r:${t.group||""}:${t.datum?.category??""}`:"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const i=this.scene[e],o=this.getNodeKey(i,t);o&&("point"===i.type?this.prevPositionMap.set(o,{x:i.x,y:i.y,r:i.r,opacity:i.style.opacity}):"rect"===i.type?this.prevPositionMap.set(o,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:i.style.opacity}):"wedge"===i.type&&this.prevPositionMap.set(o,{x:i.cx,y:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:i.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const t=this.config.transition.duration??300;if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}let e=!1;const i=new Set,o=new Map;for(let t=0;this.scene.length>t;t++){const n=this.scene[t],r=this.getNodeKey(n,o);if(!r)continue;n._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===n.type)s?(i.add(r),n._targetOpacity=n.style.opacity??1,(s.x!==n.x||s.y!==n.y||void 0!==s.r&&s.r!==n.r)&&(n._targetX=n.x,n._targetY=n.y,n._targetR=n.r,n.x=s.x,n.y=s.y,void 0!==s.r&&(n.r=s.r),e=!0)):(n._targetOpacity=n.style.opacity??1,n._targetR=n.r,n.r=0,n.style={...n.style,opacity:0},e=!0);else if("rect"===n.type)s?(i.add(r),n._targetOpacity=n.style.opacity??1,s.x===n.x&&s.y===n.y&&s.w===n.w&&s.h===n.h||(n._targetX=n.x,n._targetY=n.y,n._targetW=n.w,n._targetH=n.h,n.x=s.x,n.y=s.y,n.w=s.w??n.w,n.h=s.h??n.h,e=!0)):(n._targetOpacity=n.style.opacity??1,n.style={...n.style,opacity:0},e=!0);else if("wedge"===n.type)if(s)i.add(r),n._targetOpacity=n.style.opacity??1,s.startAngle===n.startAngle&&s.endAngle===n.endAngle||(n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle,n.startAngle=s.startAngle,n.endAngle=s.endAngle,e=!0);else{n._targetOpacity=n.style.opacity??1,n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle;const t=n.startAngle;n.startAngle=t,n.endAngle=t,n.style={...n.style,opacity:0},this.prevPositionMap.set(r,{x:n.cx,y:n.cy,startAngle:t,endAngle:t,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,o]of this.prevPositionMap)if(!i.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:o.x,y:o.y,r:o.r??3,style:{opacity:o.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:o.x,y:o.y,w:o.w??0,h:o.h??0,style:{opacity:o.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((o.startAngle??0)+(o.endAngle??0))/2,i={type:"wedge",cx:o.x,cy:o.y,innerRadius:o.innerRadius??0,outerRadius:o.outerRadius??100,startAngle:o.startAngle??0,endAngle:o.endAngle??0,style:{opacity:o.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(i)}e=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),e&&(this.activeTransition={startTime:this.currentTime(),duration:t})}advanceTransition(t){if(!this.activeTransition)return!1;const e=To(t,this.activeTransition),i=Ro(e,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const t of this.scene){const e=t._transitionKey;if(e)if("point"===t.type){if(void 0!==t._targetOpacity){const o=this.prevPositionMap.get(e);t.style.opacity=Lo(o?o.opacity??1:0,t._targetOpacity,i)}const o=this.prevPositionMap.get(e);void 0!==t._targetX&&o&&(t.x=Lo(o.x,t._targetX,i),t.y=Lo(o.y,t._targetY,i)),void 0!==t._targetR&&void 0!==o?.r&&(t.r=Lo(o.r,t._targetR,i))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=this.prevPositionMap.get(e);t.style.opacity=Lo(o?o.opacity??1:0,t._targetOpacity,i)}if(void 0===t._targetX)continue;const o=this.prevPositionMap.get(e);if(!o)continue;t.x=Lo(o.x,t._targetX,i),t.y=Lo(o.y,t._targetY,i),void 0!==o.w&&(t.w=Lo(o.w,t._targetW,i),t.h=Lo(o.h,t._targetH,i))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const o=this.prevPositionMap.get(e);t.style={...t.style,opacity:Lo(o?o.opacity??1:0,t._targetOpacity,i)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const o=this.prevPositionMap.get(e);o&&void 0!==o.startAngle&&(t.startAngle=Lo(o.startAngle,t._targetStartAngle,i),t.endAngle=Lo(o.endAngle,t._targetEndAngle,i))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Po(t),i=this.getDataId,o=t=>e.has(i(t));Tn(this.buffer,this.timestampBuffer,o);const n=this.buffer.remove(o);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const i=Po(t),o=this.getDataId,n=new Set;this.buffer.forEach((t,e)=>{i.has(o(t))&&n.add(e)});const r=this.buffer.update(t=>i.has(o(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),n.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const i=this._customRestyle;if(i)for(const o of t){const t=this._baseStyles.get(o)??o.style??{},n=i(o,e);o.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();this._categoryIndexCache=null,this.buffer.forEach(t=>{this.categories.add(this.getO(t)),this.pushValueExtent(t)})}updateConfig(e){const i={...this.config},o=Object.keys(e).filter(t=>e[t]!==i[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==i.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${i.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==i.colorScheme||"themeCategorical"in e&&e.themeCategorical!==i.themeCategorical||"colorAccessor"in e&&!t(e.colorAccessor,i.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!t(e.categoryAccessor,i.categoryAccessor)||"oAccessor"in e&&!t(e.oAccessor,i.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let n=!1;("categoryAccessor"in e||"oAccessor"in e)&&(t(this.config.categoryAccessor||this.config.oAccessor,i.categoryAccessor||i.oAccessor)||(this.getO=a(this.config.categoryAccessor||this.config.oAccessor,"category"),n=!0));let s=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,o=i.valueAccessor||i.rAccessor,n=Array.isArray(e)?e:[e],a=Array.isArray(o)?o:[o];if(s=n.length!==a.length||n.some((e,i)=>!t(e,a[i])),s){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>r(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new So)):(this.getR=r(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!t(e.stackBy,i.stackBy)&&(this.getStack=null!=this.config.stackBy?a(this.config.stackBy):void 0),"groupBy"in e&&!t(e.groupBy,i.groupBy)&&(this.getGroup=null!=this.config.groupBy?a(this.config.groupBy):void 0),"colorAccessor"in e&&!t(e.colorAccessor,i.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?a(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!t(e.symbolAccessor,i.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?a(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!t(e.connectorAccessor,i.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?a(this.config.connectorAccessor):void 0),(n||s||"accessorRevision"in e&&e.accessorRevision!==i.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Fn(pa);import{jsx as ya,jsxs as ga}from"react/jsx-runtime";import{Fragment as ma,jsx as xa,jsxs as ba}from"react/jsx-runtime";function va(t,e){const i=_(t.theme),o=t.size||[500,400],n=Ts({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Rs(t.title),s=bo(t.data),a=t.showLegend?Dr(s,t.colorAccessor||t.stackBy||t.groupBy):[],c=t.legendPosition;go(t.legend)||mo(t.legend)?Es(n,{legend:t.legend,theme:i,position:c||"right",size:o,hasTitle:r,legendLayout:t.legendLayout}):t.showLegend&&a.length>0&&Ds(n,{categories:a,colorScheme:t.colorScheme,theme:i,position:c||"right",size:o,hasTitle:r,legendLayout:t.legendLayout});const l=o[0]-n.left-n.right,u=o[1]-n.top-n.bottom,h=t.projection||"vertical",d="radial"===h,f={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:t.gradientFill,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:t.colorScheme||i.colors.categorical,themeCategorical:i.colors.categorical,themeSemantic:g(i),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors},p=new pa(f);if(t.data&&p.ingest({inserts:s,bounded:!0}),p.computeScene({width:l,height:u}),!p.scales||0===p.scene.length)return e&&(e.evidence=yo({frameType:"ordinal",width:o[0],height:o[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:p.scales?[]:["NO_SCALES"]})),Xs.renderToStaticMarkup(Ns(null,{width:o[0],height:o[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:t._idPrefix}));if(e){const i=p.scales.o?.domain?.();e.evidence=yo({frameType:"ordinal",width:o[0],height:o[1],marks:p.scene,title:t.title,description:t.description,annotations:t.annotations,yDomain:po(p.scales.r?.domain?.()),categories:Array.isArray(i)?i.map(String):void 0})}const y=t._idPrefix,m=t.showGrid?function(t,e,i,o,n){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=P(i),a=o?o+"-":"",c="vertical"===r.projection,l=Ls(r.r,5,n);return Cs("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,i)=>{const o=r.r(t);return Cs("line",{x1:0,y1:o,x2:e.width,y2:o,stroke:s,strokeWidth:.5},"gr-"+i)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,i)=>{const o=r.r(t);return Cs("line",{x1:o,y1:0,x2:o,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+i)})})}(p,{width:l,height:u},i,y,t.axisExtent):null;let x=null;if(p.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=function(t){const e=t._idPrefix||t.chartId;if(e){const t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(t)?t:"c"+t}const i=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let o=0;for(let t=0;i.length>t;t++)o=31*o+i.charCodeAt(t)|0;return"c"+(o>>>0).toString(36)}(t),o=new Set;for(const t of p.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&o.add("string"==typeof t.style.fill?t.style.fill:"#666");x=Array.from(o).map((t,o)=>function(t){const{id:e,background:i="transparent",stroke:o="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return ga("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[i&&"transparent"!==i&&ya("rect",{width:a,height:a,fill:i}),ya("line",{x1:0,y1:0,x2:0,y2:a,stroke:o,strokeWidth:n}),ya("line",{x1:r,y1:0,x2:r,y2:a,stroke:o,strokeWidth:n})]},e)}({id:`funnel-hatch-${e}-${o}`,background:t,stroke:"transparent"===i.colors.background?"#fff":i.colors.background,lineWidth:1.5,spacing:5,angle:45}));const n=new Map;Array.from(o).forEach((t,i)=>n.set(t,`funnel-hatch-${e}-${i}`));for(const t of p.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${n.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const b=p.scene.map((e,i)=>Sr({node:e,index:i,renderMode:t.renderMode,fallback:()=>wr(e,i,y)})).filter(Boolean),v=!1!==t.showAxes?function(t,e,i,o,n){const r=t.scales;if(!r)return null;if("radial"===r.projection)return null;const s=P(o),a="vertical"===r.projection,c=i.categoryFormat||i.oFormat,l=i.valueFormat||i.rFormat,u=i.categoryLabel||i.oLabel,h=i.valueLabel||i.rLabel,d=Object.values(t.columns).map(t=>({pixel:t.middle,label:(c||String)(t.name)})),f=Ls(r.r,5,i.axisExtent).map(t=>({pixel:r.r(t),label:(l||Fs)(t)}));return ba("g",a?{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[xa("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),d.map((t,i)=>ba("g",{transform:`translate(${t.pixel},${e.height})`,children:[xa("line",{y2:5,stroke:s.border,strokeWidth:1}),xa("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+i)),u&&xa("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),xa("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,e)=>ba("g",{transform:`translate(0,${t.pixel})`,children:[xa("line",{x2:-5,stroke:s.border,strokeWidth:1}),xa("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),h&&xa("text",{x:15-(i.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(i.margin?.left??40)}, ${e.height/2})`,children:h})]}:{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[xa("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,i)=>ba("g",{transform:`translate(${t.pixel},${e.height})`,children:[xa("line",{y2:5,stroke:s.border,strokeWidth:1}),xa("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+i)),h&&xa("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:h}),xa("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),d.map((t,e)=>ba("g",{transform:`translate(0,${t.pixel})`,children:[xa("line",{x2:-5,stroke:s.border,strokeWidth:1}),xa("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),u&&xa("text",{x:15-(i.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(i.margin?.left??40)}, ${e.height/2})`,children:u})]})}(p,{width:l,height:u},t,i,y):null,w=t.annotations?_s({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{o:p.scales.o,r:p.scales.r,y:"vertical"===p.scales.projection?p.scales.r:void 0},layout:{width:l,height:u},theme:i,projection:h,idPrefix:y}):null,k=t.showLegend?0===a.length?null:zr({categories:a,colorScheme:t.colorScheme,theme:i,position:t.legendPosition||"right",totalWidth:o[0],totalHeight:o[1],margin:n,hasTitle:r,legendLayout:t.legendLayout}):null,S=Ys.isValidElement(t.legend)?t.legend:Is(t.legend,{theme:i,position:t.legendPosition||"right",size:o,margin:n,hasTitle:r,legendLayout:t.legendLayout,idPrefix:t._idPrefix})||k,A=d?n.left+l/2:n.left,M=d?n.top+u/2:n.top;return Xs.renderToStaticMarkup(Ns(ba(ma,{children:[t.backgroundGraphics,m,b,v,w,t.foregroundGraphics,p.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${A},${M})`,innerWidth:l,innerHeight:u,legend:S,defs:x,idPrefix:t._idPrefix}))}import*as wa from"react";import*as ka from"react-dom/server";function Sa(t,e){var i=t.get(e);if(!i)throw Error("missing: "+e);return i}function Aa(t,e){var i,o=[],n=[],r=[],s={},a=[];function c(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&c(e)})}function l(t){var e,o,h=!1;for(n.push(t),r[t]=!0,e=0;a[t].length>e;e++)(o=a[t][e])===i?(u(i,n),h=!0):r[o]||(h=l(o));if(h)c(t);else for(e=0;a[t].length>e;e++){var d=s[o=a[t][e]];d||(s[o]=d={}),d[o]=!0}return n.pop(),h}function u(t,i){var n=[].concat(i).concat(t);e?e(n):o.push(n)}function h(e){!function(e){for(var i=0;t.length>i;i++)i>=e&&t[i]||(t[i]=[]),t[i]=t[i].filter(function(t){return t>=e})}(e);for(var i,o=function(t){for(var e=t.length,i=Array(e),o=Array(e),n=Array(e),r=Array(e),s=Array(e),a=Array(e),c=0;e>c;++c)i[c]=-1,o[c]=0,n[c]=!1,r[c]=0,s[c]=-1,a[c]=[];var l,u=0,h=[],d=[];function f(e){var c=[e],l=[e];for(i[e]=o[e]=u,n[e]=!0,u+=1;l.length>0;){var f=t[e=l[l.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>i[y]){i[y]=o[y]=u,n[y]=!0,u+=1,c.push(y),l.push(y);break}n[y]&&(o[e]=0|Math.min(o[e],o[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(o[e]===i[e]){var g=[],m=[],x=0;for(p=c.length-1;p>=0;--p){var b=c[p];if(n[b]=!1,g.push(b),m.push(a[b]),x+=a[b].length,s[b]=h.length,b===e){c.length=p;break}}h.push(g);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];d.push(v)}l.pop()}}}for(c=0;e>c;++c)0>i[c]&&f(c);for(c=0;d.length>c;c++){var p=d[c];if(0!==p.length){p.sort(function(t,e){return t-e}),l=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&l.push(p[y]);d[c]=l}}return{components:h,adjacencyList:d}}(t),n=o.components.filter(function(t){return t.length>1}),r=1/0,s=0;n.length>s;s++)for(var a=0;n[s].length>a;a++)r>n[s][a]&&(r=n[s][a],i=s);var c=n[i];return!!c&&{leastVertex:r,adjList:t.map(function(t,e){return-1===c.indexOf(e)?[]:t.filter(function(t){return-1!==c.indexOf(t)})})}}i=0;for(var d=t.length;d>i;){var f=h(i);if(i=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var y=0;a[p].length>y;y++){var g=a[p][y];r[+g]=!1,s[g]={}}l(i),i+=1}else i=d}return e?void 0:o}function Ma(t){return t.y0-t.y1>0?"up":"down"}function _a(t,e){return e(t.source)==e(t.target)}function Pa(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var i=0;return t.target.targetLinks.forEach(function(t){i=t.circular?i+1:i}),1>=e&&1>=i}function Ra(t){return t.target.x0-t.source.x1}function Ta(t,e){var i=Ca(t),o=Ra(e)/Math.tan(i);return"up"==Ma(t)?t.y1-o:t.y1+o}function La(t,e){var i=Ca(t),o=Ra(e)/Math.tan(i);return"up"==Ma(t)?t.y1+o:t.y1-o}function Ca(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function $a(t,e){return e(t)}function za(t){return Ea(t.source)}function Da(t){return Ea(t.target)}function Ea(t){return(t.y0+t.y1)/2}function Ia(t){return t.virtual?0:t.value}function Fa(t,e){var i=0;t.sourceLinks.forEach(function(t){i=t.circular&&!_a(t,e)?i+1:i});var o=0;return t.targetLinks.forEach(function(t){o=t.circular&&!_a(t,e)?o+1:o}),i+o}function Na(t){return t.target.depth}function Ba(t,e){return t.sourceLinks.length?t.depth:e-1}function Oa(t,e){return t.y0-e.y0}function Wa(t,e){return e.y0-t.y0}function ja(t,e){return t.y1-e.y1}function Ya(t,e){return e.y1-t.y1}function Xa(t,e){return Ga(t.source,e.source)||t.index-e.index}function qa(t,e){return Ga(t.target,e.target)||t.index-e.index}function Ga(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Va(t,e){return Ha(t)==Ha(e)?"bottom"==t.circularLinkType?Wa(t,e):Oa(t,e):Ha(e)-Ha(t)}function Ha(t){return t.target.column-t.source.column}function Za(t,e){return Ka(t)==Ka(e)}function Ka(t){return t.y0-t.y1>0?"up":"down"}import{min as Ua}from"d3-array";function Qa(t,e,i,o,n){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=Ua(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var c=r.links.filter(function(t){return t.circular});return c.sort(function(t,e){return e.value-t.value}),c.forEach(function(t,e){t._circularStub=e>=4}),Ja(r.links.filter(function(t){return"top"==t.circularLinkType}),e,i),Ja(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,i),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+o,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,_a(t,e)&&Pa(t))t.circularPathData.rightSmallArcRadius=o+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=o+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=o+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=o+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,c=t.circularLinkType,l=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==c});l.sort("bottom"==t.circularLinkType?Wa:Oa);var u=0;l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=o+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=o+t._circularWidth/2+n*i+u),u+=e._circularWidth||e.width}),s=t.target.column,(l=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==c})).sort("bottom"==t.circularLinkType?Ya:ja),u=0,l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=o+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=o+t._circularWidth/2+n*i+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,i=t.y0,o=t.target.x0,n=t.y1,r=(e+o)/2;return"M"+e+","+i+"C"+r+","+i+" "+r+","+n+" "+o+","+n}(t)}),r}function Ja(t,e,i){t.sort(Va);var o=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,n){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(_a(t,e)&&Pa(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;o.length>s;s++){var a=o[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&tc(t,a)){var c=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+i;r=c>r?c:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function tc(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as ec,max as ic,sum as oc,mean as nc,group as rc,groups as sc}from"d3-array";function ac(t){return function(){return t}}function cc(t){return t.index}function lc(t){return t.nodes}function uc(t){return t.links}function hc(t,e,i){var o=sc(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});o.forEach(function(n,r){var s=n.length;if(e)n.sort(e);else if(r>0){var a=new Map;n.forEach(function(t,e){var i,o,n,r=(o=0,n=0,(i=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=Ea(t.source)*e,o+=e}}),i.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=Ea(t.target)*e,o+=e}}),o>0?n/o:NaN);a.set(t,{bc:r,idx:e})}),n.sort(function(t,e){var i=a.get(t),o=a.get(e),n=i.bc,r=o.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(n)||isNaN(r)?isNaN(n)?isNaN(r)?i.idx-o.idx:1:-1:n-r})}else n.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Fa(e,i)-Fa(t,i):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});n.forEach(function(e,n){e.depth==o.length-1&&1==s||0==e.depth&&1==s?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==Fa(e,i)?(e.y0=t.y1/2+n,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+n,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-n,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*n,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+n,e.y1=e.y0+e.value*t.ky)})})}function dc(t,e,i,o,n,r){var s=sc(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,c=r;c>0;--c)l(a*=.99,i),u();function l(e,i){var o=s.length;s.forEach(function(n){var r=n.length,s=n[0].depth;n.forEach(function(n){var a;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&Fa(n,i)>0){var c=nc(n.sourceLinks,Da),l=nc(n.targetLinks,za),u=c&&l?(c+l)/2:c||l;if(u){var h=(u-Ea(n))*e*.3;n.y0+=h,n.y1+=h}}else if(0==s&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(s==o-1&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)a=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+a;else{var d=nc(n.sourceLinks,Da),f=nc(n.targetLinks,za),p=((d&&f?(d+f)/2:d||f)-Ea(n))*e;n.y0+=p,n.y1+=p}})})}function u(){s.forEach(function(i){var r,s,a,c=t.y0,l=i.length;for(i.sort(e||Ga),a=0;l>a;++a)(s=c-(r=i[a]).y0)>0&&(r.y0+=s,r.y1+=s),c=r.y1+o;if((s=c-o-t.y1)>0)for(c=r.y0-=s,r.y1-=s,a=l-2;a>=0;--a)(s=(r=i[a]).y1+n-c)>0&&(r.y0-=s,r.y1-=s),c=r.y0})}}function fc(t){t.nodes.forEach(function(t){t.sourceLinks.sort(qa),t.targetLinks.sort(Xa)}),t.nodes.forEach(function(t){var e=t.y0,i=e,o=t.y1,n=o;t.sourceLinks.forEach(function(t){t.circular?(t.y0=o-t.width/2,o-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=n-t.width/2,n-=t.width):(t.y1=i+t.width/2,i+=t.width)})})}function pc(){var t=0,e=0,i=1,o=1,n=24,r=8,s=null,a=cc,c=Ba,l=void 0,u=32,h=2,d=lc,f=uc;function p(){var p={nodes:d.apply(null,arguments),links:f.apply(null,arguments)};return function(d){d.x0=t,d.y0=e,d.x1=i,d.y1=o,d.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var i=function(t,e){var i=new Map;return rc(t,e).forEach(function(t,e){i.set(e,t[0])}),i}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var o=t.source,n=t.target;"object"!=typeof o&&(o=t.source=Sa(i,o)),"object"!=typeof n&&(n=t.target=Sa(i,n)),o.sourceLinks.push(t),n.targetLinks.push(t)})}(d,a),function(t,e){var i=0;if(null==e){for(var o=[],n=0;t.links.length>n;n++){var r=t.links[n],s=r.source.index,a=r.target.index;o[s]||(o[s]=[]),o[a]||(o[a]=[]),-1===o[s].indexOf(a)&&o[s].push(a)}var c=Aa(o);c.sort(function(t,e){return t.length-e.length});var l={};for(n=0;c.length>n;n++){var u=c[n].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,o=t.source.index;e===o||l[o]&&l[o][e]?(t.circular=!0,t.circularLinkID=i++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=i++)})}(d,l),function(t,e){var i=0,o=0;t.links.forEach(function(n){n.circular&&(n.circularLinkType=n.source.circularLinkType||n.target.circularLinkType?n.source.circularLinkType?n.source.circularLinkType:n.target.circularLinkType:o>i?"top":"bottom","top"==n.circularLinkType?i++:o++,t.nodes.forEach(function(t){$a(t,e)!=$a(n.source,e)&&$a(t,e)!=$a(n.target,e)||(t.circularLinkType=n.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),_a(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(d,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(oc(t.sourceLinks,Ia),oc(t.targetLinks,Ia)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(d),function(t,e,i){var o,n,r;if(null!=e){t.nodes.sort(function(t,i){return e(t)<e(i)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(o=t.nodes,n=[],r=0;o.length;++r,o=n,n=[])o.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>n.indexOf(t.target)&&!t.circular&&n.push(t.target)})});for(o=t.nodes,n=[],r=0;o.length;++r,o=n,n=[])o.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>n.indexOf(t.source)&&!t.circular&&n.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?i(t,r):t.column})}(d,l,c);var f=r;if(null!==s){var p=sc(d.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=ic(p,function(t){return t.length});y>1&&(f=Math.max(1,(o-e)*s/(y-1)))}(function(t,e,i){var o=sc(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var n=ec(o,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/oc(e,function(t){return t.value})});t.ky=n,t.links.forEach(function(e){e.width=e.value*t.ky});var r=ic(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-i)/r),e.x1=e.x0+i}:function(e){e.x0=t.x0,e.x1=e.x0+i})})(d,f,n),hc(d,l,a),dc(d,l,a,f,f,u),fc(d),Qa(d,a,h,10,8),hc(d,l,a),dc(d,l,a,f,f,u),fc(d),Qa(d,a,h,10,8),function(t,e){let i=t;i.nodes.forEach(function(t){t.y+(t.y1-t.y0)>i.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-i.y1));var o=i.links.filter(function(i){return $a(i.source,e)==$a(t,e)}),n=o.length;n>1&&o.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!Za(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var i=Ta(e,t);return t.y1-i}if(e.target.column>t.target.column)return Ta(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;o.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),o.forEach(function(e,i){if("bottom"==e.circularLinkType){for(var r=i+1,s=0;n>r;r++)s+=o[r].width;e.y0=t.y1-s-e.width/2}})})}(d,a),function(t,e){let i=t;i.nodes.forEach(function(t){var o=i.links.filter(function(i){return $a(i.target,e)==$a(t,e)}),n=o.length;n>1&&o.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!Za(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var i=La(e,t);return t.y0-i}if(e.source.column>t.source.column)return La(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;o.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),o.forEach(function(e,i){if("bottom"==e.circularLinkType){for(var r=i+1,s=0;n>r;r++)s+=o[r].width;e.y1=t.y1-s-e.width/2}})})}(d,a),function(t){var e=t.nodes,i=t.links,o=!1,n=!1;if(i.forEach(function(t){"top"==t.circularLinkType?o=!0:"bottom"==t.circularLinkType&&(n=!0)}),0==o||0==n){let o=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=ec(e,function(t){return t.y0}),s=ic(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=o(t.y0),t.y1=o(t.y1)}),i.forEach(function(t){t.y0=o(t.y0),t.y1=o(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,i=o(t.y0)-t.y0;t.y0=o(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+i}),t.targetLinks.forEach(function(t){t.y1=t.y1+i})})}}(d),Qa(d,a,h,10,8)}(p),p}return p.update=function(t){return fc(t),Qa(t,a,h,10,8),t},p.nodeWidth=function(t){return arguments.length?(n=+t,p):n},p.nodePadding=function(t){return arguments.length?(r=+t,p):r},p.nodePaddingRatio=function(t){return arguments.length?(s=+t,p):s},p.nodes=function(t){return arguments.length?(d="function"==typeof t?t:ac(t),p):d},p.links=function(t){return arguments.length?(f="function"==typeof t?t:ac(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:ac(t),p):a},p.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:ac(t),p):c},p.nodeSort=function(t){return arguments.length?(l=t,p):l},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(h=+t,p):h},p.extent=function(n){return arguments.length?(t=+n[0][0],e=+n[0][1],i=+n[1][0],o=+n[1][1],p):[[t,e],[i,o]]},p.size=function(n){return arguments.length?(t=e=0,i=+n[0],o=+n[1],p):[i-t,o-e]},p}import{interpolateNumber as yc}from"d3-interpolate";import{line as gc,curveLinearClosed as mc}from"d3-shape";var xc=t=>{let e,i,o,n,r,s,a,c,l;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,i=t.y1-t.sankeyWidth/2,o=t.y1+t.sankeyWidth/2,n=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=yc(r,s),c=a(.5),l=a(.5),`M${e},${r}C${e},${c} ${i},${l} ${i},${s}L${o},${s}C${o},${l} ${n},${c} ${n},${r}Z`;const u=t.sankeyWidth/2,h=yc(t.source.x1,t.target.x0),{pathD:d}=Ht({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:h(.5),cp2X:h(.5)});return d};function bc(t){const e=t.sankeyWidth/2,i=(t._circularWidth??t.sankeyWidth)/2,o=t.circularPathData;if(!o)return null;if("down"===t.direction)return null;if(t._circularStub){const i=o.sourceX,n=o.sourceY,r=o.targetX,s=o.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const a=Math.max(15,Math.min(40,.33*(o.rightFullExtent-i))),c=Math.max(15,Math.min(40,.33*(r-o.leftFullExtent)));return`M${i},${n-e}L${i+a},${n-e}L${i+a},${n+e}L${i},${n+e}ZM${r},${s-e}L${r-c},${s-e}L${r-c},${s+e}L${r},${s+e}Z`}const n=o.sourceX,r=o.sourceY,s=o.targetX,a=o.targetY,c=o.rightFullExtent,l=o.leftFullExtent,u=o.verticalFullExtent,h="bottom"===t.circularLinkType?1:-1,d=Math.max(4,Math.min(i,15));return`M${n},${r-h*e}L${c},${r-h*e}L${c+i},${r-h*e+h*d}L${c+i},${u+h*i-h*d}L${c+i-d},${u+h*i}L${l-i+d},${u+h*i}L${l-i},${u+h*i-h*d}L${l-i},${a-h*e+h*d}L${l-i+d},${a-h*e}L${s},${a-h*e}L${s},${a+h*e}L${l+i},${a+h*e}L${l+i},${u-h*i}L${c-i},${u-h*i}L${c-i},${r+h*e}L${n},${r+h*e}Z`}var vc=new Set,wc=new WeakMap;function kc(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let i=wc.get(t);if(i){const t=i.get(e);if(t)return t}else i=new Map,wc.set(t,i);const o=new Proxy(t,{get(t,i,o){if("string"==typeof i&&!(i in t)&&t.data&&i in t.data){const t=`${e}:${i}`;vc.has(t)||(vc.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${i}" on the wrapper object, but it only exists on ".data". Use d.data.${i} (or d.data?.${i}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,i,o)}});return i.set(e,o),o}var Sc={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(Na))-1:0},justify:Ba};function Ac(t){return"string"==typeof t?t:t.id}var Mc={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,i,o){if(0===t.length)return;const n="vertical"===i.orientation?"down":"right",r=i.nodeAlign||"justify",s=i.nodeWidth??15,a=i.nodePaddingRatio??.05,c=i.iterations??100,l=t.map(t=>({...t})),u=e.map(t=>({...t,source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id,value:Math.sqrt(Math.max(1,t.value||1))}));let h;h="down"===n?[[0,0],[o[1],o[0]]]:[[0,0],[o[0],o[1]]];const d=pc().extent(h).links(u).nodes(l).nodeAlign(Sc[r]||Ba).nodeId(t=>t.id).nodeWidth(s).iterations(c);d.nodePaddingRatio&&d.nodePaddingRatio(a),d();{let t=1/0,e=-1/0,i=1/0,n=-1/0;for(const o of l)t>o.x0&&(t=o.x0),o.x1>e&&(e=o.x1),i>o.y0&&(i=o.y0),o.y1>n&&(n=o.y1);for(const o of u){if(!o.circular||!o.circularPathData)continue;const r=o.circularPathData,s=(o._circularWidth??o.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),i>r.verticalFullExtent-s&&(i=r.verticalFullExtent-s),r.verticalFullExtent+s>n&&(n=r.verticalFullExtent+s)}const r=e-t,s=n-i,a=o[0],c=o[1];if(r>0&&s>0&&(0>t||0>i||e>a||n>c)){const e=Math.min(a/r,c/s),o=-t*e+(a-r*e)/2,n=-i*e+(c-s*e)/2;for(const t of l)t.x0=t.x0*e+o,t.x1=t.x1*e+o,t.y0=t.y0*e+n,t.y1=t.y1*e+n;for(const t of u)if(t.y0=t.y0*e+n,t.y1=t.y1*e+n,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const i=t.circularPathData;i.sourceX=i.sourceX*e+o,i.targetX=i.targetX*e+o,i.sourceY=i.sourceY*e+n,i.targetY=i.targetY*e+n,i.rightFullExtent=i.rightFullExtent*e+o,i.leftFullExtent=i.leftFullExtent*e+o,i.verticalFullExtent=i.verticalFullExtent*e+n,i.rightInnerExtent=i.rightInnerExtent*e+o,i.leftInnerExtent=i.leftInnerExtent*e+o,i.verticalRightInnerExtent=i.verticalRightInnerExtent*e+n,i.verticalLeftInnerExtent=i.verticalLeftInnerExtent*e+n,i.rightSmallArcRadius*=e,i.rightLargeArcRadius*=e,i.leftSmallArcRadius*=e,i.leftLargeArcRadius*=e,i.sourceWidth*=e,i.rightNodeBuffer*=e,i.leftNodeBuffer*=e,i.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of l){const e=f.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const p=new Map;for(const t of e)p.set(t._edgeKey?t._edgeKey:`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const t of u){const e=Ac(t.source),i=Ac(t.target),o=p.get(t._edgeKey?t._edgeKey:`${e}\0${i}`);if(o){o.y0=t.y0,o.y1=t.y1,o.sankeyWidth=t.width??0,o.circular=!!t.circular,o.circularPathData=t.circularPathData,o._circularWidth=t._circularWidth,o._circularStub=t._circularStub,o.path=t.path,o.circularLinkType=t.circularLinkType,o.direction=n;const r=f.get(e),s=f.get(i);r&&(o.source=r),s&&(o.target=s)}}},buildScene(t,e,i,o){const n="vertical"===i.orientation?"down":"right",r=i.nodeStyle,s=i.edgeStyle,a=i.edgeOpacity??.5,c=i.edgeColorBy||"source",l=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:D,u=new Map;t.forEach((t,e)=>{u.set(t.id,l[e%l.length])});const h=[],d=[],f=[],p=new Map;for(const e of t){const t=e.x1-e.x0,i=e.y1-e.y0;if(0>=t||0>=i)continue;const o=r?r(kc(e,"nodeStyle")):{},s={fill:o.fill||u.get(e.id)||"#4d430c",stroke:o.stroke,strokeWidth:o.strokeWidth,opacity:o.opacity};p.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),h.push("down"===n?{type:"rect",x:e.y0,y:e.x0,w:i,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:i,style:s,datum:e,id:e.id,label:e.id})}const y=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of y){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;if(!e||!o)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof c?c(t)||n:"target"===c?p.get(o.id)||u.get(o.id)||n:p.get(e.id)||u.get(e.id)||n;const r=s?s(kc(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,i=t.sankeyWidth/2,o=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),c=r.fill||n;d.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-i}L${e.sourceX+o},${e.sourceY-i}L${e.sourceX+o},${e.sourceY+i}L${e.sourceX},${e.sourceY+i}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+o}}),d.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-i}L${e.targetX-s},${e.targetY-i}L${e.targetX-s},${e.targetY+i}L${e.targetX},${e.targetY+i}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let l;(l=t.circular&&t.circularPathData?bc(t):xc(t),l)&&d.push({type:"bezier",pathD:l,bezierCache:t.bezier,style:{fill:r.fill||n,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity},datum:t})}if(!1!==i.showLabels){const e=(g=i.nodeLabel)?"function"==typeof g?g:t=>t[g]||t.id:null;for(const i of t){const t=i.x1-i.x0,r=i.y1-i.y0;if(0>=t||0>=r)continue;const s=e?e(i):i.id;if(!s)continue;let a,c,l;"down"===n?(a=i.y0+(i.y1-i.y0)/2,c=i.x1+14,l="start"):(o[0]/2>i.x0+t/2?(a=i.x0-6,l="end"):(a=i.x1+6,l="start"),c=i.y0+r/2),f.push({x:a,y:c,text:s+"",anchor:"down"===n?"middle":l,baseline:"middle",fontSize:11})}}var g;return{sceneNodes:h,sceneEdges:d,labels:f}}};import{forceSimulation as _c,forceCenter as Pc,forceX as Rc,forceY as Tc,forceLink as Lc,forceManyBody as Cc,forceCollide as $c}from"d3-force";import{scaleLinear as zc}from"d3-scale";var Dc={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,i,o){if(0===t.length)return;const n=i.forceStrength??.1,r=o[0]/2,s=o[1]/2,a=i.__previousPositions;let c=0;const l=[];for(const e of t){const t=null!=e.x&&null!=e.y&&(0!==e.x||0!==e.y),i=a?.get(e.id);t?c++:i?(e.x=i.x,e.y=i.y,c++):l.push(e)}const u=c>0&&.3>=(t.length>0?l.length/t.length:1);if(u){const i=new Map;for(const e of t)i.set(e.id,e);for(const t of l){const o=Ec(t.id,e,i);if(o.length>0){let e=0,i=0;for(const t of o)e+=t.x,i+=t.y;const n=Ic(t.id),r=n%360*(Math.PI/180),s=10+n%20;t.x=e/o.length+s*Math.cos(r),t.y=i/o.length+s*Math.sin(r)}else{const e=Ic(t.id),i=e%360*(Math.PI/180),o=15+e%30;t.x=r+o*Math.cos(i),t.y=s+o*Math.sin(i)}}}else{const e=2.399963229728653;for(let i=0;t.length>i;i++){const o=t[i];if(null==o.x||null==o.y||0===o.x&&0===o.y){const t=10*Math.sqrt(i+.5),n=i*e;o.x=r+t*Math.cos(n),o.y=s+t*Math.sin(n)}}}const h=i.__skipForceSimulation||0===i.iterations?0:u?40:i.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),d=Fc(i.nodeSize,i.nodeSizeRange,t),f=t=>d(t);if(h>0){const o=new Map,a=new Map;for(const e of t)o.set(e.id,0),a.set(e.id,e);for(const t of e){const e="string"==typeof t.source?t.source:t.source.id,i="string"==typeof t.target?t.target:t.target.id;o.set(e,(o.get(e)??0)+1),o.set(i,(o.get(i)??0)+1)}const c=Lc().strength(t=>{const e=t.weight,i="string"==typeof t.target?t.target:t.target.id,r=Math.max(1,Math.min(o.get("string"==typeof t.source?t.source:t.source.id)??1,o.get(i)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*n/(.1*r))}).distance(t=>{const e="string"==typeof t.source?a.get(t.source):t.source,i="string"==typeof t.target?a.get(t.target):t.target,o=(e?f(e):0)+(i?f(i):0)+12;return Math.max(40,o)}).id(t=>t.id),l=_c();if(void 0===i.random&&void 0===i.seed||l.randomSource(i.random??function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(i.seed)),l.force("charge",Cc().strength(t=>{const e=o.get(t.id)??0;return-15*f(t)*Math.sqrt(e+1)})).force("collide",$c(t=>f(t)+3).strength(.9).iterations(2)).force("center",Pc(r,s).strength(.8)).force("x",Rc(r).strength(.06)).force("y",Tc(s).strength(.06)),l.nodes(t),e.length>0){const t=e.map(t=>({...t,source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id}));c.links(t),l.force("link",c)}u?l.alpha(.3):.1>l.alpha()&&l.alpha(1),l.stop();for(let t=0;h>t;++t)l.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=f(e);e.x=Math.max(t,Math.min(o[0]-t,e.x)),e.y=Math.max(t,Math.min(o[1]-t,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const p=new Map;for(const e of t)p.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=p.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=p.get(t.target);e&&(t.target=e)}}},buildScene(t,e,i,o){const n=i.nodeStyle,r=i.edgeStyle,s=Fc(i.nodeSize,i.nodeSizeRange,t),a=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:D,c=new Map;t.forEach((t,e)=>{c.set(t.id,a[e%a.length])});const l=[],u=[],h=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(kc(e,"nodeSize")),o=n?n(kc(e,"nodeStyle")):{},r={fill:o.fill||c.get(e.id)||i.themeSemantic?.primary||"#007bff",stroke:o.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??2,opacity:o.opacity};l.push({type:"circle",cx:e.x,cy:e.y,r:t,style:r,datum:e,id:e.id,label:e.id})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==e.y)continue;if(null==o.x||null==o.y)continue;const n=r?r(kc(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6},datum:t})}if(!1!==i.showLabels){const e=(f=i.nodeLabel)?"function"==typeof f?f:t=>t[f]||t.id:null;for(const i of t){if(null==i.x||null==i.y)continue;const t=e?e(i):i.id;if(!t)continue;const o=s(kc(i,"nodeSize"));h.push({x:i.x,y:i.y-o-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}var f;return{sceneNodes:l,sceneEdges:u,labels:h}}};function Ec(t,e,i){const o=[];for(const n of e){const e="string"==typeof n.source?n.source:n.source.id,r="string"==typeof n.target?n.target:n.target.id;let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=i.get(s);!t||0===t.x&&0===t.y||o.push({x:t.x,y:t.y})}}return o}function Ic(t){let e=0;for(let i=0;t.length>i;i++)e=(e<<5)-e+t.charCodeAt(i)|0;return Math.abs(e)}function Fc(t,e,i){if(i.some(t=>null!=t.__forceRadius))return t=>t.__forceRadius??8;if(null==t)return()=>8;if("number"==typeof t)return()=>t;if("function"==typeof t)return e=>t(e)||8;const o=e||[5,20],n=[];for(const e of i){const i=e.data?.[t];"number"==typeof i&&n.push(i)}if(0===n.length)return()=>o[0];const[r,s]=Et(n);if(r===s)return()=>(o[0]+o[1])/2;const a=zc().domain([r,s]).range(o).clamp(!0);return e=>{const i=e.data?.[t];return null==i||"number"!=typeof i?o[0]:a(i)}}import{chord as Nc,ribbon as Bc}from"d3-chord";import{arc as Oc}from"d3-shape";var Wc=D,jc={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,i,o){if(0===t.length)return;const{padAngle:n=.01,groupWidth:r=20,sortGroups:s}=i,a=Math.min(o[0],o[1])/2,c=a-r,l=o[0]/2,u=o[1]/2,h=(d=i.valueAccessor)?"function"==typeof d?d:t=>t[d]??1:t=>t.value??1;var d;const f=new Map;for(let e=0;t.length>e;e++)f.set(t[e].id,e);const p=t.length,y=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,i=f.get("string"==typeof t.source?t.source:t.source.id),o=f.get(e);if(void 0===i||void 0===o)continue;const n=h(t);y[i][o]=n}const g=Nc().padAngle(n);s&&g.sortGroups(s);const m=g(y),x=m.groups,b=Oc().innerRadius(c).outerRadius(a);for(const e of x){const i=t[e.index],o=b.centroid({innerRadius:c,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});i.x=o[0]+l,i.y=o[1]+u,i.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,i=v.get("string"==typeof t.source?t.source:t.source.id),o=v.get(e);i&&(t.source=i),o&&(t.target=o)}const w=new Map;for(const t of e)w.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const e of m){const i=t[e.source.index].id,o=t[e.target.index].id,n=w.get(`${i}\0${o}`)||w.get(`${o}\0${i}`);n&&(n.__chordData=e)}},buildScene(t,e,i,o){const{groupWidth:n=20,edgeOpacity:r=.5}=i,s=Math.min(o[0],o[1])/2,a=s-n,c=o[0]/2,l=o[1]/2,u=i.nodeStyle,h=i.edgeStyle,d=i.edgeColorBy||"source",f=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Wc,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=Bc().radius(a),g=[],m=[],x=[];for(let e=0;t.length>e;e++){const i=t[e],o=i.__arcData;if(!o)continue;let n;n=u?u(kc(i,"nodeStyle")).fill||p.get(i.id)||f[e%f.length]:p.get(i.id)||f[e%f.length];const r=u?u(kc(i,"nodeStyle")):{};g.push({type:"arc",cx:c,cy:l,innerR:a,outerR:s,startAngle:o.startAngle-Math.PI/2,endAngle:o.endAngle-Math.PI/2,style:{fill:n,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:i,id:i.id,label:i.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const o=y(e);if(!o)continue;const n=Yc(o,c,l);let s=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";if(h)s=h(kc(t,"edgeStyle")).fill||s;else{const e="object"==typeof t.source?t.source:null,i="object"==typeof t.target?t.target:null;"target"===d&&i?s=p.get(i.id)||s:e&&(s=p.get(e.id)||s)}const a=h?h(kc(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:n,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity},datum:t})}if(!1!==i.showLabels){const e=(b=i.nodeLabel)?"function"==typeof b?b:t=>t[b]||t.id:null,o=s+12;for(const i of t){const t=i.__arcData;if(!t)continue;const n=e?e(i):i.id;if(!n)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:c+Math.cos(s)*o,y:l+Math.sin(s)*o,text:n+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}var b;return{sceneNodes:g,sceneEdges:m,labels:x}}};function Yc(t,e,i){const o=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!o)return t;const n=[];let r=0;for(;o.length>r;){const t=o[r];if("M"===t||"L"===t)for(n.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)n.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(n.push(Number(o[r])+i+""),r++);else if("C"===t)for(n.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)for(let t=0;3>t&&o.length>r&&!isNaN(Number(o[r]));t++)n.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(n.push(Number(o[r])+i+""),r++);else if("Q"===t)for(n.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)for(let t=0;2>t&&o.length>r&&!isNaN(Number(o[r]));t++)n.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(n.push(Number(o[r])+i+""),r++);else if("A"===t)for(n.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)n.push(o[r++]),o.length>r&&n.push(o[r++]),o.length>r&&n.push(o[r++]),o.length>r&&n.push(o[r++]),o.length>r&&n.push(o[r++]),o.length>r&&(n.push(Number(o[r])+e+""),r++),o.length>r&&(n.push(Number(o[r])+i+""),r++);else"Z"===t||"z"===t?(n.push(t),r++):(n.push(o[r]),r++)}return n.join(" ")}import{hierarchy as Xc,tree as qc,cluster as Gc,treemap as Vc,pack as Hc,partition as Zc,treemapBinary as Kc}from"d3-hierarchy";var Uc=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Qc(t){const[e,i,o]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(t);return.299*e+.587*i+.114*o>150?"#222":"#fff"}function Jc(t,e,i){const o=e.nodeIDAccessor;return"function"==typeof o?o(t.data)+"":"string"==typeof o&&void 0!==t.data[o]?t.data[o]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+i}function tl(t){if(!t)return null;if("function"==typeof t){const e=t;return t=>e(t.data??t)}return e=>e.data?.[t]||e[t]||e.id}function el(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Uc}function il(t){return Array.isArray(t.colorScheme)&&t.colorScheme.length>0?t.colorScheme[0]:t.themeSemantic?.primary?t.themeSemantic.primary:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical[0]:"#4d430c"}function ol(t,e,i,o,n){if("horizontal"===n){const n=(t+i)/2;return`M ${t},${e} C ${n},${e} ${n},${o} ${i},${o}`}if("radial"===n){const n=(t+i)/2;return`M ${t},${e} Q ${n},${e} ${n},${(e+o)/2} T ${i},${o}`}{const n=(e+o)/2;return`M ${t},${e} C ${t},${n} ${i},${n} ${i},${o}`}}var nl={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,i,o){const n=i.__hierarchyRoot;if(!n)return;const r=i.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(i.childrenAccessor),a=i.hierarchySum,c="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,l=Xc(n,s);l.sum(c),l.sort((t,e)=>(e.value??0)-(t.value??0));const[u,h]=o;switch(r){case"tree":!function(t,e,i,o){const n=e.treeOrientation||"vertical",r=qc();r.size("horizontal"===n?[o,i]:"radial"===n?[2*Math.PI,Math.min(i,o)/2*.8]:[i,o]),r(t)}(l,i,u,h);break;case"cluster":!function(t,e,i,o){const n=e.treeOrientation||"vertical",r=Gc();r.size("horizontal"===n?[o,i]:"radial"===n?[2*Math.PI,Math.min(i,o)/2*.8]:[i,o]),r(t)}(l,i,u,h);break;case"treemap":!function(t,e,i,o){const n=e.padding??4,r=e.paddingTop??0,s=Vc().size([i,o]).tile(Kc).padding(n);r>0&&s.paddingTop(r),s(t)}(l,i,u,h);break;case"circlepack":!function(t,e,i,o){const n=e.padding??4;Hc().size([i,o]).padding(n)(t)}(l,i,u,h);break;case"partition":!function(t,e,i,o){Zc().size([i,o]).padding(e.padding??1)(t)}(l,i,u,h)}const d=l.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;d.length>e;e++){const o=d[e],n={id:Jc(o,i,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:o.value??0,depth:o.depth,data:o.data,createdByFrame:!0};"tree"===r||"cluster"===r?rl(n,o,i):"treemap"===r||"partition"===r?sl(n,o):"circlepack"===r&&al(n,o),n.__hierarchyNode=o,t.push(n),f.set(o,n)}if("tree"===r||"cluster"===r)for(const t of d)if(t.parent){const i=f.get(t.parent),o=f.get(t);i&&o&&e.push({source:i,target:o,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,i,o){const n=i.nodeStyle||(()=>({})),r=i.edgeStyle||(()=>({}));switch(i.chartType){case"tree":case"cluster":return function(t,e,i,o,n,r){const s=[],a=[],c=[],l=i.treeOrientation||"vertical",u="radial"===l,h=o[0]/2,d=o[1]/2,f="number"==typeof(p=i.nodeSize)?p:5;var p;for(const e of t){let t=e.x,o=e.y;u&&(t+=h,o+=d);const r=n(kc(e,"nodeStyle"));let a=r.fill||il(i);if(i.colorByDepth&&void 0!==e.depth){const t=el(i);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:o,r:f,style:{fill:a,stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:e,id:e.id,label:e.id,depth:e.depth})}const y=i.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;if(!e||!o)continue;let n=e.x,s=e.y,c=o.x,f=o.y;u&&(n+=h,s+=d,c+=h,f+=d);const p=ol(n,s,c,f,l),g=r(kc(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y},datum:t})}if(!1!==i.showLabels){const e=tl(i.nodeLabel);for(const i of t){const t=e?e(i):i.id;if(!t)continue;let o,n,r,s=i.x,a=i.y;if(u&&(s+=h,a+=d),u){const t=s-h,e=a-d,i=Math.sqrt(t*t+e*e);i>0?(o=s+t/i*10,n=a+e/i*10,r=0>t?"end":"start"):(o=s,n=a-12,r="middle")}else"horizontal"===l?(i.data?.children&&0!==i.data.children.length?(o=s-f-6,r="end"):(o=s+f+6,r="start"),n=a):(o=s,n=a+f+14,r="middle");c.push({x:o,y:n,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:c}}(t,e,i,o,n,r);case"treemap":case"partition":return function(t,e,i,o){const n=[],r=[];for(const i of t){const t=i.x1-i.x0,r=i.y1-i.y0;if(0>=t||0>=r)continue;const s=o(kc(i,"nodeStyle"));let a=s.fill||il(e);if(e.colorByDepth&&void 0!==i.depth){const t=el(e);a=t[i.depth%t.length]}n.push({type:"rect",x:i.x0,y:i.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==e.showLabels){const i=tl(e.nodeLabel),n=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,c=a.y1-a.y0;if(0>=t||0>=c)continue;const l=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===n&&!l)continue;if("parent"===n&&l)continue}const u=i?i(a):a.id;if(!u)continue;if((l?30:40)>t||(l?16:14)>c)continue;let h=o(kc(a,"nodeStyle")).fill||il(e);if(e.colorByDepth&&void 0!==a.depth){const t=el(e);h=t[a.depth%t.length]}const d="string"==typeof h?Qc(h):e.themeSemantic?.text??"#000";r.push(l?{x:a.x0+t/2,y:a.y0+c/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill:d}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:d})}}return{sceneNodes:n,sceneEdges:[],labels:r}}(t,i,0,n);case"circlepack":return function(t,e,i,o){const n=[],r=[];for(const i of t){const t=i.__radius??5;if(0>=t)continue;const r=o(kc(i,"nodeStyle"));let s=r.fill||il(e);if(e.colorByDepth&&void 0!==i.depth){const t=el(e);s=t[i.depth%t.length]}n.push({type:"circle",cx:i.x,cy:i.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==e.showLabels){const i=tl(e.nodeLabel);for(const n of t){const t=n.__radius??5,s=i?i(n):n.id;if(!s)continue;if(15>t)continue;const a=!(n.data?.children&&n.data.children.length>0);let c=o(kc(n,"nodeStyle")).fill||il(e);if(e.colorByDepth&&void 0!==n.depth){const t=el(e);c=t[n.depth%t.length]}if(a){const i="string"==typeof c?Qc(c):e.themeSemantic?.text??"#000";r.push({x:n.x,y:n.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:i})}else r.push({x:n.x,y:n.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:n,sceneEdges:[],labels:r}}(t,i,0,n);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function rl(t,e,i){const o=i.treeOrientation||"vertical";if("radial"===o){const i=e.x,o=e.y;t.x=o*Math.cos(i-Math.PI/2),t.y=o*Math.sin(i-Math.PI/2)}else"horizontal"===o?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function sl(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function al(t,e){const i=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-i,t.x1=e.x+i,t.y0=e.y-i,t.y1=e.y+i,t.width=2*i,t.height=2*i,t.__radius=i}import{pie as cl}from"d3-shape";function ll(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var ul={sankey:Mc,force:Dc,chord:jc,tree:nl,cluster:nl,treemap:nl,circlepack:nl,partition:nl,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,i,o){const n=i.__hierarchyRoot;n&&function(t,e,i,o,n){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(i.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(i.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(i.orbitMode),c=i.orbitSize??2.95,l=i.orbitEccentricity??1,u="number"==typeof c?()=>c:c,h="number"==typeof l?()=>l:l,d=ll(i);d.metaMap.clear(),o.length=0,n.length=0;const f=new Map;function p(t){const e=f.get(t)??0;return f.set(t,e+1),0===e?t:`${t}__${e}`}const y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=p(s(t));o.push({id:x,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:t}),d.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,i,c,l,f,y,g){const m=r(e);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(x+1)/b,A={id:i,depth:y,data:e,parentId:i},M=g?f/u(A)*S:f*S,_=cl().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=h(A);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),h=c+M*Math.sin(r),f=l+M*Math.cos(r)*P;o.push({id:u,x:h,y:f,x0:h,x1:h,y0:f,y1:f,width:0,height:0,value:0,depth:y,data:a}),d.metaMap.set(u,{ring:M,angle:r,depth:y,parentId:i,eccentricity:P}),n.push({source:i,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:i,target:u}}),t(a,u,h,f,M,y+1,!0)}k+=v}}(t,x,y,g,m,1,!1)}(n,o,i,t,e)},buildScene(t,e,i,o){const n=i.nodeStyle,r=i.nodeSize,s="number"==typeof r?()=>r:"function"==typeof r?r:()=>6,a=[],c=[],l=[];if(!1!==i.orbitShowRings){const e=ll(i),o=new Map;for(const e of t)o.set(e.id,e);const n=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=o.get(t.parentId);if(!e)continue;const i=`${t.parentId}:${t.ring}`;n.has(i)||n.set(i,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:i,ecc:o}]of n)for(let n=0;r>n;n++){const a=n/r*Math.PI*2,l=(n+1)/r*Math.PI*2;c.push({type:"line",x1:t+i*Math.sin(a),y1:e+i*Math.cos(a)*o,x2:t+i*Math.sin(l),y2:e+i*Math.cos(l)*o,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=s(kc(e,"nodeSize")),o=n?n(kc(e,"nodeStyle")):{};a.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:o.fill||i.themeSemantic?.primary||"#6366f1",stroke:o.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity??(0===(e.depth??0)?1:.85)},datum:e,id:e.id,label:e.id,depth:e.depth})}const u=new Map;for(const e of t)u.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:u.get(t.source),i="object"==typeof t.target?t.target:u.get(t.target);e&&i&&(null!=e.x&&null!=i.x&&c.push({type:"line",x1:e.x,y1:e.y,x2:i.x,y2:i.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:t}))}if(i.showLabels){const e=i.nodeLabel;for(const i of t){const t=s(kc(i,"nodeSize"));if(4>=t)continue;const o="function"==typeof e?e(i):e?i.data?.[e]??i.id:i.id;l.push({x:i.x,y:i.y+t+12,text:o+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:a,sceneEdges:c,labels:l}},tick:(t,e,i,o,n)=>!1!==i.orbitAnimated&&(function(t,e){const i=ll(e),o=e.orbitSpeed??.25,n=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-i.startTime)/1e3,s=o*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=i.metaMap.get(e.id);if(!t||!t.parentId)continue;const o=a.get(t.parentId);if(!o)continue;const c=t.angle+r*s*n({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=o.x+t.ring*Math.sin(c),e.y=o.y+t.ring*Math.cos(c)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,i),!0)}};import{Fragment as hl,jsxs as dl}from"react/jsx-runtime";function fl(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var pl=new Set(["tree","cluster","treemap","circlepack","partition"]);function yl(t,e){const i=_(t.theme),o=t.chartType||"force",n=()=>yo({frameType:"network",width:r[0],height:r[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,nodeCount:0,edgeCount:0}),r=t.size||[500,500],s=Ts({top:20,right:20,bottom:20,left:20,...t.margin},t.title),a=Rs(t.title),c=t.showLegend?(()=>{const e="string"==typeof(i=t.colorBy)||"function"==typeof i?t.colorBy:void 0;var i;if(!e)return[];const o=bo(t.nodes||[]);if(o.length>0)return Dr(o,e);const n=Array.isArray(t.edges)?bo(t.edges):[];if(0===n.length)return[];const r=fl(t.sourceAccessor,"source"),s=fl(t.targetAccessor,"target");return Dr(Array.from(new Set(n.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[],l=t.legendPosition;go(t.legend)||mo(t.legend)?Es(s,{legend:t.legend,theme:i,position:l||"right",size:r,hasTitle:a,legendLayout:t.legendLayout}):t.showLegend&&c.length>0&&Ds(s,{categories:c,colorScheme:t.colorScheme,theme:i,position:l||"right",size:r,hasTitle:a,legendLayout:t.legendLayout});const u=r[0]-s.left-s.right,h=r[1]-s.top-s.bottom,d=function(t){return ul[t]}(o);if(!d&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${o}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const f={chartType:o,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,colorBy:t.colorBy,colorScheme:t.colorScheme||i.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let p,y;if(pl.has(o)){const o=t.data||t.edges;if(!o||Array.isArray(o))return e&&(e.evidence=n()),ka.renderToStaticMarkup(Ns(null,{width:r[0],height:r[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:h,idPrefix:t._idPrefix}));f.__hierarchyRoot=o,p=[],y=[]}else{const o=bo(t.nodes||[]),a=Array.isArray(t.edges)?bo(t.edges):[];if(0===o.length&&0===a.length)return e&&(e.evidence=n()),ka.renderToStaticMarkup(Ns(null,{width:r[0],height:r[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:h,idPrefix:t._idPrefix}));if(y=function(t,e){const i=fl(e.sourceAccessor,"source"),o=fl(e.targetAccessor,"target"),n=fl(e.valueAccessor,"value");return t.map(t=>({source:i(t)+"",target:o(t)+"",value:Number(n(t))||1,y0:0,y1:0,sankeyWidth:0,data:t}))}(a,f),0===o.length&&y.length>0){const t=new Set;for(const e of y){const i=zs(e.source),o=zs(e.target);i&&t.add(i),o&&t.add(o)}p=Array.from(t).map(t=>({id:t,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:t}}))}else p=function(t,e){const i=fl(e.nodeIDAccessor,"id");return t.map(t=>({id:i(t)+"",x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t}))}(o,f)}let g=[],m=[],x=[],b=null;if(f.customNetworkLayout){const t=f.colorScheme,e=Qi(t,i.colors.categorical,D),o=Ji(e,t),n={nodes:p,edges:y,dimensions:{width:u,height:h,plot:{x:0,y:0,width:u,height:h}},theme:{semantic:i.colors,categorical:[...e]},resolveColor:o,config:f.layoutConfig??{}},r=f.customNetworkLayout(n);g=r.sceneNodes??[],m=r.sceneEdges??[],x=r.labels??[],b=r.overlays??null}else if(d){d.computeLayout(p,y,f,[u,h]);const t=d.buildScene(p,y,f,[u,h]);g=t.sceneNodes,m=t.sceneEdges,x=t.labels}const v=P(i);for(const t of x)t.fill||(t.fill=v.text);e&&(e.evidence=yo({frameType:"network",width:r[0],height:r[1],marks:[...g.map(t=>({type:"node:"+(t.type??"node")})),...m.map(t=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,nodeCount:g.length,edgeCount:m.length}));const w=m.map((e,i)=>Sr({node:e,index:i,renderMode:t.renderMode,fallback:()=>function(t,e){switch(t.type){case"line":return fr("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth||1,opacity:t.style.opacity},"net-edge-"+e);case"bezier":{const i=t;return fr("path",{d:i.pathD,fill:gr(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth,opacity:i.style.opacity},"net-edge-"+e)}case"ribbon":{const i=t;return fr("path",{d:i.pathD,fill:gr(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth,opacity:i.style.opacity},"net-edge-"+e)}case"curved":{const i=t;return fr("path",{d:i.pathD,fill:gr(i.style.fill,"none"),stroke:i.style.stroke||"#999",strokeWidth:i.style.strokeWidth||1,opacity:i.style.opacity},"net-edge-"+e)}default:return null}}(e,i)})).filter(Boolean),k=g.map((e,i)=>Sr({node:e,index:i,renderMode:t.renderMode,fallback:()=>function(t,e){switch(t.type){case"circle":{const i=t,o=rr(i.style.fill)?sr(i.style.fill,`net-circle-${e}-hatch`):void 0;return pr(er.Fragment,{children:[o&&fr("defs",{children:o}),fr("circle",{cx:i.cx,cy:i.cy,r:i.r,fill:o?`url(#net-circle-${e}-hatch)`:gr(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity})]},"net-circle-"+e)}case"rect":{const i=t,o=rr(i.style.fill)?sr(i.style.fill,`net-rect-${e}-hatch`):void 0;return pr(er.Fragment,{children:[o&&fr("defs",{children:o}),fr("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:o?`url(#net-rect-${e}-hatch)`:gr(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity})]},"net-rect-"+e)}case"arc":{const i=t,o=ir().innerRadius(i.innerR).outerRadius(i.outerR).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2)(yr)||"",n=rr(i.style.fill)?sr(i.style.fill,`net-arc-${e}-hatch`):void 0;return pr(er.Fragment,{children:[n&&fr("defs",{children:n}),fr("path",{d:o,transform:`translate(${i.cx},${i.cy})`,fill:n?`url(#net-arc-${e}-hatch)`:gr(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity})]},"net-arc-"+e)}case"symbol":{const i=t,o=hn(i.symbolType,i.size,i.path);return fr("path",{d:o,transform:i.rotation?`translate(${i.cx},${i.cy}) rotate(${180*i.rotation/Math.PI})`:`translate(${i.cx},${i.cy})`,fill:i.style.fill?gr(i.style.fill):"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity},"net-symbol-"+e)}case"glyph":return xr(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(e,i)})).filter(Boolean),S=x.map((t,e)=>function(t,e){return fr("text",{x:t.x,y:t.y,textAnchor:t.anchor||"middle",dominantBaseline:t.baseline||"auto",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"var(--semiotic-text, #333)",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,children:t.text},"net-label-"+e)}(t,e)).filter(Boolean),A=t.annotations?_s({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{},layout:{width:u,height:h},theme:i,idPrefix:t._idPrefix}):null,M=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const n=Dr(p.length>0?p.map(t=>t.data||{id:t.id}):Array.from(new Set(y.flatMap(t=>[zs(t.source),zs(t.target)]).filter(Boolean))).map(t=>({id:t})),e);return 0===n.length?null:zr({categories:n,colorScheme:t.colorScheme,theme:i,position:t.legendPosition||"right",totalWidth:r[0],totalHeight:r[1],margin:s,hasTitle:a,legendLayout:t.legendLayout})})():null,R=wa.isValidElement(t.legend)?t.legend:Is(t.legend,{theme:i,position:t.legendPosition||"right",size:r,margin:s,hasTitle:a,legendLayout:t.legendLayout,idPrefix:t._idPrefix})||M;return ka.renderToStaticMarkup(Ns(dl(hl,{children:[t.backgroundGraphics,w,k,S,A,t.foregroundGraphics,b]}),{width:r[0],height:r[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:h,legend:R,idPrefix:t._idPrefix}))}import*as gl from"react";import*as ml from"react-dom/server";import{geoPath as xl}from"d3-geo";import{quadtree as bl}from"d3-quadtree";import{geoMercator as vl,geoEqualEarth as wl,geoAlbersUsa as kl,geoOrthographic as Sl,geoNaturalEarth1 as Al,geoEquirectangular as Ml}from"d3-geo";var _l={mercator:vl,equalEarth:wl,albersUsa:kl,orthographic:Sl,naturalEarth:Al,equirectangular:Ml};function Pl(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Rl(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Tl(t,e,i){return t?"function"==typeof t?{...i,...t(e)}:{...i,...t}:{...i}}function Ll(t,e){if(2>t.length)return[t];const i=.4*e,o=[];let n=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>i?(2>n.length||o.push(n),n=[r]):n.push(r)}return 2>n.length||o.push(n),o}function Cl(t,e,i=24){const o=e[0]-t[0],n=e[1]-t[1],r=Math.sqrt(o*o+n*n);if(0===r)return[t,e];const s=-n/r,a=o/r,c=Math.min(.3*r,80),l=(t[0]+e[0])/2+s*c,u=(t[1]+e[1])/2+a*c,h=[];for(let o=0;i>=o;o++){const n=o/i,r=1-n;h.push([r*r*t[0]+2*r*n*l+n*n*e[0],r*r*t[1]+2*r*n*u+n*n*e[1]])}return h}function $l(t,e){if(2>t.length)return t;const i=e/2+1,o=[];for(let e=0;t.length>e;e++){const n=t[e];let r,s;0===e?(r=t[1][0]-n[0],s=t[1][1]-n[1]):e===t.length-1?(r=n[0]-t[e-1][0],s=n[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;o.push([n[0]+s/a*i,n[1]+-r/a*i])}return o}function zl(t,e,i,o,n){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const c=s/a,l=-r/a,u=n/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}import{scaleLinear as Dl}from"d3-scale";var El=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Il=["scene-style","data-paint","accessibility","evidence"],Fl=(t,e)=>({retainedData:t,invalidations:e}),Nl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Bl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ol=["scene-geometry","data-paint","accessibility","evidence"],Wl=["scene-style","data-paint","accessibility","evidence"],jl=["overlay","accessibility","evidence"],Yl=[],Xl={xAccessor:Fl("rebuild",Nl),yAccessor:Fl("rebuild",Nl),lineDataAccessor:Fl("rebuild",Nl),pointIdAccessor:Fl("rebuild",Ol),lineIdAccessor:Fl("rebuild",Ol),windowSize:Fl("rebuild",Nl),projection:Fl("preserve",Bl),projectionExtent:Fl("preserve",Bl),fitPadding:Fl("preserve",Bl),lineType:Fl("preserve",Bl),flowStyle:Fl("preserve",Bl),graticule:Fl("preserve",Bl),projectionTransform:Fl("preserve",Bl),customLayout:Fl("preserve",Bl),layoutConfig:Fl("preserve",Bl),layoutMargin:Fl("preserve",Bl),areaStyle:Fl("preserve",Wl),pointStyle:Fl("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Fl("preserve",Wl),colorScheme:Fl("preserve",Wl),themeCategorical:Fl("preserve",Wl),themeDiverging:Fl("preserve",Wl),themeSemantic:Fl("preserve",Wl),themeSequential:Fl("preserve",Wl),decay:Fl("preserve",Wl),pulse:Fl("preserve",Wl),layoutSelection:Fl("preserve",Wl),annotations:Fl("preserve",jl),autoPlaceAnnotations:Fl("preserve",jl),clock:Fl("preserve",Yl),transition:Fl("preserve",Yl),introAnimation:Fl("preserve",Yl),onLayoutError:Fl("preserve",Yl)},ql=Fl("preserve",Bl),Gl=class{constructor(){this.tracker=new bi}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},El)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Il):this.recordNoop("restyle")}recordConfig(t,e={}){const i=function(t){let e="preserve";const i=new Set;for(const o of t){const t=Xl[o]??ql;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}(t),o=new Set(i.invalidations);return e.retainedDataChanged&&o.add("data"),this.tracker.record({kind:"config",keys:t},o)}};import{geoDistance as Vl,geoGraticule as Hl,geoInterpolate as Zl}from"d3-geo";function Kl(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var Ul=class t{constructor(t){this.updateResults=new Gl,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:Kl(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??Co()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),i=this.timestampBuffer?.toArray()??[],o=e.slice(-t),n=i.slice(-o.length),r=this.currentTime();this.pointBuffer=new ko(t),this.timestampBuffer=new ko(t),o.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(n[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:Kl(t.fitPadding)}:t}(t),i=this.config,o=this.getConfiguredWindowSize(),n=Object.keys(e).filter(t=>e[t]!==i[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==o;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),i=this.pointBuffer?this.pointBuffer.toArray():this.pointData,o=this.timestampBuffer?.toArray()??[],n=i.slice(-e),r=o.slice(-n.length),s=this.currentTime();this.pointBuffer=new ko(e),this.timestampBuffer=new ko(e),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();Rn(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const i of t)Rn(this.pointBuffer,i,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const i="function"==typeof e?e:t=>t[e],o=new Set(Array.isArray(t)?t:[t]),n=[];return this.lineData=this.lineData.filter(t=>!o.has(i(t)+"")||(n.push(t),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const i="function"==typeof e?e:t=>t[e],o=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>o.has(i(t)+"");Tn(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!o.has(i(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const i of this.scene){const o=this._baseStyles.get(i)??i.style,n=e(i,t);i.style=n?{...o,...n}:o}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,i=this.projection,o=this.geoPath,n=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return wl();if("string"==typeof t){const e=_l[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),wl())}if("object"==typeof t&&"type"in t){const e=_l[t.type],i=e?e():wl();return t.rotate&&"rotate"in i&&i.rotate(t.rotate),t.center&&"center"in i&&i.center(t.center),i}return t}(e.projection),this.geoPath=xl(this.projection),this.fitProjection(t),this.geoPath=xl(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(t,e)=>l([t,e]),invertedPoint:(t,e)=>l.invert?l.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=i,this.geoPath=o,this.scales=n,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,i=t.height/2,o=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:i}));o.length>0&&this.startTransition(o)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,i=this.config,o=[...this.areas],n=Pl(i.xAccessor,"lon"),r=Pl(i.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[n(t),r(t)]);o.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Rl(i.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[n(t),r(t)]);o.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==o.length){if(i.projectionExtent){const[[o,n],[r,s]]=i.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[o,n],[r,n],[r,s],[o,s],[o,n]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const o=i.fitPadding??0,n=Math.min(t.width,t.height);e.scale(n/2-n*o),e.translate([t.width/2,t.height/2])}else{const n=i.fitPadding??0,r=t.width*n,s=t.height*n;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:o})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const i=this.projection;if(!i)return;const o=this.geoPath,n=this.scales,r=i.scale(),s=[...i.translate()],a=this.currentZoom;i.scale(this.baseScale*t.k),i.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=xl(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(t,e)=>i([t,e]),invertedPoint:(t,e)=>i.invert?i.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(r),i.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const i=this.projection;if(!i)return;const o=this.geoPath,n=this.scales,r=i.scale(),s=[...i.translate()],a=this.currentZoom;i.scale(this.baseScale*t),i.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=xl(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(t,e)=>i([t,e]),invertedPoint:(t,e)=>i.invert?i.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(r),i.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const i=this.projection;if(!i||!i.rotate)return;const o=this.geoPath,n=this.scales,r=[...i.rotate()];i.rotate(t),this.geoPath=xl(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(t,e)=>i([t,e]),invertedPoint:(t,e)=>i.invert?i.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.rotate(r),this.geoPath=o,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,i=0;for(const t of this.scene)"point"===t.type&&(i++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=i)return void(this._quadtree=null);const o=Array(i);let n=0;for(const t of this.scene)"point"===t.type&&(o[n++]=t);this._quadtree=bl().x(t=>t.x).y(t=>t.y).addAll(o)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,i=this.projection,o=this.geoPath;if(e.customLayout&&this.scales){const i=e.layoutMargin??{top:0,right:0,bottom:0,left:0},o=Qi(e.colorScheme,e.themeCategorical,U),n={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:i,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...o]},resolveColor:Ji(o,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(n)}catch(t){const i=null!==this.lastCustomLayoutResult,o=mn("geo",t,i,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(o)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return i?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of s)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return pn({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:i,areas:o,points:n,lines:r,layout:s}){const a=Pl(t.xAccessor,"lon"),c=Pl(t.yAccessor,"lat"),l=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),h=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),d=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,o=Hl();e.step&&o.step(e.step);const n=i(o())||"";n&&l.push({type:"geoarea",pathData:n,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth||.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of o){const o=i(e);if(!o)continue;const n=i.centroid(e),r=i.bounds(e),s=i.area(e);l.push({type:"geoarea",pathData:o,centroid:n,bounds:r,screenArea:s,style:Tl(t.areaStyle,e,u),datum:e,interactive:!0})}const f=Rl(t.lineDataAccessor);for(const i of r){const o=f(i);if(!o||2>o.length)continue;let n=[];if("geo"===t.lineType){const t=Array(o.length);for(let e=0;o.length>e;e++)t[e]=[a(o[e]),c(o[e])];for(let i=0;t.length-1>i;i++){const o=t[i],r=t[i+1],s=Vl(o,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=Zl(o,r);for(let t=0;a>=t;t++){if(i>0&&0===t)continue;const o=e(c(t/a));null!=o&&n.push(o)}}}else for(let t=0;o.length>t;t++){const i=o[t],r=e([a(i),c(i)]);null!=r&&n.push(r)}if(2>n.length)continue;const r=Tl(t.lineStyle,i,h),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==o.length||2>n.length||"arc"!==t.flowStyle?2!==o.length||2>n.length||"offset"!==t.flowStyle||(n="geo"===t.lineType?$l(n,u):zl(n[0],n[n.length-1],0,0,u)):n=Cl(n[0],n[n.length-1]);const d=Ll(n,s.width);if(d.length>1)for(const t of d)2>t.length||l.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:i});else l.push({type:"line",path:2>n.length&&d[0]||n,style:r,datum:i})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,y=e.clipAngle?e.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const i of n){const o=a(i),n=c(i);if(null!=g&&Vl([o,n],b)>g)continue;const r=e([o,n]);if(!r)continue;const s=t.pointStyle?t.pointStyle(i):{...d},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:i,pointId:p?p(i)+"":void 0};l.push(u)}return l}({config:e,projection:i,path:o,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const i=function(t,e,i,o){const n=t.filter(t=>"point"===t.type);if(2>n.length)return null;const r=e.strength??1;if(0===r)return null;const s=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,a="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],c=n.find(t=>t.datum&&s(t.datum)+""==e.center+"");if(!c)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const l=c.x,u=c.y,h=It(n.map(t=>t.datum?a(t.datum):NaN).filter(t=>isFinite(t)&&t>=0),1),d=Math.min(i.width,i.height)/2,f=Dl().domain([0,h]).range([0,d]);o>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const i=t[e];"geoarea"===i.type&&i.interactive&&t.splice(e,1)}for(const t of n){if(t===c)continue;if(!t.datum)continue;const e=Math.atan2(t.y-u,t.x-l),i=Math.sqrt((t.x-l)**2+(t.y-u)**2),o=a(t.datum),n=i+((isFinite(o)?f(o):i)-i)*r;t.x=l+Math.cos(e)*n,t.y=u+Math.sin(e)*n}const p=i.width/2,y=i.height/2,g=p-c.x,m=y-c.y;if(Math.abs(g)>.5||Math.abs(m)>.5)for(const t of n)t.x+=g,t.y+=m;const x={cx:p,cy:y,maxCost:h,availableRadius:d},b=t.filter(t=>"line"===t.type);if(b.length>0&&"fractional"!==e.lineMode){const t=new Map;for(const e of n)e.pointId&&t.set(e.pointId,[e.x,e.y]);for(const e of b){const i=e.datum?.source,o=e.datum?.target;if(i&&o){const n=t.get(i+""),r=t.get(o+"");n&&r&&(e.path=[n,r])}}}return x}(this.scene,t,e,this.areas.length);i&&(this.cartogramLayout=i)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const i=this.scene.filter(t=>"point"===t.type);for(let o=0;i.length>o;o++){const n=$o(t,o,e);i[o]._decayOpacity=n,i[o].style={...i[o].style,opacity:n}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const i=this.scene.filter(t=>"point"===t.type),o=this.timestampBuffer.toArray(),n=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;i.length>a&&o.length>a;a++){const c=Do(e,o[a],t);s=Eo(i[a],c,n,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Io(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const i=new Map;for(const e of t)"point"===e.type&&e.pointId&&i.set(e.pointId,[e.x,e.y]);const o=this.scene.filter(t=>"point"===t.type);let n=!1;for(const t of o)if(t.pointId){const e=i.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(n=!0))}for(const t of o)t.pointId&&!i.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??1,t.style={...t.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(t){if(!this.activeTransition)return!1;const e=To(t,this.activeTransition),i=Ro(e),o=this.scene.filter(t=>"point"===t.type);for(const t of o){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=Lo(t.x,t._targetX,i),t.y=Lo(e,t._targetY,i)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*i})}if(e>=1){for(const t of o)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Ul.QUADTREE_THRESHOLD=500;var Ql=Ul;Fn(Ql);import{Fragment as Jl,jsxs as tu}from"react/jsx-runtime";function eu(t,e){const i=_(t.theme),o=t.size||[t.width||600,t.height||400],n=Ts({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Rs(t.title),s=Array.isArray(t.areas)?bo(t.areas):t.areas,a=bo(t.points),c=bo(t.lines),l=t.showLegend?(()=>{const e="string"==typeof(i=t.colorBy)||"function"==typeof i?t.colorBy:void 0;var i;return Dr(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[],u=t.legendPosition;go(t.legend)||mo(t.legend)?Es(n,{legend:t.legend,theme:i,position:u||"right",size:o,hasTitle:r,legendLayout:t.legendLayout}):t.showLegend&&l.length>0&&Ds(n,{categories:l,colorScheme:t.colorScheme,theme:i,position:u||"right",size:o,hasTitle:r,legendLayout:t.legendLayout});const h=o[0]-(n.left??0)-(n.right??0),d=o[1]-(n.top??0)-(n.bottom??0),f={projection:t.projection||"equalEarth",xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineType:t.lineType,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,themeCategorical:i.colors.categorical,themeSemantic:g(i)},p=new Ql(f);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);p.setAreas(s)}if(t.points&&p.setPoints(a),t.lines&&p.setLines(c),p.computeScene({width:h,height:d}),e&&(e.evidence=yo({frameType:"geo",width:o[0],height:o[1],marks:p.scene,title:t.title,description:t.description,annotations:t.annotations,legendItems:l.length>0?l.length:void 0})),0===p.scene.length){const e=t.backgroundGraphics||t.foregroundGraphics||t.annotations||p.customLayoutOverlays?tu(Jl,{children:[t.backgroundGraphics,t.annotations?_s({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:h,height:d},theme:i,idPrefix:t._idPrefix}):null,t.foregroundGraphics,p.customLayoutOverlays]}):null;return ml.renderToStaticMarkup(Ns(e,{width:o[0],height:o[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:h,innerHeight:d,idPrefix:t._idPrefix}))}const y=p.scene.map((e,i)=>Sr({node:e,index:i,renderMode:t.renderMode,fallback:()=>function(t,e){switch(t.type){case"geoarea":{const i=t;if(!i.pathData)return null;const o=rr(i.style.fill)?sr(i.style.fill,`geoarea-${e}-hatch`):void 0;return pr(er.Fragment,{children:[o&&fr("defs",{children:o}),fr("path",{d:i.pathData,fill:o?`url(#geoarea-${e}-hatch)`:gr(i.style.fill,"#e0e0e0"),fillOpacity:i.style.fillOpacity??1,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth||.5,strokeDasharray:i.style.strokeDasharray,opacity:i._decayOpacity??1})]},"geoarea-"+e)}case"point":{const i=t,o=rr(i.style.fill)?sr(i.style.fill,`geopoint-${e}-hatch`):void 0;return pr(er.Fragment,{children:[o&&fr("defs",{children:o}),fr("circle",{cx:i.x,cy:i.y,r:i.r,fill:o?`url(#geopoint-${e}-hatch)`:gr(i.style.fill),fillOpacity:i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i._decayOpacity??i.style.opacity??1})]},"point-"+e)}case"line":{const i=t;if(2>i.path.length)return null;const o="M"+i.path.map(t=>`${t[0]},${t[1]}`).join("L");return fr("path",{d:o,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth||1.5,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity??1},"line-"+e)}case"glyph":return xr(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(e,i)})).filter(Boolean),m=t.annotations?_s({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:h,height:d},theme:i,idPrefix:t._idPrefix}):null,x=t.showLegend?0===l.length?null:zr({categories:l,colorScheme:t.colorScheme,theme:i,position:t.legendPosition||"right",totalWidth:o[0],totalHeight:o[1],margin:n,hasTitle:r,legendLayout:t.legendLayout}):null,b=gl.isValidElement(t.legend)?t.legend:Is(t.legend,{theme:i,position:t.legendPosition||"right",size:o,margin:n,hasTitle:r,legendLayout:t.legendLayout,idPrefix:t._idPrefix})||x;return ml.renderToStaticMarkup(Ns(tu(Jl,{children:[t.backgroundGraphics,y,m,t.foregroundGraphics,p.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:i,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:h,innerHeight:d,legend:b,idPrefix:t._idPrefix}))}import*as iu from"react-dom/server";function ou(t=[]){return t.map(t=>({id:t.id,label:t.label,count:t.count,...null!=t.secondary?{secondary:t.secondary}:{},...t.secondaryLabel?{secondaryLabel:t.secondaryLabel}:{},...null!=t.observed?{observed:t.observed}:{}}))}var nu={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function ru(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}function su(t,e){const i="function"==typeof e?e(t):e;return{...nu,...i??{}}}function au(t,e={}){return t.map(t=>function(t,e={}){const i=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),o={label:e.getBodyLabel?.(t)??ru(t)},n={style:su(t,e.bodyStyle),datum:i,accessibleDatum:i,accessibility:o,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...n}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...n}}(t,e))}import{jsx as cu,jsxs as lu}from"react/jsx-runtime";function uu(t,e){const i=t.size??[t.width??600,t.height??400],o=new Ei(t.config);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&o.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const n=function(t,e={}){const{width:i=640,height:o=360,title:n,description:r,background:s,className:a,idPrefix:c="physics",...l}=e,u=function(t,e={}){const i=t.settle(e.maxSteps),o=t.readBodies(),n=t.snapshot(),r=au(o,e),s=function(t,e={}){const i=e.bodies??function(t){return t.world.bodies.map(t=>({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:{...t.shape},sleeping:t.sleeping,datum:t.datum}))}(t),o=i.filter(t=>t.sleeping).length;return{bodyCount:i.length,sleepingCount:o,settled:"settled"===t.simulationState&&0===t.queue.length&&o===i.length,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:ou(e.projectionRows)}}(n,{bodies:o,projectionRows:e.projectionRows,stepsRun:i});return{snapshot:n,bodies:o,sceneNodes:r,evidence:s,stepsRun:i}}(t,l),h=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(c),d=n?h+"-title":void 0,f=r?h+"-desc":void 0,p=[d,f].filter(Boolean).join(" ")||void 0;return{svg:iu.renderToStaticMarkup(lu("svg",{xmlns:"http://www.w3.org/2000/svg",className:a??"stream-physics-frame",width:i,height:o,viewBox:`0 0 ${i} ${o}`,role:"img","aria-labelledby":p,children:[n&&cu("title",{id:d,children:n}),r&&cu("desc",{id:f,children:r}),s&&"transparent"!==s?cu("rect",{x:0,y:0,width:i,height:o,fill:s}):null,cu("g",{id:h+"-data-area",children:u.sceneNodes.map((t,e)=>vr(t,e,h))})]})),scene:u,evidence:u.evidence}}(o,{...t,width:i[0],height:i[1],idPrefix:t.idPrefix??t._idPrefix??"physics"});return e&&(e.evidence=yo({frameType:"physics",width:i[0],height:i[1],marks:n.scene.sceneNodes,title:t.title,description:t.description,annotations:[],extraWarnings:0===n.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[]})),n.svg}import{Fragment as hu,jsx as du,jsxs as fu}from"react/jsx-runtime";function pu(t,e){switch(t){case"xy":return js(e);case"ordinal":return va(e);case"network":return yl(e);case"geo":return eu(e);case"physics":return uu(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function yu(t){return js(t)}function gu(t){return va(t)}function mu(t){return yl(t)}function xu(t){return eu(t)}var bu=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","scalePadding","sizeRange","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","barColors","legend","legendLayout"];function vu(t,e,i){return ku(t,e).svg}function wu(t,e,i){const o={},{svg:n,frameType:r}=ku(t,e,0,o),s=o.evidence??yo({frameType:r,width:"number"==typeof e.width?e.width:600,height:"number"==typeof e.height?e.height:400,marks:[],title:"string"==typeof e.title?e.title:void 0,description:"string"==typeof e.description?e.description:void 0,annotations:e.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=t,{svg:n,evidence:s}}function ku(t,e,i,o){const{data:n,width:r=600,height:s=400,theme:a,title:c,description:l,showLegend:u,showGrid:h,background:d,className:f,annotations:p,margin:y,colorScheme:g,colorBy:m,legendPosition:x,...b}=e,v=[r,s],w={...b.frameProps||{},...function(t,e){const i={};for(const o of e)void 0!==t[o]&&(i[o]=t[o]);return i}(b,bu),theme:a,title:c,description:l,showLegend:u,showGrid:h,background:d,className:f,annotations:p,size:v,...void 0!==y&&{margin:y},...void 0!==g&&{colorScheme:g},...void 0!==x&&{legendPosition:x},_idPrefix:b._idPrefix},k=ho[t];if(!k)throw Error(`Unknown chart component: "${t}". See CLAUDE.md for supported chart types.`);const S=k.buildProps(n,m,g,w,b);let A;switch(k.frameType){case"xy":A=js(S,o);break;case"ordinal":A=va(S,o);break;case"network":A=yl(S,o);break;case"geo":A=eu(S,o);break;case"physics":A=uu(S,o)}if("GaugeChart"===t&&S.__gauge){const t=S.__gauge,e=w.margin||{top:20,right:20,bottom:30,left:40},i=(r||300)-e.left-e.right,o=(s||300)-e.top-e.bottom,n=Math.min(i,o)/2*.85,c=e.left+i/2,l=e.top+o/2,u=(t.startAngleDeg+(t.gMax===t.gMin?0:(Math.max(t.gMin,Math.min(t.gMax,t.value??t.gMin))-t.gMin)/(t.gMax-t.gMin))*t.sweep-90)*Math.PI/180,h=_(a).colors.text,d=R.renderToStaticMarkup(fu(hu,{children:[du("line",{x1:c,y1:l,x2:c+n*Math.cos(u),y2:l+n*Math.sin(u),stroke:h,strokeWidth:2.5,strokeLinecap:"round"}),du("circle",{cx:c,cy:l,r:4,fill:h})]}));A=A.replace("</svg>",d+"</svg>")}return{svg:A,frameType:k.frameType}}async function Su(t,e,i={}){const{format:o="png",scale:n=1,background:r}=i;let s,a;s=["xy","ordinal","network","geo","physics"].includes(t)?pu(t,e):vu(t,e),r&&(s=s.replace(/<svg /,`<svg style="background:${r}" `));try{const t="sharp",e=await import(t);a=e.default??e}catch{throw Error('Image export requires the "sharp" package and a Node.js runtime. Install it:\n npm install sharp\nsharp is listed as an optional dependency of semiotic.')}const c=e.width||e.size?.[0]||600,l=e.height||e.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*n}).resize(Math.round(c*n),Math.round(l*n));return"jpeg"===o?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function Au(t,e={}){const{title:i,subtitle:o,theme:n,width:r=1200,height:s,layout:a={},background:c}=e,l=P(_(n)),u=a.columns||2,h=a.gap??16;let d=0;i&&(d+=30),o&&(d+=20),d>0&&(d+=10);const f=Math.floor((r-h-h*(u-1))/u),p=[];let y=0,g=d+h,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),i=e.props.height||300;y+t>u&&(g+=m+h,y=0,m=0),p.push({chart:e,x:h/2+y*(f+h),y:g,w:f*t+h*(t-1),h:i}),m=Math.max(m,i),y+=t}const x=s||g+m+h,b=p.map((t,e)=>{const{chart:i,x:o,y:r,w:s,h:a}=t,c={...i.props,width:s,height:a,theme:n,_idPrefix:"chart-"+e};let l;return l=i.component?vu(i.component,c):i.frameType?pu(i.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,du("g",{transform:`translate(${o},${r})`,children:du("foreignObject",{width:s,height:a,children:du("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+e)});return R.renderToStaticMarkup(fu("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":i||"Dashboard",style:{fontFamily:l.fontFamily},children:[i&&du("title",{children:i}),c&&du("rect",{x:0,y:0,width:r,height:x,fill:c}),i&&du("text",{x:r/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:i}),o&&du("text",{x:r/2,y:i?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:o}),b]}))}import*as Mu from"react-dom/server";import{Fragment as _u,jsx as Pu,jsxs as Ru}from"react/jsx-runtime";function Tu(t,e,i,o={}){const{stepSize:n,windowSize:r,frameCount:s,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:h="ease-out",decay:d}=o,f=i.width||600,p=i.height||400,y=_(i.theme),g={...i,...a&&{xExtent:a},...c&&{yExtent:c}};if(!e||0===e.length)return[];const m=n||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=Ts({top:20,right:20,bottom:30,left:40,...i.margin},i.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(b)for(let o=0;x.length>o;o++){const n=x[o],s=e.slice(r?Math.max(0,n-r):0,n),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:i.projection||"vertical",oAccessor:i.oAccessor||i.categoryAccessor||"category",rAccessor:i.rAccessor||i.valueAccessor||"value",colorAccessor:i.colorAccessor||i.colorBy,stackBy:i.stackBy,groupBy:i.groupBy,barPadding:i.barPadding,innerRadius:i.innerRadius,normalize:i.normalize,bins:i.bins,colorScheme:i.colorScheme||y.colors.categorical,...d&&{decay:d}},c=new pa(a);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:w,height:k}),c.scene.length>0&&S.push(Eu(c.scene,f,p,y,g))}else for(let o=0;x.length>o;o++){const n=x[o],s=e.slice(r?Math.max(0,n-r):0,n),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:i.colorAccessor||i.colorBy,groupAccessor:i.groupAccessor||i.lineBy,lineDataAccessor:i.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:i.colorScheme||y.colors.categorical,lineStyle:i.lineStyle,pointStyle:i.pointStyle,areaStyle:i.areaStyle,sizeAccessor:i.sizeAccessor||i.sizeBy,sizeRange:i.sizeRange,...d&&{decay:d},...l>0&&{transition:{duration:l*(1e3/u),easing:h}}},b=new tr(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(S.push(Du(b.scene,f,p,y,g,v)),l>0&&o>0&&b.activeTransition){const t=l*(1e3/u);for(let e=1;l>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/l*t),S.push(Du(b.scene,f,p,y,g,v))}}return S}function Lu(t,e,i={}){return e.map(e=>{try{return vu(t,{...i,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${i.width||e.width||600}" height="${i.height||e.height||400}"></svg>`}})}function Cu(t,e,i){const o=e.size??[e.width??600,e.height??400],n=_(e.theme),r=P(n),s=e.background||n.colors.background,a=e.idPrefix??"physics-gif",c=e.title?`${a}-title-${i}`:void 0,l=e.description?`${a}-desc-${i}`:void 0,u=[c,l].filter(Boolean).join(" ")||void 0,h=au(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),d=Ru("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&Pu("title",{id:c,children:e.title}),e.description&&Pu("desc",{id:l,children:e.description}),s&&"transparent"!==s?Pu("rect",{x:0,y:0,width:o[0],height:o[1],fill:s}):null,Pu("g",{id:`${a}-frame-${i}`,children:h.map((t,e)=>vr(t,e,`${a}-${i}`))})]});return Mu.renderToStaticMarkup(d)}function $u(t,e={}){const{fps:i=12,frameCount:o,durationSeconds:n=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:c}=e,l=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,i)/l)),h=o??Math.max(1,Math.ceil(n*Math.max(1,i))),d=c?{...t,background:c}:t,f=new Ei(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(Cu(f,d,0)));h>p.length;){for(let t=0;u>t;t+=1)f.tick(l);p.push(Cu(f,d,p.length))}return p}function zu(t,e){const i=t.background||e.colors.background;return i&&"transparent"!==i?i:null}function Du(t,e,i,o,n,r){const s=P(o),a=Ts({top:20,right:20,bottom:30,left:40,...n.margin},n.title),c=e-a.left-a.right,l=i-a.top-a.bottom,u=zu(n,o),h=n.renderMode,d=t.map((t,e)=>Sr({node:t,index:e,renderMode:h,fallback:()=>vr(t,e)})).filter(Boolean),f=function(t,e,i,o,n,r){if(!t||0===t.length)return null;const s=P(o),a=[];for(let o=0;t.length>o;o++){const c=t[o];if("y-threshold"===c.type&&null!=c.value){let t=null;if(r)t=r(c.value);else if(n){const[e,o]=n,r=o-e;if(0===r)continue;t=i-(c.value-e)/r*i}if(null==t)continue;const l=c.color||s.primary,u=c.labelPosition||"right";a.push(Ru("g",{children:[Pu("line",{x1:0,y1:t,x2:e,y2:t,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&Pu("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(i-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:l,fontFamily:s.fontFamily,children:c.label})]},"ann-"+o))}}return a.length>0?Pu(_u,{children:a}):null}(n.annotations,c,l,o,n.yExtent,r?.y),p="string"==typeof n.title?n.title:void 0,y="string"==typeof n.description?n.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,x=[g,m].filter(Boolean).join(" ")||void 0;return Mu.renderToStaticMarkup(Ru("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:i,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&Pu("title",{id:g,children:p}),y&&Pu("desc",{id:m,children:y}),u&&Pu("rect",{x:0,y:0,width:e,height:i,fill:u}),Ru("g",{transform:`translate(${a.left},${a.top})`,children:[f,d]}),p&&Pu("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}function Eu(t,e,i,o,n){const r=P(o),s=Ts({top:20,right:20,bottom:30,left:40,...n.margin},n.title),a="radial"===n.projection,c=a?s.left+(e-s.left-s.right)/2:s.left,l=a?s.top+(i-s.top-s.bottom)/2:s.top,u=zu(n,o),h=n.renderMode,d=t.map((t,e)=>Sr({node:t,index:e,renderMode:h,fallback:()=>wr(t,e)})).filter(Boolean),f="string"==typeof n.title?n.title:void 0,p="string"==typeof n.description?n.description:void 0,y=f?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,m=[y,g].filter(Boolean).join(" ")||void 0;return Mu.renderToStaticMarkup(Ru("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:i,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[f&&Pu("title",{id:y,children:f}),p&&Pu("desc",{id:g,children:p}),u&&Pu("rect",{x:0,y:0,width:e,height:i,fill:u}),Pu("g",{transform:`translate(${c},${l})`,children:d}),f&&Pu("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:f})]}))}async function Iu(t,e,i,o={}){const{fps:n=12,loop:r=!0,scale:s=1,background:a}=o,c=i.width||600,l=i.height||400,u=Tu(t,e,a?{...i,background:a}:i,o);if(0===u.length)throw Error("No frames generated — check that data is not empty");return Nu(u,c,l,{fps:n,loop:r,scale:s})}async function Fu(t,e={}){const{fps:i=12,loop:o=!0,scale:n=1}=e,r=t.size??[t.width??600,t.height??400],s=$u(t,e);if(0===s.length)throw Error("No physics frames generated");return Nu(s,r[0],r[1],{fps:i,loop:o,scale:n})}async function Nu(t,e,i,o={}){const{fps:n=12,loop:r=!0,scale:s=1}=o,a=Math.round(e*s),c=Math.round(i*s);let l,u,h,d;try{const t="sharp",e=await import(t);l=e.default??e}catch{throw Error('Animated GIF export requires "sharp". Install it:\n npm install sharp')}try{const t="gifenc",e=await import(t),i=[e,e.default].find(t=>"function"==typeof t?.GIFEncoder&&"function"==typeof t.quantize&&"function"==typeof t.applyPalette);if(!i)throw Error("gifenc did not expose its encoder functions");u=i.GIFEncoder,h=i.quantize,d=i.applyPalette}catch(t){throw Error('Animated GIF export requires "gifenc". Install it:\n npm install gifenc',{cause:t})}const f=Math.round(1e3/n),p=u();for(let e=0;t.length>e;e++){const i=t[e],o=await l(Buffer.from(i),{density:72*s}).resize(a,c).ensureAlpha().raw().toBuffer(),n=new Uint8Array(o),u=h(n,256),y=d(n,u);p.writeFrame(y,a,c,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}export{_ as resolveTheme,P as themeStyles,pu as renderToStaticSVG,yu as renderXYToStaticSVG,gu as renderOrdinalToStaticSVG,mu as renderNetworkToStaticSVG,xu as renderGeoToStaticSVG,vu as renderChart,wu as renderChartWithEvidence,Su as renderToImage,Au as renderDashboard,Tu as generateFrameSVGs,Lu as generateFrameSequence,$u as generatePhysicsFrameSVGs,Iu as renderToAnimatedGif,Fu as renderPhysicsToAnimatedGif};