semiotic 3.8.9 → 3.9.0
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/README.md +83 -67
- package/agent-skill/semiotic-charts/SKILL.md +11 -2
- package/ai/behaviorContracts.cjs +33 -3
- package/ai/cli.js +53 -2
- package/ai/componentMetadata.cjs +15 -0
- package/ai/dist/mcp-server.js +1530 -611
- package/ai/examples.md +48 -42
- package/{CLAUDE.md → ai/reference.md} +43 -22
- package/ai/schema.json +10603 -986
- package/ai/surface-manifest.json +643 -2
- package/ai/system-prompt.md +83 -130
- package/dist/c-3BLJEQNG.min.js +1 -0
- package/dist/c-3KZD6AXJ.min.js +1 -0
- package/dist/c-4TWEX5HG.min.js +1 -0
- package/dist/c-52TEGIUJ.min.js +1 -0
- package/dist/c-5YCIX3VZ.min.js +1 -0
- package/dist/c-6FEKTA3U.min.js +1 -0
- package/dist/c-6O5EVOPH.min.js +1 -0
- package/dist/c-74HEEZGK.min.js +1 -0
- package/dist/c-AKAF6JAD.min.js +1 -0
- package/dist/c-BBKITSXB.min.js +1 -0
- package/dist/c-BWNB6USU.min.js +1 -0
- package/dist/c-C25ENHIK.min.js +1 -0
- package/dist/c-CDR5AO3R.min.js +1 -0
- package/dist/c-COHXCW3Q.min.js +1 -0
- package/dist/{chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js → c-DADXPJXV.min.js} +0 -1
- package/dist/c-E3JFRRMI.min.js +1 -0
- package/dist/c-EBFPQHHO.min.js +1 -0
- package/dist/c-G36WS6LN.min.js +1 -0
- package/dist/c-GIKRQI4X.min.js +1 -0
- package/dist/c-GPYOFETM.min.js +1 -0
- package/dist/c-IDUHYYSI.min.js +1 -0
- package/dist/{chunk-chunk-FQPKOAIH.module.min.js → c-IUHFPMHD.min.js} +0 -1
- package/dist/c-J5G56TUH.min.js +1 -0
- package/dist/c-JAZ73J32.min.js +1 -0
- package/dist/c-KG3NXHAL.min.js +1 -0
- package/dist/c-KII3PLZE.min.js +1 -0
- package/dist/c-LIXGXMNS.min.js +1 -0
- package/dist/c-LVEY6D6B.min.js +1 -0
- package/dist/c-M4Y3BHFR.min.js +1 -0
- package/dist/c-MAIICR2Z.min.js +1 -0
- package/dist/c-MG5DM6VE.min.js +1 -0
- package/dist/{chunk-minimapBrushOverlay-JU57U7NM.module.min.js → c-MNF2S4AA.min.js} +0 -1
- package/dist/c-MT3WBK7M.min.js +1 -0
- package/dist/c-NY3JWV2K.min.js +1 -0
- package/dist/c-O6U6K4CW.min.js +1 -0
- package/dist/c-OCI56QF2.min.js +1 -0
- package/dist/c-OQ7M4AGV.min.js +1 -0
- package/dist/c-OXYMVK7Q.min.js +1 -0
- package/dist/c-PPWDL5ZI.min.js +1 -0
- package/dist/c-QHF5YON3.min.js +1 -0
- package/dist/c-RR3GO5SW.min.js +1 -0
- package/dist/{chunk-chunk-J5QD4RAM.module.min.js → c-RSVIHIQ4.min.js} +0 -1
- package/dist/{chunk-chunk-EMO5NUGE.module.min.js → c-S2BXNNJN.min.js} +0 -1
- package/dist/{chunk-chunk-YCQYG6J5.module.min.js → c-SLGMUBUL.min.js} +0 -1
- package/dist/c-SUILCHWU.min.js +1 -0
- package/dist/c-TZW3JGJ5.min.js +1 -0
- package/dist/c-US5ZFT6E.min.js +1 -0
- package/dist/{chunk-chunk-RZH7VZYS.module.min.js → c-USFMFKIH.min.js} +0 -1
- package/dist/c-UUKVD4WB.min.js +1 -0
- package/dist/{chunk-chunk-SV4XAZ3Q.module.min.js → c-VGW3VG3I.min.js} +0 -1
- package/dist/c-W3CE4A4S.min.js +1 -0
- package/dist/{chunk-chunk-2NVFEB7P.module.min.js → c-WJCD5EUY.min.js} +0 -1
- package/dist/{chunk-chunk-2JGJ5GUG.module.min.js → c-X5UBGU2V.min.js} +0 -1
- package/dist/c-YDAY2WFR.min.js +1 -0
- package/dist/c-ZOWWU34K.min.js +1 -0
- package/dist/components/AccessibleNavTree.d.ts +1 -1
- package/dist/components/CategoryColors.d.ts +1 -1
- package/dist/components/GradientLegend.d.ts +14 -0
- package/dist/components/Legend.d.ts +2 -7
- package/dist/components/LinkedCharts.d.ts +1 -1
- package/dist/components/MobileAnnotationCalloutList.d.ts +1 -1
- package/dist/components/ObservationReadout.d.ts +45 -0
- package/dist/components/ThemeProvider.d.ts +4 -4
- package/dist/components/Tooltip/FlippingTooltip.d.ts +5 -7
- package/dist/components/Tooltip/Tooltip.d.ts +30 -5
- package/dist/components/Tooltip/tooltipChrome.d.ts +43 -0
- package/dist/components/ai/chartCapabilityTypes.d.ts +86 -2
- package/dist/components/ai/chartClinic.d.ts +2 -0
- package/dist/components/ai/deriveProfileFields.d.ts +40 -0
- package/dist/components/ai/evaluateChart.d.ts +85 -0
- package/dist/components/ai/fieldPolicy.d.ts +7 -0
- package/dist/components/ai/fieldRoles.d.ts +24 -0
- package/dist/components/ai/generativeChart.d.ts +18 -2
- package/dist/components/ai/inferIntent.d.ts +26 -2
- package/dist/components/ai/intents.d.ts +35 -0
- package/dist/components/ai/navigationTree.d.ts +2 -2
- package/dist/components/ai/observedSceneAudit.d.ts +2 -1
- package/dist/components/ai/profileData.d.ts +11 -0
- package/dist/components/ai/repairChartConfig.d.ts +2 -3
- package/dist/components/ai/semanticEvidence.d.ts +4 -0
- package/dist/components/ai/semanticViability.d.ts +11 -0
- package/dist/components/ai/semanticViabilityRegistry.d.ts +5 -0
- package/dist/components/ai/streamingTypes.d.ts +4 -0
- package/dist/components/ai/suggestCharts.d.ts +5 -6
- package/dist/components/ai/suggestDashboard.d.ts +2 -3
- package/dist/components/ai/suggestStreamCharts.d.ts +1 -1
- package/dist/components/ai/suggestStretchCharts.d.ts +2 -3
- package/dist/components/ai/suggestionPropContracts.d.ts +20 -0
- package/dist/components/ai/variantDiscovery.d.ts +3 -1
- package/dist/components/charts/custom/NetworkCustomChart.d.ts +3 -0
- package/dist/components/charts/custom/OrdinalCustomChart.d.ts +3 -0
- package/dist/components/charts/custom/XYCustomChart.d.ts +1 -1
- package/dist/components/charts/geo/ChoroplethMap.d.ts +3 -1
- package/dist/components/charts/geo/DistanceCartogram.d.ts +2 -7
- package/dist/components/charts/geo/cartogramOverlay.d.ts +28 -0
- package/dist/components/charts/index.d.ts +4 -3
- package/dist/components/charts/network/ProcessSankey.d.ts +2 -136
- package/dist/components/charts/network/ProcessSankeyProps.d.ts +139 -0
- package/dist/components/charts/network/Treemap.d.ts +2 -1
- package/dist/components/charts/network/processSankey/boundaryHubOrdering.d.ts +23 -0
- package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +2 -0
- package/dist/components/charts/network/processSankey/ordering.d.ts +3 -41
- package/dist/components/charts/network/processSankey/orderingTypes.d.ts +32 -0
- package/dist/components/charts/network/processSankey/packing.d.ts +1 -1
- package/dist/components/charts/network/processSankey/packingCache.d.ts +1 -1
- package/dist/components/charts/network/processSankey/packingOptimization.d.ts +72 -0
- package/dist/components/charts/ordinal/BarChart.d.ts +4 -3
- package/dist/components/charts/ordinal/FunnelChart.d.ts +2 -0
- package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -2
- package/dist/components/charts/ordinal/StackedBarChart.d.ts +4 -3
- package/dist/components/charts/ordinal/SwimlaneChart.d.ts +2 -2
- package/dist/components/charts/physics/GaltonBoardChart.d.ts +2 -9
- package/dist/components/charts/physics/GauntletChart.d.ts +10 -41
- package/dist/components/charts/physics/ProcessFlowChart.d.ts +1 -1
- package/dist/components/charts/physics/chainReactionAccessibleTable.d.ts +9 -0
- package/dist/components/charts/physics/chainReactionRuntime.d.ts +2 -1
- package/dist/components/charts/physics/chainReactionTypes.d.ts +5 -1
- package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +2 -2
- package/dist/components/charts/physics/crucibleClone.d.ts +6 -0
- package/dist/components/charts/physics/crucibleEffects.d.ts +1 -2
- package/dist/components/charts/physics/crucibleRecord.d.ts +7 -0
- package/dist/components/charts/physics/gauntletChrome.d.ts +4 -4
- package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
- package/dist/components/charts/physics/gauntletPublic.d.ts +4 -0
- package/dist/components/charts/physics/packetFlowOverlay.d.ts +7 -0
- package/dist/components/charts/physics/physicsChartLayout.d.ts +8 -0
- package/dist/components/charts/physics/physicsChartShared.d.ts +3 -1
- package/dist/components/charts/physics/physicsChartUtils.d.ts +1 -1
- package/dist/components/charts/physics/physicsHocUtils.d.ts +25 -12
- package/dist/components/charts/physics/physicsProjectionOverlays.d.ts +24 -0
- package/dist/components/charts/physics/processFlowOverlays.d.ts +9 -0
- package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +15 -12
- package/dist/components/charts/realtime/RealtimeHistogram.d.ts +10 -7
- package/dist/components/charts/realtime/RealtimeLineChart.d.ts +35 -14
- package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +21 -14
- package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +20 -13
- package/dist/components/charts/realtime/aggregate.d.ts +4 -1
- package/dist/components/charts/realtime/eventTime.d.ts +4 -0
- package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +27 -0
- package/dist/components/charts/realtime/realtimeChartTypes.d.ts +30 -0
- package/dist/components/charts/realtime/useRealtimeCategoryColors.d.ts +30 -0
- package/dist/components/charts/shared/FrameTextAnnotationSVG.d.ts +10 -0
- package/dist/components/charts/shared/annotationActivation.d.ts +3 -7
- package/dist/components/charts/shared/annotationBandFill.d.ts +6 -0
- package/dist/components/charts/shared/annotationDispatch.d.ts +31 -0
- package/dist/components/charts/shared/annotationIdentity.d.ts +8 -0
- package/dist/components/charts/shared/annotationRules.d.ts +1 -15
- package/dist/components/charts/shared/boundedCategoryRegistry.d.ts +8 -0
- package/dist/components/charts/shared/chainReactionChartSpec.d.ts +3 -0
- package/dist/components/charts/shared/chartMode.d.ts +3 -2
- package/dist/components/charts/shared/chartSpecCore.d.ts +1 -0
- package/dist/components/charts/shared/frameTextAnnotation.d.ts +63 -0
- package/dist/components/charts/shared/gradient.d.ts +16 -0
- package/dist/components/charts/shared/hatchFill.d.ts +15 -0
- package/dist/components/charts/shared/hooks.d.ts +4 -4
- package/dist/components/charts/shared/legendUtils.d.ts +1 -0
- package/dist/components/charts/shared/streamPropsHelpers.d.ts +2 -1
- package/dist/components/charts/shared/styleRules.d.ts +9 -2
- package/dist/components/charts/shared/styleRulesWireSchema.d.ts +353 -0
- package/dist/components/charts/shared/types.d.ts +18 -9
- package/dist/components/charts/shared/useChartLegend.d.ts +43 -9
- package/dist/components/charts/shared/useChartSetup.d.ts +3 -1
- package/dist/components/charts/shared/useCustomChartSetup.d.ts +5 -2
- package/dist/components/charts/shared/useNetworkChartSetup.d.ts +5 -1
- package/dist/components/charts/shared/useOrdinalBrush.d.ts +3 -3
- package/dist/components/charts/shared/useStreamingLegend.d.ts +6 -1
- package/dist/components/charts/value/types.d.ts +1 -1
- package/dist/components/charts/xy/BubbleChart.d.ts +1 -1
- package/dist/components/charts/xy/BumpChart.capability.d.ts +14 -1
- package/dist/components/charts/xy/BumpChart.d.ts +13 -73
- package/dist/components/charts/xy/BumpChart.semanticViability.d.ts +5 -0
- package/dist/components/charts/xy/CandlestickChart.d.ts +2 -2
- package/dist/components/charts/xy/LineChart.d.ts +2 -2
- package/dist/components/charts/xy/Scatterplot.d.ts +1 -1
- package/dist/components/charts/xy/bumpData.d.ts +44 -0
- package/dist/components/charts/xy/bumpIdentity.d.ts +2 -0
- package/dist/components/charts/xy/bumpLayout.d.ts +45 -0
- package/dist/components/charts/xy/bumpTooltip.d.ts +20 -0
- package/dist/components/legendLayout.d.ts +131 -4
- package/dist/components/realtime/ReorderBuffer.d.ts +2 -0
- package/dist/components/realtime/types.d.ts +10 -1
- package/dist/components/recipes/balanceSnapshotsToFlows.d.ts +42 -0
- package/dist/components/recipes/directedReachability.d.ts +14 -0
- package/dist/components/recipes/gofishDisplayListFixtures.generated.d.ts +6 -6
- package/dist/components/recipes/gridObservatory.d.ts +1 -1
- package/dist/components/recipes/networkAnalysis.d.ts +1 -18
- package/dist/components/recipes/physics.d.ts +7 -4
- package/dist/components/recipes/processPhysics.d.ts +0 -1
- package/dist/components/recipes/waffle.d.ts +7 -4
- package/dist/components/semiotic-ai-core.d.ts +13 -4
- package/dist/components/semiotic-ai-observations.d.ts +3 -0
- package/dist/components/semiotic-ai.d.ts +16 -9
- package/dist/components/semiotic-client-shared.d.ts +10 -0
- package/dist/components/semiotic-experimental.d.ts +1 -1
- package/dist/components/semiotic-geo.d.ts +4 -1
- package/dist/components/semiotic-network.d.ts +7 -4
- package/dist/components/semiotic-ordinal.d.ts +4 -1
- package/dist/components/semiotic-physics.d.ts +11 -4
- package/dist/components/semiotic-realtime-core.d.ts +11 -4
- package/dist/components/semiotic-realtime-react.d.ts +4 -3
- package/dist/components/semiotic-realtime.d.ts +3 -1
- package/dist/components/semiotic-recipes-core.d.ts +7 -5
- package/dist/components/semiotic-server-edge.d.ts +3 -2
- package/dist/components/semiotic-server.d.ts +3 -2
- package/dist/components/semiotic-themes-core.d.ts +5 -48
- package/dist/components/semiotic-utils-core.d.ts +10 -5
- package/dist/components/semiotic-utils-react.d.ts +2 -0
- package/dist/components/semiotic-xy.d.ts +4 -1
- package/dist/components/semiotic.d.ts +68 -26
- package/dist/components/server/animatedGif.d.ts +1 -1
- package/dist/components/server/renderEvidence.d.ts +25 -2
- package/dist/components/server/renderToStaticSVG.d.ts +15 -7
- package/dist/components/server/serverChartConfigShared.d.ts +8 -1
- package/dist/components/server/serverChartConfigs.d.ts +1 -0
- package/dist/components/server/serverChartConfigsNetwork.d.ts +3 -3
- package/dist/components/server/serverChartConfigsNetworkChord.d.ts +2 -0
- package/dist/components/server/serverChartConfigsNetworkForce.d.ts +2 -0
- package/dist/components/server/serverChartConfigsNetworkHierarchy.d.ts +3 -0
- package/dist/components/server/serverChartConfigsXY.d.ts +3 -3
- package/dist/components/server/serverChartConfigsXYBubble.d.ts +5 -0
- package/dist/components/server/serverChartConfigsXYBump.d.ts +7 -0
- package/dist/components/server/serverChartConfigsXYScatter.d.ts +5 -0
- package/dist/components/server/staticAnnotationFallbacks.d.ts +10 -0
- package/dist/components/server/staticAnnotations.d.ts +28 -1
- package/dist/components/server/staticAxisTickLabel.d.ts +13 -0
- package/dist/components/server/staticLegend.d.ts +1 -1
- package/dist/components/server/staticLegendMargin.d.ts +41 -0
- package/dist/components/server/staticOrdinal.d.ts +8 -2
- package/dist/components/server/staticPhysics.d.ts +13 -1
- package/dist/components/server/staticPhysicsChrome.d.ts +20 -0
- package/dist/components/server/staticRawLegend.d.ts +15 -0
- package/dist/components/server/staticSVGChrome.d.ts +16 -55
- package/dist/components/server/staticXYAxes.d.ts +27 -0
- package/dist/components/server/staticXYAxisTicks.d.ts +39 -0
- package/dist/components/server/staticXYGrid.d.ts +11 -0
- package/dist/components/server/themeResolver.d.ts +5 -1
- package/dist/components/store/ThemeStore.d.ts +2 -98
- package/dist/components/store/designTokens.d.ts +1 -1
- package/dist/components/store/themeCSSVariables.d.ts +10 -0
- package/dist/components/store/themeCore.d.ts +91 -0
- package/dist/components/store/themePresets.d.ts +81 -0
- package/dist/components/store/themeSerialization.d.ts +2 -1
- package/dist/components/stream/AccessibleDataTable.d.ts +12 -14
- package/dist/components/stream/AccessibleTablePortalImpl.d.ts +6 -0
- package/dist/components/stream/GeoTileRenderer.d.ts +2 -0
- package/dist/components/stream/NetworkCanvasHitTester.d.ts +3 -1
- package/dist/components/stream/NetworkSSRFrame.d.ts +2 -1
- package/dist/components/stream/NetworkSVGOverlay.d.ts +3 -31
- package/dist/components/stream/OrdinalCanvasHitTester.d.ts +2 -0
- package/dist/components/stream/SVGChartTitle.d.ts +9 -0
- package/dist/components/stream/SVGOverlay.d.ts +1 -21
- package/dist/components/stream/SVGUnderlay.d.ts +24 -0
- package/dist/components/stream/SceneToSVG.d.ts +1 -1
- package/dist/components/stream/StreamGeoFrame.d.ts +1 -1
- package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -1
- package/dist/components/stream/StreamXYFrame.d.ts +1 -1
- package/dist/components/stream/accessibleDataRows.d.ts +11 -0
- package/dist/components/stream/accessibleDataTableModel.d.ts +40 -0
- package/dist/components/stream/accessibleTableTypes.d.ts +11 -0
- package/dist/components/stream/axisTickUtils.d.ts +19 -0
- package/dist/components/stream/canvasBackground.d.ts +10 -0
- package/dist/components/stream/canvasSetup.d.ts +9 -0
- package/dist/components/stream/frameCursorInteraction.d.ts +25 -0
- package/dist/components/stream/frameDefaultMargins.d.ts +37 -0
- package/dist/components/stream/frameGraphics.d.ts +18 -0
- package/dist/components/stream/frameGraphicsSubscription.d.ts +26 -0
- package/dist/components/stream/frameLegendOptions.d.ts +18 -0
- package/dist/components/stream/geoFrameCursorInteraction.d.ts +9 -0
- package/dist/components/stream/geoFrameHelpers.d.ts +29 -1
- package/dist/components/stream/geoTypes.d.ts +10 -11
- package/dist/components/stream/hitTarget.d.ts +61 -2
- package/dist/components/stream/moduleWorkerSession.d.ts +6 -0
- package/dist/components/stream/networkAnnotationAnchors.d.ts +37 -0
- package/dist/components/stream/networkCustomLayout.d.ts +2 -2
- package/dist/components/stream/networkFrameCursorInteraction.d.ts +12 -0
- package/dist/components/stream/networkFrameInteraction.d.ts +2 -0
- package/dist/components/stream/networkFramePaint.d.ts +7 -0
- package/dist/components/stream/networkPipelineConfig.d.ts +1 -1
- package/dist/components/stream/networkTypes.d.ts +30 -32
- package/dist/components/stream/normalizeXYData.d.ts +7 -0
- package/dist/components/stream/ordinalFrameCursorInteraction.d.ts +7 -0
- package/dist/components/stream/ordinalFrameInteraction.d.ts +29 -0
- package/dist/components/stream/ordinalSceneSVG.d.ts +10 -0
- package/dist/components/stream/ordinalTypes.d.ts +10 -4
- package/dist/components/stream/physics/PhysicsBodySpatialIndex.d.ts +9 -1
- package/dist/components/stream/physics/PhysicsCanvasTheme.d.ts +25 -0
- package/dist/components/stream/physics/PhysicsControllers.d.ts +0 -3
- package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +4 -1
- package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +3 -24
- package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +9 -21
- package/dist/components/stream/physics/PhysicsSettledSVGElement.d.ts +37 -0
- package/dist/components/stream/physics/PhysicsSettledScene.d.ts +7 -3
- package/dist/components/stream/physics/StreamPhysicsFrame.d.ts +1 -1
- package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +23 -4
- package/dist/components/stream/physics/physicsAnnotationContext.d.ts +19 -0
- package/dist/components/stream/physics/physicsBodyCanvas.d.ts +4 -0
- package/dist/components/stream/physics/physicsSettledChrome.d.ts +7 -0
- package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +32 -0
- package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +36 -0
- package/dist/components/stream/pipelineConfig.d.ts +6 -17
- package/dist/components/stream/pipelineDomainResolution.d.ts +1 -1
- package/dist/components/stream/renderBackend.d.ts +2 -0
- package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +13 -2
- package/dist/components/stream/renderers/resolveCSSColor.d.ts +7 -0
- package/dist/components/stream/responsiveSize.d.ts +17 -0
- package/dist/components/stream/sceneCursor.d.ts +41 -0
- package/dist/components/stream/sceneRevisionDiagnostics.d.ts +1 -1
- package/dist/components/stream/svgOverlayUtils.d.ts +22 -1
- package/dist/components/stream/types.d.ts +25 -12
- package/dist/components/stream/useCanvasFrameHost.d.ts +3 -1
- package/dist/components/stream/useFrame.d.ts +24 -1
- package/dist/components/stream/useResponsiveSize.d.ts +6 -1
- package/dist/components/stream/useStalenessCheck.d.ts +1 -1
- package/dist/components/stream/xyFrameAxisTypes.d.ts +15 -4
- package/dist/components/stream/xyFrameCursorInteraction.d.ts +6 -0
- package/dist/components/stream/xySceneBuilders/swarmScene.d.ts +1 -1
- package/dist/components/stream/xySceneBuilders/types.d.ts +6 -26
- package/dist/components/types/legendTypes.d.ts +6 -0
- package/dist/components/types/marginType.d.ts +7 -8
- package/dist/controls.min.js +1 -1
- package/dist/controls.module.min.js +1 -1
- package/dist/forceLayoutWorker.js +1 -1
- package/dist/geo.min.js +1 -1
- package/dist/geo.module.min.js +1 -1
- package/dist/network.min.js +1 -1
- package/dist/network.module.min.js +1 -1
- package/dist/ordinal.min.js +1 -1
- package/dist/ordinal.module.min.js +1 -1
- package/dist/physics-matter.module.min.js +1 -1
- package/dist/physics-rapier.module.min.js +1 -1
- package/dist/physics.min.js +1 -1
- package/dist/physics.module.min.js +1 -1
- package/dist/physicsWorker.js +1 -1
- package/dist/processSankeyLayoutWorker.js +1 -1
- package/dist/realtime.min.js +1 -1
- package/dist/realtime.module.min.js +1 -1
- package/dist/rough.min.js +1 -1
- package/dist/rough.module.min.js +1 -1
- package/dist/semiotic-ai-core.d.ts +13 -4
- 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 +16 -9
- package/dist/semiotic-ai.min.js +1 -1
- package/dist/semiotic-ai.module.min.js +1 -1
- package/dist/semiotic-client-cjs-shared.min.js +1 -0
- package/dist/semiotic-client-glyph.module.min.js +2 -0
- package/dist/semiotic-client-responsive.module.min.js +2 -0
- package/dist/semiotic-client-shared.module.min.js +2 -0
- package/dist/semiotic-custom-layout-selection-cjs-shared.min.js +2 -0
- package/dist/semiotic-data.min.js +1 -1
- package/dist/semiotic-data.module.min.js +1 -1
- package/dist/semiotic-experimental-auxiliary.module.min.js +2 -0
- package/dist/semiotic-experimental-node-auxiliary.module.min.js +2 -0
- package/dist/semiotic-experimental-node.module.min.js +2 -0
- package/dist/semiotic-experimental-react-shared.module.min.js +2 -0
- package/dist/semiotic-experimental-vacp.min.js +1 -1
- package/dist/semiotic-experimental-vacp.module.min.js +1 -1
- package/dist/semiotic-experimental.d.ts +1 -1
- package/dist/semiotic-experimental.min.js +1 -1
- package/dist/semiotic-experimental.module.min.js +1 -1
- package/dist/semiotic-geo.d.ts +4 -1
- package/dist/semiotic-network.d.ts +7 -4
- package/dist/semiotic-ordinal.d.ts +4 -1
- package/dist/semiotic-physics.d.ts +11 -4
- package/dist/semiotic-realtime-core.d.ts +11 -4
- package/dist/semiotic-realtime-core.min.js +2 -1
- package/dist/semiotic-realtime-core.module.min.js +2 -1
- package/dist/semiotic-realtime-react.d.ts +4 -3
- package/dist/semiotic-realtime-react.min.js +1 -1
- package/dist/semiotic-realtime-react.module.min.js +1 -1
- package/dist/semiotic-realtime.d.ts +3 -1
- package/dist/semiotic-recipes-core-cjs-base.min.js +1 -0
- package/dist/semiotic-recipes-core.d.ts +7 -5
- package/dist/semiotic-recipes-core.min.js +9 -1
- package/dist/semiotic-recipes-core.module.min.js +1 -1
- package/dist/semiotic-recipes-geo-cjs.min.js +1 -0
- package/dist/semiotic-recipes-react.min.js +1 -1
- package/dist/semiotic-recipes-react.module.min.js +1 -1
- package/dist/semiotic-recipes.min.js +7 -1
- package/dist/semiotic-recipes.module.min.js +2 -1
- package/dist/semiotic-server-edge-node.module.min.js +1 -0
- package/dist/semiotic-server-edge.d.ts +3 -2
- 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 +3 -2
- package/dist/semiotic-themes-core.d.ts +5 -48
- package/dist/semiotic-themes-core.min.js +1 -1
- package/dist/semiotic-themes-core.module.min.js +1 -1
- package/dist/semiotic-themes-react.min.js +1 -1
- package/dist/semiotic-themes-react.module.min.js +1 -1
- package/dist/semiotic-themes.min.js +1 -1
- package/dist/semiotic-themes.module.min.js +1 -1
- package/dist/semiotic-utils-core.d.ts +10 -5
- package/dist/semiotic-utils-core.min.js +1 -1
- package/dist/semiotic-utils-core.module.min.js +1 -1
- package/dist/semiotic-utils-react.d.ts +2 -0
- package/dist/semiotic-utils-react.min.js +1 -1
- package/dist/semiotic-utils-react.module.min.js +1 -1
- package/dist/semiotic-utils.min.js +2 -1
- package/dist/semiotic-utils.module.min.js +2 -1
- package/dist/semiotic-value.min.js +1 -1
- package/dist/semiotic-value.module.min.js +1 -1
- package/dist/semiotic-xy.d.ts +4 -1
- package/dist/semiotic.d.ts +68 -26
- 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 +53 -19
- package/dist/__tests__/scenarios/mcpProtocolTypes.d.ts +0 -20
- package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +0 -2
- package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +0 -1
- package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +0 -2
- package/dist/chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js +0 -2
- package/dist/chunk-chunk-2B3AIKUZ.module.min.js +0 -2
- package/dist/chunk-chunk-2CXCXRB4.module.min.js +0 -1
- package/dist/chunk-chunk-2X3FJCME.module.min.js +0 -1
- package/dist/chunk-chunk-2ZHHWZQM.module.min.js +0 -2
- package/dist/chunk-chunk-4ITOQRXM.module.min.js +0 -2
- package/dist/chunk-chunk-5UKL5W76.module.min.js +0 -2
- package/dist/chunk-chunk-5VVNW5AZ.module.min.js +0 -1
- package/dist/chunk-chunk-5ZON5NMV.module.min.js +0 -2
- package/dist/chunk-chunk-66PCWJUG.module.min.js +0 -1
- package/dist/chunk-chunk-6S3YGYW7.module.min.js +0 -1
- package/dist/chunk-chunk-6V5VQVCT.module.min.js +0 -2
- package/dist/chunk-chunk-7C5EDZ3Z.module.min.js +0 -2
- package/dist/chunk-chunk-A3I4HBD5.module.min.js +0 -1
- package/dist/chunk-chunk-ACLDBMRH.module.min.js +0 -2
- package/dist/chunk-chunk-AFQHURLO.module.min.js +0 -2
- package/dist/chunk-chunk-DDB4TLQG.module.min.js +0 -2
- package/dist/chunk-chunk-DTH3SUOU.module.min.js +0 -2
- package/dist/chunk-chunk-DTSNLGRK.module.min.js +0 -2
- package/dist/chunk-chunk-DVCWU7MT.module.min.js +0 -2
- package/dist/chunk-chunk-FEPXDKJP.module.min.js +0 -1
- package/dist/chunk-chunk-FJ76HWQZ.module.min.js +0 -1
- package/dist/chunk-chunk-FSIHAW6L.module.min.js +0 -2
- package/dist/chunk-chunk-G2RGVEYY.module.min.js +0 -2
- package/dist/chunk-chunk-G75OPF5N.module.min.js +0 -2
- package/dist/chunk-chunk-HADHLMY5.module.min.js +0 -1
- package/dist/chunk-chunk-HAJVODLO.module.min.js +0 -2
- package/dist/chunk-chunk-HBFA4NN6.module.min.js +0 -1
- package/dist/chunk-chunk-HIV7AW2V.module.min.js +0 -2
- package/dist/chunk-chunk-IY7RYD4S.module.min.js +0 -1
- package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
- package/dist/chunk-chunk-J3XWETBJ.module.min.js +0 -2
- package/dist/chunk-chunk-JZAMMSQQ.module.min.js +0 -2
- package/dist/chunk-chunk-KTWEBFMX.module.min.js +0 -2
- package/dist/chunk-chunk-LSJUXBMF.module.min.js +0 -1
- package/dist/chunk-chunk-MXMRXSCI.module.min.js +0 -2
- package/dist/chunk-chunk-MXVBXFKW.module.min.js +0 -2
- package/dist/chunk-chunk-NWIGA3UK.module.min.js +0 -1
- package/dist/chunk-chunk-OFAP623Y.module.min.js +0 -2
- package/dist/chunk-chunk-OHLRAEQZ.module.min.js +0 -2
- package/dist/chunk-chunk-OZK46A5U.module.min.js +0 -1
- package/dist/chunk-chunk-PMR47KRY.module.min.js +0 -2
- package/dist/chunk-chunk-PRNXOCYZ.module.min.js +0 -2
- package/dist/chunk-chunk-Q2YADC2V.module.min.js +0 -2
- package/dist/chunk-chunk-RLKZVJMQ.module.min.js +0 -2
- package/dist/chunk-chunk-ROP4HI7H.module.min.js +0 -2
- package/dist/chunk-chunk-SK2TQMG4.module.min.js +0 -2
- package/dist/chunk-chunk-SKLYXNYW.module.min.js +0 -2
- package/dist/chunk-chunk-TCMHJWFJ.module.min.js +0 -1
- package/dist/chunk-chunk-TSCFL235.module.min.js +0 -1
- package/dist/chunk-chunk-U4NZCU5T.module.min.js +0 -2
- package/dist/chunk-chunk-U66USBWU.module.min.js +0 -1
- package/dist/chunk-chunk-UOQRPGPK.module.min.js +0 -2
- package/dist/chunk-chunk-VKL6DI43.module.min.js +0 -2
- package/dist/chunk-chunk-W62673ZE.module.min.js +0 -1
- package/dist/chunk-chunk-WFHZHWT7.module.min.js +0 -1
- package/dist/chunk-chunk-XCC25CZZ.module.min.js +0 -2
- package/dist/chunk-chunk-XECNOUZY.module.min.js +0 -2
- package/dist/chunk-chunk-XYZDTYAF.module.min.js +0 -2
- package/dist/chunk-chunk-YHNZCPOZ.module.min.js +0 -2
- package/dist/chunk-chunk-YWZB3KPI.module.min.js +0 -2
- package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +0 -2
- package/dist/components/stream/test-utils/frameScheduler.d.ts +0 -12
- package/dist/components/stream/test-utils/revisionConsumption.d.ts +0 -13
- package/dist/test-utils/canvasMock.d.ts +0 -86
- package/dist/test-utils/capturedFrameProps.d.ts +0 -67
- package/dist/test-utils/frameMock.d.ts +0 -81
- package/dist/test-utils/ordinalFixtures.d.ts +0 -48
- /package/dist/{chunk-chunk-JJ2OOIET.module.min.js → c-GGISSW5E.min.js} +0 -0
- /package/dist/{chunk-chunk-SIRIJ3DY.module.min.js → c-N4G2L7ID.min.js} +0 -0
- /package/dist/{chunk-chunk-CA3YDW6F.module.min.js → c-S6U5CGT5.min.js} +0 -0
- /package/dist/components/recipes/{mobileAnnotationStrategy.d.ts → mobileAnnotationBehavior.d.ts} +0 -0
package/dist/server.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t,n,o,i,r,s=Object.create,a=Object.defineProperty,l=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,h=(e,t,n)=>function(){if(n)throw n[0];try{return e&&(t=(0,e[c(e)[0]])(e=0)),t}catch(e){throw n=[e],e}},f=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},p=(e,t,n,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of c(t))d.call(e,i)||i===n||a(e,i,{get:()=>t[i],enumerable:!(o=l(t,i))||o.enumerable});return e},g=(e,t,n)=>(n=null!=e?s(u(e)):{},p(!t&&e&&e.__esModule?n:a(n,"default",{value:e,enumerable:!0}),e)),y=h({"src/components/stream/brushAccessibility.ts"(){e=g(require("react")),t="Use arrow keys to move the selected range, Shift plus an arrow key to resize it, and Escape to clear it."}}),m={};function x(e,t,n,o){const[i,r]=[Math.min(...t),Math.max(...t)],s=(r-i)/20;let[a,l]=e;if(o)0>n?a=Math.max(i,a-s):l=Math.min(r,l+s);else{const e=l-a;a=Math.max(i,Math.min(r-e,a+n*s)),l=a+e}return[a,l]}function b(e,t){let n=0,o=t.length-1;for(;o>n;){const i=n+o+1>>1;t[i]>e?o=i-1:n=i}return t[n]}function v(e,t){let n=0,o=t.length-1;for(;o>n;){const i=n+o>>1;e>t[i]?n=i+1:o=i}return t[n]}function w({width:s,height:a,totalWidth:l,totalHeight:c,margin:u,dimension:d,scales:h,onBrush:f,binSize:p,snap:g,binBoundaries:y,snapDuring:m,streaming:w}){const k=(0,n.useRef)(null),S=(0,n.useRef)(null),A=(0,n.useRef)(f);A.current=f;const M=(0,n.useRef)(h);M.current=h;const _=(0,n.useMemo)(()=>y?[...y].sort((e,t)=>e-t):void 0,[y]),P=(0,n.useRef)(_);P.current=_;const j=(0,n.useRef)(!1),C=(0,n.useRef)(null),R=function({label:n="Data range brush",description:o=t,onAction:i}={}){const r=e.useId().replace(/:/g,""),s=e.useRef(i);return s.current=i,{description:o,descriptionId:"semiotic-brush-description-"+r,svgProps:{role:"region",tabIndex:0,"aria-label":n,"aria-describedby":"semiotic-brush-description-"+r,onKeyDown:e.useCallback(e=>{const t=function(e){return"Escape"===e.key?{type:"clear"}:"ArrowLeft"===e.key?{type:"nudge",direction:"left",resize:e.shiftKey}:"ArrowRight"===e.key?{type:"nudge",direction:"right",resize:e.shiftKey}:"ArrowUp"===e.key?{type:"nudge",direction:"up",resize:e.shiftKey}:"ArrowDown"===e.key?{type:"nudge",direction:"down",resize:e.shiftKey}:null}(e);t&&(e.preventDefault(),s.current?.(t))},[])}}}({label:"xy"===d?"Two-dimensional data range brush":d.toUpperCase()+" data range brush",onAction:e=>{const t=M.current,n=S.current;if(!t||!n||!k.current)return;const i=(0,o.select)(k.current).select(".brush-g");if("clear"===e.type)return j.current=!0,i.call(n.move,null),j.current=!1,C.current=null,void A.current(null);const r=t.x.domain(),s=t.y.domain(),a=C.current;let l=a?.x??[r[0]+.4*(r[1]-r[0]),r[0]+.6*(r[1]-r[0])],c=a?.y??[s[0]+.4*(s[1]-s[0]),s[0]+.6*(s[1]-s[0])];const u="left"===e.direction||"right"===e.direction,h="left"===e.direction||"down"===e.direction?-1:1;if(u&&"y"!==d&&(l=x(l,r,h,e.resize)),u||"x"===d||(c=x(c,s,h,e.resize)),u&&"y"===d||!u&&"x"===d)return;const f={x:l,y:c};j.current=!0,i.call(n.move,"x"===d?[t.x(l[0]),t.x(l[1])]:"y"===d?[t.y(c[1]),t.y(c[0])]:[[t.x(l[0]),t.y(c[1])],[t.x(l[1]),t.y(c[0])]]),j.current=!1,C.current=f,A.current(f)}});return(0,n.useEffect)(()=>{if(!k.current)return;const e=(0,o.select)(k.current).select(".brush-g"),t="x"===d?(0,i.brushX)():"y"===d?(0,i.brushY)():(0,i.brush)();return t.extent([[0,0],[s,a]]),t.on("brush end",n=>{if(j.current)return;const o=M.current;if(!o)return;if(!n.selection)return C.current=null,void A.current(null);let i,r;if("x"===d){const[e,t]=n.selection;i=[o.x.invert(e),o.x.invert(t)],r=[o.y.invert(a),o.y.invert(0)]}else if("y"===d){const[e,t]=n.selection;i=[o.x.invert(0),o.x.invert(s)],r=[o.y.invert(t),o.y.invert(e)]}else{const[[e,t],[s,a]]=n.selection;i=[o.x.invert(e),o.x.invert(s)],r=[o.y.invert(a),o.y.invert(t)]}if("bin"===g&&"y"!==d&&("end"===n.type||"brush"===n.type&&m)){const r=P.current;r&&r.length>0?i=function(e,t){return 0===t.length?e:[b(e[0],t),v(e[1],t)]}(i,r):p&&p>0&&(i=[Math.floor(i[0]/p)*p,Math.ceil(i[1]/p)*p]);const s=o.x(i[0]),a=o.x(i[1]);if(j.current=!0,"x"===d)e.call(t.move,[s,a]);else if("xy"===d){const o=n.selection;e.call(t.move,[[s,o[0][1]],[a,o[1][1]]])}j.current=!1}const l={x:i,y:r};C.current=l,A.current(l)}),e.call(t),S.current=t,e.select(".selection").attr("fill","steelblue").attr("fill-opacity",.15).attr("stroke","steelblue").attr("stroke-width",1),()=>{t.on("brush end",null),S.current=null}},[s,a,d,g,p,m]),(0,n.useEffect)(()=>{if(!(w&&h&&S.current&&C.current))return;if(!k.current)return;if("y"===d)return;const e=C.current,t=h.x.domain()[0],n=(0,o.select)(k.current).select(".brush-g");if(t>=e.x[1])return j.current=!0,n.call(S.current.move,null),j.current=!1,C.current=null,void A.current(null);let i=e.x[0],r=!1;if(t>e.x[0]){if(i=t,"bin"===g){const e=P.current;e&&e.length>0?i=v(t,e):p&&p>0&&(i=Math.ceil(t/p)*p)}if(i>=e.x[1])return j.current=!0,n.call(S.current.move,null),j.current=!1,C.current=null,void A.current(null);r=!0}const s=h.x(i),a=h.x(e.x[1]);if(j.current=!0,"x"===d)n.call(S.current.move,[s,a]);else{const t=h.y(e.y[1]),o=h.y(e.y[0]);n.call(S.current.move,[[s,t],[a,o]])}if(j.current=!1,r){const t={x:[i,e.x[1]],y:e.y};C.current=t,A.current(t)}},[h,w,d,g,p]),(0,r.jsxs)("svg",{ref:k,width:l,height:c,...R.svgProps,style:{position:"absolute",top:0,left:0,pointerEvents:"all"},children:[(0,r.jsx)("title",{children:R.svgProps["aria-label"]}),(0,r.jsx)("desc",{id:R.descriptionId,children:R.description}),(0,r.jsx)("g",{className:"brush-g",transform:`translate(${u.left},${u.top})`})]})}f(m,{XYBrushOverlay:()=>w});var k,S=h({"src/components/stream/XYBrushOverlay.tsx"(){n=require("react"),o=require("d3-selection"),i=require("d3-brush"),y(),r=require("react/jsx-runtime")}}),A={};function M(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}f(A,{generateFrameSVGs:()=>Zv,generateFrameSequence:()=>Qv,generatePhysicsFrameSVGs:()=>ew,renderChart:()=>qv,renderChartWithEvidence:()=>Xv,renderDashboard:()=>Vv,renderGeoToStaticSVG:()=>Nv,renderNetworkToStaticSVG:()=>Ev,renderOrdinalToStaticSVG:()=>Fv,renderPhysicsToAnimatedGif:()=>rw,renderToAnimatedGif:()=>iw,renderToImage:()=>Gv,renderToStaticSVG:()=>zv,renderXYToStaticSVG:()=>Dv,resolveTheme:()=>et,themeStyles:()=>tt}),module.exports=(k=A,p(a({},"__esModule",{value:!0}),k));var _=44,P={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:_,snap:"nearestDatum",brushHandleSize:_,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function j(e,t={}){const n=t.mobileSemantics?.interaction,o="number"==typeof n?.targetSize?n.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,i="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,r=!!n||void 0!==o,s=e&&"object"==typeof e?e:void 0;if(!1===e||!1===s?.enabled||void 0===e&&!i&&!r)return P;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??o??_,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??_,standardControls:a.standardControls??!1}}var C={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 R(e,t,n){const o=C[e||"primary"],i=e&&"primary"!==e||!n?.width?o.width:n.width,r=e&&"primary"!==e||!n?.height?o.height:n.height,s=function(e,t,n=e.responsiveRules){if(!Array.isArray(n)||0===n.length)return{props:e,matches:[]};const o=n.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){const{when:n}=e,o=t.width,i=t.height,r=function(e){if("number"==typeof e.height&&e.height>0)return e.width/e.height}(t),s=function(e){if("number"==typeof e.height&&e.height>0)return e.height>e.width?"portrait":"landscape"}(t);return!("number"==typeof n.minWidth&&n.minWidth>o||"number"==typeof n.maxWidth&&o>n.maxWidth||"number"==typeof n.minHeight&&("number"!=typeof i||n.minHeight>i)||"number"==typeof n.maxHeight&&("number"!=typeof i||i>n.maxHeight)||"number"==typeof n.minAspectRatio&&("number"!=typeof r||n.minAspectRatio>r)||"number"==typeof n.maxAspectRatio&&("number"!=typeof r||r>n.maxAspectRatio)||n.orientation&&s!==n.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:o.reduce((e,t)=>function(e,t){const n={...e,...t};for(const o of["margin","frameProps","mobileSemantics","style"])M(e[o])&&M(t[o])&&(n[o]={...e[o],...t[o]});return"string"==typeof e.className&&"string"==typeof t.className&&(n.className=`${e.className} ${t.className}`),n}(e,t.rule.transform),e),matches:o}}({...t,mode:e},{width:t.width??i,height:t.height??r}).props,a=s.mode||e||"primary",l=C[a],c="context"===a||"sparkline"===a,u="primary"===a&&n?.width?n.width:l.width;return{mode:a,width:s.width??u,height:s.height??("primary"===a&&n?.height?n.height:l.height),showAxes:s.showAxes??l.showAxes,showGrid:s.showGrid??l.showGrid,enableHover:s.enableHover??(!!s.linkedHover||l.enableHover),showLegend:s.showLegend??l.showLegend,showLabels:s.showLabels??l.showLabels,title:c?void 0:s.title,description:s.description,summary:s.summary,accessibleTable:s.accessibleTable,xLabel:c?void 0:s.xLabel,yLabel:c?void 0:s.yLabel,categoryLabel:c?void 0:s.categoryLabel,valueLabel:c?void 0:s.valueLabel,marginDefaults:L(l.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:c,mobileInteraction:j(s.mobileInteraction,{mode:a,width:s.width??u,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}function L(e,t,n){if(!1!==t)return e;const o={...e};return"horizontal"===n?o.left=Math.min(o.left,15):o.bottom=Math.min(o.bottom,15),o}function T(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};const t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}var I=g(require("react-dom/server")),$=g(require("react")),O=Object.freeze([]);function z(e){if(!e)return O;let t=!1;for(let n=0;e.length>n;n++){const o=e[n];if(null==o||"object"!=typeof o){t=!0;break}}if(!t)return e;const n=[];for(const t of e)null!=t&&"object"==typeof t&&n.push(t);return n}var D=require("d3-scale");function F(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function E(e,t,n){const o=e=>e.toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function N(e){const t=e.map(F),n=t.length-1;return e=>{if(0>=e){const[e,n,o]=t[0];return E(e,n,o)}if(e>=1){const[e,o,i]=t[n];return E(e,o,i)}const o=e*n,i=Math.floor(o),r=o-i,[s,a,l]=t[i],[c,u,d]=t[i+1];return E(Math.round(s+(c-s)*r),Math.round(a+(u-a)*r),Math.round(l+(d-l)*r))}}var B=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],W=N(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),Y=N(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),q=N(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),X=N(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),H=N(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),G=N(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),V=N(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),U=N(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),K=N(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),Z=N(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),Q=N(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),J=N(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),ee={blues:W,reds:Y,greens:q,viridis:V,oranges:X,purples:H,greys:G,plasma:U,inferno:K,magma:Z,cividis:Q,turbo:J};function te(e){return e&&ee[e]||W}var ne=N(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),oe=N(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),ie=N(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),re=N(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),se=N(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),ae=N(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),le=N(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),ce={category10:B,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...ee},ue=B,de="#007bff";function he(e,t,n=ue){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){const t=ce[e];if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:n}var fe=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],pe=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],ge=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 ye(e,t,n){if("function"==typeof t){const o=t(e);return n&&o&&"string"==typeof o&&!function(e){const t=e.toLowerCase();return t.startsWith("#")||t.startsWith("rgb")||t.startsWith("hsl")||ge.has(t)}(o)?n(o):o}const o=e?.[t]+"";return n?n(o):ue[Math.abs(function(e){let t=0;for(let n=0;e.length>n;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return Math.abs(t)}(o))%ue.length]}function me(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;const n=e[t];return"string"==typeof n&&n.length>0?n:void 0}function xe(e,t,n="category10"){if(n&&"object"==typeof n&&!Array.isArray(n)){const e=n;return t=>me(e,t)??"#999"}const o=Array.from(new Set(e.map(e=>e?.[t]).filter(e=>null!=e).map(e=>e+""))),i=o.every(e=>!isNaN(Number(e)));if(Array.isArray(n))return(0,D.scaleOrdinal)().domain(o).range(n).unknown("#999");const r=ce[n]||ce.category10;if(i&&"function"==typeof r){let e=-1/0;for(const t of o){const n=Number(t);n>e&&(e=n)}return t=>r(Number(t)/e)}{const e=Array.isArray(r)?r:ue;return(0,D.scaleOrdinal)().domain(o).range(e).unknown("#999")}}function be(e,t,n=[3,20],o){let i;if(i="function"==typeof t?t(e):e?.[t],!o)return i;const[r,s]=o,[a,l]=n;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function ve(e){let t=1/0,n=-1/0;for(const o of e)t>o&&(t=o),o>n&&(n=o);return[t,n]}function we(e,t=-1/0){let n=t;for(const t of e)t>n&&(n=t);return n}function ke(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function Se(e,t){if(!ke(t))return e??((...e)=>({}));const n={};return void 0!==t.stroke&&(n.stroke=t.stroke),void 0!==t.strokeWidth&&(n.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(n.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...n}):(...e)=>({...n})}function Ae(e){if(null==e)return()=>{};const t="function"==typeof e?e:t=>t[e];return e=>Pe(t(e))}function Me(e,t){const n=Ae(e),o=Ae(t);return(e,t)=>{const i=o(e);return{value:i,x:n(e),y:i,category:t}}}function _e(e,t){const n=Ae(t??"value"),o=null==e?void 0:"function"==typeof e?e:t=>t[e];return e=>{const t=o?o(e):void 0;return{value:n(e),category:null==t?void 0:t+""}}}function Pe(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isFinite(t)?t:void 0}}function je(e,t,n){const o=e.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(t,n):function(e,t,n){const o=null!=e.axis?n[e.axis]:null!=e.field?t[e.field]:n.value;if(void 0!==e.eq&&o!==e.eq)return!1;if(void 0!==e.ne&&o===e.ne)return!1;if(void 0!==e.in&&!e.in.includes(o))return!1;if(void 0===e.gt&&void 0===e.gte&&void 0===e.lt&&void 0===e.lte&&void 0===e.within&&void 0===e.outside)return!0;const i=Pe(o);if(void 0===i)return!1;if(void 0!==e.gt&&e.gt>=i)return!1;if(void 0!==e.gte&&e.gte>i)return!1;if(void 0!==e.lt&&i>=e.lt)return!1;if(void 0!==e.lte&&i>e.lte)return!1;if(void 0!==e.within){const[t,n]=e.within;if(t>i||i>n)return!1}if(void 0!==e.outside){const[t,n]=e.outside;if(i>=t&&n>=i)return!1}return!0}(o,t,n))}function Ce(e,t,n){if(!t||0===t.length)return{};let o={};for(const i of t){if(!je(i,e,n))continue;const t="function"==typeof i.style?i.style(e,n):i.style;t&&(o={...o,...t})}return o}function Re(e,t,n,o=e=>e){const i=e??(()=>({}));return t&&0!==t.length?(e,r)=>{const s=o(e),a={...i(e,r)};return Object.assign(a,Ce(s,t,n(s,r))),a}:i}function Le(e,t,n,o){if(!e||0===e.length)return o;const i=_e(t,n);return(t,n)=>{const r=t&&t.data||t,s=Ce(r,e,i(r)),a=o?o(t,n):void 0;return a?{...s,...a}:s}}var Te={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function Ie(e,t=Te){if(e)return!0===e?t:"stops"in e?Array.isArray(e.stops)?e:void 0:"colorStops"in e?Array.isArray(e.colorStops)?{stops:e.colorStops.map(({offset:e,color:t})=>({offset:e,color:t}))}:void 0:{stops:[{offset:0,opacity:e.topOpacity??t.stops[0]?.opacity??.8},{offset:1,opacity:e.bottomOpacity??t.stops.at(-1)?.opacity??.05}]}}function $e(e){return e?Ie(e):void 0}function Oe(e,t,n){return"function"==typeof e?e(n):n[e||t]}function ze(e){return e instanceof Date?e.getTime():Number(e)}function De(e,t){return V(1===t?.5:e/(t-1))}function Fe(e){const t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}var Ee=require("react"),Ne=require("react/jsx-runtime");function Be(e){let t=null;const n=()=>(t||(t=(0,Ee.createContext)(null)),t),o=We(e);return[function({children:t,initialState:o}){const i=(0,Ee.useRef)(o),r=(0,Ee.useMemo)(()=>We(e,i.current),[]),s=n();return(0,Ne.jsx)(s.Provider,{value:r,children:t})},(e,t)=>{const i=n(),r=(0,Ee.useContext)(i)??o,s=(0,Ee.useRef)(e);s.current=e;const a=(0,Ee.useRef)({hasValue:!1,value:void 0}),l=(0,Ee.useCallback)(()=>{const e=s.current(r.getState()),n=a.current;return n.hasValue&&t&&t(n.value,e)?n.value:(a.current={hasValue:!0,value:e},e)},[r,t]),c=(0,Ee.useCallback)(()=>s.current(r.getState()),[r]);return(0,Ee.useSyncExternalStore)(r.subscribe,l,c)}]}function We(e,t){const n=new Set;let o={...e(function(e){const t=e(o);if(Ye(t)){o={...o,...t};for(const e of n)e()}}),...t??{}};return{getState:()=>o,subscribe:function(e){return n.add(e),()=>{n.delete(e)}}}}function Ye(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}function qe(e){if(!e?.colors)return;const t=e.colors;return{primary:t.primary,secondary:t.secondary||t.primary,surface:t.surface||t.background,success:t.success,danger:t.danger,warning:t.warning,error:t.error,info:t.info,text:t.text,textSecondary:t.textSecondary,border:t.border,grid:t.grid}}function Xe(e){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:He}}),e.accessibility.highContrast){const e="dark"===t.mode;t={...t,colors:{...t.colors,text:e?"#ffffff":"#000000",textSecondary:e?"#cccccc":"#333333",grid:e?"#666666":"#999999",border:e?"#888888":"#000000"}}}return t}var He=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],Ge={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}},Ve={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}},Ue={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:He,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 Ke(e,t){if("light"===t)return Ge;if("dark"===t)return Ve;if("high-contrast"===t)return Ue;if("string"==typeof t)return void 0!==console&&console.warn(`[ThemeStore] Unknown theme preset "${t}". Keeping current theme.`),e;if(t.mode&&"auto"!==t.mode){const e="dark"===t.mode?Ve:Ge;return Xe({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}return Xe({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}var[Ze,Qe]=Be(e=>({theme:Ge,setTheme(t){e(e=>({theme:Ke(e.theme,t)}))}})),Je={light:Ge,dark:Ve,"high-contrast":Ue,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 et(e){if(!e)return Ge;if("string"==typeof e){if("light"===e)return Ge;if("dark"===e)return Ve;if("high-contrast"===e)return Ue;return Je[e]||Ge}const t="dark"===e.mode?Ve:Ge;return Xe({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}})}function tt(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function nt(e,t,n){const o="function"==typeof t?t(e):e[t??n];if(null==o)return null;if(o instanceof Date)return o.getTime();if("string"==typeof o&&""===o.trim())return null;const i=Number(o);return Number.isFinite(i)?i:null}function ot(e){return Math.round(100*e)/100}function it(e,t=2){const n=[],o=[],i=t+1;for(let t=0;i>t;t++){let r=0;for(const[n,o]of e)null!==o&&(r+=n**t*o);n.push(r);const s=[];for(let n=0;i>n;n++){let o=0;for(const[i,r]of e)null!==r&&(o+=i**(t+n));s.push(o)}o.push(s)}o.push(n);const r=function(e,t){const n=e,o=e.length-1,i=[t];for(let e=0;o>e;e++){let t=e;for(let i=e+1;o>i;i++)Math.abs(n[e][i])>Math.abs(n[e][t])&&(t=i);for(let i=e;o+1>i;i++){const o=n[i][e];n[i][e]=n[i][t],n[i][t]=o}for(let t=e+1;o>t;t++)for(let i=o;i>=e;i--)n[i][t]-=n[i][e]*n[e][t]/n[e][e]}for(let e=o-1;e>=0;e--){let t=0;for(let r=e+1;o>r;r++)t+=n[r][e]*i[r];i[e]=(n[o][e]-t)/n[e][e]}return i}(o,i).map(ot);return{points:e.map(([e])=>[ot(e),ot(r.reduce((t,n,o)=>t+n*e**o,0))]),equation:[...r].reverse()}}function rt(e){const t=e.length;let n=0,o=0,i=0,r=0;for(const[t,s]of e)n+=t,o+=s,i+=t*t,r+=t*s;const s=t*i-n*n;if(1e-12>Math.abs(s))return null;const a=(t*r-n*o)/s,l=(o-a*n)/t;return e=>l+a*e}function st(e,t){const n=e.length,o=e.map(([e,n])=>n-t(e)).reduce((e,t)=>e+t*t,0),i=Math.sqrt(o/Math.max(n-2,1)),r=e.reduce((e,t)=>e+t[0],0)/n,s=e.reduce((e,t)=>e+(t[0]-r)**2,0);return{se:i,meanX:r,ssX:s}}function at(e){return.99>e?.95>e?.9>e?1:1.645:1.96:2.576}var lt="__forecastSegment",ct="__forecastOpacity";function ut(e,t,n,o){const i=t.uncertaintyOpacity,r=t.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,l=s.max??1;if(r){const t="function"==typeof r?r:e=>e[r];for(const n of e){const e=t(n);null!=e&&Number.isFinite(e)&&(n[ct]=a+Math.max(0,Math.min(1,e))*(l-a))}return}const c=e.map(e=>{const t=n(e),i=o(e);return null!=t&&null!=i&&Number.isFinite(t)&&Number.isFinite(i)?Math.abs(t-i):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;const[d,h]=ve(u),f=h-d;e.forEach((e,t)=>{const n=c[t];Number.isFinite(n)&&(e[ct]=l-(f>0?(n-d)/f:0)*(l-a))})}function dt(e,t){return"function"==typeof t?t(e):!!e[t]}var ht="__semiotic_resolvedX",ft="__semiotic_resolvedY",pt="__compoundGroup";function gt(e,t,n){const o=e[t],i=e[n];return null==o||null==i||Number.isNaN(o)||Number.isNaN(i)}function yt(e){const t=e.xAccessor||"x",n=e.yAccessor||"y",o=e.lineBy,i=e.colorBy||o;let r=Array.isArray(e.data)?z(e.data).filter(e=>!!e&&"object"==typeof e):[];const s=function(e,t,n){const o="function"==typeof t,i="function"==typeof n,r=o?ht:t,s=i?ft:n;return o||i?{xKey:r,yKey:s,rows:e.map(e=>{const r={...e};return o&&(r[ht]=t(e)),i&&(r[ft]=n(e)),r})}:{rows:e,xKey:r,yKey:s}}(r,t,n);r=s.rows;const a=s.xKey,l=s.yKey,c=Array.isArray(e.annotations)?[...e.annotations]:[];let u,d="string"==typeof o||"function"==typeof o?o:void 0,h=e.baseLineStyle;if(e.forecast){const t=function(e,t,n,o,i){return(r=o).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(e,t,n,o,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=o,g=e.map(e=>{let t="observed";return s&&dt(e,s)?t="forecast":r&&dt(e,r)&&(t="training"),{...e,[lt]:t}}),y=o._groupBy,m=[];if(y){const e=new Map;for(const t of g){const n=t[y]??"__default";e.has(n)||e.set(n,[]),e.get(n).push(t)}const t=[];for(const[,n]of e)for(let e=0;n.length-1>e;e++)n[e][lt]!==n[e+1][lt]&&(t.push({...n[e+1],[lt]:n[e][lt]}),t.push({...n[e],[lt]:n[e+1][lt]}));m.push(...g,...t)}else for(let e=0;g.length>e;e++)m.push(g[e]),g.length-1>e&&g[e][lt]!==g[e+1][lt]&&(m.push({...g[e+1],[lt]:g[e][lt]}),m.push({...g[e],[lt]:g[e+1][lt]}));if(o.trainUnderline){const e=[];for(const t of m)"training"===t[lt]&&e.push({...t,[lt]:"training-base"});m.unshift(...e)}const x=[];if(l&&c){const e="string"==typeof l?l:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const n of m)"function"==typeof l&&(n[e]=l(n)),"function"==typeof c&&(n[t]=c(n));x.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:p})}if(o.uncertaintyOpacity||o.confidenceAccessor){const e=l?"function"==typeof l?l:e=>e[l]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};ut(m.filter(e=>"forecast"===e[lt]),o,e,t)}if(a){const e=o.anomalyStyle,t={type:"highlight",filter:e=>dt(e,a)};e?(t.style=e,t.r=f):"function"==typeof h?(t.style=e=>{const t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=f):(t.color=h,t.r=f,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(t)}return i&&x.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:m,annotations:x}}(e,0,0,o,i):function(e,t,n,o,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:l="#6366f1",bandOpacity:c=.15,label:u}=o;if(null==r)return{processedData:e,annotations:[]};const d=[],h=[];for(const n of e)n[t]>r?h.push({...n,[lt]:"observed"}):d.push({...n,[lt]:"training"});const f=d.map(e=>[e[t],e[n]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),p=[],g=[];if(f.length>=3){const i=f.length,r=rt(f);if(r){const{se:d,meanX:h,ssX:y}=st(f,r),m=at(a),x=we(e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e))),b=f.length>1?(f[i-1][0]-f[0][0])/(i-1):1;for(let e=1;s>=e;e++){const o=x+e*b,s=r(o),a=d*Math.sqrt(1+1/i+(y>0?(o-h)**2/y:0))*m;g.push({[t]:o,[n]:s,[lt]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}ut(g,o,e=>e.__forecastUpper,e=>e.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&p.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[lt]:"observed"}),y.push(...h),g.length>0){const e=h.length>0?h[h.length-1]:d[d.length-1];e&&y.push({...e,[lt]:"forecast"}),y.push(...g)}return{processedData:y,annotations:p}}(e,t,n,o,i);var r}(r,a,l,o&&"string"==typeof o&&"object"==typeof e.forecast?{...e.forecast,_groupBy:o}:e.forecast,e.anomaly);if(r=t.processedData,c.push(...t.annotations),u=function(e,t,n){const o=n.upperBounds,i=n.lowerBounds;if(!o&&!i)return;const r="function"==typeof o?o:"string"==typeof o?e=>e[o]:null,s="function"==typeof i?i:"string"==typeof i?e=>e[i]:null;let a=1/0,l=-1/0;for(const n of e){const e=Number(n[t]);if(Number.isFinite(e)&&(a>e&&(a=e),e>l&&(l=e)),r){const e=r(n);null!=e&&Number.isFinite(e)&&(e>l&&(l=e),a>e&&(a=e))}if(s){const e=s(n);null!=e&&Number.isFinite(e)&&(a>e&&(a=e),e>l&&(l=e))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,e.forecast),o&&"string"==typeof o?(r=r.map(e=>({...e,[pt]:`${e[o]}__${e[lt]||"observed"}`})),d=pt):d=lt,e.baseLineStyle){const t=function(e,t){const n=t.trainDasharray??"8,4",o=t.forecastDasharray??"4,4",i=t.color||"#6366f1",r=t.trainOpacity,s=t.forecastOpacity,a=t.trainStroke,l=t.trainLinecap,c=t.trainUnderline;return t=>{const u=e(t),d=t[lt];if("training"===d){let e=u.stroke;return"darken"===a?e=function(e,t=.5){const n=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!n)return e;const o=Math.round(parseInt(n[1],16)*(1-t)),i=Math.round(parseInt(n[2],16)*(1-t)),r=Math.round(parseInt(n[3],16)*(1-t));return`#${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(e=a),{...u,stroke:e,strokeDasharray:n,...l&&{strokeLinecap:l},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let e=u.stroke||"#666";return"lighten"===c&&(e=function(e,t=.5){const n=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!n)return e;const o=Math.round(parseInt(n[1],16)+(255-parseInt(n[1],16))*t),i=Math.round(parseInt(n[2],16)+(255-parseInt(n[2],16))*t),r=Math.round(parseInt(n[3],16)+(255-parseInt(n[3],16))*t);return`#${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(e,.4)),{...u,stroke:e,strokeDasharray:void 0}}if("forecast"===d){const e=t[ct],n=null!=e?e:s;return{...u,stroke:i,strokeDasharray:o,...null!=n&&{strokeOpacity:n}}}return u}}(t=>e.baseLineStyle(t),e.forecast);h=e=>t(e)}}else e.anomaly&&c.push(...(f=e.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(e.gapStrategy){if("function"==typeof d){const e=d;r=r.map(t=>({...t,__semiotic_gapGroup:e(t)})),d="__semiotic_gapGroup"}const t=function(e,t,n,o,i){const r=new Map;for(const t of e){const e=i?(t[i]??"")+"":"__single";r.has(e)||r.set(e,[]),r.get(e).push(t)}if("interpolate"===t){const e=[];for(const[,t]of r)for(const i of t)gt(i,n,o)||e.push(i);return{rows:e,groupKey:i}}if("zero"===t){const e=[];for(const[,t]of r)for(const i of t)gt(i,n,o)?e.push({...i,[o]:0}):e.push(i);return{rows:e,groupKey:i}}const s=[],a="_gapSegment";for(const[e,t]of r){let i=0,r=[];const l=()=>{if(0===r.length)return;const t="__single"===e?"__seg"+i:`${e}__seg${i}`;for(const e of r)s.push({...e,[a]:t});r=[],i++};for(const e of t)gt(e,n,o)?l():r.push(e);l()}return{rows:s,groupKey:a}}(r,e.gapStrategy,a,l,"string"==typeof d?d:void 0);r=t.rows,t.groupKey&&(d=t.groupKey)}let p;if(e.directLabel){const t=function(e,t,n,o,i,r,s,a){if(!t||!n)return{annotations:[]};const l="object"==typeof t?t:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof n?n:e=>e[n],h=new Map;for(const t of e){const e=d(t);if(null==e)continue;const n=e+"";""!==n&&(h.has(n)||h.set(n,[]),h.get(n).push(t))}const f=new Map;for(const[e,t]of h)t.sort((e,t)=>Number(e[o])-Number(t[o])),f.set(e,"end"===c?t[t.length-1]:t[0]);const p=xe(Array.from(f.entries()).map(([e])=>({__lbl:e})),"__lbl",r??s),g=Array.from(f.entries()).map(([e,t])=>({type:"text",label:e,[o]:t[o],[i]:t[i],dx:"end"===c?6:-6,dy:0,color:p?ye({__lbl:e},"__lbl",p):a||de,fontSize:u}));g.sort((e,t)=>Number(e[i])-Number(t[i]));for(let e=1;g.length>e;e++){const t=g[e-1],n=g[e],o=Number(t[i])+t.dy;u+2>Math.abs(Number(n[i])+n.dy-o)&&(n.dy+=u+2)}const y=g.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,e.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,e.colorScheme,e.themeCategorical,e.color);c.push(...t.annotations),p=t.marginExtra}return{data:r,xAccessor:"function"==typeof t?a:t,yAccessor:"function"==typeof n?l:n,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:p}}var mt=require("react"),xt=g(require("react")),bt=require("react/jsx-runtime"),vt={isActive:!1,predicate:()=>!0},wt=xt.createContext(null);function kt({value:e,children:t}){return(0,bt.jsx)(wt.Provider,{value:e,children:t})}function St(e,t){return null!=e?(0,bt.jsx)(kt,{value:t,children:e}):e}var At=require("react"),Mt=g(require("react")),_t=require("react"),Pt=g(require("react")),jt=require("react/jsx-runtime"),Ct=null,Rt=null;function Lt(e){const[t,n]=Pt.useState(()=>Ct);return Pt.useEffect(()=>{if(t)return;let e=!1;return(Ct?Promise.resolve(Ct):(Rt||(Rt=Promise.resolve().then(()=>(S(),m)).then(e=>Ct=e.XYBrushOverlay).catch(e=>{throw Rt=null,e})),Rt)).then(t=>{e||n(()=>t)}),()=>{e=!0}},[t]),t?(0,jt.jsx)(t,{...e}):null}var Tt=class{constructor(e,t){this.lastBoundedData=null,this.chunkTimer=0,this.pushBuffer=[],this.flushScheduled=!1,this.callback=e,this.chunkThreshold=t?.chunkThreshold??5e3,this.chunkSize=t?.chunkSize??5e3}updateChunkOptions(e){null!=e.chunkThreshold&&(this.chunkThreshold=e.chunkThreshold),null!=e.chunkSize&&(this.chunkSize=e.chunkSize)}clearLastData(){this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0)}setBoundedData(e){if(e=z(e),this.lastBoundedData===e)return;if(this.lastBoundedData=e,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.chunkThreshold>=e.length)return void this.callback({inserts:e,bounded:!0});this.callback({inserts:e.slice(0,this.chunkSize),bounded:!0,totalSize:e.length});let t=this.chunkSize;const n=()=>{if(t>=e.length)return void(this.chunkTimer=0);if(e!==this.lastBoundedData)return void(this.chunkTimer=0);const o=Math.min(t+this.chunkSize,e.length);this.callback({inserts:e.slice(t,o),bounded:!1}),t=o,this.chunkTimer=e.length>t?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}setReplacementData(e){if(e=z(e),this.lastBoundedData=e,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.pushBuffer=[],this.flushScheduled=!1,this.chunkThreshold>=e.length)return void this.callback({inserts:e,bounded:!0,preserveCategoryOrder:!0});this.callback({inserts:e.slice(0,this.chunkSize),bounded:!0,preserveCategoryOrder:!0,totalSize:e.length});let t=this.chunkSize;const n=()=>{if(t>=e.length)return void(this.chunkTimer=0);if(e!==this.lastBoundedData)return void(this.chunkTimer=0);const o=Math.min(t+this.chunkSize,e.length);this.callback({inserts:e.slice(t,o),bounded:!1}),t=o,this.chunkTimer=e.length>t?requestAnimationFrame(n):0};this.chunkTimer=requestAnimationFrame(n)}flushPushBuffer(){if(this.flushScheduled=!1,0===this.pushBuffer.length)return;const e=this.pushBuffer;this.pushBuffer=[],this.callback({inserts:e,bounded:!1})}scheduleFlush(){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushPushBuffer()))}push(e){null!=e&&"object"==typeof e&&(this.pushBuffer.push(e),this.scheduleFlush())}pushMany(e){if(0===e.length)return;let t=0;for(let n=0;e.length>n;n++){const o=e[n];null!=o&&"object"==typeof o&&(this.pushBuffer.push(o),t++)}0!==t&&this.scheduleFlush()}flush(){this.flushPushBuffer()}clear(){this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1}},It=class{constructor(e){if(this._capacity=e,this.head=0,this._size=0,1>e)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){const t=[];for(const n of e){const e=this.push(n);void 0!==e&&t.push(e)}return t}get(e){if(e>=0&&this._size>e)return this.buffer[(this.head-this._size+e+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 e=0;return{next:()=>this._size>e?{done:!1,value:this.get(e++)}:{done:!0,value:void 0}}}forEach(e){const t=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++)e(this.buffer[(t+n)%this._capacity],n)}toArray(){const e=Array(this._size),t=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++)e[n]=this.buffer[(t+n)%this._capacity];return e}resize(e){if(1>e)throw Error("RingBuffer capacity must be at least 1");const t=this.toArray();let n=0,o=[];t.length>e&&(n=t.length-e,o=t.slice(0,n)),this._capacity=e,this.buffer=Array(e),this.head=0,this._size=0;for(let e=n;t.length>e;e++)this.push(t[e]);return o}update(e,t){const n=[],o=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const r=(o+i)%this._capacity,s=this.buffer[r];if(e(s)){let e;e="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},n.push(e),this.buffer[r]=t(s)}}return n}remove(e){const t=[],n=[];if(this.forEach(o=>{e(o)?n.push(o):t.push(o)}),0===n.length)return n;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const e of t)this.push(e);return n}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},$t=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isFinite(e)&&(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}evict(e){e!==this._min&&e!==this._max||(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(const n of e){const e=t?t(n):n;Number.isFinite(e)&&(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function Ot(e,t){return e===t}function zt(e,t){if("function"==typeof e)return t=>+e(t);const n=e||t;return e=>+e[n]}function Dt(e,t){if("function"==typeof e)return e;const n=e||t;return e=>e[n]}function Ft(e,t){return"function"==typeof e?e:e?t=>t[e]+"":t?e=>e[t]+"":void 0}function Et(e){return e?"function"==typeof e?e:t=>t[e]||t.id:null}function Nt(e){return"string"==typeof e?e:e.id}var Bt=/^\d{4}-\d{1,2}$/;function Wt(e){const t=e.trim();if(!t||!Number.isNaN(Number(t)))return NaN;const n=Bt.test(t)?t+"-01":t;if(n===t&&10>t.length)return NaN;const o=Date.parse(n);return Number.isFinite(o)?o:NaN}function Yt(e){return e instanceof Date?e.getTime():"string"==typeof e?Wt(e):+e}function qt(e){return new Set(Array.isArray(e)?e:[e])}function Xt(e,t="ease-out-cubic"){return"linear"===t?e:1-Math.pow(1-e,3)}function Ht(e,t){return Math.min((e-t.startTime)/t.duration,1)}function Gt(e,t,n){return e+(t-e)*n}function Vt(){return"undefined"!=typeof performance?performance.now():Date.now()}function Ut(e,t,n){if(1>=n)return 1;const o=n-1;return function(e){const t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||0>=e.extent)return 1;const n=Math.max(0,e.age);if("step"===e.type)return(e.threshold??.5*e.extent)>n?1:t;if("exponential"===e.type){const o=e.halfLife??e.extent/2;return t+Math.pow(.5,n/(o>0?o:e.extent/2))*(1-t)}return t+Math.max(0,Math.min(1,1-n/e.extent))*(1-t)}({age:o-t,extent:o,type:e.type,halfLife:e.halfLife??n/2,threshold:e.stepThreshold??.5*n,minOpacity:e.minOpacity??.1})}function Kt(e){const t=new Map;for(let n=0;e.length>n;n++)t.set(e[n],n);return t}function Zt(e,t,n){const o=e.duration??500,i=n-t;return o>i?1-i/o:0}function Qt(e,t,n,o){let i=!1;return t>0?(e._pulseIntensity!==t&&(e._pulseIntensity=t,i=!0),e._pulseColor!==n&&(e._pulseColor=n,i=!0),e._pulseGlowRadius!==o&&(e._pulseGlowRadius=o,i=!0),i):(0!==e._pulseIntensity&&(e._pulseIntensity=0,i=!0),void 0!==e._pulseColor&&(e._pulseColor=void 0,i=!0),void 0!==e._pulseGlowRadius&&(e._pulseGlowRadius=void 0,i=!0),i)}function Jt(e,t,n=("undefined"!=typeof performance?performance.now():Date.now())){if(!t||0===t.size)return!1;const o=e.duration??500,i=t.peek();return null!=i&&o>n-i}function en(e,t,n){if(t._transitionKey)return t._transitionKey;switch(t.type){case"point":if(t.pointId)return"p:"+t.pointId;if("streaming"===e.runtimeMode&&t.datum){const n=e.getX(t.datum),o=e.getY(t.datum);if(e.getCategory)return`p:${e.getCategory(t.datum)}:${n}:${o}`;if(null!=n&&null!=o)return`p:${n}:${o}`}return"p:"+n;case"glyph":return t.pointId?"g:"+t.pointId:"g:"+n;case"rect":return`r:${t.group||""}:${t.datum?.binStart??t.datum?.category??n}`;case"heatcell":return`h:${t.x}_${t.y}`;case"candlestick":return null==t.datum?"c:"+n:"c:"+e.getX(t.datum);case"line":return"l:"+(t.group||"_default");case"area":return"a:"+(t.group||"_default");default:return null}}function tn(e){return e?null!=e.opacity?e.opacity:null!=e.fillOpacity?e.fillOpacity:1:1}function nn(e,t,n,o,i,r){const s=[];for(const i of e){const e=n(i),r=o(i);Number.isFinite(e)&&Number.isFinite(r)&&s.push({px:t.x(e),py:t.y(r),rawY:r,d:i})}s.sort((e,t)=>e.px-t.px);const a=Array(s.length),l=Array(s.length),c=Array(s.length);for(let e=0;s.length>e;e++){const t=s[e];a[e]=[t.px,t.py],l[e]=t.rawY,c[e]=t.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function on(e,t,n,o,i,r,s,a){const l=[];for(const r of e){const e=n(r),s=o(r);if(!Number.isFinite(e)||!Number.isFinite(s))continue;const c=t.x(e),u=a?a(r):i;l.push({px:c,topY:t.y(s),botY:t.y(u),rawY:s})}l.sort((e,t)=>e.px-t.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let e=0;l.length>e;e++){const t=l[e];c[e]=[t.px,t.topY],u[e]=[t.px,t.botY],d[e]=t.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:e,group:s}}function rn(e,t,n,o){const i=new Map;if("silhouette"===o)for(const o of e){let e=0;for(const i of t)e+=n(i,o)||0;i.set(o,-e/2)}else if("wiggle"===o){e.length>0&&i.set(e[0],0);for(let o=1;e.length>o;o++){const r=e[o-1],s=e[o];let a=0,l=0,c=0;for(const e of t){const t=n(e,s)||0;a+=(2*c+t)*(t-(n(e,r)||0)),l+=t,c+=t}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):0))}if(e.length>0){let o=0;for(const r of e){let e=0;for(const o of t)e+=n(o,r)||0;o+=(i.get(r)??0)+e/2}const r=o/e.length;for(const t of e)i.set(t,(i.get(t)??0)-r)}}else for(const t of e)i.set(t,0);return i}function sn(e,t,n,o,i,r,s){const a=n(e),l=o(e);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:t.x(a),y:t.y(l),r:i,style:r,datum:e};return void 0!==s&&(c.pointId=s),c}function an(e,t,n,o,i,r,s,a){const l=n(e),c=o(e);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:t.x(l),y:t.y(c),size:i,symbolType:r,style:s,datum:e};return void 0!==a&&(u.pointId=a),u}function ln(e,t,n,o,i,r,s){return{type:"rect",x:e,y:t,w:n,h:o,style:i,datum:r,group:s}}function cn(e,t,n,o,i,r,s){const a={type:"heatcell",x:e,y:t,w:n,h:o,fill:i,datum:r};return s?.showValues&&(a.showValues=!0,a.value=s.value,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function un(e,t,n,o){return"function"==typeof t.style?t.style(o||{},n):t.style&&"object"==typeof t.style?t.style:e.resolveBoundsStyle(n,o)}function dn(e,t,n,o){if(!e.scales)return null;const i=[],r=[];for(const n of t){const t=e.getX(n);if(!Number.isFinite(t))continue;const s=o.getTop(n),a=o.getBottom(n);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const l=e.scales.x(t),c=e.scales.y(s),u=e.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...e.config.curve&&"linear"!==e.config.curve&&{curve:e.config.curve},style:un(e,o,n,t[0]),datum:t,group:n,interactive:o.interactive}}function hn(e){const t=[],n=[];if(!e)return{perSeries:t,aggregate:n};for(const o of e)o.perSeries?t.push(o):n.push(o);return{perSeries:t,aggregate:n}}function fn(e,t,n){const o=[];for(const i of n){const n=dn(e,t,"__ribbon_aggregate",i);n&&o.push(n)}return o}function pn(e,t,n,o){const i=[];for(const r of o){const o=dn(e,t,n,r);o&&i.push(o)}return i}function gn(e,t){if(!e)return{};if(!t||0===t.length)return e;const n=[];for(const o of t){if("band"!==o.kind)continue;const t=o.getTop(e),i=o.getBottom(e);Number.isFinite(i)&&Number.isFinite(t)&&n.push({y0:i,y1:t})}return 0===n.length?e:{...e,band:n[0],bands:n}}function yn(e,t,n,o){if(!e.config.pointStyle)return;const i=o??e.getY;for(const o of t){const t=e.resolveGroupColor(o.key);for(const r of o.data){let o=e.config.pointStyle(r);!o.fill&&t&&(o={...o,fill:t});const s=o.r??3,a=e.getPointId?e.getPointId(r)+"":void 0,l=sn(r,e.scales,e.getX,i,s,o,a);l&&n.push(l)}}}function mn(e){return"threshold"===e.type&&"string"==typeof e.color&&"number"==typeof e.value}function xn(e){return Ie(e)}var bn=require("d3-shape"),vn={circle:bn.symbolCircle,square:bn.symbolSquare,triangle:bn.symbolTriangle,diamond:bn.symbolDiamond,star:bn.symbolStar,cross:bn.symbolCross,wye:bn.symbolWye},wn=["circle","triangle","diamond","star","square","chevron","cross","wye"];function kn(e,t,n){if(n)return n;const o=e??"circle";return"chevron"===o?function(e){const t=1.5*Sn(e),n=.92*t;return`M0,${-t}L${n},${(.78*t).toFixed(3)}L0,${(.28*t).toFixed(3)}L${-n},${(.78*t).toFixed(3)}Z`}(t):(0,bn.symbol)(vn[o]??bn.symbolCircle,Math.max(1,t))()??""}function Sn(e){return Math.sqrt(Math.max(1,e)/Math.PI)}function An(e,t){const n=new Map;let o=0;return i=>{const r=e(i)+"",s=t?.[r];if(s)return s;let a=n.get(r);return a||(a=wn[o%wn.length],o++,n.set(r,a)),a}}var Mn=new Map;function _n(e,t,n){const o=n.config.areaStyle?.(t);return o&&(e.style=o),e}function Pn(e,t,n,o,i){const r=new Map;for(const s of e){const e=t(s),a=n(s);if(null==e||null==a||Number.isNaN(e)||Number.isNaN(a))continue;const l=Math.floor(e/o)*o;let c=r.get(l);if(c||(c={start:l,end:l+o,total:0,categories:new Map},r.set(l,c)),c.total+=a,i){const e=i(s);c.categories.set(e,(c.categories.get(e)||0)+a)}}return r}function jn(e){if("production"===process.env.NODE_ENV)return;const{label:t,nodes:n,overlays:o,warned:i}=e;Cn(o)&&0===n.length&&Rn(i,"overlay-only",`[semiotic] ${t} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),n.length>0&&n.every(e=>null==e.datum)&&Rn(i,"null-datums",`[semiotic] ${t} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Cn(e){return null!=e&&!1!==e&&""!==e&&(!Array.isArray(e)||e.some(Cn))}function Rn(e,t,n){e.has(t)||(e.add(t),console.warn(n))}function Ln(e,t,n,o){const i=function(e){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Custom layout threw."};if("string"==typeof e)return{name:"Error",message:e};if(null==e)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:e+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(t),r="network"===e?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:e,source:r,message:`Semiotic ${e} ${r} failed: ${i.message}`,error:i,recovery:n?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:n,affectedRevision:o}}function Tn(e,t){const n="function"==typeof e?e:n=>n[e||t];return e=>{const t=n(e);return null==t?NaN:+t}}function In(e){const t=[],n=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode,o=Tn(n&&e.valueAccessor||e.yAccessor,n?"value":"y");if(e.boundsAccessor){const n=zt(e.boundsAccessor,"bounds");t.push({kind:"bounds",getTop:e=>{const t=o(e);if(!Number.isFinite(t))return NaN;const i=n(e);return Number.isFinite(i)&&0!==i?t+i:t},getBottom:e=>{const t=o(e);if(!Number.isFinite(t))return NaN;const i=n(e);return Number.isFinite(i)&&0!==i?t-i:t},style:e.boundsStyle,perSeries:!0,interactive:!1})}if(e.band){const n=Array.isArray(e.band)?e.band:[e.band];for(const e of n)t.push({kind:"band",getTop:Tn(e.y1Accessor,"y1"),getBottom:Tn(e.y0Accessor,"y0"),style:e.style,perSeries:!1!==e.perSeries,interactive:!0===e.interactive})}return t}var $n=require("d3-scale");function On(e,t){return t?[t[0]??e[0],t[1]??e[1]]:e}function zn(e,t,n){if("log"===e){const e=[Math.max(t[0],1e-6),Math.max(t[1],1e-6)];return(0,$n.scaleLog)().domain(e).range(n).clamp(!0)}return"symlog"===e?(0,$n.scaleSymlog)().domain(t).range(n):"time"===e?(0,$n.scaleTime)().domain([new Date(t[0]),new Date(t[1])]).range(n):(0,$n.scaleLinear)().domain(t).range(n)}function Dn(e,t,n){t>e.capacity&&(e.resize(t),n&&t>n.capacity&&n.resize(t))}function Fn(e,t){const n=new It(e.capacity);return e.forEach(()=>n.push(t)),n}function En(e,t,n,o){const i=e.push(t);return n&&n.push(o),i}function Nn(e,t,n){if(!t||0===t.size)return;const o=new Set;if(e.forEach((e,t)=>{n(e)&&o.add(t)}),0===o.size)return;const i=t.toArray();t.clear();for(let e=0;i.length>e;e++)o.has(e)||t.push(i[e])}var Bn=new WeakMap;function Wn(){return this.updateResults.last}function Yn(){return this.updateResults.last}function qn(e){return this.updateResults.subscribe(e)}function Xn(e){this.config.layoutSelection=e}function Hn(){Bn.set(this,!0)}function Gn(){const e=!0===Bn.get(this);return Bn.delete(this),e}function Vn(e){Object.assign(e.prototype,{getLastUpdateResult:Wn,getUpdateSnapshot:Yn,subscribeUpdateResult:qn,setLayoutSelection:Xn,markStylePaintPending:Hn,consumeStylePaintPending:Gn})}var Un={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 Kn(e,t){const n={...e};for(const e of t)n[Un[e]]++;return n}function Zn(e,t,n){const o=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:o,revisions:Kn(n,o)}}var Qn=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=Zn({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){const n=Zn(e,t,this.revisions);this.revisions=n.revisions,this.latest=n;for(const e of[...this.listeners])e();return n}},Jn=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],eo=["scene-style","data-paint","accessibility","evidence"],to=(e,t)=>({retainedData:e,invalidations:t}),no=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],oo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],io=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ro=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],so=["scene-geometry","data-paint","accessibility","evidence"],ao=["scene-style","data-paint","accessibility","evidence"],lo=[],co={chartType:to("rebuild",no),runtimeMode:to("rebuild",no),xAccessor:to("rebuild",no),yAccessor:to("rebuild",no),timeAccessor:to("rebuild",no),valueAccessor:to("rebuild",no),y0Accessor:to("rebuild",no),boundsAccessor:to("rebuild",no),band:to("rebuild",no),openAccessor:to("rebuild",no),highAccessor:to("rebuild",no),lowAccessor:to("rebuild",no),closeAccessor:to("rebuild",no),candlestickRangeMode:to("rebuild",no),accessorRevision:to("rebuild",no),groupAccessor:to("rebuild",oo),categoryAccessor:to("rebuild",oo),lineDataAccessor:to("rebuild",oo),colorAccessor:to("rebuild",ao),sizeAccessor:to("rebuild",so),symbolAccessor:to("rebuild",so),pointIdAccessor:to("rebuild",so),xScaleType:to("preserve",io),yScaleType:to("preserve",io),xExtent:to("preserve",io),yExtent:to("preserve",io),extentPadding:to("preserve",io),scalePadding:to("preserve",io),axisExtent:to("preserve",io),yAxisExtent:to("preserve",io),binSize:to("preserve",io),normalize:to("preserve",io),heatmapAggregation:to("preserve",io),heatmapXBins:to("preserve",io),heatmapYBins:to("preserve",io),arrowOfTime:to("preserve",ro),baseline:to("preserve",ro),stackOrder:to("preserve",ro),sizeRange:to("preserve",ro),curve:to("preserve",ro),areaGroups:to("preserve",ro),customLayout:to("preserve",ro),layoutConfig:to("preserve",ro),layoutMargin:to("preserve",ro),symbolMap:to("preserve",so),showValues:to("preserve",so),heatmapValueFormat:to("preserve",so),lineStyle:to("preserve",ao),pointStyle:to("preserve",ao),areaStyle:to("preserve",ao),barStyle:to("preserve",ao),swarmStyle:to("preserve",ao),waterfallStyle:to("preserve",ao),candlestickStyle:to("preserve",ao),boundsStyle:to("preserve",ao),gradientFill:to("preserve",ao),lineGradient:to("preserve",ao),semanticLineStops:to("preserve",ao),colorScheme:to("preserve",ao),themeCategorical:to("preserve",ao),themeSemantic:to("preserve",ao),themeSequential:to("preserve",ao),themeDiverging:to("preserve",ao),barColors:to("preserve",ao),decay:to("preserve",ao),pulse:to("preserve",ao),staleness:to("preserve",ao),layoutSelection:to("preserve",ao),annotations:to("preserve",["overlay","accessibility","evidence"]),windowSize:to("preserve",lo),windowMode:to("preserve",lo),maxCapacity:to("preserve",lo),clock:to("preserve",lo),transition:to("preserve",lo),introAnimation:to("preserve",lo),onLayoutError:to("preserve",lo)},uo=to("preserve",ro),ho=class{constructor(){this.tracker=new Qn}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Jn)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},eo):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const n=new Set;for(const o of e){const e=co[o]??uo;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}},fo=require("d3-quadtree"),po=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(e,t){if("scatter"!==e&&"bubble"!==e&&"custom"!==e)return void this.clear();let n=0,o=0;for(const e of t)"point"===e.type&&(n++,e.r>o&&(o=e.r));if(this.maxRadius=o,500>=n)return void(this.tree=null);const i=Array(n);let r=0;for(const e of t)"point"===e.type&&(i[r++]=e);this.tree=(0,fo.quadtree)().x(e=>e.x).y(e=>e.y).addAll(i)}},go=class e{constructor(e){if(this.xExtent=new $t,this.yExtent=new $t,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 ho,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 po,this._lastBoundedInsertsRef=null,this.applyPulse=(e,t,n)=>!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,n,o,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=e.color??"rgba(255,255,255,0.6)",a=e.glowRadius??4;let l=!1;const c=i??(()=>{const e=new Map;for(let t=0;n.length>t;t++)e.set(n[t],t);return e})();for(const n of t){if("line"===n.type)continue;if("area"===n.type){const t=Array.isArray(n.datum)?n.datum:[n.datum];let i=0,a=!1;for(const n of t){const t=c.get(n);if(null==t)continue;a=!0;const s=o.get(t);if(null==s)continue;const l=Zt(e,s,r);l>i&&(i=l)}a&&(l=Qt(n,i,s)||l);continue}const t=c.get(n.datum);if(null==t)continue;const i=o.get(t);l=Qt(n,null==i?0:Zt(e,i,r),s,a)||l}return l}(this.config.pulse,e,t,this.timestampBuffer,this.getDatumIndexMap(t),n),this.config=e,this.buffer=new It(e.windowSize),this.growingCap=e.windowSize,["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode?(this.getX=zt(e.timeAccessor||e.xAccessor,"time"),this.getY=zt(e.valueAccessor||e.yAccessor,"value")):(this.getX=zt(e.xAccessor,"x"),this.getY=zt(e.yAccessor,"y")),this.getGroup=Ft(e.groupAccessor),this.getCategory=Ft(e.categoryAccessor),this.getSize=e.sizeAccessor?zt(e.sizeAccessor,"size"):void 0,this.getColor=Ft(e.colorAccessor),this.getSymbol=Ft(e.symbolAccessor),this.getY0=e.y0Accessor?zt(e.y0Accessor,"y0"):void 0,this.resolvedRibbons=In(e),this.getPointId=Ft(e.pointIdAccessor),"candlestick"===e.chartType){const t=null!=e.openAccessor,n=null!=e.closeAccessor;this.getOpen=t?zt(e.openAccessor,"open"):void 0,this.getHigh=zt(e.highAccessor,"high"),this.getLow=zt(e.lowAccessor,"low"),this.getClose=n?zt(e.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!n}e.pulse&&(this.timestampBuffer=new It(e.windowSize))}currentTime(){return this.config.clock?.()??Vt()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Fn(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(e)),void this.yExtent.push(this.getLow(e));this.yExtent.push(this.getY(e)),this.getY0&&this.yExtent.push(this.getY0(e));for(const t of this.resolvedRibbons){const n=t.getTop(e),o=t.getBottom(e);Number.isFinite(n)&&this.yExtent.push(n),Number.isFinite(o)&&this.yExtent.push(o)}}evictDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(e)),void this.yExtent.evict(this.getLow(e));this.yExtent.evict(this.getY(e)),this.getY0&&this.yExtent.evict(this.getY0(e));for(const t of this.resolvedRibbons){const n=t.getTop(e),o=t.getBottom(e);Number.isFinite(n)&&this.yExtent.evict(n),Number.isFinite(o)&&this.yExtent.evict(o)}}rebuildYExtent(){this.yExtent.clear();for(const e of this.buffer)this.pushDatumYExtent(e)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const e of this.buffer)this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e)}ingest(e){if(e.bounded&&this._lastBoundedInsertsRef===e.inserts)return this.updateResults.recordNoop("replace"),!1;const t=this.currentTime();if(this.lastIngestTime=t,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,e.bounded){this._lastBoundedInsertsRef=e.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const n=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=n?zt(this.config.timeAccessor||this.config.xAccessor,"time"):zt(this.config.xAccessor,"x"),this.xIsDate=!1,e.inserts.length>0){const t=e.inserts[0],n=this.config.xAccessor,o="function"==typeof n?n(t):t[n||"x"],i=o instanceof Date,r="string"==typeof o&&Number.isFinite(Wt(o));if(this.xIsDate=i||r,r){const e="string"==typeof n?n:void 0;this.getX=e?t=>Yt(t[e]):e=>Yt(n(e))}}Dn(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const n of e.inserts)En(this.buffer,n,this.timestampBuffer,t),this.xExtent.push(this.getX(n)),this.pushDatumYExtent(n)}else for(const n of e.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const e=this.config.maxCapacity??1e5;e>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,e),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${e}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const e=En(this.buffer,n,this.timestampBuffer,t);this.xExtent.push(this.getX(n)),this.pushDatumYExtent(n),null!=e&&(this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e))}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}computeScene(e){const{config:t,buffer:n}=this,o=this.scales,i=this.lastLayout;if(!this.needsFullRebuild&&!t.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==e.width||this.lastLayout.height!==e.height))return void this.remapScene(e);this.xExtent.dirty&&this.xExtent.recalculate(n,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=On(this.xExtent.extent,t.xExtent),l=On(s,t.yExtent);const c=!(!(u=t.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(t.yAxisExtent??t.axisExtent);if("stackedarea"===t.chartType&&!c&&n.size>0){const e=function(e){const{config:t,groups:n,getX:o,getY:i}=e,r="exact"===(t.yAxisExtent??t.axisExtent);if(t.normalize){const n=[0,r?1:1+t.extentPadding];return{yDomain:n,stackExtentCache:{key:`${e.bufferSize}:${e.ingestVersion}:norm`,yDomain:n}}}const s=`${e.bufferSize}:${e.ingestVersion}:${t.baseline??"zero"}:${t.stackOrder??"key"}`;if(e.stackExtentCache&&e.stackExtentCache.key===s)return{yDomain:e.stackExtentCache.yDomain,stackExtentCache:e.stackExtentCache};const a=new Map,l=new Set;let c=0;const u=new Map,d=new Map;for(const e of n){const t=new Map;let n=0;for(const r of e.data){const e=o(r),s=i(r);if(!Number.isFinite(e)||!Number.isFinite(s))continue;t.set(e,(t.get(e)||0)+s),l.add(e),n+=s;const a=(u.get(e)||0)+s;u.set(e,a),a>c&&(c=a)}a.set(e.key,t),d.set(e.key,n)}const h=t.stackOrder??"key",f=(e,t)=>t>e?-1:e>t?1:0;let p,g;if("input"===h)p=n.map(e=>e.key);else if("insideOut"===h){const e=[...n].map(e=>e.key).sort((e,t)=>{const n=(d.get(t)??0)-(d.get(e)??0);return 0!==n?n:f(e,t)}),t=[],o=[];let i=0,r=0;for(const n of e)r>i?(t.push(n),i+=d.get(n)??0):(o.push(n),r+=d.get(n)??0);p=[...o.reverse(),...t]}else p="asc"===h?n.map(e=>e.key).sort((e,t)=>{const n=(d.get(e)??0)-(d.get(t)??0);return 0!==n?n:f(e,t)}):"desc"===h?n.map(e=>e.key).sort((e,t)=>{const n=(d.get(t)??0)-(d.get(e)??0);return 0!==n?n:f(e,t)}):n.map(e=>e.key).sort(f);if("wiggle"===t.baseline||"silhouette"===t.baseline){const e=Array.from(l).sort((e,t)=>e-t),n=rn(e,p,(e,t)=>a.get(e)?.get(t)||0,t.baseline);let o=1/0,i=-1/0;for(const t of e){const e=n.get(t)??0,r=u.get(t)??0;o>e&&(o=e),e+r>i&&(i=e+r)}Number.isFinite(o)&&Number.isFinite(i)||(o=0,i=0);const s=i-o,c=r?0:s>0?s*t.extentPadding:1;g=[o-c,i+c]}else if("diverging"===t.baseline){const e=Array.from(l).sort((e,t)=>e-t),[n,o]=function(e,t,n){let o=0,i=0;for(const r of e){let e=0,s=0;for(const o of t){const t=n(o,r)||0;0>t?s+=t:e+=t}o>s&&(o=s),e>i&&(i=e)}return[o,i]}(e,p,(e,t)=>a.get(e)?.get(t)||0),i=o-n,s=r?0:i>0?i*t.extentPadding:1;g=[n-s,o+s]}else g=[0,c+(r?0:c>0?c*t.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({config:t,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:n.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=e.yDomain,this._stackExtentCache=e.stackExtentCache}else"bar"===t.chartType&&t.binSize&&!c&&n.size>0?l=function(e,t,n,o,i,r,s){const[,a]=function(e,t,n,o,i){const r=Pn(e,t,n,o,i);if(0===r.size)return[0,0];let s=0;for(const e of r.values())e.total>s&&(s=e.total);return[0,s]}(e,t,n,o,i);return[0,s?a:a+a*r]}(n,this.getX,this.getY,t.binSize,this.getCategory,t.extentPadding,d):"waterfall"===t.chartType&&!c&&n.size>0?l=function(e,t,n,o){const[i,r]=function(e,t){let n=0,o=0,i=0;for(const r of e){const e=t(r);null==e||Number.isNaN(e)||(i+=e,n>i&&(n=i),i>o&&(o=i))}return[n,o]}(e,t),s=r-i,a=o?0:s>0?s*n:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(n,this.getY,t.extentPadding,d):c||l[0]===1/0||(l=function(e,t,n){if(!n.length)return e;let[o,i]=e;for(const e of t)for(const t of n){const n=t.getTop(e),r=t.getBottom(e);Number.isFinite(n)&&(o>n&&(o=n),n>i&&(i=n)),Number.isFinite(r)&&(o>r&&(o=r),r>i&&(i=r))}return[o,i]}(l,r,this.resolvedRibbons),l=function(e,t){const n=e[1]-e[0],o=t.exactMode?0:n>0?n*t.extentPadding:1,i=[null!=t.userMin?e[0]:e[0]-o,null!=t.userMax?e[1]:e[1]+o];return"log"!==t.yScaleType||i[0]>0||0>=t.dataYDomain[0]||t.exactMode||null==t.userMin&&(i[0]=t.dataYDomain[0]/(1+t.extentPadding)),i}(l,{exactMode:d,extentPadding:t.extentPadding,userMin:t.yExtent?.[0],userMax:t.yExtent?.[1],yScaleType:t.yScaleType,dataYDomain:s}));l=function(e,t,n){if(!t||n)return e;const o=t[0],i=t[1];return null==o&&null==i?e:[null!=o?o:e[0],null!=i?i:e[1]]}(l,t.yExtent,!!c),({xDomain:a,yDomain:l}=function(e,t,n){let o=e,i=t;if(o[0]===1/0||o[1]===-1/0)if("time"===n){const e=Date.now();o=[e-864e5,e]}else o=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:o,yDomain:i}}(a,l,t.xScaleType)),this.scales=function(e){const{config:t,layout:n,xDomain:o,yDomain:i}=e,r="streaming"===t.runtimeMode,s=Math.max(0,Math.min(t.scalePadding||0,Math.min(n.width,n.height)/2-1));if(r){if("x"==("up"===(a=t.arrowOfTime)||"down"===a?"y":"x")){const e="right"===t.arrowOfTime?[s,n.width-s]:[n.width-s,s];return{x:(0,$n.scaleLinear)().domain(o).range(e),y:zn(t.yScaleType,i,[n.height-s,s])}}const e="down"===t.arrowOfTime?[s,n.height-s]:[n.height-s,s];return{x:zn(t.yScaleType,i,[s,n.width-s]),y:(0,$n.scaleLinear)().domain(o).range(e)}}var a;return{x:zn(t.xScaleType,o,[s,n.width-s]),y:zn(t.yScaleType,i,[n.height-s,s])}}({config:t,layout:e,xDomain:a,yDomain:l}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(e,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.lastLayout=i):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=h,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:e.width,height:e.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(e){const t=e.width/this.lastLayout.width,n=e.height/this.lastLayout.height;for(const e of this.scene)switch(e.type){case"line":for(const o of e.path)o[0]*=t,o[1]*=n;break;case"area":for(const o of e.topPath)o[0]*=t,o[1]*=n;for(const o of e.bottomPath)o[0]*=t,o[1]*=n;e.clipRect&&(e.clipRect={x:e.clipRect.x*t,y:e.clipRect.y*n,width:e.clipRect.width*t,height:e.clipRect.height*n}),e.strokeColorBands&&(e.strokeColorBands=e.strokeColorBands.map(e=>({...e,y:e.y*n,height:e.height*n})));break;case"point":case"glyph":e.x*=t,e.y*=n;break;case"rect":case"heatcell":e.x*=t,e.y*=n,e.w*=t,e.h*=n;break;case"candlestick":e.x*=t,e.openY*=n,e.closeY*=n,e.highY*=n,e.lowY*=n}const o=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=zn,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(e.width,e.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,o,r[0]>r[1]?[e.width-l,l]:[l,e.width-l]),y:a(this.config.yScaleType,i,c?[l,e.height-l]:[e.height-l,l])},this.lastLayout={width:e.width,height:e.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(e,t){const{config:n,scales:o}=this;if(!o)return[];if(n.customLayout){const i={data:t,scales:o,dimensions:{width:e.width,height:e.height,margin:n.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:n.themeSemantic??{},categorical:n.themeCategorical??fe},resolveColor:(e,t)=>{const o=this.resolveGroupColor(e);if(o)return o;const i=this.resolveLineStyle(e,t);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:n.themeSemantic?.primary??"#4e79a7"},config:n.layoutConfig??{},selection:n.layoutSelection??null};let r;try{r=n.customLayout(i)}catch(e){const t=null!==this.lastCustomLayoutResult,o=Ln("xy",e,t,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",e);try{n.onLayoutError?.(o)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return t?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 e of s)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(s,n.layoutSelection??null)}return jn({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===t.length)return[];const i={scales:o,config:n,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(e,t)=>this.resolveLineStyle(e,t),resolveAreaStyle:(e,t)=>this.resolveAreaStyle(e,t),resolveBoundsStyle:(e,t)=>this.resolveBoundsStyle(e,t),resolveColorMap:e=>this.resolveColorMap(e),resolveGroupColor:e=>this.resolveGroupColor(e),groupData:e=>this.groupData(e),barCategoryCache:this._barCategoryCache};switch(n.chartType){case"line":return function(e,t){const n=e.groupData(t),o=[],i=e.config.annotations?.filter(mn).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(e.ribbons&&e.ribbons.length>0){const{perSeries:i,aggregate:r}=hn(e.ribbons);if(r.length>0&&o.push(...fn(e,t,r)),i.length>0)for(const t of n)o.push(...pn(e,t.data,t.key,i))}for(const t of n){const n=e.resolveLineStyle(t.key,t.data[0]),r=nn(t.data,e.scales,e.getX,e.getY,n,t.key);i&&i.length>0&&(r.colorThresholds=i),e.config.curve&&"linear"!==e.config.curve&&(r.curve=e.config.curve),e.config.lineGradient&&(r.strokeGradient=e.config.lineGradient),o.push(r)}return yn(e,n,o),o}(i,t);case"area":return function(e,t){const n=e.groupData(t),o=[];if(e.ribbons&&e.ribbons.length>0){const{perSeries:i,aggregate:r}=hn(e.ribbons);if(r.length>0&&o.push(...fn(e,t,r)),i.length>0)for(const t of n)o.push(...pn(e,t.data,t.key,i))}const i=e.scales.y.domain(),r=i[0],s=e.config.semanticLineStops?.filter(e=>Number.isFinite(e.offset)).map(e=>({value:i[0]+Math.max(0,Math.min(1,e.offset))*(i[1]-i[0]),color:e.color,thresholdType:"greater"})).sort((e,t)=>e.value-t.value),a=s&&s.length>0?(()=>{const t=s.reduce((e,t)=>(e.at(-1)?.value===t.value?e[e.length-1]=t:e.push(t),e),[]),n=[{from:i[0],to:t[0].value}];for(let e=0;t.length>e;e++)n.push({from:t[e].value,to:t[e+1]?.value??i[1],color:t[e].color});return n.map(({from:t,to:n,color:o})=>{const i=e.scales.y(t),r=e.scales.y(n);return{y:Math.min(i,r),height:Math.abs(r-i),color:o}}).filter(e=>e.height>0)})():void 0,l=e.getY0?t=>{const n=e.getY0(t);return null==n?r:n}:void 0;for(const t of n){const n=e.resolveAreaStyle(t.key,t.data[0]),i=on(t.data,e.scales,e.getX,e.getY,r,n,t.key,l),c=xn(e.config.gradientFill);c&&(i.fillGradient=c),e.config.curve&&"linear"!==e.config.curve&&(i.curve=e.config.curve),e.config.lineGradient&&(i.strokeGradient=e.config.lineGradient),s&&s.length>0&&(i.colorThresholds=s,i.strokeColorBands=a),o.push(i)}return yn(e,n,o),o}(i,t);case"mixed":return function(e,t){const n=e.groupData(t),o=[],i=e.config.areaGroups||new Set;if(e.ribbons&&e.ribbons.length>0){const{perSeries:i,aggregate:r}=hn(e.ribbons);if(r.length>0&&o.push(...fn(e,t,r)),i.length>0)for(const t of n)o.push(...pn(e,t.data,t.key,i))}const r=e.scales.y.domain()[0],s=e.getY0?t=>{const n=e.getY0(t);return null==n?r:n}:void 0;for(const t of n)if(i.has(t.key)){const n=e.resolveAreaStyle(t.key,t.data[0]),i=on(t.data,e.scales,e.getX,e.getY,r,n,t.key,s),a=xn(e.config.gradientFill);a&&(i.fillGradient=a),e.config.curve&&"linear"!==e.config.curve&&(i.curve=e.config.curve),e.config.lineGradient&&(i.strokeGradient=e.config.lineGradient),o.push(i)}else{const n=e.resolveLineStyle(t.key,t.data[0]),i=nn(t.data,e.scales,e.getX,e.getY,n,t.key);e.config.curve&&"linear"!==e.config.curve&&(i.curve=e.config.curve),e.config.lineGradient&&(i.strokeGradient=e.config.lineGradient),o.push(i)}return yn(e,n,o),o}(i,t);case"stackedarea":return function(e,t){const n=e.groupData(t),o=e.config.stackOrder??"key",i=()=>n.sort((e,t)=>t.key>e.key?-1:e.key>t.key?1:0);if("input"===o);else if("key"===o)i();else if("asc"===o||"desc"===o||"insideOut"===o){const t=new Map;for(const o of n){let n=0;for(const t of o.data){const o=e.getX(t),i=e.getY(t);Number.isFinite(o)&&Number.isFinite(i)&&(n+=i)}t.set(o.key,n)}const i=(e,t)=>t>e?-1:e>t?1:0;if("asc"===o)n.sort((e,n)=>{const o=(t.get(e.key)??0)-(t.get(n.key)??0);return 0!==o?o:i(e.key,n.key)});else if("desc"===o)n.sort((e,n)=>{const o=(t.get(n.key)??0)-(t.get(e.key)??0);return 0!==o?o:i(e.key,n.key)});else{const e=[...n].sort((e,n)=>{const o=(t.get(n.key)??0)-(t.get(e.key)??0);return 0!==o?o:i(e.key,n.key)}),o=[],r=[];let s=0,a=0;for(const n of e)a>s?(o.push(n),s+=t.get(n.key)??0):(r.push(n),a+=t.get(n.key)??0);n.length=0,n.push(...r.reverse(),...o)}}else i();const r=e.config.curve&&"linear"!==e.config.curve?e.config.curve:void 0,s=e.config.normalize?"zero":e.config.baseline??"zero",{nodes:a,stackedTops:l}=function(e,t,n,o,i,r,s,a="zero"){const l=new Set;for(const t of e)for(const e of t.data){const t=n(e);Number.isFinite(t)&&l.add(t)}const c=Array.from(l).sort((e,t)=>e-t),u=new Map;for(const t of e){const e=new Map;for(const i of t.data){const t=n(i),r=o(i);Number.isFinite(t)&&Number.isFinite(r)&&e.set(t,(e.get(t)||0)+r)}u.set(t.key,e)}let d;if(r){d=new Map;for(const t of c){let n=0;for(const o of e)n+=u.get(o.key)?.get(t)||0;d.set(t,n||1)}}const h=rn(c,e.map(e=>e.key),(e,t)=>u.get(e)?.get(t)||0,a),f="diverging"===a&&!r,p=[],g=new Map,y=new Map,m=new Map,x=new Map;for(const e of c)y.set(e,h.get(e)??0),m.set(e,0),x.set(e,0);for(const n of e){const e=u.get(n.key),o=new Map;let a=[],l=[];const h=()=>{if(a.length>=2){const e={type:"area",topPath:a,bottomPath:l,style:i(n.key,n.data[0]),datum:n.data,group:n.key};s&&(e.curve=s),p.push(e)}a=[],l=[]};for(const n of c){const i=e.has(n);let s,c,u=i?e.get(n):0;if(r&&i&&(u/=d.get(n)),!i||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(n),c=s+u,m.set(n,c)):(s=x.get(n),c=s+u,x.set(n,c)):(s=y.get(n),c=s+u,y.set(n,c));const p=t.x(n);l.push([p,t.y(s)]),a.push([p,t.y(c)]),o.set(n,c)}h(),g.set(n.key,o)}return{nodes:p,stackedTops:g}}(n,e.scales,e.getX,e.getY,(t,n)=>e.resolveAreaStyle(t,n),e.config.normalize,r,s),c=a;if(e.config.pointStyle){const t=new WeakMap;for(const o of n){const n=l.get(o.key);if(n)for(const i of o.data){const o=e.getX(i),r=e.getY(i);null==o||Number.isNaN(o)||null==r||Number.isNaN(r)||!n.has(o)||t.set(i,n.get(o))}}const o=n=>t.get(n)??e.getY(n);yn(e,n,c,o)}return c}(i,t);case"scatter":case"bubble":return function(e,t){const n=[],o="bubble"===e.config.chartType?10:5,i=e.config.sizeRange||[3,15];let r=null;if(e.getSize&&!e.config.pointStyle){const n=t.map(t=>e.getSize(t)).filter(e=>null!=e&&!Number.isNaN(e));if(n.length>0){let e=1/0,t=-1/0;for(const o of n)e>o&&(e=o),o>t&&(t=o);r=n=>e===t?(i[0]+i[1])/2:i[0]+(n-e)/(t-e)*(i[1]-i[0])}}const s=e.getColor?e.resolveColorMap(t):null,a=e.config.themeSemantic?.primary||"#4e79a7",l=e.getSymbol,c=l?An(l,e.config.symbolMap):null;for(const i of t){let t=e.config.pointStyle?e.config.pointStyle(i):{fill:a,opacity:.8},l=t.r||o;if(r&&e.getSize){const t=e.getSize(i);null==t||Number.isNaN(t)||(l=r(t))}if(s&&e.getColor&&!t.fill){const n=e.getColor(i);n&&s.has(n)&&(t={...t,fill:s.get(n)})}const u=e.getPointId?e.getPointId(i)+"":void 0;if(c){const o=c(i),r=an(i,e.scales,e.getX,e.getY,Math.PI*l*l,o,t,u);r&&n.push(r)}else{const o=sn(i,e.scales,e.getX,e.getY,l,t,u);o&&n.push(o)}}return n}(i,t);case"heatmap":return function(e,t,n){if(e.config.heatmapAggregation)return function(e,t,n){const o=Math.max(1,Math.floor(e.config.heatmapXBins??20)),i=Math.max(1,Math.floor(e.config.heatmapYBins??20)),r=e.config.heatmapAggregation??"count",s=zt(e.config.valueAccessor,"value");if(!e.scales||0===t.length)return[];const[a,l]=e.scales.x.domain(),[c,u]=e.scales.y.domain(),d=(l-a||1)/o,h=(u-c||1)/i,f=o*i;if(f>1e6)return[];const p=new Int32Array(f),g=new Float64Array(f);for(let n=0;t.length>n;n++){const r=t[n],l=e.getX(r),u=e.getY(r);if(!isFinite(l)||!isFinite(u))continue;const f=Math.min(Math.floor((l-a)/d),o-1),y=Math.min(Math.floor((u-c)/h),i-1);if(0>f||0>y)continue;const m=y*o+f;p[m]++;const x=s(r);g[m]+=isFinite(x)?x:0}let y=1/0,m=-1/0;for(let e=0;f>e;e++){if(0===p[e])continue;let t;switch(r){case"sum":t=g[e];break;case"mean":t=g[e]/p[e];break;default:t=p[e]}y>t&&(y=t),t>m&&(m=t)}if(!isFinite(y))return[];const x=m-y||1,b=n.width/o,v=n.height/i,w=e.config.showValues,k=e.config.heatmapValueFormat,S=[];for(let t=0;i>t;t++){const n=t*o;for(let s=0;o>s;s++){const o=n+s;if(0===p[o])continue;let l;switch(r){case"sum":l=g[o];break;case"mean":l=g[o]/p[o];break;default:l=p[o]}const u=(l-y)/x,f={xi:s,yi:t,value:l,count:p[o],sum:g[o],xCenter:a+(s+.5)*d,yCenter:c+(t+.5)*h,agg:r};S.push(_n(cn(s*b,(i-1-t)*v,b,v,`rgb(${220-(180*u+.5)|0},${220-(100*u+.5)|0},${255-(50*u+.5)|0})`,f,w?{value:l,showValues:!0,valueFormat:k}:void 0),f,e))}}return S}(e,t,n);if(0===t.length)return[];const o=zt(e.config.valueAccessor,"value"),i=Dt(e.config.xAccessor,"x"),r=Dt(e.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(t.length),c=Array(t.length);for(let e=0;t.length>e;e++){const n=t[e],o=i(n),u=r(n);l[e]=o,c[e]=u,s.has(o)||s.set(o,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),f=Array.from(a.keys()),p=h.every(e=>"number"==typeof e&&!isNaN(e)),g=f.every(e=>"number"==typeof e&&!isNaN(e));if(p){h.sort((e,t)=>Number(e)-Number(t)),s.clear();for(let e=0;h.length>e;e++)s.set(h[e],e)}if(g){f.sort((e,t)=>Number(e)-Number(t)),a.clear();for(let e=0;f.length>e;e++)a.set(f[e],e)}const y=new Float64Array(t.length),m=new Float64Array(t.length),x=Array(t.length),b=new Map;let v=0;for(let e=0;t.length>e;e++){const n=t[e],i=s.get(l[e]),r=a.get(c[e]);if(void 0===i||void 0===r)continue;const d=o(n),h=r*u+i,f=b.get(h);let p;void 0!==f?p=f:(p=v++,b.set(h,p)),y[p]=h,m[p]=d,x[p]=n}let w=1/0,k=-1/0;for(let e=0;v>e;e++){const t=m[e];isFinite(t)&&(w>t&&(w=t),t>k&&(k=t))}if(!isFinite(w)||!isFinite(k))return[];const S=function(e){const t=e in ee?e:"blues";let n=Mn.get(t);if(n)return n;n=Array(256);const o=te(t);for(let e=0;256>e;e++)n[e]=o(e/255);return Mn.set(t,n),n}("string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues"),A=255/(k-w||1),M=n.width/u,_=n.height/d,P=e.config.showValues,j=e.config.heatmapValueFormat,C=[];for(let t=0;v>t;t++){const n=m[t];if(!isFinite(n))continue;const o=y[t],i=o%u,r=x[t];C.push(_n(cn(i*M,(d-1-(o-i)/u)*_,M,_,S[Math.min((n-w)*A+.5|0,255)],r,P?{value:n,showValues:!0,valueFormat:j}:void 0),r,e))}return C}(i,t,e);case"bar":{const e=function(e,t){if(!e.config.binSize)return{nodes:[],binBoundaries:[]};const n=Pn(t,e.getX,e.getY,e.config.binSize,e.getCategory);if(0===n.size)return{nodes:[],binBoundaries:[]};let o=null;if(e.getCategory){const t=new Set;for(const e of n.values())for(const n of e.categories.keys())t.add(n);const i=e.config.barColors?Object.keys(e.config.barColors):[],r=new Set(i),s=Array.from(t).filter(e=>!r.has(e)).sort(),a=i.filter(e=>t.has(e)),l=a.join("\0")+""+s.join("\0");e.barCategoryCache&&e.barCategoryCache.key===l?o=e.barCategoryCache.order:(o=[...a,...s],e.barCategoryCache={key:l,order:o})}const i=[],r=e.scales,[s,a]=r.x.domain(),l=e.config.barStyle,c=e.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity);for(const t of n.values()){const n=Math.max(t.start,s),u=Math.min(t.end,a);if(n>=u)continue;const f=r.x(n),p=r.x(u),g=Math.abs(p-f),y=g>d+1?d:0,m=Math.min(f,p)+y/2,x=Math.max(g-y,1);if(x>0)if(o&&t.categories.size>0){let n=0;for(const s of o){const o=t.categories.get(s)||0;if(0===o)continue;const a=r.y(n),u=r.y(n+o);i.push(ln(m,Math.min(a,u),x,Math.abs(a-u),{fill:e.config.barColors?.[s]||l?.fill||c||"#4e79a7",...h},{binStart:t.start,binEnd:t.end,total:t.total,category:s,categoryValue:o},s)),n+=o}}else{const e=r.y(0),n=r.y(t.total);i.push(ln(m,Math.min(e,n),x,Math.abs(e-n),{fill:l?.fill||c||"#007bff",...h},{binStart:t.start,binEnd:t.end,total:t.total}))}}const f=new Set;for(const e of n.values())f.add(e.start),f.add(e.end);return{nodes:i,binBoundaries:Array.from(f).sort((e,t)=>e-t)}}(i,t);return this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=e.binBoundaries,e.nodes}case"swarm":return function(e,t){const n=[],o=e.config.swarmStyle||{},i=o.radius??3,r=o.fill??e.config.themeSemantic?.primary??"#007bff",s=o.opacity??.7,a=o.stroke,l=o.strokeWidth;for(const o of t){const t=e.getX(o),c=e.getY(o);if(null==c||Number.isNaN(c))continue;const u=e.scales.x(t),d=e.scales.y(c);let h=r;if(e.getCategory){const t=e.getCategory(o);h=e.config.barColors?.[t]||h}const{r:f,...p}=e.config.pointStyle?.(o)??{},g={type:"point",x:u,y:d,r:f??i,style:{fill:h,opacity:s,stroke:a,strokeWidth:l,...p},datum:o};e.getPointId&&(g.pointId=e.getPointId(o)+""),n.push(g)}return n}(i,t);case"waterfall":return function(e,t,n){const o=[],i=e.scales,r=e.config.waterfallStyle,s=t.filter(t=>{const n=e.getY(t),o=e.getX(t);return null!=n&&!Number.isNaN(n)&&null!=o&&isFinite(o)});if(0===s.length)return o;const a=r?.positiveColor??e.config.themeSemantic?.success??"#28a745",l=r?.negativeColor??e.config.themeSemantic?.danger??"#dc3545",c=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let f=0;for(let t=0;s.length>t;t++){const p=s[t],g=e.getX(p),y=e.getY(p),m=f+y;let x;x=s.length-1>t?e.getX(s[t+1])-g:t>0?g-e.getX(s[t-1]):0;const b=i.x(g),v=0!==x?i.x(g+x):b+n.width/10,w=Math.min(b,v)+c/2,k=Math.max(b,v)-c/2-w;if(0>=k){f=m;continue}const S=i.y(f),A=i.y(m),M=Math.min(S,A),_=Math.abs(S-A),P={fill:0>y?l:a,stroke:u,strokeWidth:d};null!=h&&(P.opacity=h),o.push(ln(w,M,k,_,P,{...p,baseline:f,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth})),f=m}return o}(i,t,e);case"candlestick":return function(e,t,n){if(!e.getHigh||!e.getLow||!e.scales)return[];const o=e.config.candlestickRangeMode??!1;if(!(o||e.getOpen&&e.getClose))return[];const i=[],r=e.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=o?s:r.upColor||"#28a745",l=o?s:r.downColor||"#dc3545",c=o?s:r.wickColor||"#333",u=r.wickWidth||(o?2:1),d=t.map(t=>e.getX(t)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let t=1/0;for(let n=1;d.length>n;n++){const o=Math.abs(e.scales.x(d[n])-e.scales.x(d[n-1]));o>0&&t>o&&(t=o)}h=t!==1/0?Math.max(2,Math.min(.6*t,20)):6}else h=6;for(const r of t){const t=e.getX(r);if(null==t||Number.isNaN(t))continue;const s=e.getHigh(r),d=e.getLow(r);if(null==s||Number.isNaN(s)||null==d||Number.isNaN(d))continue;const f=o?s:e.getOpen(r),p=o?d:e.getClose(r);if(!o&&[f,p].some(e=>null==e||Number.isNaN(e)))continue;const g=p>=f,y={type:"candlestick",x:e.scales.x(t),openY:e.scales.y(f),closeY:e.scales.y(p),highY:e.scales.y(s),lowY:e.scales.y(d),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:g,datum:r};o&&(y.isRange=!0,y.dotRadius=Math.max(2,Math.min(h/2,.12*n.height))),i.push(y)}return i}(i,t,e);default:return[]}}resolveBoundsStyle(e,t){return function(e,t,n,o){const i=e.boundsStyle;return"function"==typeof i?i(n||{},t):i&&"object"==typeof i?i:{fill:o(t,n).stroke||e.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none"}}(this.config,e,t,(e,t)=>this.resolveLineStyle(e,t))}computeDecayOpacity(e,t){const n=this.config.decay;return n&&t>1?Ut(n,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const t=Kt(e);return this._datumIndexCache={version:this._ingestVersion,map:t},t}applyDecay(e,t){this.config.decay&&function(e,t,n,o=Kt(n)){const i=n.length;if(i>1)for(const n of t){if("line"===n.type){const t=Array.isArray(n.datum)?n.datum:[];if(2>t.length)continue;const r=Array(t.length);let s=!1;for(let n=0;t.length>n;n++){const a=o.get(t[n]);null!=a?(r[n]=Ut(e,a,i),1>r[n]&&(s=!0)):r[n]=1}s&&(n._decayOpacities=r);continue}if("area"===n.type){const t=Array.isArray(n.datum)?n.datum:[],r=n.topPath?n.topPath.length:t.length;if(2>r)continue;if(t.length===r){const s=Array(r);let a=!1;for(let n=0;t.length>n;n++){const r=o.get(t[n]);null!=r?(s[n]=Ut(e,r,i),1>s[n]&&(a=!0)):s[n]=1}a&&(n._decayOpacities=s)}else{let s=1;for(const n of t){const t=o.get(n);if(null!=t){const n=Ut(e,t,i);s>n&&(s=n)}}if(1>s){const e=Array(r);e.fill(s),n._decayOpacities=e}}continue}const t=o.get(n.datum);if(null==t)continue;const r=Ut(e,t,i);"heatcell"===n.type?n.style={opacity:r}:"candlestick"===n.type?n._decayOpacity=r:n.style={...n.style,opacity:(n.style?.opacity??1)*r}}}(this.config.decay,e,t,this.getDatumIndexMap(t))}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&Jt(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(e,t,n,o){n.clear(),o.clear();for(let i=0;t.length>i;i++){const r=t[i],s=en(e,r,i);s&&("point"===r.type?n.set(s,{x:r.x,y:r.y,r:r.r,opacity:tn(r.style)}):"glyph"===r.type?n.set(s,{x:r.x,y:r.y,r:r.size,opacity:tn(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?n.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:tn(r.style)}):"candlestick"===r.type?n.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:tn(r.style)}):"line"===r.type?o.set(s,{path:r.path.map(e=>[e[0],e[1]]),opacity:r.style?.opacity}):"area"===r.type&&o.set(s,{topPath:r.topPath.map(e=>[e[0],e[1]]),bottomPath:r.bottomPath.map(e=>[e[0],e[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const e=this.scales?.y(0)??0;for(let t=0;this.scene.length>t;t++){const n=this.scene[t],o=en(this.transitionContext,n,t);o&&("point"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,r:0,opacity:0}):"rect"===n.type?this.prevPositionMap.set(o,{x:n.x,y:e,w:n.w,h:0,opacity:n.style.opacity??1}):"heatcell"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,w:n.w,h:n.h,opacity:0}):"line"===n.type?(n._introClipFraction=0,this.prevPathMap.set(o,{path:n.path.map(e=>[e[0],e[1]]),opacity:n.style.opacity})):"area"===n.type&&(n._introClipFraction=0,this.prevPathMap.set(o,{topPath:n.topPath.map(e=>[e[0],e[1]]),bottomPath:n.bottomPath.map(e=>[e[0],e[1]]),opacity:n.style.opacity})))}}startTransition(){if(!this.config.transition)return;const e=function(e,t,n,o,i,r=Vt()){if(0===o.size&&0===i.size)return n;const s=t.duration??300;if(n.exitNodes.length>0){const e=new Set(n.exitNodes);n.scene=n.scene.filter(t=>!e.has(t)),n.exitNodes=[]}let a=!1;const l=new Set,c=new Set;for(let t=0;n.scene.length>t;t++){const r=n.scene[t],s=en(e,r,t);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const e=i.get(s);if(e){if(c.add(s),"line"===r.type&&e.path&&e.path.length===r.path.length){r._targetPath=r.path.map(e=>[e[0],e[1]]),r._prevPath=e.path;for(let t=0;r.path.length>t;t++)r.path[t]=[e.path[t][0],e.path[t][1]];a=!0}else if("area"===r.type&&e.topPath&&e.bottomPath&&e.topPath.length===r.topPath.length&&e.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(e=>[e[0],e[1]]),r._targetBottomPath=r.bottomPath.map(e=>[e[0],e[1]]),r._prevTopPath=e.topPath,r._prevBottomPath=e.bottomPath;for(let t=0;r.topPath.length>t;t++)r.topPath[t]=[e.topPath[t][0],e.topPath[t][1]];for(let t=0;r.bottomPath.length>t;t++)r.bottomPath[t]=[e.bottomPath[t][0],e.bottomPath[t][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=e.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=o.get(s);if("point"===r.type)if(u){l.add(s);const e={x:r.x,y:r.y,r:r.r};r._targetOpacity=tn(r.style),u.x===e.x&&u.y===e.y&&u.r===e.r||(r._targetX=e.x,r._targetY=e.y,r._targetR=e.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=tn(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const e={x:r.x,y:r.y,size:r.size};r._targetOpacity=tn(r.style),u.x===e.x&&u.y===e.y&&u.r===e.size||(r._targetX=e.x,r._targetY=e.y,r._targetR=e.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=tn(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const e={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=tn(r.style),u.x===e.x&&u.y===e.y&&u.w===e.w&&u.h===e.h||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.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=tn(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const e={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=tn(r.style),u.x===e.x&&u.y===e.y&&u.w===e.w&&u.h===e.h||(r._targetX=e.x,r._targetY=e.y,r._targetW=e.w,r._targetH=e.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=tn(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const e={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=tn(r.style),(u.x!==e.x||u.openY!==e.openY||u.closeY!==e.closeY||u.highY!==e.highY||u.lowY!==e.lowY)&&(r._targetX=e.x,r._targetOpenY=e.openY,r._targetCloseY=e.closeY,r._targetHighY=e.highY,r._targetLowY=e.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=tn(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[e,t]of i)if(!c.has(e))if(e.startsWith("l:")&&t.path){const o={type:"line",path:t.path.map(e=>[e[0],e[1]]),group:e.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e,datum:null};n.exitNodes.push(o),a=!0}else if(e.startsWith("a:")&&t.topPath&&t.bottomPath){const o={type:"area",topPath:t.topPath.map(e=>[e[0],e[1]]),bottomPath:t.bottomPath.map(e=>[e[0],e[1]]),group:e.slice(2),style:{fill:"#999",opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e,datum:null};n.exitNodes.push(o),a=!0}for(const[e,t]of o)if(!l.has(e)){if(e.startsWith("p:"))n.exitNodes.push({type:"point",x:t.x,y:t.y,r:t.r??3,style:{opacity:t.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("g:")&&t.glyph)n.exitNodes.push({type:"glyph",x:t.x,y:t.y,size:t.r??12,glyph:t.glyph,color:"#999",accent:"#999",style:{opacity:t.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))n.exitNodes.push({type:"rect",x:t.x,y:t.y,w:t.w??0,h:t.h??0,style:{opacity:t.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("h:"))n.exitNodes.push({type:"heatcell",x:t.x,y:t.y,w:t.w??0,h:t.h??0,fill:"#999",datum:null,style:{opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e});else if(e.startsWith("c:")){const o=t.openY??t.y;n.exitNodes.push({type:"candlestick",x:t.x,openY:o,closeY:t.closeY??o,highY:t.highY??o,lowY:t.lowY??o,bodyWidth:t.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e})}a=!0}return n.exitNodes.length>0&&(n.scene=[...n.scene,...n.exitNodes]),a&&(n.activeTransition={startTime:r,duration:s}),n}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition}advanceTransition(e){if(!this.activeTransition||!this.config.transition)return!1;const t={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},n=function(e,t,n,o){if(!n.activeTransition)return!1;const i=Ht(e,n.activeTransition),r=Xt(i,"linear"===t.easing?"linear":"ease-out-cubic");for(const e of n.scene){const t=e._transitionKey;if("point"===e.type){if(void 0!==e._targetOpacity){const n=t?o.get(t):void 0;e.style.opacity=Gt(n?n.opacity??1:0,e._targetOpacity,r)}if(void 0===e._targetX)continue;if(!t)continue;const n=o.get(t);if(!n)continue;e.x=Gt(n.x,e._targetX,r),e.y=Gt(n.y,e._targetY,r),void 0!==e._targetR&&void 0!==n.r&&(e.r=Gt(n.r,e._targetR,r))}else if("glyph"===e.type){if(void 0!==e._targetOpacity){const n=t?o.get(t):void 0;e.style.opacity=Gt(n?n.opacity??1:0,e._targetOpacity,r)}if(void 0===e._targetX)continue;if(!t)continue;const n=o.get(t);if(!n)continue;e.x=Gt(n.x,e._targetX,r),e.y=Gt(n.y,e._targetY,r),void 0!==e._targetR&&void 0!==n.r&&(e.size=Gt(n.r,e._targetR,r))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const n=t?o.get(t):void 0;e.style.opacity=Gt(n?n.opacity??1:0,e._targetOpacity,r)}if(void 0===e._targetX)continue;if(!t)continue;const n=o.get(t);if(!n)continue;e.x=Gt(n.x,e._targetX,r),e.y=Gt(n.y,e._targetY,r),void 0!==n.w&&(e.w=Gt(n.w,e._targetW,r)),void 0!==n.h&&(e.h=Gt(n.h,e._targetH,r))}else if("heatcell"===e.type){if(void 0!==e._targetOpacity){const n=t?o.get(t):void 0;e.style={...e.style||{},opacity:Gt(n?n.opacity??1:0,e._targetOpacity,r)}}if(void 0===e._targetX)continue;if(!t)continue;const n=o.get(t);if(!n)continue;e.x=Gt(n.x,e._targetX,r),e.y=Gt(n.y,e._targetY,r),void 0!==n.w&&(e.w=Gt(n.w,e._targetW,r)),void 0!==n.h&&(e.h=Gt(n.h,e._targetH,r))}else if("candlestick"===e.type){if(void 0!==e._targetOpacity){const n=t?o.get(t):void 0;e.style={...e.style||{},opacity:Gt(n?n.opacity??1:0,e._targetOpacity,r)}}if(void 0===e._targetX)continue;if(!t)continue;const n=o.get(t);if(!n)continue;e.x=Gt(n.x,e._targetX,r),void 0!==n.openY&&(e.openY=Gt(n.openY,e._targetOpenY,r)),void 0!==n.closeY&&(e.closeY=Gt(n.closeY,e._targetCloseY,r)),void 0!==n.highY&&(e.highY=Gt(n.highY,e._targetHighY,r)),void 0!==n.lowY&&(e.lowY=Gt(n.lowY,e._targetLowY,r))}else if("line"===e.type){void 0!==e._targetOpacity&&(e.style={...e.style,opacity:Gt(e._startOpacity??0,e._targetOpacity,r)}),void 0!==e._introClipFraction&&(e._introClipFraction=r);const t=e._prevPath,n=e._targetPath;if(t&&n&&t.length===e.path.length)for(let o=0;e.path.length>o;o++)e.path[o][0]=Gt(t[o][0],n[o][0],r),e.path[o][1]=Gt(t[o][1],n[o][1],r)}else if("area"===e.type){void 0!==e._targetOpacity&&(e.style={...e.style,opacity:Gt(e._startOpacity??0,e._targetOpacity,r)}),void 0!==e._introClipFraction&&(e._introClipFraction=r);const t=e._prevTopPath,n=e._prevBottomPath,o=e._targetTopPath,i=e._targetBottomPath;if(t&&o&&t.length===e.topPath.length)for(let n=0;e.topPath.length>n;n++)e.topPath[n][0]=Gt(t[n][0],o[n][0],r),e.topPath[n][1]=Gt(t[n][1],o[n][1],r);if(n&&i&&n.length===e.bottomPath.length)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t][0]=Gt(n[t][0],i[t][0],r),e.bottomPath[t][1]=Gt(n[t][1],i[t][1],r)}}if(i>=1){for(const e of n.scene){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style="line"===e.type||"area"===e.type?{...e.style,opacity:0===t?0:t}:{...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("glyph"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("heatcell"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("candlestick"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0}else if("line"===e.type){const t=e._targetPath;if(t)for(let n=0;e.path.length>n;n++)e.path[n]=t[n];e._prevPath=void 0,e._targetPath=void 0,e._introClipFraction=void 0}else if("area"===e.type){const t=e._targetTopPath,n=e._targetBottomPath;if(t)for(let n=0;e.topPath.length>n;n++)e.topPath[n]=t[n];if(n)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=n[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0,e._introClipFraction=void 0}}if(n.exitNodes.length>0){const e=new Set(n.exitNodes);n.scene=n.scene.filter(t=>!e.has(t)),n.exitNodes=[]}return n.activeTransition=null,!1}return!0}(e,this.config.transition,t,this.prevPositionMap);return this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition,n}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(e){for(const t of e){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("glyph"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("rect"===t.type||"heatcell"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0);else if("candlestick"===t.type)void 0!==t._targetX&&(t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0);else if("line"===t.type||"area"===t.type){if(t._introClipFraction=void 0,"line"===t.type&&t._targetPath){for(let e=0;t.path.length>e;e++)t.path[e]=t._targetPath[e];t._prevPath=void 0,t._targetPath=void 0}if("area"===t.type){if(t._targetTopPath)for(let e=0;t.topPath.length>e;e++)t.topPath[e]=t._targetTopPath[e];if(t._targetBottomPath)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=t._targetBottomPath[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(e){const{result:t,cache:n}=function(e,t,n,o){if(o&&o.version===n&&o.group===t&&o.data===e)return{result:o.result,cache:o};let i;if(t){const n=new Map;for(const o of e){const e=t(o);n.has(e)||n.set(e,[]),n.get(e).push(o)}i=Array.from(n.entries()).map(([e,t])=>({key:e,data:t}))}else i=[{key:"_default",data:e}];return{result:i,cache:{version:n,group:t,data:e,result:i}}}(e,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=n,t}resolveColorMap(e){const{map:t,cache:n}=function(e,t,n,o,i){if(i&&i.version===o)return{map:i.map,cache:i};const r=new Set;if(t)for(const n of e){const e=t(n);e&&r.add(e)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const e={...i,version:o};return{map:e.map,cache:e}}const l=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical||fe,c=new Map;for(let e=0;s.length>e;e++)c.set(s[e],l[e%l.length]);return{map:c,cache:{key:a,map:c,version:o}}}(e,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=n,t}resolveLineStyle(e,t){return function(e,t,n,o){const i=e.lineStyle;if("function"==typeof i){const e=i(n||{},t);if(e&&!e.stroke&&t){const n=o(t);if(n)return{...e,stroke:n}}return e}const r=e.themeSemantic?.primary;return i&&"object"==typeof i?{stroke:i.stroke||r||"#007bff",strokeWidth:i.strokeWidth||2,strokeDasharray:i.strokeDasharray,fill:i.fill,fillOpacity:i.fillOpacity,opacity:i.opacity}:{stroke:o(t)||r||"#007bff",strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveAreaStyle(e,t){return function(e,t,n,o){if(e.areaStyle){const i=e.areaStyle(n||{});if(i&&!i.fill&&t){const e=o(t);if(e)return{...i,fill:e,stroke:i.stroke||e}}return i}const i=e.lineStyle;if("function"==typeof i){const e=i(n||{},t);if(e&&!e.fill&&t){const n=o(t);if(n)return{...e,fill:n,stroke:e.stroke||n}}return e}const r=e.themeSemantic?.primary;if(i&&"object"==typeof i)return{fill:i.fill||i.stroke||r||"#4e79a7",fillOpacity:i.fillOpacity??.7,stroke:i.stroke||r||"#4e79a7",strokeWidth:i.strokeWidth||2};const s=o(t)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveGroupColor(t){const{color:n,groupColorCounter:o}=function(e){const{group:t,colorMapCache:n,groupColorMap:o,groupColorMapCap:i,config:r}=e;let{groupColorCounter:s}=e;if(n){const e=n.map.get(t);if(e)return{color:e,groupColorCounter:s}}const a=o.get(t);if(a)return{color:a,groupColorCounter:s};const l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||fe;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,o.set(t,c),o.size>i){const e=o.keys().next().value;void 0!==e&&o.delete(e)}return{color:c,groupColorCounter:s}}({group:t,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:e.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=o,n}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(e){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const t=qt(e),n=this.getPointId,o=e=>t.has(n(e));Nn(this.buffer,this.timestampBuffer,o);const i=this.buffer.remove(o);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const e of i)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(e,t){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const n=qt(e),o=this.getPointId,i=new Set;this.buffer.forEach((e,t)=>{n.has(o(e))&&i.add(t)});const r=this.buffer.update(e=>n.has(o(e)),t);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const e of r)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.buffer.forEach((e,t)=>{i.has(t)&&(this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",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(e,t){const n=this._customRestyle;if(n)for(const o of e){const e=this._baseStyles.get(o)??o.style??{},i=n(o,t);o.style=i?{...e,...i}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){const t={...this.config},n=Object.keys(e).filter(n=>e[n]!==t[n]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=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 o=!1,i=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();const r="chartType"in e&&e.chartType!==t.chartType||"runtimeMode"in e&&e.runtimeMode!==t.runtimeMode;if(r||"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,s=e&&t.valueAccessor||t.yAccessor,a=r||!Ot(e&&this.config.timeAccessor||this.config.xAccessor,e&&t.timeAccessor||t.xAccessor),l=r||!Ot(n,s);(a||l)&&(e?(this.getX=zt(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=zt(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=zt(this.config.xAccessor,"x"),this.getY=zt(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(e=>"bounds"===e.kind)&&(this.resolvedRibbons=In(this.config)),o=!0,i=!0)}if("groupAccessor"in e&&!Ot(e.groupAccessor,t.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?Ft(this.config.groupAccessor):void 0,o=!0),"categoryAccessor"in e&&!Ot(e.categoryAccessor,t.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?Ft(this.config.categoryAccessor):void 0,o=!0),"sizeAccessor"in e&&!Ot(e.sizeAccessor,t.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?zt(this.config.sizeAccessor,"size"):void 0,o=!0),"symbolAccessor"in e&&!Ot(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Ft(this.config.symbolAccessor):void 0,o=!0),"colorAccessor"in e&&!Ot(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Ft(this.config.colorAccessor):void 0,o=!0),"y0Accessor"in e&&!Ot(e.y0Accessor,t.y0Accessor)&&(this.getY0=this.config.y0Accessor?zt(this.config.y0Accessor,"y0"):void 0,o=!0,i=!0),("boundsAccessor"in e&&!Ot(e.boundsAccessor,t.boundsAccessor)||"band"in e&&e.band!==t.band||"boundsStyle"in e&&e.boundsStyle!==t.boundsStyle)&&(this.resolvedRibbons=In(this.config),o=!0,i=!0),"pointIdAccessor"in e&&!Ot(e.pointIdAccessor,t.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?Ft(this.config.pointIdAccessor):void 0,o=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in e&&!Ot(e.openAccessor,t.openAccessor)||"closeAccessor"in e&&!Ot(e.closeAccessor,t.closeAccessor)||"highAccessor"in e&&!Ot(e.highAccessor,t.highAccessor)||"lowAccessor"in e&&!Ot(e.lowAccessor,t.lowAccessor))){const e=null!=this.config.openAccessor,t=null!=this.config.closeAccessor;this.getOpen=e?zt(this.config.openAccessor,"open"):void 0,this.getHigh=zt(this.config.highAccessor,"high"),this.getLow=zt(this.config.lowAccessor,"low"),this.getClose=t?zt(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!t,o=!0,i=!0}if("accessorRevision"in e&&e.accessorRevision!==t.accessorRevision&&(o=!0,i=!0),!o){const n=Object.keys(e).filter(e=>!e.endsWith("Accessor")&&"timeAccessor"!==e&&"valueAccessor"!==e);for(const i of n)if(e[i]!==t[i]){o=!0;break}}o&&(i&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(n)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};go.GROUP_COLOR_MAP_CAP=1e3;var yo=go;Vn(yo);var mo=require("react"),xo={sceneGeometry:0,layout:0,domain:0};function bo(e){const{domain:t,layout:n,sceneGeometry:o}=e.revisions;return{domain:t,layout:n,sceneGeometry:o}}function vo(e,t){return{sceneGeometry:Math.max(e.sceneGeometry,t.sceneGeometry),layout:Math.max(e.layout,t.layout),domain:Math.max(e.domain,t.domain)}}var wo="production"!==process.env.NODE_ENV,ko={revisions:xo,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},So=class{constructor(e="scene host"){this.hostName=e,this.lastConsumed=xo,this.lastObserved=xo,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(e){wo&&(this.lastObserved=vo(this.lastObserved,bo(e)))}beforeCompute(e,t){if(!wo)return ko;const n=vo(bo(e),this.lastObserved),o=function(e){return`${e.sceneGeometry}|${e.layout}|${e.domain}`}(n),i=!((r=n).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:n,signature:o,sawSignals:e.changed.has("scene-geometry")||e.changed.has("layout")||e.changed.has("domain"),wasUnconsumed:i,warnUnconsumed:!t&&i&&this.lastUnconsumedWarning!==o}}afterCompute(e,t,n){if(wo){if(t&&e.wasUnconsumed&&(this.lastConsumed=e.revisions),e.warnUnconsumed&&!t)return console.warn(`[semiotic] ${this.hostName} observed scene-affecting revisions without a scene rebuild: ${e.signature}.`),void(this.lastUnconsumedWarning=e.signature);t&&e.sawSignals&&!e.wasUnconsumed&&!n&&this.lastDuplicateWarning!==e.signature?(console.warn(`[semiotic] ${this.hostName} performed scene rebuild with unchanged scene revisions: ${e.signature}.`),this.lastDuplicateWarning=e.signature):t&&!e.sawSignals&&(this.lastDuplicateWarning="")}}},Ao=(0,mo.memo)(function({store:e,diagnostics:t}){return(0,mo.useEffect)(()=>{const n=()=>t.observeUpdateResult(e.getUpdateSnapshot());return n(),e.subscribeUpdateResult(n)},[t,e]),null}),Mo=g(require("react"));function _o(...e){const t=e.filter(e=>null!=e);return 0===t.length?null:1===t.length?t[0]:Mo.createElement(Mo.Fragment,null,...t)}var Po=require("react");function jo(e,t,n){return n.x>e||e>n.x+n.w||n.y>t||t>n.y+n.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:n.x+n.w/2,cy:n.y+n.h/2}}function Co(e,t=30){return Math.max((e??4)+5,12,t)}function Ro(e){return e instanceof Date?e:"number"==typeof e&&e>1e9?new Date(e):null}function Lo(e,t){const n=Ro(e);if(!n)return!1;const o=Ro(t);return!o||n.getFullYear()!==o.getFullYear()||n.getMonth()!==o.getMonth()}var To=[40,40],Io=[.5,.5];function $o(e,t){const[n,o]=e.viewBox??To,[i,r]=e.anchor??Io,s=o>0?o:1,a=Math.max(0,t)/s,l=(n>0?n:s)*a,c=s*a;return{width:l,height:c,scale:a,offsetX:-i*l,offsetY:-r*c}}function Oo(e,t,n,o){if("none"!==e)return"color"===e||null==e?t??o:"accent"===e?n:e}var zo=null;function Do(e){if("undefined"==typeof Path2D)return null;zo||(zo=new Map);const t=zo.get(e);if(t)return t;const n=new Path2D(e);return zo.size>1024&&zo.clear(),zo.set(e,n),n}function Fo(e,t,n=0,o="horizontal"){const[i,r]=e.viewBox??To,s=Math.min(1,Math.max(0,n)),a=Math.min(1,Math.max(0,t));return a>s?s>0||1>a?"vertical"===o?{x:0,y:r*(1-a),width:i,height:r*(a-s)}:{x:i*s,y:0,width:i*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}function Eo(e,t){const n=$o(e,t);return{centerDx:n.offsetX+n.width/2,centerDy:n.offsetY+n.height/2,halfWidth:n.width/2,halfHeight:n.height/2,radius:Math.hypot(n.width,n.height)/2}}function No(e,t,n,o,i,r=e=>e){for(const s of t.parts){const t=Do(s.d);if(!t)continue;const a=s.opacity??1,l=e.globalAlpha;1!==a&&(e.globalAlpha=l*a);const c=i?"none"===s.fill?void 0:i:Oo(s.fill,n,o);c&&(e.fillStyle=r(c),e.fill(t));const u=i?s.stroke&&"none"!==s.stroke?i:void 0:Oo(s.stroke??"none",n,o);u&&(e.strokeStyle=r(u),e.lineWidth=s.strokeWidth??1,e.lineCap=s.strokeLinecap??"butt",e.lineJoin=s.strokeLinejoin??"miter",e.stroke(t)),1!==a&&(e.globalAlpha=l)}}var Bo=new WeakMap,Wo=0,Yo=!1,qo=null,Xo=null;function Ho(e,t){if(!t)return t;const n=function(e){const t=e.trim();if(!t.startsWith("var(")||!t.endsWith(")"))return null;const n=t.slice(4,-1),o=n.indexOf(",");if(-1===o){const e=n.trim();return e.startsWith("--")?{name:e}:null}const i=n.slice(0,o).trim(),r=n.slice(o+1).trim();return i.startsWith("--")?{name:i,fallback:r||void 0}:null}(t);if(!n)return t;const o=()=>n.fallback?Ho(e,n.fallback):t,i=e.canvas;if(!i)return o();!function(){if(Yo)return;if("undefined"==typeof window||"undefined"==typeof document)return;Yo=!0;const e=()=>{Wo++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"],subtree:!0}),"function"==typeof window.matchMedia)try{qo=window.matchMedia("(prefers-color-scheme: dark)"),Xo=e,"function"==typeof qo.addEventListener?qo.addEventListener("change",Xo):"function"==typeof qo.addListener&&qo.addListener(Xo)}catch{}}();let r=Bo.get(i);r&&r.version===Wo||(r={version:Wo,map:new Map},Bo.set(i,r));const s=r.map.get(t);if(void 0!==s)return s;const a=getComputedStyle(i).getPropertyValue(n.name).trim()||o()||t;return r.map.set(t,a),a}function Go(e){return{type:"hatch",background:e.background,stroke:e.stroke,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle}}var Vo=null;var Uo=require("react/jsx-runtime");function Ko(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function Zo(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}var Qo=new Map;function Jo(e,t){const{background:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=e,l=Math.max(8,Math.ceil(2*r));return(0,Uo.jsxs)("pattern",{id:t,width:l,height:l,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&(0,Uo.jsx)("rect",{width:l,height:l,fill:n}),(0,Uo.jsx)("line",{x1:0,y1:0,x2:0,y2:l,stroke:o,strokeWidth:i,strokeOpacity:a}),(0,Uo.jsx)("line",{x1:r,y1:0,x2:r,y2:l,stroke:o,strokeWidth:i,strokeOpacity:a})]},t)}function ei(e,t,n="#4e79a7"){if(Ko(e)){const n=function(e,t){let n=2166136261;const o=Zo(t);for(let e=0;o.length>e;e++)n^=o.charCodeAt(e),n=Math.imul(n,16777619);return`${e}-hatch-${(n>>>0).toString(36)}`}(t,e);return{fill:`url(#${n})`,def:Jo(e,n)}}return e&&"string"==typeof e?{fill:e}:{fill:n}}var ti=require("d3-shape");function ni(e){switch(e){case"monotoneX":return ti.curveMonotoneX;case"monotoneY":return ti.curveMonotoneY;case"cardinal":return ti.curveCardinal;case"catmullRom":return ti.curveCatmullRom;case"step":return ti.curveStep;case"stepBefore":return ti.curveStepBefore;case"stepAfter":return ti.curveStepAfter;case"basis":return ti.curveBasis;case"natural":return ti.curveNatural;default:return null}}function oi(e,t,n){if(null==t)return n;if(Ko(t)){const o=function(e,t){const n=e.background??"transparent",o=e.stroke??"#000",i="transparent"===n||"none"===n?n:Ho(t,n)||n,r=Ho(t,o)||o||"#000",s="undefined"!=typeof window&&window.devicePixelRatio||1,a=`${Zo(e)}|${i}|${r}@${s}`,l=Qo.get(a);if(void 0!==l)return l;const c=function(e={},t){const{background:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=e,a={background:n,stroke:o,lineWidth:i,spacing:r,angle:s},l=Math.max(8,Math.ceil(2*r));let c;try{c=function(e){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(e,e):(Vo||(Vo=document.createElement("canvas")),Vo.width=e,Vo.height=e,Vo)}(l)}catch{return Go(a)}const u=c.getContext("2d");if(!u)return Go(a);n&&"transparent"!==n?(u.fillStyle=n,u.fillRect(0,0,l,l)):u.clearRect(0,0,l,l),u.strokeStyle=o,u.lineWidth=i,u.lineCap="square";const d=s*Math.PI/180;if(45===s||-45===s){const e=s>0?1:-1;for(let t=-l;2*l>=t;t+=r)u.beginPath(),u.moveTo(t,0),u.lineTo(t+e*l,l),u.stroke()}else{u.save(),u.translate(l/2,l/2),u.rotate(d);const e=2*l;for(let t=-e;e>=t;t+=r)u.beginPath(),u.moveTo(-e,t),u.lineTo(e,t),u.stroke();u.restore()}return(t||u).createPattern(c,"repeat")}({background:i,stroke:r,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle},t),u=Ko(c)?null:c;return Qo.set(a,u),u}(t,e);return o||t.background&&Ho(e,t.background)||n}return"string"!=typeof t?t:Ho(e,t)||n}function ii(e,t,n,o,i,r,s){const a=t.stops.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity)));if(2>a.length)return null;const l=e.createLinearGradient(o,i,r,s);for(const t of a)l.addColorStop(Math.max(0,Math.min(1,t.offset)),ri(e,t,n));return l}function ri(e,t,n){const o=t.color??n,i=Ho(e,o)||o;if(null==t.opacity)return i;const r=Math.max(0,Math.min(1,t.opacity)),[s,a,l]=function(e,t){const n=e.fillStyle,o="#010203";try{e.fillStyle=o,e.fillStyle=t}catch{return e.fillStyle=n,[78,121,167]}const i=e.fillStyle;if(e.fillStyle=n,"string"!=typeof i)return[78,121,167];if(i.toLowerCase()===o&&t.trim().toLowerCase()!==o)return[78,121,167];if(i.startsWith("#"))return[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16)];const r=i.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?[+r[1],+r[2],+r[3]]:[78,121,167]}(e,i);return`rgba(${s},${a},${l},${r})`}var si=require("d3-shape"),ai=new WeakMap;function li(e,t){const n=ni(t);if(!n)return e;const o=ai.get(e);if(o)return o;const i=function(e,t,n=8){if(!t||2>e.length)return e.map(([e,t])=>[e,t]);const o=[];let i=null;const r={moveTo(e,t){i=[e,t],o.push([e,t])},lineTo(e,t){i=[e,t],o.push([e,t])},bezierCurveTo(e,t,r,s,a,l){if(!i)return i=[a,l],void o.push([a,l]);const[c,u]=i;for(let i=1;n>=i;i++){const d=i/n,h=1-d;o.push([h*h*h*c+3*h*h*d*e+3*h*d*d*r+d*d*d*a,h*h*h*u+3*h*h*d*t+3*h*d*d*s+d*d*d*l])}i=[a,l]},closePath(){},arc(){},rect(){},arcTo(){},quadraticCurveTo(e,t,n,r){i=[n,r],o.push([n,r])}};return(0,si.line)().x(e=>e[0]).y(e=>e[1]).curve(t).context(r)(e),o}(e,n);return ai.set(e,i),i}function ci(e,t,n,o=30,i,r=0){let s=null;if(i){const e=function(e,t,n,o,i,r=e=>e.x,s=e=>e.y,a=e=>e.r){const l=Math.max(o,i+5,12),c=t-l,u=t+l,d=n-l,h=n+l;let f=null,p=1/0;return e.visit((e,i,l,g,y)=>{if(i>u||c>g||l>h||d>y)return!0;if(!e.length){let i=e;do{const e=i.data,l=r(e)-t,c=s(e)-n,u=Math.sqrt(l*l+c*c);Co(a(e),o)>=u&&p>u&&(f=e,p=u),i=i.next}while(i)}return!1}),f?{node:f,distance:p}:null}(i,t,n,o,r);e&&(s={node:e.node,datum:e.node.datum,x:e.node.x,y:e.node.y,distance:e.distance})}for(const r of e){let e=null;switch(r.type){case"point":if(i)break;e=di(r,t,n,o);break;case"symbol":e=hi(r,t,n,o);break;case"glyph":e=fi(r,t,n,o);break;case"line":e=pi(r,t,n,o);break;case"rect":if(null==r.datum)break;e=yi(r,t,n);break;case"heatcell":e=mi(r,t,n);break;case"area":if(!1===r.interactive)break;e=bi(r,t,n);break;case"candlestick":e=xi(r,t,n)}e&&o>e.distance&&(s&&e.distance>=s.distance||(s=e))}return s}function ui(e,t,n){if(0===e.length)return null;if(e[0][0]>t||t>e[e.length-1][0])return null;const o=vi(e,t);if(0>o)return null;if(Math.abs(e[o][0]-t)>n)return null;let i=o,r=o;o>0&&e[o][0]>=t?(i=o-1,r=o):e.length-1>o&&(i=o,r=o+1);const[s,a]=e[i],[l,c]=e[r];return l===s?a:a+Math.max(0,Math.min(1,(t-s)/(l-s)))*(c-a)}function di(e,t,n,o=30){const i=t-e.x,r=n-e.y,s=Math.sqrt(i*i+r*r);return s>Co(e.r,o)?null:{node:e,datum:e.datum,x:e.x,y:e.y,distance:s}}function hi(e,t,n,o=30){const i=t-e.x,r=n-e.y,s=Math.sqrt(i*i+r*r);return s>Co(Sn(e.size),o)?null:{node:e,datum:e.datum,x:e.x,y:e.y,distance:s}}function fi(e,t,n,o=30){if(null==e.datum)return null;const i=Eo(e.glyph,e.size),r=e.x+i.centerDx,s=e.y+i.centerDy,a=t-r,l=n-s,c=Math.sqrt(a*a+l*l);return c>Co(i.radius,o)?null:{node:e,datum:e.datum,x:r,y:s,distance:c}}function pi(e,t,n,o=30){if(0===e.path.length)return null;const i=vi(e.path,t);if(0>i)return null;const[r,s]=e.path[i];let a;if(e.path.length>1){let o=1/0;const r=Math.max(0,i-1),s=Math.min(e.path.length-2,i);for(let i=r;s>=i;i++){const[r,s]=e.path[i],[a,l]=e.path[i+1],c=gi(t,n,r,s,a,l);o>c&&(o=c)}a=o}else{const e=t-r,o=n-s;a=Math.sqrt(e*e+o*o)}const l=e.style;return a>Math.max(5,(l.strokeWidth??l.lineWidth??1)/2+2,o)?null:{node:e,datum:Array.isArray(e.datum)&&e.datum[i]?e.datum[i]:e.datum,x:r,y:s,distance:a}}function gi(e,t,n,o,i,r){const s=i-n,a=r-o,l=s*s+a*a;if(0===l)return Math.sqrt((e-n)**2+(t-o)**2);let c=((e-n)*s+(t-o)*a)/l;return c=Math.max(0,Math.min(1,c)),Math.sqrt((e-(n+c*s))**2+(t-(o+c*a))**2)}function yi(e,t,n){const o=jo(t,n,e);return o.hit?{node:e,datum:e.datum,x:o.cx,y:o.cy,distance:0}:null}function mi(e,t,n){const o=jo(t,n,e);return o.hit?{node:e,datum:e.datum,x:o.cx,y:o.cy,distance:0}:null}function xi(e,t,n){const o=e.bodyWidth/2,i=Math.min(e.openY,e.closeY);if(!(e.x-o-3>t||t>e.x+o+3||e.highY-3>n||n>e.lowY+3)){const o=i+Math.max(Math.max(e.openY,e.closeY)-i,1)/2,r=t-e.x,s=n-o;return{node:e,datum:e.datum,x:e.x,y:o,distance:Math.sqrt(r*r+s*s)}}return null}function bi(e,t,n){if(0===e.topPath.length)return null;const o=vi(e.topPath,t);if(0>o)return null;const[i,r]=e.topPath[o],s=t-i,a=n-r,l=Math.sqrt(s*s+a*a);return{node:e,datum:Array.isArray(e.datum)&&e.datum[o]?e.datum[o]:e.datum,x:i,y:r,distance:l}}function vi(e,t){if(0===e.length)return-1;let n=0,o=e.length-1;for(;o>n;){const i=n+o>>1;t>e[i][0]?n=i+1:o=i}return n>0&&Math.abs(e[n][0]-t)>=Math.abs(e[n-1][0]-t)?n-1:n}var wi=require("react"),ki={fresh:1,aging:.7,stale:.45,expired:.25},Si={alpha:1,band:"fresh",isStale:!1};function Ai(e,t){if(!e||0>=t)return Si;const n=null!=e.threshold&&e.threshold>0?e.threshold:5e3,o=e.graded;if(o){const e="object"==typeof o?o:{},i=function(e,t,n={}){return Number.isFinite(t)&&t>0?Number.isNaN(e)?"fresh":e===1/0?"expired":0>e||t*(n.fresh??1)>e?"fresh":t*(n.aging??1.5)>e?"aging":t*(n.stale??3)>e?"stale":"expired":"fresh"}(t,n,e.thresholds);return{alpha:{...ki,...e.opacities??{}}[i],band:i,isStale:"fresh"!==i}}return t>n?{alpha:e.dimOpacity??.5,band:"stale",isStale:!0}:Si}var Mi=require("react/jsx-runtime");function _i({isStale:e,position:t}){return(0,Mi.jsx)("div",{className:"stream-staleness-badge",style:{position:"absolute",..."top-left"===t?{top:4,left:4}:"bottom-left"===t?{bottom:4,left:4}:"bottom-right"===t?{bottom:4,right:4}:{top:4,right:4},padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",zIndex:3,background:e?"#dc3545":"#28a745",color:"white"},children:e?"STALE":"LIVE"})}var Pi=require("react"),ji=g(require("react"));function Ci(...e){let t;for(const n of e)n&&(t=Ri(t)&&Ri(n)?{legendGroups:[...t.legendGroups,...n.legendGroups],legendDistance:n.legendDistance??t.legendDistance}:n);return t}function Ri(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function Li(e){return"object"==typeof e&&null!==e&&"gradient"in e}var Ti=16,Ii=6,$i=10,Oi=22,zi=100,Di=10;function Fi(e){return Math.ceil(7*e.length)}function Ei(e,t){if(Ri(e)){const n=Vi(t),o=e.legendGroups.flatMap(e=>[e.label?Fi(e.label):0,...e.items.map(e=>n.swatchSize+n.labelGap+Fi(e.label))]);return Math.max(zi,...o)}if(Li(e)){const{gradient:t}=e,n=t.format||(e=>Math.round(100*e)/100+""),o=Math.max(Fi(n(t.domain[0])),Fi(n(t.domain[1]))),i=t.label?Fi(t.label):0;return Math.max(zi,19+o,i)}return zi}function Ni(e){return(Ri(e)||Li(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):Di}function Bi(e){return Math.max(0,e?.sideGutter??0)}var Wi=22,Yi=46,qi=64;function Xi(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?qi:Yi:Wi:0}function Hi(e,t,n){if(Li(e))return e.gradient.label?34:26;if(!Ri(e))return 20;const o=Vi(n),i=Math.max(1,n?.maxWidth??t);let r=o.rowHeight;for(const t of e.legendGroups){let e=0,n=0;for(const r of t.items){const t=o.swatchSize+o.labelGap+Fi(r.label),s=0===n?t:n+o.itemGap+t;n>0&&s>i?(e+=1,n=t):n=s}t.items.length>0&&(e+=1),r=Math.max(r,e*o.rowHeight,t.label?Fi(t.label):0)}return r+(e.legendGroups.length>1?16:0)}function Gi(e,t){return Ei(e,t)+Ni(e)+Bi(t)}function Vi(e){const t=Math.max(1,e?.swatchSize??Ti),n=Math.max(t,e?.rowHeight??Oi);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??Ii),itemGap:Math.max(0,e?.itemGap??$i),rowHeight:n,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}function Ui(e,t){let n=24;return e.map(({hasLabel:e,itemCount:o})=>{n+=5;const i=n;let r;n+=8,e&&(n+=16,r=n,n+=8);const s=n;return n+=o*t+8,{lineY:i,labelY:r,itemsY:s,endY:n}})}var Ki=require("react/jsx-runtime"),Zi={fill:(e,t)=>(0,Ki.jsx)("rect",{style:e,width:t,height:t}),line:(e,t)=>(0,Ki.jsx)("line",{style:e,x1:0,y1:0,x2:t,y2:t})};function Qi(e,t,n,o,i){let r;return r="function"==typeof n?n(e):(0,Zi[n])(o(e,t),i),r}function Ji({swatchSize:e}){return(0,Ki.jsx)("path",{d:`M${.25*e},${.55*e} L${.45*e},${.75*e} L${.8*e},${.3*e}`,fill:"none",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}function er(e,t,n){return n&&n.size>0?n.has(e.label)?1:.3:null!=t?e.label===t?1:.3:1}var tr=(e,t,n,o,i,r,s,a,l,c,u)=>{const{type:d="fill",styleFn:h,items:f}=e,p=[];let g=0;const y=!(!t&&!n),m="isolate"===c||void 0===c&&null!=i,{swatchSize:x,labelGap:b,rowHeight:v}=u;return f.forEach((e,c)=>{const u=Qi(e,c,d,h,x),w=er(e,o,i),k=i&&i.size>0&&i.has(e.label);p.push((0,Ki.jsxs)("g",{transform:`translate(0,${g})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===r&&c===s?0:-1:void 0,role:y?"option":void 0,"aria-selected":y&&m?k||!1:void 0,"aria-current":y&&!m&&null!=o&&e.label===o||void 0,"aria-label":e.label,onKeyDown:y?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowDown"===n.key||"ArrowUp"===n.key){n.preventDefault();const e=(c+("ArrowDown"===n.key?1:-1)+f.length)%f.length;l(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:y?t=>{l(a,c),n&&n(e);const o=t.currentTarget.querySelector(".semiotic-legend-focus-ring");o&&o.setAttribute("visibility","visible")}:void 0,onBlur:y?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:y?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[y&&(0,Ki.jsx)("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:x+b+2+7*e.label.length,height:x+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),u,k&&(0,Ki.jsx)(Ji,{swatchSize:x}),(0,Ki.jsx)("text",{y:x/2,x:x+b,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+c)),g+=v}),p};function nr({config:e,orientation:t="vertical",width:n=100}){const{colorFn:o,domain:i,label:r,format:s}=e,a=s||(e=>Math.round(100*e)/100+""),l="grad-legend-"+ji.useId();if("horizontal"===t){const e=12,t=Math.min(n,200),s=Math.max(0,(n-t)/2),c=[];for(let e=0;64>=e;e++){const t=e/64;c.push((0,Ki.jsx)("stop",{offset:100*t+"%",stopColor:o(i[0]+t*(i[1]-i[0]))},e))}return(0,Ki.jsxs)("g",{"aria-label":r||"Gradient legend",children:[(0,Ki.jsx)("defs",{children:(0,Ki.jsx)("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),r&&(0,Ki.jsx)("text",{x:s+t/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),(0,Ki.jsx)("rect",{x:s,y:0,width:t,height:e,fill:`url(#${l})`,rx:2}),(0,Ki.jsx)("text",{x:s,y:e+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])}),(0,Ki.jsx)("text",{x:s+t,y:e+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])})]})}const c=[];for(let e=0;64>=e;e++){const t=e/64;c.push((0,Ki.jsx)("stop",{offset:100*t+"%",stopColor:o(i[1]-t*(i[1]-i[0]))},e))}return(0,Ki.jsxs)("g",{"aria-label":r||"Gradient legend",children:[r&&(0,Ki.jsx)("text",{x:0,y:-6,textAnchor:"start",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),(0,Ki.jsx)("defs",{children:(0,Ki.jsx)("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),(0,Ki.jsx)("rect",{x:0,y:0,width:14,height:100,fill:`url(#${l})`,rx:2}),(0,Ki.jsx)("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])}),(0,Ki.jsx)("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])})]})}function or(e){const{legendGroups:t,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:l=100,height:c=20,orientation:u="vertical",legendLayout:d}=e,h=Vi(d),[f,p]=ji.useState(0),[g,y]=ji.useState(0),m=ji.useCallback((e,t)=>{p(e),y(t)},[]),x="vertical"===u?(({legendGroups:e,width:t,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:l,legendInteraction:c,metrics:u})=>{const d=[],h=Ui(e.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),u.rowHeight);return e.forEach((e,f)=>{const p=h[f];d.push((0,Ki.jsx)("line",{stroke:"gray",x1:0,y1:p.lineY,x2:t,y2:p.lineY},"legend-top-line legend-symbol-"+f)),e.label&&null!=p.labelY&&d.push((0,Ki.jsx)("text",{y:p.labelY,className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label},"legend-text-"+f)),d.push((0,Ki.jsx)("g",{className:"legend-item",transform:`translate(0,${p.itemsY})`,children:tr(e,n,o,i,r,s,a,f,l,c,u)},"legend-group-"+f))}),d})({legendGroups:t||[],width:l,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:g,onFocusedIndexChange:m,legendInteraction:s,metrics:h}):(({legendGroups:e,height:t,width:n,customClickBehavior:o,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:l,onFocusedIndexChange:c,legendInteraction:u,metrics:d})=>{let h=0;const f=[];e.forEach((e,t)=>{let p=0;e.label&&(p+=16);const g=((e,t,n,o,i,r,s,a,l,c,u,d)=>{const{type:h="fill",styleFn:f,items:p}=e,g=[],{swatchSize:y,labelGap:m,itemGap:x,rowHeight:b,align:v}=u,w=!(!t&&!n),k="isolate"===c||void 0===c&&null!=i,S=p.map(e=>y+m+7*e.label.length),A=[];let M=0,_=0;S.forEach((e,t)=>{const n=0===_?e:_+x+e;d&&d>0&&_>0&&n>d?(A.push({start:M,end:t,width:_}),M=t,_=e):_=n}),p.length>0&&A.push({start:M,end:p.length,width:_}),A.forEach((e,c)=>{let u="center"===v?Math.max(0,((d??e.width)-e.width)/2):"end"===v?Math.max(0,(d??e.width)-e.width):0;for(let d=e.start;e.end>d;d++){const e=p[d],v=Qi(e,d,h,f,y),A=er(e,o,i),M=i&&i.size>0&&i.has(e.label);g.push((0,Ki.jsxs)("g",{transform:`translate(${u},${c*b})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===r&&d===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?M||!1:void 0,"aria-current":w&&!k&&null!=o&&e.label===o||void 0,"aria-label":e.label,onKeyDown:w?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowRight"===n.key||"ArrowLeft"===n.key){n.preventDefault();const e=(d+("ArrowRight"===n.key?1:-1)+p.length)%p.length;l(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:w?t=>{l(a,d),n&&n(e);const o=t.currentTarget.querySelector(".semiotic-legend-focus-ring");o&&o.setAttribute("visibility","visible")}:void 0,onBlur:w?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:A,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&(0,Ki.jsx)("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:y+m+2+7*e.label.length,height:y+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,M&&(0,Ki.jsx)(Ji,{swatchSize:y}),(0,Ki.jsx)("text",{y:y/2,x:y+m,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+d)),u+=S[d]+x}});const P=Math.max(0,...A.map(e=>e.width)),j=A.length;return{items:g,offset:P,totalRows:j,totalHeight:j*b}})(e,o,i,r,s,a,l,t,c,u,d,d.maxWidth??n);p+=g.offset+5,f.push({label:e.label,...g,offset:p,totalRows:g.totalRows,totalHeight:g.totalHeight}),h+=p+12});const p=d.maxWidth??n;let g=h>p?0:"center"===d.align?Math.max(0,(p-h)/2):"end"===d.align?Math.max(0,p-h):0;const y=[];return f.forEach((n,o)=>{const i=e[o];i.label&&(y.push((0,Ki.jsx)("text",{transform:`translate(${g},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:i.label},"legend-text-"+o)),g+=16),y.push((0,Ki.jsx)("g",{className:"legend-item",transform:`translate(${g},0)`,children:n.items},"legend-group-"+o)),g+=n.offset+5,e[o+1]&&y.push((0,Ki.jsx)("line",{stroke:"gray",x1:g,y1:-8,x2:g,y2:(n.totalHeight||t)+0+8},"legend-top-line legend-symbol-"+o)),g+=12}),(0,Ki.jsx)("g",{children:y})})({legendGroups:t||[],title:a,height:c,width:l,customClickBehavior:n,customHoverBehavior:o,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:g,onFocusedIndexChange:m,legendInteraction:s,metrics:h}),b=!(!n&&!o);return(0,Ki.jsxs)("g",{role:b?"listbox":void 0,"aria-multiselectable":!(!b||"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&&(0,Ki.jsx)("text",{className:"legend-title",y:16,x:l/2,textAnchor:"middle",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),x]})}var ir=require("react/jsx-runtime");function rr(e){const{legend:t,totalWidth:n,totalHeight:o,margin:i,legendPosition:r="right",legendLayout:s,legendHoverBehavior:a,legendClickBehavior:l,legendHighlightedCategory:c,legendIsolatedCategories:u,legendInteraction:d}=e;if(!t)return null;const h="top"===r||"bottom"===r,f=Math.max(0,n-i.left-i.right),p=Math.max(1,h?s?.maxWidth??f:Ei(t,s)),g=Ni(t),y=Bi(s),m=Xi(e.axisChrome,s),x=Xi(void 0,s),b=Hi(t,f,s);let v,w;if("left"===r)v=i.left-y-p-g,w=i.top;else if("top"===r)v=i.left,w=i.top-x-g-b;else if("bottom"===r){v=i.left;const e=o-i.bottom;w=Math.max(e+g,Math.min(e+m+g,o-b))}else v=n-i.right+y+g,w=i.top;return(0,ir.jsx)("g",{transform:`translate(${v}, ${w})`,children:Li(t)?(0,ir.jsx)(nr,{config:t.gradient,orientation:h?"horizontal":"vertical",width:p}):Ri(t)?(0,ir.jsx)(or,{legendGroups:t.legendGroups,title:"",width:p,orientation:h?"horizontal":"vertical",legendLayout:s,customHoverBehavior:a,customClickBehavior:l,highlightedCategory:c,isolatedCategories:u,legendInteraction:d}):t})}var sr=require("react"),ar=require("d3-array"),lr=require("react/jsx-runtime");function cr(e){return"string"==typeof e?{type:e}:e}function ur({orient:e,config:t,values:n,scale:o,size:i,length:r}){const s=function(e){return{type:e.type,bins:e.bins??20,fill:e.fill??"#4e79a7",fillOpacity:e.fillOpacity??.5,stroke:e.stroke??"none",strokeWidth:e.strokeWidth??1}}(t),a="top"===e||"bottom"===e,l=(0,sr.useMemo)(()=>{if(0===n.length)return null;const t=o.domain(),l=i-8;if("boxplot"===s.type){const t=function(e){const t=[...e].sort((e,t)=>e-t),n=t.length;if(0===n)return null;const o=t[Math.floor(.25*n)],i=t[Math.floor(.5*n)],r=t[Math.floor(.75*n)],s=r-o;return{q1:o,median:i,q3:r,whiskerLow:Math.max(t[0],o-1.5*s),whiskerHigh:Math.min(t[n-1],r+1.5*s)}}(n);if(!t)return null;const{q1:i,median:r,q3:c,whiskerLow:u,whiskerHigh:d}=t,h=Math.min(.5*l,20),f=(l-h)/2+4;if(a){const t=o(i),n=o(c),a=o(r),l=o(u),p=o(d),g="top"===e?-1:1,y=0;return(0,lr.jsxs)("g",{"data-testid":"marginal-boxplot-"+e,children:[(0,lr.jsx)("line",{x1:l,y1:y+g*(f+h/2),x2:p,y2:y+g*(f+h/2),stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:l,y1:y+g*f,x2:l,y2:y+g*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:p,y1:y+g*f,x2:p,y2:y+g*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("rect",{x:Math.min(t,n),y:"top"===e?y-f-h:y+f,width:Math.abs(n-t),height:h,fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:a,y1:"top"===e?y-f-h:y+f,x2:a,y2:"top"===e?y-f:y+f+h,stroke:s.fill,strokeWidth:2})]})}{const t=o(i),n=o(c),a=o(r),l=o(u),p=o(d),g="left"===e?-1:1,y=0;return(0,lr.jsxs)("g",{"data-testid":"marginal-boxplot-"+e,children:[(0,lr.jsx)("line",{x1:y+g*(f+h/2),y1:l,x2:y+g*(f+h/2),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:y+g*f,y1:l,x2:y+g*(f+h),y2:l,stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:y+g*f,y1:p,x2:y+g*(f+h),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),(0,lr.jsx)("rect",{x:"left"===e?y-f-h:y+f,y:Math.min(t,n),width:h,height:Math.abs(n-t),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),(0,lr.jsx)("line",{x1:"left"===e?y-f-h:y+f,y1:a,x2:"left"===e?y-f:y+f+h,y2:a,stroke:s.fill,strokeWidth:2})]})}}const c=(0,ar.bin)().domain(t).thresholds(s.bins)(n);if(0===c.length)return null;const u=we(c.map(e=>e.length));if(0===u)return null;if("histogram"===s.type)return(0,lr.jsx)("g",{"data-testid":"marginal-histogram-"+e,children:c.map((t,n)=>{if(null==t.x0||null==t.x1)return null;const i=t.length/u*l;if(a){const r=o(t.x0),a=o(t.x1)-o(t.x0);return(0,lr.jsx)("rect",{x:r,y:"top"===e?-4-i:4,width:Math.max(a,.5),height:i,fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},n)}{const r=o(t.x0),a=o(t.x1)-o(t.x0);return(0,lr.jsx)("rect",{x:"left"===e?-4-i:4,y:Math.min(r,r+a),width:i,height:Math.abs(a),fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},n)}})});if("violin"===s.type){const t=l/2+4,n=[];for(const i of c){if(null==i.x0||null==i.x1)continue;const r=i.length/u*(l/2),s=o((i.x0+i.x1)/2);n.push(a?`${s},${"top"===e?-(t-r):t-r}`:`${"left"===e?-(t-r):t-r},${s}`)}for(let i=c.length-1;i>=0;i--){const r=c[i];if(null==r.x0||null==r.x1)continue;const s=r.length/u*(l/2),d=o((r.x0+r.x1)/2);n.push(a?`${d},${"top"===e?-(t+s):t+s}`:`${"left"===e?-(t+s):t+s},${d}`)}return(0,lr.jsx)("g",{"data-testid":"marginal-violin-"+e,children:(0,lr.jsx)("polygon",{points:n.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}if("ridgeline"===s.type){const t=[];if(a){const n=0,i=null!=c[0].x0?o(c[0].x0):0;t.push(`M${i},${n}`);for(const n of c){if(null==n.x0||null==n.x1)continue;const i=n.length/u*l,r=o((n.x0+n.x1)/2);t.push(`L${r},${"top"===e?-i-4:i+4}`)}const s=null!=c[c.length-1].x1?o(c[c.length-1].x1):r;t.push(`L${s},${n}`),t.push("Z")}else{const n=0,i=null!=c[0].x0?o(c[0].x0):0;t.push(`M${n},${i}`);for(const n of c){if(null==n.x0||null==n.x1)continue;const i=n.length/u*l,r=o((n.x0+n.x1)/2);t.push(`L${"left"===e?-i-4:i+4},${r}`)}const s=null!=c[c.length-1].x1?o(c[c.length-1].x1):r;t.push(`L${n},${s}`),t.push("Z")}return(0,lr.jsx)("g",{"data-testid":"marginal-ridgeline-"+e,children:(0,lr.jsx)("path",{d:t.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}return null},[n,o,s,i,r,e,a,4]);return l?(0,lr.jsx)("g",{className:"marginal-"+e,"data-testid":"marginal-"+e,children:l}):null}var dr=g(require("react")),hr=require("react/jsx-runtime");function fr(e,t=120,n=8){if(!e)return[];const o=Math.max(1,Math.floor(t/n)),i=e.split(/\s+/),r=[];let s="";for(const e of i)s&&s.length+1+e.length>o?(r.push(s),s=e):s=s?`${s} ${e}`:e;return s&&r.push(s),r}function pr(e,t,n,o){return"curly"===e?o?`M0,0 C${.6*n},0 ${.4*n},${t/2} ${n},${t/2} C${.4*n},${t/2} ${.6*n},${t} 0,${t}`:`M0,0 C0,${.6*n} ${t/2},${.4*n} ${t/2},${n} C${t/2},${.4*n} ${t},${.6*n} ${t},0`:o?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function gr(e,t,n,o){if(!e)return(0,hr.jsx)("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=e;if(!i&&!r)return(0,hr.jsx)("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>t?"right":"left":0>n?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>t?"end":"start";const f=16,p=r?c?[r]:fr(r,l):[],g=i?c?[i]:fr(i,l):[],y="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=o||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";e.useHTML||e.html?x.push((0,hr.jsx)("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(f,(p.length+g.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:(0,hr.jsxs)("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&(0,hr.jsx)("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&(0,hr.jsx)("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(x.push((0,hr.jsx)("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:p.map((e,t)=>(0,hr.jsx)("tspan",{x:y,dy:0===t?0:f,children:e},t))},"annotation-note-title")),m=p.length*f),g.length>0&&x.push((0,hr.jsx)("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:g.map((e,t)=>(0,hr.jsx)("tspan",{x:y,dy:0===t?0:f,children:e},t))},"annotation-note-label")));let v=null;if((r||i)&&(0!==t||0!==n))if("topBottom"===u){const e=Math.min(l,120);let t=0,n=e;"end"===h?(t=-e,n=0):"middle"===h&&(t=-e/2,n=e/2),v=(0,hr.jsx)("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}else{const e=(p.length+g.length)*f+(g.length>0?f:0);let t=0,n=e;"bottom"===d?(t=-e,n=0):"middle"===d&&(t=-e/2,n=e/2),v=(0,hr.jsx)("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+g.length-1)*f;let k=0;return"topBottom"===u?k=0>n?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(g.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>n?-(w+2):18),(0,hr.jsxs)("g",{className:"annotation-note",transform:`translate(${t},${n})`,children:[(0,hr.jsx)("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function yr(e,t,n,o,i){const r=[];switch(e){case"callout-circle":{const e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&r.push((0,hr.jsx)("circle",{r:e,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const e=t?.width||0,o=t?.height||0;(e>0||o>0)&&r.push((0,hr.jsx)("rect",{width:e,height:o,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":t?.custom&&r.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=o||0,s=i||0;if(void 0!==t?.x){const o=(t.x||0)-e;r.push((0,hr.jsx)("line",{x1:o,y1:(t.y1||0)-s,x2:o,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==t?.y){const o=(t.y||0)-s;r.push((0,hr.jsx)("line",{x1:(t.x1||0)-e,y1:o,x2:(t.x2||0)-e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==t?.x1||void 0!==t?.x2?r.push((0,hr.jsx)("line",{x1:(t.x1||0)-e,y1:0,x2:(t.x2||0)-e,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===t?.y1&&void 0===t?.y2||r.push((0,hr.jsx)("line",{x1:0,y1:(t.y1||0)-s,x2:0,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const e=t?.type||"curly",o=t?.width??t?.height;void 0!==o&&r.push((0,hr.jsx)("path",{d:pr(e,o,t?.depth||30,void 0===t?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return(0,hr.jsx)("g",{className:"annotation-subject",children:r})}function mr(e,t,n,o,i,r){const s=[];let a=0,l=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const n=r.width||0,o=r.height||0;if(n>0||o>0){const i=n/2,r=o/2,s=e-i,c=t-r;if(0!==s||0!==c){const e=Math.abs(s),t=Math.abs(c),u=n/2,d=o/2,h=e*d>t*u?u/e:d/t;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const e=r.width,t=r.height,n=r.depth||30;void 0!==e?(a=e/2,l=n):void 0!==t&&(a=n,l=t/2)}}else{const n=(r.radius||0)+(r.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const o=Math.atan2(t,e);a=Math.cos(o)*n,l=Math.sin(o)*n}}const c=Math.sqrt((e-a)**2+(t-l)**2);if(c>.5){const i=o||"var(--semiotic-text-secondary, currentColor)",r="curve"===n?.type;let u=Math.atan2(t-l,e-a);if(r){const o=(a+e)/2,r=(l+t)/2,d=-(t-l)/c,h=(e-a)/c,f=(n?.curve??.25)*c,p=o+d*f,g=r+h*f;s.push((0,hr.jsx)("path",{className:"connector-curve",d:`M${a},${l}Q${p},${g} ${e},${t}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,p-a)}else s.push((0,hr.jsx)("line",{x1:a,y1:l,x2:e,y2:t,stroke:i},"connector-line"));if("arrow"===n?.end){const e=10,t=16/180*Math.PI;s.push((0,hr.jsx)("path",{d:`M${a},${l}L${a+e*Math.cos(u+t)},${l+e*Math.sin(u+t)}L${a+e*Math.cos(u-t)},${l+e*Math.sin(u-t)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return(0,hr.jsx)("g",{className:"annotation-connector",children:s})}function xr(e){const{x:t=0,y:n=0,dx:o,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:g,events:y={},"data-testid":m}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(f)?f:[]);let w=o||0,k=i||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const S="string"==typeof u?u:"label";if("bracket"===S&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const e=c.depth||30;k=e+(0>e?-5:5)}else if(void 0!==c.height){const e=c.depth||30;w=e+(0>e?-5:5),k=c.height/2}return(0,hr.jsxs)("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&mr(w,k,l,d,S,c),!v.has("subject")&&yr(S,c,d,x,b),!v.has("note")&&gr(a,w,k,d)]})}function br(e){const{noteData:t}=e,{screenCoordinates:n}=t,o="string"==typeof t.type?t.type:"label",i=t.eventListeners||t.events||{};if(t.coordinates&&n){const e=t.nx||n[0][0]+(t.dx??0),i=t.ny||n[0][1]+(t.dy??0),r=n.map((n,r)=>{const s=Object.assign({},t,{note:0===r?t.note:{label:""},x:n[0],y:n[1],nx:e,ny:i});return(0,hr.jsx)(xr,{"data-testid":"semiotic-annotation",...s,type:o},"multi-annotation-"+r)});return(0,hr.jsx)("g",{children:r})}const r=t.note||{title:"none",label:t.label},s=`${r.label}-${r.title}-${t.i}`;return(0,hr.jsx)(xr,{"data-testid":"semiotic-annotation",events:i,...t,type:o},s)}var vr=require("d3-hierarchy"),wr=require("d3-shape");function kr(e,t){const n=t.scales?.x??t.scales?.time;return n?null!=e.x?n(e.x):t.xAccessor&&null!=e[t.xAccessor]?n(e[t.xAccessor]):null:null}function Sr(e,t){const n=t.scales?.y??t.scales?.value;return n?null!=e.y?n(e.y):t.yAccessor&&null!=e[t.yAccessor]?n(e[t.yAccessor]):null:null}function Ar(e){return null==e?null:e+""}function Mr(e,t,n){return t.stickyPositionCache?.set(e,n),n}function _r(e,t,n){const o=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===o){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let o=n.pointNodes.length-1;o>=0;o--){const i=n.pointNodes[o];if(i.pointId===e.pointId)return Mr(t,n,{x:i.x,y:i.y})}const o=function(e){const t=e.data;if(!t||0===t.length)return null;const n=t[t.length-1],o=e.scales?.x??e.scales?.time,i=e.scales?.y??e.scales?.value;if(!o||!i)return null;const r=n[e.xAccessor||"x"],s=n[e.yAccessor||"y"];return null==r||null==s?null:{x:o(r),y:i(s)}}(n);return o?Mr(t,n,o):null}if("semantic"===o){const o=function(e,t,n){const o=function(e){return Ar(e.provenance?.stableId??e.stableId)}(e);if(!o)return null;const i=n.pointNodes?.find(e=>Ar(e.pointId)===o);if(i)return Mr(t,n,{x:i.x,y:i.y});const r=n.data?.find(e=>function(e){return Ar(e.stableId??e.id??e.provenance?.stableId)}(e)===o);if(!r)return null;const s=kr(r,n),a=Sr(r,n);return null==s||null==a?null:Mr(t,n,{x:s,y:a})}(e,t,n);if(o)return o}let i=null,r=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(i=t.x,r=t.y)}if(null!=i&&null!=r||(i=kr(e,n),r=Sr(e,n)),null!=i&&null!=r)return Mr(t,n,{x:i,y:r});if("sticky"===o){const e=n.stickyPositionCache?.get(t);if(e)return e}return null}function Pr(e,t,n,o=50){return!(-o>e||e>(n.width||0)+o||-o>t||t>(n.height||0)+o)}var jr=require("react/jsx-runtime"),Cr={secondary:0,primary:3},Rr=1,Lr=2,Tr=.6,Ir="0.88em",$r=.95,Or=.72,zr=.06,Dr=".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}}",Fr=".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}";function Er(e){return!0===e?._annotationDeferred}function Nr(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Br(e){const t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function Wr(e){return Math.max(Or,$r-e*zr)}var Yr=g(require("react")),[qr,Xr]=Be(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const n=e.observations;return n.push(t),n.length>e.maxObservations&&n.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}}));function Hr(e,t={}){const n=function(e){const t=e.provenance,n=e.id??e.stableId??t?.stableId;return null==n||""===n?void 0:n+""}(e);return{"data-semiotic-annotation-widget":"",...n?{"data-semiotic-annotation-id":n}:{},onClickCapture(o){const i=function(e){const t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(o);t.onAnnotationActivate?.({annotation:e,annotationId:n,chartId:t.chartId,inputType:i}),n&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:n,inputType:i,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}var Gr=require("react/jsx-runtime"),Vr="var(--semiotic-bg, #ffffff)",Ur=.85;function Kr(e){const{x:t,y:n,text:o,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{type:e.type??"halo",...e}}(u),f=e=>(0,Gr.jsx)("text",{x:t,y:n,textAnchor:l,dominantBaseline:c,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...e?{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}:{},children:o});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??Vr,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},g="number"==typeof p?p:p.x,y="number"==typeof p?p:p.y,m=function(e,t){return(e+"").length*t*.6}(o,r),x=r+2*y;let b,v;return b="middle"===l?t-m/2-g:"end"===l?t-m-g:t-g,v="middle"===c||"central"===c?n-x/2:"hanging"===c||"text-before-edge"===c?n-y:n-.8*r-y,(0,Gr.jsxs)("g",{className:d,children:[(0,Gr.jsx)("rect",{x:b,y:v,width:m+2*g,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Vr,fillOpacity:h.opacity??Ur,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}var Zr=require("react/jsx-runtime"),Qr={linear:wr.curveLinear,monotoneX:wr.curveMonotoneX,monotoneY:wr.curveMonotoneY,step:wr.curveStep,stepAfter:wr.curveStepAfter,stepBefore:wr.curveStepBefore,basis:wr.curveBasis,cardinal:wr.curveCardinal,catmullRom:wr.curveCatmullRom};function Jr(e,t,n,o){const i=[];return e.forEach((e,r)=>{let s;if(n){const i=n(e,r,o);s=null!=i?i:t(e,r,o)}else s=t(e,r,o);s&&i.push({node:s,annotation:e})}),function(e){const t=e.map((e,t)=>{return{p:e,i:t,emphasis:(n=e.annotation,"primary"===n?.emphasis||"secondary"===n?.emphasis?n.emphasis:null),confidence:Br(e.annotation),readingOrder:null,rank:Rr};var n}),n=t.some(e=>null!=e.emphasis||null!=e.confidence),o=e.some(e=>Er(e.annotation)),i=e.some(e=>null!=Nr(e.annotation)),r=e.some(e=>"layer"===Nr(e.annotation));if(!n&&!o&&!i)return e.map(e=>e.node);const s=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);s.forEach((e,t)=>{e.readingOrder=t,e.rank=Lr-t/Math.max(1,s.length)});for(const e of t)e.emphasis&&(e.rank=Cr[e.emphasis]);const a=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{const{p:t,i:n,emphasis:o,readingOrder:i}=e,r=Er(t.annotation);let s=t.node;if("primary"===o||"secondary"===o||null!=i){const e=null==o&&null!=i;s=(0,jr.jsx)("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+o,..."secondary"===o?{opacity:Tr,fontSize:Ir}:{},...e?{opacity:Wr(i),"data-annotation-reading-order":i}:{},children:t.node},"annotation-emphasis-"+n)}const a=Nr(t.annotation);return a&&(s=(0,jr.jsx)("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),r&&(s=(0,jr.jsx)("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return o&&a.unshift((0,jr.jsx)("style",{children:Dr},"annotation-disclosure-style")),r&&a.unshift((0,jr.jsx)("style",{children:Fr},"annotation-cohesion-style")),a}(i)}var es=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function ts(e){return!!e&&"object"==typeof e&&es.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}new Set(["label","callout","callout-circle","callout-rect"]);var ns=2e4,os=1;function is(e){return"primary"===e?.emphasis||!0===e?.defensive}function rs(e,t,n={}){return"number"==typeof n.maxAnnotations&&Number.isFinite(n.maxAnnotations)?Math.max(0,Math.floor(n.maxAnnotations)):e>0&&t>0?Math.max(1,Math.round(e*t/(n.areaPerAnnotation&&n.areaPerAnnotation>0?n.areaPerAnnotation:ns))):1/0}function ss(e){let t;const n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;const o=e?.provenance?.confidence;switch("number"==typeof o&&Number.isFinite(o)&&(t+=15*Math.max(0,Math.min(1,o))),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}var as=32,ls=6,cs=4,us=8,ds=72,hs=30,fs=-30,ps=8,gs=480,ys=3;var ms={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function xs(e){if(!bs(e))return e;const t=("string"==typeof e.mobileText?e.mobileText:void 0)??("string"==typeof e.shortText?e.shortText:void 0);return!t||"string"!=typeof e.label&&null!=e.label?e:{...e,label:t}}function bs(e){return ts(e)}function vs(e,t){if(!e)return[];const n=Math.max(1,Math.floor(t/7)),o=e.split(/\s+/).filter(Boolean),i=[];let r="";for(const e of o)r&&r.length+e.length+1>n?(i.push(r),r=e):r=r?`${r} ${e}`:e;return r&&i.push(r),i}function ws(e,t,n,o,i){const r=e+n,s=t+o;return Math.abs(n)>Math.abs(o)?{x:0>n?r-i.width-4:r+4,y:0>o?s-i.height:s,width:i.width,height:i.height}:{x:0>n?r-i.width:r,y:0>o?s-i.height-4:s+4,width:i.width,height:i.height}}function ks(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Ss(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function As(e,t,n,o,i,r,s,a){const l=ks(e,s);let c=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,o){const i=Math.max(0,o-e.x),r=Math.max(0,o-e.y);return(i+Math.max(0,e.x+e.width-(t-o)))*e.height+(r+Math.max(0,e.y+e.height-(n-o)))*e.width}(l,i,r,a);for(const e of n)c+=12*Ss(l,e);for(const e of o)c+=4*Ss(l,e);return c}function Ms(e){const{annotations:t,context:n,defaultOffset:o=as,notePadding:i=ls,markPadding:r=cs,edgePadding:s=us,preserveManualOffsets:a=!0,routeLongConnectors:l=!0,connectorThreshold:c=ds,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:f,mobile:p,cohesion:g,audience:y}=e,m=n.width||0,x=n.height||0,b="object"==typeof p?p:{},v=b.breakpoint??gs,w=!!p&&v>=m,k=w&&!1!==b.preferShortText?t.map(xs):t,S=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!f?b.responsive??{minWidth:v}:f,_=w&&!g?b.cohesion:g;if(0===k.length||0>=m||0>=x)return k.slice();const P=[],j=function(e,t){return(e.pointNodes||[]).map(e=>{const n=Math.max(1,e.r||1)+t;return{x:e.x-n,y:e.y-n,width:2*n,height:2*n}})}(n,r);let C=!1;const R=k.map((e,t)=>{if(!bs(e))return e;const r=function(e,t,n){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};const o=e.pointId??e.nodeId;if(null!=o&&n.pointNodes){const e=n.pointNodes.find(e=>e.pointId===o);if(e)return{x:e.x,y:e.y}}const i=e.coordinates,r=n.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&r){const e=i[0],t=i[1];if("number"==typeof e&&"number"==typeof t){const n=r([e,t]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof e.x||"number"!=typeof e.y?_r(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!r)return e;const u=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};const t="number"==typeof e.wrap?e.wrap:120,n=[...vs("string"==typeof e.title?e.title:void 0,t),...vs("string"==typeof e.label?e.label:void 0,t)],o=n.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(t,7*o)+10),height:Math.max(18,16*n.length+6)}}(e);if(a&&("number"==typeof(d=e).dx||"number"==typeof d.dy)){const t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:hs,dy:fs}}(e);return P.push(ks(ws(r.x,r.y,"number"==typeof e.dx?e.dx:t.dx,"number"==typeof e.dy?e.dy:t.dy,u),i)),e}var d;let h=null,f=1/0;for(const e of function(e){const t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}(o)){const t=As(ws(r.x,r.y,e.dx,e.dy,u),e,P,j,m,x,i,s);f>t&&(h=e,f=t)}if(!h)return e;const p=ks(ws(r.x,r.y,h.dx,h.dy,u),i);P.push(p);const g=Math.hypot(h.dx,h.dy),y=l&&g>=c&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return C=!0,{...e,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),L=C?R:k.slice();let T=L;if(h){let e=!1;const t=L.map(t=>{const n=function(e){return"text"!==e.type||"string"!=typeof e.color||Math.hypot("number"==typeof e.dx?e.dx:0,"number"==typeof e.dy?e.dy:0)<ps?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});T=e?t:L}{let e=!1;const t=T.map(t=>{if(!0!==t?.defensive)return t;const n=function(e){const t=e?.provenance;if(!t||"object"!=typeof t)return e;const n="string"==typeof t.source?ms[t.source]??t.source:null,o="number"==typeof t.confidence&&Number.isFinite(t.confidence)?Math.round(100*Math.max(0,Math.min(1,t.confidence)))+"%":null;if(!n&&!o)return e;if(null!=e.label&&"string"!=typeof e.label)return e;const i=[n,o].filter(Boolean).join(" · "),r="string"==typeof e.label?e.label:"";return r.includes(`(${i})`)?e:{...e,label:r?`${r} (${i})`:`(${i})`}}(t);return n!==t&&(e=!0),n});T=e?t:T}const I=new Set;if(S){const e="object"==typeof S?S:{},t=function(e){if(!e)return 1;const t=function(e){const t=e?.familiarity;if(!t)return ys;const n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?ys:n.reduce((e,t)=>e+t,0)/n.length}(e);return t>2?4>t?1:.6:1.5}(y),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??rs(m,x,e))*t))},{deferred:o}=function(e){const{annotations:t,width:n,height:o}=e,i=Math.max(0,e.minVisible??os),r=rs(n,o,e),s=t.map((e,t)=>{return{annotation:e,index:t,note:(n=e,ts(n))};var n}),a=s.filter(e=>e.note);if(0===a.length||r>=a.length)return{visible:t.slice(),deferred:[],budget:r};const l=a.filter(e=>is(e.annotation)),c=a.filter(e=>!is(e.annotation)).sort((e,t)=>ss(t.annotation)-ss(e.annotation)||e.index-t.index),u=Math.min(c.length,Math.max(Math.max(0,r-l.length),Math.max(0,i-l.length))),d=new Set([...l.map(e=>e.index),...c.slice(0,u).map(e=>e.index)]),h=[],f=[];for(const{annotation:e,index:t,note:n}of s)!n||d.has(t)?h.push(e):f.push(e);return{visible:h,deferred:f,budget:r}}({annotations:T,width:m,height:x,...n});for(const e of o)I.add(e)}if(M&&("object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:gs)>=m)for(const e of T)bs(e)&&"secondary"===e.emphasis&&I.add(e);if(I.size>0)for(const e of T)!0===e?.defensive&&I.delete(e);let $;return $=0===I.size?T:A?T.map(e=>I.has(e)?{...e,_annotationDeferred:!0}:e):T.filter(e=>!I.has(e)),_?function(e,t){let n=!1;const o=e.map(e=>bs(e)?"blended"===e.cohesion||"layer"===e.cohesion?e:(n=!0,{...e,cohesion:t}):e);return n?o:e}($,_):$}function _s(e,t={}){const n=!0===t.showRetractedAnnotations,o=!0===t.showSupersededAnnotations,i=new Set;for(const t of e){const e=t?.lifecycle?.supersedes;e&&"retracted"!==t?.lifecycle?.status&&i.add(e)}return e.filter(e=>{if("retracted"===e?.lifecycle?.status&&!n)return!1;const t=e?.provenance?.stableId;return!(t&&i.has(t)&&!o)})}var Ps=require("react"),js={positions:new Map},Cs=new Set;function Rs(){for(const e of Cs)e()}function Ls(e,t){const n=js.positions.get(e);if(n?.locked)return;if(!n||n.sourceId!==t)return;const o=new Map(js.positions);o.delete(e),js={positions:o},Rs()}function Ts(e,t){const n=js.positions.get(e);if(!n?.locked)return;if(t&&n.sourceId!==t)return;const o=new Map(js.positions);o.delete(e),js={positions:o},Rs()}function Is(){return js}function $s(e){return Cs.add(e),()=>Cs.delete(e)}var Os={positions:new Map};function zs(){return()=>{}}function Ds(){return Os}function Fs(e,t,n){return"exact"===n?function(e,t){const n=e.domain(),o=n[0],i=n[n.length-1],r=o instanceof Date,s=o instanceof Date?o.getTime():o,a=i instanceof Date?i.getTime():i;if(2>t||s===a)return r?[new Date(s),new Date(a)]:[s,a];const l=(a-s)/(t-1),c=Array(t);for(let e=0;t>e;e++){const n=e===t-1?a:s+e*l;c[e]=r?new Date(n):n}return c}(e,t):e.ticks(t)}function Es(e,t,n){if("edges"===e){if(t)return"start";if(n)return"end"}return"middle"}function Ns(e,t,n){if("edges"===e){if(t)return"hanging";if(n)return"auto"}return"middle"}function Bs(e){if(0===e.length)return{min:null,max:null};let t=1/0,n=-1/0;for(const o of e)t>o.pixel&&(t=o.pixel),o.pixel>n&&(n=o.pixel);return{min:t,max:n}}function Ws(e){if(e)return"dashed"===e?"6,4":"dotted"===e?"2,4":e}function Ys(e,t,n){if("left"===e||"right"===e){const o="left"===e?n:0,i="left"===e?-1:1,r=Math.ceil(t/8);let s="M0,"+o;for(let e=0;r>e;e++){const n=8*(e+1);s+=`L${Math.min(8*e+4,t)},${o+4*i}`,s+=`L${Math.min(n,t)},${o}`}return s}const o="bottom"===e?0:t,i="bottom"===e?1:-1,r=Math.ceil(n/8);let s=`M${o},0`;for(let e=0;r>e;e++){const t=8*(e+1);s+=`L${o+4*i},${Math.min(8*e+4,n)}`,s+=`L${o},${Math.min(t,n)}`}return s}var qs=36,Xs=34,Hs=58,Gs=22;function Vs(e){return"string"==typeof e&&e.length>0}function Us(e,t,n=!1){const o=n?t?Hs:Xs:t?qs:0;return o>e.top?{...e,top:o}:e}function Ks(e,t){return Us(e,Vs(t))}var Zs=require("react/jsx-runtime");function Qs(e){const{width:t,height:n,totalWidth:o,totalHeight:i,margin:r,scales:s,showAxes:a,axes:l,showGrid:c,xFormat:u,yFormat:d,axisExtent:h}=e,f=(0,Pi.useMemo)(()=>{if(!s)return[];const e=l?.find(e=>"bottom"===e.orient),n=l?.find(e=>"top"===e.orient),o=e??n,i=o?.extent??h,r=o?.tickFormat||u||Js,a=Math.max(2,Math.floor(t/70)),c=o?.ticks??5,d="exact"===i?Math.max(2,c):Math.min(c,a),f=o?.tickValues??Fs(s.x,d,i),p=f.map(e=>e.valueOf()),g=f.map((e,t)=>({value:e,pixel:s.x(e),label:r(e,t,p)})),y=g.reduce((e,t)=>Math.max(e,"string"==typeof t.label?6.5*t.label.length:"number"==typeof t.label?6.5*(t.label+"").length:60),0);return ea(g,Math.max(55,y+8))},[s,l,u,t,h]),p=(0,Pi.useMemo)(()=>{if(!s)return[];const e=l?.find(e=>"left"===e.orient),t=e?.extent??h,o=e?.tickFormat||d||Js,i=Math.max(2,Math.floor(n/30)),r=e?.ticks??5,a="exact"===t?Math.max(2,r):Math.min(r,i);return ea((e?.tickValues??Fs(s.y,a,t)).map(e=>({value:e,pixel:s.y(e),label:o(e)})),22)},[s,l,d,n,h]),g=c&&s,y=a&&s;if(!g&&!y)return null;const m=l?.find(e=>"bottom"===e.orient),x=l?.find(e=>"left"===e.orient),b=y&&(!m||!1!==m.baseline),v=y&&(!x||!1!==x.baseline),w=m?.jaggedBase||!1,k=x?.jaggedBase||!1,S="var(--semiotic-border, #ccc)";return(0,Zs.jsx)("svg",{width:o,height:i,style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:(0,Zs.jsxs)("g",{transform:`translate(${r.left},${r.top})`,children:[g&&(()=>{const e=Ws(l?.find(e=>"bottom"===e.orient)?.gridStyle),o=Ws(l?.find(e=>"left"===e.orient)?.gridStyle),i=!1!==l?.find(e=>"bottom"===e.orient)?.grid,r=!1!==l?.find(e=>"left"===e.orient)?.grid;return(0,Zs.jsxs)("g",{className:"stream-grid",children:[i&&f.map((t,o)=>(0,Zs.jsx)("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:n,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:e},"xgrid-"+o)),r&&p.map((e,n)=>(0,Zs.jsx)("line",{x1:0,y1:e.pixel,x2:t,y2:e.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:o},"ygrid-"+n))]})})(),b&&!w&&(0,Zs.jsx)("line",{x1:0,y1:n,x2:t,y2:n,stroke:S,strokeWidth:1}),w&&(0,Zs.jsx)("path",{d:Ys("bottom",t,n),fill:"none",stroke:S,strokeWidth:1}),v&&!k&&(0,Zs.jsx)("line",{x1:0,y1:0,x2:0,y2:n,stroke:S,strokeWidth:1}),k&&(0,Zs.jsx)("path",{d:Ys("left",t,n),fill:"none",stroke:S,strokeWidth:1})]})})}function Js(e,t,n){return e instanceof Date?`${e.toLocaleString("en",{month:"short"})} ${e.getDate()}`:"number"==typeof e?Math.round(100*e)/100+"":e+""}function ea(e,t){if(2>=e.length)return e;const n=[e[0]];for(let o=1;e.length-1>o;o++)t>Math.abs(e[o].pixel-n[n.length-1].pixel)||n.push(e[o]);const o=e[e.length-1];return t>Math.abs(o.pixel-n[n.length-1].pixel)?n[n.length-1]=o:n.push(o),n}function ta(e){const{width:t,height:n,totalWidth:o,totalHeight:i,margin:r,scales:s,showAxes:a,axes:l,xLabel:c,yLabel:u,yLabelRight:d,xFormat:h,yFormat:f,axisExtent:p,showGrid:g,title:y,legend:m,legendHoverBehavior:x,legendClickBehavior:b,legendHighlightedCategory:v,legendIsolatedCategories:w,legendPosition:k="right",legendLayout:S,foregroundGraphics:A,marginalGraphics:M,xValues:_,yValues:P,annotations:j,onAnnotationActivate:C,onObservation:R,chartId:L,chartType:T,autoPlaceAnnotations:I,svgAnnotationRules:$,xAccessor:O,yAccessor:z,annotationData:D,pointNodes:F,curve:E,underlayRendered:N,canvasObscuresUnderlay:B=!0,linkedCrosshairName:W,linkedCrosshairSourceId:Y,children:q}=e,X=function(e){const t=Xr(e=>e.pushObservation),n=Yr.useCallback(n=>{e.onObservation?.(n),t?.(n)},[e,t]);return Yr.useMemo(()=>({...e,onObservation:n}),[n,e])}({onAnnotationActivate:C,onObservation:R,chartId:L,chartType:T}),H=Bi(S),G=m&&"left"===k&&H>0?H:r.left,V=m&&"right"===k&&H>0?H:r.right,U=(0,Pi.useMemo)(()=>{if(!a||!s)return[];const e=l?.find(e=>"bottom"===e.orient),n=l?.find(e=>"top"===e.orient),o=e??n,i=o?.extent??p,r=o?.tickFormat||h||Js,c=Math.max(2,Math.floor(t/70)),u=o?.ticks??5,d="exact"===i?Math.max(2,u):Math.min(u,c),f=o?.tickValues??Fs(s.x,d,i),g=f.map(e=>e.valueOf()),y=f.map((e,t)=>({value:e,pixel:s.x(e),label:r(e,t,g)})),m=y.reduce((e,t)=>Math.max(e,"string"==typeof t.label?6.5*t.label.length:"number"==typeof t.label?6.5*(t.label+"").length:60),0),x=o?.autoRotate?Math.max(20,Math.min(m+8,55)):Math.max(55,m+8);let b=ea(y,x);if(b.length>1&&(b=b.filter((e,t)=>0===t||e.label+""!=b[t-1].label+"")),o?.includeMax&&b.length>0&&"exact"!==i&&!o?.tickValues){const e=s.x.domain()[1],t=s.x(e),n=b[b.length-1].pixel;if(Math.abs(t-n)>1){const o=r(e,b.length,g);x>t-n&&b.length>1&&(b=b.slice(0,-1)),b.push({value:e,pixel:t,label:o})}}return b},[a,s,l,h,t,p]),K=(0,Pi.useMemo)(()=>{const e=l?.find(e=>"bottom"===e.orient);if(!e?.autoRotate||1>=U.length)return!1;const n=t/Math.max(U.length-1,1);return U.reduce((e,t)=>Math.max(e,"string"==typeof t.label?6.5*t.label.length:60),0)+8>n},[l,U,t]),Z=(0,Pi.useMemo)(()=>{if(!a||!s)return[];const e=l?.find(e=>"left"===e.orient),t=e?.extent??p,o=e?.tickFormat||f||Js,i=Math.max(2,Math.floor(n/30)),r=e?.ticks??5,c="exact"===t?Math.max(2,r):Math.min(r,i);let u=ea((e?.tickValues??Fs(s.y,c,t)).map(e=>({value:e,pixel:s.y(e),label:o(e)})),22);if(u.length>1&&(u=u.filter((e,t)=>0===t||e.label+""!=u[t-1].label+"")),e?.includeMax&&u.length>0&&"exact"!==t&&!e?.tickValues){const e=s.y.domain()[1],t=s.y(e),n=u[u.length-1].pixel;if(Math.abs(t-n)>1){const i=o(e);22>Math.abs(t-n)&&u.length>1&&(u=u.slice(0,-1)),u.push({value:e,pixel:t,label:i})}}return u},[a,s,l,f,n,p]),Q=(0,Pi.useMemo)(()=>{if(!a||!s)return[];const e=l?.find(e=>"right"===e.orient);if(!e)return[];const t=e.extent??p,o=e.tickFormat||f||Js,i=Math.max(2,Math.floor(n/30)),r=e.ticks??5;return ea((e.tickValues??Fs(s.y,"exact"===t?Math.max(2,r):Math.min(r,i),t)).map(e=>({value:e,pixel:s.y(e),label:o(e)})),22)},[a,s,l,f,n,p]),J=(0,Pi.useRef)(new Map),ee=(0,Pi.useRef)(j?.length??0),te=j?.length??0;ee.current!==te&&(ee.current=te,J.current=new Map);const ne=(0,Pi.useMemo)(()=>{if(!j||0===j.length)return null;const e=_s(j),o=function(e,t={}){return function(e,n,o){switch(e.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const t=_r(e,n,o);if(!t)return null;const{x:i,y:r}=t;if(!Pr(i,r,o))return null;const s="callout"===e.type?"callout-circle":e.type,a="callout-circle"===s?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===s?{width:e.width,height:e.height}:void 0;return(0,Zr.jsx)(br,{noteData:{x:i,y:r,dx:e.dx??30,dy:e.dy??-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:s,...a?{subject:a}:{},connector:e.connector||{end:"arrow"},color:e.color,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-"+n)}case"x-threshold":{const t=kr(null!=e.value?{...e,x:e.value}:e,o);if(null==t)return null;const i=e.color||"#f97316",r=e.labelPosition||"top";let s;s="bottom"===r?(o.height||0)-4:"center"===r?(o.height||0)/2:16;const a=t>.6*(o.width||0),l=a?t-4:t+4,c=a?"end":"start";return(0,Zr.jsxs)("g",{opacity:e.opacity,children:[(0,Zr.jsx)("line",{x1:t,y1:0,x2:t,y2:o.height||0,stroke:i,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Zr.jsx)(Kr,{x:l,y:s,text:e.label,textAnchor:c,fill:i,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"y-threshold":{const t=Sr(null!=e.value?{...e,y:e.value}:e,o);if(null==t)return null;const i=e.color||"#f97316",r=e.labelPosition||"right";let a,l;"left"===r?(a=4,l="start"):"center"===r?(a=(o.width||0)/2,l="middle"):(a=(o.width||0)-4,l="end");const c=20>(s=t)?Math.min((o.height||0)-4,s+16):s-4;return(0,Zr.jsxs)("g",{opacity:e.opacity,children:[(0,Zr.jsx)("line",{x1:0,y1:t,x2:o.width||0,y2:t,stroke:i,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Zr.jsx)(Kr,{x:a,y:c,text:e.label,textAnchor:l,fill:i,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"enclose":{const t=(e.coordinates||[]).map(e=>({x:kr({...e,type:"point"},o),y:Sr({...e,type:"point"},o),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const i=(0,vr.packEnclose)(t),r=e.padding||10;return(0,Zr.jsxs)("g",{children:[(0,Zr.jsx)("circle",{cx:i.x,cy:i.y,r:i.r+r,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&(0,Zr.jsx)(Kr,{x:i.x,y:i.y-i.r-r-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"rect-enclose":{const t=(e.coordinates||[]).map(e=>({x:kr({...e,type:"point"},o),y:Sr({...e,type:"point"},o)})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const i=e.padding||10,r=t.map(e=>e.x),s=t.map(e=>e.y),[a,l]=ve(r),[c,u]=ve(s),d=a-i,h=l+i,f=c-i;return(0,Zr.jsxs)("g",{children:[(0,Zr.jsx)("rect",{x:d,y:f,width:h-d,height:u+i-f,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&(0,Zr.jsx)(Kr,{x:(d+h)/2,y:f-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"highlight":{const t=o.data||[],i="function"==typeof e.filter?t.filter(e.filter):e.field&&null!=e.value?t.filter(t=>t[e.field]===e.value):[],r={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return(0,Zr.jsx)("g",{children:i.map((t,n)=>{const i=kr(t,o),s=Sr(t,o);if(null==i||null==s)return null;const a="function"==typeof e.r?e.r(t):e.r||6,l="function"==typeof e.style?e.style(t):e.style||r;return(0,Zr.jsx)("circle",{cx:i,cy:s,r:a,...l},"hl-"+n)})},"ann-"+n)}case"bracket":{const t=kr(e,o),i=Sr(e,o);return(0,Zr.jsx)(br,{noteData:{x:t??0,y:i??0,dx:e.dx||0,dy:e.dy||0,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},"ann-"+n)}case"trend":{const t=o.data||[];if(2>t.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,l=s?i:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const e of t){const t=e[l];if(null==t)continue;const n=t+"";h.has(n)||(h.set(n,d.length),d.push(n))}u=t.map(e=>{const t=e[l],n=e[c];if(null==t||null==n)return null;const o=h.get(t+"");return null!=o?[o,+n]:null}).filter(e=>null!==e)}else u=t.map(e=>[e[i],e[r]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>u.length)return null;const f=o.scales?.x??o.scales?.time,p=o.scales?.y??o.scales?.value;if(!f||!p)return null;const g=e=>t=>{const n=Math.max(0,Math.floor(t)),o=Math.min(d.length-1,n+1),i=t-n,r=e(d[n]);return r+(e(d[o])-r)*i},y=f,m=p;let x;if(s)if(a){const e=g(m);x=(t,n)=>[y(n),e(t)]}else{const e=g(y);x=(t,n)=>[e(t),m(n)]}else x=(e,t)=>[y(e),m(t)];const b=e.method||"linear";let v;if("loess"===b)v=function(e,t=.3){const n=e.length;if(2>n)return e.slice();const o=e.slice().sort((e,t)=>e[0]-t[0]),i=o.map(e=>e[0]),r=o.map(e=>e[1]),s=Math.max(2,Math.ceil(t*n)),a=[];for(let e=0;n>e;e++){const t=i[e],o=i.map(e=>Math.abs(e-t)),l=o.slice().sort((e,t)=>e-t)[Math.min(s-1,n-1)]||1,c=[];for(let e=0;n>e;e++){const t=0===l?0:o[e]/l;c[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let u=0,d=0,h=0,f=0,p=0;for(let e=0;n>e;e++){const t=c[e];0!==t&&(u+=t,d+=t*i[e],h+=t*r[e],f+=t*i[e]*i[e],p+=t*i[e]*r[e])}if(0===u){a.push([t,r[e]]);continue}const g=u*f-d*d;if(1e-12>Math.abs(g))a.push([t,h/u]);else{const e=(u*p-d*h)/g;a.push([t,(h-e*d)/u+e*t])}}return a}(u,e.bandwidth??.3);else{const t="polynomial"===b?it(u,e.order||2):function(e){const t=[0,0,0,0];let n=0;for(const[o,i]of e)null!==i&&(n++,t[0]+=o,t[1]+=i,t[2]+=o*o,t[3]+=o*i);const o=n*t[2]-t[0]*t[0],i=0===o?0:ot((n*t[3]-t[0]*t[1])/o),r=ot(t[1]/n-i*t[0]/n);return{points:e.map(([e])=>[ot(e),ot(i*e+r)]),equation:[i,r]}}(u);v=t.points}const w=v.map(([e,t])=>{const[n,o]=x(e,t);return`${n},${o}`}).join(" "),k=e.color||"#6366f1",S=v[v.length-1],[A,M]=x(S[0],S[1]);return(0,Zr.jsxs)("g",{children:[(0,Zr.jsx)("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Zr.jsx)("text",{x:A+4,y:M-4,fill:k,fontSize:11,children:e.label})]},"ann-"+n)}case"band":{const t=o.scales?.y??o.scales?.value,s=t?.domain?.(),a=e.y0??s?.[0],l=e.y1??s?.[1],c=null!=a&&t?t(a):0,u=null!=l&&t?t(l):o.height||0,d=ei(e.fill,"ann-"+n,"var(--semiotic-primary, #6366f1)");return(0,Zr.jsxs)("g",{opacity:e.opacity,children:[d.def&&(0,Zr.jsx)("defs",{children:d.def}),(0,Zr.jsx)("rect",{x:0,y:Math.min(c,u),width:o.width||0,height:Math.abs(u-c),fill:d.fill,fillOpacity:e.fillOpacity||.1}),e.label&&(0,Zr.jsx)(Kr,{x:(o.width||0)-4,y:(i=c,r=u,Math.max(Math.min(i,r),0)+16),textAnchor:"end",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"x-band":{const t=o.scales?.x??o.scales?.time,i=t?.domain?.(),r=e.x0??i?.[0],s=e.x1??i?.[1],a=null!=r&&t?t(r):null,l=null!=s&&t?t(s):null;if(null==a||null==l)return null;const c=ei(e.fill||e.color,"ann-"+n,"var(--semiotic-primary, #6366f1)");return(0,Zr.jsxs)("g",{opacity:e.opacity,children:[c.def&&(0,Zr.jsx)("defs",{children:c.def}),(0,Zr.jsx)("rect",{x:Math.min(a,l),y:0,width:Math.abs(l-a),height:o.height||0,fill:c.fill,fillOpacity:e.fillOpacity??.1}),e.label&&(0,Zr.jsx)(Kr,{x:Math.min(a,l)+4,y:16,textAnchor:"start",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"envelope":{const t=o.data||[];if(2>t.length)return null;const i=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=e.upperAccessor||"upperBounds",l=e.lowerAccessor||"lowerBounds",c=e.filter,u=t.filter(e=>null!=e[a]&&null!=e[l]&&!(c&&!c(e))).sort((e,t)=>e[i]-t[i]);if(2>u.length)return null;const d=Qr[o.curve||"linear"]||wr.curveLinear,h=(0,wr.area)().x(e=>r(e[i])).y0(e=>s(e[l])).y1(e=>s(e[a])).curve(d)(u);if(!h)return null;const f=e.fill||"#6366f1";return(0,Zr.jsxs)("g",{children:[(0,Zr.jsx)("path",{d:h,fill:f,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&u.length>0&&(0,Zr.jsx)("text",{x:r(u[u.length-1][i])+4,y:s(u[u.length-1][a])-4,fill:f,fontSize:11,children:e.label})]},"ann-"+n)}case"anomaly-band":{const t=o.data||[];if(2>t.length)return null;const i=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.map(e=>e[i]).filter(e=>null!=e&&isFinite(e));if(2>a.length)return null;const l=a.reduce((e,t)=>e+t,0)/a.length,c=a.reduce((e,t)=>e+(t-l)**2,0)/a.length,u=Math.sqrt(c),d=e.threshold??2,h=l-d*u,f=!1!==e.showBand,p=e.fill||"#6366f1",g=e.fillOpacity??.1,y=e.anomalyColor||"#ef4444",m=e.anomalyRadius??6,x=s(l+d*u),b=s(h),v=t.filter(e=>{const t=e[i];return null!=t&&Math.abs(t-l)>d*u});return(0,Zr.jsxs)("g",{children:[f&&(0,Zr.jsx)("rect",{x:0,y:Math.min(x,b),width:o.width||0,height:Math.abs(b-x),fill:p,fillOpacity:g}),v.map((e,t)=>{const n=kr(e,o),i=Sr(e,o);return null==n||null==i?null:(0,Zr.jsx)("circle",{cx:n,cy:i,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+t)}),e.label&&(0,Zr.jsx)("text",{x:(o.width||0)-4,y:Math.min(x,b)-4,textAnchor:"end",fill:p,fontSize:11,children:e.label})]},"ann-"+n)}case"forecast":{const t=o.data||[];if(3>t.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const l=t.map(e=>[e[i],e[r]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>l.length)return null;let c;if("polynomial"===(e.method||"linear")){const t=it(l,e.order||2).equation;c=e=>t.reduce((t,n,o)=>t+n*Math.pow(e,o),0)}else{const e=rt(l);if(!e)return null;c=e}const u=l.length,{se:d,meanX:h,ssX:f}=st(l,c),p=at(e.confidence??.95),g=e.steps??5,y=l[u-1][0],m=(y-l[0][0])/Math.max(u-1,1),x=[];for(let e=1;g>=e;e++)x.push(y+e*m);const b=[];for(const e of x){const t=c(e),n=d*Math.sqrt(1+1/u+(f>0?(e-h)**2/f:0))*p;b.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const v=`M${b.map(e=>`${s(e.x)},${a(e.yUpper)}`).join(" L")} L${b.slice().reverse().map(e=>`${s(e.x)},${a(e.yLower)}`).join(" L")} Z`,w=b.map(e=>`${s(e.x)},${a(e.yCenter)}`).join(" "),k=`${s(y)},${a(c(y))}`,S=e.strokeColor||"#6366f1";return(0,Zr.jsxs)("g",{children:[(0,Zr.jsx)("path",{d:v,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),(0,Zr.jsx)("polyline",{points:`${k} ${w}`,fill:"none",stroke:S,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&b.length>0&&(0,Zr.jsx)("text",{x:s(b[b.length-1].x)+4,y:a(b[b.length-1].yCenter)-4,fill:S,fontSize:11,children:e.label})]},"ann-"+n)}case"widget":{let i,r;if(null!=e.px&&null!=e.py)i=e.px,r=e.py;else{const t=_r(e,n,o);if(!t)return null;i=t.x,r=t.y}if(!Pr(i,r,o))return null;const s=e.dx??0,a=e.dy??0,l=e.width??32,c=e.height??32,u=e.content??(0,Zr.jsx)("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return(0,Zr.jsx)("foreignObject",{x:i+s-l/2,y:r+a-c/2,width:l,height:c,style:{overflow:"visible",pointerEvents:"auto"},children:(0,Zr.jsx)("div",{...Hr(e,t),style:{width:l,height:c,display:"flex",alignItems:"center",justifyContent:"center"},children:u})},"ann-"+n)}case"text":{const t=_r(e,n,o);if(!t)return null;const{x:i,y:r}=t,s=i+(e.dx||0),a=r+(e.dy||0),l=e.color||"var(--semiotic-text, #333)",c=(0,Zr.jsx)("text",{x:s,y:a,fill:l,fontSize:e.fontSize||11,opacity:e.opacity,strokeDasharray:e.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:e.label});return!0!==e._redundantConnector?dr.cloneElement(c,{key:"ann-text-"+n}):(0,Zr.jsxs)("g",{opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:[(0,Zr.jsx)("line",{x1:i,y1:r,x2:s,y2:a,stroke:l,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),dr.cloneElement(c,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+n)}case"category-highlight":{const t=e.category;if(null==t)return null;const i=e=>"function"==typeof e&&"function"==typeof e.bandwidth,r=o.scales?.o,s=o.scales?.x,a=o.scales?.y,l=i(r)?r:i(s)?s:i(a)?a:null;if(!l)return null;const c=l(t+"");if(null==c)return null;const u=l.bandwidth(),d=e.color||"var(--semiotic-primary, #4589ff)",h=e.opacity??.15,f=e.label;return(0,Zr.jsxs)("g",(o.projection?"vertical"===o.projection:l===s)?{children:[(0,Zr.jsx)("rect",{x:c,y:0,width:u,height:o.height||0,fill:d,fillOpacity:h}),f&&(0,Zr.jsx)(Kr,{x:c+u/2,y:16,textAnchor:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:e.labelBackground??"none"})]}:{children:[(0,Zr.jsx)("rect",{x:0,y:c,width:o.width||0,height:u,fill:d,fillOpacity:h}),f&&(0,Zr.jsx)(Kr,{x:12,y:c+u/2,dominantBaseline:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:e.labelBackground??"none"})]},"ann-"+n)}default:return null}var i,r,s}}(0,X),i={scales:s?{x:s.x,y:s.y,time:s.x,value:s.y}:null,timeAxis:"x",xAccessor:O,yAccessor:z,width:t,height:n,data:D,frameType:"xy",pointNodes:F,curve:E,stickyPositionCache:J.current};return Jr(I?Ms({annotations:e,context:i,..."object"==typeof I?I:{}}):e,o,$,i)},[j,I,$,t,n,O,z,D,s,F,E,X]),oe=function(e){const t=(0,Ps.useSyncExternalStore)(e?$s:zs,e?Is:Ds,e?Is:Ds);return e?t.positions.get(e)??null:null}(W);return(0,Pi.useEffect)(()=>{if(!oe?.locked||!W)return;const e=e=>{"Escape"===e.key&&Ts(W)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[oe?.locked,W]),a||y||m||A||M||ne&&ne.length>0||g||q||oe?(0,Zs.jsxs)("svg",{role:"img",width:o,height:i,overflow:"visible",style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[(0,Zs.jsx)("title",{children:"string"==typeof y?y:"XY Chart"}),(0,Zs.jsx)("desc",{children:"string"==typeof y?y+" (XY data visualization)":"XY data visualization"}),(0,Zs.jsxs)("g",{transform:`translate(${r.left},${r.top})`,children:[g&&s&&(!N||B)&&(()=>{const e=Ws(l?.find(e=>"bottom"===e.orient)?.gridStyle),o=Ws(l?.find(e=>"left"===e.orient)?.gridStyle),i=!1!==l?.find(e=>"bottom"===e.orient)?.grid,r=!1!==l?.find(e=>"left"===e.orient)?.grid;return(0,Zs.jsxs)("g",{className:"stream-grid",children:[i&&U.map((t,o)=>(0,Zs.jsx)("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:n,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:e},"xgrid-"+o)),r&&Z.map((e,n)=>(0,Zs.jsx)("line",{x1:0,y1:e.pixel,x2:t,y2:e.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:o},"ygrid-"+n))]})})(),a&&s&&(()=>{const e=l?.find(e=>"left"===e.orient),o=l?.find(e=>"bottom"===e.orient),i=!e||!1!==e.baseline,r=!o||!1!==o.baseline,s=e?.jaggedBase||!1,a=o?.jaggedBase||!1,h=o?.landmarkTicks,f=e?.landmarkTicks,p="var(--semiotic-border, #ccc)",g="var(--semiotic-text-secondary, var(--semiotic-text, #666))",y="var(--semiotic-text, #333)",m=K,x={fontSize:"var(--semiotic-tick-font-size, 12px)"},b={fontSize:"calc(var(--semiotic-tick-font-size, 12px) + 1px)"},v={fontSize:"var(--semiotic-axis-label-font-size, 12px)"},w=o?.tickAnchor,k=e?.tickAnchor,S=Bs(U),A=Bs(Z);return(0,Zs.jsxs)("g",{className:"stream-axes",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[(0,Zs.jsxs)("g",{className:"semiotic-axis semiotic-axis-bottom","data-orient":"bottom",children:[(!N||B)&&r&&!a&&(0,Zs.jsx)("line",{x1:0,y1:n,x2:t,y2:n,stroke:p,strokeWidth:1}),(!N||B)&&a&&(0,Zs.jsx)("path",{d:Ys("bottom",t,n),fill:"none",stroke:p,strokeWidth:1}),U.map((e,t)=>{const o=!!h&&("function"==typeof h?h(e.value,t):Lo(e.value,t>0?U[t-1].value:void 0));return(0,Zs.jsxs)("g",{transform:`translate(${e.pixel},${n})`,children:[(0,Zs.jsx)("line",{y2:5,stroke:p,strokeWidth:1}),"string"==typeof e.label||"number"==typeof e.label?(0,Zs.jsx)("text",{y:m?12:18,textAnchor:m?"end":Es(w,e.pixel===S.min,e.pixel===S.max),fontWeight:o?600:400,fill:g,fontSize:o?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...o?b:x},transform:m?"rotate(-45)":void 0,children:e.label}):(0,Zs.jsx)("foreignObject",{x:-30,y:6,width:60,height:24,style:{overflow:"visible"},children:(0,Zs.jsx)("div",{style:{textAlign:"center",userSelect:"none",...x},children:e.label})})]},"xtick-"+t)}),c&&(0,Zs.jsx)("text",{x:t/2,y:n+(m?58:40),textAnchor:"middle",fill:y,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...v},children:c})]}),(0,Zs.jsxs)("g",{className:"semiotic-axis semiotic-axis-left","data-orient":"left",children:[(!N||B)&&i&&!s&&(0,Zs.jsx)("line",{x1:0,y1:0,x2:0,y2:n,stroke:p,strokeWidth:1}),(!N||B)&&s&&(0,Zs.jsx)("path",{d:Ys("left",t,n),fill:"none",stroke:p,strokeWidth:1}),Z.map((e,t)=>{const n=!!f&&("function"==typeof f?f(e.value,t):Lo(e.value,t>0?Z[t-1].value:void 0));return(0,Zs.jsxs)("g",{transform:`translate(0,${e.pixel})`,children:[(0,Zs.jsx)("line",{x2:-5,stroke:p,strokeWidth:1}),"string"==typeof e.label||"number"==typeof e.label?(0,Zs.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:Ns(k,e.pixel===A.min,e.pixel===A.max),fontWeight:n?600:400,fill:g,fontSize:n?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...n?b:x},children:e.label}):(0,Zs.jsx)("foreignObject",{x:-68,y:-12,width:60,height:24,style:{overflow:"visible"},children:(0,Zs.jsx)("div",{style:{textAlign:"right",userSelect:"none",...x},children:e.label})})]},"ytick-"+t)}),(()=>{const t=e?.label||u;return t?(0,Zs.jsx)("text",{x:15-G,y:n/2,textAnchor:"middle",fill:y,transform:`rotate(-90, ${15-G}, ${n/2})`,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...v},children:t}):null})()]}),(()=>{const e=l?.find(e=>"right"===e.orient);if(!e||0===Q.length)return null;const o=!1!==e.baseline,i=e.landmarkTicks,r=e.label||d,s=e.tickAnchor,a=Bs(Q);return(0,Zs.jsxs)("g",{className:"semiotic-axis semiotic-axis-right","data-orient":"right",children:[o&&(0,Zs.jsx)("line",{x1:t,y1:0,x2:t,y2:n,stroke:p,strokeWidth:1}),Q.map((e,n)=>{const o=!!i&&("function"==typeof i?i(e.value,n):Lo(e.value,n>0?Q[n-1].value:void 0));return(0,Zs.jsxs)("g",{transform:`translate(${t},${e.pixel})`,children:[(0,Zs.jsx)("line",{x2:5,stroke:p,strokeWidth:1}),"string"==typeof e.label||"number"==typeof e.label?(0,Zs.jsx)("text",{x:8,textAnchor:"start",dominantBaseline:Ns(s,e.pixel===a.min,e.pixel===a.max),fontWeight:o?600:400,fill:g,fontSize:o?13:12,className:"semiotic-axis-tick",style:{userSelect:"none",...o?b:x},children:e.label}):(0,Zs.jsx)("foreignObject",{x:8,y:-12,width:60,height:24,style:{overflow:"visible"},children:(0,Zs.jsx)("div",{style:{textAlign:"left",userSelect:"none",...x},children:e.label})})]},"ytick-r-"+n)}),r&&(0,Zs.jsx)("text",{x:t+V-15,y:n/2,textAnchor:"middle",fill:y,transform:`rotate(90, ${t+V-15}, ${n/2})`,fontSize:12,className:"semiotic-axis-label",style:{userSelect:"none",...v},children:r})]})})()]})})(),ne,M&&s&&_&&P&&(0,Zs.jsxs)(Zs.Fragment,{children:[M.top&&(0,Zs.jsx)("g",{transform:"translate(0, 0)",children:(0,Zs.jsx)(ur,{orient:"top",config:cr(M.top),values:_,scale:s.x,size:r.top,length:t})}),M.bottom&&(0,Zs.jsx)("g",{transform:`translate(0, ${n})`,children:(0,Zs.jsx)(ur,{orient:"bottom",config:cr(M.bottom),values:_,scale:s.x,size:r.bottom,length:t})}),M.left&&(0,Zs.jsx)("g",{transform:"translate(0, 0)",children:(0,Zs.jsx)(ur,{orient:"left",config:cr(M.left),values:P,scale:s.y,size:r.left,length:n})}),M.right&&(0,Zs.jsx)("g",{transform:`translate(${t}, 0)`,children:(0,Zs.jsx)(ur,{orient:"right",config:cr(M.right),values:P,scale:s.y,size:r.right,length:n})})]}),A,oe&&oe.sourceId!==Y&&s?.x&&(()=>{const e=s.x(oe.xValue);if(null==e||0>e||e>t)return null;const o=oe.locked;return(0,Zs.jsx)("line",{x1:e,y1:0,x2:e,y2:n,stroke:o?"white":"var(--semiotic-text-secondary, rgba(0,0,0,0.25))",strokeWidth:o?1.5:1,strokeDasharray:o?"6,3":"4,4",pointerEvents:"none"})})(),q]}),y&&"string"==typeof y?(0,Zs.jsx)("text",{x:o/2,y:Gs,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)"},children:y}):y?(0,Zs.jsx)("foreignObject",{x:0,y:0,width:o,height:r.top,children:y}):null,rr({legend:m,totalWidth:o,totalHeight:i,margin:r,legendPosition:k,title:y,legendLayout:S,axisChrome:{hasAxis:!!a,hasAxisLabel:!!c,rotatedTicks:K},legendHoverBehavior:x,legendClickBehavior:b,legendHighlightedCategory:v,legendIsolatedCategories:w})]}):null}var na=g(require("react")),oa=require("d3-shape");function ia(e,t,n){let o=n;for(const n of t)"lesser"===n.thresholdType?n.value>e&&(o=n.color):e>n.value&&(o=n.color);return o}function ra(e,t,n,o){if(2>e.length||t.length!==e.length||0===n.length)return[];const i=[],r=(e,t,n)=>{const o=i[i.length-1];o?.color===e?o.path.push(n):i.push({color:e,path:[t,n]})};for(let i=1;e.length>i;i++){const[s,a]=e[i-1],[l,c]=e[i],u=t[i-1],d=t[i]-u,h=[0,...0===d?[]:n.map(({value:e})=>(e-u)/d).filter(e=>e>0&&1>e&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,n)=>0===t||e!==n[t-1]),1];for(let e=1;h.length>e;e++){const t=h[e-1],i=h[e];r(ia(u+d*((t+i)/2),n,o),[s+(l-s)*t,a+(c-a)*t],[s+(l-s)*i,a+(c-a)*i])}}return i}function sa(e){return(e.tl??0)>0||(e.tr??0)>0||(e.br??0)>0||(e.bl??0)>0}function aa(e){const t=e.cornerRadii;if(!t)return{tl:0,tr:0,br:0,bl:0};const n=Math.min(e.w,e.h)/2,o=e=>Math.max(0,Math.min(e??0,n));return{tl:o(t.tl),tr:o(t.tr),br:o(t.br),bl:o(t.bl)}}var la=require("react/jsx-runtime"),ca={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function ua(e,t="#4e79a7"){return Ko(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function da(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}function ha(e,t,n,o){const i=e.glyph;if(!i?.parts?.length||0>=e.size)return null;const r=$o(i,e.size);if(0>=r.scale)return null;const s=`translate(${t},${n})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),l=Fo(i,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),c=l?da(o+"-clip"):void 0,u=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),d=t=>i.parts.map((n,o)=>{const i=t?"none"===n.fill?void 0:t:Oo(n.fill,a,e.accent),r=t?n.stroke&&"none"!==n.stroke?t:void 0:Oo(n.stroke??"none",a,e.accent);return i||r?(0,la.jsx)("path",{d:n.d,fill:i??"none",stroke:r,strokeWidth:r?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},o):null});return(0,la.jsxs)("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&(0,la.jsx)("clipPath",{id:c,children:(0,la.jsx)("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&e.ghostColor?(0,la.jsx)("g",{children:d(e.ghostColor)}):null,l&&c?(0,la.jsx)("g",{clipPath:`url(#${c})`,children:d()}):d()]},o)}function fa(e,t){const n=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return 2>n.length?null:n.map((e,t)=>(0,la.jsx)("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}function pa(e,t,n){const o=kn(e.symbolType,e.size,e.path);return(0,la.jsx)("path",{d:o,transform:e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`,fill:e.style.fill?ua(e.style.fill):"none",fillOpacity:e.style.fillOpacity,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},`${n??""}symbol-${t}`)}var ga=g(require("react")),ya=require("d3-shape"),ma=require("react/jsx-runtime"),xa=g(require("react")),ba=require("react/jsx-runtime"),va=g(require("react")),wa=require("d3-shape"),ka=(e,t)=>({x:e*Math.cos(t),y:e*Math.sin(t)});function Sa(e){const{innerRadius:t,outerRadius:n,startAngle:o,endAngle:i}=e,r=0>=t;if(0>=(e.cornerRadius??0)||!e.roundStart&&!e.roundEnd){if(r){const e=ka(n,o),t=ka(n,i);return`M0,0 L${e.x},${e.y} A${n},${n} 0 ${i-o>Math.PI?1:0} 1 ${t.x},${t.y} Z`}const e=ka(n,o),s=ka(n,i),a=ka(t,i),l=ka(t,o),c=i-o>Math.PI?1:0;return`M${e.x},${e.y} A${n},${n} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${t},${t} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(e.cornerRadius??0,(n-t)/2));if(0===s)return Sa({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,n-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,t+s))),c=i-o,u=e.roundStart&&e.roundEnd?c/2:c,d=!!e.roundStart&&u>a,h=!!e.roundEnd&&u>a;if(!d&&!h)return Sa({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=o+(d?a:0),p=i-(h?a:0),g=o+(d?l:0),y=i-(h?l:0),m=ka(n,f),x=ka(n,p),b=(n-s)*Math.cos(a),v=ka(b,o),w=ka(b,i),k=r?null:ka(t,y),S=r?null:ka(t,g),A=r?0:(t+s)*Math.cos(l),M=r?null:ka(A,o),_=r?null:ka(A,i),P=p-f>Math.PI?1:0,j=r?0:y-g>Math.PI?1:0;let C="";if(d)C+=`M${v.x},${v.y}`,C+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const e=ka(n,o);C+=`M${e.x},${e.y}`}if(h)C+=` A${n},${n} 0 ${P} 1 ${x.x},${x.y}`,C+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const e=ka(n,i);C+=` A${n},${n} 0 ${P} 1 ${e.x},${e.y}`}if(r)C+=" L0,0";else{if(h)C+=` L${_.x},${_.y}`,C+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const e=ka(t,i);C+=` L${e.x},${e.y}`}if(d)C+=` A${t},${t} 0 ${j} 0 ${S.x},${S.y}`,C+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const e=ka(t,o);C+=` A${t},${t} 0 ${j} 0 ${e.x},${e.y}`}}return C+=" Z",C}var Aa=require("react/jsx-runtime");function Ma(e){return 1e6>e?1e4>e?1e3>e?e+"":(e/1e3).toFixed(1)+"K":(e/1e3).toFixed(0)+"K":(e/1e6).toFixed(1)+"M"}function _a(e,t){const n=e.datum;if(!n)return null;const o=[],i=n.__funnelStepLabel,r=Number(n.__funnelStepLabelX),s=Number(n.__funnelStepLabelY),a=Number(n.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||o.push((0,Aa.jsx)("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},t+"-funnel-step"));const l=Number(n.__funnelValue),c=Number(n.__funnelValueLabelX),u=Number(n.__funnelValueLabelY),d=Number(n.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const e=Number(n.__funnelPercent);let i=!0!==n.__funnelIsFirstStep&&Number.isFinite(e)?`${Ma(l)} (${.05>Math.abs(e-Math.round(e))?Math.round(e):e.toFixed(1)}%)`:Ma(l);7.8*i.length+16>d&&(i=Ma(l)),7.8*i.length+16>d||o.push((0,Aa.jsx)("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:i},t+"-funnel-value"))}return o.length?(0,Aa.jsx)("g",{children:o},t+"-funnel-labels"):null}function Pa(e,t,n){const o=("category"in e?e.category:void 0)||("group"in e?e.group:void 0)||"",i=n=>`ord-${e.type}-${o}-${t}-${n}`,r=`ord-${e.type}-${o}-${t}`;switch(e.type){case"rect":{const t=e,n=da(r)+"-grad",o=function(e,t){const n=e.fillGradient;if(!n||"object"!=typeof n)return null;let o=e.x,i=e.y,r=e.x,s=e.y+e.h;"bottom"===e.roundedEdge?(i=e.y+e.h,s=e.y):"right"===e.roundedEdge?(o=e.x+e.w,i=e.y,r=e.x,s=e.y):"left"===e.roundedEdge&&(o=e.x,i=e.y,r=e.x+e.w,s=e.y);const a=fa(n.stops,ua(e.style.fill));return a?(0,la.jsx)("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:o,y1:i,x2:r,y2:s,children:a}):null}(t,n);let i,s;if(o)s=`url(#${n})`;else if(Ko(t.style.fill)){const e=da(r)+"-hatch";i=Jo(t.style.fill,e),s=`url(#${e})`}else s=ua(t.style.fill);const a=o||i?(0,Aa.jsxs)("defs",{children:[o,i]}):null;if(t.cornerRadii&&sa(t.cornerRadii)){const e=function(e){const{x:t,y:n,w:o,h:i}=e,{tl:r,tr:s,br:a,bl:l}=aa(e);let c=`M${t+r},${n}`;return c+=` L${t+o-s},${n}`,s>0&&(c+=` A${s},${s} 0 0 1 ${t+o},${n+s}`),c+=` L${t+o},${n+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${t+o-a},${n+i}`),c+=` L${t+l},${n+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${t},${n+i-l}`),c+=` L${t},${n+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${t+r},${n}`),c+=" Z",c}(t);return(0,Aa.jsxs)(va.Fragment,{children:[a,(0,Aa.jsx)("path",{d:e,fill:s,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth})]},r)}if(t.roundedTop&&t.roundedTop>0){const e=Math.min(t.roundedTop,t.w/2,t.h/2),{x:n,y:o,w:i,h:l}=t;let c;switch(t.roundedEdge){case"right":c=`M${n},${o} L${n+i-e},${o} A${e},${e} 0 0 1 ${n+i},${o+e} L${n+i},${o+l-e} A${e},${e} 0 0 1 ${n+i-e},${o+l} L${n},${o+l} Z`;break;case"left":c=`M${n+i},${o} L${n+e},${o} A${e},${e} 0 0 0 ${n},${o+e} L${n},${o+l-e} A${e},${e} 0 0 0 ${n+e},${o+l} L${n+i},${o+l} Z`;break;case"bottom":c=`M${n},${o} L${n+i},${o} L${n+i},${o+l-e} A${e},${e} 0 0 1 ${n+i-e},${o+l} L${n+e},${o+l} A${e},${e} 0 0 1 ${n},${o+l-e} Z`;break;default:c=`M${n},${o+l} L${n},${o+e} A${e},${e} 0 0 1 ${n+e},${o} L${n+i-e},${o} A${e},${e} 0 0 1 ${n+i},${o+e} L${n+i},${o+l} Z`}return(0,Aa.jsxs)(va.Fragment,{children:[a,(0,Aa.jsx)("path",{d:c,fill:s,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth})]},r)}return(0,Aa.jsxs)(va.Fragment,{children:[a,(0,Aa.jsx)("rect",{x:t.x,y:t.y,width:t.w,height:t.h,fill:s,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth}),_a(t,r)]},r)}case"point":{const t=e;return(0,Aa.jsx)("circle",{cx:t.x,cy:t.y,r:t.r,fill:ua(t.style.fill),opacity:t.style.opacity??t.style.fillOpacity??.8,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},r)}case"symbol":return pa(e,t,n);case"glyph":return ha(e,e.x,e.y,`${n??""}ord-glyph-${e.pointId??t}`);case"wedge":{const o=e;if(o._gradientBand&&o._gradientBand.colors.length>0){const e=da(`${n?n+"-":""}gauge-grad-${o.category||r}-${t}`),{clipPath:i,slices:s}=function(e){const t=Sa({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,cornerRadius:e.cornerRadius,roundStart:e.roundStart,roundEnd:e.roundEnd}),n=[],o=e.colors;if(o.length>0){const t=(e.endAngle-e.startAngle)/o.length;for(let i=0;o.length>i;i++)n.push({d:Sa({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle+i*t,endAngle:e.endAngle}),color:o[i]})}return{clipPath:t,slices:n}}({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds?.start??!0,roundEnd:o.roundedEnds?.end??!0,colors:o._gradientBand.colors});return(0,Aa.jsxs)("g",{transform:`translate(${o.cx},${o.cy})`,opacity:o.style.opacity,fillOpacity:o.style.fillOpacity,children:[(0,Aa.jsx)("defs",{children:(0,Aa.jsx)("clipPath",{id:e,children:(0,Aa.jsx)("path",{d:i})})}),(0,Aa.jsx)("g",{clipPath:`url(#${e})`,children:s.map((e,t)=>(0,Aa.jsx)("path",{d:e.d,fill:ua(e.color)},t))}),o.style.stroke&&"none"!==o.style.stroke&&(0,Aa.jsx)("path",{d:i,fill:"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},r)}let i;if(o.roundedEnds)i=Sa({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds.start,roundEnd:o.roundedEnds.end});else{const e=(0,wa.arc)().innerRadius(o.innerRadius).outerRadius(o.outerRadius).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2);o.cornerRadius&&e.cornerRadius(o.cornerRadius),i=e(ca)||""}return(0,Aa.jsx)("path",{d:i,transform:`translate(${o.cx},${o.cy})`,fill:ua(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},r)}case"boxplot":{const t=e,n=t.columnWidth/2;return(0,Aa.jsxs)("g","vertical"===t.projection?{children:[(0,Aa.jsx)("line",{x1:t.x,y1:t.minPos,x2:t.x,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("rect",{x:t.x-n,y:Math.min(t.q1Pos,t.q3Pos),width:t.columnWidth,height:Math.abs(t.q3Pos-t.q1Pos),fill:ua(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("line",{x1:t.x-n,y1:t.medianPos,x2:t.x+n,y2:t.medianPos,stroke:t.style.stroke||"#333",strokeWidth:2}),(0,Aa.jsx)("line",{x1:t.x-.5*n,y1:t.minPos,x2:t.x+.5*n,y2:t.minPos,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("line",{x1:t.x-.5*n,y1:t.maxPos,x2:t.x+.5*n,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:1})]}:{children:[(0,Aa.jsx)("line",{x1:t.minPos,y1:t.y,x2:t.maxPos,y2:t.y,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("rect",{x:Math.min(t.q1Pos,t.q3Pos),y:t.y-n,width:Math.abs(t.q3Pos-t.q1Pos),height:t.columnWidth,fill:ua(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("line",{x1:t.medianPos,y1:t.y-n,x2:t.medianPos,y2:t.y+n,stroke:t.style.stroke||"#333",strokeWidth:2}),(0,Aa.jsx)("line",{x1:t.minPos,y1:t.y-.5*n,x2:t.minPos,y2:t.y+.5*n,stroke:t.style.stroke||"#333",strokeWidth:1}),(0,Aa.jsx)("line",{x1:t.maxPos,y1:t.y-.5*n,x2:t.maxPos,y2:t.y+.5*n,stroke:t.style.stroke||"#333",strokeWidth:1})]},r)}case"violin":{const t=e,n=[(0,Aa.jsx)("path",{d:t.pathString,transform:t.translateX||t.translateY?`translate(${t.translateX},${t.translateY})`:void 0,fill:ua(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:t.style.strokeWidth||1},i("path"))];if(t.iqrLine&&t.bounds){const e=t.bounds,o=e.x+e.width/2,r=e.y+e.height/2;t.iqrLine.isVertical?n.push((0,Aa.jsx)("line",{x1:o,y1:t.iqrLine.q1Pos,x2:o,y2:t.iqrLine.q3Pos,stroke:t.style.stroke||"#333",strokeWidth:2},i("iqr")),(0,Aa.jsx)("circle",{cx:o,cy:t.iqrLine.medianPos,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},i("med"))):n.push((0,Aa.jsx)("line",{x1:t.iqrLine.q1Pos,y1:r,x2:t.iqrLine.q3Pos,y2:r,stroke:t.style.stroke||"#333",strokeWidth:2},i("iqr")),(0,Aa.jsx)("circle",{cx:t.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},i("med")))}return(0,Aa.jsx)("g",{children:n},r)}case"connector":return(0,Aa.jsx)("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||"#999",strokeWidth:e.style.strokeWidth||1,opacity:e.style.opacity??.5},r);case"trapezoid":{const t=e,n=t.points.map(e=>`${e[0]},${e[1]}`).join(" ");return(0,Aa.jsx)("polygon",{points:n,fill:ua(t.style.fill,"#999"),opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},r)}default:return null}}var ja=require("react/jsx-runtime");function Ca(e,t,n,o){if(!e||2>t.length)return null;const i=fa(e.stops,o);return i?(0,ja.jsx)("linearGradient",{id:n,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:i}):null}function Ra(e,t,n){switch(e.type){case"line":{const o=e;if(0===o.path.length)return null;const i=ni(o.curve),r=i?(0,oa.line)().x(([e])=>e).y(([,e])=>e).curve(i)(o.path)??"":"M"+o.path.map(([e,t])=>`${e},${t}`).join("L"),s=da(`${n?n+"-":""}line-${t}-stroke-gradient`),a=Ca(o.strokeGradient,o.path,s,o.style.stroke||"#4e79a7");return(0,ja.jsxs)(na.Fragment,{children:[a&&(0,ja.jsx)("defs",{children:a}),(0,ja.jsx)("path",{d:r,fill:"none",stroke:a?`url(#${s})`:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth||2,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity})]},"line-"+t)}case"area":{const o=e;if(0===o.topPath.length)return null;const i=ni(o.curve),r=!i||2>o.topPath.length||2>o.bottomPath.length?`M${o.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...o.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`:(0,oa.area)().x(([e])=>e).y0((e,t)=>o.bottomPath[t][1]).y1(([,e])=>e).curve(i)(o.topPath)??"",s=`${n?n+"-":""}area-${t}-hatch`,a=Ko(o.style.fill)?Jo(o.style.fill,s):void 0,l=da(`${n?n+"-":""}area-${t}-gradient`),c=function(e,t){const n=e.fillGradient;if(!n||"object"!=typeof n)return null;let o=1/0;for(const[,t]of e.topPath)o=Math.min(o,t);let i=-1/0;for(const[,t]of e.bottomPath)i=Math.max(i,t);if(!Number.isFinite(o)||!Number.isFinite(i))return null;const r=fa(n.stops,ua(e.style.fill));return r?(0,ja.jsx)("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:o,x2:0,y2:i,children:r}):null}(o,l),u=c?`url(#${l})`:a?`url(#${s})`:ua(o.style.fill),d=c?void 0:o.style.fillOpacity??o.style.opacity??.7,h=i?(0,oa.line)().x(([e])=>e).y(([,e])=>e).curve(i)(o.topPath)??"":"M"+o.topPath.map(([e,t])=>`${e},${t}`).join("L"),f=da(`${n?n+"-":""}area-${t}-stroke-gradient`),p=!(!o.colorThresholds?.length||!o.rawValues||o.rawValues.length!==o.topPath.length),g=!!o.strokeColorBands?.length,y=p||g?null:Ca(o.strokeGradient,o.topPath,f,o.style.stroke||"#4e79a7"),m=o.style.strokeWidth||2;let x=1/0,b=-1/0;for(const[e]of o.topPath)x>e&&(x=e),e>b&&(b=e);const v=g?o.strokeColorBands.map((e,o)=>da(`${n?n+"-":""}area-${t}-stroke-band-${o}`)):[],w=g?o.strokeColorBands.map((e,t)=>(0,ja.jsx)("clipPath",{id:v[t],children:(0,ja.jsx)("rect",{x:x-m,y:e.y,width:b-x+2*m,height:e.height})},v[t])):null,k=o.style.stroke&&"none"!==o.style.stroke?g?o.strokeColorBands.map((e,n)=>(0,ja.jsx)("path",{d:h,fill:"none",stroke:e.color??ua(o.style.stroke),strokeWidth:m,opacity:o.style.opacity,clipPath:`url(#${v[n]})`},`area-${t}-stroke-band-${n}`)):p?ra(o.topPath,o.rawValues,o.colorThresholds,ua(o.style.stroke)).map((e,n)=>(0,ja.jsx)("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:m,opacity:o.style.opacity},`area-${t}-threshold-${n}`)):(0,ja.jsx)("path",{d:h,fill:"none",stroke:y?`url(#${f})`:ua(o.style.stroke),strokeWidth:m,opacity:o.style.opacity}):null;if(o.clipRect){const e=`${n?n+"-":""}area-clip-${t}`;return(0,ja.jsxs)("g",{children:[(0,ja.jsxs)("defs",{children:[c,!c&&a,y,w,(0,ja.jsx)("clipPath",{id:e,children:(0,ja.jsx)("rect",{x:o.clipRect.x,y:o.clipRect.y,width:o.clipRect.width,height:o.clipRect.height})})]}),(0,ja.jsxs)("g",{clipPath:`url(#${e})`,children:[(0,ja.jsx)("path",{d:r,fill:u,fillOpacity:d,opacity:c?o.style.opacity:void 0,stroke:"none"}),k]})]},"area-"+t)}return(0,ja.jsxs)(na.Fragment,{children:[(c||a||y||w)&&(0,ja.jsxs)("defs",{children:[c,!c&&a,y,w]}),(0,ja.jsx)("path",{d:r,fill:u,fillOpacity:d,opacity:c?o.style.opacity:void 0,stroke:"none"}),k]},"area-"+t)}case"point":{const o=e,i=`${n?n+"-":""}point-${t}-hatch`,r=Ko(o.style.fill)?Jo(o.style.fill,i):void 0;return(0,ja.jsxs)(na.Fragment,{children:[r&&(0,ja.jsx)("defs",{children:r}),(0,ja.jsx)("circle",{cx:o.x,cy:o.y,r:o.r,fill:r?`url(#${i})`:ua(o.style.fill),opacity:o.style.opacity??o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"point-"+t)}case"symbol":return pa(e,t);case"glyph":return ha(e,e.x,e.y,`${n??""}glyph-${e.pointId??t}`);case"rect":{const o=e,i=`${n?n+"-":""}xyrect-${t}-hatch`,r=Ko(o.style.fill)?Jo(o.style.fill,i):void 0;return(0,ja.jsxs)(na.Fragment,{children:[r&&(0,ja.jsx)("defs",{children:r}),(0,ja.jsx)("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:r?`url(#${i})`:ua(o.style.fill),opacity:o.style.opacity,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},"rect-"+t)}case"heatcell":{const n=e,o={x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill,stroke:n.style?.stroke,strokeWidth:n.style?.strokeWidth,...null!=n.style?.opacity&&{opacity:n.style.opacity}};if(n.showValues&&null!=n.value&&n.w>=20&&n.h>=20){const e=n.valueFormat?n.valueFormat(n.value):Number.isInteger(n.value)?n.value+"":100>Math.abs(n.value)?1>Math.abs(n.value)?n.value.toPrecision(3):n.value.toFixed(1):n.value.toFixed(0),[i,r,s]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(n.fill),a=.299*i+.587*r+.114*s>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return(0,ja.jsxs)("g",{children:[(0,ja.jsx)("rect",{...o}),(0,ja.jsx)("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",children:e})]},"heatcell-"+t)}return(0,ja.jsx)("rect",{...o},"heatcell-"+t)}case"candlestick":{const n=e;if(n.isRange){const e=n.dotRadius??Math.max(2,n.bodyWidth/2);return(0,ja.jsxs)("g",{children:[(0,ja.jsx)("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),(0,ja.jsx)("circle",{cx:n.x,cy:n.highY,r:e,fill:n.wickColor}),(0,ja.jsx)("circle",{cx:n.x,cy:n.lowY,r:e,fill:n.wickColor})]},"candle-"+t)}const o=Math.min(n.openY,n.closeY),i=Math.max(Math.abs(n.openY-n.closeY),1),r=n.isUp?n.upColor:n.downColor;return(0,ja.jsxs)("g",{children:[(0,ja.jsx)("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),(0,ja.jsx)("rect",{x:n.x-n.bodyWidth/2,y:o,width:n.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+t)}default:return null}}var La="undefined"==typeof window||"undefined"==typeof document,Ta=require("react"),Ia="undefined"!=typeof window?Ta.useLayoutEffect:Ta.useEffect,$a=()=>()=>{},Oa=()=>!1,za=()=>!0,Da=require("react");function Fa(e,t){const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(const o of n){if(!Object.prototype.hasOwnProperty.call(t,o))return!1;if(!Object.is(e[o],t[o]))return!1}return!0}function Ea(e,t){if(e.length!==t.length)return!1;for(let n=0;e.length>n;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function Na(e){if(null===e||"object"!=typeof e)return!1;if(Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}function Ba(e){const{background:t,hasBackgroundGraphics:n=!1,themeBackground:o=""}=e;return"transparent"===t||n?null:t||(o&&"transparent"!==o?o:"")||null}var Wa={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 Ya(e,t){const n=e.trim();if(/^#[0-9a-f]{3}$/i.test(n)){const e=n[1],o=n[2],i=n[3];return`#${e}${e}${o}${o}${i}${i}${t}`}if(/^#[0-9a-f]{6}$/i.test(n))return`${n}${t}`;const o=n.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);return o?`rgba(${o[1]}, ${(parseInt(t,16)/255).toFixed(3)})`:n}var qa=g(require("react")),Xa=g(require("react")),Ha=(require("react/jsx-runtime"),Xa.createContext(null)),Ga=require("react/jsx-runtime"),Va={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Ua({hoverPoint:e}){let t="";if(e){const n=e.data||e;t="object"==typeof n?"Data point: "+Object.entries(n).filter(([,e])=>"object"!=typeof e&&"function"!=typeof e).map(([e,t])=>`${e}: ${t}`).join(", "):"Data point: "+n}return(0,Ga.jsx)("div",{"aria-live":"polite","aria-atomic":"true",style:Va,children:t})}function Ka(e){const t={};if(null==e||"object"!=typeof e)return t;for(const[n,o]of Object.entries(e))n.startsWith("_")||null!=o&&""!==o&&("number"==typeof o?Number.isFinite(o)&&(t[n]=o):"string"==typeof o?t[n]=o:"boolean"==typeof o?t[n]=o+"":o instanceof Date&&(t[n]=o.toISOString().slice(0,10)));return t}function Za(e){return e&&"object"==typeof e?e:{}}function Qa(e){return Za(e.accessibility).tableFields??e.accessibleDatum??e.datum}var Ja=require("react/jsx-runtime");function el(e,t){if(!e||0===e.length)return t+", empty";const n={};for(const t of e){if(null===t?.datum)continue;const e=t.type+"";n[e]=(n[e]||0)+1}if(0===Object.keys(n).length)return t+", empty";const o=[],i={point:"points",line:"lines",area:"areas",rect:"bars",heatcell:"cells",circle:"nodes",candlestick:"candlesticks",wedge:"wedges",arc:"arcs",geoarea:"regions"},r=["point","line","area","rect","heatcell","circle","candlestick","wedge","arc","geoarea"],s=Object.keys(n).sort((e,t)=>{const n=r.indexOf(e),o=r.indexOf(t);return(-1===n?999:n)-(-1===o?999:o)});for(const e of s)o.push(`${n[e]} ${i[e]||e}`);return`${t}, ${o.join(", ")}`}var tl=e=>{if(null==e)return"";const t=Math.round(100*e)/100;return Number.isNaN(t)?"":t+""},nl="semiotic-accessible-data-table",ol=nl+" semiotic-accessible-data-table-hidden",il=nl+" semiotic-accessible-data-table-visible",rl={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"},sl={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},al={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)"},ll={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},cl={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))"},ul={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},dl={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},hl={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 fl({scene:e,chartType:t,tableId:n,chartTitle:o}){const[i,r]=qa.useState(!1),[s,a]=qa.useState(5),l=Xa.useContext(Ha),c=l?.visible??!1,u=i||c,d=qa.useRef(null),h=o?"Data summary for "+o:n?`Data summary for ${t} ${n}`:"Data summary for "+t;qa.useEffect(()=>{u||a(5)},[u]);const f=qa.useCallback(e=>{e.target===e.currentTarget&&(i||c||r(!0))},[i,c]),p=qa.useCallback(e=>{c||d.current?.contains(e.relatedTarget)||r(!1)},[c]);if(!e||0===e.length)return n?(0,Ja.jsx)("span",{id:n,tabIndex:-1,style:Va}):null;if(!u)return(0,Ja.jsx)("div",{id:n,className:ol,tabIndex:-1,onFocus:f,style:Va,role:"region","aria-label":h,children:(0,Ja.jsxs)("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",e.length," elements)"]})});const g=function(e){const t=[];if(!Array.isArray(e))return t;const n=e.some(e=>e&&("line"===e.type||"area"===e.type));for(const o of e)if(o&&"object"==typeof o&&null!==o.datum)try{switch(o.type){case"point":if(n)break;t.push({label:"Point",values:Ka(Qa(o))});break;case"line":case"area":{const e=Qa(o),n=Array.isArray(e)?e:[],i="line"===o.type?"Line point":"Area point";for(const e of n)t.push({label:i,values:Ka(e)});break}case"rect":{const e=Qa(o),n=null!=e&&"object"==typeof e?e:{},i=n.category??o.group??"",r=n.value??n.__aggregateValue??n.total,s=Ka(n);null==s.category&&""!==i&&(s.category=i+""),null==s.value&&null!=r&&(s.value="number"==typeof r||"string"==typeof r?r:r+""),t.push({label:"Bar",values:s});break}case"heatcell":{const e=Ka(Qa(o));null==e.value&&"number"==typeof o.value&&Number.isFinite(o.value)&&(e.value=o.value),t.push({label:"Cell",values:e});break}case"wedge":{const e=Qa(o),n=Ka(e);if(null==n.category){const t=Za(e),o=t.category??t.label;null!=o&&(n.category=o+"")}t.push({label:"Wedge",values:n});break}case"circle":t.push({label:"Node",values:Ka(Qa(o))});break;case"arc":t.push({label:"Arc",values:Ka(Qa(o))});break;case"candlestick":t.push({label:"Candlestick",values:Ka(Qa(o))});break;case"geoarea":{const e=Za(Qa(o)),n=Ka(e);if(null==n.name){const t=Za(e.properties).name??e.name;null!=t&&(n.name=t+"")}t.push({label:"Region",values:n});break}}}catch{}return t}(e),y=function(e){if(!e||0===e.length)return[];const t=new Set;for(const n of e)if(n&&n.values)for(const e of Object.keys(n.values))t.add(e);const n=[];for(const o of t){const t=[],i=new Set;for(const n of e){if(!n||!n.values)continue;const e=n.values[o];null!=e&&""!==e&&("number"==typeof e&&!Number.isNaN(e)&&Number.isFinite(e)?t.push(e):"number"==typeof e||"object"!=typeof e&&"function"!=typeof e&&i.add(e+""))}if(t.length>0){let e=t[0],i=t[0],r=0;for(const n of t)e>n&&(e=n),n>i&&(i=n),r+=n;n.push({name:o,count:t.length,numeric:!0,min:e,max:i,mean:r/t.length})}else if(i.size>0){const e=Array.from(i);n.push({name:o,count:e.length,numeric:!1,uniqueValues:e.slice(0,5)})}}return n}(g),m=function(e,t){const n=[e+" data points."];for(const e of t)if(e.numeric)n.push(`${e.name}: ${tl(e.min)} to ${tl(e.max)}, mean ${tl(e.mean)}.`);else{const t=e.uniqueValues,o=t.length>3?`${t.slice(0,3).join(", ")}… (${e.count} unique)`:t.join(", ");n.push(`${e.name}: ${o}.`)}return n.join(" ")}(g.length,y),x=Math.min(s,g.length),b=g.slice(0,x),v=g.length-x,w=new Set;for(const e of b)for(const t of Object.keys(e.values))w.add(t);const k=Array.from(w);return(0,Ja.jsxs)("div",{ref:d,id:n,className:il,tabIndex:-1,onBlur:p,style:rl,role:"region","aria-label":h,children:[(0,Ja.jsx)("button",{type:"button",className:"semiotic-accessible-data-table-close",onClick:()=>{c&&l&&l.setVisible(!1),r(!1)},"aria-label":"Close data summary",style:al,children:"×"}),(0,Ja.jsx)("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:sl,children:m}),(0,Ja.jsxs)("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Sample data for "+t,style:ll,children:[(0,Ja.jsx)("caption",{className:"semiotic-accessible-data-table-caption",style:dl,children:v>0?`First ${x} of ${g.length} data points`:`All ${g.length} data points`}),(0,Ja.jsx)("thead",{children:(0,Ja.jsxs)("tr",{children:[(0,Ja.jsx)("th",{style:cl,children:"type"}),k.map(e=>(0,Ja.jsx)("th",{style:cl,children:e},e))]})}),(0,Ja.jsx)("tbody",{children:b.map((e,t)=>(0,Ja.jsxs)("tr",{children:[(0,Ja.jsx)("td",{style:ul,children:e.label}),k.map(t=>{return(0,Ja.jsx)("td",{style:ul,children:(n=e.values[t],null==n||""===n?"—":"number"==typeof n?Number.isNaN(n)?"—":tl(n):"boolean"==typeof n?n?"true":"false":"object"==typeof n?"—":n+"")},t);var n})]},t))})]}),v>0&&(0,Ja.jsxs)("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:hl,children:["Show ",Math.min(25,v)," more"," ",1===v?"row":"rows"," (",v," remaining)"]})]})}function pl({summary:e}){return e?(0,Ja.jsx)("div",{role:"note",style:Va,children:e}):null}function gl({tableId:e}){return(0,Ja.jsx)("a",{href:"#"+e,style:Va,onClick:t=>{t.preventDefault();const n=document.getElementById(e);n&&requestAnimationFrame(()=>n.focus())},onFocus:e=>{Object.assign(e.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:e=>{const t=e.currentTarget;t.removeAttribute("style"),Object.assign(t.style,Va)},children:"Skip to data table"})}var yl=require("react/jsx-runtime"),ml="var(--semiotic-focus, #005fcc)";function xl({active:e,hoverPoint:t,margin:n,size:o,shape:i="circle",width:r,height:s,pathData:a}){if(!e||!t)return null;const l=t.x+n.left,c=t.y+n.top;let u;if("geoarea"!==i&&"path"!==i||!a)if("rect"===i&&null!=r&&null!=s){const e=Math.max(r,4),t=Math.max(s,4);u=(0,yl.jsx)("rect",{x:l-e/2-3,y:c-t/2-3,width:e+6,height:t+6,rx:3,fill:"none",stroke:ml,strokeWidth:2,strokeDasharray:"4,2"})}else u=(0,yl.jsx)("circle","wedge"===i?{cx:l,cy:c,r:12,fill:"none",stroke:ml,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:l,cy:c,r:8,fill:"none",stroke:ml,strokeWidth:2,strokeDasharray:"4,2"});else u=(0,yl.jsx)("g",{transform:`translate(${n.left},${n.top})`,children:(0,yl.jsx)("path",{d:a,fill:"none",stroke:ml,strokeWidth:2.5,strokeDasharray:"6,3"})});return(0,yl.jsx)("svg",{style:{position:"absolute",left:0,top:0,width:o[0],height:o[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:u})}var bl=g(require("react"));function vl(e,t){return"touch"===t?Math.max(e,24):e}function wl(e){return Array.isArray(e)?e[0]:e}function kl(e,t,n,o){return{data:wl(e),x:t,y:n,__semioticHoverData:!0,...o}}var Sl=["name","label","title"],Al=["type","kind","category","group","class","status","role","shape"],Ml=["value","amount","total","count","weight","score"],_l=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 Pl(e,t){for(const n of t){const t=e.find(e=>e.lower===n);if(t)return t}}function jl(e,t={}){if(!e||"object"!=typeof e)return{entries:[]};const n=t.maxEntries??6,o=!1!==t.skipPositional,i=[];for(const[t,n]of Object.entries(e)){if(t.startsWith("_"))continue;if("data"===t)continue;if(o&&_l.has(t.toLowerCase()))continue;if(null==n)continue;const e=typeof n;("string"===e||"number"===e||"boolean"===e||n instanceof Date)&&i.push({key:t,lower:t.toLowerCase(),value:n})}if(0===i.length)return{entries:[]};let r=i.findIndex(e=>Sl.includes(e.lower));const s=r>=0;0>r&&(r=i.findIndex(e=>"id"===e.lower)),0>r&&(r=i.findIndex(e=>"string"==typeof e.value));const a=0>r?void 0:i[r];let l=i.filter((e,t)=>t!==r);s&&(l=l.filter(e=>"id"!==e.lower));const c=Pl(l,Al),u=Pl(l,Ml),d=new Set(Al),h=new Set(Ml),f=[];c&&f.push({key:c.key,value:c.value}),u&&f.push({key:u.key,value:u.value});for(const e of l){if(f.length>=n)break;e!==c&&e!==u&&(d.has(e.lower)||h.has(e.lower)||f.push({key:e.key,value:e.value}))}return{titleKey:a?.key,title:a?.value,entries:f}}var Cl=require("react/jsx-runtime"),Rl={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 Ll(e,t){return"function"==typeof t?t(e):e[t]}function Tl(e,t){if(t)return t(e);if(null==e)return"";if("number"==typeof e){if(!Number.isFinite(e))return e+"";const t=Number.isInteger(e)?e:parseFloat(e.toPrecision(6));return Math.abs(t)>9999?t.toLocaleString():t+""}return e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function Il(e={}){const{fields:t,title:n,format:o,style:i={},className:r=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let s;const a=[];if(n){const t=Ll(e,n);s=Tl(t,o)}if(t&&t.length>0)t.forEach(t=>{let n,i,r;"string"==typeof t?(n=t,i=t,r=o):(n=t.label,i=t.accessor||t.key||"",r=t.format||o);const s=Ll(e,i);a.push({label:n,value:Tl(s,r)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){s=Tl(e[n],o);break}if(!s){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(s=Tl(e[t[0]],o))}}const l={...Rl,...i};return(0,Cl.jsxs)("div",{className:("semiotic-tooltip "+r).trim(),style:l,children:[s&&(0,Cl.jsx)("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((e,t)=>(0,Cl.jsxs)("div",{style:{marginTop:0===t&&s?"4px":0},children:[e.label&&(0,Cl.jsxs)("span",{children:[e.label,": "]}),e.value]},t))]})}}function $l(e){if(!0!==e){if("function"==typeof e){const t=e;return e=>{const n=!0===e?.__semioticHoverData||e&&void 0!==e.data&&"number"==typeof e.x&&"number"==typeof e.y&&e&&("node"===e.type||"edge"===e.type||void 0!==e.nodeOrEdge||void 0!==e.allSeries||void 0!==e.stats||void 0!==e.__chartType);let o=wl(n?e.data??{}:e);if(!o)return null;if(("node"===e?.nodeOrEdge&&"number"==typeof o?.x0&&"number"==typeof o?.x1||"edge"===e?.nodeOrEdge&&"number"==typeof o?.sankeyWidth)&&o.data&&"object"==typeof o.data&&(o=o.data),!o)return null;if(n&&(void 0!==e.allSeries||void 0!==e.xValue)){const t={...o};void 0!==e.allSeries&&void 0===t.allSeries&&(t.allSeries=e.allSeries),void 0!==e.xValue&&void 0===t.xValue&&(t.xValue=e.xValue),o=t}const i=t(o);return null==i?null:(0,Cl.jsx)("div",{className:"semiotic-tooltip",style:Rl,children:i})}}return!1!==e&&void 0!==e&&(function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)&&"mode"in e&&"multi"===e.mode}(e)?"function"==typeof e.content?$l(e.content):("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip={{ mode: "multi" }} reached normalizeTooltip without a chart that wires tooltipMode. Prefer LineChart/AreaChart/StackedAreaChart/DifferenceChart, or pass frameProps.tooltipMode: "multi".'),e=>{const t=e.allSeries;if(!t||0===t.length)return(0,Cl.jsx)("div",{className:"semiotic-tooltip",style:Rl,children:(0,Cl.jsx)("div",{children:Tl(e.data?.value??e.data?.y)})});const n=e.xValue??e.data?.time??e.data?.x;return(0,Cl.jsxs)("div",{className:"semiotic-tooltip",style:Rl,children:[null!=n&&(0,Cl.jsx)("div",{style:{fontWeight:600,marginBottom:4,fontSize:"0.9em",borderBottom:"1px solid var(--semiotic-border, #eee)",paddingBottom:4},children:Tl(n)}),t.map((e,t)=>(0,Cl.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"1px 0"},children:[(0,Cl.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e.color,flexShrink:0}}),(0,Cl.jsx)("span",{style:{flex:1,fontSize:"0.85em"},children:e.group}),(0,Cl.jsx)("span",{style:{fontWeight:500,fontSize:"0.85em"},children:Tl(e.value)})]},t))]})}):"object"==typeof e&&null!==e&&("fields"in e||"title"in e)?Il(e):"multi"===e?("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(e={}){const{fields:t=[],title:n,format:o,style:i={},className:r="",showLabels:s=!0,separator:a=": "}=e;return e=>{if(!e||"object"!=typeof e)return null;const l=[];if(n){const t=Ll(e,n);l.push({value:Tl(t,o)})}if(t&&Array.isArray(t)&&t.length>0)t.forEach(t=>{let n,i,r;"string"==typeof t?(n=t,i=t,r=o):(n=t.label,i=t.accessor||t.key||"",r=t.format||o);const a=Tl(Ll(e,i),r);l.push({label:s?n:void 0,value:a})});else{const t=jl(e,{skipPositional:!1});null!=t.title&&l.push({label:void 0,value:Tl(t.title,o),bold:!0}),t.entries.forEach(e=>{l.push({label:s?e.key:void 0,value:Tl(e.value,o)})})}const c={...Rl,...i};return Array.isArray(l)&&0!==l.length?(0,Cl.jsx)("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+r).trim(),style:c,children:l.map((e,t)=>(0,Cl.jsxs)("div",{style:{marginBottom:l.length-1>t?"4px":0,fontWeight:e.bold?"bold":void 0},children:[e.label&&(0,Cl.jsxs)("strong",{children:[e.label,a]}),e.value]},t))}):null}}()):Il())}}var Ol=require("react/jsx-runtime");function zl({x:e,y:t,containerWidth:n,containerHeight:o,margin:i,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const l=Number.isFinite(e)&&Number.isFinite(t),c=bl.useRef(null),[u,d]=bl.useState(null);bl.useLayoutEffect(()=>{const e=c.current;if(!e)return;const t=()=>{const t=e.getBoundingClientRect();Number.isFinite(t.width)&&Number.isFinite(t.height)&&d(e=>e&&.5>Math.abs(e.width-t.width)&&.5>Math.abs(e.height-t.height)?e:{width:t.width,height:t.height})};if(t(),"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[s,n,o,l]);let h;h=u?`translate(${u.width+12>n-e?"calc(-100% - 12px)":"12px"}, ${u.height+12>o-t?"calc(-100% - 4px)":"4px"})`:`translate(${e>.7*n?"calc(-100% - 12px)":"12px"}, ${.3*o>t?"4px":"calc(-100% - 4px)"})`;const f=function(e){if(!bl.isValidElement(e))return!1;const t=e.type;if("string"!=typeof t&&t&&!0===t.ownsChrome)return!0;const n=e.props;if(!0===n["data-semiotic-tooltip-chrome"])return!0;if("true"===n["data-semiotic-tooltip-chrome"])return!0;const o=n.style;if(o&&"object"==typeof o){if(null!=o.background&&""!==o.background&&"transparent"!==o.background)return!0;if(null!=o.backgroundColor&&""!==o.backgroundColor&&"transparent"!==o.backgroundColor)return!0}return!1}(r),p=f?null:Rl;return l?(0,Ol.jsx)("div",{ref:c,className:f?s:(s+" semiotic-tooltip").trim(),style:{...p||{},position:"absolute",left:i.left+e,top:i.top+t,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}var Dl=g(require("react")),Fl=require("react"),El=require("react");var Nl=require("react"),Bl=()=>"undefined"!=typeof performance?performance.now():Date.now();function Wl(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function Yl(e,t){const n=e();return Number.isFinite(n)?n:t}var ql=class{constructor(e={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=e.clock??Bl,this.lastWallTime=Yl(this.clock,0),this.logicalTime=this.lastWallTime,this.pausedValue=!0===e.paused,this.visibleValue=!1!==e.visible,this.setRandomSource(e.random,e.seed)}get isActive(){return!this.pausedValue&&this.visibleValue}get paused(){return this.pausedValue}get seed(){return this.seedValue}get visible(){return this.visibleValue}configure(e){this.setClock(e.clock),this.setRandomSource(e.random,e.seed)}setPaused(e){this.pausedValue!==e&&(this.advance(),this.pausedValue=e,this.emit())}setVisible(e){this.visibleValue!==e&&(this.advance(),this.visibleValue=e,this.emit())}snapshot(){return{now:this.now(),paused:this.pausedValue,seed:this.seedValue,visible:this.visibleValue}}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}advance(){const e=Yl(this.clock,this.lastWallTime),t=Math.max(0,e-this.lastWallTime);return this.lastWallTime=e,this.isActive&&(this.logicalTime+=t),this.logicalTime}emit(){for(const e of this.subscribers)e()}setClock(e){const t=e??Bl;t!==this.clock&&(this.advance(),this.clock=t,this.lastWallTime=Yl(t,this.lastWallTime))}setRandomSource(e,t){const n=function(e){return"number"==typeof e&&Number.isFinite(e)?Math.trunc(e):void 0}(t);e===this.randomInput&&n===this.seedValue||(this.randomInput=e,this.seedValue=n,this.randomSource=e??(void 0===n?Math.random:Wl(n)))}},Xl="undefined"==typeof window?Fl.useEffect:Fl.useLayoutEffect,Hl={requestAnimationFrame:e=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(e),cancelAnimationFrame:e=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(e)};function Gl(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function Vl(e){const t=function(){const[e,t]=(0,El.useState)(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return(0,El.useEffect)(()=>{if("undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-reduced-motion: reduce)");return t(e.matches),function(e,t){if("function"==typeof e.addEventListener)return e.addEventListener("change",t),()=>e.removeEventListener("change",t);const n=e;return n.addListener(t),()=>n.removeListener(t)}(e,e=>t(e.matches))},[]),e}(),n=(0,Fl.useRef)(t);n.current=t;const[o,i]=function(e,t,n){const o=(0,Nl.useRef)(null),[i,r]=(0,Nl.useState)(null);return(0,Nl.useEffect)(()=>{if(!t&&!n)return;const e=o.current;if(!e)return;const i=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;r(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return i.observe(e),()=>i.disconnect()},[t,n]),[o,[t&&i?i.w:e[0],n&&i?i.h:e[1]]]}(e.sizeProp,e.responsiveWidth,e.responsiveHeight),r=!!e.title,s=!!e.legend&&"top"===e.legendPosition,a=(0,Fl.useMemo)(()=>Us({...e.marginDefault,...e.userMargin},r,s),[e.marginDefault,e.userMargin,r,s]),l=i[0]-a.left-a.right,c=i[1]-a.top-a.bottom,u=Gl(e.foregroundGraphics,i,a),d=Gl(e.backgroundGraphics,i,a),h=Qe(e=>e.theme),{transition:f,introEnabled:p}=function(e,t){if(!1===e)return{transition:void 0,introEnabled:!1};const n="undefined"!=typeof window&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return{transition:e?!0===e?{duration:300}:{duration:e.duration??300,easing:"linear"===e.easing?"linear":"ease-out"}:t,introEnabled:!(n||!e||!0!==e&&!1===e.intro)}}(e.animate,e.transitionProp),g="semiotic-table-"+Dl.useId(),y=(0,Fl.useRef)(null);if(!y.current){const t=!e.suspendWhenHidden||"undefined"==typeof document||!document.hidden;y.current=new ql({clock:e.clock,random:e.random,seed:e.seed,paused:e.paused,visible:t})}const m=y.current;m.configure({clock:e.clock,random:e.random,seed:e.seed});const x=(0,Fl.useRef)(null),b=(0,Fl.useRef)(e.frameScheduler??Hl);b.current=e.frameScheduler??Hl;const v=(0,Fl.useRef)(null),w=(0,Fl.useRef)(!1),k=(0,Fl.useRef)(()=>{}),S=(0,Fl.useCallback)(()=>{if(null!==x.current||w.current)return;const e=b.current;let t=!1,n=!1;const o=e.requestAnimationFrame(()=>{t=!0;const e=!n;e&&(w.current=!0),x.current=null,v.current=null;try{k.current()}finally{e&&(w.current=!1)}});n=!0,t||(x.current=o,v.current=e)},[]),A=(0,Fl.useCallback)(()=>{null!==x.current&&((v.current??b.current).cancelAnimationFrame(x.current),x.current=null,v.current=null)},[]);Xl(()=>{m.setPaused(!0===e.paused)},[m,e.paused]),(0,Fl.useEffect)(()=>{if(!e.suspendWhenHidden||"undefined"==typeof document)return void m.setVisible(!0);const t=()=>m.setVisible(!document.hidden);return t(),document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[m,e.suspendWhenHidden]),(0,Fl.useEffect)(()=>()=>{A()},[A]);const M=(0,Fl.useRef)(()=>{}),_=(0,Fl.useRef)(()=>{}),P=(0,Fl.useRef)(null),j=(0,Fl.useRef)(null),C=(0,Fl.useRef)(null),R=(0,Fl.useCallback)(()=>{const e=P.current;P.current=null,e&&M.current(e)},[]),L=(0,Fl.useCallback)(e=>{if(P.current={clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType},null===j.current){const e=b.current;let t=!1;const n=e.requestAnimationFrame(()=>{t=!0,j.current=null,C.current=null,R()});t||(j.current=n,C.current=e)}},[R]),T=(0,Fl.useCallback)(()=>{P.current=null,null!==j.current&&((C.current??b.current).cancelAnimationFrame(j.current),j.current=null,C.current=null),_.current()},[]);(0,Fl.useEffect)(()=>()=>{P.current=null,null!==j.current&&((C.current??b.current).cancelAnimationFrame(j.current),j.current=null,C.current=null)},[]);const I=e.themeDirtyRef;return Xl(()=>{I&&(Wo++,I.current=!0,S())},[h,S,I]),{reducedMotion:t,reducedMotionRef:n,responsiveRef:o,size:i,margin:a,adjustedWidth:l,adjustedHeight:c,resolvedForeground:u,resolvedBackground:d,currentTheme:h,transition:f,introEnabled:p,tableId:g,frameRuntime:m,rafRef:x,renderFnRef:k,scheduleRender:S,cancelRender:A,hoverHandlerRef:M,hoverLeaveRef:_,onPointerMove:L,onPointerLeave:T}}var Ul=require("react");function Kl(e,t,n,o){const i=e.getContext("2d");if(!i)return null;const r=Math.round(t[0]*o),s=Math.round(t[1]*o),a=r/t[0],l=s/t[1],c=t[0]+"px",u=t[1]+"px";return e.style.width!==c&&(e.style.width=c),e.style.height!==u&&(e.style.height=u),e.width===r&&e.height===s||(e.width=r,e.height=s),i.setTransform(a,0,0,l,0,0),i.translate(n.left,n.top),i}var Zl=require("react/jsx-runtime");function Ql(e){const{cancelRender:t,dirtyRef:n,frameRuntime:o,manageFrameRuntime:i,maxDevicePixelRatio:r,scheduleRender:s}=e,a=(0,Ul.useRef)(null),l=(0,Ul.useRef)(null),c=(0,Ul.useRef)(!1),u=(0,Ul.useRef)(!1),d=(0,Ul.useRef)(!1);return function(e){const{hydrated:t,wasHydratingFromSSR:n,storeRef:o,dirtyRef:i,renderFnRef:r,cancelRender:s,cleanup:a}=e;Ia(()=>{const e=o.current;t&&n&&e?.cancelIntroAnimation?.(),!n&&e?.sceneNodes&&e.sceneNodes.length>0&&e?.markStylePaintPending?e.markStylePaintPending():i.current=!0,s?.(),r.current()},[t,n]);const l=(0,Ta.useRef)(a);l.current=a,(0,Ta.useEffect)(()=>()=>l.current?.(),[])}({hydrated:e.hydrated,wasHydratingFromSSR:e.wasHydratingFromSSR,storeRef:e.storeRef,dirtyRef:e.dirtyRef,renderFnRef:e.renderFnRef,cancelRender:e.cancelRender,cleanup:e.cleanup}),(0,Ul.useEffect)(()=>{if(!1!==i)return o.subscribe(()=>{o.isActive?(n.current=!0,s()):t()})},[t,n,o,i,s]),(0,Ul.useEffect)(()=>function(){if("undefined"==typeof window||"function"!=typeof window.matchMedia)return()=>{};let e=null,t=!1;const n=()=>{e&&("function"==typeof e.removeEventListener?e.removeEventListener("change",i):"function"==typeof e.removeListener&&e.removeListener(i))},o=()=>{const t=`(resolution: ${window.devicePixelRatio||1}dppx)`;e=window.matchMedia(t),e.media.includes("resolution")?"function"==typeof e.addEventListener?e.addEventListener("change",i):"function"==typeof e.addListener&&e.addListener(i):e=null};function i(){t||(n(),e=null,c.current=!0,s(),queueMicrotask(()=>{t||o()}))}return o(),()=>{t=!0,n(),e=null}}(),[s]),(0,Ul.useEffect)(()=>{d.current?(c.current=!0,s()):d.current=!0},[r,s]),(0,Ul.useEffect)(()=>{!u.current&&(u.current=!0,e.skipInitialCanvasPaintInvalidation)||(e.canvasPaintInvalidator?e.canvasPaintInvalidator():e.dirtyRef.current=!0,e.scheduleRender())},e.canvasPaintDependencies),{canvasRef:a,interactionCanvasRef:l,resolutionDirtyRef:c}}function Jl({children:e,size:t,margin:n,overflowVisible:o=!1}){return e?(0,Zl.jsx)("svg",{style:{position:"absolute",left:0,top:0,width:t[0],height:t[1],pointerEvents:"none",overflow:o?"visible":void 0},children:(0,Zl.jsx)("g",{transform:`translate(${n.left},${n.top})`,children:e})}):null}function ec(e,t,n,o){return"function"==typeof e?e({size:t,margin:n,scales:o}):e}var tc=require("react");function nc(e,t,n,o){return"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:n,fn:e}:"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:o,fn:t}:{key:void 0,fn:null}}var oc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ic=3156e7;function rc(e){const t=e[1]-e[0];return 864e5>t?e=>{const t=new Date(e);return`${(t.getUTCHours()+"").padStart(2,"0")}:${(t.getUTCMinutes()+"").padStart(2,"0")}`}:ic>t?e=>{const t=new Date(e);return`${oc[t.getUTCMonth()]} ${t.getUTCDate()}`}:5*ic>t?e=>{const t=new Date(e);return`${oc[t.getUTCMonth()]} ${t.getUTCFullYear()}`}:e=>new Date(e).getUTCFullYear()+""}function sc(e){if(!e)return;const t=[];for(const n of e)if("point"===n.type)t.push(n);else if("symbol"===n.type)t.push({pointId:n.pointId,x:n.x,y:n.y,r:Sn(n.size)});else if("glyph"===n.type){const e=Eo(n.glyph,n.size);t.push({pointId:n.pointId,x:n.x+e.centerDx,y:n.y+e.centerDy,r:e.radius})}return t}var ac=require("d3-shape");function lc(e,t,n,o,i,r){if(2>t.length)return;const s=[0];for(let e=1;t.length>e;e++){const n=t[e][0]-t[e-1][0],o=t[e][1]-t[e-1][1];s.push(s[e-1]+Math.sqrt(n*n+o*o))}const a=s[s.length-1];if(0===a)return;const l=Math.min(.2*a,40);e.strokeStyle=n,e.lineWidth=o,e.lineCap=r;for(let n=0;t.length-1>n;n++){const o=(s[n]+s[n+1])/2;let r=i;l>o&&(r*=o/l),l>a-o&&(r*=(a-o)/l),e.globalAlpha=Math.max(0,r),e.beginPath(),e.moveTo(t[n][0],t[n][1]),e.lineTo(t[n+1][0],t[n+1][1]),e.stroke()}}var cc=(e,t,n,o)=>{const i=t.filter(e=>"line"===e.type);for(const t of i){if(2>t.path.length)continue;const n=t._introClipFraction;void 0!==n&&1>n&&(e.save(),e.beginPath(),e.rect(0,0,o.width*n,o.height),e.clip());const i=t.style.stroke||"#007bff",r=Ho(e,i)||i,s=t.style.strokeWidth||2,a=t.colorThresholds,l=t.rawValues;if(e.setLineDash(t.style.strokeDasharray?t.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),e.lineWidth=s,e.lineCap=t.style.strokeLinecap||"butt",t.style._edgeFade){lc(e,t.path,r,s,t.style.opacity??1,t.style.strokeLinecap||"butt"),e.globalAlpha=1,e.setLineDash([]),e.lineCap="butt";continue}const c=ni(t.curve),u=a&&a.length>0&&l&&l.length===t.path.length,d=t._decayOpacities;if(d&&d.length===t.path.length&&!u){e.strokeStyle=r;const n=t.style.opacity??1;for(let o=0;t.path.length-1>o;o++)e.globalAlpha=.5*(d[o]+d[o+1])*n,e.beginPath(),e.moveTo(t.path[o][0],t.path[o][1]),e.lineTo(t.path[o+1][0],t.path[o+1][1]),e.stroke()}else if(u){const n=ra(t.path,l,a,r);for(const t of n){e.beginPath(),e.strokeStyle=Ho(e,t.color)||t.color,e.moveTo(t.path[0][0],t.path[0][1]);for(let n=1;t.path.length>n;n++)e.lineTo(t.path[n][0],t.path[n][1]);e.stroke()}}else{e.beginPath();const n=t.strokeGradient&&t.path.length>=2?ii(e,t.strokeGradient,r,t.path[0][0],0,t.path[t.path.length-1][0],0):null;if(e.strokeStyle=n||r,c)(0,ac.line)().x(e=>e[0]).y(e=>e[1]).curve(c).context(e)(t.path);else{const[n,o]=t.path[0];e.moveTo(n,o);for(let n=1;t.path.length>n;n++)e.lineTo(t.path[n][0],t.path[n][1])}e.stroke()}if(t.style.fill&&t.style.fillOpacity&&t.style.fillOpacity>0){if(e.beginPath(),e.globalAlpha=t.style.fillOpacity,e.fillStyle=oi(e,t.style.fill,t.style.fill),c&&!u)(0,ac.line)().x(e=>e[0]).y(e=>e[1]).curve(c).context(e)(t.path);else{const[n,o]=t.path[0];e.moveTo(n,o);for(let n=1;t.path.length>n;n++)e.lineTo(t.path[n][0],t.path[n][1])}const n=t.path[0][0];e.lineTo(t.path[t.path.length-1][0],o.height),e.lineTo(n,o.height),e.closePath(),e.fill()}void 0!==n&&1>n&&e.restore(),e.globalAlpha=1,e.setLineDash([]),e.lineCap="butt"}};function uc(e){return!(!e._pulseIntensity||0>=e._pulseIntensity)}function dc(e,t,n=.3){uc(t)&&(e.globalAlpha=t._pulseIntensity*n,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h))}function hc(e,t,n=.6){if(!uc(t))return;const o=t.r+(t._pulseGlowRadius??4)*t._pulseIntensity,i=t.cx??t.x??0,r=t.cy??t.y??0;e.beginPath(),e.arc(i,r,o,0,2*Math.PI),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=2*t._pulseIntensity,e.globalAlpha=t._pulseIntensity*n,e.stroke()}function fc(e,t,n,o=.35){uc(t)&&(e.globalAlpha=t._pulseIntensity*o,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",n?e.fill(n):e.fill())}var pc=require("d3-shape");function gc(e,t){const n=ni(t.curve);if(!n||2>t.topPath.length||2>t.bottomPath.length){e.beginPath(),e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1]);for(let n=t.bottomPath.length-1;n>=0;n--)e.lineTo(t.bottomPath[n][0],t.bottomPath[n][1]);e.closePath()}else{const o=(0,pc.area)().x(e=>e[0]).y0((e,n)=>t.bottomPath[n][1]).y1(e=>e[1]).curve(n).context(e);e.beginPath(),o(t.topPath)}}function yc(e,t){const n=ni(t.curve);if(e.beginPath(),n)(0,pc.line)().x(e=>e[0]).y(e=>e[1]).curve(n).context(e)(t.topPath);else{e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let n=1;t.topPath.length>n;n++)e.lineTo(t.topPath[n][0],t.topPath[n][1])}}var mc=(e,t,n,o)=>{const i=t.filter(e=>"area"===e.type);for(const t of i){if(2>t.topPath.length)continue;let n=!1;t.clipRect&&(e.save(),e.beginPath(),e.rect(t.clipRect.x,t.clipRect.y,t.clipRect.width,t.clipRect.height),e.clip(),n=!0);const i=t._introClipFraction;void 0!==i&&1>i&&(e.save(),e.beginPath(),e.rect(0,0,o.width*i,o.height),e.clip());const r=oi(e,t.style.fill,"#4e79a7"),s=t._decayOpacities,a=!(!t.colorThresholds?.length||!t.rawValues||t.rawValues.length!==t.topPath.length),l=!!t.strokeColorBands?.length;if(s&&s.length===t.topPath.length&&!a&&!l){const n=t.style.fillOpacity??.7;e.fillStyle=r;for(let o=0;t.topPath.length-1>o;o++)e.globalAlpha=.5*(s[o]+s[o+1])*n,e.beginPath(),e.moveTo(t.topPath[o][0],t.topPath[o][1]),e.lineTo(t.topPath[o+1][0],t.topPath[o+1][1]),e.lineTo(t.bottomPath[o+1][0],t.bottomPath[o+1][1]),e.lineTo(t.bottomPath[o][0],t.bottomPath[o][1]),e.closePath(),e.fill();if(t.style.stroke&&"none"!==t.style.stroke){e.strokeStyle=Ho(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth||2,e.setLineDash([]);for(let n=0;t.topPath.length-1>n;n++)e.globalAlpha=.5*(s[n]+s[n+1]),e.beginPath(),e.moveTo(t.topPath[n][0],t.topPath[n][1]),e.lineTo(t.topPath[n+1][0],t.topPath[n+1][1]),e.stroke()}e.globalAlpha=1;continue}const c=t.style.opacity??1;if(gc(e,t),t.fillGradient&&t.fillGradient.stops.length>=2&&t.fillGradient){let n=1/0;for(const e of t.topPath)n>e[1]&&(n=e[1]);let o=-1/0;for(const e of t.bottomPath)e[1]>o&&(o=e[1]);const i=ii(e,t.fillGradient,"string"==typeof r?r:"#4e79a7",0,n,0,o);e.fillStyle=i||r,e.globalAlpha=c}else e.globalAlpha=(t.style.fillOpacity??.7)*c,e.fillStyle=r;if(e.fill(),t._pulseIntensity&&t._pulseIntensity>0&&(gc(e,t),fc(e,t)),t.style.stroke&&"none"!==t.style.stroke){e.globalAlpha=c;const n=Ho(e,t.style.stroke)||t.style.stroke,o=a||l||!t.strokeGradient||2>t.topPath.length?null:ii(e,t.strokeGradient,n,t.topPath[0][0],0,t.topPath[t.topPath.length-1][0],0);if(e.lineWidth=t.style.strokeWidth||2,e.setLineDash([]),l){let o=1/0,i=-1/0;for(const[e]of t.topPath)o=Math.min(o,e),i=Math.max(i,e);const r=e.lineWidth;for(const s of t.strokeColorBands){e.save(),e.beginPath(),e.rect(o-r,s.y,i-o+2*r,s.height),e.clip();const a=s.color??n;e.strokeStyle=Ho(e,a)||a,yc(e,t),e.stroke(),e.restore()}}else if(a){const o=ra(t.topPath,t.rawValues,t.colorThresholds,n);for(const t of o){e.beginPath(),e.strokeStyle=Ho(e,t.color)||t.color,e.moveTo(t.path[0][0],t.path[0][1]);for(let n=1;t.path.length>n;n++)e.lineTo(t.path[n][0],t.path[n][1]);e.stroke()}}else e.strokeStyle=o||n,yc(e,t),e.stroke()}void 0!==i&&1>i&&e.restore(),n&&e.restore(),e.globalAlpha=1}},xc=(e,t,n,o)=>{const i=t.filter(e=>"point"===e.type);if(0!==i.length){e.save();try{const t=e.globalAlpha;for(const n of i)e.beginPath(),e.arc(n.x,n.y,n.r,0,2*Math.PI),e.globalAlpha=t*(n.style.opacity??n.style.fillOpacity??1),e.fillStyle=oi(e,n.style.fill,"#4e79a7"),e.fill(),n.style.stroke&&"none"!==n.style.stroke&&(e.strokeStyle=oi(e,n.style.stroke,n.style.stroke),e.lineWidth=n.style.strokeWidth||1,e.stroke()),hc(e,n)}finally{e.restore()}}},bc=new Map;function vc(e,t,n,o,i,r){if(0>=t.size)return;const s=function(e,t,n){try{if(n)return new Path2D(n);const o=`${e??"circle"}:${Math.round(t)}`;let i=bc.get(o);return i||(i=new Path2D(kn(e,t)),bc.size>256&&bc.clear(),bc.set(o,i)),i}catch{return null}}(t.symbolType,t.size,t.path);if(!s)return;e.save(),e.translate(n,o),t.rotation&&e.rotate(t.rotation);const a=(t.style.opacity??1)*(t._decayOpacity??1);t.style.fill&&(e.globalAlpha=i*a*(t.style.fillOpacity??1),e.fillStyle=oi(e,t.style.fill,r),e.fill(s)),t.style.stroke&&"none"!==t.style.stroke&&(e.globalAlpha=i*a,e.strokeStyle=Ho(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.stroke(s)),e.restore()}var wc=(e,t)=>{const n=e.globalAlpha;for(const o of t)"symbol"===o.type&&vc(e,o,o.x,o.y,n,"#4e79a7");e.globalAlpha=n};function kc(e,t,n,o,i){if(0>=t.size)return;const r=t.glyph;if(!r||!r.parts?.length)return;const s=$o(r,t.size);if(0>=s.scale)return;const a=(t.style.opacity??1)*(t._decayOpacity??1);if(0>=a)return;const l=t=>{const n=oi(e,t,t);return"string"==typeof n?n:t},c=t.color??("string"==typeof t.style.fill?t.style.fill:void 0);e.save(),e.translate(n,o),t.rotation&&e.rotate(t.rotation),e.translate(s.offsetX,s.offsetY),e.scale(s.scale,s.scale),e.globalAlpha=i*a*(t.style.fillOpacity??1);const u=Fo(r,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal");u&&t.ghostColor&&No(e,r,c,t.accent,t.ghostColor,l),u&&(e.beginPath(),e.rect(u.x,u.y,u.width,u.height),e.clip()),No(e,r,c,t.accent,void 0,l),e.restore()}function Sc(e,t){const{x:n,y:o,w:i,h:r}=t,{tl:s,tr:a,br:l,bl:c}=aa(t);e.beginPath(),e.moveTo(n+s,o),e.lineTo(n+i-a,o),a>0&&e.arcTo(n+i,o,n+i,o+a,a),e.lineTo(n+i,o+r-l),l>0&&e.arcTo(n+i,o+r,n+i-l,o+r,l),e.lineTo(n+c,o+r),c>0&&e.arcTo(n,o+r,n,o+r-c,c),e.lineTo(n,o+s),s>0&&e.arcTo(n,o,n+s,o,s),e.closePath()}function Ac(e,t){const n=oi(e,t.style.fill,Ho(e,"var(--semiotic-primary, #007bff)")),o=function(e){switch(e.roundedEdge){case"bottom":return{x0:e.x,y0:e.y+e.h,x1:e.x,y1:e.y};case"right":return{x0:e.x+e.w,y0:e.y,x1:e.x,y1:e.y};case"left":return{x0:e.x,y0:e.y,x1:e.x+e.w,y1:e.y};default:return{x0:e.x,y0:e.y,x1:e.x,y1:e.y+e.h}}}(t);return(t.fillGradient&&"string"==typeof n?ii(e,t.fillGradient,n,o.x0,o.y0,o.x1,o.y1):null)||n}function Mc(e,t){return!(!t.style.stroke||"none"===t.style.stroke||(e.strokeStyle=Ho(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth||1,0))}var _c=(e,t,n,o)=>{const i=t.filter(e=>"rect"===e.type);for(const t of i){if(null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.icon)Pc(e,t);else if(t.cornerRadii&&sa(t.cornerRadii))e.fillStyle=Ac(e,t),Sc(e,t),e.fill(),Mc(e,t)&&e.stroke();else if(t.roundedTop&&t.roundedTop>0){e.fillStyle=Ac(e,t);const n=Math.min(t.roundedTop,t.w/2,t.h/2);e.beginPath();const{x:o,y:i,w:r,h:s}=t;switch(t.roundedEdge){case"right":e.moveTo(o,i),e.lineTo(o+r-n,i),e.arcTo(o+r,i,o+r,i+n,n),e.lineTo(o+r,i+s-n),e.arcTo(o+r,i+s,o+r-n,i+s,n),e.lineTo(o,i+s);break;case"left":e.moveTo(o+r,i),e.lineTo(o+n,i),e.arcTo(o,i,o,i+n,n),e.lineTo(o,i+s-n),e.arcTo(o,i+s,o+n,i+s,n),e.lineTo(o+r,i+s);break;case"bottom":e.moveTo(o,i),e.lineTo(o+r,i),e.lineTo(o+r,i+s-n),e.arcTo(o+r,i+s,o+r-n,i+s,n),e.lineTo(o+n,i+s),e.arcTo(o,i+s,o,i+s-n,n);break;default:e.moveTo(o,i+s),e.lineTo(o,i+n),e.arcTo(o,i,o+n,i,n),e.lineTo(o+r-n,i),e.arcTo(o+r,i,o+r,i+n,n),e.lineTo(o+r,i+s)}e.closePath(),e.fill(),Mc(e,t)&&e.stroke()}else e.fillStyle=Ac(e,t),e.fillRect(t.x,t.y,t.w,t.h),Mc(e,t)&&e.strokeRect(t.x,t.y,t.w,t.h);dc(e,t),e.globalAlpha=1}};function Pc(e,t){const n=t.style.icon,o=t.style.iconPadding||2,i=Math.min(t.w,t.h)-o;if(0>=i)return;const r=t.h>t.w;if(e.save(),e.beginPath(),e.rect(t.x,t.y,t.w,t.h),e.clip(),r){const r=i+o,s=t.x+(t.w-i)/2;for(let o=t.y+t.h-i;o>=t.y-i;o-=r)e.drawImage(n,s,o,i,i)}else{const r=i+o,s=t.y+(t.h-i)/2;for(let o=t.x;t.x+t.w>o;o+=r)e.drawImage(n,o,s,i,i)}e.restore()}function jc(e){const[t,n,o]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*n+.114*o>128?"#000":"#fff"}function Cc(e){return Number.isInteger(e)?e+"":100>Math.abs(e)?1>Math.abs(e)?e.toPrecision(3):e.toFixed(1):e.toFixed(0)}var Rc=(e,t,n,o)=>{const i=t.filter(e=>"heatcell"===e.type);e.save();try{for(const t of i){const n=t.style;null!=n?.opacity&&(e.globalAlpha=n.opacity),e.fillStyle=t.fill,e.fillRect(t.x,t.y,t.w,t.h);const o=Math.max(0,n?.strokeWidth??1);if(o>0&&(e.strokeStyle=Ho(e,n?.stroke??"var(--semiotic-surface, #fff)"),e.lineWidth=o,e.strokeRect(t.x,t.y,t.w,t.h)),dc(e,t),e.globalAlpha=1,t.showValues&&null!=t.value){if(20>t.w||20>t.h)continue;const n=t.valueFormat?t.valueFormat(t.value):Cc(t.value),o=Math.max(10,Math.min(16,.3*Math.min(t.w,t.h))),i=t.x+t.w/2,r=t.y+t.h/2;e.fillStyle=jc(t.fill),e.font=o+"px sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillText(n,i,r)}}}finally{e.restore()}},Lc=(e,t,n,o)=>{for(const n of t){if("candlestick"!==n.type)continue;const t=n;e.save();const i=(t._decayOpacity??1)*(t.style?.opacity??1);1!==i&&(e.globalAlpha=i);const r=Ho(e,t.wickColor)||t.wickColor,s=60>o.height,a=s?Math.max(t.wickWidth,2):t.wickWidth,l=()=>{e.beginPath(),e.moveTo(t.x,t.highY),e.lineTo(t.x,t.lowY),e.strokeStyle=r,e.lineWidth=a,e.stroke()};if(s||l(),t.isRange){const n=t.dotRadius??Math.max(2,Math.min(t.bodyWidth/2,.12*o.height));e.fillStyle=r,e.beginPath(),e.arc(t.x,t.highY,n,0,2*Math.PI),e.fill(),e.beginPath(),e.arc(t.x,t.lowY,n,0,2*Math.PI),e.fill()}else if(t.bodyWidth>0){const n=Math.min(t.openY,t.closeY),o=Math.abs(t.openY-t.closeY),i=t.isUp?t.upColor:t.downColor,r=Ho(e,i)||i;e.fillStyle=r,e.fillRect(t.x-t.bodyWidth/2,n,t.bodyWidth,Math.max(o,1)),e.strokeStyle=r,e.lineWidth=1,e.strokeRect(t.x-t.bodyWidth/2,n,t.bodyWidth,Math.max(o,1))}s&&l(),e.restore()}},Tc={line:[mc,cc,xc],area:[mc,xc],stackedarea:[mc,xc],scatter:[xc,wc],bubble:[xc,wc],heatmap:[Rc],bar:[_c],swarm:[xc],waterfall:[(e,t,n,o)=>{_c(e,t);const i=t.filter(e=>"rect"===e.type);if(2>i.length)return;const r=i[0].datum,s=r?._connectorStroke;if(s){e.save(),e.strokeStyle=Ho(e,s)||s,e.lineWidth=r?._connectorWidth??1,e.setLineDash([]);for(let t=0;i.length-1>t;t++){const o=i[t],r=i[t+1],s=o.datum,a=r.datum;if(null==s?.cumEnd||null==a?.baseline)continue;const l=n.y(s.cumEnd),c=o.x+o.w,u=r.x;e.beginPath(),e.moveTo(c,l),e.lineTo(u,l),e.stroke()}e.restore()}}],candlestick:[Lc],mixed:[mc,cc,xc],custom:[mc,_c,Rc,cc,xc,wc,(e,t)=>{const n=e.globalAlpha;for(const o of t)"glyph"===o.type&&kc(e,o,o.x,o.y,n);e.globalAlpha=n},Lc]},Ic=new Set;function $c(e,t){const n="function"==typeof e?e(t.datum??null,t):e;return(o=n)&&"object"==typeof o&&"string"==typeof o.id&&"function"==typeof o.cacheKey&&"function"==typeof o.drawCanvas&&"function"==typeof o.renderStaticSVG?n:void 0;var o}function Oc(e,t){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const n=`${e}:${t}`;Ic.has(n)||(Ic.add(n),console.warn(`[Semiotic] Render backend "${e}" does not support scene node "${t}"; using the built-in renderer.`))}function zc(e){const{node:t,index:n,renderMode:o,fallback:i}=e,r=$c(o,t);if(!r)return i();const s=r.renderStaticSVG({node:t,style:t.style??{},key:`${r.id}-${n}`});return null!=s?s:(Oc(r.id,t.type??"unknown"),i())}function Dc(e){const t=[];return e.nodes.forEach((n,o)=>{const i=zc({node:n,index:o,renderMode:e.renderMode,fallback:()=>e.fallback(n,o)});null!=i&&!1!==i&&t.push({node:n,element:i})}),t}require("react/jsx-runtime");var Fc=require("react/jsx-runtime");function Ec(e){return null==e?"":"number"==typeof e?Number.isInteger(e)?e+"":e.toFixed(2):e instanceof Date?e.toLocaleString():e+""}function Nc({hover:e}){const t=e.data??{},n=t.y??t.value,o=t.x??t.time;if(void 0===n&&void 0===o){const e=jl(t);if(null!=e.title||e.entries.length>0)return(0,Fc.jsxs)("div",{className:"semiotic-tooltip",style:Rl,children:[null!=e.title&&(0,Fc.jsx)("div",{style:{fontWeight:600,marginBottom:e.entries.length?2:0},children:e.title+""}),e.entries.map(e=>(0,Fc.jsxs)("div",{style:{opacity:.7,fontSize:11},children:[e.key,":"," ",(0,Fc.jsx)("span",{style:{fontWeight:600},children:Ec(e.value)})]},e.key))]})}return(0,Fc.jsxs)("div",{className:"semiotic-tooltip",style:Rl,children:[(0,Fc.jsx)("div",{style:{fontWeight:600,marginBottom:2},children:Ec(n)}),(0,Fc.jsx)("div",{style:{opacity:.7,fontSize:11},children:Ec(o)})]})}function Bc(e){const{onObservation:t,datum:n,x:o=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=e;t&&(n?(t({type:"hover",datum:n,x:o,y:i,timestamp:l,chartType:r,chartId:s}),"focus"===a?.type&&t({type:"focus",datum:n,inputType:"touch"===a.inputType?"pointer":a.inputType,timestamp:l,chartType:r,chartId:s})):t({type:"hover-end",timestamp:l,chartType:r,chartId:s}))}function Wc(e){const{onObservation:t,datum:n,x:o=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=e;t&&(n?(t({type:"click",datum:n,x:o,y:i,timestamp:l,chartType:r,chartId:s}),"activate"===a?.type&&t({type:"activate",datum:n,inputType:a.inputType,timestamp:l,chartType:r,chartId:s})):t({type:"click-end",timestamp:l,chartType:r,chartId:s}))}Nc.ownsChrome=!0;var Yc=require("react"),qc=require("react");function Xc(e,t,n){const o=e.byGroup.get(t);let i=0,r=Math.abs(o[0].x-n.x);for(let e=1;o.length>e;e++){const t=Math.abs(o[e].x-n.x);r>t&&(r=t,i=e)}return o[i]._flatIndex}function Hc(e){const t=[];for(const n of e)switch(n.type){case"point":t.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"symbol":if(0>=n.size)break;t.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"glyph":{if(0>=n.size||null==n.datum)break;const e=Eo(n.glyph,n.size);t.push({x:n.x+e.centerDx,y:n.y+e.centerDy,datum:n.datum,shape:"rect",w:2*e.halfWidth,h:2*e.halfHeight,group:"_default"});break}case"line":{const e=n,o=Array.isArray(e.datum)?e.datum:[],i=e.group??"_default";for(let n=0;e.path.length>n&&o.length>n;n++)t.push({x:e.path[n][0],y:e.path[n][1],datum:o[n],shape:"circle",group:i});break}case"area":{const e=n,o=Array.isArray(e.datum)?e.datum:[],i=e.group??"_default";for(let n=0;e.topPath.length>n&&o.length>n;n++)t.push({x:e.topPath[n][0],y:e.topPath[n][1],datum:o[n],shape:"circle",group:i});break}case"rect":t.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:n.group??"_default"});break;case"heatcell":t.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:"_default"})}return t.sort((e,t)=>e.x-t.x||e.y-t.y),t}var Gc=require("react/jsx-runtime"),Vc={top:20,right:20,bottom:30,left:40},Uc=Wa;function Kc(e){if(e)return"x"===e.dimension?"pan-y":"y"===e.dimension?"pan-x":"none"}var Zc=(0,_t.memo)((0,_t.forwardRef)(function(e,t){const{chartType:n,runtimeMode:o,data:i,chunkThreshold:r,chunkSize:s,xAccessor:a,yAccessor:l,accessorRevision:c,colorAccessor:u,sizeAccessor:d,symbolAccessor:h,symbolMap:f,groupAccessor:p,lineDataAccessor:g,curve:y,normalize:m,baseline:x,stackOrder:b,binSize:v,valueAccessor:w,arrowOfTime:k="right",windowMode:S="sliding",windowSize:A=200,timeAccessor:M,xExtent:_,yExtent:P,extentPadding:j=.1,scalePadding:C,sizeRange:R,size:L=[500,300],responsiveWidth:T,responsiveHeight:I,margin:$,className:O,background:D,maxDevicePixelRatio:F,renderMode:E,lineStyle:N,pointStyle:B,areaStyle:W,barStyle:Y,waterfallStyle:q,swarmStyle:X,barColors:H,colorScheme:G,boundsAccessor:V,boundsStyle:U,y0Accessor:K,band:Z,gradientFill:Q,lineGradient:J,semanticLineStops:ee,areaGroups:te,openAccessor:ne,highAccessor:oe,lowAccessor:ie,closeAccessor:re,candlestickStyle:se,showAxes:ae=!0,axes:le,xLabel:ce,yLabel:ue,yLabelRight:de,xFormat:he,yFormat:fe,axisExtent:pe,tickFormatTime:ge,tickFormatValue:ye,hoverAnnotation:me,tooltipContent:xe,customHoverBehavior:be,customClickBehavior:ve,onObservation:we,annotationObservationCallback:ke,chartId:Se,enableHover:Ae,hoverRadius:Me=30,tooltipMode:_e,annotations:Pe,onAnnotationActivate:je,autoPlaceAnnotations:Ce,svgAnnotationRules:Re,showGrid:Le,legend:Te,legendHoverBehavior:Oe,legendClickBehavior:ze,legendHighlightedCategory:De,legendIsolatedCategories:Fe,legendPosition:Ee,legendLayout:Ne,legendCategoryAccessor:Be,onCategoriesChange:We,backgroundGraphics:Ye,foregroundGraphics:Xe,canvasPreRenderers:He,svgPreRenderers:Ge,title:Ve,categoryAccessor:Ue,brush:Ke,onBrush:Ze,decay:Qe,pulse:Je,transition:et,animate:tt,staleness:nt,frameScheduler:ot,clock:it,random:rt,seed:st,paused:at=!1,suspendWhenHidden:lt=!0,heatmapAggregation:ct,heatmapXBins:ut,heatmapYBins:dt,showValues:ht,heatmapValueFormat:ft,marginalGraphics:pt,pointIdAccessor:gt,xScaleType:yt,yScaleType:mt,accessibleTable:xt=!0,description:bt,summary:vt,linkedCrosshairName:wt,linkedCrosshairSourceId:kt,customLayout:At,onLayoutError:Pt,layoutConfig:jt,layoutSelection:Ct}=e,{customHoverBehavior:Rt,customClickBehavior:It,hasClickBehavior:$t}=function({customHoverBehavior:e,customClickBehavior:t,onObservation:n,chartId:o,chartType:i}){const r=!(!e&&!n),s=!(!t&&!n),a=(0,Yc.useCallback)((t,r)=>{e?.(t,r),Bc({onObservation:n,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:i,chartId:o,context:r})},[o,i,e,n]),l=(0,Yc.useCallback)((e,r)=>{t?.(e,r),Wc({onObservation:n,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:i,chartId:o,context:r})},[o,i,t,n]);return{customHoverBehavior:r?a:void 0,customClickBehavior:s?l:void 0,hasClickBehavior:s}}({customHoverBehavior:be,customClickBehavior:ve,onObservation:we,chartId:Se,chartType:"StreamXYFrame"}),Ot=(0,_t.useId)().replace(/:/g,""),zt=(0,_t.useRef)(!1),Dt=(0,_t.useRef)({w:-1,h:-1}),Ft=(0,_t.useRef)(!1),Et=Vl({sizeProp:L,responsiveWidth:T,responsiveHeight:I,userMargin:$,marginDefault:Vc,title:Ve,legend:Te,legendPosition:Ee,animate:tt,transitionProp:et,frameScheduler:ot,clock:it,random:rt,seed:st,paused:at,suspendWhenHidden:lt,themeDirtyRef:zt}),Nt=function(){const[e,t]=(0,Ta.useState)(!1);return Ia(()=>{t(!0)},[]),e}(),Bt=function(){const e=(0,Ta.useSyncExternalStore)($a,Oa,za);return(0,Ta.useRef)(e).current}(),{reducedMotionRef:Wt,responsiveRef:Yt,size:qt,currentTheme:Xt,transition:Ht,introEnabled:Gt,tableId:Vt,rafRef:Ut,renderFnRef:Kt,scheduleRender:Zt,frameRuntime:Qt}=Et;let Jt=Et.margin;if(pt){const e=60,t={...Et.margin};pt.top&&e>t.top&&(t.top=e),pt.bottom&&e>t.bottom&&(t.bottom=e),pt.left&&e>t.left&&(t.left=e),pt.right&&e>t.right&&(t.right=e),Jt=t}const en=qt[0]-Jt.left-Jt.right,tn=qt[1]-Jt.top-Jt.bottom,nn=(le?.find(e=>"left"===e.orient)??le?.find(e=>"right"===e.orient))?.extent??pe,on=(0,_t.useMemo)(()=>z(i),[i]),rn=me??Ae,[sn,an]=(0,_t.useState)(0),ln=(0,_t.useRef)(0),[cn,un]=(0,_t.useState)(null),dn=ec(Xe,qt,Jt,cn),hn=ec(Ye,qt,Jt,cn),fn=(0,_t.useRef)(null),pn=(0,_t.useRef)(null),yn=(0,_t.useRef)(void 0),[mn,xn]=(0,_t.useState)(null),bn=(0,_t.useRef)(Uc.primary),vn=(0,_t.useRef)(function(){let e=-1,t=Wa;return{resolve(n){if(!n)return Wa;const o=Wo;return o===e||(t=function(e){if(!e)return Wa;const t=getComputedStyle(e),n=t.getPropertyValue("--semiotic-border").trim(),o=t.getPropertyValue("--semiotic-text-secondary").trim(),i=t.getPropertyValue("--semiotic-bg").trim(),r=t.getPropertyValue("--semiotic-primary").trim(),s=o||t.getPropertyValue("--text-secondary").trim(),a=t.getPropertyValue("--text-primary").trim(),l=n||t.getPropertyValue("--surface-3").trim(),c=i||t.getPropertyValue("--surface-0").trim();return s||a||n||r?{axisStroke:l||Wa.axisStroke,tickText:s||Wa.tickText,crosshair:s?Ya(s,"66"):Wa.crosshair,hoverFill:c?Ya(c,"4D"):Wa.hoverFill,hoverStroke:s?Ya(s,"99"):Wa.hoverStroke,pointRing:c||Wa.pointRing,primary:r||Wa.primary,background:c||Wa.background}:Wa}(n),e=o),t},invalidate(){e=-1}}}()),wn=(0,_t.useRef)(!1),kn=(0,mo.useRef)(new So("StreamXYFrame")),[Sn,An]=(0,_t.useState)(!1),[Mn,_n]=(0,_t.useState)([]),[Pn,jn]=(0,_t.useState)([]),Cn="streaming"===o||["bar","swarm","waterfall"].includes(n),Rn=function(e){const t=(0,Da.useRef)(e);return function(e,t){if(Object.is(e,t))return!0;if(Array.isArray(e)&&Array.isArray(t))return Ea(e,t);if(!Na(e)||!Na(t))return!1;const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(const o of n){if(!Object.prototype.hasOwnProperty.call(t,o))return!1;const n=e[o],i=t[o];if(!Object.is(n,i))if(Array.isArray(n)&&Array.isArray(i)){if(!Ea(n,i))return!1}else{if(!Na(n)||!Na(i))return!1;if(!Fa(n,i))return!1}}return!0}(t.current,e)||(t.current=e),t.current}((0,_t.useMemo)(()=>({chartType:n,runtimeMode:Cn?"streaming":"bounded",windowSize:A,windowMode:S,arrowOfTime:Cn?k:"right",extentPadding:j,scalePadding:C,axisExtent:pe,yAxisExtent:nn,xAccessor:a,yAccessor:l,accessorRevision:c,timeAccessor:Cn?M:void 0,valueAccessor:w,colorAccessor:u,sizeAccessor:d,symbolAccessor:h,symbolMap:f,groupAccessor:p||(g?"_lineGroup":void 0),categoryAccessor:Ue,lineDataAccessor:g,xScaleType:yt,yScaleType:mt,xExtent:_,yExtent:P,sizeRange:R,binSize:v,normalize:m,baseline:x,stackOrder:b,boundsAccessor:V,boundsStyle:U,y0Accessor:K,band:Z,gradientFill:Ie(Q),areaGroups:te?new Set(te):void 0,lineGradient:$e(J),semanticLineStops:ee,openAccessor:ne,highAccessor:oe,lowAccessor:ie,closeAccessor:re,candlestickStyle:se,lineStyle:N,pointStyle:B,areaStyle:W,swarmStyle:X,waterfallStyle:q,colorScheme:G,barColors:H,barStyle:Y,annotations:Pe,decay:Qe,pulse:Je,transition:Ht,introAnimation:Gt,staleness:nt,clock:Qt.now,heatmapAggregation:ct,heatmapXBins:ut,heatmapYBins:dt,showValues:ht,heatmapValueFormat:ft,pointIdAccessor:gt,curve:y,themeCategorical:Xt?.colors?.categorical,themeSemantic:qe(Xt),themeSequential:Xt?.colors?.sequential,themeDiverging:Xt?.colors?.diverging,customLayout:At,onLayoutError:Pt,layoutConfig:jt,layoutMargin:Jt}),[n,Cn,A,S,k,j,C,pe,nn,a,l,c,M,w,u,d,h,f,p,g,Ue,yt,mt,_,P,R,v,m,x,b,V,U,K,Z,Q,te,J,ee,ne,oe,ie,re,se,N,B,W,X,q,G,H,Y,Pe,Qe,Je,Ht,Gt,nt,Qt.now,ct,ut,dt,ht,ft,gt,y,Xt,At,Pt,jt,Jt])),Ln=(0,_t.useRef)(null);Ln.current||(Ln.current=new yo(Rn));const Tn=function(e,t,n,o){const i=(0,tc.useRef)({accessor:t,onChange:n,readData:o}),r=(0,tc.useRef)([]);return i.current={accessor:t,onChange:n,readData:o},(0,tc.useCallback)(()=>{const{accessor:t,onChange:n,readData:o}=i.current;if(!n||!t)return;const s=function(e,t){if(!t)return[];const n=new Set,o=[];for(const i of e){if(!i||"object"!=typeof i)continue;const e="function"==typeof t?t(i):i[t];if(null==e)continue;const r=e+"";n.has(r)||(n.add(r),o.push(r))}return o}(e.current?o(e.current):[],t);(function(e,t){if(e.length!==t.length)return!1;for(let n=0;e.length>n;n++)if(e[n]!==t[n])return!1;return!0})(s,r.current)||(r.current=s,n(s))},[e])}(Ln,Be,We,e=>e.getData());!function(e,t,n,o){(0,Po.useEffect)(()=>{e.current?.updateConfig(t),n.current=!0,o()},[t,o,e,n])}(Ln,Rn,zt,Zt),function(e,t,n,o){const i=(0,Po.useRef)(null);(0,Po.useEffect)(()=>{const r=e.current;if(!r)return;const s=t??null;i.current!==s&&(i.current=s,r.setLayoutSelection(s),r.hasCustomRestyle?r.restyleScene(s):n.current=!0,o())},[t,o,e,n])}(Ln,Ct,zt,Zt);const In=(0,_t.useRef)(null);In.current||(In.current=new Tt(e=>{const t=Ln.current;t&&t.ingest(e)&&(zt.current=!0,Zt())},{chunkThreshold:r,chunkSize:s})),(0,_t.useEffect)(()=>{In.current?.updateChunkOptions({chunkThreshold:r,chunkSize:s})},[r,s]);const $n=(0,_t.useCallback)(e=>{In.current?.push(e)},[]),On=(0,_t.useCallback)(e=>{In.current?.pushMany(e)},[]),zn=(0,_t.useCallback)(()=>{In.current?.clear(),Ln.current?.clear(),zt.current=!0,Zt()},[Zt]);(0,_t.useImperativeHandle)(t,()=>({push:$n,pushMany:On,remove:e=>{In.current?.flush();const t=Ln.current?.remove(e)??[];return t.length>0&&(fn.current&&t.some(e=>e===fn.current?.data)&&(fn.current=null,xn(null)),zt.current=!0,Zt()),t},update:(e,t)=>{In.current?.flush();const n=Ln.current?.update(e,t)??[];return n.length>0&&(zt.current=!0,Zt()),n},clear:zn,getData:()=>(In.current?.flush(),Ln.current?.getData()??[]),getScales:()=>Ln.current?.scales??null,getExtents:()=>Ln.current?.getExtents()??null,getCustomLayout:()=>Ln.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>Ln.current?.lastCustomLayoutFailure??null}),[$n,On,zn,Zt]),(0,_t.useEffect)(()=>{if(i){if(g&&on.length>0&&"object"==typeof on[0]&&null!==on[0]){const e="string"==typeof g?g:"coordinates";if(Array.isArray(on[0][e])){const t=[];for(const n of on){const o=n[e];if(Array.isArray(o)){const e=n.label||n.id||n.key;if(null!=e)for(const n of o)t.push({...n,_lineGroup:e});else for(const e of o)t.push(e)}}return void In.current?.setBoundedData(t)}}In.current?.setBoundedData(on)}},[i,on,g]);const{canvasRef:Dn,interactionCanvasRef:Fn,resolutionDirtyRef:En}=function(e,t){return Ql({...t,renderFnRef:e.renderFnRef,scheduleRender:e.scheduleRender,cancelRender:e.cancelRender,frameRuntime:e.frameRuntime})}(Et,{storeRef:Ln,dirtyRef:zt,hydrated:Nt,wasHydratingFromSSR:Bt,cleanup:()=>In.current?.clear(),maxDevicePixelRatio:F,canvasPaintDependencies:[n,en,tn,ae,D,Ye,N,E,He,Zt]}),{hoverHandlerRef:Nn,hoverLeaveRef:Bn,onPointerMove:Wn,onPointerLeave:Yn}=Et;Nn.current=e=>{if(!rn)return;const t=Dn.current;if(!t)return;const o=t.getBoundingClientRect(),i=e.clientX-o.left-Jt.left,r=e.clientY-o.top-Jt.top;if(0>i||i>en||0>r||r>tn)return void(fn.current&&(fn.current=null,pn.current=null,xn(null),Rt?.(null),Zt()));const s=Ln.current;if(!s||0===s.scene.length)return;const l=vl(Me,e.pointerType),c=ci(s.scene,i,r,l,s.quadtree,s.maxPointRadius),u="multi"===_e,d=()=>{fn.current&&(fn.current=null,pn.current=null,xn(null),Rt&&Rt(null),Zt())};if(!c&&!u)return void d();const h=u||!c?i:c.x,f=u||!c?r:c.y,p=c?.datum?gn(c.datum,s.resolvedRibbons):{},g=s.scales?.x?.invert,y="function"==typeof g?g(h):void 0;let m=kl(p,h,f,null!=y?{xValue:y,xPx:h}:void 0);if(u&&s.scene.length>0&&s.scales){const e=function(e,t,n=30){const o=[];for(const i of e)if("line"===i.type){const e=i;if(2>e.path.length)continue;const r=ui(li(e.path,e.curve),t,n);if(null===r)continue;const s=vi(e.path,t);o.push({node:i,datum:Array.isArray(e.datum)&&e.datum[s]?e.datum[s]:e.datum,x:e.path[s][0],y:r,group:e.group,color:e.style.stroke})}else if("area"===i.type){const e=i;if(!1===e.interactive)continue;if(2>e.topPath.length)continue;const r=li(e.topPath,e.curve),s=li(e.bottomPath,e.curve),a=ui(r,t,n);if(null===a)continue;const l=ui(s,t,n),c=vi(e.topPath,t);o.push({node:i,datum:Array.isArray(e.datum)&&e.datum[c]?e.datum[c]:e.datum,x:e.topPath[c][0],y:a,y0:l??void 0,group:e.group,color:"string"==typeof e.style.stroke?e.style.stroke:"string"==typeof e.style.fill?e.style.fill:void 0})}return o}(s.scene,h,Math.max(l,en));if(e.length>0){const t=s.scales.y.invert,o=bn.current,i=g?g(h):h;if(c)m.xValue=i,m.xPx=h;else{const e={xValue:i};"string"==typeof a&&(e[a]=i),m=kl(e,h,f,{xValue:i,xPx:h})}m.allSeries=e.map(e=>{const i=t?t(e.y):e.y,r=null!=e.y0?t?t(e.y0):e.y0:void 0;return{group:e.group||"",value:"stackedarea"===n&&null!=r?i-r:i,valuePx:e.y,color:e.color||o,datum:gn(e.datum,s.resolvedRibbons)}})}}c||m.allSeries?.length?(fn.current=m,pn.current=c?.node??null,xn(m),Rt?.(m),Zt()):d()},Bn.current=()=>{fn.current&&(fn.current=null,pn.current=null,xn(null),Rt?.(null),Zt())};const qn=(0,_t.useRef)(()=>{});qn.current=e=>{if((t=e.target)instanceof Element&&null!=t.closest("[data-semiotic-annotation-widget]"))return;var t;if(!It)return;const n=Dn.current;if(!n)return;const o=n.getBoundingClientRect(),i=e.clientX-o.left-Jt.left,r=e.clientY-o.top-Jt.top;if(0>i||i>en||0>r||r>tn)return void It(null);const s=Ln.current;if(!s||0===s.scene.length)return void It(null);const a=vl(Me,yn.current),l=ci(s.scene,i,r,a,s.quadtree,s.maxPointRadius);if(!l)return void It(null);const c=l.datum||{},u=s.scales?.x?.invert,d="function"==typeof u?u(l.x):void 0;var h;It(kl(c,l.x,l.y,null!=d?{xValue:d,xPx:l.x}:void 0),{type:"activate",inputType:(h=yn.current,"touch"===h?"touch":"pointer")})};const Xn=(0,_t.useCallback)(e=>qn.current(e),[]),{kbFocusIndexRef:Hn,focusedNavPointRef:Gn,onKeyDown:Vn}=(Un={storeRef:Ln,hoverRef:fn,hoveredNodeRef:pn,setHoverPoint:xn,customHoverBehavior:Rt,customClickBehavior:It,scheduleRender:Zt},function({storeRef:e,hoverRef:t,hoveredNodeRef:n,setHoverPoint:o,customHoverBehavior:i,customClickBehavior:r,scheduleRender:s,extractPoints:a,toHover:l}){const c=(0,qc.useRef)(-1),u=(0,qc.useRef)(null),d=(0,qc.useRef)(null),h=(0,qc.useCallback)(h=>{if(function(e){const t=e.target;return t instanceof Element&&t!==e.currentTarget&&null!=t.closest("button, a[href], input, select, textarea, summary, [contenteditable='true'], [role='button'], [role='link'], [role='checkbox'], [role='radio'], [role='switch']")}(h))return;const f=e.current;if(!f)return;const p=()=>{c.current=-1,u.current=null,t.current=null,n&&(n.current=null),o(null),i?.(null),s()};if(0===f.scene.length)return void(0>c.current||p());let g;if(d.current?.version===f.version)g=d.current.graph;else{const e=a(f.scene);if(0===e.length)return void(0>c.current||p());g=function(e){const t=new Map;for(const n of e){const e=n.group??"_default";let o=t.get(e);o||(o=[],t.set(e,o)),o.push(n)}for(const e of t.values()){e.sort((e,t)=>e.x-t.x||e.y-t.y);for(let t=0;e.length>t;t++)e[t]._groupIndex=t}const n=Array.from(t.keys()).sort((e,n)=>{const o=t.get(e),i=t.get(n);return(o.length>0?o[0].y:0)-(i.length>0?i[0].y:0)}),o=Array.from(t.values()).flat();o.sort((e,t)=>e.x-t.x||e.y-t.y);const i=new Map;for(let e=0;o.length>e;e++){o[e]._flatIndex=e;const t=o[e].datum?.id;null!=t&&i.set(t+"",e)}return{flat:o,groups:n,byGroup:t,idToIdx:i}}(e),d.current={version:f.version,graph:g}}let y=c.current;if(g.flat.length>y||(p(),y=-1),("Enter"===h.key||" "===h.key)&&y>=0)return h.preventDefault(),void r?.(l(g.flat[y],f),{type:"activate",inputType:"keyboard"});if(0>y){if("Escape"===h.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(h.key))return;h.preventDefault(),c.current=0;const e=g.flat[0];u.current=e;const n=l(e,f);return t.current=n,o(n),i?.(n,{type:"focus",inputType:"keyboard"}),void s()}const m=function(e,t,n){const{group:o,indexInGroup:i}=t,r=n.byGroup.get(o);switch(e){case"ArrowRight":return r.length-1>i?r[i+1]._flatIndex:t.flatIndex;case"ArrowLeft":return i>0?r[i-1]._flatIndex:t.flatIndex;case"ArrowDown":{const e=n.groups.indexOf(o);return n.groups.length-1>e?Xc(n,n.groups[e+1],r[i]):t.flatIndex}case"ArrowUp":{const e=n.groups.indexOf(o);return e>0?Xc(n,n.groups[e-1],r[i]):t.flatIndex}case"PageDown":return Math.min(t.flatIndex+Math.max(1,Math.floor(.1*n.flat.length)),n.flat.length-1);case"PageUp":return Math.max(t.flatIndex-Math.max(1,Math.floor(.1*n.flat.length)),0);case"Home":return 0;case"End":return n.flat.length-1;case"Escape":return-1;default:return null}}(h.key,function(e,t){if(0===e.flat.length)return{flatIndex:-1,group:"_default",indexInGroup:-1};const n=Math.max(0,Math.min(t,e.flat.length-1)),o=e.flat[n];return{flatIndex:n,group:o.group??"_default",indexInGroup:o._groupIndex??0}}(g,y),g);if(null===m)return;if(h.preventDefault(),0>m)return void p();c.current=m;const x=g.flat[m];u.current=x;const b=l(x,f);t.current=b,o(b),i?.(b,{type:"focus",inputType:"keyboard"}),s()},[r,i,a,t,n,s,o,e,l]);return{kbFocusIndexRef:c,focusedNavPointRef:u,onKeyDown:h}}({...Un,extractPoints:Hc,toHover:(e,t)=>function(e){return{data:e.datum||{},x:e.x,y:e.y,__semioticHoverData:!0}}({...e,datum:gn(e.datum,t.resolvedRibbons)})}));var Un;const Kn=(0,_t.useCallback)(e=>{yn.current=e.pointerType,Hn.current=-1,Gn.current=null,Wn(e)},[Gn,Hn,Wn]),Zn=(0,_t.useCallback)(e=>{yn.current="mouse",Hn.current=-1,Gn.current=null,Wn({clientX:e.clientX,clientY:e.clientY,pointerType:"mouse"})},[Gn,Hn,Wn]),Qn=(0,_t.useCallback)(e=>{yn.current=e.pointerType},[]);Kt.current=()=>{if(Ut.current=null,!Qt.isActive)return;const e=Dn.current,t=Fn.current;if(!e||!t)return;const o=Ln.current;if(!o)return;const i=Qt.now(),r=o.advanceTransition(Wt.current?i+1e6:i),s=!Wt.current&&r,c=Dt.current.w!==en||Dt.current.h!==tn,u=En.current,d=zt.current||r||c,h=o.consumeStylePaintPending();let f=!1;const p=o.getLastUpdateResult(),g=kn.current.beforeCompute(p,s);!d||s&&!c||(o.computeScene({width:en,height:tn}),Dt.current={w:en,h:tn},f=!0,Tn()),kn.current.afterCompute(g,f,c);const y=function(e,t,n,o){const i=o.current,r=!0===e.lastCustomLayoutFailure?.preservedLastGoodScene,s=!r&&e.hasActivePulsesAt(t),a=!(n||r||!s&&!i)&&e.refreshPulse(t);return o.current=s,{changed:a,pending:s}}(o,i,f,Ft),m=function(e){if("undefined"==typeof window)return 1;const t=window.devicePixelRatio||1,n=function(){if("undefined"==typeof window)return!1;const e="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,t=768>Math.min(window.innerWidth||1/0,window.innerHeight||1/0);return e||t}()?2:3;return Math.max(1,Math.min(t,"number"==typeof e&&e>0?e:n))}(F),x=vn.current.resolve(e);bn.current=x.primary;const b=Ai(nt,o.lastIngestTime>0?i-o.lastIngestTime:0),v=nt&&b.isStale;if(d||h||y.changed||u){const t=Kl(e,qt,Jt,m);if(t){if(t.clearRect(-Jt.left,-Jt.top,qt[0],qt[1]),nt&&1>b.alpha&&(t.globalAlpha=b.alpha),function(e,t){const{background:n,hasBackgroundGraphics:o=!1,themeBackground:i="",x:r=0,y:s=0,width:a,height:l}=t,c=Ba({background:n,hasBackgroundGraphics:o,themeBackground:i});if(!c)return!1;const u=Ho(e,c);u&&(e.fillStyle=u,e.fillRect(r,s,a,l))}(t,{background:D,hasBackgroundGraphics:!!Ye,themeBackground:x.background,x:-Jt.left,y:-Jt.top,width:qt[0],height:qt[1]}),t.save(),"function"==typeof t.rect&&(t.beginPath(),t.rect(0,0,en,tn),t.clip()),He&&o.scales)for(const e of He)t.save(),e(t,o.scene,o.scales,{width:en,height:tn}),t.restore();const e=At?Tc.custom:Tc[n];!function(e){const{context:t,nodes:n,renderMode:o,pixelRatio:i,paintBuiltIn:r}=e;if(!o||"sketchy"===o)return void r(n);let s=[];const a=()=>{s.length&&(r(s),s=[])};for(const e of n){const n=$c(o,e);if(!n){s.push(e);continue}let l;a(),t.save();try{l=n.drawCanvas({context:t,node:e,style:e.style??{},pixelRatio:i})}finally{t.restore()}l||(Oc(n.id,e.type??"unknown"),r([e]))}a()}({context:t,nodes:o.scene,renderMode:E,pixelRatio:m,paintBuiltIn:n=>{if(e&&o.scales)for(const i of e)i(t,n,o.scales,{width:en,height:tn})}}),t.restore(),nt&&1>b.alpha&&(t.globalAlpha=1)}}const w=!!(rn&&fn.current&&o.scales),k=!!(pn.current&&Array.isArray(me)&&me.some(e=>e&&"object"==typeof e&&"highlight"===e.type)),S=w||k;if(S||wn.current){const e=Kl(t,qt,Jt,m);if(e&&(e.clearRect(-Jt.left,-Jt.top,qt[0],qt[1]),w&&fn.current&&function(e,t,n,o,i,r,s){if(!1===i.crosshair)return;const a=t.allSeries,l=a&&a.length>0,c=t.xPx??t.x;e.save();const u="object"==typeof i.crosshair?i.crosshair:{};if(e.strokeStyle=u.stroke||s.crosshair,e.lineWidth=u.strokeWidth||1,e.setLineDash(u.strokeDasharray?u.strokeDasharray.split(/[\s,]+/).map(Number):[4,4]),e.beginPath(),e.moveTo(l?c:t.x,0),e.lineTo(l?c:t.x,o),e.stroke(),l||(e.beginPath(),e.moveTo(0,t.y),e.lineTo(n,t.y),e.stroke()),e.restore(),l){e.lineWidth=2,e.strokeStyle=s.pointRing;for(const t of a)null!=t.valuePx&&(e.beginPath(),e.arc(c,t.valuePx,4,0,2*Math.PI),e.fillStyle=t.color||s.primary,e.fill(),e.stroke())}else{const n=i.pointColor||function(e){if(!e)return null;if("heatcell"===e.type)return e.fill||null;if("candlestick"===e.type)return e.isUp?e.upColor:e.downColor;const{style:t}=e;if(!t)return null;const n="string"==typeof t.fill?t.fill:null;return"line"===e.type||"area"===e.type?t.stroke||n||null:n||t.stroke||null}(r)||s.primary;e.beginPath(),e.arc(t.x,t.y,4,0,2*Math.PI),e.fillStyle=n,e.fill(),e.strokeStyle=s.pointRing,e.lineWidth=2,e.stroke()}}(e,fn.current,en,tn,"object"==typeof rn?rn:{},pn.current,x),k&&pn.current&&Array.isArray(me))){const t=me.find(e=>e&&"object"==typeof e&&"highlight"===e.type);t&&function(e,t,n,o,i){if(!n)return;const r="group"in n?n.group:void 0;if(void 0!==r)for(const n of t){if("line"!==n.type)continue;if(n.group!==r)continue;if(2>n.path.length)continue;const t="function"==typeof o.style?n.datum?o.style(n.datum):{}:o.style||{};e.save(),e.beginPath(),e.moveTo(n.path[0][0],n.path[0][1]);for(let t=1;n.path.length>t;t++)e.lineTo(n.path[t][0],n.path[t][1]);e.strokeStyle=t.stroke||n.style.stroke||i.primary,e.lineWidth=t.strokeWidth||(n.style.strokeWidth||2)+2,e.globalAlpha=t.opacity??1,e.stroke(),e.restore()}}(e,o.scene,pn.current,t,x)}wn.current=S}d&&e&&e.setAttribute("aria-label",el(o.scene,n+" chart"));const A=zt.current;if(zt.current=A&&s&&!f,En.current=!1,A&&o.scales){const e=e=>"object"==typeof e&&null!==e&&"function"==typeof e.valueOf?e.valueOf():e;if((!cn||e(cn.x.domain()[0])!==e(o.scales.x.domain()[0])||e(cn.x.domain()[1])!==e(o.scales.x.domain()[1])||e(cn.y.domain()[0])!==e(o.scales.y.domain()[0])||e(cn.y.domain()[1])!==e(o.scales.y.domain()[1])||cn.x.range()[0]!==o.scales.x.range()[0]||cn.x.range()[1]!==o.scales.x.range()[1]||cn.y.range()[0]!==o.scales.y.range()[0]||cn.y.range()[1]!==o.scales.y.range()[1])&&un(o.scales),pt){const e=o.getData(),t="function"==typeof a?a:e=>e[a||"x"],n="function"==typeof l?l:e=>e[l||"y"];_n(e.map(e=>t(e)).filter(e=>"number"==typeof e&&isFinite(e))),jn(e.map(e=>n(e)).filter(e=>"number"==typeof e&&isFinite(e)))}}!((Pe&&Pe.length>0||At)&&(f||s))||!f&&33>i-ln.current||(an(e=>e+1),ln.current=i),nt?.showBadge&&An(!!v),(s||null!=o.activeTransition||y.pending)&&Zt()},function(e,t,n,o,i,r){const s=(0,wi.useRef)("fresh");(0,wi.useEffect)(()=>{if(!e)return;const a=setInterval(()=>{const a=t.current;if(!a||0===a.lastIngestTime)return;const l="undefined"!=typeof performance?performance.now():Date.now(),c=Ai(e,l-a.lastIngestTime);c.band===s.current&&c.isStale===i||(s.current=c.band,c.isStale!==i&&r(c.isStale),n.current=!0,o())},1e3);return()=>clearInterval(a)},[e,i,o,t,r,n])}(nt,Ln,zt,Zt,Sn,An);const Jn=(0,_t.useMemo)(()=>{if(he||ge)return;const e=Ln.current;return e?.xIsDate&&cn?rc(cn.x.domain()):void 0},[he,ge,cn]),eo=he||ge||Jn,to=rn&&mn?xe?xe(mn):(0,Gc.jsx)(Nc,{hover:mn}):null,no=to?(0,Gc.jsx)(zl,{x:mn.x,y:mn.y,containerWidth:en,containerHeight:tn,margin:Jt,className:"stream-frame-tooltip",children:to}):null,oo=Gn.current,io=(0,Gc.jsx)(xl,{active:Hn.current>=0,hoverPoint:mn,margin:Jt,size:qt,shape:oo?.shape,width:oo?.w,height:oo?.h}),ro=nc(a,M,"__semiotic_resolvedX","__semiotic_resolvedTime"),so=nc(l,w,"__semiotic_resolvedY","__semiotic_resolvedValue"),ao=ro.key,lo=so.key,co=function(e,t,n){return o=>{if(!o||!n||!e.fn&&!t.fn)return o;let i=!1;const r=o.map(n=>{const o=e.fn&&e.key&&!(e.key in n),r=t.fn&&t.key&&!(t.key in n);if(!o&&!r)return n;i=!0;const s={...n};return o&&(s[e.key]=e.fn(n)),r&&(s[t.key]=t.fn(n)),s});return i?r:o}}(ro,so,Pe&&Pe.length>0||!1);if(La||!Nt&&Bt){const e=Ln.current;e&&i&&(e.ingest({inserts:on,bounded:!0}),e.computeScene({width:en,height:tn}));const t=e?.scene??[],n=e?.scales??null,o=ec(Xe,qt,Jt,n),r=ec(Ye,qt,Jt,n),s=eo||(()=>{if(e?.xIsDate&&n)return rc(n.x.domain())})();return(0,Gc.jsxs)("div",{ref:Yt,className:"stream-xy-frame"+(O?" "+O:""),role:"img","aria-label":bt||("string"==typeof Ve?Ve:"XY chart"),style:{position:"relative",width:T?"100%":qt[0],height:I?"100%":qt[1]},children:[(0,Gc.jsx)(pl,{summary:vt}),(0,Gc.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:qt[0],height:qt[1],style:{position:"absolute",left:0,top:0},children:[(0,Gc.jsx)("g",{transform:`translate(${Jt.left},${Jt.top})`,children:r}),(0,Gc.jsxs)("g",{transform:`translate(${Jt.left},${Jt.top})`,children:[D&&(0,Gc.jsx)("rect",{x:0,y:0,width:en,height:tn,fill:D}),Ge&&n&&Ge.map((e,o)=>(0,Gc.jsx)(Mt.Fragment,{children:e(t,n,{width:en,height:tn})},"svgpre-"+o)),t.map((e,t)=>zc({node:e,index:t,renderMode:E,fallback:()=>Ra(e,t,Ot)})).filter(Boolean)]})]}),(0,Gc.jsx)(ta,{width:en,height:tn,totalWidth:qt[0],totalHeight:qt[1],margin:Jt,scales:n,showAxes:ae,axes:le,xLabel:ce,yLabel:ue,yLabelRight:de,xFormat:s,yFormat:fe||ye,axisExtent:pe,showGrid:Le,title:Ve,legend:Te,legendHoverBehavior:Oe,legendClickBehavior:ze,legendHighlightedCategory:De,legendIsolatedCategories:Fe,legendPosition:Ee,legendLayout:Ne,foregroundGraphics:_o(o,St(Ln.current?.customLayoutOverlays,Ct??null)),marginalGraphics:pt,xValues:[],yValues:[],annotations:Pe,onAnnotationActivate:je,onObservation:ke??we,chartId:Se,chartType:"StreamXYFrame",autoPlaceAnnotations:Ce,svgAnnotationRules:Re,annotationFrame:0,xAccessor:ao,yAccessor:lo,annotationData:co(Ln.current?.getData()),pointNodes:sc(Ln.current?.scene),curve:"string"==typeof y?y:void 0,linkedCrosshairName:wt,linkedCrosshairSourceId:kt})]})}return(0,Gc.jsxs)("div",{ref:Yt,className:"stream-xy-frame"+(O?" "+O:""),role:"group","aria-label":bt||("string"==typeof Ve?Ve:"XY chart"),tabIndex:0,style:{position:"relative",width:T?"100%":qt[0],height:I?"100%":qt[1],overflow:"visible",touchAction:Kc(Ke)},onKeyDown:Vn,children:["production"!==process.env.NODE_ENV&&Ln.current&&(0,Gc.jsx)(Ao,{store:Ln.current,diagnostics:kn.current}),xt&&(0,Gc.jsx)(gl,{tableId:Vt}),xt&&(0,Gc.jsx)(fl,{scene:Ln.current?.scene??[],chartType:n+" chart",tableId:Vt,chartTitle:"string"==typeof Ve?Ve:void 0}),(0,Gc.jsx)(pl,{summary:vt}),(0,Gc.jsx)(Ua,{hoverPoint:mn}),(0,Gc.jsxs)("div",{role:"img","aria-label":bt||("string"==typeof Ve?Ve:"XY chart"),style:{position:"relative",width:"100%",height:"100%"},onPointerMove:rn?Kn:void 0,onMouseMove:rn?Zn:void 0,onPointerLeave:rn?Yn:void 0,onMouseLeave:rn?Yn:void 0,onPointerDown:rn||$t?Qn:void 0,onClick:$t?Xn:void 0,children:[(0,Gc.jsx)(Jl,{size:qt,margin:Jt,children:hn}),(0,Gc.jsx)(Qs,{width:en,height:tn,totalWidth:qt[0],totalHeight:qt[1],margin:Jt,scales:cn,showAxes:ae,axes:le,showGrid:Le,xFormat:eo,yFormat:fe||ye,axisExtent:pe}),(0,Gc.jsx)("canvas",{ref:Dn,"aria-label":el(Ln.current?.scene??[],n+" chart"),style:{position:"absolute",left:0,top:0}}),(0,Gc.jsx)("canvas",{ref:Fn,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),(0,Gc.jsx)(ta,{width:en,height:tn,totalWidth:qt[0],totalHeight:qt[1],margin:Jt,scales:cn,showAxes:ae,axes:le,xLabel:ce,yLabel:ue,yLabelRight:de,xFormat:eo,yFormat:fe||ye,axisExtent:pe,showGrid:Le,title:Ve,legend:Te,legendHoverBehavior:Oe,legendClickBehavior:ze,legendHighlightedCategory:De,legendIsolatedCategories:Fe,legendPosition:Ee,legendLayout:Ne,foregroundGraphics:_o(dn,St(Ln.current?.customLayoutOverlays,Ct??null)),marginalGraphics:pt,xValues:Mn,yValues:Pn,annotations:Pe,onAnnotationActivate:je,onObservation:ke??we,chartId:Se,chartType:"StreamXYFrame",autoPlaceAnnotations:Ce,svgAnnotationRules:Re,annotationFrame:sn,xAccessor:ao,yAccessor:lo,annotationData:co(Ln.current?.getData()),pointNodes:sc(Ln.current?.scene),curve:"string"==typeof y?y:void 0,underlayRendered:!0,canvasObscuresUnderlay:!!Ba({background:D,hasBackgroundGraphics:!!Ye,themeBackground:Xt?.colors.background}),linkedCrosshairName:wt,linkedCrosshairSourceId:kt}),(Ke||Ze)&&(0,Gc.jsx)(Lt,{width:en,height:tn,totalWidth:qt[0],totalHeight:qt[1],margin:Jt,dimension:Ke?.dimension??"xy",scales:cn,onBrush:Ze??(()=>{}),binSize:v,snap:Ke?.snap,binBoundaries:Ke?.binBoundaries??("bar"===n?Ln.current?.getBinBoundaries():void 0),snapDuring:Ke?.snapDuring,streaming:"streaming"===o}),nt?.showBadge&&(0,Gc.jsx)(_i,{isStale:Sn,position:nt.badgePosition}),io,no]})]})}));Zc.displayName="StreamXYFrame";var Qc=Zc,Jc=g(require("react")),eu=require("react/jsx-runtime");function tu({componentName:e,message:t,diagnosticHint:n,width:o,height:i}){return(0,eu.jsx)("div",{role:"alert",style:{width:o,height:Math.max(i,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"},children:(0,eu.jsxs)("div",{style:{textAlign:"center",maxWidth:400},children:[(0,eu.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:e}),(0,eu.jsx)("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:t}),n&&(0,eu.jsx)("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:n})]})})}var nu=require("react/jsx-runtime"),ou=class extends Jc.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t)}render(){if(this.state.error){const{fallback:e}=this.props,t=this.state.error;return"function"==typeof e?e(t):void 0!==e?e:(0,nu.jsx)(tu,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}},iu=require("react/jsx-runtime");function ru({componentName:e,width:t,height:n,children:o}){return(0,iu.jsx)(ou,{fallback:o=>(0,iu.jsx)(tu,{componentName:e,message:o.message,width:t,height:n}),children:o})}"undefined"!=typeof process&&process;var su={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"},au={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2},lu=require("react"),cu=require("react"),uu=require("react"),du=(require("react/jsx-runtime"),(0,uu.createContext)(null));function hu(){return(0,uu.useContext)(du)}var fu=require("react");function pu(e){const t=[];for(const[n,o]of Object.entries(e.fields))if("point"===o.type)t.push(e=>o.values.has(e[n]));else{const[e,i]=o.range;t.push(t=>{const o=t[n];return o>=e&&i>=o})}return e=>t.every(t=>t(e))}function gu(e,t){let n=e.get(t);return n||(n={name:t,resolution:"union",clauses:new Map},e.set(t,n)),n}function yu(e,t){if(e.type!==t.type)return!1;if("interval"===e.type&&"interval"===t.type)return e.range[0]===t.range[0]&&e.range[1]===t.range[1];if("point"===e.type&&"point"===t.type){if(e.values.size!==t.values.size)return!1;for(const n of e.values)if(!t.values.has(n))return!1;return!0}return!1}var[mu,xu]=Be(e=>({selections:new Map,setClause(t,n){e(e=>{const o=e.selections.get(t),i=o?.clauses.get(n.clientId);if(i&&function(e,t){if(e.clientId!==t.clientId||e.type!==t.type)return!1;const n=Object.entries(e.fields);if(n.length!==function(e){let t=0;for(const n in e)t++;return t}(t.fields))return!1;for(const[e,o]of n){const n=t.fields[e];if(!n||!yu(o,n))return!1}return!0}(i,n))return{};const r=new Map(e.selections),s=gu(r,t),a=new Map(s.clauses);return a.set(n.clientId,n),r.set(t,{...s,clauses:a}),{selections:r}})},clearClause(t,n){e(e=>{const o=e.selections.get(t);if(!o||!o.clauses.has(n))return{};const i=new Map(e.selections),r=new Map(o.clauses);return r.delete(n),i.set(t,{...o,clauses:r}),{selections:i}})},setResolution(t,n){e(e=>{const o=e.selections.get(t);if(o?.resolution===n)return{};const i=new Map(e.selections),r=gu(i,t);return i.set(t,{...r,resolution:n}),{selections:i}})},clearSelection(t){e(e=>{const n=e.selections.get(t);if(!n||0===n.clauses.size)return{};const o=new Map(e.selections);return o.set(t,{...n,clauses:new Map}),{selections:o}})}}));function bu(e){const t=(0,fu.useId)(),n=e.clientId||t,{name:o}=e,i=xu(e=>e.selections.get(o)),r=xu(e=>e.setClause),s=xu(e=>e.clearClause),a=(0,fu.useMemo)(()=>!!i&&i.clauses.size>0,[i]);return{predicate:(0,fu.useMemo)(()=>i&&0!==i.clauses.size?function(e,t){const n=[];for(const[o,i]of e.clauses)"crossfilter"===e.resolution&&o===t||n.push(pu(i));return 0===n.length?()=>!0:"intersect"===e.resolution?e=>n.every(t=>t(e)):e=>n.some(t=>t(e))}(i,n):()=>!0,[i,n]),isActive:a,selectPoints:(0,fu.useCallback)(e=>{const t={};let i=!1;for(const[n,o]of Object.entries(e))t[n]={type:"point",values:new Set(o)},i=!0;i&&r(o,{clientId:n,type:"point",fields:t})},[n,o,r]),selectInterval:(0,fu.useCallback)(e=>{const t={};let i=!1;for(const[n,o]of Object.entries(e))t[n]={type:"interval",range:o},i=!0;i&&r(o,{clientId:n,type:"interval",fields:t})},[n,o,r]),clear:(0,fu.useCallback)(()=>{s(o,n)},[s,o,n]),clientId:n}}var vu=g(require("react"));function wu(){return Qe(e=>e.theme)}function ku(e,t,n){const o=e.xValue??t?.[n];if(null==o)return null;const i=Number(o);return Number.isFinite(i)?i:null}function Su(e){let t=e.data||e.datum||e;return Array.isArray(t)&&(t=t[0]),null!=e.xValue&&t&&"object"==typeof t&&!Array.isArray(t)&&null==t.xValue?{...t,xValue:e.xValue}:t||{}}function Au(e){if(!e)return!1;for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}require("react/jsx-runtime"),vu.createContext(void 0);var Mu=require("react"),_u=require("react"),Pu=(require("react/jsx-runtime"),(0,_u.createContext)(!1));(0,_u.createContext)(!1);var ju=(0,_u.createContext)(null),Cu="undefined"==typeof window?_u.useEffect:_u.useLayoutEffect;function Ru(e,t){if(!t)return[];const n=new Set;for(const o of e){const e="function"==typeof t?t(o):o[t];null!=e&&n.add(e+"")}return Array.from(n)}function Lu({data:e,colorBy:t,colorScale:n,showLegend:o,legendPosition:i="right",userMargin:r,defaults:s={top:50,bottom:60,left:70,right:40},categories:a,additionalLegend:l,chartWidth:c,legendLayout:u,hasTitle:d=!1,axisChrome:h}){const f=(0,_u.useContext)(Pu),p=null!==(0,_u.useContext)(ju),g=void 0!==o?o:!f&&!!t,y=!!t&&(g||p),m=(0,Mu.useMemo)(()=>y?void 0!==a?a:Ru(e,t):[],[a,t,e,y]);!function(e){const t=(0,_u.useContext)(ju),n=(0,_u.useId)(),o=function(e){const t=new Set,n=[];for(const o of e)t.has(o)||(t.add(o),n.push(o));return n}(e),i=(0,_u.useRef)([]);(function(e,t){if(e.length!==t.length)return!1;for(let n=0;e.length>n;n++)if(e[n]!==t[n])return!1;return!0})(i.current,o)||(i.current=o);const r=i.current;Cu(()=>{if(t)return()=>t.unregisterCategories(n)},[t,n]),Cu(()=>{t&&t.registerCategories(n,r)},[t,n,r])}(p&&t?m:[]);const x=(0,Mu.useMemo)(()=>{if(!g||!t)return;const o=function({data:e,colorBy:t,colorScale:n,getColor:o,strokeColor:i,strokeWidth:r,categories:s}){return{legendGroups:[{styleFn:e=>{const t=e.color||"#333",n={fill:t,stroke:t};return void 0!==i&&(n.stroke=i),void 0!==r&&(n.strokeWidth=r),n},type:"fill",items:(s&&s.length>0?s:Array.from(new Set(e.map(e=>"function"==typeof t?t(e):e[t])))).map((i,r)=>{const s=e.find("function"==typeof t?e=>t(e)===i:e=>e[t]===i),a=s?o(s,t,n):n?n(i):fe[r%fe.length];return{label:i+"",color:a}}),label:""}]}}({data:e,colorBy:t,colorScale:n,getColor:ye,categories:m});return 0!==o.legendGroups.reduce((e,t)=>e+t.items.length,0)?o:void 0},[g,t,e,n,m]),b=(0,Mu.useMemo)(()=>Ci(x,l),[x,l]),{hasAxis:v,hasAxisLabel:w,rotatedTicks:k}=h??{},S=(0,Mu.useMemo)(()=>{const e="number"==typeof r?{top:r,bottom:r,left:r,right:r}:r??{},t=t=>{const n=e[t];return"number"==typeof n?n:s[t]},n={top:t("top"),right:t("right"),bottom:t("bottom"),left:t("left")},o=t=>"number"==typeof e[t];if(b){const e=Gi(b,u),t=void 0===v?{hasAxis:!0,hasAxisLabel:!0}:{hasAxis:v,hasAxisLabel:w,rotatedTicks:k},r=Hi(b,Math.max(1,(c??600)-n.left-n.right),u)+Ni(b)+Xi("bottom"===i?t:void 0,u)+("top"===i&&d?24:0);"right"===i&&!o("right")&&e>n.right?n.right=e:"left"===i&&!o("left")&&e>n.left?n.left=e:"top"!==i||o("top")?"bottom"!==i||o("bottom")||(n.bottom=Math.max(n.bottom,80,r)):n.top=Math.max(n.top,50,r)}return n},[s,r,b,i,c,u,d,v,w,k]);return{legend:b,margin:S,legendPosition:i}}var Tu=[];function Iu(){const e=wu(),t=e?.colors?.categorical;return t&&t.length>0?t:void 0}function $u(e,t,n,o,i){if(e)return e;if(n&&"object"==typeof n&&!Array.isArray(n)){const e=me(n,o);if(e)return e}let r;if(Array.isArray(n))r=n;else if(t&&t.length>0)r=t;else if("string"==typeof n){const e=ce[n];Array.isArray(e)&&(r=e)}return r&&0!==r.length?null!=o?(i.has(o)||i.set(o,i.size),r[i.get(o)%r.length]):r[0]:de}var Ou=require("react"),zu=require("react");function Du(e){const{data:t,rawData:n,colorBy:o,colorScheme:i,legendInteraction:r,legendPosition:s,selection:a,linkedHover:l,fallbackFields:c,unwrapData:u=!1,onObservation:d,chartType:h,chartId:f,showLegend:p,legend:g,legendLayout:y,userMargin:m,marginDefaults:x,onClick:b,hoverHighlight:v,mobileInteraction:w,mobileSemantics:k,loading:S,loadingContent:A,emptyContent:M,width:_,height:P,hasTitle:C,axisChrome:R}=e,L=void 0===n,T=(0,Ou.useMemo)(()=>z(t),[t]),[I,$]=(0,Ou.useState)([]),O=(0,Ou.useCallback)(e=>{$(t=>t.length===e.length&&t.every((t,n)=>t===e[n])?t:e)},[]),D="string"==typeof o?o:void 0,F=(0,Ou.useMemo)(()=>j(w,{width:_,mobileSemantics:k}),[w,_,k]),{activeSelectionHook:E,hoverSelectionHook:N,customHoverBehavior:B,customClickBehavior:W,crosshairSourceId:Y}=function({selection:e,linkedHover:t,fallbackFields:n=Tu,unwrapData:o=!1,onObservation:i,chartType:r,chartId:s,onClick:a,hoverHighlight:l,colorByField:c,mobileInteraction:u}){const d=(0,cu.useId)(),h=(0,cu.useMemo)(()=>function(e,t){return e?!0===e?{name:"hover",fields:t||[]}:"string"==typeof e?{name:e,fields:t||[]}:{name:e.name||"hover",fields:e.fields||t||[],mode:e.mode,xField:e.xField,seriesField:e.seriesField}:null}(t,n),[t,n]),f=(0,cu.useMemo)(()=>"series"===h?.mode?[h.seriesField||c||n[0]].filter(e=>!!e):h?.fields||n,[h,c,n]),p=bu({name:e?.name||"__unused__",fields:f}),g=function(e){const t=e.name||"hover",{fields:n}=e,{predicate:o,isActive:i,selectPoints:r,clear:s}=bu({name:t,fields:n});return{onHover:(0,fu.useCallback)(e=>{if(!e)return void s();const t={};for(const o of n){const n=e[o];void 0!==n&&(t[o]=[n])}Ye(t)&&r(t)},[n,r,s]),predicate:o,isActive:i}}({name:h?.name||"hover",fields:f}),y=Xr(e=>e.pushObservation),m=(0,cu.useCallback)(e=>{i?.(e),y?.(e)},[i,y]),x=e?{isActive:p.isActive,predicate:p.predicate}:null,[b,v]=(0,cu.useState)(null),w=(0,cu.useRef)(!1),k=c||n[0],S=(0,cu.useMemo)(()=>{if(!l||null==b||!k)return null;const e=b,t=k;return{isActive:!0,predicate:n=>("string"==typeof n[t]?n[t]:(n[t]??"")+"")===e}},[l,b,k]),A=(0,cu.useCallback)((e,n)=>{const o=!e&&w.current&&!!u?.enabled&&u.tapToLockTooltip;if(t)if(e){let t=e.data||e.datum||e;if(Array.isArray(t)&&(t=t[0]),"x-position"===h?.mode&&h.xField){const n=ku(e,t,h.xField);null!=n&&function(e,t,n){const o=js.positions.get(e);o?.locked||o&&o.xValue===t&&o.sourceId===n||(js={positions:new Map(js.positions).set(e,{xValue:t,sourceId:n})},Rs())}(h.name||"hover",n,d)}"x-position"!==h?.mode&&g.onHover(t)}else"x-position"!==h?.mode||o||Ls(h.name||"hover",d),"x-position"===h?.mode||o||g.onHover(null);if(l&&k)if(e){let t=e.data||e.datum||e;Array.isArray(t)&&(t=t[0]);const n=t?.[k];v(null!=n?n+"":null)}else o||v(null);(i||y)&&Bc({onObservation:m,datum:e?Su(e):null,x:e?.x,y:e?.y,chartType:r||"unknown",chartId:s,context:n})},[t,g,h,d,i,r,s,y,m,l,k,u]),M=(0,cu.useCallback)((n=!0)=>{w.current=!1,t&&"x-position"!==h?.mode&&g.onHover(null),e&&u?.tapToSelect&&p.clear(),n&&l&&v(null),"x-position"===h?.mode&&(Ts(h.name||"hover",d),Ls(h.name||"hover",d))},[t,h,g,e,u,p,l,d]),_=(0,cu.useCallback)((n,o)=>{const c=!!u?.enabled&&(u.tapToLockTooltip||u.tapToSelect),x=!!u?.enabled&&"backgroundTap"===u.clearSelection;if("x-position"===h?.mode&&h.xField&&n){let e=n.data||n.datum||n;Array.isArray(e)&&(e=e[0]);const t=ku(n,e,h.xField);null!=t&&function(e,t,n){const o=js.positions.get(e);if(o?.locked){const t=new Map(js.positions);return t.delete(e),js={positions:t},Rs(),!1}js={positions:new Map(js.positions).set(e,{xValue:t,sourceId:n,locked:!0})},Rs()}(h.name||"hover",t,d)}if(c)if(n){w.current=!0;const o=Su(n);if(t&&"x-position"!==h?.mode&&g.onHover(o),e&&u?.tapToSelect&&f.length>0){const e={};for(const t of f){const n=o[t];void 0!==n&&(e[t]=[n])}Au(e)&&p.selectPoints(e)}if(l&&k){const e=o?.[k];v(null!=e?e+"":null)}}else x&&M();if(n||x){if(n&&a){let e=n.data||n.datum||n;Array.isArray(e)&&(e=e[0]),a(e,{x:n.x??0,y:n.y??0})}(i||y)&&Wc({onObservation:m,datum:n?Su(n):null,x:n?.x,y:n?.y,chartType:r||"unknown",chartId:s,context:o})}},[a,i,y,m,r,s,h,d,u,t,g,e,p,f,l,k,M]);return(0,cu.useEffect)(()=>{if(!u?.enabled||"undefined"==typeof document)return;const e=e=>{"Escape"===e.key&&w.current&&M()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[u?.enabled,M]),(0,cu.useEffect)(()=>()=>{w.current&&M(!1)},[M]),(0,cu.useEffect)(()=>{if("x-position"!==h?.mode)return;const e=h.name||"hover";return()=>{Ts(e,d),Ls(e,d)}},[h?.mode,h?.name,d]),{activeSelectionHook:x,hoverSelectionHook:S,customHoverBehavior:A,customClickBehavior:_,crosshairSourceId:d}}({selection:a,linkedHover:l,fallbackFields:c,unwrapData:u,onObservation:d,chartType:h,chartId:f,onClick:b,hoverHighlight:v,colorByField:D,mobileInteraction:F}),q=function(e,t){const n="object"==typeof e&&null!==e?e:void 0;if("x-position"===n?.mode)return{linkedCrosshairName:n.name||"hover",linkedCrosshairSourceId:t}}(l,Y),X=function(e,t,n){const o=hu(),i=Iu();return(0,cu.useMemo)(()=>{if(!t)return;const r=o??void 0,s=n??(i&&i.length>0?i:void 0)??"category10";if(0!==e.length){if("function"==typeof t){const n=Array.from(new Set(e.map(e=>t(e)+"")));if(r&&Au(r)){const e=xe(n.map(e=>({_cat:e})),"_cat",s);return t=>r[t]||e(t)}return xe(n.map(e=>({_cat:e})),"_cat",s)}if(r&&Au(r)){const n=xe(e,t,s);return e=>r[e]||n(e)}return xe(e,t,s)}if(r&&Au(r)){const e=xe([{_:"a"}],"_",s);return t=>r[t]||e(t)}},[e,t,n,o,i])}(T,o,i),H=(0,Ou.useMemo)(()=>Ru(T,o),[T,o]),G=(0,Ou.useMemo)(()=>L&&I.length>0?I:H,[L,I,H]),V=function(e,t,n){const[o,i]=(0,Mu.useState)(null),[r,s]=(0,Mu.useState)(new Set),a=(0,Mu.useMemo)(()=>new Set,[]),l=(0,Mu.useCallback)(t=>{"highlight"===e&&i(t?t.label:null)},[e]),c=(0,Mu.useCallback)(t=>{"isolate"===e&&s(e=>{const o=new Set(e);return o.has(t.label)?o.delete(t.label):o.add(t.label),o.size===n.length?new Set:o})},[e,n.length]),u=(0,Mu.useMemo)(()=>{if(!e||"none"===e||!t)return null;const n="string"==typeof t?t:null;return"highlight"===e&&null!=o?{isActive:!0,predicate:e=>{const i=n?e[n]:"function"==typeof t?t(e):null;return("string"==typeof i?i:(i??"")+"")===o}}:"isolate"===e&&r.size>0?{isActive:!0,predicate:e=>{const o=n?e[n]:"function"==typeof t?t(e):null;return r.has("string"==typeof o?o:(o??"")+"")}}:null},[e,t,o,r]);return{highlightedCategory:"highlight"===e?o:null,isolatedCategories:"isolate"===e?r:a,onLegendHover:l,onLegendClick:c,legendSelectionHook:u}}(r,o,G),U=(0,Ou.useMemo)(()=>N||(V.legendSelectionHook?V.legendSelectionHook:E),[N,V.legendSelectionHook,E]),K=function(e){const t=Qe(e=>e.theme.colors.selectionOpacity);return(0,zu.useMemo)(()=>{if(void 0!==e||void 0!==t)return{name:e?.name??"",...e,unselectedOpacity:e?.unselectedOpacity??t}},[e,t])}(a),Z=Iu(),Q=hu(),J=(0,Ou.useMemo)(()=>{if(X)return X;if(!o||0===G.length)return;const e=Array.isArray(i)&&i.length>0||"string"==typeof i&&i.length>0?i:Z&&Z.length>0?Z:fe,t="__streamCat",n=xe(G.map(e=>({[t]:e})),t,e);return e=>Q?.[e]||n(e)||"#999"},[X,o,G,i,Z,Q]),{legend:ee,margin:te,legendPosition:ne}=Lu({data:T,colorBy:o,colorScale:J,showLegend:p,legendPosition:s,userMargin:m,defaults:x,categories:G,additionalLegend:g,chartWidth:_,legendLayout:y,hasTitle:C,axisChrome:R}),oe=(0,Ou.useMemo)(()=>{const e={};return ee&&(e.legend=ee,e.legendPosition=ne,y&&(e.legendLayout=y)),r&&"none"!==r&&(e.legendHoverBehavior=V.onLegendHover,e.legendClickBehavior=V.onLegendClick,e.legendHighlightedCategory=V.highlightedCategory,e.legendIsolatedCategories=V.isolatedCategories),L&&o&&(e.legendCategoryAccessor=o,e.onCategoriesChange=O),e},[ee,ne,y,r,V.onLegendHover,V.onLegendClick,V.highlightedCategory,V.isolatedCategories,L,o,O]),ie=Array.isArray(n)?z(n):n,re=function(e,t,n,o){if(!e)return null;if(!1===o)return null;if(null!=o)return(0,iu.jsx)("div",{style:{width:t,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:o});const i=Math.min(5,Math.floor(n/40)),r=Math.max(8,Math.floor(n/(3*i))),s=Math.max(6,Math.floor(n/(2.5*i))),a=Math.floor((n-(i*(r+s)-s))/2);return(0,iu.jsx)("div",{style:{width:t,height:n,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:i},(e,n)=>(0,iu.jsx)("div",{className:"semiotic-loading-bar",style:{...au,position:"absolute",top:a+n*(r+s),left:Math.floor(.1*t),width:30+(37*n+13)%50+"%",height:r,opacity:.5+n%2*.2}},n))})}(S,_,P,A),se=re?null:function(e,t,n,o){return!1===o||null==e||Array.isArray(e)&&e.length>0?null:Array.isArray(e)?(0,iu.jsx)("div",{style:{...su,width:t,height:n},children:o||"No data available"}):null}(ie,_,P,M);return{data:T,colorScale:X,allCategories:G,legendState:V,effectiveSelectionHook:U,activeSelectionHook:E,customHoverBehavior:B,customClickBehavior:W,mobileInteraction:F,legend:ee,margin:te,legendPosition:ne,earlyReturn:re||se||null,legendBehaviorProps:oe,crosshairProps:q,resolvedSelection:K}}var Fu=require("react");function Eu(e){const t=(0,lu.useRef)(null);return function(e,t){const{variant:n,frameRef:o,overrides:i}=t,r=(0,Fu.useRef)(i);r.current=i,(0,Fu.useImperativeHandle)(e,()=>{const e=function(e,t){if("xy"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.remove(t)??[],update:(t,n)=>e.current?.update(t,n)??[],replace:t=>e.current?.replace?.(t),clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getScales:()=>e.current?.getScales()??null,getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("network"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>{const n=Array.isArray(t)?t:[t],o=e.current?.getTopology()?.nodes??[],i=[];for(const t of n){const n=o.find(e=>e.id===t);n&&i.push({...n.data??{},id:t}),e.current?.removeNode(t)}return i},update:(t,n)=>(Array.isArray(t)?t:[t]).flatMap(t=>{const o=e.current?.updateNode(t,n);return o?[{...o,id:t}]:[]}),clear:()=>e.current?.clear(),getData:()=>e.current?.getTopology()?.nodes?.map(e=>e.data)??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("geo-points"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.removePoint(t)??[],update:(t,n)=>{const o=e.current?.removePoint(t)??[];for(const t of o)e.current?.push(n(t));return o},clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}const n=t;return{push:e=>n.current?.pushLine(e),pushMany:e=>n.current?.pushManyLines(e),remove:e=>n.current?.removeLine(e)??[],update:(e,t)=>{const o=n.current?.removeLine(e)??[];for(const e of o)n.current?.pushLine(t(e));return o},clear:()=>n.current?.clear(),getData:()=>n.current?.getLines()??[],getCustomLayout:()=>n.current?.getCustomLayout?.()??null,getLayoutFailure:()=>n.current?.getLayoutFailure?.()??null}}(n,o);return new Proxy(e,{get(e,t,n){if("string"==typeof t){const e=r.current?.[t];if("function"==typeof e)return e}return Reflect.get(e,t,n)},has:(e,t)=>!("string"!=typeof t||!r.current||!(t in r.current))||Reflect.has(e,t)})},[])}(e.imperativeRef,{variant:e.imperativeVariant,frameRef:t}),{frameRef:t,resolved:R(e.mode,{width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,xLabel:e.xLabel,yLabel:e.yLabel,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},void 0),normalizedMargin:(0,lu.useMemo)(()=>T(e.margin),[e.margin])}}function Nu(e){const{title:t,description:n,summary:o,accessibleTable:i,className:r,animate:s,maxDevicePixelRatio:a,axisExtent:l,autoPlaceAnnotations:c}=e,u={};return t&&(u.title=t),n&&(u.description=n),o&&(u.summary=o),void 0!==i&&(u.accessibleTable=i),r&&(u.className=r),null!=s&&(u.animate=s),void 0!==a&&(u.maxDevicePixelRatio=a),void 0!==l&&(u.axisExtent=l),void 0!==c&&(u.autoPlaceAnnotations=c),u}function Bu(e){const{linkedHover:t,selection:n,onObservation:o,onClick:i,hoverRadius:r,hoverHighlight:s,forceHoverBehavior:a,forceClickBehavior:l,mobileInteraction:c,customHoverBehavior:u,customClickBehavior:d,linkedHoverInClickPredicate:h=!0}=e,f={};o&&(f.annotationObservationCallback=o);const p=c?.enabled?Math.max(r??30,Math.ceil((c.targetSize||44)/2),24):r;return(a||t||o||i||s)&&(f.customHoverBehavior=u),d&&(l||(h?o||i||t:o||i)||c?.enabled&&(c.tapToSelect||c.tapToLockTooltip)&&(t||s||n))&&(f.customClickBehavior=d),null!=p&&(f.hoverRadius=p),f}var Wu=require("react/jsx-runtime"),Yu=(0,At.forwardRef)(function(e,t){const{data:n,layout:o,layoutConfig:i,onLayoutError:r,xExtent:s,yExtent:a,showAxes:l=!1,margin:c,className:u,annotations:d,onObservation:h,onClick:f,selection:p,linkedHover:g,hoverHighlight:y,chartId:m,loading:x,loadingContent:b,emptyContent:v,colorBy:w,colorScheme:k,legend:S,legendInteraction:A,legendPosition:M,frameProps:_={}}=e,{legend:P,...j}=_,C=(0,At.useMemo)(()=>Ci(P,S),[P,S]),{frameRef:R,resolved:L,safeData:T,setup:I,earlyReturn:$}=function(e){const t=Eu(e),{resolved:n,normalizedMargin:o}=t,i=Du({data:e.data??[],rawData:e.data,colorBy:e.colorBy,colorScheme:e.colorScheme,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,selection:e.selection,linkedHover:e.linkedHover,hoverHighlight:e.hoverHighlight,fallbackFields:"string"==typeof e.colorBy?[e.colorBy]:[],unwrapData:e.unwrapData,onObservation:e.onObservation,onClick:e.onClick,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,chartType:e.chartTypeLabel,chartId:e.chartId,showLegend:n.showLegend,legend:e.legend,userMargin:o,marginDefaults:n.marginDefaults,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,width:n.width,height:n.height});return{...t,safeData:i.data,setup:i,earlyReturn:i.earlyReturn}}({imperativeRef:t,imperativeVariant:"xy",chartTypeLabel:"XYCustomChart",unwrapData:!1,data:n,colorBy:w,colorScheme:k,legend:C,legendInteraction:A,legendPosition:M,selection:p,linkedHover:g,hoverHighlight:y,onObservation:h,onClick:f,chartId:m,loading:x,loadingContent:b,emptyContent:v,margin:c,width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mode:e.mode,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules,xLabel:e.xLabel,yLabel:e.yLabel}),O=I.effectiveSelectionHook,z=(0,At.useMemo)(()=>O?.isActive?{isActive:!0,predicate:O.predicate}:null,[O?.isActive,O?.predicate]);if($)return $;const{width:D,height:F,enableHover:E,showGrid:N,title:B,description:W,summary:Y,accessibleTable:q,xLabel:X,yLabel:H}=L,G={chartType:"custom",...null!=n&&{data:T},customLayout:o,layoutConfig:i,onLayoutError:r,...z&&{layoutSelection:z},xExtent:s,yExtent:a,colorAccessor:w,colorScheme:k,size:[D,F],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:I.margin,showAxes:l,xLabel:X,yLabel:H,enableHover:E,showGrid:N,...I.legendBehaviorProps,...Nu({title:B,description:W,summary:Y,accessibleTable:q,className:u,animate:e.animate,maxDevicePixelRatio:e.maxDevicePixelRatio,axisExtent:e.axisExtent,autoPlaceAnnotations:e.autoPlaceAnnotations}),...null!=e.tooltip&&{tooltipContent:e.tooltip},...Bu({linkedHover:g,selection:p,onObservation:h,onClick:f,hoverRadius:e.hoverRadius,hoverHighlight:y,mobileInteraction:I.mobileInteraction,customHoverBehavior:I.customHoverBehavior,customClickBehavior:I.customClickBehavior}),...d&&d.length>0&&{annotations:d},...I.crosshairProps,...j};return(0,Wu.jsx)(ru,{componentName:"XYCustomChart",width:D,height:F,children:(0,Wu.jsx)(Qc,{ref:R,...G})})});function qu(e,t,n,o,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*n+i*i*i*o}function Xu(e,t,n,o,i){const r=1-i;return 3*r*r*(t-e)+6*r*i*(n-t)+3*i*i*(o-n)}function Hu(e,t,n,o,i){const r=[],s=(e.x+t.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===o?(c=e.x+(t.x-e.x)*l,u=e.y+(t.y-e.y)*l,d=t.x-e.x,h=t.y-e.y):(c=qu(e.x,s,s,t.x,l),u=qu(e.y,e.y,t.y,t.y,l),d=Xu(e.x,s,s,t.x,l),h=Xu(e.y,e.y,t.y,t.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:e.radius+(t.radius-e.radius)*l,datumIndex:.5>l?n:n+1})}return r}function Gu(e,t={}){const n=[],o=[],i=[];if(2>e.length)return{topPath:n,bottomPath:o,datumIndices:i};const r=t.curve??"smooth",s=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;e.length-1>t;t++){const a=Hu(e[t],e[t+1],t,r,s);for(let e=0===t?0:1;a.length>e;e++){const t=a[e],r=Math.hypot(t.dx,t.dy)||1,s=-t.dy/r,l=t.dx/r,c=Math.max(0,t.radius);n.push([t.x+s*c,t.y+l*c]),o.push([t.x-s*c,t.y-l*c]),i.push(t.datumIndex)}}return{topPath:n,bottomPath:o,datumIndices:i}}Yu.displayName="XYCustomChart";var Vu=require("react/jsx-runtime");function Uu(e,t,n){return"function"==typeof e?e(t,n):t[e]}function Ku(e){return e instanceof Date?"date:"+e.getTime():`${typeof e}:${e+""}`}function Zu(e,t){if(!e?.length)return;const n=new Map(t.map((e,t)=>[Ku(e),t]));return e.map(e=>{const t={...e},o=o=>{if(!(o in e))return;const i=n.get(Ku(e[o]));void 0!==i&&(t[o]=i)};return o("x"),o("x0"),o("x1"),"string"!=typeof e.type||"x-threshold"!==e.type&&"x"!==e.type||o("value"),t})}function Qu(e){const{seriesOrder:t,overallOrder:n,highlightTop:o,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=e;if(null==o&&null==i)return r;const c=new Set(n.slice(0,null==o?n.length:Math.max(0,Math.floor(o)))),u=new Map,d={};for(const e of t)d[e]=i??(c.has(e)?$u(void 0,a,r,e,u):s??l??"#b8bec8");return d}function Ju(e,t={}){const n=t.xAccessor??"x",o=t.yAccessor??"y",i=t.lineBy??"series",r=t.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;e.forEach((e,t)=>{const r=Uu(n,e,t),f=Ku(r);let p=a.get(f);null==p&&(p=s.length,a.set(f,p),s.push(r),l.set(p,[]));const g=Uu(i,e,t)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(Uu(o,e,t));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(p)?.push({datum:e,inputIndex:t,series:g,value:y}))});const f=[],p=new Map,g=new Map;for(let e=0;s.length>e;e++){const t=l.get(e)??[];t.sort((e,t)=>("descending"===r?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,n)=>{const o=n+1;f.push({datum:t.datum,xIndex:e,xValue:s[e],series:t.series,value:t.value,rank:o}),p.set(t.series,(p.get(t.series)??0)+o),g.set(t.series,(g.get(t.series)??0)+1)})}const y=c.length+1,m=[...c].sort((e,t)=>{const n=g.get(e)??0,o=g.get(t)??0;return((p.get(e)??0)+(s.length-n)*y)/Math.max(1,s.length)-((p.get(t)??0)+(s.length-o)*y)/Math.max(1,s.length)||(u.get(e)??0)-(u.get(t)??0)}),x=new Set(m.slice(0,null==t.highlightTop?m.length:Math.max(0,Math.floor(t.highlightTop))));return{data:f.map(e=>{const t=x.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}function ed({datum:e,x:t,y:n,side:o,color:i,highlighted:r,labelStyle:s}){const a=xt.useContext(wt)??vt,l=a.isActive&&!a.predicate(e),c="function"==typeof s?s(e.__bumpRaw):s;return(0,Vu.jsx)("text",{className:"semiotic-bump-label",x:t+("end"===o?8:-8),y:n,dy:"0.35em",textAnchor:"end"===o?"start":"end",fill:i,fillOpacity:l?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:e.__bumpSeries})}function td(e,t,n){const[o,i]=t,[r,s]=n;return i===o?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(e-o)/(i-o)))}function nd(e){const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?t:void 0}function od(e){return{value:e.__bumpValue,x:nd(e.__bumpXValue),y:e.__bumpValue,category:e.__bumpSeries}}function id(e){const t=e.config,n=new Map;for(const t of e.data){const e=n.get(t.__bumpSeries)??[];e.push(t),n.set(t.__bumpSeries,e)}const o=t.seriesOrder.filter(e=>n.has(e)).sort((e,o)=>(n.get(e)?.[0]?.__bumpHighlighted?1:0)-(n.get(o)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(o)),i=[],r=[];for(const s of o){const o=(n.get(s)??[]).sort((e,t)=>e.x-t.x);if(2>o.length)continue;const a=o[0].__bumpHighlighted,l=e.resolveColor(o[0].__bumpSeries,o[0]),c=t.color??(a?l:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??l),u=o.map(n=>({x:e.scales.x(n.x),y:e.scales.y(n.y),radius:t.ribbon?td(n.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=Gu(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h=d.datumIndices.map(e=>o[e]),f={fill:c,fillOpacity:1,opacity:a?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(f,Ce(o[0].__bumpRaw,t.styleRules,od(o[0]))),t.areaStyle&&Object.assign(f,t.areaStyle(o[0].__bumpRaw)??{}),void 0!==t.stroke&&(f.stroke=t.stroke),void 0!==t.strokeWidth&&(f.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(f.opacity=t.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:f,datum:h,accessibleDatum:o.map(e=>e.__bumpRaw),accessibility:{label:s+" ranking trajectory",tableFields:o.map(e=>e.__bumpRaw)},group:s,interactive:!0}),t.showPoints&&o.forEach((e,n)=>{const o={fill:c,stroke:"none",opacity:a?1:.75};t.styleRules?.length&&Object.assign(o,Ce(e.__bumpRaw,t.styleRules,od(e))),t.pointStyle&&Object.assign(o,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(o.stroke=t.stroke),void 0!==t.strokeWidth&&(o.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(o.opacity=t.opacity),i.push({type:"point",x:u[n].x,y:u[n].y,r:o.r??t.pointRadius,style:o,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${s}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${s}:${e.x}`})});const p=!0===t.showLabels?"end":t.showLabels,g=(e,n,o)=>{r.push((0,Vu.jsx)(ed,{datum:e,x:u[n].x,y:u[n].y,side:o,color:"string"==typeof f.fill?f.fill:c,highlighted:a,labelStyle:t.labelStyle},`${s}-${o}`))};"start"!==p&&"both"!==p||g(o[0],0,"start"),"end"!==p&&"both"!==p||g(o.at(-1),o.length-1,"end")}return{nodes:i,overlays:r.length?(0,Vu.jsx)("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(e,t)=>{const n=function(e){const t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&n&&!t.predicate(n))return{opacity:.14}}}}function rd(e,t,n,o,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=et(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof t?t:"__ssrAreaColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrAreaColorBy:t(e)})):r,u=t?xe(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=Ae(i.yAccessor),g=i.styleRules;return(e,n)=>{const o=t&&u?ye(e,t,u):"string"==typeof i.color?i.color:de,r={fill:o,fillOpacity:f,stroke:d?o:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,Ce(e,g,{value:p(e),category:n})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function sd(e,t,n,o,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=et(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrBubbleColorBy:t(e)})):r,u=t?xe(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],f=d?r.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?ve(f):void 0;return e=>({fill:t&&u?ye(e,t,u):"string"==typeof i.color?i.color:de,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?be(e,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 ad(e,t,n,o,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=et(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof t?t:"__ssrScatterColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrScatterColorBy:t(e)})):r,u=t?xe(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],f=d?r.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?ve(f):void 0,g=Me(i.xAccessor,i.yAccessor),y=i.styleRules;return e=>{const n={fill:t&&u?ye(e,t,u):"string"==typeof i.color?i.color:de,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?be(e,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(n,Ce(e,y,g(e))),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}}(0,mt.forwardRef)(function(e,t){const n=Iu(),o=wu(),{data:i,xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l="descending",ribbon:c=!1,curve:u="smooth",ribbonSizeRange:d=[4,28],samplesPerSegment:h=12,lineWidth:f=3,highlightTop:p,neutralColor:g,styleRules:y,labelStyle:m,colorScheme:x,ribbonOpacity:b=.82,lineOpacity:v=.9,showPoints:w=!1,pointRadius:k=3,showLabels:S=!0,showAxes:A=!0,showGrid:M=!0,showLegend:_=!1,enableHover:P=!0,hoverHighlight:j=!0,tooltip:C,frameProps:R={},xFormat:L,yFormat:T,onClick:I}=e,$=(0,mt.useMemo)(()=>Ju(i,{xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l,highlightTop:p}),[i,r,s,a,l,p]),{axes:O,areaStyle:z,pointStyle:D,...F}=R,E=(0,mt.useMemo)(()=>Qu({seriesOrder:$.seriesOrder,overallOrder:$.overallOrder,highlightTop:p,color:e.color,colorScheme:x,neutralColor:g,themeCategorical:n,themeNeutral:o.colors.textSecondary}),[$.seriesOrder,$.overallOrder,p,e.color,x,g,n,o.colors.textSecondary]),N=(0,mt.useMemo)(()=>({ribbon:c,curve:u,samplesPerSegment:h,ribbonSizeRange:d,valueExtent:$.valueExtent,seriesOrder:$.seriesOrder,lineWidth:f,ribbonOpacity:b,lineOpacity:v,neutralColor:g,color:e.color,stroke:e.stroke,strokeWidth:e.strokeWidth,opacity:e.opacity,styleRules:y,areaStyle:z,pointStyle:D,labelStyle:m,showPoints:w,pointRadius:k,showLabels:S}),[c,u,h,d,$.valueExtent,$.seriesOrder,f,b,v,g,e.color,e.stroke,e.strokeWidth,e.opacity,y,z,D,m,w,k,S]),B=(0,mt.useCallback)((e,t)=>{if(0===$.xValues.length)return"";const n=$.xValues[Math.max(0,Math.min($.xValues.length-1,Math.round(Number(e))))];return L?L(n,t):(n instanceof Date?n.toLocaleDateString():n)+""},[$.xValues,L]),W=(0,mt.useCallback)(e=>T?T(e):e.toLocaleString(),[T]),Y=(0,mt.useMemo)(()=>"multi"===C?void 0:$l(C),[C]),q=(0,mt.useCallback)(e=>{const t=e?.data??e;return t?!1===C?null:Y?Y({...e,data:t.__bumpRaw,__semioticHoverData:!0}):(0,Vu.jsxs)("div",{className:"semiotic-tooltip",style:Rl,children:[(0,Vu.jsx)("div",{style:{fontWeight:700},children:t.__bumpSeries}),(0,Vu.jsxs)("div",{children:[B(t.x)," · Rank ",t.__bumpRank]}),(0,Vu.jsxs)("div",{children:["Value: ",W(t.__bumpValue)]})]}):null},[W,B,Y,C]),X=(0,mt.useMemo)(()=>{if(I)return(e,t)=>{I(e.__bumpRaw??e,t)}},[I]),H=Math.max(1,$.seriesOrder.length),G=$.xValues.map((e,t)=>t),V=Array.from({length:H},(e,t)=>t+1),U=O??[{orient:"left",tickValues:V,tickFormat:e=>e+"",label:e.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:G,tickFormat:B,label:e.xLabel,tickAnchor:"edges"}],K=(0,mt.useMemo)(()=>Zu(e.annotations,$.xValues),[e.annotations,$.xValues]);return(0,Vu.jsx)(Yu,{ref:t,data:$.data,layout:id,layoutConfig:N,xExtent:[0,Math.max(1,$.xValues.length-1)],yExtent:[H+.5,.5],showAxes:A,showGrid:M,showLegend:_,enableHover:P,hoverHighlight:j,colorBy:"__bumpSeries",colorScheme:E,tooltip:q,onClick:X,hoverRadius:e.hoverRadius,width:e.width,height:e.height,responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,responsiveRules:e.responsiveRules,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,mode:e.mode,margin:e.margin??{top:20,right:S?110:24,bottom:48,left:48},className:e.className,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,selection:e.selection,linkedHover:e.linkedHover,legend:e.legend,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,onObservation:e.onObservation,chartId:e.chartId,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,animate:e.animate,autoPlaceAnnotations:e.autoPlaceAnnotations,annotations:K,xLabel:e.xLabel,yLabel:e.yLabel??"Rank",frameProps:{axes:U,axisExtent:"exact",...F}})}).displayName="BumpChart";var ld={frameType:"xy",buildProps:(e,t,n,o,i)=>({chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:n,...o,pointStyle:o.pointStyle||sd(e,t,n,o,i),showLegend:o.showLegend??!!t})},cd={frameType:"xy",layout:{margin:e=>({top:20,right:!1===e.showLabels?24:110,bottom:48,left:48})},buildProps:(e,t,n,o,i)=>{const r=Ju(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=et(o.theme),l=Qu({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:n,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:o.areaStyle,pointStyle:o.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0},u=o.xFormat,d=(e,t)=>{if(0===r.xValues.length)return"";const n=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(e))))];return u?u(n,t):(n instanceof Date?n.toLocaleDateString():n)+""},h=r.xValues.map((e,t)=>t),f=Array.from({length:s},(e,t)=>t+1),p=o.axes??[{orient:"left",tickValues:f,tickFormat:e=>e+"",label:o.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:o.xLabel,tickAnchor:"edges"}];return{...o,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:id,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:p,axisExtent:"exact",showAxes:o.showAxes??!0,showLegend:o.showLegend??!1,annotations:Zu(o.annotations,r.xValues)}}};function ud(e,t,n,o,i){if(!i.showPoints)return;const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=et(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrPointColorBy:t(e)})):r,u=t?xe(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return e=>{const n=t&&u?ye(e,t,u):"string"==typeof i.color?i.color:de;return{r:d,fill:n,stroke:"none"}}}var dd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=t||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=et(o.theme).colors.categorical,c=function(e,t,n,o,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=et(o.theme).colors.categorical,a=n??o.colorScheme??s,l="string"==typeof t?t:"__ssrLineColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrLineColorBy:t(e)})):r,u=t?xe(c,l,a):void 0,d=Me(i.xAccessor,i.yAccessor),h=function(e){const{lineWidth:t=2,colorBy:n,colorScale:o,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:l,ruleContext:c}=e;return(e,u)=>{const d={strokeWidth:t},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let f;return r?f=r(e,u):n?o&&(f=ye(e,n,o)):f=i||de,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),l?.length&&Object.assign(d,Ce(e,l,c?c(e,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:t,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 Se(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})}(e,r,n,o,i),u=yt({data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:n,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:o.annotations,themeCategorical:l,baseLineStyle:c}),d=o.pointStyle||ud(u.data,u.colorAccessor,n,o,i);let h=o.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const f=(!i.directLabel||void 0!==o.showLegend)&&(o.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:n,lineStyle:u.lineStyle||c,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...o,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!o.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},hd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=Array.isArray(e)?z(e):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=i.valueExtent||o.yExtent,u="down"===i.direction?function({data:e,valueAccessor:t,timeAccessor:n,binSize:o,valueExtent:i,extentPadding:r}){if(i)return[i[1],i[0]];if(!e||0===e.length)return;const s=new Map;for(const i of e){const e=nt(i,n,"time"),r=nt(i,t,"value");if(null==e||null==r)continue;const a=Math.floor(e/o)*o;s.set(a,(s.get(a)??0)+r)}let a=0;for(const e of s.values())a=Math.max(a,e);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:c,extentPadding:i.extentPadding}):c,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.gap&&{gap:i.gap}};return{chartType:"bar",data:r,...o,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||o.xExtent,yExtent:u,extentPadding:i.extentPadding??o.extentPadding,binSize:i.binSize,categoryAccessor:l,barColors:i.colors||o.barColors,colorScheme:i.colors||o.colorScheme,barStyle:o.barStyle||d,showLegend:o.showLegend??!!l}}},fd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=t||i.areaBy,s=function({data:e,safeData:t,areaBy:n,lineDataAccessor:o}){if(null==e)return[];const i=void 0!==t[0]?.[o];if(!i&&!n)return t;let r;if(i)r=t;else{const e=t.reduce((e,t)=>{const i="function"==typeof n?n(t):t[n],r=i+"";if(!e[r]){const t={[o]:[]};"string"==typeof n&&(t[n]=i),e[r]=t}return e[r][o].push(t),e},{});r=Object.values(e)}return r.flatMap(e=>{const t=Array.isArray(e[o])?e[o]:[];return"string"==typeof n?t.map(t=>({...t,[n]:t[n]??e[n]})):t})}({data:e,safeData:Array.isArray(e)?z(e):[],areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),a=function(e){if(e)return Array.isArray(e)?{stops:e.map(({at:e,color:t,opacity:n})=>({offset:e/100,color:t,...null!=n&&{opacity:n}}))}:Array.isArray(e.stops)?e:void 0}(i.semanticGradient),l=a?.stops.length?{stops:a.stops.map(e=>({...e,offset:1-e.offset})).sort((e,t)=>e.offset-t.offset)}:Ie(o.gradientFill),c=!1!==i.semanticLine&&a?.stops.length?a.stops.flatMap(({offset:e,color:t})=>t?[{offset:e,color:t}]:[]):void 0,u=o.pointStyle||ud(s,r,n,o,i);return{chartType:"area",data:s,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:n,...o,...void 0!==l&&{gradientFill:l},...c&&{semanticLineStops:c},lineStyle:o.lineStyle||rd(s,r,n,o,i),...u&&{pointStyle:u}}}},pd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=e=>ze(Oe(r,"x",e)),c=e=>ze(Oe(s,"a",e)),u=e=>ze(Oe(a,"b",e)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",f=i.areaOpacity??.6,p=i.lineWidth??1.5,g=!1!==i.showLines,y=!1!==o.showLegend,m=i.seriesALabel||"A",x=i.seriesBLabel||"B",b=o.legendPosition||"right",v=function(e,t,n,o){if(!e.length)return[];const i=e.filter(e=>Number.isFinite(t(e))).sort((e,n)=>t(e)-t(n)),r=[];let s=0,a=null,l=null,c=[];const u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${s}-${e}`,h=e=>r.push(e),f=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;i.length>e;e++){const r=i[e],p=t(r),g=n(r),y=o(r);if(!Number.isFinite(p)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{const n=g-l.a-(y-l.b);if(0!==n){const o=Math.max(0,Math.min(1,(l.b-l.a)/n));e=l.x+o*(p-l.x),t=l.a+o*(g-l.a)}else e=l.x,t=l.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t}),s++,a=m,h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t});for(let e=1;c.length>e;e++)f(c[e],a)}else for(const e of c)f(e,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else{a=m;for(const e of c)f(e,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else c.push({x:p,y:g,datum:r})}for(const e of c)f(e,a??"A");return r}(Array.isArray(e)?e:[],l,c,u),w=[];if(g&&Array.isArray(e)){const t=e.filter(e=>Number.isFinite(l(e))).sort((e,t)=>l(e)-l(t));for(const e of t){const t=l(e),n=c(e),o=u(e);Number.isFinite(n)&&w.push({__x:t,__y:n,__diffSegment:"line-A"}),Number.isFinite(o)&&w.push({__x:t,__y:o,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:e=>{const t=e.__diffSegment;return{fill:"A"==(t?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:f}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?d:h,strokeWidth:p,fill:"none"}),curve:i.curve||"linear",...o,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},gd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=t||i.areaBy,s="string"==typeof r&&Array.isArray(e)?xe(e,r,n):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=o.lineStyle||(e=>{const t=null==r?void 0:ye(e,r,s),n=i.showLine??!0,o={fill:i.color??t,stroke:n?i.stroke??t:"none",...n?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},l=i.styleRules;if(l?.length){const t=Ae(i.yAccessor),n=r?"function"==typeof r?(r(e)??"")+"":(e[r]??"")+"":void 0;Object.assign(o,Ce(e,l,{value:t(e),category:n}))}return o}),c=i.normalize?"zero":i.baseline??"zero",u=o.pointStyle||ud(e,r,n,o,i);return{chartType:"stackedarea",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:n,normalize:i.normalize,baseline:c,stackOrder:i.stackOrder,lineStyle:l,...o,...u&&{pointStyle:u},curve:o.curve??i.curve??"monotoneX",showLegend:o.showLegend??!!r}}},yd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const[r]=o.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...o,scalePadding:o.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:o.extentPadding??(r>200?.1:.02)}}},md={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=o.pointStyle||ad(e,t,n,o,i),s=function(e,t,n){return e&&0!==e.length?(o,i)=>{const r=Ce(o,e,t(o,i)),s=n?n(o,i):void 0;return s?{...r,...s}:r}:n}(i.styleRules,Me(i.xAccessor||"x",i.yAccessor||"y"),l),a=s?e=>({..."function"==typeof r?r(e):r,...s(e)}):r;var l;return{chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:n,...o,sizeRange:i.sizeRange||[3,15],pointStyle:a,showLegend:o.showLegend??!!t}}},xd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,f=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,p=$.createElement,g=a?[(e,t,n)=>{if(!t?.x||!t?.y)return null;const o=n.width,i=n.height,l=null!=r?t.x(r):o/2,g=null!=s?t.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(o,l)),m=Math.max(0,Math.min(i,g)),x=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:o-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:o-y,h:i-m}],b=c?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:o-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:o-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p($.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?p("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),p("line",{key:"vc",x1:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:o,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:n,pointStyle:o.pointStyle||i.pointStyle||ad(e,t,n,o,i),...o,showLegend:o.showLegend??!!t,...g&&{svgPreRenderers:g}}}},bd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};const n=t.xAccessor||"x",o=t.yAccessor||"y",i=t.orderAccessor?[...e].sort((e,n)=>null==e||"object"!=typeof e?1:null==n||"object"!=typeof n?-1:ze(Oe(t.orderAccessor,"order",e))-ze(Oe(t.orderAccessor,"order",n))):e,r=new WeakMap;let s=0;for(const e of i){if(null==e||"object"!=typeof e)continue;const t=ze(Oe(n,"x",e)),i=ze(Oe(o,"y",e));Number.isFinite(t)&&Number.isFinite(i)&&s++}let a=0;for(const e of i){if(null==e||"object"!=typeof e)continue;const t=ze(Oe(n,"x",e)),i=ze(Oe(o,"y",e));Number.isFinite(t)&&Number.isFinite(i)&&r.set(e,{idx:a++,total:s})}return{data:i,orderMap:r}}(e,i),s=i.pointRadius??4,a=[e=>{const t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(2>t.length)return null;const n=[];for(let e=0;t.length-1>e;e++){const o=t[e],i=t[e+1],r=De(e,t.length);100>t.length&&n.push($.createElement("line",{key:"halo-"+e,x1:o.x,y1:o.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),n.push($.createElement("line",{key:"segment-"+e,x1:o.x,y1:o.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:s,strokeLinecap:"round"}))}return $.createElement($.Fragment,null,...n)}];return{chartType:"scatter",data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,colorScheme:n,pointStyle:Se(e=>{const t=r.orderMap.get(e),n=t?.idx??0,o=t?.total??1;return{fill:o>0?De(n,o):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},Fe(i)),...o,svgPreRenderers:a}}},vd={frameType:"xy",buildProps:(e,t,n,o,i)=>{const r=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1;return{chartType:"heatmap",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,colorScheme:n||i.colorScheme||"blues",showValues:i.showValues,heatmapValueFormat:i.valueFormat,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:r}),...o}}};function wd(e){return Math.max(0,Math.min(1,e))}function kd(e){const t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(n){const e=[Number(n[1]),Number(n[2]),Number(n[3])];if(e.every(Number.isFinite))return e}return null}function Sd(e,t,n){const o=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function Ad(e,t,n){const o=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:wd(e.offset),color:e.color??n,opacity:null==e.opacity?1:wd(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===o.length)return"#999999";const i=e=>{if(1===e.opacity)return e.color;const t=kd(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===o.length)return i(o[0]);const r=wd(t);if(o[0].offset>=r)return i(o[0]);if(r>=o[o.length-1].offset)return i(o[o.length-1]);for(let e=0;o.length-1>e;e++){const t=o[e],n=o[e+1];if(t.offset>r||r>n.offset)continue;const s=n.offset-t.offset,a=s>0?(r-t.offset)/s:0,l=kd(t.color),c=kd(n.color);if(!l||!c)return i(.5>a?t:n);const[u,d,h]=l,[f,p,g]=c,y=u+(f-u)*a,m=d+(p-d)*a,x=h+(g-h)*a,b=t.opacity+(n.opacity-t.opacity)*a;return 1===b?Sd(y,m,x):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(x)},${b})`}return i(o[o.length-1])}function Md(e,t,n){return null==n?`${e}-${t}`:`${e}-${t}-${n}`}var _d=require("react/jsx-runtime");function Pd(e=240){const t=360-e,n=180+t/2,o=n*Math.PI/180;return{sweepRad:e*Math.PI/180,gapDeg:t,startAngleDeg:n,startAngleRad:o,offsetRad:-Math.PI/2+o}}require("react");var jd={RdBu:ne,PiYG:oe,PRGn:ie,BrBG:re,RdYlBu:se,RdYlGn:ae,Spectral:le},Cd="__likert_neutral_neg",Rd="__likert_neutral_pos";function Ld(e,t){if("function"==typeof e)return e;const n=e||t;return e=>e[n]}var Td=g(require("react"));function Id(e){return Ie(e)}function $d(e,t,n,o,i){const r=et(o.theme).colors.categorical,s=n??o.colorScheme,a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],l="string"==typeof t?t:"__ssrColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrColorBy:t(e)})):a,u=t?xe(c,l,s??r):void 0,d=$u("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=Ae(i.valueAccessor),f=i.styleRules,p=o.pieceStyle;return(e,n)=>{const o={fill:t&&u?ye(e,t,u):d};return f?.length&&Object.assign(o,Ce(e,f,{value:h(e),category:n})),"function"==typeof p?Object.assign(o,p(e,n)||{}):p&&"object"==typeof p&&Object.assign(o,p),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}function Od(e,t,n,o,i){const r=$d(e,t,n,o,i);return(e,t)=>{const n=r(e,t);return void 0===n.fillOpacity&&(n.fillOpacity=.8),void 0===n.stroke&&(n.stroke=n.fill),n}}function zd(e,t,n,o,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s="string"==typeof t?t:"__ssrViolinColorBy",a="function"==typeof t?r.map(e=>({...e,__ssrViolinColorBy:t(e)})):r,l=et(o.theme).colors.categorical,c=n??o.colorScheme,u=t?xe(a,s,c??l):void 0,d=$u("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return e=>{const n=t&&u?ye(e,t,u):d;return{fill:n,fillOpacity:.6,stroke:i.stroke??n,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function Dd(e,t,n,o,i){const r=$d(e,t,n,o,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(e,t)=>({r:s,fillOpacity:.8,...r(e,t)})}function Fd(e,t,n,o,i){const r=$d(e,t,n,o,i),s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(e=>"function"==typeof a?a(e):Number(e[a])).filter(Number.isFinite):[],u=c.length?ve(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(e,t)=>({r:a?be(e,a,l,u):d,fillOpacity:h,...r(e,t)})}var Ed={frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"bar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:t,colorScheme:n,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Id(o.gradientFill),pieceStyle:$d(e,t,n,o,i)})},Nd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>{const r=t||i.stackBy;return{chartType:"bar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:n,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Id(o.gradientFill),pieceStyle:$d(e,r,n,o,i),showLegend:o.showLegend??!!r}}},Bd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>{const r=t||i.groupBy;return{chartType:"clusterbar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:n,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Id(o.gradientFill),pieceStyle:$d(e,r,n,o,i),showLegend:o.showLegend??!!r}}},Wd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>{const r=t||i.categoryAccessor;return{chartType:"pie",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:n,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...o,pieceStyle:$d(e,r,n,o,i),showLegend:o.showLegend??!!r}}},Yd={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,n,o,i)=>{const r=t||i.categoryAccessor;return{chartType:"donut",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:o.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:n,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...o,pieceStyle:$d(e,r,n,o,i)}}},qd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>{const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=i.valueAccessor||"value",a=r.map(e=>Number("function"==typeof s?s(e):e[s])).filter(Number.isFinite),l=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:e,oAccessor:i.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:t,colorScheme:n,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:l?{rExtent:l}:{},...o,summaryStyle:Od(e,t,n,o,i)}}},Xd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"boxplot",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:n,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...o,summaryStyle:o.summaryStyle||Od(e,t,n,o,i)})},Hd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"violin",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:n,...o,summaryStyle:o.summaryStyle||zd(e,t,n,o,i),showLegend:o.showLegend??!!t,...i.valueExtent&&{rExtent:i.valueExtent}})},Gd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"swarm",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:n,...o,sizeRange:i.sizeRange||[3,8],pieceStyle:o.pieceStyle||Fd(e,t,n,o,i),showLegend:o.showLegend??!!t})},Vd={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,n,o,i)=>({chartType:"point",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...o,pieceStyle:Dd(e,t,n,o,i),showGrid:o.showGrid??!0,showLegend:o.showLegend??!!t})},Ud={frameType:"ordinal",buildProps:(e,t,n,o,i)=>{const r=t||i.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...o,gradientFill:Id(o.gradientFill),pieceStyle:o.pieceStyle||$d(e,r,n,o,i),showLegend:o.showLegend??!!r,barPadding:i.barPadding??40}}},Kd={frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"ridgeline",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:n,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...o,summaryStyle:o.summaryStyle||((r,s)=>({fillOpacity:.5,...$d(e,t,n,o,i)(r,s)})),showLegend:o.showLegend??!!t})},Zd={frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,n,o,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(e,t,n,o,i,r){const s=new Map,a=new Set(t);for(const l of e){const e=n(l);s.has(e)||s.set(e,new Map);const c=s.get(e);if(o){const e=o(l);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}const n=e-1;if(0>n||n>=t.length)continue;const i=t[n];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const e=i(l),t=r(l);if(!a.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}const l=[];for(const[e,n]of s){let o=0;for(const e of t)o+=n.get(e)||0;if(0!==o)for(let i=0;t.length>i;i++){const r=t[i],s=n.get(r)||0;l.push({__likertCategory:e,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/o*100,__likertLevelIndex:i})}}return l}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],r,Ld(i.categoryAccessor,"question"),i.levelAccessor?null:Ld(i.valueAccessor,"score"),i.levelAccessor?Ld(i.levelAccessor,"level"):null,i.levelAccessor?Ld(i.countAccessor,"count"):null);s&&(a=function(e,t){const n=t.length,o=n%2!=0,i=Math.floor(n/2),r=new Map;for(const t of e){const e=r.get(t.__likertCategory)||[];e.push(t),r.set(t.__likertCategory,e)}const s=[];for(const[,e]of r){const t=new Map;let r,a;for(const n of e)n.__likertLevel===Cd?r=n:n.__likertLevel===Rd?a=n:t.set(n.__likertLevelIndex,n);o&&r&&s.push(r);for(let e=i-1;e>=0;e--){const n=t.get(e);n&&s.push(n)}o&&a&&s.push(a);for(let e=o?i+1:i;n>e;e++){const n=t.get(e);n&&s.push(n)}}return s}(function(e,t){const n=t.length,o=n%2!=0,i=Math.floor(n/2),r=[];for(const t of e){const e=t.__likertLevelIndex;if(o&&e===i){const e=t.__likertPct/2;r.push({...t,__likertLevel:Cd,__likertPct:-e}),r.push({...t,__likertLevel:Rd,__likertPct:e})}else r.push(i>e?{...t,__likertPct:-t.__likertPct}:t)}return r}(a,r),r));const l=et(o.theme).colors.diverging,c=Array.isArray(n)&&n.length>=r.length?n:function(e,t){if(0>=e)return[];if(t){const n=jd[t];if(n){if(1===e)return[n(.5)];const t=[];for(let o=0;e>o;o++)t.push(n(o/(e-1)));return t}}const n=["#da1e28","#ff8389","#ffb3b8"],o=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===e)return[i];const r=e%2!=0,s=Math.floor(e/2),a=[];for(let e=0;s>e;e++)a.push(n[Math.min(Math.floor(e*n.length/s),n.length-1)]);r&&a.push(i);for(let e=0;s>e;e++)a.push(o[Math.min(Math.floor(e*o.length/s),o.length-1)]);return a}(r.length,l),u=new Map(r.map((e,t)=>[e,c[t]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",f=Ci(!1===o.showLegend?void 0:{legendGroups:[{label:"",items:r.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},o.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:o.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...o,pieceStyle:Se(e=>{const t=e.__likertLevel||e.data?.__likertLevel;return{fill:t===Cd||t===Rd?d:u.get((e.__likertLevelLabel||e.data?.__likertLevelLabel||t)+"")||"#888"}},Fe(i)),showLegend:o.showLegend??!0,legendPosition:o.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},Qd={frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,n,o,i)=>{const r="vertical"===i.orientation,s=t||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:e,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:n,...o,showAxes:r,showGrid:r,pieceStyle:$d(e,s,n,o,i),showLabels:i.showLabels??!0}}},Jd={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){const n=e.__gauge;if(!n)return null;const o=(n.startAngleDeg+(n.gMax===n.gMin?0:(Math.max(n.gMin,Math.min(n.gMax,n.value??n.gMin))-n.gMin)/(n.gMax-n.gMin))*n.sweep-90)*Math.PI/180,i=n.needleColor||t.colors.text,r=n.showScaleLabels?(n.thresholds||[]).filter(e=>e.value>n.gMin&&n.gMax>e.value):[];return(0,_d.jsxs)(_d.Fragment,{children:[n.showNeedle&&(0,_d.jsxs)(_d.Fragment,{children:[(0,_d.jsx)("line",{x1:n.centerX,y1:n.centerY,x2:n.centerX+n.needleLength*Math.cos(o),y2:n.centerY+n.needleLength*Math.sin(o),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),(0,_d.jsx)("circle",{cx:n.centerX,cy:n.centerY,r:4,fill:i})]}),null!=n.contextValue&&(0,_d.jsx)("text",{x:n.centerX,y:n.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:n.valueFontSize,fontWeight:700,fill:i,children:n.contextValue}),r.map((e,o)=>{const i=(n.startAngleDeg+(n.gMax===n.gMin?0:(e.value-n.gMin)/(n.gMax-n.gMin))*n.sweep-90)*Math.PI/180,r=n.innerRadius-1,s=n.radius+1,a=n.radius+10,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return(0,_d.jsxs)("g",{children:[(0,_d.jsx)("line",{x1:n.centerX+Math.cos(i)*r,y1:n.centerY+Math.sin(i)*r,x2:n.centerX+Math.cos(i)*s,y2:n.centerY+Math.sin(i)*s,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),(0,_d.jsx)("text",{x:n.centerX+Math.cos(i)*a,y:n.centerY+Math.sin(i)*a,textAnchor:c,dominantBaseline:u,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+o)})]})},buildProps:(e,t,n,o,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=Pd(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=$e(o.gradientFill),p=function(e){const{min:t,max:n,value:o,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=e,d=n-t||1,h=(Math.max(t,Math.min(n,o))-t)/d;let f=i&&i.length>0?[...i].sort((e,t)=>e.value-t.value):[{value:n,color:r||"#007bff"}];f=f.map(e=>({...e,value:Math.max(t,Math.min(n,e.value))})),n>f[f.length-1].value&&f.push({value:n,color:f[f.length-1].color});const p=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(p){const e=a?h:1,t=Md("bg",0);if(g.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(t,{fill:s,opacity:.4}),e>0){const t=Math.max(1,Math.floor(u)),n=Math.max(1,Math.min(t,Math.round(e*t))),o=[];for(let t=0;n>t;t++)o.push(Ad(c.stops,e*(t+.5)/n,r||f[0]?.color||"#007bff"));const i=Md("fill",0);g.push({category:i,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:o}}),y.set(i,{fill:o[0]||s})}}else{let e=t;for(let n=0;f.length>n;n++){const o=f[n],i=(o.value-e)/d,r=(e-t)/d,l=(o.value-t)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const e=Md("fill",n);g.push({category:e,value:c,_zone:o.label||"Zone "+(n+1),_isFill:!0}),y.set(e,{fill:o.color})}if(u>0){const e=Md("bg",n);g.push({category:e,value:u,_zone:o.label||"Zone "+(n+1),_isFill:!1}),y.set(e,{fill:s,opacity:.4})}e=o.value}}if(l&&i&&i.length>0)for(const e of i)e.value>t&&n>e.value&&m.push({type:"gauge-label",value:e.value,label:e.label||e.value+""});return{gaugeData:g,pieceStyle:(e,t)=>y.get(t||e.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:f}),[g,y]=o.size||[300,250],m=function(e=240){const{sweepRad:t,offsetRad:n}=Pd(e),o=[[Math.cos(n),Math.sin(n)],[Math.cos(n+t),Math.sin(n+t)],[0,0]];for(let e=0;2*Math.PI>e;e+=Math.PI/2)((e-n)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>t+.001||o.push([Math.cos(e),Math.sin(e)]);const i=o.map(e=>e[0]),r=o.map(e=>e[1]),[s,a]=ve(i),[l,c]=ve(r);return{minX:s,maxX:a,minY:l,maxY:c,width:a-s,height:c-l,cx:(s+a)/2,cy:(l+c)/2}}(a),x=Math.min(10,Math.max(1,Math.min(g,y)/12)),b=Math.max(4,Math.min((g-2*x)/m.width,(y-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-l))),w=g/2-m.cx*b,k=y/2-m.cy*b,S=2*(b+4),A=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(A):Math.round(A)+"",_=i.centerContent??o.centerContent,P=null!=_?"function"==typeof _?_(A,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:Td.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Td.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&Td.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:Se(p.pieceStyle,Fe(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...o,size:[g,y],margin:{top:k-S/2,bottom:y-k-S/2,left:w-S/2,right:g-w-S/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(o.annotations)?o.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:A,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}},eh=require("d3-scale"),th={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function nh(e="static"){return th[e]??th.static}var oh=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function ih(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:oh.has(e.kind)?"fatal":"warn"}function rh(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function sh(e){const{desired:t,minGaps:n,weights:o}=e,i=t.length;if(0===i)return[];if(n.length!==Math.max(0,i-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const r=Array(i).fill(0);for(let e=1;i>e;e++)r[e]=r[e-1]+Math.max(0,Number.isFinite(n[e-1])?n[e-1]:0);const s=[];for(let e=0;i>e;e++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[e])?o[e]:1),i=(Number.isFinite(t[e])?t[e]:0)-r[e];for(s.push({start:e,end:e,weight:n,mean:i});s.length>1;){const e=s[s.length-1],t=s[s.length-2];if(e.mean>=t.mean)break;const n=t.weight+e.weight;s.splice(s.length-2,2,{start:t.start,end:e.end,weight:n,mean:(t.mean*t.weight+e.mean*e.weight)/n})}}const a=Number.isFinite(e.min)?e.min:-1/0,l=Number.isFinite(e.max)?e.max-r[i-1]:1/0,c=a>l?a:l,u=Array(i);for(const e of s){const t=Math.max(a,Math.min(c,e.mean));for(let n=e.start;e.end>=n;n++)u[n]=t+r[n]}return u}function ah(e,t){let n=0,o=e.length-1,i=-1;for(;o>=n;){const r=n+o>>>1;e[r].at>t?o=r-1:(i=r,n=r+1)}return 0>i?{at:t,before:0,after:0}:e[i]}function lh(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let i=0;e.length-1>i;i++){const r=e[i],s=e[i+1],a=[...new Set([...r.map(e=>e.at),...s.map(e=>e.at)])].sort((e,t)=>e-t);let l=0;for(const e of a){const t=ah(r,e),n=ah(s,e);l=Math.max(l,t.after+n.before)}n.push(l),o.push(o[o.length-1]+l+t)}return{adjacentClearance:n,positions:o}}function ch(e,t,n,o={}){let i=[...e];if(1>=i.length)return i;let r=[...i],s=n(i),a=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let e=0;l>e&&c>a;e++){const e=new Map(i.map((e,t)=>[e,t])),l=new Map,c=new Map;for(const n of t){const t=e.get(n.source),o=e.get(n.target);if(null==t||null==o)continue;const i=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*i),c.set(n.source,(c.get(n.source)??0)+i),l.set(n.target,(l.get(n.target)??0)+t*i),c.set(n.target,(c.get(n.target)??0)+i)}i=i.map((e,t)=>({item:e,index:t,barycenter:(l.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(o.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);const u=n(i);if(a++,s>u)s=u,r=[...i];else if(u===s)break}return r}function uh(e,t,n={}){const o=[...e],i=o.length;if(1>=i||i>(n.maxItems??8))return o;const r=Math.max(1,n.maxEvaluations??1/0);let s=0,a=[...o],l=1/0;const c=()=>{if(s>=r)return;const e=t(o);s++,l>e&&(l=e,a=[...o])};c();const u=Array(i).fill(0);let d=0;for(;i>d&&r>s;)if(d>u[d]){const e=d%2==0?0:u[d];[o[e],o[d]]=[o[d],o[e]],c(),u[d]++,d=0}else u[d]=0,d++;return a}function dh(e,t){return t>e?-1:e>t?1:0}function hh(e){return e.occupants.map(e=>e.id).sort(dh).join("\0")}function fh(e,t,n=0){return e.slice(0,-1).map((o,i)=>null!=o.group&&o.group===e[i+1].group?n:t)}function ph(e,t){return e.map(e=>{const n=new Map;for(const o of e.occupants){const e=t[o.id];if(e)for(const t of e.samples){const e=n.get(t.t)??{before:0,after:0},o=t.boundaryOffset??0;n.set(t.t,{before:Math.max(e.before,t.topMass-o),after:Math.max(e.after,t.botMass+o)})}}return[...n].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function gh(e,t,n){if(0===e.length)return[];const{padding:o,plotH:i,valueScale:r}=n,s=n.stackValueScale??r,a=fh(e,o,n.groupPadding??0),l=[o+e[0].peak.topPeak*s];for(let n=1;e.length>n;n++)l.push(l[n-1]+t[n-1]*s+a[n-1]);const c=l[l.length-1]+e[e.length-1].peak.botPeak*s+o;if(c>i&&c>0){const e=i/c;for(let t=0;l.length>t;t++)l[t]*=e}return l}function yh(e,t){const n=(e.boundaryOffset??0)*t,o=e.value*t;if("out"===e.kind){const i=e.sideMassBefore*t;return n+("top"===e.side?o/2-i:i-o/2)}const i=e.sideMassAfter*t;return n+("top"===e.side?o/2-i:i-o/2)}function mh(e,t,n,o,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:lh(ph(o,n)).adjacentClearance,a=gh(o,s,r);let l="hug"===r.lanePlacement?function(e,t,n,o,i,r,s){const a=e.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=fh(e,l,s.groupPadding??0),h=i.map((e,t)=>e*u+d[t]),f=l+e[0].peak.topPeak*u,p=c-l-e[a-1].peak.botPeak*u;if(h.reduce((e,t)=>e+t,0)+1e-6>=p-f)return gh(e,i,s);let g=1===a?[(f+p)/2]:[...r];for(let e=0;12>e;e++){const e=Array(a).fill(0),i=Array(a).fill(0);for(const r of n){const n=t[r.source],s=t[r.target];if(null==n||null==s||n===s)continue;const a=o[r.source]?.localAttachments.get(r.id),l=o[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=yh(a,u),h=yh(l,u);e[n]+=(g[s]+h-d)*c,i[n]+=c,e[s]+=(g[n]+d-h)*c,i[s]+=c}const r=sh({desired:g.map((t,n)=>0===i[n]?t:.45*t+e[n]/i[n]*.55),minGaps:h,weights:i.map(e=>Math.max(1,e)),min:f,max:p});let s=0;for(let e=0;a>e;e++)s=Math.max(s,Math.abs(r[e]-g[e]));if(g=r,.01>s)break}return g}(o,i,t,n,s,a,r):[...a];if("hug"===r.lanePlacement){const n=t=>{const n={};for(const o of e)n[o.id]=t[i[o.id]];return n};xh(n(l),t)>xh(n(a),t)+1e-6&&(l=[...a])}const c={};for(const t of e)c[t.id]=l[i[t.id]];let u=1/0,d=-1/0;for(const t of e){const e=c[t.id],o=n[t.id];Number.isFinite(e)&&o&&(u=Math.min(u,e-o.topPeak*r.valueScale),d=Math.max(d,e+o.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function xh(e,t){let n=0;for(const o of t){const t=e[o.source],i=e[o.target];Number.isFinite(t)&&Number.isFinite(i)&&(n+=Math.abs(t-i)*(o.value>0?o.value:1))}return n}function bh(e,t){const n=e?.samples;if(!n||0===n.length||n[0].t>t)return{top:0,bot:0};let o=0,i=n.length-1,r=0;for(;i>=o;){const e=o+i>>>1;n[e].t>t?i=e-1:(r=e,o=e+1)}const s=n[r].boundaryOffset??0;return{top:n[r].topMass-s,bot:n[r].botMass+s}}function vh(e,t,n,o,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*n+i*i*i*o}function wh(e,t){let n=0,o=1;for(let i=0;28>i;i++){const i=(n+o)/2;e>vh(0,t,t,1,i)?n=i:o=i}return(n+o)/2}function kh(e,t,n){const o=t+yh(e,n),i=e.value*n/2;return[o-i,o+i]}function Sh(e,t,n,o){return Math.max(0,Math.min(t,o)-Math.max(e,n))/Math.max(1e-9,t-e)}function Ah(e,t,n,o,i,r,s){const{valueScale:a,domain:l,mode:c="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of e){const e=o[s.source],h=o[s.target];if(null==e||null==h||2>Math.abs(e-h))continue;const f=t[s.source]?.localAttachments.get(s.id),p=t[s.target]?.localAttachments.get(s.id);if(!f||!p)continue;const g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,x]=kh(f,i[s.source],a),[b,v]=kh(p,i[s.target],a),w=Math.min(e,h)+1,k=Math.max(e,h)-1;for(let e=w;k>=e;e++){const o=n[e];if(!o)continue;const l=[g,y];if("quality"===c)for(const e of o.occupants)for(const n of t[e.id]?.samples??[])n.t>g&&y>n.t&&l.push(n.t);const h=e=>{const n=wh((e-g)/(y-g),u),l=vh(m,m,b,b,n),c=vh(x,x,v,v,n);let d=0;for(const n of o.occupants){if(n.id===s.source||n.id===s.target)continue;const o=r[n.id];if(null!=o?.start&&o.start>e)continue;if(null!=o?.end&&e>o.end)continue;const u=bh(t[n.id],e),h=i[n.id];d=Math.max(d,Sh(l,c,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(l)].sort((e,t)=>e-t);let p=0;for(let e=0;f.length-1>e;e++){const t=f[e],n=f[e+1]-t;p+=(h(t+.25*n)+h(t+.5*n)+h(t+.75*n))/3*n}d+=p/(y-g)*(s.value>0?s.value:1)}}return d}function Mh(e,t,n,o,i,r,s,a,l,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:xh(s,n),transitOcclusion:Ah(n,o,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function _h(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Ph(e,t){return e.map(e=>({t:_h(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function jh(e,t,n){const o=t+(e.boundaryOffset??0)*n,i=e.value*n;if("out"===e.kind){const t=e.sideMassBefore*n;if("top"===e.side){const e=o-t;return[e,e+i]}const r=o+t;return[r-i,r]}const r=e.sideMassAfter*n;if("top"===e.side){const e=o-r;return[e,e+i]}const s=o+r;return[s-i,s]}function Ch(e,t,n,o,i="temporal"){const r=t.incoming[e.id],s=t.outgoing[e.id],a=[];for(const e of r)a.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:n.get(e.id).targetSide});for(const e of s)a.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:n.get(e.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(l[e.kind]??99)-(l[t.kind]??99)||((e,t)=>{if(!o||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;const n=o.get(e.edge.id)?.target,i=o.get(t.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof i&&Number.isFinite(i)&&n!==i?"top"===e.side?n-i:i-n:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;const n=o.get(e.edge.id)?.source,i=o.get(t.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof i&&Number.isFinite(i)&&n!==i?"top"===e.side?i-n:n-i:0}return 0})(e,t)||dh(e.edge?.id??"",t.edge?.id??"")||dh(e.side,t.side)||e.delta-t.delta)},u=a.length?function(e,t=1/0){let n=t;for(const t of e)n>t&&(n=t);return n}(a.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let f=null,p=0;for(const e of a)e.time!==f&&(f=e.time,p=0),e.sequence=p++;const g=e=>({time:e.time,phase:0,sequence:e.sequence??0}),y=[];let m=0,x=0;for(const e of a)if("out"===e.kind){const t=Math.abs(e.delta);let n=t-("top"===e.side?m:x);if(n>0){const t="top"===e.side?"bot":"top",o=Math.min(n,"top"===t?m:x);if(o>0){const i=g(e);y.push({...i,delta:-o,kind:"transfer-out",side:t}),y.push({...i,delta:+o,kind:"transfer-in",side:e.side}),"top"===t?m-=o:x-=o,"top"===e.side?m+=o:x+=o,n-=o}n>0&&null!==h&&(y.push({time:h,delta:+n,kind:"create",side:e.side}),"top"===e.side?m+=n:x+=n)}"top"===e.side?m-=t:x-=t}else if("in"===e.kind){const t=Math.abs(e.delta);"top"===e.side?m+=t:x+=t}a.push(...y),c();let b=0,v=0,w=0,k=0,S=0,A=0;const M=[],_=new Map,P=e=>{M.push({t:e,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},j=()=>{k=Math.max(k,b+v),S=Math.max(S,b-w),A=Math.max(A,v+w)};for(const e of a){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&P(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){const t="top"===e.side?b:v;_.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===e.side?b+=e.delta:v+=e.delta,"transfer-in"===e.kind?(w+="top"===e.side?e.delta:-e.delta,j(),P(e.time)):"transfer-out"!==e.kind&&(j(),"out"!==e.kind||b+v>1e-12||(w=0),P(e.time))}const C=[];let R=0;for(;M.length>R;){let e=R;for(;M.length>e+1&&M[e+1].t===M[R].t;)e++;C.push(M[R]);for(let t=R+1;e>=t;t++){const e=C[C.length-1];M[t].topMass===e.topMass&&M[t].botMass===e.botMass&&(M[t].boundaryOffset??0)===(e.boundaryOffset??0)||C.push(M[t])}R=e+1}const L=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null;let T=null;for(const e of s)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===T||T>e.systemInTime)&&(T=e.systemInTime);let I=null;for(const e of r)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===I||e.systemOutTime>I)&&(I=e.systemOutTime);if(C.length>0){const e=C[C.length-1],t=Math.max(null!=L?L:-1/0,null!=I?I:-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&C.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});const n=C[0],o=C.find(e=>e.topMass+e.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&n.t>d&&n.topMass+n.botMass>0&&(r=d,i=n),o&&null!=T&&Number.isFinite(T)&&o.t>T&&r>T&&(r=T,i=o),i&&Number.isFinite(r)&&C.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let $=C;if("max"===i&&null!=d&&null!=L&&L>d){let e,t=0;for(const n of C){const o=n.topMass+n.botMass;o>t&&(t=o,e=n)}if(e){const t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};$=[...C.filter(e=>d>e.t),{t:d,...t},{t:L,...t},...C.filter(e=>e.t>L)]}}return{samples:$,peak:k,topPeak:S,botPeak:A,localAttachments:_}}function Rh(e){const t={};return e.forEach((e,n)=>{for(const o of e.occupants)t[o.id]=n}),t}function Lh(e,t,n){e.splice(0,e.length,...n);const o=Rh(n);for(const e of Object.keys(t))delete t[e];Object.assign(t,o)}function Th(e){const t=new Map,n=[];e.forEach((e,o)=>{if(!e.group)return void n.push({anchor:o,stableId:hh(e),slots:[e]});const i=t.get(e.group)??{indexes:[],slots:[]};i.indexes.push(o),i.slots.push(e),t.set(e.group,i)});for(const[e,o]of t)n.push({anchor:o.indexes.reduce((e,t)=>e+t,0)/o.indexes.length,stableId:`${e}\0${o.slots.map(hh).join("\0")}`,slots:o.slots});return n.sort((e,t)=>e.anchor-t.anchor||dh(e.stableId,t.stableId))}function Ih(e){return e.some(e=>e.group)?Th(e).flatMap(e=>e.slots):[...e]}function $h(e){return e.flatMap(e=>e.slots)}function Oh(e,t,n){const o=new Map;return e.forEach((e,t)=>{for(const n of e.slots)o.set(n,t)}),e.map((e,i)=>{if(1>=e.slots.length)return e;const r=new Map;for(const t of e.slots)r.set(t,0);for(const e of t){const t=o.get(e.source),n=o.get(e.target);if(null==t||null==n)continue;const s=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===i&&n!==i){const t=n>i?1:-1;r.set(e.source,(r.get(e.source)??0)+s*t)}else if(n===i&&t!==i){const n=t>i?1:-1;r.set(e.target,(r.get(e.target)??0)+s*n)}}const s=[...e.slots].sort((e,t)=>(r.get(e)??0)-(r.get(t)??0)||n(e,t));return{...e,slots:s}})}function zh(e,t){e.some(e=>e.group)&&Lh(e,t,Ih(e))}function Dh(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.min(e.endTime,t.endTime)>Math.max(e.startTime,t.startTime)}function Fh(e,t){return function(e,t,n=()=>!0){let o=0;for(let i=0;e.length>i;i++){const[r,s]=t(e[i]);for(let a=i+1;e.length>a;a++){if(!n(e[i],e[a]))continue;const[l,c]=t(e[a]);0>(r-l)*(s-c)&&o++}}return o}(t,t=>[e[t.source],e[t.target]],Dh)}function Eh(e,t){let n=0;for(const o of t){const t=e[o.source],i=e[o.target];null!=t&&null!=i&&(n+=Math.abs(t-i)*(o.value>0?o.value:1))}return n}function Nh(e,t,n){const[o,i]=n.get(e.first),[r,s]=n.get(e.second);return 0>(t.get(o)-t.get(r))*(t.get(i)-t.get(s))?1:0}var Bh=e=>{let t=1;for(let n=2;e>=n;n++)t*=n;return t},Wh=828*Bh(8),Yh=3e3;function qh(e,t,n,o,i,r,s){const a=[...i],l=new Map(i.map(e=>[e,hh(e)])),c=new Map;for(const e of i)for(const t of e.occupants)c.set(t.id,e);const u=new Map,d=[];for(const e of t){const t=c.get(e.source),n=c.get(e.target);t&&n&&(u.set(e,[t,n]),t!==n&&d.push({source:t,target:n,weight:e.value}))}const h=[];for(let e=0;t.length>e;e++)if(u.has(t[e]))for(let n=e+1;t.length>n;n++){if(!u.has(t[n])||!Dh(t[e],t[n]))continue;const o=new Set([...u.get(t[e]),...u.get(t[n])]);h.push({index:h.length,first:t[e],second:t[n],involvedSlots:o})}const f=new Map;for(const e of i)f.set(e,[]);for(const e of h)for(const t of e.involvedSlots)f.get(t)?.push(e);const p=new Uint32Array(h.length);let g=0;const y=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),m=s.plotH/Math.max(1,i.length),x=i.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),b=Math.max(1,y)*(Math.max(1,s.plotH)+m*Math.max(x,i.length)+1e-6*Math.max(1,i.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,S=(e,t)=>{let o=k.get(e);o||(o=new Map,k.set(e,o));const i=o.get(t);if(null!=i)return i;const r=function(e,t,n){return lh(ph([e,t],n)).adjacentClearance[0]??0}(e,t,n);return o.set(t,r),r},A=new Map(i.map((e,t)=>[e,t])),M=t.flatMap(e=>{const t=u.get(e);return t?[{source:A.get(t[0]),target:A.get(t[1]),weight:e.value>0?e.value:1}]:[]}),_=new Map;for(const e of t){const t=u.get(e);t&&_.set(e,{source:A.get(t[0]),target:A.get(t[1])})}const P=new Map,j=new Map;for(const e of t)P.has(e.source)||P.set(e.source,new Set),j.has(e.target)||j.set(e.target,new Set),P.get(e.source).add(e.target),j.get(e.target).add(e.source);const C=t.flatMap(e=>{if(!(e=>{const t=new Set([...P.get(e.source)??[],...j.get(e.source)??[]]),n=new Set([...P.get(e.target)??[],...j.get(e.target)??[]]);return 1===P.get(e.source)?.size&&P.get(e.source).has(e.target)||1===t.size&&t.has(e.target)||1===n.size&&n.has(e.source)})(e))return[];const t=_.get(e);return t&&t.source!==t.target?[{source:t.source,target:t.target,weight:e.value>0?e.value:1}]:[]}),R=e=>{let t=0;for(const n of C)t+=Math.max(0,Math.abs(e[n.source]-e[n.target])-1)*n.weight;return t*v},L=e=>{const t=new Int16Array(i.length);for(let n=0;e.length>n;n++)t[A.get(e[n])]=n;return R(t)},T=h.map(e=>{const t=_.get(e.first),n=_.get(e.second);return[t.source,t.target,n.source,n.target]}),I=new Int16Array(i.length),$=new Float64Array(i.length),O=new Float64Array(i.length+1),z=e=>{for(let t=0;e.length>t;t++)I[A.get(e[t])]=t;let t=0;for(const[e,n,o,i]of T)0>(I[e]-I[o])*(I[n]-I[i])&&t++;if(e.length>0){const t=A.get(e[0]);$[t]=s.padding+e[0].peak.topPeak*s.valueScale;for(let t=1;e.length>t;t++){const n=A.get(e[t-1]),o=A.get(e[t]);$[o]=$[n]+S(e[t-1],e[t])*s.valueScale+s.padding}const n=A.get(e[e.length-1]),o=$[n]+e[e.length-1].peak.botPeak*s.valueScale+s.padding;if(o>s.plotH&&o>0){const e=s.plotH/o;for(let t=0;$.length>t;t++)$[t]*=e}}O[0]=0;for(let t=0;e.length>t;t++)O[t+1]=O[t]+e[t].peak.topPeak+e[t].peak.botPeak;let n=0,o=0,i=0;for(const e of M){const t=I[e.source],r=I[e.target];if(n+=Math.abs(t-r)*e.weight,o+=Math.abs($[e.source]-$[e.target])*e.weight,Math.abs(t-r)>=2){const n=Math.min(t,r)+1;i+=(O[Math.max(t,r)]-O[n])*e.weight}}return t*b+o+i*m+R(I)+1e-6*n},D=(e,n)=>{const o=Array(e.length+1).fill(0);for(let t=0;e.length>t;t++)o[t+1]=o[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0;for(const e of t){const t=n[e.source],r=n[e.target];if(null==t||null==r||2>Math.abs(t-r))continue;const s=Math.min(t,r)+1;i+=(o[Math.max(t,r)]-o[s])*(e.value>0?e.value:1)}return i},F=o=>{const i=Rh(o),r=o.slice(0,-1).map((e,t)=>S(e,o[t+1])),a=mh(e,t,n,o,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:Eh(i,t),pixelLength:xh(a.centerlines,t),transitOcclusion:D(o,i)}},E=(e,t,n)=>({crossings:e,weightedLength:t.weightedLength,pixelLength:t.pixelLength,transitOcclusion:t.transitOcclusion,cost:e*b+t.pixelLength+t.transitOcclusion*m+L(n)+1e-6*t.weightedLength}),N=(e,t)=>{let n=t;if(null==n){const t=new Map(e.map((e,t)=>[e,t]));n=h.reduce((e,n)=>e+Nh(n,t,u),0),w.fullCrossing++}return E(n,F(e),e)},B=(e,i,r="quality")=>{let a=i;if(null==a){const t=new Map(e.map((e,t)=>[e,t]));a=h.reduce((e,n)=>e+Nh(n,t,u),0),w.fullCrossing++}const l=F(e);return E(a,{...l,transitOcclusion:Ah(t,n,e,l.map,l.geometry.centerlines,o,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},e)};let W=[...a];const Y=(e,t)=>dh(l.get(e),l.get(t)),q=function(e){const t=new Set;for(const n of e)if(n.group){if(t.has(n.group))return!0;t.add(n.group)}return!1}(W),X=e=>{const t=(e=>{const t=ch(e,d,e=>N(e).cost,{passes:6,compare:Y,maxEvaluations:Yh});let n=N(t),o=Yh;for(let e=0;6>e&&o>0;e++){let i=!1;const r=Array.from({length:t.length-1},(e,t)=>t);e%2==1&&r.reverse();for(const e of r){if(0>=o--)break;const r=t[e],s=t[e+1],a=new Map(t.map((e,t)=>[e,t]));let l=0;const c=[];g++;for(const e of[...f.get(r)??[],...f.get(s)??[]])p[e.index]!==g&&(p[e.index]=g,c.push(e),l+=Nh(e,a,u));[t[e],t[e+1]]=[s,r];const d=new Map(a);d.set(r,e+1),d.set(s,e);let h=0;for(const e of c)h+=Nh(e,d,u);w.localCrossing+=c.length;const y=N(t,n.crossings-l+h);n.cost>y.cost?(n=y,i=!0):[t[e],t[e+1]]=[r,s]}if(!i)break}return t})(e);if((e.length>8?1/0:Bh(e.length)*(e.length+M.length+T.length))>Wh)return t;const n=uh(e,z,{maxItems:8,maxEvaluations:5e4}),o=B(n),i=B(t);return o.crossings!==i.crossings&&i.crossings>o.crossings?n:t},H="geometry-refine"===s.mode;if(H||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!H&&"inside-out"===s.laneOrder)if(q){const e=Th(W),t=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),n=[...e].sort((e,n)=>t(n)-t(e)||dh(e.stableId,n.stableId)),o=Array(n.length);let i=Math.floor((n.length-1)/2)-1,r=Math.floor((n.length-1)/2)+1;n.length>0&&(o[Math.floor((n.length-1)/2)]=n[0]);for(let e=1;n.length>e;e++)e%2==1&&n.length>r||0>i?o[r++]=n[e]:o[i--]=n[e];W=$h(o)}else{const e=[...W].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t)),t=Array(e.length);let n=Math.floor((e.length-1)/2)-1,o=Math.floor((e.length-1)/2)+1;e.length>0&&(t[Math.floor((e.length-1)/2)]=e[0]);for(let i=1;e.length>i;i++)i%2==1&&e.length>o||0>n?t[o++]=e[i]:t[n--]=e[i];W=t}}else W=q?(e=>{let t=Th(e);if(1>=t.length)return $h(t);const n=e=>N($h(e)).cost;t=Th(X(e)),t=Oh(t,d,Y);const o=function(e,t){const n=new Map;for(const t of e)for(const e of t.slots)n.set(e,t);const o=new Map;for(const e of t){const t=n.get(e.source),i=n.get(e.target);if(!t||!i||t===i)continue;const r=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,s=i.stableId>t.stableId?`${t.stableId}\0${i.stableId}`:`${i.stableId}\0${t.stableId}`,a=o.get(s);a?a.weight=(a.weight??0)+r:o.set(s,{source:t,target:i,weight:r})}return[...o.values()]}(t,d);t=ch(t,o,n,{passes:6,compare:(e,t)=>dh(e.stableId,t.stableId),maxEvaluations:Yh}),t=function(e,t,n={}){const o=[...e];if(1>=o.length)return o;let i=t(o),r=1;const s=Math.max(0,n.passes??6),a=Math.max(1,n.maxEvaluations??1/0);for(let e=0;s>e&&a>r;e++){let e=!1;for(let n=0;o.length-1>n&&a>r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const s=t(o);r++,i>s?(i=s,e=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!e)break}return o}(t,n,{passes:8,maxEvaluations:Yh});const i=t.length>8?1/0:Bh(t.length)*(t.length+M.length+T.length);if(Wh>=i){const e=uh(t,e=>z($h(e)),{maxItems:8,maxEvaluations:5e4}),n=$h(e),o=$h(t),i=B(n),r=B(o);i.crossings!==r.crossings?t=r.crossings>i.crossings?e:t:r.cost>i.cost&&(t=e)}return t=Oh(t,d,Y),$h(t)})(W):X(W);if(!H&&"crossing-min+inside-out"===s.laneOrder&&W.length>1)if(q){const e=Th(W);let t=N($h(e)),n=$h(e),o=t;const i=Math.floor((e.length-1)/2),r=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),s=[...e].sort((e,t)=>r(t)-r(e)||dh(e.stableId,t.stableId));for(const r of s){const s=e.indexOf(r);if(s===i)continue;e.splice(s,1),e.splice(i,0,r);const a=$h(e),l=N(a);l.cost>t.cost?(e.splice(i,1),e.splice(s,0,r)):(t=l,o.cost>l.cost&&(n=a,o=l))}W=n}else{let e=N(W),t=[...W],n=e;const o=Math.floor((W.length-1)/2),i=[...W].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||Y(e,t));for(const r of i){const i=W.indexOf(r);if(i===o)continue;W.splice(i,1),W.splice(o,0,r);const s=N(W);s.cost>e.cost?(W.splice(o,1),W.splice(i,0,r)):(e=s,n.cost>s.cost&&(t=[...W],n=s))}W=t}if((H||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&W.length>1)if(q){let e=Th(W),t=B($h(e),void 0,"score");for(let n=0;6>n&&e.length>1;n++){let n=!1;for(let o=0;e.length-1>o;o++){[e[o],e[o+1]]=[e[o+1],e[o]];const i=$h(e),r=B(i,void 0,"score");t.cost>r.cost?(W=i,t=r,n=!0):[e[o],e[o+1]]=[e[o+1],e[o]]}if(!n)break}e=Oh(Th(W),d,Y),W=$h(e)}else{let e=B(W,void 0,"score");for(let t=0;W.length-1>t;t++){const n=W[t],o=W[t+1],i=new Map(W.map((e,t)=>[e,t]));let r=0;const s=[];g++;for(const e of[...f.get(n)??[],...f.get(o)??[]])p[e.index]!==g&&(p[e.index]=g,s.push(e),r+=Nh(e,i,u));[W[t],W[t+1]]=[o,n];const a=new Map(i);a.set(n,t+1),a.set(o,t);let l=0;for(const e of s)l+=Nh(e,a,u);w.localCrossing+=s.length;const c=B(W,e.crossings-r+l,"score");e.cost>c.cost?e=c:[W[t],W[t+1]]=[n,o]}}const G=Ih(a);W=Ih(W);let V=B(W);const U=B(G);if(H){const e=L(G),t=L(W);(V.crossings>U.crossings||V.crossings===U.crossings&&t>e+1e-9||V.cost>U.cost)&&(W=G,V=U)}else V.cost>U.cost&&(W=G,V=U);return Lh(i,r,W),{before:U,after:V,initialOrder:a.map(e=>l.get(e)),evaluations:w}}function Xh(e,t,n){const o=e.map(e=>{const o=e.occupants.map(e=>({id:e.id,end:n[e.id]?.end??e.end}));let i=0,r=0;for(const e of o){const n=t[e.id];i=Math.max(i,n?.topPeak||0),r=Math.max(r,n?.botPeak||0)}return{occupants:o,peak:{topPeak:i,botPeak:r},...null!=e.group?{group:e.group}:{}}}),i={};return o.forEach((e,t)=>{for(const n of e.occupants)i[n.id]=t}),{slots:o,slotByNode:i}}var Hh=new Map,Gh=1e-9,Vh=1e5;function Uh(e,t){let n=1/0,o=-1/0;for(const t of e?.samples??[])t.topMass+t.botMass>Gh&&(n=Math.min(n,t.t),o=Math.max(o,t.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=t.start&&(n=Math.max(n,t.start)),null!=t.end&&(o=Math.min(o,t.end)),n>o?{start:null,end:null}:{start:n,end:o}):{start:null,end:null}}function Kh(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(t.start>=e.end||e.start>=t.end)}function Zh(e,t){return dh(e,t)>0?`${t}\0${e}`:`${e}\0${t}`}function Qh(e){const t=new Map,n=new Map;for(const o of e)n.has(o.source)||n.set(o.source,new Set),t.has(o.target)||t.set(o.target,new Set),n.get(o.source).add(o.target),t.get(o.target).add(o.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...n].map(([e,t])=>[e,t.size]))}}function Jh(e){const t=new Map,n=new Map,o=(e,t,n,o)=>{let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,(i.get(n)??0)+o)};for(const i of e){const e=i.value>0&&Number.isFinite(i.value)?i.value:1;o(t,i.source,i.target,e),o(n,i.target,i.source,e)}const i=new Map,r=e=>{if(i.has(e))return;const o=t.get(e),r=n.get(e);if(o&&1===o.size&&(!r||0===r.size)){const[t,n]=[...o][0];return void i.set(e,{partner:t,weight:n})}const s=new Map;for(const[e,t]of o??[])s.set(e,(s.get(e)??0)+t);for(const[e,t]of r??[])s.set(e,(s.get(e)??0)+t);if(1===s.size){const[t,n]=[...s][0];i.set(e,{partner:t,weight:n})}};for(const t of e)r(t.source),r(t.target);return i}function ef(e,t,n){const o=n.get(e),i=n.get(t);return!o||!i||o.partner===i.partner||o.partner===t||i.partner===e}function tf(e,t,n){return!!n.has(e)&&t.some(t=>!ef(e,t,n))}function nf(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function of(e,t,n,o){if(12>=e.length||1>=o.slotCount)return o.assignment;const i=new Map(e.map((e,t)=>[e,t])),r=Array.from({length:e.length},()=>new Map),s=Qh(n);for(const e of n){const t=i.get(e.source),n=i.get(e.target);if(null==t||null==n||t===n)continue;const o=nf(e,s);r[t].set(n,(r[t].get(n)??0)+o),r[n].set(t,(r[n].get(t)??0)+o)}const a=Jh(n),l=e.map(e=>a.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map);let u=0;for(let n=0;e.length-1>n&&5e4>u;n++)if(a.has(e[n]))for(let o=n+1;e.length>o;o++){if(!a.has(e[o]))continue;if(t.conflicts(e[n],e[o]))continue;u++;const i=Math.min(l[n],l[o])||Math.max(l[n],l[o]),r=ef(e[n],e[o],a)?i:-i;if(Math.abs(r)>Gh&&(c[n].set(o,r),c[o].set(n,r),u>=5e4))break}const d=[...o.assignment],h=Array.from({length:o.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));const f=(e,t,n)=>{const o=d[t],i=d[n];let r=0;const s=new Set;for(const a of[t,n])for(const[l,c]of e[a]){const e=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(e))continue;s.add(e);const u=(a===t?i:o)===(l===t?i:l===n?o:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},p=(e,t,n)=>{let o=0;for(const[i,r]of e[t]){const e=n===d[i];d[t]===d[i]!==e&&(o+=e?r:-r)}return o},g=(e,t)=>e>Gh||Gh>=Math.abs(e)&&t>Gh,y=(e,t,n,o)=>e>n+Gh||Gh>=Math.abs(e-n)&&t>o+Gh;let m=0;for(let n=0;32>n&&Vh>m;n++){let n=null,o=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;e.length>u;u++){for(let f=0;h.length>f&&m++<Vh;f++){if(f===d[u])continue;if(!h[f].every(n=>!t.conflicts(e[u],e[n])))continue;const m=p(r,u,f),x=p(c,u,f);g(m,x)&&y(m,x,a,l)&&(n="move",o=u,i=-1,s=f,a=m,l=x)}if(m>=Vh)break}for(let u=0;e.length-1>u;u++){for(let p=u+1;e.length>p&&m++<Vh;p++){const m=d[u],x=d[p];if(m===x)continue;if(!h[x].every(n=>n===p||!t.conflicts(e[u],e[n])))continue;if(!h[m].every(n=>n===u||!t.conflicts(e[p],e[n])))continue;const b=f(r,u,p),v=f(c,u,p);g(b,v)&&y(b,v,a,l)&&(n="swap",o=u,i=p,s=-1,a=b,l=v)}if(m>=Vh)break}if(null==n||-1===o)break;if("move"===n){const e=d[o];h[e].splice(h[e].indexOf(o),1),h[s].push(o),d[o]=s;continue}const u=d[o],x=d[i];h[u].splice(h[u].indexOf(o),1,i),h[x].splice(h[x].indexOf(i),1,o),d[o]=x,d[i]=u}return d}function rf(e,t,n,o){const i=function(e,t,n,o){return`${e.map(e=>{const t=n[e.id],i=o[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,n,o),r=Hh.get(i);if(r)return Xh(r.slots,n,o);const s={};for(const t of e)s[t.id]=Uh(n[t.id],o[t.id]);const a=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,n)=>t[e.id].start-t[n.id].start||t[e.id].end-t[n.id].end||dh(e.id,n.id)).map(e=>e.id)}(e,s),l=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=function(e,t,n,o,i){const r=new Set,s=new Map(e.map(e=>[e,new Set])),a=new Map(e.map(e=>[e,new Set]));for(const e of o)r.add(Zh(e.source,e.target)),s.get(e.target)?.add(e.source),a.get(e.source)?.add(e.target);const l=new Map,c=new Set,u=(e,t)=>{for(let n=0;e.length>n;n++)for(let o=n+1;e.length>o;o++){const i=Zh(e[n],e[o]);t instanceof Map?t.set(i,[e[n],e[o]]):t.add(i)}};for(const e of a.values())u([...e],l);for(const e of s.values())u([...e],c);const d=new Set;for(const[e,[o,i]]of l)c.has(e)&&(Kh(t[o],t[i])||Kh(n[o],n[i])&&(d.add(o),d.add(i)));return{conflicts:(e,n)=>{const o=i.get(e),s=i.get(n);return null!=o&&null!=s&&o!==s||null!=o!=(null!=s)&&!r.has(Zh(e,n))||!!Kh(t[e],t[n])||!(!d.has(e)&&!d.has(n))&&!r.has(Zh(e,n))}}}(a,s,o,t,c),d=function(e,t,n=new Map){const o=[],i=[];for(const r of e){let e=o.findIndex(e=>e.every(e=>!t.conflicts(r,e))&&!tf(r,e,n));-1!==e||n.has(r)||(e=o.findIndex(e=>e.every(e=>!t.conflicts(r,e)))),-1===e&&(e=o.length,o.push([])),o[e].push(r),i.push(e)}return{assignment:i,slotCount:o.length}}(a,u,Jh(t)),h=function(e,t,n,o){if(0===e.length||e.length>12||1>=o.slotCount)return o.assignment;const i=new Map(e.map((e,t)=>[e,t])),r=Array.from({length:e.length},()=>new Float64Array(e.length)),s=Array.from({length:e.length},()=>new Map),a=Array.from({length:e.length},()=>new Map),l=Qh(n);for(const e of n){const t=i.get(e.source),n=i.get(e.target);if(null==t||null==n||t===n)continue;const o=nf(e,l);r[t][n]+=o,r[n][t]+=o,a[t].set(n,(a[t].get(n)??0)+o),s[n].set(t,(s[n].get(t)??0)+o)}const c=Jh(n),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;e.length>t;t++)for(let n=t+1;e.length>n;n++){for(const[e,o]of s[t])d[t][n]+=Math.min(o,s[n].get(e)??0);for(const[e,o]of a[t])d[t][n]+=Math.min(o,a[n].get(e)??0);if(c.has(e[t])&&c.has(e[n])){const o=Math.min(u[t],u[n])||Math.max(u[t],u[n]);d[t][n]+=ef(e[t],e[n],c)?o:-o}d[n][t]=d[t][n]}let h=[...o.assignment],f=(t=>{let n=0,o=0;for(let i=0;e.length>i;i++)for(let s=i+1;e.length>s;s++)t[i]===t[s]&&(n+=r[i][s],o+=d[i][s]);return{flow:n,affinity:o}})(h),p=0;const g=Array(e.length).fill(-1),y=Array.from({length:o.slotCount},()=>[]),m=(n,i,s,a)=>{if(p>=75e3)return;if(n===e.length)return p++,void((s>f.flow||s===f.flow&&a>f.affinity||s===f.flow&&a===f.affinity&&function(e,t){for(let n=0;Math.min(e.length,t.length)>n;n++)if(e[n]!==t[n])return t[n]>e[n];return t.length>e.length}(g,h))&&(h=[...g],f={flow:s,affinity:a}));const l=Math.min(i+1,o.slotCount-1);for(let o=0;l>=o;o++){if(y[o].some(o=>t.conflicts(e[n],e[o])))continue;let l=0,c=0;for(const e of y[o])l+=r[n][e],c+=d[n][e];if(g[n]=o,y[o].push(n),m(n+1,Math.max(i,o),s+l,a+c),y[o].pop(),g[n]=-1,p>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,u,t,{...d,assignment:of(a,u,t,d)}),f=new Map,p=h.map(e=>(f.has(e)||f.set(e,f.size),f.get(e))),g=Array.from({length:f.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y={};a.forEach((e,t)=>{const n=p[t],o=g[n];o.occupants.push({id:e,end:s[e].end??-1/0});const i=l.get(e)?.group;i&&(o.group=i),y[e]=n});for(const t of[...e].sort((e,t)=>dh(e.id,t.id)))null==y[t.id]&&(g[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(const e of g){e.occupants.sort((e,t)=>(s[e.id].start??1/0)-(s[t.id].start??1/0)||dh(e.id,t.id));for(const t of e.occupants){const o=n[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,o?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,o?.botPeak||0)}}const m={slots:g,slotByNode:y};return function(e,t){for(Hh.has(e)&&Hh.delete(e),Hh.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:{...t.slotByNode}});Hh.size>12;){const e=Hh.keys().next().value;if(null==e)break;Hh.delete(e)}}(i,m),m}function sf(e){return e.topMass+e.botMass}function af(e,t){const n=e.samples.filter(e=>e.t===t);if(n.length>0)return n.reduce((e,t)=>sf(t)<sf(e)?e:t,n[0]);let o=null;for(const n of e.samples){if(n.t>t)break;o=n}return o}function lf(e,t,n,o,i,r,s=0){const a=new Map;for(const n of e){if(!n.group||!t[n.id])continue;const e=a.get(n.group)??[];e.push(n),a.set(n.group,e)}if(0===a.size||0>=r)return t;const l=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]));for(const[e,c]of a){const a=n.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],f=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;const p=(h-u.peak.topPeak*r+(f+d.peak.botPeak*r))/2,g=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),y=new Map;for(const e of c)y.set(e.id,new Map);for(const e of g){const n=new Map;for(const i of c){const r=af(t[i.id],e);if(!r||1e-9>=sf(r))continue;const s=o[i.id];if(null==s)continue;const a=n.get(s)??[];a.push({node:i,sample:r}),n.set(s,a)}const a=[...n].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>sf(e)))}));if(0===a.length)continue;let l=p-(a.reduce((e,t)=>e+t.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const t of a){for(const{node:n,sample:o}of t.active){const t=(l-i[n.id])/r+o.topMass-(o.boundaryOffset??0);y.get(n.id).set(e,t)}l+=t.mass*r+Math.max(0,s)}}for(const e of c){const n=t[e.id],o=l[e.id],i=y.get(e.id),r=[];for(const e of g){const t=i.get(e),o=n.samples.filter(t=>t.t===e);if(o.length>0){r.push(...o.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}})));continue}const s=af(n,e);null!=t&&s&&sf(s)>1e-9&&r.push({...s,t:e,boundaryOffset:(s.boundaryOffset??0)+t})}o.samples=r,o.localAttachments=new Map([...n.localAttachments].map(([e,t])=>{const n=i.get(t.time);return[e,{...t,...null!=n?{boundaryOffset:(t.boundaryOffset??0)+n}:{}}]}))}}return l}function cf(e,t,n,o,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=i,g={},y={};for(const t of e)g[t.id]=n[t.id].topPeak||0,y[t.id]=n[t.id].botPeak||0;const m="half"===u,x={};for(const t of e){const e=Array.isArray(t.xExtent)?t.xExtent[0]:null,n=Array.isArray(t.xExtent)?t.xExtent[1]:null;let i=null!=e&&Number.isFinite(e)?e:1/0,r=null!=n&&Number.isFinite(n)?n:-1/0;for(const e of o.outgoing[t.id]){i>e.startTime&&(i=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&i>e.systemInTime&&(i=e.systemInTime);const t=m?(e.startTime+e.endTime)/2:e.endTime;t>r&&(r=t)}for(const e of o.incoming[t.id]){const t=m?(e.startTime+e.endTime)/2:e.startTime;i>t&&(i=t),e.endTime>r&&(r=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>r&&(r=e.systemOutTime)}x[t.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let b={},v=[],w=[];if(i.frozenSlots){const e=Xh(i.frozenSlots,n,x);v=e.slots,b=e.slotByNode,w=v.map(hh)}else if("reuse"===l){const o=rf(e,t,n,x);v=o.slots,b=o.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:x[e.id]?.end??-1/0}],peak:{topPeak:g[e.id],botPeak:y[e.id]},...e.group?{group:e.group}:{}}),b[e.id]=t});zh(v,b),0===w.length&&(w=v.map(hh));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(e,t,n){const o=new Map(n.map((e,t)=>[e,t]));Lh(e,t,[...e].sort((e,t)=>(o.get(hh(e))??1/0)-(o.get(hh(t))??1/0)||dh(hh(e),hh(t))))}(v,b,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=qh(e,t,n,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:f,domain:p}))),zh(v,b);const S=mh(e,t,n,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,j=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(hh),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:j}}function uf(e){const{sx:t,sTop:n,sBot:o,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=e,c=(n+o)/2,u=(r+s)/2;return{pathD:[`M${t},${n}`,`C${a},${n} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${o} ${t},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(o-n)/2}}}function df(e,t,n,o,i,r,s,a,l={}){const c=i,u=e=>a?Math.max(a[0],Math.min(a[1],e)):e;let d=r(u(e.time));const h=r(u(n.time)),f=e.value*c,p=n.value*c,g=t+(e.boundaryOffset??0)*c,y=o+(n.boundaryOffset??0)*c,m=e.sideMassBefore*c,x=n.sideMassAfter*c;let b,v,w,k;"top"===e.side?(b=g-m,v=b+f):(v=g+m,b=v-f),"top"===n.side?(w=y-x,k=w+p):(k=y+x,w=k-p);const S=l.sourceRunwayStart,A=l.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof S&&Number.isFinite(S),j="number"==typeof A&&Number.isFinite(A)&&A>0;if(P&&M>1e-9&&_>0&&("auto"===A||j)){const t="source"===s?.85:"target"===s?.15:.5,n="auto"===A?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(t*t,(1-t)*(1-t))))):A;if(n>_){const t=r(u(Math.min(S,e.time)));Number.isFinite(t)&&(d=Math.min(d,Math.max(Math.min(d,t),h-n)))}}const C="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:C,cp2X:C}}function hf(e){return Math.max(18,11*e.length*.58)}function ff(e){const t=1.22*hf(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function pf(e,t){const n=e.labelX-hf(e.labelText),o=t.labelX-hf(t.labelText);return t.labelX+3>=n&&e.labelX+3>=o}var gf=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function yf(e){return e.replace(gf,(e,t,n)=>`${n},${t}`)}function mf(e){if(!e)return;const t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function xf(e){return{...e,pathD:yf(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function bf(e){const{nodes:t,edges:n,domain:o,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:g="raw",styleRules:y,colorBy:m,valueAccessor:x,usageMode:b="static"}=e,v="vertical"===d?r:i,w="vertical"===d?i:r,k=function(e,t,n,o={}){const i=nh(o.usageMode??"static"),r=[],s=new Set;for(const t of e)s.has(t.id)&&r.push({kind:"duplicate-node",id:t.id,severity:i.duplicateIds}),s.add(t.id);const a=new Set,l=Array.isArray(n)&&2===n.length,c=l&&Number.isFinite(n[0])&&Number.isFinite(n[1]);l&&c&&c&&n[1]>=n[0]||r.push({kind:"invalid-domain"});for(const t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||r.push({kind:"invalid-node-time",id:t.id}));for(const e of t)a.has(e.id)&&r.push({kind:"duplicate-edge",id:e.id,severity:i.duplicateIds}),a.add(e.id),s.has(e.source)||r.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),s.has(e.target)||r.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&r.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),Number.isFinite(e.value)&&e.value>0||r.push({kind:"invalid-value",id:e.id}),e.startTime>e.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):r.push({kind:"invalid-edge-time",id:e.id});return r}(t,n,o,{usageMode:b}),{fatal:S,warnings:A}=function(e){const t=[],n=[];for(const o of e)"fatal"===ih(o)?t.push(o):n.push(o);return{fatal:t,warnings:n}}(k),M=function(e,t,n="static"){if("strip"!==nh(n).invalidSystemTime)return e;const o=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===o.size?e:e.map(e=>{if(!o.has(e.id))return e;const t={...e};return null==t.systemInTime||Number.isFinite(t.systemInTime)||delete t.systemInTime,null==t.systemOutTime||Number.isFinite(t.systemOutTime)||delete t.systemOutTime,t})}(n,k,b),_=(0,eh.scaleTime)().domain(o).range([0,v]);if(S.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:_};const P=function(e,t,n){const{plotH:o,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=n,p=Number.isFinite(d)?Math.max(0,d):0,g=function(e,t){const n={},o={};for(const t of e)n[t.id]=[],o[t.id]=[];for(const e of t)o[e.source]&&o[e.source].push(e),n[e.target]&&n[e.target].push(e);return{incoming:n,outgoing:o}}(e,t),y=function(e,t,n,o="temporal"){const i="temporal"===o?(e,t)=>e.endTime-t.endTime||dh(e.id,t.id):(e,t)=>t.value-e.value||dh(e.id,t.id),r="temporal"===o?(e,t)=>e.startTime-t.startTime||dh(e.id,t.id):(e,t)=>t.value-e.value||dh(e.id,t.id),s=new Map;for(const e of t)s.set(e.id,{});const a=(e,t)=>{const n=new Map;for(const o of e){const e=o[t];n.has(e)||n.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=n.get(e);i.edges.push(o),i.total+=o.value,i.earliestStart=Math.min(i.earliestStart,o.startTime),i.latestEnd=Math.max(i.latestEnd,o.endTime)}const s=[...n.values()];s.sort("temporal"===o?(e,n)=>"target"===t?e.earliestStart-n.earliestStart||dh(e.partner,n.partner):e.latestEnd-n.latestEnd||dh(e.partner,n.partner):(e,t)=>t.total-e.total||dh(e.partner,t.partner));for(const e of s)e.edges.sort("target"===t?r:i);return s};for(const t of e){const e=n.outgoing[t.id],o=n.incoming[t.id];if(0===o.length)a(e,"target").forEach((e,t)=>{const n=t%2==0?"top":"bot";for(const t of e.edges)s.get(t.id).sourceSide=n});else if(0===e.length)a(o,"source").forEach((e,t)=>{const n=t%2==0?"top":"bot";for(const t of e.edges)s.get(t.id).targetSide=n});else{const t=a(o,"source"),n=a(e,"target"),i=Math.max(t.length,n.length);for(let e=0;i>e;e++){const o=e%2==0?"top":"bot";if(t[e])for(const n of t[e].edges)s.get(n.id).targetSide=o;if(n[e])for(const t of n[e].edges)s.get(t.id).sourceSide=o}}}return s}(e,t,g,i);let m={};for(const t of e)m[t.id]=Ch(t,g,y,void 0,u);const x=cf(e,t,m,g,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=new Set;for(const e of t){const t=x.slotByNode[e.source],n=x.slotByNode[e.target];if(void 0===t||void 0===n)continue;const o=y.get(e.id);t!==n?t>n?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(v.add(e.id),o.sourceSide="bot",o.targetSide="bot")}for(const t of e){const e=g.outgoing[t.id],n=g.incoming[t.id],o=new Set(e.map(e=>y.get(e.id).sourceSide)),i=new Set(n.map(e=>y.get(e.id).targetSide));if(1===o.size&&n.length>0){const e=[...o][0];for(const t of n)x.slotByNode[t.source]===x.slotByNode[t.target]&&(y.get(t.id).targetSide=e)}if(1===i.size&&e.length>0){const t=[...i][0];for(const n of e)x.slotByNode[n.source]===x.slotByNode[n.target]&&(y.get(n.id).sourceSide=t)}}!function(e,t,n){const o=new Map,i=[];for(const t of e)i.push({time:t.startTime,kind:"out",edge:t}),i.push({time:t.endTime,kind:"in",edge:t});i.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||dh(e.edge.id,t.edge.id));const r=e=>{let t=o.get(e);return t||(t={top:0,bot:0},o.set(e,t)),t},s=(e,t,n)=>{const o="top"===t?"bot":"top",i=Math.min(n,e[t]);e[t]-=i;const r=n-i;r>0&&(e[o]=Math.max(0,e[o]-r))};for(const e of i){const{edge:o}=e;if("in"===e.kind){const e=t.get(o.id)?.targetSide??"bot";r(o.target)[e]+=o.value;continue}const i=r(o.source),a=t.get(o.id);let l=a.sourceSide??"bot";if(n[o.source]===n[o.target]){const e=i.top>=o.value,t=i.bot>=o.value;e!==t?l=e?"top":"bot":e||t||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,o.value)}}(t,y,x.slotByNode),function(e,t,n,o){for(const i of e){const e=t.incoming[i.id],r=t.outgoing[i.id];if(0===e.length||0===r.length)continue;const s=()=>{const t={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of e)"top"===n.get(o.id).targetSide?t.inTop+=o.value:t.inBot+=o.value;for(const e of r)"top"===n.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},a=(e,t)=>{const i=s(),a="top"===e?i.outTop-i.inTop:i.outBot-i.inBot,l="top"===t?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(t=>!o.has(t.id)&&n.get(t.id).sourceSide===e&&c>=t.value).sort((e,t)=>t.value-e.value||dh(e.id,t.id));return 0!==u.length&&(n.get(u[0].id).sourceSide=t,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(e,g,y,v),m={};for(const t of e)m[t.id]=Ch(t,g,y,void 0,u);const w=cf(e,t,m,g,{plotH:o,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((e,t,n)=>e+(null!=t.group&&t.group===w.slots[n+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*o-S*p)/A),_=2*M+fh(w.slots,M,p).reduce((e,t)=>e+t,0),P=k>0?Math.max(0,(o-_)/k):1,j=Number.isFinite(l)&&l>0?Math.min(P,l):P;let C=cf(e,t,m,g,{plotH:o,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&C.slots.length>1&&(qh(e,t,m,C.laneLifetime,C.slots,C.slotByNode,{plotH:o,padding:M,valueScale:j,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:c,mode:"geometry-refine"}),C=cf(e,t,m,g,{plotH:o,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(hh),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(e,t){const n=(e,n)=>{for(const o of e){const e=new Map;for(const i of o){const o=`${("out"===n?t.get(i.id)?.sourceSide:t.get(i.id)?.targetSide)??""}\0${"out"===n?i.startTime:i.endTime}`,r="out"===n?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=e.get(o);if(null!=s&&s!==r)return!0;e.set(o,r)}}return!1};return n(Object.values(e.outgoing),"out")||n(Object.values(e.incoming),"in")}(g,y)){const n=function(e,t,n,o){const i=new Map;for(const r of e){const e=t[r.source]?.localAttachments.get(r.id),s=t[r.target]?.localAttachments.get(r.id),a=n[r.source],l=n[r.target];if(!(e&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=jh(e,a,o),u=jh(s,l,o);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(t,m,C.centerlines,j);m={};for(const t of e)m[t.id]=Ch(t,g,y,n,u);C=cf(e,t,m,g,{plotH:o,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(hh),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const L=new Map(x.initialSlotOrder.map((e,t)=>[e,t])),T=[...C.slots].sort((e,t)=>(L.get(hh(e))??1/0)-(L.get(hh(t))??1/0)||dh(hh(e),hh(t))),I={};T.forEach((e,t)=>{for(const n of e.occupants)I[n.id]=t});const $=mh(e,t,m,T,I,{plotH:o,padding:M,valueScale:j,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),O=lf(e,m,T,I,$.centerlines,j,p),z=Mh(Fh(I,t),Eh(I,t),t,O,T,I,$.centerlines,C.laneLifetime,j,$.verticalUtilization,h,f);m=lf(e,m,C.slots,C.slotByNode,C.centerlines,j,p);const D=Mh(Fh(C.slotByNode,t),Eh(C.slotByNode,t),t,m,C.slots,C.slotByNode,C.centerlines,C.laneLifetime,j,C.verticalUtilization,h,f);return{nodeData:m,sides:y,valueScale:j,padding:M,compressedPadding:12>M,centerlines:C.centerlines,laneLifetime:C.laneLifetime,slots:C.slots,slotByNode:C.slotByNode,crossingsBefore:"insertion"===s?null:z.crossings,crossingsAfter:"insertion"===s?null:D.crossings,lengthBefore:"insertion"===s?null:z.weightedLength,lengthAfter:"insertion"===s?null:D.weightedLength,layoutQualityBefore:z,layoutQuality:D}}(t,M,{plotH:w,...u,ribbonLane:s,domain:o}),{centerlines:j,nodeData:C,valueScale:R}=P,L=_e(m,x),T=[],I=[],$=0===a?new Map:function(e,t,n){const o=new Set(t.map(e=>e.target)),i=new Map(e.map(e=>[e.id,e])),r=new Map;for(const e of t){if(o.has(e.source))continue;const t=r.get(e.source)??[];t.push(e),r.set(e.source,t)}const s=new Map;for(const t of e){if(!t.group)continue;const e=s.get(t.group)??[];e.push(t),s.set(t.group,e)}const a=new Set;for(const[e,t]of s){const n=t.flatMap(e=>r.get(e.id)??[]),i=new Set(n.map(e=>e.startTime));n.length>0&&1===i.size&&t.every(e=>{const t=e.xExtent?.[0],i=n[0].startTime;return!o.has(e.id)&&(r.get(e.id)?.length??0)>0&&Number.isFinite(t)&&i>t})&&a.add(e)}const l=new Map;for(const[e,t]of r){const o=i.get(e);if(o?.group&&!a.has(o.group))continue;const r=o?.xExtent?.[0],s=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=s[0]?.startTime-1;let u=null;for(let e=0;s.length>e;){const t=s[e].startTime;let o=e+1;for(;s.length>o&&s[o].startTime===t;)o++;for(let t=e;o>t;t++){const e=s[t],o=Number.isFinite(r)&&e.startTime>r,i=Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime;if(!o&&!i)continue;let a=n[0];o&&(a=Math.max(a,r)),i&&(a=Math.max(a,e.systemInTime)),!o&&i&&Number.isFinite(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),e.startTime>a&&l.set(e.id,a)}u=t,e=o}}for(const[e,t]of s){if(!a.has(e))continue;const n=t.flatMap(e=>r.get(e.id)??[]);if(!n.every(e=>l.has(e.id))){for(const e of n)l.delete(e.id);continue}const o=Math.max(...n.map(e=>l.get(e.id)));for(const e of n)l.set(e.id,o)}return l}(t,M,o),O=new Map(t.filter(e=>e.group).map(e=>[e.id,e.group])),z=new Map;for(const e of M){const t=C[e.source]?.localAttachments.get(e.id),n=C[e.target]?.localAttachments.get(e.id);t&&n&&z.set(e.id,df(t,j[e.source],n,j[e.target],R,_,s,o,{minRun:a,sourceRunwayStart:$.get(e.id)}))}const D=function(e,t,n,o,i,r){const s=new Map(t),a=new Map;for(const t of e){const e=r?.get(t.source),n=null==e?"node:"+t.source:"group:"+e,o=a.get(n)??new Map,i=o.get(t.startTime)??[];i.push(t),o.set(t.startTime,i),a.set(n,o)}for(const e of a.values())for(const[r,a]of e){if(!a.some(e=>n.has(e.id)))continue;const e=a.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;const l=o(r),c=Math.min(...e.map(e=>e.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(e=>{const t=n.get(e.id);return null==t?l:Math.min(l,o(t))})),d=Math.min(l,Math.max(c,u));for(const e of a){const n=t.get(e.id),o=d+(n.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(e.id,{...n,sx:d,cp1X:o,cp2X:o})}}return s}(M,z,$,_,s,O),F=function(e,t,n,o,i){const r=new Map;for(const s of e){if(!n.has(s.id))continue;const e=t.get(s.id);if(!e||e.sx>=o(s.startTime)-1e-9)continue;const a=i(e.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,D,$,_,e=>o[0]+e/v*(o[1]-o[0])),E=function(e,t,n){const o=new Map,i=new Map;for(const[e,t]of n??[]){const n=i.get(t)??[];n.push(e),i.set(t,n)}for(const r of e){const e=t.get(r.id);if(null==e||!Number.isFinite(e)||e>=r.startTime)continue;const s=n?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const t of a){const n=o.get(t)??new Map,i=n.get(r.startTime);n.set(r.startTime,null==i?e:Math.min(i,e)),o.set(t,n)}}return o}(M,F,O);t.forEach((e,t)=>{const n=C[e.id];if(!n||0===n.samples.length)return;const i=(r=n.samples,(s=E.get(e.id))&&0!==s.size?r.map(e=>{const t=s.get(e.t);return null==t?e:{...e,t:t}}):r);var r,s;const a=function(e,t,n,o,i){if(0===e.length)return null;const r=Ph(e,i),s=e=>t+(r[e].boundaryOffset??0)*n,a=e=>s(e)-r[e].topMass*n,l=e=>s(e)+r[e].botMass*n;let c=`M${o(r[0].t)},${a(0)}`;for(let e=1;r.length>e;e++)c+=` L${o(r[e].t)},${a(e)}`;c+=` L${o(r[r.length-1].t)},${l(r.length-1)}`;for(let e=r.length-2;e>=0;e--)c+=` L${o(r[e].t)},${l(e)}`;return c+" Z"}(i,j[e.id],R,_,o);if(!a)return;const l=Ph(i,o),u=l.find(e=>e.topMass+e.botMass>0)||l[0],h=j[e.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let f,p,g=c(e.id,t),m=g,x=.5;const b=e.__raw??e;if(y&&y.length>0){const e=Ce(b,y,L(b));"string"==typeof e.fill?g=e.fill:null!=e.fill&&Ko(e.fill)&&(p=e.fill,g=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:g),"string"==typeof e.stroke&&(m=e.stroke),"number"==typeof e.strokeWidth&&(x=e.strokeWidth),"number"==typeof e.fillOpacity&&(f=e.fillOpacity),"number"==typeof e.opacity&&null==f&&(f=e.opacity)}const v=function(e,t,n,o,i,r){const s=n.nodeData[e];if(!s||0===s.samples.length)return[];const a=n.valueScale,l=n.centerlines[e],c=Ph(s.samples,i),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=o(u.t),f=o(d.t),p=e=>o(_h(e,i)),g=[],y=(e,t,n,o)=>`M${e},${t} L${n},${t} L${n},${o} L${e},${o} Z`;for(const n of t){if(n.source===e&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const e=s.localAttachments.get(n.id),t=r?.get(n.id)??n.startTime;if(e&&"out"===e.kind&&t>n.systemInTime){const o=p(n.systemInTime),r=p(t),s=null!=i&&i[0]>n.systemInTime,c=s?o:o-20,u=s?Math.min(r,o+20):o,d=Math.max(h,c);if(r>d){const[t,n]=jh(e,l,a);g.push({pathD:y(d,t,r,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===e&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const e=s.localAttachments.get(n.id);if(e&&"in"===e.kind&&n.systemOutTime>n.endTime){const t=p(n.systemOutTime),o=p(n.endTime),i=t+20,r=Math.min(f,i);if(r>o){const[n,s]=jh(e,l,a);g.push({pathD:y(o,n,r,s),x0:t,x1:i,from:1,to:0})}}}}return g}(e.id,M,P,_,o,F);T.push({id:e.id,pathD:a,fill:g,stroke:m,strokeWidth:x,...null!=f&&{fillOpacity:f},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&e.xExtent?e.xExtent[0]:u.t)-4,labelY:h,labelText:e.label??e.id})});const N=new Map;t.forEach((e,t)=>N.set(e.id,t)),M.forEach(e=>{const t=D.get(e.id);if(!t)return;const n=N.get(e.source)??0,o=c(e.source,n),{pathD:i,bezier:r}=uf(t),s=e.__raw??e,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;I.push({id:e.id,pathD:i,fill:o,opacity:u,rawDatum:s,bezier:r})});const B=function(e,t,n){const o=e.map(e=>({...e})),i=new Map;for(const e of o){const n=t[e.id];if(null==n)continue;const o=i.get(n)??[];o.push(e),i.set(n,o)}const r=e=>{if(2>e.length)return;const t=e.reduce((e,t)=>e+t.labelY,0)/e.length,o=(e.length-1)/2;e.forEach((e,i)=>{e.labelY=Math.max(8,Math.min(n-8,t+16*(i-o)))})};for(const e of i.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],n=-1/0;for(const o of e){const e=o.labelX-hf(o.labelText);t.length>0&&e>n+3&&(r(t),t=[],n=-1/0),t.push(o),n=Math.max(n,o.labelX)}r(t)}return function(e,t){const n=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;3>e;e+=1){for(let e=0;n.length>e;e+=1){let t=8;for(let o=0;e>o;o+=1)pf(n[e],n[o])&&(t=Math.max(t,n[o].labelY+16));n[e].labelY=Math.max(n[e].labelY,t)}for(let e=n.length-1;e>=0;e-=1){let o=t-8;for(let t=e+1;n.length>t;t+=1)pf(n[e],n[t])&&(o=Math.min(o,n[t].labelY-16));n[e].labelY=Math.min(n[e].labelY,o)}}}(o,n),o}(T,P.slotByNode,w).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:yf(e.pathD),gradientStubs:e.gradientStubs?.map(xf),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),W="vertical"===d?function(e,t,n){const o=e.map(e=>({...e}));for(const e of o){const n=1.22*hf(e.labelText)+4;e.labelX=t-4>n?Math.max(n/2+2,Math.min(t-n/2-2,e.labelX)):t/2}const i=[],r=[...o].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(const e of r){const t=i[i.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?i.push([e]):t.push(e)}for(const e of i){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));const t=[],o=new Map;for(const n of e){const[e,i]=ff(n);let r=t.findIndex(t=>e>t+8);-1===r&&(r=t.length),t[r]=i,o.set(n,r)}const i=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=14*t.length+8>i;for(const t of e){const e=o.get(t)??0;t.labelY=r?Math.min(n-8,12+14*e):Math.max(8,i-14*e)}}return o}(B,i,r):B,Y=new Map;if(null!=f)for(const e of t){const t=e.__raw??e,n="function"==typeof f?f(t):Number(t[f]);Number.isFinite(n)&&Y.set(e.id,n)}const q=function(e,t,n,o,i={}){if(!1===o)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(e.length,Math.floor(Math.max(1,t*n)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=e.map((e,t)=>{const n=i.priorityById?.get(e.id),o=Math.abs(e.labelY);return{band:e,index:t,score:null!=n&&Number.isFinite(n)?1e6*n+hf(e.labelText):hf(e.labelText)+.01*o}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),a=new Set(s.slice(0,r).map(e=>e.band.id));return e.map(e=>a.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(W,i,r,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:q,ribbons:I.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:yf(e.pathD),bezier:mf(e.bezier)}}(e,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:A,xScale:_}}var vf=require("react/jsx-runtime"),wf="var(--semiotic-grid, #94a3b8)",kf="var(--semiotic-text-secondary, #475569)",Sf="var(--semiotic-text-secondary, #94a3b8)",Af=.22;function Mf(e,t,n){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,n))}var _f=e=>{const{bands:t=[],ribbons:n=[],showLabels:o=!0,selectionDatum:i="raw"}=e.config,r=e.selection??null,s=[];for(const e of n){const t={__kind:"ribbon",data:e.rawDatum,id:e.id},n=!Mf(t,r,i);s.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:n?Math.min(e.opacity,Af):e.opacity,stroke:"none"},datum:t})}for(const e of t){if(!e.gradientStubs)continue;const t=!Mf({__kind:"band",data:e.rawDatum,id:e.id},r,i);for(let n=0;e.gradientStubs.length>n;n++){const o=e.gradientStubs[n];s.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?Af:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,...null!=o.y0&&{y0:o.y0},...null!=o.y1&&{y1:o.y1},from:o.from,to:o.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${n}`}})}}for(const e of t){const t=!(!e.gradientStubs||0>=e.gradientStubs.length),n={__kind:"band",data:e.rawDatum,id:e.id},o=!Mf(n,r,i);s.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:e.hatchFill??e.fill,fillOpacity:o?Af:e.fillOpacity??.86},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...o&&t?{opacity:Af}:{}},datum:n})}const a=o?t.flatMap(e=>{const t=e.labelDeferred&&e.labelFullText?.trim(),n=e.labelText.trim().length>0,o=t&&r?.isActive&&Mf({__kind:"band",data:e.rawDatum,id:e.id},r,i),s=n?e.labelText:o?e.labelFullText:"";return s.trim()?[{x:e.labelX,y:e.labelY,text:s,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:s,labels:a}};function Pf(e,t){if(!e)return[];const n=[],o=e=>{n.push(e);const i="function"==typeof t?t(e):e[t];i&&Array.isArray(i)&&i.forEach(o)};return o(e),n}function jf(e,t,n,o){if(e&&e.length>0)return e;const i=new Set;return t.forEach(e=>{const t="function"==typeof n?n(e):e[n],r="function"==typeof o?o(e):e[o];i.add(t),i.add(r)}),Array.from(i).map(e=>({id:e}))}function Cf(e,t,n={}){return Se(t?"function"==typeof t?n=>({...e(n),...t(n)??{}}):n=>({...e(n),...t}):e,n)}var Rf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,n,o,i)=>{const r=function(e){if(void 0!==e.edgeStyle)return e.edgeStyle;const{edgeWidth:t,edgeColor:n,edgeOpacity:o}=e,i=e.strokeWidth??1;return void 0!==t||void 0!==n||void 0!==o||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof t)a=t;else if("function"==typeof t)a=t(s);else if("string"==typeof t){const e=s?.[t],n="number"==typeof e?e:Number(e);a=Number.isFinite(n)&&n>0?n:i}return{stroke:n??e.stroke??"#999",strokeWidth:a,opacity:o??e.opacity??.6}}:void 0}(i),s=et(o.theme).colors.categorical,a=new Map,l=i.nodeStyle??(e=>({fill:t?ye(e?.data||e,t,void 0):$u(void 0,s,n,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=Le(i.styleRules,t,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=Se(c?(e,t)=>({...l(e),...c(e,t)}):l,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:t,colorScheme:n,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:u,edgeStyle:r,...o}}},Lf={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,n,o,i)=>{const r=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",g=i.groupBy,y=i.edgeIdAccessor||"id",m=(e,t)=>"function"==typeof e?e(t):t[e],x=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],v=b.length>0?b:jf([],x,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(e=>{const t=m(c,e)+"",n=m(p,e),o=i.nodeLabel?m(i.nodeLabel,e):t,s={id:t,label:null==o?t:o+"",__raw:e},a=g?m(g,e):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(n)&&2===n.length){const e=r(n[0]),t=r(n[1]);Number.isFinite(e)&&Number.isFinite(t)&&(s.xExtent=[e,t])}return s}),S=x.map((e,t)=>{const n=m(y,e),o={id:null!=n?n+"":`${m(s,e)}-${m(a,e)}-${t}`,source:m(s,e)+"",target:m(a,e)+"",value:Number(m(l,e)),startTime:r(m(u,e)),endTime:r(m(d,e)),__raw:e};if(h){const t=r(m(h,e));Number.isFinite(t)&&(o.systemInTime=t)}if(f){const t=r(m(f,e));Number.isFinite(t)&&(o.systemOutTime=t)}return o}),[A,M]=o.size??[600,400],_=o.margin,P="vertical"===i.orientation?"vertical":"horizontal",j=function(e,t,n,o="horizontal"){return"vertical"===o?{top:e?38:t?28:16,right:24,bottom:24,left:n?72:24}:{top:e?30:t?24:8,right:80,bottom:n?28:8,left:80}}(!!o.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,P),C={...j,..._},R=(o.showLegend??!!t)&&!!t,L=o.legendPosition??"right",T=o.__explicitMargin,I=e=>"number"==typeof T||null!=T&&"object"==typeof T&&null!=T[e];R&&("right"!==L||I("right")?"bottom"!==L||I("bottom")||(C.bottom=Math.max(C.bottom,80)):C.right=Math.max(C.right,140));const $=C,O=A-$.left-$.right,z=M-$.top-$.bottom,D=he(n,et(o.theme).colors.categorical,B),F="function"==typeof t?t:null,E=F?v.map(e=>({_cat:F(e)})):v,N=F?"_cat":"string"==typeof t?t:void 0,W=n??[...D],Y=N?xe(E,N,W):null,q=new Map;for(const e of k)q.set(e.id,e.__raw);const X=(e,n)=>{if(t&&q.has(e)){const n=q.get(e);return F?ye({_cat:F(n)},"_cat",Y??void 0):ye(n,"string"==typeof t?t:"id",Y??void 0)}return D[n%D.length]},H=Ci(R&&t?(()=>{const e=new Map;v.forEach((n,o)=>{const i=m(t,n),r=null==i?"":i+"";r&&!e.has(r)&&e.set(r,{label:r,color:X(m(c,n)+"",o)})});const n=Array.from(e.values());return n.length>0?{legendGroups:[{type:"fill",label:"",items:n,styleFn:e=>{const t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,o.legend),G=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:V,layoutConfig:U,issues:K,xScale:Z}=bf({nodes:k,edges:S,domain:w,plotW:O,plotH:z,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:X,showLabels:G,styleRules:i.styleRules,colorBy:t,valueAccessor:l,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(K.length>0){const e=K.map(rh).join("; ");throw Error("ProcessSankey: data invalid — "+e)}const Q=V?function(e){const t=e.layout,n=e.nodes,o=e.orientation,i=e.plotW,r=e.plotH,s=e.timelineExtent,a=e.axisTicks,l=e.showQualityReadout??!1,c=e.showLaneRails??!1,u=(e.warnings??[]).slice(0,3),d=e.timeFormat,h=e.colorOf,f=e.toTime,p=e.xScale,{centerlines:g,laneLifetime:y,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=t;let A=null,M=null;for(const e of n){const t=y[e.id];if(!t||null===t.start||null===t.end)continue;const n=p(t.start),o=p(t.end);(null===A||A>n)&&(A=n),(null===M||o>M)&&(M=o)}const _=e=>Math.max(0,Math.min(s,e)),P=_(A??0),j=Math.max(P,_(M??s)),C=a.map((e,t)=>({tick:e,index:t,coordinate:p(f(e.date))})).filter(({coordinate:e})=>e>=P-.5&&j+.5>=e),R=null!==(w??null)&&null!=k&&null!=S,L=l&&(R||u.length>0)?(0,vf.jsxs)("g",{fill:Sf,fontSize:10,textAnchor:"end",children:[R&&(0,vf.jsxs)(vf.Fragment,{children:[(0,vf.jsxs)("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),(0,vf.jsxs)("text",{x:i,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),u.map((e,t)=>(0,vf.jsxs)("text",{x:i,y:R?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},"warn-"+t))]}):null,T=b?(0,vf.jsx)("text",{x:i,y:"vertical"===o?-3:2,fontSize:10,fill:Sf,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,I=(e,t)=>h?h(e,t):wf;return(0,vf.jsxs)("g","vertical"===o?{children:[L,T,C.map(({index:e,coordinate:t})=>(0,vf.jsx)("line",{x1:0,y1:t,x2:i,y2:t,stroke:wf,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&n.map((e,t)=>{const n=y[e.id];if(!n||null===n.start)return null;const o=m[e.id],i=o?{topPeak:o.topPeak,botPeak:o.botPeak}:{topPeak:0,botPeak:0},r=g[e.id]+(i.botPeak-i.topPeak)*x/2,s=p(n.start),a=p(n.end),l=I(e.id,t);return(0,vf.jsxs)("g",{children:[(0,vf.jsx)("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),(0,vf.jsx)("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),(0,vf.jsx)("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+e.id)}),(0,vf.jsx)("line",{x1:-4,y1:P,x2:-4,y2:j,stroke:wf}),C.map(({tick:e,index:t,coordinate:n})=>{const o=f(e.date),i=null!=e.label?e.label:d?d(new Date(o)):"";return(0,vf.jsxs)("g",{transform:`translate(-4,${n})`,children:[(0,vf.jsx)("line",{x2:-6,stroke:wf}),(0,vf.jsx)("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:kf,children:i})]},t)})]}:{children:[L,T,C.map(({index:e,coordinate:t})=>(0,vf.jsx)("line",{x1:t,y1:0,x2:t,y2:r,stroke:wf,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&n.map((e,t)=>{const n=y[e.id];if(!n||null===n.start)return null;const o=m[e.id],i=o?{topPeak:o.topPeak,botPeak:o.botPeak}:{topPeak:0,botPeak:0},r=g[e.id]+(i.botPeak-i.topPeak)*x/2,s=p(n.start),a=p(n.end),l=I(e.id,t);return(0,vf.jsxs)("g",{children:[(0,vf.jsx)("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),(0,vf.jsx)("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),(0,vf.jsx)("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+e.id)}),(0,vf.jsx)("line",{x1:P,y1:r+4,x2:j,y2:r+4,stroke:wf}),C.map(({tick:e,index:t,coordinate:n})=>{const o=f(e.date),i=null!=e.label?e.label:d?d(new Date(o)):"";return(0,vf.jsxs)("g",{transform:`translate(${n},${r+4})`,children:[(0,vf.jsx)("line",{y2:6,stroke:wf}),(0,vf.jsx)("text",{y:20,textAnchor:"middle",fontSize:11,fill:kf,children:i})]},t)})]})}({layout:V,nodes:k,orientation:P,plotW:O,plotH:z,timelineExtent:"vertical"===P?z:O,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(e=>({date:e.date,label:e.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?e=>i.timeFormat(e):void 0,colorOf:X,toTime:e=>r(e),xScale:e=>Number(Z(e))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:_f,layoutConfig:U,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:t,colorScheme:n,...Q&&{backgroundGraphics:Q},...o,showLegend:R,...H&&{legend:H,legendPosition:L},__legendIncludesAutomatic:!0,margin:$}}},Tf={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,n,o,i)=>{const r=Array.isArray(i.nodes)?i.nodes:jf([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=et(o.theme).colors.categorical,a=new Map,l="string"==typeof t?t:"__ssrSankeyColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrSankeyColorBy:t(e)})):r,u=t?xe(c,l,n??o.colorScheme??s):void 0,d=e=>({fill:t?ye(e?.data||e,t,u):$u(void 0,s,n,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=Le(i.styleRules,t,i.valueAccessor),f=h?(e,t)=>({...d(e),...h(e,t)}):d,p=function({edgeColorBy:e,colorBy:t,colorScale:n,nodeStyleFn:o,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof e)a.fill=e(s);else if("source"===e){const e="object"==typeof s.source?s.source:null;t&&e?a.fill=ye(e.data||e,t,n):e&&(a.fill=o(e,e.index).fill)}else if("target"===e){const e="object"==typeof s.target?s.target:null;t&&e?a.fill=ye(e.data||e,t,n):e&&(a.fill=o(e,e.index).fill)}else"gradient"===e&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:t,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:t,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:Se(i.nodeStyle||f,Fe(i)),edgeStyle:Se(i.edgeStyle||p,Fe(i)),colorScheme:n,...o}}},If={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,n,o,i)=>{if(!(t||Array.isArray(i.styleRules)&&i.styleRules.length>0||o.nodeStyle||i.nodeStyle||ke(Fe(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:t,edgeColorBy:i.edgeColorBy,colorScheme:n,...o};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:jf([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=et(o.theme).colors.categorical,l=he(n,a),c="string"==typeof t?t:"__ssrChordColorBy",u="function"==typeof t?s.map(e=>({...e,__ssrChordColorBy:t(e)})):s,d=t?xe(u,c,n??o.colorScheme??a):void 0,h=new Map,f=i.nodeIdAccessor||i.nodeIDAccessor||"id",p=(e,n)=>{const o=e?.data||e;let r;if(t)r=ye(o,t,d);else{const t=(e.id??o?.[f]??"")+"";h.has(t)||h.set(t,h.size);const i=e.index??n??h.get(t);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=Le(i.styleRules,t,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:t,edgeColorBy:i.edgeColorBy,colorScheme:n,nodeStyle:Se(i.nodeStyle||g,Fe(i)),...o}}},$f={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,n,o,i)=>{const r=et(o.theme).colors.categorical,s=new Map,a=Pf(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrTreeColorBy:l(e)})):a,u=l?"__ssrTreeColorBy":"string"==typeof t?t:void 0,d=t&&u?xe(c,u,n??o.colorScheme??r):void 0,h=o.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:e,childrenAccessor:i.childrenAccessor,colorBy:t,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:n,...o,nodeStyle:Cf(e=>{const o=e?.data||e;return{fill:i.colorByDepth?pe[Number(e?.depth||0)%pe.length]:t?l?ye({__ssrTreeColorBy:l(o)},"__ssrTreeColorBy",d??void 0):ye(o,t,d??void 0):$u(void 0,r,n,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,Fe(i))}}},Of={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,n,o,i)=>{const r=et(o.theme).colors.categorical,s=new Map,a=Pf(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrTreemapColorBy:l(e)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,d=t&&u?xe(c,u,n??o.colorScheme??r):void 0,h=i.showLabels??o.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:o.paddingTop,g=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,y=o.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:e,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:t,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:f,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=g&&{paddingTop:g},colorScheme:n,...o,nodeStyle:Cf(e=>{const o=e?.data||e;return{fill:i.colorByDepth?pe[Number(e?.depth||0)%pe.length]:t?l?ye({__ssrTreemapColorBy:l(o)},"__ssrTreemapColorBy",d??void 0):ye(o,t,d??void 0):$u(void 0,r,n,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},y,Fe(i))}}},zf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,n,o,i)=>{const r=et(o.theme).colors.categorical,s=new Map,a=Pf(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrCirclePackColorBy:l(e)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,d=t&&u?xe(c,u,n??o.colorScheme??r):void 0,h=o.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:e,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:t,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??o.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:n,...o,nodeStyle:Cf(e=>{const o=e?.data||e;return{fill:i.colorByDepth?pe[Number(e?.depth||0)%pe.length]:t?l?ye({__ssrCirclePackColorBy:l(o)},"__ssrCirclePackColorBy",d??void 0):ye(o,t,d??void 0):$u(void 0,r,n,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,Fe(i))}}},Df={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5},Ff=require("d3-scale");function Ef(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}var Nf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,n,o,i)=>{const r="string"==typeof n?n:"blues",s=i.areaStyle??function(e,t,n,o){if(!Array.isArray(e))return;const i=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0;let r=1/0,s=-1/0;for(const t of e){const e=i(t);null!=e&&isFinite(e)&&(r>e&&(r=e),e>s&&(s=e))}const a=(0,Ff.scaleSequential)(te(n)).domain([Number.isFinite(r)?r:0,Number.isFinite(s)?s:1]);return e=>{const t=i(e);return{fill:null!=t&&isFinite(t)?a(t):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:o}}}(i.areas,i.valueAccessor,r,i.areaOpacity??1),a=i.styleRules?Re(s,i.styleRules,e=>{return{value:(t=e,"function"==typeof i.valueAccessor?i.valueAccessor(t):null!=i.valueAccessor?t?.properties?.[i.valueAccessor]??t?.[i.valueAccessor]:void 0)};var t},Ef):s;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:a,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...o}}},Bf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,n,o,i)=>{const r=e||i.points,s=i.pointStyle??function(e,t,n,o){const i=Array.isArray(e)?e:[];let r,s;if(t){const e="string"==typeof t?t:"__geoColorBy",o="string"==typeof t?i:i.map(e=>({...e,__geoColorBy:t(e)}));r=xe(o,e,n)}if(o.sizeBy){const e=i.map("function"==typeof o.sizeBy?o.sizeBy:e=>e?.[o.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(s=ve(e))}return e=>({fill:t&&r?ye(e,t,r):de,fillOpacity:o.fillOpacity,stroke:"#fff",strokeWidth:o.strokeWidth,r:o.sizeBy?be(e,o.sizeBy,o.sizeRange,s):o.pointRadius??6})}(r,t,n,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Re(s,i.styleRules,_e(t,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||Df,pointStyle:a,sizeBy:i.sizeBy,colorBy:t,colorScheme:n,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...o}}},Wf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,n,o,i)=>{const r=(Array.isArray(e)?e:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:e=>e[l],d="function"==typeof c?c:e=>e[c],h=(i.nodes||[]).map(e=>({...e,x:u(e),y:d(e)})),f=new Map;for(const e of h)f.set(e[s]+"",e);const p=i.edgeColorBy??t,g="function"==typeof p,y=r.map(e=>{if(!e||null==e.source||null==e.target)return null;const t=f.get(e.source+""),n=f.get(e.target+"");return t&&n?{...e,coordinates:[{x:t.x,y:t.y},{x:n.x,y:n.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=p?g?xe(y.map(e=>({[m]:p(e)})),m,n||"category10"):xe(y,p,n||"category10"):null,b=e=>p&&x?ye(e,p,x):"#007bff";let v=1/0,w=-1/0;for(const e of y){const t=Number(e[a]??0);isFinite(t)&&(v>t&&(v=t),t>w&&(w=t))}const k=w>v?w-v:0,[S,A]=i.edgeWidthRange??[1,8],M=A-S,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||Df,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:n,lineStyle:e=>{const t=Number(e?.[a]),n=Number.isFinite(t)?t:v,o=S+Math.max(0,Math.min(1,k>0?(n-v)/k:0))*M;return{stroke:b(e),strokeWidth:o,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...o}}},Yf=g(require("react"));function qf(e){const[t,n]=e,o=160>t||116>n,i=o?Math.min(12,Math.max(2,.08*t)):32,r=o?Math.min(8,Math.max(2,.12*n)):24,s=o?r:34;return{width:t,height:n,plot:{x:i,y:r,width:Math.max(1,t-2*i),height:Math.max(1,n-r-s)}}}function Xf(e){const t=(e??"")+"";if(!t)return"#4e79a7";const n=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let o=0;for(let e=0;t.length>e;e+=1)o=31*o+t.charCodeAt(e)>>>0;return n[o%n.length]}function Hf(e,t="#4e79a7",n){const o=n?.styleRules,i=!!o&&o.length>0,r=i?Ae(n?.valueAccessor):void 0;return n=>{const s=n.datum,a=s&&e?"function"==typeof e?e(s,0):s[e]:void 0,l={fill:null==a?t:Xf(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,Ce(s,o,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function Gf(e,t,n,o){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:n},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...o}}}function Vf(e,t,n){return"function"==typeof n?n(e,t):e[n]}function Uf(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:null}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Kf(e,t,n){return Math.max(t,Math.min(n,e))}function Zf(e,t){const n=Uf(e);return null!=n&&n>0?n:t}function Qf(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Jf(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}var ep=require("d3-scale");function tp(e){let t=e>>>0;return function(){t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}var np={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},op=1e-9,ip=.005;function rp(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function sp(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function ap(e,t,n){return Math.max(t,Math.min(n,e))}function lp(e,t,n){return Math.min(e??n,t??n)}function cp(e,t,n){return ap(Math.max(e??n,t??n),0,1)}function up(e){return 0>e?-1:1}function dp(e){if("circle"===e.shape.type){const t=e.shape.radius;return{minX:e.x-t,minY:e.y-t,maxX:e.x+t,maxY:e.y+t}}const t=e.shape.width/2,n=e.shape.height/2;return{minX:e.x-t,minY:e.y-n,maxX:e.x+t,maxY:e.y+n}}function hp(e){const t=e.shape;if("aabb"===t.type){const e=t.width/2,n=t.height/2;return{minX:t.x-e,minY:t.y-n,maxX:t.x+e,maxY:t.y+n}}const n=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-n,minY:Math.min(t.y1,t.y2)-n,maxX:Math.max(t.x1,t.x2)+n,maxY:Math.max(t.y1,t.y2)+n}}function fp(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function pp(e,t,n,o,i,r,s,a){const l=i-e,c=(n+s)/2-Math.abs(l);if(0>=c)return null;const u=r-t,d=(o+a)/2-Math.abs(u);return d>0?d>c?{nx:up(l),ny:0,penetration:c}:{nx:0,ny:up(u),penetration:d}:null}function gp(e,t,n,o,i,r,s){const a=r/2,l=s/2,c=e-ap(e,o-a,o+a),u=t-ap(t,i-l,i+l),d=c*c+u*u;if(d>n*n)return null;if(op>=d){const r=Math.abs(e-(o-a)),s=Math.abs(e-(o+a)),c=Math.abs(t-(i-l)),u=Math.abs(t-(i+l)),d=Math.min(r,s,c,u);return d===r?{nx:-1,ny:0,penetration:n+r}:d===s?{nx:1,ny:0,penetration:n+s}:d===c?{nx:0,ny:-1,penetration:n+c}:{nx:0,ny:1,penetration:n+u}}const h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:n-h}}function yp(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,o,i,r){const s=o-e,a=i-t,l=n+r,c=s*s+a*a;if(c>=l*l)return null;if(op>=c)return{nx:1,ny:0,penetration:l};const u=Math.sqrt(c);return{nx:s/u,ny:a/u,penetration:l-u}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return pp(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);if("circle"===e.shape.type&&"aabb"===t.shape.type){const n=gp(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height);return n?{nx:-n.nx,ny:-n.ny,penetration:n.penetration}:null}return"aabb"===e.shape.type&&"circle"===t.shape.type?gp(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function mp(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?gp(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):pp(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,o,i,r,s,a=0){const l=r-o,c=s-i,u=l*l+c*c,d=u>op?ap(((e-o)*l+(t-i)*c)/u,0,1):0,h=n+a/2,f=e-(o+l*d),p=t-(i+c*d),g=f*f+p*p;if(g>=h*h)return null;if(op>=g){const e=Math.sqrt(u);return e>op?{nx:-c/e,ny:l/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(g);return{nx:f/y,ny:p/y,penetration:h-y}}(e.x,e.y,"circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2,n.x1,n.y1,n.x2,n.y2,n.thickness??0)}function xp(e,t){return`${e}\0${t}`}function bp(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function vp(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,shape:rp(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function wp(e){return e&&"function"!=typeof e?{property:e.property,equals:e.equals,notEquals:e.notEquals,oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function kp(e){return{id:e.id,shape:sp(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:wp(e.bodyFilter),index:e.index}}function Sp(e,t){return!!t?.some(t=>Object.is(e,t))}function Ap(e,t){return function(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=function(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!Sp(n,t.oneOf)||t.notOneOf&&Sp(n,t.notOneOf))}(t,e.bodyFilter)}var Mp=class{constructor(e={}){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={...np,...e},this.random=tp(this.options.seed)}init(e={}){this.options={...np,...e},this.random=tp(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){const t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(op,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:rp(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(const t of e){this.bodies.delete(t);for(const e of Array.from(this.activeSensors))bp(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const t of e)this.colliders.set(t.id,{...t,shape:sp(t.shape),bodyFilter:wp(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){const t=e.id??"spring-"+this.nextSpringIndex;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,n){const o=this.bodies.get(e);o&&(o.vx+=t/o.mass,o.vy+=n/o.mass,this.wake(o))}step(e=this.options.fixedDt){const t=Math.max(0,e);if(this.lastEvents=[],0===t)return;const n=this.sortedBodies();for(const e of n)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);const o=this.options.maxVelocity;for(const e of n)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=this.options.velocityDamping,e.vy*=this.options.velocityDamping,o>0){const t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>o){const n=o/t;e.vx*=n,e.vy*=n}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear();const i=this.bodyPairKeys(n),r=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,i,0===e),this.resolveColliders(n,r,0===e);this.updateSensors(n),this.updateSleeping(n,t)}settle(e=1200,t=this.options.fixedDt){let n=0;for(;e>n&&!this.allSleeping();)this.step(t),n+=1;return n}readState(e=[]){e.length=0;for(const t of this.sortedBodies())e.push({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:rp(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(bp)}allSleeping(){for(const e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(vp),colliders:this.sortedColliders().map(kp),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=tp(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const t of e.bodies){const e=vp(t);this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(const t of e.colliders){const e=kp(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(const t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});const e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(const t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){const n=this.bodies.get(t.bodyId);if(!n||n.sleeping)continue;const o="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!o)continue;const i=o.x-n.x,r=o.y-n.y,s=Math.sqrt(i*i+r*r);if(op>=s)continue;const a=i/s,l=r/s,c=(s-t.restLength)*t.stiffness+((("vx"in o?o.vx:0)-n.vx)*a+(("vy"in o?o.vy:0)-n.vy)*l)*t.damping;n.vx+=c*a*e/n.mass,n.vy+=c*l*e/n.mass}}resolveBodyPairs(e,t,n){for(const o of t){const[t,i]=o.split(":").map(Number),r=e[t],s=e[i];if(!r||!s)continue;const a=yp(r,s);a&&(this.resolveDynamicCollision(r,s,a),n&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(e){const t=Math.max(1,this.options.cellSize),n=new Map;for(let o=0;e.length>o;o+=1){if(!1===e[o].bodyCollisions)continue;const i=dp(e[o]),r=Math.floor(i.minX/t),s=Math.floor(i.maxX/t),a=Math.floor(i.minY/t),l=Math.floor(i.maxY/t);for(let e=r;s>=e;e+=1)for(let t=a;l>=t;t+=1){const i=`${e}:${t}`,r=n.get(i);r?r.push(o):n.set(i,[o])}}const o=new Set;for(const t of Array.from(n.keys()).sort()){const i=n.get(t)??[];i.sort((e,t)=>e-t);for(let t=0;i.length>t;t+=1)for(let n=t+1;i.length>n;n+=1){const r=i[t],s=i[n];!1!==e[r].bodyCollisions&&!1!==e[s].bodyCollisions&&fp(dp(e[r]),dp(e[s]))&&o.add(`${r}:${s}`)}}return Array.from(o).sort((e,t)=>{const[n,o]=e.split(":").map(Number),[i,r]=t.split(":").map(Number);return n===i?o-r:n-i})}resolveDynamicCollision(e,t,n){e.sleeping&&this.contactOpposesGravity(n.nx,n.ny)&&this.supportedThisStep.add(t.id),t.sleeping&&this.contactOpposesGravity(-n.nx,-n.ny)&&this.supportedThisStep.add(e.id);const o=e.sleeping?0:1/e.mass,i=t.sleeping?0:1/t.mass,r=o+i;if(op>=r)return;const s=Math.max(0,n.penetration-ip)/r;e.x-=n.nx*s*o,e.y-=n.ny*s*o,t.x+=n.nx*s*i,t.y+=n.ny*s*i;const a=(t.vx-e.vx)*n.nx+(t.vy-e.vy)*n.ny;if(a>0)return;const l=Math.abs(a),c=-(1+lp(e.restitution,t.restitution,this.options.restitution))*a/r,u=c*n.nx,d=c*n.ny;e.vx-=u*o,e.vy-=d*o,t.vx+=u*i,t.vy+=d*i,this.applyFriction(e,t,n,c,o,i),l>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,o,i,r){const s=-n.ny,a=n.nx,l=(t.vx-e.vx)*s+(t.vy-e.vy)*a,c=i+r;if(op>=Math.abs(l)||op>=c)return;const u=cp(e.friction,t.friction,this.options.friction),d=ap(-l/c,-o*u,o*u),h=d*s,f=d*a;e.vx-=h*i,e.vy-=f*i,t.vx+=h*r,t.vy+=f*r}resolveColliders(e,t,n){for(const o of e)for(const e of t){if(!Ap(e,o))continue;if(!fp(dp(o),hp(e)))continue;const t=mp(o,e);t&&(this.resolveStaticCollision(o,e,t),this.contactOpposesGravity(t.nx,t.ny)&&this.supportedThisStep.add(o.id),n&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:e.id,sensor:!1}))}}resolveStaticCollision(e,t,n){e.x+=n.nx*Math.max(0,n.penetration-ip),e.y+=n.ny*Math.max(0,n.penetration-ip);const o=e.vx*n.nx+e.vy*n.ny;if(0>o){const i=lp(e.restitution,t.restitution,this.options.restitution);e.vx-=(1+i)*o*n.nx,e.vy-=(1+i)*o*n.ny;const r=-n.ny,s=n.nx,a=e.vx*r+e.vy*s,l=cp(e.friction,t.friction,this.options.friction);e.vx-=a*r*l,e.vy-=a*s*l}}updateSensors(e){const t=new Set,n=this.sortedColliders().filter(e=>e.sensor);for(const o of e){const e=dp(o);for(const i of n){if(!Ap(i,o))continue;if(!fp(e,hp(i)))continue;if(!mp(o,i))continue;const n=xp(i.id,o.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:o.id,sensorId:i.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:o}=bp(e);this.lastEvents.push({type:"sensor-exit",bodyId:o,sensorId:n})}this.activeSensors=t}updateSleeping(e,t){const n=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const o of e)Math.sqrt(o.vx*o.vx+o.vy*o.vy)>=this.options.sleepSpeed||Math.sqrt((o.x-o.prevX)*(o.x-o.prevX)+(o.y-o.prevY)*(o.y-o.prevY))>=this.options.sleepSpeed*t||n&&!this.supportedThisStep.has(o.id)?o.sleeping?this.wake(o):o.sleepTime=0:(o.sleepTime+=t,o.sleeping||this.options.sleepAfter>o.sleepTime||(o.sleeping=!0,o.vx=0,o.vy=0,this.lastEvents.push({type:"sleep",bodyId:o.id})))}contactOpposesGravity(e,t){const{x:n,y:o}=this.options.gravity,i=Math.hypot(n,o);return 1e-9>=i||-.2>(e*n+t*o)/i}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},_p=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Mp).capabilities,engine:"builtin"},this.world=new Mp(e)}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Pp(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):function(e={}){return new _p(e)}(t)}var jp=["binId","targetBin","category","windowIndex","lane","group"];function Cp(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);const n=t-e.mean;e.mean+=n/e.count,e.m2+=n*(t-e.mean)}function Rp(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Lp(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:1/0,max:e.count>0?e.max:-1/0}}function Tp(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Ip(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?Tp(t,e):void 0}function $p(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function Op(e){const t=Rp(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:Rp(e.x),y:Rp(e.y),value:t}}var zp=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;const t=this.nextIndex;this.nextIndex+=1;const n=$p(Ip(this.config.binAccessor,e,t))??function(e){for(const t of jp){const n=$p(Tp(e,t));if(n)return n}return"sediment"}(e),o=$p(Ip(this.config.labelAccessor,e,t))??n,i=function(e,t,n){if("number"==typeof e)return e;const o="function"==typeof e?e(t,n):"string"==typeof e?Tp(t,e):1,i="number"==typeof o?o:Number(o);return Number.isFinite(i)?i:1}(this.config.valueAccessor,e,t),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(n);return s||(s={id:n,label:o,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(n,s)),s.label=o,s.lastBodyId=e.id,s.lastDatum=e.datum,Cp(s.x,e.x),Cp(s.y,e.y),Cp(s.value,i),r>0&&(s.bodyIds.push(e.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Op(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Op)}restore(e=[]){this.bins.clear();for(const t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Lp(t.x),y:Lp(t.y),value:Lp(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){const e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function Dp(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}var Fp={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Ep={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Np(e={},t=Ep){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function Bp(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Wp(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:void 0}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Yp(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function qp(e){return{...Bp(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Xp(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function Hp(e){return!1!==e&&{...e}}function Gp(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function Vp(e){return{...e,gravity:{...e.gravity}}}function Up(e,t,n,o){if("circle"===e.shape.type){const i=e.x-t,r=e.y-n,s=e.shape.radius+o,a=i*i+r*r;return a>s*s?null:a}const i=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),r=Math.max(Math.abs(n-e.y)-e.shape.height/2,0),s=i*i+r*r;return s>o*o?null:s}function Kp(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Zp(e,t={}){const{idPrefix:n="plot",includeFloor:o=!0,includeCeiling:i=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:l=a}=t,c=[],u=e.x+e.width/2,d=e.y+e.height/2;return o&&c.push({id:n+"-floor",shape:{type:"aabb",x:u,y:e.y+e.height+l/2,width:e.width+2*a,height:l}}),i&&c.push({id:n+"-ceiling",shape:{type:"aabb",x:u,y:e.y-l/2,width:e.width+2*a,height:l}}),r&&c.push({id:n+"-left-wall",shape:{type:"aabb",x:e.x-a/2,y:d,width:a,height:e.height+2*l}}),s&&c.push({id:n+"-right-wall",shape:{type:"aabb",x:e.x+e.width+a/2,y:d,width:a,height:e.height+2*l}}),c}function Qp(e){const{idPrefix:t="bin",count:n,domainStart:o,domainStep:i,xScale:r,yTop:s,yBottom:a,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,l)}=e,p=[],g=s+(a-s)/2,y=Math.abs(a-s),m=c?n:n-1;if(u||c)for(let e=c?0:1;m>=e;e+=1){if(!u&&e>0&&n>e)continue;const s=r(o+e*i);p.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:g,width:l,height:y}})}if(null!=d)for(let e=0;n>e;e+=1){const n=o+e*i,s=n+i;if(s>=d)continue;const a=r(n),c=r(s);p.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,c)+l/2,y1:h,x2:Math.max(a,c)-l/2,y2:h,thickness:f}})}return p}var Jp=require("d3-quadtree"),eg=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,o,i,r=0){const s=this.ensure(e,t);if(!s)return null;let a=null,l=1/0;const c=Math.max(0,r)+this.maxSearchRadius,u=o-c,d=o+c,h=i-c,f=i+c;return s.visit((e,t,s,c,p)=>{if(u>c||t>d||h>p||s>f)return!0;if(e.length)return!1;let g=e;for(;g;){const e=g.data;if(e){const t=Up(e,o,i,Math.max(0,r));null!=t&&(l>t||t===l&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,l=t)}g=g.next}return!1}),a}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;const n=e.readState();return 0===n.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=n.reduce((e,t)=>Math.max(e,function(e){return"circle"===e.shape.type?e.shape.radius:Math.hypot(e.shape.width,e.shape.height)/2}(t)),0),this.tree=(0,Jp.quadtree)().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},tg=["data","scene-geometry","data-paint","accessibility","evidence"],ng=["scene-geometry","data-paint","accessibility","evidence"],og=["overlay","accessibility","evidence"],ig=(e,t)=>({retainedData:e,invalidations:t}),rg=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sg=["scene-geometry","data-paint","accessibility","evidence"],ag=[],lg={engine:ig("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:ig("preserve",sg),colliders:ig("preserve",sg),sediment:ig("preserve",sg),bodyBudget:ig("preserve",rg),bodyLimit:ig("preserve",rg),eviction:ig("preserve",rg),fixedDt:ig("preserve",ag),maxDeltaSeconds:ig("preserve",ag),maxSubsteps:ig("preserve",ag),settleStepLimit:ig("preserve",ag),timeScale:ig("preserve",ag),observation:ig("preserve",ag)},cg=ig("preserve",rg);function ug(e){let t="preserve";const n=new Set;for(const o of e){const e=lg[o]??cg;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}var dg=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function hg(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&dg.every(n=>e[n]===t[n])}function fg(e,t,n,o){return e||!t?"paused":n||!o?"running":"settled"}var pg=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=function(e){const t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,n){if(n>0)return void(this.seconds=0);const o=e.readState(this.scratch),i=this.speed*this.speed;let r=!0;for(const e of o)if(!e.sleeping&&e.vx*e.vx+e.vy*e.vy>=i){r=!1;break}this.seconds=r?this.seconds+Math.max(0,t):0}},gg=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new eg,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Qn,this.simulationState="settled",this.visible=!0,this.quiescence=new pg;const{bodyBudget:t,colliders:n,engine:o,kernel:i,observation:r,sediment:s,...a}=e;this.config={...Fp,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=o,this.observation=Np(r),this.sediment=new zp(s??!1),this.world=Pp(o,{fixedDt:this.config.fixedDt,...i}),this.quiescence.setKernelOptions(i),n&&this.world.setColliders(Xp(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!hg(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:o,engine:i,kernel:r,observation:s,sediment:a,...l}=e;if(this.config={...this.config,...l},void 0!==o&&(this.bodyBudget=o,!1===o&&(this.bodyBudgetObservationKey="ok")),i&&i!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=i,this.world=Pp(i,e.options),this.world.restore(e),this.revision+=1}if(r&&!hg(r,this.configInput.kernel)){const e=this.world.snapshot(),t={...e.options,...r,gravity:{...e.options.gravity,...r.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}s&&(this.observation=Np(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(Xp(n)),this.revision+=1),this.configInput={...this.configInput,...e};const c=ug(t);this.updateResults.record({kind:"config",keys:t},c.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Xp(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},ug(["colliders"]).invalidations)}enqueue(e,t){const n=Array.isArray(e)?e:[e],o=t?function(e,t={}){const n=Wp(t.startAt)??0,o=t.pacing??"immediate";if("arrival"===o){const o=e.map((e,n)=>function(e,t,n){return"function"==typeof n?Wp(n(e,t)):"string"==typeof n?Wp(Yp(e,n)):Wp(e.spawnAt)??Wp(Yp(e,"arrivalTime"))??Wp(Yp(e,"timestamp"))??Wp(Yp(e,"time"))??Wp(Yp(e,"eventTime"))}(e,n,t.timeAccessor)),i=o.filter(e=>null!=e),r=i.length>0?Math.min(...i):0,s=Wp(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const i=o[t],s=null==i?0:Math.max(0,i-r);return{...Bp(e),spawnAt:n+s/a}})}if("object"==typeof o){const t=Wp(o.ratePerSec);if(t&&t>0)return e.map((e,o)=>({...Bp(e),spawnAt:n+o/t}))}return e.map(e=>({...Bp(e),spawnAt:n}))}(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of o)this.queue.push({...Bp(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Gp),o.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:o.length},o.length?tg:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Bp(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},tg)}materializeDueSpawns(){const e=this.revision,t=[],n=[];return this.spawnDue(t,n),0===t.length||(this.observeBodyBudget(n),this.evictOverflow(n),this.syncSimulationState(n),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?tg:[])),t}clear(){const e=this.world.snapshot().options;this.world.init({...e,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},tg)}tick(e){const t=this.revision,n=[],o=[],i=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,o,i,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}const a=Math.max(0,Math.min(e,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(n,s);const l=this.observeBodyBudget(s),c=this.evictOverflow(s);o.push(...c.evicted),i.push(...c.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,n.length),(u>0||n.length>0||o.length>0||i.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,n,o,i,r,s,void 0,l);return this.updateResults.record({kind:"tick",count:u},this.revision!==t?n.length||o.length||i.length?tg:ng:[]),d}settle(e=this.config.settleStepLimit){return this.runSettle(e,!1).steps}settleWithObservations(e=this.config.settleStepLimit){return this.runSettle(e,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:e=>{this.elapsedSeconds+=e},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>this.observeKernelEvents(e,t),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t){const n=this.revision,o=[],i=[],r=[],s=[],a=t?[]:void 0;if(t&&(this.paused||!this.visible)){const e=this.result(0,o,i,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(o,a);const l=this.observeBodyBudget(a),c=this.evictOverflow(a);i.push(...c.evicted),r.push(...c.sedimented),this.syncSimulationState(a),o.length>0&&this.quiescence.reset();const u=t?{spawned:o,evicted:i,sedimented:r,events:s,observations:a}:{spawned:o},{steps:d,budget:h}=function(e,t,n){let o,i=0;for(;t>i&&(e.queueSize()>0||!e.atRest());){e.advanceTime(e.fixedDt);const t=[];if(e.spawnDue(t,n.observations),t.length>0){n.spawned.push(...t),o=e.observeBodyBudget(n.observations);const i=e.evictOverflow(n.observations);n.evicted?.push(...i.evicted),n.sedimented?.push(...i.sedimented)}e.step(e.fixedDt);const r=e.drainEvents();n.events&&(n.events.push(...r),e.observeKernelEvents(r,n.observations),e.observeSensorTransitions(n.observations)),i+=1,e.refreshQuiescence(e.fixedDt,t.length)}return{steps:i,budget:o}}(this.settleHost(),e,u),f=o.length+i.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,o,i,r,s,a??[],void 0,h??l);return this.updateResults.record({kind:"settle",count:d},this.revision===n?[]:f?tg:ng),p}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return function(e,t={}){const{baselineY:n=0,binWidth:o=24,gap:i=2,maxHeight:r=80,value:s="count",x:a}=t,l=Math.max(1,...e.map(e=>e[s]));return e.map((e,t)=>{const c=Math.max(0,e[s]/l*r),u=a?.(e,t)??t*(o+i);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:u,y:n-c,width:o,height:c,meanX:e.x.mean,meanY:e.y.mean}})}(this.readSediment(),e)}hitTest(e,t,n=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){const{timestamp:t,chartType:n,chartId:o,...i}=e,r={...i,timestamp:t??this.elapsedSeconds,chartType:n??this.observation.chartType,chartId:o??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?og:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?og:[])}remove(e){const t=new Set(e),n=new Set(this.liveBodyOrder),o=new Set(this.queue.map(e=>e.id));this.queue=this.queue.filter(e=>!t.has(e.id)),this.liveBodyOrder=this.liveBodyOrder.filter(e=>!t.has(e)),this.world.remove(e),this.removeActiveSensorPairsForBodies(t);const i=e.filter(e=>n.has(e)||o.has(e));return i.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:i,count:i.length},i.length?tg:[]),i}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},ng),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},ng)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},ng)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,n,o)=>e.applyImpulse(t,n,o),clear:()=>e.clear(),hitTest:(t,n,o)=>e.hitTest(t,n,o),pause:()=>e.setPaused(!0),push:(t,n)=>e.enqueue(t,n),pushMany:(t,n)=>e.enqueue(t,n),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}snapshot(){const e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Hp(this.bodyBudget),config:{...this.config,kernel:Vp(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(qp),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.config={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale},this.configInput={...e.config,bodyBudget:Hp(e.bodyBudget??{}),kernel:Vp(e.world.options)},this.bodyBudget=Hp(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(qp).sort(Gp),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??fg(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping)),this.liveBodyOrder=e.liveBodyOrder.slice(),this.visible=e.visible,this.nextSequence=this.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,this.world.restore(e.world),this.updateResults.record({kind:"restore"},tg)}spawnDue(e,t){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const n=this.queue.shift();if(!n)return;this.spawnOne(n,t),e.push(n.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(const t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});const n=this.world.readState().find(t=>t.id===e.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:e.id,datum:n?.datum??e.datum,x:n?.x??e.x,y:n?.y??e.y},t)}result(e,t,n,o,i,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const l=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:i,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:l,sedimented:o,spawned:t,steps:e}}observeKernelEvents(e,t){!function(e,t,n){if(0===t.length)return;const o=new Map(e.readState().map(e=>[e.id,e]));for(const e of t){if("sleep"!==e.type)continue;const t=o.get(e.bodyId);n.emit({type:"physics-settle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,n){const o=new Set(e.activeSensorPairs().map(e=>`${e.sensorId}\0${e.bodyId}`));if(0===o.size&&0===t.size)return o;const i=new Map(e.readState().map(e=>[e.id,e])),r=(e,t)=>{const{sensorId:o,bodyId:r}=Kp(t),s=n.observation.sensors[o],a=i.get(r);n.emit({type:"enter"===e?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:o,binId:s?.binId??o})};for(const e of Array.from(o).sort())t.has(e)||r("enter",e);for(const e of Array.from(t).sort())o.has(e)||r("exit",e);return o}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(Kp(n).bodyId)&&e.delete(n)}(this.activeSensorPairs,e)}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return function(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),o=t+n,i=Dp(e.bodyLimit),r=Dp(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const o=Dp(n?.warnAt);return null!=o?o:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(i,r,e.options),a=null==i?0:Math.max(0,t-i),l=a>0?"overflow":null==s||s>o?"ok":"warning";return{action:"overflow"!==l?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:i,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:o,queuedBodies:n,state:l,warnAt:s}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){const t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;const n=`${t.state}:${t.action}`;return n===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=n,this.emitObservation({type:"overflow"===t.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:t.action,bodyLimit:t.bodyLimit,engineMaxBodiesHint:t.engineMaxBodiesHint,liveBodies:t.liveBodies,overflow:t.overflow,projectedBodies:t.projectedBodies,queuedBodies:t.queuedBodies,warnAt:t.warnAt},e)),t}syncSimulationState(e){const t=fg(this.paused,this.visible,this.queue.length>0,this.atRest());if(t===this.simulationState)return;const n=this.simulationState;this.simulationState=t,function(e,t,n){n.observation.onSimulationStateChange?.(t,e),"running"!==t&&"settled"!==t||n.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,simulationState:t,previousSimulationState:e})}(n,t,this.observationContext(e))}evictOverflow(e){const{evicted:t,sedimented:n,liveBodyOrder:o}=function(e,t,n,o,i,r){const s={evicted:[],sedimented:[],liveBodyOrder:i};if(!1===n)return s;const a=Math.max(0,Math.floor(o));if(!Number.isFinite(a))return s;const l=i.length-a;if(0>=l)return s;const c=function(e,t,n){if("sleeping-first"!==t)return n.slice();const o=new Map(e.readState().map(e=>[e.id,e.sleeping])),i=[],r=[];for(const e of n)o.get(e)?i.push(e):r.push(e);return[...i,...r]}(e,n,i),u=c.slice(0,l);if(0===u.length)return s;const d=function(e,t,n,o){const i=new Map(e.readState().map(e=>[e.id,e])),r=[];for(const e of n){const n=i.get(e);if(!n)continue;const s=t.add(n);s&&(r.push(e),o.emit({type:"physics-sediment",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:e,datum:n.datum,x:n.x,y:n.y,binId:s.id,count:s.count,total:s.total}))}return r}(e,t,u,r);e.remove(u);const h=new Set(u);return{evicted:u,sedimented:d,liveBodyOrder:i.filter(e=>!h.has(e))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=o,this.removeActiveSensorPairsForBodies(new Set(t))),{evicted:t,sedimented:n}}};var yg=require("d3-scale");function mg(e){const{count:t,idPrefix:n,wallThickness:o,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const l=Math.min(r-1,a?.(t)??s),c=Math.max(1,r-l);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:i(t),y:l+c/2,width:o,height:c}}})}var xg=require("d3-scale");function bg(e){if(Array.isArray(e)&&e.length>=2){const t=Uf(e[0]),n=Uf(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=Uf(t.x),o=Uf(t.y);return null!=n&&null!=o?{x:n,y:o}:null}return null}function vg(e){return Array.isArray(e)?e.map(bg).filter(e=>null!=e):[]}function wg(e,t,n){return"normalized"===n?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Kf(e.x,t.plot.x,t.plot.x+t.plot.width),y:Kf(e.y,t.plot.y,t.plot.y+t.plot.height)}}function kg(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}function Sg(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=Kf(t,0,1)*kg(e);let o=0;for(let t=1;e.length>t;t+=1){const i=e[t-1],r=e[t],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(o+s>=n){const e=(n-o)/s;return{x:i.x+(r.x-i.x)*e,y:i.y+(r.y-i.y)*e}}o+=s}}return{...e[e.length-1]}}function Ag(e,t){const n=Sg(e,Math.max(0,t-.02)),o=Sg(e,Math.min(1,t+.02)),i=o.x-n.x,r=o.y-n.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function Mg(e,t,n){return Math.max(t,Math.min(n,e))}function _g(e,t,n,o,i,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:o,y2:i,thickness:r.thickness??8}}}function Pg(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,o=e.width,i=e.height,{type:"aabb",x:t,y:n,width:o,height:i}),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:e.attributes,onEnter:e.onEnter,onExit:e.onExit};var t,n,o,i}function jg(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...Pg({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function Cg(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function Rg(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,o=qf(n),i=Kf(e.ballRadius??6,2,18),r=e.seed??1,s=Jf(r),a=e.idAccessor,l=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,h=e.radiusAccessor,f=e.groupCompletion??(c?"allAbsorbed":"none"),p=e.springStiffness??.28,g=e.springDamping??.72,y=!0===e.settle,m=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),x=function(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),o=Math.max(1,Math.round(e.height)),i=e.padX??46,r=e.padY??72,s=i,a=n-i,l=r,c=o-Math.max(24,Math.round(.45*r)),u=(l+c)/2,d=Math.max(1,c-l),h=Mg(e.pinchRatio??.18,.06,.5),f=Number(e.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,g=Mg(d*h+p,.06*d,.5*d),y=g/2,m=u-y,x=u+y,b=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,S=e.stages;if(!S.length)throw Error("processStageLayout requires at least one stage");const A=Mg(e.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(e){const t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(S),_=a-s;let P=s;const j=S.map((e,t)=>{const n=P,o=t===S.length-1?a:P+(e.share??1)/M*_;return P=o,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:o,x:(n+o)/2,width:o-n,y:u,height:d}}),C=j[A],R=C.x0,L=C.x1,T=(e,n)=>{if("lane"===t)return"top"===n?l:c;if("funnel"===t){const t=Mg((e-s)/Math.max(1,a-s),0,1);return"top"===n?l+(m-l)*t:c+(x-c)*t}if(R>=e){const t=Mg((e-s)/Math.max(1,R-s),0,1);return"top"===n?l+(m-l)*t:c+(x-c)*t}if(L>=e)return"top"===n?m:x;const o=Mg((e-L)/Math.max(1,a-L),0,1);return"top"===n?m+(l-m)*o:x+(c-x)*o},I=j.map(e=>{const t=Math.min(T(e.x0,"top"),T(e.x1,"top")),n=Math.max(T(e.x0,"bottom"),T(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),$={thickness:k,friction:v,restitution:w},O=[];"lane"===t?O.push(_g(b+"-top",s,l,a,l,$),_g(b+"-bottom",s,c,a,c,$),_g(b+"-left",s,l,s,c,{...$,thickness:Math.max(6,k-2)}),_g(b+"-right",a,l,a,c,{...$,thickness:Math.max(6,k)})):"funnel"===t?O.push(_g(b+"-top",s,l,a,m,$),_g(b+"-bottom",s,c,a,x,$),_g(b+"-left",s,l,s,c,{...$,thickness:Math.max(6,k-2)}),_g(b+"-right",a,m,a,x,{...$,thickness:Math.max(6,k)})):O.push(_g(b+"-left-top",s,l,R,m,$),_g(b+"-left-bottom",s,c,R,x,$),_g(b+"-center-top",R,m,L,m,$),_g(b+"-center-bottom",R,x,L,x,$),_g(b+"-right-top",L,m,a,l,$),_g(b+"-right-bottom",L,x,a,c,$),_g(b+"-left",s,l,s,c,{...$,thickness:Math.max(6,k-2)}),_g(b+"-right",a,l,a,c,{...$,thickness:Math.max(6,k)}));const z=e.membraneDampingScale??.5,D=s,F=Math.max(1,("bowtie"===t?R:a)-D),E=(e.membranes??[]).map(e=>{const t=D+Mg(e.offset,0,1)*F,n=e.width??18+18*e.cost,o=d-16,i=u+.25*(e.wobble??0);return{...e,x:t,y:i,width:n,height:o}}),N=!1===e.includeMembraneRegions?[]:E.map(e=>function(e){const t=e.dampingScale??.5,n=e.energyScale??1,o=Mg(e.cost,0,2);return{...Pg({...e,kind:e.kind??"membrane",attributes:{primitive:"membrane",membraneCost:o,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:o*t,energyDelta:-o*n}}({id:e.id,label:e.label??e.id,description:e.description??(e.label??e.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??z,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:o,padX:i,padY:r,left:s,right:a,topY:l,bottomY:c,midY:u,centerLeft:R,centerRight:L,pinchHeight:g,pinchTop:m,pinchBottom:x,stages:I,membranes:E,colliders:O,regionEffects:N,boundaryY:T}}({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,o.plot.x),padY:Math.max(36,o.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,k=x.stages[0],S=new Set(t.filter(e=>e.absorb).map(e=>e.id)),A=t.map(e=>{const t=v.get(e.id)??k;return function(e,t){const n={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return function(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...Pg({...e,kind:e.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}({...n,kind:e.kind??"sink",force:Cg(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(e.portal){const t=e.portal.force??e.force??{x:-40,y:0};return o={...n,kind:e.kind??"force-field",force:Cg(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:e.portal.targetStageId}},{...Pg({...o,kind:o.kind??"force-field",attributes:{primitive:"portal",targetStage:o.targetStage,..."object"==typeof o.attributes&&o.attributes?o.attributes:{}}}),force:o.force,impulseOnEnter:o.impulseOnEnter,damping:o.damping??.08}}var o;if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return function(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...Pg({...e,kind:e.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping,charge:e.charge??e.capacity}}({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Cg(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...n.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){const t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return function(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,o=e.dampingPerUnit??.12,i=e.energyPerUnit??0;return{...Pg({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*o,energyDelta:i?-t*i:void 0,force:e.force}}({...n,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Cg(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?jg({...n,kind:e.kind??"force-field",force:Cg(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):function(e){return{...Pg({...e,kind:e.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});A.unshift(jg({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));const M=new Map;for(const e of x.stages)M.set(e.id,0);const _=[];e.data.forEach((e,t)=>{const n=(a?Vf(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",o=(Vf(e,t,l)??w)+"",r=b.has(o)?o:w;M.set(r,(M.get(r)??0)+1);const s=c?(Vf(e,t,c)??"")+"":void 0,f=s&&u?(Vf(e,t,u)??s)+"":s,p=d?Uf(Vf(e,t,d))??1:1,g=h?Uf(Vf(e,t,h)):null,y=Kf(null!=g&&g>0?g:i,2,18);_.push({datum:e,id:n,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:y,index:t})});const P=new Map,j=new Map;for(const e of _){if(!e.groupId)continue;const t=P.get(e.groupId)??[];t.push(e.id),P.set(e.groupId,t),e.groupLabel&&j.set(e.groupId,e.groupLabel)}const C=Kf(e.groupAnchorAlong??.55,.15,.9),R=x.left+(x.right-x.left)*C,L=Array.from(P.keys()),T=L.map((e,n)=>{const o=P.get(e)??[],i=L.length>1?x.topY+28+n/Math.max(1,L.length-1)*(x.bottomY-x.topY-56):x.midY;return function(e){const t=e.x??e.anchor?.x??0,n=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}({id:e,label:j.get(e)??e,bodyIds:o,anchor:{x:R,y:i},x:R,y:i,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),I=function(e,t){const n=t instanceof Set?t:new Set(t);return e.map(e=>{const t=e.bodyIds??[],o=t.filter(e=>!n.has(e)),i=t.length-o.length,r=e.completion?.mode??"allMembersAbsorbed",s=e.completion?.valueByBodyId,a=e=>{const t=s?.[e];return Number.isFinite(t)&&Number(t)>=0?Number(t):1},l=t.reduce((e,t)=>e+a(t),0),c=t.reduce((e,t)=>e+(n.has(t)?a(t):0),0),u=e.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0;return{id:e.id,label:e.label??e.id,mode:r,complete:t.length>0&&("anyAbsorbed"===r?i>0:"threshold"===r?c>=(d??l):0===o.length),absorbed:i,total:t.length,absorbedValue:c,totalValue:l,threshold:d,missing:o}})}(T,_.filter(e=>S.has(e.stageId)).map(e=>e.id)),$=new Map(T.map(e=>[e.id,e])),O=_.map((e,t)=>{const n=v.get(e.stageId)??k,o=n.x+(s()-.5)*Math.min(24,.2*n.width),i=x.boundaryY(o,"top")+e.radius+10,r=x.boundaryY(o,"bottom")-e.radius-10,a=r>i?i+s()*Math.max(1,r-i):x.midY,l=y?o:x.left+18+t%7*4,c=y?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:o,y:a},restLength:.45*e.radius,stiffness:p,damping:g}];if(e.groupId){const t=$.get(e.groupId);t?.anchor&&!S.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:l,y:c,vx:y?0:40+40*s(),vy:y?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:y?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),z={kernel:{seed:r,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},D=x.stages.map(e=>({label:e.label??e.id,value:M.get(e.id)??0})),F=t.map(e=>{const t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:M.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:z,initialSpawns:O,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:D,metadata:{kind:"process-flow",plot:o.plot,volume:x,stages:F,groups:T,groupCompletion:I,regionEffects:A}}}var Lg=require("d3-scale");function Tg(e,t,n){return he(e,t,n)}function Ig(e,t){const n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>n&&me(n,e)||"#4e79a7":t=>{if(n){const e=me(n,t);if(e)return e}let o=0;for(let e=0;t.length>e;e++)o=31*o+t.charCodeAt(e)|0;return e[Math.abs(o)%e.length]??"#4e79a7"}}function $g(e,t){const n=t.config??{},o=(t.sensors??[]).map(e=>({...e,sensor:!0})),i=[...t.colliders??[],...o],r=[...e.colliders??[],...n.colliders??[],...i];return{...e,...n,observation:{...e.observation,...n.observation},...r.length>0&&{colliders:r}}}function Og(e){const t=Bg(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function zg(e,t,n,o){return n?"function"==typeof n?n(e,t):e[n]??o:o}function Dg(e){return`gauntlet:${e}:core`}function Fg(e,t){return`gauntlet:${e}:positive:${t}`}function Eg(e,t,n){return`gauntlet:${e}:negative:${t}:${n}`}var Ng={left:28,top:76,rightInset:30,thickness:8};function Bg(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return Ng;const n=Math.max(1,Math.min(e.width,t)),o=Math.max(2,.04*e.width);return{left:o,top:Math.max(2,.08*t),rightInset:o,thickness:Math.max(1,Math.min(4,.04*n))}}function Wg(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function Yg(e,t,n,o){const i=Bg(o),r=Math.max(2,n+2),s=i.top+i.thickness/2+r,a=o.floorY-r,l=(e,t,n)=>t>n?(t+n)/2:Math.max(t,Math.min(n,e));return{x:l(e,i.left+i.thickness/2+r,o.width-i.rightInset-i.thickness/2-r),y:l(t,s,a)}}function qg(e,t,n=1){const o=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,o.indexOf(t));return{angle:.82*-Math.PI+(o.length>1?i/(o.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*n}}function Xg(e,t,n){const o=e.activePositiveIds.reduce((e,n)=>e+(t.get(n)?.value??1),0),i=e.missingPositiveIds.length+e.poppedPositiveIds.length,r=e.negativeIds.reduce((e,t)=>e+(n.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*o-8*r-1.2*e.delay-5*i))}function Hg(e){const t=function(e,t,n){const[o,i]=e,r=220>o||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,l=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,l.length),u=.22*o,d=c>1?(.78*o-u)/(c-1):0,h=r?Math.max(Math.round(.12*o),.08*o+6):Math.max(Math.round(.14*o),110);return{crashY:a-(r?Math.min(n,Math.max(3,.22*i)):n),floorY:a,gates:l.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(r?8:54,Math.round(.07*o))})),graveyardX:Math.round(o*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(o*(r?.82:.92)),startX:h,width:o}}(e.size??[900,520],e.gates,e.crashOffset??30),n=e.positiveProperties??[],o=new Map(n.map(e=>[e.id,e])),i=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),r={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},s=(e.data??[]).map((t,s)=>{const a=function(e,t,n,o,i){const r=zg(e,t,n.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=o.map(e=>e.id),a=[...zg(e,t,n.positiveAccessor,s)],l=[...zg(e,t,n.negativeAccessor,[])].filter(e=>i.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...zg(e,t,n.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(zg(e,t,n.startTimeAccessor,0))||0),stage:"project filed",viability:zg(e,t,n.initialViability,100)}}(t,s,r,n,i);return{...a,viability:e.viability?.(a,{negativeProperties:i,positiveProperties:o})??Xg(a,o,i)}}),a=s.flatMap((n,r)=>{const s=function(e,t,n,o){const i=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(n),r=o?.(e,t,n)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(n,r,t,e.projectPlacement);return function(e,t,n,o,i,r,s){const a=Wg(n),l=Math.max(3,28*a),c=o.startX,u=o.startY+(o.startY===n.routeY?38*t*a:0),d=s?.(e,t,n,o)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...d,id:Dg(e.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??e.startedAt,datum:p}],y=Yg(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,n);g[0].x=y.x,g[0].y=y.y;for(const t of e.activePositiveIds){const o=i.get(t);if(!o)continue;const r=qg(e.activePositiveIds,t,a),s=o.radius??Math.max(2,10*a),l=Yg(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,n);g.push({id:Fg(e.id,t),x:l.x,y:l.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:o.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:o,sourceDatum:e.datum},springs:!1===o.spring?[]:[{target:{type:"body",bodyId:Dg(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...o.spring??{}}]})}return e.negativeIds.forEach((t,o)=>{const i=r.get(t);i&&g.push(function(e,t,n,o,i,r,s){const a=Wg(r),l=t.radius??Math.max(2,7.2*a),c=Yg(o+(n%4*12-12)*a,i+(54+12*Math.floor(n/4))*a,l,r);return{id:Eg(e.id,t.id,n),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Dg(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+n%4*3)*a),...t.spring??{}}]}}(e,i,o,y.x,y.y,n,d.spawnAt??e.startedAt))}),g}(n,r,t,s,o,i,e.coreBody)});return{layout:t,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:Og(t)}}}var Gg=1e-9;function Vg(e,t){return t>e?-1:e>t?1:0}function Ug(e){return{...e}}function Kg(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function Zg(e){const t=Object.fromEntries(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:Ug(t.initialMetrics),metrics:Ug(t.metrics),productIds:[...t.productIds],history:Kg(t.history)}])),n=Object.fromEntries(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:Ug(t.metrics),sourceIds:[...t.sourceIds],history:Kg(t.history)}])),o=Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?Ug(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:n,relations:o,input:{amount:e.input.amount,metrics:Ug(e.input.metrics)},metrics:Ug(e.metrics),loss:{amount:e.loss.amount,metrics:Ug(e.loss.metrics)},history:Kg(e.history)}}function Qg(e,t,n,o,i){return{severity:e,code:t,message:n,path:o,ids:i?[...i]:void 0}}function Jg(e){const t=new Set,n=new Set;for(const o of e)t.has(o)&&n.add(o),t.add(o);return[...n].sort(Vg)}function ey(e,t){return e?Object.entries(e).flatMap(([e,n])=>Number.isFinite(n)?[]:[Qg("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function ty(e,t){for(const[n,o]of Object.entries(t))e[n]=Number(e[n]??0)+o}function ny(e,t,n="selector"){const o=[],i=Object.values(e.components),r=new Set(i.map(e=>e.id)),s=(t.ids??[]).filter(e=>!r.has(e));if(s.length&&o.push(Qg("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,n+".ids",s)),void 0===t.count||Number.isInteger(t.count)&&t.count>=0||o.push(Qg("error","invalid-selector-count","Selector count must be a non-negative integer.",n+".count")),o.some(e=>"error"===e.severity))return{ids:[],diagnostics:o};const a=t.ids?new Set(t.ids):null,l=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null;let d=i.filter(e=>!a||a.has(e.id)).filter(e=>!l||l.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(Vg);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||o.push(Qg("warning","empty-selector","Selector matched no source components.",n)),{ids:d,diagnostics:o}}function oy(e,t,n={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...n}}function iy(e,t){const n={...t,eventId:e.event.id};e.materializations.push(n),e.observations.push({...n,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function ry(e,t,n){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(Qg("error","unknown-outlet",`Unknown outlet "${t}".`,n,[t])),1))}function sy(e,t,n){const o=Jg(t);t.length||e.diagnostics.push(Qg("error","empty-source-list","A product requires at least one source component.",n)),o.length&&e.diagnostics.push(Qg("error","duplicate-source",`Source ids may appear only once: ${o.join(", ")}.`,n,o));const i=t.filter(t=>!e.state.components[t]);i.length&&e.diagnostics.push(Qg("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,n,i));const r=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);r.length&&e.diagnostics.push(Qg("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,n,r));const s=t.filter(t=>"consumed"===e.state.components[t]?.status&&!r.includes(t));return s.length&&e.diagnostics.push(Qg("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,n,s)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function ay(e,t,n,o,i){const r=o?.amount??0;(!Number.isFinite(r)||0>r||r>t+Gg)&&e.diagnostics.push(Qg("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),e.diagnostics.push(...ey(o?.metrics,i+".metrics"));for(const[t,r]of Object.entries(o?.metrics??{}))(0>r||r>Number(n[t]??0)+Gg)&&e.diagnostics.push(Qg("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${i}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function ly(e,t,n,o,i,r,s){return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:r&&void 0!==e.amount?e.amount:n,metrics:r&&e.metrics?{...o,...e.metrics}:o,status:r?"complete":"forming",sourceIds:[...t],outletId:r?e.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 cy(e,t,n,o){void 0!==t.amount&&Math.abs(t.amount-n)>Gg&&e.diagnostics.push(Qg("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${n}.`,o,[t.id]))}function uy(e,t,n){const o=`events.${e.event.id}.effects.${n}`,i=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(Qg("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,o+".state")),e.diagnostics.push(...ey(t.metricsDelta,o+".metricsDelta")),ry(e,t.outletId,o+".outletId");const n=ny(i,t.select,o+".select");e.diagnostics.push(...n.diagnostics);const r=n.ids.filter(e=>i.components[e].productIds.length);if(r.length&&e.diagnostics.push(Qg("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,o+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=oy(e,t,{sourceIds:n.ids,outletIds:t.outletId?[t.outletId]:void 0});for(const e of n.ids){const n=i.components[e];n.status=t.state,n.outletId=t.outletId,n.reason=t.reason,t.metricsDelta&&ty(n.metrics,t.metricsDelta),n.history.push(s)}return i.history.push(s),void(n.ids.length&&iy(e,{type:"retarget-component",sourceIds:n.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){const{relation:n}=t;n.id&&!i.relations[n.id]||e.diagnostics.push(Qg("error","duplicate-relation",`Relation id "${n.id}" is missing or already active.`,o+".relation.id",[n.id]));const r=function(e,t,n){const o=Jg(t),i=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(Qg("error","insufficient-relation-sources","A relation requires at least two source components.",n)),o.length&&e.diagnostics.push(Qg("error","duplicate-source",`Relation source ids must be unique: ${o.join(", ")}.`,n,o)),i.length&&e.diagnostics.push(Qg("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,n,i)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,n.sourceIds,o+".relation.sourceIds");if(e.diagnostics.push(...ey(n.metrics,o+".relation.metrics")),!r||e.diagnostics.some(e=>"error"===e.severity))return;i.relations[n.id]={...n,sourceIds:[...n.sourceIds],metrics:n.metrics?{...n.metrics}:void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};const s=oy(e,t,{sourceIds:[...n.sourceIds],relationIds:[n.id]});return i.history.push(s),void iy(e,{type:"activate-relation",sourceIds:[...n.sourceIds],relationIds:[n.id]})}if("resolve-relation"===t.type){const n=Jg(t.relationIds),r=t.relationIds.filter(e=>!i.relations[e]),s=t.relationIds.filter(e=>"resolved"===i.relations[e]?.status);if(n.length&&e.diagnostics.push(Qg("error","duplicate-relation","Relation ids must be unique.",o+".relationIds",n)),r.length&&e.diagnostics.push(Qg("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,o+".relationIds",r)),s.length&&e.diagnostics.push(Qg("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,o+".relationIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const n of t.relationIds){const o=i.relations[n];o.status="resolved",o.resolution=t.resolution,o.resolvedByEventId=e.event.id,o.resolvedAt=e.context.appliedAt,o.reason=t.reason}const a=oy(e,t,{relationIds:[...t.relationIds]});return i.history.push(a),void iy(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){const n=e.productDefinitions.get(t.productId);n||e.diagnostics.push(Qg("error","unknown-product",`Product "${t.productId}" has no declared mold.`,o+".productId",[t.productId]));const r=i.products[t.productId];"combine"===t.type&&r&&e.diagnostics.push(Qg("error","duplicate-product",`Product "${t.productId}" has already been formed.`,o+".productId",[t.productId])),"contribute"!==t.type||r&&"forming"===r.status||e.diagnostics.push(Qg("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,o+".productId",[t.productId]));const s=sy(e,t.sourceIds,o+".sourceIds"),a="contribute"===t.type&&r?[...r.sourceIds,...t.sourceIds]:t.sourceIds,l=function(e,t,n,o){if(!t?.length)return[];const i=Jg(t),r=t.filter(t=>!e.state.relations[t]),s=t.filter(t=>"resolved"===e.state.relations[t]?.status),a=new Set(n),l=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!a.has(e)));return i.length&&e.diagnostics.push(Qg("error","duplicate-relation","Basis relations must be unique.",o,i)),r.length&&e.diagnostics.push(Qg("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,o,r)),s.length&&e.diagnostics.push(Qg("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,o,s)),l.length&&e.diagnostics.push(Qg("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,o,l)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,a,o+".basisRelationIds");if(!s||!l||!n||e.diagnostics.some(e=>"error"===e.severity))return;const c=s.reduce((e,t)=>e+t.amount,0),u=function(e){const t={};for(const n of e)ty(t,n.metrics);return t}(s);if(!ay(e,c,u,t.loss,o+".loss"))return;const d=c-(t.loss?.amount??0);!function(e,t,n){e.state.loss.amount+=n?.amount??0;for(const[o,i]of Object.entries(n?.metrics??{}))t[o]=Number(t[o]??0)-i,e.state.loss.metrics[o]=Number(e.state.loss.metrics[o]??0)+i}(e,u,t.loss);const h="combine"===t.type&&!1!==t.complete,f=oy(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});let p;if("combine"===t.type){if(h&&cy(e,n,d,o+".productId"),p=ly(n,t.sourceIds,d,u,e,h,f),h&&!ry(e,p.outletId,o+".productId"))return;i.products[t.productId]=p}else p=r,p.sourceIds.push(...t.sourceIds),p.amount+=d,ty(p.metrics,u),p.history.push(f);for(const e of s)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(f);return i.history.push(f),function(e,t){if(t.length){for(const n of t)n.status="resolved",n.resolution="combined",n.resolvedByEventId=e.event.id,n.resolvedAt=e.context.appliedAt;iy(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,l),iy(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:p.outletId?[p.outletId]:void 0}),void(h&&iy(e,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===t.type){const n=i.products[t.productId];return n?void function(e,t,n,o,i,r){const s=e.productDefinitions.get(t.id),a=n??s?.outletId??(e.outletIds.has("product")?"product":void 0);if(!ry(e,a,r+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(Qg("error","product-already-complete",`Product "${t.id}" is already complete.`,r,[t.id]));s&&(cy(e,s,t.amount,r+".productId"),void 0!==s.amount&&(t.amount=s.amount),s.metrics&&(t.metrics={...t.metrics,...s.metrics})),t.status="complete",t.outletId=a,t.reason=o,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;const l=oy(e,i,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0});t.history.push(l),e.state.history.push(l),iy(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0})}(e,n,t.outletId,t.reason,t,o):void e.diagnostics.push(Qg("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,o+".productId",[t.productId]))}if("split"===t.type){const n=sy(e,[t.sourceId],o+".sourceId");t.products.length||e.diagnostics.push(Qg("error","empty-split","A split requires at least one product allocation.",o+".products"));const r=t.products.map(e=>e.productId),s=Jg(r);s.length&&e.diagnostics.push(Qg("error","duplicate-product","Split product ids must be unique.",o+".products",s));const a=r.map(t=>e.productDefinitions.get(t)),l=r.filter((e,t)=>!a[t]),c=r.filter(e=>i.products[e]);l.length&&e.diagnostics.push(Qg("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,o+".products",l)),c.length&&e.diagnostics.push(Qg("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,o+".products",c));for(const[n,i]of t.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||e.diagnostics.push(Qg("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${o}.products.${n}.amount`)),e.diagnostics.push(...ey(i.metrics,`${o}.products.${n}.metrics`));if(!n?.length||e.diagnostics.some(e=>"error"===e.severity))return;const u=n[0];if(!ay(e,u.amount,u.metrics,t.loss,o+".loss"))return;const d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??a[t]?.amount),f=h.filter(e=>void 0!==e).length;if(0!==f&&f!==h.length)return void e.diagnostics.push(Qg("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",o+".products"));const p=f?h:t.products.map(()=>d/t.products.length),g=p.reduce((e,t)=>e+t,0);if(Math.abs(g-d)>Gg)return void e.diagnostics.push(Qg("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,o+".products"));const y={...u.metrics};for(const[e,n]of Object.entries(t.loss?.metrics??{}))y[e]=Number(y[e]??0)-n;const m=oy(e,t,{sourceIds:[u.id],productIds:r});if(t.products.forEach((n,r)=>{const s=a[r],l=d>Gg?p[r]/d:1/t.products.length,c=Object.fromEntries(Object.entries(y).map(([e,t])=>[e,t*l])),h=n.metrics??s.metrics??c,f=ly({...s,amount:p[r],metrics:h},[u.id],p[r],{...h},e,!0,m);ry(e,f.outletId,`${o}.products.${r}.productId`)&&(i.products[f.id]=f)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=t.loss?.amount??0;for(const[e,n]of Object.entries(t.loss?.metrics??{}))i.loss.metrics[e]=Number(i.loss.metrics[e]??0)+n;i.history.push(m),iy(e,{type:"split-source",sourceIds:[u.id],productIds:r});for(const t of r)iy(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:i.products[t].outletId?[i.products[t].outletId]:void 0});return}if("eject"===t.type){ry(e,t.outletId,o+".outletId");const n=ny(i,t.select,o+".select");e.diagnostics.push(...n.diagnostics);const r=n.ids.filter(e=>i.components[e].productIds.length);if(r.length&&e.diagnostics.push(Qg("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,o+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=oy(e,t,{sourceIds:n.ids,outletIds:[t.outletId]});for(const e of n.ids){const n=i.components[e];n.status=t.state??"ejected",n.outletId=t.outletId,n.reason=t.reason,n.history.push(s)}return i.history.push(s),void(n.ids.length&&iy(e,{type:"retarget-component",sourceIds:n.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...ey(t.metricsDelta,o+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let n,r;if("run"===t.target)ty(i.metrics,t.metricsDelta);else if("components"in t.target){const r=ny(i,t.target.components,o+".target.components");if(e.diagnostics.push(...r.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;n=r.ids;for(const e of r.ids)ty(i.components[e].metrics,t.metricsDelta)}else{r=[...t.target.productIds];const n=Jg(r),s=r.filter(e=>!i.products[e]);if(n.length&&e.diagnostics.push(Qg("error","duplicate-product","Metric target product ids must be unique.",o+".target.productIds",n)),s.length&&e.diagnostics.push(Qg("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,o+".target.productIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const e of r)ty(i.products[e].metrics,t.metricsDelta)}return void i.history.push(oy(e,t,{sourceIds:n,productIds:r}))}t.outcome.trim()?(i.outcome=t.outcome,i.summary=t.summary,i.history.push(oy(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(Qg("error","invalid-outcome","Outcome must be a non-empty string.",o+".outcome"))}function dy(e,t,n){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[Qg("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};const o=Zg(e),i={state:o,event:t,context:n,productDefinitions:new Map(n.products.map(e=>[e.id,e])),outletIds:new Set(n.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(const[n,o]of t.effects.entries())if(uy(i,o,n),i.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:i.diagnostics};return o.elapsed=Math.max(o.elapsed,n.appliedAt),o.phaseId=n.phaseId,o.eventsApplied.push(t.id),i.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:n.phaseId,authoredAt:n.authoredAt,appliedAt:n.appliedAt}),{applied:!0,state:o,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var hy=[900,520],fy=[{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}],py=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),gy=1e-9;function yy(e,t){return t>e?-1:e>t?1:0}function my(e,t,n,o,i){return{severity:e,code:t,message:n,path:o,ids:i?[...i]:void 0}}function xy(e){const t=new Set,n=new Set;for(const o of e)t.has(o)&&n.add(o),t.add(o);return[...n].sort(yy)}function by(e){const t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function vy(e,t,n,o,i,r){if(!n)return o;try{return("function"==typeof n?n(e,t):e[n])??o}catch(e){return i.push(my("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,r)),o}}function wy(e,t,n){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(my("error","invalid-metrics","Metrics must be a numeric object.",n)),{};const o={};for(const[i,r]of Object.entries(e)){const e=by(r);null!=e?o[i]=e:t.push(my("error","invalid-metric",`Metric "${i}" must be finite.`,`${n}.${i}`))}return o}function ky(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Sy(e){const{id:t,orientation:n,fixed:o,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=e,u=function(e,t,n){const o=n.map(([n,o])=>[Math.max(e,Math.min(n,o)),Math.min(t,Math.max(n,o))]).filter(([e,t])=>t>e+gy).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),i=[];let r=e;for(const[e,t]of o)e>r+gy&&i.push([r,e]),r=Math.max(r,t);return t>r+gy&&i.push([r,t]),i}(i,r,s);return u.map(([e,i],r)=>({id:1===u.length?t:`${t}:${r}`,friction:l,restitution:c,shape:"horizontal"===n?{type:"segment",x1:e,y1:o,x2:i,y2:o,thickness:a}:{type:"segment",x1:o,y1:e,x2:o,y2:i,thickness:a}}))}function Ay(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function My(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?Ay(e):1}function _y(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:My(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Py(e){return"crucible:component:"+encodeURIComponent(e)}function jy(e,t,n,o){if(void 0!==n&&Number.isFinite(n)&&n>0)return n;const i=Math.min(...t,e),r=Math.max(...t,e);return r-i>gy?o[0]+(o[1]-o[0])*Math.sqrt(Math.max(0,e-i)/(r-i)):(o[0]+o[1])/2}function Cy(e,t){const n=Math.max(.25,Math.min(1,t.width/900,t.height/520)),o=e?.[0]??7*n,i=e?.[1]??18*n,r=Math.max(1,Math.min(o,i));return[r,Math.max(r,Math.max(o,i))]}function Ry(e,t){if(!e)return[];const n=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),o=Math.max(1,Math.ceil(e/n));return Array.from({length:e},(e,i)=>({x:t.x+t.width/n*(i%n+.5),y:t.y+(Math.floor(i/n)+.5)*(t.height/o)}))}function Ly(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function Ty(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function Iy(e,t,n={}){const o=Object.values(e.products).sort((e,t)=>yy(e.id,t.id)),i=Object.values(e.components).sort((e,t)=>yy(e.id,t.id)),r=[...i.map(e=>e.amount),...o.map(e=>e.amount)],s=Cy(n.radiusRange,t),a=function(e,t){const n=new Map;for(const t of e){const e=t.outletId??"__chamber__",o=n.get(e)??[];o.push(t),n.set(e,o)}const o=new Map;for(const[e,i]of n){i.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||yy(e.id,t.id));const n=Ry(i.length,Ty(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>o.set(e.id,n[t]))}return o}(o,t),l=o.map(e=>{const o=a.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},i=1.28*jy(e.amount,r,n.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:(c=e.id,"crucible:product:"+encodeURIComponent(c)),x:o.x,y:o.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const e of i.filter(e=>!e.productIds.length)){const t=Ly(e)??"__chamber__",n=c.get(t)??[];n.push(e),c.set(t,n)}const u=new Map;for(const[e,n]of c){const o=Ry(n.length,Ty(t,"__chamber__"===e?void 0:e));n.forEach((e,t)=>u.set(e.id,o[t]))}return[...i.map(e=>{let o=u.get(e.id);if(e.productIds.length){const n=e.productIds.map(e=>a.get(e)).filter(e=>!!e);if(n.length){o={x:n.reduce((e,t)=>e+t.x,0)/n.length,y:n.reduce((e,t)=>e+t.y,0)/n.length};const i=Ay(e.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*t.width));o={x:o.x+Math.cos(i)*r,y:o.y+Math.sin(i)*r}}}o??(o={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});const i=jy(e.amount,r,n.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Py(e.id),x:o.x,y:o.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var $y=Iy;function Oy(e){return Array.isArray(e)?e.map(Oy):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>yy(e,t)).map(([e,t])=>[e,Oy(t)])):e}function zy(e,t=e.duration){const n=function(e,t){const n=by(t)??0,o=Math.max(0,Math.min(e.duration,n));if(!e.phases.length)return{elapsed:o,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=o>=e.duration-gy,r=i?e.phases[e.phases.length-1]:e.phases.find(e=>o>=e.start&&e.end>o)??e.phases[0];return{elapsed:o,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,o-r.start),complete:i}}(e,t);let o=Zg(e.initialState);const i=[],r=[],s=[];for(const t of e.events){if(t.authoredAt>n.elapsed+gy)break;const a=dy(o,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(o=a.state)}return o.elapsed=n.elapsed,o.phaseId=n.phaseId,o.phaseIndex=n.phaseIndex,o.phaseElapsed=n.phaseElapsed,o.complete=n.complete,n.complete&&"in_process"===o.outcome&&(o.outcome="complete"),o.playing=!1,{state:o,diagnostics:i,materializations:r,observations:s}}function Dy(e){const t=function(e){const t=[];e.length||t.push(my("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const n=xy(e.map(e=>e.id));n.length&&t.push(my("error","duplicate-phase-id",`Phase ids must be unique: ${n.join(", ")}.`,"phases",n));let o=0;return{phases:e.map((e,n)=>{const i=by(e.duration),r=null!=i&&i>0?i:0;e.id.trim()||t.push(my("error","invalid-phase-id","Phase ids may not be empty.",`phases.${n}.id`)),null!=i&&i>0||t.push(my("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${n}.duration`,[e.id])),void 0===e.intensity||Number.isFinite(e.intensity)||t.push(my("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${n}.intensity`,[e.id]));const s={...e,duration:r,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:n,start:o,end:o+r};return o=s.end,s}),diagnostics:t}}(e.phases),n=t.phases.at(-1)?.end??0,o=ky(e.outlets??fy),i=(e.products??[]).map(e=>({...e,metrics:e.metrics?{...e.metrics}:void 0})),r=function(e,t,n){const o=[],i=xy(e.map(e=>e.id));i.length&&o.push(my("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return e.forEach((e,i)=>{let s,a,l;if(e.id.trim()||o.push(my("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in e.at&&void 0!==e.at.time){const r=by(e.at.time);if(null==r||0>r||r>n+gy)return void o.push(my("error","event-time-out-of-range",`Event time must fall between 0 and ${n}.`,`events.${i}.at.time`,[e.id]));s=Math.max(0,Math.min(n,r));const c=function(e,t,n){const o=e.find(e=>gy>=Math.abs(e.start-n));if(o)return{phase:o,boundaryRank:1};const i=e.find(e=>n>=e.start&&e.end>n);return i?{phase:i,boundaryRank:0}:gy>=Math.abs(n-t)&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,n,s);a=c.phase,l=c.boundaryRank}else{if(a=t.find(t=>t.id===e.at.phaseId),!a)return void o.push(my("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${i}.at.phaseId`,[e.id,e.at.phaseId]));const n=e.at.progress??0;if(!Number.isFinite(n)||0>n||n>1)return void o.push(my("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[e.id]));s=a.start+a.duration*n,l=0===n?1:0}a?r.push({...e,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):o.push(my("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[e.id]))}),r.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:r,diagnostics:o}}(e.events??[],t.phases,n),s=function(e){const t=[],n={},o=[];let i=0;const r={};e.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((vy(s,a,e.idAccessor,l,t,`data.${a}.id`)??l)+"").trim();if(!c)return void t.push(my("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));o.push(c);const u=by(vy(s,a,e.amountAccessor,1,t,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&t.push(my("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=wy(vy(s,a,e.metricsAccessor,{},t,`data.${a}.metrics`),t,`data.${a}.metrics`),f=vy(s,a,e.initialStateAccessor,"active",t,`data.${a}.status`),p=py.has(f)?f:"active";py.has(f)||t.push(my("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[c]));const g=vy(s,a,e.labelAccessor,(s.label??s.name??c)+"",t,`data.${a}.label`)+"",y=vy(s,a,e.categoryAccessor,"component",t,`data.${a}.category`)+"";n[c]||(n[c]={id:c,label:g,category:y,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},i+=d,function(e,t){for(const[n,o]of Object.entries(t))e[n]=Number(e[n]??0)+o}(r,h))});const s=xy(o);s.length&&t.push(my("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=wy(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:n,products:{},relations:{},input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:t}}(e),a=function(e=hy,t=fy){const n=Math.max(1,by(e[0])??900),o=Math.max(1,by(e[1])??520),i=360>n||260>o,r=i?Math.max(4,.035*Math.min(n,o)):20,s=i?Math.max(10,.075*o):34,a={x:r,y:r,width:Math.max(1,n-2*r),height:s},l=i?Math.max(16,.14*o):Math.min(78,.16*o),c={x:r,y:o-r-l,width:Math.max(1,n-2*r),height:l},u=i?Math.max(12,.08*n):Math.min(150,.17*n),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),f={x:u,y:d,width:Math.max(24,n-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,i?84:180)),g={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},y=ky(t),m={left:y.filter(e=>"left"===(e.side??"bottom")),right:y.filter(e=>"right"===e.side),bottom:y.filter(e=>"bottom"===(e.side??"bottom"))},x=[],b=(e,t)=>{const o=Math.max(8,u-1.5*r),s=f.height/Math.max(1,t.length);t.forEach((t,a)=>{x.push({...t,side:e,x:"left"===e?r:n-r-o,y:f.y+a*s,width:o,height:Math.max(8,s-(i?2:8))})})};b("left",m.left),b("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((e,t)=>{x.push({...e,side:"bottom",x:f.x+t*v,y:f.y+f.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-f.y-f.height-(i?4:12))})}),x.sort((e,t)=>y.findIndex(t=>t.id===e.id)-y.findIndex(e=>e.id===t.id)),{width:n,height:o,phaseRail:a,chamber:f,mouth:g,projection:c,outlets:x}}(e.size??hy,o),l=function(e){const{chamber:t,mouth:n}=e,o=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),i=Math.max(t.x,n.x),r=Math.min(t.x+t.width,n.x+n.width),s={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:i,y2:t.y,thickness:o}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:o}}];a.push(...Sy({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:s.left.map(e=>[e.y,e.y+e.height]),thickness:o,friction:.46,restitution:.12}),...Sy({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:s.right.map(e=>[e.y,e.y+e.height]),thickness:o,friction:.46,restitution:.12}),...Sy({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:s.bottom.map(e=>[e.x,e.x+e.width]),thickness:o,friction:.5,restitution:.08}));for(const t of e.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(t.id),sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return a}(a),c=function(e,t){const n=[],o=new Set(t.map(e=>e.id)),i=xy(t.map(e=>e.id)),r=xy(e.map(e=>e.id));return i.length&&n.push(my("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&n.push(my("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),t.forEach((e,t)=>{e.id.trim()||n.push(my("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0===e.order||Number.isFinite(e.order)||n.push(my("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||n.push(my("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0===e.amount||Number.isFinite(e.amount)&&e.amount>=0||n.push(my("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0===e.outletId||o.has(e.outletId)||n.push(my("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),wy(e.metrics??{},n,`products.${t}.metrics`)}),n}(i,o),u=(d={seed:e.seed??1,components:Object.values(s.state.components).sort((e,t)=>yy(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:n,description:o,intensity:i,motion:r,color:s,metrics:a})=>({id:e,duration:t,label:n,description:o,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:o,events:r.events.map(({id:e,label:t,description:n,summary:o,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:e,label:t,description:n,summary:o,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(Oy(d)));var d;const h=function(e,t,n={}){const o=Object.values(e.components).sort((e,t)=>yy(e.id,t.id)),i=o.map(e=>e.amount),r=Cy(n.radiusRange,t),s=function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(My(n.seed)),a=t.mouth.x+t.mouth.width/2,l=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return o.map((e,t)=>{const d=t/Math.max(1,o.length)*Math.PI*2+.18*(s()-.5),h=jy(e.amount,i,n.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Py(e.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(s.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),f=[...t.diagnostics,...r.diagnostics,...s.diagnostics,...c],p={phases:t.phases,events:r.events,products:i,outlets:o,duration:n,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:_y(e.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},g=zy(p),y=Object.values(g.state.products).filter(e=>"forming"===e.status).map(e=>e.id),m=y.length?[my("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return p.terminalState=g.state,p.terminalSpawns=$y(g.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p.diagnostics=[...f,...g.diagnostics,...m],p}var Fy=g(require("react")),Ey=require("react/jsx-runtime");function Ny(e){return Number.isFinite(e)?1e3>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):e.toLocaleString():"0"}function By(e,t,n,o){const i=e.datum;if(!i?.__crucible)return;const r="circle"===e.shape.type?e.shape.radius:8,s="string"==typeof t.fill?t.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof t.stroke?t.stroke:"#26323a",l="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=o?`${o}-crucible-body-${n}`:"crucible-body-"+n;if("product"===i.kind){const t=Array.from({length:6},(t,n)=>{const o=-Math.PI/2+n/6*Math.PI*2;return`${e.x+Math.cos(o)*r},${e.y+Math.sin(o)*r}`}).join(" "),n=u+"-glow";return(0,Ey.jsxs)(Fy.Fragment,{children:[(0,Ey.jsx)("defs",{children:(0,Ey.jsx)("filter",{id:n,x:"-60%",y:"-60%",width:"220%",height:"220%",children:(0,Ey.jsx)("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),(0,Ey.jsx)("polygon",{points:t,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${n})`}),(0,Ey.jsx)("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return(0,Ey.jsxs)(Fy.Fragment,{children:[(0,Ey.jsx)("circle",{cx:e.x,cy:e.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),(0,Ey.jsx)("circle",{cx:e.x-.25*r,cy:e.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}var Wy=require("react/jsx-runtime"),Yy="var(--semiotic-text, #26323a)",qy="var(--semiotic-text-secondary, #6c7377)",Xy="var(--semiotic-primary, #b8792d)",Hy="var(--semiotic-danger, #9f3d35)",Gy="var(--semiotic-success, #356b63)";function Vy(e){const{x:t,y:n,width:o,height:i}=e.chamber,r=Math.min(.14*o,48),s=n+i;return[`M ${t} ${n}`,`L ${t+r} ${s-.16*i}`,`Q ${t+o/2} ${s+.1*i} ${t+o-r} ${s-.16*i}`,`L ${t+o} ${n}`].join(" ")}function Uy({layout:e,phases:t,state:n,compact:o=!1}){const i=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return(0,Wy.jsxs)("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[(0,Wy.jsxs)("defs",{children:[(0,Wy.jsxs)("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,Wy.jsx)("stop",{offset:"0",stopColor:Xy,stopOpacity:"0.03"}),(0,Wy.jsx)("stop",{offset:"0.66",stopColor:Xy,stopOpacity:"0.1"}),(0,Wy.jsx)("stop",{offset:"1",stopColor:Hy,stopOpacity:"0.18"})]}),(0,Wy.jsx)("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:(0,Wy.jsx)("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Yy,strokeOpacity:"0.08",strokeWidth:"1"})})]}),(0,Wy.jsx)("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:Yy,strokeOpacity:"0.52",strokeWidth:o?1:2.2}),(0,Wy.jsx)("path",{d:Vy(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),(0,Wy.jsx)("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:Yy,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:o?2:5}),o?null:(0,Wy.jsx)("g",{"data-testid":"crucible-phase-rail",children:t.map((o,r)=>{const s=t.slice(0,r).reduce((e,t)=>e+Math.max(0,t.duration),0),a=e.phaseRail.x+s/i*e.phaseRail.width,l=Math.max(0,o.duration)/i*e.phaseRail.width,c=o.id===n.phaseId,u=n.phaseIndex>r||n.complete;return(0,Wy.jsxs)("g",{children:[(0,Wy.jsx)("rect",{x:a,y:e.phaseRail.y,width:Math.max(1,l-2),height:e.phaseRail.height,rx:2,fill:c?o.color??Xy:u?Gy:Yy,fillOpacity:c?.68:u?.28:.09}),46>l?null:(0,Wy.jsx)("text",{x:a+l/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?Yy:qy,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(o.label??o.id).toUpperCase()})]},o.id)})}),e.outlets.map(e=>(0,Wy.jsxs)("g",{children:[(0,Wy.jsx)("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?Hy:Gy),fillOpacity:"0.1",stroke:e.color??("left"===e.side?Hy:Gy),strokeDasharray:"3 3",strokeOpacity:"0.62"}),o?null:(0,Wy.jsx)("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:qy,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function Ky({rows:e,layout:t,projection:n,amountLabel:o}){if(!e.length)return null;const i=n.measure??"count",r=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,i))),s=Math.max(1,...r),a=t.projection.width/Math.max(1,e.length),l=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-l-5);return(0,Wy.jsx)("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,n)=>{const u=r[n],d=Math.max(u>0?2:0,u/s*c),h=t.projection.x+n*a+.18*a;return(0,Wy.jsxs)("g",{children:[(0,Wy.jsx)("rect",{x:h,y:t.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?Hy:"complete"===e.status?Xy:Gy,fillOpacity:"0.68"}),l>4&&a>=34?(0,Wy.jsxs)(Wy.Fragment,{children:[(0,Wy.jsx)("text",{x:h+.32*a,y:t.projection.y+c+10,fill:qy,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),(0,Wy.jsxs)("text",{x:h+.32*a,y:t.projection.y+c+19,fill:Yy,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Ny(u),"amount"===i&&o?" "+o:""]})]}):null]},e.key)})})}function Zy(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Qy(e){return e.map(e=>({...e,spawnAt:void 0}))}function Jy(e,t){return e?t?n=>Yf.createElement(Yf.Fragment,null,e,"function"==typeof t?t(n):t):e:t}var em=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function tm(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return em[(t>>>0)%em.length]}var nm={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,n,o,i)=>({chartType:"line",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||t,colorAccessor:t,...o,showAxes:!1,margin:o.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:cd,LineChart:dd,AreaChart:fd,DifferenceChart:pd,StackedAreaChart:gd,Scatterplot:md,CandlestickChart:yd,BubbleChart:ld,ConnectedScatterplot:bd,QuadrantChart:xd,Heatmap:vd,TemporalHistogram:hd,XYCustomChart:{frameType:"xy",buildProps:(e,t,n,o,i)=>({chartType:"custom",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:o.showLegend??!!t})},BarChart:Ed,StackedBarChart:Nd,GroupedBarChart:Bd,PieChart:Wd,DonutChart:Yd,Histogram:qd,BoxPlot:Xd,ViolinPlot:Hd,SwarmPlot:Gd,DotPlot:Vd,SwimlaneChart:Ud,RidgelinePlot:Kd,LikertChart:Zd,FunnelChart:Qd,GaugeChart:Jd,OrdinalCustomChart:{frameType:"ordinal",buildProps:(e,t,n,o,i)=>({chartType:"custom",data:e,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:t,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:Rf,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,n,o,i)=>({chartType:"force",nodes:i.nodes||e||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:t,colorScheme:n,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...o})},SankeyDiagram:Tf,ProcessSankey:Lf,ChordDiagram:If,TreeDiagram:$f,Treemap:Of,CirclePack:zf,ChoroplethMap:Nf,ProportionalSymbolMap:Bf,FlowMap:Wf,GeoCustomChart:{frameType:"geo",buildProps:(e,t,n,o,i)=>({points:i.points||e||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:t,colorScheme:n,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...o})},GaltonBoardChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[600,400],s=i.bins??21,a=i.seed??1,l=Math.max(1,Math.round(i.pegRows??s-1)),c="mechanical"===i.mode,u=c?function(e){const t=Math.max(2,Math.round(e.bins)),n=Math.max(1,Math.round(e.pegRows??t-1)),o=Math.max(1,Math.round(e.count??Math.max(64,4*t))),i=Kf(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Jf(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:o},(e,t)=>{let o=0;for(let e=0;n>e;e+=1)r()<i&&(o+=1);const a=n/2;return{id:`${s}-${t}`,value:o,mechanical:!0,pegRows:n,branchProbability:i,pathRights:o,side:a>o?"left":o>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:l,seed:a}):Array.isArray(e)?e:[],d=function(e){const{data:t,valueAccessor:n,bins:o,ballRadius:i,seed:r,size:s,valueExtent:a}=e,l=qf(s),c=t.map((e,t)=>Uf(Vf(e,t,n))).filter(e=>null!=e),u=function(e){if(!e)return;const t=Uf(e[0]),n=Uf(e[1]);return null!=t&&null!=n?t>n?[n,t]:[t,n]:void 0}(a),d=u?.[0]??(c.length?Math.min(...c):0),h=u?.[1]??(c.length?Math.max(...c):1),f=h===d?1:h-d,p=(0,ep.scaleLinear)().domain([0,o]).range([l.plot.x,l.plot.x+l.plot.width]),g=Array.from({length:o},()=>0),y=[];t.forEach((e,t)=>{const r=Uf(Vf(e,t,n));if(null==r)return;const s=Math.max(0,Math.min(o-1,Math.floor((r-d)/f*o)));g[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:p(s+.5),y:l.plot.y+i+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...e,value:r,bin:s}})});const m=l.plot.y+l.plot.height;return{config:Gf(r,[...Zp({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Qp({idPrefix:"galton-bin",count:o,domainStart:0,domainStep:1,xScale:p,yTop:l.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:g.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:o,plot:l.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:c?[0,l]:void 0});return{...o,config:d.config,initialSpawns:Qy(d.initialSpawns),projectionRows:d.projectionRows,bodyStyle:Hf(t||i.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[600,400],s=function(e){const{data:t,timeAccessor:n,arrivalAccessor:o,windows:i,watermark:r,ballRadius:s,seed:a,size:l,timeExtent:c,timeScale:u=1}=e,d=qf(l),h=t.map((e,t)=>Uf(Vf(e,t,n))).filter(e=>null!=e),f=Uf(c?.[0]),p=Uf(c?.[1]),g=h.length?Math.min(...h):0,y=h.length?Math.max(...h):g+i.size,m=Math.min(f??g,g),x=Math.max(p??y,y),b=Math.floor(m/i.size)*i.size,v=Math.max(1,Math.ceil((x-b+i.size)/i.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Uf(r?.value)??w-(r?.delay??i.size),S=Math.max(0,Math.min(v,Array.from({length:v},(e,t)=>t).reduce((e,t)=>b+(t+1)*i.size>k?e:e+1,0))),A=function(e,t){const n=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:n,height:e.plot.height},windowPlot:{x:e.plot.x+n,y:e.plot.y,width:Math.max(40,e.plot.width-n),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(d,s),M=b+v*i.size,_=(0,yg.scaleLinear)().domain([b,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),j=[];t.forEach((e,t)=>{const r=Uf(Vf(e,t,n));if(null==r)return;const a=Uf(Vf(e,t,o))??r,l=Math.max(0,Math.min(v-1,Math.floor((r-b)/i.size))),c=k>=b+(l+1)*i.size;P[l].value+=c?0:1,P[l].secondary+=c?1:0,j.push({id:(e.id??"event-"+t)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...e,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const C=d.plot.y+d.plot.height,R=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const o=e.windowStart,i=e.windowStart+e.windowCount*e.windowSize,r=(0,yg.scaleLinear)().domain([o,i]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+n*e.windowSize),a=e.windowPlot.x,l=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),c=e=>s===a?t:l+(e-a)/(s-a)*(t-l),u=[];for(let t=0;n>t;t+=1){const n=e.windowStart+t*e.windowSize,o=n+e.windowSize,i=r(n),s=r(o);u.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:i,y1:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:A.gutter,plot:d.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:i.size,windowStart:b},d.plot.y+.28*d.plot.height);return{config:Gf(a,[...Zp({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...mg({idPrefix:"eventdrop-window",count:v,xScale:e=>_(b+e*i.size),yTop:A.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>S)return null;const t=0===e?R[0]?.y1:R[e-1]?.y2??R[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?A.wallTop:t+1.25*s},yBottom:C,wallThickness:6}),...R.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:j,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:u},projectionRows:P.map((e,t)=>({label:`${b+t*i.size}-${b+(t+1)*i.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:R,lateCount:P.reduce((e,t)=>e+t.secondary,0),plot:d.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:i.size,windowStart:b}}}({data:Array.isArray(e)?e:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...o,config:s.config,initialSpawns:Qy(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Hf(t||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[600,400],s="mechanical"===i.mode,a=function(e){const{data:t,categoryAccessor:n,valueAccessor:o,unitValue:i,ballRadius:r,seed:s,size:a}=e,l=Zf(i,1),c=qf(a),u=[],d=new Map,h=new Map,f=[];function p(e){let t=d.get(e);return null==t&&(t=u.length,u.push(e),d.set(e,t)),t}t.forEach((e,t)=>{p((Vf(e,t,n)??"unknown")+"")});const g=Math.max(1,u.length),y=function(e,t,n){const o=e.width/Math.max(1,t),i=Math.max(2,2*n),r=Math.min(.7*o,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:o,tubeWidth:r,ballDiameter:i,perRow:s,centerX:t=>e.x+(t+.5)*o,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*i}}(c.plot,g,r),m=Math.max(0,y.tubeWidth/2-r-1),x=u.map(()=>[]);t.forEach((e,t)=>{const i=(Vf(e,t,n)??"unknown")+"",s=p(i),a=o?Uf(Vf(e,t,o)):1,u=Math.max(0,Math.round((a??0)/l)),d=y.centerX(s);for(let n=0;u>n;n+=1){const o=h.get(i)??0,a=y.perRow>1?((y.perRow>1?o%y.perRow:0)/(y.perRow-1)*2-1)*m:0;h.set(i,o+1),x[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:d+a,y:c.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:i,unitIndex:n}})}});const b=x.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;b>e;e+=1)for(const t of x)t.length>e&&f.push(t[e]);const v=c.plot.y+c.plot.height,w=[...Zp({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=c.plot.y-400;for(let e=0;g>e;e+=1){const t=y.centerX(e);for(const n of[-1,1])w.push({id:`pile-tube-${e}-${0>n?"l":"r"}`,shape:{type:"aabb",x:t+n*y.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:Gf(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(e=>({label:e,value:h.get(e)??0}))}}({data:s?function(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),n=t.length?t:["Intake"],o=Math.max(n.length,Math.round(e.count??Math.max(48,12*n.length))),i=Zf(e.unitValue,1),r=Jf(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),l=a.reduce((e,t)=>e+t,0)||1,c=o-n.length,u=a.map(e=>e/l*c),d=u.map(e=>1+Math.floor(e));let h=o-d.reduce((e,t)=>e+t,0);const f=u.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%f.length)d[f[e].index]+=1,h-=1;return n.map((e,t)=>({id:`${s}-${t}`,category:e,value:d[t]*i,mechanical:!0,unitCount:d[t],unitValue:i,share:d[t]/o}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...o,config:a.config,initialSpawns:Qy(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:Hf(t||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[600,360],s=function(e){const{data:t,xAccessor:n,groupAccessor:o,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:l,collisionIterations:c,settle:u}=e,d=qf(a),h=Jf(s),f=[],p=[],g=new Map;t.forEach((e,t)=>{const s=Uf(Vf(e,t,n));if(null==s)return;const a=o?(Vf(e,t,o)??"All")+"":"All",l=i?Uf(Vf(e,t,i)):null,c=Kf(null!=l&&l>0?l:r,2,18);!function(e){let t=g.get(e);null==t&&(t=p.length,p.push(e),g.set(e,t))}(a),f.push({datum:e,index:t,value:s,group:a,radius:c})});const y=f.map(e=>e.value),m=l?Uf(l[0]):null,x=l?Uf(l[1]):null,b=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=m??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const e=k;k=w,w=e}const S=Math.max(r,...f.map(e=>e.radius)),A=d.plot.x+S+8,M=d.plot.x+d.plot.width-S-8,_=(0,xg.scaleLinear)().domain([w,k]).range([A,M]),P=Math.max(1,p.length),j=Math.min(Math.max(28,3*S),d.plot.height/4),C=d.plot.y+j,R=Math.max(0,d.plot.y+d.plot.height-j-C),L=e=>{const t=g.get(e)??0;return 1===P?d.plot.y+.54*d.plot.height:C+t/(P-1)*R},T=new Map,I=f.map((e,t)=>{T.set(e.group,(T.get(e.group)??0)+1);const n=_(e.value),o=L(e.group),i=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:u?n+i:Kf(n+(t%9-4)*e.radius*2.5,A,M),y:u?o+r:d.plot.y-18-t%12*e.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:n,targetY:o},springs:[{target:{type:"point",x:n,y:o},restLength:0,stiffness:34,damping:5.5}]}});return{config:Gf(s,Zp({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:I,projectionRows:p.map(e=>({label:e,value:T.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(e=>({label:e,y:L(e),count:T.get(e)??0})),plot:d.plot}}}({data:Array.isArray(e)?e:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...o,config:s.config,initialSpawns:Qy(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Hf(t||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=Rg({data:Array.isArray(e)?e:[],stages:s,size:r,idAccessor:i.idAccessor,stageAccessor:i.stageAccessor||"stage",groupBy:i.groupBy,groupLabelAccessor:i.groupLabelAccessor,workAccessor:i.workAccessor,radiusAccessor:i.radiusAccessor,ballRadius:i.ballRadius??6,seed:i.seed??1,groupCompletion:i.groupCompletion,groupAnchorAlong:i.groupAnchorAlong,settle:i.settle??!0,gravityX:i.gravityX,gravityY:i.gravityY}),l=a.metadata;return{...o,config:a.config,initialSpawns:Qy(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:l?.regionEffects,bodyStyle:Hf(t||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[900,520],s=Hg({data:Array.isArray(e)?e:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...o,config:s.config,initialSpawns:Qy(s.initialSpawns),projectionRows:[],bodyStyle:Hf(t||i.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[900,520],s=Dy({data:Array.isArray(e)?e:[],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(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,by(t)??0));const n=e.phases.find(e=>e.id===t.phaseId);if(!n)return e.duration;const o=Math.max(0,Math.min(1,by(t.progress??0)??0));return n.start+n.duration*o}(s,i.snapshotAt):s.duration,l=zy(s,a).state,c=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(e,t={}){const n=t.groupBy??"outlet",o=new Map,i=e=>{const t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},n),i=o.get(t);if(i)return i.count+=1,i.amount+=e.amount,void ty(i.metrics,e.metrics);o.set(t,{key:t,label:"product"===n&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:{...e.metrics},status:"status"===n?e.status:void 0,outletId:"outlet"===n?e.outletId:void 0,category:"category"===n?e.category:void 0,productId:"product"===n&&"product"===e.kind?e.id:void 0})};for(const t of Object.values(e.components))t.productIds.length||"consumed"===t.status||i({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(const t of Object.values(e.products))i({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});const r=new Map((t.order??[]).map((e,t)=>[e,t]));return[...o.values()].sort((e,t)=>(r.get(e.key)??Number.MAX_SAFE_INTEGER)-(r.get(t.key)??Number.MAX_SAFE_INTEGER)||Vg(e.key,t.key))}(l,c),d=c.measure??"count",h=function(e,t={}){const n=t.bodies??[],o=Math.max(0,t.recentBodyLimit??6),i=new Map;for(const e of n){const n=t.getContainerId?.(e);if(!n)continue;const o=i.get(n);o?o.push(e):i.set(n,[e])}const r=e.map(e=>{const n=i.get(e.id)??[],r=Math.max(0,Math.floor(e.count??n.length)),s=n.slice(Math.max(0,n.length-o)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??Zy(e),datum:e.datum}));return{id:e.id,label:e.label,count:r,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:n.map(e=>e.id),recentBodies:s,metadata:e.metadata}}),s=r.reduce((e,t)=>e+t.count,0);return r.map(e=>({...e,share:s>0?e.count/s:0}))}(u.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===d||"amount"===d?e.amount:Number(e.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),f={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},p=t??i.colorBy??"category",g=!1===i.showChrome?null:Yf.createElement(Uy,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:Yf.createElement(Ky,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...o,config:s.config,initialSpawns:Qy(Iy(l,s.layout,f)),projectionRows:h,bodyStyle:e=>function(e,t,n,o){const i=e.datum,r={stroke:o.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:o.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:o.opacity??.96};if(!i?.__crucible)return{...r,fill:o.color??"#b8792d"};if("product"===i.kind){const e=t.products[i.semanticId];return{...r,fill:o.color??e?.color??tm(e?.id??i.semanticId)}}const s=t.components[i.semanticId];if(!s)return{...r,fill:o.color??"#356b63"};let a;return a="status"===n?s.status:"outlet"===n?s.outletId??"in chamber":"product"===n?s.productIds[0]??"unalloyed":"category"===n||null==n?s.category:"function"==typeof n?(n(s.datum)??"unassigned")+"":(s.datum[n+""]??"unassigned")+"",{...r,fill:o.color??tm(a)}}(e,l,p,i),getBodyLabel:e=>function(e,t){const n=e.datum;if(n?.__crucible)return"product"===n.kind?t.products[n.semanticId]?.label:t.components[n.semanticId]?.label}(e,l),renderBodySVG:By,backgroundGraphics:Jy(g,o.backgroundGraphics),foregroundGraphics:Jy(y,o.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[760,420],s=function(e){const{coordinateMode:t,flowSpeed:n,links:o,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:g,sourceAccessor:y,targetAccessor:m,throughputAccessor:x}=e,b=qf(g),v=Jf(p),w=new Map,k=new Map,S=[];function A(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof r){const e=r(t,0);if(null!=e)return e+""}if("string"==typeof r&&null!=t[r])return t[r]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}l.forEach((e,t)=>{const n=(Vf(e,t,r)??e.id??t)+"",o=Uf(Vf(e,t,s)),i=Uf(Vf(e,t,a));if(null!=o&&null!=i){const e={x:o,y:i};w.set(n,e),S.push(e)}k.set(n,(e.label??e.name??n)+"")});const M=[];o.forEach((e,t)=>{const n=A(Vf(e,t,y)),o=A(Vf(e,t,m)),i=Math.max(0,Uf(Vf(e,t,x))??0),r=vg(d?Vf(e,t,d):void 0),s=r.length?r:vg(e.path??e.points??e.route);s.forEach(e=>S.push(e)),M.push({id:(e.id??`physical-flow-${n}-${o}-${t}`)+"",link:e,index:t,source:n,target:o,throughput:i,rawPath:s})});const _=(j=S,"normalized"===(P=t)||"pixels"===P?P:j.length>0&&j.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var P,j;const C=new Map;for(const[e,t]of w)C.set(e,wg(t,b,_));const R=[];for(const e of M){let t=e.rawPath.map(e=>wg(e,b,_));if(2>t.length){const n=C.get(e.source),o=C.get(e.target);n&&o&&(t=[n,o])}else C.has(e.source)||C.set(e.source,t[0]),C.has(e.target)||C.set(e.target,t[t.length-1]);t.length>=2&&e.throughput>0&&(k.has(e.source)||k.set(e.source,e.source),k.has(e.target)||k.set(e.target,e.target),R.push({...e,path:t,packetCount:0}))}const L=Zf(u,.12),T=Math.max(1,Math.round(i)),I=R.map(e=>Math.max(1,Math.round(e.throughput*L))),$=I.reduce((e,t)=>e+t,0),O=$>T?T/$:1;R.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(I[t]*O))});let z=R.reduce((e,t)=>e+t.packetCount,0);for(;z>T;){const e=R.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>R[e].packetCount)?n:e,-1);if(-1===e)break;R[e].packetCount-=1,z-=1}const D=new Map,F=new Map,E=[],N=Zf(n,90),B=Zf(c,4);R.forEach((e,t)=>{D.set(e.target,(D.get(e.target)??0)+e.throughput),F.set(e.source,(F.get(e.source)??0)+e.throughput);const n=kg(e.path);for(let o=0;e.packetCount>o;o+=1){const i=(o+.5)/e.packetCount,r=f?i:Kf(.12+.84*i+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=Sg(e.path,s),l=Sg(e.path,r),c=Ag(e.path,s),u={x:-c.y,y:c.x},d=(v()-.5)*B*1.5;E.push({id:`${e.id}-packet-${o}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*N+10*(v()-.5),vy:f?0:c.y*N+10*(v()-.5),mass:.8,spawnAt:f?0:.04*t+o/32,shape:{type:"circle",radius:B},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:o,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:N,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*B,stiffness:26,damping:4.25}]:void 0})}});const W=Math.max(18,5*B),Y=Array.from(C,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:"physical-flow-node-"+Qf(e),point:t})),q=Y.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:W,height:W}})),X=Object.fromEntries(Y.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),H=Gf(p,[...Zp({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...q],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*B),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=T,H.eviction="oldest",H.observation={...H.observation,sensors:X};const G=Array.from(C,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+Qf(e),incoming:D.get(e)??0,outgoing:F.get(e)??0})),V=R.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:H,initialSpawns:E,projectionRows:G.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:E.length,totalThroughput:R.reduce((e,t)=>e+t.throughput,0),plot:b.plot,nodes:G,links:V}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(e)?e:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...o,config:s.config,initialSpawns:Qy(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Hf(t||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,n,o,i)=>{const r=o.size??[700,380],s=function(e){const t=function(e,t,n){const o=e?.observation;return{...e,observation:{...o,chartId:t??o?.chartId??"physics-custom",chartType:o?.chartType??"PhysicsCustomChart",onObservation:n??o?.onObservation}}}(e.config,e.chartId,e.onObservation),n=Tg(e.colorScheme,e.themeCategorical,B),o=qf(e.size),i={data:e.data,scales:{x:(0,Lg.scaleLinear)().domain(e.xExtent??[0,1]).range([o.plot.x,o.plot.x+o.plot.width]),y:(0,Lg.scaleLinear)().domain(e.yExtent??[0,1]).range([o.plot.y+o.plot.height,o.plot.y])},dimensions:o,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Ig(n,e.colorScheme),config:e.layoutConfig??{},world:new gg(t)},r=e.skipLayout?{}:e.layout(i)??{},s=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...o}=e,i=n.get(t)??[];i.push(o),n.set(t,i)}return e.map(e=>{const t=n.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:$g(t,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:n,config:i.config,data:Array.isArray(e)?e:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:qe(Ge)??{},size:r,themeCategorical:Ge.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...o,config:s.config,initialSpawns:Qy(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??Hf(t||i.colorBy)}}}};function om(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function im(e){if(!e||2>e.length)return;const t=om(e[0]),n=om(e[e.length-1]);return null!==t&&null!==n?[t,n]:void 0}function rm(e){const{count:t,byType:n}=function(e){const t={};for(const n of e){const e="string"==typeof n?.type&&n.type.length>0?n.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),o=0===t,i=[...e.extraWarnings??[]];o&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE");const r=e.margin,s=r?{x:r.left,y:r.top,width:e.width-r.left-r.right,height:e.height-r.top-r.bottom}:void 0;return{component:"",frameType:e.frameType,status:o?"empty":"ok",empty:o,markCount:t,markCountByType:n,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:Array.isArray(e.annotations)?e.annotations.length:0,ariaLabel:"string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,warnings:i,...r?{margin:r}:{},...s?{plot:s}:{}}}var sm=g(require("react")),am=g(require("react-dom/server")),lm=require("d3-scale"),cm=require("react/jsx-runtime"),um=Oi;function dm(e,t,n){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>me(e,t)??"#999"}const o=Array.isArray(t)?t:n.colors.categorical.length>0?n.colors.categorical:B;return(0,lm.scaleOrdinal)().domain(e).range(o)}function hm(e,t,n){if(0===e.length)return;const o=dm(e,t,n);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:o(e.label)})}]}}function fm(e){return"left"===e?"start":"right"===e?"end":e??"start"}function pm(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function gm(e,t,n,o){const i=pm(o);return t+n+Math.ceil(e.length*i*.58)}function ym(e){const{categories:t,theme:n,position:o="right",totalWidth:i,margin:r,legendLayout:s}=e,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=Vi(s),d=a+l,h="top"===o||"bottom"===o,f=Math.max(a,i-r.left-r.right),p=t.map(e=>gm(e,a,l,n));if(h){const e=Math.max(a,s?.maxWidth??f),n=[];let o=0,i=0;p.forEach((t,r)=>{const s=0===i?t:i+c+t;i>0&&s>e?(n.push({start:o,end:r,width:i}),o=r,i=t):i=s}),t.length>0&&n.push({start:o,end:t.length,width:i});const r=fm(s?.align),l=[];return n.forEach((n,o)=>{let i="center"===r?Math.max(0,(e-n.width)/2):"end"===r?Math.max(0,e-n.width):0;for(let e=n.start;n.end>e;e++)l.push({category:t[e],width:p[e],x:i,y:o*u}),i+=p[e]+c}),{items:l,width:Math.max(0,...n.map(e=>e.width)),height:n.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...p);return{items:t.map((e,t)=>({category:e,width:p[t],x:0,y:t*u})),width:g,height:t.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function mm(e){const{legendGroups:t,theme:n,position:o="right",totalWidth:i,margin:r,legendLayout:s}=e,{swatchSize:a,labelGap:l,rowHeight:c}=Vi(s),u=a+l,d=Math.max(12,pm(n)),h="top"===o||"bottom"===o,f=Math.max(a,i-r.left-r.right);if(h){const o=Math.max(a,s?.maxWidth??f),i=fm(s?.align);let r=0,l=0;const c=[];for(const i of t){const t=i.items.map(e=>e.label),u=ym({...e,categories:t,legendLayout:{...s,maxWidth:Math.max(a,o-d-8),align:"start"}}),h=i.label?d:0,f=i.label?gm(i.label,0,0,n):0,p=h>0?h+8:0,g=p+u.width,y=Math.max(u.height,f);c.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.length>0?r-12:0,p=h>o?0:"center"===i?Math.max(0,(o-h)/2):"end"===i?Math.max(0,o-h):0;return{groups:c.map(e=>({...e,x:e.x+p})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Ui(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c);let g=0;return{groups:t.map((e,t)=>{const o=e.items.map(e=>gm(e.label,a,l,n)),i=Math.max(0,...o,e.label?gm(e.label,0,0,n):0);return g=Math.max(g,i),{group:e,x:0,y:p[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:e.items.length*c,items:e.items.map((e,t)=>({category:e.label,width:o[t],x:0,y:t*c}))}}),width:g,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function xm(e){const t="top"===e.position||"bottom"===e.position,n=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??n,200),height:e.gradient.label?34:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?124:108,swatchSize:14}}function bm(e,t){if(!t||!e||0===e.length)return[];const n="function"==typeof t?t:e=>e[t],o=new Set;for(const t of e){const e=n(t);null!=e&&o.add(e+"")}return Array.from(o)}var vm=require("react/jsx-runtime"),wm=16,km=20;function Sm(e,t){return e.color||t.colors.annotation||t.colors.text}function Am(e,t,n){const o=e.labelBackground,i=t.colors.background,r=i&&"transparent"!==i?i:t.colors.surface||i;return void 0===o?"none"===n?"none":{type:"halo",fill:r}:!1===o||"none"===o?"none":!0===o||"halo"===o?{type:"halo",fill:r}:"box"===o?{type:"box",fill:r}:{fill:r,...o}}function Mm(e,t,n){return null!=e.x&&t.x?t.x(e.x):n&&null!=e[n]&&t.x?t.x(e[n]):"number"==typeof e.x?e.x:null}function _m(e,t,n){return null!=e.y&&t.y?t.y(e.y):n&&null!=e[n]&&t.y?t.y(e[n]):"number"==typeof e.y?e.y:null}function Pm(e){const{annotations:t}=e;if(!t||0===t.length)return null;const n=_s(t),o=e.scales.geoProjection,i=o?n.map(e=>{if(!Array.isArray(e.coordinates)||2>e.coordinates.length)return e;const t=o([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):n,r=!!o&&!e.scales.x&&!e.scales.y,s=e=>Number(e),a=e.scales.x??(r?s:void 0),l=e.scales.y??(r?s:void 0),c=e.projection?"horizontal"===e.projection?"horizontal":"vertical":void 0,u={scales:{x:a,y:l,time:a,value:l,o:e.scales.o,...o?{geoProjection:o}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,frameType:e.projection?"ordinal":o||e.scales.x||e.scales.y?"xy":"network",...c?{projection:c}:{}},d=Jr(e.autoPlaceAnnotations?Ms({annotations:i,context:u,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):i,(t,n)=>function(e,t,n){const{scales:o,layout:i,theme:r,xAccessor:s,yAccessor:a}=n;switch(e.type){case"y-threshold":{const s=e.value;if(null==s)return null;const a=Sm(e,r),l=e.label,c=e.labelPosition||"right",u=e.strokeDasharray||"6,4",d=e.strokeWidth??1.5;if("horizontal"===n.projection&&o.r){const n=o.r(s);return null==n?null:(0,vm.jsxs)("g",{opacity:e.opacity,children:[(0,vm.jsx)("line",{x1:n,y1:0,x2:n,y2:i.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&(0,vm.jsx)(Kr,{x:n+4,y:wm,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Am(e,r,"halo")})]},"ann-ythresh-"+t)}const h=o.y?o.y(s):o.r?o.r(s):null;return null==h?null:(0,vm.jsxs)("g",{children:[(0,vm.jsx)("line",{x1:0,y1:h,x2:i.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&(0,vm.jsx)(Kr,{x:"left"===c?4:"center"===c?i.width/2:i.width-4,y:km>h?Math.min(i.height-4,h+wm):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Am(e,r,"halo")})]},"ann-ythresh-"+t)}case"x-threshold":{const s=e.value;if(null==s)return null;const a="horizontal"===n.projection&&o.r?o.r(s):o.x?o.x(s):null;if(null==a)return null;const l=Sm(e,r),c=e.label,u=e.labelPosition||"top";return(0,vm.jsxs)("g",{opacity:e.opacity,children:[(0,vm.jsx)("line",{x1:a,y1:0,x2:a,y2:i.height,stroke:l,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),c&&(0,vm.jsx)(Kr,{x:a>.6*i.width?a-4:a+4,y:"bottom"===u?i.height-4:"center"===u?i.height/2:wm,textAnchor:a>.6*i.width?"end":"start",fontSize:r.typography.tickSize,fill:l,fontFamily:r.typography.fontFamily,text:c,background:Am(e,r,"halo")})]},"ann-xthresh-"+t)}case"band":{const n=o.y?.domain?.(),s=e.y0??n?.[0],a=e.y1??n?.[1],l=null!=s&&o.y?o.y(s):null,c=null!=a&&o.y?o.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ei(e.fill||Sm(e,r),"ssr-band-"+t),f=e.fillOpacity??.1;return(0,vm.jsxs)("g",{opacity:e.opacity,children:[h.def&&(0,vm.jsx)("defs",{children:h.def}),(0,vm.jsx)("rect",{x:0,y:u,width:i.width,height:d,fill:h.fill,fillOpacity:f}),e.label&&(0,vm.jsx)(Kr,{x:i.width-4,y:Math.max(u,0)+wm,textAnchor:"end",fontSize:r.typography.tickSize,fill:e.color||Sm(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Am(e,r,"halo")})]},"ann-band-"+t)}case"x-band":{const n=o.x?.domain?.(),s=e.x0??n?.[0],a=e.x1??n?.[1],l=null!=s&&o.x?o.x(s):null,c=null!=a&&o.x?o.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ei(e.fill||Sm(e,r),"ssr-xband-"+t),f=e.fillOpacity??.1;return(0,vm.jsxs)("g",{opacity:e.opacity,children:[h.def&&(0,vm.jsx)("defs",{children:h.def}),(0,vm.jsx)("rect",{x:u,y:0,width:d,height:i.height,fill:h.fill,fillOpacity:f}),e.label&&(0,vm.jsx)(Kr,{x:u+4,y:wm,textAnchor:"start",fontSize:r.typography.tickSize,fill:e.color||r.colors.primary||Sm(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Am(e,r,"halo")})]},"ann-xband-"+t)}case"category-highlight":{if(null==e.category||!o.o)return null;const s=o.o(e.category+"");if(null==s)return null;const a=o.o.bandwidth?o.o.bandwidth():40,l=Sm(e,r),c=e.opacity??.1,u=e.label;return(0,vm.jsxs)("g","horizontal"===n.projection?{children:[(0,vm.jsx)("rect",{x:0,y:s,width:i.width,height:a,fill:l,opacity:c}),u&&(0,vm.jsx)(Kr,{x:12,y:s+a/2,dominantBaseline:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Am(e,r,"none")})]}:{children:[(0,vm.jsx)("rect",{x:s,y:0,width:a,height:i.height,fill:l,opacity:c}),u&&(0,vm.jsx)(Kr,{x:s+a/2,y:wm,textAnchor:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Am(e,r,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:n,y:i}=function(e,t,n,o){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){const n=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(n)return{x:n[0],y:n[1]}}return{x:Mm(e,t,n),y:_m(e,t,o)}}(e,o,s,a);if(null==n||null==i)return null;const l="text"===e.type,c=e.dx??(l?0:30),u=e.dy??(l?0:-30),d=e.color||r.colors.text;if(!l){const o="callout"===e.type?"callout-circle":e.type,r="callout-circle"===o?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===o?{width:e.width,height:e.height}:void 0;return(0,vm.jsx)(br,{noteData:{x:n,y:i,dx:c,dy:u,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:o,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:d,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return(0,vm.jsx)("g",{children:(0,vm.jsx)("text",{x:n+c,y:i+u,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||r.typography.labelSize,fill:d,fontFamily:r.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}(t,n,e),e.svgAnnotationRules,u);return d.length>0?(0,vm.jsx)("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:d}):null}var jm=g(require("react")),Cm=require("react/jsx-runtime");function Rm(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function Lm(e){const t=e._idPrefix||e.chartId;if(t){const e=(t+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:"c"+e}const n=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`;let o=0;for(let e=0;n.length>e;e++)o=31*o+n.charCodeAt(e)|0;return"c"+(o>>>0).toString(36)}function Tm(e,t,n){return Ci(e.showLegend&&!e.__legendIncludesAutomatic?hm(t,e.colorScheme,n):void 0,e.legend)}var Im={right:110,left:110,top:50,bottom:80};function $m(e,t){if(e.__autoLegendMargin&&!Om(e,t))return Im[t]}function Om(e,t){const n=e.__explicitMargin;return"number"==typeof n||!(!n||"object"!=typeof n||"number"!=typeof n[t])}function zm(e,t){const{props:n,categories:o,theme:i,size:r,hasTitle:s}=t,a=n.legendPosition||"right",l={theme:i,position:a,size:r,hasTitle:s,legendLayout:n.legendLayout,axisChrome:n.axisChrome,minimumMargin:$m(n,a),preserveExplicitMargin:Om(n,a)};if(null!=n.legend){const t=Tm(n,o,i);(Ri(t)||Li(t))&&function(e,t){if(t.preserveExplicitMargin)return;const n=t.position||"right",o={theme:t.theme,position:n,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout},i=Ri(t.legend)?function(e){const{width:t,height:n,swatchSize:o}=mm(e);return{width:t,height:n,swatchSize:o}}({...o,legendGroups:t.legend.legendGroups}):Li(t.legend)?xm({...o,gradient:t.legend.gradient}):null;if(!i)return;const r=Ni(t.legend),s=Math.max(t.minimumMargin??0,Gi(t.legend,t.legendLayout)),a=Xi(t.axisChrome,t.legendLayout),l=Math.max(t.minimumMargin??0,r+i.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,a+r+i.height);"right"===n?e.right=Math.max(e.right,s):"left"===n?e.left=Math.max(e.left,s):"top"===n?e.top=Math.max(e.top,l):e.bottom=Math.max(e.bottom,c)}(e,{...l,legend:t})}else n.showLegend&&o.length>0&&function(e,t){if(0===t.categories.length)return;if(t.preserveExplicitMargin)return;const n=t.position||"right",o=function(e){const{width:t,height:n,swatchSize:o}=ym(e);return{width:t,height:n,swatchSize:o}}({categories:t.categories,colorScheme:t.colorScheme,theme:t.theme,position:n,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout}),i=hm(t.categories,t.colorScheme,t.theme),r=Ni(i),s=Math.max(t.minimumMargin??0,Gi(i,t.legendLayout)),a=Xi(t.axisChrome,t.legendLayout),l=Math.max(t.minimumMargin??0,r+o.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,a+r+o.height);"right"===n?e.right=Math.max(e.right,s):"left"===n?e.left=Math.max(e.left,s):"top"===n?e.top=Math.max(e.top,l):e.bottom=Math.max(e.bottom,c)}(e,{...l,categories:o,colorScheme:n.colorScheme});return a}function Dm(e){const{props:t,categories:n,theme:o,size:i,margin:r,hasTitle:s}=e,a=t.legendPosition||"right",l={theme:o,position:a,size:i,margin:r,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(null!=t.legend){const e=Tm(t,n,o);if(jm.isValidElement(e))return e;const i=function(e,t){const n={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,axisChrome:t.axisChrome,legendDistance:Ri(e)||Li(e)?e.legendDistance:void 0};return Ri(e)?function(e){if(0===(t=e.legendGroups,t.flatMap(e=>e.items.map((t,n)=>({group:e,item:t,itemIndex:n,label:t.label})))).length)return null;var t;const n=mm(e),o="top"===e.position||"bottom"===e.position,i={legendGroups:e.legendGroups,legendDistance:e.legendDistance},r=e.reservedWidth??Ei(i,e.legendLayout),s=Ni(i),a=Bi(e.legendLayout),l=Xi(e.axisChrome,e.legendLayout),c=Xi(void 0,e.legendLayout),u=e.theme.colors.grid||e.theme.colors.textSecondary;let d,h;if("left"===e.position?(d=e.margin.left-a-r-s,h=e.margin.top):"top"===e.position?(d=e.margin.left,h=e.margin.top-c-s-n.height):"bottom"===e.position?(d=e.margin.left,h=Math.max(e.totalHeight-e.margin.bottom+s,Math.min(e.totalHeight-e.margin.bottom+l+s,e.totalHeight-n.height))):(d=e.totalWidth-e.margin.right+a+s,h=e.margin.top),!o){const t=Ui(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(n.swatchSize,e.legendLayout?.rowHeight??um)),o=e.legendGroups.flatMap((o,i)=>{const s=t[i],a=o.type??"fill",l=[(0,cm.jsx)("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return o.label&&null!=s.labelY&&l.push((0,cm.jsx)("text",{y:s.labelY,fontSize:pm(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:o.label},"legend-group-label-"+i)),l.push((0,cm.jsx)("g",{transform:`translate(0,${s.itemsY})`,children:o.items.map((t,r)=>{const s=o.styleFn(t,r),l="function"==typeof a?a(t):"line"===a?(0,cm.jsx)("line",{x1:0,y1:0,x2:n.swatchSize,y2:n.swatchSize,style:s}):(0,cm.jsx)("rect",{width:n.swatchSize,height:n.swatchSize,rx:n.swatchRadius,style:s});return(0,cm.jsxs)("g",{transform:`translate(0,${r*Math.max(n.swatchSize,e.legendLayout?.rowHeight??um)})`,children:[l,(0,cm.jsx)("text",{x:n.labelOffset,y:n.swatchSize/2,dominantBaseline:"central",fontSize:pm(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return(0,cm.jsx)("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":"vertical",children:o})}const f=n.groups.flatMap((t,i)=>{const{group:r}=t,s=r.type??"fill",a=[];if(r.label&&a.push((0,cm.jsx)("text",o?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:pm(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:r.label}:{x:t.x,y:t.y+pm(e.theme),fontSize:pm(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:r.label},"legend-group-label-"+i)),a.push(...t.items.map((o,a)=>{const l=r.items[a],c=r.styleFn(l,a),u="function"==typeof s?s(l):"line"===s?(0,cm.jsx)("line",{x1:0,y1:0,x2:n.swatchSize,y2:n.swatchSize,style:c}):(0,cm.jsx)("rect",{width:n.swatchSize,height:n.swatchSize,rx:n.swatchRadius,style:c});return(0,cm.jsxs)("g",{transform:`translate(${t.x+t.itemOffsetX+o.x},${t.y+t.itemOffsetY+o.y})`,children:[u,(0,cm.jsx)("text",{x:n.labelOffset,y:n.swatchSize/2,dominantBaseline:"central",fontSize:pm(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:o.category})]},`legend-${i}-${a}`)})),o&&n.groups.length-1>i){const e=t.x+t.width+6;a.push((0,cm.jsx)("line",{x1:e,y1:0,x2:e,y2:n.height,stroke:u},"legend-group-separator-"+i))}return a});return(0,cm.jsx)("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":o?"horizontal":"vertical",children:f})}({...n,legendGroups:e.legendGroups}):Li(e)?function(e){const t=xm(e),n="top"===e.position||"bottom"===e.position,o={gradient:e.gradient,legendDistance:e.legendDistance},i=Ei(o),r=Ni(o),s=Bi(e.legendLayout),a=Xi(e.axisChrome,e.legendLayout),l=Xi(void 0,e.legendLayout),c=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",u=e.gradient.format||(e=>Math.round(100*e)/100+"");let d,h;"left"===e.position?(d=e.margin.left-s-i-r,h=e.margin.top):"top"===e.position?(d=e.margin.left,h=e.margin.top-l-r-t.height):"bottom"===e.position?(d=e.margin.left,h=Math.max(e.totalHeight-e.margin.bottom+r,Math.min(e.totalHeight-e.margin.bottom+a+r,e.totalHeight-t.height))):(d=e.totalWidth-e.margin.right+s+r,h=e.margin.top);const f=Array.from({length:17},(t,o)=>{const i=o/16;return(0,cm.jsx)("stop",{offset:100*i+"%",stopColor:e.gradient.colorFn(n?e.gradient.domain[0]+i*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-i*(e.gradient.domain[1]-e.gradient.domain[0]))},o)});if(n){const n=12,o=e.gradient.label?0:void 0,i=e.gradient.label?8:0;return(0,cm.jsxs)("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,children:[(0,cm.jsx)("defs",{children:(0,cm.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:f})}),e.gradient.label&&(0,cm.jsx)("text",{x:t.width/2,y:o,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),(0,cm.jsx)("rect",{x:0,y:i,width:t.width,height:n,fill:`url(#${c})`,rx:2}),(0,cm.jsx)("text",{x:0,y:i+n+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[0])}),(0,cm.jsx)("text",{x:t.width,y:i+n+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[1])})]})}const p=e.gradient.label?-6:void 0;return(0,cm.jsxs)("g",{className:"semiotic-legend",transform:`translate(${d},${h+(e.gradient.label?12:0)})`,children:[(0,cm.jsx)("defs",{children:(0,cm.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:f})}),e.gradient.label&&(0,cm.jsx)("text",{x:0,y:p,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),(0,cm.jsx)("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),(0,cm.jsx)("text",{x:19,y:10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[1])}),(0,cm.jsx)("text",{x:19,y:100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[0])})]})}({...n,gradient:e.gradient}):null}(e,l);return i||(Ri(e)||Li(e)?null:e??null)}return t.showLegend&&0!==n.length?function(e){const{categories:t,colorScheme:n,theme:o,position:i="right",totalWidth:r,totalHeight:s,margin:a}=e;if(!t||0===t.length)return null;const l=dm(t,n,o),c="top"===i||"bottom"===i,u=ym(e),d=hm(t,n,o),h=e.reservedWidth??Ei(d,e.legendLayout),f="number"==typeof e.legendDistance?Math.max(0,e.legendDistance):Ni(d),p=Bi(e.legendLayout),g=Xi(e.axisChrome,e.legendLayout),y=Xi(void 0,e.legendLayout);let m,x;if("left"===i?(m=a.left-p-h-f,x=a.top):"top"===i?(m=a.left,x=a.top-y-f-u.height):"bottom"===i?(m=a.left,x=Math.max(s-a.bottom+f,Math.min(s-a.bottom+g+f,s-u.height))):(m=r-a.right+p+f,x=a.top),c){const e=u.items.map((e,t)=>(0,cm.jsxs)("g",{transform:`translate(${e.x},${e.y})`,children:[(0,cm.jsx)("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),(0,cm.jsx)("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:pm(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:e.category})]},"legend-"+t));return(0,cm.jsx)("g",{className:"semiotic-legend",transform:`translate(${m},${x})`,children:e})}const b=Ui([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??um))[0],v=u.items.map((e,t)=>(0,cm.jsxs)("g",{transform:`translate(${e.x},${e.y+b.itemsY})`,children:[(0,cm.jsx)("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),(0,cm.jsx)("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:pm(o),fill:o.colors.text,fontFamily:o.typography.fontFamily,children:e.category})]},"legend-"+t));return(0,cm.jsxs)("g",{className:"semiotic-legend",transform:`translate(${m},${x})`,children:[(0,cm.jsx)("line",{x1:0,y1:b.lineY,x2:h,y2:b.lineY,stroke:"gray"}),v]})}({categories:n,colorScheme:t.colorScheme,theme:o,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function Fm(e){return Math.round(100*e)/100+""}function Em(e,t){const n=tt(t.theme),o=t.background??n.background,i=t.idPrefix?t.idPrefix+"-":"",r="string"==typeof t.title?t.title:void 0,s=r?i+"semiotic-title":void 0,a=t.description?i+"semiotic-desc":void 0,l=[s,a].filter(Boolean).join(" ")||void 0;return(0,Cm.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":l,style:{fontFamily:n.fontFamily},children:[r&&(0,Cm.jsx)("title",{id:s,children:r}),t.description&&(0,Cm.jsx)("desc",{id:a,children:t.description}),t.defs&&(0,Cm.jsx)("defs",{children:t.defs}),o&&"transparent"!==o&&(0,Cm.jsx)("rect",{x:0,y:0,width:t.width,height:t.height,fill:o}),(0,Cm.jsx)("g",{id:i+"data-area",transform:t.innerTransform,children:e}),r&&(0,Cm.jsx)("text",{id:i+"chart-title",x:t.width/2,y:Gs,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:r}),t.legend&&(0,Cm.jsx)("g",{id:i+"legend",children:t.legend}),t.outerElements]})}var Nm=require("react/jsx-runtime");function Bm(e,t){const n=et(e.theme),o=e.size||[500,300],i=Ks({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=Vs(e.title),s=z(e.data),a=e.showLegend?bm(s,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[],l={hasAxis:!1!==e.showAxes,hasAxisLabel:!!e.xLabel};zm(i,{props:{...e,axisChrome:l},categories:a,theme:n,size:o,hasTitle:r});const c=o[0]-i.left-i.right,u=o[1]-i.top-i.bottom,d="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),h=e.colorScheme||n.colors.categorical,f=(e.axes?.find(e=>"left"===e.orient)??e.axes?.find(e=>"right"===e.orient))?.extent??e.axisExtent,p={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:d?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:d?void 0:e.xAccessor,yAccessor:d?void 0:e.yAccessor,timeAccessor:d?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor,categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,axisExtent:e.axisExtent,yAxisExtent:f,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:Ie(e.gradientFill),lineGradient:$e(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:h,themeCategorical:n.colors.categorical,themeSemantic:qe(n),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},g=new yo(p);if(e.data&&g.ingest({inserts:s,bounded:!0}),g.computeScene({width:c,height:u}),!g.scales||0===g.scene.length)return t&&(t.evidence=rm({frameType:"xy",width:o[0],height:o[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:g.scales?[]:["NO_SCALES"],margin:i})),am.renderToStaticMarkup(Em(null,{width:o[0],height:o[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));const y=e._idPrefix,m=Dc({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>Ra(e,t,y)});t&&(t.evidence=rm({frameType:"xy",width:o[0],height:o[1],marks:m.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:im(g.scales.x?.domain?.()),yDomain:im(g.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const x=e.showGrid?function(e,t,n,o,i,r){const{grid:s}=tt(n),a=o?o+"-":"",l=r?.find(e=>"bottom"===e.orient),c=r?.find(e=>"top"===e.orient),u=r?.find(e=>"left"===e.orient),d=r?.find(e=>"right"===e.orient),h=l??c,f=u??d,p=h?.extent??i,g=f?.extent??i,y="exact"===p?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),x=h?.tickValues??Fs(e.x,h?.ticks??y,p),b=f?.tickValues??Fs(e.y,f?.ticks??m,g),v=!1!==h?.grid,w=!1!==f?.grid,k=Ws(h?.gridStyle),S=Ws(f?.gridStyle);return(0,Cm.jsxs)("g",{id:a+"grid",className:"semiotic-grid",opacity:.8,children:[v&&x.map((n,o)=>{const i=e.x(n);return(0,Cm.jsx)("line",{x1:i,y1:0,x2:i,y2:t.height,stroke:s,strokeWidth:.5,strokeDasharray:k},"gx-"+o)}),w&&b.map((n,o)=>{const i=e.y(n);return(0,Cm.jsx)("line",{x1:0,y1:i,x2:t.width,y2:i,stroke:s,strokeWidth:.5,strokeDasharray:S},"gy-"+o)})]})}(g.scales,{width:c,height:u},n,y,e.axisExtent,e.axes):null,b=m.map(e=>e.element),v=Lm(e)+"-plot-clip",w=!1!==e.showAxes?function(e,t,n,o,i){const r=tt(o),s=Bi(n.legendLayout),a=n.legend&&"left"===n.legendPosition&&s>0?s:n.margin?.left??40,l=n.axes?.find(e=>"bottom"===e.orient),c=n.axes?.find(e=>"top"===e.orient),u=n.axes?.find(e=>"left"===e.orient),d=n.axes?.find(e=>"right"===e.orient),h=l??c,f=u??d,p=h?.extent??n.axisExtent,g=f?.extent??n.axisExtent,y="exact"===p?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),x=h?.tickValues??Fs(e.x,h?.ticks??y,p),b=x.map(e=>e.valueOf()),v=h?.tickFormat||n.xFormat||n.tickFormatTime||Fm,w=x.map((t,n)=>({pixel:e.x(t),label:v(t,n,b)})),k=f?.tickValues??Fs(e.y,f?.ticks??m,g),S=f?.tickFormat||n.yFormat||n.tickFormatValue||Fm,A=k.map(t=>({pixel:e.y(t),label:S(t)})),M=h?.label??n.xLabel,_=f?.label??n.yLabel;return(0,Cm.jsxs)("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==h?.baseline&&(0,Cm.jsx)("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:r.border,strokeWidth:1}),w.map((e,n)=>(0,Cm.jsxs)("g",{transform:`translate(${e.pixel},${t.height})`,children:[(0,Cm.jsx)("line",{y2:5,stroke:r.border,strokeWidth:1}),(0,Cm.jsx)("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"xtick-"+n)),M&&(0,Cm.jsx)("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:M}),!1!==f?.baseline&&(0,Cm.jsx)("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:r.border,strokeWidth:1}),A.map((e,t)=>(0,Cm.jsxs)("g",{transform:`translate(0,${e.pixel})`,children:[(0,Cm.jsx)("line",{x2:-5,stroke:r.border,strokeWidth:1}),(0,Cm.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"ytick-"+t)),_&&(0,Cm.jsx)("text",{x:15-a,y:t.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-a}, ${t.height/2})`,children:_})]})}(g.scales,{width:c,height:u},e,n,y):null,k=e.annotations?Pm({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{x:g.scales.x,y:g.scales.y},layout:{width:c,height:u},theme:n,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:y}):null,S=e.svgPreRenderers&&g.scales?e.svgPreRenderers.map((e,t)=>{try{return(0,Nm.jsx)(sm.Fragment,{children:e(g.scene,g.scales,{width:c,height:u})},"pre-"+t)}catch{return null}}).filter(Boolean):null,A=Dm({props:{...e,axisChrome:l},categories:a,theme:n,size:o,margin:i,hasTitle:r});return am.renderToStaticMarkup(Em((0,Nm.jsxs)(Nm.Fragment,{children:[e.backgroundGraphics,S,x,(0,Nm.jsx)("defs",{children:(0,Nm.jsx)("clipPath",{id:v,children:(0,Nm.jsx)("rect",{x:0,y:0,width:c,height:u})})}),(0,Nm.jsx)("g",{clipPath:`url(#${v})`,children:b}),w,k,e.foregroundGraphics,g.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,legend:A,idPrefix:e._idPrefix}))}var Wm=g(require("react-dom/server")),Ym=require("d3-scale"),qm=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,n){if(t&&"function"==typeof e.pieceStyle){const o=e.pieceStyle(t,n);return o&&!o.fill&&n?{...o,fill:this.getColorFromScheme(e,n)}:o}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&n?{fill:e.barColors[n]||"#007bff"}:{fill:n?this.getColorFromScheme(e,n):"#007bff"}}resolveSummaryStyle(e,t,n){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,n):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){const n=this.colorSchemeMap.get(t);if(n)return n;const o=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||fe,i=o[this.colorSchemeIndex%o.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,i),i}};function Xm(e){const t=e.getSymbol;return t?An(t,e.config.symbolMap):null}function Hm(e,t,n,o,i,r,s){e.push(t?{type:"symbol",x:o,y:i,size:Math.PI*r*r,symbolType:t(n),style:s,datum:n}:{type:"point",x:o,y:i,r:r,style:s,datum:n})}function Gm(e,t){const{columns:n,config:o,resolvePieceStyle:i}=e,r=[],s=Math.min(t.width,t.height)/2-4,a="donut"===o.chartType?o.innerRadius||60:0,l=-Math.PI/2+(o.startAngle||0)*Math.PI/180,c=null!=o.sweepAngle?o.sweepAngle*Math.PI/180:2*Math.PI,u=null!=o.sweepAngle&&360>o.sweepAngle,d=Object.values(n),h=d.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),f=u&&!h&&d.length>1&&(o.cornerRadius??0)>0;for(let e=0;d.length>e;e++){const t=d[e],n=t.pieceData[0],u="number"==typeof n?._pctStart?n._pctStart:t.pctStart,h=l+u*c,p=l+(u+("number"==typeof n?._pct?n._pct:t.pct))*c,g=i(t.pieceData[0],t.name),y=0===e,m=e===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...o.cornerRadius&&{cornerRadius:o.cornerRadius},style:g,datum:n?._nonInteractive?null:t.pieceData,category:t.name};n?._roundedEnds?x.roundedEnds=n._roundedEnds:f&&(x.roundedEnds={start:y,end:m}),n?._gradientBand&&(x._gradientBand=n._gradientBand),r.push(x)}return r}var Vm=require("d3-array");function Um(e){const t=e.length,n=e[0],o=e[t-1];return{n:t,min:n,q1:(0,Vm.quantile)(e,.25)??n,median:(0,Vm.quantile)(e,.5)??(n+o)/2,q3:(0,Vm.quantile)(e,.75)??o,max:o,mean:e.reduce((e,t)=>e+t,0)/t}}var Km=require("d3-scale"),Zm={bar:function(e,t){const{scales:n,columns:o,config:i,getR:r,getStack:s,resolvePieceStyle:a}=e,{r:l,projection:c}=n,u=[],d="vertical"===c,h="horizontal"===c,f=i.normalize,p=[];if(s){const e=new Set;for(const t of Object.values(o))for(const n of t.pieceData){const t=s(n);e.has(t)||(e.add(t),p.push(t))}}else p.push("_default");for(const e of Object.values(o)){const t=new Map;for(const n of e.pieceData){const e=s?s(n):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const o=t.get(e);o.total+=r(n),o.pieces.push(n)}let n=0;if(f)for(const e of t.values())n+=Math.abs(e.total);let o=0,i=0;for(const r of p){const c=t.get(r);if(!c)continue;let p=c.total;f&&n>0&&(p/=n);const g=a(c.pieces[0],s?r:e.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:e.name};if(d){const t=l(0>p?i:o+p),n=0>p?l(i+p)-l(i):l(o)-l(o+p);u.push(ln(e.x,t,e.width,Math.abs(n),g,y,r)),0>p?i+=p:o+=p}else if(h){const t=l(0>p?i+p:o),n=0>p?l(i)-l(i+p):l(o+p)-l(o);u.push(ln(t,e.x,Math.abs(n),e.width,g,y,r)),0>p?i+=p:o+=p}}}const g="vertical"===c,y=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;const t=e.datum?.__aggregateValue??0;e.roundedEdge=g?0>t?"bottom":"top":0>t?"left":"right",i.gradientFill&&(e.fillGradient=i.gradientFill)}if(y>0){const e=new Map;for(const t of u){if("rect"!==t.type)continue;const n=t.datum?.category||"";e.has(n)||e.set(n,[]),e.get(n).push(t)}for(const t of e.values()){if(0===t.length)continue;const e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),n=t.filter(e=>0>(e.datum?.__aggregateValue??0));e.length>0&&(e.reduce(g?(e,t)=>t.y>e.y?e:t:(e,t)=>e.x+e.w>t.x+t.w?e:t).roundedTop=y),n.length>0&&(n.reduce(g?(e,t)=>e.y+e.h>t.y+t.h?e:t:(e,t)=>t.x>e.x?e:t).roundedTop=y)}}return u},clusterbar:function(e,t){const{scales:n,columns:o,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=e,{r:l,projection:c}=n,u=[],d="vertical"===c,h=[],f=new Set;for(const e of Object.values(o))for(const t of e.pieceData){const e=s?s(t):"_default";f.has(e)||(f.add(e),h.push(e))}const p=h.length||1;for(const e of Object.values(o)){const t=e.width/p,n=.2*t,o=t-n,i=new Map;for(const t of e.pieceData){const e=s?s(t):"_default";i.has(e)||i.set(e,[]),i.get(e).push(t)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),f=a(i,h[s]);if(d){const r=e.x+s*t+n/2,a=l(0),d=l(c);u.push(ln(r,Math.min(a,d),o,Math.abs(a-d),f,i,h[s]))}else{const r=e.x+s*t+n/2,a=l(0),d=l(c);u.push(ln(Math.min(a,d),r,Math.abs(d-a),o,f,i,h[s]))}}}}const g=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=r(e.datum);g>0&&(e.roundedTop=g),e.roundedEdge=d?0>t?"bottom":"top":0>t?"left":"right",i.gradientFill&&(e.fillGradient=i.gradientFill)}return u},point:function(e,t){const{scales:n,columns:o,getR:i,multiScales:r,resolvePieceStyle:s}=e,{r:a,projection:l}=n,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,f=Xm(e),p=2*Math.PI,g=-Math.PI/2;for(const e of Object.values(o))for(const t of e.pieceData){const n=t.__rIndex??0,o=t.__rValue??i(t),l=h&&r[n]||a,y=s(t,e.name),m=y.r||5;let x,b;if(d){const t=g+(e.pctStart+e.pct/2)*p,n=l(o);x=Math.cos(t)*n,b=Math.sin(t)*n}else u?(x=e.middle,b=l(o)):(x=l(o),b=e.middle);Hm(c,f,t,x,b,m,y)}return c},swarm:function(e,t){const{scales:n,columns:o,getR:i,resolvePieceStyle:r}=e,{r:s,projection:a}=n,l=[],c="vertical"===a,u=Xm(e);for(const e of Object.values(o)){const t=e.width/2;for(let n=0;e.pieceData.length>n;n++){const o=e.pieceData[n],a=i(o),d=r(o,e.name),h=d.r||4,f=(7919*n%100/100-.5)*t*.8;Hm(l,u,o,c?e.middle+f:s(a),c?s(a):e.middle+f,h,d)}}return l},pie:Gm,donut:Gm,boxplot:function(e,t){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=n,c=[],u="vertical"===l,d=!1!==i.showOutliers;for(const t of Object.values(o)){const n=t.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===n.length)continue;const o=n[0],i=n[n.length-1],l=(0,Vm.quantile)(n,.25)??o,h=(0,Vm.quantile)(n,.5)??(o+i)/2,f=(0,Vm.quantile)(n,.75)??i,p=f-l,g=l-1.5*p,y=f+1.5*p,m=n.find(e=>e>=g)??o,x=[...n].reverse().find(e=>y>=e)??i,b=s(t.pieceData[0],t.name),v=[];if(d)for(const e of t.pieceData){const n=r(e);if(g>n||n>y){const o=u?t.middle:a(n),i=u?a(n):t.middle;v.push({px:o,py:i,value:n,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:a(m),q1Pos:a(l),medianPos:a(h),q3Pos:a(f),maxPos:a(x),stats:{n:n.length,min:m,q1:l,median:h,q3:f,max:x,mean:n.reduce((e,t)=>e+t,0)/n.length},style:b,datum:t.pieceData,category:t.name,outliers:v}),d)for(const t of v)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:b.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6},datum:t.datum})}return c},violin:function(e,t){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=n,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.showIQR;for(const e of Object.values(o)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const n=t[0],o=t[t.length-1],i=(o-n)/d||1,l=Array(d).fill(0);for(const e of t)l[Math.min(Math.floor((e-n)/i),d-1)]++;const f=we(l,1),p=e.width/2*.9;let g;if(u){g=`M ${e.middle} ${a(n)}`;for(let t=0;d>t;t++){const o=a(n+(t+.5)*i);g+=` L ${e.middle+l[t]/f*p} ${o}`}g+=` L ${e.middle} ${a(o)}`;for(let t=d-1;t>=0;t--){const o=a(n+(t+.5)*i);g+=` L ${e.middle-l[t]/f*p} ${o}`}g+=" Z"}else{g=`M ${a(n)} ${e.middle}`;for(let t=0;d>t;t++)g+=` L ${a(n+(t+.5)*i)} ${e.middle-l[t]/f*p}`;g+=` L ${a(o)} ${e.middle}`;for(let t=d-1;t>=0;t--)g+=` L ${a(n+(t+.5)*i)} ${e.middle+l[t]/f*p}`;g+=" Z"}const y=s(e.pieceData[0],e.name);let m;if(h&&t.length>=4){const i=(0,Vm.quantile)(t,.25)??n,r=(0,Vm.quantile)(t,.5)??(n+o)/2,s=(0,Vm.quantile)(t,.75)??o;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:e.middle,isVertical:u}}const x=u?{x:e.x,y:Math.min(a(o),a(n)),width:e.width,height:Math.abs(a(o)-a(n))}:{x:Math.min(a(n),a(o)),y:e.x,width:Math.abs(a(o)-a(n)),height:e.width};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:Um(t),style:y,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a}=n,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(const e of Object.values(o)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;const[n,o]=ve(t),i=null!=h&&isFinite(h)?h:n,d=null!=f&&isFinite(f)?f:o,p=(d-i)/c||1,g=Array(c).fill(0);for(const e of t)i>e||e>d||g[Math.min(Math.floor((e-i)/p),c-1)]++;const y=t.length,m=we(g,1),x=s(e.pieceData[0],e.name);for(let t=0;c>t;t++){if(0===g[t])continue;const n=(u?g[t]/y:g[t]/m)*e.width*.9,o=a(i+t*p),r=a(i+(t+1)*p);l.push(ln(Math.min(o,r),e.x+e.width-n,Math.abs(r-o),n,x,{bin:t,count:g[t],range:[i+t*p,i+(t+1)*p],category:e.name},e.name))}}return l},ridgeline:function(e,t){const{scales:n,columns:o,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=n,c=[],u=i.bins||20,d="horizontal"===l,h=i.amplitude||1.5;for(const e of Object.values(o)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const n=t[0],o=t[t.length-1],i=(o-n)/u||1,l=Array(u).fill(0);for(const e of t)n>e||e>o||l[Math.min(Math.floor((e-n)/i),u-1)]++;const f=we(l,1),p=s(e.pieceData[0],e.name),g=e.width*h;let y;if(d){const t=e.x+e.width;y=`M ${a(n)} ${t}`;for(let e=0;u>e;e++)y+=` L ${a(n+(e+.5)*i)} ${t-l[e]/f*g}`;y+=` L ${a(o)} ${t} Z`}else{const t=e.x;y=`M ${t} ${a(n)}`;for(let e=0;u>e;e++){const o=a(n+(e+.5)*i);y+=` L ${t+l[e]/f*g} ${o}`}y+=` L ${t} ${a(o)} Z`}const m=d?{x:Math.min(a(n),a(o)),y:e.x,width:Math.abs(a(o)-a(n)),height:e.width}:{x:e.x,y:Math.min(a(o),a(n)),width:e.width,height:Math.abs(a(o)-a(n))};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:Um(t),style:{...p,fillOpacity:p.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){const{scales:n,columns:o,getRawRange:i,resolvePieceStyle:r}=e,{r:s,projection:a}=n,l=[],c="horizontal"===a;for(const e of Object.values(o))for(const t of e.pieceData){const n=i(t);if(!n)continue;const[o,a]=n,u=r(t,e.name);if(c){const n=s(Math.min(o,a)),i=s(Math.max(o,a));l.push(ln(n,e.x,i-n,e.width,u,t,e.name))}else{const n=s(Math.max(o,a)),i=s(Math.min(o,a));l.push(ln(e.x,n,e.width,i-n,u,t,e.name))}}return l},funnel:function(e,t){const{columns:n,getR:o,getStack:i,resolvePieceStyle:r}=e,s=[],a=t.width/2,l=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>n[e]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const e of c)for(const t of e.pieceData){const e=i?i(t):"_default";d.has(e)||(d.add(e),u.push(e))}const h=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const e of c){const t=new Map;let n=0;for(const r of e.pieceData){const e=i?i(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const s=t.get(e),a=o(r);s.total+=a,s.pieces.push(r),n+=a}f.push({col:e,groups:t,stepTotal:n}),h||n>p&&(p=n)}if(h)for(const e of f){let t=0,n=0;for(let o=0;u.length>o;o++){const i=e.groups.get(u[o]);i&&(o%2==0?t+=i.total:n+=i.total)}const o=Math.max(t,n);o>p&&(p=o)}if(0===p)return s;const g=new Map;for(const e of u){const t=f[0].groups.get(e);g.set(e,t?.total??0)}const y=f[0].stepTotal,m=h?.95*a:.9*t.width,x=(0,Km.scaleLinear)().domain([0,p]).range([0,m]),b=e.config.connectorOpacity??.3;let v=new Map;for(let t=0;f.length>t;t++){const n=f[t],o=n.col,i=0===t,c=o.width,d=.55*c,p=o.x+(c-d)/2,m=new Map;if(h){let e=0;for(const t of u){const o=n.groups.get(t);o&&(e+=x(o.total))}let t=a,c=a;for(let h=0;u.length>h;h++){const f=u[h],y=n.groups.get(f);if(!y)continue;const b=x(y.total),v=h%2==0,w=v?t:c-b;v?t+=b:c-=b;const k=r(y.pieces[0],f),S=g.get(f)??y.total,A={...y.pieces[0],__funnelValue:y.total,__funnelPercent:S>0?y.total/S*100:0,__funnelStep:o.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:f};l&&(0===h&&(A.__funnelStepLabel=o.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=e),A.__funnelValueLabelX=w+b/2,A.__funnelValueLabelY=p,A.__funnelBarW=b),s.push(ln(w,p,b,d,k,A,f)),m.set(f,{x:w,y:p,w:b,h:d})}}else{const e=n.stepTotal,t=x(e),c=a-t/2,h=u[0],f="_default"!==h,g=n.groups.get(h)?.pieces[0]??o.pieceData[0],b=f?h:o.name,v=r(g,b),w=y>0?e/y*100:0,k={...g,__funnelValue:e,__funnelPercent:w,__funnelStep:o.name,__funnelIsFirstStep:i,category:f?h:o.name};l&&(k.__funnelStepLabel=o.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=t,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=t),s.push(ln(c,p,t,d,v,k,b)),m.set(h,{x:c,y:p,w:t,h:d})}if(t>0&&v.size>0){const t=h?u:[u[0]];for(const i of t){const t=v.get(i),a=m.get(i);if(!t||!a)continue;const l=(()=>{const e=n.groups.get(i);return r(e?e.pieces[0]:o.pieceData[0],"_default"===i?o.name:i)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||e.config.themeSemantic?.secondary||"#999",opacity:b},datum:n.groups.get(i)?.pieces[0]??o.pieceData[0],category:"_default"===i?o.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(e,t){const{columns:n,getR:o,getStack:i,resolvePieceStyle:r,scales:s}=e,a=[],l=s.o.domain().map(e=>n[e]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const e of l)for(const t of e.pieceData){const e=i?i(t):"_default";u.has(e)||(u.add(e),c.push(e))}const d=c.length>1&&"_default"!==c[0],h=[];for(const e of l){const t=new Map;let n=0;for(const r of e.pieceData){const e=i?i(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const s=t.get(e),a=o(r);s.total+=a,s.pieces.push(r),n+=a}h.push({col:e,groups:t,stepTotal:n})}const f=new Map;for(const e of c){const t=h[0]?.groups.get(e);f.set(e,t?.total??0)}const p=s.r,g=d?c.length:1,y=d?.15:0;for(let e=0;h.length>e;e++){const t=h[e],n=t.col,o=0===e,i=e>0?h[e-1]:null,s=n.width/g,l=s*y,u=s-l;for(let e=0;c.length>e;e++){const h=c[e],g=t.groups.get(h);if(!g)continue;const y=g.total,m=f.get(h)??y,x=m>0?y/m*100:0,b=i?.groups.get(h),v=o?0:Math.max(0,(b?.total??y)-y),w=n.x+e*s+l/2,k=p(y),S=p(0)-k,A=r(g.pieces[0],d?h:n.name),M={...g.pieces[0],__barFunnelValue:y,__barFunnelPercent:x,__barFunnelIsFirstStep:o,__barFunnelIsDropoff:!1,__barFunnelStep:n.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:n.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(y+v)};if(a.push(ln(w,k,u,S,A,M,d?h:n.name)),v>0){const e=p(y+v),t=k-e,o={...A},i={...g.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:n.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:n.name};a.push(ln(w,e,u,t,o,i,d?h:n.name))}}}return a},swimlane:function(e,t){const{scales:n,columns:o,getR:i,getStack:r,resolvePieceStyle:s}=e,{r:a,projection:l}=n,c=[],u="horizontal"===l,d=e.config.gradientFill,h=u?"left":"bottom",f=e.config.trackFill;if(f){const e="string"==typeof f?f:f.color,t="string"==typeof f?1:f.opacity??1,[n,i]=a.range(),r=Math.min(n,i),s=Math.abs(i-n);for(const n of Object.values(o)){const o={fill:e,opacity:t},i=u?ln(r,n.x,s,n.width,o,null,"__track__"):ln(n.x,r,n.width,s,o,null,"__track__");c.push(i)}}const p=e.config.roundedTop&&e.config.roundedTop>0?Math.max(0,e.config.roundedTop):0;for(const e of Object.values(o)){let t=0;const n=c.length;for(const n of e.pieceData){const o=Math.abs(i(n));if(0===o)continue;const l=r?r(n):e.name,f=s(n,l);let p;if(u){const i=a(t),r=a(t+o);p=ln(i,e.x,r-i,e.width,f,n,l)}else{const i=a(t+o),r=a(t);p=ln(e.x,i,e.width,r-i,f,n,l)}d&&(p.fillGradient=d,p.roundedEdge=h),c.push(p),t+=o}if(p>0&&c.length>n){const e=c.slice(n),t=e[0],o=e[e.length-1];1===e.length?t.cornerRadii={tl:p,tr:p,br:p,bl:p}:u?(t.cornerRadii={tl:p,bl:p},o.cornerRadii={tr:p,br:p}):(t.cornerRadii={bl:p,br:p},o.cornerRadii={tl:p,tr:p})}}return c}},Qm=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Jm=["scene-style","data-paint","accessibility","evidence"],ex=(e,t)=>({retainedData:e,invalidations:t}),tx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],nx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ox=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ix=["scene-geometry","data-paint","accessibility","evidence"],rx=["scene-style","data-paint","accessibility","evidence"],sx=[],ax={chartType:ex("rebuild",tx),runtimeMode:ex("rebuild",tx),categoryAccessor:ex("rebuild",tx),valueAccessor:ex("rebuild",tx),oAccessor:ex("rebuild",tx),rAccessor:ex("rebuild",tx),stackBy:ex("rebuild",tx),groupBy:ex("rebuild",tx),timeAccessor:ex("rebuild",tx),accessorRevision:ex("rebuild",tx),colorAccessor:ex("rebuild",rx),symbolAccessor:ex("rebuild",ix),connectorAccessor:ex("rebuild",ix),dataIdAccessor:ex("rebuild",ix),projection:ex("preserve",nx),extentPadding:ex("preserve",nx),axisExtent:ex("preserve",nx),rExtent:ex("preserve",nx),oExtent:ex("preserve",nx),multiAxis:ex("preserve",nx),normalize:ex("preserve",nx),bins:ex("preserve",nx),oSort:ex("preserve",ox),barPadding:ex("preserve",ox),roundedTop:ex("preserve",ox),baselinePadding:ex("preserve",ox),innerRadius:ex("preserve",ox),cornerRadius:ex("preserve",ox),startAngle:ex("preserve",ox),sweepAngle:ex("preserve",ox),trackFill:ex("preserve",ox),showOutliers:ex("preserve",ox),showIQR:ex("preserve",ox),amplitude:ex("preserve",ox),connectorOpacity:ex("preserve",ox),showLabels:ex("preserve",ox),dynamicColumnWidth:ex("rebuild",ox),customLayout:ex("preserve",ox),layoutConfig:ex("preserve",ox),layoutMargin:ex("preserve",ox),symbolMap:ex("preserve",ix),pieceStyle:ex("preserve",rx),summaryStyle:ex("preserve",rx),connectorStyle:ex("preserve",rx),gradientFill:ex("preserve",rx),colorScheme:ex("preserve",rx),themeCategorical:ex("preserve",rx),themeSemantic:ex("preserve",rx),themeSequential:ex("preserve",rx),themeDiverging:ex("preserve",rx),barColors:ex("preserve",rx),decay:ex("preserve",rx),pulse:ex("preserve",rx),staleness:ex("preserve",rx),layoutSelection:ex("preserve",rx),windowSize:ex("preserve",sx),windowMode:ex("preserve",sx),clock:ex("preserve",sx),transition:ex("preserve",sx),introAnimation:ex("preserve",sx),onLayoutError:ex("preserve",sx)},lx=ex("preserve",ox),cx=class{constructor(){this.tracker=new Qn}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Qm)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Jm):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const n=new Set;for(const o of e){const e=ax[o]??lx;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}},ux=require("d3-quadtree"),dx=class{constructor(e){this.rExtent=new $t,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new cx,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new qm,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=e,this.buffer=new It(e.windowSize),this.getO=Ft(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>zt(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new $t)):(this.getR=zt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Ft(e.stackBy),this.getGroup=Ft(e.groupBy),this.getColor=Ft(e.colorAccessor),this.getSymbol=Ft(e.symbolAccessor),this.getConnector=Ft(e.connectorAccessor),this.getDataId=Ft(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new It(e.windowSize))}syncPulseTimestampBuffer(){var e,t,n,o;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,n=this.timestampBuffer,o=this.currentTime(),e?null!=n&&n.capacity===t.capacity&&n.size===t.size?n:Fn(t,o):null)}currentTime(){return this.config.clock?.()??Vt()}ingest(e){const t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),Dn(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const n of e.inserts)En(this.buffer,n,this.timestampBuffer,t),this.categories.add(this.getO(n)),this.pushValueExtent(n)}else{this._hasStreamingData=!0;for(const n of e.inserts){const e=En(this.buffer,n,this.timestampBuffer,t);this.categories.add(this.getO(n)),this.pushValueExtent(n),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){const t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;const n="function"==typeof t?t(e):e[t];return Array.isArray(n)&&n.length>=2?[+n[0],+n[1]]:null}computeScene(e){const{config:t,buffer:n}=this,o=this.scales,i=this.multiScales,r=this.columns;if(0===n.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(n,this.getR);const s=this.getBufferArray(),a=t.projection||"vertical",l=t.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===a?e.width:e.height):.1));let f,p;if(d){f=(0,Ym.scaleBand)().domain(l).range([0,1]).padding(0);const n=Math.min(e.width,e.height)/2,o=t.innerRadius||0;p=(0,Ym.scaleLinear)().domain(c).range([o,n])}else u?(f=(0,Ym.scaleBand)().domain(l).range([0,e.height]).padding(h),p=(0,Ym.scaleLinear)().domain(c).range([0,e.width])):(f=(0,Ym.scaleBand)().domain(l).range([0,e.width]).padding(h),p=(0,Ym.scaleLinear)().domain(c).range([e.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&t.multiAxis?this.rAccessors.map((o,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(n,o);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(t.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?(0,Ym.scaleLinear)().domain([s,a]).range([0,e.width]):(0,Ym.scaleLinear)().domain([s,a]).range([e.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(e=>this.rAccessors.map((t,n)=>({...e,__rIndex:n,__rValue:t(e),__rName:this.resolveRAccessorName(n)})))),this.columns=this.buildColumns(g,l,f,a,e),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=o,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){const t=this.config.valueAccessor||this.config.rAccessor,n=Array.isArray(t)?t[e]:t;return"string"==typeof n?n:"value"+e}resolveCategories(e){const t=this.config.oSort,n="streaming"===this.config.runtimeMode||this._hasStreamingData,o="auto"===t?void 0:t;let i=null;if(n){i=new Set;for(const t of e)i.add(this.getO(t))}const r=i?Array.from(this.categories).filter(e=>i.has(e)):Array.from(this.categories);if(n&&void 0===o){const e=Math.max(50,3*i.size);if(this.categories.size>e){let t=this.categories.size-e;for(const e of this.categories){if(0>=t)break;i.has(e)||(this.categories.delete(e),t--)}}return r}if(!1===o)return r;if("function"==typeof o)return r.sort(o);const s=new Map;for(const t of e){const e=this.getO(t);s.set(e,(s.get(e)||0)+Math.abs(this.getR(t)))}return r.sort("asc"===o?(e,t)=>(s.get(e)||0)-(s.get(t)||0):(e,t)=>(s.get(t)||0)-(s.get(e)||0))}computeValueDomain(e,t){return function(e){const{data:t,chartType:n,projection:o,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=e,f=s;if("radial"===o&&("pie"===n||"donut"===n))return[0,1];let p=0,g=0;if("bar"===n&&d&&i)p=0,g=1;else if("bar"===n&&d){const e=new Map,n=new Map;for(const o of t){const t=c(o),i=u(o);0>i?n.set(t,(n.get(t)||0)+i):e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>g&&(g=t);for(const e of n.values())p>e&&(p=e)}else if("bar"===n){const e=new Map;for(const n of t){const t=c(n),o=u(n);e.set(t,(e.get(t)||0)+o)}for(const t of e.values())t>g&&(g=t),p>t&&(p=t)}else if("swimlane"===n){const e=new Map;for(const n of t){const t=c(n),o=Math.abs(u(n));e.set(t,(e.get(t)||0)+o)}for(const t of e.values())t>g&&(g=t)}else if("clusterbar"===n||"bar-funnel"===n)for(const e of t){const t=u(e);t>g&&(g=t),p>t&&(p=t)}else{const e=h[0],t=h[1];e!==1/0&&(p=e),t!==-1/0&&(g=t)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===n||"clusterbar"===n||"bar-funnel"===n||"swimlane"===n;if(y&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>g&&(g=0)),"bar-funnel"!==n&&"exact"!==l){const e=g-p,t=e>0?e*f:1,o=y&&!a&&0===p,i=y&&!a&&0===g||"swimlane"===n;null!=r?.[0]||o||(p-=t),null!=r?.[1]||i||(g+=t)}return[p,g]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,n,o,i){return function(e){const{data:t,oExtent:n,oScale:o,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=e,c={},u=new Map;for(const e of t){const t=a(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===i)for(const e of t)d+=Math.abs(l(e));let h=null;if(s&&"radial"!==i){h=new Map;let e=0;for(const t of n){const n=u.get(t)||[];let o;o="string"==typeof s?n.reduce((e,t)=>e+(Number(t[s])||0),0):s(n),h.set(t,o),e+=o}const t=("horizontal"===i?r.height:r.width)-o.padding()*o.step()*n.length;if(e>0)for(const[n,o]of h)h.set(n,o/e*t)}let f=0,p=0;for(const e of n){const t=u.get(e)||[],n=t.reduce((e,t)=>e+Math.abs(l(t)),0),i=d>0?n/d:0;let r,s;h?(r=p,s=h.get(e)||o.bandwidth(),p+=s+o.padding()*o.step()):(r=o(e)??0,s=o.bandwidth()),c[e]={name:e,x:r,y:0,width:s,middle:r+s/2,padding:o.padding()*o.step(),pieceData:t,pct:i,pctStart:f},f+=i}return c}({data:e,oExtent:t,oScale:n,projection:o,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){const n=this.buildLayoutContext(e,t);let o;try{o=this.config.customLayout(n)}catch(e){const t=null!==this.lastCustomLayoutResult,n=Ln("ordinal",e,t,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",e);try{this.config.onLayoutError?.(n)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return t?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=o.overlays??null,this.lastCustomLayoutResult=o,this.lastCustomLayoutFailure=null;const i=o.nodes??[];if(this._customRestyle=o.restyle,this.hasCustomRestyle=!!o.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const e of i)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return jn({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const n=this.getSceneContext(),o=Zm[this.config.chartType];let i=o?o(n,t):[];if(this.getConnector&&this.scales){const e=function(e,t){const{scales:n,config:o,getConnector:i,getO:r}=e;if(!i||!n)return[];const s=[],{projection:a}=n,l=new Map;for(const e of t){if("point"!==e.type&&"rect"!==e.type)continue;const t=e.datum;if(!t)continue;const n=i(t);if(!n)continue;let o,s;"point"===e.type?(o=e.x,s=e.y):(o=e.x+e.w/2,s=e.y+("vertical"===a?0:e.h/2)),l.has(n)||l.set(n,[]),l.get(n).push({x:o,y:s,datum:t,category:r(t)})}const c=n.o.domain(),u=o.connectorStyle;for(const[t,n]of l)if(n.length>=2){n.sort((e,t)=>c.indexOf(e.category)-c.indexOf(t.category));for(let o=0;n.length-1>o;o++){const i=n[o],r=n[o+1],a="function"==typeof u?u(i.datum):u||{stroke:e.config.themeSemantic?.border||e.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:t})}}return s}(n,i);i=[...e,...i]}return i}buildLayoutContext(e,t){const n=this.config,o=n.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Tg(n.colorScheme,n.themeCategorical,fe),r=this.scales;return{data:e,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:t.width,height:t.height,margin:o,plot:"radial"===r.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:n.themeSemantic??{},categorical:[...i]},resolveColor:Ig(i,n.colorScheme),config:n.layoutConfig??{},selection:n.layoutSelection??null}}computeDecayOpacity(e,t){const n=this.config.decay;return n&&t>1?Ut(n,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const t=Kt(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const t=function(e,t){const n="function"==typeof t,o=n?null:t||"category",i=new Map;for(let r=0;e.length>r;r++){const s=e[r],a=n?t(s):s[o],l=i.get(a);l?l.push(r):i.set(a,[r])}return i}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){const e=function(e){let t=0,n=0;for(const o of e)"point"===o.type&&(t++,o.r>n&&(n=o.r));if(500>=t)return{quadtree:null,maxRadius:n};const o=Array(t);let i=0;for(const t of e)"point"===t.type&&(o[i++]=t);return{maxRadius:n,quadtree:(0,ux.quadtree)().x(e=>e.x).y(e=>e.y).addAll(o)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;const n=t.length;if(1>=n)return;const o=this.getDatumIndexMap(t);for(const t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type)continue;if(!t.datum)continue;const e=o.get(t.datum);if(null==e)continue;const i=this.computeDecayOpacity(e,n);t.style={...t.style,opacity:(t.style?.opacity??1)*i}}}applyPulse(e,t,n=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,n,o,i,r){const s=e.color??"rgba(255,255,255,0.6)",a=e.glowRadius??4;let l=!1;for(const c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const t=c.category;if(!t)continue;let o=0;for(const s of i(t)??[]){const t=n.get(s);null!=t&&(o=Math.max(o,Zt(e,t,r)))}l=Qt(c,o,s)||l;continue}if(null==c.datum)continue;const t=o.get(c.datum);if(null==t)continue;const u=n.get(t);l=Qt(c,null==u?0:Zt(e,u,r),s,a)||l}return l}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),n)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&Jt(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const e=new Map,t=this.scales?.r(0)??0,n="horizontal"!==this.scales?.projection;let o;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,e);s&&("rect"===r.type?this.prevPositionMap.set(s,n?{x:r.x,y:t,w:r.w,h:0,opacity:r.style.opacity??1}:{x:t,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===o&&(o=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:o,endAngle:o,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){const n=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,o=t.get(n)||0;return t.set(n,o+1),`${n}:${o}`}if("rect"===e.type){const n=e.datum?null!=e.datum.category&&""!==e.datum.category?e.datum.category+"":(this.getO(e.datum)??"")+"":"",o=`r:${e.group||""}:${n}`,i=t.get(o)||0;return t.set(o,i+1),0===i?o:`${o}:${i}`}return"wedge"===e.type?"w:"+(e.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const e=new Map;for(let t=0;this.scene.length>t;t++){const n=this.scene[t],o=this.getNodeKey(n,e);o&&("point"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,r:n.r,opacity:n.style.opacity??n.style.fillOpacity}):"rect"===n.type?this.prevPositionMap.set(o,{x:n.x,y:n.y,w:n.w,h:n.h,opacity:n.style.opacity??n.style.fillOpacity}):"wedge"===n.type&&this.prevPositionMap.set(o,{x:n.cx,y:n.cy,startAngle:n.startAngle,endAngle:n.endAngle,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:n.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const e=this.config.transition.duration??300;if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1;const n=new Set,o=new Map;for(let e=0;this.scene.length>e;e++){const i=this.scene[e],r=this.getNodeKey(i,o);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),t=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},t=!0);else if("rect"===i.type)s?(n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,t=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},t=!0);else if("wedge"===i.type)if(s)n.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,t=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const e=i.startAngle;i.startAngle=e,i.endAngle=e,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:e,endAngle:e,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(const[e,o]of this.prevPositionMap)if(!n.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:o.x,y:o.y,r:o.r??3,style:{opacity:o.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:o.x,y:o.y,w:o.w??0,h:o.h??0,style:{opacity:o.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){const t=((o.startAngle??0)+(o.endAngle??0))/2,n={type:"wedge",cx:o.x,cy:o.y,innerRadius:o.innerRadius??0,outerRadius:o.outerRadius??100,startAngle:o.startAngle??0,endAngle:o.endAngle??0,style:{opacity:o.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(n)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;const t=Ht(e,this.activeTransition),n=Xt(t,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const e of this.scene){const t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){const o=this.prevPositionMap.get(t);e.style.opacity=Gt(o?o.opacity??1:0,e._targetOpacity,n)}const o=this.prevPositionMap.get(t);void 0!==e._targetX&&o&&(e.x=Gt(o.x,e._targetX,n),e.y=Gt(o.y,e._targetY,n)),void 0!==e._targetR&&void 0!==o?.r&&(e.r=Gt(o.r,e._targetR,n))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const o=this.prevPositionMap.get(t);e.style.opacity=Gt(o?o.opacity??1:0,e._targetOpacity,n)}if(void 0===e._targetX)continue;const o=this.prevPositionMap.get(t);if(!o)continue;e.x=Gt(o.x,e._targetX,n),e.y=Gt(o.y,e._targetY,n),void 0!==o.w&&(e.w=Gt(o.w,e._targetW,n),e.h=Gt(o.h,e._targetH,n))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){const o=this.prevPositionMap.get(t);e.style={...e.style,opacity:Gt(o?o.opacity??1:0,e._targetOpacity,n)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){const o=this.prevPositionMap.get(t);o&&void 0!==o.startAngle&&(e.startAngle=Gt(o.startAngle,e._targetStartAngle,n),e.endAngle=Gt(o.endAngle,e._targetEndAngle,n))}}}if(t>=1){for(const e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(e){for(const t of e){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}"point"===t.type?void 0!==t._targetX?(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0):void 0!==t._targetR&&(t.r=t._targetR,t._targetR=void 0):"rect"===t.type?void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0):"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const t=qt(e),n=this.getDataId,o=e=>t.has(n(e));Nn(this.buffer,this.timestampBuffer,o);const i=this.buffer.remove(o);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const e of i)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const n=qt(e),o=this.getDataId,i=new Set;this.buffer.forEach((e,t)=>{n.has(o(e))&&i.add(t)});const r=this.buffer.update(e=>n.has(o(e)),t);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const e of r)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),i.has(t)&&this.pushValueExtent(e)}),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(e,t){const n=this._customRestyle;if(n)for(const o of e){const e=this._baseStyles.get(o)??o.style??{},i=n(o,t);o.style=i?{...e,...i}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){const t={...this.config},n=Object.keys(e).filter(n=>e[n]!==t[n]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!Ot(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!Ot(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!Ot(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let o=!1;("categoryAccessor"in e||"oAccessor"in e)&&(Ot(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=Ft(this.config.categoryAccessor||this.config.oAccessor,"category"),o=!0));let i=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,n=t.valueAccessor||t.rAccessor,o=Array.isArray(e)?e:[e],r=Array.isArray(n)?n:[n];if(i=o.length!==r.length||o.some((e,t)=>!Ot(e,r[t])),i){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>zt(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new $t)):(this.getR=zt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!Ot(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?Ft(this.config.stackBy):void 0),"groupBy"in e&&!Ot(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?Ft(this.config.groupBy):void 0),"colorAccessor"in e&&!Ot(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Ft(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!Ot(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Ft(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!Ot(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Ft(this.config.connectorAccessor):void 0),(o||i||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(n)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};Vn(dx);var hx=require("react/jsx-runtime"),fx=require("react/jsx-runtime");function px(e,t){const n=et(e.theme),o=e.size||[500,400],i=Ks({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=Vs(e.title),s=z(e.data),a=e.showLegend?bm(s,e.colorAccessor||e.stackBy||e.groupBy):[],l=e.projection||"vertical",c={hasAxis:!1!==e.showAxes&&"radial"!==l,hasAxisLabel:"horizontal"===l?!(!e.valueLabel&&!e.rLabel):!(!e.categoryLabel&&!e.oLabel)};zm(i,{props:{...e,axisChrome:c},categories:a,theme:n,size:o,hasTitle:r});const u=o[0]-i.left-i.right,d=o[1]-i.top-i.bottom,h=e.projection||"vertical",f="radial"===h,p=e.colorScheme||n.colors.categorical,g={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:h,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:Ie(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:p,themeCategorical:n.colors.categorical,themeSemantic:qe(n),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,layoutSelection:e.layoutSelection,barColors:e.barColors},y=new dx(g);if(e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d}),!y.scales||0===y.scene.length)return t&&(t.evidence=rm({frameType:"ordinal",width:o[0],height:o[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Wm.renderToStaticMarkup(Em(null,{width:o[0],height:o[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,idPrefix:e._idPrefix}));const m=e._idPrefix,x=e.showGrid?function(e,t,n,o,i){const r=e.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=tt(n),a=o?o+"-":"",l="vertical"===r.projection,c=Fs(r.r,5,i);return(0,Cm.jsx)("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((e,n)=>{const o=r.r(e);return(0,Cm.jsx)("line",{x1:0,y1:o,x2:t.width,y2:o,stroke:s,strokeWidth:.5},"gr-"+n)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((e,n)=>{const o=r.r(e);return(0,Cm.jsx)("line",{x1:o,y1:0,x2:o,y2:t.height,stroke:s,strokeWidth:.5},"gr-"+n)})})}(y,{width:u,height:d},n,m,e.axisExtent):null;let b=null;if(y.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){const t=Lm(e),o=new Set;for(const e of y.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&o.add("string"==typeof e.style.fill?e.style.fill:"#666");b=Array.from(o).map((e,o)=>function(e){const{id:t,background:n="transparent",stroke:o="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=e,a=Math.max(8,Math.ceil(2*r));return(0,hx.jsxs)("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&(0,hx.jsx)("rect",{width:a,height:a,fill:n}),(0,hx.jsx)("line",{x1:0,y1:0,x2:0,y2:a,stroke:o,strokeWidth:i}),(0,hx.jsx)("line",{x1:r,y1:0,x2:r,y2:a,stroke:o,strokeWidth:i})]},t)}({id:`funnel-hatch-${t}-${o}`,background:e,stroke:"transparent"===n.colors.background?"#fff":n.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(o).forEach((e,n)=>i.set(e,`funnel-hatch-${t}-${n}`));for(const e of y.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${i.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}const v=Dc({nodes:y.scene,renderMode:e.renderMode,fallback:(e,t)=>Pa(e,t,m)}),w=v.map(e=>e.element);if(t){const n=y.scales.o?.domain?.();t.evidence=rm({frameType:"ordinal",width:o[0],height:o[1],marks:v.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:im(y.scales.r?.domain?.()),categories:Array.isArray(n)?n.map(String):void 0,margin:i})}const k=!1!==e.showAxes?function(e,t,n,o,i){const r=e.scales;if(!r)return null;if("radial"===r.projection)return null;const s=tt(o),a="vertical"===r.projection,l=n.categoryFormat||n.oFormat,c=n.valueFormat||n.rFormat,u=n.categoryLabel||n.oLabel,d=n.valueLabel||n.rLabel,h=Object.values(e.columns).map(e=>({pixel:e.middle,label:(l||String)(e.name)})),f=Fs(r.r,5,n.axisExtent).map(e=>({pixel:r.r(e),label:(c||Fm)(e)}));return(0,fx.jsxs)("g",a?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[(0,fx.jsx)("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),h.map((e,n)=>(0,fx.jsxs)("g",{transform:`translate(${e.pixel},${t.height})`,children:[(0,fx.jsx)("line",{y2:5,stroke:s.border,strokeWidth:1}),(0,fx.jsx)("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oxtick-"+n)),u&&(0,fx.jsx)("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),(0,fx.jsx)("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),f.map((e,t)=>(0,fx.jsxs)("g",{transform:`translate(0,${e.pixel})`,children:[(0,fx.jsx)("line",{x2:-5,stroke:s.border,strokeWidth:1}),(0,fx.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oytick-"+t)),d&&(0,fx.jsx)("text",{x:15-(n.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(n.margin?.left??40)}, ${t.height/2})`,children:d})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[(0,fx.jsx)("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),f.map((e,n)=>(0,fx.jsxs)("g",{transform:`translate(${e.pixel},${t.height})`,children:[(0,fx.jsx)("line",{y2:5,stroke:s.border,strokeWidth:1}),(0,fx.jsx)("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oxtick-"+n)),d&&(0,fx.jsx)("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:d}),(0,fx.jsx)("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),h.map((e,t)=>(0,fx.jsxs)("g",{transform:`translate(0,${e.pixel})`,children:[(0,fx.jsx)("line",{x2:-5,stroke:s.border,strokeWidth:1}),(0,fx.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oytick-"+t)),u&&(0,fx.jsx)("text",{x:15-(n.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(n.margin?.left??40)}, ${t.height/2})`,children:u})]})}(y,{width:u,height:d},e,n,m):null,S=e.annotations?Pm({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:u,height:d},theme:n,projection:h,idPrefix:m}):null,A=Dm({props:{...e,axisChrome:c},categories:a,theme:n,size:o,margin:i,hasTitle:r}),M=f?i.left+u/2:i.left,_=f?i.top+d/2:i.top,P=f&&e.centerContent?(0,fx.jsx)("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:(0,fx.jsx)("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return Wm.renderToStaticMarkup(Em((0,fx.jsxs)(fx.Fragment,{children:[e.backgroundGraphics,x,w,k,S,e.foregroundGraphics,y.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${M},${_})`,innerWidth:u,innerHeight:d,legend:A,defs:b,outerElements:P,idPrefix:e._idPrefix}))}var gx=g(require("react-dom/server"));function yx(e,t){var n=e.get(t);if(!n)throw Error("missing: "+t);return n}function mx(e,t){var n,o=[],i=[],r=[],s={},a=[];function l(e){r[e]=!1,s.hasOwnProperty(e)&&Object.keys(s[e]).forEach(function(t){delete s[e][t],r[t]&&l(t)})}function c(e){var t,o,d=!1;for(i.push(e),r[e]=!0,t=0;a[e].length>t;t++)(o=a[e][t])===n?(u(n,i),d=!0):r[o]||(d=c(o));if(d)l(e);else for(t=0;a[e].length>t;t++){var h=s[o=a[e][t]];h||(s[o]=h={}),h[o]=!0}return i.pop(),d}function u(e,n){var i=[].concat(n).concat(e);t?t(i):o.push(i)}function d(t){!function(t){for(var n=0;e.length>n;n++)n>=t&&e[n]||(e[n]=[]),e[n]=e[n].filter(function(e){return e>=t})}(t);for(var n,o=function(e){for(var t=e.length,n=Array(t),o=Array(t),i=Array(t),r=Array(t),s=Array(t),a=Array(t),l=0;t>l;++l)n[l]=-1,o[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function f(t){var l=[t],c=[t];for(n[t]=o[t]=u,i[t]=!0,u+=1;c.length>0;){var f=e[t=c[c.length-1]];if(f.length>r[t]){for(var p=r[t];f.length>p;++p){var g=f[p];if(0>n[g]){n[g]=o[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(o[t]=0|Math.min(o[t],o[g])),0>s[g]||a[t].push(s[g])}r[t]=p}else{if(o[t]===n[t]){var y=[],m=[],x=0;for(p=l.length-1;p>=0;--p){var b=l[p];if(i[b]=!1,y.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===t){l.length=p;break}}d.push(y);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];h.push(v)}c.pop()}}}for(l=0;t>l;++l)0>n[l]&&f(l);for(l=0;h.length>l;l++){var p=h[l];if(0!==p.length){p.sort(function(e,t){return e-t}),c=[p[0]];for(var g=1;p.length>g;g++)p[g]!==p[g-1]&&c.push(p[g]);h[l]=c}}return{components:d,adjacencyList:h}}(e),i=o.components.filter(function(e){return e.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],n=s);var l=i[n];return!!l&&{leastVertex:r,adjList:e.map(function(e,t){return-1===l.indexOf(t)?[]:e.filter(function(e){return-1!==l.indexOf(e)})})}}n=0;for(var h=e.length;h>n;){var f=d(n);if(n=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var g=0;a[p].length>g;g++){var y=a[p][g];r[+y]=!1,s[y]={}}c(n),n+=1}else n=h}return t?void 0:o}function xx(e){return e.y0-e.y1>0?"up":"down"}function bx(e,t){return t(e.source)==t(e.target)}function vx(e){var t=0;e.source.sourceLinks.forEach(function(e){t=e.circular?t+1:t});var n=0;return e.target.targetLinks.forEach(function(e){n=e.circular?n+1:n}),1>=t&&1>=n}function wx(e){return e.target.x0-e.source.x1}function kx(e,t){var n=Ax(e),o=wx(t)/Math.tan(n);return"up"==xx(e)?e.y1-o:e.y1+o}function Sx(e,t){var n=Ax(e),o=wx(t)/Math.tan(n);return"up"==xx(e)?e.y1+o:e.y1-o}function Ax(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function Mx(e,t){return t(e)}function _x(e){return jx(e.source)}function Px(e){return jx(e.target)}function jx(e){return(e.y0+e.y1)/2}function Cx(e){return e.virtual?0:e.value}function Rx(e,t){var n=0;e.sourceLinks.forEach(function(e){n=e.circular&&!bx(e,t)?n+1:n});var o=0;return e.targetLinks.forEach(function(e){o=e.circular&&!bx(e,t)?o+1:o}),n+o}function Lx(e){return e.target.depth}function Tx(e,t){return e.sourceLinks.length?e.depth:t-1}function Ix(e,t){return e.y0-t.y0}function $x(e,t){return t.y0-e.y0}function Ox(e,t){return e.y1-t.y1}function zx(e,t){return t.y1-e.y1}function Dx(e,t){return Ex(e.source,t.source)||e.index-t.index}function Fx(e,t){return Ex(e.target,t.target)||e.index-t.index}function Ex(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function Nx(e,t){return Bx(e)==Bx(t)?"bottom"==e.circularLinkType?$x(e,t):Ix(e,t):Bx(t)-Bx(e)}function Bx(e){return e.target.column-e.source.column}function Wx(e,t){return Yx(e)==Yx(t)}function Yx(e){return e.y0-e.y1>0?"up":"down"}var qx=require("d3-array");function Xx(e,t,n,o,i){let r=e;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,s))});var a=(0,qx.min)(r.links,function(e){return e.source.y0});r.links.forEach(function(e){e.circular&&(e.circularPathData={})});var l=r.links.filter(function(e){return e.circular});return l.sort(function(e,t){return t.value-e.value}),l.forEach(function(e,t){e._circularStub=t>=4}),Hx(r.links.filter(function(e){return"top"==e.circularLinkType}),t,n),Hx(r.links.filter(function(e){return"bottom"==e.circularLinkType}),t,n),r.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+o,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,bx(e,t)&&vx(e))e.circularPathData.rightSmallArcRadius=o+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=o+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=o+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=o+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+i+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-i-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var s=e.source.column,l=e.circularLinkType,c=r.links.filter(function(e){return e.source.column==s&&e.circularLinkType==l});c.sort("bottom"==e.circularLinkType?$x:Ix);var u=0;c.forEach(function(t,i){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=o+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=o+e._circularWidth/2+i*n+u),u+=t._circularWidth||t.width}),s=e.target.column,(c=r.links.filter(function(e){return e.target.column==s&&e.circularLinkType==l})).sort("bottom"==e.circularLinkType?zx:Ox),u=0,c.forEach(function(t,i){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=o+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=o+e._circularWidth/2+i*n+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(r.y1,e.source.y1,e.target.y1)+i+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=a-i-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)}e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer}e.path=e.circular?function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):function(e){var t=e.source.x1,n=e.y0,o=e.target.x0,i=e.y1,r=(t+o)/2;return"M"+t+","+n+"C"+r+","+n+" "+r+","+i+" "+o+","+i}(e)}),r}function Hx(e,t,n){e.sort(Nx);var o=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,i){var r=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(bx(e,t)&&vx(e))e.circularPathData.verticalBuffer=r+e._circularWidth/2;else{for(var s=0;o.length>s;s++){var a=o[s];if(a!==e&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&Gx(e,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+n;r=l>r?l:r}}e.circularPathData.verticalBuffer=r+e._circularWidth/2}}),e}function Gx(e,t){return e.source.column>=t.target.column&&t.source.column>=e.target.column}var Vx=require("d3-array");function Ux(e){return function(){return e}}function Kx(e){return e.index}function Zx(e){return e.nodes}function Qx(e){return e.links}function Jx(e,t,n){var o=(0,Vx.groups)(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});o.forEach(function(i,r){var s=i.length;if(t)i.sort(t);else if(r>0){var a=new Map;i.forEach(function(e,t){var n,o,i,r=(o=0,i=0,(n=e).targetLinks.forEach(function(e){if(!e.circular){var t=e.value||1;i+=jx(e.source)*t,o+=t}}),n.sourceLinks.forEach(function(e){if(!e.circular){var t=e.value||1;i+=jx(e.target)*t,o+=t}}),o>0?i/o:NaN);a.set(e,{bc:r,idx:t})}),i.sort(function(e,t){var n=a.get(e),o=a.get(t),i=n.bc,r=o.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(i)||isNaN(r)?isNaN(i)?isNaN(r)?n.idx-o.idx:1:-1:i-r})}else i.sort(function(e,t){return e.circularLinkType==t.circularLinkType?Rx(t,n)-Rx(e,n):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});i.forEach(function(t,i){t.depth==o.length-1&&1==s||0==t.depth&&1==s?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==Rx(t,n)?(t.y0=e.y1/2+i,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+i,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-i,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/s*i,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-s/2+i,t.y1=t.y0+t.value*e.ky)})})}function eb(e,t,n,o,i,r){var s=(0,Vx.groups)(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var a=1,l=r;l>0;--l)c(a*=.99,n),u();function c(t,n){var o=s.length;s.forEach(function(i){var r=i.length,s=i[0].depth;i.forEach(function(i){var a;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&Rx(i,n)>0){var l=(0,Vx.mean)(i.sourceLinks,Px),c=(0,Vx.mean)(i.targetLinks,_x),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-jx(i))*t*.3;i.y0+=d,i.y1+=d}}else if(0==s&&1==r)i.y0=e.y1/2-(a=i.y1-i.y0)/2,i.y1=e.y1/2+a/2;else if(s==o-1&&1==r)i.y0=e.y1/2-(a=i.y1-i.y0)/2,i.y1=e.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=(0,Vx.mean)(i.sourceLinks,Px),f=(0,Vx.mean)(i.targetLinks,_x),p=((h&&f?(h+f)/2:h||f)-jx(i))*t;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(n){var r,s,a,l=e.y0,c=n.length;for(n.sort(t||Ex),a=0;c>a;++a)(s=l-(r=n[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+o;if((s=l-o-e.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=n[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function tb(e){e.nodes.forEach(function(e){e.sourceLinks.sort(Fx),e.targetLinks.sort(Dx)}),e.nodes.forEach(function(e){var t=e.y0,n=t,o=e.y1,i=o;e.sourceLinks.forEach(function(e){e.circular?(e.y0=o-e.width/2,o-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=i-e.width/2,i-=e.width):(e.y1=n+e.width/2,n+=e.width)})})}function nb(){var e=0,t=0,n=1,o=1,i=24,r=8,s=null,a=Kx,l=Tx,c=void 0,u=32,d=2,h=Zx,f=Qx;function p(){var p={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return function(h){h.x0=e,h.y0=t,h.x1=n,h.y1=o,h.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var n=function(e,t){var n=new Map;return(0,Vx.group)(e,t).forEach(function(e,t){n.set(t,e[0])}),n}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var o=e.source,i=e.target;"object"!=typeof o&&(o=e.source=yx(n,o)),"object"!=typeof i&&(i=e.target=yx(n,i)),o.sourceLinks.push(e),i.targetLinks.push(e)})}(h,a),function(e,t){var n=0;if(null==t){for(var o=[],i=0;e.links.length>i;i++){var r=e.links[i],s=r.source.index,a=r.target.index;o[s]||(o[s]=[]),o[a]||(o[a]=[]),-1===o[s].indexOf(a)&&o[s].push(a)}var l=mx(o);l.sort(function(e,t){return e.length-t.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,o=e.source.index;t===o||c[o]&&c[o][t]?(e.circular=!0,e.circularLinkID=n++):e.circular=!1})}else e.links.forEach(function(e){t(e.source)<t(e.target)?e.circular=!1:(e.circular=!0,e.circularLinkID=n++)})}(h,c),function(e,t){var n=0,o=0;e.links.forEach(function(i){i.circular&&(i.circularLinkType=i.source.circularLinkType||i.target.circularLinkType?i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:o>n?"top":"bottom","top"==i.circularLinkType?n++:o++,e.nodes.forEach(function(e){Mx(e,t)!=Mx(i.source,t)&&Mx(e,t)!=Mx(i.target,t)||(e.circularLinkType=i.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),bx(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(h,a),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max((0,Vx.sum)(e.sourceLinks,Cx),(0,Vx.sum)(e.targetLinks,Cx)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(h),function(e,t,n){var o,i,r;if(null!=t){e.nodes.sort(function(e,n){return t(e)<t(n)?-1:1});var s=0,a=t(e.nodes[0]);e.nodes.forEach(function(e){s=t(e)==a?s:s+1,a=t(e)==a?a:t(e),e.column=s})}for(o=e.nodes,i=[],r=0;o.length;++r,o=i,i=[])o.forEach(function(e){e.depth=r,e.sourceLinks.forEach(function(e){0>i.indexOf(e.target)&&!e.circular&&i.push(e.target)})});for(o=e.nodes,i=[],r=0;o.length;++r,o=i,i=[])o.forEach(function(e){e.height=r,e.targetLinks.forEach(function(e){0>i.indexOf(e.source)&&!e.circular&&i.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?n(e,r):e.column})}(h,c,l);var f=r;if(null!==s){var p=(0,Vx.groups)(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=(0,Vx.max)(p,function(e){return e.length});g>1&&(f=Math.max(1,(o-t)*s/(g-1)))}(function(e,t,n){var o=(0,Vx.groups)(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var i=(0,Vx.min)(o,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/(0,Vx.sum)(t,function(e){return e.value})});e.ky=i,e.links.forEach(function(t){t.width=t.value*e.ky});var r=(0,Vx.max)(e.nodes,function(e){return e.column});e.nodes.forEach(r>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-n)/r),t.x1=t.x0+n}:function(t){t.x0=e.x0,t.x1=t.x0+n})})(h,f,i),Jx(h,c,a),eb(h,c,a,f,f,u),tb(h),Xx(h,a,d,10,8),Jx(h,c,a),eb(h,c,a,f,f,u),tb(h),Xx(h,a,d,10,8),function(e,t){let n=e;n.nodes.forEach(function(e){e.y+(e.y1-e.y0)>n.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-n.y1));var o=n.links.filter(function(n){return Mx(n.source,t)==Mx(e,t)}),i=o.length;i>1&&o.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!Wx(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var n=kx(t,e);return e.y1-n}if(t.target.column>e.target.column)return kx(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var r=e.y0;o.forEach(function(e){e.y0=r+e.width/2,r+=e.width}),o.forEach(function(t,n){if("bottom"==t.circularLinkType){for(var r=n+1,s=0;i>r;r++)s+=o[r].width;t.y0=e.y1-s-t.width/2}})})}(h,a),function(e,t){let n=e;n.nodes.forEach(function(e){var o=n.links.filter(function(n){return Mx(n.target,t)==Mx(e,t)}),i=o.length;i>1&&o.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!Wx(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var n=Sx(t,e);return e.y0-n}if(t.source.column>e.source.column)return Sx(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var r=e.y0;o.forEach(function(e){e.y1=r+e.width/2,r+=e.width}),o.forEach(function(t,n){if("bottom"==t.circularLinkType){for(var r=n+1,s=0;i>r;r++)s+=o[r].width;t.y1=e.y1-s-t.width/2}})})}(h,a),function(e){var t=e.nodes,n=e.links,o=!1,i=!1;if(n.forEach(function(e){"top"==e.circularLinkType?o=!0:"bottom"==e.circularLinkType&&(i=!0)}),0==o||0==i){let o=function(t){return(t-r)/(s-r)*(e.y1-e.y0)+e.y0};var r=(0,Vx.min)(t,function(e){return e.y0}),s=(0,Vx.max)(t,function(e){return e.y1}),a=(e.y1-e.y0)/(s-r);1>a?(t.forEach(function(e){e.y0=o(e.y0),e.y1=o(e.y1)}),n.forEach(function(e){e.y0=o(e.y0),e.y1=o(e.y1),e.width=e.width*a})):t.forEach(function(e){var t=e.y1-e.y0,n=o(e.y0)-e.y0;e.y0=o(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+n}),e.targetLinks.forEach(function(e){e.y1=e.y1+n})})}}(h),Xx(h,a,d,10,8)}(p),p}return p.update=function(e){return tb(e),Xx(e,a,d,10,8),e},p.nodeWidth=function(e){return arguments.length?(i=+e,p):i},p.nodePadding=function(e){return arguments.length?(r=+e,p):r},p.nodePaddingRatio=function(e){return arguments.length?(s=+e,p):s},p.nodes=function(e){return arguments.length?(h="function"==typeof e?e:Ux(e),p):h},p.links=function(e){return arguments.length?(f="function"==typeof e?e:Ux(e),p):f},p.nodeId=function(e){return arguments.length?(a="function"==typeof e?e:Ux(e),p):a},p.nodeAlign=function(e){return arguments.length?(l="function"==typeof e?e:Ux(e),p):l},p.nodeSort=function(e){return arguments.length?(c=e,p):c},p.iterations=function(e){return arguments.length?(u=+e,p):u},p.circularLinkGap=function(e){return arguments.length?(d=+e,p):d},p.extent=function(i){return arguments.length?(e=+i[0][0],t=+i[0][1],n=+i[1][0],o=+i[1][1],p):[[e,t],[n,o]]},p.size=function(i){return arguments.length?(e=t=0,n=+i[0],o=+i[1],p):[n-e,o-t]},p}var ob=require("d3-interpolate"),ib=(require("d3-shape"),.5),rb=e=>{let t,n,o,i,r,s,a,l,c;if("down"===e.direction)return t=e.y0-e.sankeyWidth/2,n=e.y1-e.sankeyWidth/2,o=e.y1+e.sankeyWidth/2,i=e.y0+e.sankeyWidth/2,r=e.source.x1,s=e.target.x0,a=(0,ob.interpolateNumber)(r,s),l=a(ib),c=a(.5),`M${t},${r}C${t},${l} ${n},${c} ${n},${s}L${o},${s}C${o},${c} ${i},${l} ${i},${r}Z`;const u=e.sankeyWidth/2,d=(0,ob.interpolateNumber)(e.source.x1,e.target.x0),{pathD:h}=uf({sx:e.source.x1,sTop:e.y0-u,sBot:e.y0+u,tx:e.target.x0,tTop:e.y1-u,tBot:e.y1+u,cp1X:d(ib),cp2X:d(.5)});return h};function sb(e){const t=e.sankeyWidth/2,n=(e._circularWidth??e.sankeyWidth)/2,o=e.circularPathData;if(!o)return null;if("down"===e.direction)return null;if(e._circularStub){const n=o.sourceX,i=o.sourceY,r=o.targetX,s=o.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;const a=Math.max(15,Math.min(40,.33*(o.rightFullExtent-n))),l=Math.max(15,Math.min(40,.33*(r-o.leftFullExtent)));return`M${n},${i-t}L${n+a},${i-t}L${n+a},${i+t}L${n},${i+t}ZM${r},${s-t}L${r-l},${s-t}L${r-l},${s+t}L${r},${s+t}Z`}const i=o.sourceX,r=o.sourceY,s=o.targetX,a=o.targetY,l=o.rightFullExtent,c=o.leftFullExtent,u=o.verticalFullExtent,d="bottom"===e.circularLinkType?1:-1,h=Math.max(4,Math.min(n,15));return`M${i},${r-d*t}L${l},${r-d*t}L${l+n},${r-d*t+d*h}L${l+n},${u+d*n-d*h}L${l+n-h},${u+d*n}L${c-n+h},${u+d*n}L${c-n},${u+d*n-d*h}L${c-n},${a-d*t+d*h}L${c-n+h},${a-d*t}L${s},${a-d*t}L${s},${a+d*t}L${c+n},${a+d*t}L${c+n},${u-d*n}L${l-n},${u-d*n}L${l-n},${r+d*t}L${i},${r+d*t}Z`}var ab=new Set,lb=new WeakMap;function cb(e,t){if("production"===process.env.NODE_ENV)return e;if(!e||!e.data||"object"!=typeof e.data)return e;let n=lb.get(e);if(n){const e=n.get(t);if(e)return e}else n=new Map,lb.set(e,n);const o=new Proxy(e,{get(e,n,o){if("string"==typeof n&&!(n in e)&&e.data&&n in e.data){const e=`${t}:${n}`;ab.has(e)||(ab.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${n}" on the wrapper object, but it only exists on ".data". Use d.data.${n} (or d.data?.${n}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,n,o)}});return n.set(t,o),o}var ub={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(Lx))-1:0},justify:Tx},db={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,n,o){if(0===e.length)return;const i="vertical"===n.orientation?"down":"right",r=n.nodeAlign||"justify",s=n.nodeWidth??15,a=n.nodePaddingRatio??.05,l=n.iterations??100,c=e.map(e=>({...e})),u=t.map(e=>({...e,source:Nt(e.source),target:Nt(e.target),value:Math.sqrt(Math.max(1,e.value||1))}));let d;d="down"===i?[[0,0],[o[1],o[0]]]:[[0,0],[o[0],o[1]]];const h=nb().extent(d).links(u).nodes(c).nodeAlign(ub[r]||Tx).nodeId(e=>e.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let e=1/0,t=-1/0,n=1/0,i=-1/0;for(const o of c)e>o.x0&&(e=o.x0),o.x1>t&&(t=o.x1),n>o.y0&&(n=o.y0),o.y1>i&&(i=o.y1);for(const o of u){if(!o.circular||!o.circularPathData)continue;const r=o.circularPathData,s=(o._circularWidth??o.width??0)/2;e>r.leftFullExtent-s&&(e=r.leftFullExtent-s),r.rightFullExtent+s>t&&(t=r.rightFullExtent+s),n>r.verticalFullExtent-s&&(n=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=t-e,s=i-n,a=o[0],l=o[1];if(r>0&&s>0&&(0>e||0>n||t>a||i>l)){const t=Math.min(a/r,l/s),o=-e*t+(a-r*t)/2,i=-n*t+(l-s*t)/2;for(const e of c)e.x0=e.x0*t+o,e.x1=e.x1*t+o,e.y0=e.y0*t+i,e.y1=e.y1*t+i;for(const e of u)if(e.y0=e.y0*t+i,e.y1=e.y1*t+i,e.width=(e.width??0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){const n=e.circularPathData;n.sourceX=n.sourceX*t+o,n.targetX=n.targetX*t+o,n.sourceY=n.sourceY*t+i,n.targetY=n.targetY*t+i,n.rightFullExtent=n.rightFullExtent*t+o,n.leftFullExtent=n.leftFullExtent*t+o,n.verticalFullExtent=n.verticalFullExtent*t+i,n.rightInnerExtent=n.rightInnerExtent*t+o,n.leftInnerExtent=n.leftInnerExtent*t+o,n.verticalRightInnerExtent=n.verticalRightInnerExtent*t+i,n.verticalLeftInnerExtent=n.verticalLeftInnerExtent*t+i,n.rightSmallArcRadius*=t,n.rightLargeArcRadius*=t,n.leftSmallArcRadius*=t,n.leftLargeArcRadius*=t,n.sourceWidth*=t,n.rightNodeBuffer*=t,n.leftNodeBuffer*=t,n.arcRadius*=t}}}const f=new Map;for(const t of e)f.set(t.id,t);for(const e of c){const t=f.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}const p=new Map;for(const e of t)if(e._edgeKey)p.set(e._edgeKey,e);else{const t=Nt(e.source),n=Nt(e.target);p.set(`${t}\0${n}`,e)}for(const e of u){const t=Nt(e.source),n=Nt(e.target),o=p.get(e._edgeKey?e._edgeKey:`${t}\0${n}`);if(o){o.y0=e.y0,o.y1=e.y1,o.sankeyWidth=e.width??0,o.circular=!!e.circular,o.circularPathData=e.circularPathData,o._circularWidth=e._circularWidth,o._circularStub=e._circularStub,o.path=e.path,o.circularLinkType=e.circularLinkType,o.direction=i;const r=f.get(t),s=f.get(n);r&&(o.source=r),s&&(o.target=s)}}},buildScene(e,t,n,o){const i="vertical"===n.orientation?"down":"right",r=n.nodeStyle,s=n.edgeStyle,a=n.edgeOpacity??.5,l=n.edgeColorBy||"source",c=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:B,u=new Map;e.forEach((e,t)=>{u.set(e.id,c[t%c.length])});const d=[],h=[],f=[],p=new Map;for(const t of e){const e=t.x1-t.x0,n=t.y1-t.y0;if(0>=e||0>=n)continue;const o=r?r(cb(t,"nodeStyle")):{},s={fill:o.fill||u.get(t.id)||"#4d430c",stroke:o.stroke,strokeWidth:o.strokeWidth,opacity:o.opacity};p.set(t.id,("string"==typeof s.fill?s.fill:null)||u.get(t.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:t.y0,y:t.x0,w:n,h:e,style:s,datum:t,id:t.id,label:t.id}:{type:"rect",x:t.x0,y:t.y0,w:e,h:n,style:s,datum:t,id:t.id,label:t.id})}const g=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(const e of g){if(!e.sankeyWidth||0>=e.sankeyWidth)continue;const t="object"==typeof e.source?e.source:null,o="object"==typeof e.target?e.target:null;if(!t||!o)continue;let i=n.themeSemantic?.border||n.themeSemantic?.secondary||"#999";i="function"==typeof l?l(e)||i:"target"===l?p.get(o.id)||u.get(o.id)||i:p.get(t.id)||u.get(t.id)||i;const r=s?s(cb(e,"edgeStyle")):{};if(e._circularStub&&e.circular&&e.circularPathData){const t=e.circularPathData,n=e.sankeyWidth/2,o=Math.max(15,Math.min(40,.33*(t.rightFullExtent-t.sourceX))),s=Math.max(15,Math.min(40,.33*(t.targetX-t.leftFullExtent))),l=r.fill||i;h.push({type:"bezier",pathD:`M${t.sourceX},${t.sourceY-n}L${t.sourceX+o},${t.sourceY-n}L${t.sourceX+o},${t.sourceY+n}L${t.sourceX},${t.sourceY+n}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:e,_gradient:{direction:"right",from:1,to:0,x0:t.sourceX,x1:t.sourceX+o}}),h.push({type:"bezier",pathD:`M${t.targetX},${t.targetY-n}L${t.targetX-s},${t.targetY-n}L${t.targetX-s},${t.targetY+n}L${t.targetX},${t.targetY+n}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity},datum:e,_gradient:{direction:"left",from:0,to:1,x0:t.targetX-s,x1:t.targetX}});continue}let c;(c=e.circular&&e.circularPathData?sb(e):rb(e),c)&&h.push({type:"bezier",pathD:c,bezierCache:e.bezier,style:{fill:r.fill||i,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity},datum:e})}if(!1!==n.showLabels){const t=Et(n.nodeLabel);for(const n of e){const e=n.x1-n.x0,r=n.y1-n.y0;if(0>=e||0>=r)continue;const s=t?t(n):n.id;if(!s)continue;let a,l,c;"down"===i?(a=n.y0+(n.y1-n.y0)/2,l=n.x1+14,c="start"):(o[0]/2>n.x0+e/2?(a=n.x0-6,c="end"):(a=n.x1+6,c="start"),l=n.y0+r/2),f.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}},hb=require("d3-force"),fb=require("d3-scale"),pb={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,n,o){if(0===e.length)return;const i=n.forceStrength??.1,r=o[0]/2,s=o[1]/2,a=Math.max(.1,Math.min(1,Math.min(o[0],o[1])/200)),l=Math.min(.5,.06+1.8*(1-a)),c=n.__previousPositions;let u=0;const d=[];for(const t of e){const e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),n=c?.get(t.id);e?u++:n?(t.x=n.x,t.y=n.y,u++):d.push(t)}const h=u>0&&.3>=(e.length>0?d.length/e.length:1);if(h){const n=new Map;for(const t of e)n.set(t.id,t);for(const e of d){const o=gb(e.id,t,n);if(o.length>0){let t=0,n=0;for(const e of o)t+=e.x,n+=e.y;const i=yb(e.id),r=i%360*(Math.PI/180),s=(10+i%20)*a;e.x=t/o.length+s*Math.cos(r),e.y=n/o.length+s*Math.sin(r)}else{const t=yb(e.id),n=t%360*(Math.PI/180),o=(15+t%30)*a;e.x=r+o*Math.cos(n),e.y=s+o*Math.sin(n)}}}else{const t=2.399963229728653;for(let n=0;e.length>n;n++){const o=e[n];if(null==o.x||null==o.y||0===o.x&&0===o.y){const e=10*Math.sqrt(n+.5)*a,i=n*t;o.x=r+e*Math.cos(i),o.y=s+e*Math.sin(i)}}}const f=n.__skipForceSimulation||0===n.iterations?0:h?40:n.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),p=mb(n.nodeSize,n.nodeSizeRange,e),g=e=>p(e);if(f>0){const c=new Map,u=new Map;for(const t of e)c.set(t.id,0),u.set(t.id,t);for(const e of t){const t=Nt(e.source),n=Nt(e.target);c.set(t,(c.get(t)??0)+1),c.set(n,(c.get(n)??0)+1)}const d=(0,hb.forceLink)().strength(e=>{const t=e.weight,n=Nt(e.source),o=Nt(e.target),r=Math.max(1,Math.min(c.get(n)??1,c.get(o)??1));return Math.min(2.5,(t&&t>0?Math.sqrt(t):1)*i/(.1*r))}).distance(e=>{const t="string"==typeof e.source?u.get(e.source):e.source,n="string"==typeof e.target?u.get(e.target):e.target,o=(t?g(t):0)+(n?g(n):0)+Math.max(6,12*a);return Math.max(16,40*a,o)}).id(e=>e.id),p=(0,hb.forceSimulation)();if(void 0===n.random&&void 0===n.seed||p.randomSource(n.random??Wl(n.seed)),p.force("charge",(0,hb.forceManyBody)().strength(e=>{const t=c.get(e.id)??0;return-15*a*g(e)*Math.sqrt(t+1)})).force("collide",(0,hb.forceCollide)(e=>g(e)+3*a).strength(.9).iterations(2)).force("center",(0,hb.forceCenter)(r,s).strength(.8)).force("x",(0,hb.forceX)(r).strength(l)).force("y",(0,hb.forceY)(s).strength(l)).force("bounds",function(e,t,n=2,o=.6){let i=[];const r=r=>{const s=o*Math.max(r,.2);for(const o of i){const i=o.x??e[0]/2,r=o.y??e[1]/2,a=o.vx??0,l=o.vy??0,c=t(o)+n,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),h=Math.min(e[1]/2,c),f=Math.max(e[1]/2,e[1]-c),p=i+a,g=r+l;u>p?o.vx=a+(u-p)*s:p>d&&(o.vx=a+(d-p)*s),h>g?o.vy=l+(h-g)*s:g>f&&(o.vy=l+(f-g)*s)}};return r.initialize=e=>{i=e},r}(o,g)),p.nodes(e),t.length>0){const e=t.map(e=>({...e,source:Nt(e.source),target:Nt(e.target)}));d.links(e),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let e=0;f>e;++e)p.tick()}for(const t of e){if(null==t.x||null==t.y)continue;const e=g(t),n=f>0?2:0,i=Math.min(o[0]/2,e+n),r=Math.min(o[1]/2,e+n);t.x=Math.max(i,Math.min(o[0]-i,t.x)),t.y=Math.max(r,Math.min(o[1]-r,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}const y=new Map;for(const t of e)y.set(t.id,t);for(const e of t){if("string"==typeof e.source){const t=y.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){const t=y.get(e.target);t&&(e.target=t)}}},buildScene(e,t,n,o){const i=n.nodeStyle,r=n.edgeStyle,s=mb(n.nodeSize,n.nodeSizeRange,e),a=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:B,l=new Map;e.forEach((e,t)=>{l.set(e.id,a[t%a.length])});const c=[],u=[],d=[];for(const t of e){if(null==t.x||null==t.y)continue;const e=s(cb(t,"nodeSize")),o=i?i(cb(t,"nodeStyle")):{},r={fill:o.fill||l.get(t.id)||n.themeSemantic?.primary||"#007bff",stroke:o.stroke||n.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??2,opacity:o.opacity};c.push({type:"circle",cx:t.x,cy:t.y,r:e,style:r,datum:t,id:t.id,label:t.id})}const h=new Map;for(const t of e)h.set(t.id,t);for(const e of t){const t="object"==typeof e.source?e.source:h.get(e.source),o="object"==typeof e.target?e.target:h.get(e.target);if(!t||!o)continue;if(null==t.x||null==t.y)continue;if(null==o.x||null==o.y)continue;const i=r?r(cb(e,"edgeStyle")):{};u.push({type:"line",x1:t.x,y1:t.y,x2:o.x,y2:o.y,style:{stroke:i.stroke||n.themeSemantic?.border||n.themeSemantic?.secondary||"#999",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.6},datum:e})}if(!1!==n.showLabels){const t=Et(n.nodeLabel);for(const n of e){if(null==n.x||null==n.y)continue;const e=t?t(n):n.id;if(!e)continue;const o=s(cb(n,"nodeSize"));d.push({x:n.x,y:n.y-o-4,text:e+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function gb(e,t,n){const o=[];for(const i of t){const t=Nt(i.source),r=Nt(i.target);let s=null;if(t===e?s=r:r===e&&(s=t),s){const e=n.get(s);!e||0===e.x&&0===e.y||o.push({x:e.x,y:e.y})}}return o}function yb(e){let t=0;for(let n=0;e.length>n;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)}function mb(e,t,n){if(n.some(e=>null!=e.__forceRadius))return e=>e.__forceRadius??8;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;const o=t||[5,20],i=[];for(const t of n){const n=t.data?.[e];"number"==typeof n&&i.push(n)}if(0===i.length)return()=>o[0];const[r,s]=ve(i);if(r===s)return()=>(o[0]+o[1])/2;const a=(0,fb.scaleLinear)().domain([r,s]).range(o).clamp(!0);return t=>{const n=t.data?.[e];return null==n||"number"!=typeof n?o[0]:a(n)}}var xb=require("d3-chord"),bb=require("d3-shape"),vb=B,wb={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,n,o){if(0===e.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=n,a=Math.min(o[0],o[1])/2,l=a-r,c=o[0]/2,u=o[1]/2,d=(h=n.valueAccessor)?"function"==typeof h?h:e=>e[h]??1:e=>e.value??1;var h;const f=new Map;for(let t=0;e.length>t;t++)f.set(e[t].id,t);const p=e.length,g=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const e of t){const t=Nt(e.source),n=Nt(e.target),o=f.get(t),i=f.get(n);if(void 0===o||void 0===i)continue;const r=d(e);g[o][i]=r}const y=(0,xb.chord)().padAngle(i);s&&y.sortGroups(s);const m=y(g),x=m.groups,b=(0,bb.arc)().innerRadius(l).outerRadius(a);for(const t of x){const n=e[t.index],o=b.centroid({innerRadius:l,outerRadius:a,startAngle:t.startAngle,endAngle:t.endAngle});n.x=o[0]+c,n.y=o[1]+u,n.__arcData={startAngle:t.startAngle,endAngle:t.endAngle}}const v=new Map;for(const t of e)v.set(t.id,t);for(const e of t){const t=Nt(e.source),n=Nt(e.target),o=v.get(t),i=v.get(n);o&&(e.source=o),i&&(e.target=i)}const w=new Map;for(const e of t){const t=Nt(e.source),n=Nt(e.target);w.set(`${t}\0${n}`,e)}for(const t of m){const n=e[t.source.index].id,o=e[t.target.index].id,i=w.get(`${n}\0${o}`)||w.get(`${o}\0${n}`);i&&(i.__chordData=t)}},buildScene(e,t,n,o){const{groupWidth:i=20,edgeOpacity:r=.5}=n,s=Math.min(o[0],o[1])/2,a=s-i,l=o[0]/2,c=o[1]/2,u=n.nodeStyle,d=n.edgeStyle,h=n.edgeColorBy||"source",f=Array.isArray(n.colorScheme)?n.colorScheme:n.themeCategorical&&n.themeCategorical.length>0?n.themeCategorical:vb,p=new Map;e.forEach((e,t)=>{p.set(e.id,f[t%f.length])});const g=(0,xb.ribbon)().radius(a),y=[],m=[],x=[];for(let t=0;e.length>t;t++){const n=e[t],o=n.__arcData;if(!o)continue;let i;i=u?u(cb(n,"nodeStyle")).fill||p.get(n.id)||f[t%f.length]:p.get(n.id)||f[t%f.length];const r=u?u(cb(n,"nodeStyle")):{};y.push({type:"arc",cx:l,cy:c,innerR:a,outerR:s,startAngle:o.startAngle-Math.PI/2,endAngle:o.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:n,id:n.id,label:n.id})}for(const e of t){const t=e.__chordData;if(!t)continue;const o=g(t);if(!o)continue;const i=kb(o,l,c);let s=n.themeSemantic?.border||n.themeSemantic?.secondary||"#999";if(d)s=d(cb(e,"edgeStyle")).fill||s;else{const t="object"==typeof e.source?e.source:null,n="object"==typeof e.target?e.target:null;"target"===h&&n?s=p.get(n.id)||s:t&&(s=p.get(t.id)||s)}const a=d?d(cb(e,"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:e})}if(!1!==n.showLabels){const t=Et(n.nodeLabel),o=s+12;for(const n of e){const e=n.__arcData;if(!e)continue;const i=t?t(n):n.id;if(!i)continue;const r=(e.startAngle+e.endAngle)/2,s=r-Math.PI/2;x.push({x:l+Math.cos(s)*o,y:c+Math.sin(s)*o,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:y,sceneEdges:m,labels:x}}};function kb(e,t,n){const o=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!o)return e;const i=[];let r=0;for(;o.length>r;){const e=o[r];if("M"===e||"L"===e)for(i.push(e),r++;o.length>r&&!isNaN(Number(o[r]));)i.push(Number(o[r])+t+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("C"===e)for(i.push(e),r++;o.length>r&&!isNaN(Number(o[r]));)for(let e=0;3>e&&o.length>r&&!isNaN(Number(o[r]));e++)i.push(Number(o[r])+t+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("Q"===e)for(i.push(e),r++;o.length>r&&!isNaN(Number(o[r]));)for(let e=0;2>e&&o.length>r&&!isNaN(Number(o[r]));e++)i.push(Number(o[r])+t+""),r++,o.length>r&&!isNaN(Number(o[r]))&&(i.push(Number(o[r])+n+""),r++);else if("A"===e)for(i.push(e),r++;o.length>r&&!isNaN(Number(o[r]));)i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&i.push(o[r++]),o.length>r&&(i.push(Number(o[r])+t+""),r++),o.length>r&&(i.push(Number(o[r])+n+""),r++);else"Z"===e||"z"===e?(i.push(e),r++):(i.push(o[r]),r++)}return i.join(" ")}var Sb=require("d3-hierarchy"),Ab=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Mb(e){const[t,n,o]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*n+.114*o>150?"#222":"#fff"}function _b(e,t,n){const o=t.nodeIDAccessor;return"function"==typeof o?o(e.data)+"":"string"==typeof o&&void 0!==e.data[o]?e.data[o]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+n}function Pb(e){if(!e)return null;if("function"==typeof e){const t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function jb(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:Ab}function Cb(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function Rb(e,t,n,o,i){if("horizontal"===i){const i=(e+n)/2;return`M ${e},${t} C ${i},${t} ${i},${o} ${n},${o}`}if("radial"===i){const i=(e+n)/2;return`M ${e},${t} Q ${i},${t} ${i},${(t+o)/2} T ${n},${o}`}{const i=(t+o)/2;return`M ${e},${t} C ${e},${i} ${n},${i} ${n},${o}`}}var Lb={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,n,o){const i=n.__hierarchyRoot;if(!i)return;const r=n.chartType,s=function(e){if(e)return"function"==typeof e?e:t=>t[e]}(n.childrenAccessor),a=n.hierarchySum,l="function"==typeof a?a:"string"==typeof a?e=>Number(e[a])||0:e=>Number(e.value)||0,c=(0,Sb.hierarchy)(i,s);c.sum(l),c.sort((e,t)=>(t.value??0)-(e.value??0));const[u,d]=o;switch(r){case"tree":!function(e,t,n,o){const i=t.treeOrientation||"vertical",r=(0,Sb.tree)();r.size("horizontal"===i?[o,n]:"radial"===i?[2*Math.PI,Math.min(n,o)/2*.8]:[n,o]),r(e)}(c,n,u,d);break;case"cluster":!function(e,t,n,o){const i=t.treeOrientation||"vertical",r=(0,Sb.cluster)();r.size("horizontal"===i?[o,n]:"radial"===i?[2*Math.PI,Math.min(n,o)/2*.8]:[n,o]),r(e)}(c,n,u,d);break;case"treemap":!function(e,t,n,o){const i=t.padding??4,r=t.paddingTop??0,s=(0,Sb.treemap)().size([n,o]).tile(Sb.treemapBinary).padding(i);r>0&&s.paddingTop(r),s(e)}(c,n,u,d);break;case"circlepack":!function(e,t,n,o){const i=t.padding??4;(0,Sb.pack)().size([n,o]).padding(i)(e)}(c,n,u,d);break;case"partition":!function(e,t,n,o){(0,Sb.partition)().size([n,o]).padding(t.padding??1)(e)}(c,n,u,d)}const h=c.descendants();e.length=0,t.length=0;const f=new Map;for(let t=0;h.length>t;t++){const o=h[t],i={id:_b(o,n,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:o.value??0,depth:o.depth,data:o.data,createdByFrame:!0};"tree"===r||"cluster"===r?Tb(i,o,n):"treemap"===r||"partition"===r?Ib(i,o):"circlepack"===r&&$b(i,o),i.__hierarchyNode=o,e.push(i),f.set(o,i)}if("tree"===r||"cluster"===r)for(const e of h)if(e.parent){const n=f.get(e.parent),o=f.get(e);n&&o&&t.push({source:n,target:o,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,n,o){const i=n.nodeStyle||(()=>({})),r=n.edgeStyle||(()=>({}));switch(n.chartType){case"tree":case"cluster":return function(e,t,n,o,i,r){const s=[],a=[],l=[],c=n.treeOrientation||"vertical",u="radial"===c,d=o[0]/2,h=o[1]/2,f="number"==typeof(p=n.nodeSize)?p:5;var p;for(const t of e){let e=t.x,o=t.y;u&&(e+=d,o+=h);const r=i(cb(t,"nodeStyle"));let a=r.fill||Cb(n);if(n.colorByDepth&&void 0!==t.depth){const e=jb(n);a=e[t.depth%e.length]}s.push({type:"circle",cx:e,cy:o,r:f,style:{fill:a,stroke:r.stroke||n.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:t,id:t.id,label:t.id,depth:t.depth})}const g=n.edgeOpacity??.5;for(const e of t){const t="object"==typeof e.source?e.source:null,o="object"==typeof e.target?e.target:null;if(!t||!o)continue;let i=t.x,s=t.y,l=o.x,f=o.y;u&&(i+=d,s+=h,l+=d,f+=h);const p=Rb(i,s,l,f,c),y=r(cb(e,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:y.stroke||n.themeSemantic?.border||n.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g},datum:e})}if(!1!==n.showLabels){const t=Pb(n.nodeLabel);for(const n of e){const e=t?t(n):n.id;if(!e)continue;let o,i,r,s=n.x,a=n.y;if(u&&(s+=d,a+=h),u){const e=s-d,t=a-h,n=Math.sqrt(e*e+t*t);n>0?(o=s+e/n*10,i=a+t/n*10,r=0>e?"end":"start"):(o=s,i=a-12,r="middle")}else"horizontal"===c?(n.data?.children&&0!==n.data.children.length?(o=s-f-6,r="end"):(o=s+f+6,r="start"),i=a):(o=s,i=a+f+14,r="middle");l.push({x:o,y:i,text:e+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(e,t,n,o,i,r);case"treemap":case"partition":return function(e,t,n,o){const i=[],r=[];for(const n of e){const e=n.x1-n.x0,r=n.y1-n.y0;if(0>=e||0>=r)continue;const s=o(cb(n,"nodeStyle"));let a=s.fill||Cb(t);if(t.colorByDepth&&void 0!==n.depth){const e=jb(t);a=e[n.depth%e.length]}i.push({type:"rect",x:n.x0,y:n.y0,w:e,h:r,style:{fill:a,stroke:s.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){const n=Pb(t.nodeLabel),i=t.labelMode||"leaf",s="partition"===t.chartType;for(const a of e){const e=a.x1-a.x0,l=a.y1-a.y0;if(0>=e||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=n?n(a):a.id;if(!u)continue;if((c?30:40)>e||(c?16:14)>l)continue;let d=o(cb(a,"nodeStyle")).fill||Cb(t);if(t.colorByDepth&&void 0!==a.depth){const e=jb(t);d=e[a.depth%e.length]}const h="string"==typeof d?Mb(d):t.themeSemantic?.text??"#000";r.push(c?{x:a.x0+e/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,l)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(e,n,0,i);case"circlepack":return function(e,t,n,o){const i=[],r=[];for(const n of e){const e=n.__radius??5;if(0>=e)continue;const r=o(cb(n,"nodeStyle"));let s=r.fill||Cb(t);if(t.colorByDepth&&void 0!==n.depth){const e=jb(t);s=e[n.depth%e.length]}i.push({type:"circle",cx:n.x,cy:n.y,r:e,style:{fill:s,stroke:r.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){const n=Pb(t.nodeLabel);for(const i of e){const e=i.__radius??5,s=n?n(i):i.id;if(!s)continue;if(15>e)continue;const a=!(i.data?.children&&i.data.children.length>0);let l=o(cb(i,"nodeStyle")).fill||Cb(t);if(t.colorByDepth&&void 0!==i.depth){const e=jb(t);l=e[i.depth%e.length]}if(a){const n="string"==typeof l?Mb(l):t.themeSemantic?.text??"#000";r.push({x:i.x,y:i.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:n})}else r.push({x:i.x,y:i.y-e+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(e,n,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Tb(e,t,n){const o=n.treeOrientation||"vertical";if("radial"===o){const n=t.x,o=t.y;e.x=o*Math.cos(n-Math.PI/2),e.y=o*Math.sin(n-Math.PI/2)}else"horizontal"===o?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);e.x0=e.x-5,e.x1=e.x+5,e.y0=e.y-5,e.y1=e.y+5,e.width=10,e.height=10}function Ib(e,t){e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.x=(t.x0+t.x1)/2,e.y=(t.y0+t.y1)/2,e.width=t.x1-t.x0,e.height=t.y1-t.y0}function $b(e,t){const n=t.r??0;e.x=t.x,e.y=t.y,e.x0=t.x-n,e.x1=t.x+n,e.y0=t.y-n,e.y1=t.y+n,e.width=2*n,e.height=2*n,e.__radius=n}var Ob=require("d3-shape");function zb(e){let t=e.__orbitState;return t||(t={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},e.__orbitState=t),t}var Db={sankey:db,force:pb,chord:wb,tree:Lb,cluster:Lb,treemap:Lb,circlepack:Lb,partition:Lb,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,n,o){const i=n.__hierarchyRoot;i&&function(e,t,n,o,i){const r=function(e){if("function"==typeof e)return e;const t=e||"children";return e=>e[t]||null}(n.childrenAccessor),s=function(e){if("function"==typeof e)return e;const t=e||"name";return e=>(e[t]??"")+""}(n.nodeIDAccessor),a=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(n.orbitMode),l=n.orbitSize??2.95,c=n.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=zb(n);h.metaMap.clear(),o.length=0,i.length=0;const f=new Map;function p(e){const t=f.get(e)??0;return f.set(e,t+1),0===t?e:`${e}__${t}`}const g=t[0]/2,y=t[1]/2,m=Math.min(t[0],t[1])/2*.85,x=p(s(e));o.push({id:x,x:g,y:y,x0:g,x1:g,y0:y,y1:y,width:0,height:0,value:0,depth:0,data:e}),h.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,n,l,c,f,g,y){const m=r(t);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(x+1)/b,A={id:n,depth:g,data:t,parentId:n},M=y?f/u(A)*S:f*S,_=(0,Ob.pie)().value(e=>{const t=r(e)?.length;return t?4:1}).sort(null)(w),P=d(A);for(let t=0;w.length>t;t++){const r=(_[t].startAngle+_[t].endAngle)/2,a=w[t],u=p(s(a)),d=l+M*Math.sin(r),f=c+M*Math.cos(r)*P;o.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,parentId:n,eccentricity:P}),i.push({source:n,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:n,target:u}}),e(a,u,d,f,M,g+1,!0)}k+=v}}(e,x,g,y,m,1,!1)}(i,o,n,e,t)},buildScene(e,t,n,o){const i=n.nodeStyle,r=n.nodeSize,s="number"==typeof r?()=>r:"function"==typeof r?r:()=>6,a=[],l=[],c=[];if(!1!==n.orbitShowRings){const t=zb(n),o=new Map;for(const t of e)o.set(t.id,t);const i=new Map;for(const[,e]of t.metaMap){if(!e.parentId)continue;const t=o.get(e.parentId);if(!t)continue;const n=`${e.parentId}:${e.ring}`;i.has(n)||i.set(n,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:e,parentY:t,ring:n,ecc:o}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,c=(i+1)/r*Math.PI*2;l.push({type:"line",x1:e+n*Math.sin(a),y1:t+n*Math.cos(a)*o,x2:e+n*Math.sin(c),y2:t+n*Math.cos(c)*o,style:s,datum:null})}}for(const t of e){if(null==t.x||null==t.y)continue;const e=s(cb(t,"nodeSize")),o=i?i(cb(t,"nodeStyle")):{};a.push({type:"circle",cx:t.x,cy:t.y,r:e,style:{fill:o.fill||n.themeSemantic?.primary||"#6366f1",stroke:o.stroke||n.themeSemantic?.surface||"#fff",strokeWidth:o.strokeWidth??1,opacity:o.opacity??(0===(t.depth??0)?1:.85)},datum:t,id:t.id,label:t.id,depth:t.depth})}const u=new Map;for(const t of e)u.set(t.id,t);for(const e of t){const t="object"==typeof e.source?e.source:u.get(e.source),n="object"==typeof e.target?e.target:u.get(e.target);t&&n&&(null!=t.x&&null!=n.x&&l.push({type:"line",x1:t.x,y1:t.y,x2:n.x,y2:n.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:e}))}if(n.showLabels){const t=n.nodeLabel;for(const n of e){const e=s(cb(n,"nodeSize"));if(4>=e)continue;const o="function"==typeof t?t(n):t?n.data?.[t]??n.id:n.id;c.push({x:n.x,y:n.y+e+12,text:o+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:a,sceneEdges:l,labels:c}},tick:(e,t,n,o,i)=>!1!==n.orbitAnimated&&(function(e,t){const n=zb(t),o=t.orbitSpeed??.25,i=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{const t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-n.startTime)/1e3,s=o*(Math.PI/6),a=new Map;for(const t of e)a.set(t.id,t);for(const t of e){const e=n.metaMap.get(t.id);if(!e||!e.parentId)continue;const o=a.get(e.parentId);if(!o)continue;const l=e.angle+r*s*i({id:t.id,depth:e.depth,data:t.data,parentId:e.parentId});t.x=o.x+e.ring*Math.sin(l),t.y=o.y+e.ring*Math.cos(l)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,n),!0)}},Fb=require("react/jsx-runtime");function Eb(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Nb=new Set(["tree","cluster","treemap","circlepack","partition"]);function Bb(e,t){const n=et(e.theme),o=e.chartType||"force",i=()=>rm({frameType:"network",width:r[0],height:r[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,nodeCount:0,edgeCount:0,margin:s}),r=e.size||[500,500],s=Ks({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=Vs(e.title),l=e.showLegend?(()=>{const t="string"==typeof(n=e.colorBy)||"function"==typeof n?e.colorBy:void 0;var n;if(!t)return[];const o=z(e.nodes||[]);if(o.length>0)return bm(o,t);const i=Array.isArray(e.edges)?z(e.edges):[];if(0===i.length)return[];const r=Eb(e.sourceAccessor,"source"),s=Eb(e.targetAccessor,"target");return bm(Array.from(new Set(i.flatMap(e=>[r(e),s(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];zm(s,{props:e,categories:l,theme:n,size:r,hasTitle:a});const c=r[0]-s.left-s.right,u=r[1]-s.top-s.bottom,d=function(e){return Db[e]}(o);if(!d&&!e.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${o}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const h={chartType:o,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||n.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig};let f,p;if(Nb.has(o)){const o=e.data||e.edges;if(!o||Array.isArray(o))return t&&(t.evidence=i()),gx.renderToStaticMarkup(Em(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));h.__hierarchyRoot=o,f=[],p=[]}else{const o=z(e.nodes||[]),a=Array.isArray(e.edges)?z(e.edges):[];if(0===o.length&&0===a.length)return t&&(t.evidence=i()),gx.renderToStaticMarkup(Em(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));if(p=function(e,t){const n=Eb(t.sourceAccessor,"source"),o=Eb(t.targetAccessor,"target"),i=Eb(t.valueAccessor,"value");return e.map(e=>({source:n(e)+"",target:o(e)+"",value:Number(i(e))||1,y0:0,y1:0,sankeyWidth:0,data:e}))}(a,h),0===o.length&&p.length>0){const e=new Set;for(const t of p){const n=Rm(t.source),o=Rm(t.target);n&&e.add(n),o&&e.add(o)}f=Array.from(e).map(e=>({id:e,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:e}}))}else f=function(e,t){const n=Eb(t.nodeIDAccessor,"id");return e.map(e=>({id:n(e)+"",x:e.x??0,y:e.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:e}))}(o,h)}let g=[],y=[],m=[],x=null;if(h.customNetworkLayout){const e=h.colorScheme,t=Tg(e,n.colors.categorical,B),o=Ig(t,e),i={nodes:f,edges:p,dimensions:{width:c,height:u,plot:{x:0,y:0,width:c,height:u}},theme:{semantic:n.colors,categorical:[...t]},resolveColor:o,config:h.layoutConfig??{}},r=h.customNetworkLayout(i);g=r.sceneNodes??[],y=r.sceneEdges??[],m=r.labels??[],x=r.overlays??null}else if(d){d.computeLayout(f,p,h,[c,u]);const e=d.buildScene(f,p,h,[c,u]);g=e.sceneNodes,y=e.sceneEdges,m=e.labels}const b=tt(n);for(const e of m)e.fill||(e.fill=b.text);const v=Dc({nodes:y,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){switch(e.type){case"line":return(0,ma.jsx)("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||"#999",strokeWidth:e.style.strokeWidth||1,opacity:e.style.opacity},"net-edge-"+t);case"bezier":{const n=e,o=`net-bezier-${t}-hatch`,i=Ko(n.style.fill)?Jo(n.style.fill,o):void 0;return(0,ma.jsxs)(ga.Fragment,{children:[i&&(0,ma.jsx)("defs",{children:i}),(0,ma.jsx)("path",{d:n.pathD,fill:i?`url(#${o})`:ua(n.style.fill,"#999"),fillOpacity:n.style.fillOpacity,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth,opacity:n.style.opacity})]},"net-edge-"+t)}case"ribbon":{const n=e,o=`net-ribbon-${t}-hatch`,i=Ko(n.style.fill)?Jo(n.style.fill,o):void 0;return(0,ma.jsxs)(ga.Fragment,{children:[i&&(0,ma.jsx)("defs",{children:i}),(0,ma.jsx)("path",{d:n.pathD,fill:i?`url(#${o})`:ua(n.style.fill,"#999"),fillOpacity:n.style.fillOpacity,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth,opacity:n.style.opacity})]},"net-edge-"+t)}case"curved":{const n=e;return(0,ma.jsx)("path",{d:n.pathD,fill:ua(n.style.fill,"none"),stroke:n.style.stroke||"#999",strokeWidth:n.style.strokeWidth||1,opacity:n.style.opacity},"net-edge-"+t)}default:return null}}(e,t)}),w=Dc({nodes:g,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){switch(e.type){case"circle":{const n=e,o=Ko(n.style.fill)?Jo(n.style.fill,`net-circle-${t}-hatch`):void 0;return(0,ma.jsxs)(ga.Fragment,{children:[o&&(0,ma.jsx)("defs",{children:o}),(0,ma.jsx)("circle",{cx:n.cx,cy:n.cy,r:n.r,fill:o?`url(#net-circle-${t}-hatch)`:ua(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-circle-"+t)}case"rect":{const n=e,o=Ko(n.style.fill)?Jo(n.style.fill,`net-rect-${t}-hatch`):void 0;return(0,ma.jsxs)(ga.Fragment,{children:[o&&(0,ma.jsx)("defs",{children:o}),(0,ma.jsx)("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:o?`url(#net-rect-${t}-hatch)`:ua(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-rect-"+t)}case"arc":{const n=e,o=(0,ya.arc)().innerRadius(n.innerR).outerRadius(n.outerR).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2)(ca)||"",i=Ko(n.style.fill)?Jo(n.style.fill,`net-arc-${t}-hatch`):void 0;return(0,ma.jsxs)(ga.Fragment,{children:[i&&(0,ma.jsx)("defs",{children:i}),(0,ma.jsx)("path",{d:o,transform:`translate(${n.cx},${n.cy})`,fill:i?`url(#net-arc-${t}-hatch)`:ua(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity})]},"net-arc-"+t)}case"symbol":{const n=e,o=kn(n.symbolType,n.size,n.path);return(0,ma.jsx)("path",{d:o,transform:n.rotation?`translate(${n.cx},${n.cy}) rotate(${180*n.rotation/Math.PI})`:`translate(${n.cx},${n.cy})`,fill:n.style.fill?ua(n.style.fill):"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,opacity:n.style.opacity},"net-symbol-"+t)}case"glyph":return ha(e,e.cx,e.cy,"net-glyph-"+(e.id??t));default:return null}}(e,t)});t&&(t.evidence=rm({frameType:"network",width:r[0],height:r[1],marks:[...w.map(({node:e})=>({type:"node:"+(e.type??"node")})),...v.map(({node:e})=>({type:"edge:"+(e.type??"edge")}))],title:e.title,description:e.description,annotations:e.annotations,nodeCount:w.length,edgeCount:v.length,margin:s}));const k=v.map(e=>e.element),S=w.map(e=>e.element),A=m.map((e,t)=>function(e,t){return(0,ma.jsx)("text",{x:e.x,y:e.y,textAnchor:e.anchor||"middle",dominantBaseline:e.baseline||"auto",fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,children:e.text},"net-label-"+t)}(e,t)).filter(Boolean),M=e.annotations?Pm({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{},layout:{width:c,height:u},theme:n,idPrefix:e._idPrefix}):null,_=Dm({props:e,categories:l,theme:n,size:r,margin:s,hasTitle:a});return gx.renderToStaticMarkup(Em((0,Fb.jsxs)(Fb.Fragment,{children:[e.backgroundGraphics,k,S,A,M,e.foregroundGraphics,x]}),{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,legend:_,idPrefix:e._idPrefix}))}var Wb=g(require("react-dom/server")),Yb=require("d3-geo"),qb=require("d3-quadtree"),Xb=require("d3-geo"),Hb={mercator:Xb.geoMercator,equalEarth:Xb.geoEqualEarth,albersUsa:Xb.geoAlbersUsa,orthographic:Xb.geoOrthographic,naturalEarth:Xb.geoNaturalEarth1,equirectangular:Xb.geoEquirectangular};function Gb(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Vb(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function Ub(e,t,n){return e?"function"==typeof e?{...n,...e(t)}:{...n,...e}:{...n}}function Kb(e,t){if(2>e.length)return[e];const n=.4*t,o=[];let i=[e[0]];for(let t=1;e.length>t;t++){const r=e[t];Math.abs(r[0]-e[t-1][0])>n?(2>i.length||o.push(i),i=[r]):i.push(r)}return 2>i.length||o.push(i),o}function Zb(e,t,n=24){const o=t[0]-e[0],i=t[1]-e[1],r=Math.sqrt(o*o+i*i);if(0===r)return[e,t];const s=-i/r,a=o/r,l=Math.min(.3*r,80),c=(e[0]+t[0])/2+s*l,u=(e[1]+t[1])/2+a*l,d=[];for(let o=0;n>=o;o++){const i=o/n,r=1-i;d.push([r*r*e[0]+2*r*i*c+i*i*t[0],r*r*e[1]+2*r*i*u+i*i*t[1]])}return d}function Qb(e,t){if(2>e.length)return e;const n=t/2+1,o=[];for(let t=0;e.length>t;t++){const i=e[t];let r,s;0===t?(r=e[1][0]-i[0],s=e[1][1]-i[1]):t===e.length-1?(r=i[0]-e[t-1][0],s=i[1]-e[t-1][1]):(r=e[t+1][0]-e[t-1][0],s=e[t+1][1]-e[t-1][1]);const a=Math.sqrt(r*r+s*s)||1;o.push([i[0]+s/a*n,i[1]+-r/a*n])}return o}function Jb(e,t,n,o,i){const r=t[0]-e[0],s=t[1]-e[1],a=Math.sqrt(r*r+s*s);if(0===a)return[e,t];const l=s/a,c=-r/a,u=i/2+1;return[[e[0]+l*u,e[1]+c*u],[t[0]+l*u,t[1]+c*u]]}var ev=require("d3-scale");var tv=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],nv=["scene-style","data-paint","accessibility","evidence"],ov=(e,t)=>({retainedData:e,invalidations:t}),iv=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],rv=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sv=["scene-geometry","data-paint","accessibility","evidence"],av=["scene-style","data-paint","accessibility","evidence"],lv=["overlay","accessibility","evidence"],cv=[],uv={xAccessor:ov("rebuild",iv),yAccessor:ov("rebuild",iv),lineDataAccessor:ov("rebuild",iv),pointIdAccessor:ov("rebuild",sv),lineIdAccessor:ov("rebuild",sv),windowSize:ov("rebuild",iv),projection:ov("preserve",rv),projectionExtent:ov("preserve",rv),fitPadding:ov("preserve",rv),lineType:ov("preserve",rv),flowStyle:ov("preserve",rv),graticule:ov("preserve",rv),projectionTransform:ov("preserve",rv),customLayout:ov("preserve",rv),layoutConfig:ov("preserve",rv),layoutMargin:ov("preserve",rv),areaStyle:ov("preserve",av),pointStyle:ov("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:ov("preserve",av),colorScheme:ov("preserve",av),themeCategorical:ov("preserve",av),themeDiverging:ov("preserve",av),themeSemantic:ov("preserve",av),themeSequential:ov("preserve",av),decay:ov("preserve",av),pulse:ov("preserve",av),layoutSelection:ov("preserve",av),annotations:ov("preserve",lv),autoPlaceAnnotations:ov("preserve",lv),clock:ov("preserve",cv),transition:ov("preserve",cv),introAnimation:ov("preserve",cv),onLayoutError:ov("preserve",cv)},dv=ov("preserve",rv),hv=class{constructor(){this.tracker=new Qn}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},tv)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},nv):this.recordNoop("restyle")}recordConfig(e,t={}){const n=function(e){let t="preserve";const n=new Set;for(const o of e){const e=uv[o]??dv;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}(e),o=new Set(n.invalidations);return t.retainedDataChanged&&o.add("data"),this.tracker.record({kind:"config",keys:e},o)}},fv=require("d3-geo");function pv(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&.5>e)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${e+""}.`)}var gv=class e{constructor(e){this.updateResults=new hv,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(e){return{...e,fitPadding:pv(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??Vt()}getConfiguredWindowSize(){const e=this.config.windowSize??500;if(!Number.isInteger(e)||1>e)throw Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){const t=this.pointBuffer.toArray(),n=this.timestampBuffer?.toArray()??[],o=t.slice(-e),i=n.slice(-o.length),r=this.currentTime();this.pointBuffer=new It(e),this.timestampBuffer=new It(e),o.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(i[t]??r)})}this.retainNewestLines(e)}updateConfig(e){const t=function(e){return"fitPadding"in e?{...e,fitPadding:pv(e.fitPadding)}:e}(e),n=this.config,o=this.getConfiguredWindowSize(),i=Object.keys(t).filter(e=>t[e]!==n[e]);this.config={...this.config,...t};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==o;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(i,{retainedDataChanged:s})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});const t=this.getConfiguredWindowSize(),n=this.pointBuffer?this.pointBuffer.toArray():this.pointData,o=this.timestampBuffer?.toArray()??[],i=n.slice(-t),r=o.slice(-i.length),s=this.currentTime();this.pointBuffer=new It(t),this.timestampBuffer=new It(t),i.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(r[t]??s)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();En(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();for(const n of e)En(this.pointBuffer,n,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");const t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(const e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){const{lineIdAccessor:t}=this.config;if(!t)throw Error("removeLine() requires lineIdAccessor to be configured");const n="function"==typeof t?t:e=>e[t],o=new Set(Array.isArray(e)?e:[e]),i=[];return this.lineData=this.lineData.filter(e=>!o.has(n(e)+"")||(i.push(e),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(e){const{pointIdAccessor:t}=this.config;if(!t)throw Error("removePoint() requires pointIdAccessor to be configured");const n="function"==typeof t?t:e=>e[t],o=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){const e=e=>o.has(n(e)+"");Nn(this.pointBuffer,this.timestampBuffer,e);const t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{const e=[];return this.pointData=this.pointData.filter(t=>!o.has(n(t)+"")||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){const t=this._customRestyle;if(t){for(const n of this.scene){const o=this._baseStyles.get(n)??n.style,i=t(n,e);n.style=i?{...o,...i}:o}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){const{config:t}=this,n=this.projection,o=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],l=this.scene;this.projection=function(e){if(!e)return(0,Xb.geoEqualEarth)();if("string"==typeof e){const t=Hb[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),(0,Xb.geoEqualEarth)())}if("object"==typeof e&&"type"in e){const t=Hb[e.type],n=t?t():(0,Xb.geoEqualEarth)();return e.rotate&&"rotate"in n&&n.rotate(e.rotate),e.center&&"center"in n&&n.center(e.center),n}return e}(t.projection),this.geoPath=(0,Yb.geoPath)(this.projection),this.fitProjection(e),this.geoPath=(0,Yb.geoPath)(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(e,t)=>c([e,t]),invertedPoint:(e,t)=>c.invert?c.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=n,this.geoPath=o,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){const t=e.width/2,n=e.height/2,o=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:n}));o.length>0&&this.startTransition(o)}this._hasRenderedOnce=!0,t.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(e){const t=this.projection,n=this.config,o=[...this.areas],i=Gb(n.xAccessor,"lon"),r=Gb(n.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const e=s.map(e=>[i(e),r(e)]);o.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}const a=Vb(n.lineDataAccessor);for(const e of this.lineData){const t=a(e);if(t&&t.length>0){const e=t.map(e=>[i(e),r(e)]);o.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==o.length){if(n.projectionExtent){const[[o,i],[r,s]]=n.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[o,i],[o,s],[r,s],[r,i],[o,i]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){const o=n.fitPadding??0,i=Math.min(e.width,e.height);t.scale(i/2-i*o),t.translate([e.width/2,e.height/2])}else{const i=n.fitPadding??0,r=e.width*i,s=e.height*i;t.fitExtent([[r,s],[e.width-r,e.height-s]],{type:"FeatureCollection",features:o})}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){const n=this.projection;if(!n)return;const o=this.geoPath,i=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*e.k),n.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=(0,Yb.geoPath)(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(e,t)=>n([e,t]),invertedPoint:(e,t)=>n.invert?n.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){const n=this.projection;if(!n)return;const o=this.geoPath,i=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*e),n.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=(0,Yb.geoPath)(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(e,t)=>n([e,t]),invertedPoint:(e,t)=>n.invert?n.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){const n=this.projection;if(!n||!n.rotate)return;const o=this.geoPath,i=this.scales,r=[...n.rotate()];n.rotate(e),this.geoPath=(0,Yb.geoPath)(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(e,t)=>n([e,t]),invertedPoint:(e,t)=>n.invert?n.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.rotate(r),this.geoPath=o,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){const t=this.projection;t&&t.rotate&&t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let t=0,n=0;for(const e of this.scene)"point"===e.type&&!1!==e.interactive&&(n++,e.r>t&&(t=e.r));if(this._maxPointRadius=t,e.QUADTREE_THRESHOLD>=n)return void(this._quadtree=null);const o=Array(n);let i=0;for(const e of this.scene)"point"===e.type&&!1!==e.interactive&&(o[i++]=e);this._quadtree=(0,qb.quadtree)().x(e=>e.x).y(e=>e.y).addAll(o)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;const{config:t}=this,n=this.projection,o=this.geoPath;if(t.customLayout&&this.scales){const n=t.layoutMargin??{top:0,right:0,bottom:0,left:0},o=Tg(t.colorScheme,t.themeCategorical,fe),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:n,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...o]},resolveColor:Ig(o,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null};let r;try{r=t.customLayout(i)}catch(e){const n=null!==this.lastCustomLayoutResult,o=Ln("geo",e,n,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",e);try{t.onLayoutError?.(o)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return n?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const e of s)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return jn({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:e,projection:t,path:n,areas:o,points:i,lines:r,layout:s}){const a=Gb(e.xAccessor,"lon"),l=Gb(e.yAccessor,"lat"),c=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){const t=!0===e.graticule?{}:e.graticule,o=(0,fv.geoGraticule)();t.step&&o.step(t.step);const i=n(o())||"";i&&c.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth||.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const t of o){const o=n(t);if(!o)continue;const i=n.centroid(t),r=n.bounds(t),s=n.area(t);c.push({type:"geoarea",pathData:o,centroid:i,bounds:r,screenArea:s,style:Ub(e.areaStyle,t,u),datum:t,interactive:!0})}const f=Vb(e.lineDataAccessor);for(const n of r){const o=f(n);if(!o||2>o.length)continue;let i=[];if("geo"===e.lineType){const e=Array(o.length);for(let t=0;o.length>t;t++)e[t]=[a(o[t]),l(o[t])];for(let n=0;e.length-1>n;n++){const o=e[n],r=e[n+1],s=(0,fv.geoDistance)(o,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=(0,fv.geoInterpolate)(o,r);for(let e=0;a>=e;e++){if(n>0&&0===e)continue;const o=t(l(e/a));null!=o&&i.push(o)}}}else for(let e=0;o.length>e;e++){const n=o[e],r=t([a(n),l(n)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Ub(e.lineStyle,n,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==o.length||2>i.length||"arc"!==e.flowStyle?2!==o.length||2>i.length||"offset"!==e.flowStyle||(i="geo"===e.lineType?Qb(i,u):Jb(i[0],i[i.length-1],0,0,u)):i=Zb(i[0],i[i.length-1]);const h=Kb(i,s.width);if(h.length>1)for(const e of h)2>e.length||c.push({type:"line",path:e,style:{...r,_edgeFade:!0},datum:n});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:n})}const p=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,g=t.clipAngle?t.clipAngle()??0:0,y=g>0?g*Math.PI/180:null,m=t.rotate?t.rotate():[0,0,0],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const n of i){const o=a(n),i=l(n);if(null!=y&&(0,fv.geoDistance)([o,i],b)>y)continue;const r=t([o,i]);if(!r)continue;const s=e.pointStyle?e.pointStyle(n):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:n,pointId:p?p(n)+"":void 0};c.push(u)}return c}({config:t,projection:n,path:o,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){const n=function(e,t,n,o){const i=e.filter(e=>"point"===e.type);if(2>i.length)return null;const r=t.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===t.layout?"strip":"radial";if("radial"===a&&0===s)return null;const l=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=i.find(e=>e.datum&&l(e.datum)+""==t.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;const d=we(i.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),1);o>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){const n=e[t];"geoarea"===n.type&&n.interactive&&e.splice(t,1)}const h="strip"===a?function(e,t,n,o,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=(0,ev.scaleLinear)().domain([0,o]).range([0,s]);t.x=r,t.y=a;const c=[];for(const i of e){if(i===t)continue;if(!i.datum){i.x=r,i.y=a;continue}const e=Number(n(i.datum)),s=r+(isFinite(e)&&e>=0&&o>0?l(e):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((e,t)=>e.x-t.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let e=d+1;for(;c.length>e&&3>Math.abs(c[e].x-c[d].x);)e++;const t=e-d;if(t>1&&u>0)for(let e=0;t>e;e++)c[d+e].node.y=a+(e-(t-1)/2)*Math.min(2.5,2*u/Math.max(1,t-1));d=e}return{cx:r,cy:a,maxCost:o,availableRadius:s,layout:"strip"}}(i,u,c,d,n):function(e,t,n,o,i,r){const s=t.x,a=t.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=(0,ev.scaleLinear)().domain([0,o]).range([0,u]);for(const r of e){if(r===t)continue;if(!r.datum)continue;const e=r.x,u=r.y,h=Math.atan2(u-a,e-s),f=Math.hypot(e-s,u-a),p=Number(n(r.datum)),g=isFinite(p)&&p>=0?o>0?d(p):0:f,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=e+(y-e)*i,r.y=u+(m-u)*i}return t.x=s+(l-s)*i,t.y=a+(c-a)*i,{cx:t.x,cy:t.y,maxCost:o,availableRadius:u,layout:"radial"}}(i,u,c,d,s,n),f=e.filter(e=>"line"===e.type);if(f.length>0){const e=new Map;for(const t of i)null!=t.pointId&&e.set(t.pointId+"",[t.x,t.y]);for(const n of f){const o=n.datum?.source,i=n.datum?.target;if(null!=o&&null!=i){const r=e.get(o+""),s=e.get(i+"");if(r&&s)if("fractional"===t.lineMode&&n.path.length>2){const e=n.path[0],t=n.path[n.path.length-1],o=[r[0]-e[0],r[1]-e[1]],i=[s[0]-t[0],s[1]-t[1]],a=[0];for(let e=1;n.path.length>e;e++)a.push(a[e-1]+Math.hypot(n.path[e][0]-n.path[e-1][0],n.path[e][1]-n.path[e-1][1]));const l=a[a.length-1];n.path=n.path.map((e,t)=>{const r=l>0?a[t]/l:t/(n.path.length-1);return[e[0]+o[0]*(1-r)+i[0]*r,e[1]+o[1]*(1-r)+i[1]*r]})}else n.path=[r,s]}}}return h}(this.scene,e,t,this.areas.length);n&&(this.cartogramLayout=n)}applyDecay(){const e=this.config.decay;if(!e||!this.pointBuffer)return;const t=this.pointBuffer.size;if(0===t)return;const n=this.scene.filter(e=>"point"===e.type);for(let o=0;n.length>o;o++){const i=Ut(e,o,t);n[o]._decayOpacity=i,n[o].style={...n[o].style,opacity:i}}}applyPulse(e=this.currentTime()){const t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;const n=this.scene.filter(e=>"point"===e.type),o=this.timestampBuffer.toArray(),i=t.color||"rgba(255,255,255,0.6)",r=t.glowRadius??4;let s=!1;for(let a=0;n.length>a&&o.length>a;a++){const l=Zt(t,o[a],e);s=Qt(n[a],l,i,r)||s}return s}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&Jt(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){const t=this.config.transition?.duration??300;if(0>=t)return;const n=new Map;for(const t of e)"point"===t.type&&t.pointId&&n.set(t.pointId,[t.x,t.y]);const o=this.scene.filter(e=>"point"===e.type);let i=!1;for(const e of o)if(e.pointId){const t=n.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(i=!0))}for(const e of o)e.pointId&&!n.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??e.style?.fillOpacity??1,e.style={...e.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(const e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(e){if(!this.activeTransition)return!1;const t=Ht(e,this.activeTransition),n=Xt(t),o=this.scene.filter(e=>"point"===e.type);for(const e of o){if(null!=e._targetX&&null!=e._targetY){const t=e.y;e.x=Gt(e.x,e._targetX,n),e.y=Gt(t,e._targetY,n)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*n})}if(t>=1){for(const e of o)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};gv.QUADTREE_THRESHOLD=500;var yv=gv;Vn(yv);var mv=require("react/jsx-runtime");function xv(e,t){const n=et(e.theme),o=e.size||[e.width||600,e.height||400],i=Ks({top:10,right:10,bottom:10,left:10,...e.margin},e.title),r=Vs(e.title),s=Array.isArray(e.areas)?z(e.areas):e.areas,a=z(e.points),l=z(e.lines),c=e.showLegend?(()=>{const t="string"==typeof(n=e.colorBy)||"function"==typeof n?e.colorBy:void 0;var n;return bm(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof t?s.map(e=>({...e.properties||{},...e})):s:[],t)})():[];zm(i,{props:e,categories:c,theme:n,size:o,hasTitle:r});const u=o[0]-(i.left??0)-(i.right??0),d=o[1]-(i.top??0)-(i.bottom??0),h={projection:e.projection||"equalEarth",xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineType:e.lineType,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,themeCategorical:n.colors.categorical,themeSemantic:qe(n)},f=new yv(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)}e.points&&f.setPoints(a),e.lines&&f.setLines(l),f.computeScene({width:u,height:d});const p=Dc({nodes:f.scene,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){switch(e.type){case"geoarea":{const n=e;if(!n.pathData)return null;const o=Ko(n.style.fill)?Jo(n.style.fill,`geoarea-${t}-hatch`):void 0;return(0,ba.jsxs)(xa.Fragment,{children:[o&&(0,ba.jsx)("defs",{children:o}),(0,ba.jsx)("path",{d:n.pathData,fill:o?`url(#geoarea-${t}-hatch)`:ua(n.style.fill,"#e0e0e0"),fillOpacity:n.style.fillOpacity??1,stroke:n.style.stroke||"none",strokeWidth:n.style.strokeWidth||.5,strokeDasharray:n.style.strokeDasharray,opacity:n._decayOpacity??1})]},"geoarea-"+t)}case"point":{const n=e,o=Ko(n.style.fill)?Jo(n.style.fill,`geopoint-${t}-hatch`):void 0;return(0,ba.jsxs)(xa.Fragment,{children:[o&&(0,ba.jsx)("defs",{children:o}),(0,ba.jsx)("circle",{cx:n.x,cy:n.y,r:n.r,fill:o?`url(#geopoint-${t}-hatch)`:ua(n.style.fill),fillOpacity:n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n._decayOpacity??n.style.opacity??1})]},"point-"+t)}case"line":{const n=e;if(2>n.path.length)return null;const o="M"+n.path.map(e=>`${e[0]},${e[1]}`).join("L");return(0,ba.jsx)("path",{d:o,fill:"none",stroke:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||1.5,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity??1},"line-"+t)}case"glyph":return ha(e,e.x,e.y,"geo-glyph-"+(e.pointId??t));default:return null}}(e,t)});if(t&&(t.evidence=rm({frameType:"geo",width:o[0],height:o[1],marks:p.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,legendItems:c.length>0?c.length:void 0,margin:i})),0===p.length){const t=e.backgroundGraphics||e.foregroundGraphics||e.annotations||f.customLayoutOverlays?(0,mv.jsxs)(mv.Fragment,{children:[e.backgroundGraphics,e.annotations?Pm({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([e,t])=>f.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:n,idPrefix:e._idPrefix}):null,e.foregroundGraphics,f.customLayoutOverlays]}):null;return Wb.renderToStaticMarkup(Em(t,{width:o[0],height:o[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,idPrefix:e._idPrefix}))}const g=p.map(e=>e.element),y=e.annotations?Pm({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([e,t])=>f.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:n,idPrefix:e._idPrefix}):null,m=Dm({props:e,categories:c,theme:n,size:o,margin:i,hasTitle:r});return Wb.renderToStaticMarkup(Em((0,mv.jsxs)(mv.Fragment,{children:[e.backgroundGraphics,g,y,e.foregroundGraphics,f.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:n,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,legend:m,idPrefix:e._idPrefix}))}var bv=g(require("react-dom/server"));function vv(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var wv={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function kv(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Sv(e,t){const n="function"==typeof t?t(e):t;return{...wv,...n??{}}}function Av(e,t={}){return e.map(e=>function(e,t={}){const n=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),o={label:t.getBodyLabel?.(e)??kv(e)},i={style:Sv(e,t.bodyStyle),datum:n,accessibleDatum:n,accessibility:o,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...i}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...i}}(e,t))}var Mv=require("react/jsx-runtime"),_v={top:0,right:0,bottom:0,left:0};function Pv(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function jv(e,t){const n=e.size??[e.width??600,e.height??400],o=new gg(e.config);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&o.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));const i=function(e,t={}){const{width:n=640,height:o=360,title:i,description:r,background:s,backgroundGraphics:a,className:l,foregroundGraphics:c,idPrefix:u="physics",margin:d,renderBodySVG:h,...f}=t,p=function(e,t={}){const n=e.settle(t.maxSteps),o=e.readBodies(),i=e.snapshot(),r=Av(o,t),s=function(e,t={}){const n=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),o=n.filter(e=>e.sleeping).length,i=e.queue.length,r=e.sediment.reduce((e,t)=>e+t.count,0),s="settled"===e.simulationState&&0===i&&o===n.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const l=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,n,o){const i=e-(t+n+o);return{charge:e,live:t,queued:n,sedimented:o,unaccounted:i,balanced:0===i}}(t.charge,n.length,i,r):void 0;return l&&!l.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:n.length,sleepingCount:o,settled:s,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:vv(t.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},warnings:a}}(i,{bodies:o,projectionRows:t.projectionRows,stepsRun:n,charge:t.charge});return{snapshot:i,bodies:o,sceneNodes:r,evidence:s,stepsRun:n}}(e,f),g={..._v,...d},y=[n,o],m=Pv(a,y,g),x=Pv(c,y,g),b=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(u),v=i?b+"-title":void 0,w=r?b+"-desc":void 0,k=[v,w].filter(Boolean).join(" ")||void 0;return{svg:bv.renderToStaticMarkup((0,Mv.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:n,height:o,viewBox:`0 0 ${n} ${o}`,role:"img","aria-labelledby":k,children:[i&&(0,Mv.jsx)("title",{id:v,children:i}),r&&(0,Mv.jsx)("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?(0,Mv.jsx)("rect",{x:0,y:0,width:n,height:o,fill:s}):null,m,(0,Mv.jsx)("g",{id:b+"-data-area",children:p.sceneNodes.map((e,t)=>{const n=p.bodies[t];return(n&&h?h(n,e.style??{},t,b):void 0)??Ra(e,t,b)})}),x]})),scene:p,evidence:p.evidence}}(o,{...e,width:n[0],height:n[1],charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics"});return t&&(t.evidence=rm({frameType:"physics",width:n[0],height:n[1],marks:i.scene.sceneNodes,title:e.title,description:e.description,annotations:[],extraWarnings:[...0===i.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...i.scene.evidence.warnings]})),i.svg}var Cv=g(require("react-dom/server"));var Rv=require("react/jsx-runtime"),Lv={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Tv(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}var Iv={BigNumber:function(e,t){const n="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",o=Lv[n],i=Tv(e.width,o.width),r=Tv(e.height,o.height),s="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):o.padding,a="center"===e.align||"end"===e.align||"start"===e.align?e.align:o.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=et(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=function(e,t={}){if("function"==typeof e)return e;const n=t.locale??"en-US";if("currency"===e){const e=t.precision??2,o=new Intl.NumberFormat(n,{style:"currency",currency:t.currency??"USD",maximumFractionDigits:e,minimumFractionDigits:e});return e=>o.format(e)}if("percent"===e){const e=new Intl.NumberFormat(n,{style:"percent",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("compact"===e){const e=new Intl.NumberFormat(n,{notation:"compact",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("duration"===e)return e=>function(e){if(!Number.isFinite(e))return e+"";const t=0>e?"-":"",n=Math.abs(e);if(1e3>n)return`${t}${Math.round(n)}ms`;const o=n/1e3;if(60>o)return`${t}${i=o,Math.round(100*i)/100+""}s`;var i;const r=o/60;if(60>r){const e=Math.floor(r),n=Math.round(o-60*e);return 0===n?`${t}${e}m`:`${t}${e}m ${n}s`}const s=r/60;if(24>s){const e=Math.floor(s),n=Math.round(r-60*e);return 0===n?`${t}${e}h`:`${t}${e}h ${n}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${t}${a}d`:`${t}${a}d ${l}h`}(e);const o=new Intl.NumberFormat(n,{notation:t.notation??"standard",maximumFractionDigits:t.precision??0,minimumFractionDigits:0});return e=>o.format(e)}("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof e.prefix?e.prefix:void 0)??""}${p}${("string"==typeof e.suffix?e.suffix:void 0)??""}`);var p;const g=void 0===d?void 0:function(e,t){if(!t||0===t.length)return null;if(!Number.isFinite(e))return null;const n=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at);let o=null;for(const t of n){if(t.at>e)break;o=t}return o}(d,e.thresholds),y="string"==typeof e.color?e.color:function(e,t,n){return t||("success"===e?n.colors.success??"#2ca02c":"warning"===e?n.colors.warning??"#b26a00":"danger"===e?n.colors.danger??"#d62728":"info"===e?n.colors.info??n.colors.primary:n.colors.text)}(g?.level??"neutral",g?.color,u),m="string"==typeof e.label?e.label:void 0,x="string"==typeof e.caption?e.caption:void 0,b="string"==typeof e.unit?e.unit:void 0,v=void 0===d?void 0:function(e,t,n){const o=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,i=o&&"number"==typeof o.value&&Number.isFinite(o.value)?o.value:void 0,r=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===i?void 0:t-i);if(void 0===r)return;const s=function(e,t){return Number.isFinite(e)?0===e?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}(r,n);return`${s}${o&&"string"==typeof o.label?" "+o.label:""}`}(e,d,h),w=void 0===d?void 0:function(e,t,n){const o=e.target&&"object"==typeof e.target?e.target:void 0;if(!o||"number"!=typeof o.value||!Number.isFinite(o.value))return;const i="string"==typeof o.label?" "+o.label:"";return 0===o.value?`target ${n(o.value)}${i}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/o.value)} of ${n(o.value)}${i}`}(e,d,h),k=[v,w,g?.label].filter(Boolean).join(" · "),S="string"==typeof e.description&&e.description||[m,f,b,k].filter(Boolean).join(", "),A="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,M="string"==typeof e.borderColor?e.borderColor:u.colors.border,_=s+o.labelSize,P=_+o.captionSize+4,j="presentation"===n?r/2+.32*o.valueSize:"thumbnail"===n?r/2+.34*o.valueSize:Math.min(r-s-(k?26:4),(o.showHeader&&(m||x)?x?P+10:_+14:s)+o.valueSize),C=c+("start"===l?Math.max(o.valueSize,f.length*o.valueSize*.55):0),R=Cv.renderToStaticMarkup((0,Rv.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber",children:[(0,Rv.jsx)("title",{children:m??f}),"string"==typeof e.description&&(0,Rv.jsx)("desc",{children:e.description}),(0,Rv.jsx)("rect",{x:o.border?.5:0,y:o.border?.5:0,width:o.border?i-1:i,height:o.border?r-1:r,rx:o.border?8:0,fill:A,stroke:o.border?M:"none"}),o.showHeader&&m&&(0,Rv.jsx)("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.labelSize,fontWeight:600,fill:u.colors.text,children:m}),o.showHeader&&x&&(0,Rv.jsx)("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.captionSize,fill:u.colors.textSecondary,children:x}),(0,Rv.jsx)("text",{x:c,y:j,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===l&&(0,Rv.jsx)("text",{x:C+6,y:j,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*o.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),o.showDetail&&k&&(0,Rv.jsx)("text",{x:c,y:Math.min(r-s,j+o.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:o.detailSize,fill:u.colors.textSecondary,children:k})]}));return t&&(t.evidence=rm({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:S})),R}};function $v(e,t,n){return Iv[e](t,n)}var Ov=require("react/jsx-runtime");function zv(e,t){switch(e){case"xy":return Bm(t);case"ordinal":return px(t);case"network":return Bb(t);case"geo":return xv(t);case"physics":return jv(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Dv(e){return Bm(e)}function Fv(e){return px(e)}function Ev(e){return Bb(e)}function Nv(e){return xv(e)}var Bv=["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"],Wv=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Yv(e,t){const n={};for(const o of t)void 0!==e[o]&&(n[o]=e[o]);return n}function qv(e,t,n){return Hv(e,t).svg}function Xv(e,t,n){const o={},{svg:i,frameType:r}=Hv(e,t,0,o),s=o.evidence??rm({frameType:r,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=e,{svg:i,evidence:s}}function Hv(e,t,n,o){if(e in Iv)return{svg:$v(e,t,o),frameType:"value"};const i=nm[e];if(!i)throw Error(`Unknown chart component: "${e}". See CLAUDE.md for supported chart types.`);var r;const s=R(i.layout?.mode??("string"==typeof(r=t.mode)&&Object.prototype.hasOwnProperty.call(C,r)?t.mode:void 0),{...i.layout?.modeDefaults,...Yv(t,Wv)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:g,...y}=t,{width:m,height:x}=s,b=[m,x],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(t,s):w??s.marginDefaults,S=void 0!==h?h:v.margin,A=T(S),M="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...k,...A},_=Yv(y,Bv),P=e=>v[e]??s[e],j={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:b,margin:M,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},L=i.buildProps(a,p,f,j,y);let $;switch(i.frameType){case"xy":$=Bm(L,o);break;case"ordinal":$=px(L,o);break;case"network":$=Bb(L,o);break;case"geo":$=xv(L,o);break;case"physics":$=jv(L,o)}const O=i.renderOverlay?.(L,{theme:et(l)});if(null!=O){const e=I.renderToStaticMarkup((0,Ov.jsx)(Ov.Fragment,{children:O}));$=$.replace("</svg>",e+"</svg>")}return{svg:$,frameType:i.frameType}}async function Gv(e,t,n={}){const{format:o="png",scale:i=1,background:r}=n;let s,a;s=["xy","ordinal","network","geo","physics"].includes(e)?zv(e,t):qv(e,t),r&&(s=s.replace(/<svg /,`<svg style="background:${r}" `));try{const e="sharp",t=await import(e);a=t.default??t}catch{throw Error('Image export requires the "sharp" package and a Node.js runtime. Install it:\n npm install sharp\nsharp is listed as an optional dependency of semiotic.')}const l=t.width||t.size?.[0]||600,c=t.height||t.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*i}).resize(Math.round(l*i),Math.round(c*i));return"jpeg"===o?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function Vv(e,t={}){const{title:n,subtitle:o,theme:i,width:r=1200,height:s,layout:a={},background:l}=t,c=tt(et(i)),u=a.columns||2,d=a.gap??16;let h=0;n&&(h+=30),o&&(h+=20),h>0&&(h+=10);const f=Math.floor((r-d-d*(u-1))/u),p=[];let g=0,y=h+d,m=0;for(const t of e){const e=Math.min(t.colSpan||1,u),n=t.props.height||300;g+e>u&&(y+=m+d,g=0,m=0),p.push({chart:t,x:d/2+g*(f+d),y:y,w:f*e+d*(e-1),h:n}),m=Math.max(m,n),g+=e}const x=s||y+m+d,b=p.map((e,t)=>{const{chart:n,x:o,y:r,w:s,h:a}=e,l={...n.props,width:s,height:a,theme:i,_idPrefix:"chart-"+t};let c;return c=n.component?qv(n.component,l):n.frameType?zv(n.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,(0,Ov.jsx)("g",{transform:`translate(${o},${r})`,children:(0,Ov.jsx)("foreignObject",{width:s,height:a,children:(0,Ov.jsx)("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+t)});return I.renderToStaticMarkup((0,Ov.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":n||"Dashboard",style:{fontFamily:c.fontFamily},children:[n&&(0,Ov.jsx)("title",{children:n}),l&&(0,Ov.jsx)("rect",{x:0,y:0,width:r,height:x,fill:l}),n&&(0,Ov.jsx)("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleSize+4,fontWeight:"bold",fill:c.text,fontFamily:c.fontFamily,children:n}),o&&(0,Ov.jsx)("text",{x:r/2,y:n?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:o}),b]}))}var Uv=g(require("react-dom/server")),Kv=require("react/jsx-runtime");function Zv(e,t,n,o={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=o,f=n.width||600,p=n.height||400,g=et(n.theme),y={...n,...a&&{xExtent:a},...l&&{yExtent:l}};if(!t||0===t.length)return[];const m=i||Math.max(1,Math.ceil(t.length/(s||Math.min(60,Math.max(10,t.length))))),x=[];for(let e=m;t.length>=e;e+=m)x.push(e);x[x.length-1]!==t.length&&x.push(t.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),v=Ks({top:20,right:20,bottom:30,left:40,...n.margin},n.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(b)for(let o=0;x.length>o;o++){const i=x[o],s=t.slice(r?Math.max(0,i-r):0,i),a={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:n.projection||"vertical",oAccessor:n.oAccessor||n.categoryAccessor||"category",rAccessor:n.rAccessor||n.valueAccessor||"value",colorAccessor:n.colorAccessor||n.colorBy,stackBy:n.stackBy,groupBy:n.groupBy,barPadding:n.barPadding,innerRadius:n.innerRadius,normalize:n.normalize,bins:n.bins,colorScheme:n.colorScheme||g.colors.categorical,...h&&{decay:h}},l=new dx(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&S.push(ow(l.scene,f,p,g,y))}else for(let o=0;x.length>o;o++){const i=x[o],s=t.slice(r?Math.max(0,i-r):0,i),m={chartType:e,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:n.colorAccessor||n.colorBy,groupAccessor:n.groupAccessor||n.lineBy,lineDataAccessor:n.lineDataAccessor,xExtent:a,yExtent:l,colorScheme:n.colorScheme||g.colors.categorical,lineStyle:n.lineStyle,pointStyle:n.pointStyle,areaStyle:n.areaStyle,sizeAccessor:n.sizeAccessor||n.sizeBy,sizeRange:n.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},b=new yo(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(S.push(nw(b.scene,f,p,g,y,v)),c>0&&o>0&&b.activeTransition){const e=c*(1e3/u);for(let t=1;c>=t;t++)b.advanceTransition(b.activeTransition.startTime+t/c*e),S.push(nw(b.scene,f,p,g,y,v))}}return S}function Qv(e,t,n={}){return t.map(t=>{try{return qv(e,{...n,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${n.width||t.width||600}" height="${n.height||t.height||400}"></svg>`}})}function Jv(e,t,n){const o=t.size??[t.width??600,t.height??400],i=et(t.theme),r=tt(i),s=t.background||i.colors.background,a=t.idPrefix??"physics-gif",l=t.title?`${a}-title-${n}`:void 0,c=t.description?`${a}-desc-${n}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=Av(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),h=(0,Kv.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[t.title&&(0,Kv.jsx)("title",{id:l,children:t.title}),t.description&&(0,Kv.jsx)("desc",{id:c,children:t.description}),s&&"transparent"!==s?(0,Kv.jsx)("rect",{x:0,y:0,width:o[0],height:o[1],fill:s}):null,(0,Kv.jsx)("g",{id:`${a}-frame-${n}`,children:d.map((e,t)=>Ra(e,t,`${a}-${n}`))})]});return Uv.renderToStaticMarkup(h)}function ew(e,t={}){const{fps:n=12,frameCount:o,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:l}=t,c=Math.max(.001,s??e.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,n)/c)),d=o??Math.max(1,Math.ceil(i*Math.max(1,n))),h=l?{...e,background:l}:e,f=new gg(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(Jv(f,h,0)));d>p.length;){for(let e=0;u>e;e+=1)f.tick(c);p.push(Jv(f,h,p.length))}return p}function tw(e,t){const n=e.background||t.colors.background;return n&&"transparent"!==n?n:null}function nw(e,t,n,o,i,r){const s=tt(o),a=Ks({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=t-a.left-a.right,c=n-a.top-a.bottom,u=tw(i,o),d=i.renderMode,h=e.map((e,t)=>zc({node:e,index:t,renderMode:d,fallback:()=>Ra(e,t)})).filter(Boolean),f=function(e,t,n,o,i,r){if(!e||0===e.length)return null;const s=tt(o),a=[];for(let o=0;e.length>o;o++){const l=e[o];if("y-threshold"===l.type&&null!=l.value){let e=null;if(r)e=r(l.value);else if(i){const[t,o]=i,r=o-t;if(0===r)continue;e=n-(l.value-t)/r*n}if(null==e)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push((0,Kv.jsxs)("g",{children:[(0,Kv.jsx)("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&(0,Kv.jsx)("text",{x:"left"===u?4:"center"===u?t/2:t-4,y:20>e?Math.min(n-4,e+16):e-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+o))}}return a.length>0?(0,Kv.jsx)(Kv.Fragment,{children:a}):null}(i.annotations,l,c,o,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=p?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Uv.renderToStaticMarkup((0,Kv.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:n,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&(0,Kv.jsx)("title",{id:y,children:p}),g&&(0,Kv.jsx)("desc",{id:m,children:g}),u&&(0,Kv.jsx)("rect",{x:0,y:0,width:t,height:n,fill:u}),(0,Kv.jsxs)("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&(0,Kv.jsx)("text",{x:t/2,y:Gs,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}function ow(e,t,n,o,i){const r=tt(o),s=Ks({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(t-s.left-s.right)/2:s.left,c=a?s.top+(n-s.top-s.bottom)/2:s.top,u=tw(i,o),d=i.renderMode,h=e.map((e,t)=>zc({node:e,index:t,renderMode:d,fallback:()=>Pa(e,t)})).filter(Boolean),f="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,g=f?"semiotic-title":void 0,y=p?"semiotic-desc":void 0,m=[g,y].filter(Boolean).join(" ")||void 0;return Uv.renderToStaticMarkup((0,Kv.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:n,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[f&&(0,Kv.jsx)("title",{id:g,children:f}),p&&(0,Kv.jsx)("desc",{id:y,children:p}),u&&(0,Kv.jsx)("rect",{x:0,y:0,width:t,height:n,fill:u}),(0,Kv.jsx)("g",{transform:`translate(${l},${c})`,children:h}),f&&(0,Kv.jsx)("text",{x:t/2,y:Gs,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:f})]}))}async function iw(e,t,n,o={}){const{fps:i=12,loop:r=!0,scale:s=1,background:a}=o,l=n.width||600,c=n.height||400,u=Zv(e,t,a?{...n,background:a}:n,o);if(0===u.length)throw Error("No frames generated — check that data is not empty");return sw(u,l,c,{fps:i,loop:r,scale:s})}async function rw(e,t={}){const{fps:n=12,loop:o=!0,scale:i=1}=t,r=e.size??[e.width??600,e.height??400],s=ew(e,t);if(0===s.length)throw Error("No physics frames generated");return sw(s,r[0],r[1],{fps:n,loop:o,scale:i})}async function sw(e,t,n,o={}){const{fps:i=12,loop:r=!0,scale:s=1}=o,a=Math.round(t*s),l=Math.round(n*s);let c,u,d,h;try{const e="sharp",t=await import(e);c=t.default??t}catch{throw Error('Animated GIF export requires "sharp". Install it:\n npm install sharp')}try{const e="gifenc",t=await import(e),n=[t,t.default].find(e=>"function"==typeof e?.GIFEncoder&&"function"==typeof e.quantize&&"function"==typeof e.applyPalette);if(!n)throw Error("gifenc did not expose its encoder functions");u=n.GIFEncoder,d=n.quantize,h=n.applyPalette}catch(e){throw Error('Animated GIF export requires "gifenc". Install it:\n npm install gifenc',{cause:e})}const f=Math.round(1e3/i),p=u();for(let t=0;e.length>t;t++){const n=e[t],o=await c(Buffer.from(n),{density:72*s}).resize(a,l).ensureAlpha().raw().toBuffer(),i=new Uint8Array(o),u=d(i,256),g=h(i,u);p.writeFrame(g,a,l,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}
|
|
1
|
+
var t,e=Object.create,o=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(t,e,r,a)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let c of n(e))s.call(t,c)||c===r||o(t,c,{get:()=>e[c],enumerable:!(a=i(e,c))||a.enumerable});return t},c=(t,i,n)=>(n=null!=t?e(r(t)):{},a(!i&&t&&t.__esModule?n:o(n,"default",{value:t,enumerable:!0}),t)),l={};function u(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}((t,e)=>{for(var i in e)o(t,i,{get:e[i],enumerable:!0})})(l,{generateFrameSVGs:()=>dm,generateFrameSequence:()=>hm,generatePhysicsFrameSVGs:()=>pm,renderChart:()=>nm,renderChartWithEvidence:()=>rm,renderDashboard:()=>cm,renderGeoToStaticSVG:()=>Kg,renderNetworkToStaticSVG:()=>Ug,renderOrdinalToStaticSVG:()=>Hg,renderPhysicsToAnimatedGif:()=>bm,renderToAnimatedGif:()=>xm,renderToImage:()=>am,renderToStaticSVG:()=>Gg,renderXYToStaticSVG:()=>Vg,resolveTheme:()=>Ot,serializeSvgPrecision:()=>tm,themeStyles:()=>zt}),module.exports=(t=l,a(o({},"__esModule",{value:!0}),t));var d=44,h={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:d,snap:"nearestDatum",brushHandleSize:d,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function f(t,e={}){const o=e.mobileSemantics?.interaction,i="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,n="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==i,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!n&&!r)return h;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??i??d,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??d,standardControls:a.standardControls??!1}}var p={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 y(t,e,o){if(!1!==e)return t;const i={...t};return"horizontal"===o?i.left=Math.min(i.left,15):i.bottom=Math.min(i.bottom,15),i}function g(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var m={kind:"rank-competition"};function x(t,e,o,i){const n=t??e;return"function"==typeof n?n(o,i):o[n+""]}var b=Symbol.for("semiotic.semantic-viability"),v=globalThis,w=v[b]??(v[b]=new Map);function k(t){return"string"==typeof t?.code&&t.code.length>0&&("warning"===t.severity||"error"===t.severity)&&"string"==typeof t.message&&t.message.length>0}function S(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const i=function(t){return function(t){return w.has(t)}(t)?function(t){return w.get(t)}(t):"BumpChart"===t?m:void 0}(e);if(!i)return;let n;try{const e="function"==typeof i?i(o,t):function(t){const e=new Map;(Array.isArray(t.data)?t.data:[]).forEach((o,i)=>{if(!Number.isFinite(Number(x(t.yAccessor,"y",o,i))))return;const n=g(x(t.xAccessor,"x",o,i)),r=e.get(n)??new Set;r.add(x(t.lineBy,"series",o,i)+""),e.set(n,r)});const o=Array.from(e.values(),t=>t.size).sort((t,e)=>t-e);if(0===o.length)return[];const i=Math.floor(o.length/2),n={columns:o.length,median:o.length%2?o[i]:(o[i-1]+o[i])/2,max:o[o.length-1],contestedColumns:o.filter(t=>t>=2).length},r=2>n.max;return r||2>n.contestedColumns||2>n.median?[{code:r?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:r?"error":"warning",message:r?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...n}}]:[]}(o);n=Array.from(e).filter(k)}catch{return void(t.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||t.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}t.semanticDiagnostics=n,t.semanticStatus=n.some(t=>"error"===t.severity)?"degenerate":n.some(t=>"warning"===t.severity)?"degraded":"meaningful";for(const e of n)t.warnings.includes(e.code)||t.warnings.push(e.code)}var A=c(require("react-dom/server")),M=c(require("react")),_=Object.freeze([]);function P(t){if(!t)return _;let e=!1;for(let o=0;t.length>o;o++){const i=t[o];if(null==i||"object"!=typeof i){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}var j=require("d3-scale");function L(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function $(t,e,o){const i=t=>t.toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(o)}`}function R(t){const e=t.map(L),o=e.length-1;return t=>{if(0>=t){const[t,o,i]=e[0];return $(t,o,i)}if(t>=1){const[t,i,n]=e[o];return $(t,i,n)}const i=t*o,n=Math.floor(i),r=i-n,[s,a,c]=e[n],[l,u,d]=e[n+1];return $(Math.round(s+(l-s)*r),Math.round(a+(u-a)*r),Math.round(c+(d-c)*r))}}var C=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],I=R(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),T=R(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),O=R(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),z=R(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),F=R(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),N=R(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),E=R(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),D=R(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),B=R(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),W=R(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),Y=R(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),q=R(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),X={blues:I,reds:T,greens:O,viridis:E,oranges:z,purples:F,greys:N,plasma:D,inferno:B,magma:W,cividis:Y,turbo:q};function G(t){return t&&Object.prototype.hasOwnProperty.call(X,t)?X[t]:I}var V=R(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),H=R(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),U=R(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),K=R(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Z=R(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Q=R(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),J=R(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),tt={category10:C,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...X},et=C,ot="#007bff";function it(t,e,o=et){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=Object.prototype.hasOwnProperty.call(tt,t)?tt[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var nt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],rt=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],st=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 at(t,e,o){if("function"==typeof e){const i=e(t);return o&&i&&"string"==typeof i&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||st.has(e)}(i)?o(i):i}const i=t?.[e]+"";return o?o(i):et[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)}(i))%et.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 lt(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>ct(t,e)??"#999"}const i=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),n=i.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return(0,j.scaleOrdinal)().domain(i).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(tt,o)?tt[o]:tt.category10;if(n&&"function"==typeof r){let t=-1/0;for(const e of i){const o=Number(e);o>t&&(t=o)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:et;return(0,j.scaleOrdinal)().domain(i).range(t).unknown("#999")}}function ut(t,e,o=[3,20],i){let n;if(n="function"==typeof e?e(t):t?.[e],!i)return n;const[r,s]=i,[a,c]=o;if(s===r)return(a+c)/2;let l=(n-r)/(s-r);return 0>l?l=0:l>1&&(l=1),a+l*(c-a)}function dt(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function ht(t,e){if(!dt(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 ft(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>gt(e(t))}function pt(t,e){const o=ft(t),i=ft(e);return(t,e)=>{const n=i(t);return{value:n,x:o(t),y:n,category:e}}}function yt(t,e){const o=ft(e??"value"),i=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=i?i(t):void 0;return{value:o(t),category:null==e?void 0:e+""}}}function gt(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 mt(t,e,o){const i=t.when;return void 0===i||!0===i||!1!==i&&("function"==typeof i?i(e,o):function(t,e,o){const i=null!=t.axis?o[t.axis]:null!=t.field?e[t.field]:o.value;if(void 0!==t.eq&&i!==t.eq)return!1;if(void 0!==t.ne&&i===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(i))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const n=gt(i);if(void 0===n)return!1;if(void 0!==t.gt&&t.gt>=n)return!1;if(void 0!==t.gte&&t.gte>n)return!1;if(void 0!==t.lt&&n>=t.lt)return!1;if(void 0!==t.lte&&n>t.lte)return!1;if(void 0!==t.within){const[e,o]=t.within;if(e>n||n>o)return!1}if(void 0!==t.outside){const[e,o]=t.outside;if(n>=e&&o>=n)return!1}return!0}(i,e,o))}function xt(t,e,o){if(!e||0===e.length)return{};let i={};for(const n of e){if(!mt(n,t,o))continue;const e="function"==typeof n.style?n.style(t,o):n.style;e&&(i={...i,...e})}return i}function bt(t,e,o,i=t=>t){const n=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=i(t),a={...n(t,r)};return Object.assign(a,xt(s,e,o(s,r))),a}:n}function vt(t,e,o,i){if(!t||0===t.length)return i;const n=yt(e,o);return(e,o)=>{const r=e&&e.data||e,s=xt(r,t,n(r)),a=i?i(e,o):void 0;return a?{...s,...a}:s}}var wt={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function kt(t,e=wt){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function St(t){return t?kt(t):void 0}function At(t,e,o){return"function"==typeof t?t(o):o[t||e]}function Mt(t){return t instanceof Date?t.getTime():Number(t)}function _t(t,e){return E(1===e?.5:t/(e-1))}function Pt(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function jt(t,e){const o=function(t){if(!t)return;const e="boolean"==typeof t?{}:"string"==typeof t?{method:t}:t;return{type:"trend",method:e.method??"linear",...null!=e.bandwidth&&{bandwidth:e.bandwidth},...null!=e.order&&{order:e.order},...null!=e.color&&{color:e.color},...null!=e.strokeWidth&&{strokeWidth:e.strokeWidth},...null!=e.strokeDasharray&&{strokeDasharray:e.strokeDasharray},...null!=e.label&&{label:e.label}}}(e),i=Array.isArray(t)?t:void 0;return o?[o,...i??[]]:i}var Lt=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],$t={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}},Rt={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}},Ct={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:Lt,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 It(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}}var Tt={light:$t,dark:Rt,"high-contrast":Ct,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 Ot(t){if(!t)return $t;if("string"==typeof t){if("light"===t)return $t;if("dark"===t)return Rt;if("high-contrast"===t)return Ct;return(Object.prototype.hasOwnProperty.call(Tt,e=t)?Tt[e]:void 0)||$t}var e;const o="dark"===t.mode?Rt:$t;return function(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:Lt}}),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}({...o,...t,colors:{...o.colors,...t.colors||{}},typography:{...o.typography,...t.typography||{}},tooltip:{...o.tooltip,...t.tooltip||{}}})}function zt(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,legendFontFamily:t.typography.legendFontFamily??t.typography.fontFamily,legendFontWeight:t.typography.legendFontWeight,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,titleFontFamily:t.typography.titleFontFamily??t.typography.fontFamily,titleFontWeight:t.typography.titleFontWeight??"bold",tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}function Ft(t,e,o){const i="function"==typeof e?e(t):t[e??o];if(null==i)return null;if(i instanceof Date)return i.getTime();if("string"==typeof i&&""===i.trim())return null;const n=Number(i);return Number.isFinite(n)?n:null}function Nt(t){let e=1/0,o=-1/0;for(const i of t)e>i&&(e=i),i>o&&(o=i);return[e,o]}function Et(t,e=-1/0){let o=e;for(const e of t)e>o&&(o=e);return o}var Dt=2;function Bt(t){const e=10**Dt;return Math.round(t*e)/e}function Wt(t,e=2){const o=[],i=[],n=e+1;for(let e=0;n>e;e++){let r=0;for(const[o,i]of t)null!==i&&(r+=o**e*i);o.push(r);const s=[];for(let o=0;n>o;o++){let i=0;for(const[n,r]of t)null!==r&&(i+=n**(e+o));s.push(i)}i.push(s)}i.push(o);const r=function(t,e){const o=t,i=t.length-1,n=[e];for(let t=0;i>t;t++){let e=t;for(let n=t+1;i>n;n++)Math.abs(o[t][n])>Math.abs(o[t][e])&&(e=n);for(let n=t;i+1>n;n++){const i=o[n][t];o[n][t]=o[n][e],o[n][e]=i}for(let e=t+1;i>e;e++)for(let n=i;n>=t;n--)o[n][e]-=o[n][t]*o[t][e]/o[t][t]}for(let t=i-1;t>=0;t--){let e=0;for(let r=t+1;i>r;r++)e+=o[r][t]*n[r];n[t]=(o[i][t]-e)/o[t][t]}return n}(i,n).map(Bt);return{points:t.map(([t])=>[Bt(t),Bt(r.reduce((e,o,i)=>e+o*t**i,0))]),equation:[...r].reverse()}}function Yt(t){const e=t.length;let o=0,i=0,n=0,r=0;for(const[e,s]of t)o+=e,i+=s,n+=e*e,r+=e*s;const s=e*n-o*o;if(1e-12>Math.abs(s))return null;const a=(e*r-o*i)/s,c=(i-a*o)/e;return t=>c+a*t}function qt(t,e){const o=t.length,i=t.map(([t,o])=>o-e(t)).reduce((t,e)=>t+e*e,0),n=Math.sqrt(i/Math.max(o-2,1)),r=t.reduce((t,e)=>t+e[0],0)/o,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:n,meanX:r,ssX:s}}function Xt(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Gt="__forecastSegment",Vt="__forecastOpacity";function Ht(t,e,o,i){const n=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!n&&!r)return;const s="object"==typeof n?n:{},a=s.min??.15,c=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const o of t){const t=e(o);null!=t&&Number.isFinite(t)&&(o[Vt]=a+Math.max(0,Math.min(1,t))*(c-a))}return}const l=t.map(t=>{const e=o(t),n=i(t);return null!=e&&null!=n&&Number.isFinite(e)&&Number.isFinite(n)?Math.abs(e-n):NaN}),u=l.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=Nt(u),f=h-d;t.forEach((t,e)=>{const o=l[e];Number.isFinite(o)&&(t[Vt]=c-(f>0?(o-d)/f:0)*(c-a))})}function Ut(t,e){return"function"==typeof e?e(t):!!t[e]}var Kt="__semiotic_resolvedX",Zt="__semiotic_resolvedY",Qt="__compoundGroup";function Jt(t,e,o){const i=t[e],n=t[o];return null==i||null==n||Number.isNaN(i)||Number.isNaN(n)}function te(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",i=t.lineBy,n=t.colorBy||i;let r=Array.isArray(t.data)?P(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const i="function"==typeof e,n="function"==typeof o,r=i?Kt:e,s=n?Zt:o;return i||n?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return i&&(r[Kt]=e(t)),n&&(r[Zt]=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="string"==typeof i||"function"==typeof i?i:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,i,n){return(r=i).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,i,n){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:c,lowerBounds:l,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=i,y=t.map(t=>{let e="observed";return s&&Ut(t,s)?e="forecast":r&&Ut(t,r)&&(e="training"),{...t,[Gt]:e}}),g=i._groupBy,m=[];if(g){const t=new Map;for(const e of y){const o=e[g]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Gt]!==o[t+1][Gt]&&(e.push({...o[t+1],[Gt]:o[t][Gt]}),e.push({...o[t],[Gt]:o[t+1][Gt]}));m.push(...y,...e)}else for(let t=0;y.length>t;t++)m.push(y[t]),y.length-1>t&&y[t][Gt]!==y[t+1][Gt]&&(m.push({...y[t+1],[Gt]:y[t][Gt]}),m.push({...y[t],[Gt]:y[t+1][Gt]}));if(i.trainUnderline){const t=[];for(const e of m)"training"===e[Gt]&&t.push({...e,[Gt]:"training-base"});m.unshift(...t)}const x=[];if(c&&l){const t="string"==typeof c?c:"__envUpper",e="string"==typeof l?l:"__envLower";if("function"==typeof c||"function"==typeof l)for(const o of m)"function"==typeof c&&(o[t]=c(o)),"function"==typeof l&&(o[e]=l(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(i.uncertaintyOpacity||i.confidenceAccessor){const t=c?"function"==typeof c?c:t=>t[c]:()=>{},e=l?"function"==typeof l?l:t=>t[l]:()=>{};Ht(m.filter(t=>"forecast"===t[Gt]),i,t,e)}if(a){const t=i.anomalyStyle,e={type:"highlight",filter:t=>Ut(t,a)};t?(e.style=t,e.r=f):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=f):(e.color=h,e.r=f,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(e)}return n&&x.push({type:"anomaly-band",threshold:n.threshold??2,showBand:!1!==n.showBand,fill:n.bandColor||"#6366f1",fillOpacity:n.bandOpacity??.1,anomalyColor:n.anomalyColor||"#ef4444",anomalyRadius:n.anomalyRadius??6,label:n.label}),{processedData:m,annotations:x}}(t,0,0,i,n):function(t,e,o,i,n){const{trainEnd:r,steps:s=10,confidence:a=.95,color:c="#6366f1",bandOpacity:l=.15,label:u}=i;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const o of t)o[e]>r?h.push({...o,[Gt]:"observed"}):d.push({...o,[Gt]:"training"});const f=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),p=[],y=[];if(f.length>=3){const n=f.length,r=Yt(f);if(r){const{se:d,meanX:h,ssX:g}=qt(f,r),m=Xt(a),x=Et(t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t))),b=f.length>1?(f[n-1][0]-f[0][0])/(n-1):1;for(let t=1;s>=t;t++){const i=x+t*b,s=r(i),a=d*Math.sqrt(1+1/n+(g>0?(i-h)**2/g:0))*m;y.push({[e]:i,[o]:s,[Gt]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}Ht(y,i,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:c,fillOpacity:l,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),n&&p.push({type:"anomaly-band",threshold:n.threshold??2,showBand:!1!==n.showBand,fill:n.bandColor||"#6366f1",fillOpacity:n.bandOpacity??.1,anomalyColor:n.anomalyColor||"#ef4444",anomalyRadius:n.anomalyRadius??6,label:n.label});const g=[];if(g.push(...d),d.length>0&&h.length>0&&g.push({...d[d.length-1],[Gt]:"observed"}),g.push(...h),y.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&g.push({...t,[Gt]:"forecast"}),g.push(...y)}return{processedData:g,annotations:p}}(t,e,o,i,n);var r}(r,a,c,i&&"string"==typeof i&&"object"==typeof t.forecast?{...t.forecast,_groupBy:i}:t.forecast,t.anomaly);if(r=e.processedData,l.push(...e.annotations),u=function(t,e,o){const i=o.upperBounds,n=o.lowerBounds;if(!i&&!n)return;const r="function"==typeof i?i:"string"==typeof i?t=>t[i]:null,s="function"==typeof n?n:"string"==typeof n?t=>t[n]: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),i&&"string"==typeof i?(r=r.map(t=>({...t,[Qt]:`${t[i]}__${t[Gt]||"observed"}`})),d=Qt):d=Gt,t.baseLineStyle){const e=function(t,e){const o=e.trainDasharray??"8,4",i=e.forecastDasharray??"4,4",n=e.color||"#6366f1",r=e.trainOpacity,s=e.forecastOpacity,a=e.trainStroke,c=e.trainLinecap,l=e.trainUnderline;return e=>{const u=t(e),d=e[Gt];if("training"===d){let t=u.stroke;return"darken"===a?t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const i=Math.round(parseInt(o[1],16)*(1-e)),n=Math.round(parseInt(o[2],16)*(1-e)),r=Math.round(parseInt(o[3],16)*(1-e));return`#${i.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(t=a),{...u,stroke:t,strokeDasharray:o,...c&&{strokeLinecap:c},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let t=u.stroke||"#666";return"lighten"===l&&(t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const i=Math.round(parseInt(o[1],16)+(255-parseInt(o[1],16))*e),n=Math.round(parseInt(o[2],16)+(255-parseInt(o[2],16))*e),r=Math.round(parseInt(o[3],16)+(255-parseInt(o[3],16))*e);return`#${i.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(t,.4)),{...u,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Vt],o=null!=t?t:s;return{...u,stroke:n,strokeDasharray:i,...null!=o&&{strokeOpacity:o}}}return u}}(e=>t.baseLineStyle(e),t.forecast);h=t=>e(t)}}else t.anomaly&&l.push(...(f=t.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,i,n){const r=new Map;for(const e of t){const t=n?(e[n]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const n of e)Jt(n,o,i)||t.push(n);return{rows:t,groupKey:n}}if("zero"===e){const t=[];for(const[,e]of r)for(const n of e)Jt(n,o,i)?t.push({...n,[i]:0}):t.push(n);return{rows:t,groupKey:n}}const s=[],a="_gapSegment";for(const[t,e]of r){let n=0,r=[];const c=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+n:`${t}__seg${n}`;for(const t of r)s.push({...t,[a]:e});r=[],n++};for(const t of e)Jt(t,o,i)?c():r.push(t);c()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,c,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let p;if(t.directLabel){const e=function(t,e,o,i,n,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[i])-Number(e[i])),f.set(t,"end"===l?e[e.length-1]:e[0]);const p=lt(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),y=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[i]:e[i],[n]:e[n],dx:"end"===l?6:-6,dy:0,color:p?at({__lbl:t},"__lbl",p):a||ot,fontSize:u}));y.sort((t,e)=>Number(t[n])-Number(e[n]));for(let t=1;y.length>t;t++){const e=y[t-1],o=y[t],i=Number(e[n])+e.dy;u+2>Math.abs(Number(o[n])+o.dy-i)&&(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 n||"function"==typeof n?n:void 0,a,c,t.colorScheme,t.themeCategorical,t.color);l.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?c:o,groupAccessor:d,colorAccessor:n,annotations:l,lineStyle:h,yExtent:u,marginExtra:p}}function ee(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Ot(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrScatterColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?lt(l,c,a):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[3,15],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Nt(f):void 0,y=pt(n.xAccessor,n.yAccessor),g=n.styleRules;return t=>{const o={fill:e&&u?at(t,e,u):"string"==typeof n.color?n.color:ot,fillOpacity:"number"==typeof n.pointOpacity?n.pointOpacity:.8,r:d?ut(t,d,h,p):"number"==typeof n.pointRadius?n.pointRadius:5};return g?.length&&Object.assign(o,xt(t,g,y(t))),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}var oe={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=te({data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:Ot(i.theme).colors.categorical}),s=jt(r.annotations,n.regression);return{chartType:"scatter",data:r.data,xAccessor:r.xAccessor,yAccessor:r.yAccessor,colorAccessor:e,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:o,...i,...s&&s.length>0&&{annotations:s},...r.yExtent&&!i.yExtent&&{yExtent:r.yExtent},sizeRange:n.sizeRange||[3,15],pointStyle:i.pointStyle||ee(t,e,o,i,n),showLegend:i.showLegend??!!e}}},ie={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=jt(i.annotations,n.regression);return{chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:o,...i,...r&&{annotations:r},pointStyle:i.pointStyle||ne(t,e,o,i,n),showLegend:i.showLegend??!!e}}};function ne(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Ot(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrBubbleColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?lt(l,c,a):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[5,40],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Nt(f):void 0,y=pt(n.xAccessor,n.yAccessor),g=n.styleRules;return t=>{const o={fill:e&&u?at(t,e,u):"string"==typeof n.color?n.color:ot,fillOpacity:"number"==typeof n.bubbleOpacity?n.bubbleOpacity:.6,r:d?ut(t,d,h,p):h[0],stroke:n.bubbleStrokeColor??"white",strokeWidth:n.bubbleStrokeWidth??1};return g?.length&&Object.assign(o,xt(t,g,y(t))),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}function re(...t){let e;for(const o of t)o&&(e=se(e)&&se(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function se(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function ae(t){return"object"==typeof t&&null!==t&&"gradient"in t}require("react");var ce=36,le=34,ue=58,de=22;function he(t){return"string"==typeof t&&t.length>0}function fe(t,e,o=!1){const i=o?e?ue:le:e?ce:0;return i>t.top?{...t,top:i}:t}function pe(t,e){return fe(t,he(e))}var ye=16,ge=6,me=10,xe=22,be=100,ve=10,we=3;function ke(t,e,o,i,n=8){const r=i,s="left"===i?"right":"right"===i?"left":"top"===i?"bottom":"top",a=Math.max(e[r],Math.max(0,("left"===i||"right"===i?o[0]:o[1])-n)-t[s]);t[r]>a&&(t[r]=a)}var Se=12,Ae=18,Me=46,_e=26;function Pe(t){return Math.ceil(7*t.length)}function je(t,e){if(se(t)){const o=We(e),i=t.legendGroups.flatMap(t=>[t.label?Pe(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+Pe(t.label))]);return Math.max(be,...i)}if(ae(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),i=Math.max(Pe(o(e.domain[0])),Pe(o(e.domain[1]))),n=e.label?Pe(e.label):0;return Math.max(be,19+i,n)}return be}function Le(t){return(se(t)||ae(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):ve}function $e(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?ze:Oe:0}function Re(t){return Math.max(0,t?.edgeGutter??we)}var Ce=22,Ie=46,Te=64,Oe=34,ze=70;function Fe(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?Te:Ie:Ce:0}function Ne(t,e,o){if(ae(t))return t.gradient.label?Me:_e;if(!se(t))return 20;const i=We(o),n=Math.max(1,o?.maxWidth??e);let r=i.rowHeight;for(const e of t.legendGroups){let t=0,o=0;for(const r of e.items){const e=i.swatchSize+i.labelGap+Pe(r.label),s=0===o?e:o+i.itemGap+e;o>0&&s>n?(t+=1,o=e):o=s}e.items.length>0&&(t+=1),r=Math.max(r,t*i.rowHeight,e.label?Pe(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function Ee(t,e,o){return je(t,e)+Le(t)+$e(e,o)+Re(e)}function De(t,e){const{legend:o}=e;if(!o)return;const i=e.position??"right",n=Ne(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+Le(o)+Fe("bottom"===i?e.axisChrome:"top"===i?e.axisChrome?.topAxis:void 0,e.legendLayout)+("top"===i&&e.hasTitle?24:0),r=Math.max(e.minimumMargin??0,"top"===i?e.hasTitle?ue:le:0);"right"===i?t.right=Math.max(t.right,r,Ee(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===i?t.left=Math.max(t.left,r,Ee(o,e.legendLayout,e.axisChrome?.leftAxis)):"top"===i?t.top=Math.max(t.top,r,n):t.bottom=Math.max(t.bottom,r,n)}function Be(t,e){const o=e.position??"right",i="top"===o||"bottom"===o,n=Math.max(0,e.totalWidth-e.margin.left-e.margin.right),r=Math.max(1,i?e.legendLayout?.maxWidth??n:e.reservedWidth??je(t,e.legendLayout)),s=Le(t),a=$e(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),c=Re(e.legendLayout),l=Ne(t,n,e.legendLayout),u=Fe(e.axisChrome,e.legendLayout),d=Fe(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(c,e.margin.left-a-r-s),y:e.margin.top,width:r,height:l};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-l,width:r,height:l};if("bottom"===o){const t=e.totalHeight-e.margin.bottom;return{x:e.margin.left,y:Math.max(t+s,Math.min(t+u+s,e.totalHeight-l)),width:r,height:l}}return{x:Math.min(e.totalWidth-r-c,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:l}}function We(t){const e=Math.max(1,t?.swatchSize??ye),o=Math.max(e,t?.rowHeight??xe);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??ge),itemGap:Math.max(0,t?.itemGap??me),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function Ye(t,e){let o=24;return t.map(({hasLabel:t,itemCount:i})=>{o+=5;const n=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=i*e+8,{lineY:n,labelY:r,itemsY:s,endY:o}})}function qe(t,e,o,i,n){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=ct(o,i);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=tt[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=i?(n.has(i)||n.set(i,n.size),r[n.get(i)%r.length]):r[0]:ot}function Xe(t,e,o){return"function"==typeof t?t(e,o):e[t]}function Ge(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[g(t),e]));return t.map(t=>{const e={...t},i=i=>{if(!(i in t))return;const n=o.get(g(t[i]));void 0!==n&&(e[i]=n)};return i("x"),i("x0"),i("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||i("value"),e})}var Ve,He=c(require("react")),Ue=(require("react/jsx-runtime"),{isActive:!1,predicate:()=>!0});function Ke(t,e,o,i,n){const r=1-n;return r*r*r*t+3*r*r*n*e+3*r*n*n*o+n*n*n*i}function Ze(t,e,o,i,n){const r=1-n;return 3*r*r*(e-t)+6*r*n*(o-e)+3*n*n*(i-o)}function Qe(t,e,o,i,n){const r=[],s=(t.x+e.x)/2;for(let a=0;n>=a;a++){const c=a/n;let l,u,d,h;"linear"===i?(l=t.x+(e.x-t.x)*c,u=t.y+(e.y-t.y)*c,d=e.x-t.x,h=e.y-t.y):(l=Ke(t.x,s,s,e.x,c),u=Ke(t.y,t.y,e.y,e.y,c),d=Ze(t.x,s,s,e.x,c),h=Ze(t.y,t.y,e.y,e.y,c)),r.push({x:l,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*c,datumIndex:.5>c?o:o+1})}return r}function Je(t,e={}){const o=[],i=[],n=[];if(2>t.length)return{topPath:o,bottomPath:i,datumIndices:n};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=Qe(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,c=e.dx/r,l=Math.max(0,e.radius);o.push([e.x+s*l,e.y+c*l]),i.push([e.x-s*l,e.y-c*l]),n.push(e.datumIndex)}}return{topPath:o,bottomPath:i,datumIndices:n}}var to=require("react/jsx-runtime");function eo({datum:t,x:e,y:o,side:i,color:n,highlighted:r,labelStyle:s}){const a=function(){const t=(Ve??(Ve=He.createContext(null)),Ve);return He.useContext(t)??Ue}(),c=a.isActive&&!a.predicate(t),l="function"==typeof s?s(t.__bumpRaw):s;return(0,to.jsx)("text",{className:"semiotic-bump-label",x:e+("end"===i?8:-8),y:o,dy:"0.35em",textAnchor:"end"===i?"start":"end",fill:n,fillOpacity:c?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...l},children:t.__bumpSeries})}function oo(t,e,o){const[i,n]=e,[r,s]=o;return n===i?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-i)/(n-i)))}function io(t){const e=t.__bumpXValue instanceof Date?t.__bumpXValue.getTime():Number(t.__bumpXValue);return{value:t.__bumpValue,x:Number.isFinite(e)?e:void 0,y:t.__bumpValue,category:t.__bumpSeries}}function no(t){const e=t.config,o=new Map;for(const e of t.data){const t=o.get(e.__bumpSeries)??[];t.push(e),o.set(e.__bumpSeries,t)}const i=e.seriesOrder.filter(t=>o.has(t)).sort((t,i)=>(o.get(t)?.[0]?.__bumpHighlighted?1:0)-(o.get(i)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(i)),n=[],r=[],s=[];for(const r of i){const i=(o.get(r)??[]).sort((t,e)=>t.x-e.x);if(2>i.length)continue;const a=i[0].__bumpHighlighted,c=(e.colorMap&&ct(e.colorMap,r))??t.resolveColor(i[0].__bumpSeries,i[0]),l=e.color??(a?c:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??c),u=i.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?oo(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=Je(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:l,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(h,xt(i[0].__bumpRaw,e.styleRules,io(i[0]))),e.areaStyle&&Object.assign(h,e.areaStyle(i[0].__bumpRaw)??{}),void 0!==e.stroke&&(h.stroke=e.stroke),void 0!==e.strokeWidth&&(h.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(h.opacity=e.opacity),n.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(t=>i[t]),accessibleDatum:i.map(t=>t.__bumpRaw),accessibility:{label:r+" ranking trajectory",tableFields:i.map(t=>t.__bumpRaw)},group:r,interactive:!0}),e.showPoints&&i.forEach((t,o)=>{const i={fill:l,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(i,xt(t.__bumpRaw,e.styleRules,io(t))),e.pointStyle&&Object.assign(i,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(i.stroke=e.stroke),void 0!==e.strokeWidth&&(i.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(i.opacity=e.opacity),n.push({type:"point",x:u[o].x,y:u[o].y,r:i.r??e.pointRadius,style:i,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${r}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${r}:${t.x}`})});const f=!0===e.showLabels?"end":e.showLabels,p=(t,o,i)=>{const n=null==e.labelPriorityAccessor?void 0:"function"==typeof e.labelPriorityAccessor?e.labelPriorityAccessor(t.__bumpRaw):Number(t.__bumpRaw[e.labelPriorityAccessor]);s.push({id:`${r}\0${i}`,datum:t,x:u[o].x,y:u[o].y,side:i,rank:t.__bumpRank,highlighted:a,priority:Number.isFinite(n)?n:void 0,color:"string"==typeof h.fill?h.fill:l})};"start"!==f&&"both"!==f||p(i[0],0,"start"),"end"!==f&&"both"!==f&&"auto"!==f||p(i.at(-1),i.length-1,"end")}const a=function(t,e,o,i){const n=Math.max(1,Math.floor(e/18)),r="auto"===o?Number.isFinite(i)&&(i??0)>=0?Math.min(n,Math.floor(i)):n:1/0,s=t.map((t,e)=>({candidate:t,index:e})).sort((t,e)=>(e.candidate.priority??0)-(t.candidate.priority??0)||Number(e.candidate.highlighted)-Number(t.candidate.highlighted)||t.candidate.rank-e.candidate.rank||t.index-e.index),a=[];for(const{candidate:t}of s){if(a.length>=r)break;a.some(e=>e.side===t.side&&14>Math.abs(e.y-t.y))||a.push(t)}return new Set(a.map(t=>t.id))}(s,t.dimensions.plot.height,"auto"!==(!0===e.showLabels?"end":e.showLabels)||"auto",e.maxLabels);for(const t of s)a.has(t.id)&&r.push((0,to.jsx)(eo,{datum:t.datum,x:t.x,y:t.y,side:t.side,color:t.color,highlighted:t.highlighted,labelStyle:e.labelStyle},t.id));return{nodes:n,overlays:r.length?(0,to.jsx)("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const o=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&o&&!e.predicate(o))return{opacity:.14}}}}var ro={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,i,n)=>{const r=function(t,e={}){const o=e.xAccessor??"x",i=e.yAccessor??"y",n=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,c=new Map,l=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=Xe(o,t,e),f=g(r);let p=a.get(f);null==p&&(p=s.length,a.set(f,p),s.push(r),c.set(p,[]));const y=Xe(n,t,e)+"";u.has(y)||(u.set(y,l.length),l.push(y));const m=Number(Xe(i,t,e));Number.isFinite(m)&&(d=Math.min(d,m),h=Math.max(h,m),c.get(p)?.push({datum:t,inputIndex:e,series:y,value:m}))});const f=[],p=new Map,y=new Map;for(let t=0;s.length>t;t++){const e=c.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const i=o+1;f.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:i}),p.set(e.series,(p.get(e.series)??0)+i),y.set(e.series,(y.get(e.series)??0)+1)})}const m=l.length+1,x=[...l].sort((t,e)=>{const o=y.get(t)??0,i=y.get(e)??0;return((p.get(t)??0)+(s.length-o)*m)/Math.max(1,s.length)-((p.get(e)??0)+(s.length-i)*m)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),b=new Set(x.slice(0,null==e.highlightTop?x.length:Math.max(0,Math.floor(e.highlightTop))));return{data:f.map(t=>{const e=b.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:s,seriesOrder:l,overallOrder:x,valueExtent:d===1/0?[0,0]:[d,h]}}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:n.xAccessor,yAccessor:n.yAccessor,lineBy:n.lineBy,rankDirection:n.rankDirection,highlightTop:"number"==typeof n.highlightTop?n.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=Ot(i.theme),c=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:i,color:n,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:c}=t;if(null==i&&null==n)return r;const l=new Set(o.slice(0,null==i?o.length:Math.max(0,Math.floor(i)))),u=new Map,d={};for(const t of e)Object.defineProperty(d,t,{configurable:!0,enumerable:!0,writable:!0,value:n??(l.has(t)?qe(void 0,a,r,t,u):s??c??"#b8bec8")});return d}({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof n.highlightTop?n.highlightTop:void 0,color:"string"==typeof n.color?n.color:void 0,colorScheme:o,neutralColor:"string"==typeof n.neutralColor?n.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),l={ribbon:!0===n.ribbon,curve:"linear"===n.curve?"linear":"smooth",samplesPerSegment:"number"==typeof n.samplesPerSegment?n.samplesPerSegment:12,ribbonSizeRange:Array.isArray(n.ribbonSizeRange)?n.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof n.lineWidth?n.lineWidth:3,ribbonOpacity:"number"==typeof n.ribbonOpacity?n.ribbonOpacity:.82,lineOpacity:"number"==typeof n.lineOpacity?n.lineOpacity:.9,neutralColor:"string"==typeof n.neutralColor?n.neutralColor:void 0,color:"string"==typeof n.color?n.color:void 0,colorMap:c&&"object"==typeof c&&!Array.isArray(c)?c:void 0,stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0,styleRules:n.styleRules,areaStyle:i.areaStyle,pointStyle:i.pointStyle,labelStyle:n.labelStyle,showPoints:!0===n.showPoints,pointRadius:"number"==typeof n.pointRadius?n.pointRadius:3,showLabels:n.showLabels??!0,labelPriorityAccessor:n.labelPriorityAccessor,maxLabels:"number"==typeof n.maxLabels?n.maxLabels:void 0},u=i.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),f=Array.from({length:s},(t,e)=>e+1),p=i.axes??[{orient:"left",tickValues:f,tickFormat:t=>t+"",label:i.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:i.xLabel,tickAnchor:"edges"}];return{...i,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:no,layoutConfig:l,colorAccessor:"__bumpSeries",colorScheme:c,xFormat:d,axes:p,axisExtent:"exact",showAxes:i.showAxes??!0,showLegend:i.showLegend??!1,annotations:Ge(i.annotations,r.xValues)}}};function so(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Ot(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrAreaColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?lt(l,c,a):void 0,d=!1!==n.showLine,h="number"==typeof n.lineWidth?n.lineWidth:2,f="number"==typeof n.areaOpacity?n.areaOpacity:.7,p=ft(n.yAccessor),y=n.styleRules;return(t,o)=>{const i=e&&u?at(t,e,u):"string"==typeof n.color?n.color:ot,r={fill:i,fillOpacity:f,stroke:d?i:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(r,xt(t,y,{value:p(t),category:o})),void 0!==n.stroke&&(r.stroke=n.stroke),void 0!==n.strokeWidth&&(r.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(r.opacity=n.opacity),r}}function ao(t,e,o,i,n){if(!n.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Ot(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrPointColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?lt(l,c,a):void 0,d="number"==typeof n.pointRadius?n.pointRadius:3;return t=>{const o=e&&u?at(t,e,u):"string"==typeof n.color?n.color:ot;return{r:d,fill:o,stroke:"none"}}}var co={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.lineBy,s=n.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",c=Ot(i.theme).colors.categorical,l=function(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Ot(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrLineColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?lt(l,c,a):void 0,d=pt(n.xAccessor,n.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:i,color:n,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?i&&(f=at(t,o,i)):f=n||ot,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),c?.length&&Object.assign(d,xt(t,c,l?l(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof n.color?n.color:void 0,fillArea:n.fillArea,areaOpacity:"number"==typeof n.areaOpacity?n.areaOpacity:.3,styleRules:n.styleRules,ruleContext:d});return ht(h,{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0})}(t,r,o,i,n),u=te({data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof n.color?n.color:void 0,forecast:n.forecast,anomaly:n.anomaly,gapStrategy:n.gapStrategy,directLabel:n.directLabel,annotations:i.annotations,themeCategorical:c,baseLineStyle:l}),d=i.pointStyle||ao(u.data,u.colorAccessor,o,i,n);let h=i.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=(!n.directLabel||void 0!==i.showLegend)&&(i.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!=n.areaOpacity&&{areaOpacity:n.areaOpacity},...null!=n.band&&{band:n.band},...i,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!i.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},lo={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=Array.isArray(t)?P(t):[],s=n.timeAccessor||"time",a=n.valueAccessor||"value",c=n.categoryAccessor,l=n.valueExtent||i.yExtent,u="down"===n.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:i,valueExtent:n,extentPadding:r}){if(n)return[n[1],n[0]];if(!t||0===t.length)return;const s=new Map;for(const n of t){const t=Ft(n,o,"time"),r=Ft(n,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/i)*i;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(n.binSize),valueExtent:l,extentPadding:n.extentPadding}):l,d={...void 0!==n.fill&&{fill:n.fill},...void 0!==n.stroke&&{stroke:n.stroke},...void 0!==n.strokeWidth&&{strokeWidth:n.strokeWidth},...void 0!==n.opacity&&{opacity:n.opacity},...void 0!==n.cursor&&{cursor:n.cursor},...void 0!==n.gap&&{gap:n.gap}};return{chartType:"bar",data:r,...i,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:n.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:n.timeExtent||i.xExtent,yExtent:u,extentPadding:n.extentPadding??i.extentPadding,binSize:n.binSize,categoryAccessor:c,barColors:n.colors||i.barColors,colorScheme:n.colors||i.colorScheme,barStyle:i.barStyle||d,showLegend:i.showLegend??!!c}}},uo={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.areaBy,s=te({data:Array.isArray(t)?P(t):[],xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.areaBy,forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:Ot(i.theme).colors.categorical}),a=function({data:t,safeData:e,areaBy:o,lineDataAccessor:i}){if(null==t)return[];const n=void 0!==e[0]?.[i];if(!n&&!o)return e;let r;if(n)r=e;else{const t=e.reduce((t,e)=>{const n="function"==typeof o?o(e):e[o],r=n+"";if(!t[r]){const e={[i]:[]};"string"==typeof o&&(e[o]=n),t[r]=e}return t[r][i].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[i])?t[i]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}({data:t,safeData:s.data,areaBy:n.areaBy,lineDataAccessor:n.lineDataAccessor||"coordinates"}),c=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(n.semanticGradient),l=c?.stops.length?{stops:c.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:kt(i.gradientFill),u=!1!==n.semanticLine?function(t){const e=t?.stops.filter(t=>"string"==typeof t.color&&Number.isFinite(t.offset)).map(({offset:t,color:e,opacity:o})=>({offset:Math.max(0,Math.min(1,t)),color:e,...Number.isFinite(o)&&{opacity:Math.max(0,Math.min(1,o))}})).sort((t,e)=>t.offset-e.offset);if(!e?.length)return;const o=e[0];return o.offset>0?[{...o,offset:0},...e]:e}(c):void 0,d=i.pointStyle||ao(a,r,o,i,n);return{chartType:"area",data:a,xAccessor:s.xAccessor,yAccessor:s.yAccessor,y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||void 0,colorAccessor:r,colorScheme:o,...i,...s.annotations.length>0&&{annotations:s.annotations},...s.yExtent&&!i.yExtent&&{yExtent:s.yExtent},...void 0!==l&&{gradientFill:l},...u&&{semanticLineStops:u},lineStyle:i.lineStyle||so(a,r,o,i,n),...d&&{pointStyle:d}}}},ho={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.xAccessor||"x",s=n.seriesAAccessor||"a",a=n.seriesBAccessor||"b",c=t=>Mt(At(r,"x",t)),l=t=>Mt(At(s,"a",t)),u=t=>Mt(At(a,"b",t)),d=n.seriesAColor||"var(--semiotic-danger, #dc2626)",h=n.seriesBColor||"var(--semiotic-info, #2563eb)",f=n.areaOpacity??.6,p=n.lineWidth??1.5,y=!1!==n.showLines,g=!1!==i.showLegend,m=n.seriesALabel||"A",x=n.seriesBLabel||"B",b=i.legendPosition||"right",v=function(t,e,o,i){if(!t.length)return[];const n=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;n.length>t;t++){const r=n[t],p=e(r),y=o(r),g=i(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 i=Math.max(0,Math.min(1,(c.b-c.a)/o));t=c.x+i*(p-c.x),e=c.a+i*(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),i=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(i)&&w.push({__x:e,__y:i,__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:n.curve||"linear",...i,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},fo={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.areaBy,s="string"==typeof r&&Array.isArray(t)?lt(t,r,o):void 0,a="number"==typeof n.areaOpacity?n.areaOpacity:.7,c=i.lineStyle||(t=>{const e=null==r?void 0:at(t,r,s),o=n.showLine??!0,i={fill:n.color??e,stroke:o?n.stroke??e:"none",...o?{strokeWidth:n.strokeWidth??n.lineWidth??2}:{},fillOpacity:a,...null==n.opacity?{}:{opacity:n.opacity}},c=n.styleRules;if(c?.length){const e=ft(n.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(i,xt(t,c,{value:e(t),category:o}))}return i}),l=n.normalize?"zero":n.baseline??"zero",u=i.pointStyle||ao(t,r,o,i,n);return{chartType:"stackedarea",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:r,colorScheme:o,normalize:n.normalize,baseline:l,stackOrder:n.stackOrder,lineStyle:c,...i,...u&&{pointStyle:u},curve:i.curve??n.curve??"monotoneX",showLegend:i.showLegend??!!r}}},po={frameType:"xy",buildProps:(t,e,o,i,n)=>{const[r]=i.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...i,scalePadding:i.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:i.extentPadding??(r>200?.1:.02)}}},yo={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.xCenter,s=n.yCenter,a=n.quadrants,c=n.centerlineStyle||{},l=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,d=c.stroke||"#999",h=c.strokeWidth??1,f=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,p=M.createElement,y=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const i=o.width,n=o.height,c=null!=r?e.x(r):i/2,y=null!=s?e.y(s):n/2;if(null!=r&&!Number.isFinite(c))return null;if(null!=s&&!Number.isFinite(y))return null;const g=Math.max(0,Math.min(i,c)),m=Math.max(0,Math.min(n,y)),x=[{c:a.topLeft,x:0,y:0,w:g,h:m},{c:a.topRight,x:g,y:0,w:i-g,h:m},{c:a.bottomLeft,x:0,y:m,w:g,h:n-m},{c:a.bottomRight,x:g,y:m,w:i-g,h:n-m}],b=l?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:i-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:n-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:i-8,y:n-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(M.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?p("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),p("line",{key:"vc",x1:g,y1:0,x2:g,y2:n,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:i,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...b)}]:void 0;return{chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[3,15],colorScheme:o,pointStyle:i.pointStyle||n.pointStyle||ee(t,e,o,i,n),...i,showLegend:i.showLegend??!!e,...y&&{svgPreRenderers:y}}}},go={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",i=e.yAccessor||"y",n=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:Mt(At(e.orderAccessor,"order",t))-Mt(At(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=Mt(At(o,"x",t)),n=Mt(At(i,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&s++}let a=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=Mt(At(o,"x",t)),n=Mt(At(i,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&r.set(t,{idx:a++,total:s})}return{data:n,orderMap:r}}(t,n),s=te({data:r.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:Ot(i.theme).colors.categorical}),a=jt(s.annotations,n.regression),c=n.pointRadius??4,l=pt(n.xAccessor,n.yAccessor),u=n.styleRules,d=[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 i=e[t],n=e[t+1],r=_t(t,e.length);100>e.length&&o.push(M.createElement("line",{key:"halo-"+t,x1:i.x,y1:i.y,x2:n.x,y2:n.y,stroke:"white",strokeWidth:c+2,strokeLinecap:"round",opacity:.5})),o.push(M.createElement("line",{key:"segment-"+t,x1:i.x,y1:i.y,x2:n.x,y2:n.y,stroke:r,strokeWidth:c,strokeLinecap:"round"}))}return M.createElement(M.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:ht(t=>{const e=r.orderMap.get(t),o=e?.idx??0,i=e?.total??1,n={fill:i>0?_t(o,i):"#6366f1",stroke:"white",strokeWidth:1,r:c,fillOpacity:1};return u?.length&&Object.assign(n,xt(t,u,l(t))),n},Pt(n)),...i,...a&&a.length>0&&{annotations:a},...s.yExtent&&!i.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}},mo={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:void 0,s=Number.isFinite(n.cellBorderWidth)?Math.max(0,n.cellBorderWidth):1,a=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,c=null!=r&&Object.hasOwn(r,"heatmapColorScale"),l=r?.heatmapColorScale,u=c?"function"==typeof l?l:void 0:"custom"===a&&"function"==typeof n.customColorScale?n.customColorScale:void 0;return{chartType:"heatmap",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,showValues:n.showValues,heatmapValueFormat:n.valueFormat,areaStyle:()=>({stroke:n.cellBorderColor??"#fff",strokeWidth:s}),...i,...void 0!==a&&{colorScheme:a},...u&&{heatmapColorScale:u}}}};function xo(t){return Math.max(0,Math.min(1,t))}function bo(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 vo(t,e,o){const i=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(o)}`}function wo(t,e,o){const i=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:xo(t.offset),color:t.color??o,opacity:null==t.opacity?1:xo(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===i.length)return"#999999";const n=t=>{if(1===t.opacity)return t.color;const e=bo(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===i.length)return n(i[0]);const r=xo(e);if(i[0].offset>=r)return n(i[0]);if(r>=i[i.length-1].offset)return n(i[i.length-1]);for(let t=0;i.length-1>t;t++){const e=i[t],o=i[t+1];if(e.offset>r||r>o.offset)continue;const s=o.offset-e.offset,a=s>0?(r-e.offset)/s:0,c=bo(e.color),l=bo(o.color);if(!c||!l)return n(.5>a?e:o);const[u,d,h]=c,[f,p,y]=l,g=u+(f-u)*a,m=d+(p-d)*a,x=h+(y-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?vo(g,m,x):`rgba(${Math.round(g)},${Math.round(m)},${Math.round(x)},${b})`}return n(i[i.length-1])}function ko(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}var So=require("react/jsx-runtime");function Ao(t=240){const e=360-t,o=180+e/2,i=o*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:o,startAngleRad:i,offsetRad:-Math.PI/2+i}}require("react");var Mo={RdBu:V,PiYG:H,PRGn:U,BrBG:K,RdYlBu:Z,RdYlGn:Q,Spectral:J},_o="__likert_neutral_neg",Po="__likert_neutral_pos";function jo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}var Lo=c(require("react"));function $o(t){return kt(t)}function Ro(t,e,o,i,n){const r=Ot(i.theme).colors.categorical,s=o??i.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?lt(l,c,s??r):void 0,d=qe("string"==typeof n.color?n.color:void 0,r,s,void 0,new Map),h=ft(n.valueAccessor),f=n.styleRules,p=i.pieceStyle;return(t,o)=>{const i={fill:e&&u?at(t,e,u):d};return f?.length&&Object.assign(i,xt(t,f,{value:h(t),category:o})),"function"==typeof p?Object.assign(i,p(t,o)||{}):p&&"object"==typeof p&&Object.assign(i,p),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}function Co(t,e,o,i,n){const r=Ro(t,e,o,i,n);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 Io(t,e,o,i,n){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=Ot(i.theme).colors.categorical,l=o??i.colorScheme,u=e?lt(a,s,l??c):void 0,d=qe("string"==typeof n.color?n.color:void 0,c,l,void 0,new Map);return t=>{const o=e&&u?at(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:n.stroke??o,...void 0!==n.strokeWidth&&{strokeWidth:n.strokeWidth},...void 0!==n.opacity&&{opacity:n.opacity}}}}function To(t,e,o,i,n){const r=Ro(t,e,o,i,n),s="number"==typeof n.dotRadius?n.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function Oo(t,e,o,i,n){const r=Ro(t,e,o,i,n),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=n.sizeBy,c=Array.isArray(n.sizeRange)?n.sizeRange:[3,8],l=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=l.length?Nt(l):void 0,d="number"==typeof n.pointRadius?n.pointRadius:4,h="number"==typeof n.pointOpacity?n.pointOpacity:.7;return(t,e)=>({r:a?ut(t,a,c,u):d,fillOpacity:h,...r(t,e)})}var zo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=jt(i.annotations,n.regression);return{chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,colorAccessor:e,colorScheme:o,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,...r&&{annotations:r},gradientFill:$o(i.gradientFill),pieceStyle:Ro(t,e,o,i,n)}}},Fo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.stackBy;return{chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===n.orientation?"horizontal":"vertical",normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:$o(i.gradientFill),pieceStyle:Ro(t,r,o,i,n),showLegend:i.showLegend??!!r}}},No={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.groupBy;return{chartType:"clusterbar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:$o(i.gradientFill),pieceStyle:Ro(t,r,o,i,n),showLegend:i.showLegend??!!r}}},Eo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.categoryAccessor;return{chartType:"pie",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...i,pieceStyle:Ro(t,r,o,i,n),showLegend:i.showLegend??!!r}}},Do={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,i,n)=>{const r=e||n.categoryAccessor;return{chartType:"donut",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",margin:i.margin??{top:50,right:40,bottom:60,left:70},innerRadius:n.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...i,pieceStyle:Ro(t,r,o,i,n)}}},Bo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=n.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:n.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:n.bins??25,normalize:n.relative??!1,colorAccessor:e,colorScheme:o,barPadding:n.categoryPadding??20,...n.valueExtent?{rExtent:n.valueExtent}:c?{rExtent:c}:{},...i,summaryStyle:Co(t,e,o,i,n)}}},Wo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"boxplot",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=n.showOutliers&&{showOutliers:n.showOutliers},...null!=n.outlierRadius&&{outlierRadius:n.outlierRadius},...i,summaryStyle:i.summaryStyle||Co(t,e,o,i,n)})},Yo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"violin",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===n.orientation?"horizontal":"vertical",bins:n.bins??25,showIQR:n.showIQR??!0,barPadding:n.categoryPadding??20,colorScheme:o,...i,summaryStyle:i.summaryStyle||Io(t,e,o,i,n),showLegend:i.showLegend??!!e,...n.valueExtent&&{rExtent:n.valueExtent}})},qo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"swarm",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:o,...i,sizeRange:n.sizeRange||[3,8],pieceStyle:i.pieceStyle||Oo(t,e,o,i,n),showLegend:i.showLegend??!!e})},Xo={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,i,n)=>{const r=jt(i.annotations,n.regression);return{chartType:"point",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",oSort:n.sort??"auto",barPadding:n.categoryPadding??10,...i,...r&&{annotations:r},pieceStyle:To(t,e,o,i,n),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!e}}},Go={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:r,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",...null!=n.trackFill&&{trackFill:n.trackFill},...n.valueExtent&&{rExtent:n.valueExtent},...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:$o(i.gradientFill),pieceStyle:i.pieceStyle||Ro(t,r,o,i,n),showLegend:i.showLegend??!!r,barPadding:n.barPadding??40}}},Vo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"ridgeline",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",bins:n.bins??20,amplitude:n.amplitude??1.5,barPadding:n.categoryPadding??5,oSort:n.oSort??!1,...i,summaryStyle:i.summaryStyle||((r,s)=>({fillOpacity:.5,...Ro(t,e,o,i,n)(r,s)})),showLegend:i.showLegend??!!e})},Ho={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,i,n)=>{const r=Array.isArray(n.levels)&&n.levels.length>=2?n.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==n.orientation;let a=function(t,e,o,i,n,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(i){const t=i(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 n=e[o];l.set(n,(l.get(n)||0)+1)}else if(n&&r){const t=n(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 i=0;for(const t of e)i+=o.get(t)||0;if(0!==i)for(let n=0;e.length>n;n++){const r=e[n],s=o.get(r)||0;c.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/i*100,__likertLevelIndex:n})}}return c}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,jo(n.categoryAccessor,"question"),n.levelAccessor?null:jo(n.valueAccessor,"score"),n.levelAccessor?jo(n.levelAccessor,"level"):null,n.levelAccessor?jo(n.countAccessor,"count"):null);s&&(a=function(t,e){const o=e.length,i=o%2!=0,n=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===_o?r=o:o.__likertLevel===Po?a=o:e.set(o.__likertLevelIndex,o);i&&r&&s.push(r);for(let t=n-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}i&&a&&s.push(a);for(let t=i?n+1:n;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,i=o%2!=0,n=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(i&&t===n){const t=e.__likertPct/2;r.push({...e,__likertLevel:_o,__likertPct:-t}),r.push({...e,__likertLevel:Po,__likertPct:t})}else r.push(n>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const c=Ot(i.theme).colors.diverging,l=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(Mo,e)){const o=Mo[e];if(1===t)return[o(.5)];const i=[];for(let e=0;t>e;e++)i.push(o(e/(t-1)));return i}const o=["#da1e28","#ff8389","#ffb3b8"],i=["#a6c8ff","#4589ff","#0043ce"],n="#a8a8a8";if(1===t)return[n];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(n);for(let t=0;s>t;t++)a.push(i[Math.min(Math.floor(t*i.length/s),i.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 n.valueFormat?n.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",f=re(!1===i.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},i.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:n.barPadding,showGrid:i.showGrid,oLabel:n.categoryLabel,rLabel:n.valueLabel||(s?void 0:"Percentage"),rFormat:h,...n.categoryFormat&&{oFormat:n.categoryFormat},...n.valueExtent&&{rExtent:n.valueExtent},...i,pieceStyle:ht(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===_o||e===Po?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},Pt(n)),showLegend:i.showLegend??!0,legendPosition:i.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},Uo={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,i,n)=>{const r="vertical"===n.orientation,s=e||n.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:s,categoryAccessor:n.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!r&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:r?40:0,colorScheme:o,...i,showAxes:r&&!1!==i.showAxes,showGrid:r,pieceStyle:Ro(t,s,o,i,n),showLabels:n.showLabels??!0}}},Ko={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const i=(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,n=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return(0,So.jsxs)(So.Fragment,{children:[o.showNeedle&&(0,So.jsxs)(So.Fragment,{children:[(0,So.jsx)("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(i),y2:o.centerY+o.needleLength*Math.sin(i),stroke:n,strokeWidth:2.5,strokeLinecap:"round"}),(0,So.jsx)("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:n})]}),null!=o.contextValue&&(0,So.jsx)("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:n,children:o.contextValue}),r.map((t,i)=>{const n=(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=((n+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(0,So.jsxs)("g",{children:[(0,So.jsx)("line",{x1:o.centerX+Math.cos(n)*r,y1:o.centerY+Math.sin(n)*r,x2:o.centerX+Math.cos(n)*s,y2:o.centerY+Math.sin(n)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),(0,So.jsx)("text",{x:o.centerX+Math.cos(n)*a,y:o.centerY+Math.sin(n)*a,textAnchor:l,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+i)})]})},buildProps:(t,e,o,i,n)=>{const r=n.min??0,s=n.max??100,a=n.sweep??240,c=n.arcWidth??.3,l=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:d}=Ao(a),h=n.thresholds||[{value:s,color:n.color||"#4e79a7"}],f=St(i.gradientFill),p=function(t){const{min:e,max:o,value:i,thresholds:n,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,i))-e)/d;let f=n&&n.length>0?[...n].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.stops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?h:1,e=ko("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))),i=[];for(let e=0;o>e;e++)i.push(wo(l.stops,t*(e+.5)/o,r||f[0]?.color||"#007bff"));const n=ko("fill",0);y.push({category:n,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:i}}),g.set(n,{fill:i[0]||s})}}else{let t=e;for(let o=0;f.length>o;o++){const i=f[o],n=(i.value-t)/d,r=(t-e)/d,c=(i.value-e)/d,l=Math.max(0,(a?Math.min(h,c):c)-r),u=a?Math.max(0,n-l):0;if(l>0){const t=ko("fill",o);y.push({category:t,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),g.set(t,{fill:i.color})}if(u>0){const t=ko("bg",o);y.push({category:t,value:u,_zone:i.label||"Zone "+(o+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=i.value}}if(c&&n&&n.length>0)for(const t of n)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:n.value,thresholds:h,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==n.showScaleLabels,gradientFill:f}),[y,g]=i.size||[300,250],m=function(t=240){const{sweepRad:e,offsetRad:o}=Ao(t),i=[[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||i.push([Math.cos(t),Math.sin(t)]);const n=i.map(t=>t[0]),r=i.map(t=>t[1]),[s,a]=Nt(n),[c,l]=Nt(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),x=Math.min(10,Math.max(1,Math.min(y,g)/12)),b=Math.max(4,Math.min((y-2*x)/m.width,(g-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-c))),w=y/2-m.cx*b,k=g/2-m.cy*b,S=2*(b+4),A=Math.max(r,Math.min(s,n.value??r)),M="function"==typeof n.valueFormat?n.valueFormat(A):Math.round(A)+"",_=n.centerContent??i.centerContent,P=null!=_?"function"==typeof _?_(A,r,s):_:"sparkline"===n.mode||"context"===n.mode?void 0:Lo.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Lo.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==n.showScaleLabels&&Lo.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:ht(p.pieceStyle,Pt(n)),...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...i,size:[y,g],margin:{top:k-S/2,bottom:g-k-S/2,left:w-S/2,right:y-w-S/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(i.annotations)?i.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:c,value:A,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==n.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:l,needleColor:n.needleColor,..."context"===n.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}},Zo=require("d3-scale"),Qo={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function Jo(t="static"){return Qo[t]??Qo.static}var ti=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function ei(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:ti.has(t.kind)?"fatal":"warn"}function oi(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function ii(t){const{desired:e,minGaps:o,weights:i}=t,n=e.length;if(0===n)return[];if(o.length!==Math.max(0,n-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const r=Array(n).fill(0);for(let t=1;n>t;t++)r[t]=r[t-1]+Math.max(0,Number.isFinite(o[t-1])?o[t-1]:0);const s=[];for(let t=0;n>t;t++){const o=Math.max(Number.EPSILON,Number.isFinite(i?.[t])?i[t]:1),n=(Number.isFinite(e[t])?e[t]:0)-r[t];for(s.push({start:t,end:t,weight:o,mean:n});s.length>1;){const t=s[s.length-1],e=s[s.length-2];if(t.mean>=e.mean)break;const o=e.weight+t.weight;s.splice(s.length-2,2,{start:e.start,end:t.end,weight:o,mean:(e.mean*e.weight+t.mean*t.weight)/o})}}const a=Number.isFinite(t.min)?t.min:-1/0,c=Number.isFinite(t.max)?t.max-r[n-1]:1/0,l=a>c?a:c,u=Array(n);for(const t of s){const e=Math.max(a,Math.min(l,t.mean));for(let o=t.start;t.end>=o;o++)u[o]=e+r[o]}return u}function ni(t,e){let o=0,i=t.length-1,n=-1;for(;i>=o;){const r=o+i>>>1;t[r].at>e?i=r-1:(n=r,o=r+1)}return 0>n?{at:e,before:0,after:0}:t[n]}function ri(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const o=[],i=[0];for(let n=0;t.length-1>n;n++){const r=t[n],s=t[n+1],a=[...new Set([...r.map(t=>t.at),...s.map(t=>t.at)])].sort((t,e)=>t-e);let c=0;for(const t of a){const e=ni(r,t),o=ni(s,t);c=Math.max(c,e.after+o.before)}o.push(c),i.push(i[i.length-1]+c+e)}return{adjacentClearance:o,positions:i}}function si(t,e,o,i={}){let n=[...t];if(1>=n.length)return n;let r=[...n],s=o(n),a=1;const c=Math.max(0,i.passes??6),l=Math.max(1,i.maxEvaluations??1/0);for(let t=0;c>t&&l>a;t++){const t=new Map(n.map((t,e)=>[t,e])),c=new Map,l=new Map;for(const o of e){const e=t.get(o.source),i=t.get(o.target);if(null==e||null==i)continue;const n=Number.isFinite(o.weight)&&o.weight>0?o.weight:1;c.set(o.source,(c.get(o.source)??0)+i*n),l.set(o.source,(l.get(o.source)??0)+n),c.set(o.target,(c.get(o.target)??0)+e*n),l.set(o.target,(l.get(o.target)??0)+n)}n=n.map((t,e)=>({item:t,index:e,barycenter:(c.get(t)??e)/(l.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(i.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=o(n);if(a++,s>u)s=u,r=[...n];else if(u===s)break}return r}function ai(t,e,o={}){const i=[...t],n=i.length;if(1>=n||n>(o.maxItems??8))return i;const r=Math.max(1,o.maxEvaluations??1/0);let s=0,a=[...i],c=1/0;const l=()=>{if(s>=r)return;const t=e(i);s++,c>t&&(c=t,a=[...i])};l();const u=Array(n).fill(0);let d=0;for(;n>d&&r>s;)if(d>u[d]){const t=d%2==0?0:u[d];[i[t],i[d]]=[i[d],i[t]],l(),u[d]++,d=0}else u[d]=0,d++;return a}function ci(){return Object.create(null)}function li(t,e){return e>t?-1:t>e?1:0}function ui(t){return t.occupants.map(t=>t.id).sort(li).join("\0")}function di(t,e,o=0){return t.slice(0,-1).map((i,n)=>null!=i.group&&i.group===t[n+1].group?o:e)}function hi(t,e){return t.map(t=>{const o=new Map;for(const i of t.occupants){const t=e[i.id];if(t)for(const e of t.samples){const t=o.get(e.t)??{before:0,after:0},i=e.boundaryOffset??0;o.set(e.t,{before:Math.max(t.before,e.topMass-i),after:Math.max(t.after,e.botMass+i)})}}return[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function fi(t,e,o){if(0===t.length)return[];const{padding:i,plotH:n,valueScale:r}=o,s=o.stackValueScale??r,a=di(t,i,o.groupPadding??0),c=[i+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)c.push(c[o-1]+e[o-1]*s+a[o-1]);const l=c[c.length-1]+t[t.length-1].peak.botPeak*s+i;if(l>n&&l>0){const t=n/l;for(let e=0;c.length>e;e++)c[e]*=t}return c}function pi(t,e){const o=(t.boundaryOffset??0)*e,i=t.value*e;if("out"===t.kind){const n=t.sideMassBefore*e;return o+("top"===t.side?i/2-n:n-i/2)}const n=t.sideMassAfter*e;return o+("top"===t.side?i/2-n:n-i/2)}function yi(t,e,o,i,n,r){const s=r.adjacentClearance?[...r.adjacentClearance]:ri(hi(i,o)).adjacentClearance,a=fi(i,s,r);let c="hug"===r.lanePlacement?function(t,e,o,i,n,r,s){const a=t.length;if(0===a)return[];const{padding:c,plotH:l,valueScale:u}=s,d=di(t,c,s.groupPadding??0),h=n.map((t,e)=>t*u+d[e]),f=c+t[0].peak.topPeak*u,p=l-c-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=p-f)return fi(t,n,s);let y=1===a?[(f+p)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),n=Array(a).fill(0);for(const r of o){const o=e[r.source],s=e[r.target];if(null==o||null==s||o===s)continue;const a=i[r.source]?.localAttachments.get(r.id),c=i[r.target]?.localAttachments.get(r.id);if(!a||!c)continue;const l=r.value>0&&Number.isFinite(r.value)?r.value:1,d=pi(a,u),h=pi(c,u);t[o]+=(y[s]+h-d)*l,n[o]+=l,t[s]+=(y[o]+d-h)*l,n[s]+=l}const r=ii({desired:y.map((e,o)=>0===n[o]?e:.45*e+t[o]/n[o]*.55),minGaps:h,weights:n.map(t=>Math.max(1,t)),min:f,max:p});let s=0;for(let t=0;a>t;t++)s=Math.max(s,Math.abs(r[t]-y[t]));if(y=r,.01>s)break}return y}(i,n,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=ci();for(const i of t)o[i.id]=e[n[i.id]];return o};gi(o(c),e)>gi(o(a),e)+1e-6&&(c=[...a])}const l=ci();for(const e of t)l[e.id]=c[n[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=l[e.id],i=o[e.id];Number.isFinite(t)&&i&&(u=Math.min(u,t-i.topPeak*r.valueScale),d=Math.max(d,t+i.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:l,slotCenter:c,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function gi(t,e){let o=0;for(const i of e){const e=t[i.source],n=t[i.target];Number.isFinite(e)&&Number.isFinite(n)&&(o+=Math.abs(e-n)*(i.value>0?i.value:1))}return o}function mi(t,e){const o=t?.samples;if(!o||0===o.length||o[0].t>e)return{top:0,bot:0};let i=0,n=o.length-1,r=0;for(;n>=i;){const t=i+n>>>1;o[t].t>e?n=t-1:(r=t,i=t+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function xi(t,e,o,i,n){const r=1-n;return r*r*r*t+3*r*r*n*e+3*r*n*n*o+n*n*n*i}function bi(t,e){let o=0,i=1;for(let n=0;28>n;n++){const n=(o+i)/2;t>xi(0,e,e,1,n)?o=n:i=n}return(o+i)/2}function vi(t,e,o){const i=e+pi(t,o),n=t.value*o/2;return[i-n,i+n]}function wi(t,e,o,i){return Math.max(0,Math.min(e,i)-Math.max(t,o))/Math.max(1e-9,e-t)}function ki(t,e,o,i,n,r,s){const{valueScale:a,domain:c,mode:l="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=i[s.source],h=i[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const f=e[s.source]?.localAttachments.get(s.id),p=e[s.target]?.localAttachments.get(s.id);if(!f||!p)continue;const y=Math.max(s.startTime,c?.[0]??-1/0),g=Math.min(s.endTime,c?.[1]??1/0);if(y>=g)continue;const[m,x]=vi(f,n[s.source],a),[b,v]=vi(p,n[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const i=o[t];if(!i)continue;const c=[y,g];if("quality"===l)for(const t of i.occupants)for(const o of e[t.id]?.samples??[])o.t>y&&g>o.t&&c.push(o.t);const h=t=>{const o=bi((t-y)/(g-y),u),c=xi(m,m,b,b,o),l=xi(x,x,v,v,o);let d=0;for(const o of i.occupants){if(o.id===s.source||o.id===s.target)continue;const i=r[o.id];if(null!=i?.start&&i.start>t)continue;if(null!=i?.end&&t>i.end)continue;const u=mi(e[o.id],t),h=n[o.id];d=Math.max(d,wi(c,l,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(c)].sort((t,e)=>t-e);let p=0;for(let t=0;f.length-1>t;t++){const e=f[t],o=f[t+1]-e;p+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=p/(g-y)*(s.value>0?s.value:1)}}return d}function Si(t,e,o,i,n,r,s,a,c,l,u="both",d){return{crossings:t,weightedLength:e,pixelLength:gi(s,o),transitOcclusion:ki(o,i,n,r,s,a,{valueScale:c,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:l}}function Ai(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function Mi(t,e){return t.map(t=>({t:Ai(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function _i(t,e,o){const i=e+(t.boundaryOffset??0)*o,n=t.value*o;if("out"===t.kind){const e=t.sideMassBefore*o;if("top"===t.side){const t=i-e;return[t,t+n]}const r=i+e;return[r-n,r]}const r=t.sideMassAfter*o;if("top"===t.side){const t=i-r;return[t,t+n]}const s=i+r;return[s-n,s]}function Pi(t,e,o,i,n="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const c={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},l=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(c[t.kind]??99)-(c[e.kind]??99)||((t,e)=>{if(!i||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const o=i.get(t.edge.id)?.target,n=i.get(e.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof n&&Number.isFinite(n)&&o!==n?"top"===t.side?o-n:n-o:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const o=i.get(t.edge.id)?.source,n=i.get(e.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof n&&Number.isFinite(n)&&o!==n?"top"===t.side?n-o:o-n:0}return 0})(t,e)||li(t.edge?.id??"",e.edge?.id??"")||li(t.side,e.side)||t.delta-e.delta)},u=a.length?function(t,e=1/0){let o=e;for(const e of t)o>e&&(o=e);return o}(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;l();let f=null,p=0;for(const t of a)t.time!==f&&(f=t.time,p=0),t.sequence=p++;const y=t=>({time:t.time,phase:0,sequence:t.sequence??0}),g=[];let m=0,x=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?m:x);if(o>0){const e="top"===t.side?"bot":"top",i=Math.min(o,"top"===e?m:x);if(i>0){const n=y(t);g.push({...n,delta:-i,kind:"transfer-out",side:e}),g.push({...n,delta:+i,kind:"transfer-in",side:t.side}),"top"===e?m-=i:x-=i,"top"===t.side?m+=i:x+=i,o-=i}o>0&&null!==h&&(g.push({time:h,delta:+o,kind:"create",side:t.side}),"top"===t.side?m+=o:x+=o)}"top"===t.side?m-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:x+=e}a.push(...g),l();let b=0,v=0,w=0,k=0,S=0,A=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},j=()=>{k=Math.max(k,b+v),S=Math.max(S,b-w),A=Math.max(A,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?b:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?b+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,j(),P(t.time)):"transfer-out"!==t.kind&&(j(),"out"!==t.kind||b+v>1e-12||(w=0),P(t.time))}const L=[];let $=0;for(;M.length>$;){let t=$;for(;M.length>t+1&&M[t+1].t===M[$].t;)t++;L.push(M[$]);for(let e=$+1;t>=e;e++){const t=L[L.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||L.push(M[e])}$=t+1}const R=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let C=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===C||C>t.systemInTime)&&(C=t.systemInTime);let I=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===I||t.systemOutTime>I)&&(I=t.systemOutTime);if(L.length>0){const t=L[L.length-1],e=Math.max(null!=R?R:-1/0,null!=I?I:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&L.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const o=L[0],i=L.find(t=>t.topMass+t.botMass>0);let n,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,n=o),i&&null!=C&&Number.isFinite(C)&&i.t>C&&r>C&&(r=C,n=i),n&&Number.isFinite(r)&&L.unshift({t:r,topMass:n.topMass,botMass:n.botMass,...null!=n.boundaryOffset&&{boundaryOffset:n.boundaryOffset}})}let T=L;if("max"===n&&null!=d&&null!=R&&R>d){let t,e=0;for(const o of L){const i=o.topMass+o.botMass;i>e&&(e=i,t=o)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};T=[...L.filter(t=>d>t.t),{t:d,...e},{t:R,...e},...L.filter(t=>t.t>R)]}}return{samples:T,peak:k,topPeak:S,botPeak:A,localAttachments:_}}function ji(t){const e=ci();return t.forEach((t,o)=>{for(const i of t.occupants)e[i.id]=o}),e}function Li(t,e,o){t.splice(0,t.length,...o);const i=ji(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,i)}function $i(t){const e=new Map,o=[];t.forEach((t,i)=>{if(!t.group)return void o.push({anchor:i,stableId:ui(t),slots:[t]});const n=e.get(t.group)??{indexes:[],slots:[]};n.indexes.push(i),n.slots.push(t),e.set(t.group,n)});for(const[t,i]of e)o.push({anchor:i.indexes.reduce((t,e)=>t+e,0)/i.indexes.length,stableId:`${t}\0${i.slots.map(ui).join("\0")}`,slots:i.slots});return o.sort((t,e)=>t.anchor-e.anchor||li(t.stableId,e.stableId))}function Ri(t){return t.some(t=>t.group)?$i(t).flatMap(t=>t.slots):[...t]}function Ci(t){return t.flatMap(t=>t.slots)}function Ii(t,e,o){const i=new Map;return t.forEach((t,e)=>{for(const o of t.slots)i.set(o,e)}),t.map((t,n)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===n&&o!==n){const e=o>n?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(o===n&&e!==n){const o=e>n?1:-1;r.set(t.target,(r.get(t.target)??0)+s*o)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||o(t,e));return{...t,slots:s}})}function Ti(t,e){t.some(t=>t.group)&&Li(t,e,Ri(t))}function Oi(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function zi(t,e){return function(t,e,o=()=>!0){let i=0;for(let n=0;t.length>n;n++){const[r,s]=e(t[n]);for(let a=n+1;t.length>a;a++){if(!o(t[n],t[a]))continue;const[c,l]=e(t[a]);0>(r-c)*(s-l)&&i++}}return i}(e,e=>[t[e.source],t[e.target]],Oi)}function Fi(t,e){let o=0;for(const i of e){const e=t[i.source],n=t[i.target];null!=e&&null!=n&&(o+=Math.abs(e-n)*(i.value>0?i.value:1))}return o}function Ni(t,e,o){const[i,n]=o.get(t.first),[r,s]=o.get(t.second);return 0>(e.get(i)-e.get(r))*(e.get(n)-e.get(s))?1:0}var Ei=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},Di=828*Ei(8),Bi=3e3;function Wi(t,e,o,i,n,r,s){const a=[...n],c=new Map(n.map(t=>[t,ui(t)])),l=new Map;for(const t of n)for(const e of t.occupants)l.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=l.get(t.source),o=l.get(t.target);e&&o&&(u.set(t,[e,o]),e!==o&&d.push({source:e,target:o,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let o=t+1;e.length>o;o++){if(!u.has(e[o])||!Oi(e[t],e[o]))continue;const i=new Set([...u.get(e[t]),...u.get(e[o])]);h.push({index:h.length,first:e[t],second:e[o],involvedSlots:i})}const f=new Map;for(const t of n)f.set(t,[]);for(const t of h)for(const e of t.involvedSlots)f.get(e)?.push(t);const p=new Uint32Array(h.length);let y=0;const g=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,n.length),x=n.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),b=Math.max(1,g)*(Math.max(1,s.plotH)+m*Math.max(x,n.length)+1e-6*Math.max(1,n.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,S=(t,e)=>{let i=k.get(t);i||(i=new Map,k.set(t,i));const n=i.get(e);if(null!=n)return n;const r=function(t,e,o){return ri(hi([t,e],o)).adjacentClearance[0]??0}(t,e,o);return i.set(e,r),r},A=new Map(n.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:A.get(e[0]),target:A.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:A.get(e[0]),target:A.get(e[1])})}const P=new Map,j=new Map,L=new Map,$=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)$(P,t.source,t.target),$(j,t.target,t.source),$(L,t.source,t.target),$(L,t.target,t.source);const R=e.flatMap(t=>{if(!(t=>1===P.get(t.source)?.size&&P.get(t.source).has(t.target)||1===L.get(t.source)?.size||1===L.get(t.target)?.size)(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),C=t=>{let e=0;for(const o of R)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},I=t=>{const e=new Int16Array(n.length);for(let o=0;t.length>o;o++)e[A.get(t[o])]=o;return C(e)},T=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),O=new Int16Array(n.length),z=new Float64Array(n.length),F=new Float64Array(n.length+1),N=t=>{for(let e=0;t.length>e;e++)O[A.get(t[e])]=e;let e=0;for(const[t,o,i,n]of T)0>(O[t]-O[i])*(O[o]-O[n])&&e++;if(t.length>0){const e=A.get(t[0]);z[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=A.get(t[e-1]),i=A.get(t[e]);z[i]=z[o]+S(t[e-1],t[e])*s.valueScale+s.padding}const o=A.get(t[t.length-1]),i=z[o]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(i>s.plotH&&i>0){const t=s.plotH/i;for(let e=0;z.length>e;e++)z[e]*=t}}F[0]=0;for(let e=0;t.length>e;e++)F[e+1]=F[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,i=0,n=0;for(const t of M){const e=O[t.source],r=O[t.target];if(o+=Math.abs(e-r)*t.weight,i+=Math.abs(z[t.source]-z[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;n+=(F[Math.max(e,r)]-F[o])*t.weight}}return e*b+i+n*m+C(O)+1e-6*o},E=(t,o)=>{const i=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)i[e+1]=i[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0;for(const t of e){const e=o[t.source],r=o[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;n+=(i[Math.max(e,r)]-i[s])*(t.value>0?t.value:1)}return n},D=i=>{const n=ji(i),r=i.slice(0,-1).map((t,e)=>S(t,i[e+1])),a=yi(t,e,o,i,n,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:n,geometry:a,weightedLength:Fi(n,e),pixelLength:gi(a.centerlines,e),transitOcclusion:E(i,n)}},B=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+I(o)+1e-6*e.weightedLength}),W=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+Ni(o,e,u),0),w.fullCrossing++}return B(o,D(t),t)},Y=(t,n,r="quality")=>{let a=n;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,o)=>t+Ni(o,e,u),0),w.fullCrossing++}const c=D(t);return B(a,{...c,transitOcclusion:ki(e,o,t,c.map,c.geometry.centerlines,i,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let q=[...a];const X=(t,e)=>li(c.get(t),c.get(e)),G=function(t){const e=new Set;for(const o of t)if(o.group){if(e.has(o.group))return!0;e.add(o.group)}return!1}(q),V=t=>{const e=(t=>{const e=si(t,d,t=>W(t).cost,{passes:6,compare:X,maxEvaluations:Bi});let o=W(e),i=Bi;for(let t=0;6>t&&i>0;t++){let n=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=i--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let c=0;const l=[];y++;for(const t of[...f.get(r)??[],...f.get(s)??[]])p[t.index]!==y&&(p[t.index]=y,l.push(t),c+=Ni(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of l)h+=Ni(t,d,u);w.localCrossing+=l.length;const g=W(e,o.crossings-c+h);o.cost>g.cost?(o=g,n=!0):[e[t],e[t+1]]=[r,s]}if(!n)break}return e})(t);if((t.length>8?1/0:Ei(t.length)*(t.length+M.length+T.length))>Di)return e;const o=ai(t,N,{maxItems:8,maxEvaluations:5e4}),i=Y(o),n=Y(e);return i.crossings!==n.crossings&&n.crossings>i.crossings?o:e},H="geometry-refine"===s.mode;if(H||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!H&&"inside-out"===s.laneOrder)if(G){const t=$i(q),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||li(t.stableId,o.stableId)),i=Array(o.length);let n=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(i[Math.floor((o.length-1)/2)]=o[0]);for(let t=1;o.length>t;t++)t%2==1&&o.length>r||0>n?i[r++]=o[t]:i[n--]=o[t];q=Ci(i)}else{const t=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||X(t,e)),e=Array(t.length);let o=Math.floor((t.length-1)/2)-1,i=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let n=1;t.length>n;n++)n%2==1&&t.length>i||0>o?e[i++]=t[n]:e[o--]=t[n];q=e}}else q=G?(t=>{let e=$i(t);if(1>=e.length)return Ci(e);const o=t=>W(Ci(t)).cost;e=$i(V(t)),e=Ii(e,d,X);const i=function(t,e){const o=new Map;for(const e of t)for(const t of e.slots)o.set(t,e);const i=new Map;for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(!e||!n||e===n)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=n.stableId>e.stableId?`${e.stableId}\0${n.stableId}`:`${n.stableId}\0${e.stableId}`,a=i.get(s);a?a.weight=(a.weight??0)+r:i.set(s,{source:e,target:n,weight:r})}return[...i.values()]}(e,d);e=si(e,i,o,{passes:6,compare:(t,e)=>li(t.stableId,e.stableId),maxEvaluations:Bi}),e=function(t,e,o={}){const i=[...t];if(1>=i.length)return i;let n=e(i),r=1;const s=Math.max(0,o.passes??6),a=Math.max(1,o.maxEvaluations??1/0);for(let t=0;s>t&&a>r;t++){let t=!1;for(let o=0;i.length-1>o&&a>r;o++){[i[o],i[o+1]]=[i[o+1],i[o]];const s=e(i);r++,n>s?(n=s,t=!0):[i[o],i[o+1]]=[i[o+1],i[o]]}if(!t)break}return i}(e,o,{passes:8,maxEvaluations:Bi});const n=e.length>8?1/0:Ei(e.length)*(e.length+M.length+T.length);if(Di>=n){const t=ai(e,t=>N(Ci(t)),{maxItems:8,maxEvaluations:5e4}),o=Ci(t),i=Ci(e),n=Y(o),r=Y(i);n.crossings!==r.crossings?e=r.crossings>n.crossings?t:e:r.cost>n.cost&&(e=t)}return e=Ii(e,d,X),Ci(e)})(q):V(q);if(!H&&"crossing-min+inside-out"===s.laneOrder&&q.length>1)if(G){const t=$i(q);let e=W(Ci(t)),o=Ci(t),i=e;const n=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||li(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===n)continue;t.splice(s,1),t.splice(n,0,r);const a=Ci(t),c=W(a);c.cost>e.cost?(t.splice(n,1),t.splice(s,0,r)):(e=c,i.cost>c.cost&&(o=a,i=c))}q=o}else{let t=W(q),e=[...q],o=t;const i=Math.floor((q.length-1)/2),n=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||X(t,e));for(const r of n){const n=q.indexOf(r);if(n===i)continue;q.splice(n,1),q.splice(i,0,r);const s=W(q);s.cost>t.cost?(q.splice(i,1),q.splice(n,0,r)):(t=s,o.cost>s.cost&&(e=[...q],o=s))}q=e}if((H||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&q.length>1)if(G){let t=$i(q),e=Y(Ci(t),void 0,"score");for(let o=0;6>o&&t.length>1;o++){let o=!1;for(let i=0;t.length-1>i;i++){[t[i],t[i+1]]=[t[i+1],t[i]];const n=Ci(t),r=Y(n,void 0,"score");e.cost>r.cost?(q=n,e=r,o=!0):[t[i],t[i+1]]=[t[i+1],t[i]]}if(!o)break}t=Ii($i(q),d,X),q=Ci(t)}else{let t=Y(q,void 0,"score");for(let e=0;q.length-1>e;e++){const o=q[e],i=q[e+1],n=new Map(q.map((t,e)=>[t,e]));let r=0;const s=[];y++;for(const t of[...f.get(o)??[],...f.get(i)??[]])p[t.index]!==y&&(p[t.index]=y,s.push(t),r+=Ni(t,n,u));[q[e],q[e+1]]=[i,o];const a=new Map(n);a.set(o,e+1),a.set(i,e);let c=0;for(const t of s)c+=Ni(t,a,u);w.localCrossing+=s.length;const l=Y(q,t.crossings-r+c,"score");t.cost>l.cost?t=l:[q[e],q[e+1]]=[o,i]}}const U=Ri(a);q=Ri(q);let K=Y(q);const Z=Y(U);if(H){const t=I(U),e=I(q);(K.crossings>Z.crossings||K.crossings===Z.crossings&&e>t+1e-9||K.cost>Z.cost)&&(q=U,K=Z)}else K.cost>Z.cost&&(q=U,K=Z);const Q=function({order:t,after:e,nodes:o,edges:i,outgoingPartners:n,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:c}){const l=(o,n)=>{const r=[...new Set(n.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),l=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-l+1!==r.length||1>=Math.abs(2*s-l-u))return;const d=[...t];d.splice(s,1),d.splice(l+u>>1,0,o);const h=Ri(d),f=c(h),p=new Set(o.occupants.map(t=>t.id)),y=new Set(n.flatMap(t=>t.occupants.map(t=>t.id))),g=i.reduce((t,e)=>p.has(e.source)&&y.has(e.target)||p.has(e.target)&&y.has(e.source)?t+(e.value>0?e.value:1):t,0);(function(t,e,o=0){return e.crossings>t.crossings||t.crossings===e.crossings&&e.cost+o>=t.cost})(f,e,Math.abs(2*s-l-u)*a*Math.max(1,g))&&(t=h,e=f)};for(const[t,e]of n)r.has(t)||3>e.size||l(s.get(t),[...e].map(t=>s.get(t)));for(const t of o){const e=s.get(t.id);t.group||!e.group||3>(r.get(t.id)?.size??0)||l(e,[...r.get(t.id)??[]].map(t=>s.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,o)=>o.indexOf(t)===e))}return{order:t,after:e}}({order:q,after:K,nodes:t,edges:e,outgoingPartners:P,incomingPartners:j,slotForNode:l,averageGap:m,evaluate:Y});return q=Q.order,K=Q.after,Li(n,r,q),{before:Z,after:K,initialOrder:a.map(t=>c.get(t)),evaluations:w}}function Yi(t,e,o){const i=t.map(t=>{const i=t.occupants.map(t=>({id:t.id,end:o[t.id]?.end??t.end}));let n=0,r=0;for(const t of i){const o=e[t.id];n=Math.max(n,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:i,peak:{topPeak:n,botPeak:r},...null!=t.group?{group:t.group}:{}}}),n=ci();return i.forEach((t,e)=>{for(const o of t.occupants)n[o.id]=e}),{slots:i,slotByNode:n}}var qi=new Map,Xi=1e5,Gi=1e-9;function Vi(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function Hi(t,e){return li(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function Ui(t){const e=new Map,o=new Map;for(const i of t)o.has(i.source)||o.set(i.source,new Set),e.has(i.target)||e.set(i.target,new Set),o.get(i.source).add(i.target),e.get(i.target).add(i.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...o].map(([t,e])=>[t,e.size]))}}function Ki(t){const e=new Map,o=new Map,i=(t,e,o,i)=>{let n=t.get(e);n||(n=new Map,t.set(e,n)),n.set(o,(n.get(o)??0)+i)};for(const n of t){const t=n.value>0&&Number.isFinite(n.value)?n.value:1;i(e,n.source,n.target,t),i(o,n.target,n.source,t)}const n=new Map,r=t=>{if(n.has(t))return;const i=e.get(t),r=o.get(t),s=new Map;for(const[t,e]of i??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,o]=[...s][0];n.set(t,{partner:e,weight:o})}};for(const e of t)r(e.source),r(e.target);return n}function Zi(t,e,o){const i=o.get(t),n=o.get(e);return!i||!n||i.partner===n.partner||i.partner===e||n.partner===t}function Qi(t,e,o){return!!o.has(t)&&e.some(e=>!Zi(t,e,o))}function Ji(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function tn(t,e,o,i){if(12>=t.length||1>=i.slotCount)return i.assignment;const n=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=Ui(o);for(const t of o){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o||e===o)continue;const i=Ji(t,s);r[e].set(o,(r[e].get(o)??0)+i),r[o].set(e,(r[o].get(e)??0)+i)}const a=Ki(o),c=t.map(t=>a.get(t)?.weight??0),l=Array.from({length:t.length},()=>new Map);let u=0;for(let o=0;t.length-1>o&&5e4>u;o++)if(a.has(t[o]))for(let i=o+1;t.length>i;i++){if(!a.has(t[i]))continue;if(e.conflicts(t[o],t[i]))continue;u++;const n=Math.min(c[o],c[i])||Math.max(c[o],c[i]),r=Zi(t[o],t[i],a)?n:-n;if(Math.abs(r)>Gi&&(l[o].set(i,r),l[i].set(o,r),u>=5e4))break}const d=[...i.assignment],h=Array.from({length:i.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const f=(t,e,o)=>{const i=d[e],n=d[o];let r=0;const s=new Set;for(const a of[e,o])for(const[c,l]of t[a]){const t=c>a?`${a}:${c}`:`${c}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?n:i)===(c===e?n:c===o?i:d[c]);d[a]===d[c]!==u&&(r+=u?l:-l)}return r},p=(t,e,o)=>{let i=0;for(const[n,r]of t[e]){const t=o===d[n];d[e]===d[n]!==t&&(i+=t?r:-r)}return i},y=(t,e)=>t>Gi||Gi>=Math.abs(t)&&e>Gi,g=(t,e,o,i)=>t>o+Gi||Gi>=Math.abs(t-o)&&e>i+Gi;let m=0;for(let o=0;32>o&&Xi>m;o++){let o=null,i=-1,n=-1,s=-1,a=-1/0,c=-1/0;for(let u=0;t.length>u;u++){for(let f=0;h.length>f&&m++<Xi;f++){if(f===d[u])continue;if(!h[f].every(o=>!e.conflicts(t[u],t[o])))continue;const m=p(r,u,f),x=p(l,u,f);y(m,x)&&g(m,x,a,c)&&(o="move",i=u,n=-1,s=f,a=m,c=x)}if(m>=Xi)break}for(let u=0;t.length-1>u;u++){for(let p=u+1;t.length>p&&m++<Xi;p++){const m=d[u],x=d[p];if(m===x)continue;if(!h[x].every(o=>o===p||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[p],t[o])))continue;const b=f(r,u,p),v=f(l,u,p);y(b,v)&&g(b,v,a,c)&&(o="swap",i=u,n=p,s=-1,a=b,c=v)}if(m>=Xi)break}if(null==o||-1===i)break;if("move"===o){const t=d[i];h[t].splice(h[t].indexOf(i),1),h[s].push(i),d[i]=s;continue}const u=d[i],x=d[n];h[u].splice(h[u].indexOf(i),1,n),h[x].splice(h[x].indexOf(n),1,i),d[i]=x,d[n]=u}return d}function en(t,e){let o=1/0,i=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>1e-9&&(o=Math.min(o,e.t),i=Math.max(i,e.t));return Number.isFinite(o)&&Number.isFinite(i)?(null!=e.start&&(o=Math.max(o,e.start)),null!=e.end&&(i=Math.min(i,e.end)),o>i?{start:null,end:null}:{start:o,end:i}):{start:null,end:null}}function on(t,e,o,i){const n=function(t,e,o,i){return`${t.map(t=>{const e=o[t.id],n=i[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,n?.start??"",n?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,o,i),r=qi.get(n);if(r)return Yi(r.slots,o,i);const s=ci();for(const e of t)s[e.id]=en(o[e.id],i[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,o)=>e[t.id].start-e[o.id].start||e[t.id].end-e[o.id].end||li(t.id,o.id)).map(t=>t.id)}(t,s),c=new Map(t.map(t=>[t.id,t])),l=new Map(t.map(t=>[t.id,t.group||void 0])),u=Ki(e),d=function(t,e,o,i,n,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),c=new Map(t.map(t=>[t,new Set]));for(const t of i)s.add(Hi(t.source,t.target)),a.get(t.target)?.add(t.source),c.get(t.source)?.add(t.target);const l=new Map,u=new Set,d=(t,e)=>{for(let o=0;t.length>o;o++)for(let i=o+1;t.length>i;i++){const n=Hi(t[o],t[i]);e instanceof Map?e.set(n,[t[o],t[i]]):e.add(n)}};for(const t of c.values())d([...t],l);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[i,n]]of l)u.has(t)&&(Vi(e[i],e[n])||Vi(o[i],o[n])&&(h.add(i),h.add(n)));return{conflicts:(t,o)=>{const i=n.get(t),a=n.get(o);return null!=i&&null!=a&&i!==a||!(null!=i==(null!=a)||s.has(Hi(t,o))||r.has(t)&&r.has(o)&&Zi(t,o,r))||!!Vi(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(Hi(t,o))}}}(a,s,i,e,l,u),h=function(t,e,o=new Map){const i=[],n=[];for(const r of t){let t=i.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!Qi(r,t,o));-1!==t||o.has(r)||(t=i.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=i.length,i.push([])),i[t].push(r),n.push(t)}return{assignment:n,slotCount:i.length}}(a,d,u),f=function(t,e,o,i){if(0===t.length||t.length>12||1>=i.slotCount)return i.assignment;const n=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),c=Ui(o);for(const t of o){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o||e===o)continue;const i=Ji(t,c);r[e][o]+=i,r[o][e]+=i,a[e].set(o,(a[e].get(o)??0)+i),s[o].set(e,(s[o].get(e)??0)+i)}const l=Ki(o),u=t.map(t=>l.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let o=e+1;t.length>o;o++){for(const[t,i]of s[e])d[e][o]+=Math.min(i,s[o].get(t)??0);for(const[t,i]of a[e])d[e][o]+=Math.min(i,a[o].get(t)??0);if(l.has(t[e])&&l.has(t[o])){const i=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=Zi(t[e],t[o],l)?i:-i}d[o][e]=d[e][o]}let h=[...i.assignment],f=(e=>{let o=0,i=0;for(let n=0;t.length>n;n++)for(let s=n+1;t.length>s;s++)e[n]===e[s]&&(o+=r[n][s],i+=d[n][s]);return{flow:o,affinity:i}})(h),p=0;const y=Array(t.length).fill(-1),g=Array.from({length:i.slotCount},()=>[]),m=(o,n,s,a)=>{if(p>=75e3)return;if(o===t.length)return p++,void((s>f.flow||s===f.flow&&a>f.affinity||s===f.flow&&a===f.affinity&&function(t,e){for(let o=0;Math.min(t.length,e.length)>o;o++)if(t[o]!==e[o])return e[o]>t[o];return e.length>t.length}(y,h))&&(h=[...y],f={flow:s,affinity:a}));const c=Math.min(n+1,i.slotCount-1);for(let i=0;c>=i;i++){if(g[i].some(i=>e.conflicts(t[o],t[i])))continue;let c=0,l=0;for(const t of g[i])c+=r[o][t],l+=d[o][t];if(y[o]=i,g[i].push(o),m(o+1,Math.max(n,i),s+c,a+l),g[i].pop(),y[o]=-1,p>=75e3)return}};return y[0]=0,g[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:tn(a,d,e,h)}),p=new Map,y=f.map(t=>(p.has(t)||p.set(t,p.size),p.get(t))),g=Array.from({length:p.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=ci();a.forEach((t,e)=>{const o=y[e],i=g[o];i.occupants.push({id:t,end:s[t].end??-1/0});const n=c.get(t)?.group;n&&(i.group=n),m[t]=o});for(const e of[...t].sort((t,e)=>li(t.id,e.id)))null==m[e.id]&&(g[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of g){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||li(t.id,e.id));for(const e of t.occupants){const i=o[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,i?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,i?.botPeak||0)}}const x={slots:g,slotByNode:m};return function(t,e){for(qi.has(t)&&qi.delete(t),qi.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(ci(),e.slotByNode)});qi.size>12;){const t=qi.keys().next().value;if(null==t)break;qi.delete(t)}}(n,x),x}function nn(t){return t.topMass+t.botMass}function rn(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>nn(e)<nn(t)?t:e,o[0]);let i=null;for(const o of t.samples){if(o.t>e)break;i=o}return i}function sn(t,e,o,i,n,r,s=0){const a=new Map;for(const o of t){if(!o.group||!e[o.id])continue;const t=a.get(o.group)??[];t.push(o),a.set(o.group,t)}if(0===a.size||0>=r)return e;const c=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,l]of a){const a=o.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=n[u.occupants[0]?.id],f=n[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;const p=(h-u.peak.topPeak*r+(f+d.peak.botPeak*r))/2,y=[...new Set(l.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),g=new Map;for(const t of l)g.set(t.id,new Map);for(const t of y){const o=new Map;for(const n of l){const r=rn(e[n.id],t);if(!r||1e-9>=nn(r))continue;const s=i[n.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:n,sample:r}),o.set(s,a)}const a=[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>nn(t)))}));if(0===a.length)continue;let c=p-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:o,sample:i}of e.active){const e=(c-n[o.id])/r+i.topMass-(i.boundaryOffset??0);g.get(o.id).set(t,e)}c+=e.mass*r+Math.max(0,s)}}for(const t of l){const o=e[t.id],i=c[t.id],n=g.get(t.id),r=[];for(const t of y){const e=n.get(t),i=o.samples.filter(e=>e.t===t);if(i.length>0){r.push(...i.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=rn(o,t);null!=e&&s&&nn(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}i.samples=r,i.localAttachments=new Map([...o.localAttachments].map(([t,e])=>{const o=n.get(e.time);return[t,{...e,...null!=o?{boundaryOffset:(e.boundaryOffset??0)+o}:{}}]}))}}return c}function an(t,e,o,i,n){const{plotH:r,padding:s,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=n,y=ci(),g=ci();for(const e of t)y[e.id]=o[e.id].topPeak||0,g[e.id]=o[e.id].botPeak||0;const m="half"===u,x=ci();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 n=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of i.outgoing[e.id]){n>t.startTime&&(n=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&n>t.systemInTime&&(n=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of i.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;n>e&&(n=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}x[e.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(r)?r:null}}let b=ci(),v=[],w=[];if(n.frozenSlots){const t=Yi(n.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(ui)}else if("reuse"===c){const i=on(t,e,o,x);v=i.slots,b=i.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:x[t.id]?.end??-1/0}],peak:{topPeak:y[t.id],botPeak:g[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Ti(v,b),0===w.length&&(w=v.map(ui));let k=null;n.frozenSlots||(n.fixedSlotOrder?function(t,e,o){const i=new Map(o.map((t,e)=>[t,e]));Li(t,e,[...t].sort((t,e)=>(i.get(ui(t))??1/0)-(i.get(ui(e))??1/0)||li(ui(t),ui(e))))}(v,b,n.fixedSlotOrder):n.runOrdering&&l&&"insertion"!==l&&(k=Wi(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:l,ribbonLane:f,domain:p}))),Ti(v,b);const S=yi(t,e,o,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:n.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,j=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(ui),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:j}}function cn(t){const{sx:e,sTop:o,sBot:i,tx:n,tTop:r,tBot:s,cp1X:a,cp2X:c}=t,l=(o+i)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${c},${r} ${n},${r}`,`L${n},${s}`,`C${c},${s} ${a},${i} ${e},${i}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:l},{x:a,y:l},{x:c,y:u},{x:n,y:u}],halfWidth:(i-o)/2}}}function ln(t,e,o,i,n,r,s,a,c={}){const l=n,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(o.time)),f=t.value*l,p=o.value*l,y=e+(t.boundaryOffset??0)*l,g=i+(o.boundaryOffset??0)*l,m=t.sideMassBefore*l,x=o.sideMassAfter*l;let b,v,w,k;"top"===t.side?(b=y-m,v=b+f):(v=y+m,b=v-f),"top"===o.side?(w=g-x,k=w+p):(k=g+x,w=k-p);const S=c.sourceRunwayStart,A=c.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof S&&Number.isFinite(S),j="number"==typeof A&&Number.isFinite(A)&&A>0;if(P&&M>1e-9&&_>0&&("auto"===A||j)){const e="source"===s?.85:"target"===s?.15:.5,o="auto"===A?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):A;if(o>_){const e=r(u(Math.min(S,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-o)))}}const L="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:L,cp2X:L}}function un(t){return Math.max(18,11*t.length*.58)}function dn(t){const e=1.22*un(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function hn(t,e){const o=t.labelX-un(t.labelText),i=e.labelX-un(e.labelText);return e.labelX+3>=o&&t.labelX+3>=i}var fn=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function pn(t){return t.replace(fn,(t,e,o)=>`${o},${e}`)}function yn(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function gn(t){return{...t,pathD:pn(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}var mn=require("react/jsx-runtime");function xn(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function bn(t,e){const{background:o="transparent",stroke:i="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,c=Math.max(8,Math.ceil(2*r));return(0,mn.jsxs)("pattern",{id:e,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&(0,mn.jsx)("rect",{width:c,height:c,fill:o}),(0,mn.jsx)("line",{x1:0,y1:0,x2:0,y2:c,stroke:i,strokeWidth:n,strokeOpacity:a}),(0,mn.jsx)("line",{x1:r,y1:0,x2:r,y2:c,stroke:i,strokeWidth:n,strokeOpacity:a})]},e)}function vn(t){const{nodes:e,edges:o,domain:i,plotW:n,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:c,colorOf:l,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:y="raw",styleRules:g,colorBy:m,valueAccessor:x,usageMode:b="static"}=t,v="vertical"===d?r:n,w="vertical"===d?n:r,k=function(t,e,o,i={}){const n=Jo(i.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:n.duplicateIds}),s.add(e.id);const a=new Set,c=Array.isArray(o)&&2===o.length,l=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]);c&&l&&l&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:n.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,o,i,{usageMode:b}),{fatal:S,warnings:A}=function(t){const e=[],o=[];for(const i of t)"fatal"===ei(i)?e.push(i):o.push(i);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==Jo(o).invalidSystemTime)return t;const i=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===i.size?t:t.map(t=>{if(!i.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(o,k,b),_=(0,Zo.scaleTime)().domain(i).range([0,v]);if(S.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:_};const P=function(t,e,o){const{plotH:i,pairing:n="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:c,lanePlacement:l="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=o,p=Number.isFinite(d)?Math.max(0,d):0,y=function(t,e){const o=ci(),i=ci();for(const e of t)o[e.id]=[],i[e.id]=[];for(const t of e)i[t.source]&&i[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:i}}(t,e),g=function(t,e,o,i="temporal"){const n="temporal"===i?(t,e)=>t.endTime-e.endTime||li(t.id,e.id):(t,e)=>e.value-t.value||li(t.id,e.id),r="temporal"===i?(t,e)=>t.startTime-e.startTime||li(t.id,e.id):(t,e)=>e.value-t.value||li(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const i of t){const t=i[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const n=o.get(t);n.edges.push(i),n.total+=i.value,n.earliestStart=Math.min(n.earliestStart,i.startTime),n.latestEnd=Math.max(n.latestEnd,i.endTime)}const s=[...o.values()];s.sort("temporal"===i?(t,o)=>"target"===e?t.earliestStart-o.earliestStart||li(t.partner,o.partner):t.latestEnd-o.latestEnd||li(t.partner,o.partner):(t,e)=>e.total-t.total||li(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:n);return s};for(const e of t){const t=o.outgoing[e.id],i=o.incoming[e.id];if(0===i.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(i,"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(i,"source"),o=a(t,"target"),n=Math.max(e.length,o.length);for(let t=0;n>t;t++){const i=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=i;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=i}}}return s}(t,e,y,n);let m=ci();for(const e of t)m[e.id]=Pi(e,y,g,void 0,u);const x=an(t,e,m,y,{plotH:i,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=x.slotByNode[t.source],o=x.slotByNode[t.target];if(void 0===e||void 0===o)continue;const i=g.get(t.id);e!==o?e>o?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(v.add(t.id),i.sourceSide="bot",i.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],o=y.incoming[e.id],i=new Set(t.map(t=>g.get(t.id).sourceSide)),n=new Set(o.map(t=>g.get(t.id).targetSide));if(1===i.size&&o.length>0){const t=[...i][0];for(const e of o)x.slotByNode[e.source]===x.slotByNode[e.target]&&(g.get(e.id).targetSide=t)}if(1===n.size&&t.length>0){const e=[...n][0];for(const o of t)x.slotByNode[o.source]===x.slotByNode[o.target]&&(g.get(o.id).sourceSide=e)}}!function(t,e,o){const i=new Map,n=[];for(const e of t)n.push({time:e.startTime,kind:"out",edge:e}),n.push({time:e.endTime,kind:"in",edge:e});n.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||li(t.edge.id,e.edge.id));const r=t=>{let e=i.get(t);return e||(e={top:0,bot:0},i.set(t,e)),e},s=(t,e,o)=>{const i="top"===e?"bot":"top",n=Math.min(o,t[e]);t[e]-=n;const r=o-n;r>0&&(t[i]=Math.max(0,t[i]-r))};for(const t of n){const{edge:i}=t;if("in"===t.kind){const t=e.get(i.id)?.targetSide??"bot";r(i.target)[t]+=i.value;continue}const n=r(i.source),a=e.get(i.id);let c=a.sourceSide??"bot";if(o[i.source]===o[i.target]){const t=n.top>=i.value,e=n.bot>=i.value;t!==e?c=t?"top":"bot":t||e||n.top===n.bot||(c=n.top>n.bot?"top":"bot"),a.sourceSide=c,a.targetSide=c}s(n,c,i.value)}}(e,g,x.slotByNode),function(t,e,o,i){for(const n of t){const t=e.incoming[n.id],r=e.outgoing[n.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const i of t)"top"===o.get(i.id).targetSide?e.inTop+=i.value:e.inBot+=i.value;for(const t of r)"top"===o.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const n=s(),a="top"===t?n.outTop-n.inTop:n.outBot-n.inBot,c="top"===e?n.inTop-n.outTop:n.inBot-n.outBot;if(0>=a||0>=c)return!1;const l=Math.min(a,c),u=r.filter(e=>!i.has(e.id)&&o.get(e.id).sourceSide===t&&l>=e.value).sort((t,e)=>e.value-t.value||li(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let c=r.length+1;for(;c-- >0&&(a("top","bot")||a("bot","top")););}}(t,y,g,v),m=ci();for(const e of t)m[e.id]=Pi(e,y,g,void 0,u);const w=an(t,e,m,y,{plotH:i,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((t,e,o)=>t+(null!=e.group&&e.group===w.slots[o+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*i-S*p)/A),_=2*M+di(w.slots,M,p).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(i-_)/k):1,j=Number.isFinite(c)&&c>0?Math.min(P,c):P;let L=an(t,e,m,y,{plotH:i,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const $=Number.isFinite(c)&&c>0&&P>c+1e-12;if("insertion"!==s&&("hug"===l||$)&&L.slots.length>1&&(Wi(t,e,m,L.laneLifetime,L.slots,L.slotByNode,{plotH:i,padding:M,valueScale:j,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:l,mode:"geometry-refine"}),L=an(t,e,m,y,{plotH:i,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(ui),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(t,e){const o=(t,o)=>{for(const i of t){const t=new Map;for(const n of i){const i=`${("out"===o?e.get(n.id)?.sourceSide:e.get(n.id)?.targetSide)??""}\0${"out"===o?n.startTime:n.endTime}`,r="out"===o?`${n.target}\0${n.endTime}`:`${n.source}\0${n.startTime}`,s=t.get(i);if(null!=s&&s!==r)return!0;t.set(i,r)}}return!1};return o(Object.values(t.outgoing),"out")||o(Object.values(t.incoming),"in")}(y,g)){const o=function(t,e,o,i){const n=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=o[r.source],c=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(c)))continue;const l=_i(t,a,i),u=_i(s,c,i);n.set(r.id,{source:(l[0]+l[1])/2,target:(u[0]+u[1])/2})}return n}(e,m,L.centerlines,j);m=ci();for(const e of t)m[e.id]=Pi(e,y,g,o,u);L=an(t,e,m,y,{plotH:i,padding:M,valueScale:j,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(ui),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const R=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),C=[...L.slots].sort((t,e)=>(R.get(ui(t))??1/0)-(R.get(ui(e))??1/0)||li(ui(t),ui(e))),I=ci();C.forEach((t,e)=>{for(const o of t.occupants)I[o.id]=e});const T=yi(t,e,m,C,I,{plotH:i,padding:M,valueScale:j,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),O=sn(t,m,C,I,T.centerlines,j,p),z=Si(zi(I,e),Fi(I,e),e,O,C,I,T.centerlines,L.laneLifetime,j,T.verticalUtilization,h,f);m=sn(t,m,L.slots,L.slotByNode,L.centerlines,j,p);const F=Si(zi(L.slotByNode,e),Fi(L.slotByNode,e),e,m,L.slots,L.slotByNode,L.centerlines,L.laneLifetime,j,L.verticalUtilization,h,f);return{nodeData:m,sides:g,valueScale:j,padding:M,compressedPadding:12>M,centerlines:L.centerlines,laneLifetime:L.laneLifetime,slots:L.slots,slotByNode:L.slotByNode,crossingsBefore:"insertion"===s?null:z.crossings,crossingsAfter:"insertion"===s?null:F.crossings,lengthBefore:"insertion"===s?null:z.weightedLength,lengthAfter:"insertion"===s?null:F.weightedLength,layoutQualityBefore:z,layoutQuality:F}}(e,M,{plotH:w,...u,ribbonLane:s,domain:i}),{centerlines:j,nodeData:L,valueScale:$}=P,R=yt(m,x),C=[],I=[],T=0===a?new Map:function(t,e,o){const i=new Set(e.map(t=>t.target)),n=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(i.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const o=e.flatMap(t=>r.get(t.id)??[]),n=new Set(o.map(t=>t.startTime));o.length>0&&1===n.size&&e.every(t=>{const e=t.xExtent?.[0],n=o[0].startTime;return!i.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&n>e})&&a.add(t)}const c=new Map;for(const[t,e]of r){const i=n.get(t);if(i?.group&&!a.has(i.group))continue;const r=i?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),l=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let i=t+1;for(;s.length>i&&s[i].startTime===e;)i++;for(let e=t;i>e;e++){const t=s[e],i=Number.isFinite(r)&&t.startTime>r,n=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!i&&!n)continue;let a=o[0];i&&(a=Math.max(a,r)),n&&(a=Math.max(a,t.systemInTime)),!i&&n&&Number.isFinite(l)&&(a=Math.max(a,l)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&c.set(t.id,a)}u=e,t=i}}for(const[t,e]of s){if(!a.has(t))continue;const o=e.flatMap(t=>r.get(t.id)??[]);if(!o.every(t=>c.has(t.id))){for(const t of o)c.delete(t.id);continue}const i=Math.max(...o.map(t=>c.get(t.id)));for(const t of o)c.set(t.id,i)}return c}(e,M,i),O=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),z=new Map;for(const t of M){const e=L[t.source]?.localAttachments.get(t.id),o=L[t.target]?.localAttachments.get(t.id);e&&o&&z.set(t.id,ln(e,j[t.source],o,j[t.target],$,_,s,i,{minRun:a,sourceRunwayStart:T.get(t.id)}))}const F=function(t,e,o,i,n,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),o=null==t?"node:"+e.source:"group:"+t,i=a.get(o)??new Map,n=i.get(e.startTime)??[];n.push(e),i.set(e.startTime,n),a.set(o,i)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>o.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const c=i(r),l=Math.min(...t.map(t=>t.sx));if(l>=c-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?c:Math.min(c,i(e))})),d=Math.min(c,Math.max(l,u));for(const t of a){const o=e.get(t.id),i=d+(o.tx-d)*("source"===n?.85:"target"===n?.15:.5);s.set(t.id,{...o,sx:d,cp1X:i,cp2X:i})}}return s}(M,z,T,_,s,O),N=function(t,e,o,i,n){const r=new Map;for(const s of t){if(!o.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=i(s.startTime)-1e-9)continue;const a=n(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,F,T,_,t=>i[0]+t/v*(i[1]-i[0])),E=function(t,e,o){const i=new Map,n=new Map;for(const[t,e]of o??[]){const o=n.get(e)??[];o.push(t),n.set(e,o)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:n.get(s)??[r.source];for(const e of a){const o=i.get(e)??new Map,n=o.get(r.startTime);o.set(r.startTime,null==n?t:Math.min(n,t)),i.set(e,o)}}return i}(M,N,O);e.forEach((t,e)=>{const o=L[t.id];if(!o||0===o.samples.length)return;const n=(r=o.samples,(s=E.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,o,i,n){if(0===t.length)return null;const r=Mi(t,n),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,c=t=>s(t)+r[t].botMass*o;let l=`M${i(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)l+=` L${i(r[t].t)},${a(t)}`;l+=` L${i(r[r.length-1].t)},${c(r.length-1)}`;for(let t=r.length-2;t>=0;t--)l+=` L${i(r[t].t)},${c(t)}`;return l+" Z"}(n,j[t.id],$,_,i);if(!a)return;const c=Mi(n,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],h=j[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*$/2;let f,p,y=l(t.id,e),m=y,x=.5;const b=t.__raw??t;if(g&&g.length>0){const t=xt(b,g,R(b));"string"==typeof t.fill?y=t.fill:null!=t.fill&&xn(t.fill)&&(p=t.fill,y=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:y),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(f=t.fillOpacity),"number"==typeof t.opacity&&null==f&&(f=t.opacity)}const v=function(t,e,o,i,n,r){const s=o.nodeData[t];if(!s||0===s.samples.length)return[];const a=o.valueScale,c=o.centerlines[t],l=Mi(s.samples,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],d=[...l].reverse().find(t=>t.topMass+t.botMass>0)||l[l.length-1],h=i(u.t),f=i(d.t),p=t=>i(Ai(t,n)),y=[],g=(t,e,o,i)=>`M${t},${e} L${o},${e} L${o},${i} L${t},${i} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=s.localAttachments.get(o.id),e=r?.get(o.id)??o.startTime;if(t&&"out"===t.kind&&e>o.systemInTime){const i=p(o.systemInTime),r=p(e),s=null!=n&&n[0]>o.systemInTime,l=s?i:i-20,u=s?Math.min(r,i+20):i,d=Math.max(h,l);if(r>d){const[e,o]=_i(t,c,a);y.push({pathD:g(d,e,r,o),x0:l,x1:u,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=s.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=p(o.systemOutTime),i=p(o.endTime),n=e+20,r=Math.min(f,n);if(r>i){const[o,s]=_i(t,c,a);y.push({pathD:g(i,o,r,s),x0:e,x1:n,from:1,to:0})}}}}return y}(t.id,M,P,_,i,N);C.push({id:t.id,pathD:a,fill:y,stroke:m,strokeWidth:x,...null!=f&&{fillOpacity:f},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const D=new Map;e.forEach((t,e)=>D.set(t.id,e)),M.forEach(t=>{const e=F.get(t.id);if(!e)return;const o=D.get(t.source)??0,i=l(t.source,o),{pathD:n,bezier:r}=cn(e),s=t.__raw??t,a="function"==typeof c?Number(c(s)):c,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;I.push({id:t.id,pathD:n,fill:i,opacity:u,rawDatum:s,bezier:r})});const B=function(t,e,o){const i=t.map(t=>({...t})),n=new Map;for(const t of i){const o=e[t.id];if(null==o)continue;const i=n.get(o)??[];i.push(t),n.set(o,i)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,i=(t.length-1)/2;t.forEach((t,n)=>{t.labelY=Math.max(8,Math.min(o-8,e+16*(n-i)))})};for(const t of n.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],o=-1/0;for(const i of t){const t=i.labelX-un(i.labelText);e.length>0&&t>o+3&&(r(e),e=[],o=-1/0),e.push(i),o=Math.max(o,i.labelX)}r(e)}return function(t,e){const o=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;o.length>t;t+=1){let e=8;for(let i=0;t>i;i+=1)hn(o[t],o[i])&&(e=Math.max(e,o[i].labelY+16));o[t].labelY=Math.max(o[t].labelY,e)}for(let t=o.length-1;t>=0;t-=1){let i=e-8;for(let e=t+1;o.length>e;e+=1)hn(o[t],o[e])&&(i=Math.min(i,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,i)}}}(i,o),i}(C,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:pn(t.pathD),gradientStubs:t.gradientStubs?.map(gn),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),W="vertical"===d?function(t,e,o){const i=t.map(t=>({...t}));for(const t of i){const o=1.22*un(t.labelText)+4;t.labelX=e-4>o?Math.max(o/2+2,Math.min(e-o/2-2,t.labelX)):e/2}const n=[],r=[...i].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=n[n.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?n.push([t]):e.push(t)}for(const t of n){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],i=new Map;for(const o of t){const[t,n]=dn(o);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=n,i.set(o,r)}const n=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>n;for(const e of t){const t=i.get(e)??0;e.labelY=r?Math.min(o-8,12+14*t):Math.max(8,n-14*t)}}return i}(B,n,r):B,Y=new Map;if(null!=f)for(const t of e){const e=t.__raw??t,o="function"==typeof f?f(e):Number(e[f]);Number.isFinite(o)&&Y.set(t.id,o)}const q=function(t,e,o,i,n={}){if(!1===i)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===i)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*o)/14e3)));Number.isFinite(n.maxLabels)&&n.maxLabels>=0&&(r=Math.min(r,Math.floor(n.maxLabels)));const s=t.map((t,e)=>{const o=n.priorityById?.get(t.id),i=Math.abs(t.labelY);return{band:t,index:e,score:null!=o&&Number.isFinite(o)?1e6*o+un(t.labelText):un(t.labelText)+.01*i}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(W,n,r,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:q,ribbons:I.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:pn(t.pathD),bezier:yn(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:A,xScale:_}}var wn=require("react/jsx-runtime"),kn="var(--semiotic-grid, #94a3b8)",Sn="var(--semiotic-text-secondary, #475569)",An="var(--semiotic-text-secondary, #94a3b8)",Mn=.22;function _n(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var Pn=t=>{const{bands:e=[],ribbons:o=[],showLabels:i=!0,selectionDatum:n="raw"}=t.config,r=t.selection??null,s=[];for(const t of o){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},o=!_n(e,r,n);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:o?Math.min(t.opacity,Mn):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!_n({__kind:"band",data:t.rawDatum,id:t.id},r,n);for(let o=0;t.gradientStubs.length>o;o++){const i=t.gradientStubs[o];s.push({type:"bezier",pathD:i.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?Mn:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:i.x0,x1:i.x1,...null!=i.y0&&{y0:i.y0},...null!=i.y1&&{y1:i.y1},from:i.from,to:i.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${o}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),o={__kind:"band",data:t.rawDatum,id:t.id},i=!_n(o,r,n);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:i?Mn:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...i&&e?{opacity:Mn}:{}},datum:o})}const a=i?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),o=t.labelText.trim().length>0,i=e&&r?.isActive&&_n({__kind:"band",data:t.rawDatum,id:t.id},r,n),s=o?t.labelText:i?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function jn(t,e){if(!t)return[];const o=[],i=t=>{o.push(t);const n="function"==typeof e?e(t):t[e];n&&Array.isArray(n)&&n.forEach(i)};return i(t),o}function Ln(t,e,o,i){if(t&&t.length>0)return t;const n=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof i?i(t):t[i];n.add(e),n.add(r)}),Array.from(n).map(t=>({id:t}))}function $n(t,e,o={}){return ht(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var Rn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{if(!(e||Array.isArray(n.styleRules)&&n.styleRules.length>0||i.nodeStyle||n.nodeStyle||dt(Pt(n))))return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,showLabels:n.showLabels,colorBy:e,edgeColorBy:n.edgeColorBy,colorScheme:o,...i};const r=Array.isArray(n.edges)?n.edges:[],s=Array.isArray(n.nodes)&&n.nodes.length>0?n.nodes:Ln([],r,n.sourceAccessor||"source",n.targetAccessor||"target"),a=Ot(i.theme).colors.categorical,c=it(o,a),l="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?lt(u,l,o??i.colorScheme??a):void 0,h=new Map,f=n.nodeIdAccessor||n.nodeIDAccessor||"id",p=(t,o)=>{const i=t?.data||t;let r;if(e)r=at(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=vt(n.styleRules,e,n.valueAccessor);return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,showLabels:n.showLabels,colorBy:e,edgeColorBy:n.edgeColorBy,colorScheme:o,nodeStyle:ht(n.nodeStyle||(y?(t,e)=>({...p(t,e),...y(t,e)}):p),Pt(n)),...i}}},Cn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:o,edgeOpacity:i}=t,n=t.strokeWidth??1;return void 0!==e||void 0!==o||void 0!==i||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=n;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],o="number"==typeof t?t:Number(t);a=Number.isFinite(o)&&o>0?o:n}return{stroke:o??t.stroke??"#999",strokeWidth:a,opacity:i??t.opacity??.6}}:void 0}(n),s=Ot(i.theme).colors.categorical,a=new Map,c=n.nodeStyle??(t=>({fill:e?at(t?.data||t,e,void 0):qe(void 0,s,o,void 0,a),..."number"==typeof n.nodeSize&&{r:n.nodeSize}})),l=vt(n.styleRules,e,"number"==typeof n.nodeSize?void 0:n.nodeSize),u=ht(l?(t,e)=>({...c(t),...l(t,e)}):c,{stroke:n.nodeStroke??n.stroke,strokeWidth:n.nodeStrokeWidth??n.strokeWidth,opacity:n.opacity});return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:e,colorScheme:o,iterations:n.iterations,forceStrength:n.forceStrength,showLabels:n.showLabels??!1,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize??8,nodeSizeRange:n.nodeSizeRange,nodeStyle:u,edgeStyle:r,...i}}},In={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=Ot(i.theme).colors.categorical,s=new Map,a=jn(t??null,n.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?lt(l,u,o??i.colorScheme??r):void 0,h=i.nodeStyle||n.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,showLabels:n.showLabels,nodeLabel:n.showLabels??i.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},colorScheme:o,...i,nodeStyle:$n(t=>{const i=t?.data||t;return{fill:n.colorByDepth?rt[Number(t?.depth||0)%rt.length]:e?c?at({__ssrCirclePackColorBy:c(i)},"__ssrCirclePackColorBy",d??void 0):at(i,e,d??void 0):qe(void 0,r,o,void 0,s),fillOpacity:n.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,Pt(n))}}},Tn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=t??n.data,s=n.childrenAccessor||"children",a=n.nodeIdAccessor||n.nodeIDAccessor||"name",c=Ot(i.theme).colors.categorical,l=o??i.colorScheme??c,u=it(l,c),d=jn(r,s),h="__ssrOrbitColorBy",f="function"==typeof e?e:null,p=e?lt(f?d.map(t=>({[h]:f(t)})):d,f?h:e,l):void 0;return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:l,colorByDepth:n.colorByDepth??!1,nodeSize:n.nodeRadius??6,nodeLabel:n.showLabels?a:void 0,showLabels:n.showLabels??!1,orbitMode:n.orbitMode??"flat",orbitSize:n.orbitSize??2.95,orbitSpeed:n.speed??.25,orbitRevolution:n.revolution,orbitRevolutionStyle:n.revolutionStyle,orbitEccentricity:n.eccentricity??1,orbitShowRings:n.showRings??!0,orbitAnimated:!1,nodeStyle:ht(t=>{const o=t.data||t,i=Number(t.depth??0);return{fill:n.colorByDepth?0===i?u[0]:rt[i%rt.length]:e?f?at({[h]:f(o)},h,p):at(o,e,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===i?1:.85}},Pt(n)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...i}}},On={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,i,n)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=n.sourceAccessor||"source",a=n.targetAccessor||"target",c=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",u=n.startTimeAccessor||"startTime",d=n.endTimeAccessor||"endTime",h=n.systemInTimeAccessor,f=n.systemOutTimeAccessor,p=n.xExtentAccessor||"xExtent",y=n.groupBy,g=n.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],x=Array.isArray(n.edges)?n.edges:[],b=Array.isArray(n.nodes)?n.nodes:[],v=b.length>0?b:Ln([],x,s,a),w=[r(n.domain?.[0]),r(n.domain?.[1])],k=v.map(t=>{const e=m(l,t)+"",o=m(p,t),i=n.nodeLabel?m(n.nodeLabel,t):e,s={id:e,label:null==i?e:i+"",__raw:t},a=y?m(y,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),S=x.map((t,e)=>{const o=m(g,t),i={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(c,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(i.systemInTime=e)}if(f){const e=r(m(f,t));Number.isFinite(e)&&(i.systemOutTime=e)}return i}),[A,M]=i.size??[600,400],_=i.margin,P="vertical"===n.orientation?"vertical":"horizontal",j=function(t,e,o,i="horizontal"){return"vertical"===i?{top:t?38:e?28:16,right:24,bottom:24,left:o?72:24}:{top:t?30:e?24:8,right:80,bottom:o?28:8,left:80}}(!!i.title,!!n.showQualityReadout,Array.isArray(n.axisTicks)&&n.axisTicks.length>0,P),L={...j,..._},$=(i.showLegend??!!e)&&!!e,R=i.legendPosition??"right";$&&("right"===R?L.right=Math.max(L.right,140):"left"===R?L.left=Math.max(L.left,140):"top"===R?L.top=Math.max(L.top,50):"bottom"===R&&(L.bottom=Math.max(L.bottom,80)));const I=L,T=A-I.left-I.right,O=M-I.top-I.bottom,z=it(o,Ot(i.theme).colors.categorical,C),F="function"==typeof e?e:null,N=F?v.map(t=>({_cat:F(t)})):v,E=F?"_cat":"string"==typeof e?e:void 0,D=o??[...z],B=E?lt(N,E,D):null,W=new Map;for(const t of k)W.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&W.has(t)){const o=W.get(t);return F?at({_cat:F(o)},"_cat",B??void 0):at(o,"string"==typeof e?e:"id",B??void 0)}return z[o%z.length]},q=re($&&e?(()=>{const t=new Map;v.forEach((o,i)=>{const n=m(e,o),r=null==n?"":n+"";r&&!t.has(r)&&t.set(r,{label:r,color:Y(m(l,o)+"",i)})});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,i.legend),X=!1!==n.showLabels&&("auto"!==n.showLabels||"auto"),{layout:G,layoutConfig:V,issues:H,xScale:U}=vn({nodes:k,edges:S,domain:w,plotW:T,plotH:O,orientation:P,ribbonLane:n.ribbonLane||"both",ribbonMinRun:"auto"===n.ribbonMinRun||"number"==typeof n.ribbonMinRun?n.ribbonMinRun:0,edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:Y,showLabels:X,styleRules:n.styleRules,colorBy:e,valueAccessor:c,layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half",maxValueScale:"number"==typeof n.maxValueScale?n.maxValueScale:void 0,lanePlacement:n.lanePlacement||"stack",nodeSizing:n.nodeSizing||"temporal",groupPadding:"number"==typeof n.groupPadding?n.groupPadding:0}});if(H.length>0){const t=H.map(oi).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const K=G?function(t){const e=t.layout,o=t.nodes,i=t.orientation,n=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,c=t.showQualityReadout??!1,l=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,f=t.toTime,p=t.xScale,{centerlines:y,laneLifetime:g,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=e;let A=null,M=null;for(const t of o){const e=g[t.id];if(!e||null===e.start||null===e.end)continue;const o=p(e.start),i=p(e.end);(null===A||A>o)&&(A=o),(null===M||i>M)&&(M=i)}const _=t=>Math.max(0,Math.min(s,t)),P=_(A??0),j=Math.max(P,_(M??s)),L=a.map((t,e)=>({tick:t,index:e,coordinate:p(f(t.date))})).filter(({coordinate:t})=>t>=P-.5&&j+.5>=t),$=null!==(w??null)&&null!=k&&null!=S,R=c&&($||u.length>0)?(0,wn.jsxs)("g",{fill:An,fontSize:10,textAnchor:"end",children:[$&&(0,wn.jsxs)(wn.Fragment,{children:[(0,wn.jsxs)("text",{x:n,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),(0,wn.jsxs)("text",{x:n,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),u.map((t,e)=>(0,wn.jsxs)("text",{x:n,y:$?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,C=b?(0,wn.jsx)("text",{x:n,y:"vertical"===i?-3:2,fontSize:10,fill:An,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,I=(t,e)=>h?h(t,e):kn;return(0,wn.jsxs)("g","vertical"===i?{children:[R,C,L.map(({index:t,coordinate:e})=>(0,wn.jsx)("line",{x1:0,y1:e,x2:n,y2:e,stroke:kn,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const i=m[t.id],n=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(n.botPeak-n.topPeak)*x/2,s=p(o.start),a=p(o.end),c=I(t.id,e);return(0,wn.jsxs)("g",{children:[(0,wn.jsx)("line",{x1:r,y1:s,x2:r,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),(0,wn.jsx)("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:c,strokeOpacity:.5}),(0,wn.jsx)("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),(0,wn.jsx)("line",{x1:-4,y1:P,x2:-4,y2:j,stroke:kn}),L.map(({tick:t,index:e,coordinate:o})=>{const i=f(t.date),n=null!=t.label?t.label:d?d(new Date(i)):"";return(0,wn.jsxs)("g",{transform:`translate(-4,${o})`,children:[(0,wn.jsx)("line",{x2:-6,stroke:kn}),(0,wn.jsx)("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Sn,children:n})]},e)})]}:{children:[R,C,L.map(({index:t,coordinate:e})=>(0,wn.jsx)("line",{x1:e,y1:0,x2:e,y2:r,stroke:kn,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const i=m[t.id],n=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(n.botPeak-n.topPeak)*x/2,s=p(o.start),a=p(o.end),c=I(t.id,e);return(0,wn.jsxs)("g",{children:[(0,wn.jsx)("line",{x1:s,y1:r,x2:a,y2:r,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),(0,wn.jsx)("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:c,strokeOpacity:.5}),(0,wn.jsx)("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),(0,wn.jsx)("line",{x1:P,y1:r+4,x2:j,y2:r+4,stroke:kn}),L.map(({tick:t,index:e,coordinate:o})=>{const i=f(t.date),n=null!=t.label?t.label:d?d(new Date(i)):"";return(0,wn.jsxs)("g",{transform:`translate(${o},${r+4})`,children:[(0,wn.jsx)("line",{y2:6,stroke:kn}),(0,wn.jsx)("text",{y:20,textAnchor:"middle",fontSize:11,fill:Sn,children:n})]},e)})]})}({layout:G,nodes:k,orientation:P,plotW:T,plotH:O,timelineExtent:"vertical"===P?O:T,axisTicks:Array.isArray(n.axisTicks)?n.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!n.showQualityReadout,showLaneRails:!!n.showLaneRails,timeFormat:"function"==typeof n.timeFormat?t=>n.timeFormat(t):void 0,colorOf:Y,toTime:t=>r(t),xScale:t=>Number(U(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:Pn,layoutConfig:V,sourceAccessor:s,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:e,colorScheme:o,...K&&{backgroundGraphics:K},...i,showLegend:$,...q&&{legend:q,legendPosition:R},__legendIncludesAutomatic:!0,margin:I}}},zn={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,i,n)=>{const r=Array.isArray(n.nodes)?n.nodes:Ln([],Array.isArray(n.edges)?n.edges:[],n.sourceAccessor||"source",n.targetAccessor||"target"),s=Ot(i.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?lt(l,c,o??i.colorScheme??s):void 0,d=t=>({fill:e?at(t?.data||t,e,u):qe(void 0,s,o,void 0,a),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=vt(n.styleRules,e,n.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:i,edgeOpacity:n,baseStyle:r={}}){return s=>{const a={fillOpacity:n,...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=at(t.data||t,e,o):t&&(a.fill=i(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=at(t.data||t,e,o):t&&(a.fill=i(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*n);return a}}({edgeColorBy:n.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:f,edgeOpacity:n.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:e,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:ht(n.nodeStyle||f,Pt(n)),edgeStyle:ht(n.edgeStyle||p,Pt(n)),colorScheme:o,...i}}},Fn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=Ot(i.theme).colors.categorical,s=new Map,a=jn(t??null,n.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?lt(l,u,o??i.colorScheme??r):void 0,h=i.nodeStyle||n.nodeStyle;return{chartType:"cluster"===n.layout?"cluster":"tree",data:t,childrenAccessor:n.childrenAccessor,colorBy:e,colorByDepth:n.colorByDepth,orientation:n.orientation,showLabels:n.showLabels,nodeLabel:!1!==n.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,colorScheme:o,...i,nodeStyle:$n(t=>{const i=t?.data||t;return{fill:n.colorByDepth?rt[Number(t?.depth||0)%rt.length]:e?c?at({__ssrTreeColorBy:c(i)},"__ssrTreeColorBy",d??void 0):at(i,e,d??void 0):qe(void 0,r,o,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},h,Pt(n))}}},Nn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=Ot(i.theme).colors.categorical,s=new Map,a=jn(t??null,n.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?lt(l,u,o??i.colorScheme??r):void 0,h=n.showLabels??i.showLabels,f=n.labelMode,p=void 0!==n.paddingTop?n.paddingTop:i.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=i.nodeStyle||n.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,showLabels:n.showLabels,labelMode:f,nodeLabel:h?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...null!=y&&{paddingTop:y},colorScheme:o,...i,nodeStyle:$n(t=>{const i=t?.data||t;return{fill:n.colorByDepth?rt[Number(t?.depth||0)%rt.length]:e?c?at({__ssrTreemapColorBy:c(i)},"__ssrTreemapColorBy",d??void 0):at(i,e,d??void 0):qe(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},g,Pt(n))}}},En={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5},Dn=require("d3-scale");function Bn(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Wn={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r="string"==typeof o?o:"blues",s=function(t,e,o){if(!Array.isArray(t))return;const i=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let n=1/0,r=-1/0;for(const e of t){const t=i(e);null!=t&&isFinite(t)&&(n>t&&(n=t),t>r&&(r=t))}const s=[Number.isFinite(n)?n:0,Number.isFinite(r)?r:1],a=(0,Dn.scaleSequential)(G(o)).domain(s);return{domain:s,colorScale:t=>a(t),valueAccessor:i}}(n.areas,n.valueAccessor,r),a=n.areaStyle??function(t,e){if(t)return o=>{const i=t.valueAccessor(o);return{fill:null!=i&&isFinite(i)?t.colorScale(i):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:e}}}(s,n.areaOpacity??1),c=n.styleRules?bt(a,n.styleRules,t=>{return{value:(e=t,"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0)};var e},Bn):a,l=!1!==i.showLegend&&s?{gradient:{colorFn:s.colorScale,domain:s.domain,label:"string"==typeof n.valueAccessor?n.valueAccessor:"value"}}:void 0;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:c,valueAccessor:n.valueAccessor,colorScheme:r,graticule:n.graticule,fitPadding:n.fitPadding,...i,...void 0===i.legend&&l?{legend:l}:{}}}},Yn={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r=t||n.points,s=n.pointStyle??function(t,e,o,i){const n=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",i="string"==typeof e?n:n.map(t=>({...t,__geoColorBy:e(t)}));r=lt(i,t,o)}if(i.sizeBy){const t=n.map("function"==typeof i.sizeBy?i.sizeBy:t=>t?.[i.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=Nt(t))}return t=>({fill:e&&r?at(t,e,r):ot,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?ut(t,i.sizeBy,i.sizeRange,s):i.pointRadius??6})}(r,e,o,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=n.styleRules?bt(s,n.styleRules,yt(e,n.sizeBy)):s;return{points:r,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle||En,pointStyle:a,sizeBy:n.sizeBy,colorBy:e,colorScheme:o,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...i}}},qn={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r=(Array.isArray(t)?t:null)||n.flows||[],s=n.nodeIdAccessor||"id",a=n.valueAccessor||"value",c=n.xAccessor||"lon",l=n.yAccessor||"lat",u="function"==typeof c?c:t=>t[c],d="function"==typeof l?l:t=>t[l],h=(n.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=n.edgeColorBy??e,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),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",x=p?y?lt(g.map(t=>({[m]:p(t)})),m,o||"category10"):lt(g,p,o||"category10"):null,b=t=>p&&x?at(t,p,x):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[S,A]=n.edgeWidthRange??[1,8],M=A-S,_=n.edgeOpacity??.6,P=n.edgeLinecap??"round";return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle||En,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,i=S+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:b(t),strokeWidth:i,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...i}}},Xn=c(require("react"));function Gn(t){const[e,o]=t,i=160>e||116>o,n=i?Math.min(12,Math.max(2,.08*e)):32,r=i?Math.min(8,Math.max(2,.12*o)):24,s=i?r:34;return{width:e,height:o,plot:{x:n,y:r,width:Math.max(1,e-2*n),height:Math.max(1,o-r-s)}}}function Vn(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let t=0;e.length>t;t+=1)i=31*i+e.charCodeAt(t)>>>0;return o[i%o.length]}function Hn(t,e="#4e79a7",o){const i=o?.styleRules,n=!!i&&i.length>0,r=n?ft(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:Vn(a),stroke:"#111827",strokeWidth:1,opacity:.9};return n&&s&&Object.assign(c,xt(s,i,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function Un(t,e,o,i){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,...i}}}function Kn(t,e,o){return"function"==typeof o?o(t,e):t[o]}function Zn(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 Qn(t,e,o){return Math.max(e,Math.min(o,t))}function Jn(t,e){const o=Zn(t);return null!=o&&o>0?o:e}function tr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function er(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}}var or=require("d3-scale");function ir(t){let e=t>>>0;return function(){e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}var nr={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},rr=1e-9,sr=.005;function ar(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function cr(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 lr(t,e,o){return Math.max(e,Math.min(o,t))}function ur(t,e,o){return Math.min(t??o,e??o)}function dr(t,e,o){return lr(Math.max(t??o,e??o),0,1)}function hr(t){return 0>t?-1:1}function fr(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 pr(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 yr(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function gr(t,e,o,i,n,r,s,a){const c=n-t,l=(o+s)/2-Math.abs(c);if(0>=l)return null;const u=r-e,d=(i+a)/2-Math.abs(u);return d>0?d>l?{nx:hr(c),ny:0,penetration:l}:{nx:0,ny:hr(u),penetration:d}:null}function mr(t,e,o,i,n,r,s){const a=r/2,c=s/2,l=t-lr(t,i-a,i+a),u=e-lr(e,n-c,n+c),d=l*l+u*u;if(d>o*o)return null;if(rr>=d){const r=Math.abs(t-(i-a)),s=Math.abs(t-(i+a)),l=Math.abs(e-(n-c)),u=Math.abs(e-(n+c)),d=Math.min(r,s,l,u);return d===r?{nx:-1,ny:0,penetration:o+r}:d===s?{nx:1,ny:0,penetration:o+s}:d===l?{nx:0,ny:-1,penetration:o+l}:{nx:0,ny:1,penetration:o+u}}const h=Math.sqrt(d);return{nx:l/h,ny:u/h,penetration:o-h}}function xr(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,o,i,n,r){const s=i-t,a=n-e,c=o+r,l=s*s+a*a;if(l>=c*c)return null;if(rr>=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 gr(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=mr(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?mr(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function br(t,e){const o=e.shape;return"aabb"===o.type?"circle"===t.shape.type?mr(t.x,t.y,t.shape.radius,o.x,o.y,o.width,o.height):gr(o.x,o.y,o.width,o.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,o,i,n,r,s,a=0){const c=r-i,l=s-n,u=c*c+l*l,d=u>rr?lr(((t-i)*c+(e-n)*l)/u,0,1):0,h=o+a/2,f=t-(i+c*d),p=e-(n+l*d),y=f*f+p*p;if(y>=h*h)return null;if(rr>=y){const t=Math.sqrt(u);return t>rr?{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 vr(t,e){return`${t}\0${e}`}function wr(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function kr(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:ar(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function Sr(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 Ar(t){return{id:t.id,shape:cr(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:Sr(t.bodyFilter),index:t.index}}function Mr(t,e){return!!e?.some(e=>Object.is(t,e))}function _r(t,e){return function(t,e){if(!e)return!0;if("function"==typeof e)return e(t);const o=function(t,e){if(!e)return;let o=t;for(const t of e.split(".")){if(null==o||"object"!=typeof o)return;if(!Object.prototype.hasOwnProperty.call(o,t))return;o=o[t]}return o}(t,e.property);return!("equals"in e&&!Object.is(o,e.equals)||"notEquals"in e&&Object.is(o,e.notEquals)||e.oneOf&&!Mr(o,e.oneOf)||e.notOneOf&&Mr(o,e.notOneOf))}(e,t.bodyFilter)}var Pr=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={...nr,...t},this.random=ir(this.options.seed)}init(t={}){this.options={...nr,...t},this.random=ir(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(rr,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:ar(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))wr(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:cr(e.shape),bodyFilter:Sr(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 i=this.bodies.get(t);i&&(i.vx+=e/i.mass,i.vy+=o/i.mass,this.wake(i))}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 i=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,i>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>i){const o=i/e;t.vx*=o,t.vy*=o}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const n=this.bodyPairKeys(o),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(o,n,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:ar(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(wr)}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(kr),colliders:this.sortedColliders().map(Ar),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=ir(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=kr(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=Ar(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 i="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!i)continue;const n=i.x-o.x,r=i.y-o.y,s=Math.sqrt(n*n+r*r);if(rr>=s)continue;const a=n/s,c=r/s,l=(s-e.restLength)*e.stiffness+((("vx"in i?i.vx:0)-o.vx)*a+(("vy"in i?i.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 i of e){const[e,n]=i.split(":").map(Number),r=t[e],s=t[n];if(!r||!s)continue;const a=xr(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 i=0;t.length>i;i+=1){if(!1===t[i].bodyCollisions)continue;const n=fr(t[i]),r=Math.floor(n.minX/e),s=Math.floor(n.maxX/e),a=Math.floor(n.minY/e),c=Math.floor(n.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;c>=e;e+=1){const n=`${t}:${e}`,r=o.get(n);r?r.push(i):o.set(n,[i])}}const i=new Set;for(const e of Array.from(o.keys()).sort()){const n=o.get(e)??[];n.sort((t,e)=>t-e);for(let e=0;n.length>e;e+=1)for(let o=e+1;n.length>o;o+=1){const r=n[e],s=n[o];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&yr(fr(t[r]),fr(t[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((t,e)=>{const[o,i]=t.split(":").map(Number),[n,r]=e.split(":").map(Number);return o===n?i-r:o-n})}resolveDynamicCollision(t,e,o){t.sleeping&&this.contactOpposesGravity(o.nx,o.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-o.nx,-o.ny)&&this.supportedThisStep.add(t.id);const i=t.sleeping?0:1/t.mass,n=e.sleeping?0:1/e.mass,r=i+n;if(rr>=r)return;const s=Math.max(0,o.penetration-sr)/r;t.x-=o.nx*s*i,t.y-=o.ny*s*i,e.x+=o.nx*s*n,e.y+=o.ny*s*n;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+ur(t.restitution,e.restitution,this.options.restitution))*a/r,u=l*o.nx,d=l*o.ny;t.vx-=u*i,t.vy-=d*i,e.vx+=u*n,e.vy+=d*n,this.applyFriction(t,e,o,l,i,n),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,o,i,n,r){const s=-o.ny,a=o.nx,c=(e.vx-t.vx)*s+(e.vy-t.vy)*a,l=n+r;if(rr>=Math.abs(c)||rr>=l)return;const u=dr(t.friction,e.friction,this.options.friction),d=lr(-c/l,-i*u,i*u),h=d*s,f=d*a;t.vx-=h*n,t.vy-=f*n,e.vx+=h*r,e.vy+=f*r}resolveColliders(t,e,o){for(const i of t)for(const t of e){if(!_r(t,i))continue;if(!yr(fr(i),pr(t)))continue;const e=br(i,t);e&&(this.resolveStaticCollision(i,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(i.id),o&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,o){t.x+=o.nx*Math.max(0,o.penetration-sr),t.y+=o.ny*Math.max(0,o.penetration-sr);const i=t.vx*o.nx+t.vy*o.ny;if(0>i){const n=ur(t.restitution,e.restitution,this.options.restitution);t.vx-=(1+n)*i*o.nx,t.vy-=(1+n)*i*o.ny;const r=-o.ny,s=o.nx,a=t.vx*r+t.vy*s,c=dr(t.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 i of t){const t=fr(i);for(const n of o){if(!_r(n,i))continue;if(!yr(t,pr(n)))continue;if(!br(i,n))continue;const o=vr(n.id,i.id);e.add(o),this.activeSensors.has(o)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:n.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:o,bodyId:i}=wr(t);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:o})}this.activeSensors=e}updateSleeping(t,e){const o=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of t)Math.sqrt(i.vx*i.vx+i.vy*i.vy)>=this.options.sleepSpeed||Math.sqrt((i.x-i.prevX)*(i.x-i.prevX)+(i.y-i.prevY)*(i.y-i.prevY))>=this.options.sleepSpeed*e||o&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=e,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}contactOpposesGravity(t,e){const{x:o,y:i}=this.options.gravity,n=Math.hypot(o,i);return 1e-9>=n||-.2>(t*o+e*i)/n}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},jr=class{constructor(t={}){this.id="builtin",this.capabilities={...(new Pr).capabilities,engine:"builtin"},this.world=new Pr(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 Lr(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new jr(t)}(e)}var $r=["binId","targetBin","category","windowIndex","lane","group"];function Rr(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 Cr(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 Ir(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 Tr(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function Or(t,e,o){return"function"==typeof t?t(e,o):"string"==typeof t?Tr(e,t):void 0}function zr(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function Fr(t){const e=Cr(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:Cr(t.x),y:Cr(t.y),value:e}}var Nr=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=zr(Or(this.config.binAccessor,t,e))??function(t){for(const e of $r){const o=zr(Tr(t,e));if(o)return o}return"sediment"}(t),i=zr(Or(this.config.labelAccessor,t,e))??o,n=function(t,e,o){if("number"==typeof t)return t;const i="function"==typeof t?t(e,o):"string"==typeof t?Tr(e,t):1,n="number"==typeof i?i:Number(i);return Number.isFinite(n)?n:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(o);return s||(s={id:o,label:i,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=i,s.lastBodyId=t.id,s.lastDatum=t.datum,Rr(s.x,t.x),Rr(s.y,t.y),Rr(s.value,n),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Fr(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Fr)}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:Ir(e.x),y:Ir(e.y),value:Ir(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 Er(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var Dr={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Br={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Wr(t={},e=Br){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 Yr(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function qr(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 Xr(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function Gr(t){return{...Yr(t),sequence:t.sequence,spawnAt:t.spawnAt}}function Vr(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 Hr(t){return!1!==t&&{...t}}function Ur(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function Kr(t){return{...t,gravity:{...t.gravity}}}function Zr(t,e,o,i){if("circle"===t.shape.type){const n=t.x-e,r=t.y-o,s=t.shape.radius+i,a=n*n+r*r;return a>s*s?null:a}const n=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(o-t.y)-t.shape.height/2,0),s=n*n+r*r;return s>i*i?null:s}function Qr(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Jr(t,e={}){const{idPrefix:o="plot",includeFloor:i=!0,includeCeiling:n=!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 i&&l.push({id:o+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+c/2,width:t.width+2*a,height:c}}),n&&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 ts(t){const{idPrefix:e="bin",count:o,domainStart:i,domainStep:n,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(i+t*n);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=i+t*n,s=o+n;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}var es={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 os(t,e){const o={...t};for(const t of e)o[es[t]]++;return o}function is(t,e,o){const i=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:i,revisions:os(o,i)}}var ns=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=is({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=is(t,e,this.revisions);this.revisions=o.revisions,this.latest=o;for(const t of[...this.listeners])t();return o}},rs=require("d3-quadtree"),ss=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,o,i,n,r=0,s){const a=this.ensure(t,e);if(!a)return null;let c=null,l=1/0;const u=Math.max(0,s?.searchRadius??Math.max(0,r)+this.maxSearchRadius),d=i-u,h=i+u,f=n-u,p=n+u;return a.visit((t,e,a,u,y)=>{if(d>u||e>h||f>y||a>p)return!0;if(t.length)return!1;let g=t;for(;g;){const t=g.data;if(t&&(!s?.include||s.include(t))){const e=s?.distanceSquared?s.distanceSquared(t,i,n):Zr(t,i,n,Math.max(0,r));null!=e&&(l>e||e===l&&o.indexOf(t.id)>o.indexOf(c?.id??""))&&(c=t,l=e)}g=g.next}return!1}),c}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=(0,rs.quadtree)().x(t=>t.x).y(t=>t.y).addAll(o),this.revision=e,this.tree)}},as=["data","scene-geometry","data-paint","accessibility","evidence"],cs=["scene-geometry","data-paint","accessibility","evidence"],ls=["overlay","accessibility","evidence"],us=(t,e)=>({retainedData:t,invalidations:e}),ds=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],hs=["scene-geometry","data-paint","accessibility","evidence"],fs=[],ps={engine:us("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:us("preserve",hs),colliders:us("preserve",hs),sediment:us("preserve",hs),bodyBudget:us("preserve",ds),bodyLimit:us("preserve",ds),eviction:us("preserve",ds),fixedDt:us("preserve",fs),maxDeltaSeconds:us("preserve",fs),maxSubsteps:us("preserve",fs),settleStepLimit:us("preserve",fs),timeScale:us("preserve",fs),observation:us("preserve",fs)},ys=us("preserve",ds);function gs(t){let e="preserve";const o=new Set;for(const i of t){const t=ps[i]??ys;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}var ms=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function xs(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&ms.every(o=>t[o]===e[o])}function bs(t,e,o,i){return t||!e?"paused":o||!i?"running":"settled"}var vs=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 i=t.readState(this.scratch),n=this.speed*this.speed;let r=!0;for(const t of i)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=n){r=!1;break}this.seconds=r?this.seconds+Math.max(0,e):0}},ws=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new ss,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new ns,this.simulationState="settled",this.visible=!0,this.quiescence=new vs;const{bodyBudget:e,colliders:o,engine:i,kernel:n,observation:r,sediment:s,...a}=t;this.config={...Dr,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=i,this.observation=Wr(r),this.sediment=new Nr(s??!1),this.world=Lr(i,{fixedDt:this.config.fixedDt,...n}),this.quiescence.setKernelOptions(n),o&&this.world.setColliders(Vr(o))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(o=>"kernel"===o?!xs(t.kernel,e.kernel):t[o]!==e[o])}(t,this.configInput),{colliders:o,bodyBudget:i,engine:n,kernel:r,observation:s,sediment:a,...c}=t;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=Lr(n,t.options),this.world.restore(t),this.revision+=1}if(r&&!xs(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=Wr(s,this.observation)),this.sediment.updateConfig(a),o&&(this.world.setColliders(Vr(o)),this.revision+=1),this.configInput={...this.configInput,...t};const l=gs(e);this.updateResults.record({kind:"config",keys:e},l.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(Vr(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},gs(["colliders"]).invalidations)}enqueue(t,e){const o=Array.isArray(t)?t:[t],i=e?function(t,e={}){const o=qr(e.startAt)??0,i=e.pacing??"immediate";if("arrival"===i){const i=t.map((t,o)=>function(t,e,o){return"function"==typeof o?qr(o(t,e)):"string"==typeof o?qr(Xr(t,o)):qr(t.spawnAt)??qr(Xr(t,"arrivalTime"))??qr(Xr(t,"timestamp"))??qr(Xr(t,"time"))??qr(Xr(t,"eventTime"))}(t,o,e.timeAccessor)),n=i.filter(t=>null!=t),r=n.length>0?Math.min(...n):0,s=qr(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const n=i[e],s=null==n?0:Math.max(0,n-r);return{...Yr(t),spawnAt:o+s/a}})}if("object"==typeof i){const e=qr(i.ratePerSec);if(e&&e>0)return t.map((t,i)=>({...Yr(t),spawnAt:o+i/e}))}return t.map(t=>({...Yr(t),spawnAt:o}))}(o,{...e,startAt:e.startAt??this.elapsedSeconds}):o;for(const t of i)this.queue.push({...Yr(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Ur),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?as:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(Yr(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},as)}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?as:[])),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"},as)}tick(t){const e=this.revision,o=[],i=[],n=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,i,n,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(o,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),n.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,o.length),(u>0||o.length>0||i.length>0||n.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,o,i,n,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?o.length||i.length||n.length?as:cs:[]),d}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const o=this.revision,i=[],n=[],r=[],s=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,i,n,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(i,a);const c=this.observeBodyBudget(a),l=this.evictOverflow(a);n.push(...l.evicted),r.push(...l.sedimented),this.syncSimulationState(a),i.length>0&&this.quiescence.reset();const u=e?{spawned:i,evicted:n,sedimented:r,events:s,observations:a}:{spawned:i},{steps:d,budget:h}=function(t,e,o){let i,n=0;for(;e>n&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,o.observations),e.length>0){o.spawned.push(...e),i=t.observeBodyBudget(o.observations);const n=t.evictOverflow(o.observations);o.evicted?.push(...n.evicted),o.sedimented?.push(...n.sedimented)}t.step(t.fixedDt);const r=t.drainEvents();o.events&&(o.events.push(...r),t.observeKernelEvents(r,o.observations),t.observeSensorTransitions(o.observations)),n+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:n,budget:i}}(this.settleHost(),t,u),f=i.length+n.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,i,n,r,s,a??[],void 0,h??c);return this.updateResults.record({kind:"settle",count:d},this.revision===o?[]:f?as:cs),p}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:o=0,binWidth:i=24,gap:n=2,maxHeight:r=80,value:s="count",x:a}=e,c=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const l=Math.max(0,t[s]/c*r),u=a?.(t,e)??e*(i+n);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:o-l,width:i,height:l,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,o=0,i){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,o,i)}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:i,...n}=t,r={...n,timestamp:e??this.elapsedSeconds,chartType:o??this.observation.chartType,chartId:i??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?ls:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?ls:[])}remove(t){const e=new Set(t),o=new Set(this.liveBodyOrder),i=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const n=t.filter(t=>o.has(t)||i.has(t));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?as:[]),n}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},cs),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},cs)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},cs)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,o,i)=>t.applyImpulse(e,o,i),clear:()=>t.clear(),hitTest:(e,o,i)=>t.hitTest(e,o,i),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:Hr(this.bodyBudget),config:{...this.config,kernel:Kr(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Gr),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:Hr(t.bodyBudget??{}),kernel:Kr(t.world.options)},this.bodyBudget=Hr(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(Gr).sort(Ur),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??bs(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"},as)}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,i,n,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:o,events:n,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:i,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,o){if(0===e.length)return;const i=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=i.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 i=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===i.size&&0===e.size)return i;const n=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:i,bodyId:r}=Qr(e),s=o.observation.sensors[i],a=n.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:i,binId:s?.binId??i})};for(const t of Array.from(i).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())i.has(t)||r("exit",t);return i}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const o of t)e.has(Qr(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)),i=e+o,n=Er(t.bodyLimit),r=Er(t.engineMaxBodiesHint),s=function(t,e,o){if(!1===o)return;const i=Er(o?.warnAt);return null!=i?i:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(n,r,t.options),a=null==n?0:Math.max(0,e-n),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:i,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=bs(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:i}=function(t,e,o,i,n,r){const s={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===o)return s;const a=Math.max(0,Math.floor(i));if(!Number.isFinite(a))return s;const c=n.length-a;if(0>=c)return s;const l=function(t,e,o){if("sleeping-first"!==e)return o.slice();const i=new Map(t.readState().map(t=>[t.id,t.sleeping])),n=[],r=[];for(const t of o)i.get(t)?n.push(t):r.push(t);return[...n,...r]}(t,o,n),u=l.slice(0,c);if(0===u.length)return s;const d=function(t,e,o,i){const n=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of o){const o=n.get(t);if(!o)continue;const s=e.add(o);s&&(r.push(t),i.emit({type:"physics-sediment",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.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:n.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=i,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:o}}};var ks=require("d3-scale");function Ss(t){const{count:e,idPrefix:o,wallThickness:i,xScale:n,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const c=Math.min(r-1,a?.(e)??s),l=Math.max(1,r-c);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:n(e),y:c+l/2,width:i,height:l}}})}function As(t,e,o){const i=t.width/Math.max(1,e),n=Math.max(2,2*o),r=Math.min(.7*i,Math.max(3.2*n,n+8)),s=Math.max(1,Math.floor(r/n));return{laneWidth:i,tubeWidth:r,ballDiameter:n,perRow:s,centerX:e=>t.x+(e+.5)*i,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*n}}var Ms=require("d3-scale");function _s(t){if(Array.isArray(t)&&t.length>=2){const e=Zn(t[0]),o=Zn(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=Zn(e.x),i=Zn(e.y);return null!=o&&null!=i?{x:o,y:i}:null}return null}function Ps(t){return Array.isArray(t)?t.map(_s).filter(t=>null!=t):[]}function js(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:Qn(t.x,e.plot.x,e.plot.x+e.plot.width),y:Qn(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Ls(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 $s(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=Qn(e,0,1)*Ls(t);let i=0;for(let e=1;t.length>e;e+=1){const n=t[e-1],r=t[e],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(i+s>=o){const t=(o-i)/s;return{x:n.x+(r.x-n.x)*t,y:n.y+(r.y-n.y)*t}}i+=s}}return{...t[t.length-1]}}function Rs(t,e){const o=$s(t,Math.max(0,e-.02)),i=$s(t,Math.min(1,e+.02)),n=i.x-o.x,r=i.y-o.y,s=Math.hypot(n,r)||1;return{x:n/s,y:r/s}}function Cs(t,e,o){return Math.max(e,Math.min(o,t))}function Is(t,e,o,i,n,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:o,x2:i,y2:n,thickness:r.thickness??8}}}function Ts(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,o=t.y,i=t.width,n=t.height,{type:"aabb",x:e,y:o,width:i,height:n}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,o,i,n}function Os(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...Ts({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function zs(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}}var Fs=require("d3-scale");function Ns(t,e,o){return it(t,e,o)}function Es(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 i=0;for(let t=0;e.length>t;t++)i=31*i+e.charCodeAt(t)|0;return t[Math.abs(i)%t.length]??"#4e79a7"}}function Ds(t,e){const o=e.config??{},i=(e.sensors??[]).map(t=>({...t,sensor:!0})),n=[...e.colliders??[],...i],r=[...t.colliders??[],...o.colliders??[],...n];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function Bs(t){const e=Vs(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 Ws(t,e,o,i){return o?"function"==typeof o?o(t,e):t[o]??i:i}function Ys(t){return`gauntlet:${t}:core`}function qs(t,e){return`gauntlet:${t}:positive:${e}`}function Xs(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Gs={left:28,top:76,rightInset:30,thickness:8};function Vs(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Gs;const o=Math.max(1,Math.min(t.width,e)),i=Math.max(2,.04*t.width);return{left:i,top:Math.max(2,.08*e),rightInset:i,thickness:Math.max(1,Math.min(4,.04*o))}}function Hs(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Us(t,e,o,i){const n=Vs(i),r=Math.max(2,o+2),s=n.top+n.thickness/2+r,a=i.floorY-r,c=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:c(t,n.left+n.thickness/2+r,i.width-n.rightInset-n.thickness/2-r),y:c(e,s,a)}}function Ks(t,e,o=1){const i=[...t].sort((t,e)=>t.localeCompare(e)),n=Math.max(0,i.indexOf(e));return{angle:.82*-Math.PI+(i.length>1?n/(i.length-1):.5)*Math.PI*.64,index:n,radius:(48+n%2*6)*o}}function Zs(t,e,o){const i=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),n=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*i-8*r-1.2*t.delay-5*n))}function Qs(t){const e=function(t,e,o){const[i,n]=t,r=220>i||160>n,s=Math.round(.48*n),a=r?n-Math.max(3,Math.min(12,.1*n)):n-36,c=(e??[]).filter(t=>!1!==t.enabled),l=Math.max(1,c.length),u=.22*i,d=l>1?(.78*i-u)/(l-1):0,h=r?Math.max(Math.round(.12*i),.08*i+6):Math.max(Math.round(.14*i),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*n)):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*i))})),graveyardX:Math.round(i*(r?.72:.84)),graveyardY:a-4,height:n,routeY:s,socketX:Math.round(i*(r?.82:.92)),startX:h,width:i}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],i=new Map(o.map(t=>[t.id,t])),n=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,o,i,n){const r=Ws(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=i.map(t=>t.id),a=[...Ws(t,e,o.positiveAccessor,s)],c=[...Ws(t,e,o.negativeAccessor,[])].filter(t=>n.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ws(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ws(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ws(t,e,o.initialViability,100)}}(e,s,r,o,n);return{...a,viability:t.viability?.(a,{negativeProperties:n,positiveProperties:i})??Zs(a,i,n)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,i){const n=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(o),r=i?.(t,e,o)??{};return{...n,...r,startY:r.startY??r.routeY??n.startY,socketY:r.socketY??r.routeY??n.socketY,graveyardY:r.graveyardY??n.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,i,n,r,s){const a=Hs(o),c=Math.max(3,28*a),l=i.startX,u=i.startY+(i.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,i)??{},h=d.x??l,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},y=[{...d,id:Ys(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=Us(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 i=n.get(e);if(!i)continue;const r=Ks(t.activePositiveIds,e,a),s=i.radius??Math.max(2,10*a),c=Us(g.x+Math.cos(r.angle)*r.radius,g.y+Math.sin(r.angle)*r.radius,s,o);y.push({id:qs(t.id,e),x:c.x,y:c.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:i,sourceDatum:t.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:Ys(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...i.spring??{}}]})}return t.negativeIds.forEach((e,i)=>{const n=r.get(e);n&&y.push(function(t,e,o,i,n,r,s){const a=Hs(r),c=e.radius??Math.max(2,7.2*a),l=Us(i+(o%4*12-12)*a,n+(54+12*Math.floor(o/4))*a,c,r);return{id:Xs(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:Ys(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,n,i,g.x,g.y,o,d.spawnAt??t.startedAt))}),y}(o,r,e,s,i,n,t.coreBody)});return{layout:e,states:s,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:Bs(e)}}}function Js(t=[]){const e=Object.create(null);for(const[o,i]of t)e[o]=i;return e}function ta(...t){const e=Js();for(const o of t)for(const[t,i]of Object.entries(o??{}))e[t]=i;return e}function ea(t){return ta(t)}function oa(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 ia(t){const e=Js(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:ea(e.initialMetrics),metrics:ea(e.metrics),productIds:[...e.productIds],history:oa(e.history)}])),o=Js(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:ea(e.metrics),sourceIds:[...e.sourceIds],history:oa(e.history)}])),i=Js(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?ea(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:i,input:{amount:t.input.amount,metrics:ea(t.input.metrics)},metrics:ea(t.metrics),loss:{amount:t.loss.amount,metrics:ea(t.loss.metrics)},history:oa(t.history)}}var na=1e-9;function ra(t,e){return e>t?-1:t>e?1:0}function sa(t,e,o,i,n){return{severity:t,code:e,message:o,path:i,ids:n?[...n]:void 0}}function aa(t){const e=new Set,o=new Set;for(const i of t)e.has(i)&&o.add(i),e.add(i);return[...o].sort(ra)}function ca(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[sa("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function la(t,e){for(const[o,i]of Object.entries(e))t[o]=Number(t[o]??0)+i}function ua(t,e,o="selector"){const i=[],n=Object.values(t.components),r=new Set(n.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&i.push(sa("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||i.push(sa("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),i.some(t=>"error"===t.severity))return{ids:[],diagnostics:i};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=n.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(ra);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||i.push(sa("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:i}}function da(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 ha(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 fa(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(sa("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function pa(t,e,o){const i=aa(e);e.length||t.diagnostics.push(sa("error","empty-source-list","A product requires at least one source component.",o)),i.length&&t.diagnostics.push(sa("error","duplicate-source",`Source ids may appear only once: ${i.join(", ")}.`,o,i));const n=e.filter(e=>!t.state.components[e]);n.length&&t.diagnostics.push(sa("error","unknown-component",`Unknown source component id${1===n.length?"":"s"}: ${n.join(", ")}.`,o,n));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(sa("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(sa("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 ya(t,e,o,i,n){const r=i?.amount??0;(!Number.isFinite(r)||0>r||r>e+na)&&t.diagnostics.push(sa("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",n+".amount")),t.diagnostics.push(...ca(i?.metrics,n+".metrics"));for(const[e,r]of Object.entries(i?.metrics??{}))(0>r||r>Number(o[e]??0)+na)&&t.diagnostics.push(sa("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${n}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function ga(t,e,o,i,n,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?ta(i,t.metrics):ea(i),status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(n.outletIds.has("product")?"product":void 0):void 0,createdByEventId:n.event.id,createdAt:n.context.appliedAt,completedByEventId:r?n.event.id:void 0,completedAt:r?n.context.appliedAt:void 0,history:[s]}}function ma(t,e,o,i){void 0!==e.amount&&Math.abs(e.amount-o)>na&&t.diagnostics.push(sa("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,i,[e.id]))}function xa(t,e,o){const i=`events.${t.event.id}.effects.${o}`,n=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(sa("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,i+".state")),t.diagnostics.push(...ca(e.metricsDelta,i+".metricsDelta")),fa(t,e.outletId,i+".outletId");const o=ua(n,e.select,i+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>n.components[t].productIds.length);if(r.length&&t.diagnostics.push(sa("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,i+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=da(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=n.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&la(o.metrics,e.metricsDelta),o.history.push(s)}return n.history.push(s),void(o.ids.length&&ha(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&&!n.relations[o.id]||t.diagnostics.push(sa("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,i+".relation.id",[o.id]));const r=function(t,e,o){const i=aa(e),n=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(sa("error","insufficient-relation-sources","A relation requires at least two source components.",o)),i.length&&t.diagnostics.push(sa("error","duplicate-source",`Relation source ids must be unique: ${i.join(", ")}.`,o,i)),n.length&&t.diagnostics.push(sa("error","unknown-component",`Relation references unknown source component${1===n.length?"":"s"}: ${n.join(", ")}.`,o,n)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,i+".relation.sourceIds");if(t.diagnostics.push(...ca(o.metrics,i+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;n.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?ea(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=da(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return n.history.push(s),void ha(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=aa(e.relationIds),r=e.relationIds.filter(t=>!n.relations[t]),s=e.relationIds.filter(t=>"resolved"===n.relations[t]?.status);if(o.length&&t.diagnostics.push(sa("error","duplicate-relation","Relation ids must be unique.",i+".relationIds",o)),r.length&&t.diagnostics.push(sa("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,i+".relationIds",r)),s.length&&t.diagnostics.push(sa("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,i+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const i=n.relations[o];i.status="resolved",i.resolution=e.resolution,i.resolvedByEventId=t.event.id,i.resolvedAt=t.context.appliedAt,i.reason=e.reason}const a=da(t,e,{relationIds:[...e.relationIds]});return n.history.push(a),void ha(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(sa("error","unknown-product",`Product "${e.productId}" has no declared mold.`,i+".productId",[e.productId]));const r=n.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(sa("error","duplicate-product",`Product "${e.productId}" has already been formed.`,i+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(sa("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,i+".productId",[e.productId]));const s=pa(t,e.sourceIds,i+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,c=function(t,e,o,i){if(!e?.length)return[];const n=aa(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 n.length&&t.diagnostics.push(sa("error","duplicate-relation","Basis relations must be unique.",i,n)),r.length&&t.diagnostics.push(sa("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,i,r)),s.length&&t.diagnostics.push(sa("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,i,s)),c.length&&t.diagnostics.push(sa("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,i,c)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,i+".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=Js();for(const o of t)la(e,o.metrics);return e}(s);if(!ya(t,l,u,e.loss,i+".loss"))return;const d=l-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[i,n]of Object.entries(o?.metrics??{}))e[i]=Number(e[i]??0)-n,t.state.loss.metrics[i]=Number(t.state.loss.metrics[i]??0)+n}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=da(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&ma(t,o,d,i+".productId"),p=ga(o,e.sourceIds,d,u,t,h,f),h&&!fa(t,p.outletId,i+".productId"))return;n.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,la(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 n.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;ha(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,c),ha(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&&ha(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const o=n.products[e.productId];return o?void function(t,e,o,i,n,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!fa(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(sa("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(ma(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=ta(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=i,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const c=da(t,n,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(c),t.state.history.push(c),ha(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,i):void t.diagnostics.push(sa("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,i+".productId",[e.productId]))}if("split"===e.type){const o=pa(t,[e.sourceId],i+".sourceId");e.products.length||t.diagnostics.push(sa("error","empty-split","A split requires at least one product allocation.",i+".products"));const r=e.products.map(t=>t.productId),s=aa(r);s.length&&t.diagnostics.push(sa("error","duplicate-product","Split product ids must be unique.",i+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),c=r.filter((t,e)=>!a[e]),l=r.filter(t=>n.products[t]);c.length&&t.diagnostics.push(sa("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,i+".products",c)),l.length&&t.diagnostics.push(sa("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,i+".products",l));for(const[o,n]of e.products.entries())void 0===n.amount||Number.isFinite(n.amount)&&n.amount>=0||t.diagnostics.push(sa("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${i}.products.${o}.amount`)),t.diagnostics.push(...ca(n.metrics,`${i}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!ya(t,u.amount,u.metrics,e.loss,i+".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(sa("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",i+".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)>na)return void t.diagnostics.push(sa("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,i+".products"));const g=ea(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))g[t]=Number(g[t]??0)-o;const m=da(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],c=d>na?p[r]/d:1/e.products.length,l=Js(Object.entries(g).map(([t,e])=>[t,e*c])),h=o.metrics??s.metrics??l,f=ga({...s,amount:p[r],metrics:h},[u.id],p[r],ea(h),t,!0,m);fa(t,f.outletId,`${i}.products.${r}.productId`)&&(n.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),n.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))n.loss.metrics[t]=Number(n.loss.metrics[t]??0)+o;n.history.push(m),ha(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)ha(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:n.products[e].outletId?[n.products[e].outletId]:void 0});return}if("eject"===e.type){fa(t,e.outletId,i+".outletId");const o=ua(n,e.select,i+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>n.components[t].productIds.length);if(r.length&&t.diagnostics.push(sa("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,i+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=da(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=n.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return n.history.push(s),void(o.ids.length&&ha(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...ca(e.metricsDelta,i+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)la(n.metrics,e.metricsDelta);else if("components"in e.target){const r=ua(n,e.target.components,i+".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)la(n.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=aa(r),s=r.filter(t=>!n.products[t]);if(o.length&&t.diagnostics.push(sa("error","duplicate-product","Metric target product ids must be unique.",i+".target.productIds",o)),s.length&&t.diagnostics.push(sa("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,i+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)la(n.products[t].metrics,e.metricsDelta)}return void n.history.push(da(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(n.outcome=e.outcome,n.summary=e.summary,n.history.push(da(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(sa("error","invalid-outcome","Outcome must be a non-empty string.",i+".outcome"))}function ba(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[sa("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const i=ia(t),n={state:i,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,i]of e.effects.entries())if(xa(n,i,o),n.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:n.diagnostics};return i.elapsed=Math.max(i.elapsed,o.appliedAt),i.phaseId=o.phaseId,i.eventsApplied.push(e.id),n.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:i,materializations:n.materializations,observations:n.observations,diagnostics:n.diagnostics}}var va=[900,520],wa=[{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}],ka=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Sa=1e-9;function Aa(t,e){return e>t?-1:t>e?1:0}function Ma(t,e,o,i,n){return{severity:t,code:e,message:o,path:i,ids:n?[...n]:void 0}}function _a(t){const e=new Set,o=new Set;for(const i of t)e.has(i)&&o.add(i),e.add(i);return[...o].sort(Aa)}function Pa(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function ja(t,e,o,i,n,r){if(!o)return i;try{return("function"==typeof o?o(t,e):t[o])??i}catch(t){return n.push(Ma("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),i}}function La(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(Ma("error","invalid-metrics","Metrics must be a numeric object.",o)),Js();const i=Js();for(const[n,r]of Object.entries(t)){const t=Pa(r);null!=t?i[n]=t:e.push(Ma("error","invalid-metric",`Metric "${n}" must be finite.`,`${o}.${n}`))}return i}function $a(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 Ra(t){const{id:e,orientation:o,fixed:i,start:n,end:r,openings:s,thickness:a,friction:c,restitution:l}=t,u=function(t,e,o){const i=o.map(([o,i])=>[Math.max(t,Math.min(o,i)),Math.min(e,Math.max(o,i))]).filter(([t,e])=>e>t+Sa).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),n=[];let r=t;for(const[t,e]of i)t>r+Sa&&n.push([r,t]),r=Math.max(r,e);return e>r+Sa&&n.push([r,e]),n}(n,r,s);return u.map(([t,n],r)=>({id:1===u.length?e:`${e}:${r}`,friction:c,restitution:l,shape:"horizontal"===o?{type:"segment",x1:t,y1:i,x2:n,y2:i,thickness:a}:{type:"segment",x1:i,y1:t,x2:i,y2:n,thickness:a}}))}function Ca(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 Ia(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Ca(t):1}function Ta(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Ia(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Oa(t){return"crucible:component:"+encodeURIComponent(t)}function za(t,e,o,i){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const n=Math.min(...e,t),r=Math.max(...e,t);return r-n>Sa?i[0]+(i[1]-i[0])*Math.sqrt(Math.max(0,t-n)/(r-n)):(i[0]+i[1])/2}function Fa(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),i=t?.[0]??7*o,n=t?.[1]??18*o,r=Math.max(1,Math.min(i,n));return[r,Math.max(r,Math.max(i,n))]}function Na(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)))))),i=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,n)=>({x:e.x+e.width/o*(n%o+.5),y:e.y+(Math.floor(n/o)+.5)*(e.height/i)}))}function Ea(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 Da(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 Ba(t,e,o={}){const i=Object.values(t.products).sort((t,e)=>Aa(t.id,e.id)),n=Object.values(t.components).sort((t,e)=>Aa(t.id,e.id)),r=[...n.map(t=>t.amount),...i.map(t=>t.amount)],s=Fa(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",i=o.get(t)??[];i.push(e),o.set(t,i)}const i=new Map;for(const[t,n]of o){n.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||Aa(t.id,e.id));const o=Na(n.length,Da(e,"__chamber__"===t?void 0:t));n.forEach((t,e)=>i.set(t.id,o[e]))}return i}(i,e),c=i.map(t=>{const i=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},n=1.28*za(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:i.x,y:i.y,mass:Math.max(.25,n*n*.018),bodyCollisions:!1,shape:{type:"circle",radius:n},datum:c};var l}),l=new Map;for(const t of n.filter(t=>!t.productIds.length)){const e=Ea(t)??"__chamber__",o=l.get(e)??[];o.push(t),l.set(e,o)}const u=new Map;for(const[t,o]of l){const i=Na(o.length,Da(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,i[e]))}return[...n.map(t=>{let i=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){i={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const n=Ca(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));i={x:i.x+Math.cos(n)*r,y:i.y+Math.sin(n)*r}}}i??(i={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const n=za(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Oa(t.id),x:i.x,y:i.y,mass:Math.max(.25,n*n*.015),shape:{type:"circle",radius:n},datum:c}}),...c]}var Wa=Ba;function Ya(t){return Array.isArray(t)?t.map(Ya):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>Aa(t,e)).map(([t,e])=>[t,Ya(e)])):t}function qa(t,e=t.duration){const o=function(t,e){const o=Pa(e)??0,i=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:i,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const n=i>=t.duration-Sa,r=n?t.phases[t.phases.length-1]:t.phases.find(t=>i>=t.start&&t.end>i)??t.phases[0];return{elapsed:i,phaseId:r.id,phaseIndex:r.index,phaseElapsed:n?r.duration:Math.max(0,i-r.start),complete:n}}(t,e);let i=ia(t.initialState);const n=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+Sa)break;const a=ba(i,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});n.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(i=a.state)}return i.elapsed=o.elapsed,i.phaseId=o.phaseId,i.phaseIndex=o.phaseIndex,i.phaseElapsed=o.phaseElapsed,i.complete=o.complete,o.complete&&"in_process"===i.outcome&&(i.outcome="complete"),i.playing=!1,{state:i,diagnostics:n,materializations:r,observations:s}}function Xa(t){const e=function(t){const e=[];t.length||e.push(Ma("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=_a(t.map(t=>t.id));o.length&&e.push(Ma("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let i=0;return{phases:t.map((t,o)=>{const n=Pa(t.duration),r=null!=n&&n>0?n:0;t.id.trim()||e.push(Ma("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=n&&n>0||e.push(Ma("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(Ma("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:i,end:i+r};return i=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,i=$a(t.outlets??wa),n=(t.products??[]).map(t=>({...t,metrics:t.metrics?ta(t.metrics):void 0})),r=function(t,e,o){const i=[],n=_a(t.map(t=>t.id));n.length&&i.push(Ma("error","duplicate-event-id",`Event ids must be unique: ${n.join(", ")}.`,"events",n));const r=[];return t.forEach((t,n)=>{let s,a,c;if(t.id.trim()||i.push(Ma("error","invalid-event-id","Event ids may not be empty.",`events.${n}.id`)),"time"in t.at&&void 0!==t.at.time){const r=Pa(t.at.time);if(null==r||0>r||r>o+Sa)return void i.push(Ma("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${n}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const l=function(t,e,o){const i=t.find(t=>Sa>=Math.abs(t.start-o));if(i)return{phase:i,boundaryRank:1};const n=t.find(t=>o>=t.start&&t.end>o);return n?{phase:n,boundaryRank:0}:Sa>=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 i.push(Ma("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${n}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void i.push(Ma("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${n}.at.progress`,[t.id]));s=a.start+a.duration*o,c=0===o?1:0}a?r.push({...t,index:n,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):i.push(Ma("error","event-without-phase","Event could not be assigned to a phase.",`events.${n}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:i}}(t.events??[],e.phases,o),s=function(t){const e=[],o=Js(),i=[];let n=0;const r=Js();t.data.forEach((s,a)=>{const c=(s.id??"component-"+a)+"",l=((ja(s,a,t.idAccessor,c,e,`data.${a}.id`)??c)+"").trim();if(!l)return void e.push(Ma("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));i.push(l);const u=Pa(ja(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(Ma("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=La(ja(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=ja(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=ka.has(f)?f:"active";ka.has(f)||e.push(Ma("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[l]));const y=ja(s,a,t.labelAccessor,(s.label??s.name??l)+"",e,`data.${a}.label`)+"",g=ja(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,l)||(o[l]={id:l,label:y,category:g,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:ta(h),metrics:ta(h),productIds:[],history:[]},n+=d,function(t,e){for(const[o,i]of Object.entries(e))t[o]=Number(t[o]??0)+i}(r,h))});const s=_a(i);s.length&&e.push(Ma("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=La(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:Js(),relations:Js(),input:{amount:n,metrics:r},metrics:a,loss:{amount:0,metrics:Js()},history:[]},diagnostics:e}}(t),a=function(t=va,e=wa){const o=Math.max(1,Pa(t[0])??900),i=Math.max(1,Pa(t[1])??520),n=360>o||260>i,r=n?Math.max(4,.035*Math.min(o,i)):20,s=n?Math.max(10,.075*i):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},c=n?Math.max(16,.14*i):Math.min(78,.16*i),l={x:r,y:i-r-c,width:Math.max(1,o-2*r),height:c},u=n?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(n?12:38),h=l.y-(n?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,n?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(n?10:24),width:p,height:n?12:28},g=$a(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"))},x=[],b=(t,e)=>{const i=Math.max(8,u-1.5*r),s=f.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-i,y:f.y+a*s,width:i,height:Math.max(8,s-(n?2:8))})})};b("left",m.left),b("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:f.x+e*v,y:f.y+f.height+(n?2:7),width:Math.max(8,v-(n?2:8)),height:Math.max(8,l.y-f.y-f.height-(n?4:12))})}),x.sort((t,e)=>g.findIndex(e=>e.id===t.id)-g.findIndex(t=>t.id===e.id)),{width:o,height:i,phaseRail:a,chamber:f,mouth:y,projection:l,outlets:x}}(t.size??va,i),c=function(t){const{chamber:e,mouth:o}=t,i=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),n=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:n,y2:e.y,thickness:i}},{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:i}}];a.push(...Ra({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:i,friction:.46,restitution:.12}),...Ra({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:i,friction:.46,restitution:.12}),...Ra({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:i,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=[],i=new Set(e.map(t=>t.id)),n=_a(e.map(t=>t.id)),r=_a(t.map(t=>t.id));return n.length&&o.push(Ma("error","duplicate-outlet-id",`Outlet ids must be unique: ${n.join(", ")}.`,"outlets",n)),r.length&&o.push(Ma("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(Ma("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(Ma("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(Ma("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(Ma("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||i.has(t.outletId)||o.push(Ma("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),La(t.metrics??{},o,`products.${e}.metrics`)}),o}(n,i),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>Aa(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:i,intensity:n,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:i,intensity:n,motion:r,color:s,metrics:a})),products:n,outlets:i,events:r.events.map(({id:t,label:e,description:o,summary:i,authoredAt:n,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:i,authoredAt:n,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(Ya(d)));var d;const h=function(t,e,o={}){const i=Object.values(t.components).sort((t,e)=>Aa(t.id,e.id)),n=i.map(t=>t.amount),r=Fa(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}}(Ia(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 i.map((t,e)=>{const d=e/Math.max(1,i.length)*Math.PI*2+.18*(s()-.5),h=za(t.amount,n,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Oa(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:n,outlets:i,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:c,config:Ta(t.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},y=qa(p),g=Object.values(y.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=g.length?[Ma("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=Wa(y.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...y.diagnostics,...m],p}var Ga=c(require("react")),Va=require("d3-shape");function Ha(t){switch(t){case"monotoneX":return Va.curveMonotoneX;case"monotoneY":return Va.curveMonotoneY;case"cardinal":return Va.curveCardinal;case"catmullRom":return Va.curveCatmullRom;case"step":return Va.curveStep;case"stepBefore":return Va.curveStepBefore;case"stepAfter":return Va.curveStepAfter;case"basis":return Va.curveBasis;case"natural":return Va.curveNatural;default:return null}}var Ua=require("react/jsx-runtime");function Ka(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 Za(t,e,o,i){const n=t.datum;if(!n?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===n.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=i?`${i}-crucible-body-${o}`:"crucible-body-"+o;if("product"===n.kind){const e=Array.from({length:6},(e,o)=>{const i=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(i)*r},${t.y+Math.sin(i)*r}`}).join(" "),o=u+"-glow";return(0,Ua.jsxs)(Ga.Fragment,{children:[(0,Ua.jsx)("defs",{children:(0,Ua.jsx)("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:(0,Ua.jsx)("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),(0,Ua.jsx)("polygon",{points:e,fill:s,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),(0,Ua.jsx)("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:c,opacity:.72*l})]},u)}return(0,Ua.jsxs)(Ga.Fragment,{children:[(0,Ua.jsx)("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:c,opacity:l}),(0,Ua.jsx)("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)}var Qa=require("react/jsx-runtime"),Ja="var(--semiotic-text, #26323a)",tc="var(--semiotic-text-secondary, #6c7377)",ec="var(--semiotic-primary, #b8792d)",oc="var(--semiotic-danger, #9f3d35)",ic="var(--semiotic-success, #356b63)";function nc(t){const{x:e,y:o,width:i,height:n}=t.chamber,r=Math.min(.14*i,48),s=o+n;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*n}`,`Q ${e+i/2} ${s+.1*n} ${e+i-r} ${s-.16*n}`,`L ${e+i} ${o}`].join(" ")}function rc({layout:t,phases:e,state:o,compact:i=!1}){const n=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return(0,Qa.jsxs)("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[(0,Qa.jsxs)("defs",{children:[(0,Qa.jsxs)("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,Qa.jsx)("stop",{offset:"0",stopColor:ec,stopOpacity:"0.03"}),(0,Qa.jsx)("stop",{offset:"0.66",stopColor:ec,stopOpacity:"0.1"}),(0,Qa.jsx)("stop",{offset:"1",stopColor:oc,stopOpacity:"0.18"})]}),(0,Qa.jsx)("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:(0,Qa.jsx)("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Ja,strokeOpacity:"0.08",strokeWidth:"1"})})]}),(0,Qa.jsx)("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:Ja,strokeOpacity:"0.52",strokeWidth:i?1:2.2}),(0,Qa.jsx)("path",{d:nc(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),(0,Qa.jsx)("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Ja,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:i?2:5}),i?null:(0,Qa.jsx)("g",{"data-testid":"crucible-phase-rail",children:e.map((i,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/n*t.phaseRail.width,c=Math.max(0,i.duration)/n*t.phaseRail.width,l=i.id===o.phaseId,u=o.phaseIndex>r||o.complete;return(0,Qa.jsxs)("g",{children:[(0,Qa.jsx)("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,c-2),height:t.phaseRail.height,rx:2,fill:l?i.color??ec:u?ic:Ja,fillOpacity:l?.68:u?.28:.09}),46>c?null:(0,Qa.jsx)("text",{x:a+c/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:l?Ja:tc,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(i.label??i.id).toUpperCase()})]},i.id)})}),t.outlets.map(t=>(0,Qa.jsxs)("g",{children:[(0,Qa.jsx)("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?oc:ic),fillOpacity:"0.1",stroke:t.color??("left"===t.side?oc:ic),strokeDasharray:"3 3",strokeOpacity:"0.62"}),i?null:(0,Qa.jsx)("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:tc,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function sc({rows:t,layout:e,projection:o,amountLabel:i}){if(!t.length)return null;const n=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,n))),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(0,Qa.jsx)("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(0,Qa.jsxs)("g",{children:[(0,Qa.jsx)("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?oc:"complete"===t.status?ec:ic,fillOpacity:"0.68"}),c>4&&a>=34?(0,Qa.jsxs)(Qa.Fragment,{children:[(0,Qa.jsx)("text",{x:h+.32*a,y:e.projection.y+l+10,fill:tc,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),(0,Qa.jsxs)("text",{x:h+.32*a,y:e.projection.y+l+19,fill:Ja,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Ka(u),"amount"===n&&i?" "+i:""]})]}):null]},t.key)})})}function ac(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}var cc=require("react/jsx-runtime");function lc(t,e,o,i,n){const r=Array.isArray(n)?n:n?[n]:[];if(!1!==o||0!==r.length)return({size:n})=>{const s=[Number(n[0])||700,Number(n[1])||420],a=Gn(s),c=Math.max(2,Math.round(e)),l=a.plot.width/c,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[f,p]=i?.valueExtent??[0,c],y=p===f?1:p-f,g=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*l).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return(0,cc.jsxs)("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:s[0],height:s[1],viewBox:`0 0 ${s[0]} ${s[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?(0,cc.jsxs)(cc.Fragment,{children:[Array.from({length:c+1},(t,e)=>{const o=a.plot.x+e*l;return(0,cc.jsx)("line",{"data-testid":"galton-board-bin-wall",x1:o,x2:o,y1:a.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+e)}),(0,cc.jsx)("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),(0,cc.jsx)("path",{d:g,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?(0,cc.jsx)("text",{x:a.plot.x+(e+.5)*l,y:Math.max(a.plot.y+10,u-t.value/d*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.value},`${t.label}-${e}`):null)]}):null,r.map((t,e)=>{const o=Number(t.value);if(!Number.isFinite(o))return null;const i=a.plot.x+Math.max(0,Math.min(1,(o-f)/y))*a.plot.width,n=t.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===t.labelPosition?Math.min(s[1]-8,u+16):a.plot.y+16;return(0,cc.jsxs)("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[(0,cc.jsx)("line",{x1:i,x2:i,y1:a.plot.y+8,y2:u-4,stroke:n,strokeDasharray:t.strokeDasharray??"6 5",strokeWidth:t.strokeWidth??2}),null==t.label?null:(0,cc.jsx)("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:r,fill:n,fontSize:10,fontWeight:700,children:t.label})]},`galton-reference-${e}-${o}`)})]})}}function uc(t,e,o){if(!1!==o&&e)return({size:o})=>{const i=[Number(o[0])||760,Number(o[1])||360],n=Gn(i),r=Math.max(1,e.windowCount),s=e.plot??n.plot,a=e.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=e.windowPlot??s,l=c.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,f=e.windowStart,p=e.windowStart+r*e.windowSize,y=c.x+Math.max(0,Math.min(1,p===f?0:(e.watermarkValue-f)/(p-f)))*c.width;return(0,cc.jsxs)("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,cc.jsx)("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),a.width>0?(0,cc.jsxs)("g",{children:[(0,cc.jsx)("rect",{x:a.x,y:h,width:a.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),(0,cc.jsx)("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(o,n)=>{const r=t[n],s=c.x+n*l,a=e.closedWindowCount>n,h=r?.secondary??0;return(0,cc.jsxs)("g",{children:[(0,cc.jsx)("rect",{x:s,y:d,width:l,height:u-d,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?e.lidSegments.filter(t=>t.windowIndex===n).map(t=>(0,cc.jsx)("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},t.id)):null,(0,cc.jsxs)("text",{x:s+l/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),(0,cc.jsx)("text",{x:s+l/2,y:Math.min(i[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+n)}),e.lidSegments.filter(t=>null==t.windowIndex).map(t=>(0,cc.jsx)("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},t.id)),(0,cc.jsx)("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),(0,cc.jsx)("line",{"data-testid":"event-drop-watermark",x1:y,x2:y,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),(0,cc.jsxs)("text",{x:Math.min(s.x+s.width-4,y+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*e.watermarkValue)/100]}),e.lateCount>0?(0,cc.jsxs)("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[e.lateCount," late"]}):null]})}}function dc(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const i=[Number(o[0])||700,Number(o[1])||380],n=Gn(i),r=As(n.plot,t.length,e),s=n.plot.y+n.plot.height;return(0,cc.jsxs)("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,cc.jsx)("line",{x1:n.plot.x,x2:n.plot.x+n.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),t.map((t,e)=>{const o=Math.min(n.plot.height,r.pileHeight(t.value)),a=r.tubeWidth,c=r.centerX(e),l=s-o;return(0,cc.jsxs)("g",{children:[(0,cc.jsx)("rect",{x:c-a/2,y:l,width:a,height:o,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),(0,cc.jsx)("text",{x:c,y:Math.max(n.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),(0,cc.jsx)("text",{x:c,y:Math.min(i[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${e}`)})]})}}function hc(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function fc(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],i=Gn(o),n=i.plot.y+i.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,c=[{label:hc(r),x:t.xRange[0]},{label:hc(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:hc(s),x:t.xRange[1]}];return(0,cc.jsxs)("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t.groups.map(t=>(0,cc.jsxs)("g",{children:[(0,cc.jsx)("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:t.y,y2:t.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),(0,cc.jsx)("text",{x:i.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),(0,cc.jsxs)("text",{x:i.plot.x+i.plot.width-4,y:t.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",t.count]})]},t.label)),(0,cc.jsx)("line",{x1:t.xRange[0],x2:t.xRange[1],y1:n,y2:n,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(t=>(0,cc.jsxs)("g",{children:[(0,cc.jsx)("line",{x1:t.x,x2:t.x,y1:n,y2:n+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),(0,cc.jsx)("text",{x:t.x,y:Math.min(o[1]-8,n+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${t.x}`))]})}}var pc=require("react/jsx-runtime"),yc={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}};function gc(t,e,o){return Math.max(e,Math.min(o,t))}function mc(t){return 6.2*t.length}function xc(t,e){const o=t.trim();if(e>=o.length)return o;if(1>=e)return o.slice(0,1);const i=o.split(/\s+/).filter(Boolean).map(t=>t[0]).join("").toUpperCase();return i.length>1&&e>=i.length?i:e>3?o.slice(0,Math.max(1,e-2))+"..":o.slice(0,e).toUpperCase()}function bc(t,e,o="auto"){const i=Math.max(1,Math.floor(e/6.2)),n="compact"===o?xc(t,i):"full"===o?t:mc(t)>e?xc(t,i):t;return{text:n,textLength:mc(n)>e?Math.max(4,e):void 0}}var vc=require("react/jsx-runtime");function wc(t,e,o={},i){if(!1===e||!t)return;const{volume:n,stages:r,groups:s,groupCompletion:a}=t,c=new Map(n.stages.map(t=>[t.id,t])),l=new Map(a.map(t=>[t.id,t]));return({size:t})=>{const e=Number(t[0])||n.width,a=Number(t[1])||n.height,u=r.map(t=>{const e=c.get(t.id),i=o["process-stage-"+t.id];return{id:t.id,label:t.label,x0:e?.x0??t.x-t.width/2,x1:(e?.x0??t.x-t.width/2)+(e?.width??t.width),x:t.x,width:e?.width??t.width,count:t.count,capacity:t.capacity,absorb:t.absorb,portalTarget:t.portalTarget,queueDepth:i?.queueDepth,processed:i?.processedCount}}),d=s.map(t=>{const e=l.get(t.id);return{id:t.id,label:t.label??t.id,x:t.anchor?.x??t.x??0,y:t.anchor?.y??t.y??0,absorbed:e?.absorbed,total:e?.total,complete:e?.complete}});return function(t,e={}){const{showFlowSpine:o=!0,showStageCounts:i=!0,showCapacityBadges:n=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=e,{width:l,height:u,left:d,right:h,topY:f,bottomY:p,midY:y,stages:g,groups:m=[]}=t,x=p-f;return(0,pc.jsxs)("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:u,viewBox:`0 0 ${l} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[(0,pc.jsx)("defs",{children:(0,pc.jsxs)("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,pc.jsx)("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),(0,pc.jsx)("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),(0,pc.jsx)("rect",{x:0,y:0,width:l,height:u,fill:"url(#semiotic-process-floor)"}),(0,pc.jsx)("rect",{x:d-6,y:f-8,width:h-d+12,height:x+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),o?(0,pc.jsx)("line",{x1:d+8,x2:h-8,y1:y,y2:y,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,g.map((t,e)=>{const o=function(t){return t.absorb?"absorb":t.portalTarget?"portal":null!=t.capacity?"capacity":"flow"}(t),r=yc[o],c=Math.max(12,t.width-8),l=gc(c-8,22,88),d=bc(t.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,m=function(t){if(null!=t.capacity){const e=null!=t.queueDepth?" · q "+t.queueDepth:"";return t.capacityLabel?`${t.capacityLabel}${e}`:`cap ${Number.isInteger(t.capacity)?t.capacity+"":t.capacity.toFixed(1)}${e}`}return t.absorb?"absorb":t.portalTarget?"portal":"flow"}(t),b=bc(m,Math.max(16,c-10),"auto"),v=n&&!1!==t.showBadge&&c>=32,w=null!=t.count?`n=${t.count}${null!=t.processed?" done "+t.processed:""}`:"",k=bc(w,Math.max(16,c-8),"auto"),S=Math.max(30,f-15),A=S-13;return(0,pc.jsxs)("g",{"data-stage":t.id,"data-role":o,children:[(0,pc.jsx)("rect",{className:"semiotic-process-chrome__stage-bay",x:t.x0+4,y:f+6,width:c,height:x-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===o?1:1.6}),g.length-1>e?(0,pc.jsx)("polygon",{points:`${t.x1-2},${y-7} ${t.x1+8},${y} ${t.x1-2},${y+7}`,fill:r.accent,opacity:.85}):null,h?(0,pc.jsxs)(pc.Fragment,{children:[(0,pc.jsx)("rect",{className:"semiotic-process-chrome__stage-label-bg",x:t.x-l/2,y:A,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),(0,pc.jsxs)("text",{x:t.x,y:S,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[(0,pc.jsx)("title",{children:t.label}),d.text]})]}):null,v?(0,pc.jsxs)("text",{x:t.x,y:f+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:b.textLength,lengthAdjust:b.textLength?"spacingAndGlyphs":void 0,children:[(0,pc.jsx)("title",{children:m}),b.text]}):null,i&&null!=t.count?(0,pc.jsxs)("text",{x:t.x,y:Math.min(u-8,p+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[(0,pc.jsx)("title",{children:w}),k.text]}):null]},t.id)}),r?m.map((t,e)=>{const o=t.total??0,i=t.absorbed??0,n=t.complete??(o>0&&i>=o),r=!n&&o>0&&i/o>=.75,s=n?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=n?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=o>0?`${i}/${o}${n?" shipped":r?" almost":""}`:"feature "+(e+1),l=gc(Math.max(54,mc(t.label)+18,mc(c)+16),54,104),u=bc(t.label,l-12,"auto"),d=bc(c,l-12,"auto");return(0,pc.jsxs)("g",{"data-group":t.id,children:[(0,pc.jsx)("rect",{x:t.x-l/2,y:t.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),(0,pc.jsxs)("text",{x:t.x,y:t.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[(0,pc.jsx)("title",{children:t.label}),u.text]}),(0,pc.jsxs)("text",{x:t.x,y:t.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[(0,pc.jsx)("title",{children:c}),d.text]})]},t.id)}):null]})}({width:e,height:a,left:n.left,right:n.right,topY:n.topY,bottomY:n.bottomY,midY:n.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}function kc(t,e,o){if(!1===o||!e||0===t.length)return;const i=new Map(e.volume.stages.map(t=>[t.id,t]));return({size:o})=>{const n=[Number(o[0])||e.volume.width,Number(o[1])||e.volume.height],r=Gn(n),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return(0,vc.jsx)("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:e.stages.map((e,o)=>{const n=t[o];if(!n)return null;const r=i.get(e.id);if(!r)return null;const l=Math.max(2,n.value/s*a),u=Math.max(8,.35*r.width);return(0,vc.jsx)("rect",{x:r.x-u/2,y:c,width:u,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function Sc(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}var Ac=require("react/jsx-runtime");function Mc(t,e){const{showNodeLabels:o,showSensors:i,showStaticFlow:n}=e;if(t&&(n||i||o))return({size:e})=>{const r=[Number(e[0])||760,Number(e[1])||420],s=Math.max(1,...t.links.map(t=>t.throughput)),a=new Set(t.nodes.map(t=>t.sensorId));return(0,Ac.jsxs)("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[n?t.links.map(t=>{const e=3+t.throughput/s*16,o=t.path[Math.floor(t.path.length/2)];return(0,Ac.jsxs)("g",{children:[(0,Ac.jsx)("path",{d:Sc(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),(0,Ac.jsx)("path",{d:Sc(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?(0,Ac.jsx)("text",{x:o.x,y:o.y-e/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(i=t.throughput,i.toLocaleString(void 0,1e3>Math.abs(i)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},t.id);var i}):null,t.nodes.map(t=>(0,Ac.jsxs)("g",{children:[i&&a.has(t.sensorId)?(0,Ac.jsx)("rect",{"data-testid":"physical-flow-sensor-overlay",x:t.x-12,y:t.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,n?(0,Ac.jsx)("circle",{cx:t.x,cy:t.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,o?(0,Ac.jsx)("text",{x:t.x,y:t.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:t.label}):null]},t.id))]})}}var _c=require("react/jsx-runtime");function Pc({layout:t,compact:e,showLabels:o}){const i=e?Math.round(.14*t.height):Math.max(80,t.routeY-180),n=e?Math.max(6,Math.round(.72*t.height)):Math.min(360,t.height-170);return(0,_c.jsx)(_c.Fragment,{children:t.gates.map(r=>(0,_c.jsxs)("g",{children:[(0,_c.jsx)("rect",{x:r.x-r.width/2,y:i,width:r.width,height:n,rx:e?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),o?(0,_c.jsx)("text",{x:r.x,y:Math.max(64,t.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function jc({layout:t,states:e,compact:o=!1}){return o?(0,_c.jsx)("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:(0,_c.jsx)(Pc,{layout:t,compact:!0,showLabels:!1})}):(0,_c.jsxs)("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,_c.jsx)("path",{d:`M ${t.startX-42} ${t.routeY} C ${.24*t.width} ${t.routeY-70}, ${.42*t.width} ${t.routeY+78}, ${.58*t.width} ${t.routeY} S ${.78*t.width} ${t.routeY-82}, ${t.socketX+36} ${t.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),(0,_c.jsx)("line",{x1:Math.round(.06*t.width),x2:Math.round(.94*t.width),y1:t.crashY,y2:t.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),(0,_c.jsx)("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),(0,_c.jsx)(Pc,{layout:t,compact:!1,showLabels:!0}),(0,_c.jsxs)("g",{children:[(0,_c.jsx)("rect",{x:t.socketX-52,y:t.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),(0,_c.jsx)("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),(0,_c.jsxs)("g",{children:[(0,_c.jsx)("rect",{x:t.graveyardX-82,y:t.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),(0,_c.jsx)("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),(0,_c.jsx)("text",{x:t.graveyardX,y:t.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:e.some(t=>t.killed)?"lift shut off":"too heavy or too small"})]})]})}function Lc({states:t,layout:e}){const o=function(t){return t.map(t=>({label:t.id,value:Math.max(0,Number(t.viability)||0),outcome:t.outcome||t.stage||"in-process"}))}(t);if(!o.length)return null;const i=Math.max(1,...o.map(t=>t.value)),n=Math.max(40,(e.width-80)/o.length);return(0,_c.jsxs)("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,_c.jsx)("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),o.map((t,e)=>{const o=40+e*n,r=Math.max(2,t.value/i*28),s=/kill|crash|block|grave/i.test(t.outcome);return(0,_c.jsxs)("g",{children:[(0,_c.jsx)("rect",{x:o+.18*n,y:28-r+22,width:Math.max(10,.45*n),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),(0,_c.jsx)("text",{x:o+.4*n,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:t.label})]},t.label)})]})}var $c={margin:(t,e)=>e.compactMode?"sparkline"===t.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}};function Rc(t){return t.map(t=>({...t,spawnAt:void 0}))}function Cc(t,e){return t?e?o=>Xn.createElement(Xn.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function Ic(t,e,o){const i=e[o];return"boolean"==typeof i?i:!0!==t.__compactMode}var Tc=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Oc(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Tc[(e>>>0)%Tc.length]}var zc={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,i,n)=>({chartType:"line",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||e,colorAccessor:e,...i,showAxes:!1,margin:i.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:ro,LineChart:co,AreaChart:uo,DifferenceChart:ho,StackedAreaChart:fo,Scatterplot:oe,CandlestickChart:po,BubbleChart:ie,ConnectedScatterplot:go,QuadrantChart:yo,Heatmap:mo,TemporalHistogram:lo,XYCustomChart:{frameType:"xy",buildProps:(t,e,o,i,n)=>({chartType:"custom",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i,showAxes:n.frameProps?.showAxes??n.showAxes??!1,showLegend:i.showLegend??!!e})},BarChart:zo,StackedBarChart:Fo,GroupedBarChart:No,PieChart:Eo,DonutChart:Do,Histogram:Bo,BoxPlot:Wo,ViolinPlot:Yo,SwarmPlot:qo,DotPlot:Xo,SwimlaneChart:Go,RidgelinePlot:Vo,LikertChart:Ho,FunnelChart:Uo,GaugeChart:Ko,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"custom",data:t,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i,showAxes:n.frameProps?.showAxes??n.showAxes??!1})},ForceDirectedGraph:Cn,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,i,n)=>({chartType:"force",nodes:n.nodes||t||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:e,colorScheme:o,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...i})},SankeyDiagram:zn,ProcessSankey:On,ChordDiagram:Rn,TreeDiagram:Fn,Treemap:Nn,CirclePack:In,OrbitDiagram:Tn,ChoroplethMap:Wn,ProportionalSymbolMap:Yn,FlowMap:qn,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,i,n)=>({points:n.points||t||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i})},GaltonBoardChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s=n.bins??21,a=n.seed??1,c=Math.max(1,Math.round(n.pegRows??s-1)),l="mechanical"===n.mode,u=l?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),i=Math.max(1,Math.round(t.count??Math.max(64,4*e))),n=Qn(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=er(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:i},(t,e)=>{let i=0;for(let t=0;o>t;t+=1)r()<n&&(i+=1);const a=o/2;return{id:`${s}-${e}`,value:i,mechanical:!0,pegRows:o,branchProbability:n,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:s,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:c,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:o,bins:i,ballRadius:n,seed:r,size:s,valueExtent:a}=t,c=Gn(s),l=e.map((t,e)=>Zn(Kn(t,e,o))).filter(t=>null!=t),u=function(t){if(!t)return;const e=Zn(t[0]),o=Zn(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=(0,or.scaleLinear)().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),y=Array.from({length:i},()=>0),g=[];e.forEach((t,e)=>{const r=Zn(Kn(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-d)/f*i)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:c.plot.y+n+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:n},datum:{...t,value:r,bin:s}})});const m=c.plot.y+c.plot.height;return{config:Un(r,[...Jr({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...ts({idPrefix:"galton-bin",count:i,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:i,plot:c.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:n.valueAccessor||"value",bins:s,ballRadius:n.ballRadius??4,seed:a,size:r,valueExtent:l?[0,c]:void 0});return{...i,config:d.config,initialSpawns:Rc(d.initialSpawns),projectionRows:d.projectionRows,foregroundGraphics:Cc(lc(d.projectionRows,s,Ic(i,n,"showProjection"),d.metadata,n.referenceLines),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy||(l?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:i,windows:n,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:u=1}=t,d=Gn(c),h=e.map((t,e)=>Zn(Kn(t,e,o))).filter(t=>null!=t),f=Zn(l?.[0]),p=Zn(l?.[1]),y=h.length?Math.min(...h):0,g=h.length?Math.max(...h):y+n.size,m=Math.min(f??y,y),x=Math.max(p??g,g),b=Math.floor(m/n.size)*n.size,v=Math.max(1,Math.ceil((x-b+n.size)/n.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Zn(r?.value)??w-(r?.delay??n.size),S=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>b+(e+1)*n.size>k?t:t+1,0))),A=function(t,e){const 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=b+v*n.size,_=(0,ks.scaleLinear)().domain([b,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),j=[];e.forEach((t,e)=>{const r=Zn(Kn(t,e,o));if(null==r)return;const a=Zn(Kn(t,e,i))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-b)/n.size))),l=k>=b+(c+1)*n.size;P[c].value+=l?0:1,P[c].secondary+=l?1:0,j.push({id:(t.id??"event-"+e)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const L=d.plot.y+d.plot.height,$=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const i=t.windowStart,n=t.windowStart+t.windowCount*t.windowSize,r=(0,ks.scaleLinear)().domain([i,n]).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,i=o+t.windowSize,n=r(o),s=r(i);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:n,y1:l(n),x2:s,y2:l(s)})}return u}({closedWindowCount:S,gutter:A.gutter,plot:d.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:n.size,windowStart:b},d.plot.y+.28*d.plot.height);return{config:Un(a,[...Jr({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Ss({idPrefix:"eventdrop-window",count:v,xScale:t=>_(b+t*n.size),yTop:A.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?$[0]?.y1:$[t-1]?.y2??$[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?A.wallTop:e+1.25*s},yBottom:L,wallThickness:6}),...$.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:j,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${b+e*n.size}-${b+(e+1)*n.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:$,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:n.size,windowStart:b}}}({data:Array.isArray(t)?t:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r,timeExtent:n.timeExtent,timeScale:n.timeScale??1});return{...i,config:s.config,initialSpawns:Rc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Cc(uc(s.projectionRows,s.metadata,Ic(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s="mechanical"===n.mode,a=function(t){const{data:e,categoryAccessor:o,valueAccessor:i,unitValue:n,ballRadius:r,seed:s,size:a}=t,c=Jn(n,1),l=Gn(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((Kn(t,e,o)??"unknown")+"")});const y=Math.max(1,u.length),g=As(l.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),x=u.map(()=>[]);e.forEach((t,e)=>{const n=(Kn(t,e,o)??"unknown")+"",s=p(n),a=i?Zn(Kn(t,e,i)):1,u=Math.max(0,Math.round((a??0)/c)),d=g.centerX(s);for(let o=0;u>o;o+=1){const i=h.get(n)??0,a=g.perRow>1?((g.perRow>1?i%g.perRow:0)/(g.perRow-1)*2-1)*m:0;h.set(n,i+1),x[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:n,unitIndex:o}})}});const b=x.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;b>t;t+=1)for(const e of x)e.length>t&&f.push(e[t]);const v=l.plot.y+l.plot.height,w=[...Jr({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:Un(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:h.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],i=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),n=Jn(t.unitValue,1),r=er(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),c=a.reduce((t,e)=>t+e,0)||1,l=i-o.length,u=a.map(t=>t/c*l),d=u.map(t=>1+Math.floor(t));let h=i-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]*n,mechanical:!0,unitCount:d[e],unitValue:n,share:d[e]/i}))}({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(s?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r});return{...i,config:a.config,initialSpawns:Rc(a.initialSpawns),projectionRows:a.projectionRows,foregroundGraphics:Cc(dc(a.projectionRows,n.ballRadius??5,Ic(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:i,radiusAccessor:n,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:u}=t,d=Gn(a),h=er(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=Zn(Kn(t,e,o));if(null==s)return;const a=i?(Kn(t,e,i)??"All")+"":"All",c=n?Zn(Kn(t,e,n)):null,l=Qn(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?Zn(c[0]):null,x=c?Zn(c[1]):null,b=g.length?Math.min(...g):0,v=g.length?Math.max(...g):1;let w=m??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const t=k;k=w,w=t}const S=Math.max(r,...f.map(t=>t.radius)),A=d.plot.x+S+8,M=d.plot.x+d.plot.width-S-8,_=(0,Ms.scaleLinear)().domain([w,k]).range([A,M]),P=Math.max(1,p.length),j=Math.min(Math.max(28,3*S),d.plot.height/4),L=d.plot.y+j,$=Math.max(0,d.plot.y+d.plot.height-j-L),R=t=>{const e=y.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:L+e/(P-1)*$},C=new Map,I=f.map((t,e)=>{C.set(t.group,(C.get(t.group)??0)+1);const o=_(t.value),i=R(t.group),n=(h()-.5)*t.radius*1.6,r=(h()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?o+n:Qn(o+(e%9-4)*t.radius*2.5,A,M),y:u?i+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:i},springs:[{target:{type:"point",x:o,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:Un(s,Jr({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:I,projectionRows:p.map(t=>({label:t,value:C.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(t=>({label:t,y:R(t),count:C.get(t)??0})),plot:d.plot}}}({data:Array.isArray(t)?t:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:r,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...i,config:s.config,initialSpawns:Rc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Cc(fc(s.metadata,Ic(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,420],s=Array.isArray(n.stages)?n.stages:[],a=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,i=Gn(o),n=Qn(t.ballRadius??6,2,18),r=t.seed??1,s=er(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})),x=function(t){const e=t.shape??"lane",o=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height)),n=t.padX??46,r=t.padY??72,s=n,a=o-n,c=r,l=i-Math.max(24,Math.round(.45*r)),u=(c+l)/2,d=Math.max(1,l-c),h=Cs(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=Cs(d*h+p,.06*d,.5*d),g=y/2,m=u-g,x=u+g,b=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,S=t.stages;if(!S.length)throw Error("processStageLayout requires at least one stage");const A=Cs(t.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(S),_=a-s;let P=s;const j=S.map((t,e)=>{const o=P,i=e===S.length-1?a:P+(t.share??1)/M*_;return P=i,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:o,x1:i,x:(o+i)/2,width:i-o,y:u,height:d}}),L=j[A],$=L.x0,R=L.x1,C=(t,o)=>{if("lane"===e)return"top"===o?c:l;if("funnel"===e){const e=Cs((t-s)/Math.max(1,a-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if($>=t){const e=Cs((t-s)/Math.max(1,$-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if(R>=t)return"top"===o?m:x;const i=Cs((t-R)/Math.max(1,a-R),0,1);return"top"===o?m+(c-m)*i:x+(l-x)*i},I=j.map(t=>{const e=Math.min(C(t.x0,"top"),C(t.x1,"top")),o=Math.max(C(t.x0,"bottom"),C(t.x1,"bottom"));return{...t,y:(e+o)/2,height:Math.max(1,o-e)}}),T={thickness:k,friction:v,restitution:w},O=[];"lane"===e?O.push(Is(b+"-top",s,c,a,c,T),Is(b+"-bottom",s,l,a,l,T),Is(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),Is(b+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)})):"funnel"===e?O.push(Is(b+"-top",s,c,a,m,T),Is(b+"-bottom",s,l,a,x,T),Is(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),Is(b+"-right",a,m,a,x,{...T,thickness:Math.max(6,k)})):O.push(Is(b+"-left-top",s,c,$,m,T),Is(b+"-left-bottom",s,l,$,x,T),Is(b+"-center-top",$,m,R,m,T),Is(b+"-center-bottom",$,x,R,x,T),Is(b+"-right-top",R,m,a,c,T),Is(b+"-right-bottom",R,x,a,l,T),Is(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),Is(b+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)}));const z=t.membraneDampingScale??.5,F=s,N=Math.max(1,("bowtie"===e?$:a)-F),E=(t.membranes??[]).map(t=>{const e=F+Cs(t.offset,0,1)*N,o=t.width??18+18*t.cost,i=d-16,n=u+.25*(t.wobble??0);return{...t,x:e,y:n,width:o,height:i}}),D=!1===t.includeMembraneRegions?[]:E.map(t=>function(t){const e=t.dampingScale??.5,o=t.energyScale??1,i=Cs(t.cost,0,2);return{...Ts({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:i*e,energyDelta:-i*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??z,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:o,height:i,padX:n,padY:r,left:s,right:a,topY:c,bottomY:l,midY:u,centerLeft:$,centerRight:R,pinchHeight:y,pinchTop:m,pinchBottom:x,stages:I,membranes:E,colliders:O,regionEffects:D,boundaryY:C}}({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((t,e)=>[t.id,e])),v=new Map(x.stages.map(t=>[t.id,t])),w=x.stages[0].id,k=x.stages[0],S=new Set(e.filter(t=>t.absorb).map(t=>t.id)),A=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const 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{...Ts({...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:zs(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 i={...o,kind:t.kind??"force-field",force:zs(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...Ts({...i,kind:i.kind??"force-field",attributes:{primitive:"portal",targetStage:i.targetStage,..."object"==typeof i.attributes&&i.attributes?i.attributes:{}}}),force:i.force,impulseOnEnter:i.impulseOnEnter,damping:i.damping??.08}}var i;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{...Ts({...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:zs(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,i=t.dampingPerUnit??.12,n=t.energyPerUnit??0;return{...Ts({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o+e*i,energyDelta:n?-e*n: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:zs(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?Os({...o,kind:t.kind??"force-field",force:zs(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):function(t){return{...Ts({...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:x.midY,width:e.width,height:x.bottomY-x.topY})});A.unshift(Os({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));const M=new Map;for(const t of x.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const o=(a?Kn(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",i=(Kn(t,e,c)??w)+"",r=b.has(i)?i:w;M.set(r,(M.get(r)??0)+1);const s=l?(Kn(t,e,l)??"")+"":void 0,f=s&&u?(Kn(t,e,u)??s)+"":s,p=d?Zn(Kn(t,e,d))??1:1,y=h?Zn(Kn(t,e,h)):null,g=Qn(null!=y&&y>0?y:n,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,j=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&&j.set(t.groupId,t.groupLabel)}const L=Qn(t.groupAnchorAlong??.55,.15,.9),$=x.left+(x.right-x.left)*L,R=Array.from(P.keys()),C=R.map((t,o)=>{const i=P.get(t)??[],n=R.length>1?x.topY+28+o/Math.max(1,R.length-1)*(x.bottomY-x.topY-56):x.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:j.get(t)??t,bodyIds:i,anchor:{x:$,y:n},x:$,y:n,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),I=function(t,e){const o=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],i=e.filter(t=>!o.has(t)),n=e.length-i.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s&&Object.prototype.hasOwnProperty.call(o=s,i=t)?o[i]:void 0;var o,i;return"number"==typeof e&&Number.isFinite(e)&&e>=0?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?n>0:"threshold"===r?l>=(d??c):0===i.length),absorbed:n,total:e.length,absorbedValue:l,totalValue:c,threshold:d,missing:i}})}(C,_.filter(t=>S.has(t.stageId)).map(t=>t.id)),T=new Map(C.map(t=>[t.id,t])),O=_.map((t,e)=>{const o=v.get(t.stageId)??k,i=o.x+(s()-.5)*Math.min(24,.2*o.width),n=x.boundaryY(i,"top")+t.radius+10,r=x.boundaryY(i,"bottom")-t.radius-10,a=r>n?n+s()*Math.max(1,r-n):x.midY,c=g?i:x.left+18+e%7*4,l=g?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:i,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=T.get(t.groupId);e?.anchor&&!S.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:c,y:l,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),z={kernel:{seed:r,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},F=x.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),N=e.map(t=>{const e=v.get(t.id)??k;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:M.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:z,initialSpawns:O,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:F,metadata:{kind:"process-flow",plot:i.plot,volume:x,stages:N,groups:C,groupCompletion:I,regionEffects:A}}}({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),c=a.metadata;return{...i,config:a.config,initialSpawns:Rc(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,backgroundGraphics:Cc(wc(a.metadata,Ic(i,n,"showChrome"),{},n.chromeOptions),i.backgroundGraphics),foregroundGraphics:Cc(kc(a.projectionRows,a.metadata,Ic(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy||n.groupBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.workAccessor||n.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,520],s=Qs({data:Array.isArray(t)?t:[],size:r,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...i,config:s.config,initialSpawns:Rc(s.initialSpawns),projectionRows:[],backgroundGraphics:Cc(Ic(i,n,"showChrome")?Xn.createElement(jc,{layout:s.layout,states:s.states,compact:!0===i.__compactMode}):void 0,i.backgroundGraphics),foregroundGraphics:Cc(Ic(i,n,"showProjection")?Xn.createElement(Lc,{layout:s.layout,states:s.states}):void 0,i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy)}}},CrucibleChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,520],s=Xa({data:Array.isArray(t)?t:[],phases:Array.isArray(n.phases)?n.phases:[],products:Array.isArray(n.products)?n.products:void 0,outlets:Array.isArray(n.outlets)?n.outlets:void 0,events:Array.isArray(n.events)?n.events:void 0,idAccessor:n.idAccessor,labelAccessor:n.labelAccessor,categoryAccessor:n.categoryAccessor,amountAccessor:n.amountAccessor,metricsAccessor:n.metricsAccessor,initialStateAccessor:n.initialStateAccessor,metrics:n.metrics,size:r,seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange}),a="snapshot"===n.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,Pa(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const i=Math.max(0,Math.min(1,Pa(e.progress??0)??0));return o.start+o.duration*i}(s,n.snapshotAt):s.duration,c=qa(s,a).state,l=n.projection&&"object"==typeof n.projection?n.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",i=new Map,n=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),n=i.get(e);if(n)return n.count+=1,n.amount+=t.amount,void la(n.metrics,t.metrics);i.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:ea(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||n({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))n({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[...i.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||ra(t.key,e.key))}(c,l),d=l.measure??"count",h=function(t,e={}){const o=e.bodies??[],i=Math.max(0,e.recentBodyLimit??6),n=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const i=n.get(o);i?i.push(t):n.set(o,[t])}const r=t.map(t=>{const o=n.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-i)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??ac(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?n.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),f={seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange},p=e??n.colorBy??"category",y=!1===n.showChrome?null:Xn.createElement(rc,{layout:s.layout,phases:s.phases,state:c,compact:520>r[0]||360>r[1]}),g=!1===n.showProjection?null:Xn.createElement(sc,{rows:u,layout:s.layout,projection:l,amountLabel:n.amountLabel});return{...i,config:s.config,initialSpawns:Rc(Ba(c,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,o,i){const n=t.datum,r={stroke:i.stroke??("product"===n?.kind?"#fffaf0":"#26323a"),strokeWidth:i.strokeWidth??("product"===n?.kind?1.8:1.1),opacity:i.opacity??.96};if(!n?.__crucible)return{...r,fill:i.color??"#b8792d"};if("product"===n.kind){const t=e.products[n.semanticId];return{...r,fill:i.color??t?.color??Oc(t?.id??n.semanticId)}}const s=e.components[n.semanticId];if(!s)return{...r,fill:i.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:i.color??Oc(a)}}(t,c,p,n),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:Za,backgroundGraphics:Cc(y,i.backgroundGraphics),foregroundGraphics:Cc(g,i.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:i,maxParticles:n,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:x}=t,b=Gn(y),v=er(p),w=new Map,k=new Map,S=[];function A(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(Kn(t,e,r)??t.id??e)+"",i=Zn(Kn(t,e,s)),n=Zn(Kn(t,e,a));if(null!=i&&null!=n){const t={x:i,y:n};w.set(o,t),S.push(t)}k.set(o,(t.label??t.name??o)+"")});const M=[];i.forEach((t,e)=>{const o=A(Kn(t,e,g)),i=A(Kn(t,e,m)),n=Math.max(0,Zn(Kn(t,e,x))??0),r=Ps(d?Kn(t,e,d):void 0),s=r.length?r:Ps(t.path??t.points??t.route);s.forEach(t=>S.push(t)),M.push({id:(t.id??`physical-flow-${o}-${i}-${e}`)+"",link:t,index:e,source:o,target:i,throughput:n,rawPath:s})});const _=(j=S,"normalized"===(P=e)||"pixels"===P?P:j.length>0&&j.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,j;const L=new Map;for(const[t,e]of w)L.set(t,js(e,b,_));const $=[];for(const t of M){let e=t.rawPath.map(t=>js(t,b,_));if(2>e.length){const o=L.get(t.source),i=L.get(t.target);o&&i&&(e=[o,i])}else L.has(t.source)||L.set(t.source,e[0]),L.has(t.target)||L.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(k.has(t.source)||k.set(t.source,t.source),k.has(t.target)||k.set(t.target,t.target),$.push({...t,path:e,packetCount:0}))}const R=Jn(u,.12),C=Math.max(1,Math.round(n)),I=$.map(t=>Math.max(1,Math.round(t.throughput*R))),T=I.reduce((t,e)=>t+e,0),O=T>C?C/T:1;$.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(I[e]*O))});let z=$.reduce((t,e)=>t+e.packetCount,0);for(;z>C;){const t=$.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>$[t].packetCount)?o:t,-1);if(-1===t)break;$[t].packetCount-=1,z-=1}const F=new Map,N=new Map,E=[],D=Jn(o,90),B=Jn(l,4);$.forEach((t,e)=>{F.set(t.target,(F.get(t.target)??0)+t.throughput),N.set(t.source,(N.get(t.source)??0)+t.throughput);const o=Ls(t.path);for(let i=0;t.packetCount>i;i+=1){const n=(i+.5)/t.packetCount,r=f?n:Qn(.12+.84*n+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=$s(t.path,s),c=$s(t.path,r),l=Rs(t.path,s),u={x:-l.y,y:l.x},d=(v()-.5)*B*1.5;E.push({id:`${t.id}-packet-${i}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:l.x*D+10*(v()-.5),vy:f?0:l.y*D+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+i/32,shape:{type:"circle",radius:B},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:i,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:D,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*B,stiffness:26,damping:4.25}]:void 0})}});const W=Math.max(18,5*B),Y=Array.from(L,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+tr(t),point:e})),q=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:W,height:W}})),X=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=Un(p,[...Jr({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...q],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*B),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=C,G.eviction="oldest",G.observation={...G.observation,sensors:X};const V=Array.from(L,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+tr(t),incoming:F.get(t)??0,outgoing:N.get(t)??0})),H=$.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:G,initialSpawns:E,projectionRows:V.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:E.length,totalThroughput:$.reduce((t,e)=>t+e.throughput,0),plot:b.plot,nodes:V,links:H}}}({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(t)?t:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:r});return{...i,config:s.config,initialSpawns:Rc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Cc(Mc(s.metadata,{showNodeLabels:!1!==n.showNodeLabels,showSensors:!1!==n.showSensors,showStaticFlow:!1!==n.showStaticFlow}),i.foregroundGraphics),bodyStyle:Hn(e||n.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",layout:$c,buildProps:(t,e,o,i,n)=>{const r=i.size??[700,380],s=Ot(i.theme),a=function(t){const e=function(t,e,o){const i=t?.observation;return{...t,observation:{...i,chartId:e??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:o??i?.onObservation}}}(t.config,t.chartId,t.onObservation),o=Ns(t.colorScheme,t.themeCategorical,C),i=Gn(t.size),n={data:t.data,scales:{x:(0,Fs.scaleLinear)().domain(t.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:(0,Fs.scaleLinear)().domain(t.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:t.semantic,categorical:[...o]},resolveColor:Es(o,t.colorScheme),config:t.layoutConfig??{},world:new ws(e)},r=t.skipLayout?{}:t.layout(n)??{},s=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...i}=t,n=o.get(e)??[];n.push(i),o.set(e,n)}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:Ds(e,r),context:n,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:n.chartId,colorScheme:o,config:n.config,data:Array.isArray(t)?t:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:It(s)??{},size:r,themeCategorical:s.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...i,config:a.config,initialSpawns:Rc(a.initialSpawns),projectionRows:[],bodyStyle:a.result.bodyStyle??Hn(e||n.colorBy),backgroundGraphics:Cc(i.backgroundGraphics,a.result.backgroundOverlays),foregroundGraphics:Cc(i.foregroundGraphics,a.result.overlays)}}}};function Fc(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Nc(t){if(!t||2>t.length)return;const e=Fc(t[0]),o=Fc(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Ec(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),i=0===e,n=[...t.extraWarnings??[]];i&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),t.annotationRender&&t.annotationRender.unrenderedCount>0&&!n.includes("UNRENDERED_ANNOTATIONS")&&n.push("UNRENDERED_ANNOTATIONS");const r=Array.isArray(t.annotations)?t.annotations.length:0,s=t.margin,a=s?{x:s.left,y:s.top,width:t.width-s.left-s.right,height:t.height-s.top-s.bottom}:void 0;return{component:"",frameType:t.frameType,status:i?"empty":"ok",empty:i,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:t.annotationRender?.renderedCount??r,...t.annotationRender?{annotationInputCount:t.annotationRender.inputCount,unrenderedAnnotationCount:t.annotationRender.unrenderedCount,...t.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:t.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:n,semanticStatus:"not-assessed",semanticDiagnostics:[],...s?{margin:s}:{},...a?{plot:a}:{}}}var Dc=c(require("react")),Bc=c(require("react-dom/server")),Wc=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,i=[];e.length>t&&(o=e.length-t,i=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 i}update(t,e){const o=[],i=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++){const r=(i+n)%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(i=>{t(i)?o.push(i):e.push(i)}),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}},Yc=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 qc(t,e){return t===e}function Xc(t,e){if("function"==typeof t)return e=>+t(e);const o=t||e;return t=>+t[o]}function Gc(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}function Vc(t,e){return"function"==typeof t?e=>t(e)+"":t?e=>e[t]+"":e?t=>t[e]+"":void 0}function Hc(t){return t?"function"==typeof t?t:e=>e[t]||e.id:null}function Uc(t){return"string"==typeof t?t:t.id}var Kc=/^\d{4}-\d{1,2}$/;function Zc(t){const e=t.trim();if(!e||!Number.isNaN(Number(e)))return NaN;const o=Kc.test(e)?e+"-01":e;if(o===e&&10>e.length)return NaN;const i=Date.parse(o);return Number.isFinite(i)?i:NaN}function Qc(t){return t instanceof Date?t.getTime():"string"==typeof t?Zc(t):+t}function Jc(t){return new Set(Array.isArray(t)?t:[t])}function tl(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function el(t,e){return Math.min((t-e.startTime)/e.duration,1)}function ol(t,e,o){return t+(e-t)*o}function il(){return"undefined"!=typeof performance?performance.now():Date.now()}function nl(t,e,o){if(1>=o)return 1;const i=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 i=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(i>0?i:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:i-e,extent:i,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function rl(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function sl(t,e,o){const i=t.duration??500,n=o-e;return i>n?1-n/i:0}function al(t,e,o,i){let n=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,n=!0),t._pulseColor!==o&&(t._pulseColor=o,n=!0),t._pulseGlowRadius!==i&&(t._pulseGlowRadius=i,n=!0),n):(0!==t._pulseIntensity&&(t._pulseIntensity=0,n=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,n=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,n=!0),n)}function cl(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const i=t.duration??500,n=e.peek();return null!=n&&i>o-n}function ll(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),i=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${i}`;if(null!=o&&null!=i)return`p:${o}:${i}`}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 ul(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function dl(t,e,o,i,n,r){const s=[];for(const n of t){const t=o(n),r=i(n);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:n})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),c=Array(s.length),l=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],c[t]=e.rawY,l[t]=e.d}return{type:"line",path:a,rawValues:c,style:n,datum:l,group:r}}function hl(t,e,o,i,n,r,s,a){const c=[];for(const r of t){const t=o(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const l=e.x(t),u=a?a(r):n;c.push({px:l,topY:e.y(s),botY:e.y(u),rawY:s})}c.sort((t,e)=>t.px-e.px);const l=Array(c.length),u=Array(c.length),d=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],d[t]=e.rawY}return{type:"area",topPath:l,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function fl(t,e,o,i){const n=new Map;if("silhouette"===i)for(const i of t){let t=0;for(const n of e)t+=o(n,i)||0;n.set(i,-t/2)}else if("wiggle"===i){t.length>0&&n.set(t[0],0);for(let i=1;t.length>i;i++){const r=t[i-1],s=t[i];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=n.get(r)??0;n.set(s,u-(c>0?a/(2*c):0))}if(t.length>0){let i=0;for(const r of t){let t=0;for(const i of e)t+=o(i,r)||0;i+=(n.get(r)??0)+t/2}const r=i/t.length;for(const e of t)n.set(e,(n.get(e)??0)-r)}}else for(const e of t)n.set(e,0);return n}function pl(t,e,o,i,n,r,s){const a=o(t),c=i(t);if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l={type:"point",x:e.x(a),y:e.y(c),r:n,style:r,datum:t};return void 0!==s&&(l.pointId=s),l}function yl(t,e,o,i,n,r,s,a){const c=o(t),l=i(t);if(!Number.isFinite(c)||!Number.isFinite(l))return null;const u={type:"symbol",x:e.x(c),y:e.y(l),size:n,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function gl(t,e,o,i,n,r,s){return{type:"rect",x:t,y:e,w:o,h:i,style:n,datum:r,group:s}}function ml(t,e,o,i,n,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:i,fill:n,datum:r};return void 0!==s?.value&&(a.value=s.value),s?.showValues&&(a.showValues=!0,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function xl(t,e,o,i){return"function"==typeof e.style?e.style(i||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,i)}function bl(t,e,o,i){if(!t.scales)return null;const n=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=i.getTop(o),a=i.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)&&(n.push([c,l]),r.push([c,u]))}return 2>n.length?null:{type:"area",topPath:n,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:xl(t,i,o,e[0]),datum:e,group:o,interactive:i.interactive}}function vl(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const i of t)i.perSeries?e.push(i):o.push(i);return{perSeries:e,aggregate:o}}function wl(t,e,o){const i=[];for(const n of o){const o=bl(t,e,"__ribbon_aggregate",n);o&&i.push(o)}return i}function kl(t,e,o,i){const n=[];for(const r of i){const i=bl(t,e,o,r);i&&n.push(i)}return n}function Sl(t,e,o,i){if(!t.config.pointStyle)return;const n=i??t.getY;for(const i of e){const e=t.resolveGroupColor(i.key);for(const r of i.data){let i=t.config.pointStyle(r);!i.fill&&e&&(i={...i,fill:e});const s=i.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,c=pl(r,t.scales,t.getX,n,s,i,a);c&&o.push(c)}}}function Al(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function Ml(t){return kt(t)}var _l=require("d3-shape"),Pl={circle:_l.symbolCircle,square:_l.symbolSquare,triangle:_l.symbolTriangle,diamond:_l.symbolDiamond,star:_l.symbolStar,cross:_l.symbolCross,wye:_l.symbolWye},jl=new Set(["circle","square","triangle","diamond","star","cross","wye","chevron"]),Ll=["circle","triangle","diamond","star","square","chevron","cross","wye"];function $l(t,e,o){if(o)return o;const i=t??"circle";if("chevron"===i)return function(t){const e=1.5*Rl(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);const n=Object.prototype.hasOwnProperty.call(Pl,i)?Pl[i]:_l.symbolCircle;return(0,_l.symbol)(n,Math.max(1,e))()??""}function Rl(t){return Math.sqrt(Math.max(1,t)/Math.PI)}function Cl(t,e){const o=new Map;let i=0;return n=>{const r=t(n)+"",s=e&&Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(s&&jl.has(s))return s;let a=o.get(r);return a||(a=Ll[i%Ll.length],i++,o.set(r,a)),a}}var Il=new Map;function Tl(t){const e=Object.prototype.hasOwnProperty.call(X,t)?t:"blues";let o=Il.get(e);if(o)return o;o=Array(256);const i=G(e);for(let t=0;256>t;t++)o[t]=i(t/255);return Il.set(e,o),o}function Ol(t,e,o){const i=o.config.areaStyle?.(e);return i&&("string"==typeof i.fill&&(t.fill=i.fill),t.style=i),t}function zl(t,e,o,i,n){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/i)*i;let l=r.get(c);if(l||(l={start:c,end:c+i,total:0,categories:new Map},r.set(c,l)),l.total+=a,n){const t=n(s);l.categories.set(t,(l.categories.get(t)||0)+a)}}return r}function Fl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:i,warned:n}=t;Nl(i)&&0===o.length&&El(n,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),o.length>0&&o.every(t=>null==t.datum)&&El(n,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Nl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(Nl))}function El(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Dl(t,e,o,i){const n=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${n.message}`,error:n,recovery:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:i}}function Bl(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function Wl(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,i=Bl(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=Xc(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=i(t);if(!Number.isFinite(e))return NaN;const n=o(t);return Number.isFinite(n)&&0!==n?e+n:e},getBottom:t=>{const e=i(t);if(!Number.isFinite(e))return NaN;const n=o(t);return Number.isFinite(n)&&0!==n?e-n: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:Bl(t.y1Accessor,"y1"),getBottom:Bl(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}var Yl=require("d3-scale");function ql(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Xl(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return(0,Yl.scaleLog)().domain(t).range(o).clamp(!0)}return"symlog"===t?(0,Yl.scaleSymlog)().domain(e).range(o):"time"===t?(0,Yl.scaleTime)().domain([new Date(e[0]),new Date(e[1])]).range(o):(0,Yl.scaleLinear)().domain(e).range(o)}function Gl(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Vl(t,e){const o=new Wc(t.capacity);return t.forEach(()=>o.push(e)),o}function Hl(t,e,o,i){const n=t.push(e);return o&&o.push(i),n}function Ul(t,e,o){if(!e||0===e.size)return;const i=new Set;if(t.forEach((t,e)=>{o(t)&&i.add(e)}),0===i.size)return;const n=e.toArray();e.clear();for(let t=0;n.length>t;t++)i.has(t)||e.push(n[t])}var Kl=new WeakMap;function Zl(){return this.updateResults.last}function Ql(){return this.updateResults.last}function Jl(t){return this.updateResults.subscribe(t)}function tu(t){this.config.layoutSelection=t}function eu(){Kl.set(this,!0)}function ou(){const t=!0===Kl.get(this);return Kl.delete(this),t}function iu(t){Object.assign(t.prototype,{getLastUpdateResult:Zl,getUpdateSnapshot:Ql,subscribeUpdateResult:Jl,setLayoutSelection:tu,markStylePaintPending:eu,consumeStylePaintPending:ou})}var nu=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ru=["scene-style","data-paint","accessibility","evidence"],su=(t,e)=>({retainedData:t,invalidations:e}),au=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],cu=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],lu=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],uu=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],du=["scene-geometry","data-paint","accessibility","evidence"],hu=["scene-style","data-paint","accessibility","evidence"],fu=[],pu={chartType:su("rebuild",au),runtimeMode:su("rebuild",au),xAccessor:su("rebuild",au),yAccessor:su("rebuild",au),timeAccessor:su("rebuild",au),valueAccessor:su("rebuild",au),y0Accessor:su("rebuild",au),boundsAccessor:su("rebuild",au),band:su("rebuild",au),openAccessor:su("rebuild",au),highAccessor:su("rebuild",au),lowAccessor:su("rebuild",au),closeAccessor:su("rebuild",au),candlestickRangeMode:su("rebuild",au),accessorRevision:su("rebuild",au),groupAccessor:su("rebuild",cu),categoryAccessor:su("rebuild",cu),lineDataAccessor:su("rebuild",cu),colorAccessor:su("rebuild",hu),sizeAccessor:su("rebuild",du),symbolAccessor:su("rebuild",du),pointIdAccessor:su("rebuild",du),xScaleType:su("preserve",lu),yScaleType:su("preserve",lu),xExtent:su("preserve",lu),yExtent:su("preserve",lu),extentPadding:su("preserve",lu),scalePadding:su("preserve",lu),axisExtent:su("preserve",lu),yAxisExtent:su("preserve",lu),binSize:su("preserve",lu),normalize:su("preserve",lu),heatmapAggregation:su("preserve",lu),heatmapXBins:su("preserve",lu),heatmapYBins:su("preserve",lu),arrowOfTime:su("preserve",uu),baseline:su("preserve",uu),stackOrder:su("preserve",uu),sizeRange:su("preserve",uu),curve:su("preserve",uu),areaGroups:su("preserve",uu),customLayout:su("preserve",uu),layoutConfig:su("preserve",uu),layoutMargin:su("preserve",uu),symbolMap:su("preserve",du),showValues:su("preserve",du),heatmapValueFormat:su("preserve",du),lineStyle:su("preserve",hu),pointStyle:su("preserve",hu),areaStyle:su("preserve",hu),barStyle:su("preserve",hu),swarmStyle:su("preserve",hu),waterfallStyle:su("preserve",hu),candlestickStyle:su("preserve",hu),boundsStyle:su("preserve",hu),gradientFill:su("preserve",hu),lineGradient:su("preserve",hu),semanticLineStops:su("preserve",hu),colorScheme:su("preserve",hu),themeCategorical:su("preserve",hu),themeSemantic:su("preserve",hu),themeSequential:su("preserve",hu),themeDiverging:su("preserve",hu),barColors:su("preserve",hu),decay:su("preserve",hu),pulse:su("preserve",hu),staleness:su("preserve",hu),layoutSelection:su("preserve",hu),annotations:su("preserve",["overlay","accessibility","evidence"]),windowSize:su("preserve",fu),windowMode:su("preserve",fu),maxCapacity:su("preserve",fu),clock:su("preserve",fu),transition:su("preserve",fu),introAnimation:su("preserve",fu),onLayoutError:su("preserve",fu)},yu=su("preserve",uu),gu=class{constructor(){this.tracker=new ns}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}},nu)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},ru):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const i of t){const t=pu[i]??yu;"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)}},mu=require("d3-quadtree"),xu=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,i=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(o++,t.r>i&&(i=t.r));if(this.maxRadius=i,500>=o)return void(this.tree=null);const n=Array(o);let r=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(n[r++]=t);this.tree=(0,mu.quadtree)().x(t=>t.x).y(t=>t.y).addAll(n)}},bu=class t{constructor(t){if(this.xExtent=new Yc,this.yExtent=new Yc,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 gu,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 xu,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,i,n,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;const l=n??(()=>{const t=new Map;for(let e=0;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 n=0,a=!1;for(const o of e){const e=l.get(o);if(null==e)continue;a=!0;const s=i.get(e);if(null==s)continue;const c=sl(t,s,r);c>n&&(n=c)}a&&(c=al(o,n,s)||c);continue}const e=l.get(o.datum);if(null==e)continue;const n=i.get(e);c=al(o,null==n?0:sl(t,n,r),s,a)||c}return c}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new Wc(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=Xc(t.timeAccessor||t.xAccessor,"time"),this.getY=Xc(t.valueAccessor||t.yAccessor,"value")):(this.getX=Xc(t.xAccessor,"x"),this.getY=Xc(t.yAccessor,"y")),this.getGroup=Vc(t.groupAccessor),this.getCategory=Vc(t.categoryAccessor),this.getSize=t.sizeAccessor?Xc(t.sizeAccessor,"size"):void 0,this.getColor=Vc(t.colorAccessor),this.getSymbol=Vc(t.symbolAccessor),this.getY0=t.y0Accessor?Xc(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=Wl(t),this.getPointId=Vc(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?Xc(t.openAccessor,"open"):void 0,this.getHigh=Xc(t.highAccessor,"high"),this.getLow=Xc(t.lowAccessor,"low"),this.getClose=o?Xc(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new Wc(t.windowSize))}currentTime(){return this.config.clock?.()??il()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Vl(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),i=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(i)&&this.yExtent.push(i)}}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),i=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(i)&&this.yExtent.evict(i)}}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?Xc(this.config.timeAccessor||this.config.xAccessor,"time"):Xc(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,i="function"==typeof o?o(e):e[o||"x"],n=i instanceof Date,r="string"==typeof i&&Number.isFinite(Zc(i));if(this.xIsDate=n||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>Qc(e[t]):t=>Qc(o(t))}}Gl(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Hl(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=Hl(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,i=this.scales,n=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=ql(this.xExtent.extent,e.xExtent),c=ql(s,e.yExtent);const l=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!l&&o.size>0){const t=function(t){const{config:e,groups:o,getX:i,getY:n}=t,r="exact"===(e.yAxisExtent??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=i(r),s=n(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=[],i=[];let n=0,r=0;for(const o of t)r>n?(e.push(o),n+=d.get(o)??0):(i.push(o),r+=d.get(o)??0);p=[...i.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=fl(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let i=1/0,n=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;i>t&&(i=t),t+r>n&&(n=t+r)}Number.isFinite(i)&&Number.isFinite(n)||(i=0,n=0);const s=n-i,l=r?0:s>0?s*e.extentPadding:1;y=[i-l,n+l]}else if("diverging"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),[o,i]=function(t,e,o){let i=0,n=0;for(const r of t){let t=0,s=0;for(const i of e){const e=o(i,r)||0;0>e?s+=e:t+=e}i>s&&(i=s),t>n&&(n=t)}return[i,n]}(t,p,(t,e)=>a.get(t)?.get(e)||0),n=i-o,s=r?0:n>0?n*e.extentPadding:1;y=[o-s,i+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,i,n,r,s){const[,a]=function(t,e,o,i,n){const r=zl(t,e,o,i,n);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,o,i,n);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,i){const[n,r]=function(t,e){let o=0,i=0,n=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(n+=t,o>n&&(o=n),n>i&&(i=n))}return[o,i]}(t,e),s=r-n,a=i?0:s>0?s*o:1;return[Math.min(0,n-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[i,n]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(i>o&&(i=o),o>n&&(n=o)),Number.isFinite(r)&&(i>r&&(i=r),r>n&&(n=r))}return[i,n]}(c,r,this.resolvedRibbons),c=function(t,e){const o=t[1]-t[0],i=e.exactMode?0:o>0?o*e.extentPadding:1,n=[null!=e.userMin?t[0]:t[0]-i,null!=e.userMax?t[1]:t[1]+i];return"log"!==e.yScaleType||n[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(n[0]=e.dataYDomain[0]/(1+e.extentPadding)),n}(c,{exactMode: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 i=e[0],n=e[1];return null==i&&null==n?t:[null!=i?i:t[0],null!=n?n:t[1]]}(c,e.yExtent,!!l),({xDomain:a,yDomain:c}=function(t,e,o){let i=t,n=e;if(i[0]===1/0||i[1]===-1/0)if("time"===o){const t=Date.now();i=[t-864e5,t]}else i=[0,1];return n[0]!==1/0&&n[1]!==-1/0||(n=[0,1]),{xDomain:i,yDomain:n}}(a,c,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:i,yDomain:n}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){const t="left"===e.arrowOfTime?[o.width-s,s]:[s,o.width-s];return{x:(0,Yl.scaleLinear)().domain(i).range(t),y:Xl(e.yScaleType,n,[o.height-s,s])}}return{x:Xl(e.xScaleType,i,[s,o.width-s]),y:Xl(e.yScaleType,n,[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=i,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=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 i of t.path)i[0]*=e,i[1]*=o;break;case"area":for(const i of t.topPath)i[0]*=e,i[1]*=o;for(const i of t.bottomPath)i[0]*=e,i[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}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*o,height:t.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 i=this.scales.x.domain(),n=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Xl,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,i,r[0]>r[1]?[t.width-c,c]:[c,t.width-c]),y:a(this.config.yScaleType,n,l?[c,t.height-c]:[t.height-c,c])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:i}=this;if(!i)return[];if(o.customLayout){const n={data:e,scales:i,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??nt},resolveColor:(t,e)=>{const i=this.resolveGroupColor(t);if(i)return i;const n=this.resolveLineStyle(t,e);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null};let r;try{r=o.customLayout(n)}catch(t){const e=null!==this.lastCustomLayoutResult,i=Dl("xy",t,e,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.onLayoutError?.(i)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=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 Fl({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const n={scales:i,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),i=[],n=t.config.annotations?.filter(Al).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=vl(t.ribbons);if(r.length>0&&i.push(...wl(t,e,r)),n.length>0)for(const e of o)i.push(...kl(t,e.data,e.key,n))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=dl(e.data,t.scales,t.getX,t.getY,o,e.key);n&&n.length>0&&(r.colorThresholds=n),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),i.push(r)}return Sl(t,o,i),i}(n,e);case"area":return function(t,e){const o=t.groupData(e),i=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=vl(t.ribbons);if(r.length>0&&i.push(...wl(t,e,r)),n.length>0)for(const e of o)i.push(...kl(t,e.data,e.key,n))}const n=t.scales.y.domain(),r=n[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:n[0]+Math.max(0,Math.min(1,t.offset))*(n[1]-n[0]),color:t.color,opacity:t.opacity,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),o=[{from:n[0],to:e[0].value,color:e[0].color,opacity:e[0].opacity}];for(let t=0;e.length>t;t++)o.push({from:e[t].value,to:e[t+1]?.value??n[1],color:e[t].color,opacity:e[t].opacity});return o.map(({from:e,to:o,color:i,opacity:n})=>{const r=t.scales.y(e),s=t.scales.y(o);return{y:Math.min(r,s),height:Math.abs(s-r),color:i,...null!=n&&{opacity:n}}}).filter(t=>t.height>0)})():void 0,c=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),n=hl(e.data,t.scales,t.getX,t.getY,r,o,e.key,c),l=Ml(t.config.gradientFill);l&&(n.fillGradient=l),t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),s&&s.length>0&&(n.colorThresholds=s,n.strokeColorBands=a),i.push(n)}return Sl(t,o,i),i}(n,e);case"mixed":return function(t,e){const o=t.groupData(e),i=[],n=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=vl(t.ribbons);if(r.length>0&&i.push(...wl(t,e,r)),n.length>0)for(const e of o)i.push(...kl(t,e.data,e.key,n))}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(n.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),n=hl(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=Ml(t.config.gradientFill);a&&(n.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),i.push(n)}else{const o=t.resolveLineStyle(e.key,e.data[0]),n=dl(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),i.push(n)}return Sl(t,o,i),i}(n,e);case"stackedarea":return function(t,e){const o=t.groupData(e),i=t.config.stackOrder??"key",n=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===i);else if("key"===i)n();else if("asc"===i||"desc"===i||"insideOut"===i){const e=new Map;for(const i of o){let o=0;for(const e of i.data){const i=t.getX(e),n=t.getY(e);Number.isFinite(i)&&Number.isFinite(n)&&(o+=n)}e.set(i.key,o)}const n=(t,e)=>e>t?-1:t>e?1:0;if("asc"===i)o.sort((t,o)=>{const i=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==i?i:n(t.key,o.key)});else if("desc"===i)o.sort((t,o)=>{const i=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==i?i:n(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const i=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==i?i:n(t.key,o.key)}),i=[],r=[];let s=0,a=0;for(const o of t)a>s?(i.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...i)}}else n();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:c}=function(t,e,o,i,n,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 n of e.data){const e=o(n),r=i(n);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 i of t)o+=u.get(i.key)?.get(e)||0;d.set(e,o||1)}}const h=fl(l,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,x=new Map;for(const t of l)g.set(t,h.get(t)??0),m.set(t,0),x.set(t,0);for(const o of t){const t=u.get(o.key),i=new Map;let a=[],c=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:c,style:n(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 n=t.has(o);let s,l,u=n?t.get(o):0;if(r&&n&&(u/=d.get(o)),!n||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(o),l=s+u,m.set(o,l)):(s=x.get(o),l=s+u,x.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)]),i.set(o,l)}h(),y.set(o.key,i)}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 i of o){const o=c.get(i.key);if(o)for(const n of i.data){const i=t.getX(n),r=t.getY(n);null==i||Number.isNaN(i)||null==r||Number.isNaN(r)||!o.has(i)||e.set(n,o.get(i))}}const i=o=>e.get(o)??t.getY(o);Sl(t,o,l,i)}return l}(n,e);case"scatter":case"bubble":return function(t,e){const o=[],i="bubble"===t.config.chartType?10:5,n=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 i of o)t>i&&(t=i),i>e&&(e=i);r=o=>t===e?(n[0]+n[1])/2:n[0]+(o-t)/(e-t)*(n[1]-n[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",c=t.getSymbol,l=c?Cl(c,t.config.symbolMap):null;for(const n of e){let e=t.config.pointStyle?t.config.pointStyle(n):{fill:a,opacity:.8},c=e.r||i;if(r&&t.getSize){const e=t.getSize(n);null==e||Number.isNaN(e)||(c=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(n);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(n)+"":void 0;if(l){const i=l(n),r=yl(n,t.scales,t.getX,t.getY,Math.PI*c*c,i,e,u);r&&o.push(r)}else{const i=pl(n,t.scales,t.getX,t.getY,c,e,u);i&&o.push(i)}}return o}(n,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(t,e,o){const i=Math.max(1,Math.floor(t.config.heatmapXBins??20)),n=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=Xc(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)/i,h=(u-l||1)/n,f=i*n;if(f>1e6)return[];const p=new Int32Array(f),y=new Float64Array(f);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 f=Math.min(Math.floor((c-a)/d),i-1),g=Math.min(Math.floor((u-l)/h),n-1);if(0>f||0>g)continue;const m=g*i+f;p[m]++;const x=s(r);y[m]+=isFinite(x)?x:0}let g=1/0,m=-1/0;for(let t=0;f>t;t++){if(0===p[t])continue;let e;switch(r){case"sum":e=y[t];break;case"mean":e=y[t]/p[t];break;default:e=p[t]}g>e&&(g=e),e>m&&(m=e)}if(!isFinite(g))return[];const x=m-g||1,b=t.config.heatmapColorScale,v=b?void 0:Tl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),w=255/x,k=o.width/i,S=o.height/n,A=t.config.showValues,M=t.config.heatmapValueFormat,_=[];for(let e=0;n>e;e++){const o=e*i;for(let s=0;i>s;s++){const i=o+s;if(0===p[i])continue;let c;switch(r){case"sum":c=y[i];break;case"mean":c=y[i]/p[i];break;default:c=p[i]}const u=Math.min((c-g)*w+.5|0,255),f=b?b(c):v[u],m={xi:s,yi:e,value:c,count:p[i],sum:y[i],xCenter:a+(s+.5)*d,yCenter:l+(e+.5)*h,agg:r};_.push(Ol(ml(s*k,(n-1-e)*S,k,S,f,m,A?{value:c,showValues:!0,valueFormat:M}:{value:c}),m,t))}}return _}(t,e,o);if(0===e.length)return[];const i=Xc(t.config.valueAccessor,"value"),n=Gc(t.config.xAccessor,"x"),r=Gc(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],i=n(o),u=r(o);c[t]=i,l[t]=u,s.has(i)||s.set(i,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),f=Array.from(a.keys()),p=h.every(t=>"number"==typeof t&&!isNaN(t)),y=f.every(t=>"number"==typeof t&&!isNaN(t));if(p){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(y){f.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;f.length>t;t++)a.set(f[t],t)}const g=new Float64Array(e.length),m=new Float64Array(e.length),x=Array(e.length),b=new Map;let v=0;for(let t=0;e.length>t;t++){const o=e[t],n=s.get(c[t]),r=a.get(l[t]);if(void 0===n||void 0===r)continue;const d=i(o),h=r*u+n,f=b.get(h);let p;void 0!==f?p=f:(p=v++,b.set(h,p)),g[p]=h,m[p]=d,x[p]=o}let w=1/0,k=-1/0;for(let t=0;v>t;t++){const e=m[t];isFinite(e)&&(w>e&&(w=e),e>k&&(k=e))}if(!isFinite(w)||!isFinite(k))return[];const S=t.config.heatmapColorScale,A=S?void 0:Tl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),M=255/(k-w||1),_=o.width/u,P=o.height/d,j=t.config.showValues,L=t.config.heatmapValueFormat,$=[];for(let e=0;v>e;e++){const o=m[e];if(!isFinite(o))continue;const i=g[e],n=i%u,r=(i-n)/u,s=Math.min((o-w)*M+.5|0,255),a=S?S(o):A[s],c=x[e];$.push(Ol(ml(n*_,(d-1-r)*P,_,P,a,c,j?{value:o,showValues:!0,valueFormat:L}:{value:o}),c,t))}return $}(n,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=zl(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===o.size)return{nodes:[],binBoundaries:[]};let i=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 n=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(n),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=n.filter(t=>e.has(t)),c=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===c?i=t.barCategoryCache.order:(i=[...a,...s],t.barCategoryCache={key:c,order:i})}const n=[],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),c?.cursor&&(h.cursor=c.cursor);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,x=Math.max(y-g,1);if(x>0)if(i&&e.categories.size>0){let o=0;for(const s of i){const i=e.categories.get(s)||0;if(0===i)continue;const a=r.y(o),u=r.y(o+i),d=Math.min(a,u),f=Math.abs(a-u),p=(t.config.barColors?ct(t.config.barColors,s):void 0)??c?.fill??l??"#4e79a7",y={binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:i},g=t.config.areaStyle?.(y)??{};n.push(gl(m,d,x,f,{fill:p,...h,...g},y,s)),o+=i}}else{const o=r.y(0),i=r.y(e.total),s=Math.min(o,i),a=Math.abs(o-i),u=c?.fill||l||"#007bff",d={binStart:e.start,binEnd:e.end,total:e.total},f=t.config.areaStyle?.(d)??{};n.push(gl(m,s,x,a,{fill:u,...h,...f},d))}}const f=new Set;for(const t of o.values())f.add(t.start),f.add(t.end);return{nodes:n,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(n,e);return this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const o=[],i=t.config.swarmStyle||{},n=i.radius??3,r=i.fill??t.config.themeSemantic?.primary??"#007bff",s=i.opacity??.7,a=i.stroke,c=i.strokeWidth,l=i.cursor;for(const i of e){const e=t.getX(i),u=t.getY(i);if(null==u||Number.isNaN(u))continue;const d=t.scales.x(e),h=t.scales.y(u);let f=r;if(t.getCategory){const e=t.getCategory(i)+"";f=(t.config.barColors?ct(t.config.barColors,e):void 0)??f}const{r:p,...y}=t.config.pointStyle?.(i)??{},g={type:"point",x:d,y:h,r:p??n,style:{fill:f,opacity:s,stroke:a,strokeWidth:c,cursor:l,...y},datum:i};t.getPointId&&(g.pointId=t.getPointId(i)+""),o.push(g)}return o}(n,e);case"waterfall":return function(t,e,o){const i=[],n=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),i=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=i&&isFinite(i)});if(0===s.length)return i;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 x;x=s.length-1>e?t.getX(s[e+1])-y:e>0?y-t.getX(s[e-1]):0;const b=n.x(y),v=0!==x?n.x(y+x):b+o.width/10,w=Math.min(b,v)+l/2,k=Math.max(b,v)-l/2-w;if(0>=k){f=m;continue}const S=n.y(f),A=n.y(m),M=Math.min(S,A),_=Math.abs(S-A),P=0>g?c:a,j={...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},L={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(j)};i.push(gl(w,M,k,_,L,j)),f=m}return i}(n,e,t);case"candlestick":return function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const i=t.config.candlestickRangeMode??!1;if(!(i||t.getOpen&&t.getClose))return[];const n=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=i?s:r.upColor||"#28a745",c=i?s:r.downColor||"#dc3545",l=i?s:r.wickColor||"#333",u=r.wickWidth||(i?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 i=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));i>0&&e>i&&(e=i)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const s of e){const e=t.getX(s);if(null==e||Number.isNaN(e))continue;const d=t.getHigh(s),f=t.getLow(s);if(null==d||Number.isNaN(d)||null==f||Number.isNaN(f))continue;const p=i?d:t.getOpen(s),y=i?f:t.getClose(s);if(!i&&[p,y].some(t=>null==t||Number.isNaN(t)))continue;const g=y>=p,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(p),closeY:t.scales.y(y),highY:t.scales.y(d),lowY:t.scales.y(f),bodyWidth:h,upColor:a,downColor:c,wickColor:l,wickWidth:u,isUp:g,style:{cursor:r.cursor},datum:s};i&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),n.push(m)}return n}(n,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,i){const n=t.boundsStyle;if("function"==typeof n)return n(o||{},e);if(n&&"object"==typeof n)return n;const r=i(e,o);return{fill:r.stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none",cursor:r.cursor}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?nl(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=rl(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,i=rl(o)){const n=o.length;if(n>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=i.get(e[o]);null!=a?(r[o]=nl(t,a,n),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=i.get(e[o]);null!=r?(s[o]=nl(t,r,n),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=i.get(o);if(null!=e){const o=nl(t,e,n);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=i.get(o.datum);if(null==e)continue;const r=nl(t,e,n);"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&&cl(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,i){o.clear(),i.clear();for(let n=0;e.length>n;n++){const r=e[n],s=ll(t,r,n);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:ul(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:ul(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:ul(r.style)}):"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:ul(r.style)}):"line"===r.type?i.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&i.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],i=ll(this.transitionContext,o,e);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(i,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(i,{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,i,n,r=il()){if(0===i.size&&0===n.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=ll(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=n.get(s);if(t){if(l.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=i.get(s);if("point"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=ul(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=ul(r.style),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=ul(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=ul(r.style),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=ul(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=ul(r.style),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=ul(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=ul(r.style),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=ul(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=ul(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of n)if(!l.has(t))if(t.startsWith("l:")&&e.path){const i={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(i),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const i={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(i),a=!0}for(const[t,e]of i)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 i=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:i,closeY:e.closeY??i,highY:e.highY??i,lowY:e.lowY??i,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,i){if(!o.activeTransition)return!1;const n=el(t,o.activeTransition),r=tl(n,"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?i.get(e):void 0;t.style.opacity=ol(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=ol(o.x,t._targetX,r),t.y=ol(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=ol(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style.opacity=ol(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=ol(o.x,t._targetX,r),t.y=ol(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=ol(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style.opacity=ol(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=ol(o.x,t._targetX,r),t.y=ol(o.y,t._targetY,r),void 0!==o.w&&(t.w=ol(o.w,t._targetW,r)),void 0!==o.h&&(t.h=ol(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style={...t.style||{},opacity:ol(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=ol(o.x,t._targetX,r),t.y=ol(o.y,t._targetY,r),void 0!==o.w&&(t.w=ol(o.w,t._targetW,r)),void 0!==o.h&&(t.h=ol(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style={...t.style||{},opacity:ol(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=ol(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=ol(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=ol(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=ol(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=ol(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:ol(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 i=0;t.path.length>i;i++)t.path[i][0]=ol(e[i][0],o[i][0],r),t.path[i][1]=ol(e[i][1],o[i][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:ol(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,i=t._targetTopPath,n=t._targetBottomPath;if(e&&i&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=ol(e[o][0],i[o][0],r),t.topPath[o][1]=ol(e[o][1],i[o][1],r);if(o&&n&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=ol(o[e][0],n[e][0],r),t.bottomPath[e][1]=ol(o[e][1],n[e][1],r)}}if(n>=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,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:o}=function(t,e,o,i){if(i&&i.version===o&&i.group===e&&i.data===t)return{result:i.result,cache:i};let n;if(e){const o=new Map;for(const i of t){const t=e(i);o.has(t)||o.set(t,[]),o.get(t).push(i)}n=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else n=[{key:"_default",data:t}];return{result:n,cache:{version:o,group:e,data:t,result:n}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,i,n){if(n&&n.version===i)return{map:n.map,cache:n};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(n&&n.key===a){const t={...n,version:i};return{map:t.map,cache:t}}const c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||nt,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:i}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,i){const n=t.lineStyle;if("function"==typeof n){const t=n(o||{},e);if(t&&!t.stroke&&e){const o=i(e);if(o)return{...t,stroke:o}}return t}const r=t.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||r||"#007bff",strokeWidth:n.strokeWidth??2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity,cursor:n.cursor}:{stroke:i(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,i){if(t.areaStyle){const n=t.areaStyle(o||{});if(n&&!n.fill&&e){const t=i(e);if(t)return{...n,fill:t,stroke:n.stroke||t}}return n}const n=t.lineStyle;if("function"==typeof n){const t=n(o||{},e);if(t&&!t.fill&&e){const o=i(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}return t}const r=t.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||r||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||r||"#4e79a7",strokeWidth:n.strokeWidth??2,cursor:n.cursor};const s=i(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(e){const{color:o,groupColorCounter:i}=function(t){const{group:e,colorMapCache:o,groupColorMap:i,groupColorMapCap:n,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=i.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)||nt;if(0===c.length)return{color:null,groupColorCounter:s};const l=c[s%c.length];if(s++,i.set(e,l),i.size>n){const t=i.keys().next().value;void 0!==t&&i.delete(t)}return{color:l,groupColorCounter:s}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:t.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=i,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=Jc(t),o=this.getPointId,i=t=>e.has(o(t));Ul(this.buffer,this.timestampBuffer,i);const n=this.buffer.remove(i);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const o=Jc(t),i=this.getPointId,n=new Set;this.buffer.forEach((t,e)=>{o.has(i(t))&&n.add(e)});const r=this.buffer.update(t=>o.has(i(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{n.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const i of t){const t=this._baseStyles.get(i)??i.style??{},n=o(i,e);i.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.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 t||"themeCategorical"in t||"colorAccessor"in t)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in t||"colorScheme"in t)&&(this._barCategoryCache=null),("normalize"in t||"extentPadding"in t||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t||"boundsAccessor"in t||"band"in t||"y0Accessor"in t||"openAccessor"in t||"highAccessor"in t||"lowAccessor"in t||"closeAccessor"in t||"groupAccessor"in t||"categoryAccessor"in t||"chartType"in t||"runtimeMode"in t)&&(this._stackExtentCache=null);let i=!1,n=!1;Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();const r="chartType"in t&&t.chartType!==e.chartType||"runtimeMode"in t&&t.runtimeMode!==e.runtimeMode;if(r||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t){const t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=t&&this.config.valueAccessor||this.config.yAccessor,s=t&&e.valueAccessor||e.yAccessor,a=r||!qc(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),c=r||!qc(o,s);(a||c)&&(t?(this.getX=Xc(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=Xc(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=Xc(this.config.xAccessor,"x"),this.getY=Xc(this.config.yAccessor,"y")),c&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=Wl(this.config)),i=!0,n=!0)}if("groupAccessor"in t&&!qc(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?Vc(this.config.groupAccessor):void 0,i=!0),"categoryAccessor"in t&&!qc(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?Vc(this.config.categoryAccessor):void 0,i=!0),"sizeAccessor"in t&&!qc(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?Xc(this.config.sizeAccessor,"size"):void 0,i=!0),"symbolAccessor"in t&&!qc(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Vc(this.config.symbolAccessor):void 0,i=!0),"colorAccessor"in t&&!qc(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Vc(this.config.colorAccessor):void 0,i=!0),"y0Accessor"in t&&!qc(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?Xc(this.config.y0Accessor,"y0"):void 0,i=!0,n=!0),("boundsAccessor"in t&&!qc(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=Wl(this.config),i=!0,n=!0),"pointIdAccessor"in t&&!qc(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?Vc(this.config.pointIdAccessor):void 0,i=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!qc(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!qc(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!qc(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!qc(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?Xc(this.config.openAccessor,"open"):void 0,this.getHigh=Xc(this.config.highAccessor,"high"),this.getLow=Xc(this.config.lowAccessor,"low"),this.getClose=e?Xc(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,i=!0,n=!0}if("accessorRevision"in t&&t.accessorRevision!==e.accessorRevision&&(i=!0,n=!0),!i){const o=Object.keys(t).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const n of o)if(t[n]!==e[n]){i=!0;break}}i&&(n&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};bu.GROUP_COLOR_MAP_CAP=1e3;var vu=bu;iu(vu);var wu=c(require("react")),ku=require("d3-shape");function Su(t,e,o){let i=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(i=o.color):t>o.value&&(i=o.color);return i}var Au=[40,40],Mu=[.5,.5];function _u(t,e){const[o,i]=t.viewBox??Au,[n,r]=t.anchor??Mu,s=i>0?i:1,a=Math.max(0,e)/s,c=(o>0?o:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-n*c,offsetY:-r*l}}function Pu(t,e,o,i){if("none"!==t)return"color"===t||null==t?e??i:"accent"===t?o:t}function ju(t,e){const o=_u(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}}var Lu=require("react/jsx-runtime"),$u={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function Ru(t,e="#4e79a7"){return xn(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function Cu(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function Iu(t,e,o,i){const n=t.glyph;if(!n?.parts?.length||0>=t.size)return null;const r=_u(n,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=function(t,e,o=0,i="horizontal"){const[n,r]=t.viewBox??Au,s=Math.min(1,Math.max(0,o)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===i?{x:0,y:r*(1-a),width:n,height:r*(a-s)}:{x:n*s,y:0,width:n*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(n,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),l=c?Cu(i+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>n.parts.map((o,i)=>{const n=e?"none"===o.fill?void 0:e:Pu(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:Pu(o.stroke??"none",a,t.accent);return n||r?(0,Lu.jsx)("path",{d:o.d,fill:n??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},i):null});return(0,Lu.jsxs)("g",{transform:s,opacity:1===u?void 0:u,children:[c&&l&&(0,Lu.jsx)("clipPath",{id:l,children:(0,Lu.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&t.ghostColor?(0,Lu.jsx)("g",{children:d(t.ghostColor)}):null,c&&l?(0,Lu.jsx)("g",{clipPath:`url(#${l})`,children:d()}):d()]},i)}function Tu(t,e){const o=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>o.length?null:o.map((t,e)=>(0,Lu.jsx)("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function Ou(t,e,o){const i=$l(t.symbolType,t.size,t.path);return(0,Lu.jsx)("path",{d:i,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?Ru(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}c(require("react"));var zu=require("react/jsx-runtime");function Fu(t){if(!1!==t?.interactive)return t?.style?.cursor}function Nu(t,e,o){const i=Fu(e);return i&&null!=t&&!1!==t?(0,zu.jsx)("g",{style:{cursor:i},"data-semiotic-mark-cursor":i,children:t},o):t}var Eu=c(require("react")),Du=require("d3-shape"),Bu=require("react/jsx-runtime");var Wu=c(require("react")),Yu=require("react/jsx-runtime");var qu=c(require("react")),Xu=require("d3-shape"),Gu=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function Vu(t){const{innerRadius:e,outerRadius:o,startAngle:i,endAngle:n}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=Gu(o,i),e=Gu(o,n);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${n-i>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=Gu(o,i),s=Gu(o,n),a=Gu(e,n),c=Gu(e,i),l=n-i>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 Vu({...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=n-i,u=t.roundStart&&t.roundEnd?l/2:l,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return Vu({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=i+(d?a:0),p=n-(h?a:0),y=i+(d?c:0),g=n-(h?c:0),m=Gu(o,f),x=Gu(o,p),b=(o-s)*Math.cos(a),v=Gu(b,i),w=Gu(b,n),k=r?null:Gu(e,g),S=r?null:Gu(e,y),A=r?0:(e+s)*Math.cos(c),M=r?null:Gu(A,i),_=r?null:Gu(A,n),P=p-f>Math.PI?1:0,j=r?0:g-y>Math.PI?1:0;let L="";if(d)L+=`M${v.x},${v.y}`,L+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=Gu(o,i);L+=`M${t.x},${t.y}`}if(h)L+=` A${o},${o} 0 ${P} 1 ${x.x},${x.y}`,L+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=Gu(o,n);L+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)L+=" L0,0";else{if(h)L+=` L${_.x},${_.y}`,L+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=Gu(e,n);L+=` L${t.x},${t.y}`}if(d)L+=` A${e},${e} 0 ${j} 0 ${S.x},${S.y}`,L+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=Gu(e,i);L+=` A${e},${e} 0 ${j} 0 ${t.x},${t.y}`}}return L+=" Z",L}var Hu=require("react/jsx-runtime");function Uu(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 Ku(t,e){const o=t.datum;if(!o)return null;const i=[],n=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof n||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*n.length+16>a||i.push((0,Hu.jsx)("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:n},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 n=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${Uu(c)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:Uu(c);7.8*n.length+16>d&&(n=Uu(c)),7.8*n.length+16>d||i.push((0,Hu.jsx)("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:n},e+"-funnel-value"))}return i.length?(0,Hu.jsx)("g",{children:i},e+"-funnel-labels"):null}function Zu(t,e,o){return Nu(function(t,e,o){const i=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",n=o=>`ord-${t.type}-${i}-${e}-${o}`,r=`ord-${t.type}-${i}-${e}`;switch(t.type){case"rect":{const e=t,o=Cu(r)+"-grad",i=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let i=t.x,n=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(n=t.y+t.h,s=t.y):"right"===t.roundedEdge?(i=t.x+t.w,n=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(i=t.x,n=t.y,r=t.x+t.w,s=t.y);const a=Tu(o.stops,Ru(t.style.fill));return a?(0,Lu.jsx)("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:i,y1:n,x2:r,y2:s,children:a}):null}(e,o);let n,a;if(i)a=`url(#${o})`;else if(xn(e.style.fill)){const t=Cu(r)+"-hatch";n=bn(e.style.fill,t),a=`url(#${t})`}else a=Ru(e.style.fill);const c=i||n?(0,Hu.jsxs)("defs",{children:[i,n]}):null;if(e.cornerRadii&&(((s=e.cornerRadii).tl??0)>0||(s.tr??0)>0||(s.br??0)>0||(s.bl??0)>0)){const t=function(t){const{x:e,y:o,w:i,h:n}=t,{tl:r,tr:s,br:a,bl:c}=function(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,i=t=>Math.max(0,Math.min(t??0,o));return{tl:i(e.tl),tr:i(e.tr),br:i(e.br),bl:i(e.bl)}}(t);let l=`M${e+r},${o}`;return l+=` L${e+i-s},${o}`,s>0&&(l+=` A${s},${s} 0 0 1 ${e+i},${o+s}`),l+=` L${e+i},${o+n-a}`,a>0&&(l+=` A${a},${a} 0 0 1 ${e+i-a},${o+n}`),l+=` L${e+c},${o+n}`,c>0&&(l+=` A${c},${c} 0 0 1 ${e},${o+n-c}`),l+=` L${e},${o+r}`,r>0&&(l+=` A${r},${r} 0 0 1 ${e+r},${o}`),l+=" Z",l}(e);return(0,Hu.jsxs)(qu.Fragment,{children:[c,(0,Hu.jsx)("path",{d:t,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:i,w:n,h:s}=e;let l;switch(e.roundedEdge){case"right":l=`M${o},${i} L${o+n-t},${i} A${t},${t} 0 0 1 ${o+n},${i+t} L${o+n},${i+s-t} A${t},${t} 0 0 1 ${o+n-t},${i+s} L${o},${i+s} Z`;break;case"left":l=`M${o+n},${i} L${o+t},${i} A${t},${t} 0 0 0 ${o},${i+t} L${o},${i+s-t} A${t},${t} 0 0 0 ${o+t},${i+s} L${o+n},${i+s} Z`;break;case"bottom":l=`M${o},${i} L${o+n},${i} L${o+n},${i+s-t} A${t},${t} 0 0 1 ${o+n-t},${i+s} L${o+t},${i+s} A${t},${t} 0 0 1 ${o},${i+s-t} Z`;break;default:l=`M${o},${i+s} L${o},${i+t} A${t},${t} 0 0 1 ${o+t},${i} L${o+n-t},${i} A${t},${t} 0 0 1 ${o+n},${i+t} L${o+n},${i+s} Z`}return(0,Hu.jsxs)(qu.Fragment,{children:[c,(0,Hu.jsx)("path",{d:l,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return(0,Hu.jsxs)(qu.Fragment,{children:[c,(0,Hu.jsx)("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),Ku(e,r)]},r)}case"point":{const e=t;return(0,Hu.jsx)("circle",{cx:e.x,cy:e.y,r:e.r,fill:Ru(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return Ou(t,e,o);case"glyph":return Iu(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const i=t;if(i._gradientBand&&i._gradientBand.colors.length>0){const t=Cu(`${o?o+"-":""}gauge-grad-${i.category||r}-${e}`),{clipPath:n,slices:s}=function(t){const e=Vu({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],i=t.colors;if(i.length>0){const e=(t.endAngle-t.startAngle)/i.length;for(let n=0;i.length>n;n++)o.push({d:Vu({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+n*e,endAngle:t.endAngle}),color:i[n]})}return{clipPath:e,slices:o}}({innerRadius:i.innerRadius,outerRadius:i.outerRadius,startAngle:i.startAngle,endAngle:i.endAngle,cornerRadius:i.cornerRadius,roundStart:i.roundedEnds?.start??!0,roundEnd:i.roundedEnds?.end??!0,colors:i._gradientBand.colors});return(0,Hu.jsxs)("g",{transform:`translate(${i.cx},${i.cy})`,opacity:i.style.opacity,fillOpacity:i.style.fillOpacity,children:[(0,Hu.jsx)("defs",{children:(0,Hu.jsx)("clipPath",{id:t,children:(0,Hu.jsx)("path",{d:n})})}),(0,Hu.jsx)("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>(0,Hu.jsx)("path",{d:t.d,fill:Ru(t.color)},e))}),i.style.stroke&&"none"!==i.style.stroke&&(0,Hu.jsx)("path",{d:n,fill:"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},r)}let n;if(i.roundedEnds)n=Vu({innerRadius:i.innerRadius,outerRadius:i.outerRadius,startAngle:i.startAngle,endAngle:i.endAngle,cornerRadius:i.cornerRadius,roundStart:i.roundedEnds.start,roundEnd:i.roundedEnds.end});else{const t=(0,Xu.arc)().innerRadius(i.innerRadius).outerRadius(i.outerRadius).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2);i.cornerRadius&&t.cornerRadius(i.cornerRadius),n=t($u)||""}return(0,Hu.jsx)("path",{d:n,transform:`translate(${i.cx},${i.cy})`,fill:Ru(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2,i=e.style.strokeWidth??1;return(0,Hu.jsxs)("g","vertical"===e.projection?{children:[(0,Hu.jsx)("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:Ru(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*i}),(0,Hu.jsx)("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:i})]}:{children:[(0,Hu.jsx)("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:Ru(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*i}),(0,Hu.jsx)("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:i}),(0,Hu.jsx)("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:i})]},r)}case"violin":{const e=t,o=[(0,Hu.jsx)("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:Ru(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth??1},n("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,i=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push((0,Hu.jsx)("line",{x1:i,y1:e.iqrLine.q1Pos,x2:i,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),(0,Hu.jsx)("circle",{cx:i,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med"))):o.push((0,Hu.jsx)("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),(0,Hu.jsx)("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med")))}return(0,Hu.jsx)("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?Ru(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return(0,Hu.jsx)("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||o,strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity??.5},r)}case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return(0,Hu.jsx)("polygon",{points:o,fill:Ru(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}var s}(t,e,o),t,"ordinal-cursor-"+e)}var Qu=require("react/jsx-runtime");function Ju(t,e,o,i){if(!t||2>e.length)return null;const n=Tu(t.stops,i);return n?(0,Qu.jsx)("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:n}):null}function td(t,e,o,i=30){const n=function(t,e,o,i=30){switch(t.type){case"line":{const i=t;if(0===i.path.length)return null;const n=Ha(i.curve),r=n?(0,ku.line)().x(([t])=>t).y(([,t])=>t).curve(n)(i.path)??"":"M"+i.path.map(([t,e])=>`${t},${e}`).join("L"),s=Cu(`${o?o+"-":""}line-${e}-stroke-gradient`),a=Ju(i.strokeGradient,i.path,s,i.style.stroke||"#4e79a7");return(0,Qu.jsxs)(wu.Fragment,{children:[a&&(0,Qu.jsx)("defs",{children:a}),(0,Qu.jsx)("path",{d:r,fill:"none",stroke:a?`url(#${s})`:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth??2,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity})]},"line-"+e)}case"area":{const n=t;if(0===n.topPath.length)return null;const r=Ha(n.curve),s=!r||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`:(0,ku.area)().x(([t])=>t).y0((t,e)=>n.bottomPath[e][1]).y1(([,t])=>t).curve(r)(n.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,c=xn(n.style.fill)?bn(n.style.fill,a):void 0,l=Cu(`${o?o+"-":""}area-${e}-gradient`),u=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let i=1/0;for(const[,e]of t.topPath)i=Math.min(i,e);let n=-1/0;for(const[,e]of t.bottomPath)n=Math.max(n,e);if(!Number.isFinite(i)||!Number.isFinite(n))return null;const r=Tu(o.stops,Ru(t.style.fill));return r?(0,Qu.jsx)("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:i,x2:0,y2:n,children:r}):null}(n,l),d=u?`url(#${l})`:c?`url(#${a})`:Ru(n.style.fill),h=u?void 0:n.style.fillOpacity??n.style.opacity??.7,f=r?(0,ku.line)().x(([t])=>t).y(([,t])=>t).curve(r)(n.topPath)??"":"M"+n.topPath.map(([t,e])=>`${t},${e}`).join("L"),p=Fu(n),y=p&&i>=0?(0,Qu.jsx)("path",{d:f,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*i),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:p},"data-semiotic-mark-cursor":p,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,g=Cu(`${o?o+"-":""}area-${e}-stroke-gradient`),m=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),x=!!n.strokeColorBands?.length,b=m||x?null:Ju(n.strokeGradient,n.topPath,g,n.style.stroke||"#4e79a7"),v=n.style.strokeWidth??2;let w=1/0,k=-1/0;for(const[t]of n.topPath)w>t&&(w=t),t>k&&(k=t);const S=x?n.strokeColorBands.map((t,i)=>Cu(`${o?o+"-":""}area-${e}-stroke-band-${i}`)):[],A=x?n.strokeColorBands.map((t,e)=>(0,Qu.jsx)("clipPath",{id:S[e],children:(0,Qu.jsx)("rect",{x:w-v,y:t.y,width:k-w+2*v,height:t.height})},S[e])):null,M=n.style.stroke&&"none"!==n.style.stroke?x?n.strokeColorBands.map((t,o)=>(0,Qu.jsx)("path",{d:f,fill:"none",stroke:t.color??Ru(n.style.stroke),strokeWidth:v,opacity:(n.style.opacity??1)*(t.opacity??1),clipPath:`url(#${S[o]})`},`area-${e}-stroke-band-${o}`)):m?function(t,e,o,i){if(2>t.length||e.length!==t.length||0===o.length)return[];const n=[],r=(t,e,o)=>{const i=n[n.length-1];i?.color===t?i.path.push(o):n.push({color:t,path:[e,o]})};for(let n=1;t.length>n;n++){const[s,a]=t[n-1],[c,l]=t[n],u=e[n-1],d=e[n]-u,h=[0,...0===d?[]:o.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,o)=>0===e||t!==o[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],n=h[t];r(Su(u+d*((e+n)/2),o,i),[s+(c-s)*e,a+(l-a)*e],[s+(c-s)*n,a+(l-a)*n])}}return n}(n.topPath,n.rawValues,n.colorThresholds,Ru(n.style.stroke)).map((t,o)=>(0,Qu.jsx)("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:v,opacity:n.style.opacity},`area-${e}-threshold-${o}`)):(0,Qu.jsx)("path",{d:f,fill:"none",stroke:b?`url(#${g})`:Ru(n.style.stroke),strokeWidth:v,opacity:n.style.opacity}):null;if(n.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return(0,Qu.jsxs)("g",{children:[(0,Qu.jsxs)("defs",{children:[u,!u&&c,b,A,(0,Qu.jsx)("clipPath",{id:t,children:(0,Qu.jsx)("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),(0,Qu.jsxs)("g",{clipPath:`url(#${t})`,children:[(0,Qu.jsx)("path",{d:s,fill:d,fillOpacity:h,opacity:u?n.style.opacity:void 0,stroke:"none"}),M,y]})]},"area-"+e)}return(0,Qu.jsxs)(wu.Fragment,{children:[(u||c||b||A)&&(0,Qu.jsxs)("defs",{children:[u,!u&&c,b,A]}),(0,Qu.jsx)("path",{d:s,fill:d,fillOpacity:h,opacity:u?n.style.opacity:void 0,stroke:"none"}),M,y]},"area-"+e)}case"point":{const i=t,n=`${o?o+"-":""}point-${e}-hatch`,r=xn(i.style.fill)?bn(i.style.fill,n):void 0;return(0,Qu.jsxs)(wu.Fragment,{children:[r&&(0,Qu.jsx)("defs",{children:r}),(0,Qu.jsx)("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#${n})`:Ru(i.style.fill),opacity:i.style.opacity??i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"point-"+e)}case"symbol":return Ou(t,e);case"glyph":return Iu(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const i=t,n=`${o?o+"-":""}xyrect-${e}-hatch`,r=xn(i.style.fill)?bn(i.style.fill,n):void 0;return(0,Qu.jsxs)(wu.Fragment,{children:[r&&(0,Qu.jsx)("defs",{children:r}),(0,Qu.jsx)("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:r?`url(#${n})`:Ru(i.style.fill),opacity:i.style.opacity,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t,i={x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth,...null!=o.style?.opacity&&{opacity:o.style.opacity}};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,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),a=.299*n+.587*r+.114*s>128?"#000":"#fff",c=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return(0,Qu.jsxs)("g",{children:[(0,Qu.jsx)("rect",{...i}),(0,Qu.jsx)("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:c+"px",children:t})]},"heatcell-"+e)}return(0,Qu.jsx)("rect",{...i},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return(0,Qu.jsxs)("g",{children:[(0,Qu.jsx)("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),(0,Qu.jsx)("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),(0,Qu.jsx)("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const i=Math.min(o.openY,o.closeY),n=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return(0,Qu.jsxs)("g",{children:[(0,Qu.jsx)("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),(0,Qu.jsx)("rect",{x:o.x-o.bodyWidth/2,y:i,width:o.bodyWidth,height:n,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}(t,e,o,i);return"area"===t.type?n:Nu(n,t,"xy-cursor-"+e)}var ed=new Set;function od(t){const{node:e,index:o,renderMode:i,fallback:n}=t,r=function(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(i=o)&&"object"==typeof i&&"string"==typeof i.id&&"function"==typeof i.cacheKey&&"function"==typeof i.drawCanvas&&"function"==typeof i.renderStaticSVG?o:void 0;var i}(i,e);if(!r)return{element:n(),renderedByBackend:!1};const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?{element:Nu(s,e,`${r.id}-${o}-cursor`),renderedByBackend:!0}:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;ed.has(o)||(ed.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),{element:n(),renderedByBackend:!1})}function id(t){const e=[];return t.nodes.forEach((o,i)=>{const n=od({node:o,index:i,renderMode:t.renderMode,fallback:()=>t.fallback(o,i)});null!=n.element&&!1!==n.element&&e.push({node:o,index:i,...n})}),e}var nd=require("d3-scale"),rd=require("react/jsx-runtime"),sd=xe;function ad(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>ct(t,e)??"#999"}const i=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:C;return(0,nd.scaleOrdinal)().domain(t).range(i)}function cd(t,e,o){if(0===t.length)return;const i=ad(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:i(t.label)})}]}}function ld(t){return"left"===t?"start":"right"===t?"end":t??"start"}function ud(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function dd(t){return t.typography.legendFontFamily??t.typography.fontFamily}function hd(t){return t.typography.legendFontWeight}function fd(t,e,o,i){const n=ud(i);return e+o+Math.ceil(t.length*n*.58)}function pd(t){const{categories:e,theme:o,position:i="right",totalWidth:n,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=We(s),d=a+c,h="top"===i||"bottom"===i,f=Math.max(a,n-r.left-r.right),p=e.map(t=>fd(t,a,c,o));if(h){const t=Math.max(a,s?.maxWidth??f),o=[];let i=0,n=0;p.forEach((e,r)=>{const s=0===n?e:n+l+e;n>0&&s>t?(o.push({start:i,end:r,width:n}),i=r,n=e):n=s}),e.length>0&&o.push({start:i,end:e.length,width:n});const r=ld(s?.align),c=[];return o.forEach((o,i)=>{let n="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:n,y:i*u}),n+=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 yd(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],i=new Set;for(const e of t){const t=o(e);null!=t&&i.add(t+"")}return Array.from(i)}var gd=require("react/jsx-runtime");function md(t,e=120,o=8){if(!t)return[];const i=Math.max(1,Math.floor(e/o)),n=t.split(/\s+/),r=[];let s="";for(const t of n)s&&s.length+1+t.length>i?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function xd(t,e,o,i){return"curly"===t?i?`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`:i?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function bd(t,e,o,i){if(!t)return(0,gd.jsx)("g",{className:"annotation-note"});const{label:n,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=t;if(!n&&!r)return(0,gd.jsx)("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]:md(r,c):[],y=n?l?[n]:md(n,c):[],g="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push((0,gd.jsx)("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&&n?2:0))+f,style:{overflow:"visible"},children:(0,gd.jsxs)("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&(0,gd.jsx)("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),n&&(0,gd.jsx)("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html")):(p.length>0&&(x.push((0,gd.jsx)("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>(0,gd.jsx)("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&x.push((0,gd.jsx)("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:y.map((t,e)=>(0,gd.jsx)("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||n)&&(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=(0,gd.jsx)("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:i||"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=(0,gd.jsx)("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:i||"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),(0,gd.jsxs)("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[(0,gd.jsx)("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function vd(t,e,o,i,n){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push((0,gd.jsx)("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,i=e?.height||0;(t>0||i>0)&&r.push((0,gd.jsx)("rect",{width:t,height:i,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=i||0,s=n||0;if(void 0!==e?.x){const i=(e.x||0)-t;r.push((0,gd.jsx)("line",{x1:i,y1:(e.y1||0)-s,x2:i,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const i=(e.y||0)-s;r.push((0,gd.jsx)("line",{x1:(e.x1||0)-t,y1:i,x2:(e.x2||0)-t,y2:i,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push((0,gd.jsx)("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((0,gd.jsx)("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",i=e?.width??e?.height;void 0!==i&&r.push((0,gd.jsx)("path",{d:xd(t,i,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return(0,gd.jsx)("g",{className:"annotation-subject",children:r})}function wd(t,e,o,i,n,r){const s=[];let a=0,c=0;if("callout-circle"!==n&&"label"!==n||!r?.radius){if("callout-rect"===n&&r){const o=r.width||0,i=r.height||0;if(o>0||i>0){const n=o/2,r=i/2,s=t-n,l=e-r;if(0!==s||0!==l){const t=Math.abs(s),e=Math.abs(l),u=o/2,d=i/2,h=t*d>e*u?u/t:d/e;a=n+s*h,c=r+l*h}}}else if("bracket"===n&&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 i=Math.atan2(e,t);a=Math.cos(i)*o,c=Math.sin(i)*o}}const l=Math.sqrt((t-a)**2+(e-c)**2);if(l>.5){const n=i||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-c,t-a);if(r){const i=(a+t)/2,r=(c+e)/2,d=-(e-c)/l,h=(t-a)/l,f=(o?.curve??.25)*l,p=i+d*f,y=r+h*f;s.push((0,gd.jsx)("path",{className:"connector-curve",d:`M${a},${c}Q${p},${y} ${t},${e}`,fill:"none",stroke:n},"connector-line")),u=Math.atan2(y-c,p-a)}else s.push((0,gd.jsx)("line",{x1:a,y1:c,x2:t,y2:e,stroke:n},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push((0,gd.jsx)("path",{d:`M${a},${c}L${a+t*Math.cos(u+e)},${c+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${c+t*Math.sin(u-e)}Z`,fill:n,stroke:"none"},"connector-arrow"))}}return(0,gd.jsx)("g",{className:"annotation-connector",children:s})}function kd(t){const{x:e=0,y:o=0,dx:i,dy:n,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,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(f)?f:[]);let w=i||0,k=n||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const S="string"==typeof u?u:"label";if("bracket"===S&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const t=l.depth||30;k=t+(0>t?-5:5)}else if(void 0!==l.height){const t=l.depth||30;w=t+(0>t?-5:5),k=l.height/2}return(0,gd.jsxs)("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&wd(w,k,c,d,S,l),!v.has("subject")&&vd(S,l,d,x,b),!v.has("note")&&bd(a,w,k,d)]})}function Sd(t){const{noteData:e}=t,{screenCoordinates:o}=e,i="string"==typeof e.type?e.type:"label",n=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),n=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:n});return(0,gd.jsx)(kd,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+r)});return(0,gd.jsx)("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return(0,gd.jsx)(kd,{"data-testid":"semiotic-annotation",events:n,...e,type:i},s)}var Ad=require("react/jsx-runtime"),Md={secondary:0,primary:3},_d=1,Pd=2,jd=.6,Ld="0.88em",$d=.95,Rd=.72,Cd=.06,Id=".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}}",Td=".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}";function Od(t){return!0===t?._annotationDeferred}function zd(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Fd(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Nd(t){return Math.max(Rd,$d-t*Cd)}function Ed(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:Fd(t.annotation),readingOrder:null,rank:_d};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),i=t.some(t=>Od(t.annotation)),n=t.some(t=>null!=zd(t.annotation)),r=t.some(t=>"layer"===zd(t.annotation));if(!o&&!i&&!n)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=Pd-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=Md[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:i,readingOrder:n}=t,r=Od(e.annotation);let s=e.node;if("primary"===i||"secondary"===i||null!=n){const t=null==i&&null!=n;s=(0,Ad.jsx)("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:jd,fontSize:Ld}:{},...t?{opacity:Nd(n),"data-annotation-reading-order":n}:{},children:e.node},"annotation-emphasis-"+o)}const a=zd(e.annotation);return a&&(s=(0,Ad.jsx)("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=(0,Ad.jsx)("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return i&&a.unshift((0,Ad.jsx)("style",{children:Id},"annotation-disclosure-style")),r&&a.unshift((0,Ad.jsx)("style",{children:Td},"annotation-cohesion-style")),a}function Dd(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 Bd(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 Wd(t){return null==t?null:t+""}function Yd(t,e,o){return e.stickyPositionCache?.set(t,o),o}function qd(t,e,o){const i=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===i){if(null!=t.pointId&&o.pointNodes&&o.pointNodes.length>0)for(let i=o.pointNodes.length-1;i>=0;i--){const n=o.pointNodes[i];if(n.pointId===t.pointId)return Yd(e,o,{x:n.x,y:n.y})}const i=function(t){const e=t.data;if(!e||0===e.length)return null;const o=e[e.length-1],i=t.scales?.x??t.scales?.time,n=t.scales?.y??t.scales?.value;if(!i||!n)return null;const r=o[t.xAccessor||"x"],s=o[t.yAccessor||"y"];return null==r||null==s?null:{x:i(r),y:n(s)}}(o);return i?Yd(e,o,i):null}if("semantic"===i){const i=function(t,e,o){const i=function(t){return Wd(t.provenance?.stableId??t.stableId)}(t);if(!i)return null;const n=o.pointNodes?.find(t=>Wd(t.pointId)===i);if(n)return Yd(e,o,{x:n.x,y:n.y});const r=o.data?.find(t=>function(t){return Wd(t.stableId??t.id??t.provenance?.stableId)}(t)===i);if(!r)return null;const s=Dd(r,o),a=Bd(r,o);return null==s||null==a?null:Yd(e,o,{x:s,y:a})}(t,e,o);if(i)return i}let n=null,r=null;if(null!=t.pointId&&o.pointNodes){const e=o.pointNodes.find(e=>e.pointId===t.pointId);e&&(n=e.x,r=e.y)}if(null!=n&&null!=r||(n=Dd(t,o),r=Bd(t,o)),null!=n&&null!=r)return Yd(e,o,{x:n,y:r});if("sticky"===i){const t=o.stickyPositionCache?.get(e);if(t)return t}return null}var Xd=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function Gd(t){return!!t&&"object"==typeof t&&Xd.has(function(t){return"string"==typeof t?.type?t.type:""}(t))}new Set(["label","callout","callout-circle","callout-rect"]);var Vd=2e4,Hd=1;function Ud(t){return"primary"===t?.emphasis||!0===t?.defensive}function Kd(t,e,o={}){return"number"==typeof o.maxAnnotations&&Number.isFinite(o.maxAnnotations)?Math.max(0,Math.floor(o.maxAnnotations)):t>0&&e>0?Math.max(1,Math.round(t*e/(o.areaPerAnnotation&&o.areaPerAnnotation>0?o.areaPerAnnotation:Vd))):1/0}function Zd(t){let e;const o=t?.emphasis;e="primary"===o?100:"secondary"===o?10:50;const i=t?.provenance?.confidence;switch("number"==typeof i&&Number.isFinite(i)&&(e+=15*Math.max(0,Math.min(1,i))),t?.lifecycle?.freshness){case"fresh":e+=8;break;case"aging":e+=4;break;case"stale":e+=1;break;case"expired":e-=200}return e}var Qd=32,Jd=6,th=4,eh=8,oh=72,ih=30,nh=-30,rh=8,sh=480,ah=3;var ch={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function lh(t){if(!uh(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 uh(t){return Gd(t)}function dh(t,e){if(!t)return[];const o=Math.max(1,Math.floor(e/7)),i=t.split(/\s+/).filter(Boolean),n=[];let r="";for(const t of i)r&&r.length+t.length+1>o?(n.push(r),r=t):r=r?`${r} ${t}`:t;return r&&n.push(r),n}function hh(t,e,o,i,n){const r=t+o,s=e+i;return Math.abs(o)>Math.abs(i)?{x:0>o?r-n.width-4:r+4,y:0>i?s-n.height:s,width:n.width,height:n.height}:{x:0>o?r-n.width:r,y:0>i?s-n.height-4:s+4,width:n.width,height:n.height}}function fh(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function ph(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 yh(t,e,o,i,n,r,s,a){const c=fh(t,s);let l=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,o,i){const n=Math.max(0,i-t.x),r=Math.max(0,i-t.y);return(n+Math.max(0,t.x+t.width-(e-i)))*t.height+(r+Math.max(0,t.y+t.height-(o-i)))*t.width}(c,n,r,a);for(const t of o)l+=12*ph(c,t);for(const t of i)l+=4*ph(c,t);return l}function gh(t){const{annotations:e,context:o,defaultOffset:i=Qd,notePadding:n=Jd,markPadding:r=th,edgePadding:s=eh,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=oh,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:f,mobile:p,cohesion:y,audience:g}=t,m=o.width||0,x=o.height||0,b="object"==typeof p?p:{},v=b.breakpoint??sh,w=!!p&&v>=m,k=w&&!1!==b.preferShortText?e.map(lh):e,S=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!f?b.responsive??{minWidth:v}:f,_=w&&!y?b.cohesion:y;if(0===k.length||0>=m||0>=x)return k.slice();const P=[],j=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}})}(o,r);let L=!1;const $=k.map((t,e)=>{if(!uh(t))return t;const r=function(t,e,o){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const i=t.pointId??t.nodeId;if(null!=i&&o.pointNodes){const t=o.pointNodes.find(t=>t.pointId===i);if(t)return{x:t.x,y:t.y}}const n=t.coordinates,r=o.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&r){const t=n[0],e=n[1];if("number"==typeof t&&"number"==typeof e){const 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?qd(t,e,o):{x:t.x,y:t.y}}(t,e,o);if(!r)return t;const u=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=[...dh("string"==typeof t.title?t.title:void 0,e),...dh("string"==typeof t.label?t.label:void 0,e)],i=o.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*i)+10),height:Math.max(18,16*o.length+6)}}(t);if(a&&("number"==typeof(d=t).dx||"number"==typeof d.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:ih,dy:nh}}(t);return P.push(fh(hh(r.x,r.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,u),n)),t}var d;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}]}(i)){const e=yh(hh(r.x,r.y,t.dx,t.dy,u),t,P,j,m,x,n,s);f>e&&(h=t,f=e)}if(!h)return t;const p=fh(hh(r.x,r.y,h.dx,h.dy,u),n);P.push(p);const y=Math.hypot(h.dx,h.dy),g=c&&y>=l&&"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}:{}}}),R=L?$:k.slice();let C=R;if(h){let t=!1;const e=R.map(e=>{const o=function(t){return"text"!==t.type||"string"!=typeof t.color||Math.hypot("number"==typeof t.dx?t.dx:0,"number"==typeof t.dy?t.dy:0)<rh?t:{...t,_redundantConnector:!0}}(e);return o!==e&&(t=!0),o});C=t?e:R}{let t=!1;const e=C.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?Object.prototype.hasOwnProperty.call(ch,e.source)?ch[e.source]:e.source:null,i="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!o&&!i)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const n=[o,i].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${n})`)?t:{...t,label:r?`${r} (${n})`:`(${n})`}}(e);return o!==e&&(t=!0),o});C=t?e:C}const I=new Set;if(S){const t="object"==typeof S?S:{},e=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return ah;const o=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===o.length?ah:o.reduce((t,e)=>t+e,0)/o.length}(t);return e>2?4>e?1:.6:1.5}(g),o=1===e?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??Kd(m,x,t))*e))},{deferred:i}=function(t){const{annotations:e,width:o,height:i}=t,n=Math.max(0,t.minVisible??Hd),r=Kd(o,i,t),s=e.map((t,e)=>{return{annotation:t,index:e,note:(o=t,Gd(o))};var o}),a=s.filter(t=>t.note);if(0===a.length||r>=a.length)return{visible:e.slice(),deferred:[],budget:r};const c=a.filter(t=>Ud(t.annotation)),l=a.filter(t=>!Ud(t.annotation)).sort((t,e)=>Zd(e.annotation)-Zd(t.annotation)||t.index-e.index),u=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,n-c.length))),d=new Set([...c.map(t=>t.index),...l.slice(0,u).map(t=>t.index)]),h=[],f=[];for(const{annotation:t,index:e,note:o}of s)!o||d.has(e)?h.push(t):f.push(t);return{visible:h,deferred:f,budget:r}}({annotations:C,width:m,height:x,...o});for(const t of i)I.add(t)}if(M&&("object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:sh)>=m)for(const t of C)uh(t)&&"secondary"===t.emphasis&&I.add(t);if(I.size>0)for(const t of C)!0===t?.defensive&&I.delete(t);let T;return T=0===I.size?C:A?C.map(t=>I.has(t)?{...t,_annotationDeferred:!0}:t):C.filter(t=>!I.has(t)),_?function(t,e){let o=!1;const i=t.map(t=>uh(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(o=!0,{...t,cohesion:e}):t);return o?i:t}(T,_):T}var mh=require("react/jsx-runtime"),xh="var(--semiotic-bg, #ffffff)",bh=.85;function vh(t){const{x:e,y:o,text:i,fill:n,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=>(0,mh.jsx)("text",{x:e,y:o,textAnchor:c,dominantBaseline:l,fill:n,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{style:{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}}:{},children:i});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??xh,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}(i,r),x=r+2*g;let b,v;return b="middle"===c?e-m/2-y:"end"===c?e-m-y:e-y,v="middle"===l||"central"===l?o-x/2:"hanging"===l||"text-before-edge"===l?o-g:o-.8*r-g,(0,mh.jsxs)("g",{className:d,children:[(0,mh.jsx)("rect",{x:b,y:v,width:m+2*y,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??xh,fillOpacity:h.opacity??bh,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}function wh(t,e,o,i){const n=function(t,e,o="#4e79a7"){if(xn(t)){const o=function(t,e){let o=2166136261;const i=function(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}(e);for(let t=0;i.length>t;t++)o^=i.charCodeAt(t),o=Math.imul(o,16777619);return`${t}-hatch-${(o>>>0).toString(36)}`}(e,t);return{fill:`url(#${o})`,def:bn(t,o)}}return t&&"string"==typeof t?{fill:t}:{fill:o}}(t.fill??t.color,e,i);return function(t,e,o,i){if(!t||"object"!=typeof t)return;const n=t;if(!Array.isArray(n.stops))return;const r=n.stops.flatMap(t=>{if(!t||"object"!=typeof t)return[];const{offset:e,color:o,opacity:n}=t;return"number"==typeof e&&Number.isFinite(e)?[{offset:Math.max(0,Math.min(1,e)),color:"string"==typeof o&&o?o:i,opacity:"number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):void 0}]:[]}).sort((t,e)=>t.offset-e.offset);if(!r.length)return;const s="horizontal"===n.direction?"horizontal":"vertical"===n.direction?"vertical":o,a=e+"-gradient";return{fill:`url(#${a})`,def:(0,mn.jsx)("linearGradient",{id:a,x1:0,y1:0,x2:"horizontal"===s?"100%":0,y2:"vertical"===s?"100%":0,children:r.map((t,e)=>(0,mn.jsx)("stop",{offset:100*t.offset+"%",stopColor:t.color,stopOpacity:t.opacity},`${t.offset}-${e}`))},a)}}(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:i)??n}var kh=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Sh(t,e,o,i){const n=function(t,e,o){const i=t.position,n="string"==typeof i&&kh.has(i)?i:"bottom-left",r=n.endsWith("left")?"left":n.endsWith("right")?"right":"center",s=n.startsWith("top")?"top":n.startsWith("bottom")?"bottom":"middle",a="top"===s?0:"bottom"===s?o:o/2;return{x:("left"===r?0:"right"===r?e:e/2)+("number"==typeof t.dx&&Number.isFinite(t.dx)?t.dx:0),y:a+("number"==typeof t.dy&&Number.isFinite(t.dy)?t.dy:0),textAnchor:"start"===t.textAnchor||"middle"===t.textAnchor||"end"===t.textAnchor?t.textAnchor:"left"===r?"start":"right"===r?"end":"middle",dominantBaseline:"auto"===t.dominantBaseline||"middle"===t.dominantBaseline||"hanging"===t.dominantBaseline?t.dominantBaseline:"top"===s?"hanging":"bottom"===s?"auto":"middle"}}(t,e,o);return{...n,fill:t.fill??t.color??i.fill,fontSize:t.fontSize??i.fontSize,fontFamily:t.fontFamily??i.fontFamily,fontWeight:t.fontWeight,fontStyle:t.fontStyle,letterSpacing:t.letterSpacing,opacity:t.opacity,className:t.className,style:{pointerEvents:"none"}}}var Ah=require("react/jsx-runtime"),Mh={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function _h({annotation:t,width:e,height:o,defaults:i=Mh}){const n=t.label??t.text;return null==n?null:(0,Ah.jsx)("text",{...Sh(t,e,o,i),children:n})}var Ph=require("d3-hierarchy"),jh=require("d3-shape");function Lh(t,e={}){const o=function(t){const e=t.provenance,o=t.id??t.stableId??e?.stableId;return null==o||""===o?void 0:o+""}(t);return{"data-semiotic-annotation-widget":"",...o?{"data-semiotic-annotation-id":o}:{},onClickCapture(i){const n=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(i);e.onAnnotationActivate?.({annotation:t,annotationId:o,chartId:e.chartId,inputType:n}),o&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:o,inputType:n,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}c(require("react"));var $h=require("react/jsx-runtime"),Rh={linear:jh.curveLinear,monotoneX:jh.curveMonotoneX,monotoneY:jh.curveMonotoneY,step:jh.curveStep,stepAfter:jh.curveStepAfter,stepBefore:jh.curveStepBefore,basis:jh.curveBasis,cardinal:jh.curveCardinal,catmullRom:jh.curveCatmullRom};var Ch=require("react/jsx-runtime"),Ih=16,Th=20;function Oh(t,e){return t.color||e.colors.annotation||e.colors.text}function zh(t,e,o){const i=t.labelBackground,n=e.colors.background,r=n&&"transparent"!==n?n:e.colors.surface||n;return void 0===i?"none"===o?"none":{type:"halo",fill:r}:!1===i||"none"===i?"none":!0===i||"halo"===i?{type:"halo",fill:r}:"box"===i?{type:"box",fill:r}:{fill:r,...i}}function Fh(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 Nh(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 Eh(t){const{annotations:e}=t;if(!e||0===e.length)return t.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;const o=function(t,e={}){const o=!0===e.showRetractedAnnotations,i=!0===e.showSupersededAnnotations,n=new Set;for(const e of t){const t=e?.lifecycle?.supersedes;t&&"retracted"!==e?.lifecycle?.status&&n.add(t)}return t.filter(t=>{if("retracted"===t?.lifecycle?.status&&!o)return!1;const e=t?.provenance?.stableId;return!(e&&n.has(e)&&!i)})}(e),i=t.scales.geoProjection,n=i?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=i([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,r=!!i&&!t.scales.x&&!t.scales.y,s=t=>Number(t),a=t.scales.x??(r?s:void 0),c=t.scales.y??(r?s:void 0),l=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,u={scales:{..."vertical"===t.projection?{x:t.scales.o??a,y:t.scales.r??c,time:t.scales.o??a,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??a,y:t.scales.o??c,time:t.scales.r??a,value:t.scales.o??c,o:t.scales.o}:{x:a,y:c,time:a,value:c,o:t.scales.o},...i?{geoProjection:i}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,pointNodes:t.pointNodes,frameType:t.frameType??(t.projection?"ordinal":i||t.scales.x||t.scales.y?"xy":"network"),...l?{projection:l}:{}},d=t.autoPlaceAnnotations?gh({annotations:n,context:u,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):n,h=function(t,e,o,i){const n=[];return t.forEach((t,r)=>{let s;if(o){const n=o(t,r,i);s=null!=n?n:e(t,r,i)}else s=e(t,r,i);s&&n.push({node:s,annotation:t})}),{nodes:Ed(n),renderedAnnotations:n.map(t=>t.annotation)}}(d,(e,o,i)=>function(t,e,o,i){const{scales:n,layout:r,theme:s,xAccessor:a,yAccessor:c}=o;switch(t.type){case"frame-text":return(0,Ch.jsx)(_h,{annotation:t,width:r.width,height:r.height,defaults:{fill:s.colors.text,fontSize:11,fontFamily:s.typography.fontFamily}},"ann-frame-text-"+e);case"y-threshold":{const i=t.value??t.y;if(null==i)return null;const a=Oh(t,s),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(i);return null==o?null:(0,Ch.jsxs)("g",{opacity:t.opacity,children:[(0,Ch.jsx)("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&(0,Ch.jsx)(vh,{x:o+4,y:Ih,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:zh(t,s,"halo")})]},"ann-ythresh-"+e)}const h=n.y?n.y(i):n.r?n.r(i):null;return null==h?null:(0,Ch.jsxs)("g",{children:[(0,Ch.jsx)("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&(0,Ch.jsx)(vh,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:Th>h?Math.min(r.height-4,h+Ih):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:zh(t,s,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const i=t.value??t.x;if(null==i)return null;const a="horizontal"===o.projection&&n.r?n.r(i):n.x?n.x(i):null;if(null==a)return null;const c=Oh(t,s),l=t.label,u=t.labelPosition||"top";return(0,Ch.jsxs)("g",{opacity:t.opacity,children:[(0,Ch.jsx)("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:c,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),l&&(0,Ch.jsx)(vh,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Ih,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:c,fontFamily:s.typography.fontFamily,text:l,background:zh(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=n.y?.domain?.(),i=t.y0??o?.[0],a=t.y1??o?.[1],c=null!=i&&n.y?n.y(i):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=wh(t,"ssr-band-"+e,"vertical",Oh(t,s)),f=t.fillOpacity??.1;return(0,Ch.jsxs)("g",{opacity:t.opacity,children:[h.def&&(0,Ch.jsx)("defs",{children:h.def}),(0,Ch.jsx)("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&(0,Ch.jsx)(vh,{x:r.width-4,y:Math.max(u,0)+Ih,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Oh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:zh(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=n.x?.domain?.(),i=t.x0??o?.[0],a=t.x1??o?.[1],c=null!=i&&n.x?n.x(i):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=wh(t,"ssr-xband-"+e,"horizontal",Oh(t,s)),f=t.fillOpacity??.1;return(0,Ch.jsxs)("g",{opacity:t.opacity,children:[h.def&&(0,Ch.jsx)("defs",{children:h.def}),(0,Ch.jsx)("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:f}),t.label&&(0,Ch.jsx)(vh,{x:u+4,y:Ih,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Oh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:zh(t,s,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!n.o)return null;const i=n.o(t.category+"");if(null==i)return null;const a=n.o.bandwidth?n.o.bandwidth():40,c=Oh(t,s),l=t.opacity??.1,u=t.label;return(0,Ch.jsxs)("g","horizontal"===o.projection?{children:[(0,Ch.jsx)("rect",{x:0,y:i,width:r.width,height:a,fill:c,opacity:l}),u&&(0,Ch.jsx)(vh,{x:12,y:i+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:zh(t,s,"none")})]}:{children:[(0,Ch.jsx)("rect",{x:i,y:0,width:a,height:r.height,fill:c,opacity:l}),u&&(0,Ch.jsx)(vh,{x:i+a/2,y:Ih,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:zh(t,s,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const o=function(t,e,o,i){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:Fh(t,e,o),y:Nh(t,e,i)}}(t,n,a,c),r=null==o.x||null==o.y?qd(t,e,i):null,l=o.x??r?.x??null,u=o.y??r?.y??null;if(null==l||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),f=t.dy??(d?0:-30),p=t.color||s.colors.text;if(!d){const o="callout"===t.type?"callout-circle":t.type,i="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return(0,Ch.jsx)(Sd,{noteData:{x:l,y:u,dx:h,dy:f,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...i?{subject:i}:{},connector:t.connector||{end:"arrow"},color:p,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return(0,Ch.jsx)("g",{children:(0,Ch.jsx)("text",{x:l+h,y:u+f,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:p,fontFamily:s.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,i)??function(t,e,o){switch(t.type){case"enclose":{const i=(t.coordinates||[]).map(t=>({x:Dd({...t,type:"point"},o),y:Bd({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>i.length)return null;const n=(0,Ph.packEnclose)(i),r=t.padding||10;return(0,$h.jsxs)("g",{children:[(0,$h.jsx)("circle",{cx:n.x,cy:n.y,r:n.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&(0,$h.jsx)(vh,{x:n.x,y:n.y-n.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"rect-enclose":{const i=(t.coordinates||[]).map(t=>({x:Dd({...t,type:"point"},o),y:Bd({...t,type:"point"},o)})).filter(t=>null!=t.x&&null!=t.y);if(2>i.length)return null;const n=t.padding||10,[r,s]=Nt(i.map(t=>t.x)),[a,c]=Nt(i.map(t=>t.y)),l=r-n,u=s+n,d=a-n;return(0,$h.jsxs)("g",{children:[(0,$h.jsx)("rect",{x:l,y:d,width:u-l,height:c+n-d,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&(0,$h.jsx)(vh,{x:(l+u)/2,y:d-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"highlight":{const i=o.data||[],n="function"==typeof t.filter?i.filter(t.filter):t.field&&null!=t.value?i.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return(0,$h.jsx)("g",{children:n.map((e,i)=>{const n=Dd(e,o),s=Bd(e,o);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(0,$h.jsx)("circle",{cx:n,cy:s,r:a,...c},"hl-"+i)})},"ann-"+e)}case"bracket":{const i=Dd(t,o),n=Bd(t,o);return(0,$h.jsx)(Sd,{noteData:{x:i??0,y:n??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+e)}case"trend":{const i=o.data||[];if(2>i.length)return null;const n=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,c=s?n:null,l=s?r:null;let u;const d=[],h=new Map;if(s&&c&&l){for(const t of i){const e=t[c];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=i.map(t=>{const e=t[c],o=t[l];if(null==e||null==o)return null;const i=h.get(e+"");return null!=i?[i,+o]:null}).filter(t=>null!==t)}else u=i.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const f=o.scales?.x??o.scales?.time,p=o.scales?.y??o.scales?.value;if(!f||!p)return null;const y=t=>e=>{const o=Math.max(0,Math.floor(e)),i=Math.min(d.length-1,o+1),n=e-o,r=t(d[o]);return r+(t(d[i])-r)*n},g=f,m=p;let x;if(s)if(a){const t=y(m);x=(e,o)=>[g(o),t(e)]}else{const t=y(g);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[g(t),m(e)];const b=t.method||"linear",v="loess"===b?function(t,e=.3){const o=t.length;if(2>o)return t.slice();const i=t.slice().sort((t,e)=>t[0]-e[0]),n=i.map(t=>t[0]),r=i.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=n[t],i=n.map(t=>Math.abs(t-e)),c=i.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:i[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*n[t],h+=e*r[t],f+=e*n[t]*n[t],p+=e*n[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):("polynomial"===b?Wt(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[i,n]of t)null!==n&&(o++,e[0]+=i,e[1]+=n,e[2]+=i*i,e[3]+=i*n);const i=o*e[2]-e[0]*e[0],n=0===i?0:Bt((o*e[3]-e[0]*e[1])/i),r=Bt(e[1]/o-n*e[0]/o);return{points:t.map(([t])=>[Bt(t),Bt(n*t+r)]),equation:[n,r]}}(u)).points,w=v.map(([t,e])=>{const[o,i]=x(t,e);return`${o},${i}`}).join(" "),k=t.color||"#6366f1",S=v[v.length-1],[A,M]=x(S[0],S[1]);return(0,$h.jsxs)("g",{children:[(0,$h.jsx)("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&(0,$h.jsx)("text",{x:A+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+e)}case"envelope":{const i=o.data||[];if(2>i.length)return null;const n=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",c=t.lowerAccessor||"lowerBounds",l=t.filter,u=i.filter(t=>null!=t[a]&&null!=t[c]&&(!l||l(t))).sort((t,e)=>t[n]-e[n]);if(2>u.length)return null;const d=Rh[o.curve||"linear"]||jh.curveLinear,h=(0,jh.area)().x(t=>r(t[n])).y0(t=>s(t[c])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1",p=u[u.length-1];return(0,$h.jsxs)("g",{children:[(0,$h.jsx)("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&(0,$h.jsx)("text",{x:r(p[n])+4,y:s(p[a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+e)}case"anomaly-band":{const i=o.data||[];if(2>i.length)return null;const n=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=i.map(t=>t[n]).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=s(c+d*u),p=s(h),y=t.fill||"#6366f1",g=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=i.filter(t=>{const e=t[n];return null!=e&&Math.abs(e-c)>d*u});return(0,$h.jsxs)("g",{children:[!1!==t.showBand&&(0,$h.jsx)("rect",{x:0,y:Math.min(f,p),width:o.width||0,height:Math.abs(p-f),fill:y,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const i=Dd(t,o),n=Bd(t,o);return null==i||null==n?null:(0,$h.jsx)("circle",{cx:i,cy:n,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+e)}),t.label&&(0,$h.jsx)("text",{x:(o.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:y,fontSize:11,children:t.label})]},"ann-"+e)}case"forecast":{const i=o.data||[];if(3>i.length)return null;const n=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const c=i.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>c.length)return null;let l;if("polynomial"===t.method){const e=Wt(c,t.order||2).equation;l=t=>e.reduce((e,o,i)=>e+o*Math.pow(t,i),0)}else{const t=Yt(c);if(!t)return null;l=t}const{se:u,meanX:d,ssX:h}=qt(c,l),f=c.length,p=Xt(t.confidence??.95),y=c[f-1][0],g=(y-c[0][0])/Math.max(f-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=y+(e+1)*g,i=l(o),n=u*Math.sqrt(1+1/f+(h>0?(o-d)**2/h:0))*p;return{x:o,center:i,upper:i+n,lower:i-n}}),x=m.map(t=>`${s(t.x)},${a(t.upper)}`).join(" L"),b=m.slice().reverse().map(t=>`${s(t.x)},${a(t.lower)}`).join(" L"),v=m.map(t=>`${s(t.x)},${a(t.center)}`).join(" "),w=t.strokeColor||"#6366f1",k=m[m.length-1];return(0,$h.jsxs)("g",{children:[(0,$h.jsx)("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),(0,$h.jsx)("polyline",{points:`${s(y)},${a(l(y))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&(0,$h.jsx)("text",{x:s(k.x)+4,y:a(k.center)-4,fill:w,fontSize:11,children:t.label})]},"ann-"+e)}case"widget":{let i,n;if(null!=t.px&&null!=t.py)i=t.px,n=t.py;else{const r=qd(t,e,o);if(!r)return null;i=r.x,n=r.y}if(!function(t,e,o,i=50){return!(-i>t||t>(o.width||0)+i||-i>e||e>(o.height||0)+i)}(i,n,o))return null;const r=t.width??32,s=t.height??32,a=t.content??(0,$h.jsx)("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return(0,$h.jsx)("foreignObject",{x:i+(t.dx??0)-r/2,y:n+(t.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:(0,$h.jsx)("div",{...Lh(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,i),t.svgAnnotationRules,u),f=h.nodes,p=new Map;for(const t of h.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";p.set(e,(p.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=p.get(e)??0;o>0?p.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:d.length,renderedCount:h.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?(0,Ch.jsx)("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}var Dh=require("react/jsx-runtime");function Bh(t,e,o,i="right",n,r){if(null==t||!1===t)return null;const{x:s,y:a}=Be(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:i,legendLayout:n,axisChrome:r});return(0,Dh.jsx)("g",{transform:`translate(${s}, ${a})`,children:t})}var Wh=c(require("react"));function Yh(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function qh(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function Xh(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const i of t)e>i.pixel&&(e=i.pixel),i.pixel>o&&(o=i.pixel);return{min:e,max:o}}function Gh(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function Vh(t,e){return t&&"string"!=typeof t?{stroke:t.stroke??e.stroke,strokeWidth:t.strokeWidth??e.strokeWidth,...null!=t.strokeOpacity&&{strokeOpacity:t.strokeOpacity},...t.strokeDasharray&&{strokeDasharray:t.strokeDasharray}}:{...e,..."string"==typeof t&&{strokeDasharray:Gh(t)}}}function Hh(t,e,o){if("left"===t||"right"===t){const i="left"===t?o:0,n="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+i;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${i+4*n}`,s+=`L${Math.min(o,e)},${i}`}return s}const i="bottom"===t?0:e,n="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${i},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${i+4*n},${Math.min(8*t+4,o)}`,s+=`L${i},${Math.min(e,o)}`}return s}function Uh(t,e){return t?.ticks??t?.tickCount??e}function Kh(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function Zh(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),i=o[0],n=o[o.length-1],r=i instanceof Date,s=i instanceof Date?i.getTime():i,a=n instanceof Date?n.getTime():n;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const c=(a-s)/(e-1),l=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*c;l[t]=r?new Date(o):o}return l}(t,e):t.ticks(e)}var Qh=require("react/jsx-runtime");function Jh(t){return"string"==typeof t||"number"==typeof t}function tf(t){const{label:e,x:o,y:i,textAlign:n,fontSize:r,fontFamily:s,color:a}=t;return(0,Qh.jsx)("foreignObject",{x:o,y:i,width:60,height:24,style:{overflow:"visible"},children:(0,Qh.jsx)("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:n,userSelect:"none"},children:e})})}function ef(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function of(t){const{values:e,scale:o,format:i}=t,n=e.map(t=>t.valueOf());return e.map((t,e)=>({value:t,pixel:o(t),label:i(t,e,n)}))}function nf(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function rf(t){const{candidates:e,scale:o,minPixelDistance:i,includeMax:n,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:c=!0,format:l}=t;let u=function(t,e){if(2>=t.length)return t;const o=[t[0]];for(let i=1;t.length-1>i;i++)e>Math.abs(t[i].pixel-o[o.length-1].pixel)||o.push(t[i]);const i=t[t.length-1];return e>Math.abs(i.pixel-o[o.length-1].pixel)?o[o.length-1]=i:o.push(i),o}(e,i);if(a&&u.length>1&&(u=u.filter((t,e)=>{return 0===e||(i=u[e-1].label,!!("string"!=typeof(o=t.label)&&"number"!=typeof o||"string"!=typeof i&&"number"!=typeof i||o+""!=i+""));var o,i})),!c||!n||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const f=o(h),p=u[u.length-1].pixel;if(1>=Math.abs(f-p))return u;const y=e.map(t=>t.value.valueOf()),g={value:h,pixel:f,label:l(h,u.length,y)};return i>Math.abs(f-p)&&u.length>1&&(u=u.slice(0,-1)),[...u,g]}function sf(t,e,o,i){return!!t&&("function"==typeof t?t(e.value,o):function(t,e){const o=ef(t);if(!o)return!1;const i=ef(e);return!i||o.getFullYear()!==i.getFullYear()||o.getMonth()!==i.getMonth()}(e.value,o>0?i[o-1].value:void 0))}var af=require("react/jsx-runtime");function cf(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function lf(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 i=0;for(let t=0;o.length>t;t++)i=31*i+o.charCodeAt(t)|0;return"c"+(i>>>0).toString(36)}function uf(t,e,o){return re(t.showLegend&&!t.__legendIncludesAutomatic?cd(e,t.colorScheme,o):void 0,t.legend)}var df={right:110,left:110,top:50,bottom:80};function hf(t,e){if(t.__autoLegendMargin)return df[e]}function ff(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,axisChrome:e.axisChrome,legendDistance:se(t)||ae(t)?t.legendDistance:void 0};return se(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=function(t){const{legendGroups:e,theme:o,position:i="right",totalWidth:n,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,rowHeight:l}=We(s),u=a+c,d=Math.max(12,ud(o)),h="top"===i||"bottom"===i,f=Math.max(a,n-r.left-r.right);if(h){const i=Math.max(a,s?.maxWidth??f),n=ld(s?.align);let r=0,c=0;const l=[];for(const n of e){const e=n.items.map(t=>t.label),u=pd({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,i-d-8),align:"start"}}),h=n.label?d:0,f=n.label?fd(n.label,0,0,o):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);l.push({group:n,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>i?0:"center"===n?Math.max(0,(i-h)/2):"end"===n?Math.max(0,i-h):0;return{groups:l.map(t=>({...t,x:t.x+p})),width:h,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Ye(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),l);let y=0;return{groups:e.map((t,e)=>{const i=t.items.map(t=>fd(t.label,a,c,o)),n=Math.max(0,...i,t.label?fd(t.label,0,0,o):0);return y=Math.max(y,n),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:n,height:t.items.length*l,items:t.items.map((t,e)=>({category:t.label,width:i[e],x:0,y:e*l}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}(t),i="top"===t.position||"bottom"===t.position,n={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??je(n,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:c}=Be(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:r});if(!i){const e=Ye(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??sd)),i=t.legendGroups.flatMap((i,n)=>{const s=e[n],a=i.type??"fill",c=[(0,rd.jsx)("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+n)];return i.label&&null!=s.labelY&&c.push((0,rd.jsx)("text",{y:s.labelY,fontSize:ud(t.theme),fill:t.theme.colors.text,fontFamily:dd(t.theme),children:i.label},"legend-group-label-"+n)),c.push((0,rd.jsx)("g",{transform:`translate(0,${s.itemsY})`,children:i.items.map((e,r)=>{const s=i.styleFn(e,r),c="function"==typeof a?a(e):"line"===a?(0,rd.jsx)("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):(0,rd.jsx)("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return(0,rd.jsxs)("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??sd)})`,children:[c,(0,rd.jsx)("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:ud(t.theme),fill:t.theme.colors.text,fontFamily:dd(t.theme),children:e.label})]},`legend-${n}-${r}`)})},"legend-group-"+n)),c});return(0,rd.jsx)("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":"vertical",fontWeight:hd(t.theme),children:i})}const l=o.groups.flatMap((e,n)=>{const{group:r}=e,a=r.type??"fill",c=[];if(r.label&&c.push((0,rd.jsx)("text",i?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:ud(t.theme),fill:t.theme.colors.text,fontFamily:dd(t.theme),children:r.label}:{x:e.x,y:e.y+ud(t.theme),fontSize:ud(t.theme),fill:t.theme.colors.text,fontFamily:dd(t.theme),children:r.label},"legend-group-label-"+n)),c.push(...e.items.map((i,s)=>{const c=r.items[s],l=r.styleFn(c,s),u="function"==typeof a?a(c):"line"===a?(0,rd.jsx)("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):(0,rd.jsx)("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return(0,rd.jsxs)("g",{transform:`translate(${e.x+e.itemOffsetX+i.x},${e.y+e.itemOffsetY+i.y})`,children:[u,(0,rd.jsx)("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:ud(t.theme),fill:t.theme.colors.text,fontFamily:dd(t.theme),children:i.category})]},`legend-${n}-${s}`)})),i&&o.groups.length-1>n){const t=e.x+e.width+6;c.push((0,rd.jsx)("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+n))}return c});return(0,rd.jsx)("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":i?"horizontal":"vertical",fontWeight:hd(t.theme),children:l})}({...o,legendGroups:t.legendGroups}):ae(t)?function(t){const e=function(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?Me:_e,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?Ae+108:108,swatchSize:14}}(t),o="top"===t.position||"bottom"===t.position,i={gradient:t.gradient,legendDistance:t.legendDistance},n=je(i),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:c}=Be(i,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:n}),l=Array.from({length:17},(e,i)=>{const n=i/16;return(0,rd.jsx)("stop",{offset:100*n+"%",stopColor:t.gradient.colorFn(o?t.gradient.domain[0]+n*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-n*(t.gradient.domain[1]-t.gradient.domain[0]))},i)});if(o){const o=12,i=t.gradient.label?Se:void 0,n=t.gradient.label?Ae:0;return(0,rd.jsxs)("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:hd(t.theme),children:[(0,rd.jsx)("defs",{children:(0,rd.jsx)("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),t.gradient.label&&(0,rd.jsx)("text",{x:e.width/2,y:i,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:dd(t.theme),children:t.gradient.label}),(0,rd.jsx)("rect",{x:0,y:n,width:e.width,height:o,fill:`url(#${r})`,rx:2}),(0,rd.jsx)("text",{x:0,y:n+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:dd(t.theme),children:s(t.gradient.domain[0])}),(0,rd.jsx)("text",{x:e.width,y:n+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:dd(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?Se:void 0,d=t.gradient.label?Ae:0;return(0,rd.jsxs)("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:hd(t.theme),children:[(0,rd.jsx)("defs",{children:(0,rd.jsx)("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),t.gradient.label&&(0,rd.jsx)("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:dd(t.theme),children:t.gradient.label}),(0,rd.jsx)("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),(0,rd.jsx)("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:dd(t.theme),children:s(t.gradient.domain[1])}),(0,rd.jsx)("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:dd(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function pf(t,e){const{props:o,categories:i,theme:n,size:r,hasTitle:s}=e,a=o.legendPosition||"right",c={...t},l={theme:n,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:hf(o,a)};if(null!=o.legend){const e=uf(o,i,n);null!=e&&!1!==e&&function(t,e){De(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,legend:e})}else o.showLegend&&i.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";De(t,{legend:cd(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,categories:i,colorScheme:o.colorScheme});return ke(t,c,r,a),a}function yf(t){const{props:e,categories:o,theme:i,size:n,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",c={theme:i,position:a,size:n,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=uf(e,o,i);if(Wh.isValidElement(t))return Bh(t,n,r,a,e.legendLayout,e.axisChrome);return ff(t,c)||(se(t)||ae(t)?null:Bh(t??null,n,r,a,e.legendLayout,e.axisChrome))}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:i,position:n="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const c=ad(e,o,i),l="top"===n||"bottom"===n,u=pd(t),d={...cd(e,o,i),legendDistance:t.legendDistance},h=t.reservedWidth??je(d,t.legendLayout),{x:f,y:p}=Be(d,{totalWidth:r,totalHeight:s,margin:a,position:n,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(l){const t=u.items.map((t,e)=>(0,rd.jsxs)("g",{transform:`translate(${t.x},${t.y})`,children:[(0,rd.jsx)("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),(0,rd.jsx)("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:ud(i),fill:i.colors.text,fontFamily:dd(i),children:t.category})]},"legend-"+e));return(0,rd.jsx)("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:hd(i),children:t})}const y=Ye([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??sd))[0],g=u.items.map((t,e)=>(0,rd.jsxs)("g",{transform:`translate(${t.x},${t.y+y.itemsY})`,children:[(0,rd.jsx)("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),(0,rd.jsx)("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:ud(i),fill:i.colors.text,fontFamily:dd(i),children:t.category})]},"legend-"+e));return(0,rd.jsxs)("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:hd(i),children:[(0,rd.jsx)("line",{x1:0,y1:y.lineY,x2:h,y2:y.lineY,stroke:"gray"}),g]})}({categories:o,colorScheme:e.colorScheme,theme:i,position:a,totalWidth:n[0],totalHeight:n[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}var gf=Kh;function mf(t,e){const o=zt(e.theme),i=e.background??o.background,n=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?n+"semiotic-title":void 0,a=e.description?n+"semiotic-desc":void 0,c=[s,a].filter(Boolean).join(" ")||void 0;return(0,af.jsxs)("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&&(0,af.jsx)("title",{id:s,children:r}),e.description&&(0,af.jsx)("desc",{id:a,children:e.description}),e.defs&&(0,af.jsx)("defs",{children:e.defs}),i&&"transparent"!==i&&(0,af.jsx)("rect",{x:0,y:0,width:e.width,height:e.height,fill:i}),(0,af.jsx)("g",{id:n+"data-area",transform:e.innerTransform,children:t}),r&&(0,af.jsx)("text",{id:n+"chart-title",x:e.width/2,y:de,textAnchor:"middle",fontSize:o.titleFontSize,fontWeight:o.titleFontWeight,fill:o.text,fontFamily:o.titleFontFamily,children:r}),e.legend&&(0,af.jsx)("g",{id:n+"legend",children:e.legend}),e.outerElements]})}var xf=require("react/jsx-runtime");function bf(t,e,o,i){return"function"==typeof t?t({size:e,margin:o,scales:i}):t}var vf={top:50,right:40,bottom:60,left:70},wf={top:20,right:80,bottom:20,left:80},kf={top:40,right:40,bottom:40,left:40},Sf=new Set(["chord","force","circlepack","orbit"]),Af=require("react/jsx-runtime"),Mf=require("react/jsx-runtime");function _f(t,e){const o=Ot(t.theme),i=t.size||[500,300],n=pe({...vf,...t.margin},t.title),r=he(t.title),s=function(t,e){if(!e||0===t.length)return t;if(!t.some(t=>null!=t&&"object"==typeof t&&Array.isArray(t[e])))return t;const o=[];for(const i of t){if(null==i||"object"!=typeof i)continue;const t=i[e];if(!Array.isArray(t))continue;const n=i.label??i.id??i.key;for(const e of t)null!=e&&"object"==typeof e&&o.push(null==n?e:{...e,_lineGroup:n})}return o}(P(t.data),t.lineDataAccessor),a=t.showLegend?yd(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],c=function(t){const e=t.axes?.find(t=>"bottom"===t.orient),o=t.axes?.find(t=>"top"===t.orient),i=t.axes?.find(t=>"left"===t.orient),n=t.axes?.find(t=>"right"===t.orient),r=!o||!!e,s=!!o&&!e,a=!n||!!i,c=!!n,l=!1!==t.showAxes;return{hasAxis:l&&r,hasAxisLabel:l&&r&&!!(e?.label??t.xLabel),rotatedTicks:l&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:l,hasAxisLabel:l&&!!(o?.label??t.xLabel),rotatedTicks:l&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:l,hasAxisLabel:l&&!!(i?.label??t.yLabel)}:void 0,rightAxis:c?{hasAxis:l,hasAxisLabel:l&&!!(n?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});pf(n,{props:{...t,axisChrome:c},categories:a,theme:o,size:i,hasTitle:r});const l=yf({props:{...t,axisChrome:c},categories:a,theme:o,size:i,margin:n,hasTitle:r}),u=i[0]-n.left-n.right,d=i[1]-n.top-n.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),f=t.colorScheme||o.colors.categorical,p=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,y={chartType:t.chartType,runtimeMode:h?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,yAxisExtent:p,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:kt(t.gradientFill),lineGradient:St(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:f,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:It(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},g=new vu(y);t.data&&g.ingest({inserts:s,bounded:!0}),g.computeScene({width:u,height:d});const m=bf(t.backgroundGraphics,i,n,g.scales),x=bf(t.foregroundGraphics,i,n,g.scales);if(!g.scales){let r;const a=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ec({frameType:"xy",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:g.scales?[]:["NO_SCALES"],margin:n})),Bc.renderToStaticMarkup(mf(m||x||t.annotations?(0,Mf.jsxs)(Mf.Fragment,{children:[m,a,x]}):null,{width:i[0],height:i[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=id({nodes:g.scene,renderMode:t.renderMode,fallback:(e,o)=>td(e,o,b,t.hoverRadius??30)}),w=t.showGrid?function(t,e,o,i,n,r,s){const{grid:a}=zt(o),c=i?i+"-":"",l=r?.find(t=>"bottom"===t.orient),u=r?.find(t=>"top"===t.orient),d=r?.find(t=>"left"===t.orient),h=r?.find(t=>"right"===t.orient),f=l??u,p=d??h,y=f?.extent??n,g=p?.extent??n,m="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=f?.tickValues??Zh(t.x,Uh(f,m),y),v=f?.tickFormat||s?.xFormat||s?.tickFormatTime||Kh,w=of({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,nf(e.label)),0),S=rf({candidates:w,scale:t.x,minPixelDistance:f?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:v}),A=p?.tickValues??Zh(t.y,Uh(p,x),g),M=p?.tickFormat||s?.yFormat||s?.tickFormatValue||Kh,_=t=>M(t),P=rf({candidates:of({values:A,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:_}),j=!1!==f?.grid,L=!1!==p?.grid,$=Gh(f?.gridStyle),R=Gh(p?.gridStyle),C=Vh(f?.gridStyle,{stroke:a,strokeWidth:.5}),I=Vh(p?.gridStyle,{stroke:a,strokeWidth:.5});return(0,xf.jsxs)("g",{id:c+"grid",className:"semiotic-grid",opacity:.8,children:[j&&S.map((t,o)=>(0,xf.jsx)("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...C,strokeDasharray:$??C.strokeDasharray},"gx-"+o)),L&&P.map((t,o)=>(0,xf.jsx)("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...I,strokeDasharray:R??I.strokeDasharray},"gy-"+o))]})}(g.scales,{width:u,height:d},o,b,t.axisExtent,t.axes,t):null,k=v.map(t=>t.element),S=lf(t)+"-plot-clip",A=!1!==t.showAxes,M=A?function(t,e,o,i,n,r,s,a=!1){const c=zt(i),l=o.legendPosition??"right",u=$e(o.legendLayout,s?.leftAxis),d=$e(o.legendLayout,s?.rightAxis),h=a&&"left"===l&&u>0?u:r?.left??o.margin?.left??40,f=a&&"right"===l&&d>0?d:r?.right??o.margin?.right??40,p=o.axes?.find(t=>"bottom"===t.orient),y=o.axes?.find(t=>"top"===t.orient),g=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=p??y,b=g??m,v=p?"bottom":y?"top":"bottom",w=g?"left":m?"right":"left",k="top"===v?0:e.height,S="right"===w?e.width:0,A="top"===v?-1:1,M="right"===w?1:-1,_=x?.extent??o.axisExtent,P=b?.extent??o.axisExtent,j="exact"===_?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),L="exact"===P?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),$=x?.tickValues??Zh(t.x,Uh(x,j),_),R=x?.tickFormat||o.xFormat||o.tickFormatTime||gf,C=of({values:$,scale:t.x,format:R}),I=C.reduce((t,e)=>Math.max(t,nf(e.label)),0),T=rf({candidates:C,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(I+8,55)):Math.max(55,I+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:R}),O=b?.tickValues??Zh(t.y,Uh(b,L),P),z=b?.tickFormat||o.yFormat||o.tickFormatValue||gf,F=t=>z(t),N=rf({candidates:of({values:O,scale:t.y,format:F}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:F}),E=!!(x?.autoRotate&&T.length>1&&e.width/Math.max(T.length-1,1)<T.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),D=Xh(T),B=Xh(N),W=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),q=Vh(x?.axisStyle,{stroke:c.border,strokeWidth:1}),X=Vh(b?.axisStyle,{stroke:c.border,strokeWidth:1}),G="right"===w?e.width+f-15:15-h;return(0,af.jsxs)("g",{id:(n?n+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&(0,af.jsx)("line",{x1:0,y1:k,x2:e.width,y2:k,...q}),x?.jaggedBase&&(0,af.jsx)("path",{d:Hh(v,e.width,e.height),fill:"none",...q}),T.map((t,e)=>{const o=sf(x?.landmarkTicks,t,e,T);return(0,af.jsxs)("g",{transform:`translate(${t.pixel},${k})`,children:[(0,af.jsx)("line",{y2:5*A,...q}),Jh(t.label)?(0,af.jsx)("text",{y:A*(E?12:18),textAnchor:E?"end":Yh(x?.tickAnchor,t.pixel===D.min,t.pixel===D.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,transform:E?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):tf({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"xtick-"+e)}),W&&(0,af.jsx)("text",{x:e.width/2,y:"top"===v?-(E?58:40):e.height+(E?58:40),textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:W}),!1!==b?.baseline&&!b?.jaggedBase&&(0,af.jsx)("line",{x1:S,y1:0,x2:S,y2:e.height,...X}),b?.jaggedBase&&(0,af.jsx)("path",{d:Hh(w,e.width,e.height),fill:"none",...X}),N.map((t,e)=>{const o=sf(b?.landmarkTicks,t,e,N);return(0,af.jsxs)("g",{transform:`translate(${S},${t.pixel})`,children:[(0,af.jsx)("line",{x2:5*M,...X}),Jh(t.label)?(0,af.jsx)("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:qh(b?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):tf({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"ytick-"+e)}),Y&&(0,af.jsx)("text",{x:G,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${G}, ${e.height/2})`,children:Y})]})}(g.scales,{width:u,height:d},t,o,b,n,c,!!l):null,_=A?function(t){const{scales:e,layout:o,props:i,theme:n,leftAxis:r,rightAxis:s,margin:a,axisChrome:c,hasRenderedLegend:l}=t;if(!r||!s)return null;const u=zt(n),d=s.extent??i.axisExtent,h="exact"===d?Math.max(2,Uh(s,5)):Math.min(Uh(s,5),Math.max(2,Math.floor(o.height/30))),f=s.tickValues??Zh(e.y,h,d),p=s.tickFormat||i.yFormat||i.tickFormatValue||Kh,y=t=>p(t),g=rf({candidates:of({values:f,scale:e.y,format:y}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:y}),m=Xh(g),x=s.label??i.yLabelRight,b=Vh(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=i.legendPosition??"right",w=$e(i.legendLayout,c?.rightAxis),k=o.width+(l&&"right"===v&&w>0?w:a.right)-15;return(0,Af.jsxs)("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&(0,Af.jsx)("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&(0,Af.jsx)("path",{d:Hh("right",o.width,o.height),fill:"none",...b}),g.map((t,e)=>{const i=sf(s.landmarkTicks,t,e,g);return(0,Af.jsxs)("g",{transform:`translate(${o.width},${t.pixel})`,children:[(0,Af.jsx)("line",{x2:5,...b}),Jh(t.label)?(0,Af.jsx)("text",{x:8,textAnchor:"start",dominantBaseline:qh(s.tickAnchor,t.pixel===m.min,t.pixel===m.max),fontWeight:i?600:400,fontSize:i?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:t.label}):tf({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&(0,Af.jsx)("text",{x:k,y:o.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${k}, ${o.height/2})`,children:x})]})}({scales:g.scales,layout:{width:u,height:d},props:t,theme:o,leftAxis:t.axes?.find(t=>"left"===t.orient),rightAxis:t.axes?.find(t=>"right"===t.orient),margin:n,axisChrome:c,hasRenderedLegend:!!l}):null;let j;const L=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:g.scales.x,y:g.scales.y},layout:{width:u,height:d},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:b,onRender:t=>{j=t}}):null;e&&(e.evidence=Ec({frameType:"xy",width:i[0],height:i[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:j,xDomain:Nc(g.scales.x?.domain?.()),yDomain:Nc(g.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:n}));const $=t.svgPreRenderers&&g.scales?t.svgPreRenderers.map((t,e)=>{try{return(0,Mf.jsx)(Dc.Fragment,{children:t(g.scene,g.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Bc.renderToStaticMarkup(mf((0,Mf.jsxs)(Mf.Fragment,{children:[m,$,w,(0,Mf.jsx)("defs",{children:(0,Mf.jsx)("clipPath",{id:S,children:(0,Mf.jsx)("rect",{x:0,y:0,width:u,height:d})})}),(0,Mf.jsx)("g",{clipPath:`url(#${S})`,children:k}),M,_,L,x,g.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}var Pf=c(require("react")),jf=c(require("react-dom/server")),Lf=require("d3-scale"),$f=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 i=t.pieceStyle(e,o);return i&&!i.fill&&o?{...i,fill:this.getColorFromScheme(t,o)}:i}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:ct(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 i=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||nt,n=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,n),n}};function Rf(t,e,o){const i="function"==typeof t?t(o?e.w:e.h):t;return"number"==typeof i&&Number.isFinite(i)?Math.max(0,i):0}function Cf(t){const e=t.getSymbol;return e?Cl(e,t.config.symbolMap):null}function If(t,e,o,i,n,r,s){t.push(e?{type:"symbol",x:i,y:n,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:i,y:n,r:r,style:s,datum:o})}function Tf(t,e){const{columns:o,config:i,resolvePieceStyle:n}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===i.chartType?i.innerRadius||60:0,c=-Math.PI/2+(i.startAngle||0)*Math.PI/180,l=null!=i.sweepAngle?i.sweepAngle*Math.PI/180:2*Math.PI,u=null!=i.sweepAngle&&360>i.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&&(i.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=n(e.pieceData[0],e.name),g=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...i.cornerRadius&&{cornerRadius:i.cornerRadius},style:y,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:f&&(x.roundedEnds={start:g,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}var Of=require("d3-array");function zf(t){const e=t.length,o=t[0],i=t[e-1];return{n:e,min:o,q1:(0,Of.quantile)(t,.25)??o,median:(0,Of.quantile)(t,.5)??(o+i)/2,q3:(0,Of.quantile)(t,.75)??i,max:i,mean:t.reduce((t,e)=>t+e,0)/e}}var Ff=require("d3-scale"),Nf={bar:function(t,e){const{scales:o,columns:i,config:n,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h="horizontal"===l,f=n.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(i))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(i)){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 i=e.get(t);i.total+=r(o),i.pieces.push(o)}let o=0;if(f)for(const t of e.values())o+=Math.abs(t.total);let i=0,n=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?n:i+p),o=0>p?c(n+p)-c(n):c(i)-c(i+p);u.push(gl(t.x,e,t.width,Math.abs(o),y,g,r)),0>p?n+=p:i+=p}else if(h){const e=c(0>p?n+p:i),o=0>p?c(n)-c(n+p):c(i+p)-c(i);u.push(gl(e,t.x,Math.abs(o),t.width,y,g,r)),0>p?n+=p:i+=p}}}const y="vertical"===l;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=y?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}if(void 0!==n.roundedTop){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));if(t.length>0){const e=t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=Rf(n.roundedTop,e,y);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=Rf(n.roundedTop,t,y);e>0&&(t.roundedTop=e)}}}return u},clusterbar:function(t,e){const{scales:o,columns:i,config:n,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(i))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(i)){const e=t.width/p,o=.2*e,i=e-o,n=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";n.has(t)||n.set(t,[]),n.get(t).push(e)}for(let s=0;h.length>s;s++){const l=n.get(h[s])||[];for(const n of l){const l=r(n),f=a(n,h[s]);if(d){const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(gl(r,Math.min(a,d),i,Math.abs(a-d),f,n,h[s]))}else{const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(gl(Math.min(a,d),r,Math.abs(d-a),i,f,n,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=Rf(n.roundedTop,t,d);o>0&&(t.roundedTop=o),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}return u},point:function(t,e){const{scales:o,columns:i,getR:n,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d="radial"===c,h=r.length>0,f=Cf(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(i))for(const e of t.pieceData){const o=e.__rIndex??0,i=e.__rValue??n(e),c=h&&r[o]||a,g=s(e,t.name),m=g.r||5;let x,b;if(d){const e=y+(t.pctStart+t.pct/2)*p,o=c(i);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=c(i)):(x=c(i),b=t.middle);If(l,f,e,x,b,m,g)}return l},swarm:function(t,e){const{scales:o,columns:i,getR:n,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="vertical"===a,u=Cf(t);for(const t of Object.values(i)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const i=t.pieceData[o],a=n(i),d=r(i,t.name),h=d.r||4,f=(7919*o%100/100-.5)*e*.8;If(c,u,i,l?t.middle+f:s(a),l?s(a):t.middle+f,h,d)}}return c},pie:Tf,donut:Tf,boxplot:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=!1!==n.showOutliers;for(const e of Object.values(i)){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 i=o[0],n=o[o.length-1],c=(0,Of.quantile)(o,.25)??i,h=(0,Of.quantile)(o,.5)??(i+n)/2,f=(0,Of.quantile)(o,.75)??n,p=f-c,y=c-1.5*p,g=f+1.5*p,m=o.find(t=>t>=y)??i,x=[...o].reverse().find(t=>g>=t)??n,b=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 i=u?e.middle:a(o),n=u?a(o):e.middle;v.push({px:i,py:n,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(x),stats:{n:o.length,min:m,q1:c,median:h,q3:f,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},style:b,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:b.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:b.cursor},datum:e.datum})}return l},violin:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=n.bins||20,h=!1!==n.showIQR;for(const t of Object.values(i)){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],i=e[e.length-1],n=(i-o)/d||1,c=Array(d).fill(0);for(const t of e)c[Math.min(Math.floor((t-o)/n),d-1)]++;const f=Et(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 i=a(o+(e+.5)*n);y+=` L ${t.middle+c[e]/f*p} ${i}`}y+=` L ${t.middle} ${a(i)}`;for(let e=d-1;e>=0;e--){const i=a(o+(e+.5)*n);y+=` L ${t.middle-c[e]/f*p} ${i}`}y+=" Z"}else{y=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)y+=` L ${a(o+(e+.5)*n)} ${t.middle-c[e]/f*p}`;y+=` L ${a(i)} ${t.middle}`;for(let e=d-1;e>=0;e--)y+=` L ${a(o+(e+.5)*n)} ${t.middle+c[e]/f*p}`;y+=" Z"}const g=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const n=(0,Of.quantile)(e,.25)??o,r=(0,Of.quantile)(e,.5)??(o+i)/2,s=(0,Of.quantile)(e,.75)??i;m={q1Pos:a(n),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=u?{x:t.x,y:Math.min(a(i),a(o)),width:t.width,height:Math.abs(a(i)-a(o))}:{x:Math.min(a(o),a(i)),y:t.x,width:Math.abs(a(i)-a(o)),height:t.width};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:zf(e),style:g,datum:t.pieceData,category:t.name})}return l},histogram:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,c=[],l=n.bins||25,u=n.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(const t of Object.values(i)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,i]=Nt(e),n=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:i,p=(d-n)/l||1,y=Array(l).fill(0);for(const t of e)n>t||t>d||y[Math.min(Math.floor((t-n)/p),l-1)]++;const g=e.length,m=Et(y,1),x=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,i=a(n+e*p),r=a(n+(e+1)*p);c.push(gl(Math.min(i,r),t.x+t.width-o,Math.abs(r-i),o,x,{bin:e,count:y[e],range:[n+e*p,n+(e+1)*p],category:t.name},t.name))}}return c},ridgeline:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u=n.bins||20,d="horizontal"===c,h=n.amplitude||1.5;for(const t of Object.values(i)){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],i=e[e.length-1],n=(i-o)/u||1,c=Array(u).fill(0);for(const t of e)o>t||t>i||c[Math.min(Math.floor((t-o)/n),u-1)]++;const f=Et(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)*n)} ${e-c[t]/f*y}`;g+=` L ${a(i)} ${e} Z`}else{const e=t.x;g=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const i=a(o+(t+.5)*n);g+=` L ${e+c[t]/f*y} ${i}`}g+=` L ${e} ${a(i)} Z`}const m=d?{x:Math.min(a(o),a(i)),y:t.x,width:Math.abs(a(i)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(i),a(o)),width:t.width,height:Math.abs(a(i)-a(o))};l.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:m,stats:zf(e),style:{...p,fillOpacity:p.fillOpacity??.5},datum:t.pieceData,category:t.name})}return l},timeline:function(t,e){const{scales:o,columns:i,getRawRange:n,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="horizontal"===a;for(const t of Object.values(i))for(const e of t.pieceData){const o=n(e);if(!o)continue;const[i,a]=o,u=r(e,t.name);if(l){const o=s(Math.min(i,a)),n=s(Math.max(i,a));c.push(gl(o,t.x,n-o,t.width,u,e,t.name))}else{const o=s(Math.max(i,a)),n=s(Math.min(i,a));c.push(gl(t.x,o,t.width,n-o,u,e,t.name))}}return c},funnel:function(t,e){const{columns:o,getR:i,getStack:n,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=n?n(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=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=i(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 i=0;u.length>i;i++){const n=t.groups.get(u[i]);n&&(i%2==0?e+=n.total:o+=n.total)}const i=Math.max(e,o);i>p&&(p=i)}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,x=(0,Ff.scaleLinear)().domain([0,p]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const o=f[e],i=o.col,n=0===e,l=i.width,d=.55*l,p=i.x+(l-d)/2,m=new Map;if(h){let t=0;for(const e of u){const i=o.groups.get(e);i&&(t+=x(i.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 b=x(g.total),v=h%2==0,w=v?e:l-b;v?e+=b:l-=b;const k=r(g.pieces[0],f),S=y.get(f)??g.total,A={...g.pieces[0],__funnelValue:g.total,__funnelPercent:S>0?g.total/S*100:0,__funnelStep:i.name,__funnelIsFirstStep:n,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};c&&(0===h&&(A.__funnelStepLabel=i.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=t),A.__funnelValueLabelX=w+b/2,A.__funnelValueLabelY=p,A.__funnelBarW=b),s.push(gl(w,p,b,d,k,A,f)),m.set(f,{x:w,y:p,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),l=a-e/2,h=u[0],f="_default"!==h,y=o.groups.get(h)?.pieces[0]??i.pieceData[0],b=f?h:i.name,v=r(y,b),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:i.name,__funnelIsFirstStep:n,category:f?h:i.name};c&&(k.__funnelStepLabel=i.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(gl(l,p,e,d,v,k,b)),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 n of e){const e=v.get(n),a=m.get(n);if(!e||!a)continue;const c=(()=>{const t=o.groups.get(n);return r(t?t.pieces[0]:i.pieceData[0],"_default"===n?i.name:n)})(),l={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:c.cursor},datum:o.groups.get(n)?.pieces[0]??i.pieceData[0],category:"_default"===n?i.name:n};s.push(l)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:i,getStack:n,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=n?n(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=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=i(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,i=0===t,n=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,x=m>0?g/m*100:0,b=n?.groups.get(h),v=i?0:Math.max(0,(b?.total??g)-g),w=o.x+t*s+c/2,k=p(g),S=p(0)-k,A=r(y.pieces[0],d?h:o.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:x,__barFunnelIsFirstStep:i,__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(gl(w,k,u,S,A,M,d?h:o.name)),v>0){const t=p(g+v),e=k-t,i={...A},n={...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(gl(w,t,u,e,i,n,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:i,getR:n,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="horizontal"===c,d=t.config.gradientFill,h=u?"left":"bottom",f=new Map,p=e=>{const o=f.get(e);if(void 0!==o)return o;const i="function"==typeof t.config.roundedTop?t.config.roundedTop(e.width):t.config.roundedTop,n="number"==typeof i&&Number.isFinite(i)?Math.max(0,i):0;return f.set(e,n),n},y=t.config.trackFill;if(y){const t="string"==typeof y?y:y.color,e="string"==typeof y?1:y.opacity??1,[o,n]=a.range(),r=Math.min(o,n),s=Math.abs(n-o);for(const o of Object.values(i)){const i={fill:t,opacity:e},n=u?gl(r,o.x,s,o.width,i,null,"__track__"):gl(o.x,r,o.width,s,i,null,"__track__"),a=p(o);a>0&&(n.cornerRadii={tl:a,tr:a,br:a,bl:a}),l.push(n)}}for(const t of Object.values(i)){let e=0;const o=l.length,i=p(t);for(const o of t.pieceData){const i=Math.abs(n(o));if(0===i)continue;const c=r?r(o):t.name,f=s(o,c);let p;if(u){const n=a(e),r=a(e+i);p=gl(n,t.x,r-n,t.width,f,o,c)}else{const n=a(e+i),r=a(e);p=gl(t.x,n,t.width,r-n,f,o,c)}d&&(p.fillGradient=d,p.roundedEdge=h),l.push(p),e+=i}if(i>0&&l.length>o){const t=l.slice(o),e=t[0],n=t[t.length-1];1===t.length?e.cornerRadii={tl:i,tr:i,br:i,bl:i}:u?(e.cornerRadii={tl:i,bl:i},n.cornerRadii={tr:i,br:i}):(e.cornerRadii={bl:i,br:i},n.cornerRadii={tl:i,tr:i})}}return l}},Ef=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Df=["scene-style","data-paint","accessibility","evidence"],Bf=(t,e)=>({retainedData:t,invalidations:e}),Wf=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Yf=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],qf=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Xf=["scene-geometry","data-paint","accessibility","evidence"],Gf=["scene-style","data-paint","accessibility","evidence"],Vf=[],Hf={chartType:Bf("rebuild",Wf),runtimeMode:Bf("rebuild",Wf),categoryAccessor:Bf("rebuild",Wf),valueAccessor:Bf("rebuild",Wf),oAccessor:Bf("rebuild",Wf),rAccessor:Bf("rebuild",Wf),stackBy:Bf("rebuild",Wf),groupBy:Bf("rebuild",Wf),timeAccessor:Bf("rebuild",Wf),accessorRevision:Bf("rebuild",Wf),colorAccessor:Bf("rebuild",Gf),symbolAccessor:Bf("rebuild",Xf),connectorAccessor:Bf("rebuild",Xf),dataIdAccessor:Bf("rebuild",Xf),projection:Bf("preserve",Yf),extentPadding:Bf("preserve",Yf),axisExtent:Bf("preserve",Yf),rExtent:Bf("preserve",Yf),oExtent:Bf("preserve",Yf),multiAxis:Bf("preserve",Yf),normalize:Bf("preserve",Yf),bins:Bf("preserve",Yf),oSort:Bf("preserve",qf),barPadding:Bf("preserve",qf),roundedTop:Bf("preserve",qf),baselinePadding:Bf("preserve",qf),innerRadius:Bf("preserve",qf),cornerRadius:Bf("preserve",qf),startAngle:Bf("preserve",qf),sweepAngle:Bf("preserve",qf),trackFill:Bf("preserve",qf),showOutliers:Bf("preserve",qf),showIQR:Bf("preserve",qf),amplitude:Bf("preserve",qf),connectorOpacity:Bf("preserve",qf),showLabels:Bf("preserve",qf),dynamicColumnWidth:Bf("rebuild",qf),customLayout:Bf("preserve",qf),layoutConfig:Bf("preserve",qf),layoutMargin:Bf("preserve",qf),symbolMap:Bf("preserve",Xf),pieceStyle:Bf("preserve",Gf),summaryStyle:Bf("preserve",Gf),connectorStyle:Bf("preserve",Gf),gradientFill:Bf("preserve",Gf),colorScheme:Bf("preserve",Gf),themeCategorical:Bf("preserve",Gf),themeSemantic:Bf("preserve",Gf),themeSequential:Bf("preserve",Gf),themeDiverging:Bf("preserve",Gf),barColors:Bf("preserve",Gf),decay:Bf("preserve",Gf),pulse:Bf("preserve",Gf),staleness:Bf("preserve",Gf),layoutSelection:Bf("preserve",Gf),windowSize:Bf("preserve",Vf),windowMode:Bf("preserve",Vf),clock:Bf("preserve",Vf),transition:Bf("preserve",Vf),introAnimation:Bf("preserve",Vf),onLayoutError:Bf("preserve",Vf)},Uf=Bf("preserve",qf),Kf=class{constructor(){this.tracker=new ns}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}},Ef)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Df):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const i of t){const t=Hf[i]??Uf;"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)}},Zf=require("d3-quadtree"),Qf=class{constructor(t){this.rExtent=new Yc,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Kf,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new $f,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 Wc(t.windowSize),this.getO=Vc(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>Xc(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Yc)):(this.getR=Xc(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Vc(t.stackBy),this.getGroup=Vc(t.groupBy),this.getColor=Vc(t.colorAccessor),this.getSymbol=Vc(t.symbolAccessor),this.getConnector=Vc(t.connectorAccessor),this.getDataId=Vc(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new Wc(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,i;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,i=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:Vl(e,i):null)}currentTime(){return this.config.clock?.()??il()}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(),Gl(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Hl(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=Hl(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,i=this.scales,n=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=(0,Lf.scaleBand)().domain(c).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,i=e.innerRadius||0;p=(0,Lf.scaleLinear)().domain(l).range([i,o])}else u?(f=(0,Lf.scaleBand)().domain(c).range([0,t.height]).padding(h),p=(0,Lf.scaleLinear)().domain(l).range([0,t.width])):(f=(0,Lf.scaleBand)().domain(c).range([0,t.width]).padding(h),p=(0,Lf.scaleLinear)().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((i,n)=>{const r=this.rExtents[n];r.dirty&&r.recalculate(o,i);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?(0,Lf.scaleLinear)().domain([s,a]).range([0,t.width]):(0,Lf.scaleLinear)().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=i,this.multiScales=n,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,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,i="auto"===e?void 0:e;let n=null;if(o){n=new Set;for(const e of t)n.add(this.getO(e))}const r=n?Array.from(this.categories).filter(t=>n.has(t)):Array.from(this.categories);if(o&&void 0===i){const t=Math.max(50,3*n.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;n.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===i)return r;if("function"==typeof i)return r.sort(i);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"===i?(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:i,normalize:n,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let p=0,y=0;if("bar"===o&&d&&n)p=0,y=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const i of e){const e=l(i),n=u(i);0>n?o.set(e,(o.get(e)||0)+n):t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e);for(const t of o.values())p>t&&(p=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=l(o),i=u(o);t.set(e,(t.get(e)||0)+i)}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),i=Math.abs(u(o));t.set(e,(t.get(e)||0)+i)}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,i=g&&!a&&0===p,n=g&&!a&&0===y||"swimlane"===o;null!=r?.[0]||i||(p-=e),null!=r?.[1]||n||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,i,n){return function(t){const{data:e,oExtent:o,oScale:i,projection:n,layout:r,dynamicColumnWidth:s,getO:a,getR:c}=t,l=Object.create(null),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"===n)for(const t of e)d+=Math.abs(c(t));let h=null;if(s&&"radial"!==n){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let i;i="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,i),t+=i}const e=("horizontal"===n?r.height:r.width)-i.padding()*i.step()*o.length;if(t>0)for(const[o,i]of h)h.set(o,i/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),n=d>0?o/d:0;let r,s;h?(r=p,s=h.get(t)||i.bandwidth(),p+=s+i.padding()*i.step()):(r=i(t)??0,s=i.bandwidth()),l[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:i.padding()*i.step(),pieceData:e,pct:n,pctStart:f},f+=n}return l}({data:t,oExtent:e,oScale:o,projection:i,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e);let i;try{i=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Dl("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=i.overlays??null,this.lastCustomLayoutResult=i,this.lastCustomLayoutFailure=null;const n=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of n)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(n,this.config.layoutSelection??null)}return Fl({label:"ordinal customLayout",nodes:n,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),n}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),i=Nf[this.config.chartType];let n=i?i(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:i,getConnector:n,getO:r}=t;if(!n||!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=n(e);if(!o)continue;let i,s;"point"===t.type?(i=t.x,s=t.y):(i=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:i,y:s,datum:e,category:r(e)})}const l=o.o.domain(),u=i.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 i=0;o.length-1>i;i++){const n=o[i],r=o[i+1],a="function"==typeof u?u(n.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:n.x,y1:n.y,x2:r.x,y2:r.y,style:a,datum:n.datum,group:e})}}return s}(o,n);n=[...t,...n]}return n}buildLayoutContext(t,e){const o=this.config,i=o.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Ns(o.colorScheme,o.themeCategorical,nt),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:i,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:[...n]},resolveColor:Es(n,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?nl(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=rl(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,i=o?null:e||"category",n=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[i],c=n.get(a);c?c.push(r):n.set(a,[r])}return n}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,o=0;for(const i of t)"point"===i.type&&!1!==i.interactive&&(e++,i.r>o&&(o=i.r));if(500>=e)return{quadtree:null,maxRadius:o};const i=Array(e);let n=0;for(const e of t)"point"===e.type&&!1!==e.interactive&&(i[n++]=e);return{maxRadius:o,quadtree:(0,Zf.quadtree)().x(t=>t.x).y(t=>t.y).addAll(i)}}(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 i=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=i.get(e.datum);if(null==t)continue;const n=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*n}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,i,n,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;for(const l of e){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const e=l.category;if(!e)continue;let i=0;for(const s of n(e)??[]){const e=o.get(s);null!=e&&(i=Math.max(i,sl(t,e,r)))}c=al(l,i,s)||c;continue}if(null==l.datum)continue;const e=i.get(l.datum);if(null==e)continue;const u=o.get(e);c=al(l,null==u?0:sl(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&&cl(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 i;for(let n=0;this.scene.length>n;n++){const r=this.scene[n],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,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===i&&(i=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:i,endAngle:i,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}`,i=e.get(o)||0;return e.set(o,i+1),`${o}:${i}`}if("rect"===t.type){const o=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",i=`r:${t.group||""}:${o}`,n=e.get(i)||0;return e.set(i,n+1),0===n?i:`${i}:${n}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],i=this.getNodeKey(o,t);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(i,{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,i=new Map;for(let t=0;this.scene.length>t;t++){const n=this.scene[t],r=this.getNodeKey(n,i);if(!r)continue;n._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===n.type)s?(o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(s.x!==n.x||s.y!==n.y||void 0!==s.r&&s.r!==n.r)&&(n._targetX=n.x,n._targetY=n.y,n._targetR=n.r,n.x=s.x,n.y=s.y,void 0!==s.r&&(n.r=s.r),e=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetR=n.r,n.r=0,n.style={...n.style,opacity:0},e=!0);else if("rect"===n.type)s?(o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,s.x===n.x&&s.y===n.y&&s.w===n.w&&s.h===n.h||(n._targetX=n.x,n._targetY=n.y,n._targetW=n.w,n._targetH=n.h,n.x=s.x,n.y=s.y,n.w=s.w??n.w,n.h=s.h??n.h,e=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n.style={...n.style,opacity:0},e=!0);else if("wedge"===n.type)if(s)o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,s.startAngle===n.startAngle&&s.endAngle===n.endAngle||(n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle,n.startAngle=s.startAngle,n.endAngle=s.endAngle,e=!0);else{n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle;const t=n.startAngle;n.startAngle=t,n.endAngle=t,n.style={...n.style,opacity:0},this.prevPositionMap.set(r,{x:n.cx,y:n.cy,startAngle:t,endAngle:t,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,i]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:i.x,y:i.y,r:i.r??3,style:{opacity:i.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:i.x,y:i.y,w:i.w??0,h:i.h??0,style:{opacity:i.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((i.startAngle??0)+(i.endAngle??0))/2,o={type:"wedge",cx:i.x,cy:i.y,innerRadius:i.innerRadius??0,outerRadius:i.outerRadius??100,startAngle:i.startAngle??0,endAngle:i.endAngle??0,style:{opacity:i.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=el(t,this.activeTransition),o=tl(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 i=this.prevPositionMap.get(e);t.style.opacity=ol(i?i.opacity??1:0,t._targetOpacity,o)}const i=this.prevPositionMap.get(e);void 0!==t._targetX&&i&&(t.x=ol(i.x,t._targetX,o),t.y=ol(i.y,t._targetY,o)),void 0!==t._targetR&&void 0!==i?.r&&(t.r=ol(i.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const i=this.prevPositionMap.get(e);t.style.opacity=ol(i?i.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const i=this.prevPositionMap.get(e);if(!i)continue;t.x=ol(i.x,t._targetX,o),t.y=ol(i.y,t._targetY,o),void 0!==i.w&&(t.w=ol(i.w,t._targetW,o),t.h=ol(i.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const i=this.prevPositionMap.get(e);t.style={...t.style,opacity:ol(i?i.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const i=this.prevPositionMap.get(e);i&&void 0!==i.startAngle&&(t.startAngle=ol(i.startAngle,t._targetStartAngle,o),t.endAngle=ol(i.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,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Jc(t),o=this.getDataId,i=t=>e.has(o(t));Ul(this.buffer,this.timestampBuffer,i);const n=this.buffer.remove(i);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=Jc(t),i=this.getDataId,n=new Set;this.buffer.forEach((t,e)=>{o.has(i(t))&&n.add(e)});const r=this.buffer.update(t=>o.has(i(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),n.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const i of t){const t=this._baseStyles.get(i)??i.style??{},n=o(i,e);i.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),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(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.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 t&&t.colorScheme!==e.colorScheme||"themeCategorical"in t&&t.themeCategorical!==e.themeCategorical||"colorAccessor"in t&&!qc(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!qc(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!qc(t.oAccessor,e.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in t||"oAccessor"in t)&&(qc(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=Vc(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let n=!1;if("valueAccessor"in t||"rAccessor"in t){const t=this.config.valueAccessor||this.config.rAccessor,o=e.valueAccessor||e.rAccessor,i=Array.isArray(t)?t:[t],r=Array.isArray(o)?o:[o];if(n=i.length!==r.length||i.some((t,e)=>!qc(t,r[e])),n){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>Xc(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Yc)):(this.getR=Xc(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!qc(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?Vc(this.config.stackBy):void 0),"groupBy"in t&&!qc(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?Vc(this.config.groupBy):void 0),"colorAccessor"in t&&!qc(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Vc(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!qc(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Vc(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!qc(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Vc(this.config.connectorAccessor):void 0),(i||n||"accessorRevision"in t&&t.accessorRevision!==e.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};iu(Qf);var Jf=c(require("react")),tp=require("react/jsx-runtime");function ep(t){return"connector"===t.node.type}function op(t,e,o,i){if(2>t.length)return null;const n=t[0].node,r=n.style.fill;if(!r||"none"===r)return null;const s=Cu(`${e?e+"-":""}connector-${o}-${i}-hatch`),a=xn(r)?bn(r,s):null,c=[`${n.x1},${n.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return Nu((0,tp.jsxs)(Jf.Fragment,{children:[a&&(0,tp.jsx)("defs",{children:a}),(0,tp.jsx)("polygon",{points:c,fill:a?`url(#${s})`:Ru(r,"#999"),opacity:n.style.fillOpacity??n.style.opacity??.3,"data-semiotic-connector-fill":n.group||"_default"})]}),n,`ordinal-connector-fill-${o}-${i}`)}function ip(t,e,o){const i=new Map;for(const e of t){if(!ep(e))continue;const t=e.node.group||"_default",o=i.get(t);o?o.push(e):i.set(t,[e])}if(0===i.size)return;const n=Array.from(i.values()).map((t,i)=>(0,tp.jsxs)("g",{children:[op(t,e,o,i),t.map(t=>t.element)]},`ordinal-connectors-${o}-${i}`)),r=t[0],s=ep(r)?null:r.element;for(const t of i.values())for(const e of t)e.element=null;r.element=(0,tp.jsxs)(Jf.Fragment,{children:[n,s]},"ordinal-connector-run-"+o)}function np(t){const e=id({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>Zu(e,o,t.idPrefix)});let o=0;for(let i=0;e.length>i;){if(e[i].renderedByBackend){i++;continue}let n=i+1;for(;e.length>n&&!e[n].renderedByBackend;)n++;ip(e.slice(i,n),t.idPrefix,o++),i=n}return e}var rp=require("react/jsx-runtime"),sp=require("react/jsx-runtime"),ap=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function cp(t,e){const o=Ot(t.theme),i=t.size||[500,400],n=pe({...vf,...t.margin},t.title),r=he(t.title),s=P(t.data),a=t.showLegend?yd(s,t.colorAccessor||t.stackBy||t.groupBy):[],c=function(t){const e=t.projection??"vertical",o=!1!==t.showAxes&&"radial"!==e;return{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasValueLabel:t.hasCategoryLabel),leftAxis:{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasCategoryLabel:t.hasValueLabel)}}}({showAxes:t.showAxes,projection:t.projection,hasCategoryLabel:!(!t.categoryLabel&&!t.oLabel),hasValueLabel:!(!t.valueLabel&&!t.rLabel)});pf(n,{props:{...t,axisChrome:c},categories:a,theme:o,size:i,hasTitle:r});const l=yf({props:{...t,axisChrome:c},categories:a,theme:o,size:i,margin:n,hasTitle:r}),u=i[0]-n.left-n.right,d=i[1]-n.top-n.bottom,h=t.projection||"vertical",f="radial"===h,p=t.colorScheme||o.colors.categorical,y={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:kt(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:p,themeCategorical:o.colors.categorical,themeSemantic:It(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors},g=new Qf(y);t.data&&g.ingest({inserts:s,bounded:!0}),g.computeScene({width:u,height:d});const m=bf(t.backgroundGraphics,i,n,g.scales),x=bf(t.foregroundGraphics,i,n,g.scales);if(!g.scales){let r;const a=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,projection:h,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ec({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:g.scales?[]:["NO_SCALES"],margin:n})),jf.renderToStaticMarkup(mf(m||x||t.annotations?(0,sp.jsxs)(sp.Fragment,{children:[m,a,x,g.customLayoutOverlays]}):null,{width:i[0],height:i[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=t.showGrid?function(t,e,o,i,n){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=zt(o),a=i?i+"-":"",c="vertical"===r.projection,l=Zh(r.r,5,n);return(0,af.jsx)("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const i=r.r(t);return(0,af.jsx)("line",{x1:0,y1:i,x2:e.width,y2:i,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const i=r.r(t);return(0,af.jsx)("line",{x1:i,y1:0,x2:i,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(g,{width:u,height:d},o,b,t.axisExtent):null;let w=null;if(g.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=lf(t),i=new Set;for(const t of g.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&i.add("string"==typeof t.style.fill?t.style.fill:"#666");w=Array.from(i).map((t,i)=>function(t){const{id:e,background:o="transparent",stroke:i="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return(0,rp.jsxs)("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&(0,rp.jsx)("rect",{width:a,height:a,fill:o}),(0,rp.jsx)("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:n}),(0,rp.jsx)("line",{x1:r,y1:0,x2:r,y2:a,stroke:i,strokeWidth:n})]},e)}({id:`funnel-hatch-${e}-${i}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const n=new Map;Array.from(i).forEach((t,o)=>n.set(t,`funnel-hatch-${e}-${o}`));for(const t of g.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${n.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const k=np({nodes:g.scene,renderMode:t.renderMode,idPrefix:b}),S=k.map(t=>t.element),A=!1!==t.showAxes?function(t,e,o,i,n,r,s,a=!1){const c=t.scales;if(!c)return null;if("radial"===c.projection)return null;const l=zt(i),u="vertical"===c.projection,d=t.columns,h=o.categoryFormat||o.oFormat,f=o.valueFormat||o.rFormat,p=o.categoryLabel||o.oLabel,y=o.valueLabel||o.rLabel,g=o.legendPosition??"right",m=$e(o.legendLayout,s?.leftAxis),x=a&&"left"===g&&m>0?m:r?.left??o.margin?.left??40,b=Object.values(d).map((t,e)=>({pixel:t.middle,label:h?h(t.name,e):t.name})),v=Zh(c.r,5,o.axisExtent).map(t=>({pixel:c.r(t),label:(f||gf)(t)}));return(0,sp.jsxs)("g",u?{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[(0,sp.jsx)("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,o)=>(0,sp.jsxs)("g",{transform:`translate(${t.pixel},${e.height})`,children:[(0,sp.jsx)("line",{y2:5,stroke:l.border,strokeWidth:1}),Jh(t.label)?(0,sp.jsx)("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):tf({label:t.label,x:-30,y:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oxtick-"+o)),p&&(0,sp.jsx)("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:p}),(0,sp.jsx)("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,e)=>(0,sp.jsxs)("g",{transform:`translate(0,${t.pixel})`,children:[(0,sp.jsx)("line",{x2:-5,stroke:l.border,strokeWidth:1}),(0,sp.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oytick-"+e)),y&&(0,sp.jsx)("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:y})]}:{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[(0,sp.jsx)("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,o)=>(0,sp.jsxs)("g",{transform:`translate(${t.pixel},${e.height})`,children:[(0,sp.jsx)("line",{y2:5,stroke:l.border,strokeWidth:1}),(0,sp.jsx)("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oxtick-"+o)),y&&(0,sp.jsx)("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:y}),(0,sp.jsx)("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,e)=>(0,sp.jsxs)("g",{transform:`translate(0,${t.pixel})`,children:[(0,sp.jsx)("line",{x2:-5,stroke:l.border,strokeWidth:1}),Jh(t.label)?(0,sp.jsx)("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):tf({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oytick-"+e)),p&&(0,sp.jsx)("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:p})]})}(g,{width:u,height:d},t,o,b,n,c,!!l):null;let M;const _=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:g.scales.o,r:g.scales.r,y:"vertical"===g.scales.projection?g.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,xAccessor:"string"==typeof t.oAccessor?t.oAccessor:void 0,yAccessor:"string"==typeof t.rAccessor?t.rAccessor:void 0,idPrefix:b,onRender:t=>{M=t}}):null;if(e){const o=g.scales.o?.domain?.();e.evidence=Ec({frameType:"ordinal",width:i[0],height:i[1],marks:k.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:M,yDomain:Nc(g.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:n})}const j=f&&t.centerContent?function(t,e,o){if(!Pf.isValidElement(t))return null;if("string"!=typeof t.type||!ap.has(t.type))return null;const i=t,n="text"===i.type?Pf.cloneElement(i,{x:i.props.x??0,y:i.props.y??0,textAnchor:i.props.textAnchor??"middle",dominantBaseline:i.props.dominantBaseline??"middle"}):i;return(0,sp.jsx)("g",{className:"semiotic-radial-center-content",transform:`translate(${e},${o})`,pointerEvents:"none",children:n})}(t.centerContent,n.left+u/2,n.top+d/2):null,L=f&&t.centerContent?j??(0,sp.jsx)("foreignObject",{x:n.left,y:n.top,width:u,height:d,pointerEvents:"none",children:(0,sp.jsx)("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,$=(0,sp.jsxs)(sp.Fragment,{children:[v,S,A,_,x,g.customLayoutOverlays]});return jf.renderToStaticMarkup(mf((0,sp.jsxs)(sp.Fragment,f?{children:[m?(0,sp.jsx)("g",{transform:`translate(${-u/2},${-d/2})`,children:m}):null,$]}:{children:[m,$]}),{width:i[0],height:i[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:f?`translate(${n.left+u/2},${n.top+d/2})`:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,defs:w,outerElements:L,idPrefix:t._idPrefix}))}var lp=c(require("react-dom/server"));function up(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function dp(t,e){var o,i=[],n=[],r=[],s={},a=[];function c(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&c(e)})}function l(t){var e,i,d=!1;for(n.push(t),r[t]=!0,e=0;a[t].length>e;e++)(i=a[t][e])===o?(u(o,n),d=!0):r[i]||(d=l(i));if(d)c(t);else for(e=0;a[t].length>e;e++){var h=s[i=a[t][e]];h||(s[i]=h={}),h[i]=!0}return n.pop(),d}function u(t,o){var n=[].concat(o).concat(t);e?e(n):i.push(n)}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,i=function(t){for(var e=t.length,o=Array(e),i=Array(e),n=Array(e),r=Array(e),s=Array(e),a=Array(e),c=0;e>c;++c)o[c]=-1,i[c]=0,n[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]=i[e]=u,n[e]=!0,u+=1;l.length>0;){var f=t[e=l[l.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>o[y]){o[y]=i[y]=u,n[y]=!0,u+=1,c.push(y),l.push(y);break}n[y]&&(i[e]=0|Math.min(i[e],i[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(i[e]===o[e]){var g=[],m=[],x=0;for(p=c.length-1;p>=0;--p){var b=c[p];if(n[b]=!1,g.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){c.length=p;break}}d.push(g);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];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),n=i.components.filter(function(t){return t.length>1}),r=1/0,s=0;n.length>s;s++)for(var a=0;n[s].length>a;a++)r>n[s][a]&&(r=n[s][a],o=s);var c=n[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:i}function hp(t){return t.y0-t.y1>0?"up":"down"}function fp(t,e){return e(t.source)==e(t.target)}function pp(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 yp(t){return t.target.x0-t.source.x1}function gp(t,e){var o=xp(t),i=yp(e)/Math.tan(o);return"up"==hp(t)?t.y1-i:t.y1+i}function mp(t,e){var o=xp(t),i=yp(e)/Math.tan(o);return"up"==hp(t)?t.y1+i:t.y1-i}function xp(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function bp(t,e){return e(t)}function vp(t){return kp(t.source)}function wp(t){return kp(t.target)}function kp(t){return(t.y0+t.y1)/2}function Sp(t){return t.virtual?0:t.value}function Ap(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!fp(t,e)?o+1:o});var i=0;return t.targetLinks.forEach(function(t){i=t.circular&&!fp(t,e)?i+1:i}),o+i}function Mp(t){return t.target.depth}function _p(t,e){return t.sourceLinks.length?t.depth:e-1}function Pp(t,e){return t.y0-e.y0}function jp(t,e){return e.y0-t.y0}function Lp(t,e){return t.y1-e.y1}function $p(t,e){return e.y1-t.y1}function Rp(t,e){return Ip(t.source,e.source)||t.index-e.index}function Cp(t,e){return Ip(t.target,e.target)||t.index-e.index}function Ip(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Tp(t,e){return Op(t)==Op(e)?"bottom"==t.circularLinkType?jp(t,e):Pp(t,e):Op(e)-Op(t)}function Op(t){return t.target.column-t.source.column}function zp(t,e){return Fp(t)==Fp(e)}function Fp(t){return t.y0-t.y1>0?"up":"down"}var Np=require("d3-array");function Ep(t,e,o,i,n){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=(0,Np.min)(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}),Dp(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),Dp(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+i,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,fp(t,e)&&pp(t))t.circularPathData.rightSmallArcRadius=i+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=i+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=i+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=i+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,c=t.circularLinkType,l=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==c});l.sort("bottom"==t.circularLinkType?jp:Pp);var u=0;l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=i+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=i+t._circularWidth/2+n*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?$p:Lp),u=0,l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=i+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=i+t._circularWidth/2+n*o+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,o=t.y0,i=t.target.x0,n=t.y1,r=(e+i)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+n+" "+i+","+n}(t)}),r}function Dp(t,e,o){t.sort(Tp);var i=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,n){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(fp(t,e)&&pp(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;i.length>s;s++){var a=i[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&Bp(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 Bp(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}var Wp=require("d3-array");function Yp(t){return function(){return t}}function qp(t){return t.index}function Xp(t){return t.nodes}function Gp(t){return t.links}function Vp(t,e,o){var i=(0,Wp.groups)(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});i.forEach(function(n,r){var s=n.length;if(e)n.sort(e);else if(r>0){var a=new Map;n.forEach(function(t,e){var o,i,n,r=(i=0,n=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=kp(t.source)*e,i+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=kp(t.target)*e,i+=e}}),i>0?n/i:NaN);a.set(t,{bc:r,idx:e})}),n.sort(function(t,e){var o=a.get(t),i=a.get(e),n=o.bc,r=i.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(n)||isNaN(r)?isNaN(n)?isNaN(r)?o.idx-i.idx:1:-1:n-r})}else n.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Ap(e,o)-Ap(t,o):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});n.forEach(function(e,n){e.depth==i.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==Ap(e,o)?(e.y0=t.y1/2+n,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+n,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-n,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*n,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+n,e.y1=e.y0+e.value*t.ky)})})}function Hp(t,e,o,i,n,r){var s=(0,Wp.groups)(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 i=s.length;s.forEach(function(n){var r=n.length,s=n[0].depth;n.forEach(function(n){var a;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&Ap(n,o)>0){var c=(0,Wp.mean)(n.sourceLinks,wp),l=(0,Wp.mean)(n.targetLinks,vp),u=c&&l?(c+l)/2:c||l;if(u){var d=(u-kp(n))*e*.3;n.y0+=d,n.y1+=d}}else if(0==s&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(s==i-1&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)a=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+a;else{var h=(0,Wp.mean)(n.sourceLinks,wp),f=(0,Wp.mean)(n.targetLinks,vp),p=((h&&f?(h+f)/2:h||f)-kp(n))*e;n.y0+=p,n.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,c=t.y0,l=o.length;for(o.sort(e||Ip),a=0;l>a;++a)(s=c-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),c=r.y1+i;if((s=c-i-t.y1)>0)for(c=r.y0-=s,r.y1-=s,a=l-2;a>=0;--a)(s=(r=o[a]).y1+n-c)>0&&(r.y0-=s,r.y1-=s),c=r.y0})}}function Up(t){t.nodes.forEach(function(t){t.sourceLinks.sort(Cp),t.targetLinks.sort(Rp)}),t.nodes.forEach(function(t){var e=t.y0,o=e,i=t.y1,n=i;t.sourceLinks.forEach(function(t){t.circular?(t.y0=i-t.width/2,i-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=n-t.width/2,n-=t.width):(t.y1=o+t.width/2,o+=t.width)})})}function Kp(){var t=0,e=0,o=1,i=1,n=24,r=8,s=null,a=qp,c=_p,l=void 0,u=32,d=2,h=Xp,f=Gp;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=i,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(0,Wp.group)(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 i=t.source,n=t.target;"object"!=typeof i&&(i=t.source=up(o,i)),"object"!=typeof n&&(n=t.target=up(o,n)),i.sourceLinks.push(t),n.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var i=[],n=0;t.links.length>n;n++){var r=t.links[n],s=r.source.index,a=r.target.index;i[s]||(i[s]=[]),i[a]||(i[a]=[]),-1===i[s].indexOf(a)&&i[s].push(a)}var c=dp(i);c.sort(function(t,e){return t.length-e.length});var l={};for(n=0;c.length>n;n++){var u=c[n].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,i=t.source.index;e===i||l[i]&&l[i][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,i=0;t.links.forEach(function(n){n.circular&&(n.circularLinkType=n.source.circularLinkType||n.target.circularLinkType?n.source.circularLinkType?n.source.circularLinkType:n.target.circularLinkType:i>o?"top":"bottom","top"==n.circularLinkType?o++:i++,t.nodes.forEach(function(t){bp(t,e)!=bp(n.source,e)&&bp(t,e)!=bp(n.target,e)||(t.circularLinkType=n.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),fp(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max((0,Wp.sum)(t.sourceLinks,Sp),(0,Wp.sum)(t.targetLinks,Sp)),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 i,n,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(i=t.nodes,n=[],r=0;i.length;++r,i=n,n=[])i.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>n.indexOf(t.target)&&!t.circular&&n.push(t.target)})});for(i=t.nodes,n=[],r=0;i.length;++r,i=n,n=[])i.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>n.indexOf(t.source)&&!t.circular&&n.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,l,c);var f=r;if(null!==s){var p=(0,Wp.groups)(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=(0,Wp.max)(p,function(t){return t.length});y>1&&(f=Math.max(1,(i-e)*s/(y-1)))}(function(t,e,o){var i=(0,Wp.groups)(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var n=(0,Wp.min)(i,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/(0,Wp.sum)(e,function(t){return t.value})});t.ky=n,t.links.forEach(function(e){e.width=e.value*t.ky});var r=(0,Wp.max)(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,n),Vp(h,l,a),Hp(h,l,a,f,f,u),Up(h),Ep(h,a,d,10,8),Vp(h,l,a),Hp(h,l,a,f,f,u),Up(h),Ep(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 i=o.links.filter(function(o){return bp(o.source,e)==bp(t,e)}),n=i.length;n>1&&i.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!zp(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=gp(e,t);return t.y1-o}if(e.target.column>t.target.column)return gp(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;i.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),i.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;n>r;r++)s+=i[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var i=o.links.filter(function(o){return bp(o.target,e)==bp(t,e)}),n=i.length;n>1&&i.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!zp(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=mp(e,t);return t.y0-o}if(e.source.column>t.source.column)return mp(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;i.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),i.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;n>r;r++)s+=i[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,i=!1,n=!1;if(o.forEach(function(t){"top"==t.circularLinkType?i=!0:"bottom"==t.circularLinkType&&(n=!0)}),0==i||0==n){let i=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=(0,Wp.min)(e,function(t){return t.y0}),s=(0,Wp.max)(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=i(t.y0),t.y1=i(t.y1)}),o.forEach(function(t){t.y0=i(t.y0),t.y1=i(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=i(t.y0)-t.y0;t.y0=i(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),Ep(h,a,d,10,8)}(p),p}return p.update=function(t){return Up(t),Ep(t,a,d,10,8),t},p.nodeWidth=function(t){return arguments.length?(n=+t,p):n},p.nodePadding=function(t){return arguments.length?(r=+t,p):r},p.nodePaddingRatio=function(t){return arguments.length?(s=+t,p):s},p.nodes=function(t){return arguments.length?(h="function"==typeof t?t:Yp(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:Yp(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:Yp(t),p):a},p.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:Yp(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(n){return arguments.length?(t=+n[0][0],e=+n[0][1],o=+n[1][0],i=+n[1][1],p):[[t,e],[o,i]]},p.size=function(n){return arguments.length?(t=e=0,o=+n[0],i=+n[1],p):[o-t,i-e]},p}var Zp=require("d3-interpolate"),Qp=(require("d3-shape"),.5),Jp=t=>{let e,o,i,n,r,s,a,c,l;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,i=t.y1+t.sankeyWidth/2,n=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=(0,Zp.interpolateNumber)(r,s),c=a(Qp),l=a(.5),`M${e},${r}C${e},${c} ${o},${l} ${o},${s}L${i},${s}C${i},${l} ${n},${c} ${n},${r}Z`;const u=t.sankeyWidth/2,d=(0,Zp.interpolateNumber)(t.source.x1,t.target.x0),{pathD:h}=cn({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(Qp),cp2X:d(.5)});return h};function ty(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,i=t.circularPathData;if(!i)return null;if("down"===t.direction)return null;if(t._circularStub){const o=i.sourceX,n=i.sourceY,r=i.targetX,s=i.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*(i.rightFullExtent-o))),c=Math.max(15,Math.min(40,.33*(r-i.leftFullExtent)));return`M${o},${n-e}L${o+a},${n-e}L${o+a},${n+e}L${o},${n+e}ZM${r},${s-e}L${r-c},${s-e}L${r-c},${s+e}L${r},${s+e}Z`}const n=i.sourceX,r=i.sourceY,s=i.targetX,a=i.targetY,c=i.rightFullExtent,l=i.leftFullExtent,u=i.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${n},${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${n},${r+d*e}Z`}var ey=new Set,oy=new WeakMap;function iy(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=oy.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,oy.set(t,o);const i=new Proxy(t,{get(t,o,i){if("string"==typeof o&&!(o in t)&&t.data&&o in t.data){const t=`${e}:${o}`;ey.has(t)||(ey.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,i)}});return o.set(e,i),i}var ny={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(Mp))-1:0},justify:_p},ry={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const n="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:Uc(t.source),target:Uc(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===n?[[0,0],[i[1],i[0]]]:[[0,0],[i[0],i[1]]];const h=Kp().extent(d).links(u).nodes(l).nodeAlign(ny[r]||_p).nodeId(t=>t.id).nodeWidth(s).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,n=-1/0;for(const i of l)t>i.x0&&(t=i.x0),i.x1>e&&(e=i.x1),o>i.y0&&(o=i.y0),i.y1>n&&(n=i.y1);for(const i of u){if(!i.circular||!i.circularPathData)continue;const r=i.circularPathData,s=(i._circularWidth??i.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>n&&(n=r.verticalFullExtent+s)}const r=e-t,s=n-o,a=i[0],c=i[1];if(r>0&&s>0&&(0>t||0>o||e>a||n>c)){const e=Math.min(a/r,c/s),i=-t*e+(a-r*e)/2,n=-o*e+(c-s*e)/2;for(const t of l)t.x0=t.x0*e+i,t.x1=t.x1*e+i,t.y0=t.y0*e+n,t.y1=t.y1*e+n;for(const t of u)if(t.y0=t.y0*e+n,t.y1=t.y1*e+n,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+i,o.targetX=o.targetX*e+i,o.sourceY=o.sourceY*e+n,o.targetY=o.targetY*e+n,o.rightFullExtent=o.rightFullExtent*e+i,o.leftFullExtent=o.leftFullExtent*e+i,o.verticalFullExtent=o.verticalFullExtent*e+n,o.rightInnerExtent=o.rightInnerExtent*e+i,o.leftInnerExtent=o.leftInnerExtent*e+i,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+n,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+n,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)if(t._edgeKey)p.set(t._edgeKey,t);else{const e=Uc(t.source),o=Uc(t.target);p.set(`${e}\0${o}`,t)}for(const t of u){const e=Uc(t.source),o=Uc(t.target),i=p.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(i){i.y0=t.y0,i.y1=t.y1,i.sankeyWidth=t.width??0,i.circular=!!t.circular,i.circularPathData=t.circularPathData,i._circularWidth=t._circularWidth,i._circularStub=t._circularStub,i.path=t.path,i.circularLinkType=t.circularLinkType,i.direction=n;const r=f.get(e),s=f.get(o);r&&(i.source=r),s&&(i.target=s)}}},buildScene(t,e,o,i){const n="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:C,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 i=r?r(iy(e,"nodeStyle")):{},s={fill:i.fill||u.get(e.id)||"#4d430c",stroke:i.stroke,strokeWidth:i.strokeWidth,opacity:i.opacity,cursor:i.cursor};p.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===n?{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,i="object"==typeof t.target?t.target:null;if(!e||!i)continue;let n=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";n="function"==typeof c?c(t)||n:"target"===c?p.get(i.id)||u.get(i.id)||n:p.get(e.id)||u.get(e.id)||n;const r=s?s(iy(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,i=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),c=r.fill||n;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+i},${e.sourceY-o}L${e.sourceX+i},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+i}}),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,cursor:r.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let l;(l=t.circular&&t.circularPathData?ty(t):Jp(t),l)&&h.push({type:"bezier",pathD:l,bezierCache:t.bezier,style:{fill:r.fill||n,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor},datum:t})}if(!1!==o.showLabels){const e=Hc(o.nodeLabel);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"===n?(a=o.y0+(o.y1-o.y0)/2,c=o.x1+14,l="start"):(i[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"===n?"middle":l,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}},sy=require("d3-force"),ay=require("d3-scale"),cy={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const n=o.forceStrength??.1,r=i[0]/2,s=i[1]/2,a=Math.max(.1,Math.min(1,Math.min(i[0],i[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 i=ly(t.id,e,o);if(i.length>0){let e=0,o=0;for(const t of i)e+=t.x,o+=t.y;const n=uy(t.id),r=n%360*(Math.PI/180),s=(10+n%20)*a;t.x=e/i.length+s*Math.cos(r),t.y=o/i.length+s*Math.sin(r)}else{const e=uy(t.id),o=e%360*(Math.PI/180),i=(15+e%30)*a;t.x=r+i*Math.cos(o),t.y=s+i*Math.sin(o)}}}else{const e=2.399963229728653;for(let o=0;t.length>o;o++){const i=t[o];if(null==i.x||null==i.y||0===i.x&&0===i.y){const t=10*Math.sqrt(o+.5)*a,n=o*e;i.x=r+t*Math.cos(n),i.y=s+t*Math.sin(n)}}}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=dy(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=Uc(t.source),o=Uc(t.target);l.set(e,(l.get(e)??0)+1),l.set(o,(l.get(o)??0)+1)}const d=(0,sy.forceLink)().strength(t=>{const e=t.weight,o=Uc(t.source),i=Uc(t.target),r=Math.max(1,Math.min(l.get(o)??1,l.get(i)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*n/(.1*r))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,o="string"==typeof t.target?u.get(t.target):t.target,i=(e?y(e):0)+(o?y(o):0)+Math.max(6,12*a);return Math.max(16,40*a,i)}).id(t=>t.id),p=(0,sy.forceSimulation)();if(void 0===o.random&&void 0===o.seed||p.randomSource(o.random??function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(o.seed)),p.force("charge",(0,sy.forceManyBody)().strength(t=>{const e=l.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",(0,sy.forceCollide)(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",(0,sy.forceCenter)(r,s).strength(.8)).force("x",(0,sy.forceX)(r).strength(c)).force("y",(0,sy.forceY)(s).strength(c)).force("bounds",function(t,e,o=2,i=.6){let n=[];const r=r=>{const s=i*Math.max(r,.2);for(const i of n){const n=i.x??t[0]/2,r=i.y??t[1]/2,a=i.vx??0,c=i.vy??0,l=e(i)+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=n+a,y=r+c;u>p?i.vx=a+(u-p)*s:p>d&&(i.vx=a+(d-p)*s),h>y?i.vy=c+(h-y)*s:y>f&&(i.vy=c+(f-y)*s)}};return r.initialize=t=>{n=t},r}(i,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:Uc(t.source),target:Uc(t.target)}));d.links(t),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let t=0;f>t;++t)p.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=y(e),o=f>0?2:0,n=Math.min(i[0]/2,t+o),r=Math.min(i[1]/2,t+o);e.x=Math.max(n,Math.min(i[0]-n,e.x)),e.y=Math.max(r,Math.min(i[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,i){const n=o.nodeStyle,r=o.edgeStyle,s=dy(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:C,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(iy(e,"nodeSize")),i=n?n(iy(e,"nodeStyle")):{},r={fill:i.fill||c.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:i.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??2,opacity:i.opacity,cursor:i.cursor};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),i="object"==typeof t.target?t.target:h.get(t.target);if(!e||!i)continue;if(null==e.x||null==e.y)continue;if(null==i.x||null==i.y)continue;const n=r?r(iy(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:i.x,y2:i.y,style:{stroke:n.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor},datum:t})}if(!1!==o.showLabels){const e=Hc(o.nodeLabel);for(const o of t){if(null==o.x||null==o.y)continue;const t=e?e(o):o.id;if(!t)continue;const i=s(iy(o,"nodeSize"));d.push({x:o.x,y:o.y-i-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:l,sceneEdges:u,labels:d}}};function ly(t,e,o){const i=[];for(const n of e){const e=Uc(n.source),r=Uc(n.target);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||i.push({x:t.x,y:t.y})}}return i}function uy(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 dy(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 i=e||[5,20],n=[];for(const e of o){const o=e.data?.[t];"number"==typeof o&&n.push(o)}if(0===n.length)return()=>i[0];const[r,s]=Nt(n);if(r===s)return()=>(i[0]+i[1])/2;const a=(0,ay.scaleLinear)().domain([r,s]).range(i).clamp(!0);return e=>{const o=e.data?.[t];return null==o||"number"!=typeof o?i[0]:a(o)}}var hy=require("d3-chord"),fy=require("d3-shape"),py=C,yy={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const{padAngle:n=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(i[0],i[1])/2,c=a-r,l=i[0]/2,u=i[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=Uc(t.source),o=Uc(t.target),i=f.get(e),n=f.get(o);if(void 0===i||void 0===n)continue;const r=d(t);y[i][n]=r}const g=(0,hy.chord)().padAngle(n);s&&g.sortGroups(s);const m=g(y),x=m.groups,b=(0,fy.arc)().innerRadius(c).outerRadius(a);for(const e of x){const o=t[e.index],i=b.centroid({innerRadius:c,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=i[0]+l,o.y=i[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=Uc(t.source),o=Uc(t.target),i=v.get(e),n=v.get(o);i&&(t.source=i),n&&(t.target=n)}const w=new Map;for(const t of e){const e=Uc(t.source),o=Uc(t.target);w.set(`${e}\0${o}`,t)}for(const e of m){const o=t[e.source.index].id,i=t[e.target.index].id,n=w.get(`${o}\0${i}`)||w.get(`${i}\0${o}`);n&&(n.__chordData=e)}},buildScene(t,e,o,i){const{groupWidth:n=20,edgeOpacity:r=.5}=o,s=Math.min(i[0],i[1])/2,a=s-n,c=i[0]/2,l=i[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:py,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=(0,hy.ribbon)().radius(a),g=[],m=[],x=[];for(let e=0;t.length>e;e++){const o=t[e],i=o.__arcData;if(!i)continue;let n;if(u){const t=u(iy(o,"nodeStyle"));n=("string"==typeof t.fill?t.fill:void 0)||p.get(o.id)||f[e%f.length]}else n=p.get(o.id)||f[e%f.length];const r=u?u(iy(o,"nodeStyle")):{};g.push({type:"arc",cx:c,cy:l,innerR:a,outerR:s,startAngle:i.startAngle-Math.PI/2,endAngle:i.endAngle-Math.PI/2,style:{fill:n,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const i=y(e);if(!i)continue;const n=gy(i,c,l);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(iy(t,"edgeStyle"));s=("string"==typeof e.fill?e.fill:void 0)||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(iy(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:n,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor},datum:t})}if(!1!==o.showLabels){const e=Hc(o.nodeLabel),i=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const n=e?e(o):o.id;if(!n)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:c+Math.cos(s)*i,y:l+Math.sin(s)*i,text:n+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:g,sceneEdges:m,labels:x}}};function gy(t,e,o){const i=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!i)return t;const n=[];let r=0;for(;i.length>r;){const t=i[r];if("M"===t||"L"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("C"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)for(let t=0;3>t&&i.length>r&&!isNaN(Number(i[r]));t++)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("Q"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)for(let t=0;2>t&&i.length>r&&!isNaN(Number(i[r]));t++)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("A"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&(n.push(Number(i[r])+e+""),r++),i.length>r&&(n.push(Number(i[r])+o+""),r++);else"Z"===t||"z"===t?(n.push(t),r++):(n.push(i[r]),r++)}return n.join(" ")}var my=require("d3-hierarchy"),xy=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function by(t){const[e,o,i]=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*i>150?"#222":"#fff"}function vy(t,e,o){const i=e.nodeIDAccessor;return"function"==typeof i?i(t.data)+"":"string"==typeof i&&void 0!==t.data[i]?t.data[i]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function wy(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 ky(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:xy}function Sy(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 Ay(t,e,o,i,n){if("horizontal"===n){const n=(t+o)/2;return`M ${t},${e} C ${n},${e} ${n},${i} ${o},${i}`}if("radial"===n){const n=(t+o)/2;return`M ${t},${e} Q ${n},${e} ${n},${(e+i)/2} T ${o},${i}`}{const n=(e+i)/2;return`M ${t},${e} C ${t},${n} ${o},${n} ${o},${i}`}}var My={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,i){const n=o.__hierarchyRoot;if(!n)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=(0,my.hierarchy)(n,s);l.sum(c),l.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=i;switch(r){case"tree":!function(t,e,o,i){const n=e.treeOrientation||"vertical",r=(0,my.tree)();r.size("horizontal"===n?[i,o]:"radial"===n?[2*Math.PI,Math.min(o,i)/2*.8]:[o,i]),r(t)}(l,o,u,d);break;case"cluster":!function(t,e,o,i){const n=e.treeOrientation||"vertical",r=(0,my.cluster)();r.size("horizontal"===n?[i,o]:"radial"===n?[2*Math.PI,Math.min(o,i)/2*.8]:[o,i]),r(t)}(l,o,u,d);break;case"treemap":!function(t,e,o,i){const n=e.padding??4,r=e.paddingTop??0,s=(0,my.treemap)().size([o,i]).tile(my.treemapBinary).padding(n);r>0&&s.paddingTop(r),s(t)}(l,o,u,d);break;case"circlepack":!function(t,e,o,i){const n=e.padding??4;(0,my.pack)().size([o,i]).padding(n)(t)}(l,o,u,d);break;case"partition":!function(t,e,o,i){(0,my.partition)().size([o,i]).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 i=h[e],n={id:vy(i,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:i.value??0,depth:i.depth,data:i.data,createdByFrame:!0};"tree"===r||"cluster"===r?_y(n,i,o):"treemap"===r||"partition"===r?Py(n,i):"circlepack"===r&&jy(n,i),n.__hierarchyNode=i,t.push(n),f.set(i,n)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=f.get(t.parent),i=f.get(t);o&&i&&e.push({source:o,target:i,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,i){const n=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,i,n,r){const s=[],a=[],c=[],l=o.treeOrientation||"vertical",u="radial"===l,d=i[0]/2,h=i[1]/2,f="number"==typeof(p=o.nodeSize)?p:5;var p;for(const e of t){let t=e.x,i=e.y;u&&(t+=d,i+=h);const r=n(iy(e,"nodeStyle"));let a=r.fill||Sy(o);if(o.colorByDepth&&void 0!==e.depth){const t=ky(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:i,r:f,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},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,i="object"==typeof t.target?t.target:null;if(!e||!i)continue;let n=e.x,s=e.y,c=i.x,f=i.y;u&&(n+=d,s+=h,c+=d,f+=h);const p=Ay(n,s,c,f,l),g=r(iy(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,cursor:g.cursor},datum:t})}if(!1!==o.showLabels){const e=wy(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let i,n,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?(i=s+t/o*10,n=a+e/o*10,r=0>t?"end":"start"):(i=s,n=a-12,r="middle")}else"horizontal"===l?(o.data?.children&&0!==o.data.children.length?(i=s-f-6,r="end"):(i=s+f+6,r="start"),n=a):(i=s,n=a+f+14,r="middle");c.push({x:i,y:n,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:c}}(t,e,o,i,n,r);case"treemap":case"partition":return function(t,e,o,i){const n=[],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=i(iy(o,"nodeStyle"));let a=s.fill||Sy(e);if(e.colorByDepth&&void 0!==o.depth){const t=ky(e);a=t[o.depth%t.length]}n.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,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity,cursor:s.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=wy(e.nodeLabel),n=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,c=a.y1-a.y0;if(0>=t||0>=c)continue;const l=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===n&&!l)continue;if("parent"===n&&l)continue}const u=o?o(a):a.id;if(!u)continue;if((l?30:40)>t||(l?16:14)>c)continue;let d=i(iy(a,"nodeStyle")).fill||Sy(e);if(e.colorByDepth&&void 0!==a.depth){const t=ky(e);d=t[a.depth%t.length]}const h="string"==typeof d?by(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:n,sceneEdges:[],labels:r}}(t,o,0,n);case"circlepack":return function(t,e,o,i){const n=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=i(iy(o,"nodeStyle"));let s=r.fill||Sy(e);if(e.colorByDepth&&void 0!==o.depth){const t=ky(e);s=t[o.depth%t.length]}n.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,cursor:r.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=wy(e.nodeLabel);for(const n of t){const t=n.__radius??5,s=o?o(n):n.id;if(!s)continue;if(15>t)continue;const a=!(n.data?.children&&n.data.children.length>0);let c=i(iy(n,"nodeStyle")).fill||Sy(e);if(e.colorByDepth&&void 0!==n.depth){const t=ky(e);c=t[n.depth%t.length]}if(a){const o="string"==typeof c?by(c):e.themeSemantic?.text??"#000";r.push({x:n.x,y:n.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:o})}else r.push({x:n.x,y:n.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:n,sceneEdges:[],labels:r}}(t,o,0,n);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function _y(t,e,o){const i=o.treeOrientation||"vertical";if("radial"===i){const o=e.x,i=e.y;t.x=i*Math.cos(o-Math.PI/2),t.y=i*Math.sin(o-Math.PI/2)}else"horizontal"===i?(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 Py(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 jy(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}var Ly=require("d3-shape");function $y(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var Ry={sankey:ry,force:cy,chord:yy,tree:My,cluster:My,treemap:My,circlepack:My,partition:My,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,i){const n=o.__hierarchyRoot;n&&function(t,e,o,i,n){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=$y(o);h.metaMap.clear(),i.length=0,n.length=0;const f=new Map;function p(t){const e=f.get(t)??0;return f.set(t,e+1),0===e?t:`${t}__${e}`}const y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=p(s(t));i.push({id:x,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(x,{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 x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(x+1)/b,A={id:o,depth:y,data:e,parentId:o},M=g?f/u(A)*S:f*S,_=(0,Ly.pie)().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(A);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=c+M*Math.sin(r),f=l+M*Math.cos(r)*P;i.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}),n.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,x,y,g,m,1,!1)}(n,i,o,t,e)},buildScene(t,e,o,i){const n=o.nodeStyle,r=o.edgeStyle,s=o.nodeSize,a="number"==typeof s?()=>s:"function"==typeof s?s:()=>6,c=[],l=[],u=[];if(!1!==o.orbitShowRings){const e=$y(o),i=new Map;for(const e of t)i.set(e.id,e);const n=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=i.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;n.has(o)||n.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:i}]of n)for(let n=0;r>n;n++){const a=n/r*Math.PI*2,c=(n+1)/r*Math.PI*2;l.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*i,x2:t+o*Math.sin(c),y2:e+o*Math.cos(c)*i,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(iy(e,"nodeSize")),i=n?n(iy(e,"nodeStyle")):{};c.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:i.fill||o.themeSemantic?.primary||"#6366f1",stroke:i.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity??(0===(e.depth??0)?1:.85),cursor:i.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==o.x)continue;const i=r?r(iy(t,"edgeStyle")):{};l.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:i.stroke||"rgba(128,128,128,0.35)",strokeWidth:i.strokeWidth??.5,opacity:i.opacity??1,cursor:i.cursor},datum:t})}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=a(iy(o,"nodeSize"));if(4>=t)continue;const i="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;u.push({x:o.x,y:o.y+t+12,text:i+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:c,sceneEdges:l,labels:u}},tick:(t,e,o,i,n)=>!1!==o.orbitAnimated&&(function(t,e){const o=$y(e),i=e.orbitSpeed??.25,n=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-o.startTime)/1e3,s=i*(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 i=a.get(t.parentId);if(!i)continue;const c=t.angle+r*s*n({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=i.x+t.ring*Math.sin(c),e.y=i.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)}};function Cy(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function Iy(t){if("glyph"===t.type&&t.glyph&&"number"==typeof t.size){const e=t.cx??t.x,o=t.cy??t.y;if("number"!=typeof e||"number"!=typeof o)return null;const i=ju(t.glyph,t.size);return{x:e+i.centerDx,y:o+i.centerDy,r:Math.max(1,i.radius)}}const e=t.cx??(null!=t.x&&null!=t.w?t.x+t.w/2:t.x),o=t.cy??(null!=t.y&&null!=t.h?t.y+t.h/2:t.y);return"number"!=typeof e||"number"!=typeof o?null:{x:e,y:o,r:"number"==typeof t.r?Math.max(1,t.r):"number"==typeof t.outerR?Math.max(1,t.outerR):"number"==typeof t.size?Math.max(1,Rl(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function Ty(t){if(!t)return;const e=[];for(const o of t){const t=Iy(o);t&&e.push({pointId:Cy(o),...t})}return e}var Oy=require("react/jsx-runtime");function zy(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var Fy=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function Ny(t){return t.map(t=>{const e=t.datum&&"object"==typeof t.datum?t.datum:{},o=e.data&&"object"==typeof e.data?e.data:e,i="cx"in t?t.cx:t.x+t.w/2,n="cy"in t?t.cy:t.y+t.h/2;return{...o,...null==o.id&&null!=t.id?{id:t.id}:{},x:i,y:n}})}function Ey(t,e){const o=Ot(t.theme),i=t.chartType||"force",n=t.size||[500,500],r=function(t){return Sf.has(t)?kf:wf}(i),s=pe({...r,...t.margin},t.title),a=he(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 i=P(t.nodes||[]);if(i.length>0)return yd(i,e);const n=Array.isArray(t.edges)?P(t.edges):[];if(0===n.length)return[];const r=zy(t.sourceAccessor,"source"),s=zy(t.targetAccessor,"target");return yd(Array.from(new Set(n.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];pf(s,{props:t,categories:c,theme:o,size:n,hasTitle:a});const l=yf({props:t,categories:c,theme:o,size:n,margin:s,hasTitle:a}),u=n[0]-s.left-s.right,d=n[1]-s.top-s.bottom,h=bf(t.backgroundGraphics,n,s,null),f=bf(t.foregroundGraphics,n,s,null),p=()=>{let i;const r=t=>Number(t),a=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:o,frameType:"network",idPrefix:t._idPrefix,onRender:t=>{i=t}}):null;return e&&(e.evidence=(e=>Ec({frameType:"network",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,nodeCount:0,edgeCount:0,margin:s}))(i)),lp.renderToStaticMarkup(mf(h||f||t.annotations?(0,Oy.jsxs)(Oy.Fragment,{children:[h,a,f]}):null,{width:n[0],height:n[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:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))},y=function(t){return Ry[t]}(i);if(!y&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${i}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const g={chartType:i,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,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let m,x;if(Fy.has(i)){const e=t.data||t.edges;if(!e||Array.isArray(e))return p();g.__hierarchyRoot=e,m=[],x=[]}else{const e=P(t.nodes||[]),o=Array.isArray(t.edges)?P(t.edges):[];if(0===e.length&&0===o.length)return p();if(x=function(t,e){const o=zy(e.sourceAccessor,"source"),i=zy(e.targetAccessor,"target"),n=zy(e.valueAccessor,"value");return t.map(t=>{const e=Number(n(t));return{source:o(t)+"",target:i(t)+"",value:Number.isFinite(e)?e:1,y0:0,y1:0,sankeyWidth:0,data:t}})}(o,g),0===e.length&&x.length>0){const t=new Set;for(const e of x){const o=cf(e.source),i=cf(e.target);o&&t.add(o),i&&t.add(i)}m=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 m=function(t,e){const o=zy(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}))}(e,g)}let b=[],v=[],w=[],k=null;if(g.customNetworkLayout){const t=g.colorScheme,e=Ns(t,o.colors.categorical,C),i=Es(e,t),n={nodes:m,edges:x,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:i,config:g.layoutConfig??{}},r=g.customNetworkLayout(n);b=r.sceneNodes??[],v=r.sceneEdges??[],w=r.labels??[],k=r.overlays??null}else if(y){y.computeLayout(m,x,g,[u,d]);const t=y.buildScene(m,x,g,[u,d]);b=t.sceneNodes,v=t.sceneEdges,w=t.labels}const S=zt(o);for(const t of w)t.fill||(t.fill=S.text);const A=id({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Nu(function(t,e){switch(t.type){case"line":return(0,Bu.jsx)("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,i=`net-bezier-${e}-hatch`,n=xn(o.style.fill)?bn(o.style.fill,i):void 0;return(0,Bu.jsxs)(Eu.Fragment,{children:[n&&(0,Bu.jsx)("defs",{children:n}),(0,Bu.jsx)("path",{d:o.pathD,fill:n?`url(#${i})`:Ru(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,i=`net-ribbon-${e}-hatch`,n=xn(o.style.fill)?bn(o.style.fill,i):void 0;return(0,Bu.jsxs)(Eu.Fragment,{children:[n&&(0,Bu.jsx)("defs",{children:n}),(0,Bu.jsx)("path",{d:o.pathD,fill:n?`url(#${i})`:Ru(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(0,Bu.jsx)("path",{d:o.pathD,fill:Ru(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),t,"network-edge-cursor-"+e)}(t,e)}),M=id({nodes:b,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Nu(function(t,e){switch(t.type){case"circle":{const o=t,i=xn(o.style.fill)?bn(o.style.fill,`net-circle-${e}-hatch`):void 0;return(0,Bu.jsxs)(Eu.Fragment,{children:[i&&(0,Bu.jsx)("defs",{children:i}),(0,Bu.jsx)("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:i?`url(#net-circle-${e}-hatch)`:Ru(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,i=xn(o.style.fill)?bn(o.style.fill,`net-rect-${e}-hatch`):void 0;return(0,Bu.jsxs)(Eu.Fragment,{children:[i&&(0,Bu.jsx)("defs",{children:i}),(0,Bu.jsx)("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:i?`url(#net-rect-${e}-hatch)`:Ru(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,i=(0,Du.arc)().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)($u)||"",n=xn(o.style.fill)?bn(o.style.fill,`net-arc-${e}-hatch`):void 0;return(0,Bu.jsxs)(Eu.Fragment,{children:[n&&(0,Bu.jsx)("defs",{children:n}),(0,Bu.jsx)("path",{d:i,transform:`translate(${o.cx},${o.cy})`,fill:n?`url(#net-arc-${e}-hatch)`:Ru(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,i=$l(o.symbolType,o.size,o.path);return(0,Bu.jsx)("path",{d:i,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?Ru(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return Iu(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),_=A.map(t=>t.element),j=M.map(t=>t.element),L=w.map((t,e)=>function(t,e){return(0,Bu.jsx)("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);let $;const R=t=>Number(t),I=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:R,y:R},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:Ny(b),pointNodes:Ty(b),idPrefix:t._idPrefix,onRender:t=>{$=t}}):null;return e&&(e.evidence=Ec({frameType:"network",width:n[0],height:n[1],marks:[...M.map(({node:t})=>({type:"node:"+(t.type??"node")})),...A.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:$,nodeCount:M.length,edgeCount:A.length,margin:s})),lp.renderToStaticMarkup(mf((0,Oy.jsxs)(Oy.Fragment,{children:[h,_,j,L,I,f,k]}),{width:n[0],height:n[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:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}var Dy=c(require("react-dom/server")),By=require("d3-geo"),Wy=require("d3-quadtree"),Yy=require("d3-geo"),qy={mercator:Yy.geoMercator,equalEarth:Yy.geoEqualEarth,albersUsa:Yy.geoAlbersUsa,orthographic:Yy.geoOrthographic,naturalEarth:Yy.geoNaturalEarth1,equirectangular:Yy.geoEquirectangular};function Xy(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Gy(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Vy(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function Hy(t,e){if(2>t.length)return[t];const o=.4*e,i=[];let n=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>n.length||i.push(n),n=[r]):n.push(r)}return 2>n.length||i.push(n),i}function Uy(t,e,o=24){const i=e[0]-t[0],n=e[1]-t[1],r=Math.sqrt(i*i+n*n);if(0===r)return[t,e];const s=-n/r,a=i/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 i=0;o>=i;i++){const n=i/o,r=1-n;d.push([r*r*t[0]+2*r*n*l+n*n*e[0],r*r*t[1]+2*r*n*u+n*n*e[1]])}return d}function Ky(t,e){if(2>t.length)return t;const o=e/2+1,i=[];for(let e=0;t.length>e;e++){const n=t[e];let r,s;0===e?(r=t[1][0]-n[0],s=t[1][1]-n[1]):e===t.length-1?(r=n[0]-t[e-1][0],s=n[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;i.push([n[0]+s/a*o,n[1]+-r/a*o])}return i}function Zy(t,e,o,i,n){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const c=s/a,l=-r/a,u=n/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}var Qy=require("d3-scale");var Jy=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],tg=["scene-style","data-paint","accessibility","evidence"],eg=(t,e)=>({retainedData:t,invalidations:e}),og=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ig=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ng=["scene-geometry","data-paint","accessibility","evidence"],rg=["scene-style","data-paint","accessibility","evidence"],sg=["overlay","accessibility","evidence"],ag=[],cg={xAccessor:eg("rebuild",og),yAccessor:eg("rebuild",og),lineDataAccessor:eg("rebuild",og),pointIdAccessor:eg("rebuild",ng),lineIdAccessor:eg("rebuild",ng),windowSize:eg("rebuild",og),projection:eg("preserve",ig),projectionExtent:eg("preserve",ig),fitPadding:eg("preserve",ig),lineType:eg("preserve",ig),flowStyle:eg("preserve",ig),graticule:eg("preserve",ig),projectionTransform:eg("preserve",ig),customLayout:eg("preserve",ig),layoutConfig:eg("preserve",ig),layoutMargin:eg("preserve",ig),areaStyle:eg("preserve",rg),pointStyle:eg("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:eg("preserve",rg),colorScheme:eg("preserve",rg),themeCategorical:eg("preserve",rg),themeDiverging:eg("preserve",rg),themeSemantic:eg("preserve",rg),themeSequential:eg("preserve",rg),decay:eg("preserve",rg),pulse:eg("preserve",rg),layoutSelection:eg("preserve",rg),annotations:eg("preserve",sg),autoPlaceAnnotations:eg("preserve",sg),clock:eg("preserve",ag),transition:eg("preserve",ag),introAnimation:eg("preserve",ag),onLayoutError:eg("preserve",ag)},lg=eg("preserve",ig),ug=class{constructor(){this.tracker=new ns}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}},Jy)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},tg):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const i of t){const t=cg[i]??lg;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),i=new Set(o.invalidations);return e.retainedDataChanged&&i.add("data"),this.tracker.record({kind:"config",keys:t},i)}},dg=require("d3-geo");function hg(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 fg=class t{constructor(t){this.updateResults=new ug,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:hg(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??il()}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()??[],i=e.slice(-t),n=o.slice(-i.length),r=this.currentTime();this.pointBuffer=new Wc(t),this.timestampBuffer=new Wc(t),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(n[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:hg(t.fitPadding)}:t}(t),o=this.config,i=this.getConfiguredWindowSize(),n=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==i;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,i=this.timestampBuffer?.toArray()??[],n=o.slice(-e),r=i.slice(-n.length),s=this.currentTime();this.pointBuffer=new Wc(e),this.timestampBuffer=new Wc(e),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();Hl(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)Hl(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],i=new Set(Array.isArray(t)?t:[t]),n=[];return this.lineData=this.lineData.filter(t=>!i.has(o(t)+"")||(n.push(t),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],i=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>i.has(o(t)+"");Ul(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=>!i.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 i=this._baseStyles.get(o)??o.style,n=e(o,t);o.style=n?{...i,...n}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,i=this.geoPath,n=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return(0,Yy.geoEqualEarth)();if("string"==typeof t){const e=qy[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),(0,Yy.geoEqualEarth)())}if("object"==typeof t&&"type"in t){const e=qy[t.type],o=e?e():(0,Yy.geoEqualEarth)();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=(0,By.geoPath)(this.projection),this.fitProjection(t),this.geoPath=(0,By.geoPath)(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=i,this.scales=n,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,o=t.height/2,i=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));i.length>0&&this.startTransition(i)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,o=this.config,i=[...this.areas],n=Xy(o.xAccessor,"lon"),r=Xy(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[n(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Gy(o.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[n(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==i.length){if(o.projectionExtent){const[[i,n],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,n],[i,s],[r,s],[r,n],[i,n]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const i=o.fitPadding??0,n=Math.min(t.width,t.height);e.scale(n/2-n*i),e.translate([t.width/2,t.height/2])}else{const n=o.fitPadding??0,r=t.width*n,s=t.height*n;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:i})}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 i=this.geoPath,n=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=(0,By.geoPath)(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=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const i=this.geoPath,n=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=(0,By.geoPath)(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=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const i=this.geoPath,n=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=(0,By.geoPath)(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=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}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&&!1!==t.interactive&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const i=Array(o);let n=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(i[n++]=t);this._quadtree=(0,Wy.quadtree)().x(t=>t.x).y(t=>t.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,i=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Ns(e.colorScheme,e.themeCategorical,nt),n={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:[...i]},resolveColor:Es(i,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(n)}catch(t){const o=null!==this.lastCustomLayoutResult,i=Dl("geo",t,o,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(i)}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 Fl({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:i,points:n,lines:r,layout:s}){const a=Xy(t.xAccessor,"lon"),c=Xy(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,i=(0,dg.geoGraticule)();e.step&&i.step(e.step);const n=o(i())||"";n&&l.push({type:"geoarea",pathData:n,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth??.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of i){const i=o(e);if(!i)continue;const n=o.centroid(e),r=o.bounds(e),s=o.area(e);l.push({type:"geoarea",pathData:i,centroid:n,bounds:r,screenArea:s,style:Vy(t.areaStyle,e,u),datum:e,interactive:!0})}const f=Gy(t.lineDataAccessor);for(const o of r){const i=f(o);if(!i||2>i.length)continue;let n=[];if("geo"===t.lineType){const t=Array(i.length);for(let e=0;i.length>e;e++)t[e]=[a(i[e]),c(i[e])];for(let o=0;t.length-1>o;o++){const i=t[o],r=t[o+1],s=(0,dg.geoDistance)(i,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=(0,dg.geoInterpolate)(i,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const i=e(c(t/a));null!=i&&n.push(i)}}}else for(let t=0;i.length>t;t++){const o=i[t],r=e([a(o),c(o)]);null!=r&&n.push(r)}if(2>n.length)continue;const r=Vy(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==i.length||2>n.length||"arc"!==t.flowStyle?2!==i.length||2>n.length||"offset"!==t.flowStyle||(n="geo"===t.lineType?Ky(n,u):Zy(n[0],n[n.length-1],0,0,u)):n=Uy(n[0],n[n.length-1]);const h=Hy(n,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>n.length&&h[0]||n,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],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of n){const i=a(o),n=c(o);if(null!=g&&(0,dg.geoDistance)([i,n],b)>g)continue;const r=e([i,n]);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:i,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,i){const n=t.filter(t=>"point"===t.type);if(2>n.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const c=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,l="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=n.find(t=>t.datum&&c(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=Et(n.map(t=>t.datum?Number(l(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),1);i>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"===a?function(t,e,o,i,n){const r=Math.max(3,Math.min(8,.35*n.height)),s=Math.max(1,n.width-2*r),a=n.height/2,c=(0,Qy.scaleLinear)().domain([0,i]).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)),s=r+(isFinite(t)&&t>=0&&i>0?c(t):0);n.x=s,n.y=a,l.push({node:n,x:s})}l.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(n.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:i,availableRadius:s,layout:"strip"}}(n,u,l,d,o):function(t,e,o,i,n,r){const s=e.x,a=e.y,c=r.width/2,l=r.height/2,u=Math.min(r.width,r.height)/2,d=(0,Qy.scaleLinear)().domain([0,i]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),f=Math.hypot(t-s,u-a),p=Number(o(r.datum)),y=isFinite(p)&&p>=0?i>0?d(p):0:f,g=c+Math.cos(h)*y,m=l+Math.sin(h)*y;r.x=t+(g-t)*n,r.y=u+(m-u)*n}return e.x=s+(c-s)*n,e.y=a+(l-a)*n,{cx:e.x,cy:e.y,maxCost:i,availableRadius:u,layout:"radial"}}(n,u,l,d,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of n)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const i=o.datum?.source,n=o.datum?.target;if(null!=i&&null!=n){const r=t.get(i+""),s=t.get(n+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],i=[r[0]-t[0],r[1]-t[1]],n=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const c=a[a.length-1];o.path=o.path.map((t,e)=>{const r=c>0?a[e]/c:e/(o.path.length-1);return[t[0]+i[0]*(1-r)+n[0]*r,t[1]+i[1]*(1-r)+n[1]*r]})}else o.path=[r,s]}}}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 i=0;o.length>i;i++){const n=nl(t,i,e);o[i]._decayOpacity=n,o[i].style={...o[i].style,opacity:n}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),i=this.timestampBuffer.toArray(),n=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&i.length>a;a++){const c=sl(e,i[a],t);s=al(o[a],c,n,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&cl(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 i=this.scene.filter(t=>"point"===t.type);let n=!1;for(const t of i)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)&&(n=!0))}for(const t of i)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=el(t,this.activeTransition),o=tl(e),i=this.scene.filter(t=>"point"===t.type);for(const t of i){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=ol(t.x,t._targetX,o),t.y=ol(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of i)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}};fg.QUADTREE_THRESHOLD=500;var pg=fg;function yg(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("glyph"===o.type){const t=o,i=ju(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+i.centerDx,y:t.y+i.centerDy,r:i.radius})}return e}iu(pg);var gg=require("react/jsx-runtime");function mg(t,e){const o=Ot(t.theme),i=t.size||[t.width||600,t.height||400],n=pe({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=he(t.title),s=Array.isArray(t.areas)?P(t.areas):t.areas,a=P(t.points),c=P(t.lines),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return yd(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];pf(n,{props:t,categories:l,theme:o,size:i,hasTitle:r});const u=yf({props:t,categories:l,theme:o,size:i,margin:n,hasTitle:r}),d=i[0]-(n.left??0)-(n.right??0),h=i[1]-(n.top??0)-(n.bottom??0),f={projection:t.projection||"equalEarth",projectionExtent:t.projectionExtent,xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineIdAccessor:t.lineIdAccessor,lineType:t.lineType,flowStyle:t.flowStyle,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,colorScheme:t.colorScheme,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,onLayoutError:t.onLayoutError,themeCategorical:o.colors.categorical,themeSemantic:It(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},p=new pg(f);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);p.setAreas(s)}t.points&&p.setPoints(a),t.lines&&p.setLines(c),p.computeScene({width:d,height:h});const y=bf(t.backgroundGraphics,i,n,p.scales),g=bf(t.foregroundGraphics,i,n,p.scales),m=id({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Nu(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const i=xn(o.style.fill)?bn(o.style.fill,`geoarea-${e}-hatch`):void 0;return(0,Yu.jsxs)(Wu.Fragment,{children:[i&&(0,Yu.jsx)("defs",{children:i}),(0,Yu.jsx)("path",{d:o.pathData,fill:i?`url(#geoarea-${e}-hatch)`:Ru(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,i=xn(o.style.fill)?bn(o.style.fill,`geopoint-${e}-hatch`):void 0;return(0,Yu.jsxs)(Wu.Fragment,{children:[i&&(0,Yu.jsx)("defs",{children:i}),(0,Yu.jsx)("circle",{cx:o.x,cy:o.y,r:o.r,fill:i?`url(#geopoint-${e}-hatch)`:Ru(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 i="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return(0,Yu.jsx)("path",{d:i,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 Iu(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===m.length){let r;const s=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:yg(p.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ec({frameType:"geo",width:i[0],height:i[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:n})),Dy.renderToStaticMarkup(mf(y||g||t.annotations||p.customLayoutOverlays?(0,gg.jsxs)(gg.Fragment,{children:[y,s,g,p.customLayoutOverlays]}):null,{width:i[0],height:i[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}const x=m.map(t=>t.element);let b;const v=t.annotations?Eh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:yg(p.scene),idPrefix:t._idPrefix,onRender:t=>{b=t}}):null;return e&&(e.evidence=Ec({frameType:"geo",width:i[0],height:i[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:b,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:n})),Dy.renderToStaticMarkup(mf((0,gg.jsxs)(gg.Fragment,{children:[y,x,v,g,p.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}var xg=c(require("react-dom/server"));function bg(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 vg={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function wg(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 kg(t,e,o){const i="function"==typeof e?e(t,o):e;return{...vg,...i??{}}}function Sg(t,e={},o="settled"){return t.map((t,i)=>function(t,e={},o={index:0,simulationState:"settled"}){const i=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),n={label:e.getBodyLabel?.(t)??wg(t)},r={style:kg(t,e.bodyStyle,o),datum:i,accessibleDatum:i,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,...r}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...r}}(t,e,{index:i,simulationState:o}))}var Ag=require("react/jsx-runtime"),Mg={top:0,right:0,bottom:0,left:0};function _g(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function Pg(t,e={}){const{element:o,scene:i,evidence:n}=function(t,e={}){const{width:o=640,height:i=360,title:n,description:r,background:s,backgroundGraphics:a,backgroundGraphicsBackdrop:c,className:l,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:y,...g}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),i=t.readBodies(),n=t.snapshot(),r=Sg(i,e,n.simulationState),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),i=o.filter(t=>t.sleeping).length,n=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===n&&i===o.length,a=[];n>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const c=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,o,i){const n=t-(e+o+i);return{charge:t,live:e,queued:o,sedimented:i,unaccounted:n,balanced:0===n}}(e.charge,o.length,n,r):void 0;return c&&!c.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:i,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:bg(e.projectionRows),queuedCount:n,sedimentedCount:r,...c?{ledger:c}:{},warnings:a}}(n,{bodies:i,projectionRows:e.projectionRows,stepsRun:o,charge:e.charge});return{snapshot:n,bodies:i,sceneNodes:r,evidence:s,stepsRun:o}}(t,g),x={...Mg,...h},b=[o,i],v=_g(a,b,x),w=_g(u,b,x),k=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(d),S=n?k+"-title":void 0,A=r?k+"-desc":void 0,M=[S,A].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,o-x.left-x.right),j=Math.max(1,i-x.top-x.bottom),L=k+"-plot-clip",$=_&&null!=v?(0,Ag.jsx)("g",{transform:_,children:v}):v;return{element:(0,Ag.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:o,height:i,viewBox:`0 0 ${o} ${i}`,role:"img","aria-labelledby":M,style:f,children:[n&&(0,Ag.jsx)("title",{id:S,children:n}),r&&(0,Ag.jsx)("desc",{id:A,children:r}),(0,Ag.jsx)("defs",{children:(0,Ag.jsx)("clipPath",{id:L,children:(0,Ag.jsx)("rect",{width:P,height:j})})}),c&&"transparent"!==c?(0,Ag.jsx)("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:i,fill:c}):null,!a&&s&&"transparent"!==s?(0,Ag.jsx)("rect",{x:0,y:0,width:o,height:i,fill:s}):null,$,(0,Ag.jsx)("g",{id:k+"-data-area",transform:_,clipPath:`url(#${L})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],i=o&&p?p(o,t.style??{},e,k):void 0;return null!=i?Nu(i,t,e):td(t,e,k)})}),w,y?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:xg.renderToStaticMarkup(o),scene:i,evidence:n}}function jg(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function Lg(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,jg(t.thickness)??jg(o)??jg(e.thickness)??4)}function $g(t){return t.sensorId??"stream-region-"+t.id}function Rg(t){const e=$g(t),o={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("boundary"===t.collider&&"aabb"===t.shape.type){const i=t.colliderThickness??8,n=t.shape.x-t.shape.width/2,r=t.shape.x+t.shape.width/2,s=t.shape.y-t.shape.height/2,a=t.shape.y+t.shape.height/2;return[{...o,id:e+"-top",shape:{type:"segment",x1:n,y1:s,x2:r,y2:s,thickness:i}},{...o,id:e+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...o,id:e+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:n,y2:a,thickness:i}},{...o,id:e+"-left",shape:{type:"segment",x1:n,y1:a,x2:n,y2:s,thickness:i}}]}return t.collider?[{...o,id:e+"-collider",shape:t.shape}]:[]}var Cg=require("react/jsx-runtime");function Ig({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?(0,Cg.jsx)("foreignObject",{x:0,y:0,width:e,height:o,children:t}):(0,Cg.jsx)("text",{x:e/2,y:de,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:t}):null}var Tg=require("d3-scale");function Og(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}var zg=require("react/jsx-runtime");var Fg={top:0,right:0,bottom:0,left:0};function Ng(t,e){const o=t.size??[t.width??600,t.height??400],i=Ot(t.theme),n=void 0===t.theme?{}:function(t){const e={"--semiotic-bg":t.colors.background,"--semiotic-text":t.colors.text,"--semiotic-text-secondary":t.colors.textSecondary,"--semiotic-grid":t.colors.grid,"--semiotic-border":t.colors.border,"--semiotic-cell-border":t.colors.cellBorder||t.colors.border,"--semiotic-primary":t.colors.primary,"--semiotic-font-family":t.typography.fontFamily,"--semiotic-secondary":t.colors.secondary||t.colors.primary,"--semiotic-surface":t.colors.surface||t.colors.background};t.colors.categorical.forEach((t,o)=>{e["--semiotic-category-"+(o+1)]=t}),t.colors.focus&&(e["--semiotic-focus"]=t.colors.focus),t.colors.selection&&(e["--semiotic-selection-color"]=t.colors.selection),null!=t.colors.selectionOpacity&&(e["--semiotic-selection-opacity"]=t.colors.selectionOpacity+""),t.colors.diverging&&(e["--semiotic-diverging"]=t.colors.diverging),t.colors.annotation&&(e["--semiotic-annotation-color"]=t.colors.annotation),t.colors.success&&(e["--semiotic-success"]=t.colors.success),t.colors.danger&&(e["--semiotic-danger"]=t.colors.danger),t.colors.warning&&(e["--semiotic-warning"]=t.colors.warning),t.colors.error&&(e["--semiotic-error"]=t.colors.error),t.colors.info&&(e["--semiotic-info"]=t.colors.info),t.tooltip?.background&&(e["--semiotic-tooltip-bg"]=t.tooltip.background),t.tooltip?.text&&(e["--semiotic-tooltip-text"]=t.tooltip.text),t.tooltip?.borderRadius&&(e["--semiotic-tooltip-radius"]=t.tooltip.borderRadius),t.tooltip?.fontSize&&(e["--semiotic-tooltip-font-size"]=t.tooltip.fontSize),t.tooltip?.shadow&&(e["--semiotic-tooltip-shadow"]=t.tooltip.shadow),t.borderRadius&&(e["--semiotic-border-radius"]=t.borderRadius);const o=t.typography.legendSize??t.typography.labelSize;null!=o&&(e["--semiotic-legend-font-size"]=o+"px"),null!=t.typography.legendFontFamily&&(e["--semiotic-legend-font-family"]=t.typography.legendFontFamily),null!=t.typography.legendFontWeight&&(e["--semiotic-legend-font-weight"]=t.typography.legendFontWeight+"");const i=t.typography.titleFontSize??t.typography.titleSize;return null!=i&&(e["--semiotic-title-font-size"]=i+"px"),null!=t.typography.titleFontFamily&&(e["--semiotic-title-font-family"]=t.typography.titleFontFamily),null!=t.typography.titleFontWeight&&(e["--semiotic-title-font-weight"]=t.typography.titleFontWeight+""),null!=t.typography.tickFontFamily&&(e["--semiotic-tick-font-family"]=t.typography.tickFontFamily),null!=t.typography.tickSize&&(e["--semiotic-tick-font-size"]=t.typography.tickSize+"px"),null!=t.typography.labelSize&&(e["--semiotic-axis-label-font-size"]=t.typography.labelSize+"px"),e}(i),r=t.bodyStyle,s=!1,a=t.legendPosition??"right",c=fe({...Fg,...t.margin},s,!!t.legend&&"top"===a);if(t.legend){const e={...c};De(c,{legend:t.legend,position:a,size:o,hasTitle:s,legendLayout:t.legendLayout}),ke(c,e,o,a)}let l;const u=function({annotations:t,chartId:e,chartType:o,config:i,onRegionObservation:n,regionEffects:r,seed:s,size:a}){const c=function(t=[],e={}){const o=e.idPrefix?e.idPrefix+"-":"",i=[];for(const n of t){if("barrier"!==n.physics&&"sensor"!==n.physics)continue;const t=n.axis??e.defaultAxis??"x",r=Lg(n,e),s=n.colliderId??`${o}${n.id}`;let a;if("x"===t){const t=jg(n.x),o=jg(n.y1)??jg(e.plotBounds?.y)??jg(n.y),i=jg(n.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??jg(n.y);if(null==t||null==o||null==i)continue;a={type:"segment",x1:t,y1:o,x2:t,y2:i,thickness:r}}else{const t=jg(n.y),o=jg(n.x1)??jg(e.plotBounds?.x)??jg(n.x),i=jg(n.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??jg(n.x);if(null==t||null==o||null==i)continue;a={type:"segment",x1:o,y1:t,x2:i,y2:t,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===n.physics,..."barrier"!==n.physics||null==n.restitution&&null==e.barrierRestitution?{}:{restitution:jg(n.restitution)??jg(e.barrierRestitution)},..."barrier"!==n.physics||null==n.friction&&null==e.barrierFriction?{}:{friction:jg(n.friction)??jg(e.barrierFriction)}})}return i}((t??[]).filter(t=>"barrier"===t.physics||"sensor"===t.physics),{idPrefix:e?e+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),l=void 0===s||void 0!==i?.kernel?.seed?i:{...i,kernel:{...i?.kernel,seed:s}},u=r.flatMap(t=>[{id:$g(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...Rg(t)]),d=Object.fromEntries(r.map(t=>[$g(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=l?.observation,f=r.length>0;return f||u.length>0||c.length>0||null!=e||h?{...l,colliders:[...l?.colliders??[],...u,...c],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{f&&n(t),h?.onObservation?.(t)}}}:l}({annotations:t.annotations,chartId:t.chartId,chartType:"StreamPhysicsFrame",config:t.config,onRegionObservation:()=>{},regionEffects:t.regionEffects??[],seed:t.seed,size:[Math.max(1,o[0]-c.left-c.right),Math.max(1,o[1]-c.top-c.bottom)]}),d=new ws(u);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&d.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const h=Pg(d,{...t,width:o[0],height:o[1],background:t.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof r?r(t,e):r}),style:{...n,fontFamily:i.typography.fontFamily,...t.style},charge:t.charge,idPrefix:t.idPrefix??t._idPrefix??"physics",margin:c,renderChrome:e=>{const n=function(t,e,o,i,n){const r=Math.max(1,o[0]-i.left-i.right),s=Math.max(1,o[1]-i.top-i.bottom),a=function(t){return t?.length?t.map(t=>null!=t.pointId||null==t.bodyId?t:{...t,pointId:t.bodyId+""}):t}(e.annotations),c=function(t){const{width:e,height:o,pointNodes:i=[],data:n}=t;return{scales:{x:(0,Tg.scaleLinear)().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:(0,Tg.scaleLinear)().domain([0,Math.max(1,o)]).range([0,Math.max(1,o)])},width:e,height:o,frameType:"network",pointNodes:i,data:n,xAccessor:"x",yAccessor:"y"}}({width:r,height:s,pointNodes:(l=t.bodies,l.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,Og(t))})))});var l;const u=c.scales?.x,d=c.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const f=Eh({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:n,frameType:"network",xAccessor:c.xAccessor,yAccessor:c.yAccessor,pointNodes:c.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),p=e.legend?ff(e.legend,{theme:n,position:e.legendPosition,size:[o[0],o[1]],margin:i,hasTitle:!!e.title,legendLayout:e.legendLayout})??Bh(e.legend,o,i,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:(0,zg.jsxs)("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:o[0],height:o[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[(0,zg.jsx)("g",{transform:`translate(${i.left},${i.top})`,children:f}),(0,zg.jsx)(Ig,{title:e.title,totalWidth:o[0],marginTop:Math.max(i.top,28)}),p]})}}(e,t,o,c,i);return l=n.annotationRender,n.node}});return e&&(e.evidence=Ec({frameType:"physics",width:o[0],height:o[1],marks:h.scene.sceneNodes,title:t.title,description:t.description,annotations:t.annotations,annotationRender:l,extraWarnings:[...0===h.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...h.scene.evidence.warnings]})),h.svg}var Eg=c(require("react-dom/server"));var Dg=require("react/jsx-runtime"),Bg={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Wg(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var Yg={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",i=Bg[o],n=Wg(t.width,i.width),r=Wg(t.height,i.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):i.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:i.align,c="center"===a?"middle":"end"===a?"end":"start",l="center"===a?n/2:"end"===a?n-s:s,u=Ot(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,i=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>i.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const i=o/1e3;if(60>i)return`${e}${n=i,Math.round(100*n)/100+""}s`;var n;const r=i/60;if(60>r){const t=Math.floor(r),o=Math.round(i-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),c=Math.round(s-24*a);return 0===c?`${e}${a}d`:`${e}${a}d ${c}h`}(t);const i=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>i.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${p}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var p;const y=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let i=null;for(const e of o){if(e.at>t)break;i=e}return i}(d,t.thresholds),g="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(y?.level??"neutral",y?.color,u),m="string"==typeof t.label?t.label:void 0,x="string"==typeof t.caption?t.caption:void 0,b="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const i=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,n=i&&"number"==typeof i.value&&Number.isFinite(i.value)?i.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===n?void 0:e-n);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${i&&"string"==typeof i.label?" "+i.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const i=t.target&&"object"==typeof t.target?t.target:void 0;if(!i||"number"!=typeof i.value||!Number.isFinite(i.value))return;const n="string"==typeof i.label?" "+i.label:"";return 0===i.value?`target ${o(i.value)}${n}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/i.value)} of ${o(i.value)}${n}`}(t,d,h),k=[v,w,y?.label].filter(Boolean).join(" · "),S="string"==typeof t.description&&t.description||[m,f,b,k].filter(Boolean).join(", "),A="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+i.labelSize,P=_+i.captionSize+4,j="presentation"===o?r/2+.32*i.valueSize:"thumbnail"===o?r/2+.34*i.valueSize:Math.min(r-s-(k?26:4),(i.showHeader&&(m||x)?x?P+10:_+14:s)+i.valueSize),L=l+("start"===c?Math.max(i.valueSize,f.length*i.valueSize*.55):0),$=Eg.renderToStaticMarkup((0,Dg.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:r,viewBox:`0 0 ${n} ${r}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber",children:[(0,Dg.jsx)("title",{children:m??f}),"string"==typeof t.description&&(0,Dg.jsx)("desc",{children:t.description}),(0,Dg.jsx)("rect",{x:i.border?.5:0,y:i.border?.5:0,width:i.border?n-1:n,height:i.border?r-1:r,rx:i.border?8:0,fill:A,stroke:i.border?M:"none"}),i.showHeader&&m&&(0,Dg.jsx)("text",{x:l,y:_,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.labelSize,fontWeight:600,fill:u.colors.text,children:m}),i.showHeader&&x&&(0,Dg.jsx)("text",{x:l,y:P,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.captionSize,fill:u.colors.textSecondary,children:x}),(0,Dg.jsx)("text",{x:l,y:j,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:g,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===c&&(0,Dg.jsx)("text",{x:L+6,y:j,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*i.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),i.showDetail&&k&&(0,Dg.jsx)("text",{x:l,y:Math.min(r-s,j+i.detailSize+10),textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Ec({frameType:"value",width:n,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:S})),$}};function qg(t,e,o){return Yg[t](e,o)}var Xg=require("react/jsx-runtime");function Gg(t,e){switch(t){case"xy":return _f(e);case"ordinal":return cp(e);case"network":return Ey(e);case"geo":return mg(e);case"physics":return Ng(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Vg(t){return _f(t)}function Hg(t){return cp(t)}function Ug(t){return Ey(t)}function Kg(t){return mg(t)}var Zg=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),Qg=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Jg(t,e){const o=Number(t);if(!Number.isFinite(o))return t;const i=10**e,n=Math.round((o+Number.EPSILON)*i)/i;return Object.is(n,-0)?"0":n+""}function tm(t,e){const o=function(t){if(Number.isFinite(t))return Math.max(0,Math.min(8,Math.floor(t)))}(e);return void 0===o?t:t.replace(/<[^>]+>/g,t=>t.replace(/\s([\w:-]+)="([^"]*)"/g,(t,e,i)=>!Zg.has(e)||/\b(?:var|calc|url)\(/i.test(i)?t:` ${e}="${function(t,e){const o=RegExp(Qg.source,Qg.flags);let i,n="",r=0,s=!1;for(;i=o.exec(t);){const o=t.slice(r,i.index);n+=s&&0===o.length?" ":o,n+=Jg(i[0],e),r=i.index+i[0].length,s=!0}return n+t.slice(r)}(i,o)}"`))}var em=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],om=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function im(t,e){const o={};for(const i of e)void 0!==t[i]&&(o[i]=t[i]);return o}function nm(t,e,o){return sm(t,e,o).svg}function rm(t,e,o){const i={},{svg:n,frameType:r}=sm(t,e,o,i),s=i.evidence??Ec({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,S(s,t,e),{svg:n,evidence:s}}function sm(t,e,o,i){if(Object.prototype.hasOwnProperty.call(Yg,t))return{svg:tm(qg(t,e,i),o?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(zc,t))throw Error(`Unknown chart component: "${t}". Run \`npx semiotic-ai --list\` for supported chart types.`);const n=zc[t];var r;const s=function(t,e,o){const i=p[t||"primary"],n=t&&"primary"!==t||!o?.width?i.width:o.width,r=t&&"primary"!==t||!o?.height?i.height:o.height,s=function(t,e,o=t.responsiveRules){if(!Array.isArray(o)||0===o.length)return{props:t,matches:[]};const i=o.map((t,e)=>({rule:t,index:e})).filter(t=>function(t,e){const{when:o}=t,i=e.width,n=e.height,r=function(t){if("number"==typeof t.height&&t.height>0)return t.width/t.height}(e),s=function(t){if("number"==typeof t.height&&t.height>0)return t.height>t.width?"portrait":"landscape"}(e);return!("number"==typeof o.minWidth&&o.minWidth>i||"number"==typeof o.maxWidth&&i>o.maxWidth||"number"==typeof o.minHeight&&("number"!=typeof n||o.minHeight>n)||"number"==typeof o.maxHeight&&("number"!=typeof n||n>o.maxHeight)||"number"==typeof o.minAspectRatio&&("number"!=typeof r||o.minAspectRatio>r)||"number"==typeof o.maxAspectRatio&&("number"!=typeof r||r>o.maxAspectRatio)||o.orientation&&s!==o.orientation)}(t.rule,e)).sort((t,e)=>("number"==typeof t.rule.priority?t.rule.priority:t.index)-("number"==typeof e.rule.priority?e.rule.priority:e.index));return{props:i.reduce((t,e)=>function(t,e){const o={...t,...e};for(const i of["margin","frameProps","mobileSemantics","style"])u(t[i])&&u(e[i])&&(o[i]={...t[i],...e[i]});return"string"==typeof t.className&&"string"==typeof e.className&&(o.className=`${t.className} ${e.className}`),o}(t,e.rule.transform),t),matches:i}}({...e,mode:t},{width:e.width??n,height:e.height??r}).props,a=s.mode||t||"primary",c=p[a],l="context"===a||"sparkline"===a,d="primary"===a&&o?.width?o.width:c.width;return{mode:a,width:s.width??d,height:s.height??("primary"===a&&o?.height?o.height:c.height),showAxes:s.showAxes??c.showAxes,showGrid:s.showGrid??c.showGrid,enableHover:s.enableHover??(!!s.linkedHover||c.enableHover),showLegend:s.showLegend??c.showLegend,showLabels:s.showLabels??c.showLabels,title:l?void 0:s.title,description:s.description,summary:s.summary,accessibleTable:s.accessibleTable,xLabel:l?void 0:s.xLabel,yLabel:l?void 0:s.yLabel,categoryLabel:l?void 0:s.categoryLabel,valueLabel:l?void 0:s.valueLabel,marginDefaults:y(c.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:l,mobileInteraction:f(s.mobileInteraction,{mode:a,width:s.width??d,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}(n.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(p,r)?e.mode:void 0),{...n.layout?.modeDefaults,...im(e,om)},n.layout?.primarySize),{data:a,theme:c,background:l,className:d,annotations:h,margin:g,colorScheme:m,colorBy:x,legendPosition:b,...v}=e,{width:w,height:k}=s,S=[w,k],M=v.frameProps||{},_=n.layout?.margin,P="function"==typeof _?_(e,s):_??s.marginDefaults,j=void 0!==g?g:M.margin,L=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}(j),$="number"==typeof j?{top:j,right:j,bottom:j,left:j}:{...P,...L},R=im(v,em),C=t=>M[t]??s[t],I={...M,...R,theme:c,title:s.title,description:s.description,showAxes:C("showAxes"),showLegend:C("showLegend"),showLabels:C("showLabels"),showGrid:C("showGrid"),xLabel:C("xLabel"),yLabel:C("yLabel"),categoryLabel:C("categoryLabel"),valueLabel:C("valueLabel"),background:l,className:d,annotations:h,size:S,margin:$,__compactMode:s.compactMode,__autoLegendMargin:!0,...void 0!==m&&{colorScheme:m},...void 0!==b&&{legendPosition:b},_idPrefix:v._idPrefix},T=n.buildProps(a,x,m,I,v);let O;switch(n.frameType){case"xy":O=_f(T,i);break;case"ordinal":O=cp(T,i);break;case"network":O=Ey(T,i);break;case"geo":O=mg(T,i);break;case"physics":O=Ng(T,i)}const z=n.renderOverlay?.(T,{theme:Ot(c)});if(null!=z){const t=A.renderToStaticMarkup((0,Xg.jsx)(Xg.Fragment,{children:z})),e=O.lastIndexOf("</svg>");O=0>e?`${O}${t}`:`${O.slice(0,e)}${t}${O.slice(e)}`}return{svg:tm(O,o?.precision),frameType:n.frameType}}async function am(t,e,o={}){const{format:i="png",scale:n=1,background:r}=o;let s,a;s=["xy","ordinal","network","geo","physics"].includes(t)?Gg(t,e):nm(t,e),r&&(s=s.replace(/<svg /,`<svg style="background:${r}" `));try{const t="sharp",e=await import(t);a=e.default??e}catch{throw Error('Image export requires the "sharp" package and a Node.js runtime. Install it:\n npm install sharp\nsharp is listed as an optional dependency of semiotic.')}const c=e.width||e.size?.[0]||600,l=e.height||e.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*n}).resize(Math.round(c*n),Math.round(l*n));return"jpeg"===i?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function cm(t,e={}){const{title:o,subtitle:i,theme:n,width:r=1200,height:s,layout:a={},background:c}=e,l=zt(Ot(n)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),i&&(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 x=s||g+m+d,b=p.map((t,e)=>{const{chart:o,x:i,y:r,w:s,h:a}=t,c={...o.props,width:s,height:a,theme:n,_idPrefix:"chart-"+e};let l;return l=o.component?nm(o.component,c):o.frameType?Gg(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,(0,Xg.jsx)("g",{transform:`translate(${i},${r})`,children:(0,Xg.jsx)("foreignObject",{width:s,height:a,children:(0,Xg.jsx)("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+e)});return A.renderToStaticMarkup((0,Xg.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&(0,Xg.jsx)("title",{children:o}),c&&(0,Xg.jsx)("rect",{x:0,y:0,width:r,height:x,fill:c}),o&&(0,Xg.jsx)("text",{x:r/2,y:24,textAnchor:"middle",fontSize:l.titleFontSize+4,fontWeight:l.titleFontWeight,fill:l.text,fontFamily:l.titleFontFamily,children:o}),i&&(0,Xg.jsx)("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),b]}))}var lm=c(require("react-dom/server")),um=require("react/jsx-runtime");function dm(t,e,o,i={}){const{stepSize:n,windowSize:r,frameCount:s,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:d="ease-out",decay:h}=i,f=o.width||600,p=o.height||400,y=Ot(o.theme),g={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!e||0===e.length)return[];const m=n||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=pe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(b)for(let i=0;x.length>i;i++){const n=x[i],s=e.slice(r?Math.max(0,n-r):0,n),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,connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||y.colors.categorical,...h&&{decay:h}},c=new Qf(a);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:w,height:k}),c.scene.length>0&&S.push(mm(c.scene,f,p,y,g))}else for(let i=0;x.length>i;i++){const n=x[i],s=e.slice(r?Math.max(0,n-r):0,n),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor: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}}},b=new vu(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(S.push(gm(b.scene,f,p,y,g,v)),l>0&&i>0&&b.activeTransition){const t=l*(1e3/u);for(let e=1;l>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/l*t),S.push(gm(b.scene,f,p,y,g,v))}}return S}function hm(t,e,o={}){return e.map(e=>{try{return nm(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 fm(t,e,o){const i=e.size??[e.width??600,e.height??400],n=Ot(e.theme),r=zt(n),s=e.background||n.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=Sg(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=(0,um.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&(0,um.jsx)("title",{id:c,children:e.title}),e.description&&(0,um.jsx)("desc",{id:l,children:e.description}),s&&"transparent"!==s?(0,um.jsx)("rect",{x:0,y:0,width:i[0],height:i[1],fill:s}):null,(0,um.jsx)("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>td(t,e,`${a}-${o}`))})]});return lm.renderToStaticMarkup(h)}function pm(t,e={}){const{fps:o=12,frameCount:i,durationSeconds:n=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:c}=e,l=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=i??Math.max(1,Math.ceil(n*Math.max(1,o))),h=c?{...t,background:c}:t,f=new ws(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(fm(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(l);p.push(fm(f,h,p.length))}return p}function ym(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function gm(t,e,o,i,n,r){const s=zt(i),a=pe({top:20,right:20,bottom:30,left:40,...n.margin},n.title),c=e-a.left-a.right,l=o-a.top-a.bottom,u=ym(n,i),d=n.renderMode,h=t.map((t,e)=>od({node:t,index:e,renderMode:d,fallback:()=>td(t,e)}).element).filter(Boolean),f=function(t,e,o,i,n,r){if(!t||0===t.length)return null;const s=zt(i),a=[];for(let i=0;t.length>i;i++){const c=t[i];if("y-threshold"===c.type&&null!=c.value){let t=null;if(r)t=r(c.value);else if(n){const[e,i]=n,r=i-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((0,um.jsxs)("g",{children:[(0,um.jsx)("line",{x1:0,y1:t,x2:e,y2:t,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&(0,um.jsx)("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-"+i))}}return a.length>0?(0,um.jsx)(um.Fragment,{children:a}):null}(n.annotations,c,l,i,n.yExtent,r?.y),p="string"==typeof n.title?n.title:void 0,y="string"==typeof n.description?n.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,x=[g,m].filter(Boolean).join(" ")||void 0;return lm.renderToStaticMarkup((0,um.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&(0,um.jsx)("title",{id:g,children:p}),y&&(0,um.jsx)("desc",{id:m,children:y}),u&&(0,um.jsx)("rect",{x:0,y:0,width:e,height:o,fill:u}),(0,um.jsxs)("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&(0,um.jsx)("text",{x:e/2,y:de,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:p})]}))}function mm(t,e,o,i,n){const r=zt(i),s=pe({top:20,right:20,bottom:30,left:40,...n.margin},n.title),a="radial"===n.projection,c=a?s.left+(e-s.left-s.right)/2:s.left,l=a?s.top+(o-s.top-s.bottom)/2:s.top,u=ym(n,i),d=np({nodes:t,renderMode:n.renderMode,idPrefix:n.idPrefix}).map(t=>t.element),h="string"==typeof n.title?n.title:void 0,f="string"==typeof n.description?n.description:void 0,p=h?"semiotic-title":void 0,y=f?"semiotic-desc":void 0,g=[p,y].filter(Boolean).join(" ")||void 0;return lm.renderToStaticMarkup((0,um.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":g,style:{fontFamily:r.fontFamily},children:[h&&(0,um.jsx)("title",{id:p,children:h}),f&&(0,um.jsx)("desc",{id:y,children:f}),u&&(0,um.jsx)("rect",{x:0,y:0,width:e,height:o,fill:u}),(0,um.jsx)("g",{transform:`translate(${c},${l})`,children:d}),h&&(0,um.jsx)("text",{x:e/2,y:de,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}async function xm(t,e,o,i={}){const{fps:n=12,loop:r=!0,scale:s=1,background:a}=i,c=o.width||600,l=o.height||400,u=dm(t,e,a?{...o,background:a}:o,i);if(0===u.length)throw Error("No frames generated — check that data is not empty");return vm(u,c,l,{fps:n,loop:r,scale:s})}async function bm(t,e={}){const{fps:o=12,loop:i=!0,scale:n=1}=e,r=t.size??[t.width??600,t.height??400],s=pm(t,e);if(0===s.length)throw Error("No physics frames generated");return vm(s,r[0],r[1],{fps:o,loop:i,scale:n})}async function vm(t,e,o,i={}){const{fps:n=12,loop:r=!0,scale:s=1}=i,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/n),p=u();for(let e=0;t.length>e;e++){const o=t[e],i=await l(Buffer.from(o),{density:72*s}).resize(a,c).ensureAlpha().raw().toBuffer(),n=new Uint8Array(i),u=d(n,256),y=h(n,u);p.writeFrame(y,a,c,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}
|