semiotic 3.8.2 → 3.8.4

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 (195) hide show
  1. package/CLAUDE.md +9 -9
  2. package/README.md +42 -40
  3. package/ai/examples.md +1 -1
  4. package/ai/schema.json +2726 -300
  5. package/ai/surface-manifest.json +1 -1
  6. package/ai/system-prompt.md +1 -1
  7. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +0 -1
  8. package/dist/chunk-chunk-3ILKBVVQ.module.min.js +1 -0
  9. package/dist/{chunk-chunk-NO4MCQVD.module.min.js → chunk-chunk-5RKXZQ2P.module.min.js} +1 -1
  10. package/dist/{chunk-chunk-CYIML3AV.module.min.js → chunk-chunk-6TPGFL7M.module.min.js} +1 -1
  11. package/dist/{chunk-chunk-VVCA3DB7.module.min.js → chunk-chunk-7ALTGHK6.module.min.js} +1 -1
  12. package/dist/chunk-chunk-7KZJUTKP.module.min.js +2 -0
  13. package/dist/chunk-chunk-7RYBCTK5.module.min.js +1 -0
  14. package/dist/chunk-chunk-ACLDBMRH.module.min.js +2 -0
  15. package/dist/chunk-chunk-ANYDWOZF.module.min.js +1 -0
  16. package/dist/{chunk-chunk-ZLKRTF5N.module.min.js → chunk-chunk-AQPQN2HH.module.min.js} +1 -1
  17. package/dist/chunk-chunk-ASKSE5F5.module.min.js +1 -0
  18. package/dist/chunk-chunk-AVBI6GDT.module.min.js +1 -0
  19. package/dist/chunk-chunk-B3DRZPBK.module.min.js +2 -0
  20. package/dist/chunk-chunk-BFHUYEOS.module.min.js +2 -0
  21. package/dist/chunk-chunk-C4YA6TDR.module.min.js +1 -0
  22. package/dist/chunk-chunk-C57LR3YG.module.min.js +1 -0
  23. package/dist/chunk-chunk-EMO5NUGE.module.min.js +1 -0
  24. package/dist/chunk-chunk-F5V4UIE6.module.min.js +2 -0
  25. package/dist/chunk-chunk-F7WFPD4O.module.min.js +2 -0
  26. package/dist/chunk-chunk-FBGHXL72.module.min.js +2 -0
  27. package/dist/chunk-chunk-FP44FHFO.module.min.js +2 -0
  28. package/dist/chunk-chunk-HKXUAEPJ.module.min.js +2 -0
  29. package/dist/chunk-chunk-ICEXPNDC.module.min.js +2 -0
  30. package/dist/chunk-chunk-IY7RYD4S.module.min.js +1 -0
  31. package/dist/{chunk-chunk-7LHMKRKE.module.min.js → chunk-chunk-JDXT6ORT.module.min.js} +1 -1
  32. package/dist/chunk-chunk-JMVEIZXP.module.min.js +1 -0
  33. package/dist/chunk-chunk-KHCOJMGK.module.min.js +1 -0
  34. package/dist/chunk-chunk-KQ546MKE.module.min.js +2 -0
  35. package/dist/chunk-chunk-LQBSXO7K.module.min.js +2 -0
  36. package/dist/chunk-chunk-LRIFN2HK.module.min.js +1 -0
  37. package/dist/chunk-chunk-MFHF4J2Z.module.min.js +1 -0
  38. package/dist/chunk-chunk-N6VKKF3A.module.min.js +2 -0
  39. package/dist/chunk-chunk-NEVE562N.module.min.js +1 -0
  40. package/dist/chunk-chunk-NKZ75IM5.module.min.js +2 -0
  41. package/dist/chunk-chunk-PLIDPQNG.module.min.js +2 -0
  42. package/dist/{chunk-chunk-FYY2ACNJ.module.min.js → chunk-chunk-PRDGLMJT.module.min.js} +1 -1
  43. package/dist/chunk-chunk-QGZGZI4X.module.min.js +1 -0
  44. package/dist/chunk-chunk-RP7WTID5.module.min.js +1 -0
  45. package/dist/chunk-chunk-S7KLNUO6.module.min.js +1 -0
  46. package/dist/chunk-chunk-SR4ZXOWR.module.min.js +2 -0
  47. package/dist/chunk-chunk-ZOAQDIJO.module.min.js +1 -0
  48. package/dist/chunk-minimapBrushOverlay-JU57U7NM.module.min.js +2 -0
  49. package/dist/chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js +2 -0
  50. package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +1 -0
  51. package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +1 -0
  52. package/dist/components/ChartContainer.d.ts +2 -2
  53. package/dist/components/ai/chartCapabilityTypes.d.ts +5 -0
  54. package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
  55. package/dist/components/charts/geo/ChoroplethMap.d.ts +2 -0
  56. package/dist/components/charts/geo/DistanceCartogram.d.ts +7 -3
  57. package/dist/components/charts/geo/FlowMap.d.ts +4 -0
  58. package/dist/components/charts/geo/ProportionalSymbolMap.d.ts +3 -1
  59. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +6 -1
  60. package/dist/components/charts/physics/GaltonBoardChart.d.ts +6 -1
  61. package/dist/components/charts/physics/gauntletChartProps.d.ts +7 -1
  62. package/dist/components/charts/physics/gauntletChrome.d.ts +2 -1
  63. package/dist/components/charts/physics/gauntletPhysics.d.ts +19 -4
  64. package/dist/components/charts/physics/gauntletRuntime.d.ts +3 -0
  65. package/dist/components/charts/physics/physicsHocUtils.d.ts +12 -0
  66. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +5 -6
  67. package/dist/components/charts/realtime/temporalHistogramConfig.d.ts +11 -0
  68. package/dist/components/charts/shared/areaSeriesData.d.ts +15 -0
  69. package/dist/components/charts/shared/chartMode.d.ts +75 -0
  70. package/dist/components/charts/shared/chartSpecCore.d.ts +2 -2
  71. package/dist/components/charts/shared/colorUtils.d.ts +8 -0
  72. package/dist/components/charts/shared/geoStyleDefaults.d.ts +3 -0
  73. package/dist/components/charts/shared/hatchPattern.d.ts +8 -3
  74. package/dist/components/charts/shared/hooks.d.ts +13 -80
  75. package/dist/components/charts/shared/lineSeriesSsr.d.ts +55 -0
  76. package/dist/components/charts/shared/types.d.ts +2 -2
  77. package/dist/components/charts/shared/useChartSetup.d.ts +3 -0
  78. package/dist/components/charts/shared/useCustomChartSetup.d.ts +3 -0
  79. package/dist/components/charts/shared/useXYLineStyle.d.ts +3 -2
  80. package/dist/components/charts/shared/validateProps.d.ts +1 -1
  81. package/dist/components/charts/shared/xyLineStyle.d.ts +21 -0
  82. package/dist/components/charts/xy/AreaChart.d.ts +10 -0
  83. package/dist/components/charts/xy/LineChart.d.ts +3 -0
  84. package/dist/components/charts/xy/minimapBrushOverlay.d.ts +17 -0
  85. package/dist/components/charts/xy/minimapBrushOverlayLazy.d.ts +4 -0
  86. package/dist/components/charts/xy/scatterplotMatrixBrushOverlay.d.ts +8 -0
  87. package/dist/components/charts/xy/scatterplotMatrixBrushOverlayLazy.d.ts +3 -0
  88. package/dist/components/legendLayout.d.ts +31 -0
  89. package/dist/components/realtime/types.d.ts +5 -0
  90. package/dist/components/recipes/gridObservatory.d.ts +176 -0
  91. package/dist/components/recipes/recipeChrome.d.ts +24 -0
  92. package/dist/components/recipes/sequenceLayout.d.ts +139 -0
  93. package/dist/components/semiotic-recipes-core.d.ts +6 -2
  94. package/dist/components/server/serverChartConfigShared.d.ts +29 -0
  95. package/dist/components/server/serverChartConfigs.d.ts +2 -13
  96. package/dist/components/server/serverChartConfigsXY.d.ts +3 -0
  97. package/dist/components/server/serverGaugeOverlay.d.ts +28 -0
  98. package/dist/components/server/staticAnnotations.d.ts +3 -1
  99. package/dist/components/server/staticLegend.d.ts +7 -1
  100. package/dist/components/server/staticSVGChrome.d.ts +57 -0
  101. package/dist/components/stream/GeoPipelineStore.d.ts +2 -0
  102. package/dist/components/stream/GeoSVGOverlay.d.ts +2 -0
  103. package/dist/components/stream/SceneToSVG.d.ts +10 -8
  104. package/dist/components/stream/SceneToSVGGeo.d.ts +10 -0
  105. package/dist/components/stream/SceneToSVGNetwork.d.ts +12 -0
  106. package/dist/components/stream/SceneToSVGOrdinal.d.ts +12 -0
  107. package/dist/components/stream/canvasBackground.d.ts +7 -0
  108. package/dist/components/stream/networkFramePaint.d.ts +2 -0
  109. package/dist/components/stream/networkTypes.d.ts +2 -4
  110. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +18 -2
  111. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +7 -0
  112. package/dist/components/stream/physics/physicsPipelineEviction.d.ts +15 -0
  113. package/dist/components/stream/physics/physicsPipelineObservations.d.ts +1 -1
  114. package/dist/components/stream/physics/physicsPipelineQuiescence.d.ts +20 -0
  115. package/dist/components/stream/renderBackend.d.ts +14 -0
  116. package/dist/components/stream/sceneToSVGShared.d.ts +80 -0
  117. package/dist/components/stream/types.d.ts +4 -0
  118. package/dist/components/stream/useHydration.d.ts +7 -1
  119. package/dist/components/stream/xySceneBuilders/candlestickScene.d.ts +1 -1
  120. package/dist/components/types/legendTypes.d.ts +16 -3
  121. package/dist/forceLayoutWorker.js +1 -1
  122. package/dist/geo.min.js +1 -1
  123. package/dist/geo.module.min.js +1 -1
  124. package/dist/network.min.js +1 -1
  125. package/dist/network.module.min.js +1 -1
  126. package/dist/ordinal.min.js +1 -1
  127. package/dist/ordinal.module.min.js +1 -1
  128. package/dist/physics.min.js +1 -1
  129. package/dist/physics.module.min.js +1 -1
  130. package/dist/physicsWorker.js +1 -1
  131. package/dist/realtime.min.js +1 -1
  132. package/dist/realtime.module.min.js +1 -1
  133. package/dist/rough.min.js +1 -1
  134. package/dist/rough.module.min.js +1 -1
  135. package/dist/semiotic-ai-core.min.js +1 -1
  136. package/dist/semiotic-ai-core.module.min.js +1 -1
  137. package/dist/semiotic-ai.min.js +1 -1
  138. package/dist/semiotic-ai.module.min.js +1 -1
  139. package/dist/semiotic-experimental.min.js +1 -1
  140. package/dist/semiotic-experimental.module.min.js +1 -1
  141. package/dist/semiotic-realtime-core.min.js +1 -1
  142. package/dist/semiotic-realtime-core.module.min.js +1 -1
  143. package/dist/semiotic-recipes-core.d.ts +6 -2
  144. package/dist/semiotic-recipes-core.min.js +1 -1
  145. package/dist/semiotic-recipes-core.module.min.js +1 -1
  146. package/dist/semiotic-recipes.min.js +1 -1
  147. package/dist/semiotic-recipes.module.min.js +1 -1
  148. package/dist/semiotic-server-edge.min.js +1 -1
  149. package/dist/semiotic-server-edge.module.min.js +1 -1
  150. package/dist/semiotic-server-node.min.js +1 -1
  151. package/dist/semiotic-server-node.module.min.js +1 -1
  152. package/dist/semiotic-utils-core.min.js +1 -1
  153. package/dist/semiotic-utils-core.module.min.js +1 -1
  154. package/dist/semiotic-utils.min.js +1 -1
  155. package/dist/semiotic-utils.module.min.js +1 -1
  156. package/dist/semiotic-value.module.min.js +1 -1
  157. package/dist/semiotic.min.js +1 -1
  158. package/dist/semiotic.module.min.js +1 -1
  159. package/dist/server.min.js +1 -1
  160. package/dist/server.module.min.js +1 -1
  161. package/dist/xy.min.js +1 -1
  162. package/dist/xy.module.min.js +1 -1
  163. package/package.json +3 -2
  164. package/dist/chunk-chunk-255KDHW5.module.min.js +0 -1
  165. package/dist/chunk-chunk-27HVVXS6.module.min.js +0 -1
  166. package/dist/chunk-chunk-2UN3ANRN.module.min.js +0 -2
  167. package/dist/chunk-chunk-2VUEY5TH.module.min.js +0 -1
  168. package/dist/chunk-chunk-2WVCH4PL.module.min.js +0 -1
  169. package/dist/chunk-chunk-5WEFWNUW.module.min.js +0 -2
  170. package/dist/chunk-chunk-6F6GEAQU.module.min.js +0 -1
  171. package/dist/chunk-chunk-BHYTYMY2.module.min.js +0 -2
  172. package/dist/chunk-chunk-C6EJ4IOD.module.min.js +0 -2
  173. package/dist/chunk-chunk-CP3EN6KZ.module.min.js +0 -1
  174. package/dist/chunk-chunk-DNY43POY.module.min.js +0 -1
  175. package/dist/chunk-chunk-E7MIQX7D.module.min.js +0 -2
  176. package/dist/chunk-chunk-ES4DCG3L.module.min.js +0 -1
  177. package/dist/chunk-chunk-FAKO3RGQ.module.min.js +0 -2
  178. package/dist/chunk-chunk-H4PPRW6N.module.min.js +0 -1
  179. package/dist/chunk-chunk-IFYPMWKY.module.min.js +0 -1
  180. package/dist/chunk-chunk-J3ELI22J.module.min.js +0 -1
  181. package/dist/chunk-chunk-L6D3I3V7.module.min.js +0 -2
  182. package/dist/chunk-chunk-M337NY6L.module.min.js +0 -1
  183. package/dist/chunk-chunk-ODUZEEBH.module.min.js +0 -2
  184. package/dist/chunk-chunk-P6UBCMSQ.module.min.js +0 -2
  185. package/dist/chunk-chunk-QRIBHZYW.module.min.js +0 -1
  186. package/dist/chunk-chunk-RH5TSQPH.module.min.js +0 -1
  187. package/dist/chunk-chunk-STZFFTAN.module.min.js +0 -2
  188. package/dist/chunk-chunk-T27ZEV6A.module.min.js +0 -1
  189. package/dist/chunk-chunk-U3AGQ5EF.module.min.js +0 -2
  190. package/dist/chunk-chunk-W3DB2MN4.module.min.js +0 -2
  191. package/dist/chunk-chunk-WDIN4LRC.module.min.js +0 -1
  192. package/dist/chunk-chunk-XOYX77KF.module.min.js +0 -2
  193. package/dist/chunk-chunk-Z5KXAVQD.module.min.js +0 -2
  194. package/dist/chunk-chunk-ZCNBUZPL.module.min.js +0 -2
  195. package/dist/chunk-chunk-ZTNVDWAK.module.min.js +0 -2
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{needsDataCanvasPaint as e,paintCanvasBackground as t}from"./chunk-chunk-KQ546MKE.module.min.js";import{StalenessBadge as r,attachUpdateResultStore as n,buildNavGraph as o,composeOverlays as i,computeDecayOpacity as a,createCustomLayoutFailureDiagnostic as s,extractNetworkNavPoints as c,filterAnnotationsByStatus as l,findHitPointInQuadtree as u,formatVal as d,getHitRadius as h,hitTestRect as y,networkGlyphRenderer as f,nextNetworkIndex as g,normalizeAngle as p,paintSceneWithBackend as m,renderCirclePulse as v,renderRectPulse as x,renderSceneWithBackend as k,resolvePosition as b,useConfigSync as S,useLayoutSelectionSync as _,useStableShallow as w,useStalenessCheck as A,warnCustomLayoutDiagnostics as L}from"./chunk-chunk-F7WFPD4O.module.min.js";import{CustomLayoutSelectionProvider as E,wrapWithCustomLayoutSelection as P}from"./chunk-chunk-5UKL5W76.module.min.js";import{commonJsWorkerModuleUrl as D}from"./chunk-chunk-SV4XAZ3Q.module.min.js";import{buildResolveColor as M,resolveCustomLayoutPalette as R}from"./chunk-chunk-FBGHXL72.module.min.js";import{ANNOTATION_DISCLOSURE_REVEAL_CSS as N,AriaLiveTooltip as T,CanvasFrameBackground as C,DEFAULT_COLORS as W,FlippingTooltip as I,FocusRing as $,NetworkAccessibleDataTable as z,SceneRevisionDiagnosticsObserver as F,ScreenReaderSummary as B,SkipToTableLink as O,TITLE_BASELINE as Y,UpdateResultTracker as X,annotationActivationProps as j,annotationLayout as H,buildHoverData as G,computeEasing as V,computeNetworkAriaLabel as q,computeRawProgress as Q,createDefaultAnnotationRules as K,createSeededFrameRandom as Z,defaultTooltipStyle as U,emitClickObservations as J,emitHoverObservations as ee,filterSparseArray as te,getDevicePixelRatio as re,isAnnotationActivationTarget as ne,isInteractiveKeyboardTarget as oe,isServerEnvironment as ie,lerp as ae,networkLabelToSVG as se,networkSceneEdgeToSVG as ce,networkSceneNodeToSVG as le,now as ue,observationInputType as de,prepareCanvas as he,renderAnnotationPass as ye,renderLegendFromConfig as fe,resolveCSSColor as ge,resolveCanvasFill as pe,runSceneBuild as me,schemeCategory10 as ve,smartTooltipEntries as xe,symbolPathString as ke,symbolRadius as be,useAnnotationActivationOptions as Se,useFrame as _e,useFrameCanvasHost as we,useSceneRevisionDiagnostics as Ae}from"./chunk-chunk-BFHUYEOS.module.min.js";import{getMinMax as Le}from"./chunk-chunk-JJ2OOIET.module.min.js";import{resolveThemeSemanticColors as Ee}from"./chunk-chunk-WCX6U47H.module.min.js";import{glyphHitGeometry as Pe}from"./chunk-chunk-KTWEBFMX.module.min.js";import{renderLoadingState as De,useHydration as Me,useWasHydratingFromSSR as Re}from"./chunk-chunk-ACLDBMRH.module.min.js";import*as Ne from"react";import{useRef as Te,useState as Ce,useEffect as We,useMemo as Ie,useCallback as $e,useImperativeHandle as ze,forwardRef as Fe,memo as Be}from"react";var Oe={weightChange:.1,newEdge:.5,newNode:1,threshold:3,transitionDuration:500},Ye={radius:3,opacity:.7,speedMultiplier:1,maxPerEdge:50,spawnRate:.1},Xe=class{constructor(e){this.capacity=e,this.particles=Array(e),this._freeIndices=Array(e);for(let t=0;e>t;t++)this.particles[t]={t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0},this._freeIndices[t]=e-1-t}spawn(e,t=Math.random){const r=this._freeIndices.pop();if(void 0===r)return null;const n=this.particles[r];return n.active=!0,n.t=0,n.offset=t()-.5,n.edgeIndex=e,n.x=0,n.y=0,n}step(e,t,r,n){for(let o=0;this.capacity>o;o++){const i=this.particles[o];if(!i.active)continue;const a=r[i.edgeIndex];a&&a.bezier?(i.t+=e*t*(n?n[i.edgeIndex]??1:1)*(a.bezier.circular?.3:1),1>i.t?je(a.bezier,i.t,i.offset,i):(i.active=!1,this._freeIndices.push(o))):(i.active=!1,this._freeIndices.push(o))}}countForEdge(e){let t=0;for(let r=0;this.capacity>r;r++)this.particles[r].active&&this.particles[r].edgeIndex===e&&t++;return t}clear(){for(let e=0;this.capacity>e;e++)this.particles[e].active=!1;this._freeIndices.length=0;for(let e=this.capacity-1;e>=0;e--)this._freeIndices.push(e)}resize(e){if(this.capacity>=e)return;const t=this.particles;this.particles=Array(e);for(let r=0;e>r;r++)t.length>r?this.particles[r]=t[r]:(this.particles[r]={t:0,offset:0,edgeIndex:0,active:!1,x:0,y:0},this._freeIndices.push(r));this.capacity=e}};function je(e,t,r,n){if(e.circular&&e.segments)return void function(e,t,r,n,o){const i=e.length,a=t*i,s=Math.min(Math.floor(a),i-1),c=a-s,[l,u,d,h]=e[s];He(l,u,d,h,c,o);const y=h.x-l.x,f=h.y-l.y,g=Math.sqrt(y*y+f*f);if(g>.001){const e=y/g;o.x+=-f/g*r*n*2,o.y+=e*r*n*2}}(e.segments,t,r,e.halfWidth,n);if(!e.points)return n.x=0,void(n.y=0);const[o,i,a,s]=e.points;He(o,i,a,s,t,n);const c=s.x-o.x,l=s.y-o.y,u=Math.sqrt(c*c+l*l);if(u>.001){const t=c/u;n.x+=-l/u*r*e.halfWidth*2,n.y+=t*r*e.halfWidth*2}}function He(e,t,r,n,o,i){const a=1-o,s=a*a,c=s*a,l=o*o,u=l*o;i.x=c*e.x+3*s*o*t.x+3*a*l*r.x+u*n.x,i.y=c*e.y+3*s*o*t.y+3*a*l*r.y+u*n.y}function Ge(e,t){var r=e.get(t);if(!r)throw Error("missing: "+t);return r}function Ve(e,t){var r,n=[],o=[],i=[],a={},s=[];function c(e){i[e]=!1,a.hasOwnProperty(e)&&Object.keys(a[e]).forEach(function(t){delete a[e][t],i[t]&&c(t)})}function l(e){var t,n,d=!1;for(o.push(e),i[e]=!0,t=0;s[e].length>t;t++)(n=s[e][t])===r?(u(r,o),d=!0):i[n]||(d=l(n));if(d)c(e);else for(t=0;s[e].length>t;t++){var h=a[n=s[e][t]];h||(a[n]=h={}),h[n]=!0}return o.pop(),d}function u(e,r){var o=[].concat(r).concat(e);t?t(o):n.push(o)}function d(t){!function(t){for(var r=0;e.length>r;r++)r>=t&&e[r]||(e[r]=[]),e[r]=e[r].filter(function(e){return e>=t})}(t);for(var r,n=function(e){for(var t=e.length,r=Array(t),n=Array(t),o=Array(t),i=Array(t),a=Array(t),s=Array(t),c=0;t>c;++c)r[c]=-1,n[c]=0,o[c]=!1,i[c]=0,a[c]=-1,s[c]=[];var l,u=0,d=[],h=[];function y(t){var c=[t],l=[t];for(r[t]=n[t]=u,o[t]=!0,u+=1;l.length>0;){var y=e[t=l[l.length-1]];if(y.length>i[t]){for(var f=i[t];y.length>f;++f){var g=y[f];if(0>r[g]){r[g]=n[g]=u,o[g]=!0,u+=1,c.push(g),l.push(g);break}o[g]&&(n[t]=0|Math.min(n[t],n[g])),0>a[g]||s[t].push(a[g])}i[t]=f}else{if(n[t]===r[t]){var p=[],m=[],v=0;for(f=c.length-1;f>=0;--f){var x=c[f];if(o[x]=!1,p.push(x),m.push(s[x]),v+=s[x].length,a[x]=d.length,x===t){c.length=f;break}}d.push(p);var k=Array(v);for(f=0;m.length>f;f++)for(var b=0;m[f].length>b;b++)k[--v]=m[f][b];h.push(k)}l.pop()}}}for(c=0;t>c;++c)0>r[c]&&y(c);for(c=0;h.length>c;c++){var f=h[c];if(0!==f.length){f.sort(function(e,t){return e-t}),l=[f[0]];for(var g=1;f.length>g;g++)f[g]!==f[g-1]&&l.push(f[g]);h[c]=l}}return{components:d,adjacencyList:h}}(e),o=n.components.filter(function(e){return e.length>1}),i=1/0,a=0;o.length>a;a++)for(var s=0;o[a].length>s;s++)i>o[a][s]&&(i=o[a][s],r=a);var c=o[r];return!!c&&{leastVertex:i,adjList:e.map(function(e,t){return-1===c.indexOf(t)?[]:e.filter(function(e){return-1!==c.indexOf(e)})})}}r=0;for(var h=e.length;h>r;){var y=d(r);if(r=y.leastVertex,s=y.adjList){for(var f=0;s.length>f;f++)for(var g=0;s[f].length>g;g++){var p=s[f][g];i[+p]=!1,a[p]={}}l(r),r+=1}else r=h}return t?void 0:n}function qe(e){return e.y0-e.y1>0?"up":"down"}function Qe(e,t){return t(e.source)==t(e.target)}function Ke(e){var t=0;e.source.sourceLinks.forEach(function(e){t=e.circular?t+1:t});var r=0;return e.target.targetLinks.forEach(function(e){r=e.circular?r+1:r}),1>=t&&1>=r}function Ze(e){return e.target.x0-e.source.x1}function Ue(e,t){var r=et(e),n=Ze(t)/Math.tan(r);return"up"==qe(e)?e.y1-n:e.y1+n}function Je(e,t){var r=et(e),n=Ze(t)/Math.tan(r);return"up"==qe(e)?e.y1+n:e.y1-n}function et(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function tt(e,t){return t(e)}function rt(e){return ot(e.source)}function nt(e){return ot(e.target)}function ot(e){return(e.y0+e.y1)/2}function it(e){return e.virtual?0:e.value}function at(e,t){var r=0;e.sourceLinks.forEach(function(e){r=e.circular&&!Qe(e,t)?r+1:r});var n=0;return e.targetLinks.forEach(function(e){n=e.circular&&!Qe(e,t)?n+1:n}),r+n}function st(e){return e.target.depth}function ct(e,t){return e.sourceLinks.length?e.depth:t-1}function lt(e,t){return e.y0-t.y0}function ut(e,t){return t.y0-e.y0}function dt(e,t){return e.y1-t.y1}function ht(e,t){return t.y1-e.y1}function yt(e,t){return gt(e.source,t.source)||e.index-t.index}function ft(e,t){return gt(e.target,t.target)||e.index-t.index}function gt(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function pt(e,t){return mt(e)==mt(t)?"bottom"==e.circularLinkType?ut(e,t):lt(e,t):mt(t)-mt(e)}function mt(e){return e.target.column-e.source.column}function vt(e,t){return xt(e)==xt(t)}function xt(e){return e.y0-e.y1>0?"up":"down"}import{min as kt}from"d3-array";function bt(e,t,r,n,o){let i=e;var a=Math.max(8,.15*(i.y1-i.y0));i.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,a))});var s=kt(i.links,function(e){return e.source.y0});i.links.forEach(function(e){e.circular&&(e.circularPathData={})});var c=i.links.filter(function(e){return e.circular});return c.sort(function(e,t){return t.value-e.value}),c.forEach(function(e,t){e._circularStub=t>=4}),St(i.links.filter(function(e){return"top"==e.circularLinkType}),t,r),St(i.links.filter(function(e){return"bottom"==e.circularLinkType}),t,r),i.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+n,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,Qe(e,t)&&Ke(e))e.circularPathData.rightSmallArcRadius=n+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=n+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=n+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=n+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var a=e.source.column,c=e.circularLinkType,l=i.links.filter(function(e){return e.source.column==a&&e.circularLinkType==c});l.sort("bottom"==e.circularLinkType?ut:lt);var u=0;l.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=n+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=n+e._circularWidth/2+o*r+u),u+=t._circularWidth||t.width}),a=e.target.column,(l=i.links.filter(function(e){return e.target.column==a&&e.circularLinkType==c})).sort("bottom"==e.circularLinkType?ht:dt),u=0,l.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=n+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=n+e._circularWidth/2+o*r+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(i.y1,e.source.y1,e.target.y1)+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=s-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)}e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer}e.path=e.circular?function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):function(e){var t=e.source.x1,r=e.y0,n=e.target.x0,o=e.y1,i=(t+n)/2;return"M"+t+","+r+"C"+i+","+r+" "+i+","+o+" "+n+","+o}(e)}),i}function St(e,t,r){e.sort(pt);var n=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,o){var i=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(Qe(e,t)&&Ke(e))e.circularPathData.verticalBuffer=i+e._circularWidth/2;else{for(var a=0;n.length>a;a++){var s=n[a];if(s!==e&&s.circularPathData&&void 0!==s.circularPathData.verticalBuffer&&_t(e,s)){var c=s.circularPathData.verticalBuffer+(s._circularWidth||s.width)/2+r;i=c>i?c:i}}e.circularPathData.verticalBuffer=i+e._circularWidth/2}}),e}function _t(e,t){return e.source.column>=t.target.column&&t.source.column>=e.target.column}import{min as wt,max as At,sum as Lt,mean as Et,group as Pt,groups as Dt}from"d3-array";function Mt(e){return function(){return e}}function Rt(e){return e.index}function Nt(e){return e.nodes}function Tt(e){return e.links}function Ct(e,t,r){var n=Dt(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});n.forEach(function(o,i){var a=o.length;if(t)o.sort(t);else if(i>0){var s=new Map;o.forEach(function(e,t){var r,n,o,i=(n=0,o=0,(r=e).targetLinks.forEach(function(e){if(!e.circular){var t=e.value||1;o+=ot(e.source)*t,n+=t}}),r.sourceLinks.forEach(function(e){if(!e.circular){var t=e.value||1;o+=ot(e.target)*t,n+=t}}),n>0?o/n:NaN);s.set(e,{bc:i,idx:t})}),o.sort(function(e,t){var r=s.get(e),n=s.get(t),o=r.bc,i=n.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(o)||isNaN(i)?isNaN(o)?isNaN(i)?r.idx-n.idx:1:-1:o-i})}else o.sort(function(e,t){return e.circularLinkType==t.circularLinkType?at(t,r)-at(e,r):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});o.forEach(function(t,o){t.depth==n.length-1&&1==a||0==t.depth&&1==a?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==at(t,r)?(t.y0=e.y1/2+o,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+o,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-o,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/a*o,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-a/2+o,t.y1=t.y0+t.value*e.ky)})})}function Wt(e,t,r,n,o,i){var a=Dt(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var s=1,c=i;c>0;--c)l(s*=.99,r),u();function l(t,r){var n=a.length;a.forEach(function(o){var i=o.length,a=o[0].depth;o.forEach(function(o){var s;if(o.sourceLinks.length||o.targetLinks.length)if(o.partOfCycle&&at(o,r)>0){var c=Et(o.sourceLinks,nt),l=Et(o.targetLinks,rt),u=c&&l?(c+l)/2:c||l;if(u){var d=(u-ot(o))*t*.3;o.y0+=d,o.y1+=d}}else if(0==a&&1==i)o.y0=e.y1/2-(s=o.y1-o.y0)/2,o.y1=e.y1/2+s/2;else if(a==n-1&&1==i)o.y0=e.y1/2-(s=o.y1-o.y0)/2,o.y1=e.y1/2+s/2;else if(1==o.targetLinks.length&&1==o.targetLinks[0].source.sourceLinks.length)s=o.y1-o.y0,o.y0=o.targetLinks[0].source.y0,o.y1=o.y0+s;else{var h=Et(o.sourceLinks,nt),y=Et(o.targetLinks,rt),f=((h&&y?(h+y)/2:h||y)-ot(o))*t;o.y0+=f,o.y1+=f}})})}function u(){a.forEach(function(r){var i,a,s,c=e.y0,l=r.length;for(r.sort(t||gt),s=0;l>s;++s)(a=c-(i=r[s]).y0)>0&&(i.y0+=a,i.y1+=a),c=i.y1+n;if((a=c-n-e.y1)>0)for(c=i.y0-=a,i.y1-=a,s=l-2;s>=0;--s)(a=(i=r[s]).y1+o-c)>0&&(i.y0-=a,i.y1-=a),c=i.y0})}}function It(e){e.nodes.forEach(function(e){e.sourceLinks.sort(ft),e.targetLinks.sort(yt)}),e.nodes.forEach(function(e){var t=e.y0,r=t,n=e.y1,o=n;e.sourceLinks.forEach(function(e){e.circular?(e.y0=n-e.width/2,n-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=o-e.width/2,o-=e.width):(e.y1=r+e.width/2,r+=e.width)})})}function $t(){var e=0,t=0,r=1,n=1,o=24,i=8,a=null,s=Rt,c=ct,l=void 0,u=32,d=2,h=Nt,y=Tt;function f(){var f={nodes:h.apply(null,arguments),links:y.apply(null,arguments)};return function(h){h.x0=e,h.y0=t,h.x1=r,h.y1=n,h.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var r=function(e,t){var r=new Map;return Pt(e,t).forEach(function(e,t){r.set(t,e[0])}),r}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var n=e.source,o=e.target;"object"!=typeof n&&(n=e.source=Ge(r,n)),"object"!=typeof o&&(o=e.target=Ge(r,o)),n.sourceLinks.push(e),o.targetLinks.push(e)})}(h,s),function(e,t){var r=0;if(null==t){for(var n=[],o=0;e.links.length>o;o++){var i=e.links[o],a=i.source.index,s=i.target.index;n[a]||(n[a]=[]),n[s]||(n[s]=[]),-1===n[a].indexOf(s)&&n[a].push(s)}var c=Ve(n);c.sort(function(e,t){return e.length-t.length});var l={};for(o=0;c.length>o;o++){var u=c[o].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,n=e.source.index;t===n||l[n]&&l[n][t]?(e.circular=!0,e.circularLinkID=r++):e.circular=!1})}else e.links.forEach(function(e){t(e.source)<t(e.target)?e.circular=!1:(e.circular=!0,e.circularLinkID=r++)})}(h,l),function(e,t){var r=0,n=0;e.links.forEach(function(o){o.circular&&(o.circularLinkType=o.source.circularLinkType||o.target.circularLinkType?o.source.circularLinkType?o.source.circularLinkType:o.target.circularLinkType:n>r?"top":"bottom","top"==o.circularLinkType?r++:n++,e.nodes.forEach(function(e){tt(e,t)!=tt(o.source,t)&&tt(e,t)!=tt(o.target,t)||(e.circularLinkType=o.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),Qe(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(h,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(Lt(e.sourceLinks,it),Lt(e.targetLinks,it)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(h),function(e,t,r){var n,o,i;if(null!=t){e.nodes.sort(function(e,r){return t(e)<t(r)?-1:1});var a=0,s=t(e.nodes[0]);e.nodes.forEach(function(e){a=t(e)==s?a:a+1,s=t(e)==s?s:t(e),e.column=a})}for(n=e.nodes,o=[],i=0;n.length;++i,n=o,o=[])n.forEach(function(e){e.depth=i,e.sourceLinks.forEach(function(e){0>o.indexOf(e.target)&&!e.circular&&o.push(e.target)})});for(n=e.nodes,o=[],i=0;n.length;++i,n=o,o=[])n.forEach(function(e){e.height=i,e.targetLinks.forEach(function(e){0>o.indexOf(e.source)&&!e.circular&&o.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?r(e,i):e.column})}(h,l,c);var y=i;if(null!==a){var f=Dt(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=At(f,function(e){return e.length});g>1&&(y=Math.max(1,(n-t)*a/(g-1)))}(function(e,t,r){var n=Dt(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var o=wt(n,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/Lt(t,function(e){return e.value})});e.ky=o,e.links.forEach(function(t){t.width=t.value*e.ky});var i=At(e.nodes,function(e){return e.column});e.nodes.forEach(i>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-r)/i),t.x1=t.x0+r}:function(t){t.x0=e.x0,t.x1=t.x0+r})})(h,y,o),Ct(h,l,s),Wt(h,l,s,y,y,u),It(h),bt(h,s,d,10,8),Ct(h,l,s),Wt(h,l,s,y,y,u),It(h),bt(h,s,d,10,8),function(e,t){let r=e;r.nodes.forEach(function(e){e.y+(e.y1-e.y0)>r.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-r.y1));var n=r.links.filter(function(r){return tt(r.source,t)==tt(e,t)}),o=n.length;o>1&&n.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!vt(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var r=Ue(t,e);return e.y1-r}if(t.target.column>e.target.column)return Ue(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;n.forEach(function(e){e.y0=i+e.width/2,i+=e.width}),n.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var i=r+1,a=0;o>i;i++)a+=n[i].width;t.y0=e.y1-a-t.width/2}})})}(h,s),function(e,t){let r=e;r.nodes.forEach(function(e){var n=r.links.filter(function(r){return tt(r.target,t)==tt(e,t)}),o=n.length;o>1&&n.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!vt(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var r=Je(t,e);return e.y0-r}if(t.source.column>e.source.column)return Je(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;n.forEach(function(e){e.y1=i+e.width/2,i+=e.width}),n.forEach(function(t,r){if("bottom"==t.circularLinkType){for(var i=r+1,a=0;o>i;i++)a+=n[i].width;t.y1=e.y1-a-t.width/2}})})}(h,s),function(e){var t=e.nodes,r=e.links,n=!1,o=!1;if(r.forEach(function(e){"top"==e.circularLinkType?n=!0:"bottom"==e.circularLinkType&&(o=!0)}),0==n||0==o){let n=function(t){return(t-i)/(a-i)*(e.y1-e.y0)+e.y0};var i=wt(t,function(e){return e.y0}),a=At(t,function(e){return e.y1}),s=(e.y1-e.y0)/(a-i);1>s?(t.forEach(function(e){e.y0=n(e.y0),e.y1=n(e.y1)}),r.forEach(function(e){e.y0=n(e.y0),e.y1=n(e.y1),e.width=e.width*s})):t.forEach(function(e){var t=e.y1-e.y0,r=n(e.y0)-e.y0;e.y0=n(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+r}),e.targetLinks.forEach(function(e){e.y1=e.y1+r})})}}(h),bt(h,s,d,10,8)}(f),f}return f.update=function(e){return It(e),bt(e,s,d,10,8),e},f.nodeWidth=function(e){return arguments.length?(o=+e,f):o},f.nodePadding=function(e){return arguments.length?(i=+e,f):i},f.nodePaddingRatio=function(e){return arguments.length?(a=+e,f):a},f.nodes=function(e){return arguments.length?(h="function"==typeof e?e:Mt(e),f):h},f.links=function(e){return arguments.length?(y="function"==typeof e?e:Mt(e),f):y},f.nodeId=function(e){return arguments.length?(s="function"==typeof e?e:Mt(e),f):s},f.nodeAlign=function(e){return arguments.length?(c="function"==typeof e?e:Mt(e),f):c},f.nodeSort=function(e){return arguments.length?(l=e,f):l},f.iterations=function(e){return arguments.length?(u=+e,f):u},f.circularLinkGap=function(e){return arguments.length?(d=+e,f):d},f.extent=function(o){return arguments.length?(e=+o[0][0],t=+o[0][1],r=+o[1][0],n=+o[1][1],f):[[e,t],[r,n]]},f.size=function(o){return arguments.length?(e=t=0,r=+o[0],n=+o[1],f):[r-e,n-t]},f}import{interpolateNumber as zt}from"d3-interpolate";import{line as Ft,curveLinearClosed as Bt}from"d3-shape";function Ot(e){const{sx:t,sTop:r,sBot:n,tx:o,tTop:i,tBot:a,cp1X:s,cp2X:c}=e,l=(r+n)/2,u=(i+a)/2;return{pathD:[`M${t},${r}`,`C${s},${r} ${c},${i} ${o},${i}`,`L${o},${a}`,`C${c},${a} ${s},${n} ${t},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:l},{x:s,y:l},{x:c,y:u},{x:o,y:u}],halfWidth:(n-r)/2}}}var Yt=e=>{let t,r,n,o,i,a,s,c,l;if("down"===e.direction)return t=e.y0-e.sankeyWidth/2,r=e.y1-e.sankeyWidth/2,n=e.y1+e.sankeyWidth/2,o=e.y0+e.sankeyWidth/2,i=e.source.x1,a=e.target.x0,s=zt(i,a),c=s(.5),l=s(.5),`M${t},${i}C${t},${c} ${r},${l} ${r},${a}L${n},${a}C${n},${l} ${o},${c} ${o},${i}Z`;const u=e.sankeyWidth/2,d=zt(e.source.x1,e.target.x0),{pathD:h}=Ot({sx:e.source.x1,sTop:e.y0-u,sBot:e.y0+u,tx:e.target.x0,tTop:e.y1-u,tBot:e.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function Xt(e){const t=e.sankeyWidth/2,r=(e._circularWidth??e.sankeyWidth)/2,n=e.circularPathData;if(!n)return null;if("down"===e.direction)return null;if(e._circularStub){const r=n.sourceX,o=n.sourceY,i=n.targetX,a=n.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;const s=Math.max(15,Math.min(40,.33*(n.rightFullExtent-r))),c=Math.max(15,Math.min(40,.33*(i-n.leftFullExtent)));return`M${r},${o-t}L${r+s},${o-t}L${r+s},${o+t}L${r},${o+t}ZM${i},${a-t}L${i-c},${a-t}L${i-c},${a+t}L${i},${a+t}Z`}const o=n.sourceX,i=n.sourceY,a=n.targetX,s=n.targetY,c=n.rightFullExtent,l=n.leftFullExtent,u=n.verticalFullExtent,d="bottom"===e.circularLinkType?1:-1,h=Math.max(4,Math.min(r,15));return`M${o},${i-d*t}L${c},${i-d*t}L${c+r},${i-d*t+d*h}L${c+r},${u+d*r-d*h}L${c+r-h},${u+d*r}L${l-r+h},${u+d*r}L${l-r},${u+d*r-d*h}L${l-r},${s-d*t+d*h}L${l-r+h},${s-d*t}L${a},${s-d*t}L${a},${s+d*t}L${l+r},${s+d*t}L${l+r},${u-d*r}L${c-r},${u-d*r}L${c-r},${i+d*t}L${o},${i+d*t}Z`}var jt=new Set,Ht=new WeakMap;function Gt(e,t){if("production"===process.env.NODE_ENV)return e;if(!e||!e.data||"object"!=typeof e.data)return e;let r=Ht.get(e);if(r){const e=r.get(t);if(e)return e}else r=new Map,Ht.set(e,r);const n=new Proxy(e,{get(e,r,n){if("string"==typeof r&&!(r in e)&&e.data&&r in e.data){const e=`${t}:${r}`;jt.has(e)||(jt.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${r}" on the wrapper object, but it only exists on ".data". Use d.data.${r} (or d.data?.${r}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,r,n)}});return r.set(t,n),n}var Vt={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(st))-1:0},justify:ct};function qt(e){return"string"==typeof e?e:e.id}var Qt={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,r,n){if(0===e.length)return;const o="vertical"===r.orientation?"down":"right",i=r.nodeAlign||"justify",a=r.nodeWidth??15,s=r.nodePaddingRatio??.05,c=r.iterations??100,l=e.map(e=>({...e})),u=t.map(e=>({...e,source:"string"==typeof e.source?e.source:e.source.id,target:"string"==typeof e.target?e.target:e.target.id,value:Math.sqrt(Math.max(1,e.value||1))}));let d;d="down"===o?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const h=$t().extent(d).links(u).nodes(l).nodeAlign(Vt[i]||ct).nodeId(e=>e.id).nodeWidth(a).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(s),h();{let e=1/0,t=-1/0,r=1/0,o=-1/0;for(const n of l)e>n.x0&&(e=n.x0),n.x1>t&&(t=n.x1),r>n.y0&&(r=n.y0),n.y1>o&&(o=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const i=n.circularPathData,a=(n._circularWidth??n.width??0)/2;e>i.leftFullExtent-a&&(e=i.leftFullExtent-a),i.rightFullExtent+a>t&&(t=i.rightFullExtent+a),r>i.verticalFullExtent-a&&(r=i.verticalFullExtent-a),i.verticalFullExtent+a>o&&(o=i.verticalFullExtent+a)}const i=t-e,a=o-r,s=n[0],c=n[1];if(i>0&&a>0&&(0>e||0>r||t>s||o>c)){const t=Math.min(s/i,c/a),n=-e*t+(s-i*t)/2,o=-r*t+(c-a*t)/2;for(const e of l)e.x0=e.x0*t+n,e.x1=e.x1*t+n,e.y0=e.y0*t+o,e.y1=e.y1*t+o;for(const e of u)if(e.y0=e.y0*t+o,e.y1=e.y1*t+o,e.width=(e.width??0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){const r=e.circularPathData;r.sourceX=r.sourceX*t+n,r.targetX=r.targetX*t+n,r.sourceY=r.sourceY*t+o,r.targetY=r.targetY*t+o,r.rightFullExtent=r.rightFullExtent*t+n,r.leftFullExtent=r.leftFullExtent*t+n,r.verticalFullExtent=r.verticalFullExtent*t+o,r.rightInnerExtent=r.rightInnerExtent*t+n,r.leftInnerExtent=r.leftInnerExtent*t+n,r.verticalRightInnerExtent=r.verticalRightInnerExtent*t+o,r.verticalLeftInnerExtent=r.verticalLeftInnerExtent*t+o,r.rightSmallArcRadius*=t,r.rightLargeArcRadius*=t,r.leftSmallArcRadius*=t,r.leftLargeArcRadius*=t,r.sourceWidth*=t,r.rightNodeBuffer*=t,r.leftNodeBuffer*=t,r.arcRadius*=t}}}const y=new Map;for(const t of e)y.set(t.id,t);for(const e of l){const t=y.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}const f=new Map;for(const e of t)f.set(e._edgeKey?e._edgeKey:`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,e);for(const e of u){const t=qt(e.source),r=qt(e.target),n=f.get(e._edgeKey?e._edgeKey:`${t}\0${r}`);if(n){n.y0=e.y0,n.y1=e.y1,n.sankeyWidth=e.width??0,n.circular=!!e.circular,n.circularPathData=e.circularPathData,n._circularWidth=e._circularWidth,n._circularStub=e._circularStub,n.path=e.path,n.circularLinkType=e.circularLinkType,n.direction=o;const i=y.get(t),a=y.get(r);i&&(n.source=i),a&&(n.target=a)}}},buildScene(e,t,r,n){const o="vertical"===r.orientation?"down":"right",i=r.nodeStyle,a=r.edgeStyle,s=r.edgeOpacity??.5,c=r.edgeColorBy||"source",l=Array.isArray(r.colorScheme)?r.colorScheme:r.themeCategorical&&r.themeCategorical.length>0?r.themeCategorical:ve,u=new Map;e.forEach((e,t)=>{u.set(e.id,l[t%l.length])});const d=[],h=[],y=[],f=new Map;for(const t of e){const e=t.x1-t.x0,r=t.y1-t.y0;if(0>=e||0>=r)continue;const n=i?i(Gt(t,"nodeStyle")):{},a={fill:n.fill||u.get(t.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity};f.set(t.id,("string"==typeof a.fill?a.fill:null)||u.get(t.id)||"#4d430c"),d.push("down"===o?{type:"rect",x:t.y0,y:t.x0,w:r,h:e,style:a,datum:t,id:t.id,label:t.id}:{type:"rect",x:t.x0,y:t.y0,w:e,h:r,style:a,datum:t,id:t.id,label:t.id})}const g=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(const e of g){if(!e.sankeyWidth||0>=e.sankeyWidth)continue;const t="object"==typeof e.source?e.source:null,n="object"==typeof e.target?e.target:null;if(!t||!n)continue;let o=r.themeSemantic?.border||r.themeSemantic?.secondary||"#999";o="function"==typeof c?c(e)||o:"target"===c?f.get(n.id)||u.get(n.id)||o:f.get(t.id)||u.get(t.id)||o;const i=a?a(Gt(e,"edgeStyle")):{};if(e._circularStub&&e.circular&&e.circularPathData){const t=e.circularPathData,r=e.sankeyWidth/2,n=Math.max(15,Math.min(40,.33*(t.rightFullExtent-t.sourceX))),a=Math.max(15,Math.min(40,.33*(t.targetX-t.leftFullExtent))),c=i.fill||o;h.push({type:"bezier",pathD:`M${t.sourceX},${t.sourceY-r}L${t.sourceX+n},${t.sourceY-r}L${t.sourceX+n},${t.sourceY+r}L${t.sourceX},${t.sourceY+r}Z`,style:{fill:c,fillOpacity:i.fillOpacity??s,stroke:"none",opacity:i.opacity},datum:e,_gradient:{direction:"right",from:1,to:0,x0:t.sourceX,x1:t.sourceX+n}}),h.push({type:"bezier",pathD:`M${t.targetX},${t.targetY-r}L${t.targetX-a},${t.targetY-r}L${t.targetX-a},${t.targetY+r}L${t.targetX},${t.targetY+r}Z`,style:{fill:c,fillOpacity:i.fillOpacity??s,stroke:"none",opacity:i.opacity},datum:e,_gradient:{direction:"left",from:0,to:1,x0:t.targetX-a,x1:t.targetX}});continue}let l;(l=e.circular&&e.circularPathData?Xt(e):Yt(e),l)&&h.push({type:"bezier",pathD:l,bezierCache:e.bezier,style:{fill:i.fill||o,fillOpacity:i.fillOpacity??s,stroke:i.stroke||"none",strokeWidth:i.strokeWidth,opacity:i.opacity},datum:e})}if(!1!==r.showLabels){const t=(p=r.nodeLabel)?"function"==typeof p?p:e=>e[p]||e.id:null;for(const r of e){const e=r.x1-r.x0,i=r.y1-r.y0;if(0>=e||0>=i)continue;const a=t?t(r):r.id;if(!a)continue;let s,c,l;"down"===o?(s=r.y0+(r.y1-r.y0)/2,c=r.x1+14,l="start"):(n[0]/2>r.x0+e/2?(s=r.x0-6,l="end"):(s=r.x1+6,l="start"),c=r.y0+i/2),y.push({x:s,y:c,text:a+"",anchor:"down"===o?"middle":l,baseline:"middle",fontSize:11})}}var p;return{sceneNodes:d,sceneEdges:h,labels:y}}};import{forceSimulation as Kt,forceCenter as Zt,forceX as Ut,forceY as Jt,forceLink as er,forceManyBody as tr,forceCollide as rr}from"d3-force";import{scaleLinear as nr}from"d3-scale";var or={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,r,n){if(0===e.length)return;const o=r.forceStrength??.1,i=n[0]/2,a=n[1]/2,s=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),c=Math.min(.5,.06+1.8*(1-s)),l=r.__previousPositions;let u=0;const d=[];for(const t of e){const e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),r=l?.get(t.id);e?u++:r?(t.x=r.x,t.y=r.y,u++):d.push(t)}const h=u>0&&.3>=(e.length>0?d.length/e.length:1);if(h){const r=new Map;for(const t of e)r.set(t.id,t);for(const e of d){const n=ir(e.id,t,r);if(n.length>0){let t=0,r=0;for(const e of n)t+=e.x,r+=e.y;const o=ar(e.id),i=o%360*(Math.PI/180),a=(10+o%20)*s;e.x=t/n.length+a*Math.cos(i),e.y=r/n.length+a*Math.sin(i)}else{const t=ar(e.id),r=t%360*(Math.PI/180),n=(15+t%30)*s;e.x=i+n*Math.cos(r),e.y=a+n*Math.sin(r)}}}else{const t=2.399963229728653;for(let r=0;e.length>r;r++){const n=e[r];if(null==n.x||null==n.y||0===n.x&&0===n.y){const e=10*Math.sqrt(r+.5)*s,o=r*t;n.x=i+e*Math.cos(o),n.y=a+e*Math.sin(o)}}}const y=r.__skipForceSimulation||0===r.iterations?0:h?40:r.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),f=sr(r.nodeSize,r.nodeSizeRange,e),g=e=>f(e);if(y>0){const l=new Map,u=new Map;for(const t of e)l.set(t.id,0),u.set(t.id,t);for(const e of t){const t="string"==typeof e.source?e.source:e.source.id,r="string"==typeof e.target?e.target:e.target.id;l.set(t,(l.get(t)??0)+1),l.set(r,(l.get(r)??0)+1)}const d=er().strength(e=>{const t=e.weight,r="string"==typeof e.target?e.target:e.target.id,n=Math.max(1,Math.min(l.get("string"==typeof e.source?e.source:e.source.id)??1,l.get(r)??1));return Math.min(2.5,(t&&t>0?Math.sqrt(t):1)*o/(.1*n))}).distance(e=>{const t="string"==typeof e.source?u.get(e.source):e.source,r="string"==typeof e.target?u.get(e.target):e.target,n=(t?g(t):0)+(r?g(r):0)+Math.max(6,12*s);return Math.max(16,40*s,n)}).id(e=>e.id),f=Kt();if(void 0===r.random&&void 0===r.seed||f.randomSource(r.random??Z(r.seed)),f.force("charge",tr().strength(e=>{const t=l.get(e.id)??0;return-15*s*g(e)*Math.sqrt(t+1)})).force("collide",rr(e=>g(e)+3*s).strength(.9).iterations(2)).force("center",Zt(i,a).strength(.8)).force("x",Ut(i).strength(c)).force("y",Jt(a).strength(c)).force("bounds",function(e,t,r=2,n=.6){let o=[];const i=i=>{const a=n*Math.max(i,.2);for(const n of o){const o=n.x??e[0]/2,i=n.y??e[1]/2,s=n.vx??0,c=n.vy??0,l=t(n)+r,u=Math.min(e[0]/2,l),d=Math.max(e[0]/2,e[0]-l),h=Math.min(e[1]/2,l),y=Math.max(e[1]/2,e[1]-l),f=o+s,g=i+c;u>f?n.vx=s+(u-f)*a:f>d&&(n.vx=s+(d-f)*a),h>g?n.vy=c+(h-g)*a:g>y&&(n.vy=c+(y-g)*a)}};return i.initialize=e=>{o=e},i}(n,g)),f.nodes(e),t.length>0){const e=t.map(e=>({...e,source:"string"==typeof e.source?e.source:e.source.id,target:"string"==typeof e.target?e.target:e.target.id}));d.links(e),f.force("link",d)}h?f.alpha(.3):.1>f.alpha()&&f.alpha(1),f.stop();for(let e=0;y>e;++e)f.tick()}for(const t of e){if(null==t.x||null==t.y)continue;const e=g(t),r=y>0?2:0,o=Math.min(n[0]/2,e+r),i=Math.min(n[1]/2,e+r);t.x=Math.max(o,Math.min(n[0]-o,t.x)),t.y=Math.max(i,Math.min(n[1]-i,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}const p=new Map;for(const t of e)p.set(t.id,t);for(const e of t){if("string"==typeof e.source){const t=p.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){const t=p.get(e.target);t&&(e.target=t)}}},buildScene(e,t,r,n){const o=r.nodeStyle,i=r.edgeStyle,a=sr(r.nodeSize,r.nodeSizeRange,e),s=Array.isArray(r.colorScheme)?r.colorScheme:r.themeCategorical&&r.themeCategorical.length>0?r.themeCategorical:ve,c=new Map;e.forEach((e,t)=>{c.set(e.id,s[t%s.length])});const l=[],u=[],d=[];for(const t of e){if(null==t.x||null==t.y)continue;const e=a(Gt(t,"nodeSize")),n=o?o(Gt(t,"nodeStyle")):{},i={fill:n.fill||c.get(t.id)||r.themeSemantic?.primary||"#007bff",stroke:n.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??2,opacity:n.opacity};l.push({type:"circle",cx:t.x,cy:t.y,r:e,style:i,datum:t,id:t.id,label:t.id})}const h=new Map;for(const t of e)h.set(t.id,t);for(const e of t){const t="object"==typeof e.source?e.source:h.get(e.source),n="object"==typeof e.target?e.target:h.get(e.target);if(!t||!n)continue;if(null==t.x||null==t.y)continue;if(null==n.x||null==n.y)continue;const o=i?i(Gt(e,"edgeStyle")):{};u.push({type:"line",x1:t.x,y1:t.y,x2:n.x,y2:n.y,style:{stroke:o.stroke||r.themeSemantic?.border||r.themeSemantic?.secondary||"#999",strokeWidth:o.strokeWidth??1,opacity:o.opacity??.6},datum:e})}if(!1!==r.showLabels){const t=(y=r.nodeLabel)?"function"==typeof y?y:e=>e[y]||e.id:null;for(const r of e){if(null==r.x||null==r.y)continue;const e=t?t(r):r.id;if(!e)continue;const n=a(Gt(r,"nodeSize"));d.push({x:r.x,y:r.y-n-4,text:e+"",anchor:"middle",baseline:"auto",fontSize:11})}}var y;return{sceneNodes:l,sceneEdges:u,labels:d}}};function ir(e,t,r){const n=[];for(const o of t){const t="string"==typeof o.source?o.source:o.source.id,i="string"==typeof o.target?o.target:o.target.id;let a=null;if(t===e?a=i:i===e&&(a=t),a){const e=r.get(a);!e||0===e.x&&0===e.y||n.push({x:e.x,y:e.y})}}return n}function ar(e){let t=0;for(let r=0;e.length>r;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t)}function sr(e,t,r){if(r.some(e=>null!=e.__forceRadius))return e=>e.__forceRadius??8;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;const n=t||[5,20],o=[];for(const t of r){const r=t.data?.[e];"number"==typeof r&&o.push(r)}if(0===o.length)return()=>n[0];const[i,a]=Le(o);if(i===a)return()=>(n[0]+n[1])/2;const s=nr().domain([i,a]).range(n).clamp(!0);return t=>{const r=t.data?.[e];return null==r||"number"!=typeof r?n[0]:s(r)}}import{chord as cr,ribbon as lr}from"d3-chord";import{arc as ur}from"d3-shape";var dr=ve,hr={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,r,n){if(0===e.length)return;const{padAngle:o=.01,groupWidth:i=20,sortGroups:a}=r,s=Math.min(n[0],n[1])/2,c=s-i,l=n[0]/2,u=n[1]/2,d=(h=r.valueAccessor)?"function"==typeof h?h:e=>e[h]??1:e=>e.value??1;var h;const y=new Map;for(let t=0;e.length>t;t++)y.set(e[t].id,t);const f=e.length,g=Array.from({length:f},()=>Array.from({length:f},()=>0));for(const e of t){const t="string"==typeof e.target?e.target:e.target.id,r=y.get("string"==typeof e.source?e.source:e.source.id),n=y.get(t);if(void 0===r||void 0===n)continue;const o=d(e);g[r][n]=o}const p=cr().padAngle(o);a&&p.sortGroups(a);const m=p(g),v=m.groups,x=ur().innerRadius(c).outerRadius(s);for(const t of v){const r=e[t.index],n=x.centroid({innerRadius:c,outerRadius:s,startAngle:t.startAngle,endAngle:t.endAngle});r.x=n[0]+l,r.y=n[1]+u,r.__arcData={startAngle:t.startAngle,endAngle:t.endAngle}}const k=new Map;for(const t of e)k.set(t.id,t);for(const e of t){const t="string"==typeof e.target?e.target:e.target.id,r=k.get("string"==typeof e.source?e.source:e.source.id),n=k.get(t);r&&(e.source=r),n&&(e.target=n)}const b=new Map;for(const e of t)b.set(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,e);for(const t of m){const r=e[t.source.index].id,n=e[t.target.index].id,o=b.get(`${r}\0${n}`)||b.get(`${n}\0${r}`);o&&(o.__chordData=t)}},buildScene(e,t,r,n){const{groupWidth:o=20,edgeOpacity:i=.5}=r,a=Math.min(n[0],n[1])/2,s=a-o,c=n[0]/2,l=n[1]/2,u=r.nodeStyle,d=r.edgeStyle,h=r.edgeColorBy||"source",y=Array.isArray(r.colorScheme)?r.colorScheme:r.themeCategorical&&r.themeCategorical.length>0?r.themeCategorical:dr,f=new Map;e.forEach((e,t)=>{f.set(e.id,y[t%y.length])});const g=lr().radius(s),p=[],m=[],v=[];for(let t=0;e.length>t;t++){const r=e[t],n=r.__arcData;if(!n)continue;let o;o=u?u(Gt(r,"nodeStyle")).fill||f.get(r.id)||y[t%y.length]:f.get(r.id)||y[t%y.length];const i=u?u(Gt(r,"nodeStyle")):{};p.push({type:"arc",cx:c,cy:l,innerR:s,outerR:a,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:{fill:o,stroke:i.stroke||"black",strokeWidth:i.strokeWidth??1,opacity:i.opacity},datum:r,id:r.id,label:r.id})}for(const e of t){const t=e.__chordData;if(!t)continue;const n=g(t);if(!n)continue;const o=yr(n,c,l);let a=r.themeSemantic?.border||r.themeSemantic?.secondary||"#999";if(d)a=d(Gt(e,"edgeStyle")).fill||a;else{const t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;"target"===h&&r?a=f.get(r.id)||a:t&&(a=f.get(t.id)||a)}const s=d?d(Gt(e,"edgeStyle")):{};m.push({type:"ribbon",pathD:o,style:{fill:a,fillOpacity:s.fillOpacity??i,stroke:s.stroke||"none",strokeWidth:s.strokeWidth,opacity:s.opacity},datum:e})}if(!1!==r.showLabels){const t=(x=r.nodeLabel)?"function"==typeof x?x:e=>e[x]||e.id:null,n=a+12;for(const r of e){const e=r.__arcData;if(!e)continue;const o=t?t(r):r.id;if(!o)continue;const i=(e.startAngle+e.endAngle)/2,a=i-Math.PI/2;v.push({x:c+Math.cos(a)*n,y:l+Math.sin(a)*n,text:o+"",anchor:i>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}var x;return{sceneNodes:p,sceneEdges:m,labels:v}}};function yr(e,t,r){const n=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return e;const o=[];let i=0;for(;n.length>i;){const e=n[i];if("M"===e||"L"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("C"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)for(let e=0;3>e&&n.length>i&&!isNaN(Number(n[i]));e++)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("Q"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)for(let e=0;2>e&&n.length>i&&!isNaN(Number(n[i]));e++)o.push(Number(n[i])+t+""),i++,n.length>i&&!isNaN(Number(n[i]))&&(o.push(Number(n[i])+r+""),i++);else if("A"===e)for(o.push(e),i++;n.length>i&&!isNaN(Number(n[i]));)o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&o.push(n[i++]),n.length>i&&(o.push(Number(n[i])+t+""),i++),n.length>i&&(o.push(Number(n[i])+r+""),i++);else"Z"===e||"z"===e?(o.push(e),i++):(o.push(n[i]),i++)}return o.join(" ")}import{hierarchy as fr,tree as gr,cluster as pr,treemap as mr,pack as vr,partition as xr,treemapBinary as kr}from"d3-hierarchy";var br=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Sr(e){const[t,r,n]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*r+.114*n>150?"#222":"#fff"}function _r(e,t,r){const n=t.nodeIDAccessor;return"function"==typeof n?n(e.data)+"":"string"==typeof n&&void 0!==e.data[n]?e.data[n]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+r}function wr(e){if(!e)return null;if("function"==typeof e){const t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function Ar(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:br}function Lr(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function Er(e,t,r,n,o){if("horizontal"===o){const o=(e+r)/2;return`M ${e},${t} C ${o},${t} ${o},${n} ${r},${n}`}if("radial"===o){const o=(e+r)/2;return`M ${e},${t} Q ${o},${t} ${o},${(t+n)/2} T ${r},${n}`}{const o=(t+n)/2;return`M ${e},${t} C ${e},${o} ${r},${o} ${r},${n}`}}var Pr={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,r,n){const o=r.__hierarchyRoot;if(!o)return;const i=r.chartType,a=function(e){if(e)return"function"==typeof e?e:t=>t[e]}(r.childrenAccessor),s=r.hierarchySum,c="function"==typeof s?s:"string"==typeof s?e=>Number(e[s])||0:e=>Number(e.value)||0,l=fr(o,a);l.sum(c),l.sort((e,t)=>(t.value??0)-(e.value??0));const[u,d]=n;switch(i){case"tree":!function(e,t,r,n){const o=t.treeOrientation||"vertical",i=gr();i.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),i(e)}(l,r,u,d);break;case"cluster":!function(e,t,r,n){const o=t.treeOrientation||"vertical",i=pr();i.size("horizontal"===o?[n,r]:"radial"===o?[2*Math.PI,Math.min(r,n)/2*.8]:[r,n]),i(e)}(l,r,u,d);break;case"treemap":!function(e,t,r,n){const o=t.padding??4,i=t.paddingTop??0,a=mr().size([r,n]).tile(kr).padding(o);i>0&&a.paddingTop(i),a(e)}(l,r,u,d);break;case"circlepack":!function(e,t,r,n){const o=t.padding??4;vr().size([r,n]).padding(o)(e)}(l,r,u,d);break;case"partition":!function(e,t,r,n){xr().size([r,n]).padding(t.padding??1)(e)}(l,r,u,d)}const h=l.descendants();e.length=0,t.length=0;const y=new Map;for(let t=0;h.length>t;t++){const n=h[t],o={id:_r(n,r,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:n.value??0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===i||"cluster"===i?Dr(o,n,r):"treemap"===i||"partition"===i?Mr(o,n):"circlepack"===i&&Rr(o,n),o.__hierarchyNode=n,e.push(o),y.set(n,o)}if("tree"===i||"cluster"===i)for(const e of h)if(e.parent){const r=y.get(e.parent),n=y.get(e);r&&n&&t.push({source:r,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,r,n){const o=r.nodeStyle||(()=>({})),i=r.edgeStyle||(()=>({}));switch(r.chartType){case"tree":case"cluster":return function(e,t,r,n,o,i){const a=[],s=[],c=[],l=r.treeOrientation||"vertical",u="radial"===l,d=n[0]/2,h=n[1]/2,y="number"==typeof(f=r.nodeSize)?f:5;var f;for(const t of e){let e=t.x,n=t.y;u&&(e+=d,n+=h);const i=o(Gt(t,"nodeStyle"));let s=i.fill||Lr(r);if(r.colorByDepth&&void 0!==t.depth){const e=Ar(r);s=e[t.depth%e.length]}a.push({type:"circle",cx:e,cy:n,r:y,style:{fill:s,stroke:i.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity},datum:t,id:t.id,label:t.id,depth:t.depth})}const g=r.edgeOpacity??.5;for(const e of t){const t="object"==typeof e.source?e.source:null,n="object"==typeof e.target?e.target:null;if(!t||!n)continue;let o=t.x,a=t.y,c=n.x,y=n.y;u&&(o+=d,a+=h,c+=d,y+=h);const f=Er(o,a,c,y,l),p=i(Gt(e,"edgeStyle"));s.push({type:"curved",pathD:f,style:{fill:"none",stroke:p.stroke||r.themeSemantic?.border||r.themeSemantic?.secondary||"#999",strokeWidth:p.strokeWidth??1.5,opacity:p.opacity??g},datum:e})}if(!1!==r.showLabels){const t=wr(r.nodeLabel);for(const r of e){const e=t?t(r):r.id;if(!e)continue;let n,o,i,a=r.x,s=r.y;if(u&&(a+=d,s+=h),u){const e=a-d,t=s-h,r=Math.sqrt(e*e+t*t);r>0?(n=a+e/r*10,o=s+t/r*10,i=0>e?"end":"start"):(n=a,o=s-12,i="middle")}else"horizontal"===l?(r.data?.children&&0!==r.data.children.length?(n=a-y-6,i="end"):(n=a+y+6,i="start"),o=s):(n=a,o=s+y+14,i="middle");c.push({x:n,y:o,text:e+"",anchor:i,baseline:"middle",fontSize:11})}}return{sceneNodes:a,sceneEdges:s,labels:c}}(e,t,r,n,o,i);case"treemap":case"partition":return function(e,t,r,n){const o=[],i=[];for(const r of e){const e=r.x1-r.x0,i=r.y1-r.y0;if(0>=e||0>=i)continue;const a=n(Gt(r,"nodeStyle"));let s=a.fill||Lr(t);if(t.colorByDepth&&void 0!==r.depth){const e=Ar(t);s=e[r.depth%e.length]}o.push({type:"rect",x:r.x0,y:r.y0,w:e,h:i,style:{fill:s,stroke:a.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??1,opacity:a.opacity},datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==t.showLabels){const r=wr(t.nodeLabel),o=t.labelMode||"leaf",a="partition"===t.chartType;for(const s of e){const e=s.x1-s.x0,c=s.y1-s.y0;if(0>=e||0>=c)continue;const l=!(s.data?.children&&s.data.children.length>0);if(!a){if("leaf"===o&&!l)continue;if("parent"===o&&l)continue}const u=r?r(s):s.id;if(!u)continue;if((l?30:40)>e||(l?16:14)>c)continue;let d=n(Gt(s,"nodeStyle")).fill||Lr(t);if(t.colorByDepth&&void 0!==s.depth){const e=Ar(t);d=e[s.depth%e.length]}const h="string"==typeof d?Sr(d):t.themeSemantic?.text??"#000";i.push(l?{x:s.x0+e/2,y:s.y0+c/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,c)/6)),fill:h}:{x:s.x0+4,y:s.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:o,sceneEdges:[],labels:i}}(e,r,0,o);case"circlepack":return function(e,t,r,n){const o=[],i=[];for(const r of e){const e=r.__radius??5;if(0>=e)continue;const i=n(Gt(r,"nodeStyle"));let a=i.fill||Lr(t);if(t.colorByDepth&&void 0!==r.depth){const e=Ar(t);a=e[r.depth%e.length]}o.push({type:"circle",cx:r.x,cy:r.y,r:e,style:{fill:a,stroke:i.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.7},datum:r,id:r.id,label:r.id,depth:r.depth})}if(!1!==t.showLabels){const r=wr(t.nodeLabel);for(const o of e){const e=o.__radius??5,a=r?r(o):o.id;if(!a)continue;if(15>e)continue;const s=!(o.data?.children&&o.data.children.length>0);let c=n(Gt(o,"nodeStyle")).fill||Lr(t);if(t.colorByDepth&&void 0!==o.depth){const e=Ar(t);c=e[o.depth%e.length]}if(s){const r="string"==typeof c?Sr(c):t.themeSemantic?.text??"#000";i.push({x:o.x,y:o.y,text:a+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:r})}else i.push({x:o.x,y:o.y-e+14,text:a+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:o,sceneEdges:[],labels:i}}(e,r,0,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Dr(e,t,r){const n=r.treeOrientation||"vertical";if("radial"===n){const r=t.x,n=t.y;e.x=n*Math.cos(r-Math.PI/2),e.y=n*Math.sin(r-Math.PI/2)}else"horizontal"===n?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);e.x0=e.x-5,e.x1=e.x+5,e.y0=e.y-5,e.y1=e.y+5,e.width=10,e.height=10}function Mr(e,t){e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.x=(t.x0+t.x1)/2,e.y=(t.y0+t.y1)/2,e.width=t.x1-t.x0,e.height=t.y1-t.y0}function Rr(e,t){const r=t.r??0;e.x=t.x,e.y=t.y,e.x0=t.x-r,e.x1=t.x+r,e.y0=t.y-r,e.y1=t.y+r,e.width=2*r,e.height=2*r,e.__radius=r}import{pie as Nr}from"d3-shape";function Tr(e){let t=e.__orbitState;return t||(t={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},e.__orbitState=t),t}var Cr={sankey:Qt,force:or,chord:hr,tree:Pr,cluster:Pr,treemap:Pr,circlepack:Pr,partition:Pr,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,r,n){const o=r.__hierarchyRoot;o&&function(e,t,r,n,o){const i=function(e){if("function"==typeof e)return e;const t=e||"children";return e=>e[t]||null}(r.childrenAccessor),a=function(e){if("function"==typeof e)return e;const t=e||"name";return e=>(e[t]??"")+""}(r.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(r.orbitMode),c=r.orbitSize??2.95,l=r.orbitEccentricity??1,u="number"==typeof c?()=>c:c,d="number"==typeof l?()=>l:l,h=Tr(r);h.metaMap.clear(),n.length=0,o.length=0;const y=new Map;function f(e){const t=y.get(e)??0;return y.set(e,t+1),0===t?e:`${e}__${t}`}const g=t[0]/2,p=t[1]/2,m=Math.min(t[0],t[1])/2*.85,v=f(a(e));n.push({id:v,x:g,y:p,x0:g,x1:g,y0:p,y1:p,width:0,height:0,value:0,depth:0,data:e}),h.metaMap.set(v,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,r,c,l,y,g,p){const m=i(t);if(!m?.length)return;const v=m.length;let x=0,k=0,b=0;for(;v>k;)k+=s[Math.min(b,s.length-1)],b++,x++;let S=0;for(let v=0;x>v;v++){const k=s[Math.min(v,s.length-1)],b=m.slice(S,S+k);if(!b.length)break;const _=(v+1)/x,w={id:r,depth:g,data:t,parentId:r},A=p?y/u(w)*_:y*_,L=Nr().value(e=>{const t=i(e)?.length;return t?4:1}).sort(null)(b),E=d(w);for(let t=0;b.length>t;t++){const i=(L[t].startAngle+L[t].endAngle)/2,s=b[t],u=f(a(s)),d=c+A*Math.sin(i),y=l+A*Math.cos(i)*E;n.push({id:u,x:d,y:y,x0:d,x1:d,y0:y,y1:y,width:0,height:0,value:0,depth:g,data:s}),h.metaMap.set(u,{ring:A,angle:i,depth:g,parentId:r,eccentricity:E}),o.push({source:r,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:r,target:u}}),e(s,u,d,y,A,g+1,!0)}S+=k}}(e,v,g,p,m,1,!1)}(o,n,r,e,t)},buildScene(e,t,r,n){const o=r.nodeStyle,i=r.nodeSize,a="number"==typeof i?()=>i:"function"==typeof i?i:()=>6,s=[],c=[],l=[];if(!1!==r.orbitShowRings){const t=Tr(r),n=new Map;for(const t of e)n.set(t.id,t);const o=new Map;for(const[,e]of t.metaMap){if(!e.parentId)continue;const t=n.get(e.parentId);if(!t)continue;const r=`${e.parentId}:${e.ring}`;o.has(r)||o.set(r,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}const i=48,a={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:e,parentY:t,ring:r,ecc:n}]of o)for(let o=0;i>o;o++){const s=o/i*Math.PI*2,l=(o+1)/i*Math.PI*2;c.push({type:"line",x1:e+r*Math.sin(s),y1:t+r*Math.cos(s)*n,x2:e+r*Math.sin(l),y2:t+r*Math.cos(l)*n,style:a,datum:null})}}for(const t of e){if(null==t.x||null==t.y)continue;const e=a(Gt(t,"nodeSize")),n=o?o(Gt(t,"nodeStyle")):{};s.push({type:"circle",cx:t.x,cy:t.y,r:e,style:{fill:n.fill||r.themeSemantic?.primary||"#6366f1",stroke:n.stroke||r.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.opacity??(0===(t.depth??0)?1:.85)},datum:t,id:t.id,label:t.id,depth:t.depth})}const u=new Map;for(const t of e)u.set(t.id,t);for(const e of t){const t="object"==typeof e.source?e.source:u.get(e.source),r="object"==typeof e.target?e.target:u.get(e.target);t&&r&&(null!=t.x&&null!=r.x&&c.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:e}))}if(r.showLabels){const t=r.nodeLabel;for(const r of e){const e=a(Gt(r,"nodeSize"));if(4>=e)continue;const n="function"==typeof t?t(r):t?r.data?.[t]??r.id:r.id;l.push({x:r.x,y:r.y+e+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:s,sceneEdges:c,labels:l}},tick:(e,t,r,n,o)=>!1!==r.orbitAnimated&&(function(e,t){const r=Tr(t),n=t.orbitSpeed??.25,o=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{const t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),i=(("undefined"!=typeof performance?performance.now():Date.now())-r.startTime)/1e3,a=n*(Math.PI/6),s=new Map;for(const t of e)s.set(t.id,t);for(const t of e){const e=r.metaMap.get(t.id);if(!e||!e.parentId)continue;const n=s.get(e.parentId);if(!n)continue;const c=e.angle+i*a*o({id:t.id,depth:e.depth,data:t.data,parentId:e.parentId});t.x=n.x+e.ring*Math.sin(c),t.y=n.y+e.ring*Math.cos(c)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,r),!0)}};function Wr(e){return Cr[e]}import{quadtree as Ir}from"d3-quadtree";function $r(e){return{id:e,x0:0,x1:0,y0:0,y1:0,x:0,y:0,width:0,height:0,value:0,createdByFrame:!0}}function zr(e){if(!e||"object"!=typeof e)return!1;const t=e;if("boolean"!=typeof t.circular)return!1;if("number"!=typeof t.halfWidth||!Number.isFinite(t.halfWidth))return!1;if(t.circular){if(!Array.isArray(t.segments)||0===t.segments.length)return!1;for(const e of t.segments)if(!Fr(e))return!1;return!0}return Fr(t.points)}function Fr(e){if(!Array.isArray(e)||4!==e.length)return!1;for(const t of e){if(!t||"object"!=typeof t)return!1;const e=t;if("number"!=typeof e.x||!Number.isFinite(e.x))return!1;if("number"!=typeof e.y||!Number.isFinite(e.y))return!1}return!0}import{interpolateNumber as Br}from"d3-interpolate";var Or="rgba(34, 197, 94, 0.7)",Yr=2e3,Xr=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],jr=["scene-style","data-paint","accessibility","evidence"],Hr=(e,t)=>({retainedData:e,invalidations:t}),Gr=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vr=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],qr=["scene-geometry","data-paint","overlay","accessibility","evidence"],Qr=["scene-style","data-paint","accessibility","evidence"],Kr=["scene-geometry","data-paint","overlay","accessibility","evidence"],Zr=[],Ur={chartType:Hr("rebuild",Gr),nodeIDAccessor:Hr("rebuild",Gr),sourceAccessor:Hr("rebuild",Gr),targetAccessor:Hr("rebuild",Gr),valueAccessor:Hr("rebuild",Gr),edgeIdAccessor:Hr("rebuild",Gr),childrenAccessor:Hr("rebuild",Gr),hierarchySum:Hr("rebuild",Gr),orientation:Hr("preserve",Vr),nodeAlign:Hr("preserve",Vr),nodePaddingRatio:Hr("preserve",Vr),nodeWidth:Hr("preserve",Vr),edgeSort:Hr("preserve",Vr),iterations:Hr("preserve",Vr),forceStrength:Hr("preserve",Vr),padAngle:Hr("preserve",Vr),groupWidth:Hr("preserve",Vr),sortGroups:Hr("preserve",Vr),treeOrientation:Hr("preserve",Vr),edgeType:Hr("preserve",Vr),padding:Hr("preserve",Vr),paddingTop:Hr("preserve",Vr),orbitMode:Hr("preserve",Vr),orbitSize:Hr("preserve",Vr),orbitSpeed:Hr("preserve",Vr),orbitRevolution:Hr("preserve",Vr),orbitRevolutionStyle:Hr("preserve",Vr),orbitEccentricity:Hr("preserve",Vr),orbitShowRings:Hr("preserve",Vr),orbitAnimated:Hr("preserve",Vr),customNetworkLayout:Hr("preserve",Vr),layoutConfig:Hr("preserve",Vr),nodeSize:Hr("preserve",qr),nodeSizeRange:Hr("preserve",qr),colorByDepth:Hr("preserve",qr),nodeLabel:Hr("preserve",Kr),showLabels:Hr("preserve",Kr),labelMode:Hr("preserve",Kr),nodeStyle:Hr("preserve",Qr),edgeStyle:Hr("preserve",Qr),colorBy:Hr("preserve",Qr),colorScheme:Hr("preserve",Qr),themeCategorical:Hr("preserve",Qr),themeSemantic:Hr("preserve",Qr),edgeColorBy:Hr("preserve",Qr),edgeOpacity:Hr("preserve",Qr),showParticles:Hr("preserve",Qr),particleStyle:Hr("preserve",Qr),decay:Hr("preserve",Qr),pulse:Hr("preserve",Qr),thresholds:Hr("preserve",Qr),staleness:Hr("preserve",Qr),layoutSelection:Hr("preserve",Qr),clock:Hr("preserve",Zr),random:Hr("preserve",Zr),seed:Hr("preserve",Zr),tensionConfig:Hr("preserve",Zr),transition:Hr("preserve",Zr),introAnimation:Hr("preserve",Zr),onLayoutError:Hr("preserve",Zr),__skipForceSimulation:Hr("preserve",Zr),__hierarchyRoot:Hr("preserve",Zr),__orbitState:Hr("preserve",Zr),__previousPositions:Hr("preserve",Zr)},Jr=Hr("preserve",Vr),en=class{constructor(){this.tracker=new X}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}},Xr)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},jr):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const r=new Set;for(const n of e){const e=Ur[n]??Jr;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)r.add(t)}return{retainedData:t,invalidations:r}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}},tn=class e{constructor(e){this.nodes=new Map,this.edges=new Map,this.tension=0,this.layoutVersion=0,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this.customLayoutHtmlMarks=[],this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this._customRestyleEdge=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._nodeQuadtree=null,this._maxNodeRadius=0,this._sceneNodesRevision=0,this._nodeQuadtreeRevision=-1,this._nodesArrCache=null,this._edgesArrCache=null,this._arrCacheVersion=-1,this.particlePool=null,this.updateResults=new en,this.transition=null,this._hasRenderedOnce=!1,this._boundedPrevSnapshot=null,this._boundedEdgeSnapshot=null,this.lastIngestTime=0,this.nodeTimestamps=new Map,this.edgeTimestamps=new Map,this._decaySortedNodes=null,this._decayAgeMap=null,this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set,this.lastTopologyChangeTime=0,this.previousNodeIds=new Set,this.previousEdgeKeys=new Set,this._networkDecayCache=null,this._lastPositionSnapshot=null,this.config=e,this.tensionConfig={...Oe,...e.tensionConfig},e.showParticles&&("sankey"===e.chartType||e.customNetworkLayout)&&(this.particlePool=new Xe(2e3))}currentTime(){return this.config.clock?.()??ue()}updateConfig(e){const t=this.config,r={...t,...e};t.__orbitState&&(r.__orbitState=t.__orbitState),t.__hierarchyRoot&&(r.__hierarchyRoot=t.__hierarchyRoot),void 0===e.layoutSelection&&null!=t.layoutSelection&&(r.layoutSelection=t.layoutSelection);const n=[...new Set([...Object.keys(t),...Object.keys(r)])].filter(e=>t[e]!==r[e]);this.config=r,this.tensionConfig={...Oe,...r.tensionConfig},!r.showParticles||"sankey"!==r.chartType&&!r.customNetworkLayout||this.particlePool||(this.particlePool=new Xe(2e3)),this.updateResults.recordConfig(n)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}ingestHierarchy(e,t){this._boundedPrevSnapshot=new Map;for(const[e,t]of this.nodes)0===t.x0&&0===t.x1&&0===t.y0&&0===t.y1||this._boundedPrevSnapshot.set(e,{x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1});this.nodes.clear(),this.edges.clear(),this._decaySortedNodes=null,this._networkDecayCache=null,this.config.__hierarchyRoot=e,this.runLayout(t),this._boundedPrevSnapshot=null,this.updateResults.recordData("replace",1)}ingestBounded(e,t,r,n){const{nodeIDAccessor:o="id",sourceAccessor:i="source",targetAccessor:a="target",valueAccessor:s="value"}=this.config,c="function"==typeof o?o:e=>e[o],l="function"==typeof i?i:e=>e[i],u="function"==typeof a?a:e=>e[a],d="function"==typeof s?s:e=>e[s]??1;this._boundedPrevSnapshot=new Map;for(const[e,t]of this.nodes)0===t.x0&&0===t.x1&&0===t.y0&&0===t.y1||this._boundedPrevSnapshot.set(e,{x0:t.x0,x1:t.x1,y0:t.y0,y1:t.y1});this._boundedEdgeSnapshot=new Map;for(const[,e]of this.edges)e.sankeyWidth>0&&this._boundedEdgeSnapshot.set(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`,{y0:e.y0,y1:e.y1,sankeyWidth:e.sankeyWidth});this.nodes.clear(),this.edges.clear(),this._decaySortedNodes=null,this._networkDecayCache=null;for(const t of e){const e=c(t)+"";this.nodes.set(e,{...$r(e),data:t})}for(let e=0;t.length>e;e++){const r=t[e],n=l(r)+"",o=u(r)+"",i=d(r),a=null==i?NaN:Number(i),s=Number.isFinite(a)?a:1;this.nodes.has(n)||this.nodes.set(n,{...$r(n),data:r}),this.nodes.has(o)||this.nodes.set(o,{...$r(o),data:r});const c=`${n}\0${o}\0${e}`,h={source:n,target:o,value:s,y0:0,y1:0,sankeyWidth:0,data:r,_edgeKey:c};r&&"object"==typeof r&&zr(r.bezier)&&(h.bezier=r.bezier),this.edges.set(c,h)}n?.deferLayout||this.runLayout(r),this.updateResults.recordData("replace",e.length+t.length)}ingestBoundedWithResult(e,t,r,n){return this.ingestBounded(e,t,r,n),this.updateResults.last}applyForceLayoutPositions(e,t){for(const[t,r]of Object.entries(e)){const e=this.nodes.get(t);e&&(e.x=r.x,e.y=r.y)}this.config.__skipForceSimulation=!0;try{this.runLayout(t)}finally{this.config.__skipForceSimulation=void 0}}edgeKey(e,t){return`${e}\0${t}`}ingestEdge(e){const{source:t,target:r,value:n}=e,o=0===this.nodes.size;let i=!1;const a=this.currentTime();this.lastIngestTime=a,this._decaySortedNodes=null,this._networkDecayCache=null,this.nodes.has(t)||(this.nodes.set(t,$r(t)),this.nodeTimestamps.set(t,a),this.tension+=this.tensionConfig.newNode,i=!0),this.nodes.has(r)||(this.nodes.set(r,$r(r)),this.nodeTimestamps.set(r,a),this.tension+=this.tensionConfig.newNode,i=!0);const s=this.edgeKey(t,r),c=this.edges.get(s);let l=!1;c?(c.value+=n,this.edgeTimestamps.set(s,a),this.tension+=this.tensionConfig.weightChange,l=!0):(this.edges.set(s,{source:t,target:r,value:n,y0:0,y1:0,sankeyWidth:0}),this.edgeTimestamps.set(s,a),this.tension+=this.tensionConfig.newEdge,i=!0);const u=o||i||l||this.tension>=this.tensionConfig.threshold;return this.updateResults.recordData("ingest",1),u}ingestEdgeWithResult(e){return this.ingestEdge(e),this.updateResults.last}runLayout(e){if(this.config.customNetworkLayout)return this.recordTopologyDiff(),void this.layoutVersion++;const t=Wr(this.config.chartType);if(!t)return;let r=Array.from(this.nodes.values());const n=Array.from(this.edges.values());if(0===r.length&&!t.hierarchical)return;if(this.prepareForRelayout(),t.supportsStreaming&&!t.hierarchical){const e=new Map;for(const t of r)void 0!==t._prevX0?e.set(t.id,{x:(t._prevX0??0)+((t._prevX1??0)-(t._prevX0??0))/2,y:(t._prevY0??0)+((t._prevY1??0)-(t._prevY0??0))/2}):0===t.x&&0===t.y||e.set(t.id,{x:t.x,y:t.y});if(this._lastPositionSnapshot)for(const[t,r]of this._lastPositionSnapshot)e.has(t)||e.set(t,r);this.config.__previousPositions=e.size>0?e:void 0}if(t.computeLayout(r,n,this.config,e),this.config.__previousPositions=void 0,t.hierarchical&&r.length>0){this.nodes.clear(),this.edges.clear(),this._decaySortedNodes=null,this._networkDecayCache=null;for(const e of r)this.nodes.set(e.id,e);for(let e=0;n.length>e;e++){const t=n[e],r=t._edgeKey||`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}\0${e}`;t._edgeKey=r,this.edges.set(r,t)}const e=this._boundedPrevSnapshot;if(e&&e.size>0)for(const t of this.nodes.values()){const r=e.get(t.id);r&&(t._prevX0=r.x0,t._prevX1=r.x1,t._prevY0=r.y0,t._prevY1=r.y1)}this._boundedPrevSnapshot=null,this._boundedEdgeSnapshot=null,r=Array.from(this.nodes.values())}this.finalizeLayout();const o=new Map;for(const e of this.nodes.values())0===e.x&&0===e.y||o.set(e.id,{x:e.x,y:e.y});this._lastPositionSnapshot=o,this.saveTargetPositions();const i=r.some(e=>void 0!==e._prevX0&&(0!==e._prevX0||0!==e._prevX1||0!==e._prevY0||0!==e._prevY1)),a=this.config.transition?.duration??this.tensionConfig.transitionDuration,s=["sankey","tree","treemap","circlepack","partition"].includes(this.config.chartType);if(!this._hasRenderedOnce&&this.config.introAnimation&&s&&r.length>0&&a>0){const t=e[0]/2,r=e[1]/2;for(const e of this.nodes.values())e._prevX0=t,e._prevX1=t,e._prevY0=r,e._prevY1=r;for(const e of this.edges.values())e._prevY0=r,e._prevY1=r,e._prevSankeyWidth=0,e._introFromZero=!0;this.restorePreviousPositions(),this.transition={startTime:this.currentTime(),duration:a}}else i&&a>0&&(this.restorePreviousPositions(),this.transition={startTime:this.currentTime(),duration:a});this._hasRenderedOnce=!0,this.recordTopologyDiff(),this.layoutVersion++}recordTopologyDiff(){const e=new Set(this.nodes.keys()),t=new Set(this.edges.keys());this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set;for(const t of e)this.previousNodeIds.has(t)||this.addedNodes.add(t);for(const t of this.previousNodeIds)e.has(t)||this.removedNodes.add(t);for(const e of t)this.previousEdgeKeys.has(e)||this.addedEdges.add(e);for(const e of this.previousEdgeKeys)t.has(e)||this.removedEdges.add(e);(this.addedNodes.size>0||this.removedNodes.size>0||this.addedEdges.size>0||this.removedEdges.size>0)&&(this.lastTopologyChangeTime=this.currentTime()),this.previousNodeIds=e,this.previousEdgeKeys=t}restyleScene(e){const t=function({nodes:e,edges:t,restyle:r,restyleEdge:n,baseStyles:o,selection:i}){const a=!(!r&&!n);if(r)for(const t of e){const e=o.get(t)??t.style,n=r(t,i);t.style=n?{...e,...n}:e}if(n)for(const e of t){const t=o.get(e)??e.style,r=n(e,i);e.style=r?{...t,...r}:t}return a}({nodes:this.sceneNodes,edges:this.sceneEdges,restyle:this._customRestyle,restyleEdge:this._customRestyleEdge,baseStyles:this._baseStyles,selection:e});this.markStylePaintPending(),this.updateResults.recordRestyle(t)}buildScene(e){if(this.config.customNetworkLayout){const t=function({config:e,customLayout:t,size:r,nodes:n,edges:o,previousResult:i,revision:a}){const c=R(e.colorScheme,e.themeCategorical,ve),l={nodes:n,edges:o,dimensions:{width:r[0],height:r[1],plot:{x:0,y:0,width:r[0],height:r[1]}},theme:{semantic:e.themeSemantic??{},categorical:[...c]},resolveColor:M(c,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};try{return{kind:"success",result:t(l)}}catch(t){const r=null!==i,n=s("network",t,r,a);"production"!==process.env.NODE_ENV&&console.error("[semiotic] customNetworkLayout threw:",t);try{e.onLayoutError?.(n)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return{kind:"failure",diagnostic:n,preservedLastGoodScene:r}}}({config:this.config,customLayout:this.config.customNetworkLayout,size:e,nodes:Array.from(this.nodes.values()),edges:Array.from(this.edges.values()),previousResult:this.lastCustomLayoutResult,revision:this.layoutVersion});if("failure"===t.kind)return this.lastCustomLayoutFailure=t.diagnostic,void(t.preservedLastGoodScene||(this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.customLayoutOverlays=null,this.customLayoutHtmlMarks=[],this.lastCustomLayoutResult=null,this._customRestyle=void 0,this._customRestyleEdge=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._sceneNodesRevision++));const r=t.result;return this.sceneNodes=r.sceneNodes??[],this.sceneEdges=r.sceneEdges??[],this.labels=r.labels??[],this.customLayoutOverlays=r.overlays??null,this.customLayoutHtmlMarks=r.htmlMarks??[],this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._sceneNodesRevision++,this._customRestyle=r.restyle,this._customRestyleEdge=r.restyleEdge,this.hasCustomRestyle=!(!r.restyle&&!r.restyleEdge),this.hasCustomRestyle&&(this._baseStyles=function(e,t){const r=new WeakMap;for(const t of e)r.set(t,t.style);for(const e of t)r.set(e,e.style);return r}(this.sceneNodes,this.sceneEdges),this.restyleScene(this.config.layoutSelection??null)),void L({label:"customNetworkLayout",nodes:this.sceneNodes,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned})}this._customRestyle=void 0,this._customRestyleEdge=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.customLayoutOverlays=null,this.customLayoutHtmlMarks=[],this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null;const t=Wr(this.config.chartType);if(!t)return void this._sceneNodesRevision++;const r=t.hierarchical?Array.from(this.nodes.values()):this.nodesArray,n=t.hierarchical?Array.from(this.edges.values()):this.edgesArray,{sceneNodes:o,sceneEdges:i,labels:a}=t.buildScene(r,n,this.config,e);this.sceneNodes=o,this.sceneEdges=i,this.labels=a,this._sceneNodesRevision++}rebuildNodeQuadtree(){let t=0,r=0;for(const e of this.sceneNodes)"circle"===e.type&&(t++,e.r>r&&(r=e.r));if(this._maxNodeRadius=r,e.QUADTREE_THRESHOLD>=t)return void(this._nodeQuadtree=null);const n=Array(t);let o=0;for(const e of this.sceneNodes)"circle"===e.type&&(n[o++]=e);this._nodeQuadtree=Ir().x(e=>e.cx).y(e=>e.cy).addAll(n)}get nodeQuadtree(){return this._nodeQuadtreeRevision!==this._sceneNodesRevision&&(this.rebuildNodeQuadtree(),this._nodeQuadtreeRevision=this._sceneNodesRevision),this._nodeQuadtree}get maxNodeRadius(){return this._maxNodeRadius}_ensureArrays(){this._arrCacheVersion===this.layoutVersion&&this._nodesArrCache&&this._edgesArrCache||(this._nodesArrCache=Array.from(this.nodes.values()),this._edgesArrCache=Array.from(this.edges.values()),this._arrCacheVersion=this.layoutVersion)}get nodesArray(){return this._ensureArrays(),this._nodesArrCache}get edgesArray(){return this._ensureArrays(),this._edgesArrCache}get isAnimating(){const e=Wr(this.config.chartType);return!!e?.supportsAnimation&&!1!==this.config.orbitAnimated}tickAnimation(e,t){const r=Wr(this.config.chartType);if(!r?.tick)return!1;const n=r.hierarchical?Array.from(this.nodes.values()):this.nodesArray,o=r.hierarchical?Array.from(this.edges.values()):this.edgesArray;return r.tick(n,o,this.config,e,t)}cancelIntroAnimation(){this.transition=null;for(const e of this.nodes.values())e._prevX0=void 0,e._prevX1=void 0,e._prevY0=void 0,e._prevY1=void 0;for(const e of this.edges.values())e._prevY0=void 0,e._prevY1=void 0,e._prevSankeyWidth=void 0,e._introFromZero=!1}advanceTransition(e){if(!this.transition)return!1;const t=Q(e,this.transition),r=V(t);for(const e of this.nodes.values())void 0===e._targetX0||void 0===e._prevX0||0===e._prevX0&&0===e._prevX1||(e.x0=ae(e._prevX0,e._targetX0,r),e.x1=ae(e._prevX1,e._targetX1,r),e.y0=ae(e._prevY0,e._targetY0,r),e.y1=ae(e._prevY1,e._targetY1,r));for(const e of this.edges.values())void 0!==e._targetY0&&void 0!==e._prevY0&&void 0!==e._prevSankeyWidth&&(e._prevSankeyWidth>0||e._introFromZero)&&(e.y0=ae(e._prevY0,e._targetY0,r),e.y1=ae(e._prevY1,e._targetY1,r),e.sankeyWidth=ae(e._prevSankeyWidth,e._targetSankeyWidth,r));return this.rebuildAllBeziers(),1>t||(this.snapToTargets(),this.transition=null,!1)}prepareForRelayout(){const e=this._boundedPrevSnapshot;for(const t of this.nodes.values()){const r=e?.get(t.id);r&&0===t.x0&&0===t.x1&&0===t.y0&&0===t.y1?(t._prevX0=r.x0,t._prevX1=r.x1,t._prevY0=r.y0,t._prevY1=r.y1):(t._prevX0=t.x0,t._prevX1=t.x1,t._prevY0=t.y0,t._prevY1=t.y1)}const t=this._boundedEdgeSnapshot;for(const e of this.edges.values()){if(t&&0===e.sankeyWidth){const r=t.get(`${"string"==typeof e.source?e.source:e.source.id}\0${"string"==typeof e.target?e.target:e.target.id}`);if(r){e._prevY0=r.y0,e._prevY1=r.y1,e._prevSankeyWidth=r.sankeyWidth;continue}}e._prevY0=e.y0,e._prevY1=e.y1,e._prevSankeyWidth=e.sankeyWidth}this.nodes.size>0&&(this._boundedPrevSnapshot=null,this._boundedEdgeSnapshot=null)}finalizeLayout(){const e="vertical"===this.config.orientation?"down":"right";for(const e of this.nodes.values())if(0!==e.x0||0!==e.x1||0!==e.y0||0!==e.y1)e.width=e.x1-e.x0,e.height=e.y1-e.y0,e.x=e.x0+e.width/2,e.y=e.y0+e.height/2;else{const t=5;e.x0=e.x-t,e.x1=e.x+t,e.y0=e.y-t,e.y1=e.y+t,e.width=2*t,e.height=2*t}for(const t of this.edges.values())t.direction=e,this.updateEdgeBezier(t);this.tension=0}saveTargetPositions(){for(const e of this.nodes.values())e._targetX0=e.x0,e._targetX1=e.x1,e._targetY0=e.y0,e._targetY1=e.y1;for(const e of this.edges.values())e._targetY0=e.y0,e._targetY1=e.y1,e._targetSankeyWidth=e.sankeyWidth}restorePreviousPositions(){for(const e of this.nodes.values())void 0===e._prevX0||0===e._prevX0&&0===e._prevX1||(e.x0=e._prevX0,e.x1=e._prevX1,e.y0=e._prevY0,e.y1=e._prevY1);for(const e of this.edges.values())void 0!==e._prevY0&&void 0!==e._prevSankeyWidth&&e._prevSankeyWidth>0&&(e.y0=e._prevY0,e.y1=e._prevY1,e.sankeyWidth=e._prevSankeyWidth);this.rebuildAllBeziers()}snapToTargets(){for(const e of this.nodes.values())void 0!==e._targetX0&&(e.x0=e._targetX0,e.x1=e._targetX1,e.y0=e._targetY0,e.y1=e._targetY1);for(const e of this.edges.values())void 0!==e._targetY0&&(e.y0=e._targetY0,e.y1=e._targetY1,e.sankeyWidth=e._targetSankeyWidth),e._introFromZero=void 0;this.rebuildAllBeziers()}updateEdgeBezier(e){!function(e,t,r=.5){const n="string"==typeof e.source?t.get(e.source):e.source,o="string"==typeof e.target?t.get(e.target):e.target;!n||!o||(e.bezier=e.circular&&e.circularPathData?function(e){const t=(e._circularWidth||e.sankeyWidth||1)/2,r=e.circularPathData;if(!r)throw Error("buildCircularBezier requires circularPathData");if(e._circularStub){const e=Math.max(15,Math.min(40,.33*(r.rightFullExtent-r.sourceX))),n=Math.max(15,Math.min(40,.33*(r.targetX-r.leftFullExtent)));return{circular:!0,segments:[[{x:r.sourceX,y:r.sourceY},{x:r.sourceX+.33*e,y:r.sourceY},{x:r.sourceX+.66*e,y:r.sourceY},{x:r.sourceX+e,y:r.sourceY}],[{x:r.targetX-n,y:r.targetY},{x:r.targetX-.66*n,y:r.targetY},{x:r.targetX-.33*n,y:r.targetY},{x:r.targetX,y:r.targetY}]],halfWidth:t}}let n;n="down"===e.direction?[{x:r.sourceY,y:r.sourceX},{x:r.sourceY,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.rightFullExtent},{x:r.verticalFullExtent,y:r.leftFullExtent},{x:r.targetY,y:r.leftFullExtent},{x:r.targetY,y:r.targetX}]:[{x:r.sourceX,y:r.sourceY},{x:r.rightFullExtent,y:r.sourceY},{x:r.rightFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.verticalFullExtent},{x:r.leftFullExtent,y:r.targetY},{x:r.targetX,y:r.targetY}];const o=[];for(let e=0;n.length-1>e;e++){const t=n[e],r=n[e+1],i=r.x-t.x,a=r.y-t.y;o.push([t,{x:t.x+i/3,y:t.y+a/3},{x:t.x+2*i/3,y:t.y+2*a/3},r])}return{circular:!0,segments:o,halfWidth:t}}(e):function(e,t,r,n=.5){const o=(e.sankeyWidth||1)/2;if("down"===e.direction){const i=t.x1,a=r.x0,s=Br(i,a);return{circular:!1,points:[{x:e.y0,y:i},{x:e.y0,y:s(n)},{x:e.y1,y:s(1-n)},{x:e.y1,y:a}],halfWidth:o}}const i=t.x1,a=r.x0,s=Br(i,a);return{circular:!1,points:[{x:i,y:e.y0},{x:s(n),y:e.y0},{x:s(1-n),y:e.y1},{x:a,y:e.y1}],halfWidth:o}}(e,n,o,r))}(e,this.nodes,.5)}rebuildAllBeziers(){for(const e of this.nodes.values())e.width=e.x1-e.x0,e.height=e.y1-e.y0,e.x=e.x0+e.width/2,e.y=e.y0+e.height/2;for(const e of this.edges.values())this.updateEdgeBezier(e)}applyPulse(e){!function(e){const t=e.pulse;if(!t)return;const r=t.duration??500,n=t.color??"rgba(255,255,255,0.6)",o=t.glowRadius??4,{now:i}=e;for(const t of e.sceneNodes){const a=t.id;if(!a)continue;const s=e.nodeTimestamps.get(a);if(!s)continue;const c=i-s;r>c&&(t._pulseIntensity=1-c/r,t._pulseColor=n,t._pulseGlowRadius=o)}for(const t of e.sceneEdges){const o=t.datum;if(!o)continue;const a="object"==typeof o.source?o.source?.id:o.source,s="object"==typeof o.target?o.target?.id:o.target;if(!a||!s)continue;const c=e.edgeTimestamps.get(`${a}\0${s}`);if(!c)continue;const l=i-c;r>l&&(t._pulseIntensity=1-l/r,t._pulseColor=n)}}({sceneNodes:this.sceneNodes,sceneEdges:this.sceneEdges,nodeTimestamps:this.nodeTimestamps,edgeTimestamps:this.edgeTimestamps,pulse:this.config.pulse,now:e})}applyDecay(){this._networkDecayCache||(this._networkDecayCache={sortedNodes:null,ageMap:null}),this._decaySortedNodes||(this._networkDecayCache.sortedNodes=null,this._networkDecayCache.ageMap=null),function(e){const t=e.decay;if(!t)return;const r=e.nodeTimestamps.size;if(1>=r)return;if(!e.cache.sortedNodes){e.cache.sortedNodes=Array.from(e.nodeTimestamps.entries()).sort((e,t)=>e[1]-t[1]);const t=new Map;for(let r=0;e.cache.sortedNodes.length>r;r++)t.set(e.cache.sortedNodes[r][0],r);e.cache.ageMap=t}const n=e.cache.ageMap;for(const o of e.sceneNodes){const e=o.id;if(!e)continue;const i=n.get(e);if(void 0===i)continue;const s=a(t,i,r);o.style={...o.style,opacity:(o.style?.opacity??1)*s}}}({sceneNodes:this.sceneNodes,nodeTimestamps:this.nodeTimestamps,decay:this.config.decay,cache:this._networkDecayCache}),this._decaySortedNodes=this._networkDecayCache.sortedNodes,this._decayAgeMap=this._networkDecayCache.ageMap}applyTopologyDiff(e){!function(e){for(const t of e.sceneNodes)t._pulseColor===Or&&(t._pulseIntensity=0,t._pulseColor=void 0,t._pulseGlowRadius=void 0);if(0===e.addedNodes.size)return;const t=e.now-e.lastTopologyChangeTime;if(t>=Yr)return;const r=1-t/Yr;for(const t of e.sceneNodes){const n=t.id;n&&e.addedNodes.has(n)&&(t._pulseIntensity=Math.max(t._pulseIntensity??0,r),t._pulseColor=Or,t._pulseGlowRadius=8)}}({sceneNodes:this.sceneNodes,addedNodes:this.addedNodes,lastTopologyChangeTime:this.lastTopologyChangeTime,now:e})}get hasActiveTopologyDiff(){return function(e,t,r=("undefined"!=typeof performance?performance.now():Date.now())){return 0!==e.size&&Yr>r-t}(this.addedNodes,this.lastTopologyChangeTime)}applyThresholds(e){!function(e){const t=e.thresholds;if(!t)return;const r=t.warningColor??"#f59e0b",n=t.criticalColor??"#ef4444",o=!1!==t.pulse;for(const i of e.sceneNodes){const a=i.id;if(!a)continue;const s=e.nodes.get(a);if(!s)continue;const c=t.metric(s);let l=null;void 0===t.critical||t.critical>c?void 0===t.warning||t.warning>c||(l=r):l=n,l&&(i.style={...i.style,fill:l},o&&(i._pulseIntensity=.6+.4*Math.sin(e.now/300),i._pulseColor=l,i._pulseGlowRadius=6))}}({sceneNodes:this.sceneNodes,nodes:this.nodes,thresholds:this.config.thresholds,now:e})}get hasActiveThresholds(){return function(e,t){if(!t)return!1;for(const r of e){const e=t.metric(r);if(void 0!==t.warning&&e>=t.warning||void 0!==t.critical&&e>=t.critical)return!0}return!1}(this.nodes.values(),this.config.thresholds)}get hasActivePulses(){return function(e){const t=e.pulse;if(!t||0===e.lastIngestTime)return!1;const r=e.now??("undefined"!=typeof performance?performance.now():Date.now());return(t.duration??500)>r-e.lastIngestTime}({pulse:this.config.pulse,lastIngestTime:this.lastIngestTime})}getLayoutData(){return{nodes:Array.from(this.nodes.values()),edges:Array.from(this.edges.values())}}updateNode(e,t){const r=this.nodes.get(e);if(!r)return this.updateResults.recordNoop("update"),null;const n=r.data?{...r.data}:{};return r.data=t(r.data??{}),this.layoutVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",1),n}updateEdge(e,t,r){const n=this.config.valueAccessor,o="function"==typeof n?n:n?e=>e[n]:e=>e.value,i=[];for(const[,n]of this.edges)if(("string"==typeof n.source?n.source:n.source.id)===e&&("string"==typeof n.target?n.target:n.target.id)===t){i.push(n.data?{...n.data}:{}),n.data=r(n.data??{});const e=o(n.data);null!=e&&(n.value=Number(e))}return i.length>0?(this.layoutVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",i.length)):this.updateResults.recordNoop("update"),i}removeNode(e){if(!this.nodes.has(e))return this.updateResults.recordNoop("remove"),!1;this.nodes.delete(e),this.nodeTimestamps.delete(e);for(const[t,r]of this.edges)("string"==typeof r.source?r.source:r.source.id)!==e&&("string"==typeof r.target?r.target:r.target.id)!==e||(this.edges.delete(t),this.edgeTimestamps.delete(t));return this.layoutVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",1),!0}removeEdge(e,t){const r=[];if(void 0===t){const t=this.config.edgeIdAccessor;if(!t)throw Error("removeEdge(edgeId) requires edgeIdAccessor to be configured. Use removeEdge(sourceId, targetId) instead.");const n="function"==typeof t?t:e=>e?.[t];for(const[t,o]of this.edges)o.data&&n(o.data)===e&&r.push(t)}else for(const[n,o]of this.edges)("string"==typeof o.source?o.source:o.source.id)===e&&("string"==typeof o.target?o.target:o.target.id)===t&&r.push(n);for(const e of r)this.edges.delete(e),this.edgeTimestamps.delete(e);return r.length>0?(this.layoutVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",r.length)):this.updateResults.recordNoop("remove"),r.length>0}clear(){this.nodes.clear(),this.edges.clear(),this._decaySortedNodes=null,this._networkDecayCache=null,this._decayAgeMap=null,this._nodeQuadtree=null,this._nodesArrCache=null,this._edgesArrCache=null,this._sceneNodesRevision++,this.tension=0,this.layoutVersion++,this.sceneNodes=[],this.sceneEdges=[],this.labels=[],this.customLayoutOverlays=null,this.customLayoutHtmlMarks=[],this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this._customRestyleEdge=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.transition=null,this._hasRenderedOnce=!1,this.lastIngestTime=0,this._lastPositionSnapshot=null,this.nodeTimestamps.clear(),this.edgeTimestamps.clear(),this.previousNodeIds=new Set,this.previousEdgeKeys=new Set,this.addedNodes=new Set,this.removedNodes=new Set,this.addedEdges=new Set,this.removedEdges=new Set,this.lastTopologyChangeTime=0,this._boundedPrevSnapshot=null,this._boundedEdgeSnapshot=null,this.particlePool&&this.particlePool.clear(),this.updateResults.recordData("clear")}};tn.QUADTREE_THRESHOLD=500;var rn=tn;n(rn);import*as nn from"react";import{Fragment as on,jsx as an,jsxs as sn}from"react/jsx-runtime";function cn(e){const{width:t,height:r,totalWidth:n,totalHeight:o,margin:i,labels:a,title:s,legend:c,legendHoverBehavior:u,legendClickBehavior:d,legendHighlightedCategory:h,legendIsolatedCategories:y,legendPosition:f="right",legendLayout:g,foregroundGraphics:p,sceneNodes:m,annotations:v,onAnnotationActivate:x,onObservation:k,chartId:b,chartType:S,autoPlaceAnnotations:_,svgAnnotationRules:w}=e,A=Se({onAnnotationActivate:x,onObservation:k,chartId:b,chartType:S}),L=nn.useMemo(()=>{const e=(m||[]).flatMap(e=>{const t=function(e){if("glyph"===e.type&&e.glyph&&"number"==typeof e.size){const t=e.cx??e.x,r=e.cy??e.y;if("number"!=typeof t||"number"!=typeof r)return null;const n=Pe(e.glyph,e.size);return{x:t+n.centerDx,y:r+n.centerDy,r:Math.max(1,n.radius)}}const t=e.cx??(null!=e.x&&null!=e.w?e.x+e.w/2:e.x),r=e.cy??(null!=e.y&&null!=e.h?e.y+e.h/2:e.y);return"number"!=typeof t||"number"!=typeof r?null:{x:t,y:r,r:"number"==typeof e.r?Math.max(1,e.r):"number"==typeof e.outerR?Math.max(1,e.outerR):"number"==typeof e.size?Math.max(1,be(e.size)):Math.max(1,e.w??0,e.h??0)/2}}(e),r=function(e){const t=e.id??e.datum?.id??e.datum?.data?.id??e.datum?.data?.name;return null==t?void 0:t+""}(e);return t?[{pointId:r,...t}]:[]});return{scales:null,width:t,height:r,frameType:"network",pointNodes:e,sceneNodes:m}},[r,m,t]),E=nn.useMemo(()=>{if(!v)return v;const e=l(v);return _?H({annotations:e,context:L,..."object"==typeof _?_:{}}):e},[v,_,L]),P=nn.useMemo(()=>K("network"),[]),D=E?ye(E.filter(e=>"widget"!==e.type),P,w,L):null,M=!0===E?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return sn(on,{children:[M&&an("style",{children:N},"annotation-widget-disclosure-style"),sn("svg",{role:"img",width:n,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:[an("title",{children:"string"==typeof s?s:"Network Chart"}),an("desc",{children:"string"==typeof s?s+" (network data visualization)":"Network data visualization"}),sn("g",{transform:`translate(${i.left},${i.top})`,children:[a.map((e,t)=>an("text",{x:e.x,y:e.y,textAnchor:e.anchor||"start",dominantBaseline:e.baseline||"middle",fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,style:{pointerEvents:"none"},children:e.text},"label-"+t)),D,p]}),s&&"string"==typeof s?an("text",{x:n/2,y:Y,textAnchor:"middle",fontWeight:600,fill:"currentColor",className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:s}):s?an("foreignObject",{x:0,y:0,width:n,height:i.top,children:s}):null,fe({legend:c,totalWidth:n,totalHeight:o,margin:i,legendPosition:f,title:s,legendLayout:g,legendHoverBehavior:u,legendClickBehavior:d,legendHighlightedCategory:h,legendIsolatedCategories:y})]}),E?.filter(e=>"widget"===e.type&&e.nodeId&&m).map((e,t)=>{const r=!0===e._annotationDeferred,n=m.find(t=>t.id===e.nodeId||t.datum?.id===e.nodeId||t.datum?.data?.id===e.nodeId||t.datum?.data?.name===e.nodeId);if(!n)return null;const o=i.left+(n.cx??(null!=n.x&&null!=n.w?n.x+n.w/2:n.x??0)),a=i.top+(n.cy??(null!=n.y&&null!=n.h?n.y+n.h/2:n.y??0)),s=e.dx??0,c=e.dy??-16,l=e.width??32,u=e.height??32,d=e.content??an("span",{style:{fontSize:18,cursor:"default"},children:"ℹ️"});return an("div",{...j(e,A),className:r?"annotation-deferred":void 0,"data-annotation-disclosure":r?"deferred":void 0,style:{position:"absolute",left:o+s-l/2,top:a+c-u/2,width:l,height:u,display:"flex",alignItems:"center",justifyContent:"center",zIndex:5},children:d},"widget-"+t)})]})}cn.displayName="NetworkSVGOverlay";import*as ln from"react";import{jsx as un}from"react/jsx-runtime";var dn={position:"absolute",top:0,left:0,pointerEvents:"none"};function hn({marks:e,margin:t,selection:r=null,overscan:n=400}){const o=ln.useRef(null),i=function(e,t,r){const[n,o]=ln.useState(null);return ln.useLayoutEffect(()=>{const e=t.current,r=function(e){let t=e?.parentElement??null;for(;t;){const{overflow:e,overflowX:r,overflowY:n}=window.getComputedStyle(t);if(/(auto|scroll|overlay)/.test(`${e} ${n} ${r}`))return t;t=t.parentElement}return null}(e);if(!e||!r)return void o(null);let n=0;const i=()=>{n=0;const t=r.getBoundingClientRect(),i=e.getBoundingClientRect();o(0!==t.width&&0!==t.height?{scroll:{left:t.left,top:t.top,right:t.right,bottom:t.bottom},originX:i.left,originY:i.top}:null)},a=()=>{0===n&&(n=window.requestAnimationFrame(i))};i(),r.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(r),()=>{0!==n&&window.cancelAnimationFrame(n),r.removeEventListener("scroll",a),s.disconnect()}},[t,e,r]),ln.useMemo(()=>{if(!e||!n)return e;const{scroll:t,originX:o,originY:i}=n,a=t.left-r,s=t.right+r,c=t.top-r,l=t.bottom+r;return e.filter(e=>{const t=o+e.x,r=i+e.y;return!(a>t+e.width||t>s||c>r+e.height||r>l)})},[e,n,r])}(e,o,n);if(!e||0===e.length)return null;const a=un("div",{className:"semiotic-network-html-marks",ref:o,style:{...dn,transform:`translate(${t.left}px, ${t.top}px)`},children:(i??e).map(e=>un("div",{className:"semiotic-network-html-mark","data-mark-id":e.id,style:{position:"absolute",transform:`translate(${e.x}px, ${e.y}px)`,width:e.width,height:e.height,pointerEvents:"none"},children:e.content},e.id))});return null!=r?un(E,{value:r,children:a}):a}import{jsx as yn,jsxs as fn}from"react/jsx-runtime";function gn({props:e,store:t,responsiveRef:r,size:n,margin:o,adjustedWidth:a,adjustedHeight:s,resolvedBackground:c,resolvedForeground:l}){const{chartType:u,nodes:d,edges:h,data:y,className:f,description:g,title:p,responsiveWidth:m,responsiveHeight:v,summary:x,background:b,renderMode:S,legend:_,legendPosition:w,legendLayout:A,legendHoverBehavior:L,legendClickBehavior:E,legendHighlightedCategory:D,legendIsolatedCategories:M,layoutSelection:R,annotations:N,onAnnotationActivate:T,annotationObservationCallback:C,onObservation:W,chartId:I,autoPlaceAnnotations:$,svgAnnotationRules:z}=e;if(t){const e=["tree","cluster","treemap","circlepack","partition","orbit"].includes(u),r=e?y||(Array.isArray(h)?void 0:h):void 0;if(e&&r)t.ingestHierarchy(r,[a,s]),t.buildScene([a,s]);else{const e=te(d),r=Array.isArray(h)?te(h):[];(e.length>0||r.length>0)&&(t.ingestBounded(e,r,[a,s]),t.buildScene([a,s]))}}const F=t?.sceneNodes??[],O=t?.sceneEdges??[],Y=t?.labels??[];return fn("div",{ref:r,className:"stream-network-frame"+(f?" "+f:""),role:"img","aria-label":g||("string"==typeof p?p:"Network chart"),style:{position:"relative",width:m?"100%":n[0],height:v?"100%":n[1]},children:[yn(B,{summary:x}),fn("svg",{xmlns:"http://www.w3.org/2000/svg",width:n[0],height:n[1],style:{position:"absolute",left:0,top:0},children:[c&&yn("g",{transform:`translate(${o.left},${o.top})`,children:c}),fn("g",{transform:`translate(${o.left},${o.top})`,children:[b&&yn("rect",{x:0,y:0,width:a,height:s,fill:b}),O.map((e,t)=>k({node:e,index:t,renderMode:S,fallback:()=>ce(e,t)})).filter(Boolean),F.map((e,t)=>k({node:e,index:t,renderMode:S,fallback:()=>le(e,t)})).filter(Boolean),Y.map((e,t)=>se(e,t)).filter(Boolean)]})]}),yn(cn,{width:a,height:s,totalWidth:n[0],totalHeight:n[1],margin:o,labels:Y,sceneNodes:F,title:p,legend:_,legendPosition:w,legendLayout:A,legendHoverBehavior:L,legendClickBehavior:E,legendHighlightedCategory:D,legendIsolatedCategories:M,foregroundGraphics:i(l,P(t?.customLayoutOverlays,R??null)),annotations:N,onAnnotationActivate:T,onObservation:C??W,chartId:I,chartType:"StreamNetworkFrame",autoPlaceAnnotations:$,svgAnnotationRules:z,annotationFrame:0}),yn(hn,{marks:t?.customLayoutHtmlMarks,margin:o,selection:R??null})]})}function pn(e,t,r,n,o=4e4){return"sync"!==e&&("worker"===e||n*(t+r)>=o)}function mn(){return"undefined"!=typeof window&&"undefined"!=typeof Worker}function vn(){if("undefined"!=typeof DOMException)return new DOMException("Force layout aborted","AbortError");const e=Error("Force layout aborted");return e.name="AbortError",e}var xn=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):D("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.worker=e,this.worker.onmessage=e=>{const t=e.data,r=t.requestId,n=null!=r?this.pending.get(r):this.pending.values().next().value;if(n){if(null!=r?this.pending.delete(r):this.pending.clear(),n.cleanup(),t.error){const e=Error(t.error.message);return e.name=t.error.name??"Error",t.error.stack&&(e.stack=t.error.stack),void n.reject(e)}n.resolve({positions:t.positions??{}})}},this.worker.onerror=e=>{this.rejectAll(Error(e.message||"Force layout worker failed")),this.terminate()}}get isDead(){return this.dead}request(e,t){if(this.dead)return Promise.reject(Error("Force layout worker session is closed"));if(t?.aborted)return Promise.reject(vn());const r=this.nextRequestId;this.nextRequestId+=1;const n={requestId:r,request:e};return new Promise((e,o)=>{const i=()=>{this.pending.delete(r),t?.removeEventListener("abort",i),o(vn())},a=()=>t?.removeEventListener("abort",i);this.pending.set(r,{cleanup:a,reject:o,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(n)}catch(e){this.pending.delete(r),a(),o(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error("Force layout worker terminated")),this.worker.terminate())}rejectAll(e){for(const t of this.pending.values())t.cleanup(),t.reject(e);this.pending.clear()}},kn=null;function bn(e,t){return mn()?t?.aborted?Promise.reject(vn()):(kn&&!kn.isDead||(kn=new xn),kn).request(e,t):Promise.reject(Error("Web Workers are unavailable"))}import{jsx as Sn,jsxs as _n}from"react/jsx-runtime";var wn=/^(value|amount|total|count|weight|score)$/i;function An({data:e}){if("edge"===e.nodeOrEdge){const t=e.data;return t?_n("div",{className:"semiotic-tooltip",style:U,children:[_n("div",{style:{fontWeight:600},children:["object"==typeof t.source?t.source.id:t.source," → ","object"==typeof t.target?t.target.id:t.target]}),null!=t.value&&_n("div",{style:{marginTop:4,opacity:.8},children:["Value:"," ","number"==typeof t.value?t.value.toLocaleString():t.value+""]})]}):null}const t=e.data;if(!t)return null;const r=t.__hierarchyNode;if(r){const e=[];let n=r;for(;n;){const r=n.data?.name??n.data?.id??t.id;null!=r&&e.unshift(r+""),n=n.parent}e.length>1&&e.shift();const o=e.length-1;return _n("div",{className:"semiotic-tooltip",style:U,children:[Sn("div",{children:e.map((e,t)=>_n("span",{children:[t>0&&Sn("span",{style:{margin:"0 3px",opacity:.5},children:" → "}),t===o?Sn("strong",{children:e}):Sn("span",{style:{opacity:.7},children:e})]},t))}),null!=t.value&&t.value>0&&Sn("div",{style:{marginTop:4,opacity:.8},children:"number"==typeof t.value?t.value.toLocaleString():t.value+""})]})}const n=(t.sourceLinks?.length||0)+(t.targetLinks?.length||0),o=(t.sourceLinks||[]).reduce((e,t)=>e+(t.value||0),0)+(t.targetLinks||[]).reduce((e,t)=>e+(t.value||0),0),i=xe(t.data??t),a=null!=i.title?i.title+"":t.id,s=i.entries.some(e=>wn.test(e.key));return _n("div",{className:"semiotic-tooltip",style:U,children:[Sn("div",{style:{fontWeight:600},children:a}),i.entries.map(e=>_n("div",{style:{marginTop:4,opacity:.8},children:[e.key,": ",d(e.value)]},e.key)),!s&&null!=t.value&&t.value>0&&_n("div",{style:{marginTop:4,opacity:.8},children:["Total:"," ","number"==typeof t.value?t.value.toLocaleString():t.value+""]}),n>0&&_n("div",{style:{marginTop:4,opacity:.8},children:["Connections: ",n,o!==n&&` (weighted: ${o.toLocaleString()})`]})]})}function Ln(e){return e._cachedPath2D&&e._cachedPath2DSource===e.pathD||(e._cachedPath2D=new Path2D(e.pathD),e._cachedPath2DSource=e.pathD),e._cachedPath2D}function En(e,t){if(!t.pathD)return;e.save();const r=Ln(t);if(t.style.fill&&"none"!==t.style.fill){const n=t._gradient;if(n){const r=e.createLinearGradient(n.x0,0,n.x1,0),o=t.style.fillOpacity??t.style.opacity??.5,i="string"==typeof t.style.fill?t.style.fill:"#999",a=ge(e,i)||i;r.addColorStop(0,1===n.from?a:"transparent"),r.addColorStop(1,1===n.to?a:"transparent"),e.fillStyle=r,e.globalAlpha=o}else e.fillStyle=pe(e,t.style.fill,"#007bff"),e.globalAlpha=t.style.fillOpacity??t.style.opacity??.5;e.fill(r)}t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??.5,e.globalAlpha=.5*(t.style.opacity??1),e.stroke(r)),t._pulseIntensity&&t._pulseIntensity>0&&(e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.globalAlpha=.2*t._pulseIntensity,e.fill(r)),e.restore()}function Pn(e,t){e.save();const r=t.style.stroke||"#999";e.strokeStyle=ge(e,r)||r,e.lineWidth=t.style.strokeWidth??1,void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.strokeDasharray&&e.setLineDash(t.style.strokeDasharray.split(/[\s,]+/).map(Number)),e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke(),t._pulseIntensity&&t._pulseIntensity>0&&(e.setLineDash([]),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=(t.style.strokeWidth??1)+3*t._pulseIntensity,e.globalAlpha=.4*t._pulseIntensity,e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke()),e.restore()}function Dn(e,t){if(!t.pathD)return;e.save();const r=Ln(t);t.style.fill&&"none"!==t.style.fill&&(e.fillStyle=pe(e,t.style.fill,"#007bff"),e.globalAlpha=t.style.fillOpacity??t.style.opacity??.5,e.fill(r)),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??.5,e.globalAlpha=.3*(t.style.opacity??1),e.stroke(r)),t._pulseIntensity&&t._pulseIntensity>0&&(e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.globalAlpha=.25*t._pulseIntensity,e.fill(r)),e.restore()}function Mn(e,t){if(!t.pathD)return;e.save();const r=Ln(t),n=t.style.stroke||"#999";e.strokeStyle=ge(e,n)||n,e.lineWidth=t.style.strokeWidth??1,void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.stroke(r),t.style.fill&&"none"!==t.style.fill&&(e.fillStyle=pe(e,t.style.fill,"#007bff"),e.globalAlpha=t.style.fillOpacity??.1,e.fill(r)),e.restore()}An.ownsChrome=!0;var Rn=new Map;function Nn(e){try{if(e.path)return new Path2D(e.path);const t=`${e.symbolType??"circle"}:${Math.round(e.size)}`;let r=Rn.get(t);return r||(r=new Path2D(ke(e.symbolType,e.size)),Rn.size>256&&Rn.clear(),Rn.set(t,r)),r}catch{return null}}function Tn(e,t,r,n=30){switch(e.type){case"circle":return function(e,t,r,n=30){const o=t-e.cx,i=r-e.cy,a=Math.sqrt(o*o+i*i);return a>h(e.r,n)?null:{type:"node",datum:e.datum,x:e.cx,y:e.cy,distance:a}}(e,t,r,n);case"rect":return function(e,t,r){const n=y(t,r,e);return n.hit?{type:"node",datum:e.datum,x:n.cx,y:n.cy,distance:0}:null}(e,t,r);case"arc":return function(e,t,r){const n=t-e.cx,o=r-e.cy,i=Math.sqrt(n*n+o*o);if(e.innerR-2>i||i>e.outerR+2)return null;const a=p(Math.atan2(o,n)),s=p(e.startAngle),c=p(e.endAngle);if(s>c?a>=s||c>=a:a>=s&&c>=a){const t=(e.startAngle+e.endAngle)/2,r=(e.innerR+e.outerR)/2;return{type:"node",datum:e.datum,x:e.cx+r*Math.cos(t),y:e.cy+r*Math.sin(t),distance:0}}return null}(e,t,r);case"symbol":return function(e,t,r,n=30){const o=t-e.cx,i=r-e.cy,a=Math.sqrt(o*o+i*i);return a>h(be(e.size),n)?null:{type:"node",datum:e.datum,x:e.cx,y:e.cy,distance:a}}(e,t,r,n);case"glyph":return function(e,t,r,n=30){if(null==e.datum)return null;const o=Pe(e.glyph,e.size),i=e.cx+o.centerDx,a=e.cy+o.centerDy,s=t-i,c=r-a,l=Math.sqrt(s*s+c*c);return l>h(o.radius,n)?null:{type:"node",datum:e.datum,x:i,y:a,distance:l}}(e,t,r,n);default:return null}}var Cn=null,Wn=null;function In(){return Wn||((Cn=document.createElement("canvas")).width=1,Cn.height=1,Wn=Cn.getContext("2d")),Wn}function $n(e){if(e._cachedPath2D&&e._cachedPath2DSource===e.pathD)return e._cachedPath2D;try{return e._cachedPath2D=new Path2D(e.pathD),e._cachedPath2DSource=e.pathD,e._cachedPath2D}catch{return null}}function zn(e,t,r){switch(e.type){case"bezier":return function(e,t,r){if(!e.pathD)return null;const n=$n(e),o=In();if(!n||!o)return null;try{if(o.isPointInPath(n,t,r))return{type:"edge",datum:e.datum,x:t,y:r,distance:0};const i=o.lineWidth;o.lineWidth=10;const a=o.isPointInStroke(n,t,r);if(o.lineWidth=i,a)return{type:"edge",datum:e.datum,x:t,y:r,distance:4}}catch{}return null}(e,t,r);case"line":return function(e,t,r){const n=e.x2-e.x1,o=e.y2-e.y1,i=n*n+o*o;if(0===i)return null;let a=((t-e.x1)*n+(r-e.y1)*o)/i;a=Math.max(0,Math.min(1,a));const s=e.x1+a*n,c=e.y1+a*o,l=Math.sqrt((t-s)**2+(r-c)**2);return l>5?null:{type:"edge",datum:e.datum,x:s,y:c,distance:l}}(e,t,r);case"ribbon":case"curved":return function(e,t,r){if(!e.pathD)return null;const n=$n(e),o=In();if(!n||!o)return null;try{if(o.isPointInPath(n,t,r))return{type:"edge",datum:e.datum,x:t,y:r,distance:0};const i=o.lineWidth;o.lineWidth=10;const a=o.isPointInStroke(n,t,r);if(o.lineWidth=i,a)return{type:"edge",datum:e.datum,x:t,y:r,distance:4}}catch{}return null}(e,t,r);default:return null}}function Fn(e){const{clientX:t,clientY:r,canvasRect:n,margin:o,adjustedWidth:i,adjustedHeight:a,sceneNodes:s,sceneEdges:c,nodeQuadtree:l,maxNodeRadius:d,hitRadius:h=30}=e,y=t-n.left-o.left,f=r-n.top-o.top;if(0>y||y>i||0>f||f>a)return{kind:"miss-outside"};const g=function(e,t,r,n,o=30,i,a=0){let s=null,c=o,l=1/0;if(i){const e=u(i,r,n,o,a,e=>e.cx,e=>e.cy,e=>e.r);e&&(s={type:"node",datum:e.node.datum,x:e.node.cx,y:e.node.cy,distance:e.distance},c=e.distance)}for(const t of e){if(i&&"circle"===t.type)continue;const e=Tn(t,r,n,o);if(e)if("rect"===t.type){const r=t.w*t.h;l>r&&(s=e,l=r)}else c>e.distance&&(s=e,c=e.distance)}if(s)return s;for(const e of t){if(!1===e.interactive)continue;const t=zn(e,r,n);t&&c>t.distance&&(s=t,c=t.distance)}return s}(s,c,y,f,h,l,d);return g?{kind:"hit",hover:G(g.datum||{},g.x,g.y,{nodeOrEdge:g.type})}:{kind:"miss"}}import{useCallback as Bn}from"react";var On="StreamNetworkFrame";import{jsx as Yn,jsxs as Xn}from"react/jsx-runtime";var jn={top:20,right:80,bottom:20,left:80},Hn={top:40,right:40,bottom:40,left:40},Gn=new Set(["chord","force","circlepack","orbit"]),Vn=[800,600],qn=Be(Fe(function(n,a){const{chartType:s,nodes:l,edges:u,data:d,initialEdges:h,nodeIDAccessor:y="id",sourceAccessor:p="source",targetAccessor:k="target",valueAccessor:L="value",edgeIdAccessor:E,childrenAccessor:D,hierarchySum:M,orientation:R="horizontal",nodeAlign:N="justify",nodePaddingRatio:Y=.05,nodeWidth:X=15,iterations:j=300,forceStrength:H=.1,layoutExecution:V="auto",layoutLoadingContent:Q,onLayoutStateChange:K,padAngle:Z=.01,groupWidth:U=20,sortGroups:ae,edgeSort:se,treeOrientation:ce="vertical",edgeType:le="curve",padding:ue,paddingTop:ye,tensionConfig:fe,showParticles:ve=!1,particleStyle:xe,renderMode:ke,nodeStyle:be,edgeStyle:Se,colorBy:Le,colorScheme:Pe="category10",edgeColorBy:Fe="source",edgeOpacity:Be=.5,colorByDepth:Xe=!1,nodeSize:je=8,nodeSizeRange:He=[5,20],nodeLabel:Ge,showLabels:Ve=!0,labelMode:qe,size:Qe=Vn,responsiveWidth:Ke,responsiveHeight:Ze,margin:Ue,className:Je,background:et,enableHover:tt=!0,tooltipContent:rt,customHoverBehavior:nt,customClickBehavior:ot,onObservation:it,annotationObservationCallback:at,chartId:st,onTopologyChange:ct,annotations:lt,onAnnotationActivate:ut,autoPlaceAnnotations:dt,svgAnnotationRules:ht,legend:yt,legendPosition:ft,legendLayout:gt,legendHoverBehavior:pt,legendClickBehavior:mt,legendHighlightedCategory:vt,legendIsolatedCategories:xt,title:kt,foregroundGraphics:bt,backgroundGraphics:St,decay:_t,pulse:wt,transition:At,animate:Lt,staleness:Et,frameScheduler:Pt,clock:Dt,random:Mt,seed:Rt,paused:Nt=!1,suspendWhenHidden:Tt=!0,thresholds:Ct,accessibleTable:Wt=!0,description:It,summary:$t,orbitMode:zt,orbitSize:Ft,orbitSpeed:Bt,orbitRevolution:Ot,orbitRevolutionStyle:Yt,orbitEccentricity:Xt,orbitShowRings:jt,orbitAnimated:Ht,customNetworkLayout:Gt,onLayoutError:Vt,layoutConfig:qt,layoutSelection:Qt}=n,Kt=Gn.has(s)?Hn:jn,Zt=Te(!0),Ut=_e({sizeProp:Qe,responsiveWidth:Ke,responsiveHeight:Ze,userMargin:Ue,marginDefault:Kt,title:kt,legend:yt,legendPosition:ft,foregroundGraphics:bt,backgroundGraphics:St,animate:Lt,transitionProp:At,frameScheduler:Pt,clock:Dt,random:Mt,seed:Rt,paused:Nt,suspendWhenHidden:Tt,themeDirtyRef:Zt}),{reducedMotionRef:Jt,responsiveRef:er,size:tr,margin:rr,adjustedWidth:nr,adjustedHeight:or,resolvedForeground:ir,resolvedBackground:ar,transition:cr,introEnabled:lr,tableId:ur,rafRef:dr,renderFnRef:hr,scheduleRender:yr,frameRuntime:fr,currentTheme:gr}=Ut,pr=Me(),mr=Re(),vr=Ie(()=>te(l),[l]),xr=Ie(()=>Array.isArray(u)?te(u):u,[u]),kr=Ie(()=>({...Oe,...fe}),[fe]),br=Ie(()=>({...Ye,...xe}),[xe]),Sr=Ie(()=>{return{chartType:(e={chartType:s,clock:fr.now,random:Mt,seed:Rt,nodeIDAccessor:y,sourceAccessor:p,targetAccessor:k,valueAccessor:L,edgeIdAccessor:E,childrenAccessor:D,hierarchySum:M,orientation:R,nodeAlign:N,nodePaddingRatio:Y,nodeWidth:X,iterations:j,forceStrength:H,padAngle:Z,groupWidth:U,sortGroups:ae,edgeSort:se,treeOrientation:ce,edgeType:le,padding:ue,paddingTop:ye,tensionConfig:kr,showParticles:ve,particleStyle:br,nodeStyle:be,edgeStyle:Se,nodeLabel:Ge,showLabels:Ve,labelMode:qe,colorBy:Le,colorScheme:Pe,edgeColorBy:Fe,edgeOpacity:Be,colorByDepth:Xe,nodeSize:je,nodeSizeRange:He,decay:_t,pulse:wt,transition:cr,introAnimation:lr,staleness:Et,thresholds:Ct,orbitMode:zt,orbitSize:Ft,orbitSpeed:Bt,orbitRevolution:Ot,orbitRevolutionStyle:Yt,orbitEccentricity:Xt,orbitShowRings:jt,orbitAnimated:Ht,customNetworkLayout:Gt,onLayoutError:Vt,layoutConfig:qt,currentTheme:gr}).chartType,clock:e.clock,random:e.random,seed:e.seed,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,edgeIdAccessor:e.edgeIdAccessor,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,tensionConfig:e.tensionConfig,showParticles:e.showParticles,particleStyle:e.particleStyle,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme,themeCategorical:e.currentTheme?.colors?.categorical,themeSemantic:Ee(e.currentTheme),edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,decay:e.decay,pulse:e.pulse,transition:e.transition,introAnimation:e.introAnimation,staleness:e.staleness,thresholds:e.thresholds,orbitMode:e.orbitMode,orbitSize:e.orbitSize,orbitSpeed:e.orbitSpeed,orbitRevolution:e.orbitRevolution,orbitRevolutionStyle:e.orbitRevolutionStyle,orbitEccentricity:e.orbitEccentricity,orbitShowRings:e.orbitShowRings,orbitAnimated:e.orbitAnimated,customNetworkLayout:e.customNetworkLayout,onLayoutError:e.onLayoutError,layoutConfig:e.layoutConfig};var e},[s,fr.now,Mt,Rt,y,p,k,L,E,D,M,R,N,Y,X,j,H,Z,U,ae,se,ce,le,ue,ye,kr,ve,br,be,Se,Ge,Ve,qe,Le,Pe,Fe,Be,Xe,je,He,_t,wt,cr,lr,Et,Ct,zt,Ft,Bt,Ot,Yt,Xt,jt,Ht,Gt,Vt,qt,gr]),_r=w(Sr),wr=w({chartType:(Ar={chartType:s,nodeIDAccessor:y,sourceAccessor:p,targetAccessor:k,valueAccessor:L,edgeIdAccessor:E,childrenAccessor:D,hierarchySum:M,orientation:R,nodeAlign:N,nodePaddingRatio:Y,nodeWidth:X,iterations:j,forceStrength:H,padAngle:Z,groupWidth:U,sortGroups:ae,edgeSort:se,treeOrientation:ce,edgeType:le,padding:ue,paddingTop:ye,random:Mt,seed:Rt,tensionConfig:kr,customNetworkLayout:Gt,orbitMode:zt,orbitSize:Ft,orbitEccentricity:Xt}).chartType,nodeIDAccessor:Ar.nodeIDAccessor,sourceAccessor:Ar.sourceAccessor,targetAccessor:Ar.targetAccessor,valueAccessor:Ar.valueAccessor,edgeIdAccessor:Ar.edgeIdAccessor,childrenAccessor:Ar.childrenAccessor,hierarchySum:Ar.hierarchySum,orientation:Ar.orientation,nodeAlign:Ar.nodeAlign,nodePaddingRatio:Ar.nodePaddingRatio,nodeWidth:Ar.nodeWidth,iterations:Ar.iterations,forceStrength:Ar.forceStrength,padAngle:Ar.padAngle,groupWidth:Ar.groupWidth,sortGroups:Ar.sortGroups,edgeSort:Ar.edgeSort,treeOrientation:Ar.treeOrientation,edgeType:Ar.edgeType,padding:Ar.padding,paddingTop:Ar.paddingTop,random:Ar.random,seed:Ar.seed,tensionConfig:Ar.tensionConfig,customNetworkLayout:Ar.customNetworkLayout,orbitMode:Ar.orbitMode,orbitSize:Ar.orbitSize,orbitEccentricity:Ar.orbitEccentricity});var Ar;const Lr=Te(0),Er=Te(0),Pr=Te(!1),Dr=Te(null);Dr.current||(Dr.current=new rn(_r));const Mr=Ae("StreamNetworkFrame"),Rr=$e((e,t,r=!1)=>me(Mr.current,e,()=>e.buildScene(t),r),[Mr]),[Nr,Tr]=Ce(null),[Cr,Wr]=Ce(0),[Ir,$r]=Ce(0),[zr,Fr]=Ce(!1),[Br,Or]=Ce(!1),Yr=Te(0),Xr=Te(null),jr=Te(!1),Hr=Te(K);Hr.current=K;const Gr=Te(_r);Gr.current=_r;const Vr=Te(null),qr=Te(new Map),Qr=Te(0),Kr=$e(e=>function(e){const{node:t,colorBy:r,colorScheme:n,nodeColorMap:o,colorIndexRef:i}=e;if("function"==typeof r)return r(t)+"";if("string"==typeof r&&t.data){const e=t.data[r];if(void 0!==e){if(!o.has(e+"")){const t=Array.isArray(n)?n:W;o.set(e+"",t[i.current++%t.length])}return o.get(e+"")}}if(o.has(t.id))return o.get(t.id);const a=Array.isArray(n)?n:W,s=r?a[i.current++%a.length]:a[0];return o.set(t.id,s),s}({node:e,colorBy:Le,colorScheme:Pe,nodeColorMap:qr.current,colorIndexRef:Qr}),[Le,Pe]),Zr=$e(e=>{Qr.current=function(e){const{sceneNodes:t,nodes:r,nodeColorMap:n,colorScheme:o}=e;for(const e of t)e.id&&"string"==typeof e.style?.fill&&n.set(e.id,e.style.fill);const i=Array.isArray(o)?o:W,a=Array.from(r);for(let e=0;a.length>e;e++){const t=a[e];n.has(t.id)||n.set(t.id,i[e%i.length])}return a.length}({sceneNodes:e.sceneNodes,nodes:e.nodes.values(),nodeColorMap:qr.current,colorScheme:Pe})},[Pe]),Ur=$e((e,t)=>{Rr(e,t),Zr(e),Zt.current=!1,e.markStylePaintPending()},[Rr,Zr]),Jr=(en=gr,en?.colors?.border||en?.colors?.secondary||en?.colors?.primary||"#999");var en;const tn=$e(e=>function(e,t){return e?"object"==typeof e?e:t?.get(e)??null:null}(e,Dr.current?.nodes),[]),nn=$e(e=>function(e){const{edge:t,edgeColorBy:r,getNodeColor:n,resolveEndpoint:o,fallback:i}=e;if("function"==typeof r)return r(t);const a=o(t.source),s=o(t.target);return"target"===r&&s?n(s):a?n(a):i}({edge:e,edgeColorBy:Fe,getNodeColor:Kr,resolveEndpoint:tn,fallback:Jr}),[Fe,Kr,Jr,tn]),on=$e(e=>function(e){const{edge:t,particleStyleColor:r,particleColorBy:n,hasExplicitParticleColorBy:o,getEdgeColor:i,getNodeColor:a,resolveEndpoint:s,fallback:c}=e;if("function"==typeof r){const e=s(t.source);return e?r(t,e):c}if(!o)return i(t);const l=n,u=s(t.source),d=s(t.target);return"target"===l&&d?a(d):u?a(u):c}({edge:e,particleStyleColor:br.color,particleColorBy:br.colorBy,hasExplicitParticleColorBy:!!xe?.colorBy,getEdgeColor:nn,getNodeColor:Kr,resolveEndpoint:tn,fallback:Jr}),[xe?.colorBy,br.color,br.colorBy,Kr,nn,Jr,tn]),an=function(e,t,r,n,o){return("sankey"===e||t)&&r||n||o}(s,!!Gt,ve,!!wt,Dr.current?.isAnimating??!1);S(Dr,_r,Zt,yr),_(Dr,Qt,Zt,yr),We(()=>{const e=Dr.current;e&&(Ur(e,[nr,or]),yr())},[gr,nr,or,Ur,yr]);const sn=$e(()=>{const e=Dr.current;if(e&&(e.runLayout([nr,or]),Ur(e,[nr,or]),Wr(e.layoutVersion),ct)){const{nodes:t,edges:r}=e.getLayoutData();ct(t,r)}},[nr,or,Ur,ct]),ln=$e(e=>{if(null==e||"object"!=typeof e)return;const t=Dr.current;t&&(t.ingestEdge(e)&&sn(),yr())},[sn,yr]),un=$e(e=>{const t=Dr.current;if(!t)return;let r=!1;for(const n of e)null!=n&&"object"==typeof n&&t.ingestEdge(n)&&(r=!0);r&&sn(),yr()},[sn,yr]),dn=$e(()=>{Dr.current?.clear(),qr.current.clear(),Qr.current=0,Wr(Dr.current?.layoutVersion??0),Tr(null),Vr.current=null,Zt.current=!0,yr()},[yr]),yn=$e(()=>{const e=Dr.current;e&&(e.tension+=999,sn(),yr())},[sn,yr]);ze(a,()=>({push:ln,pushMany:un,removeNode:e=>{const t=Dr.current?.removeNode(e)??!1;if(t){const t=Vr.current?.data?"function"==typeof y?y(Vr.current.data):Vr.current.data[y]:void 0;Vr.current&&"node"===Vr.current.nodeOrEdge&&t===e&&(Vr.current=null,Tr(null)),qr.current.delete(e),sn(),Zt.current=!0,yr()}return t},removeEdge:(e,t)=>{const r=Dr.current?.removeEdge(e,t)??!1;if(r){if(Vr.current&&"edge"===Vr.current.nodeOrEdge){const r=Vr.current.data;let n;n=void 0!==t?("object"==typeof r?.source?r.source.id:r?.source)===e&&("object"==typeof r?.target?r.target.id:r?.target)===t:!E||!r||("function"==typeof E?E:e=>e?.[E])(r)===e,n&&(Vr.current=null,Tr(null))}sn(),Zt.current=!0,yr()}return r},updateNode:(e,t)=>{const r=Dr.current?.updateNode(e,t)??null;return r&&(sn(),Zt.current=!0,yr()),r},updateEdge:(e,t,r)=>{const n=Dr.current?.updateEdge(e,t,r)??[];return n.length>0&&(sn(),Zt.current=!0,yr()),n},clear:dn,getTopology:()=>Dr.current?.getLayoutData()??{nodes:[],edges:[]},getCustomLayout:()=>Dr.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>Dr.current?.lastCustomLayoutFailure??null,getTopologyDiff:()=>{const e=Dr.current;return e?{addedNodes:Array.from(e.addedNodes),removedNodes:Array.from(e.removedNodes),addedEdges:Array.from(e.addedEdges),removedEdges:Array.from(e.removedEdges)}:{addedNodes:[],removedNodes:[],addedEdges:[],removedEdges:[]}},relayout:yn,getTension:()=>Dr.current?.tension??0}),[ln,un,dn,yn,y,sn,yr,E]);const fn=["tree","cluster","treemap","circlepack","partition","orbit"].includes(s),vn=fn?d||(Array.isArray(u)?void 0:u):void 0;We(()=>{const e=Dr.current;if(!e)return;const t=++Yr.current;if(Xr.current?.abort(),Xr.current=null,fn&&vn)e.ingestHierarchy(vn,[nr,or]),Ur(e,[nr,or]),Or(!1),Hr.current?.("ready"),yr();else{const r=vr,n=Array.isArray(xr)?xr:[];if(0===r.length&&0===n.length)return null==l&&null==u||0>=e.nodes.size&&0>=e.edges.size||dn(),Or(!1),void Hr.current?.("ready");const o=[nr,or],i="force"===s&&!Gt&&mn()&&!Mt&&pn(V,r.length,n.length,j);if(i&&mr&&!jr.current&&e.sceneNodes.length>0)return jr.current=!0,Or(!1),Hr.current?.("ready"),Zt.current=!0,void yr();if(i){const i=new AbortController;Xr.current=i;const a=e._lastPositionSnapshot;e.ingestBounded(r,n,o,{deferLayout:!0});const s=e.getLayoutData(),c=function(e,t,r,n,o){const i=sr(r.nodeSize,r.nodeSizeRange,e);return{kind:"frame",nodes:e.map(e=>{const t=o?.get(e.id);return{id:e.id,x:0!==e.x||0!==e.y?e.x:t?.x??0,y:0!==e.x||0!==e.y?e.y:t?.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:e.value,__forceRadius:i(e)}}),edges:t.map(e=>{const t="string"==typeof e.source?e.source:e.source.id,r="string"==typeof e.target?e.target:e.target.id,n=e.data?.weight,o="number"==typeof n&&Number.isFinite(n)?n:e.value;return{source:t,target:r,value:e.value,y0:0,y1:0,sankeyWidth:0,weight:o}}),config:{chartType:"force",iterations:r.iterations,forceStrength:r.forceStrength,seed:r.seed},size:n}}(s.nodes,s.edges,Gr.current,o,a);return Or(!0),Hr.current?.("pending"),bn(c,i.signal).then(({positions:r})=>{t===Yr.current&&(e.applyForceLayoutPositions(r,o),Ur(e,o),Or(!1),Hr.current?.("ready"),Wr(e.layoutVersion),yr())}).catch(r=>{"AbortError"!==r.name&&t===Yr.current&&(e.runLayout(o),Ur(e,o),Or(!1),Hr.current?.("error"),Wr(e.layoutVersion),yr())}),()=>i.abort()}e.ingestBounded(r,n,o),Ur(e,o),Or(!1),Hr.current?.("ready"),yr()}},[vr,xr,l,u,d,vn,fn,nr,or,wr,V,j,mr,s,Gt,Mt,yr,dn,Ur]);const xn=Ne.useRef(!1);We(()=>{xn.current||h&&h.length>0&&(xn.current=!0,un(h))},[h,un]);const{customHoverBehavior:kn,customClickBehavior:Sn}=function({customHoverBehavior:e,customClickBehavior:t,onObservation:r,chartId:n}){return{customHoverBehavior:Bn((t,o)=>{e?.(t,o),ee({onObservation:r,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:On,chartId:n,context:o})},[e,r,n]),customClickBehavior:Bn((e,o)=>{t?.(e,o),J({onObservation:r,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:On,chartId:n,context:o})},[t,r,n])}}({customHoverBehavior:nt,customClickBehavior:ot,onObservation:it,chartId:st}),{hoverHandlerRef:_n,hoverLeaveRef:wn,onPointerMove:Ln,onPointerLeave:Rn}=Ut,Tn=()=>!Gt||(Dr.current?.hasCustomRestyle??!1);_n.current=e=>{if(!tt)return;const t=Tn(),r=Kn.current;if(!r)return;const n=Dr.current;if(!n)return;const o=Fn({clientX:e.clientX,clientY:e.clientY,canvasRect:r.getBoundingClientRect(),margin:rr,adjustedWidth:nr,adjustedHeight:or,sceneNodes:n.sceneNodes,sceneEdges:n.sceneEdges,nodeQuadtree:n.nodeQuadtree,maxNodeRadius:n.maxNodeRadius});"hit"===o.kind?(Vr.current=o.hover,Tr(o.hover),kn&&(kn(o.hover),t&&(Zt.current=!0)),t&&yr()):Vr.current&&(Vr.current=null,Tr(null),kn&&(kn(null),t&&(Zt.current=!0)),t&&yr())},wn.current=()=>{if(Vr.current){const e=Tn();Vr.current=null,Tr(null),kn&&(kn(null),e&&(Zt.current=!0)),e&&yr()}};const Cn=Te(()=>{});Cn.current=e=>{if(ne(e.target))return;if(!ot&&!it)return;const t=Kn.current;if(!t)return;const r=Dr.current;if(!r)return;const n=Fn({clientX:e.clientX,clientY:e.clientY,canvasRect:t.getBoundingClientRect(),margin:rr,adjustedWidth:nr,adjustedHeight:or,sceneNodes:r.sceneNodes,sceneEdges:r.sceneEdges,nodeQuadtree:r.nodeQuadtree,maxNodeRadius:r.maxNodeRadius});"hit"===n.kind?Sn(n.hover,{type:"activate",inputType:de(e.nativeEvent.pointerType)}):"miss"===n.kind&&Sn(null)};const Wn=$e(e=>Cn.current(e),[]),In=Te(-1),$n=Te(null),zn=Te(-1),qn=$e(e=>{if(oe(e))return;const t=Dr.current;if(!t)return;const r=()=>{In.current=-1,$n.current=null,zn.current=-1,Vr.current=null,Tr(null),kn&&(kn(null),Zt.current=!0),yr()},n=c(t.sceneNodes);if(0===n.length)return void(0>In.current||r());const i=o(n);let a=In.current;if(i.flat.length>a||(r(),a=-1)," "===e.key&&a>=0){e.preventDefault();const t=i.flat[a];return void Sn(G(t.datum||{},t.x,t.y,{nodeOrEdge:"node"}),{type:"activate",inputType:"keyboard"})}if(0>a){if("Escape"===e.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown","Enter"].includes(e.key))return;e.preventDefault(),In.current=0,zn.current=-1;const t=i.flat[0];$n.current={shape:t.shape,w:t.w,h:t.h};const r=G(t.datum||{},t.x,t.y,{nodeOrEdge:"node"});return Vr.current=r,Tr(r),kn&&(kn(r,{type:"focus",inputType:"keyboard"}),Zt.current=!0),void yr()}const s=b(i,a),l=g(e.key,s,i,t.sceneEdges??[],zn);if(null===l)return;if(e.preventDefault(),0>l)return void r();In.current=l;const u=i.flat[l];$n.current={shape:u.shape,w:u.w,h:u.h};const d={data:u.datum||{},x:u.x,y:u.y,__semioticHoverData:!0,nodeOrEdge:"node"};Vr.current=d,Tr(d),kn&&(kn(d,{type:"focus",inputType:"keyboard"}),Zt.current=!0),yr()},[Sn,kn,yr]),Qn=$e(e=>{In.current=-1,$n.current=null,Ln(e)},[Ln]);hr.current=()=>{if(dr.current=null,!fr.isActive)return;const r=Kn.current;if(!r)return;const n=Dr.current;n&&function(r){const{canvas:n,store:o,sceneRevisionDiagnostics:i,size:a,margin:s,adjustedWidth:c,adjustedHeight:l,background:u,renderMode:d,hasBackgroundGraphics:h=!1,dirtyRef:y,lastFrameTimeRef:g,now:p,random:k,reducedMotion:b,showParticles:S,isContinuous:_,animate:w,decay:A,pulse:L,thresholds:E,staleness:P,particleStyle:D,getParticleColor:M,pendingAnnotationFrameRef:R,lastAnnotationFrameTimeRef:N,setAnnotationFrame:T,scheduleNextFrame:C,syncColorMap:W}=r,I=n.getContext("2d");if(!I)return;const $=g.current?Math.min((p-g.current)/1e3,.1):.016;g.current=p;const z=o.advanceTransition(b?p+1e6:p),F=!b&&z,B=!b&&o.tickAnimation([c,l],$),O=y.current,Y=i?.beforeCompute(o.getLastUpdateResult(),F),X=z||O||B;X&&(o.buildScene([c,l]),O&&W?.()),Y&&i?.afterCompute(Y,X,!1);const j=S&&!b&&!!o.particlePool,H=!!A||!!L||!!E||!1!==w&&o.hasActiveTopologyDiff||o.hasActivePulses||o.hasActiveThresholds,G=o.consumeStylePaintPending(),V=e({dirtyOrRebuilt:O,transitioning:F,animationTicked:B,continuous:j||_,liveEncoding:H,forced:G}),Q=!!P&&o.lastIngestTime>0&&p-o.lastIngestTime>(P?.threshold??5e3);if(V){const e=re();if(!he(n,a,s,e))return;if(I.clearRect(-s.left,-s.top,a[0],a[1]),t(I,{background:u,hasBackgroundGraphics:h,width:c,height:l}),A&&o.applyDecay(),L&&o.applyPulse(p),E&&o.applyThresholds(p),!1!==w&&o.applyTopologyDiff(p),Q&&(I.globalAlpha=P?.dimOpacity??.5),m({context:I,nodes:o.sceneEdges,renderMode:d,pixelRatio:e,paintBuiltIn:e=>function(e,t){for(const r of t)switch(r.type){case"bezier":En(e,r);break;case"line":Pn(e,r);break;case"ribbon":Dn(e,r);break;case"curved":Mn(e,r)}}(I,e)}),m({context:I,nodes:o.sceneNodes,renderMode:d,pixelRatio:e,paintBuiltIn:e=>{const t=e;!function(e,t){for(const r of t){if("rect"!==r.type)continue;const t=r;t.w>0&&t.h>0&&(e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.fill&&(e.fillStyle=pe(e,t.style.fill,"#007bff"),void 0!==t.style.fillOpacity&&(e.globalAlpha=(t.style.opacity??1)*t.style.fillOpacity),e.fillRect(t.x,t.y,t.w,t.h)),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.globalAlpha=t.style.opacity??1,e.strokeRect(t.x,t.y,t.w,t.h)),x(e,t),e.restore())}}(I,t),function(e,t){for(const r of t){if("circle"!==r.type)continue;const t=r;t.r>0&&(e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.beginPath(),e.arc(t.cx,t.cy,t.r,0,2*Math.PI),t.style.fill&&(e.fillStyle=pe(e,t.style.fill,"#007bff"),void 0!==t.style.fillOpacity&&(e.globalAlpha=(t.style.opacity??1)*t.style.fillOpacity),e.fill()),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.globalAlpha=t.style.opacity??1,e.stroke()),v(e,t),e.restore())}}(I,t),function(e,t){for(const r of t){if("arc"!==r.type)continue;const t=r;e.save(),void 0!==t.style.opacity&&(e.globalAlpha=t.style.opacity),e.beginPath(),e.arc(t.cx,t.cy,t.outerR,t.startAngle,t.endAngle),e.arc(t.cx,t.cy,t.innerR,t.endAngle,t.startAngle,!0),e.closePath(),t.style.fill&&(e.fillStyle=pe(e,t.style.fill,"#007bff"),void 0!==t.style.fillOpacity&&(e.globalAlpha=(t.style.opacity??1)*t.style.fillOpacity),e.fill()),t.style.stroke&&"none"!==t.style.stroke&&(e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.globalAlpha=t.style.opacity??1,e.stroke()),e.restore()}}(I,t),function(e,t){const r=e.globalAlpha;for(const n of t){if("symbol"!==n.type)continue;const t=n;if(0>=t.size)continue;const o=Nn(t);if(!o)continue;e.save(),e.translate(t.cx,t.cy),t.rotation&&e.rotate(t.rotation);const i=t.style.opacity??1;t.style.fill&&(e.globalAlpha=r*i*(t.style.fillOpacity??1),e.fillStyle=pe(e,t.style.fill,"#007bff"),e.fill(o)),t.style.stroke&&"none"!==t.style.stroke&&(e.globalAlpha=r*i,e.strokeStyle=ge(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.stroke(o)),e.restore()}}(I,t),f(I,t)}}),j&&!Q){const e=o.edgesArray;if(e.length>0){!function(e,t,r,n,o=Math.random){const i=n.spawnRate??.1,a=n.maxPerEdge??50;for(let n=0;t.length>n;n++){const s=t[n];if(!s.bezier)continue;if(e.countForEdge(n)>=a)continue;const c=s.value*i*r*(s.bezier.circular?.3:1),l=Math.floor(c),u=c-l;let d=l;o()<u&&d++;for(let t=0;d>t&&e.countForEdge(n)<a;t++)e.spawn(n,o)}}(o.particlePool,e,$,D,k);const t=.5*(D.speedMultiplier??1);let r;if(D.proportionalSpeed){const t=e.reduce((e,t)=>Math.max(e,t.value||1),1);r=e.map(e=>.3+(e.value||1)/t*1.7)}o.particlePool.step($,t,e,r),function(e,t,r,n,o){const i=n.radius??3;e.globalAlpha=n.opacity??.7;for(let a=0;t.particles.length>a;a++){const s=t.particles[a];if(!s.active)continue;const c=r[s.edgeIndex];if(!c)continue;let l;l="string"==typeof n.color&&"inherit"!==n.color?n.color:o(c),e.fillStyle=ge(e,l)||l,e.beginPath(),e.arc(s.x,s.y,i,0,2*Math.PI),e.fill()}e.globalAlpha=1}(I,o.particlePool,e,D,M)}}Q&&(I.globalAlpha=1)}y.current=!1,(O||F||B)&&n.setAttribute("aria-label",q(o.sceneNodes?.length??0,o.sceneEdges?.length??0,"Network chart"));const K=O||F||B||R.current;K&&p-N.current>=33?(T(e=>e+1),N.current=p,R.current=!1):R.current=!!K,(_||F||null!=o.transition||B||o.hasActivePulses||o.hasActiveThresholds||!1!==w&&o.hasActiveTopologyDiff||R.current)&&C()}({canvas:r,store:n,sceneRevisionDiagnostics:Mr.current,size:tr,margin:rr,adjustedWidth:nr,adjustedHeight:or,background:et,renderMode:ke,hasBackgroundGraphics:!!St,dirtyRef:Zt,lastFrameTimeRef:Lr,now:fr.now(),random:fr.random,reducedMotion:!!Jt.current,showParticles:ve,isContinuous:an,animate:Lt,decay:_t,pulse:wt,thresholds:Ct,staleness:Et,particleStyle:br,getParticleColor:on,pendingAnnotationFrameRef:Pr,lastAnnotationFrameTimeRef:Er,setAnnotationFrame:$r,scheduleNextFrame:()=>{yr()},syncColorMap:()=>Zr(n)})};const{canvasRef:Kn}=we(Ut,{hydrated:pr,wasHydratingFromSSR:mr,storeRef:Dr,dirtyRef:Zt,skipInitialCanvasPaintInvalidation:!0,canvasPaintDependencies:[s,nr,or,et,St,ke,yr]});A(Et,Dr,Zt,yr,zr,Fr);const Zn=tt&&Nr?Yn(I,{x:Nr.x,y:Nr.y,containerWidth:nr,containerHeight:or,margin:rr,className:"stream-network-tooltip",zIndex:2,children:rt?rt(Nr):Yn(An,{data:Nr})}):null;if(ie||!pr&&mr)return Yn(gn,{props:n,store:Dr.current,responsiveRef:er,size:tr,margin:rr,adjustedWidth:nr,adjustedHeight:or,resolvedBackground:ar,resolvedForeground:ir});const Un=Dr.current;return Xn("div",{ref:er,className:"stream-network-frame"+(Je?" "+Je:""),role:"group","aria-label":It||("string"==typeof kt?kt:"Network chart"),tabIndex:0,"aria-busy":Br||void 0,style:{position:"relative",width:Ke?"100%":tr[0],height:Ze?"100%":tr[1],overflow:"visible"},onKeyDown:qn,children:["production"!==process.env.NODE_ENV&&Dr.current&&Yn(F,{store:Dr.current,diagnostics:Mr.current}),Wt&&Yn(O,{tableId:ur}),Wt&&Yn(z,{nodes:Un?.sceneNodes??[],edges:Un?.sceneEdges??[],chartType:"Network chart",tableId:ur,chartTitle:"string"==typeof kt?kt:void 0}),Yn(B,{summary:$t}),Yn(T,{hoverPoint:Nr}),Xn("div",{role:"img","aria-label":It||("string"==typeof kt?kt:"Network chart"),style:{position:"relative",width:"100%",height:"100%"},onMouseMove:tt?Qn:void 0,onMouseLeave:tt?Rn:void 0,onClick:ot||it?Wn:void 0,children:[Br&&!1!==Q&&Yn("div",{style:{position:"absolute",inset:0,zIndex:3,background:"var(--semiotic-bg, #fff)"},children:De(!0,tr[0],tr[1],Q)}),Yn(C,{size:tr,margin:rr,overflowVisible:!0,children:ar}),Yn("canvas",{ref:Kn,"aria-label":q(Un?.sceneNodes?.length??0,Un?.sceneEdges?.length??0,"Network chart"),style:{position:"absolute",top:0,left:0}}),Yn(cn,{width:nr,height:or,totalWidth:tr[0],totalHeight:tr[1],margin:rr,labels:Un?.labels||[],sceneNodes:Un?.sceneNodes,title:kt,legend:yt,legendPosition:ft,legendLayout:gt,legendHoverBehavior:pt,legendClickBehavior:mt,legendHighlightedCategory:vt,legendIsolatedCategories:xt,foregroundGraphics:i(ir,P(Dr.current?.customLayoutOverlays,Qt??null)),annotations:lt,onAnnotationActivate:ut,onObservation:at??it,chartId:st,chartType:"StreamNetworkFrame",autoPlaceAnnotations:dt,svgAnnotationRules:ht,annotationFrame:Ir}),Yn(hn,{marks:Un?.customLayoutHtmlMarks,margin:rr,selection:Qt??null}),Yn($,{active:In.current>=0,hoverPoint:Nr,margin:rr,size:tr,shape:$n.current?.shape,width:$n.current?.w,height:$n.current?.h}),Zn,Et?.showBadge&&Yn(r,{isStale:zr,position:Et.badgePosition})]})]})}));qn.displayName="StreamNetworkFrame";var Qn=qn;export{Ot as buildRibbonGeometry,pn as shouldUseForceWorker,mn as canUseForceWorker,bn as runForceLayoutWorker,Qn as StreamNetworkFrame_default};
@@ -0,0 +1 @@
1
+ import{mulberry32 as t}from"./chunk-chunk-SIRIJ3DY.module.min.js";import{UpdateResultTracker as e}from"./chunk-chunk-5RKXZQ2P.module.min.js";var i={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},s=1e-9,n=.005;function o(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function r(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function a(t,e,i){return Math.max(e,Math.min(i,t))}function d(t){return 0>t?-1:1}function h(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,i=t.shape.height/2;return{minX:t.x-e,minY:t.y-i,maxX:t.x+e,maxY:t.y+i}}function c(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,i=e.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}const i=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-i,minY:Math.min(e.y1,e.y2)-i,maxX:Math.max(e.x1,e.x2)+i,maxY:Math.max(e.y1,e.y2)+i}}function l(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function u(t,e,i,s,n,o,r,a){const h=n-t,c=(i+r)/2-Math.abs(h);if(0>=c)return null;const l=o-e,u=(s+a)/2-Math.abs(l);return u>0?u>c?{nx:d(h),ny:0,penetration:c}:{nx:0,ny:d(l),penetration:u}:null}function p(t,e,i,n,o,r,d){const h=r/2,c=d/2;let l=t-a(t,n-h,n+h),u=e-a(e,o-c,o+c);const p=l*l+u*u;if(p>i*i)return null;if(s>=p){const s=Math.abs(t-(n-h)),r=Math.abs(t-(n+h)),a=Math.abs(e-(o-c)),d=Math.abs(e-(o+c)),p=Math.min(s,r,a,d);return p===s?(l=-1,u=0,{nx:l,ny:u,penetration:i+s}):p===r?(l=1,u=0,{nx:l,ny:u,penetration:i+r}):p===a?(l=0,u=-1,{nx:l,ny:u,penetration:i+a}):(l=0,u=1,{nx:l,ny:u,penetration:i+d})}const m=Math.sqrt(p);return{nx:l/m,ny:u/m,penetration:i-m}}function m(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,i,n,o,r){const a=n-t,d=o-e,h=i+r,c=a*a+d*d;if(c>=h*h)return null;if(s>=c)return{nx:1,ny:0,penetration:h};const l=Math.sqrt(c);return{nx:a/l,ny:d/l,penetration:h-l}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return u(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const i=p(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return i?{nx:-i.nx,ny:-i.ny,penetration:i.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?p(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function y(t,e){const i=e.shape;return"aabb"===i.type?"circle"===t.shape.type?p(t.x,t.y,t.shape.radius,i.x,i.y,i.width,i.height):u(i.x,i.y,i.width,i.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,i,n,o,r,d,h=0){const c=r-n,l=d-o,u=c*c+l*l,p=u>s?a(((t-n)*c+(e-o)*l)/u,0,1):0,m=i+h/2,y=t-(n+c*p),f=e-(o+l*p),v=y*y+f*f;if(v>=m*m)return null;if(s>=v){const t=Math.sqrt(u);return t>s?{nx:-l/t,ny:c/t,penetration:m}:{nx:1,ny:0,penetration:m}}const b=Math.sqrt(v);return{nx:y/b,ny:f/b,penetration:m-b}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,i.x1,i.y1,i.x2,i.y2,i.thickness??0)}function f(t,e){return`${t}\0${e}`}function v(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function b(t){return{id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,bodyCollisions:t.bodyCollisions,shape:o(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function g(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function x(t){return{id:t.id,shape:r(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:g(t.bodyFilter),index:t.index}}function S(t,e){return!!e?.some(e=>Object.is(t,e))}function w(t,e){const i=t.bodyFilter;if(!i)return!0;if("function"==typeof i)return i(e);const s=function(t,e){if(!e)return;let i=t;for(const t of e.split(".")){if(null==i||"object"!=typeof i)return;i=i[t]}return i}(e,i.property);return!("equals"in i&&!Object.is(s,i.equals)||"notEquals"in i&&Object.is(s,i.notEquals)||i.oneOf&&!S(s,i.oneOf)||i.notOneOf&&S(s,i.notOneOf))}var I=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...i,...e},this.random=t(this.options.seed)}init(e={}){this.options={...i,...e},this.random=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(s,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:o(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))v(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:r(e.shape),bodyFilter:g(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,i){const s=this.bodies.get(t);s&&(s.vx+=e/s.mass,s.vy+=i/s.mass,this.wake(s))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const i=this.sortedBodies();for(const t of i)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const s=this.options.maxVelocity;for(const t of i)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,s>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>s){const i=s/e;t.vx*=i,t.vy*=i}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const n=this.bodyPairKeys(i),o=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(i,n,0===t),this.resolveColliders(i,o,0===t);this.updateSensors(i),this.updateSleeping(i,e)}settle(t=1200,e=this.options.fixedDt){let i=0;for(;t>i&&!this.allSleeping();)this.step(e),i+=1;return i}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:o(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(v)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(b),colliders:this.sortedColliders().map(x),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const t of e.bodies){const e=b(t);this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(const t of e.colliders){const e=x(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(const t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});const e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const i=this.bodies.get(e.bodyId);if(!i||i.sleeping)continue;const n="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!n)continue;const o=n.x-i.x,r=n.y-i.y,a=Math.sqrt(o*o+r*r);if(s>=a)continue;const d=o/a,h=r/a,c=(a-e.restLength)*e.stiffness+((("vx"in n?n.vx:0)-i.vx)*d+(("vy"in n?n.vy:0)-i.vy)*h)*e.damping;i.vx+=c*d*t/i.mass,i.vy+=c*h*t/i.mass}}resolveBodyPairs(t,e,i){for(const s of e){const[e,n]=s.split(":").map(Number),o=t[e],r=t[n];if(!o||!r)continue;const a=m(o,r);a&&(this.resolveDynamicCollision(o,r,a),i&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:r.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),i=new Map;for(let s=0;t.length>s;s+=1){if(!1===t[s].bodyCollisions)continue;const n=h(t[s]),o=Math.floor(n.minX/e),r=Math.floor(n.maxX/e),a=Math.floor(n.minY/e),d=Math.floor(n.maxY/e);for(let t=o;r>=t;t+=1)for(let e=a;d>=e;e+=1){const n=`${t}:${e}`,o=i.get(n);o?o.push(s):i.set(n,[s])}}const s=new Set;for(const e of Array.from(i.keys()).sort()){const n=i.get(e)??[];n.sort((t,e)=>t-e);for(let e=0;n.length>e;e+=1)for(let i=e+1;n.length>i;i+=1){const o=n[e],r=n[i];!1!==t[o].bodyCollisions&&!1!==t[r].bodyCollisions&&l(h(t[o]),h(t[r]))&&s.add(`${o}:${r}`)}}return Array.from(s).sort((t,e)=>{const[i,s]=t.split(":").map(Number),[n,o]=e.split(":").map(Number);return i===n?s-o:i-n})}resolveDynamicCollision(t,e,i){t.sleeping&&this.supportedThisStep.add(e.id),e.sleeping&&this.supportedThisStep.add(t.id);const o=t.sleeping?0:1/t.mass,r=e.sleeping?0:1/e.mass,a=o+r;if(s>=a)return;const d=Math.max(0,i.penetration-n)/a;t.x-=i.nx*d*o,t.y-=i.ny*d*o,e.x+=i.nx*d*r,e.y+=i.ny*d*r;const h=(e.vx-t.vx)*i.nx+(e.vy-t.vy)*i.ny;if(h>0)return;const c=Math.abs(h),l=-(1+Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution))*h/a,u=l*i.nx,p=l*i.ny;t.vx-=u*o,t.vy-=p*o,e.vx+=u*r,e.vy+=p*r,this.applyFriction(t,e,i,l,o,r),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,i,n,o,r){const d=-i.ny,h=i.nx,c=(e.vx-t.vx)*d+(e.vy-t.vy)*h,l=o+r;if(s>=Math.abs(c)||s>=l)return;const u=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction))),p=a(-c/l,-n*u,n*u),m=p*d,y=p*h;t.vx-=m*o,t.vy-=y*o,e.vx+=m*r,e.vy+=y*r}resolveColliders(t,e,i){for(const s of t)for(const t of e){if(!w(t,s))continue;if(!l(h(s),c(t)))continue;const e=y(s,t);e&&(this.resolveStaticCollision(s,t,e),this.supportedThisStep.add(s.id),i&&this.lastEvents.push({type:"contact",bodyId:s.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,i){t.x+=i.nx*Math.max(0,i.penetration-n),t.y+=i.ny*Math.max(0,i.penetration-n);const s=t.vx*i.nx+t.vy*i.ny;if(0>s){const n=Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution);t.vx-=(1+n)*s*i.nx,t.vy-=(1+n)*s*i.ny;const o=-i.ny,r=i.nx,a=t.vx*o+t.vy*r,d=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction)));t.vx-=a*o*d,t.vy-=a*r*d}}updateSensors(t){const e=new Set,i=this.sortedColliders().filter(t=>t.sensor);for(const s of t){const t=h(s);for(const n of i){if(!w(n,s))continue;if(!l(t,c(n)))continue;if(!y(s,n))continue;const i=f(n.id,s.id);e.add(i),this.activeSensors.has(i)||this.lastEvents.push({type:"sensor-enter",bodyId:s.id,sensorId:n.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:i,bodyId:s}=v(t);this.lastEvents.push({type:"sensor-exit",bodyId:s,sensorId:i})}this.activeSensors=e}updateSleeping(t,e){const i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const s of t)Math.sqrt(s.vx*s.vx+s.vy*s.vy)>=this.options.sleepSpeed||Math.sqrt((s.x-s.prevX)*(s.x-s.prevX)+(s.y-s.prevY)*(s.y-s.prevY))>=this.options.sleepSpeed*e||i&&!this.supportedThisStep.has(s.id)?s.sleeping?this.wake(s):s.sleepTime=0:(s.sleepTime+=e,s.sleeping||this.options.sleepAfter>s.sleepTime||(s.sleeping=!0,s.vx=0,s.vy=0,this.lastEvents.push({type:"sleep",bodyId:s.id})))}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},M=class{constructor(t={}){this.id="builtin",this.capabilities={...(new I).capabilities,engine:"builtin"},this.world=new I(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function B(t={}){return new M(t)}function k(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):B(e)}var O=["binId","targetBin","category","windowIndex","lane","group"];function q(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const i=e-t.mean;t.mean+=i/t.count,t.m2+=i*(e-t.mean)}function C(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function T(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function R(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function D(t,e,i){return"function"==typeof t?t(e,i):"string"==typeof t?R(e,t):void 0}function A(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function Y(t){const e=C(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:C(t.x),y:C(t.y),value:e}}var F=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const i=A(D(this.config.binAccessor,t,e))??function(t){for(const e of O){const i=A(R(t,e));if(i)return i}return"sediment"}(t),s=A(D(this.config.labelAccessor,t,e))??i,n=function(t,e,i){if("number"==typeof t)return t;const s="function"==typeof t?t(e,i):"string"==typeof t?R(e,t):1,n="number"==typeof s?s:Number(s);return Number.isFinite(n)?n:1}(this.config.valueAccessor,t,e),o=Math.max(0,Math.floor(this.config.retainBodyIds??12));let r=this.bins.get(i);return r||(r={id:i,label:s,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(i,r)),r.label=s,r.lastBodyId=t.id,r.lastDatum=t.datum,q(r.x,t.x),q(r.y,t.y),q(r.value,n),o>0&&(r.bodyIds.push(t.id),r.bodyIds.length>o&&(r.bodyIds=r.bodyIds.slice(r.bodyIds.length-o))),Y(r)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Y)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:T(e.x),y:T(e.y),value:T(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function E(t,e={}){const{baselineY:i=0,binWidth:s=24,gap:n=2,maxHeight:o=80,value:r="count",x:a}=e,d=Math.max(1,...t.map(t=>t[r]));return t.map((t,e)=>{const h=Math.max(0,t[r]/d*o),c=a?.(t,e)??e*(s+n);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:c,y:i-h,width:s,height:h,meanX:t.x.mean,meanY:t.y.mean}})}function P(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}function L(t){const e=Math.max(0,Math.floor(t.liveBodies)),i=Math.max(0,Math.floor(t.queuedBodies??0)),s=e+i,n=P(t.bodyLimit),o=P(t.engineMaxBodiesHint),r=function(t,e,i){if(!1===i)return;const s=P(i?.warnAt);return null!=s?s:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(n,o,t.options),a=null==n?0:Math.max(0,e-n),d=a>0?"overflow":null==r||r>s?"ok":"warning";return{action:"overflow"!==d?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:o,liveBodies:e,overflow:a,projectedBodies:s,queuedBodies:i,state:d,warnAt:r}}var X={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},N={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function j(t={},e=N){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function K(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function $(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function W(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function H(t,e={}){const i=$(e.startAt)??0,s=e.pacing??"immediate";if("arrival"===s){const s=t.map((t,i)=>function(t,e,i){return"function"==typeof i?$(i(t,e)):"string"==typeof i?$(W(t,i)):$(t.spawnAt)??$(W(t,"arrivalTime"))??$(W(t,"timestamp"))??$(W(t,"time"))??$(W(t,"eventTime"))}(t,i,e.timeAccessor)),n=s.filter(t=>null!=t),o=n.length>0?Math.min(...n):0,r=$(e.timeScale)??1,a=r>0?r:1;return t.map((t,e)=>{const n=s[e],r=null==n?0:Math.max(0,n-o);return{...K(t),spawnAt:i+r/a}})}if("object"==typeof s){const e=$(s.ratePerSec);if(e&&e>0)return t.map((t,s)=>({...K(t),spawnAt:i+s/e}))}return t.map(t=>({...K(t),spawnAt:i}))}function z(t){return{...K(t),sequence:t.sequence,spawnAt:t.spawnAt}}function V(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function U(t){return!1!==t&&{...t}}function G(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function J(t){return{...t,gravity:{...t.gravity}}}function Q(t,e,i,s){if("circle"===t.shape.type){const n=t.x-e,o=t.y-i,r=t.shape.radius+s,a=n*n+o*o;return a>r*r?null:a}const n=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),o=Math.max(Math.abs(i-t.y)-t.shape.height/2,0),r=n*n+o*o;return r>s*s?null:r}function Z(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function _(t,e={}){const{idPrefix:i="plot",includeFloor:s=!0,includeCeiling:n=!1,includeLeftWall:o=!0,includeRightWall:r=!0,wallThickness:a=20,floorThickness:d=a}=e,h=[],c=t.x+t.width/2,l=t.y+t.height/2;return s&&h.push({id:i+"-floor",shape:{type:"aabb",x:c,y:t.y+t.height+d/2,width:t.width+2*a,height:d}}),n&&h.push({id:i+"-ceiling",shape:{type:"aabb",x:c,y:t.y-d/2,width:t.width+2*a,height:d}}),o&&h.push({id:i+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:l,width:a,height:t.height+2*d}}),r&&h.push({id:i+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:l,width:a,height:t.height+2*d}}),h}function tt(t){const{idPrefix:e="bin",count:i,domainStart:s,domainStep:n,xScale:o,yTop:r,yBottom:a,wallThickness:d=4,includeBoundaryWalls:h=!0,includeInteriorWalls:c=!0,closedBefore:l,lidY:u=r,lidThickness:p=Math.max(2,d)}=t,m=[],y=r+(a-r)/2,f=Math.abs(a-r),v=h?i:i-1;if(c||h)for(let t=h?0:1;v>=t;t+=1){if(!c&&t>0&&i>t)continue;const r=o(s+t*n);m.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:r,y:y,width:d,height:f}})}if(null!=l)for(let t=0;i>t;t+=1){const i=s+t*n,r=i+n;if(r>=l)continue;const a=o(i),h=o(r);m.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,h)+d/2,y1:u,x2:Math.max(a,h)-d/2,y2:u,thickness:p}})}return m}import{quadtree as et}from"d3-quadtree";var it=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,i,s,n,o=0){const r=this.ensure(t,e);if(!r)return null;let a=null,d=1/0;const h=Math.max(0,o)+this.maxSearchRadius,c=s-h,l=s+h,u=n-h,p=n+h;return r.visit((t,e,r,h,m)=>{if(c>h||e>l||u>m||r>p)return!0;if(t.length)return!1;let y=t;for(;y;){const t=y.data;if(t){const e=Q(t,s,n,Math.max(0,o));null!=e&&(d>e||e===d&&i.indexOf(t.id)>i.indexOf(a?.id??""))&&(a=t,d=e)}y=y.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const i=t.readState();return 0===i.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=i.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=et().x(t=>t.x).y(t=>t.y).addAll(i),this.revision=e,this.tree)}},st=["data","scene-geometry","data-paint","accessibility","evidence"],nt=["scene-geometry","data-paint","accessibility","evidence"],ot=["overlay","accessibility","evidence"],rt=(t,e)=>({retainedData:t,invalidations:e}),at=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],dt=["scene-geometry","data-paint","accessibility","evidence"],ht=[],ct={engine:rt("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:rt("preserve",dt),colliders:rt("preserve",dt),sediment:rt("preserve",dt),bodyBudget:rt("preserve",at),bodyLimit:rt("preserve",at),eviction:rt("preserve",at),fixedDt:rt("preserve",ht),maxDeltaSeconds:rt("preserve",ht),maxSubsteps:rt("preserve",ht),settleStepLimit:rt("preserve",ht),timeScale:rt("preserve",ht),observation:rt("preserve",ht)},lt=rt("preserve",at);function ut(t){let e="preserve";const i=new Set;for(const s of t){const t=ct[s]??lt;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}var pt=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function mt(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&pt.every(i=>t[i]===e[i])}function yt(t,e,i,s){return t||!e?"paused":i||!s?"running":"settled"}var ft=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,i){if(i>0)return void(this.seconds=0);const s=t.readState(this.scratch),n=this.speed*this.speed;let o=!0;for(const t of s)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=n){o=!1;break}this.seconds=o?this.seconds+Math.max(0,e):0}},vt=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new it,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new e,this.simulationState="settled",this.visible=!0,this.quiescence=new ft;const{bodyBudget:i,colliders:s,engine:n,kernel:o,observation:r,sediment:a,...d}=t;this.config={...X,...d},this.configInput={...t},this.bodyBudget=i??{},this.engineInput=n,this.observation=j(r),this.sediment=new F(a??!1),this.world=k(n,{fixedDt:this.config.fixedDt,...o}),this.quiescence.setKernelOptions(o),s&&this.world.setColliders(V(s))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(i=>"kernel"===i?!mt(t.kernel,e.kernel):t[i]!==e[i])}(t,this.configInput),{colliders:i,bodyBudget:s,engine:n,kernel:o,observation:r,sediment:a,...d}=t;if(this.config={...this.config,...d},void 0!==s&&(this.bodyBudget=s,!1===s&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=k(n,t.options),this.world.restore(t),this.revision+=1}if(o&&!mt(o,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...o,gravity:{...t.options.gravity,...o.gravity}};this.world.restore({...t,options:e}),this.quiescence.setKernelOptions(e),this.revision+=1}r&&(this.observation=j(r,this.observation)),this.sediment.updateConfig(a),i&&(this.world.setColliders(V(i)),this.revision+=1),this.configInput={...this.configInput,...t};const h=ut(e);this.updateResults.record({kind:"config",keys:e},h.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(V(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},ut(["colliders"]).invalidations)}enqueue(t,e){const i=Array.isArray(t)?t:[t],s=e?H(i,{...e,startAt:e.startAt??this.elapsedSeconds}):i;for(const t of s)this.queue.push({...K(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(G),s.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:s.length},s.length?st:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(K(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},st)}materializeDueSpawns(){const t=this.revision,e=[],i=[];return this.spawnDue(e,i),0===e.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?st:[])),e}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},st)}tick(t){const e=this.revision,i=[],s=[],n=[],o=[],r=[];if(this.paused||!this.visible){const t=this.result(0,i,s,n,o,r,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(i,r);const d=this.observeBodyBudget(r),h=this.evictOverflow(r);s.push(...h.evicted),n.push(...h.sedimented),this.syncSimulationState(r),this.accumulator+=a;let c=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>c;){this.world.step(this.config.fixedDt);const t=this.world.events();o.push(...t),this.observeKernelEvents(t,r),this.observeSensorTransitions(r),this.accumulator-=this.config.fixedDt,c+=1}c===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,i.length),(c>0||i.length>0||s.length>0||n.length>0||o.length>0)&&(this.revision+=1);const l=this.result(c,i,s,n,o,r,void 0,d);return this.updateResults.record({kind:"tick",count:c},this.revision!==e?i.length||s.length||n.length?st:nt:[]),l}settle(t=this.config.settleStepLimit){const e=this.revision;this.spawnDue([],[]);const i=this.world.settle(t,this.config.fixedDt);return i>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:i},this.revision!==e?nt:[]),i}settleWithObservations(t=this.config.settleStepLimit){const e=this.revision,i=[],s=[],n=[],o=[],r=[];if(this.paused||!this.visible){const t=this.result(0,i,s,n,o,r,!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(i,r);const a=this.observeBodyBudget(r),d=this.evictOverflow(r);s.push(...d.evicted),n.push(...d.sedimented),this.syncSimulationState(r);let h=0;for(i.length>0&&this.quiescence.reset();t>h&&!this.atRest();){this.world.step(this.config.fixedDt);const t=this.world.events();o.push(...t),this.observeKernelEvents(t,r),this.observeSensorTransitions(r),h+=1,this.quiescence.refresh(this.world,this.config.fixedDt,0)}(h>0||i.length>0||s.length>0||n.length>0||o.length>0)&&(this.revision+=1);const c=this.result(h,i,s,n,o,r,void 0,a);return this.updateResults.record({kind:"settle",count:h},this.revision!==e?i.length||s.length||n.length?st:nt:[]),c}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return E(this.readSediment(),t)}hitTest(t,e,i=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,i)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:i,chartId:s,...n}=t,o={...n,timestamp:e??this.elapsedSeconds,chartType:i??this.observation.chartType,chartId:s??this.observation.chartId};return this.emitObservation(o),this.updateResults.record({kind:"update",count:1},["evidence"]),o}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?ot:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?ot:[])}remove(t){const e=new Set(t),i=new Set(this.liveBodyOrder),s=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const n=t.filter(t=>i.has(t)||s.has(t));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?st:[]),n}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},nt),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},nt)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},nt)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,i,s)=>t.applyImpulse(e,i,s),clear:()=>t.clear(),hitTest:(e,i,s)=>t.hitTest(e,i,s),pause:()=>t.setPaused(!0),push:(e,i)=>t.enqueue(e,i),pushMany:(e,i)=>t.enqueue(e,i),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:U(this.bodyBudget),config:{...this.config,kernel:J(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(z),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:U(t.bodyBudget??{}),kernel:J(t.world.options)},this.bodyBudget=U(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(z).sort(G),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??yt(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},st)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const i=this.queue.shift();if(!i)return;this.spawnOne(i,e),t.push(i.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const i=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:i?.datum??t.datum,x:i?.x??t.x,y:i?.y??t.y},e)}result(t,e,i,s,n,o,r,a=this.evaluateBodyBudget()){this.syncSimulationState(o);const d=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:r??(this.queue.length>0||!this.atRest()),sleeping:d,sedimented:s,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,i){if(0===e.length)return;const s=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=s.get(t.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,i){const s=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===s.size&&0===e.size)return s;const n=new Map(t.readState().map(t=>[t.id,t])),o=(t,e)=>{const{sensorId:s,bodyId:o}=Z(e),r=i.observation.sensors[s],a=n.get(o);i.emit({type:"enter"===t?r?.enterType??"physics-bin-enter":r?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:o,datum:a?.datum,x:a?.x,y:a?.y,sensorId:s,binId:r?.binId??s})};for(const t of Array.from(s).sort())e.has(t)||o("enter",t);for(const t of Array.from(e).sort())s.has(t)||o("exit",t);return s}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const i of t)e.has(Z(i).bodyId)&&t.delete(i)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return L({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const i=`${e.state}:${e.action}`;return i===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=i,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=yt(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const i=this.simulationState;this.simulationState=e,function(t,e,i){i.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||i.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:e,previousSimulationState:t})}(i,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:i,liveBodyOrder:s}=function(t,e,i,s,n,o){const r={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===i)return r;const a=Math.max(0,Math.floor(s));if(!Number.isFinite(a))return r;const d=n.length-a;if(0>=d)return r;const h=function(t,e,i){if("sleeping-first"!==e)return i.slice();const s=new Map(t.readState().map(t=>[t.id,t.sleeping])),n=[],o=[];for(const t of i)s.get(t)?n.push(t):o.push(t);return[...n,...o]}(t,i,n),c=h.slice(0,d);if(0===c.length)return r;const l=function(t,e,i,s){const n=new Map(t.readState().map(t=>[t.id,t])),o=[];for(const t of i){const i=n.get(t);if(!i)continue;const r=e.add(i);r&&(o.push(t),s.emit({type:"physics-sediment",timestamp:s.elapsedSeconds,chartType:s.observation.chartType,chartId:s.observation.chartId,bodyId:t,datum:i.datum,x:i.x,y:i.y,binId:r.id,count:r.count,total:r.total}))}return o}(t,e,c,o);t.remove(c);const u=new Set(c);return{evicted:c,sedimented:l,liveBodyOrder:n.filter(t=>!u.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=s,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:i}}};function bt(t,e){if("region-enter"!==e.type)return t;const i=e.region.id,s=t[i]??{id:i,label:e.region.label??i,count:0,bodyIds:[]};if(s.bodyIds.includes(e.bodyId))return t;const n=[...s.bodyIds,e.bodyId];return{...t,[i]:{...s,count:n.length,bodyIds:n}}}function gt(t,e){return(e??Object.keys(t)).map(e=>t[e]).filter(t=>null!=t).map(t=>({label:t.label??t.id,value:t.count}))}function xt(t,e){const i=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],s=e.filter(t=>!i.has(t)),n=e.length-s.length,o=t.completion?.mode??"allMembersAbsorbed",r=t.completion?.valueByBodyId,a=t=>{const e=r?.[t];return Number.isFinite(e)&&Number(e)>=0?Number(e):1},d=e.reduce((t,e)=>t+a(e),0),h=e.reduce((t,e)=>t+(i.has(e)?a(e):0),0),c=t.completion?.threshold,l="threshold"===o?Number.isFinite(c)&&Number(c)>=0?Number(c):d:void 0;return{id:t.id,label:t.label??t.id,mode:o,complete:e.length>0&&("anyAbsorbed"===o?n>0:"threshold"===o?h>=(l??d):0===s.length),absorbed:n,total:e.length,absorbedValue:h,totalValue:d,threshold:l,missing:s}})}function St(t,e,i){return Math.max(e,Math.min(i,t))}function wt(t,e,i={}){const s=i.random??Math.random,n=t.stages.find(t=>t.id===e)??t.stages[t.stages.length-1],o=St(i.along??.5,.05,.95),r=i.jitterX??0,a=i.padY??20,d=n.x0+(n.x1-n.x0)*o+(2*s()-1)*r,h=Math.min(1,n.width/2),c=St(d,n.x0+h,n.x1-h),l=t.boundaryY(c,"top")+a,u=t.boundaryY(c,"bottom")-a;return{x:c,y:u>l?l+s()*Math.max(1,u-l):t.midY}}function It(t){return"bowtie"===t.shape?[{id:"incoming",role:"incoming",points:[[t.left,t.topY],[t.centerLeft,t.pinchTop],[t.centerLeft,t.pinchBottom],[t.left,t.bottomY]]},{id:"center",role:"center",points:[[t.centerLeft,t.pinchTop],[t.centerRight,t.pinchTop],[t.centerRight,t.pinchBottom],[t.centerLeft,t.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[t.centerRight,t.pinchTop],[t.right,t.topY],[t.right,t.bottomY],[t.centerRight,t.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[t.left,t.topY],[t.right,"funnel"===t.shape?t.pinchTop:t.topY],[t.right,"funnel"===t.shape?t.pinchBottom:t.bottomY],[t.left,t.bottomY]]}]}function Mt(t,e,i){return Math.max(e,Math.min(i,t))}function Bt(t,e,i,s,n,o={}){return{id:t,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:e,y1:i,x2:s,y2:n,thickness:o.thickness??8}}}function kt(t){const e=t.shape??"lane",i=Math.max(1,Math.round(t.width)),s=Math.max(1,Math.round(t.height)),n=t.padX??46,o=t.padY??72,r=n,a=i-n,d=o,h=s-Math.max(24,Math.round(.45*o)),c=(d+h)/2,l=Math.max(1,h-d),u=Mt(t.pinchRatio??.18,.06,.5),p=Number(t.pinchHeightOffset??0),m=Number.isFinite(p)?p:0,y=Mt(l*u+m,.06*l,.5*l),f=y/2,v=c-f,b=c+f,g=t.idPrefix??"process",x=t.friction??.58,S=t.restitution??.18,w=t.wallThickness??8,I=t.stages;if(!I.length)throw Error("processStageLayout requires at least one stage");const M=Mt(t.centerStageIndex??Math.floor(I.length/2),0,I.length-1),B=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(I),k=a-r;let O=r;const q=I.map((t,e)=>{const i=O,s=e===I.length-1?a:O+(t.share??1)/B*k;return O=s,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:i,x1:s,x:(i+s)/2,width:s-i,y:c,height:l}}),C=q[M],T=C.x0,R=C.x1,D=(t,i)=>{if("lane"===e)return"top"===i?d:h;if("funnel"===e){const e=Mt((t-r)/Math.max(1,a-r),0,1);return"top"===i?d+(v-d)*e:h+(b-h)*e}if(T>=t){const e=Mt((t-r)/Math.max(1,T-r),0,1);return"top"===i?d+(v-d)*e:h+(b-h)*e}if(R>=t)return"top"===i?v:b;const s=Mt((t-R)/Math.max(1,a-R),0,1);return"top"===i?v+(d-v)*s:b+(h-b)*s},A=q.map(t=>{const e=Math.min(D(t.x0,"top"),D(t.x1,"top")),i=Math.max(D(t.x0,"bottom"),D(t.x1,"bottom"));return{...t,y:(e+i)/2,height:Math.max(1,i-e)}}),Y={thickness:w,friction:x,restitution:S},F=[];"lane"===e?F.push(Bt(g+"-top",r,d,a,d,Y),Bt(g+"-bottom",r,h,a,h,Y),Bt(g+"-left",r,d,r,h,{...Y,thickness:Math.max(6,w-2)}),Bt(g+"-right",a,d,a,h,{...Y,thickness:Math.max(6,w)})):"funnel"===e?F.push(Bt(g+"-top",r,d,a,v,Y),Bt(g+"-bottom",r,h,a,b,Y),Bt(g+"-left",r,d,r,h,{...Y,thickness:Math.max(6,w-2)}),Bt(g+"-right",a,v,a,b,{...Y,thickness:Math.max(6,w)})):F.push(Bt(g+"-left-top",r,d,T,v,Y),Bt(g+"-left-bottom",r,h,T,b,Y),Bt(g+"-center-top",T,v,R,v,Y),Bt(g+"-center-bottom",T,b,R,b,Y),Bt(g+"-right-top",R,v,a,d,Y),Bt(g+"-right-bottom",R,b,a,h,Y),Bt(g+"-left",r,d,r,h,{...Y,thickness:Math.max(6,w-2)}),Bt(g+"-right",a,d,a,h,{...Y,thickness:Math.max(6,w)}));const E=t.membraneDampingScale??.5,P=r,L=Math.max(1,("bowtie"===e?T:a)-P),X=(t.membranes??[]).map(t=>{const e=P+Mt(t.offset,0,1)*L,i=t.width??18+18*t.cost,s=l-16,n=c+.25*(t.wobble??0);return{...t,x:e,y:n,width:i,height:s}}),N=!1===t.includeMembraneRegions?[]:X.map(t=>Ct({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??E,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:i,height:s,padX:n,padY:o,left:r,right:a,topY:d,bottomY:h,midY:c,centerLeft:T,centerRight:R,pinchHeight:y,pinchTop:v,pinchBottom:b,stages:A,membranes:X,colliders:F,regionEffects:N,boundaryY:D}}function Ot(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,i=t.y,s=t.width,n=t.height,{type:"aabb",x:e,y:i,width:s,height:n}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,i,s,n}function qt(t,e={}){const i=e.idPrefix??"stage",s=Math.max(0,e.insetX??0),n=Math.max(0,e.insetY??1);return t.stages.map(t=>{const o="function"==typeof e.metadata?e.metadata(t):e.metadata??{};return{...Ot({id:i?`${i}:${t.id}`:t.id,label:t.label??t.id,description:t.description,kind:"region",x:t.x,y:t.y,width:Math.max(1,t.width-2*s),height:Math.max(1,t.height-2*n),bodyFilter:e.bodyFilter,semanticItem:e.semanticItem,attributes:{primitive:"processStage",stageId:t.id,stageIndex:t.index},metadata:{...o,primitive:"processStage",stageId:t.id,stageIndex:t.index}})}})}function Ct(t){const e=t.dampingScale??.5,i=t.energyScale??1,s=Mt(t.cost,0,2);return{...Ot({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:s,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:s*e,energyDelta:-s*i}}function Tt(t){return{...Ot({...t,kind:t.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),charge:t.charge??!0,energyDelta:t.energyDelta,impulseOnEnter:t.impulseOnEnter}}function Rt(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...Ot({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function Dt(t){const e=t.pressure??t.occupancy??0,i=t.baseDamping??.08,s=t.dampingPerUnit??.12,n=t.energyPerUnit??0;return{...Ot({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:i+e*s,energyDelta:n?-e*n:void 0,force:t.force}}function At(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...Ot({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}function Yt(t){return{...Ot({...t,kind:t.kind??"force-field",attributes:{primitive:"portal",targetStage:t.targetStage,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,impulseOnEnter:t.impulseOnEnter,damping:t.damping??.08}}function Ft(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...Ot({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}function Et(t){return{...Ot({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}function Pt(t){const e=t.x??t.anchor?.x??0,i=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:i,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:i},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}function Lt(t){const e=t.idPrefix??"lane",i={thickness:t.thickness??8,friction:t.friction??.5,restitution:t.restitution??.16},s=[Bt(e+"-top",t.left,t.top,t.right,t.top,i),Bt(e+"-bottom",t.left,t.bottom,t.right,t.bottom,i)];return t.openEnds||s.push(Bt(e+"-left",t.left,t.top,t.left,t.bottom,i),Bt(e+"-right",t.right,t.top,t.right,t.bottom,i)),s}export{M as BuiltInPhysicsEngineAdapter,B as createDefaultPhysicsEngineAdapter,F as PhysicsSedimentAccumulator,E as sedimentHeightfield,L as evaluatePhysicsBodyBudget,H as schedulePhysicsSpawns,_ as collidersFromPlotBounds,tt as collidersFromXScaleBins,vt as PhysicsPipelineStore,bt as aggregateRegionCounts,gt as regionCountsToProjectionRows,xt as groupCompletionRows,wt as stageTargetInVolume,It as processVolumePolygons,kt as processStageLayout,qt as processStageRegions,Ct as membraneRegion,Tt as chargeGateRegion,Rt as routeSurfaceRegion,Dt as pressureFieldRegion,At as capacitatedRegion,Yt as portalRegion,Ft as absorbRegion,Et as forceFieldRegion,Pt as bodyGroupSpec,Lt as processLaneWalls};