semiotic 3.8.5 → 3.8.7
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 +37 -10
- package/README.md +83 -56
- package/ai/behaviorContracts.cjs +88 -3
- package/ai/componentMetadata.cjs +5 -10
- package/ai/dist/mcp-server.js +99 -10
- package/ai/examples.md +198 -9
- package/ai/schema.json +2002 -165
- package/ai/surface-manifest.json +14 -10
- package/ai/system-prompt.md +9 -3
- package/dist/{chunk-chartContainerDataAudit-74TLKIP6.module.min.js → chunk-chartContainerDataAudit-JDSVSKGM.module.min.js} +1 -1
- package/dist/chunk-chunk-2JGJ5GUG.module.min.js +1 -0
- package/dist/chunk-chunk-2YAZHXL4.module.min.js +2 -0
- package/dist/chunk-chunk-3NGIKFD6.module.min.js +1 -0
- package/dist/{chunk-chunk-G7WFWHAD.module.min.js → chunk-chunk-4ITOQRXM.module.min.js} +1 -1
- package/dist/chunk-chunk-5SD6BHVW.module.min.js +2 -0
- package/dist/chunk-chunk-6V5VQVCT.module.min.js +2 -0
- package/dist/chunk-chunk-7TTBHSAG.module.min.js +2 -0
- package/dist/chunk-chunk-7ZDJSYKI.module.min.js +2 -0
- package/dist/chunk-chunk-BGHPD3RA.module.min.js +1 -0
- package/dist/chunk-chunk-BMRZ2SPU.module.min.js +2 -0
- package/dist/chunk-chunk-BNGBEY7N.module.min.js +2 -0
- package/dist/chunk-chunk-C7APLVQD.module.min.js +2 -0
- package/dist/chunk-chunk-DGWFBOGB.module.min.js +1 -0
- package/dist/chunk-chunk-DIVE2DRA.module.min.js +2 -0
- package/dist/chunk-chunk-FBUNUIPV.module.min.js +2 -0
- package/dist/chunk-chunk-FQPKOAIH.module.min.js +2 -0
- package/dist/chunk-chunk-FRO4TRXK.module.min.js +2 -0
- package/dist/chunk-chunk-G7QVPZUD.module.min.js +2 -0
- package/dist/chunk-chunk-GBPYV4FP.module.min.js +2 -0
- package/dist/chunk-chunk-GU2EJIDJ.module.min.js +2 -0
- package/dist/chunk-chunk-J5QD4RAM.module.min.js +2 -0
- package/dist/{chunk-chunk-LJLS6DY7.module.min.js → chunk-chunk-JWXLNZSM.module.min.js} +1 -1
- package/dist/chunk-chunk-KXAFCCDB.module.min.js +2 -0
- package/dist/chunk-chunk-LG7YKJAK.module.min.js +2 -0
- package/dist/{chunk-chunk-I36PJ4OC.module.min.js → chunk-chunk-LVHDZAT3.module.min.js} +1 -1
- package/dist/chunk-chunk-LWITSR2O.module.min.js +2 -0
- package/dist/chunk-chunk-MX35T6RX.module.min.js +2 -0
- package/dist/chunk-chunk-NH4MEAKP.module.min.js +2 -0
- package/dist/chunk-chunk-NJETWX42.module.min.js +2 -0
- package/dist/chunk-chunk-NW25WGLS.module.min.js +2 -0
- package/dist/{chunk-chunk-TMWIZL3K.module.min.js → chunk-chunk-OI7R7EJB.module.min.js} +1 -1
- package/dist/chunk-chunk-ONMLEXHR.module.min.js +2 -0
- package/dist/chunk-chunk-OY66GCE6.module.min.js +1 -0
- package/dist/chunk-chunk-PZFT457G.module.min.js +1 -0
- package/dist/chunk-chunk-Q3WW6JGR.module.min.js +1 -0
- package/dist/chunk-chunk-Q6XKQTOQ.module.min.js +1 -0
- package/dist/chunk-chunk-RJRM2E6P.module.min.js +1 -0
- package/dist/chunk-chunk-RPL7WYXI.module.min.js +1 -0
- package/dist/chunk-chunk-SV4XAZ3Q.module.min.js +1 -0
- package/dist/chunk-chunk-TSCFL235.module.min.js +1 -0
- package/dist/chunk-chunk-UOQRPGPK.module.min.js +2 -0
- package/dist/chunk-chunk-V3OAKG32.module.min.js +1 -0
- package/dist/chunk-chunk-WLOIUMWG.module.min.js +2 -0
- package/dist/chunk-chunk-XEGXX4F7.module.min.js +1 -0
- package/dist/chunk-chunk-XFRBLXYM.module.min.js +1 -0
- package/dist/chunk-chunk-Z2AJERX5.module.min.js +2 -0
- package/dist/chunk-chunk-ZXYDYAB7.module.min.js +2 -0
- package/dist/components/ai/SemioticVACPBridge.d.ts +22 -0
- package/dist/components/ai/chartCapabilities.d.ts +5 -3
- package/dist/components/ai/conversationArc.d.ts +2 -176
- package/dist/components/ai/conversationArcTypes.d.ts +202 -0
- package/dist/components/ai/readerGrounding.d.ts +12 -0
- package/dist/components/ai/vacpAdapter.d.ts +13 -0
- package/dist/components/ai/vacpAdapterActions.d.ts +2 -0
- package/dist/components/ai/vacpAdapterModel.d.ts +7 -0
- package/dist/components/ai/vacpAdapterRuntime.d.ts +26 -0
- package/dist/components/ai/vacpAdapterState.d.ts +3 -0
- package/dist/components/ai/vacpAdapterTypes.d.ts +169 -0
- package/dist/components/ai/vacpTypes.d.ts +160 -0
- package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
- package/dist/components/charts/geo/DistanceCartogram.d.ts +1 -1
- package/dist/components/charts/index.d.ts +7 -4
- package/dist/components/charts/ordinal/BarChart.d.ts +7 -14
- package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
- package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -0
- package/dist/components/charts/ordinal/StackedBarChart.d.ts +3 -0
- package/dist/components/charts/ordinal/SwimlaneChart.d.ts +4 -14
- package/dist/components/charts/physics/ChainReactionChart.capability.d.ts +9 -0
- package/dist/components/charts/physics/ChainReactionChart.d.ts +29 -0
- package/dist/components/charts/physics/CollisionSwarmChart.d.ts +1 -1
- package/dist/components/charts/physics/EventDropChart.d.ts +7 -2
- package/dist/components/charts/physics/GaltonBoardChart.d.ts +1 -1
- package/dist/components/charts/physics/{PhysicsPileChart.capability.d.ts → PacketFlowChart.capability.d.ts} +1 -1
- package/dist/components/charts/physics/{PhysicalFlowChart.d.ts → PacketFlowChart.d.ts} +22 -6
- package/dist/components/charts/physics/PhysicsCustomChart.d.ts +1 -1
- package/dist/components/charts/physics/ProcessFlowChart.d.ts +7 -4
- package/dist/components/charts/physics/{PhysicalFlowChart.capability.d.ts → UnitPileChart.capability.d.ts} +1 -1
- package/dist/components/charts/physics/{PhysicsPileChart.d.ts → UnitPileChart.d.ts} +19 -6
- package/dist/components/charts/physics/crucibleChartProps.d.ts +1 -1
- package/dist/components/charts/physics/crucibleChartUtils.d.ts +9 -0
- package/dist/components/charts/physics/gauntletChartProps.d.ts +6 -1
- package/dist/components/charts/physics/gauntletTerminal.d.ts +61 -0
- package/dist/components/charts/physics/packetFlowSemantics.d.ts +6 -0
- package/dist/components/charts/physics/physicsHocUtils.d.ts +45 -2
- package/dist/components/charts/shared/auditAccessibilityStyles.d.ts +9 -0
- package/dist/components/charts/shared/chartSpecCore.d.ts +2 -4
- package/dist/components/charts/shared/gaugeGradient.d.ts +4 -8
- package/dist/components/charts/shared/gradient.d.ts +35 -0
- package/dist/components/charts/shared/hatchFill.d.ts +3 -10
- package/dist/components/charts/shared/hooks.d.ts +2 -50
- package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
- package/dist/components/charts/shared/streamPropsHelpers.d.ts +1 -2
- package/dist/components/charts/shared/useChartLegend.d.ts +65 -0
- package/dist/components/charts/shared/useChartSetup.d.ts +12 -0
- package/dist/components/charts/shared/useCustomChartSetup.d.ts +6 -1
- package/dist/components/charts/shared/useNetworkChartSetup.d.ts +1 -0
- package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
- package/dist/components/charts/xy/AreaChart.d.ts +25 -42
- package/dist/components/charts/xy/BumpChart.capability.d.ts +11 -0
- package/dist/components/charts/xy/BumpChart.d.ts +161 -0
- package/dist/components/charts/xy/DifferenceChart.d.ts +3 -10
- package/dist/components/charts/xy/Heatmap.d.ts +3 -0
- package/dist/components/charts/xy/LineChart.d.ts +6 -8
- package/dist/components/data/portability/capabilityBinding.d.ts +41 -0
- package/dist/components/data/portability/index.d.ts +2 -0
- package/dist/components/geometry/bumpRibbonGeometry.d.ts +36 -0
- package/dist/components/legendLayout.d.ts +75 -1
- package/dist/components/recipes/geographicDotGrid.d.ts +82 -0
- package/dist/components/recipes/geographicGrid.d.ts +100 -0
- package/dist/components/recipes/physics.d.ts +2 -0
- package/dist/components/recipes/physicsStageGeography.d.ts +137 -0
- package/dist/components/semiotic-ai.d.ts +6 -4
- package/dist/components/semiotic-experimental-vacp.d.ts +11 -0
- package/dist/components/semiotic-experimental.d.ts +6 -3
- package/dist/components/semiotic-geo.d.ts +5 -0
- package/dist/components/semiotic-network.d.ts +1 -0
- package/dist/components/semiotic-ordinal.d.ts +2 -0
- package/dist/components/semiotic-physics.d.ts +10 -6
- package/dist/components/semiotic-realtime-core.d.ts +1 -0
- package/dist/components/semiotic-recipes-core.d.ts +6 -1
- package/dist/components/semiotic-server-edge.d.ts +1 -1
- package/dist/components/semiotic-server.d.ts +1 -1
- package/dist/components/semiotic-xy.d.ts +4 -0
- package/dist/components/semiotic.d.ts +4 -4
- package/dist/components/server/renderEvidence.d.ts +1 -1
- package/dist/components/server/renderToStaticSVG.d.ts +2 -1
- package/dist/components/server/serverChartConfigHeatmap.d.ts +6 -0
- package/dist/components/server/serverChartConfigNetworkStyles.d.ts +12 -0
- package/dist/components/server/serverChartConfigShared.d.ts +16 -0
- package/dist/components/server/serverChartConfigs.d.ts +3 -2
- package/dist/components/server/serverChartConfigsPhysics.d.ts +2 -2
- package/dist/components/server/serverChartConfigsXY.d.ts +1 -1
- package/dist/components/server/staticLegend.d.ts +10 -2
- package/dist/components/server/staticSVGChrome.d.ts +14 -6
- package/dist/components/server/staticValue.d.ts +8 -0
- package/dist/components/stream/GeoSVGOverlay.d.ts +4 -10
- package/dist/components/stream/NetworkSVGOverlay.d.ts +2 -6
- package/dist/components/stream/OrdinalSVGOverlay.d.ts +2 -6
- package/dist/components/stream/SVGOverlay.d.ts +2 -6
- package/dist/components/stream/StalenessBadge.d.ts +2 -6
- package/dist/components/stream/geoPipelineConfig.d.ts +10 -0
- package/dist/components/stream/geoTypes.d.ts +3 -6
- package/dist/components/stream/legendRenderer.d.ts +10 -6
- package/dist/components/stream/ordinalTypes.d.ts +7 -31
- package/dist/components/stream/physics/PhysicsEvidence.d.ts +37 -0
- package/dist/components/stream/physics/PhysicsKernel.d.ts +1 -0
- package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +9 -0
- package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +2 -6
- package/dist/components/stream/physics/PhysicsSettledScene.d.ts +5 -0
- package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +2 -6
- package/dist/components/stream/physics/physicsFramePipelineConfig.d.ts +19 -0
- package/dist/components/stream/physics/physicsPipelineSettle.d.ts +52 -0
- package/dist/components/stream/physics/physicsRegionRuntime.d.ts +23 -0
- package/dist/components/stream/pipelineConfig.d.ts +7 -15
- package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +9 -69
- package/dist/components/stream/renderers/cornerRadii.d.ts +2 -9
- package/dist/components/stream/renderers/thresholdLineSegments.d.ts +12 -0
- package/dist/components/stream/sceneToSVGShared.d.ts +3 -5
- package/dist/components/stream/types.d.ts +34 -56
- package/dist/components/stream/xySceneBuilders/areaGradient.d.ts +4 -20
- package/dist/components/stream/xySceneBuilders/types.d.ts +6 -6
- package/dist/components/types/legendTypes.d.ts +31 -6
- package/dist/controls.min.js +1 -1
- package/dist/controls.module.min.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/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.d.ts +6 -4
- package/dist/semiotic-ai.min.js +1 -1
- package/dist/semiotic-ai.module.min.js +1 -1
- package/dist/semiotic-data.module.min.js +1 -1
- package/dist/semiotic-experimental-vacp.d.ts +11 -0
- package/dist/semiotic-experimental-vacp.min.js +1 -0
- package/dist/semiotic-experimental-vacp.module.min.js +1 -0
- package/dist/semiotic-experimental.d.ts +6 -3
- package/dist/semiotic-experimental.min.js +2 -1
- package/dist/semiotic-experimental.module.min.js +2 -1
- package/dist/semiotic-geo.d.ts +5 -0
- package/dist/semiotic-network.d.ts +1 -0
- package/dist/semiotic-ordinal.d.ts +2 -0
- package/dist/semiotic-physics.d.ts +10 -6
- package/dist/semiotic-realtime-core.d.ts +1 -0
- 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 +6 -1
- 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.d.ts +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-server.d.ts +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.min.js +1 -1
- package/dist/semiotic-utils.module.min.js +1 -1
- package/dist/semiotic-xy.d.ts +4 -0
- package/dist/semiotic.d.ts +4 -4
- 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 +18 -2
- package/spec/README.md +94 -2
- package/spec/bindings/README.md +14 -3
- package/spec/v0.1/examples/annotation-provenance-reviewed-revision.json +27 -0
- package/spec/v0.1/examples/annotation-provenance-watcher-threshold.json +21 -0
- package/spec/v0.1/examples/audience-profile-executive-review.json +24 -0
- package/spec/v0.1/examples/audience-profile-incident-operators.json +42 -0
- package/spec/v0.1/examples/chart-capability-bar-comparison.json +48 -0
- package/spec/v0.1/examples/chart-capability-service-flow.json +54 -0
- package/dist/chunk-chunk-4AANPFOX.module.min.js +0 -2
- package/dist/chunk-chunk-5I3UZV4Q.module.min.js +0 -2
- package/dist/chunk-chunk-5RKXZQ2P.module.min.js +0 -1
- package/dist/chunk-chunk-74CCPVXB.module.min.js +0 -1
- package/dist/chunk-chunk-7ALTGHK6.module.min.js +0 -1
- package/dist/chunk-chunk-ANYDWOZF.module.min.js +0 -1
- package/dist/chunk-chunk-AVBI6GDT.module.min.js +0 -1
- package/dist/chunk-chunk-BANTPINB.module.min.js +0 -2
- package/dist/chunk-chunk-C4YA6TDR.module.min.js +0 -1
- package/dist/chunk-chunk-C57LR3YG.module.min.js +0 -1
- package/dist/chunk-chunk-CKMD5NV3.module.min.js +0 -2
- package/dist/chunk-chunk-CO5KQMGH.module.min.js +0 -1
- package/dist/chunk-chunk-CWQ5YIHX.module.min.js +0 -2
- package/dist/chunk-chunk-E6TXX6MI.module.min.js +0 -1
- package/dist/chunk-chunk-GMQ5AYTD.module.min.js +0 -1
- package/dist/chunk-chunk-JCG72SGW.module.min.js +0 -2
- package/dist/chunk-chunk-K3DMEW22.module.min.js +0 -1
- package/dist/chunk-chunk-KT2VAZMZ.module.min.js +0 -1
- package/dist/chunk-chunk-L6EA5V3G.module.min.js +0 -2
- package/dist/chunk-chunk-LJPCLYSC.module.min.js +0 -2
- package/dist/chunk-chunk-LRIFN2HK.module.min.js +0 -1
- package/dist/chunk-chunk-N5DDKCCF.module.min.js +0 -1
- package/dist/chunk-chunk-NEVE562N.module.min.js +0 -1
- package/dist/chunk-chunk-NLO44TOS.module.min.js +0 -2
- package/dist/chunk-chunk-PZJ2SBLL.module.min.js +0 -2
- package/dist/chunk-chunk-QSQVBIJA.module.min.js +0 -1
- package/dist/chunk-chunk-QUJ6TTLY.module.min.js +0 -1
- package/dist/chunk-chunk-RBIDBUT4.module.min.js +0 -2
- package/dist/chunk-chunk-RCF52Z42.module.min.js +0 -2
- package/dist/chunk-chunk-RFLAG356.module.min.js +0 -1
- package/dist/chunk-chunk-RPU4IZAV.module.min.js +0 -2
- package/dist/chunk-chunk-SKMBCFIL.module.min.js +0 -2
- package/dist/chunk-chunk-TAE7W424.module.min.js +0 -2
- package/dist/chunk-chunk-TUBMTZMU.module.min.js +0 -2
- package/dist/chunk-chunk-UFFEXJQY.module.min.js +0 -1
- package/dist/chunk-chunk-XSCHTS4D.module.min.js +0 -2
- package/dist/chunk-chunk-XXWSHGPL.module.min.js +0 -2
- package/dist/chunk-chunk-ZOAQDIJO.module.min.js +0 -1
- package/dist/chunk-chunk-ZXIXAPRE.module.min.js +0 -2
- package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +0 -1
- package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{accessorsEquivalent as t,annotationActivationProps as e,annotationBudget as o,annotationDensity as n,bandFromAge as i,coerceDateLikeValue as r,createStore as s,filterAnnotationsByStatus as a,isAnnotationActivationTarget as c,isNoteAnnotation as l,mulberry32 as u,parseDateLikeString as d,resolveAccessor as h,resolveRawAccessor as f,resolveResponsiveRules as p,resolveStringAccessor as y,useAnnotationActivationOptions as g,useObservationSelector as m,validateArrayData as b}from"./chunk-chunk-74CCPVXB.module.min.js";import{SEGMENT_FIELD as x,buildAnomalyAnnotations as v,buildForecast as w,createSegmentLineStyle as k,getMax as A,getMin as S,getMinMax as M}from"./chunk-chunk-AVBI6GDT.module.min.js";function _(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 P(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:C}}),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 C=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],R={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}},I={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}},L={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:C,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 T(t,e){if("light"===e)return R;if("dark"===e)return I;if("high-contrast"===e)return L;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?I:R;return P({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}return P({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}var[$,z]=s(t=>({theme:R,setTheme(e){t(t=>({theme:T(t.theme,e)}))}})),D={light:R,dark:I,"high-contrast":L,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 E(t){if(!t)return R;if("string"==typeof t){if("light"===t)return R;if("dark"===t)return I;if("high-contrast"===t)return L;return D[t]||R}const e="dark"===t.mode?I:R;return P({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}})}function O(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 F={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function B(t,e={}){const o=e.mobileSemantics?.interaction,n="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==n,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return F;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??n??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var N={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 W(t,e,o){const n=N[t||"primary"],i=t&&"primary"!==t||!o?.width?n.width:o.width,r=t&&"primary"!==t||!o?.height?n.height:o.height,s={...e,mode:t},a=p(s,{width:e.width??i,height:e.height??r}).props,c=a.mode||t||"primary",l=N[c],u="context"===c||"sparkline"===c,d="primary"===c&&o?.width?o.width:l.width;return{mode:c,width:a.width??d,height:a.height??("primary"===c&&o?.height?o.height:l.height),showAxes:a.showAxes??l.showAxes,showGrid:a.showGrid??l.showGrid,enableHover:a.enableHover??(!!a.linkedHover||l.enableHover),showLegend:a.showLegend??l.showLegend,showLabels:a.showLabels??l.showLabels,title: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:j(l.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:B(a.mobileInteraction,{mode:c,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}function j(t,e,o){if(!1!==e)return t;const n={...t};return"horizontal"===o?n.left=Math.min(n.left,15):n.bottom=Math.min(n.bottom,15),n}import*as Y from"react-dom/server";import*as G from"react";function q({data:t,safeData:e,areaBy:o,lineDataAccessor:n}){if(null==t)return[];const i=void 0!==e[0]?.[n];if(!i&&!o)return e;let r;if(i)r=e;else{const t=e.reduce((t,e)=>{const i="function"==typeof o?o(e):e[o],r=i+"";if(!t[r]){const e={[n]:[]};"string"==typeof o&&(e[o]=i),t[r]=e}return t[r][n].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[n])?t[n]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}var X=Object.freeze([]);function H(t){if(!t)return X;let e=!1;for(let o=0;t.length>o;o++){const n=t[o];if(null==n||"object"!=typeof n){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}import{scaleOrdinal as V}from"d3-scale";function U(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function K(t,e,o){const n=t=>t.toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Z(t){const e=t.map(U),o=e.length-1;return t=>{if(0>=t){const[t,o,n]=e[0];return K(t,o,n)}if(t>=1){const[t,n,i]=e[o];return K(t,n,i)}const n=t*o,i=Math.floor(n),r=n-i,[s,a,c]=e[i],[l,u,d]=e[i+1];return K(Math.round(s+(l-s)*r),Math.round(a+(u-a)*r),Math.round(c+(d-c)*r))}}var Q=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],J=Z(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),tt=Z(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),et=Z(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),ot=Z(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),nt=Z(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),it=Z(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),rt=Z(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),st=Z(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),at=Z(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),ct=Z(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),lt=Z(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),ut=Z(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),dt={blues:J,reds:tt,greens:et,viridis:rt,oranges:ot,purples:nt,greys:it,plasma:st,inferno:at,magma:ct,cividis:lt,turbo:ut};function ht(t){return t&&dt[t]||J}var ft=Z(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),pt=Z(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),yt=Z(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),gt=Z(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),mt=Z(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),bt=Z(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),xt=Z(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),vt={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"],...dt},wt=Q,kt="#007bff";function At(t,e,o=wt){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=vt[t];if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var St=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Mt=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],_t=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 Pt(t,e,o){if("function"==typeof e){const n=e(t);return o&&n&&"string"==typeof n&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||_t.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):wt[Math.abs(function(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o),e&=e;return Math.abs(e)}(n))%wt.length]}function Ct(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const o=t[e];return"string"==typeof o&&o.length>0?o:void 0}function Rt(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>Ct(t,e)??"#999"}const n=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),i=n.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return V().domain(n).range(o).unknown("#999");const r=vt[o]||vt.category10;if(i&&"function"==typeof r){let t=-1/0;for(const e of n){const o=Number(e);o>t&&(t=o)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:wt;return V().domain(n).range(t).unknown("#999")}}function It(t,e,o=[3,20],n){let i;if(i="function"==typeof e?e(t):t?.[e],!n)return i;const[r,s]=n,[a,c]=o;if(s===r)return(a+c)/2;let l=(i-r)/(s-r);return 0>l?l=0:l>1&&(l=1),a+l*(c-a)}function Lt(t,e){if(!function(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}function Tt(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>Dt(e(t))}function $t(t,e){const o=Tt(t),n=Tt(e);return(t,e)=>{const i=n(t);return{value:i,x:o(t),y:i,category:e}}}function zt(t,e){const o=Tt(e??"value"),n=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=n?n(t):void 0;return{value:o(t),category:null==e?void 0:e+""}}}function Dt(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 Et(t,e,o){const n=t.when;return void 0===n||!0===n||!1!==n&&("function"==typeof n?n(e,o):function(t,e,o){const n=null!=t.axis?o[t.axis]:null!=t.field?e[t.field]:o.value;if(void 0!==t.eq&&n!==t.eq)return!1;if(void 0!==t.ne&&n===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(n))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=Dt(n);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,o]=t.within;if(e>i||i>o)return!1}if(void 0!==t.outside){const[e,o]=t.outside;if(i>=e&&o>=i)return!1}return!0}(n,e,o))}function Ot(t,e,o){if(!e||0===e.length)return{};let n={};for(const i of e){if(!Et(i,t,o))continue;const e="function"==typeof i.style?i.style(t,o):i.style;e&&(n={...n,...e})}return n}function Ft(t,e,o,n=t=>t){const i=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=n(t),a={...i(t,r)};return Object.assign(a,Ot(s,e,o(s,r))),a}:i}function Bt(t,e,o,n){if(!t||0===t.length)return n;const i=zt(e,o);return(e,o)=>{const r=e&&e.data||e,s=Ot(r,t,i(r)),a=n?n(e,o):void 0;return a?{...s,...a}:s}}function Nt(t,e){return"touch"===e?Math.max(t,24):t}function Wt(t){return Array.isArray(t)?t[0]:t}function jt(t,e,o,n){return{data:Wt(t),x:e,y:o,__semioticHoverData:!0,...n}}var Yt=["name","label","title"],Gt=["type","kind","category","group","class","status","role","shape"],qt=["value","amount","total","count","weight","score"],Xt=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 Ht(t,e){for(const o of e){const e=t.find(t=>t.lower===o);if(e)return e}}function Vt(t,e={}){if(!t||"object"!=typeof t)return{entries:[]};const o=e.maxEntries??6,n=!1!==e.skipPositional,i=[];for(const[e,o]of Object.entries(t)){if(e.startsWith("_"))continue;if("data"===e)continue;if(n&&Xt.has(e.toLowerCase()))continue;if(null==o)continue;const t=typeof o;("string"===t||"number"===t||"boolean"===t||o instanceof Date)&&i.push({key:e,lower:e.toLowerCase(),value:o})}if(0===i.length)return{entries:[]};let r=i.findIndex(t=>Yt.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 c=i.filter((t,e)=>e!==r);s&&(c=c.filter(t=>"id"!==t.lower));const l=Ht(c,Gt),u=Ht(c,qt),d=new Set(Gt),h=new Set(qt),f=[];l&&f.push({key:l.key,value:l.value}),u&&f.push({key:u.key,value:u.value});for(const t of c){if(f.length>=o)break;t!==l&&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 Ut,jsxs as Kt}from"react/jsx-runtime";var Zt={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 Qt(t,e){return"function"==typeof e?e(t):t[e]}function Jt(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 te(t={}){const{fields:e,title:o,format:n,style:i={},className:r=""}=t;return t=>{if(!t||"object"!=typeof t)return null;let s;const a=[];if(o){const e=Qt(t,o);s=Jt(e,n)}if(e&&e.length>0)e.forEach(e=>{let o,i,r;"string"==typeof e?(o=e,i=e,r=n):(o=e.label,i=e.accessor||e.key||"",r=e.format||n);const s=Qt(t,i);a.push({label:o,value:Jt(s,r)})});else if(!o){const e=["value","y","name","id","label"];for(const o of e)if(void 0!==t[o]){s=Jt(t[o],n);break}if(!s){const e=Object.keys(t).filter(t=>!t.startsWith("_"));e.length>0&&(s=Jt(t[e[0]],n))}}const c={...Zt,...i};return Kt("div",{className:("semiotic-tooltip "+r).trim(),style:c,children:[s&&Ut("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((t,e)=>Kt("div",{style:{marginTop:0===e&&s?"4px":0},children:[t.label&&Kt("span",{children:[t.label,": "]}),t.value]},e))]})}}function ee(t){if(!0!==t){if("function"==typeof t){const e=t;return t=>{let o=Wt(!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)?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;const n=e(o);return null==n?null:Ut("div",{className:"semiotic-tooltip",style:Zt,children:n})}}return!1!==t&&void 0!==t&&("object"==typeof t&&null!==t&&("fields"in t||"title"in t)?te(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:o,format:n,style:i={},className:r="",showLabels:s=!0,separator:a=": "}=t;return t=>{if(!t||"object"!=typeof t)return null;const c=[];if(o){const e=Qt(t,o);c.push({value:Jt(e,n)})}if(e&&Array.isArray(e)&&e.length>0)e.forEach(e=>{let o,i,r;"string"==typeof e?(o=e,i=e,r=n):(o=e.label,i=e.accessor||e.key||"",r=e.format||n);const a=Jt(Qt(t,i),r);c.push({label:s?o:void 0,value:a})});else{const e=Vt(t,{skipPositional:!1});null!=e.title&&c.push({label:void 0,value:Jt(e.title,n),bold:!0}),e.entries.forEach(t=>{c.push({label:s?t.key:void 0,value:Jt(t.value,n)})})}const l={...Zt,...i};return Array.isArray(c)&&0!==c.length?Ut("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+r).trim(),style:l,children:c.map((t,e)=>Kt("div",{style:{marginBottom:c.length-1>e?"4px":0,fontWeight:t.bold?"bold":void 0},children:[t.label&&Kt("strong",{children:[t.label,a]}),t.value]},e))}):null}}()):te())}}function oe(t){const{title:e,description:o,summary:n,accessibleTable:i,className:r,animate:s,axisExtent:a,autoPlaceAnnotations:c}=t,l={};return e&&(l.title=e),o&&(l.description=o),n&&(l.summary=n),void 0!==i&&(l.accessibleTable=i),r&&(l.className=r),null!=s&&(l.animate=s),void 0!==a&&(l.axisExtent=a),void 0!==c&&(l.autoPlaceAnnotations=c),l}function ne(t){const{linkedHover:e,selection:o,onObservation:n,onClick:i,hoverRadius:r,hoverHighlight:s,forceHoverBehavior:a,forceClickBehavior:c,mobileInteraction:l,customHoverBehavior:u,customClickBehavior:d,linkedHoverInClickPredicate:h=!0}=t,f={};n&&(f.annotationObservationCallback=n);const p=l?.enabled?Math.max(r??30,Math.ceil((l.targetSize||44)/2),24):r;return(a||e||n||i||s)&&(f.customHoverBehavior=u),d&&(c||(h?n||i||e:n||i)||l?.enabled&&(l.tapToSelect||l.tapToLockTooltip)&&(e||s||o))&&(f.customClickBehavior=d),null!=p&&(f.hoverRadius=p),f}function ie(t){const{tooltip:e,defaultTooltipContent:o}=t;return{tooltipContent:!1===e?()=>null:ee(e)||o}}import{useMemo as re,forwardRef as se,useRef as ae}from"react";import*as ce from"react";import{useRef as le,useState as ue,useEffect as de,useMemo as he,useCallback as fe,useImperativeHandle as pe,useId as ye,forwardRef as ge,memo as me}from"react";import*as be from"react";import{jsx as xe}from"react/jsx-runtime";var ve=null,we=null;function ke(t){const[e,o]=be.useState(()=>ve);return be.useEffect(()=>{if(e)return;let t=!1;return(ve?Promise.resolve(ve):(we||(we=import("./chunk-XYBrushOverlay-ECZJJLAJ.module.min.js").then(t=>ve=t.XYBrushOverlay).catch(t=>{throw we=null,t})),we)).then(e=>{t||o(()=>e)}),()=>{t=!0}},[e]),e?xe(e,{...t}):null}var Ae=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=H(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 o=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const n=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,n),bounded:!1}),e=n,this.chunkTimer=t.length>e?requestAnimationFrame(o):0};this.chunkTimer=requestAnimationFrame(o)}setReplacementData(t){if(t=H(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 o=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const n=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,n),bounded:!1}),e=n,this.chunkTimer=t.length>e?requestAnimationFrame(o):0};this.chunkTimer=requestAnimationFrame(o)}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 o=0;t.length>o;o++){const n=t[o];null!=n&&"object"==typeof n&&(this.pushBuffer.push(n),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}},Se=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 o of t){const t=this.push(o);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 o=0;this._size>o;o++)t(this.buffer[(e+o)%this._capacity],o)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t[o]=this.buffer[(e+o)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let o=0,n=[];e.length>t&&(o=e.length-t,n=e.slice(0,o)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=o;e.length>t;t++)this.push(e[t]);return n}update(t,e){const o=[],n=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const r=(n+i)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},o.push(t),this.buffer[r]=e(s)}}return o}remove(t){const e=[],o=[];if(this.forEach(n=>{t(n)?o.push(n):e.push(n)}),0===o.length)return o;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return o}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}},Me=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 o of t){const t=e?e(o):o;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 _e(t){return new Set(Array.isArray(t)?t:[t])}function Pe(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Ce(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Re(t,e,o){return t+(e-t)*o}function Ie(){return"undefined"!=typeof performance?performance.now():Date.now()}function Le(t,e,o){if(1>=o)return 1;const n=o-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 o=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>o?1:e;if("exponential"===t.type){const n=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(n>0?n:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:n-e,extent:n,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function Te(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function $e(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function ze(t,e,o,n){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==o&&(t._pulseColor=o,i=!0),t._pulseGlowRadius!==n&&(t._pulseGlowRadius=n,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 De(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const n=t.duration??500,i=e.peek();return null!=i&&n>o-i}function Ee(t,e,o){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 o=t.getX(e.datum),n=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${n}`;if(null!=o&&null!=n)return`p:${o}:${n}`}return"p:"+o;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+o;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??o}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+o:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function Oe(t,e,o,n,i,r){const s=[];for(const i of t){const t=o(i),r=n(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),c=Array(s.length),l=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],c[t]=e.rawY,l[t]=e.d}return{type:"line",path:a,rawValues:c,style:i,datum:l,group:r}}function Fe(t,e,o,n,i,r,s,a){const c=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const l=e.x(t),u=a?a(r):i;c.push({px:l,topY:e.y(s),botY:e.y(u)})}c.sort((t,e)=>t.px-e.px);const l=Array(c.length),u=Array(c.length);for(let t=0;c.length>t;t++){const e=c[t];l[t]=[e.px,e.topY],u[t]=[e.px,e.botY]}return{type:"area",topPath:l,bottomPath:u,style:r,datum:t,group:s}}function Be(t,e,o,n){const i=new Map;if("silhouette"===n)for(const n of t){let t=0;for(const i of e)t+=o(i,n)||0;i.set(n,-t/2)}else if("wiggle"===n){t.length>0&&i.set(t[0],0);for(let n=1;t.length>n;n++){const r=t[n-1],s=t[n];let a=0,c=0,l=0;for(const t of e){const e=o(t,s)||0;a+=(2*l+e)*(e-(o(t,r)||0)),c+=e,l+=e}const u=i.get(r)??0;i.set(s,u-(c>0?a/(2*c):0))}if(t.length>0){let n=0;for(const r of t){let t=0;for(const n of e)t+=o(n,r)||0;n+=(i.get(r)??0)+t/2}const r=n/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 Ne(t,e,o,n,i,r,s){const a=o(t),c=n(t);if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l={type:"point",x:e.x(a),y:e.y(c),r:i,style:r,datum:t};return void 0!==s&&(l.pointId=s),l}function We(t,e,o,n,i,r,s,a){const c=o(t),l=n(t);if(!Number.isFinite(c)||!Number.isFinite(l))return null;const u={type:"symbol",x:e.x(c),y:e.y(l),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function je(t,e,o,n,i,r,s){return{type:"rect",x:t,y:e,w:o,h:n,style:i,datum:r,group:s}}function Ye(t,e,o,n,i,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:n,fill:i,datum:r};return s?.showValues&&(a.showValues=!0,a.value=s.value,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function Ge(t,e,o,n){return"function"==typeof e.style?e.style(n||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,n)}function qe(t,e,o,n){if(!t.scales)return null;const i=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=n.getTop(o),a=n.getBottom(o);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const c=t.scales.x(e),l=t.scales.y(s),u=t.scales.y(a);Number.isFinite(c)&&Number.isFinite(l)&&Number.isFinite(u)&&(i.push([c,l]),r.push([c,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:Ge(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function Xe(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const n of t)n.perSeries?e.push(n):o.push(n);return{perSeries:e,aggregate:o}}function He(t,e,o){const n=[];for(const i of o){const o=qe(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function Ve(t,e,o,n){const i=[];for(const r of n){const n=qe(t,e,o,r);n&&i.push(n)}return i}function Ue(t,e){if(!t)return{};if(!e||0===e.length)return t;const o=[];for(const n of e){if("band"!==n.kind)continue;const e=n.getTop(t),i=n.getBottom(t);Number.isFinite(i)&&Number.isFinite(e)&&o.push({y0:i,y1:e})}return 0===o.length?t:{...t,band:o[0],bands:o}}function Ke(t,e,o,n){if(!t.config.pointStyle)return;const i=n??t.getY;for(const n of e){const e=t.resolveGroupColor(n.key);for(const r of n.data){let n=t.config.pointStyle(r);!n.fill&&e&&(n={...n,fill:e});const s=n.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,c=Ne(r,t.scales,t.getX,i,s,n,a);c&&o.push(c)}}}function Ze(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}var Qe={topOpacity:.8,bottomOpacity:.05};function Je(t){if(t)return!0===t?Qe:"colorStops"in t?t:{topOpacity:t.topOpacity??Qe.topOpacity,bottomOpacity:t.bottomOpacity??Qe.bottomOpacity}}import{symbol as to,symbolCircle as eo,symbolCross as oo,symbolDiamond as no,symbolSquare as io,symbolStar as ro,symbolTriangle as so,symbolWye as ao}from"d3-shape";var co={circle:eo,square:io,triangle:so,diamond:no,star:ro,cross:oo,wye:ao},lo=["circle","triangle","diamond","star","square","chevron","cross","wye"];function uo(t,e,o){if(o)return o;const n=t??"circle";return"chevron"===n?function(t){const e=1.5*ho(t),o=.92*e;return`M0,${-e}L${o},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-o},${(.78*e).toFixed(3)}Z`}(e):to(co[n]??eo,Math.max(1,e))()??""}function ho(t){return Math.sqrt(Math.max(1,t)/Math.PI)}var fo=new Map;function po(t,e,o){const n=o.config.areaStyle?.(e);return n&&(t.style=n),t}function yo(t,e,o,n,i){const r=new Map;for(const s of t){const t=e(s),a=o(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const c=Math.floor(t/n)*n;let l=r.get(c);if(l||(l={start:c,end:c+n,total:0,categories:new Map},r.set(c,l)),l.total+=a,i){const t=i(s);l.categories.set(t,(l.categories.get(t)||0)+a)}}return r}function go(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;mo(n)&&0===o.length&&bo(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.`),o.length>0&&o.every(t=>null==t.datum)&&bo(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 mo(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(mo))}function bo(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function xo(t,e,o,n){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:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:n}}function vo(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function wo(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=vo(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=h(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e+i:e},getBottom:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e-i:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const o=Array.isArray(t.band)?t.band:[t.band];for(const t of o)e.push({kind:"band",getTop:vo(t.y1Accessor,"y1"),getBottom:vo(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as ko,scaleLog as Ao,scaleSymlog as So,scaleTime as Mo}from"d3-scale";function _o(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Po(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return Ao().domain(t).range(o).clamp(!0)}return"symlog"===t?So().domain(e).range(o):"time"===t?Mo().domain([new Date(e[0]),new Date(e[1])]).range(o):ko().domain(e).range(o)}function Co(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Ro(t,e){const o=new Se(t.capacity);return t.forEach(()=>o.push(e)),o}function Io(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Lo(t,e,o){if(!e||0===e.size)return;const n=new Set;if(t.forEach((t,e)=>{o(t)&&n.add(e)}),0===n.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)n.has(t)||e.push(i[t])}var To=new WeakMap;function $o(){return this.updateResults.last}function zo(){return this.updateResults.last}function Do(t){return this.updateResults.subscribe(t)}function Eo(t){this.config.layoutSelection=t}function Oo(){To.set(this,!0)}function Fo(){const t=!0===To.get(this);return To.delete(this),t}function Bo(t){Object.assign(t.prototype,{getLastUpdateResult:$o,getUpdateSnapshot:zo,subscribeUpdateResult:Do,setLayoutSelection:Eo,markStylePaintPending:Oo,consumeStylePaintPending:Fo})}var No={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 Wo(t,e){const o={...t};for(const t of e)o[No[t]]++;return o}function jo(t,e,o){const n=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:n,revisions:Wo(o,n)}}var Yo=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=jo({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 o=jo(t,e,this.revisions);this.revisions=o.revisions,this.latest=o;for(const t of[...this.listeners])t();return o}},Go=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],qo=["scene-style","data-paint","accessibility","evidence"],Xo=(t,e)=>({retainedData:t,invalidations:e}),Ho=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Uo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ko=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zo=["scene-geometry","data-paint","accessibility","evidence"],Qo=["scene-style","data-paint","accessibility","evidence"],Jo=[],tn={chartType:Xo("rebuild",Ho),runtimeMode:Xo("rebuild",Ho),xAccessor:Xo("rebuild",Ho),yAccessor:Xo("rebuild",Ho),timeAccessor:Xo("rebuild",Ho),valueAccessor:Xo("rebuild",Ho),y0Accessor:Xo("rebuild",Ho),boundsAccessor:Xo("rebuild",Ho),band:Xo("rebuild",Ho),openAccessor:Xo("rebuild",Ho),highAccessor:Xo("rebuild",Ho),lowAccessor:Xo("rebuild",Ho),closeAccessor:Xo("rebuild",Ho),candlestickRangeMode:Xo("rebuild",Ho),accessorRevision:Xo("rebuild",Ho),groupAccessor:Xo("rebuild",Vo),categoryAccessor:Xo("rebuild",Vo),lineDataAccessor:Xo("rebuild",Vo),colorAccessor:Xo("rebuild",Qo),sizeAccessor:Xo("rebuild",Zo),symbolAccessor:Xo("rebuild",Zo),pointIdAccessor:Xo("rebuild",Zo),xScaleType:Xo("preserve",Uo),yScaleType:Xo("preserve",Uo),xExtent:Xo("preserve",Uo),yExtent:Xo("preserve",Uo),extentPadding:Xo("preserve",Uo),scalePadding:Xo("preserve",Uo),axisExtent:Xo("preserve",Uo),binSize:Xo("preserve",Uo),normalize:Xo("preserve",Uo),heatmapAggregation:Xo("preserve",Uo),heatmapXBins:Xo("preserve",Uo),heatmapYBins:Xo("preserve",Uo),arrowOfTime:Xo("preserve",Ko),baseline:Xo("preserve",Ko),stackOrder:Xo("preserve",Ko),sizeRange:Xo("preserve",Ko),curve:Xo("preserve",Ko),areaGroups:Xo("preserve",Ko),customLayout:Xo("preserve",Ko),layoutConfig:Xo("preserve",Ko),layoutMargin:Xo("preserve",Ko),symbolMap:Xo("preserve",Zo),showValues:Xo("preserve",Zo),heatmapValueFormat:Xo("preserve",Zo),lineStyle:Xo("preserve",Qo),pointStyle:Xo("preserve",Qo),areaStyle:Xo("preserve",Qo),barStyle:Xo("preserve",Qo),swarmStyle:Xo("preserve",Qo),waterfallStyle:Xo("preserve",Qo),candlestickStyle:Xo("preserve",Qo),boundsStyle:Xo("preserve",Qo),gradientFill:Xo("preserve",Qo),lineGradient:Xo("preserve",Qo),colorScheme:Xo("preserve",Qo),themeCategorical:Xo("preserve",Qo),themeSemantic:Xo("preserve",Qo),themeSequential:Xo("preserve",Qo),themeDiverging:Xo("preserve",Qo),barColors:Xo("preserve",Qo),decay:Xo("preserve",Qo),pulse:Xo("preserve",Qo),staleness:Xo("preserve",Qo),layoutSelection:Xo("preserve",Qo),annotations:Xo("preserve",["overlay","accessibility","evidence"]),windowSize:Xo("preserve",Jo),windowMode:Xo("preserve",Jo),maxCapacity:Xo("preserve",Jo),clock:Xo("preserve",Jo),transition:Xo("preserve",Jo),introAnimation:Xo("preserve",Jo),onLayoutError:Xo("preserve",Jo)},en=Xo("preserve",Ko),on=class{constructor(){this.tracker=new Yo}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}},Go)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},qo):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=tn[n]??en;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as nn}from"d3-quadtree";var rn=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 o=0,n=0;for(const t of e)"point"===t.type&&(o++,t.r>n&&(n=t.r));if(this.maxRadius=n,500>=o)return void(this.tree=null);const i=Array(o);let r=0;for(const t of e)"point"===t.type&&(i[r++]=t);this.tree=nn().x(t=>t.x).y(t=>t.y).addAll(i)}},sn=class e{constructor(t){if(this.xExtent=new Me,this.yExtent=new Me,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 on,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 rn,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;const l=i??(()=>{const t=new Map;for(let e=0;o.length>e;e++)t.set(o[e],e);return t})();for(const o of e){if("line"===o.type)continue;if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[o.datum];let i=0,a=!1;for(const o of e){const e=l.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const c=$e(t,s,r);c>i&&(i=c)}a&&(c=ze(o,i,s)||c);continue}const e=l.get(o.datum);if(null==e)continue;const i=n.get(e);c=ze(o,null==i?0:$e(t,i,r),s,a)||c}return c}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new Se(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=h(t.timeAccessor||t.xAccessor,"time"),this.getY=h(t.valueAccessor||t.yAccessor,"value")):(this.getX=h(t.xAccessor,"x"),this.getY=h(t.yAccessor,"y")),this.getGroup=y(t.groupAccessor),this.getCategory=y(t.categoryAccessor),this.getSize=t.sizeAccessor?h(t.sizeAccessor,"size"):void 0,this.getColor=y(t.colorAccessor),this.getSymbol=y(t.symbolAccessor),this.getY0=t.y0Accessor?h(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=wo(t),this.getPointId=y(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?h(t.openAccessor,"open"):void 0,this.getHigh=h(t.highAccessor,"high"),this.getLow=h(t.lowAccessor,"low"),this.getClose=o?h(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new Se(t.windowSize))}currentTime(){return this.config.clock?.()??Ie()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Ro(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 o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(n)&&this.yExtent.push(n)}}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 o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(n)&&this.yExtent.evict(n)}}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 o=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=o?h(this.config.timeAccessor||this.config.xAccessor,"time"):h(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,n="function"==typeof o?o(e):e[o||"x"],i=n instanceof Date,s="string"==typeof n&&Number.isFinite(d(n));if(this.xIsDate=i||s,s){const t="string"==typeof o?o:void 0;this.getX=t?e=>r(e[t]):t=>r(o(t))}}Co(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Io(this.buffer,o,this.timestampBuffer,e),this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o)}else for(const o 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=Io(this.buffer,o,this.timestampBuffer,e);this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o),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:o}=this,n=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(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=_o(this.xExtent.extent,e.xExtent),c=_o(s,e.yExtent);const l=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===e.axisExtent;if("stackedarea"===e.chartType&&!l&&o.size>0){const t=function(t){const{config:e,groups:o,getX:n,getY:i}=t,r="exact"===e.axisExtent;if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,c=new Set;let l=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=n(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),c.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>l&&(l=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,y;if("input"===h)p=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}),e=[],n=[];let i=0,r=0;for(const o of t)r>i?(e.push(o),i+=d.get(o)??0):(n.push(o),r+=d.get(o)??0);p=[...n.reverse(),...e]}else p="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:f(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}):o.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),o=Be(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let n=1/0,i=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;n>t&&(n=t),t+r>i&&(i=t+r)}Number.isFinite(n)&&Number.isFinite(i)||(n=0,i=0);const s=i-n,l=r?0:s>0?s*e.extentPadding:1;y=[n-l,i+l]}else if("diverging"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),[o,n]=function(t,e,o){let n=0,i=0;for(const r of t){let t=0,s=0;for(const n of e){const e=o(n,r)||0;0>e?s+=e:t+=e}n>s&&(n=s),t>i&&(i=t)}return[n,i]}(t,p,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;y=[o-s,n+s]}else y=[0,l+(r?0:l>0?l*e.extentPadding:1)];return{yDomain:y,stackExtentCache:{key:s,yDomain:y}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!l&&o.size>0?c=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=yo(t,e,o,n,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,o,n,i);return[0,s?a:a+a*r]}(o,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,d):"waterfall"===e.chartType&&!l&&o.size>0?c=function(t,e,o,n){const[i,r]=function(t,e){let o=0,n=0,i=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(i+=t,o>i&&(o=i),i>n&&(n=i))}return[o,n]}(t,e),s=r-i,a=n?0:s>0?s*o:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(o,this.getY,e.extentPadding,d):l||c[0]===1/0||(c=function(t,e,o){if(!o.length)return t;let[n,i]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(n>o&&(n=o),o>i&&(i=o)),Number.isFinite(r)&&(n>r&&(n=r),r>i&&(i=r))}return[n,i]}(c,r,this.resolvedRibbons),c=function(t,e){const o=t[1]-t[0],n=e.exactMode?0:o>0?o*e.extentPadding:1,i=[null!=e.userMin?t[0]:t[0]-n,null!=e.userMax?t[1]:t[1]+n];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}(c,{exactMode:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));c=function(t,e,o){if(!e||o)return t;const n=e[0],i=e[1];return null==n&&null==i?t:[null!=n?n:t[0],null!=i?i:t[1]]}(c,e.yExtent,!!l),({xDomain:a,yDomain:c}=function(t,e,o){let n=t,i=e;if(n[0]===1/0||n[1]===-1/0)if("time"===o){const t=Date.now();n=[t-864e5,t]}else n=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:n,yDomain:i}}(a,c,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:n,yDomain:i}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){if("x"==("up"===(a=e.arrowOfTime)||"down"===a?"y":"x")){const t="right"===e.arrowOfTime?[s,o.width-s]:[o.width-s,s];return{x:ko().domain(n).range(t),y:Po(e.yScaleType,i,[o.height-s,s])}}const t="down"===e.arrowOfTime?[s,o.height-s]:[o.height-s,s];return{x:Po(e.yScaleType,i,[s,o.width-s]),y:ko().domain(n).range(t)}}var a;return{x:Po(e.xScaleType,n,[s,o.width-s]),y:Po(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:c}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,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,o=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const n of t.path)n[0]*=e,n[1]*=o;break;case"area":for(const n of t.topPath)n[0]*=e,n[1]*=o;for(const n of t.bottomPath)n[0]*=e,n[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*o,width:t.clipRect.width*e,height:t.clipRect.height*o});break;case"point":case"glyph":t.x*=e,t.y*=o;break;case"rect":case"heatcell":t.x*=e,t.y*=o,t.w*=e,t.h*=o;break;case"candlestick":t.x*=e,t.openY*=o,t.closeY*=o,t.highY*=o,t.lowY*=o}const n=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Po,c=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),l=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-c,c]:[c,t.width-c]),y:a(this.config.yScaleType,i,l?[c,t.height-c]:[t.height-c,c])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:n}=this;if(!n)return[];if(o.customLayout){const i={data:e,scales:n,dimensions:{width:t.width,height:t.height,margin:o.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:o.themeCategorical??St},resolveColor:(t,e)=>{const n=this.resolveGroupColor(t);if(n)return n;const i=this.resolveLineStyle(t,e);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null};let r;try{r=o.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,n=xo("xy",t,e,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.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=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,o.layoutSelection??null)}return go({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:n,config:o,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(o.chartType){case"line":return function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(Ze).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=Xe(t.ribbons);if(r.length>0&&n.push(...He(t,e,r)),i.length>0)for(const e of o)n.push(...Ve(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=Oe(e.data,t.scales,t.getX,t.getY,o,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),n.push(r)}return Ke(t,o,n),n}(i,e);case"area":return function(t,e){const o=t.groupData(e),n=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=Xe(t.ribbons);if(r.length>0&&n.push(...He(t,e,r)),i.length>0)for(const e of o)n.push(...Ve(t,e.data,e.key,i))}const i=t.scales.y.domain()[0],r=t.getY0?e=>{const o=t.getY0(e);return null==o?i:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),s=Fe(e.data,t.scales,t.getX,t.getY,i,o,e.key,r),a=Je(t.config.gradientFill);a&&(s.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(s.curve=t.config.curve),t.config.lineGradient&&(s.strokeGradient=t.config.lineGradient),n.push(s)}return Ke(t,o,n),n}(i,e);case"mixed":return function(t,e){const o=t.groupData(e),n=[],i=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=Xe(t.ribbons);if(r.length>0&&n.push(...He(t,e,r)),i.length>0)for(const e of o)n.push(...Ve(t,e.data,e.key,i))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o)if(i.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),i=Fe(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=Je(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),n.push(i)}else{const o=t.resolveLineStyle(e.key,e.data[0]),i=Oe(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}return Ke(t,o,n),n}(i,e);case"stackedarea":return function(t,e){const o=t.groupData(e),n=t.config.stackOrder??"key",i=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===n);else if("key"===n)i();else if("asc"===n||"desc"===n||"insideOut"===n){const e=new Map;for(const n of o){let o=0;for(const e of n.data){const n=t.getX(e),i=t.getY(e);Number.isFinite(n)&&Number.isFinite(i)&&(o+=i)}e.set(n.key,o)}const i=(t,e)=>e>t?-1:t>e?1:0;if("asc"===n)o.sort((t,o)=>{const n=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==n?n:i(t.key,o.key)});else if("desc"===n)o.sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)}),n=[],r=[];let s=0,a=0;for(const o of t)a>s?(n.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...n)}}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:c}=function(t,e,o,n,i,r,s,a="zero"){const c=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&c.add(e)}const l=Array.from(c).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const i of e.data){const e=o(i),r=n(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 l){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=Be(l,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,b=new Map;for(const t of l)g.set(t,h.get(t)??0),m.set(t,0),b.set(t,0);for(const o of t){const t=u.get(o.key),n=new Map;let a=[],c=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:c,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),p.push(t)}a=[],c=[]};for(const o of l){const i=t.has(o);let s,l,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(o),l=s+u,m.set(o,l)):(s=b.get(o),l=s+u,b.set(o,l)):(s=g.get(o),l=s+u,g.set(o,l));const p=e.x(o);c.push([p,e.y(s)]),a.push([p,e.y(l)]),n.set(o,l)}h(),y.set(o.key,n)}return{nodes:p,stackedTops:y}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),l=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=c.get(n.key);if(o)for(const i of n.data){const n=t.getX(i),r=t.getY(i);null==n||Number.isNaN(n)||null==r||Number.isNaN(r)||!o.has(n)||e.set(i,o.get(n))}}const n=o=>e.get(o)??t.getY(o);Ke(t,o,l,n)}return l}(i,e);case"scatter":case"bubble":return function(t,e){const o=[],n="bubble"===t.config.chartType?10:5,i=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const o=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(o.length>0){let t=1/0,e=-1/0;for(const n of o)t>n&&(t=n),n>e&&(e=n);r=o=>t===e?(i[0]+i[1])/2:i[0]+(o-t)/(e-t)*(i[1]-i[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",c=t.getSymbol,l=t.config.symbolMap,u=new Map;let d=0;const h=t=>{const e=l?.[t];if(e)return e;let o=u.get(t);return o||(o=lo[d%lo.length],d++,u.set(t,o)),o};for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(i);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(c){const n=h(c(i)+""),r=We(i,t.scales,t.getX,t.getY,Math.PI*l*l,n,e,u);r&&o.push(r)}else{const n=Ne(i,t.scales,t.getX,t.getY,l,e,u);n&&o.push(n)}}return o}(i,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(t,e,o){const n=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=h(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,c]=t.scales.x.domain(),[l,u]=t.scales.y.domain(),d=(c-a||1)/n,f=(u-l||1)/i,p=n*i;if(p>1e6)return[];const y=new Int32Array(p),g=new Float64Array(p);for(let o=0;e.length>o;o++){const r=e[o],c=t.getX(r),u=t.getY(r);if(!isFinite(c)||!isFinite(u))continue;const h=Math.min(Math.floor((c-a)/d),n-1),p=Math.min(Math.floor((u-l)/f),i-1);if(0>h||0>p)continue;const m=p*n+h;y[m]++;const b=s(r);g[m]+=isFinite(b)?b:0}let m=1/0,b=-1/0;for(let t=0;p>t;t++){if(0===y[t])continue;let e;switch(r){case"sum":e=g[t];break;case"mean":e=g[t]/y[t];break;default:e=y[t]}m>e&&(m=e),e>b&&(b=e)}if(!isFinite(m))return[];const x=b-m||1,v=o.width/n,w=o.height/i,k=t.config.showValues,A=t.config.heatmapValueFormat,S=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===y[n])continue;let c;switch(r){case"sum":c=g[n];break;case"mean":c=g[n]/y[n];break;default:c=y[n]}const u=(c-m)/x,h={xi:s,yi:e,value:c,count:y[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:l+(e+.5)*f,agg:r};S.push(po(Ye(s*v,(i-1-e)*w,v,w,`rgb(${220-(180*u+.5)|0},${220-(100*u+.5)|0},${255-(50*u+.5)|0})`,h,k?{value:c,showValues:!0,valueFormat:A}:void 0),h,t))}}return S}(t,e,o);if(0===e.length)return[];const n=h(t.config.valueAccessor,"value"),i=f(t.config.xAccessor,"x"),r=f(t.config.yAccessor,"y"),s=new Map,a=new Map,c=Array(e.length),l=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);c[t]=n,l[t]=u,s.has(n)||s.set(n,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const p=Array.from(s.keys()),y=Array.from(a.keys()),g=p.every(t=>"number"==typeof t&&!isNaN(t)),m=y.every(t=>"number"==typeof t&&!isNaN(t));if(g){p.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;p.length>t;t++)s.set(p[t],t)}if(m){y.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;y.length>t;t++)a.set(y[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 o=e[t],i=s.get(c[t]),r=a.get(l[t]);if(void 0===i||void 0===r)continue;const d=n(o),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]=o}let A=1/0,S=-1/0;for(let t=0;k>t;t++){const e=x[t];isFinite(e)&&(A>e&&(A=e),e>S&&(S=e))}if(!isFinite(A)||!isFinite(S))return[];const M=function(t){const e=t in dt?t:"blues";let o=fo.get(e);if(o)return o;o=Array(256);const n=ht(e);for(let t=0;256>t;t++)o[t]=n(t/255);return fo.set(e,o),o}("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),_=255/(S-A||1),P=o.width/u,C=o.height/d,R=t.config.showValues,I=t.config.heatmapValueFormat,L=[];for(let e=0;k>e;e++){const o=x[e];if(!isFinite(o))continue;const n=b[e],i=n%u,r=v[e];L.push(po(Ye(i*P,(d-1-(n-i)/u)*C,P,C,M[Math.min((o-A)*_+.5|0,255)],r,R?{value:o,showValues:!0,valueFormat:I}:void 0),r,t))}return L}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=yo(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===o.size)return{nodes:[],binBoundaries:[]};let n=null;if(t.getCategory){const e=new Set;for(const t of o.values())for(const o of t.categories.keys())e.add(o);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)),c=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===c?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:c,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),c=t.config.barStyle,l=t.config.themeSemantic?.primary,u=c?.gap,d="number"!=typeof u||0>u?1:u,h={};c?.stroke&&(h.stroke=c.stroke),"number"==typeof c?.strokeWidth&&(h.strokeWidth=c.strokeWidth),"number"==typeof c?.opacity&&(h.opacity=c.opacity);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const f=r.x(o),p=r.x(u),y=Math.abs(p-f),g=y>d+1?d:0,m=Math.min(f,p)+g/2,b=Math.max(y-g,1);if(b>0)if(n&&e.categories.size>0){let o=0;for(const s of n){const n=e.categories.get(s)||0;if(0===n)continue;const a=r.y(o),u=r.y(o+n);i.push(je(m,Math.min(a,u),b,Math.abs(a-u),{fill:t.config.barColors?.[s]||c?.fill||l||"#4e79a7",...h},{binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},s)),o+=n}}else{const t=r.y(0),o=r.y(e.total);i.push(je(m,Math.min(t,o),b,Math.abs(t-o),{fill:c?.fill||l||"#007bff",...h},{binStart:e.start,binEnd:e.end,total:e.total}))}}const f=new Set;for(const t of o.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 o=[],n=t.config.swarmStyle||{},i=n.radius??3,r=n.fill??t.config.themeSemantic?.primary??"#007bff",s=n.opacity??.7,a=n.stroke,c=n.strokeWidth;for(const n of e){const e=t.getX(n),l=t.getY(n);if(null==l||Number.isNaN(l))continue;const u=t.scales.x(e),d=t.scales.y(l);let h=r;if(t.getCategory){const e=t.getCategory(n);h=t.config.barColors?.[e]||h}const{r:f,...p}=t.config.pointStyle?.(n)??{},y={type:"point",x:u,y:d,r:f??i,style:{fill:h,opacity:s,stroke:a,strokeWidth:c,...p},datum:n};t.getPointId&&(y.pointId=t.getPointId(n)+""),o.push(y)}return o}(i,e);case"waterfall":return function(t,e,o){const n=[],i=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),n=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=n&&isFinite(n)});if(0===s.length)return n;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",c=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",l=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],y=t.getX(p),g=t.getY(p),m=f+g;let b;b=s.length-1>e?t.getX(s[e+1])-y:e>0?y-t.getX(s[e-1]):0;const x=i.x(y),v=0!==b?i.x(y+b):x+o.width/10,w=Math.min(x,v)+l/2,k=Math.max(x,v)-l/2-w;if(0>=k){f=m;continue}const A=i.y(f),S=i.y(m),M=Math.min(A,S),_=Math.abs(A-S),P={fill:0>g?c:a,stroke:u,strokeWidth:d};null!=h&&(P.opacity=h),n.push(je(w,M,k,_,P,{...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth})),f=m}return n}(i,e,t);case"candlestick":return function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const n=t.config.candlestickRangeMode??!1;if(!(n||t.getOpen&&t.getClose))return[];const i=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=n?s:r.upColor||"#28a745",c=n?s:r.downColor||"#dc3545",l=n?s:r.wickColor||"#333",u=r.wickWidth||(n?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 o=1;d.length>o;o++){const n=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));n>0&&e>n&&(e=n)}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=n?s:t.getOpen(r),p=n?d:t.getClose(r);if(!n&&[f,p].some(t=>null==t||Number.isNaN(t)))continue;const y=p>=f,g={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:c,wickColor:l,wickWidth:u,isUp:y,datum:r};n&&(g.isRange=!0,g.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(g)}return i}(i,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,n){const i=t.boundsStyle;return"function"==typeof i?i(o||{},e):i&&"object"==typeof i?i:{fill:n(e,o).stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none"}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Le(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=Te(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=Te(o)){const i=o.length;if(i>1)for(const o of e){if("line"===o.type){const e=Array.isArray(o.datum)?o.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let o=0;e.length>o;o++){const a=n.get(e[o]);null!=a?(r[o]=Le(t,a,i),1>r[o]&&(s=!0)):r[o]=1}s&&(o._decayOpacities=r);continue}if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[],r=o.topPath?o.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let o=0;e.length>o;o++){const r=n.get(e[o]);null!=r?(s[o]=Le(t,r,i),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=n.get(o);if(null!=e){const o=Le(t,e,i);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=n.get(o.datum);if(null==e)continue;const r=Le(t,e,i);"heatcell"===o.type?o.style={opacity:r}:"candlestick"===o.type?o._decayOpacity=r:o.style={...o.style,opacity:(o.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&&De(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,o,n){o.clear(),n.clear();for(let i=0;e.length>i;i++){const r=e[i],s=Ee(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:r.style.opacity}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:r.style.opacity,glyph:r.glyph}):"rect"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style.opacity}):"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style?.opacity}):"candlestick"===r.type?o.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:r.style?.opacity}):"line"===r.type?n.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&n.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 o=this.scene[e],n=Ee(this.transitionContext,o,e);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(n,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(n,{topPath:o.topPath.map(t=>[t[0],t[1]]),bottomPath:o.bottomPath.map(t=>[t[0],t[1]]),opacity:o.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,o,n,i,r=Ie()){if(0===n.size&&0===i.size)return o;const s=e.duration??300;if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}let a=!1;const c=new Set,l=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=Ee(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(l.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=n.get(s);if("point"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=r.style.opacity??1,u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=r.style?.opacity??1,u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=r.style?.opacity??1,r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){c.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=r.style?.opacity??1,(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=r.style?.opacity??1,r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!l.has(t))if(t.startsWith("l:")&&e.path){const n={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};o.exitNodes.push(n),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const n={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};o.exitNodes.push(n),a=!0}for(const[t,e]of n)if(!c.has(t)){if(t.startsWith("p:"))o.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)o.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:"))o.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:"))o.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 n=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:n,closeY:e.closeY??n,highY:e.highY??n,lowY:e.lowY??n,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 o.exitNodes.length>0&&(o.scene=[...o.scene,...o.exitNodes]),a&&(o.activeTransition={startTime:r,duration:s}),o}(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},o=function(t,e,o,n){if(!o.activeTransition)return!1;const i=Ce(t,o.activeTransition),r=Pe(i,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of o.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Re(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Re(o.x,t._targetX,r),t.y=Re(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Re(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Re(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Re(o.x,t._targetX,r),t.y=Re(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Re(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Re(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Re(o.x,t._targetX,r),t.y=Re(o.y,t._targetY,r),void 0!==o.w&&(t.w=Re(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Re(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Re(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Re(o.x,t._targetX,r),t.y=Re(o.y,t._targetY,r),void 0!==o.w&&(t.w=Re(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Re(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Re(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Re(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Re(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Re(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Re(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Re(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Re(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,o=t._targetPath;if(e&&o&&e.length===t.path.length)for(let n=0;t.path.length>n;n++)t.path[n][0]=Re(e[n][0],o[n][0],r),t.path[n][1]=Re(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Re(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,n=t._targetTopPath,i=t._targetBottomPath;if(e&&n&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=Re(e[o][0],n[o][0],r),t.topPath[o][1]=Re(e[o][1],n[o][1],r);if(o&&i&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Re(o[e][0],i[e][0],r),t.bottomPath[e][1]=Re(o[e][1],i[e][1],r)}}if(i>=1){for(const t of o.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 o=0;t.path.length>o;o++)t.path[o]=e[o];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,o=t._targetBottomPath;if(e)for(let o=0;t.topPath.length>o;o++)t.topPath[o]=e[o];if(o)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=o[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}return o.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,o}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null;for(const t of this.scene)"line"!==t.type&&"area"!==t.type||(t._introClipFraction=void 0)}groupData(t){const{result:e,cache:o}=function(t,e,o,n){if(n&&n.version===o&&n.group===e&&n.data===t)return{result:n.result,cache:n};let i;if(e){const o=new Map;for(const n of t){const t=e(n);o.has(t)||o.set(t,[]),o.get(t).push(n)}i=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else i=[{key:"_default",data:t}];return{result:i,cache:{version:o,group:e,data:t,result:i}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,n,i){if(i&&i.version===n)return{map:i.map,cache:i};const r=new Set;if(e)for(const o of t){const t=e(o);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const t={...i,version:n};return{map:t.map,cache:t}}const c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||St,l=new Map;for(let t=0;s.length>t;t++)l.set(s[t],c[t%c.length]);return{map:l,cache:{key:a,map:l,version:n}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,n){const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.stroke&&e){const o=n(e);if(o)return{...t,stroke:o}}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:n(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,n){if(t.areaStyle){const i=t.areaStyle(o||{});if(i&&!i.fill&&e){const t=n(e);if(t)return{...i,fill:t,stroke:i.stroke||t}}return i}const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.fill&&e){const o=n(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}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=n(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(t){const{color:o,groupColorCounter:n}=function(t){const{group:e,colorMapCache:o,groupColorMap:n,groupColorMapCap:i,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=n.get(e);if(a)return{color:a,groupColorCounter:s};const c=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||St;if(0===c.length)return{color:null,groupColorCounter:s};const l=c[s%c.length];if(s++,n.set(e,l),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:l,groupColorCounter:s}}({group:t,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:e.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=n,o}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=_e(t),o=this.getPointId,n=t=>e.has(o(t));Lo(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);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 o=_e(t),n=this.getPointId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(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 o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.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 o={...this.config},n=Object.keys(e).filter(t=>e[t]!==o[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==o.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${o.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!==o.chartType||"runtimeMode"in e&&e.runtimeMode!==o.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,n=e&&this.config.valueAccessor||this.config.yAccessor,a=e&&o.valueAccessor||o.yAccessor,c=s||!t(e&&this.config.timeAccessor||this.config.xAccessor,e&&o.timeAccessor||o.xAccessor),l=s||!t(n,a);(c||l)&&(e?(this.getX=h(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=h(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=h(this.config.xAccessor,"x"),this.getY=h(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=wo(this.config)),i=!0,r=!0)}if("groupAccessor"in e&&!t(e.groupAccessor,o.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?y(this.config.groupAccessor):void 0,i=!0),"categoryAccessor"in e&&!t(e.categoryAccessor,o.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?y(this.config.categoryAccessor):void 0,i=!0),"sizeAccessor"in e&&!t(e.sizeAccessor,o.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?h(this.config.sizeAccessor,"size"):void 0,i=!0),"symbolAccessor"in e&&!t(e.symbolAccessor,o.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?y(this.config.symbolAccessor):void 0,i=!0),"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?y(this.config.colorAccessor):void 0,i=!0),"y0Accessor"in e&&!t(e.y0Accessor,o.y0Accessor)&&(this.getY0=this.config.y0Accessor?h(this.config.y0Accessor,"y0"):void 0,i=!0,r=!0),("boundsAccessor"in e&&!t(e.boundsAccessor,o.boundsAccessor)||"band"in e&&e.band!==o.band||"boundsStyle"in e&&e.boundsStyle!==o.boundsStyle)&&(this.resolvedRibbons=wo(this.config),i=!0,r=!0),"pointIdAccessor"in e&&!t(e.pointIdAccessor,o.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?y(this.config.pointIdAccessor):void 0,i=!0),"candlestick"===this.config.chartType&&(s||"openAccessor"in e&&!t(e.openAccessor,o.openAccessor)||"closeAccessor"in e&&!t(e.closeAccessor,o.closeAccessor)||"highAccessor"in e&&!t(e.highAccessor,o.highAccessor)||"lowAccessor"in e&&!t(e.lowAccessor,o.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?h(this.config.openAccessor,"open"):void 0,this.getHigh=h(this.config.highAccessor,"high"),this.getLow=h(this.config.lowAccessor,"low"),this.getClose=e?h(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,i=!0,r=!0}if("accessorRevision"in e&&e.accessorRevision!==o.accessorRevision&&(i=!0,r=!0),!i){const t=Object.keys(e).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const n of t)if(e[n]!==o[n]){i=!0;break}}i&&(r&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(n)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};sn.GROUP_COLOR_MAP_CAP=1e3;var an=sn;Bo(an);import{memo as cn,useEffect as ln,useRef as un}from"react";var dn={sceneGeometry:0,layout:0,domain:0};function hn(t){const{domain:e,layout:o,sceneGeometry:n}=t.revisions;return{domain:e,layout:o,sceneGeometry:n}}function fn(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 pn="production"!==process.env.NODE_ENV,yn={revisions:dn,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},gn=class{constructor(t="scene host"){this.hostName=t,this.lastConsumed=dn,this.lastObserved=dn,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(t){pn&&(this.lastObserved=fn(this.lastObserved,hn(t)))}beforeCompute(t,e){if(!pn)return yn;const o=fn(hn(t),this.lastObserved),n=function(t){return`${t.sceneGeometry}|${t.layout}|${t.domain}`}(o),i=!((r=o).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:o,signature:n,sawSignals:t.changed.has("scene-geometry")||t.changed.has("layout")||t.changed.has("domain"),wasUnconsumed:i,warnUnconsumed:!e&&i&&this.lastUnconsumedWarning!==n}}afterCompute(t,e,o){if(pn){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&&!o&&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="")}}},mn=cn(function({store:t,diagnostics:e}){return ln(()=>{const o=()=>e.observeUpdateResult(t.getUpdateSnapshot());return o(),t.subscribeUpdateResult(o)},[e,t]),null});import*as bn from"react";function xn(...t){const e=t.filter(t=>null!=t);return 0===e.length?null:1===e.length?e[0]:bn.createElement(bn.Fragment,null,...e)}import*as vn from"react";import{jsx as wn}from"react/jsx-runtime";var kn=vn.createContext(null);function An({value:t,children:e}){return wn(kn.Provider,{value:t,children:e})}function Sn(t,e){return null!=t?wn(An,{value:e,children:t}):t}import{useEffect as Mn,useRef as _n}from"react";function Pn(t,e,o){return o.x>t||t>o.x+o.w||o.y>e||e>o.y+o.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:o.x+o.w/2,cy:o.y+o.h/2}}function Cn(t,e=30){return Math.max((t??4)+5,12,e)}function Rn(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function In(t,e){const o=Rn(t);if(!o)return!1;const n=Rn(e);return!n||o.getFullYear()!==n.getFullYear()||o.getMonth()!==n.getMonth()}var Ln=[40,40],Tn=[.5,.5];function $n(t,e){const[o,n]=t.viewBox??Ln,[i,r]=t.anchor??Tn,s=n>0?n:1,a=Math.max(0,e)/s,c=(o>0?o:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-i*c,offsetY:-r*l}}function zn(t,e,o,n){if("none"!==t)return"color"===t||null==t?e??n:"accent"===t?o:t}var Dn=null;function En(t){if("undefined"==typeof Path2D)return null;Dn||(Dn=new Map);const e=Dn.get(t);if(e)return e;const o=new Path2D(t);return Dn.size>1024&&Dn.clear(),Dn.set(t,o),o}function On(t,e,o=0,n="horizontal"){const[i,r]=t.viewBox??Ln,s=Math.min(1,Math.max(0,o)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===n?{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 Fn(t,e){const o=$n(t,e);return{centerDx:o.offsetX+o.width/2,centerDy:o.offsetY+o.height/2,halfWidth:o.width/2,halfHeight:o.height/2,radius:Math.hypot(o.width,o.height)/2}}function Bn(t,e,o,n,i,r=t=>t){for(const s of e.parts){const e=En(s.d);if(!e)continue;const a=s.opacity??1,c=t.globalAlpha;1!==a&&(t.globalAlpha=c*a);const l=i?"none"===s.fill?void 0:i:zn(s.fill,o,n);l&&(t.fillStyle=r(l),t.fill(e));const u=i?s.stroke&&"none"!==s.stroke?i:void 0:zn(s.stroke??"none",o,n);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=c)}}var Nn=new WeakMap,Wn=0,jn=!1,Yn=null,Gn=null;function qn(t,e){if(!e)return e;const o=function(t){const e=t.trim();if(!e.startsWith("var(")||!e.endsWith(")"))return null;const o=e.slice(4,-1),n=o.indexOf(",");if(-1===n){const t=o.trim();return t.startsWith("--")?{name:t}:null}const i=o.slice(0,n).trim(),r=o.slice(n+1).trim();return i.startsWith("--")?{name:i,fallback:r||void 0}:null}(e);if(!o)return e;const n=()=>o.fallback?qn(t,o.fallback):e,i=t.canvas;if(!i)return n();!function(){if(jn)return;if("undefined"==typeof window||"undefined"==typeof document)return;jn=!0;const t=()=>{Wn++};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{Yn=window.matchMedia("(prefers-color-scheme: dark)"),Gn=t,"function"==typeof Yn.addEventListener?Yn.addEventListener("change",Gn):"function"==typeof Yn.addListener&&Yn.addListener(Gn)}catch{}}();let r=Nn.get(i);r&&r.version===Wn||(r={version:Wn,map:new Map},Nn.set(i,r));const s=r.map.get(e);if(void 0!==s)return s;const a=getComputedStyle(i).getPropertyValue(o.name).trim()||n()||e;return r.map.set(e,a),a}function Xn(t){return{type:"hatch",background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle}}var Hn=null;import{jsx as Vn,jsxs as Un}from"react/jsx-runtime";function Kn(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function Zn(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}var Qn=new Map;function Jn(t,e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,c=Math.max(8,Math.ceil(2*r));return Un("pattern",{id:e,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Vn("rect",{width:c,height:c,fill:o}),Vn("line",{x1:0,y1:0,x2:0,y2:c,stroke:n,strokeWidth:i,strokeOpacity:a}),Vn("line",{x1:r,y1:0,x2:r,y2:c,stroke:n,strokeWidth:i,strokeOpacity:a})]},e)}function ti(t,e,o="#4e79a7"){if(Kn(t)){const o=function(t,e){let o=2166136261;const n=Zn(e);for(let t=0;n.length>t;t++)o^=n.charCodeAt(t),o=Math.imul(o,16777619);return`${t}-hatch-${(o>>>0).toString(36)}`}(e,t);return{fill:`url(#${o})`,def:Jn(t,o)}}return t&&"string"==typeof t?{fill:t}:{fill:o}}import{curveMonotoneX as ei,curveMonotoneY as oi,curveCardinal as ni,curveCatmullRom as ii,curveStep as ri,curveStepBefore as si,curveStepAfter as ai,curveBasis as ci,curveNatural as li}from"d3-shape";function ui(t){switch(t){case"monotoneX":return ei;case"monotoneY":return oi;case"cardinal":return ni;case"catmullRom":return ii;case"step":return ri;case"stepBefore":return si;case"stepAfter":return ai;case"basis":return ci;case"natural":return li;default:return null}}function di(t,e,o){if(null==e)return o;if(Kn(e)){const n=function(t,e){const o="undefined"!=typeof window&&window.devicePixelRatio||1,n=`${Zn(t)}@${o}`,i=Qn.get(n);if(void 0!==i)return i;const r=function(t={},e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a={background:o,stroke:n,lineWidth:i,spacing:r,angle:s},c=Math.max(8,Math.ceil(2*r));let l;try{l=function(t){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(t,t):(Hn||(Hn=document.createElement("canvas")),Hn.width=t,Hn.height=t,Hn)}(c)}catch{return Xn(a)}const u=l.getContext("2d");if(!u)return Xn(a);o&&"transparent"!==o?(u.fillStyle=o,u.fillRect(0,0,c,c)):u.clearRect(0,0,c,c),u.strokeStyle=n,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=-c;2*c>=e;e+=r)u.beginPath(),u.moveTo(e,0),u.lineTo(e+t*c,c),u.stroke()}else{u.save(),u.translate(c/2,c/2),u.rotate(d);const t=2*c;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(l,"repeat")}({background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle},e),s=Kn(r)?null:r;return Qn.set(n,s),s}(e,t);return n||e.background&&qn(t,e.background)||o}return"string"!=typeof e?e:qn(t,e)||o}function hi(t,e,o,n,i,r,s){if("colorStops"in e){const o=e.colorStops.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color}));if(2>o.length)return null;const a=t.createLinearGradient(n,i,r,s);for(const t of o)a.addColorStop(t.offset,t.color);return a}const{topOpacity:a,bottomOpacity:c}=e;if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l=Math.max(0,Math.min(1,a)),u=Math.max(0,Math.min(1,c)),d=t.createLinearGradient(n,i,r,s),[h,f,p]=function(t,e){const o=t.fillStyle,n="#010203";try{t.fillStyle=n,t.fillStyle=e}catch{return t.fillStyle=o,[78,121,167]}const i=t.fillStyle;if(t.fillStyle=o,"string"!=typeof i)return[78,121,167];if(i.toLowerCase()===n&&e.trim().toLowerCase()!==n)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,o);return d.addColorStop(0,`rgba(${h},${f},${p},${l})`),d.addColorStop(1,`rgba(${h},${f},${p},${u})`),d}function fi(t,e,o,n,i,r){const s=e.colorStops.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color}));if(2>s.length)return null;const a=t.createLinearGradient(o,n,i,r);for(const t of s)a.addColorStop(t.offset,t.color);return a}import{line as pi}from"d3-shape";var yi=new WeakMap;function gi(t,e){const o=ui(e);if(!o)return t;const n=yi.get(t);if(n)return n;const i=function(t,e,o=8){if(!e||2>t.length)return t.map(([t,e])=>[t,e]);const n=[];let i=null;const r={moveTo(t,e){i=[t,e],n.push([t,e])},lineTo(t,e){i=[t,e],n.push([t,e])},bezierCurveTo(t,e,r,s,a,c){if(!i)return i=[a,c],void n.push([a,c]);const[l,u]=i;for(let i=1;o>=i;i++){const d=i/o,h=1-d;n.push([h*h*h*l+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*c])}i=[a,c]},closePath(){},arc(){},rect(){},arcTo(){},quadraticCurveTo(t,e,o,r){i=[o,r],n.push([o,r])}};return pi().x(t=>t[0]).y(t=>t[1]).curve(e).context(r)(t),n}(t,o);return yi.set(t,i),i}function mi(t,e,o,n=30,i,r=0){let s=null;if(i){const t=function(t,e,o,n,i,r=t=>t.x,s=t=>t.y,a=t=>t.r){const c=Math.max(n,i+5,12),l=e-c,u=e+c,d=o-c,h=o+c;let f=null,p=1/0;return t.visit((t,i,c,y,g)=>{if(i>u||l>y||c>h||d>g)return!0;if(!t.length){let i=t;do{const t=i.data,c=r(t)-e,l=s(t)-o,u=Math.sqrt(c*c+l*l);Cn(a(t),n)>=u&&p>u&&(f=t,p=u),i=i.next}while(i)}return!1}),f?{node:f,distance:p}:null}(i,e,o,n,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=xi(r,e,o,n);break;case"symbol":t=vi(r,e,o,n);break;case"glyph":t=wi(r,e,o,n);break;case"line":t=ki(r,e,o,n);break;case"rect":if(null==r.datum)break;t=Si(r,e,o);break;case"heatcell":t=Mi(r,e,o);break;case"area":if(!1===r.interactive)break;t=Pi(r,e,o);break;case"candlestick":t=_i(r,e,o)}t&&n>t.distance&&(s&&t.distance>=s.distance||(s=t))}return s}function bi(t,e,o){if(0===t.length)return null;if(t[0][0]>e||e>t[t.length-1][0])return null;const n=Ci(t,e);if(0>n)return null;if(Math.abs(t[n][0]-e)>o)return null;let i=n,r=n;n>0&&t[n][0]>=e?(i=n-1,r=n):t.length-1>n&&(i=n,r=n+1);const[s,a]=t[i],[c,l]=t[r];return c===s?a:a+Math.max(0,Math.min(1,(e-s)/(c-s)))*(l-a)}function xi(t,e,o,n=30){const i=e-t.x,r=o-t.y,s=Math.sqrt(i*i+r*r);return s>Cn(t.r,n)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function vi(t,e,o,n=30){const i=e-t.x,r=o-t.y,s=Math.sqrt(i*i+r*r);return s>Cn(ho(t.size),n)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function wi(t,e,o,n=30){if(null==t.datum)return null;const i=Fn(t.glyph,t.size),r=t.x+i.centerDx,s=t.y+i.centerDy,a=e-r,c=o-s,l=Math.sqrt(a*a+c*c);return l>Cn(i.radius,n)?null:{node:t,datum:t.datum,x:r,y:s,distance:l}}function ki(t,e,o,n=30){if(0===t.path.length)return null;const i=Ci(t.path,e);if(0>i)return null;const[r,s]=t.path[i];let a;if(t.path.length>1){let n=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,c]=t.path[i+1],l=Ai(e,o,r,s,a,c);n>l&&(n=l)}a=n}else{const t=e-r,n=o-s;a=Math.sqrt(t*t+n*n)}const c=t.style;return a>Math.max(5,(c.strokeWidth??c.lineWidth??1)/2+2,n)?null:{node:t,datum:Array.isArray(t.datum)&&t.datum[i]?t.datum[i]:t.datum,x:r,y:s,distance:a}}function Ai(t,e,o,n,i,r){const s=i-o,a=r-n,c=s*s+a*a;if(0===c)return Math.sqrt((t-o)**2+(e-n)**2);let l=((t-o)*s+(e-n)*a)/c;return l=Math.max(0,Math.min(1,l)),Math.sqrt((t-(o+l*s))**2+(e-(n+l*a))**2)}function Si(t,e,o){const n=Pn(e,o,t);return n.hit?{node:t,datum:t.datum,x:n.cx,y:n.cy,distance:0}:null}function Mi(t,e,o){const n=Pn(e,o,t);return n.hit?{node:t,datum:t.datum,x:n.cx,y:n.cy,distance:0}:null}function _i(t,e,o){const n=t.bodyWidth/2,i=Math.min(t.openY,t.closeY);if(!(t.x-n-3>e||e>t.x+n+3||t.highY-3>o||o>t.lowY+3)){const n=i+Math.max(Math.max(t.openY,t.closeY)-i,1)/2,r=e-t.x,s=o-n;return{node:t,datum:t.datum,x:t.x,y:n,distance:Math.sqrt(r*r+s*s)}}return null}function Pi(t,e,o){if(0===t.topPath.length)return null;const n=Ci(t.topPath,e);if(0>n)return null;const[i,r]=t.topPath[n],s=e-i,a=o-r,c=Math.sqrt(s*s+a*a);return{node:t,datum:Array.isArray(t.datum)&&t.datum[n]?t.datum[n]:t.datum,x:i,y:r,distance:c}}function Ci(t,e){if(0===t.length)return-1;let o=0,n=t.length-1;for(;n>o;){const i=o+n>>1;e>t[i][0]?o=i+1:n=i}return o>0&&Math.abs(t[o][0]-e)>=Math.abs(t[o-1][0]-e)?o-1:o}import{useEffect as Ri,useRef as Ii}from"react";var Li={fresh:1,aging:.7,stale:.45,expired:.25},Ti={alpha:1,band:"fresh",isStale:!1};function $i(t,e){if(!t||0>=e)return Ti;const o=null!=t.threshold&&t.threshold>0?t.threshold:5e3,n=t.graded;if(n){const t="object"==typeof n?n:{},r=i(e,o,t.thresholds);return{alpha:{...Li,...t.opacities??{}}[r],band:r,isStale:"fresh"!==r}}return e>o?{alpha:t.dimOpacity??.5,band:"stale",isStale:!0}:Ti}import{jsx as zi}from"react/jsx-runtime";function Di({isStale:t,position:e}){return zi("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 Ei,useRef as Oi,useEffect as Fi}from"react";import*as Bi from"react";function Ni(t){const e=Math.max(1,t?.swatchSize??16),o=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function Wi(t,e){let o=24;return t.map(({hasLabel:t,itemCount:n})=>{o+=5;const i=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=n*e+8,{lineY:i,labelY:r,itemsY:s,endY:o}})}import{jsx as ji,jsxs as Yi}from"react/jsx-runtime";var Gi={fill:(t,e)=>ji("rect",{style:t,width:e,height:e}),line:(t,e)=>ji("line",{style:t,x1:0,y1:0,x2:e,y2:e})};function qi(t,e,o,n,i){let r;return r="function"==typeof o?o(t):(0,Gi[o])(n(t,e),i),r}function Xi({swatchSize:t}){return ji("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 Hi(t,e,o){return o&&o.size>0?o.has(t.label)?1:.3:null!=e?t.label===e?1:.3:1}var Vi=(t,e,o,n,i,r,s,a,c,l,u)=>{const{type:d="fill",styleFn:h,items:f}=t,p=[];let y=0;const g=!(!e&&!o),m="isolate"===l||void 0===l&&null!=i,{swatchSize:b,labelGap:x,rowHeight:v}=u;return f.forEach((t,l)=>{const u=qi(t,l,d,h,b),w=Hi(t,n,i),k=i&&i.size>0&&i.has(t.label);p.push(Yi("g",{transform:`translate(0,${y})`,onClick:e?()=>e(t):void 0,onMouseEnter:o?()=>o(t):void 0,onMouseLeave:o?()=>o(null):void 0,tabIndex:g?a===r&&l===s?0:-1:void 0,role:g?"option":void 0,"aria-selected":g&&m?k||!1:void 0,"aria-current":g&&!m&&null!=n&&t.label===n||void 0,"aria-label":t.label,onKeyDown:g?o=>{if("Enter"!==o.key&&" "!==o.key||(o.preventDefault(),e&&e(t)),"ArrowDown"===o.key||"ArrowUp"===o.key){o.preventDefault();const t=(l+("ArrowDown"===o.key?1:-1)+f.length)%f.length;c(a,t);const e=o.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:g?e=>{c(a,l),o&&o(t);const n=e.currentTarget.querySelector(".semiotic-legend-focus-ring");n&&n.setAttribute("visibility","visible")}:void 0,onBlur:g?t=>{o&&o(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:g?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[g&&ji("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&&ji(Xi,{swatchSize:b}),ji("text",{y:b/2,x:b+x,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+l)),y+=v}),p};function Ui({config:t,orientation:e="vertical",width:o=100}){const{colorFn:n,domain:i,label:r,format:s}=t,a=s||(t=>Math.round(100*t)/100+""),c="grad-legend-"+Bi.useId();if("horizontal"===e){const t=12,e=Math.min(o,200),s=Math.max(0,(o-e)/2),l=[];for(let t=0;64>=t;t++){const e=t/64;l.push(ji("stop",{offset:100*e+"%",stopColor:n(i[0]+e*(i[1]-i[0]))},t))}return Yi("g",{"aria-label":r||"Gradient legend",children:[ji("defs",{children:ji("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),r&&ji("text",{x:s+e/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),ji("rect",{x:s,y:0,width:e,height:t,fill:`url(#${c})`,rx:2}),ji("text",{x:s,y:t+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])}),ji("text",{x:s+e,y:t+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])})]})}const l=[];for(let t=0;64>=t;t++){const e=t/64;l.push(ji("stop",{offset:100*e+"%",stopColor:n(i[1]-e*(i[1]-i[0]))},t))}return Yi("g",{"aria-label":r||"Gradient legend",children:[r&&ji("text",{x:7,y:-6,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),ji("defs",{children:ji("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),ji("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),ji("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])}),ji("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])})]})}function Ki(t){const{legendGroups:e,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:c=100,height:l=20,orientation:u="vertical",legendLayout:d}=t,h=Ni(d),[f,p]=Bi.useState(0),[y,g]=Bi.useState(0),m=Bi.useCallback((t,e)=>{p(t),g(e)},[]),b="vertical"===u?(({legendGroups:t,width:e,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:c,legendInteraction:l,metrics:u})=>{const d=[],h=Wi(t.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),u.rowHeight);return t.forEach((t,f)=>{const p=h[f];d.push(ji("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(ji("text",{y:p.labelY,className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label},"legend-text-"+f)),d.push(ji("g",{className:"legend-item",transform:`translate(0,${p.itemsY})`,children:Vi(t,o,n,i,r,s,a,f,c,l,u)},"legend-group-"+f))}),d})({legendGroups:e||[],width:c,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:y,onFocusedIndexChange:m,legendInteraction:s,metrics:h}):(({legendGroups:t,height:e,width:o,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:c,onFocusedIndexChange:l,legendInteraction:u,metrics:d})=>{let h=0;const f=[];t.forEach((t,e)=>{let p=0;t.label&&(p+=16);const y=((t,e,o,n,i,r,s,a,c,l,u,d)=>{const{type:h="fill",styleFn:f,items:p}=t,y=[],{swatchSize:g,labelGap:m,itemGap:b,rowHeight:x,align:v}=u,w=!(!e&&!o),k="isolate"===l||void 0===l&&null!=i,A=p.map(t=>g+m+7*t.label.length),S=[];let M=0,_=0;A.forEach((t,e)=>{const o=0===_?t:_+b+t;d&&d>0&&_>0&&o>d?(S.push({start:M,end:e,width:_}),M=e,_=t):_=o}),p.length>0&&S.push({start:M,end:p.length,width:_}),S.forEach((t,l)=>{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=qi(t,d,h,f,g),S=Hi(t,n,i),M=i&&i.size>0&&i.has(t.label);y.push(Yi("g",{transform:`translate(${u},${l*x})`,onClick:e?()=>e(t):void 0,onMouseEnter:o?()=>o(t):void 0,onMouseLeave:o?()=>o(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!=n&&t.label===n||void 0,"aria-label":t.label,onKeyDown:w?o=>{if("Enter"!==o.key&&" "!==o.key||(o.preventDefault(),e&&e(t)),"ArrowRight"===o.key||"ArrowLeft"===o.key){o.preventDefault();const t=(d+("ArrowRight"===o.key?1:-1)+p.length)%p.length;c(a,t);const e=o.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:w?e=>{c(a,d),o&&o(t);const n=e.currentTarget.querySelector(".semiotic-legend-focus-ring");n&&n.setAttribute("visibility","visible")}:void 0,onBlur:w?t=>{o&&o(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:S,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&ji("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:g+m+2+7*t.label.length,height:g+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,M&&ji(Xi,{swatchSize:g}),ji("text",{y:g/2,x:g+m,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+d)),u+=A[d]+b}});const P=Math.max(0,...S.map(t=>t.width)),C=S.length;return{items:y,offset:P,totalRows:C,totalHeight:C*x}})(t,n,i,r,s,a,c,e,l,u,d,d.maxWidth??o);p+=y.offset+5,f.push({label:t.label,...y,offset:p,totalRows:y.totalRows,totalHeight:y.totalHeight}),h+=p+12});const p=d.maxWidth??o;let y=h>p?0:"center"===d.align?Math.max(0,(p-h)/2):"end"===d.align?Math.max(0,p-h):0;const g=[];return f.forEach((o,n)=>{const i=t[n];i.label&&(g.push(ji("text",{transform:`translate(${y},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:i.label},"legend-text-"+n)),y+=16),g.push(ji("g",{className:"legend-item",transform:`translate(${y},0)`,children:o.items},"legend-group-"+n)),y+=o.offset+5,t[n+1]&&g.push(ji("line",{stroke:"gray",x1:y,y1:-8,x2:y,y2:(o.totalHeight||e)+0+8},"legend-top-line legend-symbol-"+n)),y+=12}),ji("g",{children:g})})({legendGroups:e||[],title:a,height:l,width:c,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:y,onFocusedIndexChange:m,legendInteraction:s,metrics:h}),x=!(!o&&!n);return Yi("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&&ji("text",{className:"legend-title",y:16,x:c/2,textAnchor:"middle",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}function Zi(...t){let e;for(const o of t)o&&(e=Qi(e)&&Qi(o)?{legendGroups:[...e.legendGroups,...o.legendGroups]}:o);return e}function Qi(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function Ji(t){return"object"==typeof t&&null!==t&&"gradient"in t}import{jsx as tr}from"react/jsx-runtime";function er(t){const{legend:e,totalWidth:o,totalHeight:n,margin:i,legendPosition:r="right",legendLayout:s,title:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:u,legendIsolatedCategories:d,legendInteraction:h}=t;if(!e)return null;const f="top"===r||"bottom"===r,p=!!a,y=Math.max(0,o-i.left-i.right),g=Math.max(1,f?s?.maxWidth??y:100);let m,b;return"left"===r?(m=Math.max(4,i.left-g-10),b=i.top):"top"===r?(m=i.left,b=p?32:8):"bottom"===r?(m=i.left,b=n-i.bottom+38):(m=o-i.right+10,b=i.top),tr("g",{transform:`translate(${m}, ${b})`,children:Ji(e)?tr(Ui,{config:e.gradient,orientation:f?"horizontal":"vertical",width:g}):Qi(e)?tr(Ki,{legendGroups:e.legendGroups,title:"",width:g,orientation:f?"horizontal":"vertical",legendLayout:s,customHoverBehavior:c,customClickBehavior:l,highlightedCategory:u,isolatedCategories:d,legendInteraction:h}):e})}import{useMemo as or}from"react";import{bin as nr}from"d3-array";import{jsx as ir,jsxs as rr}from"react/jsx-runtime";function sr(t){return"string"==typeof t?{type:t}:t}function ar({orient:t,config:e,values:o,scale:n,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,c=or(()=>{if(0===o.length)return null;const e=n.domain(),c=i-8;if("boxplot"===s.type){const e=function(t){const e=[...t].sort((t,e)=>t-e),o=e.length;if(0===o)return null;const n=e[Math.floor(.25*o)],i=e[Math.floor(.5*o)],r=e[Math.floor(.75*o)],s=r-n;return{q1:n,median:i,q3:r,whiskerLow:Math.max(e[0],n-1.5*s),whiskerHigh:Math.min(e[o-1],r+1.5*s)}}(o);if(!e)return null;const{q1:i,median:r,q3:l,whiskerLow:u,whiskerHigh:d}=e,h=Math.min(.5*c,20),f=(c-h)/2+4;if(a){const e=n(i),o=n(l),a=n(r),c=n(u),p=n(d),y="top"===t?-1:1,g=0;return rr("g",{"data-testid":"marginal-boxplot-"+t,children:[ir("line",{x1:c,y1:g+y*(f+h/2),x2:p,y2:g+y*(f+h/2),stroke:s.fill,strokeWidth:s.strokeWidth}),ir("line",{x1:c,y1:g+y*f,x2:c,y2:g+y*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),ir("line",{x1:p,y1:g+y*f,x2:p,y2:g+y*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),ir("rect",{x:Math.min(e,o),y:"top"===t?g-f-h:g+f,width:Math.abs(o-e),height:h,fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),ir("line",{x1:a,y1:"top"===t?g-f-h:g+f,x2:a,y2:"top"===t?g-f:g+f+h,stroke:s.fill,strokeWidth:2})]})}{const e=n(i),o=n(l),a=n(r),c=n(u),p=n(d),y="left"===t?-1:1,g=0;return rr("g",{"data-testid":"marginal-boxplot-"+t,children:[ir("line",{x1:g+y*(f+h/2),y1:c,x2:g+y*(f+h/2),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),ir("line",{x1:g+y*f,y1:c,x2:g+y*(f+h),y2:c,stroke:s.fill,strokeWidth:s.strokeWidth}),ir("line",{x1:g+y*f,y1:p,x2:g+y*(f+h),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),ir("rect",{x:"left"===t?g-f-h:g+f,y:Math.min(e,o),width:h,height:Math.abs(o-e),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),ir("line",{x1:"left"===t?g-f-h:g+f,y1:a,x2:"left"===t?g-f:g+f+h,y2:a,stroke:s.fill,strokeWidth:2})]})}}const l=nr().domain(e).thresholds(s.bins)(o);if(0===l.length)return null;const u=A(l.map(t=>t.length));if(0===u)return null;if("histogram"===s.type)return ir("g",{"data-testid":"marginal-histogram-"+t,children:l.map((e,o)=>{if(null==e.x0||null==e.x1)return null;const i=e.length/u*c;if(a){const r=n(e.x0),a=n(e.x1)-n(e.x0);return ir("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},o)}{const r=n(e.x0),a=n(e.x1)-n(e.x0);return ir("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},o)}})});if("violin"===s.type){const e=c/2+4,o=[];for(const i of l){if(null==i.x0||null==i.x1)continue;const r=i.length/u*(c/2),s=n((i.x0+i.x1)/2);o.push(a?`${s},${"top"===t?-(e-r):e-r}`:`${"left"===t?-(e-r):e-r},${s}`)}for(let i=l.length-1;i>=0;i--){const r=l[i];if(null==r.x0||null==r.x1)continue;const s=r.length/u*(c/2),d=n((r.x0+r.x1)/2);o.push(a?`${d},${"top"===t?-(e+s):e+s}`:`${"left"===t?-(e+s):e+s},${d}`)}return ir("g",{"data-testid":"marginal-violin-"+t,children:ir("polygon",{points:o.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 o=0,i=null!=l[0].x0?n(l[0].x0):0;e.push(`M${i},${o}`);for(const o of l){if(null==o.x0||null==o.x1)continue;const i=o.length/u*c,r=n((o.x0+o.x1)/2);e.push(`L${r},${"top"===t?-i-4:i+4}`)}const s=null!=l[l.length-1].x1?n(l[l.length-1].x1):r;e.push(`L${s},${o}`),e.push("Z")}else{const o=0,i=null!=l[0].x0?n(l[0].x0):0;e.push(`M${o},${i}`);for(const o of l){if(null==o.x0||null==o.x1)continue;const i=o.length/u*c,r=n((o.x0+o.x1)/2);e.push(`L${"left"===t?-i-4:i+4},${r}`)}const s=null!=l[l.length-1].x1?n(l[l.length-1].x1):r;e.push(`L${o},${s}`),e.push("Z")}return ir("g",{"data-testid":"marginal-ridgeline-"+t,children:ir("path",{d:e.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}return null},[o,n,s,i,r,t,a,4]);return c?ir("g",{className:"marginal-"+t,"data-testid":"marginal-"+t,children:c}):null}import*as cr from"react";import{jsx as lr,jsxs as ur}from"react/jsx-runtime";function dr(t,e=120,o=8){if(!t)return[];const n=Math.max(1,Math.floor(e/o)),i=t.split(/\s+/),r=[];let s="";for(const t of i)s&&s.length+1+t.length>n?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function hr(t,e,o,n){return"curly"===t?n?`M0,0 C${.6*o},0 ${.4*o},${e/2} ${o},${e/2} C${.4*o},${e/2} ${.6*o},${e} 0,${e}`:`M0,0 C0,${.6*o} ${e/2},${.4*o} ${e/2},${o} C${e/2},${.4*o} ${e},${.6*o} ${e},0`:n?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function fr(t,e,o,n){if(!t)return lr("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=t;if(!i&&!r)return lr("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"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?l?[r]:dr(r,c):[],y=i?l?[i]:dr(i,c):[],g="leftRight"===u?"end"===h?-4:4:0;let m=0;const b=[],x=n||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?b.push(lr("foreignObject",{className:"annotation-note-html",x:"end"===h?g-c:"middle"===h?g-c/2:g,y:-16,width:c,height:Math.max(f,(p.length+y.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:ur("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:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&lr("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&lr("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(b.push(lr("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>lr("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&b.push(lr("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:m,children:y.map((t,e)=>lr("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(c,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=lr("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+y.length)*f+(y.length>0?f:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=lr("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+y.length-1)*f;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(y.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),ur("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[lr("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function pr(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(lr("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,n=e?.height||0;(t>0||n>0)&&r.push(lr("rect",{width:t,height:n,fill:"none",stroke:o||"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=n||0,s=i||0;if(void 0!==e?.x){const n=(e.x||0)-t;r.push(lr("line",{x1:n,y1:(e.y1||0)-s,x2:n,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const n=(e.y||0)-s;r.push(lr("line",{x1:(e.x1||0)-t,y1:n,x2:(e.x2||0)-t,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(lr("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(lr("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",n=e?.width??e?.height;void 0!==n&&r.push(lr("path",{d:hr(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return lr("g",{className:"annotation-subject",children:r})}function yr(t,e,o,n,i,r){const s=[];let a=0,c=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const o=r.width||0,n=r.height||0;if(o>0||n>0){const i=o/2,r=n/2,s=t-i,l=e-r;if(0!==s||0!==l){const t=Math.abs(s),e=Math.abs(l),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,c=r+l*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,c=o):void 0!==e&&(a=o,c=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const n=Math.atan2(e,t);a=Math.cos(n)*o,c=Math.sin(n)*o}}const l=Math.sqrt((t-a)**2+(e-c)**2);if(l>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-c,t-a);if(r){const n=(a+t)/2,r=(c+e)/2,d=-(e-c)/l,h=(t-a)/l,f=(o?.curve??.25)*l,p=n+d*f,y=r+h*f;s.push(lr("path",{className:"connector-curve",d:`M${a},${c}Q${p},${y} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(y-c,p-a)}else s.push(lr("line",{x1:a,y1:c,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(lr("path",{d:`M${a},${c}L${a+t*Math.cos(u+e)},${c+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${c+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return lr("g",{className:"annotation-connector",children:s})}function gr(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:c,subject:l,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=t,b=Array.isArray(e)?e[0]??0:e,x=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(f)?f:[]);let w=n||0,k=i||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const A="string"==typeof u?u:"label";if("bracket"===A&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const t=l.depth||30;k=t+(0>t?-5:5)}else if(void 0!==l.height){const t=l.depth||30;w=t+(0>t?-5:5),k=l.height/2}return ur("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&yr(w,k,c,d,A,l),!v.has("subject")&&pr(A,l,d,b,x),!v.has("note")&&fr(a,w,k,d)]})}function mr(t){const{noteData:e}=t,{screenCoordinates:o}=e,n="string"==typeof e.type?e.type:"label",i=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),i=e.ny||o[0][1]+(e.dy??0),r=o.map((o,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:o[0],y:o[1],nx:t,ny:i});return lr(gr,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return lr("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return lr(gr,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{packEnclose as br}from"d3-hierarchy";import{area as xr,curveLinear as vr,curveMonotoneX as wr,curveMonotoneY as kr,curveStep as Ar,curveStepAfter as Sr,curveStepBefore as Mr,curveBasis as _r,curveCardinal as Pr,curveCatmullRom as Cr}from"d3-shape";function Rr(t){return Math.round(100*t)/100}function Ir(t,e=2){const o=[],n=[],i=e+1;for(let e=0;i>e;e++){let r=0;for(const[o,n]of t)null!==n&&(r+=o**e*n);o.push(r);const s=[];for(let o=0;i>o;o++){let n=0;for(const[i,r]of t)null!==r&&(n+=i**(e+o));s.push(n)}n.push(s)}n.push(o);const r=function(t,e){const o=t,n=t.length-1,i=[e];for(let t=0;n>t;t++){let e=t;for(let i=t+1;n>i;i++)Math.abs(o[t][i])>Math.abs(o[t][e])&&(e=i);for(let i=t;n+1>i;i++){const n=o[i][t];o[i][t]=o[i][e],o[i][e]=n}for(let e=t+1;n>e;e++)for(let i=n;i>=t;i--)o[i][e]-=o[i][t]*o[t][e]/o[t][t]}for(let t=n-1;t>=0;t--){let e=0;for(let r=t+1;n>r;r++)e+=o[r][t]*i[r];i[t]=(o[n][t]-e)/o[t][t]}return i}(n,i).map(Rr);return{points:t.map(([t])=>[Rr(t),Rr(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function Lr(t,e){const o=e.scales?.x??e.scales?.time;return o?null!=t.x?o(t.x):e.xAccessor&&null!=t[e.xAccessor]?o(t[e.xAccessor]):null:null}function Tr(t,e){const o=e.scales?.y??e.scales?.value;return o?null!=t.y?o(t.y):e.yAccessor&&null!=t[e.yAccessor]?o(t[e.yAccessor]):null:null}function $r(t){return null==t?null:t+""}function zr(t,e,o){return e.stickyPositionCache?.set(t,o),o}function Dr(t,e,o){const n=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===n){if(null!=t.pointId&&o.pointNodes&&o.pointNodes.length>0)for(let n=o.pointNodes.length-1;n>=0;n--){const i=o.pointNodes[n];if(i.pointId===t.pointId)return zr(e,o,{x:i.x,y:i.y})}const n=function(t){const e=t.data;if(!e||0===e.length)return null;const o=e[e.length-1],n=t.scales?.x??t.scales?.time,i=t.scales?.y??t.scales?.value;if(!n||!i)return null;const r=o[t.xAccessor||"x"],s=o[t.yAccessor||"y"];return null==r||null==s?null:{x:n(r),y:i(s)}}(o);return n?zr(e,o,n):null}if("semantic"===n){const n=function(t,e,o){const n=function(t){return $r(t.provenance?.stableId??t.stableId)}(t);if(!n)return null;const i=o.pointNodes?.find(t=>$r(t.pointId)===n);if(i)return zr(e,o,{x:i.x,y:i.y});const r=o.data?.find(t=>function(t){return $r(t.stableId??t.id??t.provenance?.stableId)}(t)===n);if(!r)return null;const s=Lr(r,o),a=Tr(r,o);return null==s||null==a?null:zr(e,o,{x:s,y:a})}(t,e,o);if(n)return n}let i=null,r=null;if(null!=t.pointId&&o.pointNodes){const e=o.pointNodes.find(e=>e.pointId===t.pointId);e&&(i=e.x,r=e.y)}if(null!=i&&null!=r||(i=Lr(t,o),r=Tr(t,o)),null!=i&&null!=r)return zr(e,o,{x:i,y:r});if("sticky"===n){const t=o.stickyPositionCache?.get(e);if(t)return t}return null}function Er(t,e,o,n=50){return!(-n>t||t>(o.width||0)+n||-n>e||e>(o.height||0)+n)}import{jsx as Or}from"react/jsx-runtime";var Fr={secondary:0,primary:3};function Br(t){return!0===t?._annotationDeferred}function Nr(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Wr(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function jr(t){return Math.max(.72,.95-.06*t)}import{jsx as Yr,jsxs as Gr}from"react/jsx-runtime";var qr="var(--semiotic-bg, #ffffff)";function Xr(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,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=>Yr("text",{x:e,y:o,textAnchor:c,dominantBaseline:l,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}:{},children:n});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??qr,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},y="number"==typeof p?p:p.x,g="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(n,r),b=r+2*g;let x,v;return x="middle"===c?e-m/2-y:"end"===c?e-m-y:e-y,v="middle"===l||"central"===l?o-b/2:"hanging"===l||"text-before-edge"===l?o-g:o-.8*r-g,Gr("g",{className:d,children:[Yr("rect",{x:x,y:v,width:m+2*y,height:b,rx:h.radius??3,ry:h.radius??3,fill:h.fill??qr,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}import{jsx as Hr,jsxs as Vr}from"react/jsx-runtime";var Ur={linear:vr,monotoneX:wr,monotoneY:kr,step:Ar,stepAfter:Sr,stepBefore:Mr,basis:_r,cardinal:Pr,catmullRom:Cr};function Kr(t,e,o,n){const i=[];return t.forEach((t,r)=>{let s;if(o){const i=o(t,r,n);s=null!=i?i:e(t,r,n)}else s=e(t,r,n);s&&i.push({node:s,annotation:t})}),function(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(o=t.annotation,"primary"===o?.emphasis||"secondary"===o?.emphasis?o.emphasis:null),confidence:Wr(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>Br(t.annotation)),i=t.some(t=>null!=Nr(t.annotation)),r=t.some(t=>"layer"===Nr(t.annotation));if(!o&&!n&&!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=Fr[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:n,readingOrder:i}=t,r=Br(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=Or("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:jr(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=Nr(e.annotation);return a&&(s=Or("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=Or("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(Or("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(Or("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 Zr=32,Qr=6,Jr=4,ts=8,es=72;var os={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function ns(t){if(!is(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 is(t){return l(t)}function rs(t,e){if(!t)return[];const o=Math.max(1,Math.floor(e/7)),n=t.split(/\s+/).filter(Boolean),i=[];let r="";for(const t of n)r&&r.length+t.length+1>o?(i.push(r),r=t):r=r?`${r} ${t}`:t;return r&&i.push(r),i}function ss(t,e,o,n,i){const r=t+o,s=e+n;return Math.abs(o)>Math.abs(n)?{x:0>o?r-i.width-4:r+4,y:0>n?s-i.height:s,width:i.width,height:i.height}:{x:0>o?r-i.width:r,y:0>n?s-i.height-4:s+4,width:i.width,height:i.height}}function as(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function cs(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 ls(t,e,o,n,i,r,s,a){const c=as(t,s);let l=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,o,n){const i=Math.max(0,n-t.x),r=Math.max(0,n-t.y);return(i+Math.max(0,t.x+t.width-(e-n)))*t.height+(r+Math.max(0,t.y+t.height-(o-n)))*t.width}(c,i,r,a);for(const t of o)l+=12*cs(c,t);for(const t of n)l+=4*cs(c,t);return l}function us(t){const{annotations:e,context:i,defaultOffset:r=Zr,notePadding:s=Qr,markPadding:a=Jr,edgePadding:c=ts,preserveManualOffsets:l=!0,routeLongConnectors:u=!0,connectorThreshold:d=es,density:h,progressiveDisclosure:f=!1,redundantCues:p=!1,responsive:y,mobile:g,cohesion:m,audience:b}=t,x=i.width||0,v=i.height||0,w="object"==typeof g?g:{},k=w.breakpoint??480,A=!!g&&k>=x,S=A&&!1!==w.preferShortText?e.map(ns):e,M=A&&!h?{maxAnnotations:w.maxAnnotations??("callout-list"===w.strategy?1:2),minVisible:w.minVisible??1}:h,_=f||A&&(!1!==w.progressiveDisclosure||"callout-list"===w.strategy),P=A&&!y?w.responsive??{minWidth:k}:y,C=A&&!m?w.cohesion:m;if(0===S.length||0>=x||0>=v)return S.slice();const R=[],I=function(t,e){return(t.pointNodes||[]).map(t=>{const o=Math.max(1,t.r||1)+e;return{x:t.x-o,y:t.y-o,width:2*o,height:2*o}})}(i,a);let L=!1;const T=S.map((t,e)=>{if(!is(t))return t;const o=function(t,e,o){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const n=t.pointId??t.nodeId;if(null!=n&&o.pointNodes){const t=o.pointNodes.find(t=>t.pointId===n);if(t)return{x:t.x,y:t.y}}const i=t.coordinates,r=o.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 o=r([t,e]);if(o&&"number"==typeof o[0]&&"number"==typeof o[1])return{x:o[0],y:o[1]}}}return o.scales||"number"!=typeof t.x||"number"!=typeof t.y?Dr(t,e,o):{x:t.x,y:t.y}}(t,e,i);if(!o)return t;const n=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,o=[...rs("string"==typeof t.title?t.title:void 0,e),...rs("string"==typeof t.label?t.label:void 0,e)],n=o.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*n)+10),height:Math.max(18,16*o.length+6)}}(t);if(l&&("number"==typeof(a=t).dx||"number"==typeof a.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:30,dy:-30}}(t);return R.push(as(ss(o.x,o.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,n),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=ls(ss(o.x,o.y,t.dx,t.dy,n),t,R,I,x,v,s,c);f>e&&(h=t,f=e)}if(!h)return t;const p=as(ss(o.x,o.y,h.dx,h.dy,n),s);R.push(p);const y=Math.hypot(h.dx,h.dy),g=u&&y>=d&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return L=!0,{...t,dx:h.dx,dy:h.dy,...g?{connector:g}:{}}}),$=L?T:S.slice();let z=$;if(p){let t=!1;const e=$.map(e=>{const o=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 o!==e&&(t=!0),o});z=t?e:$}{let t=!1;const e=z.map(e=>{if(!0!==e?.defensive)return e;const o=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const o="string"==typeof e.source?os[e.source]??e.source:null,n="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!o&&!n)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const i=[o,n].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${i})`)?t:{...t,label:r?`${r} (${i})`:`(${i})`}}(e);return o!==e&&(t=!0),o});z=t?e:z}const D=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 o=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===o.length?3:o.reduce((t,e)=>t+e,0)/o.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??o(x,v,t))*e))},{deferred:r}=n({annotations:z,width:x,height:v,...i});for(const t of r)D.add(t)}if(P&&("object"==typeof P&&"number"==typeof P.minWidth?P.minWidth:480)>=x)for(const t of z)is(t)&&"secondary"===t.emphasis&&D.add(t);if(D.size>0)for(const t of z)!0===t?.defensive&&D.delete(t);let E;return E=0===D.size?z:_?z.map(t=>D.has(t)?{...t,_annotationDeferred:!0}:t):z.filter(t=>!D.has(t)),C?function(t,e){let o=!1;const n=t.map(t=>is(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(o=!0,{...t,cohesion:e}):t);return o?n:t}(E,C):E}import{useSyncExternalStore as ds}from"react";var hs={positions:new Map},fs=new Set;function ps(){for(const t of fs)t()}function ys(t,e){const o=hs.positions.get(t);if(o?.locked)return;if(!o||o.sourceId!==e)return;const n=new Map(hs.positions);n.delete(t),hs={positions:n},ps()}function gs(t,e){const o=hs.positions.get(t);if(!o?.locked)return;if(e&&o.sourceId!==e)return;const n=new Map(hs.positions);n.delete(t),hs={positions:n},ps()}function ms(){return hs}function bs(t){return fs.add(t),()=>fs.delete(t)}var xs={positions:new Map};function vs(){return()=>{}}function ws(){return xs}function ks(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),n=o[0],i=o[o.length-1],r=n instanceof Date,s=n instanceof Date?n.getTime():n,a=i instanceof Date?i.getTime():i;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const c=(a-s)/(e-1),l=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*c;l[t]=r?new Date(o):o}return l}(t,e):t.ticks(e)}function As(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function Ss(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function Ms(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const n of t)e>n.pixel&&(e=n.pixel),n.pixel>o&&(o=n.pixel);return{min:e,max:o}}function _s(t){if(t)return"dashed"===t?"6,4":"dotted"===t?"2,4":t}function Ps(t,e,o){if("left"===t||"right"===t){const n="left"===t?o:0,i="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+n;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${n+4*i}`,s+=`L${Math.min(o,e)},${n}`}return s}const n="bottom"===t?0:e,i="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${n},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${n+4*i},${Math.min(8*t+4,o)}`,s+=`L${n},${Math.min(e,o)}`}return s}function Cs(t){return"string"==typeof t&&t.length>0}function Rs(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function Is(t,e){return Rs(t,Cs(e))}import{Fragment as Ls,jsx as Ts,jsxs as $s}from"react/jsx-runtime";function zs(t){const{width:e,height:o,totalWidth:n,totalHeight:i,margin:r,scales:s,showAxes:a,axes:c,showGrid:l,xFormat:u,yFormat:d,axisExtent:h}=t,f=Ei(()=>{if(!s)return[];const t=c?.find(t=>"bottom"===t.orient),o=t?.tickFormat||u||Ds,n=Math.max(2,Math.floor(e/70)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,n),a=t?.tickValues??ks(s.x,r,h),l=a.map(t=>t.valueOf()),d=a.map((t,e)=>({value:t,pixel:s.x(t),label:o(t,e,l)})),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 Es(d,Math.max(55,f+8))},[s,c,u,e,h]),p=Ei(()=>{if(!s)return[];const t=c?.find(t=>"left"===t.orient),e=t?.tickFormat||d||Ds,n=Math.max(2,Math.floor(o/30)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,n);return Es((t?.tickValues??ks(s.y,r,h)).map(t=>({value:t,pixel:s.y(t),label:e(t)})),22)},[s,c,d,o,h]),y=l&&s,g=a&&s;if(!y&&!g)return null;const m=c?.find(t=>"bottom"===t.orient),b=c?.find(t=>"left"===t.orient),x=g&&(!m||!1!==m.baseline),v=g&&(!b||!1!==b.baseline),w=m?.jaggedBase||!1,k=b?.jaggedBase||!1,A="var(--semiotic-border, #ccc)";return Ts("svg",{width:n,height:i,style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:$s("g",{transform:`translate(${r.left},${r.top})`,children:[y&&(()=>{const t=_s(c?.find(t=>"bottom"===t.orient)?.gridStyle),n=_s(c?.find(t=>"left"===t.orient)?.gridStyle);return $s("g",{className:"stream-grid",children:[f.map((e,n)=>Ts("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:o,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+n)),p.map((t,o)=>Ts("line",{x1:0,y1:t.pixel,x2:e,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:n},"ygrid-"+o))]})})(),x&&!w&&Ts("line",{x1:0,y1:o,x2:e,y2:o,stroke:A,strokeWidth:1}),w&&Ts("path",{d:Ps("bottom",e,o),fill:"none",stroke:A,strokeWidth:1}),v&&!k&&Ts("line",{x1:0,y1:0,x2:0,y2:o,stroke:A,strokeWidth:1}),k&&Ts("path",{d:Ps("left",e,o),fill:"none",stroke:A,strokeWidth:1})]})})}function Ds(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function Es(t,e){if(2>=t.length)return t;const o=[t[0]];for(let n=1;t.length-1>n;n++)e>Math.abs(t[n].pixel-o[o.length-1].pixel)||o.push(t[n]);const n=t[t.length-1];return e>Math.abs(n.pixel-o[o.length-1].pixel)?o[o.length-1]=n:o.push(n),o}function Os(t){const{width:o,height:n,totalWidth:i,totalHeight:r,margin:s,scales:c,showAxes:l,axes:u,xLabel:d,yLabel:h,yLabelRight:f,xFormat:p,yFormat:y,axisExtent:m,showGrid:b,title:x,legend:v,legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:A,legendIsolatedCategories:S,legendPosition:_="right",legendLayout:P,foregroundGraphics:C,marginalGraphics:R,xValues:I,yValues:L,annotations:T,onAnnotationActivate:$,onObservation:z,chartId:D,chartType:E,autoPlaceAnnotations:O,svgAnnotationRules:F,xAccessor:B,yAccessor:N,annotationData:W,pointNodes:j,curve:Y,underlayRendered:G,canvasObscuresUnderlay:q=!0,linkedCrosshairName:X,linkedCrosshairSourceId:H,children:V}=t,U=g({onAnnotationActivate:$,onObservation:z,chartId:D,chartType:E}),K=Ei(()=>{if(!l||!c)return[];const t=u?.find(t=>"bottom"===t.orient),e=t?.tickFormat||p||Ds,n=Math.max(2,Math.floor(o/70)),i=t?.ticks??5,r="exact"===m?Math.max(2,i):Math.min(i,n),s=t?.tickValues??ks(c.x,r,m),a=s.map(t=>t.valueOf()),d=s.map((t,o)=>({value:t,pixel:c.x(t),label:e(t,o,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 y=Es(d,f);if(y.length>1&&(y=y.filter((t,e)=>0===e||t.label+""!=y[e-1].label+"")),t?.includeMax&&y.length>0&&"exact"!==m&&!t?.tickValues){const t=c.x.domain()[1],o=c.x(t),n=y[y.length-1].pixel;if(Math.abs(o-n)>1){const i=e(t,y.length,a);f>o-n&&y.length>1&&(y=y.slice(0,-1)),y.push({value:t,pixel:o,label:i})}}return y},[l,c,u,p,o,m]),Z=Ei(()=>{if(!l||!c)return[];const t=u?.find(t=>"left"===t.orient),e=t?.tickFormat||y||Ds,o=Math.max(2,Math.floor(n/30)),i=t?.ticks??5,r="exact"===m?Math.max(2,i):Math.min(i,o);let s=Es((t?.tickValues??ks(c.y,r,m)).map(t=>({value:t,pixel:c.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"!==m&&!t?.tickValues){const t=c.y.domain()[1],o=c.y(t),n=s[s.length-1].pixel;if(Math.abs(o-n)>1){const i=e(t);22>Math.abs(o-n)&&s.length>1&&(s=s.slice(0,-1)),s.push({value:t,pixel:o,label:i})}}return s},[l,c,u,y,n,m]),Q=Ei(()=>{if(!l||!c)return[];const t=u?.find(t=>"right"===t.orient);if(!t)return[];const e=t.tickFormat||y||Ds,o=Math.max(2,Math.floor(n/30)),i=t.ticks??5;return Es((t.tickValues??ks(c.y,"exact"===m?Math.max(2,i):Math.min(i,o),m)).map(t=>({value:t,pixel:c.y(t),label:e(t)})),22)},[l,c,u,y,n,m]),J=Oi(new Map),tt=Oi(T?.length??0),et=T?.length??0;tt.current!==et&&(tt.current=et,J.current=new Map);const ot=Ei(()=>{if(!T||0===T.length)return null;const t=a(T),i=function(t,o={}){return function(t,n,i){switch(t.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const e=Dr(t,n,i);if(!e)return null;const{x:o,y:r}=e;if(!Er(o,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 Hr(mr,{noteData:{x:o,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-"+n)}case"x-threshold":{const e=Lr(null!=t.value?{...t,x:t.value}:t,i);if(null==e)return null;const o=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),c=a?e-4:e+4,l=a?"end":"start";return Vr("g",{opacity:t.opacity,children:[Hr("line",{x1:e,y1:0,x2:e,y2:i.height||0,stroke:o,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Hr(Xr,{x:c,y:s,text:t.label,textAnchor:l,fill:o,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+n)}case"y-threshold":{const e=Tr(null!=t.value?{...t,y:t.value}:t,i);if(null==e)return null;const o=t.color||"#f97316",r=t.labelPosition||"right";let s,c;"left"===r?(s=4,c="start"):"center"===r?(s=(i.width||0)/2,c="middle"):(s=(i.width||0)-4,c="end");const l=20>(a=e)?Math.min((i.height||0)-4,a+16):a-4;return Vr("g",{opacity:t.opacity,children:[Hr("line",{x1:0,y1:e,x2:i.width||0,y2:e,stroke:o,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Hr(Xr,{x:s,y:l,text:t.label,textAnchor:c,fill:o,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+n)}case"enclose":{const e=(t.coordinates||[]).map(t=>({x:Lr({...t,type:"point"},i),y:Tr({...t,type:"point"},i),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const o=br(e),r=t.padding||10;return Vr("g",{children:[Hr("circle",{cx:o.x,cy:o.y,r:o.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&&Hr(Xr,{x:o.x,y:o.y-o.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+n)}case"rect-enclose":{const e=(t.coordinates||[]).map(t=>({x:Lr({...t,type:"point"},i),y:Tr({...t,type:"point"},i)})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const o=t.padding||10,r=e.map(t=>t.x),s=e.map(t=>t.y),[a,c]=M(r),[l,u]=M(s),d=a-o,h=c+o,f=l-o;return Vr("g",{children:[Hr("rect",{x:d,y:f,width:h-d,height:u+o-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&&Hr(Xr,{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-"+n)}case"highlight":{const e=i.data||[],o="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 Hr("g",{children:o.map((e,o)=>{const n=Lr(e,i),s=Tr(e,i);if(null==n||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,c="function"==typeof t.style?t.style(e):t.style||r;return Hr("circle",{cx:n,cy:s,r:a,...c},"hl-"+o)})},"ann-"+n)}case"bracket":{const e=Lr(t,i),o=Tr(t,i);return Hr(mr,{noteData:{x:e??0,y:o??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-"+n)}case"trend":{const e=i.data||[];if(2>e.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s="ordinal"===i.frameType,a="horizontal"===i.projection,c=s?o:null,l=s?r:null;let u;const d=[],h=new Map;if(s&&c&&l){for(const t of e){const e=t[c];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=e.map(t=>{const e=t[c],o=t[l];if(null==e||null==o)return null;const n=h.get(e+"");return null!=n?[n,+o]:null}).filter(t=>null!==t)}else u=e.map(t=>[t[o],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 y=t=>e=>{const o=Math.max(0,Math.floor(e)),n=Math.min(d.length-1,o+1),i=e-o,r=t(d[o]);return r+(t(d[n])-r)*i},g=f,m=p;let b;if(s)if(a){const t=y(m);b=(e,o)=>[g(o),t(e)]}else{const t=y(g);b=(e,o)=>[t(e),m(o)]}else b=(t,e)=>[g(t),m(e)];const x=t.method||"linear";let v;if("loess"===x)v=function(t,e=.3){const o=t.length;if(2>o)return t.slice();const n=t.slice().sort((t,e)=>t[0]-e[0]),i=n.map(t=>t[0]),r=n.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=i[t],n=i.map(t=>Math.abs(t-e)),c=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,l=[];for(let t=0;o>t;t++){const e=0===c?0:n[t]/c;l[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;o>t;t++){const e=l[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 y=u*f-d*d;if(1e-12>Math.abs(y))a.push([e,h/u]);else{const t=(u*p-d*h)/y;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3);else{const e="polynomial"===x?Ir(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[n,i]of t)null!==i&&(o++,e[0]+=n,e[1]+=i,e[2]+=n*n,e[3]+=n*i);const n=o*e[2]-e[0]*e[0],i=0===n?0:Rr((o*e[3]-e[0]*e[1])/n),r=Rr(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[Rr(t),Rr(i*t+r)]),equation:[i,r]}}(u);v=e.points}const w=v.map(([t,e])=>{const[o,n]=b(t,e);return`${o},${n}`}).join(" "),k=t.color||"#6366f1",A=v[v.length-1],[S,M]=b(A[0],A[1]);return Vr("g",{children:[Hr("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth||2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Hr("text",{x:S+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+n)}case"band":{const e=i.scales?.y??i.scales?.value,o=e?.domain?.(),a=t.y0??o?.[0],c=t.y1??o?.[1],l=null!=a&&e?e(a):0,u=null!=c&&e?e(c):i.height||0,d=ti(t.fill,"ann-"+n,"var(--semiotic-primary, #6366f1)");return Vr("g",{opacity:t.opacity,children:[d.def&&Hr("defs",{children:d.def}),Hr("rect",{x:0,y:Math.min(l,u),width:i.width||0,height:Math.abs(u-l),fill:d.fill,fillOpacity:t.fillOpacity||.1}),t.label&&Hr(Xr,{x:(i.width||0)-4,y:(r=l,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-"+n)}case"x-band":{const e=i.scales?.x??i.scales?.time,o=e?.domain?.(),r=t.x0??o?.[0],s=t.x1??o?.[1],a=null!=r&&e?e(r):null,c=null!=s&&e?e(s):null;if(null==a||null==c)return null;const l=ti(t.fill||t.color,"ann-"+n,"var(--semiotic-primary, #6366f1)");return Vr("g",{opacity:t.opacity,children:[l.def&&Hr("defs",{children:l.def}),Hr("rect",{x:Math.min(a,c),y:0,width:Math.abs(c-a),height:i.height||0,fill:l.fill,fillOpacity:t.fillOpacity??.1}),t.label&&Hr(Xr,{x:Math.min(a,c)+4,y:16,textAnchor:"start",fill:t.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:t.label,background:t.labelBackground??"halo"})]},"ann-"+n)}case"envelope":{const e=i.data||[];if(2>e.length)return null;const o=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",c=t.lowerAccessor||"lowerBounds",l=t.filter,u=e.filter(t=>null!=t[a]&&null!=t[c]&&!(l&&!l(t))).sort((t,e)=>t[o]-e[o]);if(2>u.length)return null;const d=Ur[i.curve||"linear"]||vr,h=xr().x(t=>r(t[o])).y0(t=>s(t[c])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1";return Vr("g",{children:[Hr("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&u.length>0&&Hr("text",{x:r(u[u.length-1][o])+4,y:s(u[u.length-1][a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+n)}case"anomaly-band":{const e=i.data||[];if(2>e.length)return null;const o=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[o]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const c=a.reduce((t,e)=>t+e,0)/a.length,l=a.reduce((t,e)=>t+(e-c)**2,0)/a.length,u=Math.sqrt(l),d=t.threshold??2,h=c-d*u,f=!1!==t.showBand,p=t.fill||"#6366f1",y=t.fillOpacity??.1,g=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,b=s(c+d*u),x=s(h),v=e.filter(t=>{const e=t[o];return null!=e&&Math.abs(e-c)>d*u});return Vr("g",{children:[f&&Hr("rect",{x:0,y:Math.min(b,x),width:i.width||0,height:Math.abs(x-b),fill:p,fillOpacity:y}),v.map((t,e)=>{const o=Lr(t,i),n=Tr(t,i);return null==o||null==n?null:Hr("circle",{cx:o,cy:n,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Hr("text",{x:(i.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:p,fontSize:11,children:t.label})]},"ann-"+n)}case"forecast":{const e=i.data||[];if(3>e.length)return null;const o=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 c=e.map(t=>[t[o],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>c.length)return null;let l;if("polynomial"===(t.method||"linear")){const e=Ir(c,t.order||2).equation;l=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=c.length;let e=0,o=0,n=0,i=0;for(const[t,r]of c)e+=t,o+=r,n+=t*t,i+=t*r;const r=t*n-e*e;if(1e-12>Math.abs(r))return null;const s=(t*i-e*o)/r,a=(o-s*e)/t;l=t=>a+s*t}const u=c.length,d=c.map(([t,e])=>e-l(t)),h=d.reduce((t,e)=>t+e*e,0),f=Math.sqrt(h/Math.max(u-2,1)),p=c.reduce((t,e)=>t+e[0],0)/u,y=c.reduce((t,e)=>t+(e[0]-p)**2,0),g=t.confidence??.95,m=.99>g?.95>g?.9>g?1:1.645:1.96:2.576,b=t.steps??5,x=c[u-1][0],v=(x-c[0][0])/Math.max(u-1,1),w=[];for(let t=1;b>=t;t++)w.push(x+t*v);const k=[];for(const t of w){const e=l(t),o=f*Math.sqrt(1+1/u+(y>0?(t-p)**2/y:0))*m;k.push({x:t,yCenter:e,yUpper:e+o,yLower:e-o})}const A=`M${k.map(t=>`${s(t.x)},${a(t.yUpper)}`).join(" L")} L${k.slice().reverse().map(t=>`${s(t.x)},${a(t.yLower)}`).join(" L")} Z`,S=k.map(t=>`${s(t.x)},${a(t.yCenter)}`).join(" "),M=`${s(x)},${a(l(x))}`,_=t.strokeColor||"#6366f1";return Vr("g",{children:[Hr("path",{d:A,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Hr("polyline",{points:`${M} ${S}`,fill:"none",stroke:_,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k.length>0&&Hr("text",{x:s(k[k.length-1].x)+4,y:a(k[k.length-1].yCenter)-4,fill:_,fontSize:11,children:t.label})]},"ann-"+n)}case"widget":{let r,s;if(null!=t.px&&null!=t.py)r=t.px,s=t.py;else{const e=Dr(t,n,i);if(!e)return null;r=e.x,s=e.y}if(!Er(r,s,i))return null;const a=t.dx??0,c=t.dy??0,l=t.width??32,u=t.height??32,d=t.content??Hr("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Hr("foreignObject",{x:r+a-l/2,y:s+c-u/2,width:l,height:u,style:{overflow:"visible",pointerEvents:"auto"},children:Hr("div",{...e(t,o),style:{width:l,height:u,display:"flex",alignItems:"center",justifyContent:"center"},children:d})},"ann-"+n)}case"text":{const e=Dr(t,n,i);if(!e)return null;const{x:o,y:r}=e,s=o+(t.dx||0),a=r+(t.dy||0),c=t.color||"var(--semiotic-text, #333)",l=Hr("text",{x:s,y:a,fill:c,fontSize:t.fontSize||11,opacity:t.opacity,strokeDasharray:t.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:t.label});return!0!==t._redundantConnector?cr.cloneElement(l,{key:"ann-text-"+n}):Vr("g",{opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:[Hr("line",{x1:o,y1:r,x2:s,y2:a,stroke:c,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),cr.cloneElement(l,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+n)}case"category-highlight":{const e=t.category;if(null==e)return null;const o=t=>"function"==typeof t&&"function"==typeof t.bandwidth,r=i.scales?.o,s=i.scales?.x,a=i.scales?.y,c=o(r)?r:o(s)?s:o(a)?a:null;if(!c)return null;const l=c(e+"");if(null==l)return null;const u=c.bandwidth(),d=t.color||"var(--semiotic-primary, #4589ff)",h=t.opacity??.15,f=t.label;return Vr("g",(i.projection?"vertical"===i.projection:c===s)?{children:[Hr("rect",{x:l,y:0,width:u,height:i.height||0,fill:d,fillOpacity:h}),f&&Hr(Xr,{x:l+u/2,y:16,textAnchor:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]}:{children:[Hr("rect",{x:0,y:l,width:i.width||0,height:u,fill:d,fillOpacity:h}),f&&Hr(Xr,{x:12,y:l+u/2,dominantBaseline:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]},"ann-"+n)}default:return null}var r,s,a}}(0,U),r={scales:c?{x:c.x,y:c.y,time:c.x,value:c.y}:null,timeAxis:"x",xAccessor:B,yAccessor:N,width:o,height:n,data:W,frameType:"xy",pointNodes:j,curve:Y,stickyPositionCache:J.current};return Kr(O?us({annotations:t,context:r,..."object"==typeof O?O:{}}):t,i,F,r)},[T,O,F,o,n,B,N,W,c,j,Y,U]),nt=function(t){const e=ds(t?bs:vs,t?ms:ws,t?ms:ws);return t?e.positions.get(t)??null:null}(X);return Fi(()=>{if(!nt?.locked||!X)return;const t=t=>{"Escape"===t.key&&gs(X)};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[nt?.locked,X]),l||x||v||C||R||ot&&ot.length>0||b||V||nt?$s("svg",{role:"img",width:i,height:r,overflow:"visible",style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Ts("title",{children:"string"==typeof x?x:"XY Chart"}),Ts("desc",{children:"string"==typeof x?x+" (XY data visualization)":"XY data visualization"}),$s("g",{transform:`translate(${s.left},${s.top})`,children:[b&&c&&(!G||q)&&(()=>{const t=_s(u?.find(t=>"bottom"===t.orient)?.gridStyle),e=_s(u?.find(t=>"left"===t.orient)?.gridStyle);return $s("g",{className:"stream-grid",children:[K.map((e,o)=>Ts("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:n,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+o)),Z.map((t,n)=>Ts("line",{x1:0,y1:t.pixel,x2:o,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:e},"ygrid-"+n))]})})(),l&&c&&(()=>{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,a=t?.jaggedBase||!1,c=e?.jaggedBase||!1,l=e?.landmarkTicks,p=t?.landmarkTicks,y="var(--semiotic-border, #ccc)",g="var(--semiotic-text-secondary, var(--semiotic-text, #666))",m="var(--semiotic-text, #333)",b=!!e?.autoRotate&&K.length>1&&(()=>{const t=o/Math.max(K.length-1,1);return K.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8>t})(),x=b?12:18,v=n+(b?58:40),w={fontSize:"var(--semiotic-tick-font-size, 12px)"},k={fontSize:"calc(var(--semiotic-tick-font-size, 12px) + 1px)"},A={fontSize:"var(--semiotic-axis-label-font-size, 12px)"},S=e?.tickAnchor,M=t?.tickAnchor,_=Ms(K),P=Ms(Z);return $s("g",{className:"stream-axes",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[$s("g",{className:"semiotic-axis semiotic-axis-bottom","data-orient":"bottom",children:[(!G||q)&&r&&!c&&Ts("line",{x1:0,y1:n,x2:o,y2:n,stroke:y,strokeWidth:1}),(!G||q)&&c&&Ts("path",{d:Ps("bottom",o,n),fill:"none",stroke:y,strokeWidth:1}),K.map((t,e)=>{const o=!!l&&("function"==typeof l?l(t.value,e):In(t.value,e>0?K[e-1].value:void 0));return $s("g",{transform:`translate(${t.pixel},${n})`,children:[Ts("line",{y2:5,stroke:y,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ts("text",{y:x,textAnchor:b?"end":As(S,t.pixel===_.min,t.pixel===_.max),fontWeight:o?600:400,fill:g,className:"semiotic-axis-tick",style:{userSelect:"none",...o?k:w},transform:b?"rotate(-45)":void 0,children:t.label}):Ts("foreignObject",{x:-30,y:6,width:60,height:24,style:{overflow:"visible"},children:Ts("div",{style:{textAlign:"center",userSelect:"none",...w},children:t.label})})]},"xtick-"+e)}),d&&Ts("text",{x:o/2,y:v,textAnchor:"middle",fill:m,className:"semiotic-axis-label",style:{userSelect:"none",...A},children:d})]}),$s("g",{className:"semiotic-axis semiotic-axis-left","data-orient":"left",children:[(!G||q)&&i&&!a&&Ts("line",{x1:0,y1:0,x2:0,y2:n,stroke:y,strokeWidth:1}),(!G||q)&&a&&Ts("path",{d:Ps("left",o,n),fill:"none",stroke:y,strokeWidth:1}),Z.map((t,e)=>{const o=!!p&&("function"==typeof p?p(t.value,e):In(t.value,e>0?Z[e-1].value:void 0));return $s("g",{transform:`translate(0,${t.pixel})`,children:[Ts("line",{x2:-5,stroke:y,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ts("text",{x:-8,textAnchor:"end",dominantBaseline:Ss(M,t.pixel===P.min,t.pixel===P.max),fontWeight:o?600:400,fill:g,className:"semiotic-axis-tick",style:{userSelect:"none",...o?k:w},children:t.label}):Ts("foreignObject",{x:-68,y:-12,width:60,height:24,style:{overflow:"visible"},children:Ts("div",{style:{textAlign:"right",userSelect:"none",...w},children:t.label})})]},"ytick-"+e)}),(()=>{const e=t?.label||h;return e?Ts("text",{x:15-s.left,y:n/2,textAnchor:"middle",fill:m,transform:`rotate(-90, ${15-s.left}, ${n/2})`,className:"semiotic-axis-label",style:{userSelect:"none",...A},children:e}):null})()]}),(()=>{const t=u?.find(t=>"right"===t.orient);if(!t||0===Q.length)return null;const e=!1!==t.baseline,i=t.landmarkTicks,r=t.label||f,a=t.tickAnchor,c=Ms(Q);return $s("g",{className:"semiotic-axis semiotic-axis-right","data-orient":"right",children:[e&&Ts("line",{x1:o,y1:0,x2:o,y2:n,stroke:y,strokeWidth:1}),Q.map((t,e)=>{const n=!!i&&("function"==typeof i?i(t.value,e):In(t.value,e>0?Q[e-1].value:void 0));return $s("g",{transform:`translate(${o},${t.pixel})`,children:[Ts("line",{x2:5,stroke:y,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ts("text",{x:8,textAnchor:"start",dominantBaseline:Ss(a,t.pixel===c.min,t.pixel===c.max),fontWeight:n?600:400,fill:g,className:"semiotic-axis-tick",style:{userSelect:"none",...n?k:w},children:t.label}):Ts("foreignObject",{x:8,y:-12,width:60,height:24,style:{overflow:"visible"},children:Ts("div",{style:{textAlign:"left",userSelect:"none",...w},children:t.label})})]},"ytick-r-"+e)}),r&&Ts("text",{x:o+s.right-15,y:n/2,textAnchor:"middle",fill:m,transform:`rotate(90, ${o+s.right-15}, ${n/2})`,className:"semiotic-axis-label",style:{userSelect:"none",...A},children:r})]})})()]})})(),ot,R&&c&&I&&L&&$s(Ls,{children:[R.top&&Ts("g",{transform:"translate(0, 0)",children:Ts(ar,{orient:"top",config:sr(R.top),values:I,scale:c.x,size:s.top,length:o})}),R.bottom&&Ts("g",{transform:`translate(0, ${n})`,children:Ts(ar,{orient:"bottom",config:sr(R.bottom),values:I,scale:c.x,size:s.bottom,length:o})}),R.left&&Ts("g",{transform:"translate(0, 0)",children:Ts(ar,{orient:"left",config:sr(R.left),values:L,scale:c.y,size:s.left,length:n})}),R.right&&Ts("g",{transform:`translate(${o}, 0)`,children:Ts(ar,{orient:"right",config:sr(R.right),values:L,scale:c.y,size:s.right,length:n})})]}),C,nt&&nt.sourceId!==H&&c?.x&&(()=>{const t=c.x(nt.xValue);if(null==t||0>t||t>o)return null;const e=nt.locked;return Ts("line",{x1:t,y1:0,x2:t,y2:n,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"})})(),V]}),x&&"string"==typeof x?Ts("text",{x:i/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)"},children:x}):x?Ts("foreignObject",{x:0,y:0,width:i,height:s.top,children:x}):null,er({legend:v,totalWidth:i,totalHeight:r,margin:s,legendPosition:_,title:x,legendLayout:P,legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:A,legendIsolatedCategories:S})]}):null}import*as Fs from"react";import{area as Bs,line as Ns}from"d3-shape";function Ws(t){return(t.tl??0)>0||(t.tr??0)>0||(t.br??0)>0||(t.bl??0)>0}function js(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,n=t=>Math.max(0,Math.min(t??0,o));return{tl:n(e.tl),tr:n(e.tr),br:n(e.br),bl:n(e.bl)}}import{jsx as Ys,jsxs as Gs}from"react/jsx-runtime";var qs={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function Xs(t,e="#4e79a7"){return Kn(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function Hs(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function Vs(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=$n(i,t.size);if(0>=r.scale)return null;const s=`translate(${e},${o})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),c=On(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),l=c?Hs(n+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>i.parts.map((o,n)=>{const i=e?"none"===o.fill?void 0:e:zn(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:zn(o.stroke??"none",a,t.accent);return i||r?Ys("path",{d:o.d,fill:i??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},n):null});return Gs("g",{transform:s,opacity:1===u?void 0:u,children:[c&&l&&Ys("clipPath",{id:l,children:Ys("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&t.ghostColor?Ys("g",{children:d(t.ghostColor)}):null,c&&l?Ys("g",{clipPath:`url(#${l})`,children:d()}):d()]},n)}function Us(t){const e=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color}));return 2>e.length?null:e.map((t,e)=>Ys("stop",{offset:t.offset,stopColor:t.color},e))}function Ks(t,e,o){const n=uo(t.symbolType,t.size,t.path);return Ys("path",{d:n,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?Xs(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}import*as Zs from"react";import{arc as Qs}from"d3-shape";import{jsx as Js,jsxs as ta}from"react/jsx-runtime";import*as ea from"react";import{jsx as oa,jsxs as na}from"react/jsx-runtime";import*as ia from"react";import{arc as ra}from"d3-shape";var sa=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function aa(t){const{innerRadius:e,outerRadius:o,startAngle:n,endAngle:i}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=sa(o,n),e=sa(o,i);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${i-n>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=sa(o,n),s=sa(o,i),a=sa(e,i),c=sa(e,n),l=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${l} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${l} 0 ${c.x},${c.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return aa({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),c=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),l=i-n,u=t.roundStart&&t.roundEnd?l/2:l,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return aa({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=n+(d?a:0),p=i-(h?a:0),y=n+(d?c:0),g=i-(h?c:0),m=sa(o,f),b=sa(o,p),x=(o-s)*Math.cos(a),v=sa(x,n),w=sa(x,i),k=r?null:sa(e,g),A=r?null:sa(e,y),S=r?0:(e+s)*Math.cos(c),M=r?null:sa(S,n),_=r?null:sa(S,i),P=p-f>Math.PI?1:0,C=r?0:g-y>Math.PI?1:0;let R="";if(d)R+=`M${v.x},${v.y}`,R+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=sa(o,n);R+=`M${t.x},${t.y}`}if(h)R+=` A${o},${o} 0 ${P} 1 ${b.x},${b.y}`,R+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=sa(o,i);R+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)R+=" L0,0";else{if(h)R+=` L${_.x},${_.y}`,R+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=sa(e,i);R+=` L${t.x},${t.y}`}if(d)R+=` A${e},${e} 0 ${C} 0 ${A.x},${A.y}`,R+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=sa(e,n);R+=` A${e},${e} 0 ${C} 0 ${t.x},${t.y}`}}return R+=" Z",R}import{jsx as ca,jsxs as la}from"react/jsx-runtime";function ua(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 da(t,e){const o=t.datum;if(!o)return null;const n=[],i=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||n.push(ca("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 c=Number(o.__funnelValue),l=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(c)&&0!==c&&Number.isFinite(l)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${ua(c)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:ua(c);7.8*i.length+16>d&&(i=ua(c)),7.8*i.length+16>d||n.push(ca("text",{x:l,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 n.length?ca("g",{children:n},e+"-funnel-labels"):null}function ha(t,e,o){const n=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",i=o=>`ord-${t.type}-${n}-${e}-${o}`,r=`ord-${t.type}-${n}-${e}`;switch(t.type){case"rect":{const e=t,o=Hs(r)+"-grad",n=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=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?(n=t.x+t.w,i=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(n=t.x,i=t.y,r=t.x+t.w,s=t.y);const a=[];if("colorStops"in o){const t=Us(o.colorStops);if(!t)return null;a.push(...t)}else{const e=Xs(t.style.fill);a.push(Ys("stop",{offset:0,stopColor:e,stopOpacity:o.topOpacity},"0")),a.push(Ys("stop",{offset:1,stopColor:e,stopOpacity:o.bottomOpacity},"1"))}return Ys("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a})}(e,o);let i,s;if(n)s=`url(#${o})`;else if(Kn(e.style.fill)){const t=Hs(r)+"-hatch";i=Jn(e.style.fill,t),s=`url(#${t})`}else s=Xs(e.style.fill);const a=n||i?la("defs",{children:[n,i]}):null;if(e.cornerRadii&&Ws(e.cornerRadii)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:c}=js(t);let l=`M${e+r},${o}`;return l+=` L${e+n-s},${o}`,s>0&&(l+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),l+=` L${e+n},${o+i-a}`,a>0&&(l+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),l+=` L${e+c},${o+i}`,c>0&&(l+=` A${c},${c} 0 0 1 ${e},${o+i-c}`),l+=` L${e},${o+r}`,r>0&&(l+=` A${r},${r} 0 0 1 ${e+r},${o}`),l+=" Z",l}(e);return la(ia.Fragment,{children:[a,ca("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:o,y:n,w:i,h:c}=e;let l;switch(e.roundedEdge){case"right":l=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+c-t} A${t},${t} 0 0 1 ${o+i-t},${n+c} L${o},${n+c} Z`;break;case"left":l=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+c-t} A${t},${t} 0 0 0 ${o+t},${n+c} L${o+i},${n+c} Z`;break;case"bottom":l=`M${o},${n} L${o+i},${n} L${o+i},${n+c-t} A${t},${t} 0 0 1 ${o+i-t},${n+c} L${o+t},${n+c} A${t},${t} 0 0 1 ${o},${n+c-t} Z`;break;default:l=`M${o},${n+c} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+c} Z`}return la(ia.Fragment,{children:[a,ca("path",{d:l,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return la(ia.Fragment,{children:[a,ca("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}),da(e,r)]},r)}case"point":{const e=t;return ca("circle",{cx:e.x,cy:e.y,r:e.r,fill:Xs(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return Ks(t,e,o);case"glyph":return Vs(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const n=t;if(n._gradientBand&&n._gradientBand.colors.length>0){const t=Hs(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=aa({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],n=t.colors;if(n.length>0){const e=(t.endAngle-t.startAngle)/n.length;for(let i=0;n.length>i;i++)o.push({d:aa({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+i*e,endAngle:t.endAngle}),color:n[i]})}return{clipPath:e,slices:o}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return la("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[ca("defs",{children:ca("clipPath",{id:t,children:ca("path",{d:i})})}),ca("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>ca("path",{d:t.d,fill:Xs(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&ca("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=aa({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{const t=ra().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&t.cornerRadius(n.cornerRadius),i=t(qs)||""}return ca("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:Xs(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2;return la("g","vertical"===e.projection?{children:[ca("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:Xs(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2}),ca("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1})]}:{children:[ca("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:Xs(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2}),ca("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:1}),ca("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:1})]},r)}case"violin":{const e=t,o=[ca("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:Xs(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,n=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push(ca("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),ca("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(ca("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),ca("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return ca("g",{children:o},r)}case"connector":return ca("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,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return ca("polygon",{points:o,fill:Xs(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}}import{jsx as fa,jsxs as pa}from"react/jsx-runtime";function ya(t,e,o){if(!t||2>e.length)return null;const n=Us(t.colorStops);return n?fa("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:n}):null}function ga(t,e,o){switch(t.type){case"line":{const n=t;if(0===n.path.length)return null;const i=ui(n.curve),r=i?Ns().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=Hs(`${o?o+"-":""}line-${e}-stroke-gradient`),a=ya(n.strokeGradient,n.path,s);return pa(Fs.Fragment,{children:[a&&fa("defs",{children:a}),fa("path",{d:r,fill:"none",stroke:a?`url(#${s})`:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity})]},"line-"+e)}case"area":{const n=t;if(0===n.topPath.length)return null;const i=ui(n.curve),r=!i||2>n.topPath.length||2>n.bottomPath.length?`M${n.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...n.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:Bs().x(([t])=>t).y0((t,e)=>n.bottomPath[e][1]).y1(([,t])=>t).curve(i)(n.topPath)??"",s=`${o?o+"-":""}area-${e}-hatch`,a=Kn(n.style.fill)?Jn(n.style.fill,s):void 0,c=Hs(`${o?o+"-":""}area-${e}-gradient`),l=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=1/0;for(const[,e]of t.topPath)n=Math.min(n,e);let i=-1/0;for(const[,e]of t.bottomPath)i=Math.max(i,e);if(!Number.isFinite(n)||!Number.isFinite(i))return null;const r=[];if("colorStops"in o){const t=Us(o.colorStops);if(!t)return null;r.push(...t)}else{if(!Number.isFinite(o.topOpacity)||!Number.isFinite(o.bottomOpacity))return null;r.push(fa("stop",{offset:0,stopColor:Xs(t.style.fill),stopOpacity:Math.max(0,Math.min(1,o.topOpacity))},"0")),r.push(fa("stop",{offset:1,stopColor:Xs(t.style.fill),stopOpacity:Math.max(0,Math.min(1,o.bottomOpacity))},"1"))}return fa("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r})}(n,c),u=l?`url(#${c})`:a?`url(#${s})`:Xs(n.style.fill),d=l?void 0:n.style.fillOpacity??n.style.opacity??.7,h=i?Ns().x(([t])=>t).y(([,t])=>t).curve(i)(n.topPath)??"":"M"+n.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=Hs(`${o?o+"-":""}area-${e}-stroke-gradient`),p=ya(n.strokeGradient,n.topPath,f),y=n.style.stroke&&"none"!==n.style.stroke?fa("path",{d:h,fill:"none",stroke:p?`url(#${f})`:Xs(n.style.stroke),strokeWidth:n.style.strokeWidth||2,opacity:n.style.opacity}):null;if(n.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return pa("g",{children:[pa("defs",{children:[l,!l&&a,p,fa("clipPath",{id:t,children:fa("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),pa("g",{clipPath:`url(#${t})`,children:[fa("path",{d:r,fill:u,fillOpacity:d,opacity:l?n.style.opacity:void 0,stroke:"none"}),y]})]},"area-"+e)}return pa(Fs.Fragment,{children:[(l||a||p)&&pa("defs",{children:[l,!l&&a,p]}),fa("path",{d:r,fill:u,fillOpacity:d,opacity:l?n.style.opacity:void 0,stroke:"none"}),y]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=Kn(n.style.fill)?Jn(n.style.fill,i):void 0;return pa(Fs.Fragment,{children:[r&&fa("defs",{children:r}),fa("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:Xs(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return Ks(t,e);case"glyph":return Vs(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=Kn(n.style.fill)?Jn(n.style.fill,i):void 0;return pa(Fs.Fragment,{children:[r&&fa("defs",{children:r}),fa("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:Xs(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t;if(o.showValues&&null!=o.value&&o.w>=20&&o.h>=20){const t=o.valueFormat?o.valueFormat(o.value):Number.isInteger(o.value)?o.value+"":100>Math.abs(o.value)?1>Math.abs(o.value)?o.value.toPrecision(3):o.value.toFixed(1):o.value.toFixed(0),[n,i,r]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),s=.299*n+.587*i+.114*r>128?"#000":"#fff",a=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return pa("g",{children:[fa("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth}),fa("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:a+"px",children:t})]},"heatcell-"+e)}return fa("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return pa("g",{children:[fa("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),fa("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),fa("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const n=Math.min(o.openY,o.closeY),i=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return pa("g",{children:[fa("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),fa("rect",{x:o.x-o.bodyWidth/2,y:n,width:o.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}var ma="undefined"==typeof window||"undefined"==typeof document;import{useEffect as ba,useLayoutEffect as xa,useRef as va,useState as wa,useSyncExternalStore as ka}from"react";var Aa="undefined"!=typeof window?xa:ba,Sa=()=>()=>{},Ma=()=>!1,_a=()=>!0;import{useRef as Pa}from"react";function Ca(t,e){const o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return!1;for(const n of o){if(!Object.prototype.hasOwnProperty.call(e,n))return!1;if(!Object.is(t[n],e[n]))return!1}return!0}function Ra(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(!Object.is(t[o],e[o]))return!1;return!0}function Ia(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 La(t){const{background:e,hasBackgroundGraphics:o=!1,themeBackground:n=""}=t;return"transparent"===e||o?null:e||(n&&"transparent"!==n?n:"")||null}var Ta={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 $a(t,e){const o=t.trim();if(/^#[0-9a-f]{3}$/i.test(o)){const t=o[1],n=o[2],i=o[3];return`#${t}${t}${n}${n}${i}${i}${e}`}if(/^#[0-9a-f]{6}$/i.test(o))return`${o}${e}`;const n=o.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);return n?`rgba(${n[1]}, ${(parseInt(e,16)/255).toFixed(3)})`:o}import*as za from"react";import*as Da from"react";import{jsx as Ea}from"react/jsx-runtime";var Oa=Da.createContext(null);import{jsx as Fa}from"react/jsx-runtime";var Ba={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Na({hoverPoint:t}){let e="";if(t){const o=t.data||t;e="object"==typeof o?"Data point: "+Object.entries(o).filter(([,t])=>"object"!=typeof t&&"function"!=typeof t).map(([t,e])=>`${t}: ${e}`).join(", "):"Data point: "+o}return Fa("div",{"aria-live":"polite","aria-atomic":"true",style:Ba,children:e})}function Wa(t){const e={};if(null==t||"object"!=typeof t)return e;for(const[o,n]of Object.entries(t))o.startsWith("_")||null!=n&&""!==n&&("number"==typeof n?Number.isFinite(n)&&(e[o]=n):"string"==typeof n?e[o]=n:"boolean"==typeof n?e[o]=n+"":n instanceof Date&&(e[o]=n.toISOString().slice(0,10)));return e}function ja(t){return t&&"object"==typeof t?t:{}}function Ya(t){return ja(t.accessibility).tableFields??t.accessibleDatum??t.datum}import{jsx as Ga,jsxs as qa}from"react/jsx-runtime";function Xa(t,e){if(!t||0===t.length)return e+", empty";const o={};for(const e of t){if(null===e?.datum)continue;const t=e.type+"";o[t]=(o[t]||0)+1}if(0===Object.keys(o).length)return e+", empty";const n=[],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(o).sort((t,e)=>{const o=r.indexOf(t),n=r.indexOf(e);return(-1===o?999:o)-(-1===n?999:n)});for(const t of s)n.push(`${o[t]} ${i[t]||t}`);return`${e}, ${n.join(", ")}`}var Ha=t=>{if(null==t)return"";const e=Math.round(100*t)/100;return Number.isNaN(e)?"":e+""},Va="semiotic-accessible-data-table",Ua=Va+" semiotic-accessible-data-table-hidden",Ka=Va+" semiotic-accessible-data-table-visible",Za={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"},Qa={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},Ja={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)"},tc={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},ec={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))"},oc={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},nc={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},ic={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 rc({scene:t,chartType:e,tableId:o,chartTitle:n}){const[i,r]=za.useState(!1),[s,a]=za.useState(5),c=Da.useContext(Oa),l=c?.visible??!1,u=i||l,d=za.useRef(null),h=n?"Data summary for "+n:o?`Data summary for ${e} ${o}`:"Data summary for "+e;za.useEffect(()=>{u||a(5)},[u]);const f=za.useCallback(t=>{t.target===t.currentTarget&&(i||l||r(!0))},[i,l]),p=za.useCallback(t=>{l||d.current?.contains(t.relatedTarget)||r(!1)},[l]);if(!t||0===t.length)return o?Ga("span",{id:o,tabIndex:-1,style:Ba}):null;if(!u)return Ga("div",{id:o,className:Ua,tabIndex:-1,onFocus:f,style:Ba,role:"region","aria-label":h,children:qa("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",t.length," elements)"]})});const y=function(t){const e=[];if(!Array.isArray(t))return e;const o=t.some(t=>t&&("line"===t.type||"area"===t.type));for(const n of t)if(n&&"object"==typeof n&&null!==n.datum)try{switch(n.type){case"point":if(o)break;e.push({label:"Point",values:Wa(Ya(n))});break;case"line":case"area":{const t=Ya(n),o=Array.isArray(t)?t:[],i="line"===n.type?"Line point":"Area point";for(const t of o)e.push({label:i,values:Wa(t)});break}case"rect":{const t=Ya(n),o=null!=t&&"object"==typeof t?t:{},i=o.category??n.group??"",r=o.value??o.__aggregateValue??o.total,s=Wa(o);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=Wa(Ya(n));null==t.value&&"number"==typeof n.value&&Number.isFinite(n.value)&&(t.value=n.value),e.push({label:"Cell",values:t});break}case"wedge":{const t=Ya(n),o=Wa(t);if(null==o.category){const e=ja(t),n=e.category??e.label;null!=n&&(o.category=n+"")}e.push({label:"Wedge",values:o});break}case"circle":e.push({label:"Node",values:Wa(Ya(n))});break;case"arc":e.push({label:"Arc",values:Wa(Ya(n))});break;case"candlestick":e.push({label:"Candlestick",values:Wa(Ya(n))});break;case"geoarea":{const t=ja(Ya(n)),o=Wa(t);if(null==o.name){const e=ja(t.properties).name??t.name;null!=e&&(o.name=e+"")}e.push({label:"Region",values:o});break}}}catch{}return e}(t),g=function(t){if(!t||0===t.length)return[];const e=new Set;for(const o of t)if(o&&o.values)for(const t of Object.keys(o.values))e.add(t);const o=[];for(const n of e){const e=[],i=new Set;for(const o of t){if(!o||!o.values)continue;const t=o.values[n];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 o of e)t>o&&(t=o),o>i&&(i=o),r+=o;o.push({name:n,count:e.length,numeric:!0,min:t,max:i,mean:r/e.length})}else if(i.size>0){const t=Array.from(i);o.push({name:n,count:t.length,numeric:!1,uniqueValues:t.slice(0,5)})}}return o}(y),m=function(t,e){const o=[t+" data points."];for(const t of e)if(t.numeric)o.push(`${t.name}: ${Ha(t.min)} to ${Ha(t.max)}, mean ${Ha(t.mean)}.`);else{const e=t.uniqueValues,n=e.length>3?`${e.slice(0,3).join(", ")}… (${t.count} unique)`:e.join(", ");o.push(`${t.name}: ${n}.`)}return o.join(" ")}(y.length,g),b=Math.min(s,y.length),x=y.slice(0,b),v=y.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 qa("div",{ref:d,id:o,className:Ka,tabIndex:-1,onBlur:p,style:Za,role:"region","aria-label":h,children:[Ga("button",{type:"button",className:"semiotic-accessible-data-table-close",onClick:()=>{l&&c&&c.setVisible(!1),r(!1)},"aria-label":"Close data summary",style:Ja,children:"×"}),Ga("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Qa,children:m}),qa("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Sample data for "+e,style:tc,children:[Ga("caption",{className:"semiotic-accessible-data-table-caption",style:nc,children:v>0?`First ${b} of ${y.length} data points`:`All ${y.length} data points`}),Ga("thead",{children:qa("tr",{children:[Ga("th",{style:ec,children:"type"}),k.map(t=>Ga("th",{style:ec,children:t},t))]})}),Ga("tbody",{children:x.map((t,e)=>qa("tr",{children:[Ga("td",{style:oc,children:t.label}),k.map(e=>{return Ga("td",{style:oc,children:(o=t.values[e],null==o||""===o?"—":"number"==typeof o?Number.isNaN(o)?"—":Ha(o):"boolean"==typeof o?o?"true":"false":"object"==typeof o?"—":o+"")},e);var o})]},e))})]}),v>0&&qa("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(t=>t+25),style:ic,children:["Show ",Math.min(25,v)," more"," ",1===v?"row":"rows"," (",v," remaining)"]})]})}function sc({summary:t}){return t?Ga("div",{role:"note",style:Ba,children:t}):null}function ac({tableId:t}){return Ga("a",{href:"#"+t,style:Ba,onClick:e=>{e.preventDefault();const o=document.getElementById(t);o&&requestAnimationFrame(()=>o.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,Ba)},children:"Skip to data table"})}import{jsx as cc}from"react/jsx-runtime";var lc="var(--semiotic-focus, #005fcc)";function uc({active:t,hoverPoint:e,margin:o,size:n,shape:i="circle",width:r,height:s,pathData:a}){if(!t||!e)return null;const c=e.x+o.left,l=e.y+o.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=cc("rect",{x:c-t/2-3,y:l-e/2-3,width:t+6,height:e+6,rx:3,fill:"none",stroke:lc,strokeWidth:2,strokeDasharray:"4,2"})}else u=cc("circle","wedge"===i?{cx:c,cy:l,r:12,fill:"none",stroke:lc,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:c,cy:l,r:8,fill:"none",stroke:lc,strokeWidth:2,strokeDasharray:"4,2"});else u=cc("g",{transform:`translate(${o.left},${o.top})`,children:cc("path",{d:a,fill:"none",stroke:lc,strokeWidth:2.5,strokeDasharray:"6,3"})});return cc("svg",{style:{position:"absolute",left:0,top:0,width:n[0],height:n[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:u})}import*as dc from"react";import{jsx as hc}from"react/jsx-runtime";function fc({x:t,y:e,containerWidth:o,containerHeight:n,margin:i,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const c=Number.isFinite(t)&&Number.isFinite(e),l=dc.useRef(null),[u,d]=dc.useState(null);dc.useLayoutEffect(()=>{const t=l.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 o=new ResizeObserver(e);return o.observe(t),()=>o.disconnect()},[s,o,n,c]);let h;h=u?`translate(${u.width+12>o-t?"calc(-100% - 12px)":"12px"}, ${u.height+12>n-e?"calc(-100% - 4px)":"4px"})`:`translate(${t>.7*o?"calc(-100% - 12px)":"12px"}, ${.3*n>e?"4px":"calc(-100% - 4px)"})`;const f=function(t){if(!dc.isValidElement(t))return!1;const e=t.type;if("string"!=typeof e&&e&&!0===e.ownsChrome)return!0;const o=t.props;if(!0===o["data-semiotic-tooltip-chrome"])return!0;if("true"===o["data-semiotic-tooltip-chrome"])return!0;const n=o.style;if(n&&"object"==typeof n){if(null!=n.background&&""!==n.background&&"transparent"!==n.background)return!0;if(null!=n.backgroundColor&&""!==n.backgroundColor&&"transparent"!==n.backgroundColor)return!0}return!1}(r),p=f?null:Zt;return c?hc("div",{ref:l,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 pc from"react";import{useCallback as yc,useEffect as gc,useLayoutEffect as mc,useMemo as bc,useRef as xc}from"react";import{useState as vc,useEffect as wc}from"react";import{useRef as kc,useState as Ac,useEffect as Sc}from"react";var Mc=()=>"undefined"!=typeof performance?performance.now():Date.now();function _c(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 Pc(t,e){const o=t();return Number.isFinite(o)?o:e}var Cc=class{constructor(t={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=t.clock??Mc,this.lastWallTime=Pc(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=Pc(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??Mc;e!==this.clock&&(this.advance(),this.clock=e,this.lastWallTime=Pc(e,this.lastWallTime))}setRandomSource(t,e){const o=function(t){return"number"==typeof t&&Number.isFinite(t)?Math.trunc(t):void 0}(e);t===this.randomInput&&o===this.seedValue||(this.randomInput=t,this.seedValue=o,this.randomSource=t??(void 0===o?Math.random:_c(o)))}},Rc="undefined"==typeof window?gc:mc,Ic={requestAnimationFrame:t=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(t),cancelAnimationFrame:t=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(t)};function Lc(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function Tc(t){const e=function(){const[t,e]=vc(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return wc(()=>{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 o=t;return o.addListener(e),()=>o.removeListener(e)}(t,t=>e(t.matches))},[]),t}(),o=xc(e);o.current=e;const[n,i]=function(t,e,o){const n=kc(null),[i,r]=Ac(null);return Sc(()=>{if(!e&&!o)return;const t=n.current;if(!t)return;const i=new ResizeObserver(t=>{for(const e of t){const{width:t,height:o}=e.contentRect;r(e=>e&&e.w===t&&e.h===o?e:{w:t,h:o})}});return i.observe(t),()=>i.disconnect()},[e,o]),[n,[e&&i?i.w:t[0],o&&i?i.h:t[1]]]}(t.sizeProp,t.responsiveWidth,t.responsiveHeight),r=!!t.title,s=!!t.legend&&"top"===t.legendPosition,a=bc(()=>Rs({...t.marginDefault,...t.userMargin},r,s),[t.marginDefault,t.userMargin,r,s]),c=i[0]-a.left-a.right,l=i[1]-a.top-a.bottom,u=Lc(t.foregroundGraphics,i,a),d=Lc(t.backgroundGraphics,i,a),h=z(t=>t.theme),{transition:f,introEnabled:p}=function(t,e){if(!1===t)return{transition:void 0,introEnabled:!1};const o="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:!(o||!t||!0!==t&&!1===t.intro)}}(t.animate,t.transitionProp),y="semiotic-table-"+pc.useId(),g=xc(null);if(!g.current){const e=!t.suspendWhenHidden||"undefined"==typeof document||!document.hidden;g.current=new Cc({clock:t.clock,random:t.random,seed:t.seed,paused:t.paused,visible:e})}const m=g.current;m.configure({clock:t.clock,random:t.random,seed:t.seed});const b=xc(null),x=xc(t.frameScheduler??Ic);x.current=t.frameScheduler??Ic;const v=xc(null),w=xc(!1),k=xc(()=>{}),A=yc(()=>{if(null!==b.current||w.current)return;const t=x.current;let e=!1,o=!1;const n=t.requestAnimationFrame(()=>{e=!0;const t=!o;t&&(w.current=!0),b.current=null,v.current=null;try{k.current()}finally{t&&(w.current=!1)}});o=!0,e||(b.current=n,v.current=t)},[]),S=yc(()=>{null!==b.current&&((v.current??x.current).cancelAnimationFrame(b.current),b.current=null,v.current=null)},[]);Rc(()=>{m.setPaused(!0===t.paused)},[m,t.paused]),gc(()=>{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]),gc(()=>()=>{S()},[S]);const M=xc(()=>{}),_=xc(()=>{}),P=xc(null),C=xc(null),R=xc(null),I=yc(()=>{const t=P.current;P.current=null,t&&M.current(t)},[]),L=yc(t=>{if(P.current={clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType},null===C.current){const t=x.current;let e=!1;const o=t.requestAnimationFrame(()=>{e=!0,C.current=null,R.current=null,I()});e||(C.current=o,R.current=t)}},[I]),T=yc(()=>{P.current=null,null!==C.current&&((R.current??x.current).cancelAnimationFrame(C.current),C.current=null,R.current=null),_.current()},[]);gc(()=>()=>{P.current=null,null!==C.current&&((R.current??x.current).cancelAnimationFrame(C.current),C.current=null,R.current=null)},[]);const $=t.themeDirtyRef;return Rc(()=>{$&&(Wn++,$.current=!0,A())},[h,A,$]),{reducedMotion:e,reducedMotionRef:o,responsiveRef:n,size:i,margin:a,adjustedWidth:c,adjustedHeight:l,resolvedForeground:u,resolvedBackground:d,currentTheme:h,transition:f,introEnabled:p,tableId:y,frameRuntime:m,rafRef:b,renderFnRef:k,scheduleRender:A,cancelRender:S,hoverHandlerRef:M,hoverLeaveRef:_,onPointerMove:L,onPointerLeave:T}}import{useEffect as $c,useRef as zc}from"react";import{jsx as Dc}from"react/jsx-runtime";function Ec({children:t,size:e,margin:o,overflowVisible:n=!1}){return t?Dc("svg",{style:{position:"absolute",left:0,top:0,width:e[0],height:e[1],pointerEvents:"none",overflow:n?"visible":void 0},children:Dc("g",{transform:`translate(${o.left},${o.top})`,children:t})}):null}function Oc(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}function Fc(t,e,o,n){const i=t.getContext("2d");if(!i)return null;const r=Math.round(e[0]*n),s=Math.round(e[1]*n),a=r/e[0],c=s/e[1],l=e[0]+"px",u=e[1]+"px";return t.style.width!==l&&(t.style.width=l),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,c,0,0),i.translate(o.left,o.top),i}import{useCallback as Bc,useRef as Nc}from"react";function Wc(t,e,o,n){return"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:o,fn:t}:"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:n,fn:e}:{key:void 0,fn:null}}var jc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Yc=3156e7;function Gc(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`${jc[e.getUTCMonth()]} ${e.getUTCDate()}`}:5*Yc>e?t=>{const e=new Date(t);return`${jc[e.getUTCMonth()]} ${e.getUTCFullYear()}`}:t=>new Date(t).getUTCFullYear()+""}function qc(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("symbol"===o.type)e.push({pointId:o.pointId,x:o.x,y:o.y,r:ho(o.size)});else if("glyph"===o.type){const t=Fn(o.glyph,o.size);e.push({pointId:o.pointId,x:o.x+t.centerDx,y:o.y+t.centerDy,r:t.radius})}return e}import{line as Xc}from"d3-shape";function Hc(t,e,o){let n=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(n=o.color):t>o.value&&(n=o.color);return n}function Vc(t,e,o,n,i,r){if(2>e.length)return;const s=[0];for(let t=1;e.length>t;t++){const o=e[t][0]-e[t-1][0],n=e[t][1]-e[t-1][1];s.push(s[t-1]+Math.sqrt(o*o+n*n))}const a=s[s.length-1];if(0===a)return;const c=Math.min(.2*a,40);t.strokeStyle=o,t.lineWidth=n,t.lineCap=r;for(let o=0;e.length-1>o;o++){const n=(s[o]+s[o+1])/2;let r=i;c>n&&(r*=n/c),c>a-n&&(r*=(a-n)/c),t.globalAlpha=Math.max(0,r),t.beginPath(),t.moveTo(e[o][0],e[o][1]),t.lineTo(e[o+1][0],e[o+1][1]),t.stroke()}}var Uc=(t,e,o,n)=>{const i=e.filter(t=>"line"===t.type);for(const e of i){if(2>e.path.length)continue;const o=e._introClipFraction;void 0!==o&&1>o&&(t.save(),t.beginPath(),t.rect(0,0,n.width*o,n.height),t.clip());const i=e.style.stroke||"#007bff",r=qn(t,i)||i,s=e.style.strokeWidth||2,a=e.colorThresholds,c=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 l=ui(e.curve),u=a&&a.length>0&&c&&c.length===e.path.length,d=e._decayOpacities;if(d&&d.length===e.path.length&&!u){t.strokeStyle=r;const o=e.style.opacity??1;for(let n=0;e.path.length-1>n;n++)t.globalAlpha=.5*(d[n]+d[n+1])*o,t.beginPath(),t.moveTo(e.path[n][0],e.path[n][1]),t.lineTo(e.path[n+1][0],e.path[n+1][1]),t.stroke()}else if(u){let o=function(e,o,n){t.beginPath(),t.strokeStyle=e,t.moveTo(o,n),d=!0},n=function(){d&&(t.stroke(),d=!1)},i=null,s=null,l=null,u=null,d=!1;for(let d=0;e.path.length>d;d++){const[h,f]=e.path[d],p=c[d],y=Hc(p,a,r);if(null!==i&&null!==u&&null!==l){if(y===u)t.lineTo(h,f);else{const e=[];for(const t of a){const o=t.value;(l>o||o>p)&&(o>l||p>o)||l===o||p===o||e.push({t:(o-l)/(p-l)})}e.sort((t,e)=>t.t-e.t);for(const c of e){const e=i+(h-i)*c.t,u=s+(f-s)*c.t,d=Hc(l+(p-l)*Math.min(c.t+1e-4,1),a,r);t.lineTo(e,u),n(),o(d,e,u)}t.lineTo(h,f)}i=h,s=f,l=p,u=y}else o(y,h,f),i=h,s=f,l=p,u=y}n()}else{t.beginPath();const o=e.strokeGradient&&e.path.length>=2?fi(t,e.strokeGradient,e.path[0][0],0,e.path[e.path.length-1][0],0):null;if(t.strokeStyle=o||r,l)Xc().x(t=>t[0]).y(t=>t[1]).curve(l).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}t.stroke()}if(e.style.fill&&e.style.fillOpacity&&e.style.fillOpacity>0){if(t.beginPath(),t.globalAlpha=e.style.fillOpacity,t.fillStyle=di(t,e.style.fill,e.style.fill),l&&!u)Xc().x(t=>t[0]).y(t=>t[1]).curve(l).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}const o=e.path[0][0];t.lineTo(e.path[e.path.length-1][0],n.height),t.lineTo(o,n.height),t.closePath(),t.fill()}void 0!==o&&1>o&&t.restore(),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt"}};function Kc(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function Zc(t,e,o=.3){Kc(e)&&(t.globalAlpha=e._pulseIntensity*o,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h))}function Qc(t,e,o=.6){if(!Kc(e))return;const n=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,n,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=e._pulseIntensity*o,t.stroke()}function Jc(t,e,o,n=.35){Kc(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",o?t.fill(o):t.fill())}import{area as tl,line as el}from"d3-shape";function ol(t,e){const o=ui(e.curve);if(!o||2>e.topPath.length||2>e.bottomPath.length){t.beginPath(),t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1]);for(let o=e.bottomPath.length-1;o>=0;o--)t.lineTo(e.bottomPath[o][0],e.bottomPath[o][1]);t.closePath()}else{const n=tl().x(t=>t[0]).y0((t,o)=>e.bottomPath[o][1]).y1(t=>t[1]).curve(o).context(t);t.beginPath(),n(e.topPath)}}var nl=(t,e,o,n)=>{const i=e.filter(t=>"area"===t.type);for(const e of i){if(2>e.topPath.length)continue;let o=!1;e.clipRect&&(t.save(),t.beginPath(),t.rect(e.clipRect.x,e.clipRect.y,e.clipRect.width,e.clipRect.height),t.clip(),o=!0);const i=e._introClipFraction;void 0!==i&&1>i&&(t.save(),t.beginPath(),t.rect(0,0,n.width*i,n.height),t.clip());const r=di(t,e.style.fill,"#4e79a7"),s=e._decayOpacities;if(s&&s.length===e.topPath.length){const o=e.style.fillOpacity??.7;t.fillStyle=r;for(let n=0;e.topPath.length-1>n;n++)t.globalAlpha=.5*(s[n]+s[n+1])*o,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.lineTo(e.bottomPath[n+1][0],e.bottomPath[n+1][1]),t.lineTo(e.bottomPath[n][0],e.bottomPath[n][1]),t.closePath(),t.fill();if(e.style.stroke&&"none"!==e.style.stroke){t.strokeStyle=qn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]);for(let o=0;e.topPath.length-1>o;o++)t.globalAlpha=.5*(s[o]+s[o+1]),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.stroke()}t.globalAlpha=1;continue}const a=e.style.opacity??1;if(ol(t,e),e.fillGradient&&("colorStops"in e.fillGradient&&e.fillGradient.colorStops.length>=2||"topOpacity"in e.fillGradient)&&e.fillGradient){let o=1/0;for(const t of e.topPath)o>t[1]&&(o=t[1]);let n=-1/0;for(const t of e.bottomPath)t[1]>n&&(n=t[1]);const i=hi(t,e.fillGradient,"string"==typeof r?r:"#4e79a7",0,o,0,n);t.fillStyle=i||r,t.globalAlpha=a}else t.globalAlpha=(e.style.fillOpacity??.7)*a,t.fillStyle=r;if(t.fill(),e._pulseIntensity&&e._pulseIntensity>0&&(ol(t,e),Jc(t,e)),e.style.stroke&&"none"!==e.style.stroke){t.globalAlpha=a;const o=e.strokeGradient&&e.topPath.length>=2?fi(t,e.strokeGradient,e.topPath[0][0],0,e.topPath[e.topPath.length-1][0],0):null;t.strokeStyle=o||qn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]);const n=ui(e.curve);if(t.beginPath(),n)el().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 o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1])}t.stroke()}void 0!==i&&1>i&&t.restore(),o&&t.restore(),t.globalAlpha=1}},il=(t,e,o,n)=>{const i=e.filter(t=>"point"===t.type);if(0!==i.length){t.save();try{const e=t.globalAlpha;for(const o of i)t.beginPath(),t.arc(o.x,o.y,o.r,0,2*Math.PI),t.globalAlpha=e*(o.style.opacity??o.style.fillOpacity??1),t.fillStyle=di(t,o.style.fill,"#4e79a7"),t.fill(),o.style.stroke&&(t.strokeStyle=di(t,o.style.stroke,o.style.stroke),t.lineWidth=o.style.strokeWidth||1,t.stroke()),Qc(t,o)}finally{t.restore()}}},rl=new Map;function sl(t){try{if(t.path)return new Path2D(t.path);const e=`${t.symbolType??"circle"}:${Math.round(t.size)}`;let o=rl.get(e);return o||(o=new Path2D(uo(t.symbolType,t.size)),rl.size>256&&rl.clear(),rl.set(e,o)),o}catch{return null}}var al=(t,e)=>{const o=t.globalAlpha;for(const n of e){if("symbol"!==n.type)continue;const e=n;if(0>=e.size)continue;const i=sl(e);if(!i)continue;t.save(),t.translate(e.x,e.y),e.rotation&&t.rotate(e.rotation);const r=(e.style.opacity??1)*(e._decayOpacity??1);e.style.fill&&(t.globalAlpha=o*r*(e.style.fillOpacity??1),t.fillStyle=di(t,e.style.fill,"#4e79a7"),t.fill(i)),e.style.stroke&&"none"!==e.style.stroke&&(t.globalAlpha=o*r,t.strokeStyle=di(t,e.style.stroke,e.style.stroke),t.lineWidth=e.style.strokeWidth??1,t.stroke(i)),t.restore()}t.globalAlpha=o};function cl(t,e,o,n,i){if(0>=e.size)return;const r=e.glyph;if(!r||!r.parts?.length)return;const s=$n(r,e.size);if(0>=s.scale)return;const a=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=a)return;const c=e=>{const o=di(t,e,e);return"string"==typeof o?o:e},l=e.color??("string"==typeof e.style.fill?e.style.fill:void 0);t.save(),t.translate(o,n),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=On(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");u&&e.ghostColor&&Bn(t,r,l,e.accent,e.ghostColor,c),u&&(t.beginPath(),t.rect(u.x,u.y,u.width,u.height),t.clip()),Bn(t,r,l,e.accent,void 0,c),t.restore()}function ll(t,e){const{x:o,y:n,w:i,h:r}=e,{tl:s,tr:a,br:c,bl:l}=js(e);t.beginPath(),t.moveTo(o+s,n),t.lineTo(o+i-a,n),a>0&&t.arcTo(o+i,n,o+i,n+a,a),t.lineTo(o+i,n+r-c),c>0&&t.arcTo(o+i,n+r,o+i-c,n+r,c),t.lineTo(o+l,n+r),l>0&&t.arcTo(o,n+r,o,n+r-l,l),t.lineTo(o,n+s),s>0&&t.arcTo(o,n,o+s,n,s),t.closePath()}function ul(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}}}var dl=(t,e,o,n)=>{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)hl(t,e);else if(e.cornerRadii&&Ws(e.cornerRadii)){const o=di(t,e.style.fill,qn(t,"var(--semiotic-primary, #007bff)")),n=ul(e),i=e.fillGradient&&"string"==typeof o?hi(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o,ll(t,e),t.fill(),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=qn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.stroke())}else if(e.roundedTop&&e.roundedTop>0){const o=di(t,e.style.fill,qn(t,"var(--semiotic-primary, #007bff)")),n=ul(e),i=e.fillGradient&&"string"==typeof o?hi(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o;const r=Math.min(e.roundedTop,e.w/2,e.h/2);t.beginPath();const{x:s,y:a,w:c,h:l}=e;switch(e.roundedEdge){case"right":t.moveTo(s,a),t.lineTo(s+c-r,a),t.arcTo(s+c,a,s+c,a+r,r),t.lineTo(s+c,a+l-r),t.arcTo(s+c,a+l,s+c-r,a+l,r),t.lineTo(s,a+l);break;case"left":t.moveTo(s+c,a),t.lineTo(s+r,a),t.arcTo(s,a,s,a+r,r),t.lineTo(s,a+l-r),t.arcTo(s,a+l,s+r,a+l,r),t.lineTo(s+c,a+l);break;case"bottom":t.moveTo(s,a),t.lineTo(s+c,a),t.lineTo(s+c,a+l-r),t.arcTo(s+c,a+l,s+c-r,a+l,r),t.lineTo(s+r,a+l),t.arcTo(s,a+l,s,a+l-r,r);break;default:t.moveTo(s,a+l),t.lineTo(s,a+r),t.arcTo(s,a,s+r,a,r),t.lineTo(s+c-r,a),t.arcTo(s+c,a,s+c,a+r,r),t.lineTo(s+c,a+l)}t.closePath(),t.fill(),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=qn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.stroke())}else{const o=di(t,e.style.fill,qn(t,"var(--semiotic-primary, #007bff)")),n=ul(e),i=e.fillGradient&&"string"==typeof o?hi(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o,t.fillRect(e.x,e.y,e.w,e.h),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=qn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.strokeRect(e.x,e.y,e.w,e.h))}Zc(t,e),t.globalAlpha=1}};function hl(t,e){const o=e.style.icon,n=e.style.iconPadding||2,i=Math.min(e.w,e.h)-n;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+n,s=e.x+(e.w-i)/2;for(let n=e.y+e.h-i;n>=e.y-i;n-=r)t.drawImage(o,s,n,i,i)}else{const r=i+n,s=e.y+(e.h-i)/2;for(let n=e.x;e.x+e.w>n;n+=r)t.drawImage(o,n,s,i,i)}t.restore()}function fl(t){const[e,o,n]=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*o+.114*n>128?"#000":"#fff"}function pl(t){return Number.isInteger(t)?t+"":100>Math.abs(t)?1>Math.abs(t)?t.toPrecision(3):t.toFixed(1):t.toFixed(0)}var yl=(t,e,o,n)=>{const i=e.filter(t=>"heatcell"===t.type);t.save();try{for(const e of i){const o=e.style;null!=o?.opacity&&(t.globalAlpha=o.opacity),t.fillStyle=e.fill,t.fillRect(e.x,e.y,e.w,e.h);const n=Math.max(0,o?.strokeWidth??1);if(n>0&&(t.strokeStyle=qn(t,o?.stroke??"var(--semiotic-surface, #fff)"),t.lineWidth=n,t.strokeRect(e.x,e.y,e.w,e.h)),Zc(t,e),t.globalAlpha=1,e.showValues&&null!=e.value){if(20>e.w||20>e.h)continue;const o=e.valueFormat?e.valueFormat(e.value):pl(e.value),n=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=fl(e.fill),t.font=n+"px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(o,i,r)}}}finally{t.restore()}},gl=(t,e,o,n)=>{for(const o of e){if("candlestick"!==o.type)continue;const e=o;t.save();const i=(e._decayOpacity??1)*(e.style?.opacity??1);1!==i&&(t.globalAlpha=i);const r=qn(t,e.wickColor)||e.wickColor,s=60>n.height,a=s?Math.max(e.wickWidth,2):e.wickWidth,c=()=>{t.beginPath(),t.moveTo(e.x,e.highY),t.lineTo(e.x,e.lowY),t.strokeStyle=r,t.lineWidth=a,t.stroke()};if(s||c(),e.isRange){const o=e.dotRadius??Math.max(2,Math.min(e.bodyWidth/2,.12*n.height));t.fillStyle=r,t.beginPath(),t.arc(e.x,e.highY,o,0,2*Math.PI),t.fill(),t.beginPath(),t.arc(e.x,e.lowY,o,0,2*Math.PI),t.fill()}else if(e.bodyWidth>0){const o=Math.min(e.openY,e.closeY),n=Math.abs(e.openY-e.closeY),i=e.isUp?e.upColor:e.downColor,r=qn(t,i)||i;t.fillStyle=r,t.fillRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1)),t.strokeStyle=r,t.lineWidth=1,t.strokeRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1))}s&&c(),t.restore()}},ml={line:[nl,Uc,il],area:[nl,il],stackedarea:[nl,il],scatter:[il,al],bubble:[il,al],heatmap:[yl],bar:[dl],swarm:[il],waterfall:[(t,e,o,n)=>{dl(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=qn(t,s)||s,t.lineWidth=r?._connectorWidth??1,t.setLineDash([]);for(let e=0;i.length-1>e;e++){const n=i[e],r=i[e+1],s=n.datum,a=r.datum;if(null==s?.cumEnd||null==a?.baseline)continue;const c=o.y(s.cumEnd),l=n.x+n.w,u=r.x;t.beginPath(),t.moveTo(l,c),t.lineTo(u,c),t.stroke()}t.restore()}}],candlestick:[gl],mixed:[nl,Uc,il],custom:[nl,dl,yl,Uc,il,al,(t,e)=>{const o=t.globalAlpha;for(const n of e)"glyph"===n.type&&cl(t,n,n.x,n.y,o);t.globalAlpha=o},gl]},bl=new Set;function xl(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(n=o)&&"object"==typeof n&&"string"==typeof n.id&&"function"==typeof n.cacheKey&&"function"==typeof n.drawCanvas&&"function"==typeof n.renderStaticSVG?o:void 0;var n}function vl(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;bl.has(o)||(bl.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}function wl(t){const{node:e,index:o,renderMode:n,fallback:i}=t,r=xl(n,e);if(!r)return i();const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?s:(vl(r.id,e.type??"unknown"),i())}function kl(t){const e=[];return t.nodes.forEach((o,n)=>{const i=wl({node:o,index:n,renderMode:t.renderMode,fallback:()=>t.fallback(o,n)});null!=i&&!1!==i&&e.push({node:o,element:i})}),e}import{jsx as Al,jsxs as Sl}from"react/jsx-runtime";function Ml(t){return"string"==typeof t?t:"value"}function _l(t){return null==t?"–":"number"==typeof t?Math.abs(t)>9999?t.toLocaleString():t+"":t instanceof Date?t.toLocaleDateString():t+""}function Pl(t,e){if(!e)return _l(t);try{const o=e(t);return null==o?_l(t):o}catch{return _l(t)}}function Cl(t,e){return"function"==typeof e?e(t):t[e]}function Rl(t,e){if(!t)return[];const o=[];return(Array.isArray(t)?t:[t]).forEach((t,n)=>{const i="string"==typeof t?.y0Accessor?t.y0Accessor:"low",r="string"==typeof t?.y1Accessor?t.y1Accessor:"high";o.push({label:i,accessor:t=>t.bands?.[n]?.y0??(0===n?t.band?.y0:void 0),format:e}),o.push({label:r,accessor:t=>t.bands?.[n]?.y1??(0===n?t.band?.y1:void 0),format:e})}),o}import{jsx as Il,jsxs as Ll}from"react/jsx-runtime";function Tl(t){return null==t?"":"number"==typeof t?Number.isInteger(t)?t+"":t.toFixed(2):t instanceof Date?t.toLocaleString():t+""}function $l({hover:t}){const e=t.data??{},o=e.y??e.value,n=e.x??e.time;if(void 0===o&&void 0===n){const t=Vt(e);if(null!=t.title||t.entries.length>0)return Ll("div",{className:"semiotic-tooltip",style:Zt,children:[null!=t.title&&Il("div",{style:{fontWeight:600,marginBottom:t.entries.length?2:0},children:t.title+""}),t.entries.map(t=>Ll("div",{style:{opacity:.7,fontSize:11},children:[t.key,":"," ",Il("span",{style:{fontWeight:600},children:Tl(t.value)})]},t.key))]})}return Ll("div",{className:"semiotic-tooltip",style:Zt,children:[Il("div",{style:{fontWeight:600,marginBottom:2},children:Tl(o)}),Il("div",{style:{opacity:.7,fontSize:11},children:Tl(n)})]})}function zl(t){const{onObservation:e,datum:o,x:n=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:c=Date.now()}=t;e&&(o?(e({type:"hover",datum:o,x:n,y:i,timestamp:c,chartType:r,chartId:s}),"focus"===a?.type&&e({type:"focus",datum:o,inputType:"touch"===a.inputType?"pointer":a.inputType,timestamp:c,chartType:r,chartId:s})):e({type:"hover-end",timestamp:c,chartType:r,chartId:s}))}function Dl(t){const{onObservation:e,datum:o,x:n=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:c=Date.now()}=t;e&&(o?(e({type:"click",datum:o,x:n,y:i,timestamp:c,chartType:r,chartId:s}),"activate"===a?.type&&e({type:"activate",datum:o,inputType:a.inputType,timestamp:c,chartType:r,chartId:s})):e({type:"click-end",timestamp:c,chartType:r,chartId:s}))}$l.ownsChrome=!0;import{useCallback as El}from"react";import{useCallback as Ol,useRef as Fl}from"react";function Bl(t,e,o){const n=t.byGroup.get(e);let i=0,r=Math.abs(n[0].x-o.x);for(let t=1;n.length>t;t++){const e=Math.abs(n[t].x-o.x);r>e&&(r=e,i=t)}return n[i]._flatIndex}function Nl(t){const e=[];for(const o of t)switch(o.type){case"point":e.push({x:o.x,y:o.y,datum:o.datum,shape:"circle",group:"_default"});break;case"symbol":if(0>=o.size)break;e.push({x:o.x,y:o.y,datum:o.datum,shape:"circle",group:"_default"});break;case"glyph":{if(0>=o.size||null==o.datum)break;const t=Fn(o.glyph,o.size);e.push({x:o.x+t.centerDx,y:o.y+t.centerDy,datum:o.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:"_default"});break}case"line":{const t=o,n=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let o=0;t.path.length>o&&n.length>o;o++)e.push({x:t.path[o][0],y:t.path[o][1],datum:n[o],shape:"circle",group:i});break}case"area":{const t=o,n=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let o=0;t.topPath.length>o&&n.length>o;o++)e.push({x:t.topPath[o][0],y:t.topPath[o][1],datum:n[o],shape:"circle",group:i});break}case"rect":e.push({x:o.x+o.w/2,y:o.y+o.h/2,datum:o.datum,shape:"rect",w:o.w,h:o.h,group:o.group??"_default"});break;case"heatcell":e.push({x:o.x+o.w/2,y:o.y+o.h/2,datum:o.datum,shape:"rect",w:o.w,h:o.h,group:"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}import{jsx as Wl,jsxs as jl}from"react/jsx-runtime";var Yl={top:20,right:20,bottom:30,left:40},Gl=Ta;function ql(t){if(t)return"x"===t.dimension?"pan-y":"y"===t.dimension?"pan-x":"none"}var Xl=me(ge(function(t,e){const{chartType:o,runtimeMode:n,data:i,chunkThreshold:r,chunkSize:s,xAccessor:a,yAccessor:l,accessorRevision:u,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:y,lineDataAccessor:g,curve:m,normalize:b,baseline:x,stackOrder:v,binSize:w,valueAccessor:k,arrowOfTime:A="right",windowMode:S="sliding",windowSize:M=200,timeAccessor:P,xExtent:C,yExtent:R,extentPadding:I=.1,scalePadding:L,sizeRange:T,size:$=[500,300],responsiveWidth:z,responsiveHeight:D,margin:E,className:O,background:F,renderMode:B,lineStyle:N,pointStyle:W,areaStyle:j,barStyle:Y,waterfallStyle:G,swarmStyle:q,barColors:X,colorScheme:V,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:J,lineGradient:tt,areaGroups:et,openAccessor:ot,highAccessor:nt,lowAccessor:it,closeAccessor:rt,candlestickStyle:st,showAxes:at=!0,axes:ct,xLabel:lt,yLabel:ut,yLabelRight:dt,xFormat:ht,yFormat:ft,axisExtent:pt,tickFormatTime:yt,tickFormatValue:gt,hoverAnnotation:mt,tooltipContent:bt,customHoverBehavior:xt,customClickBehavior:vt,onObservation:wt,annotationObservationCallback:kt,chartId:At,enableHover:St,hoverRadius:Mt=30,tooltipMode:_t,annotations:Pt,onAnnotationActivate:Ct,autoPlaceAnnotations:Rt,svgAnnotationRules:It,showGrid:Lt,legend:Tt,legendHoverBehavior:$t,legendClickBehavior:zt,legendHighlightedCategory:Dt,legendIsolatedCategories:Et,legendPosition:Ot,legendLayout:Ft,legendCategoryAccessor:Bt,onCategoriesChange:Wt,backgroundGraphics:Yt,foregroundGraphics:Gt,canvasPreRenderers:qt,svgPreRenderers:Xt,title:Ht,categoryAccessor:Vt,brush:Ut,onBrush:Kt,decay:Zt,pulse:Qt,transition:Jt,animate:te,staleness:ee,frameScheduler:oe,clock:ne,random:ie,seed:re,paused:se=!1,suspendWhenHidden:ae=!0,heatmapAggregation:ge,heatmapXBins:me,heatmapYBins:be,showValues:xe,heatmapValueFormat:ve,marginalGraphics:we,pointIdAccessor:Se,xScaleType:Me,yScaleType:_e,accessibleTable:Pe=!0,description:Ce,summary:Re,linkedCrosshairName:Ie,linkedCrosshairSourceId:Le,customLayout:Te,onLayoutError:$e,layoutConfig:ze,layoutSelection:De}=t,{customHoverBehavior:Ee,customClickBehavior:Oe,hasClickBehavior:Fe}=function({customHoverBehavior:t,customClickBehavior:e,onObservation:o,chartId:n,chartType:i}){return{customHoverBehavior:El((e,r)=>{t?.(e,r),zl({onObservation:o,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:i,chartId:n,context:r})},[n,i,t,o]),customClickBehavior:El((t,r)=>{e?.(t,r),Dl({onObservation:o,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:i,chartId:n,context:r})},[n,i,e,o]),hasClickBehavior:!(!e&&!o)}}({customHoverBehavior:xt,customClickBehavior:vt,onObservation:wt,chartId:At,chartType:"StreamXYFrame"}),Be=ye().replace(/:/g,""),Ne=le(!1),We=le({w:-1,h:-1}),je=le(!1),Ye=Tc({sizeProp:$,responsiveWidth:z,responsiveHeight:D,userMargin:E,marginDefault:Yl,title:Ht,legend:Tt,legendPosition:Ot,animate:te,transitionProp:Jt,frameScheduler:oe,clock:ne,random:ie,seed:re,paused:se,suspendWhenHidden:ae,themeDirtyRef:Ne}),Ge=function(){const[t,e]=wa(!1);return Aa(()=>{e(!0)},[]),t}(),qe=function(){const t=ka(Sa,Ma,_a);return va(t).current}(),{reducedMotionRef:Xe,responsiveRef:He,size:Ve,currentTheme:Ke,transition:Ze,introEnabled:Qe,tableId:Je,rafRef:to,renderFnRef:eo,scheduleRender:oo,frameRuntime:no}=Ye;let io=Ye.margin;if(we){const t=60,e={...Ye.margin};we.top&&t>e.top&&(e.top=t),we.bottom&&t>e.bottom&&(e.bottom=t),we.left&&t>e.left&&(e.left=t),we.right&&t>e.right&&(e.right=t),io=e}const ro=Ve[0]-io.left-io.right,so=Ve[1]-io.top-io.bottom,ao=he(()=>H(i),[i]),co=mt??St,[lo,uo]=ue(0),ho=le(0),[fo,po]=ue(null),yo=Oc(Gt,Ve,io,fo),go=Oc(Yt,Ve,io,fo),mo=le(null),bo=le(null),xo=le(void 0),[vo,wo]=ue(null),ko=le(Gl.primary),Ao=le(function(){let t=-1,e=Ta;return{resolve(o){if(!o)return Ta;const n=Wn;return n===t||(e=function(t){if(!t)return Ta;const e=getComputedStyle(t),o=e.getPropertyValue("--semiotic-border").trim(),n=e.getPropertyValue("--semiotic-text-secondary").trim(),i=e.getPropertyValue("--semiotic-bg").trim(),r=e.getPropertyValue("--semiotic-primary").trim(),s=n||e.getPropertyValue("--text-secondary").trim(),a=e.getPropertyValue("--text-primary").trim(),c=o||e.getPropertyValue("--surface-3").trim(),l=i||e.getPropertyValue("--surface-0").trim();return s||a||o||r?{axisStroke:c||Ta.axisStroke,tickText:s||Ta.tickText,crosshair:s?$a(s,"66"):Ta.crosshair,hoverFill:l?$a(l,"4D"):Ta.hoverFill,hoverStroke:s?$a(s,"99"):Ta.hoverStroke,pointRing:l||Ta.pointRing,primary:r||Ta.primary,background:l||Ta.background}:Ta}(o),t=n),e},invalidate(){t=-1}}}()),So=le(!1),Mo=un(new gn("StreamXYFrame")),[_o,Po]=ue(!1),[Co,Ro]=ue([]),[Io,Lo]=ue([]),To="streaming"===n||["bar","swarm","waterfall"].includes(o),$o=function(t){const e=Pa(t);return function(t,e){if(Object.is(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return Ra(t,e);if(!Ia(t)||!Ia(e))return!1;const o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return!1;for(const n of o){if(!Object.prototype.hasOwnProperty.call(e,n))return!1;const o=t[n],i=e[n];if(!Object.is(o,i))if(Array.isArray(o)&&Array.isArray(i)){if(!Ra(o,i))return!1}else{if(!Ia(o)||!Ia(i))return!1;if(!Ca(o,i))return!1}}return!0}(e.current,t)||(e.current=t),e.current}(he(()=>({chartType:o,runtimeMode:To?"streaming":"bounded",windowSize:M,windowMode:S,arrowOfTime:To?A:"right",extentPadding:I,scalePadding:L,axisExtent:pt,xAccessor:a,yAccessor:l,accessorRevision:u,timeAccessor:To?P:void 0,valueAccessor:k,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:y||(g?"_lineGroup":void 0),categoryAccessor:Vt,lineDataAccessor:g,xScaleType:Me,yScaleType:_e,xExtent:C,yExtent:R,sizeRange:T,binSize:w,normalize:b,baseline:x,stackOrder:v,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:!0===J?{topOpacity:.8,bottomOpacity:.05}:!1===J?void 0:J,areaGroups:et?new Set(et):void 0,lineGradient:tt,openAccessor:ot,highAccessor:nt,lowAccessor:it,closeAccessor:rt,candlestickStyle:st,lineStyle:N,pointStyle:W,areaStyle:j,swarmStyle:q,waterfallStyle:G,colorScheme:V,barColors:X,barStyle:Y,annotations:Pt,decay:Zt,pulse:Qt,transition:Ze,introAnimation:Qe,staleness:ee,clock:no.now,heatmapAggregation:ge,heatmapXBins:me,heatmapYBins:be,showValues:xe,heatmapValueFormat:ve,pointIdAccessor:Se,curve:m,themeCategorical:Ke?.colors?.categorical,themeSemantic:_(Ke),themeSequential:Ke?.colors?.sequential,themeDiverging:Ke?.colors?.diverging,customLayout:Te,onLayoutError:$e,layoutConfig:ze,layoutMargin:io}),[o,To,M,S,A,I,L,pt,a,l,u,P,k,d,h,f,p,y,g,Vt,Me,_e,C,R,T,w,b,x,v,U,K,Z,Q,J,et,tt,ot,nt,it,rt,st,N,W,j,q,G,V,X,Y,Pt,Zt,Qt,Ze,Qe,ee,no.now,ge,me,be,xe,ve,Se,m,Ke,Te,$e,ze,io])),zo=le(null);zo.current||(zo.current=new an($o));const Do=function(t,e,o,n){const i=Nc({accessor:e,onChange:o,readData:n}),r=Nc([]);return i.current={accessor:e,onChange:o,readData:n},Bc(()=>{const{accessor:e,onChange:o,readData:n}=i.current;if(!o||!e)return;const s=function(t,e){if(!e)return[];const o=new Set,n=[];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+"";o.has(r)||(o.add(r),n.push(r))}return n}(t.current?n(t.current):[],e);(function(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(t[o]!==e[o])return!1;return!0})(s,r.current)||(r.current=s,o(s))},[t])}(zo,Bt,Wt,t=>t.getData());!function(t,e,o,n){Mn(()=>{t.current?.updateConfig(e),o.current=!0,n()},[e,n,t,o])}(zo,$o,Ne,oo),function(t,e,o,n){const i=_n(null);Mn(()=>{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):o.current=!0,n())},[e,n,t,o])}(zo,De,Ne,oo);const Eo=le(null);Eo.current||(Eo.current=new Ae(t=>{const e=zo.current;e&&e.ingest(t)&&(Ne.current=!0,oo())},{chunkThreshold:r,chunkSize:s})),de(()=>{Eo.current?.updateChunkOptions({chunkThreshold:r,chunkSize:s})},[r,s]);const Oo=fe(t=>{Eo.current?.push(t)},[]),Fo=fe(t=>{Eo.current?.pushMany(t)},[]),Bo=fe(()=>{Eo.current?.clear(),zo.current?.clear(),Ne.current=!0,oo()},[oo]);pe(e,()=>({push:Oo,pushMany:Fo,remove:t=>{Eo.current?.flush();const e=zo.current?.remove(t)??[];return e.length>0&&(mo.current&&e.some(t=>t===mo.current?.data)&&(mo.current=null,wo(null)),Ne.current=!0,oo()),e},update:(t,e)=>{Eo.current?.flush();const o=zo.current?.update(t,e)??[];return o.length>0&&(Ne.current=!0,oo()),o},clear:Bo,getData:()=>(Eo.current?.flush(),zo.current?.getData()??[]),getScales:()=>zo.current?.scales??null,getExtents:()=>zo.current?.getExtents()??null,getCustomLayout:()=>zo.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>zo.current?.lastCustomLayoutFailure??null}),[Oo,Fo,Bo,oo]),de(()=>{if(i){if(g&&ao.length>0&&"object"==typeof ao[0]&&null!==ao[0]){const t="string"==typeof g?g:"coordinates";if(Array.isArray(ao[0][t])){const e=[];for(const o of ao){const n=o[t];if(Array.isArray(n)){const t=o.label||o.id||o.key;if(null!=t)for(const o of n)e.push({...o,_lineGroup:t});else for(const t of n)e.push(t)}}return void Eo.current?.setBoundedData(e)}}Eo.current?.setBoundedData(ao)}},[i,ao,g]);const{canvasRef:No,interactionCanvasRef:Wo}=function(t,e){return function(t){const{cancelRender:e,dirtyRef:o,frameRuntime:n,manageFrameRuntime:i,scheduleRender:r}=t,s=zc(null),a=zc(null),c=zc(!1);return function(t){const{hydrated:e,wasHydratingFromSSR:o,storeRef:n,dirtyRef:i,renderFnRef:r,cancelRender:s,cleanup:a}=t;Aa(()=>{const t=n.current;e&&o&&t?.cancelIntroAnimation?.(),!o&&t?.sceneNodes&&t.sceneNodes.length>0&&t?.markStylePaintPending?t.markStylePaintPending():i.current=!0,s?.(),r.current()},[e,o]);const c=va(a);c.current=a,ba(()=>()=>c.current?.(),[])}({hydrated:t.hydrated,wasHydratingFromSSR:t.wasHydratingFromSSR,storeRef:t.storeRef,dirtyRef:t.dirtyRef,renderFnRef:t.renderFnRef,cancelRender:t.cancelRender,cleanup:t.cleanup}),$c(()=>{if(!1!==i)return n.subscribe(()=>{n.isActive?(o.current=!0,r()):e()})},[e,o,n,i,r]),$c(()=>{!c.current&&(c.current=!0,t.skipInitialCanvasPaintInvalidation)||(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})}(Ye,{storeRef:zo,dirtyRef:Ne,hydrated:Ge,wasHydratingFromSSR:qe,cleanup:()=>Eo.current?.clear(),canvasPaintDependencies:[o,ro,so,at,F,Yt,N,B,qt,oo]}),{hoverHandlerRef:jo,hoverLeaveRef:Yo,onPointerMove:Go,onPointerLeave:qo}=Ye;jo.current=t=>{if(!co)return;const e=No.current;if(!e)return;const n=e.getBoundingClientRect(),i=t.clientX-n.left-io.left,r=t.clientY-n.top-io.top;if(0>i||i>ro||0>r||r>so)return void(mo.current&&(mo.current=null,bo.current=null,wo(null),Ee&&(Ee(null),Ne.current=!0),oo()));const s=zo.current;if(!s||0===s.scene.length)return;const c=Nt(Mt,t.pointerType),l=mi(s.scene,i,r,c,s.quadtree,s.maxPointRadius),u="multi"===_t,d=()=>{mo.current&&(mo.current=null,bo.current=null,wo(null),Ee&&Ee(null),oo())};if(!l&&!u)return void d();const h=u||!l?i:l.x,f=u||!l?r:l.y,p=l?.datum?Ue(l.datum,s.resolvedRibbons):{},y=s.scales?.x?.invert,g="function"==typeof y?y(h):void 0;let m=jt(p,h,f,null!=g?{xValue:g,xPx:h}:void 0);if(u&&s.scene.length>0&&s.scales){const t=function(t,e,o=30){const n=[];for(const i of t)if("line"===i.type){const t=i;if(2>t.path.length)continue;const r=bi(gi(t.path,t.curve),e,o);if(null===r)continue;const s=Ci(t.path,e);n.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=gi(t.topPath,t.curve),s=gi(t.bottomPath,t.curve),a=bi(r,e,o);if(null===a)continue;const c=bi(s,e,o),l=Ci(t.topPath,e);n.push({node:i,datum:Array.isArray(t.datum)&&t.datum[l]?t.datum[l]:t.datum,x:t.topPath[l][0],y:a,y0:c??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 n}(s.scene,h,Math.max(c,ro));if(t.length>0){const e=s.scales.y.invert,n=ko.current,i=y?y(h):h;if(l)m.xValue=i,m.xPx=h;else{const t={xValue:i};"string"==typeof a&&(t[a]=i),m=jt(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"===o&&null!=r?i-r:i,valuePx:t.y,color:t.color||n,datum:Ue(t.datum,s.resolvedRibbons)}})}}l||m.allSeries?.length?(mo.current=m,bo.current=l?.node??null,wo(m),Ee&&(Ee(m),Ne.current=!0),oo()):d()},Yo.current=()=>{mo.current&&(mo.current=null,bo.current=null,wo(null),Ee&&(Ee(null),Ne.current=!0),oo())};const Xo=le(()=>{});Xo.current=t=>{if(c(t.target))return;if(!Oe)return;const e=No.current;if(!e)return;const o=e.getBoundingClientRect(),n=t.clientX-o.left-io.left,i=t.clientY-o.top-io.top;if(0>n||n>ro||0>i||i>so)return void Oe(null);const r=zo.current;if(!r||0===r.scene.length)return void Oe(null);const s=Nt(Mt,xo.current),a=mi(r.scene,n,i,s,r.quadtree,r.maxPointRadius);if(!a)return void Oe(null);const l=a.datum||{},u=r.scales?.x?.invert,d="function"==typeof u?u(a.x):void 0;var h;Oe(jt(l,a.x,a.y,null!=d?{xValue:d,xPx:a.x}:void 0),{type:"activate",inputType:(h=xo.current,"touch"===h?"touch":"pointer")})};const Ho=fe(t=>Xo.current(t),[]),{kbFocusIndexRef:Vo,focusedNavPointRef:Uo,onKeyDown:Ko}=(Zo={storeRef:zo,hoverRef:mo,hoveredNodeRef:bo,setHoverPoint:wo,customHoverBehavior:Ee,customClickBehavior:Oe,scheduleRender:oo},function({storeRef:t,hoverRef:e,hoveredNodeRef:o,setHoverPoint:n,customHoverBehavior:i,customClickBehavior:r,scheduleRender:s,extractPoints:a,toHover:c}){const l=Fl(-1),u=Fl(null),d=Fl(null),h=Ol(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=()=>{l.current=-1,u.current=null,e.current=null,o&&(o.current=null),n(null),i(null),s()};if(0===f.scene.length)return void(0>l.current||p());let y;if(d.current?.version===f.version)y=d.current.graph;else{const t=a(f.scene);if(0===t.length)return void(0>l.current||p());y=function(t){const e=new Map;for(const o of t){const t=o.group??"_default";let n=e.get(t);n||(n=[],e.set(t,n)),n.push(o)}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 o=Array.from(e.keys()).sort((t,o)=>{const n=e.get(t),i=e.get(o);return(n.length>0?n[0].y:0)-(i.length>0?i[0].y:0)}),n=Array.from(e.values()).flat();n.sort((t,e)=>t.x-e.x||t.y-e.y);const i=new Map;for(let t=0;n.length>t;t++){n[t]._flatIndex=t;const e=n[t].datum?.id;null!=e&&i.set(e+"",t)}return{flat:n,groups:o,byGroup:e,idToIdx:i}}(t),d.current={version:f.version,graph:y}}let g=l.current;if(y.flat.length>g||(p(),g=-1),("Enter"===h.key||" "===h.key)&&g>=0)return h.preventDefault(),void r(c(y.flat[g],f),{type:"activate",inputType:"keyboard"});if(0>g){if("Escape"===h.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(h.key))return;h.preventDefault(),l.current=0;const t=y.flat[0];u.current=t;const o=c(t,f);return e.current=o,n(o),i(o,{type:"focus",inputType:"keyboard"}),void s()}const m=function(t,e,o){const{group:n,indexInGroup:i}=e,r=o.byGroup.get(n);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=o.groups.indexOf(n);return o.groups.length-1>t?Bl(o,o.groups[t+1],r[i]):e.flatIndex}case"ArrowUp":{const t=o.groups.indexOf(n);return t>0?Bl(o,o.groups[t-1],r[i]):e.flatIndex}case"PageDown":return Math.min(e.flatIndex+Math.max(1,Math.floor(.1*o.flat.length)),o.flat.length-1);case"PageUp":return Math.max(e.flatIndex-Math.max(1,Math.floor(.1*o.flat.length)),0);case"Home":return 0;case"End":return o.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 o=Math.max(0,Math.min(e,t.flat.length-1)),n=t.flat[o];return{flatIndex:o,group:n.group??"_default",indexInGroup:n._groupIndex??0}}(y,g),y);if(null===m)return;if(h.preventDefault(),0>m)return void p();l.current=m;const b=y.flat[m];u.current=b;const x=c(b,f);e.current=x,n(x),i(x,{type:"focus",inputType:"keyboard"}),s()},[r,i,a,e,o,s,n,t,c]);return{kbFocusIndexRef:l,focusedNavPointRef:u,onKeyDown:h}}({...Zo,extractPoints:Nl,toHover:(t,e)=>function(t){return{data:t.datum||{},x:t.x,y:t.y,__semioticHoverData:!0}}({...t,datum:Ue(t.datum,e.resolvedRibbons)})}));var Zo;const Qo=fe(t=>{xo.current=t.pointerType,Vo.current=-1,Uo.current=null,Go(t)},[Uo,Vo,Go]),Jo=fe(t=>{xo.current="mouse",Vo.current=-1,Uo.current=null,Go({clientX:t.clientX,clientY:t.clientY,pointerType:"mouse"})},[Uo,Vo,Go]),tn=fe(t=>{xo.current=t.pointerType},[]);eo.current=()=>{if(to.current=null,!no.isActive)return;const t=No.current,e=Wo.current;if(!t||!e)return;const n=zo.current;if(!n)return;const i=no.now(),r=n.advanceTransition(Xe.current?i+1e6:i),s=!Xe.current&&r,c=We.current.w!==ro||We.current.h!==so,u=Ne.current||r||c,d=n.consumeStylePaintPending();let h=!1;const f=n.getLastUpdateResult(),p=Mo.current.beforeCompute(f,s);!u||s&&!c||(n.computeScene({width:ro,height:so}),We.current={w:ro,h:so},h=!0,Do()),Mo.current.afterCompute(p,h,c);const y=function(t,e,o,n){const i=n.current,r=!0===t.lastCustomLayoutFailure?.preservedLastGoodScene,s=!r&&t.hasActivePulsesAt(e),a=!(o||r||!s&&!i)&&t.refreshPulse(e);return n.current=s,{changed:a,pending:s}}(n,i,h,je),g=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=Ao.current.resolve(t);ko.current=m.primary;const b=$i(ee,n.lastIngestTime>0?i-n.lastIngestTime:0),x=ee&&b.isStale;if(u||d||y.changed){const e=Fc(t,Ve,io,g);if(e){if(e.clearRect(-io.left,-io.top,Ve[0],Ve[1]),ee&&1>b.alpha&&(e.globalAlpha=b.alpha),function(t,e){const{background:o,hasBackgroundGraphics:n=!1,themeBackground:i="",x:r=0,y:s=0,width:a,height:c}=e,l=La({background:o,hasBackgroundGraphics:n,themeBackground:i});if(!l)return!1;const u=qn(t,l);u&&(t.fillStyle=u,t.fillRect(r,s,a,c))}(e,{background:F,hasBackgroundGraphics:!!Yt,themeBackground:m.background,x:-io.left,y:-io.top,width:Ve[0],height:Ve[1]}),e.save(),"function"==typeof e.rect&&(e.beginPath(),e.rect(0,0,ro,so),e.clip()),qt&&n.scales)for(const t of qt)e.save(),t(e,n.scene,n.scales,{width:ro,height:so}),e.restore();const t=Te?ml.custom:ml[o];!function(t){const{context:e,nodes:o,renderMode:n,pixelRatio:i,paintBuiltIn:r}=t;if(!n||"sketchy"===n)return void r(o);let s=[];const a=()=>{s.length&&(r(s),s=[])};for(const t of o){const o=xl(n,t);if(!o){s.push(t);continue}let c;a(),e.save();try{c=o.drawCanvas({context:e,node:t,style:t.style??{},pixelRatio:i})}finally{e.restore()}c||(vl(o.id,t.type??"unknown"),r([t]))}a()}({context:e,nodes:n.scene,renderMode:B,pixelRatio:g,paintBuiltIn:o=>{if(t&&n.scales)for(const i of t)i(e,o,n.scales,{width:ro,height:so})}}),e.restore(),ee&&1>b.alpha&&(e.globalAlpha=1)}}const v=!!(co&&mo.current&&n.scales),w=!!(bo.current&&Array.isArray(mt)&&mt.some(t=>t&&"object"==typeof t&&"highlight"===t.type)),k=v||w;if(k||So.current){const t=Fc(e,Ve,io,g);if(t&&(t.clearRect(-io.left,-io.top,Ve[0],Ve[1]),v&&mo.current&&function(t,e,o,n,i,r,s){if(!1===i.crosshair)return;const a=e.allSeries,c=a&&a.length>0,l=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(c?l:e.x,0),t.lineTo(c?l:e.x,n),t.stroke(),c||(t.beginPath(),t.moveTo(0,e.y),t.lineTo(o,e.y),t.stroke()),t.restore(),c){t.lineWidth=2,t.strokeStyle=s.pointRing;for(const e of a)null!=e.valuePx&&(t.beginPath(),t.arc(l,e.valuePx,4,0,2*Math.PI),t.fillStyle=e.color||s.primary,t.fill(),t.stroke())}else{const o=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 o="string"==typeof e.fill?e.fill:null;return"line"===t.type||"area"===t.type?e.stroke||o||null:o||e.stroke||null}(r)||s.primary;t.beginPath(),t.arc(e.x,e.y,4,0,2*Math.PI),t.fillStyle=o,t.fill(),t.strokeStyle=s.pointRing,t.lineWidth=2,t.stroke()}}(t,mo.current,ro,so,"object"==typeof co?co:{},bo.current,m),w&&bo.current&&Array.isArray(mt))){const e=mt.find(t=>t&&"object"==typeof t&&"highlight"===t.type);e&&function(t,e,o,n,i){if(!o)return;const r="group"in o?o.group:void 0;if(void 0!==r)for(const o of e){if("line"!==o.type)continue;if(o.group!==r)continue;if(2>o.path.length)continue;const e="function"==typeof n.style?o.datum?n.style(o.datum):{}:n.style||{};t.save(),t.beginPath(),t.moveTo(o.path[0][0],o.path[0][1]);for(let e=1;o.path.length>e;e++)t.lineTo(o.path[e][0],o.path[e][1]);t.strokeStyle=e.stroke||o.style.stroke||i.primary,t.lineWidth=e.strokeWidth||(o.style.strokeWidth||2)+2,t.globalAlpha=e.opacity??1,t.stroke(),t.restore()}}(t,n.scene,bo.current,e,m)}So.current=k}u&&t&&t.setAttribute("aria-label",Xa(n.scene,o+" chart"));const A=Ne.current;if(Ne.current=A&&s&&!h,A&&n.scales){const t=t=>"object"==typeof t&&null!==t&&"function"==typeof t.valueOf?t.valueOf():t;if((!fo||t(fo.x.domain()[0])!==t(n.scales.x.domain()[0])||t(fo.x.domain()[1])!==t(n.scales.x.domain()[1])||t(fo.y.domain()[0])!==t(n.scales.y.domain()[0])||t(fo.y.domain()[1])!==t(n.scales.y.domain()[1])||fo.x.range()[0]!==n.scales.x.range()[0]||fo.x.range()[1]!==n.scales.x.range()[1]||fo.y.range()[0]!==n.scales.y.range()[0]||fo.y.range()[1]!==n.scales.y.range()[1])&&po(n.scales),we){const t=n.getData(),e="function"==typeof a?a:t=>t[a||"x"],o="function"==typeof l?l:t=>t[l||"y"];Ro(t.map(t=>e(t)).filter(t=>"number"==typeof t&&isFinite(t))),Lo(t.map(t=>o(t)).filter(t=>"number"==typeof t&&isFinite(t)))}}!((Pt&&Pt.length>0||Te)&&(h||s))||!h&&33>i-ho.current||(uo(t=>t+1),ho.current=i),ee?.showBadge&&Po(!!x),(s||null!=n.activeTransition||y.pending)&&oo()},function(t,e,o,n,i,r){const s=Ii("fresh");Ri(()=>{if(!t)return;const a=setInterval(()=>{const a=e.current;if(!a||0===a.lastIngestTime)return;const c="undefined"!=typeof performance?performance.now():Date.now(),l=$i(t,c-a.lastIngestTime);l.band===s.current&&l.isStale===i||(s.current=l.band,l.isStale!==i&&r(l.isStale),o.current=!0,n())},1e3);return()=>clearInterval(a)},[t,i,n,e,r,o])}(ee,zo,Ne,oo,_o,Po);const en=he(()=>{if(ht||yt)return;const t=zo.current;return t?.xIsDate&&fo?Gc(fo.x.domain()):void 0},[ht,yt,fo]),on=ht||yt||en,nn=co&&vo?bt?bt(vo):Wl($l,{hover:vo}):null,rn=nn?Wl(fc,{x:vo.x,y:vo.y,containerWidth:ro,containerHeight:so,margin:io,className:"stream-frame-tooltip",children:nn}):null,sn=Uo.current,cn=Wl(uc,{active:Vo.current>=0,hoverPoint:vo,margin:io,size:Ve,shape:sn?.shape,width:sn?.w,height:sn?.h}),ln=Wc(a,P,"__semiotic_resolvedX","__semiotic_resolvedTime"),dn=Wc(l,k,"__semiotic_resolvedY","__semiotic_resolvedValue"),hn=ln.key,fn=dn.key,pn=function(t,e,o){return n=>{if(!n||!o||!t.fn&&!e.fn)return n;let i=!1;const r=n.map(o=>{const n=t.fn&&t.key&&!(t.key in o),r=e.fn&&e.key&&!(e.key in o);if(!n&&!r)return o;i=!0;const s={...o};return n&&(s[t.key]=t.fn(o)),r&&(s[e.key]=e.fn(o)),s});return i?r:n}}(ln,dn,Pt&&Pt.length>0||!1);if(ma||!Ge&&qe){const t=zo.current;t&&i&&(t.ingest({inserts:ao,bounded:!0}),t.computeScene({width:ro,height:so}));const e=t?.scene??[],o=t?.scales??null,n=Oc(Gt,Ve,io,o),r=Oc(Yt,Ve,io,o),s=on||(()=>{if(t?.xIsDate&&o)return Gc(o.x.domain())})();return jl("div",{ref:He,className:"stream-xy-frame"+(O?" "+O:""),role:"img","aria-label":Ce||("string"==typeof Ht?Ht:"XY chart"),style:{position:"relative",width:z?"100%":Ve[0],height:D?"100%":Ve[1]},children:[Wl(sc,{summary:Re}),jl("svg",{xmlns:"http://www.w3.org/2000/svg",width:Ve[0],height:Ve[1],style:{position:"absolute",left:0,top:0},children:[Wl("g",{transform:`translate(${io.left},${io.top})`,children:r}),jl("g",{transform:`translate(${io.left},${io.top})`,children:[F&&Wl("rect",{x:0,y:0,width:ro,height:so,fill:F}),Xt&&o&&Xt.map((t,n)=>Wl(ce.Fragment,{children:t(e,o,{width:ro,height:so})},"svgpre-"+n)),e.map((t,e)=>wl({node:t,index:e,renderMode:B,fallback:()=>ga(t,e,Be)})).filter(Boolean)]})]}),Wl(Os,{width:ro,height:so,totalWidth:Ve[0],totalHeight:Ve[1],margin:io,scales:o,showAxes:at,axes:ct,xLabel:lt,yLabel:ut,yLabelRight:dt,xFormat:s,yFormat:ft||gt,axisExtent:pt,showGrid:Lt,title:Ht,legend:Tt,legendHoverBehavior:$t,legendClickBehavior:zt,legendHighlightedCategory:Dt,legendIsolatedCategories:Et,legendPosition:Ot,legendLayout:Ft,foregroundGraphics:xn(n,Sn(zo.current?.customLayoutOverlays,De??null)),marginalGraphics:we,xValues:[],yValues:[],annotations:Pt,onAnnotationActivate:Ct,onObservation:kt??wt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Rt,svgAnnotationRules:It,annotationFrame:0,xAccessor:hn,yAccessor:fn,annotationData:pn(zo.current?.getData()),pointNodes:qc(zo.current?.scene),curve:"string"==typeof m?m:void 0,linkedCrosshairName:Ie,linkedCrosshairSourceId:Le})]})}return jl("div",{ref:He,className:"stream-xy-frame"+(O?" "+O:""),role:"group","aria-label":Ce||("string"==typeof Ht?Ht:"XY chart"),tabIndex:0,style:{position:"relative",width:z?"100%":Ve[0],height:D?"100%":Ve[1],overflow:"visible",touchAction:ql(Ut)},onKeyDown:Ko,children:["production"!==process.env.NODE_ENV&&zo.current&&Wl(mn,{store:zo.current,diagnostics:Mo.current}),Pe&&Wl(ac,{tableId:Je}),Pe&&Wl(rc,{scene:zo.current?.scene??[],chartType:o+" chart",tableId:Je,chartTitle:"string"==typeof Ht?Ht:void 0}),Wl(sc,{summary:Re}),Wl(Na,{hoverPoint:vo}),jl("div",{role:"img","aria-label":Ce||("string"==typeof Ht?Ht:"XY chart"),style:{position:"relative",width:"100%",height:"100%"},onPointerMove:co?Qo:void 0,onMouseMove:co?Jo:void 0,onPointerLeave:co?qo:void 0,onMouseLeave:co?qo:void 0,onPointerDown:co||Fe?tn:void 0,onClick:Fe?Ho:void 0,children:[Wl(Ec,{size:Ve,margin:io,children:go}),Wl(zs,{width:ro,height:so,totalWidth:Ve[0],totalHeight:Ve[1],margin:io,scales:fo,showAxes:at,axes:ct,showGrid:Lt,xFormat:on,yFormat:ft||gt,axisExtent:pt}),Wl("canvas",{ref:No,"aria-label":Xa(zo.current?.scene??[],o+" chart"),style:{position:"absolute",left:0,top:0}}),Wl("canvas",{ref:Wo,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),Wl(Os,{width:ro,height:so,totalWidth:Ve[0],totalHeight:Ve[1],margin:io,scales:fo,showAxes:at,axes:ct,xLabel:lt,yLabel:ut,yLabelRight:dt,xFormat:on,yFormat:ft||gt,axisExtent:pt,showGrid:Lt,title:Ht,legend:Tt,legendHoverBehavior:$t,legendClickBehavior:zt,legendHighlightedCategory:Dt,legendIsolatedCategories:Et,legendPosition:Ot,legendLayout:Ft,foregroundGraphics:xn(yo,Sn(zo.current?.customLayoutOverlays,De??null)),marginalGraphics:we,xValues:Co,yValues:Io,annotations:Pt,onAnnotationActivate:Ct,onObservation:kt??wt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Rt,svgAnnotationRules:It,annotationFrame:lo,xAccessor:hn,yAccessor:fn,annotationData:pn(zo.current?.getData()),pointNodes:qc(zo.current?.scene),curve:"string"==typeof m?m:void 0,underlayRendered:!0,canvasObscuresUnderlay:!!La({background:F,hasBackgroundGraphics:!!Yt,themeBackground:Ke?.colors.background}),linkedCrosshairName:Ie,linkedCrosshairSourceId:Le}),(Ut||Kt)&&Wl(ke,{width:ro,height:so,totalWidth:Ve[0],totalHeight:Ve[1],margin:io,dimension:Ut?.dimension??"xy",scales:fo,onBrush:Kt??(()=>{}),binSize:w,snap:Ut?.snap,binBoundaries:Ut?.binBoundaries??("bar"===o?zo.current?.getBinBoundaries():void 0),snapDuring:Ut?.snapDuring,streaming:"streaming"===n}),ee?.showBadge&&Wl(Di,{isStale:_o,position:ee.badgePosition}),cn,rn]})]})}));Xl.displayName="StreamXYFrame";var Hl=Xl;import{useMemo as Vl,useCallback as Ul,useState as Kl,useId as Zl,useEffect as Ql,useRef as Jl}from"react";import{createContext as tu,useContext as eu,useMemo as ou}from"react";import{jsx as nu}from"react/jsx-runtime";var iu=tu(null);function ru(){return eu(iu)}import{createContext as su,useContext as au,useEffect as cu,useId as lu,useLayoutEffect as uu,useMemo as du,useRef as hu,useState as fu,useCallback as pu}from"react";function yu(t){const e=[];for(const[o,n]of Object.entries(t.fields))if("point"===n.type)e.push(t=>n.values.has(t[o]));else{const[t,i]=n.range;e.push(e=>{const n=e[o];return n>=t&&i>=n})}return t=>e.every(e=>e(t))}function gu(t,e){let o=t.get(e);return o||(o={name:e,resolution:"union",clauses:new Map},t.set(e,o)),o}function mu(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 o of t.values)if(!e.values.has(o))return!1;return!0}return!1}var[bu,xu]=s(t=>({selections:new Map,setClause(e,o){t(t=>{const n=t.selections.get(e),i=n?.clauses.get(o.clientId);if(i&&function(t,e){if(t.clientId!==e.clientId||t.type!==e.type)return!1;const o=Object.entries(t.fields);if(o.length!==function(t){let e=0;for(const o in t)e++;return e}(e.fields))return!1;for(const[t,n]of o){const o=e.fields[t];if(!o||!mu(n,o))return!1}return!0}(i,o))return{};const r=new Map(t.selections),s=gu(r,e),a=new Map(s.clauses);return a.set(o.clientId,o),r.set(e,{...s,clauses:a}),{selections:r}})},clearClause(e,o){t(t=>{const n=t.selections.get(e);if(!n||!n.clauses.has(o))return{};const i=new Map(t.selections),r=new Map(n.clauses);return r.delete(o),i.set(e,{...n,clauses:r}),{selections:i}})},setResolution(e,o){t(t=>{const n=t.selections.get(e);if(n?.resolution===o)return{};const i=new Map(t.selections),r=gu(i,e);return i.set(e,{...r,resolution:o}),{selections:i}})},clearSelection(e){t(t=>{const o=t.selections.get(e);if(!o||0===o.clauses.size)return{};const n=new Map(t.selections);return n.set(e,{...o,clauses:new Map}),{selections:n}})}}));import{useId as vu,useMemo as wu,useCallback as ku}from"react";function Au(t){const e=vu(),o=t.clientId||e,{name:n}=t,i=xu(t=>t.selections.get(n)),r=xu(t=>t.setClause),s=xu(t=>t.clearClause),a=wu(()=>!!i&&i.clauses.size>0,[i]);return{predicate:wu(()=>i&&0!==i.clauses.size?function(t,e){const o=[];for(const[n,i]of t.clauses)"crossfilter"===t.resolution&&n===e||o.push(yu(i));return 0===o.length?()=>!0:"intersect"===t.resolution?t=>o.every(e=>e(t)):t=>o.some(e=>e(t))}(i,o):()=>!0,[i,o]),isActive:a,selectPoints:ku(t=>{const e={};let i=!1;for(const[o,n]of Object.entries(t))e[o]={type:"point",values:new Set(n)},i=!0;i&&r(n,{clientId:o,type:"point",fields:e})},[o,n,r]),selectInterval:ku(t=>{const e={};let i=!1;for(const[o,n]of Object.entries(t))e[o]={type:"interval",range:n},i=!0;i&&r(n,{clientId:o,type:"interval",fields:e})},[o,n,r]),clear:ku(()=>{s(n,o)},[s,n,o]),clientId:o}}import{jsx as Su,jsxs as Mu}from"react/jsx-runtime";var _u=su(!1);su(!1);var Pu=su(null),Cu="undefined"==typeof window?cu:uu;import*as Ru from"react";import{jsx as Iu,jsxs as Lu}from"react/jsx-runtime";function Tu(t,e,o){const n=t.xValue??e?.[o];if(null==n)return null;const i=Number(n);return Number.isFinite(i)?i:null}function $u(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 zu(t){if(!t)return!1;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1}Ru.createContext(void 0);var Du=[];function Eu(){const t=z(t=>t.theme),e=t?.colors?.categorical;return e&&e.length>0?e:void 0}function Ou(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=Ct(o,n);if(t)return t}let r;if(Array.isArray(o))r=o;else if(e&&e.length>0)r=e;else if("string"==typeof o){const t=vt[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=n?(i.has(n)||i.set(n,i.size),r[i.get(n)%r.length]):r[0]:kt}function Fu({selection:t,linkedHover:e,fallbackFields:o=Du,unwrapData:n=!1,onObservation:i,chartType:r,chartId:s,onClick:a,hoverHighlight:c,colorByField:l,mobileInteraction:u}){const d=Zl(),h=Vl(()=>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,o),[e,o]),f=Vl(()=>"series"===h?.mode?[h.seriesField||l||o[0]].filter(t=>!!t):h?.fields||o,[h,l,o]),p=Au({name:t?.name||"__unused__",fields:f}),y=function(t){const e=t.name||"hover",{fields:o}=t,{predicate:n,isActive:i,selectPoints:r,clear:s}=Au({name:e,fields:o});return{onHover:ku(t=>{if(!t)return void s();const e={};for(const n of o){const o=t[n];void 0!==o&&(e[n]=[o])}(function(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1})(e)&&r(e)},[o,r,s]),predicate:n,isActive:i}}({name:h?.name||"hover",fields:f}),g=m(t=>t.pushObservation),b=Ul(t=>{i?.(t),g?.(t)},[i,g]),x=t?{isActive:p.isActive,predicate:p.predicate}:null,[v,w]=Kl(null),k=Jl(!1),A=l||o[0],S=Vl(()=>{if(!c||null==v||!A)return null;const t=v,e=A;return{isActive:!0,predicate:o=>("string"==typeof o[e]?o[e]:(o[e]??"")+"")===t}},[c,v,A]),M=Ul((t,o)=>{const n=!t&&k.current&&!!u?.enabled&&u.tapToLockTooltip;if(e)if(t){let e=t.data||t.datum||t;if(Array.isArray(e)&&(e=e[0]),"x-position"===h?.mode&&h.xField){const o=Tu(t,e,h.xField);null!=o&&function(t,e,o){const n=hs.positions.get(t);n?.locked||n&&n.xValue===e&&n.sourceId===o||(hs={positions:new Map(hs.positions).set(t,{xValue:e,sourceId:o})},ps())}(h.name||"hover",o,d)}"x-position"!==h?.mode&&y.onHover(e)}else"x-position"!==h?.mode||n||ys(h.name||"hover",d),"x-position"===h?.mode||n||y.onHover(null);if(c&&A)if(t){let e=t.data||t.datum||t;Array.isArray(e)&&(e=e[0]);const o=e?.[A];w(null!=o?o+"":null)}else n||w(null);(i||g)&&zl({onObservation:b,datum:t?$u(t):null,x:t?.x,y:t?.y,chartType:r||"unknown",chartId:s,context:o})},[e,y,h,d,i,r,s,g,b,c,A,u]),_=Ul((o=!0)=>{k.current=!1,e&&"x-position"!==h?.mode&&y.onHover(null),t&&u?.tapToSelect&&p.clear(),o&&c&&w(null),"x-position"===h?.mode&&(gs(h.name||"hover",d),ys(h.name||"hover",d))},[e,h,y,t,u,p,c,d]),P=Ul((o,n)=>{const l=!!u?.enabled&&(u.tapToLockTooltip||u.tapToSelect),m=!!u?.enabled&&"backgroundTap"===u.clearSelection;if("x-position"===h?.mode&&h.xField&&o){let t=o.data||o.datum||o;Array.isArray(t)&&(t=t[0]);const e=Tu(o,t,h.xField);null!=e&&function(t,e,o){const n=hs.positions.get(t);if(n?.locked){const e=new Map(hs.positions);return e.delete(t),hs={positions:e},ps(),!1}hs={positions:new Map(hs.positions).set(t,{xValue:e,sourceId:o,locked:!0})},ps()}(h.name||"hover",e,d)}if(l)if(o){k.current=!0;const n=$u(o);if(e&&"x-position"!==h?.mode&&y.onHover(n),t&&u?.tapToSelect&&f.length>0){const t={};for(const e of f){const o=n[e];void 0!==o&&(t[e]=[o])}zu(t)&&p.selectPoints(t)}if(c&&A){const t=n?.[A];w(null!=t?t+"":null)}}else m&&_();if(o||m){if(o&&a){let t=o.data||o.datum||o;Array.isArray(t)&&(t=t[0]),a(t,{x:o.x??0,y:o.y??0})}(i||g)&&Dl({onObservation:b,datum:o?$u(o):null,x:o?.x,y:o?.y,chartType:r||"unknown",chartId:s,context:n})}},[a,i,g,b,r,s,h,d,u,e,y,t,p,f,c,A,_]);return Ql(()=>{if(!u?.enabled||"undefined"==typeof document)return;const t=t=>{"Escape"===t.key&&k.current&&_()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[u?.enabled,_]),Ql(()=>()=>{k.current&&_(!1)},[_]),Ql(()=>{if("x-position"!==h?.mode)return;const t=h.name||"hover";return()=>{gs(t,d),ys(t,d)}},[h?.mode,h?.name,d]),{activeSelectionHook:x,hoverSelectionHook:S,customHoverBehavior:M,customClickBehavior:P,crosshairSourceId:d}}function Bu({data:t,colorBy:e,colorScale:o,showLegend:n,legendPosition:i="right",userMargin:r,defaults:s={top:50,bottom:60,left:70,right:40},categories:a,additionalLegend:c}){const l=au(_u),u=null!==au(Pu),d=void 0!==n?n:!l&&!!e,h=!!e&&(d||u),f=Vl(()=>{if(!h)return[];if(void 0!==a)return a;const o=new Set;for(const n of t){const t="function"==typeof e?e(n):n[e];null!=t&&o.add(t+"")}return Array.from(o)},[a,e,t,h]);!function(t){const e=au(Pu),o=lu(),n=function(t){const e=new Set,o=[];for(const n of t)e.has(n)||(e.add(n),o.push(n));return o}(t),i=hu([]);(function(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(t[o]!==e[o])return!1;return!0})(i.current,n)||(i.current=n);const r=i.current;Cu(()=>{if(e)return()=>e.unregisterCategories(o)},[e,o]),Cu(()=>{e&&e.registerCategories(o,r)},[e,o,r])}(u&&e?f:[]);const p=Vl(()=>{if(!d||!e)return;const n=function({data:t,colorBy:e,colorScale:o,getColor:n,strokeColor:i,strokeWidth:r,categories:s}){return{legendGroups:[{styleFn:t=>{const e=t.color||"#333",o={fill:e,stroke:e};return void 0!==i&&(o.stroke=i),void 0!==r&&(o.strokeWidth=r),o},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?n(s,e,o):o?o(i):St[r%St.length];return{label:i+"",color:a}}),label:""}]}}({data:t,colorBy:e,colorScale:o,getColor:Pt,categories:f});return 0!==n.legendGroups.reduce((t,e)=>t+e.items.length,0)?n:void 0},[d,e,t,o,f]),y=Vl(()=>Zi(p,c),[p,c]),g=Vl(()=>{const t="number"==typeof r?{top:r,bottom:r,left:r,right:r}:r??{},e=e=>{const o=t[e];return"number"==typeof o?o:s[e]},o={top:e("top"),right:e("right"),bottom:e("bottom"),left:e("left")},n=e=>"number"==typeof t[e];return y&&("right"===i&&!n("right")&&110>o.right?o.right=110:"left"===i&&!n("left")&&110>o.left?o.left=110:"top"===i&&!n("top")&&50>o.top?o.top=50:"bottom"===i&&!n("bottom")&&80>o.bottom&&(o.bottom=80)),o},[s,r,y,i]);return{legend:y,margin:g,legendPosition:i}}import{jsx as Nu,jsxs as Wu}from"react/jsx-runtime";function ju({componentName:t,message:e,diagnosticHint:o,width:n,height:i}){return Nu("div",{role:"alert",style:{width:n,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:Wu("div",{style:{textAlign:"center",maxWidth:400},children:[Nu("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:t}),Nu("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:e}),o&&Nu("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:o})]})})}import*as Yu from"react";import{jsx as Gu}from"react/jsx-runtime";var qu=class extends Yu.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:Gu(ju,{componentName:"ChartErrorBoundary",message:e.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}};import{jsx as Xu}from"react/jsx-runtime";var Hu="undefined"!=typeof process&&"production"!==process.env?.NODE_ENV;function Vu({componentName:t,width:e,height:o,children:n}){return Xu(qu,{fallback:n=>Xu(ju,{componentName:t,message:n.message,width:e,height:o}),children:n})}var Uu={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"},Ku={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};function Zu(t,e,o,n){if(!Hu)return;if(!e||0===e.length)return;if("string"!=typeof n)return;const i=e[0];if(!i||"object"!=typeof i)return;if(n in i)return;const r=Object.keys(i).join(", ");console.warn(`[semiotic] ${t}: ${o} "${n}" not found in data. Available keys: ${r}`)}import{useCallback as Qu,useMemo as Ju,useState as td}from"react";import{useMemo as ed}from"react";import{useImperativeHandle as od,useRef as nd}from"react";import{useMemo as id}from"react";import{useEffect as rd,useMemo as sd,useRef as ad,useState as cd}from"react";var ld=null;async function ud(){return ld||(ld=await import("./chunk-statisticalOverlays-T77OKLDY.module.min.js")),ld}var dd="__semiotic_resolvedX",hd="__semiotic_resolvedY";import{jsx as fd}from"react/jsx-runtime";function pd(t,e){if(null==e)return t;const o=t.trim(),n=o.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(n){const t=n[1],o=3===t.length?t.split("").map(t=>t+t).join(""):t;return`rgba(${parseInt(o.slice(0,2),16)}, ${parseInt(o.slice(2,4),16)}, ${parseInt(o.slice(4,6),16)}, ${e})`}if(o.startsWith("rgba(")){const t=o.lastIndexOf(","),n=o.lastIndexOf(")");if(-1!==t&&n>t)return`${o.slice(0,t+1)} ${e})`}return o.startsWith("rgb(")?o.replace(/^rgb\(/,"rgba(").replace(/\)$/,`, ${e})`):t}function yd(t){return t.filter(t=>Number.isFinite(t.at)).map(t=>({offset:1-Math.max(0,Math.min(100,t.at))/100,color:pd(t.color,t.opacity)})).sort((t,e)=>t.offset-e.offset)}function gd(t,e,o){return"function"==typeof t?t(o):o[t||e]}function md(t){return t instanceof Date?t.getTime():Number(t)}function bd(t,e){return rt(1===e?.5:t/(e-1))}function xd(t,e,o){const n="function"==typeof e?e(t):t[e??o];if(null==n)return null;if(n instanceof Date)return n.getTime();if("string"==typeof n&&""===n.trim())return null;const i=Number(n);return Number.isFinite(i)?i:null}se(function(t,e){const o=ae(null);!function(t,e){const{variant:o,frameRef:n,overrides:i}=e,r=nd(i);r.current=i,od(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,o)=>t.current?.update(e,o)??[],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 o=Array.isArray(e)?e:[e],n=t.current?.getTopology()?.nodes??[],i=[];for(const e of o){const o=n.find(t=>t.id===e);o&&i.push({...o.data??{},id:e}),t.current?.removeNode(e)}return i},update:(e,o)=>(Array.isArray(e)?e:[e]).flatMap(e=>{const n=t.current?.updateNode(e,o);return n?[{...n,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,o)=>{const n=t.current?.removePoint(e)??[];for(const e of n)t.current?.push(o(e));return n},clear:()=>t.current?.clear(),getData:()=>t.current?.getData()??[],getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}const o=e;return{push:t=>o.current?.pushLine(t),pushMany:t=>o.current?.pushManyLines(t),remove:t=>o.current?.removeLine(t)??[],update:(t,e)=>{const n=o.current?.removeLine(t)??[];for(const t of n)o.current?.pushLine(e(t));return n},clear:()=>o.current?.clear(),getData:()=>o.current?.getLines()??[],getCustomLayout:()=>o.current?.getCustomLayout?.()??null,getLayoutFailure:()=>o.current?.getLayoutFailure?.()??null}}(o,n);return new Proxy(t,{get(t,e,o){if("string"==typeof e){const t=r.current?.[e];if("function"==typeof t)return t}return Reflect.get(t,e,o)},has:(t,e)=>!("string"!=typeof e||!r.current||!(e in r.current))||Reflect.has(t,e)})},[])}(e,{variant:"xy",frameRef:o});const n=W(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,xLabel:t.xLabel,yLabel:t.yLabel,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,responsiveRules:t.responsiveRules},void 0);const{data:i,margin:r,className:s,xFormat:a,yFormat:c,xAccessor:l="x",yAccessor:u="y",areaBy:d,y0Accessor:h,gradientFill:f=!1,semanticGradient:p,lineDataAccessor:y="coordinates",colorBy:g,colorScheme:m,styleRules:x,curve:v="monotoneX",areaOpacity:w=.7,lineGradient:k,showLine:A=!0,lineWidth:S=2,showPoints:M=!1,pointRadius:_=3,tooltip:P,annotations:C,forecast:R,anomaly:I,band:L,xExtent:T,yExtent:$,frameProps:D={},selection:E,linkedHover:O,onObservation:F,onClick:N,hoverHighlight:j,chartId:Y,loading:G,loadingContent:X,emptyContent:V,legendInteraction:U,legendPosition:K,color:Z,stroke:Q,strokeWidth:J,opacity:tt}=t,{width:et,height:ot,enableHover:nt,showGrid:it,showLegend:rt,title:st,description:at,summary:ct,accessibleTable:lt,xLabel:ut,yLabel:dt}=n,ht=re(()=>H(i),[i]),ft=g||d,pt=re(()=>p&&p.length>0?{colorStops:yd(p)}:f,[p,f]);Zu("AreaChart",ht,"xAccessor",l),Zu("AreaChart",ht,"yAccessor",u);const yt=function(t){const{data:e,rawData:o,colorBy:n,colorScheme:i,legendInteraction:r,legendPosition:s,selection:a,linkedHover:c,fallbackFields:l,unwrapData:u=!1,onObservation:d,chartType:h,chartId:f,showLegend:p,legend:y,userMargin:g,marginDefaults:m,onClick:b,hoverHighlight:x,mobileInteraction:v,mobileSemantics:w,loading:k,loadingContent:A,emptyContent:S,width:M,height:_}=t,P=void 0===o,C=Ju(()=>H(e),[e]),[R,I]=td([]),L=Qu(t=>{I(e=>e.length===t.length&&e.every((e,o)=>e===t[o])?e:t)},[]),T="string"==typeof t.colorBy?t.colorBy:void 0,$=Ju(()=>B(v,{width:M,mobileSemantics:w}),[v,M,w]),{activeSelectionHook:D,hoverSelectionHook:E,customHoverBehavior:O,customClickBehavior:F,crosshairSourceId:N}=Fu({selection:a,linkedHover:c,fallbackFields:l,unwrapData:u,onObservation:d,chartType:h,chartId:f,onClick:b,hoverHighlight:x,colorByField:T,mobileInteraction:$}),W=function(t,e){const o="object"==typeof t&&null!==t?t:void 0;if("x-position"===o?.mode)return{linkedCrosshairName:o.name||"hover",linkedCrosshairSourceId:e}}(c,N),j=function(t,e,o){const n=ru(),i=Eu();return Vl(()=>{if(!e)return;const r=n??void 0,s=o??(i&&i.length>0?i:void 0)??"category10";if(0!==t.length){if("function"==typeof e){const o=Array.from(new Set(t.map(t=>e(t)+"")));if(r&&zu(r)){const t=Rt(o.map(t=>({_cat:t})),"_cat",s);return e=>r[e]||t(e)}return Rt(o.map(t=>({_cat:t})),"_cat",s)}if(r&&zu(r)){const o=Rt(t,e,s);return t=>r[t]||o(t)}return Rt(t,e,s)}if(r&&zu(r)){const t=Rt([{_:"a"}],"_",s);return e=>r[e]||t(e)}},[t,e,o,n,i])}(C,n,i),Y=Ju(()=>{if(!n)return[];const t=new Set;for(const e of C){const o="function"==typeof n?n(e):e[n];null!=o&&t.add(o+"")}return Array.from(t)},[C,n]),G=Ju(()=>P&&R.length>0?R:Y,[P,R,Y]),q=function(t,e,o){const[n,i]=Kl(null),[r,s]=Kl(new Set),a=Vl(()=>new Set,[]),c=Ul(e=>{"highlight"===t&&i(e?e.label:null)},[t]),l=Ul(e=>{"isolate"===t&&s(t=>{const n=new Set(t);return n.has(e.label)?n.delete(e.label):n.add(e.label),n.size===o.length?new Set:n})},[t,o.length]),u=Vl(()=>{if(!t||"none"===t||!e)return null;const o="string"==typeof e?e:null;return"highlight"===t&&null!=n?{isActive:!0,predicate:t=>(o?t[o]:"function"==typeof e?e(t):null)===n}:"isolate"===t&&r.size>0?{isActive:!0,predicate:t=>{const n=o?t[o]:"function"==typeof e?e(t):null;return r.has(n)}}:null},[t,e,n,r]);return{highlightedCategory:"highlight"===t?n:null,isolatedCategories:"isolate"===t?r:a,onLegendHover:c,onLegendClick:l,legendSelectionHook:u}}(r,n,G),X=Ju(()=>E||(q.legendSelectionHook?q.legendSelectionHook:D),[E,q.legendSelectionHook,D]),V=function(t){const e=z(t=>t.theme.colors.selectionOpacity);return ed(()=>{if(void 0!==t||void 0!==e)return{name:t?.name??"",...t,unselectedOpacity:t?.unselectedOpacity??e}},[t,e])}(a),U=Eu(),K=ru(),Z=Ju(()=>{if(j)return j;if(!n||0===G.length)return;const t=Array.isArray(i)&&i.length>0||"string"==typeof i&&i.length>0?i:U&&U.length>0?U:St,e="__streamCat",o=Rt(G.map(t=>({[e]:t})),e,t);return t=>K?.[t]||o(t)||"#999"},[j,n,G,i,U,K]),{legend:Q,margin:J,legendPosition:tt}=Bu({data:C,colorBy:n,colorScale:Z,showLegend:p,legendPosition:s,userMargin:g,defaults:m,categories:G,additionalLegend:y}),et=Ju(()=>{const t={};return Q&&(t.legend=Q,t.legendPosition=tt),r&&"none"!==r&&(t.legendHoverBehavior=q.onLegendHover,t.legendClickBehavior=q.onLegendClick,t.legendHighlightedCategory=q.highlightedCategory,t.legendIsolatedCategories=q.isolatedCategories),P&&n&&(t.legendCategoryAccessor=n,t.onCategoriesChange=L),t},[Q,tt,r,q.onLegendHover,q.onLegendClick,q.highlightedCategory,q.isolatedCategories,P,n,L]),ot=Array.isArray(o)?H(o):o,nt=function(t,e,o,n){if(!t)return null;if(!1===n)return null;if(null!=n)return Xu("div",{style:{width:e,height:o,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:n});const i=Math.min(5,Math.floor(o/40)),r=Math.max(8,Math.floor(o/(3*i))),s=Math.max(6,Math.floor(o/(2.5*i))),a=Math.floor((o-(i*(r+s)-s))/2);return Xu("div",{style:{width:e,height:o,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:i},(t,o)=>Xu("div",{className:"semiotic-loading-bar",style:{...Ku,position:"absolute",top:a+o*(r+s),left:Math.floor(.1*e),width:30+(37*o+13)%50+"%",height:r,opacity:.5+o%2*.2}},o))})}(k,M,_,A),it=nt?null:function(t,e,o,n){return!1===n||null==t||Array.isArray(t)&&t.length>0?null:Array.isArray(t)?Xu("div",{style:{...Uu,width:e,height:o},children:n||"No data available"}):null}(ot,M,_,S);return{data:C,colorScale:j,allCategories:G,legendState:q,effectiveSelectionHook:X,activeSelectionHook:D,customHoverBehavior:O,customClickBehavior:F,mobileInteraction:$,legend:Q,margin:J,legendPosition:tt,earlyReturn:nt||it||null,legendBehaviorProps:et,crosshairProps:W,resolvedSelection:V}}({data:ht,rawData:i,colorBy:ft,colorScheme:m,legendInteraction:U,legendPosition:K,selection:E,linkedHover:O,fallbackFields:ft?["string"==typeof ft?ft:""]:[],unwrapData:!1,onObservation:F,onClick:N,hoverHighlight:j,mobileInteraction:n.mobileInteraction,mobileSemantics:n.mobileSemantics,chartType:"AreaChart",chartId:Y,showLegend:rt,userMargin:r,marginDefaults:n.marginDefaults,loading:G,loadingContent:X,emptyContent:V,width:et,height:ot}),{effectiveData:gt,statisticalAnnotations:mt}=function(t){const{data:e,xAccessor:o,yAccessor:n,forecast:i,anomaly:r,groupBy:s}=t,a="string"==typeof o?o:dd,c="string"==typeof n?n:hd,l=sd(()=>{if(!i&&!r)return e;const t="function"==typeof o,s="function"==typeof n;return t||s?e.map(e=>{const i={...e};return t&&(i[dd]=o(e)),s&&(i[hd]=n(e)),i}):e},[e,i,r,o,n]),[u,d]=cd(null),[h,f]=cd([]),p=ad(i),y=ad(r);return rd(()=>{if(!i&&!r)return void((p.current||y.current)&&(d(null),f([]),p.current=i,y.current=r));let t=!1;const e=i!==p.current||r!==y.current;if(p.current=i,y.current=r,e&&(d(null),f([])),i){const e=s&&"string"==typeof s&&"object"==typeof i?{...i,_groupBy:s}:i;(async function(...t){return(await ud()).buildForecast(...t)})(l,a,c,e,r).then(e=>{t||(d(e),f(e.annotations))}).catch(()=>{t||(d(null),f([]))})}else r&&async function(...t){return(await ud()).buildAnomalyAnnotations(...t)}(r).then(e=>{t||(d(null),f(e))}).catch(()=>{t||f([])});return()=>{t=!0}},[l,i,r,a,c,s]),{effectiveData:u?u.processedData:e,statisticalAnnotations:h,hasForecast:!!u,xAccessorKey:a,yAccessorKey:c}}({data:ht,xAccessor:l,yAccessor:u,forecast:R,anomaly:I,groupBy:d}),bt=re(()=>$t(l,u),[l,u]),{flattenedData:xt,lineStyle:vt,pointStyle:wt,defaultTooltipContent:At}=function(t){const{safeData:e,data:o,areaBy:n,lineDataAccessor:i,colorBy:r,colorScale:s,color:a,stroke:c,strokeWidth:l,opacity:u,effectiveSelectionHook:d,resolvedSelection:h,areaOpacity:f,showLine:p,lineWidth:y,showPoints:g,pointRadius:m,xAccessor:b,yAccessor:x,xLabel:v,yLabel:w,xFormat:k,yFormat:A,groupField:S,styleRules:M,ruleContext:_}=t,P=id(()=>q({data:o,safeData:e,areaBy:n,lineDataAccessor:i}),[o,e,n,i]),C=id(()=>t=>{const e={};if(r){if(s){const o=Pt(t,r,s);e.fill=o,p?(e.stroke=o,e.strokeWidth=y):e.stroke="none"}}else{const t=a||kt;e.fill=t,p?(e.stroke=t,e.strokeWidth=y):e.stroke="none"}return e.fillOpacity=f,M&&M.length>0&&Object.assign(e,Ot(t,M,_?_(t):{value:void 0})),e},[r,s,a,f,p,y,M,_]),R=id(()=>Lt(C,{stroke:c,strokeWidth:l,opacity:u}),[C,c,l,u]);return{flattenedData:P,lineStyle:id(()=>{return t=R,o=h,(e=d??null)?(n,...i)=>{const r={...t(n,...i)};if(e.isActive)if(e.predicate(n))o?.selectedStyle&&Object.assign(r,o.selectedStyle);else{const t=o?.unselectedOpacity??.5;r.opacity=t,r.fillOpacity=t,r.strokeOpacity=t,o?.unselectedStyle&&Object.assign(r,o.unselectedStyle)}return r}:t;var t,e,o},[R,d,h]),pointStyle:id(()=>{if(g)return t=>{const e={r:m,fillOpacity:1};return r?s&&(e.fill=Pt(t.parentLine||t,r,s)):e.fill=a||kt,e}},[g,m,r,s,a]),defaultTooltipContent:id(()=>function(t){const e=t.find(t=>"title"===t.role),o=t.filter(t=>"title"!==t.role);return t=>{const n=t.data;if(!n)return null;const i=e?Pl(Cl(n,e.accessor),e.format):null;return Sl("div",{className:"semiotic-tooltip",style:Zt,children:[null!=i&&Al("div",{style:{fontWeight:"bold",marginBottom:o.length>0?4:0},children:i}),o.map((t,e)=>{const o=Pl(Cl(n,t.accessor),t.format);return Sl("div",{style:e>0?{marginTop:2}:void 0,children:[Sl("span",{style:{opacity:.7},children:[t.label,": "]}),Al("span",{children:o})]},e)})]})}}([{label:v||Ml(b),accessor:b,role:"x",format:k},{label:w||Ml(x),accessor:x,role:"y",format:A},...S?[{label:Ml(S),accessor:S,role:"group"}]:[],...Rl(t.band,A)]),[b,x,v,w,S,k,A,t.band])}}({safeData:gt,data:i,areaBy:d,lineDataAccessor:y,colorBy:ft,colorScale:yt.colorScale,color:Z,stroke:Q,strokeWidth:J,opacity:tt,effectiveSelectionHook:yt.effectiveSelectionHook,resolvedSelection:yt.resolvedSelection,areaOpacity:w,showLine:A,lineWidth:S,showPoints:M,pointRadius:_,xAccessor:l,yAccessor:u,xLabel:ut,yLabel:dt,xFormat:a,yFormat:c,groupField:d||g,band:L,styleRules:x,ruleContext:bt}),Mt=b({componentName:"AreaChart",data:i,accessors:{xAccessor:l,yAccessor:u}}),_t={chartType:"area",...null!=i&&{data:xt},xAccessor:l,yAccessor:u,groupAccessor:d||void 0,...h&&{y0Accessor:h},...L&&{band:L},...pt&&{gradientFill:pt},...k&&{lineGradient:k},curve:v,lineStyle:vt,...M&&wt&&{pointStyle:wt},size:[et,ot],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:yt.margin,showAxes:n.showAxes,xLabel:ut,yLabel:dt,xFormat:a,yFormat:c,enableHover:nt,...t.pointIdAccessor&&{pointIdAccessor:t.pointIdAccessor},showGrid:it,...yt.legendBehaviorProps,...oe({title:st,description:at,summary:ct,accessibleTable:lt,className:s,animate:t.animate,axisExtent:t.axisExtent,autoPlaceAnnotations:t.autoPlaceAnnotations}),..."multi"===P?{tooltipContent:t=>{const e=t.allSeries;if(!e||0===e.length)return Ut("div",{className:"semiotic-tooltip",style:Zt,children:Ut("div",{children:Jt(t.data?.value??t.data?.y)})});const o=t.xValue??t.data?.time??t.data?.x;return Kt("div",{className:"semiotic-tooltip",style:Zt,children:[null!=o&&Ut("div",{style:{fontWeight:600,marginBottom:4,fontSize:"0.9em",borderBottom:"1px solid var(--semiotic-border, #eee)",paddingBottom:4},children:Jt(o)}),e.map((t,e)=>Kt("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"1px 0"},children:[Ut("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:t.color,flexShrink:0}}),Ut("span",{style:{flex:1,fontSize:"0.85em"},children:t.group}),Ut("span",{style:{fontWeight:500,fontSize:"0.85em"},children:Jt(t.value)})]},e))]})},tooltipMode:"multi"}:ie({tooltip:P,defaultTooltipContent:At}),...ne({linkedHover:O,selection:E,onObservation:F,onClick:N,hoverHighlight:j,mobileInteraction:yt.mobileInteraction,customHoverBehavior:yt.customHoverBehavior,customClickBehavior:yt.customClickBehavior}),...(C&&C.length>0||mt.length>0)&&{annotations:[...C||[],...mt]},...T&&{xExtent:T},...$&&{yExtent:$},...yt.crosshairProps,...D};return yt.earlyReturn?yt.earlyReturn:Mt?fd(ju,{componentName:"AreaChart",message:Mt,width:et,height:ot}):fd(Vu,{componentName:"AreaChart",width:et,height:ot,children:fd(Hl,{ref:o,..._t})})}).displayName="AreaChart";var vd="__semiotic_resolvedX",wd="__semiotic_resolvedY",kd="__compoundGroup";function Ad(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Sd(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=E(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrAreaColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?Rt(l,c,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=Tt(i.yAccessor),y=i.styleRules;return(t,o)=>{const n=e&&u?Pt(t,e,u):"string"==typeof i.color?i.color:kt,r={fill:n,fillOpacity:f,stroke:d?n:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(r,Ot(t,y,{value:p(t),category:o})),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 Md(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=E(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrBubbleColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?Rt(l,c,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?M(f):void 0;return t=>({fill:e&&u?Pt(t,e,u):"string"==typeof i.color?i.color:kt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?It(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 _d(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=E(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrScatterColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?Rt(l,c,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?M(f):void 0,y=$t(i.xAccessor,i.yAccessor),g=i.styleRules;return t=>{const o={fill:e&&u?Pt(t,e,u):"string"==typeof i.color?i.color:kt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?It(t,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return g?.length&&Object.assign(o,Ot(t,g,y(t))),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}}var Pd={frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:o,...n,pointStyle:n.pointStyle||Md(t,e,o,n,i),showLegend:n.showLegend??!!e})};function Cd(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=E(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrPointColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?Rt(l,c,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?Pt(t,e,u):"string"==typeof i.color?i.color:kt;return{r:d,fill:o,stroke:"none"}}}var Rd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",c=E(n.theme).colors.categorical,l=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=E(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrLineColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?Rt(l,c,a):void 0,d=$t(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:c,ruleContext:l}=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):o?n&&(f=Pt(t,o,n)):f=i||kt,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),c?.length&&Object.assign(d,Ot(t,c,l?l(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,o,n,i),u=function(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?H(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const n="function"==typeof e,i="function"==typeof o,r=n?vd:e,s=i?wd:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[vd]=e(t)),i&&(r[wd]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,c=s.yKey,l=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d,h="string"==typeof n||"function"==typeof n?n:void 0,f=t.baseLineStyle;if(t.forecast){const e=n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,o=w(r,a,c,e,t.anomaly);if(r=o.processedData,l.push(...o.annotations),u=function(t,e,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?t=>t[n]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,c=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>c&&(c=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t))}}return Number.isFinite(a)&&Number.isFinite(c)?[a,c]:void 0}(r,c,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[kd]:`${t[n]}__${t[x]||"observed"}`})),h=kd):h=x,t.baseLineStyle){const e=k(e=>t.baseLineStyle(e),t.forecast);f=t=>e(t)}}else t.anomaly&&l.push(...v(t.anomaly));if(t.gapStrategy){if("function"==typeof h){const t=h;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),h="__semiotic_gapGroup"}const e=function(t,e,o,n,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)Ad(i,o,n)||t.push(i);return{rows:t,groupKey:i}}if("zero"===e){const t=[];for(const[,e]of r)for(const i of e)Ad(i,o,n)?t.push({...i,[n]:0}):t.push(i);return{rows:t,groupKey:i}}const s=[],a="_gapSegment";for(const[t,e]of r){let i=0,r=[];const c=()=>{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)Ad(t,o,n)?c():r.push(t);c()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,c,"string"==typeof h?h:void 0);r=e.rows,e.groupKey&&(h=e.groupKey)}if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const c="object"==typeof e?e:{},l=c.position||"end",u=c.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const f=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),f.set(t,"end"===l?e[e.length-1]:e[0]);const p=Rt(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),y=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===l?6:-6,dy:0,color:p?Pt({__lbl:t},"__lbl",p):a||kt,fontSize:u}));y.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;y.length>t;t++){const e=y[t-1],o=y[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const g=y.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:y,marginExtra:"end"===l?{right:g}:{left:g}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,c,t.colorScheme,t.themeCategorical,t.color);l.push(...e.annotations),d=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?c:o,groupAccessor:h,colorAccessor:i,annotations:l,lineStyle:f,yExtent:u,marginExtra:d}}({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:n.annotations,themeCategorical:c,baseLineStyle:l}),d=n.pointStyle||Cd(u.data,u.colorAccessor,o,n,i);let h=n.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!==n.showLegend)&&(n.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||l,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!n.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},Id={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?H(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",c=i.categoryAccessor,l=i.valueExtent||n.yExtent,u="down"===i.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:n,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=xd(i,o,"time"),r=xd(i,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/n)*n;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:l,extentPadding:i.extentPadding}):l,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,...n,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||n.xExtent,yExtent:u,extentPadding:i.extentPadding??n.extentPadding,binSize:i.binSize,categoryAccessor:c,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,showLegend:n.showLegend??!!c}}},Ld={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=q({data:t,safeData:Array.isArray(t)?H(t):[],areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),a=i.semanticGradient,c=a&&a.length>0?{colorStops:yd(a)}:n.gradientFill,l=n.pointStyle||Cd(s,r,o,n,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:o,...n,...void 0!==c&&{gradientFill:c},lineStyle:n.lineStyle||Sd(s,r,o,n,i),...l&&{pointStyle:l}}}},Td={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",c=t=>md(gd(r,"x",t)),l=t=>md(gd(s,"a",t)),u=t=>md(gd(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,y=!1!==i.showLines,g=!1!==n.showLegend,m=i.seriesALabel||"A",b=i.seriesBLabel||"B",x=n.legendPosition||"right",v=function(t,e,o,n){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,c=null,l=[];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),y=o(r),g=n(r);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;const m=u(y,g);if(null!==m)if(null!=a){if(c&&c.w!==m){let t,e;if(l.length>0)t=l[0].x,e=l[0].y;else{const o=y-c.a-(g-c.b);if(0!==o){const n=Math.max(0,Math.min(1,(c.b-c.a)/o));t=c.x+n*(p-c.x),e=c.a+n*(y-c.a)}else t=c.x,e=c.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;l.length>t;t++)f(l[t],a)}else for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else{a=m;for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else l.push({x:p,y:y,datum:r})}for(const t of l)f(t,a??"A");return r}(Array.isArray(t)?t:[],c,l,u),w=[];if(y&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(c(t))).sort((t,e)=>c(t)-c(e));for(const t of e){const e=c(t),o=l(t),n=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:e,__y:n,__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",...n,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:b,color:h}]}]},legendPosition:x}}}},$d={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?Rt(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,c=n.lineStyle||(t=>{const e=null==r?void 0:Pt(t,r,s),o=i.showLine??!0,n={fill:i.color??e,stroke:o?i.stroke??e:"none",...o?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},c=i.styleRules;if(c?.length){const e=Tt(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,Ot(t,c,{value:e(t),category:o}))}return n}),l=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Cd(t,r,o,n,i);return{chartType:"stackedarea",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:o,normalize:i.normalize,baseline:l,stackOrder:i.stackOrder,lineStyle:c,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},zd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const[r]=n.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,...n,scalePadding:n.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:n.extentPadding??(r>200?.1:.02)}}},Dd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=n.pointStyle||_d(t,e,o,n,i),s=function(t,e,o){return t&&0!==t.length?(n,i)=>{const r=Ot(n,t,e(n,i)),s=o?o(n,i):void 0;return s?{...r,...s}:r}:o}(i.styleRules,$t(i.xAccessor||"x",i.yAccessor||"y"),c),a=s?t=>({..."function"==typeof r?r(t):r,...s(t)}):r;var c;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:o,...n,sizeRange:i.sizeRange||[3,15],pointStyle:a,showLegend:n.showLegend??!!e}}},Ed={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,c=i.centerlineStyle||{},l=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=c.stroke||"#999",h=c.strokeWidth??1,f=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,p=G.createElement,y=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,c=null!=r?e.x(r):n/2,y=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(c))return null;if(null!=s&&!Number.isFinite(y))return null;const g=Math.max(0,Math.min(n,c)),m=Math.max(0,Math.min(i,y)),b=[{c:a.topLeft,x:0,y:0,w:g,h:m},{c:a.topRight,x:g,y:0,w:n-g,h:m},{c:a.bottomLeft,x:0,y:m,w:g,h:i-m},{c:a.bottomRight,x:g,y:m,w:n-g,h:i-m}],x=l?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:n-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:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(G.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:g,y1:0,x2:g,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:n,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:o,pointStyle:n.pointStyle||i.pointStyle||_d(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...y&&{svgPreRenderers:y}}}},Od={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",n=e.yAccessor||"y",i=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:md(gd(e.orderAccessor,"order",t))-md(gd(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=md(gd(o,"x",t)),i=md(gd(n,"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=md(gd(o,"x",t)),i=md(gd(n,"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;return{chartType:"scatter",data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,pointStyle:t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1;return{fill:n>0?bd(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},...n,svgPreRenderers:[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const o=[];for(let t=0;e.length-1>t;t++){const n=e[t],i=e[t+1],r=bd(t,e.length);100>e.length&&o.push(G.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),o.push(G.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:s,strokeLinecap:"round"}))}return G.createElement(G.Fragment,null,...o)}]}}};function Fd(t){return Math.max(0,Math.min(1,t))}function Bd(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 o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const t=[Number(o[1]),Number(o[2]),Number(o[3])];if(t.every(Number.isFinite))return t}return null}function Nd(t,e,o){const n=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Wd(t,e){const o=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:Fd(t.offset),color:t.color})).sort((t,e)=>t.offset-e.offset);if(0===o.length)return"#999999";if(1===o.length)return o[0].color;const n=Fd(e);if(o[0].offset>=n)return o[0].color;if(n>=o[o.length-1].offset)return o[o.length-1].color;for(let t=0;o.length-1>t;t++){const e=o[t],i=o[t+1];if(e.offset>n||n>i.offset)continue;const r=i.offset-e.offset,s=r>0?(n-e.offset)/r:0,a=Bd(e.color),c=Bd(i.color);if(!a||!c)return.5>s?e.color:i.color;const[l,u,d]=a,[h,f,p]=c;return Nd(l+(h-l)*s,u+(f-u)*s,d+(p-d)*s)}return o[o.length-1].color}function jd(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as Yd,jsx as Gd,jsxs as qd}from"react/jsx-runtime";function Xd(t=240){const e=360-t,o=180+e/2,n=o*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:o,startAngleRad:n,offsetRad:-Math.PI/2+n}}import{useMemo as Hd,useCallback as Vd,useRef as Ud}from"react";var Kd={RdBu:ft,PiYG:pt,PRGn:yt,BrBG:gt,RdYlBu:mt,RdYlGn:bt,Spectral:xt},Zd="__likert_neutral_neg",Qd="__likert_neutral_pos";function Jd(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as th from"react";function eh(t){return!0===t?{topOpacity:.8,bottomOpacity:.05}:!1===t?void 0:t}function oh(t,e,o,n,i){const r=E(n.theme).colors.categorical,s=o??n.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],c="string"==typeof e?e:"__ssrColorBy",l="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?Rt(l,c,s??r):void 0,d=Ou("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=Tt(i.valueAccessor),f=i.styleRules,p=n.pieceStyle;return(t,o)=>{const n={fill:e&&u?Pt(t,e,u):d};return f?.length&&Object.assign(n,Ot(t,f,{value:h(t),category:o})),"function"==typeof p?Object.assign(n,p(t,o)||{}):p&&"object"==typeof p&&Object.assign(n,p),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}}function nh(t,e,o,n,i){const r=oh(t,e,o,n,i);return(t,e)=>{const o=r(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function ih(t,e,o,n,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,c=E(n.theme).colors.categorical,l=o??n.colorScheme,u=e?Rt(a,s,l??c):void 0,d=Ou("string"==typeof i.color?i.color:void 0,c,l,void 0,new Map);return t=>{const o=e&&u?Pt(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:i.stroke??o,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function rh(t,e,o,n,i){const r=oh(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function sh(t,e,o,n,i){const r=oh(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,c=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],l=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=l.length?M(l):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?It(t,a,c,u):d,fillOpacity:h,...r(t,e)})}var ah={frameType:"ordinal",buildProps:(t,e,o,n,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:o,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:eh(n.gradientFill),pieceStyle:oh(t,e,o,n,i)})},ch={frameType:"ordinal",buildProps:(t,e,o,n,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:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:eh(n.gradientFill),pieceStyle:oh(t,r,o,n,i),showLegend:n.showLegend??!!r}}},lh={frameType:"ordinal",buildProps:(t,e,o,n,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:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:eh(n.gradientFill),pieceStyle:oh(t,r,o,n,i),showLegend:n.showLegend??!!r}}},uh={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"pie",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:oh(t,r,o,n,i),showLegend:n.showLegend??!!r}}},dh={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"donut",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:n.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:oh(t,r,o,n,i)}}},hh={frameType:"ordinal",buildProps:(t,e,o,n,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),c=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:o,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:c?{rExtent:c}:{},...n,summaryStyle:nh(t,e,o,n,i)}}},fh={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"boxplot",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...n,summaryStyle:n.summaryStyle||nh(t,e,o,n,i)})},ph={frameType:"ordinal",buildProps:(t,e,o,n,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:o,...n,summaryStyle:n.summaryStyle||ih(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},yh={frameType:"ordinal",buildProps:(t,e,o,n,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:o,...n,sizeRange:i.sizeRange||[3,8],pieceStyle:n.pieceStyle||sh(t,e,o,n,i),showLegend:n.showLegend??!!e})},gh={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>({chartType:"point",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...n,pieceStyle:rh(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e})},mh={frameType:"ordinal",buildProps:(t,e,o,n,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:o,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:eh(n.gradientFill),pieceStyle:n.pieceStyle||oh(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},bh={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"ridgeline",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...n,summaryStyle:n.summaryStyle||((r,s)=>({fillOpacity:.5,...oh(t,e,o,n,i)(r,s)})),showLegend:n.showLegend??!!e})},xh={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,o,n,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,o,n,i,r){const s=new Map,a=new Set(e);for(const c of t){const t=o(c);s.has(t)||s.set(t,new Map);const l=s.get(t);if(n){const t=n(c);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 o=t-1;if(0>o||o>=e.length)continue;const i=e[o];l.set(i,(l.get(i)||0)+1)}else if(i&&r){const t=i(c),e=r(c);if(!a.has(t))continue;l.set(t,(l.get(t)||0)+(Number.isFinite(e)?e:0))}}const c=[];for(const[t,o]of s){let n=0;for(const t of e)n+=o.get(t)||0;if(0!==n)for(let i=0;e.length>i;i++){const r=e[i],s=o.get(r)||0;c.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/n*100,__likertLevelIndex:i})}}return c}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,Jd(i.categoryAccessor,"question"),i.levelAccessor?null:Jd(i.valueAccessor,"score"),i.levelAccessor?Jd(i.levelAccessor,"level"):null,i.levelAccessor?Jd(i.countAccessor,"count"):null);s&&(a=function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/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 o of t)o.__likertLevel===Zd?r=o:o.__likertLevel===Qd?a=o:e.set(o.__likertLevelIndex,o);n&&r&&s.push(r);for(let t=i-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}n&&a&&s.push(a);for(let t=n?i+1:i;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(n&&t===i){const t=e.__likertPct/2;r.push({...e,__likertLevel:Zd,__likertPct:-t}),r.push({...e,__likertLevel:Qd,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const c=E(n.theme).colors.diverging,l=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e){const o=Kd[e];if(o){if(1===t)return[o(.5)];const e=[];for(let n=0;t>n;n++)e.push(o(n/(t-1)));return e}}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#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(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);return a}(r.length,c),u=new Map(r.map((t,e)=>[t,l[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=Zi(!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},n.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:n.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...n,pieceStyle:t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===Zd||e===Qd?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},vh={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,o,n,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:o,...n,showAxes:r,showGrid:r,pieceStyle:oh(t,s,o,n,i),showLabels:i.showLabels??!0}}},wh={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,i=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return qd(Yd,{children:[o.showNeedle&&qd(Yd,{children:[Gd("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(n),y2:o.centerY+o.needleLength*Math.sin(n),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),Gd("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&Gd("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:i,children:o.contextValue}),r.map((t,n)=>{const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(t.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,c=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",u=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return qd("g",{children:[Gd("line",{x1:o.centerX+Math.cos(i)*r,y1:o.centerY+Math.sin(i)*r,x2:o.centerX+Math.cos(i)*s,y2:o.centerY+Math.sin(i)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),Gd("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:l,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+n)})]})},buildProps:(t,e,o,n,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,c=i.arcWidth??.3,l=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=Xd(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=n.gradientFill,p=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let f=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>f[f.length-1].value&&f.push({value:o,color:f[f.length-1].color});const p=!!l&&l.colorStops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?h:1,e=jd("bg",0);if(y.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),n=[];for(let e=0;o>e;e++)n.push(Wd(l.colorStops,t*(e+.5)/o));const i=jd("fill",0);y.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),g.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;f.length>o;o++){const n=f[o],i=(n.value-t)/d,r=(t-e)/d,c=(n.value-e)/d,l=Math.max(0,(a?Math.min(h,c):c)-r),u=a?Math.max(0,i-l):0;if(l>0){const t=jd("fill",o);y.push({category:t,value:l,_zone:n.label||"Zone "+(o+1),_isFill:!0}),g.set(t,{fill:n.color})}if(u>0){const t=jd("bg",o);y.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=n.value}}if(c&&i&&i.length>0)for(const t of i)t.value>e&&o>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:y,pieceStyle:(t,e)=>g.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:f&&"object"==typeof f&&"colorStops"in f?f:void 0}),[y,g]=n.size||[300,250],m=function(t=240){const{sweepRad:e,offsetRad:o}=Xd(t),n=[[Math.cos(o),Math.sin(o)],[Math.cos(o+e),Math.sin(o+e)],[0,0]];for(let t=0;2*Math.PI>t;t+=Math.PI/2)((t-o)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>e+.001||n.push([Math.cos(t),Math.sin(t)]);const i=n.map(t=>t[0]),r=n.map(t=>t[1]),[s,a]=M(i),[c,l]=M(r);return{minX:s,maxX:a,minY:c,maxY:l,width:a-s,height:l-c,cx:(s+a)/2,cy:(c+l)/2}}(a),b=Math.min(10,Math.max(1,Math.min(y,g)/12)),x=Math.max(4,Math.min((y-2*b)/m.width,(g-2*b)/m.height)-2),v=Math.max(0,Math.min(x-1.5,x*(1-c))),w=y/2-m.cx*x,k=g/2-m.cy*x,A=2*(x+4),S=Math.max(r,Math.min(s,i.value??r)),_="function"==typeof i.valueFormat?i.valueFormat(S):Math.round(S)+"",P=i.centerContent??n.centerContent,C=null!=P?"function"==typeof P?P(S,r,s):P:"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)"}},_),!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:p.pieceStyle,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[y,g],margin:{top:k-A/2,bottom:g-k-A/2,left:w-A/2,right:y-w-A/2},...null!=C&&{centerContent:C},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:c,value:S,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:x,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:x-1,showNeedle:l,needleColor:i.needleColor,..."context"===i.mode&&null==P&&{contextValue:_,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*x))}}}}};import{scaleTime as kh}from"d3-scale";function Ah(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:t.kind}function Sh(t,e,o){const n=e.incoming[t.id],i=e.outgoing[t.id],r=[];for(const t of n)r.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of i)r.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},a=()=>{r.sort((t,e)=>t.time-e.time||(s[t.kind]??99)-(s[e.kind]??99))},c=r.length?S(r.map(t=>t.time)):null,l=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,u=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,d=[...new Set(r.map(t=>t.time))].sort((t,e)=>t-e),h=new Map;for(let t=1;d.length>t;t++)h.set(d[t],d[t-1]);const f=t=>{const e=h.get(t);return null!=e?(e+t)/2:null!=u?u:t};a();const p=[];let y=0,g=0;for(const t of r)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?y:g);if(o>0){const e="top"===t.side?"bot":"top",n=Math.min(o,"top"===e?y:g);if(n>0){const i=f(t.time);p.push({time:i,delta:-n,kind:"transfer-out",side:e}),p.push({time:i,delta:+n,kind:"transfer-in",side:t.side}),"top"===e?y-=n:g-=n,"top"===t.side?y+=n:g+=n,o-=n}o>0&&null!==u&&(p.push({time:u,delta:+o,kind:"create",side:t.side}),"top"===t.side?y+=o:g+=o)}"top"===t.side?y-=e:g-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?y+=e:g+=e}r.push(...p),a();let m=0,b=0,x=0,v=0,w=0;const k=[],A=new Map;for(const t of r){if(k.push({t:t.time,topMass:m,botMass:b}),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?m:b;A.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta)})}"top"===t.side?m+=t.delta:b+=t.delta,m+b>x&&(x=m+b),m>v&&(v=m),b>w&&(w=b),k.push({t:t.time,topMass:m,botMass:b})}const M=[];let _=0;for(;k.length>_;){let t=_;for(;k.length>t+1&&k[t+1].t===k[_].t;)t++;M.push(k[_]);for(let e=_+1;t>=e;e++){const t=M[M.length-1];k[e].topMass===t.topMass&&k[e].botMass===t.botMass||M.push(k[e])}_=t+1}const P=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let C=null;for(const t of i)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===C||C>t.systemInTime)&&(C=t.systemInTime);let R=null;for(const t of n)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===R||t.systemOutTime>R)&&(R=t.systemOutTime);if(M.length>0){const t=M[M.length-1],e=Math.max(null!=P?P:-1/0,null!=R?R:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&M.push({t:e,topMass:t.topMass,botMass:t.botMass});const o=M[0],n=Math.min(null!=l?l:1/0,null!=C?C:1/0);Number.isFinite(n)&&o.t>n&&o.topMass+o.botMass>0&&M.unshift({t:n,topMass:o.topMass,botMass:o.botMass})}return{samples:M,peak:x,topPeak:v,botPeak:w,localAttachments:A}}function Mh(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function _h(t,e){return t.map(t=>({t:Mh(t.t,e),topMass:t.topMass,botMass:t.botMass}))}function Ph(t,e,o){const n=t.value*o;if("out"===t.kind){const i=t.sideMassBefore*o;if("top"===t.side){const t=e-i;return[t,t+n]}const r=e+i;return[r-n,r]}const i=t.sideMassAfter*o;if("top"===t.side){const t=e-i;return[t,t+n]}const r=e+i;return[r-n,r]}function Ch(t,e){let o=0;for(let n=0;e.length>n;n++)for(let i=n+1;e.length>i;i++){const r=e[n],s=e[i];r.source!==s.source&&r.target!==s.target&&r.source!==s.target&&r.target!==s.source&&(Math.min(r.endTime,s.endTime)>Math.max(r.startTime,s.startTime)&&t[s.source]>t[r.source]!=t[s.target]>t[r.target]&&o++)}return o}function Rh(t,e){let o=0;for(const n of e)o+=Math.abs(t[n.source]-t[n.target])*(n.value||1);return o}function Ih(t,e){return 1e3*Ch(t,e)+Rh(t,e)}function Lh(t,e){return{slots:t.map(t=>({peak:{...t.peak},occupants:t.occupants.slice()})),map:{...e}}}function Th(t,e,o){t.length>8||o.length>40?(function(t,e,o,n=6){const i=t.length;if(1>=i)return;let r=Lh(t,e),s=Ih(e,o);for(let a=0;n>a;a++){const n=Array(i).fill(0),a=Array(i).fill(0);for(const t of o){const o=e[t.source],i=e[t.target];n[o]+=i*(t.value||1),a[o]+=t.value||1,n[i]+=o*(t.value||1),a[i]+=t.value||1}const c=Array.from({length:i},(t,e)=>e).sort((t,e)=>(a[t]>0?n[t]/a[t]:t)-(a[e]>0?n[e]/a[e]:e)),l=c.map(e=>t[e]),u=new Map;c.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of l)t.push(e);const d=Ih(e,o);if(s>d)s=d,r=Lh(t,e);else if(d===s)break}!function(t,e,o){t.length=0;for(const e of o.slots)t.push(e);for(const t of Object.keys(e))delete e[t];for(const t of Object.keys(o.map))e[t]=o.map[t]}(t,e,r)}(t,e,o,6),function(t,e,o,n=6){const i=t.length;if(1>=i)return;let r=Ih(e,o);for(let s=0;n>s;s++){let n=!1;for(let s=0;i-1>s;s++){const i=t[s];t[s]=t[s+1],t[s+1]=i;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s);const a=Ih(e,o);if(r>a)r=a,n=!0;else{const o=t[s];t[s]=t[s+1],t[s+1]=o;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s)}}if(!n)break}}(t,e,o,6)):function(t,e,o){const n=t.length;if(1>=n)return;const i={...e},r=Object.keys(i),s=Array.from({length:n},(t,e)=>e),a=s.slice(),c={...i};let l=s.slice(),u=1/0;const d=()=>{for(const t of r)c[t]=a[i[t]];const t=Ih(c,o);u>t&&(u=t,l=s.slice())},h=(t,e)=>{const o=s[t],n=s[e];s[t]=n,s[e]=o,a[o]=e,a[n]=t};d();const f=Array(n).fill(0);let p=0;for(;n>p;)p>f[p]?(h(p%2==0?0:f[p],p),d(),f[p]++,p=0):(f[p]=0,p++);const y=l.map(e=>t[e]),g=new Map;l.forEach((t,e)=>g.set(t,e));for(const t of Object.keys(e))e[t]=g.get(e[t]);t.length=0;for(const e of y)t.push(e)}(t,e,o)}function $h(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="full"}=i,d={},h={};for(const e of t)d[e.id]=o[e.id].topPeak||0,h[e.id]=o[e.id].botPeak||0;const f="half"===u,p={};for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,o=Array.isArray(e.xExtent)?e.xExtent[1]:null;let i=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of n.outgoing[e.id]){i>t.startTime&&(i=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&i>t.systemInTime&&(i=t.systemInTime);const e=f?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of n.incoming[e.id]){const e=f?(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)}p[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}const y={},g=[];if("reuse"===c){const o=new Map;for(const e of t)o.set(e.id,0);const i=new Map;for(const e of t)i.set(e.id,0);for(const t of e)i.set(t.target,(i.get(t.target)??0)+1);const r=[];for(const e of t)0===(i.get(e.id)??0)&&r.push(e.id);for(;r.length;){const t=r.shift();for(const e of n.outgoing[t]??[]){const n=(o.get(t)??0)+1;n>(o.get(e.target)??0)&&o.set(e.target,n),i.set(e.target,i.get(e.target)-1),0===i.get(e.target)&&r.push(e.target)}}const s=[...t].filter(t=>null!==p[t.id].start).sort((t,e)=>{const n=o.get(t.id)??0,i=o.get(e.id)??0;return n!==i?n-i:p[t.id].start-p[e.id].start}),a=t.filter(t=>null===p[t.id].start);for(const t of[...s,...a]){const e=p[t.id];let o=-1;for(let t=0;g.length>t;t++){const n=g[t].occupants[g[t].occupants.length-1];if(null===e.start||void 0===n||e.start>=n.end){o=t;break}}-1===o&&(g.push({occupants:[],peak:{topPeak:0,botPeak:0}}),o=g.length-1),g[o].occupants.push({id:t.id,end:e?.end??-1/0}),g[o].peak.topPeak=Math.max(g[o].peak.topPeak,d[t.id]),g[o].peak.botPeak=Math.max(g[o].peak.botPeak,h[t.id]),y[t.id]=o}}else t.forEach((t,e)=>{g.push({occupants:[{id:t.id,end:p[t.id]?.end??-1/0}],peak:{topPeak:d[t.id],botPeak:h[t.id]}}),y[t.id]=e});let m=null,b=null,x=null,v=null;const w=()=>{m=Ch(y,e),x=Rh(y,e)},k=()=>{b=Ch(y,e),v=Rh(y,e)};"crossing-min"===l?(w(),Th(g,y,e),k()):"inside-out"===l?(w(),function(t,e){const o=t.length;if(1>=o)return;const n=t=>t.peak.topPeak+t.peak.botPeak,i=t.map((t,e)=>({slot:t,idx:e})).sort((t,e)=>n(e.slot)-n(t.slot)),r=Array(o),s=Math.floor((o-1)/2);r[s]=i[0].idx;let a=s-1,c=s+1;for(let t=1;i.length>t;t++)t%2==1&&o>c||0>a?r[c++]=i[t].idx:r[a--]=i[t].idx;const l=r.map(e=>t[e]),u=new Map;r.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of l)t.push(e)}(g,y),k()):"crossing-min+inside-out"===l&&(w(),Th(g,y,e),function(t,e,o){const n=t.length;if(1>=n)return;const i=t.map(t=>{return{slot:t,size:(e=t,e.peak.topPeak+e.peak.botPeak)};var e}).sort((t,e)=>e.size-t.size),r=Math.floor((n-1)/2);let s=Ih(e,o);for(const{slot:a}of i){const i=t.indexOf(a);if(0>i)continue;const c=r;if(i===c)continue;const l=t[i];t.splice(i,1),t.splice(c,0,l);const u=new Map;for(let t=0;n>t;t++)u.set(t,t);if(c>i){for(let t=i+1;c>=t;t++)u.set(t,t-1);u.set(i,c)}else{for(let t=c;i>t;t++)u.set(t,t+1);u.set(i,c)}for(const t of Object.keys(e))e[t]=u.get(e[t]);const d=Ih(e,o);if(d>s){const o=t[c];t.splice(c,1),t.splice(i,0,o);const r=new Map;for(let t=0;n>t;t++)r.set(t,t);if(i>c){for(let t=c+1;i>=t;t++)r.set(t,t-1);r.set(c,i)}else{for(let t=i;c>t;t++)r.set(t,t+1);r.set(c,i)}for(const t of Object.keys(e))e[t]=r.get(e[t])}else s=d}}(g,y,e),k());const A=g.map(t=>{const e=new Map;for(const n of t.occupants){const t=o[n.id];if(t)for(const o of t.samples){const t=e.get(o.t)||{top:0,bot:0};e.set(o.t,{top:Math.max(t.top,o.topMass),bot:Math.max(t.bot,o.botMass)})}}return[...e.entries()].sort((t,e)=>t[0]-e[0])}),S=(t,e)=>{let o={top:0,bot:0};for(const[n,i]of t){if(n>e)break;o=i}return o},M=[];for(let t=0;g.length-1>t;t++){const e=A[t],o=A[t+1],n=new Set([...e.map(t=>t[0]),...o.map(t=>t[0])]);let i=0;for(const t of n){const n=S(e,t),r=S(o,t);n.bot+r.top>i&&(i=n.bot+r.top)}M.push(i)}const _=[];let P=s+(g[0]?.peak.topPeak??0)*a;g.length>0&&_.push(P);for(let t=1;g.length>t;t++)P+=M[t-1]*a+s,_.push(P);if(g.length>0&&(P+=g[g.length-1].peak.botPeak*a+s),P>r){const t=r/P;for(let e=0;_.length>e;e++)_[e]*=t}const C=0===g.length?0:g[0].peak.topPeak+M.reduce((t,e)=>t+e,0)+g[g.length-1].peak.botPeak,R={};for(const e of t)R[e.id]=_[y[e.id]];return{effectiveSlotsHeight:C,centerlines:R,laneLifetime:p,slots:g,slotByNode:y,slotCenter:_,crossingsBefore:m,crossingsAfter:b,lengthBefore:x,lengthAfter:v}}function zh(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:c}=t,l=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${c},${r} ${i},${r}`,`L${i},${s}`,`C${c},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:l},{x:a,y:l},{x:c,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function Dh(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,edgeOpacity:a,colorOf:c,layoutOpts:l}=t,u=function(t,e,o){const n=[],i=new Set(t.map(t=>t.id)),r=Array.isArray(o)&&2===o.length,s=r&&Number.isFinite(o[0])&&Number.isFinite(o[1]);r&&s&&s&&o[1]>=o[0]||n.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]||n.push({kind:"invalid-node-time",id:e.id}));for(const t of e)i.has(t.source)||n.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),i.has(t.target)||n.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?(Number.isFinite(t.value)&&t.value>0||n.push({kind:"invalid-value",id:t.id}),t.endTime>t.startTime||n.push({kind:"backward-edge",id:t.id,source:t.source,target:t.target})):n.push({kind:"invalid-edge-time",id:t.id});return n}(e,o,n),d=kh().domain(n).range([0,i]);if(u.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:u,xScale:d};const h=function(t,e,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half"}=o,c=function(t,e){const o={},n={};for(const e of t)o[e.id]=[],n[e.id]=[];for(const t of e)n[t.source]&&n[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:n}}(t,e),l=function(t,e,o,n="value"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime:(t,e)=>e.value-t.value,r="temporal"===n?(t,e)=>t.startTime-e.startTime:(t,e)=>e.value-t.value,s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const n of t){const t=n[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=o.get(t);i.edges.push(n),i.total+=n.value,i.earliestStart=Math.min(i.earliestStart,n.startTime),i.latestEnd=Math.max(i.latestEnd,n.endTime)}const s=[...o.values()];s.sort("temporal"===n?(t,o)=>"target"===e?t.earliestStart-o.earliestStart:t.latestEnd-o.latestEnd:(t,e)=>e.total-t.total);for(const t of s)t.edges.sort("target"===e?r:i);return s};for(const e of t){const t=o.outgoing[e.id],n=o.incoming[e.id];if(0===n.length)a(t,"target").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=o});else if(0===t.length)a(n,"source").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=o});else{const e=a(n,"source"),o=a(t,"target"),i=Math.max(e.length,o.length);for(let t=0;i>t;t++){const n=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=n;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=n}}}return s}(t,e,c,i);let u={};for(const e of t)u[e.id]=Sh(e,c,l);const d=$h(t,e,u,c,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),h=new Set;for(const t of e){const e=d.slotByNode[t.source],o=d.slotByNode[t.target];if(void 0===e||void 0===o)continue;const n=l.get(t.id);e!==o?e>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(h.add(t.id),n.sourceSide="bot",n.targetSide="bot")}for(const e of t){const t=c.outgoing[e.id],o=c.incoming[e.id],n=new Set(t.map(t=>l.get(t.id).sourceSide)),i=new Set(o.map(t=>l.get(t.id).targetSide));if(1===n.size&&o.length>0){const t=[...n][0];for(const e of o)d.slotByNode[e.source]===d.slotByNode[e.target]&&(l.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const o of t)d.slotByNode[o.source]===d.slotByNode[o.target]&&(l.get(o.id).sourceSide=e)}}for(const e of t){const t=c.incoming[e.id],o=c.outgoing[e.id];if(0===t.length||0===o.length)continue;const n=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===l.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of o)"top"===l.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},i=(t,e)=>{const i=n(),r="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,s="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=r||0>=s)return!1;const a=Math.min(r,s),c=o.filter(e=>!h.has(e.id)&&l.get(e.id).sourceSide===t&&a>=e.value).sort((t,e)=>e.value-t.value);return 0!==c.length&&(l.get(c[0].id).sourceSide=e,!0)};let r=o.length+1;for(;r-- >0&&(i("top","bot")||i("bot","top")););}u={};for(const e of t)u[e.id]=Sh(e,c,l);const f=$h(t,e,u,c,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),p=f.effectiveSlotsHeight??f.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),y=Math.min(12,.35*n/Math.max(f.slots.length+1,1)),g=p>0?Math.max(0,(n-y*(f.slots.length+1))/p):1,m=$h(t,e,u,c,{plotH:n,padding:y,valueScale:g,packing:r,laneOrder:s,lifetimeMode:a});return{nodeData:u,sides:l,valueScale:g,padding:y,compressedPadding:12>y,centerlines:m.centerlines,laneLifetime:m.laneLifetime,slots:m.slots,slotByNode:m.slotByNode,crossingsBefore:m.crossingsBefore,crossingsAfter:m.crossingsAfter,lengthBefore:m.lengthBefore,lengthAfter:m.lengthAfter}}(e,o,{plotH:r,...l}),{centerlines:f,nodeData:p,valueScale:y}=h,g=[],m=[];e.forEach((t,e)=>{const i=p[t.id];if(!i||0===i.samples.length)return;const r=function(t,e,o,n,i){if(0===t.length)return null;const r=_h(t,i),s=t=>e-r[t].topMass*o,a=t=>e+r[t].botMass*o;let c=`M${n(r[0].t)},${s(0)}`;for(let t=1;r.length>t;t++)c+=` L${n(r[t].t)},${s(t)}`;c+=` L${n(r[r.length-1].t)},${a(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${n(r[t].t)},${a(t)}`;return c+" Z"}(i.samples,f[t.id],y,d,n);if(!r)return;const s=_h(i.samples,n),a=s.find(t=>t.topMass+t.botMass>0)||s[0],l=f[t.id]+(a.botMass-a.topMass)*y/2,u=c(t.id,e),m=function(t,e,o,n,i){const r=o.nodeData[t];if(!r||0===r.samples.length)return[];const s=o.valueScale,a=o.centerlines[t],c=_h(r.samples,i),l=c.find(t=>t.topMass+t.botMass>0)||c[0],u=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],d=n(l.t),h=n(u.t),f=t=>n(Mh(t,i)),p=[],y=(t,e,o,n)=>`M${t},${e} L${o},${e} L${o},${n} L${t},${n} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=r.localAttachments.get(o.id);if(t&&"out"===t.kind&&o.startTime>o.systemInTime){const e=f(o.systemInTime),n=f(o.startTime),i=e-20,r=Math.max(d,i);if(n>r){const[o,c]=Ph(t,a,s);p.push({pathD:y(r,o,n,c),x0:i,x1:e,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=r.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=f(o.systemOutTime),n=f(o.endTime),i=e+20,r=Math.min(h,i);if(r>n){const[o,c]=Ph(t,a,s);p.push({pathD:y(n,o,r,c),x0:e,x1:i,from:1,to:0})}}}}return p}(t.id,o,h,d,n);g.push({id:t.id,pathD:r,fill:u,stroke:u,strokeWidth:.5,...m.length>0&&{gradientStubs:m},rawDatum:t.__raw??t,labelX:d(a.t)-4,labelY:l,labelText:t.id})});const b=new Map;return e.forEach((t,e)=>b.set(t.id,e)),o.forEach(t=>{const e=p[t.source]?.localAttachments.get(t.id),o=p[t.target]?.localAttachments.get(t.id);if(!e||!o)return;const i=b.get(t.source)??0,r=c(t.source,i),l=function(t,e,o,n,i,r,s,a){const c=i,l=t=>a?Math.max(a[0],Math.min(a[1],t)):t,u=r(l(t.time)),d=r(l(o.time)),h=t.value*c,f=o.value*c,p=t.sideMassBefore*c,y=o.sideMassAfter*c;let g,m,b,x;"top"===t.side?(g=e-p,m=g+h):(m=e+p,g=m-h),"top"===o.side?(b=n-y,x=b+f):(x=n+y,b=x-f);const v="source"===s?u+.85*(d-u):"target"===s?u+.15*(d-u):(u+d)/2;return{sx:u,sTop:g,sBot:m,tx:d,tTop:b,tBot:x,cp1X:v,cp2X:v}}(e,f[t.source],o,f[t.target],y,d,s,n),{pathD:u,bezier:h}=zh(l);m.push({id:t.id,pathD:u,fill:r,opacity:a,rawDatum:t.__raw??t,bezier:h})}),{layout:h,layoutConfig:{bands:g,ribbons:m,showLabels:!0},issues:[],xScale:d}}var Eh=t=>{const{bands:e=[],ribbons:o=[],showLabels:n=!0}=t.config,i=[];for(const t of o)i.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:t.opacity,stroke:"none"},datum:{__kind:"ribbon",data:t.rawDatum,id:t.id}});for(const t of e)if(t.gradientStubs)for(let e=0;t.gradientStubs.length>e;e++){const o=t.gradientStubs[e];i.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,from:o.from,to:o.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${e}`}})}for(const t of e)i.push({type:"bezier",pathD:t.pathD,style:{...t.gradientStubs&&t.gradientStubs.length>0?{fill:"none"}:{fill:t.fill,fillOpacity:.86},stroke:t.stroke??t.fill,strokeWidth:t.strokeWidth??.5},datum:{__kind:"band",data:t.rawDatum,id:t.id}});const r=n?e.map(t=>({x:t.labelX,y:t.labelY,text:t.labelText,anchor:"end",baseline:"middle",fontSize:11,fontWeight:600})):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:i,labels:r}};function Oh(t,e){if(!t)return[];const o=[],n=t=>{o.push(t);const i="function"==typeof e?e(t):t[e];i&&Array.isArray(i)&&i.forEach(n)};return n(t),o}function Fh(t,e,o,n){if(t&&t.length>0)return t;const i=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof n?n(t):t[n];i.add(e),i.add(r)}),Array.from(i).map(t=>({id:t}))}import*as Bh from"react";function Nh(t,e){return e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t}var Wh={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const{edgeWidth:r,edgeColor:s,edgeOpacity:a}=i,c=i.edgeStyle??(void 0!==r||void 0!==s||void 0!==a?t=>{const e=t?.data||t;let o=1;if("number"==typeof r)o=r;else if("function"==typeof r)o=r(e);else if("string"==typeof r){const t=e?.[r],n="number"==typeof t?t:Number(t);o=Number.isFinite(n)&&n>0?n:1}return{stroke:s??"#999",strokeWidth:o,opacity:a??.6}}:void 0),l=E(n.theme).colors.categorical,u=new Map,d=i.nodeStyle??(t=>({fill:e?Pt(t?.data||t,e,void 0):Ou(void 0,l,o,void 0,u),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),h=Bt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize);return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:e,colorScheme:o,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:h?(t,e)=>({...d(t),...h(t,e)}):d,edgeStyle:c,...n}}},jh={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,n,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",c=i.valueAccessor||"value",l=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",y=i.edgeIdAccessor||"id",g=(t,e)=>"function"==typeof t?t(e):e[t],m=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],x=b.length>0?b:Fh([],m,s,a),v=[r(i.domain?.[0]),r(i.domain?.[1])],w=x.map(t=>{const e=g(l,t)+"",o=g(p,t),n={id:e,__raw:t};if(Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(n.xExtent=[t,e])}return n}),k=m.map((t,e)=>{const o=g(y,t),n={id:null!=o?o+"":`${g(s,t)}-${g(a,t)}-${e}`,source:g(s,t)+"",target:g(a,t)+"",value:Number(g(c,t)),startTime:r(g(u,t)),endTime:r(g(d,t)),__raw:t};if(h){const e=r(g(h,t));Number.isFinite(e)&&(n.systemInTime=e)}if(f){const e=r(g(f,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[A,S]=n.size??[600,400],M={top:20,right:20,bottom:20,left:20,...n.margin},_=(n.showLegend??!!e)&&!!e,P=n.legendPosition??"right",C=n.__explicitMargin,R=t=>"number"==typeof C||null!=C&&"object"==typeof C&&null!=C[t];_&&("right"!==P||R("right")?"bottom"!==P||R("bottom")||(M.bottom=Math.max(M.bottom,80)):M.right=Math.max(M.right,140));const I=M,L=A-I.left-I.right,T=S-I.top-I.bottom,$=At(o,E(n.theme).colors.categorical,Q),z="function"==typeof e?e:null,D=z?x.map(t=>({_cat:z(t)})):x,O=z?"_cat":"string"==typeof e?e:void 0,F=o??[...$],B=O?Rt(D,O,F):null,N=new Map;for(const t of w)N.set(t.id,t.__raw);const W=(t,o)=>{if(e&&N.has(t)){const o=N.get(t);return z?Pt({_cat:z(o)},"_cat",B??void 0):Pt(o,"string"==typeof e?e:"id",B??void 0)}return $[o%$.length]},j=Zi(_&&e?(()=>{const t=new Map;x.forEach((o,n)=>{const i=g(e,o),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:W(g(l,o)+"",n)})});const o=Array.from(t.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,n.legend),{layout:Y,layoutConfig:G,issues:q,xScale:X}=Dh({nodes:w,edges:k,domain:v,plotW:L,plotH:T,ribbonLane:i.ribbonLane||"both",edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:W,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half"}});if(q.length>0){const t=q.map(Ah).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const H=Array.isArray(i.axisTicks)?i.axisTicks:[],V=Y?(()=>{let t=null,e=null;for(const o of w){const n=Y.laneLifetime[o.id];if(!n||null==n.start||null==n.end)continue;const i=Number(X(n.start)),r=Number(X(n.end));t=null==t?i:Math.min(t,i),e=null==e?r:Math.max(e,r)}const o=t=>Math.max(0,Math.min(L,t)),n=o(t??0),s=Math.max(n,o(e??L)),a=H.map((t,e)=>({tick:t,index:e,x:Number(X(r(t.date)))})).filter(({x:t})=>t>=n-.5&&s+.5>=t);return Bh.createElement("g",null,...a.map(({index:t,x:e})=>Bh.createElement("line",{key:"grid-"+t,x1:e,y1:0,x2:e,y2:T,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),Bh.createElement("line",{key:"axis",x1:n,y1:T+4,x2:s,y2:T+4,stroke:"#94a3b8"}),...a.map(({tick:t,index:e,x:o})=>{const n=r(t.date),s=null!=t.label?t.label:"function"==typeof i.timeFormat?i.timeFormat(new Date(n)):"";return Bh.createElement("g",{key:"tick-"+e,transform:`translate(${o},${T+4})`},Bh.createElement("line",{y2:6,stroke:"#94a3b8"}),Bh.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},s))}))})():void 0;return{chartType:"force",nodes:x,edges:m,customNetworkLayout:Eh,layoutConfig:G,sourceAccessor:s,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:e,colorScheme:o,...V&&{backgroundGraphics:V},...n,showLegend:_,...j&&{legend:j,legendPosition:P},__legendIncludesAutomatic:!0,margin:I}}},Yh={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Fh([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=E(n.theme).colors.categorical,a=new Map,c="string"==typeof e?e:"__ssrSankeyColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?Rt(l,c,o??n.colorScheme??s):void 0,d=t=>({fill:e?Pt(t?.data||t,e,u):Ou(void 0,s,o,void 0,a),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=Bt(i.styleRules,e,i.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:n,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=Pt(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=Pt(t.data||t,e,o):t&&(a.fill=n(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:n.nodeStyle||i.nodeStyle||f,edgeStyle:n.edgeStyle||i.edgeStyle||p,colorScheme:o,...n}}},Gh={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{if(!(e||Array.isArray(i.styleRules)&&i.styleRules.length>0||n.nodeStyle||i.nodeStyle))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:o,...n};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Fh([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=E(n.theme).colors.categorical,c=At(o,a),l="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?Rt(u,l,o??n.colorScheme??a):void 0,h=new Map,f=i.nodeIdAccessor||i.nodeIDAccessor||"id",p=(t,o)=>{const i=t?.data||t;let r;if(e)r=Pt(i,e,d);else{const e=(t.id??i?.[f]??"")+"";h.has(e)||h.set(e,h.size);const n=t.index??o??h.get(e);r=c[n%c.length]}return{fill:r,stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},y=Bt(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:o,nodeStyle:n.nodeStyle||i.nodeStyle||y,...n}}},qh={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=E(n.theme).colors.categorical,s=new Map,a=Oh(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreeColorBy:c(t)})):a,u=c?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?Rt(l,u,o??n.colorScheme??r):void 0,h=n.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:o,...n,nodeStyle:Nh(t=>{const a=t?.data||t;return{fill:i.colorByDepth?Mt[Number(t?.depth||0)%Mt.length]:e?c?Pt({__ssrTreeColorBy:c(a)},"__ssrTreeColorBy",d??void 0):Pt(a,e,d??void 0):Ou(void 0,r,o,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},h)}}},Xh={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=E(n.theme).colors.categorical,s=new Map,a=Oh(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreemapColorBy:c(t)})):a,u=c?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?Rt(l,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=n.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!=y&&{paddingTop:y},colorScheme:o,...n,nodeStyle:Nh(t=>{const n=t?.data||t;return{fill:i.colorByDepth?Mt[Number(t?.depth||0)%Mt.length]:e?c?Pt({__ssrTreemapColorBy:c(n)},"__ssrTreemapColorBy",d??void 0):Pt(n,e,d??void 0):Ou(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},g)}}},Hh={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=E(n.theme).colors.categorical,s=new Map,a=Oh(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrCirclePackColorBy:c(t)})):a,u=c?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?Rt(l,u,o??n.colorScheme??r):void 0,h=n.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??n.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,nodeStyle:Nh(t=>{const n=t?.data||t;return{fill:i.colorByDepth?Mt[Number(t?.depth||0)%Mt.length]:e?c?Pt({__ssrCirclePackColorBy:c(n)},"__ssrCirclePackColorBy",d??void 0):Pt(n,e,d??void 0):Ou(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h)}}},Vh={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Uh}from"d3-scale";function Kh(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Zh={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="string"==typeof o?o:"blues",s=i.areaStyle??function(t,e,o,n){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=Uh(ht(o)).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:n}}}(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},Kh):s;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:a,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n}}},Qh={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=t||i.points,s=i.pointStyle??function(t,e,o,n){const i=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",n="string"==typeof e?i:i.map(t=>({...t,__geoColorBy:e(t)}));r=Rt(n,t,o)}if(n.sizeBy){const t=i.map("function"==typeof n.sizeBy?n.sizeBy:t=>t?.[n.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=M(t))}return t=>({fill:e&&r?Pt(t,e,r):kt,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?It(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Ft(s,i.styleRules,zt(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||Vh,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},Jh={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",c=i.xAccessor||"lon",l=i.yAccessor||"lat",u="function"==typeof c?c:t=>t[c],d="function"==typeof l?l:t=>t[l],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,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),o=f.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",b=p?y?Rt(g.map(t=>({[m]:p(t)})),m,o||"category10"):Rt(g,p,o||"category10"):null,x=t=>p&&b?Pt(t,p,b):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[A,S]=i.edgeWidthRange??[1,8],M=S-A,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||Vh,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,n=A+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:x(t),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import*as tf from"react";function ef(t){const[e,o]=t,n=160>e||116>o,i=n?Math.min(12,Math.max(2,.08*e)):32,r=n?Math.min(8,Math.max(2,.12*o)):24,s=n?r:34;return{width:e,height:o,plot:{x:i,y:r,width:Math.max(1,e-2*i),height:Math.max(1,o-r-s)}}}function of(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return o[n%o.length]}function nf(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?Tt(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,c={fill:null==a?e:of(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(c,Ot(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function rf(t,e,o,n){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:o},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...n}}}function sf(t,e,o){return"function"==typeof o?o(t,e):t[o]}function af(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 cf(t,e,o){return Math.max(e,Math.min(o,t))}function lf(t,e){const o=af(t);return null!=o&&o>0?o:e}function uf(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function df(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 hf}from"d3-scale";var ff={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},pf=1e-9,yf=.005;function gf(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function mf(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 bf(t,e,o){return Math.max(e,Math.min(o,t))}function xf(t){return 0>t?-1:1}function vf(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,o=t.shape.height/2;return{minX:t.x-e,minY:t.y-o,maxX:t.x+e,maxY:t.y+o}}function wf(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,o=e.height/2;return{minX:e.x-t,minY:e.y-o,maxX:e.x+t,maxY:e.y+o}}const o=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-o,minY:Math.min(e.y1,e.y2)-o,maxX:Math.max(e.x1,e.x2)+o,maxY:Math.max(e.y1,e.y2)+o}}function kf(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function Af(t,e,o,n,i,r,s,a){const c=i-t,l=(o+s)/2-Math.abs(c);if(0>=l)return null;const u=r-e,d=(n+a)/2-Math.abs(u);return d>0?d>l?{nx:xf(c),ny:0,penetration:l}:{nx:0,ny:xf(u),penetration:d}:null}function Sf(t,e,o,n,i,r,s){const a=r/2,c=s/2;let l=t-bf(t,n-a,n+a),u=e-bf(e,i-c,i+c);const d=l*l+u*u;if(d>o*o)return null;if(pf>=d){const r=Math.abs(t-(n-a)),s=Math.abs(t-(n+a)),d=Math.abs(e-(i-c)),h=Math.abs(e-(i+c)),f=Math.min(r,s,d,h);return f===r?(l=-1,u=0,{nx:l,ny:u,penetration:o+r}):f===s?(l=1,u=0,{nx:l,ny:u,penetration:o+s}):f===d?(l=0,u=-1,{nx:l,ny:u,penetration:o+d}):(l=0,u=1,{nx:l,ny:u,penetration:o+h})}const h=Math.sqrt(d);return{nx:l/h,ny:u/h,penetration:o-h}}function Mf(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,o,n,i,r){const s=n-t,a=i-e,c=o+r,l=s*s+a*a;if(l>=c*c)return null;if(pf>=l)return{nx:1,ny:0,penetration:c};const u=Math.sqrt(l);return{nx:s/u,ny:a/u,penetration:c-u}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return Af(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 o=Sf(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return o?{nx:-o.nx,ny:-o.ny,penetration:o.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?Sf(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function _f(t,e){const o=e.shape;return"aabb"===o.type?"circle"===t.shape.type?Sf(t.x,t.y,t.shape.radius,o.x,o.y,o.width,o.height):Af(o.x,o.y,o.width,o.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,o,n,i,r,s,a=0){const c=r-n,l=s-i,u=c*c+l*l,d=u>pf?bf(((t-n)*c+(e-i)*l)/u,0,1):0,h=o+a/2,f=t-(n+c*d),p=e-(i+l*d),y=f*f+p*p;if(y>=h*h)return null;if(pf>=y){const t=Math.sqrt(u);return t>pf?{nx:-l/t,ny:c/t,penetration:h}:{nx:1,ny:0,penetration:h}}const g=Math.sqrt(y);return{nx:f/g,ny:p/g,penetration:h-g}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,o.x1,o.y1,o.x2,o.y2,o.thickness??0)}function Pf(t,e){return`${t}\0${e}`}function Cf(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Rf(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:gf(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function If(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 Lf(t){return{id:t.id,shape:mf(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:If(t.bodyFilter),index:t.index}}function Tf(t,e){return!!e?.some(e=>Object.is(t,e))}function $f(t,e){const o=t.bodyFilter;if(!o)return!0;if("function"==typeof o)return o(e);const n=function(t,e){if(!e)return;let o=t;for(const t of e.split(".")){if(null==o||"object"!=typeof o)return;o=o[t]}return o}(e,o.property);return!("equals"in o&&!Object.is(n,o.equals)||"notEquals"in o&&Object.is(n,o.notEquals)||o.oneOf&&!Tf(n,o.oneOf)||o.notOneOf&&Tf(n,o.notOneOf))}var zf=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={...ff,...t},this.random=u(this.options.seed)}init(t={}){this.options={...ff,...t},this.random=u(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(pf,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:gf(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))Cf(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:mf(e.shape),bodyFilter:If(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,o){const n=this.bodies.get(t);n&&(n.vx+=e/n.mass,n.vy+=o/n.mass,this.wake(n))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const o=this.sortedBodies();for(const t of o)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const n=this.options.maxVelocity;for(const t of o)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,n>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>n){const o=n/e;t.vx*=o,t.vy*=o}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const i=this.bodyPairKeys(o),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(o,i,0===t),this.resolveColliders(o,r,0===t);this.updateSensors(o),this.updateSleeping(o,e)}settle(t=1200,e=this.options.fixedDt){let o=0;for(;t>o&&!this.allSleeping();)this.step(e),o+=1;return o}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:gf(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Cf)}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(Rf),colliders:this.sortedColliders().map(Lf),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=u(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=Rf(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=Lf(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 o=this.bodies.get(e.bodyId);if(!o||o.sleeping)continue;const n="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!n)continue;const i=n.x-o.x,r=n.y-o.y,s=Math.sqrt(i*i+r*r);if(pf>=s)continue;const a=i/s,c=r/s,l=(s-e.restLength)*e.stiffness+((("vx"in n?n.vx:0)-o.vx)*a+(("vy"in n?n.vy:0)-o.vy)*c)*e.damping;o.vx+=l*a*t/o.mass,o.vy+=l*c*t/o.mass}}resolveBodyPairs(t,e,o){for(const n of e){const[e,i]=n.split(":").map(Number),r=t[e],s=t[i];if(!r||!s)continue;const a=Mf(r,s);a&&(this.resolveDynamicCollision(r,s,a),o&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),o=new Map;for(let n=0;t.length>n;n+=1){if(!1===t[n].bodyCollisions)continue;const i=vf(t[n]),r=Math.floor(i.minX/e),s=Math.floor(i.maxX/e),a=Math.floor(i.minY/e),c=Math.floor(i.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;c>=e;e+=1){const i=`${t}:${e}`,r=o.get(i);r?r.push(n):o.set(i,[n])}}const n=new Set;for(const e of Array.from(o.keys()).sort()){const i=o.get(e)??[];i.sort((t,e)=>t-e);for(let e=0;i.length>e;e+=1)for(let o=e+1;i.length>o;o+=1){const r=i[e],s=i[o];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&kf(vf(t[r]),vf(t[s]))&&n.add(`${r}:${s}`)}}return Array.from(n).sort((t,e)=>{const[o,n]=t.split(":").map(Number),[i,r]=e.split(":").map(Number);return o===i?n-r:o-i})}resolveDynamicCollision(t,e,o){t.sleeping&&this.supportedThisStep.add(e.id),e.sleeping&&this.supportedThisStep.add(t.id);const n=t.sleeping?0:1/t.mass,i=e.sleeping?0:1/e.mass,r=n+i;if(pf>=r)return;const s=Math.max(0,o.penetration-yf)/r;t.x-=o.nx*s*n,t.y-=o.ny*s*n,e.x+=o.nx*s*i,e.y+=o.ny*s*i;const a=(e.vx-t.vx)*o.nx+(e.vy-t.vy)*o.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution))*a/r,u=l*o.nx,d=l*o.ny;t.vx-=u*n,t.vy-=d*n,e.vx+=u*i,e.vy+=d*i,this.applyFriction(t,e,o,l,n,i),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,o,n,i,r){const s=-o.ny,a=o.nx,c=(e.vx-t.vx)*s+(e.vy-t.vy)*a,l=i+r;if(pf>=Math.abs(c)||pf>=l)return;const u=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction))),d=bf(-c/l,-n*u,n*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,o){for(const n of t)for(const t of e){if(!$f(t,n))continue;if(!kf(vf(n),wf(t)))continue;const e=_f(n,t);e&&(this.resolveStaticCollision(n,t,e),this.supportedThisStep.add(n.id),o&&this.lastEvents.push({type:"contact",bodyId:n.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,o){t.x+=o.nx*Math.max(0,o.penetration-yf),t.y+=o.ny*Math.max(0,o.penetration-yf);const n=t.vx*o.nx+t.vy*o.ny;if(0>n){const i=Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution);t.vx-=(1+i)*n*o.nx,t.vy-=(1+i)*n*o.ny;const r=-o.ny,s=o.nx,a=t.vx*r+t.vy*s,c=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction)));t.vx-=a*r*c,t.vy-=a*s*c}}updateSensors(t){const e=new Set,o=this.sortedColliders().filter(t=>t.sensor);for(const n of t){const t=vf(n);for(const i of o){if(!$f(i,n))continue;if(!kf(t,wf(i)))continue;if(!_f(n,i))continue;const o=Pf(i.id,n.id);e.add(o),this.activeSensors.has(o)||this.lastEvents.push({type:"sensor-enter",bodyId:n.id,sensorId:i.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:o,bodyId:n}=Cf(t);this.lastEvents.push({type:"sensor-exit",bodyId:n,sensorId:o})}this.activeSensors=e}updateSleeping(t,e){const o=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const n of t)Math.sqrt(n.vx*n.vx+n.vy*n.vy)>=this.options.sleepSpeed||Math.sqrt((n.x-n.prevX)*(n.x-n.prevX)+(n.y-n.prevY)*(n.y-n.prevY))>=this.options.sleepSpeed*e||o&&!this.supportedThisStep.has(n.id)?n.sleeping?this.wake(n):n.sleepTime=0:(n.sleepTime+=e,n.sleeping||this.options.sleepAfter>n.sleepTime||(n.sleeping=!0,n.vx=0,n.vy=0,this.lastEvents.push({type:"sleep",bodyId:n.id})))}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},Df=class{constructor(t={}){this.id="builtin",this.capabilities={...(new zf).capabilities,engine:"builtin"},this.world=new zf(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,o){this.world.applyImpulse(t,e,o)}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 Ef(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new Df(t)}(e)}var Of=["binId","targetBin","category","windowIndex","lane","group"];function Ff(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 o=e-t.mean;t.mean+=o/t.count,t.m2+=o*(e-t.mean)}function Bf(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 Nf(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 Wf(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function jf(t,e,o){return"function"==typeof t?t(e,o):"string"==typeof t?Wf(e,t):void 0}function Yf(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function Gf(t){const e=Bf(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:Bf(t.x),y:Bf(t.y),value:e}}var qf=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 o=Yf(jf(this.config.binAccessor,t,e))??function(t){for(const e of Of){const o=Yf(Wf(t,e));if(o)return o}return"sediment"}(t),n=Yf(jf(this.config.labelAccessor,t,e))??o,i=function(t,e,o){if("number"==typeof t)return t;const n="function"==typeof t?t(e,o):"string"==typeof t?Wf(e,t):1,i="number"==typeof n?n:Number(n);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(o);return s||(s={id:o,label:n,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(o,s)),s.label=n,s.lastBodyId=t.id,s.lastDatum=t.datum,Ff(s.x,t.x),Ff(s.y,t.y),Ff(s.value,i),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Gf(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Gf)}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:Nf(e.x),y:Nf(e.y),value:Nf(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 Xf(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var Hf={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Vf={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Uf(t={},e=Vf){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 Kf(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function Zf(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 Qf(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function Jf(t){return{...Kf(t),sequence:t.sequence,spawnAt:t.spawnAt}}function tp(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 ep(t){return!1!==t&&{...t}}function op(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function np(t){return{...t,gravity:{...t.gravity}}}function ip(t,e,o,n){if("circle"===t.shape.type){const i=t.x-e,r=t.y-o,s=t.shape.radius+n,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(o-t.y)-t.shape.height/2,0),s=i*i+r*r;return s>n*n?null:s}function rp(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function sp(t,e={}){const{idPrefix:o="plot",includeFloor:n=!0,includeCeiling:i=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=e,l=[],u=t.x+t.width/2,d=t.y+t.height/2;return n&&l.push({id:o+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+c/2,width:t.width+2*a,height:c}}),i&&l.push({id:o+"-ceiling",shape:{type:"aabb",x:u,y:t.y-c/2,width:t.width+2*a,height:c}}),r&&l.push({id:o+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:d,width:a,height:t.height+2*c}}),s&&l.push({id:o+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:d,width:a,height:t.height+2*c}}),l}function ap(t){const{idPrefix:e="bin",count:o,domainStart:n,domainStep:i,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,c)}=t,p=[],y=s+(a-s)/2,g=Math.abs(a-s),m=l?o:o-1;if(u||l)for(let t=l?0:1;m>=t;t+=1){if(!u&&t>0&&o>t)continue;const s=r(n+t*i);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:y,width:c,height:g}})}if(null!=d)for(let t=0;o>t;t+=1){const o=n+t*i,s=o+i;if(s>=d)continue;const a=r(o),l=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:f}})}return p}import{quadtree as cp}from"d3-quadtree";var lp=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,o,n,i,r=0){const s=this.ensure(t,e);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,u=n-l,d=n+l,h=i-l,f=i+l;return s.visit((t,e,s,l,p)=>{if(u>l||e>d||h>p||s>f)return!0;if(t.length)return!1;let y=t;for(;y;){const t=y.data;if(t){const e=ip(t,n,i,Math.max(0,r));null!=e&&(c>e||e===c&&o.indexOf(t.id)>o.indexOf(a?.id??""))&&(a=t,c=e)}y=y.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const o=t.readState();return 0===o.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=o.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=cp().x(t=>t.x).y(t=>t.y).addAll(o),this.revision=e,this.tree)}},up=["data","scene-geometry","data-paint","accessibility","evidence"],dp=["scene-geometry","data-paint","accessibility","evidence"],hp=["overlay","accessibility","evidence"],fp=(t,e)=>({retainedData:t,invalidations:e}),pp=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],yp=["scene-geometry","data-paint","accessibility","evidence"],gp=[],mp={engine:fp("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:fp("preserve",yp),colliders:fp("preserve",yp),sediment:fp("preserve",yp),bodyBudget:fp("preserve",pp),bodyLimit:fp("preserve",pp),eviction:fp("preserve",pp),fixedDt:fp("preserve",gp),maxDeltaSeconds:fp("preserve",gp),maxSubsteps:fp("preserve",gp),settleStepLimit:fp("preserve",gp),timeScale:fp("preserve",gp),observation:fp("preserve",gp)},bp=fp("preserve",pp);function xp(t){let e="preserve";const o=new Set;for(const n of t){const t=mp[n]??bp;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}var vp=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function wp(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&vp.every(o=>t[o]===e[o])}function kp(t,e,o,n){return t||!e?"paused":o||!n?"running":"settled"}var Ap=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,o){if(o>0)return void(this.seconds=0);const n=t.readState(this.scratch),i=this.speed*this.speed;let r=!0;for(const t of n)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}},Sp=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new lp,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Yo,this.simulationState="settled",this.visible=!0,this.quiescence=new Ap;const{bodyBudget:e,colliders:o,engine:n,kernel:i,observation:r,sediment:s,...a}=t;this.config={...Hf,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=n,this.observation=Uf(r),this.sediment=new qf(s??!1),this.world=Ef(n,{fixedDt:this.config.fixedDt,...i}),this.quiescence.setKernelOptions(i),o&&this.world.setColliders(tp(o))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(o=>"kernel"===o?!wp(t.kernel,e.kernel):t[o]!==e[o])}(t,this.configInput),{colliders:o,bodyBudget:n,engine:i,kernel:r,observation:s,sediment:a,...c}=t;if(this.config={...this.config,...c},void 0!==n&&(this.bodyBudget=n,!1===n&&(this.bodyBudgetObservationKey="ok")),i&&i!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=i,this.world=Ef(i,t.options),this.world.restore(t),this.revision+=1}if(r&&!wp(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=Uf(s,this.observation)),this.sediment.updateConfig(a),o&&(this.world.setColliders(tp(o)),this.revision+=1),this.configInput={...this.configInput,...t};const l=xp(e);this.updateResults.record({kind:"config",keys:e},l.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(tp(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},xp(["colliders"]).invalidations)}enqueue(t,e){const o=Array.isArray(t)?t:[t],n=e?function(t,e={}){const o=Zf(e.startAt)??0,n=e.pacing??"immediate";if("arrival"===n){const n=t.map((t,o)=>function(t,e,o){return"function"==typeof o?Zf(o(t,e)):"string"==typeof o?Zf(Qf(t,o)):Zf(t.spawnAt)??Zf(Qf(t,"arrivalTime"))??Zf(Qf(t,"timestamp"))??Zf(Qf(t,"time"))??Zf(Qf(t,"eventTime"))}(t,o,e.timeAccessor)),i=n.filter(t=>null!=t),r=i.length>0?Math.min(...i):0,s=Zf(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const i=n[e],s=null==i?0:Math.max(0,i-r);return{...Kf(t),spawnAt:o+s/a}})}if("object"==typeof n){const e=Zf(n.ratePerSec);if(e&&e>0)return t.map((t,n)=>({...Kf(t),spawnAt:o+n/e}))}return t.map(t=>({...Kf(t),spawnAt:o}))}(o,{...e,startAt:e.startAt??this.elapsedSeconds}):o;for(const t of n)this.queue.push({...Kf(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(op),n.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:n.length},n.length?up:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(Kf(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},up)}materializeDueSpawns(){const t=this.revision,e=[],o=[];return this.spawnDue(e,o),0===e.length||(this.observeBodyBudget(o),this.evictOverflow(o),this.syncSimulationState(o),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?up:[])),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"},up)}tick(t){const e=this.revision,o=[],n=[],i=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,n,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(o,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);n.push(...l.evicted),i.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,o.length),(u>0||o.length>0||n.length>0||i.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,o,n,i,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?o.length||n.length||i.length?up:dp:[]),d}settle(t=this.config.settleStepLimit){const e=this.revision;this.spawnDue([],[]);const o=this.world.settle(t,this.config.fixedDt);return o>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:o},this.revision!==e?dp:[]),o}settleWithObservations(t=this.config.settleStepLimit){const e=this.revision,o=[],n=[],i=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,n,i,r,s,!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(o,s);const a=this.observeBodyBudget(s),c=this.evictOverflow(s);n.push(...c.evicted),i.push(...c.sedimented),this.syncSimulationState(s);let l=0;for(o.length>0&&this.quiescence.reset();t>l&&!this.atRest();){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),l+=1,this.quiescence.refresh(this.world,this.config.fixedDt,0)}(l>0||o.length>0||n.length>0||i.length>0||r.length>0)&&(this.revision+=1);const u=this.result(l,o,n,i,r,s,void 0,a);return this.updateResults.record({kind:"settle",count:l},this.revision!==e?o.length||n.length||i.length?up:dp:[]),u}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:o=0,binWidth:n=24,gap:i=2,maxHeight:r=80,value:s="count",x:a}=e,c=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const l=Math.max(0,t[s]/c*r),u=a?.(t,e)??e*(n+i);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:o-l,width:n,height:l,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,o=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,o)}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:o,chartId:n,...i}=t,r={...i,timestamp:e??this.elapsedSeconds,chartType:o??this.observation.chartType,chartId:n??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?hp:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?hp:[])}remove(t){const e=new Set(t),o=new Set(this.liveBodyOrder),n=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=>o.has(t)||n.has(t));return i.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:i,count:i.length},i.length?up:[]),i}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},dp),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},dp)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},dp)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,o,n)=>t.applyImpulse(e,o,n),clear:()=>t.clear(),hitTest:(e,o,n)=>t.hitTest(e,o,n),pause:()=>t.setPaused(!0),push:(e,o)=>t.enqueue(e,o),pushMany:(e,o)=>t.enqueue(e,o),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:ep(this.bodyBudget),config:{...this.config,kernel:np(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Jf),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:ep(t.bodyBudget??{}),kernel:np(t.world.options)},this.bodyBudget=ep(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(Jf).sort(op),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??kp(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"},up)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const o=this.queue.shift();if(!o)return;this.spawnOne(o,e),t.push(o.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 o=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:o?.datum??t.datum,x:o?.x??t.x,y:o?.y??t.y},e)}result(t,e,o,n,i,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:o,events:i,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:n,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,o){if(0===e.length)return;const n=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=n.get(t.bodyId);o.emit({type:"physics-settle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.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,o){const n=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===n.size&&0===e.size)return n;const i=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:n,bodyId:r}=rp(e),s=o.observation.sensors[n],a=i.get(r);o.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:n,binId:s?.binId??n})};for(const t of Array.from(n).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())n.has(t)||r("exit",t);return n}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const o of t)e.has(rp(o).bodyId)&&t.delete(o)}(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)),o=Math.max(0,Math.floor(t.queuedBodies??0)),n=e+o,i=Xf(t.bodyLimit),r=Xf(t.engineMaxBodiesHint),s=function(t,e,o){if(!1===o)return;const n=Xf(o?.warnAt);return null!=n?n: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),c=a>0?"overflow":null==s||s>n?"ok":"warning";return{action:"overflow"!==c?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:i,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:n,queuedBodies:o,state:c,warnAt:s}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const o=`${e.state}:${e.action}`;return o===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=o,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=kp(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const o=this.simulationState;this.simulationState=e,function(t,e,o){o.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||o.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,simulationState:e,previousSimulationState:t})}(o,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:o,liveBodyOrder:n}=function(t,e,o,n,i,r){const s={evicted:[],sedimented:[],liveBodyOrder:i};if(!1===o)return s;const a=Math.max(0,Math.floor(n));if(!Number.isFinite(a))return s;const c=i.length-a;if(0>=c)return s;const l=function(t,e,o){if("sleeping-first"!==e)return o.slice();const n=new Map(t.readState().map(t=>[t.id,t.sleeping])),i=[],r=[];for(const t of o)n.get(t)?i.push(t):r.push(t);return[...i,...r]}(t,o,i),u=l.slice(0,c);if(0===u.length)return s;const d=function(t,e,o,n){const i=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of o){const o=i.get(t);if(!o)continue;const s=e.add(o);s&&(r.push(t),n.emit({type:"physics-sediment",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:t,datum:o.datum,x:o.x,y:o.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=n,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:o}}};import{scaleLinear as Mp}from"d3-scale";function _p(t){const{count:e,idPrefix:o,wallThickness:n,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const c=Math.min(r-1,a?.(e)??s),l=Math.max(1,r-c);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:c+l/2,width:n,height:l}}})}import{scaleLinear as Pp}from"d3-scale";function Cp(t){if(Array.isArray(t)&&t.length>=2){const e=af(t[0]),o=af(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=af(e.x),n=af(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Rp(t){return Array.isArray(t)?t.map(Cp).filter(t=>null!=t):[]}function Ip(t,e,o){return"normalized"===o?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:cf(t.x,e.plot.x,e.plot.x+e.plot.width),y:cf(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Lp(t){let e=0;for(let o=1;t.length>o;o+=1)e+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y);return e}function Tp(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=cf(e,0,1)*Lp(t);let n=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(n+s>=o){const t=(o-n)/s;return{x:i.x+(r.x-i.x)*t,y:i.y+(r.y-i.y)*t}}n+=s}}return{...t[t.length-1]}}function $p(t,e){const o=Tp(t,Math.max(0,e-.02)),n=Tp(t,Math.min(1,e+.02)),i=n.x-o.x,r=n.y-o.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function zp(t,e,o){return Math.max(e,Math.min(o,t))}function Dp(t,e,o,n,i,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:o,x2:n,y2:i,thickness:r.thickness??8}}}function Ep(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,o=t.y,n=t.width,i=t.height,{type:"aabb",x:e,y:o,width:n,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,o,n,i}function Op(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...Ep({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function Fp(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 Bp(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,n=ef(o),i=cf(t.ballRadius??6,2,18),r=t.seed??1,s=df(r),a=t.idAccessor,c=t.stageAccessor??"stage",l=t.groupBy,u=t.groupLabelAccessor,d=t.workAccessor,h=t.radiusAccessor,f=t.groupCompletion??(l?"allAbsorbed":"none"),p=t.springStiffness??.28,y=t.springDamping??.72,g=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),b=function(t){const e=t.shape??"lane",o=Math.max(1,Math.round(t.width)),n=Math.max(1,Math.round(t.height)),i=t.padX??46,r=t.padY??72,s=i,a=o-i,c=r,l=n-Math.max(24,Math.round(.45*r)),u=(c+l)/2,d=Math.max(1,l-c),h=zp(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=zp(d*h+p,.06*d,.5*d),g=y/2,m=u-g,b=u+g,x=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,A=t.stages;if(!A.length)throw Error("processStageLayout requires at least one stage");const S=zp(t.centerStageIndex??Math.floor(A.length/2),0,A.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(A),_=a-s;let P=s;const C=A.map((t,e)=>{const o=P,n=e===A.length-1?a:P+(t.share??1)/M*_;return P=n,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:o,x1:n,x:(o+n)/2,width:n-o,y:u,height:d}}),R=C[S],I=R.x0,L=R.x1,T=(t,o)=>{if("lane"===e)return"top"===o?c:l;if("funnel"===e){const e=zp((t-s)/Math.max(1,a-s),0,1);return"top"===o?c+(m-c)*e:l+(b-l)*e}if(I>=t){const e=zp((t-s)/Math.max(1,I-s),0,1);return"top"===o?c+(m-c)*e:l+(b-l)*e}if(L>=t)return"top"===o?m:b;const n=zp((t-L)/Math.max(1,a-L),0,1);return"top"===o?m+(c-m)*n:b+(l-b)*n},$=C.map(t=>{const e=Math.min(T(t.x0,"top"),T(t.x1,"top")),o=Math.max(T(t.x0,"bottom"),T(t.x1,"bottom"));return{...t,y:(e+o)/2,height:Math.max(1,o-e)}}),z={thickness:k,friction:v,restitution:w},D=[];"lane"===e?D.push(Dp(x+"-top",s,c,a,c,z),Dp(x+"-bottom",s,l,a,l,z),Dp(x+"-left",s,c,s,l,{...z,thickness:Math.max(6,k-2)}),Dp(x+"-right",a,c,a,l,{...z,thickness:Math.max(6,k)})):"funnel"===e?D.push(Dp(x+"-top",s,c,a,m,z),Dp(x+"-bottom",s,l,a,b,z),Dp(x+"-left",s,c,s,l,{...z,thickness:Math.max(6,k-2)}),Dp(x+"-right",a,m,a,b,{...z,thickness:Math.max(6,k)})):D.push(Dp(x+"-left-top",s,c,I,m,z),Dp(x+"-left-bottom",s,l,I,b,z),Dp(x+"-center-top",I,m,L,m,z),Dp(x+"-center-bottom",I,b,L,b,z),Dp(x+"-right-top",L,m,a,c,z),Dp(x+"-right-bottom",L,b,a,l,z),Dp(x+"-left",s,c,s,l,{...z,thickness:Math.max(6,k-2)}),Dp(x+"-right",a,c,a,l,{...z,thickness:Math.max(6,k)}));const E=t.membraneDampingScale??.5,O=s,F=Math.max(1,("bowtie"===e?I:a)-O),B=(t.membranes??[]).map(t=>{const e=O+zp(t.offset,0,1)*F,o=t.width??18+18*t.cost,n=d-16,i=u+.25*(t.wobble??0);return{...t,x:e,y:i,width:o,height:n}}),N=!1===t.includeMembraneRegions?[]:B.map(t=>function(t){const e=t.dampingScale??.5,o=t.energyScale??1,n=zp(t.cost,0,2);return{...Ep({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:n,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:n*e,energyDelta:-n*o}}({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??E,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:o,height:n,padX:i,padY:r,left:s,right:a,topY:c,bottomY:l,midY:u,centerLeft:I,centerRight:L,pinchHeight:y,pinchTop:m,pinchBottom:b,stages:$,membranes:B,colliders:D,regionEffects:N,boundaryY:T}}({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,n.plot.x),padY:Math.max(36,n.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],A=new Set(e.filter(t=>t.absorb).map(t=>t.id)),S=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const o={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{...Ep({...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"}}({...o,kind:t.kind??"sink",force:Fp(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return n={...o,kind:t.kind??"force-field",force:Fp(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...Ep({...n,kind:n.kind??"force-field",attributes:{primitive:"portal",targetStage:n.targetStage,..."object"==typeof n.attributes&&n.attributes?n.attributes:{}}}),force:n.force,impulseOnEnter:n.impulseOnEnter,damping:n.damping??.08}}var n;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{...Ep({...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}}({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Fp(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.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,o=t.baseDamping??.08,n=t.dampingPerUnit??.12,i=t.energyPerUnit??0;return{...Ep({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o+e*n,energyDelta:i?-e*i:void 0,force:t.force}}({...o,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:Fp(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?Op({...o,kind:t.kind??"force-field",force:Fp(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):function(t){return{...Ep({...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}}({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:b.midY,width:e.width,height:b.bottomY-b.topY})});S.unshift(Op({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 o=(a?sf(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(sf(t,e,c)??w)+"",r=x.has(n)?n:w;M.set(r,(M.get(r)??0)+1);const s=l?(sf(t,e,l)??"")+"":void 0,f=s&&u?(sf(t,e,u)??s)+"":s,p=d?af(sf(t,e,d))??1:1,y=h?af(sf(t,e,h)):null,g=cf(null!=y&&y>0?y:i,2,18);_.push({datum:t,id:o,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:g,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 R=cf(t.groupAnchorAlong??.55,.15,.9),I=b.left+(b.right-b.left)*R,L=Array.from(P.keys()),T=L.map((t,o)=>{const n=P.get(t)??[],i=L.length>1?b.topY+28+o/Math.max(1,L.length-1)*(b.bottomY-b.topY-56):b.midY;return function(t){const e=t.x??t.anchor?.x??0,o=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:o,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:o},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:C.get(t)??t,bodyIds:n,anchor:{x:I,y:i},x:I,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 o=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],n=e.filter(t=>!o.has(t)),i=e.length-n.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s?.[t];return Number.isFinite(e)&&Number(e)>=0?Number(e):1},c=e.reduce((t,e)=>t+a(e),0),l=e.reduce((t,e)=>t+(o.has(e)?a(e):0),0),u=t.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):c:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?i>0:"threshold"===r?l>=(d??c):0===n.length),absorbed:i,total:e.length,absorbedValue:l,totalValue:c,threshold:d,missing:n}})}(T,_.filter(t=>A.has(t.stageId)).map(t=>t.id)),z=new Map(T.map(t=>[t.id,t])),D=_.map((t,e)=>{const o=v.get(t.stageId)??k,n=o.x+(s()-.5)*Math.min(24,.2*o.width),i=b.boundaryY(n,"top")+t.radius+10,r=b.boundaryY(n,"bottom")-t.radius-10,a=r>i?i+s()*Math.max(1,r-i):b.midY,c=g?n:b.left+18+e%7*4,l=g?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,u=[{target:{type:"point",x:n,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=z.get(t.groupId);e?.anchor&&!A.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:c,y:l,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),E={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},O=b.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),F=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:E,initialSpawns:D,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:O,metadata:{kind:"process-flow",plot:n.plot,volume:b,stages:F,groups:T,groupCompletion:$,regionEffects:S}}}import{scaleLinear as Np}from"d3-scale";function Wp(t,e,o){return At(t,e,o)}function jp(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&Ct(o,t)||"#4e79a7":e=>{if(o){const t=Ct(o,e);if(t)return t}let n=0;for(let t=0;e.length>t;t++)n=31*n+e.charCodeAt(t)|0;return t[Math.abs(n)%t.length]??"#4e79a7"}}function Yp(t,e){const o=e.config??{},n=(e.sensors??[]).map(t=>({...t,sensor:!0})),i=[...e.colliders??[],...n],r=[...t.colliders??[],...o.colliders??[],...i];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function Gp(t){const e=Kp(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 qp(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function Xp(t){return`gauntlet:${t}:core`}function Hp(t,e){return`gauntlet:${t}:positive:${e}`}function Vp(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Up={left:28,top:76,rightInset:30,thickness:8};function Kp(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Up;const o=Math.max(1,Math.min(t.width,e)),n=Math.max(2,.04*t.width);return{left:n,top:Math.max(2,.08*e),rightInset:n,thickness:Math.max(1,Math.min(4,.04*o))}}function Zp(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Qp(t,e,o,n){const i=Kp(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,c=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:c(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:c(e,s,a)}}function Jp(t,e,o=1){const n=[...t].sort((t,e)=>t.localeCompare(e)),i=Math.max(0,n.indexOf(e));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*o}}function ty(t,e,o){const n=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),i=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(o.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*n-8*r-1.2*t.delay-5*i))}function ey(t){const e=function(t,e,o){const[n,i]=t,r=220>n||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,c=(e??[]).filter(t=>!1!==t.enabled),l=Math.max(1,c.length),u=.22*n,d=l>1?(.78*n-u)/(l-1):0,h=r?Math.max(Math.round(.12*n),.08*n+6):Math.max(Math.round(.14*n),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*i)):o),floorY:a,gates:c.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*n))})),graveyardX:Math.round(n*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(n*(r?.82:.92)),startX:h,width:n}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],n=new Map(o.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,o,n,i){const r=qp(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...qp(t,e,o.positiveAccessor,s)],c=[...qp(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...qp(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(qp(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:qp(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??ty(a,n,i)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,n){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}}(o),r=n?.(t,e,o)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,n,i,r,s){const a=Zp(o),c=Math.max(3,28*a),l=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??l,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},y=[{...d,id:Xp(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:c},spawnAt:d.spawnAt??t.startedAt,datum:p}],g=Qp(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||c,o);y[0].x=g.x,y[0].y=g.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=Jp(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),c=Qp(g.x+Math.cos(r.angle)*r.radius,g.y+Math.sin(r.angle)*r.radius,s,o);y.push({id:Hp(t.id,e),x:c.x,y:c.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:n.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:n,sourceDatum:t.datum},springs:!1===n.spring?[]:[{target:{type:"body",bodyId:Xp(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return t.negativeIds.forEach((e,n)=>{const i=r.get(e);i&&y.push(function(t,e,o,n,i,r,s){const a=Zp(r),c=e.radius??Math.max(2,7.2*a),l=Qp(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,c,r);return{id:Vp(t.id,e.id,o),x:l.x,y:l.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:Xp(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,g.x,g.y,o,d.spawnAt??t.startedAt))}),y}(o,r,e,s,n,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:Gp(e)}}}var oy=1e-9;function ny(t,e){return e>t?-1:t>e?1:0}function iy(t){return{...t}}function ry(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 sy(t){const e=Object.fromEntries(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:iy(e.initialMetrics),metrics:iy(e.metrics),productIds:[...e.productIds],history:ry(e.history)}])),o=Object.fromEntries(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:iy(e.metrics),sourceIds:[...e.sourceIds],history:ry(e.history)}])),n=Object.fromEntries(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?iy(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:iy(t.input.metrics)},metrics:iy(t.metrics),loss:{amount:t.loss.amount,metrics:iy(t.loss.metrics)},history:ry(t.history)}}function ay(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function cy(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(ny)}function ly(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[ay("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function uy(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function dy(t,e,o="selector"){const n=[],i=Object.values(t.components),r=new Set(i.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&n.push(ay("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||n.push(ay("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),n.some(t=>"error"===t.severity))return{ids:[],diagnostics:n};const a=e.ids?new Set(e.ids):null,c=e.categories?new Set(e.categories):null,l=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=>!c||c.has(t.category)).filter(t=>!l||l.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(ny);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(ay("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function hy(t,e,o={}){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,...o}}function fy(t,e){const o={...e,eventId:t.event.id};t.materializations.push(o),t.observations.push({...o,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function py(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(ay("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function yy(t,e,o){const n=cy(e);e.length||t.diagnostics.push(ay("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(ay("error","duplicate-source",`Source ids may appear only once: ${n.join(", ")}.`,o,n));const i=e.filter(e=>!t.state.components[e]);i.length&&t.diagnostics.push(ay("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(ay("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(ay("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function gy(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+oy)&&t.diagnostics.push(ay("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...ly(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+oy)&&t.diagnostics.push(ay("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 my(t,e,o,n,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:o,metrics:r&&t.metrics?{...n,...t.metrics}:n,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 by(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>oy&&t.diagnostics.push(ay("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function xy(t,e,o){const n=`events.${t.event.id}.effects.${o}`,i=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(ay("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...ly(e.metricsDelta,n+".metricsDelta")),py(t,e.outletId,n+".outletId");const o=dy(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(ay("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=hy(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=i.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&uy(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&fy(t,{type:"retarget-component",sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:o}=e;o.id&&!i.relations[o.id]||t.diagnostics.push(ay("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,n+".relation.id",[o.id]));const r=function(t,e,o){const n=cy(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(ay("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(ay("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(ay("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,n+".relation.sourceIds");if(t.diagnostics.push(...ly(o.metrics,n+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;i.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?{...o.metrics}:void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=hy(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void fy(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=cy(e.relationIds),r=e.relationIds.filter(t=>!i.relations[t]),s=e.relationIds.filter(t=>"resolved"===i.relations[t]?.status);if(o.length&&t.diagnostics.push(ay("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(ay("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(ay("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,n+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const n=i.relations[o];n.status="resolved",n.resolution=e.resolution,n.resolvedByEventId=t.event.id,n.resolvedAt=t.context.appliedAt,n.reason=e.reason}const a=hy(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void fy(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const o=t.productDefinitions.get(e.productId);o||t.diagnostics.push(ay("error","unknown-product",`Product "${e.productId}" has no declared mold.`,n+".productId",[e.productId]));const r=i.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(ay("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(ay("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=yy(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,c=function(t,e,o,n){if(!e?.length)return[];const i=cy(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),c=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(ay("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(ay("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(ay("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),c.length&&t.diagnostics.push(ay("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,n,c)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!c||!o||t.diagnostics.some(t=>"error"===t.severity))return;const l=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e={};for(const o of t)uy(e,o.metrics);return e}(s);if(!gy(t,l,u,e.loss,n+".loss"))return;const d=l-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))e[n]=Number(e[n]??0)-i,t.state.loss.metrics[n]=Number(t.state.loss.metrics[n]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=hy(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&by(t,o,d,n+".productId"),p=my(o,e.sourceIds,d,u,t,h,f),h&&!py(t,p.outletId,n+".productId"))return;i.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,uy(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 o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;fy(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,c),fy(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&&fy(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const o=i.products[e.productId];return o?void function(t,e,o,n,i,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!py(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(ay("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(by(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=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const c=hy(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(c),t.state.history.push(c),fy(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,n):void t.diagnostics.push(ay("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=yy(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(ay("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=cy(r);s.length&&t.diagnostics.push(ay("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),c=r.filter((t,e)=>!a[e]),l=r.filter(t=>i.products[t]);c.length&&t.diagnostics.push(ay("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,n+".products",c)),l.length&&t.diagnostics.push(ay("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,n+".products",l));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(ay("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...ly(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!gy(t,u.amount,u.metrics,e.loss,n+".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(ay("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const p=f?h:e.products.map(()=>d/e.products.length),y=p.reduce((t,e)=>t+e,0);if(Math.abs(y-d)>oy)return void t.diagnostics.push(ay("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,n+".products"));const g={...u.metrics};for(const[t,o]of Object.entries(e.loss?.metrics??{}))g[t]=Number(g[t]??0)-o;const m=hy(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],c=d>oy?p[r]/d:1/e.products.length,l=Object.fromEntries(Object.entries(g).map(([t,e])=>[t,e*c])),h=o.metrics??s.metrics??l,f=my({...s,amount:p[r],metrics:h},[u.id],p[r],{...h},t,!0,m);py(t,f.outletId,`${n}.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,o]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+o;i.history.push(m),fy(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)fy(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){py(t,e.outletId,n+".outletId");const o=dy(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(ay("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=hy(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=i.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return i.history.push(s),void(o.ids.length&&fy(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...ly(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)uy(i.metrics,e.metricsDelta);else if("components"in e.target){const r=dy(i,e.target.components,n+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;o=r.ids;for(const t of r.ids)uy(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=cy(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(ay("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(ay("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,n+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)uy(i.products[t].metrics,e.metricsDelta)}return void i.history.push(hy(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(hy(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(ay("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function vy(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[ay("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=sy(t),i={state:n,event:e,context:o,productDefinitions:new Map(o.products.map(t=>[t.id,t])),outletIds:new Set(o.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,n]of e.effects.entries())if(xy(i,n,o),i.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:i.diagnostics};return n.elapsed=Math.max(n.elapsed,o.appliedAt),n.phaseId=o.phaseId,n.eventsApplied.push(e.id),i.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:n,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var wy=[900,520],ky=[{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}],Ay=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Sy=1e-9;function My(t,e){return e>t?-1:t>e?1:0}function _y(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Py(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(My)}function Cy(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Ry(t,e,o,n,i,r){if(!o)return n;try{return("function"==typeof o?o(t,e):t[o])??n}catch(t){return i.push(_y("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function Iy(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(_y("error","invalid-metrics","Metrics must be a numeric object.",o)),{};const n={};for(const[i,r]of Object.entries(t)){const t=Cy(r);null!=t?n[i]=t:e.push(_y("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function Ly(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 Ty(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:c,restitution:l}=t,u=function(t,e,o){const n=o.map(([o,n])=>[Math.max(t,Math.min(o,n)),Math.min(e,Math.max(o,n))]).filter(([t,e])=>e>t+Sy).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+Sy&&i.push([r,t]),r=Math.max(r,e);return e>r+Sy&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:c,restitution:l,shape:"horizontal"===o?{type:"segment",x1:t,y1:n,x2:i,y2:n,thickness:a}:{type:"segment",x1:n,y1:t,x2:n,y2:i,thickness:a}}))}function $y(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function zy(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?$y(t):1}function Dy(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:zy(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ey(t){return"crucible:component:"+encodeURIComponent(t)}function Oy(t,e,o,n){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const i=Math.min(...e,t),r=Math.max(...e,t);return r-i>Sy?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function Fy(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),n=t?.[0]??7*o,i=t?.[1]??18*o,r=Math.max(1,Math.min(n,i));return[r,Math.max(r,Math.max(n,i))]}function By(t,e){if(!t)return[];const o=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),n=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,i)=>({x:e.x+e.width/o*(i%o+.5),y:e.y+(Math.floor(i/o)+.5)*(e.height/n)}))}function Ny(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 Wy(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 jy(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>My(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>My(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=Fy(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",n=o.get(t)??[];n.push(e),o.set(t,n)}const n=new Map;for(const[t,i]of o){i.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||My(t.id,e.id));const o=By(i.length,Wy(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),c=n.map(t=>{const n=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},i=1.28*Oy(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(l=t.id,"crucible:product:"+encodeURIComponent(l)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:c};var l}),l=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=Ny(t)??"__chamber__",o=l.get(e)??[];o.push(t),l.set(e,o)}const u=new Map;for(const[t,o]of l){const n=By(o.length,Wy(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,n[e]))}return[...i.map(t=>{let n=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){n={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const i=$y(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));n={x:n.x+Math.cos(i)*r,y:n.y+Math.sin(i)*r}}}n??(n={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const i=Oy(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ey(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:c}}),...c]}var Yy=jy;function Gy(t){return Array.isArray(t)?t.map(Gy):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>My(t,e)).map(([t,e])=>[t,Gy(e)])):t}function qy(t,e=t.duration){const o=function(t,e){const o=Cy(e)??0,n=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:n,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=n>=t.duration-Sy,r=i?t.phases[t.phases.length-1]:t.phases.find(t=>n>=t.start&&t.end>n)??t.phases[0];return{elapsed:n,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,n-r.start),complete:i}}(t,e);let n=sy(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+Sy)break;const a=vy(n,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&&(n=a.state)}return n.elapsed=o.elapsed,n.phaseId=o.phaseId,n.phaseIndex=o.phaseIndex,n.phaseElapsed=o.phaseElapsed,n.complete=o.complete,o.complete&&"in_process"===n.outcome&&(n.outcome="complete"),n.playing=!1,{state:n,diagnostics:i,materializations:r,observations:s}}function Xy(t){const e=function(t){const e=[];t.length||e.push(_y("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Py(t.map(t=>t.id));o.length&&e.push(_y("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=Cy(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(_y("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(_y("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(_y("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.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:o,start:n,end:n+r};return n=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,n=Ly(t.outlets??ky),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?{...t.metrics}:void 0})),r=function(t,e,o){const n=[],i=Py(t.map(t=>t.id));i.length&&n.push(_y("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,c;if(t.id.trim()||n.push(_y("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=Cy(t.at.time);if(null==r||0>r||r>o+Sy)return void n.push(_y("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${i}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const l=function(t,e,o){const n=t.find(t=>Sy>=Math.abs(t.start-o));if(n)return{phase:n,boundaryRank:1};const i=t.find(t=>o>=t.start&&t.end>o);return i?{phase:i,boundaryRank:0}:Sy>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=l.phase,c=l.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(_y("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${i}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void n.push(_y("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*o,c=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):n.push(_y("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:n}}(t.events??[],e.phases,o),s=function(t){const e=[],o={},n=[];let i=0;const r={};t.data.forEach((s,a)=>{const c=(s.id??"component-"+a)+"",l=((Ry(s,a,t.idAccessor,c,e,`data.${a}.id`)??c)+"").trim();if(!l)return void e.push(_y("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(l);const u=Cy(Ry(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(_y("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=Iy(Ry(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=Ry(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=Ay.has(f)?f:"active";Ay.has(f)||e.push(_y("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[l]));const y=Ry(s,a,t.labelAccessor,(s.label??s.name??l)+"",e,`data.${a}.label`)+"",g=Ry(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";o[l]||(o[l]={id:l,label:y,category:g,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},i+=d,function(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}(r,h))});const s=Py(n);s.length&&e.push(_y("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=Iy(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:o,products:{},relations:{},input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:e}}(t),a=function(t=wy,e=ky){const o=Math.max(1,Cy(t[0])??900),n=Math.max(1,Cy(t[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},c=i?Math.max(16,.14*n):Math.min(78,.16*n),l={x:r,y:n-r-c,width:Math.max(1,o-2*r),height:c},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=l.y-(i?10:34),f={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,i?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},g=Ly(e),m={left:g.filter(t=>"left"===(t.side??"bottom")),right:g.filter(t=>"right"===t.side),bottom:g.filter(t=>"bottom"===(t.side??"bottom"))},b=[],x=(t,e)=>{const n=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:o-r-n,y:f.y+a*s,width:n,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,l.y-f.y-f.height-(i?4:12))})}),b.sort((t,e)=>g.findIndex(e=>e.id===t.id)-g.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:f,mouth:y,projection:l,outlets:b}}(t.size??wy,n),c=function(t){const{chamber:e,mouth:o}=t,n=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),i=Math.max(e.x,o.x),r=Math.min(e.x+e.width,o.x+o.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:n}},{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:n}}];a.push(...Ty({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:n,friction:.46,restitution:.12}),...Ty({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:n,friction:.46,restitution:.12}),...Ty({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:n,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),l=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=Py(e.map(t=>t.id)),r=Py(t.map(t=>t.id));return i.length&&o.push(_y("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(_y("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(_y("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(_y("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(_y("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||o.push(_y("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||n.has(t.outletId)||o.push(_y("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),Iy(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>My(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:o,description:n,intensity:i,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:n,events:r.events.map(({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(Gy(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>My(t.id,e.id)),i=n.map(t=>t.amount),r=Fy(o.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}}(zy(o.seed)),a=e.mouth.x+e.mouth.width/2,c=e.chamber.y+Math.max(18,.18*e.chamber.height),l=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return n.map((t,e)=>{const d=e/Math.max(1,n.length)*Math.PI*2+.18*(s()-.5),h=Oy(t.amount,i,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ey(t.id),x:a+Math.cos(d)*l*(.45+.45*s()),y:c+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,...l],p={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:c,config:Dy(t.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},y=qy(p),g=Object.values(y.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=g.length?[_y("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=y.state,p.terminalSpawns=Yy(y.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...y.diagnostics,...m],p}import*as Hy from"react";import{jsx as Vy,jsxs as Uy}from"react/jsx-runtime";function Ky(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 Zy(t,e,o,n){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",c="number"==typeof e.strokeWidth?e.strokeWidth:1.25,l="number"==typeof e.opacity?e.opacity:.96,u=n?`${n}-crucible-body-${o}`:"crucible-body-"+o;if("product"===i.kind){const e=Array.from({length:6},(e,o)=>{const n=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(n)*r},${t.y+Math.sin(n)*r}`}).join(" "),o=u+"-glow";return Uy(Hy.Fragment,{children:[Vy("defs",{children:Vy("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Vy("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Vy("polygon",{points:e,fill:s,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),Vy("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-background, #fffaf0)",strokeWidth:c,opacity:.72*l})]},u)}return Uy(Hy.Fragment,{children:[Vy("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:c,opacity:l}),Vy("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 Qy,jsx as Jy,jsxs as tg}from"react/jsx-runtime";var eg="var(--semiotic-text, #26323a)",og="var(--semiotic-text-secondary, #6c7377)",ng="var(--semiotic-accent, #b8792d)",ig="var(--semiotic-negative, #9f3d35)",rg="var(--semiotic-positive, #356b63)";function sg(t){const{x:e,y:o,width:n,height:i}=t.chamber,r=Math.min(.14*n,48),s=o+i;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*i}`,`Q ${e+n/2} ${s+.1*i} ${e+n-r} ${s-.16*i}`,`L ${e+n} ${o}`].join(" ")}function ag({layout:t,phases:e,state:o,compact:n=!1}){const i=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return tg("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[tg("defs",{children:[tg("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[Jy("stop",{offset:"0",stopColor:ng,stopOpacity:"0.03"}),Jy("stop",{offset:"0.66",stopColor:ng,stopOpacity:"0.1"}),Jy("stop",{offset:"1",stopColor:ig,stopOpacity:"0.18"})]}),Jy("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:Jy("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:eg,strokeOpacity:"0.08",strokeWidth:"1"})})]}),Jy("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:eg,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),Jy("path",{d:sg(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),Jy("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:eg,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:Jy("g",{"data-testid":"crucible-phase-rail",children:e.map((n,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,c=Math.max(0,n.duration)/i*t.phaseRail.width,l=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return tg("g",{children:[Jy("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,c-2),height:t.phaseRail.height,rx:2,fill:l?n.color??ng:u?rg:eg,fillOpacity:l?.68:u?.28:.09}),46>c?null:Jy("text",{x:a+c/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:l?eg:og,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>tg("g",{children:[Jy("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?ig:rg),fillOpacity:"0.1",stroke:t.color??("left"===t.side?ig:rg),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:Jy("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:og,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function cg({rows:t,layout:e,projection:o,amountLabel:n}){if(!t.length)return null;const i=o.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),c=e.projection.height>48?21:4,l=Math.max(5,e.projection.height-c-5);return Jy("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,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*l),h=e.projection.x+o*a+.18*a;return tg("g",{children:[Jy("rect",{x:h,y:e.projection.y+l-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?ig:"complete"===t.status?ng:rg,fillOpacity:"0.68"}),c>4&&a>=34?tg(Qy,{children:[Jy("text",{x:h+.32*a,y:e.projection.y+l+10,fill:og,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),tg("text",{x:h+.32*a,y:e.projection.y+l+19,fill:eg,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Ky(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function lg(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 ug(t){return t.map(t=>({...t,spawnAt:void 0}))}function dg(t,e){return t?e?o=>tf.createElement(tf.Fragment,null,t,"function"==typeof e?e(o):e):t:e}var hg=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function fg(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return hg[(e>>>0)%hg.length]}var pg={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,n,i)=>({chartType:"line",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||e,colorAccessor:e,...n,showAxes:!1,margin:n.margin,showLegend:!1,showGrid:!1,title:void 0})},LineChart:Rd,AreaChart:Ld,DifferenceChart:Td,StackedAreaChart:$d,Scatterplot:Dd,CandlestickChart:zd,BubbleChart:Pd,ConnectedScatterplot:Od,QuadrantChart:Ed,Heatmap:{frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"heatmap",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,colorScheme:o||i.colorScheme||"blues",showValues:i.showValues,heatmapValueFormat:i.valueFormat,cellBorderColor:i.cellBorderColor,...n})},TemporalHistogram:Id,XYCustomChart:{frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:n.showLegend??!!e})},BarChart:ah,StackedBarChart:ch,GroupedBarChart:lh,PieChart:uh,DonutChart:dh,Histogram:hh,BoxPlot:fh,ViolinPlot:ph,SwarmPlot:yh,DotPlot:gh,SwimlaneChart:mh,RidgelinePlot:bh,LikertChart:xh,FunnelChart:vh,GaugeChart:wh,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:Wh,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,n,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:o,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...n})},SankeyDiagram:Yh,ProcessSankey:jh,ChordDiagram:Gh,TreeDiagram:qh,Treemap:Xh,CirclePack:Hh,ChoroplethMap:Zh,ProportionalSymbolMap:Qh,FlowMap:Jh,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,n,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:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n})},GaltonBoardChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,a=i.seed??1,c=Math.max(1,Math.round(i.pegRows??s-1)),l="mechanical"===i.mode,u=l?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),n=Math.max(1,Math.round(t.count??Math.max(64,4*e))),i=cf(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=df(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:n},(t,e)=>{let n=0;for(let t=0;o>t;t+=1)r()<i&&(n+=1);const a=o/2;return{id:`${s}-${e}`,value:n,mechanical:!0,pegRows:o,branchProbability:i,pathRights:n,side:a>n?"left":n>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:c,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:a}=t,c=ef(s),l=e.map((t,e)=>af(sf(t,e,o))).filter(t=>null!=t),u=function(t){if(!t)return;const e=af(t[0]),o=af(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(a),d=u?.[0]??(l.length?Math.min(...l):0),h=u?.[1]??(l.length?Math.max(...l):1),f=h===d?1:h-d,p=hf().domain([0,n]).range([c.plot.x,c.plot.x+c.plot.width]),y=Array.from({length:n},()=>0),g=[];e.forEach((t,e)=>{const r=af(sf(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-d)/f*n)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:c.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=c.plot.y+c.plot.height;return{config:rf(r,[...sp({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...ap({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:p,yTop:c.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:g,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:c.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:l?[0,c]:void 0});return{...n,config:d.config,initialSpawns:ug(d.initialSpawns),projectionRows:d.projectionRows,bodyStyle:nf(e||i.colorBy||(l?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:u=1}=t,d=ef(c),h=e.map((t,e)=>af(sf(t,e,o))).filter(t=>null!=t),f=af(l?.[0]),p=af(l?.[1]),y=h.length?Math.min(...h):0,g=h.length?Math.max(...h):y+i.size,m=Math.min(f??y,y),b=Math.max(p??g,g),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):af(r?.value)??w-(r?.delay??i.size),A=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))),S=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(d,s),M=x+v*i.size,_=Mp().domain([x,M]).range([S.windowPlot.x,S.windowPlot.x+S.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),C=[];e.forEach((t,e)=>{const r=af(sf(t,e,o));if(null==r)return;const a=af(sf(t,e,n))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-x)/i.size))),l=k>=x+(c+1)*i.size;P[c].value+=l?0:1,P[c].secondary+=l?1:0,C.push({id:(t.id??"event-"+e)+"",x:Math.max(S.windowPlot.x+s,Math.min(S.windowPlot.x+S.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:c,late:l}})});const R=d.plot.y+d.plot.height,I=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const n=t.windowStart,i=t.windowStart+t.windowCount*t.windowSize,r=Mp().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,c=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),l=t=>s===a?e:c+(t-a)/(s-a)*(e-c),u=[];for(let e=0;o>e;e+=1){const o=t.windowStart+e*t.windowSize,n=o+t.windowSize,i=r(o),s=r(n);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:i,y1:l(i),x2:s,y2:l(s)})}return u}({closedWindowCount:A,gutter:S.gutter,plot:d.plot,windowCount:v,windowPlot:S.windowPlot,windowSize:i.size,windowStart:x},d.plot.y+.28*d.plot.height);return{config:rf(a,[...sp({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),..._p({idPrefix:"eventdrop-window",count:v,xScale:t=>_(x+t*i.size),yTop:S.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>A)return null;const e=0===t?I[0]?.y1:I[t-1]?.y2??I[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?S.wallTop:e+1.25*s},yBottom:R,wallThickness:6}),...I.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:A,gutter:S.gutter,lidSegments:I,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:S.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{...n,config:s.config,initialSpawns:ug(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:nf(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},PhysicsPileChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,a=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:a}=t,c=lf(i,1),l=ef(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((sf(t,e,o)??"unknown")+"")});const y=Math.max(1,u.length),g=function(t,e,o){const n=t.width/Math.max(1,e),i=Math.max(2,2*o),r=Math.min(.7*n,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:n,tubeWidth:r,ballDiameter:i,perRow:s,centerX:e=>t.x+(e+.5)*n,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*i}}(l.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),b=u.map(()=>[]);e.forEach((t,e)=>{const i=(sf(t,e,o)??"unknown")+"",s=p(i),a=n?af(sf(t,e,n)):1,u=Math.max(0,Math.round((a??0)/c)),d=g.centerX(s);for(let o=0;u>o;o+=1){const n=h.get(i)??0,a=g.perRow>1?((g.perRow>1?n%g.perRow:0)/(g.perRow-1)*2-1)*m:0;h.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:l.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:i,unitIndex:o}})}});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=l.plot.y+l.plot.height,w=[...sp({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=l.plot.y-400;for(let t=0;y>t;t+=1){const e=g.centerX(t);for(const o of[-1,1])w.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*g.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:rf(s,w,"PhysicsPileChart"),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),o=e.length?e:["Intake"],n=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),i=lf(t.unitValue,1),r=df(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),c=a.reduce((t,e)=>t+e,0)||1,l=n-o.length,u=a.map(t=>t/c*l),d=u.map(t=>1+Math.floor(t));let h=n-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 o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/n}))}({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{...n,config:a.config,initialSpawns:ug(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:nf(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:u}=t,d=ef(a),h=df(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=af(sf(t,e,o));if(null==s)return;const a=n?(sf(t,e,n)??"All")+"":"All",c=i?af(sf(t,e,i)):null,l=cf(null!=c&&c>0?c:r,2,18);!function(t){let e=y.get(t);null==e&&(e=p.length,p.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:l})});const g=f.map(t=>t.value),m=c?af(c[0]):null,b=c?af(c[1]):null,x=g.length?Math.min(...g):0,v=g.length?Math.max(...g):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 A=Math.max(r,...f.map(t=>t.radius)),S=d.plot.x+A+8,M=d.plot.x+d.plot.width-A-8,_=Pp().domain([w,k]).range([S,M]),P=Math.max(1,p.length),C=Math.min(Math.max(28,3*A),d.plot.height/4),R=d.plot.y+C,I=Math.max(0,d.plot.y+d.plot.height-C-R),L=t=>{const e=y.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:R+e/(P-1)*I},T=new Map,$=f.map((t,e)=>{T.set(t.group,(T.get(t.group)??0)+1);const o=_(t.value),n=L(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?o+i:cf(o+(e%9-4)*t.radius*2.5,S,M),y:u?n+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:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:rf(s,sp({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*A),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:$,projectionRows:p.map(t=>({label:t,value:T.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[S,M],groups:p.map(t=>({label:t,y:L(t),count:T.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{...n,config:s.config,initialSpawns:ug(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:nf(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=Bp({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}),c=a.metadata;return{...n,config:a.config,initialSpawns:ug(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,bodyStyle:nf(e||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=ey({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{...n,config:s.config,initialSpawns:ug(s.initialSpawns),projectionRows:[],bodyStyle:nf(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Xy({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,Cy(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const n=Math.max(0,Math.min(1,Cy(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,c=qy(s,a).state,l=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",n=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"},o),i=n.get(e);if(i)return i.count+=1,i.amount+=t.amount,void uy(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:{...t.metrics},status:"status"===o?t.status:void 0,outletId:"outlet"===o?t.outletId:void 0,category:"category"===o?t.category:void 0,productId:"product"===o&&"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[...n.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||ny(t.key,e.key))}(c,l),d=l.measure??"count",h=function(t,e={}){const o=e.bodies??[],n=Math.max(0,e.recentBodyLimit??6),i=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const n=i.get(o);n?n.push(t):i.set(o,[t])}const r=t.map(t=>{const o=i.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-n)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??lg(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:o.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",y=!1===i.showChrome?null:tf.createElement(ag,{layout:s.layout,phases:s.phases,state:c,compact:520>r[0]||360>r[1]}),g=!1===i.showProjection?null:tf.createElement(cg,{rows:u,layout:s.layout,projection:l,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:ug(jy(c,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,o,n){const i=t.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:n.color??t?.color??fg(t?.id??i.semanticId)}}const s=e.components[i.semanticId];if(!s)return{...r,fill:n.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:n.color??fg(a)}}(t,c,p,i),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,c),renderBodySVG:Zy,backgroundGraphics:dg(y,n.backgroundGraphics),foregroundGraphics:dg(g,n.foregroundGraphics)}}},PhysicalFlowChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:y,sourceAccessor:g,targetAccessor:m,throughputAccessor:b}=t,x=ef(y),v=df(p),w=new Map,k=new Map,A=[];function S(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(sf(t,e,r)??t.id??e)+"",n=af(sf(t,e,s)),i=af(sf(t,e,a));if(null!=n&&null!=i){const t={x:n,y:i};w.set(o,t),A.push(t)}k.set(o,(t.label??t.name??o)+"")});const M=[];n.forEach((t,e)=>{const o=S(sf(t,e,g)),n=S(sf(t,e,m)),i=Math.max(0,af(sf(t,e,b))??0),r=Rp(d?sf(t,e,d):void 0),s=r.length?r:Rp(t.path??t.points??t.route);s.forEach(t=>A.push(t)),M.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const _=(C=A,"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 R=new Map;for(const[t,e]of w)R.set(t,Ip(e,x,_));const I=[];for(const t of M){let e=t.rawPath.map(t=>Ip(t,x,_));if(2>e.length){const o=R.get(t.source),n=R.get(t.target);o&&n&&(e=[o,n])}else R.has(t.source)||R.set(t.source,e[0]),R.has(t.target)||R.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),I.push({...t,path:e,packetCount:0}))}const L=lf(u,.12),T=Math.max(1,Math.round(i)),$=I.map(t=>Math.max(1,Math.round(t.throughput*L))),z=$.reduce((t,e)=>t+e,0),D=z>T?T/z:1;I.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor($[e]*D))});let E=I.reduce((t,e)=>t+e.packetCount,0);for(;E>T;){const t=I.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>I[t].packetCount)?o:t,-1);if(-1===t)break;I[t].packetCount-=1,E-=1}const O=new Map,F=new Map,B=[],N=lf(o,90),W=lf(l,4);I.forEach((t,e)=>{O.set(t.target,(O.get(t.target)??0)+t.throughput),F.set(t.source,(F.get(t.source)??0)+t.throughput);const o=Lp(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:cf(.12+.84*i+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=Tp(t.path,s),c=Tp(t.path,r),l=$p(t.path,s),u={x:-l.y,y:l.x},d=(v()-.5)*W*1.5;B.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:l.x*N+10*(v()-.5),vy:f?0:l.y*N+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:W},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:n,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:N,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==h&&f?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from(R,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+uf(t),point:e})),G=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:j,height:j}})),q=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),X=rf(p,[...sp({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"PhysicalFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});X.bodyLimit=T,X.eviction="oldest",X.observation={...X.observation,sensors:q};const H=Array.from(R,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+uf(t),incoming:O.get(t)??0,outgoing:F.get(t)??0})),V=I.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:X,initialSpawns:B,projectionRows:H.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:B.length,totalThroughput:I.reduce((t,e)=>t+e.throughput,0),plot:x.plot,nodes:H,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{...n,config:s.config,initialSpawns:ug(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:nf(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[700,380],s=function(t){const e=function(t,e,o){const n=t?.observation;return{...t,observation:{...n,chartId:e??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(t.config,t.chartId,t.onObservation),o=Wp(t.colorScheme,t.themeCategorical,Q),n=ef(t.size),i={data:t.data,scales:{x:Np().domain(t.xExtent??[0,1]).range([n.plot.x,n.plot.x+n.plot.width]),y:Np().domain(t.yExtent??[0,1]).range([n.plot.y+n.plot.height,n.plot.y])},dimensions:n,theme:{semantic:t.semantic,categorical:[...o]},resolveColor:jp(o,t.colorScheme),config:t.layoutConfig??{},world:new Sp(e)},r=t.skipLayout?{}:t.layout(i)??{},s=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...n}=t,i=o.get(e)??[];i.push(n),o.set(e,i)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Yp(e,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:o,config:i.config,data:Array.isArray(t)?t:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:_(R)??{},size:r,themeCategorical:R.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...n,config:s.config,initialSpawns:ug(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??nf(e||i.colorBy)}}}};function yg(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function gg(t){if(!t||2>t.length)return;const e=yg(t[0]),o=yg(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function mg(t){const{count:e,byType:o}=function(t){const e={};for(const o of t){const t="string"==typeof o?.type&&o.type.length>0?o.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),n=0===e,i=[...t.extraWarnings??[]];n&&!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:n?"empty":"ok",empty:n,markCount:e,markCountByType:o,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 bg from"react";import*as xg from"react-dom/server";import{scaleOrdinal as vg}from"d3-scale";import{jsx as wg,jsxs as kg}from"react/jsx-runtime";function Ag(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>Ct(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:Q;return vg().domain(t).range(n)}function Sg(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Mg(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function _g(t,e,o,n){const i=Mg(n);return e+o+Math.ceil(t.length*i*.58)}function Pg(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=Ni(s),d=a+c,h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right),p=e.map(t=>_g(t,a,c,o));if(h){const t=Math.max(a,s?.maxWidth??f),o=[];let n=0,i=0;p.forEach((e,r)=>{const s=0===i?e:i+l+e;i>0&&s>t?(o.push({start:n,end:r,width:i}),n=r,i=e):i=s}),e.length>0&&o.push({start:n,end:e.length,width:i});const r=Sg(s?.align),c=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)c.push({category:e[t],width:p[t],x:i,y:n*u}),i+=p[t]+l}),{items:c,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const y=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:y,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Cg(t){const{legendGroups:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,rowHeight:l}=Ni(s),u=a+c,d=Math.max(12,Mg(o)),h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??f),i=Sg(s?.align);let r=0,c=0;const l=[];for(const i of e){const e=i.items.map(t=>t.label),u=Pg({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,f=i.label?_g(i.label,0,0,o):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);l.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:y,height:g,items:u.items}),r+=y+12,c=Math.max(c,g)}const h=l.length>0?r-12:0,p=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:l.map(t=>({...t,x:t.x+p})),width:h,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Wi(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),l);let y=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>_g(t.label,a,c,o)),i=Math.max(0,...n,t.label?_g(t.label,0,0,o):0);return y=Math.max(y,i),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*l,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*l}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function Rg(t){const e="top"===t.position||"bottom"===t.position,o=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??o,200),height:t.gradient.label?34:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?124:108,swatchSize:14}}function Ig(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],n=new Set;for(const e of t){const t=o(e);null!=t&&n.add(t+"")}return Array.from(n)}import{jsx as Lg,jsxs as Tg}from"react/jsx-runtime";var $g=16;function zg(t,e){return t.color||e.colors.annotation||e.colors.text}function Dg(t,e,o){const n=t.labelBackground,i=e.colors.background,r=i&&"transparent"!==i?i:e.colors.surface||i;return void 0===n?"none"===o?"none":{type:"halo",fill:r}:!1===n||"none"===n?"none":!0===n||"halo"===n?{type:"halo",fill:r}:"box"===n?{type:"box",fill:r}:{fill:r,...n}}function Eg(t,e,o){return null!=t.x&&e.x?e.x(t.x):o&&null!=t[o]&&e.x?e.x(t[o]):"number"==typeof t.x?t.x:null}function Og(t,e,o){return null!=t.y&&e.y?e.y(t.y):o&&null!=t[o]&&e.y?e.y(t[o]):"number"==typeof t.y?t.y:null}function Fg(t){const{annotations:e}=t;if(!e||0===e.length)return null;const o=a(e),n=t.scales.geoProjection,i=n?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=n([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,r=!!n&&!t.scales.x&&!t.scales.y,s=t=>Number(t),c=t.scales.x??(r?s:void 0),l=t.scales.y??(r?s:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{x:c,y:l,time:c,value:l,o:t.scales.o,...n?{geoProjection:n}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,frameType:t.projection?"ordinal":n||t.scales.x||t.scales.y?"xy":"network",...u?{projection:u}:{}},h=Kr(t.autoPlaceAnnotations?us({annotations:i,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):i,(e,o)=>function(t,e,o){const{scales:n,layout:i,theme:r,xAccessor:s,yAccessor:a}=o;switch(t.type){case"y-threshold":{const s=t.value;if(null==s)return null;const a=zg(t,r),c=t.label,l=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&n.r){const o=n.r(s);return null==o?null:Tg("g",{opacity:t.opacity,children:[Lg("line",{x1:o,y1:0,x2:o,y2:i.height,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Lg(Xr,{x:o+4,y:$g,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Dg(t,r,"halo")})]},"ann-ythresh-"+e)}const h=n.y?n.y(s):n.r?n.r(s):null;return null==h?null:Tg("g",{children:[Lg("line",{x1:0,y1:h,x2:i.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Lg(Xr,{x:"left"===l?4:"center"===l?i.width/2:i.width-4,y:20>h?Math.min(i.height-4,h+$g):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Dg(t,r,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const s=t.value;if(null==s)return null;const a="horizontal"===o.projection&&n.r?n.r(s):n.x?n.x(s):null;if(null==a)return null;const c=zg(t,r),l=t.label,u=t.labelPosition||"top";return Tg("g",{opacity:t.opacity,children:[Lg("line",{x1:a,y1:0,x2:a,y2:i.height,stroke:c,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),l&&Lg(Xr,{x:a>.6*i.width?a-4:a+4,y:"bottom"===u?i.height-4:"center"===u?i.height/2:$g,textAnchor:a>.6*i.width?"end":"start",fontSize:r.typography.tickSize,fill:c,fontFamily:r.typography.fontFamily,text:l,background:Dg(t,r,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=n.y?.domain?.(),s=t.y0??o?.[0],a=t.y1??o?.[1],c=null!=s&&n.y?n.y(s):null,l=null!=a&&n.y?n.y(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=ti(t.fill||zg(t,r),"ssr-band-"+e),f=t.fillOpacity??.1;return Tg("g",{opacity:t.opacity,children:[h.def&&Lg("defs",{children:h.def}),Lg("rect",{x:0,y:u,width:i.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&Lg(Xr,{x:i.width-4,y:Math.max(u,0)+$g,textAnchor:"end",fontSize:r.typography.tickSize,fill:t.color||zg(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Dg(t,r,"halo")})]},"ann-band-"+e)}case"x-band":{const o=n.x?.domain?.(),s=t.x0??o?.[0],a=t.x1??o?.[1],c=null!=s&&n.x?n.x(s):null,l=null!=a&&n.x?n.x(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=ti(t.fill||zg(t,r),"ssr-xband-"+e),f=t.fillOpacity??.1;return Tg("g",{opacity:t.opacity,children:[h.def&&Lg("defs",{children:h.def}),Lg("rect",{x:u,y:0,width:d,height:i.height,fill:h.fill,fillOpacity:f}),t.label&&Lg(Xr,{x:u+4,y:$g,textAnchor:"start",fontSize:r.typography.tickSize,fill:t.color||r.colors.primary||zg(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:Dg(t,r,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!n.o)return null;const s=n.o(t.category+"");if(null==s)return null;const a=n.o.bandwidth?n.o.bandwidth():40,c=zg(t,r),l=t.opacity??.1,u=t.label;return Tg("g","horizontal"===o.projection?{children:[Lg("rect",{x:0,y:s,width:i.width,height:a,fill:c,opacity:l}),u&&Lg(Xr,{x:12,y:s+a/2,dominantBaseline:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Dg(t,r,"none")})]}:{children:[Lg("rect",{x:s,y:0,width:a,height:i.height,fill:c,opacity:l}),u&&Lg(Xr,{x:s+a/2,y:$g,textAnchor:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Dg(t,r,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:i}=function(t,e,o,n){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const o=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Eg(t,e,o),y:Og(t,e,n)}}(t,n,s,a);if(null==o||null==i)return null;const c="text"===t.type,l=t.dx??(c?0:30),u=t.dy??(c?0:-30),d=t.color||r.colors.text;if(!c){const n="callout"===t.type?"callout-circle":t.type,r="callout-circle"===n?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===n?{width:t.width,height:t.height}:void 0;return Lg(mr,{noteData:{x:o,y:i,dx:l,dy:u,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:n,...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 Lg("g",{children:Lg("text",{x:o+l,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,o,t),t.svgAnnotationRules,d);return h.length>0?Lg("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as Bg from"react";import{jsx as Ng,jsxs as Wg}from"react/jsx-runtime";function jg(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function Yg(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 o=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let n=0;for(let t=0;o.length>t;t++)n=31*n+o.charCodeAt(t)|0;return"c"+(n>>>0).toString(36)}function Gg(t,e,o){const n=t.showLegend&&!t.__legendIncludesAutomatic?function(t,e,o){if(0===t.length)return;const n=Ag(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}(e,t.colorScheme,o):void 0;return Zi(n,t.legend)}var qg={right:110,left:110,top:50,bottom:80};function Xg(t,e){if(t.__autoLegendMargin&&!Hg(t,e))return qg[e]}function Hg(t,e){const o=t.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[e])}function Vg(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",c={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,minimumMargin:Xg(o,a),preserveExplicitMargin:Hg(o,a)};if(null!=o.legend){const e=Gg(o,n,i);(Qi(e)||Ji(e))&&function(t,e){if(e.preserveExplicitMargin)return;const o=e.position||"right",n={theme:e.theme,position:o,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout},i=Qi(e.legend)?function(t){const{width:e,height:o,swatchSize:n}=Cg(t);return{width:e,height:o,swatchSize:n}}({...n,legendGroups:e.legend.legendGroups}):Ji(e.legend)?Rg({...n,gradient:e.legend.gradient}):null;if(!i)return;const r=e.minimumMargin??i.width+14,s=e.minimumMargin??(e.hasTitle?32:8)+i.height+4,a=e.minimumMargin??38+i.height+4;"right"===o?t.right=Math.max(t.right,r):"left"===o?t.left=Math.max(t.left,r):"top"===o?t.top=Math.max(t.top,s):t.bottom=Math.max(t.bottom,a)}(t,{...c,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;if(e.preserveExplicitMargin)return;const o=e.position||"right",n=function(t){const{width:e,height:o,swatchSize:n}=Pg(t);return{width:e,height:o,swatchSize:n}}({categories:e.categories,colorScheme:e.colorScheme,theme:e.theme,position:o,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout}),i=e.minimumMargin??n.width+14,r=e.minimumMargin??(e.hasTitle?32:8)+n.height+4,s=e.minimumMargin??38+n.height+4;"right"===o?t.right=Math.max(t.right,i):"left"===o?t.left=Math.max(t.left,i):"top"===o?t.top=Math.max(t.top,r):t.bottom=Math.max(t.bottom,s)}(t,{...c,categories:n,colorScheme:o.colorScheme});return a}function Ug(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",c={theme:n,position:a,size:i,margin:r,hasTitle:s,legendLayout:e.legendLayout,idPrefix:e._idPrefix,reservedWidth:e.__autoLegendMargin?100:void 0};if(null!=e.legend){const t=Gg(e,o,n);if(Bg.isValidElement(t))return t;const i=function(t,e){const o={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};return Qi(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,o)=>({group:t,item:e,itemIndex:o,label:e.label})))).length)return null;var e;const o=Cg(t),n="top"===t.position||"bottom"===t.position,i=t.theme.colors.grid||t.theme.colors.textSecondary;let r,s;if("left"===t.position?(r=Math.max(4,t.margin.left-(t.reservedWidth??100)-10),s=t.margin.top):"top"===t.position?(r=t.margin.left,s=t.hasTitle?32:8):"bottom"===t.position?(r=t.margin.left,s=t.totalHeight-t.margin.bottom+38):(r=t.totalWidth-t.margin.right+10,s=t.margin.top),!n){const e=Wi(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)),n=t.legendGroups.flatMap((n,i)=>{const r=e[i],s=n.type??"fill",a=[wg("line",{x1:0,y1:r.lineY,x2:t.reservedWidth??100,y2:r.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=r.labelY&&a.push(wg("text",{y:r.labelY,fontSize:Mg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:n.label},"legend-group-label-"+i)),a.push(wg("g",{transform:`translate(0,${r.itemsY})`,children:n.items.map((e,r)=>{const a=n.styleFn(e,r),c="function"==typeof s?s(e):"line"===s?wg("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:a}):wg("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:a});return kg("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[c,wg("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Mg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),a});return wg("g",{className:"semiotic-legend",transform:`translate(${r},${s})`,"data-orientation":"vertical",children:n})}const a=o.groups.flatMap((e,r)=>{const{group:s}=e,a=s.type??"fill",c=[];if(s.label&&c.push(wg("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Mg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:s.label}:{x:e.x,y:e.y+Mg(t.theme),fontSize:Mg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:s.label},"legend-group-label-"+r)),c.push(...e.items.map((n,i)=>{const c=s.items[i],l=s.styleFn(c,i),u="function"==typeof a?a(c):"line"===a?wg("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):wg("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return kg("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,wg("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Mg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:n.category})]},`legend-${r}-${i}`)})),n&&o.groups.length-1>r){const t=e.x+e.width+6;c.push(wg("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:i},"legend-group-separator-"+r))}return c});return wg("g",{className:"semiotic-legend",transform:`translate(${r},${s})`,"data-orientation":n?"horizontal":"vertical",children:a})}({...o,legendGroups:t.legendGroups}):Ji(t)?function(t){const e=Rg(t),o="top"===t.position||"bottom"===t.position,n=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",i=t.gradient.format||(t=>Math.round(100*t)/100+"");let r,s;"left"===t.position?(r=Math.max(4,t.margin.left-100-10),s=t.margin.top):"top"===t.position?(r=t.margin.left,s=t.hasTitle?32:8):"bottom"===t.position?(r=t.margin.left,s=t.totalHeight-t.margin.bottom+38):(r=t.totalWidth-t.margin.right+10,s=t.margin.top);const a=Array.from({length:17},(e,n)=>{const i=n/16;return wg("stop",{offset:100*i+"%",stopColor:t.gradient.colorFn(o?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]))},n)});if(o){const o=12,c=t.gradient.label?0:void 0,l=t.gradient.label?8:0;return kg("g",{className:"semiotic-legend",transform:`translate(${r},${s})`,children:[wg("defs",{children:wg("linearGradient",{id:n,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:a})}),t.gradient.label&&wg("text",{x:e.width/2,y:c,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),wg("rect",{x:0,y:l,width:e.width,height:o,fill:`url(#${n})`,rx:2}),wg("text",{x:0,y:l+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:i(t.gradient.domain[0])}),wg("text",{x:e.width,y:l+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:i(t.gradient.domain[1])})]})}const c=t.gradient.label?-6:void 0;return kg("g",{className:"semiotic-legend",transform:`translate(${r},${s+(t.gradient.label?12:0)})`,children:[wg("defs",{children:wg("linearGradient",{id:n,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:a})}),t.gradient.label&&wg("text",{x:7,y:c,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),wg("rect",{x:0,y:0,width:14,height:100,fill:`url(#${n})`,rx:2}),wg("text",{x:19,y:10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:i(t.gradient.domain[1])}),wg("text",{x:19,y:100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:i(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}(t,c);return i||(Qi(t)||Ji(t)?null:t??null)}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:n,position:i="right",totalWidth:r,totalHeight:s,margin:a,hasTitle:c=!1}=t;if(!e||0===e.length)return null;const l=Ag(e,o,n),u="top"===i||"bottom"===i,d=Pg(t);let h,f;if("left"===i?(h=Math.max(4,a.left-(t.reservedWidth??100)-10),f=a.top):"top"===i?(h=a.left,f=c?32:8):"bottom"===i?(h=a.left,f=s-a.bottom+38):(h=r-a.right+10,f=a.top),u){const t=d.items.map((t,e)=>kg("g",{transform:`translate(${t.x},${t.y})`,children:[wg("rect",{width:d.swatchSize,height:d.swatchSize,fill:l(t.category),rx:d.swatchRadius}),wg("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:Mg(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:t.category})]},"legend-"+e));return wg("g",{className:"semiotic-legend",transform:`translate(${h},${f})`,children:t})}const p=Wi([{hasLabel:!1,itemCount:e.length}],Math.max(d.swatchSize,t.legendLayout?.rowHeight??22))[0],y=d.items.map((t,e)=>kg("g",{transform:`translate(${t.x},${t.y+p.itemsY})`,children:[wg("rect",{width:d.swatchSize,height:d.swatchSize,fill:l(t.category),rx:d.swatchRadius}),wg("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:Mg(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:t.category})]},"legend-"+e));return kg("g",{className:"semiotic-legend",transform:`translate(${h},${f})`,children:[wg("line",{x1:0,y1:p.lineY,x2:t.reservedWidth??100,y2:p.lineY,stroke:"gray"}),y]})}({categories:o,colorScheme:e.colorScheme,theme:n,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,reservedWidth:e.__autoLegendMargin?100:void 0,idPrefix:e._idPrefix}):null}function Kg(t){return Math.round(100*t)/100+""}function Zg(t,e){const o=O(e.theme),n=e.background??o.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,c=[s,a].filter(Boolean).join(" ")||void 0;return Wg("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":c,style:{fontFamily:o.fontFamily},children:[r&&Ng("title",{id:s,children:r}),e.description&&Ng("desc",{id:a,children:e.description}),e.defs&&Ng("defs",{children:e.defs}),n&&"transparent"!==n&&Ng("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),Ng("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&Ng("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:r}),e.legend&&Ng("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{Fragment as Qg,jsx as Jg,jsxs as tm}from"react/jsx-runtime";function em(t,e){const o=E(t.theme),n=t.size||[500,300],i=Is({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Cs(t.title),s=H(t.data),a=t.showLegend?Ig(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[];Vg(i,{props:t,categories:a,theme:o,size:n,hasTitle:r});const c=n[0]-i.left-i.right,l=n[1]-i.top-i.bottom,u="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),d=t.colorScheme||o.colors.categorical,h={chartType:t.chartType,windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:u?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:u?void 0:t.xAccessor,yAccessor:u?void 0:t.yAccessor,timeAccessor:u?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:!0===t.gradientFill?{topOpacity:.8,bottomOpacity:.05}:!1===t.gradientFill?void 0:t.gradientFill,lineGradient:t.lineGradient,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:d,themeCategorical:o.colors.categorical,themeSemantic:_(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat},f=new an(h);if(t.data&&f.ingest({inserts:s,bounded:!0}),f.computeScene({width:c,height:l}),!f.scales||0===f.scene.length)return e&&(e.evidence=mg({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:f.scales?[]:["NO_SCALES"],margin:i})),xg.renderToStaticMarkup(Zg(null,{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:l,idPrefix:t._idPrefix}));const p=t._idPrefix,y=kl({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>ga(t,e,p)});e&&(e.evidence=mg({frameType:"xy",width:n[0],height:n[1],marks:y.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,xDomain:gg(f.scales.x?.domain?.()),yDomain:gg(f.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const g=t.showGrid?function(t,e,o,n,i){const{grid:r}=O(o),s=n?n+"-":"",a="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))),l=ks(t.x,a,i),u=ks(t.y,c,i);return Wg("g",{id:s+"grid",className:"semiotic-grid",opacity:.8,children:[l.map((o,n)=>{const i=t.x(o);return Ng("line",{x1:i,y1:0,x2:i,y2:e.height,stroke:r,strokeWidth:.5},"gx-"+n)}),u.map((o,n)=>{const i=t.y(o);return Ng("line",{x1:0,y1:i,x2:e.width,y2:i,stroke:r,strokeWidth:.5},"gy-"+n)})]})}(f.scales,{width:c,height:l},o,p,t.axisExtent):null,m=y.map(t=>t.element),b=Yg(t)+"-plot-clip",x=!1!==t.showAxes?function(t,e,o,n,i){const r=O(n),s="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),a="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),c=ks(t.x,s,o.axisExtent).map(e=>({pixel:t.x(e),label:(o.xFormat||o.tickFormatTime||Kg)(e)})),l=ks(t.y,a,o.axisExtent).map(e=>({pixel:t.y(e),label:(o.yFormat||o.tickFormatValue||Kg)(e)}));return Wg("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[Ng("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:r.border,strokeWidth:1}),c.map((t,o)=>Wg("g",{transform:`translate(${t.pixel},${e.height})`,children:[Ng("line",{y2:5,stroke:r.border,strokeWidth:1}),Ng("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"xtick-"+o)),o.xLabel&&Ng("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:o.xLabel}),Ng("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:r.border,strokeWidth:1}),l.map((t,e)=>Wg("g",{transform:`translate(0,${t.pixel})`,children:[Ng("line",{x2:-5,stroke:r.border,strokeWidth:1}),Ng("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"ytick-"+e)),o.yLabel&&Ng("text",{x:15-(o.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${e.height/2})`,children:o.yLabel})]})}(f.scales,{width:c,height:l},t,o,p):null,v=t.annotations?Fg({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:f.scales.x,y:f.scales.y},layout:{width:c,height:l},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:p}):null,w=t.svgPreRenderers&&f.scales?t.svgPreRenderers.map((t,e)=>{try{return Jg(bg.Fragment,{children:t(f.scene,f.scales,{width:c,height:l})},"pre-"+e)}catch{return null}}).filter(Boolean):null,k=Ug({props:t,categories:a,theme:o,size:n,margin:i,hasTitle:r});return xg.renderToStaticMarkup(Zg(tm(Qg,{children:[t.backgroundGraphics,w,g,Jg("defs",{children:Jg("clipPath",{id:b,children:Jg("rect",{x:0,y:0,width:c,height:l})})}),Jg("g",{clipPath:`url(#${b})`,children:m}),x,v,t.foregroundGraphics,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:l,legend:k,idPrefix:t._idPrefix}))}import*as om from"react-dom/server";import{scaleBand as nm,scaleLinear as im}from"d3-scale";var rm=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,o){if(e&&"function"==typeof t.pieceStyle){const n=t.pieceStyle(e,o);return n&&!n.fill&&o?{...n,fill:this.getColorFromScheme(t,o)}:n}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:t.barColors[o]||"#007bff"}:{fill:o?this.getColorFromScheme(t,o):"#007bff"}}resolveSummaryStyle(t,e,o){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,o):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const o=this.colorSchemeMap.get(e);if(o)return o;const n=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||St,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function sm(t){const e=t.getSymbol;if(!e)return null;const o=t.config.symbolMap,n=new Map;let i=0;return t=>{const r=e(t)+"",s=o?.[r];if(s)return s;let a=n.get(r);return a||(a=lo[i%lo.length],i++,n.set(r,a)),a}}function am(t,e,o,n,i,r,s){t.push(e?{type:"symbol",x:n,y:i,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:n,y:i,r:r,style:s,datum:o})}function cm(t,e){const{columns:o,config:n,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,c=-Math.PI/2+(n.startAngle||0)*Math.PI/180,l=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),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&&(n.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=c+u*l,p=c+(u+("number"==typeof o?._pct?o._pct:e.pct))*l,y=i(e.pieceData[0],e.name),g=0===t,m=t===d.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?b.roundedEnds=o._roundedEnds:f&&(b.roundedEnds={start:g,end:m}),o?._gradientBand&&(b._gradientBand=o._gradientBand),r.push(b)}return r}import{quantile as lm}from"d3-array";function um(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:lm(t,.25)??o,median:lm(t,.5)??(o+n)/2,q3:lm(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as dm}from"d3-scale";var hm={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h="horizontal"===l,f=i.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(n))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),p.push(e))}}else p.push("_default");for(const t of Object.values(n)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const n=e.get(t);n.total+=r(o),n.pieces.push(o)}let o=0;if(f)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of p){const l=e.get(r);if(!l)continue;let p=l.total;f&&o>0&&(p/=o);const y=a(l.pieces[0],s?r:t.name),g={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:t.name};if(d){const e=c(0>p?i:n+p),o=0>p?c(i+p)-c(i):c(n)-c(n+p);u.push(je(t.x,e,t.width,Math.abs(o),y,g,r)),0>p?i+=p:n+=p}else if(h){const e=c(0>p?i+p:n),o=0>p?c(i)-c(i+p):c(n+p)-c(n);u.push(je(e,t.x,Math.abs(o),t.width,y,g,r)),0>p?i+=p:n+=p}}}const y="vertical"===l,g=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=y?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(g>0){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const o=e.datum?.category||"";t.has(o)||t.set(o,[]),t.get(o).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),o=e.filter(t=>0>(t.datum?.__aggregateValue??0));t.length>0&&(t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e).roundedTop=g),o.length>0&&(o.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e).roundedTop=g)}}return u},clusterbar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h=[],f=new Set;for(const t of Object.values(n))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(n)){const e=t.width/p,o=.2*e,n=e-o,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 l=i.get(h[s])||[];for(const i of l){const l=r(i),f=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(je(r,Math.min(a,d),n,Math.abs(a-d),f,i,h[s]))}else{const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(je(Math.min(a,d),r,Math.abs(d-a),n,f,i,h[s]))}}}}const y=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);y>0&&(t.roundedTop=y),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:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d="radial"===c,h=r.length>0,f=sm(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(n))for(const e of t.pieceData){const o=e.__rIndex??0,n=e.__rValue??i(e),c=h&&r[o]||a,g=s(e,t.name),m=g.r||5;let b,x;if(d){const e=y+(t.pctStart+t.pct/2)*p,o=c(n);b=Math.cos(e)*o,x=Math.sin(e)*o}else u?(b=t.middle,x=c(n)):(b=c(n),x=t.middle);am(l,f,e,b,x,m,g)}return l},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="vertical"===a,u=sm(t);for(const t of Object.values(n)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const n=t.pieceData[o],a=i(n),d=r(n,t.name),h=d.r||4,f=(7919*o%100/100-.5)*e*.8;am(c,u,n,l?t.middle+f:s(a),l?s(a):t.middle+f,h,d)}}return c},pie:cm,donut:cm,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=!1!==i.showOutliers;for(const e of Object.values(n)){const o=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===o.length)continue;const n=o[0],i=o[o.length-1],c=lm(o,.25)??n,h=lm(o,.5)??(n+i)/2,f=lm(o,.75)??i,p=f-c,y=c-1.5*p,g=f+1.5*p,m=o.find(t=>t>=y)??n,b=[...o].reverse().find(t=>g>=t)??i,x=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(y>o||o>g){const n=u?e.middle:a(o),i=u?a(o):e.middle;v.push({px:n,py:i,value:o,datum:t})}}if(l.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(c),medianPos:a(h),q3Pos:a(f),maxPos:a(b),stats:{n:o.length,min:m,q1:c,median:h,q3:f,max:b,mean:o.reduce((t,e)=>t+e,0)/o.length},style:x,datum:e.pieceData,category:e.name,outliers:v}),d)for(const e of v)l.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 l},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=i.bins||20,h=!1!==i.showIQR;for(const t of Object.values(n)){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 o=e[0],n=e[e.length-1],i=(n-o)/d||1,c=Array(d).fill(0);for(const t of e)c[Math.min(Math.floor((t-o)/i),d-1)]++;const f=A(c,1),p=t.width/2*.9;let y;if(u){y=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);y+=` L ${t.middle+c[e]/f*p} ${n}`}y+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);y+=` L ${t.middle-c[e]/f*p} ${n}`}y+=" Z"}else{y=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)y+=` L ${a(o+(e+.5)*i)} ${t.middle-c[e]/f*p}`;y+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)y+=` L ${a(o+(e+.5)*i)} ${t.middle+c[e]/f*p}`;y+=" Z"}const g=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=lm(e,.25)??o,r=lm(e,.5)??(o+n)/2,s=lm(e,.75)??n;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(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:um(e),style:g,datum:t.pieceData,category:t.name})}return l},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,c=[],l=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(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,n]=M(e),i=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:n,p=(d-i)/l||1,y=Array(l).fill(0);for(const t of e)i>t||t>d||y[Math.min(Math.floor((t-i)/p),l-1)]++;const g=e.length,m=A(y,1),b=s(t.pieceData[0],t.name);for(let e=0;l>e;e++){if(0===y[e])continue;const o=(u?y[e]/g:y[e]/m)*t.width*.9,n=a(i+e*p),r=a(i+(e+1)*p);c.push(je(Math.min(n,r),t.x+t.width-o,Math.abs(r-n),o,b,{bin:e,count:y[e],range:[i+e*p,i+(e+1)*p],category:t.name},t.name))}}return c},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u=i.bins||20,d="horizontal"===c,h=i.amplitude||1.5;for(const t of Object.values(n)){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 o=e[0],n=e[e.length-1],i=(n-o)/u||1,c=Array(u).fill(0);for(const t of e)o>t||t>n||c[Math.min(Math.floor((t-o)/i),u-1)]++;const f=A(c,1),p=s(t.pieceData[0],t.name),y=t.width*h;let g;if(d){const e=t.x+t.width;g=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)g+=` L ${a(o+(t+.5)*i)} ${e-c[t]/f*y}`;g+=` L ${a(n)} ${e} Z`}else{const e=t.x;g=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);g+=` L ${e+c[t]/f*y} ${n}`}g+=` L ${e} ${a(n)} Z`}const m=d?{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))};l.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:m,stats:um(e),style:{...p,fillOpacity:p.fillOpacity??.5},datum:t.pieceData,category:t.name})}return l},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="horizontal"===a;for(const t of Object.values(n))for(const e of t.pieceData){const o=i(e);if(!o)continue;const[n,a]=o,u=r(e,t.name);if(l){const o=s(Math.min(n,a)),i=s(Math.max(n,a));c.push(je(o,t.x,i-o,t.width,u,e,t.name))}else{const o=s(Math.max(n,a)),i=s(Math.min(n,a));c.push(je(t.x,o,t.width,i-o,u,e,t.name))}}return c},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,c=!1!==t.config.showLabels,l=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return s;const u=[],d=new Set;for(const t of l)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 l){const e=new Map;let o=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=n(r);s.total+=a,s.pieces.push(r),o+=a}f.push({col:t,groups:e,stepTotal:o}),h||o>p&&(p=o)}if(h)for(const t of f){let e=0,o=0;for(let n=0;u.length>n;n++){const i=t.groups.get(u[n]);i&&(n%2==0?e+=i.total:o+=i.total)}const n=Math.max(e,o);n>p&&(p=n)}if(0===p)return s;const y=new Map;for(const t of u){const e=f[0].groups.get(t);y.set(t,e?.total??0)}const g=f[0].stepTotal,m=h?.95*a:.9*e.width,b=dm().domain([0,p]).range([0,m]),x=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const o=f[e],n=o.col,i=0===e,l=n.width,d=.55*l,p=n.x+(l-d)/2,m=new Map;if(h){let t=0;for(const e of u){const n=o.groups.get(e);n&&(t+=b(n.total))}let e=a,l=a;for(let h=0;u.length>h;h++){const f=u[h],g=o.groups.get(f);if(!g)continue;const x=b(g.total),v=h%2==0,w=v?e:l-x;v?e+=x:l-=x;const k=r(g.pieces[0],f),A=y.get(f)??g.total,S={...g.pieces[0],__funnelValue:g.total,__funnelPercent:A>0?g.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};c&&(0===h&&(S.__funnelStepLabel=n.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=p,S.__funnelRowWidth=t),S.__funnelValueLabelX=w+x/2,S.__funnelValueLabelY=p,S.__funnelBarW=x),s.push(je(w,p,x,d,k,S,f)),m.set(f,{x:w,y:p,w:x,h:d})}}else{const t=o.stepTotal,e=b(t),l=a-e/2,h=u[0],f="_default"!==h,y=o.groups.get(h)?.pieces[0]??n.pieceData[0],x=f?h:n.name,v=r(y,x),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:f?h:n.name};c&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(je(l,p,e,d,v,k,x)),m.set(h,{x:l,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 c=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),l={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||t.config.themeSemantic?.secondary||"#999",opacity:x},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(l)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],c=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),l.push(t))}const d=l.length>1&&"_default"!==l[0],h=[];for(const t of c){const e=new Map;let o=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=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const f=new Map;for(const t of l){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,y=d?l.length:1,g=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,n=0===t,i=t>0?h[t-1]:null,s=o.width/y,c=s*g,u=s-c;for(let t=0;l.length>t;t++){const h=l[t],y=e.groups.get(h);if(!y)continue;const g=y.total,m=f.get(h)??g,b=m>0?g/m*100:0,x=i?.groups.get(h),v=n?0:Math.max(0,(x?.total??g)-g),w=o.x+t*s+c/2,k=p(g),A=p(0)-k,S=r(y.pieces[0],d?h:o.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:b,__barFunnelIsFirstStep:n,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(g+v)};if(a.push(je(w,k,u,A,S,M,d?h:o.name)),v>0){const t=p(g+v),e=k-t,n={...S},i={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(je(w,t,u,e,n,i,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="horizontal"===c,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,[o,i]=a.range(),r=Math.min(o,i),s=Math.abs(i-o);for(const o of Object.values(n)){const n={fill:t,opacity:e},i=u?je(r,o.x,s,o.width,n,null,"__track__"):je(o.x,r,o.width,s,n,null,"__track__");l.push(i)}}const p=t.config.roundedTop&&t.config.roundedTop>0?Math.max(0,t.config.roundedTop):0;for(const t of Object.values(n)){let e=0;const o=l.length;for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const c=r?r(o):t.name,f=s(o,c);let p;if(u){const i=a(e),r=a(e+n);p=je(i,t.x,r-i,t.width,f,o,c)}else{const i=a(e+n),r=a(e);p=je(t.x,i,t.width,r-i,f,o,c)}d&&(p.fillGradient=d,p.roundedEdge=h),l.push(p),e+=n}if(p>0&&l.length>o){const t=l.slice(o),e=t[0],n=t[t.length-1];1===t.length?e.cornerRadii={tl:p,tr:p,br:p,bl:p}:u?(e.cornerRadii={tl:p,bl:p},n.cornerRadii={tr:p,br:p}):(e.cornerRadii={bl:p,br:p},n.cornerRadii={tl:p,tr:p})}}return l}},fm=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],pm=["scene-style","data-paint","accessibility","evidence"],ym=(t,e)=>({retainedData:t,invalidations:e}),gm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],mm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],bm=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xm=["scene-geometry","data-paint","accessibility","evidence"],vm=["scene-style","data-paint","accessibility","evidence"],wm=[],km={chartType:ym("rebuild",gm),runtimeMode:ym("rebuild",gm),categoryAccessor:ym("rebuild",gm),valueAccessor:ym("rebuild",gm),oAccessor:ym("rebuild",gm),rAccessor:ym("rebuild",gm),stackBy:ym("rebuild",gm),groupBy:ym("rebuild",gm),timeAccessor:ym("rebuild",gm),accessorRevision:ym("rebuild",gm),colorAccessor:ym("rebuild",vm),symbolAccessor:ym("rebuild",xm),connectorAccessor:ym("rebuild",xm),dataIdAccessor:ym("rebuild",xm),projection:ym("preserve",mm),extentPadding:ym("preserve",mm),axisExtent:ym("preserve",mm),rExtent:ym("preserve",mm),oExtent:ym("preserve",mm),multiAxis:ym("preserve",mm),normalize:ym("preserve",mm),bins:ym("preserve",mm),oSort:ym("preserve",bm),barPadding:ym("preserve",bm),roundedTop:ym("preserve",bm),baselinePadding:ym("preserve",bm),innerRadius:ym("preserve",bm),cornerRadius:ym("preserve",bm),startAngle:ym("preserve",bm),sweepAngle:ym("preserve",bm),trackFill:ym("preserve",bm),showOutliers:ym("preserve",bm),showIQR:ym("preserve",bm),amplitude:ym("preserve",bm),connectorOpacity:ym("preserve",bm),showLabels:ym("preserve",bm),dynamicColumnWidth:ym("rebuild",bm),customLayout:ym("preserve",bm),layoutConfig:ym("preserve",bm),layoutMargin:ym("preserve",bm),symbolMap:ym("preserve",xm),pieceStyle:ym("preserve",vm),summaryStyle:ym("preserve",vm),connectorStyle:ym("preserve",vm),gradientFill:ym("preserve",vm),colorScheme:ym("preserve",vm),themeCategorical:ym("preserve",vm),themeSemantic:ym("preserve",vm),themeSequential:ym("preserve",vm),themeDiverging:ym("preserve",vm),barColors:ym("preserve",vm),decay:ym("preserve",vm),pulse:ym("preserve",vm),staleness:ym("preserve",vm),layoutSelection:ym("preserve",vm),windowSize:ym("preserve",wm),windowMode:ym("preserve",wm),clock:ym("preserve",wm),transition:ym("preserve",wm),introAnimation:ym("preserve",wm),onLayoutError:ym("preserve",wm)},Am=ym("preserve",bm),Sm=class{constructor(){this.tracker=new Yo}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}},fm)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},pm):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=km[n]??Am;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as Mm}from"d3-quadtree";var _m=class{constructor(t){this.rExtent=new Me,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Sm,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new rm,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 Se(t.windowSize),this.getO=y(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>h(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Me)):(this.getR=h(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=y(t.stackBy),this.getGroup=y(t.groupBy),this.getColor=y(t.colorAccessor),this.getSymbol=y(t.symbolAccessor),this.getConnector=y(t.connectorAccessor),this.getDataId=y(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new Se(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,n;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,n=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:Ro(e,n):null)}currentTime(){return this.config.clock?.()??Ie()}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(),Co(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Io(this.buffer,o,this.timestampBuffer,e),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of t.inserts){const t=Io(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),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 o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.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(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",c=e.oExtent||this.resolveCategories(s),l=this.computeValueDomain(s,c),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=nm().domain(c).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;p=im().domain(l).range([n,o])}else u?(f=nm().domain(c).range([0,t.height]).padding(h),p=im().domain(l).range([0,t.width])):(f=nm().domain(c).range([0,t.width]).padding(h),p=im().domain(l).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const c=a-s,l=c>0?c*(e.extentPadding??.05):1;return s-=l,a+=l,s>0&&(s=0),u?im().domain([s,a]).range([0,t.width]):im().domain([s,a]).range([t.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(y,c,f,a,t),this._customLayoutFailedThisBuild=!1;const g=this.buildSceneNodes(y,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===e?void 0:e;let i=null;if(o){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(o&&void 0===n){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===n)return r;if("function"==typeof n)return r.sort(n);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"===n?(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:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let p=0,y=0;if("bar"===o&&d&&i)p=0,y=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=l(n),i=u(n);0>i?o.set(e,(o.get(e)||0)+i):t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>y&&(y=e);for(const t of o.values())p>t&&(p=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=l(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e),p>e&&(p=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=l(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>y&&(y=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(y=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(y=r[1]));const g="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(g&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>y&&(y=0)),"bar-funnel"!==o&&"exact"!==c){const t=y-p,e=t>0?t*f:1,n=g&&!a&&0===p,i=g&&!a&&0===y||"swimlane"===o;null!=r?.[0]||n||(p-=e),null!=r?.[1]||i||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,n,i){return function(t){const{data:e,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:c}=t,l={},u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(c(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let n;n="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,n),t+=n}const e=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(t>0)for(const[o,n]of h)h.set(o,n/t*e)}let f=0,p=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(c(e)),0),i=d>0?o/d:0;let r,s;h?(r=p,s=h.get(t)||n.bandwidth(),p+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),l[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:f},f+=i}return l}({data:t,oExtent:e,oScale:o,projection:n,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 o=this.buildLayoutContext(t,e);let n;try{n=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=xo("ordinal",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.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=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;const i=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.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 go({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 o=this.getSceneContext(),n=hm[this.config.chartType];let i=n?n(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:n,getConnector:i,getO:r}=t;if(!i||!o)return[];const s=[],{projection:a}=o,c=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const o=i(e);if(!o)continue;let n,s;"point"===t.type?(n=t.x,s=t.y):(n=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:n,y:s,datum:e,category:r(e)})}const l=o.o.domain(),u=n.connectorStyle;for(const[e,o]of c)if(o.length>=2){o.sort((t,e)=>l.indexOf(t.category)-l.indexOf(e.category));for(let n=0;o.length-1>n;n++){const i=o[n],r=o[n+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}(o,i);i=[...t,...i]}return i}buildLayoutContext(t,e){const o=this.config,n=o.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Wp(o.colorScheme,o.themeCategorical,St),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:n,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:o.themeSemantic??{},categorical:[...i]},resolveColor:jp(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Le(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=Te(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 o="function"==typeof e,n=o?null:e||"category",i=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[n],c=i.get(a);c?c.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,o=0;for(const n of t)"point"===n.type&&(e++,n.r>o&&(o=n.r));if(500>=e)return{quadtree:null,maxRadius:o};const n=Array(e);let i=0;for(const e of t)"point"===e.type&&(n[i++]=e);return{maxRadius:o,quadtree:Mm().x(t=>t.x).y(t=>t.y).addAll(n)}}(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 o=e.length;if(1>=o)return;const n=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=n.get(e.datum);if(null==t)continue;const i=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*i}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;for(const l of e){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const e=l.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,$e(t,e,r)))}c=ze(l,n,s)||c;continue}if(null==l.datum)continue;const e=n.get(l.datum);if(null==e)continue;const u=o.get(e);c=ze(l,null==u?0:$e(t,u,r),s,a)||c}return c}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),o)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&De(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,o="horizontal"!==this.scales?.projection;let n;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,o?{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===n&&(n=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:n,endAngle:n,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const o=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,n=e.get(o)||0;return e.set(o,n+1),`${o}:${n}`}return"rect"===t.type?`r:${t.group||""}:${t.datum?.category??""}`:"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=this.getNodeKey(o,t);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity}):"wedge"===o.type&&this.prevPositionMap.set(n,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.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 o=new Set,n=new Map;for(let t=0;this.scene.length>t;t++){const i=this.scene[t],r=this.getNodeKey(i,n);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??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??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},e=!0);else if("rect"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??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??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??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??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,n]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:n.x,y:n.y,r:n.r??3,style:{opacity:n.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{opacity:n.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((n.startAngle??0)+(n.endAngle??0))/2,o={type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,style:{opacity:n.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(o)}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=Ce(t,this.activeTransition),o=Pe(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 n=this.prevPositionMap.get(e);t.style.opacity=Re(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Re(n.x,t._targetX,o),t.y=Re(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Re(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Re(n?n.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const n=this.prevPositionMap.get(e);if(!n)continue;t.x=Re(n.x,t._targetX,o),t.y=Re(n.y,t._targetY,o),void 0!==n.w&&(t.w=Re(n.w,t._targetW,o),t.h=Re(n.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style={...t.style,opacity:Re(n?n.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const n=this.prevPositionMap.get(e);n&&void 0!==n.startAngle&&(t.startAngle=Re(n.startAngle,t._targetStartAngle,o),t.endAngle=Re(n.endAngle,t._targetEndAngle,o))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=_e(t),o=this.getDataId,n=t=>e.has(o(t));Lo(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);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 o=_e(t),n=this.getDataId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(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 o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.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 o={...this.config},n=Object.keys(e).filter(t=>e[t]!==o[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==o.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${o.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!==o.colorScheme||"themeCategorical"in e&&e.themeCategorical!==o.themeCategorical||"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!t(e.categoryAccessor,o.categoryAccessor)||"oAccessor"in e&&!t(e.oAccessor,o.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,o.categoryAccessor||o.oAccessor)||(this.getO=y(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,n=o.valueAccessor||o.rAccessor,i=Array.isArray(e)?e:[e],s=Array.isArray(n)?n:[n];if(r=i.length!==s.length||i.some((e,o)=>!t(e,s[o])),r){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>h(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Me)):(this.getR=h(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!t(e.stackBy,o.stackBy)&&(this.getStack=null!=this.config.stackBy?y(this.config.stackBy):void 0),"groupBy"in e&&!t(e.groupBy,o.groupBy)&&(this.getGroup=null!=this.config.groupBy?y(this.config.groupBy):void 0),"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?y(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!t(e.symbolAccessor,o.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?y(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!t(e.connectorAccessor,o.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?y(this.config.connectorAccessor):void 0),(i||r||"accessorRevision"in e&&e.accessorRevision!==o.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(n)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Bo(_m);import{jsx as Pm,jsxs as Cm}from"react/jsx-runtime";import{Fragment as Rm,jsx as Im,jsxs as Lm}from"react/jsx-runtime";function Tm(t,e){const o=E(t.theme),n=t.size||[500,400],i=Is({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Cs(t.title),s=H(t.data),a=t.showLegend?Ig(s,t.colorAccessor||t.stackBy||t.groupBy):[];Vg(i,{props:t,categories:a,theme:o,size:n,hasTitle:r});const c=n[0]-i.left-i.right,l=n[1]-i.top-i.bottom,u=t.projection||"vertical",d="radial"===u,h={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:u,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:t.gradientFill,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:t.colorScheme||o.colors.categorical,themeCategorical:o.colors.categorical,themeSemantic:_(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},f=new _m(h);if(t.data&&f.ingest({inserts:s,bounded:!0}),f.computeScene({width:c,height:l}),!f.scales||0===f.scene.length)return e&&(e.evidence=mg({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:f.scales?[]:["NO_SCALES"],margin:i})),om.renderToStaticMarkup(Zg(null,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:l,idPrefix:t._idPrefix}));const p=t._idPrefix,y=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=O(o),a=n?n+"-":"",c="vertical"===r.projection,l=ks(r.r,5,i);return Ng("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const n=r.r(t);return Ng("line",{x1:0,y1:n,x2:e.width,y2:n,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const n=r.r(t);return Ng("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(f,{width:c,height:l},o,p,t.axisExtent):null;let g=null;if(f.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=Yg(t),n=new Set;for(const t of f.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");g=Array.from(n).map((t,n)=>function(t){const{id:e,background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return Cm("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Pm("rect",{width:a,height:a,fill:o}),Pm("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Pm("line",{x1:r,y1:0,x2:r,y2:a,stroke:n,strokeWidth:i})]},e)}({id:`funnel-hatch-${e}-${n}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(n).forEach((t,o)=>i.set(t,`funnel-hatch-${e}-${o}`));for(const t of f.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 m=kl({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>ha(t,e,p)}),b=m.map(t=>t.element);if(e){const o=f.scales.o?.domain?.();e.evidence=mg({frameType:"ordinal",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,yDomain:gg(f.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const x=!1!==t.showAxes?function(t,e,o,n,i){const r=t.scales;if(!r)return null;if("radial"===r.projection)return null;const s=O(n),a="vertical"===r.projection,c=o.categoryFormat||o.oFormat,l=o.valueFormat||o.rFormat,u=o.categoryLabel||o.oLabel,d=o.valueLabel||o.rLabel,h=Object.values(t.columns).map(t=>({pixel:t.middle,label:(c||String)(t.name)})),f=ks(r.r,5,o.axisExtent).map(t=>({pixel:r.r(t),label:(l||Kg)(t)}));return Lm("g",a?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Im("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,o)=>Lm("g",{transform:`translate(${t.pixel},${e.height})`,children:[Im("line",{y2:5,stroke:s.border,strokeWidth:1}),Im("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+o)),u&&Im("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),Im("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,e)=>Lm("g",{transform:`translate(0,${t.pixel})`,children:[Im("line",{x2:-5,stroke:s.border,strokeWidth:1}),Im("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),d&&Im("text",{x:15-(o.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${e.height/2})`,children:d})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Im("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,o)=>Lm("g",{transform:`translate(${t.pixel},${e.height})`,children:[Im("line",{y2:5,stroke:s.border,strokeWidth:1}),Im("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+o)),d&&Im("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:d}),Im("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,e)=>Lm("g",{transform:`translate(0,${t.pixel})`,children:[Im("line",{x2:-5,stroke:s.border,strokeWidth:1}),Im("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),u&&Im("text",{x:15-(o.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${e.height/2})`,children:u})]})}(f,{width:c,height:l},t,o,p):null,v=t.annotations?Fg({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:f.scales.o,r:f.scales.r,y:"vertical"===f.scales.projection?f.scales.r:void 0},layout:{width:c,height:l},theme:o,projection:u,idPrefix:p}):null,w=Ug({props:t,categories:a,theme:o,size:n,margin:i,hasTitle:r}),k=d?i.left+c/2:i.left,A=d?i.top+l/2:i.top,S=d&&t.centerContent?Im("foreignObject",{x:i.left,y:i.top,width:c,height:l,pointerEvents:"none",children:Im("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null;return om.renderToStaticMarkup(Zg(Lm(Rm,{children:[t.backgroundGraphics,y,b,x,v,t.foregroundGraphics,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${k},${A})`,innerWidth:c,innerHeight:l,legend:w,defs:g,outerElements:S,idPrefix:t._idPrefix}))}import*as $m from"react-dom/server";function zm(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function Dm(t,e){var o,n=[],i=[],r=[],s={},a=[];function c(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&c(e)})}function l(t){var e,n,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(n=a[t][e])===o?(u(o,i),d=!0):r[n]||(d=l(n));if(d)c(t);else for(e=0;a[t].length>e;e++){var h=s[n=a[t][e]];h||(s[n]=h={}),h[n]=!0}return i.pop(),d}function u(t,o){var i=[].concat(o).concat(t);e?e(i):n.push(i)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,n=function(t){for(var e=t.length,o=Array(e),n=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),c=0;e>c;++c)o[c]=-1,n[c]=0,i[c]=!1,r[c]=0,s[c]=-1,a[c]=[];var l,u=0,d=[],h=[];function f(e){var c=[e],l=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;l.length>0;){var f=t[e=l[l.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>o[y]){o[y]=n[y]=u,i[y]=!0,u+=1,c.push(y),l.push(y);break}i[y]&&(n[e]=0|Math.min(n[e],n[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(n[e]===o[e]){var g=[],m=[],b=0;for(p=c.length-1;p>=0;--p){var x=c[p];if(i[x]=!1,g.push(x),m.push(a[x]),b+=a[x].length,s[x]=d.length,x===e){c.length=p;break}}d.push(g);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)}l.pop()}}}for(c=0;e>c;++c)0>o[c]&&f(c);for(c=0;h.length>c;c++){var p=h[c];if(0!==p.length){p.sort(function(t,e){return t-e}),l=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&l.push(p[y]);h[c]=l}}return{components:d,adjacencyList:h}}(t),i=n.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],o=s);var c=i[o];return!!c&&{leastVertex:r,adjList:t.map(function(t,e){return-1===c.indexOf(e)?[]:t.filter(function(t){return-1!==c.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var f=d(o);if(o=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var y=0;a[p].length>y;y++){var g=a[p][y];r[+g]=!1,s[g]={}}l(o),o+=1}else o=h}return e?void 0:n}function Em(t){return t.y0-t.y1>0?"up":"down"}function Om(t,e){return e(t.source)==e(t.target)}function Fm(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var o=0;return t.target.targetLinks.forEach(function(t){o=t.circular?o+1:o}),1>=e&&1>=o}function Bm(t){return t.target.x0-t.source.x1}function Nm(t,e){var o=jm(t),n=Bm(e)/Math.tan(o);return"up"==Em(t)?t.y1-n:t.y1+n}function Wm(t,e){var o=jm(t),n=Bm(e)/Math.tan(o);return"up"==Em(t)?t.y1+n:t.y1-n}function jm(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function Ym(t,e){return e(t)}function Gm(t){return Xm(t.source)}function qm(t){return Xm(t.target)}function Xm(t){return(t.y0+t.y1)/2}function Hm(t){return t.virtual?0:t.value}function Vm(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!Om(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!Om(t,e)?n+1:n}),o+n}function Um(t){return t.target.depth}function Km(t,e){return t.sourceLinks.length?t.depth:e-1}function Zm(t,e){return t.y0-e.y0}function Qm(t,e){return e.y0-t.y0}function Jm(t,e){return t.y1-e.y1}function tb(t,e){return e.y1-t.y1}function eb(t,e){return nb(t.source,e.source)||t.index-e.index}function ob(t,e){return nb(t.target,e.target)||t.index-e.index}function nb(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function ib(t,e){return rb(t)==rb(e)?"bottom"==t.circularLinkType?Qm(t,e):Zm(t,e):rb(e)-rb(t)}function rb(t){return t.target.column-t.source.column}function sb(t,e){return ab(t)==ab(e)}function ab(t){return t.y0-t.y1>0?"up":"down"}import{min as cb}from"d3-array";function lb(t,e,o,n,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=cb(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var c=r.links.filter(function(t){return t.circular});return c.sort(function(t,e){return e.value-t.value}),c.forEach(function(t,e){t._circularStub=e>=4}),ub(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),ub(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,o),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+n,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,Om(t,e)&&Fm(t))t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=n+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,c=t.circularLinkType,l=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==c});l.sort("bottom"==t.circularLinkType?Qm:Zm);var u=0;l.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),s=t.target.column,(l=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==c})).sort("bottom"==t.circularLinkType?tb:Jm),u=0,l.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2+i*o+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,o=t.y0,n=t.target.x0,i=t.y1,r=(e+n)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+i+" "+n+","+i}(t)}),r}function ub(t,e,o){t.sort(ib);var n=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(Om(t,e)&&Fm(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;n.length>s;s++){var a=n[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&db(t,a)){var c=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=c>r?c:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function db(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as hb,max as fb,sum as pb,mean as yb,group as gb,groups as mb}from"d3-array";function bb(t){return function(){return t}}function xb(t){return t.index}function vb(t){return t.nodes}function wb(t){return t.links}function kb(t,e,o){var n=mb(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});n.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 o,n,i,r=(n=0,i=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Xm(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Xm(t.target)*e,n+=e}}),n>0?i/n:NaN);a.set(t,{bc:r,idx:e})}),i.sort(function(t,e){var o=a.get(t),n=a.get(e),i=o.bc,r=n.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)?o.idx-n.idx:1:-1:i-r})}else i.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Vm(e,o)-Vm(t,o):"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==n.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==Vm(e,o)?(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 Ab(t,e,o,n,i,r){var s=mb(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,c=r;c>0;--c)l(a*=.99,o),u();function l(e,o){var n=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&&Vm(i,o)>0){var c=yb(i.sourceLinks,qm),l=yb(i.targetLinks,Gm),u=c&&l?(c+l)/2:c||l;if(u){var d=(u-Xm(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==n-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=yb(i.sourceLinks,qm),f=yb(i.targetLinks,Gm),p=((h&&f?(h+f)/2:h||f)-Xm(i))*e;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,c=t.y0,l=o.length;for(o.sort(e||nb),a=0;l>a;++a)(s=c-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),c=r.y1+n;if((s=c-n-t.y1)>0)for(c=r.y0-=s,r.y1-=s,a=l-2;a>=0;--a)(s=(r=o[a]).y1+i-c)>0&&(r.y0-=s,r.y1-=s),c=r.y0})}}function Sb(t){t.nodes.forEach(function(t){t.sourceLinks.sort(ob),t.targetLinks.sort(eb)}),t.nodes.forEach(function(t){var e=t.y0,o=e,n=t.y1,i=n;t.sourceLinks.forEach(function(t){t.circular?(t.y0=n-t.width/2,n-=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=o+t.width/2,o+=t.width)})})}function Mb(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=xb,c=Km,l=void 0,u=32,d=2,h=vb,f=wb;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=o,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return gb(t,e).forEach(function(t,e){o.set(e,t[0])}),o}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var n=t.source,i=t.target;"object"!=typeof n&&(n=t.source=zm(o,n)),"object"!=typeof i&&(i=t.target=zm(o,i)),n.sourceLinks.push(t),i.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var n=[],i=0;t.links.length>i;i++){var r=t.links[i],s=r.source.index,a=r.target.index;n[s]||(n[s]=[]),n[a]||(n[a]=[]),-1===n[s].indexOf(a)&&n[s].push(a)}var c=Dm(n);c.sort(function(t,e){return t.length-e.length});var l={};for(i=0;c.length>i;i++){var u=c[i].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||l[n]&&l[n][e]?(t.circular=!0,t.circularLinkID=o++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=o++)})}(h,l),function(t,e){var o=0,n=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:n>o?"top":"bottom","top"==i.circularLinkType?o++:n++,t.nodes.forEach(function(t){Ym(t,e)!=Ym(i.source,e)&&Ym(t,e)!=Ym(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),Om(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(pb(t.sourceLinks,Hm),pb(t.targetLinks,Hm)),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,o){var n,i,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-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(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.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?o(t,r):t.column})}(h,l,c);var f=r;if(null!==s){var p=mb(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=fb(p,function(t){return t.length});y>1&&(f=Math.max(1,(n-e)*s/(y-1)))}(function(t,e,o){var n=mb(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=hb(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/pb(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=fb(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,f,i),kb(h,l,a),Ab(h,l,a,f,f,u),Sb(h),lb(h,a,d,10,8),kb(h,l,a),Ab(h,l,a,f,f,u),Sb(h),lb(h,a,d,10,8),function(t,e){let o=t;o.nodes.forEach(function(t){t.y+(t.y1-t.y0)>o.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-o.y1));var n=o.links.filter(function(o){return Ym(o.source,e)==Ym(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!sb(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=Nm(e,t);return t.y1-o}if(e.target.column>t.target.column)return Nm(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;n.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var n=o.links.filter(function(o){return Ym(o.target,e)==Ym(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!sb(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=Wm(e,t);return t.y0-o}if(e.source.column>t.source.column)return Wm(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;n.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,n=!1,i=!1;if(o.forEach(function(t){"top"==t.circularLinkType?n=!0:"bottom"==t.circularLinkType&&(i=!0)}),0==n||0==i){let n=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=hb(e,function(t){return t.y0}),s=fb(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1)}),o.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=n(t.y0)-t.y0;t.y0=n(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+o}),t.targetLinks.forEach(function(t){t.y1=t.y1+o})})}}(h),lb(h,a,d,10,8)}(p),p}return p.update=function(t){return Sb(t),lb(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:bb(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:bb(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:bb(t),p):a},p.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:bb(t),p):c},p.nodeSort=function(t){return arguments.length?(l=t,p):l},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(d=+t,p):d},p.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],p):[[t,e],[o,n]]},p.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],p):[o-t,n-e]},p}import{interpolateNumber as _b}from"d3-interpolate";import{line as Pb,curveLinearClosed as Cb}from"d3-shape";var Rb=t=>{let e,o,n,i,r,s,a,c,l;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,n=t.y1+t.sankeyWidth/2,i=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=_b(r,s),c=a(.5),l=a(.5),`M${e},${r}C${e},${c} ${o},${l} ${o},${s}L${n},${s}C${n},${l} ${i},${c} ${i},${r}Z`;const u=t.sankeyWidth/2,d=_b(t.source.x1,t.target.x0),{pathD:h}=zh({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 Ib(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,n=t.circularPathData;if(!n)return null;if("down"===t.direction)return null;if(t._circularStub){const o=n.sourceX,i=n.sourceY,r=n.targetX,s=n.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*(n.rightFullExtent-o))),c=Math.max(15,Math.min(40,.33*(r-n.leftFullExtent)));return`M${o},${i-e}L${o+a},${i-e}L${o+a},${i+e}L${o},${i+e}ZM${r},${s-e}L${r-c},${s-e}L${r-c},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,c=n.rightFullExtent,l=n.leftFullExtent,u=n.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${i},${r-d*e}L${c},${r-d*e}L${c+o},${r-d*e+d*h}L${c+o},${u+d*o-d*h}L${c+o-h},${u+d*o}L${l-o+h},${u+d*o}L${l-o},${u+d*o-d*h}L${l-o},${a-d*e+d*h}L${l-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${l+o},${a+d*e}L${l+o},${u-d*o}L${c-o},${u-d*o}L${c-o},${r+d*e}L${i},${r+d*e}Z`}var Lb=new Set,Tb=new WeakMap;function $b(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=Tb.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,Tb.set(t,o);const n=new Proxy(t,{get(t,o,n){if("string"==typeof o&&!(o in t)&&t.data&&o in t.data){const t=`${e}:${o}`;Lb.has(t)||(Lb.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${o}" on the wrapper object, but it only exists on ".data". Use d.data.${o} (or d.data?.${o}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,o,n)}});return o.set(e,n),n}var zb={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(Um))-1:0},justify:Km};function Db(t){return"string"==typeof t?t:t.id}var Eb={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i="vertical"===o.orientation?"down":"right",r=o.nodeAlign||"justify",s=o.nodeWidth??15,a=o.nodePaddingRatio??.05,c=o.iterations??100,l=t.map(t=>({...t})),u=e.map(t=>({...t,source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id,value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===i?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const h=Mb().extent(d).links(u).nodes(l).nodeAlign(zb[r]||Km).nodeId(t=>t.id).nodeWidth(s).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of l)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),o>n.y0&&(o=n.y0),n.y1>i&&(i=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const r=n.circularPathData,s=(n._circularWidth??n.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-o,a=n[0],c=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>c)){const e=Math.min(a/r,c/s),n=-t*e+(a-r*e)/2,i=-o*e+(c-s*e)/2;for(const t of l)t.x0=t.x0*e+n,t.x1=t.x1*e+n,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 o=t.circularPathData;o.sourceX=o.sourceX*e+n,o.targetX=o.targetX*e+n,o.sourceY=o.sourceY*e+i,o.targetY=o.targetY*e+i,o.rightFullExtent=o.rightFullExtent*e+n,o.leftFullExtent=o.leftFullExtent*e+n,o.verticalFullExtent=o.verticalFullExtent*e+i,o.rightInnerExtent=o.rightInnerExtent*e+n,o.leftInnerExtent=o.leftInnerExtent*e+n,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+i,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+i,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of l){const e=f.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const p=new Map;for(const t of e)p.set(t._edgeKey?t._edgeKey:`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const t of u){const e=Db(t.source),o=Db(t.target),n=p.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(n){n.y0=t.y0,n.y1=t.y1,n.sankeyWidth=t.width??0,n.circular=!!t.circular,n.circularPathData=t.circularPathData,n._circularWidth=t._circularWidth,n._circularStub=t._circularStub,n.path=t.path,n.circularLinkType=t.circularLinkType,n.direction=i;const r=f.get(e),s=f.get(o);r&&(n.source=r),s&&(n.target=s)}}},buildScene(t,e,o,n){const i="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,c=o.edgeColorBy||"source",l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Q,u=new Map;t.forEach((t,e)=>{u.set(t.id,l[e%l.length])});const d=[],h=[],f=[],p=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const n=r?r($b(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity};p.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:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,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,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";i="function"==typeof c?c(t)||i:"target"===c?p.get(n.id)||u.get(n.id)||i:p.get(e.id)||u.get(e.id)||i;const r=s?s($b(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,n=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),c=r.fill||i;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+n},${e.sourceY-o}L${e.sourceX+n},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+n}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-o}L${e.targetX-s},${e.targetY-o}L${e.targetX-s},${e.targetY+o}L${e.targetX},${e.targetY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let l;(l=t.circular&&t.circularPathData?Ib(t):Rb(t),l)&&h.push({type:"bezier",pathD:l,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!==o.showLabels){const e=(g=o.nodeLabel)?"function"==typeof g?g:t=>t[g]||t.id:null;for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,c,l;"down"===i?(a=o.y0+(o.y1-o.y0)/2,c=o.x1+14,l="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,l="end"):(a=o.x1+6,l="start"),c=o.y0+r/2),f.push({x:a,y:c,text:s+"",anchor:"down"===i?"middle":l,baseline:"middle",fontSize:11})}}var g;return{sceneNodes:d,sceneEdges:h,labels:f}}};import{forceSimulation as Ob,forceCenter as Fb,forceX as Bb,forceY as Nb,forceLink as Wb,forceManyBody as jb,forceCollide as Yb}from"d3-force";import{scaleLinear as Gb}from"d3-scale";var qb={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i=o.forceStrength??.1,r=n[0]/2,s=n[1]/2,a=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),c=Math.min(.5,.06+1.8*(1-a)),l=o.__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),o=l?.get(e.id);t?u++:o?(e.x=o.x,e.y=o.y,u++):d.push(e)}const h=u>0&&.3>=(t.length>0?d.length/t.length:1);if(h){const o=new Map;for(const e of t)o.set(e.id,e);for(const t of d){const n=Xb(t.id,e,o);if(n.length>0){let e=0,o=0;for(const t of n)e+=t.x,o+=t.y;const i=Hb(t.id),r=i%360*(Math.PI/180),s=(10+i%20)*a;t.x=e/n.length+s*Math.cos(r),t.y=o/n.length+s*Math.sin(r)}else{const e=Hb(t.id),o=e%360*(Math.PI/180),n=(15+e%30)*a;t.x=r+n*Math.cos(o),t.y=s+n*Math.sin(o)}}}else{const e=2.399963229728653;for(let o=0;t.length>o;o++){const n=t[o];if(null==n.x||null==n.y||0===n.x&&0===n.y){const t=10*Math.sqrt(o+.5)*a,i=o*e;n.x=r+t*Math.cos(i),n.y=s+t*Math.sin(i)}}}const f=o.__skipForceSimulation||0===o.iterations?0:h?40:o.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),p=Vb(o.nodeSize,o.nodeSizeRange,t),y=t=>p(t);if(f>0){const l=new Map,u=new Map;for(const e of t)l.set(e.id,0),u.set(e.id,e);for(const t of e){const e="string"==typeof t.source?t.source:t.source.id,o="string"==typeof t.target?t.target:t.target.id;l.set(e,(l.get(e)??0)+1),l.set(o,(l.get(o)??0)+1)}const d=Wb().strength(t=>{const e=t.weight,o="string"==typeof t.target?t.target:t.target.id,n=Math.max(1,Math.min(l.get("string"==typeof t.source?t.source:t.source.id)??1,l.get(o)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*i/(.1*n))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,o="string"==typeof t.target?u.get(t.target):t.target,n=(e?y(e):0)+(o?y(o):0)+Math.max(6,12*a);return Math.max(16,40*a,n)}).id(t=>t.id),p=Ob();if(void 0===o.random&&void 0===o.seed||p.randomSource(o.random??_c(o.seed)),p.force("charge",jb().strength(t=>{const e=l.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",Yb(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",Fb(r,s).strength(.8)).force("x",Bb(r).strength(c)).force("y",Nb(s).strength(c)).force("bounds",function(t,e,o=2,n=.6){let i=[];const r=r=>{const s=n*Math.max(r,.2);for(const n of i){const i=n.x??t[0]/2,r=n.y??t[1]/2,a=n.vx??0,c=n.vy??0,l=e(n)+o,u=Math.min(t[0]/2,l),d=Math.max(t[0]/2,t[0]-l),h=Math.min(t[1]/2,l),f=Math.max(t[1]/2,t[1]-l),p=i+a,y=r+c;u>p?n.vx=a+(u-p)*s:p>d&&(n.vx=a+(d-p)*s),h>y?n.vy=c+(h-y)*s:y>f&&(n.vy=c+(f-y)*s)}};return r.initialize=t=>{i=t},r}(n,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id}));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),o=f>0?2:0,i=Math.min(n[0]/2,t+o),r=Math.min(n[1]/2,t+o);e.x=Math.max(i,Math.min(n[0]-i,e.x)),e.y=Math.max(r,Math.min(n[1]-r,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const g=new Map;for(const e of t)g.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=g.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=g.get(t.target);e&&(t.target=e)}}},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=Vb(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Q,c=new Map;t.forEach((t,e)=>{c.set(t.id,a[e%a.length])});const l=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s($b(e,"nodeSize")),n=i?i($b(e,"nodeStyle")):{},r={fill:n.fill||c.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??2,opacity:n.opacity};l.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),n="object"==typeof t.target?t.target:h.get(t.target);if(!e||!n)continue;if(null==e.x||null==e.y)continue;if(null==n.x||null==n.y)continue;const i=r?r($b(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:i.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.6},datum:t})}if(!1!==o.showLabels){const e=(f=o.nodeLabel)?"function"==typeof f?f:t=>t[f]||t.id:null;for(const o of t){if(null==o.x||null==o.y)continue;const t=e?e(o):o.id;if(!t)continue;const n=s($b(o,"nodeSize"));d.push({x:o.x,y:o.y-n-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}var f;return{sceneNodes:l,sceneEdges:u,labels:d}}};function Xb(t,e,o){const n=[];for(const i of e){const e="string"==typeof i.source?i.source:i.source.id,r="string"==typeof i.target?i.target:i.target.id;let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=o.get(s);!t||0===t.x&&0===t.y||n.push({x:t.x,y:t.y})}}return n}function Hb(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}function Vb(t,e,o){if(o.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 n=e||[5,20],i=[];for(const e of o){const o=e.data?.[t];"number"==typeof o&&i.push(o)}if(0===i.length)return()=>n[0];const[r,s]=M(i);if(r===s)return()=>(n[0]+n[1])/2;const a=Gb().domain([r,s]).range(n).clamp(!0);return e=>{const o=e.data?.[t];return null==o||"number"!=typeof o?n[0]:a(o)}}import{chord as Ub,ribbon as Kb}from"d3-chord";import{arc as Zb}from"d3-shape";var Qb=Q,Jb={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(n[0],n[1])/2,c=a-r,l=n[0]/2,u=n[1]/2,d=(h=o.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="string"==typeof t.target?t.target:t.target.id,o=f.get("string"==typeof t.source?t.source:t.source.id),n=f.get(e);if(void 0===o||void 0===n)continue;const i=d(t);y[o][n]=i}const g=Ub().padAngle(i);s&&g.sortGroups(s);const m=g(y),b=m.groups,x=Zb().innerRadius(c).outerRadius(a);for(const e of b){const o=t[e.index],n=x.centroid({innerRadius:c,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+l,o.y=n[1]+u,o.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,o=v.get("string"==typeof t.source?t.source:t.source.id),n=v.get(e);o&&(t.source=o),n&&(t.target=n)}const w=new Map;for(const t of e)w.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const e of m){const o=t[e.source.index].id,n=t[e.target.index].id,i=w.get(`${o}\0${n}`)||w.get(`${n}\0${o}`);i&&(i.__chordData=e)}},buildScene(t,e,o,n){const{groupWidth:i=20,edgeOpacity:r=.5}=o,s=Math.min(n[0],n[1])/2,a=s-i,c=n[0]/2,l=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",f=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Qb,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=Kb().radius(a),g=[],m=[],b=[];for(let e=0;t.length>e;e++){const o=t[e],n=o.__arcData;if(!n)continue;let i;i=u?u($b(o,"nodeStyle")).fill||p.get(o.id)||f[e%f.length]:p.get(o.id)||f[e%f.length];const r=u?u($b(o,"nodeStyle")):{};g.push({type:"arc",cx:c,cy:l,innerR:a,outerR:s,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const n=y(e);if(!n)continue;const i=tx(n,c,l);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d)s=d($b(t,"edgeStyle")).fill||s;else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=p.get(o.id)||s:e&&(s=p.get(e.id)||s)}const a=d?d($b(t,"edgeStyle")):{};m.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!==o.showLabels){const e=(x=o.nodeLabel)?"function"==typeof x?x:t=>t[x]||t.id:null,n=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const i=e?e(o):o.id;if(!i)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;b.push({x:c+Math.cos(s)*n,y:l+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}var x;return{sceneNodes:g,sceneEdges:m,labels:b}}};function tx(t,e,o){const n=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return t;const i=[];let r=0;for(;n.length>r;){const t=n[r];if("M"===t||"L"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("C"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;3>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("Q"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;2>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("A"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&(i.push(Number(n[r])+e+""),r++),n.length>r&&(i.push(Number(n[r])+o+""),r++);else"Z"===t||"z"===t?(i.push(t),r++):(i.push(n[r]),r++)}return i.join(" ")}import{hierarchy as ex,tree as ox,cluster as nx,treemap as ix,pack as rx,partition as sx,treemapBinary as ax}from"d3-hierarchy";var cx=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function lx(t){const[e,o,n]=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*o+.114*n>150?"#222":"#fff"}function ux(t,e,o){const n=e.nodeIDAccessor;return"function"==typeof n?n(t.data)+"":"string"==typeof n&&void 0!==t.data[n]?t.data[n]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function dx(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 hx(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:cx}function fx(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 px(t,e,o,n,i){if("horizontal"===i){const i=(t+o)/2;return`M ${t},${e} C ${i},${e} ${i},${n} ${o},${n}`}if("radial"===i){const i=(t+o)/2;return`M ${t},${e} Q ${i},${e} ${i},${(e+n)/2} T ${o},${n}`}{const i=(e+n)/2;return`M ${t},${e} C ${t},${i} ${o},${i} ${o},${n}`}}var yx={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;if(!i)return;const r=o.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(o.childrenAccessor),a=o.hierarchySum,c="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,l=ex(i,s);l.sum(c),l.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=n;switch(r){case"tree":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=ox();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(l,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=nx();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(l,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=ix().size([o,n]).tile(ax).padding(i);r>0&&s.paddingTop(r),s(t)}(l,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;rx().size([o,n]).padding(i)(t)}(l,o,u,d);break;case"partition":!function(t,e,o,n){sx().size([o,n]).padding(e.padding??1)(t)}(l,o,u,d)}const h=l.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:ux(n,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:n.value??0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===r||"cluster"===r?gx(i,n,o):"treemap"===r||"partition"===r?mx(i,n):"circlepack"===r&&bx(i,n),i.__hierarchyNode=n,t.push(i),f.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=f.get(t.parent),n=f.get(t);o&&n&&e.push({source:o,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,n){const i=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,n,i,r){const s=[],a=[],c=[],l=o.treeOrientation||"vertical",u="radial"===l,d=n[0]/2,h=n[1]/2,f="number"==typeof(p=o.nodeSize)?p:5;var p;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i($b(e,"nodeStyle"));let a=r.fill||fx(o);if(o.colorByDepth&&void 0!==e.depth){const t=hx(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:f,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:e,id:e.id,label:e.id,depth:e.depth})}const y=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=e.x,s=e.y,c=n.x,f=n.y;u&&(i+=d,s+=h,c+=d,f+=h);const p=px(i,s,c,f,l),g=r($b(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y},datum:t})}if(!1!==o.showLabels){const e=dx(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let n,i,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(n=s+t/o*10,i=a+e/o*10,r=0>t?"end":"start"):(n=s,i=a-12,r="middle")}else"horizontal"===l?(o.data?.children&&0!==o.data.children.length?(n=s-f-6,r="end"):(n=s+f+6,r="start"),i=a):(n=s,i=a+f+14,r="middle");c.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:c}}(t,e,o,n,i,r);case"treemap":case"partition":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=n($b(o,"nodeStyle"));let a=s.fill||fx(e);if(e.colorByDepth&&void 0!==o.depth){const t=hx(e);a=t[o.depth%t.length]}i.push({type:"rect",x:o.x0,y:o.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=dx(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,c=a.y1-a.y0;if(0>=t||0>=c)continue;const l=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!l)continue;if("parent"===i&&l)continue}const u=o?o(a):a.id;if(!u)continue;if((l?30:40)>t||(l?16:14)>c)continue;let d=n($b(a,"nodeStyle")).fill||fx(e);if(e.colorByDepth&&void 0!==a.depth){const t=hx(e);d=t[a.depth%t.length]}const h="string"==typeof d?lx(d):e.themeSemantic?.text??"#000";r.push(l?{x:a.x0+t/2,y:a.y0+c/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill: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,o,0,i);case"circlepack":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=n($b(o,"nodeStyle"));let s=r.fill||fx(e);if(e.colorByDepth&&void 0!==o.depth){const t=hx(e);s=t[o.depth%t.length]}i.push({type:"circle",cx:o.x,cy:o.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=dx(e.nodeLabel);for(const i of t){const t=i.__radius??5,s=o?o(i):i.id;if(!s)continue;if(15>t)continue;const a=!(i.data?.children&&i.data.children.length>0);let c=n($b(i,"nodeStyle")).fill||fx(e);if(e.colorByDepth&&void 0!==i.depth){const t=hx(e);c=t[i.depth%t.length]}if(a){const o="string"==typeof c?lx(c):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:o})}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,o,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function gx(t,e,o){const n=o.treeOrientation||"vertical";if("radial"===n){const o=e.x,n=e.y;t.x=n*Math.cos(o-Math.PI/2),t.y=n*Math.sin(o-Math.PI/2)}else"horizontal"===n?(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 mx(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 bx(t,e){const o=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-o,t.x1=e.x+o,t.y0=e.y-o,t.y1=e.y+o,t.width=2*o,t.height=2*o,t.__radius=o}import{pie as xx}from"d3-shape";function vx(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var wx={sankey:Eb,force:qb,chord:Jb,tree:yx,cluster:yx,treemap:yx,circlepack:yx,partition:yx,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;i&&function(t,e,o,n,i){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(o.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(o.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(o.orbitMode),c=o.orbitSize??2.95,l=o.orbitEccentricity??1,u="number"==typeof c?()=>c:c,d="number"==typeof l?()=>l:l,h=vx(o);h.metaMap.clear(),n.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 y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,b=p(s(t));n.push({id:b,x:y,y:g,x0:y,x1:y,y0:g,y1:g,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,o,c,l,f,y,g){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 A=(b+1)/x,S={id:o,depth:y,data:e,parentId:o},M=g?f/u(S)*A:f*A,_=xx().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(S);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=c+M*Math.sin(r),f=l+M*Math.cos(r)*P;n.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:y,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:y,parentId:o,eccentricity:P}),i.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,f,M,y+1,!0)}k+=v}}(t,b,y,g,m,1,!1)}(i,n,o,t,e)},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.nodeSize,s="number"==typeof r?()=>r:"function"==typeof r?r:()=>6,a=[],c=[],l=[];if(!1!==o.orbitShowRings){const e=vx(o),n=new Map;for(const e of t)n.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=n.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;i.has(o)||i.set(o,{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:o,ecc:n}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,l=(i+1)/r*Math.PI*2;c.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(l),y2:e+o*Math.cos(l)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=s($b(e,"nodeSize")),n=i?i($b(e,"nodeStyle")):{};a.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:n.fill||o.themeSemantic?.primary||"#6366f1",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.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),o="object"==typeof t.target?t.target:u.get(t.target);e&&o&&(null!=e.x&&null!=o.x&&c.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:t}))}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=s($b(o,"nodeSize"));if(4>=t)continue;const n="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;l.push({x:o.x,y:o.y+t+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:a,sceneEdges:c,labels:l}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=vx(e),n=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())-o.startTime)/1e3,s=n*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=o.metaMap.get(e.id);if(!t||!t.parentId)continue;const n=a.get(t.parentId);if(!n)continue;const c=t.angle+r*s*i({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=n.x+t.ring*Math.sin(c),e.y=n.y+t.ring*Math.cos(c)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)}};import{Fragment as kx,jsxs as Ax}from"react/jsx-runtime";function Sx(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var Mx=new Set(["tree","cluster","treemap","circlepack","partition"]);function _x(t,e){const o=E(t.theme),n=t.chartType||"force",i=()=>mg({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=Is({top:20,right:20,bottom:20,left:20,...t.margin},t.title),a=Cs(t.title),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const n=H(t.nodes||[]);if(n.length>0)return Ig(n,e);const i=Array.isArray(t.edges)?H(t.edges):[];if(0===i.length)return[];const r=Sx(t.sourceAccessor,"source"),s=Sx(t.targetAccessor,"target");return Ig(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Vg(s,{props:t,categories:c,theme:o,size:r,hasTitle:a});const l=r[0]-s.left-s.right,u=r[1]-s.top-s.bottom,d=function(t){return wx[t]}(n);if(!d&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const h={chartType:n,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||o.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(Mx.has(n)){const n=t.data||t.edges;if(!n||Array.isArray(n))return e&&(e.evidence=i()),$m.renderToStaticMarkup(Zg(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:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:l,innerHeight:u,idPrefix:t._idPrefix}));h.__hierarchyRoot=n,f=[],p=[]}else{const n=H(t.nodes||[]),a=Array.isArray(t.edges)?H(t.edges):[];if(0===n.length&&0===a.length)return e&&(e.evidence=i()),$m.renderToStaticMarkup(Zg(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:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:l,innerHeight:u,idPrefix:t._idPrefix}));if(p=function(t,e){const o=Sx(e.sourceAccessor,"source"),n=Sx(e.targetAccessor,"target"),i=Sx(e.valueAccessor,"value");return t.map(t=>({source:o(t)+"",target:n(t)+"",value:Number(i(t))||1,y0:0,y1:0,sankeyWidth:0,data:t}))}(a,h),0===n.length&&p.length>0){const t=new Set;for(const e of p){const o=jg(e.source),n=jg(e.target);o&&t.add(o),n&&t.add(n)}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 o=Sx(e.nodeIDAccessor,"id");return t.map(t=>({id:o(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}))}(n,h)}let y=[],g=[],m=[],b=null;if(h.customNetworkLayout){const t=h.colorScheme,e=Wp(t,o.colors.categorical,Q),n=jp(e,t),i={nodes:f,edges:p,dimensions:{width:l,height:u,plot:{x:0,y:0,width:l,height:u}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:h.layoutConfig??{}},r=h.customNetworkLayout(i);y=r.sceneNodes??[],g=r.sceneEdges??[],m=r.labels??[],b=r.overlays??null}else if(d){d.computeLayout(f,p,h,[l,u]);const t=d.buildScene(f,p,h,[l,u]);y=t.sceneNodes,g=t.sceneEdges,m=t.labels}const x=O(o);for(const t of m)t.fill||(t.fill=x.text);const v=kl({nodes:g,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"line":return Js("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 o=t;return Js("path",{d:o.pathD,fill:Xs(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},"net-edge-"+e)}case"ribbon":{const o=t;return Js("path",{d:o.pathD,fill:Xs(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},"net-edge-"+e)}case"curved":{const o=t;return Js("path",{d:o.pathD,fill:Xs(o.style.fill,"none"),stroke:o.style.stroke||"#999",strokeWidth:o.style.strokeWidth||1,opacity:o.style.opacity},"net-edge-"+e)}default:return null}}(t,e)}),w=kl({nodes:y,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"circle":{const o=t,n=Kn(o.style.fill)?Jn(o.style.fill,`net-circle-${e}-hatch`):void 0;return ta(Zs.Fragment,{children:[n&&Js("defs",{children:n}),Js("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:Xs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,n=Kn(o.style.fill)?Jn(o.style.fill,`net-rect-${e}-hatch`):void 0;return ta(Zs.Fragment,{children:[n&&Js("defs",{children:n}),Js("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:Xs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,n=Qs().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(qs)||"",i=Kn(o.style.fill)?Jn(o.style.fill,`net-arc-${e}-hatch`):void 0;return ta(Zs.Fragment,{children:[i&&Js("defs",{children:i}),Js("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:Xs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,n=uo(o.symbolType,o.size,o.path);return Js("path",{d:n,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?Xs(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return Vs(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e)});e&&(e.evidence=mg({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),A=w.map(t=>t.element),S=m.map((t,e)=>function(t,e){return Js("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?Fg({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{},layout:{width:l,height:u},theme:o,idPrefix:t._idPrefix}):null,_=Ug({props:t,categories:c,theme:o,size:r,margin:s,hasTitle:a});return $m.renderToStaticMarkup(Zg(Ax(kx,{children:[t.backgroundGraphics,k,A,S,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:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:l,innerHeight:u,legend:_,idPrefix:t._idPrefix}))}import*as Px from"react-dom/server";import{geoPath as Cx}from"d3-geo";import{quadtree as Rx}from"d3-quadtree";import{geoMercator as Ix,geoEqualEarth as Lx,geoAlbersUsa as Tx,geoOrthographic as $x,geoNaturalEarth1 as zx,geoEquirectangular as Dx}from"d3-geo";var Ex={mercator:Ix,equalEarth:Lx,albersUsa:Tx,orthographic:$x,naturalEarth:zx,equirectangular:Dx};function Ox(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Fx(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Bx(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function Nx(t,e){if(2>t.length)return[t];const o=.4*e,n=[];let i=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>i.length||n.push(i),i=[r]):i.push(r)}return 2>i.length||n.push(i),n}function Wx(t,e,o=24){const n=e[0]-t[0],i=e[1]-t[1],r=Math.sqrt(n*n+i*i);if(0===r)return[t,e];const s=-i/r,a=n/r,c=Math.min(.3*r,80),l=(t[0]+e[0])/2+s*c,u=(t[1]+e[1])/2+a*c,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*l+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function jx(t,e){if(2>t.length)return t;const o=e/2+1,n=[];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;n.push([i[0]+s/a*o,i[1]+-r/a*o])}return n}function Yx(t,e,o,n,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 c=s/a,l=-r/a,u=i/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}import{scaleLinear as Gx}from"d3-scale";var qx=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Xx=["scene-style","data-paint","accessibility","evidence"],Hx=(t,e)=>({retainedData:t,invalidations:e}),Vx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ux=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Kx=["scene-geometry","data-paint","accessibility","evidence"],Zx=["scene-style","data-paint","accessibility","evidence"],Qx=["overlay","accessibility","evidence"],Jx=[],tv={xAccessor:Hx("rebuild",Vx),yAccessor:Hx("rebuild",Vx),lineDataAccessor:Hx("rebuild",Vx),pointIdAccessor:Hx("rebuild",Kx),lineIdAccessor:Hx("rebuild",Kx),windowSize:Hx("rebuild",Vx),projection:Hx("preserve",Ux),projectionExtent:Hx("preserve",Ux),fitPadding:Hx("preserve",Ux),lineType:Hx("preserve",Ux),flowStyle:Hx("preserve",Ux),graticule:Hx("preserve",Ux),projectionTransform:Hx("preserve",Ux),customLayout:Hx("preserve",Ux),layoutConfig:Hx("preserve",Ux),layoutMargin:Hx("preserve",Ux),areaStyle:Hx("preserve",Zx),pointStyle:Hx("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Hx("preserve",Zx),colorScheme:Hx("preserve",Zx),themeCategorical:Hx("preserve",Zx),themeDiverging:Hx("preserve",Zx),themeSemantic:Hx("preserve",Zx),themeSequential:Hx("preserve",Zx),decay:Hx("preserve",Zx),pulse:Hx("preserve",Zx),layoutSelection:Hx("preserve",Zx),annotations:Hx("preserve",Qx),autoPlaceAnnotations:Hx("preserve",Qx),clock:Hx("preserve",Jx),transition:Hx("preserve",Jx),introAnimation:Hx("preserve",Jx),onLayoutError:Hx("preserve",Jx)},ev=Hx("preserve",Ux),ov=class{constructor(){this.tracker=new Yo}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}},qx)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Xx):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=tv[n]??ev;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),n=new Set(o.invalidations);return e.retainedDataChanged&&n.add("data"),this.tracker.record({kind:"config",keys:t},n)}};import{geoDistance as nv,geoGraticule as iv,geoInterpolate as rv}from"d3-geo";function sv(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 av=class t{constructor(t){this.updateResults=new ov,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:sv(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??Ie()}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(),o=this.timestampBuffer?.toArray()??[],n=e.slice(-t),i=o.slice(-n.length),r=this.currentTime();this.pointBuffer=new Se(t),this.timestampBuffer=new Se(t),n.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:sv(t.fitPadding)}:t}(t),o=this.config,n=this.getConfiguredWindowSize(),i=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==n;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(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,n=this.timestampBuffer?.toArray()??[],i=o.slice(-e),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new Se(e),this.timestampBuffer=new Se(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();Io(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 o of t)Io(this.pointBuffer,o,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 o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]),i=[];return this.lineData=this.lineData.filter(t=>!n.has(o(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 o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>n.has(o(t)+"");Lo(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=>!n.has(o(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 o of this.scene){const n=this._baseStyles.get(o)??o.style,i=e(o,t);o.style=i?{...n,...i}:n}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,n=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return Lx();if("string"==typeof t){const e=Ex[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),Lx())}if("object"==typeof t&&"type"in t){const e=Ex[t.type],o=e?e():Lx();return t.rotate&&"rotate"in o&&o.rotate(t.rotate),t.center&&"center"in o&&o.center(t.center),o}return t}(e.projection),this.geoPath=Cx(this.projection),this.fitProjection(t),this.geoPath=Cx(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(t,e)=>l([t,e]),invertedPoint:(t,e)=>l.invert?l.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=n,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,o=t.height/2,n=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));n.length>0&&this.startTransition(n)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=Ox(o.xAccessor,"lon"),r=Ox(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Fx(o.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)]);n.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==n.length){if(o.projectionExtent){const[[n,i],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n,i],[n,s],[r,s],[r,i],[n,i]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const n=o.fitPadding??0,i=Math.min(t.width,t.height);e.scale(i/2-i*n),e.translate([t.width/2,t.height/2])}else{const i=o.fitPadding??0,r=t.width*i,s=t.height*i;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:n})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t.k),o.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=Cx(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t),o.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=Cx(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const n=this.geoPath,i=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=Cx(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=n,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,o=0;for(const t of this.scene)"point"===t.type&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const n=Array(o);let i=0;for(const t of this.scene)"point"===t.type&&(n[i++]=t);this._quadtree=Rx().x(t=>t.x).y(t=>t.y).addAll(n)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,n=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Wp(e.colorScheme,e.themeCategorical,St),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:o,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...n]},resolveColor:jp(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(i)}catch(t){const o=null!==this.lastCustomLayoutResult,n=xo("geo",t,o,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return o?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 go({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:o,areas:n,points:i,lines:r,layout:s}){const a=Ox(t.xAccessor,"lon"),c=Ox(t.yAccessor,"lat"),l=[],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,n=iv();e.step&&n.step(e.step);const i=o(n())||"";i&&l.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 n){const n=o(e);if(!n)continue;const i=o.centroid(e),r=o.bounds(e),s=o.area(e);l.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:Bx(t.areaStyle,e,u),datum:e,interactive:!0})}const f=Fx(t.lineDataAccessor);for(const o of r){const n=f(o);if(!n||2>n.length)continue;let i=[];if("geo"===t.lineType){const t=Array(n.length);for(let e=0;n.length>e;e++)t[e]=[a(n[e]),c(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=nv(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=rv(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(c(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),c(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Bx(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==n.length||2>i.length||"arc"!==t.flowStyle?2!==n.length||2>i.length||"offset"!==t.flowStyle||(i="geo"===t.lineType?jx(i,u):Yx(i[0],i[i.length-1],0,0,u)):i=Wx(i[0],i[i.length-1]);const h=Nx(i,s.width);if(h.length>1)for(const t of h)2>t.length||l.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,y=e.clipAngle?e.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],b="function"==typeof e.center?e.center():[0,0],x=[(b[0]??0)-m[0],(b[1]??0)-m[1]];for(const o of i){const n=a(o),i=c(o);if(null!=g&&nv([n,i],x)>g)continue;const r=e([n,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:p?p(o)+"":void 0};l.push(u)}return l}({config:e,projection:o,path:n,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,n){const i=t.filter(t=>"point"===t.type);if(2>i.length)return null;const r=e.strength??1,s="strip"===e.layout?"strip":"radial";if("radial"===s&&0===r)return null;const a=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],l=i.find(t=>t.datum&&a(t.datum)+""==e.center+"");if(!l)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const u=i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),d=A(u,1);n>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 o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const h="strip"===s?function(t,e,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,c=Gx().domain([0,n]).range([0,s]);e.x=r,e.y=a;const l=[];for(const n of t){if(n===e)continue;if(!n.datum){n.x=r,n.y=a;continue}const t=Number(o(n.datum)),i=r+(isFinite(t)&&t>=0?c(t):0);n.x=i,n.y=a,l.push({node:n,x:i})}l.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;l.length>d;){let t=d+1;for(;l.length>t&&3>Math.abs(l[t].x-l[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)l[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:n,availableRadius:s,layout:"strip"}}(i,l,c,d,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,c=Math.min(r.width,r.height)/2,l=Gx().domain([0,n]).range([0,c]);for(const n of t){if(n===e)continue;if(!n.datum)continue;const t=Math.atan2(n.y-a,n.x-s),r=Math.sqrt((n.x-s)**2+(n.y-a)**2),c=Number(o(n.datum)),u=r+((isFinite(c)?l(c):r)-r)*i;n.x=s+Math.cos(t)*u,n.y=a+Math.sin(t)*u}const u=r.width/2,d=r.height/2,h=u-e.x,f=d-e.y;if(Math.abs(h)>.5||Math.abs(f)>.5)for(const e of t)e.x+=h,e.y+=f;return{cx:u,cy:d,maxCost:n,availableRadius:c,layout:"radial"}}(i,l,c,d,r,o),f=t.filter(t=>"line"===t.type);if(f.length>0&&"fractional"!==e.lineMode){const t=new Map;for(const e of i)e.pointId&&t.set(e.pointId,[e.x,e.y]);for(const e of f){const o=e.datum?.source,n=e.datum?.target;if(o&&n){const i=t.get(o+""),r=t.get(n+"");i&&r&&(e.path=[i,r])}}}return h}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let n=0;o.length>n;n++){const i=Le(t,n,e);o[n]._decayOpacity=i,o[n].style={...o[n].style,opacity:i}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),n=this.timestampBuffer.toArray(),i=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&n.length>a;a++){const c=$e(e,n[a],t);s=ze(o[a],c,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&De(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 o=new Map;for(const e of t)"point"===e.type&&e.pointId&&o.set(e.pointId,[e.x,e.y]);const n=this.scene.filter(t=>"point"===t.type);let i=!1;for(const t of n)if(t.pointId){const e=o.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 n)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(t){if(!this.activeTransition)return!1;const e=Ce(t,this.activeTransition),o=Pe(e),n=this.scene.filter(t=>"point"===t.type);for(const t of n){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=Re(t.x,t._targetX,o),t.y=Re(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of n)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}};av.QUADTREE_THRESHOLD=500;var cv=av;Bo(cv);import{Fragment as lv,jsxs as uv}from"react/jsx-runtime";function dv(t,e){const o=E(t.theme),n=t.size||[t.width||600,t.height||400],i=Is({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Cs(t.title),s=Array.isArray(t.areas)?H(t.areas):t.areas,a=H(t.points),c=H(t.lines),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return Ig(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Vg(i,{props:t,categories:l,theme:o,size:n,hasTitle:r});const u=n[0]-(i.left??0)-(i.right??0),d=n[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:o.colors.categorical,themeSemantic:_(o)},f=new cv(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(c),f.computeScene({width:u,height:d});const p=kl({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=Kn(o.style.fill)?Jn(o.style.fill,`geoarea-${e}-hatch`):void 0;return na(ea.Fragment,{children:[n&&oa("defs",{children:n}),oa("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:Xs(o.style.fill,"#e0e0e0"),fillOpacity:o.style.fillOpacity??1,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth||.5,strokeDasharray:o.style.strokeDasharray,opacity:o._decayOpacity??1})]},"geoarea-"+e)}case"point":{const o=t,n=Kn(o.style.fill)?Jn(o.style.fill,`geopoint-${e}-hatch`):void 0;return na(ea.Fragment,{children:[n&&oa("defs",{children:n}),oa("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:Xs(o.style.fill),fillOpacity:o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o._decayOpacity??o.style.opacity??1})]},"point-"+e)}case"line":{const o=t;if(2>o.path.length)return null;const n="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return oa("path",{d:n,fill:"none",stroke:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth||1.5,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity??1},"line-"+e)}case"glyph":return Vs(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e)});if(e&&(e.evidence=mg({frameType:"geo",width:n[0],height:n[1],marks:p.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,legendItems:l.length>0?l.length:void 0,margin:i})),0===p.length){const e=t.backgroundGraphics||t.foregroundGraphics||t.annotations||f.customLayoutOverlays?uv(lv,{children:[t.backgroundGraphics,t.annotations?Fg({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:o,idPrefix:t._idPrefix}):null,t.foregroundGraphics,f.customLayoutOverlays]}):null;return Px.renderToStaticMarkup(Zg(e,{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,idPrefix:t._idPrefix}))}const y=p.map(t=>t.element),g=t.annotations?Fg({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:o,idPrefix:t._idPrefix}):null,m=Ug({props:t,categories:l,theme:o,size:n,margin:i,hasTitle:r});return Px.renderToStaticMarkup(Zg(uv(lv,{children:[t.backgroundGraphics,y,g,t.foregroundGraphics,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,legend:m,idPrefix:t._idPrefix}))}import*as hv from"react-dom/server";function fv(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 pv={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function yv(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 gv(t,e){const o="function"==typeof e?e(t):e;return{...pv,...o??{}}}function mv(t,e={}){return t.map(t=>function(t,e={}){const o=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),n={label:e.getBodyLabel?.(t)??yv(t)},i={style:gv(t,e.bodyStyle),datum:o,accessibleDatum:o,accessibility:n,_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 bv,jsxs as xv}from"react/jsx-runtime";var vv={top:0,right:0,bottom:0,left:0};function wv(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function kv(t,e){const o=t.size??[t.width??600,t.height??400],n=new Sp(t.config);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&n.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const i=function(t,e={}){const{width:o=640,height:n=360,title:i,description:r,background:s,backgroundGraphics:a,className:c,foregroundGraphics:l,idPrefix:u="physics",margin:d,renderBodySVG:h,...f}=e,p=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=mv(n,e),s=function(t,e={}){const o=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),n=o.filter(t=>t.sleeping).length;return{bodyCount:o.length,sleepingCount:n,settled:"settled"===t.simulationState&&0===t.queue.length&&n===o.length,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:fv(e.projectionRows)}}(i,{bodies:n,projectionRows:e.projectionRows,stepsRun:o});return{snapshot:i,bodies:n,sceneNodes:r,evidence:s,stepsRun:o}}(t,f),y={...vv,...d},g=[o,n],m=wv(a,g,y),b=wv(l,g,y),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:hv.renderToStaticMarkup(xv("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":k,children:[i&&bv("title",{id:v,children:i}),r&&bv("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?bv("rect",{x:0,y:0,width:o,height:n,fill:s}):null,m,bv("g",{id:x+"-data-area",children:p.sceneNodes.map((t,e)=>{const o=p.bodies[e];return(o&&h?h(o,t.style??{},e,x):void 0)??ga(t,e,x)})}),b]})),scene:p,evidence:p.evidence}}(n,{...t,width:o[0],height:o[1],idPrefix:t.idPrefix??t._idPrefix??"physics"});return e&&(e.evidence=mg({frameType:"physics",width:o[0],height:o[1],marks:i.scene.sceneNodes,title:t.title,description:t.description,annotations:[],extraWarnings:0===i.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[]})),i.svg}import{Fragment as Av,jsx as Sv,jsxs as Mv}from"react/jsx-runtime";function _v(t,e){switch(t){case"xy":return em(e);case"ordinal":return Tm(e);case"network":return _x(e);case"geo":return dv(e);case"physics":return kv(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Pv(t){return em(t)}function Cv(t){return Tm(t)}function Rv(t){return _x(t)}function Iv(t){return dv(t)}var Lv=["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"],Tv=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function $v(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function zv(t,e,o){return Ev(t,e).svg}function Dv(t,e,o){const n={},{svg:i,frameType:r}=Ev(t,e,0,n),s=n.evidence??mg({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 Ev(t,e,o,n){const i=pg[t];if(!i)throw Error(`Unknown chart component: "${t}". See CLAUDE.md for supported chart types.`);var r;const s=W(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(N,r)?e.mode:void 0),{...i.layout?.modeDefaults,...$v(e,Tv)},i.layout?.primarySize),{data:a,theme:c,background:l,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:y,...g}=e,{width:m,height:b}=s,x=[m,b],v=g.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,A=void 0!==h?h:v.margin,S=function(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}(A),M="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...k,...S},_=$v(g,Lv),P=t=>v[t]??s[t],C={...v,..._,theme:c,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:l,className:u,annotations:d,size:x,margin:M,__explicitMargin:A,__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==y&&{legendPosition:y},_idPrefix:g._idPrefix},R=i.buildProps(a,p,f,C,g);let I;switch(i.frameType){case"xy":I=em(R,n);break;case"ordinal":I=Tm(R,n);break;case"network":I=_x(R,n);break;case"geo":I=dv(R,n);break;case"physics":I=kv(R,n)}const L=i.renderOverlay?.(R,{theme:E(c)});if(null!=L){const t=Y.renderToStaticMarkup(Sv(Av,{children:L}));I=I.replace("</svg>",t+"</svg>")}return{svg:I,frameType:i.frameType}}async function Ov(t,e,o={}){const{format:n="png",scale:i=1,background:r}=o;let s,a;s=["xy","ordinal","network","geo","physics"].includes(t)?_v(t,e):zv(t,e),r&&(s=s.replace(/<svg /,`<svg style="background:${r}" `));try{const t="sharp",e=await import(t);a=e.default??e}catch{throw Error('Image export requires the "sharp" package and a Node.js runtime. Install it:\n npm install sharp\nsharp is listed as an optional dependency of semiotic.')}const c=e.width||e.size?.[0]||600,l=e.height||e.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*i}).resize(Math.round(c*i),Math.round(l*i));return"jpeg"===n?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function Fv(t,e={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:c}=e,l=O(E(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const f=Math.floor((r-d-d*(u-1))/u),p=[];let y=0,g=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;y+t>u&&(g+=m+d,y=0,m=0),p.push({chart:e,x:d/2+y*(f+d),y:g,w:f*t+d*(t-1),h:o}),m=Math.max(m,o),y+=t}const b=s||g+m+d,x=p.map((t,e)=>{const{chart:o,x:n,y:r,w:s,h:a}=t,c={...o.props,width:s,height:a,theme:i,_idPrefix:"chart-"+e};let l;return l=o.component?zv(o.component,c):o.frameType?_v(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Sv("g",{transform:`translate(${n},${r})`,children:Sv("foreignObject",{width:s,height:a,children:Sv("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+e)});return Y.renderToStaticMarkup(Mv("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&Sv("title",{children:o}),c&&Sv("rect",{x:0,y:0,width:r,height:b,fill:c}),o&&Sv("text",{x:r/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:o}),n&&Sv("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:n}),x]}))}import*as Bv from"react-dom/server";import{Fragment as Nv,jsx as Wv,jsxs as jv}from"react/jsx-runtime";function Yv(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:d="ease-out",decay:h}=n,f=o.width||600,p=o.height||400,y=E(o.theme),g={...o,...a&&{xExtent:a},...c&&{yExtent:c}};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=Is({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=f-v.left-v.right,k=p-v.top-v.bottom,A=[];if(x)for(let n=0;b.length>n;n++){const i=b[n],s=e.slice(r?Math.max(0,i-r):0,i),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||y.colors.categorical,...h&&{decay:h}},c=new _m(a);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:w,height:k}),c.scene.length>0&&A.push(Uv(c.scene,f,p,y,g))}else for(let n=0;b.length>n;n++){const i=b[n],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:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:o.colorScheme||y.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...l>0&&{transition:{duration:l*(1e3/u),easing:d}}},x=new an(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(A.push(Vv(x.scene,f,p,y,g,v)),l>0&&n>0&&x.activeTransition){const t=l*(1e3/u);for(let e=1;l>=e;e++)x.advanceTransition(x.activeTransition.startTime+e/l*t),A.push(Vv(x.scene,f,p,y,g,v))}}return A}function Gv(t,e,o={}){return e.map(e=>{try{return zv(t,{...o,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||e.width||600}" height="${o.height||e.height||400}"></svg>`}})}function qv(t,e,o){const n=e.size??[e.width??600,e.height??400],i=E(e.theme),r=O(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",c=e.title?`${a}-title-${o}`:void 0,l=e.description?`${a}-desc-${o}`:void 0,u=[c,l].filter(Boolean).join(" ")||void 0,d=mv(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=jv("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&Wv("title",{id:c,children:e.title}),e.description&&Wv("desc",{id:l,children:e.description}),s&&"transparent"!==s?Wv("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,Wv("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>ga(t,e,`${a}-${o}`))})]});return Bv.renderToStaticMarkup(h)}function Xv(t,e={}){const{fps:o=12,frameCount:n,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:c}=e,l=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=n??Math.max(1,Math.ceil(i*Math.max(1,o))),h=c?{...t,background:c}:t,f=new Sp(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(qv(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(l);p.push(qv(f,h,p.length))}return p}function Hv(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function Vv(t,e,o,n,i,r){const s=O(n),a=Is({top:20,right:20,bottom:30,left:40,...i.margin},i.title),c=e-a.left-a.right,l=o-a.top-a.bottom,u=Hv(i,n),d=i.renderMode,h=t.map((t,e)=>wl({node:t,index:e,renderMode:d,fallback:()=>ga(t,e)})).filter(Boolean),f=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=O(n),a=[];for(let n=0;t.length>n;n++){const c=t[n];if("y-threshold"===c.type&&null!=c.value){let t=null;if(r)t=r(c.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(c.value-e)/r*o}if(null==t)continue;const l=c.color||s.primary,u=c.labelPosition||"right";a.push(jv("g",{children:[Wv("line",{x1:0,y1:t,x2:e,y2:t,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&Wv("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(o-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:l,fontFamily:s.fontFamily,children:c.label})]},"ann-"+n))}}return a.length>0?Wv(Nv,{children:a}):null}(i.annotations,c,l,n,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,y="string"==typeof i.description?i.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,b=[g,m].filter(Boolean).join(" ")||void 0;return Bv.renderToStaticMarkup(jv("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":b,style:{fontFamily:s.fontFamily},children:[p&&Wv("title",{id:g,children:p}),y&&Wv("desc",{id:m,children:y}),u&&Wv("rect",{x:0,y:0,width:e,height:o,fill:u}),jv("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&Wv("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}function Uv(t,e,o,n,i){const r=O(n),s=Is({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,c=a?s.left+(e-s.left-s.right)/2:s.left,l=a?s.top+(o-s.top-s.bottom)/2:s.top,u=Hv(i,n),d=i.renderMode,h=t.map((t,e)=>wl({node:t,index:e,renderMode:d,fallback:()=>ha(t,e)})).filter(Boolean),f="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,y=f?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,m=[y,g].filter(Boolean).join(" ")||void 0;return Bv.renderToStaticMarkup(jv("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[f&&Wv("title",{id:y,children:f}),p&&Wv("desc",{id:g,children:p}),u&&Wv("rect",{x:0,y:0,width:e,height:o,fill:u}),Wv("g",{transform:`translate(${c},${l})`,children:h}),f&&Wv("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:f})]}))}async function Kv(t,e,o,n={}){const{fps:i=12,loop:r=!0,scale:s=1,background:a}=n,c=o.width||600,l=o.height||400,u=Yv(t,e,a?{...o,background:a}:o,n);if(0===u.length)throw Error("No frames generated — check that data is not empty");return Qv(u,c,l,{fps:i,loop:r,scale:s})}async function Zv(t,e={}){const{fps:o=12,loop:n=!0,scale:i=1}=e,r=t.size??[t.width??600,t.height??400],s=Xv(t,e);if(0===s.length)throw Error("No physics frames generated");return Qv(s,r[0],r[1],{fps:o,loop:n,scale:i})}async function Qv(t,e,o,n={}){const{fps:i=12,loop:r=!0,scale:s=1}=n,a=Math.round(e*s),c=Math.round(o*s);let l,u,d,h;try{const t="sharp",e=await import(t);l=e.default??e}catch{throw Error('Animated GIF export requires "sharp". Install it:\n npm install sharp')}try{const t="gifenc",e=await import(t),o=[e,e.default].find(t=>"function"==typeof t?.GIFEncoder&&"function"==typeof t.quantize&&"function"==typeof t.applyPalette);if(!o)throw Error("gifenc did not expose its encoder functions");u=o.GIFEncoder,d=o.quantize,h=o.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 o=t[e],n=await l(Buffer.from(o),{density:72*s}).resize(a,c).ensureAlpha().raw().toBuffer(),i=new Uint8Array(n),u=d(i,256),y=h(i,u);p.writeFrame(y,a,c,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}export{E as resolveTheme,O as themeStyles,_v as renderToStaticSVG,Pv as renderXYToStaticSVG,Cv as renderOrdinalToStaticSVG,Rv as renderNetworkToStaticSVG,Iv as renderGeoToStaticSVG,zv as renderChart,Dv as renderChartWithEvidence,Ov as renderToImage,Fv as renderDashboard,Yv as generateFrameSVGs,Gv as generateFrameSequence,Xv as generatePhysicsFrameSVGs,Kv as renderToAnimatedGif,Zv as renderPhysicsToAnimatedGif};
|