semiotic 3.8.4 → 3.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/CLAUDE.md +9 -5
  2. package/README.md +52 -46
  3. package/ai/behaviorContracts.cjs +2 -2
  4. package/ai/componentMetadata.cjs +2 -2
  5. package/ai/dist/mcp-server.js +6 -2
  6. package/ai/examples.md +211 -2
  7. package/ai/schema.json +1388 -14
  8. package/ai/surface-manifest.json +8 -4
  9. package/ai/system-prompt.md +1 -1
  10. package/dist/chunk-chartContainerDataAudit-FEOD5GTQ.module.min.js +2 -0
  11. package/dist/chunk-chunk-2CHN2TA3.module.min.js +1 -0
  12. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +1 -0
  13. package/dist/chunk-chunk-3NGIKFD6.module.min.js +1 -0
  14. package/dist/chunk-chunk-3SHB24AG.module.min.js +1 -0
  15. package/dist/chunk-chunk-4MMOOYTX.module.min.js +2 -0
  16. package/dist/chunk-chunk-75OTQSXS.module.min.js +1 -0
  17. package/dist/chunk-chunk-A5GRQUOF.module.min.js +1 -0
  18. package/dist/chunk-chunk-AAF5LZAU.module.min.js +2 -0
  19. package/dist/{chunk-chunk-LQBSXO7K.module.min.js → chunk-chunk-ARZGA4LJ.module.min.js} +1 -1
  20. package/dist/chunk-chunk-CAFLML4L.module.min.js +2 -0
  21. package/dist/chunk-chunk-CO5KQMGH.module.min.js +1 -0
  22. package/dist/chunk-chunk-FHBN7OEB.module.min.js +2 -0
  23. package/dist/{chunk-chunk-KQ546MKE.module.min.js → chunk-chunk-GFTVACTO.module.min.js} +1 -1
  24. package/dist/chunk-chunk-IP2UE74X.module.min.js +1 -0
  25. package/dist/chunk-chunk-ITDWLZXV.module.min.js +2 -0
  26. package/dist/chunk-chunk-LPSPATPC.module.min.js +1 -0
  27. package/dist/chunk-chunk-OM6NWS4H.module.min.js +2 -0
  28. package/dist/chunk-chunk-PX5YQGDP.module.min.js +2 -0
  29. package/dist/chunk-chunk-Q2BS46W2.module.min.js +2 -0
  30. package/dist/{chunk-chunk-FBGHXL72.module.min.js → chunk-chunk-RA7JCG7D.module.min.js} +1 -1
  31. package/dist/chunk-chunk-RNUHEXZA.module.min.js +2 -0
  32. package/dist/chunk-chunk-ROZWKEUG.module.min.js +1 -0
  33. package/dist/chunk-chunk-SMVD3EQJ.module.min.js +2 -0
  34. package/dist/chunk-chunk-T2FKJD4O.module.min.js +2 -0
  35. package/dist/chunk-chunk-UDREYOLV.module.min.js +1 -0
  36. package/dist/chunk-chunk-VOWE3SAP.module.min.js +2 -0
  37. package/dist/chunk-chunk-VQPNBUSW.module.min.js +2 -0
  38. package/dist/{chunk-chunk-7RYBCTK5.module.min.js → chunk-chunk-WAWCIHFJ.module.min.js} +1 -1
  39. package/dist/{chunk-chunk-F7WFPD4O.module.min.js → chunk-chunk-WYARAXHR.module.min.js} +1 -1
  40. package/dist/{chunk-chunk-JDXT6ORT.module.min.js → chunk-chunk-XP3OHHFX.module.min.js} +1 -1
  41. package/dist/chunk-chunk-XV3KGYTR.module.min.js +2 -0
  42. package/dist/chunk-chunk-YC2IVEPX.module.min.js +1 -0
  43. package/dist/chunk-chunk-ZXIXAPRE.module.min.js +2 -0
  44. package/dist/components/ChartContainer.d.ts +10 -0
  45. package/dist/components/ai/chartCapabilities.d.ts +3 -1
  46. package/dist/components/ai/chartCapabilityTypes.d.ts +14 -0
  47. package/dist/components/chartContainerDataAudit.d.ts +10 -0
  48. package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
  49. package/dist/components/charts/geo/DistanceCartogram.d.ts +30 -4
  50. package/dist/components/charts/index.d.ts +4 -0
  51. package/dist/components/charts/network/ForceDirectedGraph.d.ts +36 -1
  52. package/dist/components/charts/ordinal/BarChart.d.ts +7 -14
  53. package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
  54. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -0
  55. package/dist/components/charts/ordinal/StackedBarChart.d.ts +3 -0
  56. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +4 -14
  57. package/dist/components/charts/physics/CrucibleChart.capability.d.ts +8 -0
  58. package/dist/components/charts/physics/CrucibleChart.d.ts +63 -0
  59. package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +27 -0
  60. package/dist/components/charts/physics/crucibleChartProps.d.ts +90 -0
  61. package/dist/components/charts/physics/crucibleChrome.d.ts +47 -0
  62. package/dist/components/charts/physics/crucibleController.d.ts +59 -0
  63. package/dist/components/charts/physics/crucibleEffects.d.ts +30 -0
  64. package/dist/components/charts/physics/cruciblePhysics.d.ts +54 -0
  65. package/dist/components/charts/physics/crucibleProgram.d.ts +38 -0
  66. package/dist/components/charts/physics/crucibleTypes.d.ts +415 -0
  67. package/dist/components/charts/shared/chartSpecCore.d.ts +10 -4
  68. package/dist/components/charts/shared/crucibleWireSchema.d.ts +5 -0
  69. package/dist/components/charts/shared/diagnoseTypes.d.ts +10 -0
  70. package/dist/components/charts/shared/gaugeGradient.d.ts +4 -8
  71. package/dist/components/charts/shared/gradient.d.ts +35 -0
  72. package/dist/components/charts/shared/hatchFill.d.ts +3 -10
  73. package/dist/components/charts/shared/hooks.d.ts +2 -50
  74. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  75. package/dist/components/charts/shared/streamPropsHelpers.d.ts +1 -2
  76. package/dist/components/charts/shared/useChartLegend.d.ts +58 -0
  77. package/dist/components/charts/shared/useChartSetup.d.ts +5 -0
  78. package/dist/components/charts/shared/useCustomChartSetup.d.ts +6 -1
  79. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +1 -0
  80. package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
  81. package/dist/components/charts/xy/AreaChart.d.ts +25 -42
  82. package/dist/components/charts/xy/BumpChart.capability.d.ts +11 -0
  83. package/dist/components/charts/xy/BumpChart.d.ts +161 -0
  84. package/dist/components/charts/xy/DifferenceChart.d.ts +3 -10
  85. package/dist/components/charts/xy/Heatmap.d.ts +3 -0
  86. package/dist/components/charts/xy/LineChart.d.ts +6 -8
  87. package/dist/components/data/auditData.d.ts +51 -0
  88. package/dist/components/data/dataAuditPresentation.d.ts +18 -0
  89. package/dist/components/data/dataAuditSources.d.ts +9 -0
  90. package/dist/components/data/numericContracts.d.ts +59 -0
  91. package/dist/components/data/numericFieldProfiler.d.ts +23 -0
  92. package/dist/components/geometry/bumpRibbonGeometry.d.ts +36 -0
  93. package/dist/components/legendLayout.d.ts +19 -1
  94. package/dist/components/recipes/netEnsembleLayout.d.ts +167 -0
  95. package/dist/components/recipes/netEnsembleOverlays.d.ts +20 -0
  96. package/dist/components/recipes/wordTrails.d.ts +156 -0
  97. package/dist/components/recipes/wordTrailsProgressiveReveal.d.ts +42 -0
  98. package/dist/components/semiotic-ai-core.d.ts +3 -0
  99. package/dist/components/semiotic-ai-data-audit.d.ts +4 -0
  100. package/dist/components/semiotic-ai.d.ts +9 -6
  101. package/dist/components/semiotic-geo.d.ts +1 -0
  102. package/dist/components/semiotic-network.d.ts +1 -0
  103. package/dist/components/semiotic-ordinal.d.ts +2 -0
  104. package/dist/components/semiotic-physics.d.ts +2 -0
  105. package/dist/components/semiotic-realtime-core.d.ts +1 -0
  106. package/dist/components/semiotic-recipes-core.d.ts +4 -0
  107. package/dist/components/semiotic-server-edge.d.ts +1 -1
  108. package/dist/components/semiotic-server.d.ts +1 -1
  109. package/dist/components/semiotic-utils-core.d.ts +3 -0
  110. package/dist/components/semiotic-xy.d.ts +4 -0
  111. package/dist/components/semiotic.d.ts +5 -5
  112. package/dist/components/server/renderEvidence.d.ts +27 -0
  113. package/dist/components/server/serverChartConfigs.d.ts +2 -0
  114. package/dist/components/server/serverChartConfigsPhysics.d.ts +9 -0
  115. package/dist/components/server/serverChartConfigsXY.d.ts +1 -0
  116. package/dist/components/server/staticAnnotations.d.ts +12 -0
  117. package/dist/components/server/staticLegend.d.ts +4 -2
  118. package/dist/components/server/staticSVGChrome.d.ts +4 -4
  119. package/dist/components/stream/GeoPipelineStore.d.ts +1 -0
  120. package/dist/components/stream/GeoSVGOverlay.d.ts +11 -10
  121. package/dist/components/stream/NetworkSVGOverlay.d.ts +2 -6
  122. package/dist/components/stream/OrdinalSVGOverlay.d.ts +2 -6
  123. package/dist/components/stream/SVGOverlay.d.ts +2 -6
  124. package/dist/components/stream/StalenessBadge.d.ts +2 -6
  125. package/dist/components/stream/geoCartogram.d.ts +7 -0
  126. package/dist/components/stream/geoTypes.d.ts +20 -8
  127. package/dist/components/stream/legendRenderer.d.ts +2 -6
  128. package/dist/components/stream/networkFrameHandleTypes.d.ts +4 -0
  129. package/dist/components/stream/ordinalTypes.d.ts +7 -31
  130. package/dist/components/stream/physics/PhysicsKernel.d.ts +1 -0
  131. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +2 -6
  132. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +8 -0
  133. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +2 -6
  134. package/dist/components/stream/pipelineConfig.d.ts +7 -15
  135. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +9 -69
  136. package/dist/components/stream/renderers/cornerRadii.d.ts +2 -9
  137. package/dist/components/stream/renderers/thresholdLineSegments.d.ts +12 -0
  138. package/dist/components/stream/sceneToSVGShared.d.ts +3 -5
  139. package/dist/components/stream/types.d.ts +32 -56
  140. package/dist/components/stream/xySceneBuilders/areaGradient.d.ts +4 -20
  141. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -6
  142. package/dist/components/types/legendTypes.d.ts +15 -6
  143. package/dist/components/useChartContainerDataAudit.d.ts +7 -0
  144. package/dist/geo.min.js +1 -1
  145. package/dist/geo.module.min.js +1 -1
  146. package/dist/network.min.js +1 -1
  147. package/dist/network.module.min.js +1 -1
  148. package/dist/ordinal.min.js +1 -1
  149. package/dist/ordinal.module.min.js +1 -1
  150. package/dist/physics.min.js +1 -1
  151. package/dist/physics.module.min.js +1 -1
  152. package/dist/physicsWorker.js +1 -1
  153. package/dist/realtime.min.js +1 -1
  154. package/dist/realtime.module.min.js +1 -1
  155. package/dist/semiotic-ai-core.d.ts +3 -0
  156. package/dist/semiotic-ai-core.min.js +1 -1
  157. package/dist/semiotic-ai-core.module.min.js +1 -1
  158. package/dist/semiotic-ai.d.ts +9 -6
  159. package/dist/semiotic-ai.min.js +1 -1
  160. package/dist/semiotic-ai.module.min.js +1 -1
  161. package/dist/semiotic-experimental.min.js +1 -1
  162. package/dist/semiotic-experimental.module.min.js +1 -1
  163. package/dist/semiotic-geo.d.ts +1 -0
  164. package/dist/semiotic-network.d.ts +1 -0
  165. package/dist/semiotic-ordinal.d.ts +2 -0
  166. package/dist/semiotic-physics.d.ts +2 -0
  167. package/dist/semiotic-realtime-core.d.ts +1 -0
  168. package/dist/semiotic-realtime-core.min.js +1 -1
  169. package/dist/semiotic-realtime-core.module.min.js +1 -1
  170. package/dist/semiotic-recipes-core.d.ts +4 -0
  171. package/dist/semiotic-recipes-core.min.js +1 -1
  172. package/dist/semiotic-recipes-core.module.min.js +1 -1
  173. package/dist/semiotic-recipes.min.js +1 -1
  174. package/dist/semiotic-recipes.module.min.js +1 -1
  175. package/dist/semiotic-server-edge.d.ts +1 -1
  176. package/dist/semiotic-server-edge.min.js +1 -1
  177. package/dist/semiotic-server-edge.module.min.js +1 -1
  178. package/dist/semiotic-server-node.min.js +1 -1
  179. package/dist/semiotic-server-node.module.min.js +1 -1
  180. package/dist/semiotic-server.d.ts +1 -1
  181. package/dist/semiotic-utils-core.d.ts +3 -0
  182. package/dist/semiotic-utils-core.min.js +1 -1
  183. package/dist/semiotic-utils-core.module.min.js +1 -1
  184. package/dist/semiotic-utils.min.js +1 -1
  185. package/dist/semiotic-utils.module.min.js +1 -1
  186. package/dist/semiotic-xy.d.ts +4 -0
  187. package/dist/semiotic.d.ts +5 -5
  188. package/dist/semiotic.min.js +1 -1
  189. package/dist/semiotic.module.min.js +1 -1
  190. package/dist/server.min.js +1 -1
  191. package/dist/server.module.min.js +1 -1
  192. package/dist/xy.min.js +1 -1
  193. package/dist/xy.module.min.js +1 -1
  194. package/package.json +2 -2
  195. package/dist/chunk-chunk-3ILKBVVQ.module.min.js +0 -1
  196. package/dist/chunk-chunk-6TPGFL7M.module.min.js +0 -2
  197. package/dist/chunk-chunk-7KZJUTKP.module.min.js +0 -2
  198. package/dist/chunk-chunk-ANYDWOZF.module.min.js +0 -1
  199. package/dist/chunk-chunk-AQPQN2HH.module.min.js +0 -2
  200. package/dist/chunk-chunk-ASKSE5F5.module.min.js +0 -1
  201. package/dist/chunk-chunk-AVBI6GDT.module.min.js +0 -1
  202. package/dist/chunk-chunk-B3DRZPBK.module.min.js +0 -2
  203. package/dist/chunk-chunk-BFHUYEOS.module.min.js +0 -2
  204. package/dist/chunk-chunk-C57LR3YG.module.min.js +0 -1
  205. package/dist/chunk-chunk-F5V4UIE6.module.min.js +0 -2
  206. package/dist/chunk-chunk-FP44FHFO.module.min.js +0 -2
  207. package/dist/chunk-chunk-HKXUAEPJ.module.min.js +0 -2
  208. package/dist/chunk-chunk-ICEXPNDC.module.min.js +0 -2
  209. package/dist/chunk-chunk-JMVEIZXP.module.min.js +0 -1
  210. package/dist/chunk-chunk-KHCOJMGK.module.min.js +0 -1
  211. package/dist/chunk-chunk-LRIFN2HK.module.min.js +0 -1
  212. package/dist/chunk-chunk-MFHF4J2Z.module.min.js +0 -1
  213. package/dist/chunk-chunk-N6VKKF3A.module.min.js +0 -2
  214. package/dist/chunk-chunk-NEVE562N.module.min.js +0 -1
  215. package/dist/chunk-chunk-NKZ75IM5.module.min.js +0 -2
  216. package/dist/chunk-chunk-PLIDPQNG.module.min.js +0 -2
  217. package/dist/chunk-chunk-QGZGZI4X.module.min.js +0 -1
  218. package/dist/chunk-chunk-RP7WTID5.module.min.js +0 -1
  219. package/dist/chunk-chunk-S7KLNUO6.module.min.js +0 -1
  220. package/dist/chunk-chunk-SR4ZXOWR.module.min.js +0 -2
  221. package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +0 -1
  222. package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +0 -1
@@ -1 +1 @@
1
- import{computeArcBoundingBox as e,sweepToAngles as t}from"./chunk-chunk-ANYDWOZF.module.min.js";import{buildCollisionSwarmPhysics as o,buildEventDropPhysics as i,buildGaltonBoardPhysics as r,buildPhysicalFlowPhysics as s,buildPhysicsPile as n,buildProcessFlowPhysics as a,generateGaltonMechanicalSamples as c,generatePhysicsPileMechanicalSamples as l,physicsBodiesToXYSceneNodes as u,renderPhysicsSettledSVG as h,resolveCustomLayout as d,styleFromColorAccessor as g}from"./chunk-chunk-ASKSE5F5.module.min.js";import{composeStyleRules as p,makeNodeRuleContext as f,makeRuleValueResolver as y,makeXYRuleContext as m,resolveStyleRules as b,styleRulesToNodeStyle as x,styleRulesToXYStyle as v,validateArrayData as A}from"./chunk-chunk-NEVE562N.module.min.js";import{PhysicsPipelineStore as S}from"./chunk-chunk-LRIFN2HK.module.min.js";import"./chunk-chunk-SIRIJ3DY.module.min.js";import{SEGMENT_FIELD as w,buildAnomalyAnnotations as k,buildForecast as _,createSegmentLineStyle as M}from"./chunk-chunk-C57LR3YG.module.min.js";import"./chunk-chunk-2JGJ5GUG.module.min.js";import{PipelineStore as P,StreamXYFrame_default as T,accessorName as L,attachUpdateResultStore as R,bandTooltipFields as C,buildBaseMetadataProps as z,buildCustomBehaviorProps as F,buildDatumIndexMap as B,buildDefaultTooltip as O,buildRectNode as E,buildRibbonGeometry as D,buildTooltipProps as j,compactTimestampBufferForRemoval as N,computeDecayOpacity as W,computePulseIntensity as I,createCustomLayoutFailureDiagnostic as $,createTimestampBufferForData as G,ensureRingBufferCapacity as Y,getLayoutPlugin as H,hasActivePulses as V,pushWithTimestamp as X,renderSceneListWithBackend as q,renderSceneWithBackend as Q,resolveDownwardHistogramExtent as K,setPulseState as Z,ticksForMode as U,toIdSet as J,warnCustomLayoutDiagnostics as ee}from"./chunk-chunk-3ILKBVVQ.module.min.js";import{IncrementalExtent as te,RingBuffer as oe}from"./chunk-chunk-7ALTGHK6.module.min.js";import"./chunk-chunk-C4YA6TDR.module.min.js";import{AnnotationLabel as ie,ChartError as re,DEFAULT_COLOR as se,DEFAULT_LEGEND_ROW_HEIGHT as ne,DEPTH_PALETTE_COLORS as ae,STREAMING_PALETTE as ce,SafeRender as le,SemioticAnnotation as ue,TITLE_BASELINE as he,applyAnnotationEmphasis as de,buildResolveColor as ge,composeLegendConfigs as pe,computeEasing as fe,computeRawProgress as ye,createColorScale as me,filterSparseArray as be,geoSceneNodeToSVG as xe,getColor as ve,getCrosshairProps as Ae,getSize as Se,hasTextTitle as we,isChartMode as ke,isGradientLegendConfig as _e,isLegendConfig as Me,layoutVerticalLegendGroups as Pe,lerp as Te,networkLabelToSVG as Le,networkSceneEdgeToSVG as Re,networkSceneNodeToSVG as Ce,now as ze,ordinalSceneNodeToSVG as Fe,renderEmptyState as Be,renderLoadingState as Oe,reserveTitleMargin as Ee,resolveCategoricalPalette as De,resolveChartMode as je,resolveCustomLayoutPalette as Ne,resolveDefaultFill as We,resolveExplicitColor as Ie,resolveLegendMetrics as $e,resolveMobileInteraction as Ge,useCategoryColors as Ye,useChartLegendAndMargin as He,useChartMode as Ve,useChartSelection as Xe,useColorScale as qe,useLegendInteraction as Qe,useThemeCategorical as Ke,warnMissingField as Ze,wrapStyleWithSelection as Ue,xySceneNodeToSVG as Je}from"./chunk-chunk-MFHF4J2Z.module.min.js";import"./chunk-chunk-XEVJDUTH.module.min.js";import{MultiPointTooltip as et,accessorsEquivalent as tt,filterAnnotationsByStatus as ot,resolveAccessor as it,resolveStringAccessor as rt,resolveSvgFill as st}from"./chunk-chunk-JMVEIZXP.module.min.js";import{SYMBOL_SEQUENCE as nt,UpdateResultTracker as at,annotationLayout as ct,getSequentialInterpolator as lt,interpolateBrBG as ut,interpolatePRGn as ht,interpolatePiYG as dt,interpolateRdBu as gt,interpolateRdYlBu as pt,interpolateRdYlGn as ft,interpolateSpectral as yt,interpolateViridis as mt,schemeCategory10 as bt}from"./chunk-chunk-5RKXZQ2P.module.min.js";import"./chunk-chunk-U66USBWU.module.min.js";import{getMax as xt,getMin as vt,getMinMax as At}from"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-IY7RYD4S.module.min.js";import"./chunk-chunk-J3QOW4OE.module.min.js";import{DARK_THEME as St,HIGH_CONTRAST_THEME as wt,LIGHT_THEME as kt,THEME_PRESETS as _t,applyThemeAccessibility as Mt,resolveThemeSemanticColors as Pt,useThemeSelector as Tt}from"./chunk-chunk-DSNGDNJY.module.min.js";import*as Lt from"react-dom/server";import*as Rt from"react";function Ct({data:e,safeData:t,areaBy:o,lineDataAccessor:i}){if(null==e)return[];const r=void 0!==t[0]?.[i];if(!r&&!o)return t;let s;if(r)s=t;else{const e=t.reduce((e,t)=>{const r="function"==typeof o?o(t):t[o],s=r+"";if(!e[s]){const t={[i]:[]};"string"==typeof o&&(t[o]=r),e[s]=t}return e[s][i].push(t),e},{});s=Object.values(e)}return s.flatMap(e=>{const t=Array.isArray(e[i])?e[i]:[];return"string"==typeof o?t.map(t=>({...t,[o]:t[o]??e[o]})):t})}function zt(e,t){if(!function(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}(t))return e??((...e)=>({}));const o={};return void 0!==t.stroke&&(o.stroke=t.stroke),void 0!==t.strokeWidth&&(o.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(o.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...o}):(...e)=>({...o})}import{useMemo as Ft,forwardRef as Bt,useRef as Ot}from"react";import{useCallback as Et,useMemo as Dt,useState as jt}from"react";import{useMemo as Nt}from"react";import{useImperativeHandle as Wt,useRef as It}from"react";import{useMemo as $t}from"react";import{useEffect as Gt,useMemo as Yt,useRef as Ht,useState as Vt}from"react";var Xt=null;async function qt(){return Xt||(Xt=await import("./chunk-statisticalOverlays-QGDLRUHX.module.min.js")),Xt}var Qt="__semiotic_resolvedX",Kt="__semiotic_resolvedY";import{jsx as Zt}from"react/jsx-runtime";function Ut(e,t){if(null==t)return e;const o=e.trim(),i=o.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(i){const e=i[1],o=3===e.length?e.split("").map(e=>e+e).join(""):e;return`rgba(${parseInt(o.slice(0,2),16)}, ${parseInt(o.slice(2,4),16)}, ${parseInt(o.slice(4,6),16)}, ${t})`}if(o.startsWith("rgba(")){const e=o.lastIndexOf(","),i=o.lastIndexOf(")");if(-1!==e&&i>e)return`${o.slice(0,e+1)} ${t})`}return o.startsWith("rgb(")?o.replace(/^rgb\(/,"rgba(").replace(/\)$/,`, ${t})`):e}function Jt(e){return e.filter(e=>Number.isFinite(e.at)).map(e=>({offset:1-Math.max(0,Math.min(100,e.at))/100,color:Ut(e.color,e.opacity)})).sort((e,t)=>e.offset-t.offset)}function eo(e,t,o){return"function"==typeof e?e(o):o[e||t]}function to(e){return e instanceof Date?e.getTime():Number(e)}function oo(e,t){return mt(1===t?.5:e/(t-1))}function io(e){if(!e)return kt;if("string"==typeof e){if("light"===e)return kt;if("dark"===e)return St;if("high-contrast"===e)return wt;return _t[e]||kt}const t="dark"===e.mode?St:kt,o={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return Mt(o)}function ro(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}Bt(function(e,t){const o=Ot(null);!function(e,t){const{variant:o,frameRef:i,overrides:r}=t,s=It(r);s.current=r,Wt(e,()=>{const e=function(e,t){if("xy"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.remove(t)??[],update:(t,o)=>e.current?.update(t,o)??[],replace:t=>e.current?.replace?.(t),clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getScales:()=>e.current?.getScales()??null,getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("network"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>{const o=Array.isArray(t)?t:[t],i=e.current?.getTopology()?.nodes??[],r=[];for(const t of o){const o=i.find(e=>e.id===t);o&&r.push({...o.data??{},id:t}),e.current?.removeNode(t)}return r},update:(t,o)=>(Array.isArray(t)?t:[t]).flatMap(t=>{const i=e.current?.updateNode(t,o);return i?[{...i,id:t}]:[]}),clear:()=>e.current?.clear(),getData:()=>e.current?.getTopology()?.nodes?.map(e=>e.data)??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("geo-points"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.removePoint(t)??[],update:(t,o)=>{const i=e.current?.removePoint(t)??[];for(const t of i)e.current?.push(o(t));return i},clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}const o=t;return{push:e=>o.current?.pushLine(e),pushMany:e=>o.current?.pushManyLines(e),remove:e=>o.current?.removeLine(e)??[],update:(e,t)=>{const i=o.current?.removeLine(e)??[];for(const e of i)o.current?.pushLine(t(e));return i},clear:()=>o.current?.clear(),getData:()=>o.current?.getLines()??[],getCustomLayout:()=>o.current?.getCustomLayout?.()??null,getLayoutFailure:()=>o.current?.getLayoutFailure?.()??null}}(o,i);return new Proxy(e,{get(e,t,o){if("string"==typeof t){const e=s.current?.[t];if("function"==typeof e)return e}return Reflect.get(e,t,o)},has:(e,t)=>!("string"!=typeof t||!s.current||!(t in s.current))||Reflect.has(e,t)})},[])}(t,{variant:"xy",frameRef:o});const i=Ve(e.mode,{width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,xLabel:e.xLabel,yLabel:e.yLabel,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules}),{data:r,margin:s,className:n,xFormat:a,yFormat:c,xAccessor:l="x",yAccessor:u="y",areaBy:h,y0Accessor:d,gradientFill:g=!1,semanticGradient:p,lineDataAccessor:f="coordinates",colorBy:y,colorScheme:x,styleRules:v,curve:S="monotoneX",areaOpacity:w=.7,lineGradient:k,showLine:_=!0,lineWidth:M=2,showPoints:P=!1,pointRadius:R=3,tooltip:B,annotations:E,forecast:D,anomaly:N,band:W,xExtent:I,yExtent:$,frameProps:G={},selection:Y,linkedHover:H,onObservation:V,onClick:X,hoverHighlight:q,chartId:Q,loading:K,loadingContent:Z,emptyContent:U,legendInteraction:J,legendPosition:ee,color:te,stroke:oe,strokeWidth:ie,opacity:ne}=e,{width:ae,height:ue,enableHover:he,showGrid:de,showLegend:ge,title:pe,description:fe,summary:ye,accessibleTable:xe,xLabel:Se,yLabel:we}=i,ke=Ft(()=>be(r),[r]),_e=y||h,Me=Ft(()=>p&&p.length>0?{colorStops:Jt(p)}:g,[p,g]);Ze("AreaChart",ke,"xAccessor",l),Ze("AreaChart",ke,"yAccessor",u);const Pe=function(e){const{data:t,rawData:o,colorBy:i,colorScheme:r,legendInteraction:s,legendPosition:n,selection:a,linkedHover:c,fallbackFields:l,unwrapData:u=!1,onObservation:h,chartType:d,chartId:g,showLegend:p,legend:f,userMargin:y,marginDefaults:m,onClick:b,hoverHighlight:x,mobileInteraction:v,mobileSemantics:A,loading:S,loadingContent:w,emptyContent:k,width:_,height:M}=e,P=void 0===o,T=Dt(()=>be(t),[t]),[L,R]=jt([]),C=Et(e=>{R(t=>t.length===e.length&&t.every((t,o)=>t===e[o])?t:e)},[]),z="string"==typeof e.colorBy?e.colorBy:void 0,F=Dt(()=>Ge(v,{width:_,mobileSemantics:A}),[v,_,A]),{activeSelectionHook:B,hoverSelectionHook:O,customHoverBehavior:E,customClickBehavior:D,crosshairSourceId:j}=Xe({selection:a,linkedHover:c,fallbackFields:l,unwrapData:u,onObservation:h,chartType:d,chartId:g,onClick:b,hoverHighlight:x,colorByField:z,mobileInteraction:F}),N=Ae(c,j),W=qe(T,i,r),I=Dt(()=>{if(!i)return[];const e=new Set;for(const t of T){const o="function"==typeof i?i(t):t[i];null!=o&&e.add(o+"")}return Array.from(e)},[T,i]),$=Dt(()=>P&&L.length>0?L:I,[P,L,I]),G=Qe(s,i,$),Y=Dt(()=>O||(G.legendSelectionHook?G.legendSelectionHook:B),[O,G.legendSelectionHook,B]),H=function(e){const t=Tt(e=>e.theme.colors.selectionOpacity);return Nt(()=>{if(void 0!==e||void 0!==t)return{name:e?.name??"",...e,unselectedOpacity:e?.unselectedOpacity??t}},[e,t])}(a),V=Ke(),X=Ye(),q=Dt(()=>{if(W)return W;if(!i||0===$.length)return;const e=Array.isArray(r)&&r.length>0||"string"==typeof r&&r.length>0?r:V&&V.length>0?V:ce,t="__streamCat",o=$.map(e=>({[t]:e})),s=me(o,t,e);return e=>X?.[e]||s(e)||"#999"},[W,i,$,r,V,X]),{legend:Q,margin:K,legendPosition:Z}=He({data:T,colorBy:i,colorScale:q,showLegend:p,legendPosition:n,userMargin:y,defaults:m,categories:$,additionalLegend:f}),U=Dt(()=>{const e={};return Q&&(e.legend=Q,e.legendPosition=Z),s&&"none"!==s&&(e.legendHoverBehavior=G.onLegendHover,e.legendClickBehavior=G.onLegendClick,e.legendHighlightedCategory=G.highlightedCategory,e.legendIsolatedCategories=G.isolatedCategories),P&&i&&(e.legendCategoryAccessor=i,e.onCategoriesChange=C),e},[Q,Z,s,G.onLegendHover,G.onLegendClick,G.highlightedCategory,G.isolatedCategories,P,i,C]),J=Array.isArray(o)?be(o):o,ee=Oe(S,_,M,w),te=ee?null:Be(J,_,M,k);return{data:T,colorScale:W,allCategories:$,legendState:G,effectiveSelectionHook:Y,activeSelectionHook:B,customHoverBehavior:E,customClickBehavior:D,mobileInteraction:F,legend:Q,margin:K,legendPosition:Z,earlyReturn:ee||te||null,legendBehaviorProps:U,crosshairProps:N,resolvedSelection:H}}({data:ke,rawData:r,colorBy:_e,colorScheme:x,legendInteraction:J,legendPosition:ee,selection:Y,linkedHover:H,fallbackFields:_e?["string"==typeof _e?_e:""]:[],unwrapData:!1,onObservation:V,onClick:X,hoverHighlight:q,mobileInteraction:i.mobileInteraction,mobileSemantics:i.mobileSemantics,chartType:"AreaChart",chartId:Q,showLegend:ge,userMargin:s,marginDefaults:i.marginDefaults,loading:K,loadingContent:Z,emptyContent:U,width:ae,height:ue}),{effectiveData:Te,statisticalAnnotations:Le}=function(e){const{data:t,xAccessor:o,yAccessor:i,forecast:r,anomaly:s,groupBy:n}=e,a="string"==typeof o?o:Qt,c="string"==typeof i?i:Kt,l=Yt(()=>{if(!r&&!s)return t;const e="function"==typeof o,n="function"==typeof i;return e||n?t.map(t=>{const r={...t};return e&&(r[Qt]=o(t)),n&&(r[Kt]=i(t)),r}):t},[t,r,s,o,i]),[u,h]=Vt(null),[d,g]=Vt([]),p=Ht(r),f=Ht(s);return Gt(()=>{if(!r&&!s)return void((p.current||f.current)&&(h(null),g([]),p.current=r,f.current=s));let e=!1;const t=r!==p.current||s!==f.current;if(p.current=r,f.current=s,t&&(h(null),g([])),r){const t=n&&"string"==typeof n&&"object"==typeof r?{...r,_groupBy:n}:r;(async function(...e){return(await qt()).buildForecast(...e)})(l,a,c,t,s).then(t=>{e||(h(t),g(t.annotations))}).catch(()=>{e||(h(null),g([]))})}else s&&async function(...e){return(await qt()).buildAnomalyAnnotations(...e)}(s).then(t=>{e||(h(null),g(t))}).catch(()=>{e||g([])});return()=>{e=!0}},[l,r,s,a,c,n]),{effectiveData:u?u.processedData:t,statisticalAnnotations:d,hasForecast:!!u,xAccessorKey:a,yAccessorKey:c}}({data:ke,xAccessor:l,yAccessor:u,forecast:D,anomaly:N,groupBy:h}),Re=Ft(()=>m(l,u),[l,u]),{flattenedData:Ce,lineStyle:ze,pointStyle:Fe,defaultTooltipContent:Ee}=function(e){const{safeData:t,data:o,areaBy:i,lineDataAccessor:r,colorBy:s,colorScale:n,color:a,stroke:c,strokeWidth:l,opacity:u,effectiveSelectionHook:h,resolvedSelection:d,areaOpacity:g,showLine:p,lineWidth:f,showPoints:y,pointRadius:m,xAccessor:x,yAccessor:v,xLabel:A,yLabel:S,xFormat:w,yFormat:k,groupField:_,styleRules:M,ruleContext:P}=e,T=$t(()=>Ct({data:o,safeData:t,areaBy:i,lineDataAccessor:r}),[o,t,i,r]),R=$t(()=>e=>{const t={};if(s){if(n){const o=ve(e,s,n);t.fill=o,p?(t.stroke=o,t.strokeWidth=f):t.stroke="none"}}else{const e=a||se;t.fill=e,p?(t.stroke=e,t.strokeWidth=f):t.stroke="none"}return t.fillOpacity=g,M&&M.length>0&&Object.assign(t,b(e,M,P?P(e):{value:void 0})),t},[s,n,a,g,p,f,M,P]),z=$t(()=>zt(R,{stroke:c,strokeWidth:l,opacity:u}),[R,c,l,u]);return{flattenedData:T,lineStyle:$t(()=>Ue(z,h??null,d),[z,h,d]),pointStyle:$t(()=>{if(y)return e=>{const t={r:m,fillOpacity:1};return s?n&&(t.fill=ve(e.parentLine||e,s,n)):t.fill=a||se,t}},[y,m,s,n,a]),defaultTooltipContent:$t(()=>O([{label:A||L(x),accessor:x,role:"x",format:w},{label:S||L(v),accessor:v,role:"y",format:k},..._?[{label:L(_),accessor:_,role:"group"}]:[],...C(e.band,k)]),[x,v,A,S,_,w,k,e.band])}}({safeData:Te,data:r,areaBy:h,lineDataAccessor:f,colorBy:_e,colorScale:Pe.colorScale,color:te,stroke:oe,strokeWidth:ie,opacity:ne,effectiveSelectionHook:Pe.effectiveSelectionHook,resolvedSelection:Pe.resolvedSelection,areaOpacity:w,showLine:_,lineWidth:M,showPoints:P,pointRadius:R,xAccessor:l,yAccessor:u,xLabel:Se,yLabel:we,xFormat:a,yFormat:c,groupField:h||y,band:W,styleRules:v,ruleContext:Re}),De=A({componentName:"AreaChart",data:r,accessors:{xAccessor:l,yAccessor:u}}),je={chartType:"area",...null!=r&&{data:Ce},xAccessor:l,yAccessor:u,groupAccessor:h||void 0,...d&&{y0Accessor:d},...W&&{band:W},...Me&&{gradientFill:Me},...k&&{lineGradient:k},curve:S,lineStyle:ze,...P&&Fe&&{pointStyle:Fe},size:[ae,ue],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:Pe.margin,showAxes:i.showAxes,xLabel:Se,yLabel:we,xFormat:a,yFormat:c,enableHover:he,...e.pointIdAccessor&&{pointIdAccessor:e.pointIdAccessor},showGrid:de,...Pe.legendBehaviorProps,...z({title:pe,description:fe,summary:ye,accessibleTable:xe,className:n,animate:e.animate,axisExtent:e.axisExtent,autoPlaceAnnotations:e.autoPlaceAnnotations}),..."multi"===B?{tooltipContent:et(),tooltipMode:"multi"}:j({tooltip:B,defaultTooltipContent:Ee}),...F({linkedHover:H,selection:Y,onObservation:V,onClick:X,hoverHighlight:q,mobileInteraction:Pe.mobileInteraction,customHoverBehavior:Pe.customHoverBehavior,customClickBehavior:Pe.customClickBehavior}),...(E&&E.length>0||Le.length>0)&&{annotations:[...E||[],...Le]},...I&&{xExtent:I},...$&&{yExtent:$},...Pe.crosshairProps,...G};return Pe.earlyReturn?Pe.earlyReturn:De?Zt(re,{componentName:"AreaChart",message:De,width:ae,height:ue}):Zt(le,{componentName:"AreaChart",width:ae,height:ue,children:Zt(T,{ref:o,...je})})}).displayName="AreaChart";var so="__semiotic_resolvedX",no="__semiotic_resolvedY",ao="__compoundGroup";function co(e,t,o){const i=e[t],r=e[o];return null==i||null==r||Number.isNaN(i)||Number.isNaN(r)}function lo(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=io(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrAreaColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrAreaColorBy:t(e)})):s,u=t?me(l,c,a):void 0,h=!1!==r.showLine,d="number"==typeof r.lineWidth?r.lineWidth:2,g="number"==typeof r.areaOpacity?r.areaOpacity:.7,p=y(r.yAccessor),f=r.styleRules;return(e,o)=>{const i=t&&u?ve(e,t,u):"string"==typeof r.color?r.color:se,s={fill:i,fillOpacity:g,stroke:h?i:"none",...h&&{strokeWidth:d}};return f?.length&&Object.assign(s,b(e,f,{value:p(e),category:o})),void 0!==r.stroke&&(s.stroke=r.stroke),void 0!==r.strokeWidth&&(s.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(s.opacity=r.opacity),s}}function uo(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=io(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrBubbleColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrBubbleColorBy:t(e)})):s,u=t?me(l,c,a):void 0,h=r.sizeBy,d=Array.isArray(r.sizeRange)?r.sizeRange:[5,40],g=h?s.map(e=>"function"==typeof h?h(e):Number(e[h])).filter(Number.isFinite):[],p=g.length?At(g):void 0;return e=>({fill:t&&u?ve(e,t,u):"string"==typeof r.color?r.color:se,fillOpacity:"number"==typeof r.bubbleOpacity?r.bubbleOpacity:.6,r:h?Se(e,h,d,p):d[0],stroke:r.stroke??r.bubbleStrokeColor??"white",strokeWidth:r.strokeWidth??r.bubbleStrokeWidth??1,...void 0!==r.opacity&&{opacity:r.opacity}})}function ho(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=io(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrScatterColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrScatterColorBy:t(e)})):s,u=t?me(l,c,a):void 0,h=r.sizeBy,d=Array.isArray(r.sizeRange)?r.sizeRange:[3,15],g=h?s.map(e=>"function"==typeof h?h(e):Number(e[h])).filter(Number.isFinite):[],p=g.length?At(g):void 0,f=m(r.xAccessor,r.yAccessor),y=r.styleRules;return e=>{const o={fill:t&&u?ve(e,t,u):"string"==typeof r.color?r.color:se,fillOpacity:"number"==typeof r.pointOpacity?r.pointOpacity:.8,r:h?Se(e,h,d,p):"number"==typeof r.pointRadius?r.pointRadius:5};return y?.length&&Object.assign(o,b(e,y,f(e))),void 0!==r.stroke&&(o.stroke=r.stroke),void 0!==r.strokeWidth&&(o.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(o.opacity=r.opacity),o}}function go(e,t,o,i,r){if(!r.showPoints)return;const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=io(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrPointColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrPointColorBy:t(e)})):s,u=t?me(l,c,a):void 0,h="number"==typeof r.pointRadius?r.pointRadius:3;return e=>{const o=t&&u?ve(e,t,u):"string"==typeof r.color?r.color:se;return{r:h,fill:o,stroke:"none"}}}function po(e){return Math.max(0,Math.min(1,e))}function fo(e){const t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const o=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const e=[Number(o[1]),Number(o[2]),Number(o[3])];if(e.every(Number.isFinite))return e}return null}function yo(e,t,o){const i=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(o)}`}function mo(e,t){const o=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:po(e.offset),color:e.color})).sort((e,t)=>e.offset-t.offset);if(0===o.length)return"#999999";if(1===o.length)return o[0].color;const i=po(t);if(o[0].offset>=i)return o[0].color;if(i>=o[o.length-1].offset)return o[o.length-1].color;for(let e=0;o.length-1>e;e++){const t=o[e],r=o[e+1];if(t.offset>i||i>r.offset)continue;const s=r.offset-t.offset,n=s>0?(i-t.offset)/s:0,a=fo(t.color),c=fo(r.color);if(!a||!c)return.5>n?t.color:r.color;const[l,u,h]=a,[d,g,p]=c;return yo(l+(d-l)*n,u+(g-u)*n,h+(p-h)*n)}return o[o.length-1].color}function bo(e,t,o){return null==o?`${e}-${t}`:`${e}-${t}-${o}`}import{Fragment as xo,jsx as vo,jsxs as Ao}from"react/jsx-runtime";import{useMemo as So,useCallback as wo,useRef as ko}from"react";var _o={RdBu:gt,PiYG:dt,PRGn:ht,BrBG:ut,RdYlBu:pt,RdYlGn:ft,Spectral:yt},Mo="__likert_neutral_neg",Po="__likert_neutral_pos";function To(e,t){if("function"==typeof e)return e;const o=e||t;return e=>e[o]}import*as Lo from"react";function Ro(e){return!0===e?{topOpacity:.8,bottomOpacity:.05}:!1===e?void 0:e}function Co(e,t,o,i,r){const s=io(i.theme).colors.categorical,n=o??i.colorScheme,a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",l="function"==typeof t?a.map(e=>({...e,__ssrColorBy:t(e)})):a,u=t?me(l,c,n??s):void 0,h=We("string"==typeof r.color?r.color:void 0,s,n,void 0,new Map),d=y(r.valueAccessor),g=r.styleRules,p=i.pieceStyle;return(e,o)=>{const i={fill:t&&u?ve(e,t,u):h};return g?.length&&Object.assign(i,b(e,g,{value:d(e),category:o})),"function"==typeof p?Object.assign(i,p(e,o)||{}):p&&"object"==typeof p&&Object.assign(i,p),void 0!==r.stroke&&(i.stroke=r.stroke),void 0!==r.strokeWidth&&(i.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(i.opacity=r.opacity),i}}function zo(e,t,o,i,r){const s=Co(e,t,o,i,r);return(e,t)=>{const o=s(e,t);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function Fo(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n="string"==typeof t?t:"__ssrViolinColorBy",a="function"==typeof t?s.map(e=>({...e,__ssrViolinColorBy:t(e)})):s,c=io(i.theme).colors.categorical,l=o??i.colorScheme,u=t?me(a,n,l??c):void 0,h=We("string"==typeof r.color?r.color:void 0,c,l,void 0,new Map);return e=>{const o=t&&u?ve(e,t,u):h;return{fill:o,fillOpacity:.6,stroke:r.stroke??o,...void 0!==r.strokeWidth&&{strokeWidth:r.strokeWidth},...void 0!==r.opacity&&{opacity:r.opacity}}}}function Bo(e,t,o,i,r){const s=Co(e,t,o,i,r),n="number"==typeof r.dotRadius?r.dotRadius:5;return(e,t)=>({r:n,fillOpacity:.8,...s(e,t)})}function Oo(e,t,o,i,r){const s=Co(e,t,o,i,r),n=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=r.sizeBy,c=Array.isArray(r.sizeRange)?r.sizeRange:[3,8],l=a?n.map(e=>"function"==typeof a?a(e):Number(e[a])).filter(Number.isFinite):[],u=l.length?At(l):void 0,h="number"==typeof r.pointRadius?r.pointRadius:4,d="number"==typeof r.pointOpacity?r.pointOpacity:.7;return(e,t)=>({r:a?Se(e,a,c,u):h,fillOpacity:d,...s(e,t)})}import{scaleTime as Eo}from"d3-scale";function Do(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:e.kind}function jo(e,t,o){const i=t.incoming[e.id],r=t.outgoing[e.id],s=[];for(const e of i)s.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:o.get(e.id).targetSide});for(const e of r)s.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:o.get(e.id).sourceSide});const n={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},a=()=>{s.sort((e,t)=>e.time-t.time||(n[e.kind]??99)-(n[t.kind]??99))},c=s.length?vt(s.map(e=>e.time)):null,l=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,u=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,h=[...new Set(s.map(e=>e.time))].sort((e,t)=>e-t),d=new Map;for(let e=1;h.length>e;e++)d.set(h[e],h[e-1]);const g=e=>{const t=d.get(e);return null!=t?(t+e)/2:null!=u?u:e};a();const p=[];let f=0,y=0;for(const e of s)if("out"===e.kind){const t=Math.abs(e.delta);let o=t-("top"===e.side?f:y);if(o>0){const t="top"===e.side?"bot":"top",i=Math.min(o,"top"===t?f:y);if(i>0){const r=g(e.time);p.push({time:r,delta:-i,kind:"transfer-out",side:t}),p.push({time:r,delta:+i,kind:"transfer-in",side:e.side}),"top"===t?f-=i:y-=i,"top"===e.side?f+=i:y+=i,o-=i}o>0&&null!==u&&(p.push({time:u,delta:+o,kind:"create",side:e.side}),"top"===e.side?f+=o:y+=o)}"top"===e.side?f-=t:y-=t}else if("in"===e.kind){const t=Math.abs(e.delta);"top"===e.side?f+=t:y+=t}s.push(...p),a();let m=0,b=0,x=0,v=0,A=0;const S=[],w=new Map;for(const e of s){if(S.push({t:e.time,topMass:m,botMass:b}),("in"===e.kind||"out"===e.kind)&&e.edge){const t="top"===e.side?m:b;w.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta)})}"top"===e.side?m+=e.delta:b+=e.delta,m+b>x&&(x=m+b),m>v&&(v=m),b>A&&(A=b),S.push({t:e.time,topMass:m,botMass:b})}const k=[];let _=0;for(;S.length>_;){let e=_;for(;S.length>e+1&&S[e+1].t===S[_].t;)e++;k.push(S[_]);for(let t=_+1;e>=t;t++){const e=k[k.length-1];S[t].topMass===e.topMass&&S[t].botMass===e.botMass||k.push(S[t])}_=e+1}const M=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null;let P=null;for(const e of r)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===P||P>e.systemInTime)&&(P=e.systemInTime);let T=null;for(const e of i)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===T||e.systemOutTime>T)&&(T=e.systemOutTime);if(k.length>0){const e=k[k.length-1],t=Math.max(null!=M?M:-1/0,null!=T?T:-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&k.push({t:t,topMass:e.topMass,botMass:e.botMass});const o=k[0],i=Math.min(null!=l?l:1/0,null!=P?P:1/0);Number.isFinite(i)&&o.t>i&&o.topMass+o.botMass>0&&k.unshift({t:i,topMass:o.topMass,botMass:o.botMass})}return{samples:k,peak:x,topPeak:v,botPeak:A,localAttachments:w}}function No(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Wo(e,t){return e.map(e=>({t:No(e.t,t),topMass:e.topMass,botMass:e.botMass}))}function Io(e,t,o){const i=e.value*o;if("out"===e.kind){const r=e.sideMassBefore*o;if("top"===e.side){const e=t-r;return[e,e+i]}const s=t+r;return[s-i,s]}const r=e.sideMassAfter*o;if("top"===e.side){const e=t-r;return[e,e+i]}const s=t+r;return[s-i,s]}function $o(e,t){let o=0;for(let i=0;t.length>i;i++)for(let r=i+1;t.length>r;r++){const s=t[i],n=t[r];s.source!==n.source&&s.target!==n.target&&s.source!==n.target&&s.target!==n.source&&(Math.min(s.endTime,n.endTime)>Math.max(s.startTime,n.startTime)&&e[n.source]>e[s.source]!=e[n.target]>e[s.target]&&o++)}return o}function Go(e,t){let o=0;for(const i of t)o+=Math.abs(e[i.source]-e[i.target])*(i.value||1);return o}function Yo(e,t){return 1e3*$o(e,t)+Go(e,t)}function Ho(e,t){return{slots:e.map(e=>({peak:{...e.peak},occupants:e.occupants.slice()})),map:{...t}}}function Vo(e,t,o){e.length>8||o.length>40?(function(e,t,o,i=6){const r=e.length;if(1>=r)return;let s=Ho(e,t),n=Yo(t,o);for(let a=0;i>a;a++){const i=Array(r).fill(0),a=Array(r).fill(0);for(const e of o){const o=t[e.source],r=t[e.target];i[o]+=r*(e.value||1),a[o]+=e.value||1,i[r]+=o*(e.value||1),a[r]+=e.value||1}const c=Array.from({length:r},(e,t)=>t).sort((e,t)=>(a[e]>0?i[e]/a[e]:e)-(a[t]>0?i[t]/a[t]:t)),l=c.map(t=>e[t]),u=new Map;c.forEach((e,t)=>u.set(e,t));for(const e of Object.keys(t))t[e]=u.get(t[e]);e.length=0;for(const t of l)e.push(t);const h=Yo(t,o);if(n>h)n=h,s=Ho(e,t);else if(h===n)break}!function(e,t,o){e.length=0;for(const t of o.slots)e.push(t);for(const e of Object.keys(t))delete t[e];for(const e of Object.keys(o.map))t[e]=o.map[e]}(e,t,s)}(e,t,o,6),function(e,t,o,i=6){const r=e.length;if(1>=r)return;let s=Yo(t,o);for(let n=0;i>n;n++){let i=!1;for(let n=0;r-1>n;n++){const r=e[n];e[n]=e[n+1],e[n+1]=r;for(const e of Object.keys(t))t[e]===n?t[e]=n+1:t[e]===n+1&&(t[e]=n);const a=Yo(t,o);if(s>a)s=a,i=!0;else{const o=e[n];e[n]=e[n+1],e[n+1]=o;for(const e of Object.keys(t))t[e]===n?t[e]=n+1:t[e]===n+1&&(t[e]=n)}}if(!i)break}}(e,t,o,6)):function(e,t,o){const i=e.length;if(1>=i)return;const r={...t},s=Object.keys(r),n=Array.from({length:i},(e,t)=>t),a=n.slice(),c={...r};let l=n.slice(),u=1/0;const h=()=>{for(const e of s)c[e]=a[r[e]];const e=Yo(c,o);u>e&&(u=e,l=n.slice())},d=(e,t)=>{const o=n[e],i=n[t];n[e]=i,n[t]=o,a[o]=t,a[i]=e};h();const g=Array(i).fill(0);let p=0;for(;i>p;)p>g[p]?(d(p%2==0?0:g[p],p),h(),g[p]++,p=0):(g[p]=0,p++);const f=l.map(t=>e[t]),y=new Map;l.forEach((e,t)=>y.set(e,t));for(const e of Object.keys(t))t[e]=y.get(t[e]);e.length=0;for(const t of f)e.push(t)}(e,t,o)}function Xo(e,t,o,i,r){const{plotH:s,padding:n,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="full"}=r,h={},d={};for(const t of e)h[t.id]=o[t.id].topPeak||0,d[t.id]=o[t.id].botPeak||0;const g="half"===u,p={};for(const t of e){const e=Array.isArray(t.xExtent)?t.xExtent[0]:null,o=Array.isArray(t.xExtent)?t.xExtent[1]:null;let r=null!=e&&Number.isFinite(e)?e:1/0,s=null!=o&&Number.isFinite(o)?o:-1/0;for(const e of i.outgoing[t.id]){r>e.startTime&&(r=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&r>e.systemInTime&&(r=e.systemInTime);const t=g?(e.startTime+e.endTime)/2:e.endTime;t>s&&(s=t)}for(const e of i.incoming[t.id]){const t=g?(e.startTime+e.endTime)/2:e.startTime;r>t&&(r=t),e.endTime>s&&(s=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>s&&(s=e.systemOutTime)}p[t.id]={start:Number.isFinite(r)?r:null,end:Number.isFinite(s)?s:null}}const f={},y=[];if("reuse"===c){const o=new Map;for(const t of e)o.set(t.id,0);const r=new Map;for(const t of e)r.set(t.id,0);for(const e of t)r.set(e.target,(r.get(e.target)??0)+1);const s=[];for(const t of e)0===(r.get(t.id)??0)&&s.push(t.id);for(;s.length;){const e=s.shift();for(const t of i.outgoing[e]??[]){const i=(o.get(e)??0)+1;i>(o.get(t.target)??0)&&o.set(t.target,i),r.set(t.target,r.get(t.target)-1),0===r.get(t.target)&&s.push(t.target)}}const n=[...e].filter(e=>null!==p[e.id].start).sort((e,t)=>{const i=o.get(e.id)??0,r=o.get(t.id)??0;return i!==r?i-r:p[e.id].start-p[t.id].start}),a=e.filter(e=>null===p[e.id].start);for(const e of[...n,...a]){const t=p[e.id];let o=-1;for(let e=0;y.length>e;e++){const i=y[e].occupants[y[e].occupants.length-1];if(null===t.start||void 0===i||t.start>=i.end){o=e;break}}-1===o&&(y.push({occupants:[],peak:{topPeak:0,botPeak:0}}),o=y.length-1),y[o].occupants.push({id:e.id,end:t?.end??-1/0}),y[o].peak.topPeak=Math.max(y[o].peak.topPeak,h[e.id]),y[o].peak.botPeak=Math.max(y[o].peak.botPeak,d[e.id]),f[e.id]=o}}else e.forEach((e,t)=>{y.push({occupants:[{id:e.id,end:p[e.id]?.end??-1/0}],peak:{topPeak:h[e.id],botPeak:d[e.id]}}),f[e.id]=t});let m=null,b=null,x=null,v=null;const A=()=>{m=$o(f,t),x=Go(f,t)},S=()=>{b=$o(f,t),v=Go(f,t)};"crossing-min"===l?(A(),Vo(y,f,t),S()):"inside-out"===l?(A(),function(e,t){const o=e.length;if(1>=o)return;const i=e=>e.peak.topPeak+e.peak.botPeak,r=e.map((e,t)=>({slot:e,idx:t})).sort((e,t)=>i(t.slot)-i(e.slot)),s=Array(o),n=Math.floor((o-1)/2);s[n]=r[0].idx;let a=n-1,c=n+1;for(let e=1;r.length>e;e++)e%2==1&&o>c||0>a?s[c++]=r[e].idx:s[a--]=r[e].idx;const l=s.map(t=>e[t]),u=new Map;s.forEach((e,t)=>u.set(e,t));for(const e of Object.keys(t))t[e]=u.get(t[e]);e.length=0;for(const t of l)e.push(t)}(y,f),S()):"crossing-min+inside-out"===l&&(A(),Vo(y,f,t),function(e,t,o){const i=e.length;if(1>=i)return;const r=e.map(e=>{return{slot:e,size:(t=e,t.peak.topPeak+t.peak.botPeak)};var t}).sort((e,t)=>t.size-e.size),s=Math.floor((i-1)/2);let n=Yo(t,o);for(const{slot:a}of r){const r=e.indexOf(a);if(0>r)continue;const c=s;if(r===c)continue;const l=e[r];e.splice(r,1),e.splice(c,0,l);const u=new Map;for(let e=0;i>e;e++)u.set(e,e);if(c>r){for(let e=r+1;c>=e;e++)u.set(e,e-1);u.set(r,c)}else{for(let e=c;r>e;e++)u.set(e,e+1);u.set(r,c)}for(const e of Object.keys(t))t[e]=u.get(t[e]);const h=Yo(t,o);if(h>n){const o=e[c];e.splice(c,1),e.splice(r,0,o);const s=new Map;for(let e=0;i>e;e++)s.set(e,e);if(r>c){for(let e=c+1;r>=e;e++)s.set(e,e-1);s.set(c,r)}else{for(let e=r;c>e;e++)s.set(e,e+1);s.set(c,r)}for(const e of Object.keys(t))t[e]=s.get(t[e])}else n=h}}(y,f,t),S());const w=y.map(e=>{const t=new Map;for(const i of e.occupants){const e=o[i.id];if(e)for(const o of e.samples){const e=t.get(o.t)||{top:0,bot:0};t.set(o.t,{top:Math.max(e.top,o.topMass),bot:Math.max(e.bot,o.botMass)})}}return[...t.entries()].sort((e,t)=>e[0]-t[0])}),k=(e,t)=>{let o={top:0,bot:0};for(const[i,r]of e){if(i>t)break;o=r}return o},_=[];for(let e=0;y.length-1>e;e++){const t=w[e],o=w[e+1],i=new Set([...t.map(e=>e[0]),...o.map(e=>e[0])]);let r=0;for(const e of i){const i=k(t,e),s=k(o,e);i.bot+s.top>r&&(r=i.bot+s.top)}_.push(r)}const M=[];let P=n+(y[0]?.peak.topPeak??0)*a;y.length>0&&M.push(P);for(let e=1;y.length>e;e++)P+=_[e-1]*a+n,M.push(P);if(y.length>0&&(P+=y[y.length-1].peak.botPeak*a+n),P>s){const e=s/P;for(let t=0;M.length>t;t++)M[t]*=e}const T=0===y.length?0:y[0].peak.topPeak+_.reduce((e,t)=>e+t,0)+y[y.length-1].peak.botPeak,L={};for(const t of e)L[t.id]=M[f[t.id]];return{effectiveSlotsHeight:T,centerlines:L,laneLifetime:p,slots:y,slotByNode:f,slotCenter:M,crossingsBefore:m,crossingsAfter:b,lengthBefore:x,lengthAfter:v}}function qo(e){const{nodes:t,edges:o,domain:i,plotW:r,plotH:s,ribbonLane:n,edgeOpacity:a,colorOf:c,layoutOpts:l}=e,u=function(e,t,o){const i=[],r=new Set(e.map(e=>e.id)),s=Array.isArray(o)&&2===o.length,n=s&&Number.isFinite(o[0])&&Number.isFinite(o[1]);s&&n&&n&&o[1]>=o[0]||i.push({kind:"invalid-domain"});for(const t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||i.push({kind:"invalid-node-time",id:t.id}));for(const e of t)r.has(e.source)||i.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),r.has(e.target)||i.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?(Number.isFinite(e.value)&&e.value>0||i.push({kind:"invalid-value",id:e.id}),e.endTime>e.startTime||i.push({kind:"backward-edge",id:e.id,source:e.source,target:e.target})):i.push({kind:"invalid-edge-time",id:e.id});return i}(t,o,i),h=Eo().domain(i).range([0,r]);if(u.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:u,xScale:h};const d=function(e,t,o){const{plotH:i,pairing:r="temporal",packing:s="reuse",laneOrder:n="crossing-min",lifetimeMode:a="half"}=o,c=function(e,t){const o={},i={};for(const t of e)o[t.id]=[],i[t.id]=[];for(const e of t)i[e.source]&&i[e.source].push(e),o[e.target]&&o[e.target].push(e);return{incoming:o,outgoing:i}}(e,t),l=function(e,t,o,i="value"){const r="temporal"===i?(e,t)=>e.endTime-t.endTime:(e,t)=>t.value-e.value,s="temporal"===i?(e,t)=>e.startTime-t.startTime:(e,t)=>t.value-e.value,n=new Map;for(const e of t)n.set(e.id,{});const a=(e,t)=>{const o=new Map;for(const i of e){const e=i[t];o.has(e)||o.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const r=o.get(e);r.edges.push(i),r.total+=i.value,r.earliestStart=Math.min(r.earliestStart,i.startTime),r.latestEnd=Math.max(r.latestEnd,i.endTime)}const n=[...o.values()];n.sort("temporal"===i?(e,o)=>"target"===t?e.earliestStart-o.earliestStart:e.latestEnd-o.latestEnd:(e,t)=>t.total-e.total);for(const e of n)e.edges.sort("target"===t?s:r);return n};for(const t of e){const e=o.outgoing[t.id],i=o.incoming[t.id];if(0===i.length)a(e,"target").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)n.get(t.id).sourceSide=o});else if(0===e.length)a(i,"source").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)n.get(t.id).targetSide=o});else{const t=a(i,"source"),o=a(e,"target"),r=Math.max(t.length,o.length);for(let e=0;r>e;e++){const i=e%2==0?"top":"bot";if(t[e])for(const o of t[e].edges)n.get(o.id).targetSide=i;if(o[e])for(const t of o[e].edges)n.get(t.id).sourceSide=i}}}return n}(e,t,c,r);let u={};for(const t of e)u[t.id]=jo(t,c,l);const h=Xo(e,t,u,c,{plotH:i,padding:12,valueScale:1,packing:s,laneOrder:n,lifetimeMode:a}),d=new Set;for(const e of t){const t=h.slotByNode[e.source],o=h.slotByNode[e.target];if(void 0===t||void 0===o)continue;const i=l.get(e.id);t!==o?t>o?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(d.add(e.id),i.sourceSide="bot",i.targetSide="bot")}for(const t of e){const e=c.outgoing[t.id],o=c.incoming[t.id],i=new Set(e.map(e=>l.get(e.id).sourceSide)),r=new Set(o.map(e=>l.get(e.id).targetSide));if(1===i.size&&o.length>0){const e=[...i][0];for(const t of o)h.slotByNode[t.source]===h.slotByNode[t.target]&&(l.get(t.id).targetSide=e)}if(1===r.size&&e.length>0){const t=[...r][0];for(const o of e)h.slotByNode[o.source]===h.slotByNode[o.target]&&(l.get(o.id).sourceSide=t)}}for(const t of e){const e=c.incoming[t.id],o=c.outgoing[t.id];if(0===e.length||0===o.length)continue;const i=()=>{const t={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of e)"top"===l.get(o.id).targetSide?t.inTop+=o.value:t.inBot+=o.value;for(const e of o)"top"===l.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},r=(e,t)=>{const r=i(),s="top"===e?r.outTop-r.inTop:r.outBot-r.inBot,n="top"===t?r.inTop-r.outTop:r.inBot-r.outBot;if(0>=s||0>=n)return!1;const a=Math.min(s,n),c=o.filter(t=>!d.has(t.id)&&l.get(t.id).sourceSide===e&&a>=t.value).sort((e,t)=>t.value-e.value);return 0!==c.length&&(l.get(c[0].id).sourceSide=t,!0)};let s=o.length+1;for(;s-- >0&&(r("top","bot")||r("bot","top")););}u={};for(const t of e)u[t.id]=jo(t,c,l);const g=Xo(e,t,u,c,{plotH:i,padding:12,valueScale:1,packing:s,laneOrder:n,lifetimeMode:a}),p=g.effectiveSlotsHeight??g.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),f=Math.min(12,.35*i/Math.max(g.slots.length+1,1)),y=p>0?Math.max(0,(i-f*(g.slots.length+1))/p):1,m=Xo(e,t,u,c,{plotH:i,padding:f,valueScale:y,packing:s,laneOrder:n,lifetimeMode:a});return{nodeData:u,sides:l,valueScale:y,padding:f,compressedPadding:12>f,centerlines:m.centerlines,laneLifetime:m.laneLifetime,slots:m.slots,slotByNode:m.slotByNode,crossingsBefore:m.crossingsBefore,crossingsAfter:m.crossingsAfter,lengthBefore:m.lengthBefore,lengthAfter:m.lengthAfter}}(t,o,{plotH:s,...l}),{centerlines:g,nodeData:p,valueScale:f}=d,y=[],m=[];t.forEach((e,t)=>{const r=p[e.id];if(!r||0===r.samples.length)return;const s=function(e,t,o,i,r){if(0===e.length)return null;const s=Wo(e,r),n=e=>t-s[e].topMass*o,a=e=>t+s[e].botMass*o;let c=`M${i(s[0].t)},${n(0)}`;for(let e=1;s.length>e;e++)c+=` L${i(s[e].t)},${n(e)}`;c+=` L${i(s[s.length-1].t)},${a(s.length-1)}`;for(let e=s.length-2;e>=0;e--)c+=` L${i(s[e].t)},${a(e)}`;return c+" Z"}(r.samples,g[e.id],f,h,i);if(!s)return;const n=Wo(r.samples,i),a=n.find(e=>e.topMass+e.botMass>0)||n[0],l=g[e.id]+(a.botMass-a.topMass)*f/2,u=c(e.id,t),m=function(e,t,o,i,r){const s=o.nodeData[e];if(!s||0===s.samples.length)return[];const n=o.valueScale,a=o.centerlines[e],c=Wo(s.samples,r),l=c.find(e=>e.topMass+e.botMass>0)||c[0],u=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=i(l.t),d=i(u.t),g=e=>i(No(e,r)),p=[],f=(e,t,o,i)=>`M${e},${t} L${o},${t} L${o},${i} L${e},${i} Z`;for(const o of t){if(o.source===e&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const e=s.localAttachments.get(o.id);if(e&&"out"===e.kind&&o.startTime>o.systemInTime){const t=g(o.systemInTime),i=g(o.startTime),r=t-20,s=Math.max(h,r);if(i>s){const[o,c]=Io(e,a,n);p.push({pathD:f(s,o,i,c),x0:r,x1:t,from:0,to:1})}}}if(o.target===e&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const e=s.localAttachments.get(o.id);if(e&&"in"===e.kind&&o.systemOutTime>o.endTime){const t=g(o.systemOutTime),i=g(o.endTime),r=t+20,s=Math.min(d,r);if(s>i){const[o,c]=Io(e,a,n);p.push({pathD:f(i,o,s,c),x0:t,x1:r,from:1,to:0})}}}}return p}(e.id,o,d,h,i);y.push({id:e.id,pathD:s,fill:u,stroke:u,strokeWidth:.5,...m.length>0&&{gradientStubs:m},rawDatum:e.__raw??e,labelX:h(a.t)-4,labelY:l,labelText:e.id})});const b=new Map;return t.forEach((e,t)=>b.set(e.id,t)),o.forEach(e=>{const t=p[e.source]?.localAttachments.get(e.id),o=p[e.target]?.localAttachments.get(e.id);if(!t||!o)return;const r=b.get(e.source)??0,s=c(e.source,r),l=function(e,t,o,i,r,s,n,a){const c=r,l=e=>a?Math.max(a[0],Math.min(a[1],e)):e,u=s(l(e.time)),h=s(l(o.time)),d=e.value*c,g=o.value*c,p=e.sideMassBefore*c,f=o.sideMassAfter*c;let y,m,b,x;"top"===e.side?(y=t-p,m=y+d):(m=t+p,y=m-d),"top"===o.side?(b=i-f,x=b+g):(x=i+f,b=x-g);const v="source"===n?u+.85*(h-u):"target"===n?u+.15*(h-u):(u+h)/2;return{sx:u,sTop:y,sBot:m,tx:h,tTop:b,tBot:x,cp1X:v,cp2X:v}}(t,g[e.source],o,g[e.target],f,h,n,i),{pathD:u,bezier:d}=D(l);m.push({id:e.id,pathD:u,fill:s,opacity:a,rawDatum:e.__raw??e,bezier:d})}),{layout:d,layoutConfig:{bands:y,ribbons:m,showLabels:!0},issues:[],xScale:h}}var Qo=e=>{const{bands:t=[],ribbons:o=[],showLabels:i=!0}=e.config,r=[];for(const e of o)r.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:e.opacity,stroke:"none"},datum:{__kind:"ribbon",data:e.rawDatum,id:e.id}});for(const e of t)if(e.gradientStubs)for(let t=0;e.gradientStubs.length>t;t++){const o=e.gradientStubs[t];r.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,from:o.from,to:o.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${t}`}})}for(const e of t)r.push({type:"bezier",pathD:e.pathD,style:{...e.gradientStubs&&e.gradientStubs.length>0?{fill:"none"}:{fill:e.fill,fillOpacity:.86},stroke:e.stroke??e.fill,strokeWidth:e.strokeWidth??.5},datum:{__kind:"band",data:e.rawDatum,id:e.id}});const s=i?t.map(e=>({x:e.labelX,y:e.labelY,text:e.labelText,anchor:"end",baseline:"middle",fontSize:11,fontWeight:600})):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:r,labels:s}};function Ko(e,t){if(!e)return[];const o=[],i=e=>{o.push(e);const r="function"==typeof t?t(e):e[t];r&&Array.isArray(r)&&r.forEach(i)};return i(e),o}function Zo(e,t,o,i){if(e&&e.length>0)return e;const r=new Set;return t.forEach(e=>{const t="function"==typeof o?o(e):e[o],s="function"==typeof i?i(e):e[i];r.add(t),r.add(s)}),Array.from(r).map(e=>({id:e}))}import*as Uo from"react";var Jo={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as ei}from"d3-scale";function ti(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}function oi(e){const t=ci(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function ii(e,t,o,i){return o?"function"==typeof o?o(e,t):e[o]??i:i}function ri(e){return`gauntlet:${e}:core`}function si(e,t){return`gauntlet:${e}:positive:${t}`}function ni(e,t,o){return`gauntlet:${e}:negative:${t}:${o}`}var ai={left:28,top:76,rightInset:30,thickness:8};function ci(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return ai;const o=Math.max(1,Math.min(e.width,t)),i=Math.max(2,.04*e.width);return{left:i,top:Math.max(2,.08*t),rightInset:i,thickness:Math.max(1,Math.min(4,.04*o))}}function li(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function ui(e,t,o,i){const r=ci(i),s=Math.max(2,o+2),n=r.top+r.thickness/2+s,a=i.floorY-s,c=(e,t,o)=>t>o?(t+o)/2:Math.max(t,Math.min(o,e));return{x:c(e,r.left+r.thickness/2+s,i.width-r.rightInset-r.thickness/2-s),y:c(t,n,a)}}function hi(e,t,o=1){const i=[...e].sort((e,t)=>e.localeCompare(t)),r=Math.max(0,i.indexOf(t));return{angle:.82*-Math.PI+(i.length>1?r/(i.length-1):.5)*Math.PI*.64,index:r,radius:(48+r%2*6)*o}}function di(e,t,o){const i=e.activePositiveIds.reduce((e,o)=>e+(t.get(o)?.value??1),0),r=e.missingPositiveIds.length+e.poppedPositiveIds.length,s=e.negativeIds.reduce((e,t)=>e+(o.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*s-1.2*e.delay-5*r))}function gi(e){const t=function(e,t,o){const[i,r]=e,s=220>i||160>r,n=Math.round(.48*r),a=s?r-Math.max(3,Math.min(12,.1*r)):r-36,c=(t??[]).filter(e=>!1!==e.enabled),l=Math.max(1,c.length),u=.22*i,h=l>1?(.78*i-u)/(l-1):0,d=s?Math.max(Math.round(.12*i),.08*i+6):Math.max(Math.round(.14*i),110);return{crashY:a-(s?Math.min(o,Math.max(3,.22*r)):o),floorY:a,gates:c.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*h),width:e.width??Math.max(s?8:54,Math.round(.07*i))})),graveyardX:Math.round(i*(s?.72:.84)),graveyardY:a-4,height:r,routeY:n,socketX:Math.round(i*(s?.82:.92)),startX:d,width:i}}(e.size??[900,520],e.gates,e.crashOffset??30),o=e.positiveProperties??[],i=new Map(o.map(e=>[e.id,e])),r=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),s={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},n=(e.data??[]).map((t,n)=>{const a=function(e,t,o,i,r){const s=ii(e,t,o.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",n=i.map(e=>e.id),a=[...ii(e,t,o.positiveAccessor,n)],c=[...ii(e,t,o.negativeAccessor,[])].filter(e=>r.has(e));return{id:s,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...ii(e,t,o.metricsAccessor,{})},missingPositiveIds:n.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(ii(e,t,o.startTimeAccessor,0))||0),stage:"project filed",viability:ii(e,t,o.initialViability,100)}}(t,n,s,o,r);return{...a,viability:e.viability?.(a,{negativeProperties:r,positiveProperties:i})??di(a,i,r)}}),a=n.flatMap((o,s)=>{const n=function(e,t,o,i){const r=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(o),s=i?.(e,t,o)??{};return{...r,...s,startY:s.startY??s.routeY??r.startY,socketY:s.socketY??s.routeY??r.socketY,graveyardY:s.graveyardY??r.graveyardY}}(o,s,t,e.projectPlacement);return function(e,t,o,i,r,s,n){const a=li(o),c=Math.max(3,28*a),l=i.startX,u=i.startY+(i.startY===o.routeY?38*t*a:0),h=n?.(e,t,o,i)??{},d=h.x??l,g=h.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},f=[{...h,id:ri(e.id),x:d,y:g,vx:h.vx??42,vy:h.vy??0,mass:h.mass??7,bodyCollisions:h.bodyCollisions??!0,shape:h.shape??{type:"circle",radius:c},spawnAt:h.spawnAt??e.startedAt,datum:p}],y=ui(d,g,h.shape&&"radius"in h.shape&&Number(h.shape.radius)||c,o);f[0].x=y.x,f[0].y=y.y;for(const t of e.activePositiveIds){const i=r.get(t);if(!i)continue;const s=hi(e.activePositiveIds,t,a),n=i.radius??Math.max(2,10*a),c=ui(y.x+Math.cos(s.angle)*s.radius,y.y+Math.sin(s.angle)*s.radius,n,o);f.push({id:si(e.id,t),x:c.x,y:c.y,vx:18*Math.cos(s.angle),vy:18*Math.sin(s.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:n},spawnAt:h.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:ri(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+s.index%2*4)*a),...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const r=s.get(t);r&&f.push(function(e,t,o,i,r,s,n){const a=li(s),c=t.radius??Math.max(2,7.2*a),l=ui(i+(o%4*12-12)*a,r+(54+12*Math.floor(o/4))*a,c,s);return{id:ni(e.id,t.id,o),x:l.x,y:l.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:n,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:ri(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...t.spring??{}}]}}(e,r,i,y.x,y.y,o,h.spawnAt??e.startedAt))}),f}(o,s,t,n,i,r,e.coreBody)});return{layout:t,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:oi(t)}}}function pi(e){return e.map(e=>({...e,spawnAt:void 0}))}var fi={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,o,i,r)=>({chartType:"line",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",groupAccessor:r.lineBy||t,colorAccessor:t,...i,showAxes:!1,margin:i.margin,showLegend:!1,showGrid:!1,title:void 0})},LineChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.lineBy,n=r.fillArea,a=Array.isArray(n)?"mixed":n?"area":"line",c=io(i.theme).colors.categorical,l=function(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=io(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrLineColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrLineColorBy:t(e)})):s,u=t?me(l,c,a):void 0,h=m(r.xAccessor,r.yAccessor),d=function(e){const{lineWidth:t=2,colorBy:o,colorScale:i,color:r,resolveStroke:s,fillArea:n,areaOpacity:a=.3,styleRules:c,ruleContext:l}=e;return(e,u)=>{const h={strokeWidth:t},d=!0===n||Array.isArray(n)&&null!=u&&n.includes(u);let g;return s?g=s(e,u):o?i&&(g=ve(e,o,i)):g=r||se,void 0!==g&&(h.stroke=g,d&&(h.fill=g,h.fillOpacity=a)),c?.length&&Object.assign(h,b(e,c,l?l(e,u):{value:void 0,category:u})),h}}({lineWidth:"number"==typeof r.lineWidth?r.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof r.color?r.color:void 0,fillArea:r.fillArea,areaOpacity:"number"==typeof r.areaOpacity?r.areaOpacity:.3,styleRules:r.styleRules,ruleContext:h});return zt(d,{stroke:"string"==typeof r.stroke?r.stroke:void 0,strokeWidth:"number"==typeof r.strokeWidth?r.strokeWidth:void 0,opacity:"number"==typeof r.opacity?r.opacity:void 0})}(e,s,o,i,r),u=function(e){const t=e.xAccessor||"x",o=e.yAccessor||"y",i=e.lineBy,r=e.colorBy||i;let s=Array.isArray(e.data)?be(e.data).filter(e=>!!e&&"object"==typeof e):[];const n=function(e,t,o){const i="function"==typeof t,r="function"==typeof o,s=i?so:t,n=r?no:o;return i||r?{xKey:s,yKey:n,rows:e.map(e=>{const s={...e};return i&&(s[so]=t(e)),r&&(s[no]=o(e)),s})}:{rows:e,xKey:s,yKey:n}}(s,t,o);s=n.rows;const a=n.xKey,c=n.yKey,l=Array.isArray(e.annotations)?[...e.annotations]:[];let u,h,d="string"==typeof i||"function"==typeof i?i:void 0,g=e.baseLineStyle;if(e.forecast){const t=i&&"string"==typeof i&&"object"==typeof e.forecast?{...e.forecast,_groupBy:i}:e.forecast,o=_(s,a,c,t,e.anomaly);if(s=o.processedData,l.push(...o.annotations),u=function(e,t,o){const i=o.upperBounds,r=o.lowerBounds;if(!i&&!r)return;const s="function"==typeof i?i:"string"==typeof i?e=>e[i]:null,n="function"==typeof r?r:"string"==typeof r?e=>e[r]:null;let a=1/0,c=-1/0;for(const o of e){const e=Number(o[t]);if(Number.isFinite(e)&&(a>e&&(a=e),e>c&&(c=e)),s){const e=s(o);null!=e&&Number.isFinite(e)&&(e>c&&(c=e),a>e&&(a=e))}if(n){const e=n(o);null!=e&&Number.isFinite(e)&&(a>e&&(a=e),e>c&&(c=e))}}return Number.isFinite(a)&&Number.isFinite(c)?[a,c]:void 0}(s,c,e.forecast),i&&"string"==typeof i?(s=s.map(e=>({...e,[ao]:`${e[i]}__${e[w]||"observed"}`})),d=ao):d=w,e.baseLineStyle){const t=M(t=>e.baseLineStyle(t),e.forecast);g=e=>t(e)}}else e.anomaly&&l.push(...k(e.anomaly));if(e.gapStrategy){if("function"==typeof d){const e=d;s=s.map(t=>({...t,__semiotic_gapGroup:e(t)})),d="__semiotic_gapGroup"}const t=function(e,t,o,i,r){const s=new Map;for(const t of e){const e=r?(t[r]??"")+"":"__single";s.has(e)||s.set(e,[]),s.get(e).push(t)}if("interpolate"===t){const e=[];for(const[,t]of s)for(const r of t)co(r,o,i)||e.push(r);return{rows:e,groupKey:r}}if("zero"===t){const e=[];for(const[,t]of s)for(const r of t)co(r,o,i)?e.push({...r,[i]:0}):e.push(r);return{rows:e,groupKey:r}}const n=[],a="_gapSegment";for(const[e,t]of s){let r=0,s=[];const c=()=>{if(0===s.length)return;const t="__single"===e?"__seg"+r:`${e}__seg${r}`;for(const e of s)n.push({...e,[a]:t});s=[],r++};for(const e of t)co(e,o,i)?c():s.push(e);c()}return{rows:n,groupKey:a}}(s,e.gapStrategy,a,c,"string"==typeof d?d:void 0);s=t.rows,t.groupKey&&(d=t.groupKey)}if(e.directLabel){const t=function(e,t,o,i,r,s,n,a){if(!t||!o)return{annotations:[]};const c="object"==typeof t?t:{},l=c.position||"end",u=c.fontSize||11,h="function"==typeof o?o:e=>e[o],d=new Map;for(const t of e){const e=h(t);if(null==e)continue;const o=e+"";""!==o&&(d.has(o)||d.set(o,[]),d.get(o).push(t))}const g=new Map;for(const[e,t]of d)t.sort((e,t)=>Number(e[i])-Number(t[i])),g.set(e,"end"===l?t[t.length-1]:t[0]);const p=me(Array.from(g.entries()).map(([e])=>({__lbl:e})),"__lbl",s??n),f=Array.from(g.entries()).map(([e,t])=>({type:"text",label:e,[i]:t[i],[r]:t[r],dx:"end"===l?6:-6,dy:0,color:p?ve({__lbl:e},"__lbl",p):a||se,fontSize:u}));f.sort((e,t)=>Number(e[r])-Number(t[r]));for(let e=1;f.length>e;e++){const t=f[e-1],o=f[e],i=Number(t[r])+t.dy;u+2>Math.abs(Number(o[r])+o.dy-i)&&(o.dy+=u+2)}const y=f.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*u)),0)+10;return{annotations:f,marginExtra:"end"===l?{right:y}:{left:y}}}(s,e.directLabel,"string"==typeof r||"function"==typeof r?r:void 0,a,c,e.colorScheme,e.themeCategorical,e.color);l.push(...t.annotations),h=t.marginExtra}return{data:s,xAccessor:"function"==typeof t?a:t,yAccessor:"function"==typeof o?c:o,groupAccessor:d,colorAccessor:r,annotations:l,lineStyle:g,yExtent:u,marginExtra:h}}({data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",lineBy:r.lineBy,colorBy:s,colorScheme:o,color:"string"==typeof r.color?r.color:void 0,forecast:r.forecast,anomaly:r.anomaly,gapStrategy:r.gapStrategy,directLabel:r.directLabel,annotations:i.annotations,themeCategorical:c,baseLineStyle:l}),h=i.pointStyle||go(u.data,u.colorAccessor,o,i,r);let d=i.margin;u.marginExtra&&d&&"object"==typeof d?d={...d,...null!=u.marginExtra.right&&{right:Math.max(Number(d.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(d.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==d&&(d={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const g=(!r.directLabel||void 0!==i.showLegend)&&(i.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||l,...Array.isArray(n)&&{areaGroups:n},...n&&null!=r.areaOpacity&&{areaOpacity:r.areaOpacity},...null!=r.band&&{band:r.band},...i,...void 0!==d&&{margin:d},annotations:u.annotations,...u.yExtent&&!i.yExtent&&{yExtent:u.yExtent},...h&&{pointStyle:h},showLegend:g}}},AreaChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.areaBy,n=Ct({data:e,safeData:Array.isArray(e)?be(e):[],areaBy:r.areaBy,lineDataAccessor:r.lineDataAccessor||"coordinates"}),a=r.semanticGradient,c=a&&a.length>0?{colorStops:Jt(a)}:i.gradientFill,l=i.pointStyle||go(n,s,o,i,r);return{chartType:"area",data:n,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",y0Accessor:r.y0Accessor,groupAccessor:r.areaBy||void 0,colorAccessor:s,colorScheme:o,...i,...void 0!==c&&{gradientFill:c},lineStyle:i.lineStyle||lo(n,s,o,i,r),...l&&{pointStyle:l}}}},DifferenceChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=r.xAccessor||"x",n=r.seriesAAccessor||"a",a=r.seriesBAccessor||"b",c=e=>to(eo(s,"x",e)),l=e=>to(eo(n,"a",e)),u=e=>to(eo(a,"b",e)),h=r.seriesAColor||"var(--semiotic-danger, #dc2626)",d=r.seriesBColor||"var(--semiotic-info, #2563eb)",g=r.areaOpacity??.6,p=r.lineWidth??1.5,f=!1!==r.showLines,y=!1!==i.showLegend,m=r.seriesALabel||"A",b=r.seriesBLabel||"B",x=i.legendPosition||"right",v=function(e,t,o,i){if(!e.length)return[];const r=e.filter(e=>Number.isFinite(t(e))).sort((e,o)=>t(e)-t(o)),s=[];let n=0,a=null,c=null,l=[];const u=(e,t)=>e>t?"A":t>e?"B":null,h=e=>`seg-${n}-${e}`,d=e=>s.push(e),g=(e,t)=>{d({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:h(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;r.length>e;e++){const s=r[e],p=t(s),f=o(s),y=i(s);if(!Number.isFinite(p)||!Number.isFinite(f)||!Number.isFinite(y))continue;const m=u(f,y);if(null!==m)if(null!=a){if(c&&c.w!==m){let e,t;if(l.length>0)e=l[0].x,t=l[0].y;else{const o=f-c.a-(y-c.b);if(0!==o){const i=Math.max(0,Math.min(1,(c.b-c.a)/o));e=c.x+i*(p-c.x),t=c.a+i*(f-c.a)}else e=c.x,t=c.a}d({__x:e,__y:t,__y0:t,__diffSegment:h(a),__diffWinner:a,__valA:t,__valB:t}),n++,a=m,d({__x:e,__y:t,__y0:t,__diffSegment:h(a),__diffWinner:a,__valA:t,__valB:t});for(let e=1;l.length>e;e++)g(l[e],a)}else for(const e of l)g(e,a);l=[],d({__x:p,__y:y>f?y:f,__y0:y>f?f:y,__diffSegment:h(a),__diffWinner:a,__valA:f,__valB:y,__sourceDatum:s}),c={x:p,a:f,b:y,w:m}}else{a=m;for(const e of l)g(e,a);l=[],d({__x:p,__y:y>f?y:f,__y0:y>f?f:y,__diffSegment:h(a),__diffWinner:a,__valA:f,__valB:y,__sourceDatum:s}),c={x:p,a:f,b:y,w:m}}else l.push({x:p,y:f,datum:s})}for(const e of l)g(e,a??"A");return s}(Array.isArray(e)?e:[],c,l,u),A=[];if(f&&Array.isArray(e)){const t=e.filter(e=>Number.isFinite(c(e))).sort((e,t)=>c(e)-c(t));for(const e of t){const t=c(e),o=l(e),i=u(e);Number.isFinite(o)&&A.push({__x:t,__y:o,__diffSegment:"line-A"}),Number.isFinite(i)&&A.push({__x:t,__y:i,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...A],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:e=>{const t=e.__diffSegment;return{fill:"A"==(t?.endsWith("-A")?"A":"B")?h:d,stroke:"none",fillOpacity:g}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?h:d,strokeWidth:p,fill:"none"}),curve:r.curve||"linear",...i,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:m,color:h},{label:b,color:d}]}]},legendPosition:x}}}},StackedAreaChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.areaBy,n="string"==typeof s&&Array.isArray(e)?me(e,s,o):void 0,a="number"==typeof r.areaOpacity?r.areaOpacity:.7,c=i.lineStyle||(e=>{const t=null==s?void 0:ve(e,s,n),o=r.showLine??!0,i={fill:r.color??t,stroke:o?r.stroke??t:"none",...o?{strokeWidth:r.strokeWidth??r.lineWidth??2}:{},fillOpacity:a,...null==r.opacity?{}:{opacity:r.opacity}},c=r.styleRules;if(c?.length){const t=y(r.yAccessor),o=s?"function"==typeof s?(s(e)??"")+"":(e[s]??"")+"":void 0;Object.assign(i,b(e,c,{value:t(e),category:o}))}return i}),l=r.normalize?"zero":r.baseline??"zero",u=i.pointStyle||go(e,s,o,i,r);return{chartType:"stackedarea",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",groupAccessor:r.areaBy,colorAccessor:s,colorScheme:o,normalize:r.normalize,baseline:l,stackOrder:r.stackOrder,lineStyle:c,...i,...u&&{pointStyle:u},curve:i.curve??r.curve??"monotoneX",showLegend:i.showLegend??!!s}}},Scatterplot:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=i.pointStyle||ho(e,t,o,i,r),n=v(r.styleRules,r.xAccessor||"x",r.yAccessor||"y"),a=n?e=>({..."function"==typeof s?s(e):s,...n(e)}):s;return{chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,...r.symbolBy&&{symbolAccessor:r.symbolBy},...r.symbolMap&&{symbolMap:r.symbolMap},colorScheme:o,...i,sizeRange:r.sizeRange||[3,15],pointStyle:a,showLegend:i.showLegend??!!t}}},CandlestickChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const[s]=i.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.highAccessor||"high",highAccessor:r.highAccessor||"high",lowAccessor:r.lowAccessor||"low",openAccessor:r.openAccessor,closeAccessor:r.closeAccessor,candlestickStyle:r.candlestickStyle,...i,scalePadding:i.scalePadding??Math.max(2,Math.min(12,Math.round(s/40))),extentPadding:i.extentPadding??(s>200?.1:.02)}}},BubbleChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,sizeRange:r.sizeRange||[5,40],colorScheme:o,...i,pointStyle:i.pointStyle||uo(e,t,o,i,r),showLegend:i.showLegend??!!t})},ConnectedScatterplot:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};const o=t.xAccessor||"x",i=t.yAccessor||"y",r=t.orderAccessor?[...e].sort((e,o)=>null==e||"object"!=typeof e?1:null==o||"object"!=typeof o?-1:to(eo(t.orderAccessor,"order",e))-to(eo(t.orderAccessor,"order",o))):e,s=new WeakMap;let n=0;for(const e of r){if(null==e||"object"!=typeof e)continue;const t=to(eo(o,"x",e)),r=to(eo(i,"y",e));Number.isFinite(t)&&Number.isFinite(r)&&n++}let a=0;for(const e of r){if(null==e||"object"!=typeof e)continue;const t=to(eo(o,"x",e)),r=to(eo(i,"y",e));Number.isFinite(t)&&Number.isFinite(r)&&s.set(e,{idx:a++,total:n})}return{data:r,orderMap:s}}(e,r),n=r.pointRadius??4;return{chartType:"scatter",data:s.data,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,colorScheme:o,pointStyle:e=>{const t=s.orderMap.get(e),o=t?.idx??0,i=t?.total??1;return{fill:i>0?oo(o,i):"#6366f1",stroke:"white",strokeWidth:1,r:n,fillOpacity:1}},...i,svgPreRenderers:[e=>{const t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(2>t.length)return null;const o=[];for(let e=0;t.length-1>e;e++){const i=t[e],r=t[e+1],s=oo(e,t.length);100>t.length&&o.push(Rt.createElement("line",{key:"halo-"+e,x1:i.x,y1:i.y,x2:r.x,y2:r.y,stroke:"white",strokeWidth:n+2,strokeLinecap:"round",opacity:.5})),o.push(Rt.createElement("line",{key:"segment-"+e,x1:i.x,y1:i.y,x2:r.x,y2:r.y,stroke:s,strokeWidth:n,strokeLinecap:"round"}))}return Rt.createElement(Rt.Fragment,null,...o)}]}}},QuadrantChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=r.xCenter,n=r.yCenter,a=r.quadrants,c=r.centerlineStyle||{},l=!1!==r.showQuadrantLabels,u=r.quadrantLabelSize??12,h=c.stroke||"#999",d=c.strokeWidth??1,g=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,p=Rt.createElement,f=a?[(e,t,o)=>{if(!t?.x||!t?.y)return null;const i=o.width,r=o.height,c=null!=s?t.x(s):i/2,f=null!=n?t.y(n):r/2;if(null!=s&&!Number.isFinite(c))return null;if(null!=n&&!Number.isFinite(f))return null;const y=Math.max(0,Math.min(i,c)),m=Math.max(0,Math.min(r,f)),b=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:i-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:r-m},{c:a.bottomRight,x:y,y:m,w:i-y,h:r-m}],x=l?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:i-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:r-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:i-8,y:r-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(Rt.Fragment,null,...b.map((e,t)=>e.w>0&&e.h>0?p("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),p("line",{key:"vc",x1:y,y1:0,x2:y,y2:r,stroke:h,strokeWidth:d,strokeDasharray:g}),p("line",{key:"hc",x1:0,y1:m,x2:i,y2:m,stroke:h,strokeWidth:d,strokeDasharray:g}),...x)}]:void 0;return{chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,sizeRange:r.sizeRange||[3,15],colorScheme:o,pointStyle:i.pointStyle||r.pointStyle||ho(e,t,o,i,r),...i,showLegend:i.showLegend??!!t,...f&&{svgPreRenderers:f}}}},Heatmap:{frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"heatmap",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",valueAccessor:r.valueAccessor,colorScheme:o||r.colorScheme||"blues",showValues:r.showValues,heatmapValueFormat:r.valueFormat,cellBorderColor:r.cellBorderColor,...i})},TemporalHistogram:{frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=Array.isArray(e)?be(e):[],n=r.timeAccessor||"time",a=r.valueAccessor||"value",c=r.categoryAccessor,l=r.valueExtent||i.yExtent,u="down"===r.direction?K({data:s,timeAccessor:n,valueAccessor:a,binSize:Number(r.binSize),valueExtent:l,extentPadding:r.extentPadding}):l,h={...void 0!==r.fill&&{fill:r.fill},...void 0!==r.stroke&&{stroke:r.stroke},...void 0!==r.strokeWidth&&{strokeWidth:r.strokeWidth},...void 0!==r.opacity&&{opacity:r.opacity},...void 0!==r.gap&&{gap:r.gap}};return{chartType:"bar",data:s,...i,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,s.length),arrowOfTime:r.arrowOfTime||"right",timeAccessor:n,valueAccessor:a,xExtent:r.timeExtent||i.xExtent,yExtent:u,extentPadding:r.extentPadding??i.extentPadding,binSize:r.binSize,categoryAccessor:c,barColors:r.colors||i.barColors,colorScheme:r.colors||i.colorScheme,barStyle:i.barStyle||h,showLegend:i.showLegend??!!c}}},XYCustomChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"custom",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i,showAxes:r.frameProps?.showAxes??r.showAxes??!1,showLegend:i.showLegend??!!t})},BarChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"bar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"horizontal"===r.orientation?"horizontal":"vertical",oSort:r.sort??!1,colorAccessor:t,colorScheme:o,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:Ro(i.gradientFill),pieceStyle:Co(e,t,o,i,r)})},StackedBarChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.stackBy;return{chartType:"bar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",stackBy:r.stackBy,colorAccessor:s,colorScheme:o,projection:"horizontal"===r.orientation?"horizontal":"vertical",normalize:r.normalize,oSort:r.sort??!1,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:Ro(i.gradientFill),pieceStyle:Co(e,s,o,i,r),showLegend:i.showLegend??!!s}}},GroupedBarChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.groupBy;return{chartType:"clusterbar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",groupBy:r.groupBy,colorAccessor:s,colorScheme:o,projection:"horizontal"===r.orientation?"horizontal":"vertical",oSort:r.sort??!1,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:Ro(i.gradientFill),pieceStyle:Co(e,s,o,i,r),showLegend:i.showLegend??!!s}}},PieChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.categoryAccessor;return{chartType:"pie",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"radial",colorAccessor:s,colorScheme:o,...null!=r.cornerRadius&&{cornerRadius:r.cornerRadius},...null!=r.startAngle&&{startAngle:r.startAngle},...i,pieceStyle:Co(e,s,o,i,r),showLegend:i.showLegend??!!s}}},DonutChart:{frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,o,i,r)=>{const s=t||r.categoryAccessor;return{chartType:"donut",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"radial",margin:i.margin??{top:50,right:40,bottom:60,left:70},innerRadius:r.innerRadius??60,colorAccessor:s,colorScheme:o,...null!=r.cornerRadius&&{cornerRadius:r.cornerRadius},...null!=r.startAngle&&{startAngle:r.startAngle},...i,pieceStyle:Co(e,s,o,i,r)}}},Histogram:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=r.valueAccessor||"value",a=s.map(e=>Number("function"==typeof n?n(e):e[n])).filter(Number.isFinite),c=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:e,oAccessor:r.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:n,projection:"horizontal",bins:r.bins??25,normalize:r.relative??!1,colorAccessor:t,colorScheme:o,barPadding:r.categoryPadding??20,...r.valueExtent?{rExtent:r.valueExtent}:c?{rExtent:c}:{},...i,summaryStyle:zo(e,t,o,i,r)}}},BoxPlot:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"boxplot",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,...null!=r.showOutliers&&{showOutliers:r.showOutliers},...null!=r.outlierRadius&&{outlierRadius:r.outlierRadius},...i,summaryStyle:i.summaryStyle||zo(e,t,o,i,r)})},ViolinPlot:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"violin",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===r.orientation?"horizontal":"vertical",bins:r.bins??25,showIQR:r.showIQR??!0,barPadding:r.categoryPadding??20,colorScheme:o,...i,summaryStyle:i.summaryStyle||Fo(e,t,o,i,r),showLegend:i.showLegend??!!t,...r.valueExtent&&{rExtent:r.valueExtent}})},SwarmPlot:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"swarm",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,...r.symbolBy&&{symbolAccessor:r.symbolBy},...r.symbolMap&&{symbolMap:r.symbolMap},colorScheme:o,...i,sizeRange:r.sizeRange||[3,8],pieceStyle:i.pieceStyle||Oo(e,t,o,i,r),showLegend:i.showLegend??!!t})},DotPlot:{frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,o,i,r)=>({chartType:"point",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",oSort:r.sort??"auto",barPadding:r.categoryPadding??10,...i,pieceStyle:Bo(e,t,o,i,r),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!t})},SwimlaneChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",stackBy:r.subcategoryAccessor,colorAccessor:s,categoryAccessor:r.categoryAccessor,subcategoryAccessor:r.subcategoryAccessor,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",...null!=r.trackFill&&{trackFill:r.trackFill},...r.valueExtent&&{rExtent:r.valueExtent},...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:Ro(i.gradientFill),pieceStyle:i.pieceStyle||Co(e,s,o,i,r),showLegend:i.showLegend??!!s,barPadding:r.barPadding??40}}},RidgelinePlot:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"ridgeline",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",bins:r.bins??20,amplitude:r.amplitude??1.5,barPadding:r.categoryPadding??5,oSort:r.oSort??!1,...i,summaryStyle:i.summaryStyle||((s,n)=>({fillOpacity:.5,...Co(e,t,o,i,r)(s,n)})),showLegend:i.showLegend??!!t})},LikertChart:{frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,o,i,r)=>{const s=Array.isArray(r.levels)&&r.levels.length>=2?r.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],n="vertical"!==r.orientation;let a=function(e,t,o,i,r,s){const n=new Map,a=new Set(t);for(const c of e){const e=o(c);n.has(e)||n.set(e,new Map);const l=n.get(e);if(i){const e=i(c);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}const o=e-1;if(0>o||o>=t.length)continue;const r=t[o];l.set(r,(l.get(r)||0)+1)}else if(r&&s){const e=r(c),t=s(c);if(!a.has(e))continue;l.set(e,(l.get(e)||0)+(Number.isFinite(t)?t:0))}}const c=[];for(const[e,o]of n){let i=0;for(const e of t)i+=o.get(e)||0;if(0!==i)for(let r=0;t.length>r;r++){const s=t[r],n=o.get(s)||0;c.push({__likertCategory:e,__likertLevel:s,__likertLevelLabel:s,__likertCount:n,__likertPct:n/i*100,__likertLevelIndex:r})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s,To(r.categoryAccessor,"question"),r.levelAccessor?null:To(r.valueAccessor,"score"),r.levelAccessor?To(r.levelAccessor,"level"):null,r.levelAccessor?To(r.countAccessor,"count"):null);n&&(a=function(e,t){const o=t.length,i=o%2!=0,r=Math.floor(o/2),s=new Map;for(const t of e){const e=s.get(t.__likertCategory)||[];e.push(t),s.set(t.__likertCategory,e)}const n=[];for(const[,e]of s){const t=new Map;let s,a;for(const o of e)o.__likertLevel===Mo?s=o:o.__likertLevel===Po?a=o:t.set(o.__likertLevelIndex,o);i&&s&&n.push(s);for(let e=r-1;e>=0;e--){const o=t.get(e);o&&n.push(o)}i&&a&&n.push(a);for(let e=i?r+1:r;o>e;e++){const o=t.get(e);o&&n.push(o)}}return n}(function(e,t){const o=t.length,i=o%2!=0,r=Math.floor(o/2),s=[];for(const t of e){const e=t.__likertLevelIndex;if(i&&e===r){const e=t.__likertPct/2;s.push({...t,__likertLevel:Mo,__likertPct:-e}),s.push({...t,__likertLevel:Po,__likertPct:e})}else s.push(r>e?{...t,__likertPct:-t.__likertPct}:t)}return s}(a,s),s));const c=io(i.theme).colors.diverging,l=Array.isArray(o)&&o.length>=s.length?o:function(e,t){if(0>=e)return[];if(t){const o=_o[t];if(o){if(1===e)return[o(.5)];const t=[];for(let i=0;e>i;i++)t.push(o(i/(e-1)));return t}}const o=["#da1e28","#ff8389","#ffb3b8"],i=["#a6c8ff","#4589ff","#0043ce"],r="#a8a8a8";if(1===e)return[r];const s=e%2!=0,n=Math.floor(e/2),a=[];for(let e=0;n>e;e++)a.push(o[Math.min(Math.floor(e*o.length/n),o.length-1)]);s&&a.push(r);for(let e=0;n>e;e++)a.push(i[Math.min(Math.floor(e*i.length/n),i.length-1)]);return a}(s.length,c),u=new Map(s.map((e,t)=>[e,l[t]||"#888"])),h=s.length%2&&u.get(s[Math.floor(s.length/2)])||"#888",d="function"==typeof r.valueFormat?r.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",g=!1===i.showLegend?void 0:{legendGroups:[{label:"",items:s.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},p=pe(g,i.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:n?"horizontal":"vertical",barPadding:r.barPadding,showGrid:i.showGrid,oLabel:r.categoryLabel,rLabel:r.valueLabel||(n?void 0:"Percentage"),rFormat:d,...r.categoryFormat&&{oFormat:r.categoryFormat},...r.valueExtent&&{rExtent:r.valueExtent},...i,pieceStyle:e=>{const t=e.__likertLevel||e.data?.__likertLevel;return{fill:t===Mo||t===Po?h:u.get((e.__likertLevelLabel||e.data?.__likertLevelLabel||t)+"")||"#888"}},showLegend:i.showLegend??!0,legendPosition:i.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}},FunnelChart:{frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s="vertical"===r.orientation,n=t||r.categoryAccessor;return{chartType:s?"bar-funnel":"funnel",data:e,oAccessor:r.stepAccessor||"step",rAccessor:r.valueAccessor||"value",colorAccessor:n,categoryAccessor:r.categoryAccessor,projection:s?"vertical":"horizontal",connectorAccessor:r.connectorAccessor,connectorStyle:r.connectorStyle,...!s&&null!=r.connectorOpacity&&{connectorOpacity:r.connectorOpacity},barPadding:s?40:0,colorScheme:o,...i,showAxes:s,showGrid:s,pieceStyle:Co(e,n,o,i,r),showLabels:r.showLabels??!0}}},GaugeChart:{frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){const o=e.__gauge;if(!o)return null;const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.needleColor||t.colors.text,s=o.showScaleLabels?(o.thresholds||[]).filter(e=>e.value>o.gMin&&o.gMax>e.value):[];return Ao(xo,{children:[o.showNeedle&&Ao(xo,{children:[vo("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(i),y2:o.centerY+o.needleLength*Math.sin(i),stroke:r,strokeWidth:2.5,strokeLinecap:"round"}),vo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:r})]}),null!=o.contextValue&&vo("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:r,children:o.contextValue}),s.map((e,i)=>{const r=(o.startAngleDeg+(o.gMax===o.gMin?0:(e.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,s=o.innerRadius-1,n=o.radius+1,a=o.radius+10,c=((r+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",u=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return Ao("g",{children:[vo("line",{x1:o.centerX+Math.cos(r)*s,y1:o.centerY+Math.sin(r)*s,x2:o.centerX+Math.cos(r)*n,y2:o.centerY+Math.sin(r)*n,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),vo("text",{x:o.centerX+Math.cos(r)*a,y:o.centerY+Math.sin(r)*a,textAnchor:l,dominantBaseline:u,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+i)})]})},buildProps:(o,i,r,s,n)=>{const a=n.min??0,c=n.max??100,l=n.sweep??240,u=n.arcWidth??.3,h=!1!==n.showNeedle,d=!1!==n.fillZones,{startAngleDeg:g}=t(l),p=n.thresholds||[{value:c,color:n.color||"#4e79a7"}],f=s.gradientFill,y=function(e){const{min:t,max:o,value:i,thresholds:r,fillColor:s,backgroundColor:n,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=e,h=o-t||1,d=(Math.max(t,Math.min(o,i))-t)/h;let g=r&&r.length>0?[...r].sort((e,t)=>e.value-t.value):[{value:o,color:s||"#007bff"}];g=g.map(e=>({...e,value:Math.max(t,Math.min(o,e.value))})),o>g[g.length-1].value&&g.push({value:o,color:g[g.length-1].color});const p=!!l&&l.colorStops.length>=2,f=[],y=new Map,m=[];if(p){const e=a?d:1,t=bo("bg",0);if(f.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(t,{fill:n,opacity:.4}),e>0){const t=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(t,Math.round(e*t))),i=[];for(let t=0;o>t;t++)i.push(mo(l.colorStops,e*(t+.5)/o));const r=bo("fill",0);f.push({category:r,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:i}}),y.set(r,{fill:i[0]||n})}}else{let e=t;for(let o=0;g.length>o;o++){const i=g[o],r=(i.value-e)/h,s=(e-t)/h,c=(i.value-t)/h,l=Math.max(0,(a?Math.min(d,c):c)-s),u=a?Math.max(0,r-l):0;if(l>0){const e=bo("fill",o);f.push({category:e,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),y.set(e,{fill:i.color})}if(u>0){const e=bo("bg",o);f.push({category:e,value:u,_zone:i.label||"Zone "+(o+1),_isFill:!1}),y.set(e,{fill:n,opacity:.4})}e=i.value}}if(c&&r&&r.length>0)for(const e of r)e.value>t&&o>e.value&&m.push({type:"gauge-label",value:e.value,label:e.label||e.value+""});return{gaugeData:f,pieceStyle:(e,t)=>y.get(t||e.category)||{fill:n},gaugeAnnotations:m}}({min:a,max:c,value:n.value,thresholds:p,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:d,showScaleLabels:!1!==n.showScaleLabels,gradientFill:f&&"object"==typeof f&&"colorStops"in f?f:void 0}),[m,b]=s.size||[300,250],x=e(l),v=Math.min(10,Math.max(1,Math.min(m,b)/12)),A=Math.max(4,Math.min((m-2*v)/x.width,(b-2*v)/x.height)-2),S=Math.max(0,Math.min(A-1.5,A*(1-u))),w=m/2-x.cx*A,k=b/2-x.cy*A,_=2*(A+4),M=Math.max(a,Math.min(c,n.value??a)),P="function"==typeof n.valueFormat?n.valueFormat(M):Math.round(M)+"",T=n.centerContent??s.centerContent,L=null!=T?"function"==typeof T?T(M,a,c):T:"sparkline"===n.mode||"context"===n.mode?void 0:Lo.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Lo.createElement("div",{style:{fontSize:Math.max(16,.3*A),fontWeight:700,color:"var(--semiotic-text, #333)"}},P),!1!==n.showScaleLabels&&Lo.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${a} – ${c}`));return{chartType:"donut",data:y.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:S,sweepAngle:l,startAngle:g,oSort:!1,pieceStyle:y.pieceStyle,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...s,size:[m,b],margin:{top:k-_/2,bottom:b-k-_/2,left:w-_/2,right:m-w-_/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(s.annotations)?s.annotations:[],...y.gaugeAnnotations],__gauge:{gMin:a,gMax:c,sweep:l,arcWidth:u,value:M,startAngleDeg:g,thresholds:p,centerX:w,centerY:k,radius:A,innerRadius:S,showScaleLabels:!1!==n.showScaleLabels,needleLength:S>20?S-8:A-1,showNeedle:h,needleColor:n.needleColor,..."context"===n.mode&&null==T&&{contextValue:P,contextValueY:k-.2*S,valueFontSize:Math.max(12,Math.min(22,.28*A))}}}}},OrdinalCustomChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"custom",data:e,oAccessor:r.categoryAccessor||r.oAccessor||"category",rAccessor:r.valueAccessor||r.rAccessor||"value",projection:r.projection||"vertical",colorAccessor:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i,showAxes:r.frameProps?.showAxes??r.showAxes??!1})},ForceDirectedGraph:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const{edgeWidth:s,edgeColor:n,edgeOpacity:a}=r,c=r.edgeStyle??(void 0!==s||void 0!==n||void 0!==a?e=>{const t=e?.data||e;let o=1;if("number"==typeof s)o=s;else if("function"==typeof s)o=s(t);else if("string"==typeof s){const e=t?.[s],i="number"==typeof e?e:Number(e);o=Number.isFinite(i)&&i>0?i:1}return{stroke:n??"#999",strokeWidth:o,opacity:a??.6}}:void 0),l=io(i.theme).colors.categorical,u=new Map,h=r.nodeStyle??(e=>({fill:t?ve(e?.data||e,t,void 0):We(void 0,l,o,void 0,u),..."number"==typeof r.nodeSize&&{r:r.nodeSize}})),d=x(r.styleRules,t,"number"==typeof r.nodeSize?void 0:r.nodeSize);return{chartType:"force",nodes:r.nodes,edges:r.edges,nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor,sourceAccessor:r.sourceAccessor,targetAccessor:r.targetAccessor,colorBy:t,colorScheme:o,iterations:r.iterations,forceStrength:r.forceStrength,showLabels:r.showLabels??!1,nodeLabel:r.nodeLabel,nodeSize:r.nodeSize??8,nodeSizeRange:r.nodeSizeRange,nodeStyle:d?(e,t)=>({...h(e),...d(e,t)}):h,edgeStyle:c,...i}}},NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,o,i,r)=>({chartType:"force",nodes:r.nodes||e||[],edges:r.edges||[],nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor||"id",sourceAccessor:r.sourceAccessor||"source",targetAccessor:r.targetAccessor||"target",valueAccessor:r.valueAccessor||"value",colorBy:t,colorScheme:o,customNetworkLayout:r.layout||r.customNetworkLayout,layoutConfig:r.layoutConfig,...i})},SankeyDiagram:{frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,o,i,r)=>{const s=Array.isArray(r.nodes)?r.nodes:Zo([],Array.isArray(r.edges)?r.edges:[],r.sourceAccessor||"source",r.targetAccessor||"target"),n=io(i.theme).colors.categorical,a=new Map,c="string"==typeof t?t:"__ssrSankeyColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrSankeyColorBy:t(e)})):s,u=t?me(l,c,o??i.colorScheme??n):void 0,h=e=>({fill:t?ve(e?.data||e,t,u):We(void 0,n,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),d=x(r.styleRules,t,r.valueAccessor),g=d?(e,t)=>({...h(e),...d(e,t)}):h,p=function({edgeColorBy:e,colorBy:t,colorScale:o,nodeStyleFn:i,edgeOpacity:r,baseStyle:s={}}){return n=>{const a={fillOpacity:r,...s};if("function"==typeof e)a.fill=e(n);else if("source"===e){const e="object"==typeof n.source?n.source:null;t&&e?a.fill=ve(e.data||e,t,o):e&&(a.fill=i(e,e.index).fill)}else if("target"===e){const e="object"==typeof n.target?n.target:null;t&&e?a.fill=ve(e.data||e,t,o):e&&(a.fill=i(e,e.index).fill)}else"gradient"===e&&(a.fill="#999",a.fillOpacity=.7*r);return a}}({edgeColorBy:r.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:g,edgeOpacity:r.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:r.nodes,edges:r.edges,nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor,sourceAccessor:r.sourceAccessor,targetAccessor:r.targetAccessor,valueAccessor:r.valueAccessor,orientation:r.orientation,nodeAlign:r.nodeAlign,nodeWidth:r.nodeWidth,nodePaddingRatio:r.nodePaddingRatio,showLabels:r.showLabels,nodeLabel:r.nodeLabel,colorBy:t,edgeColorBy:r.edgeColorBy,edgeOpacity:r.edgeOpacity,nodeStyle:i.nodeStyle||r.nodeStyle||g,edgeStyle:i.edgeStyle||r.edgeStyle||p,colorScheme:o,...i}}},ProcessSankey:{frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,o,i,r)=>{const s=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),n=r.sourceAccessor||"source",a=r.targetAccessor||"target",c=r.valueAccessor||"value",l=r.nodeIdAccessor||"id",u=r.startTimeAccessor||"startTime",h=r.endTimeAccessor||"endTime",d=r.systemInTimeAccessor,g=r.systemOutTimeAccessor,p=r.xExtentAccessor||"xExtent",f=r.edgeIdAccessor||"id",y=(e,t)=>"function"==typeof e?e(t):t[e],m=Array.isArray(r.edges)?r.edges:[],b=Array.isArray(r.nodes)?r.nodes:[],x=b.length>0?b:Zo([],m,n,a),v=[s(r.domain?.[0]),s(r.domain?.[1])],A=x.map(e=>{const t=y(l,e)+"",o=y(p,e),i={id:t,__raw:e};if(Array.isArray(o)&&2===o.length){const e=s(o[0]),t=s(o[1]);Number.isFinite(e)&&Number.isFinite(t)&&(i.xExtent=[e,t])}return i}),S=m.map((e,t)=>{const o=y(f,e),i={id:null!=o?o+"":`${y(n,e)}-${y(a,e)}-${t}`,source:y(n,e)+"",target:y(a,e)+"",value:Number(y(c,e)),startTime:s(y(u,e)),endTime:s(y(h,e)),__raw:e};if(d){const t=s(y(d,e));Number.isFinite(t)&&(i.systemInTime=t)}if(g){const t=s(y(g,e));Number.isFinite(t)&&(i.systemOutTime=t)}return i}),[w,k]=i.size??[600,400],_={top:20,right:20,bottom:20,left:20,...i.margin},M=(i.showLegend??!!t)&&!!t,P=i.legendPosition??"right",T=i.__explicitMargin,L=e=>"number"==typeof T||null!=T&&"object"==typeof T&&null!=T[e];M&&("right"!==P||L("right")?"bottom"!==P||L("bottom")||(_.bottom=Math.max(_.bottom,80)):_.right=Math.max(_.right,140));const R=_,C=w-R.left-R.right,z=k-R.top-R.bottom,F=io(i.theme),B=De(o,F.colors.categorical,bt),O="function"==typeof t?t:null,E=O?x.map(e=>({_cat:O(e)})):x,D=O?"_cat":"string"==typeof t?t:void 0,j=o??[...B],N=D?me(E,D,j):null,W=new Map;for(const e of A)W.set(e.id,e.__raw);const I=(e,o)=>{if(t&&W.has(e)){const o=W.get(e);return O?ve({_cat:O(o)},"_cat",N??void 0):ve(o,"string"==typeof t?t:"id",N??void 0)}return B[o%B.length]},$=M&&t?(()=>{const e=new Map;x.forEach((o,i)=>{const r=y(t,o),s=null==r?"":r+"";s&&!e.has(s)&&e.set(s,{label:s,color:I(y(l,o)+"",i)})});const o=Array.from(e.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:e=>{const t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,G=pe($,i.legend),{layout:Y,layoutConfig:H,issues:V,xScale:X}=qo({nodes:A,edges:S,domain:v,plotW:C,plotH:z,ribbonLane:r.ribbonLane||"both",edgeOpacity:"number"==typeof r.edgeOpacity?r.edgeOpacity:.35,colorOf:I,layoutOpts:{pairing:r.pairing||"temporal",packing:r.packing||"reuse",laneOrder:r.laneOrder||"crossing-min",lifetimeMode:r.lifetimeMode||"half"}});if(V.length>0){const e=V.map(Do).join("; ");throw Error("ProcessSankey: data invalid — "+e)}const q=Array.isArray(r.axisTicks)?r.axisTicks:[],Q=Y?(()=>{let e=null,t=null;for(const o of A){const i=Y.laneLifetime[o.id];if(!i||null==i.start||null==i.end)continue;const r=Number(X(i.start)),s=Number(X(i.end));e=null==e?r:Math.min(e,r),t=null==t?s:Math.max(t,s)}const o=e=>Math.max(0,Math.min(C,e)),i=o(e??0),n=Math.max(i,o(t??C)),a=q.map((e,t)=>({tick:e,index:t,x:Number(X(s(e.date)))})).filter(({x:e})=>e>=i-.5&&n+.5>=e);return Uo.createElement("g",null,...a.map(({index:e,x:t})=>Uo.createElement("line",{key:"grid-"+e,x1:t,y1:0,x2:t,y2:z,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),Uo.createElement("line",{key:"axis",x1:i,y1:z+4,x2:n,y2:z+4,stroke:"#94a3b8"}),...a.map(({tick:e,index:t,x:o})=>{const i=s(e.date),n=null!=e.label?e.label:"function"==typeof r.timeFormat?r.timeFormat(new Date(i)):"";return Uo.createElement("g",{key:"tick-"+t,transform:`translate(${o},${z+4})`},Uo.createElement("line",{y2:6,stroke:"#94a3b8"}),Uo.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},n))}))})():void 0;return{chartType:"force",nodes:x,edges:m,customNetworkLayout:Qo,layoutConfig:H,sourceAccessor:n,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:t,colorScheme:o,...Q&&{backgroundGraphics:Q},...i,showLegend:M,...G&&{legend:G,legendPosition:P},__legendIncludesAutomatic:!0,margin:R}}},ChordDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{if(!(t||Array.isArray(r.styleRules)&&r.styleRules.length>0||i.nodeStyle||r.nodeStyle))return{chartType:"chord",nodes:r.nodes,edges:r.edges,valueAccessor:r.valueAccessor,padAngle:r.padAngle,groupWidth:r.groupWidth,showLabels:r.showLabels,colorBy:t,edgeColorBy:r.edgeColorBy,colorScheme:o,...i};const s=Array.isArray(r.edges)?r.edges:[],n=Array.isArray(r.nodes)&&r.nodes.length>0?r.nodes:Zo([],s,r.sourceAccessor||"source",r.targetAccessor||"target"),a=io(i.theme).colors.categorical,c=De(o,a),l="string"==typeof t?t:"__ssrChordColorBy",u="function"==typeof t?n.map(e=>({...e,__ssrChordColorBy:t(e)})):n,h=t?me(u,l,o??i.colorScheme??a):void 0,d=new Map,g=r.nodeIdAccessor||r.nodeIDAccessor||"id",p=(e,o)=>{const r=e?.data||e;let s;if(t)s=ve(r,t,h);else{const t=(e.id??r?.[g]??"")+"";d.has(t)||d.set(t,d.size);const i=e.index??o??d.get(t);s=c[i%c.length]}return{fill:s,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},f=x(r.styleRules,t,r.valueAccessor,p)??p;return{chartType:"chord",nodes:r.nodes,edges:r.edges,valueAccessor:r.valueAccessor,padAngle:r.padAngle,groupWidth:r.groupWidth,showLabels:r.showLabels,colorBy:t,edgeColorBy:r.edgeColorBy,colorScheme:o,nodeStyle:i.nodeStyle||r.nodeStyle||f,...i}}},TreeDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=io(i.theme).colors.categorical,n=new Map,a=Ko(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreeColorBy:c(e)})):a,u=c?"__ssrTreeColorBy":"string"==typeof t?t:void 0,h=t&&u?me(l,u,o??i.colorScheme??s):void 0;return{chartType:"cluster"===r.layout?"cluster":"tree",data:e,childrenAccessor:r.childrenAccessor,colorBy:t,colorByDepth:r.colorByDepth,orientation:r.orientation,showLabels:r.showLabels,nodeLabel:!1!==r.showLabels?r.nodeLabel||r.nodeIdAccessor:void 0,colorScheme:o,...i,nodeStyle:i.nodeStyle||r.nodeStyle||(e=>{const a=e?.data||e;return{fill:r.colorByDepth?ae[Number(e?.depth||0)%ae.length]:t?c?ve({__ssrTreeColorBy:c(a)},"__ssrTreeColorBy",h??void 0):ve(a,t,h??void 0):We(void 0,s,o,void 0,n),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}})}}},Treemap:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=io(i.theme).colors.categorical,n=new Map,a=Ko(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreemapColorBy:c(e)})):a,u=c?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,h=t&&u?me(l,u,o??i.colorScheme??s):void 0,d=r.showLabels??i.showLabels,g=r.labelMode,p=void 0!==r.paddingTop?r.paddingTop:!d||"parent"!==g&&"all"!==g?void 0:18;return{chartType:"treemap",data:e,childrenAccessor:r.childrenAccessor,hierarchySum:r.valueAccessor,colorBy:t,colorByDepth:r.colorByDepth,showLabels:r.showLabels,labelMode:g,nodeLabel:d?r.nodeLabel||r.nodeIdAccessor:void 0,...null!=r.padding&&{padding:r.padding},...null!=p&&{paddingTop:p},colorScheme:o,...i,nodeStyle:i.nodeStyle||r.nodeStyle||(e=>{const i=e?.data||e;return{fill:r.colorByDepth?ae[Number(e?.depth||0)%ae.length]:t?c?ve({__ssrTreemapColorBy:c(i)},"__ssrTreemapColorBy",h??void 0):ve(i,t,h??void 0):We(void 0,s,o,void 0,n),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}})}}},CirclePack:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=io(i.theme).colors.categorical,n=new Map,a=Ko(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrCirclePackColorBy:c(e)})):a,u=c?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,h=t&&u?me(l,u,o??i.colorScheme??s):void 0;return{chartType:"circlepack",data:e,childrenAccessor:r.childrenAccessor,hierarchySum:r.valueAccessor,colorBy:t,colorByDepth:r.colorByDepth,showLabels:r.showLabels,nodeLabel:r.showLabels??i.showLabels?r.nodeLabel||r.nodeIdAccessor:void 0,...null!=r.padding&&{padding:r.padding},colorScheme:o,...i,nodeStyle:i.nodeStyle||r.nodeStyle||(e=>{const i=e?.data||e;return{fill:r.colorByDepth?ae[Number(e?.depth||0)%ae.length]:t?c?ve({__ssrCirclePackColorBy:c(i)},"__ssrCirclePackColorBy",h??void 0):ve(i,t,h??void 0):We(void 0,s,o,void 0,n),fillOpacity:r.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}})}}},ChoroplethMap:{frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s="string"==typeof o?o:"blues",n=r.areaStyle??function(e,t,o,i){if(!Array.isArray(e))return;const r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0;let s=1/0,n=-1/0;for(const t of e){const e=r(t);null!=e&&isFinite(e)&&(s>e&&(s=e),e>n&&(n=e))}const a=ei(lt(o)).domain([Number.isFinite(s)?s:0,Number.isFinite(n)?n:1]);return e=>{const t=r(e);return{fill:null!=t&&isFinite(t)?a(t):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:i}}}(r.areas,r.valueAccessor,s,r.areaOpacity??1),a=r.styleRules?p(n,r.styleRules,e=>{return{value:(t=e,"function"==typeof r.valueAccessor?r.valueAccessor(t):null!=r.valueAccessor?t?.properties?.[r.valueAccessor]??t?.[r.valueAccessor]:void 0)};var t},ti):n;return{areas:r.areas,projection:r.projection||"equalEarth",areaStyle:a,valueAccessor:r.valueAccessor,colorScheme:s,graticule:r.graticule,fitPadding:r.fitPadding,...i}}},ProportionalSymbolMap:{frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s=e||r.points,n=r.pointStyle??function(e,t,o,i){const r=Array.isArray(e)?e:[];let s,n;if(t){const e="string"==typeof t?t:"__geoColorBy",i="string"==typeof t?r:r.map(e=>({...e,__geoColorBy:t(e)}));s=me(i,e,o)}if(i.sizeBy){const e=r.map("function"==typeof i.sizeBy?i.sizeBy:e=>e?.[i.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(n=At(e))}return e=>({fill:t&&s?ve(e,t,s):se,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?Se(e,i.sizeBy,i.sizeRange,n):i.pointRadius??6})}(s,t,o,{sizeBy:r.sizeBy,sizeRange:r.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=r.styleRules?p(n,r.styleRules,f(t,r.sizeBy)):n;return{points:s,xAccessor:r.xAccessor||"lon",yAccessor:r.yAccessor||"lat",areas:r.areas,areaStyle:r.areaStyle||Jo,pointStyle:a,sizeBy:r.sizeBy,colorBy:t,colorScheme:o,projection:r.projection||"equalEarth",graticule:r.graticule,fitPadding:r.fitPadding,...i}}},FlowMap:{frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s=(Array.isArray(e)?e:null)||r.flows||[],n=r.nodeIdAccessor||"id",a=r.valueAccessor||"value",c=r.xAccessor||"lon",l=r.yAccessor||"lat",u="function"==typeof c?c:e=>e[c],h="function"==typeof l?l:e=>e[l],d=(r.nodes||[]).map(e=>({...e,x:u(e),y:h(e)})),g=new Map;for(const e of d)g.set(e[n]+"",e);const p=r.edgeColorBy??t,f="function"==typeof p,y=s.map(e=>{if(!e||null==e.source||null==e.target)return null;const t=g.get(e.source+""),o=g.get(e.target+"");return t&&o?{...e,coordinates:[{x:t.x,y:t.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",b=(()=>{if(!p)return null;if(f){const e=y.map(e=>({[m]:p(e)}));return me(e,m,o||"category10")}return me(y,p,o||"category10")})(),x=e=>p&&b?ve(e,p,b):"#007bff";let v=1/0,A=-1/0;for(const e of y){const t=Number(e[a]??0);isFinite(t)&&(v>t&&(v=t),t>A&&(A=t))}const S=A>v?A-v:0,[w,k]=r.edgeWidthRange??[1,8],_=k-w,M=r.edgeOpacity??.6,P=r.edgeLinecap??"round";return{lines:y,points:d,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:r.lineType||"geo",flowStyle:r.flowStyle||"basic",areas:r.areas,areaStyle:r.areaStyle||Jo,projection:r.projection||"equalEarth",graticule:r.graticule,fitPadding:r.fitPadding,colorScheme:o,lineStyle:e=>{const t=Number(e?.[a]),o=Number.isFinite(t)?t:v,i=w+Math.max(0,Math.min(1,S>0?(o-v)/S:0))*_;return{stroke:x(e),strokeWidth:i,strokeLinecap:P,opacity:M,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...i}}},GeoCustomChart:{frameType:"geo",buildProps:(e,t,o,i,r)=>({points:r.points||e||[],areas:r.areas||[],lines:r.lines||[],projection:r.projection||"equirectangular",xAccessor:r.xAccessor||"lon",yAccessor:r.yAccessor||"lat",lineDataAccessor:r.lineDataAccessor,colorBy:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i})},GaltonBoardChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const n=i.size??[600,400],a=s.bins??21,l=s.seed??1,u=Math.max(1,Math.round(s.pegRows??a-1)),h="mechanical"===s.mode,d=h?c({bins:a,branchProbability:s.branchProbability,count:s.mechanicalCount,pegRows:u,seed:l}):Array.isArray(e)?e:[],p=r({data:d,valueAccessor:s.valueAccessor||"value",bins:a,ballRadius:s.ballRadius??4,seed:l,size:n,valueExtent:h?[0,u]:void 0});return{...i,config:p.config,initialSpawns:pi(p.initialSpawns),projectionRows:p.projectionRows,bodyStyle:g(t||s.colorBy||(h?"side":void 0),"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(e,t,o,r,s)=>{const n=r.size??[600,400],a=i({data:Array.isArray(e)?e:[],timeAccessor:s.timeAccessor||"time",arrivalAccessor:s.arrivalAccessor||"arrivalTime",windows:s.windows||{size:10},watermark:s.watermark,ballRadius:s.ballRadius??5,seed:s.seed??1,size:n,timeExtent:s.timeExtent,timeScale:s.timeScale??1});return{...r,config:a.config,initialSpawns:pi(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||s.colorBy,"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.valueAccessor||s.timeAccessor||"time"})}}},PhysicsPileChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[600,400],a="mechanical"===r.mode,c=a?l({categories:r.mechanicalCategories,count:r.mechanicalCount,seed:r.seed??1,unitValue:r.unitValue??1}):Array.isArray(e)?e:[],u=n({data:c,categoryAccessor:r.categoryAccessor||"category",valueAccessor:r.valueAccessor||(a?"value":void 0),unitValue:r.unitValue??1,ballRadius:r.ballRadius??5,seed:r.seed??1,size:s});return{...i,config:u.config,initialSpawns:pi(u.initialSpawns),projectionRows:u.projectionRows,bodyStyle:g(t||r.colorBy||(a?"category":void 0),"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(e,t,i,r,s)=>{const n=r.size??[600,360],a=o({data:Array.isArray(e)?e:[],xAccessor:s.xAccessor||"x",groupAccessor:s.groupAccessor,radiusAccessor:s.radiusAccessor,pointRadius:s.pointRadius??5,seed:s.seed??1,size:n,xExtent:s.xExtent,collisionIterations:s.collisionIterations,settle:s.settle});return{...r,config:a.config,initialSpawns:pi(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||s.colorBy||s.groupAccessor,"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,420],n=Array.isArray(r.stages)?r.stages:[],c=a({data:Array.isArray(e)?e:[],stages:n,size:s,idAccessor:r.idAccessor,stageAccessor:r.stageAccessor||"stage",groupBy:r.groupBy,groupLabelAccessor:r.groupLabelAccessor,workAccessor:r.workAccessor,radiusAccessor:r.radiusAccessor,ballRadius:r.ballRadius??6,seed:r.seed??1,groupCompletion:r.groupCompletion,groupAnchorAlong:r.groupAnchorAlong,settle:r.settle??!0,gravityX:r.gravityX,gravityY:r.gravityY}),l=c.metadata;return{...i,config:c.config,initialSpawns:pi(c.initialSpawns),projectionRows:c.projectionRows,regionEffects:l?.regionEffects,bodyStyle:g(t||r.colorBy||r.groupBy,"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.workAccessor||r.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,520],n=gi({data:Array.isArray(e)?e:[],size:s,gates:r.gates,positiveProperties:r.positiveProperties,negativeProperties:r.negativeProperties,crashOffset:r.crashOffset,idAccessor:r.idAccessor,positiveAccessor:r.positiveAccessor,negativeAccessor:r.negativeAccessor,metricsAccessor:r.metricsAccessor,initialViability:r.initialViability,projectPlacement:r.projectPlacement,coreBody:r.coreBody,viability:r.viability});return{...i,config:n.config,initialSpawns:pi(n.initialSpawns),projectionRows:[],bodyStyle:g(t||r.colorBy)}}},PhysicalFlowChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const n=i.size??[760,420],a=s({nodes:Array.isArray(r.nodes)?r.nodes:[],links:Array.isArray(r.links)?r.links:Array.isArray(r.edges)?r.edges:Array.isArray(e)?e:[],nodeIdAccessor:r.nodeIdAccessor||"id",nodeXAccessor:r.nodeXAccessor||"x",nodeYAccessor:r.nodeYAccessor||"y",sourceAccessor:r.sourceAccessor||"source",targetAccessor:r.targetAccessor||"target",throughputAccessor:r.throughputAccessor||"value",pathAccessor:r.pathAccessor||"path",coordinateMode:r.coordinateMode||"auto",particleRate:r.particleRate??.16,maxParticles:r.maxParticles??180,particleRadius:r.particleRadius??4,flowSpeed:r.flowSpeed??90,pathConstraint:r.pathConstraint||"path",reducedMotion:!0,seed:r.seed??1,size:n});return{...i,config:a.config,initialSpawns:pi(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||r.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[700,380],n=d({chartId:r.chartId,colorScheme:o,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Pt(kt)??{},size:s,themeCategorical:kt.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:n.config,initialSpawns:pi(n.initialSpawns),projectionRows:[],bodyStyle:n.result.bodyStyle??g(t||r.colorBy)}}}};function yi(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function mi(e){if(!e||2>e.length)return;const t=yi(e[0]),o=yi(e[e.length-1]);return null!==t&&null!==o?[t,o]:void 0}function bi(e){const{count:t,byType:o}=function(e){const t={};for(const o of e){const e="string"==typeof o?.type&&o.type.length>0?o.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),i=0===t,r=[...e.extraWarnings??[]];return i&&!r.includes("EMPTY_SCENE")&&r.push("EMPTY_SCENE"),{component:"",frameType:e.frameType,status:i?"empty":"ok",empty:i,markCount:t,markCountByType:o,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:Array.isArray(e.annotations)?e.annotations.length:0,ariaLabel:"string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,warnings:r}}import*as xi from"react";import*as vi from"react-dom/server";import{scaleOrdinal as Ai}from"d3-scale";import{jsx as Si,jsxs as wi}from"react/jsx-runtime";var ki=ne;function _i(e,t,o){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>Ie(e,t)??"#999"}const i=Array.isArray(t)?t:o.colors.categorical.length>0?o.colors.categorical:bt;return Ai().domain(e).range(i)}function Mi(e){return"left"===e?"start":"right"===e?"end":e??"start"}function Pi(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function Ti(e,t,o,i){const r=Pi(i);return t+o+Math.ceil(e.length*r*.58)}function Li(e){const{categories:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=$e(n),h=a+c,d="top"===i||"bottom"===i,g=Math.max(a,r-s.left-s.right),p=t.map(e=>Ti(e,a,c,o));if(d){const e=Math.max(a,n?.maxWidth??g),o=[];let i=0,r=0;p.forEach((t,s)=>{const n=0===r?t:r+l+t;r>0&&n>e?(o.push({start:i,end:s,width:r}),i=s,r=t):r=n}),t.length>0&&o.push({start:i,end:t.length,width:r});const s=Mi(n?.align),c=[];return o.forEach((o,i)=>{let r="center"===s?Math.max(0,(e-o.width)/2):"end"===s?Math.max(0,e-o.width):0;for(let e=o.start;o.end>e;e++)c.push({category:t[e],width:p[e],x:r,y:i*u}),r+=p[e]+l}),{items:c,width:Math.max(0,...o.map(e=>e.width)),height:o.length*u,swatchSize:a,labelOffset:h,swatchRadius:0}}const f=Math.max(0,...p);return{items:t.map((e,t)=>({category:e,width:p[t],x:0,y:t*u})),width:f,height:t.length*u,swatchSize:a,labelOffset:h,swatchRadius:0}}function Ri(e){const{legendGroups:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,rowHeight:l}=$e(n),u=a+c,h=Math.max(12,Pi(o)),d="top"===i||"bottom"===i,g=Math.max(a,r-s.left-s.right);if(d){const i=Math.max(a,n?.maxWidth??g),r=Mi(n?.align);let s=0,c=0;const l=[];for(const r of t){const t=r.items.map(e=>e.label),u=Li({...e,categories:t,legendLayout:{...n,maxWidth:Math.max(a,i-h-8),align:"start"}}),d=r.label?h:0,g=r.label?Ti(r.label,0,0,o):0,p=d>0?d+8:0,f=p+u.width,y=Math.max(u.height,g);l.push({group:r,x:s,y:0,itemOffsetX:p,itemOffsetY:0,width:f,height:y,items:u.items}),s+=f+12,c=Math.max(c,y)}const d=l.length>0?s-12:0,p=d>i?0:"center"===r?Math.max(0,(i-d)/2):"end"===r?Math.max(0,i-d):0;return{groups:l.map(e=>({...e,x:e.x+p})),width:d,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Pe(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),l);let f=0;return{groups:t.map((e,t)=>{const i=e.items.map(e=>Ti(e.label,a,c,o)),r=Math.max(0,...i,e.label?Ti(e.label,0,0,o):0);return f=Math.max(f,r),{group:e,x:0,y:p[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:r,height:e.items.length*l,items:e.items.map((e,t)=>({category:e.label,width:i[t],x:0,y:t*l}))}}),width:f,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function Ci(e){const t="top"===e.position||"bottom"===e.position,o=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??o,200),height:e.gradient.label?34:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?124:108,swatchSize:14}}function zi(e,t){if(!t||!e||0===e.length)return[];const o="function"==typeof t?t:e=>e[t],i=new Set;for(const t of e){const e=o(t);null!=e&&i.add(e+"")}return Array.from(i)}import{jsx as Fi,jsxs as Bi}from"react/jsx-runtime";var Oi=16;function Ei(e,t){return e.color||t.colors.annotation||t.colors.text}function Di(e,t,o){const i=e.labelBackground,r=t.colors.background,s=r&&"transparent"!==r?r:t.colors.surface||r;return void 0===i?"none"===o?"none":{type:"halo",fill:s}:!1===i||"none"===i?"none":!0===i||"halo"===i?{type:"halo",fill:s}:"box"===i?{type:"box",fill:s}:{fill:s,...i}}function ji(e,t,o){return null!=e.x&&t.x?t.x(e.x):o&&null!=e[o]&&t.x?t.x(e[o]):"number"==typeof e.x?e.x:null}function Ni(e,t,o){return null!=e.y&&t.y?t.y(e.y):o&&null!=e[o]&&t.y?t.y(e[o]):"number"==typeof e.y?e.y:null}function Wi(e){const{annotations:t}=e;if(!t||0===t.length)return null;const o=ot(t),i=e.autoPlaceAnnotations?ct({annotations:o,context:{scales:{x:e.scales.x,y:e.scales.y,time:e.scales.x,value:e.scales.y,o:e.scales.o,geoProjection:e.scales.geoProjection},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,frameType:e.projection?"ordinal":"xy",projection:"horizontal"===e.projection?"horizontal":"vertical"},..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):o,r=[];for(let t=0;i.length>t;t++){const o=Ii(i[t],t,e);o&&r.push({node:o,annotation:i[t]})}const s=de(r);return s.length>0?Fi("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:s}):null}function Ii(e,t,o){const{scales:i,layout:r,theme:s,xAccessor:n,yAccessor:a}=o;switch(e.type){case"y-threshold":{const n=e.value;if(null==n)return null;const a=Ei(e,s),c=e.label,l=e.labelPosition||"right",u=e.strokeDasharray||"6,4",h=e.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:Bi("g",{opacity:e.opacity,children:[Fi("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:h,strokeDasharray:u}),c&&Fi(ie,{x:o+4,y:Oi,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Di(e,s,"halo")})]},"ann-ythresh-"+t)}const d=i.y?i.y(n):i.r?i.r(n):null;return null==d?null:Bi("g",{children:[Fi("line",{x1:0,y1:d,x2:r.width,y2:d,stroke:a,strokeWidth:h,strokeDasharray:u}),c&&Fi(ie,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:20>d?Math.min(r.height-4,d+Oi):d-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Di(e,s,"halo")})]},"ann-ythresh-"+t)}case"x-threshold":{const o=e.value;if(null==o||!i.x)return null;const n=i.x(o);if(null==n)return null;const a=Ei(e,s),c=e.label,l=e.labelPosition||"top";return Bi("g",{opacity:e.opacity,children:[Fi("line",{x1:n,y1:0,x2:n,y2:r.height,stroke:a,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),c&&Fi(ie,{x:n>.6*r.width?n-4:n+4,y:"bottom"===l?r.height-4:"center"===l?r.height/2:Oi,textAnchor:n>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Di(e,s,"halo")})]},"ann-xthresh-"+t)}case"band":{const o=i.y?.domain?.(),n=e.y0??o?.[0],a=e.y1??o?.[1],c=null!=n&&i.y?i.y(n):null,l=null!=a&&i.y?i.y(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),h=Math.abs(l-c),d=st(e.fill||Ei(e,s),"ssr-band-"+t),g=e.fillOpacity??.1;return Bi("g",{opacity:e.opacity,children:[d.def&&Fi("defs",{children:d.def}),Fi("rect",{x:0,y:u,width:r.width,height:h,fill:d.fill,fillOpacity:g}),e.label&&Fi(ie,{x:r.width-4,y:Math.max(u,0)+Oi,textAnchor:"end",fontSize:s.typography.tickSize,fill:e.color||Ei(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Di(e,s,"halo")})]},"ann-band-"+t)}case"x-band":{const o=i.x?.domain?.(),n=e.x0??o?.[0],a=e.x1??o?.[1],c=null!=n&&i.x?i.x(n):null,l=null!=a&&i.x?i.x(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),h=Math.abs(l-c),d=st(e.fill||Ei(e,s),"ssr-xband-"+t),g=e.fillOpacity??.1;return Bi("g",{opacity:e.opacity,children:[d.def&&Fi("defs",{children:d.def}),Fi("rect",{x:u,y:0,width:h,height:r.height,fill:d.fill,fillOpacity:g}),e.label&&Fi(ie,{x:u+4,y:Oi,textAnchor:"start",fontSize:s.typography.tickSize,fill:e.color||s.colors.primary||Ei(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Di(e,s,"halo")})]},"ann-xband-"+t)}case"category-highlight":{if(null==e.category||!i.o)return null;const n=i.o(e.category+"");if(null==n)return null;const a=i.o.bandwidth?i.o.bandwidth():40,c=Ei(e,s),l=e.opacity??.1,u=e.label;return Bi("g","horizontal"===o.projection?{children:[Fi("rect",{x:0,y:n,width:r.width,height:a,fill:c,opacity:l}),u&&Fi(ie,{x:12,y:n+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Di(e,s,"none")})]}:{children:[Fi("rect",{x:n,y:0,width:a,height:r.height,fill:c,opacity:l}),u&&Fi(ie,{x:n+a/2,y:Oi,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Di(e,s,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:r}=function(e,t,o,i){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){const o=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:ji(e,t,o),y:Ni(e,t,i)}}(e,i,n,a);if(null==o||null==r)return null;const c="text"===e.type,l=e.dx??(c?0:30),u=e.dy??(c?0:-30),h=e.color||s.colors.text;if(!c){const i="callout"===e.type?"callout-circle":e.type,s="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return Fi(ue,{noteData:{x:o,y:r,dx:l,dy:u,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:i,...s?{subject:s}:{},connector:e.connector||{end:"arrow"},color:h,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return Fi("g",{children:Fi("text",{x:o+l,y:r+u,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||s.typography.labelSize,fill:h,fontFamily:s.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}import*as $i from"react";import{jsx as Gi,jsxs as Yi}from"react/jsx-runtime";function Hi(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function Vi(e){const t=e._idPrefix||e.chartId;if(t){const e=(t+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:"c"+e}const o=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`;let i=0;for(let e=0;o.length>e;e++)i=31*i+o.charCodeAt(e)|0;return"c"+(i>>>0).toString(36)}function Xi(e,t,o){const i=e.showLegend&&!e.__legendIncludesAutomatic?function(e,t,o){if(0===e.length)return;const i=_i(e,t,o);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:i(e.label)})}]}}(t,e.colorScheme,o):void 0;return pe(i,e.legend)}var qi={right:110,left:110,top:50,bottom:80};function Qi(e,t){if(e.__autoLegendMargin&&!Ki(e,t))return qi[t]}function Ki(e,t){const o=e.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[t])}function Zi(e,t){const{props:o,categories:i,theme:r,size:s,hasTitle:n}=t,a=o.legendPosition||"right",c={theme:r,position:a,size:s,hasTitle:n,legendLayout:o.legendLayout,minimumMargin:Qi(o,a),preserveExplicitMargin:Ki(o,a)};if(null!=o.legend){const t=Xi(o,i,r);(Me(t)||_e(t))&&function(e,t){if(t.preserveExplicitMargin)return;const o=t.position||"right",i={theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout},r=Me(t.legend)?function(e){const{width:t,height:o,swatchSize:i}=Ri(e);return{width:t,height:o,swatchSize:i}}({...i,legendGroups:t.legend.legendGroups}):_e(t.legend)?Ci({...i,gradient:t.legend.gradient}):null;if(!r)return;const s=t.minimumMargin??r.width+14,n=t.minimumMargin??(t.hasTitle?32:8)+r.height+4,a=t.minimumMargin??38+r.height+4;"right"===o?e.right=Math.max(e.right,s):"left"===o?e.left=Math.max(e.left,s):"top"===o?e.top=Math.max(e.top,n):e.bottom=Math.max(e.bottom,a)}(e,{...c,legend:t})}else o.showLegend&&i.length>0&&function(e,t){if(0===t.categories.length)return;if(t.preserveExplicitMargin)return;const o=t.position||"right",i=function(e){const{width:t,height:o,swatchSize:i}=Li(e);return{width:t,height:o,swatchSize:i}}({categories:t.categories,colorScheme:t.colorScheme,theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout}),r=t.minimumMargin??i.width+14,s=t.minimumMargin??(t.hasTitle?32:8)+i.height+4,n=t.minimumMargin??38+i.height+4;"right"===o?e.right=Math.max(e.right,r):"left"===o?e.left=Math.max(e.left,r):"top"===o?e.top=Math.max(e.top,s):e.bottom=Math.max(e.bottom,n)}(e,{...c,categories:i,colorScheme:o.colorScheme});return a}function Ui(e){const{props:t,categories:o,theme:i,size:r,margin:s,hasTitle:n}=e,a=t.legendPosition||"right",c={theme:i,position:a,size:r,margin:s,hasTitle:n,legendLayout:t.legendLayout,idPrefix:t._idPrefix,reservedWidth:t.__autoLegendMargin?100:void 0};if(null!=t.legend){const e=Xi(t,o,i);if($i.isValidElement(e))return e;const r=function(e,t){const o={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth};return Me(e)?function(e){if(0===(t=e.legendGroups,t.flatMap(e=>e.items.map((t,o)=>({group:e,item:t,itemIndex:o,label:t.label})))).length)return null;var t;const o=Ri(e),i="top"===e.position||"bottom"===e.position,r=e.theme.colors.grid||e.theme.colors.textSecondary;let s,n;if("left"===e.position?(s=Math.max(4,e.margin.left-(e.reservedWidth??100)-10),n=e.margin.top):"top"===e.position?(s=e.margin.left,n=e.hasTitle?32:8):"bottom"===e.position?(s=e.margin.left,n=e.totalHeight-e.margin.bottom+38):(s=e.totalWidth-e.margin.right+10,n=e.margin.top),!i){const t=Pe(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(o.swatchSize,e.legendLayout?.rowHeight??ki)),i=e.legendGroups.flatMap((i,r)=>{const s=t[r],n=i.type??"fill",a=[Si("line",{x1:0,y1:s.lineY,x2:e.reservedWidth??100,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+r)];return i.label&&null!=s.labelY&&a.push(Si("text",{y:s.labelY,fontSize:Pi(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.label},"legend-group-label-"+r)),a.push(Si("g",{transform:`translate(0,${s.itemsY})`,children:i.items.map((t,s)=>{const a=i.styleFn(t,s),c="function"==typeof n?n(t):"line"===n?Si("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:a}):Si("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:a});return wi("g",{transform:`translate(0,${s*Math.max(o.swatchSize,e.legendLayout?.rowHeight??ki)})`,children:[c,Si("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Pi(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${r}-${s}`)})},"legend-group-"+r)),a});return Si("g",{className:"semiotic-legend",transform:`translate(${s},${n})`,"data-orientation":"vertical",children:i})}const a=o.groups.flatMap((t,s)=>{const{group:n}=t,a=n.type??"fill",c=[];if(n.label&&c.push(Si("text",i?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:Pi(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label}:{x:t.x,y:t.y+Pi(e.theme),fontSize:Pi(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label},"legend-group-label-"+s)),c.push(...t.items.map((i,r)=>{const c=n.items[r],l=n.styleFn(c,r),u="function"==typeof a?a(c):"line"===a?Si("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):Si("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return wi("g",{transform:`translate(${t.x+t.itemOffsetX+i.x},${t.y+t.itemOffsetY+i.y})`,children:[u,Si("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Pi(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.category})]},`legend-${s}-${r}`)})),i&&o.groups.length-1>s){const e=t.x+t.width+6;c.push(Si("line",{x1:e,y1:0,x2:e,y2:o.height,stroke:r},"legend-group-separator-"+s))}return c});return Si("g",{className:"semiotic-legend",transform:`translate(${s},${n})`,"data-orientation":i?"horizontal":"vertical",children:a})}({...o,legendGroups:e.legendGroups}):_e(e)?function(e){const t=Ci(e),o="top"===e.position||"bottom"===e.position,i=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",r=e.gradient.format||(e=>Math.round(100*e)/100+"");let s,n;"left"===e.position?(s=Math.max(4,e.margin.left-100-10),n=e.margin.top):"top"===e.position?(s=e.margin.left,n=e.hasTitle?32:8):"bottom"===e.position?(s=e.margin.left,n=e.totalHeight-e.margin.bottom+38):(s=e.totalWidth-e.margin.right+10,n=e.margin.top);const a=Array.from({length:17},(t,i)=>{const r=i/16;return Si("stop",{offset:100*r+"%",stopColor:e.gradient.colorFn(o?e.gradient.domain[0]+r*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-r*(e.gradient.domain[1]-e.gradient.domain[0]))},i)});if(o){const o=12,c=e.gradient.label?0:void 0,l=e.gradient.label?8:0;return wi("g",{className:"semiotic-legend",transform:`translate(${s},${n})`,children:[Si("defs",{children:Si("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:a})}),e.gradient.label&&Si("text",{x:t.width/2,y:c,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),Si("rect",{x:0,y:l,width:t.width,height:o,fill:`url(#${i})`,rx:2}),Si("text",{x:0,y:l+o+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:r(e.gradient.domain[0])}),Si("text",{x:t.width,y:l+o+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:r(e.gradient.domain[1])})]})}const c=e.gradient.label?-6:void 0;return wi("g",{className:"semiotic-legend",transform:`translate(${s},${n+(e.gradient.label?12:0)})`,children:[Si("defs",{children:Si("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:a})}),e.gradient.label&&Si("text",{x:7,y:c,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),Si("rect",{x:0,y:0,width:14,height:100,fill:`url(#${i})`,rx:2}),Si("text",{x:19,y:10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:r(e.gradient.domain[1])}),Si("text",{x:19,y:100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:r(e.gradient.domain[0])})]})}({...o,gradient:e.gradient}):null}(e,c);return r||(Me(e)||_e(e)?null:e??null)}return t.showLegend&&0!==o.length?function(e){const{categories:t,colorScheme:o,theme:i,position:r="right",totalWidth:s,totalHeight:n,margin:a,hasTitle:c=!1}=e;if(!t||0===t.length)return null;const l=_i(t,o,i),u="top"===r||"bottom"===r,h=Li(e);let d,g;if("left"===r?(d=Math.max(4,a.left-(e.reservedWidth??100)-10),g=a.top):"top"===r?(d=a.left,g=c?32:8):"bottom"===r?(d=a.left,g=n-a.bottom+38):(d=s-a.right+10,g=a.top),u){const e=h.items.map((e,t)=>wi("g",{transform:`translate(${e.x},${e.y})`,children:[Si("rect",{width:h.swatchSize,height:h.swatchSize,fill:l(e.category),rx:h.swatchRadius}),Si("text",{x:h.labelOffset,y:h.swatchSize/2,dominantBaseline:"central",fontSize:Pi(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return Si("g",{className:"semiotic-legend",transform:`translate(${d},${g})`,children:e})}const p=Pe([{hasLabel:!1,itemCount:t.length}],Math.max(h.swatchSize,e.legendLayout?.rowHeight??ki))[0],f=h.items.map((e,t)=>wi("g",{transform:`translate(${e.x},${e.y+p.itemsY})`,children:[Si("rect",{width:h.swatchSize,height:h.swatchSize,fill:l(e.category),rx:h.swatchRadius}),Si("text",{x:h.labelOffset,y:h.swatchSize/2,dominantBaseline:"central",fontSize:Pi(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return wi("g",{className:"semiotic-legend",transform:`translate(${d},${g})`,children:[Si("line",{x1:0,y1:p.lineY,x2:e.reservedWidth??100,y2:p.lineY,stroke:"gray"}),f]})}({categories:o,colorScheme:t.colorScheme,theme:i,position:a,totalWidth:r[0],totalHeight:r[1],margin:s,hasTitle:n,legendLayout:t.legendLayout,reservedWidth:t.__autoLegendMargin?100:void 0,idPrefix:t._idPrefix}):null}function Ji(e){return Math.round(100*e)/100+""}function er(e,t){const o=ro(t.theme),i=t.background??o.background,r=t.idPrefix?t.idPrefix+"-":"",s="string"==typeof t.title?t.title:void 0,n=s?r+"semiotic-title":void 0,a=t.description?r+"semiotic-desc":void 0,c=[n,a].filter(Boolean).join(" ")||void 0;return Yi("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":c,style:{fontFamily:o.fontFamily},children:[s&&Gi("title",{id:n,children:s}),t.description&&Gi("desc",{id:a,children:t.description}),t.defs&&Gi("defs",{children:t.defs}),i&&"transparent"!==i&&Gi("rect",{x:0,y:0,width:t.width,height:t.height,fill:i}),Gi("g",{id:r+"data-area",transform:t.innerTransform,children:e}),s&&Gi("text",{id:r+"chart-title",x:t.width/2,y:he,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:s}),t.legend&&Gi("g",{id:r+"legend",children:t.legend}),t.outerElements]})}import{Fragment as tr,jsx as or,jsxs as ir}from"react/jsx-runtime";function rr(e,t){const o=io(e.theme),i=e.size||[500,300],r=Ee({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=we(e.title),n=be(e.data),a=e.showLegend?zi(n,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[];Zi(r,{props:e,categories:a,theme:o,size:i,hasTitle:s});const c=i[0]-r.left-r.right,l=i[1]-r.top-r.bottom,u="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),h=e.colorScheme||o.colors.categorical,d={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:u?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:u?void 0:e.xAccessor,yAccessor:u?void 0:e.yAccessor,timeAccessor:u?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor,categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,axisExtent:e.axisExtent,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:!0===e.gradientFill?{topOpacity:.8,bottomOpacity:.05}:!1===e.gradientFill?void 0:e.gradientFill,lineGradient:e.lineGradient,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:h,themeCategorical:o.colors.categorical,themeSemantic:Pt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},g=new P(d);if(e.data&&g.ingest({inserts:n,bounded:!0}),g.computeScene({width:c,height:l}),!g.scales||0===g.scene.length)return t&&(t.evidence=bi({frameType:"xy",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:g.scales?[]:["NO_SCALES"]})),vi.renderToStaticMarkup(er(null,{width:i[0],height:i[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const p=e._idPrefix,f=q({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>Je(e,t,p)});t&&(t.evidence=bi({frameType:"xy",width:i[0],height:i[1],marks:f.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:mi(g.scales.x?.domain?.()),yDomain:mi(g.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0}));const y=e.showGrid?function(e,t,o,i,r){const{grid:s}=ro(o),n=i?i+"-":"",a="exact"===r?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),c="exact"===r?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),l=U(e.x,a,r),u=U(e.y,c,r);return Yi("g",{id:n+"grid",className:"semiotic-grid",opacity:.8,children:[l.map((o,i)=>{const r=e.x(o);return Gi("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},"gx-"+i)}),u.map((o,i)=>{const r=e.y(o);return Gi("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:s,strokeWidth:.5},"gy-"+i)})]})}(g.scales,{width:c,height:l},o,p,e.axisExtent):null,m=f.map(e=>e.element),b=Vi(e)+"-plot-clip",x=!1!==e.showAxes?function(e,t,o,i,r){const s=ro(i),n="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),a="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),c=U(e.x,n,o.axisExtent).map(t=>({pixel:e.x(t),label:(o.xFormat||o.tickFormatTime||Ji)(t)})),l=U(e.y,a,o.axisExtent).map(t=>({pixel:e.y(t),label:(o.yFormat||o.tickFormatValue||Ji)(t)}));return Yi("g",{id:(r?r+"-":"")+"axes",className:"stream-axes",children:[Gi("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),c.map((e,o)=>Yi("g",{transform:`translate(${e.pixel},${t.height})`,children:[Gi("line",{y2:5,stroke:s.border,strokeWidth:1}),Gi("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"xtick-"+o)),o.xLabel&&Gi("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:o.xLabel}),Gi("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),l.map((e,t)=>Yi("g",{transform:`translate(0,${e.pixel})`,children:[Gi("line",{x2:-5,stroke:s.border,strokeWidth:1}),Gi("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"ytick-"+t)),o.yLabel&&Gi("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:o.yLabel})]})}(g.scales,{width:c,height:l},e,o,p):null,v=e.annotations?Wi({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:g.scales.x,y:g.scales.y},layout:{width:c,height:l},theme:o,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:p}):null,A=e.svgPreRenderers&&g.scales?e.svgPreRenderers.map((e,t)=>{try{return or(xi.Fragment,{children:e(g.scene,g.scales,{width:c,height:l})},"pre-"+t)}catch{return null}}).filter(Boolean):null,S=Ui({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s});return vi.renderToStaticMarkup(er(ir(tr,{children:[e.backgroundGraphics,A,y,or("defs",{children:or("clipPath",{id:b,children:or("rect",{x:0,y:0,width:c,height:l})})}),or("g",{clipPath:`url(#${b})`,children:m}),x,v,e.foregroundGraphics,g.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,legend:S,idPrefix:e._idPrefix}))}import*as sr from"react-dom/server";import{scaleBand as nr,scaleLinear as ar}from"d3-scale";var cr=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,o){if(t&&"function"==typeof e.pieceStyle){const i=e.pieceStyle(t,o);return i&&!i.fill&&o?{...i,fill:this.getColorFromScheme(e,o)}:i}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&o?{fill:e.barColors[o]||"#007bff"}:{fill:o?this.getColorFromScheme(e,o):"#007bff"}}resolveSummaryStyle(e,t,o){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,o):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){const o=this.colorSchemeMap.get(t);if(o)return o;const i=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||ce,r=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,r),r}};function lr(e){const t=e.getSymbol;if(!t)return null;const o=e.config.symbolMap,i=new Map;let r=0;return e=>{const s=t(e)+"",n=o?.[s];if(n)return n;let a=i.get(s);return a||(a=nt[r%nt.length],r++,i.set(s,a)),a}}function ur(e,t,o,i,r,s,n){e.push(t?{type:"symbol",x:i,y:r,size:Math.PI*s*s,symbolType:t(o),style:n,datum:o}:{type:"point",x:i,y:r,r:s,style:n,datum:o})}function hr(e,t){const{columns:o,config:i,resolvePieceStyle:r}=e,s=[],n=Math.min(t.width,t.height)/2-4,a="donut"===i.chartType?i.innerRadius||60:0,c=-Math.PI/2+(i.startAngle||0)*Math.PI/180,l=null!=i.sweepAngle?i.sweepAngle*Math.PI/180:2*Math.PI,u=null!=i.sweepAngle&&360>i.sweepAngle,h=Object.values(o),d=h.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),g=u&&!d&&h.length>1&&(i.cornerRadius??0)>0;for(let e=0;h.length>e;e++){const t=h[e],o=t.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:t.pctStart,d=c+u*l,p=c+(u+("number"==typeof o?._pct?o._pct:t.pct))*l,f=r(t.pieceData[0],t.name),y=0===e,m=e===h.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:n,startAngle:d,endAngle:p,...i.cornerRadius&&{cornerRadius:i.cornerRadius},style:f,datum:o?._nonInteractive?null:t.pieceData,category:t.name};o?._roundedEnds?b.roundedEnds=o._roundedEnds:g&&(b.roundedEnds={start:y,end:m}),o?._gradientBand&&(b._gradientBand=o._gradientBand),s.push(b)}return s}import{quantile as dr}from"d3-array";function gr(e){const t=e.length,o=e[0],i=e[t-1];return{n:t,min:o,q1:dr(e,.25)??o,median:dr(e,.5)??(o+i)/2,q3:dr(e,.75)??i,max:i,mean:e.reduce((e,t)=>e+t,0)/t}}import{scaleLinear as pr}from"d3-scale";var fr={bar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getStack:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,u=[],h="vertical"===l,d="horizontal"===l,g=r.normalize,p=[];if(n){const e=new Set;for(const t of Object.values(i))for(const o of t.pieceData){const t=n(o);e.has(t)||(e.add(t),p.push(t))}}else p.push("_default");for(const e of Object.values(i)){const t=new Map;for(const o of e.pieceData){const e=n?n(o):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const i=t.get(e);i.total+=s(o),i.pieces.push(o)}let o=0;if(g)for(const e of t.values())o+=Math.abs(e.total);let i=0,r=0;for(const s of p){const l=t.get(s);if(!l)continue;let p=l.total;g&&o>0&&(p/=o);const f=a(l.pieces[0],n?s:e.name),y={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:e.name};if(h){const t=c(0>p?r:i+p),o=0>p?c(r+p)-c(r):c(i)-c(i+p);u.push(E(e.x,t,e.width,Math.abs(o),f,y,s)),0>p?r+=p:i+=p}else if(d){const t=c(0>p?r+p:i),o=0>p?c(r)-c(r+p):c(i+p)-c(i);u.push(E(t,e.x,Math.abs(o),e.width,f,y,s)),0>p?r+=p:i+=p}}}const f="vertical"===l,y=r.roundedTop&&r.roundedTop>0?Math.max(0,r.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;const t=e.datum?.__aggregateValue??0;e.roundedEdge=f?0>t?"bottom":"top":0>t?"left":"right",r.gradientFill&&(e.fillGradient=r.gradientFill)}if(y>0){const e=new Map;for(const t of u){if("rect"!==t.type)continue;const o=t.datum?.category||"";e.has(o)||e.set(o,[]),e.get(o).push(t)}for(const t of e.values()){if(0===t.length)continue;const e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),o=t.filter(e=>0>(e.datum?.__aggregateValue??0));e.length>0&&(e.reduce(f?(e,t)=>t.y>e.y?e:t:(e,t)=>e.x+e.w>t.x+t.w?e:t).roundedTop=y),o.length>0&&(o.reduce(f?(e,t)=>e.y+e.h>t.y+t.h?e:t:(e,t)=>t.x>e.x?e:t).roundedTop=y)}}return u},clusterbar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getGroup:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,u=[],h="vertical"===l,d=[],g=new Set;for(const e of Object.values(i))for(const t of e.pieceData){const e=n?n(t):"_default";g.has(e)||(g.add(e),d.push(e))}const p=d.length||1;for(const e of Object.values(i)){const t=e.width/p,o=.2*t,i=t-o,r=new Map;for(const t of e.pieceData){const e=n?n(t):"_default";r.has(e)||r.set(e,[]),r.get(e).push(t)}for(let n=0;d.length>n;n++){const l=r.get(d[n])||[];for(const r of l){const l=s(r),g=a(r,d[n]);if(h){const s=e.x+n*t+o/2,a=c(0),h=c(l);u.push(E(s,Math.min(a,h),i,Math.abs(a-h),g,r,d[n]))}else{const s=e.x+n*t+o/2,a=c(0),h=c(l);u.push(E(Math.min(a,h),s,Math.abs(h-a),i,g,r,d[n]))}}}}const f=r.roundedTop&&r.roundedTop>0?Math.max(0,r.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=s(e.datum);f>0&&(e.roundedTop=f),e.roundedEdge=h?0>t?"bottom":"top":0>t?"left":"right",r.gradientFill&&(e.fillGradient=r.gradientFill)}return u},point:function(e,t){const{scales:o,columns:i,getR:r,multiScales:s,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,h="radial"===c,d=s.length>0,g=lr(e),p=2*Math.PI,f=-Math.PI/2;for(const e of Object.values(i))for(const t of e.pieceData){const o=t.__rIndex??0,i=t.__rValue??r(t),c=d&&s[o]||a,y=n(t,e.name),m=y.r||5;let b,x;if(h){const t=f+(e.pctStart+e.pct/2)*p,o=c(i);b=Math.cos(t)*o,x=Math.sin(t)*o}else u?(b=e.middle,x=c(i)):(b=c(i),x=e.middle);ur(l,g,t,b,x,m,y)}return l},swarm:function(e,t){const{scales:o,columns:i,getR:r,resolvePieceStyle:s}=e,{r:n,projection:a}=o,c=[],l="vertical"===a,u=lr(e);for(const e of Object.values(i)){const t=e.width/2;for(let o=0;e.pieceData.length>o;o++){const i=e.pieceData[o],a=r(i),h=s(i,e.name),d=h.r||4,g=(7919*o%100/100-.5)*t*.8;ur(c,u,i,l?e.middle+g:n(a),l?n(a):e.middle+g,d,h)}}return c},pie:hr,donut:hr,boxplot:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,h=!1!==r.showOutliers;for(const t of Object.values(i)){const o=t.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===o.length)continue;const i=o[0],r=o[o.length-1],c=dr(o,.25)??i,d=dr(o,.5)??(i+r)/2,g=dr(o,.75)??r,p=g-c,f=c-1.5*p,y=g+1.5*p,m=o.find(e=>e>=f)??i,b=[...o].reverse().find(e=>y>=e)??r,x=n(t.pieceData[0],t.name),v=[];if(h)for(const e of t.pieceData){const o=s(e);if(f>o||o>y){const i=u?t.middle:a(o),r=u?a(o):t.middle;v.push({px:i,py:r,value:o,datum:e})}}if(l.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:a(m),q1Pos:a(c),medianPos:a(d),q3Pos:a(g),maxPos:a(b),stats:{n:o.length,min:m,q1:c,median:d,q3:g,max:b,mean:o.reduce((e,t)=>e+t,0)/o.length},style:x,datum:t.pieceData,category:t.name,outliers:v}),h)for(const t of v)l.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:x.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6},datum:t.datum})}return l},violin:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,h=r.bins||20,d=!1!==r.showIQR;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],r=(i-o)/h||1,c=Array(h).fill(0);for(const e of t)c[Math.min(Math.floor((e-o)/r),h-1)]++;const g=xt(c,1),p=e.width/2*.9;let f;if(u){f=`M ${e.middle} ${a(o)}`;for(let t=0;h>t;t++){const i=a(o+(t+.5)*r);f+=` L ${e.middle+c[t]/g*p} ${i}`}f+=` L ${e.middle} ${a(i)}`;for(let t=h-1;t>=0;t--){const i=a(o+(t+.5)*r);f+=` L ${e.middle-c[t]/g*p} ${i}`}f+=" Z"}else{f=`M ${a(o)} ${e.middle}`;for(let t=0;h>t;t++)f+=` L ${a(o+(t+.5)*r)} ${e.middle-c[t]/g*p}`;f+=` L ${a(i)} ${e.middle}`;for(let t=h-1;t>=0;t--)f+=` L ${a(o+(t+.5)*r)} ${e.middle+c[t]/g*p}`;f+=" Z"}const y=n(e.pieceData[0],e.name);let m;if(d&&t.length>=4){const r=dr(t,.25)??o,s=dr(t,.5)??(o+i)/2,n=dr(t,.75)??i;m={q1Pos:a(r),medianPos:a(s),q3Pos:a(n),centerPos:e.middle,isVertical:u}}const b=u?{x:e.x,y:Math.min(a(i),a(o)),width:e.width,height:Math.abs(a(i)-a(o))}:{x:Math.min(a(o),a(i)),y:e.x,width:Math.abs(a(i)-a(o)),height:e.width};l.push({type:"violin",pathString:f,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:gr(t),style:y,datum:e.pieceData,category:e.name})}return l},histogram:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a}=o,c=[],l=r.bins||25,u=r.normalize,h=a.domain?.(),d=h?+h[0]:void 0,g=h?+h[1]:void 0;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;const[o,i]=At(t),r=null!=d&&isFinite(d)?d:o,h=null!=g&&isFinite(g)?g:i,p=(h-r)/l||1,f=Array(l).fill(0);for(const e of t)r>e||e>h||f[Math.min(Math.floor((e-r)/p),l-1)]++;const y=t.length,m=xt(f,1),b=n(e.pieceData[0],e.name);for(let t=0;l>t;t++){if(0===f[t])continue;const o=(u?f[t]/y:f[t]/m)*e.width*.9,i=a(r+t*p),s=a(r+(t+1)*p);c.push(E(Math.min(i,s),e.x+e.width-o,Math.abs(s-i),o,b,{bin:t,count:f[t],range:[r+t*p,r+(t+1)*p],category:e.name},e.name))}}return c},ridgeline:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u=r.bins||20,h="horizontal"===c,d=r.amplitude||1.5;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],r=(i-o)/u||1,c=Array(u).fill(0);for(const e of t)o>e||e>i||c[Math.min(Math.floor((e-o)/r),u-1)]++;const g=xt(c,1),p=n(e.pieceData[0],e.name),f=e.width*d;let y;if(h){const t=e.x+e.width;y=`M ${a(o)} ${t}`;for(let e=0;u>e;e++)y+=` L ${a(o+(e+.5)*r)} ${t-c[e]/g*f}`;y+=` L ${a(i)} ${t} Z`}else{const t=e.x;y=`M ${t} ${a(o)}`;for(let e=0;u>e;e++){const i=a(o+(e+.5)*r);y+=` L ${t+c[e]/g*f} ${i}`}y+=` L ${t} ${a(i)} Z`}const m=h?{x:Math.min(a(o),a(i)),y:e.x,width:Math.abs(a(i)-a(o)),height:e.width}:{x:e.x,y:Math.min(a(i),a(o)),width:e.width,height:Math.abs(a(i)-a(o))};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:gr(t),style:{...p,fillOpacity:p.fillOpacity??.5},datum:e.pieceData,category:e.name})}return l},timeline:function(e,t){const{scales:o,columns:i,getRawRange:r,resolvePieceStyle:s}=e,{r:n,projection:a}=o,c=[],l="horizontal"===a;for(const e of Object.values(i))for(const t of e.pieceData){const o=r(t);if(!o)continue;const[i,a]=o,u=s(t,e.name);if(l){const o=n(Math.min(i,a)),r=n(Math.max(i,a));c.push(E(o,e.x,r-o,e.width,u,t,e.name))}else{const o=n(Math.max(i,a)),r=n(Math.min(i,a));c.push(E(e.x,o,e.width,r-o,u,t,e.name))}}return c},funnel:function(e,t){const{columns:o,getR:i,getStack:r,resolvePieceStyle:s}=e,n=[],a=t.width/2,c=!1!==e.config.showLabels,l=e.scales.o.domain().map(e=>o[e]).filter(Boolean);if(0===l.length)return n;const u=[],h=new Set;for(const e of l)for(const t of e.pieceData){const e=r?r(t):"_default";h.has(e)||(h.add(e),u.push(e))}const d=u.length>1&&"_default"!==u[0],g=[];let p=0;for(const e of l){const t=new Map;let o=0;for(const s of e.pieceData){const e=r?r(s):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(s);n.total+=a,n.pieces.push(s),o+=a}g.push({col:e,groups:t,stepTotal:o}),d||o>p&&(p=o)}if(d)for(const e of g){let t=0,o=0;for(let i=0;u.length>i;i++){const r=e.groups.get(u[i]);r&&(i%2==0?t+=r.total:o+=r.total)}const i=Math.max(t,o);i>p&&(p=i)}if(0===p)return n;const f=new Map;for(const e of u){const t=g[0].groups.get(e);f.set(e,t?.total??0)}const y=g[0].stepTotal,m=d?.95*a:.9*t.width,b=pr().domain([0,p]).range([0,m]),x=e.config.connectorOpacity??.3;let v=new Map;for(let t=0;g.length>t;t++){const o=g[t],i=o.col,r=0===t,l=i.width,h=.55*l,p=i.x+(l-h)/2,m=new Map;if(d){let e=0;for(const t of u){const i=o.groups.get(t);i&&(e+=b(i.total))}let t=a,l=a;for(let d=0;u.length>d;d++){const g=u[d],y=o.groups.get(g);if(!y)continue;const x=b(y.total),v=d%2==0,A=v?t:l-x;v?t+=x:l-=x;const S=s(y.pieces[0],g),w=f.get(g)??y.total,k={...y.pieces[0],__funnelValue:y.total,__funnelPercent:w>0?y.total/w*100:0,__funnelStep:i.name,__funnelIsFirstStep:r,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:g};c&&(0===d&&(k.__funnelStepLabel=i.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e),k.__funnelValueLabelX=A+x/2,k.__funnelValueLabelY=p,k.__funnelBarW=x),n.push(E(A,p,x,h,S,k,g)),m.set(g,{x:A,y:p,w:x,h:h})}}else{const e=o.stepTotal,t=b(e),l=a-t/2,d=u[0],g="_default"!==d,f=o.groups.get(d)?.pieces[0]??i.pieceData[0],x=g?d:i.name,v=s(f,x),A=y>0?e/y*100:0,S={...f,__funnelValue:e,__funnelPercent:A,__funnelStep:i.name,__funnelIsFirstStep:r,category:g?d:i.name};c&&(S.__funnelStepLabel=i.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=p,S.__funnelRowWidth=t,S.__funnelValueLabelX=a,S.__funnelValueLabelY=p,S.__funnelBarW=t),n.push(E(l,p,t,h,v,S,x)),m.set(d,{x:l,y:p,w:t,h:h})}if(t>0&&v.size>0){const t=d?u:[u[0]];for(const r of t){const t=v.get(r),a=m.get(r);if(!t||!a)continue;const c=(()=>{const e=o.groups.get(r);return s(e?e.pieces[0]:i.pieceData[0],"_default"===r?i.name:r)})(),l={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||e.config.themeSemantic?.secondary||"#999",opacity:x},datum:o.groups.get(r)?.pieces[0]??i.pieceData[0],category:"_default"===r?i.name:r};n.push(l)}}v=m}return n},"bar-funnel":function(e,t){const{columns:o,getR:i,getStack:r,resolvePieceStyle:s,scales:n}=e,a=[],c=n.o.domain().map(e=>o[e]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const e of c)for(const t of e.pieceData){const e=r?r(t):"_default";u.has(e)||(u.add(e),l.push(e))}const h=l.length>1&&"_default"!==l[0],d=[];for(const e of c){const t=new Map;let o=0;for(const s of e.pieceData){const e=r?r(s):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(s);n.total+=a,n.pieces.push(s),o+=a}d.push({col:e,groups:t,stepTotal:o})}const g=new Map;for(const e of l){const t=d[0]?.groups.get(e);g.set(e,t?.total??0)}const p=n.r,f=h?l.length:1,y=h?.15:0;for(let e=0;d.length>e;e++){const t=d[e],o=t.col,i=0===e,r=e>0?d[e-1]:null,n=o.width/f,c=n*y,u=n-c;for(let e=0;l.length>e;e++){const d=l[e],f=t.groups.get(d);if(!f)continue;const y=f.total,m=g.get(d)??y,b=m>0?y/m*100:0,x=r?.groups.get(d),v=i?0:Math.max(0,(x?.total??y)-y),A=o.x+e*n+c/2,S=p(y),w=p(0)-S,k=s(f.pieces[0],h?d:o.name),_={...f.pieces[0],__barFunnelValue:y,__barFunnelPercent:b,__barFunnelIsFirstStep:i,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===d?void 0:d,category:h?d:o.name,__barFunnelLabelX:A+u/2,__barFunnelLabelY:p(y+v)};if(a.push(E(A,S,u,w,k,_,h?d:o.name)),v>0){const e=p(y+v),t=S-e,i={...k},r={...f.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===d?void 0:d,category:h?d:o.name};a.push(E(A,e,u,t,i,r,h?d:o.name))}}}return a},swimlane:function(e,t){const{scales:o,columns:i,getR:r,getStack:s,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],u="horizontal"===c,h=e.config.gradientFill,d=u?"left":"bottom",g=e.config.trackFill;if(g){const e="string"==typeof g?g:g.color,t="string"==typeof g?1:g.opacity??1,[o,r]=a.range(),s=Math.min(o,r),n=Math.abs(r-o);for(const o of Object.values(i)){const i={fill:e,opacity:t},r=u?E(s,o.x,n,o.width,i,null,"__track__"):E(o.x,s,o.width,n,i,null,"__track__");l.push(r)}}const p=e.config.roundedTop&&e.config.roundedTop>0?Math.max(0,e.config.roundedTop):0;for(const e of Object.values(i)){let t=0;const o=l.length;for(const o of e.pieceData){const i=Math.abs(r(o));if(0===i)continue;const c=s?s(o):e.name,g=n(o,c);let p;if(u){const r=a(t),s=a(t+i);p=E(r,e.x,s-r,e.width,g,o,c)}else{const r=a(t+i),s=a(t);p=E(e.x,r,e.width,s-r,g,o,c)}h&&(p.fillGradient=h,p.roundedEdge=d),l.push(p),t+=i}if(p>0&&l.length>o){const e=l.slice(o),t=e[0],i=e[e.length-1];1===e.length?t.cornerRadii={tl:p,tr:p,br:p,bl:p}:u?(t.cornerRadii={tl:p,bl:p},i.cornerRadii={tr:p,br:p}):(t.cornerRadii={bl:p,br:p},i.cornerRadii={tl:p,tr:p})}}return l}},yr=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],mr=["scene-style","data-paint","accessibility","evidence"],br=(e,t)=>({retainedData:e,invalidations:t}),xr=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],vr=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ar=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Sr=["scene-geometry","data-paint","accessibility","evidence"],wr=["scene-style","data-paint","accessibility","evidence"],kr=[],_r={chartType:br("rebuild",xr),runtimeMode:br("rebuild",xr),categoryAccessor:br("rebuild",xr),valueAccessor:br("rebuild",xr),oAccessor:br("rebuild",xr),rAccessor:br("rebuild",xr),stackBy:br("rebuild",xr),groupBy:br("rebuild",xr),timeAccessor:br("rebuild",xr),accessorRevision:br("rebuild",xr),colorAccessor:br("rebuild",wr),symbolAccessor:br("rebuild",Sr),connectorAccessor:br("rebuild",Sr),dataIdAccessor:br("rebuild",Sr),projection:br("preserve",vr),extentPadding:br("preserve",vr),axisExtent:br("preserve",vr),rExtent:br("preserve",vr),oExtent:br("preserve",vr),multiAxis:br("preserve",vr),normalize:br("preserve",vr),bins:br("preserve",vr),oSort:br("preserve",Ar),barPadding:br("preserve",Ar),roundedTop:br("preserve",Ar),baselinePadding:br("preserve",Ar),innerRadius:br("preserve",Ar),cornerRadius:br("preserve",Ar),startAngle:br("preserve",Ar),sweepAngle:br("preserve",Ar),trackFill:br("preserve",Ar),showOutliers:br("preserve",Ar),showIQR:br("preserve",Ar),amplitude:br("preserve",Ar),connectorOpacity:br("preserve",Ar),showLabels:br("preserve",Ar),dynamicColumnWidth:br("rebuild",Ar),customLayout:br("preserve",Ar),layoutConfig:br("preserve",Ar),layoutMargin:br("preserve",Ar),symbolMap:br("preserve",Sr),pieceStyle:br("preserve",wr),summaryStyle:br("preserve",wr),connectorStyle:br("preserve",wr),gradientFill:br("preserve",wr),colorScheme:br("preserve",wr),themeCategorical:br("preserve",wr),themeSemantic:br("preserve",wr),themeSequential:br("preserve",wr),themeDiverging:br("preserve",wr),barColors:br("preserve",wr),decay:br("preserve",wr),pulse:br("preserve",wr),staleness:br("preserve",wr),layoutSelection:br("preserve",wr),windowSize:br("preserve",kr),windowMode:br("preserve",kr),clock:br("preserve",kr),transition:br("preserve",kr),introAnimation:br("preserve",kr),onLayoutError:br("preserve",kr)},Mr=br("preserve",Ar),Pr=class{constructor(){this.tracker=new at}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},yr)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},mr):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const o=new Set;for(const i of e){const e=_r[i]??Mr;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as Tr}from"d3-quadtree";var Lr=class{constructor(e){this.rExtent=new te,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Pr,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new cr,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new oe(e.windowSize),this.getO=rt(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>it(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new te)):(this.getR=it(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=rt(e.stackBy),this.getGroup=rt(e.groupBy),this.getColor=rt(e.colorAccessor),this.getSymbol=rt(e.symbolAccessor),this.getConnector=rt(e.connectorAccessor),this.getDataId=rt(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new oe(e.windowSize))}syncPulseTimestampBuffer(){var e,t,o,i;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,o=this.timestampBuffer,i=this.currentTime(),e?null!=o&&o.capacity===t.capacity&&o.size===t.size?o:G(t,i):null)}currentTime(){return this.config.clock?.()??ze()}ingest(e){const t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),Y(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const o of e.inserts)X(this.buffer,o,this.timestampBuffer,t),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of e.inserts){const e=X(this.buffer,o,this.timestampBuffer,t);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){const t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;const o="function"==typeof t?t(e):e[t];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(e){const{config:t,buffer:o}=this,i=this.scales,r=this.multiScales,s=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const n=this.getBufferArray(),a=t.projection||"vertical",c=t.oExtent||this.resolveCategories(n),l=this.computeValueDomain(n,c),u="horizontal"===a,h="radial"===a,d=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===a?e.width:e.height):.1));let g,p;if(h){g=nr().domain(c).range([0,1]).padding(0);const o=Math.min(e.width,e.height)/2,i=t.innerRadius||0;p=ar().domain(l).range([i,o])}else u?(g=nr().domain(c).range([0,e.height]).padding(d),p=ar().domain(l).range([0,e.width])):(g=nr().domain(c).range([0,e.width]).padding(d),p=ar().domain(l).range([e.height,0]));this.scales={o:g,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&t.multiAxis?this.rAccessors.map((i,r)=>{const s=this.rExtents[r];s.dirty&&s.recalculate(o,i);let[n,a]=s.extent;n===1/0&&(n=0,a=1);const c=a-n,l=c>0?c*(t.extentPadding??.05):1;return n-=l,a+=l,n>0&&(n=0),u?ar().domain([n,a]).range([0,e.width]):ar().domain([n,a]).range([e.height,0])}):[];let f=n;this.rAccessors.length>1&&(f=n.flatMap(e=>this.rAccessors.map((t,o)=>({...e,__rIndex:o,__rValue:t(e),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(f,c,g,a,e),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(f,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=i,this.multiScales=r,this.columns=s):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,n),this.config.pulse&&this.applyPulse(this.scene,n),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){const t=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(t)?t[e]:t;return"string"==typeof o?o:"value"+e}resolveCategories(e){const t=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,i="auto"===t?void 0:t;let r=null;if(o){r=new Set;for(const t of e)r.add(this.getO(t))}const s=r?Array.from(this.categories).filter(e=>r.has(e)):Array.from(this.categories);if(o&&void 0===i){const e=Math.max(50,3*r.size);if(this.categories.size>e){let t=this.categories.size-e;for(const e of this.categories){if(0>=t)break;r.has(e)||(this.categories.delete(e),t--)}}return s}if(!1===i)return s;if("function"==typeof i)return s.sort(i);const n=new Map;for(const t of e){const e=this.getO(t);n.set(e,(n.get(e)||0)+Math.abs(this.getR(t)))}return s.sort("asc"===i?(e,t)=>(n.get(e)||0)-(n.get(t)||0):(e,t)=>(n.get(t)||0)-(n.get(e)||0))}computeValueDomain(e,t){return function(e){const{data:t,chartType:o,projection:i,normalize:r,rExtent:s,extentPadding:n=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:h,rawRExtent:d}=e,g=n;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let p=0,f=0;if("bar"===o&&h&&r)p=0,f=1;else if("bar"===o&&h){const e=new Map,o=new Map;for(const i of t){const t=l(i),r=u(i);0>r?o.set(t,(o.get(t)||0)+r):e.set(t,(e.get(t)||0)+r)}for(const t of e.values())t>f&&(f=t);for(const e of o.values())p>e&&(p=e)}else if("bar"===o){const e=new Map;for(const o of t){const t=l(o),i=u(o);e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>f&&(f=t),p>t&&(p=t)}else if("swimlane"===o){const e=new Map;for(const o of t){const t=l(o),i=Math.abs(u(o));e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>f&&(f=t)}else if("clusterbar"===o||"bar-funnel"===o)for(const e of t){const t=u(e);t>f&&(f=t),p>t&&(p=t)}else{const e=d[0],t=d[1];e!==1/0&&(p=e),t!==-1/0&&(f=t)}s&&(null!=s[0]&&(p=s[0]),null!=s[1]&&(f=s[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==s?.[0]&&null==s?.[1]&&(p>0&&(p=0),0>f&&(f=0)),"bar-funnel"!==o&&"exact"!==c){const e=f-p,t=e>0?e*g:1,i=y&&!a&&0===p,r=y&&!a&&0===f||"swimlane"===o;null!=s?.[0]||i||(p-=t),null!=s?.[1]||r||(f+=t)}return[p,f]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,o,i,r){return function(e){const{data:t,oExtent:o,oScale:i,projection:r,layout:s,dynamicColumnWidth:n,getO:a,getR:c}=e,l={},u=new Map;for(const e of t){const t=a(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let h=0;if("radial"===r)for(const e of t)h+=Math.abs(c(e));let d=null;if(n&&"radial"!==r){d=new Map;let e=0;for(const t of o){const o=u.get(t)||[];let i;i="string"==typeof n?o.reduce((e,t)=>e+(Number(t[n])||0),0):n(o),d.set(t,i),e+=i}const t=("horizontal"===r?s.height:s.width)-i.padding()*i.step()*o.length;if(e>0)for(const[o,i]of d)d.set(o,i/e*t)}let g=0,p=0;for(const e of o){const t=u.get(e)||[],o=t.reduce((e,t)=>e+Math.abs(c(t)),0),r=h>0?o/h:0;let s,n;d?(s=p,n=d.get(e)||i.bandwidth(),p+=n+i.padding()*i.step()):(s=i(e)??0,n=i.bandwidth()),l[e]={name:e,x:s,y:0,width:n,middle:s+n/2,padding:i.padding()*i.step(),pieceData:t,pct:r,pctStart:g},g+=r}return l}({data:e,oExtent:t,oScale:o,projection:i,layout:r,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(e,t);let i;try{i=this.config.customLayout(o)}catch(e){const t=null!==this.lastCustomLayoutResult,o=$("ordinal",e,t,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",e);try{this.config.onLayoutError?.(o)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return t?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=i.overlays??null,this.lastCustomLayoutResult=i,this.lastCustomLayoutFailure=null;const r=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const e of r)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(r,this.config.layoutSelection??null)}return ee({label:"ordinal customLayout",nodes:r,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),r}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),i=fr[this.config.chartType];let r=i?i(o,t):[];if(this.getConnector&&this.scales){const e=function(e,t){const{scales:o,config:i,getConnector:r,getO:s}=e;if(!r||!o)return[];const n=[],{projection:a}=o,c=new Map;for(const e of t){if("point"!==e.type&&"rect"!==e.type)continue;const t=e.datum;if(!t)continue;const o=r(t);if(!o)continue;let i,n;"point"===e.type?(i=e.x,n=e.y):(i=e.x+e.w/2,n=e.y+("vertical"===a?0:e.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:i,y:n,datum:t,category:s(t)})}const l=o.o.domain(),u=i.connectorStyle;for(const[t,o]of c)if(o.length>=2){o.sort((e,t)=>l.indexOf(e.category)-l.indexOf(t.category));for(let i=0;o.length-1>i;i++){const r=o[i],s=o[i+1],a="function"==typeof u?u(r.datum):u||{stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};n.push({type:"connector",x1:r.x,y1:r.y,x2:s.x,y2:s.y,style:a,datum:r.datum,group:t})}}return n}(o,r);r=[...e,...r]}return r}buildLayoutContext(e,t){const o=this.config,i=o.layoutMargin??{top:0,right:0,bottom:0,left:0},r=Ne(o.colorScheme,o.themeCategorical,ce),s=this.scales;return{data:e,scales:{o:s.o,r:s.r,projection:s.projection},dimensions:{width:t.width,height:t.height,margin:i,plot:"radial"===s.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:[...r]},resolveColor:ge(r,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(e,t){const o=this.config.decay;return o&&t>1?W(o,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const t=B(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const t=function(e,t){const o="function"==typeof t,i=o?null:t||"category",r=new Map;for(let s=0;e.length>s;s++){const n=e[s],a=o?t(n):n[i],c=r.get(a);c?c.push(s):r.set(a,[s])}return r}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){const e=function(e){let t=0,o=0;for(const i of e)"point"===i.type&&(t++,i.r>o&&(o=i.r));if(500>=t)return{quadtree:null,maxRadius:o};const i=Array(t);let r=0;for(const t of e)"point"===t.type&&(i[r++]=t);return{maxRadius:o,quadtree:Tr().x(e=>e.x).y(e=>e.y).addAll(i)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;const o=t.length;if(1>=o)return;const i=this.getDatumIndexMap(t);for(const t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type)continue;if(!t.datum)continue;const e=i.get(t.datum);if(null==e)continue;const r=this.computeDecayOpacity(e,o);t.style={...t.style,opacity:(t.style?.opacity??1)*r}}}applyPulse(e,t,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,o,i,r,s){const n=e.color??"rgba(255,255,255,0.6)",a=e.glowRadius??4;let c=!1;for(const l of t){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const t=l.category;if(!t)continue;let i=0;for(const n of r(t)??[]){const t=o.get(n);null!=t&&(i=Math.max(i,I(e,t,s)))}c=Z(l,i,n)||c;continue}if(null==l.datum)continue;const t=i.get(l.datum);if(null==t)continue;const u=o.get(t),h=null==u?0:I(e,u,s);c=Z(l,h,n,a)||c}return c}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),o)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&V(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const e=new Map,t=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let i;for(let r=0;this.scene.length>r;r++){const s=this.scene[r],n=this.getNodeKey(s,e);n&&("rect"===s.type?this.prevPositionMap.set(n,o?{x:s.x,y:t,w:s.w,h:0,opacity:s.style.opacity??1}:{x:t,y:s.y,w:0,h:s.h,opacity:s.style.opacity??1}):"point"===s.type?this.prevPositionMap.set(n,{x:s.x,y:s.y,r:0,opacity:0}):"wedge"===s.type&&(void 0===i&&(i=s.startAngle),this.prevPositionMap.set(n,{x:s.cx,y:s.cy,startAngle:i,endAngle:i,innerRadius:s.innerRadius,outerRadius:s.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){const o=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,i=t.get(o)||0;return t.set(o,i+1),`${o}:${i}`}return"rect"===e.type?`r:${e.group||""}:${e.datum?.category??""}`:"wedge"===e.type?"w:"+(e.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const e=new Map;for(let t=0;this.scene.length>t;t++){const o=this.scene[t],i=this.getNodeKey(o,e);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity}):"wedge"===o.type&&this.prevPositionMap.set(i,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const e=this.config.transition.duration??300;if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1;const o=new Set,i=new Map;for(let e=0;this.scene.length>e;e++){const r=this.scene[e],s=this.getNodeKey(r,i);if(!s)continue;r._transitionKey=s;const n=this.prevPositionMap.get(s);if("point"===r.type)n?(o.add(s),r._targetOpacity=r.style.opacity??1,(n.x!==r.x||n.y!==r.y||void 0!==n.r&&n.r!==r.r)&&(r._targetX=r.x,r._targetY=r.y,r._targetR=r.r,r.x=n.x,r.y=n.y,void 0!==n.r&&(r.r=n.r),t=!0)):(r._targetOpacity=r.style.opacity??1,r._targetR=r.r,r.r=0,r.style={...r.style,opacity:0},t=!0);else if("rect"===r.type)n?(o.add(s),r._targetOpacity=r.style.opacity??1,n.x===r.x&&n.y===r.y&&n.w===r.w&&n.h===r.h||(r._targetX=r.x,r._targetY=r.y,r._targetW=r.w,r._targetH=r.h,r.x=n.x,r.y=n.y,r.w=n.w??r.w,r.h=n.h??r.h,t=!0)):(r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},t=!0);else if("wedge"===r.type)if(n)o.add(s),r._targetOpacity=r.style.opacity??1,n.startAngle===r.startAngle&&n.endAngle===r.endAngle||(r._targetStartAngle=r.startAngle,r._targetEndAngle=r.endAngle,r.startAngle=n.startAngle,r.endAngle=n.endAngle,t=!0);else{r._targetOpacity=r.style.opacity??1,r._targetStartAngle=r.startAngle,r._targetEndAngle=r.endAngle;const e=r.startAngle;r.startAngle=e,r.endAngle=e,r.style={...r.style,opacity:0},this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:e,endAngle:e,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(const[e,i]of this.prevPositionMap)if(!o.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:i.x,y:i.y,r:i.r??3,style:{opacity:i.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:i.x,y:i.y,w:i.w??0,h:i.h??0,style:{opacity:i.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){const t=((i.startAngle??0)+(i.endAngle??0))/2,o={type:"wedge",cx:i.x,cy:i.y,innerRadius:i.innerRadius??0,outerRadius:i.outerRadius??100,startAngle:i.startAngle??0,endAngle:i.endAngle??0,style:{opacity:i.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(o)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;const t=ye(e,this.activeTransition),o=fe(t,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const e of this.scene){const t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=Te(i?i.opacity??1:0,e._targetOpacity,o)}const i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=Te(i.x,e._targetX,o),e.y=Te(i.y,e._targetY,o)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=Te(i.r,e._targetR,o))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=Te(i?i.opacity??1:0,e._targetOpacity,o)}if(void 0===e._targetX)continue;const i=this.prevPositionMap.get(t);if(!i)continue;e.x=Te(i.x,e._targetX,o),e.y=Te(i.y,e._targetY,o),void 0!==i.w&&(e.w=Te(i.w,e._targetW,o),e.h=Te(i.h,e._targetH,o))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style={...e.style,opacity:Te(i?i.opacity??1:0,e._targetOpacity,o)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){const i=this.prevPositionMap.get(t);i&&void 0!==i.startAngle&&(e.startAngle=Te(i.startAngle,e._targetStartAngle,o),e.endAngle=Te(i.endAngle,e._targetEndAngle,o))}}}if(t>=1){for(const e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const t=J(e),o=this.getDataId,i=e=>t.has(o(e));N(this.buffer,this.timestampBuffer,i);const r=this.buffer.remove(i);if(0===r.length)return this.updateResults.recordNoop("remove"),r;for(const e of r)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",r.length),r}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=J(e),i=this.getDataId,r=new Set;this.buffer.forEach((e,t)=>{o.has(i(e))&&r.add(t)});const s=this.buffer.update(e=>o.has(i(e)),t);if(0===s.length)return this.updateResults.recordNoop("update"),s;for(const e of s)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),r.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",s.length),s}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){const o=this._customRestyle;if(o)for(const i of e){const e=this._baseStyles.get(i)??i.style??{},r=o(i,t);i.style=r?{...e,...r}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){const t={...this.config},o=Object.keys(e).filter(o=>e[o]!==t[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!tt(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!tt(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!tt(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in e||"oAccessor"in e)&&(tt(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=rt(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let r=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,o=t.valueAccessor||t.rAccessor,i=Array.isArray(e)?e:[e],s=Array.isArray(o)?o:[o];if(r=i.length!==s.length||i.some((e,t)=>!tt(e,s[t])),r){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>it(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new te)):(this.getR=it(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!tt(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?rt(this.config.stackBy):void 0),"groupBy"in e&&!tt(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?rt(this.config.groupBy):void 0),"colorAccessor"in e&&!tt(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?rt(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!tt(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?rt(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!tt(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?rt(this.config.connectorAccessor):void 0),(i||r||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};R(Lr);import{jsx as Rr,jsxs as Cr}from"react/jsx-runtime";import{Fragment as zr,jsx as Fr,jsxs as Br}from"react/jsx-runtime";function Or(e,t){const o=io(e.theme),i=e.size||[500,400],r=Ee({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=we(e.title),n=be(e.data),a=e.showLegend?zi(n,e.colorAccessor||e.stackBy||e.groupBy):[];Zi(r,{props:e,categories:a,theme:o,size:i,hasTitle:s});const c=i[0]-r.left-r.right,l=i[1]-r.top-r.bottom,u=e.projection||"vertical",h="radial"===u,d={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:u,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:e.gradientFill,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:e.colorScheme||o.colors.categorical,themeCategorical:o.colors.categorical,themeSemantic:Pt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors},g=new Lr(d);if(e.data&&g.ingest({inserts:n,bounded:!0}),g.computeScene({width:c,height:l}),!g.scales||0===g.scene.length)return t&&(t.evidence=bi({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:g.scales?[]:["NO_SCALES"]})),sr.renderToStaticMarkup(er(null,{width:i[0],height:i[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const p=e._idPrefix,f=e.showGrid?function(e,t,o,i,r){const s=e.scales;if(!s||"radial"===s.projection)return null;const{grid:n}=ro(o),a=i?i+"-":"",c="vertical"===s.projection,l=U(s.r,5,r);return Gi("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=s.r(e);return Gi("line",{x1:0,y1:i,x2:t.width,y2:i,stroke:n,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=s.r(e);return Gi("line",{x1:i,y1:0,x2:i,y2:t.height,stroke:n,strokeWidth:.5},"gr-"+o)})})}(g,{width:c,height:l},o,p,e.axisExtent):null;let y=null;if(g.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){const t=Vi(e),i=new Set;for(const e of g.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&i.add("string"==typeof e.style.fill?e.style.fill:"#666");y=Array.from(i).map((e,i)=>function(e){const{id:t,background:o="transparent",stroke:i="#000",lineWidth:r=1.5,spacing:s=6,angle:n=45}=e,a=Math.max(8,Math.ceil(2*s));return Cr("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[o&&"transparent"!==o&&Rr("rect",{width:a,height:a,fill:o}),Rr("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:r}),Rr("line",{x1:s,y1:0,x2:s,y2:a,stroke:i,strokeWidth:r})]},t)}({id:`funnel-hatch-${t}-${i}`,background:e,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const r=new Map;Array.from(i).forEach((e,o)=>r.set(e,`funnel-hatch-${t}-${o}`));for(const e of g.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${r.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}const m=q({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>Fe(e,t,p)}),b=m.map(e=>e.element);if(t){const o=g.scales.o?.domain?.();t.evidence=bi({frameType:"ordinal",width:i[0],height:i[1],marks:m.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:mi(g.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0})}const x=!1!==e.showAxes?function(e,t,o,i,r){const s=e.scales;if(!s)return null;if("radial"===s.projection)return null;const n=ro(i),a="vertical"===s.projection,c=o.categoryFormat||o.oFormat,l=o.valueFormat||o.rFormat,u=o.categoryLabel||o.oLabel,h=o.valueLabel||o.rLabel,d=Object.values(e.columns).map(e=>({pixel:e.middle,label:(c||String)(e.name)})),g=U(s.r,5,o.axisExtent).map(e=>({pixel:s.r(e),label:(l||Ji)(e)}));return Br("g",a?{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Fr("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),d.map((e,o)=>Br("g",{transform:`translate(${e.pixel},${t.height})`,children:[Fr("line",{y2:5,stroke:n.border,strokeWidth:1}),Fr("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),u&&Fr("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:u}),Fr("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),g.map((e,t)=>Br("g",{transform:`translate(0,${e.pixel})`,children:[Fr("line",{x2:-5,stroke:n.border,strokeWidth:1}),Fr("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),h&&Fr("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:h})]}:{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Fr("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),g.map((e,o)=>Br("g",{transform:`translate(${e.pixel},${t.height})`,children:[Fr("line",{y2:5,stroke:n.border,strokeWidth:1}),Fr("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),h&&Fr("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:h}),Fr("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),d.map((e,t)=>Br("g",{transform:`translate(0,${e.pixel})`,children:[Fr("line",{x2:-5,stroke:n.border,strokeWidth:1}),Fr("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),u&&Fr("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:u})]})}(g,{width:c,height:l},e,o,p):null,v=e.annotations?Wi({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{o:g.scales.o,r:g.scales.r,y:"vertical"===g.scales.projection?g.scales.r:void 0},layout:{width:c,height:l},theme:o,projection:u,idPrefix:p}):null,A=Ui({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s}),S=h?r.left+c/2:r.left,w=h?r.top+l/2:r.top,k=h&&e.centerContent?Fr("foreignObject",{x:r.left,y:r.top,width:c,height:l,pointerEvents:"none",children:Fr("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return sr.renderToStaticMarkup(er(Br(zr,{children:[e.backgroundGraphics,f,b,x,v,e.foregroundGraphics,g.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${S},${w})`,innerWidth:c,innerHeight:l,legend:A,defs:y,outerElements:k,idPrefix:e._idPrefix}))}import*as Er from"react-dom/server";import{Fragment as Dr,jsxs as jr}from"react/jsx-runtime";function Nr(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Wr=new Set(["tree","cluster","treemap","circlepack","partition"]);function Ir(e,t){const o=io(e.theme),i=e.chartType||"force",r=()=>bi({frameType:"network",width:s[0],height:s[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,nodeCount:0,edgeCount:0}),s=e.size||[500,500],n=Ee({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=we(e.title),c=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;if(!t)return[];const i=be(e.nodes||[]);if(i.length>0)return zi(i,t);const r=Array.isArray(e.edges)?be(e.edges):[];if(0===r.length)return[];const s=Nr(e.sourceAccessor,"source"),n=Nr(e.targetAccessor,"target");return zi(Array.from(new Set(r.flatMap(e=>[s(e),n(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];Zi(n,{props:e,categories:c,theme:o,size:s,hasTitle:a});const l=s[0]-n.left-n.right,u=s[1]-n.top-n.bottom,h=H(i);if(!h&&!e.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${i}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const d={chartType:i,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||o.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig};let g,p;if(Wr.has(i)){const i=e.data||e.edges;if(!i||Array.isArray(i))return t&&(t.evidence=r()),Er.renderToStaticMarkup(er(null,{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:e._idPrefix}));d.__hierarchyRoot=i,g=[],p=[]}else{const i=be(e.nodes||[]),a=Array.isArray(e.edges)?be(e.edges):[];if(0===i.length&&0===a.length)return t&&(t.evidence=r()),Er.renderToStaticMarkup(er(null,{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:e._idPrefix}));if(p=function(e,t){const o=Nr(t.sourceAccessor,"source"),i=Nr(t.targetAccessor,"target"),r=Nr(t.valueAccessor,"value");return e.map(e=>({source:o(e)+"",target:i(e)+"",value:Number(r(e))||1,y0:0,y1:0,sankeyWidth:0,data:e}))}(a,d),0===i.length&&p.length>0){const e=new Set;for(const t of p){const o=Hi(t.source),i=Hi(t.target);o&&e.add(o),i&&e.add(i)}g=Array.from(e).map(e=>({id:e,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:e}}))}else g=function(e,t){const o=Nr(t.nodeIDAccessor,"id");return e.map(e=>({id:o(e)+"",x:e.x??0,y:e.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:e}))}(i,d)}let f=[],y=[],m=[],b=null;if(d.customNetworkLayout){const e=d.colorScheme,t=Ne(e,o.colors.categorical,bt),i=ge(t,e),r={nodes:g,edges:p,dimensions:{width:l,height:u,plot:{x:0,y:0,width:l,height:u}},theme:{semantic:o.colors,categorical:[...t]},resolveColor:i,config:d.layoutConfig??{}},s=d.customNetworkLayout(r);f=s.sceneNodes??[],y=s.sceneEdges??[],m=s.labels??[],b=s.overlays??null}else if(h){h.computeLayout(g,p,d,[l,u]);const e=h.buildScene(g,p,d,[l,u]);f=e.sceneNodes,y=e.sceneEdges,m=e.labels}const x=ro(o);for(const e of m)e.fill||(e.fill=x.text);const v=q({nodes:y,renderMode:e.renderMode,fallback:(e,t)=>Re(e,t)}),A=q({nodes:f,renderMode:e.renderMode,fallback:(e,t)=>Ce(e,t)});t&&(t.evidence=bi({frameType:"network",width:s[0],height:s[1],marks:[...A.map(({node:e})=>({type:"node:"+(e.type??"node")})),...v.map(({node:e})=>({type:"edge:"+(e.type??"edge")}))],title:e.title,description:e.description,annotations:e.annotations,nodeCount:A.length,edgeCount:v.length}));const S=v.map(e=>e.element),w=A.map(e=>e.element),k=m.map((e,t)=>Le(e,t)).filter(Boolean),_=e.annotations?Wi({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{},layout:{width:l,height:u},theme:o,idPrefix:e._idPrefix}):null,M=Ui({props:e,categories:c,theme:o,size:s,margin:n,hasTitle:a});return Er.renderToStaticMarkup(er(jr(Dr,{children:[e.backgroundGraphics,S,w,k,_,e.foregroundGraphics,b]}),{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,legend:M,idPrefix:e._idPrefix}))}import*as $r from"react-dom/server";import{geoPath as Gr}from"d3-geo";import{quadtree as Yr}from"d3-quadtree";import{geoMercator as Hr,geoEqualEarth as Vr,geoAlbersUsa as Xr,geoOrthographic as qr,geoNaturalEarth1 as Qr,geoEquirectangular as Kr}from"d3-geo";var Zr={mercator:Hr,equalEarth:Vr,albersUsa:Xr,orthographic:qr,naturalEarth:Qr,equirectangular:Kr};function Ur(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Jr(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function es(e,t,o){return e?"function"==typeof e?{...o,...e(t)}:{...o,...e}:{...o}}function ts(e,t){if(2>e.length)return[e];const o=.4*t,i=[];let r=[e[0]];for(let t=1;e.length>t;t++){const s=e[t];Math.abs(s[0]-e[t-1][0])>o?(2>r.length||i.push(r),r=[s]):r.push(s)}return 2>r.length||i.push(r),i}function os(e,t,o=24){const i=t[0]-e[0],r=t[1]-e[1],s=Math.sqrt(i*i+r*r);if(0===s)return[e,t];const n=-r/s,a=i/s,c=Math.min(.3*s,80),l=(e[0]+t[0])/2+n*c,u=(e[1]+t[1])/2+a*c,h=[];for(let i=0;o>=i;i++){const r=i/o,s=1-r;h.push([s*s*e[0]+2*s*r*l+r*r*t[0],s*s*e[1]+2*s*r*u+r*r*t[1]])}return h}function is(e,t){if(2>e.length)return e;const o=t/2+1,i=[];for(let t=0;e.length>t;t++){const r=e[t];let s,n;0===t?(s=e[1][0]-r[0],n=e[1][1]-r[1]):t===e.length-1?(s=r[0]-e[t-1][0],n=r[1]-e[t-1][1]):(s=e[t+1][0]-e[t-1][0],n=e[t+1][1]-e[t-1][1]);const a=Math.sqrt(s*s+n*n)||1;i.push([r[0]+n/a*o,r[1]+-s/a*o])}return i}function rs(e,t,o,i,r){const s=t[0]-e[0],n=t[1]-e[1],a=Math.sqrt(s*s+n*n);if(0===a)return[e,t];const c=n/a,l=-s/a,u=r/2+1;return[[e[0]+c*u,e[1]+l*u],[t[0]+c*u,t[1]+l*u]]}import{scaleLinear as ss}from"d3-scale";var ns=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],as=["scene-style","data-paint","accessibility","evidence"],cs=(e,t)=>({retainedData:e,invalidations:t}),ls=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],us=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],hs=["scene-geometry","data-paint","accessibility","evidence"],ds=["scene-style","data-paint","accessibility","evidence"],gs=["overlay","accessibility","evidence"],ps=[],fs={xAccessor:cs("rebuild",ls),yAccessor:cs("rebuild",ls),lineDataAccessor:cs("rebuild",ls),pointIdAccessor:cs("rebuild",hs),lineIdAccessor:cs("rebuild",hs),windowSize:cs("rebuild",ls),projection:cs("preserve",us),projectionExtent:cs("preserve",us),fitPadding:cs("preserve",us),lineType:cs("preserve",us),flowStyle:cs("preserve",us),graticule:cs("preserve",us),projectionTransform:cs("preserve",us),customLayout:cs("preserve",us),layoutConfig:cs("preserve",us),layoutMargin:cs("preserve",us),areaStyle:cs("preserve",ds),pointStyle:cs("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:cs("preserve",ds),colorScheme:cs("preserve",ds),themeCategorical:cs("preserve",ds),themeDiverging:cs("preserve",ds),themeSemantic:cs("preserve",ds),themeSequential:cs("preserve",ds),decay:cs("preserve",ds),pulse:cs("preserve",ds),layoutSelection:cs("preserve",ds),annotations:cs("preserve",gs),autoPlaceAnnotations:cs("preserve",gs),clock:cs("preserve",ps),transition:cs("preserve",ps),introAnimation:cs("preserve",ps),onLayoutError:cs("preserve",ps)},ys=cs("preserve",us),ms=class{constructor(){this.tracker=new at}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},ns)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},as):this.recordNoop("restyle")}recordConfig(e,t={}){const o=function(e){let t="preserve";const o=new Set;for(const i of e){const e=fs[i]??ys;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e),i=new Set(o.invalidations);return t.retainedDataChanged&&i.add("data"),this.tracker.record({kind:"config",keys:e},i)}};import{geoDistance as bs,geoGraticule as xs,geoInterpolate as vs}from"d3-geo";function As(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&.5>e)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${e+""}.`)}var Ss=class e{constructor(e){this.updateResults=new ms,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(e){return{...e,fitPadding:As(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??ze()}getConfiguredWindowSize(){const e=this.config.windowSize??500;if(!Number.isInteger(e)||1>e)throw Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){const t=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],i=t.slice(-e),r=o.slice(-i.length),s=this.currentTime();this.pointBuffer=new oe(e),this.timestampBuffer=new oe(e),i.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(r[t]??s)})}this.retainNewestLines(e)}updateConfig(e){const t=function(e){return"fitPadding"in e?{...e,fitPadding:As(e.fitPadding)}:e}(e),o=this.config,i=this.getConfiguredWindowSize(),r=Object.keys(t).filter(e=>t[e]!==o[e]);this.config={...this.config,...t};const s=this.getConfiguredWindowSize(),n=this.streaming&&s!==i;n&&(this.resizeStreamingWindow(s),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(r,{retainedDataChanged:n})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});const t=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,i=this.timestampBuffer?.toArray()??[],r=o.slice(-t),s=i.slice(-r.length),n=this.currentTime();this.pointBuffer=new oe(t),this.timestampBuffer=new oe(t),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(s[t]??n)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();X(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();for(const o of e)X(this.pointBuffer,o,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");const t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(const e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){const{lineIdAccessor:t}=this.config;if(!t)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],i=new Set(Array.isArray(e)?e:[e]),r=[];return this.lineData=this.lineData.filter(e=>!i.has(o(e)+"")||(r.push(e),!1)),r.length>0?(this.version++,this.updateResults.recordData("remove",r.length)):this.updateResults.recordNoop("remove"),r}getLines(){return this.lineData.slice()}removePoint(e){const{pointIdAccessor:t}=this.config;if(!t)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],i=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){const e=e=>i.has(o(e)+"");N(this.pointBuffer,this.timestampBuffer,e);const t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{const e=[];return this.pointData=this.pointData.filter(t=>!i.has(o(t)+"")||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){const t=this._customRestyle;if(t){for(const o of this.scene){const i=this._baseStyles.get(o)??o.style,r=t(o,e);o.style=r?{...i,...r}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){const{config:t}=this,o=this.projection,i=this.geoPath,r=this.scales,s=this.baseScale,n=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(e){if(!e)return Vr();if("string"==typeof e){const t=Zr[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),Vr())}if("object"==typeof e&&"type"in e){const t=Zr[e.type],o=t?t():Vr();return e.rotate&&"rotate"in o&&o.rotate(e.rotate),e.center&&"center"in o&&o.center(e.center),o}return e}(t.projection),this.geoPath=Gr(this.projection),this.fitProjection(e),this.geoPath=Gr(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(e,t)=>l([e,t]),invertedPoint:(e,t)=>l.invert?l.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=i,this.scales=r,this.baseScale=s,this.baseTranslate=n,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){const t=e.width/2,o=e.height/2,i=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:o}));i.length>0&&this.startTransition(i)}this._hasRenderedOnce=!0,t.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(e){const t=this.projection,o=this.config,i=[...this.areas],r=Ur(o.xAccessor,"lon"),s=Ur(o.yAccessor,"lat"),n=this.getPoints();if(n.length>0){const e=n.map(e=>[r(e),s(e)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}const a=Jr(o.lineDataAccessor);for(const e of this.lineData){const t=a(e);if(t&&t.length>0){const e=t.map(e=>[r(e),s(e)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==i.length){if(o.projectionExtent){const[[i,r],[s,n]]=o.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,r],[i,n],[s,n],[s,r],[i,r]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){const i=o.fitPadding??0,r=Math.min(e.width,e.height);t.scale(r/2-r*i),t.translate([e.width/2,e.height/2])}else{const r=o.fitPadding??0,s=e.width*r,n=e.height*r;t.fitExtent([[s,n],[e.width-s,e.height-n]],{type:"FeatureCollection",features:i})}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){const o=this.projection;if(!o)return;const i=this.geoPath,r=this.scales,s=o.scale(),n=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e.k),o.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=Gr(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(s),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){const o=this.projection;if(!o)return;const i=this.geoPath,r=this.scales,s=o.scale(),n=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e),o.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=Gr(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(s),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){const o=this.projection;if(!o||!o.rotate)return;const i=this.geoPath,r=this.scales,s=[...o.rotate()];o.rotate(e),this.geoPath=Gr(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const n=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(s),this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=n,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){const t=this.projection;t&&t.rotate&&t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let t=0,o=0;for(const e of this.scene)"point"===e.type&&(o++,e.r>t&&(t=e.r));if(this._maxPointRadius=t,e.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const i=Array(o);let r=0;for(const e of this.scene)"point"===e.type&&(i[r++]=e);this._quadtree=Yr().x(e=>e.x).y(e=>e.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;const{config:t}=this,o=this.projection,i=this.geoPath;if(t.customLayout&&this.scales){const o=t.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Ne(t.colorScheme,t.themeCategorical,ce),r={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:o,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...i]},resolveColor:ge(i,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null};let s;try{s=t.customLayout(r)}catch(e){const o=null!==this.lastCustomLayoutResult,i=$("geo",e,o,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",e);try{t.onLayoutError?.(i)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const n=s.nodes??[];if(this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null,this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const e of n)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return ee({label:"geo customLayout",nodes:n,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),n}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:o,areas:i,points:r,lines:s,layout:n}){const a=Ur(e.xAccessor,"lon"),c=Ur(e.yAccessor,"lat"),l=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),h=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),d=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){const t=!0===e.graticule?{}:e.graticule,i=xs();t.step&&i.step(t.step);const r=o(i())||"";r&&l.push({type:"geoarea",pathData:r,centroid:[n.width/2,n.height/2],bounds:[[0,0],[n.width,n.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth||.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const t of i){const i=o(t);if(!i)continue;const r=o.centroid(t),s=o.bounds(t),n=o.area(t);l.push({type:"geoarea",pathData:i,centroid:r,bounds:s,screenArea:n,style:es(e.areaStyle,t,u),datum:t,interactive:!0})}const g=Jr(e.lineDataAccessor);for(const o of s){const i=g(o);if(!i||2>i.length)continue;let r=[];if("geo"===e.lineType){const e=Array(i.length);for(let t=0;i.length>t;t++)e[t]=[a(i[t]),c(i[t])];for(let o=0;e.length-1>o;o++){const i=e[o],s=e[o+1],n=bs(i,s)||0,a=Math.max(2,Math.ceil(n/(Math.PI/180))),c=vs(i,s);for(let e=0;a>=e;e++){if(o>0&&0===e)continue;const i=t(c(e/a));null!=i&&r.push(i)}}}else for(let e=0;i.length>e;e++){const o=i[e],s=t([a(o),c(o)]);null!=s&&r.push(s)}if(2>r.length)continue;const s=es(e.lineStyle,o,h),u="number"==typeof s.strokeWidth?s.strokeWidth:1;2!==i.length||2>r.length||"arc"!==e.flowStyle?2!==i.length||2>r.length||"offset"!==e.flowStyle||(r="geo"===e.lineType?is(r,u):rs(r[0],r[r.length-1],0,0,u)):r=os(r[0],r[r.length-1]);const d=ts(r,n.width);if(d.length>1)for(const e of d)2>e.length||l.push({type:"line",path:e,style:{...s,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>r.length&&d[0]||r,style:s,datum:o})}const p=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,f=t.clipAngle?t.clipAngle()??0:0,y=f>0?f*Math.PI/180:null,m=t.rotate?t.rotate():[0,0,0],b="function"==typeof t.center?t.center():[0,0],x=[(b[0]??0)-m[0],(b[1]??0)-m[1]];for(const o of r){const i=a(o),r=c(o);if(null!=y&&bs([i,r],x)>y)continue;const s=t([i,r]);if(!s)continue;const n=e.pointStyle?e.pointStyle(o):{...d},u={type:"point",x:s[0],y:s[1],r:n.r||4,style:n,datum:o,pointId:p?p(o)+"":void 0};l.push(u)}return l}({config:t,projection:o,path:i,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){const o=function(e,t,o,i){const r=e.filter(e=>"point"===e.type);if(2>r.length)return null;const s=t.strength??1;if(0===s)return null;const n=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,a="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],c=r.find(e=>e.datum&&n(e.datum)+""==t.center+"");if(!c)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;const l=c.x,u=c.y,h=r.map(e=>e.datum?a(e.datum):NaN).filter(e=>isFinite(e)&&e>=0),d=xt(h,1),g=Math.min(o.width,o.height)/2,p=ss().domain([0,d]).range([0,g]);i>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){const o=e[t];"geoarea"===o.type&&o.interactive&&e.splice(t,1)}for(const e of r){if(e===c)continue;if(!e.datum)continue;const t=Math.atan2(e.y-u,e.x-l),o=Math.sqrt((e.x-l)**2+(e.y-u)**2),i=a(e.datum),r=o+((isFinite(i)?p(i):o)-o)*s;e.x=l+Math.cos(t)*r,e.y=u+Math.sin(t)*r}const f=o.width/2,y=o.height/2,m=f-c.x,b=y-c.y;if(Math.abs(m)>.5||Math.abs(b)>.5)for(const e of r)e.x+=m,e.y+=b;const x={cx:f,cy:y,maxCost:d,availableRadius:g},v=e.filter(e=>"line"===e.type);if(v.length>0&&"fractional"!==t.lineMode){const e=new Map;for(const t of r)t.pointId&&e.set(t.pointId,[t.x,t.y]);for(const t of v){const o=t.datum?.source,i=t.datum?.target;if(o&&i){const r=e.get(o+""),s=e.get(i+"");r&&s&&(t.path=[r,s])}}}return x}(this.scene,e,t,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const e=this.config.decay;if(!e||!this.pointBuffer)return;const t=this.pointBuffer.size;if(0===t)return;const o=this.scene.filter(e=>"point"===e.type);for(let i=0;o.length>i;i++){const r=W(e,i,t);o[i]._decayOpacity=r,o[i].style={...o[i].style,opacity:r}}}applyPulse(e=this.currentTime()){const t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;const o=this.scene.filter(e=>"point"===e.type),i=this.timestampBuffer.toArray(),r=t.color||"rgba(255,255,255,0.6)",s=t.glowRadius??4;let n=!1;for(let a=0;o.length>a&&i.length>a;a++){const c=I(t,i[a],e);n=Z(o[a],c,r,s)||n}return n}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&V(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){const t=this.config.transition?.duration??300;if(0>=t)return;const o=new Map;for(const t of e)"point"===t.type&&t.pointId&&o.set(t.pointId,[t.x,t.y]);const i=this.scene.filter(e=>"point"===e.type);let r=!1;for(const e of i)if(e.pointId){const t=o.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(r=!0))}for(const e of i)e.pointId&&!o.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??1,e.style={...e.style,opacity:0},r=!0);r&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(e){if(!this.activeTransition)return!1;const t=ye(e,this.activeTransition),o=fe(t),i=this.scene.filter(e=>"point"===e.type);for(const e of i){if(null!=e._targetX&&null!=e._targetY){const t=e.y;e.x=Te(e.x,e._targetX,o),e.y=Te(t,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(t>=1){for(const e of i)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Ss.QUADTREE_THRESHOLD=500;var ws=Ss;R(ws);import{Fragment as ks,jsxs as _s}from"react/jsx-runtime";function Ms(e,t){const o=io(e.theme),i=e.size||[e.width||600,e.height||400],r=Ee({top:10,right:10,bottom:10,left:10,...e.margin},e.title),s=we(e.title),n=Array.isArray(e.areas)?be(e.areas):e.areas,a=be(e.points),c=be(e.lines),l=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;return zi(a.length>0?a:Array.isArray(n)&&n.length>0?"string"==typeof t?n.map(e=>({...e.properties||{},...e})):n:[],t)})():[];Zi(r,{props:e,categories:l,theme:o,size:i,hasTitle:s});const u=i[0]-(r.left??0)-(r.right??0),h=i[1]-(r.top??0)-(r.bottom??0),d={projection:e.projection||"equalEarth",xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineType:e.lineType,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,themeCategorical:o.colors.categorical,themeSemantic:Pt(o)},g=new ws(d);if(n){if("string"==typeof n)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${n}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${n}')\` before calling renderGeoToStaticSVG.`);g.setAreas(n)}e.points&&g.setPoints(a),e.lines&&g.setLines(c),g.computeScene({width:u,height:h});const p=q({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>xe(e,t)});if(t&&(t.evidence=bi({frameType:"geo",width:i[0],height:i[1],marks:p.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,legendItems:l.length>0?l.length:void 0})),0===p.length){const t=e.backgroundGraphics||e.foregroundGraphics||e.annotations||g.customLayoutOverlays?_s(ks,{children:[e.backgroundGraphics,e.annotations?Wi({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:u,height:h},theme:o,idPrefix:e._idPrefix}):null,e.foregroundGraphics,g.customLayoutOverlays]}):null;return $r.renderToStaticMarkup(er(t,{width:i[0],height:i[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left??0},${r.top??0})`,innerWidth:u,innerHeight:h,idPrefix:e._idPrefix}))}const f=p.map(e=>e.element),y=e.annotations?Wi({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:u,height:h},theme:o,idPrefix:e._idPrefix}):null,m=Ui({props:e,categories:l,theme:o,size:i,margin:r,hasTitle:s});return $r.renderToStaticMarkup(er(_s(ks,{children:[e.backgroundGraphics,f,y,e.foregroundGraphics,g.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left??0},${r.top??0})`,innerWidth:u,innerHeight:h,legend:m,idPrefix:e._idPrefix}))}function Ps(e,t){const o=e.size??[e.width??600,e.height??400],i=new S(e.config);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&i.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));const r=h(i,{...e,width:o[0],height:o[1],idPrefix:e.idPrefix??e._idPrefix??"physics"});return t&&(t.evidence=bi({frameType:"physics",width:o[0],height:o[1],marks:r.scene.sceneNodes,title:e.title,description:e.description,annotations:[],extraWarnings:0===r.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[]})),r.svg}import{Fragment as Ts,jsx as Ls,jsxs as Rs}from"react/jsx-runtime";function Cs(e,t){switch(e){case"xy":return rr(t);case"ordinal":return Or(t);case"network":return Ir(t);case"geo":return Ms(t);case"physics":return Ps(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function zs(e){return rr(e)}function Fs(e){return Or(e)}function Bs(e){return Ir(e)}function Os(e){return Ms(e)}var Es=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","barColors","legend","legendLayout","autoPlaceAnnotations"],Ds=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function js(e,t){const o={};for(const i of t)void 0!==e[i]&&(o[i]=e[i]);return o}function Ns(e,t,o){return Is(e,t).svg}function Ws(e,t,o){const i={},{svg:r,frameType:s}=Is(e,t,0,i),n=i.evidence??bi({frameType:s,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});return n.component=e,{svg:r,evidence:n}}function Is(e,t,o,i){const r=fi[e];if(!r)throw Error(`Unknown chart component: "${e}". See CLAUDE.md for supported chart types.`);const s=r.layout?.mode??(ke(t.mode)?t.mode:void 0),n=je(s,{...r.layout?.modeDefaults,...js(t,Ds)},r.layout?.primarySize),{data:a,theme:c,background:l,className:u,annotations:h,margin:d,colorScheme:g,colorBy:p,legendPosition:f,...y}=t,{width:m,height:b}=n,x=[m,b],v=y.frameProps||{},A=r.layout?.margin,S="function"==typeof A?A(t,n):A??n.marginDefaults,w=void 0!==d?d:v.margin,k=function(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};const t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}(w),_="number"==typeof w?{top:w,right:w,bottom:w,left:w}:{...S,...k},M=js(y,Es),P={...v,...M,theme:c,title:n.title,description:n.description,showAxes:n.showAxes,showLegend:n.showLegend,showLabels:n.showLabels,showGrid:n.showGrid,xLabel:n.xLabel,yLabel:n.yLabel,categoryLabel:n.categoryLabel,valueLabel:n.valueLabel,background:l,className:u,annotations:h,size:x,margin:_,__explicitMargin:w,__autoLegendMargin:!0,...void 0!==g&&{colorScheme:g},...void 0!==f&&{legendPosition:f},_idPrefix:y._idPrefix},T=r.buildProps(a,p,g,P,y);let L;switch(r.frameType){case"xy":L=rr(T,i);break;case"ordinal":L=Or(T,i);break;case"network":L=Ir(T,i);break;case"geo":L=Ms(T,i);break;case"physics":L=Ps(T,i)}const R=r.renderOverlay?.(T,{theme:io(c)});if(null!=R){const e=Lt.renderToStaticMarkup(Ls(Ts,{children:R}));L=L.replace("</svg>",e+"</svg>")}return{svg:L,frameType:r.frameType}}function $s(e,t={}){const{title:o,subtitle:i,theme:r,width:s=1200,height:n,layout:a={},background:c}=t,l=ro(io(r)),u=a.columns||2,h=a.gap??16;let d=0;o&&(d+=30),i&&(d+=20),d>0&&(d+=10);const g=Math.floor((s-h-h*(u-1))/u),p=[];let f=0,y=d+h,m=0;for(const t of e){const e=Math.min(t.colSpan||1,u),o=t.props.height||300;f+e>u&&(y+=m+h,f=0,m=0),p.push({chart:t,x:h/2+f*(g+h),y:y,w:g*e+h*(e-1),h:o}),m=Math.max(m,o),f+=e}const b=n||y+m+h,x=p.map((e,t)=>{const{chart:o,x:i,y:s,w:n,h:a}=e,c={...o.props,width:n,height:a,theme:r,_idPrefix:"chart-"+t};let l;return l=o.component?Ns(o.component,c):o.frameType?Cs(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${a}"></svg>`,Ls("g",{transform:`translate(${i},${s})`,children:Ls("foreignObject",{width:n,height:a,children:Ls("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+t)});return Lt.renderToStaticMarkup(Rs("svg",{xmlns:"http://www.w3.org/2000/svg",width:s,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&Ls("title",{children:o}),c&&Ls("rect",{x:0,y:0,width:s,height:b,fill:c}),o&&Ls("text",{x:s/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:o}),i&&Ls("text",{x:s/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),x]}))}import*as Gs from"react-dom/server";import{Fragment as Ys,jsx as Hs,jsxs as Vs}from"react/jsx-runtime";function Xs(e,t,o,i={}){const{stepSize:r,windowSize:s,frameCount:n,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:h="ease-out",decay:d}=i,g=o.width||600,p=o.height||400,f=io(o.theme),y={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!t||0===t.length)return[];const m=r||Math.max(1,Math.ceil(t.length/(n||Math.min(60,Math.max(10,t.length))))),b=[];for(let e=m;t.length>=e;e+=m)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);const x=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),v=Ee({top:20,right:20,bottom:30,left:40,...o.margin},o.title),A=g-v.left-v.right,S=p-v.top-v.bottom,w=[];if(x)for(let i=0;b.length>i;i++){const r=b[i],n=t.slice(s?Math.max(0,r-s):0,r),a={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||f.colors.categorical,...d&&{decay:d}},c=new Lr(a);c.ingest({inserts:n,bounded:!0}),c.computeScene({width:A,height:S}),c.scene.length>0&&w.push(Js(c.scene,g,p,f,y))}else for(let i=0;b.length>i;i++){const r=b[i],n=t.slice(s?Math.max(0,r-s):0,r),m={chartType:e,windowSize:n.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:o.colorScheme||f.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...d&&{decay:d},...l>0&&{transition:{duration:l*(1e3/u),easing:h}}},x=new P(m);if(x.ingest({inserts:n,bounded:!0}),x.computeScene({width:A,height:S}),0===x.scene.length)continue;const v=x.scales?{y:x.scales.y}:void 0;if(w.push(Us(x.scene,g,p,f,y,v)),l>0&&i>0&&x.activeTransition){const e=l*(1e3/u);for(let t=1;l>=t;t++)x.advanceTransition(x.activeTransition.startTime+t/l*e),w.push(Us(x.scene,g,p,f,y,v))}}return w}function qs(e,t,o={}){return t.map(t=>{try{return Ns(e,{...o,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||t.width||600}" height="${o.height||t.height||400}"></svg>`}})}function Qs(e,t,o){const i=t.size??[t.width??600,t.height??400],r=io(t.theme),s=ro(r),n=t.background||r.colors.background,a=t.idPrefix??"physics-gif",c=t.title?`${a}-title-${o}`:void 0,l=t.description?`${a}-desc-${o}`:void 0,h=[c,l].filter(Boolean).join(" ")||void 0,d=u(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),g=Vs("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,role:"img","aria-labelledby":h,style:{fontFamily:s.fontFamily},children:[t.title&&Hs("title",{id:c,children:t.title}),t.description&&Hs("desc",{id:l,children:t.description}),n&&"transparent"!==n?Hs("rect",{x:0,y:0,width:i[0],height:i[1],fill:n}):null,Hs("g",{id:`${a}-frame-${o}`,children:d.map((e,t)=>Je(e,t,`${a}-${o}`))})]});return Gs.renderToStaticMarkup(g)}function Ks(e,t={}){const{fps:o=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:n,stepsPerFrame:a,background:c}=t,l=Math.max(.001,n??e.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),h=i??Math.max(1,Math.ceil(r*Math.max(1,o))),d=c?{...e,background:c}:e,g=new S(e.config);e.initialSpawns?.length&&g.enqueue(e.initialSpawns,e.initialSpawnPacing);const p=[];for(s&&(g.tick(0),p.push(Qs(g,d,0)));h>p.length;){for(let e=0;u>e;e+=1)g.tick(l);p.push(Qs(g,d,p.length))}return p}function Zs(e,t){const o=e.background||t.colors.background;return o&&"transparent"!==o?o:null}function Us(e,t,o,i,r,s){const n=ro(i),a=Ee({top:20,right:20,bottom:30,left:40,...r.margin},r.title),c=t-a.left-a.right,l=o-a.top-a.bottom,u=Zs(r,i),h=r.renderMode,d=e.map((e,t)=>Q({node:e,index:t,renderMode:h,fallback:()=>Je(e,t)})).filter(Boolean),g=function(e,t,o,i,r,s){if(!e||0===e.length)return null;const n=ro(i),a=[];for(let i=0;e.length>i;i++){const c=e[i];if("y-threshold"===c.type&&null!=c.value){let e=null;if(s)e=s(c.value);else if(r){const[t,i]=r,s=i-t;if(0===s)continue;e=o-(c.value-t)/s*o}if(null==e)continue;const l=c.color||n.primary,u=c.labelPosition||"right";a.push(Vs("g",{children:[Hs("line",{x1:0,y1:e,x2:t,y2:e,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&Hs("text",{x:"left"===u?4:"center"===u?t/2:t-4,y:20>e?Math.min(o-4,e+16):e-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:n.tickSize,fill:l,fontFamily:n.fontFamily,children:c.label})]},"ann-"+i))}}return a.length>0?Hs(Ys,{children:a}):null}(r.annotations,c,l,i,r.yExtent,s?.y),p="string"==typeof r.title?r.title:void 0,f="string"==typeof r.description?r.description:void 0,y=p?"semiotic-title":void 0,m=f?"semiotic-desc":void 0,b=[y,m].filter(Boolean).join(" ")||void 0;return Gs.renderToStaticMarkup(Vs("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":b,style:{fontFamily:n.fontFamily},children:[p&&Hs("title",{id:y,children:p}),f&&Hs("desc",{id:m,children:f}),u&&Hs("rect",{x:0,y:0,width:t,height:o,fill:u}),Vs("g",{transform:`translate(${a.left},${a.top})`,children:[g,d]}),p&&Hs("text",{x:t/2,y:he,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:p})]}))}function Js(e,t,o,i,r){const s=ro(i),n=Ee({top:20,right:20,bottom:30,left:40,...r.margin},r.title),a="radial"===r.projection,c=a?n.left+(t-n.left-n.right)/2:n.left,l=a?n.top+(o-n.top-n.bottom)/2:n.top,u=Zs(r,i),h=r.renderMode,d=e.map((e,t)=>Q({node:e,index:t,renderMode:h,fallback:()=>Fe(e,t)})).filter(Boolean),g="string"==typeof r.title?r.title:void 0,p="string"==typeof r.description?r.description:void 0,f=g?"semiotic-title":void 0,y=p?"semiotic-desc":void 0,m=[f,y].filter(Boolean).join(" ")||void 0;return Gs.renderToStaticMarkup(Vs("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":m,style:{fontFamily:s.fontFamily},children:[g&&Hs("title",{id:f,children:g}),p&&Hs("desc",{id:y,children:p}),u&&Hs("rect",{x:0,y:0,width:t,height:o,fill:u}),Hs("g",{transform:`translate(${c},${l})`,children:d}),g&&Hs("text",{x:t/2,y:he,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:g})]}))}export{Xs as generateFrameSVGs,qs as generateFrameSequence,Ks as generatePhysicsFrameSVGs,Ns as renderChart,Ws as renderChartWithEvidence,$s as renderDashboard,Os as renderGeoToStaticSVG,Bs as renderNetworkToStaticSVG,Fs as renderOrdinalToStaticSVG,Cs as renderToStaticSVG,zs as renderXYToStaticSVG,io as resolveTheme,ro as themeStyles};
1
+ import{computeArcBoundingBox as e,darkenColor as t,lightenColor as o,sweepToAngles as i}from"./chunk-chunk-ROZWKEUG.module.min.js";import{buildCollisionSwarmPhysics as r,buildEventDropPhysics as s,buildGaltonBoardPhysics as n,buildPhysicalFlowPhysics as a,buildPhysicsPile as c,buildPhysicsSettledProjection as l,buildProcessFlowPhysics as u,generateGaltonMechanicalSamples as d,generatePhysicsPileMechanicalSamples as h,physicsBodiesToXYSceneNodes as p,renderPhysicsSettledSVG as m,resolveCustomLayout as g,styleFromColorAccessor as f}from"./chunk-chunk-UDREYOLV.module.min.js";import{composeStyleRules as y,makeNodeRuleContext as b,makeRuleValueResolver as x,makeXYRuleContext as v,resolveStyleRules as A,styleRulesToNodeStyle as w,styleRulesToXYStyle as S}from"./chunk-chunk-IP2UE74X.module.min.js";import{PhysicsPipelineStore as k}from"./chunk-chunk-LPSPATPC.module.min.js";import"./chunk-chunk-SIRIJ3DY.module.min.js";import{PipelineStore as _,StreamXYFrame_default as M,attachUpdateResultStore as R,buildBaseMetadataProps as P,buildCustomBehaviorProps as L,buildDatumIndexMap as I,buildRectNode as T,buildRibbonGeometry as C,compactTimestampBufferForRemoval as z,computeDecayOpacity as O,computePulseIntensity as F,createCustomLayoutFailureDiagnostic as B,createTimestampBufferForData as E,ensureRingBufferCapacity as j,getLayoutPlugin as D,hasActivePulses as N,normalizeColorGradient as $,normalizeGradient as W,normalizeSemanticGradient as G,pushWithTimestamp as V,renderSceneListWithBackend as H,renderSceneWithBackend as Y,resolveDownwardHistogramExtent as X,reverseGradient as q,setPulseState as U,ticksForMode as Q,toIdSet as K,warnCustomLayoutDiagnostics as Z}from"./chunk-chunk-3SHB24AG.module.min.js";import{IncrementalExtent as J,RingBuffer as ee}from"./chunk-chunk-7ALTGHK6.module.min.js";import{useCustomLayoutSelection as te}from"./chunk-chunk-C4YA6TDR.module.min.js";import{AnnotationLabel as oe,DEFAULT_COLOR as ie,DEFAULT_LEGEND_ROW_HEIGHT as re,DEPTH_PALETTE_COLORS as se,STREAMING_PALETTE as ne,SafeRender as ae,SemioticAnnotation as ce,TITLE_BASELINE as le,buildResolveColor as ue,composeLegendConfigs as de,computeEasing as he,computeRawProgress as pe,createColorScale as me,filterSparseArray as ge,geoSceneNodeToSVG as fe,getColor as ye,getCrosshairProps as be,getSize as xe,hasTextTitle as ve,isChartMode as Ae,isGradientLegendConfig as we,isLegendConfig as Se,layoutVerticalLegendGroups as ke,lerp as _e,networkLabelToSVG as Me,networkSceneEdgeToSVG as Re,networkSceneNodeToSVG as Pe,now as Le,ordinalSceneNodeToSVG as Ie,renderAnnotationPass as Te,renderEmptyState as Ce,renderLoadingState as ze,reserveTitleMargin as Oe,resolveCategoricalPalette as Fe,resolveChartMode as Be,resolveCustomLayoutPalette as Ee,resolveDefaultFill as je,resolveExplicitColor as De,resolveLegendDistance as Ne,resolveLegendMetrics as $e,resolveLegendSideGutter as We,resolveMobileInteraction as Ge,resolveSideLegendMargin as Ve,resolveSideLegendWidth as He,useCategoryColors as Ye,useChartLegendAndMargin as Xe,useChartMode as qe,useChartSelection as Ue,useColorScale as Qe,useLegendInteraction as Ke,useThemeCategorical as Ze,xySceneNodeToSVG as Je}from"./chunk-chunk-A5GRQUOF.module.min.js";import{useTheme as et}from"./chunk-chunk-XEVJDUTH.module.min.js";import{accessorsEquivalent as tt,defaultTooltipStyle as ot,filterAnnotationsByStatus as it,normalizeTooltip as rt,resolveAccessor as st,resolveStringAccessor as nt,resolveSvgFill as at}from"./chunk-chunk-CO5KQMGH.module.min.js";import{SYMBOL_SEQUENCE as ct,UpdateResultTracker as lt,annotationLayout as ut,getSequentialInterpolator as dt,interpolateBrBG as ht,interpolatePRGn as pt,interpolatePiYG as mt,interpolateRdBu as gt,interpolateRdYlBu as ft,interpolateRdYlGn as yt,interpolateSpectral as bt,interpolateViridis as xt,schemeCategory10 as vt}from"./chunk-chunk-5RKXZQ2P.module.min.js";import"./chunk-chunk-U66USBWU.module.min.js";import{getMax as At,getMin as wt,getMinMax as St}from"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-IY7RYD4S.module.min.js";import"./chunk-chunk-J3QOW4OE.module.min.js";import{DARK_THEME as kt,HIGH_CONTRAST_THEME as _t,LIGHT_THEME as Mt,THEME_PRESETS as Rt,applyThemeAccessibility as Pt,resolveThemeSemanticColors as Lt,useThemeSelector as It}from"./chunk-chunk-DSNGDNJY.module.min.js";function Tt(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};const t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}import*as Ct from"react-dom/server";import*as zt from"react";function Ot(e,t,o){return"function"==typeof e?e(o):o[e||t]}function Ft(e){return e instanceof Date?e.getTime():Number(e)}function Bt(e,t){return xt(1===t?.5:e/(t-1))}function Et(e){if(!e)return Mt;if("string"==typeof e){if("light"===e)return Mt;if("dark"===e)return kt;if("high-contrast"===e)return _t;return Rt[e]||Mt}const t="dark"===e.mode?kt:Mt,o={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return Pt(o)}function jt(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}var Dt="__forecastSegment",Nt="__forecastOpacity";function $t(e,t,o,i){const r=t.uncertaintyOpacity,s=t.confidenceAccessor;if(!r&&!s)return;const n="object"==typeof r?r:{},a=n.min??.15,c=n.max??1;if(s){const t="function"==typeof s?s:e=>e[s];for(const o of e){const e=t(o);null!=e&&Number.isFinite(e)&&(o[Nt]=a+Math.max(0,Math.min(1,e))*(c-a))}return}const l=e.map(e=>{const t=o(e),r=i(e);return null!=t&&null!=r&&Number.isFinite(t)&&Number.isFinite(r)?Math.abs(t-r):NaN}),u=l.filter(e=>Number.isFinite(e));if(0===u.length)return;const[d,h]=St(u),p=h-d;e.forEach((e,t)=>{const o=l[t];Number.isFinite(o)&&(e[Nt]=c-(p>0?(o-d)/p:0)*(c-a))})}function Wt(e,t){return"function"==typeof t?t(e):!!e[t]}var Gt="__semiotic_resolvedX",Vt="__semiotic_resolvedY",Ht="__compoundGroup";function Yt(e,t,o){const i=e[t],r=e[o];return null==i||null==r||Number.isNaN(i)||Number.isNaN(r)}function Xt(e){const i=e.xAccessor||"x",r=e.yAccessor||"y",s=e.lineBy,n=e.colorBy||s;let a=Array.isArray(e.data)?ge(e.data).filter(e=>!!e&&"object"==typeof e):[];const c=function(e,t,o){const i="function"==typeof t,r="function"==typeof o,s=i?Gt:t,n=r?Vt:o;return i||r?{xKey:s,yKey:n,rows:e.map(e=>{const s={...e};return i&&(s[Gt]=t(e)),r&&(s[Vt]=o(e)),s})}:{rows:e,xKey:s,yKey:n}}(a,i,r);a=c.rows;const l=c.xKey,u=c.yKey,d=Array.isArray(e.annotations)?[...e.annotations]:[];let h,p="string"==typeof s||"function"==typeof s?s:void 0,m=e.baseLineStyle;if(e.forecast){const i=function(e,t,o,i,r){return(s=i).isTraining||s.isForecast||s.isAnomaly||s.upperBounds||s.lowerBounds?function(e,t,o,i,r){const{isTraining:s,isForecast:n,isAnomaly:a,upperBounds:c,lowerBounds:l,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:m}=i,g=e.map(e=>{let t="observed";return n&&Wt(e,n)?t="forecast":s&&Wt(e,s)&&(t="training"),{...e,[Dt]:t}}),f=i._groupBy,y=[];if(f){const e=new Map;for(const t of g){const o=t[f]??"__default";e.has(o)||e.set(o,[]),e.get(o).push(t)}const t=[];for(const[,o]of e)for(let e=0;o.length-1>e;e++)o[e][Dt]!==o[e+1][Dt]&&(t.push({...o[e+1],[Dt]:o[e][Dt]}),t.push({...o[e],[Dt]:o[e+1][Dt]}));y.push(...g,...t)}else for(let e=0;g.length>e;e++)y.push(g[e]),g.length-1>e&&g[e][Dt]!==g[e+1][Dt]&&(y.push({...g[e+1],[Dt]:g[e][Dt]}),y.push({...g[e],[Dt]:g[e+1][Dt]}));if(i.trainUnderline){const e=[];for(const t of y)"training"===t[Dt]&&e.push({...t,[Dt]:"training-base"});y.unshift(...e)}const b=[];if(c&&l){const e="string"==typeof c?c:"__envUpper",t="string"==typeof l?l:"__envLower";if("function"==typeof c||"function"==typeof l)for(const o of y)"function"==typeof c&&(o[e]=c(o)),"function"==typeof l&&(o[t]=l(o));b.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:m})}if(i.uncertaintyOpacity||i.confidenceAccessor){const e=c?"function"==typeof c?c:e=>e[c]:()=>{},t=l?"function"==typeof l?l:e=>e[l]:()=>{};$t(y.filter(e=>"forecast"===e[Dt]),i,e,t)}if(a){const e=i.anomalyStyle,t={type:"highlight",filter:e=>Wt(e,a)};e?(t.style=e,t.r=p):"function"==typeof h?(t.style=e=>{const t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=p):(t.color=h,t.r=p,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),b.push(t)}return r&&b.push({type:"anomaly-band",threshold:r.threshold??2,showBand:!1!==r.showBand,fill:r.bandColor||"#6366f1",fillOpacity:r.bandOpacity??.1,anomalyColor:r.anomalyColor||"#ef4444",anomalyRadius:r.anomalyRadius??6,label:r.label}),{processedData:y,annotations:b}}(e,0,0,i,r):function(e,t,o,i,r){const{trainEnd:s,steps:n=10,confidence:a=.95,color:c="#6366f1",bandOpacity:l=.15,label:u}=i;if(null==s)return{processedData:e,annotations:[]};const d=[],h=[];for(const o of e)o[t]>s?h.push({...o,[Dt]:"observed"}):d.push({...o,[Dt]:"training"});const p=d.map(e=>[e[t],e[o]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),m=[],g=[];if(p.length>=3){const r=p.length;let s=0,d=0,h=0,f=0;for(const[e,t]of p)s+=e,d+=t,h+=e*e,f+=e*t;const y=r*h-s*s;if(Math.abs(y)>1e-12){const h=(r*f-s*d)/y,b=(d-h*s)/r,x=e=>b+h*e,v=p.map(([e,t])=>t-x(e)).reduce((e,t)=>e+t*t,0),A=Math.sqrt(v/Math.max(r-2,1)),w=p.reduce((e,t)=>e+t[0],0)/r,S=p.reduce((e,t)=>e+(t[0]-w)**2,0),k=.99>a?.95>a?.9>a?1:1.645:1.96:2.576,_=e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e)),M=At(_),R=p.length>1?(p[r-1][0]-p[0][0])/(r-1):1;for(let e=1;n>=e;e++){const i=M+e*R,s=x(i),n=A*Math.sqrt(1+1/r+(S>0?(i-w)**2/S:0))*k;g.push({[t]:i,[o]:s,[Dt]:"forecast",__forecastUpper:s+n,__forecastLower:s-n})}$t(g,i,e=>e.__forecastUpper,e=>e.__forecastLower),m.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:c,fillOpacity:l,label:u})}}m.push({type:"x-threshold",x:s,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),r&&m.push({type:"anomaly-band",threshold:r.threshold??2,showBand:!1!==r.showBand,fill:r.bandColor||"#6366f1",fillOpacity:r.bandOpacity??.1,anomalyColor:r.anomalyColor||"#ef4444",anomalyRadius:r.anomalyRadius??6,label:r.label});const f=[];if(f.push(...d),d.length>0&&h.length>0&&f.push({...d[d.length-1],[Dt]:"observed"}),f.push(...h),g.length>0){const e=h.length>0?h[h.length-1]:d[d.length-1];e&&f.push({...e,[Dt]:"forecast"}),f.push(...g)}return{processedData:f,annotations:m}}(e,t,o,i,r);var s}(a,l,u,s&&"string"==typeof s&&"object"==typeof e.forecast?{...e.forecast,_groupBy:s}:e.forecast,e.anomaly);if(a=i.processedData,d.push(...i.annotations),h=function(e,t,o){const i=o.upperBounds,r=o.lowerBounds;if(!i&&!r)return;const s="function"==typeof i?i:"string"==typeof i?e=>e[i]:null,n="function"==typeof r?r:"string"==typeof r?e=>e[r]:null;let a=1/0,c=-1/0;for(const o of e){const e=Number(o[t]);if(Number.isFinite(e)&&(a>e&&(a=e),e>c&&(c=e)),s){const e=s(o);null!=e&&Number.isFinite(e)&&(e>c&&(c=e),a>e&&(a=e))}if(n){const e=n(o);null!=e&&Number.isFinite(e)&&(a>e&&(a=e),e>c&&(c=e))}}return Number.isFinite(a)&&Number.isFinite(c)?[a,c]:void 0}(a,u,e.forecast),s&&"string"==typeof s?(a=a.map(e=>({...e,[Ht]:`${e[s]}__${e[Dt]||"observed"}`})),p=Ht):p=Dt,e.baseLineStyle){const i=function(i,r){const s=r.trainDasharray??"8,4",n=r.forecastDasharray??"4,4",a=r.color||"#6366f1",c=r.trainOpacity,l=r.forecastOpacity,u=r.trainStroke,d=r.trainLinecap,h=r.trainUnderline;return i=>{const r=(t=>e.baseLineStyle(t))(i),p=i[Dt];if("training"===p){let e=r.stroke;return"darken"===u?e=t(r.stroke||"#666",.5):u&&(e=u),{...r,stroke:e,strokeDasharray:s,...d&&{strokeLinecap:d},...null!=c&&{strokeOpacity:c}}}if("training-base"===p){let e=r.stroke||"#666";return"lighten"===h&&(e=o(e,.4)),{...r,stroke:e,strokeDasharray:void 0}}if("forecast"===p){const e=i[Nt],t=null!=e?e:l;return{...r,stroke:a,strokeDasharray:n,...null!=t&&{strokeOpacity:t}}}return r}}(0,e.forecast);m=e=>i(e)}}else e.anomaly&&d.push(...(g=e.anomaly,[{type:"anomaly-band",threshold:g.threshold??2,showBand:!1!==g.showBand,fill:g.bandColor||"#6366f1",fillOpacity:g.bandOpacity??.1,anomalyColor:g.anomalyColor||"#ef4444",anomalyRadius:g.anomalyRadius??6,label:g.label}]));var g;if(e.gapStrategy){if("function"==typeof p){const e=p;a=a.map(t=>({...t,__semiotic_gapGroup:e(t)})),p="__semiotic_gapGroup"}const t=function(e,t,o,i,r){const s=new Map;for(const t of e){const e=r?(t[r]??"")+"":"__single";s.has(e)||s.set(e,[]),s.get(e).push(t)}if("interpolate"===t){const e=[];for(const[,t]of s)for(const r of t)Yt(r,o,i)||e.push(r);return{rows:e,groupKey:r}}if("zero"===t){const e=[];for(const[,t]of s)for(const r of t)Yt(r,o,i)?e.push({...r,[i]:0}):e.push(r);return{rows:e,groupKey:r}}const n=[],a="_gapSegment";for(const[e,t]of s){let r=0,s=[];const c=()=>{if(0===s.length)return;const t="__single"===e?"__seg"+r:`${e}__seg${r}`;for(const e of s)n.push({...e,[a]:t});s=[],r++};for(const e of t)Yt(e,o,i)?c():s.push(e);c()}return{rows:n,groupKey:a}}(a,e.gapStrategy,l,u,"string"==typeof p?p:void 0);a=t.rows,t.groupKey&&(p=t.groupKey)}let f;if(e.directLabel){const t=function(e,t,o,i,r,s,n,a){if(!t||!o)return{annotations:[]};const c="object"==typeof t?t:{},l=c.position||"end",u=c.fontSize||11,d="function"==typeof o?o:e=>e[o],h=new Map;for(const t of e){const e=d(t);if(null==e)continue;const o=e+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(t))}const p=new Map;for(const[e,t]of h)t.sort((e,t)=>Number(e[i])-Number(t[i])),p.set(e,"end"===l?t[t.length-1]:t[0]);const m=me(Array.from(p.entries()).map(([e])=>({__lbl:e})),"__lbl",s??n),g=Array.from(p.entries()).map(([e,t])=>({type:"text",label:e,[i]:t[i],[r]:t[r],dx:"end"===l?6:-6,dy:0,color:m?ye({__lbl:e},"__lbl",m):a||ie,fontSize:u}));g.sort((e,t)=>Number(e[r])-Number(t[r]));for(let e=1;g.length>e;e++){const t=g[e-1],o=g[e],i=Number(t[r])+t.dy;u+2>Math.abs(Number(o[r])+o.dy-i)&&(o.dy+=u+2)}const f=g.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===l?{right:f}:{left:f}}}(a,e.directLabel,"string"==typeof n||"function"==typeof n?n:void 0,l,u,e.colorScheme,e.themeCategorical,e.color);d.push(...t.annotations),f=t.marginExtra}return{data:a,xAccessor:"function"==typeof i?l:i,yAccessor:"function"==typeof r?u:r,groupAccessor:p,colorAccessor:n,annotations:d,lineStyle:m,yExtent:h,marginExtra:f}}import{forwardRef as qt,useCallback as Ut,useMemo as Qt}from"react";import{forwardRef as Kt,useMemo as Zt}from"react";import{useMemo as Jt,useRef as eo}from"react";import{useCallback as to,useMemo as oo,useState as io}from"react";import{useMemo as ro}from"react";import{useImperativeHandle as so,useRef as no}from"react";function ao(e){const t=eo(null);return function(e,t){const{variant:o,frameRef:i,overrides:r}=t,s=no(r);s.current=r,so(e,()=>{const e=function(e,t){if("xy"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.remove(t)??[],update:(t,o)=>e.current?.update(t,o)??[],replace:t=>e.current?.replace?.(t),clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getScales:()=>e.current?.getScales()??null,getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("network"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>{const o=Array.isArray(t)?t:[t],i=e.current?.getTopology()?.nodes??[],r=[];for(const t of o){const o=i.find(e=>e.id===t);o&&r.push({...o.data??{},id:t}),e.current?.removeNode(t)}return r},update:(t,o)=>(Array.isArray(t)?t:[t]).flatMap(t=>{const i=e.current?.updateNode(t,o);return i?[{...i,id:t}]:[]}),clear:()=>e.current?.clear(),getData:()=>e.current?.getTopology()?.nodes?.map(e=>e.data)??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("geo-points"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.removePoint(t)??[],update:(t,o)=>{const i=e.current?.removePoint(t)??[];for(const t of i)e.current?.push(o(t));return i},clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}const o=t;return{push:e=>o.current?.pushLine(e),pushMany:e=>o.current?.pushManyLines(e),remove:e=>o.current?.removeLine(e)??[],update:(e,t)=>{const i=o.current?.removeLine(e)??[];for(const e of i)o.current?.pushLine(t(e));return i},clear:()=>o.current?.clear(),getData:()=>o.current?.getLines()??[],getCustomLayout:()=>o.current?.getCustomLayout?.()??null,getLayoutFailure:()=>o.current?.getLayoutFailure?.()??null}}(o,i);return new Proxy(e,{get(e,t,o){if("string"==typeof t){const e=s.current?.[t];if("function"==typeof e)return e}return Reflect.get(e,t,o)},has:(e,t)=>!("string"!=typeof t||!s.current||!(t in s.current))||Reflect.has(e,t)})},[])}(e.imperativeRef,{variant:e.imperativeVariant,frameRef:t}),{frameRef:t,resolved:qe(e.mode,{width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,xLabel:e.xLabel,yLabel:e.yLabel,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules}),normalizedMargin:Jt(()=>Tt(e.margin),[e.margin])}}import{jsx as co}from"react/jsx-runtime";var lo=Kt(function(e,t){const{data:o,layout:i,layoutConfig:r,onLayoutError:s,xExtent:n,yExtent:a,showAxes:c=!1,margin:l,className:u,annotations:d,onObservation:h,onClick:p,selection:m,linkedHover:g,hoverHighlight:f,chartId:y,loading:b,loadingContent:x,emptyContent:v,colorBy:A,colorScheme:w,legend:S,legendInteraction:k,legendPosition:_,frameProps:R={}}=e,{legend:I,...T}=R,C=Zt(()=>de(I,S),[I,S]),{frameRef:z,resolved:O,safeData:F,setup:B,earlyReturn:E}=function(e){const t=ao(e),{resolved:o,normalizedMargin:i}=t,r=function(e){const{data:t,rawData:o,colorBy:i,colorScheme:r,legendInteraction:s,legendPosition:n,selection:a,linkedHover:c,fallbackFields:l,unwrapData:u=!1,onObservation:d,chartType:h,chartId:p,showLegend:m,legend:g,legendLayout:f,userMargin:y,marginDefaults:b,onClick:x,hoverHighlight:v,mobileInteraction:A,mobileSemantics:w,loading:S,loadingContent:k,emptyContent:_,width:M,height:R,hasTitle:P}=e,L=void 0===o,I=oo(()=>ge(t),[t]),[T,C]=io([]),z=to(e=>{C(t=>t.length===e.length&&t.every((t,o)=>t===e[o])?t:e)},[]),O="string"==typeof e.colorBy?e.colorBy:void 0,F=oo(()=>Ge(A,{width:M,mobileSemantics:w}),[A,M,w]),{activeSelectionHook:B,hoverSelectionHook:E,customHoverBehavior:j,customClickBehavior:D,crosshairSourceId:N}=Ue({selection:a,linkedHover:c,fallbackFields:l,unwrapData:u,onObservation:d,chartType:h,chartId:p,onClick:x,hoverHighlight:v,colorByField:O,mobileInteraction:F}),$=be(c,N),W=Qe(I,i,r),G=oo(()=>{if(!i)return[];const e=new Set;for(const t of I){const o="function"==typeof i?i(t):t[i];null!=o&&e.add(o+"")}return Array.from(e)},[I,i]),V=oo(()=>L&&T.length>0?T:G,[L,T,G]),H=Ke(s,i,V),Y=oo(()=>E||(H.legendSelectionHook?H.legendSelectionHook:B),[E,H.legendSelectionHook,B]),X=function(e){const t=It(e=>e.theme.colors.selectionOpacity);return ro(()=>{if(void 0!==e||void 0!==t)return{name:e?.name??"",...e,unselectedOpacity:e?.unselectedOpacity??t}},[e,t])}(a),q=Ze(),U=Ye(),Q=oo(()=>{if(W)return W;if(!i||0===V.length)return;const e=Array.isArray(r)&&r.length>0||"string"==typeof r&&r.length>0?r:q&&q.length>0?q:ne,t="__streamCat",o=V.map(e=>({[t]:e})),s=me(o,t,e);return e=>U?.[e]||s(e)||"#999"},[W,i,V,r,q,U]),{legend:K,margin:Z,legendPosition:J}=Xe({data:I,colorBy:i,colorScale:Q,showLegend:m,legendPosition:n,userMargin:y,defaults:b,categories:V,additionalLegend:g,chartWidth:M,legendLayout:f,hasTitle:P}),ee=oo(()=>{const e={};return K&&(e.legend=K,e.legendPosition=J,f&&(e.legendLayout=f)),s&&"none"!==s&&(e.legendHoverBehavior=H.onLegendHover,e.legendClickBehavior=H.onLegendClick,e.legendHighlightedCategory=H.highlightedCategory,e.legendIsolatedCategories=H.isolatedCategories),L&&i&&(e.legendCategoryAccessor=i,e.onCategoriesChange=z),e},[K,J,f,s,H.onLegendHover,H.onLegendClick,H.highlightedCategory,H.isolatedCategories,L,i,z]),te=Array.isArray(o)?ge(o):o,oe=ze(S,M,R,k),ie=oe?null:Ce(te,M,R,_);return{data:I,colorScale:W,allCategories:V,legendState:H,effectiveSelectionHook:Y,activeSelectionHook:B,customHoverBehavior:j,customClickBehavior:D,mobileInteraction:F,legend:K,margin:Z,legendPosition:J,earlyReturn:oe||ie||null,legendBehaviorProps:ee,crosshairProps:$,resolvedSelection:X}}({data:e.data??[],rawData:e.data,colorBy:e.colorBy,colorScheme:e.colorScheme,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,selection:e.selection,linkedHover:e.linkedHover,hoverHighlight:e.hoverHighlight,fallbackFields:"string"==typeof e.colorBy?[e.colorBy]:[],unwrapData:e.unwrapData,onObservation:e.onObservation,onClick:e.onClick,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,chartType:e.chartTypeLabel,chartId:e.chartId,showLegend:o.showLegend,legend:e.legend,userMargin:i,marginDefaults:o.marginDefaults,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,width:o.width,height:o.height});return{...t,safeData:r.data,setup:r,earlyReturn:r.earlyReturn}}({imperativeRef:t,imperativeVariant:"xy",chartTypeLabel:"XYCustomChart",unwrapData:!1,data:o,colorBy:A,colorScheme:w,legend:C,legendInteraction:k,legendPosition:_,selection:m,linkedHover:g,hoverHighlight:f,onObservation:h,onClick:p,chartId:y,loading:b,loadingContent:x,emptyContent:v,margin:l,width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mode:e.mode,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules,xLabel:e.xLabel,yLabel:e.yLabel}),j=B.effectiveSelectionHook,D=Zt(()=>j?.isActive?{isActive:!0,predicate:j.predicate}:null,[j?.isActive,j?.predicate]);if(E)return E;const{width:N,height:$,enableHover:W,showGrid:G,title:V,description:H,summary:Y,accessibleTable:X,xLabel:q,yLabel:U}=O,Q={chartType:"custom",...null!=o&&{data:F},customLayout:i,layoutConfig:r,onLayoutError:s,...D&&{layoutSelection:D},xExtent:n,yExtent:a,colorAccessor:A,colorScheme:w,size:[N,$],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:B.margin,showAxes:c,xLabel:q,yLabel:U,enableHover:W,showGrid:G,...B.legendBehaviorProps,...P({title:V,description:H,summary:Y,accessibleTable:X,className:u,animate:e.animate,axisExtent:e.axisExtent,autoPlaceAnnotations:e.autoPlaceAnnotations}),...null!=e.tooltip&&{tooltipContent:e.tooltip},...L({linkedHover:g,selection:m,onObservation:h,onClick:p,hoverRadius:e.hoverRadius,hoverHighlight:f,mobileInteraction:B.mobileInteraction,customHoverBehavior:B.customHoverBehavior,customClickBehavior:B.customClickBehavior}),...d&&d.length>0&&{annotations:d},...B.crosshairProps,...T};return co(ae,{componentName:"XYCustomChart",width:N,height:$,children:co(M,{ref:z,...Q})})});function uo(e,t,o,i,r){const s=1-r;return s*s*s*e+3*s*s*r*t+3*s*r*r*o+r*r*r*i}function ho(e,t,o,i,r){const s=1-r;return 3*s*s*(t-e)+6*s*r*(o-t)+3*r*r*(i-o)}function po(e,t,o,i,r){const s=[],n=(e.x+t.x)/2;for(let a=0;r>=a;a++){const c=a/r;let l,u,d,h;"linear"===i?(l=e.x+(t.x-e.x)*c,u=e.y+(t.y-e.y)*c,d=t.x-e.x,h=t.y-e.y):(l=uo(e.x,n,n,t.x,c),u=uo(e.y,e.y,t.y,t.y,c),d=ho(e.x,n,n,t.x,c),h=ho(e.y,e.y,t.y,t.y,c)),s.push({x:l,y:u,dx:d,dy:h,radius:e.radius+(t.radius-e.radius)*c,datumIndex:.5>c?o:o+1})}return s}function mo(e,t={}){const o=[],i=[],r=[];if(2>e.length)return{topPath:o,bottomPath:i,datumIndices:r};const s=t.curve??"smooth",n=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;e.length-1>t;t++){const a=po(e[t],e[t+1],t,s,n);for(let e=0===t?0:1;a.length>e;e++){const t=a[e],s=Math.hypot(t.dx,t.dy)||1,n=-t.dy/s,c=t.dx/s,l=Math.max(0,t.radius);o.push([t.x+n*l,t.y+c*l]),i.push([t.x-n*l,t.y-c*l]),r.push(t.datumIndex)}}return{topPath:o,bottomPath:i,datumIndices:r}}lo.displayName="XYCustomChart";import{jsx as go,jsxs as fo}from"react/jsx-runtime";function yo(e,t,o){return"function"==typeof e?e(t,o):t[e]}function bo(e){return e instanceof Date?"date:"+e.getTime():`${typeof e}:${e+""}`}function xo(e,t){if(!e?.length)return;const o=new Map(t.map((e,t)=>[bo(e),t]));return e.map(e=>{const t={...e},i=i=>{if(!(i in e))return;const r=o.get(bo(e[i]));void 0!==r&&(t[i]=r)};return i("x"),i("x0"),i("x1"),"string"!=typeof e.type||"x-threshold"!==e.type&&"x"!==e.type||i("value"),t})}function vo(e){const{seriesOrder:t,overallOrder:o,highlightTop:i,color:r,colorScheme:s,neutralColor:n,themeCategorical:a,themeNeutral:c}=e;if(null==i&&null==r)return s;const l=new Set(o.slice(0,null==i?o.length:Math.max(0,Math.floor(i)))),u=new Map,d={};for(const e of t)d[e]=r??(l.has(e)?je(void 0,a,s,e,u):n??c??"#b8bec8");return d}function Ao(e,t={}){const o=t.xAccessor??"x",i=t.yAccessor??"y",r=t.lineBy??"series",s=t.rankDirection??"descending",n=[],a=new Map,c=new Map,l=[],u=new Map;let d=1/0,h=-1/0;e.forEach((e,t)=>{const s=yo(o,e,t),p=bo(s);let m=a.get(p);null==m&&(m=n.length,a.set(p,m),n.push(s),c.set(m,[]));const g=yo(r,e,t)+"";u.has(g)||(u.set(g,l.length),l.push(g));const f=Number(yo(i,e,t));Number.isFinite(f)&&(d=Math.min(d,f),h=Math.max(h,f),c.get(m)?.push({datum:e,inputIndex:t,series:g,value:f}))});const p=[],m=new Map,g=new Map;for(let e=0;n.length>e;e++){const t=c.get(e)??[];t.sort((e,t)=>("descending"===s?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,o)=>{const i=o+1;p.push({datum:t.datum,xIndex:e,xValue:n[e],series:t.series,value:t.value,rank:i}),m.set(t.series,(m.get(t.series)??0)+i),g.set(t.series,(g.get(t.series)??0)+1)})}const f=l.length+1,y=[...l].sort((e,t)=>{const o=g.get(e)??0,i=g.get(t)??0;return((m.get(e)??0)+(n.length-o)*f)/Math.max(1,n.length)-((m.get(t)??0)+(n.length-i)*f)/Math.max(1,n.length)||(u.get(e)??0)-(u.get(t)??0)}),b=new Set(y.slice(0,null==t.highlightTop?y.length:Math.max(0,Math.floor(t.highlightTop))));return{data:p.map(e=>{const t=b.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:n,seriesOrder:l,overallOrder:y,valueExtent:d===1/0?[0,0]:[d,h]}}function wo({datum:e,x:t,y:o,side:i,color:r,highlighted:s,labelStyle:n}){const a=te(),c=a.isActive&&!a.predicate(e),l="function"==typeof n?n(e.__bumpRaw):n;return go("text",{className:"semiotic-bump-label",x:t+("end"===i?8:-8),y:o,dy:"0.35em",textAnchor:"end"===i?"start":"end",fill:r,fillOpacity:c?.16:1,fontWeight:s?650:450,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 11px)",...l},children:e.__bumpSeries})}function So(e,t,o){const[i,r]=t,[s,n]=o;return r===i?(s+n)/2:s+(n-s)*Math.max(0,Math.min(1,(e-i)/(r-i)))}function ko(e){const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?t:void 0}function _o(e){return{value:e.__bumpValue,x:ko(e.__bumpXValue),y:e.__bumpValue,category:e.__bumpSeries}}function Mo(e){const t=e.config,o=new Map;for(const t of e.data){const e=o.get(t.__bumpSeries)??[];e.push(t),o.set(t.__bumpSeries,e)}const i=t.seriesOrder.filter(e=>o.has(e)).sort((e,i)=>(o.get(e)?.[0]?.__bumpHighlighted?1:0)-(o.get(i)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(i)),r=[],s=[];for(const n of i){const i=(o.get(n)??[]).sort((e,t)=>e.x-t.x);if(2>i.length)continue;const a=i[0].__bumpHighlighted,c=e.resolveColor(i[0].__bumpSeries,i[0]),l=t.color??(a?c:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??c),u=i.map(o=>({x:e.scales.x(o.x),y:e.scales.y(o.y),radius:t.ribbon?So(o.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=mo(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h=d.datumIndices.map(e=>i[e]),p={fill:l,fillOpacity:1,opacity:a?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(p,A(i[0].__bumpRaw,t.styleRules,_o(i[0]))),t.areaStyle&&Object.assign(p,t.areaStyle(i[0].__bumpRaw)??{}),void 0!==t.stroke&&(p.stroke=t.stroke),void 0!==t.strokeWidth&&(p.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(p.opacity=t.opacity),r.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:p,datum:h,accessibleDatum:i.map(e=>e.__bumpRaw),accessibility:{label:n+" ranking trajectory",tableFields:i.map(e=>e.__bumpRaw)},group:n,interactive:!0}),t.showPoints&&i.forEach((e,o)=>{const i={fill:l,stroke:"none",opacity:a?1:.75};t.styleRules?.length&&Object.assign(i,A(e.__bumpRaw,t.styleRules,_o(e))),t.pointStyle&&Object.assign(i,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(i.stroke=t.stroke),void 0!==t.strokeWidth&&(i.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(i.opacity=t.opacity),r.push({type:"point",x:u[o].x,y:u[o].y,r:i.r??t.pointRadius,style:i,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${n}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${n}:${e.x}`})});const m=!0===t.showLabels?"end":t.showLabels,g=(e,o,i)=>{s.push(go(wo,{datum:e,x:u[o].x,y:u[o].y,side:i,color:"string"==typeof p.fill?p.fill:l,highlighted:a,labelStyle:t.labelStyle},`${n}-${i}`))};"start"!==m&&"both"!==m||g(i[0],0,"start"),"end"!==m&&"both"!==m||g(i.at(-1),i.length-1,"end")}return{nodes:r,overlays:s.length?go("g",{className:"semiotic-bump-labels",children:s}):void 0,restyle:(e,t)=>{const o=function(e){const t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&o&&!t.predicate(o))return{opacity:.14}}}}function Ro(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Et(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrAreaColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrAreaColorBy:t(e)})):s,u=t?me(l,c,a):void 0,d=!1!==r.showLine,h="number"==typeof r.lineWidth?r.lineWidth:2,p="number"==typeof r.areaOpacity?r.areaOpacity:.7,m=x(r.yAccessor),g=r.styleRules;return(e,o)=>{const i=t&&u?ye(e,t,u):"string"==typeof r.color?r.color:ie,s={fill:i,fillOpacity:p,stroke:d?i:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(s,A(e,g,{value:m(e),category:o})),void 0!==r.stroke&&(s.stroke=r.stroke),void 0!==r.strokeWidth&&(s.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(s.opacity=r.opacity),s}}function Po(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Et(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrBubbleColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrBubbleColorBy:t(e)})):s,u=t?me(l,c,a):void 0,d=r.sizeBy,h=Array.isArray(r.sizeRange)?r.sizeRange:[5,40],p=d?s.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],m=p.length?St(p):void 0;return e=>({fill:t&&u?ye(e,t,u):"string"==typeof r.color?r.color:ie,fillOpacity:"number"==typeof r.bubbleOpacity?r.bubbleOpacity:.6,r:d?xe(e,d,h,m):h[0],stroke:r.stroke??r.bubbleStrokeColor??"white",strokeWidth:r.strokeWidth??r.bubbleStrokeWidth??1,...void 0!==r.opacity&&{opacity:r.opacity}})}function Lo(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Et(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrScatterColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrScatterColorBy:t(e)})):s,u=t?me(l,c,a):void 0,d=r.sizeBy,h=Array.isArray(r.sizeRange)?r.sizeRange:[3,15],p=d?s.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],m=p.length?St(p):void 0,g=v(r.xAccessor,r.yAccessor),f=r.styleRules;return e=>{const o={fill:t&&u?ye(e,t,u):"string"==typeof r.color?r.color:ie,fillOpacity:"number"==typeof r.pointOpacity?r.pointOpacity:.8,r:d?xe(e,d,h,m):"number"==typeof r.pointRadius?r.pointRadius:5};return f?.length&&Object.assign(o,A(e,f,g(e))),void 0!==r.stroke&&(o.stroke=r.stroke),void 0!==r.strokeWidth&&(o.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(o.opacity=r.opacity),o}}qt(function(e,t){const o=Ze(),i=et(),{data:r,xAccessor:s,yAccessor:n,lineBy:a,rankDirection:c="descending",ribbon:l=!1,curve:u="smooth",ribbonSizeRange:d=[4,28],samplesPerSegment:h=12,lineWidth:p=3,highlightTop:m,neutralColor:g,styleRules:f,labelStyle:y,colorScheme:b,ribbonOpacity:x=.82,lineOpacity:v=.9,showPoints:A=!1,pointRadius:w=3,showLabels:S=!0,showAxes:k=!0,showGrid:_=!0,showLegend:M=!1,enableHover:R=!0,hoverHighlight:P=!0,tooltip:L,frameProps:I={},xFormat:T,yFormat:C,onClick:z}=e,O=Qt(()=>Ao(r,{xAccessor:s,yAccessor:n,lineBy:a,rankDirection:c,highlightTop:m}),[r,s,n,a,c,m]),{axes:F,areaStyle:B,pointStyle:E,...j}=I,D=Qt(()=>vo({seriesOrder:O.seriesOrder,overallOrder:O.overallOrder,highlightTop:m,color:e.color,colorScheme:b,neutralColor:g,themeCategorical:o,themeNeutral:i.colors.textSecondary}),[O.seriesOrder,O.overallOrder,m,e.color,b,g,o,i.colors.textSecondary]),N=Qt(()=>({ribbon:l,curve:u,samplesPerSegment:h,ribbonSizeRange:d,valueExtent:O.valueExtent,seriesOrder:O.seriesOrder,lineWidth:p,ribbonOpacity:x,lineOpacity:v,neutralColor:g,color:e.color,stroke:e.stroke,strokeWidth:e.strokeWidth,opacity:e.opacity,styleRules:f,areaStyle:B,pointStyle:E,labelStyle:y,showPoints:A,pointRadius:w,showLabels:S}),[l,u,h,d,O.valueExtent,O.seriesOrder,p,x,v,g,e.color,e.stroke,e.strokeWidth,e.opacity,f,B,E,y,A,w,S]),$=Ut((e,t)=>{if(0===O.xValues.length)return"";const o=O.xValues[Math.max(0,Math.min(O.xValues.length-1,Math.round(Number(e))))];return T?T(o,t):(o instanceof Date?o.toLocaleDateString():o)+""},[O.xValues,T]),W=Ut(e=>C?C(e):e.toLocaleString(),[C]),G=Qt(()=>"multi"===L?void 0:rt(L),[L]),V=Ut(e=>{const t=e?.data??e;return t?!1===L?null:G?G({...e,data:t.__bumpRaw,__semioticHoverData:!0}):fo("div",{className:"semiotic-tooltip",style:ot,children:[go("div",{style:{fontWeight:700},children:t.__bumpSeries}),fo("div",{children:[$(t.x)," · Rank ",t.__bumpRank]}),fo("div",{children:["Value: ",W(t.__bumpValue)]})]}):null},[W,$,G,L]),H=Qt(()=>{if(z)return(e,t)=>{z(e.__bumpRaw??e,t)}},[z]),Y=Math.max(1,O.seriesOrder.length),X=O.xValues.map((e,t)=>t),q=Array.from({length:Y},(e,t)=>t+1),U=F??[{orient:"left",tickValues:q,tickFormat:e=>e+"",label:e.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:X,tickFormat:$,label:e.xLabel,tickAnchor:"edges"}],Q=Qt(()=>xo(e.annotations,O.xValues),[e.annotations,O.xValues]);return go(lo,{ref:t,data:O.data,layout:Mo,layoutConfig:N,xExtent:[0,Math.max(1,O.xValues.length-1)],yExtent:[Y+.5,.5],showAxes:k,showGrid:_,showLegend:M,enableHover:R,hoverHighlight:P,colorBy:"__bumpSeries",colorScheme:D,tooltip:V,onClick:H,hoverRadius:e.hoverRadius,width:e.width,height:e.height,responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,responsiveRules:e.responsiveRules,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,mode:e.mode,margin:e.margin??{top:20,right:S?110:24,bottom:48,left:48},className:e.className,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,selection:e.selection,linkedHover:e.linkedHover,legend:e.legend,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,onObservation:e.onObservation,chartId:e.chartId,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,animate:e.animate,autoPlaceAnnotations:e.autoPlaceAnnotations,annotations:Q,xLabel:e.xLabel,yLabel:e.yLabel??"Rank",frameProps:{axes:U,axisExtent:"exact",...j}})}).displayName="BumpChart";var Io={frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,sizeRange:r.sizeRange||[5,40],colorScheme:o,...i,pointStyle:i.pointStyle||Po(e,t,o,i,r),showLegend:i.showLegend??!!t})},To={frameType:"xy",layout:{margin:e=>({top:20,right:!1===e.showLabels?24:110,bottom:48,left:48})},buildProps:(e,t,o,i,r)=>{const s=Ao(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],{xAccessor:r.xAccessor,yAccessor:r.yAccessor,lineBy:r.lineBy,rankDirection:r.rankDirection,highlightTop:"number"==typeof r.highlightTop?r.highlightTop:void 0}),n=Math.max(1,s.seriesOrder.length),a=Et(i.theme),c=vo({seriesOrder:s.seriesOrder,overallOrder:s.overallOrder,highlightTop:"number"==typeof r.highlightTop?r.highlightTop:void 0,color:"string"==typeof r.color?r.color:void 0,colorScheme:o,neutralColor:"string"==typeof r.neutralColor?r.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),l={ribbon:!0===r.ribbon,curve:"linear"===r.curve?"linear":"smooth",samplesPerSegment:"number"==typeof r.samplesPerSegment?r.samplesPerSegment:12,ribbonSizeRange:Array.isArray(r.ribbonSizeRange)?r.ribbonSizeRange:[4,28],valueExtent:s.valueExtent,seriesOrder:s.seriesOrder,lineWidth:"number"==typeof r.lineWidth?r.lineWidth:3,ribbonOpacity:"number"==typeof r.ribbonOpacity?r.ribbonOpacity:.82,lineOpacity:"number"==typeof r.lineOpacity?r.lineOpacity:.9,neutralColor:"string"==typeof r.neutralColor?r.neutralColor:void 0,color:"string"==typeof r.color?r.color:void 0,stroke:"string"==typeof r.stroke?r.stroke:void 0,strokeWidth:"number"==typeof r.strokeWidth?r.strokeWidth:void 0,opacity:"number"==typeof r.opacity?r.opacity:void 0,styleRules:r.styleRules,areaStyle:i.areaStyle,pointStyle:i.pointStyle,labelStyle:r.labelStyle,showPoints:!0===r.showPoints,pointRadius:"number"==typeof r.pointRadius?r.pointRadius:3,showLabels:r.showLabels??!0},u=i.xFormat,d=(e,t)=>{if(0===s.xValues.length)return"";const o=s.xValues[Math.max(0,Math.min(s.xValues.length-1,Math.round(Number(e))))];return u?u(o,t):(o instanceof Date?o.toLocaleDateString():o)+""},h=s.xValues.map((e,t)=>t),p=Array.from({length:n},(e,t)=>t+1),m=i.axes??[{orient:"left",tickValues:p,tickFormat:e=>e+"",label:i.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:i.xLabel,tickAnchor:"edges"}];return{...i,chartType:"custom",data:s.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,s.xValues.length-1)],yExtent:[n+.5,.5],customLayout:Mo,layoutConfig:l,colorAccessor:"__bumpSeries",colorScheme:c,xFormat:d,axes:m,axisExtent:"exact",showAxes:i.showAxes??!0,showLegend:i.showLegend??!1,annotations:xo(i.annotations,s.xValues)}}};function Co(e,t,o,i,r){if(!r.showPoints)return;const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Et(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrPointColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrPointColorBy:t(e)})):s,u=t?me(l,c,a):void 0,d="number"==typeof r.pointRadius?r.pointRadius:3;return e=>{const o=t&&u?ye(e,t,u):"string"==typeof r.color?r.color:ie;return{r:d,fill:o,stroke:"none"}}}var zo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.lineBy,n=r.fillArea,a=Array.isArray(n)?"mixed":n?"area":"line",c=Et(i.theme).colors.categorical,l=function(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Et(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrLineColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrLineColorBy:t(e)})):s,u=t?me(l,c,a):void 0,d=v(r.xAccessor,r.yAccessor),h=function(e){const{lineWidth:t=2,colorBy:o,colorScale:i,color:r,resolveStroke:s,fillArea:n,areaOpacity:a=.3,styleRules:c,ruleContext:l}=e;return(e,u)=>{const d={strokeWidth:t},h=!0===n||Array.isArray(n)&&null!=u&&n.includes(u);let p;return s?p=s(e,u):o?i&&(p=ye(e,o,i)):p=r||ie,void 0!==p&&(d.stroke=p,h&&(d.fill=p,d.fillOpacity=a)),c?.length&&Object.assign(d,A(e,c,l?l(e,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof r.lineWidth?r.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof r.color?r.color:void 0,fillArea:r.fillArea,areaOpacity:"number"==typeof r.areaOpacity?r.areaOpacity:.3,styleRules:r.styleRules,ruleContext:d});return function(e,t){if(!function(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}(t))return e??((...e)=>({}));const o={};return void 0!==t.stroke&&(o.stroke=t.stroke),void 0!==t.strokeWidth&&(o.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(o.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...o}):(...e)=>({...o})}(h,{stroke:"string"==typeof r.stroke?r.stroke:void 0,strokeWidth:"number"==typeof r.strokeWidth?r.strokeWidth:void 0,opacity:"number"==typeof r.opacity?r.opacity:void 0})}(e,s,o,i,r),u=Xt({data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",lineBy:r.lineBy,colorBy:s,colorScheme:o,color:"string"==typeof r.color?r.color:void 0,forecast:r.forecast,anomaly:r.anomaly,gapStrategy:r.gapStrategy,directLabel:r.directLabel,annotations:i.annotations,themeCategorical:c,baseLineStyle:l}),d=i.pointStyle||Co(u.data,u.colorAccessor,o,i,r);let h=i.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const p=(!r.directLabel||void 0!==i.showLegend)&&(i.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||l,...Array.isArray(n)&&{areaGroups:n},...n&&null!=r.areaOpacity&&{areaOpacity:r.areaOpacity},...null!=r.band&&{band:r.band},...i,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!i.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:p}}},Oo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=Array.isArray(e)?ge(e):[],n=r.timeAccessor||"time",a=r.valueAccessor||"value",c=r.categoryAccessor,l=r.valueExtent||i.yExtent,u="down"===r.direction?X({data:s,timeAccessor:n,valueAccessor:a,binSize:Number(r.binSize),valueExtent:l,extentPadding:r.extentPadding}):l,d={...void 0!==r.fill&&{fill:r.fill},...void 0!==r.stroke&&{stroke:r.stroke},...void 0!==r.strokeWidth&&{strokeWidth:r.strokeWidth},...void 0!==r.opacity&&{opacity:r.opacity},...void 0!==r.gap&&{gap:r.gap}};return{chartType:"bar",data:s,...i,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,s.length),arrowOfTime:r.arrowOfTime||"right",timeAccessor:n,valueAccessor:a,xExtent:r.timeExtent||i.xExtent,yExtent:u,extentPadding:r.extentPadding??i.extentPadding,binSize:r.binSize,categoryAccessor:c,barColors:r.colors||i.barColors,colorScheme:r.colors||i.colorScheme,barStyle:i.barStyle||d,showLegend:i.showLegend??!!c}}},Fo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.areaBy,n=function({data:e,safeData:t,areaBy:o,lineDataAccessor:i}){if(null==e)return[];const r=void 0!==t[0]?.[i];if(!r&&!o)return t;let s;if(r)s=t;else{const e=t.reduce((e,t)=>{const r="function"==typeof o?o(t):t[o],s=r+"";if(!e[s]){const t={[i]:[]};"string"==typeof o&&(t[o]=r),e[s]=t}return e[s][i].push(t),e},{});s=Object.values(e)}return s.flatMap(e=>{const t=Array.isArray(e[i])?e[i]:[];return"string"==typeof o?t.map(t=>({...t,[o]:t[o]??e[o]})):t})}({data:e,safeData:Array.isArray(e)?ge(e):[],areaBy:r.areaBy,lineDataAccessor:r.lineDataAccessor||"coordinates"}),a=G(r.semanticGradient),c=a?.stops.length?q(a):W(i.gradientFill),l=!1!==r.semanticLine&&a?.stops.length?a.stops.flatMap(({offset:e,color:t})=>t?[{offset:e,color:t}]:[]):void 0,u=i.pointStyle||Co(n,s,o,i,r);return{chartType:"area",data:n,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",y0Accessor:r.y0Accessor,groupAccessor:r.areaBy||void 0,colorAccessor:s,colorScheme:o,...i,...void 0!==c&&{gradientFill:c},...l&&{semanticLineStops:l},lineStyle:i.lineStyle||Ro(n,s,o,i,r),...u&&{pointStyle:u}}}},Bo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=r.xAccessor||"x",n=r.seriesAAccessor||"a",a=r.seriesBAccessor||"b",c=e=>Ft(Ot(s,"x",e)),l=e=>Ft(Ot(n,"a",e)),u=e=>Ft(Ot(a,"b",e)),d=r.seriesAColor||"var(--semiotic-danger, #dc2626)",h=r.seriesBColor||"var(--semiotic-info, #2563eb)",p=r.areaOpacity??.6,m=r.lineWidth??1.5,g=!1!==r.showLines,f=!1!==i.showLegend,y=r.seriesALabel||"A",b=r.seriesBLabel||"B",x=i.legendPosition||"right",v=function(e,t,o,i){if(!e.length)return[];const r=e.filter(e=>Number.isFinite(t(e))).sort((e,o)=>t(e)-t(o)),s=[];let n=0,a=null,c=null,l=[];const u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${n}-${e}`,h=e=>s.push(e),p=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;r.length>e;e++){const s=r[e],m=t(s),g=o(s),f=i(s);if(!Number.isFinite(m)||!Number.isFinite(g)||!Number.isFinite(f))continue;const y=u(g,f);if(null!==y)if(null!=a){if(c&&c.w!==y){let e,t;if(l.length>0)e=l[0].x,t=l[0].y;else{const o=g-c.a-(f-c.b);if(0!==o){const i=Math.max(0,Math.min(1,(c.b-c.a)/o));e=c.x+i*(m-c.x),t=c.a+i*(g-c.a)}else e=c.x,t=c.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t}),n++,a=y,h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t});for(let e=1;l.length>e;e++)p(l[e],a)}else for(const e of l)p(e,a);l=[],h({__x:m,__y:f>g?f:g,__y0:f>g?g:f,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:f,__sourceDatum:s}),c={x:m,a:g,b:f,w:y}}else{a=y;for(const e of l)p(e,a);l=[],h({__x:m,__y:f>g?f:g,__y0:f>g?g:f,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:f,__sourceDatum:s}),c={x:m,a:g,b:f,w:y}}else l.push({x:m,y:g,datum:s})}for(const e of l)p(e,a??"A");return s}(Array.isArray(e)?e:[],c,l,u),A=[];if(g&&Array.isArray(e)){const t=e.filter(e=>Number.isFinite(c(e))).sort((e,t)=>c(e)-c(t));for(const e of t){const t=c(e),o=l(e),i=u(e);Number.isFinite(o)&&A.push({__x:t,__y:o,__diffSegment:"line-A"}),Number.isFinite(i)&&A.push({__x:t,__y:i,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...A],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:e=>{const t=e.__diffSegment;return{fill:"A"==(t?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:p}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?d:h,strokeWidth:m,fill:"none"}),curve:r.curve||"linear",...i,...f&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:y,color:d},{label:b,color:h}]}]},legendPosition:x}}}},Eo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.areaBy,n="string"==typeof s&&Array.isArray(e)?me(e,s,o):void 0,a="number"==typeof r.areaOpacity?r.areaOpacity:.7,c=i.lineStyle||(e=>{const t=null==s?void 0:ye(e,s,n),o=r.showLine??!0,i={fill:r.color??t,stroke:o?r.stroke??t:"none",...o?{strokeWidth:r.strokeWidth??r.lineWidth??2}:{},fillOpacity:a,...null==r.opacity?{}:{opacity:r.opacity}},c=r.styleRules;if(c?.length){const t=x(r.yAccessor),o=s?"function"==typeof s?(s(e)??"")+"":(e[s]??"")+"":void 0;Object.assign(i,A(e,c,{value:t(e),category:o}))}return i}),l=r.normalize?"zero":r.baseline??"zero",u=i.pointStyle||Co(e,s,o,i,r);return{chartType:"stackedarea",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",groupAccessor:r.areaBy,colorAccessor:s,colorScheme:o,normalize:r.normalize,baseline:l,stackOrder:r.stackOrder,lineStyle:c,...i,...u&&{pointStyle:u},curve:i.curve??r.curve??"monotoneX",showLegend:i.showLegend??!!s}}},jo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const[s]=i.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.highAccessor||"high",highAccessor:r.highAccessor||"high",lowAccessor:r.lowAccessor||"low",openAccessor:r.openAccessor,closeAccessor:r.closeAccessor,candlestickStyle:r.candlestickStyle,...i,scalePadding:i.scalePadding??Math.max(2,Math.min(12,Math.round(s/40))),extentPadding:i.extentPadding??(s>200?.1:.02)}}},Do={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=i.pointStyle||Lo(e,t,o,i,r),n=S(r.styleRules,r.xAccessor||"x",r.yAccessor||"y"),a=n?e=>({..."function"==typeof s?s(e):s,...n(e)}):s;return{chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,...r.symbolBy&&{symbolAccessor:r.symbolBy},...r.symbolMap&&{symbolMap:r.symbolMap},colorScheme:o,...i,sizeRange:r.sizeRange||[3,15],pointStyle:a,showLegend:i.showLegend??!!t}}},No={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=r.xCenter,n=r.yCenter,a=r.quadrants,c=r.centerlineStyle||{},l=!1!==r.showQuadrantLabels,u=r.quadrantLabelSize??12,d=c.stroke||"#999",h=c.strokeWidth??1,p=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,m=zt.createElement,g=a?[(e,t,o)=>{if(!t?.x||!t?.y)return null;const i=o.width,r=o.height,c=null!=s?t.x(s):i/2,g=null!=n?t.y(n):r/2;if(null!=s&&!Number.isFinite(c))return null;if(null!=n&&!Number.isFinite(g))return null;const f=Math.max(0,Math.min(i,c)),y=Math.max(0,Math.min(r,g)),b=[{c:a.topLeft,x:0,y:0,w:f,h:y},{c:a.topRight,x:f,y:0,w:i-f,h:y},{c:a.bottomLeft,x:0,y:y,w:f,h:r-y},{c:a.bottomRight,x:f,y:y,w:i-f,h:r-y}],x=l?[m("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),m("text",{key:"ltr",x:i-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),m("text",{key:"lbl",x:8,y:r-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),m("text",{key:"lbr",x:i-8,y:r-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return m(zt.Fragment,null,...b.map((e,t)=>e.w>0&&e.h>0?m("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),m("line",{key:"vc",x1:f,y1:0,x2:f,y2:r,stroke:d,strokeWidth:h,strokeDasharray:p}),m("line",{key:"hc",x1:0,y1:y,x2:i,y2:y,stroke:d,strokeWidth:h,strokeDasharray:p}),...x)}]:void 0;return{chartType:"scatter",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,sizeAccessor:r.sizeBy,sizeRange:r.sizeRange||[3,15],colorScheme:o,pointStyle:i.pointStyle||r.pointStyle||Lo(e,t,o,i,r),...i,showLegend:i.showLegend??!!t,...g&&{svgPreRenderers:g}}}},$o={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};const o=t.xAccessor||"x",i=t.yAccessor||"y",r=t.orderAccessor?[...e].sort((e,o)=>null==e||"object"!=typeof e?1:null==o||"object"!=typeof o?-1:Ft(Ot(t.orderAccessor,"order",e))-Ft(Ot(t.orderAccessor,"order",o))):e,s=new WeakMap;let n=0;for(const e of r){if(null==e||"object"!=typeof e)continue;const t=Ft(Ot(o,"x",e)),r=Ft(Ot(i,"y",e));Number.isFinite(t)&&Number.isFinite(r)&&n++}let a=0;for(const e of r){if(null==e||"object"!=typeof e)continue;const t=Ft(Ot(o,"x",e)),r=Ft(Ot(i,"y",e));Number.isFinite(t)&&Number.isFinite(r)&&s.set(e,{idx:a++,total:n})}return{data:r,orderMap:s}}(e,r),n=r.pointRadius??4;return{chartType:"scatter",data:s.data,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,colorScheme:o,pointStyle:e=>{const t=s.orderMap.get(e),o=t?.idx??0,i=t?.total??1;return{fill:i>0?Bt(o,i):"#6366f1",stroke:"white",strokeWidth:1,r:n,fillOpacity:1}},...i,svgPreRenderers:[e=>{const t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(2>t.length)return null;const o=[];for(let e=0;t.length-1>e;e++){const i=t[e],r=t[e+1],s=Bt(e,t.length);100>t.length&&o.push(zt.createElement("line",{key:"halo-"+e,x1:i.x,y1:i.y,x2:r.x,y2:r.y,stroke:"white",strokeWidth:n+2,strokeLinecap:"round",opacity:.5})),o.push(zt.createElement("line",{key:"segment-"+e,x1:i.x,y1:i.y,x2:r.x,y2:r.y,stroke:s,strokeWidth:n,strokeLinecap:"round"}))}return zt.createElement(zt.Fragment,null,...o)}]}}};function Wo(e){return Math.max(0,Math.min(1,e))}function Go(e){const t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const o=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const e=[Number(o[1]),Number(o[2]),Number(o[3])];if(e.every(Number.isFinite))return e}return null}function Vo(e,t,o){const i=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(o)}`}function Ho(e,t,o){const i=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:Wo(e.offset),color:e.color??o,opacity:null==e.opacity?1:Wo(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===i.length)return"#999999";const r=e=>{if(1===e.opacity)return e.color;const t=Go(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===i.length)return r(i[0]);const s=Wo(t);if(i[0].offset>=s)return r(i[0]);if(s>=i[i.length-1].offset)return r(i[i.length-1]);for(let e=0;i.length-1>e;e++){const t=i[e],o=i[e+1];if(t.offset>s||s>o.offset)continue;const n=o.offset-t.offset,a=n>0?(s-t.offset)/n:0,c=Go(t.color),l=Go(o.color);if(!c||!l)return r(.5>a?t:o);const[u,d,h]=c,[p,m,g]=l,f=u+(p-u)*a,y=d+(m-d)*a,b=h+(g-h)*a,x=t.opacity+(o.opacity-t.opacity)*a;return 1===x?Vo(f,y,b):`rgba(${Math.round(f)},${Math.round(y)},${Math.round(b)},${x})`}return r(i[i.length-1])}function Yo(e,t,o){return null==o?`${e}-${t}`:`${e}-${t}-${o}`}import{Fragment as Xo,jsx as qo,jsxs as Uo}from"react/jsx-runtime";import{useMemo as Qo,useCallback as Ko,useRef as Zo}from"react";var Jo={RdBu:gt,PiYG:mt,PRGn:pt,BrBG:ht,RdYlBu:ft,RdYlGn:yt,Spectral:bt},ei="__likert_neutral_neg",ti="__likert_neutral_pos";function oi(e,t){if("function"==typeof e)return e;const o=e||t;return e=>e[o]}import*as ii from"react";function ri(e){return W(e)}function si(e,t,o,i,r){const s=Et(i.theme).colors.categorical,n=o??i.colorScheme,a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",l="function"==typeof t?a.map(e=>({...e,__ssrColorBy:t(e)})):a,u=t?me(l,c,n??s):void 0,d=je("string"==typeof r.color?r.color:void 0,s,n,void 0,new Map),h=x(r.valueAccessor),p=r.styleRules,m=i.pieceStyle;return(e,o)=>{const i={fill:t&&u?ye(e,t,u):d};return p?.length&&Object.assign(i,A(e,p,{value:h(e),category:o})),"function"==typeof m?Object.assign(i,m(e,o)||{}):m&&"object"==typeof m&&Object.assign(i,m),void 0!==r.stroke&&(i.stroke=r.stroke),void 0!==r.strokeWidth&&(i.strokeWidth=r.strokeWidth),void 0!==r.opacity&&(i.opacity=r.opacity),i}}function ni(e,t,o,i,r){const s=si(e,t,o,i,r);return(e,t)=>{const o=s(e,t);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function ai(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n="string"==typeof t?t:"__ssrViolinColorBy",a="function"==typeof t?s.map(e=>({...e,__ssrViolinColorBy:t(e)})):s,c=Et(i.theme).colors.categorical,l=o??i.colorScheme,u=t?me(a,n,l??c):void 0,d=je("string"==typeof r.color?r.color:void 0,c,l,void 0,new Map);return e=>{const o=t&&u?ye(e,t,u):d;return{fill:o,fillOpacity:.6,stroke:r.stroke??o,...void 0!==r.strokeWidth&&{strokeWidth:r.strokeWidth},...void 0!==r.opacity&&{opacity:r.opacity}}}}function ci(e,t,o,i,r){const s=si(e,t,o,i,r),n="number"==typeof r.dotRadius?r.dotRadius:5;return(e,t)=>({r:n,fillOpacity:.8,...s(e,t)})}function li(e,t,o,i,r){const s=si(e,t,o,i,r),n=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=r.sizeBy,c=Array.isArray(r.sizeRange)?r.sizeRange:[3,8],l=a?n.map(e=>"function"==typeof a?a(e):Number(e[a])).filter(Number.isFinite):[],u=l.length?St(l):void 0,d="number"==typeof r.pointRadius?r.pointRadius:4,h="number"==typeof r.pointOpacity?r.pointOpacity:.7;return(e,t)=>({r:a?xe(e,a,c,u):d,fillOpacity:h,...s(e,t)})}var ui={frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"bar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"horizontal"===r.orientation?"horizontal":"vertical",oSort:r.sort??!1,colorAccessor:t,colorScheme:o,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:ri(i.gradientFill),pieceStyle:si(e,t,o,i,r)})},di={frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.stackBy;return{chartType:"bar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",stackBy:r.stackBy,colorAccessor:s,colorScheme:o,projection:"horizontal"===r.orientation?"horizontal":"vertical",normalize:r.normalize,oSort:r.sort??!1,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:ri(i.gradientFill),pieceStyle:si(e,s,o,i,r),showLegend:i.showLegend??!!s}}},hi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.groupBy;return{chartType:"clusterbar",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",groupBy:r.groupBy,colorAccessor:s,colorScheme:o,projection:"horizontal"===r.orientation?"horizontal":"vertical",oSort:r.sort??!1,barPadding:r.barPadding,...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:ri(i.gradientFill),pieceStyle:si(e,s,o,i,r),showLegend:i.showLegend??!!s}}},pi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.categoryAccessor;return{chartType:"pie",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"radial",colorAccessor:s,colorScheme:o,...null!=r.cornerRadius&&{cornerRadius:r.cornerRadius},...null!=r.startAngle&&{startAngle:r.startAngle},...i,pieceStyle:si(e,s,o,i,r),showLegend:i.showLegend??!!s}}},mi={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,o,i,r)=>{const s=t||r.categoryAccessor;return{chartType:"donut",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",projection:"radial",margin:i.margin??{top:50,right:40,bottom:60,left:70},innerRadius:r.innerRadius??60,colorAccessor:s,colorScheme:o,...null!=r.cornerRadius&&{cornerRadius:r.cornerRadius},...null!=r.startAngle&&{startAngle:r.startAngle},...i,pieceStyle:si(e,s,o,i,r)}}},gi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=r.valueAccessor||"value",a=s.map(e=>Number("function"==typeof n?n(e):e[n])).filter(Number.isFinite),c=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:e,oAccessor:r.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:n,projection:"horizontal",bins:r.bins??25,normalize:r.relative??!1,colorAccessor:t,colorScheme:o,barPadding:r.categoryPadding??20,...r.valueExtent?{rExtent:r.valueExtent}:c?{rExtent:c}:{},...i,summaryStyle:ni(e,t,o,i,r)}}},fi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"boxplot",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,...null!=r.showOutliers&&{showOutliers:r.showOutliers},...null!=r.outlierRadius&&{outlierRadius:r.outlierRadius},...i,summaryStyle:i.summaryStyle||ni(e,t,o,i,r)})},yi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"violin",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===r.orientation?"horizontal":"vertical",bins:r.bins??25,showIQR:r.showIQR??!0,barPadding:r.categoryPadding??20,colorScheme:o,...i,summaryStyle:i.summaryStyle||ai(e,t,o,i,r),showLegend:i.showLegend??!!t,...r.valueExtent&&{rExtent:r.valueExtent}})},bi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"swarm",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,...r.symbolBy&&{symbolAccessor:r.symbolBy},...r.symbolMap&&{symbolMap:r.symbolMap},colorScheme:o,...i,sizeRange:r.sizeRange||[3,8],pieceStyle:i.pieceStyle||li(e,t,o,i,r),showLegend:i.showLegend??!!t})},xi={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,o,i,r)=>({chartType:"point",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",oSort:r.sort??"auto",barPadding:r.categoryPadding??10,...i,pieceStyle:ci(e,t,o,i,r),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!t})},vi={frameType:"ordinal",buildProps:(e,t,o,i,r)=>{const s=t||r.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",stackBy:r.subcategoryAccessor,colorAccessor:s,categoryAccessor:r.categoryAccessor,subcategoryAccessor:r.subcategoryAccessor,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",...null!=r.trackFill&&{trackFill:r.trackFill},...r.valueExtent&&{rExtent:r.valueExtent},...null!=r.roundedTop&&{roundedTop:r.roundedTop},...i,gradientFill:ri(i.gradientFill),pieceStyle:i.pieceStyle||si(e,s,o,i,r),showLegend:i.showLegend??!!s,barPadding:r.barPadding??40}}},Ai={frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"ridgeline",data:e,oAccessor:r.categoryAccessor||"category",rAccessor:r.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===r.orientation?"vertical":"horizontal",bins:r.bins??20,amplitude:r.amplitude??1.5,barPadding:r.categoryPadding??5,oSort:r.oSort??!1,...i,summaryStyle:i.summaryStyle||((s,n)=>({fillOpacity:.5,...si(e,t,o,i,r)(s,n)})),showLegend:i.showLegend??!!t})},wi={frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,o,i,r)=>{const s=Array.isArray(r.levels)&&r.levels.length>=2?r.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],n="vertical"!==r.orientation;let a=function(e,t,o,i,r,s){const n=new Map,a=new Set(t);for(const c of e){const e=o(c);n.has(e)||n.set(e,new Map);const l=n.get(e);if(i){const e=i(c);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}const o=e-1;if(0>o||o>=t.length)continue;const r=t[o];l.set(r,(l.get(r)||0)+1)}else if(r&&s){const e=r(c),t=s(c);if(!a.has(e))continue;l.set(e,(l.get(e)||0)+(Number.isFinite(t)?t:0))}}const c=[];for(const[e,o]of n){let i=0;for(const e of t)i+=o.get(e)||0;if(0!==i)for(let r=0;t.length>r;r++){const s=t[r],n=o.get(s)||0;c.push({__likertCategory:e,__likertLevel:s,__likertLevelLabel:s,__likertCount:n,__likertPct:n/i*100,__likertLevelIndex:r})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s,oi(r.categoryAccessor,"question"),r.levelAccessor?null:oi(r.valueAccessor,"score"),r.levelAccessor?oi(r.levelAccessor,"level"):null,r.levelAccessor?oi(r.countAccessor,"count"):null);n&&(a=function(e,t){const o=t.length,i=o%2!=0,r=Math.floor(o/2),s=new Map;for(const t of e){const e=s.get(t.__likertCategory)||[];e.push(t),s.set(t.__likertCategory,e)}const n=[];for(const[,e]of s){const t=new Map;let s,a;for(const o of e)o.__likertLevel===ei?s=o:o.__likertLevel===ti?a=o:t.set(o.__likertLevelIndex,o);i&&s&&n.push(s);for(let e=r-1;e>=0;e--){const o=t.get(e);o&&n.push(o)}i&&a&&n.push(a);for(let e=i?r+1:r;o>e;e++){const o=t.get(e);o&&n.push(o)}}return n}(function(e,t){const o=t.length,i=o%2!=0,r=Math.floor(o/2),s=[];for(const t of e){const e=t.__likertLevelIndex;if(i&&e===r){const e=t.__likertPct/2;s.push({...t,__likertLevel:ei,__likertPct:-e}),s.push({...t,__likertLevel:ti,__likertPct:e})}else s.push(r>e?{...t,__likertPct:-t.__likertPct}:t)}return s}(a,s),s));const c=Et(i.theme).colors.diverging,l=Array.isArray(o)&&o.length>=s.length?o:function(e,t){if(0>=e)return[];if(t){const o=Jo[t];if(o){if(1===e)return[o(.5)];const t=[];for(let i=0;e>i;i++)t.push(o(i/(e-1)));return t}}const o=["#da1e28","#ff8389","#ffb3b8"],i=["#a6c8ff","#4589ff","#0043ce"],r="#a8a8a8";if(1===e)return[r];const s=e%2!=0,n=Math.floor(e/2),a=[];for(let e=0;n>e;e++)a.push(o[Math.min(Math.floor(e*o.length/n),o.length-1)]);s&&a.push(r);for(let e=0;n>e;e++)a.push(i[Math.min(Math.floor(e*i.length/n),i.length-1)]);return a}(s.length,c),u=new Map(s.map((e,t)=>[e,l[t]||"#888"])),d=s.length%2&&u.get(s[Math.floor(s.length/2)])||"#888",h="function"==typeof r.valueFormat?r.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",p=!1===i.showLegend?void 0:{legendGroups:[{label:"",items:s.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},m=de(p,i.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:n?"horizontal":"vertical",barPadding:r.barPadding,showGrid:i.showGrid,oLabel:r.categoryLabel,rLabel:r.valueLabel||(n?void 0:"Percentage"),rFormat:h,...r.categoryFormat&&{oFormat:r.categoryFormat},...r.valueExtent&&{rExtent:r.valueExtent},...i,pieceStyle:e=>{const t=e.__likertLevel||e.data?.__likertLevel;return{fill:t===ei||t===ti?d:u.get((e.__likertLevelLabel||e.data?.__likertLevelLabel||t)+"")||"#888"}},showLegend:i.showLegend??!0,legendPosition:i.legendPosition||"right",...m&&{legend:m},__legendIncludesAutomatic:!0}}},Si={frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s="vertical"===r.orientation,n=t||r.categoryAccessor;return{chartType:s?"bar-funnel":"funnel",data:e,oAccessor:r.stepAccessor||"step",rAccessor:r.valueAccessor||"value",colorAccessor:n,categoryAccessor:r.categoryAccessor,projection:s?"vertical":"horizontal",connectorAccessor:r.connectorAccessor,connectorStyle:r.connectorStyle,...!s&&null!=r.connectorOpacity&&{connectorOpacity:r.connectorOpacity},barPadding:s?40:0,colorScheme:o,...i,showAxes:s,showGrid:s,pieceStyle:si(e,n,o,i,r),showLabels:r.showLabels??!0}}},ki={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){const o=e.__gauge;if(!o)return null;const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.needleColor||t.colors.text,s=o.showScaleLabels?(o.thresholds||[]).filter(e=>e.value>o.gMin&&o.gMax>e.value):[];return Uo(Xo,{children:[o.showNeedle&&Uo(Xo,{children:[qo("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(i),y2:o.centerY+o.needleLength*Math.sin(i),stroke:r,strokeWidth:2.5,strokeLinecap:"round"}),qo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:r})]}),null!=o.contextValue&&qo("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:r,children:o.contextValue}),s.map((e,i)=>{const r=(o.startAngleDeg+(o.gMax===o.gMin?0:(e.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,s=o.innerRadius-1,n=o.radius+1,a=o.radius+10,c=((r+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",u=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return Uo("g",{children:[qo("line",{x1:o.centerX+Math.cos(r)*s,y1:o.centerY+Math.sin(r)*s,x2:o.centerX+Math.cos(r)*n,y2:o.centerY+Math.sin(r)*n,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),qo("text",{x:o.centerX+Math.cos(r)*a,y:o.centerY+Math.sin(r)*a,textAnchor:l,dominantBaseline:u,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+i)})]})},buildProps:(t,o,r,s,n)=>{const a=n.min??0,c=n.max??100,l=n.sweep??240,u=n.arcWidth??.3,d=!1!==n.showNeedle,h=!1!==n.fillZones,{startAngleDeg:p}=i(l),m=n.thresholds||[{value:c,color:n.color||"#4e79a7"}],g=$(s.gradientFill),f=function(e){const{min:t,max:o,value:i,thresholds:r,fillColor:s,backgroundColor:n,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=e,d=o-t||1,h=(Math.max(t,Math.min(o,i))-t)/d;let p=r&&r.length>0?[...r].sort((e,t)=>e.value-t.value):[{value:o,color:s||"#007bff"}];p=p.map(e=>({...e,value:Math.max(t,Math.min(o,e.value))})),o>p[p.length-1].value&&p.push({value:o,color:p[p.length-1].color});const m=!!l&&l.stops.length>=2,g=[],f=new Map,y=[];if(m){const e=a?h:1,t=Yo("bg",0);if(g.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),f.set(t,{fill:n,opacity:.4}),e>0){const t=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(t,Math.round(e*t))),i=[];for(let t=0;o>t;t++)i.push(Ho(l.stops,e*(t+.5)/o,s||p[0]?.color||"#007bff"));const r=Yo("fill",0);g.push({category:r,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:i}}),f.set(r,{fill:i[0]||n})}}else{let e=t;for(let o=0;p.length>o;o++){const i=p[o],r=(i.value-e)/d,s=(e-t)/d,c=(i.value-t)/d,l=Math.max(0,(a?Math.min(h,c):c)-s),u=a?Math.max(0,r-l):0;if(l>0){const e=Yo("fill",o);g.push({category:e,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),f.set(e,{fill:i.color})}if(u>0){const e=Yo("bg",o);g.push({category:e,value:u,_zone:i.label||"Zone "+(o+1),_isFill:!1}),f.set(e,{fill:n,opacity:.4})}e=i.value}}if(c&&r&&r.length>0)for(const e of r)e.value>t&&o>e.value&&y.push({type:"gauge-label",value:e.value,label:e.label||e.value+""});return{gaugeData:g,pieceStyle:(e,t)=>f.get(t||e.category)||{fill:n},gaugeAnnotations:y}}({min:a,max:c,value:n.value,thresholds:m,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:h,showScaleLabels:!1!==n.showScaleLabels,gradientFill:g}),[y,b]=s.size||[300,250],x=e(l),v=Math.min(10,Math.max(1,Math.min(y,b)/12)),A=Math.max(4,Math.min((y-2*v)/x.width,(b-2*v)/x.height)-2),w=Math.max(0,Math.min(A-1.5,A*(1-u))),S=y/2-x.cx*A,k=b/2-x.cy*A,_=2*(A+4),M=Math.max(a,Math.min(c,n.value??a)),R="function"==typeof n.valueFormat?n.valueFormat(M):Math.round(M)+"",P=n.centerContent??s.centerContent,L=null!=P?"function"==typeof P?P(M,a,c):P:"sparkline"===n.mode||"context"===n.mode?void 0:ii.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},ii.createElement("div",{style:{fontSize:Math.max(16,.3*A),fontWeight:700,color:"var(--semiotic-text, #333)"}},R),!1!==n.showScaleLabels&&ii.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${a} – ${c}`));return{chartType:"donut",data:f.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:w,sweepAngle:l,startAngle:p,oSort:!1,pieceStyle:f.pieceStyle,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...s,size:[y,b],margin:{top:k-_/2,bottom:b-k-_/2,left:S-_/2,right:y-S-_/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(s.annotations)?s.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:a,gMax:c,sweep:l,arcWidth:u,value:M,startAngleDeg:p,thresholds:m,centerX:S,centerY:k,radius:A,innerRadius:w,showScaleLabels:!1!==n.showScaleLabels,needleLength:w>20?w-8:A-1,showNeedle:d,needleColor:n.needleColor,..."context"===n.mode&&null==P&&{contextValue:R,contextValueY:k-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*A))}}}}};import{scaleTime as _i}from"d3-scale";function Mi(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:e.kind}function Ri(e,t,o){const i=t.incoming[e.id],r=t.outgoing[e.id],s=[];for(const e of i)s.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:o.get(e.id).targetSide});for(const e of r)s.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:o.get(e.id).sourceSide});const n={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},a=()=>{s.sort((e,t)=>e.time-t.time||(n[e.kind]??99)-(n[t.kind]??99))},c=s.length?wt(s.map(e=>e.time)):null,l=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,u=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,d=[...new Set(s.map(e=>e.time))].sort((e,t)=>e-t),h=new Map;for(let e=1;d.length>e;e++)h.set(d[e],d[e-1]);const p=e=>{const t=h.get(e);return null!=t?(t+e)/2:null!=u?u:e};a();const m=[];let g=0,f=0;for(const e of s)if("out"===e.kind){const t=Math.abs(e.delta);let o=t-("top"===e.side?g:f);if(o>0){const t="top"===e.side?"bot":"top",i=Math.min(o,"top"===t?g:f);if(i>0){const r=p(e.time);m.push({time:r,delta:-i,kind:"transfer-out",side:t}),m.push({time:r,delta:+i,kind:"transfer-in",side:e.side}),"top"===t?g-=i:f-=i,"top"===e.side?g+=i:f+=i,o-=i}o>0&&null!==u&&(m.push({time:u,delta:+o,kind:"create",side:e.side}),"top"===e.side?g+=o:f+=o)}"top"===e.side?g-=t:f-=t}else if("in"===e.kind){const t=Math.abs(e.delta);"top"===e.side?g+=t:f+=t}s.push(...m),a();let y=0,b=0,x=0,v=0,A=0;const w=[],S=new Map;for(const e of s){if(w.push({t:e.time,topMass:y,botMass:b}),("in"===e.kind||"out"===e.kind)&&e.edge){const t="top"===e.side?y:b;S.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta)})}"top"===e.side?y+=e.delta:b+=e.delta,y+b>x&&(x=y+b),y>v&&(v=y),b>A&&(A=b),w.push({t:e.time,topMass:y,botMass:b})}const k=[];let _=0;for(;w.length>_;){let e=_;for(;w.length>e+1&&w[e+1].t===w[_].t;)e++;k.push(w[_]);for(let t=_+1;e>=t;t++){const e=k[k.length-1];w[t].topMass===e.topMass&&w[t].botMass===e.botMass||k.push(w[t])}_=e+1}const M=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null;let R=null;for(const e of r)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===R||R>e.systemInTime)&&(R=e.systemInTime);let P=null;for(const e of i)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===P||e.systemOutTime>P)&&(P=e.systemOutTime);if(k.length>0){const e=k[k.length-1],t=Math.max(null!=M?M:-1/0,null!=P?P:-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&k.push({t:t,topMass:e.topMass,botMass:e.botMass});const o=k[0],i=Math.min(null!=l?l:1/0,null!=R?R:1/0);Number.isFinite(i)&&o.t>i&&o.topMass+o.botMass>0&&k.unshift({t:i,topMass:o.topMass,botMass:o.botMass})}return{samples:k,peak:x,topPeak:v,botPeak:A,localAttachments:S}}function Pi(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Li(e,t){return e.map(e=>({t:Pi(e.t,t),topMass:e.topMass,botMass:e.botMass}))}function Ii(e,t,o){const i=e.value*o;if("out"===e.kind){const r=e.sideMassBefore*o;if("top"===e.side){const e=t-r;return[e,e+i]}const s=t+r;return[s-i,s]}const r=e.sideMassAfter*o;if("top"===e.side){const e=t-r;return[e,e+i]}const s=t+r;return[s-i,s]}function Ti(e,t){let o=0;for(let i=0;t.length>i;i++)for(let r=i+1;t.length>r;r++){const s=t[i],n=t[r];s.source!==n.source&&s.target!==n.target&&s.source!==n.target&&s.target!==n.source&&(Math.min(s.endTime,n.endTime)>Math.max(s.startTime,n.startTime)&&e[n.source]>e[s.source]!=e[n.target]>e[s.target]&&o++)}return o}function Ci(e,t){let o=0;for(const i of t)o+=Math.abs(e[i.source]-e[i.target])*(i.value||1);return o}function zi(e,t){return 1e3*Ti(e,t)+Ci(e,t)}function Oi(e,t){return{slots:e.map(e=>({peak:{...e.peak},occupants:e.occupants.slice()})),map:{...t}}}function Fi(e,t,o){e.length>8||o.length>40?(function(e,t,o,i=6){const r=e.length;if(1>=r)return;let s=Oi(e,t),n=zi(t,o);for(let a=0;i>a;a++){const i=Array(r).fill(0),a=Array(r).fill(0);for(const e of o){const o=t[e.source],r=t[e.target];i[o]+=r*(e.value||1),a[o]+=e.value||1,i[r]+=o*(e.value||1),a[r]+=e.value||1}const c=Array.from({length:r},(e,t)=>t).sort((e,t)=>(a[e]>0?i[e]/a[e]:e)-(a[t]>0?i[t]/a[t]:t)),l=c.map(t=>e[t]),u=new Map;c.forEach((e,t)=>u.set(e,t));for(const e of Object.keys(t))t[e]=u.get(t[e]);e.length=0;for(const t of l)e.push(t);const d=zi(t,o);if(n>d)n=d,s=Oi(e,t);else if(d===n)break}!function(e,t,o){e.length=0;for(const t of o.slots)e.push(t);for(const e of Object.keys(t))delete t[e];for(const e of Object.keys(o.map))t[e]=o.map[e]}(e,t,s)}(e,t,o,6),function(e,t,o,i=6){const r=e.length;if(1>=r)return;let s=zi(t,o);for(let n=0;i>n;n++){let i=!1;for(let n=0;r-1>n;n++){const r=e[n];e[n]=e[n+1],e[n+1]=r;for(const e of Object.keys(t))t[e]===n?t[e]=n+1:t[e]===n+1&&(t[e]=n);const a=zi(t,o);if(s>a)s=a,i=!0;else{const o=e[n];e[n]=e[n+1],e[n+1]=o;for(const e of Object.keys(t))t[e]===n?t[e]=n+1:t[e]===n+1&&(t[e]=n)}}if(!i)break}}(e,t,o,6)):function(e,t,o){const i=e.length;if(1>=i)return;const r={...t},s=Object.keys(r),n=Array.from({length:i},(e,t)=>t),a=n.slice(),c={...r};let l=n.slice(),u=1/0;const d=()=>{for(const e of s)c[e]=a[r[e]];const e=zi(c,o);u>e&&(u=e,l=n.slice())},h=(e,t)=>{const o=n[e],i=n[t];n[e]=i,n[t]=o,a[o]=t,a[i]=e};d();const p=Array(i).fill(0);let m=0;for(;i>m;)m>p[m]?(h(m%2==0?0:p[m],m),d(),p[m]++,m=0):(p[m]=0,m++);const g=l.map(t=>e[t]),f=new Map;l.forEach((e,t)=>f.set(e,t));for(const e of Object.keys(t))t[e]=f.get(t[e]);e.length=0;for(const t of g)e.push(t)}(e,t,o)}function Bi(e,t,o,i,r){const{plotH:s,padding:n,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="full"}=r,d={},h={};for(const t of e)d[t.id]=o[t.id].topPeak||0,h[t.id]=o[t.id].botPeak||0;const p="half"===u,m={};for(const t of e){const e=Array.isArray(t.xExtent)?t.xExtent[0]:null,o=Array.isArray(t.xExtent)?t.xExtent[1]:null;let r=null!=e&&Number.isFinite(e)?e:1/0,s=null!=o&&Number.isFinite(o)?o:-1/0;for(const e of i.outgoing[t.id]){r>e.startTime&&(r=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&r>e.systemInTime&&(r=e.systemInTime);const t=p?(e.startTime+e.endTime)/2:e.endTime;t>s&&(s=t)}for(const e of i.incoming[t.id]){const t=p?(e.startTime+e.endTime)/2:e.startTime;r>t&&(r=t),e.endTime>s&&(s=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>s&&(s=e.systemOutTime)}m[t.id]={start:Number.isFinite(r)?r:null,end:Number.isFinite(s)?s:null}}const g={},f=[];if("reuse"===c){const o=new Map;for(const t of e)o.set(t.id,0);const r=new Map;for(const t of e)r.set(t.id,0);for(const e of t)r.set(e.target,(r.get(e.target)??0)+1);const s=[];for(const t of e)0===(r.get(t.id)??0)&&s.push(t.id);for(;s.length;){const e=s.shift();for(const t of i.outgoing[e]??[]){const i=(o.get(e)??0)+1;i>(o.get(t.target)??0)&&o.set(t.target,i),r.set(t.target,r.get(t.target)-1),0===r.get(t.target)&&s.push(t.target)}}const n=[...e].filter(e=>null!==m[e.id].start).sort((e,t)=>{const i=o.get(e.id)??0,r=o.get(t.id)??0;return i!==r?i-r:m[e.id].start-m[t.id].start}),a=e.filter(e=>null===m[e.id].start);for(const e of[...n,...a]){const t=m[e.id];let o=-1;for(let e=0;f.length>e;e++){const i=f[e].occupants[f[e].occupants.length-1];if(null===t.start||void 0===i||t.start>=i.end){o=e;break}}-1===o&&(f.push({occupants:[],peak:{topPeak:0,botPeak:0}}),o=f.length-1),f[o].occupants.push({id:e.id,end:t?.end??-1/0}),f[o].peak.topPeak=Math.max(f[o].peak.topPeak,d[e.id]),f[o].peak.botPeak=Math.max(f[o].peak.botPeak,h[e.id]),g[e.id]=o}}else e.forEach((e,t)=>{f.push({occupants:[{id:e.id,end:m[e.id]?.end??-1/0}],peak:{topPeak:d[e.id],botPeak:h[e.id]}}),g[e.id]=t});let y=null,b=null,x=null,v=null;const A=()=>{y=Ti(g,t),x=Ci(g,t)},w=()=>{b=Ti(g,t),v=Ci(g,t)};"crossing-min"===l?(A(),Fi(f,g,t),w()):"inside-out"===l?(A(),function(e,t){const o=e.length;if(1>=o)return;const i=e=>e.peak.topPeak+e.peak.botPeak,r=e.map((e,t)=>({slot:e,idx:t})).sort((e,t)=>i(t.slot)-i(e.slot)),s=Array(o),n=Math.floor((o-1)/2);s[n]=r[0].idx;let a=n-1,c=n+1;for(let e=1;r.length>e;e++)e%2==1&&o>c||0>a?s[c++]=r[e].idx:s[a--]=r[e].idx;const l=s.map(t=>e[t]),u=new Map;s.forEach((e,t)=>u.set(e,t));for(const e of Object.keys(t))t[e]=u.get(t[e]);e.length=0;for(const t of l)e.push(t)}(f,g),w()):"crossing-min+inside-out"===l&&(A(),Fi(f,g,t),function(e,t,o){const i=e.length;if(1>=i)return;const r=e.map(e=>{return{slot:e,size:(t=e,t.peak.topPeak+t.peak.botPeak)};var t}).sort((e,t)=>t.size-e.size),s=Math.floor((i-1)/2);let n=zi(t,o);for(const{slot:a}of r){const r=e.indexOf(a);if(0>r)continue;const c=s;if(r===c)continue;const l=e[r];e.splice(r,1),e.splice(c,0,l);const u=new Map;for(let e=0;i>e;e++)u.set(e,e);if(c>r){for(let e=r+1;c>=e;e++)u.set(e,e-1);u.set(r,c)}else{for(let e=c;r>e;e++)u.set(e,e+1);u.set(r,c)}for(const e of Object.keys(t))t[e]=u.get(t[e]);const d=zi(t,o);if(d>n){const o=e[c];e.splice(c,1),e.splice(r,0,o);const s=new Map;for(let e=0;i>e;e++)s.set(e,e);if(r>c){for(let e=c+1;r>=e;e++)s.set(e,e-1);s.set(c,r)}else{for(let e=r;c>e;e++)s.set(e,e+1);s.set(c,r)}for(const e of Object.keys(t))t[e]=s.get(t[e])}else n=d}}(f,g,t),w());const S=f.map(e=>{const t=new Map;for(const i of e.occupants){const e=o[i.id];if(e)for(const o of e.samples){const e=t.get(o.t)||{top:0,bot:0};t.set(o.t,{top:Math.max(e.top,o.topMass),bot:Math.max(e.bot,o.botMass)})}}return[...t.entries()].sort((e,t)=>e[0]-t[0])}),k=(e,t)=>{let o={top:0,bot:0};for(const[i,r]of e){if(i>t)break;o=r}return o},_=[];for(let e=0;f.length-1>e;e++){const t=S[e],o=S[e+1],i=new Set([...t.map(e=>e[0]),...o.map(e=>e[0])]);let r=0;for(const e of i){const i=k(t,e),s=k(o,e);i.bot+s.top>r&&(r=i.bot+s.top)}_.push(r)}const M=[];let R=n+(f[0]?.peak.topPeak??0)*a;f.length>0&&M.push(R);for(let e=1;f.length>e;e++)R+=_[e-1]*a+n,M.push(R);if(f.length>0&&(R+=f[f.length-1].peak.botPeak*a+n),R>s){const e=s/R;for(let t=0;M.length>t;t++)M[t]*=e}const P=0===f.length?0:f[0].peak.topPeak+_.reduce((e,t)=>e+t,0)+f[f.length-1].peak.botPeak,L={};for(const t of e)L[t.id]=M[g[t.id]];return{effectiveSlotsHeight:P,centerlines:L,laneLifetime:m,slots:f,slotByNode:g,slotCenter:M,crossingsBefore:y,crossingsAfter:b,lengthBefore:x,lengthAfter:v}}function Ei(e){const{nodes:t,edges:o,domain:i,plotW:r,plotH:s,ribbonLane:n,edgeOpacity:a,colorOf:c,layoutOpts:l}=e,u=function(e,t,o){const i=[],r=new Set(e.map(e=>e.id)),s=Array.isArray(o)&&2===o.length,n=s&&Number.isFinite(o[0])&&Number.isFinite(o[1]);s&&n&&n&&o[1]>=o[0]||i.push({kind:"invalid-domain"});for(const t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||i.push({kind:"invalid-node-time",id:t.id}));for(const e of t)r.has(e.source)||i.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),r.has(e.target)||i.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?(Number.isFinite(e.value)&&e.value>0||i.push({kind:"invalid-value",id:e.id}),e.endTime>e.startTime||i.push({kind:"backward-edge",id:e.id,source:e.source,target:e.target})):i.push({kind:"invalid-edge-time",id:e.id});return i}(t,o,i),d=_i().domain(i).range([0,r]);if(u.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:u,xScale:d};const h=function(e,t,o){const{plotH:i,pairing:r="temporal",packing:s="reuse",laneOrder:n="crossing-min",lifetimeMode:a="half"}=o,c=function(e,t){const o={},i={};for(const t of e)o[t.id]=[],i[t.id]=[];for(const e of t)i[e.source]&&i[e.source].push(e),o[e.target]&&o[e.target].push(e);return{incoming:o,outgoing:i}}(e,t),l=function(e,t,o,i="value"){const r="temporal"===i?(e,t)=>e.endTime-t.endTime:(e,t)=>t.value-e.value,s="temporal"===i?(e,t)=>e.startTime-t.startTime:(e,t)=>t.value-e.value,n=new Map;for(const e of t)n.set(e.id,{});const a=(e,t)=>{const o=new Map;for(const i of e){const e=i[t];o.has(e)||o.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const r=o.get(e);r.edges.push(i),r.total+=i.value,r.earliestStart=Math.min(r.earliestStart,i.startTime),r.latestEnd=Math.max(r.latestEnd,i.endTime)}const n=[...o.values()];n.sort("temporal"===i?(e,o)=>"target"===t?e.earliestStart-o.earliestStart:e.latestEnd-o.latestEnd:(e,t)=>t.total-e.total);for(const e of n)e.edges.sort("target"===t?s:r);return n};for(const t of e){const e=o.outgoing[t.id],i=o.incoming[t.id];if(0===i.length)a(e,"target").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)n.get(t.id).sourceSide=o});else if(0===e.length)a(i,"source").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)n.get(t.id).targetSide=o});else{const t=a(i,"source"),o=a(e,"target"),r=Math.max(t.length,o.length);for(let e=0;r>e;e++){const i=e%2==0?"top":"bot";if(t[e])for(const o of t[e].edges)n.get(o.id).targetSide=i;if(o[e])for(const t of o[e].edges)n.get(t.id).sourceSide=i}}}return n}(e,t,c,r);let u={};for(const t of e)u[t.id]=Ri(t,c,l);const d=Bi(e,t,u,c,{plotH:i,padding:12,valueScale:1,packing:s,laneOrder:n,lifetimeMode:a}),h=new Set;for(const e of t){const t=d.slotByNode[e.source],o=d.slotByNode[e.target];if(void 0===t||void 0===o)continue;const i=l.get(e.id);t!==o?t>o?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(h.add(e.id),i.sourceSide="bot",i.targetSide="bot")}for(const t of e){const e=c.outgoing[t.id],o=c.incoming[t.id],i=new Set(e.map(e=>l.get(e.id).sourceSide)),r=new Set(o.map(e=>l.get(e.id).targetSide));if(1===i.size&&o.length>0){const e=[...i][0];for(const t of o)d.slotByNode[t.source]===d.slotByNode[t.target]&&(l.get(t.id).targetSide=e)}if(1===r.size&&e.length>0){const t=[...r][0];for(const o of e)d.slotByNode[o.source]===d.slotByNode[o.target]&&(l.get(o.id).sourceSide=t)}}for(const t of e){const e=c.incoming[t.id],o=c.outgoing[t.id];if(0===e.length||0===o.length)continue;const i=()=>{const t={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of e)"top"===l.get(o.id).targetSide?t.inTop+=o.value:t.inBot+=o.value;for(const e of o)"top"===l.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},r=(e,t)=>{const r=i(),s="top"===e?r.outTop-r.inTop:r.outBot-r.inBot,n="top"===t?r.inTop-r.outTop:r.inBot-r.outBot;if(0>=s||0>=n)return!1;const a=Math.min(s,n),c=o.filter(t=>!h.has(t.id)&&l.get(t.id).sourceSide===e&&a>=t.value).sort((e,t)=>t.value-e.value);return 0!==c.length&&(l.get(c[0].id).sourceSide=t,!0)};let s=o.length+1;for(;s-- >0&&(r("top","bot")||r("bot","top")););}u={};for(const t of e)u[t.id]=Ri(t,c,l);const p=Bi(e,t,u,c,{plotH:i,padding:12,valueScale:1,packing:s,laneOrder:n,lifetimeMode:a}),m=p.effectiveSlotsHeight??p.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),g=Math.min(12,.35*i/Math.max(p.slots.length+1,1)),f=m>0?Math.max(0,(i-g*(p.slots.length+1))/m):1,y=Bi(e,t,u,c,{plotH:i,padding:g,valueScale:f,packing:s,laneOrder:n,lifetimeMode:a});return{nodeData:u,sides:l,valueScale:f,padding:g,compressedPadding:12>g,centerlines:y.centerlines,laneLifetime:y.laneLifetime,slots:y.slots,slotByNode:y.slotByNode,crossingsBefore:y.crossingsBefore,crossingsAfter:y.crossingsAfter,lengthBefore:y.lengthBefore,lengthAfter:y.lengthAfter}}(t,o,{plotH:s,...l}),{centerlines:p,nodeData:m,valueScale:g}=h,f=[],y=[];t.forEach((e,t)=>{const r=m[e.id];if(!r||0===r.samples.length)return;const s=function(e,t,o,i,r){if(0===e.length)return null;const s=Li(e,r),n=e=>t-s[e].topMass*o,a=e=>t+s[e].botMass*o;let c=`M${i(s[0].t)},${n(0)}`;for(let e=1;s.length>e;e++)c+=` L${i(s[e].t)},${n(e)}`;c+=` L${i(s[s.length-1].t)},${a(s.length-1)}`;for(let e=s.length-2;e>=0;e--)c+=` L${i(s[e].t)},${a(e)}`;return c+" Z"}(r.samples,p[e.id],g,d,i);if(!s)return;const n=Li(r.samples,i),a=n.find(e=>e.topMass+e.botMass>0)||n[0],l=p[e.id]+(a.botMass-a.topMass)*g/2,u=c(e.id,t),y=function(e,t,o,i,r){const s=o.nodeData[e];if(!s||0===s.samples.length)return[];const n=o.valueScale,a=o.centerlines[e],c=Li(s.samples,r),l=c.find(e=>e.topMass+e.botMass>0)||c[0],u=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],d=i(l.t),h=i(u.t),p=e=>i(Pi(e,r)),m=[],g=(e,t,o,i)=>`M${e},${t} L${o},${t} L${o},${i} L${e},${i} Z`;for(const o of t){if(o.source===e&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const e=s.localAttachments.get(o.id);if(e&&"out"===e.kind&&o.startTime>o.systemInTime){const t=p(o.systemInTime),i=p(o.startTime),r=t-20,s=Math.max(d,r);if(i>s){const[o,c]=Ii(e,a,n);m.push({pathD:g(s,o,i,c),x0:r,x1:t,from:0,to:1})}}}if(o.target===e&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const e=s.localAttachments.get(o.id);if(e&&"in"===e.kind&&o.systemOutTime>o.endTime){const t=p(o.systemOutTime),i=p(o.endTime),r=t+20,s=Math.min(h,r);if(s>i){const[o,c]=Ii(e,a,n);m.push({pathD:g(i,o,s,c),x0:t,x1:r,from:1,to:0})}}}}return m}(e.id,o,h,d,i);f.push({id:e.id,pathD:s,fill:u,stroke:u,strokeWidth:.5,...y.length>0&&{gradientStubs:y},rawDatum:e.__raw??e,labelX:d(a.t)-4,labelY:l,labelText:e.id})});const b=new Map;return t.forEach((e,t)=>b.set(e.id,t)),o.forEach(e=>{const t=m[e.source]?.localAttachments.get(e.id),o=m[e.target]?.localAttachments.get(e.id);if(!t||!o)return;const r=b.get(e.source)??0,s=c(e.source,r),l=function(e,t,o,i,r,s,n,a){const c=r,l=e=>a?Math.max(a[0],Math.min(a[1],e)):e,u=s(l(e.time)),d=s(l(o.time)),h=e.value*c,p=o.value*c,m=e.sideMassBefore*c,g=o.sideMassAfter*c;let f,y,b,x;"top"===e.side?(f=t-m,y=f+h):(y=t+m,f=y-h),"top"===o.side?(b=i-g,x=b+p):(x=i+g,b=x-p);const v="source"===n?u+.85*(d-u):"target"===n?u+.15*(d-u):(u+d)/2;return{sx:u,sTop:f,sBot:y,tx:d,tTop:b,tBot:x,cp1X:v,cp2X:v}}(t,p[e.source],o,p[e.target],g,d,n,i),{pathD:u,bezier:h}=C(l);y.push({id:e.id,pathD:u,fill:s,opacity:a,rawDatum:e.__raw??e,bezier:h})}),{layout:h,layoutConfig:{bands:f,ribbons:y,showLabels:!0},issues:[],xScale:d}}var ji=e=>{const{bands:t=[],ribbons:o=[],showLabels:i=!0}=e.config,r=[];for(const e of o)r.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:e.opacity,stroke:"none"},datum:{__kind:"ribbon",data:e.rawDatum,id:e.id}});for(const e of t)if(e.gradientStubs)for(let t=0;e.gradientStubs.length>t;t++){const o=e.gradientStubs[t];r.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,from:o.from,to:o.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${t}`}})}for(const e of t)r.push({type:"bezier",pathD:e.pathD,style:{...e.gradientStubs&&e.gradientStubs.length>0?{fill:"none"}:{fill:e.fill,fillOpacity:.86},stroke:e.stroke??e.fill,strokeWidth:e.strokeWidth??.5},datum:{__kind:"band",data:e.rawDatum,id:e.id}});const s=i?t.map(e=>({x:e.labelX,y:e.labelY,text:e.labelText,anchor:"end",baseline:"middle",fontSize:11,fontWeight:600})):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:r,labels:s}};function Di(e,t){if(!e)return[];const o=[],i=e=>{o.push(e);const r="function"==typeof t?t(e):e[t];r&&Array.isArray(r)&&r.forEach(i)};return i(e),o}function Ni(e,t,o,i){if(e&&e.length>0)return e;const r=new Set;return t.forEach(e=>{const t="function"==typeof o?o(e):e[o],s="function"==typeof i?i(e):e[i];r.add(t),r.add(s)}),Array.from(r).map(e=>({id:e}))}import*as $i from"react";function Wi(e,t){return t?"function"==typeof t?o=>({...e(o),...t(o)??{}}):o=>({...e(o),...t}):e}var Gi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const{edgeWidth:s,edgeColor:n,edgeOpacity:a}=r,c=r.edgeStyle??(void 0!==s||void 0!==n||void 0!==a?e=>{const t=e?.data||e;let o=1;if("number"==typeof s)o=s;else if("function"==typeof s)o=s(t);else if("string"==typeof s){const e=t?.[s],i="number"==typeof e?e:Number(e);o=Number.isFinite(i)&&i>0?i:1}return{stroke:n??"#999",strokeWidth:o,opacity:a??.6}}:void 0),l=Et(i.theme).colors.categorical,u=new Map,d=r.nodeStyle??(e=>({fill:t?ye(e?.data||e,t,void 0):je(void 0,l,o,void 0,u),..."number"==typeof r.nodeSize&&{r:r.nodeSize}})),h=w(r.styleRules,t,"number"==typeof r.nodeSize?void 0:r.nodeSize);return{chartType:"force",nodes:r.nodes,edges:r.edges,nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor,sourceAccessor:r.sourceAccessor,targetAccessor:r.targetAccessor,colorBy:t,colorScheme:o,iterations:r.iterations,forceStrength:r.forceStrength,showLabels:r.showLabels??!1,nodeLabel:r.nodeLabel,nodeSize:r.nodeSize??8,nodeSizeRange:r.nodeSizeRange,nodeStyle:h?(e,t)=>({...d(e),...h(e,t)}):d,edgeStyle:c,...i}}},Vi={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,o,i,r)=>{const s=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),n=r.sourceAccessor||"source",a=r.targetAccessor||"target",c=r.valueAccessor||"value",l=r.nodeIdAccessor||"id",u=r.startTimeAccessor||"startTime",d=r.endTimeAccessor||"endTime",h=r.systemInTimeAccessor,p=r.systemOutTimeAccessor,m=r.xExtentAccessor||"xExtent",g=r.edgeIdAccessor||"id",f=(e,t)=>"function"==typeof e?e(t):t[e],y=Array.isArray(r.edges)?r.edges:[],b=Array.isArray(r.nodes)?r.nodes:[],x=b.length>0?b:Ni([],y,n,a),v=[s(r.domain?.[0]),s(r.domain?.[1])],A=x.map(e=>{const t=f(l,e)+"",o=f(m,e),i={id:t,__raw:e};if(Array.isArray(o)&&2===o.length){const e=s(o[0]),t=s(o[1]);Number.isFinite(e)&&Number.isFinite(t)&&(i.xExtent=[e,t])}return i}),w=y.map((e,t)=>{const o=f(g,e),i={id:null!=o?o+"":`${f(n,e)}-${f(a,e)}-${t}`,source:f(n,e)+"",target:f(a,e)+"",value:Number(f(c,e)),startTime:s(f(u,e)),endTime:s(f(d,e)),__raw:e};if(h){const t=s(f(h,e));Number.isFinite(t)&&(i.systemInTime=t)}if(p){const t=s(f(p,e));Number.isFinite(t)&&(i.systemOutTime=t)}return i}),[S,k]=i.size??[600,400],_={top:20,right:20,bottom:20,left:20,...i.margin},M=(i.showLegend??!!t)&&!!t,R=i.legendPosition??"right",P=i.__explicitMargin,L=e=>"number"==typeof P||null!=P&&"object"==typeof P&&null!=P[e];M&&("right"!==R||L("right")?"bottom"!==R||L("bottom")||(_.bottom=Math.max(_.bottom,80)):_.right=Math.max(_.right,140));const I=_,T=S-I.left-I.right,C=k-I.top-I.bottom,z=Et(i.theme),O=Fe(o,z.colors.categorical,vt),F="function"==typeof t?t:null,B=F?x.map(e=>({_cat:F(e)})):x,E=F?"_cat":"string"==typeof t?t:void 0,j=o??[...O],D=E?me(B,E,j):null,N=new Map;for(const e of A)N.set(e.id,e.__raw);const $=(e,o)=>{if(t&&N.has(e)){const o=N.get(e);return F?ye({_cat:F(o)},"_cat",D??void 0):ye(o,"string"==typeof t?t:"id",D??void 0)}return O[o%O.length]},W=M&&t?(()=>{const e=new Map;x.forEach((o,i)=>{const r=f(t,o),s=null==r?"":r+"";s&&!e.has(s)&&e.set(s,{label:s,color:$(f(l,o)+"",i)})});const o=Array.from(e.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:e=>{const t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,G=de(W,i.legend),{layout:V,layoutConfig:H,issues:Y,xScale:X}=Ei({nodes:A,edges:w,domain:v,plotW:T,plotH:C,ribbonLane:r.ribbonLane||"both",edgeOpacity:"number"==typeof r.edgeOpacity?r.edgeOpacity:.35,colorOf:$,layoutOpts:{pairing:r.pairing||"temporal",packing:r.packing||"reuse",laneOrder:r.laneOrder||"crossing-min",lifetimeMode:r.lifetimeMode||"half"}});if(Y.length>0){const e=Y.map(Mi).join("; ");throw Error("ProcessSankey: data invalid — "+e)}const q=Array.isArray(r.axisTicks)?r.axisTicks:[],U=V?(()=>{let e=null,t=null;for(const o of A){const i=V.laneLifetime[o.id];if(!i||null==i.start||null==i.end)continue;const r=Number(X(i.start)),s=Number(X(i.end));e=null==e?r:Math.min(e,r),t=null==t?s:Math.max(t,s)}const o=e=>Math.max(0,Math.min(T,e)),i=o(e??0),n=Math.max(i,o(t??T)),a=q.map((e,t)=>({tick:e,index:t,x:Number(X(s(e.date)))})).filter(({x:e})=>e>=i-.5&&n+.5>=e);return $i.createElement("g",null,...a.map(({index:e,x:t})=>$i.createElement("line",{key:"grid-"+e,x1:t,y1:0,x2:t,y2:C,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),$i.createElement("line",{key:"axis",x1:i,y1:C+4,x2:n,y2:C+4,stroke:"#94a3b8"}),...a.map(({tick:e,index:t,x:o})=>{const i=s(e.date),n=null!=e.label?e.label:"function"==typeof r.timeFormat?r.timeFormat(new Date(i)):"";return $i.createElement("g",{key:"tick-"+t,transform:`translate(${o},${C+4})`},$i.createElement("line",{y2:6,stroke:"#94a3b8"}),$i.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},n))}))})():void 0;return{chartType:"force",nodes:x,edges:y,customNetworkLayout:ji,layoutConfig:H,sourceAccessor:n,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:t,colorScheme:o,...U&&{backgroundGraphics:U},...i,showLegend:M,...G&&{legend:G,legendPosition:R},__legendIncludesAutomatic:!0,margin:I}}},Hi={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,o,i,r)=>{const s=Array.isArray(r.nodes)?r.nodes:Ni([],Array.isArray(r.edges)?r.edges:[],r.sourceAccessor||"source",r.targetAccessor||"target"),n=Et(i.theme).colors.categorical,a=new Map,c="string"==typeof t?t:"__ssrSankeyColorBy",l="function"==typeof t?s.map(e=>({...e,__ssrSankeyColorBy:t(e)})):s,u=t?me(l,c,o??i.colorScheme??n):void 0,d=e=>({fill:t?ye(e?.data||e,t,u):je(void 0,n,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=w(r.styleRules,t,r.valueAccessor),p=h?(e,t)=>({...d(e),...h(e,t)}):d,m=function({edgeColorBy:e,colorBy:t,colorScale:o,nodeStyleFn:i,edgeOpacity:r,baseStyle:s={}}){return n=>{const a={fillOpacity:r,...s};if("function"==typeof e)a.fill=e(n);else if("source"===e){const e="object"==typeof n.source?n.source:null;t&&e?a.fill=ye(e.data||e,t,o):e&&(a.fill=i(e,e.index).fill)}else if("target"===e){const e="object"==typeof n.target?n.target:null;t&&e?a.fill=ye(e.data||e,t,o):e&&(a.fill=i(e,e.index).fill)}else"gradient"===e&&(a.fill="#999",a.fillOpacity=.7*r);return a}}({edgeColorBy:r.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:p,edgeOpacity:r.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:r.nodes,edges:r.edges,nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor,sourceAccessor:r.sourceAccessor,targetAccessor:r.targetAccessor,valueAccessor:r.valueAccessor,orientation:r.orientation,nodeAlign:r.nodeAlign,nodeWidth:r.nodeWidth,nodePaddingRatio:r.nodePaddingRatio,showLabels:r.showLabels,nodeLabel:r.nodeLabel,colorBy:t,edgeColorBy:r.edgeColorBy,edgeOpacity:r.edgeOpacity,nodeStyle:i.nodeStyle||r.nodeStyle||p,edgeStyle:i.edgeStyle||r.edgeStyle||m,colorScheme:o,...i}}},Yi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{if(!(t||Array.isArray(r.styleRules)&&r.styleRules.length>0||i.nodeStyle||r.nodeStyle))return{chartType:"chord",nodes:r.nodes,edges:r.edges,valueAccessor:r.valueAccessor,padAngle:r.padAngle,groupWidth:r.groupWidth,showLabels:r.showLabels,colorBy:t,edgeColorBy:r.edgeColorBy,colorScheme:o,...i};const s=Array.isArray(r.edges)?r.edges:[],n=Array.isArray(r.nodes)&&r.nodes.length>0?r.nodes:Ni([],s,r.sourceAccessor||"source",r.targetAccessor||"target"),a=Et(i.theme).colors.categorical,c=Fe(o,a),l="string"==typeof t?t:"__ssrChordColorBy",u="function"==typeof t?n.map(e=>({...e,__ssrChordColorBy:t(e)})):n,d=t?me(u,l,o??i.colorScheme??a):void 0,h=new Map,p=r.nodeIdAccessor||r.nodeIDAccessor||"id",m=(e,o)=>{const r=e?.data||e;let s;if(t)s=ye(r,t,d);else{const t=(e.id??r?.[p]??"")+"";h.has(t)||h.set(t,h.size);const i=e.index??o??h.get(t);s=c[i%c.length]}return{fill:s,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=w(r.styleRules,t,r.valueAccessor,m)??m;return{chartType:"chord",nodes:r.nodes,edges:r.edges,valueAccessor:r.valueAccessor,padAngle:r.padAngle,groupWidth:r.groupWidth,showLabels:r.showLabels,colorBy:t,edgeColorBy:r.edgeColorBy,colorScheme:o,nodeStyle:i.nodeStyle||r.nodeStyle||g,...i}}},Xi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=Et(i.theme).colors.categorical,n=new Map,a=Di(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreeColorBy:c(e)})):a,u=c?"__ssrTreeColorBy":"string"==typeof t?t:void 0,d=t&&u?me(l,u,o??i.colorScheme??s):void 0,h=i.nodeStyle||r.nodeStyle;return{chartType:"cluster"===r.layout?"cluster":"tree",data:e,childrenAccessor:r.childrenAccessor,colorBy:t,colorByDepth:r.colorByDepth,orientation:r.orientation,showLabels:r.showLabels,nodeLabel:!1!==r.showLabels?r.nodeLabel||r.nodeIdAccessor:void 0,colorScheme:o,...i,nodeStyle:Wi(e=>{const a=e?.data||e;return{fill:r.colorByDepth?se[Number(e?.depth||0)%se.length]:t?c?ye({__ssrTreeColorBy:c(a)},"__ssrTreeColorBy",d??void 0):ye(a,t,d??void 0):je(void 0,s,o,void 0,n),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h)}}},qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=Et(i.theme).colors.categorical,n=new Map,a=Di(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreemapColorBy:c(e)})):a,u=c?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,d=t&&u?me(l,u,o??i.colorScheme??s):void 0,h=r.showLabels??i.showLabels,p=r.labelMode,m=void 0!==r.paddingTop?r.paddingTop:i.paddingTop,g=void 0!==m?m:!h||"parent"!==p&&"all"!==p?void 0:18,f=i.nodeStyle||r.nodeStyle;return{chartType:"treemap",data:e,childrenAccessor:r.childrenAccessor,hierarchySum:r.valueAccessor,colorBy:t,colorByDepth:r.colorByDepth,showLabels:r.showLabels,labelMode:p,nodeLabel:h?r.nodeLabel||r.nodeIdAccessor:void 0,...null!=r.padding&&{padding:r.padding},...null!=g&&{paddingTop:g},colorScheme:o,...i,nodeStyle:Wi(e=>{const i=e?.data||e;return{fill:r.colorByDepth?se[Number(e?.depth||0)%se.length]:t?c?ye({__ssrTreemapColorBy:c(i)},"__ssrTreemapColorBy",d??void 0):ye(i,t,d??void 0):je(void 0,s,o,void 0,n),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},f)}}},Ui={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=Et(i.theme).colors.categorical,n=new Map,a=Di(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrCirclePackColorBy:c(e)})):a,u=c?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,d=t&&u?me(l,u,o??i.colorScheme??s):void 0,h=i.nodeStyle||r.nodeStyle;return{chartType:"circlepack",data:e,childrenAccessor:r.childrenAccessor,hierarchySum:r.valueAccessor,colorBy:t,colorByDepth:r.colorByDepth,showLabels:r.showLabels,nodeLabel:r.showLabels??i.showLabels?r.nodeLabel||r.nodeIdAccessor:void 0,...null!=r.padding&&{padding:r.padding},colorScheme:o,...i,nodeStyle:Wi(e=>{const i=e?.data||e;return{fill:r.colorByDepth?se[Number(e?.depth||0)%se.length]:t?c?ye({__ssrCirclePackColorBy:c(i)},"__ssrCirclePackColorBy",d??void 0):ye(i,t,d??void 0):je(void 0,s,o,void 0,n),fillOpacity:r.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h)}}},Qi={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Ki}from"d3-scale";function Zi(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}var Ji={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s="string"==typeof o?o:"blues",n=r.areaStyle??function(e,t,o,i){if(!Array.isArray(e))return;const r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0;let s=1/0,n=-1/0;for(const t of e){const e=r(t);null!=e&&isFinite(e)&&(s>e&&(s=e),e>n&&(n=e))}const a=Ki(dt(o)).domain([Number.isFinite(s)?s:0,Number.isFinite(n)?n:1]);return e=>{const t=r(e);return{fill:null!=t&&isFinite(t)?a(t):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:i}}}(r.areas,r.valueAccessor,s,r.areaOpacity??1),a=r.styleRules?y(n,r.styleRules,e=>{return{value:(t=e,"function"==typeof r.valueAccessor?r.valueAccessor(t):null!=r.valueAccessor?t?.properties?.[r.valueAccessor]??t?.[r.valueAccessor]:void 0)};var t},Zi):n;return{areas:r.areas,projection:r.projection||"equalEarth",areaStyle:a,valueAccessor:r.valueAccessor,colorScheme:s,graticule:r.graticule,fitPadding:r.fitPadding,...i}}},er={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s=e||r.points,n=r.pointStyle??function(e,t,o,i){const r=Array.isArray(e)?e:[];let s,n;if(t){const e="string"==typeof t?t:"__geoColorBy",i="string"==typeof t?r:r.map(e=>({...e,__geoColorBy:t(e)}));s=me(i,e,o)}if(i.sizeBy){const e=r.map("function"==typeof i.sizeBy?i.sizeBy:e=>e?.[i.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(n=St(e))}return e=>({fill:t&&s?ye(e,t,s):ie,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?xe(e,i.sizeBy,i.sizeRange,n):i.pointRadius??6})}(s,t,o,{sizeBy:r.sizeBy,sizeRange:r.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=r.styleRules?y(n,r.styleRules,b(t,r.sizeBy)):n;return{points:s,xAccessor:r.xAccessor||"lon",yAccessor:r.yAccessor||"lat",areas:r.areas,areaStyle:r.areaStyle||Qi,pointStyle:a,sizeBy:r.sizeBy,colorBy:t,colorScheme:o,projection:r.projection||"equalEarth",graticule:r.graticule,fitPadding:r.fitPadding,...i}}},tr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,r)=>{const s=(Array.isArray(e)?e:null)||r.flows||[],n=r.nodeIdAccessor||"id",a=r.valueAccessor||"value",c=r.xAccessor||"lon",l=r.yAccessor||"lat",u="function"==typeof c?c:e=>e[c],d="function"==typeof l?l:e=>e[l],h=(r.nodes||[]).map(e=>({...e,x:u(e),y:d(e)})),p=new Map;for(const e of h)p.set(e[n]+"",e);const m=r.edgeColorBy??t,g="function"==typeof m,f=s.map(e=>{if(!e||null==e.source||null==e.target)return null;const t=p.get(e.source+""),o=p.get(e.target+"");return t&&o?{...e,coordinates:[{x:t.x,y:t.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),y="__flowMapEdgeColor",b=(()=>{if(!m)return null;if(g){const e=f.map(e=>({[y]:m(e)}));return me(e,y,o||"category10")}return me(f,m,o||"category10")})(),x=e=>m&&b?ye(e,m,b):"#007bff";let v=1/0,A=-1/0;for(const e of f){const t=Number(e[a]??0);isFinite(t)&&(v>t&&(v=t),t>A&&(A=t))}const w=A>v?A-v:0,[S,k]=r.edgeWidthRange??[1,8],_=k-S,M=r.edgeOpacity??.6,R=r.edgeLinecap??"round";return{lines:f,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:r.lineType||"geo",flowStyle:r.flowStyle||"basic",areas:r.areas,areaStyle:r.areaStyle||Qi,projection:r.projection||"equalEarth",graticule:r.graticule,fitPadding:r.fitPadding,colorScheme:o,lineStyle:e=>{const t=Number(e?.[a]),o=Number.isFinite(t)?t:v,i=S+Math.max(0,Math.min(1,w>0?(o-v)/w:0))*_;return{stroke:x(e),strokeWidth:i,strokeLinecap:R,opacity:M,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...i}}};import*as or from"react";function ir(e){const t=lr(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function rr(e,t,o,i){return o?"function"==typeof o?o(e,t):e[o]??i:i}function sr(e){return`gauntlet:${e}:core`}function nr(e,t){return`gauntlet:${e}:positive:${t}`}function ar(e,t,o){return`gauntlet:${e}:negative:${t}:${o}`}var cr={left:28,top:76,rightInset:30,thickness:8};function lr(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return cr;const o=Math.max(1,Math.min(e.width,t)),i=Math.max(2,.04*e.width);return{left:i,top:Math.max(2,.08*t),rightInset:i,thickness:Math.max(1,Math.min(4,.04*o))}}function ur(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function dr(e,t,o,i){const r=lr(i),s=Math.max(2,o+2),n=r.top+r.thickness/2+s,a=i.floorY-s,c=(e,t,o)=>t>o?(t+o)/2:Math.max(t,Math.min(o,e));return{x:c(e,r.left+r.thickness/2+s,i.width-r.rightInset-r.thickness/2-s),y:c(t,n,a)}}function hr(e,t,o=1){const i=[...e].sort((e,t)=>e.localeCompare(t)),r=Math.max(0,i.indexOf(t));return{angle:.82*-Math.PI+(i.length>1?r/(i.length-1):.5)*Math.PI*.64,index:r,radius:(48+r%2*6)*o}}function pr(e,t,o){const i=e.activePositiveIds.reduce((e,o)=>e+(t.get(o)?.value??1),0),r=e.missingPositiveIds.length+e.poppedPositiveIds.length,s=e.negativeIds.reduce((e,t)=>e+(o.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*s-1.2*e.delay-5*r))}function mr(e){const t=function(e,t,o){const[i,r]=e,s=220>i||160>r,n=Math.round(.48*r),a=s?r-Math.max(3,Math.min(12,.1*r)):r-36,c=(t??[]).filter(e=>!1!==e.enabled),l=Math.max(1,c.length),u=.22*i,d=l>1?(.78*i-u)/(l-1):0,h=s?Math.max(Math.round(.12*i),.08*i+6):Math.max(Math.round(.14*i),110);return{crashY:a-(s?Math.min(o,Math.max(3,.22*r)):o),floorY:a,gates:c.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(s?8:54,Math.round(.07*i))})),graveyardX:Math.round(i*(s?.72:.84)),graveyardY:a-4,height:r,routeY:n,socketX:Math.round(i*(s?.82:.92)),startX:h,width:i}}(e.size??[900,520],e.gates,e.crashOffset??30),o=e.positiveProperties??[],i=new Map(o.map(e=>[e.id,e])),r=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),s={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},n=(e.data??[]).map((t,n)=>{const a=function(e,t,o,i,r){const s=rr(e,t,o.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",n=i.map(e=>e.id),a=[...rr(e,t,o.positiveAccessor,n)],c=[...rr(e,t,o.negativeAccessor,[])].filter(e=>r.has(e));return{id:s,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...rr(e,t,o.metricsAccessor,{})},missingPositiveIds:n.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(rr(e,t,o.startTimeAccessor,0))||0),stage:"project filed",viability:rr(e,t,o.initialViability,100)}}(t,n,s,o,r);return{...a,viability:e.viability?.(a,{negativeProperties:r,positiveProperties:i})??pr(a,i,r)}}),a=n.flatMap((o,s)=>{const n=function(e,t,o,i){const r=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(o),s=i?.(e,t,o)??{};return{...r,...s,startY:s.startY??s.routeY??r.startY,socketY:s.socketY??s.routeY??r.socketY,graveyardY:s.graveyardY??r.graveyardY}}(o,s,t,e.projectPlacement);return function(e,t,o,i,r,s,n){const a=ur(o),c=Math.max(3,28*a),l=i.startX,u=i.startY+(i.startY===o.routeY?38*t*a:0),d=n?.(e,t,o,i)??{},h=d.x??l,p=d.y??u,m={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...d,id:sr(e.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:c},spawnAt:d.spawnAt??e.startedAt,datum:m}],f=dr(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||c,o);g[0].x=f.x,g[0].y=f.y;for(const t of e.activePositiveIds){const i=r.get(t);if(!i)continue;const s=hr(e.activePositiveIds,t,a),n=i.radius??Math.max(2,10*a),c=dr(f.x+Math.cos(s.angle)*s.radius,f.y+Math.sin(s.angle)*s.radius,n,o);g.push({id:nr(e.id,t),x:c.x,y:c.y,vx:18*Math.cos(s.angle),vy:18*Math.sin(s.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:n},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:sr(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+s.index%2*4)*a),...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const r=s.get(t);r&&g.push(function(e,t,o,i,r,s,n){const a=ur(s),c=t.radius??Math.max(2,7.2*a),l=dr(i+(o%4*12-12)*a,r+(54+12*Math.floor(o/4))*a,c,s);return{id:ar(e.id,t.id,o),x:l.x,y:l.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:n,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:sr(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...t.spring??{}}]}}(e,r,i,f.x,f.y,o,d.spawnAt??e.startedAt))}),g}(o,s,t,n,i,r,e.coreBody)});return{layout:t,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:ir(t)}}}var gr=1e-9;function fr(e,t){return t>e?-1:e>t?1:0}function yr(e){return{...e}}function br(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function xr(e){const t=Object.fromEntries(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:yr(t.initialMetrics),metrics:yr(t.metrics),productIds:[...t.productIds],history:br(t.history)}])),o=Object.fromEntries(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:yr(t.metrics),sourceIds:[...t.sourceIds],history:br(t.history)}])),i=Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?yr(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:o,relations:i,input:{amount:e.input.amount,metrics:yr(e.input.metrics)},metrics:yr(e.metrics),loss:{amount:e.loss.amount,metrics:yr(e.loss.metrics)},history:br(e.history)}}function vr(e,t,o,i,r){return{severity:e,code:t,message:o,path:i,ids:r?[...r]:void 0}}function Ar(e){const t=new Set,o=new Set;for(const i of e)t.has(i)&&o.add(i),t.add(i);return[...o].sort(fr)}function wr(e,t){return e?Object.entries(e).flatMap(([e,o])=>Number.isFinite(o)?[]:[vr("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function Sr(e,t){for(const[o,i]of Object.entries(t))e[o]=Number(e[o]??0)+i}function kr(e,t,o="selector"){const i=[],r=Object.values(e.components),s=new Set(r.map(e=>e.id)),n=(t.ids??[]).filter(e=>!s.has(e));if(n.length&&i.push(vr("error","unknown-component",`Selector references unknown component id${1===n.length?"":"s"}: ${n.join(", ")}.`,o+".ids",n)),void 0===t.count||Number.isInteger(t.count)&&t.count>=0||i.push(vr("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),i.some(e=>"error"===e.severity))return{ids:[],diagnostics:i};const a=t.ids?new Set(t.ids):null,c=t.categories?new Set(t.categories):null,l=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null;let d=r.filter(e=>!a||a.has(e.id)).filter(e=>!c||c.has(e.category)).filter(e=>!l||l.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(fr);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||i.push(vr("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:i}}function _r(e,t,o={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...o}}function Mr(e,t){const o={...t,eventId:e.event.id};e.materializations.push(o),e.observations.push({...o,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function Rr(e,t,o){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(vr("error","unknown-outlet",`Unknown outlet "${t}".`,o,[t])),1))}function Pr(e,t,o){const i=Ar(t);t.length||e.diagnostics.push(vr("error","empty-source-list","A product requires at least one source component.",o)),i.length&&e.diagnostics.push(vr("error","duplicate-source",`Source ids may appear only once: ${i.join(", ")}.`,o,i));const r=t.filter(t=>!e.state.components[t]);r.length&&e.diagnostics.push(vr("error","unknown-component",`Unknown source component id${1===r.length?"":"s"}: ${r.join(", ")}.`,o,r));const s=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);s.length&&e.diagnostics.push(vr("error","source-already-assigned",`Source component${1===s.length?" is":"s are"} already assigned: ${s.join(", ")}.`,o,s));const n=t.filter(t=>"consumed"===e.state.components[t]?.status&&!s.includes(t));return n.length&&e.diagnostics.push(vr("error","source-unavailable",`Consumed source component${1===n.length?" is":"s are"} unavailable: ${n.join(", ")}.`,o,n)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function Lr(e,t,o,i,r){const s=i?.amount??0;(!Number.isFinite(s)||0>s||s>t+gr)&&e.diagnostics.push(vr("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",r+".amount")),e.diagnostics.push(...wr(i?.metrics,r+".metrics"));for(const[t,s]of Object.entries(i?.metrics??{}))(0>s||s>Number(o[t]??0)+gr)&&e.diagnostics.push(vr("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${r}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function Ir(e,t,o,i,r,s,n){return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:s&&void 0!==e.amount?e.amount:o,metrics:s&&e.metrics?{...i,...e.metrics}:i,status:s?"complete":"forming",sourceIds:[...t],outletId:s?e.outletId??(r.outletIds.has("product")?"product":void 0):void 0,createdByEventId:r.event.id,createdAt:r.context.appliedAt,completedByEventId:s?r.event.id:void 0,completedAt:s?r.context.appliedAt:void 0,history:[n]}}function Tr(e,t,o,i){void 0!==t.amount&&Math.abs(t.amount-o)>gr&&e.diagnostics.push(vr("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${o}.`,i,[t.id]))}function Cr(e,t,o){const i=`events.${e.event.id}.effects.${o}`,r=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(vr("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,i+".state")),e.diagnostics.push(...wr(t.metricsDelta,i+".metricsDelta")),Rr(e,t.outletId,i+".outletId");const o=kr(r,t.select,i+".select");e.diagnostics.push(...o.diagnostics);const s=o.ids.filter(e=>r.components[e].productIds.length);if(s.length&&e.diagnostics.push(vr("error","source-already-assigned",`Assigned source components cannot be retargeted: ${s.join(", ")}.`,i+".select",s)),e.diagnostics.some(e=>"error"===e.severity))return;const n=_r(e,t,{sourceIds:o.ids,outletIds:t.outletId?[t.outletId]:void 0});for(const e of o.ids){const o=r.components[e];o.status=t.state,o.outletId=t.outletId,o.reason=t.reason,t.metricsDelta&&Sr(o.metrics,t.metricsDelta),o.history.push(n)}return r.history.push(n),void(o.ids.length&&Mr(e,{type:"retarget-component",sourceIds:o.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){const{relation:o}=t;o.id&&!r.relations[o.id]||e.diagnostics.push(vr("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,i+".relation.id",[o.id]));const s=function(e,t,o){const i=Ar(t),r=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(vr("error","insufficient-relation-sources","A relation requires at least two source components.",o)),i.length&&e.diagnostics.push(vr("error","duplicate-source",`Relation source ids must be unique: ${i.join(", ")}.`,o,i)),r.length&&e.diagnostics.push(vr("error","unknown-component",`Relation references unknown source component${1===r.length?"":"s"}: ${r.join(", ")}.`,o,r)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,o.sourceIds,i+".relation.sourceIds");if(e.diagnostics.push(...wr(o.metrics,i+".relation.metrics")),!s||e.diagnostics.some(e=>"error"===e.severity))return;r.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?{...o.metrics}:void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};const n=_r(e,t,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return r.history.push(n),void Mr(e,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===t.type){const o=Ar(t.relationIds),s=t.relationIds.filter(e=>!r.relations[e]),n=t.relationIds.filter(e=>"resolved"===r.relations[e]?.status);if(o.length&&e.diagnostics.push(vr("error","duplicate-relation","Relation ids must be unique.",i+".relationIds",o)),s.length&&e.diagnostics.push(vr("error","unknown-relation",`Unknown relation: ${s.join(", ")}.`,i+".relationIds",s)),n.length&&e.diagnostics.push(vr("error","resolved-relation",`Relation is already resolved: ${n.join(", ")}.`,i+".relationIds",n)),e.diagnostics.some(e=>"error"===e.severity))return;for(const o of t.relationIds){const i=r.relations[o];i.status="resolved",i.resolution=t.resolution,i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt,i.reason=t.reason}const a=_r(e,t,{relationIds:[...t.relationIds]});return r.history.push(a),void Mr(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){const o=e.productDefinitions.get(t.productId);o||e.diagnostics.push(vr("error","unknown-product",`Product "${t.productId}" has no declared mold.`,i+".productId",[t.productId]));const s=r.products[t.productId];"combine"===t.type&&s&&e.diagnostics.push(vr("error","duplicate-product",`Product "${t.productId}" has already been formed.`,i+".productId",[t.productId])),"contribute"!==t.type||s&&"forming"===s.status||e.diagnostics.push(vr("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,i+".productId",[t.productId]));const n=Pr(e,t.sourceIds,i+".sourceIds"),a="contribute"===t.type&&s?[...s.sourceIds,...t.sourceIds]:t.sourceIds,c=function(e,t,o,i){if(!t?.length)return[];const r=Ar(t),s=t.filter(t=>!e.state.relations[t]),n=t.filter(t=>"resolved"===e.state.relations[t]?.status),a=new Set(o),c=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!a.has(e)));return r.length&&e.diagnostics.push(vr("error","duplicate-relation","Basis relations must be unique.",i,r)),s.length&&e.diagnostics.push(vr("error","unknown-relation",`Unknown basis relation: ${s.join(", ")}.`,i,s)),n.length&&e.diagnostics.push(vr("error","resolved-relation",`Basis relation is already resolved: ${n.join(", ")}.`,i,n)),c.length&&e.diagnostics.push(vr("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,i,c)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,a,i+".basisRelationIds");if(!n||!c||!o||e.diagnostics.some(e=>"error"===e.severity))return;const l=n.reduce((e,t)=>e+t.amount,0),u=function(e){const t={};for(const o of e)Sr(t,o.metrics);return t}(n);if(!Lr(e,l,u,t.loss,i+".loss"))return;const d=l-(t.loss?.amount??0);!function(e,t,o){e.state.loss.amount+=o?.amount??0;for(const[i,r]of Object.entries(o?.metrics??{}))t[i]=Number(t[i]??0)-r,e.state.loss.metrics[i]=Number(e.state.loss.metrics[i]??0)+r}(e,u,t.loss);const h="combine"===t.type&&!1!==t.complete,p=_r(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});let m;if("combine"===t.type){if(h&&Tr(e,o,d,i+".productId"),m=Ir(o,t.sourceIds,d,u,e,h,p),h&&!Rr(e,m.outletId,i+".productId"))return;r.products[t.productId]=m}else m=s,m.sourceIds.push(...t.sourceIds),m.amount+=d,Sr(m.metrics,u),m.history.push(p);for(const e of n)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(p);return r.history.push(p),function(e,t){if(t.length){for(const o of t)o.status="resolved",o.resolution="combined",o.resolvedByEventId=e.event.id,o.resolvedAt=e.context.appliedAt;Mr(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,c),Mr(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:m.outletId?[m.outletId]:void 0}),void(h&&Mr(e,{type:"complete-product",sourceIds:[...m.sourceIds],productIds:[m.id],outletIds:m.outletId?[m.outletId]:void 0}))}if("complete-product"===t.type){const o=r.products[t.productId];return o?void function(e,t,o,i,r,s){const n=e.productDefinitions.get(t.id),a=o??n?.outletId??(e.outletIds.has("product")?"product":void 0);if(!Rr(e,a,s+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(vr("error","product-already-complete",`Product "${t.id}" is already complete.`,s,[t.id]));n&&(Tr(e,n,t.amount,s+".productId"),void 0!==n.amount&&(t.amount=n.amount),n.metrics&&(t.metrics={...t.metrics,...n.metrics})),t.status="complete",t.outletId=a,t.reason=i,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;const c=_r(e,r,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0});t.history.push(c),e.state.history.push(c),Mr(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0})}(e,o,t.outletId,t.reason,t,i):void e.diagnostics.push(vr("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,i+".productId",[t.productId]))}if("split"===t.type){const o=Pr(e,[t.sourceId],i+".sourceId");t.products.length||e.diagnostics.push(vr("error","empty-split","A split requires at least one product allocation.",i+".products"));const s=t.products.map(e=>e.productId),n=Ar(s);n.length&&e.diagnostics.push(vr("error","duplicate-product","Split product ids must be unique.",i+".products",n));const a=s.map(t=>e.productDefinitions.get(t)),c=s.filter((e,t)=>!a[t]),l=s.filter(e=>r.products[e]);c.length&&e.diagnostics.push(vr("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,i+".products",c)),l.length&&e.diagnostics.push(vr("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,i+".products",l));for(const[o,r]of t.products.entries())void 0===r.amount||Number.isFinite(r.amount)&&r.amount>=0||e.diagnostics.push(vr("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${i}.products.${o}.amount`)),e.diagnostics.push(...wr(r.metrics,`${i}.products.${o}.metrics`));if(!o?.length||e.diagnostics.some(e=>"error"===e.severity))return;const u=o[0];if(!Lr(e,u.amount,u.metrics,t.loss,i+".loss"))return;const d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??a[t]?.amount),p=h.filter(e=>void 0!==e).length;if(0!==p&&p!==h.length)return void e.diagnostics.push(vr("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",i+".products"));const m=p?h:t.products.map(()=>d/t.products.length),g=m.reduce((e,t)=>e+t,0);if(Math.abs(g-d)>gr)return void e.diagnostics.push(vr("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,i+".products"));const f={...u.metrics};for(const[e,o]of Object.entries(t.loss?.metrics??{}))f[e]=Number(f[e]??0)-o;const y=_r(e,t,{sourceIds:[u.id],productIds:s});if(t.products.forEach((o,s)=>{const n=a[s],c=d>gr?m[s]/d:1/t.products.length,l=Object.fromEntries(Object.entries(f).map(([e,t])=>[e,t*c])),h=o.metrics??n.metrics??l,p=Ir({...n,amount:m[s],metrics:h},[u.id],m[s],{...h},e,!0,y);Rr(e,p.outletId,`${i}.products.${s}.productId`)&&(r.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=s,u.status="consumed",u.outletId=void 0,u.history.push(y),r.loss.amount+=t.loss?.amount??0;for(const[e,o]of Object.entries(t.loss?.metrics??{}))r.loss.metrics[e]=Number(r.loss.metrics[e]??0)+o;r.history.push(y),Mr(e,{type:"split-source",sourceIds:[u.id],productIds:s});for(const t of s)Mr(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:r.products[t].outletId?[r.products[t].outletId]:void 0});return}if("eject"===t.type){Rr(e,t.outletId,i+".outletId");const o=kr(r,t.select,i+".select");e.diagnostics.push(...o.diagnostics);const s=o.ids.filter(e=>r.components[e].productIds.length);if(s.length&&e.diagnostics.push(vr("error","source-already-assigned",`Assigned source components cannot be ejected: ${s.join(", ")}.`,i+".select",s)),e.diagnostics.some(e=>"error"===e.severity))return;const n=_r(e,t,{sourceIds:o.ids,outletIds:[t.outletId]});for(const e of o.ids){const o=r.components[e];o.status=t.state??"ejected",o.outletId=t.outletId,o.reason=t.reason,o.history.push(n)}return r.history.push(n),void(o.ids.length&&Mr(e,{type:"retarget-component",sourceIds:o.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...wr(t.metricsDelta,i+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let o,s;if("run"===t.target)Sr(r.metrics,t.metricsDelta);else if("components"in t.target){const s=kr(r,t.target.components,i+".target.components");if(e.diagnostics.push(...s.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;o=s.ids;for(const e of s.ids)Sr(r.components[e].metrics,t.metricsDelta)}else{s=[...t.target.productIds];const o=Ar(s),n=s.filter(e=>!r.products[e]);if(o.length&&e.diagnostics.push(vr("error","duplicate-product","Metric target product ids must be unique.",i+".target.productIds",o)),n.length&&e.diagnostics.push(vr("error","unknown-product-state",`Metric target product has not formed: ${n.join(", ")}.`,i+".target.productIds",n)),e.diagnostics.some(e=>"error"===e.severity))return;for(const e of s)Sr(r.products[e].metrics,t.metricsDelta)}return void r.history.push(_r(e,t,{sourceIds:o,productIds:s}))}t.outcome.trim()?(r.outcome=t.outcome,r.summary=t.summary,r.history.push(_r(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(vr("error","invalid-outcome","Outcome must be a non-empty string.",i+".outcome"))}function zr(e,t,o){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[vr("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};const i=xr(e),r={state:i,event:t,context:o,productDefinitions:new Map(o.products.map(e=>[e.id,e])),outletIds:new Set(o.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,i]of t.effects.entries())if(Cr(r,i,o),r.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:r.diagnostics};return i.elapsed=Math.max(i.elapsed,o.appliedAt),i.phaseId=o.phaseId,i.eventsApplied.push(t.id),r.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:i,materializations:r.materializations,observations:r.observations,diagnostics:r.diagnostics}}var Or=[900,520],Fr=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Br=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Er=1e-9;function jr(e,t){return t>e?-1:e>t?1:0}function Dr(e,t,o,i,r){return{severity:e,code:t,message:o,path:i,ids:r?[...r]:void 0}}function Nr(e){const t=new Set,o=new Set;for(const i of e)t.has(i)&&o.add(i),t.add(i);return[...o].sort(jr)}function $r(e){const t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Wr(e,t,o,i,r,s){if(!o)return i;try{return("function"==typeof o?o(e,t):e[o])??i}catch(e){return r.push(Dr("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,s)),i}}function Gr(e,t,o){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(Dr("error","invalid-metrics","Metrics must be a numeric object.",o)),{};const i={};for(const[r,s]of Object.entries(e)){const e=$r(s);null!=e?i[r]=e:t.push(Dr("error","invalid-metric",`Metric "${r}" must be finite.`,`${o}.${r}`))}return i}function Vr(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Hr(e){const{id:t,orientation:o,fixed:i,start:r,end:s,openings:n,thickness:a,friction:c,restitution:l}=e,u=function(e,t,o){const i=o.map(([o,i])=>[Math.max(e,Math.min(o,i)),Math.min(t,Math.max(o,i))]).filter(([e,t])=>t>e+Er).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),r=[];let s=e;for(const[e,t]of i)e>s+Er&&r.push([s,e]),s=Math.max(s,t);return t>s+Er&&r.push([s,t]),r}(r,s,n);return u.map(([e,r],s)=>({id:1===u.length?t:`${t}:${s}`,friction:c,restitution:l,shape:"horizontal"===o?{type:"segment",x1:e,y1:i,x2:r,y2:i,thickness:a}:{type:"segment",x1:i,y1:e,x2:i,y2:r,thickness:a}}))}function Yr(e){let t=2166136261;for(let o=0;e.length>o;o+=1)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return t>>>0}function Xr(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?Yr(e):1}function qr(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:Xr(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ur(e){return"crucible:component:"+encodeURIComponent(e)}function Qr(e,t,o,i){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const r=Math.min(...t,e),s=Math.max(...t,e);return s-r>Er?i[0]+(i[1]-i[0])*Math.sqrt(Math.max(0,e-r)/(s-r)):(i[0]+i[1])/2}function Kr(e,t){const o=Math.max(.25,Math.min(1,t.width/900,t.height/520)),i=e?.[0]??7*o,r=e?.[1]??18*o,s=Math.max(1,Math.min(i,r));return[s,Math.max(s,Math.max(i,r))]}function Zr(e,t){if(!e)return[];const o=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),i=Math.max(1,Math.ceil(e/o));return Array.from({length:e},(e,r)=>({x:t.x+t.width/o*(r%o+.5),y:t.y+(Math.floor(r/o)+.5)*(t.height/i)}))}function Jr(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function es(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function ts(e,t,o={}){const i=Object.values(e.products).sort((e,t)=>jr(e.id,t.id)),r=Object.values(e.components).sort((e,t)=>jr(e.id,t.id)),s=[...r.map(e=>e.amount),...i.map(e=>e.amount)],n=Kr(o.radiusRange,t),a=function(e,t){const o=new Map;for(const t of e){const e=t.outletId??"__chamber__",i=o.get(e)??[];i.push(t),o.set(e,i)}const i=new Map;for(const[e,r]of o){r.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||jr(e.id,t.id));const o=Zr(r.length,es(t,"__chamber__"===e?void 0:e));r.forEach((e,t)=>i.set(e.id,o[t]))}return i}(i,t),c=i.map(e=>{const i=a.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},r=1.28*Qr(e.amount,s,o.bodyRadius,n),c={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:(l=e.id,"crucible:product:"+encodeURIComponent(l)),x:i.x,y:i.y,mass:Math.max(.25,r*r*.018),bodyCollisions:!1,shape:{type:"circle",radius:r},datum:c};var l}),l=new Map;for(const e of r.filter(e=>!e.productIds.length)){const t=Jr(e)??"__chamber__",o=l.get(t)??[];o.push(e),l.set(t,o)}const u=new Map;for(const[e,o]of l){const i=Zr(o.length,es(t,"__chamber__"===e?void 0:e));o.forEach((e,t)=>u.set(e.id,i[t]))}return[...r.map(e=>{let i=u.get(e.id);if(e.productIds.length){const o=e.productIds.map(e=>a.get(e)).filter(e=>!!e);if(o.length){i={x:o.reduce((e,t)=>e+t.x,0)/o.length,y:o.reduce((e,t)=>e+t.y,0)/o.length};const r=Yr(e.id)/4294967295*Math.PI*2,s=Math.min(20,Math.max(4,.012*t.width));i={x:i.x+Math.cos(r)*s,y:i.y+Math.sin(r)*s}}}i??(i={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});const r=Qr(e.amount,s,o.bodyRadius,n),c={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Ur(e.id),x:i.x,y:i.y,mass:Math.max(.25,r*r*.015),shape:{type:"circle",radius:r},datum:c}}),...c]}var os=ts;function is(e){return Array.isArray(e)?e.map(is):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>jr(e,t)).map(([e,t])=>[e,is(t)])):e}function rs(e,t=e.duration){const o=function(e,t){const o=$r(t)??0,i=Math.max(0,Math.min(e.duration,o));if(!e.phases.length)return{elapsed:i,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const r=i>=e.duration-Er,s=r?e.phases[e.phases.length-1]:e.phases.find(e=>i>=e.start&&e.end>i)??e.phases[0];return{elapsed:i,phaseId:s.id,phaseIndex:s.index,phaseElapsed:r?s.duration:Math.max(0,i-s.start),complete:r}}(e,t);let i=xr(e.initialState);const r=[],s=[],n=[];for(const t of e.events){if(t.authoredAt>o.elapsed+Er)break;const a=zr(i,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});r.push(...a.diagnostics),s.push(...a.materializations),n.push(...a.observations),a.applied&&(i=a.state)}return i.elapsed=o.elapsed,i.phaseId=o.phaseId,i.phaseIndex=o.phaseIndex,i.phaseElapsed=o.phaseElapsed,i.complete=o.complete,o.complete&&"in_process"===i.outcome&&(i.outcome="complete"),i.playing=!1,{state:i,diagnostics:r,materializations:s,observations:n}}function ss(e){const t=function(e){const t=[];e.length||t.push(Dr("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Nr(e.map(e=>e.id));o.length&&t.push(Dr("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let i=0;return{phases:e.map((e,o)=>{const r=$r(e.duration),s=null!=r&&r>0?r:0;e.id.trim()||t.push(Dr("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=r&&r>0||t.push(Dr("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[e.id])),void 0===e.intensity||Number.isFinite(e.intensity)||t.push(Dr("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[e.id]));const n={...e,duration:s,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:o,start:i,end:i+s};return i=n.end,n}),diagnostics:t}}(e.phases),o=t.phases.at(-1)?.end??0,i=Vr(e.outlets??Fr),r=(e.products??[]).map(e=>({...e,metrics:e.metrics?{...e.metrics}:void 0})),s=function(e,t,o){const i=[],r=Nr(e.map(e=>e.id));r.length&&i.push(Dr("error","duplicate-event-id",`Event ids must be unique: ${r.join(", ")}.`,"events",r));const s=[];return e.forEach((e,r)=>{let n,a,c;if(e.id.trim()||i.push(Dr("error","invalid-event-id","Event ids may not be empty.",`events.${r}.id`)),"time"in e.at&&void 0!==e.at.time){const s=$r(e.at.time);if(null==s||0>s||s>o+Er)return void i.push(Dr("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${r}.at.time`,[e.id]));n=Math.max(0,Math.min(o,s));const l=function(e,t,o){const i=e.find(e=>Er>=Math.abs(e.start-o));if(i)return{phase:i,boundaryRank:1};const r=e.find(e=>o>=e.start&&e.end>o);return r?{phase:r,boundaryRank:0}:Er>=Math.abs(o-t)&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,o,n);a=l.phase,c=l.boundaryRank}else{if(a=t.find(t=>t.id===e.at.phaseId),!a)return void i.push(Dr("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${r}.at.phaseId`,[e.id,e.at.phaseId]));const o=e.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void i.push(Dr("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${r}.at.progress`,[e.id]));n=a.start+a.duration*o,c=0===o?1:0}a?s.push({...e,index:r,authoredAt:n,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):i.push(Dr("error","event-without-phase","Event could not be assigned to a phase.",`events.${r}.at`,[e.id]))}),s.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:s,diagnostics:i}}(e.events??[],t.phases,o),n=function(e){const t=[],o={},i=[];let r=0;const s={};e.data.forEach((n,a)=>{const c=(n.id??"component-"+a)+"",l=((Wr(n,a,e.idAccessor,c,t,`data.${a}.id`)??c)+"").trim();if(!l)return void t.push(Dr("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));i.push(l);const u=$r(Wr(n,a,e.amountAccessor,1,t,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&t.push(Dr("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=Gr(Wr(n,a,e.metricsAccessor,{},t,`data.${a}.metrics`),t,`data.${a}.metrics`),p=Wr(n,a,e.initialStateAccessor,"active",t,`data.${a}.status`),m=Br.has(p)?p:"active";Br.has(p)||t.push(Dr("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[l]));const g=Wr(n,a,e.labelAccessor,(n.label??n.name??l)+"",t,`data.${a}.label`)+"",f=Wr(n,a,e.categoryAccessor,"component",t,`data.${a}.category`)+"";o[l]||(o[l]={id:l,label:g,category:f,datum:n,status:m,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},r+=d,function(e,t){for(const[o,i]of Object.entries(t))e[o]=Number(e[o]??0)+i}(s,h))});const n=Nr(i);n.length&&t.push(Dr("error","duplicate-component-id",`Component ids must be unique: ${n.join(", ")}.`,"data",n));const a=Gr(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:{},relations:{},input:{amount:r,metrics:s},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:t}}(e),a=function(e=Or,t=Fr){const o=Math.max(1,$r(e[0])??900),i=Math.max(1,$r(e[1])??520),r=360>o||260>i,s=r?Math.max(4,.035*Math.min(o,i)):20,n=r?Math.max(10,.075*i):34,a={x:s,y:s,width:Math.max(1,o-2*s),height:n},c=r?Math.max(16,.14*i):Math.min(78,.16*i),l={x:s,y:i-s-c,width:Math.max(1,o-2*s),height:c},u=r?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(r?12:38),h=l.y-(r?10:34),p={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},m=Math.max(18,Math.min(.32*p.width,r?84:180)),g={x:p.x+(p.width-m)/2,y:p.y-(r?10:24),width:m,height:r?12:28},f=Vr(t),y={left:f.filter(e=>"left"===(e.side??"bottom")),right:f.filter(e=>"right"===e.side),bottom:f.filter(e=>"bottom"===(e.side??"bottom"))},b=[],x=(e,t)=>{const i=Math.max(8,u-1.5*s),n=p.height/Math.max(1,t.length);t.forEach((t,a)=>{b.push({...t,side:e,x:"left"===e?s:o-s-i,y:p.y+a*n,width:i,height:Math.max(8,n-(r?2:8))})})};x("left",y.left),x("right",y.right);const v=p.width/Math.max(1,y.bottom.length);return y.bottom.forEach((e,t)=>{b.push({...e,side:"bottom",x:p.x+t*v,y:p.y+p.height+(r?2:7),width:Math.max(8,v-(r?2:8)),height:Math.max(8,l.y-p.y-p.height-(r?4:12))})}),b.sort((e,t)=>f.findIndex(t=>t.id===e.id)-f.findIndex(e=>e.id===t.id)),{width:o,height:i,phaseRail:a,chamber:p,mouth:g,projection:l,outlets:b}}(e.size??Or,i),c=function(e){const{chamber:t,mouth:o}=e,i=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),r=Math.max(t.x,o.x),s=Math.min(t.x+t.width,o.x+o.width),n={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:r,y2:t.y,thickness:i}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:s,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:i}}];a.push(...Hr({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:n.left.map(e=>[e.y,e.y+e.height]),thickness:i,friction:.46,restitution:.12}),...Hr({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:n.right.map(e=>[e.y,e.y+e.height]),thickness:i,friction:.46,restitution:.12}),...Hr({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:n.bottom.map(e=>[e.x,e.x+e.width]),thickness:i,friction:.5,restitution:.08}));for(const t of e.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(t.id),sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return a}(a),l=function(e,t){const o=[],i=new Set(t.map(e=>e.id)),r=Nr(t.map(e=>e.id)),s=Nr(e.map(e=>e.id));return r.length&&o.push(Dr("error","duplicate-outlet-id",`Outlet ids must be unique: ${r.join(", ")}.`,"outlets",r)),s.length&&o.push(Dr("error","duplicate-product-id",`Product ids must be unique: ${s.join(", ")}.`,"products",s)),t.forEach((e,t)=>{e.id.trim()||o.push(Dr("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0===e.order||Number.isFinite(e.order)||o.push(Dr("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||o.push(Dr("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0===e.amount||Number.isFinite(e.amount)&&e.amount>=0||o.push(Dr("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0===e.outletId||i.has(e.outletId)||o.push(Dr("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Gr(e.metrics??{},o,`products.${t}.metrics`)}),o}(r,i),u=(d={seed:e.seed??1,components:Object.values(n.state.components).sort((e,t)=>jr(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:o,description:i,intensity:r,motion:s,color:n,metrics:a})=>({id:e,duration:t,label:o,description:i,intensity:r,motion:s,color:n,metrics:a})),products:r,outlets:i,events:s.events.map(({id:e,label:t,description:o,summary:i,authoredAt:r,phaseId:s,boundaryRank:n,effects:a})=>({id:e,label:t,description:o,summary:i,authoredAt:r,phaseId:s,boundaryRank:n,effects:a}))},JSON.stringify(is(d)));var d;const h=function(e,t,o={}){const i=Object.values(e.components).sort((e,t)=>jr(e.id,t.id)),r=i.map(e=>e.amount),s=Kr(o.radiusRange,t),n=function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(Xr(o.seed)),a=t.mouth.x+t.mouth.width/2,c=t.chamber.y+Math.max(18,.18*t.chamber.height),l=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return i.map((e,t)=>{const d=t/Math.max(1,i.length)*Math.PI*2+.18*(n()-.5),h=Qr(e.amount,r,o.bodyRadius,s),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Ur(e.id),x:a+Math.cos(d)*l*(.45+.45*n()),y:c+Math.sin(d)*u*(.45+.45*n()),vx:24*(n()-.5),vy:18*(n()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(n.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p=[...t.diagnostics,...s.diagnostics,...n.diagnostics,...l],m={phases:t.phases,events:s.events,products:r,outlets:i,duration:o,initialState:n.state,terminalState:n.state,layout:a,colliders:c,config:qr(e.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:p},g=rs(m),f=Object.values(g.state.products).filter(e=>"forming"===e.status).map(e=>e.id),y=f.length?[Dr("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${f.join(", ")}.`,"events",f)]:[];return m.terminalState=g.state,m.terminalSpawns=os(g.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),m.diagnostics=[...p,...g.diagnostics,...y],m}import*as ns from"react";import{jsx as as,jsxs as cs}from"react/jsx-runtime";function ls(e){return Number.isFinite(e)?1e3>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):e.toLocaleString():"0"}function us(e,t,o,i){const r=e.datum;if(!r?.__crucible)return;const s="circle"===e.shape.type?e.shape.radius:8,n="string"==typeof t.fill?t.fill:"product"===r.kind?"#b8792d":"#356b63",a="string"==typeof t.stroke?t.stroke:"#26323a",c="number"==typeof t.strokeWidth?t.strokeWidth:1.25,l="number"==typeof t.opacity?t.opacity:.96,u=i?`${i}-crucible-body-${o}`:"crucible-body-"+o;if("product"===r.kind){const t=Array.from({length:6},(t,o)=>{const i=-Math.PI/2+o/6*Math.PI*2;return`${e.x+Math.cos(i)*s},${e.y+Math.sin(i)*s}`}).join(" "),o=u+"-glow";return cs(ns.Fragment,{children:[as("defs",{children:as("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:as("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:n,floodOpacity:"0.8"})})}),as("polygon",{points:t,fill:n,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),as("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*s),fill:"none",stroke:"var(--semiotic-background, #fffaf0)",strokeWidth:c,opacity:.72*l})]},u)}return cs(ns.Fragment,{children:[as("circle",{cx:e.x,cy:e.y,r:s,fill:n,stroke:a,strokeWidth:c,opacity:l}),as("circle",{cx:e.x-.25*s,cy:e.y-.28*s,r:Math.max(1,.18*s),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as ds,jsx as hs,jsxs as ps}from"react/jsx-runtime";var ms="var(--semiotic-text, #26323a)",gs="var(--semiotic-text-secondary, #6c7377)",fs="var(--semiotic-accent, #b8792d)",ys="var(--semiotic-negative, #9f3d35)",bs="var(--semiotic-positive, #356b63)";function xs(e){const{x:t,y:o,width:i,height:r}=e.chamber,s=Math.min(.14*i,48),n=o+r;return[`M ${t} ${o}`,`L ${t+s} ${n-.16*r}`,`Q ${t+i/2} ${n+.1*r} ${t+i-s} ${n-.16*r}`,`L ${t+i} ${o}`].join(" ")}function vs({layout:e,phases:t,state:o,compact:i=!1}){const r=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return ps("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[ps("defs",{children:[ps("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[hs("stop",{offset:"0",stopColor:fs,stopOpacity:"0.03"}),hs("stop",{offset:"0.66",stopColor:fs,stopOpacity:"0.1"}),hs("stop",{offset:"1",stopColor:ys,stopOpacity:"0.18"})]}),hs("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:hs("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:ms,strokeOpacity:"0.08",strokeWidth:"1"})})]}),hs("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:ms,strokeOpacity:"0.52",strokeWidth:i?1:2.2}),hs("path",{d:xs(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),hs("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:ms,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:i?2:5}),i?null:hs("g",{"data-testid":"crucible-phase-rail",children:t.map((i,s)=>{const n=t.slice(0,s).reduce((e,t)=>e+Math.max(0,t.duration),0),a=e.phaseRail.x+n/r*e.phaseRail.width,c=Math.max(0,i.duration)/r*e.phaseRail.width,l=i.id===o.phaseId,u=o.phaseIndex>s||o.complete;return ps("g",{children:[hs("rect",{x:a,y:e.phaseRail.y,width:Math.max(1,c-2),height:e.phaseRail.height,rx:2,fill:l?i.color??fs:u?bs:ms,fillOpacity:l?.68:u?.28:.09}),46>c?null:hs("text",{x:a+c/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:l?ms:gs,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(i.label??i.id).toUpperCase()})]},i.id)})}),e.outlets.map(e=>ps("g",{children:[hs("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?ys:bs),fillOpacity:"0.1",stroke:e.color??("left"===e.side?ys:bs),strokeDasharray:"3 3",strokeOpacity:"0.62"}),i?null:hs("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:gs,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function As({rows:e,layout:t,projection:o,amountLabel:i}){if(!e.length)return null;const r=o.measure??"count",s=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,r))),n=Math.max(1,...s),a=t.projection.width/Math.max(1,e.length),c=t.projection.height>48?21:4,l=Math.max(5,t.projection.height-c-5);return hs("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,o)=>{const u=s[o],d=Math.max(u>0?2:0,u/n*l),h=t.projection.x+o*a+.18*a;return ps("g",{children:[hs("rect",{x:h,y:t.projection.y+l-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?ys:"complete"===e.status?fs:bs,fillOpacity:"0.68"}),c>4&&a>=34?ps(ds,{children:[hs("text",{x:h+.32*a,y:t.projection.y+l+10,fill:gs,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),ps("text",{x:h+.32*a,y:t.projection.y+l+19,fill:ms,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[ls(u),"amount"===r&&i?" "+i:""]})]}):null]},e.key)})})}function ws(e){return e.map(e=>({...e,spawnAt:void 0}))}function Ss(e,t){return e?t?o=>or.createElement(or.Fragment,null,e,"function"==typeof t?t(o):t):e:t}var ks=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function _s(e){let t=2166136261;for(let o=0;e.length>o;o+=1)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return ks[(t>>>0)%ks.length]}var Ms={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,o,i,r)=>({chartType:"line",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",groupAccessor:r.lineBy||t,colorAccessor:t,...i,showAxes:!1,margin:i.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:To,LineChart:zo,AreaChart:Fo,DifferenceChart:Bo,StackedAreaChart:Eo,Scatterplot:Do,CandlestickChart:jo,BubbleChart:Io,ConnectedScatterplot:$o,QuadrantChart:No,Heatmap:{frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"heatmap",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",valueAccessor:r.valueAccessor,colorScheme:o||r.colorScheme||"blues",showValues:r.showValues,heatmapValueFormat:r.valueFormat,cellBorderColor:r.cellBorderColor,...i})},TemporalHistogram:Oo,XYCustomChart:{frameType:"xy",buildProps:(e,t,o,i,r)=>({chartType:"custom",data:e,xAccessor:r.xAccessor||"x",yAccessor:r.yAccessor||"y",colorAccessor:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i,showAxes:r.frameProps?.showAxes??r.showAxes??!1,showLegend:i.showLegend??!!t})},BarChart:ui,StackedBarChart:di,GroupedBarChart:hi,PieChart:pi,DonutChart:mi,Histogram:gi,BoxPlot:fi,ViolinPlot:yi,SwarmPlot:bi,DotPlot:xi,SwimlaneChart:vi,RidgelinePlot:Ai,LikertChart:wi,FunnelChart:Si,GaugeChart:ki,OrdinalCustomChart:{frameType:"ordinal",buildProps:(e,t,o,i,r)=>({chartType:"custom",data:e,oAccessor:r.categoryAccessor||r.oAccessor||"category",rAccessor:r.valueAccessor||r.rAccessor||"value",projection:r.projection||"vertical",colorAccessor:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i,showAxes:r.frameProps?.showAxes??r.showAxes??!1})},ForceDirectedGraph:Gi,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,o,i,r)=>({chartType:"force",nodes:r.nodes||e||[],edges:r.edges||[],nodeIDAccessor:r.nodeIdAccessor||r.nodeIDAccessor||"id",sourceAccessor:r.sourceAccessor||"source",targetAccessor:r.targetAccessor||"target",valueAccessor:r.valueAccessor||"value",colorBy:t,colorScheme:o,customNetworkLayout:r.layout||r.customNetworkLayout,layoutConfig:r.layoutConfig,...i})},SankeyDiagram:Hi,ProcessSankey:Vi,ChordDiagram:Yi,TreeDiagram:Xi,Treemap:qi,CirclePack:Ui,ChoroplethMap:Ji,ProportionalSymbolMap:er,FlowMap:tr,GeoCustomChart:{frameType:"geo",buildProps:(e,t,o,i,r)=>({points:r.points||e||[],areas:r.areas||[],lines:r.lines||[],projection:r.projection||"equirectangular",xAccessor:r.xAccessor||"lon",yAccessor:r.yAccessor||"lat",lineDataAccessor:r.lineDataAccessor,colorBy:t,colorScheme:o,customLayout:r.layout||r.customLayout,layoutConfig:r.layoutConfig,...i})},GaltonBoardChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[600,400],a=r.bins??21,c=r.seed??1,l=Math.max(1,Math.round(r.pegRows??a-1)),u="mechanical"===r.mode,h=u?d({bins:a,branchProbability:r.branchProbability,count:r.mechanicalCount,pegRows:l,seed:c}):Array.isArray(e)?e:[],p=n({data:h,valueAccessor:r.valueAccessor||"value",bins:a,ballRadius:r.ballRadius??4,seed:c,size:s,valueExtent:u?[0,l]:void 0});return{...i,config:p.config,initialSpawns:ws(p.initialSpawns),projectionRows:p.projectionRows,bodyStyle:f(t||r.colorBy||(u?"side":void 0),"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const n=i.size??[600,400],a=s({data:Array.isArray(e)?e:[],timeAccessor:r.timeAccessor||"time",arrivalAccessor:r.arrivalAccessor||"arrivalTime",windows:r.windows||{size:10},watermark:r.watermark,ballRadius:r.ballRadius??5,seed:r.seed??1,size:n,timeExtent:r.timeExtent,timeScale:r.timeScale??1});return{...i,config:a.config,initialSpawns:ws(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:f(t||r.colorBy,"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||r.timeAccessor||"time"})}}},PhysicsPileChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[600,400],n="mechanical"===r.mode,a=n?h({categories:r.mechanicalCategories,count:r.mechanicalCount,seed:r.seed??1,unitValue:r.unitValue??1}):Array.isArray(e)?e:[],l=c({data:a,categoryAccessor:r.categoryAccessor||"category",valueAccessor:r.valueAccessor||(n?"value":void 0),unitValue:r.unitValue??1,ballRadius:r.ballRadius??5,seed:r.seed??1,size:s});return{...i,config:l.config,initialSpawns:ws(l.initialSpawns),projectionRows:l.projectionRows,bodyStyle:f(t||r.colorBy||(n?"category":void 0),"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const n=i.size??[600,360],a=r({data:Array.isArray(e)?e:[],xAccessor:s.xAccessor||"x",groupAccessor:s.groupAccessor,radiusAccessor:s.radiusAccessor,pointRadius:s.pointRadius??5,seed:s.seed??1,size:n,xExtent:s.xExtent,collisionIterations:s.collisionIterations,settle:s.settle});return{...i,config:a.config,initialSpawns:ws(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:f(t||s.colorBy||s.groupAccessor,"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,420],n=Array.isArray(r.stages)?r.stages:[],a=u({data:Array.isArray(e)?e:[],stages:n,size:s,idAccessor:r.idAccessor,stageAccessor:r.stageAccessor||"stage",groupBy:r.groupBy,groupLabelAccessor:r.groupLabelAccessor,workAccessor:r.workAccessor,radiusAccessor:r.radiusAccessor,ballRadius:r.ballRadius??6,seed:r.seed??1,groupCompletion:r.groupCompletion,groupAnchorAlong:r.groupAnchorAlong,settle:r.settle??!0,gravityX:r.gravityX,gravityY:r.gravityY}),c=a.metadata;return{...i,config:a.config,initialSpawns:ws(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,bodyStyle:f(t||r.colorBy||r.groupBy,"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.workAccessor||r.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,520],n=mr({data:Array.isArray(e)?e:[],size:s,gates:r.gates,positiveProperties:r.positiveProperties,negativeProperties:r.negativeProperties,crashOffset:r.crashOffset,idAccessor:r.idAccessor,positiveAccessor:r.positiveAccessor,negativeAccessor:r.negativeAccessor,metricsAccessor:r.metricsAccessor,initialViability:r.initialViability,projectPlacement:r.projectPlacement,coreBody:r.coreBody,viability:r.viability});return{...i,config:n.config,initialSpawns:ws(n.initialSpawns),projectionRows:[],bodyStyle:f(t||r.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,520],n=ss({data:Array.isArray(e)?e:[],phases:Array.isArray(r.phases)?r.phases:[],products:Array.isArray(r.products)?r.products:void 0,outlets:Array.isArray(r.outlets)?r.outlets:void 0,events:Array.isArray(r.events)?r.events:void 0,idAccessor:r.idAccessor,labelAccessor:r.labelAccessor,categoryAccessor:r.categoryAccessor,amountAccessor:r.amountAccessor,metricsAccessor:r.metricsAccessor,initialStateAccessor:r.initialStateAccessor,metrics:r.metrics,size:s,seed:r.seed,bodyRadius:"number"==typeof r.bodyRadius?r.bodyRadius:void 0,radiusRange:r.radiusRange}),a="snapshot"===r.playback?function(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,$r(t)??0));const o=e.phases.find(e=>e.id===t.phaseId);if(!o)return e.duration;const i=Math.max(0,Math.min(1,$r(t.progress??0)??0));return o.start+o.duration*i}(n,r.snapshotAt):n.duration,c=rs(n,a).state,u=r.projection&&"object"==typeof r.projection?r.projection:{groupBy:"outlet",measure:"count"},d=function(e,t={}){const o=t.groupBy??"outlet",i=new Map,r=e=>{const t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},o),r=i.get(t);if(r)return r.count+=1,r.amount+=e.amount,void Sr(r.metrics,e.metrics);i.set(t,{key:t,label:"product"===o&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:{...e.metrics},status:"status"===o?e.status:void 0,outletId:"outlet"===o?e.outletId:void 0,category:"category"===o?e.category:void 0,productId:"product"===o&&"product"===e.kind?e.id:void 0})};for(const t of Object.values(e.components))t.productIds.length||"consumed"===t.status||r({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(const t of Object.values(e.products))r({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});const s=new Map((t.order??[]).map((e,t)=>[e,t]));return[...i.values()].sort((e,t)=>(s.get(e.key)??Number.MAX_SAFE_INTEGER)-(s.get(t.key)??Number.MAX_SAFE_INTEGER)||fr(e.key,t.key))}(c,u),h=u.measure??"count",p=l(d.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===h||"amount"===h?e.amount:Number(e.metrics[h]??0),secondaryLabel:"count"===h||"amount"===h?r.amountLabel??"amount":h,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),m={seed:r.seed,bodyRadius:"number"==typeof r.bodyRadius?r.bodyRadius:void 0,radiusRange:r.radiusRange},g=t??r.colorBy??"category",f=!1===r.showChrome?null:or.createElement(vs,{layout:n.layout,phases:n.phases,state:c,compact:520>s[0]||360>s[1]}),y=!1===r.showProjection?null:or.createElement(As,{rows:d,layout:n.layout,projection:u,amountLabel:r.amountLabel});return{...i,config:n.config,initialSpawns:ws(ts(c,n.layout,m)),projectionRows:p,bodyStyle:e=>function(e,t,o,i){const r=e.datum,s={stroke:i.stroke??("product"===r?.kind?"#fffaf0":"#26323a"),strokeWidth:i.strokeWidth??("product"===r?.kind?1.8:1.1),opacity:i.opacity??.96};if(!r?.__crucible)return{...s,fill:i.color??"#b8792d"};if("product"===r.kind){const e=t.products[r.semanticId];return{...s,fill:i.color??e?.color??_s(e?.id??r.semanticId)}}const n=t.components[r.semanticId];if(!n)return{...s,fill:i.color??"#356b63"};let a;return a="status"===o?n.status:"outlet"===o?n.outletId??"in chamber":"product"===o?n.productIds[0]??"unalloyed":"category"===o||null==o?n.category:"function"==typeof o?(o(n.datum)??"unassigned")+"":(n.datum[o+""]??"unassigned")+"",{...s,fill:i.color??_s(a)}}(e,c,g,r),getBodyLabel:e=>function(e,t){const o=e.datum;if(o?.__crucible)return"product"===o.kind?t.products[o.semanticId]?.label:t.components[o.semanticId]?.label}(e,c),renderBodySVG:us,backgroundGraphics:Ss(f,i.backgroundGraphics),foregroundGraphics:Ss(y,i.foregroundGraphics)}}},PhysicalFlowChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[760,420],n=a({nodes:Array.isArray(r.nodes)?r.nodes:[],links:Array.isArray(r.links)?r.links:Array.isArray(r.edges)?r.edges:Array.isArray(e)?e:[],nodeIdAccessor:r.nodeIdAccessor||"id",nodeXAccessor:r.nodeXAccessor||"x",nodeYAccessor:r.nodeYAccessor||"y",sourceAccessor:r.sourceAccessor||"source",targetAccessor:r.targetAccessor||"target",throughputAccessor:r.throughputAccessor||"value",pathAccessor:r.pathAccessor||"path",coordinateMode:r.coordinateMode||"auto",particleRate:r.particleRate??.16,maxParticles:r.maxParticles??180,particleRadius:r.particleRadius??4,flowSpeed:r.flowSpeed??90,pathConstraint:r.pathConstraint||"path",reducedMotion:!0,seed:r.seed??1,size:s});return{...i,config:n.config,initialSpawns:ws(n.initialSpawns),projectionRows:n.projectionRows,bodyStyle:f(t||r.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[700,380],n=g({chartId:r.chartId,colorScheme:o,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Lt(Mt)??{},size:s,themeCategorical:Mt.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:n.config,initialSpawns:ws(n.initialSpawns),projectionRows:[],bodyStyle:n.result.bodyStyle??f(t||r.colorBy)}}}};function Rs(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Ps(e){if(!e||2>e.length)return;const t=Rs(e[0]),o=Rs(e[e.length-1]);return null!==t&&null!==o?[t,o]:void 0}function Ls(e){const{count:t,byType:o}=function(e){const t={};for(const o of e){const e="string"==typeof o?.type&&o.type.length>0?o.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),i=0===t,r=[...e.extraWarnings??[]];i&&!r.includes("EMPTY_SCENE")&&r.push("EMPTY_SCENE");const s=e.margin,n=s?{x:s.left,y:s.top,width:e.width-s.left-s.right,height:e.height-s.top-s.bottom}:void 0;return{component:"",frameType:e.frameType,status:i?"empty":"ok",empty:i,markCount:t,markCountByType:o,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:Array.isArray(e.annotations)?e.annotations.length:0,ariaLabel:"string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,warnings:r,...s?{margin:s}:{},...n?{plot:n}:{}}}import*as Is from"react";import*as Ts from"react-dom/server";import{scaleOrdinal as Cs}from"d3-scale";import{jsx as zs,jsxs as Os}from"react/jsx-runtime";var Fs=re;function Bs(e,t,o){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>De(e,t)??"#999"}const i=Array.isArray(t)?t:o.colors.categorical.length>0?o.colors.categorical:vt;return Cs().domain(e).range(i)}function Es(e,t,o){if(0===e.length)return;const i=Bs(e,t,o);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:i(e.label)})}]}}function js(e){return"left"===e?"start":"right"===e?"end":e??"start"}function Ds(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function Ns(e,t,o,i){const r=Ds(i);return t+o+Math.ceil(e.length*r*.58)}function $s(e){const{categories:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=$e(n),d=a+c,h="top"===i||"bottom"===i,p=Math.max(a,r-s.left-s.right),m=t.map(e=>Ns(e,a,c,o));if(h){const e=Math.max(a,n?.maxWidth??p),o=[];let i=0,r=0;m.forEach((t,s)=>{const n=0===r?t:r+l+t;r>0&&n>e?(o.push({start:i,end:s,width:r}),i=s,r=t):r=n}),t.length>0&&o.push({start:i,end:t.length,width:r});const s=js(n?.align),c=[];return o.forEach((o,i)=>{let r="center"===s?Math.max(0,(e-o.width)/2):"end"===s?Math.max(0,e-o.width):0;for(let e=o.start;o.end>e;e++)c.push({category:t[e],width:m[e],x:r,y:i*u}),r+=m[e]+l}),{items:c,width:Math.max(0,...o.map(e=>e.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...m);return{items:t.map((e,t)=>({category:e,width:m[t],x:0,y:t*u})),width:g,height:t.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Ws(e){const{legendGroups:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,rowHeight:l}=$e(n),u=a+c,d=Math.max(12,Ds(o)),h="top"===i||"bottom"===i,p=Math.max(a,r-s.left-s.right);if(h){const i=Math.max(a,n?.maxWidth??p),r=js(n?.align);let s=0,c=0;const l=[];for(const r of t){const t=r.items.map(e=>e.label),u=$s({...e,categories:t,legendLayout:{...n,maxWidth:Math.max(a,i-d-8),align:"start"}}),h=r.label?d:0,p=r.label?Ns(r.label,0,0,o):0,m=h>0?h+8:0,g=m+u.width,f=Math.max(u.height,p);l.push({group:r,x:s,y:0,itemOffsetX:m,itemOffsetY:0,width:g,height:f,items:u.items}),s+=g+12,c=Math.max(c,f)}const h=l.length>0?s-12:0,m=h>i?0:"center"===r?Math.max(0,(i-h)/2):"end"===r?Math.max(0,i-h):0;return{groups:l.map(e=>({...e,x:e.x+m})),width:h,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const m=ke(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),l);let g=0;return{groups:t.map((e,t)=>{const i=e.items.map(e=>Ns(e.label,a,c,o)),r=Math.max(0,...i,e.label?Ns(e.label,0,0,o):0);return g=Math.max(g,r),{group:e,x:0,y:m[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:r,height:e.items.length*l,items:e.items.map((e,t)=>({category:e.label,width:i[t],x:0,y:t*l}))}}),width:g,height:m.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function Gs(e){const t="top"===e.position||"bottom"===e.position,o=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??o,200),height:e.gradient.label?34:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?124:108,swatchSize:14}}function Vs(e,t){if(!t||!e||0===e.length)return[];const o="function"==typeof t?t:e=>e[t],i=new Set;for(const t of e){const e=o(t);null!=e&&i.add(e+"")}return Array.from(i)}import{jsx as Hs,jsxs as Ys}from"react/jsx-runtime";var Xs=16;function qs(e,t){return e.color||t.colors.annotation||t.colors.text}function Us(e,t,o){const i=e.labelBackground,r=t.colors.background,s=r&&"transparent"!==r?r:t.colors.surface||r;return void 0===i?"none"===o?"none":{type:"halo",fill:s}:!1===i||"none"===i?"none":!0===i||"halo"===i?{type:"halo",fill:s}:"box"===i?{type:"box",fill:s}:{fill:s,...i}}function Qs(e,t,o){return null!=e.x&&t.x?t.x(e.x):o&&null!=e[o]&&t.x?t.x(e[o]):"number"==typeof e.x?e.x:null}function Ks(e,t,o){return null!=e.y&&t.y?t.y(e.y):o&&null!=e[o]&&t.y?t.y(e[o]):"number"==typeof e.y?e.y:null}function Zs(e){const{annotations:t}=e;if(!t||0===t.length)return null;const o=it(t),i=e.scales.geoProjection,r=i?o.map(e=>{if(!Array.isArray(e.coordinates)||2>e.coordinates.length)return e;const t=i([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):o,s=!!i&&!e.scales.x&&!e.scales.y,n=e=>Number(e),a=e.scales.x??(s?n:void 0),c=e.scales.y??(s?n:void 0),l=e.projection?"horizontal"===e.projection?"horizontal":"vertical":void 0,u={scales:{x:a,y:c,time:a,value:c,o:e.scales.o,...i?{geoProjection:i}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,frameType:e.projection?"ordinal":i||e.scales.x||e.scales.y?"xy":"network",...l?{projection:l}:{}},d=e.autoPlaceAnnotations?ut({annotations:r,context:u,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):r,h=Te(d,(t,o)=>function(e,t,o){const{scales:i,layout:r,theme:s,xAccessor:n,yAccessor:a}=o;switch(e.type){case"y-threshold":{const n=e.value;if(null==n)return null;const a=qs(e,s),c=e.label,l=e.labelPosition||"right",u=e.strokeDasharray||"6,4",d=e.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:Ys("g",{opacity:e.opacity,children:[Hs("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Hs(oe,{x:o+4,y:Xs,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Us(e,s,"halo")})]},"ann-ythresh-"+t)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:Ys("g",{children:[Hs("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Hs(oe,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Xs):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Us(e,s,"halo")})]},"ann-ythresh-"+t)}case"x-threshold":{const n=e.value;if(null==n)return null;const a="horizontal"===o.projection&&i.r?i.r(n):i.x?i.x(n):null;if(null==a)return null;const c=qs(e,s),l=e.label,u=e.labelPosition||"top";return Ys("g",{opacity:e.opacity,children:[Hs("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:c,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),l&&Hs(oe,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Xs,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:c,fontFamily:s.typography.fontFamily,text:l,background:Us(e,s,"halo")})]},"ann-xthresh-"+t)}case"band":{const o=i.y?.domain?.(),n=e.y0??o?.[0],a=e.y1??o?.[1],c=null!=n&&i.y?i.y(n):null,l=null!=a&&i.y?i.y(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=at(e.fill||qs(e,s),"ssr-band-"+t),p=e.fillOpacity??.1;return Ys("g",{opacity:e.opacity,children:[h.def&&Hs("defs",{children:h.def}),Hs("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:p}),e.label&&Hs(oe,{x:r.width-4,y:Math.max(u,0)+Xs,textAnchor:"end",fontSize:s.typography.tickSize,fill:e.color||qs(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Us(e,s,"halo")})]},"ann-band-"+t)}case"x-band":{const o=i.x?.domain?.(),n=e.x0??o?.[0],a=e.x1??o?.[1],c=null!=n&&i.x?i.x(n):null,l=null!=a&&i.x?i.x(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=at(e.fill||qs(e,s),"ssr-xband-"+t),p=e.fillOpacity??.1;return Ys("g",{opacity:e.opacity,children:[h.def&&Hs("defs",{children:h.def}),Hs("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:p}),e.label&&Hs(oe,{x:u+4,y:Xs,textAnchor:"start",fontSize:s.typography.tickSize,fill:e.color||s.colors.primary||qs(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Us(e,s,"halo")})]},"ann-xband-"+t)}case"category-highlight":{if(null==e.category||!i.o)return null;const n=i.o(e.category+"");if(null==n)return null;const a=i.o.bandwidth?i.o.bandwidth():40,c=qs(e,s),l=e.opacity??.1,u=e.label;return Ys("g","horizontal"===o.projection?{children:[Hs("rect",{x:0,y:n,width:r.width,height:a,fill:c,opacity:l}),u&&Hs(oe,{x:12,y:n+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Us(e,s,"none")})]}:{children:[Hs("rect",{x:n,y:0,width:a,height:r.height,fill:c,opacity:l}),u&&Hs(oe,{x:n+a/2,y:Xs,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Us(e,s,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:r}=function(e,t,o,i){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){const o=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Qs(e,t,o),y:Ks(e,t,i)}}(e,i,n,a);if(null==o||null==r)return null;const c="text"===e.type,l=e.dx??(c?0:30),u=e.dy??(c?0:-30),d=e.color||s.colors.text;if(!c){const i="callout"===e.type?"callout-circle":e.type,s="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return Hs(ce,{noteData:{x:o,y:r,dx:l,dy:u,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:i,...s?{subject:s}:{},connector:e.connector||{end:"arrow"},color:d,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return Hs("g",{children:Hs("text",{x:o+l,y:r+u,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||s.typography.labelSize,fill:d,fontFamily:s.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}(t,o,e),e.svgAnnotationRules,u);return h.length>0?Hs("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as Js from"react";import{jsx as en,jsxs as tn}from"react/jsx-runtime";function on(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function rn(e){const t=e._idPrefix||e.chartId;if(t){const e=(t+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:"c"+e}const o=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`;let i=0;for(let e=0;o.length>e;e++)i=31*i+o.charCodeAt(e)|0;return"c"+(i>>>0).toString(36)}function sn(e,t,o){const i=e.showLegend&&!e.__legendIncludesAutomatic?Es(t,e.colorScheme,o):void 0;return de(i,e.legend)}var nn={right:110,left:110,top:50,bottom:80};function an(e,t){if(e.__autoLegendMargin&&!cn(e,t))return nn[t]}function cn(e,t){const o=e.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[t])}function ln(e,t){const{props:o,categories:i,theme:r,size:s,hasTitle:n}=t,a=o.legendPosition||"right",c={theme:r,position:a,size:s,hasTitle:n,legendLayout:o.legendLayout,minimumMargin:an(o,a),preserveExplicitMargin:cn(o,a)};if(null!=o.legend){const t=sn(o,i,r);(Se(t)||we(t))&&function(e,t){if(t.preserveExplicitMargin)return;const o=t.position||"right",i={theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout},r=Se(t.legend)?function(e){const{width:t,height:o,swatchSize:i}=Ws(e);return{width:t,height:o,swatchSize:i}}({...i,legendGroups:t.legend.legendGroups}):we(t.legend)?Gs({...i,gradient:t.legend.gradient}):null;if(!r)return;const s=Ne(t.legend),n=Math.max(t.minimumMargin??0,Ve(t.legend,t.legendLayout)),a=Math.max(t.minimumMargin??0,s+r.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,s+r.height);"right"===o?e.right=Math.max(e.right,n):"left"===o?e.left=Math.max(e.left,n):"top"===o?e.top=Math.max(e.top,a):e.bottom=Math.max(e.bottom,c)}(e,{...c,legend:t})}else o.showLegend&&i.length>0&&function(e,t){if(0===t.categories.length)return;if(t.preserveExplicitMargin)return;const o=t.position||"right",i=function(e){const{width:t,height:o,swatchSize:i}=$s(e);return{width:t,height:o,swatchSize:i}}({categories:t.categories,colorScheme:t.colorScheme,theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout}),r=Es(t.categories,t.colorScheme,t.theme),s=Ne(r),n=Math.max(t.minimumMargin??0,Ve(r,t.legendLayout)),a=Math.max(t.minimumMargin??0,s+i.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,s+i.height);"right"===o?e.right=Math.max(e.right,n):"left"===o?e.left=Math.max(e.left,n):"top"===o?e.top=Math.max(e.top,a):e.bottom=Math.max(e.bottom,c)}(e,{...c,categories:i,colorScheme:o.colorScheme});return a}function un(e){const{props:t,categories:o,theme:i,size:r,margin:s,hasTitle:n}=e,a=t.legendPosition||"right",c={theme:i,position:a,size:r,margin:s,hasTitle:n,legendLayout:t.legendLayout,idPrefix:t._idPrefix};if(null!=t.legend){const e=sn(t,o,i);if(Js.isValidElement(e))return e;const r=function(e,t){const o={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,legendDistance:Se(e)||we(e)?e.legendDistance:void 0};return Se(e)?function(e){if(0===(t=e.legendGroups,t.flatMap(e=>e.items.map((t,o)=>({group:e,item:t,itemIndex:o,label:t.label})))).length)return null;var t;const o=Ws(e),i="top"===e.position||"bottom"===e.position,r={legendGroups:e.legendGroups,legendDistance:e.legendDistance},s=e.reservedWidth??He(r,e.legendLayout),n=Ne(r),a=We(e.legendLayout),c=e.theme.colors.grid||e.theme.colors.textSecondary;let l,u;if("left"===e.position?(l=e.margin.left-a-s-n,u=e.margin.top):"top"===e.position?(l=e.margin.left,u=e.margin.top-n-o.height):"bottom"===e.position?(l=e.margin.left,u=e.totalHeight-e.margin.bottom+n):(l=e.totalWidth-e.margin.right+a+n,u=e.margin.top),!i){const t=ke(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(o.swatchSize,e.legendLayout?.rowHeight??Fs)),i=e.legendGroups.flatMap((i,r)=>{const n=t[r],a=i.type??"fill",c=[zs("line",{x1:0,y1:n.lineY,x2:s,y2:n.lineY,stroke:"gray"},"legend-group-neatline-"+r)];return i.label&&null!=n.labelY&&c.push(zs("text",{y:n.labelY,fontSize:Ds(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.label},"legend-group-label-"+r)),c.push(zs("g",{transform:`translate(0,${n.itemsY})`,children:i.items.map((t,s)=>{const n=i.styleFn(t,s),c="function"==typeof a?a(t):"line"===a?zs("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:n}):zs("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:n});return Os("g",{transform:`translate(0,${s*Math.max(o.swatchSize,e.legendLayout?.rowHeight??Fs)})`,children:[c,zs("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Ds(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${r}-${s}`)})},"legend-group-"+r)),c});return zs("g",{className:"semiotic-legend",transform:`translate(${l},${u})`,"data-orientation":"vertical",children:i})}const d=o.groups.flatMap((t,r)=>{const{group:s}=t,n=s.type??"fill",a=[];if(s.label&&a.push(zs("text",i?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:Ds(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:s.label}:{x:t.x,y:t.y+Ds(e.theme),fontSize:Ds(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:s.label},"legend-group-label-"+r)),a.push(...t.items.map((i,a)=>{const c=s.items[a],l=s.styleFn(c,a),u="function"==typeof n?n(c):"line"===n?zs("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):zs("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return Os("g",{transform:`translate(${t.x+t.itemOffsetX+i.x},${t.y+t.itemOffsetY+i.y})`,children:[u,zs("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Ds(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.category})]},`legend-${r}-${a}`)})),i&&o.groups.length-1>r){const e=t.x+t.width+6;a.push(zs("line",{x1:e,y1:0,x2:e,y2:o.height,stroke:c},"legend-group-separator-"+r))}return a});return zs("g",{className:"semiotic-legend",transform:`translate(${l},${u})`,"data-orientation":i?"horizontal":"vertical",children:d})}({...o,legendGroups:e.legendGroups}):we(e)?function(e){const t=Gs(e),o="top"===e.position||"bottom"===e.position,i={gradient:e.gradient,legendDistance:e.legendDistance},r=He(i),s=Ne(i),n=We(e.legendLayout),a=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",c=e.gradient.format||(e=>Math.round(100*e)/100+"");let l,u;"left"===e.position?(l=e.margin.left-n-r-s,u=e.margin.top):"top"===e.position?(l=e.margin.left,u=e.margin.top-s-t.height):"bottom"===e.position?(l=e.margin.left,u=e.totalHeight-e.margin.bottom+s):(l=e.totalWidth-e.margin.right+n+s,u=e.margin.top);const d=Array.from({length:17},(t,i)=>{const r=i/16;return zs("stop",{offset:100*r+"%",stopColor:e.gradient.colorFn(o?e.gradient.domain[0]+r*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-r*(e.gradient.domain[1]-e.gradient.domain[0]))},i)});if(o){const o=12,i=e.gradient.label?0:void 0,r=e.gradient.label?8:0;return Os("g",{className:"semiotic-legend",transform:`translate(${l},${u})`,children:[zs("defs",{children:zs("linearGradient",{id:a,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:d})}),e.gradient.label&&zs("text",{x:t.width/2,y:i,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),zs("rect",{x:0,y:r,width:t.width,height:o,fill:`url(#${a})`,rx:2}),zs("text",{x:0,y:r+o+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:c(e.gradient.domain[0])}),zs("text",{x:t.width,y:r+o+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:c(e.gradient.domain[1])})]})}const h=e.gradient.label?-6:void 0;return Os("g",{className:"semiotic-legend",transform:`translate(${l},${u+(e.gradient.label?12:0)})`,children:[zs("defs",{children:zs("linearGradient",{id:a,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:d})}),e.gradient.label&&zs("text",{x:0,y:h,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),zs("rect",{x:0,y:0,width:14,height:100,fill:`url(#${a})`,rx:2}),zs("text",{x:19,y:10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:c(e.gradient.domain[1])}),zs("text",{x:19,y:100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:c(e.gradient.domain[0])})]})}({...o,gradient:e.gradient}):null}(e,c);return r||(Se(e)||we(e)?null:e??null)}return t.showLegend&&0!==o.length?function(e){const{categories:t,colorScheme:o,theme:i,position:r="right",totalWidth:s,totalHeight:n,margin:a}=e;if(!t||0===t.length)return null;const c=Bs(t,o,i),l="top"===r||"bottom"===r,u=$s(e),d=Es(t,o,i),h=e.reservedWidth??He(d,e.legendLayout),p="number"==typeof e.legendDistance?Math.max(0,e.legendDistance):Ne(d),m=We(e.legendLayout);let g,f;if("left"===r?(g=a.left-m-h-p,f=a.top):"top"===r?(g=a.left,f=a.top-p-u.height):"bottom"===r?(g=a.left,f=n-a.bottom+p):(g=s-a.right+m+p,f=a.top),l){const e=u.items.map((e,t)=>Os("g",{transform:`translate(${e.x},${e.y})`,children:[zs("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(e.category),rx:u.swatchRadius}),zs("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Ds(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return zs("g",{className:"semiotic-legend",transform:`translate(${g},${f})`,children:e})}const y=ke([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??Fs))[0],b=u.items.map((e,t)=>Os("g",{transform:`translate(${e.x},${e.y+y.itemsY})`,children:[zs("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(e.category),rx:u.swatchRadius}),zs("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Ds(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return Os("g",{className:"semiotic-legend",transform:`translate(${g},${f})`,children:[zs("line",{x1:0,y1:y.lineY,x2:h,y2:y.lineY,stroke:"gray"}),b]})}({categories:o,colorScheme:t.colorScheme,theme:i,position:a,totalWidth:r[0],totalHeight:r[1],margin:s,hasTitle:n,legendLayout:t.legendLayout,idPrefix:t._idPrefix}):null}function dn(e){return Math.round(100*e)/100+""}function hn(e,t){const o=jt(t.theme),i=t.background??o.background,r=t.idPrefix?t.idPrefix+"-":"",s="string"==typeof t.title?t.title:void 0,n=s?r+"semiotic-title":void 0,a=t.description?r+"semiotic-desc":void 0,c=[n,a].filter(Boolean).join(" ")||void 0;return tn("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":c,style:{fontFamily:o.fontFamily},children:[s&&en("title",{id:n,children:s}),t.description&&en("desc",{id:a,children:t.description}),t.defs&&en("defs",{children:t.defs}),i&&"transparent"!==i&&en("rect",{x:0,y:0,width:t.width,height:t.height,fill:i}),en("g",{id:r+"data-area",transform:t.innerTransform,children:e}),s&&en("text",{id:r+"chart-title",x:t.width/2,y:le,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:s}),t.legend&&en("g",{id:r+"legend",children:t.legend}),t.outerElements]})}import{Fragment as pn,jsx as mn,jsxs as gn}from"react/jsx-runtime";function fn(e,t){const o=Et(e.theme),i=e.size||[500,300],r=Oe({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=ve(e.title),n=ge(e.data),a=e.showLegend?Vs(n,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[];ln(r,{props:e,categories:a,theme:o,size:i,hasTitle:s});const c=i[0]-r.left-r.right,l=i[1]-r.top-r.bottom,u="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),d=e.colorScheme||o.colors.categorical,h={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:u?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:u?void 0:e.xAccessor,yAccessor:u?void 0:e.yAccessor,timeAccessor:u?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor,categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,axisExtent:e.axisExtent,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:W(e.gradientFill),lineGradient:$(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:d,themeCategorical:o.colors.categorical,themeSemantic:Lt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},p=new _(h);if(e.data&&p.ingest({inserts:n,bounded:!0}),p.computeScene({width:c,height:l}),!p.scales||0===p.scene.length)return t&&(t.evidence=Ls({frameType:"xy",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:p.scales?[]:["NO_SCALES"],margin:r})),Ts.renderToStaticMarkup(hn(null,{width:i[0],height:i[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const m=e._idPrefix,g=H({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>Je(e,t,m)});t&&(t.evidence=Ls({frameType:"xy",width:i[0],height:i[1],marks:g.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:Ps(p.scales.x?.domain?.()),yDomain:Ps(p.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:r}));const f=e.showGrid?function(e,t,o,i,r){const{grid:s}=jt(o),n=i?i+"-":"",a="exact"===r?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),c="exact"===r?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),l=Q(e.x,a,r),u=Q(e.y,c,r);return tn("g",{id:n+"grid",className:"semiotic-grid",opacity:.8,children:[l.map((o,i)=>{const r=e.x(o);return en("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},"gx-"+i)}),u.map((o,i)=>{const r=e.y(o);return en("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:s,strokeWidth:.5},"gy-"+i)})]})}(p.scales,{width:c,height:l},o,m,e.axisExtent):null,y=g.map(e=>e.element),b=rn(e)+"-plot-clip",x=!1!==e.showAxes?function(e,t,o,i,r){const s=jt(i),n=We(o.legendLayout),a=o.legend&&"left"===o.legendPosition&&n>0?n:o.margin?.left??40,c="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),l="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),u=o.axes?.find(e=>"bottom"===e.orient),d=o.axes?.find(e=>"left"===e.orient),h=u?.tickValues??Q(e.x,u?.ticks??c,o.axisExtent),p=h.map(e=>e.valueOf()),m=u?.tickFormat||o.xFormat||o.tickFormatTime||dn,g=h.map((t,o)=>({pixel:e.x(t),label:m(t,o,p)})),f=d?.tickValues??Q(e.y,d?.ticks??l,o.axisExtent),y=d?.tickFormat||o.yFormat||o.tickFormatValue||dn,b=f.map(t=>({pixel:e.y(t),label:y(t)})),x=u?.label??o.xLabel,v=d?.label??o.yLabel;return tn("g",{id:(r?r+"-":"")+"axes",className:"stream-axes",children:[!1!==u?.baseline&&en("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),g.map((e,o)=>tn("g",{transform:`translate(${e.pixel},${t.height})`,children:[en("line",{y2:5,stroke:s.border,strokeWidth:1}),en("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"xtick-"+o)),x&&en("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:x}),!1!==d?.baseline&&en("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),b.map((e,t)=>tn("g",{transform:`translate(0,${e.pixel})`,children:[en("line",{x2:-5,stroke:s.border,strokeWidth:1}),en("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"ytick-"+t)),v&&en("text",{x:15-a,y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-a}, ${t.height/2})`,children:v})]})}(p.scales,{width:c,height:l},e,o,m):null,v=e.annotations?Zs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:n,scales:{x:p.scales.x,y:p.scales.y},layout:{width:c,height:l},theme:o,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:m}):null,A=e.svgPreRenderers&&p.scales?e.svgPreRenderers.map((e,t)=>{try{return mn(Is.Fragment,{children:e(p.scene,p.scales,{width:c,height:l})},"pre-"+t)}catch{return null}}).filter(Boolean):null,w=un({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s});return Ts.renderToStaticMarkup(hn(gn(pn,{children:[e.backgroundGraphics,A,f,mn("defs",{children:mn("clipPath",{id:b,children:mn("rect",{x:0,y:0,width:c,height:l})})}),mn("g",{clipPath:`url(#${b})`,children:y}),x,v,e.foregroundGraphics,p.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,legend:w,idPrefix:e._idPrefix}))}import*as yn from"react-dom/server";import{scaleBand as bn,scaleLinear as xn}from"d3-scale";var vn=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,o){if(t&&"function"==typeof e.pieceStyle){const i=e.pieceStyle(t,o);return i&&!i.fill&&o?{...i,fill:this.getColorFromScheme(e,o)}:i}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&o?{fill:e.barColors[o]||"#007bff"}:{fill:o?this.getColorFromScheme(e,o):"#007bff"}}resolveSummaryStyle(e,t,o){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,o):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){const o=this.colorSchemeMap.get(t);if(o)return o;const i=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||ne,r=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,r),r}};function An(e){const t=e.getSymbol;if(!t)return null;const o=e.config.symbolMap,i=new Map;let r=0;return e=>{const s=t(e)+"",n=o?.[s];if(n)return n;let a=i.get(s);return a||(a=ct[r%ct.length],r++,i.set(s,a)),a}}function wn(e,t,o,i,r,s,n){e.push(t?{type:"symbol",x:i,y:r,size:Math.PI*s*s,symbolType:t(o),style:n,datum:o}:{type:"point",x:i,y:r,r:s,style:n,datum:o})}function Sn(e,t){const{columns:o,config:i,resolvePieceStyle:r}=e,s=[],n=Math.min(t.width,t.height)/2-4,a="donut"===i.chartType?i.innerRadius||60:0,c=-Math.PI/2+(i.startAngle||0)*Math.PI/180,l=null!=i.sweepAngle?i.sweepAngle*Math.PI/180:2*Math.PI,u=null!=i.sweepAngle&&360>i.sweepAngle,d=Object.values(o),h=d.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),p=u&&!h&&d.length>1&&(i.cornerRadius??0)>0;for(let e=0;d.length>e;e++){const t=d[e],o=t.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:t.pctStart,h=c+u*l,m=c+(u+("number"==typeof o?._pct?o._pct:t.pct))*l,g=r(t.pieceData[0],t.name),f=0===e,y=e===d.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:n,startAngle:h,endAngle:m,...i.cornerRadius&&{cornerRadius:i.cornerRadius},style:g,datum:o?._nonInteractive?null:t.pieceData,category:t.name};o?._roundedEnds?b.roundedEnds=o._roundedEnds:p&&(b.roundedEnds={start:f,end:y}),o?._gradientBand&&(b._gradientBand=o._gradientBand),s.push(b)}return s}import{quantile as kn}from"d3-array";function _n(e){const t=e.length,o=e[0],i=e[t-1];return{n:t,min:o,q1:kn(e,.25)??o,median:kn(e,.5)??(o+i)/2,q3:kn(e,.75)??i,max:i,mean:e.reduce((e,t)=>e+t,0)/t}}import{scaleLinear as Mn}from"d3-scale";var Rn={bar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getStack:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,u=[],d="vertical"===l,h="horizontal"===l,p=r.normalize,m=[];if(n){const e=new Set;for(const t of Object.values(i))for(const o of t.pieceData){const t=n(o);e.has(t)||(e.add(t),m.push(t))}}else m.push("_default");for(const e of Object.values(i)){const t=new Map;for(const o of e.pieceData){const e=n?n(o):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const i=t.get(e);i.total+=s(o),i.pieces.push(o)}let o=0;if(p)for(const e of t.values())o+=Math.abs(e.total);let i=0,r=0;for(const s of m){const l=t.get(s);if(!l)continue;let m=l.total;p&&o>0&&(m/=o);const g=a(l.pieces[0],n?s:e.name),f={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:e.name};if(d){const t=c(0>m?r:i+m),o=0>m?c(r+m)-c(r):c(i)-c(i+m);u.push(T(e.x,t,e.width,Math.abs(o),g,f,s)),0>m?r+=m:i+=m}else if(h){const t=c(0>m?r+m:i),o=0>m?c(r)-c(r+m):c(i+m)-c(i);u.push(T(t,e.x,Math.abs(o),e.width,g,f,s)),0>m?r+=m:i+=m}}}const g="vertical"===l,f=r.roundedTop&&r.roundedTop>0?Math.max(0,r.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;const t=e.datum?.__aggregateValue??0;e.roundedEdge=g?0>t?"bottom":"top":0>t?"left":"right",r.gradientFill&&(e.fillGradient=r.gradientFill)}if(f>0){const e=new Map;for(const t of u){if("rect"!==t.type)continue;const o=t.datum?.category||"";e.has(o)||e.set(o,[]),e.get(o).push(t)}for(const t of e.values()){if(0===t.length)continue;const e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),o=t.filter(e=>0>(e.datum?.__aggregateValue??0));e.length>0&&(e.reduce(g?(e,t)=>t.y>e.y?e:t:(e,t)=>e.x+e.w>t.x+t.w?e:t).roundedTop=f),o.length>0&&(o.reduce(g?(e,t)=>e.y+e.h>t.y+t.h?e:t:(e,t)=>t.x>e.x?e:t).roundedTop=f)}}return u},clusterbar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getGroup:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,u=[],d="vertical"===l,h=[],p=new Set;for(const e of Object.values(i))for(const t of e.pieceData){const e=n?n(t):"_default";p.has(e)||(p.add(e),h.push(e))}const m=h.length||1;for(const e of Object.values(i)){const t=e.width/m,o=.2*t,i=t-o,r=new Map;for(const t of e.pieceData){const e=n?n(t):"_default";r.has(e)||r.set(e,[]),r.get(e).push(t)}for(let n=0;h.length>n;n++){const l=r.get(h[n])||[];for(const r of l){const l=s(r),p=a(r,h[n]);if(d){const s=e.x+n*t+o/2,a=c(0),d=c(l);u.push(T(s,Math.min(a,d),i,Math.abs(a-d),p,r,h[n]))}else{const s=e.x+n*t+o/2,a=c(0),d=c(l);u.push(T(Math.min(a,d),s,Math.abs(d-a),i,p,r,h[n]))}}}}const g=r.roundedTop&&r.roundedTop>0?Math.max(0,r.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=s(e.datum);g>0&&(e.roundedTop=g),e.roundedEdge=d?0>t?"bottom":"top":0>t?"left":"right",r.gradientFill&&(e.fillGradient=r.gradientFill)}return u},point:function(e,t){const{scales:o,columns:i,getR:r,multiScales:s,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,d="radial"===c,h=s.length>0,p=An(e),m=2*Math.PI,g=-Math.PI/2;for(const e of Object.values(i))for(const t of e.pieceData){const o=t.__rIndex??0,i=t.__rValue??r(t),c=h&&s[o]||a,f=n(t,e.name),y=f.r||5;let b,x;if(d){const t=g+(e.pctStart+e.pct/2)*m,o=c(i);b=Math.cos(t)*o,x=Math.sin(t)*o}else u?(b=e.middle,x=c(i)):(b=c(i),x=e.middle);wn(l,p,t,b,x,y,f)}return l},swarm:function(e,t){const{scales:o,columns:i,getR:r,resolvePieceStyle:s}=e,{r:n,projection:a}=o,c=[],l="vertical"===a,u=An(e);for(const e of Object.values(i)){const t=e.width/2;for(let o=0;e.pieceData.length>o;o++){const i=e.pieceData[o],a=r(i),d=s(i,e.name),h=d.r||4,p=(7919*o%100/100-.5)*t*.8;wn(c,u,i,l?e.middle+p:n(a),l?n(a):e.middle+p,h,d)}}return c},pie:Sn,donut:Sn,boxplot:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,d=!1!==r.showOutliers;for(const t of Object.values(i)){const o=t.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===o.length)continue;const i=o[0],r=o[o.length-1],c=kn(o,.25)??i,h=kn(o,.5)??(i+r)/2,p=kn(o,.75)??r,m=p-c,g=c-1.5*m,f=p+1.5*m,y=o.find(e=>e>=g)??i,b=[...o].reverse().find(e=>f>=e)??r,x=n(t.pieceData[0],t.name),v=[];if(d)for(const e of t.pieceData){const o=s(e);if(g>o||o>f){const i=u?t.middle:a(o),r=u?a(o):t.middle;v.push({px:i,py:r,value:o,datum:e})}}if(l.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:a(y),q1Pos:a(c),medianPos:a(h),q3Pos:a(p),maxPos:a(b),stats:{n:o.length,min:y,q1:c,median:h,q3:p,max:b,mean:o.reduce((e,t)=>e+t,0)/o.length},style:x,datum:t.pieceData,category:t.name,outliers:v}),d)for(const t of v)l.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:x.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6},datum:t.datum})}return l},violin:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u="vertical"===c,d=r.bins||20,h=!1!==r.showIQR;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],r=(i-o)/d||1,c=Array(d).fill(0);for(const e of t)c[Math.min(Math.floor((e-o)/r),d-1)]++;const p=At(c,1),m=e.width/2*.9;let g;if(u){g=`M ${e.middle} ${a(o)}`;for(let t=0;d>t;t++){const i=a(o+(t+.5)*r);g+=` L ${e.middle+c[t]/p*m} ${i}`}g+=` L ${e.middle} ${a(i)}`;for(let t=d-1;t>=0;t--){const i=a(o+(t+.5)*r);g+=` L ${e.middle-c[t]/p*m} ${i}`}g+=" Z"}else{g=`M ${a(o)} ${e.middle}`;for(let t=0;d>t;t++)g+=` L ${a(o+(t+.5)*r)} ${e.middle-c[t]/p*m}`;g+=` L ${a(i)} ${e.middle}`;for(let t=d-1;t>=0;t--)g+=` L ${a(o+(t+.5)*r)} ${e.middle+c[t]/p*m}`;g+=" Z"}const f=n(e.pieceData[0],e.name);let y;if(h&&t.length>=4){const r=kn(t,.25)??o,s=kn(t,.5)??(o+i)/2,n=kn(t,.75)??i;y={q1Pos:a(r),medianPos:a(s),q3Pos:a(n),centerPos:e.middle,isVertical:u}}const b=u?{x:e.x,y:Math.min(a(i),a(o)),width:e.width,height:Math.abs(a(i)-a(o))}:{x:Math.min(a(o),a(i)),y:e.x,width:Math.abs(a(i)-a(o)),height:e.width};l.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:b,iqrLine:y,stats:_n(t),style:f,datum:e.pieceData,category:e.name})}return l},histogram:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a}=o,c=[],l=r.bins||25,u=r.normalize,d=a.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;const[o,i]=St(t),r=null!=h&&isFinite(h)?h:o,d=null!=p&&isFinite(p)?p:i,m=(d-r)/l||1,g=Array(l).fill(0);for(const e of t)r>e||e>d||g[Math.min(Math.floor((e-r)/m),l-1)]++;const f=t.length,y=At(g,1),b=n(e.pieceData[0],e.name);for(let t=0;l>t;t++){if(0===g[t])continue;const o=(u?g[t]/f:g[t]/y)*e.width*.9,i=a(r+t*m),s=a(r+(t+1)*m);c.push(T(Math.min(i,s),e.x+e.width-o,Math.abs(s-i),o,b,{bin:t,count:g[t],range:[r+t*m,r+(t+1)*m],category:e.name},e.name))}}return c},ridgeline:function(e,t){const{scales:o,columns:i,config:r,getR:s,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],u=r.bins||20,d="horizontal"===c,h=r.amplitude||1.5;for(const e of Object.values(i)){const t=e.pieceData.map(e=>s(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],r=(i-o)/u||1,c=Array(u).fill(0);for(const e of t)o>e||e>i||c[Math.min(Math.floor((e-o)/r),u-1)]++;const p=At(c,1),m=n(e.pieceData[0],e.name),g=e.width*h;let f;if(d){const t=e.x+e.width;f=`M ${a(o)} ${t}`;for(let e=0;u>e;e++)f+=` L ${a(o+(e+.5)*r)} ${t-c[e]/p*g}`;f+=` L ${a(i)} ${t} Z`}else{const t=e.x;f=`M ${t} ${a(o)}`;for(let e=0;u>e;e++){const i=a(o+(e+.5)*r);f+=` L ${t+c[e]/p*g} ${i}`}f+=` L ${t} ${a(i)} Z`}const y=d?{x:Math.min(a(o),a(i)),y:e.x,width:Math.abs(a(i)-a(o)),height:e.width}:{x:e.x,y:Math.min(a(i),a(o)),width:e.width,height:Math.abs(a(i)-a(o))};l.push({type:"violin",pathString:f,translateX:0,translateY:0,bounds:y,stats:_n(t),style:{...m,fillOpacity:m.fillOpacity??.5},datum:e.pieceData,category:e.name})}return l},timeline:function(e,t){const{scales:o,columns:i,getRawRange:r,resolvePieceStyle:s}=e,{r:n,projection:a}=o,c=[],l="horizontal"===a;for(const e of Object.values(i))for(const t of e.pieceData){const o=r(t);if(!o)continue;const[i,a]=o,u=s(t,e.name);if(l){const o=n(Math.min(i,a)),r=n(Math.max(i,a));c.push(T(o,e.x,r-o,e.width,u,t,e.name))}else{const o=n(Math.max(i,a)),r=n(Math.min(i,a));c.push(T(e.x,o,e.width,r-o,u,t,e.name))}}return c},funnel:function(e,t){const{columns:o,getR:i,getStack:r,resolvePieceStyle:s}=e,n=[],a=t.width/2,c=!1!==e.config.showLabels,l=e.scales.o.domain().map(e=>o[e]).filter(Boolean);if(0===l.length)return n;const u=[],d=new Set;for(const e of l)for(const t of e.pieceData){const e=r?r(t):"_default";d.has(e)||(d.add(e),u.push(e))}const h=u.length>1&&"_default"!==u[0],p=[];let m=0;for(const e of l){const t=new Map;let o=0;for(const s of e.pieceData){const e=r?r(s):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(s);n.total+=a,n.pieces.push(s),o+=a}p.push({col:e,groups:t,stepTotal:o}),h||o>m&&(m=o)}if(h)for(const e of p){let t=0,o=0;for(let i=0;u.length>i;i++){const r=e.groups.get(u[i]);r&&(i%2==0?t+=r.total:o+=r.total)}const i=Math.max(t,o);i>m&&(m=i)}if(0===m)return n;const g=new Map;for(const e of u){const t=p[0].groups.get(e);g.set(e,t?.total??0)}const f=p[0].stepTotal,y=h?.95*a:.9*t.width,b=Mn().domain([0,m]).range([0,y]),x=e.config.connectorOpacity??.3;let v=new Map;for(let t=0;p.length>t;t++){const o=p[t],i=o.col,r=0===t,l=i.width,d=.55*l,m=i.x+(l-d)/2,y=new Map;if(h){let e=0;for(const t of u){const i=o.groups.get(t);i&&(e+=b(i.total))}let t=a,l=a;for(let h=0;u.length>h;h++){const p=u[h],f=o.groups.get(p);if(!f)continue;const x=b(f.total),v=h%2==0,A=v?t:l-x;v?t+=x:l-=x;const w=s(f.pieces[0],p),S=g.get(p)??f.total,k={...f.pieces[0],__funnelValue:f.total,__funnelPercent:S>0?f.total/S*100:0,__funnelStep:i.name,__funnelIsFirstStep:r,__aggregateValue:f.total,__pieceCount:f.pieces.length,category:p};c&&(0===h&&(k.__funnelStepLabel=i.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=m,k.__funnelRowWidth=e),k.__funnelValueLabelX=A+x/2,k.__funnelValueLabelY=m,k.__funnelBarW=x),n.push(T(A,m,x,d,w,k,p)),y.set(p,{x:A,y:m,w:x,h:d})}}else{const e=o.stepTotal,t=b(e),l=a-t/2,h=u[0],p="_default"!==h,g=o.groups.get(h)?.pieces[0]??i.pieceData[0],x=p?h:i.name,v=s(g,x),A=f>0?e/f*100:0,w={...g,__funnelValue:e,__funnelPercent:A,__funnelStep:i.name,__funnelIsFirstStep:r,category:p?h:i.name};c&&(w.__funnelStepLabel=i.name,w.__funnelStepLabelX=a,w.__funnelStepLabelY=m,w.__funnelRowWidth=t,w.__funnelValueLabelX=a,w.__funnelValueLabelY=m,w.__funnelBarW=t),n.push(T(l,m,t,d,v,w,x)),y.set(h,{x:l,y:m,w:t,h:d})}if(t>0&&v.size>0){const t=h?u:[u[0]];for(const r of t){const t=v.get(r),a=y.get(r);if(!t||!a)continue;const c=(()=>{const e=o.groups.get(r);return s(e?e.pieces[0]:i.pieceData[0],"_default"===r?i.name:r)})(),l={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||e.config.themeSemantic?.secondary||"#999",opacity:x},datum:o.groups.get(r)?.pieces[0]??i.pieceData[0],category:"_default"===r?i.name:r};n.push(l)}}v=y}return n},"bar-funnel":function(e,t){const{columns:o,getR:i,getStack:r,resolvePieceStyle:s,scales:n}=e,a=[],c=n.o.domain().map(e=>o[e]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const e of c)for(const t of e.pieceData){const e=r?r(t):"_default";u.has(e)||(u.add(e),l.push(e))}const d=l.length>1&&"_default"!==l[0],h=[];for(const e of c){const t=new Map;let o=0;for(const s of e.pieceData){const e=r?r(s):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(s);n.total+=a,n.pieces.push(s),o+=a}h.push({col:e,groups:t,stepTotal:o})}const p=new Map;for(const e of l){const t=h[0]?.groups.get(e);p.set(e,t?.total??0)}const m=n.r,g=d?l.length:1,f=d?.15:0;for(let e=0;h.length>e;e++){const t=h[e],o=t.col,i=0===e,r=e>0?h[e-1]:null,n=o.width/g,c=n*f,u=n-c;for(let e=0;l.length>e;e++){const h=l[e],g=t.groups.get(h);if(!g)continue;const f=g.total,y=p.get(h)??f,b=y>0?f/y*100:0,x=r?.groups.get(h),v=i?0:Math.max(0,(x?.total??f)-f),A=o.x+e*n+c/2,w=m(f),S=m(0)-w,k=s(g.pieces[0],d?h:o.name),_={...g.pieces[0],__barFunnelValue:f,__barFunnelPercent:b,__barFunnelIsFirstStep:i,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:A+u/2,__barFunnelLabelY:m(f+v)};if(a.push(T(A,w,u,S,k,_,d?h:o.name)),v>0){const e=m(f+v),t=w-e,i={...k},r={...g.pieces[0],__barFunnelValue:v,__barFunnelPercent:y>0?v/y*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(T(A,e,u,t,i,r,d?h:o.name))}}}return a},swimlane:function(e,t){const{scales:o,columns:i,getR:r,getStack:s,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],u="horizontal"===c,d=e.config.gradientFill,h=u?"left":"bottom",p=e.config.trackFill;if(p){const e="string"==typeof p?p:p.color,t="string"==typeof p?1:p.opacity??1,[o,r]=a.range(),s=Math.min(o,r),n=Math.abs(r-o);for(const o of Object.values(i)){const i={fill:e,opacity:t},r=u?T(s,o.x,n,o.width,i,null,"__track__"):T(o.x,s,o.width,n,i,null,"__track__");l.push(r)}}const m=e.config.roundedTop&&e.config.roundedTop>0?Math.max(0,e.config.roundedTop):0;for(const e of Object.values(i)){let t=0;const o=l.length;for(const o of e.pieceData){const i=Math.abs(r(o));if(0===i)continue;const c=s?s(o):e.name,p=n(o,c);let m;if(u){const r=a(t),s=a(t+i);m=T(r,e.x,s-r,e.width,p,o,c)}else{const r=a(t+i),s=a(t);m=T(e.x,r,e.width,s-r,p,o,c)}d&&(m.fillGradient=d,m.roundedEdge=h),l.push(m),t+=i}if(m>0&&l.length>o){const e=l.slice(o),t=e[0],i=e[e.length-1];1===e.length?t.cornerRadii={tl:m,tr:m,br:m,bl:m}:u?(t.cornerRadii={tl:m,bl:m},i.cornerRadii={tr:m,br:m}):(t.cornerRadii={bl:m,br:m},i.cornerRadii={tl:m,tr:m})}}return l}},Pn=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ln=["scene-style","data-paint","accessibility","evidence"],In=(e,t)=>({retainedData:e,invalidations:t}),Tn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Cn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],zn=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],On=["scene-geometry","data-paint","accessibility","evidence"],Fn=["scene-style","data-paint","accessibility","evidence"],Bn=[],En={chartType:In("rebuild",Tn),runtimeMode:In("rebuild",Tn),categoryAccessor:In("rebuild",Tn),valueAccessor:In("rebuild",Tn),oAccessor:In("rebuild",Tn),rAccessor:In("rebuild",Tn),stackBy:In("rebuild",Tn),groupBy:In("rebuild",Tn),timeAccessor:In("rebuild",Tn),accessorRevision:In("rebuild",Tn),colorAccessor:In("rebuild",Fn),symbolAccessor:In("rebuild",On),connectorAccessor:In("rebuild",On),dataIdAccessor:In("rebuild",On),projection:In("preserve",Cn),extentPadding:In("preserve",Cn),axisExtent:In("preserve",Cn),rExtent:In("preserve",Cn),oExtent:In("preserve",Cn),multiAxis:In("preserve",Cn),normalize:In("preserve",Cn),bins:In("preserve",Cn),oSort:In("preserve",zn),barPadding:In("preserve",zn),roundedTop:In("preserve",zn),baselinePadding:In("preserve",zn),innerRadius:In("preserve",zn),cornerRadius:In("preserve",zn),startAngle:In("preserve",zn),sweepAngle:In("preserve",zn),trackFill:In("preserve",zn),showOutliers:In("preserve",zn),showIQR:In("preserve",zn),amplitude:In("preserve",zn),connectorOpacity:In("preserve",zn),showLabels:In("preserve",zn),dynamicColumnWidth:In("rebuild",zn),customLayout:In("preserve",zn),layoutConfig:In("preserve",zn),layoutMargin:In("preserve",zn),symbolMap:In("preserve",On),pieceStyle:In("preserve",Fn),summaryStyle:In("preserve",Fn),connectorStyle:In("preserve",Fn),gradientFill:In("preserve",Fn),colorScheme:In("preserve",Fn),themeCategorical:In("preserve",Fn),themeSemantic:In("preserve",Fn),themeSequential:In("preserve",Fn),themeDiverging:In("preserve",Fn),barColors:In("preserve",Fn),decay:In("preserve",Fn),pulse:In("preserve",Fn),staleness:In("preserve",Fn),layoutSelection:In("preserve",Fn),windowSize:In("preserve",Bn),windowMode:In("preserve",Bn),clock:In("preserve",Bn),transition:In("preserve",Bn),introAnimation:In("preserve",Bn),onLayoutError:In("preserve",Bn)},jn=In("preserve",zn),Dn=class{constructor(){this.tracker=new lt}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Pn)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Ln):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const o=new Set;for(const i of e){const e=En[i]??jn;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as Nn}from"d3-quadtree";var $n=class{constructor(e){this.rExtent=new J,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Dn,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new vn,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new ee(e.windowSize),this.getO=nt(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>st(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new J)):(this.getR=st(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=nt(e.stackBy),this.getGroup=nt(e.groupBy),this.getColor=nt(e.colorAccessor),this.getSymbol=nt(e.symbolAccessor),this.getConnector=nt(e.connectorAccessor),this.getDataId=nt(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new ee(e.windowSize))}syncPulseTimestampBuffer(){var e,t,o,i;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,o=this.timestampBuffer,i=this.currentTime(),e?null!=o&&o.capacity===t.capacity&&o.size===t.size?o:E(t,i):null)}currentTime(){return this.config.clock?.()??Le()}ingest(e){const t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),j(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const o of e.inserts)V(this.buffer,o,this.timestampBuffer,t),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of e.inserts){const e=V(this.buffer,o,this.timestampBuffer,t);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){const t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;const o="function"==typeof t?t(e):e[t];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(e){const{config:t,buffer:o}=this,i=this.scales,r=this.multiScales,s=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const n=this.getBufferArray(),a=t.projection||"vertical",c=t.oExtent||this.resolveCategories(n),l=this.computeValueDomain(n,c),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===a?e.width:e.height):.1));let p,m;if(d){p=bn().domain(c).range([0,1]).padding(0);const o=Math.min(e.width,e.height)/2,i=t.innerRadius||0;m=xn().domain(l).range([i,o])}else u?(p=bn().domain(c).range([0,e.height]).padding(h),m=xn().domain(l).range([0,e.width])):(p=bn().domain(c).range([0,e.width]).padding(h),m=xn().domain(l).range([e.height,0]));this.scales={o:p,r:m,projection:a},this.multiScales=this.rAccessors.length>1&&t.multiAxis?this.rAccessors.map((i,r)=>{const s=this.rExtents[r];s.dirty&&s.recalculate(o,i);let[n,a]=s.extent;n===1/0&&(n=0,a=1);const c=a-n,l=c>0?c*(t.extentPadding??.05):1;return n-=l,a+=l,n>0&&(n=0),u?xn().domain([n,a]).range([0,e.width]):xn().domain([n,a]).range([e.height,0])}):[];let g=n;this.rAccessors.length>1&&(g=n.flatMap(e=>this.rAccessors.map((t,o)=>({...e,__rIndex:o,__rValue:t(e),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(g,c,p,a,e),this._customLayoutFailedThisBuild=!1;const f=this.buildSceneNodes(g,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=i,this.multiScales=r,this.columns=s):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=f,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,n),this.config.pulse&&this.applyPulse(this.scene,n),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){const t=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(t)?t[e]:t;return"string"==typeof o?o:"value"+e}resolveCategories(e){const t=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,i="auto"===t?void 0:t;let r=null;if(o){r=new Set;for(const t of e)r.add(this.getO(t))}const s=r?Array.from(this.categories).filter(e=>r.has(e)):Array.from(this.categories);if(o&&void 0===i){const e=Math.max(50,3*r.size);if(this.categories.size>e){let t=this.categories.size-e;for(const e of this.categories){if(0>=t)break;r.has(e)||(this.categories.delete(e),t--)}}return s}if(!1===i)return s;if("function"==typeof i)return s.sort(i);const n=new Map;for(const t of e){const e=this.getO(t);n.set(e,(n.get(e)||0)+Math.abs(this.getR(t)))}return s.sort("asc"===i?(e,t)=>(n.get(e)||0)-(n.get(t)||0):(e,t)=>(n.get(t)||0)-(n.get(e)||0))}computeValueDomain(e,t){return function(e){const{data:t,chartType:o,projection:i,normalize:r,rExtent:s,extentPadding:n=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:d,rawRExtent:h}=e,p=n;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let m=0,g=0;if("bar"===o&&d&&r)m=0,g=1;else if("bar"===o&&d){const e=new Map,o=new Map;for(const i of t){const t=l(i),r=u(i);0>r?o.set(t,(o.get(t)||0)+r):e.set(t,(e.get(t)||0)+r)}for(const t of e.values())t>g&&(g=t);for(const e of o.values())m>e&&(m=e)}else if("bar"===o){const e=new Map;for(const o of t){const t=l(o),i=u(o);e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>g&&(g=t),m>t&&(m=t)}else if("swimlane"===o){const e=new Map;for(const o of t){const t=l(o),i=Math.abs(u(o));e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>g&&(g=t)}else if("clusterbar"===o||"bar-funnel"===o)for(const e of t){const t=u(e);t>g&&(g=t),m>t&&(m=t)}else{const e=h[0],t=h[1];e!==1/0&&(m=e),t!==-1/0&&(g=t)}s&&(null!=s[0]&&(m=s[0]),null!=s[1]&&(g=s[1]));const f="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(f&&null==s?.[0]&&null==s?.[1]&&(m>0&&(m=0),0>g&&(g=0)),"bar-funnel"!==o&&"exact"!==c){const e=g-m,t=e>0?e*p:1,i=f&&!a&&0===m,r=f&&!a&&0===g||"swimlane"===o;null!=s?.[0]||i||(m-=t),null!=s?.[1]||r||(g+=t)}return[m,g]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,o,i,r){return function(e){const{data:t,oExtent:o,oScale:i,projection:r,layout:s,dynamicColumnWidth:n,getO:a,getR:c}=e,l={},u=new Map;for(const e of t){const t=a(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===r)for(const e of t)d+=Math.abs(c(e));let h=null;if(n&&"radial"!==r){h=new Map;let e=0;for(const t of o){const o=u.get(t)||[];let i;i="string"==typeof n?o.reduce((e,t)=>e+(Number(t[n])||0),0):n(o),h.set(t,i),e+=i}const t=("horizontal"===r?s.height:s.width)-i.padding()*i.step()*o.length;if(e>0)for(const[o,i]of h)h.set(o,i/e*t)}let p=0,m=0;for(const e of o){const t=u.get(e)||[],o=t.reduce((e,t)=>e+Math.abs(c(t)),0),r=d>0?o/d:0;let s,n;h?(s=m,n=h.get(e)||i.bandwidth(),m+=n+i.padding()*i.step()):(s=i(e)??0,n=i.bandwidth()),l[e]={name:e,x:s,y:0,width:n,middle:s+n/2,padding:i.padding()*i.step(),pieceData:t,pct:r,pctStart:p},p+=r}return l}({data:e,oExtent:t,oScale:o,projection:i,layout:r,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(e,t);let i;try{i=this.config.customLayout(o)}catch(e){const t=null!==this.lastCustomLayoutResult,o=B("ordinal",e,t,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",e);try{this.config.onLayoutError?.(o)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return t?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=i.overlays??null,this.lastCustomLayoutResult=i,this.lastCustomLayoutFailure=null;const r=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const e of r)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(r,this.config.layoutSelection??null)}return Z({label:"ordinal customLayout",nodes:r,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),r}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),i=Rn[this.config.chartType];let r=i?i(o,t):[];if(this.getConnector&&this.scales){const e=function(e,t){const{scales:o,config:i,getConnector:r,getO:s}=e;if(!r||!o)return[];const n=[],{projection:a}=o,c=new Map;for(const e of t){if("point"!==e.type&&"rect"!==e.type)continue;const t=e.datum;if(!t)continue;const o=r(t);if(!o)continue;let i,n;"point"===e.type?(i=e.x,n=e.y):(i=e.x+e.w/2,n=e.y+("vertical"===a?0:e.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:i,y:n,datum:t,category:s(t)})}const l=o.o.domain(),u=i.connectorStyle;for(const[t,o]of c)if(o.length>=2){o.sort((e,t)=>l.indexOf(e.category)-l.indexOf(t.category));for(let i=0;o.length-1>i;i++){const r=o[i],s=o[i+1],a="function"==typeof u?u(r.datum):u||{stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};n.push({type:"connector",x1:r.x,y1:r.y,x2:s.x,y2:s.y,style:a,datum:r.datum,group:t})}}return n}(o,r);r=[...e,...r]}return r}buildLayoutContext(e,t){const o=this.config,i=o.layoutMargin??{top:0,right:0,bottom:0,left:0},r=Ee(o.colorScheme,o.themeCategorical,ne),s=this.scales;return{data:e,scales:{o:s.o,r:s.r,projection:s.projection},dimensions:{width:t.width,height:t.height,margin:i,plot:"radial"===s.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:[...r]},resolveColor:ue(r,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(e,t){const o=this.config.decay;return o&&t>1?O(o,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const t=I(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const t=function(e,t){const o="function"==typeof t,i=o?null:t||"category",r=new Map;for(let s=0;e.length>s;s++){const n=e[s],a=o?t(n):n[i],c=r.get(a);c?c.push(s):r.set(a,[s])}return r}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){const e=function(e){let t=0,o=0;for(const i of e)"point"===i.type&&(t++,i.r>o&&(o=i.r));if(500>=t)return{quadtree:null,maxRadius:o};const i=Array(t);let r=0;for(const t of e)"point"===t.type&&(i[r++]=t);return{maxRadius:o,quadtree:Nn().x(e=>e.x).y(e=>e.y).addAll(i)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;const o=t.length;if(1>=o)return;const i=this.getDatumIndexMap(t);for(const t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type)continue;if(!t.datum)continue;const e=i.get(t.datum);if(null==e)continue;const r=this.computeDecayOpacity(e,o);t.style={...t.style,opacity:(t.style?.opacity??1)*r}}}applyPulse(e,t,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,o,i,r,s){const n=e.color??"rgba(255,255,255,0.6)",a=e.glowRadius??4;let c=!1;for(const l of t){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const t=l.category;if(!t)continue;let i=0;for(const n of r(t)??[]){const t=o.get(n);null!=t&&(i=Math.max(i,F(e,t,s)))}c=U(l,i,n)||c;continue}if(null==l.datum)continue;const t=i.get(l.datum);if(null==t)continue;const u=o.get(t),d=null==u?0:F(e,u,s);c=U(l,d,n,a)||c}return c}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),o)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&N(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const e=new Map,t=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let i;for(let r=0;this.scene.length>r;r++){const s=this.scene[r],n=this.getNodeKey(s,e);n&&("rect"===s.type?this.prevPositionMap.set(n,o?{x:s.x,y:t,w:s.w,h:0,opacity:s.style.opacity??1}:{x:t,y:s.y,w:0,h:s.h,opacity:s.style.opacity??1}):"point"===s.type?this.prevPositionMap.set(n,{x:s.x,y:s.y,r:0,opacity:0}):"wedge"===s.type&&(void 0===i&&(i=s.startAngle),this.prevPositionMap.set(n,{x:s.cx,y:s.cy,startAngle:i,endAngle:i,innerRadius:s.innerRadius,outerRadius:s.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){const o=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,i=t.get(o)||0;return t.set(o,i+1),`${o}:${i}`}return"rect"===e.type?`r:${e.group||""}:${e.datum?.category??""}`:"wedge"===e.type?"w:"+(e.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const e=new Map;for(let t=0;this.scene.length>t;t++){const o=this.scene[t],i=this.getNodeKey(o,e);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity}):"wedge"===o.type&&this.prevPositionMap.set(i,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const e=this.config.transition.duration??300;if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1;const o=new Set,i=new Map;for(let e=0;this.scene.length>e;e++){const r=this.scene[e],s=this.getNodeKey(r,i);if(!s)continue;r._transitionKey=s;const n=this.prevPositionMap.get(s);if("point"===r.type)n?(o.add(s),r._targetOpacity=r.style.opacity??1,(n.x!==r.x||n.y!==r.y||void 0!==n.r&&n.r!==r.r)&&(r._targetX=r.x,r._targetY=r.y,r._targetR=r.r,r.x=n.x,r.y=n.y,void 0!==n.r&&(r.r=n.r),t=!0)):(r._targetOpacity=r.style.opacity??1,r._targetR=r.r,r.r=0,r.style={...r.style,opacity:0},t=!0);else if("rect"===r.type)n?(o.add(s),r._targetOpacity=r.style.opacity??1,n.x===r.x&&n.y===r.y&&n.w===r.w&&n.h===r.h||(r._targetX=r.x,r._targetY=r.y,r._targetW=r.w,r._targetH=r.h,r.x=n.x,r.y=n.y,r.w=n.w??r.w,r.h=n.h??r.h,t=!0)):(r._targetOpacity=r.style.opacity??1,r.style={...r.style,opacity:0},t=!0);else if("wedge"===r.type)if(n)o.add(s),r._targetOpacity=r.style.opacity??1,n.startAngle===r.startAngle&&n.endAngle===r.endAngle||(r._targetStartAngle=r.startAngle,r._targetEndAngle=r.endAngle,r.startAngle=n.startAngle,r.endAngle=n.endAngle,t=!0);else{r._targetOpacity=r.style.opacity??1,r._targetStartAngle=r.startAngle,r._targetEndAngle=r.endAngle;const e=r.startAngle;r.startAngle=e,r.endAngle=e,r.style={...r.style,opacity:0},this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:e,endAngle:e,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(const[e,i]of this.prevPositionMap)if(!o.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:i.x,y:i.y,r:i.r??3,style:{opacity:i.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:i.x,y:i.y,w:i.w??0,h:i.h??0,style:{opacity:i.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){const t=((i.startAngle??0)+(i.endAngle??0))/2,o={type:"wedge",cx:i.x,cy:i.y,innerRadius:i.innerRadius??0,outerRadius:i.outerRadius??100,startAngle:i.startAngle??0,endAngle:i.endAngle??0,style:{opacity:i.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(o)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;const t=pe(e,this.activeTransition),o=he(t,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const e of this.scene){const t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=_e(i?i.opacity??1:0,e._targetOpacity,o)}const i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=_e(i.x,e._targetX,o),e.y=_e(i.y,e._targetY,o)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=_e(i.r,e._targetR,o))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=_e(i?i.opacity??1:0,e._targetOpacity,o)}if(void 0===e._targetX)continue;const i=this.prevPositionMap.get(t);if(!i)continue;e.x=_e(i.x,e._targetX,o),e.y=_e(i.y,e._targetY,o),void 0!==i.w&&(e.w=_e(i.w,e._targetW,o),e.h=_e(i.h,e._targetH,o))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style={...e.style,opacity:_e(i?i.opacity??1:0,e._targetOpacity,o)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){const i=this.prevPositionMap.get(t);i&&void 0!==i.startAngle&&(e.startAngle=_e(i.startAngle,e._targetStartAngle,o),e.endAngle=_e(i.endAngle,e._targetEndAngle,o))}}}if(t>=1){for(const e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const t=K(e),o=this.getDataId,i=e=>t.has(o(e));z(this.buffer,this.timestampBuffer,i);const r=this.buffer.remove(i);if(0===r.length)return this.updateResults.recordNoop("remove"),r;for(const e of r)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",r.length),r}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=K(e),i=this.getDataId,r=new Set;this.buffer.forEach((e,t)=>{o.has(i(e))&&r.add(t)});const s=this.buffer.update(e=>o.has(i(e)),t);if(0===s.length)return this.updateResults.recordNoop("update"),s;for(const e of s)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),r.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",s.length),s}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){const o=this._customRestyle;if(o)for(const i of e){const e=this._baseStyles.get(i)??i.style??{},r=o(i,t);i.style=r?{...e,...r}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){const t={...this.config},o=Object.keys(e).filter(o=>e[o]!==t[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!tt(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!tt(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!tt(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in e||"oAccessor"in e)&&(tt(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=nt(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let r=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,o=t.valueAccessor||t.rAccessor,i=Array.isArray(e)?e:[e],s=Array.isArray(o)?o:[o];if(r=i.length!==s.length||i.some((e,t)=>!tt(e,s[t])),r){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>st(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new J)):(this.getR=st(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!tt(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?nt(this.config.stackBy):void 0),"groupBy"in e&&!tt(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?nt(this.config.groupBy):void 0),"colorAccessor"in e&&!tt(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?nt(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!tt(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?nt(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!tt(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?nt(this.config.connectorAccessor):void 0),(i||r||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};R($n);import{jsx as Wn,jsxs as Gn}from"react/jsx-runtime";import{Fragment as Vn,jsx as Hn,jsxs as Yn}from"react/jsx-runtime";function Xn(e,t){const o=Et(e.theme),i=e.size||[500,400],r=Oe({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=ve(e.title),n=ge(e.data),a=e.showLegend?Vs(n,e.colorAccessor||e.stackBy||e.groupBy):[];ln(r,{props:e,categories:a,theme:o,size:i,hasTitle:s});const c=i[0]-r.left-r.right,l=i[1]-r.top-r.bottom,u=e.projection||"vertical",d="radial"===u,h=e.colorScheme||o.colors.categorical,p={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:u,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:W(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:h,themeCategorical:o.colors.categorical,themeSemantic:Lt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors},m=new $n(p);if(e.data&&m.ingest({inserts:n,bounded:!0}),m.computeScene({width:c,height:l}),!m.scales||0===m.scene.length)return t&&(t.evidence=Ls({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:m.scales?[]:["NO_SCALES"],margin:r})),yn.renderToStaticMarkup(hn(null,{width:i[0],height:i[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left},${r.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const g=e._idPrefix,f=e.showGrid?function(e,t,o,i,r){const s=e.scales;if(!s||"radial"===s.projection)return null;const{grid:n}=jt(o),a=i?i+"-":"",c="vertical"===s.projection,l=Q(s.r,5,r);return en("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=s.r(e);return en("line",{x1:0,y1:i,x2:t.width,y2:i,stroke:n,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=s.r(e);return en("line",{x1:i,y1:0,x2:i,y2:t.height,stroke:n,strokeWidth:.5},"gr-"+o)})})}(m,{width:c,height:l},o,g,e.axisExtent):null;let y=null;if(m.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){const t=rn(e),i=new Set;for(const e of m.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&i.add("string"==typeof e.style.fill?e.style.fill:"#666");y=Array.from(i).map((e,i)=>function(e){const{id:t,background:o="transparent",stroke:i="#000",lineWidth:r=1.5,spacing:s=6,angle:n=45}=e,a=Math.max(8,Math.ceil(2*s));return Gn("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[o&&"transparent"!==o&&Wn("rect",{width:a,height:a,fill:o}),Wn("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:r}),Wn("line",{x1:s,y1:0,x2:s,y2:a,stroke:i,strokeWidth:r})]},t)}({id:`funnel-hatch-${t}-${i}`,background:e,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const r=new Map;Array.from(i).forEach((e,o)=>r.set(e,`funnel-hatch-${t}-${o}`));for(const e of m.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${r.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}const b=H({nodes:m.scene,renderMode:e.renderMode,fallback:(e,t)=>Ie(e,t,g)}),x=b.map(e=>e.element);if(t){const o=m.scales.o?.domain?.();t.evidence=Ls({frameType:"ordinal",width:i[0],height:i[1],marks:b.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:Ps(m.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:r})}const v=!1!==e.showAxes?function(e,t,o,i,r){const s=e.scales;if(!s)return null;if("radial"===s.projection)return null;const n=jt(i),a="vertical"===s.projection,c=o.categoryFormat||o.oFormat,l=o.valueFormat||o.rFormat,u=o.categoryLabel||o.oLabel,d=o.valueLabel||o.rLabel,h=Object.values(e.columns).map(e=>({pixel:e.middle,label:(c||String)(e.name)})),p=Q(s.r,5,o.axisExtent).map(e=>({pixel:s.r(e),label:(l||dn)(e)}));return Yn("g",a?{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Hn("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),h.map((e,o)=>Yn("g",{transform:`translate(${e.pixel},${t.height})`,children:[Hn("line",{y2:5,stroke:n.border,strokeWidth:1}),Hn("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),u&&Hn("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:u}),Hn("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),p.map((e,t)=>Yn("g",{transform:`translate(0,${e.pixel})`,children:[Hn("line",{x2:-5,stroke:n.border,strokeWidth:1}),Hn("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),d&&Hn("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:d})]}:{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Hn("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),p.map((e,o)=>Yn("g",{transform:`translate(${e.pixel},${t.height})`,children:[Hn("line",{y2:5,stroke:n.border,strokeWidth:1}),Hn("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),d&&Hn("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:d}),Hn("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),h.map((e,t)=>Yn("g",{transform:`translate(0,${e.pixel})`,children:[Hn("line",{x2:-5,stroke:n.border,strokeWidth:1}),Hn("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),u&&Hn("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:u})]})}(m,{width:c,height:l},e,o,g):null,A=e.annotations?Zs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:n,scales:{o:m.scales.o,r:m.scales.r,y:"vertical"===m.scales.projection?m.scales.r:void 0},layout:{width:c,height:l},theme:o,projection:u,idPrefix:g}):null,w=un({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s}),S=d?r.left+c/2:r.left,k=d?r.top+l/2:r.top,_=d&&e.centerContent?Hn("foreignObject",{x:r.left,y:r.top,width:c,height:l,pointerEvents:"none",children:Hn("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return yn.renderToStaticMarkup(hn(Yn(Vn,{children:[e.backgroundGraphics,f,x,v,A,e.foregroundGraphics,m.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${S},${k})`,innerWidth:c,innerHeight:l,legend:w,defs:y,outerElements:_,idPrefix:e._idPrefix}))}import*as qn from"react-dom/server";import{Fragment as Un,jsxs as Qn}from"react/jsx-runtime";function Kn(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Zn=new Set(["tree","cluster","treemap","circlepack","partition"]);function Jn(e,t){const o=Et(e.theme),i=e.chartType||"force",r=()=>Ls({frameType:"network",width:s[0],height:s[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,nodeCount:0,edgeCount:0,margin:n}),s=e.size||[500,500],n=Oe({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=ve(e.title),c=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;if(!t)return[];const i=ge(e.nodes||[]);if(i.length>0)return Vs(i,t);const r=Array.isArray(e.edges)?ge(e.edges):[];if(0===r.length)return[];const s=Kn(e.sourceAccessor,"source"),n=Kn(e.targetAccessor,"target");return Vs(Array.from(new Set(r.flatMap(e=>[s(e),n(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];ln(n,{props:e,categories:c,theme:o,size:s,hasTitle:a});const l=s[0]-n.left-n.right,u=s[1]-n.top-n.bottom,d=D(i);if(!d&&!e.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${i}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const h={chartType:i,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||o.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig};let p,m;if(Zn.has(i)){const i=e.data||e.edges;if(!i||Array.isArray(i))return t&&(t.evidence=r()),qn.renderToStaticMarkup(hn(null,{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:e._idPrefix}));h.__hierarchyRoot=i,p=[],m=[]}else{const i=ge(e.nodes||[]),a=Array.isArray(e.edges)?ge(e.edges):[];if(0===i.length&&0===a.length)return t&&(t.evidence=r()),qn.renderToStaticMarkup(hn(null,{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,idPrefix:e._idPrefix}));if(m=function(e,t){const o=Kn(t.sourceAccessor,"source"),i=Kn(t.targetAccessor,"target"),r=Kn(t.valueAccessor,"value");return e.map(e=>({source:o(e)+"",target:i(e)+"",value:Number(r(e))||1,y0:0,y1:0,sankeyWidth:0,data:e}))}(a,h),0===i.length&&m.length>0){const e=new Set;for(const t of m){const o=on(t.source),i=on(t.target);o&&e.add(o),i&&e.add(i)}p=Array.from(e).map(e=>({id:e,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:e}}))}else p=function(e,t){const o=Kn(t.nodeIDAccessor,"id");return e.map(e=>({id:o(e)+"",x:e.x??0,y:e.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:e}))}(i,h)}let g=[],f=[],y=[],b=null;if(h.customNetworkLayout){const e=h.colorScheme,t=Ee(e,o.colors.categorical,vt),i=ue(t,e),r={nodes:p,edges:m,dimensions:{width:l,height:u,plot:{x:0,y:0,width:l,height:u}},theme:{semantic:o.colors,categorical:[...t]},resolveColor:i,config:h.layoutConfig??{}},s=h.customNetworkLayout(r);g=s.sceneNodes??[],f=s.sceneEdges??[],y=s.labels??[],b=s.overlays??null}else if(d){d.computeLayout(p,m,h,[l,u]);const e=d.buildScene(p,m,h,[l,u]);g=e.sceneNodes,f=e.sceneEdges,y=e.labels}const x=jt(o);for(const e of y)e.fill||(e.fill=x.text);const v=H({nodes:f,renderMode:e.renderMode,fallback:(e,t)=>Re(e,t)}),A=H({nodes:g,renderMode:e.renderMode,fallback:(e,t)=>Pe(e,t)});t&&(t.evidence=Ls({frameType:"network",width:s[0],height:s[1],marks:[...A.map(({node:e})=>({type:"node:"+(e.type??"node")})),...v.map(({node:e})=>({type:"edge:"+(e.type??"edge")}))],title:e.title,description:e.description,annotations:e.annotations,nodeCount:A.length,edgeCount:v.length,margin:n}));const w=v.map(e=>e.element),S=A.map(e=>e.element),k=y.map((e,t)=>Me(e,t)).filter(Boolean),_=e.annotations?Zs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{},layout:{width:l,height:u},theme:o,idPrefix:e._idPrefix}):null,M=un({props:e,categories:c,theme:o,size:s,margin:n,hasTitle:a});return qn.renderToStaticMarkup(hn(Qn(Un,{children:[e.backgroundGraphics,w,S,k,_,e.foregroundGraphics,b]}),{width:s[0],height:s[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:u,legend:M,idPrefix:e._idPrefix}))}import*as ea from"react-dom/server";import{geoPath as ta}from"d3-geo";import{quadtree as oa}from"d3-quadtree";import{geoMercator as ia,geoEqualEarth as ra,geoAlbersUsa as sa,geoOrthographic as na,geoNaturalEarth1 as aa,geoEquirectangular as ca}from"d3-geo";var la={mercator:ia,equalEarth:ra,albersUsa:sa,orthographic:na,naturalEarth:aa,equirectangular:ca};function ua(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function da(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function ha(e,t,o){return e?"function"==typeof e?{...o,...e(t)}:{...o,...e}:{...o}}function pa(e,t){if(2>e.length)return[e];const o=.4*t,i=[];let r=[e[0]];for(let t=1;e.length>t;t++){const s=e[t];Math.abs(s[0]-e[t-1][0])>o?(2>r.length||i.push(r),r=[s]):r.push(s)}return 2>r.length||i.push(r),i}function ma(e,t,o=24){const i=t[0]-e[0],r=t[1]-e[1],s=Math.sqrt(i*i+r*r);if(0===s)return[e,t];const n=-r/s,a=i/s,c=Math.min(.3*s,80),l=(e[0]+t[0])/2+n*c,u=(e[1]+t[1])/2+a*c,d=[];for(let i=0;o>=i;i++){const r=i/o,s=1-r;d.push([s*s*e[0]+2*s*r*l+r*r*t[0],s*s*e[1]+2*s*r*u+r*r*t[1]])}return d}function ga(e,t){if(2>e.length)return e;const o=t/2+1,i=[];for(let t=0;e.length>t;t++){const r=e[t];let s,n;0===t?(s=e[1][0]-r[0],n=e[1][1]-r[1]):t===e.length-1?(s=r[0]-e[t-1][0],n=r[1]-e[t-1][1]):(s=e[t+1][0]-e[t-1][0],n=e[t+1][1]-e[t-1][1]);const a=Math.sqrt(s*s+n*n)||1;i.push([r[0]+n/a*o,r[1]+-s/a*o])}return i}function fa(e,t,o,i,r){const s=t[0]-e[0],n=t[1]-e[1],a=Math.sqrt(s*s+n*n);if(0===a)return[e,t];const c=n/a,l=-s/a,u=r/2+1;return[[e[0]+c*u,e[1]+l*u],[t[0]+c*u,t[1]+l*u]]}import{scaleLinear as ya}from"d3-scale";var ba=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xa=["scene-style","data-paint","accessibility","evidence"],va=(e,t)=>({retainedData:e,invalidations:t}),Aa=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wa=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Sa=["scene-geometry","data-paint","accessibility","evidence"],ka=["scene-style","data-paint","accessibility","evidence"],_a=["overlay","accessibility","evidence"],Ma=[],Ra={xAccessor:va("rebuild",Aa),yAccessor:va("rebuild",Aa),lineDataAccessor:va("rebuild",Aa),pointIdAccessor:va("rebuild",Sa),lineIdAccessor:va("rebuild",Sa),windowSize:va("rebuild",Aa),projection:va("preserve",wa),projectionExtent:va("preserve",wa),fitPadding:va("preserve",wa),lineType:va("preserve",wa),flowStyle:va("preserve",wa),graticule:va("preserve",wa),projectionTransform:va("preserve",wa),customLayout:va("preserve",wa),layoutConfig:va("preserve",wa),layoutMargin:va("preserve",wa),areaStyle:va("preserve",ka),pointStyle:va("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:va("preserve",ka),colorScheme:va("preserve",ka),themeCategorical:va("preserve",ka),themeDiverging:va("preserve",ka),themeSemantic:va("preserve",ka),themeSequential:va("preserve",ka),decay:va("preserve",ka),pulse:va("preserve",ka),layoutSelection:va("preserve",ka),annotations:va("preserve",_a),autoPlaceAnnotations:va("preserve",_a),clock:va("preserve",Ma),transition:va("preserve",Ma),introAnimation:va("preserve",Ma),onLayoutError:va("preserve",Ma)},Pa=va("preserve",wa),La=class{constructor(){this.tracker=new lt}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},ba)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},xa):this.recordNoop("restyle")}recordConfig(e,t={}){const o=function(e){let t="preserve";const o=new Set;for(const i of e){const e=Ra[i]??Pa;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e),i=new Set(o.invalidations);return t.retainedDataChanged&&i.add("data"),this.tracker.record({kind:"config",keys:e},i)}};import{geoDistance as Ia,geoGraticule as Ta,geoInterpolate as Ca}from"d3-geo";function za(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&.5>e)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${e+""}.`)}var Oa=class e{constructor(e){this.updateResults=new La,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(e){return{...e,fitPadding:za(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??Le()}getConfiguredWindowSize(){const e=this.config.windowSize??500;if(!Number.isInteger(e)||1>e)throw Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){const t=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],i=t.slice(-e),r=o.slice(-i.length),s=this.currentTime();this.pointBuffer=new ee(e),this.timestampBuffer=new ee(e),i.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(r[t]??s)})}this.retainNewestLines(e)}updateConfig(e){const t=function(e){return"fitPadding"in e?{...e,fitPadding:za(e.fitPadding)}:e}(e),o=this.config,i=this.getConfiguredWindowSize(),r=Object.keys(t).filter(e=>t[e]!==o[e]);this.config={...this.config,...t};const s=this.getConfiguredWindowSize(),n=this.streaming&&s!==i;n&&(this.resizeStreamingWindow(s),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(r,{retainedDataChanged:n})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});const t=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,i=this.timestampBuffer?.toArray()??[],r=o.slice(-t),s=i.slice(-r.length),n=this.currentTime();this.pointBuffer=new ee(t),this.timestampBuffer=new ee(t),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(s[t]??n)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();V(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();for(const o of e)V(this.pointBuffer,o,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");const t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(const e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){const{lineIdAccessor:t}=this.config;if(!t)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],i=new Set(Array.isArray(e)?e:[e]),r=[];return this.lineData=this.lineData.filter(e=>!i.has(o(e)+"")||(r.push(e),!1)),r.length>0?(this.version++,this.updateResults.recordData("remove",r.length)):this.updateResults.recordNoop("remove"),r}getLines(){return this.lineData.slice()}removePoint(e){const{pointIdAccessor:t}=this.config;if(!t)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],i=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){const e=e=>i.has(o(e)+"");z(this.pointBuffer,this.timestampBuffer,e);const t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{const e=[];return this.pointData=this.pointData.filter(t=>!i.has(o(t)+"")||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){const t=this._customRestyle;if(t){for(const o of this.scene){const i=this._baseStyles.get(o)??o.style,r=t(o,e);o.style=r?{...i,...r}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){const{config:t}=this,o=this.projection,i=this.geoPath,r=this.scales,s=this.baseScale,n=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(e){if(!e)return ra();if("string"==typeof e){const t=la[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),ra())}if("object"==typeof e&&"type"in e){const t=la[e.type],o=t?t():ra();return e.rotate&&"rotate"in o&&o.rotate(e.rotate),e.center&&"center"in o&&o.center(e.center),o}return e}(t.projection),this.geoPath=ta(this.projection),this.fitProjection(e),this.geoPath=ta(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(e,t)=>l([e,t]),invertedPoint:(e,t)=>l.invert?l.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=i,this.scales=r,this.baseScale=s,this.baseTranslate=n,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){const t=e.width/2,o=e.height/2,i=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:o}));i.length>0&&this.startTransition(i)}this._hasRenderedOnce=!0,t.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(e){const t=this.projection,o=this.config,i=[...this.areas],r=ua(o.xAccessor,"lon"),s=ua(o.yAccessor,"lat"),n=this.getPoints();if(n.length>0){const e=n.map(e=>[r(e),s(e)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}const a=da(o.lineDataAccessor);for(const e of this.lineData){const t=a(e);if(t&&t.length>0){const e=t.map(e=>[r(e),s(e)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==i.length){if(o.projectionExtent){const[[i,r],[s,n]]=o.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,r],[i,n],[s,n],[s,r],[i,r]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){const i=o.fitPadding??0,r=Math.min(e.width,e.height);t.scale(r/2-r*i),t.translate([e.width/2,e.height/2])}else{const r=o.fitPadding??0,s=e.width*r,n=e.height*r;t.fitExtent([[s,n],[e.width-s,e.height-n]],{type:"FeatureCollection",features:i})}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){const o=this.projection;if(!o)return;const i=this.geoPath,r=this.scales,s=o.scale(),n=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e.k),o.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=ta(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(s),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){const o=this.projection;if(!o)return;const i=this.geoPath,r=this.scales,s=o.scale(),n=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e),o.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=ta(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(s),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){const o=this.projection;if(!o||!o.rotate)return;const i=this.geoPath,r=this.scales,s=[...o.rotate()];o.rotate(e),this.geoPath=ta(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const n=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(s),this.geoPath=i,this.scales=r):(this.scene=[],this.rebuildQuadtree()):(this.scene=n,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){const t=this.projection;t&&t.rotate&&t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let t=0,o=0;for(const e of this.scene)"point"===e.type&&(o++,e.r>t&&(t=e.r));if(this._maxPointRadius=t,e.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const i=Array(o);let r=0;for(const e of this.scene)"point"===e.type&&(i[r++]=e);this._quadtree=oa().x(e=>e.x).y(e=>e.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;const{config:t}=this,o=this.projection,i=this.geoPath;if(t.customLayout&&this.scales){const o=t.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Ee(t.colorScheme,t.themeCategorical,ne),r={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:o,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...i]},resolveColor:ue(i,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null};let s;try{s=t.customLayout(r)}catch(e){const o=null!==this.lastCustomLayoutResult,i=B("geo",e,o,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",e);try{t.onLayoutError?.(i)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const n=s.nodes??[];if(this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null,this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const e of n)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return Z({label:"geo customLayout",nodes:n,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),n}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:o,areas:i,points:r,lines:s,layout:n}){const a=ua(e.xAccessor,"lon"),c=ua(e.yAccessor,"lat"),l=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){const t=!0===e.graticule?{}:e.graticule,i=Ta();t.step&&i.step(t.step);const r=o(i())||"";r&&l.push({type:"geoarea",pathData:r,centroid:[n.width/2,n.height/2],bounds:[[0,0],[n.width,n.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth||.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const t of i){const i=o(t);if(!i)continue;const r=o.centroid(t),s=o.bounds(t),n=o.area(t);l.push({type:"geoarea",pathData:i,centroid:r,bounds:s,screenArea:n,style:ha(e.areaStyle,t,u),datum:t,interactive:!0})}const p=da(e.lineDataAccessor);for(const o of s){const i=p(o);if(!i||2>i.length)continue;let r=[];if("geo"===e.lineType){const e=Array(i.length);for(let t=0;i.length>t;t++)e[t]=[a(i[t]),c(i[t])];for(let o=0;e.length-1>o;o++){const i=e[o],s=e[o+1],n=Ia(i,s)||0,a=Math.max(2,Math.ceil(n/(Math.PI/180))),c=Ca(i,s);for(let e=0;a>=e;e++){if(o>0&&0===e)continue;const i=t(c(e/a));null!=i&&r.push(i)}}}else for(let e=0;i.length>e;e++){const o=i[e],s=t([a(o),c(o)]);null!=s&&r.push(s)}if(2>r.length)continue;const s=ha(e.lineStyle,o,d),u="number"==typeof s.strokeWidth?s.strokeWidth:1;2!==i.length||2>r.length||"arc"!==e.flowStyle?2!==i.length||2>r.length||"offset"!==e.flowStyle||(r="geo"===e.lineType?ga(r,u):fa(r[0],r[r.length-1],0,0,u)):r=ma(r[0],r[r.length-1]);const h=pa(r,n.width);if(h.length>1)for(const e of h)2>e.length||l.push({type:"line",path:e,style:{...s,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>r.length&&h[0]||r,style:s,datum:o})}const m=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,g=t.clipAngle?t.clipAngle()??0:0,f=g>0?g*Math.PI/180:null,y=t.rotate?t.rotate():[0,0,0],b="function"==typeof t.center?t.center():[0,0],x=[(b[0]??0)-y[0],(b[1]??0)-y[1]];for(const o of r){const i=a(o),r=c(o);if(null!=f&&Ia([i,r],x)>f)continue;const s=t([i,r]);if(!s)continue;const n=e.pointStyle?e.pointStyle(o):{...h},u={type:"point",x:s[0],y:s[1],r:n.r||4,style:n,datum:o,pointId:m?m(o)+"":void 0};l.push(u)}return l}({config:t,projection:o,path:i,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){const o=function(e,t,o,i){const r=e.filter(e=>"point"===e.type);if(2>r.length)return null;const s=t.strength??1,n=Number.isFinite(s)?Math.max(0,Math.min(1,s)):1,a="strip"===t.layout?"strip":"radial";if("radial"===a&&0===n)return null;const c=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,l="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=r.find(e=>e.datum&&c(e.datum)+""==t.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;const d=r.map(e=>e.datum?Number(l(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),h=At(d,1);i>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){const o=e[t];"geoarea"===o.type&&o.interactive&&e.splice(t,1)}const p="strip"===a?function(e,t,o,i,r){const s=Math.max(3,Math.min(8,.35*r.height)),n=Math.max(1,r.width-2*s),a=r.height/2,c=ya().domain([0,i]).range([0,n]);t.x=s,t.y=a;const l=[];for(const r of e){if(r===t)continue;if(!r.datum){r.x=s,r.y=a;continue}const e=Number(o(r.datum)),n=s+(isFinite(e)&&e>=0&&i>0?c(e):0);r.x=n,r.y=a,l.push({node:r,x:n})}l.sort((e,t)=>e.x-t.x);const u=Math.max(0,Math.min(r.height/2-1,6));let d=0;for(;l.length>d;){let e=d+1;for(;l.length>e&&3>Math.abs(l[e].x-l[d].x);)e++;const t=e-d;if(t>1&&u>0)for(let e=0;t>e;e++)l[d+e].node.y=a+(e-(t-1)/2)*Math.min(2.5,2*u/Math.max(1,t-1));d=e}return{cx:s,cy:a,maxCost:i,availableRadius:n,layout:"strip"}}(r,u,l,h,o):function(e,t,o,i,r,s){const n=t.x,a=t.y,c=s.width/2,l=s.height/2,u=Math.min(s.width,s.height)/2,d=ya().domain([0,i]).range([0,u]);for(const s of e){if(s===t)continue;if(!s.datum)continue;const e=s.x,u=s.y,h=Math.atan2(u-a,e-n),p=Math.hypot(e-n,u-a),m=Number(o(s.datum)),g=isFinite(m)&&m>=0?i>0?d(m):0:p,f=c+Math.cos(h)*g,y=l+Math.sin(h)*g;s.x=e+(f-e)*r,s.y=u+(y-u)*r}return t.x=n+(c-n)*r,t.y=a+(l-a)*r,{cx:t.x,cy:t.y,maxCost:i,availableRadius:u,layout:"radial"}}(r,u,l,h,n,o),m=e.filter(e=>"line"===e.type);if(m.length>0){const e=new Map;for(const t of r)null!=t.pointId&&e.set(t.pointId+"",[t.x,t.y]);for(const o of m){const i=o.datum?.source,r=o.datum?.target;if(null!=i&&null!=r){const s=e.get(i+""),n=e.get(r+"");if(s&&n)if("fractional"===t.lineMode&&o.path.length>2){const e=o.path[0],t=o.path[o.path.length-1],i=[s[0]-e[0],s[1]-e[1]],r=[n[0]-t[0],n[1]-t[1]],a=[0];for(let e=1;o.path.length>e;e++)a.push(a[e-1]+Math.hypot(o.path[e][0]-o.path[e-1][0],o.path[e][1]-o.path[e-1][1]));const c=a[a.length-1];o.path=o.path.map((e,t)=>{const s=c>0?a[t]/c:t/(o.path.length-1);return[e[0]+i[0]*(1-s)+r[0]*s,e[1]+i[1]*(1-s)+r[1]*s]})}else o.path=[s,n]}}}return p}(this.scene,e,t,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const e=this.config.decay;if(!e||!this.pointBuffer)return;const t=this.pointBuffer.size;if(0===t)return;const o=this.scene.filter(e=>"point"===e.type);for(let i=0;o.length>i;i++){const r=O(e,i,t);o[i]._decayOpacity=r,o[i].style={...o[i].style,opacity:r}}}applyPulse(e=this.currentTime()){const t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;const o=this.scene.filter(e=>"point"===e.type),i=this.timestampBuffer.toArray(),r=t.color||"rgba(255,255,255,0.6)",s=t.glowRadius??4;let n=!1;for(let a=0;o.length>a&&i.length>a;a++){const c=F(t,i[a],e);n=U(o[a],c,r,s)||n}return n}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&N(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){const t=this.config.transition?.duration??300;if(0>=t)return;const o=new Map;for(const t of e)"point"===t.type&&t.pointId&&o.set(t.pointId,[t.x,t.y]);const i=this.scene.filter(e=>"point"===e.type);let r=!1;for(const e of i)if(e.pointId){const t=o.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(r=!0))}for(const e of i)e.pointId&&!o.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??1,e.style={...e.style,opacity:0},r=!0);r&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(e){if(!this.activeTransition)return!1;const t=pe(e,this.activeTransition),o=he(t),i=this.scene.filter(e=>"point"===e.type);for(const e of i){if(null!=e._targetX&&null!=e._targetY){const t=e.y;e.x=_e(e.x,e._targetX,o),e.y=_e(t,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(t>=1){for(const e of i)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Oa.QUADTREE_THRESHOLD=500;var Fa=Oa;R(Fa);import{Fragment as Ba,jsxs as Ea}from"react/jsx-runtime";function ja(e,t){const o=Et(e.theme),i=e.size||[e.width||600,e.height||400],r=Oe({top:10,right:10,bottom:10,left:10,...e.margin},e.title),s=ve(e.title),n=Array.isArray(e.areas)?ge(e.areas):e.areas,a=ge(e.points),c=ge(e.lines),l=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;return Vs(a.length>0?a:Array.isArray(n)&&n.length>0?"string"==typeof t?n.map(e=>({...e.properties||{},...e})):n:[],t)})():[];ln(r,{props:e,categories:l,theme:o,size:i,hasTitle:s});const u=i[0]-(r.left??0)-(r.right??0),d=i[1]-(r.top??0)-(r.bottom??0),h={projection:e.projection||"equalEarth",xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineType:e.lineType,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,themeCategorical:o.colors.categorical,themeSemantic:Lt(o)},p=new Fa(h);if(n){if("string"==typeof n)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${n}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${n}')\` before calling renderGeoToStaticSVG.`);p.setAreas(n)}e.points&&p.setPoints(a),e.lines&&p.setLines(c),p.computeScene({width:u,height:d});const m=H({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>fe(e,t)});if(t&&(t.evidence=Ls({frameType:"geo",width:i[0],height:i[1],marks:m.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,legendItems:l.length>0?l.length:void 0,margin:r})),0===m.length){const t=e.backgroundGraphics||e.foregroundGraphics||e.annotations||p.customLayoutOverlays?Ea(Ba,{children:[e.backgroundGraphics,e.annotations?Zs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([e,t])=>p.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:o,idPrefix:e._idPrefix}):null,e.foregroundGraphics,p.customLayoutOverlays]}):null;return ea.renderToStaticMarkup(hn(t,{width:i[0],height:i[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left??0},${r.top??0})`,innerWidth:u,innerHeight:d,idPrefix:e._idPrefix}))}const g=m.map(e=>e.element),f=e.annotations?Zs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([e,t])=>p.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:o,idPrefix:e._idPrefix}):null,y=un({props:e,categories:l,theme:o,size:i,margin:r,hasTitle:s});return ea.renderToStaticMarkup(hn(Ea(Ba,{children:[e.backgroundGraphics,g,f,e.foregroundGraphics,p.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${r.left??0},${r.top??0})`,innerWidth:u,innerHeight:d,legend:y,idPrefix:e._idPrefix}))}function Da(e,t){const o=e.size??[e.width??600,e.height??400],i=new k(e.config);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&i.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));const r=m(i,{...e,width:o[0],height:o[1],idPrefix:e.idPrefix??e._idPrefix??"physics"});return t&&(t.evidence=Ls({frameType:"physics",width:o[0],height:o[1],marks:r.scene.sceneNodes,title:e.title,description:e.description,annotations:[],extraWarnings:0===r.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[]})),r.svg}import{Fragment as Na,jsx as $a,jsxs as Wa}from"react/jsx-runtime";function Ga(e,t){switch(e){case"xy":return fn(t);case"ordinal":return Xn(t);case"network":return Jn(t);case"geo":return ja(t);case"physics":return Da(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Va(e){return fn(e)}function Ha(e){return Xn(e)}function Ya(e){return Jn(e)}function Xa(e){return ja(e)}var qa=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],Ua=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Qa(e,t){const o={};for(const i of t)void 0!==e[i]&&(o[i]=e[i]);return o}function Ka(e,t,o){return Ja(e,t).svg}function Za(e,t,o){const i={},{svg:r,frameType:s}=Ja(e,t,0,i),n=i.evidence??Ls({frameType:s,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});return n.component=e,{svg:r,evidence:n}}function Ja(e,t,o,i){const r=Ms[e];if(!r)throw Error(`Unknown chart component: "${e}". See CLAUDE.md for supported chart types.`);const s=r.layout?.mode??(Ae(t.mode)?t.mode:void 0),n=Be(s,{...r.layout?.modeDefaults,...Qa(t,Ua)},r.layout?.primarySize),{data:a,theme:c,background:l,className:u,annotations:d,margin:h,colorScheme:p,colorBy:m,legendPosition:g,...f}=t,{width:y,height:b}=n,x=[y,b],v=f.frameProps||{},A=r.layout?.margin,w="function"==typeof A?A(t,n):A??n.marginDefaults,S=void 0!==h?h:v.margin,k=Tt(S),_="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...w,...k},M=Qa(f,qa),R=e=>v[e]??n[e],P={...v,...M,theme:c,title:n.title,description:n.description,showAxes:R("showAxes"),showLegend:R("showLegend"),showLabels:R("showLabels"),showGrid:R("showGrid"),xLabel:R("xLabel"),yLabel:R("yLabel"),categoryLabel:R("categoryLabel"),valueLabel:R("valueLabel"),background:l,className:u,annotations:d,size:x,margin:_,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==g&&{legendPosition:g},_idPrefix:f._idPrefix},L=r.buildProps(a,m,p,P,f);let I;switch(r.frameType){case"xy":I=fn(L,i);break;case"ordinal":I=Xn(L,i);break;case"network":I=Jn(L,i);break;case"geo":I=ja(L,i);break;case"physics":I=Da(L,i)}const T=r.renderOverlay?.(L,{theme:Et(c)});if(null!=T){const e=Ct.renderToStaticMarkup($a(Na,{children:T}));I=I.replace("</svg>",e+"</svg>")}return{svg:I,frameType:r.frameType}}function ec(e,t={}){const{title:o,subtitle:i,theme:r,width:s=1200,height:n,layout:a={},background:c}=t,l=jt(Et(r)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),i&&(h+=20),h>0&&(h+=10);const p=Math.floor((s-d-d*(u-1))/u),m=[];let g=0,f=h+d,y=0;for(const t of e){const e=Math.min(t.colSpan||1,u),o=t.props.height||300;g+e>u&&(f+=y+d,g=0,y=0),m.push({chart:t,x:d/2+g*(p+d),y:f,w:p*e+d*(e-1),h:o}),y=Math.max(y,o),g+=e}const b=n||f+y+d,x=m.map((e,t)=>{const{chart:o,x:i,y:s,w:n,h:a}=e,c={...o.props,width:n,height:a,theme:r,_idPrefix:"chart-"+t};let l;return l=o.component?Ka(o.component,c):o.frameType?Ga(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${a}"></svg>`,$a("g",{transform:`translate(${i},${s})`,children:$a("foreignObject",{width:n,height:a,children:$a("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+t)});return Ct.renderToStaticMarkup(Wa("svg",{xmlns:"http://www.w3.org/2000/svg",width:s,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&$a("title",{children:o}),c&&$a("rect",{x:0,y:0,width:s,height:b,fill:c}),o&&$a("text",{x:s/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:o}),i&&$a("text",{x:s/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),x]}))}import*as tc from"react-dom/server";import{Fragment as oc,jsx as ic,jsxs as rc}from"react/jsx-runtime";function sc(e,t,o,i={}){const{stepSize:r,windowSize:s,frameCount:n,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:d="ease-out",decay:h}=i,p=o.width||600,m=o.height||400,g=Et(o.theme),f={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!t||0===t.length)return[];const y=r||Math.max(1,Math.ceil(t.length/(n||Math.min(60,Math.max(10,t.length))))),b=[];for(let e=y;t.length>=e;e+=y)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);const x=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),v=Oe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),A=p-v.left-v.right,w=m-v.top-v.bottom,S=[];if(x)for(let i=0;b.length>i;i++){const r=b[i],n=t.slice(s?Math.max(0,r-s):0,r),a={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||g.colors.categorical,...h&&{decay:h}},c=new $n(a);c.ingest({inserts:n,bounded:!0}),c.computeScene({width:A,height:w}),c.scene.length>0&&S.push(dc(c.scene,p,m,g,f))}else for(let i=0;b.length>i;i++){const r=b[i],n=t.slice(s?Math.max(0,r-s):0,r),y={chartType:e,windowSize:n.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:o.colorScheme||g.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...l>0&&{transition:{duration:l*(1e3/u),easing:d}}},x=new _(y);if(x.ingest({inserts:n,bounded:!0}),x.computeScene({width:A,height:w}),0===x.scene.length)continue;const v=x.scales?{y:x.scales.y}:void 0;if(S.push(uc(x.scene,p,m,g,f,v)),l>0&&i>0&&x.activeTransition){const e=l*(1e3/u);for(let t=1;l>=t;t++)x.advanceTransition(x.activeTransition.startTime+t/l*e),S.push(uc(x.scene,p,m,g,f,v))}}return S}function nc(e,t,o={}){return t.map(t=>{try{return Ka(e,{...o,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||t.width||600}" height="${o.height||t.height||400}"></svg>`}})}function ac(e,t,o){const i=t.size??[t.width??600,t.height??400],r=Et(t.theme),s=jt(r),n=t.background||r.colors.background,a=t.idPrefix??"physics-gif",c=t.title?`${a}-title-${o}`:void 0,l=t.description?`${a}-desc-${o}`:void 0,u=[c,l].filter(Boolean).join(" ")||void 0,d=p(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),h=rc("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:s.fontFamily},children:[t.title&&ic("title",{id:c,children:t.title}),t.description&&ic("desc",{id:l,children:t.description}),n&&"transparent"!==n?ic("rect",{x:0,y:0,width:i[0],height:i[1],fill:n}):null,ic("g",{id:`${a}-frame-${o}`,children:d.map((e,t)=>Je(e,t,`${a}-${o}`))})]});return tc.renderToStaticMarkup(h)}function cc(e,t={}){const{fps:o=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:n,stepsPerFrame:a,background:c}=t,l=Math.max(.001,n??e.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=i??Math.max(1,Math.ceil(r*Math.max(1,o))),h=c?{...e,background:c}:e,p=new k(e.config);e.initialSpawns?.length&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);const m=[];for(s&&(p.tick(0),m.push(ac(p,h,0)));d>m.length;){for(let e=0;u>e;e+=1)p.tick(l);m.push(ac(p,h,m.length))}return m}function lc(e,t){const o=e.background||t.colors.background;return o&&"transparent"!==o?o:null}function uc(e,t,o,i,r,s){const n=jt(i),a=Oe({top:20,right:20,bottom:30,left:40,...r.margin},r.title),c=t-a.left-a.right,l=o-a.top-a.bottom,u=lc(r,i),d=r.renderMode,h=e.map((e,t)=>Y({node:e,index:t,renderMode:d,fallback:()=>Je(e,t)})).filter(Boolean),p=function(e,t,o,i,r,s){if(!e||0===e.length)return null;const n=jt(i),a=[];for(let i=0;e.length>i;i++){const c=e[i];if("y-threshold"===c.type&&null!=c.value){let e=null;if(s)e=s(c.value);else if(r){const[t,i]=r,s=i-t;if(0===s)continue;e=o-(c.value-t)/s*o}if(null==e)continue;const l=c.color||n.primary,u=c.labelPosition||"right";a.push(rc("g",{children:[ic("line",{x1:0,y1:e,x2:t,y2:e,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&ic("text",{x:"left"===u?4:"center"===u?t/2:t-4,y:20>e?Math.min(o-4,e+16):e-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:n.tickSize,fill:l,fontFamily:n.fontFamily,children:c.label})]},"ann-"+i))}}return a.length>0?ic(oc,{children:a}):null}(r.annotations,c,l,i,r.yExtent,s?.y),m="string"==typeof r.title?r.title:void 0,g="string"==typeof r.description?r.description:void 0,f=m?"semiotic-title":void 0,y=g?"semiotic-desc":void 0,b=[f,y].filter(Boolean).join(" ")||void 0;return tc.renderToStaticMarkup(rc("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":b,style:{fontFamily:n.fontFamily},children:[m&&ic("title",{id:f,children:m}),g&&ic("desc",{id:y,children:g}),u&&ic("rect",{x:0,y:0,width:t,height:o,fill:u}),rc("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),m&&ic("text",{x:t/2,y:le,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:m})]}))}function dc(e,t,o,i,r){const s=jt(i),n=Oe({top:20,right:20,bottom:30,left:40,...r.margin},r.title),a="radial"===r.projection,c=a?n.left+(t-n.left-n.right)/2:n.left,l=a?n.top+(o-n.top-n.bottom)/2:n.top,u=lc(r,i),d=r.renderMode,h=e.map((e,t)=>Y({node:e,index:t,renderMode:d,fallback:()=>Ie(e,t)})).filter(Boolean),p="string"==typeof r.title?r.title:void 0,m="string"==typeof r.description?r.description:void 0,g=p?"semiotic-title":void 0,f=m?"semiotic-desc":void 0,y=[g,f].filter(Boolean).join(" ")||void 0;return tc.renderToStaticMarkup(rc("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":y,style:{fontFamily:s.fontFamily},children:[p&&ic("title",{id:g,children:p}),m&&ic("desc",{id:f,children:m}),u&&ic("rect",{x:0,y:0,width:t,height:o,fill:u}),ic("g",{transform:`translate(${c},${l})`,children:h}),p&&ic("text",{x:t/2,y:le,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}export{sc as generateFrameSVGs,nc as generateFrameSequence,cc as generatePhysicsFrameSVGs,Ka as renderChart,Za as renderChartWithEvidence,ec as renderDashboard,Xa as renderGeoToStaticSVG,Ya as renderNetworkToStaticSVG,Ha as renderOrdinalToStaticSVG,Ga as renderToStaticSVG,Va as renderXYToStaticSVG,Et as resolveTheme,jt as themeStyles};