semiotic 3.8.7 → 3.8.8
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.
- package/CLAUDE.md +2 -2
- package/README.md +56 -46
- package/ai/dist/mcp-server.js +28 -2
- package/ai/schema.json +124 -4
- package/ai/surface-manifest.json +1 -1
- package/ai/system-prompt.md +1 -1
- package/dist/{chunk-chartContainerDataAudit-JDSVSKGM.module.min.js → chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js} +1 -1
- package/dist/chunk-chunk-2B3AIKUZ.module.min.js +2 -0
- package/dist/chunk-chunk-2NVFEB7P.module.min.js +2 -0
- package/dist/chunk-chunk-3GCILWPB.module.min.js +2 -0
- package/dist/chunk-chunk-46KRGJQP.module.min.js +1 -0
- package/dist/{chunk-chunk-5SD6BHVW.module.min.js → chunk-chunk-4MLLQUGW.module.min.js} +1 -1
- package/dist/chunk-chunk-57RBPDBQ.module.min.js +2 -0
- package/dist/chunk-chunk-5VVNW5AZ.module.min.js +1 -0
- package/dist/chunk-chunk-66PCWJUG.module.min.js +1 -0
- package/dist/chunk-chunk-7LE56WAE.module.min.js +2 -0
- package/dist/chunk-chunk-7T25U75Z.module.min.js +2 -0
- package/dist/chunk-chunk-AF53TBSN.module.min.js +2 -0
- package/dist/chunk-chunk-BTZYH2IE.module.min.js +1 -0
- package/dist/chunk-chunk-BWV55BZK.module.min.js +2 -0
- package/dist/{chunk-chunk-FRO4TRXK.module.min.js → chunk-chunk-BZNOAHJV.module.min.js} +1 -1
- package/dist/chunk-chunk-CD6PVVS3.module.min.js +2 -0
- package/dist/chunk-chunk-DTSNLGRK.module.min.js +2 -0
- package/dist/{chunk-chunk-BNGBEY7N.module.min.js → chunk-chunk-FC3NZWYR.module.min.js} +1 -1
- package/dist/chunk-chunk-FEPXDKJP.module.min.js +1 -0
- package/dist/chunk-chunk-FJ76HWQZ.module.min.js +1 -0
- package/dist/chunk-chunk-FRGBMTZR.module.min.js +1 -0
- package/dist/chunk-chunk-G75OPF5N.module.min.js +2 -0
- package/dist/{chunk-chunk-NH4MEAKP.module.min.js → chunk-chunk-H5IFO6CU.module.min.js} +1 -1
- package/dist/chunk-chunk-HADHLMY5.module.min.js +1 -0
- package/dist/chunk-chunk-HBFA4NN6.module.min.js +1 -0
- package/dist/chunk-chunk-HCNDE26Q.module.min.js +2 -0
- package/dist/chunk-chunk-JJ4BSUYL.module.min.js +2 -0
- package/dist/chunk-chunk-JRHXQGEV.module.min.js +2 -0
- package/dist/chunk-chunk-L6FFYGYS.module.min.js +1 -0
- package/dist/{chunk-chunk-Z2AJERX5.module.min.js → chunk-chunk-LJDH3WV3.module.min.js} +1 -1
- package/dist/chunk-chunk-LSJUXBMF.module.min.js +1 -0
- package/dist/chunk-chunk-N3Q33XCB.module.min.js +2 -0
- package/dist/chunk-chunk-NWIGA3UK.module.min.js +1 -0
- package/dist/chunk-chunk-OG3TTJGJ.module.min.js +2 -0
- package/dist/{chunk-chunk-XEVJDUTH.module.min.js → chunk-chunk-OZK46A5U.module.min.js} +1 -1
- package/dist/chunk-chunk-PMR47KRY.module.min.js +2 -0
- package/dist/chunk-chunk-QQJNG23C.module.min.js +2 -0
- package/dist/{chunk-chunk-LG7YKJAK.module.min.js → chunk-chunk-RGJ6TKAH.module.min.js} +1 -1
- package/dist/{chunk-chunk-JWXLNZSM.module.min.js → chunk-chunk-SFLUSZ73.module.min.js} +1 -1
- package/dist/chunk-chunk-TCMHJWFJ.module.min.js +1 -0
- package/dist/{chunk-chunk-LVHDZAT3.module.min.js → chunk-chunk-UEZ6SHW5.module.min.js} +1 -1
- package/dist/chunk-chunk-VUWYT7DY.module.min.js +2 -0
- package/dist/{chunk-chunk-OI7R7EJB.module.min.js → chunk-chunk-W5HWGQMD.module.min.js} +1 -1
- package/dist/chunk-chunk-WFHZHWT7.module.min.js +1 -0
- package/dist/chunk-chunk-WGROBM3I.module.min.js +2 -0
- package/dist/{chunk-chunk-GU2EJIDJ.module.min.js → chunk-chunk-WSDJFBKX.module.min.js} +1 -1
- package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +2 -0
- package/dist/components/charts/index.d.ts +2 -2
- package/dist/components/charts/network/ProcessSankey.d.ts +105 -74
- package/dist/components/charts/network/processSankey/accessors.d.ts +7 -0
- package/dist/components/charts/network/processSankey/algorithm.d.ts +14 -193
- package/dist/components/charts/network/processSankey/axisChrome.d.ts +31 -0
- package/dist/components/charts/network/processSankey/bandPaths.d.ts +45 -0
- package/dist/components/charts/network/processSankey/buildScenes.d.ts +41 -3
- package/dist/components/charts/network/processSankey/fixtures.d.ts +17 -0
- package/dist/components/charts/network/processSankey/frameMargins.d.ts +11 -0
- package/dist/components/charts/network/processSankey/groupBonding.d.ts +13 -0
- package/dist/components/charts/network/processSankey/inventoryAtTime.d.ts +41 -0
- package/dist/components/charts/network/processSankey/labelPlacement.d.ts +34 -0
- package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +47 -0
- package/dist/components/charts/network/processSankey/layoutOrchestrator.d.ts +44 -0
- package/dist/components/charts/network/processSankey/layoutQualityProduct.d.ts +27 -0
- package/dist/components/charts/network/processSankey/massSimulation.d.ts +16 -0
- package/dist/components/charts/network/processSankey/ordering.d.ts +55 -0
- package/dist/components/charts/network/processSankey/orderingBond.d.ts +33 -0
- package/dist/components/charts/network/processSankey/orientation.d.ts +5 -0
- package/dist/components/charts/network/processSankey/packing.d.ts +8 -0
- package/dist/components/charts/network/processSankey/packingCache.d.ts +23 -0
- package/dist/components/charts/network/processSankey/processSankeyLayoutAsync.d.ts +27 -0
- package/dist/components/charts/network/processSankey/processSankeyLayoutWorkerClient.d.ts +72 -0
- package/dist/components/charts/network/processSankey/processSankeyTooltip.d.ts +26 -0
- package/dist/components/charts/network/processSankey/processSankeyTypes.d.ts +163 -0
- package/dist/components/charts/network/processSankey/ribbonInputs.d.ts +26 -2
- package/dist/components/charts/network/processSankey/ribbonRunway.d.ts +45 -0
- package/dist/components/charts/network/processSankey/streamingLayout.d.ts +23 -0
- package/dist/components/charts/network/processSankey/time.d.ts +11 -0
- package/dist/components/charts/network/processSankey/useProcessSankeyPush.d.ts +29 -0
- package/dist/components/charts/network/processSankey/useProcessSankeyScenes.d.ts +26 -0
- package/dist/components/charts/network/processSankey/validation.d.ts +33 -0
- package/dist/components/charts/shared/chartFamilySets.d.ts +1 -0
- package/dist/components/charts/shared/formatUtils.d.ts +12 -1
- package/dist/components/charts/shared/hatchFill.d.ts +2 -0
- package/dist/components/charts/shared/hooks.d.ts +1 -1
- package/dist/components/charts/shared/leastSquaresRegression.d.ts +31 -0
- package/dist/components/charts/shared/styleRules.d.ts +5 -1
- package/dist/components/charts/shared/useChartLegend.d.ts +6 -0
- package/dist/components/charts/shared/useChartSetup.d.ts +1 -1
- package/dist/components/charts/shared/validateProps.d.ts +2 -2
- package/dist/components/charts/shared/withChartWrapper.d.ts +0 -6
- package/dist/components/data/numericFieldProfiler.d.ts +2 -0
- package/dist/components/recipes/layout1d.d.ts +68 -0
- package/dist/components/semiotic-network.d.ts +2 -2
- package/dist/components/semiotic-recipes-core.d.ts +2 -0
- package/dist/components/semiotic.d.ts +2 -0
- package/dist/components/server/staticSVGChrome.d.ts +2 -1
- package/dist/components/store/createStore.d.ts +2 -0
- package/dist/components/stream/OrdinalPipelineStore.d.ts +3 -0
- package/dist/components/stream/PipelineStore.d.ts +5 -0
- package/dist/components/stream/accessorUtils.d.ts +21 -0
- package/dist/components/stream/frameKeyboardNavigation.d.ts +3 -2
- package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +3 -8
- package/dist/components/stream/layouts/index.d.ts +1 -1
- package/dist/components/stream/moduleWorkerSession.d.ts +67 -0
- package/dist/components/stream/networkTypes.d.ts +2 -0
- package/dist/components/stream/ordinalSceneBuilders/sceneBuilderMap.d.ts +2 -1
- package/dist/components/stream/physics/PhysicsKernel.d.ts +9 -0
- package/dist/components/stream/pipelineIntroCancellation.d.ts +6 -0
- package/dist/components/stream/pipelineTransitions.d.ts +15 -1
- package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +16 -4
- package/dist/components/stream/renderers/symbolCanvasRenderer.d.ts +4 -0
- package/dist/components/stream/symbolPath.d.ts +8 -0
- package/dist/components/stream/types.d.ts +2 -0
- package/dist/components/stream/useCanvasFrameHost.d.ts +6 -0
- package/dist/components/stream/useSemanticFrameInteractions.d.ts +12 -3
- package/dist/components/stream/xyFrameAxisTypes.d.ts +4 -0
- package/dist/forceLayoutWorker.js +1 -1
- package/dist/geo.min.js +1 -1
- package/dist/geo.module.min.js +1 -1
- package/dist/network.min.js +1 -1
- package/dist/network.module.min.js +1 -1
- package/dist/ordinal.min.js +1 -1
- package/dist/ordinal.module.min.js +1 -1
- package/dist/physics.min.js +1 -1
- package/dist/physics.module.min.js +1 -1
- package/dist/physicsWorker.js +1 -1
- package/dist/processSankeyLayoutWorker.js +1 -0
- package/dist/realtime.min.js +1 -1
- package/dist/realtime.module.min.js +1 -1
- package/dist/semiotic-ai-core.min.js +1 -1
- package/dist/semiotic-ai-core.module.min.js +1 -1
- package/dist/semiotic-ai.min.js +1 -1
- package/dist/semiotic-ai.module.min.js +1 -1
- package/dist/semiotic-experimental-vacp.min.js +1 -1
- package/dist/semiotic-experimental-vacp.module.min.js +1 -1
- package/dist/semiotic-experimental.min.js +1 -1
- package/dist/semiotic-experimental.module.min.js +1 -1
- package/dist/semiotic-network.d.ts +2 -2
- package/dist/semiotic-realtime-core.min.js +1 -1
- package/dist/semiotic-realtime-core.module.min.js +1 -1
- package/dist/semiotic-recipes-core.d.ts +2 -0
- package/dist/semiotic-recipes-core.min.js +1 -1
- package/dist/semiotic-recipes-core.module.min.js +1 -1
- package/dist/semiotic-recipes.min.js +1 -1
- package/dist/semiotic-recipes.module.min.js +1 -1
- package/dist/semiotic-server-edge.min.js +1 -1
- package/dist/semiotic-server-edge.module.min.js +1 -1
- package/dist/semiotic-server-node.min.js +1 -1
- package/dist/semiotic-server-node.module.min.js +1 -1
- package/dist/semiotic-themes-core.module.min.js +1 -1
- package/dist/semiotic-themes-react.module.min.js +1 -1
- package/dist/semiotic-themes.module.min.js +1 -1
- package/dist/semiotic-utils-core.min.js +1 -1
- package/dist/semiotic-utils-core.module.min.js +1 -1
- package/dist/semiotic-utils-react.module.min.js +1 -1
- package/dist/semiotic-utils.min.js +1 -1
- package/dist/semiotic-utils.module.min.js +1 -1
- package/dist/semiotic-value.min.js +1 -1
- package/dist/semiotic-value.module.min.js +1 -1
- package/dist/semiotic.d.ts +2 -0
- package/dist/semiotic.min.js +1 -1
- package/dist/semiotic.module.min.js +1 -1
- package/dist/server.min.js +1 -1
- package/dist/server.module.min.js +1 -1
- package/dist/xy.min.js +1 -1
- package/dist/xy.module.min.js +1 -1
- package/package.json +4 -3
- package/dist/chunk-chunk-2YAZHXL4.module.min.js +0 -2
- package/dist/chunk-chunk-3NGIKFD6.module.min.js +0 -1
- package/dist/chunk-chunk-7TTBHSAG.module.min.js +0 -2
- package/dist/chunk-chunk-7ZDJSYKI.module.min.js +0 -2
- package/dist/chunk-chunk-BGHPD3RA.module.min.js +0 -1
- package/dist/chunk-chunk-BMRZ2SPU.module.min.js +0 -2
- package/dist/chunk-chunk-C7APLVQD.module.min.js +0 -2
- package/dist/chunk-chunk-DGWFBOGB.module.min.js +0 -1
- package/dist/chunk-chunk-DIVE2DRA.module.min.js +0 -2
- package/dist/chunk-chunk-DSNGDNJY.module.min.js +0 -1
- package/dist/chunk-chunk-FBUNUIPV.module.min.js +0 -2
- package/dist/chunk-chunk-G7QVPZUD.module.min.js +0 -2
- package/dist/chunk-chunk-GBPYV4FP.module.min.js +0 -2
- package/dist/chunk-chunk-KXAFCCDB.module.min.js +0 -2
- package/dist/chunk-chunk-LWITSR2O.module.min.js +0 -2
- package/dist/chunk-chunk-MX35T6RX.module.min.js +0 -2
- package/dist/chunk-chunk-NJETWX42.module.min.js +0 -2
- package/dist/chunk-chunk-NW25WGLS.module.min.js +0 -2
- package/dist/chunk-chunk-ONMLEXHR.module.min.js +0 -2
- package/dist/chunk-chunk-OY66GCE6.module.min.js +0 -1
- package/dist/chunk-chunk-PRDGLMJT.module.min.js +0 -2
- package/dist/chunk-chunk-PZFT457G.module.min.js +0 -1
- package/dist/chunk-chunk-Q3WW6JGR.module.min.js +0 -1
- package/dist/chunk-chunk-Q6XKQTOQ.module.min.js +0 -1
- package/dist/chunk-chunk-RJRM2E6P.module.min.js +0 -1
- package/dist/chunk-chunk-RPL7WYXI.module.min.js +0 -1
- package/dist/chunk-chunk-V3OAKG32.module.min.js +0 -1
- package/dist/chunk-chunk-WCX6U47H.module.min.js +0 -2
- package/dist/chunk-chunk-WLOIUMWG.module.min.js +0 -2
- package/dist/chunk-chunk-XEGXX4F7.module.min.js +0 -1
- package/dist/chunk-chunk-XFRBLXYM.module.min.js +0 -1
- package/dist/chunk-chunk-ZXYDYAB7.module.min.js +0 -2
- package/dist/chunk-statisticalOverlays-6MVAK5RW.module.min.js +0 -2
- package/dist/components/stream/renderers/networkSymbolRenderer.d.ts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{accessorsEquivalent as t,annotationActivationProps as e,annotationBudget as n,annotationDensity as o,bandFromAge as i,coerceDateLikeValue as r,createStore as s,filterAnnotationsByStatus as a,hasOwnEnumerableKey as l,isAnnotationActivationTarget as c,isNoteAnnotation as u,mulberry32 as d,parseDateLikeString as h,resolveAccessor as f,resolveLabelFn as p,resolveNodeRefId as g,resolveRawAccessor as y,resolveResponsiveRules as m,resolveStringAccessor as b,useAnnotationActivationOptions as x,useObservationSelector as v}from"./chunk-chunk-66PCWJUG.module.min.js";function w(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 k(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:S}}),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 S=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],A={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}},M={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}},_={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:S,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 P(t,e){if("light"===e)return A;if("dark"===e)return M;if("high-contrast"===e)return _;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?M:A;return k({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}return k({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}var[C,L]=s(t=>({theme:A,setTheme(e){t(t=>({theme:P(t.theme,e)}))}})),R={light:A,dark:M,"high-contrast":_,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(t){if(!t)return A;if("string"==typeof t){if("light"===t)return A;if("dark"===t)return M;if("high-contrast"===t)return _;return R[t]||A}const e="dark"===t.mode?M:A;return k({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}})}function I(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}}var $={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function O(t,e={}){const n=e.mobileSemantics?.interaction,o="number"==typeof n?.targetSize?n.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!n||void 0!==o,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return $;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??o??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var z={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function F(t,e,n){const o=z[t||"primary"],i=t&&"primary"!==t||!n?.width?o.width:n.width,r=t&&"primary"!==t||!n?.height?o.height:n.height,s={...e,mode:t},a=m(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=z[l],u="context"===l||"sparkline"===l,d="primary"===l&&n?.width?n.width:c.width;return{mode:l,width:a.width??d,height:a.height??("primary"===l&&n?.height?n.height:c.height),showAxes:a.showAxes??c.showAxes,showGrid:a.showGrid??c.showGrid,enableHover:a.enableHover??(!!a.linkedHover||c.enableHover),showLegend:a.showLegend??c.showLegend,showLabels:a.showLabels??c.showLabels,title:u?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:u?void 0:a.xLabel,yLabel:u?void 0:a.yLabel,categoryLabel:u?void 0:a.categoryLabel,valueLabel:u?void 0:a.valueLabel,marginDefaults:D(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:O(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}function D(t,e,n){if(!1!==e)return t;const o={...t};return"horizontal"===n?o.left=Math.min(o.left,15):o.bottom=Math.min(o.bottom,15),o}function E(t){if(null==t)return;if("number"==typeof t)return{top:t,right:t,bottom:t,left:t};const e={};return"number"==typeof t.top&&(e.top=t.top),"number"==typeof t.right&&(e.right=t.right),"number"==typeof t.bottom&&(e.bottom=t.bottom),"number"==typeof t.left&&(e.left=t.left),e}import*as N from"react-dom/server";import*as B from"react";var W=Object.freeze([]);function j(t){if(!t)return W;let e=!1;for(let n=0;t.length>n;n++){const o=t[n];if(null==o||"object"!=typeof o){e=!0;break}}if(!e)return t;const n=[];for(const e of t)null!=e&&"object"==typeof e&&n.push(e);return n}import{scaleOrdinal as Y}from"d3-scale";function X(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function H(t,e,n){const o=t=>t.toString(16).padStart(2,"0");return`#${o(t)}${o(e)}${o(n)}`}function G(t){const e=t.map(X),n=e.length-1;return t=>{if(0>=t){const[t,n,o]=e[0];return H(t,n,o)}if(t>=1){const[t,o,i]=e[n];return H(t,o,i)}const o=t*n,i=Math.floor(o),r=o-i,[s,a,l]=e[i],[c,u,d]=e[i+1];return H(Math.round(s+(c-s)*r),Math.round(a+(u-a)*r),Math.round(l+(d-l)*r))}}var q=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],V=G(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),U=G(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),K=G(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Z=G(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Q=G(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),J=G(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),tt=G(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),et=G(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),nt=G(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),ot=G(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),it=G(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),rt=G(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),st={blues:V,reds:U,greens:K,viridis:tt,oranges:Z,purples:Q,greys:J,plasma:et,inferno:nt,magma:ot,cividis:it,turbo:rt};function at(t){return t&&st[t]||V}var lt=G(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),ct=G(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),ut=G(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),dt=G(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),ht=G(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),ft=G(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),pt=G(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),gt={category10:q,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...st},yt=q,mt="#007bff";function bt(t,e,n=yt){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=gt[t];if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:n}var xt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],vt=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],wt=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 kt(t,e,n){if("function"==typeof e){const o=e(t);return n&&o&&"string"==typeof o&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||wt.has(e)}(o)?n(o):o}const o=t?.[e]+"";return n?n(o):yt[Math.abs(function(t){let e=0;for(let n=0;t.length>n;n++)e=(e<<5)-e+t.charCodeAt(n),e&=e;return Math.abs(e)}(o))%yt.length]}function St(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const n=t[e];return"string"==typeof n&&n.length>0?n:void 0}function At(t,e,n="category10"){if(n&&"object"==typeof n&&!Array.isArray(n)){const t=n;return e=>St(t,e)??"#999"}const o=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),i=o.every(t=>!isNaN(Number(t)));if(Array.isArray(n))return Y().domain(o).range(n).unknown("#999");const r=gt[n]||gt.category10;if(i&&"function"==typeof r){let t=-1/0;for(const e of o){const n=Number(e);n>t&&(t=n)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:yt;return Y().domain(o).range(t).unknown("#999")}}function Mt(t,e,n=[3,20],o){let i;if(i="function"==typeof e?e(t):t?.[e],!o)return i;const[r,s]=o,[a,l]=n;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function _t(t){let e=1/0,n=-1/0;for(const o of t)e>o&&(e=o),o>n&&(n=o);return[e,n]}function Pt(t,e=-1/0){let n=e;for(const e of t)e>n&&(n=e);return n}function Ct(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function Lt(t,e){if(!Ct(e))return t??((...t)=>({}));const n={};return void 0!==e.stroke&&(n.stroke=e.stroke),void 0!==e.strokeWidth&&(n.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(n.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...n}):(...t)=>({...n})}function Rt(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>$t(e(t))}function Tt(t,e){const n=Rt(t),o=Rt(e);return(t,e)=>{const i=o(t);return{value:i,x:n(t),y:i,category:e}}}function It(t,e){const n=Rt(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:n(t),category:null==e?void 0:e+""}}}function $t(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 Ot(t,e,n){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,n):function(t,e,n){const o=null!=t.axis?n[t.axis]:null!=t.field?e[t.field]:n.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const i=$t(o);if(void 0===i)return!1;if(void 0!==t.gt&&t.gt>=i)return!1;if(void 0!==t.gte&&t.gte>i)return!1;if(void 0!==t.lt&&i>=t.lt)return!1;if(void 0!==t.lte&&i>t.lte)return!1;if(void 0!==t.within){const[e,n]=t.within;if(e>i||i>n)return!1}if(void 0!==t.outside){const[e,n]=t.outside;if(i>=e&&n>=i)return!1}return!0}(o,e,n))}function zt(t,e,n){if(!e||0===e.length)return{};let o={};for(const i of e){if(!Ot(i,t,n))continue;const e="function"==typeof i.style?i.style(t,n):i.style;e&&(o={...o,...e})}return o}function Ft(t,e,n,o=t=>t){const i=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=o(t),a={...i(t,r)};return Object.assign(a,zt(s,e,n(s,r))),a}:i}function Dt(t,e,n,o){if(!t||0===t.length)return o;const i=It(e,n);return(e,n)=>{const r=e&&e.data||e,s=zt(r,t,i(r)),a=o?o(e,n):void 0;return a?{...s,...a}:s}}var Et={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function Nt(t,e=Et){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function Bt(t){return t?Nt(t):void 0}function Wt(t,e,n){return"function"==typeof t?t(n):n[t||e]}function jt(t){return t instanceof Date?t.getTime():Number(t)}function Yt(t,e){return tt(1===e?.5:t/(e-1))}function Xt(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function Ht(t,e,n){const o="function"==typeof e?e(t):t[e??n];if(null==o)return null;if(o instanceof Date)return o.getTime();if("string"==typeof o&&""===o.trim())return null;const i=Number(o);return Number.isFinite(i)?i:null}function Gt(t){return Math.round(100*t)/100}function qt(t,e=2){const n=[],o=[],i=e+1;for(let e=0;i>e;e++){let r=0;for(const[n,o]of t)null!==o&&(r+=n**e*o);n.push(r);const s=[];for(let n=0;i>n;n++){let o=0;for(const[i,r]of t)null!==r&&(o+=i**(e+n));s.push(o)}o.push(s)}o.push(n);const r=function(t,e){const n=t,o=t.length-1,i=[e];for(let t=0;o>t;t++){let e=t;for(let i=t+1;o>i;i++)Math.abs(n[t][i])>Math.abs(n[t][e])&&(e=i);for(let i=t;o+1>i;i++){const o=n[i][t];n[i][t]=n[i][e],n[i][e]=o}for(let e=t+1;o>e;e++)for(let i=o;i>=t;i--)n[i][e]-=n[i][t]*n[t][e]/n[t][t]}for(let t=o-1;t>=0;t--){let e=0;for(let r=t+1;o>r;r++)e+=n[r][t]*i[r];i[t]=(n[o][t]-e)/n[t][t]}return i}(o,i).map(Gt);return{points:t.map(([t])=>[Gt(t),Gt(r.reduce((e,n,o)=>e+n*t**o,0))]),equation:[...r].reverse()}}function Vt(t){const e=t.length;let n=0,o=0,i=0,r=0;for(const[e,s]of t)n+=e,o+=s,i+=e*e,r+=e*s;const s=e*i-n*n;if(1e-12>Math.abs(s))return null;const a=(e*r-n*o)/s,l=(o-a*n)/e;return t=>l+a*t}function Ut(t,e){const n=t.length,o=t.map(([t,n])=>n-e(t)).reduce((t,e)=>t+e*e,0),i=Math.sqrt(o/Math.max(n-2,1)),r=t.reduce((t,e)=>t+e[0],0)/n,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:i,meanX:r,ssX:s}}function Kt(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Zt="__forecastSegment",Qt="__forecastOpacity";function Jt(t,e,n,o){const i=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,l=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const n of t){const t=e(n);null!=t&&Number.isFinite(t)&&(n[Qt]=a+Math.max(0,Math.min(1,t))*(l-a))}return}const c=t.map(t=>{const e=n(t),i=o(t);return null!=e&&null!=i&&Number.isFinite(e)&&Number.isFinite(i)?Math.abs(e-i):NaN}),u=c.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=_t(u),f=h-d;t.forEach((t,e)=>{const n=c[e];Number.isFinite(n)&&(t[Qt]=l-(f>0?(n-d)/f:0)*(l-a))})}function te(t,e){return"function"==typeof e?e(t):!!t[e]}var ee="__semiotic_resolvedX",ne="__semiotic_resolvedY",oe="__compoundGroup";function ie(t,e,n){const o=t[e],i=t[n];return null==o||null==i||Number.isNaN(o)||Number.isNaN(i)}function re(t){const e=t.xAccessor||"x",n=t.yAccessor||"y",o=t.lineBy,i=t.colorBy||o;let r=Array.isArray(t.data)?j(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,n){const o="function"==typeof e,i="function"==typeof n,r=o?ee:e,s=i?ne:n;return o||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return o&&(r[ee]=e(t)),i&&(r[ne]=n(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,n);r=s.rows;const a=s.xKey,l=s.yKey,c=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof o||"function"==typeof o?o:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,n,o,i){return(r=o).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,n,o,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=o,g=t.map(t=>{let e="observed";return s&&te(t,s)?e="forecast":r&&te(t,r)&&(e="training"),{...t,[Zt]:e}}),y=o._groupBy,m=[];if(y){const t=new Map;for(const e of g){const n=e[y]??"__default";t.has(n)||t.set(n,[]),t.get(n).push(e)}const e=[];for(const[,n]of t)for(let t=0;n.length-1>t;t++)n[t][Zt]!==n[t+1][Zt]&&(e.push({...n[t+1],[Zt]:n[t][Zt]}),e.push({...n[t],[Zt]:n[t+1][Zt]}));m.push(...g,...e)}else for(let t=0;g.length>t;t++)m.push(g[t]),g.length-1>t&&g[t][Zt]!==g[t+1][Zt]&&(m.push({...g[t+1],[Zt]:g[t][Zt]}),m.push({...g[t],[Zt]:g[t+1][Zt]}));if(o.trainUnderline){const t=[];for(const e of m)"training"===e[Zt]&&t.push({...e,[Zt]:"training-base"});m.unshift(...t)}const b=[];if(l&&c){const t="string"==typeof l?l:"__envUpper",e="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const n of m)"function"==typeof l&&(n[t]=l(n)),"function"==typeof c&&(n[e]=c(n));b.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(o.uncertaintyOpacity||o.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};Jt(m.filter(t=>"forecast"===t[Zt]),o,t,e)}if(a){const t=o.anomalyStyle,e={type:"highlight",filter:t=>te(t,a)};t?(e.style=t,e.r=f):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=f):(e.color=h,e.r=f,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),b.push(e)}return i&&b.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:m,annotations:b}}(t,0,0,o,i):function(t,e,n,o,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:l="#6366f1",bandOpacity:c=.15,label:u}=o;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const n of t)n[e]>r?h.push({...n,[Zt]:"observed"}):d.push({...n,[Zt]:"training"});const f=d.map(t=>[t[e],t[n]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),p=[],g=[];if(f.length>=3){const i=f.length,r=Vt(f);if(r){const{se:d,meanX:h,ssX:y}=Ut(f,r),m=Kt(a),b=Pt(t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t))),x=f.length>1?(f[i-1][0]-f[0][0])/(i-1):1;for(let t=1;s>=t;t++){const o=b+t*x,s=r(o),a=d*Math.sqrt(1+1/i+(y>0?(o-h)**2/y:0))*m;g.push({[e]:o,[n]:s,[Zt]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}Jt(g,o,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&p.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[Zt]:"observed"}),y.push(...h),g.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&y.push({...t,[Zt]:"forecast"}),y.push(...g)}return{processedData:y,annotations:p}}(t,e,n,o,i);var r}(r,a,l,o&&"string"==typeof o&&"object"==typeof t.forecast?{...t.forecast,_groupBy:o}:t.forecast,t.anomaly);if(r=e.processedData,c.push(...e.annotations),u=function(t,e,n){const o=n.upperBounds,i=n.lowerBounds;if(!o&&!i)return;const r="function"==typeof o?o:"string"==typeof o?t=>t[o]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,l=-1/0;for(const n of t){const t=Number(n[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(n);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(n);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),o&&"string"==typeof o?(r=r.map(t=>({...t,[oe]:`${t[o]}__${t[Zt]||"observed"}`})),d=oe):d=Zt,t.baseLineStyle){const e=function(t,e){const n=e.trainDasharray??"8,4",o=e.forecastDasharray??"4,4",i=e.color||"#6366f1",r=e.trainOpacity,s=e.forecastOpacity,a=e.trainStroke,l=e.trainLinecap,c=e.trainUnderline;return e=>{const u=t(e),d=e[Zt];if("training"===d){let t=u.stroke;return"darken"===a?t=function(t,e=.5){const n=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!n)return t;const o=Math.round(parseInt(n[1],16)*(1-e)),i=Math.round(parseInt(n[2],16)*(1-e)),r=Math.round(parseInt(n[3],16)*(1-e));return`#${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(t=a),{...u,stroke:t,strokeDasharray:n,...l&&{strokeLinecap:l},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let t=u.stroke||"#666";return"lighten"===c&&(t=function(t,e=.5){const n=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!n)return t;const o=Math.round(parseInt(n[1],16)+(255-parseInt(n[1],16))*e),i=Math.round(parseInt(n[2],16)+(255-parseInt(n[2],16))*e),r=Math.round(parseInt(n[3],16)+(255-parseInt(n[3],16))*e);return`#${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(t,.4)),{...u,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Qt],n=null!=t?t:s;return{...u,stroke:i,strokeDasharray:o,...null!=n&&{strokeOpacity:n}}}return u}}(e=>t.baseLineStyle(e),t.forecast);h=t=>e(t)}}else t.anomaly&&c.push(...(f=t.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,n,o,i){const r=new Map;for(const e of t){const t=i?(e[i]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const i of e)ie(i,n,o)||t.push(i);return{rows:t,groupKey:i}}if("zero"===e){const t=[];for(const[,e]of r)for(const i of e)ie(i,n,o)?t.push({...i,[o]:0}):t.push(i);return{rows:t,groupKey:i}}const s=[],a="_gapSegment";for(const[t,e]of r){let i=0,r=[];const l=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+i:`${t}__seg${i}`;for(const t of r)s.push({...t,[a]:e});r=[],i++};for(const t of e)ie(t,n,o)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let p;if(t.directLabel){const e=function(t,e,n,o,i,r,s,a){if(!e||!n)return{annotations:[]};const l="object"==typeof e?e:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof n?n:t=>t[n],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const n=t+"";""!==n&&(h.has(n)||h.set(n,[]),h.get(n).push(e))}const f=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[o])-Number(e[o])),f.set(t,"end"===c?e[e.length-1]:e[0]);const p=At(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),g=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[o]:e[o],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:p?kt({__lbl:t},"__lbl",p):a||mt,fontSize:u}));g.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;g.length>t;t++){const e=g[t-1],n=g[t],o=Number(e[i])+e.dy;u+2>Math.abs(Number(n[i])+n.dy-o)&&(n.dy+=u+2)}const y=g.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof n?l:n,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:p}}import{forwardRef as se,useCallback as ae,useMemo as le}from"react";import*as ce from"react";import{jsx as ue}from"react/jsx-runtime";var de={isActive:!1,predicate:()=>!0},he=ce.createContext(null);function fe({value:t,children:e}){return ue(he.Provider,{value:t,children:e})}function pe(t,e){return null!=t?ue(fe,{value:e,children:t}):t}import{forwardRef as ge,useMemo as ye}from"react";import*as me from"react";import{useRef as be,useState as xe,useEffect as ve,useMemo as we,useCallback as ke,useImperativeHandle as Se,useId as Ae,forwardRef as Me,memo as _e}from"react";import*as Pe from"react";import{jsx as Ce}from"react/jsx-runtime";var Le=null,Re=null;function Te(t){const[e,n]=Pe.useState(()=>Le);return Pe.useEffect(()=>{if(e)return;let t=!1;return(Le?Promise.resolve(Le):(Re||(Re=import("./chunk-XYBrushOverlay-ECZJJLAJ.module.min.js").then(t=>Le=t.XYBrushOverlay).catch(t=>{throw Re=null,t})),Re)).then(e=>{t||n(()=>e)}),()=>{t=!0}},[e]),e?Ce(e,{...t}):null}var Ie=class{constructor(t,e){this.lastBoundedData=null,this.chunkTimer=0,this.pushBuffer=[],this.flushScheduled=!1,this.callback=t,this.chunkThreshold=e?.chunkThreshold??5e3,this.chunkSize=e?.chunkSize??5e3}updateChunkOptions(t){null!=t.chunkThreshold&&(this.chunkThreshold=t.chunkThreshold),null!=t.chunkSize&&(this.chunkSize=t.chunkSize)}clearLastData(){this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0)}setBoundedData(t){if(t=j(t),this.lastBoundedData===t)return;if(this.lastBoundedData=t,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.chunkThreshold>=t.length)return void this.callback({inserts:t,bounded:!0});this.callback({inserts:t.slice(0,this.chunkSize),bounded:!0,totalSize:t.length});let e=this.chunkSize;const n=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const o=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,o),bounded:!1}),e=o,this.chunkTimer=t.length>e?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}setReplacementData(t){if(t=j(t),this.lastBoundedData=t,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.pushBuffer=[],this.flushScheduled=!1,this.chunkThreshold>=t.length)return void this.callback({inserts:t,bounded:!0,preserveCategoryOrder:!0});this.callback({inserts:t.slice(0,this.chunkSize),bounded:!0,preserveCategoryOrder:!0,totalSize:t.length});let e=this.chunkSize;const n=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const o=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,o),bounded:!1}),e=o,this.chunkTimer=t.length>e?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}flushPushBuffer(){if(this.flushScheduled=!1,0===this.pushBuffer.length)return;const t=this.pushBuffer;this.pushBuffer=[],this.callback({inserts:t,bounded:!1})}scheduleFlush(){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushPushBuffer()))}push(t){null!=t&&"object"==typeof t&&(this.pushBuffer.push(t),this.scheduleFlush())}pushMany(t){if(0===t.length)return;let e=0;for(let n=0;t.length>n;n++){const o=t[n];null!=o&&"object"==typeof o&&(this.pushBuffer.push(o),e++)}0!==e&&this.scheduleFlush()}flush(){this.flushPushBuffer()}clear(){this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1}},$e=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 n of t){const t=this.push(n);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 n=0;this._size>n;n++)t(this.buffer[(e+n)%this._capacity],n)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++)t[n]=this.buffer[(e+n)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let n=0,o=[];e.length>t&&(n=e.length-t,o=e.slice(0,n)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=n;e.length>t;t++)this.push(e[t]);return o}update(t,e){const n=[],o=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const r=(o+i)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},n.push(t),this.buffer[r]=e(s)}}return n}remove(t){const e=[],n=[];if(this.forEach(o=>{t(o)?n.push(o):e.push(o)}),0===n.length)return n;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return n}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}},Oe=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 n of t){const t=e?e(n):n;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}};function ze(t){return new Set(Array.isArray(t)?t:[t])}function Fe(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function De(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Ee(t,e,n){return t+(e-t)*n}function Ne(){return"undefined"!=typeof performance?performance.now():Date.now()}function Be(t,e,n){if(1>=n)return 1;const o=n-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 n=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>n?1:e;if("exponential"===t.type){const o=t.halfLife??t.extent/2;return e+Math.pow(.5,n/(o>0?o:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-n/t.extent))*(1-e)}({age:o-e,extent:o,type:t.type,halfLife:t.halfLife??n/2,threshold:t.stepThreshold??.5*n,minOpacity:t.minOpacity??.1})}function We(t){const e=new Map;for(let n=0;t.length>n;n++)e.set(t[n],n);return e}function je(t,e,n){const o=t.duration??500,i=n-e;return o>i?1-i/o:0}function Ye(t,e,n,o){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==n&&(t._pulseColor=n,i=!0),t._pulseGlowRadius!==o&&(t._pulseGlowRadius=o,i=!0),i):(0!==t._pulseIntensity&&(t._pulseIntensity=0,i=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,i=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,i=!0),i)}function Xe(t,e,n=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const o=t.duration??500,i=e.peek();return null!=i&&o>n-i}function He(t,e,n){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 n=t.getX(e.datum),o=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${n}:${o}`;if(null!=n&&null!=o)return`p:${n}:${o}`}return"p:"+n;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+n;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??n}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+n:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function Ge(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function qe(t,e,n,o,i,r){const s=[];for(const i of t){const t=n(i),r=o(i);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:i})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),l=Array(s.length),c=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],l[t]=e.rawY,c[t]=e.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function Ve(t,e,n,o,i,r,s,a){const l=[];for(const r of t){const t=n(r),s=o(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const c=e.x(t),u=a?a(r):i;l.push({px:c,topY:e.y(s),botY:e.y(u),rawY:s})}l.sort((t,e)=>t.px-e.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let t=0;l.length>t;t++){const e=l[t];c[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function Ue(t,e,n,o){const i=new Map;if("silhouette"===o)for(const o of t){let t=0;for(const i of e)t+=n(i,o)||0;i.set(o,-t/2)}else if("wiggle"===o){t.length>0&&i.set(t[0],0);for(let o=1;t.length>o;o++){const r=t[o-1],s=t[o];let a=0,l=0,c=0;for(const t of e){const e=n(t,s)||0;a+=(2*c+e)*(e-(n(t,r)||0)),l+=e,c+=e}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):0))}if(t.length>0){let o=0;for(const r of t){let t=0;for(const o of e)t+=n(o,r)||0;o+=(i.get(r)??0)+t/2}const r=o/t.length;for(const e of t)i.set(e,(i.get(e)??0)-r)}}else for(const e of t)i.set(e,0);return i}function Ke(t,e,n,o,i,r,s){const a=n(t),l=o(t);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:e.x(a),y:e.y(l),r:i,style:r,datum:t};return void 0!==s&&(c.pointId=s),c}function Ze(t,e,n,o,i,r,s,a){const l=n(t),c=o(t);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:e.x(l),y:e.y(c),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function Qe(t,e,n,o,i,r,s){return{type:"rect",x:t,y:e,w:n,h:o,style:i,datum:r,group:s}}function Je(t,e,n,o,i,r,s){const a={type:"heatcell",x:t,y:e,w:n,h:o,fill:i,datum:r};return s?.showValues&&(a.showValues=!0,a.value=s.value,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function tn(t,e,n,o){return"function"==typeof e.style?e.style(o||{},n):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(n,o)}function en(t,e,n,o){if(!t.scales)return null;const i=[],r=[];for(const n of e){const e=t.getX(n);if(!Number.isFinite(e))continue;const s=o.getTop(n),a=o.getBottom(n);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const l=t.scales.x(e),c=t.scales.y(s),u=t.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:tn(t,o,n,e[0]),datum:e,group:n,interactive:o.interactive}}function nn(t){const e=[],n=[];if(!t)return{perSeries:e,aggregate:n};for(const o of t)o.perSeries?e.push(o):n.push(o);return{perSeries:e,aggregate:n}}function on(t,e,n){const o=[];for(const i of n){const n=en(t,e,"__ribbon_aggregate",i);n&&o.push(n)}return o}function rn(t,e,n,o){const i=[];for(const r of o){const o=en(t,e,n,r);o&&i.push(o)}return i}function sn(t,e){if(!t)return{};if(!e||0===e.length)return t;const n=[];for(const o of e){if("band"!==o.kind)continue;const e=o.getTop(t),i=o.getBottom(t);Number.isFinite(i)&&Number.isFinite(e)&&n.push({y0:i,y1:e})}return 0===n.length?t:{...t,band:n[0],bands:n}}function an(t,e,n,o){if(!t.config.pointStyle)return;const i=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,l=Ke(r,t.scales,t.getX,i,s,o,a);l&&n.push(l)}}}function ln(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function cn(t){return Nt(t)}import{symbol as un,symbolCircle as dn,symbolCross as hn,symbolDiamond as fn,symbolSquare as pn,symbolStar as gn,symbolTriangle as yn,symbolWye as mn}from"d3-shape";var bn={circle:dn,square:pn,triangle:yn,diamond:fn,star:gn,cross:hn,wye:mn},xn=["circle","triangle","diamond","star","square","chevron","cross","wye"];function vn(t,e,n){if(n)return n;const o=t??"circle";return"chevron"===o?function(t){const e=1.5*wn(t),n=.92*e;return`M0,${-e}L${n},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-n},${(.78*e).toFixed(3)}Z`}(e):un(bn[o]??dn,Math.max(1,e))()??""}function wn(t){return Math.sqrt(Math.max(1,t)/Math.PI)}function kn(t,e){const n=new Map;let o=0;return i=>{const r=t(i)+"",s=e?.[r];if(s)return s;let a=n.get(r);return a||(a=xn[o%xn.length],o++,n.set(r,a)),a}}var Sn=new Map;function An(t,e,n){const o=n.config.areaStyle?.(e);return o&&(t.style=o),t}function Mn(t,e,n,o,i){const r=new Map;for(const s of t){const t=e(s),a=n(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const l=Math.floor(t/o)*o;let c=r.get(l);if(c||(c={start:l,end:l+o,total:0,categories:new Map},r.set(l,c)),c.total+=a,i){const t=i(s);c.categories.set(t,(c.categories.get(t)||0)+a)}}return r}function _n(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:n,overlays:o,warned:i}=t;Pn(o)&&0===n.length&&Cn(i,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),n.length>0&&n.every(t=>null==t.datum)&&Cn(i,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Pn(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(Pn))}function Cn(t,e,n){t.has(e)||(t.add(e),console.warn(n))}function Ln(t,e,n,o){const i=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${i.message}`,error:i,recovery:n?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:n,affectedRevision:o}}function Rn(t,e){const n="function"==typeof t?t:n=>n[t||e];return t=>{const e=n(t);return null==e?NaN:+e}}function Tn(t){const e=[],n=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,o=Rn(n&&t.valueAccessor||t.yAccessor,n?"value":"y");if(t.boundsAccessor){const n=f(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=o(t);if(!Number.isFinite(e))return NaN;const i=n(t);return Number.isFinite(i)&&0!==i?e+i:e},getBottom:t=>{const e=o(t);if(!Number.isFinite(e))return NaN;const i=n(t);return Number.isFinite(i)&&0!==i?e-i:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const n=Array.isArray(t.band)?t.band:[t.band];for(const t of n)e.push({kind:"band",getTop:Rn(t.y1Accessor,"y1"),getBottom:Rn(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as In,scaleLog as $n,scaleSymlog as On,scaleTime as zn}from"d3-scale";function Fn(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Dn(t,e,n){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return $n().domain(t).range(n).clamp(!0)}return"symlog"===t?On().domain(e).range(n):"time"===t?zn().domain([new Date(e[0]),new Date(e[1])]).range(n):In().domain(e).range(n)}function En(t,e,n){e>t.capacity&&(t.resize(e),n&&e>n.capacity&&n.resize(e))}function Nn(t,e){const n=new $e(t.capacity);return t.forEach(()=>n.push(e)),n}function Bn(t,e,n,o){const i=t.push(e);return n&&n.push(o),i}function Wn(t,e,n){if(!e||0===e.size)return;const o=new Set;if(t.forEach((t,e)=>{n(t)&&o.add(e)}),0===o.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)o.has(t)||e.push(i[t])}var jn=new WeakMap;function Yn(){return this.updateResults.last}function Xn(){return this.updateResults.last}function Hn(t){return this.updateResults.subscribe(t)}function Gn(t){this.config.layoutSelection=t}function qn(){jn.set(this,!0)}function Vn(){const t=!0===jn.get(this);return jn.delete(this),t}function Un(t){Object.assign(t.prototype,{getLastUpdateResult:Yn,getUpdateSnapshot:Xn,subscribeUpdateResult:Hn,setLayoutSelection:Gn,markStylePaintPending:qn,consumeStylePaintPending:Vn})}var Kn={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 Zn(t,e){const n={...t};for(const t of e)n[Kn[t]]++;return n}function Qn(t,e,n){const o=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:o,revisions:Zn(n,o)}}var Jn=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=Qn({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 n=Qn(t,e,this.revisions);this.revisions=n.revisions,this.latest=n;for(const t of[...this.listeners])t();return n}},to=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],eo=["scene-style","data-paint","accessibility","evidence"],no=(t,e)=>({retainedData:t,invalidations:e}),oo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],io=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ro=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],so=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ao=["scene-geometry","data-paint","accessibility","evidence"],lo=["scene-style","data-paint","accessibility","evidence"],co=[],uo={chartType:no("rebuild",oo),runtimeMode:no("rebuild",oo),xAccessor:no("rebuild",oo),yAccessor:no("rebuild",oo),timeAccessor:no("rebuild",oo),valueAccessor:no("rebuild",oo),y0Accessor:no("rebuild",oo),boundsAccessor:no("rebuild",oo),band:no("rebuild",oo),openAccessor:no("rebuild",oo),highAccessor:no("rebuild",oo),lowAccessor:no("rebuild",oo),closeAccessor:no("rebuild",oo),candlestickRangeMode:no("rebuild",oo),accessorRevision:no("rebuild",oo),groupAccessor:no("rebuild",io),categoryAccessor:no("rebuild",io),lineDataAccessor:no("rebuild",io),colorAccessor:no("rebuild",lo),sizeAccessor:no("rebuild",ao),symbolAccessor:no("rebuild",ao),pointIdAccessor:no("rebuild",ao),xScaleType:no("preserve",ro),yScaleType:no("preserve",ro),xExtent:no("preserve",ro),yExtent:no("preserve",ro),extentPadding:no("preserve",ro),scalePadding:no("preserve",ro),axisExtent:no("preserve",ro),binSize:no("preserve",ro),normalize:no("preserve",ro),heatmapAggregation:no("preserve",ro),heatmapXBins:no("preserve",ro),heatmapYBins:no("preserve",ro),arrowOfTime:no("preserve",so),baseline:no("preserve",so),stackOrder:no("preserve",so),sizeRange:no("preserve",so),curve:no("preserve",so),areaGroups:no("preserve",so),customLayout:no("preserve",so),layoutConfig:no("preserve",so),layoutMargin:no("preserve",so),symbolMap:no("preserve",ao),showValues:no("preserve",ao),heatmapValueFormat:no("preserve",ao),lineStyle:no("preserve",lo),pointStyle:no("preserve",lo),areaStyle:no("preserve",lo),barStyle:no("preserve",lo),swarmStyle:no("preserve",lo),waterfallStyle:no("preserve",lo),candlestickStyle:no("preserve",lo),boundsStyle:no("preserve",lo),gradientFill:no("preserve",lo),lineGradient:no("preserve",lo),semanticLineStops:no("preserve",lo),colorScheme:no("preserve",lo),themeCategorical:no("preserve",lo),themeSemantic:no("preserve",lo),themeSequential:no("preserve",lo),themeDiverging:no("preserve",lo),barColors:no("preserve",lo),decay:no("preserve",lo),pulse:no("preserve",lo),staleness:no("preserve",lo),layoutSelection:no("preserve",lo),annotations:no("preserve",["overlay","accessibility","evidence"]),windowSize:no("preserve",co),windowMode:no("preserve",co),maxCapacity:no("preserve",co),clock:no("preserve",co),transition:no("preserve",co),introAnimation:no("preserve",co),onLayoutError:no("preserve",co)},ho=no("preserve",so),fo=class{constructor(){this.tracker=new Jn}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}},to)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},eo):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const n=new Set;for(const o of t){const t=uo[o]??ho;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)n.add(e)}return{retainedData:e,invalidations:n}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as po}from"d3-quadtree";var go=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 n=0,o=0;for(const t of e)"point"===t.type&&(n++,t.r>o&&(o=t.r));if(this.maxRadius=o,500>=n)return void(this.tree=null);const i=Array(n);let r=0;for(const t of e)"point"===t.type&&(i[r++]=t);this.tree=po().x(t=>t.x).y(t=>t.y).addAll(i)}},yo=class e{constructor(t){if(this.xExtent=new Oe,this.yExtent=new Oe,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 fo,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 go,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,n)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,n,o,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;const c=i??(()=>{const t=new Map;for(let e=0;n.length>e;e++)t.set(n[e],e);return t})();for(const n of e){if("line"===n.type)continue;if("area"===n.type){const e=Array.isArray(n.datum)?n.datum:[n.datum];let i=0,a=!1;for(const n of e){const e=c.get(n);if(null==e)continue;a=!0;const s=o.get(e);if(null==s)continue;const l=je(t,s,r);l>i&&(i=l)}a&&(l=Ye(n,i,s)||l);continue}const e=c.get(n.datum);if(null==e)continue;const i=o.get(e);l=Ye(n,null==i?0:je(t,i,r),s,a)||l}return l}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),n),this.config=t,this.buffer=new $e(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=f(t.timeAccessor||t.xAccessor,"time"),this.getY=f(t.valueAccessor||t.yAccessor,"value")):(this.getX=f(t.xAccessor,"x"),this.getY=f(t.yAccessor,"y")),this.getGroup=b(t.groupAccessor),this.getCategory=b(t.categoryAccessor),this.getSize=t.sizeAccessor?f(t.sizeAccessor,"size"):void 0,this.getColor=b(t.colorAccessor),this.getSymbol=b(t.symbolAccessor),this.getY0=t.y0Accessor?f(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=Tn(t),this.getPointId=b(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,n=null!=t.closeAccessor;this.getOpen=e?f(t.openAccessor,"open"):void 0,this.getHigh=f(t.highAccessor,"high"),this.getLow=f(t.lowAccessor,"low"),this.getClose=n?f(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!n}t.pulse&&(this.timestampBuffer=new $e(t.windowSize))}currentTime(){return this.config.clock?.()??Ne()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Nn(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 n=e.getTop(t),o=e.getBottom(t);Number.isFinite(n)&&this.yExtent.push(n),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 n=e.getTop(t),o=e.getBottom(t);Number.isFinite(n)&&this.yExtent.evict(n),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 n=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=n?f(this.config.timeAccessor||this.config.xAccessor,"time"):f(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],n=this.config.xAccessor,o="function"==typeof n?n(e):e[n||"x"],i=o instanceof Date,s="string"==typeof o&&Number.isFinite(h(o));if(this.xIsDate=i||s,s){const t="string"==typeof n?n:void 0;this.getX=t?e=>r(e[t]):t=>r(n(t))}}En(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const n of t.inserts)Bn(this.buffer,n,this.timestampBuffer,e),this.xExtent.push(this.getX(n)),this.pushDatumYExtent(n)}else for(const n 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=Bn(this.buffer,n,this.timestampBuffer,e);this.xExtent.push(this.getX(n)),this.pushDatumYExtent(n),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:n}=this,o=this.scales,i=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(n,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=Fn(this.xExtent.extent,e.xExtent),l=Fn(s,e.yExtent);const c=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===e.axisExtent;if("stackedarea"===e.chartType&&!c&&n.size>0){const t=function(t){const{config:e,groups:n,getX:o,getY:i}=t,r="exact"===e.axisExtent;if(e.normalize){const n=[0,r?1:1+e.extentPadding];return{yDomain:n,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:n}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,l=new Set;let c=0;const u=new Map,d=new Map;for(const t of n){const e=new Map;let n=0;for(const r of t.data){const t=o(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),l.add(t),n+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=a)}a.set(t.key,e),d.set(t.key,n)}const h=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,g;if("input"===h)p=n.map(t=>t.key);else if("insideOut"===h){const t=[...n].map(t=>t.key).sort((t,e)=>{const n=(d.get(e)??0)-(d.get(t)??0);return 0!==n?n:f(t,e)}),e=[],o=[];let i=0,r=0;for(const n of t)r>i?(e.push(n),i+=d.get(n)??0):(o.push(n),r+=d.get(n)??0);p=[...o.reverse(),...e]}else p="asc"===h?n.map(t=>t.key).sort((t,e)=>{const n=(d.get(t)??0)-(d.get(e)??0);return 0!==n?n:f(t,e)}):"desc"===h?n.map(t=>t.key).sort((t,e)=>{const n=(d.get(e)??0)-(d.get(t)??0);return 0!==n?n:f(t,e)}):n.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),n=Ue(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let o=1/0,i=-1/0;for(const e of t){const t=n.get(e)??0,r=u.get(e)??0;o>t&&(o=t),t+r>i&&(i=t+r)}Number.isFinite(o)&&Number.isFinite(i)||(o=0,i=0);const s=i-o,c=r?0:s>0?s*e.extentPadding:1;g=[o-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),[n,o]=function(t,e,n){let o=0,i=0;for(const r of t){let t=0,s=0;for(const o of e){const e=n(o,r)||0;0>e?s+=e:t+=e}o>s&&(o=s),t>i&&(i=t)}return[o,i]}(t,p,(t,e)=>a.get(t)?.get(e)||0),i=o-n,s=r?0:i>0?i*e.extentPadding:1;g=[n-s,o+s]}else g=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:n.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!c&&n.size>0?l=function(t,e,n,o,i,r,s){const[,a]=function(t,e,n,o,i){const r=Mn(t,e,n,o,i);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,n,o,i);return[0,s?a:a+a*r]}(n,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,d):"waterfall"===e.chartType&&!c&&n.size>0?l=function(t,e,n,o){const[i,r]=function(t,e){let n=0,o=0,i=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(i+=t,n>i&&(n=i),i>o&&(o=i))}return[n,o]}(t,e),s=r-i,a=o?0:s>0?s*n:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(n,this.getY,e.extentPadding,d):c||l[0]===1/0||(l=function(t,e,n){if(!n.length)return t;let[o,i]=t;for(const t of e)for(const e of n){const n=e.getTop(t),r=e.getBottom(t);Number.isFinite(n)&&(o>n&&(o=n),n>i&&(i=n)),Number.isFinite(r)&&(o>r&&(o=r),r>i&&(i=r))}return[o,i]}(l,r,this.resolvedRibbons),l=function(t,e){const n=t[1]-t[0],o=e.exactMode?0:n>0?n*e.extentPadding:1,i=[null!=e.userMin?t[0]:t[0]-o,null!=e.userMax?t[1]:t[1]+o];return"log"!==e.yScaleType||i[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(i[0]=e.dataYDomain[0]/(1+e.extentPadding)),i}(l,{exactMode:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));l=function(t,e,n){if(!e||n)return t;const o=e[0],i=e[1];return null==o&&null==i?t:[null!=o?o:t[0],null!=i?i:t[1]]}(l,e.yExtent,!!c),({xDomain:a,yDomain:l}=function(t,e,n){let o=t,i=e;if(o[0]===1/0||o[1]===-1/0)if("time"===n){const t=Date.now();o=[t-864e5,t]}else o=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:o,yDomain:i}}(a,l,e.xScaleType)),this.scales=function(t){const{config:e,layout:n,xDomain:o,yDomain:i}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(n.width,n.height)/2-1));if(r){if("x"==("up"===(a=e.arrowOfTime)||"down"===a?"y":"x")){const t="right"===e.arrowOfTime?[s,n.width-s]:[n.width-s,s];return{x:In().domain(o).range(t),y:Dn(e.yScaleType,i,[n.height-s,s])}}const t="down"===e.arrowOfTime?[s,n.height-s]:[n.height-s,s];return{x:Dn(e.yScaleType,i,[s,n.width-s]),y:In().domain(o).range(t)}}var a;return{x:Dn(e.xScaleType,o,[s,n.width-s]),y:Dn(e.yScaleType,i,[n.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:l}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.lastLayout=i):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=h,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,n=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]*=n;break;case"area":for(const o of t.topPath)o[0]*=e,o[1]*=n;for(const o of t.bottomPath)o[0]*=e,o[1]*=n;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*n,width:t.clipRect.width*e,height:t.clipRect.height*n}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*n,height:t.height*n})));break;case"point":case"glyph":t.x*=e,t.y*=n;break;case"rect":case"heatcell":t.x*=e,t.y*=n,t.w*=e,t.h*=n;break;case"candlestick":t.x*=e,t.openY*=n,t.closeY*=n,t.highY*=n,t.lowY*=n}const o=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Dn,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,o,r[0]>r[1]?[t.width-l,l]:[l,t.width-l]),y:a(this.config.yScaleType,i,c?[l,t.height-l]:[t.height-l,l])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:n,scales:o}=this;if(!o)return[];if(n.customLayout){const i={data:e,scales:o,dimensions:{width:t.width,height:t.height,margin:n.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:n.themeSemantic??{},categorical:n.themeCategorical??xt},resolveColor:(t,e)=>{const o=this.resolveGroupColor(t);if(o)return o;const i=this.resolveLineStyle(t,e);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:n.themeSemantic?.primary??"#4e79a7"},config:n.layoutConfig??{},selection:n.layoutSelection??null};let r;try{r=n.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Ln("xy",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{n.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,n.layoutSelection??null)}return _n({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const i={scales:o,config:n,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(n.chartType){case"line":return function(t,e){const n=t.groupData(e),o=[],i=t.config.annotations?.filter(ln).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=nn(t.ribbons);if(r.length>0&&o.push(...on(t,e,r)),i.length>0)for(const e of n)o.push(...rn(t,e.data,e.key,i))}for(const e of n){const n=t.resolveLineStyle(e.key,e.data[0]),r=qe(e.data,t.scales,t.getX,t.getY,n,e.key);i&&i.length>0&&(r.colorThresholds=i),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),o.push(r)}return an(t,n,o),o}(i,e);case"area":return function(t,e){const n=t.groupData(e),o=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=nn(t.ribbons);if(r.length>0&&o.push(...on(t,e,r)),i.length>0)for(const e of n)o.push(...rn(t,e.data,e.key,i))}const i=t.scales.y.domain(),r=i[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:i[0]+Math.max(0,Math.min(1,t.offset))*(i[1]-i[0]),color:t.color,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),n=[{from:i[0],to:e[0].value}];for(let t=0;e.length>t;t++)n.push({from:e[t].value,to:e[t+1]?.value??i[1],color:e[t].color});return n.map(({from:e,to:n,color:o})=>{const i=t.scales.y(e),r=t.scales.y(n);return{y:Math.min(i,r),height:Math.abs(r-i),color:o}}).filter(t=>t.height>0)})():void 0,l=t.getY0?e=>{const n=t.getY0(e);return null==n?r:n}:void 0;for(const e of n){const n=t.resolveAreaStyle(e.key,e.data[0]),i=Ve(e.data,t.scales,t.getX,t.getY,r,n,e.key,l),c=cn(t.config.gradientFill);c&&(i.fillGradient=c),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),s&&s.length>0&&(i.colorThresholds=s,i.strokeColorBands=a),o.push(i)}return an(t,n,o),o}(i,e);case"mixed":return function(t,e){const n=t.groupData(e),o=[],i=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=nn(t.ribbons);if(r.length>0&&o.push(...on(t,e,r)),i.length>0)for(const e of n)o.push(...rn(t,e.data,e.key,i))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const n=t.getY0(e);return null==n?r:n}:void 0;for(const e of n)if(i.has(e.key)){const n=t.resolveAreaStyle(e.key,e.data[0]),i=Ve(e.data,t.scales,t.getX,t.getY,r,n,e.key,s),a=cn(t.config.gradientFill);a&&(i.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),o.push(i)}else{const n=t.resolveLineStyle(e.key,e.data[0]),i=qe(e.data,t.scales,t.getX,t.getY,n,e.key);t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),o.push(i)}return an(t,n,o),o}(i,e);case"stackedarea":return function(t,e){const n=t.groupData(e),o=t.config.stackOrder??"key",i=()=>n.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===o);else if("key"===o)i();else if("asc"===o||"desc"===o||"insideOut"===o){const e=new Map;for(const o of n){let n=0;for(const e of o.data){const o=t.getX(e),i=t.getY(e);Number.isFinite(o)&&Number.isFinite(i)&&(n+=i)}e.set(o.key,n)}const i=(t,e)=>e>t?-1:t>e?1:0;if("asc"===o)n.sort((t,n)=>{const o=(e.get(t.key)??0)-(e.get(n.key)??0);return 0!==o?o:i(t.key,n.key)});else if("desc"===o)n.sort((t,n)=>{const o=(e.get(n.key)??0)-(e.get(t.key)??0);return 0!==o?o:i(t.key,n.key)});else{const t=[...n].sort((t,n)=>{const o=(e.get(n.key)??0)-(e.get(t.key)??0);return 0!==o?o:i(t.key,n.key)}),o=[],r=[];let s=0,a=0;for(const n of t)a>s?(o.push(n),s+=e.get(n.key)??0):(r.push(n),a+=e.get(n.key)??0);n.length=0,n.push(...r.reverse(),...o)}}else i();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:l}=function(t,e,n,o,i,r,s,a="zero"){const l=new Set;for(const e of t)for(const t of e.data){const e=n(t);Number.isFinite(e)&&l.add(e)}const c=Array.from(l).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const i of e.data){const e=n(i),r=o(i);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let d;if(r){d=new Map;for(const e of c){let n=0;for(const o of t)n+=u.get(o.key)?.get(e)||0;d.set(e,n||1)}}const h=Ue(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],g=new Map,y=new Map,m=new Map,b=new Map;for(const t of c)y.set(t,h.get(t)??0),m.set(t,0),b.set(t,0);for(const n of t){const t=u.get(n.key),o=new Map;let a=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(n.key,n.data[0]),datum:n.data,group:n.key};s&&(t.curve=s),p.push(t)}a=[],l=[]};for(const n of c){const i=t.has(n);let s,c,u=i?t.get(n):0;if(r&&i&&(u/=d.get(n)),!i||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(n),c=s+u,m.set(n,c)):(s=b.get(n),c=s+u,b.set(n,c)):(s=y.get(n),c=s+u,y.set(n,c));const p=e.x(n);l.push([p,e.y(s)]),a.push([p,e.y(c)]),o.set(n,c)}h(),g.set(n.key,o)}return{nodes:p,stackedTops:g}}(n,t.scales,t.getX,t.getY,(e,n)=>t.resolveAreaStyle(e,n),t.config.normalize,r,s),c=a;if(t.config.pointStyle){const e=new WeakMap;for(const o of n){const n=l.get(o.key);if(n)for(const i of o.data){const o=t.getX(i),r=t.getY(i);null==o||Number.isNaN(o)||null==r||Number.isNaN(r)||!n.has(o)||e.set(i,n.get(o))}}const o=n=>e.get(n)??t.getY(n);an(t,n,c,o)}return c}(i,e);case"scatter":case"bubble":return function(t,e){const n=[],o="bubble"===t.config.chartType?10:5,i=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const n=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(n.length>0){let t=1/0,e=-1/0;for(const o of n)t>o&&(t=o),o>e&&(e=o);r=n=>t===e?(i[0]+i[1])/2:i[0]+(n-t)/(e-t)*(i[1]-i[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",l=t.getSymbol,c=l?kn(l,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||o;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=r(e))}if(s&&t.getColor&&!e.fill){const n=t.getColor(i);n&&s.has(n)&&(e={...e,fill:s.get(n)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(c){const o=c(i),r=Ze(i,t.scales,t.getX,t.getY,Math.PI*l*l,o,e,u);r&&n.push(r)}else{const o=Ke(i,t.scales,t.getX,t.getY,l,e,u);o&&n.push(o)}}return n}(i,e);case"heatmap":return function(t,e,n){if(t.config.heatmapAggregation)return function(t,e,n){const o=Math.max(1,Math.floor(t.config.heatmapXBins??20)),i=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=f(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,l]=t.scales.x.domain(),[c,u]=t.scales.y.domain(),d=(l-a||1)/o,h=(u-c||1)/i,p=o*i;if(p>1e6)return[];const g=new Int32Array(p),y=new Float64Array(p);for(let n=0;e.length>n;n++){const r=e[n],l=t.getX(r),u=t.getY(r);if(!isFinite(l)||!isFinite(u))continue;const f=Math.min(Math.floor((l-a)/d),o-1),p=Math.min(Math.floor((u-c)/h),i-1);if(0>f||0>p)continue;const m=p*o+f;g[m]++;const b=s(r);y[m]+=isFinite(b)?b:0}let m=1/0,b=-1/0;for(let t=0;p>t;t++){if(0===g[t])continue;let e;switch(r){case"sum":e=y[t];break;case"mean":e=y[t]/g[t];break;default:e=g[t]}m>e&&(m=e),e>b&&(b=e)}if(!isFinite(m))return[];const x=b-m||1,v=n.width/o,w=n.height/i,k=t.config.showValues,S=t.config.heatmapValueFormat,A=[];for(let e=0;i>e;e++){const n=e*o;for(let s=0;o>s;s++){const o=n+s;if(0===g[o])continue;let l;switch(r){case"sum":l=y[o];break;case"mean":l=y[o]/g[o];break;default:l=g[o]}const u=(l-m)/x,f={xi:s,yi:e,value:l,count:g[o],sum:y[o],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*h,agg:r};A.push(An(Je(s*v,(i-1-e)*w,v,w,`rgb(${220-(180*u+.5)|0},${220-(100*u+.5)|0},${255-(50*u+.5)|0})`,f,k?{value:l,showValues:!0,valueFormat:S}:void 0),f,t))}}return A}(t,e,n);if(0===e.length)return[];const o=f(t.config.valueAccessor,"value"),i=y(t.config.xAccessor,"x"),r=y(t.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(e.length),c=Array(e.length);for(let t=0;e.length>t;t++){const n=e[t],o=i(n),u=r(n);l[t]=o,c[t]=u,s.has(o)||s.set(o,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),p=Array.from(a.keys()),g=h.every(t=>"number"==typeof t&&!isNaN(t)),m=p.every(t=>"number"==typeof t&&!isNaN(t));if(g){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(m){p.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;p.length>t;t++)a.set(p[t],t)}const b=new Float64Array(e.length),x=new Float64Array(e.length),v=Array(e.length),w=new Map;let k=0;for(let t=0;e.length>t;t++){const n=e[t],i=s.get(l[t]),r=a.get(c[t]);if(void 0===i||void 0===r)continue;const d=o(n),h=r*u+i,f=w.get(h);let p;void 0!==f?p=f:(p=k++,w.set(h,p)),b[p]=h,x[p]=d,v[p]=n}let S=1/0,A=-1/0;for(let t=0;k>t;t++){const e=x[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 st?t:"blues";let n=Sn.get(e);if(n)return n;n=Array(256);const o=at(e);for(let t=0;256>t;t++)n[t]=o(t/255);return Sn.set(e,n),n}("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),_=255/(A-S||1),P=n.width/u,C=n.height/d,L=t.config.showValues,R=t.config.heatmapValueFormat,T=[];for(let e=0;k>e;e++){const n=x[e];if(!isFinite(n))continue;const o=b[e],i=o%u,r=v[e];T.push(An(Je(i*P,(d-1-(o-i)/u)*C,P,C,M[Math.min((n-S)*_+.5|0,255)],r,L?{value:n,showValues:!0,valueFormat:R}:void 0),r,t))}return T}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const n=Mn(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===n.size)return{nodes:[],binBoundaries:[]};let o=null;if(t.getCategory){const e=new Set;for(const t of n.values())for(const n of t.categories.keys())e.add(n);const i=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(i),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=i.filter(t=>e.has(t)),l=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===l?o=t.barCategoryCache.order:(o=[...a,...s],t.barCategoryCache={key:l,order:o})}const i=[],r=t.scales,[s,a]=r.x.domain(),l=t.config.barStyle,c=t.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity);for(const e of n.values()){const n=Math.max(e.start,s),u=Math.min(e.end,a);if(n>=u)continue;const f=r.x(n),p=r.x(u),g=Math.abs(p-f),y=g>d+1?d:0,m=Math.min(f,p)+y/2,b=Math.max(g-y,1);if(b>0)if(o&&e.categories.size>0){let n=0;for(const s of o){const o=e.categories.get(s)||0;if(0===o)continue;const a=r.y(n),u=r.y(n+o);i.push(Qe(m,Math.min(a,u),b,Math.abs(a-u),{fill:t.config.barColors?.[s]||l?.fill||c||"#4e79a7",...h},{binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:o},s)),n+=o}}else{const t=r.y(0),n=r.y(e.total);i.push(Qe(m,Math.min(t,n),b,Math.abs(t-n),{fill:l?.fill||c||"#007bff",...h},{binStart:e.start,binEnd:e.end,total:e.total}))}}const f=new Set;for(const t of n.values())f.add(t.start),f.add(t.end);return{nodes:i,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(i,e);return this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const n=[],o=t.config.swarmStyle||{},i=o.radius??3,r=o.fill??t.config.themeSemantic?.primary??"#007bff",s=o.opacity??.7,a=o.stroke,l=o.strokeWidth;for(const o of e){const e=t.getX(o),c=t.getY(o);if(null==c||Number.isNaN(c))continue;const u=t.scales.x(e),d=t.scales.y(c);let h=r;if(t.getCategory){const e=t.getCategory(o);h=t.config.barColors?.[e]||h}const{r:f,...p}=t.config.pointStyle?.(o)??{},g={type:"point",x:u,y:d,r:f??i,style:{fill:h,opacity:s,stroke:a,strokeWidth:l,...p},datum:o};t.getPointId&&(g.pointId=t.getPointId(o)+""),n.push(g)}return n}(i,e);case"waterfall":return function(t,e,n){const o=[],i=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const n=t.getY(e),o=t.getX(e);return null!=n&&!Number.isNaN(n)&&null!=o&&isFinite(o)});if(0===s.length)return o;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",l=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",c=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let f=0;for(let e=0;s.length>e;e++){const p=s[e],g=t.getX(p),y=t.getY(p),m=f+y;let b;b=s.length-1>e?t.getX(s[e+1])-g:e>0?g-t.getX(s[e-1]):0;const x=i.x(g),v=0!==b?i.x(g+b):x+n.width/10,w=Math.min(x,v)+c/2,k=Math.max(x,v)-c/2-w;if(0>=k){f=m;continue}const S=i.y(f),A=i.y(m),M=Math.min(S,A),_=Math.abs(S-A),P={fill:0>y?l:a,stroke:u,strokeWidth:d};null!=h&&(P.opacity=h),o.push(Qe(w,M,k,_,P,{...p,baseline:f,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth})),f=m}return o}(i,e,t);case"candlestick":return function(t,e,n){if(!t.getHigh||!t.getLow||!t.scales)return[];const o=t.config.candlestickRangeMode??!1;if(!(o||t.getOpen&&t.getClose))return[];const i=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=o?s:r.upColor||"#28a745",l=o?s:r.downColor||"#dc3545",c=o?s:r.wickColor||"#333",u=r.wickWidth||(o?2:1),d=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let e=1/0;for(let n=1;d.length>n;n++){const o=Math.abs(t.scales.x(d[n])-t.scales.x(d[n-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 r of e){const e=t.getX(r);if(null==e||Number.isNaN(e))continue;const s=t.getHigh(r),d=t.getLow(r);if(null==s||Number.isNaN(s)||null==d||Number.isNaN(d))continue;const f=o?s:t.getOpen(r),p=o?d:t.getClose(r);if(!o&&[f,p].some(t=>null==t||Number.isNaN(t)))continue;const g=p>=f,y={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(f),closeY:t.scales.y(p),highY:t.scales.y(s),lowY:t.scales.y(d),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:g,datum:r};o&&(y.isRange=!0,y.dotRadius=Math.max(2,Math.min(h/2,.12*n.height))),i.push(y)}return i}(i,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,n,o){const i=t.boundsStyle;return"function"==typeof i?i(n||{},e):i&&"object"==typeof i?i:{fill:o(e,n).stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none"}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const n=this.config.decay;return n&&e>1?Be(n,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=We(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,n,o=We(n)){const i=n.length;if(i>1)for(const n of e){if("line"===n.type){const e=Array.isArray(n.datum)?n.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let n=0;e.length>n;n++){const a=o.get(e[n]);null!=a?(r[n]=Be(t,a,i),1>r[n]&&(s=!0)):r[n]=1}s&&(n._decayOpacities=r);continue}if("area"===n.type){const e=Array.isArray(n.datum)?n.datum:[],r=n.topPath?n.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let n=0;e.length>n;n++){const r=o.get(e[n]);null!=r?(s[n]=Be(t,r,i),1>s[n]&&(a=!0)):s[n]=1}a&&(n._decayOpacities=s)}else{let s=1;for(const n of e){const e=o.get(n);if(null!=e){const n=Be(t,e,i);s>n&&(s=n)}}if(1>s){const t=Array(r);t.fill(s),n._decayOpacities=t}}continue}const e=o.get(n.datum);if(null==e)continue;const r=Be(t,e,i);"heatcell"===n.type?n.style={opacity:r}:"candlestick"===n.type?n._decayOpacity=r:n.style={...n.style,opacity:(n.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&&Xe(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,n,o){n.clear(),o.clear();for(let i=0;e.length>i;i++){const r=e[i],s=He(t,r,i);s&&("point"===r.type?n.set(s,{x:r.x,y:r.y,r:r.r,opacity:Ge(r.style)}):"glyph"===r.type?n.set(s,{x:r.x,y:r.y,r:r.size,opacity:Ge(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?n.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:Ge(r.style)}):"candlestick"===r.type?n.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:Ge(r.style)}):"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 n=this.scene[e],o=He(this.transitionContext,n,e);o&&("point"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,r:0,opacity:0}):"rect"===n.type?this.prevPositionMap.set(o,{x:n.x,y:t,w:n.w,h:0,opacity:n.style.opacity??1}):"heatcell"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,w:n.w,h:n.h,opacity:0}):"line"===n.type?(n._introClipFraction=0,this.prevPathMap.set(o,{path:n.path.map(t=>[t[0],t[1]]),opacity:n.style.opacity})):"area"===n.type&&(n._introClipFraction=0,this.prevPathMap.set(o,{topPath:n.topPath.map(t=>[t[0],t[1]]),bottomPath:n.bottomPath.map(t=>[t[0],t[1]]),opacity:n.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,n,o,i,r=Ne()){if(0===o.size&&0===i.size)return n;const s=e.duration??300;if(n.exitNodes.length>0){const t=new Set(n.exitNodes);n.scene=n.scene.filter(e=>!t.has(e)),n.exitNodes=[]}let a=!1;const l=new Set,c=new Set;for(let e=0;n.scene.length>e;e++){const r=n.scene[e],s=He(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(c.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=o.get(s);if("point"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=Ge(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=Ge(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=Ge(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=Ge(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=Ge(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=Ge(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=Ge(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=Ge(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=Ge(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=Ge(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!c.has(t))if(t.startsWith("l:")&&e.path){const 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};n.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};n.exitNodes.push(o),a=!0}for(const[t,e]of o)if(!l.has(t)){if(t.startsWith("p:"))n.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)n.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:"))n.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:"))n.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;n.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 n.exitNodes.length>0&&(n.scene=[...n.scene,...n.exitNodes]),a&&(n.activeTransition={startTime:r,duration:s}),n}(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},n=function(t,e,n,o){if(!n.activeTransition)return!1;const i=De(t,n.activeTransition),r=Fe(i,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of n.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const n=e?o.get(e):void 0;t.style.opacity=Ee(n?n.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const n=o.get(e);if(!n)continue;t.x=Ee(n.x,t._targetX,r),t.y=Ee(n.y,t._targetY,r),void 0!==t._targetR&&void 0!==n.r&&(t.r=Ee(n.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const n=e?o.get(e):void 0;t.style.opacity=Ee(n?n.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const n=o.get(e);if(!n)continue;t.x=Ee(n.x,t._targetX,r),t.y=Ee(n.y,t._targetY,r),void 0!==t._targetR&&void 0!==n.r&&(t.size=Ee(n.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=e?o.get(e):void 0;t.style.opacity=Ee(n?n.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const n=o.get(e);if(!n)continue;t.x=Ee(n.x,t._targetX,r),t.y=Ee(n.y,t._targetY,r),void 0!==n.w&&(t.w=Ee(n.w,t._targetW,r)),void 0!==n.h&&(t.h=Ee(n.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const n=e?o.get(e):void 0;t.style={...t.style||{},opacity:Ee(n?n.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const n=o.get(e);if(!n)continue;t.x=Ee(n.x,t._targetX,r),t.y=Ee(n.y,t._targetY,r),void 0!==n.w&&(t.w=Ee(n.w,t._targetW,r)),void 0!==n.h&&(t.h=Ee(n.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const n=e?o.get(e):void 0;t.style={...t.style||{},opacity:Ee(n?n.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const n=o.get(e);if(!n)continue;t.x=Ee(n.x,t._targetX,r),void 0!==n.openY&&(t.openY=Ee(n.openY,t._targetOpenY,r)),void 0!==n.closeY&&(t.closeY=Ee(n.closeY,t._targetCloseY,r)),void 0!==n.highY&&(t.highY=Ee(n.highY,t._targetHighY,r)),void 0!==n.lowY&&(t.lowY=Ee(n.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ee(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,n=t._targetPath;if(e&&n&&e.length===t.path.length)for(let o=0;t.path.length>o;o++)t.path[o][0]=Ee(e[o][0],n[o][0],r),t.path[o][1]=Ee(e[o][1],n[o][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ee(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,n=t._prevBottomPath,o=t._targetTopPath,i=t._targetBottomPath;if(e&&o&&e.length===t.topPath.length)for(let n=0;t.topPath.length>n;n++)t.topPath[n][0]=Ee(e[n][0],o[n][0],r),t.topPath[n][1]=Ee(e[n][1],o[n][1],r);if(n&&i&&n.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Ee(n[e][0],i[e][0],r),t.bottomPath[e][1]=Ee(n[e][1],i[e][1],r)}}if(i>=1){for(const t of n.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 n=0;t.path.length>n;n++)t.path[n]=e[n];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,n=t._targetBottomPath;if(e)for(let n=0;t.topPath.length>n;n++)t.topPath[n]=e[n];if(n)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=n[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(n.exitNodes.length>0){const t=new Set(n.exitNodes);n.scene=n.scene.filter(e=>!t.has(e)),n.exitNodes=[]}return n.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,n}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:n}=function(t,e,n,o){if(o&&o.version===n&&o.group===e&&o.data===t)return{result:o.result,cache:o};let i;if(e){const n=new Map;for(const o of t){const t=e(o);n.has(t)||n.set(t,[]),n.get(t).push(o)}i=Array.from(n.entries()).map(([t,e])=>({key:t,data:e}))}else i=[{key:"_default",data:t}];return{result:i,cache:{version:n,group:e,data:t,result:i}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=n,e}resolveColorMap(t){const{map:e,cache:n}=function(t,e,n,o,i){if(i&&i.version===o)return{map:i.map,cache:i};const r=new Set;if(e)for(const n of t){const t=e(n);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const t={...i,version:o};return{map:t.map,cache:t}}const l=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical||xt,c=new Map;for(let t=0;s.length>t;t++)c.set(s[t],l[t%l.length]);return{map:c,cache:{key:a,map:c,version:o}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=n,e}resolveLineStyle(t,e){return function(t,e,n,o){const i=t.lineStyle;if("function"==typeof i){const t=i(n||{},e);if(t&&!t.stroke&&e){const n=o(e);if(n)return{...t,stroke:n}}return t}const r=t.themeSemantic?.primary;return i&&"object"==typeof i?{stroke:i.stroke||r||"#007bff",strokeWidth:i.strokeWidth||2,strokeDasharray:i.strokeDasharray,fill:i.fill,fillOpacity:i.fillOpacity,opacity:i.opacity}:{stroke:o(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,n,o){if(t.areaStyle){const i=t.areaStyle(n||{});if(i&&!i.fill&&e){const t=o(e);if(t)return{...i,fill:t,stroke:i.stroke||t}}return i}const i=t.lineStyle;if("function"==typeof i){const t=i(n||{},e);if(t&&!t.fill&&e){const n=o(e);if(n)return{...t,fill:n,stroke:t.stroke||n}}return t}const r=t.themeSemantic?.primary;if(i&&"object"==typeof i)return{fill:i.fill||i.stroke||r||"#4e79a7",fillOpacity:i.fillOpacity??.7,stroke:i.stroke||r||"#4e79a7",strokeWidth:i.strokeWidth||2};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:n,groupColorCounter:o}=function(t){const{group:e,colorMapCache:n,groupColorMap:o,groupColorMapCap:i,config:r}=t;let{groupColorCounter:s}=t;if(n){const t=n.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=o.get(e);if(a)return{color:a,groupColorCounter:s};const l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||xt;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,o.set(e,c),o.size>i){const t=o.keys().next().value;void 0!==t&&o.delete(t)}return{color:c,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,n}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=ze(t),n=this.getPointId,o=t=>e.has(n(t));Wn(this.buffer,this.timestampBuffer,o);const i=this.buffer.remove(o);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const n=ze(t),o=this.getPointId,i=new Set;this.buffer.forEach((t,e)=>{n.has(o(t))&&i.add(e)});const r=this.buffer.update(t=>n.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)=>{i.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const n=this._customRestyle;if(n)for(const o of t){const t=this._baseStyles.get(o)??o.style??{},i=n(o,e);o.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){const n={...this.config},o=Object.keys(e).filter(t=>e[t]!==n[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==n.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${n.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 i=!1,r=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();const s="chartType"in e&&e.chartType!==n.chartType||"runtimeMode"in e&&e.runtimeMode!==n.runtimeMode;if(s||"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&&n.valueAccessor||n.yAccessor,l=s||!t(e&&this.config.timeAccessor||this.config.xAccessor,e&&n.timeAccessor||n.xAccessor),c=s||!t(o,a);(l||c)&&(e?(this.getX=f(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=f(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=f(this.config.xAccessor,"x"),this.getY=f(this.config.yAccessor,"y")),c&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=Tn(this.config)),i=!0,r=!0)}if("groupAccessor"in e&&!t(e.groupAccessor,n.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?b(this.config.groupAccessor):void 0,i=!0),"categoryAccessor"in e&&!t(e.categoryAccessor,n.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?b(this.config.categoryAccessor):void 0,i=!0),"sizeAccessor"in e&&!t(e.sizeAccessor,n.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?f(this.config.sizeAccessor,"size"):void 0,i=!0),"symbolAccessor"in e&&!t(e.symbolAccessor,n.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?b(this.config.symbolAccessor):void 0,i=!0),"colorAccessor"in e&&!t(e.colorAccessor,n.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?b(this.config.colorAccessor):void 0,i=!0),"y0Accessor"in e&&!t(e.y0Accessor,n.y0Accessor)&&(this.getY0=this.config.y0Accessor?f(this.config.y0Accessor,"y0"):void 0,i=!0,r=!0),("boundsAccessor"in e&&!t(e.boundsAccessor,n.boundsAccessor)||"band"in e&&e.band!==n.band||"boundsStyle"in e&&e.boundsStyle!==n.boundsStyle)&&(this.resolvedRibbons=Tn(this.config),i=!0,r=!0),"pointIdAccessor"in e&&!t(e.pointIdAccessor,n.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?b(this.config.pointIdAccessor):void 0,i=!0),"candlestick"===this.config.chartType&&(s||"openAccessor"in e&&!t(e.openAccessor,n.openAccessor)||"closeAccessor"in e&&!t(e.closeAccessor,n.closeAccessor)||"highAccessor"in e&&!t(e.highAccessor,n.highAccessor)||"lowAccessor"in e&&!t(e.lowAccessor,n.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?f(this.config.openAccessor,"open"):void 0,this.getHigh=f(this.config.highAccessor,"high"),this.getLow=f(this.config.lowAccessor,"low"),this.getClose=e?f(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,i=!0,r=!0}if("accessorRevision"in e&&e.accessorRevision!==n.accessorRevision&&(i=!0,r=!0),!i){const t=Object.keys(e).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const o of t)if(e[o]!==n[o]){i=!0;break}}i&&(r&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};yo.GROUP_COLOR_MAP_CAP=1e3;var mo=yo;Un(mo);import{memo as bo,useEffect as xo,useRef as vo}from"react";var wo={sceneGeometry:0,layout:0,domain:0};function ko(t){const{domain:e,layout:n,sceneGeometry:o}=t.revisions;return{domain:e,layout:n,sceneGeometry:o}}function So(t,e){return{sceneGeometry:Math.max(t.sceneGeometry,e.sceneGeometry),layout:Math.max(t.layout,e.layout),domain:Math.max(t.domain,e.domain)}}var Ao="production"!==process.env.NODE_ENV,Mo={revisions:wo,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},_o=class{constructor(t="scene host"){this.hostName=t,this.lastConsumed=wo,this.lastObserved=wo,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(t){Ao&&(this.lastObserved=So(this.lastObserved,ko(t)))}beforeCompute(t,e){if(!Ao)return Mo;const n=So(ko(t),this.lastObserved),o=function(t){return`${t.sceneGeometry}|${t.layout}|${t.domain}`}(n),i=!((r=n).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:n,signature:o,sawSignals:t.changed.has("scene-geometry")||t.changed.has("layout")||t.changed.has("domain"),wasUnconsumed:i,warnUnconsumed:!e&&i&&this.lastUnconsumedWarning!==o}}afterCompute(t,e,n){if(Ao){if(e&&t.wasUnconsumed&&(this.lastConsumed=t.revisions),t.warnUnconsumed&&!e)return console.warn(`[semiotic] ${this.hostName} observed scene-affecting revisions without a scene rebuild: ${t.signature}.`),void(this.lastUnconsumedWarning=t.signature);e&&t.sawSignals&&!t.wasUnconsumed&&!n&&this.lastDuplicateWarning!==t.signature?(console.warn(`[semiotic] ${this.hostName} performed scene rebuild with unchanged scene revisions: ${t.signature}.`),this.lastDuplicateWarning=t.signature):e&&!t.sawSignals&&(this.lastDuplicateWarning="")}}},Po=bo(function({store:t,diagnostics:e}){return xo(()=>{const n=()=>e.observeUpdateResult(t.getUpdateSnapshot());return n(),t.subscribeUpdateResult(n)},[e,t]),null});import*as Co from"react";function Lo(...t){const e=t.filter(t=>null!=t);return 0===e.length?null:1===e.length?e[0]:Co.createElement(Co.Fragment,null,...e)}import{useEffect as Ro,useRef as To}from"react";function Io(t,e,n){return n.x>t||t>n.x+n.w||n.y>e||e>n.y+n.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:n.x+n.w/2,cy:n.y+n.h/2}}function $o(t,e=30){return Math.max((t??4)+5,12,e)}function Oo(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function zo(t,e){const n=Oo(t);if(!n)return!1;const o=Oo(e);return!o||n.getFullYear()!==o.getFullYear()||n.getMonth()!==o.getMonth()}var Fo=[40,40],Do=[.5,.5];function Eo(t,e){const[n,o]=t.viewBox??Fo,[i,r]=t.anchor??Do,s=o>0?o:1,a=Math.max(0,e)/s,l=(n>0?n:s)*a,c=s*a;return{width:l,height:c,scale:a,offsetX:-i*l,offsetY:-r*c}}function No(t,e,n,o){if("none"!==t)return"color"===t||null==t?e??o:"accent"===t?n:t}var Bo=null;function Wo(t){if("undefined"==typeof Path2D)return null;Bo||(Bo=new Map);const e=Bo.get(t);if(e)return e;const n=new Path2D(t);return Bo.size>1024&&Bo.clear(),Bo.set(t,n),n}function jo(t,e,n=0,o="horizontal"){const[i,r]=t.viewBox??Fo,s=Math.min(1,Math.max(0,n)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===o?{x:0,y:r*(1-a),width:i,height:r*(a-s)}:{x:i*s,y:0,width:i*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}function Yo(t,e){const n=Eo(t,e);return{centerDx:n.offsetX+n.width/2,centerDy:n.offsetY+n.height/2,halfWidth:n.width/2,halfHeight:n.height/2,radius:Math.hypot(n.width,n.height)/2}}function Xo(t,e,n,o,i,r=t=>t){for(const s of e.parts){const e=Wo(s.d);if(!e)continue;const a=s.opacity??1,l=t.globalAlpha;1!==a&&(t.globalAlpha=l*a);const c=i?"none"===s.fill?void 0:i:No(s.fill,n,o);c&&(t.fillStyle=r(c),t.fill(e));const u=i?s.stroke&&"none"!==s.stroke?i:void 0:No(s.stroke??"none",n,o);u&&(t.strokeStyle=r(u),t.lineWidth=s.strokeWidth??1,t.lineCap=s.strokeLinecap??"butt",t.lineJoin=s.strokeLinejoin??"miter",t.stroke(e)),1!==a&&(t.globalAlpha=l)}}var Ho=new WeakMap,Go=0,qo=!1,Vo=null,Uo=null;function Ko(t,e){if(!e)return e;const n=function(t){const e=t.trim();if(!e.startsWith("var(")||!e.endsWith(")"))return null;const n=e.slice(4,-1),o=n.indexOf(",");if(-1===o){const t=n.trim();return t.startsWith("--")?{name:t}:null}const i=n.slice(0,o).trim(),r=n.slice(o+1).trim();return i.startsWith("--")?{name:i,fallback:r||void 0}:null}(e);if(!n)return e;const o=()=>n.fallback?Ko(t,n.fallback):e,i=t.canvas;if(!i)return o();!function(){if(qo)return;if("undefined"==typeof window||"undefined"==typeof document)return;qo=!0;const t=()=>{Go++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(t).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"],subtree:!0}),"function"==typeof window.matchMedia)try{Vo=window.matchMedia("(prefers-color-scheme: dark)"),Uo=t,"function"==typeof Vo.addEventListener?Vo.addEventListener("change",Uo):"function"==typeof Vo.addListener&&Vo.addListener(Uo)}catch{}}();let r=Ho.get(i);r&&r.version===Go||(r={version:Go,map:new Map},Ho.set(i,r));const s=r.map.get(e);if(void 0!==s)return s;const a=getComputedStyle(i).getPropertyValue(n.name).trim()||o()||e;return r.map.set(e,a),a}function Zo(t){return{type:"hatch",background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle}}var Qo=null;import{jsx as Jo,jsxs as ti}from"react/jsx-runtime";function ei(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function ni(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}var oi=new Map;function ii(t,e){const{background:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,l=Math.max(8,Math.ceil(2*r));return ti("pattern",{id:e,width:l,height:l,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&Jo("rect",{width:l,height:l,fill:n}),Jo("line",{x1:0,y1:0,x2:0,y2:l,stroke:o,strokeWidth:i,strokeOpacity:a}),Jo("line",{x1:r,y1:0,x2:r,y2:l,stroke:o,strokeWidth:i,strokeOpacity:a})]},e)}function ri(t,e,n="#4e79a7"){if(ei(t)){const n=function(t,e){let n=2166136261;const o=ni(e);for(let t=0;o.length>t;t++)n^=o.charCodeAt(t),n=Math.imul(n,16777619);return`${t}-hatch-${(n>>>0).toString(36)}`}(e,t);return{fill:`url(#${n})`,def:ii(t,n)}}return t&&"string"==typeof t?{fill:t}:{fill:n}}import{curveMonotoneX as si,curveMonotoneY as ai,curveCardinal as li,curveCatmullRom as ci,curveStep as ui,curveStepBefore as di,curveStepAfter as hi,curveBasis as fi,curveNatural as pi}from"d3-shape";function gi(t){switch(t){case"monotoneX":return si;case"monotoneY":return ai;case"cardinal":return li;case"catmullRom":return ci;case"step":return ui;case"stepBefore":return di;case"stepAfter":return hi;case"basis":return fi;case"natural":return pi;default:return null}}function yi(t,e,n){if(null==e)return n;if(ei(e)){const o=function(t,e){const n=t.background??"transparent",o=t.stroke??"#000",i="transparent"===n||"none"===n?n:Ko(e,n)||n,r=Ko(e,o)||o||"#000",s="undefined"!=typeof window&&window.devicePixelRatio||1,a=`${ni(t)}|${i}|${r}@${s}`,l=oi.get(a);if(void 0!==l)return l;const c=function(t={},e){const{background:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a={background:n,stroke:o,lineWidth:i,spacing:r,angle:s},l=Math.max(8,Math.ceil(2*r));let c;try{c=function(t){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(t,t):(Qo||(Qo=document.createElement("canvas")),Qo.width=t,Qo.height=t,Qo)}(l)}catch{return Zo(a)}const u=c.getContext("2d");if(!u)return Zo(a);n&&"transparent"!==n?(u.fillStyle=n,u.fillRect(0,0,l,l)):u.clearRect(0,0,l,l),u.strokeStyle=o,u.lineWidth=i,u.lineCap="square";const d=s*Math.PI/180;if(45===s||-45===s){const t=s>0?1:-1;for(let e=-l;2*l>=e;e+=r)u.beginPath(),u.moveTo(e,0),u.lineTo(e+t*l,l),u.stroke()}else{u.save(),u.translate(l/2,l/2),u.rotate(d);const t=2*l;for(let e=-t;t>=e;e+=r)u.beginPath(),u.moveTo(-t,e),u.lineTo(t,e),u.stroke();u.restore()}return(e||u).createPattern(c,"repeat")}({background:i,stroke:r,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle},e),u=ei(c)?null:c;return oi.set(a,u),u}(e,t);return o||e.background&&Ko(t,e.background)||n}return"string"!=typeof e?e:Ko(t,e)||n}function mi(t,e,n,o,i,r,s){const a=e.stops.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity)));if(2>a.length)return null;const l=t.createLinearGradient(o,i,r,s);for(const e of a)l.addColorStop(Math.max(0,Math.min(1,e.offset)),bi(t,e,n));return l}function bi(t,e,n){const o=e.color??n,i=Ko(t,o)||o;if(null==e.opacity)return i;const r=Math.max(0,Math.min(1,e.opacity)),[s,a,l]=function(t,e){const n=t.fillStyle,o="#010203";try{t.fillStyle=o,t.fillStyle=e}catch{return t.fillStyle=n,[78,121,167]}const i=t.fillStyle;if(t.fillStyle=n,"string"!=typeof i)return[78,121,167];if(i.toLowerCase()===o&&e.trim().toLowerCase()!==o)return[78,121,167];if(i.startsWith("#"))return[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16)];const r=i.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?[+r[1],+r[2],+r[3]]:[78,121,167]}(t,i);return`rgba(${s},${a},${l},${r})`}import{line as xi}from"d3-shape";var vi=new WeakMap;function wi(t,e){const n=gi(e);if(!n)return t;const o=vi.get(t);if(o)return o;const i=function(t,e,n=8){if(!e||2>t.length)return t.map(([t,e])=>[t,e]);const o=[];let i=null;const r={moveTo(t,e){i=[t,e],o.push([t,e])},lineTo(t,e){i=[t,e],o.push([t,e])},bezierCurveTo(t,e,r,s,a,l){if(!i)return i=[a,l],void o.push([a,l]);const[c,u]=i;for(let i=1;n>=i;i++){const d=i/n,h=1-d;o.push([h*h*h*c+3*h*h*d*t+3*h*d*d*r+d*d*d*a,h*h*h*u+3*h*h*d*e+3*h*d*d*s+d*d*d*l])}i=[a,l]},closePath(){},arc(){},rect(){},arcTo(){},quadraticCurveTo(t,e,n,r){i=[n,r],o.push([n,r])}};return xi().x(t=>t[0]).y(t=>t[1]).curve(e).context(r)(t),o}(t,n);return vi.set(t,i),i}function ki(t,e,n,o=30,i,r=0){let s=null;if(i){const t=function(t,e,n,o,i,r=t=>t.x,s=t=>t.y,a=t=>t.r){const l=Math.max(o,i+5,12),c=e-l,u=e+l,d=n-l,h=n+l;let f=null,p=1/0;return t.visit((t,i,l,g,y)=>{if(i>u||c>g||l>h||d>y)return!0;if(!t.length){let i=t;do{const t=i.data,l=r(t)-e,c=s(t)-n,u=Math.sqrt(l*l+c*c);$o(a(t),o)>=u&&p>u&&(f=t,p=u),i=i.next}while(i)}return!1}),f?{node:f,distance:p}:null}(i,e,n,o,r);t&&(s={node:t.node,datum:t.node.datum,x:t.node.x,y:t.node.y,distance:t.distance})}for(const r of t){let t=null;switch(r.type){case"point":if(i)break;t=Ai(r,e,n,o);break;case"symbol":t=Mi(r,e,n,o);break;case"glyph":t=_i(r,e,n,o);break;case"line":t=Pi(r,e,n,o);break;case"rect":if(null==r.datum)break;t=Li(r,e,n);break;case"heatcell":t=Ri(r,e,n);break;case"area":if(!1===r.interactive)break;t=Ii(r,e,n);break;case"candlestick":t=Ti(r,e,n)}t&&o>t.distance&&(s&&t.distance>=s.distance||(s=t))}return s}function Si(t,e,n){if(0===t.length)return null;if(t[0][0]>e||e>t[t.length-1][0])return null;const o=$i(t,e);if(0>o)return null;if(Math.abs(t[o][0]-e)>n)return null;let i=o,r=o;o>0&&t[o][0]>=e?(i=o-1,r=o):t.length-1>o&&(i=o,r=o+1);const[s,a]=t[i],[l,c]=t[r];return l===s?a:a+Math.max(0,Math.min(1,(e-s)/(l-s)))*(c-a)}function Ai(t,e,n,o=30){const i=e-t.x,r=n-t.y,s=Math.sqrt(i*i+r*r);return s>$o(t.r,o)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function Mi(t,e,n,o=30){const i=e-t.x,r=n-t.y,s=Math.sqrt(i*i+r*r);return s>$o(wn(t.size),o)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function _i(t,e,n,o=30){if(null==t.datum)return null;const i=Yo(t.glyph,t.size),r=t.x+i.centerDx,s=t.y+i.centerDy,a=e-r,l=n-s,c=Math.sqrt(a*a+l*l);return c>$o(i.radius,o)?null:{node:t,datum:t.datum,x:r,y:s,distance:c}}function Pi(t,e,n,o=30){if(0===t.path.length)return null;const i=$i(t.path,e);if(0>i)return null;const[r,s]=t.path[i];let a;if(t.path.length>1){let o=1/0;const r=Math.max(0,i-1),s=Math.min(t.path.length-2,i);for(let i=r;s>=i;i++){const[r,s]=t.path[i],[a,l]=t.path[i+1],c=Ci(e,n,r,s,a,l);o>c&&(o=c)}a=o}else{const t=e-r,o=n-s;a=Math.sqrt(t*t+o*o)}const l=t.style;return a>Math.max(5,(l.strokeWidth??l.lineWidth??1)/2+2,o)?null:{node:t,datum:Array.isArray(t.datum)&&t.datum[i]?t.datum[i]:t.datum,x:r,y:s,distance:a}}function Ci(t,e,n,o,i,r){const s=i-n,a=r-o,l=s*s+a*a;if(0===l)return Math.sqrt((t-n)**2+(e-o)**2);let c=((t-n)*s+(e-o)*a)/l;return c=Math.max(0,Math.min(1,c)),Math.sqrt((t-(n+c*s))**2+(e-(o+c*a))**2)}function Li(t,e,n){const o=Io(e,n,t);return o.hit?{node:t,datum:t.datum,x:o.cx,y:o.cy,distance:0}:null}function Ri(t,e,n){const o=Io(e,n,t);return o.hit?{node:t,datum:t.datum,x:o.cx,y:o.cy,distance:0}:null}function Ti(t,e,n){const o=t.bodyWidth/2,i=Math.min(t.openY,t.closeY);if(!(t.x-o-3>e||e>t.x+o+3||t.highY-3>n||n>t.lowY+3)){const o=i+Math.max(Math.max(t.openY,t.closeY)-i,1)/2,r=e-t.x,s=n-o;return{node:t,datum:t.datum,x:t.x,y:o,distance:Math.sqrt(r*r+s*s)}}return null}function Ii(t,e,n){if(0===t.topPath.length)return null;const o=$i(t.topPath,e);if(0>o)return null;const[i,r]=t.topPath[o],s=e-i,a=n-r,l=Math.sqrt(s*s+a*a);return{node:t,datum:Array.isArray(t.datum)&&t.datum[o]?t.datum[o]:t.datum,x:i,y:r,distance:l}}function $i(t,e){if(0===t.length)return-1;let n=0,o=t.length-1;for(;o>n;){const i=n+o>>1;e>t[i][0]?n=i+1:o=i}return n>0&&Math.abs(t[n][0]-e)>=Math.abs(t[n-1][0]-e)?n-1:n}import{useEffect as Oi,useRef as zi}from"react";var Fi={fresh:1,aging:.7,stale:.45,expired:.25},Di={alpha:1,band:"fresh",isStale:!1};function Ei(t,e){if(!t||0>=e)return Di;const n=null!=t.threshold&&t.threshold>0?t.threshold:5e3,o=t.graded;if(o){const t="object"==typeof o?o:{},r=i(e,n,t.thresholds);return{alpha:{...Fi,...t.opacities??{}}[r],band:r,isStale:"fresh"!==r}}return e>n?{alpha:t.dimOpacity??.5,band:"stale",isStale:!0}:Di}import{jsx as Ni}from"react/jsx-runtime";function Bi({isStale:t,position:e}){return Ni("div",{className:"stream-staleness-badge",style:{position:"absolute",..."top-left"===e?{top:4,left:4}:"bottom-left"===e?{bottom:4,left:4}:"bottom-right"===e?{bottom:4,right:4}:{top:4,right:4},padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",zIndex:3,background:t?"#dc3545":"#28a745",color:"white"},children:t?"STALE":"LIVE"})}import{useMemo as Wi,useRef as ji,useEffect as Yi}from"react";import*as Xi from"react";function Hi(...t){let e;for(const n of t)n&&(e=Gi(e)&&Gi(n)?{legendGroups:[...e.legendGroups,...n.legendGroups],legendDistance:n.legendDistance??e.legendDistance}:n);return e}function Gi(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function qi(t){return"object"==typeof t&&null!==t&&"gradient"in t}function Vi(t){return Math.ceil(7*t.length)}function Ui(t,e){if(Gi(t)){const n=er(e),o=t.legendGroups.flatMap(t=>[t.label?Vi(t.label):0,...t.items.map(t=>n.swatchSize+n.labelGap+Vi(t.label))]);return Math.max(100,...o)}if(qi(t)){const{gradient:e}=t,n=e.format||(t=>Math.round(100*t)/100+""),o=Math.max(Vi(n(e.domain[0])),Vi(n(e.domain[1]))),i=e.label?Vi(e.label):0;return Math.max(100,19+o,i)}return 100}function Ki(t){return(Gi(t)||qi(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function Zi(t){return Math.max(0,t?.sideGutter??0)}function Qi(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function Ji(t,e,n){if(qi(t))return t.gradient.label?34:26;if(!Gi(t))return 20;const o=er(n),i=Math.max(1,n?.maxWidth??e);let r=o.rowHeight;for(const e of t.legendGroups){let t=0,n=0;for(const r of e.items){const e=o.swatchSize+o.labelGap+Vi(r.label),s=0===n?e:n+o.itemGap+e;n>0&&s>i?(t+=1,n=e):n=s}e.items.length>0&&(t+=1),r=Math.max(r,t*o.rowHeight,e.label?Vi(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function tr(t,e){return Ui(t,e)+Ki(t)+Zi(e)}function er(t){const e=Math.max(1,t?.swatchSize??16),n=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:n,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function nr(t,e){let n=24;return t.map(({hasLabel:t,itemCount:o})=>{n+=5;const i=n;let r;n+=8,t&&(n+=16,r=n,n+=8);const s=n;return n+=o*e+8,{lineY:i,labelY:r,itemsY:s,endY:n}})}import{jsx as or,jsxs as ir}from"react/jsx-runtime";var rr={fill:(t,e)=>or("rect",{style:t,width:e,height:e}),line:(t,e)=>or("line",{style:t,x1:0,y1:0,x2:e,y2:e})};function sr(t,e,n,o,i){let r;return r="function"==typeof n?n(t):(0,rr[n])(o(t,e),i),r}function ar({swatchSize:t}){return or("path",{d:`M${.25*t},${.55*t} L${.45*t},${.75*t} L${.8*t},${.3*t}`,fill:"none",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}function lr(t,e,n){return n&&n.size>0?n.has(t.label)?1:.3:null!=e?t.label===e?1:.3:1}var cr=(t,e,n,o,i,r,s,a,l,c,u)=>{const{type:d="fill",styleFn:h,items:f}=t,p=[];let g=0;const y=!(!e&&!n),m="isolate"===c||void 0===c&&null!=i,{swatchSize:b,labelGap:x,rowHeight:v}=u;return f.forEach((t,c)=>{const u=sr(t,c,d,h,b),w=lr(t,o,i),k=i&&i.size>0&&i.has(t.label);p.push(ir("g",{transform:`translate(0,${g})`,onClick:e?()=>e(t):void 0,onMouseEnter:n?()=>n(t):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===r&&c===s?0:-1:void 0,role:y?"option":void 0,"aria-selected":y&&m?k||!1:void 0,"aria-current":y&&!m&&null!=o&&t.label===o||void 0,"aria-label":t.label,onKeyDown:y?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),e&&e(t)),"ArrowDown"===n.key||"ArrowUp"===n.key){n.preventDefault();const t=(c+("ArrowDown"===n.key?1:-1)+f.length)%f.length;l(a,t);const e=n.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:y?e=>{l(a,c),n&&n(t);const o=e.currentTarget.querySelector(".semiotic-legend-focus-ring");o&&o.setAttribute("visibility","visible")}:void 0,onBlur:y?t=>{n&&n(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:y?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[y&&or("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:b+x+2+7*t.label.length,height:b+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),u,k&&or(ar,{swatchSize:b}),or("text",{y:b/2,x:b+x,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+c)),g+=v}),p};function ur({config:t,orientation:e="vertical",width:n=100}){const{colorFn:o,domain:i,label:r,format:s}=t,a=s||(t=>Math.round(100*t)/100+""),l="grad-legend-"+Xi.useId();if("horizontal"===e){const t=12,e=Math.min(n,200),s=Math.max(0,(n-e)/2),c=[];for(let t=0;64>=t;t++){const e=t/64;c.push(or("stop",{offset:100*e+"%",stopColor:o(i[0]+e*(i[1]-i[0]))},t))}return ir("g",{"aria-label":r||"Gradient legend",children:[or("defs",{children:or("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),r&&or("text",{x:s+e/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),or("rect",{x:s,y:0,width:e,height:t,fill:`url(#${l})`,rx:2}),or("text",{x:s,y:t+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])}),or("text",{x:s+e,y:t+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])})]})}const c=[];for(let t=0;64>=t;t++){const e=t/64;c.push(or("stop",{offset:100*e+"%",stopColor:o(i[1]-e*(i[1]-i[0]))},t))}return ir("g",{"aria-label":r||"Gradient legend",children:[r&&or("text",{x:0,y:-6,textAnchor:"start",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),or("defs",{children:or("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),or("rect",{x:0,y:0,width:14,height:100,fill:`url(#${l})`,rx:2}),or("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])}),or("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])})]})}function dr(t){const{legendGroups:e,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:l=100,height:c=20,orientation:u="vertical",legendLayout:d}=t,h=er(d),[f,p]=Xi.useState(0),[g,y]=Xi.useState(0),m=Xi.useCallback((t,e)=>{p(t),y(e)},[]),b="vertical"===u?(({legendGroups:t,width:e,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:l,legendInteraction:c,metrics:u})=>{const d=[],h=nr(t.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),u.rowHeight);return t.forEach((t,f)=>{const p=h[f];d.push(or("line",{stroke:"gray",x1:0,y1:p.lineY,x2:e,y2:p.lineY},"legend-top-line legend-symbol-"+f)),t.label&&null!=p.labelY&&d.push(or("text",{y:p.labelY,className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label},"legend-text-"+f)),d.push(or("g",{className:"legend-item",transform:`translate(0,${p.itemsY})`,children:cr(t,n,o,i,r,s,a,f,l,c,u)},"legend-group-"+f))}),d})({legendGroups:e||[],width:l,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:g,onFocusedIndexChange:m,legendInteraction:s,metrics:h}):(({legendGroups:t,height:e,width:n,customClickBehavior:o,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:l,onFocusedIndexChange:c,legendInteraction:u,metrics:d})=>{let h=0;const f=[];t.forEach((t,e)=>{let p=0;t.label&&(p+=16);const g=((t,e,n,o,i,r,s,a,l,c,u,d)=>{const{type:h="fill",styleFn:f,items:p}=t,g=[],{swatchSize:y,labelGap:m,itemGap:b,rowHeight:x,align:v}=u,w=!(!e&&!n),k="isolate"===c||void 0===c&&null!=i,S=p.map(t=>y+m+7*t.label.length),A=[];let M=0,_=0;S.forEach((t,e)=>{const n=0===_?t:_+b+t;d&&d>0&&_>0&&n>d?(A.push({start:M,end:e,width:_}),M=e,_=t):_=n}),p.length>0&&A.push({start:M,end:p.length,width:_}),A.forEach((t,c)=>{let u="center"===v?Math.max(0,((d??t.width)-t.width)/2):"end"===v?Math.max(0,(d??t.width)-t.width):0;for(let d=t.start;t.end>d;d++){const t=p[d],v=sr(t,d,h,f,y),A=lr(t,o,i),M=i&&i.size>0&&i.has(t.label);g.push(ir("g",{transform:`translate(${u},${c*x})`,onClick:e?()=>e(t):void 0,onMouseEnter:n?()=>n(t):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===r&&d===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?M||!1:void 0,"aria-current":w&&!k&&null!=o&&t.label===o||void 0,"aria-label":t.label,onKeyDown:w?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),e&&e(t)),"ArrowRight"===n.key||"ArrowLeft"===n.key){n.preventDefault();const t=(d+("ArrowRight"===n.key?1:-1)+p.length)%p.length;l(a,t);const e=n.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:w?e=>{l(a,d),n&&n(t);const o=e.currentTarget.querySelector(".semiotic-legend-focus-ring");o&&o.setAttribute("visibility","visible")}:void 0,onBlur:w?t=>{n&&n(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:A,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&or("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:y+m+2+7*t.label.length,height:y+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,M&&or(ar,{swatchSize:y}),or("text",{y:y/2,x:y+m,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+d)),u+=S[d]+b}});const P=Math.max(0,...A.map(t=>t.width)),C=A.length;return{items:g,offset:P,totalRows:C,totalHeight:C*x}})(t,o,i,r,s,a,l,e,c,u,d,d.maxWidth??n);p+=g.offset+5,f.push({label:t.label,...g,offset:p,totalRows:g.totalRows,totalHeight:g.totalHeight}),h+=p+12});const p=d.maxWidth??n;let g=h>p?0:"center"===d.align?Math.max(0,(p-h)/2):"end"===d.align?Math.max(0,p-h):0;const y=[];return f.forEach((n,o)=>{const i=t[o];i.label&&(y.push(or("text",{transform:`translate(${g},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:i.label},"legend-text-"+o)),g+=16),y.push(or("g",{className:"legend-item",transform:`translate(${g},0)`,children:n.items},"legend-group-"+o)),g+=n.offset+5,t[o+1]&&y.push(or("line",{stroke:"gray",x1:g,y1:-8,x2:g,y2:(n.totalHeight||e)+0+8},"legend-top-line legend-symbol-"+o)),g+=12}),or("g",{children:y})})({legendGroups:e||[],title:a,height:c,width:l,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:g,onFocusedIndexChange:m,legendInteraction:s,metrics:h}),x=!(!n&&!o);return ir("g",{role:x?"listbox":void 0,"aria-multiselectable":!(!x||"isolate"!==s&&(void 0!==s||null==r))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===u&&or("text",{className:"legend-title",y:16,x:l/2,textAnchor:"middle",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}import{jsx as hr}from"react/jsx-runtime";function fr(t){const{legend:e,totalWidth:n,totalHeight:o,margin:i,legendPosition:r="right",legendLayout:s,legendHoverBehavior:a,legendClickBehavior:l,legendHighlightedCategory:c,legendIsolatedCategories:u,legendInteraction:d}=t;if(!e)return null;const h="top"===r||"bottom"===r,f=Math.max(0,n-i.left-i.right),p=Math.max(1,h?s?.maxWidth??f:Ui(e,s)),g=Ki(e),y=Zi(s),m=Qi(t.axisChrome,s),b=Qi(void 0,s),x=Ji(e,f,s);let v,w;if("left"===r)v=i.left-y-p-g,w=i.top;else if("top"===r)v=i.left,w=i.top-b-g-x;else if("bottom"===r){v=i.left;const t=o-i.bottom;w=Math.max(t+g,Math.min(t+m+g,o-x))}else v=n-i.right+y+g,w=i.top;return hr("g",{transform:`translate(${v}, ${w})`,children:qi(e)?hr(ur,{config:e.gradient,orientation:h?"horizontal":"vertical",width:p}):Gi(e)?hr(dr,{legendGroups:e.legendGroups,title:"",width:p,orientation:h?"horizontal":"vertical",legendLayout:s,customHoverBehavior:a,customClickBehavior:l,highlightedCategory:c,isolatedCategories:u,legendInteraction:d}):e})}import{useMemo as pr}from"react";import{bin as gr}from"d3-array";import{jsx as yr,jsxs as mr}from"react/jsx-runtime";function br(t){return"string"==typeof t?{type:t}:t}function xr({orient:t,config:e,values:n,scale:o,size:i,length:r}){const s=function(t){return{type:t.type,bins:t.bins??20,fill:t.fill??"#4e79a7",fillOpacity:t.fillOpacity??.5,stroke:t.stroke??"none",strokeWidth:t.strokeWidth??1}}(e),a="top"===t||"bottom"===t,l=pr(()=>{if(0===n.length)return null;const e=o.domain(),l=i-8;if("boxplot"===s.type){const e=function(t){const e=[...t].sort((t,e)=>t-e),n=e.length;if(0===n)return null;const o=e[Math.floor(.25*n)],i=e[Math.floor(.5*n)],r=e[Math.floor(.75*n)],s=r-o;return{q1:o,median:i,q3:r,whiskerLow:Math.max(e[0],o-1.5*s),whiskerHigh:Math.min(e[n-1],r+1.5*s)}}(n);if(!e)return null;const{q1:i,median:r,q3:c,whiskerLow:u,whiskerHigh:d}=e,h=Math.min(.5*l,20),f=(l-h)/2+4;if(a){const e=o(i),n=o(c),a=o(r),l=o(u),p=o(d),g="top"===t?-1:1,y=0;return mr("g",{"data-testid":"marginal-boxplot-"+t,children:[yr("line",{x1:l,y1:y+g*(f+h/2),x2:p,y2:y+g*(f+h/2),stroke:s.fill,strokeWidth:s.strokeWidth}),yr("line",{x1:l,y1:y+g*f,x2:l,y2:y+g*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),yr("line",{x1:p,y1:y+g*f,x2:p,y2:y+g*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),yr("rect",{x:Math.min(e,n),y:"top"===t?y-f-h:y+f,width:Math.abs(n-e),height:h,fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),yr("line",{x1:a,y1:"top"===t?y-f-h:y+f,x2:a,y2:"top"===t?y-f:y+f+h,stroke:s.fill,strokeWidth:2})]})}{const e=o(i),n=o(c),a=o(r),l=o(u),p=o(d),g="left"===t?-1:1,y=0;return mr("g",{"data-testid":"marginal-boxplot-"+t,children:[yr("line",{x1:y+g*(f+h/2),y1:l,x2:y+g*(f+h/2),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),yr("line",{x1:y+g*f,y1:l,x2:y+g*(f+h),y2:l,stroke:s.fill,strokeWidth:s.strokeWidth}),yr("line",{x1:y+g*f,y1:p,x2:y+g*(f+h),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),yr("rect",{x:"left"===t?y-f-h:y+f,y:Math.min(e,n),width:h,height:Math.abs(n-e),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),yr("line",{x1:"left"===t?y-f-h:y+f,y1:a,x2:"left"===t?y-f:y+f+h,y2:a,stroke:s.fill,strokeWidth:2})]})}}const c=gr().domain(e).thresholds(s.bins)(n);if(0===c.length)return null;const u=Pt(c.map(t=>t.length));if(0===u)return null;if("histogram"===s.type)return yr("g",{"data-testid":"marginal-histogram-"+t,children:c.map((e,n)=>{if(null==e.x0||null==e.x1)return null;const i=e.length/u*l;if(a){const r=o(e.x0),a=o(e.x1)-o(e.x0);return yr("rect",{x:r,y:"top"===t?-4-i:4,width:Math.max(a,.5),height:i,fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},n)}{const r=o(e.x0),a=o(e.x1)-o(e.x0);return yr("rect",{x:"left"===t?-4-i:4,y:Math.min(r,r+a),width:i,height:Math.abs(a),fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},n)}})});if("violin"===s.type){const e=l/2+4,n=[];for(const i of c){if(null==i.x0||null==i.x1)continue;const r=i.length/u*(l/2),s=o((i.x0+i.x1)/2);n.push(a?`${s},${"top"===t?-(e-r):e-r}`:`${"left"===t?-(e-r):e-r},${s}`)}for(let i=c.length-1;i>=0;i--){const r=c[i];if(null==r.x0||null==r.x1)continue;const s=r.length/u*(l/2),d=o((r.x0+r.x1)/2);n.push(a?`${d},${"top"===t?-(e+s):e+s}`:`${"left"===t?-(e+s):e+s},${d}`)}return yr("g",{"data-testid":"marginal-violin-"+t,children:yr("polygon",{points:n.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}if("ridgeline"===s.type){const e=[];if(a){const n=0,i=null!=c[0].x0?o(c[0].x0):0;e.push(`M${i},${n}`);for(const n of c){if(null==n.x0||null==n.x1)continue;const i=n.length/u*l,r=o((n.x0+n.x1)/2);e.push(`L${r},${"top"===t?-i-4:i+4}`)}const s=null!=c[c.length-1].x1?o(c[c.length-1].x1):r;e.push(`L${s},${n}`),e.push("Z")}else{const n=0,i=null!=c[0].x0?o(c[0].x0):0;e.push(`M${n},${i}`);for(const n of c){if(null==n.x0||null==n.x1)continue;const i=n.length/u*l,r=o((n.x0+n.x1)/2);e.push(`L${"left"===t?-i-4:i+4},${r}`)}const s=null!=c[c.length-1].x1?o(c[c.length-1].x1):r;e.push(`L${n},${s}`),e.push("Z")}return yr("g",{"data-testid":"marginal-ridgeline-"+t,children:yr("path",{d:e.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}return null},[n,o,s,i,r,t,a,4]);return l?yr("g",{className:"marginal-"+t,"data-testid":"marginal-"+t,children:l}):null}import*as vr from"react";import{jsx as wr,jsxs as kr}from"react/jsx-runtime";function Sr(t,e=120,n=8){if(!t)return[];const o=Math.max(1,Math.floor(e/n)),i=t.split(/\s+/),r=[];let s="";for(const t of i)s&&s.length+1+t.length>o?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function Ar(t,e,n,o){return"curly"===t?o?`M0,0 C${.6*n},0 ${.4*n},${e/2} ${n},${e/2} C${.4*n},${e/2} ${.6*n},${e} 0,${e}`:`M0,0 C0,${.6*n} ${e/2},${.4*n} ${e/2},${n} C${e/2},${.4*n} ${e},${.6*n} ${e},0`:o?`M0,0 L${n},0 L${n},${e} L0,${e}`:`M0,0 L0,${n} L${e},${n} L${e},0`}function Mr(t,e,n,o){if(!t)return wr("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return wr("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(n)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>n?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const f=16,p=r?c?[r]:Sr(r,l):[],g=i?c?[i]:Sr(i,l):[],y="leftRight"===u?"end"===h?-4:4:0;let m=0;const b=[],x=o||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?b.push(wr("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(f,(p.length+g.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:kr("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:x,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&wr("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&wr("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(b.push(wr("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>wr("tspan",{x:y,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),g.length>0&&b.push(wr("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:m,children:g.map((t,e)=>wr("tspan",{x:y,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==n))if("topBottom"===u){const t=Math.min(l,120);let e=0,n=t;"end"===h?(e=-t,n=0):"middle"===h&&(e=-t/2,n=t/2),v=wr("line",{className:"note-line",x1:e,x2:n,y1:0,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+g.length)*f+(g.length>0?f:0);let e=0,n=t;"bottom"===d?(e=-t,n=0):"middle"===d&&(e=-t/2,n=t/2),v=wr("line",{className:"note-line",x1:0,x2:0,y1:e,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+g.length-1)*f;let k=0;return"topBottom"===u?k=0>n?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(g.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>n?-(w+2):18),kr("g",{className:"annotation-note",transform:`translate(${e},${n})`,children:[wr("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function _r(t,e,n,o,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(wr("circle",{r:t,fill:"none",stroke:n||"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(wr("rect",{width:t,height:o,fill:"none",stroke:n||"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=i||0;if(void 0!==e?.x){const o=(e.x||0)-t;r.push(wr("line",{x1:o,y1:(e.y1||0)-s,x2:o,y2:(e.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const o=(e.y||0)-s;r.push(wr("line",{x1:(e.x1||0)-t,y1:o,x2:(e.x2||0)-t,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(wr("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(wr("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:n||"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(wr("path",{d:Ar(t,o,e?.depth||30,void 0===e?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return wr("g",{className:"annotation-subject",children:r})}function Pr(t,e,n,o,i,r){const s=[];let a=0,l=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const n=r.width||0,o=r.height||0;if(n>0||o>0){const i=n/2,r=o/2,s=t-i,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=n/2,d=o/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,n=r.depth||30;void 0!==t?(a=t/2,l=n):void 0!==e&&(a=n,l=e/2)}}else{const n=(r.radius||0)+(r.radiusPadding||0);if(n>0&&(0!==t||0!==e)){const o=Math.atan2(e,t);a=Math.cos(o)*n,l=Math.sin(o)*n}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=o||"var(--semiotic-text-secondary, currentColor)",r="curve"===n?.type;let u=Math.atan2(e-l,t-a);if(r){const o=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,f=(n?.curve??.25)*c,p=o+d*f,g=r+h*f;s.push(wr("path",{className:"connector-curve",d:`M${a},${l}Q${p},${g} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,p-a)}else s.push(wr("line",{x1:a,y1:l,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===n?.end){const t=10,e=16/180*Math.PI;s.push(wr("path",{d:`M${a},${l}L${a+t*Math.cos(u+e)},${l+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${l+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return wr("g",{className:"annotation-connector",children:s})}function Cr(t){const{x:e=0,y:n=0,dx:o,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:g,events:y={},"data-testid":m}=t,b=Array.isArray(e)?e[0]??0:e,x=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(f)?f:[]);let w=o||0,k=i||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const S="string"==typeof u?u:"label";if("bracket"===S&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const t=c.depth||30;k=t+(0>t?-5:5)}else if(void 0!==c.height){const t=c.depth||30;w=t+(0>t?-5:5),k=c.height/2}return kr("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":m,...null!=p&&{opacity:p},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&Pr(w,k,l,d,S,c),!v.has("subject")&&_r(S,c,d,b,x),!v.has("note")&&Mr(a,w,k,d)]})}function Lr(t){const{noteData:e}=t,{screenCoordinates:n}=e,o="string"==typeof e.type?e.type:"label",i=e.eventListeners||e.events||{};if(e.coordinates&&n){const t=e.nx||n[0][0]+(e.dx??0),i=e.ny||n[0][1]+(e.dy??0),r=n.map((n,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:n[0],y:n[1],nx:t,ny:i});return wr(Cr,{"data-testid":"semiotic-annotation",...s,type:o},"multi-annotation-"+r)});return wr("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return wr(Cr,{"data-testid":"semiotic-annotation",events:i,...e,type:o},s)}import{packEnclose as Rr}from"d3-hierarchy";import{area as Tr,curveLinear as Ir,curveMonotoneX as $r,curveMonotoneY as Or,curveStep as zr,curveStepAfter as Fr,curveStepBefore as Dr,curveBasis as Er,curveCardinal as Nr,curveCatmullRom as Br}from"d3-shape";function Wr(t,e){const n=e.scales?.x??e.scales?.time;return n?null!=t.x?n(t.x):e.xAccessor&&null!=t[e.xAccessor]?n(t[e.xAccessor]):null:null}function jr(t,e){const n=e.scales?.y??e.scales?.value;return n?null!=t.y?n(t.y):e.yAccessor&&null!=t[e.yAccessor]?n(t[e.yAccessor]):null:null}function Yr(t){return null==t?null:t+""}function Xr(t,e,n){return e.stickyPositionCache?.set(t,n),n}function Hr(t,e,n){const o=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===o){if(null!=t.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let o=n.pointNodes.length-1;o>=0;o--){const i=n.pointNodes[o];if(i.pointId===t.pointId)return Xr(e,n,{x:i.x,y:i.y})}const o=function(t){const e=t.data;if(!e||0===e.length)return null;const n=e[e.length-1],o=t.scales?.x??t.scales?.time,i=t.scales?.y??t.scales?.value;if(!o||!i)return null;const r=n[t.xAccessor||"x"],s=n[t.yAccessor||"y"];return null==r||null==s?null:{x:o(r),y:i(s)}}(n);return o?Xr(e,n,o):null}if("semantic"===o){const o=function(t,e,n){const o=function(t){return Yr(t.provenance?.stableId??t.stableId)}(t);if(!o)return null;const i=n.pointNodes?.find(t=>Yr(t.pointId)===o);if(i)return Xr(e,n,{x:i.x,y:i.y});const r=n.data?.find(t=>function(t){return Yr(t.stableId??t.id??t.provenance?.stableId)}(t)===o);if(!r)return null;const s=Wr(r,n),a=jr(r,n);return null==s||null==a?null:Xr(e,n,{x:s,y:a})}(t,e,n);if(o)return o}let i=null,r=null;if(null!=t.pointId&&n.pointNodes){const e=n.pointNodes.find(e=>e.pointId===t.pointId);e&&(i=e.x,r=e.y)}if(null!=i&&null!=r||(i=Wr(t,n),r=jr(t,n)),null!=i&&null!=r)return Xr(e,n,{x:i,y:r});if("sticky"===o){const t=n.stickyPositionCache?.get(e);if(t)return t}return null}function Gr(t,e,n,o=50){return!(-o>t||t>(n.width||0)+o||-o>e||e>(n.height||0)+o)}import{jsx as qr}from"react/jsx-runtime";var Vr={secondary:0,primary:3};function Ur(t){return!0===t?._annotationDeferred}function Kr(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Zr(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Qr(t){return Math.max(.72,.95-.06*t)}import{jsx as Jr,jsxs as ts}from"react/jsx-runtime";var es="var(--semiotic-bg, #ffffff)";function ns(t){const{x:e,y:n,text:o,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),f=t=>Jr("text",{x:e,y:n,textAnchor:l,dominantBaseline:c,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}:{},children:o});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??es,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},g="number"==typeof p?p:p.x,y="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(o,r),b=r+2*y;let x,v;return x="middle"===l?e-m/2-g:"end"===l?e-m-g:e-g,v="middle"===c||"central"===c?n-b/2:"hanging"===c||"text-before-edge"===c?n-y:n-.8*r-y,ts("g",{className:d,children:[Jr("rect",{x:x,y:v,width:m+2*g,height:b,rx:h.radius??3,ry:h.radius??3,fill:h.fill??es,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}import{jsx as os,jsxs as is}from"react/jsx-runtime";var rs={linear:Ir,monotoneX:$r,monotoneY:Or,step:zr,stepAfter:Fr,stepBefore:Dr,basis:Er,cardinal:Nr,catmullRom:Br};function ss(t,e,n,o){const i=[];return t.forEach((t,r)=>{let s;if(n){const i=n(t,r,o);s=null!=i?i:e(t,r,o)}else s=e(t,r,o);s&&i.push({node:s,annotation:t})}),function(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(n=t.annotation,"primary"===n?.emphasis||"secondary"===n?.emphasis?n.emphasis:null),confidence:Zr(t.annotation),readingOrder:null,rank:1};var n}),n=e.some(t=>null!=t.emphasis||null!=t.confidence),o=t.some(t=>Ur(t.annotation)),i=t.some(t=>null!=Kr(t.annotation)),r=t.some(t=>"layer"===Kr(t.annotation));if(!n&&!o&&!i)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=Vr[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:n,emphasis:o,readingOrder:i}=t,r=Ur(e.annotation);let s=e.node;if("primary"===o||"secondary"===o||null!=i){const t=null==o&&null!=i;s=qr("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+o,..."secondary"===o?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:Qr(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+n)}const a=Kr(e.annotation);return a&&(s=qr("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),r&&(s=qr("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return o&&a.unshift(qr("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(qr("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}(i)}var as=32,ls=6,cs=4,us=8,ds=72;var hs={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function fs(t){if(!ps(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 ps(t){return u(t)}function gs(t,e){if(!t)return[];const n=Math.max(1,Math.floor(e/7)),o=t.split(/\s+/).filter(Boolean),i=[];let r="";for(const t of o)r&&r.length+t.length+1>n?(i.push(r),r=t):r=r?`${r} ${t}`:t;return r&&i.push(r),i}function ys(t,e,n,o,i){const r=t+n,s=e+o;return Math.abs(n)>Math.abs(o)?{x:0>n?r-i.width-4:r+4,y:0>o?s-i.height:s,width:i.width,height:i.height}:{x:0>n?r-i.width:r,y:0>o?s-i.height-4:s+4,width:i.width,height:i.height}}function ms(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function bs(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 xs(t,e,n,o,i,r,s,a){const l=ms(t,s);let c=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,n,o){const i=Math.max(0,o-t.x),r=Math.max(0,o-t.y);return(i+Math.max(0,t.x+t.width-(e-o)))*t.height+(r+Math.max(0,t.y+t.height-(n-o)))*t.width}(l,i,r,a);for(const t of n)c+=12*bs(l,t);for(const t of o)c+=4*bs(l,t);return c}function vs(t){const{annotations:e,context:i,defaultOffset:r=as,notePadding:s=ls,markPadding:a=cs,edgePadding:l=us,preserveManualOffsets:c=!0,routeLongConnectors:u=!0,connectorThreshold:d=ds,density:h,progressiveDisclosure:f=!1,redundantCues:p=!1,responsive:g,mobile:y,cohesion:m,audience:b}=t,x=i.width||0,v=i.height||0,w="object"==typeof y?y:{},k=w.breakpoint??480,S=!!y&&k>=x,A=S&&!1!==w.preferShortText?e.map(fs):e,M=S&&!h?{maxAnnotations:w.maxAnnotations??("callout-list"===w.strategy?1:2),minVisible:w.minVisible??1}:h,_=f||S&&(!1!==w.progressiveDisclosure||"callout-list"===w.strategy),P=S&&!g?w.responsive??{minWidth:k}:g,C=S&&!m?w.cohesion:m;if(0===A.length||0>=x||0>=v)return A.slice();const L=[],R=function(t,e){return(t.pointNodes||[]).map(t=>{const n=Math.max(1,t.r||1)+e;return{x:t.x-n,y:t.y-n,width:2*n,height:2*n}})}(i,a);let T=!1;const I=A.map((t,e)=>{if(!ps(t))return t;const n=function(t,e,n){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&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===o);if(t)return{x:t.x,y:t.y}}const i=t.coordinates,r=n.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&r){const t=i[0],e=i[1];if("number"==typeof t&&"number"==typeof e){const n=r([t,e]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof t.x||"number"!=typeof t.y?Hr(t,e,n):{x:t.x,y:t.y}}(t,e,i);if(!n)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,n=[...gs("string"==typeof t.title?t.title:void 0,e),...gs("string"==typeof t.label?t.label:void 0,e)],o=n.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*n.length+6)}}(t);if(c&&("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 L.push(ms(ys(n.x,n.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,o),s)),t}var a;let h=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=xs(ys(n.x,n.y,t.dx,t.dy,o),t,L,R,x,v,s,l);f>e&&(h=t,f=e)}if(!h)return t;const p=ms(ys(n.x,n.y,h.dx,h.dy,o),s);L.push(p);const g=Math.hypot(h.dx,h.dy),y=u&&g>=d&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return T=!0,{...t,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),$=T?I:A.slice();let O=$;if(p){let t=!1;const e=$.map(e=>{const n=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 n!==e&&(t=!0),n});O=t?e:$}{let t=!1;const e=O.map(e=>{if(!0!==e?.defensive)return e;const n=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const n="string"==typeof e.source?hs[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(!n&&!o)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const i=[n,o].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${i})`)?t:{...t,label:r?`${r} (${i})`:`(${i})`}}(e);return n!==e&&(t=!0),n});O=t?e:O}const z=new Set;if(M){const t="object"==typeof M?M:{},e=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return 3;const n=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===n.length?3:n.reduce((t,e)=>t+e,0)/n.length}(t);return e>2?4>e?1:.6:1.5}(b),i=1===e?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??n(x,v,t))*e))},{deferred:r}=o({annotations:O,width:x,height:v,...i});for(const t of r)z.add(t)}if(P&&("object"==typeof P&&"number"==typeof P.minWidth?P.minWidth:480)>=x)for(const t of O)ps(t)&&"secondary"===t.emphasis&&z.add(t);if(z.size>0)for(const t of O)!0===t?.defensive&&z.delete(t);let F;return F=0===z.size?O:_?O.map(t=>z.has(t)?{...t,_annotationDeferred:!0}:t):O.filter(t=>!z.has(t)),C?function(t,e){let n=!1;const o=t.map(t=>ps(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(n=!0,{...t,cohesion:e}):t);return n?o:t}(F,C):F}import{useSyncExternalStore as ws}from"react";var ks={positions:new Map},Ss=new Set;function As(){for(const t of Ss)t()}function Ms(t,e){const n=ks.positions.get(t);if(n?.locked)return;if(!n||n.sourceId!==e)return;const o=new Map(ks.positions);o.delete(t),ks={positions:o},As()}function _s(t,e){const n=ks.positions.get(t);if(!n?.locked)return;if(e&&n.sourceId!==e)return;const o=new Map(ks.positions);o.delete(t),ks={positions:o},As()}function Ps(){return ks}function Cs(t){return Ss.add(t),()=>Ss.delete(t)}var Ls={positions:new Map};function Rs(){return()=>{}}function Ts(){return Ls}function Is(t,e,n){return"exact"===n?function(t,e){const n=t.domain(),o=n[0],i=n[n.length-1],r=o instanceof Date,s=o instanceof Date?o.getTime():o,a=i instanceof Date?i.getTime():i;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const l=(a-s)/(e-1),c=Array(e);for(let t=0;e>t;t++){const n=t===e-1?a:s+t*l;c[t]=r?new Date(n):n}return c}(t,e):t.ticks(e)}function $s(t,e,n){if("edges"===t){if(e)return"start";if(n)return"end"}return"middle"}function Os(t,e,n){if("edges"===t){if(e)return"hanging";if(n)return"auto"}return"middle"}function zs(t){if(0===t.length)return{min:null,max:null};let e=1/0,n=-1/0;for(const o of t)e>o.pixel&&(e=o.pixel),o.pixel>n&&(n=o.pixel);return{min:e,max:n}}function Fs(t){if(t)return"dashed"===t?"6,4":"dotted"===t?"2,4":t}function Ds(t,e,n){if("left"===t||"right"===t){const o="left"===t?n:0,i="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+o;for(let t=0;r>t;t++){const n=8*(t+1);s+=`L${Math.min(8*t+4,e)},${o+4*i}`,s+=`L${Math.min(n,e)},${o}`}return s}const o="bottom"===t?0:e,i="bottom"===t?1:-1,r=Math.ceil(n/8);let s=`M${o},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${o+4*i},${Math.min(8*t+4,n)}`,s+=`L${o},${Math.min(e,n)}`}return s}function Es(t){return"string"==typeof t&&t.length>0}function Ns(t,e,n=!1){const o=n?e?58:34:e?36:0;return o>t.top?{...t,top:o}:t}function Bs(t,e){return Ns(t,Es(e))}import{Fragment as Ws,jsx as js,jsxs as Ys}from"react/jsx-runtime";function Xs(t){const{width:e,height:n,totalWidth:o,totalHeight:i,margin:r,scales:s,showAxes:a,axes:l,showGrid:c,xFormat:u,yFormat:d,axisExtent:h}=t,f=Wi(()=>{if(!s)return[];const t=l?.find(t=>"bottom"===t.orient),n=t?.tickFormat||u||Hs,o=Math.max(2,Math.floor(e/70)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,o),a=t?.tickValues??Is(s.x,r,h),c=a.map(t=>t.valueOf()),d=a.map((t,e)=>({value:t,pixel:s.x(t),label:n(t,e,c)})),f=d.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:"number"==typeof e.label?6.5*(e.label+"").length:60),0);return Gs(d,Math.max(55,f+8))},[s,l,u,e,h]),p=Wi(()=>{if(!s)return[];const t=l?.find(t=>"left"===t.orient),e=t?.tickFormat||d||Hs,o=Math.max(2,Math.floor(n/30)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,o);return Gs((t?.tickValues??Is(s.y,r,h)).map(t=>({value:t,pixel:s.y(t),label:e(t)})),22)},[s,l,d,n,h]),g=c&&s,y=a&&s;if(!g&&!y)return null;const m=l?.find(t=>"bottom"===t.orient),b=l?.find(t=>"left"===t.orient),x=y&&(!m||!1!==m.baseline),v=y&&(!b||!1!==b.baseline),w=m?.jaggedBase||!1,k=b?.jaggedBase||!1,S="var(--semiotic-border, #ccc)";return js("svg",{width:o,height:i,style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:Ys("g",{transform:`translate(${r.left},${r.top})`,children:[g&&(()=>{const t=Fs(l?.find(t=>"bottom"===t.orient)?.gridStyle),o=Fs(l?.find(t=>"left"===t.orient)?.gridStyle),i=!1!==l?.find(t=>"bottom"===t.orient)?.grid,r=!1!==l?.find(t=>"left"===t.orient)?.grid;return Ys("g",{className:"stream-grid",children:[i&&f.map((e,o)=>js("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:n,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+o)),r&&p.map((t,n)=>js("line",{x1:0,y1:t.pixel,x2:e,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:o},"ygrid-"+n))]})})(),x&&!w&&js("line",{x1:0,y1:n,x2:e,y2:n,stroke:S,strokeWidth:1}),w&&js("path",{d:Ds("bottom",e,n),fill:"none",stroke:S,strokeWidth:1}),v&&!k&&js("line",{x1:0,y1:0,x2:0,y2:n,stroke:S,strokeWidth:1}),k&&js("path",{d:Ds("left",e,n),fill:"none",stroke:S,strokeWidth:1})]})})}function Hs(t,e,n){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function Gs(t,e){if(2>=t.length)return t;const n=[t[0]];for(let o=1;t.length-1>o;o++)e>Math.abs(t[o].pixel-n[n.length-1].pixel)||n.push(t[o]);const o=t[t.length-1];return e>Math.abs(o.pixel-n[n.length-1].pixel)?n[n.length-1]=o:n.push(o),n}function qs(t){const{width:n,height:o,totalWidth:i,totalHeight:r,margin:s,scales:l,showAxes:c,axes:u,xLabel:d,yLabel:h,yLabelRight:f,xFormat:p,yFormat:g,axisExtent:y,showGrid:m,title:b,legend:v,legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:S,legendIsolatedCategories:A,legendPosition:M="right",legendLayout:_,foregroundGraphics:P,marginalGraphics:C,xValues:L,yValues:R,annotations:T,onAnnotationActivate:I,onObservation:$,chartId:O,chartType:z,autoPlaceAnnotations:F,svgAnnotationRules:D,xAccessor:E,yAccessor:N,annotationData:B,pointNodes:W,curve:j,underlayRendered:Y,canvasObscuresUnderlay:X=!0,linkedCrosshairName:H,linkedCrosshairSourceId:G,children:q}=t,V=x({onAnnotationActivate:I,onObservation:$,chartId:O,chartType:z}),U=Zi(_),K=v&&"left"===M&&U>0?U:s.left,Z=v&&"right"===M&&U>0?U:s.right,Q=Wi(()=>{if(!c||!l)return[];const t=u?.find(t=>"bottom"===t.orient),e=t?.tickFormat||p||Hs,o=Math.max(2,Math.floor(n/70)),i=t?.ticks??5,r="exact"===y?Math.max(2,i):Math.min(i,o),s=t?.tickValues??Is(l.x,r,y),a=s.map(t=>t.valueOf()),d=s.map((t,n)=>({value:t,pixel:l.x(t),label:e(t,n,a)})),h=d.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:"number"==typeof e.label?6.5*(e.label+"").length:60),0),f=t?.autoRotate?Math.max(20,Math.min(h+8,55)):Math.max(55,h+8);let g=Gs(d,f);if(g.length>1&&(g=g.filter((t,e)=>0===e||t.label+""!=g[e-1].label+"")),t?.includeMax&&g.length>0&&"exact"!==y&&!t?.tickValues){const t=l.x.domain()[1],n=l.x(t),o=g[g.length-1].pixel;if(Math.abs(n-o)>1){const i=e(t,g.length,a);f>n-o&&g.length>1&&(g=g.slice(0,-1)),g.push({value:t,pixel:n,label:i})}}return g},[c,l,u,p,n,y]),J=Wi(()=>{const t=u?.find(t=>"bottom"===t.orient);if(!t?.autoRotate||1>=Q.length)return!1;const e=n/Math.max(Q.length-1,1);return Q.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8>e},[u,Q,n]),tt=Wi(()=>{if(!c||!l)return[];const t=u?.find(t=>"left"===t.orient),e=t?.tickFormat||g||Hs,n=Math.max(2,Math.floor(o/30)),i=t?.ticks??5,r="exact"===y?Math.max(2,i):Math.min(i,n);let s=Gs((t?.tickValues??Is(l.y,r,y)).map(t=>({value:t,pixel:l.y(t),label:e(t)})),22);if(s.length>1&&(s=s.filter((t,e)=>0===e||t.label+""!=s[e-1].label+"")),t?.includeMax&&s.length>0&&"exact"!==y&&!t?.tickValues){const t=l.y.domain()[1],n=l.y(t),o=s[s.length-1].pixel;if(Math.abs(n-o)>1){const i=e(t);22>Math.abs(n-o)&&s.length>1&&(s=s.slice(0,-1)),s.push({value:t,pixel:n,label:i})}}return s},[c,l,u,g,o,y]),et=Wi(()=>{if(!c||!l)return[];const t=u?.find(t=>"right"===t.orient);if(!t)return[];const e=t.tickFormat||g||Hs,n=Math.max(2,Math.floor(o/30)),i=t.ticks??5;return Gs((t.tickValues??Is(l.y,"exact"===y?Math.max(2,i):Math.min(i,n),y)).map(t=>({value:t,pixel:l.y(t),label:e(t)})),22)},[c,l,u,g,o,y]),nt=ji(new Map),ot=ji(T?.length??0),it=T?.length??0;ot.current!==it&&(ot.current=it,nt.current=new Map);const rt=Wi(()=>{if(!T||0===T.length)return null;const t=a(T),i=function(t,n={}){return function(t,o,i){switch(t.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const e=Hr(t,o,i);if(!e)return null;const{x:n,y:r}=e;if(!Gr(n,r,i))return null;const s="callout"===t.type?"callout-circle":t.type,a="callout-circle"===s?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===s?{width:t.width,height:t.height}:void 0;return os(Lr,{noteData:{x:n,y:r,dx:t.dx??30,dy:t.dy??-30,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:s,...a?{subject:a}:{},connector:t.connector||{end:"arrow"},color:t.color,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-"+o)}case"x-threshold":{const e=Wr(null!=t.value?{...t,x:t.value}:t,i);if(null==e)return null;const n=t.color||"#f97316",r=t.labelPosition||"top";let s;s="bottom"===r?(i.height||0)-4:"center"===r?(i.height||0)/2:16;const a=e>.6*(i.width||0),l=a?e-4:e+4,c=a?"end":"start";return is("g",{opacity:t.opacity,children:[os("line",{x1:e,y1:0,x2:e,y2:i.height||0,stroke:n,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&os(ns,{x:l,y:s,text:t.label,textAnchor:c,fill:n,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+o)}case"y-threshold":{const e=jr(null!=t.value?{...t,y:t.value}:t,i);if(null==e)return null;const n=t.color||"#f97316",r=t.labelPosition||"right";let s,l;"left"===r?(s=4,l="start"):"center"===r?(s=(i.width||0)/2,l="middle"):(s=(i.width||0)-4,l="end");const c=20>(a=e)?Math.min((i.height||0)-4,a+16):a-4;return is("g",{opacity:t.opacity,children:[os("line",{x1:0,y1:e,x2:i.width||0,y2:e,stroke:n,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&os(ns,{x:s,y:c,text:t.label,textAnchor:l,fill:n,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+o)}case"enclose":{const e=(t.coordinates||[]).map(t=>({x:Wr({...t,type:"point"},i),y:jr({...t,type:"point"},i),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const n=Rr(e),r=t.padding||10;return is("g",{children:[os("circle",{cx:n.x,cy:n.y,r:n.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity||.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&os(ns,{x:n.x,y:n.y-n.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+o)}case"rect-enclose":{const e=(t.coordinates||[]).map(t=>({x:Wr({...t,type:"point"},i),y:jr({...t,type:"point"},i)})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const n=t.padding||10,r=e.map(t=>t.x),s=e.map(t=>t.y),[a,l]=_t(r),[c,u]=_t(s),d=a-n,h=l+n,f=c-n;return is("g",{children:[os("rect",{x:d,y:f,width:h-d,height:u+n-f,fill:t.fill||"none",fillOpacity:t.fillOpacity||.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&os(ns,{x:(d+h)/2,y:f-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+o)}case"highlight":{const e=i.data||[],n="function"==typeof t.filter?e.filter(t.filter):t.field&&null!=t.value?e.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return os("g",{children:n.map((e,n)=>{const o=Wr(e,i),s=jr(e,i);if(null==o||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,l="function"==typeof t.style?t.style(e):t.style||r;return os("circle",{cx:o,cy:s,r:a,...l},"hl-"+n)})},"ann-"+o)}case"bracket":{const e=Wr(t,i),n=jr(t,i);return os(Lr,{noteData:{x:e??0,y:n??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+o)}case"trend":{const e=i.data||[];if(2>e.length)return null;const n=i.xAccessor||"x",r=i.yAccessor||"y",s="ordinal"===i.frameType,a="horizontal"===i.projection,l=s?n:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of e){const e=t[l];if(null==e)continue;const n=e+"";h.has(n)||(h.set(n,d.length),d.push(n))}u=e.map(t=>{const e=t[l],n=t[c];if(null==e||null==n)return null;const o=h.get(e+"");return null!=o?[o,+n]:null}).filter(t=>null!==t)}else u=e.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const f=i.scales?.x??i.scales?.time,p=i.scales?.y??i.scales?.value;if(!f||!p)return null;const g=t=>e=>{const n=Math.max(0,Math.floor(e)),o=Math.min(d.length-1,n+1),i=e-n,r=t(d[n]);return r+(t(d[o])-r)*i},y=f,m=p;let b;if(s)if(a){const t=g(m);b=(e,n)=>[y(n),t(e)]}else{const t=g(y);b=(e,n)=>[t(e),m(n)]}else b=(t,e)=>[y(t),m(e)];const x=t.method||"linear";let v;if("loess"===x)v=function(t,e=.3){const n=t.length;if(2>n)return t.slice();const o=t.slice().sort((t,e)=>t[0]-e[0]),i=o.map(t=>t[0]),r=o.map(t=>t[1]),s=Math.max(2,Math.ceil(e*n)),a=[];for(let t=0;n>t;t++){const e=i[t],o=i.map(t=>Math.abs(t-e)),l=o.slice().sort((t,e)=>t-e)[Math.min(s-1,n-1)]||1,c=[];for(let t=0;n>t;t++){const e=0===l?0:o[t]/l;c[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,f=0,p=0;for(let t=0;n>t;t++){const e=c[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],f+=e*i[t]*i[t],p+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const g=u*f-d*d;if(1e-12>Math.abs(g))a.push([e,h/u]);else{const t=(u*p-d*h)/g;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3);else{const e="polynomial"===x?qt(u,t.order||2):function(t){const e=[0,0,0,0];let n=0;for(const[o,i]of t)null!==i&&(n++,e[0]+=o,e[1]+=i,e[2]+=o*o,e[3]+=o*i);const o=n*e[2]-e[0]*e[0],i=0===o?0:Gt((n*e[3]-e[0]*e[1])/o),r=Gt(e[1]/n-i*e[0]/n);return{points:t.map(([t])=>[Gt(t),Gt(i*t+r)]),equation:[i,r]}}(u);v=e.points}const w=v.map(([t,e])=>{const[n,o]=b(t,e);return`${n},${o}`}).join(" "),k=t.color||"#6366f1",S=v[v.length-1],[A,M]=b(S[0],S[1]);return is("g",{children:[os("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth||2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&os("text",{x:A+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+o)}case"band":{const e=i.scales?.y??i.scales?.value,n=e?.domain?.(),a=t.y0??n?.[0],l=t.y1??n?.[1],c=null!=a&&e?e(a):0,u=null!=l&&e?e(l):i.height||0,d=ri(t.fill,"ann-"+o,"var(--semiotic-primary, #6366f1)");return is("g",{opacity:t.opacity,children:[d.def&&os("defs",{children:d.def}),os("rect",{x:0,y:Math.min(c,u),width:i.width||0,height:Math.abs(u-c),fill:d.fill,fillOpacity:t.fillOpacity||.1}),t.label&&os(ns,{x:(i.width||0)-4,y:(r=c,s=u,Math.max(Math.min(r,s),0)+16),textAnchor:"end",fill:t.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:t.label,background:t.labelBackground??"halo"})]},"ann-"+o)}case"x-band":{const e=i.scales?.x??i.scales?.time,n=e?.domain?.(),r=t.x0??n?.[0],s=t.x1??n?.[1],a=null!=r&&e?e(r):null,l=null!=s&&e?e(s):null;if(null==a||null==l)return null;const c=ri(t.fill||t.color,"ann-"+o,"var(--semiotic-primary, #6366f1)");return is("g",{opacity:t.opacity,children:[c.def&&os("defs",{children:c.def}),os("rect",{x:Math.min(a,l),y:0,width:Math.abs(l-a),height:i.height||0,fill:c.fill,fillOpacity:t.fillOpacity??.1}),t.label&&os(ns,{x:Math.min(a,l)+4,y:16,textAnchor:"start",fill:t.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:t.label,background:t.labelBackground??"halo"})]},"ann-"+o)}case"envelope":{const e=i.data||[];if(2>e.length)return null;const n=i.xAccessor||"x",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=e.filter(t=>null!=t[a]&&null!=t[l]&&!(c&&!c(t))).sort((t,e)=>t[n]-e[n]);if(2>u.length)return null;const d=rs[i.curve||"linear"]||Ir,h=Tr().x(t=>r(t[n])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1";return is("g",{children:[os("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&u.length>0&&os("text",{x:r(u[u.length-1][n])+4,y:s(u[u.length-1][a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+o)}case"anomaly-band":{const e=i.data||[];if(2>e.length)return null;const n=i.yAccessor||"y",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=e.map(t=>t[n]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,f=!1!==t.showBand,p=t.fill||"#6366f1",g=t.fillOpacity??.1,y=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,b=s(l+d*u),x=s(h),v=e.filter(t=>{const e=t[n];return null!=e&&Math.abs(e-l)>d*u});return is("g",{children:[f&&os("rect",{x:0,y:Math.min(b,x),width:i.width||0,height:Math.abs(x-b),fill:p,fillOpacity:g}),v.map((t,e)=>{const n=Wr(t,i),o=jr(t,i);return null==n||null==o?null:os("circle",{cx:n,cy:o,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+e)}),t.label&&os("text",{x:(i.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:p,fontSize:11,children:t.label})]},"ann-"+o)}case"forecast":{const e=i.data||[];if(3>e.length)return null;const n=i.xAccessor||"x",r=i.yAccessor||"y",s=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!s||!a)return null;const l=e.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>l.length)return null;let c;if("polynomial"===(t.method||"linear")){const e=qt(l,t.order||2).equation;c=t=>e.reduce((e,n,o)=>e+n*Math.pow(t,o),0)}else{const t=Vt(l);if(!t)return null;c=t}const u=l.length,{se:d,meanX:h,ssX:f}=Ut(l,c),p=Kt(t.confidence??.95),g=t.steps??5,y=l[u-1][0],m=(y-l[0][0])/Math.max(u-1,1),b=[];for(let t=1;g>=t;t++)b.push(y+t*m);const x=[];for(const t of b){const e=c(t),n=d*Math.sqrt(1+1/u+(f>0?(t-h)**2/f:0))*p;x.push({x:t,yCenter:e,yUpper:e+n,yLower:e-n})}const v=`M${x.map(t=>`${s(t.x)},${a(t.yUpper)}`).join(" L")} L${x.slice().reverse().map(t=>`${s(t.x)},${a(t.yLower)}`).join(" L")} Z`,w=x.map(t=>`${s(t.x)},${a(t.yCenter)}`).join(" "),k=`${s(y)},${a(c(y))}`,S=t.strokeColor||"#6366f1";return is("g",{children:[os("path",{d:v,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),os("polyline",{points:`${k} ${w}`,fill:"none",stroke:S,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&x.length>0&&os("text",{x:s(x[x.length-1].x)+4,y:a(x[x.length-1].yCenter)-4,fill:S,fontSize:11,children:t.label})]},"ann-"+o)}case"widget":{let r,s;if(null!=t.px&&null!=t.py)r=t.px,s=t.py;else{const e=Hr(t,o,i);if(!e)return null;r=e.x,s=e.y}if(!Gr(r,s,i))return null;const a=t.dx??0,l=t.dy??0,c=t.width??32,u=t.height??32,d=t.content??os("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return os("foreignObject",{x:r+a-c/2,y:s+l-u/2,width:c,height:u,style:{overflow:"visible",pointerEvents:"auto"},children:os("div",{...e(t,n),style:{width:c,height:u,display:"flex",alignItems:"center",justifyContent:"center"},children:d})},"ann-"+o)}case"text":{const e=Hr(t,o,i);if(!e)return null;const{x:n,y:r}=e,s=n+(t.dx||0),a=r+(t.dy||0),l=t.color||"var(--semiotic-text, #333)",c=os("text",{x:s,y:a,fill:l,fontSize:t.fontSize||11,opacity:t.opacity,strokeDasharray:t.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:t.label});return!0!==t._redundantConnector?vr.cloneElement(c,{key:"ann-text-"+o}):is("g",{opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:[os("line",{x1:n,y1:r,x2:s,y2:a,stroke:l,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),vr.cloneElement(c,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+o)}case"category-highlight":{const e=t.category;if(null==e)return null;const n=t=>"function"==typeof t&&"function"==typeof t.bandwidth,r=i.scales?.o,s=i.scales?.x,a=i.scales?.y,l=n(r)?r:n(s)?s:n(a)?a:null;if(!l)return null;const c=l(e+"");if(null==c)return null;const u=l.bandwidth(),d=t.color||"var(--semiotic-primary, #4589ff)",h=t.opacity??.15,f=t.label;return is("g",(i.projection?"vertical"===i.projection:l===s)?{children:[os("rect",{x:c,y:0,width:u,height:i.height||0,fill:d,fillOpacity:h}),f&&os(ns,{x:c+u/2,y:16,textAnchor:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]}:{children:[os("rect",{x:0,y:c,width:i.width||0,height:u,fill:d,fillOpacity:h}),f&&os(ns,{x:12,y:c+u/2,dominantBaseline:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]},"ann-"+o)}default:return null}var r,s,a}}(0,V),r={scales:l?{x:l.x,y:l.y,time:l.x,value:l.y}:null,timeAxis:"x",xAccessor:E,yAccessor:N,width:n,height:o,data:B,frameType:"xy",pointNodes:W,curve:j,stickyPositionCache:nt.current};return ss(F?vs({annotations:t,context:r,..."object"==typeof F?F:{}}):t,i,D,r)},[T,F,D,n,o,E,N,B,l,W,j,V]),st=function(t){const e=ws(t?Cs:Rs,t?Ps:Ts,t?Ps:Ts);return t?e.positions.get(t)??null:null}(H);return Yi(()=>{if(!st?.locked||!H)return;const t=t=>{"Escape"===t.key&&_s(H)};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[st?.locked,H]),c||b||v||P||C||rt&&rt.length>0||m||q||st?Ys("svg",{role:"img",width:i,height:r,overflow:"visible",style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[js("title",{children:"string"==typeof b?b:"XY Chart"}),js("desc",{children:"string"==typeof b?b+" (XY data visualization)":"XY data visualization"}),Ys("g",{transform:`translate(${s.left},${s.top})`,children:[m&&l&&(!Y||X)&&(()=>{const t=Fs(u?.find(t=>"bottom"===t.orient)?.gridStyle),e=Fs(u?.find(t=>"left"===t.orient)?.gridStyle),i=!1!==u?.find(t=>"bottom"===t.orient)?.grid,r=!1!==u?.find(t=>"left"===t.orient)?.grid;return Ys("g",{className:"stream-grid",children:[i&&Q.map((e,n)=>js("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:o,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+n)),r&&tt.map((t,o)=>js("line",{x1:0,y1:t.pixel,x2:n,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:e},"ygrid-"+o))]})})(),c&&l&&(()=>{const t=u?.find(t=>"left"===t.orient),e=u?.find(t=>"bottom"===t.orient),i=!t||!1!==t.baseline,r=!e||!1!==e.baseline,s=t?.jaggedBase||!1,a=e?.jaggedBase||!1,l=e?.landmarkTicks,c=t?.landmarkTicks,p="var(--semiotic-border, #ccc)",g="var(--semiotic-text-secondary, var(--semiotic-text, #666))",y="var(--semiotic-text, #333)",m=J,b=m?12:18,x=o+(m?58:40),v={fontSize:"var(--semiotic-tick-font-size, 12px)"},w={fontSize:"calc(var(--semiotic-tick-font-size, 12px) + 1px)"},k={fontSize:"var(--semiotic-axis-label-font-size, 12px)"},S=e?.tickAnchor,A=t?.tickAnchor,M=zs(Q),_=zs(tt);return Ys("g",{className:"stream-axes",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[Ys("g",{className:"semiotic-axis semiotic-axis-bottom","data-orient":"bottom",children:[(!Y||X)&&r&&!a&&js("line",{x1:0,y1:o,x2:n,y2:o,stroke:p,strokeWidth:1}),(!Y||X)&&a&&js("path",{d:Ds("bottom",n,o),fill:"none",stroke:p,strokeWidth:1}),Q.map((t,e)=>{const n=!!l&&("function"==typeof l?l(t.value,e):zo(t.value,e>0?Q[e-1].value:void 0));return Ys("g",{transform:`translate(${t.pixel},${o})`,children:[js("line",{y2:5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?js("text",{y:b,textAnchor:m?"end":$s(S,t.pixel===M.min,t.pixel===M.max),fontWeight:n?600:400,fill:g,fontSize:n?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...n?w:v},transform:m?"rotate(-45)":void 0,children:t.label}):js("foreignObject",{x:-30,y:6,width:60,height:24,style:{overflow:"visible"},children:js("div",{style:{textAlign:"center",userSelect:"none",...v},children:t.label})})]},"xtick-"+e)}),d&&js("text",{x:n/2,y:x,textAnchor:"middle",fill:y,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:d})]}),Ys("g",{className:"semiotic-axis semiotic-axis-left","data-orient":"left",children:[(!Y||X)&&i&&!s&&js("line",{x1:0,y1:0,x2:0,y2:o,stroke:p,strokeWidth:1}),(!Y||X)&&s&&js("path",{d:Ds("left",n,o),fill:"none",stroke:p,strokeWidth:1}),tt.map((t,e)=>{const n=!!c&&("function"==typeof c?c(t.value,e):zo(t.value,e>0?tt[e-1].value:void 0));return Ys("g",{transform:`translate(0,${t.pixel})`,children:[js("line",{x2:-5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?js("text",{x:-8,textAnchor:"end",dominantBaseline:Os(A,t.pixel===_.min,t.pixel===_.max),fontWeight:n?600:400,fill:g,fontSize:n?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...n?w:v},children:t.label}):js("foreignObject",{x:-68,y:-12,width:60,height:24,style:{overflow:"visible"},children:js("div",{style:{textAlign:"right",userSelect:"none",...v},children:t.label})})]},"ytick-"+e)}),(()=>{const e=t?.label||h;return e?js("text",{x:15-K,y:o/2,textAnchor:"middle",fill:y,transform:`rotate(-90, ${15-K}, ${o/2})`,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:e}):null})()]}),(()=>{const t=u?.find(t=>"right"===t.orient);if(!t||0===et.length)return null;const e=!1!==t.baseline,i=t.landmarkTicks,r=t.label||f,s=t.tickAnchor,a=zs(et);return Ys("g",{className:"semiotic-axis semiotic-axis-right","data-orient":"right",children:[e&&js("line",{x1:n,y1:0,x2:n,y2:o,stroke:p,strokeWidth:1}),et.map((t,e)=>{const o=!!i&&("function"==typeof i?i(t.value,e):zo(t.value,e>0?et[e-1].value:void 0));return Ys("g",{transform:`translate(${n},${t.pixel})`,children:[js("line",{x2:5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?js("text",{x:8,textAnchor:"start",dominantBaseline:Os(s,t.pixel===a.min,t.pixel===a.max),fontWeight:o?600:400,fill:g,fontSize:o?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...o?w:v},children:t.label}):js("foreignObject",{x:8,y:-12,width:60,height:24,style:{overflow:"visible"},children:js("div",{style:{textAlign:"left",userSelect:"none",...v},children:t.label})})]},"ytick-r-"+e)}),r&&js("text",{x:n+Z-15,y:o/2,textAnchor:"middle",fill:y,transform:`rotate(90, ${n+Z-15}, ${o/2})`,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:r})]})})()]})})(),rt,C&&l&&L&&R&&Ys(Ws,{children:[C.top&&js("g",{transform:"translate(0, 0)",children:js(xr,{orient:"top",config:br(C.top),values:L,scale:l.x,size:s.top,length:n})}),C.bottom&&js("g",{transform:`translate(0, ${o})`,children:js(xr,{orient:"bottom",config:br(C.bottom),values:L,scale:l.x,size:s.bottom,length:n})}),C.left&&js("g",{transform:"translate(0, 0)",children:js(xr,{orient:"left",config:br(C.left),values:R,scale:l.y,size:s.left,length:o})}),C.right&&js("g",{transform:`translate(${n}, 0)`,children:js(xr,{orient:"right",config:br(C.right),values:R,scale:l.y,size:s.right,length:o})})]}),P,st&&st.sourceId!==G&&l?.x&&(()=>{const t=l.x(st.xValue);if(null==t||0>t||t>n)return null;const e=st.locked;return js("line",{x1:t,y1:0,x2:t,y2:o,stroke:e?"white":"var(--semiotic-text-secondary, rgba(0,0,0,0.25))",strokeWidth:e?1.5:1,strokeDasharray:e?"6,3":"4,4",pointerEvents:"none"})})(),q]}),b&&"string"==typeof b?js("text",{x:i/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)"},children:b}):b?js("foreignObject",{x:0,y:0,width:i,height:s.top,children:b}):null,fr({legend:v,totalWidth:i,totalHeight:r,margin:s,legendPosition:M,title:b,legendLayout:_,axisChrome:{hasAxis:!!c,hasAxisLabel:!!d,rotatedTicks:J},legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:S,legendIsolatedCategories:A})]}):null}import*as Vs from"react";import{area as Us,line as Ks}from"d3-shape";function Zs(t,e,n){let o=n;for(const n of e)"lesser"===n.thresholdType?n.value>t&&(o=n.color):t>n.value&&(o=n.color);return o}function Qs(t,e,n,o){if(2>t.length||e.length!==t.length||0===n.length)return[];const i=[],r=(t,e,n)=>{const o=i[i.length-1];o?.color===t?o.path.push(n):i.push({color:t,path:[e,n]})};for(let i=1;t.length>i;i++){const[s,a]=t[i-1],[l,c]=t[i],u=e[i-1],d=e[i]-u,h=[0,...0===d?[]:n.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,n)=>0===e||t!==n[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],i=h[t];r(Zs(u+d*((e+i)/2),n,o),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}function Js(t){return(t.tl??0)>0||(t.tr??0)>0||(t.br??0)>0||(t.bl??0)>0}function ta(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const n=Math.min(t.w,t.h)/2,o=t=>Math.max(0,Math.min(t??0,n));return{tl:o(e.tl),tr:o(e.tr),br:o(e.br),bl:o(e.bl)}}import{jsx as ea,jsxs as na}from"react/jsx-runtime";var oa={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function ia(t,e="#4e79a7"){return ei(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function ra(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function sa(t,e,n,o){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=Eo(i,t.size);if(0>=r.scale)return null;const s=`translate(${e},${n})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),l=jo(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?ra(o+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>i.parts.map((n,o)=>{const i=e?"none"===n.fill?void 0:e:No(n.fill,a,t.accent),r=e?n.stroke&&"none"!==n.stroke?e:void 0:No(n.stroke??"none",a,t.accent);return i||r?ea("path",{d:n.d,fill:i??"none",stroke:r,strokeWidth:r?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},o):null});return na("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&ea("clipPath",{id:c,children:ea("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?ea("g",{children:d(t.ghostColor)}):null,l&&c?ea("g",{clipPath:`url(#${c})`,children:d()}):d()]},o)}function aa(t,e){const n=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>n.length?null:n.map((t,e)=>ea("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function la(t,e,n){const o=vn(t.symbolType,t.size,t.path);return ea("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?ia(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${n??""}symbol-${e}`)}import*as ca from"react";import{arc as ua}from"d3-shape";import{jsx as da,jsxs as ha}from"react/jsx-runtime";import*as fa from"react";import{jsx as pa,jsxs as ga}from"react/jsx-runtime";import*as ya from"react";import{arc as ma}from"d3-shape";var ba=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function xa(t){const{innerRadius:e,outerRadius:n,startAngle:o,endAngle:i}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=ba(n,o),e=ba(n,i);return`M0,0 L${t.x},${t.y} A${n},${n} 0 ${i-o>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=ba(n,o),s=ba(n,i),a=ba(e,i),l=ba(e,o),c=i-o>Math.PI?1:0;return`M${t.x},${t.y} A${n},${n} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(n-e)/2));if(0===s)return xa({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,n-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),c=i-o,u=t.roundStart&&t.roundEnd?c/2:c,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return xa({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=o+(d?a:0),p=i-(h?a:0),g=o+(d?l:0),y=i-(h?l:0),m=ba(n,f),b=ba(n,p),x=(n-s)*Math.cos(a),v=ba(x,o),w=ba(x,i),k=r?null:ba(e,y),S=r?null:ba(e,g),A=r?0:(e+s)*Math.cos(l),M=r?null:ba(A,o),_=r?null:ba(A,i),P=p-f>Math.PI?1:0,C=r?0:y-g>Math.PI?1:0;let L="";if(d)L+=`M${v.x},${v.y}`,L+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=ba(n,o);L+=`M${t.x},${t.y}`}if(h)L+=` A${n},${n} 0 ${P} 1 ${b.x},${b.y}`,L+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=ba(n,i);L+=` A${n},${n} 0 ${P} 1 ${t.x},${t.y}`}if(r)L+=" L0,0";else{if(h)L+=` L${_.x},${_.y}`,L+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=ba(e,i);L+=` L${t.x},${t.y}`}if(d)L+=` A${e},${e} 0 ${C} 0 ${S.x},${S.y}`,L+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=ba(e,o);L+=` A${e},${e} 0 ${C} 0 ${t.x},${t.y}`}}return L+=" Z",L}import{jsx as va,jsxs as wa}from"react/jsx-runtime";function ka(t){return 1e6>t?1e4>t?1e3>t?t+"":(t/1e3).toFixed(1)+"K":(t/1e3).toFixed(0)+"K":(t/1e6).toFixed(1)+"M"}function Sa(t,e){const n=t.datum;if(!n)return null;const o=[],i=n.__funnelStepLabel,r=Number(n.__funnelStepLabelX),s=Number(n.__funnelStepLabelY),a=Number(n.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||o.push(va("text",{x:r,y:s+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-step"));const l=Number(n.__funnelValue),c=Number(n.__funnelValueLabelX),u=Number(n.__funnelValueLabelY),d=Number(n.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const t=Number(n.__funnelPercent);let i=!0!==n.__funnelIsFirstStep&&Number.isFinite(t)?`${ka(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:ka(l);7.8*i.length+16>d&&(i=ka(l)),7.8*i.length+16>d||o.push(va("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-value"))}return o.length?va("g",{children:o},e+"-funnel-labels"):null}function Aa(t,e,n){const o=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",i=n=>`ord-${t.type}-${o}-${e}-${n}`,r=`ord-${t.type}-${o}-${e}`;switch(t.type){case"rect":{const e=t,n=ra(r)+"-grad",o=function(t,e){const n=t.fillGradient;if(!n||"object"!=typeof n)return null;let o=t.x,i=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(i=t.y+t.h,s=t.y):"right"===t.roundedEdge?(o=t.x+t.w,i=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(o=t.x,i=t.y,r=t.x+t.w,s=t.y);const a=aa(n.stops,ia(t.style.fill));return a?ea("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:o,y1:i,x2:r,y2:s,children:a}):null}(e,n);let i,s;if(o)s=`url(#${n})`;else if(ei(e.style.fill)){const t=ra(r)+"-hatch";i=ii(e.style.fill,t),s=`url(#${t})`}else s=ia(e.style.fill);const a=o||i?wa("defs",{children:[o,i]}):null;if(e.cornerRadii&&Js(e.cornerRadii)){const t=function(t){const{x:e,y:n,w:o,h:i}=t,{tl:r,tr:s,br:a,bl:l}=ta(t);let c=`M${e+r},${n}`;return c+=` L${e+o-s},${n}`,s>0&&(c+=` A${s},${s} 0 0 1 ${e+o},${n+s}`),c+=` L${e+o},${n+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${e+o-a},${n+i}`),c+=` L${e+l},${n+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${e},${n+i-l}`),c+=` L${e},${n+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${e+r},${n}`),c+=" Z",c}(e);return wa(ya.Fragment,{children:[a,va("path",{d:t,fill:s,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:n,y:o,w:i,h:l}=e;let c;switch(e.roundedEdge){case"right":c=`M${n},${o} L${n+i-t},${o} A${t},${t} 0 0 1 ${n+i},${o+t} L${n+i},${o+l-t} A${t},${t} 0 0 1 ${n+i-t},${o+l} L${n},${o+l} Z`;break;case"left":c=`M${n+i},${o} L${n+t},${o} A${t},${t} 0 0 0 ${n},${o+t} L${n},${o+l-t} A${t},${t} 0 0 0 ${n+t},${o+l} L${n+i},${o+l} Z`;break;case"bottom":c=`M${n},${o} L${n+i},${o} L${n+i},${o+l-t} A${t},${t} 0 0 1 ${n+i-t},${o+l} L${n+t},${o+l} A${t},${t} 0 0 1 ${n},${o+l-t} Z`;break;default:c=`M${n},${o+l} L${n},${o+t} A${t},${t} 0 0 1 ${n+t},${o} L${n+i-t},${o} A${t},${t} 0 0 1 ${n+i},${o+t} L${n+i},${o+l} Z`}return wa(ya.Fragment,{children:[a,va("path",{d:c,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return wa(ya.Fragment,{children:[a,va("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),Sa(e,r)]},r)}case"point":{const e=t;return va("circle",{cx:e.x,cy:e.y,r:e.r,fill:ia(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return la(t,e,n);case"glyph":return sa(t,t.x,t.y,`${n??""}ord-glyph-${t.pointId??e}`);case"wedge":{const o=t;if(o._gradientBand&&o._gradientBand.colors.length>0){const t=ra(`${n?n+"-":""}gauge-grad-${o.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=xa({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),n=[],o=t.colors;if(o.length>0){const e=(t.endAngle-t.startAngle)/o.length;for(let i=0;o.length>i;i++)n.push({d:xa({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+i*e,endAngle:t.endAngle}),color:o[i]})}return{clipPath:e,slices:n}}({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 wa("g",{transform:`translate(${o.cx},${o.cy})`,opacity:o.style.opacity,fillOpacity:o.style.fillOpacity,children:[va("defs",{children:va("clipPath",{id:t,children:va("path",{d:i})})}),va("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>va("path",{d:t.d,fill:ia(t.color)},e))}),o.style.stroke&&"none"!==o.style.stroke&&va("path",{d:i,fill:"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},r)}let i;if(o.roundedEnds)i=xa({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=ma().innerRadius(o.innerRadius).outerRadius(o.outerRadius).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2);o.cornerRadius&&t.cornerRadius(o.cornerRadius),i=t(oa)||""}return va("path",{d:i,transform:`translate(${o.cx},${o.cy})`,fill:ia(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},r)}case"boxplot":{const e=t,n=e.columnWidth/2;return wa("g","vertical"===e.projection?{children:[va("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1}),va("rect",{x:e.x-n,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:ia(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),va("line",{x1:e.x-n,y1:e.medianPos,x2:e.x+n,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2}),va("line",{x1:e.x-.5*n,y1:e.minPos,x2:e.x+.5*n,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:1}),va("line",{x1:e.x-.5*n,y1:e.maxPos,x2:e.x+.5*n,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1})]}:{children:[va("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:1}),va("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-n,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:ia(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),va("line",{x1:e.medianPos,y1:e.y-n,x2:e.medianPos,y2:e.y+n,stroke:e.style.stroke||"#333",strokeWidth:2}),va("line",{x1:e.minPos,y1:e.y-.5*n,x2:e.minPos,y2:e.y+.5*n,stroke:e.style.stroke||"#333",strokeWidth:1}),va("line",{x1:e.maxPos,y1:e.y-.5*n,x2:e.maxPos,y2:e.y+.5*n,stroke:e.style.stroke||"#333",strokeWidth:1})]},r)}case"violin":{const e=t,n=[va("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:ia(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth||1},i("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,o=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?n.push(va("line",{x1:o,y1:e.iqrLine.q1Pos,x2:o,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),va("circle",{cx:o,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):n.push(va("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),va("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return va("g",{children:n},r)}case"connector":return va("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,n=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return va("polygon",{points:n,fill:ia(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}}import{jsx as Ma,jsxs as _a}from"react/jsx-runtime";function Pa(t,e,n,o){if(!t||2>e.length)return null;const i=aa(t.stops,o);return i?Ma("linearGradient",{id:n,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function Ca(t,e,n){switch(t.type){case"line":{const o=t;if(0===o.path.length)return null;const i=gi(o.curve),r=i?Ks().x(([t])=>t).y(([,t])=>t).curve(i)(o.path)??"":"M"+o.path.map(([t,e])=>`${t},${e}`).join("L"),s=ra(`${n?n+"-":""}line-${e}-stroke-gradient`),a=Pa(o.strokeGradient,o.path,s,o.style.stroke||"#4e79a7");return _a(Vs.Fragment,{children:[a&&Ma("defs",{children:a}),Ma("path",{d:r,fill:"none",stroke:a?`url(#${s})`:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth||2,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity})]},"line-"+e)}case"area":{const o=t;if(0===o.topPath.length)return null;const i=gi(o.curve),r=!i||2>o.topPath.length||2>o.bottomPath.length?`M${o.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...o.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:Us().x(([t])=>t).y0((t,e)=>o.bottomPath[e][1]).y1(([,t])=>t).curve(i)(o.topPath)??"",s=`${n?n+"-":""}area-${e}-hatch`,a=ei(o.style.fill)?ii(o.style.fill,s):void 0,l=ra(`${n?n+"-":""}area-${e}-gradient`),c=function(t,e){const n=t.fillGradient;if(!n||"object"!=typeof n)return null;let o=1/0;for(const[,e]of t.topPath)o=Math.min(o,e);let i=-1/0;for(const[,e]of t.bottomPath)i=Math.max(i,e);if(!Number.isFinite(o)||!Number.isFinite(i))return null;const r=aa(n.stops,ia(t.style.fill));return r?Ma("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:o,x2:0,y2:i,children:r}):null}(o,l),u=c?`url(#${l})`:a?`url(#${s})`:ia(o.style.fill),d=c?void 0:o.style.fillOpacity??o.style.opacity??.7,h=i?Ks().x(([t])=>t).y(([,t])=>t).curve(i)(o.topPath)??"":"M"+o.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=ra(`${n?n+"-":""}area-${e}-stroke-gradient`),p=!(!o.colorThresholds?.length||!o.rawValues||o.rawValues.length!==o.topPath.length),g=!!o.strokeColorBands?.length,y=p||g?null:Pa(o.strokeGradient,o.topPath,f,o.style.stroke||"#4e79a7"),m=o.style.strokeWidth||2;let b=1/0,x=-1/0;for(const[t]of o.topPath)b>t&&(b=t),t>x&&(x=t);const v=g?o.strokeColorBands.map((t,o)=>ra(`${n?n+"-":""}area-${e}-stroke-band-${o}`)):[],w=g?o.strokeColorBands.map((t,e)=>Ma("clipPath",{id:v[e],children:Ma("rect",{x:b-m,y:t.y,width:x-b+2*m,height:t.height})},v[e])):null,k=o.style.stroke&&"none"!==o.style.stroke?g?o.strokeColorBands.map((t,n)=>Ma("path",{d:h,fill:"none",stroke:t.color??ia(o.style.stroke),strokeWidth:m,opacity:o.style.opacity,clipPath:`url(#${v[n]})`},`area-${e}-stroke-band-${n}`)):p?Qs(o.topPath,o.rawValues,o.colorThresholds,ia(o.style.stroke)).map((t,n)=>Ma("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:m,opacity:o.style.opacity},`area-${e}-threshold-${n}`)):Ma("path",{d:h,fill:"none",stroke:y?`url(#${f})`:ia(o.style.stroke),strokeWidth:m,opacity:o.style.opacity}):null;if(o.clipRect){const t=`${n?n+"-":""}area-clip-${e}`;return _a("g",{children:[_a("defs",{children:[c,!c&&a,y,w,Ma("clipPath",{id:t,children:Ma("rect",{x:o.clipRect.x,y:o.clipRect.y,width:o.clipRect.width,height:o.clipRect.height})})]}),_a("g",{clipPath:`url(#${t})`,children:[Ma("path",{d:r,fill:u,fillOpacity:d,opacity:c?o.style.opacity:void 0,stroke:"none"}),k]})]},"area-"+e)}return _a(Vs.Fragment,{children:[(c||a||y||w)&&_a("defs",{children:[c,!c&&a,y,w]}),Ma("path",{d:r,fill:u,fillOpacity:d,opacity:c?o.style.opacity:void 0,stroke:"none"}),k]},"area-"+e)}case"point":{const o=t,i=`${n?n+"-":""}point-${e}-hatch`,r=ei(o.style.fill)?ii(o.style.fill,i):void 0;return _a(Vs.Fragment,{children:[r&&Ma("defs",{children:r}),Ma("circle",{cx:o.x,cy:o.y,r:o.r,fill:r?`url(#${i})`:ia(o.style.fill),opacity:o.style.opacity??o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"point-"+e)}case"symbol":return la(t,e);case"glyph":return sa(t,t.x,t.y,`${n??""}glyph-${t.pointId??e}`);case"rect":{const o=t,i=`${n?n+"-":""}xyrect-${e}-hatch`,r=ei(o.style.fill)?ii(o.style.fill,i):void 0;return _a(Vs.Fragment,{children:[r&&Ma("defs",{children:r}),Ma("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:r?`url(#${i})`:ia(o.style.fill),opacity:o.style.opacity,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const n=t,o={x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill,stroke:n.style?.stroke,strokeWidth:n.style?.strokeWidth,...null!=n.style?.opacity&&{opacity:n.style.opacity}};if(n.showValues&&null!=n.value&&n.w>=20&&n.h>=20){const t=n.valueFormat?n.valueFormat(n.value):Number.isInteger(n.value)?n.value+"":100>Math.abs(n.value)?1>Math.abs(n.value)?n.value.toPrecision(3):n.value.toFixed(1):n.value.toFixed(0),[i,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(n.fill),a=.299*i+.587*r+.114*s>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return _a("g",{children:[Ma("rect",{...o}),Ma("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",children:t})]},"heatcell-"+e)}return Ma("rect",{...o},"heatcell-"+e)}case"candlestick":{const n=t;if(n.isRange){const t=n.dotRadius??Math.max(2,n.bodyWidth/2);return _a("g",{children:[Ma("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),Ma("circle",{cx:n.x,cy:n.highY,r:t,fill:n.wickColor}),Ma("circle",{cx:n.x,cy:n.lowY,r:t,fill:n.wickColor})]},"candle-"+e)}const o=Math.min(n.openY,n.closeY),i=Math.max(Math.abs(n.openY-n.closeY),1),r=n.isUp?n.upColor:n.downColor;return _a("g",{children:[Ma("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),Ma("rect",{x:n.x-n.bodyWidth/2,y:o,width:n.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}var La="undefined"==typeof window||"undefined"==typeof document;import{useEffect as Ra,useLayoutEffect as Ta,useRef as Ia,useState as $a,useSyncExternalStore as Oa}from"react";var za="undefined"!=typeof window?Ta:Ra,Fa=()=>()=>{},Da=()=>!1,Ea=()=>!0;import{useRef as Na}from"react";function Ba(t,e){const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const o of n){if(!Object.prototype.hasOwnProperty.call(e,o))return!1;if(!Object.is(t[o],e[o]))return!1}return!0}function Wa(t,e){if(t.length!==e.length)return!1;for(let n=0;t.length>n;n++)if(!Object.is(t[n],e[n]))return!1;return!0}function ja(t){if(null===t||"object"!=typeof t)return!1;if(Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function Ya(t){const{background:e,hasBackgroundGraphics:n=!1,themeBackground:o=""}=t;return"transparent"===e||n?null:e||(o&&"transparent"!==o?o:"")||null}var Xa={axisStroke:"#ccc",tickText:"#666",crosshair:"rgba(0, 0, 0, 0.25)",hoverFill:"rgba(255, 255, 255, 0.3)",hoverStroke:"rgba(0, 0, 0, 0.4)",pointRing:"white",primary:"#007bff",background:""};function Ha(t,e){const n=t.trim();if(/^#[0-9a-f]{3}$/i.test(n)){const t=n[1],o=n[2],i=n[3];return`#${t}${t}${o}${o}${i}${i}${e}`}if(/^#[0-9a-f]{6}$/i.test(n))return`${n}${e}`;const o=n.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);return o?`rgba(${o[1]}, ${(parseInt(e,16)/255).toFixed(3)})`:n}import*as Ga from"react";import*as qa from"react";import{jsx as Va}from"react/jsx-runtime";var Ua=qa.createContext(null);import{jsx as Ka}from"react/jsx-runtime";var Za={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Qa({hoverPoint:t}){let e="";if(t){const n=t.data||t;e="object"==typeof n?"Data point: "+Object.entries(n).filter(([,t])=>"object"!=typeof t&&"function"!=typeof t).map(([t,e])=>`${t}: ${e}`).join(", "):"Data point: "+n}return Ka("div",{"aria-live":"polite","aria-atomic":"true",style:Za,children:e})}function Ja(t){const e={};if(null==t||"object"!=typeof t)return e;for(const[n,o]of Object.entries(t))n.startsWith("_")||null!=o&&""!==o&&("number"==typeof o?Number.isFinite(o)&&(e[n]=o):"string"==typeof o?e[n]=o:"boolean"==typeof o?e[n]=o+"":o instanceof Date&&(e[n]=o.toISOString().slice(0,10)));return e}function tl(t){return t&&"object"==typeof t?t:{}}function el(t){return tl(t.accessibility).tableFields??t.accessibleDatum??t.datum}import{jsx as nl,jsxs as ol}from"react/jsx-runtime";function il(t,e){if(!t||0===t.length)return e+", empty";const n={};for(const e of t){if(null===e?.datum)continue;const t=e.type+"";n[t]=(n[t]||0)+1}if(0===Object.keys(n).length)return e+", empty";const o=[],i={point:"points",line:"lines",area:"areas",rect:"bars",heatcell:"cells",circle:"nodes",candlestick:"candlesticks",wedge:"wedges",arc:"arcs",geoarea:"regions"},r=["point","line","area","rect","heatcell","circle","candlestick","wedge","arc","geoarea"],s=Object.keys(n).sort((t,e)=>{const n=r.indexOf(t),o=r.indexOf(e);return(-1===n?999:n)-(-1===o?999:o)});for(const t of s)o.push(`${n[t]} ${i[t]||t}`);return`${e}, ${o.join(", ")}`}var rl=t=>{if(null==t)return"";const e=Math.round(100*t)/100;return Number.isNaN(e)?"":e+""},sl="semiotic-accessible-data-table",al=sl+" semiotic-accessible-data-table-hidden",ll=sl+" semiotic-accessible-data-table-visible",cl={position:"absolute",top:0,left:0,right:0,zIndex:"var(--semiotic-data-table-z-index, var(--semiotic-overlay-z-index, 20))",padding:"14px 16px 12px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontFamily:"var(--semiotic-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif)",fontSize:13,lineHeight:1.5,color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",borderRadius:"var(--semiotic-border-radius, 0px) var(--semiotic-border-radius, 0px) 0 0"},ul={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},dl={position:"absolute",top:10,right:10,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",cursor:"pointer",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:13,lineHeight:1,padding:0,borderRadius:"var(--semiotic-border-radius, 4px)"},hl={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},fl={textAlign:"left",padding:"5px 10px",borderBottom:"2px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))"},pl={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},gl={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},yl={marginTop:8,padding:"4px 10px",fontSize:12,cursor:"pointer",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",borderRadius:"var(--semiotic-border-radius, 4px)",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",fontFamily:"inherit"};function ml({scene:t,chartType:e,tableId:n,chartTitle:o}){const[i,r]=Ga.useState(!1),[s,a]=Ga.useState(5),l=qa.useContext(Ua),c=l?.visible??!1,u=i||c,d=Ga.useRef(null),h=o?"Data summary for "+o:n?`Data summary for ${e} ${n}`:"Data summary for "+e;Ga.useEffect(()=>{u||a(5)},[u]);const f=Ga.useCallback(t=>{t.target===t.currentTarget&&(i||c||r(!0))},[i,c]),p=Ga.useCallback(t=>{c||d.current?.contains(t.relatedTarget)||r(!1)},[c]);if(!t||0===t.length)return n?nl("span",{id:n,tabIndex:-1,style:Za}):null;if(!u)return nl("div",{id:n,className:al,tabIndex:-1,onFocus:f,style:Za,role:"region","aria-label":h,children:ol("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",t.length," elements)"]})});const g=function(t){const e=[];if(!Array.isArray(t))return e;const n=t.some(t=>t&&("line"===t.type||"area"===t.type));for(const o of t)if(o&&"object"==typeof o&&null!==o.datum)try{switch(o.type){case"point":if(n)break;e.push({label:"Point",values:Ja(el(o))});break;case"line":case"area":{const t=el(o),n=Array.isArray(t)?t:[],i="line"===o.type?"Line point":"Area point";for(const t of n)e.push({label:i,values:Ja(t)});break}case"rect":{const t=el(o),n=null!=t&&"object"==typeof t?t:{},i=n.category??o.group??"",r=n.value??n.__aggregateValue??n.total,s=Ja(n);null==s.category&&""!==i&&(s.category=i+""),null==s.value&&null!=r&&(s.value="number"==typeof r||"string"==typeof r?r:r+""),e.push({label:"Bar",values:s});break}case"heatcell":{const t=Ja(el(o));null==t.value&&"number"==typeof o.value&&Number.isFinite(o.value)&&(t.value=o.value),e.push({label:"Cell",values:t});break}case"wedge":{const t=el(o),n=Ja(t);if(null==n.category){const e=tl(t),o=e.category??e.label;null!=o&&(n.category=o+"")}e.push({label:"Wedge",values:n});break}case"circle":e.push({label:"Node",values:Ja(el(o))});break;case"arc":e.push({label:"Arc",values:Ja(el(o))});break;case"candlestick":e.push({label:"Candlestick",values:Ja(el(o))});break;case"geoarea":{const t=tl(el(o)),n=Ja(t);if(null==n.name){const e=tl(t.properties).name??t.name;null!=e&&(n.name=e+"")}e.push({label:"Region",values:n});break}}}catch{}return e}(t),y=function(t){if(!t||0===t.length)return[];const e=new Set;for(const n of t)if(n&&n.values)for(const t of Object.keys(n.values))e.add(t);const n=[];for(const o of e){const e=[],i=new Set;for(const n of t){if(!n||!n.values)continue;const t=n.values[o];null!=t&&""!==t&&("number"==typeof t&&!Number.isNaN(t)&&Number.isFinite(t)?e.push(t):"number"==typeof t||"object"!=typeof t&&"function"!=typeof t&&i.add(t+""))}if(e.length>0){let t=e[0],i=e[0],r=0;for(const n of e)t>n&&(t=n),n>i&&(i=n),r+=n;n.push({name:o,count:e.length,numeric:!0,min:t,max:i,mean:r/e.length})}else if(i.size>0){const t=Array.from(i);n.push({name:o,count:t.length,numeric:!1,uniqueValues:t.slice(0,5)})}}return n}(g),m=function(t,e){const n=[t+" data points."];for(const t of e)if(t.numeric)n.push(`${t.name}: ${rl(t.min)} to ${rl(t.max)}, mean ${rl(t.mean)}.`);else{const e=t.uniqueValues,o=e.length>3?`${e.slice(0,3).join(", ")}… (${t.count} unique)`:e.join(", ");n.push(`${t.name}: ${o}.`)}return n.join(" ")}(g.length,y),b=Math.min(s,g.length),x=g.slice(0,b),v=g.length-b,w=new Set;for(const t of x)for(const e of Object.keys(t.values))w.add(e);const k=Array.from(w);return ol("div",{ref:d,id:n,className:ll,tabIndex:-1,onBlur:p,style:cl,role:"region","aria-label":h,children:[nl("button",{type:"button",className:"semiotic-accessible-data-table-close",onClick:()=>{c&&l&&l.setVisible(!1),r(!1)},"aria-label":"Close data summary",style:dl,children:"×"}),nl("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:ul,children:m}),ol("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Sample data for "+e,style:hl,children:[nl("caption",{className:"semiotic-accessible-data-table-caption",style:gl,children:v>0?`First ${b} of ${g.length} data points`:`All ${g.length} data points`}),nl("thead",{children:ol("tr",{children:[nl("th",{style:fl,children:"type"}),k.map(t=>nl("th",{style:fl,children:t},t))]})}),nl("tbody",{children:x.map((t,e)=>ol("tr",{children:[nl("td",{style:pl,children:t.label}),k.map(e=>{return nl("td",{style:pl,children:(n=t.values[e],null==n||""===n?"—":"number"==typeof n?Number.isNaN(n)?"—":rl(n):"boolean"==typeof n?n?"true":"false":"object"==typeof n?"—":n+"")},e);var n})]},e))})]}),v>0&&ol("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(t=>t+25),style:yl,children:["Show ",Math.min(25,v)," more"," ",1===v?"row":"rows"," (",v," remaining)"]})]})}function bl({summary:t}){return t?nl("div",{role:"note",style:Za,children:t}):null}function xl({tableId:t}){return nl("a",{href:"#"+t,style:Za,onClick:e=>{e.preventDefault();const n=document.getElementById(t);n&&requestAnimationFrame(()=>n.focus())},onFocus:t=>{Object.assign(t.currentTarget.style,{position:"absolute",width:"auto",height:"auto",overflow:"visible",clip:"auto",whiteSpace:"normal",padding:"4px 8px",background:"var(--semiotic-bg, #fff)",color:"var(--semiotic-text, #000)",border:"2px solid var(--semiotic-focus, #005fcc)",borderRadius:"4px",zIndex:"10",fontSize:"12px",top:"4px",left:"4px"})},onBlur:t=>{const e=t.currentTarget;e.removeAttribute("style"),Object.assign(e.style,Za)},children:"Skip to data table"})}import{jsx as vl}from"react/jsx-runtime";var wl="var(--semiotic-focus, #005fcc)";function kl({active:t,hoverPoint:e,margin:n,size:o,shape:i="circle",width:r,height:s,pathData:a}){if(!t||!e)return null;const l=e.x+n.left,c=e.y+n.top;let u;if("geoarea"!==i&&"path"!==i||!a)if("rect"===i&&null!=r&&null!=s){const t=Math.max(r,4),e=Math.max(s,4);u=vl("rect",{x:l-t/2-3,y:c-e/2-3,width:t+6,height:e+6,rx:3,fill:"none",stroke:wl,strokeWidth:2,strokeDasharray:"4,2"})}else u=vl("circle","wedge"===i?{cx:l,cy:c,r:12,fill:"none",stroke:wl,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:l,cy:c,r:8,fill:"none",stroke:wl,strokeWidth:2,strokeDasharray:"4,2"});else u=vl("g",{transform:`translate(${n.left},${n.top})`,children:vl("path",{d:a,fill:"none",stroke:wl,strokeWidth:2.5,strokeDasharray:"6,3"})});return vl("svg",{style:{position:"absolute",left:0,top:0,width:o[0],height:o[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:u})}import*as Sl from"react";function Al(t,e){return"touch"===e?Math.max(t,24):t}function Ml(t){return Array.isArray(t)?t[0]:t}function _l(t,e,n,o){return{data:Ml(t),x:e,y:n,__semioticHoverData:!0,...o}}var Pl=["name","label","title"],Cl=["type","kind","category","group","class","status","role","shape"],Ll=["value","amount","total","count","weight","score"],Rl=new Set(["x","y","z","x0","x1","y0","y1","r","cx","cy","radius","layer","row","rowindex","col","column","depth","index","order","sankeywidth","coincidentpoints","sourcelinks","targetlinks","parent","children","fx","fy","vx","vy"]);function Tl(t,e){for(const n of e){const e=t.find(t=>t.lower===n);if(e)return e}}function Il(t,e={}){if(!t||"object"!=typeof t)return{entries:[]};const n=e.maxEntries??6,o=!1!==e.skipPositional,i=[];for(const[e,n]of Object.entries(t)){if(e.startsWith("_"))continue;if("data"===e)continue;if(o&&Rl.has(e.toLowerCase()))continue;if(null==n)continue;const t=typeof n;("string"===t||"number"===t||"boolean"===t||n instanceof Date)&&i.push({key:e,lower:e.toLowerCase(),value:n})}if(0===i.length)return{entries:[]};let r=i.findIndex(t=>Pl.includes(t.lower));const s=r>=0;0>r&&(r=i.findIndex(t=>"id"===t.lower)),0>r&&(r=i.findIndex(t=>"string"==typeof t.value));const a=0>r?void 0:i[r];let l=i.filter((t,e)=>e!==r);s&&(l=l.filter(t=>"id"!==t.lower));const c=Tl(l,Cl),u=Tl(l,Ll),d=new Set(Cl),h=new Set(Ll),f=[];c&&f.push({key:c.key,value:c.value}),u&&f.push({key:u.key,value:u.value});for(const t of l){if(f.length>=n)break;t!==c&&t!==u&&(d.has(t.lower)||h.has(t.lower)||f.push({key:t.key,value:t.value}))}return{titleKey:a?.key,title:a?.value,entries:f}}import{jsx as $l,jsxs as Ol}from"react/jsx-runtime";var zl={background:"var(--semiotic-tooltip-bg, rgba(0, 0, 0, 0.85))",color:"var(--semiotic-tooltip-text, white)",padding:"8px 12px",borderRadius:"var(--semiotic-tooltip-radius, 6px)",fontSize:"var(--semiotic-tooltip-font-size, 14px)",fontFamily:"var(--semiotic-font-family, inherit)",lineHeight:"1.5",boxShadow:"var(--semiotic-tooltip-shadow, 0 2px 8px rgba(0, 0, 0, 0.15))",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Fl(t,e){return"function"==typeof e?e(t):t[e]}function Dl(t,e){if(e)return e(t);if(null==t)return"";if("number"==typeof t){if(!Number.isFinite(t))return t+"";const e=Number.isInteger(t)?t:parseFloat(t.toPrecision(6));return Math.abs(e)>9999?e.toLocaleString():e+""}return t instanceof Date?t.toLocaleDateString():"object"==typeof t&&null!==t?void 0!==t.id?t.id+"":void 0!==t.name?t.name+"":JSON.stringify(t):t+""}function El(t={}){const{fields:e,title:n,format:o,style:i={},className:r=""}=t;return t=>{if(!t||"object"!=typeof t)return null;let s;const a=[];if(n){const e=Fl(t,n);s=Dl(e,o)}if(e&&e.length>0)e.forEach(e=>{let n,i,r;"string"==typeof e?(n=e,i=e,r=o):(n=e.label,i=e.accessor||e.key||"",r=e.format||o);const s=Fl(t,i);a.push({label:n,value:Dl(s,r)})});else if(!n){const e=["value","y","name","id","label"];for(const n of e)if(void 0!==t[n]){s=Dl(t[n],o);break}if(!s){const e=Object.keys(t).filter(t=>!t.startsWith("_"));e.length>0&&(s=Dl(t[e[0]],o))}}const l={...zl,...i};return Ol("div",{className:("semiotic-tooltip "+r).trim(),style:l,children:[s&&$l("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((t,e)=>Ol("div",{style:{marginTop:0===e&&s?"4px":0},children:[t.label&&Ol("span",{children:[t.label,": "]}),t.value]},e))]})}}import{jsx as Nl}from"react/jsx-runtime";function Bl({x:t,y:e,containerWidth:n,containerHeight:o,margin:i,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const l=Number.isFinite(t)&&Number.isFinite(e),c=Sl.useRef(null),[u,d]=Sl.useState(null);Sl.useLayoutEffect(()=>{const t=c.current;if(!t)return;const e=()=>{const e=t.getBoundingClientRect();Number.isFinite(e.width)&&Number.isFinite(e.height)&&d(t=>t&&.5>Math.abs(t.width-e.width)&&.5>Math.abs(t.height-e.height)?t:{width:e.width,height:e.height})};if(e(),"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(e);return n.observe(t),()=>n.disconnect()},[s,n,o,l]);let h;h=u?`translate(${u.width+12>n-t?"calc(-100% - 12px)":"12px"}, ${u.height+12>o-e?"calc(-100% - 4px)":"4px"})`:`translate(${t>.7*n?"calc(-100% - 12px)":"12px"}, ${.3*o>e?"4px":"calc(-100% - 4px)"})`;const f=function(t){if(!Sl.isValidElement(t))return!1;const e=t.type;if("string"!=typeof e&&e&&!0===e.ownsChrome)return!0;const n=t.props;if(!0===n["data-semiotic-tooltip-chrome"])return!0;if("true"===n["data-semiotic-tooltip-chrome"])return!0;const o=n.style;if(o&&"object"==typeof o){if(null!=o.background&&""!==o.background&&"transparent"!==o.background)return!0;if(null!=o.backgroundColor&&""!==o.backgroundColor&&"transparent"!==o.backgroundColor)return!0}return!1}(r),p=f?null:zl;return l?Nl("div",{ref:c,className:f?s:(s+" semiotic-tooltip").trim(),style:{...p||{},position:"absolute",left:i.left+t,top:i.top+e,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}import*as Wl from"react";import{useCallback as jl,useEffect as Yl,useLayoutEffect as Xl,useMemo as Hl,useRef as Gl}from"react";import{useState as ql,useEffect as Vl}from"react";import{useRef as Ul,useState as Kl,useEffect as Zl}from"react";var Ql=()=>"undefined"!=typeof performance?performance.now():Date.now();function Jl(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}}function tc(t,e){const n=t();return Number.isFinite(n)?n:e}var ec=class{constructor(t={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=t.clock??Ql,this.lastWallTime=tc(this.clock,0),this.logicalTime=this.lastWallTime,this.pausedValue=!0===t.paused,this.visibleValue=!1!==t.visible,this.setRandomSource(t.random,t.seed)}get isActive(){return!this.pausedValue&&this.visibleValue}get paused(){return this.pausedValue}get seed(){return this.seedValue}get visible(){return this.visibleValue}configure(t){this.setClock(t.clock),this.setRandomSource(t.random,t.seed)}setPaused(t){this.pausedValue!==t&&(this.advance(),this.pausedValue=t,this.emit())}setVisible(t){this.visibleValue!==t&&(this.advance(),this.visibleValue=t,this.emit())}snapshot(){return{now:this.now(),paused:this.pausedValue,seed:this.seedValue,visible:this.visibleValue}}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}advance(){const t=tc(this.clock,this.lastWallTime),e=Math.max(0,t-this.lastWallTime);return this.lastWallTime=t,this.isActive&&(this.logicalTime+=e),this.logicalTime}emit(){for(const t of this.subscribers)t()}setClock(t){const e=t??Ql;e!==this.clock&&(this.advance(),this.clock=e,this.lastWallTime=tc(e,this.lastWallTime))}setRandomSource(t,e){const n=function(t){return"number"==typeof t&&Number.isFinite(t)?Math.trunc(t):void 0}(e);t===this.randomInput&&n===this.seedValue||(this.randomInput=t,this.seedValue=n,this.randomSource=t??(void 0===n?Math.random:Jl(n)))}},nc="undefined"==typeof window?Yl:Xl,oc={requestAnimationFrame:t=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(t),cancelAnimationFrame:t=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(t)};function ic(t,e,n){return"function"==typeof t?t({size:e,margin:n}):t}function rc(t){const e=function(){const[t,e]=ql(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return Vl(()=>{if("undefined"==typeof window||!window.matchMedia)return;const t=window.matchMedia("(prefers-reduced-motion: reduce)");return e(t.matches),function(t,e){if("function"==typeof t.addEventListener)return t.addEventListener("change",e),()=>t.removeEventListener("change",e);const n=t;return n.addListener(e),()=>n.removeListener(e)}(t,t=>e(t.matches))},[]),t}(),n=Gl(e);n.current=e;const[o,i]=function(t,e,n){const o=Ul(null),[i,r]=Kl(null);return Zl(()=>{if(!e&&!n)return;const t=o.current;if(!t)return;const i=new ResizeObserver(t=>{for(const e of t){const{width:t,height:n}=e.contentRect;r(e=>e&&e.w===t&&e.h===n?e:{w:t,h:n})}});return i.observe(t),()=>i.disconnect()},[e,n]),[o,[e&&i?i.w:t[0],n&&i?i.h:t[1]]]}(t.sizeProp,t.responsiveWidth,t.responsiveHeight),r=!!t.title,s=!!t.legend&&"top"===t.legendPosition,a=Hl(()=>Ns({...t.marginDefault,...t.userMargin},r,s),[t.marginDefault,t.userMargin,r,s]),l=i[0]-a.left-a.right,c=i[1]-a.top-a.bottom,u=ic(t.foregroundGraphics,i,a),d=ic(t.backgroundGraphics,i,a),h=L(t=>t.theme),{transition:f,introEnabled:p}=function(t,e){if(!1===t)return{transition:void 0,introEnabled:!1};const n="undefined"!=typeof window&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return{transition:t?!0===t?{duration:300}:{duration:t.duration??300,easing:"linear"===t.easing?"linear":"ease-out"}:e,introEnabled:!(n||!t||!0!==t&&!1===t.intro)}}(t.animate,t.transitionProp),g="semiotic-table-"+Wl.useId(),y=Gl(null);if(!y.current){const e=!t.suspendWhenHidden||"undefined"==typeof document||!document.hidden;y.current=new ec({clock:t.clock,random:t.random,seed:t.seed,paused:t.paused,visible:e})}const m=y.current;m.configure({clock:t.clock,random:t.random,seed:t.seed});const b=Gl(null),x=Gl(t.frameScheduler??oc);x.current=t.frameScheduler??oc;const v=Gl(null),w=Gl(!1),k=Gl(()=>{}),S=jl(()=>{if(null!==b.current||w.current)return;const t=x.current;let e=!1,n=!1;const o=t.requestAnimationFrame(()=>{e=!0;const t=!n;t&&(w.current=!0),b.current=null,v.current=null;try{k.current()}finally{t&&(w.current=!1)}});n=!0,e||(b.current=o,v.current=t)},[]),A=jl(()=>{null!==b.current&&((v.current??x.current).cancelAnimationFrame(b.current),b.current=null,v.current=null)},[]);nc(()=>{m.setPaused(!0===t.paused)},[m,t.paused]),Yl(()=>{if(!t.suspendWhenHidden||"undefined"==typeof document)return void m.setVisible(!0);const e=()=>m.setVisible(!document.hidden);return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[m,t.suspendWhenHidden]),Yl(()=>()=>{A()},[A]);const M=Gl(()=>{}),_=Gl(()=>{}),P=Gl(null),C=Gl(null),R=Gl(null),T=jl(()=>{const t=P.current;P.current=null,t&&M.current(t)},[]),I=jl(t=>{if(P.current={clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType},null===C.current){const t=x.current;let e=!1;const n=t.requestAnimationFrame(()=>{e=!0,C.current=null,R.current=null,T()});e||(C.current=n,R.current=t)}},[T]),$=jl(()=>{P.current=null,null!==C.current&&((R.current??x.current).cancelAnimationFrame(C.current),C.current=null,R.current=null),_.current()},[]);Yl(()=>()=>{P.current=null,null!==C.current&&((R.current??x.current).cancelAnimationFrame(C.current),C.current=null,R.current=null)},[]);const O=t.themeDirtyRef;return nc(()=>{O&&(Go++,O.current=!0,S())},[h,S,O]),{reducedMotion:e,reducedMotionRef:n,responsiveRef:o,size:i,margin:a,adjustedWidth:l,adjustedHeight:c,resolvedForeground:u,resolvedBackground:d,currentTheme:h,transition:f,introEnabled:p,tableId:g,frameRuntime:m,rafRef:b,renderFnRef:k,scheduleRender:S,cancelRender:A,hoverHandlerRef:M,hoverLeaveRef:_,onPointerMove:I,onPointerLeave:$}}import{useEffect as sc,useRef as ac}from"react";import{jsx as lc}from"react/jsx-runtime";function cc({children:t,size:e,margin:n,overflowVisible:o=!1}){return t?lc("svg",{style:{position:"absolute",left:0,top:0,width:e[0],height:e[1],pointerEvents:"none",overflow:o?"visible":void 0},children:lc("g",{transform:`translate(${n.left},${n.top})`,children:t})}):null}function uc(t,e,n,o){return"function"==typeof t?t({size:e,margin:n,scales:o}):t}function dc(t,e,n,o){const i=t.getContext("2d");if(!i)return null;const r=Math.round(e[0]*o),s=Math.round(e[1]*o),a=r/e[0],l=s/e[1],c=e[0]+"px",u=e[1]+"px";return t.style.width!==c&&(t.style.width=c),t.style.height!==u&&(t.style.height=u),t.width===r&&t.height===s||(t.width=r,t.height=s),i.setTransform(a,0,0,l,0,0),i.translate(n.left,n.top),i}import{useCallback as hc,useRef as fc}from"react";function pc(t,e,n,o){return"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:n,fn:t}:"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:o,fn:e}:{key:void 0,fn:null}}var gc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],yc=3156e7;function mc(t){const e=t[1]-t[0];return 864e5>e?t=>{const e=new Date(t);return`${(e.getUTCHours()+"").padStart(2,"0")}:${(e.getUTCMinutes()+"").padStart(2,"0")}`}:yc>e?t=>{const e=new Date(t);return`${gc[e.getUTCMonth()]} ${e.getUTCDate()}`}:5*yc>e?t=>{const e=new Date(t);return`${gc[e.getUTCMonth()]} ${e.getUTCFullYear()}`}:t=>new Date(t).getUTCFullYear()+""}function bc(t){if(!t)return;const e=[];for(const n of t)if("point"===n.type)e.push(n);else if("symbol"===n.type)e.push({pointId:n.pointId,x:n.x,y:n.y,r:wn(n.size)});else if("glyph"===n.type){const t=Yo(n.glyph,n.size);e.push({pointId:n.pointId,x:n.x+t.centerDx,y:n.y+t.centerDy,r:t.radius})}return e}import{line as xc}from"d3-shape";function vc(t,e,n,o,i,r){if(2>e.length)return;const s=[0];for(let t=1;e.length>t;t++){const n=e[t][0]-e[t-1][0],o=e[t][1]-e[t-1][1];s.push(s[t-1]+Math.sqrt(n*n+o*o))}const a=s[s.length-1];if(0===a)return;const l=Math.min(.2*a,40);t.strokeStyle=n,t.lineWidth=o,t.lineCap=r;for(let n=0;e.length-1>n;n++){const o=(s[n]+s[n+1])/2;let r=i;l>o&&(r*=o/l),l>a-o&&(r*=(a-o)/l),t.globalAlpha=Math.max(0,r),t.beginPath(),t.moveTo(e[n][0],e[n][1]),t.lineTo(e[n+1][0],e[n+1][1]),t.stroke()}}var wc=(t,e,n,o)=>{const i=e.filter(t=>"line"===t.type);for(const e of i){if(2>e.path.length)continue;const n=e._introClipFraction;void 0!==n&&1>n&&(t.save(),t.beginPath(),t.rect(0,0,o.width*n,o.height),t.clip());const i=e.style.stroke||"#007bff",r=Ko(t,i)||i,s=e.style.strokeWidth||2,a=e.colorThresholds,l=e.rawValues;if(t.setLineDash(e.style.strokeDasharray?e.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),t.lineWidth=s,t.lineCap=e.style.strokeLinecap||"butt",e.style._edgeFade){vc(t,e.path,r,s,e.style.opacity??1,e.style.strokeLinecap||"butt"),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt";continue}const c=gi(e.curve),u=a&&a.length>0&&l&&l.length===e.path.length,d=e._decayOpacities;if(d&&d.length===e.path.length&&!u){t.strokeStyle=r;const n=e.style.opacity??1;for(let o=0;e.path.length-1>o;o++)t.globalAlpha=.5*(d[o]+d[o+1])*n,t.beginPath(),t.moveTo(e.path[o][0],e.path[o][1]),t.lineTo(e.path[o+1][0],e.path[o+1][1]),t.stroke()}else if(u){const n=Qs(e.path,l,a,r);for(const e of n){t.beginPath(),t.strokeStyle=Ko(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let n=1;e.path.length>n;n++)t.lineTo(e.path[n][0],e.path[n][1]);t.stroke()}}else{t.beginPath();const n=e.strokeGradient&&e.path.length>=2?mi(t,e.strokeGradient,r,e.path[0][0],0,e.path[e.path.length-1][0],0):null;if(t.strokeStyle=n||r,c)xc().x(t=>t[0]).y(t=>t[1]).curve(c).context(t)(e.path);else{const[n,o]=e.path[0];t.moveTo(n,o);for(let n=1;e.path.length>n;n++)t.lineTo(e.path[n][0],e.path[n][1])}t.stroke()}if(e.style.fill&&e.style.fillOpacity&&e.style.fillOpacity>0){if(t.beginPath(),t.globalAlpha=e.style.fillOpacity,t.fillStyle=yi(t,e.style.fill,e.style.fill),c&&!u)xc().x(t=>t[0]).y(t=>t[1]).curve(c).context(t)(e.path);else{const[n,o]=e.path[0];t.moveTo(n,o);for(let n=1;e.path.length>n;n++)t.lineTo(e.path[n][0],e.path[n][1])}const n=e.path[0][0];t.lineTo(e.path[e.path.length-1][0],o.height),t.lineTo(n,o.height),t.closePath(),t.fill()}void 0!==n&&1>n&&t.restore(),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt"}};function kc(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function Sc(t,e,n=.3){kc(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h))}function Ac(t,e,n=.6){if(!kc(e))return;const o=e.r+(e._pulseGlowRadius??4)*e._pulseIntensity,i=e.cx??e.x??0,r=e.cy??e.y??0;t.beginPath(),t.arc(i,r,o,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=e._pulseIntensity*n,t.stroke()}function Mc(t,e,n,o=.35){kc(e)&&(t.globalAlpha=e._pulseIntensity*o,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",n?t.fill(n):t.fill())}import{area as _c,line as Pc}from"d3-shape";function Cc(t,e){const n=gi(e.curve);if(!n||2>e.topPath.length||2>e.bottomPath.length){t.beginPath(),t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let n=1;e.topPath.length>n;n++)t.lineTo(e.topPath[n][0],e.topPath[n][1]);for(let n=e.bottomPath.length-1;n>=0;n--)t.lineTo(e.bottomPath[n][0],e.bottomPath[n][1]);t.closePath()}else{const o=_c().x(t=>t[0]).y0((t,n)=>e.bottomPath[n][1]).y1(t=>t[1]).curve(n).context(t);t.beginPath(),o(e.topPath)}}function Lc(t,e){const n=gi(e.curve);if(t.beginPath(),n)Pc().x(t=>t[0]).y(t=>t[1]).curve(n).context(t)(e.topPath);else{t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let n=1;e.topPath.length>n;n++)t.lineTo(e.topPath[n][0],e.topPath[n][1])}}var Rc=(t,e,n,o)=>{const i=e.filter(t=>"area"===t.type);for(const e of i){if(2>e.topPath.length)continue;let n=!1;e.clipRect&&(t.save(),t.beginPath(),t.rect(e.clipRect.x,e.clipRect.y,e.clipRect.width,e.clipRect.height),t.clip(),n=!0);const i=e._introClipFraction;void 0!==i&&1>i&&(t.save(),t.beginPath(),t.rect(0,0,o.width*i,o.height),t.clip());const r=yi(t,e.style.fill,"#4e79a7"),s=e._decayOpacities,a=!(!e.colorThresholds?.length||!e.rawValues||e.rawValues.length!==e.topPath.length),l=!!e.strokeColorBands?.length;if(s&&s.length===e.topPath.length&&!a&&!l){const n=e.style.fillOpacity??.7;t.fillStyle=r;for(let o=0;e.topPath.length-1>o;o++)t.globalAlpha=.5*(s[o]+s[o+1])*n,t.beginPath(),t.moveTo(e.topPath[o][0],e.topPath[o][1]),t.lineTo(e.topPath[o+1][0],e.topPath[o+1][1]),t.lineTo(e.bottomPath[o+1][0],e.bottomPath[o+1][1]),t.lineTo(e.bottomPath[o][0],e.bottomPath[o][1]),t.closePath(),t.fill();if(e.style.stroke&&"none"!==e.style.stroke){t.strokeStyle=Ko(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]);for(let n=0;e.topPath.length-1>n;n++)t.globalAlpha=.5*(s[n]+s[n+1]),t.beginPath(),t.moveTo(e.topPath[n][0],e.topPath[n][1]),t.lineTo(e.topPath[n+1][0],e.topPath[n+1][1]),t.stroke()}t.globalAlpha=1;continue}const c=e.style.opacity??1;if(Cc(t,e),e.fillGradient&&e.fillGradient.stops.length>=2&&e.fillGradient){let n=1/0;for(const t of e.topPath)n>t[1]&&(n=t[1]);let o=-1/0;for(const t of e.bottomPath)t[1]>o&&(o=t[1]);const i=mi(t,e.fillGradient,"string"==typeof r?r:"#4e79a7",0,n,0,o);t.fillStyle=i||r,t.globalAlpha=c}else t.globalAlpha=(e.style.fillOpacity??.7)*c,t.fillStyle=r;if(t.fill(),e._pulseIntensity&&e._pulseIntensity>0&&(Cc(t,e),Mc(t,e)),e.style.stroke&&"none"!==e.style.stroke){t.globalAlpha=c;const n=Ko(t,e.style.stroke)||e.style.stroke,o=a||l||!e.strokeGradient||2>e.topPath.length?null:mi(t,e.strokeGradient,n,e.topPath[0][0],0,e.topPath[e.topPath.length-1][0],0);if(t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]),l){let o=1/0,i=-1/0;for(const[t]of e.topPath)o=Math.min(o,t),i=Math.max(i,t);const r=t.lineWidth;for(const s of e.strokeColorBands){t.save(),t.beginPath(),t.rect(o-r,s.y,i-o+2*r,s.height),t.clip();const a=s.color??n;t.strokeStyle=Ko(t,a)||a,Lc(t,e),t.stroke(),t.restore()}}else if(a){const o=Qs(e.topPath,e.rawValues,e.colorThresholds,n);for(const e of o){t.beginPath(),t.strokeStyle=Ko(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let n=1;e.path.length>n;n++)t.lineTo(e.path[n][0],e.path[n][1]);t.stroke()}}else t.strokeStyle=o||n,Lc(t,e),t.stroke()}void 0!==i&&1>i&&t.restore(),n&&t.restore(),t.globalAlpha=1}},Tc=(t,e,n,o)=>{const i=e.filter(t=>"point"===t.type);if(0!==i.length){t.save();try{const e=t.globalAlpha;for(const n of i)t.beginPath(),t.arc(n.x,n.y,n.r,0,2*Math.PI),t.globalAlpha=e*(n.style.opacity??n.style.fillOpacity??1),t.fillStyle=yi(t,n.style.fill,"#4e79a7"),t.fill(),n.style.stroke&&"none"!==n.style.stroke&&(t.strokeStyle=yi(t,n.style.stroke,n.style.stroke),t.lineWidth=n.style.strokeWidth||1,t.stroke()),Ac(t,n)}finally{t.restore()}}},Ic=new Map;function $c(t,e,n,o,i,r){if(0>=e.size)return;const s=function(t,e,n){try{if(n)return new Path2D(n);const o=`${t??"circle"}:${Math.round(e)}`;let i=Ic.get(o);return i||(i=new Path2D(vn(t,e)),Ic.size>256&&Ic.clear(),Ic.set(o,i)),i}catch{return null}}(e.symbolType,e.size,e.path);if(!s)return;t.save(),t.translate(n,o),e.rotation&&t.rotate(e.rotation);const a=(e.style.opacity??1)*(e._decayOpacity??1);e.style.fill&&(t.globalAlpha=i*a*(e.style.fillOpacity??1),t.fillStyle=yi(t,e.style.fill,r),t.fill(s)),e.style.stroke&&"none"!==e.style.stroke&&(t.globalAlpha=i*a,t.strokeStyle=Ko(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth??1,t.stroke(s)),t.restore()}var Oc=(t,e)=>{const n=t.globalAlpha;for(const o of e)"symbol"===o.type&&$c(t,o,o.x,o.y,n,"#4e79a7");t.globalAlpha=n};function zc(t,e,n,o,i){if(0>=e.size)return;const r=e.glyph;if(!r||!r.parts?.length)return;const s=Eo(r,e.size);if(0>=s.scale)return;const a=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=a)return;const l=e=>{const n=yi(t,e,e);return"string"==typeof n?n:e},c=e.color??("string"==typeof e.style.fill?e.style.fill:void 0);t.save(),t.translate(n,o),e.rotation&&t.rotate(e.rotation),t.translate(s.offsetX,s.offsetY),t.scale(s.scale,s.scale),t.globalAlpha=i*a*(e.style.fillOpacity??1);const u=jo(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");u&&e.ghostColor&&Xo(t,r,c,e.accent,e.ghostColor,l),u&&(t.beginPath(),t.rect(u.x,u.y,u.width,u.height),t.clip()),Xo(t,r,c,e.accent,void 0,l),t.restore()}function Fc(t,e){const{x:n,y:o,w:i,h:r}=e,{tl:s,tr:a,br:l,bl:c}=ta(e);t.beginPath(),t.moveTo(n+s,o),t.lineTo(n+i-a,o),a>0&&t.arcTo(n+i,o,n+i,o+a,a),t.lineTo(n+i,o+r-l),l>0&&t.arcTo(n+i,o+r,n+i-l,o+r,l),t.lineTo(n+c,o+r),c>0&&t.arcTo(n,o+r,n,o+r-c,c),t.lineTo(n,o+s),s>0&&t.arcTo(n,o,n+s,o,s),t.closePath()}function Dc(t,e){const n=yi(t,e.style.fill,Ko(t,"var(--semiotic-primary, #007bff)")),o=function(t){switch(t.roundedEdge){case"bottom":return{x0:t.x,y0:t.y+t.h,x1:t.x,y1:t.y};case"right":return{x0:t.x+t.w,y0:t.y,x1:t.x,y1:t.y};case"left":return{x0:t.x,y0:t.y,x1:t.x+t.w,y1:t.y};default:return{x0:t.x,y0:t.y,x1:t.x,y1:t.y+t.h}}}(e);return(e.fillGradient&&"string"==typeof n?mi(t,e.fillGradient,n,o.x0,o.y0,o.x1,o.y1):null)||n}function Ec(t,e){return!(!e.style.stroke||"none"===e.style.stroke||(t.strokeStyle=Ko(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,0))}var Nc=(t,e,n,o)=>{const i=e.filter(t=>"rect"===t.type);for(const e of i){if(null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),e.style.icon)Bc(t,e);else if(e.cornerRadii&&Js(e.cornerRadii))t.fillStyle=Dc(t,e),Fc(t,e),t.fill(),Ec(t,e)&&t.stroke();else if(e.roundedTop&&e.roundedTop>0){t.fillStyle=Dc(t,e);const n=Math.min(e.roundedTop,e.w/2,e.h/2);t.beginPath();const{x:o,y:i,w:r,h:s}=e;switch(e.roundedEdge){case"right":t.moveTo(o,i),t.lineTo(o+r-n,i),t.arcTo(o+r,i,o+r,i+n,n),t.lineTo(o+r,i+s-n),t.arcTo(o+r,i+s,o+r-n,i+s,n),t.lineTo(o,i+s);break;case"left":t.moveTo(o+r,i),t.lineTo(o+n,i),t.arcTo(o,i,o,i+n,n),t.lineTo(o,i+s-n),t.arcTo(o,i+s,o+n,i+s,n),t.lineTo(o+r,i+s);break;case"bottom":t.moveTo(o,i),t.lineTo(o+r,i),t.lineTo(o+r,i+s-n),t.arcTo(o+r,i+s,o+r-n,i+s,n),t.lineTo(o+n,i+s),t.arcTo(o,i+s,o,i+s-n,n);break;default:t.moveTo(o,i+s),t.lineTo(o,i+n),t.arcTo(o,i,o+n,i,n),t.lineTo(o+r-n,i),t.arcTo(o+r,i,o+r,i+n,n),t.lineTo(o+r,i+s)}t.closePath(),t.fill(),Ec(t,e)&&t.stroke()}else t.fillStyle=Dc(t,e),t.fillRect(e.x,e.y,e.w,e.h),Ec(t,e)&&t.strokeRect(e.x,e.y,e.w,e.h);Sc(t,e),t.globalAlpha=1}};function Bc(t,e){const n=e.style.icon,o=e.style.iconPadding||2,i=Math.min(e.w,e.h)-o;if(0>=i)return;const r=e.h>e.w;if(t.save(),t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip(),r){const r=i+o,s=e.x+(e.w-i)/2;for(let o=e.y+e.h-i;o>=e.y-i;o-=r)t.drawImage(n,s,o,i,i)}else{const r=i+o,s=e.y+(e.h-i)/2;for(let o=e.x;e.x+e.w>o;o+=r)t.drawImage(n,o,s,i,i)}t.restore()}function Wc(t){const[e,n,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*n+.114*o>128?"#000":"#fff"}function jc(t){return Number.isInteger(t)?t+"":100>Math.abs(t)?1>Math.abs(t)?t.toPrecision(3):t.toFixed(1):t.toFixed(0)}var Yc=(t,e,n,o)=>{const i=e.filter(t=>"heatcell"===t.type);t.save();try{for(const e of i){const n=e.style;null!=n?.opacity&&(t.globalAlpha=n.opacity),t.fillStyle=e.fill,t.fillRect(e.x,e.y,e.w,e.h);const o=Math.max(0,n?.strokeWidth??1);if(o>0&&(t.strokeStyle=Ko(t,n?.stroke??"var(--semiotic-surface, #fff)"),t.lineWidth=o,t.strokeRect(e.x,e.y,e.w,e.h)),Sc(t,e),t.globalAlpha=1,e.showValues&&null!=e.value){if(20>e.w||20>e.h)continue;const n=e.valueFormat?e.valueFormat(e.value):jc(e.value),o=Math.max(10,Math.min(16,.3*Math.min(e.w,e.h))),i=e.x+e.w/2,r=e.y+e.h/2;t.fillStyle=Wc(e.fill),t.font=o+"px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(n,i,r)}}}finally{t.restore()}},Xc=(t,e,n,o)=>{for(const n of e){if("candlestick"!==n.type)continue;const e=n;t.save();const i=(e._decayOpacity??1)*(e.style?.opacity??1);1!==i&&(t.globalAlpha=i);const r=Ko(t,e.wickColor)||e.wickColor,s=60>o.height,a=s?Math.max(e.wickWidth,2):e.wickWidth,l=()=>{t.beginPath(),t.moveTo(e.x,e.highY),t.lineTo(e.x,e.lowY),t.strokeStyle=r,t.lineWidth=a,t.stroke()};if(s||l(),e.isRange){const n=e.dotRadius??Math.max(2,Math.min(e.bodyWidth/2,.12*o.height));t.fillStyle=r,t.beginPath(),t.arc(e.x,e.highY,n,0,2*Math.PI),t.fill(),t.beginPath(),t.arc(e.x,e.lowY,n,0,2*Math.PI),t.fill()}else if(e.bodyWidth>0){const n=Math.min(e.openY,e.closeY),o=Math.abs(e.openY-e.closeY),i=e.isUp?e.upColor:e.downColor,r=Ko(t,i)||i;t.fillStyle=r,t.fillRect(e.x-e.bodyWidth/2,n,e.bodyWidth,Math.max(o,1)),t.strokeStyle=r,t.lineWidth=1,t.strokeRect(e.x-e.bodyWidth/2,n,e.bodyWidth,Math.max(o,1))}s&&l(),t.restore()}},Hc={line:[Rc,wc,Tc],area:[Rc,Tc],stackedarea:[Rc,Tc],scatter:[Tc,Oc],bubble:[Tc,Oc],heatmap:[Yc],bar:[Nc],swarm:[Tc],waterfall:[(t,e,n,o)=>{Nc(t,e);const i=e.filter(t=>"rect"===t.type);if(2>i.length)return;const r=i[0].datum,s=r?._connectorStroke;if(s){t.save(),t.strokeStyle=Ko(t,s)||s,t.lineWidth=r?._connectorWidth??1,t.setLineDash([]);for(let e=0;i.length-1>e;e++){const o=i[e],r=i[e+1],s=o.datum,a=r.datum;if(null==s?.cumEnd||null==a?.baseline)continue;const l=n.y(s.cumEnd),c=o.x+o.w,u=r.x;t.beginPath(),t.moveTo(c,l),t.lineTo(u,l),t.stroke()}t.restore()}}],candlestick:[Xc],mixed:[Rc,wc,Tc],custom:[Rc,Nc,Yc,wc,Tc,Oc,(t,e)=>{const n=t.globalAlpha;for(const o of e)"glyph"===o.type&&zc(t,o,o.x,o.y,n);t.globalAlpha=n},Xc]},Gc=new Set;function qc(t,e){const n="function"==typeof t?t(e.datum??null,e):t;return(o=n)&&"object"==typeof o&&"string"==typeof o.id&&"function"==typeof o.cacheKey&&"function"==typeof o.drawCanvas&&"function"==typeof o.renderStaticSVG?n:void 0;var o}function Vc(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const n=`${t}:${e}`;Gc.has(n)||(Gc.add(n),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}function Uc(t){const{node:e,index:n,renderMode:o,fallback:i}=t,r=qc(o,e);if(!r)return i();const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${n}`});return null!=s?s:(Vc(r.id,e.type??"unknown"),i())}function Kc(t){const e=[];return t.nodes.forEach((n,o)=>{const i=Uc({node:n,index:o,renderMode:t.renderMode,fallback:()=>t.fallback(n,o)});null!=i&&!1!==i&&e.push({node:n,element:i})}),e}import{jsx as Zc,jsxs as Qc}from"react/jsx-runtime";import{jsx as Jc,jsxs as tu}from"react/jsx-runtime";function eu(t){return null==t?"":"number"==typeof t?Number.isInteger(t)?t+"":t.toFixed(2):t instanceof Date?t.toLocaleString():t+""}function nu({hover:t}){const e=t.data??{},n=e.y??e.value,o=e.x??e.time;if(void 0===n&&void 0===o){const t=Il(e);if(null!=t.title||t.entries.length>0)return tu("div",{className:"semiotic-tooltip",style:zl,children:[null!=t.title&&Jc("div",{style:{fontWeight:600,marginBottom:t.entries.length?2:0},children:t.title+""}),t.entries.map(t=>tu("div",{style:{opacity:.7,fontSize:11},children:[t.key,":"," ",Jc("span",{style:{fontWeight:600},children:eu(t.value)})]},t.key))]})}return tu("div",{className:"semiotic-tooltip",style:zl,children:[Jc("div",{style:{fontWeight:600,marginBottom:2},children:eu(n)}),Jc("div",{style:{opacity:.7,fontSize:11},children:eu(o)})]})}function ou(t){const{onObservation:e,datum:n,x:o=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=t;e&&(n?(e({type:"hover",datum:n,x:o,y:i,timestamp:l,chartType:r,chartId:s}),"focus"===a?.type&&e({type:"focus",datum:n,inputType:"touch"===a.inputType?"pointer":a.inputType,timestamp:l,chartType:r,chartId:s})):e({type:"hover-end",timestamp:l,chartType:r,chartId:s}))}function iu(t){const{onObservation:e,datum:n,x:o=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=t;e&&(n?(e({type:"click",datum:n,x:o,y:i,timestamp:l,chartType:r,chartId:s}),"activate"===a?.type&&e({type:"activate",datum:n,inputType:a.inputType,timestamp:l,chartType:r,chartId:s})):e({type:"click-end",timestamp:l,chartType:r,chartId:s}))}nu.ownsChrome=!0;import{useCallback as ru}from"react";import{useCallback as su,useRef as au}from"react";function lu(t,e,n){const o=t.byGroup.get(e);let i=0,r=Math.abs(o[0].x-n.x);for(let t=1;o.length>t;t++){const e=Math.abs(o[t].x-n.x);r>e&&(r=e,i=t)}return o[i]._flatIndex}function cu(t){const e=[];for(const n of t)switch(n.type){case"point":e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"symbol":if(0>=n.size)break;e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"glyph":{if(0>=n.size||null==n.datum)break;const t=Yo(n.glyph,n.size);e.push({x:n.x+t.centerDx,y:n.y+t.centerDy,datum:n.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:"_default"});break}case"line":{const t=n,o=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let n=0;t.path.length>n&&o.length>n;n++)e.push({x:t.path[n][0],y:t.path[n][1],datum:o[n],shape:"circle",group:i});break}case"area":{const t=n,o=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let n=0;t.topPath.length>n&&o.length>n;n++)e.push({x:t.topPath[n][0],y:t.topPath[n][1],datum:o[n],shape:"circle",group:i});break}case"rect":e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:n.group??"_default"});break;case"heatcell":e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}import{jsx as uu,jsxs as du}from"react/jsx-runtime";var hu={top:20,right:20,bottom:30,left:40},fu=Xa;function pu(t){if(t)return"x"===t.dimension?"pan-y":"y"===t.dimension?"pan-x":"none"}var gu=_e(Me(function(t,e){const{chartType:n,runtimeMode:o,data:i,chunkThreshold:r,chunkSize:s,xAccessor:a,yAccessor:l,accessorRevision:u,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:g,lineDataAccessor:y,curve:m,normalize:b,baseline:x,stackOrder:v,binSize:k,valueAccessor:S,arrowOfTime:A="right",windowMode:M="sliding",windowSize:_=200,timeAccessor:P,xExtent:C,yExtent:L,extentPadding:R=.1,scalePadding:T,sizeRange:I,size:$=[500,300],responsiveWidth:O,responsiveHeight:z,margin:F,className:D,background:E,renderMode:N,lineStyle:B,pointStyle:W,areaStyle:Y,barStyle:X,waterfallStyle:H,swarmStyle:G,barColors:q,colorScheme:V,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:J,lineGradient:tt,semanticLineStops:et,areaGroups:nt,openAccessor:ot,highAccessor:it,lowAccessor:rt,closeAccessor:st,candlestickStyle:at,showAxes:lt=!0,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:ft,yFormat:pt,axisExtent:gt,tickFormatTime:yt,tickFormatValue:mt,hoverAnnotation:bt,tooltipContent:xt,customHoverBehavior:vt,customClickBehavior:wt,onObservation:kt,annotationObservationCallback:St,chartId:At,enableHover:Mt,hoverRadius:_t=30,tooltipMode:Pt,annotations:Ct,onAnnotationActivate:Lt,autoPlaceAnnotations:Rt,svgAnnotationRules:Tt,showGrid:It,legend:$t,legendHoverBehavior:Ot,legendClickBehavior:zt,legendHighlightedCategory:Ft,legendIsolatedCategories:Dt,legendPosition:Et,legendLayout:Wt,legendCategoryAccessor:jt,onCategoriesChange:Yt,backgroundGraphics:Xt,foregroundGraphics:Ht,canvasPreRenderers:Gt,svgPreRenderers:qt,title:Vt,categoryAccessor:Ut,brush:Kt,onBrush:Zt,decay:Qt,pulse:Jt,transition:te,animate:ee,staleness:ne,frameScheduler:oe,clock:ie,random:re,seed:se,paused:ae=!1,suspendWhenHidden:le=!0,heatmapAggregation:ce,heatmapXBins:ue,heatmapYBins:de,showValues:he,heatmapValueFormat:fe,marginalGraphics:ge,pointIdAccessor:ye,xScaleType:Me,yScaleType:_e,accessibleTable:Pe=!0,description:Ce,summary:Le,linkedCrosshairName:Re,linkedCrosshairSourceId:$e,customLayout:Oe,onLayoutError:ze,layoutConfig:Fe,layoutSelection:De}=t,{customHoverBehavior:Ee,customClickBehavior:Ne,hasClickBehavior:Be}=function({customHoverBehavior:t,customClickBehavior:e,onObservation:n,chartId:o,chartType:i}){const r=!(!t&&!n),s=!(!e&&!n),a=ru((e,r)=>{t?.(e,r),ou({onObservation:n,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:i,chartId:o,context:r})},[o,i,t,n]),l=ru((t,r)=>{e?.(t,r),iu({onObservation:n,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:i,chartId:o,context:r})},[o,i,e,n]);return{customHoverBehavior:r?a:void 0,customClickBehavior:s?l:void 0,hasClickBehavior:s}}({customHoverBehavior:vt,customClickBehavior:wt,onObservation:kt,chartId:At,chartType:"StreamXYFrame"}),We=Ae().replace(/:/g,""),je=be(!1),Ye=be({w:-1,h:-1}),Xe=be(!1),He=rc({sizeProp:$,responsiveWidth:O,responsiveHeight:z,userMargin:F,marginDefault:hu,title:Vt,legend:$t,legendPosition:Et,animate:ee,transitionProp:te,frameScheduler:oe,clock:ie,random:re,seed:se,paused:ae,suspendWhenHidden:le,themeDirtyRef:je}),Ge=function(){const[t,e]=$a(!1);return za(()=>{e(!0)},[]),t}(),qe=function(){const t=Oa(Fa,Da,Ea);return Ia(t).current}(),{reducedMotionRef:Ve,responsiveRef:Ue,size:Ke,currentTheme:Ze,transition:Qe,introEnabled:Je,tableId:tn,rafRef:en,renderFnRef:nn,scheduleRender:on,frameRuntime:rn}=He;let an=He.margin;if(ge){const t=60,e={...He.margin};ge.top&&t>e.top&&(e.top=t),ge.bottom&&t>e.bottom&&(e.bottom=t),ge.left&&t>e.left&&(e.left=t),ge.right&&t>e.right&&(e.right=t),an=e}const ln=Ke[0]-an.left-an.right,cn=Ke[1]-an.top-an.bottom,un=we(()=>j(i),[i]),dn=bt??Mt,[hn,fn]=xe(0),pn=be(0),[gn,yn]=xe(null),mn=uc(Ht,Ke,an,gn),bn=uc(Xt,Ke,an,gn),xn=be(null),vn=be(null),wn=be(void 0),[kn,Sn]=xe(null),An=be(fu.primary),Mn=be(function(){let t=-1,e=Xa;return{resolve(n){if(!n)return Xa;const o=Go;return o===t||(e=function(t){if(!t)return Xa;const e=getComputedStyle(t),n=e.getPropertyValue("--semiotic-border").trim(),o=e.getPropertyValue("--semiotic-text-secondary").trim(),i=e.getPropertyValue("--semiotic-bg").trim(),r=e.getPropertyValue("--semiotic-primary").trim(),s=o||e.getPropertyValue("--text-secondary").trim(),a=e.getPropertyValue("--text-primary").trim(),l=n||e.getPropertyValue("--surface-3").trim(),c=i||e.getPropertyValue("--surface-0").trim();return s||a||n||r?{axisStroke:l||Xa.axisStroke,tickText:s||Xa.tickText,crosshair:s?Ha(s,"66"):Xa.crosshair,hoverFill:c?Ha(c,"4D"):Xa.hoverFill,hoverStroke:s?Ha(s,"99"):Xa.hoverStroke,pointRing:c||Xa.pointRing,primary:r||Xa.primary,background:c||Xa.background}:Xa}(n),t=o),e},invalidate(){t=-1}}}()),_n=be(!1),Pn=vo(new _o("StreamXYFrame")),[Cn,Ln]=xe(!1),[Rn,Tn]=xe([]),[In,$n]=xe([]),On="streaming"===o||["bar","swarm","waterfall"].includes(n),zn=function(t){const e=Na(t);return function(t,e){if(Object.is(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return Wa(t,e);if(!ja(t)||!ja(e))return!1;const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const o of n){if(!Object.prototype.hasOwnProperty.call(e,o))return!1;const n=t[o],i=e[o];if(!Object.is(n,i))if(Array.isArray(n)&&Array.isArray(i)){if(!Wa(n,i))return!1}else{if(!ja(n)||!ja(i))return!1;if(!Ba(n,i))return!1}}return!0}(e.current,t)||(e.current=t),e.current}(we(()=>({chartType:n,runtimeMode:On?"streaming":"bounded",windowSize:_,windowMode:M,arrowOfTime:On?A:"right",extentPadding:R,scalePadding:T,axisExtent:gt,xAccessor:a,yAccessor:l,accessorRevision:u,timeAccessor:On?P:void 0,valueAccessor:S,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:g||(y?"_lineGroup":void 0),categoryAccessor:Ut,lineDataAccessor:y,xScaleType:Me,yScaleType:_e,xExtent:C,yExtent:L,sizeRange:I,binSize:k,normalize:b,baseline:x,stackOrder:v,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:Nt(J),areaGroups:nt?new Set(nt):void 0,lineGradient:Bt(tt),semanticLineStops:et,openAccessor:ot,highAccessor:it,lowAccessor:rt,closeAccessor:st,candlestickStyle:at,lineStyle:B,pointStyle:W,areaStyle:Y,swarmStyle:G,waterfallStyle:H,colorScheme:V,barColors:q,barStyle:X,annotations:Ct,decay:Qt,pulse:Jt,transition:Qe,introAnimation:Je,staleness:ne,clock:rn.now,heatmapAggregation:ce,heatmapXBins:ue,heatmapYBins:de,showValues:he,heatmapValueFormat:fe,pointIdAccessor:ye,curve:m,themeCategorical:Ze?.colors?.categorical,themeSemantic:w(Ze),themeSequential:Ze?.colors?.sequential,themeDiverging:Ze?.colors?.diverging,customLayout:Oe,onLayoutError:ze,layoutConfig:Fe,layoutMargin:an}),[n,On,_,M,A,R,T,gt,a,l,u,P,S,d,h,f,p,g,y,Ut,Me,_e,C,L,I,k,b,x,v,U,K,Z,Q,J,nt,tt,et,ot,it,rt,st,at,B,W,Y,G,H,V,q,X,Ct,Qt,Jt,Qe,Je,ne,rn.now,ce,ue,de,he,fe,ye,m,Ze,Oe,ze,Fe,an])),Fn=be(null);Fn.current||(Fn.current=new mo(zn));const Dn=function(t,e,n,o){const i=fc({accessor:e,onChange:n,readData:o}),r=fc([]);return i.current={accessor:e,onChange:n,readData:o},hc(()=>{const{accessor:e,onChange:n,readData:o}=i.current;if(!n||!e)return;const s=function(t,e){if(!e)return[];const n=new Set,o=[];for(const i of t){if(!i||"object"!=typeof i)continue;const t="function"==typeof e?e(i):i[e];if(null==t)continue;const r=t+"";n.has(r)||(n.add(r),o.push(r))}return o}(t.current?o(t.current):[],e);(function(t,e){if(t.length!==e.length)return!1;for(let n=0;t.length>n;n++)if(t[n]!==e[n])return!1;return!0})(s,r.current)||(r.current=s,n(s))},[t])}(Fn,jt,Yt,t=>t.getData());!function(t,e,n,o){Ro(()=>{t.current?.updateConfig(e),n.current=!0,o()},[e,o,t,n])}(Fn,zn,je,on),function(t,e,n,o){const i=To(null);Ro(()=>{const r=t.current;if(!r)return;const s=e??null;i.current!==s&&(i.current=s,r.setLayoutSelection(s),r.hasCustomRestyle?r.restyleScene(s):n.current=!0,o())},[e,o,t,n])}(Fn,De,je,on);const En=be(null);En.current||(En.current=new Ie(t=>{const e=Fn.current;e&&e.ingest(t)&&(je.current=!0,on())},{chunkThreshold:r,chunkSize:s})),ve(()=>{En.current?.updateChunkOptions({chunkThreshold:r,chunkSize:s})},[r,s]);const Nn=ke(t=>{En.current?.push(t)},[]),Bn=ke(t=>{En.current?.pushMany(t)},[]),Wn=ke(()=>{En.current?.clear(),Fn.current?.clear(),je.current=!0,on()},[on]);Se(e,()=>({push:Nn,pushMany:Bn,remove:t=>{En.current?.flush();const e=Fn.current?.remove(t)??[];return e.length>0&&(xn.current&&e.some(t=>t===xn.current?.data)&&(xn.current=null,Sn(null)),je.current=!0,on()),e},update:(t,e)=>{En.current?.flush();const n=Fn.current?.update(t,e)??[];return n.length>0&&(je.current=!0,on()),n},clear:Wn,getData:()=>(En.current?.flush(),Fn.current?.getData()??[]),getScales:()=>Fn.current?.scales??null,getExtents:()=>Fn.current?.getExtents()??null,getCustomLayout:()=>Fn.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>Fn.current?.lastCustomLayoutFailure??null}),[Nn,Bn,Wn,on]),ve(()=>{if(i){if(y&&un.length>0&&"object"==typeof un[0]&&null!==un[0]){const t="string"==typeof y?y:"coordinates";if(Array.isArray(un[0][t])){const e=[];for(const n of un){const o=n[t];if(Array.isArray(o)){const t=n.label||n.id||n.key;if(null!=t)for(const n of o)e.push({...n,_lineGroup:t});else for(const t of o)e.push(t)}}return void En.current?.setBoundedData(e)}}En.current?.setBoundedData(un)}},[i,un,y]);const{canvasRef:jn,interactionCanvasRef:Yn}=function(t,e){return function(t){const{cancelRender:e,dirtyRef:n,frameRuntime:o,manageFrameRuntime:i,scheduleRender:r}=t,s=ac(null),a=ac(null),l=ac(!1);return function(t){const{hydrated:e,wasHydratingFromSSR:n,storeRef:o,dirtyRef:i,renderFnRef:r,cancelRender:s,cleanup:a}=t;za(()=>{const t=o.current;e&&n&&t?.cancelIntroAnimation?.(),!n&&t?.sceneNodes&&t.sceneNodes.length>0&&t?.markStylePaintPending?t.markStylePaintPending():i.current=!0,s?.(),r.current()},[e,n]);const l=Ia(a);l.current=a,Ra(()=>()=>l.current?.(),[])}({hydrated:t.hydrated,wasHydratingFromSSR:t.wasHydratingFromSSR,storeRef:t.storeRef,dirtyRef:t.dirtyRef,renderFnRef:t.renderFnRef,cancelRender:t.cancelRender,cleanup:t.cleanup}),sc(()=>{if(!1!==i)return o.subscribe(()=>{o.isActive?(n.current=!0,r()):e()})},[e,n,o,i,r]),sc(()=>{!l.current&&(l.current=!0,t.skipInitialCanvasPaintInvalidation)||(t.canvasPaintInvalidator?t.canvasPaintInvalidator():t.dirtyRef.current=!0,t.scheduleRender())},t.canvasPaintDependencies),{canvasRef:s,interactionCanvasRef:a}}({...e,renderFnRef:t.renderFnRef,scheduleRender:t.scheduleRender,cancelRender:t.cancelRender,frameRuntime:t.frameRuntime})}(He,{storeRef:Fn,dirtyRef:je,hydrated:Ge,wasHydratingFromSSR:qe,cleanup:()=>En.current?.clear(),canvasPaintDependencies:[n,ln,cn,lt,E,Xt,B,N,Gt,on]}),{hoverHandlerRef:Xn,hoverLeaveRef:Hn,onPointerMove:Gn,onPointerLeave:qn}=He;Xn.current=t=>{if(!dn)return;const e=jn.current;if(!e)return;const o=e.getBoundingClientRect(),i=t.clientX-o.left-an.left,r=t.clientY-o.top-an.top;if(0>i||i>ln||0>r||r>cn)return void(xn.current&&(xn.current=null,vn.current=null,Sn(null),Ee?.(null),on()));const s=Fn.current;if(!s||0===s.scene.length)return;const l=Al(_t,t.pointerType),c=ki(s.scene,i,r,l,s.quadtree,s.maxPointRadius),u="multi"===Pt,d=()=>{xn.current&&(xn.current=null,vn.current=null,Sn(null),Ee&&Ee(null),on())};if(!c&&!u)return void d();const h=u||!c?i:c.x,f=u||!c?r:c.y,p=c?.datum?sn(c.datum,s.resolvedRibbons):{},g=s.scales?.x?.invert,y="function"==typeof g?g(h):void 0;let m=_l(p,h,f,null!=y?{xValue:y,xPx:h}:void 0);if(u&&s.scene.length>0&&s.scales){const t=function(t,e,n=30){const o=[];for(const i of t)if("line"===i.type){const t=i;if(2>t.path.length)continue;const r=Si(wi(t.path,t.curve),e,n);if(null===r)continue;const s=$i(t.path,e);o.push({node:i,datum:Array.isArray(t.datum)&&t.datum[s]?t.datum[s]:t.datum,x:t.path[s][0],y:r,group:t.group,color:t.style.stroke})}else if("area"===i.type){const t=i;if(!1===t.interactive)continue;if(2>t.topPath.length)continue;const r=wi(t.topPath,t.curve),s=wi(t.bottomPath,t.curve),a=Si(r,e,n);if(null===a)continue;const l=Si(s,e,n),c=$i(t.topPath,e);o.push({node:i,datum:Array.isArray(t.datum)&&t.datum[c]?t.datum[c]:t.datum,x:t.topPath[c][0],y:a,y0:l??void 0,group:t.group,color:"string"==typeof t.style.stroke?t.style.stroke:"string"==typeof t.style.fill?t.style.fill:void 0})}return o}(s.scene,h,Math.max(l,ln));if(t.length>0){const e=s.scales.y.invert,o=An.current,i=g?g(h):h;if(c)m.xValue=i,m.xPx=h;else{const t={xValue:i};"string"==typeof a&&(t[a]=i),m=_l(t,h,f,{xValue:i,xPx:h})}m.allSeries=t.map(t=>{const i=e?e(t.y):t.y,r=null!=t.y0?e?e(t.y0):t.y0:void 0;return{group:t.group||"",value:"stackedarea"===n&&null!=r?i-r:i,valuePx:t.y,color:t.color||o,datum:sn(t.datum,s.resolvedRibbons)}})}}c||m.allSeries?.length?(xn.current=m,vn.current=c?.node??null,Sn(m),Ee?.(m),on()):d()},Hn.current=()=>{xn.current&&(xn.current=null,vn.current=null,Sn(null),Ee?.(null),on())};const Vn=be(()=>{});Vn.current=t=>{if(c(t.target))return;if(!Ne)return;const e=jn.current;if(!e)return;const n=e.getBoundingClientRect(),o=t.clientX-n.left-an.left,i=t.clientY-n.top-an.top;if(0>o||o>ln||0>i||i>cn)return void Ne(null);const r=Fn.current;if(!r||0===r.scene.length)return void Ne(null);const s=Al(_t,wn.current),a=ki(r.scene,o,i,s,r.quadtree,r.maxPointRadius);if(!a)return void Ne(null);const l=a.datum||{},u=r.scales?.x?.invert,d="function"==typeof u?u(a.x):void 0;var h;Ne(_l(l,a.x,a.y,null!=d?{xValue:d,xPx:a.x}:void 0),{type:"activate",inputType:(h=wn.current,"touch"===h?"touch":"pointer")})};const Un=ke(t=>Vn.current(t),[]),{kbFocusIndexRef:Kn,focusedNavPointRef:Zn,onKeyDown:Qn}=(Jn={storeRef:Fn,hoverRef:xn,hoveredNodeRef:vn,setHoverPoint:Sn,customHoverBehavior:Ee,customClickBehavior:Ne,scheduleRender:on},function({storeRef:t,hoverRef:e,hoveredNodeRef:n,setHoverPoint:o,customHoverBehavior:i,customClickBehavior:r,scheduleRender:s,extractPoints:a,toHover:l}){const c=au(-1),u=au(null),d=au(null),h=su(h=>{if(function(t){const e=t.target;return e instanceof Element&&e!==t.currentTarget&&null!=e.closest("button, a[href], input, select, textarea, summary, [contenteditable='true'], [role='button'], [role='link'], [role='checkbox'], [role='radio'], [role='switch']")}(h))return;const f=t.current;if(!f)return;const p=()=>{c.current=-1,u.current=null,e.current=null,n&&(n.current=null),o(null),i?.(null),s()};if(0===f.scene.length)return void(0>c.current||p());let g;if(d.current?.version===f.version)g=d.current.graph;else{const t=a(f.scene);if(0===t.length)return void(0>c.current||p());g=function(t){const e=new Map;for(const n of t){const t=n.group??"_default";let o=e.get(t);o||(o=[],e.set(t,o)),o.push(n)}for(const t of e.values()){t.sort((t,e)=>t.x-e.x||t.y-e.y);for(let e=0;t.length>e;e++)t[e]._groupIndex=e}const n=Array.from(e.keys()).sort((t,n)=>{const o=e.get(t),i=e.get(n);return(o.length>0?o[0].y:0)-(i.length>0?i[0].y:0)}),o=Array.from(e.values()).flat();o.sort((t,e)=>t.x-e.x||t.y-e.y);const i=new Map;for(let t=0;o.length>t;t++){o[t]._flatIndex=t;const e=o[t].datum?.id;null!=e&&i.set(e+"",t)}return{flat:o,groups:n,byGroup:e,idToIdx:i}}(t),d.current={version:f.version,graph:g}}let y=c.current;if(g.flat.length>y||(p(),y=-1),("Enter"===h.key||" "===h.key)&&y>=0)return h.preventDefault(),void r?.(l(g.flat[y],f),{type:"activate",inputType:"keyboard"});if(0>y){if("Escape"===h.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(h.key))return;h.preventDefault(),c.current=0;const t=g.flat[0];u.current=t;const n=l(t,f);return e.current=n,o(n),i?.(n,{type:"focus",inputType:"keyboard"}),void s()}const m=function(t,e,n){const{group:o,indexInGroup:i}=e,r=n.byGroup.get(o);switch(t){case"ArrowRight":return r.length-1>i?r[i+1]._flatIndex:e.flatIndex;case"ArrowLeft":return i>0?r[i-1]._flatIndex:e.flatIndex;case"ArrowDown":{const t=n.groups.indexOf(o);return n.groups.length-1>t?lu(n,n.groups[t+1],r[i]):e.flatIndex}case"ArrowUp":{const t=n.groups.indexOf(o);return t>0?lu(n,n.groups[t-1],r[i]):e.flatIndex}case"PageDown":return Math.min(e.flatIndex+Math.max(1,Math.floor(.1*n.flat.length)),n.flat.length-1);case"PageUp":return Math.max(e.flatIndex-Math.max(1,Math.floor(.1*n.flat.length)),0);case"Home":return 0;case"End":return n.flat.length-1;case"Escape":return-1;default:return null}}(h.key,function(t,e){if(0===t.flat.length)return{flatIndex:-1,group:"_default",indexInGroup:-1};const n=Math.max(0,Math.min(e,t.flat.length-1)),o=t.flat[n];return{flatIndex:n,group:o.group??"_default",indexInGroup:o._groupIndex??0}}(g,y),g);if(null===m)return;if(h.preventDefault(),0>m)return void p();c.current=m;const b=g.flat[m];u.current=b;const x=l(b,f);e.current=x,o(x),i?.(x,{type:"focus",inputType:"keyboard"}),s()},[r,i,a,e,n,s,o,t,l]);return{kbFocusIndexRef:c,focusedNavPointRef:u,onKeyDown:h}}({...Jn,extractPoints:cu,toHover:(t,e)=>function(t){return{data:t.datum||{},x:t.x,y:t.y,__semioticHoverData:!0}}({...t,datum:sn(t.datum,e.resolvedRibbons)})}));var Jn;const to=ke(t=>{wn.current=t.pointerType,Kn.current=-1,Zn.current=null,Gn(t)},[Zn,Kn,Gn]),eo=ke(t=>{wn.current="mouse",Kn.current=-1,Zn.current=null,Gn({clientX:t.clientX,clientY:t.clientY,pointerType:"mouse"})},[Zn,Kn,Gn]),no=ke(t=>{wn.current=t.pointerType},[]);nn.current=()=>{if(en.current=null,!rn.isActive)return;const t=jn.current,e=Yn.current;if(!t||!e)return;const o=Fn.current;if(!o)return;const i=rn.now(),r=o.advanceTransition(Ve.current?i+1e6:i),s=!Ve.current&&r,c=Ye.current.w!==ln||Ye.current.h!==cn,u=je.current||r||c,d=o.consumeStylePaintPending();let h=!1;const f=o.getLastUpdateResult(),p=Pn.current.beforeCompute(f,s);!u||s&&!c||(o.computeScene({width:ln,height:cn}),Ye.current={w:ln,h:cn},h=!0,Dn()),Pn.current.afterCompute(p,h,c);const g=function(t,e,n,o){const i=o.current,r=!0===t.lastCustomLayoutFailure?.preservedLastGoodScene,s=!r&&t.hasActivePulsesAt(e),a=!(n||r||!s&&!i)&&t.refreshPulse(e);return o.current=s,{changed:a,pending:s}}(o,i,h,Xe),y=function(){if("undefined"==typeof window)return 1;const t=window.devicePixelRatio||1,e=function(){if("undefined"==typeof window)return!1;const t="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,e=768>Math.min(window.innerWidth||1/0,window.innerHeight||1/0);return t||e}()?2:3;return Math.max(1,Math.min(t,e))}(),m=Mn.current.resolve(t);An.current=m.primary;const b=Ei(ne,o.lastIngestTime>0?i-o.lastIngestTime:0),x=ne&&b.isStale;if(u||d||g.changed){const e=dc(t,Ke,an,y);if(e){if(e.clearRect(-an.left,-an.top,Ke[0],Ke[1]),ne&&1>b.alpha&&(e.globalAlpha=b.alpha),function(t,e){const{background:n,hasBackgroundGraphics:o=!1,themeBackground:i="",x:r=0,y:s=0,width:a,height:l}=e,c=Ya({background:n,hasBackgroundGraphics:o,themeBackground:i});if(!c)return!1;const u=Ko(t,c);u&&(t.fillStyle=u,t.fillRect(r,s,a,l))}(e,{background:E,hasBackgroundGraphics:!!Xt,themeBackground:m.background,x:-an.left,y:-an.top,width:Ke[0],height:Ke[1]}),e.save(),"function"==typeof e.rect&&(e.beginPath(),e.rect(0,0,ln,cn),e.clip()),Gt&&o.scales)for(const t of Gt)e.save(),t(e,o.scene,o.scales,{width:ln,height:cn}),e.restore();const t=Oe?Hc.custom:Hc[n];!function(t){const{context:e,nodes:n,renderMode:o,pixelRatio:i,paintBuiltIn:r}=t;if(!o||"sketchy"===o)return void r(n);let s=[];const a=()=>{s.length&&(r(s),s=[])};for(const t of n){const n=qc(o,t);if(!n){s.push(t);continue}let l;a(),e.save();try{l=n.drawCanvas({context:e,node:t,style:t.style??{},pixelRatio:i})}finally{e.restore()}l||(Vc(n.id,t.type??"unknown"),r([t]))}a()}({context:e,nodes:o.scene,renderMode:N,pixelRatio:y,paintBuiltIn:n=>{if(t&&o.scales)for(const i of t)i(e,n,o.scales,{width:ln,height:cn})}}),e.restore(),ne&&1>b.alpha&&(e.globalAlpha=1)}}const v=!!(dn&&xn.current&&o.scales),w=!!(vn.current&&Array.isArray(bt)&&bt.some(t=>t&&"object"==typeof t&&"highlight"===t.type)),k=v||w;if(k||_n.current){const t=dc(e,Ke,an,y);if(t&&(t.clearRect(-an.left,-an.top,Ke[0],Ke[1]),v&&xn.current&&function(t,e,n,o,i,r,s){if(!1===i.crosshair)return;const a=e.allSeries,l=a&&a.length>0,c=e.xPx??e.x;t.save();const u="object"==typeof i.crosshair?i.crosshair:{};if(t.strokeStyle=u.stroke||s.crosshair,t.lineWidth=u.strokeWidth||1,t.setLineDash(u.strokeDasharray?u.strokeDasharray.split(/[\s,]+/).map(Number):[4,4]),t.beginPath(),t.moveTo(l?c:e.x,0),t.lineTo(l?c:e.x,o),t.stroke(),l||(t.beginPath(),t.moveTo(0,e.y),t.lineTo(n,e.y),t.stroke()),t.restore(),l){t.lineWidth=2,t.strokeStyle=s.pointRing;for(const e of a)null!=e.valuePx&&(t.beginPath(),t.arc(c,e.valuePx,4,0,2*Math.PI),t.fillStyle=e.color||s.primary,t.fill(),t.stroke())}else{const n=i.pointColor||function(t){if(!t)return null;if("heatcell"===t.type)return t.fill||null;if("candlestick"===t.type)return t.isUp?t.upColor:t.downColor;const{style:e}=t;if(!e)return null;const n="string"==typeof e.fill?e.fill:null;return"line"===t.type||"area"===t.type?e.stroke||n||null:n||e.stroke||null}(r)||s.primary;t.beginPath(),t.arc(e.x,e.y,4,0,2*Math.PI),t.fillStyle=n,t.fill(),t.strokeStyle=s.pointRing,t.lineWidth=2,t.stroke()}}(t,xn.current,ln,cn,"object"==typeof dn?dn:{},vn.current,m),w&&vn.current&&Array.isArray(bt))){const e=bt.find(t=>t&&"object"==typeof t&&"highlight"===t.type);e&&function(t,e,n,o,i){if(!n)return;const r="group"in n?n.group:void 0;if(void 0!==r)for(const n of e){if("line"!==n.type)continue;if(n.group!==r)continue;if(2>n.path.length)continue;const e="function"==typeof o.style?n.datum?o.style(n.datum):{}:o.style||{};t.save(),t.beginPath(),t.moveTo(n.path[0][0],n.path[0][1]);for(let e=1;n.path.length>e;e++)t.lineTo(n.path[e][0],n.path[e][1]);t.strokeStyle=e.stroke||n.style.stroke||i.primary,t.lineWidth=e.strokeWidth||(n.style.strokeWidth||2)+2,t.globalAlpha=e.opacity??1,t.stroke(),t.restore()}}(t,o.scene,vn.current,e,m)}_n.current=k}u&&t&&t.setAttribute("aria-label",il(o.scene,n+" chart"));const S=je.current;if(je.current=S&&s&&!h,S&&o.scales){const t=t=>"object"==typeof t&&null!==t&&"function"==typeof t.valueOf?t.valueOf():t;if((!gn||t(gn.x.domain()[0])!==t(o.scales.x.domain()[0])||t(gn.x.domain()[1])!==t(o.scales.x.domain()[1])||t(gn.y.domain()[0])!==t(o.scales.y.domain()[0])||t(gn.y.domain()[1])!==t(o.scales.y.domain()[1])||gn.x.range()[0]!==o.scales.x.range()[0]||gn.x.range()[1]!==o.scales.x.range()[1]||gn.y.range()[0]!==o.scales.y.range()[0]||gn.y.range()[1]!==o.scales.y.range()[1])&&yn(o.scales),ge){const t=o.getData(),e="function"==typeof a?a:t=>t[a||"x"],n="function"==typeof l?l:t=>t[l||"y"];Tn(t.map(t=>e(t)).filter(t=>"number"==typeof t&&isFinite(t))),$n(t.map(t=>n(t)).filter(t=>"number"==typeof t&&isFinite(t)))}}!((Ct&&Ct.length>0||Oe)&&(h||s))||!h&&33>i-pn.current||(fn(t=>t+1),pn.current=i),ne?.showBadge&&Ln(!!x),(s||null!=o.activeTransition||g.pending)&&on()},function(t,e,n,o,i,r){const s=zi("fresh");Oi(()=>{if(!t)return;const a=setInterval(()=>{const a=e.current;if(!a||0===a.lastIngestTime)return;const l="undefined"!=typeof performance?performance.now():Date.now(),c=Ei(t,l-a.lastIngestTime);c.band===s.current&&c.isStale===i||(s.current=c.band,c.isStale!==i&&r(c.isStale),n.current=!0,o())},1e3);return()=>clearInterval(a)},[t,i,o,e,r,n])}(ne,Fn,je,on,Cn,Ln);const oo=we(()=>{if(ft||yt)return;const t=Fn.current;return t?.xIsDate&&gn?mc(gn.x.domain()):void 0},[ft,yt,gn]),io=ft||yt||oo,ro=dn&&kn?xt?xt(kn):uu(nu,{hover:kn}):null,so=ro?uu(Bl,{x:kn.x,y:kn.y,containerWidth:ln,containerHeight:cn,margin:an,className:"stream-frame-tooltip",children:ro}):null,ao=Zn.current,lo=uu(kl,{active:Kn.current>=0,hoverPoint:kn,margin:an,size:Ke,shape:ao?.shape,width:ao?.w,height:ao?.h}),co=pc(a,P,"__semiotic_resolvedX","__semiotic_resolvedTime"),uo=pc(l,S,"__semiotic_resolvedY","__semiotic_resolvedValue"),ho=co.key,fo=uo.key,po=function(t,e,n){return o=>{if(!o||!n||!t.fn&&!e.fn)return o;let i=!1;const r=o.map(n=>{const o=t.fn&&t.key&&!(t.key in n),r=e.fn&&e.key&&!(e.key in n);if(!o&&!r)return n;i=!0;const s={...n};return o&&(s[t.key]=t.fn(n)),r&&(s[e.key]=e.fn(n)),s});return i?r:o}}(co,uo,Ct&&Ct.length>0||!1);if(La||!Ge&&qe){const t=Fn.current;t&&i&&(t.ingest({inserts:un,bounded:!0}),t.computeScene({width:ln,height:cn}));const e=t?.scene??[],n=t?.scales??null,o=uc(Ht,Ke,an,n),r=uc(Xt,Ke,an,n),s=io||(()=>{if(t?.xIsDate&&n)return mc(n.x.domain())})();return du("div",{ref:Ue,className:"stream-xy-frame"+(D?" "+D:""),role:"img","aria-label":Ce||("string"==typeof Vt?Vt:"XY chart"),style:{position:"relative",width:O?"100%":Ke[0],height:z?"100%":Ke[1]},children:[uu(bl,{summary:Le}),du("svg",{xmlns:"http://www.w3.org/2000/svg",width:Ke[0],height:Ke[1],style:{position:"absolute",left:0,top:0},children:[uu("g",{transform:`translate(${an.left},${an.top})`,children:r}),du("g",{transform:`translate(${an.left},${an.top})`,children:[E&&uu("rect",{x:0,y:0,width:ln,height:cn,fill:E}),qt&&n&&qt.map((t,o)=>uu(me.Fragment,{children:t(e,n,{width:ln,height:cn})},"svgpre-"+o)),e.map((t,e)=>Uc({node:t,index:e,renderMode:N,fallback:()=>Ca(t,e,We)})).filter(Boolean)]})]}),uu(qs,{width:ln,height:cn,totalWidth:Ke[0],totalHeight:Ke[1],margin:an,scales:n,showAxes:lt,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:s,yFormat:pt||mt,axisExtent:gt,showGrid:It,title:Vt,legend:$t,legendHoverBehavior:Ot,legendClickBehavior:zt,legendHighlightedCategory:Ft,legendIsolatedCategories:Dt,legendPosition:Et,legendLayout:Wt,foregroundGraphics:Lo(o,pe(Fn.current?.customLayoutOverlays,De??null)),marginalGraphics:ge,xValues:[],yValues:[],annotations:Ct,onAnnotationActivate:Lt,onObservation:St??kt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Rt,svgAnnotationRules:Tt,annotationFrame:0,xAccessor:ho,yAccessor:fo,annotationData:po(Fn.current?.getData()),pointNodes:bc(Fn.current?.scene),curve:"string"==typeof m?m:void 0,linkedCrosshairName:Re,linkedCrosshairSourceId:$e})]})}return du("div",{ref:Ue,className:"stream-xy-frame"+(D?" "+D:""),role:"group","aria-label":Ce||("string"==typeof Vt?Vt:"XY chart"),tabIndex:0,style:{position:"relative",width:O?"100%":Ke[0],height:z?"100%":Ke[1],overflow:"visible",touchAction:pu(Kt)},onKeyDown:Qn,children:["production"!==process.env.NODE_ENV&&Fn.current&&uu(Po,{store:Fn.current,diagnostics:Pn.current}),Pe&&uu(xl,{tableId:tn}),Pe&&uu(ml,{scene:Fn.current?.scene??[],chartType:n+" chart",tableId:tn,chartTitle:"string"==typeof Vt?Vt:void 0}),uu(bl,{summary:Le}),uu(Qa,{hoverPoint:kn}),du("div",{role:"img","aria-label":Ce||("string"==typeof Vt?Vt:"XY chart"),style:{position:"relative",width:"100%",height:"100%"},onPointerMove:dn?to:void 0,onMouseMove:dn?eo:void 0,onPointerLeave:dn?qn:void 0,onMouseLeave:dn?qn:void 0,onPointerDown:dn||Be?no:void 0,onClick:Be?Un:void 0,children:[uu(cc,{size:Ke,margin:an,children:bn}),uu(Xs,{width:ln,height:cn,totalWidth:Ke[0],totalHeight:Ke[1],margin:an,scales:gn,showAxes:lt,axes:ct,showGrid:It,xFormat:io,yFormat:pt||mt,axisExtent:gt}),uu("canvas",{ref:jn,"aria-label":il(Fn.current?.scene??[],n+" chart"),style:{position:"absolute",left:0,top:0}}),uu("canvas",{ref:Yn,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),uu(qs,{width:ln,height:cn,totalWidth:Ke[0],totalHeight:Ke[1],margin:an,scales:gn,showAxes:lt,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:io,yFormat:pt||mt,axisExtent:gt,showGrid:It,title:Vt,legend:$t,legendHoverBehavior:Ot,legendClickBehavior:zt,legendHighlightedCategory:Ft,legendIsolatedCategories:Dt,legendPosition:Et,legendLayout:Wt,foregroundGraphics:Lo(mn,pe(Fn.current?.customLayoutOverlays,De??null)),marginalGraphics:ge,xValues:Rn,yValues:In,annotations:Ct,onAnnotationActivate:Lt,onObservation:St??kt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Rt,svgAnnotationRules:Tt,annotationFrame:hn,xAccessor:ho,yAccessor:fo,annotationData:po(Fn.current?.getData()),pointNodes:bc(Fn.current?.scene),curve:"string"==typeof m?m:void 0,underlayRendered:!0,canvasObscuresUnderlay:!!Ya({background:E,hasBackgroundGraphics:!!Xt,themeBackground:Ze?.colors.background}),linkedCrosshairName:Re,linkedCrosshairSourceId:$e}),(Kt||Zt)&&uu(Te,{width:ln,height:cn,totalWidth:Ke[0],totalHeight:Ke[1],margin:an,dimension:Kt?.dimension??"xy",scales:gn,onBrush:Zt??(()=>{}),binSize:k,snap:Kt?.snap,binBoundaries:Kt?.binBoundaries??("bar"===n?Fn.current?.getBinBoundaries():void 0),snapDuring:Kt?.snapDuring,streaming:"streaming"===o}),ne?.showBadge&&uu(Bi,{isStale:Cn,position:ne.badgePosition}),lo,so]})]})}));gu.displayName="StreamXYFrame";var yu=gu;import*as mu from"react";import{jsx as bu,jsxs as xu}from"react/jsx-runtime";function vu({componentName:t,message:e,diagnosticHint:n,width:o,height:i}){return bu("div",{role:"alert",style:{width:o,height:Math.max(i,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"},children:xu("div",{style:{textAlign:"center",maxWidth:400},children:[bu("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:t}),bu("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:e}),n&&bu("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:n})]})})}import{jsx as wu}from"react/jsx-runtime";var ku=class extends mu.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,e){this.props.onError?.(t,e)}render(){if(this.state.error){const{fallback:t}=this.props,e=this.state.error;return"function"==typeof t?t(e):void 0!==t?t:wu(vu,{componentName:"ChartErrorBoundary",message:e.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}};import{jsx as Su}from"react/jsx-runtime";function Au({componentName:t,width:e,height:n,children:o}){return Su(ku,{fallback:o=>Su(vu,{componentName:t,message:o.message,width:e,height:n}),children:o})}"undefined"!=typeof process&&process;var Mu={display:"flex",alignItems:"center",justifyContent:"center",color:"var(--semiotic-text-secondary, #666)",fontSize:13,fontFamily:"inherit",border:"1px dashed var(--semiotic-border, #ddd)",borderRadius:4,boxSizing:"border-box"},_u={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};import{useMemo as Pu,useRef as Cu}from"react";import{useMemo as Lu,useCallback as Ru,useState as Tu,useId as Iu,useEffect as $u,useRef as Ou}from"react";import{createContext as zu,useContext as Fu,useMemo as Du}from"react";import{jsx as Eu}from"react/jsx-runtime";var Nu=zu(null);function Bu(){return Fu(Nu)}import{useId as Wu,useMemo as ju,useCallback as Yu}from"react";function Xu(t){const e=[];for(const[n,o]of Object.entries(t.fields))if("point"===o.type)e.push(t=>o.values.has(t[n]));else{const[t,i]=o.range;e.push(e=>{const o=e[n];return o>=t&&i>=o})}return t=>e.every(e=>e(t))}function Hu(t,e){let n=t.get(e);return n||(n={name:e,resolution:"union",clauses:new Map},t.set(e,n)),n}function Gu(t,e){if(t.type!==e.type)return!1;if("interval"===t.type&&"interval"===e.type)return t.range[0]===e.range[0]&&t.range[1]===e.range[1];if("point"===t.type&&"point"===e.type){if(t.values.size!==e.values.size)return!1;for(const n of t.values)if(!e.values.has(n))return!1;return!0}return!1}var[qu,Vu]=s(t=>({selections:new Map,setClause(e,n){t(t=>{const o=t.selections.get(e),i=o?.clauses.get(n.clientId);if(i&&function(t,e){if(t.clientId!==e.clientId||t.type!==e.type)return!1;const n=Object.entries(t.fields);if(n.length!==function(t){let e=0;for(const n in t)e++;return e}(e.fields))return!1;for(const[t,o]of n){const n=e.fields[t];if(!n||!Gu(o,n))return!1}return!0}(i,n))return{};const r=new Map(t.selections),s=Hu(r,e),a=new Map(s.clauses);return a.set(n.clientId,n),r.set(e,{...s,clauses:a}),{selections:r}})},clearClause(e,n){t(t=>{const o=t.selections.get(e);if(!o||!o.clauses.has(n))return{};const i=new Map(t.selections),r=new Map(o.clauses);return r.delete(n),i.set(e,{...o,clauses:r}),{selections:i}})},setResolution(e,n){t(t=>{const o=t.selections.get(e);if(o?.resolution===n)return{};const i=new Map(t.selections),r=Hu(i,e);return i.set(e,{...r,resolution:n}),{selections:i}})},clearSelection(e){t(t=>{const n=t.selections.get(e);if(!n||0===n.clauses.size)return{};const o=new Map(t.selections);return o.set(e,{...n,clauses:new Map}),{selections:o}})}}));function Uu(t){const e=Wu(),n=t.clientId||e,{name:o}=t,i=Vu(t=>t.selections.get(o)),r=Vu(t=>t.setClause),s=Vu(t=>t.clearClause),a=ju(()=>!!i&&i.clauses.size>0,[i]);return{predicate:ju(()=>i&&0!==i.clauses.size?function(t,e){const n=[];for(const[o,i]of t.clauses)"crossfilter"===t.resolution&&o===e||n.push(Xu(i));return 0===n.length?()=>!0:"intersect"===t.resolution?t=>n.every(e=>e(t)):t=>n.some(e=>e(t))}(i,n):()=>!0,[i,n]),isActive:a,selectPoints:Yu(t=>{const e={};let i=!1;for(const[n,o]of Object.entries(t))e[n]={type:"point",values:new Set(o)},i=!0;i&&r(o,{clientId:n,type:"point",fields:e})},[n,o,r]),selectInterval:Yu(t=>{const e={};let i=!1;for(const[n,o]of Object.entries(t))e[n]={type:"interval",range:o},i=!0;i&&r(o,{clientId:n,type:"interval",fields:e})},[n,o,r]),clear:Yu(()=>{s(o,n)},[s,o,n]),clientId:n}}import*as Ku from"react";import{jsx as Zu,jsxs as Qu}from"react/jsx-runtime";function Ju(){return L(t=>t.theme)}function td(t,e,n){const o=t.xValue??e?.[n];if(null==o)return null;const i=Number(o);return Number.isFinite(i)?i:null}function ed(t){let e=t.data||t.datum||t;return Array.isArray(e)&&(e=e[0]),null!=t.xValue&&e&&"object"==typeof e&&!Array.isArray(e)&&null==e.xValue?{...e,xValue:t.xValue}:e||{}}function nd(t){if(!t)return!1;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1}Ku.createContext(void 0);import{useMemo as od,useCallback as id,useState as rd}from"react";import{createContext as sd,useContext as ad,useEffect as ld,useId as cd,useLayoutEffect as ud,useMemo as dd,useRef as hd,useState as fd,useCallback as pd}from"react";import{jsx as gd,jsxs as yd}from"react/jsx-runtime";var md=sd(!1);sd(!1);var bd=sd(null),xd="undefined"==typeof window?ld:ud;function vd(t,e){if(!e)return[];const n=new Set;for(const o of t){const t="function"==typeof e?e(o):o[e];null!=t&&n.add(t+"")}return Array.from(n)}function wd({data:t,colorBy:e,colorScale:n,showLegend:o,legendPosition:i="right",userMargin:r,defaults:s={top:50,bottom:60,left:70,right:40},categories:a,additionalLegend:l,chartWidth:c,legendLayout:u,hasTitle:d=!1,axisChrome:h}){const f=ad(md),p=null!==ad(bd),g=void 0!==o?o:!f&&!!e,y=!!e&&(g||p),m=od(()=>y?void 0!==a?a:vd(t,e):[],[a,e,t,y]);!function(t){const e=ad(bd),n=cd(),o=function(t){const e=new Set,n=[];for(const o of t)e.has(o)||(e.add(o),n.push(o));return n}(t),i=hd([]);(function(t,e){if(t.length!==e.length)return!1;for(let n=0;t.length>n;n++)if(t[n]!==e[n])return!1;return!0})(i.current,o)||(i.current=o);const r=i.current;xd(()=>{if(e)return()=>e.unregisterCategories(n)},[e,n]),xd(()=>{e&&e.registerCategories(n,r)},[e,n,r])}(p&&e?m:[]);const b=od(()=>{if(!g||!e)return;const o=function({data:t,colorBy:e,colorScale:n,getColor:o,strokeColor:i,strokeWidth:r,categories:s}){return{legendGroups:[{styleFn:t=>{const e=t.color||"#333",n={fill:e,stroke:e};return void 0!==i&&(n.stroke=i),void 0!==r&&(n.strokeWidth=r),n},type:"fill",items:(s&&s.length>0?s:Array.from(new Set(t.map(t=>"function"==typeof e?e(t):t[e])))).map((i,r)=>{const s=t.find("function"==typeof e?t=>e(t)===i:t=>t[e]===i),a=s?o(s,e,n):n?n(i):xt[r%xt.length];return{label:i+"",color:a}}),label:""}]}}({data:t,colorBy:e,colorScale:n,getColor:kt,categories:m});return 0!==o.legendGroups.reduce((t,e)=>t+e.items.length,0)?o:void 0},[g,e,t,n,m]),x=od(()=>Hi(b,l),[b,l]),{hasAxis:v,hasAxisLabel:w,rotatedTicks:k}=h??{},S=od(()=>{const t="number"==typeof r?{top:r,bottom:r,left:r,right:r}:r??{},e=e=>{const n=t[e];return"number"==typeof n?n:s[e]},n={top:e("top"),right:e("right"),bottom:e("bottom"),left:e("left")},o=e=>"number"==typeof t[e];if(x){const t=tr(x,u),e=void 0===v?{hasAxis:!0,hasAxisLabel:!0}:{hasAxis:v,hasAxisLabel:w,rotatedTicks:k},r=Ji(x,Math.max(1,(c??600)-n.left-n.right),u)+Ki(x)+Qi("bottom"===i?e:void 0,u)+("top"===i&&d?24:0);"right"===i&&!o("right")&&t>n.right?n.right=t:"left"===i&&!o("left")&&t>n.left?n.left=t:"top"!==i||o("top")?"bottom"!==i||o("bottom")||(n.bottom=Math.max(n.bottom,80,r)):n.top=Math.max(n.top,50,r)}return n},[s,r,x,i,c,u,d,v,w,k]);return{legend:x,margin:S,legendPosition:i}}var kd=[];function Sd(){const t=Ju(),e=t?.colors?.categorical;return e&&e.length>0?e:void 0}function Ad(t,e,n,o,i){if(t)return t;if(n&&"object"==typeof n&&!Array.isArray(n)){const t=St(n,o);if(t)return t}let r;if(Array.isArray(n))r=n;else if(e&&e.length>0)r=e;else if("string"==typeof n){const t=gt[n];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=o?(i.has(o)||i.set(o,i.size),r[i.get(o)%r.length]):r[0]:mt}import{useCallback as Md,useMemo as _d,useState as Pd}from"react";import{useMemo as Cd}from"react";function Ld(t){const{data:e,rawData:n,colorBy:o,colorScheme:i,legendInteraction:r,legendPosition:s,selection:a,linkedHover:c,fallbackFields:u,unwrapData:d=!1,onObservation:h,chartType:f,chartId:p,showLegend:g,legend:y,legendLayout:m,userMargin:b,marginDefaults:x,onClick:w,hoverHighlight:k,mobileInteraction:S,mobileSemantics:A,loading:M,loadingContent:_,emptyContent:P,width:C,height:R,hasTitle:T,axisChrome:I}=t,$=void 0===n,z=_d(()=>j(e),[e]),[F,D]=Pd([]),E=Md(t=>{D(e=>e.length===t.length&&e.every((e,n)=>e===t[n])?e:t)},[]),N="string"==typeof o?o:void 0,B=_d(()=>O(S,{width:C,mobileSemantics:A}),[S,C,A]),{activeSelectionHook:W,hoverSelectionHook:Y,customHoverBehavior:X,customClickBehavior:H,crosshairSourceId:G}=function({selection:t,linkedHover:e,fallbackFields:n=kd,unwrapData:o=!1,onObservation:i,chartType:r,chartId:s,onClick:a,hoverHighlight:c,colorByField:u,mobileInteraction:d}){const h=Iu(),f=Lu(()=>function(t,e){return t?!0===t?{name:"hover",fields:e||[]}:"string"==typeof t?{name:t,fields:e||[]}:{name:t.name||"hover",fields:t.fields||e||[],mode:t.mode,xField:t.xField,seriesField:t.seriesField}:null}(e,n),[e,n]),p=Lu(()=>"series"===f?.mode?[f.seriesField||u||n[0]].filter(t=>!!t):f?.fields||n,[f,u,n]),g=Uu({name:t?.name||"__unused__",fields:p}),y=function(t){const e=t.name||"hover",{fields:n}=t,{predicate:o,isActive:i,selectPoints:r,clear:s}=Uu({name:e,fields:n});return{onHover:Yu(t=>{if(!t)return void s();const e={};for(const o of n){const n=t[o];void 0!==n&&(e[o]=[n])}l(e)&&r(e)},[n,r,s]),predicate:o,isActive:i}}({name:f?.name||"hover",fields:p}),m=v(t=>t.pushObservation),b=Ru(t=>{i?.(t),m?.(t)},[i,m]),x=t?{isActive:g.isActive,predicate:g.predicate}:null,[w,k]=Tu(null),S=Ou(!1),A=u||n[0],M=Lu(()=>{if(!c||null==w||!A)return null;const t=w,e=A;return{isActive:!0,predicate:n=>("string"==typeof n[e]?n[e]:(n[e]??"")+"")===t}},[c,w,A]),_=Ru((t,n)=>{const o=!t&&S.current&&!!d?.enabled&&d.tapToLockTooltip;if(e)if(t){let e=t.data||t.datum||t;if(Array.isArray(e)&&(e=e[0]),"x-position"===f?.mode&&f.xField){const n=td(t,e,f.xField);null!=n&&function(t,e,n){const o=ks.positions.get(t);o?.locked||o&&o.xValue===e&&o.sourceId===n||(ks={positions:new Map(ks.positions).set(t,{xValue:e,sourceId:n})},As())}(f.name||"hover",n,h)}"x-position"!==f?.mode&&y.onHover(e)}else"x-position"!==f?.mode||o||Ms(f.name||"hover",h),"x-position"===f?.mode||o||y.onHover(null);if(c&&A)if(t){let e=t.data||t.datum||t;Array.isArray(e)&&(e=e[0]);const n=e?.[A];k(null!=n?n+"":null)}else o||k(null);(i||m)&&ou({onObservation:b,datum:t?ed(t):null,x:t?.x,y:t?.y,chartType:r||"unknown",chartId:s,context:n})},[e,y,f,h,i,r,s,m,b,c,A,d]),P=Ru((n=!0)=>{S.current=!1,e&&"x-position"!==f?.mode&&y.onHover(null),t&&d?.tapToSelect&&g.clear(),n&&c&&k(null),"x-position"===f?.mode&&(_s(f.name||"hover",h),Ms(f.name||"hover",h))},[e,f,y,t,d,g,c,h]),C=Ru((n,o)=>{const l=!!d?.enabled&&(d.tapToLockTooltip||d.tapToSelect),u=!!d?.enabled&&"backgroundTap"===d.clearSelection;if("x-position"===f?.mode&&f.xField&&n){let t=n.data||n.datum||n;Array.isArray(t)&&(t=t[0]);const e=td(n,t,f.xField);null!=e&&function(t,e,n){const o=ks.positions.get(t);if(o?.locked){const e=new Map(ks.positions);return e.delete(t),ks={positions:e},As(),!1}ks={positions:new Map(ks.positions).set(t,{xValue:e,sourceId:n,locked:!0})},As()}(f.name||"hover",e,h)}if(l)if(n){S.current=!0;const o=ed(n);if(e&&"x-position"!==f?.mode&&y.onHover(o),t&&d?.tapToSelect&&p.length>0){const t={};for(const e of p){const n=o[e];void 0!==n&&(t[e]=[n])}nd(t)&&g.selectPoints(t)}if(c&&A){const t=o?.[A];k(null!=t?t+"":null)}}else u&&P();if(n||u){if(n&&a){let t=n.data||n.datum||n;Array.isArray(t)&&(t=t[0]),a(t,{x:n.x??0,y:n.y??0})}(i||m)&&iu({onObservation:b,datum:n?ed(n):null,x:n?.x,y:n?.y,chartType:r||"unknown",chartId:s,context:o})}},[a,i,m,b,r,s,f,h,d,e,y,t,g,p,c,A,P]);return $u(()=>{if(!d?.enabled||"undefined"==typeof document)return;const t=t=>{"Escape"===t.key&&S.current&&P()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[d?.enabled,P]),$u(()=>()=>{S.current&&P(!1)},[P]),$u(()=>{if("x-position"!==f?.mode)return;const t=f.name||"hover";return()=>{_s(t,h),Ms(t,h)}},[f?.mode,f?.name,h]),{activeSelectionHook:x,hoverSelectionHook:M,customHoverBehavior:_,customClickBehavior:C,crosshairSourceId:h}}({selection:a,linkedHover:c,fallbackFields:u,unwrapData:d,onObservation:h,chartType:f,chartId:p,onClick:w,hoverHighlight:k,colorByField:N,mobileInteraction:B}),q=function(t,e){const n="object"==typeof t&&null!==t?t:void 0;if("x-position"===n?.mode)return{linkedCrosshairName:n.name||"hover",linkedCrosshairSourceId:e}}(c,G),V=function(t,e,n){const o=Bu(),i=Sd();return Lu(()=>{if(!e)return;const r=o??void 0,s=n??(i&&i.length>0?i:void 0)??"category10";if(0!==t.length){if("function"==typeof e){const n=Array.from(new Set(t.map(t=>e(t)+"")));if(r&&nd(r)){const t=At(n.map(t=>({_cat:t})),"_cat",s);return e=>r[e]||t(e)}return At(n.map(t=>({_cat:t})),"_cat",s)}if(r&&nd(r)){const n=At(t,e,s);return t=>r[t]||n(t)}return At(t,e,s)}if(r&&nd(r)){const t=At([{_:"a"}],"_",s);return e=>r[e]||t(e)}},[t,e,n,o,i])}(z,o,i),U=_d(()=>vd(z,o),[z,o]),K=_d(()=>$&&F.length>0?F:U,[$,F,U]),Z=function(t,e,n){const[o,i]=rd(null),[r,s]=rd(new Set),a=od(()=>new Set,[]),l=id(e=>{"highlight"===t&&i(e?e.label:null)},[t]),c=id(e=>{"isolate"===t&&s(t=>{const o=new Set(t);return o.has(e.label)?o.delete(e.label):o.add(e.label),o.size===n.length?new Set:o})},[t,n.length]),u=od(()=>{if(!t||"none"===t||!e)return null;const n="string"==typeof e?e:null;return"highlight"===t&&null!=o?{isActive:!0,predicate:t=>{const i=n?t[n]:"function"==typeof e?e(t):null;return("string"==typeof i?i:(i??"")+"")===o}}:"isolate"===t&&r.size>0?{isActive:!0,predicate:t=>{const o=n?t[n]:"function"==typeof e?e(t):null;return r.has("string"==typeof o?o:(o??"")+"")}}:null},[t,e,o,r]);return{highlightedCategory:"highlight"===t?o:null,isolatedCategories:"isolate"===t?r:a,onLegendHover:l,onLegendClick:c,legendSelectionHook:u}}(r,o,K),Q=_d(()=>Y||(Z.legendSelectionHook?Z.legendSelectionHook:W),[Y,Z.legendSelectionHook,W]),J=function(t){const e=L(t=>t.theme.colors.selectionOpacity);return Cd(()=>{if(void 0!==t||void 0!==e)return{name:t?.name??"",...t,unselectedOpacity:t?.unselectedOpacity??e}},[t,e])}(a),tt=Sd(),et=Bu(),nt=_d(()=>{if(V)return V;if(!o||0===K.length)return;const t=Array.isArray(i)&&i.length>0||"string"==typeof i&&i.length>0?i:tt&&tt.length>0?tt:xt,e="__streamCat",n=At(K.map(t=>({[e]:t})),e,t);return t=>et?.[t]||n(t)||"#999"},[V,o,K,i,tt,et]),{legend:ot,margin:it,legendPosition:rt}=wd({data:z,colorBy:o,colorScale:nt,showLegend:g,legendPosition:s,userMargin:b,defaults:x,categories:K,additionalLegend:y,chartWidth:C,legendLayout:m,hasTitle:T,axisChrome:I}),st=_d(()=>{const t={};return ot&&(t.legend=ot,t.legendPosition=rt,m&&(t.legendLayout=m)),r&&"none"!==r&&(t.legendHoverBehavior=Z.onLegendHover,t.legendClickBehavior=Z.onLegendClick,t.legendHighlightedCategory=Z.highlightedCategory,t.legendIsolatedCategories=Z.isolatedCategories),$&&o&&(t.legendCategoryAccessor=o,t.onCategoriesChange=E),t},[ot,rt,m,r,Z.onLegendHover,Z.onLegendClick,Z.highlightedCategory,Z.isolatedCategories,$,o,E]),at=Array.isArray(n)?j(n):n,lt=function(t,e,n,o){if(!t)return null;if(!1===o)return null;if(null!=o)return Su("div",{style:{width:e,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:o});const i=Math.min(5,Math.floor(n/40)),r=Math.max(8,Math.floor(n/(3*i))),s=Math.max(6,Math.floor(n/(2.5*i))),a=Math.floor((n-(i*(r+s)-s))/2);return Su("div",{style:{width:e,height:n,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:i},(t,n)=>Su("div",{className:"semiotic-loading-bar",style:{..._u,position:"absolute",top:a+n*(r+s),left:Math.floor(.1*e),width:30+(37*n+13)%50+"%",height:r,opacity:.5+n%2*.2}},n))})}(M,C,R,_),ct=lt?null:function(t,e,n,o){return!1===o||null==t||Array.isArray(t)&&t.length>0?null:Array.isArray(t)?Su("div",{style:{...Mu,width:e,height:n},children:o||"No data available"}):null}(at,C,R,P);return{data:z,colorScale:V,allCategories:K,legendState:Z,effectiveSelectionHook:Q,activeSelectionHook:W,customHoverBehavior:X,customClickBehavior:H,mobileInteraction:B,legend:ot,margin:it,legendPosition:rt,earlyReturn:lt||ct||null,legendBehaviorProps:st,crosshairProps:q,resolvedSelection:J}}import{useImperativeHandle as Rd,useRef as Td}from"react";function Id(t){const e=Cu(null);return function(t,e){const{variant:n,frameRef:o,overrides:i}=e,r=Td(i);r.current=i,Rd(t,()=>{const t=function(t,e){if("xy"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>t.current?.remove(e)??[],update:(e,n)=>t.current?.update(e,n)??[],replace:e=>t.current?.replace?.(e),clear:()=>t.current?.clear(),getData:()=>t.current?.getData()??[],getScales:()=>t.current?.getScales()??null,getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}if("network"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>{const n=Array.isArray(e)?e:[e],o=t.current?.getTopology()?.nodes??[],i=[];for(const e of n){const n=o.find(t=>t.id===e);n&&i.push({...n.data??{},id:e}),t.current?.removeNode(e)}return i},update:(e,n)=>(Array.isArray(e)?e:[e]).flatMap(e=>{const o=t.current?.updateNode(e,n);return o?[{...o,id:e}]:[]}),clear:()=>t.current?.clear(),getData:()=>t.current?.getTopology()?.nodes?.map(t=>t.data)??[],getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}if("geo-points"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>t.current?.removePoint(e)??[],update:(e,n)=>{const o=t.current?.removePoint(e)??[];for(const e of o)t.current?.push(n(e));return o},clear:()=>t.current?.clear(),getData:()=>t.current?.getData()??[],getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}const n=e;return{push:t=>n.current?.pushLine(t),pushMany:t=>n.current?.pushManyLines(t),remove:t=>n.current?.removeLine(t)??[],update:(t,e)=>{const o=n.current?.removeLine(t)??[];for(const t of o)n.current?.pushLine(e(t));return o},clear:()=>n.current?.clear(),getData:()=>n.current?.getLines()??[],getCustomLayout:()=>n.current?.getCustomLayout?.()??null,getLayoutFailure:()=>n.current?.getLayoutFailure?.()??null}}(n,o);return new Proxy(t,{get(t,e,n){if("string"==typeof e){const t=r.current?.[e];if("function"==typeof t)return t}return Reflect.get(t,e,n)},has:(t,e)=>!("string"!=typeof e||!r.current||!(e in r.current))||Reflect.has(t,e)})},[])}(t.imperativeRef,{variant:t.imperativeVariant,frameRef:e}),{frameRef:e,resolved:F(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,xLabel:t.xLabel,yLabel:t.yLabel,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,responsiveRules:t.responsiveRules},void 0),normalizedMargin:Pu(()=>E(t.margin),[t.margin])}}function $d(t){const{title:e,description:n,summary:o,accessibleTable:i,className:r,animate:s,axisExtent:a,autoPlaceAnnotations:l}=t,c={};return e&&(c.title=e),n&&(c.description=n),o&&(c.summary=o),void 0!==i&&(c.accessibleTable=i),r&&(c.className=r),null!=s&&(c.animate=s),void 0!==a&&(c.axisExtent=a),void 0!==l&&(c.autoPlaceAnnotations=l),c}function Od(t){const{linkedHover:e,selection:n,onObservation:o,onClick:i,hoverRadius:r,hoverHighlight:s,forceHoverBehavior:a,forceClickBehavior:l,mobileInteraction:c,customHoverBehavior:u,customClickBehavior:d,linkedHoverInClickPredicate:h=!0}=t,f={};o&&(f.annotationObservationCallback=o);const p=c?.enabled?Math.max(r??30,Math.ceil((c.targetSize||44)/2),24):r;return(a||e||o||i||s)&&(f.customHoverBehavior=u),d&&(l||(h?o||i||e:o||i)||c?.enabled&&(c.tapToSelect||c.tapToLockTooltip)&&(e||s||n))&&(f.customClickBehavior=d),null!=p&&(f.hoverRadius=p),f}import{jsx as zd}from"react/jsx-runtime";var Fd=ge(function(t,e){const{data:n,layout:o,layoutConfig:i,onLayoutError:r,xExtent:s,yExtent:a,showAxes:l=!1,margin:c,className:u,annotations:d,onObservation:h,onClick:f,selection:p,linkedHover:g,hoverHighlight:y,chartId:m,loading:b,loadingContent:x,emptyContent:v,colorBy:w,colorScheme:k,legend:S,legendInteraction:A,legendPosition:M,frameProps:_={}}=t,{legend:P,...C}=_,L=ye(()=>Hi(P,S),[P,S]),{frameRef:R,resolved:T,safeData:I,setup:$,earlyReturn:O}=function(t){const e=Id(t),{resolved:n,normalizedMargin:o}=e,i=Ld({data:t.data??[],rawData:t.data,colorBy:t.colorBy,colorScheme:t.colorScheme,legendInteraction:t.legendInteraction,legendPosition:t.legendPosition,selection:t.selection,linkedHover:t.linkedHover,hoverHighlight:t.hoverHighlight,fallbackFields:"string"==typeof t.colorBy?[t.colorBy]:[],unwrapData:t.unwrapData,onObservation:t.onObservation,onClick:t.onClick,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:t.chartTypeLabel,chartId:t.chartId,showLegend:n.showLegend,legend:t.legend,userMargin:o,marginDefaults:n.marginDefaults,loading:t.loading,loadingContent:t.loadingContent,emptyContent:t.emptyContent,width:n.width,height:n.height});return{...e,safeData:i.data,setup:i,earlyReturn:i.earlyReturn}}({imperativeRef:e,imperativeVariant:"xy",chartTypeLabel:"XYCustomChart",unwrapData:!1,data:n,colorBy:w,colorScheme:k,legend:L,legendInteraction:A,legendPosition:M,selection:p,linkedHover:g,hoverHighlight:y,onObservation:h,onClick:f,chartId:m,loading:b,loadingContent:x,emptyContent:v,margin:c,width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,mode:t.mode,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,responsiveRules:t.responsiveRules,xLabel:t.xLabel,yLabel:t.yLabel}),z=$.effectiveSelectionHook,F=ye(()=>z?.isActive?{isActive:!0,predicate:z.predicate}:null,[z?.isActive,z?.predicate]);if(O)return O;const{width:D,height:E,enableHover:N,showGrid:B,title:W,description:j,summary:Y,accessibleTable:X,xLabel:H,yLabel:G}=T,q={chartType:"custom",...null!=n&&{data:I},customLayout:o,layoutConfig:i,onLayoutError:r,...F&&{layoutSelection:F},xExtent:s,yExtent:a,colorAccessor:w,colorScheme:k,size:[D,E],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:$.margin,showAxes:l,xLabel:H,yLabel:G,enableHover:N,showGrid:B,...$.legendBehaviorProps,...$d({title:W,description:j,summary:Y,accessibleTable:X,className:u,animate:t.animate,axisExtent:t.axisExtent,autoPlaceAnnotations:t.autoPlaceAnnotations}),...null!=t.tooltip&&{tooltipContent:t.tooltip},...Od({linkedHover:g,selection:p,onObservation:h,onClick:f,hoverRadius:t.hoverRadius,hoverHighlight:y,mobileInteraction:$.mobileInteraction,customHoverBehavior:$.customHoverBehavior,customClickBehavior:$.customClickBehavior}),...d&&d.length>0&&{annotations:d},...$.crosshairProps,...C};return zd(Au,{componentName:"XYCustomChart",width:D,height:E,children:zd(yu,{ref:R,...q})})});function Dd(t,e,n,o,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*n+i*i*i*o}function Ed(t,e,n,o,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(n-e)+3*i*i*(o-n)}function Nd(t,e,n,o,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===o?(c=t.x+(e.x-t.x)*l,u=t.y+(e.y-t.y)*l,d=e.x-t.x,h=e.y-t.y):(c=Dd(t.x,s,s,e.x,l),u=Dd(t.y,t.y,e.y,e.y,l),d=Ed(t.x,s,s,e.x,l),h=Ed(t.y,t.y,e.y,e.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*l,datumIndex:.5>l?n:n+1})}return r}function Bd(t,e={}){const n=[],o=[],i=[];if(2>t.length)return{topPath:n,bottomPath:o,datumIndices:i};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=Nd(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,l=e.dx/r,c=Math.max(0,e.radius);n.push([e.x+s*c,e.y+l*c]),o.push([e.x-s*c,e.y-l*c]),i.push(e.datumIndex)}}return{topPath:n,bottomPath:o,datumIndices:i}}Fd.displayName="XYCustomChart";import{jsx as Wd,jsxs as jd}from"react/jsx-runtime";function Yd(t,e,n){return"function"==typeof t?t(e,n):e[t]}function Xd(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}function Hd(t,e){if(!t?.length)return;const n=new Map(e.map((t,e)=>[Xd(t),e]));return t.map(t=>{const e={...t},o=o=>{if(!(o in t))return;const i=n.get(Xd(t[o]));void 0!==i&&(e[o]=i)};return o("x"),o("x0"),o("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||o("value"),e})}function Gd(t){const{seriesOrder:e,overallOrder:n,highlightTop:o,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=t;if(null==o&&null==i)return r;const c=new Set(n.slice(0,null==o?n.length:Math.max(0,Math.floor(o)))),u=new Map,d={};for(const t of e)d[t]=i??(c.has(t)?Ad(void 0,a,r,t,u):s??l??"#b8bec8");return d}function qd(t,e={}){const n=e.xAccessor??"x",o=e.yAccessor??"y",i=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=Yd(n,t,e),f=Xd(r);let p=a.get(f);null==p&&(p=s.length,a.set(f,p),s.push(r),l.set(p,[]));const g=Yd(i,t,e)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(Yd(o,t,e));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(p)?.push({datum:t,inputIndex:e,series:g,value:y}))});const f=[],p=new Map,g=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,n)=>{const o=n+1;f.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:o}),p.set(e.series,(p.get(e.series)??0)+o),g.set(e.series,(g.get(e.series)??0)+1)})}const y=c.length+1,m=[...c].sort((t,e)=>{const n=g.get(t)??0,o=g.get(e)??0;return((p.get(t)??0)+(s.length-n)*y)/Math.max(1,s.length)-((p.get(e)??0)+(s.length-o)*y)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),b=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:f.map(t=>{const e=b.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}function Vd({datum:t,x:e,y:n,side:o,color:i,highlighted:r,labelStyle:s}){const a=ce.useContext(he)??de,l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return Wd("text",{className:"semiotic-bump-label",x:e+("end"===o?8:-8),y:n,dy:"0.35em",textAnchor:"end"===o?"start":"end",fill:i,fillOpacity:l?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:t.__bumpSeries})}function Ud(t,e,n){const[o,i]=e,[r,s]=n;return i===o?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-o)/(i-o)))}function Kd(t){const e=t instanceof Date?t.getTime():Number(t);return Number.isFinite(e)?e:void 0}function Zd(t){return{value:t.__bumpValue,x:Kd(t.__bumpXValue),y:t.__bumpValue,category:t.__bumpSeries}}function Qd(t){const e=t.config,n=new Map;for(const e of t.data){const t=n.get(e.__bumpSeries)??[];t.push(e),n.set(e.__bumpSeries,t)}const o=e.seriesOrder.filter(t=>n.has(t)).sort((t,o)=>(n.get(t)?.[0]?.__bumpHighlighted?1:0)-(n.get(o)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(o)),i=[],r=[];for(const s of o){const o=(n.get(s)??[]).sort((t,e)=>t.x-e.x);if(2>o.length)continue;const a=o[0].__bumpHighlighted,l=t.resolveColor(o[0].__bumpSeries,o[0]),c=e.color??(a?l:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??l),u=o.map(n=>({x:t.scales.x(n.x),y:t.scales.y(n.y),radius:e.ribbon?Ud(n.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=Bd(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h=d.datumIndices.map(t=>o[t]),f={fill:c,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(f,zt(o[0].__bumpRaw,e.styleRules,Zd(o[0]))),e.areaStyle&&Object.assign(f,e.areaStyle(o[0].__bumpRaw)??{}),void 0!==e.stroke&&(f.stroke=e.stroke),void 0!==e.strokeWidth&&(f.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(f.opacity=e.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:f,datum:h,accessibleDatum:o.map(t=>t.__bumpRaw),accessibility:{label:s+" ranking trajectory",tableFields:o.map(t=>t.__bumpRaw)},group:s,interactive:!0}),e.showPoints&&o.forEach((t,n)=>{const o={fill:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(o,zt(t.__bumpRaw,e.styleRules,Zd(t))),e.pointStyle&&Object.assign(o,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),i.push({type:"point",x:u[n].x,y:u[n].y,r:o.r??e.pointRadius,style:o,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${s}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${s}:${t.x}`})});const p=!0===e.showLabels?"end":e.showLabels,g=(t,n,o)=>{r.push(Wd(Vd,{datum:t,x:u[n].x,y:u[n].y,side:o,color:"string"==typeof f.fill?f.fill:c,highlighted:a,labelStyle:e.labelStyle},`${s}-${o}`))};"start"!==p&&"both"!==p||g(o[0],0,"start"),"end"!==p&&"both"!==p||g(o.at(-1),o.length-1,"end")}return{nodes:i,overlays:r.length?Wd("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const n=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&n&&!e.predicate(n))return{opacity:.14}}}}function Jd(t,e,n,o,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=T(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof e?e:"__ssrAreaColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?At(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=Rt(i.yAccessor),g=i.styleRules;return(t,n)=>{const o=e&&u?kt(t,e,u):"string"==typeof i.color?i.color:mt,r={fill:o,fillOpacity:f,stroke:d?o:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,zt(t,g,{value:p(t),category:n})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function th(t,e,n,o,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=T(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof e?e:"__ssrBubbleColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?At(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?_t(f):void 0;return t=>({fill:e&&u?kt(t,e,u):"string"==typeof i.color?i.color:mt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?Mt(t,d,h,p):h[0],stroke:i.stroke??i.bubbleStrokeColor??"white",strokeWidth:i.strokeWidth??i.bubbleStrokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}})}function eh(t,e,n,o,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=T(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof e?e:"__ssrScatterColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?At(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?_t(f):void 0,g=Tt(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const n={fill:e&&u?kt(t,e,u):"string"==typeof i.color?i.color:mt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?Mt(t,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(n,zt(t,y,g(t))),void 0!==i.stroke&&(n.stroke=i.stroke),void 0!==i.strokeWidth&&(n.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(n.opacity=i.opacity),n}}se(function(t,e){const n=Sd(),o=Ju(),{data:i,xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l="descending",ribbon:c=!1,curve:u="smooth",ribbonSizeRange:d=[4,28],samplesPerSegment:h=12,lineWidth:f=3,highlightTop:p,neutralColor:g,styleRules:y,labelStyle:m,colorScheme:b,ribbonOpacity:x=.82,lineOpacity:v=.9,showPoints:w=!1,pointRadius:k=3,showLabels:S=!0,showAxes:A=!0,showGrid:M=!0,showLegend:_=!1,enableHover:P=!0,hoverHighlight:C=!0,tooltip:L,frameProps:R={},xFormat:T,yFormat:I,onClick:$}=t,O=le(()=>qd(i,{xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l,highlightTop:p}),[i,r,s,a,l,p]),{axes:z,areaStyle:F,pointStyle:D,...E}=R,N=le(()=>Gd({seriesOrder:O.seriesOrder,overallOrder:O.overallOrder,highlightTop:p,color:t.color,colorScheme:b,neutralColor:g,themeCategorical:n,themeNeutral:o.colors.textSecondary}),[O.seriesOrder,O.overallOrder,p,t.color,b,g,n,o.colors.textSecondary]),B=le(()=>({ribbon:c,curve:u,samplesPerSegment:h,ribbonSizeRange:d,valueExtent:O.valueExtent,seriesOrder:O.seriesOrder,lineWidth:f,ribbonOpacity:x,lineOpacity:v,neutralColor:g,color:t.color,stroke:t.stroke,strokeWidth:t.strokeWidth,opacity:t.opacity,styleRules:y,areaStyle:F,pointStyle:D,labelStyle:m,showPoints:w,pointRadius:k,showLabels:S}),[c,u,h,d,O.valueExtent,O.seriesOrder,f,x,v,g,t.color,t.stroke,t.strokeWidth,t.opacity,y,F,D,m,w,k,S]),W=ae((t,e)=>{if(0===O.xValues.length)return"";const n=O.xValues[Math.max(0,Math.min(O.xValues.length-1,Math.round(Number(t))))];return T?T(n,e):(n instanceof Date?n.toLocaleDateString():n)+""},[O.xValues,T]),j=ae(t=>I?I(t):t.toLocaleString(),[I]),Y=le(()=>"multi"===L?void 0:function(t){if(!0!==t){if("function"==typeof t){const e=t;return t=>{const n=!0===t?.__semioticHoverData||t&&void 0!==t.data&&"number"==typeof t.x&&"number"==typeof t.y&&t&&("node"===t.type||"edge"===t.type||void 0!==t.nodeOrEdge||void 0!==t.allSeries||void 0!==t.stats||void 0!==t.__chartType);let o=Ml(n?t.data??{}:t);if(!o)return null;if(("node"===t?.nodeOrEdge&&"number"==typeof o?.x0&&"number"==typeof o?.x1||"edge"===t?.nodeOrEdge&&"number"==typeof o?.sankeyWidth)&&o.data&&"object"==typeof o.data&&(o=o.data),!o)return null;if(n&&(void 0!==t.allSeries||void 0!==t.xValue)){const e={...o};void 0!==t.allSeries&&void 0===e.allSeries&&(e.allSeries=t.allSeries),void 0!==t.xValue&&void 0===e.xValue&&(e.xValue=t.xValue),o=e}const i=e(o);return null==i?null:$l("div",{className:"semiotic-tooltip",style:zl,children:i})}}return!1!==t&&void 0!==t&&("object"==typeof t&&null!==t&&("fields"in t||"title"in t)?El(t):"multi"===t?("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip="multi" reached normalizeTooltip — prefer charts that set tooltipMode (LineChart, AreaChart, StackedAreaChart, DifferenceChart). Rendering MultiLineTooltip content as a fallback.'),function(t={}){const{fields:e=[],title:n,format:o,style:i={},className:r="",showLabels:s=!0,separator:a=": "}=t;return t=>{if(!t||"object"!=typeof t)return null;const l=[];if(n){const e=Fl(t,n);l.push({value:Dl(e,o)})}if(e&&Array.isArray(e)&&e.length>0)e.forEach(e=>{let n,i,r;"string"==typeof e?(n=e,i=e,r=o):(n=e.label,i=e.accessor||e.key||"",r=e.format||o);const a=Dl(Fl(t,i),r);l.push({label:s?n:void 0,value:a})});else{const e=Il(t,{skipPositional:!1});null!=e.title&&l.push({label:void 0,value:Dl(e.title,o),bold:!0}),e.entries.forEach(t=>{l.push({label:s?t.key:void 0,value:Dl(t.value,o)})})}const c={...zl,...i};return Array.isArray(l)&&0!==l.length?$l("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+r).trim(),style:c,children:l.map((t,e)=>Ol("div",{style:{marginBottom:l.length-1>e?"4px":0,fontWeight:t.bold?"bold":void 0},children:[t.label&&Ol("strong",{children:[t.label,a]}),t.value]},e))}):null}}()):El())}}(L),[L]),X=ae(t=>{const e=t?.data??t;return e?!1===L?null:Y?Y({...t,data:e.__bumpRaw,__semioticHoverData:!0}):jd("div",{className:"semiotic-tooltip",style:zl,children:[Wd("div",{style:{fontWeight:700},children:e.__bumpSeries}),jd("div",{children:[W(e.x)," · Rank ",e.__bumpRank]}),jd("div",{children:["Value: ",j(e.__bumpValue)]})]}):null},[j,W,Y,L]),H=le(()=>{if($)return(t,e)=>{$(t.__bumpRaw??t,e)}},[$]),G=Math.max(1,O.seriesOrder.length),q=O.xValues.map((t,e)=>e),V=Array.from({length:G},(t,e)=>e+1),U=z??[{orient:"left",tickValues:V,tickFormat:t=>t+"",label:t.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:q,tickFormat:W,label:t.xLabel,tickAnchor:"edges"}],K=le(()=>Hd(t.annotations,O.xValues),[t.annotations,O.xValues]);return Wd(Fd,{ref:e,data:O.data,layout:Qd,layoutConfig:B,xExtent:[0,Math.max(1,O.xValues.length-1)],yExtent:[G+.5,.5],showAxes:A,showGrid:M,showLegend:_,enableHover:P,hoverHighlight:C,colorBy:"__bumpSeries",colorScheme:N,tooltip:X,onClick:H,hoverRadius:t.hoverRadius,width:t.width,height:t.height,responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,responsiveRules:t.responsiveRules,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,mode:t.mode,margin:t.margin??{top:20,right:S?110:24,bottom:48,left:48},className:t.className,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,selection:t.selection,linkedHover:t.linkedHover,legend:t.legend,legendInteraction:t.legendInteraction,legendPosition:t.legendPosition,onObservation:t.onObservation,chartId:t.chartId,loading:t.loading,loadingContent:t.loadingContent,emptyContent:t.emptyContent,animate:t.animate,autoPlaceAnnotations:t.autoPlaceAnnotations,annotations:K,xLabel:t.xLabel,yLabel:t.yLabel??"Rank",frameProps:{axes:U,axisExtent:"exact",...E}})}).displayName="BumpChart";var nh={frameType:"xy",buildProps:(t,e,n,o,i)=>({chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:n,...o,pointStyle:o.pointStyle||th(t,e,n,o,i),showLegend:o.showLegend??!!e})},oh={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,n,o,i)=>{const r=qd(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=T(o.theme),l=Gd({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:n,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:o.areaStyle,pointStyle:o.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0},u=o.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const n=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(n,e):(n instanceof Date?n.toLocaleDateString():n)+""},h=r.xValues.map((t,e)=>e),f=Array.from({length:s},(t,e)=>e+1),p=o.axes??[{orient:"left",tickValues:f,tickFormat:t=>t+"",label:o.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:o.xLabel,tickAnchor:"edges"}];return{...o,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:Qd,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:p,axisExtent:"exact",showAxes:o.showAxes??!0,showLegend:o.showLegend??!1,annotations:Hd(o.annotations,r.xValues)}}};function ih(t,e,n,o,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=T(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof e?e:"__ssrPointColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?At(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const n=e&&u?kt(t,e,u):"string"==typeof i.color?i.color:mt;return{r:d,fill:n,stroke:"none"}}}var rh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=T(o.theme).colors.categorical,c=function(t,e,n,o,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=T(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof e?e:"__ssrLineColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?At(c,l,a):void 0,d=Tt(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:n,colorScale:o,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:l,ruleContext:c}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let f;return r?f=r(t,u):n?o&&(f=kt(t,n,o)):f=i||mt,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),l?.length&&Object.assign(d,zt(t,l,c?c(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof i.color?i.color:void 0,fillArea:i.fillArea,areaOpacity:"number"==typeof i.areaOpacity?i.areaOpacity:.3,styleRules:i.styleRules,ruleContext:d});return Lt(h,{stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0})}(t,r,n,o,i),u=re({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:n,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:o.annotations,themeCategorical:l,baseLineStyle:c}),d=o.pointStyle||ih(u.data,u.colorAccessor,n,o,i);let h=o.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const f=(!i.directLabel||void 0!==o.showLegend)&&(o.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:n,lineStyle:u.lineStyle||c,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...o,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!o.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},sh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=Array.isArray(t)?j(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=i.valueExtent||o.yExtent,u="down"===i.direction?function({data:t,valueAccessor:e,timeAccessor:n,binSize:o,valueExtent:i,extentPadding:r}){if(i)return[i[1],i[0]];if(!t||0===t.length)return;const s=new Map;for(const i of t){const t=Ht(i,n,"time"),r=Ht(i,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/o)*o;s.set(a,(s.get(a)??0)+r)}let a=0;for(const t of s.values())a=Math.max(a,t);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:c,extentPadding:i.extentPadding}):c,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.gap&&{gap:i.gap}};return{chartType:"bar",data:r,...o,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||o.xExtent,yExtent:u,extentPadding:i.extentPadding??o.extentPadding,binSize:i.binSize,categoryAccessor:l,barColors:i.colors||o.barColors,colorScheme:i.colors||o.colorScheme,barStyle:o.barStyle||d,showLegend:o.showLegend??!!l}}},ah={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=e||i.areaBy,s=function({data:t,safeData:e,areaBy:n,lineDataAccessor:o}){if(null==t)return[];const i=void 0!==e[0]?.[o];if(!i&&!n)return e;let r;if(i)r=e;else{const t=e.reduce((t,e)=>{const i="function"==typeof n?n(e):e[n],r=i+"";if(!t[r]){const e={[o]:[]};"string"==typeof n&&(e[n]=i),t[r]=e}return t[r][o].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[o])?t[o]:[];return"string"==typeof n?e.map(e=>({...e,[n]:e[n]??t[n]})):e})}({data:t,safeData:Array.isArray(t)?j(t):[],areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),a=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:n})=>({offset:t/100,color:e,...null!=n&&{opacity:n}}))}:Array.isArray(t.stops)?t:void 0}(i.semanticGradient),l=a?.stops.length?{stops:a.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:Nt(o.gradientFill),c=!1!==i.semanticLine&&a?.stops.length?a.stops.flatMap(({offset:t,color:e})=>e?[{offset:t,color:e}]:[]):void 0,u=o.pointStyle||ih(s,r,n,o,i);return{chartType:"area",data:s,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:n,...o,...void 0!==l&&{gradientFill:l},...c&&{semanticLineStops:c},lineStyle:o.lineStyle||Jd(s,r,n,o,i),...u&&{pointStyle:u}}}},lh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>jt(Wt(r,"x",t)),c=t=>jt(Wt(s,"a",t)),u=t=>jt(Wt(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",f=i.areaOpacity??.6,p=i.lineWidth??1.5,g=!1!==i.showLines,y=!1!==o.showLegend,m=i.seriesALabel||"A",b=i.seriesBLabel||"B",x=o.legendPosition||"right",v=function(t,e,n,o){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,n)=>e(t)-e(n)),r=[];let s=0,a=null,l=null,c=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),f=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;i.length>t;t++){const r=i[t],p=e(r),g=n(r),y=o(r);if(!Number.isFinite(p)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const n=g-l.a-(y-l.b);if(0!==n){const o=Math.max(0,Math.min(1,(l.b-l.a)/n));t=l.x+o*(p-l.x),e=l.a+o*(g-l.a)}else t=l.x,e=l.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;c.length>t;t++)f(c[t],a)}else for(const t of c)f(t,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else{a=m;for(const t of c)f(t,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else c.push({x:p,y:g,datum:r})}for(const t of c)f(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(g&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),n=c(t),o=u(t);Number.isFinite(n)&&w.push({__x:e,__y:n,__diffSegment:"line-A"}),Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:f}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:p,fill:"none"}),curve:i.curve||"linear",...o,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:b,color:h}]}]},legendPosition:x}}}},ch={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?At(t,r,n):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=o.lineStyle||(t=>{const e=null==r?void 0:kt(t,r,s),n=i.showLine??!0,o={fill:i.color??e,stroke:n?i.stroke??e:"none",...n?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},l=i.styleRules;if(l?.length){const e=Rt(i.yAccessor),n=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(o,zt(t,l,{value:e(t),category:n}))}return o}),c=i.normalize?"zero":i.baseline??"zero",u=o.pointStyle||ih(t,r,n,o,i);return{chartType:"stackedarea",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:n,normalize:i.normalize,baseline:c,stackOrder:i.stackOrder,lineStyle:l,...o,...u&&{pointStyle:u},curve:o.curve??i.curve??"monotoneX",showLegend:o.showLegend??!!r}}},uh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const[r]=o.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...o,scalePadding:o.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:o.extentPadding??(r>200?.1:.02)}}},dh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=o.pointStyle||eh(t,e,n,o,i),s=function(t,e,n){return t&&0!==t.length?(o,i)=>{const r=zt(o,t,e(o,i)),s=n?n(o,i):void 0;return s?{...r,...s}:r}:n}(i.styleRules,Tt(i.xAccessor||"x",i.yAccessor||"y"),l),a=s?t=>({..."function"==typeof r?r(t):r,...s(t)}):r;var l;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:n,...o,sizeRange:i.sizeRange||[3,15],pointStyle:a,showLegend:o.showLegend??!!e}}},hh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,f=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,p=B.createElement,g=a?[(t,e,n)=>{if(!e?.x||!e?.y)return null;const o=n.width,i=n.height,l=null!=r?e.x(r):o/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(o,l)),m=Math.max(0,Math.min(i,g)),b=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:o-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:o-y,h:i-m}],x=c?[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:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:o-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(B.Fragment,null,...b.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:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:o,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...x)}]:void 0;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:n,pointStyle:o.pointStyle||i.pointStyle||eh(t,e,n,o,i),...o,showLegend:o.showLegend??!!e,...g&&{svgPreRenderers:g}}}},fh={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const n=e.xAccessor||"x",o=e.yAccessor||"y",i=e.orderAccessor?[...t].sort((t,n)=>null==t||"object"!=typeof t?1:null==n||"object"!=typeof n?-1:jt(Wt(e.orderAccessor,"order",t))-jt(Wt(e.orderAccessor,"order",n))):t,r=new WeakMap;let s=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=jt(Wt(n,"x",t)),i=jt(Wt(o,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&s++}let a=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=jt(Wt(n,"x",t)),i=jt(Wt(o,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=i.pointRadius??4,a=[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const n=[];for(let t=0;e.length-1>t;t++){const o=e[t],i=e[t+1],r=Yt(t,e.length);100>e.length&&n.push(B.createElement("line",{key:"halo-"+t,x1:o.x,y1:o.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),n.push(B.createElement("line",{key:"segment-"+t,x1:o.x,y1:o.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:s,strokeLinecap:"round"}))}return B.createElement(B.Fragment,null,...n)}];return{chartType:"scatter",data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:n,pointStyle:Lt(t=>{const e=r.orderMap.get(t),n=e?.idx??0,o=e?.total??1;return{fill:o>0?Yt(n,o):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},Xt(i)),...o,svgPreRenderers:a}}},ph={frameType:"xy",buildProps:(t,e,n,o,i)=>{const r=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1;return{chartType:"heatmap",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,colorScheme:n||i.colorScheme||"blues",showValues:i.showValues,heatmapValueFormat:i.valueFormat,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:r}),...o}}};function gh(t){return Math.max(0,Math.min(1,t))}function yh(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 n=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(n){const t=[Number(n[1]),Number(n[2]),Number(n[3])];if(t.every(Number.isFinite))return t}return null}function mh(t,e,n){const o=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${o(t)}${o(e)}${o(n)}`}function bh(t,e,n){const o=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:gh(t.offset),color:t.color??n,opacity:null==t.opacity?1:gh(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===o.length)return"#999999";const i=t=>{if(1===t.opacity)return t.color;const e=yh(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===o.length)return i(o[0]);const r=gh(e);if(o[0].offset>=r)return i(o[0]);if(r>=o[o.length-1].offset)return i(o[o.length-1]);for(let t=0;o.length-1>t;t++){const e=o[t],n=o[t+1];if(e.offset>r||r>n.offset)continue;const s=n.offset-e.offset,a=s>0?(r-e.offset)/s:0,l=yh(e.color),c=yh(n.color);if(!l||!c)return i(.5>a?e:n);const[u,d,h]=l,[f,p,g]=c,y=u+(f-u)*a,m=d+(p-d)*a,b=h+(g-h)*a,x=e.opacity+(n.opacity-e.opacity)*a;return 1===x?mh(y,m,b):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(b)},${x})`}return i(o[o.length-1])}function xh(t,e,n){return null==n?`${t}-${e}`:`${t}-${e}-${n}`}import{Fragment as vh,jsx as wh,jsxs as kh}from"react/jsx-runtime";function Sh(t=240){const e=360-t,n=180+e/2,o=n*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:n,startAngleRad:o,offsetRad:-Math.PI/2+o}}import{useMemo as Ah,useCallback as Mh,useRef as _h}from"react";var Ph={RdBu:lt,PiYG:ct,PRGn:ut,BrBG:dt,RdYlBu:ht,RdYlGn:ft,Spectral:pt},Ch="__likert_neutral_neg",Lh="__likert_neutral_pos";function Rh(t,e){if("function"==typeof t)return t;const n=t||e;return t=>t[n]}import*as Th from"react";function Ih(t){return Nt(t)}function $h(t,e,n,o,i){const r=T(o.theme).colors.categorical,s=n??o.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],l="string"==typeof e?e:"__ssrColorBy",c="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?At(c,l,s??r):void 0,d=Ad("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=Rt(i.valueAccessor),f=i.styleRules,p=o.pieceStyle;return(t,n)=>{const o={fill:e&&u?kt(t,e,u):d};return f?.length&&Object.assign(o,zt(t,f,{value:h(t),category:n})),"function"==typeof p?Object.assign(o,p(t,n)||{}):p&&"object"==typeof p&&Object.assign(o,p),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}function Oh(t,e,n,o,i){const r=$h(t,e,n,o,i);return(t,e)=>{const n=r(t,e);return void 0===n.fillOpacity&&(n.fillOpacity=.8),void 0===n.stroke&&(n.stroke=n.fill),n}}function zh(t,e,n,o,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s="string"==typeof e?e:"__ssrViolinColorBy",a="function"==typeof e?r.map(t=>({...t,__ssrViolinColorBy:e(t)})):r,l=T(o.theme).colors.categorical,c=n??o.colorScheme,u=e?At(a,s,c??l):void 0,d=Ad("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return t=>{const n=e&&u?kt(t,e,u):d;return{fill:n,fillOpacity:.6,stroke:i.stroke??n,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function Fh(t,e,n,o,i){const r=$h(t,e,n,o,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function Dh(t,e,n,o,i){const r=$h(t,e,n,o,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=c.length?_t(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?Mt(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var Eh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:e,colorScheme:n,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Ih(o.gradientFill),pieceStyle:$h(t,e,n,o,i)})},Nh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>{const r=e||i.stackBy;return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:n,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Ih(o.gradientFill),pieceStyle:$h(t,r,n,o,i),showLegend:o.showLegend??!!r}}},Bh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>{const r=e||i.groupBy;return{chartType:"clusterbar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:n,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Ih(o.gradientFill),pieceStyle:$h(t,r,n,o,i),showLegend:o.showLegend??!!r}}},Wh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>{const r=e||i.categoryAccessor;return{chartType:"pie",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:n,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...o,pieceStyle:$h(t,r,n,o,i),showLegend:o.showLegend??!!r}}},jh={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,n,o,i)=>{const r=e||i.categoryAccessor;return{chartType:"donut",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:o.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:n,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...o,pieceStyle:$h(t,r,n,o,i)}}},Yh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=i.valueAccessor||"value",a=r.map(t=>Number("function"==typeof s?s(t):t[s])).filter(Number.isFinite),l=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:t,oAccessor:i.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:e,colorScheme:n,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:l?{rExtent:l}:{},...o,summaryStyle:Oh(t,e,n,o,i)}}},Xh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"boxplot",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:n,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...o,summaryStyle:o.summaryStyle||Oh(t,e,n,o,i)})},Hh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"violin",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:n,...o,summaryStyle:o.summaryStyle||zh(t,e,n,o,i),showLegend:o.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},Gh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"swarm",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:n,...o,sizeRange:i.sizeRange||[3,8],pieceStyle:o.pieceStyle||Dh(t,e,n,o,i),showLegend:o.showLegend??!!e})},qh={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,n,o,i)=>({chartType:"point",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...o,pieceStyle:Fh(t,e,n,o,i),showGrid:o.showGrid??!0,showLegend:o.showLegend??!!e})},Vh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>{const r=e||i.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Ih(o.gradientFill),pieceStyle:o.pieceStyle||$h(t,r,n,o,i),showLegend:o.showLegend??!!r,barPadding:i.barPadding??40}}},Uh={frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"ridgeline",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...o,summaryStyle:o.summaryStyle||((r,s)=>({fillOpacity:.5,...$h(t,e,n,o,i)(r,s)})),showLegend:o.showLegend??!!e})},Kh={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,n,o,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(t,e,n,o,i,r){const s=new Map,a=new Set(e);for(const l of t){const t=n(l);s.has(t)||s.set(t,new Map);const c=s.get(t);if(o){const t=o(l);if(null==t||!Number.isFinite(t))continue;if(!Number.isInteger(t)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",t);continue}const n=t-1;if(0>n||n>=e.length)continue;const i=e[n];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const t=i(l),e=r(l);if(!a.has(t))continue;c.set(t,(c.get(t)||0)+(Number.isFinite(e)?e:0))}}const l=[];for(const[t,n]of s){let o=0;for(const t of e)o+=n.get(t)||0;if(0!==o)for(let i=0;e.length>i;i++){const r=e[i],s=n.get(r)||0;l.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/o*100,__likertLevelIndex:i})}}return l}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,Rh(i.categoryAccessor,"question"),i.levelAccessor?null:Rh(i.valueAccessor,"score"),i.levelAccessor?Rh(i.levelAccessor,"level"):null,i.levelAccessor?Rh(i.countAccessor,"count"):null);s&&(a=function(t,e){const n=e.length,o=n%2!=0,i=Math.floor(n/2),r=new Map;for(const e of t){const t=r.get(e.__likertCategory)||[];t.push(e),r.set(e.__likertCategory,t)}const s=[];for(const[,t]of r){const e=new Map;let r,a;for(const n of t)n.__likertLevel===Ch?r=n:n.__likertLevel===Lh?a=n:e.set(n.__likertLevelIndex,n);o&&r&&s.push(r);for(let t=i-1;t>=0;t--){const n=e.get(t);n&&s.push(n)}o&&a&&s.push(a);for(let t=o?i+1:i;n>t;t++){const n=e.get(t);n&&s.push(n)}}return s}(function(t,e){const n=e.length,o=n%2!=0,i=Math.floor(n/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(o&&t===i){const t=e.__likertPct/2;r.push({...e,__likertLevel:Ch,__likertPct:-t}),r.push({...e,__likertLevel:Lh,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=T(o.theme).colors.diverging,c=Array.isArray(n)&&n.length>=r.length?n:function(t,e){if(0>=t)return[];if(e){const n=Ph[e];if(n){if(1===t)return[n(.5)];const e=[];for(let o=0;t>o;o++)e.push(n(o/(t-1)));return e}}const n=["#da1e28","#ff8389","#ffb3b8"],o=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===t)return[i];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);return a}(r.length,l),u=new Map(r.map((t,e)=>[t,c[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",f=Hi(!1===o.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},o.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:o.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...o,pieceStyle:Lt(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===Ch||e===Lh?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},Xt(i)),showLegend:o.showLegend??!0,legendPosition:o.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},Zh={frameType:"ordinal",layout:{margin:(t,e)=>"vertical"===t.orientation?{top:e.title?60:40,right:20,bottom:60,left:60}:{top:e.title?40:10,right:10,bottom:10,left:10}},buildProps:(t,e,n,o,i)=>{const r="vertical"===i.orientation,s=e||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:n,...o,showAxes:r,showGrid:r,pieceStyle:$h(t,s,n,o,i),showLabels:i.showLabels??!0}}},Qh={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const n=t.__gauge;if(!n)return null;const o=(n.startAngleDeg+(n.gMax===n.gMin?0:(Math.max(n.gMin,Math.min(n.gMax,n.value??n.gMin))-n.gMin)/(n.gMax-n.gMin))*n.sweep-90)*Math.PI/180,i=n.needleColor||e.colors.text,r=n.showScaleLabels?(n.thresholds||[]).filter(t=>t.value>n.gMin&&n.gMax>t.value):[];return kh(vh,{children:[n.showNeedle&&kh(vh,{children:[wh("line",{x1:n.centerX,y1:n.centerY,x2:n.centerX+n.needleLength*Math.cos(o),y2:n.centerY+n.needleLength*Math.sin(o),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),wh("circle",{cx:n.centerX,cy:n.centerY,r:4,fill:i})]}),null!=n.contextValue&&wh("text",{x:n.centerX,y:n.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:n.valueFontSize,fontWeight:700,fill:i,children:n.contextValue}),r.map((t,o)=>{const i=(n.startAngleDeg+(n.gMax===n.gMin?0:(t.value-n.gMin)/(n.gMax-n.gMin))*n.sweep-90)*Math.PI/180,r=n.innerRadius-1,s=n.radius+1,a=n.radius+10,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return kh("g",{children:[wh("line",{x1:n.centerX+Math.cos(i)*r,y1:n.centerY+Math.sin(i)*r,x2:n.centerX+Math.cos(i)*s,y2:n.centerY+Math.sin(i)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),wh("text",{x:n.centerX+Math.cos(i)*a,y:n.centerY+Math.sin(i)*a,textAnchor:c,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+o)})]})},buildProps:(t,e,n,o,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=Sh(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=Bt(o.gradientFill),p=function(t){const{min:e,max:n,value:o,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=t,d=n-e||1,h=(Math.max(e,Math.min(n,o))-e)/d;let f=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:n,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(n,t.value))})),n>f[f.length-1].value&&f.push({value:n,color:f[f.length-1].color});const p=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(p){const t=a?h:1,e=xh("bg",0);if(g.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),n=Math.max(1,Math.min(e,Math.round(t*e))),o=[];for(let e=0;n>e;e++)o.push(bh(c.stops,t*(e+.5)/n,r||f[0]?.color||"#007bff"));const i=xh("fill",0);g.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:o}}),y.set(i,{fill:o[0]||s})}}else{let t=e;for(let n=0;f.length>n;n++){const o=f[n],i=(o.value-t)/d,r=(t-e)/d,l=(o.value-e)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const t=xh("fill",n);g.push({category:t,value:c,_zone:o.label||"Zone "+(n+1),_isFill:!0}),y.set(t,{fill:o.color})}if(u>0){const t=xh("bg",n);g.push({category:t,value:u,_zone:o.label||"Zone "+(n+1),_isFill:!1}),y.set(t,{fill:s,opacity:.4})}t=o.value}}if(l&&i&&i.length>0)for(const t of i)t.value>e&&n>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:g,pieceStyle:(t,e)=>y.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:f}),[g,y]=o.size||[300,250],m=function(t=240){const{sweepRad:e,offsetRad:n}=Sh(t),o=[[Math.cos(n),Math.sin(n)],[Math.cos(n+e),Math.sin(n+e)],[0,0]];for(let t=0;2*Math.PI>t;t+=Math.PI/2)((t-n)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>e+.001||o.push([Math.cos(t),Math.sin(t)]);const i=o.map(t=>t[0]),r=o.map(t=>t[1]),[s,a]=_t(i),[l,c]=_t(r);return{minX:s,maxX:a,minY:l,maxY:c,width:a-s,height:c-l,cx:(s+a)/2,cy:(l+c)/2}}(a),b=Math.min(10,Math.max(1,Math.min(g,y)/12)),x=Math.max(4,Math.min((g-2*b)/m.width,(y-2*b)/m.height)-2),v=Math.max(0,Math.min(x-1.5,x*(1-l))),w=g/2-m.cx*x,k=y/2-m.cy*x,S=2*(x+4),A=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(A):Math.round(A)+"",_=i.centerContent??o.centerContent,P=null!=_?"function"==typeof _?_(A,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:Th.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Th.createElement("div",{style:{fontSize:Math.max(16,.3*x),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&Th.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:p.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:Lt(p.pieceStyle,Xt(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...o,size:[g,y],margin:{top:k-S/2,bottom:y-k-S/2,left:w-S/2,right:g-w-S/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(o.annotations)?o.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:A,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:x,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:x-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*x))}}}}};import{scaleTime as Jh}from"d3-scale";var tf={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function ef(t="static"){return tf[t]??tf.static}var nf=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function of(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:nf.has(t.kind)?"fatal":"warn"}function rf(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function sf(t){const{desired:e,minGaps:n,weights:o}=t,i=e.length;if(0===i)return[];if(n.length!==Math.max(0,i-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const r=Array(i).fill(0);for(let t=1;i>t;t++)r[t]=r[t-1]+Math.max(0,Number.isFinite(n[t-1])?n[t-1]:0);const s=[];for(let t=0;i>t;t++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[t])?o[t]:1),i=(Number.isFinite(e[t])?e[t]:0)-r[t];for(s.push({start:t,end:t,weight:n,mean:i});s.length>1;){const t=s[s.length-1],e=s[s.length-2];if(t.mean>=e.mean)break;const n=e.weight+t.weight;s.splice(s.length-2,2,{start:e.start,end:t.end,weight:n,mean:(e.mean*e.weight+t.mean*t.weight)/n})}}const a=Number.isFinite(t.min)?t.min:-1/0,l=Number.isFinite(t.max)?t.max-r[i-1]:1/0,c=a>l?a:l,u=Array(i);for(const t of s){const e=Math.max(a,Math.min(c,t.mean));for(let n=t.start;t.end>=n;n++)u[n]=e+r[n]}return u}function af(t,e){let n=0,o=t.length-1,i=-1;for(;o>=n;){const r=n+o>>>1;t[r].at>e?o=r-1:(i=r,n=r+1)}return 0>i?{at:e,before:0,after:0}:t[i]}function lf(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let i=0;t.length-1>i;i++){const r=t[i],s=t[i+1],a=[...new Set([...r.map(t=>t.at),...s.map(t=>t.at)])].sort((t,e)=>t-e);let l=0;for(const t of a){const e=af(r,t),n=af(s,t);l=Math.max(l,e.after+n.before)}n.push(l),o.push(o[o.length-1]+l+e)}return{adjacentClearance:n,positions:o}}function cf(t,e,n,o={}){let i=[...t];if(1>=i.length)return i;let r=[...i],s=n(i),a=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let t=0;l>t&&c>a;t++){const t=new Map(i.map((t,e)=>[t,e])),l=new Map,c=new Map;for(const n of e){const e=t.get(n.source),o=t.get(n.target);if(null==e||null==o)continue;const i=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*i),c.set(n.source,(c.get(n.source)??0)+i),l.set(n.target,(l.get(n.target)??0)+e*i),c.set(n.target,(c.get(n.target)??0)+i)}i=i.map((t,e)=>({item:t,index:e,barycenter:(l.get(t)??e)/(c.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(o.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=n(i);if(a++,s>u)s=u,r=[...i];else if(u===s)break}return r}function uf(t,e,n={}){const o=[...t],i=o.length;if(1>=i||i>(n.maxItems??8))return o;const r=Math.max(1,n.maxEvaluations??1/0);let s=0,a=[...o],l=1/0;const c=()=>{if(s>=r)return;const t=e(o);s++,l>t&&(l=t,a=[...o])};c();const u=Array(i).fill(0);let d=0;for(;i>d&&r>s;)if(d>u[d]){const t=d%2==0?0:u[d];[o[t],o[d]]=[o[d],o[t]],c(),u[d]++,d=0}else u[d]=0,d++;return a}function df(t,e){return e>t?-1:t>e?1:0}function hf(t){return t.occupants.map(t=>t.id).sort(df).join("\0")}function ff(t,e,n=0){return t.slice(0,-1).map((o,i)=>null!=o.group&&o.group===t[i+1].group?n:e)}function pf(t,e){return t.map(t=>{const n=new Map;for(const o of t.occupants){const t=e[o.id];if(t)for(const e of t.samples){const t=n.get(e.t)??{before:0,after:0},o=e.boundaryOffset??0;n.set(e.t,{before:Math.max(t.before,e.topMass-o),after:Math.max(t.after,e.botMass+o)})}}return[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function gf(t,e,n){if(0===t.length)return[];const{padding:o,plotH:i,valueScale:r}=n,s=n.stackValueScale??r,a=ff(t,o,n.groupPadding??0),l=[o+t[0].peak.topPeak*s];for(let n=1;t.length>n;n++)l.push(l[n-1]+e[n-1]*s+a[n-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*s+o;if(c>i&&c>0){const t=i/c;for(let e=0;l.length>e;e++)l[e]*=t}return l}function yf(t,e){const n=(t.boundaryOffset??0)*e,o=t.value*e;if("out"===t.kind){const i=t.sideMassBefore*e;return n+("top"===t.side?o/2-i:i-o/2)}const i=t.sideMassAfter*e;return n+("top"===t.side?o/2-i:i-o/2)}function mf(t,e,n,o,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:lf(pf(o,n)).adjacentClearance,a=gf(o,s,r);let l="hug"===r.lanePlacement?function(t,e,n,o,i,r,s){const a=t.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=ff(t,l,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),f=l+t[0].peak.topPeak*u,p=c-l-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=p-f)return gf(t,i,s);let g=1===a?[(f+p)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),i=Array(a).fill(0);for(const r of n){const n=e[r.source],s=e[r.target];if(null==n||null==s||n===s)continue;const a=o[r.source]?.localAttachments.get(r.id),l=o[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=yf(a,u),h=yf(l,u);t[n]+=(g[s]+h-d)*c,i[n]+=c,t[s]+=(g[n]+d-h)*c,i[s]+=c}const r=sf({desired:g.map((e,n)=>0===i[n]?e:.45*e+t[n]/i[n]*.55),minGaps:h,weights:i.map(t=>Math.max(1,t)),min:f,max:p});let s=0;for(let t=0;a>t;t++)s=Math.max(s,Math.abs(r[t]-g[t]));if(g=r,.01>s)break}return g}(o,i,e,n,s,a,r):[...a];if("hug"===r.lanePlacement){const n=e=>{const n={};for(const o of t)n[o.id]=e[i[o.id]];return n};bf(n(l),e)>bf(n(a),e)+1e-6&&(l=[...a])}const c={};for(const e of t)c[e.id]=l[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=c[e.id],o=n[e.id];Number.isFinite(t)&&o&&(u=Math.min(u,t-o.topPeak*r.valueScale),d=Math.max(d,t+o.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function bf(t,e){let n=0;for(const o of e){const e=t[o.source],i=t[o.target];Number.isFinite(e)&&Number.isFinite(i)&&(n+=Math.abs(e-i)*(o.value>0?o.value:1))}return n}function xf(t,e){const n=t?.samples;if(!n||0===n.length||n[0].t>e)return{top:0,bot:0};let o=0,i=n.length-1,r=0;for(;i>=o;){const t=o+i>>>1;n[t].t>e?i=t-1:(r=t,o=t+1)}const s=n[r].boundaryOffset??0;return{top:n[r].topMass-s,bot:n[r].botMass+s}}function vf(t,e,n,o,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*n+i*i*i*o}function wf(t,e){let n=0,o=1;for(let i=0;28>i;i++){const i=(n+o)/2;t>vf(0,e,e,1,i)?n=i:o=i}return(n+o)/2}function kf(t,e,n){const o=e+yf(t,n),i=t.value*n/2;return[o-i,o+i]}function Sf(t,e,n,o){return Math.max(0,Math.min(e,o)-Math.max(t,n))/Math.max(1e-9,e-t)}function Af(t,e,n,o,i,r,s){const{valueScale:a,domain:l,mode:c="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=o[s.source],h=o[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const f=e[s.source]?.localAttachments.get(s.id),p=e[s.target]?.localAttachments.get(s.id);if(!f||!p)continue;const g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,b]=kf(f,i[s.source],a),[x,v]=kf(p,i[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const o=n[t];if(!o)continue;const l=[g,y];if("quality"===c)for(const t of o.occupants)for(const n of e[t.id]?.samples??[])n.t>g&&y>n.t&&l.push(n.t);const h=t=>{const n=wf((t-g)/(y-g),u),l=vf(m,m,x,x,n),c=vf(b,b,v,v,n);let d=0;for(const n of o.occupants){if(n.id===s.source||n.id===s.target)continue;const o=r[n.id];if(null!=o?.start&&o.start>t)continue;if(null!=o?.end&&t>o.end)continue;const u=xf(e[n.id],t),h=i[n.id];d=Math.max(d,Sf(l,c,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(l)].sort((t,e)=>t-e);let p=0;for(let t=0;f.length-1>t;t++){const e=f[t],n=f[t+1]-e;p+=(h(e+.25*n)+h(e+.5*n)+h(e+.75*n))/3*n}d+=p/(y-g)*(s.value>0?s.value:1)}}return d}function Mf(t,e,n,o,i,r,s,a,l,c,u="both",d){return{crossings:t,weightedLength:e,pixelLength:bf(s,n),transitOcclusion:Af(n,o,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function _f(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function Pf(t,e){return t.map(t=>({t:_f(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function Cf(t,e,n){const o=e+(t.boundaryOffset??0)*n,i=t.value*n;if("out"===t.kind){const e=t.sideMassBefore*n;if("top"===t.side){const t=o-e;return[t,t+i]}const r=o+e;return[r-i,r]}const r=t.sideMassAfter*n;if("top"===t.side){const t=o-r;return[t,t+i]}const s=o+r;return[s-i,s]}function Lf(t,e,n,o,i="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:n.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:n.get(t.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(l[t.kind]??99)-(l[e.kind]??99)||((t,e)=>{if(!o||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const n=o.get(t.edge.id)?.target,i=o.get(e.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof i&&Number.isFinite(i)&&n!==i?"top"===t.side?n-i:i-n:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const n=o.get(t.edge.id)?.source,i=o.get(e.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof i&&Number.isFinite(i)&&n!==i?"top"===t.side?i-n:n-i:0}return 0})(t,e)||df(t.edge?.id??"",e.edge?.id??"")||df(t.side,e.side)||t.delta-e.delta)},u=a.length?function(t,e=1/0){let n=e;for(const e of t)n>e&&(n=e);return n}(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let f=null,p=0;for(const t of a)t.time!==f&&(f=t.time,p=0),t.sequence=p++;const g=t=>({time:t.time,phase:0,sequence:t.sequence??0}),y=[];let m=0,b=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let n=e-("top"===t.side?m:b);if(n>0){const e="top"===t.side?"bot":"top",o=Math.min(n,"top"===e?m:b);if(o>0){const i=g(t);y.push({...i,delta:-o,kind:"transfer-out",side:e}),y.push({...i,delta:+o,kind:"transfer-in",side:t.side}),"top"===e?m-=o:b-=o,"top"===t.side?m+=o:b+=o,n-=o}n>0&&null!==h&&(y.push({time:h,delta:+n,kind:"create",side:t.side}),"top"===t.side?m+=n:b+=n)}"top"===t.side?m-=e:b-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:b+=e}a.push(...y),c();let x=0,v=0,w=0,k=0,S=0,A=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:x,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},C=()=>{k=Math.max(k,x+v),S=Math.max(S,x-w),A=Math.max(A,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?x:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?x+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,C(),P(t.time)):"transfer-out"!==t.kind&&(C(),"out"!==t.kind||x+v>1e-12||(w=0),P(t.time))}const L=[];let R=0;for(;M.length>R;){let t=R;for(;M.length>t+1&&M[t+1].t===M[R].t;)t++;L.push(M[R]);for(let e=R+1;t>=e;e++){const t=L[L.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||L.push(M[e])}R=t+1}const T=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let I=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===I||I>t.systemInTime)&&(I=t.systemInTime);let $=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===$||t.systemOutTime>$)&&($=t.systemOutTime);if(L.length>0){const t=L[L.length-1],e=Math.max(null!=T?T:-1/0,null!=$?$:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&L.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const n=L[0],o=L.find(t=>t.topMass+t.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&n.t>d&&n.topMass+n.botMass>0&&(r=d,i=n),o&&null!=I&&Number.isFinite(I)&&o.t>I&&r>I&&(r=I,i=o),i&&Number.isFinite(r)&&L.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let O=L;if("max"===i&&null!=d&&null!=T&&T>d){let t,e=0;for(const n of L){const o=n.topMass+n.botMass;o>e&&(e=o,t=n)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};O=[...L.filter(t=>d>t.t),{t:d,...e},{t:T,...e},...L.filter(t=>t.t>T)]}}return{samples:O,peak:k,topPeak:S,botPeak:A,localAttachments:_}}function Rf(t){const e={};return t.forEach((t,n)=>{for(const o of t.occupants)e[o.id]=n}),e}function Tf(t,e,n){t.splice(0,t.length,...n);const o=Rf(n);for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function If(t){const e=new Map,n=[];t.forEach((t,o)=>{if(!t.group)return void n.push({anchor:o,stableId:hf(t),slots:[t]});const i=e.get(t.group)??{indexes:[],slots:[]};i.indexes.push(o),i.slots.push(t),e.set(t.group,i)});for(const[t,o]of e)n.push({anchor:o.indexes.reduce((t,e)=>t+e,0)/o.indexes.length,stableId:`${t}\0${o.slots.map(hf).join("\0")}`,slots:o.slots});return n.sort((t,e)=>t.anchor-e.anchor||df(t.stableId,e.stableId))}function $f(t){return t.some(t=>t.group)?If(t).flatMap(t=>t.slots):[...t]}function Of(t){return t.flatMap(t=>t.slots)}function zf(t,e,n){const o=new Map;return t.forEach((t,e)=>{for(const n of t.slots)o.set(n,e)}),t.map((t,i)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(null==e||null==n)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===i&&n!==i){const e=n>i?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(n===i&&e!==i){const n=e>i?1:-1;r.set(t.target,(r.get(t.target)??0)+s*n)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||n(t,e));return{...t,slots:s}})}function Ff(t,e){t.some(t=>t.group)&&Tf(t,e,$f(t))}function Df(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function Ef(t,e){return function(t,e,n=()=>!0){let o=0;for(let i=0;t.length>i;i++){const[r,s]=e(t[i]);for(let a=i+1;t.length>a;a++){if(!n(t[i],t[a]))continue;const[l,c]=e(t[a]);0>(r-l)*(s-c)&&o++}}return o}(e,e=>[t[e.source],t[e.target]],Df)}function Nf(t,e){let n=0;for(const o of e){const e=t[o.source],i=t[o.target];null!=e&&null!=i&&(n+=Math.abs(e-i)*(o.value>0?o.value:1))}return n}function Bf(t,e,n){const[o,i]=n.get(t.first),[r,s]=n.get(t.second);return 0>(e.get(o)-e.get(r))*(e.get(i)-e.get(s))?1:0}var Wf=t=>{let e=1;for(let n=2;t>=n;n++)e*=n;return e},jf=828*Wf(8),Yf=3e3;function Xf(t,e,n,o,i,r,s){const a=[...i],l=new Map(i.map(t=>[t,hf(t)])),c=new Map;for(const t of i)for(const e of t.occupants)c.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=c.get(t.source),n=c.get(t.target);e&&n&&(u.set(t,[e,n]),e!==n&&d.push({source:e,target:n,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let n=t+1;e.length>n;n++){if(!u.has(e[n])||!Df(e[t],e[n]))continue;const o=new Set([...u.get(e[t]),...u.get(e[n])]);h.push({index:h.length,first:e[t],second:e[n],involvedSlots:o})}const f=new Map;for(const t of i)f.set(t,[]);for(const t of h)for(const e of t.involvedSlots)f.get(e)?.push(t);const p=new Uint32Array(h.length);let g=0;const y=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,i.length),b=i.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),x=Math.max(1,y)*(Math.max(1,s.plotH)+m*Math.max(b,i.length)+1e-6*Math.max(1,i.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,S=(t,e)=>{let o=k.get(t);o||(o=new Map,k.set(t,o));const i=o.get(e);if(null!=i)return i;const r=function(t,e,n){return lf(pf([t,e],n)).adjacentClearance[0]??0}(t,e,n);return o.set(e,r),r},A=new Map(i.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:A.get(e[0]),target:A.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:A.get(e[0]),target:A.get(e[1])})}const P=new Map,C=new Map;for(const t of e)P.has(t.source)||P.set(t.source,new Set),C.has(t.target)||C.set(t.target,new Set),P.get(t.source).add(t.target),C.get(t.target).add(t.source);const L=e.flatMap(t=>{if(!(t=>{const e=new Set([...P.get(t.source)??[],...C.get(t.source)??[]]),n=new Set([...P.get(t.target)??[],...C.get(t.target)??[]]);return 1===P.get(t.source)?.size&&P.get(t.source).has(t.target)||1===e.size&&e.has(t.target)||1===n.size&&n.has(t.source)})(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),R=t=>{let e=0;for(const n of L)e+=Math.max(0,Math.abs(t[n.source]-t[n.target])-1)*n.weight;return e*v},T=t=>{const e=new Int16Array(i.length);for(let n=0;t.length>n;n++)e[A.get(t[n])]=n;return R(e)},I=h.map(t=>{const e=_.get(t.first),n=_.get(t.second);return[e.source,e.target,n.source,n.target]}),$=new Int16Array(i.length),O=new Float64Array(i.length),z=new Float64Array(i.length+1),F=t=>{for(let e=0;t.length>e;e++)$[A.get(t[e])]=e;let e=0;for(const[t,n,o,i]of I)0>($[t]-$[o])*($[n]-$[i])&&e++;if(t.length>0){const e=A.get(t[0]);O[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const n=A.get(t[e-1]),o=A.get(t[e]);O[o]=O[n]+S(t[e-1],t[e])*s.valueScale+s.padding}const n=A.get(t[t.length-1]),o=O[n]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(o>s.plotH&&o>0){const t=s.plotH/o;for(let e=0;O.length>e;e++)O[e]*=t}}z[0]=0;for(let e=0;t.length>e;e++)z[e+1]=z[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0,o=0,i=0;for(const t of M){const e=$[t.source],r=$[t.target];if(n+=Math.abs(e-r)*t.weight,o+=Math.abs(O[t.source]-O[t.target])*t.weight,Math.abs(e-r)>=2){const n=Math.min(e,r)+1;i+=(z[Math.max(e,r)]-z[n])*t.weight}}return e*x+o+i*m+R($)+1e-6*n},D=(t,n)=>{const o=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)o[e+1]=o[e]+t[e].peak.topPeak+t[e].peak.botPeak;let i=0;for(const t of e){const e=n[t.source],r=n[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;i+=(o[Math.max(e,r)]-o[s])*(t.value>0?t.value:1)}return i},E=o=>{const i=Rf(o),r=o.slice(0,-1).map((t,e)=>S(t,o[e+1])),a=mf(t,e,n,o,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:Nf(i,e),pixelLength:bf(a.centerlines,e),transitOcclusion:D(o,i)}},N=(t,e,n)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*x+e.pixelLength+e.transitOcclusion*m+T(n)+1e-6*e.weightedLength}),B=(t,e)=>{let n=e;if(null==n){const e=new Map(t.map((t,e)=>[t,e]));n=h.reduce((t,n)=>t+Bf(n,e,u),0),w.fullCrossing++}return N(n,E(t),t)},W=(t,i,r="quality")=>{let a=i;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,n)=>t+Bf(n,e,u),0),w.fullCrossing++}const l=E(t);return N(a,{...l,transitOcclusion:Af(e,n,t,l.map,l.geometry.centerlines,o,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let j=[...a];const Y=(t,e)=>df(l.get(t),l.get(e)),X=function(t){const e=new Set;for(const n of t)if(n.group){if(e.has(n.group))return!0;e.add(n.group)}return!1}(j),H=t=>{const e=(t=>{const e=cf(t,d,t=>B(t).cost,{passes:6,compare:Y,maxEvaluations:Yf});let n=B(e),o=Yf;for(let t=0;6>t&&o>0;t++){let i=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=o--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let l=0;const c=[];g++;for(const t of[...f.get(r)??[],...f.get(s)??[]])p[t.index]!==g&&(p[t.index]=g,c.push(t),l+=Bf(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of c)h+=Bf(t,d,u);w.localCrossing+=c.length;const y=B(e,n.crossings-l+h);n.cost>y.cost?(n=y,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:Wf(t.length)*(t.length+M.length+I.length))>jf)return e;const n=uf(t,F,{maxItems:8,maxEvaluations:5e4}),o=W(n),i=W(e);return o.crossings!==i.crossings&&i.crossings>o.crossings?n:e},G="geometry-refine"===s.mode;if(G||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!G&&"inside-out"===s.laneOrder)if(X){const t=If(j),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),n=[...t].sort((t,n)=>e(n)-e(t)||df(t.stableId,n.stableId)),o=Array(n.length);let i=Math.floor((n.length-1)/2)-1,r=Math.floor((n.length-1)/2)+1;n.length>0&&(o[Math.floor((n.length-1)/2)]=n[0]);for(let t=1;n.length>t;t++)t%2==1&&n.length>r||0>i?o[r++]=n[t]:o[i--]=n[t];j=Of(o)}else{const t=[...j].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||Y(t,e)),e=Array(t.length);let n=Math.floor((t.length-1)/2)-1,o=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let i=1;t.length>i;i++)i%2==1&&t.length>o||0>n?e[o++]=t[i]:e[n--]=t[i];j=e}}else j=X?(t=>{let e=If(t);if(1>=e.length)return Of(e);const n=t=>B(Of(t)).cost;e=If(H(t)),e=zf(e,d,Y);const o=function(t,e){const n=new Map;for(const e of t)for(const t of e.slots)n.set(t,e);const o=new Map;for(const t of e){const e=n.get(t.source),i=n.get(t.target);if(!e||!i||e===i)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=i.stableId>e.stableId?`${e.stableId}\0${i.stableId}`:`${i.stableId}\0${e.stableId}`,a=o.get(s);a?a.weight=(a.weight??0)+r:o.set(s,{source:e,target:i,weight:r})}return[...o.values()]}(e,d);e=cf(e,o,n,{passes:6,compare:(t,e)=>df(t.stableId,e.stableId),maxEvaluations:Yf}),e=function(t,e,n={}){const o=[...t];if(1>=o.length)return o;let i=e(o),r=1;const s=Math.max(0,n.passes??6),a=Math.max(1,n.maxEvaluations??1/0);for(let t=0;s>t&&a>r;t++){let t=!1;for(let n=0;o.length-1>n&&a>r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const s=e(o);r++,i>s?(i=s,t=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!t)break}return o}(e,n,{passes:8,maxEvaluations:Yf});const i=e.length>8?1/0:Wf(e.length)*(e.length+M.length+I.length);if(jf>=i){const t=uf(e,t=>F(Of(t)),{maxItems:8,maxEvaluations:5e4}),n=Of(t),o=Of(e),i=W(n),r=W(o);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=zf(e,d,Y),Of(e)})(j):H(j);if(!G&&"crossing-min+inside-out"===s.laneOrder&&j.length>1)if(X){const t=If(j);let e=B(Of(t)),n=Of(t),o=e;const i=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||df(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===i)continue;t.splice(s,1),t.splice(i,0,r);const a=Of(t),l=B(a);l.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=l,o.cost>l.cost&&(n=a,o=l))}j=n}else{let t=B(j),e=[...j],n=t;const o=Math.floor((j.length-1)/2),i=[...j].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||Y(t,e));for(const r of i){const i=j.indexOf(r);if(i===o)continue;j.splice(i,1),j.splice(o,0,r);const s=B(j);s.cost>t.cost?(j.splice(o,1),j.splice(i,0,r)):(t=s,n.cost>s.cost&&(e=[...j],n=s))}j=e}if((G||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&j.length>1)if(X){let t=If(j),e=W(Of(t),void 0,"score");for(let n=0;6>n&&t.length>1;n++){let n=!1;for(let o=0;t.length-1>o;o++){[t[o],t[o+1]]=[t[o+1],t[o]];const i=Of(t),r=W(i,void 0,"score");e.cost>r.cost?(j=i,e=r,n=!0):[t[o],t[o+1]]=[t[o+1],t[o]]}if(!n)break}t=zf(If(j),d,Y),j=Of(t)}else{let t=W(j,void 0,"score");for(let e=0;j.length-1>e;e++){const n=j[e],o=j[e+1],i=new Map(j.map((t,e)=>[t,e]));let r=0;const s=[];g++;for(const t of[...f.get(n)??[],...f.get(o)??[]])p[t.index]!==g&&(p[t.index]=g,s.push(t),r+=Bf(t,i,u));[j[e],j[e+1]]=[o,n];const a=new Map(i);a.set(n,e+1),a.set(o,e);let l=0;for(const t of s)l+=Bf(t,a,u);w.localCrossing+=s.length;const c=W(j,t.crossings-r+l,"score");t.cost>c.cost?t=c:[j[e],j[e+1]]=[n,o]}}const q=$f(a);j=$f(j);let V=W(j);const U=W(q);if(G){const t=T(q),e=T(j);(V.crossings>U.crossings||V.crossings===U.crossings&&e>t+1e-9||V.cost>U.cost)&&(j=q,V=U)}else V.cost>U.cost&&(j=q,V=U);return Tf(i,r,j),{before:U,after:V,initialOrder:a.map(t=>l.get(t)),evaluations:w}}function Hf(t,e,n){const o=t.map(t=>{const o=t.occupants.map(t=>({id:t.id,end:n[t.id]?.end??t.end}));let i=0,r=0;for(const t of o){const n=e[t.id];i=Math.max(i,n?.topPeak||0),r=Math.max(r,n?.botPeak||0)}return{occupants:o,peak:{topPeak:i,botPeak:r},...null!=t.group?{group:t.group}:{}}}),i={};return o.forEach((t,e)=>{for(const n of t.occupants)i[n.id]=e}),{slots:o,slotByNode:i}}var Gf=new Map,qf=1e-9,Vf=1e5;function Uf(t,e){let n=1/0,o=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>qf&&(n=Math.min(n,e.t),o=Math.max(o,e.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=e.start&&(n=Math.max(n,e.start)),null!=e.end&&(o=Math.min(o,e.end)),n>o?{start:null,end:null}:{start:n,end:o}):{start:null,end:null}}function Kf(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function Zf(t,e){return df(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function Qf(t){const e=new Map,n=new Map;for(const o of t)n.has(o.source)||n.set(o.source,new Set),e.has(o.target)||e.set(o.target,new Set),n.get(o.source).add(o.target),e.get(o.target).add(o.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...n].map(([t,e])=>[t,e.size]))}}function Jf(t){const e=new Map,n=new Map,o=(t,e,n,o)=>{let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(n,(i.get(n)??0)+o)};for(const i of t){const t=i.value>0&&Number.isFinite(i.value)?i.value:1;o(e,i.source,i.target,t),o(n,i.target,i.source,t)}const i=new Map,r=t=>{if(i.has(t))return;const o=e.get(t),r=n.get(t);if(o&&1===o.size&&(!r||0===r.size)){const[e,n]=[...o][0];return void i.set(t,{partner:e,weight:n})}const s=new Map;for(const[t,e]of o??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,n]=[...s][0];i.set(t,{partner:e,weight:n})}};for(const e of t)r(e.source),r(e.target);return i}function tp(t,e,n){const o=n.get(t),i=n.get(e);return!o||!i||o.partner===i.partner||o.partner===e||i.partner===t}function ep(t,e,n){return!!n.has(t)&&e.some(e=>!tp(t,e,n))}function np(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function op(t,e,n,o){if(12>=t.length||1>=o.slotCount)return o.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=Qf(n);for(const t of n){const e=i.get(t.source),n=i.get(t.target);if(null==e||null==n||e===n)continue;const o=np(t,s);r[e].set(n,(r[e].get(n)??0)+o),r[n].set(e,(r[n].get(e)??0)+o)}const a=Jf(n),l=t.map(t=>a.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let n=0;t.length-1>n&&5e4>u;n++)if(a.has(t[n]))for(let o=n+1;t.length>o;o++){if(!a.has(t[o]))continue;if(e.conflicts(t[n],t[o]))continue;u++;const i=Math.min(l[n],l[o])||Math.max(l[n],l[o]),r=tp(t[n],t[o],a)?i:-i;if(Math.abs(r)>qf&&(c[n].set(o,r),c[o].set(n,r),u>=5e4))break}const d=[...o.assignment],h=Array.from({length:o.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const f=(t,e,n)=>{const o=d[e],i=d[n];let r=0;const s=new Set;for(const a of[e,n])for(const[l,c]of t[a]){const t=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:o)===(l===e?i:l===n?o:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},p=(t,e,n)=>{let o=0;for(const[i,r]of t[e]){const t=n===d[i];d[e]===d[i]!==t&&(o+=t?r:-r)}return o},g=(t,e)=>t>qf||qf>=Math.abs(t)&&e>qf,y=(t,e,n,o)=>t>n+qf||qf>=Math.abs(t-n)&&e>o+qf;let m=0;for(let n=0;32>n&&Vf>m;n++){let n=null,o=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;t.length>u;u++){for(let f=0;h.length>f&&m++<Vf;f++){if(f===d[u])continue;if(!h[f].every(n=>!e.conflicts(t[u],t[n])))continue;const m=p(r,u,f),b=p(c,u,f);g(m,b)&&y(m,b,a,l)&&(n="move",o=u,i=-1,s=f,a=m,l=b)}if(m>=Vf)break}for(let u=0;t.length-1>u;u++){for(let p=u+1;t.length>p&&m++<Vf;p++){const m=d[u],b=d[p];if(m===b)continue;if(!h[b].every(n=>n===p||!e.conflicts(t[u],t[n])))continue;if(!h[m].every(n=>n===u||!e.conflicts(t[p],t[n])))continue;const x=f(r,u,p),v=f(c,u,p);g(x,v)&&y(x,v,a,l)&&(n="swap",o=u,i=p,s=-1,a=x,l=v)}if(m>=Vf)break}if(null==n||-1===o)break;if("move"===n){const t=d[o];h[t].splice(h[t].indexOf(o),1),h[s].push(o),d[o]=s;continue}const u=d[o],b=d[i];h[u].splice(h[u].indexOf(o),1,i),h[b].splice(h[b].indexOf(i),1,o),d[o]=b,d[i]=u}return d}function ip(t,e,n,o){const i=function(t,e,n,o){return`${t.map(t=>{const e=n[t.id],i=o[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,n,o),r=Gf.get(i);if(r)return Hf(r.slots,n,o);const s={};for(const e of t)s[e.id]=Uf(n[e.id],o[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,n)=>e[t.id].start-e[n.id].start||e[t.id].end-e[n.id].end||df(t.id,n.id)).map(t=>t.id)}(t,s),l=new Map(t.map(t=>[t.id,t])),c=new Map(t.map(t=>[t.id,t.group||void 0])),u=function(t,e,n,o,i){const r=new Set,s=new Map(t.map(t=>[t,new Set])),a=new Map(t.map(t=>[t,new Set]));for(const t of o)r.add(Zf(t.source,t.target)),s.get(t.target)?.add(t.source),a.get(t.source)?.add(t.target);const l=new Map,c=new Set,u=(t,e)=>{for(let n=0;t.length>n;n++)for(let o=n+1;t.length>o;o++){const i=Zf(t[n],t[o]);e instanceof Map?e.set(i,[t[n],t[o]]):e.add(i)}};for(const t of a.values())u([...t],l);for(const t of s.values())u([...t],c);const d=new Set;for(const[t,[o,i]]of l)c.has(t)&&(Kf(e[o],e[i])||Kf(n[o],n[i])&&(d.add(o),d.add(i)));return{conflicts:(t,n)=>{const o=i.get(t),s=i.get(n);return null!=o&&null!=s&&o!==s||null!=o!=(null!=s)&&!r.has(Zf(t,n))||!!Kf(e[t],e[n])||!(!d.has(t)&&!d.has(n))&&!r.has(Zf(t,n))}}}(a,s,o,e,c),d=function(t,e,n=new Map){const o=[],i=[];for(const r of t){let t=o.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!ep(r,t,n));-1!==t||n.has(r)||(t=o.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=o.length,o.push([])),o[t].push(r),i.push(t)}return{assignment:i,slotCount:o.length}}(a,u,Jf(e)),h=function(t,e,n,o){if(0===t.length||t.length>12||1>=o.slotCount)return o.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),l=Qf(n);for(const t of n){const e=i.get(t.source),n=i.get(t.target);if(null==e||null==n||e===n)continue;const o=np(t,l);r[e][n]+=o,r[n][e]+=o,a[e].set(n,(a[e].get(n)??0)+o),s[n].set(e,(s[n].get(e)??0)+o)}const c=Jf(n),u=t.map(t=>c.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let n=e+1;t.length>n;n++){for(const[t,o]of s[e])d[e][n]+=Math.min(o,s[n].get(t)??0);for(const[t,o]of a[e])d[e][n]+=Math.min(o,a[n].get(t)??0);if(c.has(t[e])&&c.has(t[n])){const o=Math.min(u[e],u[n])||Math.max(u[e],u[n]);d[e][n]+=tp(t[e],t[n],c)?o:-o}d[n][e]=d[e][n]}let h=[...o.assignment],f=(e=>{let n=0,o=0;for(let i=0;t.length>i;i++)for(let s=i+1;t.length>s;s++)e[i]===e[s]&&(n+=r[i][s],o+=d[i][s]);return{flow:n,affinity:o}})(h),p=0;const g=Array(t.length).fill(-1),y=Array.from({length:o.slotCount},()=>[]),m=(n,i,s,a)=>{if(p>=75e3)return;if(n===t.length)return p++,void((s>f.flow||s===f.flow&&a>f.affinity||s===f.flow&&a===f.affinity&&function(t,e){for(let n=0;Math.min(t.length,e.length)>n;n++)if(t[n]!==e[n])return e[n]>t[n];return e.length>t.length}(g,h))&&(h=[...g],f={flow:s,affinity:a}));const l=Math.min(i+1,o.slotCount-1);for(let o=0;l>=o;o++){if(y[o].some(o=>e.conflicts(t[n],t[o])))continue;let l=0,c=0;for(const t of y[o])l+=r[n][t],c+=d[n][t];if(g[n]=o,y[o].push(n),m(n+1,Math.max(i,o),s+l,a+c),y[o].pop(),g[n]=-1,p>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,u,e,{...d,assignment:op(a,u,e,d)}),f=new Map,p=h.map(t=>(f.has(t)||f.set(t,f.size),f.get(t))),g=Array.from({length:f.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y={};a.forEach((t,e)=>{const n=p[e],o=g[n];o.occupants.push({id:t,end:s[t].end??-1/0});const i=l.get(t)?.group;i&&(o.group=i),y[t]=n});for(const e of[...t].sort((t,e)=>df(t.id,e.id)))null==y[e.id]&&(g[0].occupants.push({id:e.id,end:-1/0}),y[e.id]=0);for(const t of g){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||df(t.id,e.id));for(const e of t.occupants){const o=n[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,o?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,o?.botPeak||0)}}const m={slots:g,slotByNode:y};return function(t,e){for(Gf.has(t)&&Gf.delete(t),Gf.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:{...e.slotByNode}});Gf.size>12;){const t=Gf.keys().next().value;if(null==t)break;Gf.delete(t)}}(i,m),m}function rp(t){return t.topMass+t.botMass}function sp(t,e){const n=t.samples.filter(t=>t.t===e);if(n.length>0)return n.reduce((t,e)=>rp(e)<rp(t)?t:e,n[0]);let o=null;for(const n of t.samples){if(n.t>e)break;o=n}return o}function ap(t,e,n,o,i,r,s=0){const a=new Map;for(const n of t){if(!n.group||!e[n.id])continue;const t=a.get(n.group)??[];t.push(n),a.set(n.group,t)}if(0===a.size||0>=r)return e;const l=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,c]of a){const a=n.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],f=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;const p=(h-u.peak.topPeak*r+(f+d.peak.botPeak*r))/2,g=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),y=new Map;for(const t of c)y.set(t.id,new Map);for(const t of g){const n=new Map;for(const i of c){const r=sp(e[i.id],t);if(!r||1e-9>=rp(r))continue;const s=o[i.id];if(null==s)continue;const a=n.get(s)??[];a.push({node:i,sample:r}),n.set(s,a)}const a=[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>rp(t)))}));if(0===a.length)continue;let l=p-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:n,sample:o}of e.active){const e=(l-i[n.id])/r+o.topMass-(o.boundaryOffset??0);y.get(n.id).set(t,e)}l+=e.mass*r+Math.max(0,s)}}for(const t of c){const n=e[t.id],o=l[t.id],i=y.get(t.id),r=[];for(const t of g){const e=i.get(t),o=n.samples.filter(e=>e.t===t);if(o.length>0){r.push(...o.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=sp(n,t);null!=e&&s&&rp(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}o.samples=r,o.localAttachments=new Map([...n.localAttachments].map(([t,e])=>{const n=i.get(e.time);return[t,{...e,...null!=n?{boundaryOffset:(e.boundaryOffset??0)+n}:{}}]}))}}return l}function lp(t,e,n,o,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=i,g={},y={};for(const e of t)g[e.id]=n[e.id].topPeak||0,y[e.id]=n[e.id].botPeak||0;const m="half"===u,b={};for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,n=Array.isArray(e.xExtent)?e.xExtent[1]:null;let i=null!=t&&Number.isFinite(t)?t:1/0,r=null!=n&&Number.isFinite(n)?n:-1/0;for(const t of o.outgoing[e.id]){i>t.startTime&&(i=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&i>t.systemInTime&&(i=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of o.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;i>e&&(i=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}b[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let x={},v=[],w=[];if(i.frozenSlots){const t=Hf(i.frozenSlots,n,b);v=t.slots,x=t.slotByNode,w=v.map(hf)}else if("reuse"===l){const o=ip(t,e,n,b);v=o.slots,x=o.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:b[t.id]?.end??-1/0}],peak:{topPeak:g[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),x[t.id]=e});Ff(v,x),0===w.length&&(w=v.map(hf));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,n){const o=new Map(n.map((t,e)=>[t,e]));Tf(t,e,[...t].sort((t,e)=>(o.get(hf(t))??1/0)-(o.get(hf(e))??1/0)||df(hf(t),hf(e))))}(v,x,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=Xf(t,e,n,b,v,x,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:f,domain:p}))),Ff(v,x);const S=mf(t,e,n,v,x,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,C=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:b,slots:v,slotByNode:x,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(hf),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:C}}function cp(t){const{sx:e,sTop:n,sBot:o,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=t,c=(n+o)/2,u=(r+s)/2;return{pathD:[`M${e},${n}`,`C${a},${n} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(o-n)/2}}}function up(t,e,n,o,i,r,s,a,l={}){const c=i,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(n.time)),f=t.value*c,p=n.value*c,g=e+(t.boundaryOffset??0)*c,y=o+(n.boundaryOffset??0)*c,m=t.sideMassBefore*c,b=n.sideMassAfter*c;let x,v,w,k;"top"===t.side?(x=g-m,v=x+f):(v=g+m,x=v-f),"top"===n.side?(w=y-b,k=w+p):(k=y+b,w=k-p);const S=l.sourceRunwayStart,A=l.minRun,M=Math.abs((w+k)/2-(x+v)/2),_=h-d,P="number"==typeof S&&Number.isFinite(S),C="number"==typeof A&&Number.isFinite(A)&&A>0;if(P&&M>1e-9&&_>0&&("auto"===A||C)){const e="source"===s?.85:"target"===s?.15:.5,n="auto"===A?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):A;if(n>_){const e=r(u(Math.min(S,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-n)))}}const L="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:x,sBot:v,tx:h,tTop:w,tBot:k,cp1X:L,cp2X:L}}function dp(t){return Math.max(18,11*t.length*.58)}function hp(t){const e=1.22*dp(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function fp(t,e){const n=t.labelX-dp(t.labelText),o=e.labelX-dp(e.labelText);return e.labelX+3>=n&&t.labelX+3>=o}var pp=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function gp(t){return t.replace(pp,(t,e,n)=>`${n},${e}`)}function yp(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function mp(t){return{...t,pathD:gp(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function bp(t){const{nodes:e,edges:n,domain:o,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:g="raw",styleRules:y,colorBy:m,valueAccessor:b,usageMode:x="static"}=t,v="vertical"===d?r:i,w="vertical"===d?i:r,k=function(t,e,n,o={}){const i=ef(o.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),s.add(e.id);const a=new Set,l=Array.isArray(n)&&2===n.length,c=l&&Number.isFinite(n[0])&&Number.isFinite(n[1]);l&&c&&c&&n[1]>=n[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,n,o,{usageMode:x}),{fatal:S,warnings:A}=function(t){const e=[],n=[];for(const o of t)"fatal"===of(o)?e.push(o):n.push(o);return{fatal:e,warnings:n}}(k),M=function(t,e,n="static"){if("strip"!==ef(n).invalidSystemTime)return t;const o=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===o.size?t:t.map(t=>{if(!o.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(n,k,x),_=Jh().domain(o).range([0,v]);if(S.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:_};const P=function(t,e,n){const{plotH:o,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=n,p=Number.isFinite(d)?Math.max(0,d):0,g=function(t,e){const n={},o={};for(const e of t)n[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),n[t.target]&&n[t.target].push(t);return{incoming:n,outgoing:o}}(t,e),y=function(t,e,n,o="temporal"){const i="temporal"===o?(t,e)=>t.endTime-e.endTime||df(t.id,e.id):(t,e)=>e.value-t.value||df(t.id,e.id),r="temporal"===o?(t,e)=>t.startTime-e.startTime||df(t.id,e.id):(t,e)=>e.value-t.value||df(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const n=new Map;for(const o of t){const t=o[e];n.has(t)||n.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=n.get(t);i.edges.push(o),i.total+=o.value,i.earliestStart=Math.min(i.earliestStart,o.startTime),i.latestEnd=Math.max(i.latestEnd,o.endTime)}const s=[...n.values()];s.sort("temporal"===o?(t,n)=>"target"===e?t.earliestStart-n.earliestStart||df(t.partner,n.partner):t.latestEnd-n.latestEnd||df(t.partner,n.partner):(t,e)=>e.total-t.total||df(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:i);return s};for(const e of t){const t=n.outgoing[e.id],o=n.incoming[e.id];if(0===o.length)a(t,"target").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=n});else if(0===t.length)a(o,"source").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=n});else{const e=a(o,"source"),n=a(t,"target"),i=Math.max(e.length,n.length);for(let t=0;i>t;t++){const o=t%2==0?"top":"bot";if(e[t])for(const n of e[t].edges)s.get(n.id).targetSide=o;if(n[t])for(const e of n[t].edges)s.get(e.id).sourceSide=o}}}return s}(t,e,g,i);let m={};for(const e of t)m[e.id]=Lf(e,g,y,void 0,u);const b=lp(t,e,m,g,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),x=b.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=b.slotByNode[t.source],n=b.slotByNode[t.target];if(void 0===e||void 0===n)continue;const o=y.get(t.id);e!==n?e>n?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(v.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=g.outgoing[e.id],n=g.incoming[e.id],o=new Set(t.map(t=>y.get(t.id).sourceSide)),i=new Set(n.map(t=>y.get(t.id).targetSide));if(1===o.size&&n.length>0){const t=[...o][0];for(const e of n)b.slotByNode[e.source]===b.slotByNode[e.target]&&(y.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const n of t)b.slotByNode[n.source]===b.slotByNode[n.target]&&(y.get(n.id).sourceSide=e)}}!function(t,e,n){const o=new Map,i=[];for(const e of t)i.push({time:e.startTime,kind:"out",edge:e}),i.push({time:e.endTime,kind:"in",edge:e});i.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||df(t.edge.id,e.edge.id));const r=t=>{let e=o.get(t);return e||(e={top:0,bot:0},o.set(t,e)),e},s=(t,e,n)=>{const o="top"===e?"bot":"top",i=Math.min(n,t[e]);t[e]-=i;const r=n-i;r>0&&(t[o]=Math.max(0,t[o]-r))};for(const t of i){const{edge:o}=t;if("in"===t.kind){const t=e.get(o.id)?.targetSide??"bot";r(o.target)[t]+=o.value;continue}const i=r(o.source),a=e.get(o.id);let l=a.sourceSide??"bot";if(n[o.source]===n[o.target]){const t=i.top>=o.value,e=i.bot>=o.value;t!==e?l=t?"top":"bot":t||e||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,o.value)}}(e,y,b.slotByNode),function(t,e,n,o){for(const i of t){const t=e.incoming[i.id],r=e.outgoing[i.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===n.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of r)"top"===n.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const i=s(),a="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,l="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(e=>!o.has(e.id)&&n.get(e.id).sourceSide===t&&c>=e.value).sort((t,e)=>e.value-t.value||df(t.id,e.id));return 0!==u.length&&(n.get(u[0].id).sourceSide=e,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(t,g,y,v),m={};for(const e of t)m[e.id]=Lf(e,g,y,void 0,u);const w=lp(t,e,m,g,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:x,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((t,e,n)=>t+(null!=e.group&&e.group===w.slots[n+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*o-S*p)/A),_=2*M+ff(w.slots,M,p).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(o-_)/k):1,C=Number.isFinite(l)&&l>0?Math.min(P,l):P;let L=lp(t,e,m,g,{plotH:o,padding:M,valueScale:C,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:x,lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&L.slots.length>1&&(Xf(t,e,m,L.laneLifetime,L.slots,L.slotByNode,{plotH:o,padding:M,valueScale:C,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:c,mode:"geometry-refine"}),L=lp(t,e,m,g,{plotH:o,padding:M,valueScale:C,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(hf),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(t,e){const n=(t,n)=>{for(const o of t){const t=new Map;for(const i of o){const o=`${("out"===n?e.get(i.id)?.sourceSide:e.get(i.id)?.targetSide)??""}\0${"out"===n?i.startTime:i.endTime}`,r="out"===n?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=t.get(o);if(null!=s&&s!==r)return!0;t.set(o,r)}}return!1};return n(Object.values(t.outgoing),"out")||n(Object.values(t.incoming),"in")}(g,y)){const n=function(t,e,n,o){const i=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=n[r.source],l=n[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=Cf(t,a,o),u=Cf(s,l,o);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,L.centerlines,C);m={};for(const e of t)m[e.id]=Lf(e,g,y,n,u);L=lp(t,e,m,g,{plotH:o,padding:M,valueScale:C,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(hf),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const T=new Map(b.initialSlotOrder.map((t,e)=>[t,e])),I=[...L.slots].sort((t,e)=>(T.get(hf(t))??1/0)-(T.get(hf(e))??1/0)||df(hf(t),hf(e))),$={};I.forEach((t,e)=>{for(const n of t.occupants)$[n.id]=e});const O=mf(t,e,m,I,$,{plotH:o,padding:M,valueScale:C,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),z=ap(t,m,I,$,O.centerlines,C,p),F=Mf(Ef($,e),Nf($,e),e,z,I,$,O.centerlines,L.laneLifetime,C,O.verticalUtilization,h,f);m=ap(t,m,L.slots,L.slotByNode,L.centerlines,C,p);const D=Mf(Ef(L.slotByNode,e),Nf(L.slotByNode,e),e,m,L.slots,L.slotByNode,L.centerlines,L.laneLifetime,C,L.verticalUtilization,h,f);return{nodeData:m,sides:y,valueScale:C,padding:M,compressedPadding:12>M,centerlines:L.centerlines,laneLifetime:L.laneLifetime,slots:L.slots,slotByNode:L.slotByNode,crossingsBefore:"insertion"===s?null:F.crossings,crossingsAfter:"insertion"===s?null:D.crossings,lengthBefore:"insertion"===s?null:F.weightedLength,lengthAfter:"insertion"===s?null:D.weightedLength,layoutQualityBefore:F,layoutQuality:D}}(e,M,{plotH:w,...u,ribbonLane:s,domain:o}),{centerlines:C,nodeData:L,valueScale:R}=P,T=It(m,b),I=[],$=[],O=0===a?new Map:function(t,e,n){const o=new Set(e.map(t=>t.target)),i=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(o.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const n=e.flatMap(t=>r.get(t.id)??[]),i=new Set(n.map(t=>t.startTime));n.length>0&&1===i.size&&e.every(t=>{const e=t.xExtent?.[0],i=n[0].startTime;return!o.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&i>e})&&a.add(t)}const l=new Map;for(const[t,e]of r){const o=i.get(t);if(o?.group&&!a.has(o.group))continue;const r=o?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),c=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let o=t+1;for(;s.length>o&&s[o].startTime===e;)o++;for(let e=t;o>e;e++){const t=s[e],o=Number.isFinite(r)&&t.startTime>r,i=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!o&&!i)continue;let a=n[0];o&&(a=Math.max(a,r)),i&&(a=Math.max(a,t.systemInTime)),!o&&i&&Number.isFinite(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&l.set(t.id,a)}u=e,t=o}}for(const[t,e]of s){if(!a.has(t))continue;const n=e.flatMap(t=>r.get(t.id)??[]);if(!n.every(t=>l.has(t.id))){for(const t of n)l.delete(t.id);continue}const o=Math.max(...n.map(t=>l.get(t.id)));for(const t of n)l.set(t.id,o)}return l}(e,M,o),z=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),F=new Map;for(const t of M){const e=L[t.source]?.localAttachments.get(t.id),n=L[t.target]?.localAttachments.get(t.id);e&&n&&F.set(t.id,up(e,C[t.source],n,C[t.target],R,_,s,o,{minRun:a,sourceRunwayStart:O.get(t.id)}))}const D=function(t,e,n,o,i,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),n=null==t?"node:"+e.source:"group:"+t,o=a.get(n)??new Map,i=o.get(e.startTime)??[];i.push(e),o.set(e.startTime,i),a.set(n,o)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>n.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const l=o(r),c=Math.min(...t.map(t=>t.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(t=>{const e=n.get(t.id);return null==e?l:Math.min(l,o(e))})),d=Math.min(l,Math.max(c,u));for(const t of a){const n=e.get(t.id),o=d+(n.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(t.id,{...n,sx:d,cp1X:o,cp2X:o})}}return s}(M,F,O,_,s,z),E=function(t,e,n,o,i){const r=new Map;for(const s of t){if(!n.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=o(s.startTime)-1e-9)continue;const a=i(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,D,O,_,t=>o[0]+t/v*(o[1]-o[0])),N=function(t,e,n){const o=new Map,i=new Map;for(const[t,e]of n??[]){const n=i.get(e)??[];n.push(t),i.set(e,n)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=n?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const e of a){const n=o.get(e)??new Map,i=n.get(r.startTime);n.set(r.startTime,null==i?t:Math.min(i,t)),o.set(e,n)}}return o}(M,E,z);e.forEach((t,e)=>{const n=L[t.id];if(!n||0===n.samples.length)return;const i=(r=n.samples,(s=N.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,n,o,i){if(0===t.length)return null;const r=Pf(t,i),s=t=>e+(r[t].boundaryOffset??0)*n,a=t=>s(t)-r[t].topMass*n,l=t=>s(t)+r[t].botMass*n;let c=`M${o(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)c+=` L${o(r[t].t)},${a(t)}`;c+=` L${o(r[r.length-1].t)},${l(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${o(r[t].t)},${l(t)}`;return c+" Z"}(i,C[t.id],R,_,o);if(!a)return;const l=Pf(i,o),u=l.find(t=>t.topMass+t.botMass>0)||l[0],h=C[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let f,p,g=c(t.id,e),m=g,b=.5;const x=t.__raw??t;if(y&&y.length>0){const t=zt(x,y,T(x));"string"==typeof t.fill?g=t.fill:null!=t.fill&&ei(t.fill)&&(p=t.fill,g=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:g),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(b=t.strokeWidth),"number"==typeof t.fillOpacity&&(f=t.fillOpacity),"number"==typeof t.opacity&&null==f&&(f=t.opacity)}const v=function(t,e,n,o,i,r){const s=n.nodeData[t];if(!s||0===s.samples.length)return[];const a=n.valueScale,l=n.centerlines[t],c=Pf(s.samples,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],d=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=o(u.t),f=o(d.t),p=t=>o(_f(t,i)),g=[],y=(t,e,n,o)=>`M${t},${e} L${n},${e} L${n},${o} L${t},${o} Z`;for(const n of e){if(n.source===t&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const t=s.localAttachments.get(n.id),e=r?.get(n.id)??n.startTime;if(t&&"out"===t.kind&&e>n.systemInTime){const o=p(n.systemInTime),r=p(e),s=null!=i&&i[0]>n.systemInTime,c=s?o:o-20,u=s?Math.min(r,o+20):o,d=Math.max(h,c);if(r>d){const[e,n]=Cf(t,l,a);g.push({pathD:y(d,e,r,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===t&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const t=s.localAttachments.get(n.id);if(t&&"in"===t.kind&&n.systemOutTime>n.endTime){const e=p(n.systemOutTime),o=p(n.endTime),i=e+20,r=Math.min(f,i);if(r>o){const[n,s]=Cf(t,l,a);g.push({pathD:y(o,n,r,s),x0:e,x1:i,from:1,to:0})}}}}return g}(t.id,M,P,_,o,E);I.push({id:t.id,pathD:a,fill:g,stroke:m,strokeWidth:b,...null!=f&&{fillOpacity:f},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:x,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const B=new Map;e.forEach((t,e)=>B.set(t.id,e)),M.forEach(t=>{const e=D.get(t.id);if(!e)return;const n=B.get(t.source)??0,o=c(t.source,n),{pathD:i,bezier:r}=cp(e),s=t.__raw??t,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;$.push({id:t.id,pathD:i,fill:o,opacity:u,rawDatum:s,bezier:r})});const W=function(t,e,n){const o=t.map(t=>({...t})),i=new Map;for(const t of o){const n=e[t.id];if(null==n)continue;const o=i.get(n)??[];o.push(t),i.set(n,o)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,o=(t.length-1)/2;t.forEach((t,i)=>{t.labelY=Math.max(8,Math.min(n-8,e+16*(i-o)))})};for(const t of i.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],n=-1/0;for(const o of t){const t=o.labelX-dp(o.labelText);e.length>0&&t>n+3&&(r(e),e=[],n=-1/0),e.push(o),n=Math.max(n,o.labelX)}r(e)}return function(t,e){const n=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;n.length>t;t+=1){let e=8;for(let o=0;t>o;o+=1)fp(n[t],n[o])&&(e=Math.max(e,n[o].labelY+16));n[t].labelY=Math.max(n[t].labelY,e)}for(let t=n.length-1;t>=0;t-=1){let o=e-8;for(let e=t+1;n.length>e;e+=1)fp(n[t],n[e])&&(o=Math.min(o,n[e].labelY-16));n[t].labelY=Math.min(n[t].labelY,o)}}}(o,n),o}(I,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:gp(t.pathD),gradientStubs:t.gradientStubs?.map(mp),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),j="vertical"===d?function(t,e,n){const o=t.map(t=>({...t}));for(const t of o){const n=1.22*dp(t.labelText)+4;t.labelX=e-4>n?Math.max(n/2+2,Math.min(e-n/2-2,t.labelX)):e/2}const i=[],r=[...o].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=i[i.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?i.push([t]):e.push(t)}for(const t of i){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],o=new Map;for(const n of t){const[t,i]=hp(n);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=i,o.set(n,r)}const i=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>i;for(const e of t){const t=o.get(e)??0;e.labelY=r?Math.min(n-8,12+14*t):Math.max(8,i-14*t)}}return o}(W,i,r):W,Y=new Map;if(null!=f)for(const t of e){const e=t.__raw??t,n="function"==typeof f?f(e):Number(e[f]);Number.isFinite(n)&&Y.set(t.id,n)}const X=function(t,e,n,o,i={}){if(!1===o)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*n)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=t.map((t,e)=>{const n=i.priorityById?.get(t.id),o=Math.abs(t.labelY);return{band:t,index:e,score:null!=n&&Number.isFinite(n)?1e6*n+dp(t.labelText):dp(t.labelText)+.01*o}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(j,i,r,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:X,ribbons:$.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:gp(t.pathD),bezier:yp(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:A,xScale:_}}import{Fragment as xp,jsx as vp,jsxs as wp}from"react/jsx-runtime";var kp="var(--semiotic-grid, #94a3b8)",Sp="var(--semiotic-text-secondary, #475569)",Ap="var(--semiotic-text-secondary, #94a3b8)",Mp=.22;function _p(t,e,n){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,n))}var Pp=t=>{const{bands:e=[],ribbons:n=[],showLabels:o=!0,selectionDatum:i="raw"}=t.config,r=t.selection??null,s=[];for(const t of n){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},n=!_p(e,r,i);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:n?Math.min(t.opacity,Mp):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!_p({__kind:"band",data:t.rawDatum,id:t.id},r,i);for(let n=0;t.gradientStubs.length>n;n++){const o=t.gradientStubs[n];s.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?Mp:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,...null!=o.y0&&{y0:o.y0},...null!=o.y1&&{y1:o.y1},from:o.from,to:o.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${n}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),n={__kind:"band",data:t.rawDatum,id:t.id},o=!_p(n,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:o?Mp:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...o&&e?{opacity:Mp}:{}},datum:n})}const a=o?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),n=t.labelText.trim().length>0,o=e&&r?.isActive&&_p({__kind:"band",data:t.rawDatum,id:t.id},r,i),s=n?t.labelText:o?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function Cp(t,e){if(!t)return[];const n=[],o=t=>{n.push(t);const i="function"==typeof e?e(t):t[e];i&&Array.isArray(i)&&i.forEach(o)};return o(t),n}function Lp(t,e,n,o){if(t&&t.length>0)return t;const i=new Set;return e.forEach(t=>{const e="function"==typeof n?n(t):t[n],r="function"==typeof o?o(t):t[o];i.add(e),i.add(r)}),Array.from(i).map(t=>({id:t}))}function Rp(t,e,n={}){return Lt(e?"function"==typeof e?n=>({...t(n),...e(n)??{}}):n=>({...t(n),...e}):t,n)}var Tp={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,n,o,i)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:n,edgeOpacity:o}=t,i=t.strokeWidth??1;return void 0!==e||void 0!==n||void 0!==o||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],n="number"==typeof t?t:Number(t);a=Number.isFinite(n)&&n>0?n:i}return{stroke:n??t.stroke??"#999",strokeWidth:a,opacity:o??t.opacity??.6}}:void 0}(i),s=T(o.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?kt(t?.data||t,e,void 0):Ad(void 0,s,n,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=Dt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=Lt(c?(t,e)=>({...l(t),...c(t,e)}):l,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:e,colorScheme:n,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:u,edgeStyle:r,...o}}},Ip={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,n,o,i)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",g=i.groupBy,y=i.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],b=Array.isArray(i.edges)?i.edges:[],x=Array.isArray(i.nodes)?i.nodes:[],v=x.length>0?x:Lp([],b,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(t=>{const e=m(c,t)+"",n=m(p,t),o=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==o?e:o+"",__raw:t},a=g?m(g,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(n)&&2===n.length){const t=r(n[0]),e=r(n[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),S=b.map((t,e)=>{const n=m(y,t),o={id:null!=n?n+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(l,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(o.systemInTime=e)}if(f){const e=r(m(f,t));Number.isFinite(e)&&(o.systemOutTime=e)}return o}),[A,M]=o.size??[600,400],_=o.margin,P="vertical"===i.orientation?"vertical":"horizontal",C=function(t,e,n,o="horizontal"){return"vertical"===o?{top:t?38:e?28:16,right:24,bottom:24,left:n?72:24}:{top:t?30:e?24:8,right:80,bottom:n?28:8,left:80}}(!!o.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,P),L={...C,..._},R=(o.showLegend??!!e)&&!!e,I=o.legendPosition??"right",$=o.__explicitMargin,O=t=>"number"==typeof $||null!=$&&"object"==typeof $&&null!=$[t];R&&("right"!==I||O("right")?"bottom"!==I||O("bottom")||(L.bottom=Math.max(L.bottom,80)):L.right=Math.max(L.right,140));const z=L,F=A-z.left-z.right,D=M-z.top-z.bottom,E=bt(n,T(o.theme).colors.categorical,q),N="function"==typeof e?e:null,B=N?v.map(t=>({_cat:N(t)})):v,W=N?"_cat":"string"==typeof e?e:void 0,j=n??[...E],Y=W?At(B,W,j):null,X=new Map;for(const t of k)X.set(t.id,t.__raw);const H=(t,n)=>{if(e&&X.has(t)){const n=X.get(t);return N?kt({_cat:N(n)},"_cat",Y??void 0):kt(n,"string"==typeof e?e:"id",Y??void 0)}return E[n%E.length]},G=Hi(R&&e?(()=>{const t=new Map;v.forEach((n,o)=>{const i=m(e,n),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:H(m(c,n)+"",o)})});const n=Array.from(t.values());return n.length>0?{legendGroups:[{type:"fill",label:"",items:n,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,o.legend),V=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:U,layoutConfig:K,issues:Z,xScale:Q}=bp({nodes:k,edges:S,domain:w,plotW:F,plotH:D,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:H,showLabels:V,styleRules:i.styleRules,colorBy:e,valueAccessor:l,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(Z.length>0){const t=Z.map(rf).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const J=U?function(t){const e=t.layout,n=t.nodes,o=t.orientation,i=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,l=t.showQualityReadout??!1,c=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,f=t.toTime,p=t.xScale,{centerlines:g,laneLifetime:y,nodeData:m,valueScale:b,compressedPadding:x,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=e;let A=null,M=null;for(const t of n){const e=y[t.id];if(!e||null===e.start||null===e.end)continue;const n=p(e.start),o=p(e.end);(null===A||A>n)&&(A=n),(null===M||o>M)&&(M=o)}const _=t=>Math.max(0,Math.min(s,t)),P=_(A??0),C=Math.max(P,_(M??s)),L=a.map((t,e)=>({tick:t,index:e,coordinate:p(f(t.date))})).filter(({coordinate:t})=>t>=P-.5&&C+.5>=t),R=null!==(w??null)&&null!=k&&null!=S,T=l&&(R||u.length>0)?wp("g",{fill:Ap,fontSize:10,textAnchor:"end",children:[R&&wp(xp,{children:[wp("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),wp("text",{x:i,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),u.map((t,e)=>wp("text",{x:i,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,I=x?vp("text",{x:i,y:"vertical"===o?-3:2,fontSize:10,fill:Ap,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,$=(t,e)=>h?h(t,e):kp;return wp("g","vertical"===o?{children:[T,I,L.map(({index:t,coordinate:e})=>vp("line",{x1:0,y1:e,x2:i,y2:e,stroke:kp,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&n.map((t,e)=>{const n=y[t.id];if(!n||null===n.start)return null;const o=m[t.id],i=o?{topPeak:o.topPeak,botPeak:o.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*b/2,s=p(n.start),a=p(n.end),l=$(t.id,e);return wp("g",{children:[vp("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),vp("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),vp("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),vp("line",{x1:-4,y1:P,x2:-4,y2:C,stroke:kp}),L.map(({tick:t,index:e,coordinate:n})=>{const o=f(t.date),i=null!=t.label?t.label:d?d(new Date(o)):"";return wp("g",{transform:`translate(-4,${n})`,children:[vp("line",{x2:-6,stroke:kp}),vp("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Sp,children:i})]},e)})]}:{children:[T,I,L.map(({index:t,coordinate:e})=>vp("line",{x1:e,y1:0,x2:e,y2:r,stroke:kp,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&n.map((t,e)=>{const n=y[t.id];if(!n||null===n.start)return null;const o=m[t.id],i=o?{topPeak:o.topPeak,botPeak:o.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*b/2,s=p(n.start),a=p(n.end),l=$(t.id,e);return wp("g",{children:[vp("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),vp("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),vp("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),vp("line",{x1:P,y1:r+4,x2:C,y2:r+4,stroke:kp}),L.map(({tick:t,index:e,coordinate:n})=>{const o=f(t.date),i=null!=t.label?t.label:d?d(new Date(o)):"";return wp("g",{transform:`translate(${n},${r+4})`,children:[vp("line",{y2:6,stroke:kp}),vp("text",{y:20,textAnchor:"middle",fontSize:11,fill:Sp,children:i})]},e)})]})}({layout:U,nodes:k,orientation:P,plotW:F,plotH:D,timelineExtent:"vertical"===P?D:F,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?t=>i.timeFormat(t):void 0,colorOf:H,toTime:t=>r(t),xScale:t=>Number(Q(t))}):void 0;return{chartType:"force",nodes:v,edges:b,customNetworkLayout:Pp,layoutConfig:K,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:n,...J&&{backgroundGraphics:J},...o,showLegend:R,...G&&{legend:G,legendPosition:I},__legendIncludesAutomatic:!0,margin:z}}},$p={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,n,o,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Lp([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=T(o.theme).colors.categorical,a=new Map,l="string"==typeof e?e:"__ssrSankeyColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?At(c,l,n??o.colorScheme??s):void 0,d=t=>({fill:e?kt(t?.data||t,e,u):Ad(void 0,s,n,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=Dt(i.styleRules,e,i.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:n,nodeStyleFn:o,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=kt(t.data||t,e,n):t&&(a.fill=o(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=kt(t.data||t,e,n):t&&(a.fill=o(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:f,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:e,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:Lt(i.nodeStyle||f,Xt(i)),edgeStyle:Lt(i.edgeStyle||p,Xt(i)),colorScheme:n,...o}}},Op={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,n,o,i)=>{if(!(e||Array.isArray(i.styleRules)&&i.styleRules.length>0||o.nodeStyle||i.nodeStyle||Ct(Xt(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:n,...o};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Lp([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=T(o.theme).colors.categorical,l=bt(n,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?At(u,c,n??o.colorScheme??a):void 0,h=new Map,f=i.nodeIdAccessor||i.nodeIDAccessor||"id",p=(t,n)=>{const o=t?.data||t;let r;if(e)r=kt(o,e,d);else{const e=(t.id??o?.[f]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??n??h.get(e);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=Dt(i.styleRules,e,i.valueAccessor,p)??p;return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:n,nodeStyle:Lt(i.nodeStyle||g,Xt(i)),...o}}},zp={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,n,o,i)=>{const r=T(o.theme).colors.categorical,s=new Map,a=Cp(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreeColorBy:l(t)})):a,u=l?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?At(c,u,n??o.colorScheme??r):void 0,h=o.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:t,childrenAccessor:i.childrenAccessor,colorBy:e,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:n,...o,nodeStyle:Rp(t=>{const o=t?.data||t;return{fill:i.colorByDepth?vt[Number(t?.depth||0)%vt.length]:e?l?kt({__ssrTreeColorBy:l(o)},"__ssrTreeColorBy",d??void 0):kt(o,e,d??void 0):Ad(void 0,r,n,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,Xt(i))}}},Fp={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,n,o,i)=>{const r=T(o.theme).colors.categorical,s=new Map,a=Cp(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreemapColorBy:l(t)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?At(c,u,n??o.colorScheme??r):void 0,h=i.showLabels??o.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:o.paddingTop,g=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,y=o.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:f,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=g&&{paddingTop:g},colorScheme:n,...o,nodeStyle:Rp(t=>{const o=t?.data||t;return{fill:i.colorByDepth?vt[Number(t?.depth||0)%vt.length]:e?l?kt({__ssrTreemapColorBy:l(o)},"__ssrTreemapColorBy",d??void 0):kt(o,e,d??void 0):Ad(void 0,r,n,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},y,Xt(i))}}},Dp={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,n,o,i)=>{const r=T(o.theme).colors.categorical,s=new Map,a=Cp(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrCirclePackColorBy:l(t)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?At(c,u,n??o.colorScheme??r):void 0,h=o.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??o.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:n,...o,nodeStyle:Rp(t=>{const o=t?.data||t;return{fill:i.colorByDepth?vt[Number(t?.depth||0)%vt.length]:e?l?kt({__ssrCirclePackColorBy:l(o)},"__ssrCirclePackColorBy",d??void 0):kt(o,e,d??void 0):Ad(void 0,r,n,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,Xt(i))}}},Ep={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Np}from"d3-scale";function Bp(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Wp={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,n,o,i)=>{const r="string"==typeof n?n:"blues",s=i.areaStyle??function(t,e,n,o){if(!Array.isArray(t))return;const i=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=i(e);null!=t&&isFinite(t)&&(r>t&&(r=t),t>s&&(s=t))}const a=Np(at(n)).domain([Number.isFinite(r)?r:0,Number.isFinite(s)?s:1]);return t=>{const e=i(t);return{fill:null!=e&&isFinite(e)?a(e):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:o}}}(i.areas,i.valueAccessor,r,i.areaOpacity??1),a=i.styleRules?Ft(s,i.styleRules,t=>{return{value:(e=t,"function"==typeof i.valueAccessor?i.valueAccessor(e):null!=i.valueAccessor?e?.properties?.[i.valueAccessor]??e?.[i.valueAccessor]:void 0)};var e},Bp):s;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:a,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...o}}},jp={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,n,o,i)=>{const r=t||i.points,s=i.pointStyle??function(t,e,n,o){const i=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",o="string"==typeof e?i:i.map(t=>({...t,__geoColorBy:e(t)}));r=At(o,t,n)}if(o.sizeBy){const t=i.map("function"==typeof o.sizeBy?o.sizeBy:t=>t?.[o.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=_t(t))}return t=>({fill:e&&r?kt(t,e,r):mt,fillOpacity:o.fillOpacity,stroke:"#fff",strokeWidth:o.strokeWidth,r:o.sizeBy?Mt(t,o.sizeBy,o.sizeRange,s):o.pointRadius??6})}(r,e,n,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Ft(s,i.styleRules,It(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||Ep,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:n,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...o}}},Yp={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,n,o,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),f=new Map;for(const t of h)f.set(t[s]+"",t);const p=i.edgeColorBy??e,g="function"==typeof p,y=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),n=f.get(t.target+"");return e&&n?{...t,coordinates:[{x:e.x,y:e.y},{x:n.x,y:n.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",b=p?g?At(y.map(t=>({[m]:p(t)})),m,n||"category10"):At(y,p,n||"category10"):null,x=t=>p&&b?kt(t,p,b):"#007bff";let v=1/0,w=-1/0;for(const t of y){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[S,A]=i.edgeWidthRange??[1,8],M=A-S,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||Ep,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:n,lineStyle:t=>{const e=Number(t?.[a]),n=Number.isFinite(e)?e:v,o=S+Math.max(0,Math.min(1,k>0?(n-v)/k:0))*M;return{stroke:x(t),strokeWidth:o,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...o}}};import*as Xp from"react";function Hp(t){const[e,n]=t,o=160>e||116>n,i=o?Math.min(12,Math.max(2,.08*e)):32,r=o?Math.min(8,Math.max(2,.12*n)):24,s=o?r:34;return{width:e,height:n,plot:{x:i,y:r,width:Math.max(1,e-2*i),height:Math.max(1,n-r-s)}}}function Gp(t){const e=(t??"")+"";if(!e)return"#4e79a7";const n=["#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 n[o%n.length]}function qp(t,e="#4e79a7",n){const o=n?.styleRules,i=!!o&&o.length>0,r=i?Rt(n?.valueAccessor):void 0;return n=>{const s=n.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,l={fill:null==a?e:Gp(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,zt(s,o,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function Vp(t,e,n,o){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:n},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...o}}}function Up(t,e,n){return"function"==typeof n?n(t,e):t[n]}function Kp(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 Zp(t,e,n){return Math.max(e,Math.min(n,t))}function Qp(t,e){const n=Kp(t);return null!=n&&n>0?n:e}function Jp(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function tg(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 eg}from"d3-scale";var ng={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},og=1e-9,ig=.005;function rg(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function sg(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 ag(t,e,n){return Math.max(e,Math.min(n,t))}function lg(t,e,n){return Math.min(t??n,e??n)}function cg(t,e,n){return ag(Math.max(t??n,e??n),0,1)}function ug(t){return 0>t?-1:1}function dg(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,n=t.shape.height/2;return{minX:t.x-e,minY:t.y-n,maxX:t.x+e,maxY:t.y+n}}function hg(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,n=e.height/2;return{minX:e.x-t,minY:e.y-n,maxX:e.x+t,maxY:e.y+n}}const n=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-n,minY:Math.min(e.y1,e.y2)-n,maxX:Math.max(e.x1,e.x2)+n,maxY:Math.max(e.y1,e.y2)+n}}function fg(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function pg(t,e,n,o,i,r,s,a){const l=i-t,c=(n+s)/2-Math.abs(l);if(0>=c)return null;const u=r-e,d=(o+a)/2-Math.abs(u);return d>0?d>c?{nx:ug(l),ny:0,penetration:c}:{nx:0,ny:ug(u),penetration:d}:null}function gg(t,e,n,o,i,r,s){const a=r/2,l=s/2,c=t-ag(t,o-a,o+a),u=e-ag(e,i-l,i+l),d=c*c+u*u;if(d>n*n)return null;if(og>=d){const r=Math.abs(t-(o-a)),s=Math.abs(t-(o+a)),c=Math.abs(e-(i-l)),u=Math.abs(e-(i+l)),d=Math.min(r,s,c,u);return d===r?{nx:-1,ny:0,penetration:n+r}:d===s?{nx:1,ny:0,penetration:n+s}:d===c?{nx:0,ny:-1,penetration:n+c}:{nx:0,ny:1,penetration:n+u}}const h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:n-h}}function yg(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,n,o,i,r){const s=o-t,a=i-e,l=n+r,c=s*s+a*a;if(c>=l*l)return null;if(og>=c)return{nx:1,ny:0,penetration:l};const u=Math.sqrt(c);return{nx:s/u,ny:a/u,penetration:l-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 pg(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 n=gg(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return n?{nx:-n.nx,ny:-n.ny,penetration:n.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?gg(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function mg(t,e){const n=e.shape;return"aabb"===n.type?"circle"===t.shape.type?gg(t.x,t.y,t.shape.radius,n.x,n.y,n.width,n.height):pg(n.x,n.y,n.width,n.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,n,o,i,r,s,a=0){const l=r-o,c=s-i,u=l*l+c*c,d=u>og?ag(((t-o)*l+(e-i)*c)/u,0,1):0,h=n+a/2,f=t-(o+l*d),p=e-(i+c*d),g=f*f+p*p;if(g>=h*h)return null;if(og>=g){const t=Math.sqrt(u);return t>og?{nx:-c/t,ny:l/t,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(g);return{nx:f/y,ny:p/y,penetration:h-y}}(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,n.x1,n.y1,n.x2,n.y2,n.thickness??0)}function bg(t,e){return`${t}\0${e}`}function xg(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function vg(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:rg(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function wg(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 kg(t){return{id:t.id,shape:sg(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:wg(t.bodyFilter),index:t.index}}function Sg(t,e){return!!e?.some(e=>Object.is(t,e))}function Ag(t,e){return function(t,e){if(!e)return!0;if("function"==typeof e)return e(t);const n=function(t,e){if(!e)return;let n=t;for(const t of e.split(".")){if(null==n||"object"!=typeof n)return;n=n[t]}return n}(t,e.property);return!("equals"in e&&!Object.is(n,e.equals)||"notEquals"in e&&Object.is(n,e.notEquals)||e.oneOf&&!Sg(n,e.oneOf)||e.notOneOf&&Sg(n,e.notOneOf))}(e,t.bodyFilter)}var Mg=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={...ng,...t},this.random=d(this.options.seed)}init(t={}){this.options={...ng,...t},this.random=d(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(og,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:rg(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))xg(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:sg(e.shape),bodyFilter:wg(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,n){const o=this.bodies.get(t);o&&(o.vx+=e/o.mass,o.vy+=n/o.mass,this.wake(o))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const n=this.sortedBodies();for(const t of n)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const o=this.options.maxVelocity;for(const t of n)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 n=o/e;t.vx*=n,t.vy*=n}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const i=this.bodyPairKeys(n),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(n,i,0===t),this.resolveColliders(n,r,0===t);this.updateSensors(n),this.updateSleeping(n,e)}settle(t=1200,e=this.options.fixedDt){let n=0;for(;t>n&&!this.allSleeping();)this.step(e),n+=1;return n}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:rg(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(xg)}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(vg),colliders:this.sortedColliders().map(kg),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=d(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=vg(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=kg(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 n=this.bodies.get(e.bodyId);if(!n||n.sleeping)continue;const o="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!o)continue;const i=o.x-n.x,r=o.y-n.y,s=Math.sqrt(i*i+r*r);if(og>=s)continue;const a=i/s,l=r/s,c=(s-e.restLength)*e.stiffness+((("vx"in o?o.vx:0)-n.vx)*a+(("vy"in o?o.vy:0)-n.vy)*l)*e.damping;n.vx+=c*a*t/n.mass,n.vy+=c*l*t/n.mass}}resolveBodyPairs(t,e,n){for(const o of e){const[e,i]=o.split(":").map(Number),r=t[e],s=t[i];if(!r||!s)continue;const a=yg(r,s);a&&(this.resolveDynamicCollision(r,s,a),n&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),n=new Map;for(let o=0;t.length>o;o+=1){if(!1===t[o].bodyCollisions)continue;const i=dg(t[o]),r=Math.floor(i.minX/e),s=Math.floor(i.maxX/e),a=Math.floor(i.minY/e),l=Math.floor(i.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;l>=e;e+=1){const i=`${t}:${e}`,r=n.get(i);r?r.push(o):n.set(i,[o])}}const o=new Set;for(const e of Array.from(n.keys()).sort()){const i=n.get(e)??[];i.sort((t,e)=>t-e);for(let e=0;i.length>e;e+=1)for(let n=e+1;i.length>n;n+=1){const r=i[e],s=i[n];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&fg(dg(t[r]),dg(t[s]))&&o.add(`${r}:${s}`)}}return Array.from(o).sort((t,e)=>{const[n,o]=t.split(":").map(Number),[i,r]=e.split(":").map(Number);return n===i?o-r:n-i})}resolveDynamicCollision(t,e,n){t.sleeping&&this.contactOpposesGravity(n.nx,n.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-n.nx,-n.ny)&&this.supportedThisStep.add(t.id);const o=t.sleeping?0:1/t.mass,i=e.sleeping?0:1/e.mass,r=o+i;if(og>=r)return;const s=Math.max(0,n.penetration-ig)/r;t.x-=n.nx*s*o,t.y-=n.ny*s*o,e.x+=n.nx*s*i,e.y+=n.ny*s*i;const a=(e.vx-t.vx)*n.nx+(e.vy-t.vy)*n.ny;if(a>0)return;const l=Math.abs(a),c=-(1+lg(t.restitution,e.restitution,this.options.restitution))*a/r,u=c*n.nx,d=c*n.ny;t.vx-=u*o,t.vy-=d*o,e.vx+=u*i,e.vy+=d*i,this.applyFriction(t,e,n,c,o,i),l>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,n,o,i,r){const s=-n.ny,a=n.nx,l=(e.vx-t.vx)*s+(e.vy-t.vy)*a,c=i+r;if(og>=Math.abs(l)||og>=c)return;const u=cg(t.friction,e.friction,this.options.friction),d=ag(-l/c,-o*u,o*u),h=d*s,f=d*a;t.vx-=h*i,t.vy-=f*i,e.vx+=h*r,e.vy+=f*r}resolveColliders(t,e,n){for(const o of t)for(const t of e){if(!Ag(t,o))continue;if(!fg(dg(o),hg(t)))continue;const e=mg(o,t);e&&(this.resolveStaticCollision(o,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(o.id),n&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,n){t.x+=n.nx*Math.max(0,n.penetration-ig),t.y+=n.ny*Math.max(0,n.penetration-ig);const o=t.vx*n.nx+t.vy*n.ny;if(0>o){const i=lg(t.restitution,e.restitution,this.options.restitution);t.vx-=(1+i)*o*n.nx,t.vy-=(1+i)*o*n.ny;const r=-n.ny,s=n.nx,a=t.vx*r+t.vy*s,l=cg(t.friction,e.friction,this.options.friction);t.vx-=a*r*l,t.vy-=a*s*l}}updateSensors(t){const e=new Set,n=this.sortedColliders().filter(t=>t.sensor);for(const o of t){const t=dg(o);for(const i of n){if(!Ag(i,o))continue;if(!fg(t,hg(i)))continue;if(!mg(o,i))continue;const n=bg(i.id,o.id);e.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:o.id,sensorId:i.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:n,bodyId:o}=xg(t);this.lastEvents.push({type:"sensor-exit",bodyId:o,sensorId:n})}this.activeSensors=e}updateSleeping(t,e){const n=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||n&&!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})))}contactOpposesGravity(t,e){const{x:n,y:o}=this.options.gravity,i=Math.hypot(n,o);return 1e-9>=i||-.2>(t*n+e*o)/i}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},_g=class{constructor(t={}){this.id="builtin",this.capabilities={...(new Mg).capabilities,engine:"builtin"},this.world=new Mg(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,n){this.world.applyImpulse(t,e,n)}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 Pg(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new _g(t)}(e)}var Cg=["binId","targetBin","category","windowIndex","lane","group"];function Lg(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 n=e-t.mean;t.mean+=n/t.count,t.m2+=n*(e-t.mean)}function Rg(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 Tg(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 Ig(t,e){if(null!=t[e])return t[e];const n=t.datum;return n&&"object"==typeof n?n[e]:void 0}function $g(t,e,n){return"function"==typeof t?t(e,n):"string"==typeof t?Ig(e,t):void 0}function Og(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function zg(t){const e=Rg(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:Rg(t.x),y:Rg(t.y),value:e}}var Fg=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 n=Og($g(this.config.binAccessor,t,e))??function(t){for(const e of Cg){const n=Og(Ig(t,e));if(n)return n}return"sediment"}(t),o=Og($g(this.config.labelAccessor,t,e))??n,i=function(t,e,n){if("number"==typeof t)return t;const o="function"==typeof t?t(e,n):"string"==typeof t?Ig(e,t):1,i="number"==typeof o?o:Number(o);return Number.isFinite(i)?i:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(n);return s||(s={id:n,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(n,s)),s.label=o,s.lastBodyId=t.id,s.lastDatum=t.datum,Lg(s.x,t.x),Lg(s.y,t.y),Lg(s.value,i),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),zg(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(zg)}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:Tg(e.x),y:Tg(e.y),value:Tg(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 Dg(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var Eg={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Ng={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Bg(t={},e=Ng){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 Wg(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function jg(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 Yg(t,e){if(null!=t[e])return t[e];const n=t.datum;return n&&"object"==typeof n?n[e]:void 0}function Xg(t){return{...Wg(t),sequence:t.sequence,spawnAt:t.spawnAt}}function Hg(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 Gg(t){return!1!==t&&{...t}}function qg(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function Vg(t){return{...t,gravity:{...t.gravity}}}function Ug(t,e,n,o){if("circle"===t.shape.type){const i=t.x-e,r=t.y-n,s=t.shape.radius+o,a=i*i+r*r;return a>s*s?null:a}const i=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(n-t.y)-t.shape.height/2,0),s=i*i+r*r;return s>o*o?null:s}function Kg(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Zg(t,e={}){const{idPrefix:n="plot",includeFloor:o=!0,includeCeiling:i=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:l=a}=e,c=[],u=t.x+t.width/2,d=t.y+t.height/2;return o&&c.push({id:n+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+l/2,width:t.width+2*a,height:l}}),i&&c.push({id:n+"-ceiling",shape:{type:"aabb",x:u,y:t.y-l/2,width:t.width+2*a,height:l}}),r&&c.push({id:n+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:d,width:a,height:t.height+2*l}}),s&&c.push({id:n+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:d,width:a,height:t.height+2*l}}),c}function Qg(t){const{idPrefix:e="bin",count:n,domainStart:o,domainStep:i,xScale:r,yTop:s,yBottom:a,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,l)}=t,p=[],g=s+(a-s)/2,y=Math.abs(a-s),m=c?n:n-1;if(u||c)for(let t=c?0:1;m>=t;t+=1){if(!u&&t>0&&n>t)continue;const s=r(o+t*i);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:g,width:l,height:y}})}if(null!=d)for(let t=0;n>t;t+=1){const n=o+t*i,s=n+i;if(s>=d)continue;const a=r(n),c=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,c)+l/2,y1:h,x2:Math.max(a,c)-l/2,y2:h,thickness:f}})}return p}import{quadtree as Jg}from"d3-quadtree";var ty=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,n,o,i,r=0){const s=this.ensure(t,e);if(!s)return null;let a=null,l=1/0;const c=Math.max(0,r)+this.maxSearchRadius,u=o-c,d=o+c,h=i-c,f=i+c;return s.visit((t,e,s,c,p)=>{if(u>c||e>d||h>p||s>f)return!0;if(t.length)return!1;let g=t;for(;g;){const t=g.data;if(t){const e=Ug(t,o,i,Math.max(0,r));null!=e&&(l>e||e===l&&n.indexOf(t.id)>n.indexOf(a?.id??""))&&(a=t,l=e)}g=g.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const n=t.readState();return 0===n.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=n.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=Jg().x(t=>t.x).y(t=>t.y).addAll(n),this.revision=e,this.tree)}},ey=["data","scene-geometry","data-paint","accessibility","evidence"],ny=["scene-geometry","data-paint","accessibility","evidence"],oy=["overlay","accessibility","evidence"],iy=(t,e)=>({retainedData:t,invalidations:e}),ry=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sy=["scene-geometry","data-paint","accessibility","evidence"],ay=[],ly={engine:iy("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:iy("preserve",sy),colliders:iy("preserve",sy),sediment:iy("preserve",sy),bodyBudget:iy("preserve",ry),bodyLimit:iy("preserve",ry),eviction:iy("preserve",ry),fixedDt:iy("preserve",ay),maxDeltaSeconds:iy("preserve",ay),maxSubsteps:iy("preserve",ay),settleStepLimit:iy("preserve",ay),timeScale:iy("preserve",ay),observation:iy("preserve",ay)},cy=iy("preserve",ry);function uy(t){let e="preserve";const n=new Set;for(const o of t){const t=ly[o]??cy;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)n.add(e)}return{retainedData:e,invalidations:n}}var dy=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function hy(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&dy.every(n=>t[n]===e[n])}function fy(t,e,n,o){return t||!e?"paused":n||!o?"running":"settled"}var py=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,n){if(n>0)return void(this.seconds=0);const o=t.readState(this.scratch),i=this.speed*this.speed;let r=!0;for(const t of o)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=i){r=!1;break}this.seconds=r?this.seconds+Math.max(0,e):0}},gy=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new ty,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Jn,this.simulationState="settled",this.visible=!0,this.quiescence=new py;const{bodyBudget:e,colliders:n,engine:o,kernel:i,observation:r,sediment:s,...a}=t;this.config={...Eg,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=o,this.observation=Bg(r),this.sediment=new Fg(s??!1),this.world=Pg(o,{fixedDt:this.config.fixedDt,...i}),this.quiescence.setKernelOptions(i),n&&this.world.setColliders(Hg(n))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(n=>"kernel"===n?!hy(t.kernel,e.kernel):t[n]!==e[n])}(t,this.configInput),{colliders:n,bodyBudget:o,engine:i,kernel:r,observation:s,sediment:a,...l}=t;if(this.config={...this.config,...l},void 0!==o&&(this.bodyBudget=o,!1===o&&(this.bodyBudgetObservationKey="ok")),i&&i!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=i,this.world=Pg(i,t.options),this.world.restore(t),this.revision+=1}if(r&&!hy(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.quiescence.setKernelOptions(e),this.revision+=1}s&&(this.observation=Bg(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(Hg(n)),this.revision+=1),this.configInput={...this.configInput,...t};const c=uy(e);this.updateResults.record({kind:"config",keys:e},c.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(Hg(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},uy(["colliders"]).invalidations)}enqueue(t,e){const n=Array.isArray(t)?t:[t],o=e?function(t,e={}){const n=jg(e.startAt)??0,o=e.pacing??"immediate";if("arrival"===o){const o=t.map((t,n)=>function(t,e,n){return"function"==typeof n?jg(n(t,e)):"string"==typeof n?jg(Yg(t,n)):jg(t.spawnAt)??jg(Yg(t,"arrivalTime"))??jg(Yg(t,"timestamp"))??jg(Yg(t,"time"))??jg(Yg(t,"eventTime"))}(t,n,e.timeAccessor)),i=o.filter(t=>null!=t),r=i.length>0?Math.min(...i):0,s=jg(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const i=o[e],s=null==i?0:Math.max(0,i-r);return{...Wg(t),spawnAt:n+s/a}})}if("object"==typeof o){const e=jg(o.ratePerSec);if(e&&e>0)return t.map((t,o)=>({...Wg(t),spawnAt:n+o/e}))}return t.map(t=>({...Wg(t),spawnAt:n}))}(n,{...e,startAt:e.startAt??this.elapsedSeconds}):n;for(const t of o)this.queue.push({...Wg(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(qg),o.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:o.length},o.length?ey:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(Wg(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},ey)}materializeDueSpawns(){const t=this.revision,e=[],n=[];return this.spawnDue(e,n),0===e.length||(this.observeBodyBudget(n),this.evictOverflow(n),this.syncSimulationState(n),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?ey:[])),e}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.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},ey)}tick(t){const e=this.revision,n=[],o=[],i=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,n,o,i,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(n,s);const l=this.observeBodyBudget(s),c=this.evictOverflow(s);o.push(...c.evicted),i.push(...c.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)),this.quiescence.refresh(this.world,a,n.length),(u>0||n.length>0||o.length>0||i.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,n,o,i,r,s,void 0,l);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?n.length||o.length||i.length?ey:ny:[]),d}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const n=this.revision,o=[],i=[],r=[],s=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,o,i,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(o,a);const l=this.observeBodyBudget(a),c=this.evictOverflow(a);i.push(...c.evicted),r.push(...c.sedimented),this.syncSimulationState(a),o.length>0&&this.quiescence.reset();const u=e?{spawned:o,evicted:i,sedimented:r,events:s,observations:a}:{spawned:o},{steps:d,budget:h}=function(t,e,n){let o,i=0;for(;e>i&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,n.observations),e.length>0){n.spawned.push(...e),o=t.observeBodyBudget(n.observations);const i=t.evictOverflow(n.observations);n.evicted?.push(...i.evicted),n.sedimented?.push(...i.sedimented)}t.step(t.fixedDt);const r=t.drainEvents();n.events&&(n.events.push(...r),t.observeKernelEvents(r,n.observations),t.observeSensorTransitions(n.observations)),i+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:i,budget:o}}(this.settleHost(),t,u),f=o.length+i.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,o,i,r,s,a??[],void 0,h??l);return this.updateResults.record({kind:"settle",count:d},this.revision===n?[]:f?ey:ny),p}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:n=0,binWidth:o=24,gap:i=2,maxHeight:r=80,value:s="count",x:a}=e,l=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const c=Math.max(0,t[s]/l*r),u=a?.(t,e)??e*(o+i);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:n-c,width:o,height:c,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,n=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:n,chartId:o,...i}=t,r={...i,timestamp:e??this.elapsedSeconds,chartType:n??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?oy:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?oy:[])}remove(t){const e=new Set(t),n=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 i=t.filter(t=>n.has(t)||o.has(t));return i.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:i,count:i.length},i.length?ey:[]),i}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},ny),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},ny)}applyImpulse(t,e,n){this.world.applyImpulse(t,e,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},ny)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,n,o)=>t.applyImpulse(e,n,o),clear:()=>t.clear(),hitTest:(e,n,o)=>t.hitTest(e,n,o),pause:()=>t.setPaused(!0),push:(e,n)=>t.enqueue(e,n),pushMany:(e,n)=>t.enqueue(e,n),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:Gg(this.bodyBudget),config:{...this.config,kernel:Vg(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Xg),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:Gg(t.bodyBudget??{}),kernel:Vg(t.world.options)},this.bodyBudget=Gg(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(Xg).sort(qg),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??fy(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"},ey)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const n=this.queue.shift();if(!n)return;this.spawnOne(n,e),t.push(n.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 n=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:n?.datum??t.datum,x:n?.x??t.x,y:n?.y??t.y},e)}result(t,e,n,o,i,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const l=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:i,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:l,sedimented:o,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,n){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);n.emit({type:"physics-settle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.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,n){const o=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===o.size&&0===e.size)return o;const i=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:o,bodyId:r}=Kg(e),s=n.observation.sensors[o],a=i.get(r);n.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.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 n of t)e.has(Kg(n).bodyId)&&t.delete(n)}(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)),n=Math.max(0,Math.floor(t.queuedBodies??0)),o=e+n,i=Dg(t.bodyLimit),r=Dg(t.engineMaxBodiesHint),s=function(t,e,n){if(!1===n)return;const o=Dg(n?.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}(i,r,t.options),a=null==i?0:Math.max(0,e-i),l=a>0?"overflow":null==s||s>o?"ok":"warning";return{action:"overflow"!==l?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:i,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:o,queuedBodies:n,state:l,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 n=`${e.state}:${e.action}`;return n===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=n,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=fy(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const n=this.simulationState;this.simulationState=e,function(t,e,n){n.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||n.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,simulationState:e,previousSimulationState:t})}(n,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:n,liveBodyOrder:o}=function(t,e,n,o,i,r){const s={evicted:[],sedimented:[],liveBodyOrder:i};if(!1===n)return s;const a=Math.max(0,Math.floor(o));if(!Number.isFinite(a))return s;const l=i.length-a;if(0>=l)return s;const c=function(t,e,n){if("sleeping-first"!==e)return n.slice();const o=new Map(t.readState().map(t=>[t.id,t.sleeping])),i=[],r=[];for(const t of n)o.get(t)?i.push(t):r.push(t);return[...i,...r]}(t,n,i),u=c.slice(0,l);if(0===u.length)return s;const d=function(t,e,n,o){const i=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of n){const n=i.get(t);if(!n)continue;const s=e.add(n);s&&(r.push(t),o.emit({type:"physics-sediment",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:t,datum:n.datum,x:n.x,y:n.y,binId:s.id,count:s.count,total:s.total}))}return r}(t,e,u,r);t.remove(u);const h=new Set(u);return{evicted:u,sedimented:d,liveBodyOrder:i.filter(t=>!h.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=o,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:n}}};import{scaleLinear as yy}from"d3-scale";function my(t){const{count:e,idPrefix:n,wallThickness:o,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const l=Math.min(r-1,a?.(e)??s),c=Math.max(1,r-l);return{id:`${n}-wall-${e}`,shape:{type:"aabb",x:i(e),y:l+c/2,width:o,height:c}}})}import{scaleLinear as by}from"d3-scale";function xy(t){if(Array.isArray(t)&&t.length>=2){const e=Kp(t[0]),n=Kp(t[1]);return null!=e&&null!=n?{x:e,y:n}:null}if(t&&"object"==typeof t){const e=t,n=Kp(e.x),o=Kp(e.y);return null!=n&&null!=o?{x:n,y:o}:null}return null}function vy(t){return Array.isArray(t)?t.map(xy).filter(t=>null!=t):[]}function wy(t,e,n){return"normalized"===n?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:Zp(t.x,e.plot.x,e.plot.x+e.plot.width),y:Zp(t.y,e.plot.y,e.plot.y+e.plot.height)}}function ky(t){let e=0;for(let n=1;t.length>n;n+=1)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e}function Sy(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const n=Zp(e,0,1)*ky(t);let o=0;for(let e=1;t.length>e;e+=1){const i=t[e-1],r=t[e],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(o+s>=n){const t=(n-o)/s;return{x:i.x+(r.x-i.x)*t,y:i.y+(r.y-i.y)*t}}o+=s}}return{...t[t.length-1]}}function Ay(t,e){const n=Sy(t,Math.max(0,e-.02)),o=Sy(t,Math.min(1,e+.02)),i=o.x-n.x,r=o.y-n.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function My(t,e,n){return Math.max(e,Math.min(n,t))}function _y(t,e,n,o,i,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:n,x2:o,y2:i,thickness:r.thickness??8}}}function Py(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,n=t.y,o=t.width,i=t.height,{type:"aabb",x:e,y:n,width:o,height:i}),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,n,o,i}function Cy(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...Py({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function Ly(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 Ry(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=t.size,o=Hp(n),i=Zp(t.ballRadius??6,2,18),r=t.seed??1,s=tg(r),a=t.idAccessor,l=t.stageAccessor??"stage",c=t.groupBy,u=t.groupLabelAccessor,d=t.workAccessor,h=t.radiusAccessor,f=t.groupCompletion??(c?"allAbsorbed":"none"),p=t.springStiffness??.28,g=t.springDamping??.72,y=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),b=function(t){const e=t.shape??"lane",n=Math.max(1,Math.round(t.width)),o=Math.max(1,Math.round(t.height)),i=t.padX??46,r=t.padY??72,s=i,a=n-i,l=r,c=o-Math.max(24,Math.round(.45*r)),u=(l+c)/2,d=Math.max(1,c-l),h=My(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,g=My(d*h+p,.06*d,.5*d),y=g/2,m=u-y,b=u+y,x=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=My(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 C=S.map((t,e)=>{const n=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:n,x1:o,x:(n+o)/2,width:o-n,y:u,height:d}}),L=C[A],R=L.x0,T=L.x1,I=(t,n)=>{if("lane"===e)return"top"===n?l:c;if("funnel"===e){const e=My((t-s)/Math.max(1,a-s),0,1);return"top"===n?l+(m-l)*e:c+(b-c)*e}if(R>=t){const e=My((t-s)/Math.max(1,R-s),0,1);return"top"===n?l+(m-l)*e:c+(b-c)*e}if(T>=t)return"top"===n?m:b;const o=My((t-T)/Math.max(1,a-T),0,1);return"top"===n?m+(l-m)*o:b+(c-b)*o},$=C.map(t=>{const e=Math.min(I(t.x0,"top"),I(t.x1,"top")),n=Math.max(I(t.x0,"bottom"),I(t.x1,"bottom"));return{...t,y:(e+n)/2,height:Math.max(1,n-e)}}),O={thickness:k,friction:v,restitution:w},z=[];"lane"===e?z.push(_y(x+"-top",s,l,a,l,O),_y(x+"-bottom",s,c,a,c,O),_y(x+"-left",s,l,s,c,{...O,thickness:Math.max(6,k-2)}),_y(x+"-right",a,l,a,c,{...O,thickness:Math.max(6,k)})):"funnel"===e?z.push(_y(x+"-top",s,l,a,m,O),_y(x+"-bottom",s,c,a,b,O),_y(x+"-left",s,l,s,c,{...O,thickness:Math.max(6,k-2)}),_y(x+"-right",a,m,a,b,{...O,thickness:Math.max(6,k)})):z.push(_y(x+"-left-top",s,l,R,m,O),_y(x+"-left-bottom",s,c,R,b,O),_y(x+"-center-top",R,m,T,m,O),_y(x+"-center-bottom",R,b,T,b,O),_y(x+"-right-top",T,m,a,l,O),_y(x+"-right-bottom",T,b,a,c,O),_y(x+"-left",s,l,s,c,{...O,thickness:Math.max(6,k-2)}),_y(x+"-right",a,l,a,c,{...O,thickness:Math.max(6,k)}));const F=t.membraneDampingScale??.5,D=s,E=Math.max(1,("bowtie"===e?R:a)-D),N=(t.membranes??[]).map(t=>{const e=D+My(t.offset,0,1)*E,n=t.width??18+18*t.cost,o=d-16,i=u+.25*(t.wobble??0);return{...t,x:e,y:i,width:n,height:o}}),B=!1===t.includeMembraneRegions?[]:N.map(t=>function(t){const e=t.dampingScale??.5,n=t.energyScale??1,o=My(t.cost,0,2);return{...Py({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:o,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o*e,energyDelta:-o*n}}({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??F,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:n,height:o,padX:i,padY:r,left:s,right:a,topY:l,bottomY:c,midY:u,centerLeft:R,centerRight:T,pinchHeight:g,pinchTop:m,pinchBottom:b,stages:$,membranes:N,colliders:z,regionEffects:B,boundaryY:I}}({width:n[0],height:n[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}),x=new Map(b.stages.map((t,e)=>[t.id,e])),v=new Map(b.stages.map(t=>[t.id,t])),w=b.stages[0].id,k=b.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 n={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{...Py({...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"}}({...n,kind:t.kind??"sink",force:Ly(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return o={...n,kind:t.kind??"force-field",force:Ly(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...Py({...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{...Py({...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}}({...n,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Ly(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...n.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,n=t.baseDamping??.08,o=t.dampingPerUnit??.12,i=t.energyPerUnit??0;return{...Py({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:n+e*o,energyDelta:i?-e*i:void 0,force:t.force}}({...n,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:Ly(t.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?Cy({...n,kind:t.kind??"force-field",force:Ly(t.force,14),damping:t.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):function(t){return{...Py({...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}}({...n,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(t,{x:e.x,y:b.midY,width:e.width,height:b.bottomY-b.topY})});A.unshift(Cy({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const M=new Map;for(const t of b.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const n=(a?Up(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",o=(Up(t,e,l)??w)+"",r=x.has(o)?o:w;M.set(r,(M.get(r)??0)+1);const s=c?(Up(t,e,c)??"")+"":void 0,f=s&&u?(Up(t,e,u)??s)+"":s,p=d?Kp(Up(t,e,d))??1:1,g=h?Kp(Up(t,e,h)):null,y=Zp(null!=g&&g>0?g:i,2,18);_.push({datum:t,id:n,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:y,index:e})});const P=new Map,C=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&&C.set(t.groupId,t.groupLabel)}const L=Zp(t.groupAnchorAlong??.55,.15,.9),R=b.left+(b.right-b.left)*L,T=Array.from(P.keys()),I=T.map((t,n)=>{const o=P.get(t)??[],i=T.length>1?b.topY+28+n/Math.max(1,T.length-1)*(b.bottomY-b.topY-56):b.midY;return function(t){const e=t.x??t.anchor?.x??0,n=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:n,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:n},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:C.get(t)??t,bodyIds:o,anchor:{x:R,y:i},x:R,y:i,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),$=function(t,e){const n=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],o=e.filter(t=>!n.has(t)),i=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},l=e.reduce((t,e)=>t+a(e),0),c=e.reduce((t,e)=>t+(n.has(e)?a(e):0),0),u=t.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?i>0:"threshold"===r?c>=(d??l):0===o.length),absorbed:i,total:e.length,absorbedValue:c,totalValue:l,threshold:d,missing:o}})}(I,_.filter(t=>S.has(t.stageId)).map(t=>t.id)),O=new Map(I.map(t=>[t.id,t])),z=_.map((t,e)=>{const n=v.get(t.stageId)??k,o=n.x+(s()-.5)*Math.min(24,.2*n.width),i=b.boundaryY(o,"top")+t.radius+10,r=b.boundaryY(o,"bottom")-t.radius-10,a=r>i?i+s()*Math.max(1,r-i):b.midY,l=y?o:b.left+18+e%7*4,c=y?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,u=[{target:{type:"point",x:o,y:a},restLength:.45*t.radius,stiffness:p,damping:g}];if(t.groupId){const e=O.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:l,y:c,vx:y?0:40+40*s(),vy:y?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:y?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}}}),F={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:b.colliders,fixedDt:1/60,maxSubsteps:8},D=b.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),E=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:F,initialSpawns:z,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:D,metadata:{kind:"process-flow",plot:o.plot,volume:b,stages:E,groups:I,groupCompletion:$,regionEffects:A}}}import{scaleLinear as Ty}from"d3-scale";function Iy(t,e,n){return bt(t,e,n)}function $y(t,e){const n=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>n&&St(n,t)||"#4e79a7":e=>{if(n){const t=St(n,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 Oy(t,e){const n=e.config??{},o=(e.sensors??[]).map(t=>({...t,sensor:!0})),i=[...e.colliders??[],...o],r=[...t.colliders??[],...n.colliders??[],...i];return{...t,...n,observation:{...t.observation,...n.observation},...r.length>0&&{colliders:r}}}function zy(t){const e=Wy(t);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:e.left,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:t.width-e.rightInset,y2:e.top,thickness:e.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:t.floorY,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-e.rightInset,y1:e.top,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}}]}function Fy(t,e,n,o){return n?"function"==typeof n?n(t,e):t[n]??o:o}function Dy(t){return`gauntlet:${t}:core`}function Ey(t,e){return`gauntlet:${t}:positive:${e}`}function Ny(t,e,n){return`gauntlet:${t}:negative:${e}:${n}`}var By={left:28,top:76,rightInset:30,thickness:8};function Wy(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return By;const n=Math.max(1,Math.min(t.width,e)),o=Math.max(2,.04*t.width);return{left:o,top:Math.max(2,.08*e),rightInset:o,thickness:Math.max(1,Math.min(4,.04*n))}}function jy(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Yy(t,e,n,o){const i=Wy(o),r=Math.max(2,n+2),s=i.top+i.thickness/2+r,a=o.floorY-r,l=(t,e,n)=>e>n?(e+n)/2:Math.max(e,Math.min(n,t));return{x:l(t,i.left+i.thickness/2+r,o.width-i.rightInset-i.thickness/2-r),y:l(e,s,a)}}function Xy(t,e,n=1){const o=[...t].sort((t,e)=>t.localeCompare(e)),i=Math.max(0,o.indexOf(e));return{angle:.82*-Math.PI+(o.length>1?i/(o.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*n}}function Hy(t,e,n){const o=t.activePositiveIds.reduce((t,n)=>t+(e.get(n)?.value??1),0),i=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(n.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*o-8*r-1.2*t.delay-5*i))}function Gy(t){const e=function(t,e,n){const[o,i]=t,r=220>o||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,l=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,l.length),u=.22*o,d=c>1?(.78*o-u)/(c-1):0,h=r?Math.max(Math.round(.12*o),.08*o+6):Math.max(Math.round(.14*o),110);return{crashY:a-(r?Math.min(n,Math.max(3,.22*i)):n),floorY:a,gates:l.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(u+e*d),width:t.width??Math.max(r?8:54,Math.round(.07*o))})),graveyardX:Math.round(o*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(o*(r?.82:.92)),startX:h,width:o}}(t.size??[900,520],t.gates,t.crashOffset??30),n=t.positiveProperties??[],o=new Map(n.map(t=>[t.id,t])),i=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,n,o,i){const r=Fy(t,e,n.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=o.map(t=>t.id),a=[...Fy(t,e,n.positiveAccessor,s)],l=[...Fy(t,e,n.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Fy(t,e,n.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Fy(t,e,n.startTimeAccessor,0))||0),stage:"project filed",viability:Fy(t,e,n.initialViability,100)}}(e,s,r,n,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:o})??Hy(a,o,i)}}),a=s.flatMap((n,r)=>{const s=function(t,e,n,o){const i=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(n),r=o?.(t,e,n)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(n,r,e,t.projectPlacement);return function(t,e,n,o,i,r,s){const a=jy(n),l=Math.max(3,28*a),c=o.startX,u=o.startY+(o.startY===n.routeY?38*e*a:0),d=s?.(t,e,n,o)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},g=[{...d,id:Dy(t.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??t.startedAt,datum:p}],y=Yy(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,n);g[0].x=y.x,g[0].y=y.y;for(const e of t.activePositiveIds){const o=i.get(e);if(!o)continue;const r=Xy(t.activePositiveIds,e,a),s=o.radius??Math.max(2,10*a),l=Yy(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,n);g.push({id:Ey(t.id,e),x:l.x,y:l.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:d.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:Dy(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...o.spring??{}}]})}return t.negativeIds.forEach((e,o)=>{const i=r.get(e);i&&g.push(function(t,e,n,o,i,r,s){const a=jy(r),l=e.radius??Math.max(2,7.2*a),c=Yy(o+(n%4*12-12)*a,i+(54+12*Math.floor(n/4))*a,l,r);return{id:Ny(t.id,e.id,n),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:Dy(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+n%4*3)*a),...e.spring??{}}]}}(t,i,o,y.x,y.y,n,d.spawnAt??t.startedAt))}),g}(n,r,e,s,o,i,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:zy(e)}}}var qy=1e-9;function Vy(t,e){return e>t?-1:t>e?1:0}function Uy(t){return{...t}}function Ky(t){return t.map(t=>({...t,sourceIds:t.sourceIds?[...t.sourceIds]:void 0,productIds:t.productIds?[...t.productIds]:void 0,relationIds:t.relationIds?[...t.relationIds]:void 0,outletIds:t.outletIds?[...t.outletIds]:void 0}))}function Zy(t){const e=Object.fromEntries(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:Uy(e.initialMetrics),metrics:Uy(e.metrics),productIds:[...e.productIds],history:Ky(e.history)}])),n=Object.fromEntries(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:Uy(e.metrics),sourceIds:[...e.sourceIds],history:Ky(e.history)}])),o=Object.fromEntries(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?Uy(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:n,relations:o,input:{amount:t.input.amount,metrics:Uy(t.input.metrics)},metrics:Uy(t.metrics),loss:{amount:t.loss.amount,metrics:Uy(t.loss.metrics)},history:Ky(t.history)}}function Qy(t,e,n,o,i){return{severity:t,code:e,message:n,path:o,ids:i?[...i]:void 0}}function Jy(t){const e=new Set,n=new Set;for(const o of t)e.has(o)&&n.add(o),e.add(o);return[...n].sort(Vy)}function tm(t,e){return t?Object.entries(t).flatMap(([t,n])=>Number.isFinite(n)?[]:[Qy("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function em(t,e){for(const[n,o]of Object.entries(e))t[n]=Number(t[n]??0)+o}function nm(t,e,n="selector"){const o=[],i=Object.values(t.components),r=new Set(i.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&o.push(Qy("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,n+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||o.push(Qy("error","invalid-selector-count","Selector count must be a non-negative integer.",n+".count")),o.some(t=>"error"===t.severity))return{ids:[],diagnostics:o};const a=e.ids?new Set(e.ids):null,l=e.categories?new Set(e.categories):null,c=e.statuses?new Set(e.statuses):null,u=e.outletIds?new Set(e.outletIds):null;let d=i.filter(t=>!a||a.has(t.id)).filter(t=>!l||l.has(t.category)).filter(t=>!c||c.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Vy);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||o.push(Qy("warning","empty-selector","Selector matched no source components.",n)),{ids:d,diagnostics:o}}function om(t,e,n={}){return{eventId:t.event.id,effectType:e.type,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,label:t.event.label,summary:t.event.summary,...n}}function im(t,e){const n={...e,eventId:t.event.id};t.materializations.push(n),t.observations.push({...n,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function rm(t,e,n){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Qy("error","unknown-outlet",`Unknown outlet "${e}".`,n,[e])),1))}function sm(t,e,n){const o=Jy(e);e.length||t.diagnostics.push(Qy("error","empty-source-list","A product requires at least one source component.",n)),o.length&&t.diagnostics.push(Qy("error","duplicate-source",`Source ids may appear only once: ${o.join(", ")}.`,n,o));const i=e.filter(e=>!t.state.components[e]);i.length&&t.diagnostics.push(Qy("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,n,i));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(Qy("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,n,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(Qy("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,n,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function am(t,e,n,o,i){const r=o?.amount??0;(!Number.isFinite(r)||0>r||r>e+qy)&&t.diagnostics.push(Qy("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...tm(o?.metrics,i+".metrics"));for(const[e,r]of Object.entries(o?.metrics??{}))(0>r||r>Number(n[e]??0)+qy)&&t.diagnostics.push(Qy("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${i}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function lm(t,e,n,o,i,r,s){return{id:t.id,label:t.label??t.id,description:t.description,category:t.category??"product",color:t.color,order:t.order,declaredAmount:t.amount,amount:r&&void 0!==t.amount?t.amount:n,metrics:r&&t.metrics?{...o,...t.metrics}:o,status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(i.outletIds.has("product")?"product":void 0):void 0,createdByEventId:i.event.id,createdAt:i.context.appliedAt,completedByEventId:r?i.event.id:void 0,completedAt:r?i.context.appliedAt:void 0,history:[s]}}function cm(t,e,n,o){void 0!==e.amount&&Math.abs(e.amount-n)>qy&&t.diagnostics.push(Qy("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${n}.`,o,[e.id]))}function um(t,e,n){const o=`events.${t.event.id}.effects.${n}`,i=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(Qy("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,o+".state")),t.diagnostics.push(...tm(e.metricsDelta,o+".metricsDelta")),rm(t,e.outletId,o+".outletId");const n=nm(i,e.select,o+".select");t.diagnostics.push(...n.diagnostics);const r=n.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qy("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,o+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=om(t,e,{sourceIds:n.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of n.ids){const n=i.components[t];n.status=e.state,n.outletId=e.outletId,n.reason=e.reason,e.metricsDelta&&em(n.metrics,e.metricsDelta),n.history.push(s)}return i.history.push(s),void(n.ids.length&&im(t,{type:"retarget-component",sourceIds:n.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:n}=e;n.id&&!i.relations[n.id]||t.diagnostics.push(Qy("error","duplicate-relation",`Relation id "${n.id}" is missing or already active.`,o+".relation.id",[n.id]));const r=function(t,e,n){const o=Jy(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Qy("error","insufficient-relation-sources","A relation requires at least two source components.",n)),o.length&&t.diagnostics.push(Qy("error","duplicate-source",`Relation source ids must be unique: ${o.join(", ")}.`,n,o)),i.length&&t.diagnostics.push(Qy("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,n,i)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,n.sourceIds,o+".relation.sourceIds");if(t.diagnostics.push(...tm(n.metrics,o+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;i.relations[n.id]={...n,sourceIds:[...n.sourceIds],metrics:n.metrics?{...n.metrics}:void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=om(t,e,{sourceIds:[...n.sourceIds],relationIds:[n.id]});return i.history.push(s),void im(t,{type:"activate-relation",sourceIds:[...n.sourceIds],relationIds:[n.id]})}if("resolve-relation"===e.type){const n=Jy(e.relationIds),r=e.relationIds.filter(t=>!i.relations[t]),s=e.relationIds.filter(t=>"resolved"===i.relations[t]?.status);if(n.length&&t.diagnostics.push(Qy("error","duplicate-relation","Relation ids must be unique.",o+".relationIds",n)),r.length&&t.diagnostics.push(Qy("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,o+".relationIds",r)),s.length&&t.diagnostics.push(Qy("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,o+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const n of e.relationIds){const o=i.relations[n];o.status="resolved",o.resolution=e.resolution,o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt,o.reason=e.reason}const a=om(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void im(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const n=t.productDefinitions.get(e.productId);n||t.diagnostics.push(Qy("error","unknown-product",`Product "${e.productId}" has no declared mold.`,o+".productId",[e.productId]));const r=i.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(Qy("error","duplicate-product",`Product "${e.productId}" has already been formed.`,o+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Qy("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,o+".productId",[e.productId]));const s=sm(t,e.sourceIds,o+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,l=function(t,e,n,o){if(!e?.length)return[];const i=Jy(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(n),l=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(Qy("error","duplicate-relation","Basis relations must be unique.",o,i)),r.length&&t.diagnostics.push(Qy("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,o,r)),s.length&&t.diagnostics.push(Qy("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,o,s)),l.length&&t.diagnostics.push(Qy("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,o,l)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,o+".basisRelationIds");if(!s||!l||!n||t.diagnostics.some(t=>"error"===t.severity))return;const c=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e={};for(const n of t)em(e,n.metrics);return e}(s);if(!am(t,c,u,e.loss,o+".loss"))return;const d=c-(e.loss?.amount??0);!function(t,e,n){t.state.loss.amount+=n?.amount??0;for(const[o,i]of Object.entries(n?.metrics??{}))e[o]=Number(e[o]??0)-i,t.state.loss.metrics[o]=Number(t.state.loss.metrics[o]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=om(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&cm(t,n,d,o+".productId"),p=lm(n,e.sourceIds,d,u,t,h,f),h&&!rm(t,p.outletId,o+".productId"))return;i.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,em(p.metrics,u),p.history.push(f);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(f);return i.history.push(f),function(t,e){if(e.length){for(const n of e)n.status="resolved",n.resolution="combined",n.resolvedByEventId=t.event.id,n.resolvedAt=t.context.appliedAt;im(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),im(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:p.outletId?[p.outletId]:void 0}),void(h&&im(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const n=i.products[e.productId];return n?void function(t,e,n,o,i,r){const s=t.productDefinitions.get(e.id),a=n??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!rm(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Qy("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(cm(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics={...e.metrics,...s.metrics})),e.status="complete",e.outletId=a,e.reason=o,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const l=om(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),im(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,n,e.outletId,e.reason,e,o):void t.diagnostics.push(Qy("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,o+".productId",[e.productId]))}if("split"===e.type){const n=sm(t,[e.sourceId],o+".sourceId");e.products.length||t.diagnostics.push(Qy("error","empty-split","A split requires at least one product allocation.",o+".products"));const r=e.products.map(t=>t.productId),s=Jy(r);s.length&&t.diagnostics.push(Qy("error","duplicate-product","Split product ids must be unique.",o+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),l=r.filter((t,e)=>!a[e]),c=r.filter(t=>i.products[t]);l.length&&t.diagnostics.push(Qy("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,o+".products",l)),c.length&&t.diagnostics.push(Qy("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,o+".products",c));for(const[n,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(Qy("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${o}.products.${n}.amount`)),t.diagnostics.push(...tm(i.metrics,`${o}.products.${n}.metrics`));if(!n?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=n[0];if(!am(t,u.amount,u.metrics,e.loss,o+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),f=h.filter(t=>void 0!==t).length;if(0!==f&&f!==h.length)return void t.diagnostics.push(Qy("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",o+".products"));const p=f?h:e.products.map(()=>d/e.products.length),g=p.reduce((t,e)=>t+e,0);if(Math.abs(g-d)>qy)return void t.diagnostics.push(Qy("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,o+".products"));const y={...u.metrics};for(const[t,n]of Object.entries(e.loss?.metrics??{}))y[t]=Number(y[t]??0)-n;const m=om(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((n,r)=>{const s=a[r],l=d>qy?p[r]/d:1/e.products.length,c=Object.fromEntries(Object.entries(y).map(([t,e])=>[t,e*l])),h=n.metrics??s.metrics??c,f=lm({...s,amount:p[r],metrics:h},[u.id],p[r],{...h},t,!0,m);rm(t,f.outletId,`${o}.products.${r}.productId`)&&(i.products[f.id]=f)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=e.loss?.amount??0;for(const[t,n]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+n;i.history.push(m),im(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)im(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:i.products[e].outletId?[i.products[e].outletId]:void 0});return}if("eject"===e.type){rm(t,e.outletId,o+".outletId");const n=nm(i,e.select,o+".select");t.diagnostics.push(...n.diagnostics);const r=n.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qy("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,o+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=om(t,e,{sourceIds:n.ids,outletIds:[e.outletId]});for(const t of n.ids){const n=i.components[t];n.status=e.state??"ejected",n.outletId=e.outletId,n.reason=e.reason,n.history.push(s)}return i.history.push(s),void(n.ids.length&&im(t,{type:"retarget-component",sourceIds:n.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...tm(e.metricsDelta,o+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let n,r;if("run"===e.target)em(i.metrics,e.metricsDelta);else if("components"in e.target){const r=nm(i,e.target.components,o+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;n=r.ids;for(const t of r.ids)em(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const n=Jy(r),s=r.filter(t=>!i.products[t]);if(n.length&&t.diagnostics.push(Qy("error","duplicate-product","Metric target product ids must be unique.",o+".target.productIds",n)),s.length&&t.diagnostics.push(Qy("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,o+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)em(i.products[t].metrics,e.metricsDelta)}return void i.history.push(om(t,e,{sourceIds:n,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(om(t,e)),t.observations.push({type:"crucible-outcome",eventId:t.event.id,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,outcome:e.outcome})):t.diagnostics.push(Qy("error","invalid-outcome","Outcome must be a non-empty string.",o+".outcome"))}function dm(t,e,n){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Qy("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const o=Zy(t),i={state:o,event:e,context:n,productDefinitions:new Map(n.products.map(t=>[t.id,t])),outletIds:new Set(n.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[n,o]of e.effects.entries())if(um(i,o,n),i.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:i.diagnostics};return o.elapsed=Math.max(o.elapsed,n.appliedAt),o.phaseId=n.phaseId,o.eventsApplied.push(e.id),i.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:n.phaseId,authoredAt:n.authoredAt,appliedAt:n.appliedAt}),{applied:!0,state:o,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var hm=[900,520],fm=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],pm=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),gm=1e-9;function ym(t,e){return e>t?-1:t>e?1:0}function mm(t,e,n,o,i){return{severity:t,code:e,message:n,path:o,ids:i?[...i]:void 0}}function bm(t){const e=new Set,n=new Set;for(const o of t)e.has(o)&&n.add(o),e.add(o);return[...n].sort(ym)}function xm(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function vm(t,e,n,o,i,r){if(!n)return o;try{return("function"==typeof n?n(t,e):t[n])??o}catch(t){return i.push(mm("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),o}}function wm(t,e,n){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(mm("error","invalid-metrics","Metrics must be a numeric object.",n)),{};const o={};for(const[i,r]of Object.entries(t)){const t=xm(r);null!=t?o[i]=t:e.push(mm("error","invalid-metric",`Metric "${i}" must be finite.`,`${n}.${i}`))}return o}function km(t){return t.map((t,e)=>({outlet:t,index:e})).sort((t,e)=>(t.outlet.order??t.index)-(e.outlet.order??e.index)||t.index-e.index).map(({outlet:t})=>({...t}))}function Sm(t){const{id:e,orientation:n,fixed:o,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=t,u=function(t,e,n){const o=n.map(([n,o])=>[Math.max(t,Math.min(n,o)),Math.min(e,Math.max(n,o))]).filter(([t,e])=>e>t+gm).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of o)t>r+gm&&i.push([r,t]),r=Math.max(r,e);return e>r+gm&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:l,restitution:c,shape:"horizontal"===n?{type:"segment",x1:t,y1:o,x2:i,y2:o,thickness:a}:{type:"segment",x1:o,y1:t,x2:o,y2:i,thickness:a}}))}function Am(t){let e=2166136261;for(let n=0;t.length>n;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function Mm(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Am(t):1}function _m(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Mm(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Pm(t){return"crucible:component:"+encodeURIComponent(t)}function Cm(t,e,n,o){if(void 0!==n&&Number.isFinite(n)&&n>0)return n;const i=Math.min(...e,t),r=Math.max(...e,t);return r-i>gm?o[0]+(o[1]-o[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(o[0]+o[1])/2}function Lm(t,e){const n=Math.max(.25,Math.min(1,e.width/900,e.height/520)),o=t?.[0]??7*n,i=t?.[1]??18*n,r=Math.max(1,Math.min(o,i));return[r,Math.max(r,Math.max(o,i))]}function Rm(t,e){if(!t)return[];const n=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),o=Math.max(1,Math.ceil(t/n));return Array.from({length:t},(t,i)=>({x:e.x+e.width/n*(i%n+.5),y:e.y+(Math.floor(i/n)+.5)*(e.height/o)}))}function Tm(t){return t.outletId?t.outletId:"failed"===t.status?"failed":"recovered"===t.status?"recovered":"retained"===t.status?"retained":"ejected"===t.status?"residue":void 0}function Im(t,e){return t.outlets.find(t=>t.id===e)||{x:t.chamber.x+.18*t.chamber.width,y:t.chamber.y+.2*t.chamber.height,width:.64*t.chamber.width,height:.6*t.chamber.height}}function $m(t,e,n={}){const o=Object.values(t.products).sort((t,e)=>ym(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>ym(t.id,e.id)),r=[...i.map(t=>t.amount),...o.map(t=>t.amount)],s=Lm(n.radiusRange,e),a=function(t,e){const n=new Map;for(const e of t){const t=e.outletId??"__chamber__",o=n.get(t)??[];o.push(e),n.set(t,o)}const o=new Map;for(const[t,i]of n){i.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||ym(t.id,e.id));const n=Rm(i.length,Im(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>o.set(t.id,n[e]))}return o}(o,e),l=o.map(t=>{const o=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},i=1.28*Cm(t.amount,r,n.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(c=t.id,"crucible:product:"+encodeURIComponent(c)),x:o.x,y:o.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=Tm(t)??"__chamber__",n=c.get(e)??[];n.push(t),c.set(e,n)}const u=new Map;for(const[t,n]of c){const o=Rm(n.length,Im(e,"__chamber__"===t?void 0:t));n.forEach((t,e)=>u.set(t.id,o[e]))}return[...i.map(t=>{let o=u.get(t.id);if(t.productIds.length){const n=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(n.length){o={x:n.reduce((t,e)=>t+e.x,0)/n.length,y:n.reduce((t,e)=>t+e.y,0)/n.length};const i=Am(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));o={x:o.x+Math.cos(i)*r,y:o.y+Math.sin(i)*r}}}o??(o={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const i=Cm(t.amount,r,n.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Pm(t.id),x:o.x,y:o.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var Om=$m;function zm(t){return Array.isArray(t)?t.map(zm):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>ym(t,e)).map(([t,e])=>[t,zm(e)])):t}function Fm(t,e=t.duration){const n=function(t,e){const n=xm(e)??0,o=Math.max(0,Math.min(t.duration,n));if(!t.phases.length)return{elapsed:o,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=o>=t.duration-gm,r=i?t.phases[t.phases.length-1]:t.phases.find(t=>o>=t.start&&t.end>o)??t.phases[0];return{elapsed:o,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,o-r.start),complete:i}}(t,e);let o=Zy(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>n.elapsed+gm)break;const a=dm(o,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(o=a.state)}return o.elapsed=n.elapsed,o.phaseId=n.phaseId,o.phaseIndex=n.phaseIndex,o.phaseElapsed=n.phaseElapsed,o.complete=n.complete,n.complete&&"in_process"===o.outcome&&(o.outcome="complete"),o.playing=!1,{state:o,diagnostics:i,materializations:r,observations:s}}function Dm(t){const e=function(t){const e=[];t.length||e.push(mm("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const n=bm(t.map(t=>t.id));n.length&&e.push(mm("error","duplicate-phase-id",`Phase ids must be unique: ${n.join(", ")}.`,"phases",n));let o=0;return{phases:t.map((t,n)=>{const i=xm(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(mm("error","invalid-phase-id","Phase ids may not be empty.",`phases.${n}.id`)),null!=i&&i>0||e.push(mm("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${n}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(mm("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${n}.intensity`,[t.id]));const s={...t,duration:r,intensity:void 0===t.intensity?.5:Number.isFinite(t.intensity)?Math.max(0,Math.min(1,t.intensity)):.5,motion:t.motion??"hold",index:n,start:o,end:o+r};return o=s.end,s}),diagnostics:e}}(t.phases),n=e.phases.at(-1)?.end??0,o=km(t.outlets??fm),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?{...t.metrics}:void 0})),r=function(t,e,n){const o=[],i=bm(t.map(t=>t.id));i.length&&o.push(mm("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,l;if(t.id.trim()||o.push(mm("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=xm(t.at.time);if(null==r||0>r||r>n+gm)return void o.push(mm("error","event-time-out-of-range",`Event time must fall between 0 and ${n}.`,`events.${i}.at.time`,[t.id]));s=Math.max(0,Math.min(n,r));const c=function(t,e,n){const o=t.find(t=>gm>=Math.abs(t.start-n));if(o)return{phase:o,boundaryRank:1};const i=t.find(t=>n>=t.start&&t.end>n);return i?{phase:i,boundaryRank:0}:gm>=Math.abs(n-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,n,s);a=c.phase,l=c.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void o.push(mm("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${i}.at.phaseId`,[t.id,t.at.phaseId]));const n=t.at.progress??0;if(!Number.isFinite(n)||0>n||n>1)return void o.push(mm("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[t.id]));s=a.start+a.duration*n,l=0===n?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):o.push(mm("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:o}}(t.events??[],e.phases,n),s=function(t){const e=[],n={},o=[];let i=0;const r={};t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((vm(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(mm("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));o.push(c);const u=xm(vm(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(mm("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=wm(vm(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=vm(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=pm.has(f)?f:"active";pm.has(f)||e.push(mm("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[c]));const g=vm(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",y=vm(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";n[c]||(n[c]={id:c,label:g,category:y,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},i+=d,function(t,e){for(const[n,o]of Object.entries(e))t[n]=Number(t[n]??0)+o}(r,h))});const s=bm(o);s.length&&e.push(mm("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=wm(t.metrics??{},e,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:t.phases[0]?.id??"",phaseIndex:t.phases.length?0:-1,playing:!1,complete:0===t.phases.length,outcome:"in_process",eventsApplied:[],components:n,products:{},relations:{},input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:e}}(t),a=function(t=hm,e=fm){const n=Math.max(1,xm(t[0])??900),o=Math.max(1,xm(t[1])??520),i=360>n||260>o,r=i?Math.max(4,.035*Math.min(n,o)):20,s=i?Math.max(10,.075*o):34,a={x:r,y:r,width:Math.max(1,n-2*r),height:s},l=i?Math.max(16,.14*o):Math.min(78,.16*o),c={x:r,y:o-r-l,width:Math.max(1,n-2*r),height:l},u=i?Math.max(12,.08*n):Math.min(150,.17*n),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),f={x:u,y:d,width:Math.max(24,n-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,i?84:180)),g={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},y=km(e),m={left:y.filter(t=>"left"===(t.side??"bottom")),right:y.filter(t=>"right"===t.side),bottom:y.filter(t=>"bottom"===(t.side??"bottom"))},b=[],x=(t,e)=>{const o=Math.max(8,u-1.5*r),s=f.height/Math.max(1,e.length);e.forEach((e,a)=>{b.push({...e,side:t,x:"left"===t?r:n-r-o,y:f.y+a*s,width:o,height:Math.max(8,s-(i?2:8))})})};x("left",m.left),x("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{b.push({...t,side:"bottom",x:f.x+e*v,y:f.y+f.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-f.y-f.height-(i?4:12))})}),b.sort((t,e)=>y.findIndex(e=>e.id===t.id)-y.findIndex(t=>t.id===e.id)),{width:n,height:o,phaseRail:a,chamber:f,mouth:g,projection:c,outlets:b}}(t.size??hm,o),l=function(t){const{chamber:e,mouth:n}=t,o=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),i=Math.max(e.x,n.x),r=Math.min(e.x+e.width,n.x+n.width),s={left:t.outlets.filter(t=>"left"===t.side),right:t.outlets.filter(t=>"right"===t.side),bottom:t.outlets.filter(t=>"bottom"===t.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:e.x,y1:e.y,x2:i,y2:e.y,thickness:o}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:e.y,x2:e.x+e.width,y2:e.y,thickness:o}}];a.push(...Sm({id:"crucible:wall:left",orientation:"vertical",fixed:e.x,start:e.y,end:e.y+e.height,openings:s.left.map(t=>[t.y,t.y+t.height]),thickness:o,friction:.46,restitution:.12}),...Sm({id:"crucible:wall:right",orientation:"vertical",fixed:e.x+e.width,start:e.y,end:e.y+e.height,openings:s.right.map(t=>[t.y,t.y+t.height]),thickness:o,friction:.46,restitution:.12}),...Sm({id:"crucible:wall:bottom",orientation:"horizontal",fixed:e.y+e.height,start:e.x,end:e.x+e.width,openings:s.bottom.map(t=>[t.x,t.x+t.width]),thickness:o,friction:.5,restitution:.08}));for(const e of t.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(e.id),sensor:!0,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}});return a}(a),c=function(t,e){const n=[],o=new Set(e.map(t=>t.id)),i=bm(e.map(t=>t.id)),r=bm(t.map(t=>t.id));return i.length&&n.push(mm("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&n.push(mm("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||n.push(mm("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||n.push(mm("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||n.push(mm("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||n.push(mm("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||o.has(t.outletId)||n.push(mm("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),wm(t.metrics??{},n,`products.${e}.metrics`)}),n}(i,o),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>ym(t.id,e.id)).map(t=>({id:t.id,label:t.label,category:t.category,amount:t.amount,metrics:t.metrics,status:t.status})),phases:e.phases.map(({id:t,duration:e,label:n,description:o,intensity:i,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:n,description:o,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:o,events:r.events.map(({id:t,label:e,description:n,summary:o,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:n,summary:o,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(zm(d)));var d;const h=function(t,e,n={}){const o=Object.values(t.components).sort((t,e)=>ym(t.id,e.id)),i=o.map(t=>t.amount),r=Lm(n.radiusRange,e),s=function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(Mm(n.seed)),a=e.mouth.x+e.mouth.width/2,l=e.chamber.y+Math.max(18,.18*e.chamber.height),c=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return o.map((t,e)=>{const d=e/Math.max(1,o.length)*Math.PI*2+.18*(s()-.5),h=Cm(t.amount,i,n.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Pm(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...c],p={phases:e.phases,events:r.events,products:i,outlets:o,duration:n,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:_m(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},g=Fm(p),y=Object.values(g.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=y.length?[mm("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return p.terminalState=g.state,p.terminalSpawns=Om(g.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...g.diagnostics,...m],p}import*as Em from"react";import{jsx as Nm,jsxs as Bm}from"react/jsx-runtime";function Wm(t){return Number.isFinite(t)?1e3>Math.abs(t)?Number.isInteger(t)?t+"":t.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):t.toLocaleString():"0"}function jm(t,e,n,o){const i=t.datum;if(!i?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof e.stroke?e.stroke:"#26323a",l="number"==typeof e.strokeWidth?e.strokeWidth:1.25,c="number"==typeof e.opacity?e.opacity:.96,u=o?`${o}-crucible-body-${n}`:"crucible-body-"+n;if("product"===i.kind){const e=Array.from({length:6},(e,n)=>{const o=-Math.PI/2+n/6*Math.PI*2;return`${t.x+Math.cos(o)*r},${t.y+Math.sin(o)*r}`}).join(" "),n=u+"-glow";return Bm(Em.Fragment,{children:[Nm("defs",{children:Nm("filter",{id:n,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Nm("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Nm("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${n})`}),Nm("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return Bm(Em.Fragment,{children:[Nm("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),Nm("circle",{cx:t.x-.25*r,cy:t.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as Ym,jsx as Xm,jsxs as Hm}from"react/jsx-runtime";var Gm="var(--semiotic-text, #26323a)",qm="var(--semiotic-text-secondary, #6c7377)",Vm="var(--semiotic-primary, #b8792d)",Um="var(--semiotic-danger, #9f3d35)",Km="var(--semiotic-success, #356b63)";function Zm(t){const{x:e,y:n,width:o,height:i}=t.chamber,r=Math.min(.14*o,48),s=n+i;return[`M ${e} ${n}`,`L ${e+r} ${s-.16*i}`,`Q ${e+o/2} ${s+.1*i} ${e+o-r} ${s-.16*i}`,`L ${e+o} ${n}`].join(" ")}function Qm({layout:t,phases:e,state:n,compact:o=!1}){const i=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return Hm("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[Hm("defs",{children:[Hm("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[Xm("stop",{offset:"0",stopColor:Vm,stopOpacity:"0.03"}),Xm("stop",{offset:"0.66",stopColor:Vm,stopOpacity:"0.1"}),Xm("stop",{offset:"1",stopColor:Um,stopOpacity:"0.18"})]}),Xm("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:Xm("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Gm,strokeOpacity:"0.08",strokeWidth:"1"})})]}),Xm("rect",{x:t.chamber.x,y:t.chamber.y,width:t.chamber.width,height:t.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:Gm,strokeOpacity:"0.52",strokeWidth:o?1:2.2}),Xm("path",{d:Zm(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),Xm("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Gm,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:o?2:5}),o?null:Xm("g",{"data-testid":"crucible-phase-rail",children:e.map((o,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/i*t.phaseRail.width,l=Math.max(0,o.duration)/i*t.phaseRail.width,c=o.id===n.phaseId,u=n.phaseIndex>r||n.complete;return Hm("g",{children:[Xm("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?o.color??Vm:u?Km:Gm,fillOpacity:c?.68:u?.28:.09}),46>l?null:Xm("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?Gm:qm,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(o.label??o.id).toUpperCase()})]},o.id)})}),t.outlets.map(t=>Hm("g",{children:[Xm("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?Um:Km),fillOpacity:"0.1",stroke:t.color??("left"===t.side?Um:Km),strokeDasharray:"3 3",strokeOpacity:"0.62"}),o?null:Xm("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:qm,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function Jm({rows:t,layout:e,projection:n,amountLabel:o}){if(!t.length)return null;const i=n.measure??"count",r=t.map(t=>Math.max(0,function(t,e){return"count"===e?t.count:"amount"===e?t.amount:Number(t.metrics[e]??0)}(t,i))),s=Math.max(1,...r),a=e.projection.width/Math.max(1,t.length),l=e.projection.height>48?21:4,c=Math.max(5,e.projection.height-l-5);return Xm("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:t.map((t,n)=>{const u=r[n],d=Math.max(u>0?2:0,u/s*c),h=e.projection.x+n*a+.18*a;return Hm("g",{children:[Xm("rect",{x:h,y:e.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?Um:"complete"===t.status?Vm:Km,fillOpacity:"0.68"}),l>4&&a>=34?Hm(Ym,{children:[Xm("text",{x:h+.32*a,y:e.projection.y+c+10,fill:qm,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),Hm("text",{x:h+.32*a,y:e.projection.y+c+19,fill:Gm,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Wm(u),"amount"===i&&o?" "+o:""]})]}):null]},t.key)})})}function tb(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 eb(t){return t.map(t=>({...t,spawnAt:void 0}))}function nb(t,e){return t?e?n=>Xp.createElement(Xp.Fragment,null,t,"function"==typeof e?e(n):e):t:e}var ob=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function ib(t){let e=2166136261;for(let n=0;t.length>n;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return ob[(e>>>0)%ob.length]}var rb={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,n,o,i)=>({chartType:"line",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||e,colorAccessor:e,...o,showAxes:!1,margin:o.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:oh,LineChart:rh,AreaChart:ah,DifferenceChart:lh,StackedAreaChart:ch,Scatterplot:dh,CandlestickChart:uh,BubbleChart:nh,ConnectedScatterplot:fh,QuadrantChart:hh,Heatmap:ph,TemporalHistogram:sh,XYCustomChart:{frameType:"xy",buildProps:(t,e,n,o,i)=>({chartType:"custom",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:o.showLegend??!!e})},BarChart:Eh,StackedBarChart:Nh,GroupedBarChart:Bh,PieChart:Wh,DonutChart:jh,Histogram:Yh,BoxPlot:Xh,ViolinPlot:Hh,SwarmPlot:Gh,DotPlot:qh,SwimlaneChart:Vh,RidgelinePlot:Uh,LikertChart:Kh,FunnelChart:Zh,GaugeChart:Qh,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,n,o,i)=>({chartType:"custom",data:t,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:e,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:Tp,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,n,o,i)=>({chartType:"force",nodes:i.nodes||t||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:e,colorScheme:n,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...o})},SankeyDiagram:$p,ProcessSankey:Ip,ChordDiagram:Op,TreeDiagram:zp,Treemap:Fp,CirclePack:Dp,ChoroplethMap:Wp,ProportionalSymbolMap:jp,FlowMap:Yp,GeoCustomChart:{frameType:"geo",buildProps:(t,e,n,o,i)=>({points:i.points||t||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:e,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o})},GaltonBoardChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[600,400],s=i.bins??21,a=i.seed??1,l=Math.max(1,Math.round(i.pegRows??s-1)),c="mechanical"===i.mode,u=c?function(t){const e=Math.max(2,Math.round(t.bins)),n=Math.max(1,Math.round(t.pegRows??e-1)),o=Math.max(1,Math.round(t.count??Math.max(64,4*e))),i=Zp(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=tg(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:o},(t,e)=>{let o=0;for(let t=0;n>t;t+=1)r()<i&&(o+=1);const a=n/2;return{id:`${s}-${e}`,value:o,mechanical:!0,pegRows:n,branchProbability:i,pathRights:o,side:a>o?"left":o>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:l,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:n,bins:o,ballRadius:i,seed:r,size:s,valueExtent:a}=t,l=Hp(s),c=e.map((t,e)=>Kp(Up(t,e,n))).filter(t=>null!=t),u=function(t){if(!t)return;const e=Kp(t[0]),n=Kp(t[1]);return null!=e&&null!=n?e>n?[n,e]:[e,n]:void 0}(a),d=u?.[0]??(c.length?Math.min(...c):0),h=u?.[1]??(c.length?Math.max(...c):1),f=h===d?1:h-d,p=eg().domain([0,o]).range([l.plot.x,l.plot.x+l.plot.width]),g=Array.from({length:o},()=>0),y=[];e.forEach((t,e)=>{const r=Kp(Up(t,e,n));if(null==r)return;const s=Math.max(0,Math.min(o-1,Math.floor((r-d)/f*o)));g[s]+=1,y.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:l.plot.y+i+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...t,value:r,bin:s}})});const m=l.plot.y+l.plot.height;return{config:Vp(r,[...Zg({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Qg({idPrefix:"galton-bin",count:o,domainStart:0,domainStep:1,xScale:p,yTop:l.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:g.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:o,plot:l.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:c?[0,l]:void 0});return{...o,config:d.config,initialSpawns:eb(d.initialSpawns),projectionRows:d.projectionRows,bodyStyle:qp(e||i.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[600,400],s=function(t){const{data:e,timeAccessor:n,arrivalAccessor:o,windows:i,watermark:r,ballRadius:s,seed:a,size:l,timeExtent:c,timeScale:u=1}=t,d=Hp(l),h=e.map((t,e)=>Kp(Up(t,e,n))).filter(t=>null!=t),f=Kp(c?.[0]),p=Kp(c?.[1]),g=h.length?Math.min(...h):0,y=h.length?Math.max(...h):g+i.size,m=Math.min(f??g,g),b=Math.max(p??y,y),x=Math.floor(m/i.size)*i.size,v=Math.max(1,Math.ceil((b-x+i.size)/i.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Kp(r?.value)??w-(r?.delay??i.size),S=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>x+(e+1)*i.size>k?t:t+1,0))),A=function(t,e){const n=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:n,height:t.plot.height},windowPlot:{x:t.plot.x+n,y:t.plot.y,width:Math.max(40,t.plot.width-n),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(d,s),M=x+v*i.size,_=yy().domain([x,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),C=[];e.forEach((t,e)=>{const r=Kp(Up(t,e,n));if(null==r)return;const a=Kp(Up(t,e,o))??r,l=Math.max(0,Math.min(v-1,Math.floor((r-x)/i.size))),c=k>=x+(l+1)*i.size;P[l].value+=c?0:1,P[l].secondary+=c?1:0,C.push({id:(t.id??"event-"+e)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const L=d.plot.y+d.plot.height,R=function(t,e){const n=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!n)return[];const o=t.windowStart,i=t.windowStart+t.windowCount*t.windowSize,r=yy().domain([o,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+n*t.windowSize),a=t.windowPlot.x,l=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),c=t=>s===a?e:l+(t-a)/(s-a)*(e-l),u=[];for(let e=0;n>e;e+=1){const n=t.windowStart+e*t.windowSize,o=n+t.windowSize,i=r(n),s=r(o);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:i,y1:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:A.gutter,plot:d.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:i.size,windowStart:x},d.plot.y+.28*d.plot.height);return{config:Vp(a,[...Zg({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...my({idPrefix:"eventdrop-window",count:v,xScale:t=>_(x+t*i.size),yTop:A.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?R[0]?.y1:R[t-1]?.y2??R[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?A.wallTop:e+1.25*s},yBottom:L,wallThickness:6}),...R.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:C,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${x+e*i.size}-${x+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:R,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:i.size,windowStart:x}}}({data:Array.isArray(t)?t:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...o,config:s.config,initialSpawns:eb(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:qp(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[600,400],s="mechanical"===i.mode,a=function(t){const{data:e,categoryAccessor:n,valueAccessor:o,unitValue:i,ballRadius:r,seed:s,size:a}=t,l=Qp(i,1),c=Hp(a),u=[],d=new Map,h=new Map,f=[];function p(t){let e=d.get(t);return null==e&&(e=u.length,u.push(t),d.set(t,e)),e}e.forEach((t,e)=>{p((Up(t,e,n)??"unknown")+"")});const g=Math.max(1,u.length),y=function(t,e,n){const o=t.width/Math.max(1,e),i=Math.max(2,2*n),r=Math.min(.7*o,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:o,tubeWidth:r,ballDiameter:i,perRow:s,centerX:e=>t.x+(e+.5)*o,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*i}}(c.plot,g,r),m=Math.max(0,y.tubeWidth/2-r-1),b=u.map(()=>[]);e.forEach((t,e)=>{const i=(Up(t,e,n)??"unknown")+"",s=p(i),a=o?Kp(Up(t,e,o)):1,u=Math.max(0,Math.round((a??0)/l)),d=y.centerX(s);for(let n=0;u>n;n+=1){const o=h.get(i)??0,a=y.perRow>1?((y.perRow>1?o%y.perRow:0)/(y.perRow-1)*2-1)*m:0;h.set(i,o+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${n}`,x:d+a,y:c.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:i,unitIndex:n}})}});const x=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;x>t;t+=1)for(const e of b)e.length>t&&f.push(e[t]);const v=c.plot.y+c.plot.height,w=[...Zg({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=c.plot.y-400;for(let t=0;g>t;t+=1){const e=y.centerX(t);for(const n of[-1,1])w.push({id:`pile-tube-${t}-${0>n?"l":"r"}`,shape:{type:"aabb",x:e+n*y.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:Vp(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:h.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),n=e.length?e:["Intake"],o=Math.max(n.length,Math.round(t.count??Math.max(48,12*n.length))),i=Qp(t.unitValue,1),r=tg(t.seed??1),s=t.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=o-n.length,u=a.map(t=>t/l*c),d=u.map(t=>1+Math.floor(t));let h=o-d.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;h>0;t=(t+1)%f.length)d[f[t].index]+=1,h-=1;return n.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/o}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...o,config:a.config,initialSpawns:eb(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:qp(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[600,360],s=function(t){const{data:e,xAccessor:n,groupAccessor:o,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:l,collisionIterations:c,settle:u}=t,d=Hp(a),h=tg(s),f=[],p=[],g=new Map;e.forEach((t,e)=>{const s=Kp(Up(t,e,n));if(null==s)return;const a=o?(Up(t,e,o)??"All")+"":"All",l=i?Kp(Up(t,e,i)):null,c=Zp(null!=l&&l>0?l:r,2,18);!function(t){let e=g.get(t);null==e&&(e=p.length,p.push(t),g.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:c})});const y=f.map(t=>t.value),m=l?Kp(l[0]):null,b=l?Kp(l[1]):null,x=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=m??x,k=b??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=d.plot.x+S+8,M=d.plot.x+d.plot.width-S-8,_=by().domain([w,k]).range([A,M]),P=Math.max(1,p.length),C=Math.min(Math.max(28,3*S),d.plot.height/4),L=d.plot.y+C,R=Math.max(0,d.plot.y+d.plot.height-C-L),T=t=>{const e=g.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:L+e/(P-1)*R},I=new Map,$=f.map((t,e)=>{I.set(t.group,(I.get(t.group)??0)+1);const n=_(t.value),o=T(t.group),i=(h()-.5)*t.radius*1.6,r=(h()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?n+i:Zp(n+(e%9-4)*t.radius*2.5,A,M),y:u?o+r:d.plot.y-18-e%12*t.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:n,targetY:o},springs:[{target:{type:"point",x:n,y:o},restLength:0,stiffness:34,damping:5.5}]}});return{config:Vp(s,Zg({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.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(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:$,projectionRows:p.map(t=>({label:t,value:I.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(t=>({label:t,y:T(t),count:I.get(t)??0})),plot:d.plot}}}({data:Array.isArray(t)?t:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...o,config:s.config,initialSpawns:eb(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:qp(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=Ry({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:i.idAccessor,stageAccessor:i.stageAccessor||"stage",groupBy:i.groupBy,groupLabelAccessor:i.groupLabelAccessor,workAccessor:i.workAccessor,radiusAccessor:i.radiusAccessor,ballRadius:i.ballRadius??6,seed:i.seed??1,groupCompletion:i.groupCompletion,groupAnchorAlong:i.groupAnchorAlong,settle:i.settle??!0,gravityX:i.gravityX,gravityY:i.gravityY}),l=a.metadata;return{...o,config:a.config,initialSpawns:eb(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:l?.regionEffects,bodyStyle:qp(e||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[900,520],s=Gy({data:Array.isArray(t)?t:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...o,config:s.config,initialSpawns:eb(s.initialSpawns),projectionRows:[],bodyStyle:qp(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[900,520],s=Dm({data:Array.isArray(t)?t:[],phases:Array.isArray(i.phases)?i.phases:[],products:Array.isArray(i.products)?i.products:void 0,outlets:Array.isArray(i.outlets)?i.outlets:void 0,events:Array.isArray(i.events)?i.events:void 0,idAccessor:i.idAccessor,labelAccessor:i.labelAccessor,categoryAccessor:i.categoryAccessor,amountAccessor:i.amountAccessor,metricsAccessor:i.metricsAccessor,initialStateAccessor:i.initialStateAccessor,metrics:i.metrics,size:r,seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange}),a="snapshot"===i.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,xm(e)??0));const n=t.phases.find(t=>t.id===e.phaseId);if(!n)return t.duration;const o=Math.max(0,Math.min(1,xm(e.progress??0)??0));return n.start+n.duration*o}(s,i.snapshotAt):s.duration,l=Fm(s,a).state,c=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const n=e.groupBy??"outlet",o=new Map,i=t=>{const e=function(t,e){return"product"===e?"product"===t.kind?t.id:"unassigned":"outlet"===e?t.outletId??"unassigned":"category"===e?t.category:t.status}({...t,status:t.status??"active"},n),i=o.get(e);if(i)return i.count+=1,i.amount+=t.amount,void em(i.metrics,t.metrics);o.set(e,{key:e,label:"product"===n&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:{...t.metrics},status:"status"===n?t.status:void 0,outletId:"outlet"===n?t.outletId:void 0,category:"category"===n?t.category:void 0,productId:"product"===n&&"product"===t.kind?t.id:void 0})};for(const e of Object.values(t.components))e.productIds.length||"consumed"===e.status||i({kind:"component",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});for(const e of Object.values(t.products))i({kind:"product",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});const r=new Map((e.order??[]).map((t,e)=>[t,e]));return[...o.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||Vy(t.key,e.key))}(l,c),d=c.measure??"count",h=function(t,e={}){const n=e.bodies??[],o=Math.max(0,e.recentBodyLimit??6),i=new Map;for(const t of n){const n=e.getContainerId?.(t);if(!n)continue;const o=i.get(n);o?o.push(t):i.set(n,[t])}const r=t.map(t=>{const n=i.get(t.id)??[],r=Math.max(0,Math.floor(t.count??n.length)),s=n.slice(Math.max(0,n.length-o)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??tb(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:n.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),f={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},p=e??i.colorBy??"category",g=!1===i.showChrome?null:Xp.createElement(Qm,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:Xp.createElement(Jm,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...o,config:s.config,initialSpawns:eb($m(l,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,n,o){const i=t.datum,r={stroke:o.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:o.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:o.opacity??.96};if(!i?.__crucible)return{...r,fill:o.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:o.color??t?.color??ib(t?.id??i.semanticId)}}const s=e.components[i.semanticId];if(!s)return{...r,fill:o.color??"#356b63"};let a;return a="status"===n?s.status:"outlet"===n?s.outletId??"in chamber":"product"===n?s.productIds[0]??"unalloyed":"category"===n||null==n?s.category:"function"==typeof n?(n(s.datum)??"unassigned")+"":(s.datum[n+""]??"unassigned")+"",{...r,fill:o.color??ib(a)}}(t,l,p,i),getBodyLabel:t=>function(t,e){const n=t.datum;if(n?.__crucible)return"product"===n.kind?e.products[n.semanticId]?.label:e.components[n.semanticId]?.label}(t,l),renderBodySVG:jm,backgroundGraphics:nb(g,o.backgroundGraphics),foregroundGraphics:nb(y,o.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:n,links:o,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:g,sourceAccessor:y,targetAccessor:m,throughputAccessor:b}=t,x=Hp(g),v=tg(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")+""}l.forEach((t,e)=>{const n=(Up(t,e,r)??t.id??e)+"",o=Kp(Up(t,e,s)),i=Kp(Up(t,e,a));if(null!=o&&null!=i){const t={x:o,y:i};w.set(n,t),S.push(t)}k.set(n,(t.label??t.name??n)+"")});const M=[];o.forEach((t,e)=>{const n=A(Up(t,e,y)),o=A(Up(t,e,m)),i=Math.max(0,Kp(Up(t,e,b))??0),r=vy(d?Up(t,e,d):void 0),s=r.length?r:vy(t.path??t.points??t.route);s.forEach(t=>S.push(t)),M.push({id:(t.id??`physical-flow-${n}-${o}-${e}`)+"",link:t,index:e,source:n,target:o,throughput:i,rawPath:s})});const _=(C=S,"normalized"===(P=e)||"pixels"===P?P:C.length>0&&C.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,C;const L=new Map;for(const[t,e]of w)L.set(t,wy(e,x,_));const R=[];for(const t of M){let e=t.rawPath.map(t=>wy(t,x,_));if(2>e.length){const n=L.get(t.source),o=L.get(t.target);n&&o&&(e=[n,o])}else L.has(t.source)||L.set(t.source,e[0]),L.has(t.target)||L.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),R.push({...t,path:e,packetCount:0}))}const T=Qp(u,.12),I=Math.max(1,Math.round(i)),$=R.map(t=>Math.max(1,Math.round(t.throughput*T))),O=$.reduce((t,e)=>t+e,0),z=O>I?I/O:1;R.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor($[e]*z))});let F=R.reduce((t,e)=>t+e.packetCount,0);for(;F>I;){const t=R.reduce((t,e,n)=>e.packetCount>1&&(-1===t||e.packetCount>R[t].packetCount)?n:t,-1);if(-1===t)break;R[t].packetCount-=1,F-=1}const D=new Map,E=new Map,N=[],B=Qp(n,90),W=Qp(c,4);R.forEach((t,e)=>{D.set(t.target,(D.get(t.target)??0)+t.throughput),E.set(t.source,(E.get(t.source)??0)+t.throughput);const n=ky(t.path);for(let o=0;t.packetCount>o;o+=1){const i=(o+.5)/t.packetCount,r=f?i:Zp(.12+.84*i+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=Sy(t.path,s),l=Sy(t.path,r),c=Ay(t.path,s),u={x:-c.y,y:c.x},d=(v()-.5)*W*1.5;N.push({id:`${t.id}-packet-${o}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*B+10*(v()-.5),vy:f?0:c.y*B+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:n,flowRouteId:t.id,flowSpeed:B,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==h&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from(L,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+Jp(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}})),H=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=Vp(p,[...Zg({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],"PacketFlowChart",{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=I,G.eviction="oldest",G.observation={...G.observation,sensors:H};const q=Array.from(L,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+Jp(t),incoming:D.get(t)??0,outgoing:E.get(t)??0})),V=R.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:N,projectionRows:q.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:N.length,totalThroughput:R.reduce((t,e)=>t+e.throughput,0),plot:x.plot,nodes:q,links:V}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(t)?t:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...o,config:s.config,initialSpawns:eb(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:qp(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(t,e,n,o,i)=>{const r=o.size??[700,380],s=function(t){const e=function(t,e,n){const o=t?.observation;return{...t,observation:{...o,chartId:e??o?.chartId??"physics-custom",chartType:o?.chartType??"PhysicsCustomChart",onObservation:n??o?.onObservation}}}(t.config,t.chartId,t.onObservation),n=Iy(t.colorScheme,t.themeCategorical,q),o=Hp(t.size),i={data:t.data,scales:{x:Ty().domain(t.xExtent??[0,1]).range([o.plot.x,o.plot.x+o.plot.width]),y:Ty().domain(t.yExtent??[0,1]).range([o.plot.y+o.plot.height,o.plot.y])},dimensions:o,theme:{semantic:t.semantic,categorical:[...n]},resolveColor:$y(n,t.colorScheme),config:t.layoutConfig??{},world:new gy(e)},r=t.skipLayout?{}:t.layout(i)??{},s=function(t,e){if(!e?.length)return t;const n=new Map;for(const t of e){const{bodyId:e,...o}=t,i=n.get(e)??[];i.push(o),n.set(e,i)}return t.map(t=>{const e=n.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Oy(e,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:n,config:i.config,data:Array.isArray(t)?t:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:w(A)??{},size:r,themeCategorical:A.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...o,config:s.config,initialSpawns:eb(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??qp(e||i.colorBy)}}}};function sb(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function ab(t){if(!t||2>t.length)return;const e=sb(t[0]),n=sb(t[t.length-1]);return null!==e&&null!==n?[e,n]:void 0}function lb(t){const{count:e,byType:n}=function(t){const e={};for(const n of t){const t="string"==typeof n?.type&&n.type.length>0?n.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),o=0===e,i=[...t.extraWarnings??[]];o&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE");const r=t.margin,s=r?{x:r.left,y:r.top,width:t.width-r.left-r.right,height:t.height-r.top-r.bottom}:void 0;return{component:"",frameType:t.frameType,status:o?"empty":"ok",empty:o,markCount:e,markCountByType:n,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:i,...r?{margin:r}:{},...s?{plot:s}:{}}}import*as cb from"react";import*as ub from"react-dom/server";import{scaleOrdinal as db}from"d3-scale";import{jsx as hb,jsxs as fb}from"react/jsx-runtime";function pb(t,e,n){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>St(t,e)??"#999"}const o=Array.isArray(e)?e:n.colors.categorical.length>0?n.colors.categorical:q;return db().domain(t).range(o)}function gb(t,e,n){if(0===t.length)return;const o=pb(t,e,n);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:o(t.label)})}]}}function yb(t){return"left"===t?"start":"right"===t?"end":t??"start"}function mb(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function bb(t,e,n,o){const i=mb(o);return e+n+Math.ceil(t.length*i*.58)}function xb(t){const{categories:e,theme:n,position:o="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=er(s),d=a+l,h="top"===o||"bottom"===o,f=Math.max(a,i-r.left-r.right),p=e.map(t=>bb(t,a,l,n));if(h){const t=Math.max(a,s?.maxWidth??f),n=[];let o=0,i=0;p.forEach((e,r)=>{const s=0===i?e:i+c+e;i>0&&s>t?(n.push({start:o,end:r,width:i}),o=r,i=e):i=s}),e.length>0&&n.push({start:o,end:e.length,width:i});const r=yb(s?.align),l=[];return n.forEach((n,o)=>{let i="center"===r?Math.max(0,(t-n.width)/2):"end"===r?Math.max(0,t-n.width):0;for(let t=n.start;n.end>t;t++)l.push({category:e[t],width:p[t],x:i,y:o*u}),i+=p[t]+c}),{items:l,width:Math.max(0,...n.map(t=>t.width)),height:n.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:g,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function vb(t){const{legendGroups:e,theme:n,position:o="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,rowHeight:c}=er(s),u=a+l,d=Math.max(12,mb(n)),h="top"===o||"bottom"===o,f=Math.max(a,i-r.left-r.right);if(h){const o=Math.max(a,s?.maxWidth??f),i=yb(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=xb({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,o-d-8),align:"start"}}),h=i.label?d:0,f=i.label?bb(i.label,0,0,n):0,p=h>0?h+8:0,g=p+u.width,y=Math.max(u.height,f);c.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.length>0?r-12:0,p=h>o?0:"center"===i?Math.max(0,(o-h)/2):"end"===i?Math.max(0,o-h):0;return{groups:c.map(t=>({...t,x:t.x+p})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=nr(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let g=0;return{groups:e.map((t,e)=>{const o=t.items.map(t=>bb(t.label,a,l,n)),i=Math.max(0,...o,t.label?bb(t.label,0,0,n):0);return g=Math.max(g,i),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:o[e],x:0,y:e*c}))}}),width:g,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function wb(t){const e="top"===t.position||"bottom"===t.position,n=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??n,200),height:t.gradient.label?34:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?124:108,swatchSize:14}}function kb(t,e){if(!e||!t||0===t.length)return[];const n="function"==typeof e?e:t=>t[e],o=new Set;for(const e of t){const t=n(e);null!=t&&o.add(t+"")}return Array.from(o)}import{jsx as Sb,jsxs as Ab}from"react/jsx-runtime";var Mb=16;function _b(t,e){return t.color||e.colors.annotation||e.colors.text}function Pb(t,e,n){const o=t.labelBackground,i=e.colors.background,r=i&&"transparent"!==i?i:e.colors.surface||i;return void 0===o?"none"===n?"none":{type:"halo",fill:r}:!1===o||"none"===o?"none":!0===o||"halo"===o?{type:"halo",fill:r}:"box"===o?{type:"box",fill:r}:{fill:r,...o}}function Cb(t,e,n){return null!=t.x&&e.x?e.x(t.x):n&&null!=t[n]&&e.x?e.x(t[n]):"number"==typeof t.x?t.x:null}function Lb(t,e,n){return null!=t.y&&e.y?e.y(t.y):n&&null!=t[n]&&e.y?e.y(t[n]):"number"==typeof t.y?t.y:null}function Rb(t){const{annotations:e}=t;if(!e||0===e.length)return null;const n=a(e),o=t.scales.geoProjection,i=o?n.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=o([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):n,r=!!o&&!t.scales.x&&!t.scales.y,s=t=>Number(t),l=t.scales.x??(r?s:void 0),c=t.scales.y??(r?s:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{x:l,y:c,time:l,value:c,o:t.scales.o,...o?{geoProjection:o}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,frameType:t.projection?"ordinal":o||t.scales.x||t.scales.y?"xy":"network",...u?{projection:u}:{}},h=ss(t.autoPlaceAnnotations?vs({annotations:i,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):i,(e,n)=>function(t,e,n){const{scales:o,layout:i,theme:r,xAccessor:s,yAccessor:a}=n;switch(t.type){case"y-threshold":{const s=t.value;if(null==s)return null;const a=_b(t,r),l=t.label,c=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===n.projection&&o.r){const n=o.r(s);return null==n?null:Ab("g",{opacity:t.opacity,children:[Sb("line",{x1:n,y1:0,x2:n,y2:i.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Sb(ns,{x:n+4,y:Mb,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Pb(t,r,"halo")})]},"ann-ythresh-"+e)}const h=o.y?o.y(s):o.r?o.r(s):null;return null==h?null:Ab("g",{children:[Sb("line",{x1:0,y1:h,x2:i.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Sb(ns,{x:"left"===c?4:"center"===c?i.width/2:i.width-4,y:20>h?Math.min(i.height-4,h+Mb):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Pb(t,r,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const s=t.value;if(null==s)return null;const a="horizontal"===n.projection&&o.r?o.r(s):o.x?o.x(s):null;if(null==a)return null;const l=_b(t,r),c=t.label,u=t.labelPosition||"top";return Ab("g",{opacity:t.opacity,children:[Sb("line",{x1:a,y1:0,x2:a,y2:i.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&Sb(ns,{x:a>.6*i.width?a-4:a+4,y:"bottom"===u?i.height-4:"center"===u?i.height/2:Mb,textAnchor:a>.6*i.width?"end":"start",fontSize:r.typography.tickSize,fill:l,fontFamily:r.typography.fontFamily,text:c,background:Pb(t,r,"halo")})]},"ann-xthresh-"+e)}case"band":{const n=o.y?.domain?.(),s=t.y0??n?.[0],a=t.y1??n?.[1],l=null!=s&&o.y?o.y(s):null,c=null!=a&&o.y?o.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ri(t.fill||_b(t,r),"ssr-band-"+e),f=t.fillOpacity??.1;return Ab("g",{opacity:t.opacity,children:[h.def&&Sb("defs",{children:h.def}),Sb("rect",{x:0,y:u,width:i.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&Sb(ns,{x:i.width-4,y:Math.max(u,0)+Mb,textAnchor:"end",fontSize:r.typography.tickSize,fill:t.color||_b(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Pb(t,r,"halo")})]},"ann-band-"+e)}case"x-band":{const n=o.x?.domain?.(),s=t.x0??n?.[0],a=t.x1??n?.[1],l=null!=s&&o.x?o.x(s):null,c=null!=a&&o.x?o.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ri(t.fill||_b(t,r),"ssr-xband-"+e),f=t.fillOpacity??.1;return Ab("g",{opacity:t.opacity,children:[h.def&&Sb("defs",{children:h.def}),Sb("rect",{x:u,y:0,width:d,height:i.height,fill:h.fill,fillOpacity:f}),t.label&&Sb(ns,{x:u+4,y:Mb,textAnchor:"start",fontSize:r.typography.tickSize,fill:t.color||r.colors.primary||_b(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Pb(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,l=_b(t,r),c=t.opacity??.1,u=t.label;return Ab("g","horizontal"===n.projection?{children:[Sb("rect",{x:0,y:s,width:i.width,height:a,fill:l,opacity:c}),u&&Sb(ns,{x:12,y:s+a/2,dominantBaseline:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Pb(t,r,"none")})]}:{children:[Sb("rect",{x:s,y:0,width:a,height:i.height,fill:l,opacity:c}),u&&Sb(ns,{x:s+a/2,y:Mb,textAnchor:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Pb(t,r,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:n,y:i}=function(t,e,n,o){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const n=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(n)return{x:n[0],y:n[1]}}return{x:Cb(t,e,n),y:Lb(t,e,o)}}(t,o,s,a);if(null==n||null==i)return null;const l="text"===t.type,c=t.dx??(l?0:30),u=t.dy??(l?0:-30),d=t.color||r.colors.text;if(!l){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 Sb(Lr,{noteData:{x:n,y:i,dx:c,dy:u,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...r?{subject:r}:{},connector:t.connector||{end:"arrow"},color:d,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Sb("g",{children:Sb("text",{x:n+c,y:i+u,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||r.typography.labelSize,fill:d,fontFamily:r.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}(e,n,t),t.svgAnnotationRules,d);return h.length>0?Sb("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as Tb from"react";import{jsx as Ib,jsxs as $b}from"react/jsx-runtime";function Ob(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function zb(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 n=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let o=0;for(let t=0;n.length>t;t++)o=31*o+n.charCodeAt(t)|0;return"c"+(o>>>0).toString(36)}function Fb(t,e,n){return Hi(t.showLegend&&!t.__legendIncludesAutomatic?gb(e,t.colorScheme,n):void 0,t.legend)}var Db={right:110,left:110,top:50,bottom:80};function Eb(t,e){if(t.__autoLegendMargin&&!Nb(t,e))return Db[e]}function Nb(t,e){const n=t.__explicitMargin;return"number"==typeof n||!(!n||"object"!=typeof n||"number"!=typeof n[e])}function Bb(t,e){const{props:n,categories:o,theme:i,size:r,hasTitle:s}=e,a=n.legendPosition||"right",l={theme:i,position:a,size:r,hasTitle:s,legendLayout:n.legendLayout,axisChrome:n.axisChrome,minimumMargin:Eb(n,a),preserveExplicitMargin:Nb(n,a)};if(null!=n.legend){const e=Fb(n,o,i);(Gi(e)||qi(e))&&function(t,e){if(e.preserveExplicitMargin)return;const n=e.position||"right",o={theme:e.theme,position:n,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout},i=Gi(e.legend)?function(t){const{width:e,height:n,swatchSize:o}=vb(t);return{width:e,height:n,swatchSize:o}}({...o,legendGroups:e.legend.legendGroups}):qi(e.legend)?wb({...o,gradient:e.legend.gradient}):null;if(!i)return;const r=Ki(e.legend),s=Math.max(e.minimumMargin??0,tr(e.legend,e.legendLayout)),a=Qi(e.axisChrome,e.legendLayout),l=Math.max(e.minimumMargin??0,r+i.height+(e.hasTitle?24:0)),c=Math.max(e.minimumMargin??0,a+r+i.height);"right"===n?t.right=Math.max(t.right,s):"left"===n?t.left=Math.max(t.left,s):"top"===n?t.top=Math.max(t.top,l):t.bottom=Math.max(t.bottom,c)}(t,{...l,legend:e})}else n.showLegend&&o.length>0&&function(t,e){if(0===e.categories.length)return;if(e.preserveExplicitMargin)return;const n=e.position||"right",o=function(t){const{width:e,height:n,swatchSize:o}=xb(t);return{width:e,height:n,swatchSize:o}}({categories:e.categories,colorScheme:e.colorScheme,theme:e.theme,position:n,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout}),i=gb(e.categories,e.colorScheme,e.theme),r=Ki(i),s=Math.max(e.minimumMargin??0,tr(i,e.legendLayout)),a=Qi(e.axisChrome,e.legendLayout),l=Math.max(e.minimumMargin??0,r+o.height+(e.hasTitle?24:0)),c=Math.max(e.minimumMargin??0,a+r+o.height);"right"===n?t.right=Math.max(t.right,s):"left"===n?t.left=Math.max(t.left,s):"top"===n?t.top=Math.max(t.top,l):t.bottom=Math.max(t.bottom,c)}(t,{...l,categories:o,colorScheme:n.colorScheme});return a}function Wb(t){const{props:e,categories:n,theme:o,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",l={theme:o,position:a,size:i,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=Fb(e,n,o);if(Tb.isValidElement(t))return t;const i=function(t,e){const n={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix,reservedWidth:e.reservedWidth,axisChrome:e.axisChrome,legendDistance:Gi(t)||qi(t)?t.legendDistance:void 0};return Gi(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,n)=>({group:t,item:e,itemIndex:n,label:e.label})))).length)return null;var e;const n=vb(t),o="top"===t.position||"bottom"===t.position,i={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??Ui(i,t.legendLayout),s=Ki(i),a=Zi(t.legendLayout),l=Qi(t.axisChrome,t.legendLayout),c=Qi(void 0,t.legendLayout),u=t.theme.colors.grid||t.theme.colors.textSecondary;let d,h;if("left"===t.position?(d=t.margin.left-a-r-s,h=t.margin.top):"top"===t.position?(d=t.margin.left,h=t.margin.top-c-s-n.height):"bottom"===t.position?(d=t.margin.left,h=Math.max(t.totalHeight-t.margin.bottom+s,Math.min(t.totalHeight-t.margin.bottom+l+s,t.totalHeight-n.height))):(d=t.totalWidth-t.margin.right+a+s,h=t.margin.top),!o){const e=nr(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(n.swatchSize,t.legendLayout?.rowHeight??22)),o=t.legendGroups.flatMap((o,i)=>{const s=e[i],a=o.type??"fill",l=[hb("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return o.label&&null!=s.labelY&&l.push(hb("text",{y:s.labelY,fontSize:mb(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:o.label},"legend-group-label-"+i)),l.push(hb("g",{transform:`translate(0,${s.itemsY})`,children:o.items.map((e,r)=>{const s=o.styleFn(e,r),l="function"==typeof a?a(e):"line"===a?hb("line",{x1:0,y1:0,x2:n.swatchSize,y2:n.swatchSize,style:s}):hb("rect",{width:n.swatchSize,height:n.swatchSize,rx:n.swatchRadius,style:s});return fb("g",{transform:`translate(0,${r*Math.max(n.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,hb("text",{x:n.labelOffset,y:n.swatchSize/2,dominantBaseline:"central",fontSize:mb(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return hb("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":"vertical",children:o})}const f=n.groups.flatMap((e,i)=>{const{group:r}=e,s=r.type??"fill",a=[];if(r.label&&a.push(hb("text",o?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:mb(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:r.label}:{x:e.x,y:e.y+mb(t.theme),fontSize:mb(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:r.label},"legend-group-label-"+i)),a.push(...e.items.map((o,a)=>{const l=r.items[a],c=r.styleFn(l,a),u="function"==typeof s?s(l):"line"===s?hb("line",{x1:0,y1:0,x2:n.swatchSize,y2:n.swatchSize,style:c}):hb("rect",{width:n.swatchSize,height:n.swatchSize,rx:n.swatchRadius,style:c});return fb("g",{transform:`translate(${e.x+e.itemOffsetX+o.x},${e.y+e.itemOffsetY+o.y})`,children:[u,hb("text",{x:n.labelOffset,y:n.swatchSize/2,dominantBaseline:"central",fontSize:mb(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:o.category})]},`legend-${i}-${a}`)})),o&&n.groups.length-1>i){const t=e.x+e.width+6;a.push(hb("line",{x1:t,y1:0,x2:t,y2:n.height,stroke:u},"legend-group-separator-"+i))}return a});return hb("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":o?"horizontal":"vertical",children:f})}({...n,legendGroups:t.legendGroups}):qi(t)?function(t){const e=wb(t),n="top"===t.position||"bottom"===t.position,o={gradient:t.gradient,legendDistance:t.legendDistance},i=Ui(o),r=Ki(o),s=Zi(t.legendLayout),a=Qi(t.axisChrome,t.legendLayout),l=Qi(void 0,t.legendLayout),c=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",u=t.gradient.format||(t=>Math.round(100*t)/100+"");let d,h;"left"===t.position?(d=t.margin.left-s-i-r,h=t.margin.top):"top"===t.position?(d=t.margin.left,h=t.margin.top-l-r-e.height):"bottom"===t.position?(d=t.margin.left,h=Math.max(t.totalHeight-t.margin.bottom+r,Math.min(t.totalHeight-t.margin.bottom+a+r,t.totalHeight-e.height))):(d=t.totalWidth-t.margin.right+s+r,h=t.margin.top);const f=Array.from({length:17},(e,o)=>{const i=o/16;return hb("stop",{offset:100*i+"%",stopColor:t.gradient.colorFn(n?t.gradient.domain[0]+i*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-i*(t.gradient.domain[1]-t.gradient.domain[0]))},o)});if(n){const n=12,o=t.gradient.label?0:void 0,i=t.gradient.label?8:0;return fb("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,children:[hb("defs",{children:hb("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:f})}),t.gradient.label&&hb("text",{x:e.width/2,y:o,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),hb("rect",{x:0,y:i,width:e.width,height:n,fill:`url(#${c})`,rx:2}),hb("text",{x:0,y:i+n+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[0])}),hb("text",{x:e.width,y:i+n+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[1])})]})}const p=t.gradient.label?-6:void 0;return fb("g",{className:"semiotic-legend",transform:`translate(${d},${h+(t.gradient.label?12:0)})`,children:[hb("defs",{children:hb("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:f})}),t.gradient.label&&hb("text",{x:0,y:p,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),hb("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),hb("text",{x:19,y:10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[1])}),hb("text",{x:19,y:100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[0])})]})}({...n,gradient:t.gradient}):null}(t,l);return i||(Gi(t)||qi(t)?null:t??null)}return e.showLegend&&0!==n.length?function(t){const{categories:e,colorScheme:n,theme:o,position:i="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const l=pb(e,n,o),c="top"===i||"bottom"===i,u=xb(t),d=gb(e,n,o),h=t.reservedWidth??Ui(d,t.legendLayout),f="number"==typeof t.legendDistance?Math.max(0,t.legendDistance):Ki(d),p=Zi(t.legendLayout),g=Qi(t.axisChrome,t.legendLayout),y=Qi(void 0,t.legendLayout);let m,b;if("left"===i?(m=a.left-p-h-f,b=a.top):"top"===i?(m=a.left,b=a.top-y-f-u.height):"bottom"===i?(m=a.left,b=Math.max(s-a.bottom+f,Math.min(s-a.bottom+g+f,s-u.height))):(m=r-a.right+p+f,b=a.top),c){const t=u.items.map((t,e)=>fb("g",{transform:`translate(${t.x},${t.y})`,children:[hb("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),hb("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:mb(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:t.category})]},"legend-"+e));return hb("g",{className:"semiotic-legend",transform:`translate(${m},${b})`,children:t})}const x=nr([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],v=u.items.map((t,e)=>fb("g",{transform:`translate(${t.x},${t.y+x.itemsY})`,children:[hb("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),hb("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:mb(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:t.category})]},"legend-"+e));return fb("g",{className:"semiotic-legend",transform:`translate(${m},${b})`,children:[hb("line",{x1:0,y1:x.lineY,x2:h,y2:x.lineY,stroke:"gray"}),v]})}({categories:n,colorScheme:e.colorScheme,theme:o,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}function jb(t){return Math.round(100*t)/100+""}function Yb(t,e){const n=I(e.theme),o=e.background??n.background,i=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?i+"semiotic-title":void 0,a=e.description?i+"semiotic-desc":void 0,l=[s,a].filter(Boolean).join(" ")||void 0;return $b("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":l,style:{fontFamily:n.fontFamily},children:[r&&Ib("title",{id:s,children:r}),e.description&&Ib("desc",{id:a,children:e.description}),e.defs&&Ib("defs",{children:e.defs}),o&&"transparent"!==o&&Ib("rect",{x:0,y:0,width:e.width,height:e.height,fill:o}),Ib("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&Ib("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:r}),e.legend&&Ib("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{Fragment as Xb,jsx as Hb,jsxs as Gb}from"react/jsx-runtime";function qb(t,e){const n=T(t.theme),o=t.size||[500,300],i=Bs({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Es(t.title),s=j(t.data),a=t.showLegend?kb(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l={hasAxis:!1!==t.showAxes,hasAxisLabel:!!t.xLabel};Bb(i,{props:{...t,axisChrome:l},categories:a,theme:n,size:o,hasTitle:r});const c=o[0]-i.left-i.right,u=o[1]-i.top-i.bottom,d="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),h=t.colorScheme||n.colors.categorical,f={chartType:t.chartType,windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:d?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:d?void 0:t.xAccessor,yAccessor:d?void 0:t.yAccessor,timeAccessor:d?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,baseline:t.baseline,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,band:t.band,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:Nt(t.gradientFill),lineGradient:Bt(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:h,themeCategorical:n.colors.categorical,themeSemantic:w(n),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat},p=new mo(f);if(t.data&&p.ingest({inserts:s,bounded:!0}),p.computeScene({width:c,height:u}),!p.scales||0===p.scene.length)return e&&(e.evidence=lb({frameType:"xy",width:o[0],height:o[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:p.scales?[]:["NO_SCALES"],margin:i})),ub.renderToStaticMarkup(Yb(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:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,idPrefix:t._idPrefix}));const g=t._idPrefix,y=Kc({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>Ca(t,e,g)});e&&(e.evidence=lb({frameType:"xy",width:o[0],height:o[1],marks:y.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,xDomain:ab(p.scales.x?.domain?.()),yDomain:ab(p.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const m=t.showGrid?function(t,e,n,o,i,r){const{grid:s}=I(n),a=o?o+"-":"",l="exact"===i?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),c="exact"===i?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),u=Is(t.x,l,i),d=Is(t.y,c,i),h=!1!==r?.find(t=>"bottom"===t.orient)?.grid,f=!1!==r?.find(t=>"left"===t.orient)?.grid,p=Fs(r?.find(t=>"bottom"===t.orient)?.gridStyle),g=Fs(r?.find(t=>"left"===t.orient)?.gridStyle);return $b("g",{id:a+"grid",className:"semiotic-grid",opacity:.8,children:[h&&u.map((n,o)=>{const i=t.x(n);return Ib("line",{x1:i,y1:0,x2:i,y2:e.height,stroke:s,strokeWidth:.5,strokeDasharray:p},"gx-"+o)}),f&&d.map((n,o)=>{const i=t.y(n);return Ib("line",{x1:0,y1:i,x2:e.width,y2:i,stroke:s,strokeWidth:.5,strokeDasharray:g},"gy-"+o)})]})}(p.scales,{width:c,height:u},n,g,t.axisExtent,t.axes):null,b=y.map(t=>t.element),x=zb(t)+"-plot-clip",v=!1!==t.showAxes?function(t,e,n,o,i){const r=I(o),s=Zi(n.legendLayout),a=n.legend&&"left"===n.legendPosition&&s>0?s:n.margin?.left??40,l="exact"===n.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),c="exact"===n.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),u=n.axes?.find(t=>"bottom"===t.orient),d=n.axes?.find(t=>"left"===t.orient),h=u?.tickValues??Is(t.x,u?.ticks??l,n.axisExtent),f=h.map(t=>t.valueOf()),p=u?.tickFormat||n.xFormat||n.tickFormatTime||jb,g=h.map((e,n)=>({pixel:t.x(e),label:p(e,n,f)})),y=d?.tickValues??Is(t.y,d?.ticks??c,n.axisExtent),m=d?.tickFormat||n.yFormat||n.tickFormatValue||jb,b=y.map(e=>({pixel:t.y(e),label:m(e)})),x=u?.label??n.xLabel,v=d?.label??n.yLabel;return $b("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==u?.baseline&&Ib("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:r.border,strokeWidth:1}),g.map((t,n)=>$b("g",{transform:`translate(${t.pixel},${e.height})`,children:[Ib("line",{y2:5,stroke:r.border,strokeWidth:1}),Ib("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"xtick-"+n)),x&&Ib("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:x}),!1!==d?.baseline&&Ib("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:r.border,strokeWidth:1}),b.map((t,e)=>$b("g",{transform:`translate(0,${t.pixel})`,children:[Ib("line",{x2:-5,stroke:r.border,strokeWidth:1}),Ib("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"ytick-"+e)),v&&Ib("text",{x:15-a,y:e.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-a}, ${e.height/2})`,children:v})]})}(p.scales,{width:c,height:u},t,n,g):null,k=t.annotations?Rb({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:p.scales.x,y:p.scales.y},layout:{width:c,height:u},theme:n,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:g}):null,S=t.svgPreRenderers&&p.scales?t.svgPreRenderers.map((t,e)=>{try{return Hb(cb.Fragment,{children:t(p.scene,p.scales,{width:c,height:u})},"pre-"+e)}catch{return null}}).filter(Boolean):null,A=Wb({props:{...t,axisChrome:l},categories:a,theme:n,size:o,margin:i,hasTitle:r});return ub.renderToStaticMarkup(Yb(Gb(Xb,{children:[t.backgroundGraphics,S,m,Hb("defs",{children:Hb("clipPath",{id:x,children:Hb("rect",{x:0,y:0,width:c,height:u})})}),Hb("g",{clipPath:`url(#${x})`,children:b}),v,k,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:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,legend:A,idPrefix:t._idPrefix}))}import*as Vb from"react-dom/server";import{scaleBand as Ub,scaleLinear as Kb}from"d3-scale";var Zb=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,n){if(e&&"function"==typeof t.pieceStyle){const o=t.pieceStyle(e,n);return o&&!o.fill&&n?{...o,fill:this.getColorFromScheme(t,n)}:o}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&n?{fill:t.barColors[n]||"#007bff"}:{fill:n?this.getColorFromScheme(t,n):"#007bff"}}resolveSummaryStyle(t,e,n){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,n):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const n=this.colorSchemeMap.get(e);if(n)return n;const o=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||xt,i=o[this.colorSchemeIndex%o.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function Qb(t){const e=t.getSymbol;return e?kn(e,t.config.symbolMap):null}function Jb(t,e,n,o,i,r,s){t.push(e?{type:"symbol",x:o,y:i,size:Math.PI*r*r,symbolType:e(n),style:s,datum:n}:{type:"point",x:o,y:i,r:r,style:s,datum:n})}function tx(t,e){const{columns:n,config:o,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===o.chartType?o.innerRadius||60:0,l=-Math.PI/2+(o.startAngle||0)*Math.PI/180,c=null!=o.sweepAngle?o.sweepAngle*Math.PI/180:2*Math.PI,u=null!=o.sweepAngle&&360>o.sweepAngle,d=Object.values(n),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),f=u&&!h&&d.length>1&&(o.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],n=e.pieceData[0],u="number"==typeof n?._pctStart?n._pctStart:e.pctStart,h=l+u*c,p=l+(u+("number"==typeof n?._pct?n._pct:e.pct))*c,g=i(e.pieceData[0],e.name),y=0===t,m=t===d.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...o.cornerRadius&&{cornerRadius:o.cornerRadius},style:g,datum:n?._nonInteractive?null:e.pieceData,category:e.name};n?._roundedEnds?b.roundedEnds=n._roundedEnds:f&&(b.roundedEnds={start:y,end:m}),n?._gradientBand&&(b._gradientBand=n._gradientBand),r.push(b)}return r}import{quantile as ex}from"d3-array";function nx(t){const e=t.length,n=t[0],o=t[e-1];return{n:e,min:n,q1:ex(t,.25)??n,median:ex(t,.5)??(n+o)/2,q3:ex(t,.75)??o,max:o,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as ox}from"d3-scale";var ix={bar:function(t,e){const{scales:n,columns:o,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=n,u=[],d="vertical"===c,h="horizontal"===c,f=i.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(o))for(const n of e.pieceData){const e=s(n);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 n of t.pieceData){const t=s?s(n):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const o=e.get(t);o.total+=r(n),o.pieces.push(n)}let n=0;if(f)for(const t of e.values())n+=Math.abs(t.total);let o=0,i=0;for(const r of p){const c=e.get(r);if(!c)continue;let p=c.total;f&&n>0&&(p/=n);const g=a(c.pieces[0],s?r:t.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>p?i:o+p),n=0>p?l(i+p)-l(i):l(o)-l(o+p);u.push(Qe(t.x,e,t.width,Math.abs(n),g,y,r)),0>p?i+=p:o+=p}else if(h){const e=l(0>p?i+p:o),n=0>p?l(i)-l(i+p):l(o+p)-l(o);u.push(Qe(e,t.x,Math.abs(n),t.width,g,y,r)),0>p?i+=p:o+=p}}}const g="vertical"===c,y=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=g?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(y>0){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const n=e.datum?.category||"";t.has(n)||t.set(n,[]),t.get(n).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),n=e.filter(t=>0>(t.datum?.__aggregateValue??0));t.length>0&&(t.reduce(g?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e).roundedTop=y),n.length>0&&(n.reduce(g?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e).roundedTop=y)}}return u},clusterbar:function(t,e){const{scales:n,columns:o,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:l,projection:c}=n,u=[],d="vertical"===c,h=[],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),h.push(t))}const p=h.length||1;for(const t of Object.values(o)){const e=t.width/p,n=.2*e,o=e-n,i=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";i.has(t)||i.set(t,[]),i.get(t).push(e)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),f=a(i,h[s]);if(d){const r=t.x+s*e+n/2,a=l(0),d=l(c);u.push(Qe(r,Math.min(a,d),o,Math.abs(a-d),f,i,h[s]))}else{const r=t.x+s*e+n/2,a=l(0),d=l(c);u.push(Qe(Math.min(a,d),r,Math.abs(d-a),o,f,i,h[s]))}}}}const g=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum);g>0&&(t.roundedTop=g),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}return u},point:function(t,e){const{scales:n,columns:o,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:l}=n,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,f=Qb(t),p=2*Math.PI,g=-Math.PI/2;for(const t of Object.values(o))for(const e of t.pieceData){const n=e.__rIndex??0,o=e.__rValue??i(e),l=h&&r[n]||a,y=s(e,t.name),m=y.r||5;let b,x;if(d){const e=g+(t.pctStart+t.pct/2)*p,n=l(o);b=Math.cos(e)*n,x=Math.sin(e)*n}else u?(b=t.middle,x=l(o)):(b=l(o),x=t.middle);Jb(c,f,e,b,x,m,y)}return c},swarm:function(t,e){const{scales:n,columns:o,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=n,l=[],c="vertical"===a,u=Qb(t);for(const t of Object.values(o)){const e=t.width/2;for(let n=0;t.pieceData.length>n;n++){const o=t.pieceData[n],a=i(o),d=r(o,t.name),h=d.r||4,f=(7919*n%100/100-.5)*e*.8;Jb(l,u,o,c?t.middle+f:s(a),c?s(a):t.middle+f,h,d)}}return l},pie:tx,donut:tx,boxplot:function(t,e){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=n,c=[],u="vertical"===l,d=!1!==i.showOutliers;for(const e of Object.values(o)){const n=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===n.length)continue;const o=n[0],i=n[n.length-1],l=ex(n,.25)??o,h=ex(n,.5)??(o+i)/2,f=ex(n,.75)??i,p=f-l,g=l-1.5*p,y=f+1.5*p,m=n.find(t=>t>=g)??o,b=[...n].reverse().find(t=>y>=t)??i,x=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const n=r(t);if(g>n||n>y){const o=u?e.middle:a(n),i=u?a(n):e.middle;v.push({px:o,py:i,value:n,datum:t})}}if(c.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(l),medianPos:a(h),q3Pos:a(f),maxPos:a(b),stats:{n:n.length,min:m,q1:l,median:h,q3:f,max:b,mean:n.reduce((t,e)=>t+e,0)/n.length},style:x,datum:e.pieceData,category:e.name,outliers:v}),d)for(const e of v)c.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:x.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6},datum:e.datum})}return c},violin:function(t,e){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=n,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.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 n=e[0],o=e[e.length-1],i=(o-n)/d||1,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-n)/i),d-1)]++;const f=Pt(l,1),p=t.width/2*.9;let g;if(u){g=`M ${t.middle} ${a(n)}`;for(let e=0;d>e;e++){const o=a(n+(e+.5)*i);g+=` L ${t.middle+l[e]/f*p} ${o}`}g+=` L ${t.middle} ${a(o)}`;for(let e=d-1;e>=0;e--){const o=a(n+(e+.5)*i);g+=` L ${t.middle-l[e]/f*p} ${o}`}g+=" Z"}else{g=`M ${a(n)} ${t.middle}`;for(let e=0;d>e;e++)g+=` L ${a(n+(e+.5)*i)} ${t.middle-l[e]/f*p}`;g+=` L ${a(o)} ${t.middle}`;for(let e=d-1;e>=0;e--)g+=` L ${a(n+(e+.5)*i)} ${t.middle+l[e]/f*p}`;g+=" Z"}const y=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=ex(e,.25)??n,r=ex(e,.5)??(n+o)/2,s=ex(e,.75)??o;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const b=u?{x:t.x,y:Math.min(a(o),a(n)),width:t.width,height:Math.abs(a(o)-a(n))}:{x:Math.min(a(n),a(o)),y:t.x,width:Math.abs(a(o)-a(n)),height:t.width};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:nx(e),style:y,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=n,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[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[n,o]=_t(e),i=null!=h&&isFinite(h)?h:n,d=null!=f&&isFinite(f)?f:o,p=(d-i)/c||1,g=Array(c).fill(0);for(const t of e)i>t||t>d||g[Math.min(Math.floor((t-i)/p),c-1)]++;const y=e.length,m=Pt(g,1),b=s(t.pieceData[0],t.name);for(let e=0;c>e;e++){if(0===g[e])continue;const n=(u?g[e]/y:g[e]/m)*t.width*.9,o=a(i+e*p),r=a(i+(e+1)*p);l.push(Qe(Math.min(o,r),t.x+t.width-n,Math.abs(r-o),n,b,{bin:e,count:g[e],range:[i+e*p,i+(e+1)*p],category:t.name},t.name))}}return l},ridgeline:function(t,e){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=n,c=[],u=i.bins||20,d="horizontal"===l,h=i.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 n=e[0],o=e[e.length-1],i=(o-n)/u||1,l=Array(u).fill(0);for(const t of e)n>t||t>o||l[Math.min(Math.floor((t-n)/i),u-1)]++;const f=Pt(l,1),p=s(t.pieceData[0],t.name),g=t.width*h;let y;if(d){const e=t.x+t.width;y=`M ${a(n)} ${e}`;for(let t=0;u>t;t++)y+=` L ${a(n+(t+.5)*i)} ${e-l[t]/f*g}`;y+=` L ${a(o)} ${e} Z`}else{const e=t.x;y=`M ${e} ${a(n)}`;for(let t=0;u>t;t++){const o=a(n+(t+.5)*i);y+=` L ${e+l[t]/f*g} ${o}`}y+=` L ${e} ${a(o)} Z`}const m=d?{x:Math.min(a(n),a(o)),y:t.x,width:Math.abs(a(o)-a(n)),height:t.width}:{x:t.x,y:Math.min(a(o),a(n)),width:t.width,height:Math.abs(a(o)-a(n))};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:nx(e),style:{...p,fillOpacity:p.fillOpacity??.5},datum:t.pieceData,category:t.name})}return c},timeline:function(t,e){const{scales:n,columns:o,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=n,l=[],c="horizontal"===a;for(const t of Object.values(o))for(const e of t.pieceData){const n=i(e);if(!n)continue;const[o,a]=n,u=r(e,t.name);if(c){const n=s(Math.min(o,a)),i=s(Math.max(o,a));l.push(Qe(n,t.x,i-n,t.width,u,e,t.name))}else{const n=s(Math.max(o,a)),i=s(Math.min(o,a));l.push(Qe(t.x,n,t.width,i-n,u,e,t.name))}}return l},funnel:function(t,e){const{columns:n,getR:o,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>n[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const t of c){const e=new Map;let n=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=o(r);s.total+=a,s.pieces.push(r),n+=a}f.push({col:t,groups:e,stepTotal:n}),h||n>p&&(p=n)}if(h)for(const t of f){let e=0,n=0;for(let o=0;u.length>o;o++){const i=t.groups.get(u[o]);i&&(o%2==0?e+=i.total:n+=i.total)}const o=Math.max(e,n);o>p&&(p=o)}if(0===p)return s;const g=new Map;for(const t of u){const e=f[0].groups.get(t);g.set(t,e?.total??0)}const y=f[0].stepTotal,m=h?.95*a:.9*e.width,b=ox().domain([0,p]).range([0,m]),x=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const n=f[e],o=n.col,i=0===e,c=o.width,d=.55*c,p=o.x+(c-d)/2,m=new Map;if(h){let t=0;for(const e of u){const o=n.groups.get(e);o&&(t+=b(o.total))}let e=a,c=a;for(let h=0;u.length>h;h++){const f=u[h],y=n.groups.get(f);if(!y)continue;const x=b(y.total),v=h%2==0,w=v?e:c-x;v?e+=x:c-=x;const k=r(y.pieces[0],f),S=g.get(f)??y.total,A={...y.pieces[0],__funnelValue:y.total,__funnelPercent:S>0?y.total/S*100:0,__funnelStep:o.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:f};l&&(0===h&&(A.__funnelStepLabel=o.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=t),A.__funnelValueLabelX=w+x/2,A.__funnelValueLabelY=p,A.__funnelBarW=x),s.push(Qe(w,p,x,d,k,A,f)),m.set(f,{x:w,y:p,w:x,h:d})}}else{const t=n.stepTotal,e=b(t),c=a-e/2,h=u[0],f="_default"!==h,g=n.groups.get(h)?.pieces[0]??o.pieceData[0],x=f?h:o.name,v=r(g,x),w=y>0?t/y*100:0,k={...g,__funnelValue:t,__funnelPercent:w,__funnelStep:o.name,__funnelIsFirstStep:i,category:f?h:o.name};l&&(k.__funnelStepLabel=o.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(Qe(c,p,e,d,v,k,x)),m.set(h,{x:c,y:p,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const i of e){const e=v.get(i),a=m.get(i);if(!e||!a)continue;const l=(()=>{const t=n.groups.get(i);return r(t?t.pieces[0]:o.pieceData[0],"_default"===i?o.name:i)})(),c={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:x},datum:n.groups.get(i)?.pieces[0]??o.pieceData[0],category:"_default"===i?o.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:n,getR:o,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>n[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];for(const t of l){const e=new Map;let n=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=o(r);s.total+=a,s.pieces.push(r),n+=a}h.push({col:t,groups:e,stepTotal:n})}const f=new Map;for(const t of c){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,g=d?c.length:1,y=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],n=e.col,o=0===t,i=t>0?h[t-1]:null,s=n.width/g,l=s*y,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],g=e.groups.get(h);if(!g)continue;const y=g.total,m=f.get(h)??y,b=m>0?y/m*100:0,x=i?.groups.get(h),v=o?0:Math.max(0,(x?.total??y)-y),w=n.x+t*s+l/2,k=p(y),S=p(0)-k,A=r(g.pieces[0],d?h:n.name),M={...g.pieces[0],__barFunnelValue:y,__barFunnelPercent:b,__barFunnelIsFirstStep:o,__barFunnelIsDropoff:!1,__barFunnelStep:n.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:n.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(y+v)};if(a.push(Qe(w,k,u,S,A,M,d?h:n.name)),v>0){const t=p(y+v),e=k-t,o={...A},i={...g.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:n.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:n.name};a.push(Qe(w,t,u,e,o,i,d?h:n.name))}}}return a},swimlane:function(t,e){const{scales:n,columns:o,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:l}=n,c=[],u="horizontal"===l,d=t.config.gradientFill,h=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,[n,i]=a.range(),r=Math.min(n,i),s=Math.abs(i-n);for(const n of Object.values(o)){const o={fill:t,opacity:e},i=u?Qe(r,n.x,s,n.width,o,null,"__track__"):Qe(n.x,r,n.width,s,o,null,"__track__");c.push(i)}}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 n=c.length;for(const n of t.pieceData){const o=Math.abs(i(n));if(0===o)continue;const l=r?r(n):t.name,f=s(n,l);let p;if(u){const i=a(e),r=a(e+o);p=Qe(i,t.x,r-i,t.width,f,n,l)}else{const i=a(e+o),r=a(e);p=Qe(t.x,i,t.width,r-i,f,n,l)}d&&(p.fillGradient=d,p.roundedEdge=h),c.push(p),e+=o}if(p>0&&c.length>n){const t=c.slice(n),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 c}},rx=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sx=["scene-style","data-paint","accessibility","evidence"],ax=(t,e)=>({retainedData:t,invalidations:e}),lx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],cx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ux=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],dx=["scene-geometry","data-paint","accessibility","evidence"],hx=["scene-style","data-paint","accessibility","evidence"],fx=[],px={chartType:ax("rebuild",lx),runtimeMode:ax("rebuild",lx),categoryAccessor:ax("rebuild",lx),valueAccessor:ax("rebuild",lx),oAccessor:ax("rebuild",lx),rAccessor:ax("rebuild",lx),stackBy:ax("rebuild",lx),groupBy:ax("rebuild",lx),timeAccessor:ax("rebuild",lx),accessorRevision:ax("rebuild",lx),colorAccessor:ax("rebuild",hx),symbolAccessor:ax("rebuild",dx),connectorAccessor:ax("rebuild",dx),dataIdAccessor:ax("rebuild",dx),projection:ax("preserve",cx),extentPadding:ax("preserve",cx),axisExtent:ax("preserve",cx),rExtent:ax("preserve",cx),oExtent:ax("preserve",cx),multiAxis:ax("preserve",cx),normalize:ax("preserve",cx),bins:ax("preserve",cx),oSort:ax("preserve",ux),barPadding:ax("preserve",ux),roundedTop:ax("preserve",ux),baselinePadding:ax("preserve",ux),innerRadius:ax("preserve",ux),cornerRadius:ax("preserve",ux),startAngle:ax("preserve",ux),sweepAngle:ax("preserve",ux),trackFill:ax("preserve",ux),showOutliers:ax("preserve",ux),showIQR:ax("preserve",ux),amplitude:ax("preserve",ux),connectorOpacity:ax("preserve",ux),showLabels:ax("preserve",ux),dynamicColumnWidth:ax("rebuild",ux),customLayout:ax("preserve",ux),layoutConfig:ax("preserve",ux),layoutMargin:ax("preserve",ux),symbolMap:ax("preserve",dx),pieceStyle:ax("preserve",hx),summaryStyle:ax("preserve",hx),connectorStyle:ax("preserve",hx),gradientFill:ax("preserve",hx),colorScheme:ax("preserve",hx),themeCategorical:ax("preserve",hx),themeSemantic:ax("preserve",hx),themeSequential:ax("preserve",hx),themeDiverging:ax("preserve",hx),barColors:ax("preserve",hx),decay:ax("preserve",hx),pulse:ax("preserve",hx),staleness:ax("preserve",hx),layoutSelection:ax("preserve",hx),windowSize:ax("preserve",fx),windowMode:ax("preserve",fx),clock:ax("preserve",fx),transition:ax("preserve",fx),introAnimation:ax("preserve",fx),onLayoutError:ax("preserve",fx)},gx=ax("preserve",ux),yx=class{constructor(){this.tracker=new Jn}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}},rx)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},sx):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const n=new Set;for(const o of t){const t=px[o]??gx;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)n.add(e)}return{retainedData:e,invalidations:n}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as mx}from"d3-quadtree";var bx=class{constructor(t){this.rExtent=new Oe,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new yx,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Zb,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 $e(t.windowSize),this.getO=b(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>f(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Oe)):(this.getR=f(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=b(t.stackBy),this.getGroup=b(t.groupBy),this.getColor=b(t.colorAccessor),this.getSymbol=b(t.symbolAccessor),this.getConnector=b(t.connectorAccessor),this.getDataId=b(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new $e(t.windowSize))}syncPulseTimestampBuffer(){var t,e,n,o;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,n=this.timestampBuffer,o=this.currentTime(),t?null!=n&&n.capacity===e.capacity&&n.size===e.size?n:Nn(e,o):null)}currentTime(){return this.config.clock?.()??Ne()}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(),En(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const n of t.inserts)Bn(this.buffer,n,this.timestampBuffer,e),this.categories.add(this.getO(n)),this.pushValueExtent(n)}else{this._hasStreamingData=!0;for(const n of t.inserts){const t=Bn(this.buffer,n,this.timestampBuffer,e);this.categories.add(this.getO(n)),this.pushValueExtent(n),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 n="function"==typeof e?e(t):t[e];return Array.isArray(n)&&n.length>=2?[+n[0],+n[1]]:null}computeScene(t){const{config:e,buffer:n}=this,o=this.scales,i=this.multiScales,r=this.columns;if(0===n.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(n,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let f,p;if(d){f=Ub().domain(l).range([0,1]).padding(0);const n=Math.min(t.width,t.height)/2,o=e.innerRadius||0;p=Kb().domain(c).range([o,n])}else u?(f=Ub().domain(l).range([0,t.height]).padding(h),p=Kb().domain(c).range([0,t.width])):(f=Ub().domain(l).range([0,t.width]).padding(h),p=Kb().domain(c).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((o,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(n,o);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?Kb().domain([s,a]).range([0,t.width]):Kb().domain([s,a]).range([t.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(t=>this.rAccessors.map((e,n)=>({...t,__rIndex:n,__rValue:e(t),__rName:this.resolveRAccessorName(n)})))),this.columns=this.buildColumns(g,l,f,a,t),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,n=Array.isArray(e)?e[t]:e;return"string"==typeof n?n:"value"+t}resolveCategories(t){const e=this.config.oSort,n="streaming"===this.config.runtimeMode||this._hasStreamingData,o="auto"===e?void 0:e;let i=null;if(n){i=new Set;for(const e of t)i.add(this.getO(e))}const r=i?Array.from(this.categories).filter(t=>i.has(t)):Array.from(this.categories);if(n&&void 0===o){const t=Math.max(50,3*i.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;i.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===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:n,projection:o,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===o&&("pie"===n||"donut"===n))return[0,1];let p=0,g=0;if("bar"===n&&d&&i)p=0,g=1;else if("bar"===n&&d){const t=new Map,n=new Map;for(const o of e){const e=c(o),i=u(o);0>i?n.set(e,(n.get(e)||0)+i):t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>g&&(g=e);for(const t of n.values())p>t&&(p=t)}else if("bar"===n){const t=new Map;for(const n of e){const e=c(n),o=u(n);t.set(e,(t.get(e)||0)+o)}for(const e of t.values())e>g&&(g=e),p>e&&(p=e)}else if("swimlane"===n){const t=new Map;for(const n of e){const e=c(n),o=Math.abs(u(n));t.set(e,(t.get(e)||0)+o)}for(const e of t.values())e>g&&(g=e)}else if("clusterbar"===n||"bar-funnel"===n)for(const t of e){const e=u(t);e>g&&(g=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(g=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===n||"clusterbar"===n||"bar-funnel"===n||"swimlane"===n;if(y&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>g&&(g=0)),"bar-funnel"!==n&&"exact"!==l){const t=g-p,e=t>0?t*f:1,o=y&&!a&&0===p,i=y&&!a&&0===g||"swimlane"===n;null!=r?.[0]||o||(p-=e),null!=r?.[1]||i||(g+=e)}return[p,g]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,n,o,i){return function(t){const{data:e,oExtent:n,oScale:o,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=t,c={},u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(l(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of n){const n=u.get(e)||[];let o;o="string"==typeof s?n.reduce((t,e)=>t+(Number(e[s])||0),0):s(n),h.set(e,o),t+=o}const e=("horizontal"===i?r.height:r.width)-o.padding()*o.step()*n.length;if(t>0)for(const[n,o]of h)h.set(n,o/t*e)}let f=0,p=0;for(const t of n){const e=u.get(t)||[],n=e.reduce((t,e)=>t+Math.abs(l(e)),0),i=d>0?n/d:0;let r,s;h?(r=p,s=h.get(t)||o.bandwidth(),p+=s+o.padding()*o.step()):(r=o(t)??0,s=o.bandwidth()),c[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:o.padding()*o.step(),pieceData:e,pct:i,pctStart:f},f+=i}return c}({data:t,oExtent:e,oScale:n,projection:o,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const n=this.buildLayoutContext(t,e);let o;try{o=this.config.customLayout(n)}catch(t){const e=null!==this.lastCustomLayoutResult,n=Ln("ordinal",t,e,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=o.overlays??null,this.lastCustomLayoutResult=o,this.lastCustomLayoutFailure=null;const i=o.nodes??[];if(this._customRestyle=o.restyle,this.hasCustomRestyle=!!o.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of i)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return _n({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const n=this.getSceneContext(),o=ix[this.config.chartType];let i=o?o(n,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:n,config:o,getConnector:i,getO:r}=t;if(!i||!n)return[];const s=[],{projection:a}=n,l=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const n=i(e);if(!n)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)),l.has(n)||l.set(n,[]),l.get(n).push({x:o,y:s,datum:e,category:r(e)})}const c=n.o.domain(),u=o.connectorStyle;for(const[e,n]of l)if(n.length>=2){n.sort((t,e)=>c.indexOf(t.category)-c.indexOf(e.category));for(let o=0;n.length-1>o;o++){const i=n[o],r=n[o+1],a="function"==typeof u?u(i.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:i.x,y1:i.y,x2:r.x,y2:r.y,style:a,datum:i.datum,group:e})}}return s}(n,i);i=[...t,...i]}return i}buildLayoutContext(t,e){const n=this.config,o=n.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Iy(n.colorScheme,n.themeCategorical,xt),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:n.themeSemantic??{},categorical:[...i]},resolveColor:$y(i,n.colorScheme),config:n.layoutConfig??{},selection:n.layoutSelection??null}}computeDecayOpacity(t,e){const n=this.config.decay;return n&&e>1?Be(n,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=We(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 n="function"==typeof e,o=n?null:e||"category",i=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=n?e(s):s[o],l=i.get(a);l?l.push(r):i.set(a,[r])}return i}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,n=0;for(const o of t)"point"===o.type&&(e++,o.r>n&&(n=o.r));if(500>=e)return{quadtree:null,maxRadius:n};const o=Array(e);let i=0;for(const e of t)"point"===e.type&&(o[i++]=e);return{maxRadius:n,quadtree:mx().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 n=e.length;if(1>=n)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 i=this.computeDecayOpacity(t,n);e.style={...e.style,opacity:(e.style?.opacity??1)*i}}}applyPulse(t,e,n=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,n,o,i,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;for(const c of e){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const e=c.category;if(!e)continue;let o=0;for(const s of i(e)??[]){const e=n.get(s);null!=e&&(o=Math.max(o,je(t,e,r)))}l=Ye(c,o,s)||l;continue}if(null==c.datum)continue;const e=o.get(c.datum);if(null==e)continue;const u=n.get(e);l=Ye(c,null==u?0:je(t,u,r),s,a)||l}return l}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),n)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Xe(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,n="horizontal"!==this.scales?.projection;let o;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,n?{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 n=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,o=e.get(n)||0;return e.set(n,o+1),`${n}:${o}`}if("rect"===t.type){const n=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",o=`r:${t.group||""}:${n}`,i=e.get(o)||0;return e.set(o,i+1),0===i?o:`${o}:${i}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const n=this.scene[e],o=this.getNodeKey(n,t);o&&("point"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,r:n.r,opacity:n.style.opacity??n.style.fillOpacity}):"rect"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,w:n.w,h:n.h,opacity:n.style.opacity??n.style.fillOpacity}):"wedge"===n.type&&this.prevPositionMap.set(o,{x:n.cx,y:n.cy,startAngle:n.startAngle,endAngle:n.endAngle,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:n.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 n=new Set,o=new Map;for(let t=0;this.scene.length>t;t++){const i=this.scene[t],r=this.getNodeKey(i,o);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},e=!0);else if("rect"===i.type)s?(n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,e=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const t=i.startAngle;i.startAngle=t,i.endAngle=t,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:t,endAngle:t,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,o]of this.prevPositionMap)if(!n.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,n={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(n)}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=De(t,this.activeTransition),n=Fe(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=Ee(o?o.opacity??1:0,t._targetOpacity,n)}const o=this.prevPositionMap.get(e);void 0!==t._targetX&&o&&(t.x=Ee(o.x,t._targetX,n),t.y=Ee(o.y,t._targetY,n)),void 0!==t._targetR&&void 0!==o?.r&&(t.r=Ee(o.r,t._targetR,n))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=this.prevPositionMap.get(e);t.style.opacity=Ee(o?o.opacity??1:0,t._targetOpacity,n)}if(void 0===t._targetX)continue;const o=this.prevPositionMap.get(e);if(!o)continue;t.x=Ee(o.x,t._targetX,n),t.y=Ee(o.y,t._targetY,n),void 0!==o.w&&(t.w=Ee(o.w,t._targetW,n),t.h=Ee(o.h,t._targetH,n))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const o=this.prevPositionMap.get(e);t.style={...t.style,opacity:Ee(o?o.opacity??1:0,t._targetOpacity,n)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const o=this.prevPositionMap.get(e);o&&void 0!==o.startAngle&&(t.startAngle=Ee(o.startAngle,t._targetStartAngle,n),t.endAngle=Ee(o.endAngle,t._targetEndAngle,n))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=ze(t),n=this.getDataId,o=t=>e.has(n(t));Wn(this.buffer,this.timestampBuffer,o);const i=this.buffer.remove(o);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const n=ze(t),o=this.getDataId,i=new Set;this.buffer.forEach((t,e)=>{n.has(o(t))&&i.add(e)});const r=this.buffer.update(t=>n.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)),i.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const n=this._customRestyle;if(n)for(const o of t){const t=this._baseStyles.get(o)??o.style??{},i=n(o,e);o.style=i?{...t,...i}: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 n={...this.config},o=Object.keys(e).filter(t=>e[t]!==n[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==n.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${n.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!==n.colorScheme||"themeCategorical"in e&&e.themeCategorical!==n.themeCategorical||"colorAccessor"in e&&!t(e.colorAccessor,n.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!t(e.categoryAccessor,n.categoryAccessor)||"oAccessor"in e&&!t(e.oAccessor,n.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in e||"oAccessor"in e)&&(t(this.config.categoryAccessor||this.config.oAccessor,n.categoryAccessor||n.oAccessor)||(this.getO=b(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let r=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,o=n.valueAccessor||n.rAccessor,i=Array.isArray(e)?e:[e],s=Array.isArray(o)?o:[o];if(r=i.length!==s.length||i.some((e,n)=>!t(e,s[n])),r){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>f(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Oe)):(this.getR=f(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!t(e.stackBy,n.stackBy)&&(this.getStack=null!=this.config.stackBy?b(this.config.stackBy):void 0),"groupBy"in e&&!t(e.groupBy,n.groupBy)&&(this.getGroup=null!=this.config.groupBy?b(this.config.groupBy):void 0),"colorAccessor"in e&&!t(e.colorAccessor,n.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?b(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!t(e.symbolAccessor,n.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?b(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!t(e.connectorAccessor,n.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?b(this.config.connectorAccessor):void 0),(i||r||"accessorRevision"in e&&e.accessorRevision!==n.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Un(bx);import{jsx as xx,jsxs as vx}from"react/jsx-runtime";import{Fragment as wx,jsx as kx,jsxs as Sx}from"react/jsx-runtime";function Ax(t,e){const n=T(t.theme),o=t.size||[500,400],i=Bs({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Es(t.title),s=j(t.data),a=t.showLegend?kb(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=t.projection||"vertical",c={hasAxis:!1!==t.showAxes&&"radial"!==l,hasAxisLabel:"horizontal"===l?!(!t.valueLabel&&!t.rLabel):!(!t.categoryLabel&&!t.oLabel)};Bb(i,{props:{...t,axisChrome:c},categories:a,theme:n,size:o,hasTitle:r});const u=o[0]-i.left-i.right,d=o[1]-i.top-i.bottom,h=t.projection||"vertical",f="radial"===h,p=t.colorScheme||n.colors.categorical,g={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:Nt(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:p,themeCategorical:n.colors.categorical,themeSemantic:w(n),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},y=new bx(g);if(t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d}),!y.scales||0===y.scene.length)return e&&(e.evidence=lb({frameType:"ordinal",width:o[0],height:o[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Vb.renderToStaticMarkup(Yb(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:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,idPrefix:t._idPrefix}));const m=t._idPrefix,b=t.showGrid?function(t,e,n,o,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=I(n),a=o?o+"-":"",l="vertical"===r.projection,c=Is(r.r,5,i);return Ib("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,n)=>{const o=r.r(t);return Ib("line",{x1:0,y1:o,x2:e.width,y2:o,stroke:s,strokeWidth:.5},"gr-"+n)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,n)=>{const o=r.r(t);return Ib("line",{x1:o,y1:0,x2:o,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+n)})})}(y,{width:u,height:d},n,m,t.axisExtent):null;let x=null;if(y.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=zb(t),o=new Set;for(const t of y.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:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return vx("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&xx("rect",{width:a,height:a,fill:n}),xx("line",{x1:0,y1:0,x2:0,y2:a,stroke:o,strokeWidth:i}),xx("line",{x1:r,y1:0,x2:r,y2:a,stroke:o,strokeWidth:i})]},e)}({id:`funnel-hatch-${e}-${o}`,background:t,stroke:"transparent"===n.colors.background?"#fff":n.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(o).forEach((t,n)=>i.set(t,`funnel-hatch-${e}-${n}`));for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${i.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const v=Kc({nodes:y.scene,renderMode:t.renderMode,fallback:(t,e)=>Aa(t,e,m)}),k=v.map(t=>t.element);if(e){const n=y.scales.o?.domain?.();e.evidence=lb({frameType:"ordinal",width:o[0],height:o[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,yDomain:ab(y.scales.r?.domain?.()),categories:Array.isArray(n)?n.map(String):void 0,margin:i})}const S=!1!==t.showAxes?function(t,e,n,o,i){const r=t.scales;if(!r)return null;if("radial"===r.projection)return null;const s=I(o),a="vertical"===r.projection,l=n.categoryFormat||n.oFormat,c=n.valueFormat||n.rFormat,u=n.categoryLabel||n.oLabel,d=n.valueLabel||n.rLabel,h=Object.values(t.columns).map(t=>({pixel:t.middle,label:(l||String)(t.name)})),f=Is(r.r,5,n.axisExtent).map(t=>({pixel:r.r(t),label:(c||jb)(t)}));return Sx("g",a?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[kx("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,n)=>Sx("g",{transform:`translate(${t.pixel},${e.height})`,children:[kx("line",{y2:5,stroke:s.border,strokeWidth:1}),kx("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+n)),u&&kx("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),kx("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,e)=>Sx("g",{transform:`translate(0,${t.pixel})`,children:[kx("line",{x2:-5,stroke:s.border,strokeWidth:1}),kx("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),d&&kx("text",{x:15-(n.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(n.margin?.left??40)}, ${e.height/2})`,children:d})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[kx("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,n)=>Sx("g",{transform:`translate(${t.pixel},${e.height})`,children:[kx("line",{y2:5,stroke:s.border,strokeWidth:1}),kx("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+n)),d&&kx("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:d}),kx("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,e)=>Sx("g",{transform:`translate(0,${t.pixel})`,children:[kx("line",{x2:-5,stroke:s.border,strokeWidth:1}),kx("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),u&&kx("text",{x:15-(n.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(n.margin?.left??40)}, ${e.height/2})`,children:u})]})}(y,{width:u,height:d},t,n,m):null,A=t.annotations?Rb({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:u,height:d},theme:n,projection:h,idPrefix:m}):null,M=Wb({props:{...t,axisChrome:c},categories:a,theme:n,size:o,margin:i,hasTitle:r}),_=f?i.left+u/2:i.left,P=f?i.top+d/2:i.top,C=f&&t.centerContent?kx("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:kx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null;return Vb.renderToStaticMarkup(Yb(Sx(wx,{children:[t.backgroundGraphics,b,k,S,A,t.foregroundGraphics,y.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:n,innerTransform:`translate(${_},${P})`,innerWidth:u,innerHeight:d,legend:M,defs:x,outerElements:C,idPrefix:t._idPrefix}))}import*as Mx from"react-dom/server";function _x(t,e){var n=t.get(e);if(!n)throw Error("missing: "+e);return n}function Px(t,e){var n,o=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(t){var e,o,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(o=a[t][e])===n?(u(n,i),d=!0):r[o]||(d=c(o));if(d)l(t);else for(e=0;a[t].length>e;e++){var h=s[o=a[t][e]];h||(s[o]=h={}),h[o]=!0}return i.pop(),d}function u(t,n){var i=[].concat(n).concat(t);e?e(i):o.push(i)}function d(e){!function(e){for(var n=0;t.length>n;n++)n>=e&&t[n]||(t[n]=[]),t[n]=t[n].filter(function(t){return t>=e})}(e);for(var n,o=function(t){for(var e=t.length,n=Array(e),o=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),l=0;e>l;++l)n[l]=-1,o[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function f(e){var l=[e],c=[e];for(n[e]=o[e]=u,i[e]=!0,u+=1;c.length>0;){var f=t[e=c[c.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var g=f[p];if(0>n[g]){n[g]=o[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(o[e]=0|Math.min(o[e],o[g])),0>s[g]||a[e].push(s[g])}r[e]=p}else{if(o[e]===n[e]){var y=[],m=[],b=0;for(p=l.length-1;p>=0;--p){var x=l[p];if(i[x]=!1,y.push(x),m.push(a[x]),b+=a[x].length,s[x]=d.length,x===e){l.length=p;break}}d.push(y);var v=Array(b);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--b]=m[p][w];h.push(v)}c.pop()}}}for(l=0;e>l;++l)0>n[l]&&f(l);for(l=0;h.length>l;l++){var p=h[l];if(0!==p.length){p.sort(function(t,e){return t-e}),c=[p[0]];for(var g=1;p.length>g;g++)p[g]!==p[g-1]&&c.push(p[g]);h[l]=c}}return{components:d,adjacencyList:h}}(t),i=o.components.filter(function(t){return t.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],n=s);var l=i[n];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})})}}n=0;for(var h=t.length;h>n;){var f=d(n);if(n=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var g=0;a[p].length>g;g++){var y=a[p][g];r[+y]=!1,s[y]={}}c(n),n+=1}else n=h}return e?void 0:o}function Cx(t){return t.y0-t.y1>0?"up":"down"}function Lx(t,e){return e(t.source)==e(t.target)}function Rx(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var n=0;return t.target.targetLinks.forEach(function(t){n=t.circular?n+1:n}),1>=e&&1>=n}function Tx(t){return t.target.x0-t.source.x1}function Ix(t,e){var n=Ox(t),o=Tx(e)/Math.tan(n);return"up"==Cx(t)?t.y1-o:t.y1+o}function $x(t,e){var n=Ox(t),o=Tx(e)/Math.tan(n);return"up"==Cx(t)?t.y1+o:t.y1-o}function Ox(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function zx(t,e){return e(t)}function Fx(t){return Ex(t.source)}function Dx(t){return Ex(t.target)}function Ex(t){return(t.y0+t.y1)/2}function Nx(t){return t.virtual?0:t.value}function Bx(t,e){var n=0;t.sourceLinks.forEach(function(t){n=t.circular&&!Lx(t,e)?n+1:n});var o=0;return t.targetLinks.forEach(function(t){o=t.circular&&!Lx(t,e)?o+1:o}),n+o}function Wx(t){return t.target.depth}function jx(t,e){return t.sourceLinks.length?t.depth:e-1}function Yx(t,e){return t.y0-e.y0}function Xx(t,e){return e.y0-t.y0}function Hx(t,e){return t.y1-e.y1}function Gx(t,e){return e.y1-t.y1}function qx(t,e){return Ux(t.source,e.source)||t.index-e.index}function Vx(t,e){return Ux(t.target,e.target)||t.index-e.index}function Ux(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Kx(t,e){return Zx(t)==Zx(e)?"bottom"==t.circularLinkType?Xx(t,e):Yx(t,e):Zx(e)-Zx(t)}function Zx(t){return t.target.column-t.source.column}function Qx(t,e){return Jx(t)==Jx(e)}function Jx(t){return t.y0-t.y1>0?"up":"down"}import{min as tv}from"d3-array";function ev(t,e,n,o,i){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=tv(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=r.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),nv(r.links.filter(function(t){return"top"==t.circularLinkType}),e,n),nv(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,n),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,Lx(t,e)&&Rx(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+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,l=t.circularLinkType,c=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==l});c.sort("bottom"==t.circularLinkType?Xx:Yx);var u=0;c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=o+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=o+t._circularWidth/2+i*n+u),u+=e._circularWidth||e.width}),s=t.target.column,(c=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?Gx:Hx),u=0,c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=o+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=o+t._circularWidth/2+i*n+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,n=t.y0,o=t.target.x0,i=t.y1,r=(e+o)/2;return"M"+e+","+n+"C"+r+","+n+" "+r+","+i+" "+o+","+i}(t)}),r}function nv(t,e,n){t.sort(Kx);var o=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,i){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(Lx(t,e)&&Rx(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&&ov(t,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+n;r=l>r?l:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function ov(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as iv,max as rv,sum as sv,mean as av,group as lv,groups as cv}from"d3-array";function uv(t){return function(){return t}}function dv(t){return t.index}function hv(t){return t.nodes}function fv(t){return t.links}function pv(t,e,n){var o=cv(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(i,r){var s=i.length;if(e)i.sort(e);else if(r>0){var a=new Map;i.forEach(function(t,e){var n,o,i,r=(o=0,i=0,(n=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Ex(t.source)*e,o+=e}}),n.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Ex(t.target)*e,o+=e}}),o>0?i/o:NaN);a.set(t,{bc:r,idx:e})}),i.sort(function(t,e){var n=a.get(t),o=a.get(e),i=n.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(i)||isNaN(r)?isNaN(i)?isNaN(r)?n.idx-o.idx:1:-1:i-r})}else i.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Bx(e,n)-Bx(t,n):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});i.forEach(function(e,i){e.depth==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==Bx(e,n)?(e.y0=t.y1/2+i,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+i,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-i,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*i,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+i,e.y1=e.y0+e.value*t.ky)})})}function gv(t,e,n,o,i,r){var s=cv(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,l=r;l>0;--l)c(a*=.99,n),u();function c(e,n){var o=s.length;s.forEach(function(i){var r=i.length,s=i[0].depth;i.forEach(function(i){var a;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&Bx(i,n)>0){var l=av(i.sourceLinks,Dx),c=av(i.targetLinks,Fx),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Ex(i))*e*.3;i.y0+=d,i.y1+=d}}else if(0==s&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(s==o-1&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(1==i.targetLinks.length&&1==i.targetLinks[0].source.sourceLinks.length)a=i.y1-i.y0,i.y0=i.targetLinks[0].source.y0,i.y1=i.y0+a;else{var h=av(i.sourceLinks,Dx),f=av(i.targetLinks,Fx),p=((h&&f?(h+f)/2:h||f)-Ex(i))*e;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(n){var r,s,a,l=t.y0,c=n.length;for(n.sort(e||Ux),a=0;c>a;++a)(s=l-(r=n[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+o;if((s=l-o-t.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=n[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function yv(t){t.nodes.forEach(function(t){t.sourceLinks.sort(Vx),t.targetLinks.sort(qx)}),t.nodes.forEach(function(t){var e=t.y0,n=e,o=t.y1,i=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=i-t.width/2,i-=t.width):(t.y1=n+t.width/2,n+=t.width)})})}function mv(){var t=0,e=0,n=1,o=1,i=24,r=8,s=null,a=dv,l=jx,c=void 0,u=32,d=2,h=hv,f=fv;function p(){var p={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=n,h.y1=o,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var n=function(t,e){var n=new Map;return lv(t,e).forEach(function(t,e){n.set(e,t[0])}),n}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var o=t.source,i=t.target;"object"!=typeof o&&(o=t.source=_x(n,o)),"object"!=typeof i&&(i=t.target=_x(n,i)),o.sourceLinks.push(t),i.targetLinks.push(t)})}(h,a),function(t,e){var n=0;if(null==e){for(var o=[],i=0;t.links.length>i;i++){var r=t.links[i],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 l=Px(o);l.sort(function(t,e){return t.length-e.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,o=t.source.index;e===o||c[o]&&c[o][e]?(t.circular=!0,t.circularLinkID=n++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=n++)})}(h,c),function(t,e){var n=0,o=0;t.links.forEach(function(i){i.circular&&(i.circularLinkType=i.source.circularLinkType||i.target.circularLinkType?i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:o>n?"top":"bottom","top"==i.circularLinkType?n++:o++,t.nodes.forEach(function(t){zx(t,e)!=zx(i.source,e)&&zx(t,e)!=zx(i.target,e)||(t.circularLinkType=i.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),Lx(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(sv(t.sourceLinks,Nx),sv(t.targetLinks,Nx)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,n){var o,i,r;if(null!=e){t.nodes.sort(function(t,n){return e(t)<e(n)?-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,i=[],r=0;o.length;++r,o=i,i=[])o.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(o=t.nodes,i=[],r=0;o.length;++r,o=i,i=[])o.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>i.indexOf(t.source)&&!t.circular&&i.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?n(t,r):t.column})}(h,c,l);var f=r;if(null!==s){var p=cv(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),g=rv(p,function(t){return t.length});g>1&&(f=Math.max(1,(o-e)*s/(g-1)))}(function(t,e,n){var o=cv(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var i=iv(o,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/sv(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=rv(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-n)/r),e.x1=e.x0+n}:function(e){e.x0=t.x0,e.x1=e.x0+n})})(h,f,i),pv(h,c,a),gv(h,c,a,f,f,u),yv(h),ev(h,a,d,10,8),pv(h,c,a),gv(h,c,a,f,f,u),yv(h),ev(h,a,d,10,8),function(t,e){let n=t;n.nodes.forEach(function(t){t.y+(t.y1-t.y0)>n.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-n.y1));var o=n.links.filter(function(n){return zx(n.source,e)==zx(t,e)}),i=o.length;i>1&&o.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!Qx(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var n=Ix(e,t);return t.y1-n}if(e.target.column>t.target.column)return Ix(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,n){if("bottom"==e.circularLinkType){for(var r=n+1,s=0;i>r;r++)s+=o[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let n=t;n.nodes.forEach(function(t){var o=n.links.filter(function(n){return zx(n.target,e)==zx(t,e)}),i=o.length;i>1&&o.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!Qx(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var n=$x(e,t);return t.y0-n}if(e.source.column>t.source.column)return $x(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,n){if("bottom"==e.circularLinkType){for(var r=n+1,s=0;i>r;r++)s+=o[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,n=t.links,o=!1,i=!1;if(n.forEach(function(t){"top"==t.circularLinkType?o=!0:"bottom"==t.circularLinkType&&(i=!0)}),0==o||0==i){let o=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=iv(e,function(t){return t.y0}),s=rv(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)}),n.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,n=o(t.y0)-t.y0;t.y0=o(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+n}),t.targetLinks.forEach(function(t){t.y1=t.y1+n})})}}(h),ev(h,a,d,10,8)}(p),p}return p.update=function(t){return yv(t),ev(t,a,d,10,8),t},p.nodeWidth=function(t){return arguments.length?(i=+t,p):i},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?(h="function"==typeof t?t:uv(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:uv(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:uv(t),p):a},p.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:uv(t),p):l},p.nodeSort=function(t){return arguments.length?(c=t,p):c},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(d=+t,p):d},p.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],n=+i[1][0],o=+i[1][1],p):[[t,e],[n,o]]},p.size=function(i){return arguments.length?(t=e=0,n=+i[0],o=+i[1],p):[n-t,o-e]},p}import{interpolateNumber as bv}from"d3-interpolate";import{line as xv,curveLinearClosed as vv}from"d3-shape";var wv=t=>{let e,n,o,i,r,s,a,l,c;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,n=t.y1-t.sankeyWidth/2,o=t.y1+t.sankeyWidth/2,i=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=bv(r,s),l=a(.5),c=a(.5),`M${e},${r}C${e},${l} ${n},${c} ${n},${s}L${o},${s}C${o},${c} ${i},${l} ${i},${r}Z`;const u=t.sankeyWidth/2,d=bv(t.source.x1,t.target.x0),{pathD:h}=cp({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function kv(t){const e=t.sankeyWidth/2,n=(t._circularWidth??t.sankeyWidth)/2,o=t.circularPathData;if(!o)return null;if("down"===t.direction)return null;if(t._circularStub){const n=o.sourceX,i=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-n))),l=Math.max(15,Math.min(40,.33*(r-o.leftFullExtent)));return`M${n},${i-e}L${n+a},${i-e}L${n+a},${i+e}L${n},${i+e}ZM${r},${s-e}L${r-l},${s-e}L${r-l},${s+e}L${r},${s+e}Z`}const i=o.sourceX,r=o.sourceY,s=o.targetX,a=o.targetY,l=o.rightFullExtent,c=o.leftFullExtent,u=o.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(n,15));return`M${i},${r-d*e}L${l},${r-d*e}L${l+n},${r-d*e+d*h}L${l+n},${u+d*n-d*h}L${l+n-h},${u+d*n}L${c-n+h},${u+d*n}L${c-n},${u+d*n-d*h}L${c-n},${a-d*e+d*h}L${c-n+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${c+n},${a+d*e}L${c+n},${u-d*n}L${l-n},${u-d*n}L${l-n},${r+d*e}L${i},${r+d*e}Z`}var Sv=new Set,Av=new WeakMap;function Mv(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let n=Av.get(t);if(n){const t=n.get(e);if(t)return t}else n=new Map,Av.set(t,n);const o=new Proxy(t,{get(t,n,o){if("string"==typeof n&&!(n in t)&&t.data&&n in t.data){const t=`${e}:${n}`;Sv.has(t)||(Sv.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${n}" on the wrapper object, but it only exists on ".data". Use d.data.${n} (or d.data?.${n}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,n,o)}});return n.set(e,o),o}var _v={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(Wx))-1:0},justify:jx},Pv={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,n,o){if(0===t.length)return;const i="vertical"===n.orientation?"down":"right",r=n.nodeAlign||"justify",s=n.nodeWidth??15,a=n.nodePaddingRatio??.05,l=n.iterations??100,c=t.map(t=>({...t})),u=e.map(t=>({...t,source:g(t.source),target:g(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===i?[[0,0],[o[1],o[0]]]:[[0,0],[o[0],o[1]]];const h=mv().extent(d).links(u).nodes(c).nodeAlign(_v[r]||jx).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,n=1/0,i=-1/0;for(const o of c)t>o.x0&&(t=o.x0),o.x1>e&&(e=o.x1),n>o.y0&&(n=o.y0),o.y1>i&&(i=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),n>r.verticalFullExtent-s&&(n=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-n,a=o[0],l=o[1];if(r>0&&s>0&&(0>t||0>n||e>a||i>l)){const e=Math.min(a/r,l/s),o=-t*e+(a-r*e)/2,i=-n*e+(l-s*e)/2;for(const t of c)t.x0=t.x0*e+o,t.x1=t.x1*e+o,t.y0=t.y0*e+i,t.y1=t.y1*e+i;for(const t of u)if(t.y0=t.y0*e+i,t.y1=t.y1*e+i,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const n=t.circularPathData;n.sourceX=n.sourceX*e+o,n.targetX=n.targetX*e+o,n.sourceY=n.sourceY*e+i,n.targetY=n.targetY*e+i,n.rightFullExtent=n.rightFullExtent*e+o,n.leftFullExtent=n.leftFullExtent*e+o,n.verticalFullExtent=n.verticalFullExtent*e+i,n.rightInnerExtent=n.rightInnerExtent*e+o,n.leftInnerExtent=n.leftInnerExtent*e+o,n.verticalRightInnerExtent=n.verticalRightInnerExtent*e+i,n.verticalLeftInnerExtent=n.verticalLeftInnerExtent*e+i,n.rightSmallArcRadius*=e,n.rightLargeArcRadius*=e,n.leftSmallArcRadius*=e,n.leftLargeArcRadius*=e,n.sourceWidth*=e,n.rightNodeBuffer*=e,n.leftNodeBuffer*=e,n.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of c){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)if(t._edgeKey)p.set(t._edgeKey,t);else{const e=g(t.source),n=g(t.target);p.set(`${e}\0${n}`,t)}for(const t of u){const e=g(t.source),n=g(t.target),o=p.get(t._edgeKey?t._edgeKey:`${e}\0${n}`);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=i;const r=f.get(e),s=f.get(n);r&&(o.source=r),s&&(o.target=s)}}},buildScene(t,e,n,o){const i="vertical"===n.orientation?"down":"right",r=n.nodeStyle,s=n.edgeStyle,a=n.edgeOpacity??.5,l=n.edgeColorBy||"source",c=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:q,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.length])});const d=[],h=[],f=[],g=new Map;for(const e of t){const t=e.x1-e.x0,n=e.y1-e.y0;if(0>=t||0>=n)continue;const o=r?r(Mv(e,"nodeStyle")):{},s={fill:o.fill||u.get(e.id)||"#4d430c",stroke:o.stroke,strokeWidth:o.strokeWidth,opacity:o.opacity};g.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:e.y0,y:e.x0,w:n,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:n,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 i=n.themeSemantic?.border||n.themeSemantic?.secondary||"#999";i="function"==typeof l?l(t)||i:"target"===l?g.get(o.id)||u.get(o.id)||i:g.get(e.id)||u.get(e.id)||i;const r=s?s(Mv(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,n=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))),l=r.fill||i;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-n}L${e.sourceX+o},${e.sourceY-n}L${e.sourceX+o},${e.sourceY+n}L${e.sourceX},${e.sourceY+n}Z`,style:{fill:l,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}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-n}L${e.targetX-s},${e.targetY-n}L${e.targetX-s},${e.targetY+n}L${e.targetX},${e.targetY+n}Z`,style:{fill:l,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 c;(c=t.circular&&t.circularPathData?kv(t):wv(t),c)&&h.push({type:"bezier",pathD:c,bezierCache:t.bezier,style:{fill:r.fill||i,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity},datum:t})}if(!1!==n.showLabels){const e=p(n.nodeLabel);for(const n of t){const t=n.x1-n.x0,r=n.y1-n.y0;if(0>=t||0>=r)continue;const s=e?e(n):n.id;if(!s)continue;let a,l,c;"down"===i?(a=n.y0+(n.y1-n.y0)/2,l=n.x1+14,c="start"):(o[0]/2>n.x0+t/2?(a=n.x0-6,c="end"):(a=n.x1+6,c="start"),l=n.y0+r/2),f.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}};import{forceSimulation as Cv,forceCenter as Lv,forceX as Rv,forceY as Tv,forceLink as Iv,forceManyBody as $v,forceCollide as Ov}from"d3-force";import{scaleLinear as zv}from"d3-scale";var Fv={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,n,o){if(0===t.length)return;const i=n.forceStrength??.1,r=o[0]/2,s=o[1]/2,a=Math.max(.1,Math.min(1,Math.min(o[0],o[1])/200)),l=Math.min(.5,.06+1.8*(1-a)),c=n.__previousPositions;let u=0;const d=[];for(const e of t){const t=null!=e.x&&null!=e.y&&(0!==e.x||0!==e.y),n=c?.get(e.id);t?u++:n?(e.x=n.x,e.y=n.y,u++):d.push(e)}const h=u>0&&.3>=(t.length>0?d.length/t.length:1);if(h){const n=new Map;for(const e of t)n.set(e.id,e);for(const t of d){const o=Dv(t.id,e,n);if(o.length>0){let e=0,n=0;for(const t of o)e+=t.x,n+=t.y;const i=Ev(t.id),r=i%360*(Math.PI/180),s=(10+i%20)*a;t.x=e/o.length+s*Math.cos(r),t.y=n/o.length+s*Math.sin(r)}else{const e=Ev(t.id),n=e%360*(Math.PI/180),o=(15+e%30)*a;t.x=r+o*Math.cos(n),t.y=s+o*Math.sin(n)}}}else{const e=2.399963229728653;for(let n=0;t.length>n;n++){const o=t[n];if(null==o.x||null==o.y||0===o.x&&0===o.y){const t=10*Math.sqrt(n+.5)*a,i=n*e;o.x=r+t*Math.cos(i),o.y=s+t*Math.sin(i)}}}const f=n.__skipForceSimulation||0===n.iterations?0:h?40:n.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),p=Nv(n.nodeSize,n.nodeSizeRange,t),y=t=>p(t);if(f>0){const c=new Map,u=new Map;for(const e of t)c.set(e.id,0),u.set(e.id,e);for(const t of e){const e=g(t.source),n=g(t.target);c.set(e,(c.get(e)??0)+1),c.set(n,(c.get(n)??0)+1)}const d=Iv().strength(t=>{const e=t.weight,n=g(t.source),o=g(t.target),r=Math.max(1,Math.min(c.get(n)??1,c.get(o)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*i/(.1*r))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,n="string"==typeof t.target?u.get(t.target):t.target,o=(e?y(e):0)+(n?y(n):0)+Math.max(6,12*a);return Math.max(16,40*a,o)}).id(t=>t.id),p=Cv();if(void 0===n.random&&void 0===n.seed||p.randomSource(n.random??Jl(n.seed)),p.force("charge",$v().strength(t=>{const e=c.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",Ov(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",Lv(r,s).strength(.8)).force("x",Rv(r).strength(l)).force("y",Tv(s).strength(l)).force("bounds",function(t,e,n=2,o=.6){let i=[];const r=r=>{const s=o*Math.max(r,.2);for(const o of i){const i=o.x??t[0]/2,r=o.y??t[1]/2,a=o.vx??0,l=o.vy??0,c=e(o)+n,u=Math.min(t[0]/2,c),d=Math.max(t[0]/2,t[0]-c),h=Math.min(t[1]/2,c),f=Math.max(t[1]/2,t[1]-c),p=i+a,g=r+l;u>p?o.vx=a+(u-p)*s:p>d&&(o.vx=a+(d-p)*s),h>g?o.vy=l+(h-g)*s:g>f&&(o.vy=l+(f-g)*s)}};return r.initialize=t=>{i=t},r}(o,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:g(t.source),target:g(t.target)}));d.links(t),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let t=0;f>t;++t)p.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=y(e),n=f>0?2:0,i=Math.min(o[0]/2,t+n),r=Math.min(o[1]/2,t+n);e.x=Math.max(i,Math.min(o[0]-i,e.x)),e.y=Math.max(r,Math.min(o[1]-r,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const m=new Map;for(const e of t)m.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=m.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=m.get(t.target);e&&(t.target=e)}}},buildScene(t,e,n,o){const i=n.nodeStyle,r=n.edgeStyle,s=Nv(n.nodeSize,n.nodeSizeRange,t),a=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:q,l=new Map;t.forEach((t,e)=>{l.set(t.id,a[e%a.length])});const c=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(Mv(e,"nodeSize")),o=i?i(Mv(e,"nodeStyle")):{},r={fill:o.fill||l.get(e.id)||n.themeSemantic?.primary||"#007bff",stroke:o.stroke||n.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??2,opacity:o.opacity};c.push({type:"circle",cx:e.x,cy:e.y,r:t,style:r,datum:e,id:e.id,label:e.id})}const h=new Map;for(const e of t)h.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:h.get(t.source),o="object"==typeof t.target?t.target:h.get(t.target);if(!e||!o)continue;if(null==e.x||null==e.y)continue;if(null==o.x||null==o.y)continue;const i=r?r(Mv(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:i.stroke||n.themeSemantic?.border||n.themeSemantic?.secondary||"#999",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.6},datum:t})}if(!1!==n.showLabels){const e=p(n.nodeLabel);for(const n of t){if(null==n.x||null==n.y)continue;const t=e?e(n):n.id;if(!t)continue;const o=s(Mv(n,"nodeSize"));d.push({x:n.x,y:n.y-o-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function Dv(t,e,n){const o=[];for(const i of e){const e=g(i.source),r=g(i.target);let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=n.get(s);!t||0===t.x&&0===t.y||o.push({x:t.x,y:t.y})}}return o}function Ev(t){let e=0;for(let n=0;t.length>n;n++)e=(e<<5)-e+t.charCodeAt(n)|0;return Math.abs(e)}function Nv(t,e,n){if(n.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],i=[];for(const e of n){const n=e.data?.[t];"number"==typeof n&&i.push(n)}if(0===i.length)return()=>o[0];const[r,s]=_t(i);if(r===s)return()=>(o[0]+o[1])/2;const a=zv().domain([r,s]).range(o).clamp(!0);return e=>{const n=e.data?.[t];return null==n||"number"!=typeof n?o[0]:a(n)}}import{chord as Bv,ribbon as Wv}from"d3-chord";import{arc as jv}from"d3-shape";var Yv=q,Xv={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,n,o){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=n,a=Math.min(o[0],o[1])/2,l=a-r,c=o[0]/2,u=o[1]/2,d=(h=n.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;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=g(t.source),n=g(t.target),o=f.get(e),i=f.get(n);if(void 0===o||void 0===i)continue;const r=d(t);y[o][i]=r}const m=Bv().padAngle(i);s&&m.sortGroups(s);const b=m(y),x=b.groups,v=jv().innerRadius(l).outerRadius(a);for(const e of x){const n=t[e.index],o=v.centroid({innerRadius:l,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});n.x=o[0]+c,n.y=o[1]+u,n.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const w=new Map;for(const e of t)w.set(e.id,e);for(const t of e){const e=g(t.source),n=g(t.target),o=w.get(e),i=w.get(n);o&&(t.source=o),i&&(t.target=i)}const k=new Map;for(const t of e){const e=g(t.source),n=g(t.target);k.set(`${e}\0${n}`,t)}for(const e of b){const n=t[e.source.index].id,o=t[e.target.index].id,i=k.get(`${n}\0${o}`)||k.get(`${o}\0${n}`);i&&(i.__chordData=e)}},buildScene(t,e,n,o){const{groupWidth:i=20,edgeOpacity:r=.5}=n,s=Math.min(o[0],o[1])/2,a=s-i,l=o[0]/2,c=o[1]/2,u=n.nodeStyle,d=n.edgeStyle,h=n.edgeColorBy||"source",f=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:Yv,g=new Map;t.forEach((t,e)=>{g.set(t.id,f[e%f.length])});const y=Wv().radius(a),m=[],b=[],x=[];for(let e=0;t.length>e;e++){const n=t[e],o=n.__arcData;if(!o)continue;let i;i=u?u(Mv(n,"nodeStyle")).fill||g.get(n.id)||f[e%f.length]:g.get(n.id)||f[e%f.length];const r=u?u(Mv(n,"nodeStyle")):{};m.push({type:"arc",cx:l,cy:c,innerR:a,outerR:s,startAngle:o.startAngle-Math.PI/2,endAngle:o.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:n,id:n.id,label:n.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const o=y(e);if(!o)continue;const i=Hv(o,l,c);let s=n.themeSemantic?.border||n.themeSemantic?.secondary||"#999";if(d)s=d(Mv(t,"edgeStyle")).fill||s;else{const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;"target"===h&&n?s=g.get(n.id)||s:e&&(s=g.get(e.id)||s)}const a=d?d(Mv(t,"edgeStyle")):{};b.push({type:"ribbon",pathD:i,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity},datum:t})}if(!1!==n.showLabels){const e=p(n.nodeLabel),o=s+12;for(const n of t){const t=n.__arcData;if(!t)continue;const i=e?e(n):n.id;if(!i)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:l+Math.cos(s)*o,y:c+Math.sin(s)*o,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:m,sceneEdges:b,labels:x}}};function Hv(t,e,n){const o=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!o)return t;const i=[];let r=0;for(;o.length>r;){const t=o[r];if("M"===t||"L"===t)for(i.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)i.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("C"===t)for(i.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)for(let t=0;3>t&&o.length>r&&!isNaN(Number(o[r]));t++)i.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("Q"===t)for(i.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)for(let t=0;2>t&&o.length>r&&!isNaN(Number(o[r]));t++)i.push(Number(o[r])+e+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("A"===t)for(i.push(t),r++;o.length>r&&!isNaN(Number(o[r]));)i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&(i.push(Number(o[r])+e+""),r++),o.length>r&&(i.push(Number(o[r])+n+""),r++);else"Z"===t||"z"===t?(i.push(t),r++):(i.push(o[r]),r++)}return i.join(" ")}import{hierarchy as Gv,tree as qv,cluster as Vv,treemap as Uv,pack as Kv,partition as Zv,treemapBinary as Qv}from"d3-hierarchy";var Jv=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function tw(t){const[e,n,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*n+.114*o>150?"#222":"#fff"}function ew(t,e,n){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-"+n}function nw(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 ow(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Jv}function iw(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 rw(t,e,n,o,i){if("horizontal"===i){const i=(t+n)/2;return`M ${t},${e} C ${i},${e} ${i},${o} ${n},${o}`}if("radial"===i){const i=(t+n)/2;return`M ${t},${e} Q ${i},${e} ${i},${(e+o)/2} T ${n},${o}`}{const i=(e+o)/2;return`M ${t},${e} C ${t},${i} ${n},${i} ${n},${o}`}}var sw={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,n,o){const i=n.__hierarchyRoot;if(!i)return;const r=n.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(n.childrenAccessor),a=n.hierarchySum,l="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,c=Gv(i,s);c.sum(l),c.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=o;switch(r){case"tree":!function(t,e,n,o){const i=e.treeOrientation||"vertical",r=qv();r.size("horizontal"===i?[o,n]:"radial"===i?[2*Math.PI,Math.min(n,o)/2*.8]:[n,o]),r(t)}(c,n,u,d);break;case"cluster":!function(t,e,n,o){const i=e.treeOrientation||"vertical",r=Vv();r.size("horizontal"===i?[o,n]:"radial"===i?[2*Math.PI,Math.min(n,o)/2*.8]:[n,o]),r(t)}(c,n,u,d);break;case"treemap":!function(t,e,n,o){const i=e.padding??4,r=e.paddingTop??0,s=Uv().size([n,o]).tile(Qv).padding(i);r>0&&s.paddingTop(r),s(t)}(c,n,u,d);break;case"circlepack":!function(t,e,n,o){const i=e.padding??4;Kv().size([n,o]).padding(i)(t)}(c,n,u,d);break;case"partition":!function(t,e,n,o){Zv().size([n,o]).padding(e.padding??1)(t)}(c,n,u,d)}const h=c.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;h.length>e;e++){const o=h[e],i={id:ew(o,n,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?aw(i,o,n):"treemap"===r||"partition"===r?lw(i,o):"circlepack"===r&&cw(i,o),i.__hierarchyNode=o,t.push(i),f.set(o,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const n=f.get(t.parent),o=f.get(t);n&&o&&e.push({source:n,target:o,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,n,o){const i=n.nodeStyle||(()=>({})),r=n.edgeStyle||(()=>({}));switch(n.chartType){case"tree":case"cluster":return function(t,e,n,o,i,r){const s=[],a=[],l=[],c=n.treeOrientation||"vertical",u="radial"===c,d=o[0]/2,h=o[1]/2,f="number"==typeof(p=n.nodeSize)?p:5;var p;for(const e of t){let t=e.x,o=e.y;u&&(t+=d,o+=h);const r=i(Mv(e,"nodeStyle"));let a=r.fill||iw(n);if(n.colorByDepth&&void 0!==e.depth){const t=ow(n);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:o,r:f,style:{fill:a,stroke:r.stroke||n.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:e,id:e.id,label:e.id,depth:e.depth})}const g=n.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 i=e.x,s=e.y,l=o.x,f=o.y;u&&(i+=d,s+=h,l+=d,f+=h);const p=rw(i,s,l,f,c),y=r(Mv(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:y.stroke||n.themeSemantic?.border||n.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g},datum:t})}if(!1!==n.showLabels){const e=nw(n.nodeLabel);for(const n of t){const t=e?e(n):n.id;if(!t)continue;let o,i,r,s=n.x,a=n.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,n=Math.sqrt(t*t+e*e);n>0?(o=s+t/n*10,i=a+e/n*10,r=0>t?"end":"start"):(o=s,i=a-12,r="middle")}else"horizontal"===c?(n.data?.children&&0!==n.data.children.length?(o=s-f-6,r="end"):(o=s+f+6,r="start"),i=a):(o=s,i=a+f+14,r="middle");l.push({x:o,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(t,e,n,o,i,r);case"treemap":case"partition":return function(t,e,n,o){const i=[],r=[];for(const n of t){const t=n.x1-n.x0,r=n.y1-n.y0;if(0>=t||0>=r)continue;const s=o(Mv(n,"nodeStyle"));let a=s.fill||iw(e);if(e.colorByDepth&&void 0!==n.depth){const t=ow(e);a=t[n.depth%t.length]}i.push({type:"rect",x:n.x0,y:n.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==e.showLabels){const n=nw(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,l=a.y1-a.y0;if(0>=t||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=n?n(a):a.id;if(!u)continue;if((c?30:40)>t||(c?16:14)>l)continue;let d=o(Mv(a,"nodeStyle")).fill||iw(e);if(e.colorByDepth&&void 0!==a.depth){const t=ow(e);d=t[a.depth%t.length]}const h="string"==typeof d?tw(d):e.themeSemantic?.text??"#000";r.push(c?{x:a.x0+t/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,l)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,n,0,i);case"circlepack":return function(t,e,n,o){const i=[],r=[];for(const n of t){const t=n.__radius??5;if(0>=t)continue;const r=o(Mv(n,"nodeStyle"));let s=r.fill||iw(e);if(e.colorByDepth&&void 0!==n.depth){const t=ow(e);s=t[n.depth%t.length]}i.push({type:"circle",cx:n.x,cy:n.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==e.showLabels){const n=nw(e.nodeLabel);for(const i of t){const t=i.__radius??5,s=n?n(i):i.id;if(!s)continue;if(15>t)continue;const a=!(i.data?.children&&i.data.children.length>0);let l=o(Mv(i,"nodeStyle")).fill||iw(e);if(e.colorByDepth&&void 0!==i.depth){const t=ow(e);l=t[i.depth%t.length]}if(a){const n="string"==typeof l?tw(l):e.themeSemantic?.text??"#000";r.push({x:i.x,y:i.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:n})}else r.push({x:i.x,y:i.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,n,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function aw(t,e,n){const o=n.treeOrientation||"vertical";if("radial"===o){const n=e.x,o=e.y;t.x=o*Math.cos(n-Math.PI/2),t.y=o*Math.sin(n-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 lw(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 cw(t,e){const n=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-n,t.x1=e.x+n,t.y0=e.y-n,t.y1=e.y+n,t.width=2*n,t.height=2*n,t.__radius=n}import{pie as uw}from"d3-shape";function dw(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var hw={sankey:Pv,force:Fv,chord:Xv,tree:sw,cluster:sw,treemap:sw,circlepack:sw,partition:sw,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,n,o){const i=n.__hierarchyRoot;i&&function(t,e,n,o,i){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(n.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(n.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(n.orbitMode),l=n.orbitSize??2.95,c=n.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=dw(n);h.metaMap.clear(),o.length=0,i.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 g=e[0]/2,y=e[1]/2,m=Math.min(e[0],e[1])/2*.85,b=p(s(t));o.push({id:b,x:g,y:y,x0:g,x1:g,y0:y,y1:y,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(b,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,n,l,c,f,g,y){const m=r(e);if(!m?.length)return;const b=m.length;let x=0,v=0,w=0;for(;b>v;)v+=a[Math.min(w,a.length-1)],w++,x++;let k=0;for(let b=0;x>b;b++){const v=a[Math.min(b,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(b+1)/x,A={id:n,depth:g,data:e,parentId:n},M=y?f/u(A)*S:f*S,_=uw().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(A);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=l+M*Math.sin(r),f=c+M*Math.cos(r)*P;o.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,parentId:n,eccentricity:P}),i.push({source:n,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:n,target:u}}),t(a,u,d,f,M,g+1,!0)}k+=v}}(t,b,g,y,m,1,!1)}(i,o,n,t,e)},buildScene(t,e,n,o){const i=n.nodeStyle,r=n.nodeSize,s="number"==typeof r?()=>r:"function"==typeof r?r:()=>6,a=[],l=[],c=[];if(!1!==n.orbitShowRings){const e=dw(n),o=new Map;for(const e of t)o.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=o.get(t.parentId);if(!e)continue;const n=`${t.parentId}:${t.ring}`;i.has(n)||i.set(n,{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:n,ecc:o}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,c=(i+1)/r*Math.PI*2;l.push({type:"line",x1:t+n*Math.sin(a),y1:e+n*Math.cos(a)*o,x2:t+n*Math.sin(c),y2:e+n*Math.cos(c)*o,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=s(Mv(e,"nodeSize")),o=i?i(Mv(e,"nodeStyle")):{};a.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:o.fill||n.themeSemantic?.primary||"#6366f1",stroke:o.stroke||n.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),n="object"==typeof t.target?t.target:u.get(t.target);e&&n&&(null!=e.x&&null!=n.x&&l.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:t}))}if(n.showLabels){const e=n.nodeLabel;for(const n of t){const t=s(Mv(n,"nodeSize"));if(4>=t)continue;const o="function"==typeof e?e(n):e?n.data?.[e]??n.id:n.id;c.push({x:n.x,y:n.y+t+12,text:o+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:a,sceneEdges:l,labels:c}},tick:(t,e,n,o,i)=>!1!==n.orbitAnimated&&(function(t,e){const n=dw(e),o=e.orbitSpeed??.25,i=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-n.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=n.metaMap.get(e.id);if(!t||!t.parentId)continue;const o=a.get(t.parentId);if(!o)continue;const l=t.angle+r*s*i({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=o.x+t.ring*Math.sin(l),e.y=o.y+t.ring*Math.cos(l)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,n),!0)}};import{Fragment as fw,jsxs as pw}from"react/jsx-runtime";function gw(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var yw=new Set(["tree","cluster","treemap","circlepack","partition"]);function mw(t,e){const n=T(t.theme),o=t.chartType||"force",i=()=>lb({frameType:"network",width:r[0],height:r[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,nodeCount:0,edgeCount:0,margin:s}),r=t.size||[500,500],s=Bs({top:20,right:20,bottom:20,left:20,...t.margin},t.title),a=Es(t.title),l=t.showLegend?(()=>{const e="string"==typeof(n=t.colorBy)||"function"==typeof n?t.colorBy:void 0;var n;if(!e)return[];const o=j(t.nodes||[]);if(o.length>0)return kb(o,e);const i=Array.isArray(t.edges)?j(t.edges):[];if(0===i.length)return[];const r=gw(t.sourceAccessor,"source"),s=gw(t.targetAccessor,"target");return kb(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Bb(s,{props:t,categories:l,theme:n,size:r,hasTitle:a});const c=r[0]-s.left-s.right,u=r[1]-s.top-s.bottom,d=function(t){return hw[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 h={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,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||n.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let f,p;if(yw.has(o)){const o=t.data||t.edges;if(!o||Array.isArray(o))return e&&(e.evidence=i()),Mx.renderToStaticMarkup(Yb(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:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:t._idPrefix}));h.__hierarchyRoot=o,f=[],p=[]}else{const o=j(t.nodes||[]),a=Array.isArray(t.edges)?j(t.edges):[];if(0===o.length&&0===a.length)return e&&(e.evidence=i()),Mx.renderToStaticMarkup(Yb(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:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:t._idPrefix}));if(p=function(t,e){const n=gw(e.sourceAccessor,"source"),o=gw(e.targetAccessor,"target"),i=gw(e.valueAccessor,"value");return t.map(t=>({source:n(t)+"",target:o(t)+"",value:Number(i(t))||1,y0:0,y1:0,sankeyWidth:0,data:t}))}(a,h),0===o.length&&p.length>0){const t=new Set;for(const e of p){const n=Ob(e.source),o=Ob(e.target);n&&t.add(n),o&&t.add(o)}f=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 f=function(t,e){const n=gw(e.nodeIDAccessor,"id");return t.map(t=>({id:n(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,h)}let g=[],y=[],m=[],b=null;if(h.customNetworkLayout){const t=h.colorScheme,e=Iy(t,n.colors.categorical,q),o=$y(e,t),i={nodes:f,edges:p,dimensions:{width:c,height:u,plot:{x:0,y:0,width:c,height:u}},theme:{semantic:n.colors,categorical:[...e]},resolveColor:o,config:h.layoutConfig??{}},r=h.customNetworkLayout(i);g=r.sceneNodes??[],y=r.sceneEdges??[],m=r.labels??[],b=r.overlays??null}else if(d){d.computeLayout(f,p,h,[c,u]);const t=d.buildScene(f,p,h,[c,u]);g=t.sceneNodes,y=t.sceneEdges,m=t.labels}const x=I(n);for(const t of m)t.fill||(t.fill=x.text);const v=Kc({nodes:y,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"line":return da("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 n=t,o=`net-bezier-${e}-hatch`,i=ei(n.style.fill)?ii(n.style.fill,o):void 0;return ha(ca.Fragment,{children:[i&&da("defs",{children:i}),da("path",{d:n.pathD,fill:i?`url(#${o})`:ia(n.style.fill,"#999"),fillOpacity:n.style.fillOpacity,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth,opacity:n.style.opacity})]},"net-edge-"+e)}case"ribbon":{const n=t,o=`net-ribbon-${e}-hatch`,i=ei(n.style.fill)?ii(n.style.fill,o):void 0;return ha(ca.Fragment,{children:[i&&da("defs",{children:i}),da("path",{d:n.pathD,fill:i?`url(#${o})`:ia(n.style.fill,"#999"),fillOpacity:n.style.fillOpacity,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth,opacity:n.style.opacity})]},"net-edge-"+e)}case"curved":{const n=t;return da("path",{d:n.pathD,fill:ia(n.style.fill,"none"),stroke:n.style.stroke||"#999",strokeWidth:n.style.strokeWidth||1,opacity:n.style.opacity},"net-edge-"+e)}default:return null}}(t,e)}),w=Kc({nodes:g,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"circle":{const n=t,o=ei(n.style.fill)?ii(n.style.fill,`net-circle-${e}-hatch`):void 0;return ha(ca.Fragment,{children:[o&&da("defs",{children:o}),da("circle",{cx:n.cx,cy:n.cy,r:n.r,fill:o?`url(#net-circle-${e}-hatch)`:ia(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-circle-"+e)}case"rect":{const n=t,o=ei(n.style.fill)?ii(n.style.fill,`net-rect-${e}-hatch`):void 0;return ha(ca.Fragment,{children:[o&&da("defs",{children:o}),da("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:o?`url(#net-rect-${e}-hatch)`:ia(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-rect-"+e)}case"arc":{const n=t,o=ua().innerRadius(n.innerR).outerRadius(n.outerR).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2)(oa)||"",i=ei(n.style.fill)?ii(n.style.fill,`net-arc-${e}-hatch`):void 0;return ha(ca.Fragment,{children:[i&&da("defs",{children:i}),da("path",{d:o,transform:`translate(${n.cx},${n.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:ia(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-arc-"+e)}case"symbol":{const n=t,o=vn(n.symbolType,n.size,n.path);return da("path",{d:o,transform:n.rotation?`translate(${n.cx},${n.cy}) rotate(${180*n.rotation/Math.PI})`:`translate(${n.cx},${n.cy})`,fill:n.style.fill?ia(n.style.fill):"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity},"net-symbol-"+e)}case"glyph":return sa(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e)});e&&(e.evidence=lb({frameType:"network",width:r[0],height:r[1],marks:[...w.map(({node:t})=>({type:"node:"+(t.type??"node")})),...v.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,nodeCount:w.length,edgeCount:v.length,margin:s}));const k=v.map(t=>t.element),S=w.map(t=>t.element),A=m.map((t,e)=>function(t,e){return da("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),M=t.annotations?Rb({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{},layout:{width:c,height:u},theme:n,idPrefix:t._idPrefix}):null,_=Wb({props:t,categories:l,theme:n,size:r,margin:s,hasTitle:a});return Mx.renderToStaticMarkup(Yb(pw(fw,{children:[t.backgroundGraphics,k,S,A,M,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:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,legend:_,idPrefix:t._idPrefix}))}import*as bw from"react-dom/server";import{geoPath as xw}from"d3-geo";import{quadtree as vw}from"d3-quadtree";import{geoMercator as ww,geoEqualEarth as kw,geoAlbersUsa as Sw,geoOrthographic as Aw,geoNaturalEarth1 as Mw,geoEquirectangular as _w}from"d3-geo";var Pw={mercator:ww,equalEarth:kw,albersUsa:Sw,orthographic:Aw,naturalEarth:Mw,equirectangular:_w};function Cw(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Lw(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Rw(t,e,n){return t?"function"==typeof t?{...n,...t(e)}:{...n,...t}:{...n}}function Tw(t,e){if(2>t.length)return[t];const n=.4*e,o=[];let i=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>n?(2>i.length||o.push(i),i=[r]):i.push(r)}return 2>i.length||o.push(i),o}function Iw(t,e,n=24){const o=e[0]-t[0],i=e[1]-t[1],r=Math.sqrt(o*o+i*i);if(0===r)return[t,e];const s=-i/r,a=o/r,l=Math.min(.3*r,80),c=(t[0]+e[0])/2+s*l,u=(t[1]+e[1])/2+a*l,d=[];for(let o=0;n>=o;o++){const i=o/n,r=1-i;d.push([r*r*t[0]+2*r*i*c+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function $w(t,e){if(2>t.length)return t;const n=e/2+1,o=[];for(let e=0;t.length>e;e++){const i=t[e];let r,s;0===e?(r=t[1][0]-i[0],s=t[1][1]-i[1]):e===t.length-1?(r=i[0]-t[e-1][0],s=i[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;o.push([i[0]+s/a*n,i[1]+-r/a*n])}return o}function Ow(t,e,n,o,i){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const l=s/a,c=-r/a,u=i/2+1;return[[t[0]+l*u,t[1]+c*u],[e[0]+l*u,e[1]+c*u]]}import{scaleLinear as zw}from"d3-scale";var Fw=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Dw=["scene-style","data-paint","accessibility","evidence"],Ew=(t,e)=>({retainedData:t,invalidations:e}),Nw=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Bw=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ww=["scene-geometry","data-paint","accessibility","evidence"],jw=["scene-style","data-paint","accessibility","evidence"],Yw=["overlay","accessibility","evidence"],Xw=[],Hw={xAccessor:Ew("rebuild",Nw),yAccessor:Ew("rebuild",Nw),lineDataAccessor:Ew("rebuild",Nw),pointIdAccessor:Ew("rebuild",Ww),lineIdAccessor:Ew("rebuild",Ww),windowSize:Ew("rebuild",Nw),projection:Ew("preserve",Bw),projectionExtent:Ew("preserve",Bw),fitPadding:Ew("preserve",Bw),lineType:Ew("preserve",Bw),flowStyle:Ew("preserve",Bw),graticule:Ew("preserve",Bw),projectionTransform:Ew("preserve",Bw),customLayout:Ew("preserve",Bw),layoutConfig:Ew("preserve",Bw),layoutMargin:Ew("preserve",Bw),areaStyle:Ew("preserve",jw),pointStyle:Ew("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Ew("preserve",jw),colorScheme:Ew("preserve",jw),themeCategorical:Ew("preserve",jw),themeDiverging:Ew("preserve",jw),themeSemantic:Ew("preserve",jw),themeSequential:Ew("preserve",jw),decay:Ew("preserve",jw),pulse:Ew("preserve",jw),layoutSelection:Ew("preserve",jw),annotations:Ew("preserve",Yw),autoPlaceAnnotations:Ew("preserve",Yw),clock:Ew("preserve",Xw),transition:Ew("preserve",Xw),introAnimation:Ew("preserve",Xw),onLayoutError:Ew("preserve",Xw)},Gw=Ew("preserve",Bw),qw=class{constructor(){this.tracker=new Jn}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}},Fw)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Dw):this.recordNoop("restyle")}recordConfig(t,e={}){const n=function(t){let e="preserve";const n=new Set;for(const o of t){const t=Hw[o]??Gw;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)n.add(e)}return{retainedData:e,invalidations:n}}(t),o=new Set(n.invalidations);return e.retainedDataChanged&&o.add("data"),this.tracker.record({kind:"config",keys:t},o)}};import{geoDistance as Vw,geoGraticule as Uw,geoInterpolate as Kw}from"d3-geo";function Zw(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 Qw=class t{constructor(t){this.updateResults=new qw,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:Zw(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??Ne()}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(),n=this.timestampBuffer?.toArray()??[],o=e.slice(-t),i=n.slice(-o.length),r=this.currentTime();this.pointBuffer=new $e(t),this.timestampBuffer=new $e(t),o.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(i[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:Zw(t.fitPadding)}:t}(t),n=this.config,o=this.getConfiguredWindowSize(),i=Object.keys(e).filter(t=>e[t]!==n[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(i,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),n=this.pointBuffer?this.pointBuffer.toArray():this.pointData,o=this.timestampBuffer?.toArray()??[],i=n.slice(-e),r=o.slice(-i.length),s=this.currentTime();this.pointBuffer=new $e(e),this.timestampBuffer=new $e(e),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();Bn(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 n of t)Bn(this.pointBuffer,n,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 n="function"==typeof e?e:t=>t[e],o=new Set(Array.isArray(t)?t:[t]),i=[];return this.lineData=this.lineData.filter(t=>!o.has(n(t)+"")||(i.push(t),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const n="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(n(t)+"");Wn(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(n(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 n of this.scene){const o=this._baseStyles.get(n)??n.style,i=e(n,t);n.style=i?{...o,...i}:o}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,n=this.projection,o=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],l=this.scene;this.projection=function(t){if(!t)return kw();if("string"==typeof t){const e=Pw[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),kw())}if("object"==typeof t&&"type"in t){const e=Pw[t.type],n=e?e():kw();return t.rotate&&"rotate"in n&&n.rotate(t.rotate),t.center&&"center"in n&&n.center(t.center),n}return t}(e.projection),this.geoPath=xw(this.projection),this.fitProjection(t),this.geoPath=xw(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(t,e)=>c([t,e]),invertedPoint:(t,e)=>c.invert?c.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=n,this.geoPath=o,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,n=t.height/2,o=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:n}));o.length>0&&this.startTransition(o)}this._hasRenderedOnce=!0,e.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(t){const e=this.projection,n=this.config,o=[...this.areas],i=Cw(n.xAccessor,"lon"),r=Cw(n.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[i(t),r(t)]);o.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Lw(n.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[i(t),r(t)]);o.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==o.length){if(n.projectionExtent){const[[o,i],[r,s]]=n.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[o,i],[o,s],[r,s],[r,i],[o,i]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const o=n.fitPadding??0,i=Math.min(t.width,t.height);e.scale(i/2-i*o),e.translate([t.width/2,t.height/2])}else{const i=n.fitPadding??0,r=t.width*i,s=t.height*i;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 n=this.projection;if(!n)return;const o=this.geoPath,i=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*t.k),n.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=xw(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const n=this.projection;if(!n)return;const o=this.geoPath,i=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*t),n.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=xw(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const n=this.projection;if(!n||!n.rotate)return;const o=this.geoPath,i=this.scales,r=[...n.rotate()];n.rotate(t),this.geoPath=xw(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.rotate(r),this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,n=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(n++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=n)return void(this._quadtree=null);const o=Array(n);let i=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(o[i++]=t);this._quadtree=vw().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,n=this.projection,o=this.geoPath;if(e.customLayout&&this.scales){const n=e.layoutMargin??{top:0,right:0,bottom:0,left:0},o=Iy(e.colorScheme,e.themeCategorical,xt),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:n,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...o]},resolveColor:$y(o,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(i)}catch(t){const n=null!==this.lastCustomLayoutResult,o=Ln("geo",t,n,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 n?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 _n({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:n,areas:o,points:i,lines:r,layout:s}){const a=Cw(t.xAccessor,"lon"),l=Cw(t.yAccessor,"lat"),c=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),d=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),h=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,o=Uw();e.step&&o.step(e.step);const i=n(o())||"";i&&c.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth||.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of o){const o=n(e);if(!o)continue;const i=n.centroid(e),r=n.bounds(e),s=n.area(e);c.push({type:"geoarea",pathData:o,centroid:i,bounds:r,screenArea:s,style:Rw(t.areaStyle,e,u),datum:e,interactive:!0})}const f=Lw(t.lineDataAccessor);for(const n of r){const o=f(n);if(!o||2>o.length)continue;let i=[];if("geo"===t.lineType){const t=Array(o.length);for(let e=0;o.length>e;e++)t[e]=[a(o[e]),l(o[e])];for(let n=0;t.length-1>n;n++){const o=t[n],r=t[n+1],s=Vw(o,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Kw(o,r);for(let t=0;a>=t;t++){if(n>0&&0===t)continue;const o=e(l(t/a));null!=o&&i.push(o)}}}else for(let t=0;o.length>t;t++){const n=o[t],r=e([a(n),l(n)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Rw(t.lineStyle,n,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==o.length||2>i.length||"arc"!==t.flowStyle?2!==o.length||2>i.length||"offset"!==t.flowStyle||(i="geo"===t.lineType?$w(i,u):Ow(i[0],i[i.length-1],0,0,u)):i=Iw(i[0],i[i.length-1]);const h=Tw(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:n});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:n})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,g=e.clipAngle?e.clipAngle()??0:0,y=g>0?g*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],b="function"==typeof e.center?e.center():[0,0],x=[(b[0]??0)-m[0],(b[1]??0)-m[1]];for(const n of i){const o=a(n),i=l(n);if(null!=y&&Vw([o,i],x)>y)continue;const r=e([o,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(n):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:n,pointId:p?p(n)+"":void 0};c.push(u)}return c}({config:e,projection:n,path:o,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const n=function(t,e,n,o){const i=t.filter(t=>"point"===t.type);if(2>i.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const l=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,c="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&l(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=Pt(i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),1);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 n=t[e];"geoarea"===n.type&&n.interactive&&t.splice(e,1)}const h="strip"===a?function(t,e,n,o,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=zw().domain([0,o]).range([0,s]);e.x=r,e.y=a;const c=[];for(const i of t){if(i===e)continue;if(!i.datum){i.x=r,i.y=a;continue}const t=Number(n(i.datum)),s=r+(isFinite(t)&&t>=0&&o>0?l(t):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let t=d+1;for(;c.length>t&&3>Math.abs(c[t].x-c[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)c[d+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));d=t}return{cx:r,cy:a,maxCost:o,availableRadius:s,layout:"strip"}}(i,u,c,d,n):function(t,e,n,o,i,r){const s=e.x,a=e.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=zw().domain([0,o]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),f=Math.hypot(t-s,u-a),p=Number(n(r.datum)),g=isFinite(p)&&p>=0?o>0?d(p):0:f,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=t+(y-t)*i,r.y=u+(m-u)*i}return e.x=s+(l-s)*i,e.y=a+(c-a)*i,{cx:e.x,cy:e.y,maxCost:o,availableRadius:u,layout:"radial"}}(i,u,c,d,s,n),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of i)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const n of f){const o=n.datum?.source,i=n.datum?.target;if(null!=o&&null!=i){const r=t.get(o+""),s=t.get(i+"");if(r&&s)if("fractional"===e.lineMode&&n.path.length>2){const t=n.path[0],e=n.path[n.path.length-1],o=[r[0]-t[0],r[1]-t[1]],i=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;n.path.length>t;t++)a.push(a[t-1]+Math.hypot(n.path[t][0]-n.path[t-1][0],n.path[t][1]-n.path[t-1][1]));const l=a[a.length-1];n.path=n.path.map((t,e)=>{const r=l>0?a[e]/l:e/(n.path.length-1);return[t[0]+o[0]*(1-r)+i[0]*r,t[1]+o[1]*(1-r)+i[1]*r]})}else n.path=[r,s]}}}return h}(this.scene,t,e,this.areas.length);n&&(this.cartogramLayout=n)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const n=this.scene.filter(t=>"point"===t.type);for(let o=0;n.length>o;o++){const i=Be(t,o,e);n[o]._decayOpacity=i,n[o].style={...n[o].style,opacity:i}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const n=this.scene.filter(t=>"point"===t.type),o=this.timestampBuffer.toArray(),i=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;n.length>a&&o.length>a;a++){const l=je(e,o[a],t);s=Ye(n[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Xe(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 n=new Map;for(const e of t)"point"===e.type&&e.pointId&&n.set(e.pointId,[e.x,e.y]);const o=this.scene.filter(t=>"point"===t.type);let i=!1;for(const t of o)if(t.pointId){const e=n.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(i=!0))}for(const t of o)t.pointId&&!n.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=De(t,this.activeTransition),n=Fe(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=Ee(t.x,t._targetX,n),t.y=Ee(e,t._targetY,n)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*n})}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}};Qw.QUADTREE_THRESHOLD=500;var Jw=Qw;Un(Jw);import{Fragment as tk,jsxs as ek}from"react/jsx-runtime";function nk(t,e){const n=T(t.theme),o=t.size||[t.width||600,t.height||400],i=Bs({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Es(t.title),s=Array.isArray(t.areas)?j(t.areas):t.areas,a=j(t.points),l=j(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(n=t.colorBy)||"function"==typeof n?t.colorBy:void 0;var n;return kb(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Bb(i,{props:t,categories:c,theme:n,size:o,hasTitle:r});const u=o[0]-(i.left??0)-(i.right??0),d=o[1]-(i.top??0)-(i.bottom??0),h={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:i,themeCategorical:n.colors.categorical,themeSemantic:w(n)},f=new Jw(h);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);f.setAreas(s)}t.points&&f.setPoints(a),t.lines&&f.setLines(l),f.computeScene({width:u,height:d});const p=Kc({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"geoarea":{const n=t;if(!n.pathData)return null;const o=ei(n.style.fill)?ii(n.style.fill,`geoarea-${e}-hatch`):void 0;return ga(fa.Fragment,{children:[o&&pa("defs",{children:o}),pa("path",{d:n.pathData,fill:o?`url(#geoarea-${e}-hatch)`:ia(n.style.fill,"#e0e0e0"),fillOpacity:n.style.fillOpacity??1,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth||.5,strokeDasharray:n.style.strokeDasharray,opacity:n._decayOpacity??1})]},"geoarea-"+e)}case"point":{const n=t,o=ei(n.style.fill)?ii(n.style.fill,`geopoint-${e}-hatch`):void 0;return ga(fa.Fragment,{children:[o&&pa("defs",{children:o}),pa("circle",{cx:n.x,cy:n.y,r:n.r,fill:o?`url(#geopoint-${e}-hatch)`:ia(n.style.fill),fillOpacity:n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n._decayOpacity??n.style.opacity??1})]},"point-"+e)}case"line":{const n=t;if(2>n.path.length)return null;const o="M"+n.path.map(t=>`${t[0]},${t[1]}`).join("L");return pa("path",{d:o,fill:"none",stroke:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||1.5,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity??1},"line-"+e)}case"glyph":return sa(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e)});if(e&&(e.evidence=lb({frameType:"geo",width:o[0],height:o[1],marks:p.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,legendItems:c.length>0?c.length:void 0,margin:i})),0===p.length){const e=t.backgroundGraphics||t.foregroundGraphics||t.annotations||f.customLayoutOverlays?ek(tk,{children:[t.backgroundGraphics,t.annotations?Rb({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:u,height:d},theme:n,idPrefix:t._idPrefix}):null,t.foregroundGraphics,f.customLayoutOverlays]}):null;return bw.renderToStaticMarkup(Yb(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:n,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,idPrefix:t._idPrefix}))}const g=p.map(t=>t.element),y=t.annotations?Rb({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:u,height:d},theme:n,idPrefix:t._idPrefix}):null,m=Wb({props:t,categories:c,theme:n,size:o,margin:i,hasTitle:r});return bw.renderToStaticMarkup(Yb(ek(tk,{children:[t.backgroundGraphics,g,y,t.foregroundGraphics,f.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:n,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,legend:m,idPrefix:t._idPrefix}))}import*as ok from"react-dom/server";function ik(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 rk={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function sk(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 ak(t,e){const n="function"==typeof e?e(t):e;return{...rk,...n??{}}}function lk(t,e={}){return t.map(t=>function(t,e={}){const n=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),o={label:e.getBodyLabel?.(t)??sk(t)},i={style:ak(t,e.bodyStyle),datum:n,accessibleDatum:n,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,...i}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...i}}(t,e))}import{jsx as ck,jsxs as uk}from"react/jsx-runtime";var dk={top:0,right:0,bottom:0,left:0};function hk(t,e,n){return"function"==typeof t?t({size:e,margin:n}):t}function fk(t,e){const n=t.size??[t.width??600,t.height??400],o=new gy(t.config);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&o.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const i=function(t,e={}){const{width:n=640,height:o=360,title:i,description:r,background:s,backgroundGraphics:a,className:l,foregroundGraphics:c,idPrefix:u="physics",margin:d,renderBodySVG:h,...f}=e,p=function(t,e={}){const n=t.settle(e.maxSteps),o=t.readBodies(),i=t.snapshot(),r=lk(o,e),s=function(t,e={}){const n=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=n.filter(t=>t.sleeping).length,i=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===i&&o===n.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const l=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,n,o){const i=t-(e+n+o);return{charge:t,live:e,queued:n,sedimented:o,unaccounted:i,balanced:0===i}}(e.charge,n.length,i,r):void 0;return l&&!l.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:n.length,sleepingCount:o,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:ik(e.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},warnings:a}}(i,{bodies:o,projectionRows:e.projectionRows,stepsRun:n,charge:e.charge});return{snapshot:i,bodies:o,sceneNodes:r,evidence:s,stepsRun:n}}(t,f),g={...dk,...d},y=[n,o],m=hk(a,y,g),b=hk(c,y,g),x=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(u),v=i?x+"-title":void 0,w=r?x+"-desc":void 0,k=[v,w].filter(Boolean).join(" ")||void 0;return{svg:ok.renderToStaticMarkup(uk("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:n,height:o,viewBox:`0 0 ${n} ${o}`,role:"img","aria-labelledby":k,children:[i&&ck("title",{id:v,children:i}),r&&ck("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?ck("rect",{x:0,y:0,width:n,height:o,fill:s}):null,m,ck("g",{id:x+"-data-area",children:p.sceneNodes.map((t,e)=>{const n=p.bodies[e];return(n&&h?h(n,t.style??{},e,x):void 0)??Ca(t,e,x)})}),b]})),scene:p,evidence:p.evidence}}(o,{...t,width:n[0],height:n[1],charge:t.charge,idPrefix:t.idPrefix??t._idPrefix??"physics"});return e&&(e.evidence=lb({frameType:"physics",width:n[0],height:n[1],marks:i.scene.sceneNodes,title:t.title,description:t.description,annotations:[],extraWarnings:[...0===i.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...i.scene.evidence.warnings]})),i.svg}import*as pk from"react-dom/server";import{jsx as gk,jsxs as yk}from"react/jsx-runtime";var mk={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function bk(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var xk={BigNumber:function(t,e){const n="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",o=mk[n],i=bk(t.width,o.width),r=bk(t.height,o.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):o.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:o.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=T(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const n=e.locale??"en-US";if("currency"===t){const t=e.precision??2,o=new Intl.NumberFormat(n,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>o.format(t)}if("percent"===t){const t=new Intl.NumberFormat(n,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(n,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",n=Math.abs(t);if(1e3>n)return`${e}${Math.round(n)}ms`;const o=n/1e3;if(60>o)return`${e}${i=o,Math.round(100*i)/100+""}s`;var i;const r=o/60;if(60>r){const t=Math.floor(r),n=Math.round(o-60*t);return 0===n?`${e}${t}m`:`${e}${t}m ${n}s`}const s=r/60;if(24>s){const t=Math.floor(s),n=Math.round(r-60*t);return 0===n?`${e}${t}h`:`${e}${t}h ${n}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}h`}(t);const o=new Intl.NumberFormat(n,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>o.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${p}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var p;const g=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const n=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let o=null;for(const e of n){if(e.at>t)break;o=e}return o}(d,t.thresholds),y="string"==typeof t.color?t.color:function(t,e,n){return e||("success"===t?n.colors.success??"#2ca02c":"warning"===t?n.colors.warning??"#b26a00":"danger"===t?n.colors.danger??"#d62728":"info"===t?n.colors.info??n.colors.primary:n.colors.text)}(g?.level??"neutral",g?.color,u),m="string"==typeof t.label?t.label:void 0,b="string"==typeof t.caption?t.caption:void 0,x="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,n){const o=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,i=o&&"number"==typeof o.value&&Number.isFinite(o.value)?o.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===i?void 0:e-i);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,n);return`${s}${o&&"string"==typeof o.label?" "+o.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,n){const o=t.target&&"object"==typeof t.target?t.target:void 0;if(!o||"number"!=typeof o.value||!Number.isFinite(o.value))return;const i="string"==typeof o.label?" "+o.label:"";return 0===o.value?`target ${n(o.value)}${i}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/o.value)} of ${n(o.value)}${i}`}(t,d,h),k=[v,w,g?.label].filter(Boolean).join(" · "),S="string"==typeof t.description&&t.description||[m,f,x,k].filter(Boolean).join(", "),A="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+o.labelSize,P=_+o.captionSize+4,C="presentation"===n?r/2+.32*o.valueSize:"thumbnail"===n?r/2+.34*o.valueSize:Math.min(r-s-(k?26:4),(o.showHeader&&(m||b)?b?P+10:_+14:s)+o.valueSize),L=c+("start"===l?Math.max(o.valueSize,f.length*o.valueSize*.55):0),R=pk.renderToStaticMarkup(yk("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber",children:[gk("title",{children:m??f}),"string"==typeof t.description&&gk("desc",{children:t.description}),gk("rect",{x:o.border?.5:0,y:o.border?.5:0,width:o.border?i-1:i,height:o.border?r-1:r,rx:o.border?8:0,fill:A,stroke:o.border?M:"none"}),o.showHeader&&m&&gk("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.labelSize,fontWeight:600,fill:u.colors.text,children:m}),o.showHeader&&b&&gk("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.captionSize,fill:u.colors.textSecondary,children:b}),gk("text",{x:c,y:C,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:f}),x&&void 0!==d&&"start"===l&&gk("text",{x:L+6,y:C,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*o.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:x}),o.showDetail&&k&&gk("text",{x:c,y:Math.min(r-s,C+o.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=lb({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:S})),R}};function vk(t,e,n){return xk[t](e,n)}import{Fragment as wk,jsx as kk,jsxs as Sk}from"react/jsx-runtime";function Ak(t,e){switch(t){case"xy":return qb(e);case"ordinal":return Ax(e);case"network":return mw(e);case"geo":return nk(e);case"physics":return fk(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Mk(t){return qb(t)}function _k(t){return Ax(t)}function Pk(t){return mw(t)}function Ck(t){return nk(t)}var Lk=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],Rk=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Tk(t,e){const n={};for(const o of e)void 0!==t[o]&&(n[o]=t[o]);return n}function Ik(t,e,n){return Ok(t,e).svg}function $k(t,e,n){const o={},{svg:i,frameType:r}=Ok(t,e,0,o),s=o.evidence??lb({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:i,evidence:s}}function Ok(t,e,n,o){if(t in xk)return{svg:vk(t,e,o),frameType:"value"};const i=rb[t];if(!i)throw Error(`Unknown chart component: "${t}". See CLAUDE.md for supported chart types.`);var r;const s=F(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(z,r)?e.mode:void 0),{...i.layout?.modeDefaults,...Tk(e,Rk)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:g,...y}=e,{width:m,height:b}=s,x=[m,b],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,S=void 0!==h?h:v.margin,A=E(S),M="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...k,...A},_=Tk(y,Lk),P=t=>v[t]??s[t],C={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:x,margin:M,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},L=i.buildProps(a,p,f,C,y);let R;switch(i.frameType){case"xy":R=qb(L,o);break;case"ordinal":R=Ax(L,o);break;case"network":R=mw(L,o);break;case"geo":R=nk(L,o);break;case"physics":R=fk(L,o)}const I=i.renderOverlay?.(L,{theme:T(l)});if(null!=I){const t=N.renderToStaticMarkup(kk(wk,{children:I}));R=R.replace("</svg>",t+"</svg>")}return{svg:R,frameType:i.frameType}}async function zk(t,e,n={}){const{format:o="png",scale:i=1,background:r}=n;let s,a;s=["xy","ordinal","network","geo","physics"].includes(t)?Ak(t,e):Ik(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 l=e.width||e.size?.[0]||600,c=e.height||e.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*i}).resize(Math.round(l*i),Math.round(c*i));return"jpeg"===o?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function Fk(t,e={}){const{title:n,subtitle:o,theme:i,width:r=1200,height:s,layout:a={},background:l}=e,c=I(T(i)),u=a.columns||2,d=a.gap??16;let h=0;n&&(h+=30),o&&(h+=20),h>0&&(h+=10);const f=Math.floor((r-d-d*(u-1))/u),p=[];let g=0,y=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),n=e.props.height||300;g+t>u&&(y+=m+d,g=0,m=0),p.push({chart:e,x:d/2+g*(f+d),y:y,w:f*t+d*(t-1),h:n}),m=Math.max(m,n),g+=t}const b=s||y+m+d,x=p.map((t,e)=>{const{chart:n,x:o,y:r,w:s,h:a}=t,l={...n.props,width:s,height:a,theme:i,_idPrefix:"chart-"+e};let c;return c=n.component?Ik(n.component,l):n.frameType?Ak(n.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,kk("g",{transform:`translate(${o},${r})`,children:kk("foreignObject",{width:s,height:a,children:kk("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+e)});return N.renderToStaticMarkup(Sk("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:b,role:"img","aria-label":n||"Dashboard",style:{fontFamily:c.fontFamily},children:[n&&kk("title",{children:n}),l&&kk("rect",{x:0,y:0,width:r,height:b,fill:l}),n&&kk("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleSize+4,fontWeight:"bold",fill:c.text,fontFamily:c.fontFamily,children:n}),o&&kk("text",{x:r/2,y:n?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:o}),x]}))}import*as Dk from"react-dom/server";import{Fragment as Ek,jsx as Nk,jsxs as Bk}from"react/jsx-runtime";function Wk(t,e,n,o={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=o,f=n.width||600,p=n.height||400,g=T(n.theme),y={...n,...a&&{xExtent:a},...l&&{yExtent:l}};if(!e||0===e.length)return[];const m=i||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),b=[];for(let t=m;e.length>=t;t+=m)b.push(t);b[b.length-1]!==e.length&&b.push(e.length);const x=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=Bs({top:20,right:20,bottom:30,left:40,...n.margin},n.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(x)for(let o=0;b.length>o;o++){const i=b[o],s=e.slice(r?Math.max(0,i-r):0,i),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:n.projection||"vertical",oAccessor:n.oAccessor||n.categoryAccessor||"category",rAccessor:n.rAccessor||n.valueAccessor||"value",colorAccessor:n.colorAccessor||n.colorBy,stackBy:n.stackBy,groupBy:n.groupBy,barPadding:n.barPadding,innerRadius:n.innerRadius,normalize:n.normalize,bins:n.bins,colorScheme:n.colorScheme||g.colors.categorical,...h&&{decay:h}},l=new bx(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&S.push(qk(l.scene,f,p,g,y))}else for(let o=0;b.length>o;o++){const i=b[o],s=e.slice(r?Math.max(0,i-r):0,i),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:n.colorAccessor||n.colorBy,groupAccessor:n.groupAccessor||n.lineBy,lineDataAccessor:n.lineDataAccessor,xExtent:a,yExtent:l,colorScheme:n.colorScheme||g.colors.categorical,lineStyle:n.lineStyle,pointStyle:n.pointStyle,areaStyle:n.areaStyle,sizeAccessor:n.sizeAccessor||n.sizeBy,sizeRange:n.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},x=new mo(m);if(x.ingest({inserts:s,bounded:!0}),x.computeScene({width:w,height:k}),0===x.scene.length)continue;const v=x.scales?{y:x.scales.y}:void 0;if(S.push(Gk(x.scene,f,p,g,y,v)),c>0&&o>0&&x.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)x.advanceTransition(x.activeTransition.startTime+e/c*t),S.push(Gk(x.scene,f,p,g,y,v))}}return S}function jk(t,e,n={}){return e.map(e=>{try{return Ik(t,{...n,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${n.width||e.width||600}" height="${n.height||e.height||400}"></svg>`}})}function Yk(t,e,n){const o=e.size??[e.width??600,e.height??400],i=T(e.theme),r=I(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",l=e.title?`${a}-title-${n}`:void 0,c=e.description?`${a}-desc-${n}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=lk(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Bk("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&&Nk("title",{id:l,children:e.title}),e.description&&Nk("desc",{id:c,children:e.description}),s&&"transparent"!==s?Nk("rect",{x:0,y:0,width:o[0],height:o[1],fill:s}):null,Nk("g",{id:`${a}-frame-${n}`,children:d.map((t,e)=>Ca(t,e,`${a}-${n}`))})]});return Dk.renderToStaticMarkup(h)}function Xk(t,e={}){const{fps:n=12,frameCount:o,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:l}=e,c=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,n)/c)),d=o??Math.max(1,Math.ceil(i*Math.max(1,n))),h=l?{...t,background:l}:t,f=new gy(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(Yk(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(c);p.push(Yk(f,h,p.length))}return p}function Hk(t,e){const n=t.background||e.colors.background;return n&&"transparent"!==n?n:null}function Gk(t,e,n,o,i,r){const s=I(o),a=Bs({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=e-a.left-a.right,c=n-a.top-a.bottom,u=Hk(i,o),d=i.renderMode,h=t.map((t,e)=>Uc({node:t,index:e,renderMode:d,fallback:()=>Ca(t,e)})).filter(Boolean),f=function(t,e,n,o,i,r){if(!t||0===t.length)return null;const s=I(o),a=[];for(let o=0;t.length>o;o++){const l=t[o];if("y-threshold"===l.type&&null!=l.value){let t=null;if(r)t=r(l.value);else if(i){const[e,o]=i,r=o-e;if(0===r)continue;t=n-(l.value-e)/r*n}if(null==t)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(Bk("g",{children:[Nk("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&Nk("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(n-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+o))}}return a.length>0?Nk(Ek,{children:a}):null}(i.annotations,l,c,o,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=p?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,b=[y,m].filter(Boolean).join(" ")||void 0;return Dk.renderToStaticMarkup(Bk("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:n,role:"img","aria-labelledby":b,style:{fontFamily:s.fontFamily},children:[p&&Nk("title",{id:y,children:p}),g&&Nk("desc",{id:m,children:g}),u&&Nk("rect",{x:0,y:0,width:e,height:n,fill:u}),Bk("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&Nk("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}function qk(t,e,n,o,i){const r=I(o),s=Bs({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(e-s.left-s.right)/2:s.left,c=a?s.top+(n-s.top-s.bottom)/2:s.top,u=Hk(i,o),d=i.renderMode,h=t.map((t,e)=>Uc({node:t,index:e,renderMode:d,fallback:()=>Aa(t,e)})).filter(Boolean),f="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,g=f?"semiotic-title":void 0,y=p?"semiotic-desc":void 0,m=[g,y].filter(Boolean).join(" ")||void 0;return Dk.renderToStaticMarkup(Bk("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:n,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[f&&Nk("title",{id:g,children:f}),p&&Nk("desc",{id:y,children:p}),u&&Nk("rect",{x:0,y:0,width:e,height:n,fill:u}),Nk("g",{transform:`translate(${l},${c})`,children:h}),f&&Nk("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:f})]}))}async function Vk(t,e,n,o={}){const{fps:i=12,loop:r=!0,scale:s=1,background:a}=o,l=n.width||600,c=n.height||400,u=Wk(t,e,a?{...n,background:a}:n,o);if(0===u.length)throw Error("No frames generated — check that data is not empty");return Kk(u,l,c,{fps:i,loop:r,scale:s})}async function Uk(t,e={}){const{fps:n=12,loop:o=!0,scale:i=1}=e,r=t.size??[t.width??600,t.height??400],s=Xk(t,e);if(0===s.length)throw Error("No physics frames generated");return Kk(s,r[0],r[1],{fps:n,loop:o,scale:i})}async function Kk(t,e,n,o={}){const{fps:i=12,loop:r=!0,scale:s=1}=o,a=Math.round(e*s),l=Math.round(n*s);let c,u,d,h;try{const t="sharp",e=await import(t);c=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),n=[e,e.default].find(t=>"function"==typeof t?.GIFEncoder&&"function"==typeof t.quantize&&"function"==typeof t.applyPalette);if(!n)throw Error("gifenc did not expose its encoder functions");u=n.GIFEncoder,d=n.quantize,h=n.applyPalette}catch(t){throw Error('Animated GIF export requires "gifenc". Install it:\n npm install gifenc',{cause:t})}const f=Math.round(1e3/i),p=u();for(let e=0;t.length>e;e++){const n=t[e],o=await c(Buffer.from(n),{density:72*s}).resize(a,l).ensureAlpha().raw().toBuffer(),i=new Uint8Array(o),u=d(i,256),g=h(i,u);p.writeFrame(g,a,l,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}export{T as resolveTheme,I as themeStyles,Ak as renderToStaticSVG,Mk as renderXYToStaticSVG,_k as renderOrdinalToStaticSVG,Pk as renderNetworkToStaticSVG,Ck as renderGeoToStaticSVG,Ik as renderChart,$k as renderChartWithEvidence,zk as renderToImage,Fk as renderDashboard,Wk as generateFrameSVGs,jk as generateFrameSequence,Xk as generatePhysicsFrameSVGs,Vk as renderToAnimatedGif,Uk as renderPhysicsToAnimatedGif};
|