semiotic 3.8.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +14 -9
- package/README.md +56 -55
- package/ai/behaviorContracts.cjs +9 -0
- package/ai/dist/mcp-server.js +240 -30
- package/ai/schema.json +616 -42
- package/ai/surface-manifest.json +3 -2
- package/ai/system-prompt.md +7 -3
- package/dist/__tests__/scenarios/mcpProtocolTypes.d.ts +20 -0
- package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +2 -0
- package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +1 -0
- package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +2 -0
- package/dist/chunk-chunk-255KDHW5.module.min.js +1 -0
- package/dist/chunk-chunk-27HVVXS6.module.min.js +1 -0
- package/dist/chunk-chunk-2CXCXRB4.module.min.js +1 -0
- package/dist/chunk-chunk-2JGJ5GUG.module.min.js +2 -0
- package/dist/chunk-chunk-2UN3ANRN.module.min.js +2 -0
- package/dist/chunk-chunk-2VUEY5TH.module.min.js +1 -0
- package/dist/chunk-chunk-2WVCH4PL.module.min.js +1 -0
- package/dist/chunk-chunk-5UKL5W76.module.min.js +2 -0
- package/dist/chunk-chunk-5WEFWNUW.module.min.js +2 -0
- package/dist/chunk-chunk-6F6GEAQU.module.min.js +1 -0
- package/dist/chunk-chunk-7LHMKRKE.module.min.js +2 -0
- package/dist/chunk-chunk-BHYTYMY2.module.min.js +2 -0
- package/dist/chunk-chunk-C6EJ4IOD.module.min.js +2 -0
- package/dist/chunk-chunk-CA3YDW6F.module.min.js +1 -0
- package/dist/chunk-chunk-CP3EN6KZ.module.min.js +1 -0
- package/dist/chunk-chunk-CYIML3AV.module.min.js +2 -0
- package/dist/chunk-chunk-DNY43POY.module.min.js +1 -0
- package/dist/chunk-chunk-DSNGDNJY.module.min.js +1 -0
- package/dist/chunk-chunk-E7MIQX7D.module.min.js +2 -0
- package/dist/chunk-chunk-EMO5NUGE.module.min.js +1 -0
- package/dist/chunk-chunk-ES4DCG3L.module.min.js +1 -0
- package/dist/chunk-chunk-FAKO3RGQ.module.min.js +2 -0
- package/dist/chunk-chunk-FYY2ACNJ.module.min.js +2 -0
- package/dist/chunk-chunk-G7WFWHAD.module.min.js +2 -0
- package/dist/chunk-chunk-GMQ5AYTD.module.min.js +1 -0
- package/dist/chunk-chunk-H4PPRW6N.module.min.js +1 -0
- package/dist/chunk-chunk-IFYPMWKY.module.min.js +1 -0
- package/dist/chunk-chunk-J3ELI22J.module.min.js +1 -0
- package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
- package/dist/chunk-chunk-J3XWETBJ.module.min.js +2 -0
- package/dist/chunk-chunk-JCG72SGW.module.min.js +2 -0
- package/dist/{semiotic-ai-chunk-OG7BQUUW.module.min.js → chunk-chunk-JJ2OOIET.module.min.js} +0 -1
- package/dist/chunk-chunk-KTWEBFMX.module.min.js +2 -0
- package/dist/chunk-chunk-L6D3I3V7.module.min.js +2 -0
- package/dist/chunk-chunk-M337NY6L.module.min.js +1 -0
- package/dist/chunk-chunk-NO4MCQVD.module.min.js +1 -0
- package/dist/chunk-chunk-ODUZEEBH.module.min.js +2 -0
- package/dist/chunk-chunk-P6UBCMSQ.module.min.js +2 -0
- package/dist/chunk-chunk-Q2YADC2V.module.min.js +2 -0
- package/dist/chunk-chunk-QRIBHZYW.module.min.js +1 -0
- package/dist/chunk-chunk-QSQVBIJA.module.min.js +1 -0
- package/dist/chunk-chunk-RCF52Z42.module.min.js +2 -0
- package/dist/chunk-chunk-RH5TSQPH.module.min.js +1 -0
- package/dist/chunk-chunk-ROP4HI7H.module.min.js +2 -0
- package/dist/chunk-chunk-RZH7VZYS.module.min.js +2 -0
- package/dist/chunk-chunk-SIRIJ3DY.module.min.js +1 -0
- package/dist/chunk-chunk-STZFFTAN.module.min.js +2 -0
- package/dist/chunk-chunk-SV4XAZ3Q.module.min.js +1 -0
- package/dist/chunk-chunk-T27ZEV6A.module.min.js +1 -0
- package/dist/chunk-chunk-U3AGQ5EF.module.min.js +2 -0
- package/dist/chunk-chunk-U66USBWU.module.min.js +1 -0
- package/dist/chunk-chunk-VVCA3DB7.module.min.js +1 -0
- package/dist/chunk-chunk-W3DB2MN4.module.min.js +2 -0
- package/dist/chunk-chunk-WCX6U47H.module.min.js +2 -0
- package/dist/chunk-chunk-WDIN4LRC.module.min.js +1 -0
- package/dist/chunk-chunk-XEVJDUTH.module.min.js +1 -0
- package/dist/chunk-chunk-XOYX77KF.module.min.js +2 -0
- package/dist/chunk-chunk-YCQYG6J5.module.min.js +2 -0
- package/dist/chunk-chunk-YHNZCPOZ.module.min.js +2 -0
- package/dist/chunk-chunk-YWZB3KPI.module.min.js +2 -0
- package/dist/chunk-chunk-Z5KXAVQD.module.min.js +2 -0
- package/dist/chunk-chunk-ZCNBUZPL.module.min.js +2 -0
- package/dist/chunk-chunk-ZLKRTF5N.module.min.js +2 -0
- package/dist/chunk-chunk-ZTNVDWAK.module.min.js +2 -0
- package/dist/chunk-statisticalOverlays-6MVAK5RW.module.min.js +2 -0
- package/dist/components/AccessibleNavTree.d.ts +7 -1
- package/dist/components/ai/chartClinicMetadata.generated.d.ts +15 -0
- package/dist/components/ai/useNavigationSync.d.ts +17 -2
- package/dist/components/chartContainerMobile.d.ts +9 -0
- package/dist/components/charts/geo/ChoroplethMap.d.ts +19 -2
- package/dist/components/charts/geo/DistanceCartogram.d.ts +14 -2
- package/dist/components/charts/geo/FlowMap.d.ts +10 -6
- package/dist/components/charts/geo/ProportionalSymbolMap.d.ts +14 -2
- package/dist/components/charts/index.d.ts +6 -0
- package/dist/components/charts/network/ChordDiagram.d.ts +9 -1
- package/dist/components/charts/network/ForceDirectedGraph.d.ts +11 -0
- package/dist/components/charts/network/SankeyDiagram.d.ts +9 -1
- package/dist/components/charts/ordinal/BarChart.d.ts +21 -0
- package/dist/components/charts/ordinal/GroupedBarChart.d.ts +11 -0
- package/dist/components/charts/ordinal/StackedBarChart.d.ts +11 -0
- package/dist/components/charts/physics/CollisionSwarmChart.d.ts +7 -0
- package/dist/components/charts/physics/EventDropChart.d.ts +7 -0
- package/dist/components/charts/physics/GaltonBoardChart.d.ts +8 -0
- package/dist/components/charts/physics/PhysicalFlowChart.d.ts +7 -0
- package/dist/components/charts/physics/PhysicsCustomChart.d.ts +4 -25
- package/dist/components/charts/physics/PhysicsPileChart.d.ts +7 -0
- package/dist/components/charts/physics/physicsChartShared.d.ts +17 -1
- package/dist/components/charts/physics/physicsCustomLayout.d.ts +32 -0
- package/dist/components/charts/shared/AnnotationLabel.d.ts +88 -0
- package/dist/components/charts/shared/annotationActivation.d.ts +35 -0
- package/dist/components/charts/shared/annotationLabelLayout.d.ts +5 -0
- package/dist/components/charts/shared/annotationRules.d.ts +2 -1
- package/dist/components/charts/shared/auditAccessibilityText.d.ts +13 -0
- package/dist/components/charts/shared/chartSelectionUtils.d.ts +4 -0
- package/dist/components/charts/shared/chartSpecCore.d.ts +3 -3
- package/dist/components/charts/shared/datumTypes.d.ts +2 -0
- package/dist/components/charts/shared/diagnoseAnnotationChecks.d.ts +2 -0
- package/dist/components/charts/shared/formatUtils.d.ts +3 -3
- package/dist/components/charts/shared/hatchFill.d.ts +87 -0
- package/dist/components/charts/shared/hooks.d.ts +7 -6
- package/dist/components/charts/shared/knownChartComponents.d.ts +9 -0
- package/dist/components/charts/shared/leastSquaresRegression.d.ts +16 -0
- package/dist/components/charts/shared/mergeShapeStyle.d.ts +3 -2
- package/dist/components/charts/shared/semanticInteractions.d.ts +42 -0
- package/dist/components/charts/shared/sparseArray.d.ts +1 -1
- package/dist/components/charts/shared/streamPropsHelpers.d.ts +6 -4
- package/dist/components/charts/shared/styleRules.d.ts +205 -0
- package/dist/components/charts/shared/tooltipUtils.d.ts +22 -9
- package/dist/components/charts/shared/types.d.ts +9 -6
- package/dist/components/charts/shared/useAreaSeriesSetup.d.ts +16 -2
- package/dist/components/charts/shared/useChartSetup.d.ts +2 -2
- package/dist/components/charts/shared/useCustomChartSetup.d.ts +3 -0
- package/dist/components/charts/shared/useFrameImperativeHandle.d.ts +1 -2
- package/dist/components/charts/shared/useLikertAggregation.d.ts +4 -4
- package/dist/components/charts/shared/useOrdinalBrush.d.ts +2 -1
- package/dist/components/charts/shared/useOrdinalPieceStyle.d.ts +24 -1
- package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
- package/dist/components/charts/shared/useXYLineStyle.d.ts +10 -0
- package/dist/components/charts/shared/useXYPointStyle.d.ts +19 -1
- package/dist/components/charts/shared/validateChartData.d.ts +7 -5
- package/dist/components/charts/shared/validationMap.d.ts +11 -2
- package/dist/components/charts/shared/validationMap.generated.d.ts +6 -0
- package/dist/components/charts/shared/withChartWrapper.d.ts +4 -3
- package/dist/components/charts/value/targetPresentation.d.ts +22 -0
- package/dist/components/charts/value/types.d.ts +5 -6
- package/dist/components/charts/xy/AreaChart.d.ts +8 -0
- package/dist/components/charts/xy/BubbleChart.d.ts +9 -0
- package/dist/components/charts/xy/ConnectedScatterplot.d.ts +7 -0
- package/dist/components/charts/xy/DifferenceChart.d.ts +1 -52
- package/dist/components/charts/xy/Heatmap.d.ts +2 -2
- package/dist/components/charts/xy/LineChart.d.ts +11 -0
- package/dist/components/charts/xy/QuadrantChart.d.ts +7 -0
- package/dist/components/charts/xy/Scatterplot.d.ts +10 -0
- package/dist/components/charts/xy/StackedAreaChart.d.ts +7 -0
- package/dist/components/charts/xy/differenceSegments.d.ts +49 -0
- package/dist/components/charts/xy/scatterplotMatrixInteractionTypes.d.ts +12 -0
- package/dist/components/controls/SentenceFilter.d.ts +97 -0
- package/dist/components/data/fromVegaLite.d.ts +19 -9
- package/dist/components/rough/createRoughRenderMode.d.ts +46 -0
- package/dist/components/semiotic-ai.d.ts +3 -1
- package/dist/components/semiotic-controls.d.ts +2 -0
- package/dist/components/semiotic-geo.d.ts +4 -0
- package/dist/components/semiotic-network.d.ts +4 -0
- package/dist/components/semiotic-ordinal.d.ts +6 -0
- package/dist/components/semiotic-physics.d.ts +4 -0
- package/dist/components/semiotic-rough.d.ts +4 -0
- package/dist/components/semiotic-utils-core.d.ts +4 -0
- package/dist/components/semiotic-xy.d.ts +4 -0
- package/dist/components/semiotic.d.ts +9 -1
- package/dist/components/server/optionalImageTypes.d.ts +37 -0
- package/dist/components/server/serverChartConfigShared.d.ts +9 -5
- package/dist/components/server/serverChartConfigs.d.ts +4 -4
- package/dist/components/server/staticAnnotations.d.ts +6 -3
- package/dist/components/server/staticLegend.d.ts +1 -1
- package/dist/components/server/staticNetwork.d.ts +4 -4
- package/dist/components/server/staticSVGChrome.d.ts +5 -4
- package/dist/components/store/ObservationStore.d.ts +21 -1
- package/dist/components/stream/AccessibleDataTable.d.ts +4 -10
- package/dist/components/stream/AriaLiveTooltip.d.ts +9 -0
- package/dist/components/stream/CanvasHitTester.d.ts +4 -4
- package/dist/components/stream/DataSourceAdapter.d.ts +1 -1
- package/dist/components/stream/FrameRuntime.d.ts +57 -0
- package/dist/components/stream/GeoParticlePool.d.ts +1 -1
- package/dist/components/stream/GeoPipelineStore.d.ts +43 -12
- package/dist/components/stream/GeoSVGOverlay.d.ts +64 -0
- package/dist/components/stream/NetworkCanvasHitTester.d.ts +2 -1
- package/dist/components/stream/NetworkPipelineStore.d.ts +24 -21
- package/dist/components/stream/NetworkSSRFrame.d.ts +17 -0
- package/dist/components/stream/NetworkSVGOverlay.d.ts +6 -0
- package/dist/components/stream/OrdinalBrushOverlay.d.ts +1 -2
- package/dist/components/stream/OrdinalBrushOverlayLazy.d.ts +9 -0
- package/dist/components/stream/OrdinalCanvasHitTester.d.ts +2 -2
- package/dist/components/stream/OrdinalPipelineStore.d.ts +13 -13
- package/dist/components/stream/OrdinalSVGOverlay.d.ts +9 -1
- package/dist/components/stream/OrdinalStyleResolver.d.ts +12 -0
- package/dist/components/stream/ParticlePool.d.ts +1 -1
- package/dist/components/stream/PipelineStore.d.ts +12 -16
- package/dist/components/stream/SVGOverlay.d.ts +6 -0
- package/dist/components/stream/SceneGraph.d.ts +3 -3
- package/dist/components/stream/XYBrushOverlayLazy.d.ts +17 -0
- package/dist/components/stream/accessorUtils.d.ts +2 -2
- package/dist/components/stream/annotationAccessorResolver.d.ts +2 -2
- package/dist/components/stream/frameGraphics.d.ts +4 -0
- package/dist/components/stream/frameKeyboardNavigation.d.ts +45 -0
- package/dist/components/stream/geoPipelineHelpers.d.ts +3 -3
- package/dist/components/stream/geoPipelineUpdateResults.d.ts +34 -0
- package/dist/components/stream/geoSceneBuilder.d.ts +16 -0
- package/dist/components/stream/geoTypes.d.ts +48 -15
- package/dist/components/stream/hitTestUtils.d.ts +2 -2
- package/dist/components/stream/hoverUtils.d.ts +4 -2
- package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +1 -0
- package/dist/components/stream/layouts/hierarchyUtils.d.ts +2 -2
- package/dist/components/stream/networkCustomLayoutRunner.d.ts +23 -0
- package/dist/components/stream/networkCustomRestyle.d.ts +15 -0
- package/dist/components/stream/networkFrameAnimation.d.ts +7 -0
- package/dist/components/stream/networkFrameHandleTypes.d.ts +39 -0
- package/dist/components/stream/networkFrameObservations.d.ts +15 -0
- package/dist/components/stream/networkFramePaint.d.ts +11 -2
- package/dist/components/stream/networkInteractionTypes.d.ts +26 -0
- package/dist/components/stream/networkPipelineConfig.d.ts +2 -2
- package/dist/components/stream/networkPipelineUpdateResults.d.ts +38 -0
- package/dist/components/stream/networkTypes.d.ts +37 -56
- package/dist/components/stream/ordinalCanvasRenderers.d.ts +2 -2
- package/dist/components/stream/ordinalPipelineUpdateResults.d.ts +20 -1
- package/dist/components/stream/ordinalSceneBuilders/types.d.ts +2 -2
- package/dist/components/stream/ordinalTypes.d.ts +30 -3
- package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +2 -0
- package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +6 -0
- package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +21 -6
- package/dist/components/stream/physics/physicsFrameObservations.d.ts +19 -0
- package/dist/components/stream/physics/physicsFrameSetup.d.ts +4 -0
- package/dist/components/stream/physics/physicsPipelineUpdateResults.d.ts +19 -1
- package/dist/components/stream/physics/usePhysicsFrameLifecyclePolicy.d.ts +3 -1
- package/dist/components/stream/pipelineConfig.d.ts +4 -2
- package/dist/components/stream/pipelineDecay.d.ts +2 -2
- package/dist/components/stream/pipelinePulse.d.ts +2 -2
- package/dist/components/stream/pipelineStoreUpdateResults.d.ts +23 -2
- package/dist/components/stream/pipelineTransitions.d.ts +1 -1
- package/dist/components/stream/pipelineUpdateContract.d.ts +7 -0
- package/dist/components/stream/pipelineUpdateStore.d.ts +21 -0
- package/dist/components/stream/renderBackend.d.ts +27 -0
- package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +15 -1
- package/dist/components/stream/renderers/geoCanvasRenderer.d.ts +3 -2
- package/dist/components/stream/renderers/networkParticleRenderer.d.ts +1 -1
- package/dist/components/stream/sceneRenderBackendTypes.d.ts +28 -0
- package/dist/components/stream/sceneRevisionDiagnostics.d.ts +31 -4
- package/dist/components/stream/streamSemanticTypes.d.ts +16 -0
- package/dist/components/stream/streamThemeTypes.d.ts +14 -0
- package/dist/components/stream/svgOverlayUtils.d.ts +10 -0
- package/dist/components/stream/test-utils/frameScheduler.d.ts +12 -0
- package/dist/components/stream/test-utils/revisionConsumption.d.ts +13 -0
- package/dist/components/stream/titleLayout.d.ts +31 -0
- package/dist/components/stream/types.d.ts +30 -65
- package/dist/components/stream/useCanvasFrameHost.d.ts +71 -0
- package/dist/components/stream/useFrame.d.ts +23 -0
- package/dist/components/stream/useLegendCategoryEmission.d.ts +3 -3
- package/dist/components/stream/useSemanticFrameInteractions.d.ts +22 -0
- package/dist/components/stream/useUpdateResultSnapshot.d.ts +7 -0
- package/dist/components/stream/xyFrameAxisTypes.d.ts +50 -0
- package/dist/components/stream/xySceneBuilders/types.d.ts +6 -5
- 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.min.js +1 -1
- package/dist/physics-matter.module.min.js +1 -1
- package/dist/physics-rapier.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/realtime.min.js +1 -1
- package/dist/realtime.module.min.js +1 -1
- package/dist/rough.min.js +1 -0
- package/dist/rough.module.min.js +1 -0
- 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 +3 -1
- package/dist/semiotic-ai.min.js +1 -1
- package/dist/semiotic-ai.module.min.js +1 -1
- package/dist/semiotic-controls.d.ts +2 -0
- package/dist/semiotic-data.min.js +1 -1
- package/dist/semiotic-data.module.min.js +1 -1
- package/dist/semiotic-experimental.min.js +1 -1
- package/dist/semiotic-experimental.module.min.js +1 -1
- package/dist/semiotic-geo.d.ts +4 -0
- package/dist/semiotic-network.d.ts +4 -0
- package/dist/semiotic-ordinal.d.ts +6 -0
- package/dist/semiotic-physics.d.ts +4 -0
- package/dist/semiotic-realtime-core.min.js +1 -1
- package/dist/semiotic-realtime-core.module.min.js +1 -1
- package/dist/semiotic-realtime-react.min.js +1 -1
- package/dist/semiotic-realtime-react.module.min.js +1 -1
- package/dist/semiotic-recipes-core.min.js +1 -1
- package/dist/semiotic-recipes-core.module.min.js +1 -1
- 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 +1 -1
- package/dist/semiotic-recipes.module.min.js +1 -1
- package/dist/semiotic-rough.d.ts +4 -0
- package/dist/semiotic-server-edge.min.js +1 -1
- package/dist/semiotic-server-edge.module.min.js +1 -1
- package/dist/semiotic-server-node.min.js +1 -1
- package/dist/semiotic-server-node.module.min.js +1 -1
- package/dist/semiotic-themes-core.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 +4 -0
- package/dist/semiotic-utils-core.min.js +1 -1
- package/dist/semiotic-utils-core.module.min.js +1 -1
- 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 +1 -1
- package/dist/semiotic-utils.module.min.js +1 -1
- package/dist/semiotic-value.min.js +1 -1
- package/dist/semiotic-value.module.min.js +1 -1
- package/dist/semiotic-xy.d.ts +4 -0
- package/dist/semiotic.d.ts +9 -1
- 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/test-utils/capturedFrameProps.d.ts +67 -0
- package/dist/test-utils/frameMock.d.ts +12 -9
- package/dist/xy.min.js +1 -1
- package/dist/xy.module.min.js +1 -1
- package/package.json +29 -10
- package/dist/semiotic-ai-statisticalOverlays-CY4WKR4A.module.min.js +0 -2
- package/dist/semiotic-chunk-3FSVZ46U.module.min.js +0 -2
- package/dist/semiotic-statisticalOverlays-UOMSFKVJ.module.min.js +0 -2
- package/dist/xy-chunk-IWD6IB6V.module.min.js +0 -2
- package/dist/xy-statisticalOverlays-7RWG6LJT.module.min.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{forwardRef as e,useCallback as t,useMemo as n,useRef as i}from"react";import*as o from"react";import{forwardRef as r,memo as s,useCallback as a,useEffect as c,useImperativeHandle as l,useId as d,useRef as u}from"react";import*as h from"react";import{useCallback as p,useEffect as f,useLayoutEffect as m,useMemo as y,useRef as g}from"react";import{createContext as b,useCallback as x,useContext as v,useMemo as w,useRef as k,useSyncExternalStore as M}from"react";import{jsx as I}from"react/jsx-runtime";function S(e,t){const n=new Set;let i={...e(function(e){const t=e(i);if(function(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}(t)){i={...i,...t};for(const e of n)e()}}),...t??{}};return{getState:()=>i,subscribe:function(e){return n.add(e),()=>{n.delete(e)}}}}function A(e){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:C}}),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 C=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],D={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}},P={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},$={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:C,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function B(e,t){if("light"===t)return D;if("dark"===t)return P;if("high-contrast"===t)return $;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?P:D;return A({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}return A({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}var[j,R]=function(e){let t=null;const n=()=>(t||(t=b(null)),t),i=S(e);return[function({children:t,initialState:i}){const o=k(i),r=w(()=>S(e,o.current),[]),s=n();return I(s.Provider,{value:r,children:t})},(e,t)=>{const o=n(),r=v(o)??i,s=k(e);s.current=e;const a=k({hasValue:!1,value:void 0}),c=x(()=>{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]),l=x(()=>s.current(r.getState()),[r]);return M(r.subscribe,c,l)}]}(e=>({theme:D,setTheme(t){e(e=>({theme:B(e.theme,t)}))}}));import{useState as T,useEffect as N}from"react";import{useRef as E,useState as z,useEffect as W}from"react";var F=/^var\(\s*(--[^,)]+)(?:\s*,\s*([^)]+))?\s*\)$/,O=new WeakMap,L=0,q=!1,Y=null,H=null;function X(e,t){if(!t)return t;const n=F.exec(t);if(!n)return t;const i=e.canvas;if(!i)return n[2]?.trim()||t;!function(){if(q)return;if("undefined"==typeof window||"undefined"==typeof document)return;q=!0;const e=()=>{L++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"]}),"function"==typeof window.matchMedia)try{Y=window.matchMedia("(prefers-color-scheme: dark)"),H=e,"function"==typeof Y.addEventListener?Y.addEventListener("change",H):"function"==typeof Y.addListener&&Y.addListener(H)}catch{}}();let o=O.get(i);o&&o.version===L||(o={version:L,map:new Map},O.set(i,o));const r=o.map.get(t);if(void 0!==r)return r;const s=getComputedStyle(i).getPropertyValue(n[1]).trim()||n[2]?.trim()||t;return o.map.set(t,s),s}var G="undefined"==typeof window?f:m,_={requestAnimationFrame:e=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(e),cancelAnimationFrame:e=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(e)};function V(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function U(e){const t=function(){const[e,t]=T(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return N(()=>{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=g(t);n.current=t;const[i,o]=function(e,t,n){const i=E(null),[o,r]=z(null);return W(()=>{if(!t&&!n)return;const e=i.current;if(!e)return;const o=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 o.observe(e),()=>o.disconnect()},[t,n]),[i,[t&&o?o.w:e[0],n&&o?o.h:e[1]]]}(e.sizeProp,e.responsiveWidth,e.responsiveHeight),r=y(()=>({...e.marginDefault,...e.userMargin}),[e.marginDefault,e.userMargin]),s=o[0]-r.left-r.right,a=o[1]-r.top-r.bottom,c=V(e.foregroundGraphics,o,r),l=V(e.backgroundGraphics,o,r),d=R(e=>e.theme),{transition:u,introEnabled:m}=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),b="semiotic-table-"+h.useId(),x=g(null),v=g(e.frameScheduler??_);v.current=e.frameScheduler??_;const w=g(null),k=g(!1),M=g(()=>{}),I=p(()=>{if(null!==x.current||k.current)return;const e=v.current;let t=!1,n=!1;const i=e.requestAnimationFrame(()=>{t=!0;const e=!n;e&&(k.current=!0),x.current=null,w.current=null;try{M.current()}finally{e&&(k.current=!1)}});n=!0,t||(x.current=i,w.current=e)},[]),S=p(()=>{null!==x.current&&((w.current??v.current).cancelAnimationFrame(x.current),x.current=null,w.current=null)},[]);f(()=>()=>{S()},[S]);const A=g(()=>{}),C=g(()=>{}),D=g(null),P=g(null),$=g(null),B=p(()=>{const e=D.current;D.current=null,e&&A.current(e)},[]),j=p(e=>{if(D.current={clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType},null===P.current){const e=v.current;let t=!1;const n=e.requestAnimationFrame(()=>{t=!0,P.current=null,$.current=null,B()});t||(P.current=n,$.current=e)}},[B]),F=p(()=>{D.current=null,null!==P.current&&(($.current??v.current).cancelAnimationFrame(P.current),P.current=null,$.current=null),C.current()},[]);f(()=>()=>{D.current=null,null!==P.current&&(($.current??v.current).cancelAnimationFrame(P.current),P.current=null,$.current=null)},[]);const O=e.themeDirtyRef;return G(()=>{O&&(L++,O.current=!0,I())},[d,I,O]),{reducedMotion:t,reducedMotionRef:n,responsiveRef:i,size:o,margin:r,adjustedWidth:s,adjustedHeight:a,resolvedForeground:c,resolvedBackground:l,currentTheme:d,transition:u,introEnabled:m,tableId:b,rafRef:x,renderFnRef:M,scheduleRender:I,cancelRender:S,hoverHandlerRef:A,hoverLeaveRef:C,onPointerMove:j,onPointerLeave:F}}import{useEffect as K,useLayoutEffect as Q,useRef as Z,useState as J,useSyncExternalStore as ee}from"react";var te="undefined"!=typeof window?Q:K,ne=()=>()=>{},ie=()=>!1,oe=()=>!0;import*as re from"react";import{arc as se}from"d3-shape";import{symbol as ae,symbolCircle as ce,symbolCross as le,symbolDiamond as de,symbolSquare as ue,symbolStar as he,symbolTriangle as pe,symbolWye as fe}from"d3-shape";var me={circle:ce,square:ue,triangle:pe,diamond:de,star:he,cross:le,wye:fe};var ye=[40,40],ge=[.5,.5];function be(e,t,n,i){if("none"!==e)return"color"===e||null==e?t??i:"accent"===e?n:e}import{jsx as xe,jsxs as ve}from"react/jsx-runtime";function we(e,t="#4e79a7"){return e&&"string"==typeof e?e:t}function ke(e,t,n){switch(e.type){case"line":{const n=e;if(0===n.path.length)return null;const i="M"+n.path.map(([e,t])=>`${e},${t}`).join("L");return xe("path",{d:i,fill:"none",stroke:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity},"line-"+t)}case"area":{const i=e;if(0===i.topPath.length)return null;const o=`M${i.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...i.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`;if(i.clipRect){const e=`${n?n+"-":""}area-clip-${t}`;return ve("g",{children:[xe("defs",{children:xe("clipPath",{id:e,children:xe("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})}),xe("path",{d:o,fill:we(i.style.fill),fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,clipPath:`url(#${e})`})]},"area-"+t)}return xe("path",{d:o,fill:we(i.style.fill),fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth},"area-"+t)}case"point":{const n=e;return xe("circle",{cx:n.x,cy:n.y,r:n.r,fill:we(n.style.fill),opacity:n.style.opacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth},"point-"+t)}case"symbol":return function(e,t){const n=function(e,t,n){if(n)return n;const i=e??"circle";return"chevron"===i?function(e){const t=1.5*function(e){return Math.sqrt(Math.max(1,e)/Math.PI)}(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):ae(me[i]??ce,Math.max(1,t))()??""}(e.symbolType,e.size,e.path);return xe("path",{d:n,transform:e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`,fill:e.style.fill?we(e.style.fill):"none",opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},"symbol-"+t)}(e,t);case"glyph":return function(e,t,n,i){const o=e.glyph;if(!o?.parts?.length||0>=e.size)return null;const r=function(e,t){const[n,i]=e.viewBox??ye,[o,r]=e.anchor??ge,s=i>0?i:1,a=Math.max(0,t)/s,c=(n>0?n:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-o*c,offsetY:-r*l}}(o,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),c=function(e,t,n=0,i="horizontal"){const[o,r]=e.viewBox??ye,s=Math.min(1,Math.max(0,n)),a=Math.min(1,Math.max(0,t));return a>s?s>0||1>a?"vertical"===i?{x:0,y:r*(1-a),width:o,height:r*(a-s)}:{x:o*s,y:0,width:o*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(o,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),l=c?function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}(i+"-clip"):void 0,d=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),u=t=>o.parts.map((n,i)=>{const o=t?"none"===n.fill?void 0:t:be(n.fill,a,e.accent),r=t?n.stroke&&"none"!==n.stroke?t:void 0:be(n.stroke??"none",a,e.accent);return o||r?xe("path",{d:n.d,fill:o??"none",stroke:r,strokeWidth:r?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},i):null});return ve("g",{transform:s,opacity:1===d?void 0:d,children:[c&&l&&xe("clipPath",{id:l,children:xe("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&e.ghostColor?xe("g",{children:u(e.ghostColor)}):null,c&&l?xe("g",{clipPath:`url(#${l})`,children:u()}):u()]},i)}(e,e.x,e.y,`${n??""}glyph-${e.pointId??t}`);case"rect":{const n=e;return xe("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:we(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth},"rect-"+t)}case"heatcell":{const n=e;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,o,r]=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),s=.299*i+.587*o+.114*r>128?"#000":"#fff",a=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return ve("g",{children:[xe("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill}),xe("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:a+"px",children:e})]},"heatcell-"+t)}return xe("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill},"heatcell-"+t)}case"candlestick":{const n=e,i=Math.min(n.openY,n.closeY),o=Math.max(Math.abs(n.openY-n.closeY),1),r=n.isUp?n.upColor:n.downColor;return ve("g",{children:[xe("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),xe("rect",{x:n.x-n.bodyWidth/2,y:i,width:n.bodyWidth,height:o,fill:r,stroke:r,strokeWidth:1})]},"candle-"+t)}default:return null}}var Me="undefined"==typeof window||"undefined"==typeof document;import*as Ie from"react";import{jsx as Se,jsxs as Ae}from"react/jsx-runtime";var Ce={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 De(e,t){return"function"==typeof t?t(e):e[t]}function Pe(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 $e(e={}){const{fields:t,title:n,format:i,style:o={},className:r=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let s;const a=[];if(n){const t=De(e,n);s=Pe(t,i)}if(t&&t.length>0)t.forEach(t=>{let n,o,r;"string"==typeof t?(n=t,o=t,r=i):(n=t.label,o=t.accessor||t.key||"",r=t.format||i);const s=De(e,o);a.push({label:n,value:Pe(s,r)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){s=Pe(e[n],i);break}if(!s){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(s=Pe(e[t[0]],i))}}const c={...Ce,...o};return Ae("div",{className:("semiotic-tooltip "+r).trim(),style:c,children:[s&&Se("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((e,t)=>Ae("div",{style:{marginTop:0===t&&s?"4px":0},children:[e.label&&Ae("span",{children:[e.label,": "]}),e.value]},t))]})}}function Be(e){if(!0!==e){if("function"==typeof e){const t=e;return e=>{let n=Array.isArray(i=!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)?e.data??{}:e)?i[0]:i;var i;("node"===e?.nodeOrEdge&&"number"==typeof n?.x0&&"number"==typeof n?.x1||"edge"===e?.nodeOrEdge&&"number"==typeof n?.sankeyWidth)&&n.data&&"object"==typeof n.data&&(n=n.data);const o=t(n);return null==o?null:Se("div",{className:"semiotic-tooltip",style:Ce,children:o})}}return!1!==e&&void 0!==e&&("object"==typeof e&&null!==e&&("fields"in e||"title"in e)?$e(e):$e())}}import{jsx as je}from"react/jsx-runtime";function Re({x:e,y:t,containerWidth:n,containerHeight:i,margin:o,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const c=Number.isFinite(e)&&Number.isFinite(t),l=Ie.useRef(null),[d,u]=Ie.useState(null);Ie.useLayoutEffect(()=>{const e=l.current;if(!e)return;const t=e.getBoundingClientRect();u(e=>e&&e.width===t.width&&e.height===t.height?e:{width:t.width,height:t.height})},[r,s,n,i]);let h;h=d?`translate(${d.width+12>n-e?"calc(-100% - 12px)":"12px"}, ${d.height+12>i-t?"calc(-100% - 4px)":"4px"})`:`translate(${e>.7*n?"calc(-100% - 12px)":"12px"}, ${.3*i>t?"4px":"calc(-100% - 4px)"})`;const p=function(e){if(!Ie.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 i=n.style;if(i&&"object"==typeof i){if(null!=i.background&&""!==i.background&&"transparent"!==i.background)return!0;if(null!=i.backgroundColor&&""!==i.backgroundColor&&"transparent"!==i.backgroundColor)return!0}return!1}(r),f=p?null:Ce;return c?je("div",{ref:l,className:p?s:(s+" semiotic-tooltip").trim(),style:{...f||{},position:"absolute",left:o.left+e,top:o.top+t,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}var Te={names:["--semiotic-bg","--surface-1","--surface-0"],fallback:"#f8fafc"},Ne={names:["--semiotic-border","--surface-3"],fallback:"#334155"},Ee={names:["--semiotic-danger","--viz-4"],fallback:"#dc2626"},ze={names:["--semiotic-focus","--accent","--viz-9"],fallback:"#f97316"},We={names:["--semiotic-grid","--surface-3"],fallback:"#cbd5e1"},Fe={names:["--semiotic-primary","--accent","--viz-5"],fallback:"#0ea5e9"},Oe={names:["--semiotic-success","--viz-2"],fallback:"#22c55e"},Le={names:["--semiotic-text","--text-primary"],fallback:"#0f172a"},qe={names:["--semiotic-text-secondary","--text-secondary"],fallback:"#475569"},Ye={names:["--semiotic-warning","--viz-9","--viz-3"],fallback:"#f97316"};function He(e,t){const n=e.canvas;if("function"!=typeof getComputedStyle||!n)return t.fallback;const i=getComputedStyle(n);for(const n of t.names){const t=i.getPropertyValue(n).trim();if(t)return X(e,t)??t}return t.fallback}function Xe(e,t){const n=Math.max(0,Math.min(1,t)),i=e.trim(),o=i.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);if(o){const[,e,t,i]=o;return Xe(`#${e}${e}${t}${t}${i}${i}`,n)}const r=i.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(r){const[,e,t,i]=r;return`rgba(${parseInt(e,16)}, ${parseInt(t,16)}, ${parseInt(i,16)}, ${n})`}const s=i.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);if(s)return`rgba(${s[1]}, ${n})`;const a=i.match(/^rgba\s*\(\s*([^,]+,\s*[^,]+,\s*[^,]+),\s*[^)]+\)$/i);return a?`rgba(${a[1]}, ${n})`:i}import*as Ge from"react";import{scaleLinear as _e}from"d3-scale";import*as Ve from"react";import{jsx as Ue,jsxs as Ke}from"react/jsx-runtime";var Qe={fill:(e,t)=>Ue("rect",{style:e,width:t,height:t}),line:(e,t)=>Ue("line",{style:e,x1:0,y1:0,x2:t,y2:t})};function Ze(e,t,n,i,o){let r;return r="function"==typeof n?n(e):(0,Qe[n])(i(e,t),o),r}function Je({swatchSize:e}){return Ue("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 et(e,t,n){return n&&n.size>0?n.has(e.label)?1:.3:null!=t?e.label===t?1:.3:1}var tt=(e,t,n,i,o,r,s,a,c,l,d)=>{const{type:u="fill",styleFn:h,items:p}=e,f=[];let m=0;const y=!(!t&&!n),g="isolate"===l||void 0===l&&null!=o,{swatchSize:b,labelGap:x,rowHeight:v}=d;return p.forEach((e,l)=>{const d=Ze(e,l,u,h,b),w=et(e,i,o),k=o&&o.size>0&&o.has(e.label);f.push(Ke("g",{transform:`translate(0,${m})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===r&&l===s?0:-1:void 0,role:y?"option":void 0,"aria-selected":y&&g?k||!1:void 0,"aria-current":y&&!g&&null!=i&&e.label===i||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=(l+("ArrowDown"===n.key?1:-1)+p.length)%p.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:y?t=>{c(a,l),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.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&&Ue("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:b+x+2+7*e.label.length,height:b+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),d,k&&Ue(Je,{swatchSize:b}),Ue("text",{y:b/2,x:b+x,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+l)),m+=v}),f};function nt({config:e,orientation:t="vertical",width:n=100}){const{colorFn:i,domain:o,label:r,format:s}=e,a=s||(e=>Math.round(100*e)/100+""),c="grad-legend-"+Ve.useId();if("horizontal"===t){const e=12,t=Math.min(n,200),s=Math.max(0,(n-t)/2),l=[];for(let e=0;64>=e;e++){const t=e/64;l.push(Ue("stop",{offset:100*t+"%",stopColor:i(o[0]+t*(o[1]-o[0]))},e))}return Ke("g",{"aria-label":r||"Gradient legend",children:[Ue("defs",{children:Ue("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),r&&Ue("text",{x:s+t/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),Ue("rect",{x:s,y:0,width:t,height:e,fill:`url(#${c})`,rx:2}),Ue("text",{x:s,y:e+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])}),Ue("text",{x:s+t,y:e+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])})]})}const l=[];for(let e=0;64>=e;e++){const t=e/64;l.push(Ue("stop",{offset:100*t+"%",stopColor:i(o[1]-t*(o[1]-o[0]))},e))}return Ke("g",{"aria-label":r||"Gradient legend",children:[r&&Ue("text",{x:7,y:-6,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),Ue("defs",{children:Ue("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),Ue("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),Ue("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])}),Ue("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])})]})}function it(e){const{legendGroups:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:c=100,height:l=20,orientation:d="vertical",legendLayout:u}=e,h=function(e){const t=Math.max(1,e?.swatchSize??16),n=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:n,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}(u),[p,f]=Ve.useState(0),[m,y]=Ve.useState(0),g=Ve.useCallback((e,t)=>{f(e),y(t)},[]),b="vertical"===d?(({legendGroups:e,width:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:c,legendInteraction:l,metrics:d})=>{let u=24;const h=[];return e.forEach((e,p)=>{u+=5,h.push(Ue("line",{stroke:"gray",x1:0,y1:u,x2:t,y2:u},"legend-top-line legend-symbol-"+p)),u+=8,e.label&&(u+=16,h.push(Ue("text",{y:u,className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label},"legend-text-"+p)),u+=8),h.push(Ue("g",{className:"legend-item",transform:`translate(0,${u})`,children:tt(e,n,i,o,r,s,a,p,c,l,d)},"legend-group-"+p)),u+=e.items.length*d.rowHeight+8}),h})({legendGroups:t||[],width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}):(({legendGroups:e,height:t,width:n,customClickBehavior:i,customHoverBehavior:o,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:c,onFocusedIndexChange:l,legendInteraction:d,metrics:u})=>{let h=0;const p=[];e.forEach((e,t)=>{let f=0;e.label&&(f+=16);const m=((e,t,n,i,o,r,s,a,c,l,d,u)=>{const{type:h="fill",styleFn:p,items:f}=e,m=[],{swatchSize:y,labelGap:g,itemGap:b,rowHeight:x,align:v}=d,w=!(!t&&!n),k="isolate"===l||void 0===l&&null!=o,M=f.map(e=>y+g+7*e.label.length),I=[];let S=0,A=0;M.forEach((e,t)=>{const n=0===A?e:A+b+e;u&&u>0&&A>0&&n>u?(I.push({start:S,end:t,width:A}),S=t,A=e):A=n}),f.length>0&&I.push({start:S,end:f.length,width:A}),I.forEach((e,l)=>{let d="center"===v?Math.max(0,((u??e.width)-e.width)/2):"end"===v?Math.max(0,(u??e.width)-e.width):0;for(let u=e.start;e.end>u;u++){const e=f[u],v=Ze(e,u,h,p,y),I=et(e,i,o),S=o&&o.size>0&&o.has(e.label);m.push(Ke("g",{transform:`translate(${d},${l*x})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===r&&u===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?S||!1:void 0,"aria-current":w&&!k&&null!=i&&e.label===i||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=(u+("ArrowRight"===n.key?1:-1)+f.length)%f.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:w?t=>{c(a,u),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.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:I,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&Ue("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:y+g+2+7*e.label.length,height:y+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,S&&Ue(Je,{swatchSize:y}),Ue("text",{y:y/2,x:y+g,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+u)),d+=M[u]+b}});const C=Math.max(0,...I.map(e=>e.width)),D=I.length;return{items:m,offset:C,totalRows:D,totalHeight:D*x}})(e,i,o,r,s,a,c,t,l,d,u,u.maxWidth??n);f+=m.offset+5,p.push({label:e.label,...m,offset:f,totalRows:m.totalRows,totalHeight:m.totalHeight}),h+=f+12});const f=u.maxWidth??n;let m=h>f?0:"center"===u.align?Math.max(0,(f-h)/2):"end"===u.align?Math.max(0,f-h):0;const y=[];return p.forEach((n,i)=>{const o=e[i];o.label&&(y.push(Ue("text",{transform:`translate(${m},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:o.label},"legend-text-"+i)),m+=16),y.push(Ue("g",{className:"legend-item",transform:`translate(${m},0)`,children:n.items},"legend-group-"+i)),m+=n.offset+5,e[i+1]&&y.push(Ue("line",{stroke:"gray",x1:m,y1:-8,x2:m,y2:(n.totalHeight||t)+0+8},"legend-top-line legend-symbol-"+i)),m+=12}),Ue("g",{children:y})})({legendGroups:t||[],title:a,height:l,width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}),x=!(!n&&!i);return Ke("g",{role:x?"listbox":void 0,"aria-multiselectable":!(!x||"isolate"!==s&&(void 0!==s||null==r))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===d&&Ue("text",{className:"legend-title",y:16,x:c/2,textAnchor:"middle",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}function ot(e){return"object"==typeof e&&null!==e&&"legendGroups"in e}import{jsx as rt}from"react/jsx-runtime";function st(e){const{legend:t,totalWidth:n,totalHeight:i,margin:o,legendPosition:r="right",legendLayout:s,title:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendInteraction:h}=e;if(!t)return null;const p="top"===r||"bottom"===r,f=!!a,m=Math.max(0,n-o.left-o.right),y=Math.max(1,p?s?.maxWidth??m:100);let g,b;return"left"===r?(g=Math.max(4,o.left-y-10),b=o.top):"top"===r?(g=o.left,b=f?32:8):"bottom"===r?(g=o.left,b=i-o.bottom+38):(g=n-o.right+10,b=o.top),rt("g",{transform:`translate(${g}, ${b})`,children:(x=t,"object"==typeof x&&null!==x&&"gradient"in x?rt(nt,{config:t.gradient,orientation:p?"horizontal":"vertical",width:y}):ot(t)?rt(it,{legendGroups:t.legendGroups,title:"",width:y,orientation:p?"horizontal":"vertical",legendLayout:s,customHoverBehavior:c,customClickBehavior:l,highlightedCategory:d,isolatedCategories:u,legendInteraction:h}):t)});var x}import{jsx as at}from"react/jsx-runtime";var ct={secondary:0,primary:3},lt=".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}}";function dt(e){return!0===e?._annotationDeferred}function ut(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function ht(e){const t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function pt(e){return Math.max(.72,.95-.06*e)}import*as ft from"react";import{jsx as mt,jsxs as yt}from"react/jsx-runtime";function gt(e,t=120,n=8){if(!e)return[];const i=Math.max(1,Math.floor(t/n)),o=e.split(/\s+/),r=[];let s="";for(const e of o)s&&s.length+1+e.length>i?(r.push(s),s=e):s=s?`${s} ${e}`:e;return s&&r.push(s),r}function bt(e,t,n,i){return"curly"===e?i?`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`:i?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function xt(e,t,n,i){if(!e)return mt("g",{className:"annotation-note"});const{label:o,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=e;if(!o&&!r)return mt("g",{className:"annotation-note"});let d=s;d||(d=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let u=a;u&&"dynamic"!==u||(u="topBottom"===d?0>t?"right":"left":0>n?"bottom":"top");let h="start";"topBottom"===d?"right"===u?h="end":"middle"===u&&(h="middle"):h=0>t?"end":"start";const p=16,f=r?l?[r]:gt(r,c):[],m=o?l?[o]:gt(o,c):[],y="leftRight"===d?"end"===h?-4:4:0;let g=0;const b=[],x=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";e.useHTML||e.html?b.push(mt("foreignObject",{className:"annotation-note-html",x:"end"===h?y-c:"middle"===h?y-c/2:y,y:-16,width:c,height:Math.max(p,(f.length+m.length)*p+(r&&o?2:0))+p,style:{overflow:"visible"},children:yt("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:x,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&mt("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),o&&mt("div",{className:"annotation-note-label",children:o})]})},"annotation-note-html")):(f.length>0&&(b.push(mt("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:f.map((e,t)=>mt("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-title")),g=f.length*p),m.length>0&&b.push(mt("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:g,children:m.map((e,t)=>mt("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-label")));let v=null;if((r||o)&&(0!==t||0!==n))if("topBottom"===d){const e=Math.min(c,120);let t=0,n=e;"end"===h?(t=-e,n=0):"middle"===h&&(t=-e/2,n=e/2),v=mt("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}else{const e=(f.length+m.length)*p+(m.length>0?p:0);let t=0,n=e;"bottom"===u?(t=-e,n=0):"middle"===u&&(t=-e/2,n=e/2),v=mt("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,f.length+m.length-1)*p;let k=0;return"topBottom"===d?k=0>n?-(w+2):18:"leftRight"===d&&(k="middle"===u?-(w+p+(m.length>0&&f.length>0?2:0))/2+8:"bottom"===u||0>n?-(w+2):18),yt("g",{className:"annotation-note",transform:`translate(${t},${n})`,children:[mt("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function vt(e,t,n,i,o){const r=[];switch(e){case"callout-circle":{const e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&r.push(mt("circle",{r:e,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const e=t?.width||0,i=t?.height||0;(e>0||i>0)&&r.push(mt("rect",{width:e,height:i,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=i||0,s=o||0;if(void 0!==t?.x){const i=(t.x||0)-e;r.push(mt("line",{x1:i,y1:(t.y1||0)-s,x2:i,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==t?.y){const i=(t.y||0)-s;r.push(mt("line",{x1:(t.x1||0)-e,y1:i,x2:(t.x2||0)-e,y2:i,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==t?.x1||void 0!==t?.x2?r.push(mt("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(mt("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",i=t?.width??t?.height;void 0!==i&&r.push(mt("path",{d:bt(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return mt("g",{className:"annotation-subject",children:r})}function wt(e,t,n,i,o,r){const s=[];let a=0,c=0;if("callout-circle"!==o&&"label"!==o||!r?.radius){if("callout-rect"===o&&r){const n=r.width||0,i=r.height||0;if(n>0||i>0){const o=n/2,r=i/2,s=e-o,l=t-r;if(0!==s||0!==l){const e=Math.abs(s),t=Math.abs(l),d=n/2,u=i/2,h=e*u>t*d?d/e:u/t;a=o+s*h,c=r+l*h}}}else if("bracket"===o&&r){const e=r.width,t=r.height,n=r.depth||30;void 0!==e?(a=e/2,c=n):void 0!==t&&(a=n,c=t/2)}}else{const n=(r.radius||0)+(r.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const i=Math.atan2(t,e);a=Math.cos(i)*n,c=Math.sin(i)*n}}const l=Math.sqrt((e-a)**2+(t-c)**2);if(l>.5){const o=i||"var(--semiotic-text-secondary, currentColor)",r="curve"===n?.type;let d=Math.atan2(t-c,e-a);if(r){const i=(a+e)/2,r=(c+t)/2,u=-(t-c)/l,h=(e-a)/l,p=(n?.curve??.25)*l,f=i+u*p,m=r+h*p;s.push(mt("path",{className:"connector-curve",d:`M${a},${c}Q${f},${m} ${e},${t}`,fill:"none",stroke:o},"connector-line")),d=Math.atan2(m-c,f-a)}else s.push(mt("line",{x1:a,y1:c,x2:e,y2:t,stroke:o},"connector-line"));if("arrow"===n?.end){const e=10,t=16/180*Math.PI;s.push(mt("path",{d:`M${a},${c}L${a+e*Math.cos(d+t)},${c+e*Math.sin(d+t)}L${a+e*Math.cos(d-t)},${c+e*Math.sin(d-t)}Z`,fill:o,stroke:"none"},"connector-arrow"))}}return mt("g",{className:"annotation-connector",children:s})}function kt(e){const{x:t=0,y:n=0,dx:i,dy:o,nx:r,ny:s,note:a,connector:c,subject:l,type:d,color:u,className:h,disable:p,opacity:f,strokeDasharray:m,events:y={},"data-testid":g}=e,b=Array.isArray(t)?t[0]??0:t,x=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(p)?p:[]);let w=i||0,k=o||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const M="string"==typeof d?d:"label";if("bracket"===M&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const e=l.depth||30;k=e+(0>e?-5:5)}else if(void 0!==l.height){const e=l.depth||30;w=e+(0>e?-5:5),k=l.height/2}return yt("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":g,...null!=f&&{opacity:f},...m&&{strokeDasharray:m},...y,children:[!v.has("connector")&&wt(w,k,c,u,M,l),!v.has("subject")&&vt(M,l,u,b,x),!v.has("note")&&xt(a,w,k,u)]})}function Mt(e){const{noteData:t}=e,{screenCoordinates:n}=t,i="string"==typeof t.type?t.type:"label",o=t.eventListeners||t.events||{};if(t.coordinates&&n){const e=t.nx||n[0][0]+(t.dx??0),o=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:o});return mt(kt,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+r)});return mt("g",{children:r})}const r=t.note||{title:"none",label:t.label},s=`${r.label}-${r.title}-${t.i}`;return mt(kt,{"data-testid":"semiotic-annotation",events:o,...t,type:i},s)}import{packEnclose as It}from"d3-hierarchy";import{area as St,curveLinear as At,curveMonotoneX as Ct,curveMonotoneY as Dt,curveStep as Pt,curveStepAfter as $t,curveStepBefore as Bt,curveBasis as jt,curveCardinal as Rt,curveCatmullRom as Tt}from"d3-shape";import Nt from"regression";function Et(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 zt(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 Wt(e){return null==e?null:e+""}function Ft(e,t,n){return t.stickyPositionCache?.set(e,n),n}function Ot(e,t,n){const i=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===i){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let i=n.pointNodes.length-1;i>=0;i--){const o=n.pointNodes[i];if(o.pointId===e.pointId)return Ft(t,n,{x:o.x,y:o.y})}const i=function(e){const t=e.data;if(!t||0===t.length)return null;const n=t[t.length-1],i=e.scales?.x??e.scales?.time,o=e.scales?.y??e.scales?.value;if(!i||!o)return null;const r=n[e.xAccessor||"x"],s=n[e.yAccessor||"y"];return null==r||null==s?null:{x:i(r),y:o(s)}}(n);return i?Ft(t,n,i):null}if("semantic"===i){const i=function(e,t,n){const i=function(e){return Wt(e.provenance?.stableId??e.stableId)}(e);if(!i)return null;const o=n.pointNodes?.find(e=>Wt(e.pointId)===i);if(o)return Ft(t,n,{x:o.x,y:o.y});const r=n.data?.find(e=>function(e){return Wt(e.stableId??e.id??e.provenance?.stableId)}(e)===i);if(!r)return null;const s=Et(r,n),a=zt(r,n);return null==s||null==a?null:Ft(t,n,{x:s,y:a})}(e,t,n);if(i)return i}let o=null,r=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(o=t.x,r=t.y)}if(null!=o&&null!=r||(o=Et(e,n),r=zt(e,n)),null!=o&&null!=r)return Ft(t,n,{x:o,y:r});if("sticky"===i){const e=n.stickyPositionCache?.get(t);if(e)return e}return null}function Lt(e,t,n,i=50){return!(-i>e||e>(n.width||0)+i||-i>t||t>(n.height||0)+i)}function qt(e){let t=1/0,n=-1/0;for(const i of e)t>i&&(t=i),i>n&&(n=i);return[t,n]}import{jsx as Yt,jsxs as Ht}from"react/jsx-runtime";var Xt={linear:At,monotoneX:Ct,monotoneY:Dt,step:Pt,stepAfter:$t,stepBefore:Bt,basis:jt,cardinal:Rt,catmullRom:Tt};var Gt=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function _t(e){return!!e&&"object"==typeof e&&Gt.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function Vt(e){return"primary"===e?.emphasis||!0===e?.defensive}function Ut(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:2e4))):1/0}function Kt(e){let t;const n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;const i=e?.provenance?.confidence;switch("number"==typeof i&&Number.isFinite(i)&&(t+=15*Math.max(0,Math.min(1,i))),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}new Set(["label","callout","callout-circle","callout-rect"]);var Qt=32,Zt=6,Jt=4,en=8,tn=72;var nn={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function on(e){if(!rn(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 rn(e){return _t(e)}function sn(e,t){if(!e)return[];const n=Math.max(1,Math.floor(t/7)),i=e.split(/\s+/).filter(Boolean),o=[];let r="";for(const e of i)r&&r.length+e.length+1>n?(o.push(r),r=e):r=r?`${r} ${e}`:e;return r&&o.push(r),o}function an(e,t,n,i,o){const r=e+n,s=t+i;return Math.abs(n)>Math.abs(i)?{x:0>n?r-o.width-4:r+4,y:0>i?s-o.height:s,width:o.width,height:o.height}:{x:0>n?r-o.width:r,y:0>i?s-o.height-4:s+4,width:o.width,height:o.height}}function cn(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function ln(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 dn(e,t,n,i,o,r,s,a){const c=cn(e,s);let l=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,i){const o=Math.max(0,i-e.x),r=Math.max(0,i-e.y);return(o+Math.max(0,e.x+e.width-(t-i)))*e.height+(r+Math.max(0,e.y+e.height-(n-i)))*e.width}(c,o,r,a);for(const e of n)l+=12*ln(c,e);for(const e of i)l+=4*ln(c,e);return l}function un(e){const{annotations:t,context:n,defaultOffset:i=Qt,notePadding:o=Zt,markPadding:r=Jt,edgePadding:s=en,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=tn,density:d,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:m,audience:y}=e,g=n.width||0,b=n.height||0,x="object"==typeof f?f:{},v=x.breakpoint??480,w=!!f&&v>=g,k=w&&!1!==x.preferShortText?t.map(on):t,M=w&&!d?{maxAnnotations:x.maxAnnotations??("callout-list"===x.strategy?1:2),minVisible:x.minVisible??1}:d,I=u||w&&(!1!==x.progressiveDisclosure||"callout-list"===x.strategy),S=w&&!p?x.responsive??{minWidth:v}:p,A=w&&!m?x.cohesion:m;if(0===k.length||0>=g||0>=b)return k.slice();const C=[],D=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 P=!1;const $=k.map((e,t)=>{if(!rn(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 i=e.pointId??e.nodeId;if(null!=i&&n.pointNodes){const e=n.pointNodes.find(e=>e.pointId===i);if(e)return{x:e.x,y:e.y}}const o=e.coordinates,r=n.scales?.geoProjection;if(Array.isArray(o)&&o.length>=2&&r){const e=o[0],t=o[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?Ot(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!r)return e;const d=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=[...sn("string"==typeof e.title?e.title:void 0,t),...sn("string"==typeof e.label?e.label:void 0,t)],i=n.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(t,7*i)+10),height:Math.max(18,16*n.length+6)}}(e);if(a&&("number"==typeof(u=e).dx||"number"==typeof u.dy)){const t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e);return C.push(cn(an(r.x,r.y,"number"==typeof e.dx?e.dx:t.dx,"number"==typeof e.dy?e.dy:t.dy,d),o)),e}var u;let h=null,p=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}]}(i)){const t=dn(an(r.x,r.y,e.dx,e.dy,d),e,C,D,g,b,o,s);p>t&&(h=e,p=t)}if(!h)return e;const f=cn(an(r.x,r.y,h.dx,h.dy,d),o);C.push(f);const m=Math.hypot(h.dx,h.dy),y=c&&m>=l&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return P=!0,{...e,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),B=P?$:k.slice();let j=B;if(h){let e=!1;const t=B.map(t=>{const n=function(e){return"text"!==e.type||"string"!=typeof e.color||8>Math.hypot("number"==typeof e.dx?e.dx:0,"number"==typeof e.dy?e.dy:0)?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});j=e?t:B}{let e=!1;const t=j.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?nn[t.source]??t.source:null,i="number"==typeof t.confidence&&Number.isFinite(t.confidence)?Math.round(100*Math.max(0,Math.min(1,t.confidence)))+"%":null;if(!n&&!i)return e;if(null!=e.label&&"string"!=typeof e.label)return e;const o=[n,i].filter(Boolean).join(" · "),r="string"==typeof e.label?e.label:"";return r.includes(`(${o})`)?e:{...e,label:r?`${r} (${o})`:`(${o})`}}(t);return n!==t&&(e=!0),n});j=e?t:j}const R=new Set;if(M){const e="object"==typeof M?M:{},t=function(e){if(!e)return 1;const t=function(e){const t=e?.familiarity;if(!t)return 3;const n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?3:n.reduce((e,t)=>e+t,0)/n.length}(e);return t>2?4>t?1:.6:1.5}(y),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??Ut(g,b,e))*t))},{deferred:i}=function(e){const{annotations:t,width:n,height:i}=e,o=Math.max(0,e.minVisible??1),r=Ut(n,i,e),s=t.map((e,t)=>{return{annotation:e,index:t,note:(n=e,_t(n))};var n}),a=s.filter(e=>e.note);if(0===a.length||r>=a.length)return{visible:t.slice(),deferred:[],budget:r};const c=a.filter(e=>Vt(e.annotation)),l=a.filter(e=>!Vt(e.annotation)).sort((e,t)=>Kt(t.annotation)-Kt(e.annotation)||e.index-t.index),d=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,o-c.length))),u=new Set([...c.map(e=>e.index),...l.slice(0,d).map(e=>e.index)]),h=[],p=[];for(const{annotation:e,index:t,note:n}of s)!n||u.has(t)?h.push(e):p.push(e);return{visible:h,deferred:p,budget:r}}({annotations:j,width:g,height:b,...n});for(const e of i)R.add(e)}if(S&&("object"==typeof S&&"number"==typeof S.minWidth?S.minWidth:480)>=g)for(const e of j)rn(e)&&"secondary"===e.emphasis&&R.add(e);if(R.size>0)for(const e of j)!0===e?.defensive&&R.delete(e);let T;return T=0===R.size?j:I?j.map(e=>R.has(e)?{...e,_annotationDeferred:!0}:e):j.filter(e=>!R.has(e)),A?function(e,t){let n=!1;const i=e.map(e=>rn(e)?"blended"===e.cohesion||"layer"===e.cohesion?e:(n=!0,{...e,cohesion:t}):e);return n?i:e}(T,A):T}import{Fragment as hn,jsx as pn,jsxs as fn}from"react/jsx-runtime";function mn(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function yn(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,mn(e))}))}function gn(e){const{width:t,height:n,pointNodes:i=[],data:o}=e;return{scales:{x:_e().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:_e().domain([0,Math.max(1,n)]).range([0,Math.max(1,n)])},width:t,height:n,frameType:"network",pointNodes:i,data:o,xAccessor:"x",yAccessor:"y"}}function bn(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}function xn(e){const{width:t,height:n,totalWidth:i,totalHeight:o,margin:r,title:s,legend:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendPosition:h="right",legendLayout:p,pointNodes:f=[],annotations:m,autoPlaceAnnotations:y,svgAnnotationRules:g,children:b}=e,x=Ge.useMemo(()=>bn(m),[m]),v=Ge.useMemo(()=>gn({width:t,height:n,pointNodes:f}),[n,f,t]),w=Ge.useMemo(()=>x&&y?un({annotations:x,context:v,..."object"==typeof y?y:{}}):x,[v,y,x]),k=Ge.useMemo(()=>function(e,t,n){switch(e.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const i=Ot(e,t,n);if(!i)return null;const{x:o,y:r}=i;if(!Lt(o,r,n))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 Yt(Mt,{noteData:{x:o,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-"+t)}case"x-threshold":{const i=Et(null!=e.value?{...e,x:e.value}:e,n);if(null==i)return null;const o=e.color||"#f97316",r=e.labelPosition||"top";let s;s="bottom"===r?(n.height||0)-4:"center"===r?(n.height||0)/2:12;const a=i>.6*(n.width||0),c=a?i-4:i+4,l=a?"end":"start";return Ht("g",{opacity:e.opacity,children:[Yt("line",{x1:i,y1:0,x2:i,y2:n.height||0,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Yt("text",{x:c,y:s,textAnchor:l,fill:o,fontSize:12,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"y-threshold":{const i=zt(null!=e.value?{...e,y:e.value}:e,n);if(null==i)return null;const o=e.color||"#f97316",r=e.labelPosition||"right";let s,a;return"left"===r?(s=4,a="start"):"center"===r?(s=(n.width||0)/2,a="middle"):(s=(n.width||0)-4,a="end"),Ht("g",{opacity:e.opacity,children:[Yt("line",{x1:0,y1:i,x2:n.width||0,y2:i,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Yt("text",{x:s,y:i-4,textAnchor:a,fill:o,fontSize:12,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"enclose":{const i=(e.coordinates||[]).map(e=>({x:Et({...e,type:"point"},n),y:zt({...e,type:"point"},n),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>i.length)return null;const o=It(i),r=e.padding||10;return Ht("g",{children:[Yt("circle",{cx:o.x,cy:o.y,r:o.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&&Yt("text",{x:o.x,y:o.y-o.r-r-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,children:e.label})]},"ann-"+t)}case"rect-enclose":{const i=(e.coordinates||[]).map(e=>({x:Et({...e,type:"point"},n),y:zt({...e,type:"point"},n)})).filter(e=>null!=e.x&&null!=e.y);if(2>i.length)return null;const o=e.padding||10,r=i.map(e=>e.x),s=i.map(e=>e.y),[a,c]=qt(r),[l,d]=qt(s),u=a-o,h=c+o,p=l-o;return Ht("g",{children:[Yt("rect",{x:u,y:p,width:h-u,height:d+o-p,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Yt("text",{x:(u+h)/2,y:p-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,children:e.label})]},"ann-"+t)}case"highlight":{const i=n.data||[],o="function"==typeof e.filter?i.filter(e.filter):e.field&&null!=e.value?i.filter(t=>t[e.field]===e.value):[],r={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return Yt("g",{children:o.map((t,i)=>{const o=Et(t,n),s=zt(t,n);if(null==o||null==s)return null;const a="function"==typeof e.r?e.r(t):e.r||6,c="function"==typeof e.style?e.style(t):e.style||r;return Yt("circle",{cx:o,cy:s,r:a,...c},"hl-"+i)})},"ann-"+t)}case"bracket":{const i=Et(e,n),o=zt(e,n);return Yt(Mt,{noteData:{x:i??0,y:o??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-"+t)}case"trend":{const i=n.data||[];if(2>i.length)return null;const o=n.xAccessor||"x",r=n.yAccessor||"y",s="ordinal"===n.frameType,a="horizontal"===n.projection,c=s?o:null,l=s?r:null;let d;const u=[],h=new Map;if(s&&c&&l){for(const e of i){const t=e[c];if(null==t)continue;const n=t+"";h.has(n)||(h.set(n,u.length),u.push(n))}d=i.map(e=>{const t=e[c],n=e[l];if(null==t||null==n)return null;const i=h.get(t+"");return null!=i?[i,+n]:null}).filter(e=>null!==e)}else d=i.map(e=>[e[o],e[r]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>d.length)return null;const p=n.scales?.x??n.scales?.time,f=n.scales?.y??n.scales?.value;if(!p||!f)return null;const m=e=>t=>{const n=Math.max(0,Math.floor(t)),i=Math.min(u.length-1,n+1),o=t-n,r=e(u[n]);return r+(e(u[i])-r)*o},y=p,g=f;let b;if(s)if(a){const e=m(g);b=(t,n)=>[y(n),e(t)]}else{const e=m(y);b=(t,n)=>[e(t),g(n)]}else b=(e,t)=>[y(e),g(t)];const x=e.method||"linear";let v;v="loess"===x?function(e,t=.3){const n=e.length;if(2>n)return e.slice();const i=e.slice().sort((e,t)=>e[0]-t[0]),o=i.map(e=>e[0]),r=i.map(e=>e[1]),s=Math.max(2,Math.ceil(t*n)),a=[];for(let e=0;n>e;e++){const t=o[e],i=o.map(e=>Math.abs(e-t)),c=i.slice().sort((e,t)=>e-t)[Math.min(s-1,n-1)]||1,l=[];for(let e=0;n>e;e++){const t=0===c?0:i[e]/c;l[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let d=0,u=0,h=0,p=0,f=0;for(let e=0;n>e;e++){const t=l[e];0!==t&&(d+=t,u+=t*o[e],h+=t*r[e],p+=t*o[e]*o[e],f+=t*o[e]*r[e])}if(0===d){a.push([t,r[e]]);continue}const m=d*p-u*u;if(1e-12>Math.abs(m))a.push([t,h/d]);else{const e=(d*f-u*h)/m;a.push([t,(h-e*u)/d+e*t])}}return a}(d,e.bandwidth??.3):("polynomial"===x?Nt.polynomial(d,{order:e.order||2}):Nt.linear(d)).points;const w=v.map(([e,t])=>{const[n,i]=b(e,t);return`${n},${i}`}).join(" "),k=e.color||"#6366f1",M=v[v.length-1],[I,S]=b(M[0],M[1]);return Ht("g",{children:[Yt("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Yt("text",{x:I+4,y:S-4,fill:k,fontSize:11,children:e.label})]},"ann-"+t)}case"band":{const i=n.scales?.y??n.scales?.value,o=i?.(e.y0)??0,r=i?.(e.y1)??(n.height||0);return Ht("g",{opacity:e.opacity,children:[Yt("rect",{x:0,y:Math.min(o,r),width:n.width||0,height:Math.abs(r-o),fill:e.fill||"var(--semiotic-primary, #6366f1)",fillOpacity:e.fillOpacity||.1}),e.label&&Yt("text",{x:(n.width||0)-4,y:Math.max(Math.min(o,r),0)+13,textAnchor:"end",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"x-band":{const i=n.scales?.x??n.scales?.time,o=null!=e.x0&&i?i(e.x0):null,r=null!=e.x1&&i?i(e.x1):null;return null==o||null==r?null:Ht("g",{opacity:e.opacity,children:[Yt("rect",{x:Math.min(o,r),y:0,width:Math.abs(r-o),height:n.height||0,fill:e.fill||e.color||"var(--semiotic-primary, #6366f1)",fillOpacity:e.fillOpacity??.1}),e.label&&Yt("text",{x:Math.min(o,r)+4,y:13,textAnchor:"start",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"envelope":{const i=n.data||[];if(2>i.length)return null;const o=n.xAccessor||"x",r=n.scales?.x??n.scales?.time,s=n.scales?.y??n.scales?.value;if(!r||!s)return null;const a=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",l=e.filter,d=i.filter(e=>null!=e[a]&&null!=e[c]&&!(l&&!l(e))).sort((e,t)=>e[o]-t[o]);if(2>d.length)return null;const u=Xt[n.curve||"linear"]||At,h=St().x(e=>r(e[o])).y0(e=>s(e[c])).y1(e=>s(e[a])).curve(u)(d);if(!h)return null;const p=e.fill||"#6366f1";return Ht("g",{children:[Yt("path",{d:h,fill:p,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&d.length>0&&Yt("text",{x:r(d[d.length-1][o])+4,y:s(d[d.length-1][a])-4,fill:p,fontSize:11,children:e.label})]},"ann-"+t)}case"anomaly-band":{const i=n.data||[];if(2>i.length)return null;const o=n.yAccessor||"y",r=n.scales?.x??n.scales?.time,s=n.scales?.y??n.scales?.value;if(!r||!s)return null;const a=i.map(e=>e[o]).filter(e=>null!=e&&isFinite(e));if(2>a.length)return null;const c=a.reduce((e,t)=>e+t,0)/a.length,l=a.reduce((e,t)=>e+(t-c)**2,0)/a.length,d=Math.sqrt(l),u=e.threshold??2,h=c-u*d,p=!1!==e.showBand,f=e.fill||"#6366f1",m=e.fillOpacity??.1,y=e.anomalyColor||"#ef4444",g=e.anomalyRadius??6,b=s(c+u*d),x=s(h),v=i.filter(e=>{const t=e[o];return null!=t&&Math.abs(t-c)>u*d});return Ht("g",{children:[p&&Yt("rect",{x:0,y:Math.min(b,x),width:n.width||0,height:Math.abs(x-b),fill:f,fillOpacity:m}),v.map((e,t)=>{const i=Et(e,n),o=zt(e,n);return null==i||null==o?null:Yt("circle",{cx:i,cy:o,r:g,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+t)}),e.label&&Yt("text",{x:(n.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:f,fontSize:11,children:e.label})]},"ann-"+t)}case"forecast":{const i=n.data||[];if(3>i.length)return null;const o=n.xAccessor||"x",r=n.yAccessor||"y",s=n.scales?.x??n.scales?.time,a=n.scales?.y??n.scales?.value;if(!s||!a)return null;const c=i.map(e=>[e[o],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>c.length)return null;let l;if("polynomial"===(e.method||"linear")){const t=Nt.polynomial(c,{order:e.order||2}).equation;l=e=>t.reduce((t,n,i)=>t+n*Math.pow(e,i),0)}else{const e=c.length;let t=0,n=0,i=0,o=0;for(const[e,r]of c)t+=e,n+=r,i+=e*e,o+=e*r;const r=e*i-t*t;if(1e-12>Math.abs(r))return null;const s=(e*o-t*n)/r,a=(n-s*t)/e;l=e=>a+s*e}const d=c.length,u=c.map(([e,t])=>t-l(e)).reduce((e,t)=>e+t*t,0),h=Math.sqrt(u/Math.max(d-2,1)),p=c.reduce((e,t)=>e+t[0],0)/d,f=c.reduce((e,t)=>e+(t[0]-p)**2,0),m=e.confidence??.95,y=.99>m?.95>m?.9>m?1:1.645:1.96:2.576,g=e.steps??5,b=c[d-1][0],x=(b-c[0][0])/Math.max(d-1,1),v=[];for(let e=1;g>=e;e++)v.push(b+e*x);const w=[];for(const e of v){const t=l(e),n=h*Math.sqrt(1+1/d+(f>0?(e-p)**2/f:0))*y;w.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const k=`M${w.map(e=>`${s(e.x)},${a(e.yUpper)}`).join(" L")} L${w.slice().reverse().map(e=>`${s(e.x)},${a(e.yLower)}`).join(" L")} Z`,M=w.map(e=>`${s(e.x)},${a(e.yCenter)}`).join(" "),I=`${s(b)},${a(l(b))}`,S=e.strokeColor||"#6366f1";return Ht("g",{children:[Yt("path",{d:k,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),Yt("polyline",{points:`${I} ${M}`,fill:"none",stroke:S,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&w.length>0&&Yt("text",{x:s(w[w.length-1].x)+4,y:a(w[w.length-1].yCenter)-4,fill:S,fontSize:11,children:e.label})]},"ann-"+t)}case"widget":{let i,o;if(null!=e.px&&null!=e.py)i=e.px,o=e.py;else{const r=Ot(e,t,n);if(!r)return null;i=r.x,o=r.y}if(!Lt(i,o,n))return null;const r=e.width??32,s=e.height??32;return Yt("foreignObject",{x:i+(e.dx??0)-r/2,y:o+(e.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:Yt("div",{style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:e.content??Yt("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"})})},"ann-"+t)}case"text":{const i=Ot(e,t,n);if(!i)return null;const{x:o,y:r}=i,s=o+(e.dx||0),a=r+(e.dy||0),c=e.color||"var(--semiotic-text, #333)",l=Yt("text",{x:s,y:a,fill:c,fontSize:e.fontSize||11,opacity:e.opacity,strokeDasharray:e.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:e.label});return!0!==e._redundantConnector?ft.cloneElement(l,{key:"ann-text-"+t}):Ht("g",{opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:[Yt("line",{x1:o,y1:r,x2:s,y2:a,stroke:c,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),ft.cloneElement(l,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+t)}case"category-highlight":{const i=e.category;if(null==i)return null;const o=e=>"function"==typeof e&&"function"==typeof e.bandwidth,r=n.scales?.o,s=n.scales?.x,a=n.scales?.y,c=o(r)?r:o(s)?s:o(a)?a:null;if(!c)return null;const l=c(i+"");if(null==l)return null;const d=c.bandwidth(),u=e.color||"var(--semiotic-primary, #4589ff)",h=e.opacity??.15,p=e.label;return Ht("g",(n.projection?"vertical"===n.projection:c===s)?{children:[Yt("rect",{x:l,y:0,width:d,height:n.height||0,fill:u,fillOpacity:h}),p&&Yt("text",{x:l+d/2,y:12,textAnchor:"middle",fill:u,fontSize:12,fontWeight:"bold",children:p})]}:{children:[Yt("rect",{x:0,y:l,width:n.width||0,height:d,fill:u,fillOpacity:h}),p&&Yt("text",{x:12,y:l+d/2,dominantBaseline:"middle",fill:u,fontSize:12,fontWeight:"bold",children:p})]},"ann-"+t)}default:return null}},[]),M=w?function(e,t,n,i){const o=[];return e.forEach((e,r)=>{let s;if(n){const o=n(e,r,i);s=null!=o?o:t(e,r,i)}else s=t(e,r,i);s&&o.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:ht(e.annotation),readingOrder:null,rank:1};var n}),n=t.some(e=>null!=e.emphasis||null!=e.confidence),i=e.some(e=>dt(e.annotation)),o=e.some(e=>null!=ut(e.annotation)),r=e.some(e=>"layer"===ut(e.annotation));if(!n&&!i&&!o)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=2-t/Math.max(1,s.length)});for(const e of t)e.emphasis&&(e.rank=ct[e.emphasis]);const a=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{const{p:t,i:n,emphasis:i,readingOrder:o}=e,r=dt(t.annotation);let s=t.node;if("primary"===i||"secondary"===i||null!=o){const e=null==i&&null!=o;s=at("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:pt(o),"data-annotation-reading-order":o}:{},children:t.node},"annotation-emphasis-"+n)}const a=ut(t.annotation);return a&&(s=at("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),r&&(s=at("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return i&&a.unshift(at("style",{children:lt},"annotation-disclosure-style")),r&&a.unshift(at("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}(o)}(w.filter(e=>"widget"!==e.type),k,g,v):null,I=!0===w?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return fn(hn,{children:[I?pn("style",{children:lt},"physics-annotation-disclosure-style"):null,fn("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[fn("g",{transform:`translate(${r.left},${r.top})`,children:[M,b]}),s&&"string"==typeof s?pn("text",{x:i/2,y:16,textAnchor:"middle",fontWeight:600,fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:s}):s?pn("foreignObject",{x:0,y:0,width:i,height:Math.max(r.top,28),children:s}):null,a?st({legend:a,totalWidth:i,totalHeight:o,margin:r,legendPosition:h,legendLayout:p,title:s,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u}):null]})]})}function vn(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function wn(e,t){const n="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,vn(e.thickness)??vn(n)??vn(t.thickness)??4)}var kn=2500;function Mn(e){return"function"==typeof e}function In(e){return void 0===e||!1===e||!Mn(e.binAccessor)&&!Mn(e.labelAccessor)&&!Mn(e.valueAccessor)}function Sn(e){if(void 0!==e){if(!1===e)return!1;if(!In(e))throw new TypeError("Physics worker sediment config only supports string or numeric accessors");return{binAccessor:"string"==typeof e.binAccessor?e.binAccessor:void 0,labelAccessor:"string"==typeof e.labelAccessor?e.labelAccessor:void 0,valueAccessor:"string"==typeof e.valueAccessor||"number"==typeof e.valueAccessor?e.valueAccessor:void 0,retainBodyIds:e.retainBodyIds}}}function An(e){if(e)return{chartId:e.chartId,chartType:e.chartType,sensors:e.sensors}}function Cn(e){return function(e){return!Mn(e?.timeAccessor)}(e)}function Dn(e={}){if(e.engine)throw new TypeError("Physics workers use the built-in kernel adapter");const{engine:t,observation:n,sediment:i,...o}=e;return{...o,observation:An(n),sediment:Sn(i)}}function Pn(){if("undefined"!=typeof DOMException)return new DOMException("Physics worker request aborted","AbortError");const e=Error("Physics worker request aborted");return e.name="AbortError",e}var $n=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./physicsWorker.js",import.meta.url):function(e){if("undefined"!=typeof __filename){const t=__filename.replace(/\\/g,"/"),n=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+n)}throw Error("Cannot resolve module worker asset: "+e)}("physicsWorker.js");return new Worker(e,{type:"module",name:"semiotic-physics"})}()){this.nextRequestId=1,this.pending=new Map,this.worker=e,this.worker.onmessage=e=>{const t=e.data,n=this.pending.get(t.requestId);n&&(this.pending.delete(t.requestId),n.cleanup(),t.ok?n.resolve(t.payload):n.reject(function(e){const t=Error(e.error.message);return t.name=e.error.name??"Error",e.error.stack&&(t.stack=e.error.stack),t}(t)))},this.worker.onerror=e=>{this.rejectAll(Error(e.message||"Physics worker failed")),this.worker.terminate()}}request(e,t){if(t?.aborted)return Promise.reject(Pn());const n=this.nextRequestId;this.nextRequestId+=1;const i={command:e,requestId:n};return new Promise((e,o)=>{const r=()=>{this.pending.delete(n),t?.removeEventListener("abort",r),o(Pn())},s=()=>t?.removeEventListener("abort",r);this.pending.set(n,{cleanup:s,reject:o,resolve:e}),t?.addEventListener("abort",r,{once:!0});try{this.worker.postMessage(i)}catch(e){this.pending.delete(n),s(),o(e)}})}async init(e,t,n,i){if(!Cn(n))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const o=await this.request({type:"init",config:Dn(e),initialSpawns:t,initialSpawnPacing:n},i);if("frame"!==o.type)throw Error("Physics worker returned a non-frame init response");return o.frame}async restore(e,t){const n=await this.request({type:"restore",snapshot:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame restore response");return n.frame}async initFromSnapshot(e,t,n){const i=await this.request({type:"init",config:Dn(e),snapshot:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame init response");return i.frame}async enqueue(e,t,n){if(!Cn(t))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const i=await this.request({type:"enqueue",spawns:e,pacing:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame enqueue response");return i.frame}async tick(e,t){const n=await this.request({type:"tick",deltaSeconds:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame tick response");return n.frame}async settle(e,t){const n=await this.request({type:"settle",maxSteps:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame settle response");return n.frame}async snapshot(e){const t=await this.request({type:"snapshot"},e);if("snapshot"!==t.type)throw Error("Physics worker returned a non-snapshot response");return t.snapshot}async remove(e,t){const n=await this.request({type:"remove",ids:e},t);if("removed"!==n.type)throw Error("Physics worker returned a non-remove response");return{frame:n.frame,removed:n.removed}}terminate(){this.rejectAll(Error("Physics worker terminated")),this.worker.terminate()}rejectAll(e){for(const[t,n]of this.pending)this.pending.delete(t),n.cleanup(),n.reject(e)}};function Bn(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 jn={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},Rn=1e-9,Tn=.005;function Nn(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function En(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 zn(e,t,n){return Math.max(t,Math.min(n,e))}function Wn(e){return 0>e?-1:1}function Fn(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 On(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 Ln(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function qn(e,t,n,i,o,r,s,a){const c=o-e,l=(n+s)/2-Math.abs(c);if(0>=l)return null;const d=r-t,u=(i+a)/2-Math.abs(d);return u>0?u>l?{nx:Wn(c),ny:0,penetration:l}:{nx:0,ny:Wn(d),penetration:u}:null}function Yn(e,t,n,i,o,r,s){const a=r/2,c=s/2;let l=e-zn(e,i-a,i+a),d=t-zn(t,o-c,o+c);const u=l*l+d*d;if(u>n*n)return null;if(Rn>=u){const r=Math.abs(e-(i-a)),s=Math.abs(e-(i+a)),u=Math.abs(t-(o-c)),h=Math.abs(t-(o+c)),p=Math.min(r,s,u,h);return p===r?(l=-1,d=0,{nx:l,ny:d,penetration:n+r}):p===s?(l=1,d=0,{nx:l,ny:d,penetration:n+s}):p===u?(l=0,d=-1,{nx:l,ny:d,penetration:n+u}):(l=0,d=1,{nx:l,ny:d,penetration:n+h})}const h=Math.sqrt(u);return{nx:l/h,ny:d/h,penetration:n-h}}function Hn(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,i,o,r){const s=i-e,a=o-t,c=n+r,l=s*s+a*a;if(l>=c*c)return null;if(Rn>=l)return{nx:1,ny:0,penetration:c};const d=Math.sqrt(l);return{nx:s/d,ny:a/d,penetration:c-d}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return qn(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=Yn(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?Yn(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function Xn(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?Yn(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):qn(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,i,o,r,s,a=0){const c=r-i,l=s-o,d=c*c+l*l,u=d>Rn?zn(((e-i)*c+(t-o)*l)/d,0,1):0,h=n+a/2,p=e-(i+c*u),f=t-(o+l*u),m=p*p+f*f;if(m>=h*h)return null;if(Rn>=m){const e=Math.sqrt(d);return e>Rn?{nx:-l/e,ny:c/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(m);return{nx:p/y,ny:f/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 Gn(e,t){return`${e}\0${t}`}function _n(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Vn(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:Nn(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Un(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 Kn(e){return{id:e.id,shape:En(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Un(e.bodyFilter),index:e.index}}function Qn(e,t){return!!t?.some(t=>Object.is(e,t))}function Zn(e,t){const n=e.bodyFilter;if(!n)return!0;if("function"==typeof n)return n(t);const i=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}(t,n.property);return!("equals"in n&&!Object.is(i,n.equals)||"notEquals"in n&&Object.is(i,n.notEquals)||n.oneOf&&!Qn(i,n.oneOf)||n.notOneOf&&Qn(i,n.notOneOf))}var Jn=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={...jn,...e},this.random=Bn(this.options.seed)}init(e={}){this.options={...jn,...e},this.random=Bn(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(Rn,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:Nn(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))_n(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:En(t.shape),bodyFilter:Un(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 i=this.bodies.get(e);i&&(i.vx+=t/i.mass,i.vy+=n/i.mass,this.wake(i))}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 i=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,i>0){const t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>i){const n=i/t;e.vx*=n,e.vy*=n}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear();const o=this.bodyPairKeys(n),r=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,o,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:Nn(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(_n)}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(Vn),colliders:this.sortedColliders().map(Kn),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=Bn(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=Vn(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=Kn(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 i="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!i)continue;const o=i.x-n.x,r=i.y-n.y,s=Math.sqrt(o*o+r*r);if(Rn>=s)continue;const a=o/s,c=r/s,l=(s-t.restLength)*t.stiffness+((("vx"in i?i.vx:0)-n.vx)*a+(("vy"in i?i.vy:0)-n.vy)*c)*t.damping;n.vx+=l*a*e/n.mass,n.vy+=l*c*e/n.mass}}resolveBodyPairs(e,t,n){for(const i of t){const[t,o]=i.split(":").map(Number),r=e[t],s=e[o];if(!r||!s)continue;const a=Hn(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 i=0;e.length>i;i+=1){if(!1===e[i].bodyCollisions)continue;const o=Fn(e[i]),r=Math.floor(o.minX/t),s=Math.floor(o.maxX/t),a=Math.floor(o.minY/t),c=Math.floor(o.maxY/t);for(let e=r;s>=e;e+=1)for(let t=a;c>=t;t+=1){const o=`${e}:${t}`,r=n.get(o);r?r.push(i):n.set(o,[i])}}const i=new Set;for(const t of Array.from(n.keys()).sort()){const o=n.get(t)??[];o.sort((e,t)=>e-t);for(let t=0;o.length>t;t+=1)for(let n=t+1;o.length>n;n+=1){const r=o[t],s=o[n];!1!==e[r].bodyCollisions&&!1!==e[s].bodyCollisions&&Ln(Fn(e[r]),Fn(e[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((e,t)=>{const[n,i]=e.split(":").map(Number),[o,r]=t.split(":").map(Number);return n===o?i-r:n-o})}resolveDynamicCollision(e,t,n){e.sleeping&&this.supportedThisStep.add(t.id),t.sleeping&&this.supportedThisStep.add(e.id);const i=e.sleeping?0:1/e.mass,o=t.sleeping?0:1/t.mass,r=i+o;if(Rn>=r)return;const s=Math.max(0,n.penetration-Tn)/r;e.x-=n.nx*s*i,e.y-=n.ny*s*i,t.x+=n.nx*s*o,t.y+=n.ny*s*o;const a=(t.vx-e.vx)*n.nx+(t.vy-e.vy)*n.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution))*a/r,d=l*n.nx,u=l*n.ny;e.vx-=d*i,e.vy-=u*i,t.vx+=d*o,t.vy+=u*o,this.applyFriction(e,t,n,l,i,o),c>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,i,o,r){const s=-n.ny,a=n.nx,c=(t.vx-e.vx)*s+(t.vy-e.vy)*a,l=o+r;if(Rn>=Math.abs(c)||Rn>=l)return;const d=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction))),u=zn(-c/l,-i*d,i*d),h=u*s,p=u*a;e.vx-=h*o,e.vy-=p*o,t.vx+=h*r,t.vy+=p*r}resolveColliders(e,t,n){for(const i of e)for(const e of t){if(!Zn(e,i))continue;if(!Ln(Fn(i),On(e)))continue;const t=Xn(i,e);t&&(this.resolveStaticCollision(i,e,t),this.supportedThisStep.add(i.id),n&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:e.id,sensor:!1}))}}resolveStaticCollision(e,t,n){e.x+=n.nx*Math.max(0,n.penetration-Tn),e.y+=n.ny*Math.max(0,n.penetration-Tn);const i=e.vx*n.nx+e.vy*n.ny;if(0>i){const o=Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution);e.vx-=(1+o)*i*n.nx,e.vy-=(1+o)*i*n.ny;const r=-n.ny,s=n.nx,a=e.vx*r+e.vy*s,c=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction)));e.vx-=a*r*c,e.vy-=a*s*c}}updateSensors(e){const t=new Set,n=this.sortedColliders().filter(e=>e.sensor);for(const i of e){const e=Fn(i);for(const o of n){if(!Zn(o,i))continue;if(!Ln(e,On(o)))continue;if(!Xn(i,o))continue;const n=Gn(o.id,i.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:o.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:i}=_n(e);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:n})}this.activeSensors=t}updateSleeping(e,t){const n=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of e)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*t||n&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=t,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},ei=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Jn).capabilities,engine:"builtin"},this.world=new Jn(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 ti(e={}){return new ei(e)}function ni(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):ti(t)}var ii=["binId","targetBin","category","windowIndex","lane","group"];function oi(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 ri(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 si(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 ai(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function ci(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?ai(t,e):void 0}function li(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function di(e){const t=ri(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:ri(e.x),y:ri(e.y),value:t}}var ui=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=li(ci(this.config.binAccessor,e,t))??function(e){for(const t of ii){const n=li(ai(e,t));if(n)return n}return"sediment"}(e),i=li(ci(this.config.labelAccessor,e,t))??n,o=function(e,t,n){if("number"==typeof e)return e;const i="function"==typeof e?e(t,n):"string"==typeof e?ai(t,e):1,o="number"==typeof i?i:Number(i);return Number.isFinite(o)?o: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: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(n,s)),s.label=i,s.lastBodyId=e.id,s.lastDatum=e.datum,oi(s.x,e.x),oi(s.y,e.y),oi(s.value,o),r>0&&(s.bodyIds.push(e.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),di(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(di)}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:si(t.x),y:si(t.y),value:si(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 hi(e,t={}){const{baselineY:n=0,binWidth:i=24,gap:o=2,maxHeight:r=80,value:s="count",x:a}=t,c=Math.max(1,...e.map(e=>e[s]));return e.map((e,t)=>{const l=Math.max(0,e[s]/c*r),d=a?.(e,t)??t*(i+o);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:d,y:n-l,width:i,height:l,meanX:e.x.mean,meanY:e.y.mean}})}function pi(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}function fi(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),i=t+n,o=pi(e.bodyLimit),r=pi(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const i=pi(n?.warnAt);return null!=i?i:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(o,r,e.options),a=null==o?0:Math.max(0,t-o),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:o,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:i,queuedBodies:n,state:c,warnAt:s}}var mi={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},yi={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function gi(e={},t=yi){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 bi(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function xi(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 vi(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function wi(e){return{...bi(e),sequence:e.sequence,spawnAt:e.spawnAt}}function ki(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 Mi(e){return!1!==e&&{...e}}function Ii(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function Si(e){return{...e,gravity:{...e.gravity}}}function Ai(e,t,n,i){if("circle"===e.shape.type){const o=e.x-t,r=e.y-n,s=e.shape.radius+i,a=o*o+r*r;return a>s*s?null:a}const o=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=o*o+r*r;return s>i*i?null:s}function Ci(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Di(e,t={}){const{idPrefix:n="plot",includeFloor:i=!0,includeCeiling:o=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=t,l=[],d=e.x+e.width/2,u=e.y+e.height/2;return i&&l.push({id:n+"-floor",shape:{type:"aabb",x:d,y:e.y+e.height+c/2,width:e.width+2*a,height:c}}),o&&l.push({id:n+"-ceiling",shape:{type:"aabb",x:d,y:e.y-c/2,width:e.width+2*a,height:c}}),r&&l.push({id:n+"-left-wall",shape:{type:"aabb",x:e.x-a/2,y:u,width:a,height:e.height+2*c}}),s&&l.push({id:n+"-right-wall",shape:{type:"aabb",x:e.x+e.width+a/2,y:u,width:a,height:e.height+2*c}}),l}function Pi(e){const{idPrefix:t="bin",count:n,domainStart:i,domainStep:o,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:d=!0,closedBefore:u,lidY:h=s,lidThickness:p=Math.max(2,c)}=e,f=[],m=s+(a-s)/2,y=Math.abs(a-s),g=l?n:n-1;if(d||l)for(let e=l?0:1;g>=e;e+=1){if(!d&&e>0&&n>e)continue;const s=r(i+e*o);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:m,width:c,height:y}})}if(null!=u)for(let e=0;n>e;e+=1){const n=i+e*o,s=n+o;if(s>=u)continue;const a=r(n),l=r(s);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:p}})}return f}var $i={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 Bi(e,t){const n={...e};for(const e of t)n[$i[e]]++;return n}function ji(e,t,n){const i=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:i,revisions:Bi(n,i)}}var Ri=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=ji({kind:"initialize"},[],this.revisions)}get last(){return this.latest}record(e,t){const n=ji(e,t,this.revisions);return this.revisions=n.revisions,this.latest=n,n}};import{quadtree as Ti}from"d3-quadtree";var Ni=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,i,o,r=0){const s=this.ensure(e,t);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,d=i-l,u=i+l,h=o-l,p=o+l;return s.visit((e,t,s,l,f)=>{if(d>l||t>u||h>f||s>p)return!0;if(e.length)return!1;let m=e;for(;m;){const e=m.data;if(e){const t=Ai(e,i,o,Math.max(0,r));null!=t&&(c>t||t===c&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,c=t)}m=m.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=Ti().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},Ei=["data","scene-geometry","data-paint","accessibility","evidence"],zi=["scene-geometry","data-paint","accessibility","evidence"],Wi=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Fi=["overlay","accessibility","evidence"],Oi=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Li(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&Oi.every(n=>e[n]===t[n])}function qi(e,t,n,i){return e||!t?"paused":n||!i?"running":"settled"}var Yi=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new Ni,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Ri,this.simulationState="settled",this.visible=!0;const{bodyBudget:t,colliders:n,engine:i,kernel:o,observation:r,sediment:s,...a}=e;this.config={...mi,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=i,this.observation=gi(r),this.sediment=new ui(s??!1),this.world=ni(i,{fixedDt:this.config.fixedDt,...o}),n&&this.world.setColliders(ki(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!Li(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:i,engine:o,kernel:r,observation:s,sediment:a,...c}=e;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),o&&o!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=o,this.world=ni(o,e.options),this.world.restore(e),this.revision+=1}if(r&&!Li(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.revision+=1}s&&(this.observation=gi(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(ki(n)),this.revision+=1),this.configInput={...this.configInput,...e},this.updateResults.record({kind:"config",keys:t},t.length?Wi:[])}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(ki(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Wi)}enqueue(e,t){const n=Array.isArray(e)?e:[e],i=t?function(e,t={}){const n=xi(t.startAt)??0,i=t.pacing??"immediate";if("arrival"===i){const i=e.map((e,n)=>function(e,t,n){return"function"==typeof n?xi(n(e,t)):"string"==typeof n?xi(vi(e,n)):xi(e.spawnAt)??xi(vi(e,"arrivalTime"))??xi(vi(e,"timestamp"))??xi(vi(e,"time"))??xi(vi(e,"eventTime"))}(e,n,t.timeAccessor)),o=i.filter(e=>null!=e),r=o.length>0?Math.min(...o):0,s=xi(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const o=i[t],s=null==o?0:Math.max(0,o-r);return{...bi(e),spawnAt:n+s/a}})}if("object"==typeof i){const t=xi(i.ratePerSec);if(t&&t>0)return e.map((e,i)=>({...bi(e),spawnAt:n+i/t}))}return e.map(e=>({...bi(e),spawnAt:n}))}(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of i)this.queue.push({...bi(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Ii),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?Ei:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(bi(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},Ei)}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.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},Ei)}tick(e){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,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 c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),o.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let d=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>d;){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,d+=1}d===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(d>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const u=this.result(d,n,i,o,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:d},this.revision!==t?n.length||i.length||o.length?Ei:zi:[]),u}settle(e=this.config.settleStepLimit){const t=this.revision;this.spawnDue([],[]);const n=this.world.settle(e,this.config.fixedDt);return n>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:n},this.revision!==t?zi:[]),n}settleWithObservations(e=this.config.settleStepLimit){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,r,s,!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,s);const a=this.observeBodyBudget(s),c=this.evictOverflow(s);i.push(...c.evicted),o.push(...c.sedimented),this.syncSimulationState(s);let l=0;for(;e>l&&!this.world.allSleeping();){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),l+=1}(l>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const d=this.result(l,n,i,o,r,s,void 0,a);return this.updateResults.record({kind:"settle",count:l},this.revision!==t?n.length||i.length||o.length?Ei:zi:[]),d}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return hi(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()}hasPendingWork(){return this.queue.length>0||!this.world.allSleeping()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){const{timestamp:t,chartType:n,chartId:i,...o}=e,r={...o,timestamp:t??this.elapsedSeconds,chartType:n??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}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?Fi:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?Fi:[])}remove(e){const t=new Set(e),n=new Set(this.liveBodyOrder),i=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 o=e.filter(e=>n.has(e)||i.has(e));return o.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:o,count:o.length},o.length?Ei:[]),o}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},zi),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},zi)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},zi)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,n,i)=>e.applyImpulse(t,n,i),clear:()=>e.clear(),hitTest:(t,n,i)=>e.hitTest(t,n,i),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:Mi(this.bodyBudget),config:{...this.config,kernel:Si(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(wi),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:Mi(e.bodyBudget??{}),kernel:Si(e.world.options)},this.bodyBudget=Mi(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(wi).sort(Ii),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??qi(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"},Wi)}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,i,o,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:o,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!c),sleeping:c,sedimented:i,spawned:t,steps:e}}observeKernelEvents(e,t){!function(e,t,n){if(0===t.length)return;const i=new Map(e.readState().map(e=>[e.id,e]));for(const e of t){if("sleep"!==e.type)continue;const t=i.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 i=new Set(e.activeSensorPairs().map(e=>`${e.sensorId}\0${e.bodyId}`));if(0===i.size&&0===t.size)return i;const o=new Map(e.readState().map(e=>[e.id,e])),r=(e,t)=>{const{sensorId:i,bodyId:r}=Ci(t),s=n.observation.sensors[i],a=o.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:i,binId:s?.binId??i})};for(const e of Array.from(i).sort())t.has(e)||r("enter",e);for(const e of Array.from(t).sort())i.has(e)||r("exit",e);return i}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(Ci(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 fi({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=qi(this.paused,this.visible,this.queue.length>0,this.world.allSleeping());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){if(!1===this.config.eviction)return{evicted:[],sedimented:[]};const t=Math.max(0,Math.floor(this.config.bodyLimit));if(!Number.isFinite(t))return{evicted:[],sedimented:[]};const n=this.liveBodyOrder.length-t;if(0>=n)return{evicted:[],sedimented:[]};const i=("sleeping-first"===this.config.eviction?this.sleepingFirstEvictionOrder():this.liveBodyOrder.slice()).slice(0,n);if(0===i.length)return{evicted:[],sedimented:[]};const o=this.absorbSediment(i,e);this.world.remove(i);const r=new Set(i);return this.liveBodyOrder=this.liveBodyOrder.filter(e=>!r.has(e)),this.removeActiveSensorPairsForBodies(r),{evicted:i,sedimented:o}}absorbSediment(e,t){const n=new Map(this.world.readState().map(e=>[e.id,e])),i=[];for(const o of e){const e=n.get(o);if(!e)continue;const r=this.sediment.add(e);r&&(i.push(o),this.emitObservation({type:"physics-sediment",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:o,datum:e.datum,x:e.x,y:e.y,binId:r.id,count:r.count,total:r.total},t))}return i}sleepingFirstEvictionOrder(){const e=new Map(this.world.readState().map(e=>[e.id,e.sleeping])),t=[],n=[];for(const i of this.liveBodyOrder)e.get(i)?t.push(i):n.push(i);return[...t,...n]}};import*as Hi from"react-dom/server";function Xi(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 Gi={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function _i(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 Vi(e,t){const n="function"==typeof t?t(e):t;return{...Gi,...n??{}}}function Ui(e,t={}){const n=e.settle(t.maxSteps),i=e.readBodies(),o=e.snapshot(),r=function(e,t={}){return e.map(e=>function(e,t={}){const n=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),i={label:t.getBodyLabel?.(e)??_i(e)},o={style:Vi(e,t.bodyStyle),datum:n,accessibleDatum:n,accessibility:i,_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,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}(e,t))}(i,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),i=n.filter(e=>e.sleeping).length;return{bodyCount:n.length,sleepingCount:i,settled:"settled"===e.simulationState&&0===e.queue.length&&i===n.length,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:Xi(t.projectionRows)}}(o,{bodies:i,projectionRows:t.projectionRows,stepsRun:n});return{snapshot:o,bodies:i,sceneNodes:r,evidence:s,stepsRun:n}}import{jsx as Ki,jsxs as Qi}from"react/jsx-runtime";function Zi(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const i=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(i)&&i>0?i:1}function Ji(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=to(e.datum,t),i=to(e,t),o=n??i;if(null!=o&&(o+"").length>0)return o+""}return e.id}function eo(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),i=Math.floor(n);return e[i]+(e[Math.ceil(n)]-e[i])*(n-i)}function to(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}function no(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=to(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function io(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),i=e.queueLayout??"lane",o=e.queueSlotSpacing??14,r=e.queueStiffness??.35,s=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,a=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},d=new Map,u=new Map,h=new Map,p=new Map,f=new Map,m=new Map,y=new Map,g=[];let b=0,x=new Map,v=new Map,w=0,k=0,M=0,I=null,S=0,A=0,C=0,D=0,P=0,$=0,B=0,j=0,R=0,T=0,N=0,E=0,z=-1,W=!1;function F(e,n){const i=n(e);return!!i&&i.activeRegionIds.includes(t)}function O(){E+=1}function L(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function q(n,i,o,r){const s={bodyId:n.id,jobId:i.jobId,visitId:i.visitId,visit:i.visit,remaining:i.work,total:i.work,queuedAt:i.queuedAt,sequence:r};return d.set(i.jobId,s),y.delete(n.id),m.set(n.id,i.jobId),A+=1,C+=i.work,O(),function(n,i,o){const r=L(i);e.onQueued?.(n,r),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:i.total,jobId:i.jobId,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,queueDepth:d.size})}(n,s,o),s}function Y(e){if(d.size>=s||0===u.size)return;const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(d.size>=s)break;const t=f.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),y.delete(n.bodyId),q(t,n,e,n.sequence)):u.delete(n.jobId)}}function H(){let e=0;for(const t of d.values())e+=t.remaining;return e}function X(){R=Math.max(R,d.size),T=Math.max(T,H())}function G(){const e=M-a,t=Math.max(0,Math.min(a,M-(I??M)));let i=0,o=0,r=0,s=0,c=0;for(const t of g){if(e>t.end)continue;i+=t.arrivals,o+=t.arrivalWork,r+=t.completions,s+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?o/t:0;return{seconds:t,arrivals:i,arrivalWork:o,completions:r,completedWork:s,processedWork:c,arrivalsPerSecond:t>0?i/t:0,throughputPerSecond:t>0?r/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:i=>{const o=i.controls.readBodies(),r=new Map,A=new Map;for(const t of o){if(r.set(t.id,t),!F(t.id,i.getRegionState))continue;if(!no(t,e.bodyFilter))continue;const n=Ji(t,e.jobKey),o=A.get(n)??[];o.push(t),A.set(n,o)}const C=Number.isFinite(i.dt)?Math.max(0,i.dt):0;if(!W){const e=Number.isFinite(i.elapsed)?Math.max(0,i.elapsed):C;M=Math.max(0,e-C),W=!0}const R=M,T=R+C;M=T,I=null==I?R:Math.min(I,R);const E={start:R,end:T,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},H=new Map;for(const[e,t]of A){const n=h.get(e)?.bodyId,i=t.find(e=>e.id===n)??t[0];H.set(e,i),f.set(e,i)}for(const[n,o]of h){if(H.has(n))continue;const s=d.get(n),a=r.get(o.bodyId)??f.get(n);if(s){d.delete(n),m.delete(s.bodyId),B+=1,j+=s.remaining,O();const r={...L(s),abandonedAt:M,remainingWork:s.remaining,queueSeconds:Math.max(0,M-s.queuedAt)};a&&e.onAbandoned?.(a,r),i.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:a?.datum,x:a?.x,y:a?.y,regionId:t,work:s.total,remainingWork:s.remaining,jobId:n,visitId:s.visitId,visit:s.visit,queuedAt:s.queuedAt,abandonedAt:M,queueSeconds:r.queueSeconds,queueDepth:d.size})}u.delete(n),y.delete(o.bodyId),h.delete(n),f.delete(n)}for(const[n,o]of H){if(h.has(n))continue;const r=(p.get(n)??0)+1;p.set(n,r);const a=Zi(o,e.unitAccessor),c={bodyId:o.id,jobId:n,visitId:`${t}:${n}:${r}`,visit:r,regionId:t,work:a,queuedAt:M};h.set(n,c),S+=1,E.arrivals+=1,E.arrivalWork+=a;const l=b++;if(s>d.size)q(o,c,i,l);else{const s={...c,blockedAt:M,sequence:l};u.set(n,s),y.set(o.id,n),$+=1,O(),e.onBlocked?.(o,s),i.controls.recordObservation({type:"physics-capacity-blocked",bodyId:o.id,datum:o.datum,x:o.x,y:o.y,regionId:t,work:a,jobId:n,visitId:c.visitId,visit:r,queuedAt:M,blockedAt:M,queueDepth:d.size,blockedDepth:u.size})}}Y(i),X();const G=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);let _=n*C;for(const n of G){if(0>=_)break;const o=Math.min(n.remaining,_);if(n.remaining-=o,_-=o,D+=o,E.processedWork+=o,n.remaining>1e-6)continue;d.delete(n.jobId),m.delete(n.bodyId),k+=1,P+=n.total,E.completions+=1,E.completedWork+=n.total;const s=Math.max(0,M-n.queuedAt);N+=s,O();const a=r.get(n.bodyId);if(!a)continue;i.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...L(n),completedAt:M,queueSeconds:s};e.onProcessed?.(a,c),i.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:a.datum,x:a.x,y:a.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:M,queueSeconds:s,queueDepth:d.size})}Y(i),X(),function(){const e=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);x=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);v=new Map(t.map((e,t)=>[e.bodyId,t])),w=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&g.push(e);const t=M-a;for(;g.length>0&&t>g[0].end;)g.shift()}(E);const V=Math.floor(M/c);V!==z&&(z=V,O())},getSnapshot:()=>{const e=H(),i=function(){let e=0;for(const t of u.values())e+=t.work;return e}(),o=d.size,r=Array.from(d.values()).map(e=>Math.max(0,M-e.queuedAt)).sort((e,t)=>e-t),s=r.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:o,processedCount:k,unitsPerSecond:n,remainingWork:e,meanRemainingWork:o>0?e/o:0,waitingWork:e+i,blockedDepth:u.size,blockedWork:i,arrivalCount:S,admittedCount:A,admittedWork:C,processedWork:D,completedWork:P,blockedCount:$,abandonedCount:B,abandonedWork:j,peakQueueDepth:R,peakRemainingWork:T,queueAge:{count:r.length,meanSeconds:r.length>0?s/r.length:0,p50Seconds:eo(r,.5),p95Seconds:eo(r,.95),oldestSeconds:r.at(-1)??0},meanCompletedQueueSeconds:k>0?N/k:0,window:G(),simulatedAt:M,metricRevision:E}},bodyForce:e=>{if("none"===i)return null;const n=m.get(e.body.id),s=y.get(e.body.id),a=n?d.get(n):void 0,c=s?u.get(s):void 0;if(!a&&!c)return null;const l=a?x.get(e.body.id):v.get(e.body.id);if(null==l)return null;let h;const p=e.regions;if(p)for(let e=0;p.length>e;e+=1)if(p[e].id===t){const t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*o))-e.body.x)*r,y:(h.y-(l-((c?u.size:w)-1)/2)*o/Math.max(1,Math.sqrt(c?u.size:w))-e.body.y)*r*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function oo(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}function ro(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=oo(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function so(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),i=new Map,o=new Map,r=e.assignmentForce??.45,s=e.returnForce??.35,a=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,d=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=i.get(e);if(n)return n;const r=t.find(e=>!o.has(e.id));if(!r)return null;const s={resourceId:r.id,resourceBodyId:r.bodyId,caseBodyId:e,assignedAt:d};return i.set(e,s),o.set(r.id,s),u+=1,s},release:e=>{const t=i.get(e);return!!t&&(i.delete(e),o.delete(t.resourceId),u+=1,!0)},getAssignment:e=>i.get(e),tick:e=>{d=Math.max(d,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of i)l.has(e)&&l.has(t.resourceBodyId)||(i.delete(e),o.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(i.values()),simulatedAt:d,metricRevision:u}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=o.get(t.id),i=n?l.get(n.caseBodyId):void 0,a=n?r:s;return{x:((i?i.x+(c.x??0):t.home.x)-e.body.x)*a,y:((i?i.y+(c.y??0):t.home.y)-e.body.y)*a}}const d=i.get(e.body.id);if(!d||0>=a)return null;const u=l.get(d.resourceBodyId);return u?{x:(u.x-e.body.x)*a,y:(u.y-e.body.y)*a}:null}}}function ao(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):oo(e.datum,t.deadlineAccessor)??oo(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function co(e){const t=new Map;let n=0,i=0;function o(n){t.set(n.bodyId,n),i+=1,e.onStateChange?.({...n})}function r(e){const i=t.get(e);return!(!i||null!=i.completedAt||(o({...i,completedAt:n,state:"unhappy"===i.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const i=t.get(e);return!(!i||null!=i.completedAt||"unhappy"===i.state||(o({...i,state:"protected",protectedAt:n}),0))},complete:r,getCase:e=>t.get(e),tick:i=>{n=Math.max(n,i.elapsed);for(const s of i.controls.readBodies()){if(!ro(s,e.bodyFilter))continue;if(!t.has(s.id)){const t=ao(s,e);o({bodyId:s.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const a=t.get(s.id);a&&null==a.completedAt&&(e.completionRegionId&&i.getRegionState(s.id)?.activeRegionIds.includes(e.completionRegionId)?r(s.id):"waiting"!==a.state||a.deadlineAt>n||o({...a,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),o=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:o("waiting"),protected:o("protected"),unhappy:o("unhappy"),resolved:o("resolved"),resolvedUnhappy:o("resolved-unhappy"),simulatedAt:n,metricRevision:i}}}}function lo(e){const t=new Set;let n=0,i=0,o=0,r=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:s=>{n=Math.max(n,s.elapsed);const a=r;var c;c=n,r=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=s.controls.readBodies(),d=new Map(l.map(e=>[e.id,e]));for(const n of l){const i=s.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);i&&ro(n,e.bodyFilter)&&(r||t.has(n.id)||(t.add(n.id),o+=1,e.onHeld?.(n)))}if(r&&!a){for(const n of t){const t=d.get(n);t&&(s.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),i+=1,e.onReleased?.(t))}t.clear(),o+=1}for(const e of t)d.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:r,blocked:t.size,released:i,simulatedAt:n,metricRevision:o}),bodyForce:n=>{if(r||!t.has(n.body.id))return null;const i=n.regions?.find(t=>t.id===e.regionId),o=i?.shape;if(!o||"aabb"!==o.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const s=e.holdForce??.4;return{x:(o.x-n.body.x)*s-.45*n.body.vx,y:(o.y-n.body.y)*s-.45*n.body.vy}}}}function uo(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function ho(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,i)=>{const o={result:e,controls:n,dt:i.dt,elapsed:i.elapsed,getRegionState:i.getRegionState};for(const e of t)e.tick(o)},bodyForce:e=>{let n=null;for(const i of t)i.bodyForce&&(n=uo(n,i.bodyForce(e)));return n}}}function po(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:i=>{const o=i.controls.readBodies();for(const r of o){const o=i.getRegionState(r.id),s=o?.activeRegionIds.includes(e.fromRegionId);s?t.has(r.id)||(t.add(r.id),i.controls.applyImpulse(r.id,n.x??0,n.y??0),e.onPortal?.(r)):t.delete(r.id)}}}}import{useEffect as fo,useRef as mo}from"react";function yo(){return"undefined"==typeof document||!document.hidden}import{jsx as go}from"react/jsx-runtime";var bo="var(--semiotic-focus, #005fcc)";function xo({active:e,hoverPoint:t,margin:n,size:i,shape:o="circle",width:r,height:s,pathData:a}){if(!e||!t)return null;const c=t.x+n.left,l=t.y+n.top;let d;if("geoarea"!==o&&"path"!==o||!a)if("rect"===o&&null!=r&&null!=s){const e=Math.max(r,4),t=Math.max(s,4);d=go("rect",{x:c-e/2-3,y:l-t/2-3,width:e+6,height:t+6,rx:3,fill:"none",stroke:bo,strokeWidth:2,strokeDasharray:"4,2"})}else d=go("circle","wedge"===o?{cx:c,cy:l,r:12,fill:"none",stroke:bo,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:c,cy:l,r:8,fill:"none",stroke:bo,strokeWidth:2,strokeDasharray:"4,2"});else d=go("g",{transform:`translate(${n.left},${n.top})`,children:go("path",{d:a,fill:"none",stroke:bo,strokeWidth:2.5,strokeDasharray:"6,3"})});return go("svg",{style:{position:"absolute",left:0,top:0,width:i[0],height:i[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:d})}import*as vo from"react";import*as wo from"react";import{jsx as ko}from"react/jsx-runtime";var Mo=wo.createContext(null);import{jsx as Io,jsxs as So}from"react/jsx-runtime";var Ao={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Co({summary:e}){return e?Io("div",{role:"note",style:Ao,children:e}):null}function Do({tableId:e}){return Io("a",{href:"#"+e,style:Ao,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,Ao)},children:"Skip to data table"})}function Po({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 Io("div",{"aria-live":"polite","aria-atomic":"true",style:Ao,children:t})}function $o(e,t,n){const i=n.fill??"#4e79a7",o=n.stroke,r=n.strokeWidth??0,s=n.opacity??1,a=n.fillOpacity??1,c=function(e,t){const n=t.mark;if(n)return n;const i=e.datum,o=i?.__physicsMark??i?.mark;return"circle"===o||"halo"===o||"faceted"===o||"pill"===o||"diamond"===o||"square"===o?o:"circle"===e.shape.type?"circle":"square"}(t,n),l="circle"===t.shape.type?n.r??t.shape.radius:Math.max(t.shape.width,t.shape.height)/2;if(e.save(),e.globalAlpha*=s,e.beginPath(),"pill"===c||"square"===c||"aabb"===t.shape.type){const n="pill"===c?2.4*l:"aabb"===t.shape.type?t.shape.width:1.7*l,i="pill"===c?1.35*l:"aabb"===t.shape.type?t.shape.height:1.7*l,o=t.x-n/2,r=t.y-i/2,s="pill"===c?i/2:Math.min(4,n/4);e.moveTo(o+s,r),e.arcTo(o+n,r,o+n,r+i,s),e.arcTo(o+n,r+i,o,r+i,s),e.arcTo(o,r+i,o,r,s),e.arcTo(o,r,o+n,r,s),e.closePath()}else if("diamond"===c)e.moveTo(t.x,t.y-l),e.lineTo(t.x+l,t.y),e.lineTo(t.x,t.y+l),e.lineTo(t.x-l,t.y),e.closePath();else if("faceted"===c){const n=6;for(let i=0;n>i;i+=1){const o=2*Math.PI*i/n-Math.PI/2,r=t.x+Math.cos(o)*l,s=t.y+Math.sin(o)*l;0===i?e.moveTo(r,s):e.lineTo(r,s)}e.closePath()}else e.arc(t.x,t.y,l,0,2*Math.PI);i&&(e.save(),e.globalAlpha*=a,e.fillStyle=i,e.fill(),e.restore()),"halo"===c&&(e.beginPath(),e.arc(t.x,t.y,1.35*l,0,2*Math.PI),e.strokeStyle=o??i,e.lineWidth=Math.max(1.5,r||1.5),e.globalAlpha*=.55,e.stroke(),e.globalAlpha/=.55),o&&r>0&&(e.strokeStyle=o,e.lineWidth=r,n.strokeDasharray&&e.setLineDash(n.strokeDasharray.split(/[,\s]+/).map(e=>Number(e)).filter(e=>Number.isFinite(e))),e.stroke()),e.restore()}function Bo(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function jo(e){return e.sensorId??"stream-region-"+e.id}function Ro(e){const t=jo(e),n={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){const i=e.colliderThickness??8,o=e.shape.x-e.shape.width/2,r=e.shape.x+e.shape.width/2,s=e.shape.y-e.shape.height/2,a=e.shape.y+e.shape.height/2;return[{...n,id:t+"-top",shape:{type:"segment",x1:o,y1:s,x2:r,y2:s,thickness:i}},{...n,id:t+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...n,id:t+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:o,y2:a,thickness:i}},{...n,id:t+"-left",shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:i}}]}return e.collider?[{...n,id:t+"-collider",shape:e.shape}]:[]}function To(e){if(e)return{activeRegionIds:Array.from(e.activeRegionIds),regionIds:Array.from(e.regionIds),charges:{...e.charges},attributes:{...e.attributes},energy:e.energy}}function No(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}function Eo(e){if(!1===e.semanticItem)return null;const t=e.shape,n=e.semanticItem??{},i="aabb"===t.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:t.x,y:t.y,width:t.width,height:t.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2,pathData:`M ${t.x1} ${t.y1} L ${t.x2} ${t.y2}`};return{...i,...n,id:n.id??i.id}}function zo(e){return e.some(e=>null!=e.force||null!=e.damping||null!=e.impulseOnEnter||null!=e.impulseOnExit)}function Wo(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}var Fo=[];function Oo(e){const t=e.store.controls(),n=e.store.snapshot(),i=Math.max(0,e.result.steps*(n.config.fixedDt||1/60)),o=function(e,t,n,i){const o=Number.isFinite(i)?Math.max(0,i):0;if(0>=o||!zo(t))return!1;const r=new Map(t.map(e=>[e.id,e])),s=e.readBodies();let a=!1;for(const t of s){const i=n.get(t.id);if(!i||!i.activeRegionIds.size)continue;const s=To(i);if(s)for(const n of i.activeRegionIds){const i=r.get(n);if(!i)continue;const c=No(i.force,{body:t,region:i,regionState:s}),l=Number(i.damping??0),d=(c?.x??0)*o-(Number.isFinite(l)?t.vx*l*o:0),u=(c?.y??0)*o-(Number.isFinite(l)?t.vy*l*o:0);(d||u)&&(e.applyImpulse(t.id,d,u),a=!0)}}return a}(t,e.regionEffects,e.regionState,i),r=function(e,t,n,i,o,r){const s=Number.isFinite(r)?Math.max(0,r):0;if(0>=s||!t)return!1;const a=new Map(n.map(e=>[e.id,e])),c=e.readBodies();let l=!1;for(let n=0;c.length>n;n+=1){const r=c[n],d=i.get(r.id),u=To(d);let h=Fo;if(d&&d.activeRegionIds.size>0){const e=[];for(const t of d.activeRegionIds){const n=a.get(t);n&&e.push(n)}h=e}const p=Wo(t,{body:r,bodies:c,index:n,regionState:u,regions:h,simulationState:o});if(!p)continue;const f=(p.x??0)*s,m=(p.y??0)*s;(f||m)&&(e.applyImpulse(r.id,f,m),l=!0)}return l}(t,e.bodyForces,e.regionEffects,e.regionState,n.simulationState,i);return e.composed&&e.composed.onTick(e.result,t,{dt:i,elapsed:e.result.elapsedSeconds,getRegionState:t=>To(e.regionState.get(t))}),e.onTick?.(e.result,t),{regionEffectsApplied:o,bodyForcesApplied:r,snapshot:n}}function Lo(e,t,n,i,o,r,s,a,c,l){const d=function(e,t){return!!t?.isActive&&(t.predicate?.(e)??!0)}(e,o),u={selected:d,simulationState:t,regionState:r,regions:s},h="function"==typeof n?n(e,u):n,p=s.reduce((t,n)=>n.bodyStyle?{...t,..."function"==typeof n.bodyStyle?n.bodyStyle(e,u):n.bodyStyle}:t,{}),f=d?"function"==typeof i?i(e,u):i:void 0;return{fill:l?.color??a,stroke:l?.stroke??c,strokeWidth:l?.strokeWidth??1,opacity:l?.opacity??.9,...h,...p,...f}}import*as qo from"react";import{jsx as Yo,jsxs as Ho}from"react/jsx-runtime";var Xo={border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},Go="semiotic-accessible-data-table",_o=Go+" semiotic-accessible-data-table-hidden",Vo=Go+" semiotic-accessible-data-table-visible",Uo={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"},Ko={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},Qo={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)"},Zo={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},Jo={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))"},er={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},tr={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},nr={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 ir(e){return null==e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e?e+"":null}function or(e){return{__semioticHoverData:!0,body:e,data:e.datum??e,id:e.id,type:"body",x:e.x,y:e.y}}function rr(e){if("circle"===e.shape.type){const t=Math.max(4,2*e.shape.radius);return{height:t,shape:"circle",width:t}}return{height:e.shape.height,shape:"rect",width:e.shape.width}}function sr(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return e+""}return e.id}function ar(e){const t=cr(e.datum??e);return t.length?t.map(([e,t])=>`${e}: ${t}`).join(", "):"Physics body "+e.id}function cr(e){return e&&"object"==typeof e?Object.entries(e).map(([e,t])=>{if(e.startsWith("_"))return null;const n=ir(t);return null==n?null:[e,n]}).filter(e=>null!=e).slice(0,8):[]}function lr({hover:e}){const t=cr(e.data);return Ho("div",{className:"semiotic-tooltip",style:Ce,children:[Yo("div",{style:{fontWeight:700,marginBottom:t.length?4:0},children:e.id}),t.map(([e,t])=>Ho("div",{children:[Ho("span",{style:{opacity:.72},children:[e,": "]}),Yo("span",{children:t})]},e))]})}function dr(e){return e.datum&&"object"==typeof e.datum?Object.entries(e.datum).map(([e,t])=>{const n=ir(t);return null==n?null:`${e}: ${n}`}).filter(e=>null!=e).slice(0,8).join(", "):""}function ur(e){const t=[`${e.length} semantic item${1===e.length?"":"s"}.`],n=new Map;for(const t of e)t.group&&n.set(t.group,(n.get(t.group)??0)+1);return n.size&&t.push(Array.from(n).map(([e,t])=>`${e}: ${t}`).join(", ")),t.join(" ")}function hr(e){const{chartTitle:t,items:n,tableId:i}=e,[o,r]=qo.useState(!1),[s,a]=qo.useState(5),c=wo.useContext(Mo),l=c?.visible??!1,d=o||l,u=qo.useRef(null),h="Data summary for "+(t??"physics chart");qo.useEffect(()=>{d||a(5)},[d]);const p=qo.useCallback(e=>{e.target===e.currentTarget&&(o||l||r(!0))},[o,l]),f=qo.useCallback(e=>{l||u.current?.contains(e.relatedTarget)||r(!1)},[l]);if(!n.length)return Yo("span",{id:i,tabIndex:-1,style:Xo});if(!d)return Yo("div",{id:i,className:_o,role:"region","aria-label":h,tabIndex:-1,style:Xo,onFocus:p,children:Ho("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",n.length," semantic items)"]})});const m=Math.min(s,n.length),y=n.slice(0,m),g=n.length-m;return Ho("div",{ref:u,id:i,className:Vo,role:"region","aria-label":h,tabIndex:-1,onBlur:f,style:Uo,children:[Yo("button",{type:"button",className:"semiotic-accessible-data-table-close","aria-label":"Close data summary",onClick:()=>{l&&c&&c.setVisible(!1),r(!1)},style:Qo,children:"×"}),Yo("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Ko,children:ur(n)}),Ho("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Semantic items for "+(t??"physics chart"),style:Zo,children:[Yo("caption",{className:"semiotic-accessible-data-table-caption",style:tr,children:g>0?`First ${m} of ${n.length} semantic items`:`All ${n.length} semantic items`}),Yo("thead",{children:Ho("tr",{children:[Yo("th",{scope:"col",style:Jo,children:"Item"}),Yo("th",{scope:"col",style:Jo,children:"Description"}),Yo("th",{scope:"col",style:Jo,children:"Group"}),Yo("th",{scope:"col",style:Jo,children:"Position"}),Yo("th",{scope:"col",style:Jo,children:"Data"})]})}),Yo("tbody",{children:y.map((e,t)=>Ho("tr",{children:[Yo("th",{scope:"row",style:er,children:e.label}),Yo("td",{style:er,children:e.description??e.label}),Yo("td",{style:er,children:e.group??""}),Ho("td",{style:er,children:[Math.round(e.x),", ",Math.round(e.y)]}),Yo("td",{style:er,children:dr(e)})]},e.id??`${e.label}-${t}`))})]}),g>0?Ho("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:nr,children:["Show ",Math.min(25,g)," more"," ",1===g?"row":"rows"," (",g," remaining)"]}):null]})}lr.ownsChrome=!0;import{jsx as pr,jsxs as fr}from"react/jsx-runtime";var mr=[640,360],yr={top:0,right:0,bottom:0,left:0},gr=new Set(["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]);function br(e,t,n){const i=new Yi(e);return t?.length&&i.enqueue(t,n),i}var xr="StreamPhysicsFrame";function vr(){return"undefined"!=typeof performance?performance.now():Date.now()}var wr=s(r(function(e,t){const{accessibleTable:n=!0,annotations:i,autoPlaceAnnotations:r,background:s,backgroundGraphics:h,bodySemanticItemLimit:p=200,bodySemanticItems:f=!1,bodySemanticUpdateMs:m=200,bodyForces:y,bodyStyle:g,chartId:b,className:x,frameScheduler:v,clock:w,color:k,config:M,controllers:I,continuous:S=!1,description:A,emphasis:C,chartMode:D,enableHover:P=!0,foregroundGraphics:$,hoverRadius:B=16,initialSpawns:j,initialSpawnPacing:R,legend:T,legendClickBehavior:N,legendHighlightedCategory:E,legendHoverBehavior:z,legendIsolatedCategories:W,legendLayout:F,legendPosition:O,margin:L,onClick:q,onObservation:Y,onRegionEvent:H,onSimulationExecutionChange:X,onBodyHover:G,onBodyPointerDown:_,onSemanticItemActivate:V,onSemanticItemFocus:Q,onTick:re,opacity:se,paused:ae=!1,regionEffects:ce=[],responsiveHeight:le,responsiveWidth:de,selectedBodyStyle:ue={stroke:"#111827",strokeWidth:2,opacity:1},selection:he,semanticItems:pe=[],simulationExecution:fe="auto",size:me=mr,stroke:ye,strokeWidth:ge,summary:be,suspendWhenHidden:xe=!0,svgAnnotationRules:ve,title:we,tooltipContent:Ie,workerBodyThreshold:Se=kn,renderBody:Ae,beforePaint:Ce,afterPaint:De}=e,Pe=o.useMemo(()=>({color:k,stroke:ye,strokeWidth:ge,opacity:se}),[k,se,ye,ge]),$e=u(Y);$e.current=Y;const Be=u(b);Be.current=b;const je=u(new Map),Ge=u(ce);Ge.current=ce;const _e=u(y);_e.current=y;const Ve=u(re);Ve.current=re;const Ue=o.useMemo(()=>ho(I),[I]),Ke=u(Ue);Ke.current=Ue;const Qe=S||!!Ue?.continuous,Ze=u(Qe);Ze.current=Qe;const Je=o.useMemo(()=>{if(!y&&!Ue?.bodyForce)return y;if(!Ue?.bodyForce)return y;if(!y)return Ue.bodyForce;const e=Ue.bodyForce;return t=>{const n="function"==typeof y?y(t):y,i="function"==typeof e?e(t):e;return n||i?{x:(n?.x??0)+(i?.x??0),y:(n?.y??0)+(i?.y??0)}:null}},[y,Ue]);_e.current=Je;const et=o.useMemo(()=>new Map(ce.map(e=>[jo(e),e])),[ce]),tt=o.useMemo(()=>new Map(ce.map(e=>[e.id,e])),[ce]),nt=o.useMemo(()=>ce.map(Eo).filter(e=>null!=e),[ce]),[it,ot]=o.useState([]),rt=o.useMemo(()=>it.length||nt.length?[...pe,...it,...nt]:pe,[it,nt,pe]),st=o.useMemo(()=>zo(ce),[ce]),at=!!Je,ct=u(null),lt=u(w??vr);lt.current=w??vr;const dt=a((e,t,n)=>{const i=ct.current;if(!i||!n)return!1;const o=i.readBodies().find(t=>t.id===e),r=To(je.current.get(e));if(!o||!r)return!1;const s=No(n,{body:o,region:t,regionState:r});return!(!s||!s.x&&!s.y||(i.applyImpulse(e,s.x??0,s.y??0),0))},[]),ut=a((e,t,n)=>{if(!n.bodyId)return;const i=To(je.current.get(n.bodyId));if(!i)return;const o={bodyId:n.bodyId,datum:n.datum,observation:n,region:t,regionState:i,type:e};"region-enter"===e?t.onEnter?.(o):t.onExit?.(o),H?.(o)},[H]),ht=a(e=>{const t=e.sensorId?et.get(e.sensorId):void 0;if(!t||!e.bodyId)return;const n=function(e,t){let n=e.get(t);return n||(n={activeRegionIds:new Set,attributes:{},charges:{},energy:0,regionIds:new Set},e.set(t,n)),n}(je.current,e.bodyId),i=ct.current?.readBodies().find(t=>t.id===e.bodyId),o=To(n),r=i&&o?{body:i,region:t,regionState:o}:null;if("physics-proximity-enter"===e.type){if(n.activeRegionIds.add(t.id),n.regionIds.add(t.id),n.energy+=t.energyDelta??0,r){!function(e,t,n){const i="function"==typeof e.attributes?e.attributes(t):e.attributes;i&&(n.attributes={...n.attributes,...i})}(t,r,n);const e=function(e,t){return void 0!==e.charge?"function"==typeof e.charge?e.charge(t):e.charge:"charge-gate"===e.kind?1:void 0}(t,r);void 0!==e&&(n.charges[t.id]=e)}dt(e.bodyId,t,t.impulseOnEnter),ut("region-enter",t,e)}else"physics-proximity-exit"===e.type&&(n.activeRegionIds.delete(t.id),dt(e.bodyId,t,t.impulseOnExit),ut("region-exit",t,e))},[dt,ut,et]),pt=o.useMemo(()=>{if(!i?.length)return[];const e=i.filter(e=>"barrier"===e.physics||"sensor"===e.physics);return e.length?function(e=[],t={}){const n=t.idPrefix?t.idPrefix+"-":"",i=[];for(const o of e){if("barrier"!==o.physics&&"sensor"!==o.physics)continue;const e=o.axis??t.defaultAxis??"x",r=wn(o,t),s=o.colliderId??`${n}${o.id}`;let a;if("x"===e){const e=vn(o.x),n=vn(o.y1)??vn(t.plotBounds?.y)??vn(o.y),i=vn(o.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??vn(o.y);if(null==e||null==n||null==i)continue;a={type:"segment",x1:e,y1:n,x2:e,y2:i,thickness:r}}else{const e=vn(o.y),n=vn(o.x1)??vn(t.plotBounds?.x)??vn(o.x),i=vn(o.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??vn(o.x);if(null==e||null==n||null==i)continue;a={type:"segment",x1:n,y1:e,x2:i,y2:e,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===o.physics,..."barrier"!==o.physics||null==o.restitution&&null==t.barrierRestitution?{}:{restitution:vn(o.restitution)??vn(t.barrierRestitution)},..."barrier"!==o.physics||null==o.friction&&null==t.barrierFriction?{}:{friction:vn(o.friction)??vn(t.barrierFriction)}})}return i}(e,{idPrefix:b?b+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:me?.[0]??mr[0],height:me?.[1]??mr[1]}}):[]},[i,b,me]),ft=o.useMemo(()=>{const e=ce.flatMap(e=>[{id:jo(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...Ro(e)]),t=Object.fromEntries(ce.map(e=>[jo(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),n=M?.observation,i=ce.length>0;return i||e.length>0||pt.length>0||null!=b||n?{...M,colliders:[...M?.colliders??[],...e,...pt],observation:{...n,chartId:b??n?.chartId,chartType:n?.chartType??xr,sensors:{...n?.sensors??{},...t},onObservation:e=>{i&&ht(e),n?.onObservation?.(e)}}}:M},[pt,b,M,ht,ce]);if(!ct.current){const e=br(ft,j,R);e.setPaused(ae),xe&&e.setVisible(yo()),ct.current=e}const mt=u(null),yt=u(-1),gt=u(null),bt=u(!0),xt=u(""),vt=d().replace(/:/g,""),wt=u(!1),kt=u(!1),Mt=u(0),It=u(!1),St=u(null),At=u(!1),Ct=U({sizeProp:me,responsiveWidth:de,responsiveHeight:le,userMargin:L,marginDefault:yr,foregroundGraphics:$,backgroundGraphics:h,frameScheduler:v}),{margin:Dt,rafRef:Pt,reducedMotionRef:$t,renderFnRef:Bt,cancelRender:jt,resolvedBackground:Rt,resolvedForeground:Tt,responsiveRef:Nt,scheduleRender:Et,size:zt}=Ct,Wt=function(){const[e,t]=J(!1);return te(()=>{t(!0)},[]),e}(),Ft=function(){const e=ee(ne,ie,oe);return Z(e).current}(),[Ot,Lt]=o.useState(null),[qt,Yt]=o.useState(null),Ht=u(null),Xt=u(0),Gt=u(new Map),_t=vt+"-physics-live",Vt=a((e,t,n=!1)=>{if(!f)return void ot(e=>e.length?[]:e);const i=lt.current();if(!n&&m>0&&m>i-Xt.current)return;Xt.current=i;const o=function(e,t,n,i){if(!n)return[];const o=Math.max(0,Math.floor(i));if(!o)return[];const r=[];for(let i=0;e.length>i&&o>r.length;i+=1){const o=e[i],s="function"==typeof n?n(o,{index:i,simulationState:t}):void 0;if(!1===s)continue;const a=rr(o);r.push({datum:o.datum??o,description:ar(o),group:"body",label:sr(o),...a,...s??{},bodyId:s?.bodyId??o.id,id:s?.id??"body:"+o.id,x:s?.x??o.x,y:s?.y??o.y})}return r}(e,t,f,p);ot(e=>function(e,t){if(e.length!==t.length)return!0;for(let n=0;e.length>n;n+=1){const i=e[n],o=t[n];if(i.id!==o.id||i.label!==o.label||i.description!==o.description||i.group!==o.group||i.bodyId!==o.bodyId||Math.round(i.x)!==Math.round(o.x)||Math.round(i.y)!==Math.round(o.y))return!0}return!1}(e,o)?o:e)},[p,f,m]),Ut=a(e=>{if(!rt.length)return;const t=Math.max(0,Math.min(e,rt.length-1));yt.current=t;const n=rt[t];if(Ht.current=n.bodyId??null,Lt(n),Q?.(n),n.bodyId&&ct.current){const e=ct.current.readBodies().find(e=>e.id===n.bodyId);if(e){const t=or(e);Yt(t),G?.(e,t)}}},[rt,G,Q]),Kt=a(()=>{yt.current=-1,Ht.current=null,Lt(null),Q?.(null)},[Q]),Qt=a((e,t)=>{const n=$e.current;if(!n)return;const i=lt.current();n("hover"!==e&&"click"!==e?{type:e,timestamp:i,chartType:xr,chartId:Be.current}:{type:e,datum:t?.datum??{},x:t?.x??0,y:t?.y??0,timestamp:i,chartType:xr,chartId:Be.current})},[]),Zt=a(()=>{Yt(e=>e?(G?.(null,null),Qt("hover-end"),null):e)},[Qt,G]),Jt=a(e=>{if(!P||!ct.current)return;const t=e.currentTarget.getBoundingClientRect(),n=ct.current.hitTest(e.clientX-t.left,e.clientY-t.top,B);if(!n)return void Zt();const i=or(n);Yt(e=>e&&e.id===i.id&&e.x===i.x&&e.y===i.y?e:(G?.(n,i),Qt("hover",{datum:n.datum,x:n.x,y:n.y}),i))},[Zt,Qt,P,B,G]),en=a(e=>{Kt();const t=ct.current,n=e.currentTarget.getBoundingClientRect(),i=e.clientX-n.left,o=e.clientY-n.top,r=t?t.hitTest(i,o,Math.max(16,B)):null;_?.(r,e),r?(Qt("click",{datum:r.datum,x:r.x,y:r.y}),q?.(r.datum??null,{x:r.x,y:r.y,body:r})):(Qt("click-end"),q?.(null,{x:i,y:o,body:null}),Zt())},[Zt,Kt,Qt,B,_,q]);c(()=>{if(!rt.length)return void Kt();const e=yt.current;if(rt.length>e){if(e>=0){const t=rt[e];if(Ht.current=t.bodyId??null,Lt(e=>null!=e&&e.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t),t.bodyId&&ct.current){const e=ct.current.readBodies().find(e=>e.id===t.bodyId);if(e){const t=or(e);Yt(e=>e?.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t)}}}}else Ut(rt.length-1)},[rt,Kt,Ut]),c(()=>{P||Zt()},[Zt,P]);const tn=a(e=>{if(!rt.length)return;if("Escape"===e.key)return e.preventDefault(),void Kt();if(("Enter"===e.key||" "===e.key)&&yt.current>=0)return e.preventDefault(),void V?.(rt[yt.current]);if(!gr.has(e.key))return;e.preventDefault();const t=yt.current;if(0>t)return void Ut(0);const n=Math.max(1,Math.floor(.1*rt.length));let i=t;"Home"===e.key?i=0:"End"===e.key?i=rt.length-1:"PageDown"===e.key?i=Math.min(rt.length-1,t+n):"PageUp"===e.key?i=Math.max(0,t-n):"ArrowRight"===e.key||"ArrowDown"===e.key?i=Math.min(rt.length-1,t+1):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(i=Math.max(0,t-1)),Ut(i)},[Kt,Ut,V,rt]),[nn,on]=o.useState([]),rn=u(0),sn=!!i?.length&&i.some(e=>null!=e.pointId||null!=e.bodyId||"latest"===e.anchor),an=a(()=>{const e=mt.current,t=ct.current;if(!e||!t)return;const n=function(){if("undefined"==typeof window)return 1;const e=window.devicePixelRatio||1,t=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(e,t))}(),i=function(e,t,n,i){const o=e.getContext("2d");if(!o)return null;const r=Math.round(t[0]*i),s=Math.round(t[1]*i),a=r/t[0],c=s/t[1],l=t[0]+"px",d=t[1]+"px";return e.style.width!==l&&(e.style.width=l),e.style.height!==d&&(e.style.height=d),e.width===r&&e.height===s||(e.width=r,e.height=s),o.setTransform(a,0,0,c,0,0),o.translate(n.left,n.top),o}(e,zt,Dt,n);if(!i)return;const o=function(e){const t=He(e,Fe),n=He(e,Ee),i=He(e,Ye),o=He(e,Oe),r=He(e,Ne),s=He(e,Te),a=He(e,Le),c=He(e,qe),l=He(e,ze),d=He(e,We);return{annotationBackground:Xe(s,.94),annotationStroke:r,annotationText:a,background:s,border:r,closedWindowFill:Xe(n,.08),closedWindowStroke:Xe(n,.55),danger:n,focus:l,grid:d,gutterFill:Xe(c,.14),lateFill:i,openWindowFill:Xe(t,.07),openWindowStroke:Xe(t,.3),primary:t,selectedFill:i,selectedStroke:l,success:o,text:a,textSecondary:c,warning:i}}(i);i.clearRect(-Dt.left,-Dt.top,zt[0],zt[1]),h||"transparent"===s||(i.fillStyle=s??o.background,i.fillRect(-Dt.left,-Dt.top,zt[0],zt[1]));const r=t.snapshot(),a=t.readBodies();if(Vt(a,r.simulationState),sn){const e=lt.current();if(e-rn.current>=100){rn.current=e;const t=yn(a);on(e=>e.length===t.length&&e.every((e,n)=>e.pointId===t[n].pointId&&Math.round(e.x)===Math.round(t[n].x)&&Math.round(e.y)===Math.round(t[n].y))?e:t)}}Ce&&(i.save(),Ce(i,a),i.restore());for(const e of a){const t=je.current.get(e.id),n=t?Array.from(t.activeRegionIds).map(e=>tt.get(e)).filter(e=>null!=e):[],s=Lo(e,r.simulationState,g,ue,he,To(t),n,o.primary,o.text,Pe);Ae?(i.save(),Ae(i,e,s),i.restore()):$o(i,e,s)}De&&(i.save(),De(i,a),i.restore()),function(e,t,n){let i=!1;for(const[o,r]of t){const s=Math.min(1,Math.max(0,(n-r.startedAt)/r.durationMs));if(s>=1){t.delete(o);continue}i=!0;const a=1-Math.pow(1-s,3),{body:c}=r,l=r.radius+28*a,d=1-s;e.save(),e.globalAlpha*=d,e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=2.4*d+.4,e.beginPath(),e.arc(c.x,c.y,l,0,2*Math.PI),e.stroke(),e.globalAlpha*=.18,e.beginPath(),e.arc(c.x,c.y,.52*l,0,2*Math.PI),e.fill(),e.restore(),e.save(),e.globalAlpha*=d,e.strokeStyle=r.color,e.lineWidth=1.8;for(let t=0;8>t;t+=1){const n=t*(Math.PI/4)+1.4*s,i=r.radius+5+12*a,o=r.radius+12+34*a;e.beginPath(),e.moveTo(c.x+Math.cos(n)*i,c.y+Math.sin(n)*i),e.lineTo(c.x+Math.cos(n)*o,c.y+Math.sin(n)*o),e.stroke()}e.restore()}}(i,Gt.current,lt.current()),bt.current=!1},[De,s,h,Ce,g,Dt,sn,tt,Ae,ue,he,Pe,Vt,zt]),cn=a((e,t)=>{const n=ct.current,i=`${fe}:${e}:${t??""}`;xt.current!==i&&(xt.current=i,X?.({execution:e,liveBodies:n?.liveBodyCount()??0,queuedBodies:n?.queueSize()??0,reason:t,requested:fe}))},[X,fe]),ln=a((e,t=!0)=>{Mt.current+=1,wt.current=!1,It.current=!1,At.current=!1,St.current?.terminate(),St.current=null,t&&cn("sync",e)},[cn]),dn=a(()=>Wt?"undefined"==typeof window||"undefined"==typeof Worker?"worker unavailable":st?"runtime region effects require sync":at?"body forces require sync":Ue?"physics controllers require sync":function(e){return!e||!e.engine&&In(e.sediment)&&(!(t=e.colliders)||t.every(e=>{const t=e.bodyFilter;return!t||"function"!=typeof t}));var t}(ft??{})?Cn(R)?kt.current?"worker fallback":null:"spawn pacing is not worker-cloneable":"config is not worker-cloneable":"hydrating",[ft,Ue,at,st,Wt,R]),un=a(()=>{const e=ct.current,t=dn();if(!e||t)return{reason:t,useWorker:!1};const n=e.liveBodyCount(),i=e.queueSize(),o=function(e,t,n=0,i=kn){return"sync"!==e&&("worker"===e||t+n>=i)}(fe,n,i,Se);return{reason:o?"worker"===fe?"forced worker":"body threshold":"below threshold",useWorker:o}},[fe,Se,dn]),hn=a(e=>{const t=ct.current;return t&&e.snapshot?(t.restore(e.snapshot),bt.current=!0,t):t},[]),pn=a((e,t=!0)=>{const n=hn(e);if(!n)return;t&&re?.(e.result,n.controls()),an();const i=n.snapshot();!e.result.shouldContinue&&Gt.current.size<=0||i.paused||!i.visible||$t.current||Et()},[hn,re,an,$t,Et]),fn=a(e=>{kt.current=!0,ln("worker failed: "+((e instanceof Error?e.message:e+"")||"unknown error"))},[ln]),mn=a(()=>{const e=ct.current;if(!e)return!1;const t=un();if(!t.useWorker)return wt.current||At.current?ln(t.reason??"sync fallback"):cn("sync",t.reason??"sync"),!1;if(wt.current||At.current)return!0;const n=St.current??new $n;St.current=n,At.current=!0;const i=Mt.current+1;return Mt.current=i,n.initFromSnapshot(ft??{},e.snapshot()).then(e=>{if(Mt.current!==i)return;At.current=!1,wt.current=!0,kt.current=!1,hn(e),cn("worker",t.reason??"worker"),an();const n=ct.current?.snapshot();e.result.shouldContinue&&n&&!n.paused&&n.visible&&!$t.current&&(gt.current=null,Et())}).catch(e=>{Mt.current===i&&fn(e)}),!0},[hn,ft,fn,an,$t,cn,Et,ln,un]),gn=a(e=>"frame"===e.type||"removed"===e.type?e.frame:null,[]),bn=a((e,t=!0)=>{const n=St.current;if(!n||!wt.current)return;const i=Mt.current;n.request(e).then(e=>{if(Mt.current!==i)return;const n=gn(e);n&&pn(n,t)}).catch(fn)},[pn,gn,fn]),Mn=a(()=>{const e=ct.current;if(!e)return;const t=mn(),n=e.snapshot(),i=Qe||at||st||!!Ue;n.paused||!n.visible||!e.hasPendingWork()&&!i||$t.current?Bt.current():t&&At.current||(gt.current=null,Et())},[Ue,Qe,at,st,$t,Bt,Et,mn]),Sn=a(()=>{jt(),Pt.current=null;const e=ct.current;if(!e)return;if(wt.current&&St.current){if(It.current)return;let t=0;if(!$t.current){const e=lt.current();t=null!==gt.current?(e-gt.current)/1e3:0,gt.current=e}const n=St.current,i=Mt.current;return It.current=!0,void($t.current?n.settle():n.tick(t)).then(e=>{It.current=!1,Mt.current===i&&pn(e)}).catch(n=>{if(It.current=!1,Mt.current!==i)return;fn(n);const o=$t.current?e.settleWithObservations():e.tick(t);Oo({store:e,result:o,regionEffects:Ge.current,regionState:je.current,bodyForces:_e.current,composed:Ke.current,onTick:Ve.current}),an()})}let t;if($t.current)t=e.settleWithObservations();else{const n=lt.current(),i=null!==gt.current?(n-gt.current)/1e3:0;gt.current=n,t=e.tick(i)}const n=Ke.current,{regionEffectsApplied:i,bodyForcesApplied:o,snapshot:r}=Oo({store:e,result:t,regionEffects:Ge.current,regionState:je.current,bodyForces:_e.current,composed:n,onTick:Ve.current});an(),(Ze.current||t.shouldContinue||i||o||n||Gt.current.size>0)&&!r.paused&&r.visible&&!$t.current&&Et()},[pn,fn,an,jt,Et,$t,Pt]);Bt.current=Sn,function(e){const{hydrated:t,wasHydratingFromSSR:n,storeRef:i,dirtyRef:o,renderFnRef:r,cancelRender:s,cleanup:a}=e;te(()=>{t&&n&&i.current?.cancelIntroAnimation?.(),o.current=!0,s?.(),r.current()},[t,n]);const c=Z(a);c.current=a,K(()=>()=>c.current?.(),[])}({hydrated:Wt,wasHydratingFromSSR:Ft,storeRef:ct,dirtyRef:bt,renderFnRef:Bt,cancelRender:jt}),c(()=>{kt.current=!1,(wt.current||At.current)&&ln("config changed",!1),ct.current?.updateConfig(ft??{}),Mn()},[ft,ln]),c(()=>{kt.current=!1,Mn()},[Wt,fe,Se]),function({cancelRender:e,lastFrameTimeRef:t,paused:n,postWorkerCommand:i,requestRender:o,storeRef:r,suspendWhenHidden:s}){const a=mo(i);a.current=i;const c=mo(o);c.current=o,fo(()=>{const i=r.current;i&&(i.setPaused(n),n&&(t.current=null,e()),a.current({type:"setPaused",paused:n},!1),c.current())},[e,n]),fo(()=>{if(!s||"undefined"==typeof document)return;const n=()=>{const n=r.current;if(!n)return;const i=yo();n.setVisible(i),i||(t.current=null,e()),a.current({type:"setVisible",visible:i},!1),c.current()};return n(),document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[e,s])}({cancelRender:jt,lastFrameTimeRef:gt,paused:ae,postWorkerCommand:bn,requestRender:Mn,storeRef:ct,suspendWhenHidden:xe}),c(()=>()=>ln("unmount",!1),[ln]),c(()=>{an()},[an]),l(t,()=>({...ct.current.controls(),applyImpulse:(e,t,n)=>{ct.current.applyImpulse(e,t,n),bn({type:"applyImpulse",id:e,ix:t,iy:n}),Mn()},clear:()=>{ct.current.clear(),je.current.clear(),Gt.current.clear(),bn({type:"clear"}),Mn()},clearRegionState:e=>{e?je.current.delete(e):je.current.clear(),Mn()},getData:()=>ct.current.readBodies(),getRegionState:e=>e?To(je.current.get(e)):function(e){const t={};return e.forEach((e,n)=>{const i=To(e);i&&(t[n]=i)}),t}(je.current),getStore:()=>ct.current,pause:()=>{ct.current.setPaused(!0),bn({type:"setPaused",paused:!0},!1),Mn()},push:(e,t)=>{ct.current.enqueue(e,t),Cn(t)?bn({type:"enqueue",spawns:[e],pacing:t}):(wt.current||At.current)&&ln("spawn pacing is not worker-cloneable"),Mn()},pushMany:(e,t)=>{ct.current.enqueue(e,t),Cn(t)?bn({type:"enqueue",spawns:e,pacing:t}):(wt.current||At.current)&&ln("spawn pacing is not worker-cloneable"),Mn()},popBodies:(e,t={})=>{const n=ct.current,i=new Map(n.readBodies().map(e=>[e.id,e])),o=n.remove(e),r=lt.current();for(const e of o){const n=i.get(e);n&&(je.current.delete(e),Gt.current.set(e,{body:n,color:t.color??"#f59e0b",durationMs:Math.max(120,t.durationMs??520),radius:t.radius??Bo(n),startedAt:r}),Ht.current===e&&(Ht.current=null,Lt(null)),Yt(t=>t?.id===e?null:t))}return o.length&&(bn({type:"remove",ids:o}),Mn()),o},remove:e=>{const t=ct.current.remove(e);for(const t of e)je.current.delete(t);return bn({type:"remove",ids:e}),Mn(),t},restore:e=>{ct.current.restore(e),je.current.clear(),Gt.current.clear(),bn({type:"restore",snapshot:e},!1),Mn()},resume:()=>{ct.current.setPaused(!1),bn({type:"setPaused",paused:!1},!1),Mn()},settle:e=>{const t=ct.current.settle(e);return bn({type:"settle",maxSteps:e}),Mn(),t},settleWithObservations:e=>{const t=ct.current.settleWithObservations(e);return bn({type:"settle",maxSteps:e}),Mn(),t},step:e=>{const t=ct.current,n=t.tick(e);return Oo({store:t,result:n,regionEffects:Ge.current,regionState:je.current,bodyForces:_e.current,composed:Ke.current,onTick:Ve.current}),bn({type:"tick",deltaSeconds:e}),an(),n}}),[an,bn,Mn,ln]);const An=Me||!Wt&&Ft,Dn=["stream-physics-frame",D?"stream-physics-frame--mode-"+D:null,C?"stream-physics-frame--emphasis-"+C:null,x].filter(Boolean).join(" "),Pn=A??("string"==typeof we?we:void 0)??"Physics chart",Bn=vt+"-physics-table",jn=Math.max(1,zt[0]-Dt.left-Dt.right),Rn=Math.max(1,zt[1]-Dt.top-Dt.bottom),Tn=P&&qt?Ie?Ie(qt):pr(lr,{hover:qt}):null,Nn=Tn&&qt?pr(Re,{x:qt.x-Dt.left,y:qt.y-Dt.top,containerWidth:Math.max(1,zt[0]-Dt.left-Dt.right),containerHeight:Math.max(1,zt[1]-Dt.top-Dt.bottom),margin:Dt,className:"stream-physics-tooltip",children:Tn}):null;if(An){const e=ct.current??br(ft,j,R),t="string"==typeof we?we:void 0,{svg:n}=function(e,t={}){const{width:n=640,height:i=360,title:o,description:r,background:s,className:a,idPrefix:c="physics",...l}=t,d=Ui(e,l),u=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(c),h=o?u+"-title":void 0,p=r?u+"-desc":void 0,f=[h,p].filter(Boolean).join(" ")||void 0;return{svg:Hi.renderToStaticMarkup(Qi("svg",{xmlns:"http://www.w3.org/2000/svg",className:a??"stream-physics-frame",width:n,height:i,viewBox:`0 0 ${n} ${i}`,role:"img","aria-labelledby":f,children:[o&&Ki("title",{id:h,children:o}),r&&Ki("desc",{id:p,children:r}),s&&"transparent"!==s?Ki("rect",{x:0,y:0,width:n,height:i,fill:s}):null,Ki("g",{id:u+"-data-area",children:d.sceneNodes.map((e,t)=>ke(e,t,u))})]})),scene:d,evidence:d.evidence}}(e,{width:zt[0],height:zt[1],title:t,description:A,background:"transparent"===s?void 0:s,className:"stream-physics-frame__svg",idPrefix:"physics-"+vt});return fr("div",{ref:Nt,className:Dn,"data-semiotic-mode":D,role:"img","aria-label":Pn,style:{width:zt[0],height:zt[1]},children:[pr(Co,{summary:be}),pr("div",{dangerouslySetInnerHTML:{__html:n}})]})}return fr("div",{ref:Nt,className:Dn,"data-semiotic-mode":D,role:"group","aria-label":Pn,"aria-describedby":Ot?_t:void 0,tabIndex:0,style:{position:"relative",width:zt[0],height:zt[1]},onKeyDown:tn,children:[n?pr(Do,{tableId:Bn}):null,n?pr(hr,{chartTitle:"string"==typeof we?we:Pn,items:rt,tableId:Bn}):null,pr(Co,{summary:be}),pr(Po,{hoverPoint:qt}),pr("div",{id:_t,"aria-live":"polite","aria-atomic":"true",style:Xo,children:Ot?Ot.description??Ot.label:""}),fr("div",{role:"img","aria-label":Pn,style:{position:"relative",width:"100%",height:"100%"},children:[Rt,pr("canvas",{ref:mt,width:zt[0],height:zt[1],"aria-hidden":"true",onPointerDown:en,onPointerMove:P?Jt:void 0,onPointerLeave:P?Zt:void 0}),Tt,pr(xn,{width:jn,height:Rn,totalWidth:zt[0],totalHeight:zt[1],margin:Dt,title:we,legend:T,legendPosition:O,legendLayout:F,legendHoverBehavior:z,legendClickBehavior:N,legendHighlightedCategory:E,legendIsolatedCategories:W,pointNodes:nn,annotations:i,autoPlaceAnnotations:r,svgAnnotationRules:ve}),pr(xo,{active:null!=Ot,hoverPoint:Ot?{x:Ot.x,y:Ot.y}:null,margin:Dt,size:zt,shape:Ot?.shape,width:Ot?.width,height:Ot?.height,pathData:Ot?.pathData}),Nn]})]})}));wr.displayName="StreamPhysicsFrame";var kr=wr;function Mr(e){const[t,n]=e;return{width:t,height:n,plot:{x:32,y:24,width:Math.max(80,t-64),height:Math.max(80,n-58)}}}function Ir(e){const t=(e??"")+"";if(!t)return"#4e79a7";const n=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let e=0;t.length>e;e+=1)i=31*i+t.charCodeAt(e)>>>0;return n[i%n.length]}function Sr(e,t="#4e79a7"){return n=>{const i=n.datum,o=i&&e?"function"==typeof e?e(i,0):i[e]:void 0;return{fill:null==o?t:Ir(o),stroke:"#111827",strokeWidth:1,opacity:.9}}}function Ar(e,t,n,i){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,...i}}}function Cr(e,t,n){if(!e.length)return[];const i=Mr(t),o=i.plot.width/Math.max(1,e.length),r=Math.max(1,...e.map(e=>e.value)),s=.62*i.plot.height,a=i.plot.y+i.plot.height;return e.map((e,t)=>{const c=Math.max(8,e.value/r*s),l=`${n} ${e.label}: ${e.value}${null==e.secondary?"":`, ${e.secondary} secondary`}`;return{id:`${n}-${e.label}`,label:l,description:l,datum:e,x:i.plot.x+(t+.5)*o,y:a-c/2,shape:"rect",width:Math.max(12,.58*o),height:c,group:n}})}function Dr(e,t,n){return"function"==typeof n?n(e,t):e[n]}function Pr(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 $r(e,t,n){return Math.max(t,Math.min(n,e))}function Br(e,t){const n=Pr(e);return null!=n&&n>0?n:t}function jr(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Rr(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}}import{scaleLinear as Tr}from"d3-scale";function Nr(e){const{data:t,valueAccessor:n,bins:i,ballRadius:o,seed:r,size:s,valueExtent:a}=e,c=Mr(s),l=t.map((e,t)=>Pr(Dr(e,t,n))).filter(e=>null!=e),d=function(e){if(!e)return;const t=Pr(e[0]),n=Pr(e[1]);return null!=t&&null!=n?t>n?[n,t]:[t,n]:void 0}(a),u=d?.[0]??(l.length?Math.min(...l):0),h=d?.[1]??(l.length?Math.max(...l):1),p=h===u?1:h-u,f=Tr().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:i},()=>0),y=[];t.forEach((e,t)=>{const r=Pr(Dr(e,t,n));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-u)/p*i)));m[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:f(s+.5),y:c.plot.y+o+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,value:r,bin:s}})});const g=c.plot.y+c.plot.height;return{config:Ar(r,[...Di({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Pi({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:f,yTop:c.plot.y-400,yBottom:g,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[u,h]}}}import{scaleLinear as Er}from"d3-scale";function zr(e){const{count:t,idPrefix:n,wallThickness:i,xScale:o,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const c=Math.min(r-1,a?.(t)??s),l=Math.max(1,r-c);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:o(t),y:c+l/2,width:i,height:l}}})}function Wr(e){const{data:t,timeAccessor:n,arrivalAccessor:i,windows:o,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:d=1}=e,u=Mr(c),h=t.map((e,t)=>Pr(Dr(e,t,n))).filter(e=>null!=e),p=Pr(l?.[0]),f=Pr(l?.[1]),m=h.length?Math.min(...h):0,y=h.length?Math.max(...h):m+o.size,g=Math.min(p??m,m),b=Math.max(f??y,y),x=Math.floor(g/o.size)*o.size,v=Math.max(1,Math.ceil((b-x+o.size)/o.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Pr(r?.value)??w-(r?.delay??o.size),M=Math.max(0,Math.min(v,Array.from({length:v},(e,t)=>t).reduce((e,t)=>x+(t+1)*o.size>k?e:e+1,0))),I=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}}(u,s),S=x+v*o.size,A=Er().domain([x,S]).range([I.windowPlot.x,I.windowPlot.x+I.windowPlot.width]),C=Array.from({length:v},()=>({value:0,secondary:0})),D=[];t.forEach((e,t)=>{const r=Pr(Dr(e,t,n));if(null==r)return;const a=Pr(Dr(e,t,i))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-x)/o.size))),l=k>=x+(c+1)*o.size;C[c].value+=l?0:1,C[c].secondary+=l?1:0,D.push({id:(e.id??"event-"+t)+"",x:Math.max(I.windowPlot.x+s,Math.min(I.windowPlot.x+I.windowPlot.width-s,A(r))),y:u.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:c,late:l}})});const P=u.plot.y+u.plot.height,$=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const i=e.windowStart,o=e.windowStart+e.windowCount*e.windowSize,r=Er().domain([i,o]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+n*e.windowSize),a=e.windowPlot.x,c=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),l=e=>s===a?t:c+(e-a)/(s-a)*(t-c),d=[];for(let t=0;n>t;t+=1){const n=e.windowStart+t*e.windowSize,i=n+e.windowSize,o=r(n),s=r(i);d.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:o,y1:l(o),x2:s,y2:l(s)})}return d}({closedWindowCount:M,gutter:I.gutter,plot:u.plot,windowCount:v,windowPlot:I.windowPlot,windowSize:o.size,windowStart:x},u.plot.y+.28*u.plot.height);return{config:Ar(a,[...Di({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...zr({idPrefix:"eventdrop-window",count:v,xScale:e=>A(x+e*o.size),yTop:I.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>M)return null;const t=0===e?$[0]?.y1:$[e-1]?.y2??$[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?I.wallTop:t+1.25*s},yBottom:P,wallThickness:6}),...$.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:D,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:d},projectionRows:C.map((e,t)=>({label:`${x+t*o.size}-${x+(t+1)*o.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:I.gutter,lidSegments:$,lateCount:C.reduce((e,t)=>e+t.secondary,0),plot:u.plot,windowPlot:I.windowPlot,watermarkValue:k,windowCount:v,windowSize:o.size,windowStart:x}}}function Fr(e,t,n){const i=e.width/Math.max(1,t),o=Math.max(2,2*n),r=Math.min(.7*i,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(r/o));return{laneWidth:i,tubeWidth:r,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*i,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}function Or(e){const{data:t,categoryAccessor:n,valueAccessor:i,unitValue:o,ballRadius:r,seed:s,size:a}=e,c=Br(o,1),l=Mr(a),d=[],u=new Map,h=new Map,p=[];function f(e){let t=u.get(e);return null==t&&(t=d.length,d.push(e),u.set(e,t)),t}t.forEach((e,t)=>{f((Dr(e,t,n)??"unknown")+"")});const m=Math.max(1,d.length),y=Fr(l.plot,m,r),g=Math.max(0,y.tubeWidth/2-r-1),b=d.map(()=>[]);t.forEach((e,t)=>{const o=(Dr(e,t,n)??"unknown")+"",s=f(o),a=i?Pr(Dr(e,t,i)):1,d=Math.max(0,Math.round((a??0)/c)),u=y.centerX(s);for(let n=0;d>n;n+=1){const i=h.get(o)??0,a=y.perRow>1?((y.perRow>1?i%y.perRow:0)/(y.perRow-1)*2-1)*g:0;h.set(o,i+1),b[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:u+a,y:l.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:o,unitIndex:n}})}});const x=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;x>e;e+=1)for(const t of b)t.length>e&&p.push(t[e]);const v=l.plot.y+l.plot.height,w=[...Di({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 e=0;m>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:Ar(s,w,"PhysicsPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:h.get(e)??0}))}}import{scaleLinear as Lr}from"d3-scale";function qr(e){const{data:t,xAccessor:n,groupAccessor:i,radiusAccessor:o,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:d}=e,u=Mr(a),h=Rr(s),p=[],f=[],m=new Map;t.forEach((e,t)=>{const s=Pr(Dr(e,t,n));if(null==s)return;const a=i?(Dr(e,t,i)??"All")+"":"All",c=o?Pr(Dr(e,t,o)):null,l=$r(null!=c&&c>0?c:r,2,18);!function(e){let t=m.get(e);null==t&&(t=f.length,f.push(e),m.set(e,t))}(a),p.push({datum:e,index:t,value:s,group:a,radius:l})});const y=p.map(e=>e.value),g=c?Pr(c[0]):null,b=c?Pr(c[1]):null,x=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=g??x,k=b??v;if(w===k&&(w-=.5,k+=.5),w>k){const e=k;k=w,w=e}const M=Math.max(r,...p.map(e=>e.radius)),I=u.plot.x+M+8,S=u.plot.x+u.plot.width-M-8,A=Lr().domain([w,k]).range([I,S]),C=Math.max(1,f.length),D=u.plot.y+Math.max(28,3*M),P=Math.max(0,u.plot.y+u.plot.height-Math.max(28,3*M)-D),$=e=>{const t=m.get(e)??0;return 1===C?u.plot.y+.54*u.plot.height:D+t/(C-1)*P},B=new Map,j=p.map((e,t)=>{B.set(e.group,(B.get(e.group)??0)+1);const n=A(e.value),i=$(e.group),o=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:d?n+o:$r(n+(t%9-4)*e.radius*2.5,I,S),y:d?i+r:u.plot.y-18-t%12*e.radius,vx:d?0:22*(h()-.5),vy:d?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:i},springs:[{target:{type:"point",x:n,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:Ar(s,Di({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*M),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:j,projectionRows:f.map(e=>({label:e,value:B.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[I,S],groups:f.map(e=>({label:e,y:$(e),count:B.get(e)??0})),plot:u.plot}}}function Yr(e){if(Array.isArray(e)&&e.length>=2){const t=Pr(e[0]),n=Pr(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=Pr(t.x),i=Pr(t.y);return null!=n&&null!=i?{x:n,y:i}:null}return null}function Hr(e){return Array.isArray(e)?e.map(Yr).filter(e=>null!=e):[]}function Xr(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:$r(e.x,t.plot.x,t.plot.x+t.plot.width),y:$r(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Gr(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 _r(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=$r(t,0,1)*Gr(e);let i=0;for(let t=1;e.length>t;t+=1){const o=e[t-1],r=e[t],s=Math.hypot(r.x-o.x,r.y-o.y);if(s>0){if(i+s>=n){const e=(n-i)/s;return{x:o.x+(r.x-o.x)*e,y:o.y+(r.y-o.y)*e}}i+=s}}return{...e[e.length-1]}}function Vr(e,t){const n=_r(e,Math.max(0,t-.02)),i=_r(e,Math.min(1,t+.02)),o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{x:o/s,y:r/s}}function Ur(e){const{coordinateMode:t,flowSpeed:n,links:i,maxParticles:o,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:d,pathAccessor:u,pathConstraint:h="path",reducedMotion:p,seed:f,size:m,sourceAccessor:y,targetAccessor:g,throughputAccessor:b}=e,x=Mr(m),v=Rr(f),w=new Map,k=new Map,M=[];function I(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")+""}c.forEach((e,t)=>{const n=(Dr(e,t,r)??e.id??t)+"",i=Pr(Dr(e,t,s)),o=Pr(Dr(e,t,a));if(null!=i&&null!=o){const e={x:i,y:o};w.set(n,e),M.push(e)}k.set(n,(e.label??e.name??n)+"")});const S=[];i.forEach((e,t)=>{const n=I(Dr(e,t,y)),i=I(Dr(e,t,g)),o=Math.max(0,Pr(Dr(e,t,b))??0),r=Hr(u?Dr(e,t,u):void 0),s=r.length?r:Hr(e.path??e.points??e.route);s.forEach(e=>M.push(e)),S.push({id:(e.id??`physical-flow-${n}-${i}-${t}`)+"",link:e,index:t,source:n,target:i,throughput:o,rawPath:s})});const A=(D=M,"normalized"===(C=t)||"pixels"===C?C:D.length>0&&D.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var C,D;const P=new Map;for(const[e,t]of w)P.set(e,Xr(t,x,A));const $=[];for(const e of S){let t=e.rawPath.map(e=>Xr(e,x,A));if(2>t.length){const n=P.get(e.source),i=P.get(e.target);n&&i&&(t=[n,i])}else P.has(e.source)||P.set(e.source,t[0]),P.has(e.target)||P.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),$.push({...e,path:t,packetCount:0}))}const B=Br(d,.12),j=Math.max(1,Math.round(o)),R=$.map(e=>Math.max(1,Math.round(e.throughput*B))),T=R.reduce((e,t)=>e+t,0),N=T>j?j/T:1;$.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(R[t]*N))});let E=$.reduce((e,t)=>e+t.packetCount,0);for(;E>j;){const e=$.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>$[e].packetCount)?n:e,-1);if(-1===e)break;$[e].packetCount-=1,E-=1}const z=new Map,W=new Map,F=[],O=Br(n,90),L=Br(l,4);$.forEach((e,t)=>{z.set(e.target,(z.get(e.target)??0)+e.throughput),W.set(e.source,(W.get(e.source)??0)+e.throughput);const n=Gr(e.path);for(let i=0;e.packetCount>i;i+=1){const o=(i+.5)/e.packetCount,r=p?o:$r(.12+.84*o+.04*(v()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*v())),a=_r(e.path,s),c=_r(e.path,r),l=Vr(e.path,s),d={x:-l.y,y:l.x},u=(v()-.5)*L*1.5;F.push({id:`${e.id}-packet-${i}`,x:a.x+d.x*u,y:a.y+d.y*u,vx:p?0:l.x*O+10*(v()-.5),vy:p?0:l.y*O+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+i/32,shape:{type:"circle",radius:L},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:i,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:O,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*L,stiffness:26,damping:4.25}]:void 0})}});const q=Math.max(18,5*L),Y=Array.from(P,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:"physical-flow-node-"+jr(e),point:t})),H=Y.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:q,height:q}})),X=Object.fromEntries(Y.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=Ar(f,[...Di({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...H],"PhysicalFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*L),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=j,G.eviction="oldest",G.observation={...G.observation,sensors:X};const _=Array.from(P,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+jr(e),incoming:z.get(e)??0,outgoing:W.get(e)??0})),V=$.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:G,initialSpawns:F,projectionRows:_.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:A,particleCount:F.length,totalThroughput:$.reduce((e,t)=>e+t.throughput,0),plot:x.plot,nodes:_,links:V}}}function Kr(e,t){if("region-enter"!==t.type)return e;const n=t.region.id,i=e[n]??{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;const o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function Qr(e,t){return(t??Object.keys(e)).map(t=>e[t]).filter(e=>null!=e).map(e=>({label:e.label??e.id,value:e.count}))}function Zr(e,t){const n=t instanceof Set?t:new Set(t);return e.map(e=>{const t=e.bodyIds??[],i=t.filter(e=>!n.has(e)),o=t.length-i.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},c=t.reduce((e,t)=>e+a(t),0),l=t.reduce((e,t)=>e+(n.has(t)?a(t):0),0),d=e.completion?.threshold,u="threshold"===r?Number.isFinite(d)&&Number(d)>=0?Number(d):c:void 0;return{id:e.id,label:e.label??e.id,mode:r,complete:t.length>0&&("anyAbsorbed"===r?o>0:"threshold"===r?l>=(u??c):0===i.length),absorbed:o,total:t.length,absorbedValue:l,totalValue:c,threshold:u,missing:i}})}function Jr(e,t,n){return Math.max(t,Math.min(n,e))}function es(e,t,n={}){const i=n.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],r=Jr(n.along??.5,.05,.95),s=n.jitterX??0,a=n.padY??20,c=o.x0+(o.x1-o.x0)*r+(2*i()-1)*s,l=Math.min(1,o.width/2),d=Jr(c,o.x0+l,o.x1-l),u=e.boundaryY(d,"top")+a,h=e.boundaryY(d,"bottom")-a;return{x:d,y:h>u?u+i()*Math.max(1,h-u):e.midY}}function ts(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function ns(e,t,n){return Math.max(t,Math.min(n,e))}function is(e,t,n,i,o,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:i,y2:o,thickness:r.thickness??8}}}function os(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height)),o=e.padX??46,r=e.padY??72,s=o,a=n-o,c=r,l=i-Math.max(24,Math.round(.45*r)),d=(c+l)/2,u=Math.max(1,l-c),h=ns(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,m=ns(u*h+f,.06*u,.5*u),y=m/2,g=d-y,b=d+y,x=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,M=e.stages;if(!M.length)throw Error("processStageLayout requires at least one stage");const I=ns(e.centerStageIndex??Math.floor(M.length/2),0,M.length-1),S=function(e){const t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(M),A=a-s;let C=s;const D=M.map((e,t)=>{const n=C,i=t===M.length-1?a:C+(e.share??1)/S*A;return C=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:i,x:(n+i)/2,width:i-n,y:d,height:u}}),P=D[I],$=P.x0,B=P.x1,j=(e,n)=>{if("lane"===t)return"top"===n?c:l;if("funnel"===t){const t=ns((e-s)/Math.max(1,a-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if($>=e){const t=ns((e-s)/Math.max(1,$-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if(B>=e)return"top"===n?g:b;const i=ns((e-B)/Math.max(1,a-B),0,1);return"top"===n?g+(c-g)*i:b+(l-b)*i},R=D.map(e=>{const t=Math.min(j(e.x0,"top"),j(e.x1,"top")),n=Math.max(j(e.x0,"bottom"),j(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),T={thickness:k,friction:v,restitution:w},N=[];"lane"===t?N.push(is(x+"-top",s,c,a,c,T),is(x+"-bottom",s,l,a,l,T),is(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),is(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)})):"funnel"===t?N.push(is(x+"-top",s,c,a,g,T),is(x+"-bottom",s,l,a,b,T),is(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),is(x+"-right",a,g,a,b,{...T,thickness:Math.max(6,k)})):N.push(is(x+"-left-top",s,c,$,g,T),is(x+"-left-bottom",s,l,$,b,T),is(x+"-center-top",$,g,B,g,T),is(x+"-center-bottom",$,b,B,b,T),is(x+"-right-top",B,g,a,c,T),is(x+"-right-bottom",B,b,a,l,T),is(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),is(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)}));const E=e.membraneDampingScale??.5,z=s,W=Math.max(1,("bowtie"===t?$:a)-z),F=(e.membranes??[]).map(e=>{const t=z+ns(e.offset,0,1)*W,n=e.width??18+18*e.cost,i=u-16,o=d+.25*(e.wobble??0);return{...e,x:t,y:o,width:n,height:i}}),O=!1===e.includeMembraneRegions?[]:F.map(e=>as({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??E,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:i,padX:o,padY:r,left:s,right:a,topY:c,bottomY:l,midY:d,centerLeft:$,centerRight:B,pinchHeight:m,pinchTop:g,pinchBottom:b,stages:R,membranes:F,colliders:N,regionEffects:O,boundaryY:j}}function rs(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,i=e.width,o=e.height,{type:"aabb",x:t,y:n,width:i,height:o}),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,i,o}function ss(e,t={}){const n=t.idPrefix??"stage",i=Math.max(0,t.insetX??0),o=Math.max(0,t.insetY??1);return e.stages.map(e=>{const r="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...rs({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*i),height:Math.max(1,e.height-2*o),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...r,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function as(e){const t=e.dampingScale??.5,n=e.energyScale??1,i=ns(e.cost,0,2);return{...rs({...e,kind:e.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:i*t,energyDelta:-i*n}}function cs(e){return{...rs({...e,kind:e.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function ls(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...rs({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function ds(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,i=e.dampingPerUnit??.12,o=e.energyPerUnit??0;return{...rs({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*i,energyDelta:o?-t*o:void 0,force:e.force}}function us(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...rs({...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}}function hs(e){return{...rs({...e,kind:e.kind??"force-field",attributes:{primitive:"portal",targetStage:e.targetStage,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function ps(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...rs({...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"}}function fs(e){return{...rs({...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}}function ms(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}}function ys(e){const t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},i=[is(t+"-top",e.left,e.top,e.right,e.top,n),is(t+"-bottom",e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||i.push(is(t+"-left",e.left,e.top,e.left,e.bottom,n),is(t+"-right",e.right,e.top,e.right,e.bottom,n)),i}function gs(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 bs(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,i=Mr(n),o=$r(e.ballRadius??6,2,18),r=e.seed??1,s=Rr(r),a=e.idAccessor,c=e.stageAccessor??"stage",l=e.groupBy,d=e.groupLabelAccessor,u=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(l?"allAbsorbed":"none"),f=e.springStiffness??.28,m=e.springDamping??.72,y=!0===e.settle,g=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),b=os({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:g,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),x=new Map(b.stages.map((e,t)=>[e.id,t])),v=new Map(b.stages.map(e=>[e.id,e])),w=b.stages[0].id,k=b.stages[0],M=new Set(t.filter(e=>e.absorb).map(e=>e.id)),I=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 ps({...n,kind:e.kind??"sink",force:gs(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 hs({...n,kind:e.kind??"force-field",force:gs(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return us({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:gs(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 ds({...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:gs(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?ls({...n,kind:e.kind??"force-field",force:gs(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):fs({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:b.midY,width:t.width,height:b.bottomY-b.topY})});I.unshift(ls({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const S=new Map;for(const e of b.stages)S.set(e.id,0);const A=[];e.data.forEach((e,t)=>{const n=(a?Dr(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",i=(Dr(e,t,c)??w)+"",r=x.has(i)?i:w;S.set(r,(S.get(r)??0)+1);const s=l?(Dr(e,t,l)??"")+"":void 0,p=s&&d?(Dr(e,t,d)??s)+"":s,f=u?Pr(Dr(e,t,u))??1:1,m=h?Pr(Dr(e,t,h)):null,y=$r(null!=m&&m>0?m:o,2,18);A.push({datum:e,id:n,stageId:r,groupId:s||void 0,groupLabel:p||void 0,work:f,radius:y,index:t})});const C=new Map,D=new Map;for(const e of A){if(!e.groupId)continue;const t=C.get(e.groupId)??[];t.push(e.id),C.set(e.groupId,t),e.groupLabel&&D.set(e.groupId,e.groupLabel)}const P=$r(e.groupAnchorAlong??.55,.15,.9),$=b.left+(b.right-b.left)*P,B=Array.from(C.keys()),j=B.map((e,n)=>{const i=C.get(e)??[],o=B.length>1?b.topY+28+n/Math.max(1,B.length-1)*(b.bottomY-b.topY-56):b.midY;return ms({id:e,label:D.get(e)??e,bodyIds:i,anchor:{x:$,y:o},x:$,y:o,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),R=Zr(j,A.filter(e=>M.has(e.stageId)).map(e=>e.id)),T=new Map(j.map(e=>[e.id,e])),N=A.map((e,t)=>{const n=v.get(e.stageId)??k,i=n.x+(s()-.5)*Math.min(24,.2*n.width),o=b.boundaryY(i,"top")+e.radius+10,r=b.boundaryY(i,"bottom")-e.radius-10,a=r>o?o+s()*Math.max(1,r-o):b.midY,c=y?i:b.left+18+t%7*4,l=y?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,d=[{target:{type:"point",x:i,y:a},restLength:.45*e.radius,stiffness:f,damping:m}];if(e.groupId){const t=T.get(e.groupId);t?.anchor&&!M.has(e.stageId)&&d.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:c,y:l,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:d,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),E={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:b.colliders,fixedDt:1/60,maxSubsteps:8},z=b.stages.map(e=>({label:e.label??e.id,value:S.get(e.id)??0})),W=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:S.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:E,initialSpawns:N,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:z,metadata:{kind:"process-flow",plot:i.plot,volume:b,stages:W,groups:j,groupCompletion:R,regionEffects:I}}}import{useImperativeHandle as xs,useRef as vs}from"react";function ws(e,t){if(!t?.length)return[e];const n=t.filter(t=>{if(t.id===e||t.id.startsWith(e+"-"))return!0;const n=t.datum;return!(!n||"object"!=typeof n||null==n.id)&&n.id+""===e}).map(e=>e.id);return n.length?n:[e]}function ks(e,t,n){if("function"==typeof n)return n(e,t)+"";if("string"==typeof n){const t=e[n];if(null!=t)return t+""}return null!=e&&"object"==typeof e&&"id"in e&&null!=e.id?e.id+"":"physics-row-"+t}function Ms(e,t){const n=e?.getData().find(e=>e.id===t),i=n?.datum;if(i&&"object"==typeof i)return i}function Is(e,t){const{frameRef:n,spawnDatum:i,seedRows:o,idAccessor:r,bodyIdsForSeed:s,seedSpawns:a}=t,c=vs(new Map),l=vs(new Map),d=vs(""),u=o?o.map((e,t)=>ks(e,t,r)).join("\0"):"";if(u!==d.current&&(d.current=u,o))for(let e=0;o.length>e;e+=1){const t=o[e],n=ks(t,e,r);c.current.set(n,t),l.current.set(n,s?.(t,n,e)??ws(n,a))}xs(e,()=>{const e=c.current,t=l.current;function o(e,t){const n=i(e,t);return{datumId:n.datumId||ks(e,t,r),spawns:n.spawns.map(e=>({...e,spawnAt:void 0}))}}function s(i){const o=[];for(const{datum:n,result:r}of i)e.set(r.datumId,n),t.set(r.datumId,r.spawns.map(e=>e.id)),o.push(...r.spawns);if(!o.length)return;const r=n.current;r?(r.pushMany(o),r.step(0)):"production"!==process.env.NODE_ENV&&console.warn("[semiotic/physics] push() called before the physics frame mounted (loading/empty early-return). Omit data for push mode and ensure the chart is mounted.")}function a(i){const o=e.get(i);if(o)return o;const r=t.get(i)??[i];for(const o of r){const r=Ms(n.current,o);if(r)return e.set(i,r),t.has(i)||t.set(i,[o]),r}}return{push:t=>{s([{datum:t,result:o(t,e.size)}])},pushMany:t=>{const n=e.size;s(t.map((e,t)=>({datum:e,result:o(e,n+t)})))},remove:i=>{const o=Array.isArray(i)?i:[i],r=[],s=[];for(const n of o){const i=a(n);i&&r.push(i),e.delete(n),s.push(...t.get(n)??[n]),t.delete(n)}return s.length&&n.current?.remove(s),r},update:(i,r)=>{const c=Array.isArray(i)?i:[i],l=[];for(const i of c){const c=a(i);if(!c)continue;l.push(c);const d=t.get(i)??[i];n.current?.remove(d),e.delete(i),t.delete(i);const u=r(c);s([{datum:u,result:o(u,e.size)}])}return l},clear:()=>{e.clear(),t.clear(),d.current="",n.current?.clear()},getData:()=>{const t=n.current;if(!t)return Array.from(e.values());const i=t.getData().map(e=>e.datum).filter(e=>!!e&&"object"==typeof e);return i.length?i:Array.from(e.values())},getScales:()=>null,getCustomLayout:()=>n.current?.snapshot()??null,popBodies:(e,t)=>n.current?.popBodies(e,t)??[]}},[s,n,r,i])}import{useMemo as Ss}from"react";import*as As from"react";import{jsx as Cs,jsxs as Ds}from"react/jsx-runtime";function Ps({componentName:e,message:t,diagnosticHint:n,width:i,height:o}){return Cs("div",{role:"alert",style:{width:i,height:Math.max(o,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:Ds("div",{style:{textAlign:"center",maxWidth:400},children:[Cs("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:e}),Cs("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:t}),n&&Cs("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:n})]})})}import{jsx as $s}from"react/jsx-runtime";var Bs=class extends As.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:$s(Ps,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}};import{jsx as js}from"react/jsx-runtime";function Rs({componentName:e,width:t,height:n,children:i}){return js(Bs,{fallback:i=>js(Ps,{componentName:e,message:i.message,width:t,height:n}),children:i})}"undefined"!=typeof process&&process;var Ts={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"},Ns={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};import{useMemo as Es,useCallback as zs,useState as Ws,useId as Fs,useEffect as Os,useRef as Ls}from"react";import{scaleOrdinal as qs}from"d3-scale";function Ys(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function Hs(e,t,n){const i=e=>e.toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(n)}`}function Xs(e){const t=e.map(Ys),n=t.length-1;return e=>{if(0>=e){const[e,n,i]=t[0];return Hs(e,n,i)}if(e>=1){const[e,i,o]=t[n];return Hs(e,i,o)}const i=e*n,o=Math.floor(i),r=i-o,[s,a,c]=t[o],[l,d,u]=t[o+1];return Hs(Math.round(s+(l-s)*r),Math.round(a+(d-a)*r),Math.round(c+(u-c)*r))}}var Gs=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],_s=Xs(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),Vs=Xs(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),Us=Xs(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Ks=Xs(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Qs=Xs(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),Zs=Xs(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Js={blues:_s,reds:Vs,greens:Us,viridis:Xs(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),oranges:Ks,purples:Qs,greys:Zs,plasma:Xs(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:Xs(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:Xs(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:Xs(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:Xs(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])},ea=(Xs(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),Xs(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),Xs(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Xs(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Xs(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Xs(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Xs(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),{category10:Gs,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...Js});function ta(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 na(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var ia={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function oa(e,t={}){const n=t.mobileSemantics?.interaction,i="number"==typeof n?.targetSize?n.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,o="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,r=!!n||void 0!==i,s=e&&"object"==typeof e?e:void 0;if(!1===e||!1===s?.enabled||void 0===e&&!o&&!r)return ia;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??i??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var ra={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 sa(e,t,n){if(!1!==t)return e;const i={...e};return"horizontal"===n?i.left=Math.min(i.left,15):i.bottom=Math.min(i.bottom,15),i}import{Fragment as aa,jsx as ca,jsxs as la}from"react/jsx-runtime";var da=new Set(["sample","mechanical"]);function ua(e,t,n){const i=n?.hasSimulationMode?function(e){const t=e=>"string"==typeof e&&da.has(e);return e.simulationMode?{chartMode:t(e.mode)?void 0:e.mode,simulationMode:e.simulationMode}:t(e.mode)?{chartMode:void 0,simulationMode:e.mode}:{chartMode:e.mode,simulationMode:"sample"}}({mode:e.mode,simulationMode:e.simulationMode}):{chartMode:"sample"===e.mode||"mechanical"===e.mode?void 0:e.mode,simulationMode:"sample"},o=function(e,t,n){const i=ra[e||"primary"],o=e&&"primary"!==e||!n?.width?i.width:n.width,r=e&&"primary"!==e||!n?.height?i.height:n.height,s=function(e,t,n=e.responsiveRules){if(!Array.isArray(n)||0===n.length)return{props:e,matches:[]};const i=n.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){const{when:n}=e,i=t.width,o=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>i||"number"==typeof n.maxWidth&&i>n.maxWidth||"number"==typeof n.minHeight&&("number"!=typeof o||n.minHeight>o)||"number"==typeof n.maxHeight&&("number"!=typeof o||o>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:i.reduce((e,t)=>function(e,t){const n={...e,...t};for(const i of["margin","frameProps","mobileSemantics","style"])na(e[i])&&na(t[i])&&(n[i]={...e[i],...t[i]});return"string"==typeof e.className&&"string"==typeof t.className&&(n.className=`${e.className} ${t.className}`),n}(e,t.rule.transform),e),matches:i}}({...t,mode:e},{width:t.width??o,height:t.height??r}).props,a=s.mode||e,c=ra[a||"primary"],l="context"===a||"sparkline"===a,d=a&&"primary"!==a||!n?.width?c.width:n.width;return{width:s.width??d,height:s.height??(a&&"primary"!==a||!n?.height?c.height:n.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:sa(c.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:l,mobileInteraction:oa(s.mobileInteraction,{mode:a,width:s.width??d,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}(i.chartMode,{width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:t[0],height:t[1]}),r=e.size?.[0],s=e.size?.[1],a=t[0],c=t[1],l=Ss(()=>{return e=[a,c],(null!=r&&null!=s?[r,s]:void 0)??[o.width??e[0],o.height??e[1]];var e},[c,a,o.height,o.width,s,r]),d=o.compactMode?"sparkline"===i.chartMode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0};const u=e.showProjection??!o.compactMode,h=e.showChrome??!o.compactMode,p=ma(e.tooltip,void 0),f=void 0!==p.enableHover?p.enableHover:o.enableHover,m=o.compactMode?o.title:o.title??e.title,y=[e.className,i.chartMode&&"primary"!==i.chartMode?"semiotic-physics--"+i.chartMode:null].filter(Boolean).join(" ")||void 0;return{chartMode:i.chartMode,simulationMode:i.simulationMode,resolved:o,chartSize:l,margin:d,showProjection:u,showChrome:h,enableHover:f,title:m,description:o.description??e.description,summary:o.summary??e.summary,accessibleTable:o.accessibleTable??e.accessibleTable,className:y,compactMode:o.compactMode,mobileInteraction:o.mobileInteraction,mobileSemantics:o.mobileSemantics}}function ha(e){const[t,n]=e.size,i=function(e,t,n,i){if(!e)return null;if(!1===i)return null;if(null!=i)return js("div",{style:{width:t,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:i});const o=Math.min(5,Math.floor(n/40)),r=Math.max(8,Math.floor(n/(3*o))),s=Math.max(6,Math.floor(n/(2.5*o))),a=Math.floor((n-(o*(r+s)-s))/2);return js("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:o},(e,n)=>js("div",{className:"semiotic-loading-bar",style:{...Ns,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))})}(e.loading,t,n,e.loadingContent);return i||function(e,t,n,i){return!1===i||null==e||Array.isArray(e)&&e.length>0?null:Array.isArray(e)?js("div",{style:{...Ts,width:t,height:n},children:i||"No data available"}):null}(e.data,t,n,e.emptyContent)}function pa(e,t,n){return ca(Rs,{componentName:e,width:t[0],height:t[1],children:n})}function fa(e,t){return e?t?n=>la(aa,{children:["function"==typeof e?e(n):e,"function"==typeof t?t(n):t]}):e:t}function ma(e,t){return!1===e?{enableHover:!1}:{enableHover:t?.enableHover,tooltipContent:Be(e)||t?.tooltipContent}}function ya(e,t,n,i){return{accessibleTable:i?.accessibleTable??e.accessibleTable??t?.accessibleTable,annotations:e.annotations??t?.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations??t?.autoPlaceAnnotations,background:e.background??t?.background,chartId:e.chartId??t?.chartId,chartMode:i?.chartMode??t?.chartMode,className:i?.className??e.className??t?.className,color:e.color??t?.color,description:i?.description??e.description??t?.description,emphasis:e.emphasis??t?.emphasis,enableHover:i?.enableHover??t?.enableHover,hoverRadius:e.hoverRadius??t?.hoverRadius,legend:e.legend??t?.legend,legendLayout:e.legendLayout??t?.legendLayout,legendPosition:e.legendPosition??t?.legendPosition,margin:i?.margin??t?.margin,onClick:null!=e.onClick?(t,n)=>{e.onClick?.(t,{x:n.x,y:n.y})}:t?.onClick,onObservation:e.onObservation??t?.onObservation,opacity:e.opacity??t?.opacity,semanticItems:t?.semanticItems??n,stroke:e.stroke??t?.stroke,strokeWidth:e.strokeWidth??t?.strokeWidth,summary:i?.summary??e.summary??t?.summary,svgAnnotationRules:e.svgAnnotationRules??t?.svgAnnotationRules,title:i?.title??e.title??t?.title}}import{Fragment as ga,jsx as ba,jsxs as xa}from"react/jsx-runtime";var va=e(function(e,o){const{data:r,valueAccessor:s="value",bins:a=21,ballRadius:c=6,colorBy:l,branchProbability:d=.5,emptyContent:u,frameProps:h,loading:p,loadingContent:f,mechanicalCount:m,paused:y,pegRows:g,referenceLines:b,responsiveHeight:x,responsiveWidth:v,seed:w=1,valueExtent:k}=e,M=ua(e,[700,420],{hasSimulationMode:!0}),{chartSize:I,simulationMode:S,showProjection:A,className:C,title:D,chartMode:P,margin:$,enableHover:B,description:j,summary:R,accessibleTable:T}=M,N=i(null),E=Math.max(1,Math.round(g??a-1)),z=n(()=>"mechanical"===S?[0,E]:function(e){if(!e)return;const t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?t>n?[n,t]:[t,n]:void 0}(k),[E,S,k]),W=n(()=>"mechanical"===S?function(e){const t=Math.max(2,Math.round(e.bins)),n=Math.max(1,Math.round(e.pegRows??t-1)),i=Math.max(1,Math.round(e.count??Math.max(64,4*t))),o=$r(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Rr(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:i},(e,t)=>{let i=0;for(let e=0;n>e;e+=1)r()<o&&(i+=1);const a=n/2;return{id:`${s}-${t}`,value:i,mechanical:!0,pegRows:n,branchProbability:o,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:a,branchProbability:d,count:m,pegRows:E,seed:w}):r??[],[a,d,r,m,E,w,S]),F=n(()=>Nr({data:W,valueAccessor:s,bins:a,ballRadius:c,seed:w,size:I,valueExtent:z}),[c,a,W,I,z,w,s]);Is(o,{frameRef:N,spawnDatum:t((e,t)=>{const n=Nr({data:[e],valueAccessor:s,bins:a,ballRadius:c,seed:w+t+1,size:I,valueExtent:z}).initialSpawns[0]??{id:(e.id??"galton-push-"+t)+"",x:Mr(I).plot.x,y:Mr(I).plot.y,mass:1,shape:{type:"circle",radius:c},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[c,a,I,z,w,s]),seedRows:W,seedSpawns:F.initialSpawns});const O="mechanical"===S&&null==l?"side":l,L=n(()=>Sr(O),[O]),q=n(()=>Cr(F.projectionRows,I,"bin"),[I,F.projectionRows]),Y=ha({data:"mechanical"===S?W:r,emptyContent:u,loading:p,loadingContent:f,size:I});if(Y)return Y;const H=function(e,t,n,i,o){const r=Array.isArray(o)?o:o?[o]:[];if(!1!==n||0!==r.length)return({size:o})=>{const s=[Number(o[0])||700,Number(o[1])||420],a=Mr(s),c=Math.max(2,Math.round(t)),l=a.plot.width/c,d=a.plot.y+a.plot.height,u=Math.max(1,...e.map(e=>e.value)),h=!1!==n,[p,f]=i?.valueExtent??[0,c],m=f===p?1:f-p,y=e.map((e,t)=>{const n=d-e.value/u*a.plot.height*.9;return`${0===t?"M":"L"} ${(a.plot.x+(t+.5)*l).toFixed(1)} ${n.toFixed(1)}`}).join(" ");return xa("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?xa(ga,{children:[Array.from({length:c+1},(e,t)=>{const n=a.plot.x+t*l;return ba("line",{"data-testid":"galton-board-bin-wall",x1:n,x2:n,y1:a.plot.y,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+t)}),ba("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ba("path",{d:y,fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>e.value>0?ba("text",{x:a.plot.x+(t+.5)*l,y:Math.max(a.plot.y+10,d-e.value/u*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`):null)]}):null,r.map((e,t)=>{const n=Number(e.value);if(!Number.isFinite(n))return null;const i=a.plot.x+Math.max(0,Math.min(1,(n-p)/m))*a.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===e.labelPosition?Math.min(s[1]-8,d+16):a.plot.y+16;return xa("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[ba("line",{x1:i,x2:i,y1:a.plot.y+8,y2:d-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:ba("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:r,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${n}`)})]})}}(F.projectionRows,a,A,F.metadata,b),X=ma(e.tooltip,h),G=ya(e,h,q,{chartMode:P,className:C,title:D,description:j,summary:R,accessibleTable:T,enableHover:B,margin:$});return pa("GaltonBoardChart",I,ba(kr,{...h,...X,...G,ref:N,config:F.config,foregroundGraphics:fa(H,h?.foregroundGraphics),initialSpawns:F.initialSpawns,initialSpawnPacing:F.initialSpawnPacing,paused:y,responsiveHeight:x,responsiveWidth:v,size:I,bodyStyle:L}))});import{forwardRef as wa,useCallback as ka,useMemo as Ma,useRef as Ia}from"react";import{jsx as Sa,jsxs as Aa}from"react/jsx-runtime";var Ca=wa(function(e,t){const{arrivalAccessor:n="arrivalTime",ballRadius:i=7,colorBy:o,data:r,emptyContent:s,frameProps:a,loading:c,loadingContent:l,paused:d,responsiveHeight:u,responsiveWidth:h,seed:p=1,timeAccessor:f="time",timeExtent:m,timeScale:y=1,watermark:g,windows:b={size:10}}=e,x=ua(e,[760,360]),{chartSize:v,showProjection:w,className:k,title:M,chartMode:I,margin:S,enableHover:A,description:C,summary:D,accessibleTable:P}=x,$=Ia(null),B=Ma(()=>r??[],[r]),j=Ma(()=>Wr({data:B,timeAccessor:f,arrivalAccessor:n,windows:b,watermark:g,ballRadius:i,seed:p,size:v,timeExtent:m,timeScale:y}),[n,i,v,B,p,f,m,y,g,b]),R=j.metadata;Is(t,{frameRef:$,spawnDatum:ka((e,t)=>{const o=R?function(e,t,n,i){const o=Pr(Dr(e,t,i.timeAccessor));if(null==o)return null;const r=Pr(Dr(e,t,i.arrivalAccessor))??o,{windowPlot:s,windowStart:a,windowCount:c,windowSize:l,watermarkValue:d}=n,u=a+c*l,h=Er().domain([a,u]).range([s.x,s.x+s.width]),p=Math.max(0,Math.min(c-1,Math.floor((o-a)/l))),f=d>=a+(p+1)*l,{ballRadius:m}=i;return{id:(e.id??"event-push-"+t)+"",x:Math.max(s.x+m,Math.min(s.x+s.width-m,h(o))),y:s.y+m+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,shape:{type:"circle",radius:m},datum:{...e,eventTime:o,arrivalTime:r,windowIndex:p,late:f}}}(e,t,R,{timeAccessor:f,arrivalAccessor:n,ballRadius:i}):null,r=o??{id:(e.id??"event-push-"+t)+"",x:Mr(v).plot.x,y:Mr(v).plot.y,mass:1,shape:{type:"circle",radius:i},datum:e};return{datumId:(e.id??r.id)+"",spawns:[r]}},[n,i,v,R,f]),seedRows:B,seedSpawns:j.initialSpawns});const T=Ma(()=>Sr(o),[o]),N=Ma(()=>function(e,t,n){if(!t)return Cr(e,n,"window");const i=t.windowPlot.width/Math.max(1,e.length),o=Math.max(1,...e.map(e=>e.value+(e.secondary??0))),r=.62*t.windowPlot.height,s=t.windowPlot.y+t.windowPlot.height;return e.map((e,n)=>{const a=Math.max(8,(e.value+(e.secondary??0))/o*r),c=`window ${e.label}: ${e.value} on time${e.secondary?`, ${e.secondary} late`:""}`;return{id:"window-"+e.label,label:c,description:c,datum:e,x:t.windowPlot.x+(n+.5)*i,y:s-a/2,shape:"rect",width:Math.max(12,.58*i),height:a,group:"window"}})}(j.projectionRows,R,v),[v,j.projectionRows,R]),E=ha({data:r,emptyContent:s,loading:c,loadingContent:l,size:v});if(E)return E;const z=function(e,t,n){if(!1!==n&&t)return({size:n})=>{const i=[Number(n[0])||760,Number(n[1])||360],o=Mr(i),r=Math.max(1,t.windowCount),s=t.plot??o.plot,a=t.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=t.windowPlot??s,l=c.width/r,d=s.y+s.height,u=s.y+.48*s.height,h=t.lidSegments[0]?.y1??u,p=t.windowStart,f=t.windowStart+r*t.windowSize,m=c.x+Math.max(0,Math.min(1,f===p?0:(t.watermarkValue-p)/(f-p)))*c.width;return Aa("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:[Sa("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?Aa("g",{children:[Sa("rect",{x:a.x,y:h,width:a.width,height:d-h,fill:"var(--semiotic-negative, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),Sa("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(n,o)=>{const r=e[o],s=c.x+o*l,a=t.closedWindowCount>o,h=r?.secondary??0;return Aa("g",{children:[Sa("rect",{x:s,y:u,width:l,height:d-u,fill:a?"var(--semiotic-negative, #e15759)":"var(--semiotic-accent, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?t.lidSegments.filter(e=>e.windowIndex===o).map(e=>Sa("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,Aa("text",{x:s+l/2,y:u-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),Sa("text",{x:s+l/2,y:Math.min(i[1]-8,d+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+o)}),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>Sa("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),Sa("line",{x1:s.x,x2:s.x+s.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),Sa("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:s.y+8,y2:d,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),Aa("text",{x:Math.min(s.x+s.width-4,m+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]}),t.lateCount>0?Aa("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]}):null]})}}(j.projectionRows,j.metadata,w),W=ma(e.tooltip,a),F=ya(e,a,N,{chartMode:I,className:k,title:M,description:C,summary:D,accessibleTable:P,enableHover:A,margin:S});return pa("EventDropChart",v,Sa(kr,{...a,...W,...F,ref:$,config:j.config,foregroundGraphics:fa(z,a?.foregroundGraphics),initialSpawns:j.initialSpawns,initialSpawnPacing:j.initialSpawnPacing,paused:d,responsiveHeight:u,responsiveWidth:h,size:v,bodyStyle:T}))});import{forwardRef as Da,useCallback as Pa,useMemo as $a,useRef as Ba}from"react";import{jsx as ja,jsxs as Ra}from"react/jsx-runtime";var Ta=Da(function(e,t){const{ballRadius:n=8,categoryAccessor:i="category",colorBy:o,data:r,emptyContent:s,frameProps:a,loading:c,loadingContent:l,mechanicalCategories:d,mechanicalCount:u,paused:h,responsiveHeight:p,responsiveWidth:f,seed:m=1,unitValue:y=1,valueAccessor:g}=e,b=ua(e,[700,380],{hasSimulationMode:!0}),{chartSize:x,simulationMode:v,showProjection:w,className:k,title:M,chartMode:I,margin:S,enableHover:A,description:C,summary:D,accessibleTable:P}=b,$=Ba(null),B="mechanical"===v&&null==g?"value":g,j=$a(()=>"mechanical"===v?function(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),n=t.length?t:["Intake"],i=Math.max(n.length,Math.round(e.count??Math.max(48,12*n.length))),o=Br(e.unitValue,1),r=Rr(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),c=a.reduce((e,t)=>e+t,0)||1,l=i-n.length,d=a.map(e=>e/c*l),u=d.map(e=>1+Math.floor(e));let h=i-u.reduce((e,t)=>e+t,0);const p=d.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)%p.length)u[p[e].index]+=1,h-=1;return n.map((e,t)=>({id:`${s}-${t}`,category:e,value:u[t]*o,mechanical:!0,unitCount:u[t],unitValue:o,share:u[t]/i}))}({categories:d,count:u,seed:m,unitValue:y}):r??[],[r,d,u,m,v,y]),R=$a(()=>Or({data:j,categoryAccessor:i,valueAccessor:B,unitValue:y,ballRadius:n,seed:m,size:x}),[n,i,x,j,B,m,y]);Is(t,{frameRef:$,spawnDatum:Pa((e,t)=>{const o=Or({data:[e],categoryAccessor:i,valueAccessor:B,unitValue:y,ballRadius:n,seed:m+t+1,size:x}),r={id:(e.id??"pile-push-"+t)+"",x:Mr(x).plot.x,y:Mr(x).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e},s=o.initialSpawns.length?o.initialSpawns:[r];return{datumId:(e.id??s[0].id)+"",spawns:s}},[n,i,x,B,m,y]),seedRows:j,seedSpawns:R.initialSpawns});const T="mechanical"===v&&null==o?"category":o,N=$a(()=>Sr(T),[T]),E=$a(()=>Cr(R.projectionRows,x,"category"),[x,R.projectionRows]),z=ha({data:"mechanical"===v?j:r,emptyContent:s,loading:c,loadingContent:l,size:x});if(z)return z;const W=function(e,t,n){if(!1!==n&&0!==e.length)return({size:n})=>{const i=[Number(n[0])||700,Number(n[1])||380],o=Mr(i),r=Fr(o.plot,e.length,t),s=o.plot.y+o.plot.height;return Ra("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:[ja("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{const n=Math.min(o.plot.height,r.pileHeight(e.value)),a=r.tubeWidth,c=r.centerX(t),l=s-n;return Ra("g",{children:[ja("rect",{x:c-a/2,y:l,width:a,height:n,rx:3,fill:"var(--semiotic-accent, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),ja("text",{x:c,y:Math.max(o.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),ja("text",{x:c,y:Math.min(i[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)})]})}}(R.projectionRows,n,w),F=ma(e.tooltip,a),O=ya(e,a,E,{chartMode:I,className:k,title:M,description:C,summary:D,accessibleTable:P,enableHover:A,margin:S});return pa("PhysicsPileChart",x,ja(kr,{...a,...F,...O,ref:$,config:R.config,foregroundGraphics:fa(W,a?.foregroundGraphics),initialSpawns:R.initialSpawns,initialSpawnPacing:R.initialSpawnPacing,paused:h,responsiveHeight:p,responsiveWidth:f,size:x,bodyStyle:N}))});import{forwardRef as Na,useCallback as Ea,useMemo as za,useRef as Wa}from"react";import{scaleLinear as Fa}from"d3-scale";function Oa(e,t){const n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>n&&ta(n,e)||"#4e79a7":t=>{if(n){const e=ta(n,t);if(e)return e}let i=0;for(let e=0;t.length>e;e++)i=31*i+t.charCodeAt(e)|0;return e[Math.abs(i)%e.length]??"#4e79a7"}}var La=Object.freeze([]);function qa(e){if(!e)return La;let t=!1;for(let n=0;e.length>n;n++){const i=e[n];if(null==i||"object"!=typeof i){t=!0;break}}if(!t)return e;const n=[];for(const t of e)null!=t&&"object"==typeof t&&n.push(t);return n}import{jsx as Ya}from"react/jsx-runtime";function Ha(e,t){const n=t.config??{},i=(t.sensors??[]).map(e=>({...e,sensor:!0})),o=[...t.colliders??[],...i],r=[...e.colliders??[],...n.colliders??[],...o];return{...e,...n,observation:{...e.observation,...n.observation},...r.length>0&&{colliders:r}}}function Xa(e){const t=function(e,t,n){const i=e?.observation;return{...e,observation:{...i,chartId:t??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:n??i?.onObservation}}}(e.config,e.chartId,e.onObservation),n=function(e,t,n){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=ea[e];if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:n}(e.colorScheme,e.themeCategorical,Gs),i=Mr(e.size),o={data:e.data,scales:{x:Fa().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:Fa().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Oa(n,e.colorScheme),config:e.layoutConfig??{},world:new Yi(t)},r=e.skipLayout?{}:e.layout(o)??{},s=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...i}=e,o=n.get(t)??[];o.push(i),n.set(t,o)}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:Ha(t,r),context:o,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}var Ga=Na(function(e,t){const{chartId:n,color:i,colorBy:o,colorScheme:r,config:s,controllers:a,data:c,emptyContent:l,frameProps:d={},layout:u,layoutConfig:h,loading:p,loadingContent:f,onObservation:m,opacity:y,paused:g,spawnDatum:b,stroke:x,strokeWidth:v,title:w,xExtent:k,yExtent:M}=e,I=ua(e,[700,380]),{chartSize:S,className:A,title:C,chartMode:P,margin:$,enableHover:B,description:j,summary:T,accessibleTable:N}=I,E=Wa(null),z=Wa(null),W=Wa(""),F=ha({data:c,emptyContent:l,loading:p,loadingContent:f,size:S}),O=null!=F,L=za(()=>qa(c??[]),[c]),q=R(e=>e.theme),Y=za(()=>function(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}}(q)??{},[q]),H=q?.colors?.categorical??D.colors.categorical,X=za(()=>[S[0],S[1],L.length,L.map((e,t)=>(e.id??t)+"").join("|"),k?.join(",")??"",M?.join(",")??""].join("::"),[S,L,k,M]),G=za(()=>Xa({chartId:n,colorScheme:r,config:s,data:L,layout:u,layoutConfig:h,onObservation:m,semantic:Y,skipLayout:O,size:S,themeCategorical:H,xExtent:k,yExtent:M}),[n,S,r,s,u,h,m,L,Y,O,H,k,M]);W.current===X&&null!=z.current||(W.current=X,z.current=G.initialSpawns);const _=z.current,V=za(()=>{const e=[...G.result.controllers??[],...a??[],...d.controllers??[]];return e.length?e:void 0},[d.controllers,a,G.result.controllers]),U=za(()=>{const e=[...G.result.regionEffects??[],...d.regionEffects??[]];return e.length?e:void 0},[d.regionEffects,G.result.regionEffects]),K=Ea(e=>{const t=e.datum,n=t&&o?function(e,t,n){return"function"==typeof n?n(e,0):e[n]}(t,0,o)+"":e.id;return{fill:i??G.context.resolveColor(n,t),stroke:x??"#111827",strokeWidth:v??1,opacity:y??.9}},[i,o,y,G.context,x,v]);Is(t,{frameRef:E,spawnDatum:Ea((e,t)=>{const i=e;if(b)return function(e,t,n){return Array.isArray(n)?{datumId:(e.id??n[0]?.id??"physics-custom-"+t)+"",spawns:n}:"spawns"in n?n:{datumId:(e.id??n.id??"physics-custom-"+t)+"",spawns:[n]}}(e,t,b(i,t,G.context));const o=Xa({chartId:n,colorScheme:r,config:s,data:[i],layout:u,layoutConfig:h,onObservation:m,semantic:Y,size:S,themeCategorical:H,xExtent:k,yExtent:M}),a=o.initialSpawns.length?o.initialSpawns:[{id:(e.id??"physics-custom-"+t)+"",x:o.context.dimensions.plot.x+o.context.dimensions.plot.width/2,y:o.context.dimensions.plot.y+12,mass:1,shape:{type:"circle",radius:5},datum:e}];return{datumId:(e.id??a[0].id)+"",spawns:a}},[n,S,r,s,b,u,h,m,G.context,Y,H,k,M]),seedRows:L,seedSpawns:_});const Q=Ea((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]);if(F)return F;const Z=ma(e.tooltip,d),J=ya(e,d,G.result.semanticItems,{chartMode:P,className:A,title:C??w,description:j,summary:T,accessibleTable:N,enableHover:B,margin:$});return pa("PhysicsCustomChart",S,Ya(kr,{...d,...Z,...J,ref:E,backgroundGraphics:fa(d.backgroundGraphics,G.result.backgroundOverlays),bodyForces:G.result.bodyForces??d.bodyForces,bodyStyle:G.result.bodyStyle??d.bodyStyle??K,config:G.config,controllers:V,foregroundGraphics:fa(d.foregroundGraphics,G.result.overlays),initialSpawnPacing:G.initialSpawnPacing,initialSpawns:_,onBodyPointerDown:Q,paused:g,regionEffects:U,responsiveHeight:e.responsiveHeight,responsiveWidth:e.responsiveWidth,selectedBodyStyle:G.result.selectedBodyStyle??d.selectedBodyStyle,size:S}))});Ga.displayName="PhysicsCustomChart";import{forwardRef as _a,useCallback as Va,useMemo as Ua,useRef as Ka}from"react";import{jsx as Qa,jsxs as Za}from"react/jsx-runtime";function Ja(e){return e.toLocaleString(void 0,Math.abs(e)>=1e3||.01>Math.abs(e)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}var ec=_a(function(e,t){const{colorBy:n,collisionIterations:i,data:o,emptyContent:r,frameProps:s,groupAccessor:a,loading:c,loadingContent:l,paused:d,pointRadius:u=5,radiusAccessor:h,responsiveHeight:p,responsiveWidth:f,seed:m=1,settle:y,xAccessor:g="x",xExtent:b}=e,x=ua(e,[700,360]),{chartSize:v,showProjection:w,className:k,title:M,chartMode:I,margin:S,enableHover:A,description:C,summary:D,accessibleTable:P}=x,$=Ka(null),B=Ua(()=>o??[],[o]),j=Ua(()=>qr({data:B,xAccessor:g,groupAccessor:a,radiusAccessor:h,pointRadius:u,seed:m,size:v,xExtent:b,collisionIterations:i,settle:y}),[B,v,i,a,u,h,m,y,g,b]);Is(t,{frameRef:$,spawnDatum:Va((e,t)=>{const n=qr({data:[e],xAccessor:g,groupAccessor:a,radiusAccessor:h,pointRadius:u,seed:m+t+1,size:v,xExtent:b,collisionIterations:i,settle:y}).initialSpawns[0]??{id:(e.id??"collision-swarm-push-"+t)+"",x:Mr(v).plot.x,y:Mr(v).plot.y,mass:1,shape:{type:"circle",radius:u},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[v,i,a,u,h,m,y,g,b]),seedRows:B,seedSpawns:j.initialSpawns});const R=n??a,T=Ua(()=>Sr(R),[R]),N=ha({data:o,emptyContent:r,loading:c,loadingContent:l,size:v});if(N)return N;const E=function(e,t){if(!1!==t&&e)return({size:t})=>{const n=[Number(t[0])||700,Number(t[1])||360],i=Mr(n),o=i.plot.y+i.plot.height,[r,s]=e.xExtent,a=r+(s-r)/2,c=[{label:Ja(r),x:e.xRange[0]},{label:Ja(a),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:Ja(s),x:e.xRange[1]}];return Za("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.map(e=>Za("g",{children:[Qa("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),Qa("text",{x:i.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),Za("text",{x:i.plot.x+i.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count]})]},e.label)),Qa("line",{x1:e.xRange[0],x2:e.xRange[1],y1:o,y2:o,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(e=>Za("g",{children:[Qa("line",{x1:e.x,x2:e.x,y1:o,y2:o+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),Qa("text",{x:e.x,y:Math.min(n[1]-8,o+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}(j.metadata,w),z=function(e){if(!e)return[];const t=Math.max(24,e.xRange[1]-e.xRange[0]),n=e.xRange[0]+t/2;return e.groups.map(e=>{const i=`${e.label} lane: ${e.count} points`;return{id:"collision-swarm-"+e.label,label:i,description:i,datum:e,x:n,y:e.y,shape:"rect",width:t,height:28,group:"lane"}})}(j.metadata),W=ma(e.tooltip,s),F=ya(e,s,z,{chartMode:I,className:k,title:M,description:C,summary:D,accessibleTable:P,enableHover:A,margin:S});return pa("CollisionSwarmChart",v,Qa(kr,{...s,...W,...F,ref:$,config:j.config,foregroundGraphics:fa(E,s?.foregroundGraphics),initialSpawns:j.initialSpawns,paused:d,responsiveHeight:p,responsiveWidth:f,size:v,bodyStyle:T}))});function tc(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"}function nc(e,t,n){if(null!=e)return"function"==typeof e?e(t,n):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}function ic(e){const{data:t,encoding:n}=e,i=[],o=new Map;return t.forEach((e,t)=>{const r=nc(n.id,e,t);if(null==r||""===r)throw Error(`[semiotic] Motion encoding row ${t} resolved an empty id.`);const s=r+"";if(o.has(s))throw Error(`[semiotic] Duplicate motion encoding id "${s}".`);const a=nc(n.process?.group,e,t),c=nc(n.process?.stage,e,t),l=nc(n.accessible?.group,e,t)??(null!=a?a+"":null!=c?c+"":void 0),d={};for(const i of Object.keys(n.evidence??{}))d[i]=nc(n.evidence?.[i],e,t);const u={id:s,datum:e,time:{arrival:nc(n.time?.arrival,e,t),basis:n.time?.basis,unit:n.time?.unit},placement:{x:nc(n.placement?.x,e,t),y:nc(n.placement?.y,e,t),lane:nc(n.placement?.lane,e,t),space:n.placement?.space},kinematics:{velocityX:nc(n.kinematics?.velocityX,e,t),velocityY:nc(n.kinematics?.velocityY,e,t),space:n.kinematics?.space},process:{group:a,stage:c,target:nc(n.process?.target,e,t),work:nc(n.process?.work,e,t)},evidence:d,accessible:{description:nc(n.accessible?.description,e,t),group:l,label:nc(n.accessible?.label,e,t)??s}};i.push(u),o.set(s,u)}),{rows:i,byId:o}}function oc(e){const t=e.now-e.arrival;return{age:t,progress:Number.isFinite(t)&&Number.isFinite(e.ttl)&&e.ttl>0?Math.max(0,t)/e.ttl:t===1/0&&Number.isFinite(e.ttl)&&e.ttl>0?1/0:0,lifecycle:tc(t,e.ttl,e.thresholds)}}function rc(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 i=e.halfLife??e.extent/2;return t+Math.pow(.5,n/(i>0?i:e.extent/2))*(1-t)}return t+Math.max(0,Math.min(1,1-n/e.extent))*(1-t)}function sc(e,t){const n=Number.isFinite(e)?e:0,i=Number.isFinite(t)?t:0;return{velocityX:n,velocityY:i,speed:Math.hypot(n,i),direction:Math.atan2(i,n)}}function ac(e,t,n){return Number.isFinite(n)&&n>0?sc((t.x-e.x)/n,(t.y-e.y)/n):sc(0,0)}function cc(e){const{data:t,encoding:n,defaults:i={},scales:o}=e,r=ic({data:t,encoding:n}),s=[],a=new Map,c=[],l=[],d=new Map;return r.rows.forEach((e,t)=>{const{id:r,datum:u}=e,h=Math.max(0,nc(n.appearance?.size,u,t)??i.size??6),p=nc(n.appearance?.shape,u,t)??i.shape??{type:"circle",radius:h},f=e.placement.x??i.x??0,m=e.placement.y??i.y??0,y=o?.x?o.x(f):f,g=o?.y?o.y(m):m,b=nc(n.appearance?.color,u,t)??i.color,x=nc(n.appearance?.opacity,u,t)??i.opacity,v=nc(n.appearance?.stroke,u,t)??i.stroke,w=nc(n.appearance?.strokeWidth,u,t)??i.strokeWidth,k=nc(n.time?.spawnAt,u,t)??e.time.arrival,M=e.kinematics.velocityX,I=e.kinematics.velocityY,S=nc(n.dynamics?.mass,u,t)??i.mass??1,A=nc(n.dynamics?.friction,u,t),C=nc(n.dynamics?.restitution,u,t),D=nc(n.dynamics?.bodyCollisions,u,t),P={id:r,x:y,y:g,mass:S,shape:{...p},datum:u,...null!=k&&{spawnAt:k},...null!=M&&{vx:M},...null!=I&&{vy:I},...null!=A&&{friction:A},...null!=C&&{restitution:C},...null!=D&&{bodyCollisions:D}},$={...null!=b&&{fill:b},...null!=x&&{opacity:x},...null!=v&&{stroke:v},...null!=w&&{strokeWidth:w}},B={id:r,datum:u,appearance:{color:b,opacity:x,shape:p,size:h,stroke:v,strokeWidth:w},placement:{x:y,y:g,lane:e.placement.lane,space:n.placement?.space??"world"},time:{arrival:k,spawnAt:k,basis:n.time?.basis??"simulation",unit:n.time?.unit},kinematics:{velocityX:M,velocityY:I,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:D,friction:A,mass:S,restitution:C},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:P};s.push(B),a.set(r,B),c.push(P),d.set(r,$),l.push({id:r,bodyId:r,label:e.accessible.label,description:e.accessible.description,datum:u,x:y,y:g,group:e.accessible.group})}),{rows:s,byId:a,spawns:c,semanticItems:l,bodyStyle:e=>d.get(e.id)??{}}}function lc(e){return t=>{const n=cc({data:t.data,encoding:e.encoding,defaults:e.defaults,scales:t.scales}),i=e.extend?.(t,n)??{};return{...i,initialSpawns:n.spawns,bodyStyle:n.bodyStyle,semanticItems:[...n.semanticItems,...i.semanticItems??[]]}}}import{forwardRef as dc,useCallback as uc,useEffect as hc,useImperativeHandle as pc,useMemo as fc,useRef as mc,useState as yc}from"react";function gc(e,t={}){const n=t.id??"physics-process-boundary",i={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("segment"===e.type)return[{...i,id:n,shape:e}];const o=t.thickness??8,r=e.x-e.width/2,s=e.x+e.width/2,a=e.y-e.height/2,c=e.y+e.height/2;return[{...i,id:n+"-top",shape:{type:"segment",x1:r,y1:a,x2:s,y2:a,thickness:o}},{...i,id:n+"-right",shape:{type:"segment",x1:s,y1:a,x2:s,y2:c,thickness:o}},{...i,id:n+"-bottom",shape:{type:"segment",x1:s,y1:c,x2:r,y2:c,thickness:o}},{...i,id:n+"-left",shape:{type:"segment",x1:r,y1:c,x2:r,y2:a,thickness:o}}]}function bc(e){if(!1===e.semanticItem)return null;const t=e.semanticItem??{},n=e.shape,i="aabb"===n.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:n.x,y:n.y,width:n.width,height:n.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(n.x1+n.x2)/2,y:(n.y1+n.y2)/2,pathData:`M ${n.x1} ${n.y1} L ${n.x2} ${n.y2}`};return{...i,...t,id:t.id??i.id}}function xc(e){return e.map(e=>({id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"stage",x:e.x??0,y:e.y??0,width:e.width,height:e.height}))}function vc(e){return e.flatMap(e=>{if(!1===e.semanticItem)return[];const t=e.semanticItem??{},n={id:e.id,label:e.label??e.id,description:e.description,datum:e.datum,group:e.group??e.state??"body group",x:e.x??0,y:e.y??0,width:e.width,height:e.height};return[{...n,...t,id:t.id??n.id}]})}var wc="gauntlet-core",kc="gauntlet-positive",Mc="gauntlet-negative";function Ic(e){return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:28,y2:e.floorY,thickness:8}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:e.width-30,y2:76,thickness:8}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:e.floorY,x2:e.width-30,y2:e.floorY,thickness:8}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-30,y1:76,x2:e.width-30,y2:e.floorY,thickness:8}}]}function Sc(e,t,n,i){return n?"function"==typeof n?n(e,t):e[n]??i:i}function Ac(e){return e?.label??e?.id??"property"}function Cc(e){return`gauntlet:${e}:core`}function Dc(e,t){return`gauntlet:${e}:positive:${t}`}function Pc(e,t,n){return`gauntlet:${e}:negative:${t}:${n}`}function $c(e,t,n,i){const o=Math.max(2,n+2),r=80+o,s=i.floorY-o;return{x:Math.max(32+o,Math.min(i.width-30-4-o,e)),y:Math.max(r,Math.min(s,t))}}function Bc(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}function jc(e,t,n,i){const o=Bc(n),r=i?.(e,t,n)??{};return{...o,...r,startY:r.startY??r.routeY??o.startY,socketY:r.socketY??r.routeY??o.socketY,graveyardY:r.graveyardY??o.graveyardY}}function Rc(e,t){const n=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,n.indexOf(t));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:48+i%2*6}}function Tc(e,t,n){const i=e.activePositiveIds.reduce((e,n)=>e+(t.get(n)?.value??1),0),o=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*i-8*r-1.2*e.delay-5*o))}function Nc(e,t,n,i,o){const r=Sc(e,t,n.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=i.map(e=>e.id),a=[...Sc(e,t,n.positiveAccessor,s)],c=[...Sc(e,t,n.negativeAccessor,[])].filter(e=>o.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Sc(e,t,n.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Sc(e,t,n.startTimeAccessor,0))||0),stage:"project filed",viability:Sc(e,t,n.initialViability,100)}}function Ec(e,t,n,i,o,r,s){const a=i.startX,c=i.startY+(i.startY===n.routeY?38*t:0),l=s?.(e,t,n,i)??{},d={__gauntlet:!0,kind:wc,projectId:e.id,sourceDatum:e.datum},u=[{...l,id:Cc(e.id),x:l.x??a,y:l.y??c,vx:l.vx??42,vy:l.vy??0,mass:l.mass??7,bodyCollisions:l.bodyCollisions??!0,shape:l.shape??{type:"circle",radius:28},spawnAt:l.spawnAt??e.startedAt,datum:d}],h=$c(a,c,l.shape&&"radius"in l.shape&&Number(l.shape.radius)||28,n);u[0].x=h.x,u[0].y=h.y;for(const t of e.activePositiveIds){const i=o.get(t);if(!i)continue;const r=Rc(e.activePositiveIds,t),s=i.radius??10,a=$c(h.x+Math.cos(r.angle)*r.radius,h.y+Math.sin(r.angle)*r.radius,s,n);u.push({id:Dc(e.id,t),x:a.x,y:a.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:l.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:kc,projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:Cc(e.id)},stiffness:.56,damping:.9,restLength:52+r.index%2*4,...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const o=r.get(t);o&&u.push(zc(e,o,i,h.x,h.y,n,l.spawnAt??e.startedAt))}),u}function zc(e,t,n,i,o,r,s){const a=t.radius??7.2,c=$c(i-12+n%4*12,o+54+12*Math.floor(n/4),a,r);return{id:Pc(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:a},spawnAt:s,datum:{__gauntlet:!0,kind:Mc,projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Cc(e.id)},stiffness:.62,damping:.92,restLength:52+n%4*3,...t.spring??{}}]}}function Wc(e){return e?Array.isArray(e)?[...e]:Object.entries(e).flatMap(([e,t])=>Array.from({length:Math.max(0,Math.round(Number(t)||0))},()=>e)):[]}function Fc(e,t){return t?Array.isArray(t)?[...t]:t.ids?[...t.ids]:t.candidates?t.candidates.filter(t=>e.includes(t)).slice(0,t.count??1):[]:[]}function Oc(e,t){return Fc(e.activePositiveIds,t.popPositive)}function Lc(e){const t=Number(e.budget),n=Number.isFinite(t)?Math.max(0,t):0,i=e.properties instanceof Map?e.properties:new Map(e.properties.map(e=>[e.id,e])),o=e.candidates?new Set(e.candidates):null,r=e.attachedIds.map((e,t)=>{const n=i.get(e),o=Number(n?.work??1),r=Number(n?.priority??t);return{id:e,index:t,priority:Number.isFinite(r)?r:t,work:Number.isFinite(o)&&o>0?o:1}}).filter(e=>!o||o.has(e.id)).sort((e,t)=>e.priority-t.priority||e.index-t.index),s=[],a=[];let c=0;for(const e of r)c+e.work>n+Number.EPSILON?a.push(e.id):(s.push(e.id),c+=e.work);return{ids:s,used:c,budget:n,remaining:Math.max(0,n-c),skippedIds:a}}function qc(e,t){if(!t.from||!t.to||t.from===t.to)return{};const n=Math.max(0,Math.floor(Number(t.count??1)||0)),i=e.negativeIds.filter(e=>e===t.from).length,o=Math.min(n,i);return o?{addNegative:{[t.to]:o},popNegative:{ids:Array.from({length:o},()=>t.from)}}:{}}function Yc(e,t){const n=Fc(e.negativeIds,t.popNegative);if(!n.length)return[];const i=new Map;for(const e of n)i.set(e,(i.get(e)??0)+1);const o=[];return e.negativeIds.forEach((e,t)=>{const n=i.get(e)??0;n>0&&(o.push({propertyId:e,index:t}),i.set(e,n-1))}),o}function Hc(e,t,n){if(t.when&&!t.when(n))return e;let i={...e};const o=Oc(i,t);o.length&&(i={...i,activePositiveIds:i.activePositiveIds.filter(e=>!o.includes(e)),poppedPositiveIds:Array.from(new Set([...i.poppedPositiveIds,...o]))});const r=Yc(i,t);if(r.length){const e=new Set(r.map(e=>e.index));i={...i,negativeIds:i.negativeIds.filter((t,n)=>!e.has(n)),poppedNegativeIds:[...i.poppedNegativeIds,...r.map(e=>e.propertyId)]}}const s=Wc(t.addPositive);s.length&&(i={...i,activePositiveIds:Array.from(new Set([...i.activePositiveIds,...s])),missingPositiveIds:i.missingPositiveIds.filter(e=>!s.includes(e))});const a=Wc(t.addNegative);if(a.length&&(i={...i,negativeIds:[...i.negativeIds,...a]}),t.delayDelta&&(i={...i,delay:i.delay+t.delayDelta}),t.metricsDelta){const e={...i.metrics};for(const[n,i]of Object.entries(t.metricsDelta))e[n]=Number(e[n]??0)+i;i={...i,metrics:e}}return t.viabilityDelta&&(i={...i,viability:i.viability+t.viabilityDelta}),t.stage&&(i={...i,stage:t.stage}),t.outcome&&(i={...i,outcome:t.outcome}),i}function Xc(e,t){return{id:e.id,label:e.label??e.id,summary:e.summary??t.find(e=>e.summary)?.summary,time:e.time}}function Gc(e,t){return e.eventsApplied.includes(t.id)?e:{...e,eventsApplied:[...e.eventsApplied,t.id],eventHistory:[...e.eventHistory??[],t],lastEvent:t,stage:t.label??e.stage}}function _c(e,t){const n=e.datum;return!(!n?.__gauntlet||n.projectId!==t||n.kind!==Mc)}function Vc(e){const t=e.id.slice(e.id.lastIndexOf(":")+1),n=Number(t);return Number.isFinite(n)?n:-1}import{jsx as Uc,jsxs as Kc}from"react/jsx-runtime";function Qc(e){const t=e.data;return t?.__gauntlet?Kc("div",{className:"semiotic-tooltip",style:{background:"var(--semiotic-tooltip-bg, rgba(15, 23, 42, 0.94))",color:"var(--semiotic-tooltip-text, #f8fafc)",padding:"8px 12px",borderRadius:6,boxShadow:"var(--semiotic-tooltip-shadow, 0 8px 24px rgba(0,0,0,0.35))",maxWidth:280},children:[Uc("strong",{children:t.kind===wc?"string"==typeof t.sourceDatum?.label?t.sourceDatum.label:t.projectId:Ac(t.property)}),Uc("div",{children:t.kind===kc?"Positive property":t.kind===Mc?"Negative property":"Project core"})]}):null}function Zc(e,t,n){const i=t.datum;if(!i?.__gauntlet)return;const o="circle"===t.shape.type?t.shape.radius:8;if(e.save(),e.translate(t.x,t.y),i.kind===wc)e.fillStyle=Jc(e,n.fill,"#0f766e"),e.strokeStyle=Jc(e,n.stroke,"#f8fafc"),e.lineWidth=2.4,e.beginPath(),e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke();else{const t=i.property;e.fillStyle=Jc(e,n.fill??t?.color,"#38bdf8"),e.strokeStyle=Jc(e,n.stroke,"#0f172a"),e.lineWidth=1.1,e.beginPath(),i.kind===Mc?e.rect(-o,-o,2*o,2*o):e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke(),e.fillStyle=Jc(e,"var(--semiotic-background, #07111f)","#07111f"),e.font=`900 ${i.kind===Mc?9:8}px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(t?.short??t?.id?.slice(0,1).toUpperCase()??"?",0,.5)}e.restore()}function Jc(e,t,n){if("string"!=typeof t)return n;if("function"!=typeof getComputedStyle||!e.canvas)return t||n;const i=t.startsWith("var(")?t.match(/var\((--[^,\s)]+)/)?.[1]:t.startsWith("--")?t:null;return i?getComputedStyle(e.canvas).getPropertyValue(i).trim()||n:t||n}function el({layout:e,states:t}){return Kc("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Uc("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-accent, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),Uc("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-negative, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),Uc("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),e.gates.map(t=>Kc("g",{children:[Uc("rect",{x:t.x-t.width/2,y:Math.max(80,e.routeY-180),width:t.width,height:Math.min(360,e.height-170),rx:12,fill:t.color??"var(--semiotic-accent, #38bdf8)",fillOpacity:.1,stroke:t.color??"var(--semiotic-accent, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),Uc("text",{x:t.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:t.label??t.id})]},t.id)),Kc("g",{children:[Uc("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-positive, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-positive, #22c55e)",strokeWidth:1.5}),Uc("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),Kc("g",{children:[Uc("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-negative, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-negative, #ef4444)",strokeOpacity:.7}),Uc("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),Uc("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function tl(e){const t=e.datum;return!!t?.__gauntlet&&(t.kind===wc?{label:t.projectId+" project core",group:"project",description:"Project core carrying positive and negative properties."}:{label:`${Ac(t.property)} ${t.kind===kc?"positive":"negative"} property`,group:t.kind===kc?"positive property":"negative property",description:`${Ac(t.property)} attached to ${t.projectId}.`})}function nl({states:e,layout:t}){const n=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!n.length)return null;const i=Math.max(1,...n.map(e=>e.value)),o=Math.max(40,(t.width-80)/n.length);return Kc("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Uc("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),n.map((e,t)=>{const n=40+t*o,r=Math.max(2,e.value/i*28),s=/kill|crash|block|grave/i.test(e.outcome);return Kc("g",{children:[Uc("rect",{x:n+.18*o,y:28-r+22,width:Math.max(10,.45*o),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}),Uc("text",{x:n+.4*o,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}import{jsx as il}from"react/jsx-runtime";import{createElement as ol}from"react";var rl=[],sl=dc(function(e,t){const{bodyGroups:n,coreBody:i,coreForceMode:o="route",crashDetection:r=!0,crashOffset:s=30,data:a,emptyContent:c,events:l,frameProps:d={},gates:u,initialSpawnPacing:h,loading:p,loadingContent:f,negativeProperties:m,onCapacityChange:y,onClick:g,onStateChange:b,outcome:x,paused:v,positiveProperties:w=rl,projectPlacement:k,responsiveHeight:M,responsiveWidth:I,showTethers:S=!0,terminalBehavior:A="outcome",viability:C}=e,D=mc(null),P=fc(()=>({idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor}),[e.idAccessor,e.initialViability,e.metricsAccessor,e.negativeAccessor,e.positiveAccessor,e.startTimeAccessor]),$=ua(e,[900,520]),{chartSize:B,showProjection:j,showChrome:R,className:T,title:N,chartMode:E,margin:z,enableHover:W,description:F,summary:O,accessibleTable:L}=$,q=ha({data:a,emptyContent:c,loading:p,loadingContent:f,size:B}),Y=fc(()=>qa(a??[]),[a]),H=fc(()=>Y.map((e,t)=>Sc(e,t,P.idAccessor,null!=e.id?e.id+"":"project-"+t)+"").join("|"),[Y,P.idAccessor]),X=fc(()=>new Map(w.map(e=>[e.id,e])),[w]),G=fc(()=>new Map(m.map(e=>[e.id,e])),[m]),_=fc(()=>function(e,t,n){const[i,o]=e,r=Math.round(.48*o),s=o-36,a=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,a.length),l=.22*i,d=c>1?(.78*i-l)/(c-1):0,u=Math.max(Math.round(.14*i),110);return{crashY:s-n,floorY:s,gates:a.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(l+t*d),width:e.width??Math.max(54,Math.round(.07*i))})),graveyardX:Math.round(.84*i),graveyardY:s-4,height:o,routeY:r,socketX:Math.round(.92*i),startX:u,width:i}}(B,u,s),[B,s,u]),V=fc(()=>new Map(_.gates.map(e=>[e.id,e])),[_.gates]),U=fc(()=>_.gates.map(e=>({kind:"force-field",damping:.035,force:{x:12,y:0},semanticItem:!1,...e.regionEffect,id:"gauntlet-gate-"+e.id,label:e.label??e.id,description:e.description,bodyFilter:e.capacity?{property:"datum.kind",equals:wc}:e.regionEffect?.bodyFilter,shape:{type:"aabb",x:e.x,y:_.routeY,width:e.capacity?e.capacity.sensorWidth??Math.max(96,6*e.width):Math.max(e.width,54),height:Math.min(360,_.height-170)}})),[_.gates,_.height,_.routeY]),[K,Q]=yc(()=>Y.map((e,t)=>{const n=Nc(e,t,P,w,G);return{...n,viability:C?.(n,{negativeProperties:G,positiveProperties:X})??Tc(n,X,G)}})),Z=mc(K),J=mc(0),ee=mc(new Map),te=mc([]),ne=mc(y);ne.current=y;const ie=fc(()=>function(e){const{dataKey:t,gates:n,statesRef:i,processedGateVisitsRef:o}=e;return n.flatMap(e=>e.capacity&&e.capacity.unitsPerSecond>0?[io({id:`gauntlet-capacity-${t}-${e.id}`,regionId:"gauntlet-gate-"+e.id,unitsPerSecond:e.capacity.unitsPerSecond,bodyFilter:{property:"datum.kind",equals:wc},maxQueue:e.capacity.maxQueue,queueLayout:e.capacity.queueLayout,queueSlotSpacing:e.capacity.queueSlotSpacing,queueStiffness:e.capacity.queueStiffness??24,releaseImpulse:{x:36,y:0},unitAccessor:t=>{const n=t.datum,o=n?.sourceDatum,r=e.capacity?.unitAccessor,s=i.current.find(e=>e.id===n?.projectId);let a;"function"==typeof r?a=s?r(s):void 0:r&&(a=o?.[r]);const c=Number(a??o?.reviewWork??o?.work??s?.metrics.reviewWork??o?.points);return Number.isFinite(c)&&c>0?c:1},onProcessed:t=>{const n=t.datum;if(!n?.projectId)return;const i=`${n.projectId}:${e.id}`;o.current.set(i,(o.current.get(i)??0)+1)}})]:[])}({dataKey:H,gates:_.gates,statesRef:Z,processedGateVisitsRef:ee}),[H,_.gates]),oe=fc(()=>[...ie,...d.controllers??[]],[ie,d.controllers]),re=mc(Y);re.current=Y;const se=mc(b);se.current=b;const ae=mc({negativeById:G,positiveById:X,positiveProperties:w,stateAccessors:P,viability:C});ae.current={negativeById:G,positiveById:X,positiveProperties:w,stateAccessors:P,viability:C};const ce=uc((e,t,n=0)=>{const i=ae.current,o=Nc(e,t,i.stateAccessors,i.positiveProperties,i.negativeById);return i.stateAccessors.startTimeAccessor||(o.startedAt=Math.max(0,n)),{...o,viability:i.viability?.(o,{negativeProperties:i.negativeById,positiveProperties:i.positiveById})??Tc(o,i.positiveById,i.negativeById)}},[]);hc(()=>{ee.current.clear(),te.current=[];const e=re.current.map((e,t)=>ce(e,t));Z.current=e,Q(e)},[ce,H]),hc(()=>{Z.current=K,se.current?.(K)},[K]);const le=uc(e=>[...("function"==typeof l?l(e,_):l)??[]].sort((e,t)=>e.time-t.time),[l,_]),de=uc((e,t,n)=>{if(!t.gateId||!V.get(t.gateId)?.capacity)return!0;const i=Number(t.gateVisit),o=Number.isFinite(i)&&i>0?Math.floor(i):n.filter(e=>e.gateId===t.gateId).findIndex(e=>e.id===t.id)+1;return o>0&&(ee.current.get(`${e.id}:${t.gateId}`)??0)>=o},[V]),ue=uc(()=>{if(!ie.length)return;const e=ie.flatMap(e=>{const t=e.getSnapshot?.();return t?[t]:[]});var t,n;(t=te.current).length===(n=e).length&&t.every((e,t)=>{const i=n[t];return!!i&&e.regionId===i.regionId&&e.queueDepth===i.queueDepth&&e.blockedDepth===i.blockedDepth&&e.processedCount===i.processedCount&&e.metricRevision===i.metricRevision})||(te.current=e,ne.current?.(e))},[ie]),he=fc(()=>K.flatMap((e,t)=>{const n=jc(e,t,_,k);return Ec(e,t,_,n,X,G,i)}),[i,_,G,X,k,K]),pe=uc((e,t)=>{let n=!1;const i=Z.current.map(i=>{if(i.id!==e)return i;const o=t(i);return n=n||o!==i,o});n&&(Z.current=i,Q(i))},[]);pc(t,()=>function(e){const{statesRef:t,setStates:n,elapsedRef:i,frameRef:o,layout:r,projectPlacement:s,positiveById:a,negativeById:c,coreBody:l,createState:d}=e;return{push:e=>{const u=d(e,t.current.length,i.current),h=jc(u,t.current.length,r,s),p=Ec(u,t.current.length,r,h,a,c,l),f=[...t.current,u];t.current=f,n(f),o.current?.pushMany(p),o.current?.step(0)},pushMany:e=>{const u=[...t.current],h=[],p=i.current;e.forEach(e=>{const t=d(e,u.length,p),n=jc(t,u.length,r,s);h.push(...Ec(t,u.length,r,n,a,c,l)),u.push(t)}),t.current=u,n(u),h.length&&o.current?.pushMany(h),o.current?.step(0)},remove:e=>{const i=Array.isArray(e)?e:[e],r=[],s=[];for(const e of i){const n=t.current.find(t=>t.id===e);n&&(r.push(n.datum),s.push(Cc(n.id),...n.activePositiveIds.map(e=>Dc(n.id,e))),n.negativeIds.forEach((e,t)=>{s.push(Pc(n.id,e,t))}))}return t.current=t.current.filter(e=>!i.includes(e.id)),n(t.current),o.current?.remove(s),r},update:(e,u)=>{const h=Array.isArray(e)?e:[e],p=[];for(const e of h){const n=t.current.find(t=>t.id===e);if(!n)continue;const h=t.current.findIndex(t=>t.id===e);p.push(n.datum);const f=u(n.datum),m=d(f,0>h?t.current.length:h,n.startedAt??i.current),y=jc(m,0>h?t.current.length:h,r,s);o.current?.remove([Cc(n.id),...n.activePositiveIds.map(e=>Dc(n.id,e)),...n.negativeIds.map((e,t)=>Pc(n.id,e,t))]),o.current?.pushMany(Ec(m,0>h?t.current.length:h,r,y,a,c,l)),t.current=t.current.map(t=>t.id===e?m:t)}return n(t.current),p},clear:()=>{t.current=[],n([]),o.current?.clear()},getData:()=>t.current.map(e=>e.datum),getScales:()=>null,getCustomLayout:()=>o.current?.snapshot()??null,popBodies:(e,t)=>o.current?.popBodies(e,t)??[]}}({statesRef:Z,setStates:Q,elapsedRef:J,frameRef:D,layout:_,projectPlacement:k,positiveById:X,negativeById:G,coreBody:i,createState:ce}),[i,ce,_,G,X,k]);const fe=uc((e,t,n)=>{!function(e){const{project:t,effect:n,controls:i,layout:o,positiveById:r,negativeById:s,coreBody:a,popBodies:c}=e,l=i.readBodies().find(e=>e.id===Cc(t.id)),d=i.readBodies(),u=l?.x??o.startX,h=l?.y??o.routeY,p=function(e,t){let n=-1;for(const i of t)_c(i,e.id)&&(n=Math.max(n,Vc(i)));return Math.max(e.negativeIds.length,n+1)}(t,d),f=Wc(n.addNegative).flatMap((e,n)=>{const i=s.get(e);return i?[zc(t,i,p+n,u,h,o)]:[]}),m=Wc(n.addPositive).flatMap(e=>{if(!r.get(e)||t.activePositiveIds.includes(e))return[];const n={...Bc(o),routeY:h,socketY:h,startX:u,startY:h};return Ec({...t,activePositiveIds:[e],negativeIds:[]},0,o,n,r,s,a).filter(e=>e.id.includes(":positive:"))});(f.length||m.length)&&i.pushMany([...f,...m]);const y=Oc(t,n);for(const e of y){const n=r.get(e);c([Dc(t.id,e)],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??10)+3})}const g=Yc(t,n),b=function(e,t,n){const i=t.filter(t=>_c(t,e.id)).sort((e,t)=>Vc(e)-Vc(t)||e.id.localeCompare(t.id)),o=new Set;return n.map(t=>{const n=i.find(e=>!o.has(e.id)&&e.datum.property?.id===t.propertyId);return n?(o.add(n.id),n.id):Pc(e.id,t.propertyId,t.index)})}(t,d,g);g.forEach((e,t)=>{const n=s.get(e.propertyId);c([b[t]],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??7)+3})})}({project:e,effect:t,controls:n,layout:_,positiveById:X,negativeById:G,coreBody:i,popBodies:(e,t)=>D.current?.popBodies(e,t)})},[i,_,G,X]),me=uc(({body:e,bodies:t})=>function(e){const{body:t,bodies:n,layout:i,states:o,projectPlacement:r,positiveById:s,negativeById:a,projectEvents:c,gateById:l,coreForceMode:d,terminalBehavior:u,elapsed:h}=e,p=t.datum;if(!p?.__gauntlet)return null;const f=o.findIndex(e=>e.id===p.projectId),m=0>f?void 0:o[f];if(!m)return null;const y=jc(m,f,i,r),g=n.find(e=>e.id===Cc(m.id)),b=m.negativeIds.reduce((e,t)=>e+(a.get(t)?.load??1),0),x=m.killed?0:58;if(p.kind!==wc){if(!g)return null;let e;const o=p.property;if(o?.target){const r=n.filter(e=>{const t=e.datum;return t?.__gauntlet&&t.projectId===m.id&&t.kind===p.kind}).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),s=Math.max(0,r.findIndex(e=>e.id===t.id));e=o.target({body:t,bodies:n,core:g,index:s,layout:i,placement:y,project:m})??{x:g.x,y:g.y}}else if(p.kind===kc&&p.property){const t=Rc(m.activePositiveIds,p.property.id);e={x:g.x+Math.cos(t.angle)*t.radius,y:g.y+Math.sin(t.angle)*t.radius-2}}else{const i=n.filter(e=>e.datum?.kind===Mc&&e.datum.projectId===m.id).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),o=Math.max(0,i.findIndex(e=>e.id===t.id)),r=Math.floor(o/4);e={x:g.x+18*(o%4-(Math.min(4,i.length-4*r)-1)/2),y:g.y+54+13*r}}const r="circle"===t.shape.type?t.shape.radius:8;e=$c(e.x,e.y,r,i);const s=$c(t.x,t.y,r,i);if(Math.abs(s.x-t.x)>.5||Math.abs(s.y-t.y)>.5)return{x:48*(s.x-t.x)-6*t.vx,y:48*(s.y-t.y)-6*t.vy};const a=p.kind!==kc||m.killed?0:3.2*(o?.buoyancy??o?.value??1),c=p.kind===Mc?{x:.22*(o?.pull?.x??-8),y:.22*(o?.pull?.y??22)}:{x:0,y:0};return{x:28*(e.x-t.x)-3*(t.vx-g.vx)+c.x+.01*x,y:28*(e.y-t.y)-3*(t.vy-g.vy)+c.y-a}}if(m.killed)return{x:44*((m.crashX??m.metrics.lastX??t.x)-t.x)-9*t.vx,y:160+12*b-1.6*t.vy};const v=c(m),w=function(e,t,n,i,o,r,s){if(t.killed)return{x:t.metrics.lastX??i.graveyardX,y:i.graveyardY};const a=o[o.length-1];if(!a)return{x:i.socketX,y:i.routeY};const c=o.find(n=>e>=n.time&&!t.eventsApplied.includes(n.id)&&!(!n.gateId||!r.get(n.gateId)?.capacity)),l=c?Math.min(e,c.time):e,d="built"===t.outcome||"built_diminished"===t.outcome;if(l>a.time+.85){if("hold-last"===s){const e=a.gateId?r.get(a.gateId):void 0;return{x:a.routeX??e?.x??i.socketX,y:a.routeY??i.routeY}}return d?{x:i.socketX,y:i.socketY}:{x:i.graveyardX,y:i.graveyardY-14}}const u=.85*t.delay+12*t.negativeIds.length+8*(t.poppedPositiveIds.length+t.missingPositiveIds.length),h=[{time:0,x:i.startX,y:i.startY},...o.map(e=>{const t=e.gateId?r.get(e.gateId):void 0;return{time:e.time,x:e.routeX??t?.x??i.startX,y:e.routeY??i.routeY+.28*Math.min(180,u)}})].sort((e,t)=>e.time-t.time);let p=h[0],f=h[h.length-1];for(let e=1;h.length>e;e+=1){if(h[e].time>=l){f=h[e];break}p=h[e]}const m=Math.max(0,Math.min(1,(l-p.time)/Math.max(.1,f.time-p.time))),y=m*m*(3-2*m);return{x:p.x+(f.x-p.x)*y,y:p.y+(f.y-p.y)*y+7*Math.sin(2.6*l)}}(Math.max(0,h-(m.startedAt??0)),m,0,y,v,l,u),k=m.activePositiveIds.reduce((e,t)=>e+(s.get(t)?.buoyancy??s.get(t)?.value??1),0);return"net"===d?{x:15*(w.x-t.x)-1.8*t.vx+.18*x,y:1.25*(y.routeY-t.y)-1.4*t.vy+32*(b-k)}:{x:15*(w.x-t.x)-1.8*t.vx+.18*x,y:15*(w.y-t.y)-1.8*t.vy+13*b-2.2*k}}({body:e,bodies:t,layout:_,states:Z.current,projectPlacement:k,positiveById:X,negativeById:G,projectEvents:le,gateById:V,coreForceMode:o,terminalBehavior:A,elapsed:J.current}),[o,V,_,G,X,le,k,A]),ye=uc((e,t)=>{!function(e,t,n){const{frameProps:i,elapsedRef:o,statesRef:r,crashDetection:s,layout:a,projectEvents:c,gateById:l,capacityEventReady:d,addBodiesForEffect:u,updateProjectState:h,viability:p,positiveById:f,negativeById:m,outcome:y,reportCapacity:g}=n;i.onTick?.(e,t),o.current=e.elapsedSeconds??t.snapshot().elapsedSeconds,g();for(const e of r.current){const n=t.readBodies().find(t=>t.id===Cc(e.id));if(!n)continue;if(s&&!e.killed&&n.y+("circle"===n.shape.type?n.shape.radius:28)>=a.crashY){t.readBodies().forEach(n=>{const i=n.datum;i?.__gauntlet&&i.projectId===e.id&&t.applyImpulse(n.id,-n.vx*n.mass,0)}),h(e.id,e=>{const t={appliedAt:Math.max(0,o.current-(e.startedAt??0)),id:"gauntlet-crash-line",label:"Crash Line",summary:"The project hit the crash threshold; lift and forward motion shut off.",time:Math.max(0,o.current-(e.startedAt??0))};return{...e,crashX:n.x,eventHistory:[...e.eventHistory??[],t],killed:!0,lastEvent:t,metrics:{...e.metrics,lastX:n.x},outcome:"bad_design_crash",stage:"Crash Line",viability:Math.min(0,e.viability)}});continue}if(e.killed)continue;const i=Math.max(0,o.current-(e.startedAt??0)),r=c(e),g=r.filter(t=>i>=t.time&&!e.eventsApplied.includes(t.id)&&d(e,t,r));let b=e;for(const n of g){const o=n.gateId?l.get(n.gateId):void 0,r=n.effects??[];for(const e of r){const i={event:n,gate:o,negativeProperties:m,positiveProperties:f,project:b};e.when&&!e.when(i)||(u(b,e,t),b=Hc(b,e,i))}const s={...Xc(n,r),appliedAt:i};b=Gc(b,s),h(e.id,e=>{let t=Gc(e,s);if(t===e)return e;for(const e of r)t=Hc(t,e,{event:n,gate:o,negativeProperties:m,positiveProperties:f,project:t});const i=p?.(t,{negativeProperties:m,positiveProperties:f})??Tc(t,f,m);return t={...t,viability:i},n.final&&(t={...t,outcome:n.outcome??y?.(t,{layout:a,negativeProperties:m,positiveProperties:f})??(t.viability>20?"built":"approved_not_built")}),t})}}}(e,t,{frameProps:d,elapsedRef:J,statesRef:Z,crashDetection:r,layout:_,projectEvents:le,gateById:V,capacityEventReady:de,addBodiesForEffect:fe,updateProjectState:pe,viability:C,positiveById:X,negativeById:G,outcome:x,reportCapacity:ue})},[fe,de,r,d,V,_,G,x,X,le,ue,pe,C]),ge=uc((e,t)=>{const n="function"==typeof d.bodyStyle?d.bodyStyle(e,t):d.bodyStyle,i=e.datum;return i?.__gauntlet?{fill:i.kind===wc?"var(--semiotic-accent, #0f766e)":i.property?.color??"var(--semiotic-accent, #38bdf8)",stroke:i.kind===wc?"#f8fafc":"#0f172a",opacity:.96,...n}:n??{}},[d]),be=fc(()=>"function"==typeof n?n(K,_):n??[],[n,_,K]),xe=fc(()=>vc(be),[be]),ve=fc(()=>j?function(e,t){if(!e.length)return[];const n=Math.max(40,(t.width-80)/e.length);return e.map((e,t)=>{const i=`${e.id}: viability ${Math.round(e.viability)}, ${e.outcome||e.stage}`;return{id:"gauntlet-projection-"+e.id,label:i,description:i,datum:e,x:40+(t+.5)*n,y:28,shape:"rect",width:Math.max(16,.55*n),height:22,group:"settled projection"}})}(K,_):[],[_,j,K]),we=fc(()=>[...ve,...xe],[xe,ve]),ke=uc((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]),Me=uc((e,t)=>{g&&g(e&&"object"==typeof e&&e.__gauntlet?e.sourceDatum:e,{x:t.x,y:t.y})},[g]);if(q)return q;const Ie=ma(e.tooltip,d),Se=ya(e,d,we,{chartMode:E,className:T,title:N,description:F,summary:O,accessibleTable:L,enableHover:W,margin:z}),Ae=j?il(nl,{states:K,layout:_}):void 0,Ce=fa(R?il(el,{layout:_,states:K}):void 0,d.backgroundGraphics),De=fa(Ae,d.foregroundGraphics),Pe=d.renderBody??Zc,$e=Ie.tooltipContent??Qc;return pa("GauntletChart",B,ol(kr,{...d,...Ie,...Se,key:`${B[0]}x${B[1]}:${H}`,ref:D,accessibleTable:e.accessibleTable??d.accessibleTable,backgroundGraphics:Ce,bodyForces:me,bodySemanticItems:d.bodySemanticItems??tl,bodyStyle:ge,beforePaint:(e,t)=>{d.beforePaint?.(e,t),S&&function(e,t){const n=new Map(t.filter(e=>e.datum?.kind===wc).map(e=>[e.datum.projectId,e]));e.save(),e.lineWidth=1.1,e.setLineDash([3,4]);for(const i of t){const t=i.datum;if(!t?.__gauntlet||t.kind===wc)continue;const o=n.get(t.projectId);o&&(e.globalAlpha=t.kind===Mc?.24:.36,e.strokeStyle=t.kind===Mc?"#d94a45":"#7a8794",e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke())}e.restore()}(e,t)},onClick:g?Me:Se.onClick,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7,...d.config?.kernel??{}},colliders:[...Ic(_),...d.config?.colliders??[]]},controllers:oe,enableHover:Ie.enableHover??!0,foregroundGraphics:De,hoverRadius:e.hoverRadius??d.hoverRadius??18,initialSpawns:he,initialSpawnPacing:h,onBodyPointerDown:ke,onTick:ye,paused:v,regionEffects:[...U,...d.regionEffects??[]],renderBody:Pe,responsiveHeight:M,responsiveWidth:I,size:B,tooltipContent:$e}))});sl.displayName="GauntletChart";var al=sl;import{forwardRef as cl,useCallback as ll,useMemo as dl,useRef as ul}from"react";import{jsx as hl,jsxs as pl}from"react/jsx-runtime";function fl(e){return e.toLocaleString(void 0,1e3>Math.abs(e)?{maximumFractionDigits:1}:{maximumFractionDigits:0})}function ml(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}function yl(e){if(!e||"object"!=typeof e)return null;const t=e,n=Number(t.x),i=Number(t.y);return Number.isFinite(n)&&Number.isFinite(i)?{x:n,y:i}:null}function gl(e){if(!e||"object"!=typeof e)return[];const t=e.flowPath;return Array.isArray(t)?t.map(yl).filter(e=>null!=e):[]}function bl(e,t){if(2>t.length)return null;let n=0;const i=[];for(let e=1;t.length>e;e+=1){const o=Math.hypot(t[e].x-t[e-1].x,t[e].y-t[e-1].y);i.push(o),n+=o}if(0>=n)return null;let o=null,r=0;for(let s=1;t.length>s;s+=1){const a=t[s-1],c=t[s],l=i[s-1];if(0>=l)continue;const d=c.x-a.x,u=c.y-a.y,h=Math.max(0,Math.min(1,((e.x-a.x)*d+(e.y-a.y)*u)/(l*l))),p={x:a.x+d*h,y:a.y+u*h},f={distance:Math.hypot(e.x-p.x,e.y-p.y),point:p,progress:(r+h*l)/n,tangent:{x:d/l,y:u/l},totalLength:n};o&&f.distance>=o.distance||(o=f),r+=l}return o}function xl(e,t,n){if(0===e.length)return{x:0,y:0};if(1===e.length||0>=n)return{...e[0]};let i=0;const o=Math.max(0,Math.min(1,t))*n;for(let t=1;e.length>t;t+=1){const n=e[t-1],r=e[t],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(i+s>=o){const e=(o-i)/s;return{x:n.x+(r.x-n.x)*e,y:n.y+(r.y-n.y)*e}}i+=s}}return{...e[e.length-1]}}function vl(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function wl(e,t,n){const i=Math.hypot(e,t);if(n>=i||0>=i)return[e,t];const o=n/i;return[e*o,t*o]}function kl(e,t,n){const i=bl({...e,x:t[0].x,y:t[0].y},t),o=i?.tangent??{x:t[1].x-t[0].x,y:t[1].y-t[0].y},r=Math.hypot(o.x,o.y)||1,s=o.x/r,a=o.y/r,c=vl(e),l=function(e,t){let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return(n%1e3/1e3-.5)*t*1.4}(e.id,c);return{id:e.id,x:t[0].x+-a*l,y:t[0].y+s*l,vx:s*n,vy:a*n,mass:e.mass,shape:e.shape,datum:{...e.datum&&"object"==typeof e.datum?e.datum:{},routeProgress:0}}}var Ml=cl(function(e,t){const{chartId:n,colorBy:i,coordinateMode:o="auto",data:r,edges:s,emptyContent:a,flowSpeed:c=90,frameProps:l,links:d,loading:u,loadingContent:h,maxParticles:p=180,nodeIdAccessor:f="id",nodeXAccessor:m="x",nodeYAccessor:y="y",nodes:g,onObservation:b,particleRadius:x=4,particleRate:v=.16,pathAccessor:w="path",pathConstraint:k="path",paused:M,reducedMotion:I=!1,responsiveHeight:S,responsiveWidth:A,seed:C=1,showNodeLabels:D=!0,showSensors:P=!1,showStaticFlow:$=!0,sourceAccessor:B="source",targetAccessor:j="target",throughputAccessor:R="value"}=e,T=ua(e,[760,420]),{chartSize:N,className:E,title:z,chartMode:W,margin:F,enableHover:O,description:L,summary:q,accessibleTable:Y}=T,H=ul(null),X=dl(()=>g??[],[g]),G=dl(()=>d??s??r??[],[r,s,d]),_=dl(()=>Ur({nodes:X,links:G,nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:B,targetAccessor:j,throughputAccessor:R,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:I,seed:C,size:N}),[G,X,N,o,c,p,f,m,y,x,v,w,k,I,C,B,j,R]);Is(t,{frameRef:H,spawnDatum:ll((e,t)=>{const n=Ur({nodes:X,links:[e],nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:B,targetAccessor:j,throughputAccessor:R,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:I,seed:C+t+1,size:N}),i={id:(e.id??"physical-flow-push-"+t)+"",x:Mr(N).plot.x,y:Mr(N).plot.y,mass:1,shape:{type:"circle",radius:x},datum:e},r=n.initialSpawns.length?n.initialSpawns:[i];return{datumId:(e.id??r[0].id)+"",spawns:r}},[X,N,o,c,p,f,m,y,x,v,w,k,I,C,B,j,R]),seedRows:G,seedSpawns:_.initialSpawns});const V=i??"source",U=dl(()=>Sr(V,"#2563eb"),[V]),K=dl(()=>function(e,t,n){return{...e,observation:{...e.observation,chartId:t??e.observation?.chartId??"physical-flow",chartType:"PhysicalFlowChart",onObservation:n??e.observation?.onObservation}}}(_.config,n,b),[n,_.config,b]),Q=ul(l?.onTick);Q.current=l?.onTick;const Z=ll((e,t)=>{I||"none"===k||function(e,t){const n=e.readBodies(),i=[],o=[];for(const r of n){const n=gl(r.datum);if(2>n.length)continue;const s=bl(r,n);if(!s)continue;const a=r.datum,c=Number(a?.flowSpeed),l=Number.isFinite(c)&&c>0?c:t;if(s.progress>=.985||s.distance>Math.max(90,14*vl(r))){i.push(r.id),o.push(kl(r,n,l));continue}const d=xl(n,Math.min(1,s.progress+Math.max(.035,Math.min(.12,l/s.totalLength*.16))),s.totalLength),u=s.tangent,h=(u.x*l-r.vx)*r.mass*.16+(d.x-r.x)*r.mass*.045+(s.point.x-r.x)*r.mass*.08,p=(u.y*l-r.vy)*r.mass*.16+(d.y-r.y)*r.mass*.045+(s.point.y-r.y)*r.mass*.08,[f,m]=wl(h,p,r.mass*l*.35);e.applyImpulse(r.id,f,m)}i.length&&e.remove(i),o.length&&e.pushMany(o)}(t,c),Q.current?.(e,t)},[c,k,I]),J=ha({data:null==d&&null==s&&null==r?void 0:G,emptyContent:a,loading:u,loadingContent:h,size:N});if(J)return J;const ee=function(e,t){const{showNodeLabels:n,showSensors:i,showStaticFlow:o}=t;if(e&&(o||i))return({size:t})=>{const r=[Number(t[0])||760,Number(t[1])||420],s=Math.max(1,...e.links.map(e=>e.throughput)),a=new Set(e.nodes.map(e=>e.sensorId));return pl("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:[o?e.links.map(e=>{const t=3+e.throughput/s*16,n=e.path[Math.floor(e.path.length/2)];return pl("g",{children:[hl("path",{d:ml(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),hl("path",{d:ml(e.path),fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),n?hl("text",{x:n.x,y:n.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:fl(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>pl("g",{children:[i&&a.has(e.sensorId)?hl("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,o?hl("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,n?hl("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text-primary, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}(_.metadata,{showNodeLabels:D,showSensors:P,showStaticFlow:$}),te=(ne=_.metadata)?ne.links.map(e=>{const t=e.path[Math.floor(e.path.length/2)]??e.path[0],n=`${e.sourceLabel} to ${e.targetLabel}: ${fl(e.throughput)} throughput, ${e.packetCount} packets`;return{id:e.id,label:n,description:n,datum:e,x:t?.x??0,y:t?.y??0,shape:"path",pathData:ml(e.path),group:"flow"}}):[];var ne;const ie=ma(e.tooltip,l),oe=ya(e,l,te,{chartMode:W,className:E,title:z,description:L,summary:q,accessibleTable:Y,enableHover:O,margin:F});return pa("PhysicalFlowChart",N,hl(kr,{...l,...ie,...oe,ref:H,config:K,continuous:!I&&"none"!==k,foregroundGraphics:fa(ee,l?.foregroundGraphics),initialSpawns:_.initialSpawns,onTick:Z,paused:M||I,responsiveHeight:S,responsiveWidth:A,simulationExecution:"none"===k?l?.simulationExecution:"sync",size:N,bodyStyle:U,workerBodyThreshold:l?.workerBodyThreshold??1/0}))});Ml.displayName="PhysicalFlowChart";import{forwardRef as Il,useCallback as Sl,useEffect as Al,useMemo as Cl,useRef as Dl,useState as Pl}from"react";import{Fragment as $l,jsx as Bl,jsxs as jl}from"react/jsx-runtime";var Rl={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 Tl(e,t,n){return Math.max(t,Math.min(n,e))}function Nl(e){return 6.2*e.length}function El(e,t){const n=e.trim();if(t>=n.length)return n;if(1>=t)return n.slice(0,1);const i=n.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return i.length>1&&t>=i.length?i:t>3?n.slice(0,Math.max(1,t-2))+"..":n.slice(0,t).toUpperCase()}function zl(e,t,n="auto"){const i=Math.max(1,Math.floor(t/6.2)),o="compact"===n?El(e,i):"full"===n?e:Nl(e)>t?El(e,i):e;return{text:o,textLength:Nl(o)>t?Math.max(4,t):void 0}}function Wl(e,t={}){const{showFlowSpine:n=!0,showStageCounts:i=!0,showCapacityBadges:o=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=t,{width:l,height:d,left:u,right:h,topY:p,bottomY:f,midY:m,stages:y,groups:g=[]}=e,b=f-p;return jl("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:d,viewBox:`0 0 ${l} ${d}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Bl("defs",{children:jl("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Bl("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Bl("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Bl("rect",{x:0,y:0,width:l,height:d,fill:"url(#semiotic-process-floor)"}),Bl("rect",{x:u-6,y:p-8,width:h-u+12,height:b+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),n?Bl("line",{x1:u+8,x2:h-8,y1:m,y2:m,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,y.map((e,t)=>{const n=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),r=Rl[n],c=Math.max(12,e.width-8),l=Tl(c-8,22,88),u=zl(e.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,g=function(e){if(null!=e.capacity){const t=null!=e.queueDepth?" · q "+e.queueDepth:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?e.capacity+"":e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}(e),x=zl(g,Math.max(16,c-10),"auto"),v=o&&!1!==e.showBadge&&c>=32,w=null!=e.count?`n=${e.count}${null!=e.processed?" done "+e.processed:""}`:"",k=zl(w,Math.max(16,c-8),"auto"),M=Math.max(30,p-15),I=M-13;return jl("g",{"data-stage":e.id,"data-role":n,children:[Bl("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:c,height:b-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===n?1:1.6}),y.length-1>t?Bl("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:r.accent,opacity:.85}):null,h?jl($l,{children:[Bl("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-l/2,y:I,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),jl("text",{x:e.x,y:M,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Bl("title",{children:e.label}),u.text]})]}):null,v?jl("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:x.textLength,lengthAdjust:x.textLength?"spacingAndGlyphs":void 0,children:[Bl("title",{children:g}),x.text]}):null,i&&null!=e.count?jl("text",{x:e.x,y:Math.min(d-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[Bl("title",{children:w}),k.text]}):null]},e.id)}),r?g.map((e,t)=>{const n=e.total??0,i=e.absorbed??0,o=e.complete??(n>0&&i>=n),r=!o&&n>0&&i/n>=.75,s=o?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=o?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=n>0?`${i}/${n}${o?" shipped":r?" almost":""}`:"feature "+(t+1),l=Tl(Math.max(54,Nl(e.label)+18,Nl(c)+16),54,104),d=zl(e.label,l-12,"auto"),u=zl(c,l-12,"auto");return jl("g",{"data-group":e.id,children:[Bl("rect",{x:e.x-l/2,y:e.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),jl("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[Bl("title",{children:e.label}),d.text]}),jl("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Bl("title",{children:c}),u.text]})]},e.id)}):null]})}import{jsx as Fl}from"react/jsx-runtime";var Ol=Il(function(e,t){const{ballRadius:n=6,chromeOptions:i,colorBy:o,data:r,emptyContent:s,frameProps:a={},groupAnchorAlong:c,groupBy:l,groupCompletion:d,groupLabelAccessor:u,gravityX:h,gravityY:p,idAccessor:f,initialSpawnPacing:m,liveCapacity:y=!0,onCapacityChange:g,selection:b,bodyLimit:x,bodyMark:v,loading:w,loadingContent:k,paused:M,radiusAccessor:I,responsiveHeight:S,responsiveWidth:A,route:C="horizontal",seed:D=1,settle:P,springDamping:$,springStiffness:B,stageAccessor:j="stage",stages:R,workAccessor:T}=e,N=ua(e,[900,420]),{chartSize:E,showProjection:z,showChrome:W,className:F,title:O,chartMode:L,margin:q,enableHover:Y,description:H,summary:X,accessibleTable:G}=N,_=Dl(null),V=Cl(()=>qa(r??[]),[r]),U=Cl(()=>({data:V,stages:R,size:E,idAccessor:f,stageAccessor:j,groupBy:l,groupLabelAccessor:u,workAccessor:T,radiusAccessor:I,ballRadius:n,seed:D,route:C,groupCompletion:d,groupAnchorAlong:c,springStiffness:B,springDamping:$,gravityX:h,gravityY:p,settle:P}),[n,E,h,p,c,l,d,u,f,I,C,V,D,P,$,B,j,R,T]),K=Cl(()=>bs(U),[U]),Q=K.metadata;Is(t,{frameRef:_,spawnDatum:Sl((e,t)=>{const i=bs({...U,data:[e],seed:D+t+1,settle:!0}).initialSpawns[0]??{id:(e.id??"process-flow-push-"+t)+"",x:Mr(E).plot.x,y:Mr(E).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e};return{datumId:(e.id??i.id)+"",spawns:[i]}},[n,U,E,D]),seedRows:V,seedSpawns:K.initialSpawns});const Z=Cl(()=>Sr(o),[o]),J=Cl(()=>{if(!y)return a.controllers;const e=[...R.filter(e=>e.capacity&&e.capacity.unitsPerSecond>0).map(e=>{const t=e.capacity.unitsPerSecond;return io({id:"process-capacity-"+e.id,regionId:"process-stage-"+e.id,unitsPerSecond:t,unitAccessor:e.capacity.unitAccessor??(T?"string"==typeof T?T:e=>{const t=e.datum;if(!t)return 1;try{return Number(T(t,0))||1}catch{return 1}}:"work"),releaseImpulse:{x:70+Math.min(40,2*t),y:0},queueLayout:"lane",continuous:!0})}),...a.controllers??[]];return e.length?e:void 0},[a.controllers,y,R,T]),[ee,te]=Pl({}),ne=Dl(J);ne.current=J;const ie=Dl(a.onTick);ie.current=a.onTick;const oe=!1!==W||null!=g;Al(()=>{if(!g)return;const e=Object.values(ee);e.length&&g(e)},[ee,g]);const re=Sl((e,t)=>{if(ie.current?.(e,t),!oe)return;const n=ne.current;if(!n?.length)return;const i={};for(const e of n){const t=e.getSnapshot?.();t&&"string"==typeof t.regionId&&(i[t.regionId]=t)}te(e=>function(e,t){const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const i of n){const n=e[i],o=t[i];if(!o)return!1;if(n.queueDepth!==o.queueDepth||n.blockedDepth!==o.blockedDepth||n.processedCount!==o.processedCount||n.unitsPerSecond!==o.unitsPerSecond||n.regionId!==o.regionId||n.metricRevision!==o.metricRevision)return!1}return!0}(e,i)?e:i)},[oe]),se=Cl(()=>{const e=Z,t=a.bodyStyle;return v||t?(n,i)=>{const o="function"==typeof t?t(n,i):t;return{..."function"==typeof e?e(n):e,...o,mark:o?.mark??n.datum?.__physicsMark??n.datum?.mark??v}}:e},[v,Z,a.bodyStyle]),ae=ha({data:r,emptyContent:s,loading:w,loadingContent:k,size:E});if(ae)return ae;if(!R?.length)return pa("ProcessFlowChart",E,Fl("div",{role:"status",style:{width:E[0],height:E[1],display:"grid",placeItems:"center",color:"var(--semiotic-text-secondary, #64748b)"},children:"ProcessFlowChart requires a non-empty stages array."}));const ce=function(e,t,n={},i){if(!1===t||!e)return;const{volume:o,stages:r,groups:s,groupCompletion:a}=e,c=new Map(o.stages.map(e=>[e.id,e])),l=new Map(a.map(e=>[e.id,e]));return({size:e})=>{const t=Number(e[0])||o.width,a=Number(e[1])||o.height,d=r.map(e=>{const t=c.get(e.id),i=n["process-stage-"+e.id];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:i?.queueDepth,processed:i?.processedCount}}),u=s.map(e=>{const t=l.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return Wl({width:t,height:a,left:o.left,right:o.right,topY:o.topY,bottomY:o.bottomY,midY:o.midY,stages:d,groups:u},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}(Q,W,ee,i),le=function(e,t,n){if(!1===n||!t||0===e.length)return;const i=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:n})=>{const o=[Number(n[0])||t.volume.width,Number(n[1])||t.volume.height],r=Mr(o),s=Math.max(1,...e.map(e=>e.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return Fl("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,n)=>{const o=e[n];if(!o)return null;const r=i.get(t.id);if(!r)return null;const l=Math.max(2,o.value/s*a),d=Math.max(8,.35*r.width);return Fl("rect",{x:r.x-d/2,y:c,width:d,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}(K.projectionRows,Q,z),de=[...Cr(K.projectionRows,E,"stage"),...vc(Q?.groups??[])],ue=ma(e.tooltip,a),he=ya(e,a,de,{chartMode:L,className:F,title:O,description:H,summary:X,accessibleTable:G,enableHover:Y,margin:q}),pe=[...Q?.regionEffects??[],...a.regionEffects??[]];return pa("ProcessFlowChart",E,Fl(kr,{...a,...ue,...he,ref:_,controllers:J,regionEffects:pe,selection:b??a.selection,backgroundGraphics:fa(ce,a.backgroundGraphics),foregroundGraphics:fa(le,a.foregroundGraphics),initialSpawns:K.initialSpawns,initialSpawnPacing:m??K.initialSpawnPacing,onTick:re,paused:M,responsiveHeight:S,responsiveWidth:A,size:E,bodyStyle:se,config:{...K.config,...null!=x?{bodyLimit:x,eviction:"oldest"}:{},...a.config}}))});Ol.displayName="ProcessFlowChart";var Ll=[.1,.5,.9],ql=1e6;function Yl(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Hl(e,t,n,i,o){return"function"==typeof i?i(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,i??o)}function Xl(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Gl(e,t,n,i){const o=e.flatMap((e,o)=>{const r=Yl(Hl(e,o,t,n,"time")),s=Yl(Hl(e,o,t,i,"value"));return null==r||null==s?[]:[{time:Xl(r),value:s,index:o}]});o.sort((e,t)=>e.time-t.time||e.index-t.index);const r=[];for(const e of o){const t=r[r.length-1];t?.time===e.time?t.value=e.value:r.push({time:e.time,value:e.value})}return r}function _l(e,t,n,i){if(!e.length)return null;const o=e[0],r=e[e.length-1];if(o.time>t)return"clamp"===i?o.value:null;if(t>r.time)return"clamp"===i?r.value:null;const s=function(e,t){let n=0,i=e.length;for(;i>n;){const o=n+i>>>1;t>e[o].time?n=o+1:i=o}return n}(e,t),a=e[s];if(a?.time===t)return a.value;const c=e[Math.max(0,s-1)];return"step"!==n&&a&&a.time!==c.time?c.value+(t-c.time)/(a.time-c.time)*(a.value-c.value):c.value}function Vl(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,i=Math.floor(n),o=Math.ceil(n);return i===o?e[i]:e[i]+(e[o]-e[i])*(n-i)}function Ul(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",i=function(e){const t=(e??Ll).map(e=>{const t=Yl(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return Xl(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),o=function(e){if(Array.isArray(e)){if(e.length>ql)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Yl).filter(e=>null!=e).map(Xl))).sort((e,t)=>e-t)}const t=e,n=Yl(t.start),i=Yl(t.end),o=Yl(t.step);if(null==n||null==i||null==o||0>=o||n>i)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const r=Math.floor((i-n)/o)+1;if(r>ql)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const s=[],a=1e-10*Math.max(1,Math.abs(i),Math.abs(n));for(let e=0;r>e;e+=1){const t=n+e*o;if(t>i+a)break;s.push(Xl(Math.min(t,i)))}if(s.length&&a>=Math.abs(s[s.length-1]-i)||s.push(Xl(i)),s.length>ql)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(s)).sort((e,t)=>e-t)}(e.sampleAt),r=e.runs.map(t=>Gl(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:o.map(e=>{const o=r.map(i=>_l(i,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),s={};for(const e of i)s[e]=o.length?Vl(o,e):null;return{time:e,count:o.length,min:o.length?o[0]:null,max:o.length?o[o.length-1]:null,median:o.length?Vl(o,.5):null,quantiles:s}}),quantiles:i,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Kl(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function Ql(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Yl(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const i=Xl(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,i))throw Error(`comparePhysicsTrace could not find quantile ${i} in the reference envelope`);return e.quantiles[i]??null}function Zl(e,t,n){return t>e?"below":e>n?"above":"inside"}function Jl(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const i=e.value-e.lower,o=t.value-t.lower,r=e.value-e.upper,s=t.value-t.upper,a=[0,1];for(const[e,t]of[[i,o],[r,s]])(0>e&&t>0||e>0&&0>t)&&a.push(-e/(t-e));a.sort((e,t)=>e-t);let c=0,l=0,d=0;for(let i=0;a.length-1>i;i+=1){const o=a[i],r=a[i+1];if(o>=r)continue;const s=(o+r)/2,u=(r-o)*n,h=Zl(e.value+(t.value-e.value)*s,e.lower+(t.lower-e.lower)*s,e.upper+(t.upper-e.upper)*s);"below"===h?c+=u:"above"===h?d+=u:l+=u}return{below:c,inside:l,above:d,observed:n}}function ed(e,t,n={}){const i=n.interpolation??t.interpolation,o=n.outsideDomain??t.outsideDomain,r=Gl(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),s=n.lower??Kl(t,"lower"),a=n.upper??Kl(t,"upper"),c=t.points.map(e=>{const t=_l(r,e.time,i,o),n=Ql(e,s),c=Ql(e,a);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":Zl(t,n,c)}});let l=0,d=0,u=0,h=0,p=null,f=0,m=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?d+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,p=e.time),n>f&&(f=n,m=e.time)}let y=0,g=0,b=0,x=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],o=Math.max(0,n.time-t.time);if(o>0){if("linear"===i){const e=Jl(t,n);y+=e.below,g+=e.inside,b+=e.above,x+=e.observed;continue}"unobserved"!==t.status&&(x+=o,"below"===t.status?y+=o:"above"===t.status?b+=o:g+=o)}}const v=c[0]?.time,w=c[c.length-1]?.time,k=null==v||null==w?0:Math.max(0,w-v);return{points:c,sampleCount:c.length,observedSamples:l+d+u,belowSamples:l,insideSamples:d,aboveSamples:u,totalDuration:k,observedDuration:x,unobservedDuration:Math.max(0,k-x),belowDuration:y,insideDuration:g,aboveDuration:b,peakExcess:h,peakExcessAt:p,peakDeficit:f,peakDeficitAt:m}}function td(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function nd(e){const t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,td(e)]))}}function id(e,t,n={}){if("region-enter"!==t.type)return e;const i=function(e,t){const n=t.stageId?.(e);if(n)return n;const i=e.region.metadata;if(i&&"object"==typeof i){const e=i.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),o=e.stages.findIndex(e=>e.id===i);if(0>o)return e;const r=n.entityId?.(t)??t.bodyId;if(!r)return e;const s=e.entities[r]??td(r),a=s.currentStageId?e.stages.findIndex(e=>e.id===s.currentStageId):-1,c=!s.visitedStageIds.includes(i),l=Number(t.observation.timestamp),d=Number.isFinite(l)?l:0,u={...s,currentStageId:i,furthestStageId:o>s.furthestStageIndex?i:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,o),visitedStageIds:c?[...s.visitedStageIds,i]:s.visitedStageIds,visitsByStage:{...s.visitsByStage,[i]:(s.visitsByStage[i]??0)+1},firstEnteredAt:c?{...s.firstEnteredAt,[i]:d}:s.firstEnteredAt,lastEnteredAt:{...s.lastEnteredAt,[i]:d},regressionCount:a>=0&&a>o?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(r)?e.bodyIds:[...e.bodyIds,r],entities:{...e.entities,[r]:u}}}function od(e){const t=e.bodyIds.map(t=>e.entities[t]??td(t)),n=t.length;let i=n;return e.stages.map((e,o)=>{const r=t.filter(e=>e.furthestStageIndex>=o).length,s=t.filter(t=>t.visitedStageIds.includes(e.id)).length,a=t.reduce((t,n)=>t+(n.visitsByStage[e.id]??0),0),c={id:e.id,label:e.label??e.id,reached:r,entered:s,total:n,conversion:n>0?r/n:0,fromPrevious:i>0?r/i:0,dropoff:Math.max(0,i-r),visits:a,repeatVisits:Math.max(0,a-s)};return i=r,c})}function rd(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function sd(e,t,n,i){const o="function"==typeof e?e(t,n):e;return Number.isFinite(o)?Number(o):i}function ad(e,t,n){return rd(e[t])??n}function cd(e,t){return"number"==typeof e?e:e?.[t]??0}function ld(e){const{band:t,idPrefix:n,plot:i,projection:o}=e,{includeBoundaryWalls:r=!0,includeInteriorWalls:s=!0,wallThickness:a=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const i of e.values){const o=e.scale(i);Number.isFinite(o)&&(n.add(Number(o)),n.add(Number(o)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=r?c.length-1:c.length-2,d=[];for(let e=r?0:1;l>=e;e+=1){if(!s&&e>0&&c.length-1>e)continue;const t=c[e];d.push({id:`${n}-wall-${e}`,shape:"x"===o?{type:"aabb",x:t,y:i.y+i.height/2,width:a,height:i.height}:{type:"aabb",x:i.x+i.width/2,y:t,width:i.width,height:a}})}return d}function dd(e){const{plot:t,idPrefix:n="physics-scale",bounds:i={},xBins:o,xBands:r,yBands:s}=e,a=[];if(!1!==i&&a.push(...Di(t,{idPrefix:n,...i})),o){const{idPrefix:e,yTop:i,yBottom:r,...s}=o;a.push(...Pi({...s,idPrefix:e??n+"-xbin",yTop:i??t.y,yBottom:r??t.y+t.height}))}return r&&a.push(...ld({band:r,idPrefix:r.idPrefix??n+"-xband",plot:t,projection:"x"})),s&&a.push(...ld({band:s,idPrefix:s.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function ud(e){const{plot:t,rows:n,columns:i=n+1,pegRadius:o=3,idPrefix:r="galton-peg",yStart:s=t.y+.18*t.height,yEnd:a=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:d=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(i));if(0===u)return[];const p=u>1?(a-s)/(u-1):0,f=t.width/h,m=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?f/2:0;for(let i=0;h>i;i+=1){const a=t.x+f*(i+.5)+n;t.x+o>a||a>t.x+t.width-o||m.push({id:`${r}-${e}-${i}`,shape:{type:"aabb",x:a,y:s+e*p,width:2*o,height:2*o},restitution:l,friction:d})}}return m}function hd(e,t={}){const{idPrefix:n="physics-token",radius:i=5,shape:o,mass:r,vx:s,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=Bn(l),p=cd(d,"x"),f=cd(d,"y");return e.map((e,l)=>{const d=sd(t.x,e,l,ad(e,"x",0)),m=sd(t.y,e,l,ad(e,"y",0)),y=sd(i,e,l,5),g="function"==typeof o?o(e,l):o??{type:"circle",radius:y};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*p,y:m+(h()-.5)*f,vx:sd(s,e,l,0),vy:sd(a,e,l,0),mass:sd(r,e,l,1),spawnAt:sd(c,e,l,void 0),shape:g,datum:u?u(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function pd(e,t={}){const{idPrefix:n="sediment",collider:i=!0,colliderThickness:o=1,restitution:r=.05,friction:s=.2,...a}=t,c=hi(e,a),l=i?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+o/2,width:e.width,height:o},restitution:r,friction:s})):[];return{columns:c,colliders:l}}function fd(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:i=1,startAt:o=0,rebase:r=!0,sort:s=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return rd("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=a.length?Math.min(...a.map(e=>e.time)):0;return{initialSpawns:a.map(({spawn:e,time:t})=>({...e,spawnAt:o+(r?t-c:t)})).sort((e,t)=>s?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:o,timeAccessor:"spawnAt",timeScale:i}}}import{forwardRef as md,useCallback as yd,useEffect as gd,useImperativeHandle as bd,useMemo as xd,useRef as vd,useState as wd}from"react";function kd(e,t,n={}){const i=new Set,o=[...e.get(t)??[]];let r=0;for(;o.length>r;){const t=o[r];if(r+=1,!i.has(t)){i.add(t);for(const n of e.get(t)??[])o.push(n)}}return n.includeStart&&i.add(t),i}function Md(e,t,n){return nc(n,e,t)}function Id(e,t){return t>e?-1:e>t?1:0}function Sd(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Ad(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function Cd(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function Dd(e){const t=[],n=new Map,i=[],o=new Set;e.data.forEach((r,s)=>{const a=(Md(r,s,e.taskIDAccessor)??"")+"";if(!a)return void t.push({code:"duplicate-task-id",message:`Task row ${s} has an empty id.`,taskIDs:[]});if(n.has(a))return void t.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(Md(r,s,e.laneAccessor)??"Unassigned")+"";o.has(c)||(o.add(c),i.push(c));const l=Md(r,s,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(Id),u=Md(r,s,e.blockerAccessor),h=Md(r,s,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(Md(r,s,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:s,datum:r,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:Md(r,s,e.startAccessor),end:Md(r,s,e.endAccessor),progress:Cd(Md(r,s,e.progressAccessor)),status:h,completionTime:Md(r,s,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!Md(r,s,e.milestoneAccessor)})});const r=e.laneOrder?[...e.laneOrder,...i.filter(t=>!e.laneOrder?.includes(t))]:i,s=new Map(r.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=s.get(e.lane)??0;const a=new Map,c=new Map;for(const e of n.keys())a.set(e,[]),c.set(e,[]);const l=[],d=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of d)e.dependencyIDs.forEach((i,o)=>{const r=n.get(i);if(!r)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${i}".`,taskIDs:[e.id,i]});const s={id:Sd(i,e.id),sourceID:i,targetID:e.id,sourceIndex:r.index,targetIndex:e.index,socketID:Ad(e.id,o),socketIndex:o};l.push(s),a.get(e.id)?.push(s),c.get(i)?.push(s),e.incomingEdgeIDs.push(s.id),e.socketIDs.push(s.socketID),r.outgoingEdgeIDs.push(s.id)});for(const e of a.values())e.sort((e,t)=>Id(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=Ad(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>Id(e.targetID,t.targetID));for(const e of n.values()){const t=a.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(c.get(e.id)??[]).map(e=>e.id)}const u=new Map,h=new Map;for(const e of n.keys())u.set(e,a.get(e)?.length??0),h.set(e,0);const p=[...n.keys()].filter(e=>0===u.get(e)).sort(Id);let f=0;for(;p.length;){const e=p.shift();f+=1;for(const t of c.get(e)??[]){const n=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,n);const i=(u.get(t.targetID)??0)-1;if(u.set(t.targetID,i),0===i){const e=p.findIndex(e=>e>t.targetID);0>e?p.push(t.targetID):p.splice(e,0,t.targetID)}}}if(f!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(Id);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let m=0;const y=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of y)e.level=h.get(e.id)??0,m=Math.max(m,e.level);return{nodes:y,edges:l,byID:n,incoming:a,outgoing:c,lanes:r,maxLevel:m,diagnostics:t,valid:0===t.length}}function Pd(e,t,n={}){const i=Math.max(240,t.width),o=Math.max(220,t.height),r=t.paddingX??48,s=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(i-2*r)/Math.max(1,e.lanes.length)),l=Math.max(76,(o-s-a)/Math.max(1,e.maxLevel+1)),d=Math.min(n.taskWidth??112,Math.max(58,.78*c)),u=Math.min(n.taskHeight??58,.64*l),h=n.socketRadius??5,p=Math.max(1,Math.round(n.gutterCount??3)),f=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=f.get(e)??[];n.push(t),f.set(e,n)}for(const e of f.values())e.sort((e,t)=>Id(e.id,t.id));const m=e.nodes.map(e=>{const t=f.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id));return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:r+c*(e.laneIndex+.5),y:s+l*(e.level+.5)+(n-(t.length-1)/2)*Math.min(18,.3*u),width:d,height:u}}),y=new Map(m.map(e=>[e.taskID,e])),g=[],b=[];e.edges.forEach((t,n)=>{const i=y.get(t.sourceID),o=y.get(t.targetID);if(!i||!o)return;const r=e.incoming.get(t.targetID)??[],s=Math.min(.72*o.width,14*Math.max(1,r.length-1)),a=r.length>1?o.x-s/2+s*t.socketIndex/(r.length-1):o.x,c=o.y-o.height/2-h-2;g.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:a,y:c,radius:h});const l={x:i.x,y:i.y+i.height/2+3},d=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(n%p-(p-1)/2));var u;b.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(u=[l,{x:l.x,y:d},{x:a,y:d},{x:a,y:c}],u.filter((e,t)=>{const n=u[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const x=new Map(g.map(e=>[e.id,e])),v=new Map(b.map(e=>[e.edgeID,e]));return{tasks:m,sockets:g,routes:b,taskByID:y,socketByID:x,routeByEdgeID:v}}function $d(e,t,n="all"){const i=Array.from(new Set(t)).sort(Id),o=new Set,r=()=>i.every(e=>o.has(e));return{taskID:e,mode:n,incomingEdgeIDs:i,deliver:e=>i.includes(e)?(o.add(e),r()):r(),reset:(e=[])=>{o.clear();for(const t of e)i.includes(t)&&o.add(t)},isSatisfied:r,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...i],deliveredEdgeIDs:[...o].sort(Id),satisfied:r()})}}function Bd(e){return e instanceof Date?e.getTime():Number(e)}function jd(e,t){const n=Bd("object"!=typeof t||t instanceof Date?t:t.currentTime),i=e.map((e,t)=>({event:e,index:t,time:Bd(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),o=new Set,r=new Map,s=new Set,a=new Set;for(const{event:e}of i)"task-completed"===e.type?(o.add(e.taskID),r.delete(e.taskID)):"task-blocked"===e.type?r.set(e.taskID,e.reason):"task-unblocked"===e.type?r.delete(e.taskID):"dependency-delivered"===e.type?s.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:i.map(e=>e.event),completedTaskIDs:o,blockedByTaskID:r,deliveredEdgeIDs:s,armedTaskIDs:a}}function Rd(e,t,n={}){const i=new Set(n.completedTaskIDs??[]),o=[...kd(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(n.isComplete?n.isComplete(e):i.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),r=Array.from(new Set(o.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:o.length,affectedLaneCount:r.length,downstreamTaskIDs:o.map(e=>e.id),affectedLanes:r}}var Td=[];function Nd(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function Ed(e){if(null==e.completionTime)return null;const t=Nd(e.completionTime,NaN);return Number.isFinite(t)?t:null}function zd(e,t,n,i){const o=new Set;for(const r of e.nodes){const s=e.incoming.get(r.id)??[];(i.has(r.id)||!n.has(r.id)&&s.every(e=>t.has(e.id)))&&o.add(r.id)}return o}function Wd(e,t,n,i){const o=e.nodes.map(Ed).filter(e=>null!=e),r=o.length?Math.min(...o)-1:0,s="replay"!==t||i?n:r,a=new Set,c=new Map;for(const n of e.nodes){const e=Ed(n);(null!=e&&s>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const l=new Set;if("replay"!==t||i)for(const t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:s,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:zd(e,l,c,a),blockers:c,previewTaskID:null}}function Fd(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function Od(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function Ld(e){const t=Od(e.body);if(!t||2>t.route.length)return null;const n=function(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}(t.route),i=function(e,t){let n=1/0,i=0,o=0;for(let r=1;t.length>r;r+=1){const s=t[r-1],a=t[r],c=a.x-s.x,l=a.y-s.y,d=c*c+l*l,u=Math.sqrt(d);if(0>=u)continue;const h=Math.max(0,Math.min(1,((e.x-s.x)*c+(e.y-s.y)*l)/d)),p=Math.hypot(e.x-(s.x+c*h),e.y-(s.y+l*h));n>p&&(n=p,i=o+h*u),o+=u}return i}(e.body,t.route),o=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let i=1;e.length>i;i+=1){const o=e[i-1],r=e[i],s=r.x-o.x,a=r.y-o.y,c=Math.hypot(s,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:o.x+s*e,y:o.y+a*e},tangent:{x:s/c,y:a/c}}}n+=c}}const i=e[e.length-2],o=e[e.length-1],r=o.x-i.x,s=o.y-i.y,a=Math.hypot(r,s)||1;return{point:o,tangent:{x:r/a,y:s/a}}}(t.route,Math.min(n,i+22));return{x:2.5*(78*o.tangent.x-e.body.vx)+8*(o.point.x-e.body.x),y:2.5*(78*o.tangent.y-e.body.vy)+8*(o.point.y-e.body.y)}}function qd(e,t){const n=t.points[0]??{x:0,y:0},i=t.points[1]??n,o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:o/s*42,vy:r/s*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as Yd,jsxs as Hd}from"react/jsx-runtime";function Xd({machine:e,layout:t,runtime:n,downstreamSet:i,selectedSet:o,width:r,height:s,seed:a,reduced:c,onSelectTask:l}){return Hd("svg",{"aria-hidden":"true",width:r,height:s,viewBox:`0 0 ${r} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Yd("defs",{children:Yd("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Yd("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const i=t.tasks.filter(e=>e.laneIndex===n),o=i[0]?.x??0;return Hd("g",{children:[Yd("line",{x1:o,x2:o,y1:32,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Yd("text",{x:o,y:23,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),o=n.inFlight.has(e.edgeID),r=i.has(e.targetID)||i.has(e.sourceID),s=e.points.map(e=>`${e.x},${e.y}`).join(" ");return Yd("polyline",{points:s,fill:"none",stroke:r?"var(--semiotic-highlight, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:r?4:o?3:2,strokeOpacity:t||o||r?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return Hd("g",{children:[Yd("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-background, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&Yd("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const r=t.taskByID.get(e.id);if(!r)return null;const s=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=o.has(e.id)||u,p=i.has(e.id),f=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-muted, #75818a)"}(e,n),m=r.x-r.width/2,y=r.y-r.height/2,g=Math.max(2,r.height*e.progress);return Hd("g",{children:[Hd("g",{style:{transform:`rotate(${s?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[Yd("rect",{x:m,y:y,width:r.width,height:r.height,rx:e.milestone?12:4,fill:"var(--semiotic-background, #fff)",stroke:h||p?"var(--semiotic-highlight, #e08a1e)":f,strokeWidth:h?4:p?3:2}),Yd("rect",{x:m+3,y:y+r.height-g+1,width:r.width-6,height:Math.max(0,g-4),rx:2,fill:f,opacity:s?.86:.46})]}),d&&Hd("g",{opacity:u?.28:1,children:[Yd("line",{x1:m-8,x2:m+14,y1:r.y+9,y2:r.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Yd("circle",{cx:m-8,cy:r.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Hd("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Yd("rect",{x:m,y:y,width:r.width,height:r.height,fill:"transparent"}),Yd("text",{x:r.x,y:r.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),Hd("text",{x:r.x,y:r.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-muted, #5f6b72)",children:[Math.round(100*e.progress),"% · ",s?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as Gd,jsxs as _d}from"react/jsx-runtime";var Vd={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},Ud=md(function(e,t){const{data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p,mode:f="snapshot",insight:m="blocker-amplification",currentTime:y,controls:g=!1,selectedTaskIDs:b,onSelectionChange:x,onObservation:v,reducedMotion:w,seed:k=31,width:M=920,height:I=620,responsiveWidth:S,responsiveHeight:A,title:C="Dependency chain reaction",description:D,className:P,accessibleTable:$=!0,enableHover:B=!0}=e,j=vd(null),[R,T]=wd([]),N=b?Array.from(b):R,E=xd(()=>new Set(N),[N]),z=Nd(y,1/0),W="settle"===w,F=xd(()=>Dd({data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p}),[n,i,o,r,s,a,c,l,d,u,h,p]),O=xd(()=>Pd(F,{width:M,height:I}),[F,M,I]),[L,q]=wd(()=>Wd(F,f,z,W)),Y=vd(L),H=yd(e=>{Y.current=e,q(e)},[]),X=yd(e=>v?.(e),[v]);gd(()=>{const e=Wd(F,f,z,W);j.current?.clear(),Y.current=e,q(e)},[F,f,z,W]);const G=yd(e=>{const t=E.has(e)?N.filter(t=>t!==e):[e];b||T(t),x?.(t)},[b,x,E,N]),_=yd(e=>{if(W)return;const t=Fd(Y.current),n=[];for(const i of F.outgoing.get(e)??[]){if(t.delivered.has(i.id)||t.inFlight.has(i.id))continue;const e=O.routeByEdgeID.get(i.id);e&&(t.inFlight.add(i.id),n.push(qd(i,e)))}n.length&&(H(t),j.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[H,O,F,W]),V=yd((e,t)=>{const n=F.byID.get(e),i=Y.current;if(!n||i.completed.has(e))return;const o=Fd(i);o.completed.add(e),o.blockers.delete(e),o.armed.add(e),null!=t&&(o.currentTime=t),H(o),X({type:"task-completed",taskID:e,datum:n.datum}),_(e)},[H,X,F,_]),U=yd(e=>{const t=Fd(Y.current),n=[],i=[];for(const i of e){if(t.delivered.has(i))continue;const e=F.edges.find(e=>e.id===i);e&&(t.delivered.add(i),t.inFlight.delete(i),n.push(e))}for(const e of n){const n=F.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(F.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),i.push(n.id))}if(n.length){H(t);for(const e of n)X({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of i)X({type:"task-armed",taskID:e})}},[H,X,F]),K=yd((e,t)=>{const n=[],i=[];for(const e of t.readBodies()){const t=Od(e);if(!t||Y.current.delivered.has(t.edgeID))continue;const o=t.route[t.route.length-1];o&&9>=Math.hypot(e.x-o.x,e.y-o.y)&&(n.push(t.edgeID),i.push(e.id))}i.length&&t.remove(i),n.length&&U(n)},[U]),Q=yd(()=>{const e=Fd(Y.current);for(const t of F.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=zd(F,e.delivered,e.blockers,e.completed),e.playing=!1,j.current?.settle(),H(e),X({type:"machine-settled"})},[H,X,F]),Z=yd(()=>{const e=Fd(Y.current);e.playing=!1,H(e)},[H]),J=yd(()=>{const e=Y.current,t=F.nodes.map(e=>({node:e,time:Ed(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void V(t.node.id,t.time);Z();const n=[...e.blockers.keys()].map(t=>Rd(F,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&X({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[X,F,Z,V]),ee=yd(()=>{if(W)return void Q();const e=Fd(Y.current);e.playing=!0,H(e)},[H,W,Q]);gd(()=>{if(!L.playing||"replay"!==f||W)return;const e=window.setInterval(J,760);return()=>window.clearInterval(e)},[f,W,L.playing,J]);const te=yd(()=>{j.current?.clear(),H(Wd(F,f,z,W))},[H,F,f,z,W]),ne=yd(e=>{if(!F.byID.has(e))return;const t=Fd(Y.current);t.previewTaskID=e,H(t);const n=Rd(F,e,{completedTaskIDs:t.completed});X({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[H,X,F]),ie=yd(()=>{const e=Fd(Y.current);e.previewTaskID=null,H(e)},[H]),oe=yd((e,t)=>{if(!F.byID.has(e))return;const n=Fd(Y.current);n.blockers.set(e,t),n.armed.delete(e),H(n)},[H,F]),re=yd(e=>{if(!F.byID.has(e))return;const t=Fd(Y.current);t.blockers.delete(e),(F.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),H(t)},[H,F]),se=yd(e=>Rd(F,e,{completedTaskIDs:Y.current.completed}),[F]),ae=yd(()=>{const e=Y.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...N],tasks:F.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:F.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[F,N]);bd(t,()=>({play:ee,pause:Z,step:J,reset:te,settle:Q,previewResolve:ne,clearPreview:ie,completeTask:V,blockTask:oe,unblockTask:re,getAmplification:se,getMachineState:ae}),[oe,ie,se,ae,Z,V,ee,ne,te,Q,J,re]);const ce=L.previewTaskID??N[0]??null,le=ce?Rd(F,ce,{completedTaskIDs:L.completed}):null,de=xd(()=>new Set(le?.downstreamTaskIDs??[]),[le?.downstreamTaskIDs.join("|")]),ue=xd(()=>function(e,t,n){return e.nodes.flatMap(i=>{const o=t.taskByID.get(i.id);if(!o)return[];const r=e.incoming.get(i.id)??[],s=r.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(i.id),c=n.completed.has(i.id)?"completed":a?"blocked: "+a:n.armed.has(i.id)?"armed":"waiting";return[{id:i.id,label:`${i.label}, ${i.lane}, ${Math.round(100*i.progress)}%, ${c}`,description:`${s} of ${r.length} prerequisites delivered.`,datum:i.datum,x:o.x,y:o.y,width:o.width,height:o.height,shape:"rect",group:i.lane}]})}(F,O,L),[O,F,L]),he=xd(()=>Gd(Xd,{machine:F,layout:O,runtime:L,downstreamSet:de,selectedSet:E,width:M,height:I,seed:k,reduced:W,onSelectTask:G}),[de,I,O,F,W,L,k,G,E,M]),pe=xd(()=>{const e=[...L.blockers.keys()].map(e=>Rd(F,e,{completedTaskIDs:L.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${F.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[F,L.blockers,L.completed]),fe=xd(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:I,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:M-2,y1:0,x2:M-2,y2:I,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:M,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:I-2,x2:M,y2:I-2,thickness:4}}],[I,M]),me=!0===g?["play","pause","step","reset","settle"]:g||[];return _d("div",F.valid?{className:P,style:{width:M,maxWidth:"100%",position:"relative"},children:[me.length>0&&Gd("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:me.map(e=>Gd("button",{type:"button",onClick:"play"===e?ee:"pause"===e?Z:"step"===e?J:"reset"===e?te:Q,"aria-pressed":"play"===e?L.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),Gd(kr,{ref:j,size:[M,I],responsiveWidth:S,responsiveHeight:A,title:C,description:D??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${pe}${le&&"blocker-amplification"===m?` Selected task reaches ${le.downstreamTaskCount} unfinished tasks across ${le.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:B,initialSpawns:Td,bodyForces:Ld,bodyStyle:{fill:"var(--semiotic-accent, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:ue,onSemanticItemActivate:e=>e.id&&G(e.id),foregroundGraphics:()=>he,paused:W,continuous:L.inFlight.size>0,onTick:K,config:{bodyLimit:Math.max(16,F.edges.length+4),colliders:fe,settleStepLimit:2200,kernel:{seed:k,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),$&&_d("table",{style:Vd,children:[Gd("caption",{children:pe}),Gd("thead",{children:_d("tr",{children:[Gd("th",{children:"Task"}),Gd("th",{children:"Lane"}),Gd("th",{children:"Progress"}),Gd("th",{children:"State"}),Gd("th",{children:"Waiting on"}),Gd("th",{children:"Downstream reach"})]})}),Gd("tbody",{children:F.nodes.map(e=>{const t=Rd(F,e.id,{completedTaskIDs:L.completed});return _d("tr",{children:[Gd("th",{scope:"row",children:e.label}),Gd("td",{children:e.lane}),_d("td",{children:[Math.round(100*e.progress),"%"]}),Gd("td",{children:L.completed.has(e.id)?"Completed":L.blockers.has(e.id)?"Blocked":L.armed.has(e.id)?"Armed":"Waiting"}),Gd("td",{children:L.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!L.completed.has(e)).join(", ")||"None")}),_d("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:P,role:"alert",style:{width:M,maxWidth:"100%"},children:[Gd("strong",{children:"ChainReactionChart could not compile this dependency graph."}),Gd("ul",{children:F.diagnostics.map((e,t)=>Gd("li",{children:e.message},`${e.code}-${t}`))})]})});Ud.displayName="ChainReactionChart";var Kd=kr;export{ei as BuiltInPhysicsEngineAdapter,Ud as ChainReactionChart,ec as CollisionSwarmChart,Ca as EventDropChart,va as GaltonBoardChart,sl as GauntletChart,al as GuantletChart,Ml as PhysicalFlowChart,Ga as PhysicsCustomChart,Ta as PhysicsPileChart,Yi as PhysicsPipelineStore,xn as PhysicsSVGOverlay,ui as PhysicsSedimentAccumulator,Ol as ProcessFlowChart,wr as StreamPhysicsFrame,ps as absorbRegion,Kr as aggregateRegionCounts,fd as arrivalReplay,yn as bodiesToAnnotationAnchors,ms as bodyGroupSpec,qr as buildCollisionSwarmPhysics,Wr as buildEventDropPhysics,Nr as buildGaltonBoardPhysics,Ur as buildPhysicalFlowPhysics,gn as buildPhysicsAnnotationContext,Or as buildPhysicsPile,bs as buildProcessFlowPhysics,Rd as calculateBlockerAmplification,us as capacitatedRegion,cs as chargeGateRegion,dd as collidersFromScales,ed as comparePhysicsTrace,Dd as compileDependencyMachine,ic as compileMotionEncoding,cc as compilePhysicsEncoding,ho as composePhysicsControllers,io as createCapacityQueueController,ti as createDefaultPhysicsEngineAdapter,lo as createDependencyGateController,$d as createLogicalJoin,lc as createPhysicsEncodingLayout,po as createPortalController,nd as createProcessJourneyLedger,co as createServiceLevelController,so as createServiceResourcePoolController,Kd as default,ac as deriveMotionVector,fi as evaluatePhysicsBodyBudget,fs as forceFieldRegion,ud as galtonPegs,Zr as groupCompletionRows,as as membraneRegion,bn as normalizePhysicsAnnotations,rc as opacityFromAge,gc as physicsProcessBoundaryColliders,vc as physicsProcessGroupSemanticItems,bc as physicsProcessRegionSemanticItem,xc as physicsProcessStageSemanticItems,Ul as physicsReferenceEnvelope,Lc as planGauntletPropertyWork,hs as portalRegion,ds as pressureFieldRegion,Wl as processChrome,od as processJourneyRows,ys as processLaneWalls,os as processStageLayout,ss as processStageRegions,ts as processVolumePolygons,Qr as regionCountsToProjectionRows,qc as replaceGauntletNegative,jd as replayStateTransitions,nc as resolveMotionAccessor,oc as resolveMotionAge,sc as resolveMotionVector,Pd as routeDependencyTracks,ls as routeSurfaceRegion,pd as sedimentBake,hi as sedimentHeightfield,hd as spawnFromTokens,es as stageTargetInVolume,id as updateProcessJourney};
|
|
2
|
+
import{createProcessJourneyLedger as e,processJourneyRows as t,updateProcessJourney as n}from"./chunk-chunk-YWZB3KPI.module.min.js";import{BuiltInPhysicsEngineAdapter as s,CollisionSwarmChart as i,EventDropChart as o,GaltonBoardChart as r,GauntletChart as a,GuantletChart as c,PhysicalFlowChart as l,PhysicsCustomChart as d,PhysicsPileChart as u,PhysicsPipelineStore as h,PhysicsSVGOverlay as m,PhysicsSedimentAccumulator as p,ProcessFlowChart as f,StreamPhysicsFrame as g,StreamPhysicsFrame_default as y,absorbRegion as k,aggregateRegionCounts as x,bodiesToAnnotationAnchors as b,bodyGroupSpec as v,buildCollisionSwarmPhysics as w,buildEventDropPhysics as I,buildGaltonBoardPhysics as D,buildPhysicalFlowPhysics as M,buildPhysicsAnnotationContext as A,buildPhysicsPile as T,buildProcessFlowPhysics as S,capacitatedRegion as C,chargeGateRegion as $,collidersFromPlotBounds as E,collidersFromXScaleBins as N,composePhysicsControllers as j,createCapacityQueueController as R,createDefaultPhysicsEngineAdapter as P,createDependencyGateController as W,createPortalController as B,createServiceLevelController as F,createServiceResourcePoolController as L,evaluatePhysicsBodyBudget as q,forceFieldRegion as O,groupCompletionRows as z,membraneRegion as U,normalizePhysicsAnnotations as Z,physicsProcessBoundaryColliders as H,physicsProcessGroupSemanticItems as X,physicsProcessRegionSemanticItem as Y,physicsProcessStageSemanticItems as J,planGauntletPropertyWork as K,portalRegion as V,pressureFieldRegion as G,processChrome as Q,processLaneWalls as _,processStageLayout as ee,processStageRegions as te,processVolumePolygons as ne,regionCountsToProjectionRows as se,replaceGauntletNegative as ie,routeSurfaceRegion as oe,sedimentHeightfield as re,stageTargetInVolume as ae}from"./chunk-chunk-Z5KXAVQD.module.min.js";import{mulberry32 as ce}from"./chunk-chunk-SIRIJ3DY.module.min.js";import{composeStyleRules as le,makeRuleValueResolver as de,matchesThreshold as ue,resolveStyleRules as he,ruleMatches as me}from"./chunk-chunk-EMO5NUGE.module.min.js";import"./chunk-chunk-SV4XAZ3Q.module.min.js";import"./chunk-chunk-STZFFTAN.module.min.js";import{compileMotionEncoding as pe,deriveMotionVector as fe,hatchFillId as ge,hatchPatternDef as ye,isHatchFill as ke,opacityFromAge as xe,resolveMotionAccessor as be,resolveMotionAge as ve,resolveMotionVector as we,resolveSvgFill as Ie}from"./chunk-chunk-ODUZEEBH.module.min.js";import"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-WCX6U47H.module.min.js";import"./chunk-chunk-KTWEBFMX.module.min.js";import"./chunk-chunk-ZCNBUZPL.module.min.js";import"./chunk-chunk-YHNZCPOZ.module.min.js";function De(e){const{data:t,encoding:n,defaults:s={},scales:i}=e,o=pe({data:t,encoding:n}),r=[],a=new Map,c=[],l=[],d=new Map;return o.rows.forEach((e,t)=>{const{id:o,datum:u}=e,h=Math.max(0,be(n.appearance?.size,u,t)??s.size??6),m=be(n.appearance?.shape,u,t)??s.shape??{type:"circle",radius:h},p=e.placement.x??s.x??0,f=e.placement.y??s.y??0,g=i?.x?i.x(p):p,y=i?.y?i.y(f):f,k=be(n.appearance?.color,u,t)??s.color,x=be(n.appearance?.opacity,u,t)??s.opacity,b=be(n.appearance?.stroke,u,t)??s.stroke,v=be(n.appearance?.strokeWidth,u,t)??s.strokeWidth,w=be(n.time?.spawnAt,u,t)??e.time.arrival,I=e.kinematics.velocityX,D=e.kinematics.velocityY,M=be(n.dynamics?.mass,u,t)??s.mass??1,A=be(n.dynamics?.friction,u,t),T=be(n.dynamics?.restitution,u,t),S=be(n.dynamics?.bodyCollisions,u,t),C={id:o,x:g,y:y,mass:M,shape:{...m},datum:u,...null!=w&&{spawnAt:w},...null!=I&&{vx:I},...null!=D&&{vy:D},...null!=A&&{friction:A},...null!=T&&{restitution:T},...null!=S&&{bodyCollisions:S}},$={...null!=k&&{fill:k},...null!=x&&{opacity:x},...null!=b&&{stroke:b},...null!=v&&{strokeWidth:v}},E={id:o,datum:u,appearance:{color:k,opacity:x,shape:m,size:h,stroke:b,strokeWidth:v},placement:{x:g,y:y,lane:e.placement.lane,space:n.placement?.space??"world"},time:{arrival:w,spawnAt:w,basis:n.time?.basis??"simulation",unit:n.time?.unit},kinematics:{velocityX:I,velocityY:D,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:S,friction:A,mass:M,restitution:T},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:C};r.push(E),a.set(o,E),c.push(C),d.set(o,$),l.push({id:o,bodyId:o,label:e.accessible.label,description:e.accessible.description,datum:u,x:g,y:y,group:e.accessible.group})}),{rows:r,byId:a,spawns:c,semanticItems:l,bodyStyle:e=>d.get(e.id)??{}}}function Me(e){return t=>{const n=De({data:t.data,encoding:e.encoding,defaults:e.defaults,scales:t.scales}),s=e.extend?.(t,n)??{};return{...s,initialSpawns:n.spawns,bodyStyle:n.bodyStyle,semanticItems:[...n.semanticItems,...s.semanticItems??[]]}}}var Ae=[.1,.5,.9],Te=1e6;function Se(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ce(e,t,n,s,i){return"function"==typeof s?s(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,s??i)}function $e(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Ee(e,t,n,s){const i=e.flatMap((e,i)=>{const o=Se(Ce(e,i,t,n,"time")),r=Se(Ce(e,i,t,s,"value"));return null==o||null==r?[]:[{time:$e(o),value:r,index:i}]});i.sort((e,t)=>e.time-t.time||e.index-t.index);const o=[];for(const e of i){const t=o[o.length-1];t?.time===e.time?t.value=e.value:o.push({time:e.time,value:e.value})}return o}function Ne(e,t,n,s){if(!e.length)return null;const i=e[0],o=e[e.length-1];if(i.time>t)return"clamp"===s?i.value:null;if(t>o.time)return"clamp"===s?o.value:null;const r=function(e,t){let n=0,s=e.length;for(;s>n;){const i=n+s>>>1;t>e[i].time?n=i+1:s=i}return n}(e,t),a=e[r];if(a?.time===t)return a.value;const c=e[Math.max(0,r-1)];return"step"!==n&&a&&a.time!==c.time?c.value+(t-c.time)/(a.time-c.time)*(a.value-c.value):c.value}function je(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,s=Math.floor(n),i=Math.ceil(n);return s===i?e[s]:e[s]+(e[i]-e[s])*(n-s)}function Re(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",s=function(e){const t=(e??Ae).map(e=>{const t=Se(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return $e(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),i=function(e){if(Array.isArray(e)){if(e.length>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Se).filter(e=>null!=e).map($e))).sort((e,t)=>e-t)}const t=e,n=Se(t.start),s=Se(t.end),i=Se(t.step);if(null==n||null==s||null==i||0>=i||n>s)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const o=Math.floor((s-n)/i)+1;if(o>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const r=[],a=1e-10*Math.max(1,Math.abs(s),Math.abs(n));for(let e=0;o>e;e+=1){const t=n+e*i;if(t>s+a)break;r.push($e(Math.min(t,s)))}if(r.length&&a>=Math.abs(r[r.length-1]-s)||r.push($e(s)),r.length>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(r)).sort((e,t)=>e-t)}(e.sampleAt),o=e.runs.map(t=>Ee(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:i.map(e=>{const i=o.map(s=>Ne(s,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),r={};for(const e of s)r[e]=i.length?je(i,e):null;return{time:e,count:i.length,min:i.length?i[0]:null,max:i.length?i[i.length-1]:null,median:i.length?je(i,.5):null,quantiles:r}}),quantiles:s,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Pe(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function We(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Se(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const s=$e(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,s))throw Error(`comparePhysicsTrace could not find quantile ${s} in the reference envelope`);return e.quantiles[s]??null}function Be(e,t,n){return t>e?"below":e>n?"above":"inside"}function Fe(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const s=e.value-e.lower,i=t.value-t.lower,o=e.value-e.upper,r=t.value-t.upper,a=[0,1];for(const[e,t]of[[s,i],[o,r]])(0>e&&t>0||e>0&&0>t)&&a.push(-e/(t-e));a.sort((e,t)=>e-t);let c=0,l=0,d=0;for(let s=0;a.length-1>s;s+=1){const i=a[s],o=a[s+1];if(i>=o)continue;const r=(i+o)/2,u=(o-i)*n,h=Be(e.value+(t.value-e.value)*r,e.lower+(t.lower-e.lower)*r,e.upper+(t.upper-e.upper)*r);"below"===h?c+=u:"above"===h?d+=u:l+=u}return{below:c,inside:l,above:d,observed:n}}function Le(e,t,n={}){const s=n.interpolation??t.interpolation,i=n.outsideDomain??t.outsideDomain,o=Ee(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),r=n.lower??Pe(t,"lower"),a=n.upper??Pe(t,"upper"),c=t.points.map(e=>{const t=Ne(o,e.time,s,i),n=We(e,r),c=We(e,a);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":Be(t,n,c)}});let l=0,d=0,u=0,h=0,m=null,p=0,f=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?d+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,m=e.time),n>p&&(p=n,f=e.time)}let g=0,y=0,k=0,x=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],i=Math.max(0,n.time-t.time);if(i>0){if("linear"===s){const e=Fe(t,n);g+=e.below,y+=e.inside,k+=e.above,x+=e.observed;continue}"unobserved"!==t.status&&(x+=i,"below"===t.status?g+=i:"above"===t.status?k+=i:y+=i)}}const b=c[0]?.time,v=c[c.length-1]?.time,w=null==b||null==v?0:Math.max(0,v-b);return{points:c,sampleCount:c.length,observedSamples:l+d+u,belowSamples:l,insideSamples:d,aboveSamples:u,totalDuration:w,observedDuration:x,unobservedDuration:Math.max(0,w-x),belowDuration:g,insideDuration:y,aboveDuration:k,peakExcess:h,peakExcessAt:m,peakDeficit:p,peakDeficitAt:f}}function qe(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Oe(e,t,n,s){const i="function"==typeof e?e(t,n):e;return Number.isFinite(i)?Number(i):s}function ze(e,t,n){return qe(e[t])??n}function Ue(e,t){return"number"==typeof e?e:e?.[t]??0}function Ze(e){const{band:t,idPrefix:n,plot:s,projection:i}=e,{includeBoundaryWalls:o=!0,includeInteriorWalls:r=!0,wallThickness:a=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const s of e.values){const i=e.scale(s);Number.isFinite(i)&&(n.add(Number(i)),n.add(Number(i)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=o?c.length-1:c.length-2,d=[];for(let e=o?0:1;l>=e;e+=1){if(!r&&e>0&&c.length-1>e)continue;const t=c[e];d.push({id:`${n}-wall-${e}`,shape:"x"===i?{type:"aabb",x:t,y:s.y+s.height/2,width:a,height:s.height}:{type:"aabb",x:s.x+s.width/2,y:t,width:s.width,height:a}})}return d}function He(e){const{plot:t,idPrefix:n="physics-scale",bounds:s={},xBins:i,xBands:o,yBands:r}=e,a=[];if(!1!==s&&a.push(...E(t,{idPrefix:n,...s})),i){const{idPrefix:e,yTop:s,yBottom:o,...r}=i;a.push(...N({...r,idPrefix:e??n+"-xbin",yTop:s??t.y,yBottom:o??t.y+t.height}))}return o&&a.push(...Ze({band:o,idPrefix:o.idPrefix??n+"-xband",plot:t,projection:"x"})),r&&a.push(...Ze({band:r,idPrefix:r.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function Xe(e){const{plot:t,rows:n,columns:s=n+1,pegRadius:i=3,idPrefix:o="galton-peg",yStart:r=t.y+.18*t.height,yEnd:a=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:d=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(s));if(0===u)return[];const m=u>1?(a-r)/(u-1):0,p=t.width/h,f=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?p/2:0;for(let s=0;h>s;s+=1){const a=t.x+p*(s+.5)+n;t.x+i>a||a>t.x+t.width-i||f.push({id:`${o}-${e}-${s}`,shape:{type:"aabb",x:a,y:r+e*m,width:2*i,height:2*i},restitution:l,friction:d})}}return f}function Ye(e,t={}){const{idPrefix:n="physics-token",radius:s=5,shape:i,mass:o,vx:r,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=ce(l),m=Ue(d,"x"),p=Ue(d,"y");return e.map((e,l)=>{const d=Oe(t.x,e,l,ze(e,"x",0)),f=Oe(t.y,e,l,ze(e,"y",0)),g=Oe(s,e,l,5),y="function"==typeof i?i(e,l):i??{type:"circle",radius:g};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*m,y:f+(h()-.5)*p,vx:Oe(r,e,l,0),vy:Oe(a,e,l,0),mass:Oe(o,e,l,1),spawnAt:Oe(c,e,l,void 0),shape:y,datum:u?u(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function Je(e,t={}){const{idPrefix:n="sediment",collider:s=!0,colliderThickness:i=1,restitution:o=.05,friction:r=.2,...a}=t,c=re(e,a),l=s?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+i/2,width:e.width,height:i},restitution:o,friction:r})):[];return{columns:c,colliders:l}}function Ke(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:s=1,startAt:i=0,rebase:o=!0,sort:r=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return qe("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=a.length?Math.min(...a.map(e=>e.time)):0;return{initialSpawns:a.map(({spawn:e,time:t})=>({...e,spawnAt:i+(o?t-c:t)})).sort((e,t)=>r?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:i,timeAccessor:"spawnAt",timeScale:s}}}import{forwardRef as Ve,useCallback as Ge,useEffect as Qe,useImperativeHandle as _e,useMemo as et,useRef as tt,useState as nt}from"react";function st(e,t,n={}){const s=new Set,i=[...e.get(t)??[]];let o=0;for(;i.length>o;){const t=i[o];if(o+=1,!s.has(t)){s.add(t);for(const n of e.get(t)??[])i.push(n)}}return n.includeStart&&s.add(t),s}function it(e,t,n){return be(n,e,t)}function ot(e,t){return t>e?-1:e>t?1:0}function rt(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function at(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function ct(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function lt(e){const t=[],n=new Map,s=[],i=new Set;e.data.forEach((o,r)=>{const a=(it(o,r,e.taskIDAccessor)??"")+"";if(!a)return void t.push({code:"duplicate-task-id",message:`Task row ${r} has an empty id.`,taskIDs:[]});if(n.has(a))return void t.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(it(o,r,e.laneAccessor)??"Unassigned")+"";i.has(c)||(i.add(c),s.push(c));const l=it(o,r,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(ot),u=it(o,r,e.blockerAccessor),h=it(o,r,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(it(o,r,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:r,datum:o,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:it(o,r,e.startAccessor),end:it(o,r,e.endAccessor),progress:ct(it(o,r,e.progressAccessor)),status:h,completionTime:it(o,r,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!it(o,r,e.milestoneAccessor)})});const o=e.laneOrder?[...e.laneOrder,...s.filter(t=>!e.laneOrder?.includes(t))]:s,r=new Map(o.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=r.get(e.lane)??0;const a=new Map,c=new Map;for(const e of n.keys())a.set(e,[]),c.set(e,[]);const l=[],d=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of d)e.dependencyIDs.forEach((s,i)=>{const o=n.get(s);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${s}".`,taskIDs:[e.id,s]});const r={id:rt(s,e.id),sourceID:s,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:at(e.id,i),socketIndex:i};l.push(r),a.get(e.id)?.push(r),c.get(s)?.push(r),e.incomingEdgeIDs.push(r.id),e.socketIDs.push(r.socketID),o.outgoingEdgeIDs.push(r.id)});for(const e of a.values())e.sort((e,t)=>ot(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=at(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>ot(e.targetID,t.targetID));for(const e of n.values()){const t=a.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(c.get(e.id)??[]).map(e=>e.id)}const u=new Map,h=new Map;for(const e of n.keys())u.set(e,a.get(e)?.length??0),h.set(e,0);const m=[...n.keys()].filter(e=>0===u.get(e)).sort(ot);let p=0;for(;m.length;){const e=m.shift();p+=1;for(const t of c.get(e)??[]){const n=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,n);const s=(u.get(t.targetID)??0)-1;if(u.set(t.targetID,s),0===s){const e=m.findIndex(e=>e>t.targetID);0>e?m.push(t.targetID):m.splice(e,0,t.targetID)}}}if(p!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(ot);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let f=0;const g=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of g)e.level=h.get(e.id)??0,f=Math.max(f,e.level);return{nodes:g,edges:l,byID:n,incoming:a,outgoing:c,lanes:o,maxLevel:f,diagnostics:t,valid:0===t.length}}function dt(e,t,n={}){const s=Math.max(240,t.width),i=Math.max(220,t.height),o=t.paddingX??48,r=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(s-2*o)/Math.max(1,e.lanes.length)),l=Math.max(76,(i-r-a)/Math.max(1,e.maxLevel+1)),d=Math.min(n.taskWidth??112,Math.max(58,.78*c)),u=Math.min(n.taskHeight??58,.64*l),h=n.socketRadius??5,m=Math.max(1,Math.round(n.gutterCount??3)),p=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=p.get(e)??[];n.push(t),p.set(e,n)}for(const e of p.values())e.sort((e,t)=>ot(e.id,t.id));const f=e.nodes.map(e=>{const t=p.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id));return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:r+l*(e.level+.5)+(n-(t.length-1)/2)*Math.min(18,.3*u),width:d,height:u}}),g=new Map(f.map(e=>[e.taskID,e])),y=[],k=[];e.edges.forEach((t,n)=>{const s=g.get(t.sourceID),i=g.get(t.targetID);if(!s||!i)return;const o=e.incoming.get(t.targetID)??[],r=Math.min(.72*i.width,14*Math.max(1,o.length-1)),a=o.length>1?i.x-r/2+r*t.socketIndex/(o.length-1):i.x,c=i.y-i.height/2-h-2;y.push({id:t.socketID,edgeID:t.id,taskID:i.taskID,index:t.socketIndex,x:a,y:c,radius:h});const l={x:s.x,y:s.y+s.height/2+3},d=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(n%m-(m-1)/2));var u;k.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(u=[l,{x:l.x,y:d},{x:a,y:d},{x:a,y:c}],u.filter((e,t)=>{const n=u[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const x=new Map(y.map(e=>[e.id,e])),b=new Map(k.map(e=>[e.edgeID,e]));return{tasks:f,sockets:y,routes:k,taskByID:g,socketByID:x,routeByEdgeID:b}}function ut(e,t,n="all"){const s=Array.from(new Set(t)).sort(ot),i=new Set,o=()=>s.every(e=>i.has(e));return{taskID:e,mode:n,incomingEdgeIDs:s,deliver:e=>s.includes(e)?(i.add(e),o()):o(),reset:(e=[])=>{i.clear();for(const t of e)s.includes(t)&&i.add(t)},isSatisfied:o,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...s],deliveredEdgeIDs:[...i].sort(ot),satisfied:o()})}}function ht(e){return e instanceof Date?e.getTime():Number(e)}function mt(e,t){const n=ht("object"!=typeof t||t instanceof Date?t:t.currentTime),s=e.map((e,t)=>({event:e,index:t,time:ht(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),i=new Set,o=new Map,r=new Set,a=new Set;for(const{event:e}of s)"task-completed"===e.type?(i.add(e.taskID),o.delete(e.taskID)):"task-blocked"===e.type?o.set(e.taskID,e.reason):"task-unblocked"===e.type?o.delete(e.taskID):"dependency-delivered"===e.type?r.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:s.map(e=>e.event),completedTaskIDs:i,blockedByTaskID:o,deliveredEdgeIDs:r,armedTaskIDs:a}}function pt(e,t,n={}){const s=new Set(n.completedTaskIDs??[]),i=[...st(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(n.isComplete?n.isComplete(e):s.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),o=Array.from(new Set(i.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:i.length,affectedLaneCount:o.length,downstreamTaskIDs:i.map(e=>e.id),affectedLanes:o}}var ft=[];function gt(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function yt(e){if(null==e.completionTime)return null;const t=gt(e.completionTime,NaN);return Number.isFinite(t)?t:null}function kt(e,t,n,s){const i=new Set;for(const o of e.nodes){const r=e.incoming.get(o.id)??[];(s.has(o.id)||!n.has(o.id)&&r.every(e=>t.has(e.id)))&&i.add(o.id)}return i}function xt(e,t,n,s){const i=e.nodes.map(yt).filter(e=>null!=e),o=i.length?Math.min(...i)-1:0,r="replay"!==t||s?n:o,a=new Set,c=new Map;for(const n of e.nodes){const e=yt(n);(null!=e&&r>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const l=new Set;if("replay"!==t||s)for(const t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:r,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:kt(e,l,c,a),blockers:c,previewTaskID:null}}function bt(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function vt(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function wt(e){const t=vt(e.body);if(!t||2>t.route.length)return null;const n=function(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}(t.route),s=function(e,t){let n=1/0,s=0,i=0;for(let o=1;t.length>o;o+=1){const r=t[o-1],a=t[o],c=a.x-r.x,l=a.y-r.y,d=c*c+l*l,u=Math.sqrt(d);if(0>=u)continue;const h=Math.max(0,Math.min(1,((e.x-r.x)*c+(e.y-r.y)*l)/d)),m=Math.hypot(e.x-(r.x+c*h),e.y-(r.y+l*h));n>m&&(n=m,s=i+h*u),i+=u}return s}(e.body,t.route),i=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let s=1;e.length>s;s+=1){const i=e[s-1],o=e[s],r=o.x-i.x,a=o.y-i.y,c=Math.hypot(r,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:i.x+r*e,y:i.y+a*e},tangent:{x:r/c,y:a/c}}}n+=c}}const s=e[e.length-2],i=e[e.length-1],o=i.x-s.x,r=i.y-s.y,a=Math.hypot(o,r)||1;return{point:i,tangent:{x:o/a,y:r/a}}}(t.route,Math.min(n,s+22));return{x:2.5*(78*i.tangent.x-e.body.vx)+8*(i.point.x-e.body.x),y:2.5*(78*i.tangent.y-e.body.vy)+8*(i.point.y-e.body.y)}}function It(e,t){const n=t.points[0]??{x:0,y:0},s=t.points[1]??n,i=s.x-n.x,o=s.y-n.y,r=Math.hypot(i,o)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:i/r*42,vy:o/r*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as Dt,jsxs as Mt}from"react/jsx-runtime";function At({machine:e,layout:t,runtime:n,downstreamSet:s,selectedSet:i,width:o,height:r,seed:a,reduced:c,onSelectTask:l}){return Mt("svg",{"aria-hidden":"true",width:o,height:r,viewBox:`0 0 ${o} ${r}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Dt("defs",{children:Dt("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Dt("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const s=t.tasks.filter(e=>e.laneIndex===n),i=s[0]?.x??0;return Mt("g",{children:[Dt("line",{x1:i,x2:i,y1:32,y2:r-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Dt("text",{x:i,y:23,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),i=n.inFlight.has(e.edgeID),o=s.has(e.targetID)||s.has(e.sourceID),r=e.points.map(e=>`${e.x},${e.y}`).join(" ");return Dt("polyline",{points:r,fill:"none",stroke:o?"var(--semiotic-highlight, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:i?3:2,strokeOpacity:t||i||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return Mt("g",{children:[Dt("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-background, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&Dt("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const o=t.taskByID.get(e.id);if(!o)return null;const r=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=i.has(e.id)||u,m=s.has(e.id),p=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-muted, #75818a)"}(e,n),f=o.x-o.width/2,g=o.y-o.height/2,y=Math.max(2,o.height*e.progress);return Mt("g",{children:[Mt("g",{style:{transform:`rotate(${r?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[Dt("rect",{x:f,y:g,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-background, #fff)",stroke:h||m?"var(--semiotic-highlight, #e08a1e)":p,strokeWidth:h?4:m?3:2}),Dt("rect",{x:f+3,y:g+o.height-y+1,width:o.width-6,height:Math.max(0,y-4),rx:2,fill:p,opacity:r?.86:.46})]}),d&&Mt("g",{opacity:u?.28:1,children:[Dt("line",{x1:f-8,x2:f+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Dt("circle",{cx:f-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Mt("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Dt("rect",{x:f,y:g,width:o.width,height:o.height,fill:"transparent"}),Dt("text",{x:o.x,y:o.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),Mt("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-muted, #5f6b72)",children:[Math.round(100*e.progress),"% · ",r?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as Tt,jsxs as St}from"react/jsx-runtime";var Ct={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},$t=Ve(function(e,t){const{data:n,taskIDAccessor:s,labelAccessor:i,laneAccessor:o,dependencyAccessor:r,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:m,mode:p="snapshot",insight:f="blocker-amplification",currentTime:g,controls:k=!1,selectedTaskIDs:x,onSelectionChange:b,onObservation:v,reducedMotion:w,seed:I=31,width:D=920,height:M=620,responsiveWidth:A,responsiveHeight:T,title:S="Dependency chain reaction",description:C,className:$,accessibleTable:E=!0,enableHover:N=!0}=e,j=tt(null),[R,P]=nt([]),W=x?Array.from(x):R,B=et(()=>new Set(W),[W]),F=gt(g,1/0),L="settle"===w,q=et(()=>lt({data:n,taskIDAccessor:s,labelAccessor:i,laneAccessor:o,dependencyAccessor:r,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:m}),[n,s,i,o,r,a,c,l,d,u,h,m]),O=et(()=>dt(q,{width:D,height:M}),[q,D,M]),[z,U]=nt(()=>xt(q,p,F,L)),Z=tt(z),H=Ge(e=>{Z.current=e,U(e)},[]),X=Ge(e=>v?.(e),[v]);Qe(()=>{const e=xt(q,p,F,L);j.current?.clear(),Z.current=e,U(e)},[q,p,F,L]);const Y=Ge(e=>{const t=B.has(e)?W.filter(t=>t!==e):[e];x||P(t),b?.(t)},[x,b,B,W]),J=Ge(e=>{if(L)return;const t=bt(Z.current),n=[];for(const s of q.outgoing.get(e)??[]){if(t.delivered.has(s.id)||t.inFlight.has(s.id))continue;const e=O.routeByEdgeID.get(s.id);e&&(t.inFlight.add(s.id),n.push(It(s,e)))}n.length&&(H(t),j.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[H,O,q,L]),K=Ge((e,t)=>{const n=q.byID.get(e),s=Z.current;if(!n||s.completed.has(e))return;const i=bt(s);i.completed.add(e),i.blockers.delete(e),i.armed.add(e),null!=t&&(i.currentTime=t),H(i),X({type:"task-completed",taskID:e,datum:n.datum}),J(e)},[H,X,q,J]),V=Ge(e=>{const t=bt(Z.current),n=[],s=[];for(const s of e){if(t.delivered.has(s))continue;const e=q.edges.find(e=>e.id===s);e&&(t.delivered.add(s),t.inFlight.delete(s),n.push(e))}for(const e of n){const n=q.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(q.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),s.push(n.id))}if(n.length){H(t);for(const e of n)X({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of s)X({type:"task-armed",taskID:e})}},[H,X,q]),G=Ge((e,t)=>{const n=[],s=[];for(const e of t.readBodies()){const t=vt(e);if(!t||Z.current.delivered.has(t.edgeID))continue;const i=t.route[t.route.length-1];i&&9>=Math.hypot(e.x-i.x,e.y-i.y)&&(n.push(t.edgeID),s.push(e.id))}s.length&&t.remove(s),n.length&&V(n)},[V]),Q=Ge(()=>{const e=bt(Z.current);for(const t of q.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=kt(q,e.delivered,e.blockers,e.completed),e.playing=!1,j.current?.settle(),H(e),X({type:"machine-settled"})},[H,X,q]),_=Ge(()=>{const e=bt(Z.current);e.playing=!1,H(e)},[H]),ee=Ge(()=>{const e=Z.current,t=q.nodes.map(e=>({node:e,time:yt(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void K(t.node.id,t.time);_();const n=[...e.blockers.keys()].map(t=>pt(q,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&X({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[X,q,_,K]),te=Ge(()=>{if(L)return void Q();const e=bt(Z.current);e.playing=!0,H(e)},[H,L,Q]);Qe(()=>{if(!z.playing||"replay"!==p||L)return;const e=window.setInterval(ee,760);return()=>window.clearInterval(e)},[p,L,z.playing,ee]);const ne=Ge(()=>{j.current?.clear(),H(xt(q,p,F,L))},[H,q,p,F,L]),se=Ge(e=>{if(!q.byID.has(e))return;const t=bt(Z.current);t.previewTaskID=e,H(t);const n=pt(q,e,{completedTaskIDs:t.completed});X({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[H,X,q]),ie=Ge(()=>{const e=bt(Z.current);e.previewTaskID=null,H(e)},[H]),oe=Ge((e,t)=>{if(!q.byID.has(e))return;const n=bt(Z.current);n.blockers.set(e,t),n.armed.delete(e),H(n)},[H,q]),re=Ge(e=>{if(!q.byID.has(e))return;const t=bt(Z.current);t.blockers.delete(e),(q.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),H(t)},[H,q]),ae=Ge(e=>pt(q,e,{completedTaskIDs:Z.current.completed}),[q]),ce=Ge(()=>{const e=Z.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...W],tasks:q.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:q.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[q,W]);_e(t,()=>({play:te,pause:_,step:ee,reset:ne,settle:Q,previewResolve:se,clearPreview:ie,completeTask:K,blockTask:oe,unblockTask:re,getAmplification:ae,getMachineState:ce}),[oe,ie,ae,ce,_,K,te,se,ne,Q,ee,re]);const le=z.previewTaskID??W[0]??null,de=le?pt(q,le,{completedTaskIDs:z.completed}):null,ue=et(()=>new Set(de?.downstreamTaskIDs??[]),[de?.downstreamTaskIDs]),he=et(()=>function(e,t,n){return e.nodes.flatMap(s=>{const i=t.taskByID.get(s.id);if(!i)return[];const o=e.incoming.get(s.id)??[],r=o.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(s.id),c=n.completed.has(s.id)?"completed":a?"blocked: "+a:n.armed.has(s.id)?"armed":"waiting";return[{id:s.id,label:`${s.label}, ${s.lane}, ${Math.round(100*s.progress)}%, ${c}`,description:`${r} of ${o.length} prerequisites delivered.`,datum:s.datum,x:i.x,y:i.y,width:i.width,height:i.height,shape:"rect",group:s.lane}]})}(q,O,z),[O,q,z]),me=et(()=>Tt(At,{machine:q,layout:O,runtime:z,downstreamSet:ue,selectedSet:B,width:D,height:M,seed:I,reduced:L,onSelectTask:Y}),[ue,M,O,q,L,z,I,Y,B,D]),pe=et(()=>{const e=[...z.blockers.keys()].map(e=>pt(q,e,{completedTaskIDs:z.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${q.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[q,z.blockers,z.completed]),fe=et(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:M,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:D-2,y1:0,x2:D-2,y2:M,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:D,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:M-2,x2:D,y2:M-2,thickness:4}}],[M,D]),ge=!0===k?["play","pause","step","reset","settle"]:k||[];return St("div",q.valid?{className:$,style:{width:D,maxWidth:"100%",position:"relative"},children:[ge.length>0&&Tt("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:ge.map(e=>Tt("button",{type:"button",onClick:"play"===e?te:"pause"===e?_:"step"===e?ee:"reset"===e?ne:Q,"aria-pressed":"play"===e?z.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),Tt(y,{ref:j,size:[D,M],responsiveWidth:A,responsiveHeight:T,title:S,description:C??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${pe}${de&&"blocker-amplification"===f?` Selected task reaches ${de.downstreamTaskCount} unfinished tasks across ${de.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:N,initialSpawns:ft,bodyForces:wt,bodyStyle:{fill:"var(--semiotic-accent, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:he,onSemanticItemActivate:e=>e.id&&Y(e.id),foregroundGraphics:()=>me,paused:L,continuous:z.inFlight.size>0,onTick:G,config:{bodyLimit:Math.max(16,q.edges.length+4),colliders:fe,settleStepLimit:2200,kernel:{seed:I,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),E&&St("table",{style:Ct,children:[Tt("caption",{children:pe}),Tt("thead",{children:St("tr",{children:[Tt("th",{children:"Task"}),Tt("th",{children:"Lane"}),Tt("th",{children:"Progress"}),Tt("th",{children:"State"}),Tt("th",{children:"Waiting on"}),Tt("th",{children:"Downstream reach"})]})}),Tt("tbody",{children:q.nodes.map(e=>{const t=pt(q,e.id,{completedTaskIDs:z.completed});return St("tr",{children:[Tt("th",{scope:"row",children:e.label}),Tt("td",{children:e.lane}),St("td",{children:[Math.round(100*e.progress),"%"]}),Tt("td",{children:z.completed.has(e.id)?"Completed":z.blockers.has(e.id)?"Blocked":z.armed.has(e.id)?"Armed":"Waiting"}),Tt("td",{children:z.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!z.completed.has(e)).join(", ")||"None")}),St("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:$,role:"alert",style:{width:D,maxWidth:"100%"},children:[Tt("strong",{children:"ChainReactionChart could not compile this dependency graph."}),Tt("ul",{children:q.diagnostics.map((e,t)=>Tt("li",{children:e.message},`${e.code}-${t}`))})]})});$t.displayName="ChainReactionChart";var Et=y;export{s as BuiltInPhysicsEngineAdapter,$t as ChainReactionChart,i as CollisionSwarmChart,o as EventDropChart,r as GaltonBoardChart,a as GauntletChart,c as GuantletChart,l as PhysicalFlowChart,d as PhysicsCustomChart,u as PhysicsPileChart,h as PhysicsPipelineStore,m as PhysicsSVGOverlay,p as PhysicsSedimentAccumulator,f as ProcessFlowChart,g as StreamPhysicsFrame,k as absorbRegion,x as aggregateRegionCounts,Ke as arrivalReplay,b as bodiesToAnnotationAnchors,v as bodyGroupSpec,w as buildCollisionSwarmPhysics,I as buildEventDropPhysics,D as buildGaltonBoardPhysics,M as buildPhysicalFlowPhysics,A as buildPhysicsAnnotationContext,T as buildPhysicsPile,S as buildProcessFlowPhysics,pt as calculateBlockerAmplification,C as capacitatedRegion,$ as chargeGateRegion,He as collidersFromScales,Le as comparePhysicsTrace,lt as compileDependencyMachine,pe as compileMotionEncoding,De as compilePhysicsEncoding,j as composePhysicsControllers,le as composeStyleRules,R as createCapacityQueueController,P as createDefaultPhysicsEngineAdapter,W as createDependencyGateController,ut as createLogicalJoin,Me as createPhysicsEncodingLayout,B as createPortalController,e as createProcessJourneyLedger,F as createServiceLevelController,L as createServiceResourcePoolController,Et as default,fe as deriveMotionVector,q as evaluatePhysicsBodyBudget,O as forceFieldRegion,Xe as galtonPegs,z as groupCompletionRows,ge as hatchFillId,ye as hatchPatternDef,ke as isHatchFill,de as makeRuleValueResolver,ue as matchesThreshold,U as membraneRegion,Z as normalizePhysicsAnnotations,xe as opacityFromAge,H as physicsProcessBoundaryColliders,X as physicsProcessGroupSemanticItems,Y as physicsProcessRegionSemanticItem,J as physicsProcessStageSemanticItems,Re as physicsReferenceEnvelope,K as planGauntletPropertyWork,V as portalRegion,G as pressureFieldRegion,Q as processChrome,t as processJourneyRows,_ as processLaneWalls,ee as processStageLayout,te as processStageRegions,ne as processVolumePolygons,se as regionCountsToProjectionRows,ie as replaceGauntletNegative,mt as replayStateTransitions,be as resolveMotionAccessor,ve as resolveMotionAge,we as resolveMotionVector,he as resolveStyleRules,Ie as resolveSvgFill,dt as routeDependencyTracks,oe as routeSurfaceRegion,me as ruleMatches,Je as sedimentBake,re as sedimentHeightfield,Ye as spawnFromTokens,ae as stageTargetInVolume,n as updateProcessJourney};
|