semiotic 3.8.3 → 3.8.5

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 (215) hide show
  1. package/CLAUDE.md +13 -10
  2. package/README.md +52 -45
  3. package/ai/componentMetadata.cjs +1 -1
  4. package/ai/dist/mcp-server.js +4 -2
  5. package/ai/examples.md +168 -1
  6. package/ai/schema.json +3756 -327
  7. package/ai/surface-manifest.json +6 -4
  8. package/ai/system-prompt.md +1 -1
  9. package/dist/chunk-chartContainerDataAudit-74TLKIP6.module.min.js +2 -0
  10. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +0 -1
  11. package/dist/chunk-chunk-4AANPFOX.module.min.js +2 -0
  12. package/dist/{chunk-chunk-JNCHKRIR.module.min.js → chunk-chunk-5I3UZV4Q.module.min.js} +1 -1
  13. package/dist/chunk-chunk-74CCPVXB.module.min.js +1 -0
  14. package/dist/{chunk-chunk-VVCA3DB7.module.min.js → chunk-chunk-7ALTGHK6.module.min.js} +1 -1
  15. package/dist/chunk-chunk-ACLDBMRH.module.min.js +2 -0
  16. package/dist/chunk-chunk-AVBI6GDT.module.min.js +1 -0
  17. package/dist/{chunk-chunk-XQYVEKEJ.module.min.js → chunk-chunk-BANTPINB.module.min.js} +1 -1
  18. package/dist/chunk-chunk-C4YA6TDR.module.min.js +1 -0
  19. package/dist/chunk-chunk-C57LR3YG.module.min.js +1 -0
  20. package/dist/chunk-chunk-CKMD5NV3.module.min.js +2 -0
  21. package/dist/chunk-chunk-CO5KQMGH.module.min.js +1 -0
  22. package/dist/chunk-chunk-CWQ5YIHX.module.min.js +2 -0
  23. package/dist/chunk-chunk-E6TXX6MI.module.min.js +1 -0
  24. package/dist/{chunk-chunk-7FW6EGLP.module.min.js → chunk-chunk-I36PJ4OC.module.min.js} +1 -1
  25. package/dist/chunk-chunk-IY7RYD4S.module.min.js +1 -0
  26. package/dist/chunk-chunk-K3DMEW22.module.min.js +1 -0
  27. package/dist/chunk-chunk-KT2VAZMZ.module.min.js +1 -0
  28. package/dist/{chunk-chunk-AZJUDQRM.module.min.js → chunk-chunk-L6EA5V3G.module.min.js} +1 -1
  29. package/dist/{chunk-chunk-SANERMIZ.module.min.js → chunk-chunk-LJLS6DY7.module.min.js} +1 -1
  30. package/dist/chunk-chunk-LJPCLYSC.module.min.js +2 -0
  31. package/dist/chunk-chunk-LRIFN2HK.module.min.js +1 -0
  32. package/dist/chunk-chunk-N5DDKCCF.module.min.js +1 -0
  33. package/dist/chunk-chunk-NEVE562N.module.min.js +1 -0
  34. package/dist/chunk-chunk-NLO44TOS.module.min.js +2 -0
  35. package/dist/{chunk-chunk-FYY2ACNJ.module.min.js → chunk-chunk-PRDGLMJT.module.min.js} +1 -1
  36. package/dist/chunk-chunk-PZJ2SBLL.module.min.js +2 -0
  37. package/dist/chunk-chunk-QUJ6TTLY.module.min.js +1 -0
  38. package/dist/chunk-chunk-RBIDBUT4.module.min.js +2 -0
  39. package/dist/chunk-chunk-RFLAG356.module.min.js +1 -0
  40. package/dist/chunk-chunk-RPU4IZAV.module.min.js +2 -0
  41. package/dist/chunk-chunk-SKMBCFIL.module.min.js +2 -0
  42. package/dist/chunk-chunk-TAE7W424.module.min.js +2 -0
  43. package/dist/{chunk-chunk-OQTLSTGI.module.min.js → chunk-chunk-TMWIZL3K.module.min.js} +1 -1
  44. package/dist/chunk-chunk-TUBMTZMU.module.min.js +2 -0
  45. package/dist/chunk-chunk-UFFEXJQY.module.min.js +1 -0
  46. package/dist/chunk-chunk-XSCHTS4D.module.min.js +2 -0
  47. package/dist/chunk-chunk-XXWSHGPL.module.min.js +2 -0
  48. package/dist/chunk-chunk-ZOAQDIJO.module.min.js +1 -0
  49. package/dist/chunk-chunk-ZXIXAPRE.module.min.js +2 -0
  50. package/dist/chunk-minimapBrushOverlay-JU57U7NM.module.min.js +2 -0
  51. package/dist/chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js +2 -0
  52. package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +1 -0
  53. package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +1 -0
  54. package/dist/components/ChartContainer.d.ts +12 -2
  55. package/dist/components/ai/chartCapabilities.d.ts +2 -1
  56. package/dist/components/ai/chartCapabilityTypes.d.ts +19 -0
  57. package/dist/components/chartContainerDataAudit.d.ts +10 -0
  58. package/dist/components/charts/geo/ChoroplethMap.d.ts +2 -0
  59. package/dist/components/charts/geo/DistanceCartogram.d.ts +35 -5
  60. package/dist/components/charts/geo/FlowMap.d.ts +4 -0
  61. package/dist/components/charts/geo/ProportionalSymbolMap.d.ts +3 -1
  62. package/dist/components/charts/index.d.ts +1 -0
  63. package/dist/components/charts/network/ForceDirectedGraph.d.ts +36 -1
  64. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +6 -1
  65. package/dist/components/charts/physics/CrucibleChart.capability.d.ts +8 -0
  66. package/dist/components/charts/physics/CrucibleChart.d.ts +63 -0
  67. package/dist/components/charts/physics/GaltonBoardChart.d.ts +6 -1
  68. package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +27 -0
  69. package/dist/components/charts/physics/crucibleChartProps.d.ts +90 -0
  70. package/dist/components/charts/physics/crucibleChrome.d.ts +47 -0
  71. package/dist/components/charts/physics/crucibleController.d.ts +59 -0
  72. package/dist/components/charts/physics/crucibleEffects.d.ts +30 -0
  73. package/dist/components/charts/physics/cruciblePhysics.d.ts +54 -0
  74. package/dist/components/charts/physics/crucibleProgram.d.ts +38 -0
  75. package/dist/components/charts/physics/crucibleTypes.d.ts +415 -0
  76. package/dist/components/charts/physics/gauntletChartProps.d.ts +7 -1
  77. package/dist/components/charts/physics/gauntletChrome.d.ts +2 -1
  78. package/dist/components/charts/physics/gauntletPhysics.d.ts +19 -4
  79. package/dist/components/charts/physics/gauntletRuntime.d.ts +3 -0
  80. package/dist/components/charts/physics/physicsHocUtils.d.ts +12 -0
  81. package/dist/components/charts/shared/chartMode.d.ts +8 -0
  82. package/dist/components/charts/shared/chartSpecCore.d.ts +10 -2
  83. package/dist/components/charts/shared/crucibleWireSchema.d.ts +5 -0
  84. package/dist/components/charts/shared/diagnoseTypes.d.ts +10 -0
  85. package/dist/components/charts/shared/hatchPattern.d.ts +8 -3
  86. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  87. package/dist/components/charts/shared/lineSeriesSsr.d.ts +55 -0
  88. package/dist/components/charts/shared/types.d.ts +2 -2
  89. package/dist/components/charts/shared/validateProps.d.ts +1 -1
  90. package/dist/components/charts/xy/AreaChart.d.ts +10 -0
  91. package/dist/components/charts/xy/minimapBrushOverlay.d.ts +17 -0
  92. package/dist/components/charts/xy/minimapBrushOverlayLazy.d.ts +4 -0
  93. package/dist/components/charts/xy/scatterplotMatrixBrushOverlay.d.ts +8 -0
  94. package/dist/components/charts/xy/scatterplotMatrixBrushOverlayLazy.d.ts +3 -0
  95. package/dist/components/data/auditData.d.ts +51 -0
  96. package/dist/components/data/dataAuditPresentation.d.ts +18 -0
  97. package/dist/components/data/dataAuditSources.d.ts +9 -0
  98. package/dist/components/data/numericContracts.d.ts +59 -0
  99. package/dist/components/data/numericFieldProfiler.d.ts +23 -0
  100. package/dist/components/realtime/types.d.ts +5 -0
  101. package/dist/components/recipes/gridObservatory.d.ts +176 -0
  102. package/dist/components/recipes/netEnsembleLayout.d.ts +167 -0
  103. package/dist/components/recipes/netEnsembleOverlays.d.ts +20 -0
  104. package/dist/components/recipes/recipeChrome.d.ts +24 -0
  105. package/dist/components/recipes/sequenceLayout.d.ts +139 -0
  106. package/dist/components/recipes/wordTrails.d.ts +156 -0
  107. package/dist/components/recipes/wordTrailsProgressiveReveal.d.ts +42 -0
  108. package/dist/components/semiotic-ai-core.d.ts +3 -0
  109. package/dist/components/semiotic-ai-data-audit.d.ts +4 -0
  110. package/dist/components/semiotic-ai.d.ts +7 -5
  111. package/dist/components/semiotic-physics.d.ts +1 -0
  112. package/dist/components/semiotic-recipes-core.d.ts +10 -2
  113. package/dist/components/semiotic-utils-core.d.ts +3 -0
  114. package/dist/components/semiotic.d.ts +1 -1
  115. package/dist/components/server/renderEvidence.d.ts +27 -0
  116. package/dist/components/server/serverChartConfigs.d.ts +1 -0
  117. package/dist/components/server/serverChartConfigsPhysics.d.ts +9 -0
  118. package/dist/components/server/staticAnnotations.d.ts +15 -1
  119. package/dist/components/stream/GeoPipelineStore.d.ts +1 -0
  120. package/dist/components/stream/GeoSVGOverlay.d.ts +7 -0
  121. package/dist/components/stream/SceneToSVG.d.ts +6 -6
  122. package/dist/components/stream/SceneToSVGOrdinal.d.ts +12 -0
  123. package/dist/components/stream/geoCartogram.d.ts +7 -0
  124. package/dist/components/stream/geoTypes.d.ts +17 -2
  125. package/dist/components/stream/networkFrameHandleTypes.d.ts +4 -0
  126. package/dist/components/stream/networkFramePaint.d.ts +2 -0
  127. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +18 -2
  128. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +8 -0
  129. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +7 -0
  130. package/dist/components/stream/physics/physicsPipelineEviction.d.ts +15 -0
  131. package/dist/components/stream/physics/physicsPipelineObservations.d.ts +1 -1
  132. package/dist/components/stream/physics/physicsPipelineQuiescence.d.ts +20 -0
  133. package/dist/components/stream/sceneToSVGShared.d.ts +30 -1
  134. package/dist/components/stream/types.d.ts +4 -0
  135. package/dist/components/stream/useHydration.d.ts +7 -1
  136. package/dist/components/stream/xySceneBuilders/candlestickScene.d.ts +1 -1
  137. package/dist/components/useChartContainerDataAudit.d.ts +7 -0
  138. package/dist/forceLayoutWorker.js +1 -1
  139. package/dist/geo.min.js +1 -1
  140. package/dist/geo.module.min.js +1 -1
  141. package/dist/network.min.js +1 -1
  142. package/dist/network.module.min.js +1 -1
  143. package/dist/ordinal.min.js +1 -1
  144. package/dist/ordinal.module.min.js +1 -1
  145. package/dist/physics.min.js +1 -1
  146. package/dist/physics.module.min.js +1 -1
  147. package/dist/physicsWorker.js +1 -1
  148. package/dist/realtime.min.js +1 -1
  149. package/dist/realtime.module.min.js +1 -1
  150. package/dist/rough.min.js +1 -1
  151. package/dist/rough.module.min.js +1 -1
  152. package/dist/semiotic-ai-core.d.ts +3 -0
  153. package/dist/semiotic-ai-core.min.js +1 -1
  154. package/dist/semiotic-ai-core.module.min.js +1 -1
  155. package/dist/semiotic-ai.d.ts +7 -5
  156. package/dist/semiotic-ai.min.js +1 -1
  157. package/dist/semiotic-ai.module.min.js +1 -1
  158. package/dist/semiotic-experimental.min.js +1 -1
  159. package/dist/semiotic-experimental.module.min.js +1 -1
  160. package/dist/semiotic-physics.d.ts +1 -0
  161. package/dist/semiotic-realtime-core.min.js +1 -1
  162. package/dist/semiotic-realtime-core.module.min.js +1 -1
  163. package/dist/semiotic-recipes-core.d.ts +10 -2
  164. package/dist/semiotic-recipes-core.min.js +1 -1
  165. package/dist/semiotic-recipes-core.module.min.js +1 -1
  166. package/dist/semiotic-recipes.min.js +1 -1
  167. package/dist/semiotic-recipes.module.min.js +1 -1
  168. package/dist/semiotic-server-edge.min.js +1 -1
  169. package/dist/semiotic-server-edge.module.min.js +1 -1
  170. package/dist/semiotic-server-node.min.js +1 -1
  171. package/dist/semiotic-server-node.module.min.js +1 -1
  172. package/dist/semiotic-utils-core.d.ts +3 -0
  173. package/dist/semiotic-utils-core.min.js +1 -1
  174. package/dist/semiotic-utils-core.module.min.js +1 -1
  175. package/dist/semiotic-utils.min.js +1 -1
  176. package/dist/semiotic-utils.module.min.js +1 -1
  177. package/dist/semiotic-value.module.min.js +1 -1
  178. package/dist/semiotic.d.ts +1 -1
  179. package/dist/semiotic.min.js +1 -1
  180. package/dist/semiotic.module.min.js +1 -1
  181. package/dist/server.min.js +1 -1
  182. package/dist/server.module.min.js +1 -1
  183. package/dist/xy.min.js +1 -1
  184. package/dist/xy.module.min.js +1 -1
  185. package/package.json +4 -3
  186. package/dist/chunk-chunk-255KDHW5.module.min.js +0 -1
  187. package/dist/chunk-chunk-2CCFBTQC.module.min.js +0 -2
  188. package/dist/chunk-chunk-2RXP3FS3.module.min.js +0 -1
  189. package/dist/chunk-chunk-2WVCH4PL.module.min.js +0 -1
  190. package/dist/chunk-chunk-4TMZXLCR.module.min.js +0 -1
  191. package/dist/chunk-chunk-5APBQXZA.module.min.js +0 -1
  192. package/dist/chunk-chunk-6HSGDMTA.module.min.js +0 -2
  193. package/dist/chunk-chunk-7OEOSCBP.module.min.js +0 -1
  194. package/dist/chunk-chunk-A63CTACR.module.min.js +0 -2
  195. package/dist/chunk-chunk-B6V35LMY.module.min.js +0 -2
  196. package/dist/chunk-chunk-BOSVL645.module.min.js +0 -2
  197. package/dist/chunk-chunk-CP3EN6KZ.module.min.js +0 -1
  198. package/dist/chunk-chunk-F25UA5HT.module.min.js +0 -1
  199. package/dist/chunk-chunk-FRIO6MCV.module.min.js +0 -1
  200. package/dist/chunk-chunk-GWSWSPXN.module.min.js +0 -1
  201. package/dist/chunk-chunk-I6C3KR5H.module.min.js +0 -2
  202. package/dist/chunk-chunk-IP2UE74X.module.min.js +0 -1
  203. package/dist/chunk-chunk-J3ELI22J.module.min.js +0 -1
  204. package/dist/chunk-chunk-J5RL6GXU.module.min.js +0 -2
  205. package/dist/chunk-chunk-L3H6DQCR.module.min.js +0 -2
  206. package/dist/chunk-chunk-M337NY6L.module.min.js +0 -1
  207. package/dist/chunk-chunk-M7VYYHCE.module.min.js +0 -2
  208. package/dist/chunk-chunk-MC35ILYP.module.min.js +0 -2
  209. package/dist/chunk-chunk-N72SWNBV.module.min.js +0 -1
  210. package/dist/chunk-chunk-OBQRFTIL.module.min.js +0 -2
  211. package/dist/chunk-chunk-QRIBHZYW.module.min.js +0 -1
  212. package/dist/chunk-chunk-SA3D43RA.module.min.js +0 -2
  213. package/dist/chunk-chunk-UHSZEB74.module.min.js +0 -1
  214. package/dist/chunk-chunk-Y6AXCRVO.module.min.js +0 -1
  215. package/dist/chunk-chunk-ZCNBUZPL.module.min.js +0 -2
@@ -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 s,buildPhysicalFlowPhysics as r,buildPhysicsPile as n,buildProcessFlowPhysics as a,generateGaltonMechanicalSamples as c,generatePhysicsPileMechanicalSamples as l,physicsBodiesToXYSceneNodes as h,renderPhysicsSettledSVG as d,resolveCustomLayout as u,styleFromColorAccessor as g}from"./chunk-chunk-N72SWNBV.module.min.js";import{composeStyleRules as p,makeNodeRuleContext as f,makeRuleValueResolver as y,makeXYRuleContext as m,resolveStyleRules as x,styleRulesToNodeStyle as b,styleRulesToXYStyle as v}from"./chunk-chunk-IP2UE74X.module.min.js";import{PhysicsPipelineStore as A}from"./chunk-chunk-UHSZEB74.module.min.js";import"./chunk-chunk-SIRIJ3DY.module.min.js";import{PipelineStore as w,attachUpdateResultStore as S,buildDatumIndexMap as k,buildRectNode as _,buildRibbonGeometry as M,compactTimestampBufferForRemoval as P,computeDecayOpacity as T,computePulseIntensity as R,createCustomLayoutFailureDiagnostic as L,createTimestampBufferForData as z,ensureRingBufferCapacity as C,getLayoutPlugin as F,hasActivePulses as B,pushWithTimestamp as O,renderSceneListWithBackend as E,renderSceneWithBackend as j,resolveDownwardHistogramExtent as D,setPulseState as N,ticksForMode as W,toIdSet as $,warnCustomLayoutDiagnostics as I}from"./chunk-chunk-GWSWSPXN.module.min.js";import{IncrementalExtent as G,RingBuffer as Y}from"./chunk-chunk-VVCA3DB7.module.min.js";import"./chunk-chunk-5APBQXZA.module.min.js";import{AnnotationLabel as V,DEFAULT_COLOR as X,DEFAULT_LEGEND_ROW_HEIGHT as H,STREAMING_PALETTE as q,SemioticAnnotation as Q,TITLE_BASELINE as Z,applyAnnotationEmphasis as U,buildResolveColor as K,composeLegendConfigs as J,computeEasing as ee,computeRawProgress as te,createColorScale as oe,filterSparseArray as ie,geoSceneNodeToSVG as se,getColor as re,getSize as ne,hasTextTitle as ae,isChartMode as ce,isGradientLegendConfig as le,isLegendConfig as he,layoutVerticalLegendGroups as de,lerp as ue,networkLabelToSVG as ge,networkSceneEdgeToSVG as pe,networkSceneNodeToSVG as fe,now as ye,ordinalSceneNodeToSVG as me,reserveTitleMargin as xe,resolveCategoricalPalette as be,resolveChartMode as ve,resolveCustomLayoutPalette as Ae,resolveDefaultFill as we,resolveExplicitColor as Se,resolveLegendMetrics as ke,xySceneNodeToSVG as _e}from"./chunk-chunk-F25UA5HT.module.min.js";import"./chunk-chunk-XEVJDUTH.module.min.js";import{accessorsEquivalent as Me,resolveAccessor as Pe,resolveStringAccessor as Te,resolveSvgFill as Re}from"./chunk-chunk-2WVCH4PL.module.min.js";import{SYMBOL_SEQUENCE as Le,UpdateResultTracker as ze,annotationLayout as Ce,getSequentialInterpolator as Fe,interpolateBrBG as Be,interpolatePRGn as Oe,interpolatePiYG as Ee,interpolateRdBu as je,interpolateRdYlBu as De,interpolateRdYlGn as Ne,interpolateSpectral as We,interpolateViridis as $e,schemeCategory10 as Ie}from"./chunk-chunk-5RKXZQ2P.module.min.js";import"./chunk-chunk-U66USBWU.module.min.js";import{getMax as Ge,getMin as Ye,getMinMax as Ve}from"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-QRIBHZYW.module.min.js";import"./chunk-chunk-J3QOW4OE.module.min.js";import{DARK_THEME as Xe,HIGH_CONTRAST_THEME as He,LIGHT_THEME as qe,THEME_PRESETS as Qe,applyThemeAccessibility as Ze,resolveThemeSemanticColors as Ue}from"./chunk-chunk-DSNGDNJY.module.min.js";import*as Ke from"react-dom/server";import*as Je from"react";function et(e,t,o){return"function"==typeof e?e(o):o[e||t]}function tt(e){return e instanceof Date?e.getTime():Number(e)}function ot(e,t){return $e(1===t?.5:e/(t-1))}function it(e){if(!e)return qe;if("string"==typeof e){if("light"===e)return qe;if("dark"===e)return Xe;if("high-contrast"===e)return He;return Qe[e]||qe}const t="dark"===e.mode?Xe:qe,o={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return Ze(o)}function st(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function rt(e,t,o,i,s){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=it(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrLineColorBy",l="function"==typeof t?r.map(e=>({...e,__ssrLineColorBy:t(e)})):r,h=t?oe(l,c,a):void 0,d=m(s.xAccessor,s.yAccessor),u=function(e){const{lineWidth:t=2,colorBy:o,colorScale:i,color:s,resolveStroke:r,fillArea:n,areaOpacity:a=.3,styleRules:c,ruleContext:l}=e;return(e,h)=>{const d={strokeWidth:t},u=!0===n||Array.isArray(n)&&null!=h&&n.includes(h);let g;return r?g=r(e,h):o?i&&(g=re(e,o,i)):g=s||X,void 0!==g&&(d.stroke=g,u&&(d.fill=g,d.fillOpacity=a)),c?.length&&Object.assign(d,x(e,c,l?l(e,h):{value:void 0,category:h})),d}}({lineWidth:"number"==typeof s.lineWidth?s.lineWidth:2,colorBy:t,colorScale:h,color:"string"==typeof s.color?s.color:void 0,fillArea:s.fillArea,areaOpacity:"number"==typeof s.areaOpacity?s.areaOpacity:.3,styleRules:s.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})}(u,{stroke:"string"==typeof s.stroke?s.stroke:void 0,strokeWidth:"number"==typeof s.strokeWidth?s.strokeWidth:void 0,opacity:"number"==typeof s.opacity?s.opacity:void 0})}function nt(e,t,o,i,s){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=it(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrAreaColorBy",l="function"==typeof t?r.map(e=>({...e,__ssrAreaColorBy:t(e)})):r,h=t?oe(l,c,a):void 0,d=!1!==s.showLine,u="number"==typeof s.lineWidth?s.lineWidth:2,g="number"==typeof s.areaOpacity?s.areaOpacity:.7,p=y(s.yAccessor),f=s.styleRules;return(e,o)=>{const i=t&&h?re(e,t,h):"string"==typeof s.color?s.color:X,r={fill:i,fillOpacity:g,stroke:d?i:"none",...d&&{strokeWidth:u}};return f?.length&&Object.assign(r,x(e,f,{value:p(e),category:o})),void 0!==s.stroke&&(r.stroke=s.stroke),void 0!==s.strokeWidth&&(r.strokeWidth=s.strokeWidth),void 0!==s.opacity&&(r.opacity=s.opacity),r}}function at(e,t,o,i,s){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=it(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrBubbleColorBy",l="function"==typeof t?r.map(e=>({...e,__ssrBubbleColorBy:t(e)})):r,h=t?oe(l,c,a):void 0,d=s.sizeBy,u=Array.isArray(s.sizeRange)?s.sizeRange:[5,40],g=d?r.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=g.length?Ve(g):void 0;return e=>({fill:t&&h?re(e,t,h):"string"==typeof s.color?s.color:X,fillOpacity:"number"==typeof s.bubbleOpacity?s.bubbleOpacity:.6,r:d?ne(e,d,u,p):u[0],stroke:s.stroke??s.bubbleStrokeColor??"white",strokeWidth:s.strokeWidth??s.bubbleStrokeWidth??1,...void 0!==s.opacity&&{opacity:s.opacity}})}function ct(e,t,o,i,s){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=it(i.theme).colors.categorical,a=o??i.colorScheme??n,c="string"==typeof t?t:"__ssrScatterColorBy",l="function"==typeof t?r.map(e=>({...e,__ssrScatterColorBy:t(e)})):r,h=t?oe(l,c,a):void 0,d=s.sizeBy,u=Array.isArray(s.sizeRange)?s.sizeRange:[3,15],g=d?r.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=g.length?Ve(g):void 0,f=m(s.xAccessor,s.yAccessor),y=s.styleRules;return e=>{const o={fill:t&&h?re(e,t,h):"string"==typeof s.color?s.color:X,fillOpacity:"number"==typeof s.pointOpacity?s.pointOpacity:.8,r:d?ne(e,d,u,p):"number"==typeof s.pointRadius?s.pointRadius:5};return y?.length&&Object.assign(o,x(e,y,f(e))),void 0!==s.stroke&&(o.stroke=s.stroke),void 0!==s.strokeWidth&&(o.strokeWidth=s.strokeWidth),void 0!==s.opacity&&(o.opacity=s.opacity),o}}function lt(e){return Math.max(0,Math.min(1,e))}function ht(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 dt(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 ut(e,t){const o=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:lt(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=lt(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],s=o[e+1];if(t.offset>i||i>s.offset)continue;const r=s.offset-t.offset,n=r>0?(i-t.offset)/r:0,a=ht(t.color),c=ht(s.color);if(!a||!c)return.5>n?t.color:s.color;const[l,h,d]=a,[u,g,p]=c;return dt(l+(u-l)*n,h+(g-h)*n,d+(p-d)*n)}return o[o.length-1].color}function gt(e,t,o){return null==o?`${e}-${t}`:`${e}-${t}-${o}`}import{Fragment as pt,jsx as ft,jsxs as yt}from"react/jsx-runtime";import{useMemo as mt,useCallback as xt,useRef as bt}from"react";var vt={RdBu:je,PiYG:Ee,PRGn:Oe,BrBG:Be,RdYlBu:De,RdYlGn:Ne,Spectral:We},At="__likert_neutral_neg",wt="__likert_neutral_pos";function St(e,t){if("function"==typeof e)return e;const o=e||t;return e=>e[o]}import*as kt from"react";function _t(e){return!0===e?{topOpacity:.8,bottomOpacity:.05}:!1===e?void 0:e}function Mt(e,t,o,i,s){const r=it(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,h=t?oe(l,c,n??r):void 0,d=we("string"==typeof s.color?s.color:void 0,r,n,void 0,new Map),u=y(s.valueAccessor),g=s.styleRules,p=i.pieceStyle;return(e,o)=>{const i={fill:t&&h?re(e,t,h):d};return g?.length&&Object.assign(i,x(e,g,{value:u(e),category:o})),"function"==typeof p?Object.assign(i,p(e,o)||{}):p&&"object"==typeof p&&Object.assign(i,p),void 0!==s.stroke&&(i.stroke=s.stroke),void 0!==s.strokeWidth&&(i.strokeWidth=s.strokeWidth),void 0!==s.opacity&&(i.opacity=s.opacity),i}}function Pt(e,t,o,i,s){const r=Mt(e,t,o,i,s);return(e,t)=>{const o=r(e,t);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function Tt(e,t,o,i,s){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n="string"==typeof t?t:"__ssrViolinColorBy",a="function"==typeof t?r.map(e=>({...e,__ssrViolinColorBy:t(e)})):r,c=it(i.theme).colors.categorical,l=o??i.colorScheme,h=t?oe(a,n,l??c):void 0,d=we("string"==typeof s.color?s.color:void 0,c,l,void 0,new Map);return e=>{const o=t&&h?re(e,t,h):d;return{fill:o,fillOpacity:.6,stroke:s.stroke??o,...void 0!==s.strokeWidth&&{strokeWidth:s.strokeWidth},...void 0!==s.opacity&&{opacity:s.opacity}}}}function Rt(e,t,o,i,s){const r=Mt(e,t,o,i,s),n="number"==typeof s.dotRadius?s.dotRadius:5;return(e,t)=>({r:n,fillOpacity:.8,...r(e,t)})}function Lt(e,t,o,i,s){const r=Mt(e,t,o,i,s),n=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=s.sizeBy,c=Array.isArray(s.sizeRange)?s.sizeRange:[3,8],l=a?n.map(e=>"function"==typeof a?a(e):Number(e[a])).filter(Number.isFinite):[],h=l.length?Ve(l):void 0,d="number"==typeof s.pointRadius?s.pointRadius:4,u="number"==typeof s.pointOpacity?s.pointOpacity:.7;return(e,t)=>({r:a?ne(e,a,c,h):d,fillOpacity:u,...r(e,t)})}import{scaleTime as zt}from"d3-scale";function Ct(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 Ft(e,t,o){const i=t.incoming[e.id],s=t.outgoing[e.id],r=[];for(const e of i)r.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:o.get(e.id).targetSide});for(const e of s)r.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=()=>{r.sort((e,t)=>e.time-t.time||(n[e.kind]??99)-(n[t.kind]??99))},c=r.length?Ye(r.map(e=>e.time)):null,l=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,d=[...new Set(r.map(e=>e.time))].sort((e,t)=>e-t),u=new Map;for(let e=1;d.length>e;e++)u.set(d[e],d[e-1]);const g=e=>{const t=u.get(e);return null!=t?(t+e)/2:null!=h?h:e};a();const p=[];let f=0,y=0;for(const e of r)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 s=g(e.time);p.push({time:s,delta:-i,kind:"transfer-out",side:t}),p.push({time:s,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!==h&&(p.push({time:h,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}r.push(...p),a();let m=0,x=0,b=0,v=0,A=0;const w=[],S=new Map;for(const e of r){if(w.push({t:e.time,topMass:m,botMass:x}),("in"===e.kind||"out"===e.kind)&&e.edge){const t="top"===e.side?m:x;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?m+=e.delta:x+=e.delta,m+x>b&&(b=m+x),m>v&&(v=m),x>A&&(A=x),w.push({t:e.time,topMass:m,botMass:x})}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 P=null;for(const e of s)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:b,topPeak:v,botPeak:A,localAttachments:S}}function Bt(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Ot(e,t){return e.map(e=>({t:Bt(e.t,t),topMass:e.topMass,botMass:e.botMass}))}function Et(e,t,o){const i=e.value*o;if("out"===e.kind){const s=e.sideMassBefore*o;if("top"===e.side){const e=t-s;return[e,e+i]}const r=t+s;return[r-i,r]}const s=e.sideMassAfter*o;if("top"===e.side){const e=t-s;return[e,e+i]}const r=t+s;return[r-i,r]}function jt(e,t){let o=0;for(let i=0;t.length>i;i++)for(let s=i+1;t.length>s;s++){const r=t[i],n=t[s];r.source!==n.source&&r.target!==n.target&&r.source!==n.target&&r.target!==n.source&&(Math.min(r.endTime,n.endTime)>Math.max(r.startTime,n.startTime)&&e[n.source]>e[r.source]!=e[n.target]>e[r.target]&&o++)}return o}function Dt(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 Nt(e,t){return 1e3*jt(e,t)+Dt(e,t)}function Wt(e,t){return{slots:e.map(e=>({peak:{...e.peak},occupants:e.occupants.slice()})),map:{...t}}}function $t(e,t,o){e.length>8||o.length>40?(function(e,t,o,i=6){const s=e.length;if(1>=s)return;let r=Wt(e,t),n=Nt(t,o);for(let a=0;i>a;a++){const i=Array(s).fill(0),a=Array(s).fill(0);for(const e of o){const o=t[e.source],s=t[e.target];i[o]+=s*(e.value||1),a[o]+=e.value||1,i[s]+=o*(e.value||1),a[s]+=e.value||1}const c=Array.from({length:s},(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]),h=new Map;c.forEach((e,t)=>h.set(e,t));for(const e of Object.keys(t))t[e]=h.get(t[e]);e.length=0;for(const t of l)e.push(t);const d=Nt(t,o);if(n>d)n=d,r=Wt(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,r)}(e,t,o,6),function(e,t,o,i=6){const s=e.length;if(1>=s)return;let r=Nt(t,o);for(let n=0;i>n;n++){let i=!1;for(let n=0;s-1>n;n++){const s=e[n];e[n]=e[n+1],e[n+1]=s;for(const e of Object.keys(t))t[e]===n?t[e]=n+1:t[e]===n+1&&(t[e]=n);const a=Nt(t,o);if(r>a)r=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 s={...t},r=Object.keys(s),n=Array.from({length:i},(e,t)=>t),a=n.slice(),c={...s};let l=n.slice(),h=1/0;const d=()=>{for(const e of r)c[e]=a[s[e]];const e=Nt(c,o);h>e&&(h=e,l=n.slice())},u=(e,t)=>{const o=n[e],i=n[t];n[e]=i,n[t]=o,a[o]=t,a[i]=e};d();const g=Array(i).fill(0);let p=0;for(;i>p;)p>g[p]?(u(p%2==0?0:g[p],p),d(),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 It(e,t,o,i,s){const{plotH:r,padding:n,valueScale:a,packing:c,laneOrder:l,lifetimeMode:h="full"}=s,d={},u={};for(const t of e)d[t.id]=o[t.id].topPeak||0,u[t.id]=o[t.id].botPeak||0;const g="half"===h,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 s=null!=e&&Number.isFinite(e)?e:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const e of i.outgoing[t.id]){s>e.startTime&&(s=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&s>e.systemInTime&&(s=e.systemInTime);const t=g?(e.startTime+e.endTime)/2:e.endTime;t>r&&(r=t)}for(const e of i.incoming[t.id]){const t=g?(e.startTime+e.endTime)/2:e.startTime;s>t&&(s=t),e.endTime>r&&(r=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>r&&(r=e.systemOutTime)}p[t.id]={start:Number.isFinite(s)?s:null,end:Number.isFinite(r)?r:null}}const f={},y=[];if("reuse"===c){const o=new Map;for(const t of e)o.set(t.id,0);const s=new Map;for(const t of e)s.set(t.id,0);for(const e of t)s.set(e.target,(s.get(e.target)??0)+1);const r=[];for(const t of e)0===(s.get(t.id)??0)&&r.push(t.id);for(;r.length;){const e=r.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),s.set(t.target,s.get(t.target)-1),0===s.get(t.target)&&r.push(t.target)}}const n=[...e].filter(e=>null!==p[e.id].start).sort((e,t)=>{const i=o.get(e.id)??0,s=o.get(t.id)??0;return i!==s?i-s: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,d[e.id]),y[o].peak.botPeak=Math.max(y[o].peak.botPeak,u[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:d[e.id],botPeak:u[e.id]}}),f[e.id]=t});let m=null,x=null,b=null,v=null;const A=()=>{m=jt(f,t),b=Dt(f,t)},w=()=>{x=jt(f,t),v=Dt(f,t)};"crossing-min"===l?(A(),$t(y,f,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,s=e.map((e,t)=>({slot:e,idx:t})).sort((e,t)=>i(t.slot)-i(e.slot)),r=Array(o),n=Math.floor((o-1)/2);r[n]=s[0].idx;let a=n-1,c=n+1;for(let e=1;s.length>e;e++)e%2==1&&o>c||0>a?r[c++]=s[e].idx:r[a--]=s[e].idx;const l=r.map(t=>e[t]),h=new Map;r.forEach((e,t)=>h.set(e,t));for(const e of Object.keys(t))t[e]=h.get(t[e]);e.length=0;for(const t of l)e.push(t)}(y,f),w()):"crossing-min+inside-out"===l&&(A(),$t(y,f,t),function(e,t,o){const i=e.length;if(1>=i)return;const s=e.map(e=>{return{slot:e,size:(t=e,t.peak.topPeak+t.peak.botPeak)};var t}).sort((e,t)=>t.size-e.size),r=Math.floor((i-1)/2);let n=Nt(t,o);for(const{slot:a}of s){const s=e.indexOf(a);if(0>s)continue;const c=r;if(s===c)continue;const l=e[s];e.splice(s,1),e.splice(c,0,l);const h=new Map;for(let e=0;i>e;e++)h.set(e,e);if(c>s){for(let e=s+1;c>=e;e++)h.set(e,e-1);h.set(s,c)}else{for(let e=c;s>e;e++)h.set(e,e+1);h.set(s,c)}for(const e of Object.keys(t))t[e]=h.get(t[e]);const d=Nt(t,o);if(d>n){const o=e[c];e.splice(c,1),e.splice(s,0,o);const r=new Map;for(let e=0;i>e;e++)r.set(e,e);if(s>c){for(let e=c+1;s>=e;e++)r.set(e,e-1);r.set(c,s)}else{for(let e=s;c>e;e++)r.set(e,e+1);r.set(c,s)}for(const e of Object.keys(t))t[e]=r.get(t[e])}else n=d}}(y,f,t),w());const S=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,s]of e){if(i>t)break;o=s}return o},_=[];for(let e=0;y.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 s=0;for(const e of i){const i=k(t,e),r=k(o,e);i.bot+r.top>s&&(s=i.bot+r.top)}_.push(s)}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>r){const e=r/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,R={};for(const t of e)R[t.id]=M[f[t.id]];return{effectiveSlotsHeight:T,centerlines:R,laneLifetime:p,slots:y,slotByNode:f,slotCenter:M,crossingsBefore:m,crossingsAfter:x,lengthBefore:b,lengthAfter:v}}function Gt(e){const{nodes:t,edges:o,domain:i,plotW:s,plotH:r,ribbonLane:n,edgeOpacity:a,colorOf:c,layoutOpts:l}=e,h=function(e,t,o){const i=[],s=new Set(e.map(e=>e.id)),r=Array.isArray(o)&&2===o.length,n=r&&Number.isFinite(o[0])&&Number.isFinite(o[1]);r&&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)s.has(e.source)||i.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),s.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=zt().domain(i).range([0,s]);if(h.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:h,xScale:d};const u=function(e,t,o){const{plotH:i,pairing:s="temporal",packing:r="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 s="temporal"===i?(e,t)=>e.endTime-t.endTime:(e,t)=>t.value-e.value,r="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 s=o.get(e);s.edges.push(i),s.total+=i.value,s.earliestStart=Math.min(s.earliestStart,i.startTime),s.latestEnd=Math.max(s.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?r:s);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"),s=Math.max(t.length,o.length);for(let e=0;s>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,s);let h={};for(const t of e)h[t.id]=Ft(t,c,l);const d=It(e,t,h,c,{plotH:i,padding:12,valueScale:1,packing:r,laneOrder:n,lifetimeMode:a}),u=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"):(u.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)),s=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===s.size&&e.length>0){const t=[...s][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},s=(e,t)=>{const s=i(),r="top"===e?s.outTop-s.inTop:s.outBot-s.inBot,n="top"===t?s.inTop-s.outTop:s.inBot-s.outBot;if(0>=r||0>=n)return!1;const a=Math.min(r,n),c=o.filter(t=>!u.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 r=o.length+1;for(;r-- >0&&(s("top","bot")||s("bot","top")););}h={};for(const t of e)h[t.id]=Ft(t,c,l);const g=It(e,t,h,c,{plotH:i,padding:12,valueScale:1,packing:r,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=It(e,t,h,c,{plotH:i,padding:f,valueScale:y,packing:r,laneOrder:n,lifetimeMode:a});return{nodeData:h,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:r,...l}),{centerlines:g,nodeData:p,valueScale:f}=u,y=[],m=[];t.forEach((e,t)=>{const s=p[e.id];if(!s||0===s.samples.length)return;const r=function(e,t,o,i,s){if(0===e.length)return null;const r=Ot(e,s),n=e=>t-r[e].topMass*o,a=e=>t+r[e].botMass*o;let c=`M${i(r[0].t)},${n(0)}`;for(let e=1;r.length>e;e++)c+=` L${i(r[e].t)},${n(e)}`;c+=` L${i(r[r.length-1].t)},${a(r.length-1)}`;for(let e=r.length-2;e>=0;e--)c+=` L${i(r[e].t)},${a(e)}`;return c+" Z"}(s.samples,g[e.id],f,d,i);if(!r)return;const n=Ot(s.samples,i),a=n.find(e=>e.topMass+e.botMass>0)||n[0],l=g[e.id]+(a.botMass-a.topMass)*f/2,h=c(e.id,t),m=function(e,t,o,i,s){const r=o.nodeData[e];if(!r||0===r.samples.length)return[];const n=o.valueScale,a=o.centerlines[e],c=Ot(r.samples,s),l=c.find(e=>e.topMass+e.botMass>0)||c[0],h=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],d=i(l.t),u=i(h.t),g=e=>i(Bt(e,s)),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=r.localAttachments.get(o.id);if(e&&"out"===e.kind&&o.startTime>o.systemInTime){const t=g(o.systemInTime),i=g(o.startTime),s=t-20,r=Math.max(d,s);if(i>r){const[o,c]=Et(e,a,n);p.push({pathD:f(r,o,i,c),x0:s,x1:t,from:0,to:1})}}}if(o.target===e&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const e=r.localAttachments.get(o.id);if(e&&"in"===e.kind&&o.systemOutTime>o.endTime){const t=g(o.systemOutTime),i=g(o.endTime),s=t+20,r=Math.min(u,s);if(r>i){const[o,c]=Et(e,a,n);p.push({pathD:f(i,o,r,c),x0:t,x1:s,from:1,to:0})}}}}return p}(e.id,o,u,d,i);y.push({id:e.id,pathD:r,fill:h,stroke:h,strokeWidth:.5,...m.length>0&&{gradientStubs:m},rawDatum:e.__raw??e,labelX:d(a.t)-4,labelY:l,labelText:e.id})});const x=new Map;return t.forEach((e,t)=>x.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 s=x.get(e.source)??0,r=c(e.source,s),l=function(e,t,o,i,s,r,n,a){const c=s,l=e=>a?Math.max(a[0],Math.min(a[1],e)):e,h=r(l(e.time)),d=r(l(o.time)),u=e.value*c,g=o.value*c,p=e.sideMassBefore*c,f=o.sideMassAfter*c;let y,m,x,b;"top"===e.side?(y=t-p,m=y+u):(m=t+p,y=m-u),"top"===o.side?(x=i-f,b=x+g):(b=i+f,x=b-g);const v="source"===n?h+.85*(d-h):"target"===n?h+.15*(d-h):(h+d)/2;return{sx:h,sTop:y,sBot:m,tx:d,tTop:x,tBot:b,cp1X:v,cp2X:v}}(t,g[e.source],o,g[e.target],f,d,n,i),{pathD:h,bezier:u}=M(l);m.push({id:e.id,pathD:h,fill:r,opacity:a,rawDatum:e.__raw??e,bezier:u})}),{layout:u,layoutConfig:{bands:y,ribbons:m,showLabels:!0},issues:[],xScale:d}}var Yt=e=>{const{bands:t=[],ribbons:o=[],showLabels:i=!0}=e.config,s=[];for(const e of o)s.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];s.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)s.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 r=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:s,labels:r}};function Vt(e,t,o,i){if(e&&e.length>0)return e;const s=new Set;return t.forEach(e=>{const t="function"==typeof o?o(e):e[o],r="function"==typeof i?i(e):e[i];s.add(t),s.add(r)}),Array.from(s).map(e=>({id:e}))}import*as Xt from"react";var Ht={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as qt}from"d3-scale";function Qt(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}function Zt(e){return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:28,y2:e.floorY,thickness:8}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:e.width-30,y2:76,thickness:8}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:e.floorY,x2:e.width-30,y2:e.floorY,thickness:8}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-30,y1:76,x2:e.width-30,y2:e.floorY,thickness:8}}]}function Ut(e,t,o,i){return o?"function"==typeof o?o(e,t):e[o]??i:i}function Kt(e){return`gauntlet:${e}:core`}function Jt(e,t){return`gauntlet:${e}:positive:${t}`}function eo(e,t,o){return`gauntlet:${e}:negative:${t}:${o}`}function to(e,t,o,i){const s=Math.max(2,o+2),r=80+s,n=i.floorY-s;return{x:Math.max(32+s,Math.min(i.width-30-4-s,e)),y:Math.max(r,Math.min(n,t))}}function oo(e,t){const o=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,o.indexOf(t));return{angle:.82*-Math.PI+(o.length>1?i/(o.length-1):.5)*Math.PI*.64,index:i,radius:48+i%2*6}}function io(e,t,o){const i=e.activePositiveIds.reduce((e,o)=>e+(t.get(o)?.value??1),0),s=e.missingPositiveIds.length+e.poppedPositiveIds.length,r=e.negativeIds.reduce((e,t)=>e+(o.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*r-1.2*e.delay-5*s))}function so(e){const t=function(e,t,o){const[i,s]=e,r=Math.round(.48*s),n=s-36,a=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,a.length),l=.22*i,h=c>1?(.78*i-l)/(c-1):0,d=Math.max(Math.round(.14*i),110);return{crashY:n-o,floorY:n,gates:a.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(l+t*h),width:e.width??Math.max(54,Math.round(.07*i))})),graveyardX:Math.round(.84*i),graveyardY:n-4,height:s,routeY:r,socketX:Math.round(.92*i),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])),s=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),r={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},n=(e.data??[]).map((t,n)=>{const a=function(e,t,o,i,s){const r=Ut(e,t,o.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",n=i.map(e=>e.id),a=[...Ut(e,t,o.positiveAccessor,n)],c=[...Ut(e,t,o.negativeAccessor,[])].filter(e=>s.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ut(e,t,o.metricsAccessor,{})},missingPositiveIds:n.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ut(e,t,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ut(e,t,o.initialViability,100)}}(t,n,r,o,s);return{...a,viability:e.viability?.(a,{negativeProperties:s,positiveProperties:i})??io(a,i,s)}}),a=n.flatMap((o,r)=>{const n=function(e,t,o,i){const s=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),r=i?.(e,t,o)??{};return{...s,...r,startY:r.startY??r.routeY??s.startY,socketY:r.socketY??r.routeY??s.socketY,graveyardY:r.graveyardY??s.graveyardY}}(o,r,t,e.projectPlacement);return function(e,t,o,i,s,r,n){const a=i.startX,c=i.startY+(i.startY===o.routeY?38*t:0),l=n?.(e,t,o,i)??{},h={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},d=[{...l,id:Kt(e.id),x:l.x??a,y:l.y??c,vx:l.vx??42,vy:l.vy??0,mass:l.mass??7,bodyCollisions:l.bodyCollisions??!0,shape:l.shape??{type:"circle",radius:28},spawnAt:l.spawnAt??e.startedAt,datum:h}],u=to(a,c,l.shape&&"radius"in l.shape&&Number(l.shape.radius)||28,o);d[0].x=u.x,d[0].y=u.y;for(const t of e.activePositiveIds){const i=s.get(t);if(!i)continue;const r=oo(e.activePositiveIds,t),n=i.radius??10,a=to(u.x+Math.cos(r.angle)*r.radius,u.y+Math.sin(r.angle)*r.radius,n,o);d.push({id:Jt(e.id,t),x:a.x,y:a.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:n},spawnAt:l.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:Kt(e.id)},stiffness:.56,damping:.9,restLength:52+r.index%2*4,...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const s=r.get(t);s&&d.push(function(e,t,o,i,s,r,n){const a=t.radius??7.2,c=to(i-12+o%4*12,s+54+12*Math.floor(o/4),a,r);return{id:eo(e.id,t.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:n,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Kt(e.id)},stiffness:.62,damping:.92,restLength:52+o%4*3,...t.spring??{}}]}}(e,s,i,u.x,u.y,o,l.spawnAt??e.startedAt))}),d}(o,r,t,n,i,s,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:Zt(t)}}}function ro(e){return e.map(e=>({...e,spawnAt:void 0}))}var no={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,o,i,s)=>({chartType:"line",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",groupAccessor:s.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,s)=>{const r=t||s.lineBy;return{chartType:"line",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",groupAccessor:s.lineBy||t,colorAccessor:r,colorScheme:o,lineStyle:rt(e,r,o,i,s),...i,showLegend:i.showLegend??!!r}}},AreaChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=t||s.areaBy,n=function({data:e,safeData:t,areaBy:o,lineDataAccessor:i}){if(null==e)return[];const s=void 0!==t[0]?.[i];if(!s&&!o)return t;let r;if(s)r=t;else{const e=t.reduce((e,t)=>{const s="function"==typeof o?o(t):t[o],r=s+"";if(!e[r]){const t={[i]:[]};"string"==typeof o&&(t[o]=s),e[r]=t}return e[r][i].push(t),e},{});r=Object.values(e)}return r.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)?ie(e):[],areaBy:s.areaBy,lineDataAccessor:s.lineDataAccessor||"coordinates"});return{chartType:"area",data:n,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",y0Accessor:s.y0Accessor,groupAccessor:s.areaBy||void 0,colorAccessor:r,colorScheme:o,...i,lineStyle:i.lineStyle||nt(n,r,o,i,s)}}},DifferenceChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=s.xAccessor||"x",n=s.seriesAAccessor||"a",a=s.seriesBAccessor||"b",c=e=>tt(et(r,"x",e)),l=e=>tt(et(n,"a",e)),h=e=>tt(et(a,"b",e)),d=s.seriesAColor||"var(--semiotic-danger, #dc2626)",u=s.seriesBColor||"var(--semiotic-info, #2563eb)",g=s.areaOpacity??.6,p=s.lineWidth??1.5,f=!1!==s.showLines,y=!1!==i.showLegend,m=s.seriesALabel||"A",x=s.seriesBLabel||"B",b=i.legendPosition||"right",v=function(e,t,o,i){if(!e.length)return[];const s=e.filter(e=>Number.isFinite(t(e))).sort((e,o)=>t(e)-t(o)),r=[];let n=0,a=null,c=null,l=[];const h=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${n}-${e}`,u=e=>r.push(e),g=(e,t)=>{u({__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;s.length>e;e++){const r=s[e],p=t(r),f=o(r),y=i(r);if(!Number.isFinite(p)||!Number.isFinite(f)||!Number.isFinite(y))continue;const m=h(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}u({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t}),n++,a=m,u({__x:e,__y:t,__y0:t,__diffSegment:d(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=[],u({__x:p,__y:y>f?y:f,__y0:y>f?f:y,__diffSegment:d(a),__diffWinner:a,__valA:f,__valB:y,__sourceDatum:r}),c={x:p,a:f,b:y,w:m}}else{a=m;for(const e of l)g(e,a);l=[],u({__x:p,__y:y>f?y:f,__y0:y>f?f:y,__diffSegment:d(a),__diffWinner:a,__valA:f,__valB:y,__sourceDatum:r}),c={x:p,a:f,b:y,w:m}}else l.push({x:p,y:f,datum:r})}for(const e of l)g(e,a??"A");return r}(Array.isArray(e)?e:[],c,l,h),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=h(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:u,stroke:"none",fillOpacity:g}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?d:u,strokeWidth:p,fill:"none"}),curve:s.curve||"linear",...i,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:u}]}]},legendPosition:b}}}},StackedAreaChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=t||s.areaBy,n="string"==typeof r&&Array.isArray(e)?oe(e,r,o):void 0;return{chartType:"stackedarea",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",groupAccessor:s.areaBy,colorAccessor:r,colorScheme:o,normalize:s.normalize,stackOrder:s.stackOrder,lineStyle:null==s.areaOpacity?void 0:e=>{const t=null==r?void 0:re(e,r,n),o=s.showLine??!0;return{fill:s.color??t,stroke:o?s.stroke??t:"none",...o?{strokeWidth:s.strokeWidth??s.lineWidth??2}:{},fillOpacity:s.areaOpacity,...null==s.opacity?{}:{opacity:s.opacity}}},...i,curve:i.curve??s.curve??"monotoneX",showLegend:i.showLegend??!!r}}},Scatterplot:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=i.pointStyle||ct(e,t,o,i,s),n=v(s.styleRules,s.xAccessor||"x",s.yAccessor||"y"),a=n?e=>({..."function"==typeof r?r(e):r,...n(e)}):r;return{chartType:"scatter",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",colorAccessor:t,sizeAccessor:s.sizeBy,...s.symbolBy&&{symbolAccessor:s.symbolBy},...s.symbolMap&&{symbolMap:s.symbolMap},colorScheme:o,...i,sizeRange:s.sizeRange||[3,15],pointStyle:a,showLegend:i.showLegend??!!t}}},CandlestickChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const[r]=i.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.highAccessor||"high",highAccessor:s.highAccessor||"high",lowAccessor:s.lowAccessor||"low",openAccessor:s.openAccessor,closeAccessor:s.closeAccessor,candlestickStyle:s.candlestickStyle,...i,scalePadding:i.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:i.extentPadding??(r>200?.1:.02)}}},BubbleChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>({chartType:"scatter",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",colorAccessor:t,sizeAccessor:s.sizeBy,sizeRange:s.sizeRange||[5,40],colorScheme:o,...i,pointStyle:i.pointStyle||at(e,t,o,i,s),showLegend:i.showLegend??!!t})},ConnectedScatterplot:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};const o=t.xAccessor||"x",i=t.yAccessor||"y",s=t.orderAccessor?[...e].sort((e,o)=>null==e||"object"!=typeof e?1:null==o||"object"!=typeof o?-1:tt(et(t.orderAccessor,"order",e))-tt(et(t.orderAccessor,"order",o))):e,r=new WeakMap;let n=0;for(const e of s){if(null==e||"object"!=typeof e)continue;const t=tt(et(o,"x",e)),s=tt(et(i,"y",e));Number.isFinite(t)&&Number.isFinite(s)&&n++}let a=0;for(const e of s){if(null==e||"object"!=typeof e)continue;const t=tt(et(o,"x",e)),s=tt(et(i,"y",e));Number.isFinite(t)&&Number.isFinite(s)&&r.set(e,{idx:a++,total:n})}return{data:s,orderMap:r}}(e,s),n=s.pointRadius??4;return{chartType:"scatter",data:r.data,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",colorAccessor:t,colorScheme:o,pointStyle:e=>{const t=r.orderMap.get(e),o=t?.idx??0,i=t?.total??1;return{fill:i>0?ot(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],s=t[e+1],r=ot(e,t.length);100>t.length&&o.push(Je.createElement("line",{key:"halo-"+e,x1:i.x,y1:i.y,x2:s.x,y2:s.y,stroke:"white",strokeWidth:n+2,strokeLinecap:"round",opacity:.5})),o.push(Je.createElement("line",{key:"segment-"+e,x1:i.x,y1:i.y,x2:s.x,y2:s.y,stroke:r,strokeWidth:n,strokeLinecap:"round"}))}return Je.createElement(Je.Fragment,null,...o)}]}}},QuadrantChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=s.xCenter,n=s.yCenter,a=s.quadrants,c=s.centerlineStyle||{},l=!1!==s.showQuadrantLabels,h=s.quadrantLabelSize??12,d=c.stroke||"#999",u=c.strokeWidth??1,g=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,p=Je.createElement,f=a?[(e,t,o)=>{if(!t?.x||!t?.y)return null;const i=o.width,s=o.height,c=null!=r?t.x(r):i/2,f=null!=n?t.y(n):s/2;if(null!=r&&!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(s,f)),x=[{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:s-m},{c:a.bottomRight,x:y,y:m,w:i-y,h:s-m}],b=l?[p("text",{key:"ltl",x:8,y:8+h,fill:a.topLeft.color,fontWeight:600,fontSize:h,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:i-8,y:8+h,fill:a.topRight.color,fontWeight:600,fontSize:h,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:s-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:h,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:i-8,y:s-8,fill:a.bottomRight.color,fontWeight:600,fontSize:h,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(Je.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?p("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),p("line",{key:"vc",x1:y,y1:0,x2:y,y2:s,stroke:d,strokeWidth:u,strokeDasharray:g}),p("line",{key:"hc",x1:0,y1:m,x2:i,y2:m,stroke:d,strokeWidth:u,strokeDasharray:g}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",colorAccessor:t,sizeAccessor:s.sizeBy,sizeRange:s.sizeRange||[3,15],colorScheme:o,pointStyle:i.pointStyle||s.pointStyle||ct(e,t,o,i,s),...i,showLegend:i.showLegend??!!t,...f&&{svgPreRenderers:f}}}},Heatmap:{frameType:"xy",buildProps:(e,t,o,i,s)=>({chartType:"heatmap",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",valueAccessor:s.valueAccessor,colorScheme:o||s.colorScheme||"blues",showValues:s.showValues,heatmapValueFormat:s.valueFormat,cellBorderColor:s.cellBorderColor,...i})},TemporalHistogram:{frameType:"xy",buildProps:(e,t,o,i,s)=>{const r=Array.isArray(e)?ie(e):[],n=s.timeAccessor||"time",a=s.valueAccessor||"value",c=s.categoryAccessor,l=s.valueExtent||i.yExtent,h="down"===s.direction?D({data:r,timeAccessor:n,valueAccessor:a,binSize:Number(s.binSize),valueExtent:l,extentPadding:s.extentPadding}):l,d={...void 0!==s.fill&&{fill:s.fill},...void 0!==s.stroke&&{stroke:s.stroke},...void 0!==s.strokeWidth&&{strokeWidth:s.strokeWidth},...void 0!==s.opacity&&{opacity:s.opacity},...void 0!==s.gap&&{gap:s.gap}};return{chartType:"bar",data:r,...i,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:s.arrowOfTime||"right",timeAccessor:n,valueAccessor:a,xExtent:s.timeExtent||i.xExtent,yExtent:h,extentPadding:s.extentPadding??i.extentPadding,binSize:s.binSize,categoryAccessor:c,barColors:s.colors||i.barColors,colorScheme:s.colors||i.colorScheme,barStyle:i.barStyle||d,showLegend:i.showLegend??!!c}}},XYCustomChart:{frameType:"xy",buildProps:(e,t,o,i,s)=>({chartType:"custom",data:e,xAccessor:s.xAccessor||"x",yAccessor:s.yAccessor||"y",colorAccessor:t,colorScheme:o,customLayout:s.layout||s.customLayout,layoutConfig:s.layoutConfig,...i,showAxes:s.frameProps?.showAxes??s.showAxes??!1,showLegend:i.showLegend??!!t})},BarChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"bar",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",projection:"horizontal"===s.orientation?"horizontal":"vertical",oSort:s.sort??!1,colorAccessor:t,colorScheme:o,barPadding:s.barPadding,...null!=s.roundedTop&&{roundedTop:s.roundedTop},...i,gradientFill:_t(i.gradientFill),pieceStyle:Mt(e,t,o,i,s)})},StackedBarChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>{const r=t||s.stackBy;return{chartType:"bar",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",stackBy:s.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===s.orientation?"horizontal":"vertical",normalize:s.normalize,oSort:s.sort??!1,barPadding:s.barPadding,...null!=s.roundedTop&&{roundedTop:s.roundedTop},...i,gradientFill:_t(i.gradientFill),pieceStyle:Mt(e,r,o,i,s),showLegend:i.showLegend??!!r}}},GroupedBarChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>{const r=t||s.groupBy;return{chartType:"clusterbar",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",groupBy:s.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===s.orientation?"horizontal":"vertical",oSort:s.sort??!1,barPadding:s.barPadding,...null!=s.roundedTop&&{roundedTop:s.roundedTop},...i,gradientFill:_t(i.gradientFill),pieceStyle:Mt(e,r,o,i,s),showLegend:i.showLegend??!!r}}},PieChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>{const r=t||s.categoryAccessor;return{chartType:"pie",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=s.cornerRadius&&{cornerRadius:s.cornerRadius},...i,pieceStyle:Mt(e,r,o,i,s),showLegend:i.showLegend??!!r}}},DonutChart:{frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,o,i,s)=>{const r=t||s.categoryAccessor;return{chartType:"donut",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",projection:"radial",margin:i.margin??{top:50,right:40,bottom:60,left:70},innerRadius:s.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=s.cornerRadius&&{cornerRadius:s.cornerRadius},...i,pieceStyle:Mt(e,r,o,i,s)}}},Histogram:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>{const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=s.valueAccessor||"value",a=r.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:s.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:n,projection:"horizontal",bins:s.bins??25,normalize:s.relative??!1,colorAccessor:t,colorScheme:o,barPadding:s.categoryPadding??20,...s.valueExtent?{rExtent:s.valueExtent}:c?{rExtent:c}:{},...i,summaryStyle:Pt(e,t,o,i,s)}}},BoxPlot:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"boxplot",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",colorAccessor:t,colorScheme:o,...i,summaryStyle:i.summaryStyle||Pt(e,t,o,i,s)})},ViolinPlot:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"violin",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===s.orientation?"horizontal":"vertical",bins:s.bins??25,showIQR:s.showIQR??!0,barPadding:s.categoryPadding??20,colorScheme:o,...i,summaryStyle:i.summaryStyle||Tt(e,t,o,i,s),showLegend:i.showLegend??!!t,...s.valueExtent&&{rExtent:s.valueExtent}})},SwarmPlot:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"swarm",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",colorAccessor:t,...s.symbolBy&&{symbolAccessor:s.symbolBy},...s.symbolMap&&{symbolMap:s.symbolMap},colorScheme:o,...i,sizeRange:s.sizeRange||[3,8],pieceStyle:i.pieceStyle||Lt(e,t,o,i,s),showLegend:i.showLegend??!!t})},DotPlot:{frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,o,i,s)=>({chartType:"point",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===s.orientation?"vertical":"horizontal",oSort:s.sort??"auto",barPadding:s.categoryPadding??10,...i,pieceStyle:Rt(e,t,o,i,s),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!t})},SwimlaneChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>{const r=t||s.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",stackBy:s.subcategoryAccessor,colorAccessor:r,categoryAccessor:s.categoryAccessor,subcategoryAccessor:s.subcategoryAccessor,colorScheme:o,projection:"vertical"===s.orientation?"vertical":"horizontal",...null!=s.trackFill&&{trackFill:s.trackFill},...i,gradientFill:_t(i.gradientFill),pieceStyle:i.pieceStyle||Mt(e,r,o,i,s),showLegend:i.showLegend??!!r,barPadding:s.barPadding??40}}},RidgelinePlot:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"ridgeline",data:e,oAccessor:s.categoryAccessor||"category",rAccessor:s.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===s.orientation?"vertical":"horizontal",bins:s.bins??20,amplitude:s.amplitude??1.5,barPadding:s.categoryPadding??5,oSort:s.oSort??!1,...i,summaryStyle:i.summaryStyle||((r,n)=>({fillOpacity:.5,...Mt(e,t,o,i,s)(r,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,s)=>{const r=Array.isArray(s.levels)&&s.levels.length>=2?s.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],n="vertical"!==s.orientation;let a=function(e,t,o,i,s,r){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 s=t[o];l.set(s,(l.get(s)||0)+1)}else if(s&&r){const e=s(c),t=r(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 s=0;t.length>s;s++){const r=t[s],n=o.get(r)||0;c.push({__likertCategory:e,__likertLevel:r,__likertLevelLabel:r,__likertCount:n,__likertPct:n/i*100,__likertLevelIndex:s})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],r,St(s.categoryAccessor,"question"),s.levelAccessor?null:St(s.valueAccessor,"score"),s.levelAccessor?St(s.levelAccessor,"level"):null,s.levelAccessor?St(s.countAccessor,"count"):null);n&&(a=function(e,t){const o=t.length,i=o%2!=0,s=Math.floor(o/2),r=new Map;for(const t of e){const e=r.get(t.__likertCategory)||[];e.push(t),r.set(t.__likertCategory,e)}const n=[];for(const[,e]of r){const t=new Map;let r,a;for(const o of e)o.__likertLevel===At?r=o:o.__likertLevel===wt?a=o:t.set(o.__likertLevelIndex,o);i&&r&&n.push(r);for(let e=s-1;e>=0;e--){const o=t.get(e);o&&n.push(o)}i&&a&&n.push(a);for(let e=i?s+1:s;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,s=Math.floor(o/2),r=[];for(const t of e){const e=t.__likertLevelIndex;if(i&&e===s){const e=t.__likertPct/2;r.push({...t,__likertLevel:At,__likertPct:-e}),r.push({...t,__likertLevel:wt,__likertPct:e})}else r.push(s>e?{...t,__likertPct:-t.__likertPct}:t)}return r}(a,r),r));const c=it(i.theme).colors.diverging,l=Array.isArray(o)&&o.length>=r.length?o:function(e,t){if(0>=e)return[];if(t){const o=vt[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"],s="#a8a8a8";if(1===e)return[s];const r=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)]);r&&a.push(s);for(let e=0;n>e;e++)a.push(i[Math.min(Math.floor(e*i.length/n),i.length-1)]);return a}(r.length,c),h=new Map(r.map((e,t)=>[e,l[t]||"#888"])),d=r.length%2&&h.get(r[Math.floor(r.length/2)])||"#888",u="function"==typeof s.valueFormat?s.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",g=!1===i.showLegend?void 0:{legendGroups:[{label:"",items:r.map(e=>({label:e})),styleFn:e=>({fill:h.get(e.label)||"#888"})}]},p=J(g,i.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:n?"horizontal":"vertical",barPadding:s.barPadding,showGrid:i.showGrid,oLabel:s.categoryLabel,rLabel:s.valueLabel||(n?void 0:"Percentage"),rFormat:u,...s.categoryFormat&&{oFormat:s.categoryFormat},...s.valueExtent&&{rExtent:s.valueExtent},...i,pieceStyle:e=>{const t=e.__likertLevel||e.data?.__likertLevel;return{fill:t===At||t===wt?d:h.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,s)=>{const r="vertical"===s.orientation,n=t||s.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:e,oAccessor:s.stepAccessor||"step",rAccessor:s.valueAccessor||"value",colorAccessor:n,categoryAccessor:s.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:s.connectorAccessor,connectorStyle:s.connectorStyle,...!r&&null!=s.connectorOpacity&&{connectorOpacity:s.connectorOpacity},barPadding:r?40:0,colorScheme:o,...i,showAxes:r,showGrid:r,pieceStyle:Mt(e,n,o,i,s),showLabels:s.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,s=o.needleColor||t.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(e=>e.value>o.gMin&&o.gMax>e.value):[];return yt(pt,{children:[o.showNeedle&&yt(pt,{children:[ft("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(i),y2:o.centerY+o.needleLength*Math.sin(i),stroke:s,strokeWidth:2.5,strokeLinecap:"round"}),ft("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:s})]}),null!=o.contextValue&&ft("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:s,children:o.contextValue}),r.map((e,i)=>{const s=(o.startAngleDeg+(o.gMax===o.gMin?0:(e.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,n=o.radius+1,a=o.radius+10,c=((s+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",h=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return yt("g",{children:[ft("line",{x1:o.centerX+Math.cos(s)*r,y1:o.centerY+Math.sin(s)*r,x2:o.centerX+Math.cos(s)*n,y2:o.centerY+Math.sin(s)*n,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),ft("text",{x:o.centerX+Math.cos(s)*a,y:o.centerY+Math.sin(s)*a,textAnchor:l,dominantBaseline:h,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+i)})]})},buildProps:(o,i,s,r,n)=>{const a=n.min??0,c=n.max??100,l=n.sweep??240,h=n.arcWidth??.3,d=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:g}=t(l),p=n.thresholds||[{value:c,color:n.color||"#4e79a7"}],f=r.gradientFill,y=function(e){const{min:t,max:o,value:i,thresholds:s,fillColor:r,backgroundColor:n,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:h=240}=e,d=o-t||1,u=(Math.max(t,Math.min(o,i))-t)/d;let g=s&&s.length>0?[...s].sort((e,t)=>e.value-t.value):[{value:o,color:r||"#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?u:1,t=gt("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(h)),o=Math.max(1,Math.min(t,Math.round(e*t))),i=[];for(let t=0;o>t;t++)i.push(ut(l.colorStops,e*(t+.5)/o));const s=gt("fill",0);f.push({category:s,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:i}}),y.set(s,{fill:i[0]||n})}}else{let e=t;for(let o=0;g.length>o;o++){const i=g[o],s=(i.value-e)/d,r=(e-t)/d,c=(i.value-t)/d,l=Math.max(0,(a?Math.min(u,c):c)-r),h=a?Math.max(0,s-l):0;if(l>0){const e=gt("fill",o);f.push({category:e,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),y.set(e,{fill:i.color})}if(h>0){const e=gt("bg",o);f.push({category:e,value:h,_zone:i.label||"Zone "+(o+1),_isFill:!1}),y.set(e,{fill:n,opacity:.4})}e=i.value}}if(c&&s&&s.length>0)for(const e of s)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:u,showScaleLabels:!1!==n.showScaleLabels,gradientFill:f&&"object"==typeof f&&"colorStops"in f?f:void 0}),[m,x]=r.size||[300,250],b=e(l),v=Math.min(10,Math.max(1,Math.min(m,x)/12)),A=Math.max(4,Math.min((m-2*v)/b.width,(x-2*v)/b.height)-2),w=Math.max(0,Math.min(A-1.5,A*(1-h))),S=m/2-b.cx*A,k=x/2-b.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??r.centerContent,R=null!=T?"function"==typeof T?T(M,a,c):T:"sparkline"===n.mode||"context"===n.mode?void 0:kt.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},kt.createElement("div",{style:{fontSize:Math.max(16,.3*A),fontWeight:700,color:"var(--semiotic-text, #333)"}},P),!1!==n.showScaleLabels&&kt.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:w,sweepAngle:l,startAngle:g,oSort:!1,pieceStyle:y.pieceStyle,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...r,size:[m,x],margin:{top:k-_/2,bottom:x-k-_/2,left:S-_/2,right:m-S-_/2},...null!=R&&{centerContent:R},showAxes:!1,annotations:[...Array.isArray(r.annotations)?r.annotations:[],...y.gaugeAnnotations],__gauge:{gMin:a,gMax:c,sweep:l,arcWidth:h,value:M,startAngleDeg:g,thresholds:p,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==T&&{contextValue:P,contextValueY:k-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*A))}}}}},OrdinalCustomChart:{frameType:"ordinal",buildProps:(e,t,o,i,s)=>({chartType:"custom",data:e,oAccessor:s.categoryAccessor||s.oAccessor||"category",rAccessor:s.valueAccessor||s.rAccessor||"value",projection:s.projection||"vertical",colorAccessor:t,colorScheme:o,customLayout:s.layout||s.customLayout,layoutConfig:s.layoutConfig,...i,showAxes:s.frameProps?.showAxes??s.showAxes??!1})},ForceDirectedGraph:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,s)=>{const{edgeWidth:r,edgeColor:n,edgeOpacity:a}=s,c=s.edgeStyle??(void 0!==r||void 0!==n||void 0!==a?e=>{const t=e?.data||e;let o=1;if("number"==typeof r)o=r;else if("function"==typeof r)o=r(t);else if("string"==typeof r){const e=t?.[r],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=it(i.theme).colors.categorical,h=new Map,d=s.nodeStyle??(e=>({fill:t?re(e?.data||e,t,void 0):we(void 0,l,o,void 0,h),..."number"==typeof s.nodeSize&&{r:s.nodeSize}})),u=b(s.styleRules,t,"number"==typeof s.nodeSize?void 0:s.nodeSize);return{chartType:"force",nodes:s.nodes,edges:s.edges,nodeIDAccessor:s.nodeIdAccessor||s.nodeIDAccessor,sourceAccessor:s.sourceAccessor,targetAccessor:s.targetAccessor,colorBy:t,colorScheme:o,iterations:s.iterations,forceStrength:s.forceStrength,showLabels:s.showLabels??!1,nodeLabel:s.nodeLabel,nodeSize:s.nodeSize??8,nodeSizeRange:s.nodeSizeRange,nodeStyle:u?(e,t)=>({...d(e),...u(e,t)}):d,edgeStyle:c,...i}}},NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,o,i,s)=>({chartType:"force",nodes:s.nodes||e||[],edges:s.edges||[],nodeIDAccessor:s.nodeIdAccessor||s.nodeIDAccessor||"id",sourceAccessor:s.sourceAccessor||"source",targetAccessor:s.targetAccessor||"target",valueAccessor:s.valueAccessor||"value",colorBy:t,colorScheme:o,customNetworkLayout:s.layout||s.customNetworkLayout,layoutConfig:s.layoutConfig,...i})},SankeyDiagram:{frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,o,i,s)=>{const r=Array.isArray(s.nodes)?s.nodes:Vt([],Array.isArray(s.edges)?s.edges:[],s.sourceAccessor||"source",s.targetAccessor||"target"),n=it(i.theme).colors.categorical,a=new Map,c="string"==typeof t?t:"__ssrSankeyColorBy",l="function"==typeof t?r.map(e=>({...e,__ssrSankeyColorBy:t(e)})):r,h=t?oe(l,c,o??i.colorScheme??n):void 0,d=e=>({fill:t?re(e?.data||e,t,h):we(void 0,n,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),u=function({edgeColorBy:e,colorBy:t,colorScale:o,nodeStyleFn:i,edgeOpacity:s,baseStyle:r={}}){return n=>{const a={fillOpacity:s,...r};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=re(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=re(e.data||e,t,o):e&&(a.fill=i(e,e.index).fill)}else"gradient"===e&&(a.fill="#999",a.fillOpacity=.7*s);return a}}({edgeColorBy:s.edgeColorBy??"source",colorBy:t,colorScale:h,nodeStyleFn:d,edgeOpacity:s.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:s.nodes,edges:s.edges,nodeIDAccessor:s.nodeIdAccessor||s.nodeIDAccessor,sourceAccessor:s.sourceAccessor,targetAccessor:s.targetAccessor,valueAccessor:s.valueAccessor,orientation:s.orientation,nodeAlign:s.nodeAlign,nodeWidth:s.nodeWidth,nodePaddingRatio:s.nodePaddingRatio,showLabels:s.showLabels,nodeLabel:s.nodeLabel,colorBy:t,edgeColorBy:s.edgeColorBy,edgeOpacity:s.edgeOpacity,nodeStyle:i.nodeStyle||s.nodeStyle||d,edgeStyle:i.edgeStyle||s.edgeStyle||u,colorScheme:o,...i}}},ProcessSankey:{frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,o,i,s)=>{const r=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),n=s.sourceAccessor||"source",a=s.targetAccessor||"target",c=s.valueAccessor||"value",l=s.nodeIdAccessor||"id",h=s.startTimeAccessor||"startTime",d=s.endTimeAccessor||"endTime",u=s.systemInTimeAccessor,g=s.systemOutTimeAccessor,p=s.xExtentAccessor||"xExtent",f=s.edgeIdAccessor||"id",y=(e,t)=>"function"==typeof e?e(t):t[e],m=Array.isArray(s.edges)?s.edges:[],x=Array.isArray(s.nodes)?s.nodes:[],b=x.length>0?x:Vt([],m,n,a),v=[r(s.domain?.[0]),r(s.domain?.[1])],A=b.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=r(o[0]),t=r(o[1]);Number.isFinite(e)&&Number.isFinite(t)&&(i.xExtent=[e,t])}return i}),w=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:r(y(h,e)),endTime:r(y(d,e)),__raw:e};if(u){const t=r(y(u,e));Number.isFinite(t)&&(i.systemInTime=t)}if(g){const t=r(y(g,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,P=i.legendPosition??"right",T=i.__explicitMargin,R=e=>"number"==typeof T||null!=T&&"object"==typeof T&&null!=T[e];M&&("right"!==P||R("right")?"bottom"!==P||R("bottom")||(_.bottom=Math.max(_.bottom,80)):_.right=Math.max(_.right,140));const L=_,z=S-L.left-L.right,C=k-L.top-L.bottom,F=it(i.theme),B=be(o,F.colors.categorical,Ie),O="function"==typeof t?t:null,E=O?b.map(e=>({_cat:O(e)})):b,j=O?"_cat":"string"==typeof t?t:void 0,D=o??[...B],N=j?oe(E,j,D):null,W=new Map;for(const e of A)W.set(e.id,e.__raw);const $=(e,o)=>{if(t&&W.has(e)){const o=W.get(e);return O?re({_cat:O(o)},"_cat",N??void 0):re(o,"string"==typeof t?t:"id",N??void 0)}return B[o%B.length]},I=M&&t?(()=>{const e=new Map;b.forEach((o,i)=>{const s=y(t,o),r=null==s?"":s+"";r&&!e.has(r)&&e.set(r,{label:r,color:$(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=J(I,i.legend),{layout:Y,layoutConfig:V,issues:X,xScale:H}=Gt({nodes:A,edges:w,domain:v,plotW:z,plotH:C,ribbonLane:s.ribbonLane||"both",edgeOpacity:"number"==typeof s.edgeOpacity?s.edgeOpacity:.35,colorOf:$,layoutOpts:{pairing:s.pairing||"temporal",packing:s.packing||"reuse",laneOrder:s.laneOrder||"crossing-min",lifetimeMode:s.lifetimeMode||"half"}});if(X.length>0){const e=X.map(Ct).join("; ");throw Error("ProcessSankey: data invalid — "+e)}const q=Array.isArray(s.axisTicks)?s.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 s=Number(H(i.start)),r=Number(H(i.end));e=null==e?s:Math.min(e,s),t=null==t?r:Math.max(t,r)}const o=e=>Math.max(0,Math.min(z,e)),i=o(e??0),n=Math.max(i,o(t??z)),a=q.map((e,t)=>({tick:e,index:t,x:Number(H(r(e.date)))})).filter(({x:e})=>e>=i-.5&&n+.5>=e);return Xt.createElement("g",null,...a.map(({index:e,x:t})=>Xt.createElement("line",{key:"grid-"+e,x1:t,y1:0,x2:t,y2:C,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),Xt.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=r(e.date),n=null!=e.label?e.label:"function"==typeof s.timeFormat?s.timeFormat(new Date(i)):"";return Xt.createElement("g",{key:"tick-"+t,transform:`translate(${o},${C+4})`},Xt.createElement("line",{y2:6,stroke:"#94a3b8"}),Xt.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},n))}))})():void 0;return{chartType:"force",nodes:b,edges:m,customNetworkLayout:Yt,layoutConfig:V,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:L}}},ChordDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,s)=>({chartType:"chord",nodes:s.nodes,edges:s.edges,valueAccessor:s.valueAccessor,padAngle:s.padAngle,groupWidth:s.groupWidth,showLabels:s.showLabels,colorBy:t,edgeColorBy:s.edgeColorBy,colorScheme:o,...i})},TreeDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,s)=>{const r=it(i.theme).colors.categorical,n=new Map,a=t&&"string"==typeof t?oe(e&&"object"==typeof e?[e]:[],t,o??i.colorScheme??r):void 0,c=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7"];return{chartType:"cluster"===s.layout?"cluster":"tree",data:e,childrenAccessor:s.childrenAccessor,colorBy:t,colorByDepth:s.colorByDepth,orientation:s.orientation,showLabels:s.showLabels,colorScheme:o,...i,nodeStyle:i.nodeStyle||s.nodeStyle||(e=>{const l=e?.data||e;return{fill:s.colorByDepth?c[Number(e?.depth||0)%c.length]:t?re(l,t,a):we(void 0,r,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,s)=>({chartType:"treemap",data:e,childrenAccessor:s.childrenAccessor,hierarchySum:s.valueAccessor,colorBy:t,colorByDepth:s.colorByDepth,showLabels:s.showLabels,colorScheme:o,...i,nodeStyle:i.nodeStyle||s.nodeStyle||(()=>({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,s)=>{const r=it(i.theme).colors.categorical,n=new Map;return{chartType:"circlepack",data:e,childrenAccessor:s.childrenAccessor,hierarchySum:s.valueAccessor,colorBy:t,colorByDepth:s.colorByDepth,colorScheme:o,...i,nodeStyle:i.nodeStyle||(()=>({fill:we(void 0,r,o,void 0,n),fillOpacity:s.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,s)=>{const r="string"==typeof o?o:"blues",n=s.areaStyle??function(e,t,o,i){if(!Array.isArray(e))return;const s=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0;let r=1/0,n=-1/0;for(const t of e){const e=s(t);null!=e&&isFinite(e)&&(r>e&&(r=e),e>n&&(n=e))}const a=qt(Fe(o)).domain([Number.isFinite(r)?r:0,Number.isFinite(n)?n:1]);return e=>{const t=s(e);return{fill:null!=t&&isFinite(t)?a(t):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:i}}}(s.areas,s.valueAccessor,r,s.areaOpacity??1),a=s.styleRules?p(n,s.styleRules,e=>{return{value:(t=e,"function"==typeof s.valueAccessor?s.valueAccessor(t):null!=s.valueAccessor?t?.properties?.[s.valueAccessor]??t?.[s.valueAccessor]:void 0)};var t},Qt):n;return{areas:s.areas,projection:s.projection||"equalEarth",areaStyle:a,valueAccessor:s.valueAccessor,colorScheme:r,graticule:s.graticule,fitPadding:s.fitPadding,...i}}},ProportionalSymbolMap:{frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,s)=>{const r=e||s.points,n=s.pointStyle??function(e,t,o,i){const s=Array.isArray(e)?e:[];let r,n;if(t){const e="string"==typeof t?t:"__geoColorBy",i="string"==typeof t?s:s.map(e=>({...e,__geoColorBy:t(e)}));r=oe(i,e,o)}if(i.sizeBy){const e=s.map("function"==typeof i.sizeBy?i.sizeBy:e=>e?.[i.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(n=Ve(e))}return e=>({fill:t&&r?re(e,t,r):X,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?ne(e,i.sizeBy,i.sizeRange,n):i.pointRadius??6})}(r,t,o,{sizeBy:s.sizeBy,sizeRange:s.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=s.styleRules?p(n,s.styleRules,f(t,s.sizeBy)):n;return{points:r,xAccessor:s.xAccessor||"lon",yAccessor:s.yAccessor||"lat",areas:s.areas,areaStyle:s.areaStyle||Ht,pointStyle:a,sizeBy:s.sizeBy,colorBy:t,colorScheme:o,projection:s.projection||"equalEarth",graticule:s.graticule,fitPadding:s.fitPadding,...i}}},FlowMap:{frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,i,s)=>{const r=(Array.isArray(e)?e:null)||s.flows||[],n=s.nodeIdAccessor||"id",a=s.valueAccessor||"value",c=s.xAccessor||"lon",l=s.yAccessor||"lat",h="function"==typeof c?c:e=>e[c],d="function"==typeof l?l:e=>e[l],u=(s.nodes||[]).map(e=>({...e,x:h(e),y:d(e)})),g=new Map;for(const e of u)g.set(e[n]+"",e);const p=s.edgeColorBy??t,f="function"==typeof p,y=r.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",x=(()=>{if(!p)return null;if(f){const e=y.map(e=>({[m]:p(e)}));return oe(e,m,o||"category10")}return oe(y,p,o||"category10")})(),b=e=>p&&x?re(e,p,x):"#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 w=A>v?A-v:0,[S,k]=s.edgeWidthRange??[1,8],_=k-S,M=s.edgeOpacity??.6,P=s.edgeLinecap??"round";return{lines:y,points:u,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:s.lineType||"geo",flowStyle:s.flowStyle||"basic",areas:s.areas,areaStyle:s.areaStyle||Ht,projection:s.projection||"equalEarth",graticule:s.graticule,fitPadding:s.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:b(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,s)=>({points:s.points||e||[],areas:s.areas||[],lines:s.lines||[],projection:s.projection||"equirectangular",xAccessor:s.xAccessor||"lon",yAccessor:s.yAccessor||"lat",lineDataAccessor:s.lineDataAccessor,colorBy:t,colorScheme:o,customLayout:s.layout||s.customLayout,layoutConfig:s.layoutConfig,...i})},GaltonBoardChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const n=i.size??[600,400],a=r.bins??21,l=r.seed??1,h=Math.max(1,Math.round(r.pegRows??a-1)),d="mechanical"===r.mode,u=d?c({bins:a,branchProbability:r.branchProbability,count:r.mechanicalCount,pegRows:h,seed:l}):Array.isArray(e)?e:[],p=s({data:u,valueAccessor:r.valueAccessor||"value",bins:a,ballRadius:r.ballRadius??4,seed:l,size:n,valueExtent:d?[0,h]:void 0});return{...i,config:p.config,initialSpawns:ro(p.initialSpawns),projectionRows:p.projectionRows,bodyStyle:g(t||r.colorBy||(d?"side":void 0),"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(e,t,o,s,r)=>{const n=s.size??[600,400],a=i({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{...s,config:a.config,initialSpawns:ro(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||r.colorBy,"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.valueAccessor||r.timeAccessor||"time"})}}},PhysicsPileChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const r=i.size??[600,400],a="mechanical"===s.mode,c=a?l({categories:s.mechanicalCategories,count:s.mechanicalCount,seed:s.seed??1,unitValue:s.unitValue??1}):Array.isArray(e)?e:[],h=n({data:c,categoryAccessor:s.categoryAccessor||"category",valueAccessor:s.valueAccessor||(a?"value":void 0),unitValue:s.unitValue??1,ballRadius:s.ballRadius??5,seed:s.seed??1,size:r});return{...i,config:h.config,initialSpawns:ro(h.initialSpawns),projectionRows:h.projectionRows,bodyStyle:g(t||s.colorBy||(a?"category":void 0),"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(e,t,i,s,r)=>{const n=s.size??[600,360],a=o({data:Array.isArray(e)?e:[],xAccessor:r.xAccessor||"x",groupAccessor:r.groupAccessor,radiusAccessor:r.radiusAccessor,pointRadius:r.pointRadius??5,seed:r.seed??1,size:n,xExtent:r.xExtent,collisionIterations:r.collisionIterations,settle:r.settle});return{...s,config:a.config,initialSpawns:ro(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||r.colorBy||r.groupAccessor,"#4e79a7",{styleRules:r.styleRules,valueAccessor:r.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const r=i.size??[900,420],n=Array.isArray(s.stages)?s.stages:[],c=a({data:Array.isArray(e)?e:[],stages:n,size:r,idAccessor:s.idAccessor,stageAccessor:s.stageAccessor||"stage",groupBy:s.groupBy,groupLabelAccessor:s.groupLabelAccessor,workAccessor:s.workAccessor,radiusAccessor:s.radiusAccessor,ballRadius:s.ballRadius??6,seed:s.seed??1,groupCompletion:s.groupCompletion,groupAnchorAlong:s.groupAnchorAlong,settle:s.settle??!0,gravityX:s.gravityX,gravityY:s.gravityY}),l=c.metadata;return{...i,config:c.config,initialSpawns:ro(c.initialSpawns),projectionRows:c.projectionRows,regionEffects:l?.regionEffects,bodyStyle:g(t||s.colorBy||s.groupBy)}}},GauntletChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const r=i.size??[900,520],n=so({data:Array.isArray(e)?e:[],size:r,gates:s.gates,positiveProperties:s.positiveProperties,negativeProperties:s.negativeProperties,crashOffset:s.crashOffset,idAccessor:s.idAccessor,positiveAccessor:s.positiveAccessor,negativeAccessor:s.negativeAccessor,metricsAccessor:s.metricsAccessor,initialViability:s.initialViability,projectPlacement:s.projectPlacement,coreBody:s.coreBody,viability:s.viability});return{...i,config:n.config,initialSpawns:ro(n.initialSpawns),projectionRows:[],bodyStyle:g(t||s.colorBy)}}},PhysicalFlowChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const n=i.size??[760,420],a=r({nodes:Array.isArray(s.nodes)?s.nodes:[],links:Array.isArray(s.links)?s.links:Array.isArray(s.edges)?s.edges:Array.isArray(e)?e:[],nodeIdAccessor:s.nodeIdAccessor||"id",nodeXAccessor:s.nodeXAccessor||"x",nodeYAccessor:s.nodeYAccessor||"y",sourceAccessor:s.sourceAccessor||"source",targetAccessor:s.targetAccessor||"target",throughputAccessor:s.throughputAccessor||"value",pathAccessor:s.pathAccessor||"path",coordinateMode:s.coordinateMode||"auto",particleRate:s.particleRate??.16,maxParticles:s.maxParticles??180,particleRadius:s.particleRadius??4,flowSpeed:s.flowSpeed??90,pathConstraint:s.pathConstraint||"path",reducedMotion:!0,seed:s.seed??1,size:n});return{...i,config:a.config,initialSpawns:ro(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:g(t||s.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,o,i,s)=>{const r=i.size??[700,380],n=u({chartId:s.chartId,colorScheme:o,config:s.config,data:Array.isArray(e)?e:[],layout:s.layout,layoutConfig:s.layoutConfig,semantic:Ue(qe)??{},size:r,themeCategorical:qe.colors.categorical,xExtent:s.xExtent,yExtent:s.yExtent});return{...i,config:n.config,initialSpawns:ro(n.initialSpawns),projectionRows:[],bodyStyle:n.result.bodyStyle??g(t||s.colorBy)}}}};function ao(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function co(e){if(!e||2>e.length)return;const t=ao(e[0]),o=ao(e[e.length-1]);return null!==t&&null!==o?[t,o]:void 0}function lo(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,s=[...e.extraWarnings??[]];return i&&!s.includes("EMPTY_SCENE")&&s.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:s}}import*as ho from"react";import*as uo from"react-dom/server";import{scaleOrdinal as go}from"d3-scale";import{jsx as po,jsxs as fo}from"react/jsx-runtime";var yo=H;function mo(e,t,o){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>Se(e,t)??"#999"}const i=Array.isArray(t)?t:o.colors.categorical.length>0?o.colors.categorical:Ie;return go().domain(e).range(i)}function xo(e){return"left"===e?"start":"right"===e?"end":e??"start"}function bo(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function vo(e,t,o,i){const s=bo(i);return t+o+Math.ceil(e.length*s*.58)}function Ao(e){const{categories:t,theme:o,position:i="right",totalWidth:s,margin:r,legendLayout:n}=e,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:h}=ke(n),d=a+c,u="top"===i||"bottom"===i,g=Math.max(a,s-r.left-r.right),p=t.map(e=>vo(e,a,c,o));if(u){const e=Math.max(a,n?.maxWidth??g),o=[];let i=0,s=0;p.forEach((t,r)=>{const n=0===s?t:s+l+t;s>0&&n>e?(o.push({start:i,end:r,width:s}),i=r,s=t):s=n}),t.length>0&&o.push({start:i,end:t.length,width:s});const r=xo(n?.align),c=[];return o.forEach((o,i)=>{let s="center"===r?Math.max(0,(e-o.width)/2):"end"===r?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:s,y:i*h}),s+=p[e]+l}),{items:c,width:Math.max(0,...o.map(e=>e.width)),height:o.length*h,swatchSize:a,labelOffset:d,swatchRadius:0}}const f=Math.max(0,...p);return{items:t.map((e,t)=>({category:e,width:p[t],x:0,y:t*h})),width:f,height:t.length*h,swatchSize:a,labelOffset:d,swatchRadius:0}}function wo(e){const{legendGroups:t,theme:o,position:i="right",totalWidth:s,margin:r,legendLayout:n}=e,{swatchSize:a,labelGap:c,rowHeight:l}=ke(n),h=a+c,d=Math.max(12,bo(o)),u="top"===i||"bottom"===i,g=Math.max(a,s-r.left-r.right);if(u){const i=Math.max(a,n?.maxWidth??g),s=xo(n?.align);let r=0,c=0;const l=[];for(const s of t){const t=s.items.map(e=>e.label),h=Ao({...e,categories:t,legendLayout:{...n,maxWidth:Math.max(a,i-d-8),align:"start"}}),u=s.label?d:0,g=s.label?vo(s.label,0,0,o):0,p=u>0?u+8:0,f=p+h.width,y=Math.max(h.height,g);l.push({group:s,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:f,height:y,items:h.items}),r+=f+12,c=Math.max(c,y)}const u=l.length>0?r-12:0,p=u>i?0:"center"===s?Math.max(0,(i-u)/2):"end"===s?Math.max(0,i-u):0;return{groups:l.map(e=>({...e,x:e.x+p})),width:u,height:c,swatchSize:a,labelOffset:h,swatchRadius:0}}const p=de(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=>vo(e.label,a,c,o)),s=Math.max(0,...i,e.label?vo(e.label,0,0,o):0);return f=Math.max(f,s),{group:e,x:0,y:p[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:s,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:h,swatchRadius:0}}function So(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 ko(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 _o,jsxs as Mo}from"react/jsx-runtime";var Po=16;function To(e,t){return e.color||t.colors.annotation||t.colors.text}function Ro(e,t,o){const i=e.labelBackground,s=t.colors.background;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 Lo(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 zo(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 Co(e){const{annotations:t}=e;if(!t||0===t.length)return null;const o=e.autoPlaceAnnotations?Ce({annotations:t,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:{}}):t,i=[];for(let t=0;o.length>t;t++){const s=Fo(o[t],t,e);s&&i.push({node:s,annotation:o[t]})}const s=U(i);return s.length>0?_o("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:s}):null}function Fo(e,t,o){const{scales:i,layout:s,theme:r,xAccessor:n,yAccessor:a}=o;switch(e.type){case"y-threshold":{const n=e.value;if(null==n)return null;const a=To(e,r),c=e.label,l=e.labelPosition||"right",h=e.strokeDasharray||"6,4",d=e.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:Mo("g",{opacity:e.opacity,children:[_o("line",{x1:o,y1:0,x2:o,y2:s.height,stroke:a,strokeWidth:d,strokeDasharray:h}),c&&_o(V,{x:o+4,y:Po,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ro(e,r,"halo")})]},"ann-ythresh-"+t)}const u=i.y?i.y(n):i.r?i.r(n):null;return null==u?null:Mo("g",{children:[_o("line",{x1:0,y1:u,x2:s.width,y2:u,stroke:a,strokeWidth:d,strokeDasharray:h}),c&&_o(V,{x:"left"===l?4:"center"===l?s.width/2:s.width-4,y:20>u?Math.min(s.height-4,u+Po):u-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ro(e,r,"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=To(e,r),c=e.label,l=e.labelPosition||"top";return Mo("g",{opacity:e.opacity,children:[_o("line",{x1:n,y1:0,x2:n,y2:s.height,stroke:a,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),c&&_o(V,{x:n>.6*s.width?n-4:n+4,y:"bottom"===l?s.height-4:"center"===l?s.height/2:Po,textAnchor:n>.6*s.width?"end":"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:c,background:Ro(e,r,"halo")})]},"ann-xthresh-"+t)}case"band":{const o=null!=e.y0&&i.y?i.y(e.y0):null,n=null!=e.y1&&i.y?i.y(e.y1):null;if(null==o||null==n)return null;const a=Math.min(o,n),c=Math.abs(n-o),l=Re(e.fill||To(e,r),"ssr-band-"+t),h=e.fillOpacity??.1;return Mo("g",{opacity:e.opacity,children:[l.def&&_o("defs",{children:l.def}),_o("rect",{x:0,y:a,width:s.width,height:c,fill:l.fill,fillOpacity:h}),e.label&&_o(V,{x:s.width-4,y:Math.max(a,0)+Po,textAnchor:"end",fontSize:r.typography.tickSize,fill:e.color||To(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ro(e,r,"halo")})]},"ann-band-"+t)}case"x-band":{const o=null!=e.x0&&i.x?i.x(e.x0):null,n=null!=e.x1&&i.x?i.x(e.x1):null;if(null==o||null==n)return null;const a=Math.min(o,n),c=Math.abs(n-o),l=Re(e.fill||To(e,r),"ssr-xband-"+t),h=e.fillOpacity??.1;return Mo("g",{opacity:e.opacity,children:[l.def&&_o("defs",{children:l.def}),_o("rect",{x:a,y:0,width:c,height:s.height,fill:l.fill,fillOpacity:h}),e.label&&_o(V,{x:a+4,y:Po,textAnchor:"start",fontSize:r.typography.tickSize,fill:e.color||To(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ro(e,r,"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=To(e,r),l=e.opacity??.1,h=e.label;return Mo("g","horizontal"===o.projection?{children:[_o("rect",{x:0,y:n,width:s.width,height:a,fill:c,opacity:l}),h&&_o(V,{x:12,y:n+a/2,dominantBaseline:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:h,background:Ro(e,r,"none")})]}:{children:[_o("rect",{x:n,y:0,width:a,height:s.height,fill:c,opacity:l}),h&&_o(V,{x:n+a/2,y:Po,textAnchor:"middle",fill:c,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:h,background:Ro(e,r,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:s}=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:Lo(e,t,o),y:zo(e,t,i)}}(e,i,n,a);if(null==o||null==s)return null;const c="text"===e.type,l=e.dx??(c?0:30),h=e.dy??(c?0:-30),d=e.color||r.colors.text;if(!c){const i="callout"===e.type?"callout-circle":e.type,r="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return _o(Q,{noteData:{x:o,y:s,dx:l,dy:h,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:i,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:d,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return _o("g",{children:_o("text",{x:o+l,y:s+h,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||r.typography.labelSize,fill:d,fontFamily:r.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}import*as Bo from"react";import{jsx as Oo,jsxs as Eo}from"react/jsx-runtime";function jo(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function Do(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 No(e,t,o){const i=e.showLegend&&!e.__legendIncludesAutomatic?function(e,t,o){if(0===e.length)return;const i=mo(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 J(i,e.legend)}var Wo={right:110,left:110,top:50,bottom:80};function $o(e,t){if(e.__autoLegendMargin&&!Io(e,t))return Wo[t]}function Io(e,t){const o=e.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[t])}function Go(e,t){const{props:o,categories:i,theme:s,size:r,hasTitle:n}=t,a=o.legendPosition||"right",c={theme:s,position:a,size:r,hasTitle:n,legendLayout:o.legendLayout,minimumMargin:$o(o,a),preserveExplicitMargin:Io(o,a)};if(null!=o.legend){const t=No(o,i,s);(he(t)||le(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},s=he(t.legend)?function(e){const{width:t,height:o,swatchSize:i}=wo(e);return{width:t,height:o,swatchSize:i}}({...i,legendGroups:t.legend.legendGroups}):le(t.legend)?So({...i,gradient:t.legend.gradient}):null;if(!s)return;const r=t.minimumMargin??s.width+14,n=t.minimumMargin??(t.hasTitle?32:8)+s.height+4,a=t.minimumMargin??38+s.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,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}=Ao(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}),s=t.minimumMargin??i.width+14,r=t.minimumMargin??(t.hasTitle?32:8)+i.height+4,n=t.minimumMargin??38+i.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,r):e.bottom=Math.max(e.bottom,n)}(e,{...c,categories:i,colorScheme:o.colorScheme});return a}function Yo(e){const{props:t,categories:o,theme:i,size:s,margin:r,hasTitle:n}=e,a=t.legendPosition||"right",c={theme:i,position:a,size:s,margin:r,hasTitle:n,legendLayout:t.legendLayout,idPrefix:t._idPrefix,reservedWidth:t.__autoLegendMargin?100:void 0};if(null!=t.legend){const e=No(t,o,i);if(Bo.isValidElement(e))return e;const s=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 he(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=wo(e),i="top"===e.position||"bottom"===e.position,s=e.theme.colors.grid||e.theme.colors.textSecondary;let r,n;if("left"===e.position?(r=Math.max(4,e.margin.left-(e.reservedWidth??100)-10),n=e.margin.top):"top"===e.position?(r=e.margin.left,n=e.hasTitle?32:8):"bottom"===e.position?(r=e.margin.left,n=e.totalHeight-e.margin.bottom+38):(r=e.totalWidth-e.margin.right+10,n=e.margin.top),!i){const t=de(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(o.swatchSize,e.legendLayout?.rowHeight??yo)),i=e.legendGroups.flatMap((i,s)=>{const r=t[s],n=i.type??"fill",a=[po("line",{x1:0,y1:r.lineY,x2:e.reservedWidth??100,y2:r.lineY,stroke:"gray"},"legend-group-neatline-"+s)];return i.label&&null!=r.labelY&&a.push(po("text",{y:r.labelY,fontSize:bo(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.label},"legend-group-label-"+s)),a.push(po("g",{transform:`translate(0,${r.itemsY})`,children:i.items.map((t,r)=>{const a=i.styleFn(t,r),c="function"==typeof n?n(t):"line"===n?po("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:a}):po("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:a});return fo("g",{transform:`translate(0,${r*Math.max(o.swatchSize,e.legendLayout?.rowHeight??yo)})`,children:[c,po("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:bo(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${s}-${r}`)})},"legend-group-"+s)),a});return po("g",{className:"semiotic-legend",transform:`translate(${r},${n})`,"data-orientation":"vertical",children:i})}const a=o.groups.flatMap((t,r)=>{const{group:n}=t,a=n.type??"fill",c=[];if(n.label&&c.push(po("text",i?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:bo(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label}:{x:t.x,y:t.y+bo(e.theme),fontSize:bo(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label},"legend-group-label-"+r)),c.push(...t.items.map((i,s)=>{const c=n.items[s],l=n.styleFn(c,s),h="function"==typeof a?a(c):"line"===a?po("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):po("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return fo("g",{transform:`translate(${t.x+t.itemOffsetX+i.x},${t.y+t.itemOffsetY+i.y})`,children:[h,po("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:bo(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.category})]},`legend-${r}-${s}`)})),i&&o.groups.length-1>r){const e=t.x+t.width+6;c.push(po("line",{x1:e,y1:0,x2:e,y2:o.height,stroke:s},"legend-group-separator-"+r))}return c});return po("g",{className:"semiotic-legend",transform:`translate(${r},${n})`,"data-orientation":i?"horizontal":"vertical",children:a})}({...o,legendGroups:e.legendGroups}):le(e)?function(e){const t=So(e),o="top"===e.position||"bottom"===e.position,i=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=e.gradient.format||(e=>Math.round(100*e)/100+"");let r,n;"left"===e.position?(r=Math.max(4,e.margin.left-100-10),n=e.margin.top):"top"===e.position?(r=e.margin.left,n=e.hasTitle?32:8):"bottom"===e.position?(r=e.margin.left,n=e.totalHeight-e.margin.bottom+38):(r=e.totalWidth-e.margin.right+10,n=e.margin.top);const a=Array.from({length:17},(t,i)=>{const s=i/16;return po("stop",{offset:100*s+"%",stopColor:e.gradient.colorFn(o?e.gradient.domain[0]+s*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-s*(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 fo("g",{className:"semiotic-legend",transform:`translate(${r},${n})`,children:[po("defs",{children:po("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:a})}),e.gradient.label&&po("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}),po("rect",{x:0,y:l,width:t.width,height:o,fill:`url(#${i})`,rx:2}),po("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:s(e.gradient.domain[0])}),po("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:s(e.gradient.domain[1])})]})}const c=e.gradient.label?-6:void 0;return fo("g",{className:"semiotic-legend",transform:`translate(${r},${n+(e.gradient.label?12:0)})`,children:[po("defs",{children:po("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:a})}),e.gradient.label&&po("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}),po("rect",{x:0,y:0,width:14,height:100,fill:`url(#${i})`,rx:2}),po("text",{x:19,y:10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:s(e.gradient.domain[1])}),po("text",{x:19,y:100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:s(e.gradient.domain[0])})]})}({...o,gradient:e.gradient}):null}(e,c);return s||(he(e)||le(e)?null:e??null)}return t.showLegend&&0!==o.length?function(e){const{categories:t,colorScheme:o,theme:i,position:s="right",totalWidth:r,totalHeight:n,margin:a,hasTitle:c=!1}=e;if(!t||0===t.length)return null;const l=mo(t,o,i),h="top"===s||"bottom"===s,d=Ao(e);let u,g;if("left"===s?(u=Math.max(4,a.left-(e.reservedWidth??100)-10),g=a.top):"top"===s?(u=a.left,g=c?32:8):"bottom"===s?(u=a.left,g=n-a.bottom+38):(u=r-a.right+10,g=a.top),h){const e=d.items.map((e,t)=>fo("g",{transform:`translate(${e.x},${e.y})`,children:[po("rect",{width:d.swatchSize,height:d.swatchSize,fill:l(e.category),rx:d.swatchRadius}),po("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:bo(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return po("g",{className:"semiotic-legend",transform:`translate(${u},${g})`,children:e})}const p=de([{hasLabel:!1,itemCount:t.length}],Math.max(d.swatchSize,e.legendLayout?.rowHeight??yo))[0],f=d.items.map((e,t)=>fo("g",{transform:`translate(${e.x},${e.y+p.itemsY})`,children:[po("rect",{width:d.swatchSize,height:d.swatchSize,fill:l(e.category),rx:d.swatchRadius}),po("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:bo(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return fo("g",{className:"semiotic-legend",transform:`translate(${u},${g})`,children:[po("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:s[0],totalHeight:s[1],margin:r,hasTitle:n,legendLayout:t.legendLayout,reservedWidth:t.__autoLegendMargin?100:void 0,idPrefix:t._idPrefix}):null}function Vo(e){return Math.round(100*e)/100+""}function Xo(e,t){const o=st(t.theme),i=t.background??o.background,s=t.idPrefix?t.idPrefix+"-":"",r="string"==typeof t.title?t.title:void 0,n=r?s+"semiotic-title":void 0,a=t.description?s+"semiotic-desc":void 0,c=[n,a].filter(Boolean).join(" ")||void 0;return Eo("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:[r&&Oo("title",{id:n,children:r}),t.description&&Oo("desc",{id:a,children:t.description}),t.defs&&Oo("defs",{children:t.defs}),i&&"transparent"!==i&&Oo("rect",{x:0,y:0,width:t.width,height:t.height,fill:i}),Oo("g",{id:s+"data-area",transform:t.innerTransform,children:e}),r&&Oo("text",{id:s+"chart-title",x:t.width/2,y:Z,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:r}),t.legend&&Oo("g",{id:s+"legend",children:t.legend}),t.outerElements]})}import{Fragment as Ho,jsx as qo,jsxs as Qo}from"react/jsx-runtime";function Zo(e,t){const o=it(e.theme),i=e.size||[500,300],s=xe({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=ae(e.title),n=ie(e.data),a=e.showLegend?ko(n,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[];Go(s,{props:e,categories:a,theme:o,size:i,hasTitle:r});const c=i[0]-s.left-s.right,l=i[1]-s.top-s.bottom,h="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),d=e.colorScheme||o.colors.categorical,u={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:h?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:h?void 0:e.xAccessor,yAccessor:h?void 0:e.yAccessor,timeAccessor:h?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,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,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:d,themeCategorical:o.colors.categorical,themeSemantic:Ue(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:s,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},g=new w(u);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=lo({frameType:"xy",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:g.scales?[]:["NO_SCALES"]})),uo.renderToStaticMarkup(Xo(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(${s.left},${s.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const p=e._idPrefix,f=E({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>_e(e,t,p)});t&&(t.evidence=lo({frameType:"xy",width:i[0],height:i[1],marks:f.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:co(g.scales.x?.domain?.()),yDomain:co(g.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0}));const y=e.showGrid?function(e,t,o,i,s){const{grid:r}=st(o),n=i?i+"-":"",a="exact"===s?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),c="exact"===s?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),l=W(e.x,a,s),h=W(e.y,c,s);return Eo("g",{id:n+"grid",className:"semiotic-grid",opacity:.8,children:[l.map((o,i)=>{const s=e.x(o);return Oo("line",{x1:s,y1:0,x2:s,y2:t.height,stroke:r,strokeWidth:.5},"gx-"+i)}),h.map((o,i)=>{const s=e.y(o);return Oo("line",{x1:0,y1:s,x2:t.width,y2:s,stroke:r,strokeWidth:.5},"gy-"+i)})]})}(g.scales,{width:c,height:l},o,p,e.axisExtent):null,m=f.map(e=>e.element),x=Do(e)+"-plot-clip",b=!1!==e.showAxes?function(e,t,o,i,s){const r=st(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=W(e.x,n,o.axisExtent).map(t=>({pixel:e.x(t),label:(o.xFormat||o.tickFormatTime||Vo)(t)})),l=W(e.y,a,o.axisExtent).map(t=>({pixel:e.y(t),label:(o.yFormat||o.tickFormatValue||Vo)(t)}));return Eo("g",{id:(s?s+"-":"")+"axes",className:"stream-axes",children:[Oo("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:r.border,strokeWidth:1}),c.map((e,o)=>Eo("g",{transform:`translate(${e.pixel},${t.height})`,children:[Oo("line",{y2:5,stroke:r.border,strokeWidth:1}),Oo("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"xtick-"+o)),o.xLabel&&Oo("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:o.xLabel}),Oo("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:r.border,strokeWidth:1}),l.map((e,t)=>Eo("g",{transform:`translate(0,${e.pixel})`,children:[Oo("line",{x2:-5,stroke:r.border,strokeWidth:1}),Oo("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"ytick-"+t)),o.yLabel&&Oo("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.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?Co({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 qo(ho.Fragment,{children:e(g.scene,g.scales,{width:c,height:l})},"pre-"+t)}catch{return null}}).filter(Boolean):null,S=Yo({props:e,categories:a,theme:o,size:i,margin:s,hasTitle:r});return uo.renderToStaticMarkup(Xo(Qo(Ho,{children:[e.backgroundGraphics,A,y,qo("defs",{children:qo("clipPath",{id:x,children:qo("rect",{x:0,y:0,width:c,height:l})})}),qo("g",{clipPath:`url(#${x})`,children:m}),b,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(${s.left},${s.top})`,innerWidth:c,innerHeight:l,legend:S,idPrefix:e._idPrefix}))}import*as Uo from"react-dom/server";import{scaleBand as Ko,scaleLinear as Jo}from"d3-scale";var ei=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||q,s=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,s),s}};function ti(e){const t=e.getSymbol;if(!t)return null;const o=e.config.symbolMap,i=new Map;let s=0;return e=>{const r=t(e)+"",n=o?.[r];if(n)return n;let a=i.get(r);return a||(a=Le[s%Le.length],s++,i.set(r,a)),a}}function oi(e,t,o,i,s,r,n){e.push(t?{type:"symbol",x:i,y:s,size:Math.PI*r*r,symbolType:t(o),style:n,datum:o}:{type:"point",x:i,y:s,r:r,style:n,datum:o})}function ii(e,t){const{columns:o,config:i,resolvePieceStyle:s}=e,r=[],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,h=null!=i.sweepAngle&&360>i.sweepAngle,d=Object.values(o),u=d.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),g=h&&!u&&d.length>1&&(i.cornerRadius??0)>0;for(let e=0;d.length>e;e++){const t=d[e],o=t.pieceData[0],h="number"==typeof o?._pctStart?o._pctStart:t.pctStart,u=c+h*l,p=c+(h+("number"==typeof o?._pct?o._pct:t.pct))*l,f=s(t.pieceData[0],t.name),y=0===e,m=e===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:n,startAngle:u,endAngle:p,...i.cornerRadius&&{cornerRadius:i.cornerRadius},style:f,datum:o?._nonInteractive?null:t.pieceData,category:t.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:g&&(x.roundedEnds={start:y,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as si}from"d3-array";function ri(e){const t=e.length,o=e[0],i=e[t-1];return{n:t,min:o,q1:si(e,.25)??o,median:si(e,.5)??(o+i)/2,q3:si(e,.75)??i,max:i,mean:e.reduce((e,t)=>e+t,0)/t}}import{scaleLinear as ni}from"d3-scale";var ai={bar:function(e,t){const{scales:o,columns:i,config:s,getR:r,getStack:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,h=[],d="vertical"===l,u="horizontal"===l,g=s.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+=r(o),i.pieces.push(o)}let o=0;if(g)for(const e of t.values())o+=Math.abs(e.total);let i=0,s=0;for(const r of p){const l=t.get(r);if(!l)continue;let p=l.total;g&&o>0&&(p/=o);const f=a(l.pieces[0],n?r:e.name),y={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:e.name};if(d){const t=c(0>p?s:i+p),o=0>p?c(s+p)-c(s):c(i)-c(i+p);h.push(_(e.x,t,e.width,Math.abs(o),f,y,r)),0>p?s+=p:i+=p}else if(u){const t=c(0>p?s+p:i),o=0>p?c(s)-c(s+p):c(i+p)-c(i);h.push(_(t,e.x,Math.abs(o),e.width,f,y,r)),0>p?s+=p:i+=p}}}const f="vertical"===l,y=s.roundedTop&&s.roundedTop>0?Math.max(0,s.roundedTop):0;for(const e of h){if("rect"!==e.type)continue;const t=e.datum?.__aggregateValue??0;e.roundedEdge=f?0>t?"bottom":"top":0>t?"left":"right",s.gradientFill&&(e.fillGradient=s.gradientFill)}if(y>0){const e=new Map;for(const t of h){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 h},clusterbar:function(e,t){const{scales:o,columns:i,config:s,getR:r,getGroup:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,h=[],d="vertical"===l,u=[],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),u.push(e))}const p=u.length||1;for(const e of Object.values(i)){const t=e.width/p,o=.2*t,i=t-o,s=new Map;for(const t of e.pieceData){const e=n?n(t):"_default";s.has(e)||s.set(e,[]),s.get(e).push(t)}for(let n=0;u.length>n;n++){const l=s.get(u[n])||[];for(const s of l){const l=r(s),g=a(s,u[n]);if(d){const r=e.x+n*t+o/2,a=c(0),d=c(l);h.push(_(r,Math.min(a,d),i,Math.abs(a-d),g,s,u[n]))}else{const r=e.x+n*t+o/2,a=c(0),d=c(l);h.push(_(Math.min(a,d),r,Math.abs(d-a),i,g,s,u[n]))}}}}const f=s.roundedTop&&s.roundedTop>0?Math.max(0,s.roundedTop):0;for(const e of h){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=r(e.datum);f>0&&(e.roundedTop=f),e.roundedEdge=d?0>t?"bottom":"top":0>t?"left":"right",s.gradientFill&&(e.fillGradient=s.gradientFill)}return h},point:function(e,t){const{scales:o,columns:i,getR:s,multiScales:r,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],h="vertical"===c,d="radial"===c,u=r.length>0,g=ti(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??s(t),c=u&&r[o]||a,y=n(t,e.name),m=y.r||5;let x,b;if(d){const t=f+(e.pctStart+e.pct/2)*p,o=c(i);x=Math.cos(t)*o,b=Math.sin(t)*o}else h?(x=e.middle,b=c(i)):(x=c(i),b=e.middle);oi(l,g,t,x,b,m,y)}return l},swarm:function(e,t){const{scales:o,columns:i,getR:s,resolvePieceStyle:r}=e,{r:n,projection:a}=o,c=[],l="vertical"===a,h=ti(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=s(i),d=r(i,e.name),u=d.r||4,g=(7919*o%100/100-.5)*t*.8;oi(c,h,i,l?e.middle+g:n(a),l?n(a):e.middle+g,u,d)}}return c},pie:ii,donut:ii,boxplot:function(e,t){const{scales:o,columns:i,config:s,getR:r,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],h="vertical"===c,d=!1!==s.showOutliers;for(const t of Object.values(i)){const o=t.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===o.length)continue;const i=o[0],s=o[o.length-1],c=si(o,.25)??i,u=si(o,.5)??(i+s)/2,g=si(o,.75)??s,p=g-c,f=c-1.5*p,y=g+1.5*p,m=o.find(e=>e>=f)??i,x=[...o].reverse().find(e=>y>=e)??s,b=n(t.pieceData[0],t.name),v=[];if(d)for(const e of t.pieceData){const o=r(e);if(f>o||o>y){const i=h?t.middle:a(o),s=h?a(o):t.middle;v.push({px:i,py:s,value:o,datum:e})}}if(l.push({type:"boxplot",x:h?t.middle:0,y:h?0:t.middle,projection:h?"vertical":"horizontal",columnWidth:.6*t.width,minPos:a(m),q1Pos:a(c),medianPos:a(u),q3Pos:a(g),maxPos:a(x),stats:{n:o.length,min:m,q1:c,median:u,q3:g,max:x,mean:o.reduce((e,t)=>e+t,0)/o.length},style:b,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:b.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6},datum:t.datum})}return l},violin:function(e,t){const{scales:o,columns:i,config:s,getR:r,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],h="vertical"===c,d=s.bins||20,u=!1!==s.showIQR;for(const e of Object.values(i)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],s=(i-o)/d||1,c=Array(d).fill(0);for(const e of t)c[Math.min(Math.floor((e-o)/s),d-1)]++;const g=Ge(c,1),p=e.width/2*.9;let f;if(h){f=`M ${e.middle} ${a(o)}`;for(let t=0;d>t;t++){const i=a(o+(t+.5)*s);f+=` L ${e.middle+c[t]/g*p} ${i}`}f+=` L ${e.middle} ${a(i)}`;for(let t=d-1;t>=0;t--){const i=a(o+(t+.5)*s);f+=` L ${e.middle-c[t]/g*p} ${i}`}f+=" Z"}else{f=`M ${a(o)} ${e.middle}`;for(let t=0;d>t;t++)f+=` L ${a(o+(t+.5)*s)} ${e.middle-c[t]/g*p}`;f+=` L ${a(i)} ${e.middle}`;for(let t=d-1;t>=0;t--)f+=` L ${a(o+(t+.5)*s)} ${e.middle+c[t]/g*p}`;f+=" Z"}const y=n(e.pieceData[0],e.name);let m;if(u&&t.length>=4){const s=si(t,.25)??o,r=si(t,.5)??(o+i)/2,n=si(t,.75)??i;m={q1Pos:a(s),medianPos:a(r),q3Pos:a(n),centerPos:e.middle,isVertical:h}}const x=h?{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:x,iqrLine:m,stats:ri(t),style:y,datum:e.pieceData,category:e.name})}return l},histogram:function(e,t){const{scales:o,columns:i,config:s,getR:r,resolveSummaryStyle:n}=e,{r:a}=o,c=[],l=s.bins||25,h=s.normalize,d=a.domain?.(),u=d?+d[0]:void 0,g=d?+d[1]:void 0;for(const e of Object.values(i)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;const[o,i]=Ve(t),s=null!=u&&isFinite(u)?u:o,d=null!=g&&isFinite(g)?g:i,p=(d-s)/l||1,f=Array(l).fill(0);for(const e of t)s>e||e>d||f[Math.min(Math.floor((e-s)/p),l-1)]++;const y=t.length,m=Ge(f,1),x=n(e.pieceData[0],e.name);for(let t=0;l>t;t++){if(0===f[t])continue;const o=(h?f[t]/y:f[t]/m)*e.width*.9,i=a(s+t*p),r=a(s+(t+1)*p);c.push(_(Math.min(i,r),e.x+e.width-o,Math.abs(r-i),o,x,{bin:t,count:f[t],range:[s+t*p,s+(t+1)*p],category:e.name},e.name))}}return c},ridgeline:function(e,t){const{scales:o,columns:i,config:s,getR:r,resolveSummaryStyle:n}=e,{r:a,projection:c}=o,l=[],h=s.bins||20,d="horizontal"===c,u=s.amplitude||1.5;for(const e of Object.values(i)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],i=t[t.length-1],s=(i-o)/h||1,c=Array(h).fill(0);for(const e of t)o>e||e>i||c[Math.min(Math.floor((e-o)/s),h-1)]++;const g=Ge(c,1),p=n(e.pieceData[0],e.name),f=e.width*u;let y;if(d){const t=e.x+e.width;y=`M ${a(o)} ${t}`;for(let e=0;h>e;e++)y+=` L ${a(o+(e+.5)*s)} ${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;h>e;e++){const i=a(o+(e+.5)*s);y+=` L ${t+c[e]/g*f} ${i}`}y+=` L ${t} ${a(i)} Z`}const m=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:y,translateX:0,translateY:0,bounds:m,stats:ri(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:s,resolvePieceStyle:r}=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=s(t);if(!o)continue;const[i,a]=o,h=r(t,e.name);if(l){const o=n(Math.min(i,a)),s=n(Math.max(i,a));c.push(_(o,e.x,s-o,e.width,h,t,e.name))}else{const o=n(Math.max(i,a)),s=n(Math.min(i,a));c.push(_(e.x,o,e.width,s-o,h,t,e.name))}}return c},funnel:function(e,t){const{columns:o,getR:i,getStack:s,resolvePieceStyle:r}=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 h=[],d=new Set;for(const e of l)for(const t of e.pieceData){const e=s?s(t):"_default";d.has(e)||(d.add(e),h.push(e))}const u=h.length>1&&"_default"!==h[0],g=[];let p=0;for(const e of l){const t=new Map;let o=0;for(const r of e.pieceData){const e=s?s(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(r);n.total+=a,n.pieces.push(r),o+=a}g.push({col:e,groups:t,stepTotal:o}),u||o>p&&(p=o)}if(u)for(const e of g){let t=0,o=0;for(let i=0;h.length>i;i++){const s=e.groups.get(h[i]);s&&(i%2==0?t+=s.total:o+=s.total)}const i=Math.max(t,o);i>p&&(p=i)}if(0===p)return n;const f=new Map;for(const e of h){const t=g[0].groups.get(e);f.set(e,t?.total??0)}const y=g[0].stepTotal,m=u?.95*a:.9*t.width,x=ni().domain([0,p]).range([0,m]),b=e.config.connectorOpacity??.3;let v=new Map;for(let t=0;g.length>t;t++){const o=g[t],i=o.col,s=0===t,l=i.width,d=.55*l,p=i.x+(l-d)/2,m=new Map;if(u){let e=0;for(const t of h){const i=o.groups.get(t);i&&(e+=x(i.total))}let t=a,l=a;for(let u=0;h.length>u;u++){const g=h[u],y=o.groups.get(g);if(!y)continue;const b=x(y.total),v=u%2==0,A=v?t:l-b;v?t+=b:l-=b;const w=r(y.pieces[0],g),S=f.get(g)??y.total,k={...y.pieces[0],__funnelValue:y.total,__funnelPercent:S>0?y.total/S*100:0,__funnelStep:i.name,__funnelIsFirstStep:s,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:g};c&&(0===u&&(k.__funnelStepLabel=i.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e),k.__funnelValueLabelX=A+b/2,k.__funnelValueLabelY=p,k.__funnelBarW=b),n.push(_(A,p,b,d,w,k,g)),m.set(g,{x:A,y:p,w:b,h:d})}}else{const e=o.stepTotal,t=x(e),l=a-t/2,u=h[0],g="_default"!==u,f=o.groups.get(u)?.pieces[0]??i.pieceData[0],b=g?u:i.name,v=r(f,b),A=y>0?e/y*100:0,w={...f,__funnelValue:e,__funnelPercent:A,__funnelStep:i.name,__funnelIsFirstStep:s,category:g?u:i.name};c&&(w.__funnelStepLabel=i.name,w.__funnelStepLabelX=a,w.__funnelStepLabelY=p,w.__funnelRowWidth=t,w.__funnelValueLabelX=a,w.__funnelValueLabelY=p,w.__funnelBarW=t),n.push(_(l,p,t,d,v,w,b)),m.set(u,{x:l,y:p,w:t,h:d})}if(t>0&&v.size>0){const t=u?h:[h[0]];for(const s of t){const t=v.get(s),a=m.get(s);if(!t||!a)continue;const c=(()=>{const e=o.groups.get(s);return r(e?e.pieces[0]:i.pieceData[0],"_default"===s?i.name:s)})(),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:b},datum:o.groups.get(s)?.pieces[0]??i.pieceData[0],category:"_default"===s?i.name:s};n.push(l)}}v=m}return n},"bar-funnel":function(e,t){const{columns:o,getR:i,getStack:s,resolvePieceStyle:r,scales:n}=e,a=[],c=n.o.domain().map(e=>o[e]).filter(Boolean);if(0===c.length)return a;const l=[],h=new Set;for(const e of c)for(const t of e.pieceData){const e=s?s(t):"_default";h.has(e)||(h.add(e),l.push(e))}const d=l.length>1&&"_default"!==l[0],u=[];for(const e of c){const t=new Map;let o=0;for(const r of e.pieceData){const e=s?s(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e),a=i(r);n.total+=a,n.pieces.push(r),o+=a}u.push({col:e,groups:t,stepTotal:o})}const g=new Map;for(const e of l){const t=u[0]?.groups.get(e);g.set(e,t?.total??0)}const p=n.r,f=d?l.length:1,y=d?.15:0;for(let e=0;u.length>e;e++){const t=u[e],o=t.col,i=0===e,s=e>0?u[e-1]:null,n=o.width/f,c=n*y,h=n-c;for(let e=0;l.length>e;e++){const u=l[e],f=t.groups.get(u);if(!f)continue;const y=f.total,m=g.get(u)??y,x=m>0?y/m*100:0,b=s?.groups.get(u),v=i?0:Math.max(0,(b?.total??y)-y),A=o.x+e*n+c/2,w=p(y),S=p(0)-w,k=r(f.pieces[0],d?u:o.name),M={...f.pieces[0],__barFunnelValue:y,__barFunnelPercent:x,__barFunnelIsFirstStep:i,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===u?void 0:u,category:d?u:o.name,__barFunnelLabelX:A+h/2,__barFunnelLabelY:p(y+v)};if(a.push(_(A,w,h,S,k,M,d?u:o.name)),v>0){const e=p(y+v),t=w-e,i={...k},s={...f.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===u?void 0:u,category:d?u:o.name};a.push(_(A,e,h,t,i,s,d?u:o.name))}}}return a},swimlane:function(e,t){const{scales:o,columns:i,getR:s,getStack:r,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],h="horizontal"===c,d=e.config.gradientFill,u=h?"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,s]=a.range(),r=Math.min(o,s),n=Math.abs(s-o);for(const o of Object.values(i)){const i={fill:e,opacity:t},s=h?_(r,o.x,n,o.width,i,null,"__track__"):_(o.x,r,o.width,n,i,null,"__track__");l.push(s)}}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(s(o));if(0===i)continue;const c=r?r(o):e.name,g=n(o,c);let p;if(h){const s=a(t),r=a(t+i);p=_(s,e.x,r-s,e.width,g,o,c)}else{const s=a(t+i),r=a(t);p=_(e.x,s,e.width,r-s,g,o,c)}d&&(p.fillGradient=d,p.roundedEdge=u),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}:h?(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}},ci=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],li=["scene-style","data-paint","accessibility","evidence"],hi=(e,t)=>({retainedData:e,invalidations:t}),di=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ui=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],gi=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],pi=["scene-geometry","data-paint","accessibility","evidence"],fi=["scene-style","data-paint","accessibility","evidence"],yi=[],mi={chartType:hi("rebuild",di),runtimeMode:hi("rebuild",di),categoryAccessor:hi("rebuild",di),valueAccessor:hi("rebuild",di),oAccessor:hi("rebuild",di),rAccessor:hi("rebuild",di),stackBy:hi("rebuild",di),groupBy:hi("rebuild",di),timeAccessor:hi("rebuild",di),accessorRevision:hi("rebuild",di),colorAccessor:hi("rebuild",fi),symbolAccessor:hi("rebuild",pi),connectorAccessor:hi("rebuild",pi),dataIdAccessor:hi("rebuild",pi),projection:hi("preserve",ui),extentPadding:hi("preserve",ui),axisExtent:hi("preserve",ui),rExtent:hi("preserve",ui),oExtent:hi("preserve",ui),multiAxis:hi("preserve",ui),normalize:hi("preserve",ui),bins:hi("preserve",ui),oSort:hi("preserve",gi),barPadding:hi("preserve",gi),roundedTop:hi("preserve",gi),baselinePadding:hi("preserve",gi),innerRadius:hi("preserve",gi),cornerRadius:hi("preserve",gi),startAngle:hi("preserve",gi),sweepAngle:hi("preserve",gi),trackFill:hi("preserve",gi),showOutliers:hi("preserve",gi),showIQR:hi("preserve",gi),amplitude:hi("preserve",gi),connectorOpacity:hi("preserve",gi),showLabels:hi("preserve",gi),dynamicColumnWidth:hi("rebuild",gi),customLayout:hi("preserve",gi),layoutConfig:hi("preserve",gi),layoutMargin:hi("preserve",gi),symbolMap:hi("preserve",pi),pieceStyle:hi("preserve",fi),summaryStyle:hi("preserve",fi),connectorStyle:hi("preserve",fi),gradientFill:hi("preserve",fi),colorScheme:hi("preserve",fi),themeCategorical:hi("preserve",fi),themeSemantic:hi("preserve",fi),themeSequential:hi("preserve",fi),themeDiverging:hi("preserve",fi),barColors:hi("preserve",fi),decay:hi("preserve",fi),pulse:hi("preserve",fi),staleness:hi("preserve",fi),layoutSelection:hi("preserve",fi),windowSize:hi("preserve",yi),windowMode:hi("preserve",yi),clock:hi("preserve",yi),transition:hi("preserve",yi),introAnimation:hi("preserve",yi),onLayoutError:hi("preserve",yi)},xi=hi("preserve",gi),bi=class{constructor(){this.tracker=new ze}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}},ci)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},li):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const o=new Set;for(const i of e){const e=mi[i]??xi;"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 vi}from"d3-quadtree";var Ai=class{constructor(e){this.rExtent=new G,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new bi,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new ei,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 Y(e.windowSize),this.getO=Te(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>Pe(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new G)):(this.getR=Pe(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Te(e.stackBy),this.getGroup=Te(e.groupBy),this.getColor=Te(e.colorAccessor),this.getSymbol=Te(e.symbolAccessor),this.getConnector=Te(e.connectorAccessor),this.getDataId=Te(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new Y(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:z(t,i):null)}currentTime(){return this.config.clock?.()??ye()}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(),C(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const o of e.inserts)O(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=O(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,s=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const n=this.getBufferArray(),a=t.projection||"vertical",c=t.oExtent||this.resolveCategories(n),l=this.computeValueDomain(n,c),h="horizontal"===a,d="radial"===a,u=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===a?e.width:e.height):.1));let g,p;if(d){g=Ko().domain(c).range([0,1]).padding(0);const o=Math.min(e.width,e.height)/2,i=t.innerRadius||0;p=Jo().domain(l).range([i,o])}else h?(g=Ko().domain(c).range([0,e.height]).padding(u),p=Jo().domain(l).range([0,e.width])):(g=Ko().domain(c).range([0,e.width]).padding(u),p=Jo().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,s)=>{const r=this.rExtents[s];r.dirty&&r.recalculate(o,i);let[n,a]=r.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),h?Jo().domain([n,a]).range([0,e.width]):Jo().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=s,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,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 s=null;if(o){s=new Set;for(const t of e)s.add(this.getO(t))}const r=s?Array.from(this.categories).filter(e=>s.has(e)):Array.from(this.categories);if(o&&void 0===i){const e=Math.max(50,3*s.size);if(this.categories.size>e){let t=this.categories.size-e;for(const e of this.categories){if(0>=t)break;s.has(e)||(this.categories.delete(e),t--)}}return r}if(!1===i)return r;if("function"==typeof i)return r.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 r.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:s,rExtent:r,extentPadding:n=.05,baselinePadding:a,axisExtent:c,getO:l,getR:h,getStack:d,rawRExtent:u}=e,g=n;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let p=0,f=0;if("bar"===o&&d&&s)p=0,f=1;else if("bar"===o&&d){const e=new Map,o=new Map;for(const i of t){const t=l(i),s=h(i);0>s?o.set(t,(o.get(t)||0)+s):e.set(t,(e.get(t)||0)+s)}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=h(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(h(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=h(e);t>f&&(f=t),p>t&&(p=t)}else{const e=u[0],t=u[1];e!==1/0&&(p=e),t!==-1/0&&(f=t)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(f=r[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==r?.[0]&&null==r?.[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,s=y&&!a&&0===f||"swimlane"===o;null!=r?.[0]||i||(p-=t),null!=r?.[1]||s||(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,s){return function(e){const{data:t,oExtent:o,oScale:i,projection:s,layout:r,dynamicColumnWidth:n,getO:a,getR:c}=e,l={},h=new Map;for(const e of t){const t=a(e);h.has(t)||h.set(t,[]),h.get(t).push(e)}let d=0;if("radial"===s)for(const e of t)d+=Math.abs(c(e));let u=null;if(n&&"radial"!==s){u=new Map;let e=0;for(const t of o){const o=h.get(t)||[];let i;i="string"==typeof n?o.reduce((e,t)=>e+(Number(t[n])||0),0):n(o),u.set(t,i),e+=i}const t=("horizontal"===s?r.height:r.width)-i.padding()*i.step()*o.length;if(e>0)for(const[o,i]of u)u.set(o,i/e*t)}let g=0,p=0;for(const e of o){const t=h.get(e)||[],o=t.reduce((e,t)=>e+Math.abs(c(t)),0),s=d>0?o/d:0;let r,n;u?(r=p,n=u.get(e)||i.bandwidth(),p+=n+i.padding()*i.step()):(r=i(e)??0,n=i.bandwidth()),l[e]={name:e,x:r,y:0,width:n,middle:r+n/2,padding:i.padding()*i.step(),pieceData:t,pct:s,pctStart:g},g+=s}return l}({data:e,oExtent:t,oScale:o,projection:i,layout:s,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=L("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 s=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const e of s)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(s,this.config.layoutSelection??null)}return I({label:"ordinal customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),i=ai[this.config.chartType];let s=i?i(o,t):[];if(this.getConnector&&this.scales){const e=function(e,t){const{scales:o,config:i,getConnector:s,getO:r}=e;if(!s||!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=s(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:r(t)})}const l=o.o.domain(),h=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 s=o[i],r=o[i+1],a="function"==typeof h?h(s.datum):h||{stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};n.push({type:"connector",x1:s.x,y1:s.y,x2:r.x,y2:r.y,style:a,datum:s.datum,group:t})}}return n}(o,s);s=[...e,...s]}return s}buildLayoutContext(e,t){const o=this.config,i=o.layoutMargin??{top:0,right:0,bottom:0,left:0},s=Ae(o.colorScheme,o.themeCategorical,q),r=this.scales;return{data:e,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:t.width,height:t.height,margin:i,plot:"radial"===r.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:[...s]},resolveColor:K(s,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(e,t){const o=this.config.decay;return o&&t>1?T(o,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const t=k(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",s=new Map;for(let r=0;e.length>r;r++){const n=e[r],a=o?t(n):n[i],c=s.get(a);c?c.push(r):s.set(a,[r])}return s}(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 s=0;for(const t of e)"point"===t.type&&(i[s++]=t);return{maxRadius:o,quadtree:vi().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 s=this.computeDecayOpacity(e,o);t.style={...t.style,opacity:(t.style?.opacity??1)*s}}}applyPulse(e,t,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,o,i,s,r){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 s(t)??[]){const t=o.get(n);null!=t&&(i=Math.max(i,R(e,t,r)))}c=N(l,i,n)||c;continue}if(null==l.datum)continue;const t=i.get(l.datum);if(null==t)continue;const h=o.get(t),d=null==h?0:R(e,h,r);c=N(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&&B(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 s=0;this.scene.length>s;s++){const r=this.scene[s],n=this.getNodeKey(r,e);n&&("rect"===r.type?this.prevPositionMap.set(n,o?{x:r.x,y:t,w:r.w,h:0,opacity:r.style.opacity??1}:{x:t,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===i&&(i=r.startAngle),this.prevPositionMap.set(n,{x:r.cx,y:r.cy,startAngle:i,endAngle:i,innerRadius:r.innerRadius,outerRadius:r.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 s=this.scene[e],r=this.getNodeKey(s,i);if(!r)continue;s._transitionKey=r;const n=this.prevPositionMap.get(r);if("point"===s.type)n?(o.add(r),s._targetOpacity=s.style.opacity??1,(n.x!==s.x||n.y!==s.y||void 0!==n.r&&n.r!==s.r)&&(s._targetX=s.x,s._targetY=s.y,s._targetR=s.r,s.x=n.x,s.y=n.y,void 0!==n.r&&(s.r=n.r),t=!0)):(s._targetOpacity=s.style.opacity??1,s._targetR=s.r,s.r=0,s.style={...s.style,opacity:0},t=!0);else if("rect"===s.type)n?(o.add(r),s._targetOpacity=s.style.opacity??1,n.x===s.x&&n.y===s.y&&n.w===s.w&&n.h===s.h||(s._targetX=s.x,s._targetY=s.y,s._targetW=s.w,s._targetH=s.h,s.x=n.x,s.y=n.y,s.w=n.w??s.w,s.h=n.h??s.h,t=!0)):(s._targetOpacity=s.style.opacity??1,s.style={...s.style,opacity:0},t=!0);else if("wedge"===s.type)if(n)o.add(r),s._targetOpacity=s.style.opacity??1,n.startAngle===s.startAngle&&n.endAngle===s.endAngle||(s._targetStartAngle=s.startAngle,s._targetEndAngle=s.endAngle,s.startAngle=n.startAngle,s.endAngle=n.endAngle,t=!0);else{s._targetOpacity=s.style.opacity??1,s._targetStartAngle=s.startAngle,s._targetEndAngle=s.endAngle;const e=s.startAngle;s.startAngle=e,s.endAngle=e,s.style={...s.style,opacity:0},this.prevPositionMap.set(r,{x:s.cx,y:s.cy,startAngle:e,endAngle:e,innerRadius:s.innerRadius,outerRadius:s.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=te(e,this.activeTransition),o=ee(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=ue(i?i.opacity??1:0,e._targetOpacity,o)}const i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=ue(i.x,e._targetX,o),e.y=ue(i.y,e._targetY,o)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=ue(i.r,e._targetR,o))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=ue(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=ue(i.x,e._targetX,o),e.y=ue(i.y,e._targetY,o),void 0!==i.w&&(e.w=ue(i.w,e._targetW,o),e.h=ue(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:ue(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=ue(i.startAngle,e._targetStartAngle,o),e.endAngle=ue(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=$(e),o=this.getDataId,i=e=>t.has(o(e));P(this.buffer,this.timestampBuffer,i);const s=this.buffer.remove(i);if(0===s.length)return this.updateResults.recordNoop("remove"),s;for(const e of s)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",s.length),s}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=$(e),i=this.getDataId,s=new Set;this.buffer.forEach((e,t)=>{o.has(i(e))&&s.add(t)});const r=this.buffer.update(e=>o.has(i(e)),t);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const e of r)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),s.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){const o=this._customRestyle;if(o)for(const i of e){const e=this._baseStyles.get(i)??i.style??{},s=o(i,t);i.style=s?{...e,...s}: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&&!Me(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!Me(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!Me(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)&&(Me(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=Te(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let s=!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],r=Array.isArray(o)?o:[o];if(s=i.length!==r.length||i.some((e,t)=>!Me(e,r[t])),s){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>Pe(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new G)):(this.getR=Pe(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!Me(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?Te(this.config.stackBy):void 0),"groupBy"in e&&!Me(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?Te(this.config.groupBy):void 0),"colorAccessor"in e&&!Me(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Te(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!Me(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Te(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!Me(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Te(this.config.connectorAccessor):void 0),(i||s||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};S(Ai);import{jsx as wi,jsxs as Si}from"react/jsx-runtime";import{Fragment as ki,jsx as _i,jsxs as Mi}from"react/jsx-runtime";function Pi(e,t){const o=it(e.theme),i=e.size||[500,400],s=xe({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=ae(e.title),n=ie(e.data),a=e.showLegend?ko(n,e.colorAccessor||e.stackBy||e.groupBy):[];Go(s,{props:e,categories:a,theme:o,size:i,hasTitle:r});const c=i[0]-s.left-s.right,l=i[1]-s.top-s.bottom,h=e.projection||"vertical",d="radial"===h,u={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:h,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill: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:Ue(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:s,layoutSelection:e.layoutSelection,barColors:e.barColors},g=new Ai(u);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=lo({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:g.scales?[]:["NO_SCALES"]})),Uo.renderToStaticMarkup(Xo(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(${s.left},${s.top})`,innerWidth:c,innerHeight:l,idPrefix:e._idPrefix}));const p=e._idPrefix,f=e.showGrid?function(e,t,o,i,s){const r=e.scales;if(!r||"radial"===r.projection)return null;const{grid:n}=st(o),a=i?i+"-":"",c="vertical"===r.projection,l=W(r.r,5,s);return Oo("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=r.r(e);return Oo("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=r.r(e);return Oo("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=Do(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:s=1.5,spacing:r=6,angle:n=45}=e,a=Math.max(8,Math.ceil(2*r));return Si("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[o&&"transparent"!==o&&wi("rect",{width:a,height:a,fill:o}),wi("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:s}),wi("line",{x1:r,y1:0,x2:r,y2:a,stroke:i,strokeWidth:s})]},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 s=new Map;Array.from(i).forEach((e,o)=>s.set(e,`funnel-hatch-${t}-${o}`));for(const e of g.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${s.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}const m=E({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>me(e,t,p)}),x=m.map(e=>e.element);if(t){const o=g.scales.o?.domain?.();t.evidence=lo({frameType:"ordinal",width:i[0],height:i[1],marks:m.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:co(g.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0})}const b=!1!==e.showAxes?function(e,t,o,i,s){const r=e.scales;if(!r)return null;if("radial"===r.projection)return null;const n=st(i),a="vertical"===r.projection,c=o.categoryFormat||o.oFormat,l=o.valueFormat||o.rFormat,h=o.categoryLabel||o.oLabel,d=o.valueLabel||o.rLabel,u=Object.values(e.columns).map(e=>({pixel:e.middle,label:(c||String)(e.name)})),g=W(r.r,5,o.axisExtent).map(e=>({pixel:r.r(e),label:(l||Vo)(e)}));return Mi("g",a?{id:(s?s+"-":"")+"axes",className:"ordinal-axes",children:[_i("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),u.map((e,o)=>Mi("g",{transform:`translate(${e.pixel},${t.height})`,children:[_i("line",{y2:5,stroke:n.border,strokeWidth:1}),_i("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),h&&_i("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:h}),_i("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),g.map((e,t)=>Mi("g",{transform:`translate(0,${e.pixel})`,children:[_i("line",{x2:-5,stroke:n.border,strokeWidth:1}),_i("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),d&&_i("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:(s?s+"-":"")+"axes",className:"ordinal-axes",children:[_i("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),g.map((e,o)=>Mi("g",{transform:`translate(${e.pixel},${t.height})`,children:[_i("line",{y2:5,stroke:n.border,strokeWidth:1}),_i("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),d&&_i("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:d}),_i("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),u.map((e,t)=>Mi("g",{transform:`translate(0,${e.pixel})`,children:[_i("line",{x2:-5,stroke:n.border,strokeWidth:1}),_i("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),h&&_i("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})]})}(g,{width:c,height:l},e,o,p):null,v=e.annotations?Co({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:h,idPrefix:p}):null,A=Yo({props:e,categories:a,theme:o,size:i,margin:s,hasTitle:r}),w=d?s.left+c/2:s.left,S=d?s.top+l/2:s.top,k=d&&e.centerContent?_i("foreignObject",{x:s.left,y:s.top,width:c,height:l,pointerEvents:"none",children:_i("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return Uo.renderToStaticMarkup(Xo(Mi(ki,{children:[e.backgroundGraphics,f,x,b,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(${w},${S})`,innerWidth:c,innerHeight:l,legend:A,defs:y,outerElements:k,idPrefix:e._idPrefix}))}import*as Ti from"react-dom/server";import{Fragment as Ri,jsxs as Li}from"react/jsx-runtime";function zi(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Ci=new Set(["tree","cluster","treemap","circlepack","partition"]);function Fi(e,t){const o=it(e.theme),i=e.chartType||"force",s=()=>lo({frameType:"network",width:r[0],height:r[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,nodeCount:0,edgeCount:0}),r=e.size||[500,500],n=xe({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=ae(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=ie(e.nodes||[]);if(i.length>0)return ko(i,t);const s=Array.isArray(e.edges)?ie(e.edges):[];if(0===s.length)return[];const r=zi(e.sourceAccessor,"source"),n=zi(e.targetAccessor,"target");return ko(Array.from(new Set(s.flatMap(e=>[r(e),n(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];Go(n,{props:e,categories:c,theme:o,size:r,hasTitle:a});const l=r[0]-n.left-n.right,h=r[1]-n.top-n.bottom,d=F(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 u={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,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(Ci.has(i)){const i=e.data||e.edges;if(!i||Array.isArray(i))return t&&(t.evidence=s()),Ti.renderToStaticMarkup(Xo(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:h,idPrefix:e._idPrefix}));u.__hierarchyRoot=i,g=[],p=[]}else{const i=ie(e.nodes||[]),a=Array.isArray(e.edges)?ie(e.edges):[];if(0===i.length&&0===a.length)return t&&(t.evidence=s()),Ti.renderToStaticMarkup(Xo(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:h,idPrefix:e._idPrefix}));if(p=function(e,t){const o=zi(t.sourceAccessor,"source"),i=zi(t.targetAccessor,"target"),s=zi(t.valueAccessor,"value");return e.map(e=>({source:o(e)+"",target:i(e)+"",value:Number(s(e))||1,y0:0,y1:0,sankeyWidth:0,data:e}))}(a,u),0===i.length&&p.length>0){const e=new Set;for(const t of p){const o=jo(t.source),i=jo(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=zi(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,u)}let f=[],y=[],m=[],x=null;if(u.customNetworkLayout){const e=u.colorScheme,t=Ae(e,o.colors.categorical,Ie),i=K(t,e),s={nodes:g,edges:p,dimensions:{width:l,height:h,plot:{x:0,y:0,width:l,height:h}},theme:{semantic:o.colors,categorical:[...t]},resolveColor:i,config:u.layoutConfig??{}},r=u.customNetworkLayout(s);f=r.sceneNodes??[],y=r.sceneEdges??[],m=r.labels??[],x=r.overlays??null}else if(d){d.computeLayout(g,p,u,[l,h]);const e=d.buildScene(g,p,u,[l,h]);f=e.sceneNodes,y=e.sceneEdges,m=e.labels}const b=st(o);for(const e of m)e.fill||(e.fill=b.text);const v=E({nodes:y,renderMode:e.renderMode,fallback:(e,t)=>pe(e,t)}),A=E({nodes:f,renderMode:e.renderMode,fallback:(e,t)=>fe(e,t)});t&&(t.evidence=lo({frameType:"network",width:r[0],height:r[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 w=v.map(e=>e.element),S=A.map(e=>e.element),k=m.map((e,t)=>ge(e,t)).filter(Boolean),_=e.annotations?Co({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{},layout:{width:l,height:h},theme:o,idPrefix:e._idPrefix}):null,M=Yo({props:e,categories:c,theme:o,size:r,margin:n,hasTitle:a});return Ti.renderToStaticMarkup(Xo(Li(Ri,{children:[e.backgroundGraphics,w,S,k,_,e.foregroundGraphics,x]}),{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:l,innerHeight:h,legend:M,idPrefix:e._idPrefix}))}import*as Bi from"react-dom/server";import{geoPath as Oi}from"d3-geo";import{quadtree as Ei}from"d3-quadtree";import{geoMercator as ji,geoEqualEarth as Di,geoAlbersUsa as Ni,geoOrthographic as Wi,geoNaturalEarth1 as $i,geoEquirectangular as Ii}from"d3-geo";var Gi={mercator:ji,equalEarth:Di,albersUsa:Ni,orthographic:Wi,naturalEarth:$i,equirectangular:Ii};function Yi(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Vi(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function Xi(e,t,o){return e?"function"==typeof e?{...o,...e(t)}:{...o,...e}:{...o}}function Hi(e,t){if(2>e.length)return[e];const o=.4*t,i=[];let s=[e[0]];for(let t=1;e.length>t;t++){const r=e[t];Math.abs(r[0]-e[t-1][0])>o?(2>s.length||i.push(s),s=[r]):s.push(r)}return 2>s.length||i.push(s),i}function qi(e,t,o=24){const i=t[0]-e[0],s=t[1]-e[1],r=Math.sqrt(i*i+s*s);if(0===r)return[e,t];const n=-s/r,a=i/r,c=Math.min(.3*r,80),l=(e[0]+t[0])/2+n*c,h=(e[1]+t[1])/2+a*c,d=[];for(let i=0;o>=i;i++){const s=i/o,r=1-s;d.push([r*r*e[0]+2*r*s*l+s*s*t[0],r*r*e[1]+2*r*s*h+s*s*t[1]])}return d}function Qi(e,t){if(2>e.length)return e;const o=t/2+1,i=[];for(let t=0;e.length>t;t++){const s=e[t];let r,n;0===t?(r=e[1][0]-s[0],n=e[1][1]-s[1]):t===e.length-1?(r=s[0]-e[t-1][0],n=s[1]-e[t-1][1]):(r=e[t+1][0]-e[t-1][0],n=e[t+1][1]-e[t-1][1]);const a=Math.sqrt(r*r+n*n)||1;i.push([s[0]+n/a*o,s[1]+-r/a*o])}return i}function Zi(e,t,o,i,s){const r=t[0]-e[0],n=t[1]-e[1],a=Math.sqrt(r*r+n*n);if(0===a)return[e,t];const c=n/a,l=-r/a,h=s/2+1;return[[e[0]+c*h,e[1]+l*h],[t[0]+c*h,t[1]+l*h]]}import{scaleLinear as Ui}from"d3-scale";var Ki=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ji=["scene-style","data-paint","accessibility","evidence"],es=(e,t)=>({retainedData:e,invalidations:t}),ts=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],os=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],is=["scene-geometry","data-paint","accessibility","evidence"],ss=["scene-style","data-paint","accessibility","evidence"],rs=["overlay","accessibility","evidence"],ns=[],as={xAccessor:es("rebuild",ts),yAccessor:es("rebuild",ts),lineDataAccessor:es("rebuild",ts),pointIdAccessor:es("rebuild",is),lineIdAccessor:es("rebuild",is),windowSize:es("rebuild",ts),projection:es("preserve",os),projectionExtent:es("preserve",os),fitPadding:es("preserve",os),lineType:es("preserve",os),flowStyle:es("preserve",os),graticule:es("preserve",os),projectionTransform:es("preserve",os),customLayout:es("preserve",os),layoutConfig:es("preserve",os),layoutMargin:es("preserve",os),areaStyle:es("preserve",ss),pointStyle:es("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:es("preserve",ss),colorScheme:es("preserve",ss),themeCategorical:es("preserve",ss),themeDiverging:es("preserve",ss),themeSemantic:es("preserve",ss),themeSequential:es("preserve",ss),decay:es("preserve",ss),pulse:es("preserve",ss),layoutSelection:es("preserve",ss),annotations:es("preserve",rs),autoPlaceAnnotations:es("preserve",rs),clock:es("preserve",ns),transition:es("preserve",ns),introAnimation:es("preserve",ns),onLayoutError:es("preserve",ns)},cs=es("preserve",os),ls=class{constructor(){this.tracker=new ze}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}},Ki)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Ji):this.recordNoop("restyle")}recordConfig(e,t={}){const o=function(e){let t="preserve";const o=new Set;for(const i of e){const e=as[i]??cs;"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 hs,geoGraticule as ds,geoInterpolate as us}from"d3-geo";function gs(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 ps=class e{constructor(e){this.updateResults=new ls,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:gs(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??ye()}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),s=o.slice(-i.length),r=this.currentTime();this.pointBuffer=new Y(e),this.timestampBuffer=new Y(e),i.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(s[t]??r)})}this.retainNewestLines(e)}updateConfig(e){const t=function(e){return"fitPadding"in e?{...e,fitPadding:gs(e.fitPadding)}:e}(e),o=this.config,i=this.getConfiguredWindowSize(),s=Object.keys(t).filter(e=>t[e]!==o[e]);this.config={...this.config,...t};const r=this.getConfiguredWindowSize(),n=this.streaming&&r!==i;n&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(s,{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()??[],s=o.slice(-t),r=i.slice(-s.length),n=this.currentTime();this.pointBuffer=new Y(t),this.timestampBuffer=new Y(t),s.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(r[t]??n)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();O(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)O(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]),s=[];return this.lineData=this.lineData.filter(e=>!i.has(o(e)+"")||(s.push(e),!1)),s.length>0?(this.version++,this.updateResults.recordData("remove",s.length)):this.updateResults.recordNoop("remove"),s}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)+"");P(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,s=t(o,e);o.style=s?{...i,...s}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){const{config:t}=this,o=this.projection,i=this.geoPath,s=this.scales,r=this.baseScale,n=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(e){if(!e)return Di();if("string"==typeof e){const t=Gi[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),Di())}if("object"==typeof e&&"type"in e){const t=Gi[e.type],o=t?t():Di();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=Oi(this.projection),this.fitProjection(e),this.geoPath=Oi(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 h=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=i,this.scales=s,this.baseScale=r,this.baseTranslate=n,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=h,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],s=Yi(o.xAccessor,"lon"),r=Yi(o.yAccessor,"lat"),n=this.getPoints();if(n.length>0){const e=n.map(e=>[s(e),r(e)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}const a=Vi(o.lineDataAccessor);for(const e of this.lineData){const t=a(e);if(t&&t.length>0){const e=t.map(e=>[s(e),r(e)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==i.length){if(o.projectionExtent){const[[i,s],[r,n]]=o.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,s],[i,n],[r,n],[r,s],[i,s]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){const i=o.fitPadding??0,s=Math.min(e.width,e.height);t.scale(s/2-s*i),t.translate([e.width/2,e.height/2])}else{const s=o.fitPadding??0,r=e.width*s,n=e.height*s;t.fitExtent([[r,n],[e.width-r,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,s=this.scales,r=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=Oi(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(r),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=s):(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,s=this.scales,r=o.scale(),n=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e),o.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=Oi(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(r),o.translate(n),this.currentZoom=a,this.geoPath=i,this.scales=s):(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,s=this.scales,r=[...o.rotate()];o.rotate(e),this.geoPath=Oi(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(r),this.geoPath=i,this.scales=s):(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 s=0;for(const e of this.scene)"point"===e.type&&(i[s++]=e);this._quadtree=Ei().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=Ae(t.colorScheme,t.themeCategorical,q),s={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:K(i,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null};let r;try{r=t.customLayout(s)}catch(e){const o=null!==this.lastCustomLayoutResult,i=L("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=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const e of n)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return I({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:s,lines:r,layout:n}){const a=Yi(e.xAccessor,"lon"),c=Yi(e.yAccessor,"lat"),l=[],h=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),u=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){const t=!0===e.graticule?{}:e.graticule,i=ds();t.step&&i.step(t.step);const s=o(i())||"";s&&l.push({type:"geoarea",pathData:s,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 s=o.centroid(t),r=o.bounds(t),n=o.area(t);l.push({type:"geoarea",pathData:i,centroid:s,bounds:r,screenArea:n,style:Xi(e.areaStyle,t,h),datum:t,interactive:!0})}const g=Vi(e.lineDataAccessor);for(const o of r){const i=g(o);if(!i||2>i.length)continue;let s=[];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],r=e[o+1],n=hs(i,r)||0,a=Math.max(2,Math.ceil(n/(Math.PI/180))),c=us(i,r);for(let e=0;a>=e;e++){if(o>0&&0===e)continue;const i=t(c(e/a));null!=i&&s.push(i)}}}else for(let e=0;i.length>e;e++){const o=i[e],r=t([a(o),c(o)]);null!=r&&s.push(r)}if(2>s.length)continue;const r=Xi(e.lineStyle,o,d),h="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==i.length||2>s.length||"arc"!==e.flowStyle?2!==i.length||2>s.length||"offset"!==e.flowStyle||(s="geo"===e.lineType?Qi(s,h):Zi(s[0],s[s.length-1],0,0,h)):s=qi(s[0],s[s.length-1]);const u=Hi(s,n.width);if(u.length>1)for(const e of u)2>e.length||l.push({type:"line",path:e,style:{...r,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>s.length&&u[0]||s,style:r,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],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of s){const i=a(o),s=c(o);if(null!=y&&hs([i,s],b)>y)continue;const r=t([i,s]);if(!r)continue;const n=e.pointStyle?e.pointStyle(o):{...u},h={type:"point",x:r[0],y:r[1],r:n.r||4,style:n,datum:o,pointId:p?p(o)+"":void 0};l.push(h)}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 s=e.filter(e=>"point"===e.type);if(2>s.length)return null;const r=t.strength??1;if(0===r)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=s.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,h=c.y,d=s.map(e=>e.datum?a(e.datum):NaN).filter(e=>isFinite(e)&&e>=0),u=Ge(d,1),g=Math.min(o.width,o.height)/2,p=Ui().domain([0,u]).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 s){if(e===c)continue;if(!e.datum)continue;const t=Math.atan2(e.y-h,e.x-l),o=Math.sqrt((e.x-l)**2+(e.y-h)**2),i=a(e.datum),s=o+((isFinite(i)?p(i):o)-o)*r;e.x=l+Math.cos(t)*s,e.y=h+Math.sin(t)*s}const f=o.width/2,y=o.height/2,m=f-c.x,x=y-c.y;if(Math.abs(m)>.5||Math.abs(x)>.5)for(const e of s)e.x+=m,e.y+=x;const b={cx:f,cy:y,maxCost:u,availableRadius:g},v=e.filter(e=>"line"===e.type);if(v.length>0&&"fractional"!==t.lineMode){const e=new Map;for(const t of s)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 s=e.get(o+""),r=e.get(i+"");s&&r&&(t.path=[s,r])}}}return b}(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 s=T(e,i,t);o[i]._decayOpacity=s,o[i].style={...o[i].style,opacity:s}}}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(),s=t.color||"rgba(255,255,255,0.6)",r=t.glowRadius??4;let n=!1;for(let a=0;o.length>a&&i.length>a;a++){const c=R(t,i[a],e);n=N(o[a],c,s,r)||n}return n}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&B(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 s=!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)&&(s=!0))}for(const e of i)e.pointId&&!o.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??1,e.style={...e.style,opacity:0},s=!0);s&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(e){if(!this.activeTransition)return!1;const t=te(e,this.activeTransition),o=ee(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=ue(e.x,e._targetX,o),e.y=ue(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}};ps.QUADTREE_THRESHOLD=500;var fs=ps;S(fs);import{Fragment as ys,jsxs as ms}from"react/jsx-runtime";function xs(e,t){const o=it(e.theme),i=e.size||[e.width||600,e.height||400],s=xe({top:10,right:10,bottom:10,left:10,...e.margin},e.title),r=ae(e.title),n=Array.isArray(e.areas)?ie(e.areas):e.areas,a=ie(e.points),c=ie(e.lines),l=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;return ko(a.length>0?a:Array.isArray(n)&&n.length>0?"string"==typeof t?n.map(e=>({...e.properties||{},...e})):n:[],t)})():[];Go(s,{props:e,categories:l,theme:o,size:i,hasTitle:r});const h=i[0]-(s.left??0)-(s.right??0),d=i[1]-(s.top??0)-(s.bottom??0),u={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:s,themeCategorical:o.colors.categorical,themeSemantic:Ue(o)},g=new fs(u);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:h,height:d});const p=E({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>se(e,t)});if(t&&(t.evidence=lo({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?ms(ys,{children:[e.backgroundGraphics,e.annotations?Co({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:h,height:d},theme:o,idPrefix:e._idPrefix}):null,e.foregroundGraphics,g.customLayoutOverlays]}):null;return Bi.renderToStaticMarkup(Xo(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(${s.left??0},${s.top??0})`,innerWidth:h,innerHeight:d,idPrefix:e._idPrefix}))}const f=p.map(e=>e.element),y=e.annotations?Co({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:h,height:d},theme:o,idPrefix:e._idPrefix}):null,m=Yo({props:e,categories:l,theme:o,size:i,margin:s,hasTitle:r});return Bi.renderToStaticMarkup(Xo(ms(ys,{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(${s.left??0},${s.top??0})`,innerWidth:h,innerHeight:d,legend:m,idPrefix:e._idPrefix}))}function bs(e,t){const o=e.size??[e.width??600,e.height??400],i=new A(e.config);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&i.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));const s=d(i,{...e,width:o[0],height:o[1],idPrefix:e.idPrefix??e._idPrefix??"physics"});return t&&(t.evidence=lo({frameType:"physics",width:o[0],height:o[1],marks:s.scene.sceneNodes,title:e.title,description:e.description,annotations:[],extraWarnings:0===s.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[]})),s.svg}import{Fragment as vs,jsx as As,jsxs as ws}from"react/jsx-runtime";function Ss(e,t){switch(e){case"xy":return Zo(t);case"ordinal":return Pi(t);case"network":return Fi(t);case"geo":return xs(t);case"physics":return bs(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function ks(e){return Zo(e)}function _s(e){return Pi(e)}function Ms(e){return Fi(e)}function Ps(e){return xs(e)}var Ts=["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"],Rs=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Ls(e,t){const o={};for(const i of t)void 0!==e[i]&&(o[i]=e[i]);return o}function zs(e,t,o){return Fs(e,t).svg}function Cs(e,t,o){const i={},{svg:s,frameType:r}=Fs(e,t,0,i),n=i.evidence??lo({frameType:r,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});return n.component=e,{svg:s,evidence:n}}function Fs(e,t,o,i){const s=no[e];if(!s)throw Error(`Unknown chart component: "${e}". See CLAUDE.md for supported chart types.`);const r=s.layout?.mode??(ce(t.mode)?t.mode:void 0),n=ve(r,{...s.layout?.modeDefaults,...Ls(t,Rs)},s.layout?.primarySize),{data:a,theme:c,background:l,className:h,annotations:d,margin:u,colorScheme:g,colorBy:p,legendPosition:f,...y}=t,{width:m,height:x}=n,b=[m,x],v=y.frameProps||{},A=s.layout?.margin,w="function"==typeof A?A(t,n):A??n.marginDefaults,S=void 0!==u?u: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}(S),_="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...w,...k},M=Ls(y,Ts),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:h,annotations:d,size:b,margin:_,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==g&&{colorScheme:g},...void 0!==f&&{legendPosition:f},_idPrefix:y._idPrefix},T=s.buildProps(a,p,g,P,y);let R;switch(s.frameType){case"xy":R=Zo(T,i);break;case"ordinal":R=Pi(T,i);break;case"network":R=Fi(T,i);break;case"geo":R=xs(T,i);break;case"physics":R=bs(T,i)}const L=s.renderOverlay?.(T,{theme:it(c)});if(null!=L){const e=Ke.renderToStaticMarkup(As(vs,{children:L}));R=R.replace("</svg>",e+"</svg>")}return{svg:R,frameType:s.frameType}}function Bs(e,t={}){const{title:o,subtitle:i,theme:s,width:r=1200,height:n,layout:a={},background:c}=t,l=st(it(s)),h=a.columns||2,d=a.gap??16;let u=0;o&&(u+=30),i&&(u+=20),u>0&&(u+=10);const g=Math.floor((r-d-d*(h-1))/h),p=[];let f=0,y=u+d,m=0;for(const t of e){const e=Math.min(t.colSpan||1,h),o=t.props.height||300;f+e>h&&(y+=m+d,f=0,m=0),p.push({chart:t,x:d/2+f*(g+d),y:y,w:g*e+d*(e-1),h:o}),m=Math.max(m,o),f+=e}const x=n||y+m+d,b=p.map((e,t)=>{const{chart:o,x:i,y:r,w:n,h:a}=e,c={...o.props,width:n,height:a,theme:s,_idPrefix:"chart-"+t};let l;return l=o.component?zs(o.component,c):o.frameType?Ss(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${a}"></svg>`,As("g",{transform:`translate(${i},${r})`,children:As("foreignObject",{width:n,height:a,children:As("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+t)});return Ke.renderToStaticMarkup(ws("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&As("title",{children:o}),c&&As("rect",{x:0,y:0,width:r,height:x,fill:c}),o&&As("text",{x:r/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:o}),i&&As("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),b]}))}import*as Os from"react-dom/server";import{Fragment as Es,jsx as js,jsxs as Ds}from"react/jsx-runtime";function Ns(e,t,o,i={}){const{stepSize:s,windowSize:r,frameCount:n,xExtent:a,yExtent:c,transitionFrames:l=4,fps:h=12,easing:d="ease-out",decay:u}=i,g=o.width||600,p=o.height||400,f=it(o.theme),y={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!t||0===t.length)return[];const m=s||Math.max(1,Math.ceil(t.length/(n||Math.min(60,Math.max(10,t.length))))),x=[];for(let e=m;t.length>=e;e+=m)x.push(e);x[x.length-1]!==t.length&&x.push(t.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),v=xe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),A=g-v.left-v.right,S=p-v.top-v.bottom,k=[];if(b)for(let i=0;x.length>i;i++){const s=x[i],n=t.slice(r?Math.max(0,s-r):0,s),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,...u&&{decay:u}},c=new Ai(a);c.ingest({inserts:n,bounded:!0}),c.computeScene({width:A,height:S}),c.scene.length>0&&k.push(Vs(c.scene,g,p,f,y))}else for(let i=0;x.length>i;i++){const s=x[i],n=t.slice(r?Math.max(0,s-r):0,s),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,...u&&{decay:u},...l>0&&{transition:{duration:l*(1e3/h),easing:d}}},b=new w(m);if(b.ingest({inserts:n,bounded:!0}),b.computeScene({width:A,height:S}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(k.push(Ys(b.scene,g,p,f,y,v)),l>0&&i>0&&b.activeTransition){const e=l*(1e3/h);for(let t=1;l>=t;t++)b.advanceTransition(b.activeTransition.startTime+t/l*e),k.push(Ys(b.scene,g,p,f,y,v))}}return k}function Ws(e,t,o={}){return t.map(t=>{try{return zs(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 $s(e,t,o){const i=t.size??[t.width??600,t.height??400],s=it(t.theme),r=st(s),n=t.background||s.colors.background,a=t.idPrefix??"physics-gif",c=t.title?`${a}-title-${o}`:void 0,l=t.description?`${a}-desc-${o}`:void 0,d=[c,l].filter(Boolean).join(" ")||void 0,u=h(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),g=Ds("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":d,style:{fontFamily:r.fontFamily},children:[t.title&&js("title",{id:c,children:t.title}),t.description&&js("desc",{id:l,children:t.description}),n&&"transparent"!==n?js("rect",{x:0,y:0,width:i[0],height:i[1],fill:n}):null,js("g",{id:`${a}-frame-${o}`,children:u.map((e,t)=>_e(e,t,`${a}-${o}`))})]});return Os.renderToStaticMarkup(g)}function Is(e,t={}){const{fps:o=12,frameCount:i,durationSeconds:s=2,includeInitialFrame:r=!0,stepDt:n,stepsPerFrame:a,background:c}=t,l=Math.max(.001,n??e.config?.fixedDt??1/120),h=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=i??Math.max(1,Math.ceil(s*Math.max(1,o))),u=c?{...e,background:c}:e,g=new A(e.config);e.initialSpawns?.length&&g.enqueue(e.initialSpawns,e.initialSpawnPacing);const p=[];for(r&&(g.tick(0),p.push($s(g,u,0)));d>p.length;){for(let e=0;h>e;e+=1)g.tick(l);p.push($s(g,u,p.length))}return p}function Gs(e,t){const o=e.background||t.colors.background;return o&&"transparent"!==o?o:null}function Ys(e,t,o,i,s,r){const n=st(i),a=xe({top:20,right:20,bottom:30,left:40,...s.margin},s.title),c=t-a.left-a.right,l=o-a.top-a.bottom,h=Gs(s,i),d=s.renderMode,u=e.map((e,t)=>j({node:e,index:t,renderMode:d,fallback:()=>_e(e,t)})).filter(Boolean),g=function(e,t,o,i,s,r){if(!e||0===e.length)return null;const n=st(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(r)e=r(c.value);else if(s){const[t,i]=s,r=i-t;if(0===r)continue;e=o-(c.value-t)/r*o}if(null==e)continue;const l=c.color||n.primary,h=c.labelPosition||"right";a.push(Ds("g",{children:[js("line",{x1:0,y1:e,x2:t,y2:e,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&js("text",{x:"left"===h?4:"center"===h?t/2:t-4,y:20>e?Math.min(o-4,e+16):e-5,textAnchor:"left"===h?"start":"center"===h?"middle":"end",fontSize:n.tickSize,fill:l,fontFamily:n.fontFamily,children:c.label})]},"ann-"+i))}}return a.length>0?js(Es,{children:a}):null}(s.annotations,c,l,i,s.yExtent,r?.y),p="string"==typeof s.title?s.title:void 0,f="string"==typeof s.description?s.description:void 0,y=p?"semiotic-title":void 0,m=f?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Os.renderToStaticMarkup(Ds("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":x,style:{fontFamily:n.fontFamily},children:[p&&js("title",{id:y,children:p}),f&&js("desc",{id:m,children:f}),h&&js("rect",{x:0,y:0,width:t,height:o,fill:h}),Ds("g",{transform:`translate(${a.left},${a.top})`,children:[g,u]}),p&&js("text",{x:t/2,y:Z,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:p})]}))}function Vs(e,t,o,i,s){const r=st(i),n=xe({top:20,right:20,bottom:30,left:40,...s.margin},s.title),a="radial"===s.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,h=Gs(s,i),d=s.renderMode,u=e.map((e,t)=>j({node:e,index:t,renderMode:d,fallback:()=>me(e,t)})).filter(Boolean),g="string"==typeof s.title?s.title:void 0,p="string"==typeof s.description?s.description:void 0,f=g?"semiotic-title":void 0,y=p?"semiotic-desc":void 0,m=[f,y].filter(Boolean).join(" ")||void 0;return Os.renderToStaticMarkup(Ds("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[g&&js("title",{id:f,children:g}),p&&js("desc",{id:y,children:p}),h&&js("rect",{x:0,y:0,width:t,height:o,fill:h}),js("g",{transform:`translate(${c},${l})`,children:u}),g&&js("text",{x:t/2,y:Z,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:g})]}))}export{Ns as generateFrameSVGs,Ws as generateFrameSequence,Is as generatePhysicsFrameSVGs,zs as renderChart,Cs as renderChartWithEvidence,Bs as renderDashboard,Ps as renderGeoToStaticSVG,Ms as renderNetworkToStaticSVG,_s as renderOrdinalToStaticSVG,Ss as renderToStaticSVG,ks as renderXYToStaticSVG,it as resolveTheme,st as themeStyles};
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,buildPhysicsSettledProjection as a,buildProcessFlowPhysics as c,generateGaltonMechanicalSamples as l,generatePhysicsPileMechanicalSamples as d,physicsBodiesToXYSceneNodes as u,renderPhysicsSettledSVG as h,resolveCustomLayout as p,styleFromColorAccessor as m}from"./chunk-chunk-K3DMEW22.module.min.js";import{composeStyleRules as g,makeNodeRuleContext as f,makeRuleValueResolver as y,makeXYRuleContext as b,resolveStyleRules as x,styleRulesToNodeStyle as v,styleRulesToXYStyle as A,validateArrayData as w}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 k,buildAnomalyAnnotations as _,buildForecast as M,createSegmentLineStyle as P}from"./chunk-chunk-C57LR3YG.module.min.js";import"./chunk-chunk-2JGJ5GUG.module.min.js";import{PipelineStore as R,StreamXYFrame_default as I,accessorName as T,attachUpdateResultStore as L,bandTooltipFields as C,buildBaseMetadataProps as z,buildCustomBehaviorProps as F,buildDatumIndexMap as B,buildDefaultTooltip as j,buildRectNode as E,buildRibbonGeometry as O,buildTooltipProps as D,compactTimestampBufferForRemoval as N,computeDecayOpacity as $,computePulseIntensity as W,createCustomLayoutFailureDiagnostic as G,createTimestampBufferForData as Y,ensureRingBufferCapacity as H,getLayoutPlugin as V,hasActivePulses as X,pushWithTimestamp as q,renderSceneListWithBackend as Q,renderSceneWithBackend as K,resolveDownwardHistogramExtent as U,setPulseState as Z,ticksForMode as J,toIdSet as ee,warnCustomLayoutDiagnostics as te}from"./chunk-chunk-RFLAG356.module.min.js";import{IncrementalExtent as oe,RingBuffer as ie}from"./chunk-chunk-7ALTGHK6.module.min.js";import"./chunk-chunk-C4YA6TDR.module.min.js";import{AnnotationLabel as re,ChartError as se,DEFAULT_COLOR as ne,DEFAULT_LEGEND_ROW_HEIGHT as ae,DEPTH_PALETTE_COLORS as ce,STREAMING_PALETTE as le,SafeRender as de,SemioticAnnotation as ue,TITLE_BASELINE as he,buildResolveColor as pe,composeLegendConfigs as me,computeEasing as ge,computeRawProgress as fe,createColorScale as ye,filterSparseArray as be,geoSceneNodeToSVG as xe,getColor as ve,getCrosshairProps as Ae,getSize as we,hasTextTitle as Se,isChartMode as ke,isGradientLegendConfig as _e,isLegendConfig as Me,layoutVerticalLegendGroups as Pe,lerp as Re,networkLabelToSVG as Ie,networkSceneEdgeToSVG as Te,networkSceneNodeToSVG as Le,now as Ce,ordinalSceneNodeToSVG as ze,renderAnnotationPass as Fe,renderEmptyState as Be,renderLoadingState as je,reserveTitleMargin as Ee,resolveCategoricalPalette as Oe,resolveChartMode as De,resolveCustomLayoutPalette as Ne,resolveDefaultFill as $e,resolveExplicitColor as We,resolveLegendMetrics as Ge,resolveMobileInteraction as Ye,useCategoryColors as He,useChartLegendAndMargin as Ve,useChartMode as Xe,useChartSelection as qe,useColorScale as Qe,useLegendInteraction as Ke,useThemeCategorical as Ue,warnMissingField as Ze,wrapStyleWithSelection as Je,xySceneNodeToSVG as et}from"./chunk-chunk-E6TXX6MI.module.min.js";import"./chunk-chunk-XEVJDUTH.module.min.js";import{MultiPointTooltip as tt,accessorsEquivalent as ot,filterAnnotationsByStatus as it,resolveAccessor as rt,resolveStringAccessor as st,resolveSvgFill as nt}from"./chunk-chunk-CO5KQMGH.module.min.js";import{SYMBOL_SEQUENCE as at,UpdateResultTracker as ct,annotationLayout as lt,getSequentialInterpolator as dt,interpolateBrBG as ut,interpolatePRGn as ht,interpolatePiYG as pt,interpolateRdBu as mt,interpolateRdYlBu as gt,interpolateRdYlGn as ft,interpolateSpectral as yt,interpolateViridis as bt,schemeCategory10 as xt}from"./chunk-chunk-5RKXZQ2P.module.min.js";import"./chunk-chunk-U66USBWU.module.min.js";import{getMax as vt,getMin as At,getMinMax as wt}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 kt,LIGHT_THEME as _t,THEME_PRESETS as Mt,applyThemeAccessibility as Pt,resolveThemeSemanticColors as Rt,useThemeSelector as It}from"./chunk-chunk-DSNGDNJY.module.min.js";import*as Tt from"react-dom/server";import*as Lt 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 jt}from"react";import{useCallback as Et,useMemo as Ot,useState as Dt}from"react";import{useMemo as Nt}from"react";import{useImperativeHandle as $t,useRef as Wt}from"react";import{useMemo as Gt}from"react";import{useEffect as Yt,useMemo as Ht,useRef as Vt,useState as Xt}from"react";var qt=null;async function Qt(){return qt||(qt=await import("./chunk-statisticalOverlays-QGDLRUHX.module.min.js")),qt}var Kt="__semiotic_resolvedX",Ut="__semiotic_resolvedY";import{jsx as Zt}from"react/jsx-runtime";function Jt(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 eo(e){return e.filter(e=>Number.isFinite(e.at)).map(e=>({offset:1-Math.max(0,Math.min(100,e.at))/100,color:Jt(e.color,e.opacity)})).sort((e,t)=>e.offset-t.offset)}function to(e,t,o){return"function"==typeof e?e(o):o[e||t]}function oo(e){return e instanceof Date?e.getTime():Number(e)}function io(e,t){return bt(1===t?.5:e/(t-1))}function ro(e){if(!e)return _t;if("string"==typeof e){if("light"===e)return _t;if("dark"===e)return St;if("high-contrast"===e)return kt;return Mt[e]||_t}const t="dark"===e.mode?St:_t,o={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return Pt(o)}function so(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=jt(null);!function(e,t){const{variant:o,frameRef:i,overrides:r}=t,s=Wt(r);s.current=r,$t(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=Xe(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:d="y",areaBy:u,y0Accessor:h,gradientFill:p=!1,semanticGradient:m,lineDataAccessor:g="coordinates",colorBy:f,colorScheme:y,styleRules:v,curve:A="monotoneX",areaOpacity:S=.7,lineGradient:k,showLine:_=!0,lineWidth:M=2,showPoints:P=!1,pointRadius:R=3,tooltip:L,annotations:B,forecast:E,anomaly:O,band:N,xExtent:$,yExtent:W,frameProps:G={},selection:Y,linkedHover:H,onObservation:V,onClick:X,hoverHighlight:q,chartId:Q,loading:K,loadingContent:U,emptyContent:Z,legendInteraction:J,legendPosition:ee,color:te,stroke:oe,strokeWidth:ie,opacity:re}=e,{width:ae,height:ce,enableHover:ue,showGrid:he,showLegend:pe,title:me,description:ge,summary:fe,accessibleTable:xe,xLabel:we,yLabel:Se}=i,ke=Ft(()=>be(r),[r]),_e=f||u,Me=Ft(()=>m&&m.length>0?{colorStops:eo(m)}:p,[m,p]);Ze("AreaChart",ke,"xAccessor",l),Ze("AreaChart",ke,"yAccessor",d);const Pe=function(e){const{data:t,rawData:o,colorBy:i,colorScheme:r,legendInteraction:s,legendPosition:n,selection:a,linkedHover:c,fallbackFields:l,unwrapData:d=!1,onObservation:u,chartType:h,chartId:p,showLegend:m,legend:g,userMargin:f,marginDefaults:y,onClick:b,hoverHighlight:x,mobileInteraction:v,mobileSemantics:A,loading:w,loadingContent:S,emptyContent:k,width:_,height:M}=e,P=void 0===o,R=Ot(()=>be(t),[t]),[I,T]=Dt([]),L=Et(e=>{T(t=>t.length===e.length&&t.every((t,o)=>t===e[o])?t:e)},[]),C="string"==typeof e.colorBy?e.colorBy:void 0,z=Ot(()=>Ye(v,{width:_,mobileSemantics:A}),[v,_,A]),{activeSelectionHook:F,hoverSelectionHook:B,customHoverBehavior:j,customClickBehavior:E,crosshairSourceId:O}=qe({selection:a,linkedHover:c,fallbackFields:l,unwrapData:d,onObservation:u,chartType:h,chartId:p,onClick:b,hoverHighlight:x,colorByField:C,mobileInteraction:z}),D=Ae(c,O),N=Qe(R,i,r),$=Ot(()=>{if(!i)return[];const e=new Set;for(const t of R){const o="function"==typeof i?i(t):t[i];null!=o&&e.add(o+"")}return Array.from(e)},[R,i]),W=Ot(()=>P&&I.length>0?I:$,[P,I,$]),G=Ke(s,i,W),Y=Ot(()=>B||(G.legendSelectionHook?G.legendSelectionHook:F),[B,G.legendSelectionHook,F]),H=function(e){const t=It(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=Ue(),X=He(),q=Ot(()=>{if(N)return N;if(!i||0===W.length)return;const e=Array.isArray(r)&&r.length>0||"string"==typeof r&&r.length>0?r:V&&V.length>0?V:le,t="__streamCat",o=W.map(e=>({[t]:e})),s=ye(o,t,e);return e=>X?.[e]||s(e)||"#999"},[N,i,W,r,V,X]),{legend:Q,margin:K,legendPosition:U}=Ve({data:R,colorBy:i,colorScale:q,showLegend:m,legendPosition:n,userMargin:f,defaults:y,categories:W,additionalLegend:g}),Z=Ot(()=>{const e={};return Q&&(e.legend=Q,e.legendPosition=U),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=L),e},[Q,U,s,G.onLegendHover,G.onLegendClick,G.highlightedCategory,G.isolatedCategories,P,i,L]),J=Array.isArray(o)?be(o):o,ee=je(w,_,M,S),te=ee?null:Be(J,_,M,k);return{data:R,colorScale:N,allCategories:W,legendState:G,effectiveSelectionHook:Y,activeSelectionHook:F,customHoverBehavior:j,customClickBehavior:E,mobileInteraction:z,legend:Q,margin:K,legendPosition:U,earlyReturn:ee||te||null,legendBehaviorProps:Z,crosshairProps:D,resolvedSelection:H}}({data:ke,rawData:r,colorBy:_e,colorScheme:y,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:pe,userMargin:s,marginDefaults:i.marginDefaults,loading:K,loadingContent:U,emptyContent:Z,width:ae,height:ce}),{effectiveData:Re,statisticalAnnotations:Ie}=function(e){const{data:t,xAccessor:o,yAccessor:i,forecast:r,anomaly:s,groupBy:n}=e,a="string"==typeof o?o:Kt,c="string"==typeof i?i:Ut,l=Ht(()=>{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[Kt]=o(t)),n&&(r[Ut]=i(t)),r}):t},[t,r,s,o,i]),[d,u]=Xt(null),[h,p]=Xt([]),m=Vt(r),g=Vt(s);return Yt(()=>{if(!r&&!s)return void((m.current||g.current)&&(u(null),p([]),m.current=r,g.current=s));let e=!1;const t=r!==m.current||s!==g.current;if(m.current=r,g.current=s,t&&(u(null),p([])),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||(u(t),p(t.annotations))}).catch(()=>{e||(u(null),p([]))})}else s&&async function(...e){return(await Qt()).buildAnomalyAnnotations(...e)}(s).then(t=>{e||(u(null),p(t))}).catch(()=>{e||p([])});return()=>{e=!0}},[l,r,s,a,c,n]),{effectiveData:d?d.processedData:t,statisticalAnnotations:h,hasForecast:!!d,xAccessorKey:a,yAccessorKey:c}}({data:ke,xAccessor:l,yAccessor:d,forecast:E,anomaly:O,groupBy:u}),Te=Ft(()=>b(l,d),[l,d]),{flattenedData:Le,lineStyle:Ce,pointStyle:ze,defaultTooltipContent:Fe}=function(e){const{safeData:t,data:o,areaBy:i,lineDataAccessor:r,colorBy:s,colorScale:n,color:a,stroke:c,strokeWidth:l,opacity:d,effectiveSelectionHook:u,resolvedSelection:h,areaOpacity:p,showLine:m,lineWidth:g,showPoints:f,pointRadius:y,xAccessor:b,yAccessor:v,xLabel:A,yLabel:w,xFormat:S,yFormat:k,groupField:_,styleRules:M,ruleContext:P}=e,R=Gt(()=>Ct({data:o,safeData:t,areaBy:i,lineDataAccessor:r}),[o,t,i,r]),I=Gt(()=>e=>{const t={};if(s){if(n){const o=ve(e,s,n);t.fill=o,m?(t.stroke=o,t.strokeWidth=g):t.stroke="none"}}else{const e=a||ne;t.fill=e,m?(t.stroke=e,t.strokeWidth=g):t.stroke="none"}return t.fillOpacity=p,M&&M.length>0&&Object.assign(t,x(e,M,P?P(e):{value:void 0})),t},[s,n,a,p,m,g,M,P]),L=Gt(()=>zt(I,{stroke:c,strokeWidth:l,opacity:d}),[I,c,l,d]);return{flattenedData:R,lineStyle:Gt(()=>Je(L,u??null,h),[L,u,h]),pointStyle:Gt(()=>{if(f)return e=>{const t={r:y,fillOpacity:1};return s?n&&(t.fill=ve(e.parentLine||e,s,n)):t.fill=a||ne,t}},[f,y,s,n,a]),defaultTooltipContent:Gt(()=>j([{label:A||T(b),accessor:b,role:"x",format:S},{label:w||T(v),accessor:v,role:"y",format:k},..._?[{label:T(_),accessor:_,role:"group"}]:[],...C(e.band,k)]),[b,v,A,w,_,S,k,e.band])}}({safeData:Re,data:r,areaBy:u,lineDataAccessor:g,colorBy:_e,colorScale:Pe.colorScale,color:te,stroke:oe,strokeWidth:ie,opacity:re,effectiveSelectionHook:Pe.effectiveSelectionHook,resolvedSelection:Pe.resolvedSelection,areaOpacity:S,showLine:_,lineWidth:M,showPoints:P,pointRadius:R,xAccessor:l,yAccessor:d,xLabel:we,yLabel:Se,xFormat:a,yFormat:c,groupField:u||f,band:N,styleRules:v,ruleContext:Te}),Ee=w({componentName:"AreaChart",data:r,accessors:{xAccessor:l,yAccessor:d}}),Oe={chartType:"area",...null!=r&&{data:Le},xAccessor:l,yAccessor:d,groupAccessor:u||void 0,...h&&{y0Accessor:h},...N&&{band:N},...Me&&{gradientFill:Me},...k&&{lineGradient:k},curve:A,lineStyle:Ce,...P&&ze&&{pointStyle:ze},size:[ae,ce],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:Pe.margin,showAxes:i.showAxes,xLabel:we,yLabel:Se,xFormat:a,yFormat:c,enableHover:ue,...e.pointIdAccessor&&{pointIdAccessor:e.pointIdAccessor},showGrid:he,...Pe.legendBehaviorProps,...z({title:me,description:ge,summary:fe,accessibleTable:xe,className:n,animate:e.animate,axisExtent:e.axisExtent,autoPlaceAnnotations:e.autoPlaceAnnotations}),..."multi"===L?{tooltipContent:tt(),tooltipMode:"multi"}:D({tooltip:L,defaultTooltipContent:Fe}),...F({linkedHover:H,selection:Y,onObservation:V,onClick:X,hoverHighlight:q,mobileInteraction:Pe.mobileInteraction,customHoverBehavior:Pe.customHoverBehavior,customClickBehavior:Pe.customClickBehavior}),...(B&&B.length>0||Ie.length>0)&&{annotations:[...B||[],...Ie]},...$&&{xExtent:$},...W&&{yExtent:W},...Pe.crosshairProps,...G};return Pe.earlyReturn?Pe.earlyReturn:Ee?Zt(se,{componentName:"AreaChart",message:Ee,width:ae,height:ce}):Zt(de,{componentName:"AreaChart",width:ae,height:ce,children:Zt(I,{ref:o,...Oe})})}).displayName="AreaChart";var no="__semiotic_resolvedX",ao="__semiotic_resolvedY",co="__compoundGroup";function lo(e,t,o){const i=e[t],r=e[o];return null==i||null==r||Number.isNaN(i)||Number.isNaN(r)}function uo(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=ro(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,d=t?ye(l,c,a):void 0,u=!1!==r.showLine,h="number"==typeof r.lineWidth?r.lineWidth:2,p="number"==typeof r.areaOpacity?r.areaOpacity:.7,m=y(r.yAccessor),g=r.styleRules;return(e,o)=>{const i=t&&d?ve(e,t,d):"string"==typeof r.color?r.color:ne,s={fill:i,fillOpacity:p,stroke:u?i:"none",...u&&{strokeWidth:h}};return g?.length&&Object.assign(s,x(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 ho(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=ro(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,d=t?ye(l,c,a):void 0,u=r.sizeBy,h=Array.isArray(r.sizeRange)?r.sizeRange:[5,40],p=u?s.map(e=>"function"==typeof u?u(e):Number(e[u])).filter(Number.isFinite):[],m=p.length?wt(p):void 0;return e=>({fill:t&&d?ve(e,t,d):"string"==typeof r.color?r.color:ne,fillOpacity:"number"==typeof r.bubbleOpacity?r.bubbleOpacity:.6,r:u?we(e,u,h,m):h[0],stroke:r.stroke??r.bubbleStrokeColor??"white",strokeWidth:r.strokeWidth??r.bubbleStrokeWidth??1,...void 0!==r.opacity&&{opacity:r.opacity}})}function po(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=ro(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,d=t?ye(l,c,a):void 0,u=r.sizeBy,h=Array.isArray(r.sizeRange)?r.sizeRange:[3,15],p=u?s.map(e=>"function"==typeof u?u(e):Number(e[u])).filter(Number.isFinite):[],m=p.length?wt(p):void 0,g=b(r.xAccessor,r.yAccessor),f=r.styleRules;return e=>{const o={fill:t&&d?ve(e,t,d):"string"==typeof r.color?r.color:ne,fillOpacity:"number"==typeof r.pointOpacity?r.pointOpacity:.8,r:u?we(e,u,h,m):"number"==typeof r.pointRadius?r.pointRadius:5};return f?.length&&Object.assign(o,x(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}}var mo={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||ho(e,t,o,i,r),showLegend:i.showLegend??!!t})};function go(e,t,o,i,r){if(!r.showPoints)return;const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=ro(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,d=t?ye(l,c,a):void 0,u="number"==typeof r.pointRadius?r.pointRadius:3;return e=>{const o=t&&d?ve(e,t,d):"string"==typeof r.color?r.color:ne;return{r:u,fill:o,stroke:"none"}}}var fo={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=ro(i.theme).colors.categorical,l=function(e,t,o,i,r){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=ro(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,d=t?ye(l,c,a):void 0,u=b(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,d)=>{const u={strokeWidth:t},h=!0===n||Array.isArray(n)&&null!=d&&n.includes(d);let p;return s?p=s(e,d):o?i&&(p=ve(e,o,i)):p=r||ne,void 0!==p&&(u.stroke=p,h&&(u.fill=p,u.fillOpacity=a)),c?.length&&Object.assign(u,x(e,c,l?l(e,d):{value:void 0,category:d})),u}}({lineWidth:"number"==typeof r.lineWidth?r.lineWidth:2,colorBy:t,colorScale:d,color:"string"==typeof r.color?r.color:void 0,fillArea:r.fillArea,areaOpacity:"number"==typeof r.areaOpacity?r.areaOpacity:.3,styleRules:r.styleRules,ruleContext:u});return zt(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),d=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?no:t,n=r?ao:o;return i||r?{xKey:s,yKey:n,rows:e.map(e=>{const s={...e};return i&&(s[no]=t(e)),r&&(s[ao]=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 d,u,h="string"==typeof i||"function"==typeof i?i:void 0,p=e.baseLineStyle;if(e.forecast){const t=i&&"string"==typeof i&&"object"==typeof e.forecast?{...e.forecast,_groupBy:i}:e.forecast,o=M(s,a,c,t,e.anomaly);if(s=o.processedData,l.push(...o.annotations),d=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,[co]:`${e[i]}__${e[k]||"observed"}`})),h=co):h=k,e.baseLineStyle){const t=P(t=>e.baseLineStyle(t),e.forecast);p=e=>t(e)}}else e.anomaly&&l.push(..._(e.anomaly));if(e.gapStrategy){if("function"==typeof h){const e=h;s=s.map(t=>({...t,__semiotic_gapGroup:e(t)})),h="__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)lo(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)lo(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)lo(e,o,i)?c():s.push(e);c()}return{rows:n,groupKey:a}}(s,e.gapStrategy,a,c,"string"==typeof h?h:void 0);s=t.rows,t.groupKey&&(h=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",d=c.fontSize||11,u="function"==typeof o?o:e=>e[o],h=new Map;for(const t of e){const e=u(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=ye(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?ve({__lbl:e},"__lbl",m):a||ne,fontSize:d}));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;d+2>Math.abs(Number(o[r])+o.dy-i)&&(o.dy+=d+2)}const f=g.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*d)),0)+10;return{annotations:g,marginExtra:"end"===l?{right:f}:{left:f}}}(s,e.directLabel,"string"==typeof r||"function"==typeof r?r:void 0,a,c,e.colorScheme,e.themeCategorical,e.color);l.push(...t.annotations),u=t.marginExtra}return{data:s,xAccessor:"function"==typeof t?a:t,yAccessor:"function"==typeof o?c:o,groupAccessor:h,colorAccessor:r,annotations:l,lineStyle:p,yExtent:d,marginExtra:u}}({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}),u=i.pointStyle||go(d.data,d.colorAccessor,o,i,r);let h=i.margin;d.marginExtra&&h&&"object"==typeof h?h={...h,...null!=d.marginExtra.right&&{right:Math.max(Number(h.right)||0,d.marginExtra.right)},...null!=d.marginExtra.left&&{left:Math.max(Number(h.left)||0,d.marginExtra.left)}}:d.marginExtra&&null==h&&(h={top:20,right:d.marginExtra.right??20,bottom:30,left:d.marginExtra.left??40});const p=(!r.directLabel||void 0!==i.showLegend)&&(i.showLegend??!!d.colorAccessor);return{chartType:a,data:d.data,xAccessor:d.xAccessor,yAccessor:d.yAccessor,groupAccessor:d.groupAccessor,colorAccessor:d.colorAccessor,colorScheme:o,lineStyle:d.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:d.annotations,...d.yExtent&&!i.yExtent&&{yExtent:d.yExtent},...u&&{pointStyle:u},showLegend:p}}},yo={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,d="down"===r.direction?U({data:s,timeAccessor:n,valueAccessor:a,binSize:Number(r.binSize),valueExtent:l,extentPadding:r.extentPadding}):l,u={...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:d,extentPadding:r.extentPadding??i.extentPadding,binSize:r.binSize,categoryAccessor:c,barColors:r.colors||i.barColors,colorScheme:r.colors||i.colorScheme,barStyle:i.barStyle||u,showLegend:i.showLegend??!!c}}},bo={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:eo(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||uo(n,s,o,i,r),...l&&{pointStyle:l}}}},xo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=r.xAccessor||"x",n=r.seriesAAccessor||"a",a=r.seriesBAccessor||"b",c=e=>oo(to(s,"x",e)),l=e=>oo(to(n,"a",e)),d=e=>oo(to(a,"b",e)),u=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 d=(e,t)=>e>t?"A":t>e?"B":null,u=e=>`seg-${n}-${e}`,h=e=>s.push(e),p=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:u(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=d(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:u(a),__diffWinner:a,__valA:t,__valB:t}),n++,a=y,h({__x:e,__y:t,__y0:t,__diffSegment:u(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:u(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:u(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,d),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=d(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")?u:h,stroke:"none",fillOpacity:p}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?u: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:u},{label:b,color:h}]}]},legendPosition:x}}}},vo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=t||r.areaBy,n="string"==typeof s&&Array.isArray(e)?ye(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,x(e,c,{value:t(e),category:o}))}return i}),l=r.normalize?"zero":r.baseline??"zero",d=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,...d&&{pointStyle:d},curve:i.curve??r.curve??"monotoneX",showLegend:i.showLegend??!!s}}},Ao={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)}}},wo={frameType:"xy",buildProps:(e,t,o,i,r)=>{const s=i.pointStyle||po(e,t,o,i,r),n=A(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}}},So={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,d=r.quadrantLabelSize??12,u=c.stroke||"#999",h=c.strokeWidth??1,p=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,m=Lt.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+d,fill:a.topLeft.color,fontWeight:600,fontSize:d,opacity:.5},a.topLeft.label),m("text",{key:"ltr",x:i-8,y:8+d,fill:a.topRight.color,fontWeight:600,fontSize:d,opacity:.5,textAnchor:"end"},a.topRight.label),m("text",{key:"lbl",x:8,y:r-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:d,opacity:.5},a.bottomLeft.label),m("text",{key:"lbr",x:i-8,y:r-8,fill:a.bottomRight.color,fontWeight:600,fontSize:d,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return m(Lt.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:u,strokeWidth:h,strokeDasharray:p}),m("line",{key:"hc",x1:0,y1:y,x2:i,y2:y,stroke:u,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||po(e,t,o,i,r),...i,showLegend:i.showLegend??!!t,...g&&{svgPreRenderers:g}}}},ko={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:oo(to(t.orderAccessor,"order",e))-oo(to(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=oo(to(o,"x",e)),r=oo(to(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=oo(to(o,"x",e)),r=oo(to(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?io(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=io(e,t.length);100>t.length&&o.push(Lt.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(Lt.createElement("line",{key:"segment-"+e,x1:i.x,y1:i.y,x2:r.x,y2:r.y,stroke:s,strokeWidth:n,strokeLinecap:"round"}))}return Lt.createElement(Lt.Fragment,null,...o)}]}}};function _o(e){return Math.max(0,Math.min(1,e))}function Mo(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 Po(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 Ro(e,t){const o=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:_o(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=_o(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=Mo(t.color),c=Mo(r.color);if(!a||!c)return.5>n?t.color:r.color;const[l,d,u]=a,[h,p,m]=c;return Po(l+(h-l)*n,d+(p-d)*n,u+(m-u)*n)}return o[o.length-1].color}function Io(e,t,o){return null==o?`${e}-${t}`:`${e}-${t}-${o}`}import{Fragment as To,jsx as Lo,jsxs as Co}from"react/jsx-runtime";import{useMemo as zo,useCallback as Fo,useRef as Bo}from"react";var jo={RdBu:mt,PiYG:pt,PRGn:ht,BrBG:ut,RdYlBu:gt,RdYlGn:ft,Spectral:yt},Eo="__likert_neutral_neg",Oo="__likert_neutral_pos";function Do(e,t){if("function"==typeof e)return e;const o=e||t;return e=>e[o]}import*as No from"react";function $o(e){return!0===e?{topOpacity:.8,bottomOpacity:.05}:!1===e?void 0:e}function Wo(e,t,o,i,r){const s=ro(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,d=t?ye(l,c,n??s):void 0,u=$e("string"==typeof r.color?r.color:void 0,s,n,void 0,new Map),h=y(r.valueAccessor),p=r.styleRules,m=i.pieceStyle;return(e,o)=>{const i={fill:t&&d?ve(e,t,d):u};return p?.length&&Object.assign(i,x(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 Go(e,t,o,i,r){const s=Wo(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 Yo(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=ro(i.theme).colors.categorical,l=o??i.colorScheme,d=t?ye(a,n,l??c):void 0,u=$e("string"==typeof r.color?r.color:void 0,c,l,void 0,new Map);return e=>{const o=t&&d?ve(e,t,d):u;return{fill:o,fillOpacity:.6,stroke:r.stroke??o,...void 0!==r.strokeWidth&&{strokeWidth:r.strokeWidth},...void 0!==r.opacity&&{opacity:r.opacity}}}}function Ho(e,t,o,i,r){const s=Wo(e,t,o,i,r),n="number"==typeof r.dotRadius?r.dotRadius:5;return(e,t)=>({r:n,fillOpacity:.8,...s(e,t)})}function Vo(e,t,o,i,r){const s=Wo(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):[],d=l.length?wt(l):void 0,u="number"==typeof r.pointRadius?r.pointRadius:4,h="number"==typeof r.pointOpacity?r.pointOpacity:.7;return(e,t)=>({r:a?we(e,a,c,d):u,fillOpacity:h,...s(e,t)})}var Xo={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:$o(i.gradientFill),pieceStyle:Wo(e,t,o,i,r)})},qo={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:$o(i.gradientFill),pieceStyle:Wo(e,s,o,i,r),showLegend:i.showLegend??!!s}}},Qo={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:$o(i.gradientFill),pieceStyle:Wo(e,s,o,i,r),showLegend:i.showLegend??!!s}}},Ko={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:Wo(e,s,o,i,r),showLegend:i.showLegend??!!s}}},Uo={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:Wo(e,s,o,i,r)}}},Zo={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:Go(e,t,o,i,r)}}},Jo={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||Go(e,t,o,i,r)})},ei={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||Yo(e,t,o,i,r),showLegend:i.showLegend??!!t,...r.valueExtent&&{rExtent:r.valueExtent}})},ti={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||Vo(e,t,o,i,r),showLegend:i.showLegend??!!t})},oi={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:Ho(e,t,o,i,r),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!t})},ii={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:$o(i.gradientFill),pieceStyle:i.pieceStyle||Wo(e,s,o,i,r),showLegend:i.showLegend??!!s,barPadding:r.barPadding??40}}},ri={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,...Wo(e,t,o,i,r)(s,n)})),showLegend:i.showLegend??!!t})},si={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,Do(r.categoryAccessor,"question"),r.levelAccessor?null:Do(r.valueAccessor,"score"),r.levelAccessor?Do(r.levelAccessor,"level"):null,r.levelAccessor?Do(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===Eo?s=o:o.__likertLevel===Oo?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:Eo,__likertPct:-e}),s.push({...t,__likertLevel:Oo,__likertPct:e})}else s.push(r>e?{...t,__likertPct:-t.__likertPct}:t)}return s}(a,s),s));const c=ro(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),d=new Map(s.map((e,t)=>[e,l[t]||"#888"])),u=s.length%2&&d.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:d.get(e.label)||"#888"})}]},m=me(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===Eo||t===Oo?u:d.get((e.__likertLevelLabel||e.data?.__likertLevelLabel||t)+"")||"#888"}},showLegend:i.showLegend??!0,legendPosition:i.legendPosition||"right",...m&&{legend:m},__legendIncludesAutomatic:!0}}},ni={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:Wo(e,n,o,i,r),showLabels:r.showLabels??!0}}},ai={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 Co(To,{children:[o.showNeedle&&Co(To,{children:[Lo("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"}),Lo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:r})]}),null!=o.contextValue&&Lo("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",d=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return Co("g",{children:[Lo("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"}),Lo("text",{x:o.centerX+Math.cos(r)*a,y:o.centerY+Math.sin(r)*a,textAnchor:l,dominantBaseline:d,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,d=n.arcWidth??.3,u=!1!==n.showNeedle,h=!1!==n.fillZones,{startAngleDeg:p}=t(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:d=240}=e,u=o-t||1,h=(Math.max(t,Math.min(o,i))-t)/u;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.colorStops.length>=2,g=[],f=new Map,y=[];if(m){const e=a?h:1,t=Io("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(d)),o=Math.max(1,Math.min(t,Math.round(e*t))),i=[];for(let t=0;o>t;t++)i.push(Ro(l.colorStops,e*(t+.5)/o));const r=Io("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)/u,s=(e-t)/u,c=(i.value-t)/u,l=Math.max(0,(a?Math.min(h,c):c)-s),d=a?Math.max(0,r-l):0;if(l>0){const e=Io("fill",o);g.push({category:e,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),f.set(e,{fill:i.color})}if(d>0){const e=Io("bg",o);g.push({category:e,value:d,_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&&"object"==typeof g&&"colorStops"in g?g:void 0}),[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-d))),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)),P="function"==typeof n.valueFormat?n.valueFormat(M):Math.round(M)+"",R=n.centerContent??s.centerContent,I=null!=R?"function"==typeof R?R(M,a,c):R:"sparkline"===n.mode||"context"===n.mode?void 0:No.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},No.createElement("div",{style:{fontSize:Math.max(16,.3*A),fontWeight:700,color:"var(--semiotic-text, #333)"}},P),!1!==n.showScaleLabels&&No.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!=I&&{centerContent:I},showAxes:!1,annotations:[...Array.isArray(s.annotations)?s.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:a,gMax:c,sweep:l,arcWidth:d,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:u,needleColor:n.needleColor,..."context"===n.mode&&null==R&&{contextValue:P,contextValueY:k-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*A))}}}}};import{scaleTime as ci}from"d3-scale";function li(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 di(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?At(s.map(e=>e.time)):null,l=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,d=null!=l?l-1:null!=c&&Number.isFinite(c)?c-1:null,u=[...new Set(s.map(e=>e.time))].sort((e,t)=>e-t),h=new Map;for(let e=1;u.length>e;e++)h.set(u[e],u[e-1]);const p=e=>{const t=h.get(e);return null!=t?(t+e)/2:null!=d?d: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!==d&&(m.push({time:d,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 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 R=null;for(const e of i)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===R||e.systemOutTime>R)&&(R=e.systemOutTime);if(k.length>0){const e=k[k.length-1],t=Math.max(null!=M?M:-1/0,null!=R?R:-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:S}}function ui(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function hi(e,t){return e.map(e=>({t:ui(e.t,t),topMass:e.topMass,botMass:e.botMass}))}function pi(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 mi(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 gi(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 fi(e,t){return 1e3*mi(e,t)+gi(e,t)}function yi(e,t){return{slots:e.map(e=>({peak:{...e.peak},occupants:e.occupants.slice()})),map:{...t}}}function bi(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=yi(e,t),n=fi(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]),d=new Map;c.forEach((e,t)=>d.set(e,t));for(const e of Object.keys(t))t[e]=d.get(t[e]);e.length=0;for(const t of l)e.push(t);const u=fi(t,o);if(n>u)n=u,s=yi(e,t);else if(u===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=fi(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=fi(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(),d=1/0;const u=()=>{for(const e of s)c[e]=a[r[e]];const e=fi(c,o);d>e&&(d=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};u();const p=Array(i).fill(0);let m=0;for(;i>m;)m>p[m]?(h(m%2==0?0:p[m],m),u(),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 xi(e,t,o,i,r){const{plotH:s,padding:n,valueScale:a,packing:c,laneOrder:l,lifetimeMode:d="full"}=r,u={},h={};for(const t of e)u[t.id]=o[t.id].topPeak||0,h[t.id]=o[t.id].botPeak||0;const p="half"===d,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,u[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:u[e.id],botPeak:h[e.id]}}),g[e.id]=t});let y=null,b=null,x=null,v=null;const A=()=>{y=mi(g,t),x=gi(g,t)},w=()=>{b=mi(g,t),v=gi(g,t)};"crossing-min"===l?(A(),bi(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]),d=new Map;s.forEach((e,t)=>d.set(e,t));for(const e of Object.keys(t))t[e]=d.get(t[e]);e.length=0;for(const t of l)e.push(t)}(f,g),w()):"crossing-min+inside-out"===l&&(A(),bi(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=fi(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 d=new Map;for(let e=0;i>e;e++)d.set(e,e);if(c>r){for(let e=r+1;c>=e;e++)d.set(e,e-1);d.set(r,c)}else{for(let e=c;r>e;e++)d.set(e,e+1);d.set(r,c)}for(const e of Object.keys(t))t[e]=d.get(t[e]);const u=fi(t,o);if(u>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=u}}(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 P=n+(f[0]?.peak.topPeak??0)*a;f.length>0&&M.push(P);for(let e=1;f.length>e;e++)P+=_[e-1]*a+n,M.push(P);if(f.length>0&&(P+=f[f.length-1].peak.botPeak*a+n),P>s){const e=s/P;for(let t=0;M.length>t;t++)M[t]*=e}const R=0===f.length?0:f[0].peak.topPeak+_.reduce((e,t)=>e+t,0)+f[f.length-1].peak.botPeak,I={};for(const t of e)I[t.id]=M[g[t.id]];return{effectiveSlotsHeight:R,centerlines:I,laneLifetime:m,slots:f,slotByNode:g,slotCenter:M,crossingsBefore:y,crossingsAfter:b,lengthBefore:x,lengthAfter:v}}function vi(e){const{nodes:t,edges:o,domain:i,plotW:r,plotH:s,ribbonLane:n,edgeOpacity:a,colorOf:c,layoutOpts:l}=e,d=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),u=ci().domain(i).range([0,r]);if(d.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:d,xScale:u};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 d={};for(const t of e)d[t.id]=di(t,c,l);const u=xi(e,t,d,c,{plotH:i,padding:12,valueScale:1,packing:s,laneOrder:n,lifetimeMode:a}),h=new Set;for(const e of t){const t=u.slotByNode[e.source],o=u.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)u.slotByNode[t.source]===u.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)u.slotByNode[o.source]===u.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")););}d={};for(const t of e)d[t.id]=di(t,c,l);const p=xi(e,t,d,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=xi(e,t,d,c,{plotH:i,padding:g,valueScale:f,packing:s,laneOrder:n,lifetimeMode:a});return{nodeData:d,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=hi(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,u,i);if(!s)return;const n=hi(r.samples,i),a=n.find(e=>e.topMass+e.botMass>0)||n[0],l=p[e.id]+(a.botMass-a.topMass)*g/2,d=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=hi(s.samples,r),l=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],u=i(l.t),h=i(d.t),p=e=>i(ui(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(u,r);if(i>s){const[o,c]=pi(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]=pi(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,u,i);f.push({id:e.id,pathD:s,fill:d,stroke:d,strokeWidth:.5,...y.length>0&&{gradientStubs:y},rawDatum:e.__raw??e,labelX:u(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,d=s(l(e.time)),u=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?d+.85*(u-d):"target"===n?d+.15*(u-d):(d+u)/2;return{sx:d,sTop:f,sBot:y,tx:u,tTop:b,tBot:x,cp1X:v,cp2X:v}}(t,p[e.source],o,p[e.target],g,u,n,i),{pathD:d,bezier:h}=O(l);y.push({id:e.id,pathD:d,fill:s,opacity:a,rawDatum:e.__raw??e,bezier:h})}),{layout:h,layoutConfig:{bands:f,ribbons:y,showLabels:!0},issues:[],xScale:u}}var Ai=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 wi(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 Si(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 ki from"react";function _i(e,t){return t?"function"==typeof t?o=>({...e(o),...t(o)??{}}):o=>({...e(o),...t}):e}var Mi={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=ro(i.theme).colors.categorical,d=new Map,u=r.nodeStyle??(e=>({fill:t?ve(e?.data||e,t,void 0):$e(void 0,l,o,void 0,d),..."number"==typeof r.nodeSize&&{r:r.nodeSize}})),h=v(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)=>({...u(e),...h(e,t)}):u,edgeStyle:c,...i}}},Pi={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",d=r.startTimeAccessor||"startTime",u=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:Si([],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(d,e)),endTime:s(f(u,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,P=i.legendPosition??"right",R=i.__explicitMargin,I=e=>"number"==typeof R||null!=R&&"object"==typeof R&&null!=R[e];M&&("right"!==P||I("right")?"bottom"!==P||I("bottom")||(_.bottom=Math.max(_.bottom,80)):_.right=Math.max(_.right,140));const T=_,L=S-T.left-T.right,C=k-T.top-T.bottom,z=ro(i.theme),F=Oe(o,z.colors.categorical,xt),B="function"==typeof t?t:null,j=B?x.map(e=>({_cat:B(e)})):x,E=B?"_cat":"string"==typeof t?t:void 0,O=o??[...F],D=E?ye(j,E,O):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 B?ve({_cat:B(o)},"_cat",D??void 0):ve(o,"string"==typeof t?t:"id",D??void 0)}return F[o%F.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=me(W,i.legend),{layout:Y,layoutConfig:H,issues:V,xScale:X}=vi({nodes:A,edges:w,domain:v,plotW:L,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(V.length>0){const e=V.map(li).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(L,e)),i=o(e??0),n=Math.max(i,o(t??L)),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 ki.createElement("g",null,...a.map(({index:e,x:t})=>ki.createElement("line",{key:"grid-"+e,x1:t,y1:0,x2:t,y2:C,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),ki.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 ki.createElement("g",{key:"tick-"+t,transform:`translate(${o},${C+4})`},ki.createElement("line",{y2:6,stroke:"#94a3b8"}),ki.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},n))}))})():void 0;return{chartType:"force",nodes:x,edges:y,customNetworkLayout:Ai,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:T}}},Ri={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,o,i,r)=>{const s=Array.isArray(r.nodes)?r.nodes:Si([],Array.isArray(r.edges)?r.edges:[],r.sourceAccessor||"source",r.targetAccessor||"target"),n=ro(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,d=t?ye(l,c,o??i.colorScheme??n):void 0,u=e=>({fill:t?ve(e?.data||e,t,d):$e(void 0,n,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=v(r.styleRules,t,r.valueAccessor),p=h?(e,t)=>({...u(e),...h(e,t)}):u,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=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:d,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}}},Ii={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:Si([],s,r.sourceAccessor||"source",r.targetAccessor||"target"),a=ro(i.theme).colors.categorical,c=Oe(o,a),l="string"==typeof t?t:"__ssrChordColorBy",d="function"==typeof t?n.map(e=>({...e,__ssrChordColorBy:t(e)})):n,u=t?ye(d,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=ve(r,t,u);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=v(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}}},Ti={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=ro(i.theme).colors.categorical,n=new Map,a=wi(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreeColorBy:c(e)})):a,d=c?"__ssrTreeColorBy":"string"==typeof t?t:void 0,u=t&&d?ye(l,d,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:_i(e=>{const a=e?.data||e;return{fill:r.colorByDepth?ce[Number(e?.depth||0)%ce.length]:t?c?ve({__ssrTreeColorBy:c(a)},"__ssrTreeColorBy",u??void 0):ve(a,t,u??void 0):$e(void 0,s,o,void 0,n),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h)}}},Li={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=ro(i.theme).colors.categorical,n=new Map,a=wi(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrTreemapColorBy:c(e)})):a,d=c?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,u=t&&d?ye(l,d,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:_i(e=>{const i=e?.data||e;return{fill:r.colorByDepth?ce[Number(e?.depth||0)%ce.length]:t?c?ve({__ssrTreemapColorBy:c(i)},"__ssrTreemapColorBy",u??void 0):ve(i,t,u??void 0):$e(void 0,s,o,void 0,n),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},f)}}},Ci={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,i,r)=>{const s=ro(i.theme).colors.categorical,n=new Map,a=wi(e??null,r.childrenAccessor),c="function"==typeof t?t:null,l=c?a.map(e=>({__ssrCirclePackColorBy:c(e)})):a,d=c?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,u=t&&d?ye(l,d,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:_i(e=>{const i=e?.data||e;return{fill:r.colorByDepth?ce[Number(e?.depth||0)%ce.length]:t?c?ve({__ssrCirclePackColorBy:c(i)},"__ssrCirclePackColorBy",u??void 0):ve(i,t,u??void 0):$e(void 0,s,o,void 0,n),fillOpacity:r.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h)}}},zi={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Fi}from"d3-scale";function Bi(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=Fi(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?g(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},Bi):n;return{areas:r.areas,projection:r.projection||"equalEarth",areaStyle:a,valueAccessor:r.valueAccessor,colorScheme:s,graticule:r.graticule,fitPadding:r.fitPadding,...i}}},Ei={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=ye(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=wt(e))}return e=>({fill:t&&s?ve(e,t,s):ne,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?we(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?g(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||zi,pointStyle:a,sizeBy:r.sizeBy,colorBy:t,colorScheme:o,projection:r.projection||"equalEarth",graticule:r.graticule,fitPadding:r.fitPadding,...i}}},Oi={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",d="function"==typeof c?c:e=>e[c],u="function"==typeof l?l:e=>e[l],h=(r.nodes||[]).map(e=>({...e,x:d(e),y:u(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 ye(e,y,o||"category10")}return ye(f,m,o||"category10")})(),x=e=>m&&b?ve(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,P=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||zi,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:P,opacity:M,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...i}}};import*as Di from"react";function Ni(e){const t=Vi(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 $i(e,t,o,i){return o?"function"==typeof o?o(e,t):e[o]??i:i}function Wi(e){return`gauntlet:${e}:core`}function Gi(e,t){return`gauntlet:${e}:positive:${t}`}function Yi(e,t,o){return`gauntlet:${e}:negative:${t}:${o}`}var Hi={left:28,top:76,rightInset:30,thickness:8};function Vi(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return Hi;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 Xi(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function qi(e,t,o,i){const r=Vi(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 Qi(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 Ki(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 Ui(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),d=.22*i,u=l>1?(.78*i-d)/(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(d+t*u),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=$i(e,t,o.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",n=i.map(e=>e.id),a=[...$i(e,t,o.positiveAccessor,n)],c=[...$i(e,t,o.negativeAccessor,[])].filter(e=>r.has(e));return{id:s,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...$i(e,t,o.metricsAccessor,{})},missingPositiveIds:n.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number($i(e,t,o.startTimeAccessor,0))||0),stage:"project filed",viability:$i(e,t,o.initialViability,100)}}(t,n,s,o,r);return{...a,viability:e.viability?.(a,{negativeProperties:r,positiveProperties:i})??Ki(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=Xi(o),c=Math.max(3,28*a),l=i.startX,d=i.startY+(i.startY===o.routeY?38*t*a:0),u=n?.(e,t,o,i)??{},h=u.x??l,p=u.y??d,m={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...u,id:Wi(e.id),x:h,y:p,vx:u.vx??42,vy:u.vy??0,mass:u.mass??7,bodyCollisions:u.bodyCollisions??!0,shape:u.shape??{type:"circle",radius:c},spawnAt:u.spawnAt??e.startedAt,datum:m}],f=qi(h,p,u.shape&&"radius"in u.shape&&Number(u.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=Qi(e.activePositiveIds,t,a),n=i.radius??Math.max(2,10*a),c=qi(f.x+Math.cos(s.angle)*s.radius,f.y+Math.sin(s.angle)*s.radius,n,o);g.push({id:Gi(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:u.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:Wi(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=Xi(s),c=t.radius??Math.max(2,7.2*a),l=qi(i+(o%4*12-12)*a,r+(54+12*Math.floor(o/4))*a,c,s);return{id:Yi(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:Wi(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,u.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:Ni(t)}}}var Zi=1e-9;function Ji(e,t){return t>e?-1:e>t?1:0}function er(e){return{...e}}function tr(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 or(e){const t=Object.fromEntries(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:er(t.initialMetrics),metrics:er(t.metrics),productIds:[...t.productIds],history:tr(t.history)}])),o=Object.fromEntries(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:er(t.metrics),sourceIds:[...t.sourceIds],history:tr(t.history)}])),i=Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?er(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:o,relations:i,input:{amount:e.input.amount,metrics:er(e.input.metrics)},metrics:er(e.metrics),loss:{amount:e.loss.amount,metrics:er(e.loss.metrics)},history:tr(e.history)}}function ir(e,t,o,i,r){return{severity:e,code:t,message:o,path:i,ids:r?[...r]:void 0}}function rr(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(Ji)}function sr(e,t){return e?Object.entries(e).flatMap(([e,o])=>Number.isFinite(o)?[]:[ir("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function nr(e,t){for(const[o,i]of Object.entries(t))e[o]=Number(e[o]??0)+i}function ar(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(ir("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(ir("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,d=t.outletIds?new Set(t.outletIds):null;let u=r.filter(e=>!a||a.has(e.id)).filter(e=>!c||c.has(e.category)).filter(e=>!l||l.has(e.status)).filter(e=>!d||void 0!==e.outletId&&d.has(e.outletId)).map(e=>e.id).sort(Ji);return void 0!==t.count&&(u=u.slice(0,t.count)),u.length||i.push(ir("warning","empty-selector","Selector matched no source components.",o)),{ids:u,diagnostics:i}}function cr(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 lr(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 dr(e,t,o){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(ir("error","unknown-outlet",`Unknown outlet "${t}".`,o,[t])),1))}function ur(e,t,o){const i=rr(t);t.length||e.diagnostics.push(ir("error","empty-source-list","A product requires at least one source component.",o)),i.length&&e.diagnostics.push(ir("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(ir("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(ir("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(ir("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 hr(e,t,o,i,r){const s=i?.amount??0;(!Number.isFinite(s)||0>s||s>t+Zi)&&e.diagnostics.push(ir("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",r+".amount")),e.diagnostics.push(...sr(i?.metrics,r+".metrics"));for(const[t,s]of Object.entries(i?.metrics??{}))(0>s||s>Number(o[t]??0)+Zi)&&e.diagnostics.push(ir("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 pr(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 mr(e,t,o,i){void 0!==t.amount&&Math.abs(t.amount-o)>Zi&&e.diagnostics.push(ir("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${o}.`,i,[t.id]))}function gr(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(ir("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,i+".state")),e.diagnostics.push(...sr(t.metricsDelta,i+".metricsDelta")),dr(e,t.outletId,i+".outletId");const o=ar(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(ir("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=cr(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&&nr(o.metrics,t.metricsDelta),o.history.push(n)}return r.history.push(n),void(o.ids.length&&lr(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(ir("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=rr(t),r=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(ir("error","insufficient-relation-sources","A relation requires at least two source components.",o)),i.length&&e.diagnostics.push(ir("error","duplicate-source",`Relation source ids must be unique: ${i.join(", ")}.`,o,i)),r.length&&e.diagnostics.push(ir("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(...sr(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=cr(e,t,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return r.history.push(n),void lr(e,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===t.type){const o=rr(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(ir("error","duplicate-relation","Relation ids must be unique.",i+".relationIds",o)),s.length&&e.diagnostics.push(ir("error","unknown-relation",`Unknown relation: ${s.join(", ")}.`,i+".relationIds",s)),n.length&&e.diagnostics.push(ir("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=cr(e,t,{relationIds:[...t.relationIds]});return r.history.push(a),void lr(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(ir("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(ir("error","duplicate-product",`Product "${t.productId}" has already been formed.`,i+".productId",[t.productId])),"contribute"!==t.type||s&&"forming"===s.status||e.diagnostics.push(ir("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,i+".productId",[t.productId]));const n=ur(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=rr(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(ir("error","duplicate-relation","Basis relations must be unique.",i,r)),s.length&&e.diagnostics.push(ir("error","unknown-relation",`Unknown basis relation: ${s.join(", ")}.`,i,s)),n.length&&e.diagnostics.push(ir("error","resolved-relation",`Basis relation is already resolved: ${n.join(", ")}.`,i,n)),c.length&&e.diagnostics.push(ir("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),d=function(e){const t={};for(const o of e)nr(t,o.metrics);return t}(n);if(!hr(e,l,d,t.loss,i+".loss"))return;const u=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,d,t.loss);const h="combine"===t.type&&!1!==t.complete,p=cr(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});let m;if("combine"===t.type){if(h&&mr(e,o,u,i+".productId"),m=pr(o,t.sourceIds,u,d,e,h,p),h&&!dr(e,m.outletId,i+".productId"))return;r.products[t.productId]=m}else m=s,m.sourceIds.push(...t.sourceIds),m.amount+=u,nr(m.metrics,d),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;lr(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,c),lr(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&&lr(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(!dr(e,a,s+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(ir("error","product-already-complete",`Product "${t.id}" is already complete.`,s,[t.id]));n&&(mr(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=cr(e,r,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0});t.history.push(c),e.state.history.push(c),lr(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(ir("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,i+".productId",[t.productId]))}if("split"===t.type){const o=ur(e,[t.sourceId],i+".sourceId");t.products.length||e.diagnostics.push(ir("error","empty-split","A split requires at least one product allocation.",i+".products"));const s=t.products.map(e=>e.productId),n=rr(s);n.length&&e.diagnostics.push(ir("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(ir("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,i+".products",c)),l.length&&e.diagnostics.push(ir("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(ir("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${i}.products.${o}.amount`)),e.diagnostics.push(...sr(r.metrics,`${i}.products.${o}.metrics`));if(!o?.length||e.diagnostics.some(e=>"error"===e.severity))return;const d=o[0];if(!hr(e,d.amount,d.metrics,t.loss,i+".loss"))return;const u=d.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(ir("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(()=>u/t.products.length),g=m.reduce((e,t)=>e+t,0);if(Math.abs(g-u)>Zi)return void e.diagnostics.push(ir("error","split-amount-mismatch",`Split allocations total ${g}, but ${u} remains after loss.`,i+".products"));const f={...d.metrics};for(const[e,o]of Object.entries(t.loss?.metrics??{}))f[e]=Number(f[e]??0)-o;const y=cr(e,t,{sourceIds:[d.id],productIds:s});if(t.products.forEach((o,s)=>{const n=a[s],c=u>Zi?m[s]/u:1/t.products.length,l=Object.fromEntries(Object.entries(f).map(([e,t])=>[e,t*c])),h=o.metrics??n.metrics??l,p=pr({...n,amount:m[s],metrics:h},[d.id],m[s],{...h},e,!0,y);dr(e,p.outletId,`${i}.products.${s}.productId`)&&(r.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;d.productIds=s,d.status="consumed",d.outletId=void 0,d.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),lr(e,{type:"split-source",sourceIds:[d.id],productIds:s});for(const t of s)lr(e,{type:"complete-product",sourceIds:[d.id],productIds:[t],outletIds:r.products[t].outletId?[r.products[t].outletId]:void 0});return}if("eject"===t.type){dr(e,t.outletId,i+".outletId");const o=ar(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(ir("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=cr(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&&lr(e,{type:"retarget-component",sourceIds:o.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...sr(t.metricsDelta,i+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let o,s;if("run"===t.target)nr(r.metrics,t.metricsDelta);else if("components"in t.target){const s=ar(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)nr(r.components[e].metrics,t.metricsDelta)}else{s=[...t.target.productIds];const o=rr(s),n=s.filter(e=>!r.products[e]);if(o.length&&e.diagnostics.push(ir("error","duplicate-product","Metric target product ids must be unique.",i+".target.productIds",o)),n.length&&e.diagnostics.push(ir("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)nr(r.products[e].metrics,t.metricsDelta)}return void r.history.push(cr(e,t,{sourceIds:o,productIds:s}))}t.outcome.trim()?(r.outcome=t.outcome,r.summary=t.summary,r.history.push(cr(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(ir("error","invalid-outcome","Outcome must be a non-empty string.",i+".outcome"))}function fr(e,t,o){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[ir("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};const i=or(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(gr(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 yr=[900,520],br=[{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}],xr=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),vr=1e-9;function Ar(e,t){return t>e?-1:e>t?1:0}function wr(e,t,o,i,r){return{severity:e,code:t,message:o,path:i,ids:r?[...r]:void 0}}function Sr(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(Ar)}function kr(e){const t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function _r(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(wr("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,s)),i}}function Mr(e,t,o){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(wr("error","invalid-metrics","Metrics must be a numeric object.",o)),{};const i={};for(const[r,s]of Object.entries(e)){const e=kr(s);null!=e?i[r]=e:t.push(wr("error","invalid-metric",`Metric "${r}" must be finite.`,`${o}.${r}`))}return i}function Pr(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 Rr(e){const{id:t,orientation:o,fixed:i,start:r,end:s,openings:n,thickness:a,friction:c,restitution:l}=e,d=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+vr).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),r=[];let s=e;for(const[e,t]of i)e>s+vr&&r.push([s,e]),s=Math.max(s,t);return t>s+vr&&r.push([s,t]),r}(r,s,n);return d.map(([e,r],s)=>({id:1===d.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 Ir(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 Tr(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?Ir(e):1}function Lr(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:Tr(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Cr(e){return"crucible:component:"+encodeURIComponent(e)}function zr(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>vr?i[0]+(i[1]-i[0])*Math.sqrt(Math.max(0,e-r)/(s-r)):(i[0]+i[1])/2}function Fr(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 Br(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 Er(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 Or(e,t,o={}){const i=Object.values(e.products).sort((e,t)=>Ar(e.id,t.id)),r=Object.values(e.components).sort((e,t)=>Ar(e.id,t.id)),s=[...r.map(e=>e.amount),...i.map(e=>e.amount)],n=Fr(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)||Ar(e.id,t.id));const o=Br(r.length,Er(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*zr(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 d=new Map;for(const[e,o]of l){const i=Br(o.length,Er(t,"__chamber__"===e?void 0:e));o.forEach((e,t)=>d.set(e.id,i[t]))}return[...r.map(e=>{let i=d.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=Ir(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=zr(e.amount,s,o.bodyRadius,n),c={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Cr(e.id),x:i.x,y:i.y,mass:Math.max(.25,r*r*.015),shape:{type:"circle",radius:r},datum:c}}),...c]}var Dr=Or;function Nr(e){return Array.isArray(e)?e.map(Nr):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>Ar(e,t)).map(([e,t])=>[e,Nr(t)])):e}function $r(e,t=e.duration){const o=function(e,t){const o=kr(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-vr,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=or(e.initialState);const r=[],s=[],n=[];for(const t of e.events){if(t.authoredAt>o.elapsed+vr)break;const a=fr(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 Wr(e){const t=function(e){const t=[];e.length||t.push(wr("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Sr(e.map(e=>e.id));o.length&&t.push(wr("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let i=0;return{phases:e.map((e,o)=>{const r=kr(e.duration),s=null!=r&&r>0?r:0;e.id.trim()||t.push(wr("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=r&&r>0||t.push(wr("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(wr("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=Pr(e.outlets??br),r=(e.products??[]).map(e=>({...e,metrics:e.metrics?{...e.metrics}:void 0})),s=function(e,t,o){const i=[],r=Sr(e.map(e=>e.id));r.length&&i.push(wr("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(wr("error","invalid-event-id","Event ids may not be empty.",`events.${r}.id`)),"time"in e.at&&void 0!==e.at.time){const s=kr(e.at.time);if(null==s||0>s||s>o+vr)return void i.push(wr("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=>vr>=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}:vr>=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(wr("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(wr("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(wr("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=((_r(n,a,e.idAccessor,c,t,`data.${a}.id`)??c)+"").trim();if(!l)return void t.push(wr("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));i.push(l);const d=kr(_r(n,a,e.amountAccessor,1,t,`data.${a}.amount`)),u=null==d||0>d?0:d;(null==d||0>d)&&t.push(wr("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=Mr(_r(n,a,e.metricsAccessor,{},t,`data.${a}.metrics`),t,`data.${a}.metrics`),p=_r(n,a,e.initialStateAccessor,"active",t,`data.${a}.status`),m=xr.has(p)?p:"active";xr.has(p)||t.push(wr("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[l]));const g=_r(n,a,e.labelAccessor,(n.label??n.name??l)+"",t,`data.${a}.label`)+"",f=_r(n,a,e.categoryAccessor,"component",t,`data.${a}.category`)+"";o[l]||(o[l]={id:l,label:g,category:f,datum:n,status:m,initialAmount:u,amount:u,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},r+=u,function(e,t){for(const[o,i]of Object.entries(t))e[o]=Number(e[o]??0)+i}(s,h))});const n=Sr(i);n.length&&t.push(wr("error","duplicate-component-id",`Component ids must be unique: ${n.join(", ")}.`,"data",n));const a=Mr(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=yr,t=br){const o=Math.max(1,kr(e[0])??900),i=Math.max(1,kr(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},d=r?Math.max(12,.08*o):Math.min(150,.17*o),u=a.y+a.height+(r?12:38),h=l.y-(r?10:34),p={x:d,y:u,width:Math.max(24,o-2*d),height:Math.max(24,h-u)},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=Pr(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,d-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??yr,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(...Rr({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}),...Rr({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}),...Rr({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=Sr(t.map(e=>e.id)),s=Sr(e.map(e=>e.id));return r.length&&o.push(wr("error","duplicate-outlet-id",`Outlet ids must be unique: ${r.join(", ")}.`,"outlets",r)),s.length&&o.push(wr("error","duplicate-product-id",`Product ids must be unique: ${s.join(", ")}.`,"products",s)),t.forEach((e,t)=>{e.id.trim()||o.push(wr("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0===e.order||Number.isFinite(e.order)||o.push(wr("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||o.push(wr("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(wr("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(wr("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Mr(e.metrics??{},o,`products.${t}.metrics`)}),o}(r,i),d=(u={seed:e.seed??1,components:Object.values(n.state.components).sort((e,t)=>Ar(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(Nr(u)));var u;const h=function(e,t,o={}){const i=Object.values(e.components).sort((e,t)=>Ar(e.id,t.id)),r=i.map(e=>e.amount),s=Fr(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}}(Tr(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),d=Math.max(4,.12*t.chamber.height);return i.map((e,t)=>{const u=t/Math.max(1,i.length)*Math.PI*2+.18*(n()-.5),h=zr(e.amount,r,o.bodyRadius,s),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Cr(e.id),x:a+Math.cos(u)*l*(.45+.45*n()),y:c+Math.sin(u)*d*(.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:Lr(e.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:d,diagnostics:p},g=$r(m),f=Object.values(g.state.products).filter(e=>"forming"===e.status).map(e=>e.id),y=f.length?[wr("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=Dr(g.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),m.diagnostics=[...p,...g.diagnostics,...y],m}import*as Gr from"react";import{jsx as Yr,jsxs as Hr}from"react/jsx-runtime";function Vr(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 Xr(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,d=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=d+"-glow";return Hr(Gr.Fragment,{children:[Yr("defs",{children:Yr("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Yr("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:n,floodOpacity:"0.8"})})}),Yr("polygon",{points:t,fill:n,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),Yr("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})]},d)}return Hr(Gr.Fragment,{children:[Yr("circle",{cx:e.x,cy:e.y,r:s,fill:n,stroke:a,strokeWidth:c,opacity:l}),Yr("circle",{cx:e.x-.25*s,cy:e.y-.28*s,r:Math.max(1,.18*s),fill:"rgba(255,255,255,0.34)"})]},d)}import{Fragment as qr,jsx as Qr,jsxs as Kr}from"react/jsx-runtime";var Ur="var(--semiotic-text, #26323a)",Zr="var(--semiotic-text-secondary, #6c7377)",Jr="var(--semiotic-accent, #b8792d)",es="var(--semiotic-negative, #9f3d35)",ts="var(--semiotic-positive, #356b63)";function os(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 is({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 Kr("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[Kr("defs",{children:[Kr("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[Qr("stop",{offset:"0",stopColor:Jr,stopOpacity:"0.03"}),Qr("stop",{offset:"0.66",stopColor:Jr,stopOpacity:"0.1"}),Qr("stop",{offset:"1",stopColor:es,stopOpacity:"0.18"})]}),Qr("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:Qr("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Ur,strokeOpacity:"0.08",strokeWidth:"1"})})]}),Qr("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:Ur,strokeOpacity:"0.52",strokeWidth:i?1:2.2}),Qr("path",{d:os(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),Qr("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:Ur,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:i?2:5}),i?null:Qr("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,d=o.phaseIndex>s||o.complete;return Kr("g",{children:[Qr("rect",{x:a,y:e.phaseRail.y,width:Math.max(1,c-2),height:e.phaseRail.height,rx:2,fill:l?i.color??Jr:d?ts:Ur,fillOpacity:l?.68:d?.28:.09}),46>c?null:Qr("text",{x:a+c/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:l?Ur:Zr,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=>Kr("g",{children:[Qr("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?es:ts),fillOpacity:"0.1",stroke:e.color??("left"===e.side?es:ts),strokeDasharray:"3 3",strokeOpacity:"0.62"}),i?null:Qr("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:Zr,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function rs({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 Qr("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 d=s[o],u=Math.max(d>0?2:0,d/n*l),h=t.projection.x+o*a+.18*a;return Kr("g",{children:[Qr("rect",{x:h,y:t.projection.y+l-u,width:Math.max(3,.64*a),height:u,rx:2,fill:"failed"===e.status||"ejected"===e.status?es:"complete"===e.status?Jr:ts,fillOpacity:"0.68"}),c>4&&a>=34?Kr(qr,{children:[Qr("text",{x:h+.32*a,y:t.projection.y+l+10,fill:Zr,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),Kr("text",{x:h+.32*a,y:t.projection.y+l+19,fill:Ur,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Vr(d),"amount"===r&&i?" "+i:""]})]}):null]},e.key)})})}function ss(e){return e.map(e=>({...e,spawnAt:void 0}))}function ns(e,t){return e?t?o=>Di.createElement(Di.Fragment,null,e,"function"==typeof t?t(o):t):e:t}var as=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function cs(e){let t=2166136261;for(let o=0;e.length>o;o+=1)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return as[(t>>>0)%as.length]}var ls={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:fo,AreaChart:bo,DifferenceChart:xo,StackedAreaChart:vo,Scatterplot:wo,CandlestickChart:Ao,BubbleChart:mo,ConnectedScatterplot:ko,QuadrantChart:So,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:yo,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:Xo,StackedBarChart:qo,GroupedBarChart:Qo,PieChart:Ko,DonutChart:Uo,Histogram:Zo,BoxPlot:Jo,ViolinPlot:ei,SwarmPlot:ti,DotPlot:oi,SwimlaneChart:ii,RidgelinePlot:ri,LikertChart:si,FunnelChart:ni,GaugeChart:ai,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:Mi,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:Ri,ProcessSankey:Pi,ChordDiagram:Ii,TreeDiagram:Ti,Treemap:Li,CirclePack:Ci,ChoroplethMap:ji,ProportionalSymbolMap:Ei,FlowMap:Oi,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,c=s.seed??1,d=Math.max(1,Math.round(s.pegRows??a-1)),u="mechanical"===s.mode,h=u?l({bins:a,branchProbability:s.branchProbability,count:s.mechanicalCount,pegRows:d,seed:c}):Array.isArray(e)?e:[],p=r({data:h,valueAccessor:s.valueAccessor||"value",bins:a,ballRadius:s.ballRadius??4,seed:c,size:n,valueExtent:u?[0,d]:void 0});return{...i,config:p.config,initialSpawns:ss(p.initialSpawns),projectionRows:p.projectionRows,bodyStyle:m(t||s.colorBy||(u?"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:ss(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:m(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?d({categories:r.mechanicalCategories,count:r.mechanicalCount,seed:r.seed??1,unitValue:r.unitValue??1}):Array.isArray(e)?e:[],l=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:l.config,initialSpawns:ss(l.initialSpawns),projectionRows:l.projectionRows,bodyStyle:m(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:ss(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:m(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=c({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=a.metadata;return{...i,config:a.config,initialSpawns:ss(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:l?.regionEffects,bodyStyle:m(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=Ui({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:ss(n.initialSpawns),projectionRows:[],bodyStyle:m(t||r.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[900,520],n=Wr({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}),c="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,kr(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,kr(t.progress??0)??0));return o.start+o.duration*i}(n,r.snapshotAt):n.duration,l=$r(n,c).state,d=r.projection&&"object"==typeof r.projection?r.projection:{groupBy:"outlet",measure:"count"},u=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 nr(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)||Ji(e.key,t.key))}(l,d),h=d.measure??"count",p=a(u.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:Di.createElement(is,{layout:n.layout,phases:n.phases,state:l,compact:520>s[0]||360>s[1]}),y=!1===r.showProjection?null:Di.createElement(rs,{rows:u,layout:n.layout,projection:d,amountLabel:r.amountLabel});return{...i,config:n.config,initialSpawns:ss(Or(l,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??cs(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??cs(a)}}(e,l,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,l),renderBodySVG:Xr,backgroundGraphics:ns(f,i.backgroundGraphics),foregroundGraphics:ns(y,i.foregroundGraphics)}}},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:ss(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:m(t||r.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,o,i,r)=>{const s=i.size??[700,380],n=p({chartId:r.chartId,colorScheme:o,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Rt(_t)??{},size:s,themeCategorical:_t.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:n.config,initialSpawns:ss(n.initialSpawns),projectionRows:[],bodyStyle:n.result.bodyStyle??m(t||r.colorBy)}}}};function ds(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function us(e){if(!e||2>e.length)return;const t=ds(e[0]),o=ds(e[e.length-1]);return null!==t&&null!==o?[t,o]:void 0}function hs(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 ps from"react";import*as ms from"react-dom/server";import{scaleOrdinal as gs}from"d3-scale";import{jsx as fs,jsxs as ys}from"react/jsx-runtime";var bs=ae;function xs(e,t,o){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>We(e,t)??"#999"}const i=Array.isArray(t)?t:o.colors.categorical.length>0?o.colors.categorical:xt;return gs().domain(e).range(i)}function vs(e){return"left"===e?"start":"right"===e?"end":e??"start"}function As(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function ws(e,t,o,i){const r=As(i);return t+o+Math.ceil(e.length*r*.58)}function Ss(e){const{categories:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:d}=Ge(n),u=a+c,h="top"===i||"bottom"===i,p=Math.max(a,r-s.left-s.right),m=t.map(e=>ws(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=vs(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*d}),r+=m[e]+l}),{items:c,width:Math.max(0,...o.map(e=>e.width)),height:o.length*d,swatchSize:a,labelOffset:u,swatchRadius:0}}const g=Math.max(0,...m);return{items:t.map((e,t)=>({category:e,width:m[t],x:0,y:t*d})),width:g,height:t.length*d,swatchSize:a,labelOffset:u,swatchRadius:0}}function ks(e){const{legendGroups:t,theme:o,position:i="right",totalWidth:r,margin:s,legendLayout:n}=e,{swatchSize:a,labelGap:c,rowHeight:l}=Ge(n),d=a+c,u=Math.max(12,As(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=vs(n?.align);let s=0,c=0;const l=[];for(const r of t){const t=r.items.map(e=>e.label),d=Ss({...e,categories:t,legendLayout:{...n,maxWidth:Math.max(a,i-u-8),align:"start"}}),h=r.label?u:0,p=r.label?ws(r.label,0,0,o):0,m=h>0?h+8:0,g=m+d.width,f=Math.max(d.height,p);l.push({group:r,x:s,y:0,itemOffsetX:m,itemOffsetY:0,width:g,height:f,items:d.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:d,swatchRadius:0}}const m=Pe(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=>ws(e.label,a,c,o)),r=Math.max(0,...i,e.label?ws(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:d,swatchRadius:0}}function _s(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 Ms(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 Ps,jsxs as Rs}from"react/jsx-runtime";var Is=16;function Ts(e,t){return e.color||t.colors.annotation||t.colors.text}function Ls(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 Cs(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 zs(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 Fs(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,d={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}:{}},u=e.autoPlaceAnnotations?lt({annotations:r,context:d,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):r,h=Fe(u,(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=Ts(e,s),c=e.label,l=e.labelPosition||"right",d=e.strokeDasharray||"6,4",u=e.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:Rs("g",{opacity:e.opacity,children:[Ps("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:u,strokeDasharray:d}),c&&Ps(re,{x:o+4,y:Is,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Ls(e,s,"halo")})]},"ann-ythresh-"+t)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:Rs("g",{children:[Ps("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:u,strokeDasharray:d}),c&&Ps(re,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Is):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Ls(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=Ts(e,s),l=e.label,d=e.labelPosition||"top";return Rs("g",{opacity:e.opacity,children:[Ps("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:c,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),l&&Ps(re,{x:a>.6*r.width?a-4:a+4,y:"bottom"===d?r.height-4:"center"===d?r.height/2:Is,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:c,fontFamily:s.typography.fontFamily,text:l,background:Ls(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 d=Math.min(c,l),u=Math.abs(l-c),h=nt(e.fill||Ts(e,s),"ssr-band-"+t),p=e.fillOpacity??.1;return Rs("g",{opacity:e.opacity,children:[h.def&&Ps("defs",{children:h.def}),Ps("rect",{x:0,y:d,width:r.width,height:u,fill:h.fill,fillOpacity:p}),e.label&&Ps(re,{x:r.width-4,y:Math.max(d,0)+Is,textAnchor:"end",fontSize:s.typography.tickSize,fill:e.color||Ts(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ls(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 d=Math.min(c,l),u=Math.abs(l-c),h=nt(e.fill||Ts(e,s),"ssr-xband-"+t),p=e.fillOpacity??.1;return Rs("g",{opacity:e.opacity,children:[h.def&&Ps("defs",{children:h.def}),Ps("rect",{x:d,y:0,width:u,height:r.height,fill:h.fill,fillOpacity:p}),e.label&&Ps(re,{x:d+4,y:Is,textAnchor:"start",fontSize:s.typography.tickSize,fill:e.color||s.colors.primary||Ts(e,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ls(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=Ts(e,s),l=e.opacity??.1,d=e.label;return Rs("g","horizontal"===o.projection?{children:[Ps("rect",{x:0,y:n,width:r.width,height:a,fill:c,opacity:l}),d&&Ps(re,{x:12,y:n+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:d,background:Ls(e,s,"none")})]}:{children:[Ps("rect",{x:n,y:0,width:a,height:r.height,fill:c,opacity:l}),d&&Ps(re,{x:n+a/2,y:Is,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:d,background:Ls(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:Cs(e,t,o),y:zs(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),d=e.dy??(c?0:-30),u=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 Ps(ue,{noteData:{x:o,y:r,dx:l,dy:d,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:i,...s?{subject:s}:{},connector:e.connector||{end:"arrow"},color:u,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return Ps("g",{children:Ps("text",{x:o+l,y:r+d,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||s.typography.labelSize,fill:u,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,d);return h.length>0?Ps("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as Bs from"react";import{jsx as js,jsxs as Es}from"react/jsx-runtime";function Os(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function Ds(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 Ns(e,t,o){const i=e.showLegend&&!e.__legendIncludesAutomatic?function(e,t,o){if(0===e.length)return;const i=xs(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 me(i,e.legend)}var $s={right:110,left:110,top:50,bottom:80};function Ws(e,t){if(e.__autoLegendMargin&&!Gs(e,t))return $s[t]}function Gs(e,t){const o=e.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[t])}function Ys(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:Ws(o,a),preserveExplicitMargin:Gs(o,a)};if(null!=o.legend){const t=Ns(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}=ks(e);return{width:t,height:o,swatchSize:i}}({...i,legendGroups:t.legend.legendGroups}):_e(t.legend)?_s({...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}=Ss(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 Hs(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=Ns(t,o,i);if(Bs.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=ks(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??bs)),i=e.legendGroups.flatMap((i,r)=>{const s=t[r],n=i.type??"fill",a=[fs("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(fs("text",{y:s.labelY,fontSize:As(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:i.label},"legend-group-label-"+r)),a.push(fs("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?fs("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:a}):fs("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:a});return ys("g",{transform:`translate(0,${s*Math.max(o.swatchSize,e.legendLayout?.rowHeight??bs)})`,children:[c,fs("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:As(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${r}-${s}`)})},"legend-group-"+r)),a});return fs("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(fs("text",i?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:As(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label}:{x:t.x,y:t.y+As(e.theme),fontSize:As(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),d="function"==typeof a?a(c):"line"===a?fs("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):fs("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return ys("g",{transform:`translate(${t.x+t.itemOffsetX+i.x},${t.y+t.itemOffsetY+i.y})`,children:[d,fs("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:As(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(fs("line",{x1:e,y1:0,x2:e,y2:o.height,stroke:r},"legend-group-separator-"+s))}return c});return fs("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=_s(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 fs("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 ys("g",{className:"semiotic-legend",transform:`translate(${s},${n})`,children:[fs("defs",{children:fs("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:a})}),e.gradient.label&&fs("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}),fs("rect",{x:0,y:l,width:t.width,height:o,fill:`url(#${i})`,rx:2}),fs("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])}),fs("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 ys("g",{className:"semiotic-legend",transform:`translate(${s},${n+(e.gradient.label?12:0)})`,children:[fs("defs",{children:fs("linearGradient",{id:i,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:a})}),e.gradient.label&&fs("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}),fs("rect",{x:0,y:0,width:14,height:100,fill:`url(#${i})`,rx:2}),fs("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])}),fs("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=xs(t,o,i),d="top"===r||"bottom"===r,u=Ss(e);let h,p;if("left"===r?(h=Math.max(4,a.left-(e.reservedWidth??100)-10),p=a.top):"top"===r?(h=a.left,p=c?32:8):"bottom"===r?(h=a.left,p=n-a.bottom+38):(h=s-a.right+10,p=a.top),d){const e=u.items.map((e,t)=>ys("g",{transform:`translate(${e.x},${e.y})`,children:[fs("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),fs("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:As(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return fs("g",{className:"semiotic-legend",transform:`translate(${h},${p})`,children:e})}const m=Pe([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??bs))[0],g=u.items.map((e,t)=>ys("g",{transform:`translate(${e.x},${e.y+m.itemsY})`,children:[fs("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),fs("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:As(i),fill:i.colors.text,fontFamily:i.typography.fontFamily,children:e.category})]},"legend-"+t));return ys("g",{className:"semiotic-legend",transform:`translate(${h},${p})`,children:[fs("line",{x1:0,y1:m.lineY,x2:e.reservedWidth??100,y2:m.lineY,stroke:"gray"}),g]})}({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 Vs(e){return Math.round(100*e)/100+""}function Xs(e,t){const o=so(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 Es("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&&js("title",{id:n,children:s}),t.description&&js("desc",{id:a,children:t.description}),t.defs&&js("defs",{children:t.defs}),i&&"transparent"!==i&&js("rect",{x:0,y:0,width:t.width,height:t.height,fill:i}),js("g",{id:r+"data-area",transform:t.innerTransform,children:e}),s&&js("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&&js("g",{id:r+"legend",children:t.legend}),t.outerElements]})}import{Fragment as qs,jsx as Qs,jsxs as Ks}from"react/jsx-runtime";function Us(e,t){const o=ro(e.theme),i=e.size||[500,300],r=Ee({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=Se(e.title),n=be(e.data),a=e.showLegend?Ms(n,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[];Ys(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,d="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),u=e.colorScheme||o.colors.categorical,h={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:d?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:d?void 0:e.xAccessor,yAccessor:d?void 0:e.yAccessor,timeAccessor:d?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor,categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,axisExtent:e.axisExtent,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:u,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},p=new R(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=hs({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})),ms.renderToStaticMarkup(Xs(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=Q({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>et(e,t,m)});t&&(t.evidence=hs({frameType:"xy",width:i[0],height:i[1],marks:g.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:us(p.scales.x?.domain?.()),yDomain:us(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}=so(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=J(e.x,a,r),d=J(e.y,c,r);return Es("g",{id:n+"grid",className:"semiotic-grid",opacity:.8,children:[l.map((o,i)=>{const r=e.x(o);return js("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},"gx-"+i)}),d.map((o,i)=>{const r=e.y(o);return js("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=Ds(e)+"-plot-clip",x=!1!==e.showAxes?function(e,t,o,i,r){const s=so(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=J(e.x,n,o.axisExtent).map(t=>({pixel:e.x(t),label:(o.xFormat||o.tickFormatTime||Vs)(t)})),l=J(e.y,a,o.axisExtent).map(t=>({pixel:e.y(t),label:(o.yFormat||o.tickFormatValue||Vs)(t)}));return Es("g",{id:(r?r+"-":"")+"axes",className:"stream-axes",children:[js("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),c.map((e,o)=>Es("g",{transform:`translate(${e.pixel},${t.height})`,children:[js("line",{y2:5,stroke:s.border,strokeWidth:1}),js("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"xtick-"+o)),o.xLabel&&js("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:o.xLabel}),js("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),l.map((e,t)=>Es("g",{transform:`translate(0,${e.pixel})`,children:[js("line",{x2:-5,stroke:s.border,strokeWidth:1}),js("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"ytick-"+t)),o.yLabel&&js("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})]})}(p.scales,{width:c,height:l},e,o,m):null,v=e.annotations?Fs({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 Qs(ps.Fragment,{children:e(p.scene,p.scales,{width:c,height:l})},"pre-"+t)}catch{return null}}).filter(Boolean):null,w=Hs({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s});return ms.renderToStaticMarkup(Xs(Ks(qs,{children:[e.backgroundGraphics,A,f,Qs("defs",{children:Qs("clipPath",{id:b,children:Qs("rect",{x:0,y:0,width:c,height:l})})}),Qs("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 Zs from"react-dom/server";import{scaleBand as Js,scaleLinear as en}from"d3-scale";var tn=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||le,r=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,r),r}};function on(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=at[r%at.length],r++,i.set(s,a)),a}}function rn(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,d=null!=i.sweepAngle&&360>i.sweepAngle,u=Object.values(o),h=u.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),p=d&&!h&&u.length>1&&(i.cornerRadius??0)>0;for(let e=0;u.length>e;e++){const t=u[e],o=t.pieceData[0],d="number"==typeof o?._pctStart?o._pctStart:t.pctStart,h=c+d*l,m=c+(d+("number"==typeof o?._pct?o._pct:t.pct))*l,g=r(t.pieceData[0],t.name),f=0===e,y=e===u.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 nn}from"d3-array";function an(e){const t=e.length,o=e[0],i=e[t-1];return{n:t,min:o,q1:nn(e,.25)??o,median:nn(e,.5)??(o+i)/2,q3:nn(e,.75)??i,max:i,mean:e.reduce((e,t)=>e+t,0)/t}}import{scaleLinear as cn}from"d3-scale";var ln={bar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getStack:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,d=[],u="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(u){const t=c(0>m?r:i+m),o=0>m?c(r+m)-c(r):c(i)-c(i+m);d.push(E(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);d.push(E(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 d){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 d){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 d},clusterbar:function(e,t){const{scales:o,columns:i,config:r,getR:s,getGroup:n,resolvePieceStyle:a}=e,{r:c,projection:l}=o,d=[],u="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(u){const s=e.x+n*t+o/2,a=c(0),u=c(l);d.push(E(s,Math.min(a,u),i,Math.abs(a-u),p,r,h[n]))}else{const s=e.x+n*t+o/2,a=c(0),u=c(l);d.push(E(Math.min(a,u),s,Math.abs(u-a),i,p,r,h[n]))}}}}const g=r.roundedTop&&r.roundedTop>0?Math.max(0,r.roundedTop):0;for(const e of d){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=s(e.datum);g>0&&(e.roundedTop=g),e.roundedEdge=u?0>t?"bottom":"top":0>t?"left":"right",r.gradientFill&&(e.fillGradient=r.gradientFill)}return d},point:function(e,t){const{scales:o,columns:i,getR:r,multiScales:s,resolvePieceStyle:n}=e,{r:a,projection:c}=o,l=[],d="vertical"===c,u="radial"===c,h=s.length>0,p=on(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(u){const t=g+(e.pctStart+e.pct/2)*m,o=c(i);b=Math.cos(t)*o,x=Math.sin(t)*o}else d?(b=e.middle,x=c(i)):(b=c(i),x=e.middle);rn(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,d=on(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),u=s(i,e.name),h=u.r||4,p=(7919*o%100/100-.5)*t*.8;rn(c,d,i,l?e.middle+p:n(a),l?n(a):e.middle+p,h,u)}}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=[],d="vertical"===c,u=!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=nn(o,.25)??i,h=nn(o,.5)??(i+r)/2,p=nn(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(u)for(const e of t.pieceData){const o=s(e);if(g>o||o>f){const i=d?t.middle:a(o),r=d?a(o):t.middle;v.push({px:i,py:r,value:o,datum:e})}}if(l.push({type:"boxplot",x:d?t.middle:0,y:d?0:t.middle,projection:d?"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}),u)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=[],d="vertical"===c,u=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)/u||1,c=Array(u).fill(0);for(const e of t)c[Math.min(Math.floor((e-o)/r),u-1)]++;const p=vt(c,1),m=e.width/2*.9;let g;if(d){g=`M ${e.middle} ${a(o)}`;for(let t=0;u>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=u-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;u>t;t++)g+=` L ${a(o+(t+.5)*r)} ${e.middle-c[t]/p*m}`;g+=` L ${a(i)} ${e.middle}`;for(let t=u-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=nn(t,.25)??o,s=nn(t,.5)??(o+i)/2,n=nn(t,.75)??i;y={q1Pos:a(r),medianPos:a(s),q3Pos:a(n),centerPos:e.middle,isVertical:d}}const b=d?{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:an(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,d=r.normalize,u=a.domain?.(),h=u?+u[0]:void 0,p=u?+u[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]=wt(t),r=null!=h&&isFinite(h)?h:o,u=null!=p&&isFinite(p)?p:i,m=(u-r)/l||1,g=Array(l).fill(0);for(const e of t)r>e||e>u||g[Math.min(Math.floor((e-r)/m),l-1)]++;const f=t.length,y=vt(g,1),b=n(e.pieceData[0],e.name);for(let t=0;l>t;t++){if(0===g[t])continue;const o=(d?g[t]/f:g[t]/y)*e.width*.9,i=a(r+t*m),s=a(r+(t+1)*m);c.push(E(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=[],d=r.bins||20,u="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)/d||1,c=Array(d).fill(0);for(const e of t)o>e||e>i||c[Math.min(Math.floor((e-o)/r),d-1)]++;const p=vt(c,1),m=n(e.pieceData[0],e.name),g=e.width*h;let f;if(u){const t=e.x+e.width;f=`M ${a(o)} ${t}`;for(let e=0;d>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;d>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=u?{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:an(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,d=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,d,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,d,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 d=[],u=new Set;for(const e of l)for(const t of e.pieceData){const e=r?r(t):"_default";u.has(e)||(u.add(e),d.push(e))}const h=d.length>1&&"_default"!==d[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;d.length>i;i++){const r=e.groups.get(d[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 d){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=cn().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,u=.55*l,m=i.x+(l-u)/2,y=new Map;if(h){let e=0;for(const t of d){const i=o.groups.get(t);i&&(e+=b(i.total))}let t=a,l=a;for(let h=0;d.length>h;h++){const p=d[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(E(A,m,x,u,w,k,p)),y.set(p,{x:A,y:m,w:x,h:u})}}else{const e=o.stepTotal,t=b(e),l=a-t/2,h=d[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(E(l,m,t,u,v,w,x)),y.set(h,{x:l,y:m,w:t,h:u})}if(t>0&&v.size>0){const t=h?d:[d[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=[],d=new Set;for(const e of c)for(const t of e.pieceData){const e=r?r(t):"_default";d.has(e)||(d.add(e),l.push(e))}const u=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=u?l.length:1,f=u?.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,d=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],u?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:u?h:o.name,__barFunnelLabelX:A+d/2,__barFunnelLabelY:m(f+v)};if(a.push(E(A,w,d,S,k,_,u?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:u?h:o.name};a.push(E(A,e,d,t,i,r,u?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=[],d="horizontal"===c,u=e.config.gradientFill,h=d?"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=d?E(s,o.x,n,o.width,i,null,"__track__"):E(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(d){const r=a(t),s=a(t+i);m=E(r,e.x,s-r,e.width,p,o,c)}else{const r=a(t+i),s=a(t);m=E(e.x,r,e.width,s-r,p,o,c)}u&&(m.fillGradient=u,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}:d?(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}},dn=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],un=["scene-style","data-paint","accessibility","evidence"],hn=(e,t)=>({retainedData:e,invalidations:t}),pn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],mn=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],gn=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],fn=["scene-geometry","data-paint","accessibility","evidence"],yn=["scene-style","data-paint","accessibility","evidence"],bn=[],xn={chartType:hn("rebuild",pn),runtimeMode:hn("rebuild",pn),categoryAccessor:hn("rebuild",pn),valueAccessor:hn("rebuild",pn),oAccessor:hn("rebuild",pn),rAccessor:hn("rebuild",pn),stackBy:hn("rebuild",pn),groupBy:hn("rebuild",pn),timeAccessor:hn("rebuild",pn),accessorRevision:hn("rebuild",pn),colorAccessor:hn("rebuild",yn),symbolAccessor:hn("rebuild",fn),connectorAccessor:hn("rebuild",fn),dataIdAccessor:hn("rebuild",fn),projection:hn("preserve",mn),extentPadding:hn("preserve",mn),axisExtent:hn("preserve",mn),rExtent:hn("preserve",mn),oExtent:hn("preserve",mn),multiAxis:hn("preserve",mn),normalize:hn("preserve",mn),bins:hn("preserve",mn),oSort:hn("preserve",gn),barPadding:hn("preserve",gn),roundedTop:hn("preserve",gn),baselinePadding:hn("preserve",gn),innerRadius:hn("preserve",gn),cornerRadius:hn("preserve",gn),startAngle:hn("preserve",gn),sweepAngle:hn("preserve",gn),trackFill:hn("preserve",gn),showOutliers:hn("preserve",gn),showIQR:hn("preserve",gn),amplitude:hn("preserve",gn),connectorOpacity:hn("preserve",gn),showLabels:hn("preserve",gn),dynamicColumnWidth:hn("rebuild",gn),customLayout:hn("preserve",gn),layoutConfig:hn("preserve",gn),layoutMargin:hn("preserve",gn),symbolMap:hn("preserve",fn),pieceStyle:hn("preserve",yn),summaryStyle:hn("preserve",yn),connectorStyle:hn("preserve",yn),gradientFill:hn("preserve",yn),colorScheme:hn("preserve",yn),themeCategorical:hn("preserve",yn),themeSemantic:hn("preserve",yn),themeSequential:hn("preserve",yn),themeDiverging:hn("preserve",yn),barColors:hn("preserve",yn),decay:hn("preserve",yn),pulse:hn("preserve",yn),staleness:hn("preserve",yn),layoutSelection:hn("preserve",yn),windowSize:hn("preserve",bn),windowMode:hn("preserve",bn),clock:hn("preserve",bn),transition:hn("preserve",bn),introAnimation:hn("preserve",bn),onLayoutError:hn("preserve",bn)},vn=hn("preserve",gn),An=class{constructor(){this.tracker=new ct}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}},dn)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},un):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const o=new Set;for(const i of e){const e=xn[i]??vn;"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 wn}from"d3-quadtree";var Sn=class{constructor(e){this.rExtent=new oe,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new An,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new tn,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 ie(e.windowSize),this.getO=st(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>rt(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new oe)):(this.getR=rt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=st(e.stackBy),this.getGroup=st(e.groupBy),this.getColor=st(e.colorAccessor),this.getSymbol=st(e.symbolAccessor),this.getConnector=st(e.connectorAccessor),this.getDataId=st(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new ie(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:Y(t,i):null)}currentTime(){return this.config.clock?.()??Ce()}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(),H(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const o of e.inserts)q(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=q(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),d="horizontal"===a,u="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(u){p=Js().domain(c).range([0,1]).padding(0);const o=Math.min(e.width,e.height)/2,i=t.innerRadius||0;m=en().domain(l).range([i,o])}else d?(p=Js().domain(c).range([0,e.height]).padding(h),m=en().domain(l).range([0,e.width])):(p=Js().domain(c).range([0,e.width]).padding(h),m=en().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),d?en().domain([n,a]).range([0,e.width]):en().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:d,getStack:u,rawRExtent:h}=e,p=n;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let m=0,g=0;if("bar"===o&&u&&r)m=0,g=1;else if("bar"===o&&u){const e=new Map,o=new Map;for(const i of t){const t=l(i),r=d(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=d(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(d(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=d(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={},d=new Map;for(const e of t){const t=a(e);d.has(t)||d.set(t,[]),d.get(t).push(e)}let u=0;if("radial"===r)for(const e of t)u+=Math.abs(c(e));let h=null;if(n&&"radial"!==r){h=new Map;let e=0;for(const t of o){const o=d.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=d.get(e)||[],o=t.reduce((e,t)=>e+Math.abs(c(t)),0),r=u>0?o/u: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=G("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 te({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=ln[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(),d=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 d?d(r.datum):d||{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,le),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:pe(r,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(e,t){const o=this.config.decay;return o&&t>1?$(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:wn().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,W(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 d=o.get(t),u=null==d?0:W(e,d,s);c=Z(l,u,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&&X(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=fe(e,this.activeTransition),o=ge(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=Re(i?i.opacity??1:0,e._targetOpacity,o)}const i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=Re(i.x,e._targetX,o),e.y=Re(i.y,e._targetY,o)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=Re(i.r,e._targetR,o))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const i=this.prevPositionMap.get(t);e.style.opacity=Re(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=Re(i.x,e._targetX,o),e.y=Re(i.y,e._targetY,o),void 0!==i.w&&(e.w=Re(i.w,e._targetW,o),e.h=Re(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:Re(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=Re(i.startAngle,e._targetStartAngle,o),e.endAngle=Re(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=ee(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=ee(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&&!ot(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!ot(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!ot(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in e||"oAccessor"in e)&&(ot(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=st(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)=>!ot(e,s[t])),r){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>rt(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new oe)):(this.getR=rt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!ot(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?st(this.config.stackBy):void 0),"groupBy"in e&&!ot(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?st(this.config.groupBy):void 0),"colorAccessor"in e&&!ot(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?st(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!ot(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?st(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!ot(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?st(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}};L(Sn);import{jsx as kn,jsxs as _n}from"react/jsx-runtime";import{Fragment as Mn,jsx as Pn,jsxs as Rn}from"react/jsx-runtime";function In(e,t){const o=ro(e.theme),i=e.size||[500,400],r=Ee({top:20,right:20,bottom:30,left:40,...e.margin},e.title),s=Se(e.title),n=be(e.data),a=e.showLegend?Ms(n,e.colorAccessor||e.stackBy||e.groupBy):[];Ys(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,d=e.projection||"vertical",u="radial"===d,h={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:d,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:Rt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:r,layoutSelection:e.layoutSelection,barColors:e.barColors},p=new Sn(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=hs({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:p.scales?[]:["NO_SCALES"],margin:r})),Zs.renderToStaticMarkup(Xs(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 m=e._idPrefix,g=e.showGrid?function(e,t,o,i,r){const s=e.scales;if(!s||"radial"===s.projection)return null;const{grid:n}=so(o),a=i?i+"-":"",c="vertical"===s.projection,l=J(s.r,5,r);return js("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((e,o)=>{const i=s.r(e);return js("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 js("line",{x1:i,y1:0,x2:i,y2:t.height,stroke:n,strokeWidth:.5},"gr-"+o)})})}(p,{width:c,height:l},o,m,e.axisExtent):null;let f=null;if(p.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){const t=Ds(e),i=new Set;for(const e of p.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&i.add("string"==typeof e.style.fill?e.style.fill:"#666");f=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 _n("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[o&&"transparent"!==o&&kn("rect",{width:a,height:a,fill:o}),kn("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:r}),kn("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 p.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 y=Q({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>ze(e,t,m)}),b=y.map(e=>e.element);if(t){const o=p.scales.o?.domain?.();t.evidence=hs({frameType:"ordinal",width:i[0],height:i[1],marks:y.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:us(p.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:r})}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=so(i),a="vertical"===s.projection,c=o.categoryFormat||o.oFormat,l=o.valueFormat||o.rFormat,d=o.categoryLabel||o.oLabel,u=o.valueLabel||o.rLabel,h=Object.values(e.columns).map(e=>({pixel:e.middle,label:(c||String)(e.name)})),p=J(s.r,5,o.axisExtent).map(e=>({pixel:s.r(e),label:(l||Vs)(e)}));return Rn("g",a?{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Pn("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),h.map((e,o)=>Rn("g",{transform:`translate(${e.pixel},${t.height})`,children:[Pn("line",{y2:5,stroke:n.border,strokeWidth:1}),Pn("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),d&&Pn("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:d}),Pn("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),p.map((e,t)=>Rn("g",{transform:`translate(0,${e.pixel})`,children:[Pn("line",{x2:-5,stroke:n.border,strokeWidth:1}),Pn("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),u&&Pn("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})]}:{id:(r?r+"-":"")+"axes",className:"ordinal-axes",children:[Pn("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:n.border,strokeWidth:1}),p.map((e,o)=>Rn("g",{transform:`translate(${e.pixel},${t.height})`,children:[Pn("line",{y2:5,stroke:n.border,strokeWidth:1}),Pn("text",{y:18,textAnchor:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oxtick-"+o)),u&&Pn("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:n.labelSize,fill:n.text,fontFamily:n.fontFamily,children:u}),Pn("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:n.border,strokeWidth:1}),h.map((e,t)=>Rn("g",{transform:`translate(0,${e.pixel})`,children:[Pn("line",{x2:-5,stroke:n.border,strokeWidth:1}),Pn("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:n.tickSize,fill:n.textSecondary,fontFamily:n.fontFamily,children:e.label})]},"oytick-"+t)),d&&Pn("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})]})}(p,{width:c,height:l},e,o,m):null,v=e.annotations?Fs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:n,scales:{o:p.scales.o,r:p.scales.r,y:"vertical"===p.scales.projection?p.scales.r:void 0},layout:{width:c,height:l},theme:o,projection:d,idPrefix:m}):null,A=Hs({props:e,categories:a,theme:o,size:i,margin:r,hasTitle:s}),w=u?r.left+c/2:r.left,S=u?r.top+l/2:r.top,k=u&&e.centerContent?Pn("foreignObject",{x:r.left,y:r.top,width:c,height:l,pointerEvents:"none",children:Pn("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return Zs.renderToStaticMarkup(Xs(Rn(Mn,{children:[e.backgroundGraphics,g,b,x,v,e.foregroundGraphics,p.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(${w},${S})`,innerWidth:c,innerHeight:l,legend:A,defs:f,outerElements:k,idPrefix:e._idPrefix}))}import*as Tn from"react-dom/server";import{Fragment as Ln,jsxs as Cn}from"react/jsx-runtime";function zn(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Fn=new Set(["tree","cluster","treemap","circlepack","partition"]);function Bn(e,t){const o=ro(e.theme),i=e.chartType||"force",r=()=>hs({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=Ee({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=Se(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 Ms(i,t);const r=Array.isArray(e.edges)?be(e.edges):[];if(0===r.length)return[];const s=zn(e.sourceAccessor,"source"),n=zn(e.targetAccessor,"target");return Ms(Array.from(new Set(r.flatMap(e=>[s(e),n(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];Ys(n,{props:e,categories:c,theme:o,size:s,hasTitle:a});const l=s[0]-n.left-n.right,d=s[1]-n.top-n.bottom,u=V(i);if(!u&&!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(Fn.has(i)){const i=e.data||e.edges;if(!i||Array.isArray(i))return t&&(t.evidence=r()),Tn.renderToStaticMarkup(Xs(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:d,idPrefix:e._idPrefix}));h.__hierarchyRoot=i,p=[],m=[]}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()),Tn.renderToStaticMarkup(Xs(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:d,idPrefix:e._idPrefix}));if(m=function(e,t){const o=zn(t.sourceAccessor,"source"),i=zn(t.targetAccessor,"target"),r=zn(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=Os(t.source),i=Os(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=zn(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=Ne(e,o.colors.categorical,xt),i=pe(t,e),r={nodes:p,edges:m,dimensions:{width:l,height:d,plot:{x:0,y:0,width:l,height:d}},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(u){u.computeLayout(p,m,h,[l,d]);const e=u.buildScene(p,m,h,[l,d]);g=e.sceneNodes,f=e.sceneEdges,y=e.labels}const x=so(o);for(const e of y)e.fill||(e.fill=x.text);const v=Q({nodes:f,renderMode:e.renderMode,fallback:(e,t)=>Te(e,t)}),A=Q({nodes:g,renderMode:e.renderMode,fallback:(e,t)=>Le(e,t)});t&&(t.evidence=hs({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)=>Ie(e,t)).filter(Boolean),_=e.annotations?Fs({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{},layout:{width:l,height:d},theme:o,idPrefix:e._idPrefix}):null,M=Hs({props:e,categories:c,theme:o,size:s,margin:n,hasTitle:a});return Tn.renderToStaticMarkup(Xs(Cn(Ln,{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:d,legend:M,idPrefix:e._idPrefix}))}import*as jn from"react-dom/server";import{geoPath as En}from"d3-geo";import{quadtree as On}from"d3-quadtree";import{geoMercator as Dn,geoEqualEarth as Nn,geoAlbersUsa as $n,geoOrthographic as Wn,geoNaturalEarth1 as Gn,geoEquirectangular as Yn}from"d3-geo";var Hn={mercator:Dn,equalEarth:Nn,albersUsa:$n,orthographic:Wn,naturalEarth:Gn,equirectangular:Yn};function Vn(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Xn(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function qn(e,t,o){return e?"function"==typeof e?{...o,...e(t)}:{...o,...e}:{...o}}function Qn(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 Kn(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,d=(e[1]+t[1])/2+a*c,u=[];for(let i=0;o>=i;i++){const r=i/o,s=1-r;u.push([s*s*e[0]+2*s*r*l+r*r*t[0],s*s*e[1]+2*s*r*d+r*r*t[1]])}return u}function Un(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 Zn(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,d=r/2+1;return[[e[0]+c*d,e[1]+l*d],[t[0]+c*d,t[1]+l*d]]}import{scaleLinear as Jn}from"d3-scale";var ea=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ta=["scene-style","data-paint","accessibility","evidence"],oa=(e,t)=>({retainedData:e,invalidations:t}),ia=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ra=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],sa=["scene-geometry","data-paint","accessibility","evidence"],na=["scene-style","data-paint","accessibility","evidence"],aa=["overlay","accessibility","evidence"],ca=[],la={xAccessor:oa("rebuild",ia),yAccessor:oa("rebuild",ia),lineDataAccessor:oa("rebuild",ia),pointIdAccessor:oa("rebuild",sa),lineIdAccessor:oa("rebuild",sa),windowSize:oa("rebuild",ia),projection:oa("preserve",ra),projectionExtent:oa("preserve",ra),fitPadding:oa("preserve",ra),lineType:oa("preserve",ra),flowStyle:oa("preserve",ra),graticule:oa("preserve",ra),projectionTransform:oa("preserve",ra),customLayout:oa("preserve",ra),layoutConfig:oa("preserve",ra),layoutMargin:oa("preserve",ra),areaStyle:oa("preserve",na),pointStyle:oa("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:oa("preserve",na),colorScheme:oa("preserve",na),themeCategorical:oa("preserve",na),themeDiverging:oa("preserve",na),themeSemantic:oa("preserve",na),themeSequential:oa("preserve",na),decay:oa("preserve",na),pulse:oa("preserve",na),layoutSelection:oa("preserve",na),annotations:oa("preserve",aa),autoPlaceAnnotations:oa("preserve",aa),clock:oa("preserve",ca),transition:oa("preserve",ca),introAnimation:oa("preserve",ca),onLayoutError:oa("preserve",ca)},da=oa("preserve",ra),ua=class{constructor(){this.tracker=new ct}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}},ea)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},ta):this.recordNoop("restyle")}recordConfig(e,t={}){const o=function(e){let t="preserve";const o=new Set;for(const i of e){const e=la[i]??da;"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 ha,geoGraticule as pa,geoInterpolate as ma}from"d3-geo";function ga(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 fa=class e{constructor(e){this.updateResults=new ua,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:ga(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??Ce()}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 ie(e),this.timestampBuffer=new ie(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:ga(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 ie(t),this.timestampBuffer=new ie(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();q(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)q(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 Nn();if("string"==typeof e){const t=Hn[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),Nn())}if("object"==typeof e&&"type"in e){const t=Hn[e.type],o=t?t():Nn();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=En(this.projection),this.fitProjection(e),this.geoPath=En(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 d=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=d,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=Vn(o.xAccessor,"lon"),s=Vn(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=Xn(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=En(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=En(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=En(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=On().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,le),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:pe(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=G("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 te({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=Vn(e.xAccessor,"lon"),c=Vn(e.yAccessor,"lat"),l=[],d=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),u=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=pa();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:qn(e.areaStyle,t,d),datum:t,interactive:!0})}const p=Xn(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=ha(i,s)||0,a=Math.max(2,Math.ceil(n/(Math.PI/180))),c=ma(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=qn(e.lineStyle,o,u),d="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?Un(r,d):Zn(r[0],r[r.length-1],0,0,d)):r=Kn(r[0],r[r.length-1]);const h=Qn(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&&ha([i,r],x)>f)continue;const s=t([i,r]);if(!s)continue;const n=e.pointStyle?e.pointStyle(o):{...h},d={type:"point",x:s[0],y:s[1],r:n.r||4,style:n,datum:o,pointId:m?m(o)+"":void 0};l.push(d)}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="strip"===t.layout?"strip":"radial";if("radial"===n&&0===s)return null;const a=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],l=r.find(e=>e.datum&&a(e.datum)+""==t.center+"");if(!l)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(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),u=vt(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 h="strip"===n?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=Jn().domain([0,i]).range([0,n]);t.x=s,t.y=a;const l=[];for(const i of e){if(i===t)continue;if(!i.datum){i.x=s,i.y=a;continue}const e=Number(o(i.datum)),r=s+(isFinite(e)&&e>=0?c(e):0);i.x=r,i.y=a,l.push({node:i,x:r})}l.sort((e,t)=>e.x-t.x);const d=Math.max(0,Math.min(r.height/2-1,6));let u=0;for(;l.length>u;){let e=u+1;for(;l.length>e&&3>Math.abs(l[e].x-l[u].x);)e++;const t=e-u;if(t>1&&d>0)for(let e=0;t>e;e++)l[u+e].node.y=a+(e-(t-1)/2)*Math.min(2.5,2*d/Math.max(1,t-1));u=e}return{cx:s,cy:a,maxCost:i,availableRadius:n,layout:"strip"}}(r,l,c,u,o):function(e,t,o,i,r,s){const n=t.x,a=t.y,c=Math.min(s.width,s.height)/2,l=Jn().domain([0,i]).range([0,c]);for(const i of e){if(i===t)continue;if(!i.datum)continue;const e=Math.atan2(i.y-a,i.x-n),s=Math.sqrt((i.x-n)**2+(i.y-a)**2),c=Number(o(i.datum)),d=s+((isFinite(c)?l(c):s)-s)*r;i.x=n+Math.cos(e)*d,i.y=a+Math.sin(e)*d}const d=s.width/2,u=s.height/2,h=d-t.x,p=u-t.y;if(Math.abs(h)>.5||Math.abs(p)>.5)for(const t of e)t.x+=h,t.y+=p;return{cx:d,cy:u,maxCost:i,availableRadius:c,layout:"radial"}}(r,l,c,u,s,o),p=e.filter(e=>"line"===e.type);if(p.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 p){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 h}(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=$(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=W(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&&X(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=fe(e,this.activeTransition),o=ge(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=Re(e.x,e._targetX,o),e.y=Re(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}};fa.QUADTREE_THRESHOLD=500;var ya=fa;L(ya);import{Fragment as ba,jsxs as xa}from"react/jsx-runtime";function va(e,t){const o=ro(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=Se(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 Ms(a.length>0?a:Array.isArray(n)&&n.length>0?"string"==typeof t?n.map(e=>({...e.properties||{},...e})):n:[],t)})():[];Ys(r,{props:e,categories:l,theme:o,size:i,hasTitle:s});const d=i[0]-(r.left??0)-(r.right??0),u=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:Rt(o)},p=new ya(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:d,height:u});const m=Q({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>xe(e,t)});if(t&&(t.evidence=hs({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?xa(ba,{children:[e.backgroundGraphics,e.annotations?Fs({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:d,height:u},theme:o,idPrefix:e._idPrefix}):null,e.foregroundGraphics,p.customLayoutOverlays]}):null;return jn.renderToStaticMarkup(Xs(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:d,innerHeight:u,idPrefix:e._idPrefix}))}const g=m.map(e=>e.element),f=e.annotations?Fs({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:d,height:u},theme:o,idPrefix:e._idPrefix}):null,y=Hs({props:e,categories:l,theme:o,size:i,margin:r,hasTitle:s});return jn.renderToStaticMarkup(Xs(xa(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:d,innerHeight:u,legend:y,idPrefix:e._idPrefix}))}function Aa(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=hs({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 wa,jsx as Sa,jsxs as ka}from"react/jsx-runtime";function _a(e,t){switch(e){case"xy":return Us(t);case"ordinal":return In(t);case"network":return Bn(t);case"geo":return va(t);case"physics":return Aa(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Ma(e){return Us(e)}function Pa(e){return In(e)}function Ra(e){return Bn(e)}function Ia(e){return va(e)}var Ta=["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"],La=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Ca(e,t){const o={};for(const i of t)void 0!==e[i]&&(o[i]=e[i]);return o}function za(e,t,o){return Ba(e,t).svg}function Fa(e,t,o){const i={},{svg:r,frameType:s}=Ba(e,t,0,i),n=i.evidence??hs({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 Ba(e,t,o,i){const r=ls[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=De(s,{...r.layout?.modeDefaults,...Ca(t,La)},r.layout?.primarySize),{data:a,theme:c,background:l,className:d,annotations:u,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=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}(S),_="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...w,...k},M=Ca(f,Ta),P=e=>v[e]??n[e],R={...v,...M,theme:c,title:n.title,description:n.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:l,className:d,annotations:u,size:x,margin:_,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==g&&{legendPosition:g},_idPrefix:f._idPrefix},I=r.buildProps(a,m,p,R,f);let T;switch(r.frameType){case"xy":T=Us(I,i);break;case"ordinal":T=In(I,i);break;case"network":T=Bn(I,i);break;case"geo":T=va(I,i);break;case"physics":T=Aa(I,i)}const L=r.renderOverlay?.(I,{theme:ro(c)});if(null!=L){const e=Tt.renderToStaticMarkup(Sa(wa,{children:L}));T=T.replace("</svg>",e+"</svg>")}return{svg:T,frameType:r.frameType}}function ja(e,t={}){const{title:o,subtitle:i,theme:r,width:s=1200,height:n,layout:a={},background:c}=t,l=so(ro(r)),d=a.columns||2,u=a.gap??16;let h=0;o&&(h+=30),i&&(h+=20),h>0&&(h+=10);const p=Math.floor((s-u-u*(d-1))/d),m=[];let g=0,f=h+u,y=0;for(const t of e){const e=Math.min(t.colSpan||1,d),o=t.props.height||300;g+e>d&&(f+=y+u,g=0,y=0),m.push({chart:t,x:u/2+g*(p+u),y:f,w:p*e+u*(e-1),h:o}),y=Math.max(y,o),g+=e}const b=n||f+y+u,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?za(o.component,c):o.frameType?_a(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${a}"></svg>`,Sa("g",{transform:`translate(${i},${s})`,children:Sa("foreignObject",{width:n,height:a,children:Sa("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+t)});return Tt.renderToStaticMarkup(ka("svg",{xmlns:"http://www.w3.org/2000/svg",width:s,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&Sa("title",{children:o}),c&&Sa("rect",{x:0,y:0,width:s,height:b,fill:c}),o&&Sa("text",{x:s/2,y:24,textAnchor:"middle",fontSize:l.titleSize+4,fontWeight:"bold",fill:l.text,fontFamily:l.fontFamily,children:o}),i&&Sa("text",{x:s/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),x]}))}import*as Ea from"react-dom/server";import{Fragment as Oa,jsx as Da,jsxs as Na}from"react/jsx-runtime";function $a(e,t,o,i={}){const{stepSize:r,windowSize:s,frameCount:n,xExtent:a,yExtent:c,transitionFrames:l=4,fps:d=12,easing:u="ease-out",decay:h}=i,p=o.width||600,m=o.height||400,g=ro(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=Ee({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 Sn(a);c.ingest({inserts:n,bounded:!0}),c.computeScene({width:A,height:w}),c.scene.length>0&&S.push(Xa(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/d),easing:u}}},x=new R(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(Va(x.scene,p,m,g,f,v)),l>0&&i>0&&x.activeTransition){const e=l*(1e3/d);for(let t=1;l>=t;t++)x.advanceTransition(x.activeTransition.startTime+t/l*e),S.push(Va(x.scene,p,m,g,f,v))}}return S}function Wa(e,t,o={}){return t.map(t=>{try{return za(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 Ga(e,t,o){const i=t.size??[t.width??600,t.height??400],r=ro(t.theme),s=so(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,d=[c,l].filter(Boolean).join(" ")||void 0,h=u(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),p=Na("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":d,style:{fontFamily:s.fontFamily},children:[t.title&&Da("title",{id:c,children:t.title}),t.description&&Da("desc",{id:l,children:t.description}),n&&"transparent"!==n?Da("rect",{x:0,y:0,width:i[0],height:i[1],fill:n}):null,Da("g",{id:`${a}-frame-${o}`,children:h.map((e,t)=>et(e,t,`${a}-${o}`))})]});return Ea.renderToStaticMarkup(p)}function Ya(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),d=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),u=i??Math.max(1,Math.ceil(r*Math.max(1,o))),h=c?{...e,background:c}:e,p=new S(e.config);e.initialSpawns?.length&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);const m=[];for(s&&(p.tick(0),m.push(Ga(p,h,0)));u>m.length;){for(let e=0;d>e;e+=1)p.tick(l);m.push(Ga(p,h,m.length))}return m}function Ha(e,t){const o=e.background||t.colors.background;return o&&"transparent"!==o?o:null}function Va(e,t,o,i,r,s){const n=so(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,d=Ha(r,i),u=r.renderMode,h=e.map((e,t)=>K({node:e,index:t,renderMode:u,fallback:()=>et(e,t)})).filter(Boolean),p=function(e,t,o,i,r,s){if(!e||0===e.length)return null;const n=so(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,d=c.labelPosition||"right";a.push(Na("g",{children:[Da("line",{x1:0,y1:e,x2:t,y2:e,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&Da("text",{x:"left"===d?4:"center"===d?t/2:t-4,y:20>e?Math.min(o-4,e+16):e-5,textAnchor:"left"===d?"start":"center"===d?"middle":"end",fontSize:n.tickSize,fill:l,fontFamily:n.fontFamily,children:c.label})]},"ann-"+i))}}return a.length>0?Da(Oa,{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 Ea.renderToStaticMarkup(Na("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":b,style:{fontFamily:n.fontFamily},children:[m&&Da("title",{id:f,children:m}),g&&Da("desc",{id:y,children:g}),d&&Da("rect",{x:0,y:0,width:t,height:o,fill:d}),Na("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),m&&Da("text",{x:t/2,y:he,textAnchor:"middle",fontSize:n.titleSize,fontWeight:"bold",fill:n.text,fontFamily:n.fontFamily,children:m})]}))}function Xa(e,t,o,i,r){const s=so(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,d=Ha(r,i),u=r.renderMode,h=e.map((e,t)=>K({node:e,index:t,renderMode:u,fallback:()=>ze(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 Ea.renderToStaticMarkup(Na("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":y,style:{fontFamily:s.fontFamily},children:[p&&Da("title",{id:g,children:p}),m&&Da("desc",{id:f,children:m}),d&&Da("rect",{x:0,y:0,width:t,height:o,fill:d}),Da("g",{transform:`translate(${c},${l})`,children:h}),p&&Da("text",{x:t/2,y:he,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}export{$a as generateFrameSVGs,Wa as generateFrameSequence,Ya as generatePhysicsFrameSVGs,za as renderChart,Fa as renderChartWithEvidence,ja as renderDashboard,Ia as renderGeoToStaticSVG,Ra as renderNetworkToStaticSVG,Pa as renderOrdinalToStaticSVG,_a as renderToStaticSVG,Ma as renderXYToStaticSVG,ro as resolveTheme,so as themeStyles};