semiotic 3.8.1 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CLAUDE.md +3 -1
  2. package/README.md +53 -52
  3. package/ai/behaviorContracts.cjs +9 -0
  4. package/ai/dist/mcp-server.js +142 -13
  5. package/ai/schema.json +616 -42
  6. package/ai/surface-manifest.json +1 -1
  7. package/ai/system-prompt.md +5 -2
  8. package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +2 -0
  9. package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +1 -0
  10. package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +2 -0
  11. package/dist/chunk-chunk-255KDHW5.module.min.js +1 -0
  12. package/dist/chunk-chunk-27HVVXS6.module.min.js +1 -0
  13. package/dist/chunk-chunk-2CXCXRB4.module.min.js +1 -0
  14. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +2 -0
  15. package/dist/chunk-chunk-2UN3ANRN.module.min.js +2 -0
  16. package/dist/chunk-chunk-2VUEY5TH.module.min.js +1 -0
  17. package/dist/chunk-chunk-2WVCH4PL.module.min.js +1 -0
  18. package/dist/chunk-chunk-5UKL5W76.module.min.js +2 -0
  19. package/dist/chunk-chunk-5WEFWNUW.module.min.js +2 -0
  20. package/dist/chunk-chunk-6F6GEAQU.module.min.js +1 -0
  21. package/dist/chunk-chunk-7LHMKRKE.module.min.js +2 -0
  22. package/dist/chunk-chunk-BHYTYMY2.module.min.js +2 -0
  23. package/dist/chunk-chunk-C6EJ4IOD.module.min.js +2 -0
  24. package/dist/chunk-chunk-CA3YDW6F.module.min.js +1 -0
  25. package/dist/chunk-chunk-CP3EN6KZ.module.min.js +1 -0
  26. package/dist/chunk-chunk-CYIML3AV.module.min.js +2 -0
  27. package/dist/chunk-chunk-DNY43POY.module.min.js +1 -0
  28. package/dist/chunk-chunk-DSNGDNJY.module.min.js +1 -0
  29. package/dist/chunk-chunk-E7MIQX7D.module.min.js +2 -0
  30. package/dist/chunk-chunk-EMO5NUGE.module.min.js +1 -0
  31. package/dist/chunk-chunk-ES4DCG3L.module.min.js +1 -0
  32. package/dist/chunk-chunk-FAKO3RGQ.module.min.js +2 -0
  33. package/dist/chunk-chunk-FYY2ACNJ.module.min.js +2 -0
  34. package/dist/chunk-chunk-G7WFWHAD.module.min.js +2 -0
  35. package/dist/chunk-chunk-GMQ5AYTD.module.min.js +1 -0
  36. package/dist/chunk-chunk-H4PPRW6N.module.min.js +1 -0
  37. package/dist/chunk-chunk-IFYPMWKY.module.min.js +1 -0
  38. package/dist/chunk-chunk-J3ELI22J.module.min.js +1 -0
  39. package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
  40. package/dist/chunk-chunk-J3XWETBJ.module.min.js +2 -0
  41. package/dist/chunk-chunk-JCG72SGW.module.min.js +2 -0
  42. package/dist/{semiotic-ai-chunk-OG7BQUUW.module.min.js → chunk-chunk-JJ2OOIET.module.min.js} +0 -1
  43. package/dist/chunk-chunk-KTWEBFMX.module.min.js +2 -0
  44. package/dist/chunk-chunk-L6D3I3V7.module.min.js +2 -0
  45. package/dist/chunk-chunk-M337NY6L.module.min.js +1 -0
  46. package/dist/chunk-chunk-NO4MCQVD.module.min.js +1 -0
  47. package/dist/chunk-chunk-ODUZEEBH.module.min.js +2 -0
  48. package/dist/chunk-chunk-P6UBCMSQ.module.min.js +2 -0
  49. package/dist/chunk-chunk-Q2YADC2V.module.min.js +2 -0
  50. package/dist/chunk-chunk-QRIBHZYW.module.min.js +1 -0
  51. package/dist/chunk-chunk-QSQVBIJA.module.min.js +1 -0
  52. package/dist/chunk-chunk-RCF52Z42.module.min.js +2 -0
  53. package/dist/chunk-chunk-RH5TSQPH.module.min.js +1 -0
  54. package/dist/chunk-chunk-ROP4HI7H.module.min.js +2 -0
  55. package/dist/chunk-chunk-RZH7VZYS.module.min.js +2 -0
  56. package/dist/chunk-chunk-SIRIJ3DY.module.min.js +1 -0
  57. package/dist/chunk-chunk-STZFFTAN.module.min.js +2 -0
  58. package/dist/chunk-chunk-SV4XAZ3Q.module.min.js +1 -0
  59. package/dist/chunk-chunk-T27ZEV6A.module.min.js +1 -0
  60. package/dist/chunk-chunk-U3AGQ5EF.module.min.js +2 -0
  61. package/dist/chunk-chunk-U66USBWU.module.min.js +1 -0
  62. package/dist/chunk-chunk-VVCA3DB7.module.min.js +1 -0
  63. package/dist/chunk-chunk-W3DB2MN4.module.min.js +2 -0
  64. package/dist/chunk-chunk-WCX6U47H.module.min.js +2 -0
  65. package/dist/chunk-chunk-WDIN4LRC.module.min.js +1 -0
  66. package/dist/chunk-chunk-XEVJDUTH.module.min.js +1 -0
  67. package/dist/chunk-chunk-XOYX77KF.module.min.js +2 -0
  68. package/dist/chunk-chunk-YCQYG6J5.module.min.js +2 -0
  69. package/dist/chunk-chunk-YHNZCPOZ.module.min.js +2 -0
  70. package/dist/chunk-chunk-YWZB3KPI.module.min.js +2 -0
  71. package/dist/chunk-chunk-Z5KXAVQD.module.min.js +2 -0
  72. package/dist/chunk-chunk-ZCNBUZPL.module.min.js +2 -0
  73. package/dist/chunk-chunk-ZLKRTF5N.module.min.js +2 -0
  74. package/dist/chunk-chunk-ZTNVDWAK.module.min.js +2 -0
  75. package/dist/chunk-statisticalOverlays-6MVAK5RW.module.min.js +2 -0
  76. package/dist/components/charts/physics/PhysicalFlowChart.d.ts +7 -0
  77. package/dist/components/charts/shared/auditAccessibilityText.d.ts +13 -0
  78. package/dist/components/server/staticSVGChrome.d.ts +3 -2
  79. package/dist/components/stream/OrdinalBrushOverlay.d.ts +1 -2
  80. package/dist/components/stream/OrdinalBrushOverlayLazy.d.ts +9 -0
  81. package/dist/components/stream/XYBrushOverlayLazy.d.ts +17 -0
  82. package/dist/controls.min.js +1 -1
  83. package/dist/controls.module.min.js +1 -1
  84. package/dist/geo.min.js +1 -1
  85. package/dist/geo.module.min.js +1 -1
  86. package/dist/network.min.js +1 -1
  87. package/dist/network.module.min.js +1 -1
  88. package/dist/ordinal.min.js +1 -1
  89. package/dist/ordinal.module.min.js +1 -1
  90. package/dist/physics-matter.min.js +1 -1
  91. package/dist/physics-matter.module.min.js +1 -1
  92. package/dist/physics-rapier.min.js +1 -1
  93. package/dist/physics-rapier.module.min.js +1 -1
  94. package/dist/physics.min.js +1 -1
  95. package/dist/physics.module.min.js +1 -1
  96. package/dist/realtime.min.js +1 -1
  97. package/dist/realtime.module.min.js +1 -1
  98. package/dist/rough.min.js +1 -1
  99. package/dist/rough.module.min.js +1 -1
  100. package/dist/semiotic-ai-core.min.js +1 -1
  101. package/dist/semiotic-ai-core.module.min.js +1 -1
  102. package/dist/semiotic-ai.min.js +1 -1
  103. package/dist/semiotic-ai.module.min.js +1 -1
  104. package/dist/semiotic-data.min.js +1 -1
  105. package/dist/semiotic-data.module.min.js +1 -1
  106. package/dist/semiotic-experimental.min.js +1 -1
  107. package/dist/semiotic-experimental.module.min.js +1 -1
  108. package/dist/semiotic-realtime-core.min.js +1 -1
  109. package/dist/semiotic-realtime-core.module.min.js +1 -1
  110. package/dist/semiotic-realtime-react.min.js +1 -1
  111. package/dist/semiotic-realtime-react.module.min.js +1 -1
  112. package/dist/semiotic-recipes-core.min.js +1 -1
  113. package/dist/semiotic-recipes-core.module.min.js +1 -1
  114. package/dist/semiotic-recipes-react.min.js +1 -1
  115. package/dist/semiotic-recipes-react.module.min.js +1 -1
  116. package/dist/semiotic-recipes.min.js +1 -1
  117. package/dist/semiotic-recipes.module.min.js +1 -1
  118. package/dist/semiotic-server-edge.min.js +1 -1
  119. package/dist/semiotic-server-edge.module.min.js +1 -1
  120. package/dist/semiotic-server-node.min.js +1 -1
  121. package/dist/semiotic-server-node.module.min.js +1 -1
  122. package/dist/semiotic-themes-core.min.js +1 -1
  123. package/dist/semiotic-themes-core.module.min.js +1 -1
  124. package/dist/semiotic-themes-react.min.js +1 -1
  125. package/dist/semiotic-themes-react.module.min.js +1 -1
  126. package/dist/semiotic-themes.min.js +1 -1
  127. package/dist/semiotic-themes.module.min.js +1 -1
  128. package/dist/semiotic-utils-core.min.js +1 -1
  129. package/dist/semiotic-utils-core.module.min.js +1 -1
  130. package/dist/semiotic-utils-react.min.js +1 -1
  131. package/dist/semiotic-utils-react.module.min.js +1 -1
  132. package/dist/semiotic-utils.min.js +1 -1
  133. package/dist/semiotic-utils.module.min.js +1 -1
  134. package/dist/semiotic-value.min.js +1 -1
  135. package/dist/semiotic-value.module.min.js +1 -1
  136. package/dist/semiotic.min.js +1 -1
  137. package/dist/semiotic.module.min.js +1 -1
  138. package/dist/server.min.js +1 -1
  139. package/dist/server.module.min.js +1 -1
  140. package/dist/xy.min.js +1 -1
  141. package/dist/xy.module.min.js +1 -1
  142. package/package.json +4 -4
  143. package/dist/semiotic-ai-statisticalOverlays-CY4WKR4A.module.min.js +0 -2
  144. package/dist/semiotic-chunk-3FSVZ46U.module.min.js +0 -2
  145. package/dist/semiotic-statisticalOverlays-UOMSFKVJ.module.min.js +0 -2
  146. package/dist/xy-chunk-IWD6IB6V.module.min.js +0 -2
  147. package/dist/xy-statisticalOverlays-7RWG6LJT.module.min.js +0 -2
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{forwardRef as e,useCallback as t,useMemo as n,useRef as i}from"react";import*as o from"react";import{forwardRef as r,memo as s,useCallback as a,useEffect as c,useImperativeHandle as l,useId as d,useRef as u}from"react";import*as h from"react";import{useCallback as p,useEffect as f,useLayoutEffect as m,useMemo as y,useRef as g}from"react";import{createContext as b,useCallback as x,useContext as v,useMemo as w,useRef as k,useSyncExternalStore as M}from"react";import{jsx as S}from"react/jsx-runtime";function I(e){let t=null;const n=()=>(t||(t=b(null)),t),i=A(e);return[function({children:t,initialState:i}){const o=k(i),r=w(()=>A(e,o.current),[]),s=n();return S(s.Provider,{value:r,children:t})},(e,t)=>{const o=n(),r=v(o)??i,s=k(e);s.current=e;const a=k({hasValue:!1,value:void 0}),c=x(()=>{const e=s.current(r.getState()),n=a.current;return n.hasValue&&t&&t(n.value,e)?n.value:(a.current={hasValue:!0,value:e},e)},[r,t]),l=x(()=>s.current(r.getState()),[r]);return M(r.subscribe,c,l)}]}function A(e,t){const n=new Set;let i={...e(function(e){const t=e(i);if(function(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}(t)){i={...i,...t};for(const e of n)e()}}),...t??{}};return{getState:()=>i,subscribe:function(e){return n.add(e),()=>{n.delete(e)}}}}function C(e){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:R}}),e.accessibility.highContrast){const e="dark"===t.mode;t={...t,colors:{...t.colors,text:e?"#ffffff":"#000000",textSecondary:e?"#cccccc":"#333333",grid:e?"#666666":"#999999",border:e?"#888888":"#000000"}}}return t}var R=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],D={mode:"light",colors:{primary:"#00a2ce",secondary:"#6c757d",categorical:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],sequential:"blues",diverging:"RdBu",background:"transparent",surface:"#ffffff",text:"#333",textSecondary:"#666",grid:"#e0e0e0",border:"#ccc",selection:"#00a2ce",selectionOpacity:.15,success:"#2ca02c",danger:"#d62728",warning:"#f0ad4e",error:"#b4181b",info:"#00a2ce"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},P={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},$={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:R,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function B(e,t){if("light"===t)return D;if("dark"===t)return P;if("high-contrast"===t)return $;if("string"==typeof t)return void 0!==console&&console.warn(`[ThemeStore] Unknown theme preset "${t}". Keeping current theme.`),e;if(t.mode&&"auto"!==t.mode){const e="dark"===t.mode?P:D;return C({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}return C({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}var[j,T]=I(e=>({theme:D,setTheme(t){e(e=>({theme:B(e.theme,t)}))}}));import{useState as N,useEffect as W}from"react";import{useRef as E,useState as z,useEffect as O}from"react";var F=/^var\(\s*(--[^,)]+)(?:\s*,\s*([^)]+))?\s*\)$/,L=new WeakMap,q=0,Y=!1,H=null,G=null;function X(e,t){if(!t)return t;const n=F.exec(t);if(!n)return t;const i=e.canvas;if(!i)return n[2]?.trim()||t;!function(){if(Y)return;if("undefined"==typeof window||"undefined"==typeof document)return;Y=!0;const e=()=>{q++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"]}),"function"==typeof window.matchMedia)try{H=window.matchMedia("(prefers-color-scheme: dark)"),G=e,"function"==typeof H.addEventListener?H.addEventListener("change",G):"function"==typeof H.addListener&&H.addListener(G)}catch{}}();let o=L.get(i);o&&o.version===q||(o={version:q,map:new Map},L.set(i,o));const r=o.map.get(t);if(void 0!==r)return r;const s=getComputedStyle(i).getPropertyValue(n[1]).trim()||n[2]?.trim()||t;return o.map.set(t,s),s}var _=()=>"undefined"!=typeof performance?performance.now():Date.now();function V(e,t){const n=e();return Number.isFinite(n)?n:t}var U=class{constructor(e={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=e.clock??_,this.lastWallTime=V(this.clock,0),this.logicalTime=this.lastWallTime,this.pausedValue=!0===e.paused,this.visibleValue=!1!==e.visible,this.setRandomSource(e.random,e.seed)}get isActive(){return!this.pausedValue&&this.visibleValue}get paused(){return this.pausedValue}get seed(){return this.seedValue}get visible(){return this.visibleValue}configure(e){this.setClock(e.clock),this.setRandomSource(e.random,e.seed)}setPaused(e){this.pausedValue!==e&&(this.advance(),this.pausedValue=e,this.emit())}setVisible(e){this.visibleValue!==e&&(this.advance(),this.visibleValue=e,this.emit())}snapshot(){return{now:this.now(),paused:this.pausedValue,seed:this.seedValue,visible:this.visibleValue}}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}advance(){const e=V(this.clock,this.lastWallTime),t=Math.max(0,e-this.lastWallTime);return this.lastWallTime=e,this.isActive&&(this.logicalTime+=t),this.logicalTime}emit(){for(const e of this.subscribers)e()}setClock(e){const t=e??_;t!==this.clock&&(this.advance(),this.clock=t,this.lastWallTime=V(t,this.lastWallTime))}setRandomSource(e,t){const n=function(e){return"number"==typeof e&&Number.isFinite(e)?Math.trunc(e):void 0}(t);e===this.randomInput&&n===this.seedValue||(this.randomInput=e,this.seedValue=n,this.randomSource=e??(void 0===n?Math.random:function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(n)))}},K="undefined"==typeof window?f:m,Q={requestAnimationFrame:e=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(e),cancelAnimationFrame:e=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(e)};function Z(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function J(e){const t=function(){const[e,t]=N(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return W(()=>{if("undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-reduced-motion: reduce)");return t(e.matches),function(e,t){if("function"==typeof e.addEventListener)return e.addEventListener("change",t),()=>e.removeEventListener("change",t);const n=e;return n.addListener(t),()=>n.removeListener(t)}(e,e=>t(e.matches))},[]),e}(),n=g(t);n.current=t;const[i,o]=function(e,t,n){const i=E(null),[o,r]=z(null);return O(()=>{if(!t&&!n)return;const e=i.current;if(!e)return;const o=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;r(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return o.observe(e),()=>o.disconnect()},[t,n]),[i,[t&&o?o.w:e[0],n&&o?o.h:e[1]]]}(e.sizeProp,e.responsiveWidth,e.responsiveHeight),r=!!e.title,s=!!e.legend&&"top"===e.legendPosition,a=y(()=>function(e,t,n=!1){const i=n?t?58:34:t?36:0;return i>e.top?{...e,top:i}:e}({...e.marginDefault,...e.userMargin},r,s),[e.marginDefault,e.userMargin,r,s]),c=o[0]-a.left-a.right,l=o[1]-a.top-a.bottom,d=Z(e.foregroundGraphics,o,a),u=Z(e.backgroundGraphics,o,a),m=T(e=>e.theme),{transition:b,introEnabled:x}=function(e,t){if(!1===e)return{transition:void 0,introEnabled:!1};const n="undefined"!=typeof window&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return{transition:e?!0===e?{duration:300}:{duration:e.duration??300,easing:"linear"===e.easing?"linear":"ease-out"}:t,introEnabled:!(n||!e||!0!==e&&!1===e.intro)}}(e.animate,e.transitionProp),v="semiotic-table-"+h.useId(),w=g(null);if(!w.current){const t=!e.suspendWhenHidden||"undefined"==typeof document||!document.hidden;w.current=new U({clock:e.clock,random:e.random,seed:e.seed,paused:e.paused,visible:t})}const k=w.current;k.configure({clock:e.clock,random:e.random,seed:e.seed});const M=g(null),S=g(e.frameScheduler??Q);S.current=e.frameScheduler??Q;const I=g(null),A=g(!1),C=g(()=>{}),R=p(()=>{if(null!==M.current||A.current)return;const e=S.current;let t=!1,n=!1;const i=e.requestAnimationFrame(()=>{t=!0;const e=!n;e&&(A.current=!0),M.current=null,I.current=null;try{C.current()}finally{e&&(A.current=!1)}});n=!0,t||(M.current=i,I.current=e)},[]),D=p(()=>{null!==M.current&&((I.current??S.current).cancelAnimationFrame(M.current),M.current=null,I.current=null)},[]);K(()=>{k.setPaused(!0===e.paused)},[k,e.paused]),f(()=>{if(!e.suspendWhenHidden||"undefined"==typeof document)return void k.setVisible(!0);const t=()=>k.setVisible(!document.hidden);return t(),document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[k,e.suspendWhenHidden]),f(()=>()=>{D()},[D]);const P=g(()=>{}),$=g(()=>{}),B=g(null),j=g(null),F=g(null),L=p(()=>{const e=B.current;B.current=null,e&&P.current(e)},[]),Y=p(e=>{if(B.current={clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType},null===j.current){const e=S.current;let t=!1;const n=e.requestAnimationFrame(()=>{t=!0,j.current=null,F.current=null,L()});t||(j.current=n,F.current=e)}},[L]),H=p(()=>{B.current=null,null!==j.current&&((F.current??S.current).cancelAnimationFrame(j.current),j.current=null,F.current=null),$.current()},[]);f(()=>()=>{B.current=null,null!==j.current&&((F.current??S.current).cancelAnimationFrame(j.current),j.current=null,F.current=null)},[]);const G=e.themeDirtyRef;return K(()=>{G&&(q++,G.current=!0,R())},[m,R,G]),{reducedMotion:t,reducedMotionRef:n,responsiveRef:i,size:o,margin:a,adjustedWidth:c,adjustedHeight:l,resolvedForeground:d,resolvedBackground:u,currentTheme:m,transition:b,introEnabled:x,tableId:v,frameRuntime:k,rafRef:M,renderFnRef:C,scheduleRender:R,cancelRender:D,hoverHandlerRef:P,hoverLeaveRef:$,onPointerMove:Y,onPointerLeave:H}}import{useEffect as ee,useLayoutEffect as te,useRef as ne,useState as ie,useSyncExternalStore as oe}from"react";var re="undefined"!=typeof window?te:ee,se=()=>()=>{},ae=()=>!1,ce=()=>!0;import{useEffect as le,useRef as de}from"react";import{jsx as ue}from"react/jsx-runtime";function he({children:e,size:t,margin:n,overflowVisible:i=!1}){return e?ue("svg",{style:{position:"absolute",left:0,top:0,width:t[0],height:t[1],pointerEvents:"none",overflow:i?"visible":void 0},children:ue("g",{transform:`translate(${n.left},${n.top})`,children:e})}):null}import*as pe from"react";import{arc as fe}from"d3-shape";import{symbol as me,symbolCircle as ye,symbolCross as ge,symbolDiamond as be,symbolSquare as xe,symbolStar as ve,symbolTriangle as we,symbolWye as ke}from"d3-shape";var Me={circle:ye,square:xe,triangle:we,diamond:be,star:ve,cross:ge,wye:ke};var Se=null;import{jsx as Ie,jsxs as Ae}from"react/jsx-runtime";function Ce(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function Re(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}function De(e,t){let n=2166136261;const i=Re(t);for(let e=0;i.length>e;e++)n^=i.charCodeAt(e),n=Math.imul(n,16777619);return`${e}-hatch-${(n>>>0).toString(36)}`}var Pe=new Map;function $e(e,t){const{background:n="transparent",stroke:i="#000",lineWidth:o=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=e,c=Math.max(8,Math.ceil(2*r));return Ae("pattern",{id:t,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&Ie("rect",{width:c,height:c,fill:n}),Ie("line",{x1:0,y1:0,x2:0,y2:c,stroke:i,strokeWidth:o,strokeOpacity:a}),Ie("line",{x1:r,y1:0,x2:r,y2:c,stroke:i,strokeWidth:o,strokeOpacity:a})]},t)}function Be(e,t,n="#4e79a7"){if(Ce(e)){const n=De(t,e);return{fill:`url(#${n})`,def:$e(e,n)}}return e&&"string"==typeof e?{fill:e}:{fill:n}}var je=[40,40],Te=[.5,.5];function Ne(e,t,n,i){if("none"!==e)return"color"===e||null==e?t??i:"accent"===e?n:e}import{jsx as We,jsxs as Ee}from"react/jsx-runtime";function ze(e,t="#4e79a7"){return Ce(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function Oe(e,t,n){switch(e.type){case"line":{const n=e;if(0===n.path.length)return null;const i="M"+n.path.map(([e,t])=>`${e},${t}`).join("L");return We("path",{d:i,fill:"none",stroke:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity},"line-"+t)}case"area":{const i=e;if(0===i.topPath.length)return null;const o=`M${i.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...i.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`,r=`${n?n+"-":""}area-${t}-hatch`,s=Ce(i.style.fill)?$e(i.style.fill,r):void 0,a=s?`url(#${r})`:ze(i.style.fill);if(i.clipRect){const e=`${n?n+"-":""}area-clip-${t}`;return Ee("g",{children:[Ee("defs",{children:[s,We("clipPath",{id:e,children:We("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),We("path",{d:o,fill:a,fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,clipPath:`url(#${e})`})]},"area-"+t)}return Ee(pe.Fragment,{children:[s&&We("defs",{children:s}),We("path",{d:o,fill:a,fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"area-"+t)}case"point":{const i=e,o=`${n?n+"-":""}point-${t}-hatch`,r=Ce(i.style.fill)?$e(i.style.fill,o):void 0;return Ee(pe.Fragment,{children:[r&&We("defs",{children:r}),We("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#${o})`:ze(i.style.fill),opacity:i.style.opacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"point-"+t)}case"symbol":return function(e,t){const n=function(e,t,n){if(n)return n;const i=e??"circle";return"chevron"===i?function(e){const t=1.5*function(e){return Math.sqrt(Math.max(1,e)/Math.PI)}(e),n=.92*t;return`M0,${-t}L${n},${(.78*t).toFixed(3)}L0,${(.28*t).toFixed(3)}L${-n},${(.78*t).toFixed(3)}Z`}(t):me(Me[i]??ye,Math.max(1,t))()??""}(e.symbolType,e.size,e.path);return We("path",{d:n,transform:e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`,fill:e.style.fill?ze(e.style.fill):"none",opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},"symbol-"+t)}(e,t);case"glyph":return function(e,t,n,i){const o=e.glyph;if(!o?.parts?.length||0>=e.size)return null;const r=function(e,t){const[n,i]=e.viewBox??je,[o,r]=e.anchor??Te,s=i>0?i:1,a=Math.max(0,t)/s,c=(n>0?n:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-o*c,offsetY:-r*l}}(o,e.size);if(0>=r.scale)return null;const s=`translate(${t},${n})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),c=function(e,t,n=0,i="horizontal"){const[o,r]=e.viewBox??je,s=Math.min(1,Math.max(0,n)),a=Math.min(1,Math.max(0,t));return a>s?s>0||1>a?"vertical"===i?{x:0,y:r*(1-a),width:o,height:r*(a-s)}:{x:o*s,y:0,width:o*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(o,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),l=c?function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}(i+"-clip"):void 0,d=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),u=t=>o.parts.map((n,i)=>{const o=t?"none"===n.fill?void 0:t:Ne(n.fill,a,e.accent),r=t?n.stroke&&"none"!==n.stroke?t:void 0:Ne(n.stroke??"none",a,e.accent);return o||r?We("path",{d:n.d,fill:o??"none",stroke:r,strokeWidth:r?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},i):null});return Ee("g",{transform:s,opacity:1===d?void 0:d,children:[c&&l&&We("clipPath",{id:l,children:We("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&e.ghostColor?We("g",{children:u(e.ghostColor)}):null,c&&l?We("g",{clipPath:`url(#${l})`,children:u()}):u()]},i)}(e,e.x,e.y,`${n??""}glyph-${e.pointId??t}`);case"rect":{const i=e,o=`${n?n+"-":""}xyrect-${t}-hatch`,r=Ce(i.style.fill)?$e(i.style.fill,o):void 0;return Ee(pe.Fragment,{children:[r&&We("defs",{children:r}),We("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:r?`url(#${o})`:ze(i.style.fill),opacity:i.style.opacity,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"rect-"+t)}case"heatcell":{const n=e;if(n.showValues&&null!=n.value&&n.w>=20&&n.h>=20){const e=n.valueFormat?n.valueFormat(n.value):Number.isInteger(n.value)?n.value+"":100>Math.abs(n.value)?1>Math.abs(n.value)?n.value.toPrecision(3):n.value.toFixed(1):n.value.toFixed(0),[i,o,r]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(n.fill),s=.299*i+.587*o+.114*r>128?"#000":"#fff",a=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return Ee("g",{children:[We("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill}),We("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:a+"px",children:e})]},"heatcell-"+t)}return We("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill},"heatcell-"+t)}case"candlestick":{const n=e,i=Math.min(n.openY,n.closeY),o=Math.max(Math.abs(n.openY-n.closeY),1),r=n.isUp?n.upColor:n.downColor;return Ee("g",{children:[We("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),We("rect",{x:n.x-n.bodyWidth/2,y:i,width:n.bodyWidth,height:o,fill:r,stroke:r,strokeWidth:1})]},"candle-"+t)}default:return null}}var Fe="undefined"==typeof window||"undefined"==typeof document;import*as Le from"react";import{jsx as qe,jsxs as Ye}from"react/jsx-runtime";var He={background:"var(--semiotic-tooltip-bg, rgba(0, 0, 0, 0.85))",color:"var(--semiotic-tooltip-text, white)",padding:"8px 12px",borderRadius:"var(--semiotic-tooltip-radius, 6px)",fontSize:"var(--semiotic-tooltip-font-size, 14px)",fontFamily:"var(--semiotic-font-family, inherit)",lineHeight:"1.5",boxShadow:"var(--semiotic-tooltip-shadow, 0 2px 8px rgba(0, 0, 0, 0.15))",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Ge(e,t){return"function"==typeof t?t(e):e[t]}function Xe(e,t){if(t)return t(e);if(null==e)return"";if("number"==typeof e){if(!Number.isFinite(e))return e+"";const t=Number.isInteger(e)?e:parseFloat(e.toPrecision(6));return Math.abs(t)>9999?t.toLocaleString():t+""}return e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function _e(e={}){const{fields:t,title:n,format:i,style:o={},className:r=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let s;const a=[];if(n){const t=Ge(e,n);s=Xe(t,i)}if(t&&t.length>0)t.forEach(t=>{let n,o,r;"string"==typeof t?(n=t,o=t,r=i):(n=t.label,o=t.accessor||t.key||"",r=t.format||i);const s=Ge(e,o);a.push({label:n,value:Xe(s,r)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){s=Xe(e[n],i);break}if(!s){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(s=Xe(e[t[0]],i))}}const c={...He,...o};return Ye("div",{className:("semiotic-tooltip "+r).trim(),style:c,children:[s&&qe("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((e,t)=>Ye("div",{style:{marginTop:0===t&&s?"4px":0},children:[e.label&&Ye("span",{children:[e.label,": "]}),e.value]},t))]})}}function Ve(e){if(!0!==e){if("function"==typeof e){const t=e;return e=>{let n=Array.isArray(i=!0===e?.__semioticHoverData||e&&void 0!==e.data&&"number"==typeof e.x&&"number"==typeof e.y&&e&&("node"===e.type||"edge"===e.type||void 0!==e.nodeOrEdge||void 0!==e.allSeries||void 0!==e.stats||void 0!==e.__chartType)?e.data??{}:e)?i[0]:i;var i;if(!n)return null;if(("node"===e?.nodeOrEdge&&"number"==typeof n?.x0&&"number"==typeof n?.x1||"edge"===e?.nodeOrEdge&&"number"==typeof n?.sankeyWidth)&&n.data&&"object"==typeof n.data&&(n=n.data),!n)return null;const o=t(n);return null==o?null:qe("div",{className:"semiotic-tooltip",style:He,children:o})}}return!1!==e&&void 0!==e&&("object"==typeof e&&null!==e&&("fields"in e||"title"in e)?_e(e):_e())}}import{jsx as Ue}from"react/jsx-runtime";function Ke({x:e,y:t,containerWidth:n,containerHeight:i,margin:o,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const c=Number.isFinite(e)&&Number.isFinite(t),l=Le.useRef(null),[d,u]=Le.useState(null);Le.useLayoutEffect(()=>{const e=l.current;if(!e)return;const t=()=>{const t=e.getBoundingClientRect();Number.isFinite(t.width)&&Number.isFinite(t.height)&&u(e=>e&&.5>Math.abs(e.width-t.width)&&.5>Math.abs(e.height-t.height)?e:{width:t.width,height:t.height})};if(t(),"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[s,n,i,c]);let h;h=d?`translate(${d.width+12>n-e?"calc(-100% - 12px)":"12px"}, ${d.height+12>i-t?"calc(-100% - 4px)":"4px"})`:`translate(${e>.7*n?"calc(-100% - 12px)":"12px"}, ${.3*i>t?"4px":"calc(-100% - 4px)"})`;const p=function(e){if(!Le.isValidElement(e))return!1;const t=e.type;if("string"!=typeof t&&t&&!0===t.ownsChrome)return!0;const n=e.props;if(!0===n["data-semiotic-tooltip-chrome"])return!0;if("true"===n["data-semiotic-tooltip-chrome"])return!0;const i=n.style;if(i&&"object"==typeof i){if(null!=i.background&&""!==i.background&&"transparent"!==i.background)return!0;if(null!=i.backgroundColor&&""!==i.backgroundColor&&"transparent"!==i.backgroundColor)return!0}return!1}(r),f=p?null:He;return c?Ue("div",{ref:l,className:p?s:(s+" semiotic-tooltip").trim(),style:{...f||{},position:"absolute",left:o.left+e,top:o.top+t,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}var Qe={names:["--semiotic-bg","--surface-1","--surface-0"],fallback:"#f8fafc"},Ze={names:["--semiotic-border","--surface-3"],fallback:"#334155"},Je={names:["--semiotic-danger","--viz-4"],fallback:"#dc2626"},et={names:["--semiotic-focus","--accent","--viz-9"],fallback:"#f97316"},tt={names:["--semiotic-grid","--surface-3"],fallback:"#cbd5e1"},nt={names:["--semiotic-primary","--accent","--viz-5"],fallback:"#0ea5e9"},it={names:["--semiotic-success","--viz-2"],fallback:"#22c55e"},ot={names:["--semiotic-text","--text-primary"],fallback:"#0f172a"},rt={names:["--semiotic-text-secondary","--text-secondary"],fallback:"#475569"},st={names:["--semiotic-warning","--viz-9","--viz-3"],fallback:"#f97316"};function at(e,t){const n=e.canvas;if("function"!=typeof getComputedStyle||!n)return t.fallback;const i=getComputedStyle(n);for(const n of t.names){const t=i.getPropertyValue(n).trim();if(t)return X(e,t)??t}return t.fallback}function ct(e,t){const n=Math.max(0,Math.min(1,t)),i=e.trim(),o=i.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);if(o){const[,e,t,i]=o;return ct(`#${e}${e}${t}${t}${i}${i}`,n)}const r=i.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(r){const[,e,t,i]=r;return`rgba(${parseInt(e,16)}, ${parseInt(t,16)}, ${parseInt(i,16)}, ${n})`}const s=i.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);if(s)return`rgba(${s[1]}, ${n})`;const a=i.match(/^rgba\s*\(\s*([^,]+,\s*[^,]+,\s*[^,]+),\s*[^)]+\)$/i);return a?`rgba(${a[1]}, ${n})`:i}import*as lt from"react";import{scaleLinear as dt}from"d3-scale";import*as ut from"react";import{jsx as ht,jsxs as pt}from"react/jsx-runtime";var ft={fill:(e,t)=>ht("rect",{style:e,width:t,height:t}),line:(e,t)=>ht("line",{style:e,x1:0,y1:0,x2:t,y2:t})};function mt(e,t,n,i,o){let r;return r="function"==typeof n?n(e):(0,ft[n])(i(e,t),o),r}function yt({swatchSize:e}){return ht("path",{d:`M${.25*e},${.55*e} L${.45*e},${.75*e} L${.8*e},${.3*e}`,fill:"none",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}function gt(e,t,n){return n&&n.size>0?n.has(e.label)?1:.3:null!=t?e.label===t?1:.3:1}var bt=(e,t,n,i,o,r,s,a,c,l,d)=>{const{type:u="fill",styleFn:h,items:p}=e,f=[];let m=0;const y=!(!t&&!n),g="isolate"===l||void 0===l&&null!=o,{swatchSize:b,labelGap:x,rowHeight:v}=d;return p.forEach((e,l)=>{const d=mt(e,l,u,h,b),w=gt(e,i,o),k=o&&o.size>0&&o.has(e.label);f.push(pt("g",{transform:`translate(0,${m})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===r&&l===s?0:-1:void 0,role:y?"option":void 0,"aria-selected":y&&g?k||!1:void 0,"aria-current":y&&!g&&null!=i&&e.label===i||void 0,"aria-label":e.label,onKeyDown:y?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowDown"===n.key||"ArrowUp"===n.key){n.preventDefault();const e=(l+("ArrowDown"===n.key?1:-1)+p.length)%p.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:y?t=>{c(a,l),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.setAttribute("visibility","visible")}:void 0,onBlur:y?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:y?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[y&&ht("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:b+x+2+7*e.label.length,height:b+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),d,k&&ht(yt,{swatchSize:b}),ht("text",{y:b/2,x:b+x,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+l)),m+=v}),f};function xt({config:e,orientation:t="vertical",width:n=100}){const{colorFn:i,domain:o,label:r,format:s}=e,a=s||(e=>Math.round(100*e)/100+""),c="grad-legend-"+ut.useId();if("horizontal"===t){const e=12,t=Math.min(n,200),s=Math.max(0,(n-t)/2),l=[];for(let e=0;64>=e;e++){const t=e/64;l.push(ht("stop",{offset:100*t+"%",stopColor:i(o[0]+t*(o[1]-o[0]))},e))}return pt("g",{"aria-label":r||"Gradient legend",children:[ht("defs",{children:ht("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),r&&ht("text",{x:s+t/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),ht("rect",{x:s,y:0,width:t,height:e,fill:`url(#${c})`,rx:2}),ht("text",{x:s,y:e+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])}),ht("text",{x:s+t,y:e+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])})]})}const l=[];for(let e=0;64>=e;e++){const t=e/64;l.push(ht("stop",{offset:100*t+"%",stopColor:i(o[1]-t*(o[1]-o[0]))},e))}return pt("g",{"aria-label":r||"Gradient legend",children:[r&&ht("text",{x:7,y:-6,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),ht("defs",{children:ht("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),ht("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),ht("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])}),ht("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])})]})}function vt(e){const{legendGroups:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:c=100,height:l=20,orientation:d="vertical",legendLayout:u}=e,h=function(e){const t=Math.max(1,e?.swatchSize??16),n=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:n,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}(u),[p,f]=ut.useState(0),[m,y]=ut.useState(0),g=ut.useCallback((e,t)=>{f(e),y(t)},[]),b="vertical"===d?(({legendGroups:e,width:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:c,legendInteraction:l,metrics:d})=>{let u=24;const h=[];return e.forEach((e,p)=>{u+=5,h.push(ht("line",{stroke:"gray",x1:0,y1:u,x2:t,y2:u},"legend-top-line legend-symbol-"+p)),u+=8,e.label&&(u+=16,h.push(ht("text",{y:u,className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label},"legend-text-"+p)),u+=8),h.push(ht("g",{className:"legend-item",transform:`translate(0,${u})`,children:bt(e,n,i,o,r,s,a,p,c,l,d)},"legend-group-"+p)),u+=e.items.length*d.rowHeight+8}),h})({legendGroups:t||[],width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}):(({legendGroups:e,height:t,width:n,customClickBehavior:i,customHoverBehavior:o,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:c,onFocusedIndexChange:l,legendInteraction:d,metrics:u})=>{let h=0;const p=[];e.forEach((e,t)=>{let f=0;e.label&&(f+=16);const m=((e,t,n,i,o,r,s,a,c,l,d,u)=>{const{type:h="fill",styleFn:p,items:f}=e,m=[],{swatchSize:y,labelGap:g,itemGap:b,rowHeight:x,align:v}=d,w=!(!t&&!n),k="isolate"===l||void 0===l&&null!=o,M=f.map(e=>y+g+7*e.label.length),S=[];let I=0,A=0;M.forEach((e,t)=>{const n=0===A?e:A+b+e;u&&u>0&&A>0&&n>u?(S.push({start:I,end:t,width:A}),I=t,A=e):A=n}),f.length>0&&S.push({start:I,end:f.length,width:A}),S.forEach((e,l)=>{let d="center"===v?Math.max(0,((u??e.width)-e.width)/2):"end"===v?Math.max(0,(u??e.width)-e.width):0;for(let u=e.start;e.end>u;u++){const e=f[u],v=mt(e,u,h,p,y),S=gt(e,i,o),I=o&&o.size>0&&o.has(e.label);m.push(pt("g",{transform:`translate(${d},${l*x})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===r&&u===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?I||!1:void 0,"aria-current":w&&!k&&null!=i&&e.label===i||void 0,"aria-label":e.label,onKeyDown:w?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowRight"===n.key||"ArrowLeft"===n.key){n.preventDefault();const e=(u+("ArrowRight"===n.key?1:-1)+f.length)%f.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:w?t=>{c(a,u),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.setAttribute("visibility","visible")}:void 0,onBlur:w?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:S,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&ht("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:y+g+2+7*e.label.length,height:y+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,I&&ht(yt,{swatchSize:y}),ht("text",{y:y/2,x:y+g,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+u)),d+=M[u]+b}});const C=Math.max(0,...S.map(e=>e.width)),R=S.length;return{items:m,offset:C,totalRows:R,totalHeight:R*x}})(e,i,o,r,s,a,c,t,l,d,u,u.maxWidth??n);f+=m.offset+5,p.push({label:e.label,...m,offset:f,totalRows:m.totalRows,totalHeight:m.totalHeight}),h+=f+12});const f=u.maxWidth??n;let m=h>f?0:"center"===u.align?Math.max(0,(f-h)/2):"end"===u.align?Math.max(0,f-h):0;const y=[];return p.forEach((n,i)=>{const o=e[i];o.label&&(y.push(ht("text",{transform:`translate(${m},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:o.label},"legend-text-"+i)),m+=16),y.push(ht("g",{className:"legend-item",transform:`translate(${m},0)`,children:n.items},"legend-group-"+i)),m+=n.offset+5,e[i+1]&&y.push(ht("line",{stroke:"gray",x1:m,y1:-8,x2:m,y2:(n.totalHeight||t)+0+8},"legend-top-line legend-symbol-"+i)),m+=12}),ht("g",{children:y})})({legendGroups:t||[],title:a,height:l,width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}),x=!(!n&&!i);return pt("g",{role:x?"listbox":void 0,"aria-multiselectable":!(!x||"isolate"!==s&&(void 0!==s||null==r))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===d&&ht("text",{className:"legend-title",y:16,x:c/2,textAnchor:"middle",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}function wt(e){return"object"==typeof e&&null!==e&&"legendGroups"in e}import{jsx as kt}from"react/jsx-runtime";function Mt(e){const{legend:t,totalWidth:n,totalHeight:i,margin:o,legendPosition:r="right",legendLayout:s,title:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendInteraction:h}=e;if(!t)return null;const p="top"===r||"bottom"===r,f=!!a,m=Math.max(0,n-o.left-o.right),y=Math.max(1,p?s?.maxWidth??m:100);let g,b;return"left"===r?(g=Math.max(4,o.left-y-10),b=o.top):"top"===r?(g=o.left,b=f?32:8):"bottom"===r?(g=o.left,b=i-o.bottom+38):(g=n-o.right+10,b=o.top),kt("g",{transform:`translate(${g}, ${b})`,children:(x=t,"object"==typeof x&&null!==x&&"gradient"in x?kt(xt,{config:t.gradient,orientation:p?"horizontal":"vertical",width:y}):wt(t)?kt(vt,{legendGroups:t.legendGroups,title:"",width:y,orientation:p?"horizontal":"vertical",legendLayout:s,customHoverBehavior:c,customClickBehavior:l,highlightedCategory:d,isolatedCategories:u,legendInteraction:h}):t)});var x}import{jsx as St}from"react/jsx-runtime";var It={secondary:0,primary:3},At=".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}";function Ct(e){return!0===e?._annotationDeferred}function Rt(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Dt(e){const t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function Pt(e){return Math.max(.72,.95-.06*e)}import*as $t from"react";import{jsx as Bt,jsxs as jt}from"react/jsx-runtime";function Tt(e,t=120,n=8){if(!e)return[];const i=Math.max(1,Math.floor(t/n)),o=e.split(/\s+/),r=[];let s="";for(const e of o)s&&s.length+1+e.length>i?(r.push(s),s=e):s=s?`${s} ${e}`:e;return s&&r.push(s),r}function Nt(e,t,n,i){return"curly"===e?i?`M0,0 C${.6*n},0 ${.4*n},${t/2} ${n},${t/2} C${.4*n},${t/2} ${.6*n},${t} 0,${t}`:`M0,0 C0,${.6*n} ${t/2},${.4*n} ${t/2},${n} C${t/2},${.4*n} ${t},${.6*n} ${t},0`:i?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function Wt(e,t,n,i){if(!e)return Bt("g",{className:"annotation-note"});const{label:o,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=e;if(!o&&!r)return Bt("g",{className:"annotation-note"});let d=s;d||(d=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let u=a;u&&"dynamic"!==u||(u="topBottom"===d?0>t?"right":"left":0>n?"bottom":"top");let h="start";"topBottom"===d?"right"===u?h="end":"middle"===u&&(h="middle"):h=0>t?"end":"start";const p=16,f=r?l?[r]:Tt(r,c):[],m=o?l?[o]:Tt(o,c):[],y="leftRight"===d?"end"===h?-4:4:0;let g=0;const b=[],x=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";e.useHTML||e.html?b.push(Bt("foreignObject",{className:"annotation-note-html",x:"end"===h?y-c:"middle"===h?y-c/2:y,y:-16,width:c,height:Math.max(p,(f.length+m.length)*p+(r&&o?2:0))+p,style:{overflow:"visible"},children:jt("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:x,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&Bt("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),o&&Bt("div",{className:"annotation-note-label",children:o})]})},"annotation-note-html")):(f.length>0&&(b.push(Bt("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:f.map((e,t)=>Bt("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-title")),g=f.length*p),m.length>0&&b.push(Bt("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:g,children:m.map((e,t)=>Bt("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-label")));let v=null;if((r||o)&&(0!==t||0!==n))if("topBottom"===d){const e=Math.min(c,120);let t=0,n=e;"end"===h?(t=-e,n=0):"middle"===h&&(t=-e/2,n=e/2),v=Bt("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}else{const e=(f.length+m.length)*p+(m.length>0?p:0);let t=0,n=e;"bottom"===u?(t=-e,n=0):"middle"===u&&(t=-e/2,n=e/2),v=Bt("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,f.length+m.length-1)*p;let k=0;return"topBottom"===d?k=0>n?-(w+2):18:"leftRight"===d&&(k="middle"===u?-(w+p+(m.length>0&&f.length>0?2:0))/2+8:"bottom"===u||0>n?-(w+2):18),jt("g",{className:"annotation-note",transform:`translate(${t},${n})`,children:[Bt("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function Et(e,t,n,i,o){const r=[];switch(e){case"callout-circle":{const e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&r.push(Bt("circle",{r:e,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const e=t?.width||0,i=t?.height||0;(e>0||i>0)&&r.push(Bt("rect",{width:e,height:i,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":t?.custom&&r.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=i||0,s=o||0;if(void 0!==t?.x){const i=(t.x||0)-e;r.push(Bt("line",{x1:i,y1:(t.y1||0)-s,x2:i,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==t?.y){const i=(t.y||0)-s;r.push(Bt("line",{x1:(t.x1||0)-e,y1:i,x2:(t.x2||0)-e,y2:i,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==t?.x1||void 0!==t?.x2?r.push(Bt("line",{x1:(t.x1||0)-e,y1:0,x2:(t.x2||0)-e,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===t?.y1&&void 0===t?.y2||r.push(Bt("line",{x1:0,y1:(t.y1||0)-s,x2:0,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&r.push(Bt("path",{d:Nt(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return Bt("g",{className:"annotation-subject",children:r})}function zt(e,t,n,i,o,r){const s=[];let a=0,c=0;if("callout-circle"!==o&&"label"!==o||!r?.radius){if("callout-rect"===o&&r){const n=r.width||0,i=r.height||0;if(n>0||i>0){const o=n/2,r=i/2,s=e-o,l=t-r;if(0!==s||0!==l){const e=Math.abs(s),t=Math.abs(l),d=n/2,u=i/2,h=e*u>t*d?d/e:u/t;a=o+s*h,c=r+l*h}}}else if("bracket"===o&&r){const e=r.width,t=r.height,n=r.depth||30;void 0!==e?(a=e/2,c=n):void 0!==t&&(a=n,c=t/2)}}else{const n=(r.radius||0)+(r.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const i=Math.atan2(t,e);a=Math.cos(i)*n,c=Math.sin(i)*n}}const l=Math.sqrt((e-a)**2+(t-c)**2);if(l>.5){const o=i||"var(--semiotic-text-secondary, currentColor)",r="curve"===n?.type;let d=Math.atan2(t-c,e-a);if(r){const i=(a+e)/2,r=(c+t)/2,u=-(t-c)/l,h=(e-a)/l,p=(n?.curve??.25)*l,f=i+u*p,m=r+h*p;s.push(Bt("path",{className:"connector-curve",d:`M${a},${c}Q${f},${m} ${e},${t}`,fill:"none",stroke:o},"connector-line")),d=Math.atan2(m-c,f-a)}else s.push(Bt("line",{x1:a,y1:c,x2:e,y2:t,stroke:o},"connector-line"));if("arrow"===n?.end){const e=10,t=16/180*Math.PI;s.push(Bt("path",{d:`M${a},${c}L${a+e*Math.cos(d+t)},${c+e*Math.sin(d+t)}L${a+e*Math.cos(d-t)},${c+e*Math.sin(d-t)}Z`,fill:o,stroke:"none"},"connector-arrow"))}}return Bt("g",{className:"annotation-connector",children:s})}function Ot(e){const{x:t=0,y:n=0,dx:i,dy:o,nx:r,ny:s,note:a,connector:c,subject:l,type:d,color:u,className:h,disable:p,opacity:f,strokeDasharray:m,events:y={},"data-testid":g}=e,b=Array.isArray(t)?t[0]??0:t,x=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(p)?p:[]);let w=i||0,k=o||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const M="string"==typeof d?d:"label";if("bracket"===M&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const e=l.depth||30;k=e+(0>e?-5:5)}else if(void 0!==l.height){const e=l.depth||30;w=e+(0>e?-5:5),k=l.height/2}return jt("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":g,...null!=f&&{opacity:f},...m&&{strokeDasharray:m},...y,children:[!v.has("connector")&&zt(w,k,c,u,M,l),!v.has("subject")&&Et(M,l,u,b,x),!v.has("note")&&Wt(a,w,k,u)]})}function Ft(e){const{noteData:t}=e,{screenCoordinates:n}=t,i="string"==typeof t.type?t.type:"label",o=t.eventListeners||t.events||{};if(t.coordinates&&n){const e=t.nx||n[0][0]+(t.dx??0),o=t.ny||n[0][1]+(t.dy??0),r=n.map((n,r)=>{const s=Object.assign({},t,{note:0===r?t.note:{label:""},x:n[0],y:n[1],nx:e,ny:o});return Bt(Ot,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+r)});return Bt("g",{children:r})}const r=t.note||{title:"none",label:t.label},s=`${r.label}-${r.title}-${t.i}`;return Bt(Ot,{"data-testid":"semiotic-annotation",events:o,...t,type:i},s)}import{packEnclose as Lt}from"d3-hierarchy";import{area as qt,curveLinear as Yt,curveMonotoneX as Ht,curveMonotoneY as Gt,curveStep as Xt,curveStepAfter as _t,curveStepBefore as Vt,curveBasis as Ut,curveCardinal as Kt,curveCatmullRom as Qt}from"d3-shape";function Zt(e){return Math.round(100*e)/100}function Jt(e,t=2){const n=[],i=[],o=t+1;for(let t=0;o>t;t++){let r=0;for(const[n,i]of e)null!==i&&(r+=n**t*i);n.push(r);const s=[];for(let n=0;o>n;n++){let i=0;for(const[o,r]of e)null!==r&&(i+=o**(t+n));s.push(i)}i.push(s)}i.push(n);const r=function(e,t){const n=e,i=e.length-1,o=[t];for(let e=0;i>e;e++){let t=e;for(let o=e+1;i>o;o++)Math.abs(n[e][o])>Math.abs(n[e][t])&&(t=o);for(let o=e;i+1>o;o++){const i=n[o][e];n[o][e]=n[o][t],n[o][t]=i}for(let t=e+1;i>t;t++)for(let o=i;o>=e;o--)n[o][t]-=n[o][e]*n[e][t]/n[e][e]}for(let e=i-1;e>=0;e--){let t=0;for(let r=e+1;i>r;r++)t+=n[r][e]*o[r];o[e]=(n[i][e]-t)/n[e][e]}return o}(i,o).map(Zt);return{points:e.map(([e])=>[Zt(e),Zt(r.reduce((t,n,i)=>t+n*e**i,0))]),equation:[...r].reverse()}}function en(e,t){const n=t.scales?.x??t.scales?.time;return n?null!=e.x?n(e.x):t.xAccessor&&null!=e[t.xAccessor]?n(e[t.xAccessor]):null:null}function tn(e,t){const n=t.scales?.y??t.scales?.value;return n?null!=e.y?n(e.y):t.yAccessor&&null!=e[t.yAccessor]?n(e[t.yAccessor]):null:null}function nn(e){return null==e?null:e+""}function on(e,t,n){return t.stickyPositionCache?.set(e,n),n}function rn(e,t,n){const i=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===i){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let i=n.pointNodes.length-1;i>=0;i--){const o=n.pointNodes[i];if(o.pointId===e.pointId)return on(t,n,{x:o.x,y:o.y})}const i=function(e){const t=e.data;if(!t||0===t.length)return null;const n=t[t.length-1],i=e.scales?.x??e.scales?.time,o=e.scales?.y??e.scales?.value;if(!i||!o)return null;const r=n[e.xAccessor||"x"],s=n[e.yAccessor||"y"];return null==r||null==s?null:{x:i(r),y:o(s)}}(n);return i?on(t,n,i):null}if("semantic"===i){const i=function(e,t,n){const i=function(e){return nn(e.provenance?.stableId??e.stableId)}(e);if(!i)return null;const o=n.pointNodes?.find(e=>nn(e.pointId)===i);if(o)return on(t,n,{x:o.x,y:o.y});const r=n.data?.find(e=>function(e){return nn(e.stableId??e.id??e.provenance?.stableId)}(e)===i);if(!r)return null;const s=en(r,n),a=tn(r,n);return null==s||null==a?null:on(t,n,{x:s,y:a})}(e,t,n);if(i)return i}let o=null,r=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(o=t.x,r=t.y)}if(null!=o&&null!=r||(o=en(e,n),r=tn(e,n)),null!=o&&null!=r)return on(t,n,{x:o,y:r});if("sticky"===i){const e=n.stickyPositionCache?.get(t);if(e)return e}return null}function sn(e,t,n,i=50){return!(-i>e||e>(n.width||0)+i||-i>t||t>(n.height||0)+i)}function an(e){let t=1/0,n=-1/0;for(const i of e)t>i&&(t=i),i>n&&(n=i);return[t,n]}import*as cn from"react";var[ln,dn]=I(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const n=e.observations;return n.push(t),n.length>e.maxObservations&&n.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}}));function un(e,t={}){const n=function(e){const t=e.provenance,n=e.id??e.stableId??t?.stableId;return null==n||""===n?void 0:n+""}(e);return{"data-semiotic-annotation-widget":"",...n?{"data-semiotic-annotation-id":n}:{},onClickCapture(i){const o=function(e){const t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(i);t.onAnnotationActivate?.({annotation:e,annotationId:n,chartId:t.chartId,inputType:o}),n&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:n,inputType:o,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}import{jsx as hn,jsxs as pn}from"react/jsx-runtime";var fn="var(--semiotic-bg, #ffffff)";function mn(e){const{x:t,y:n,text:i,fill:o,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,background:d,className:u}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{type:e.type??"halo",...e}}(d),p=e=>hn("text",{x:t,y:n,textAnchor:c,dominantBaseline:l,fill:o,fontSize:r,fontWeight:s,fontFamily:a,className:u,...e?{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}:{},children:i});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??fn,strokeWidth:h.haloWidth??3});const f=h.padding??{x:6,y:3},m="number"==typeof f?f:f.x,y="number"==typeof f?f:f.y,g=function(e,t){return(e+"").length*t*.6}(i,r),b=r+2*y;let x,v;return x="middle"===c?t-g/2-m:"end"===c?t-g-m:t-m,v="middle"===l||"central"===l?n-b/2:"hanging"===l||"text-before-edge"===l?n-y:n-.8*r-y,pn("g",{className:u,children:[hn("rect",{x:x,y:v,width:g+2*m,height:b,rx:h.radius??3,ry:h.radius??3,fill:h.fill??fn,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),p()]})}import{jsx as yn,jsxs as gn}from"react/jsx-runtime";var bn={linear:Yt,monotoneX:Ht,monotoneY:Gt,step:Xt,stepAfter:_t,stepBefore:Vt,basis:Ut,cardinal:Kt,catmullRom:Qt};var xn=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function vn(e){return!!e&&"object"==typeof e&&xn.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function wn(e){return"primary"===e?.emphasis||!0===e?.defensive}function kn(e,t,n={}){return"number"==typeof n.maxAnnotations&&Number.isFinite(n.maxAnnotations)?Math.max(0,Math.floor(n.maxAnnotations)):e>0&&t>0?Math.max(1,Math.round(e*t/(n.areaPerAnnotation&&n.areaPerAnnotation>0?n.areaPerAnnotation:2e4))):1/0}function Mn(e){let t;const n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;const i=e?.provenance?.confidence;switch("number"==typeof i&&Number.isFinite(i)&&(t+=15*Math.max(0,Math.min(1,i))),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}new Set(["label","callout","callout-circle","callout-rect"]);var Sn=32,In=6,An=4,Cn=8,Rn=72;var Dn={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function Pn(e){if(!$n(e))return e;const t=("string"==typeof e.mobileText?e.mobileText:void 0)??("string"==typeof e.shortText?e.shortText:void 0);return!t||"string"!=typeof e.label&&null!=e.label?e:{...e,label:t}}function $n(e){return vn(e)}function Bn(e,t){if(!e)return[];const n=Math.max(1,Math.floor(t/7)),i=e.split(/\s+/).filter(Boolean),o=[];let r="";for(const e of i)r&&r.length+e.length+1>n?(o.push(r),r=e):r=r?`${r} ${e}`:e;return r&&o.push(r),o}function jn(e,t,n,i,o){const r=e+n,s=t+i;return Math.abs(n)>Math.abs(i)?{x:0>n?r-o.width-4:r+4,y:0>i?s-o.height:s,width:o.width,height:o.height}:{x:0>n?r-o.width:r,y:0>i?s-o.height-4:s+4,width:o.width,height:o.height}}function Tn(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Nn(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function Wn(e,t,n,i,o,r,s,a){const c=Tn(e,s);let l=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,i){const o=Math.max(0,i-e.x),r=Math.max(0,i-e.y);return(o+Math.max(0,e.x+e.width-(t-i)))*e.height+(r+Math.max(0,e.y+e.height-(n-i)))*e.width}(c,o,r,a);for(const e of n)l+=12*Nn(c,e);for(const e of i)l+=4*Nn(c,e);return l}function En(e){const{annotations:t,context:n,defaultOffset:i=Sn,notePadding:o=In,markPadding:r=An,edgePadding:s=Cn,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=Rn,density:d,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:m,audience:y}=e,g=n.width||0,b=n.height||0,x="object"==typeof f?f:{},v=x.breakpoint??480,w=!!f&&v>=g,k=w&&!1!==x.preferShortText?t.map(Pn):t,M=w&&!d?{maxAnnotations:x.maxAnnotations??("callout-list"===x.strategy?1:2),minVisible:x.minVisible??1}:d,S=u||w&&(!1!==x.progressiveDisclosure||"callout-list"===x.strategy),I=w&&!p?x.responsive??{minWidth:v}:p,A=w&&!m?x.cohesion:m;if(0===k.length||0>=g||0>=b)return k.slice();const C=[],R=function(e,t){return(e.pointNodes||[]).map(e=>{const n=Math.max(1,e.r||1)+t;return{x:e.x-n,y:e.y-n,width:2*n,height:2*n}})}(n,r);let D=!1;const P=k.map((e,t)=>{if(!$n(e))return e;const r=function(e,t,n){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};const i=e.pointId??e.nodeId;if(null!=i&&n.pointNodes){const e=n.pointNodes.find(e=>e.pointId===i);if(e)return{x:e.x,y:e.y}}const o=e.coordinates,r=n.scales?.geoProjection;if(Array.isArray(o)&&o.length>=2&&r){const e=o[0],t=o[1];if("number"==typeof e&&"number"==typeof t){const n=r([e,t]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof e.x||"number"!=typeof e.y?rn(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!r)return e;const d=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};const t="number"==typeof e.wrap?e.wrap:120,n=[...Bn("string"==typeof e.title?e.title:void 0,t),...Bn("string"==typeof e.label?e.label:void 0,t)],i=n.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(t,7*i)+10),height:Math.max(18,16*n.length+6)}}(e);if(a&&("number"==typeof(u=e).dx||"number"==typeof u.dy)){const t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e);return C.push(Tn(jn(r.x,r.y,"number"==typeof e.dx?e.dx:t.dx,"number"==typeof e.dy?e.dy:t.dy,d),o)),e}var u;let h=null,p=1/0;for(const e of function(e){const t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}(i)){const t=Wn(jn(r.x,r.y,e.dx,e.dy,d),e,C,R,g,b,o,s);p>t&&(h=e,p=t)}if(!h)return e;const f=Tn(jn(r.x,r.y,h.dx,h.dy,d),o);C.push(f);const m=Math.hypot(h.dx,h.dy),y=c&&m>=l&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return D=!0,{...e,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),$=D?P:k.slice();let B=$;if(h){let e=!1;const t=$.map(t=>{const n=function(e){return"text"!==e.type||"string"!=typeof e.color||8>Math.hypot("number"==typeof e.dx?e.dx:0,"number"==typeof e.dy?e.dy:0)?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});B=e?t:$}{let e=!1;const t=B.map(t=>{if(!0!==t?.defensive)return t;const n=function(e){const t=e?.provenance;if(!t||"object"!=typeof t)return e;const n="string"==typeof t.source?Dn[t.source]??t.source:null,i="number"==typeof t.confidence&&Number.isFinite(t.confidence)?Math.round(100*Math.max(0,Math.min(1,t.confidence)))+"%":null;if(!n&&!i)return e;if(null!=e.label&&"string"!=typeof e.label)return e;const o=[n,i].filter(Boolean).join(" · "),r="string"==typeof e.label?e.label:"";return r.includes(`(${o})`)?e:{...e,label:r?`${r} (${o})`:`(${o})`}}(t);return n!==t&&(e=!0),n});B=e?t:B}const j=new Set;if(M){const e="object"==typeof M?M:{},t=function(e){if(!e)return 1;const t=function(e){const t=e?.familiarity;if(!t)return 3;const n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?3:n.reduce((e,t)=>e+t,0)/n.length}(e);return t>2?4>t?1:.6:1.5}(y),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??kn(g,b,e))*t))},{deferred:i}=function(e){const{annotations:t,width:n,height:i}=e,o=Math.max(0,e.minVisible??1),r=kn(n,i,e),s=t.map((e,t)=>{return{annotation:e,index:t,note:(n=e,vn(n))};var n}),a=s.filter(e=>e.note);if(0===a.length||r>=a.length)return{visible:t.slice(),deferred:[],budget:r};const c=a.filter(e=>wn(e.annotation)),l=a.filter(e=>!wn(e.annotation)).sort((e,t)=>Mn(t.annotation)-Mn(e.annotation)||e.index-t.index),d=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,o-c.length))),u=new Set([...c.map(e=>e.index),...l.slice(0,d).map(e=>e.index)]),h=[],p=[];for(const{annotation:e,index:t,note:n}of s)!n||u.has(t)?h.push(e):p.push(e);return{visible:h,deferred:p,budget:r}}({annotations:B,width:g,height:b,...n});for(const e of i)j.add(e)}if(I&&("object"==typeof I&&"number"==typeof I.minWidth?I.minWidth:480)>=g)for(const e of B)$n(e)&&"secondary"===e.emphasis&&j.add(e);if(j.size>0)for(const e of B)!0===e?.defensive&&j.delete(e);let T;return T=0===j.size?B:S?B.map(e=>j.has(e)?{...e,_annotationDeferred:!0}:e):B.filter(e=>!j.has(e)),A?function(e,t){let n=!1;const i=e.map(e=>$n(e)?"blended"===e.cohesion||"layer"===e.cohesion?e:(n=!0,{...e,cohesion:t}):e);return n?i:e}(T,A):T}import{Fragment as zn,jsx as On,jsxs as Fn}from"react/jsx-runtime";function Ln(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function qn(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,Ln(e))}))}function Yn(e){const{width:t,height:n,pointNodes:i=[],data:o}=e;return{scales:{x:dt().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:dt().domain([0,Math.max(1,n)]).range([0,Math.max(1,n)])},width:t,height:n,frameType:"network",pointNodes:i,data:o,xAccessor:"x",yAccessor:"y"}}function Hn(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}function Gn(e){const{width:t,height:n,totalWidth:i,totalHeight:o,margin:r,title:s,legend:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendPosition:h="right",legendLayout:p,pointNodes:f=[],annotations:m,onAnnotationActivate:y,onObservation:g,chartId:b,chartType:x,autoPlaceAnnotations:v,svgAnnotationRules:w,children:k}=e,M=function(e){const t=dn(e=>e.pushObservation),n=cn.useCallback(n=>{e.onObservation?.(n),t?.(n)},[e,t]);return cn.useMemo(()=>({...e,onObservation:n}),[n,e])}({onAnnotationActivate:y,onObservation:g,chartId:b,chartType:x}),S=lt.useMemo(()=>Hn(m),[m]),I=lt.useMemo(()=>Yn({width:t,height:n,pointNodes:f}),[n,f,t]),A=lt.useMemo(()=>S&&v?En({annotations:S,context:I,..."object"==typeof v?v:{}}):S,[I,v,S]),C=lt.useMemo(()=>function(e,t={}){return function(e,n,i){switch(e.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const t=rn(e,n,i);if(!t)return null;const{x:o,y:r}=t;if(!sn(o,r,i))return null;const s="callout"===e.type?"callout-circle":e.type,a="callout-circle"===s?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===s?{width:e.width,height:e.height}:void 0;return yn(Ft,{noteData:{x:o,y:r,dx:e.dx??30,dy:e.dy??-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:s,...a?{subject:a}:{},connector:e.connector||{end:"arrow"},color:e.color,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-"+n)}case"x-threshold":{const t=en(null!=e.value?{...e,x:e.value}:e,i);if(null==t)return null;const o=e.color||"#f97316",r=e.labelPosition||"top";let s;s="bottom"===r?(i.height||0)-4:"center"===r?(i.height||0)/2:16;const a=t>.6*(i.width||0),c=a?t-4:t+4,l=a?"end":"start";return gn("g",{opacity:e.opacity,children:[yn("line",{x1:t,y1:0,x2:t,y2:i.height||0,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&yn(mn,{x:c,y:s,text:e.label,textAnchor:l,fill:o,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"y-threshold":{const t=tn(null!=e.value?{...e,y:e.value}:e,i);if(null==t)return null;const o=e.color||"#f97316",r=e.labelPosition||"right";let a,c;"left"===r?(a=4,c="start"):"center"===r?(a=(i.width||0)/2,c="middle"):(a=(i.width||0)-4,c="end");const l=20>(s=t)?Math.min((i.height||0)-4,s+16):s-4;return gn("g",{opacity:e.opacity,children:[yn("line",{x1:0,y1:t,x2:i.width||0,y2:t,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&yn(mn,{x:a,y:l,text:e.label,textAnchor:c,fill:o,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"enclose":{const t=(e.coordinates||[]).map(e=>({x:en({...e,type:"point"},i),y:tn({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const o=Lt(t),r=e.padding||10;return gn("g",{children:[yn("circle",{cx:o.x,cy:o.y,r:o.r+r,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&yn(mn,{x:o.x,y:o.y-o.r-r-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"rect-enclose":{const t=(e.coordinates||[]).map(e=>({x:en({...e,type:"point"},i),y:tn({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const o=e.padding||10,r=t.map(e=>e.x),s=t.map(e=>e.y),[a,c]=an(r),[l,d]=an(s),u=a-o,h=c+o,p=l-o;return gn("g",{children:[yn("rect",{x:u,y:p,width:h-u,height:d+o-p,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&yn(mn,{x:(u+h)/2,y:p-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"highlight":{const t=i.data||[],o="function"==typeof e.filter?t.filter(e.filter):e.field&&null!=e.value?t.filter(t=>t[e.field]===e.value):[],r={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return yn("g",{children:o.map((t,n)=>{const o=en(t,i),s=tn(t,i);if(null==o||null==s)return null;const a="function"==typeof e.r?e.r(t):e.r||6,c="function"==typeof e.style?e.style(t):e.style||r;return yn("circle",{cx:o,cy:s,r:a,...c},"hl-"+n)})},"ann-"+n)}case"bracket":{const t=en(e,i),o=tn(e,i);return yn(Ft,{noteData:{x:t??0,y:o??0,dx:e.dx||0,dy:e.dy||0,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},"ann-"+n)}case"trend":{const t=i.data||[];if(2>t.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s="ordinal"===i.frameType,a="horizontal"===i.projection,c=s?o:null,l=s?r:null;let d;const u=[],h=new Map;if(s&&c&&l){for(const e of t){const t=e[c];if(null==t)continue;const n=t+"";h.has(n)||(h.set(n,u.length),u.push(n))}d=t.map(e=>{const t=e[c],n=e[l];if(null==t||null==n)return null;const i=h.get(t+"");return null!=i?[i,+n]:null}).filter(e=>null!==e)}else d=t.map(e=>[e[o],e[r]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>d.length)return null;const p=i.scales?.x??i.scales?.time,f=i.scales?.y??i.scales?.value;if(!p||!f)return null;const m=e=>t=>{const n=Math.max(0,Math.floor(t)),i=Math.min(u.length-1,n+1),o=t-n,r=e(u[n]);return r+(e(u[i])-r)*o},y=p,g=f;let b;if(s)if(a){const e=m(g);b=(t,n)=>[y(n),e(t)]}else{const e=m(y);b=(t,n)=>[e(t),g(n)]}else b=(e,t)=>[y(e),g(t)];const x=e.method||"linear";let v;if("loess"===x)v=function(e,t=.3){const n=e.length;if(2>n)return e.slice();const i=e.slice().sort((e,t)=>e[0]-t[0]),o=i.map(e=>e[0]),r=i.map(e=>e[1]),s=Math.max(2,Math.ceil(t*n)),a=[];for(let e=0;n>e;e++){const t=o[e],i=o.map(e=>Math.abs(e-t)),c=i.slice().sort((e,t)=>e-t)[Math.min(s-1,n-1)]||1,l=[];for(let e=0;n>e;e++){const t=0===c?0:i[e]/c;l[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let d=0,u=0,h=0,p=0,f=0;for(let e=0;n>e;e++){const t=l[e];0!==t&&(d+=t,u+=t*o[e],h+=t*r[e],p+=t*o[e]*o[e],f+=t*o[e]*r[e])}if(0===d){a.push([t,r[e]]);continue}const m=d*p-u*u;if(1e-12>Math.abs(m))a.push([t,h/d]);else{const e=(d*f-u*h)/m;a.push([t,(h-e*u)/d+e*t])}}return a}(d,e.bandwidth??.3);else{const t="polynomial"===x?Jt(d,e.order||2):function(e){const t=[0,0,0,0];let n=0;for(const[i,o]of e)null!==o&&(n++,t[0]+=i,t[1]+=o,t[2]+=i*i,t[3]+=i*o);const i=n*t[2]-t[0]*t[0],o=0===i?0:Zt((n*t[3]-t[0]*t[1])/i),r=Zt(t[1]/n-o*t[0]/n);return{points:e.map(([e])=>[Zt(e),Zt(o*e+r)]),equation:[o,r]}}(d);v=t.points}const w=v.map(([e,t])=>{const[n,i]=b(e,t);return`${n},${i}`}).join(" "),k=e.color||"#6366f1",M=v[v.length-1],[S,I]=b(M[0],M[1]);return gn("g",{children:[yn("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&yn("text",{x:S+4,y:I-4,fill:k,fontSize:11,children:e.label})]},"ann-"+n)}case"band":{const t=i.scales?.y??i.scales?.value,s=t?.(e.y0)??0,a=t?.(e.y1)??(i.height||0),c=Be(e.fill,"ann-"+n,"var(--semiotic-primary, #6366f1)");return gn("g",{opacity:e.opacity,children:[c.def&&yn("defs",{children:c.def}),yn("rect",{x:0,y:Math.min(s,a),width:i.width||0,height:Math.abs(a-s),fill:c.fill,fillOpacity:e.fillOpacity||.1}),e.label&&yn(mn,{x:(i.width||0)-4,y:(o=s,r=a,Math.max(Math.min(o,r),0)+16),textAnchor:"end",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"x-band":{const t=i.scales?.x??i.scales?.time,o=null!=e.x0&&t?t(e.x0):null,r=null!=e.x1&&t?t(e.x1):null;if(null==o||null==r)return null;const s=Be(e.fill||e.color,"ann-"+n,"var(--semiotic-primary, #6366f1)");return gn("g",{opacity:e.opacity,children:[s.def&&yn("defs",{children:s.def}),yn("rect",{x:Math.min(o,r),y:0,width:Math.abs(r-o),height:i.height||0,fill:s.fill,fillOpacity:e.fillOpacity??.1}),e.label&&yn(mn,{x:Math.min(o,r)+4,y:16,textAnchor:"start",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"envelope":{const t=i.data||[];if(2>t.length)return null;const o=i.xAccessor||"x",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",l=e.filter,d=t.filter(e=>null!=e[a]&&null!=e[c]&&!(l&&!l(e))).sort((e,t)=>e[o]-t[o]);if(2>d.length)return null;const u=bn[i.curve||"linear"]||Yt,h=qt().x(e=>r(e[o])).y0(e=>s(e[c])).y1(e=>s(e[a])).curve(u)(d);if(!h)return null;const p=e.fill||"#6366f1";return gn("g",{children:[yn("path",{d:h,fill:p,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&d.length>0&&yn("text",{x:r(d[d.length-1][o])+4,y:s(d[d.length-1][a])-4,fill:p,fontSize:11,children:e.label})]},"ann-"+n)}case"anomaly-band":{const t=i.data||[];if(2>t.length)return null;const o=i.yAccessor||"y",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=t.map(e=>e[o]).filter(e=>null!=e&&isFinite(e));if(2>a.length)return null;const c=a.reduce((e,t)=>e+t,0)/a.length,l=a.reduce((e,t)=>e+(t-c)**2,0)/a.length,d=Math.sqrt(l),u=e.threshold??2,h=c-u*d,p=!1!==e.showBand,f=e.fill||"#6366f1",m=e.fillOpacity??.1,y=e.anomalyColor||"#ef4444",g=e.anomalyRadius??6,b=s(c+u*d),x=s(h),v=t.filter(e=>{const t=e[o];return null!=t&&Math.abs(t-c)>u*d});return gn("g",{children:[p&&yn("rect",{x:0,y:Math.min(b,x),width:i.width||0,height:Math.abs(x-b),fill:f,fillOpacity:m}),v.map((e,t)=>{const n=en(e,i),o=tn(e,i);return null==n||null==o?null:yn("circle",{cx:n,cy:o,r:g,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+t)}),e.label&&yn("text",{x:(i.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:f,fontSize:11,children:e.label})]},"ann-"+n)}case"forecast":{const t=i.data||[];if(3>t.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!s||!a)return null;const c=t.map(e=>[e[o],e[r]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>c.length)return null;let l;if("polynomial"===(e.method||"linear")){const t=Jt(c,e.order||2).equation;l=e=>t.reduce((t,n,i)=>t+n*Math.pow(e,i),0)}else{const e=c.length;let t=0,n=0,i=0,o=0;for(const[e,r]of c)t+=e,n+=r,i+=e*e,o+=e*r;const r=e*i-t*t;if(1e-12>Math.abs(r))return null;const s=(e*o-t*n)/r,a=(n-s*t)/e;l=e=>a+s*e}const d=c.length,u=c.map(([e,t])=>t-l(e)),h=u.reduce((e,t)=>e+t*t,0),p=Math.sqrt(h/Math.max(d-2,1)),f=c.reduce((e,t)=>e+t[0],0)/d,m=c.reduce((e,t)=>e+(t[0]-f)**2,0),y=e.confidence??.95,g=.99>y?.95>y?.9>y?1:1.645:1.96:2.576,b=e.steps??5,x=c[d-1][0],v=(x-c[0][0])/Math.max(d-1,1),w=[];for(let e=1;b>=e;e++)w.push(x+e*v);const k=[];for(const e of w){const t=l(e),n=p*Math.sqrt(1+1/d+(m>0?(e-f)**2/m:0))*g;k.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const M=`M${k.map(e=>`${s(e.x)},${a(e.yUpper)}`).join(" L")} L${k.slice().reverse().map(e=>`${s(e.x)},${a(e.yLower)}`).join(" L")} Z`,S=k.map(e=>`${s(e.x)},${a(e.yCenter)}`).join(" "),I=`${s(x)},${a(l(x))}`,A=e.strokeColor||"#6366f1";return gn("g",{children:[yn("path",{d:M,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),yn("polyline",{points:`${I} ${S}`,fill:"none",stroke:A,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&k.length>0&&yn("text",{x:s(k[k.length-1].x)+4,y:a(k[k.length-1].yCenter)-4,fill:A,fontSize:11,children:e.label})]},"ann-"+n)}case"widget":{let o,r;if(null!=e.px&&null!=e.py)o=e.px,r=e.py;else{const t=rn(e,n,i);if(!t)return null;o=t.x,r=t.y}if(!sn(o,r,i))return null;const s=e.dx??0,a=e.dy??0,c=e.width??32,l=e.height??32,d=e.content??yn("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return yn("foreignObject",{x:o+s-c/2,y:r+a-l/2,width:c,height:l,style:{overflow:"visible",pointerEvents:"auto"},children:yn("div",{...un(e,t),style:{width:c,height:l,display:"flex",alignItems:"center",justifyContent:"center"},children:d})},"ann-"+n)}case"text":{const t=rn(e,n,i);if(!t)return null;const{x:o,y:r}=t,s=o+(e.dx||0),a=r+(e.dy||0),c=e.color||"var(--semiotic-text, #333)",l=yn("text",{x:s,y:a,fill:c,fontSize:e.fontSize||11,opacity:e.opacity,strokeDasharray:e.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:e.label});return!0!==e._redundantConnector?$t.cloneElement(l,{key:"ann-text-"+n}):gn("g",{opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:[yn("line",{x1:o,y1:r,x2:s,y2:a,stroke:c,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),$t.cloneElement(l,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+n)}case"category-highlight":{const t=e.category;if(null==t)return null;const o=e=>"function"==typeof e&&"function"==typeof e.bandwidth,r=i.scales?.o,s=i.scales?.x,a=i.scales?.y,c=o(r)?r:o(s)?s:o(a)?a:null;if(!c)return null;const l=c(t+"");if(null==l)return null;const d=c.bandwidth(),u=e.color||"var(--semiotic-primary, #4589ff)",h=e.opacity??.15,p=e.label;return gn("g",(i.projection?"vertical"===i.projection:c===s)?{children:[yn("rect",{x:l,y:0,width:d,height:i.height||0,fill:u,fillOpacity:h}),p&&yn(mn,{x:l+d/2,y:16,textAnchor:"middle",fill:u,fontSize:12,fontWeight:"bold",text:p,background:e.labelBackground??"none"})]}:{children:[yn("rect",{x:0,y:l,width:i.width||0,height:d,fill:u,fillOpacity:h}),p&&yn(mn,{x:12,y:l+d/2,dominantBaseline:"middle",fill:u,fontSize:12,fontWeight:"bold",text:p,background:e.labelBackground??"none"})]},"ann-"+n)}default:return null}var o,r,s}}(0,M),[M]),R=A?function(e,t,n,i){const o=[];return e.forEach((e,r)=>{let s;if(n){const o=n(e,r,i);s=null!=o?o:t(e,r,i)}else s=t(e,r,i);s&&o.push({node:s,annotation:e})}),function(e){const t=e.map((e,t)=>{return{p:e,i:t,emphasis:(n=e.annotation,"primary"===n?.emphasis||"secondary"===n?.emphasis?n.emphasis:null),confidence:Dt(e.annotation),readingOrder:null,rank:1};var n}),n=t.some(e=>null!=e.emphasis||null!=e.confidence),i=e.some(e=>Ct(e.annotation)),o=e.some(e=>null!=Rt(e.annotation)),r=e.some(e=>"layer"===Rt(e.annotation));if(!n&&!i&&!o)return e.map(e=>e.node);const s=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);s.forEach((e,t)=>{e.readingOrder=t,e.rank=2-t/Math.max(1,s.length)});for(const e of t)e.emphasis&&(e.rank=It[e.emphasis]);const a=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{const{p:t,i:n,emphasis:i,readingOrder:o}=e,r=Ct(t.annotation);let s=t.node;if("primary"===i||"secondary"===i||null!=o){const e=null==i&&null!=o;s=St("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:Pt(o),"data-annotation-reading-order":o}:{},children:t.node},"annotation-emphasis-"+n)}const a=Rt(t.annotation);return a&&(s=St("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),r&&(s=St("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return i&&a.unshift(St("style",{children:At},"annotation-disclosure-style")),r&&a.unshift(St("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}(o)}(A,C,w,I):null,D=!0===A?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return Fn(zn,{children:[D?On("style",{children:At},"physics-annotation-disclosure-style"):null,Fn("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Fn("g",{transform:`translate(${r.left},${r.top})`,children:[R,k]}),s&&"string"==typeof s?On("text",{x:i/2,y:16,textAnchor:"middle",fontWeight:600,fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:s}):s?On("foreignObject",{x:0,y:0,width:i,height:Math.max(r.top,28),children:s}):null,a?Mt({legend:a,totalWidth:i,totalHeight:o,margin:r,legendPosition:h,legendLayout:p,title:s,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u}):null]})]})}function Xn(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function _n(e,t){const n="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,Xn(e.thickness)??Xn(n)??Xn(t.thickness)??4)}var Vn=2500;function Un(e){return"function"==typeof e}function Kn(e){return void 0===e||!1===e||!Un(e.binAccessor)&&!Un(e.labelAccessor)&&!Un(e.valueAccessor)}function Qn(e){if(void 0!==e){if(!1===e)return!1;if(!Kn(e))throw new TypeError("Physics worker sediment config only supports string or numeric accessors");return{binAccessor:"string"==typeof e.binAccessor?e.binAccessor:void 0,labelAccessor:"string"==typeof e.labelAccessor?e.labelAccessor:void 0,valueAccessor:"string"==typeof e.valueAccessor||"number"==typeof e.valueAccessor?e.valueAccessor:void 0,retainBodyIds:e.retainBodyIds}}}function Zn(e){if(e)return{chartId:e.chartId,chartType:e.chartType,sensors:e.sensors}}function Jn(e){return function(e){return!Un(e?.timeAccessor)}(e)}function ei(e={}){if(e.engine)throw new TypeError("Physics workers use the built-in kernel adapter");const{engine:t,observation:n,sediment:i,...o}=e;return{...o,observation:Zn(n),sediment:Qn(i)}}function ti(){if("undefined"!=typeof DOMException)return new DOMException("Physics worker request aborted","AbortError");const e=Error("Physics worker request aborted");return e.name="AbortError",e}var ni=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./physicsWorker.js",import.meta.url):function(e){if("undefined"!=typeof __filename){const t=__filename.replace(/\\/g,"/"),n=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+n)}throw Error("Cannot resolve module worker asset: "+e)}("physicsWorker.js");return new Worker(e,{type:"module",name:"semiotic-physics"})}()){this.nextRequestId=1,this.pending=new Map,this.worker=e,this.worker.onmessage=e=>{const t=e.data,n=this.pending.get(t.requestId);n&&(this.pending.delete(t.requestId),n.cleanup(),t.ok?n.resolve(t.payload):n.reject(function(e){const t=Error(e.error.message);return t.name=e.error.name??"Error",e.error.stack&&(t.stack=e.error.stack),t}(t)))},this.worker.onerror=e=>{this.rejectAll(Error(e.message||"Physics worker failed")),this.worker.terminate()}}request(e,t){if(t?.aborted)return Promise.reject(ti());const n=this.nextRequestId;this.nextRequestId+=1;const i={command:e,requestId:n};return new Promise((e,o)=>{const r=()=>{this.pending.delete(n),t?.removeEventListener("abort",r),o(ti())},s=()=>t?.removeEventListener("abort",r);this.pending.set(n,{cleanup:s,reject:o,resolve:e}),t?.addEventListener("abort",r,{once:!0});try{this.worker.postMessage(i)}catch(e){this.pending.delete(n),s(),o(e)}})}async init(e,t,n,i){if(!Jn(n))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const o=await this.request({type:"init",config:ei(e),initialSpawns:t,initialSpawnPacing:n},i);if("frame"!==o.type)throw Error("Physics worker returned a non-frame init response");return o.frame}async restore(e,t){const n=await this.request({type:"restore",snapshot:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame restore response");return n.frame}async initFromSnapshot(e,t,n){const i=await this.request({type:"init",config:ei(e),snapshot:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame init response");return i.frame}async enqueue(e,t,n){if(!Jn(t))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const i=await this.request({type:"enqueue",spawns:e,pacing:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame enqueue response");return i.frame}async tick(e,t){const n=await this.request({type:"tick",deltaSeconds:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame tick response");return n.frame}async settle(e,t){const n=await this.request({type:"settle",maxSteps:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame settle response");return n.frame}async snapshot(e){const t=await this.request({type:"snapshot"},e);if("snapshot"!==t.type)throw Error("Physics worker returned a non-snapshot response");return t.snapshot}async remove(e,t){const n=await this.request({type:"remove",ids:e},t);if("removed"!==n.type)throw Error("Physics worker returned a non-remove response");return{frame:n.frame,removed:n.removed}}terminate(){this.rejectAll(Error("Physics worker terminated")),this.worker.terminate()}rejectAll(e){for(const[t,n]of this.pending)this.pending.delete(t),n.cleanup(),n.reject(e)}};function ii(e){let t=e>>>0;return function(){t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}var oi={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},ri=1e-9,si=.005;function ai(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function ci(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function li(e,t,n){return Math.max(t,Math.min(n,e))}function di(e){return 0>e?-1:1}function ui(e){if("circle"===e.shape.type){const t=e.shape.radius;return{minX:e.x-t,minY:e.y-t,maxX:e.x+t,maxY:e.y+t}}const t=e.shape.width/2,n=e.shape.height/2;return{minX:e.x-t,minY:e.y-n,maxX:e.x+t,maxY:e.y+n}}function hi(e){const t=e.shape;if("aabb"===t.type){const e=t.width/2,n=t.height/2;return{minX:t.x-e,minY:t.y-n,maxX:t.x+e,maxY:t.y+n}}const n=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-n,minY:Math.min(t.y1,t.y2)-n,maxX:Math.max(t.x1,t.x2)+n,maxY:Math.max(t.y1,t.y2)+n}}function pi(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function fi(e,t,n,i,o,r,s,a){const c=o-e,l=(n+s)/2-Math.abs(c);if(0>=l)return null;const d=r-t,u=(i+a)/2-Math.abs(d);return u>0?u>l?{nx:di(c),ny:0,penetration:l}:{nx:0,ny:di(d),penetration:u}:null}function mi(e,t,n,i,o,r,s){const a=r/2,c=s/2;let l=e-li(e,i-a,i+a),d=t-li(t,o-c,o+c);const u=l*l+d*d;if(u>n*n)return null;if(ri>=u){const r=Math.abs(e-(i-a)),s=Math.abs(e-(i+a)),u=Math.abs(t-(o-c)),h=Math.abs(t-(o+c)),p=Math.min(r,s,u,h);return p===r?(l=-1,d=0,{nx:l,ny:d,penetration:n+r}):p===s?(l=1,d=0,{nx:l,ny:d,penetration:n+s}):p===u?(l=0,d=-1,{nx:l,ny:d,penetration:n+u}):(l=0,d=1,{nx:l,ny:d,penetration:n+h})}const h=Math.sqrt(u);return{nx:l/h,ny:d/h,penetration:n-h}}function yi(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,i,o,r){const s=i-e,a=o-t,c=n+r,l=s*s+a*a;if(l>=c*c)return null;if(ri>=l)return{nx:1,ny:0,penetration:c};const d=Math.sqrt(l);return{nx:s/d,ny:a/d,penetration:c-d}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return fi(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);if("circle"===e.shape.type&&"aabb"===t.shape.type){const n=mi(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height);return n?{nx:-n.nx,ny:-n.ny,penetration:n.penetration}:null}return"aabb"===e.shape.type&&"circle"===t.shape.type?mi(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function gi(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?mi(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):fi(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,i,o,r,s,a=0){const c=r-i,l=s-o,d=c*c+l*l,u=d>ri?li(((e-i)*c+(t-o)*l)/d,0,1):0,h=n+a/2,p=e-(i+c*u),f=t-(o+l*u),m=p*p+f*f;if(m>=h*h)return null;if(ri>=m){const e=Math.sqrt(d);return e>ri?{nx:-l/e,ny:c/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(m);return{nx:p/y,ny:f/y,penetration:h-y}}(e.x,e.y,"circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2,n.x1,n.y1,n.x2,n.y2,n.thickness??0)}function bi(e,t){return`${e}\0${t}`}function xi(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function vi(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,shape:ai(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function wi(e){return e&&"function"!=typeof e?{property:e.property,equals:e.equals,notEquals:e.notEquals,oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function ki(e){return{id:e.id,shape:ci(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:wi(e.bodyFilter),index:e.index}}function Mi(e,t){return!!t?.some(t=>Object.is(e,t))}function Si(e,t){const n=e.bodyFilter;if(!n)return!0;if("function"==typeof n)return n(t);const i=function(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(t,n.property);return!("equals"in n&&!Object.is(i,n.equals)||"notEquals"in n&&Object.is(i,n.notEquals)||n.oneOf&&!Mi(i,n.oneOf)||n.notOneOf&&Mi(i,n.notOneOf))}var Ii=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={...oi,...e},this.random=ii(this.options.seed)}init(e={}){this.options={...oi,...e},this.random=ii(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){const t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(ri,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:ai(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(const t of e){this.bodies.delete(t);for(const e of Array.from(this.activeSensors))xi(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const t of e)this.colliders.set(t.id,{...t,shape:ci(t.shape),bodyFilter:wi(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){const t=e.id??"spring-"+this.nextSpringIndex;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,n){const i=this.bodies.get(e);i&&(i.vx+=t/i.mass,i.vy+=n/i.mass,this.wake(i))}step(e=this.options.fixedDt){const t=Math.max(0,e);if(this.lastEvents=[],0===t)return;const n=this.sortedBodies();for(const e of n)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);const i=this.options.maxVelocity;for(const e of n)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=this.options.velocityDamping,e.vy*=this.options.velocityDamping,i>0){const t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>i){const n=i/t;e.vx*=n,e.vy*=n}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear();const o=this.bodyPairKeys(n),r=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,o,0===e),this.resolveColliders(n,r,0===e);this.updateSensors(n),this.updateSleeping(n,t)}settle(e=1200,t=this.options.fixedDt){let n=0;for(;e>n&&!this.allSleeping();)this.step(t),n+=1;return n}readState(e=[]){e.length=0;for(const t of this.sortedBodies())e.push({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:ai(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(xi)}allSleeping(){for(const e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(vi),colliders:this.sortedColliders().map(ki),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=ii(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=vi(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=ki(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(const t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});const e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(const t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){const n=this.bodies.get(t.bodyId);if(!n||n.sleeping)continue;const i="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!i)continue;const o=i.x-n.x,r=i.y-n.y,s=Math.sqrt(o*o+r*r);if(ri>=s)continue;const a=o/s,c=r/s,l=(s-t.restLength)*t.stiffness+((("vx"in i?i.vx:0)-n.vx)*a+(("vy"in i?i.vy:0)-n.vy)*c)*t.damping;n.vx+=l*a*e/n.mass,n.vy+=l*c*e/n.mass}}resolveBodyPairs(e,t,n){for(const i of t){const[t,o]=i.split(":").map(Number),r=e[t],s=e[o];if(!r||!s)continue;const a=yi(r,s);a&&(this.resolveDynamicCollision(r,s,a),n&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(e){const t=Math.max(1,this.options.cellSize),n=new Map;for(let i=0;e.length>i;i+=1){if(!1===e[i].bodyCollisions)continue;const o=ui(e[i]),r=Math.floor(o.minX/t),s=Math.floor(o.maxX/t),a=Math.floor(o.minY/t),c=Math.floor(o.maxY/t);for(let e=r;s>=e;e+=1)for(let t=a;c>=t;t+=1){const o=`${e}:${t}`,r=n.get(o);r?r.push(i):n.set(o,[i])}}const i=new Set;for(const t of Array.from(n.keys()).sort()){const o=n.get(t)??[];o.sort((e,t)=>e-t);for(let t=0;o.length>t;t+=1)for(let n=t+1;o.length>n;n+=1){const r=o[t],s=o[n];!1!==e[r].bodyCollisions&&!1!==e[s].bodyCollisions&&pi(ui(e[r]),ui(e[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((e,t)=>{const[n,i]=e.split(":").map(Number),[o,r]=t.split(":").map(Number);return n===o?i-r:n-o})}resolveDynamicCollision(e,t,n){e.sleeping&&this.supportedThisStep.add(t.id),t.sleeping&&this.supportedThisStep.add(e.id);const i=e.sleeping?0:1/e.mass,o=t.sleeping?0:1/t.mass,r=i+o;if(ri>=r)return;const s=Math.max(0,n.penetration-si)/r;e.x-=n.nx*s*i,e.y-=n.ny*s*i,t.x+=n.nx*s*o,t.y+=n.ny*s*o;const a=(t.vx-e.vx)*n.nx+(t.vy-e.vy)*n.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution))*a/r,d=l*n.nx,u=l*n.ny;e.vx-=d*i,e.vy-=u*i,t.vx+=d*o,t.vy+=u*o,this.applyFriction(e,t,n,l,i,o),c>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,i,o,r){const s=-n.ny,a=n.nx,c=(t.vx-e.vx)*s+(t.vy-e.vy)*a,l=o+r;if(ri>=Math.abs(c)||ri>=l)return;const d=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction))),u=li(-c/l,-i*d,i*d),h=u*s,p=u*a;e.vx-=h*o,e.vy-=p*o,t.vx+=h*r,t.vy+=p*r}resolveColliders(e,t,n){for(const i of e)for(const e of t){if(!Si(e,i))continue;if(!pi(ui(i),hi(e)))continue;const t=gi(i,e);t&&(this.resolveStaticCollision(i,e,t),this.supportedThisStep.add(i.id),n&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:e.id,sensor:!1}))}}resolveStaticCollision(e,t,n){e.x+=n.nx*Math.max(0,n.penetration-si),e.y+=n.ny*Math.max(0,n.penetration-si);const i=e.vx*n.nx+e.vy*n.ny;if(0>i){const o=Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution);e.vx-=(1+o)*i*n.nx,e.vy-=(1+o)*i*n.ny;const r=-n.ny,s=n.nx,a=e.vx*r+e.vy*s,c=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction)));e.vx-=a*r*c,e.vy-=a*s*c}}updateSensors(e){const t=new Set,n=this.sortedColliders().filter(e=>e.sensor);for(const i of e){const e=ui(i);for(const o of n){if(!Si(o,i))continue;if(!pi(e,hi(o)))continue;if(!gi(i,o))continue;const n=bi(o.id,i.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:o.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:i}=xi(e);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:n})}this.activeSensors=t}updateSleeping(e,t){const n=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of e)Math.sqrt(i.vx*i.vx+i.vy*i.vy)>=this.options.sleepSpeed||Math.sqrt((i.x-i.prevX)*(i.x-i.prevX)+(i.y-i.prevY)*(i.y-i.prevY))>=this.options.sleepSpeed*t||n&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=t,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Ai=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Ii).capabilities,engine:"builtin"},this.world=new Ii(e)}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Ci(e={}){return new Ai(e)}function Ri(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):Ci(t)}var Di=["binId","targetBin","category","windowIndex","lane","group"];function Pi(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);const n=t-e.mean;e.mean+=n/e.count,e.m2+=n*(t-e.mean)}function $i(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Bi(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:1/0,max:e.count>0?e.max:-1/0}}function ji(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Ti(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?ji(t,e):void 0}function Ni(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function Wi(e){const t=$i(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:$i(e.x),y:$i(e.y),value:t}}var Ei=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;const t=this.nextIndex;this.nextIndex+=1;const n=Ni(Ti(this.config.binAccessor,e,t))??function(e){for(const t of Di){const n=Ni(ji(e,t));if(n)return n}return"sediment"}(e),i=Ni(Ti(this.config.labelAccessor,e,t))??n,o=function(e,t,n){if("number"==typeof e)return e;const i="function"==typeof e?e(t,n):"string"==typeof e?ji(t,e):1,o="number"==typeof i?i:Number(i);return Number.isFinite(o)?o:1}(this.config.valueAccessor,e,t),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(n);return s||(s={id:n,label:i,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(n,s)),s.label=i,s.lastBodyId=e.id,s.lastDatum=e.datum,Pi(s.x,e.x),Pi(s.y,e.y),Pi(s.value,o),r>0&&(s.bodyIds.push(e.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Wi(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Wi)}restore(e=[]){this.bins.clear();for(const t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Bi(t.x),y:Bi(t.y),value:Bi(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){const e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function zi(e,t={}){const{baselineY:n=0,binWidth:i=24,gap:o=2,maxHeight:r=80,value:s="count",x:a}=t,c=Math.max(1,...e.map(e=>e[s]));return e.map((e,t)=>{const l=Math.max(0,e[s]/c*r),d=a?.(e,t)??t*(i+o);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:d,y:n-l,width:i,height:l,meanX:e.x.mean,meanY:e.y.mean}})}function Oi(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}function Fi(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),i=t+n,o=Oi(e.bodyLimit),r=Oi(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const i=Oi(n?.warnAt);return null!=i?i:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(o,r,e.options),a=null==o?0:Math.max(0,t-o),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:o,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:i,queuedBodies:n,state:c,warnAt:s}}var Li={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},qi={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Yi(e={},t=qi){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function Hi(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Gi(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:void 0}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Xi(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function _i(e){return{...Hi(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Vi(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function Ui(e){return!1!==e&&{...e}}function Ki(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function Qi(e){return{...e,gravity:{...e.gravity}}}function Zi(e,t,n,i){if("circle"===e.shape.type){const o=e.x-t,r=e.y-n,s=e.shape.radius+i,a=o*o+r*r;return a>s*s?null:a}const o=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),r=Math.max(Math.abs(n-e.y)-e.shape.height/2,0),s=o*o+r*r;return s>i*i?null:s}function Ji(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function eo(e,t={}){const{idPrefix:n="plot",includeFloor:i=!0,includeCeiling:o=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=t,l=[],d=e.x+e.width/2,u=e.y+e.height/2;return i&&l.push({id:n+"-floor",shape:{type:"aabb",x:d,y:e.y+e.height+c/2,width:e.width+2*a,height:c}}),o&&l.push({id:n+"-ceiling",shape:{type:"aabb",x:d,y:e.y-c/2,width:e.width+2*a,height:c}}),r&&l.push({id:n+"-left-wall",shape:{type:"aabb",x:e.x-a/2,y:u,width:a,height:e.height+2*c}}),s&&l.push({id:n+"-right-wall",shape:{type:"aabb",x:e.x+e.width+a/2,y:u,width:a,height:e.height+2*c}}),l}function to(e){const{idPrefix:t="bin",count:n,domainStart:i,domainStep:o,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:d=!0,closedBefore:u,lidY:h=s,lidThickness:p=Math.max(2,c)}=e,f=[],m=s+(a-s)/2,y=Math.abs(a-s),g=l?n:n-1;if(d||l)for(let e=l?0:1;g>=e;e+=1){if(!d&&e>0&&n>e)continue;const s=r(i+e*o);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:m,width:c,height:y}})}if(null!=u)for(let e=0;n>e;e+=1){const n=i+e*o,s=n+o;if(s>=u)continue;const a=r(n),l=r(s);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:p}})}return f}var no={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function io(e,t){const n={...e};for(const e of t)n[no[e]]++;return n}function oo(e,t,n){const i=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:i,revisions:io(n,i)}}var ro=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=oo({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){const n=oo(e,t,this.revisions);this.revisions=n.revisions,this.latest=n;for(const e of[...this.listeners])e();return n}};import{quadtree as so}from"d3-quadtree";var ao=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,i,o,r=0){const s=this.ensure(e,t);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,d=i-l,u=i+l,h=o-l,p=o+l;return s.visit((e,t,s,l,f)=>{if(d>l||t>u||h>f||s>p)return!0;if(e.length)return!1;let m=e;for(;m;){const e=m.data;if(e){const t=Zi(e,i,o,Math.max(0,r));null!=t&&(c>t||t===c&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,c=t)}m=m.next}return!1}),a}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;const n=e.readState();return 0===n.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=n.reduce((e,t)=>Math.max(e,function(e){return"circle"===e.shape.type?e.shape.radius:Math.hypot(e.shape.width,e.shape.height)/2}(t)),0),this.tree=so().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},co=["data","scene-geometry","data-paint","accessibility","evidence"],lo=["scene-geometry","data-paint","accessibility","evidence"],uo=["overlay","accessibility","evidence"],ho=(e,t)=>({retainedData:e,invalidations:t}),po=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],fo=["scene-geometry","data-paint","accessibility","evidence"],mo=[],yo={engine:ho("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:ho("preserve",fo),colliders:ho("preserve",fo),sediment:ho("preserve",fo),bodyBudget:ho("preserve",po),bodyLimit:ho("preserve",po),eviction:ho("preserve",po),fixedDt:ho("preserve",mo),maxDeltaSeconds:ho("preserve",mo),maxSubsteps:ho("preserve",mo),settleStepLimit:ho("preserve",mo),timeScale:ho("preserve",mo),observation:ho("preserve",mo)},go=ho("preserve",po);function bo(e){let t="preserve";const n=new Set;for(const i of e){const e=yo[i]??go;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}var xo=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function vo(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&xo.every(n=>e[n]===t[n])}function wo(e,t,n,i){return e||!t?"paused":n||!i?"running":"settled"}var ko=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new ao,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new ro,this.simulationState="settled",this.visible=!0;const{bodyBudget:t,colliders:n,engine:i,kernel:o,observation:r,sediment:s,...a}=e;this.config={...Li,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=i,this.observation=Yi(r),this.sediment=new Ei(s??!1),this.world=Ri(i,{fixedDt:this.config.fixedDt,...o}),n&&this.world.setColliders(Vi(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!vo(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:i,engine:o,kernel:r,observation:s,sediment:a,...c}=e;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),o&&o!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=o,this.world=Ri(o,e.options),this.world.restore(e),this.revision+=1}if(r&&!vo(r,this.configInput.kernel)){const e=this.world.snapshot(),t={...e.options,...r,gravity:{...e.options.gravity,...r.gravity}};this.world.restore({...e,options:t}),this.revision+=1}s&&(this.observation=Yi(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(Vi(n)),this.revision+=1),this.configInput={...this.configInput,...e};const l=bo(t);this.updateResults.record({kind:"config",keys:t},l.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Vi(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},bo(["colliders"]).invalidations)}enqueue(e,t){const n=Array.isArray(e)?e:[e],i=t?function(e,t={}){const n=Gi(t.startAt)??0,i=t.pacing??"immediate";if("arrival"===i){const i=e.map((e,n)=>function(e,t,n){return"function"==typeof n?Gi(n(e,t)):"string"==typeof n?Gi(Xi(e,n)):Gi(e.spawnAt)??Gi(Xi(e,"arrivalTime"))??Gi(Xi(e,"timestamp"))??Gi(Xi(e,"time"))??Gi(Xi(e,"eventTime"))}(e,n,t.timeAccessor)),o=i.filter(e=>null!=e),r=o.length>0?Math.min(...o):0,s=Gi(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const o=i[t],s=null==o?0:Math.max(0,o-r);return{...Hi(e),spawnAt:n+s/a}})}if("object"==typeof i){const t=Gi(i.ratePerSec);if(t&&t>0)return e.map((e,i)=>({...Hi(e),spawnAt:n+i/t}))}return e.map(e=>({...Hi(e),spawnAt:n}))}(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of i)this.queue.push({...Hi(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Ki),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?co:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Hi(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},co)}clear(){const e=this.world.snapshot().options;this.world.init({...e,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},co)}tick(e){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}const a=Math.max(0,Math.min(e,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(n,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),o.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let d=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>d;){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,d+=1}d===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(d>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const u=this.result(d,n,i,o,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:d},this.revision!==t?n.length||i.length||o.length?co:lo:[]),u}settle(e=this.config.settleStepLimit){const t=this.revision;this.spawnDue([],[]);const n=this.world.settle(e,this.config.fixedDt);return n>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:n},this.revision!==t?lo:[]),n}settleWithObservations(e=this.config.settleStepLimit){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,r,s,!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,s);const a=this.observeBodyBudget(s),c=this.evictOverflow(s);i.push(...c.evicted),o.push(...c.sedimented),this.syncSimulationState(s);let l=0;for(;e>l&&!this.world.allSleeping();){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),l+=1}(l>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const d=this.result(l,n,i,o,r,s,void 0,a);return this.updateResults.record({kind:"settle",count:l},this.revision!==t?n.length||i.length||o.length?co:lo:[]),d}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return zi(this.readSediment(),e)}hitTest(e,t,n=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}hasPendingWork(){return this.queue.length>0||!this.world.allSleeping()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){const{timestamp:t,chartType:n,chartId:i,...o}=e,r={...o,timestamp:t??this.elapsedSeconds,chartType:n??this.observation.chartType,chartId:i??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?uo:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?uo:[])}remove(e){const t=new Set(e),n=new Set(this.liveBodyOrder),i=new Set(this.queue.map(e=>e.id));this.queue=this.queue.filter(e=>!t.has(e.id)),this.liveBodyOrder=this.liveBodyOrder.filter(e=>!t.has(e)),this.world.remove(e),this.removeActiveSensorPairsForBodies(t);const o=e.filter(e=>n.has(e)||i.has(e));return o.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:o,count:o.length},o.length?co:[]),o}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},lo),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},lo)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},lo)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,n,i)=>e.applyImpulse(t,n,i),clear:()=>e.clear(),hitTest:(t,n,i)=>e.hitTest(t,n,i),pause:()=>e.setPaused(!0),push:(t,n)=>e.enqueue(t,n),pushMany:(t,n)=>e.enqueue(t,n),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}snapshot(){const e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Ui(this.bodyBudget),config:{...this.config,kernel:Qi(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(_i),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.config={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale},this.configInput={...e.config,bodyBudget:Ui(e.bodyBudget??{}),kernel:Qi(e.world.options)},this.bodyBudget=Ui(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(_i).sort(Ki),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??wo(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping)),this.liveBodyOrder=e.liveBodyOrder.slice(),this.visible=e.visible,this.nextSequence=this.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,this.world.restore(e.world),this.updateResults.record({kind:"restore"},co)}spawnDue(e,t){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const n=this.queue.shift();if(!n)return;this.spawnOne(n,t),e.push(n.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(const t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});const n=this.world.readState().find(t=>t.id===e.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:e.id,datum:n?.datum??e.datum,x:n?.x??e.x,y:n?.y??e.y},t)}result(e,t,n,i,o,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:o,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!c),sleeping:c,sedimented:i,spawned:t,steps:e}}observeKernelEvents(e,t){!function(e,t,n){if(0===t.length)return;const i=new Map(e.readState().map(e=>[e.id,e]));for(const e of t){if("sleep"!==e.type)continue;const t=i.get(e.bodyId);n.emit({type:"physics-settle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,n){const i=new Set(e.activeSensorPairs().map(e=>`${e.sensorId}\0${e.bodyId}`));if(0===i.size&&0===t.size)return i;const o=new Map(e.readState().map(e=>[e.id,e])),r=(e,t)=>{const{sensorId:i,bodyId:r}=Ji(t),s=n.observation.sensors[i],a=o.get(r);n.emit({type:"enter"===e?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:i,binId:s?.binId??i})};for(const e of Array.from(i).sort())t.has(e)||r("enter",e);for(const e of Array.from(t).sort())i.has(e)||r("exit",e);return i}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(Ji(n).bodyId)&&e.delete(n)}(this.activeSensorPairs,e)}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return Fi({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){const t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;const n=`${t.state}:${t.action}`;return n===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=n,this.emitObservation({type:"overflow"===t.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:t.action,bodyLimit:t.bodyLimit,engineMaxBodiesHint:t.engineMaxBodiesHint,liveBodies:t.liveBodies,overflow:t.overflow,projectedBodies:t.projectedBodies,queuedBodies:t.queuedBodies,warnAt:t.warnAt},e)),t}syncSimulationState(e){const t=wo(this.paused,this.visible,this.queue.length>0,this.world.allSleeping());if(t===this.simulationState)return;const n=this.simulationState;this.simulationState=t,function(e,t,n){n.observation.onSimulationStateChange?.(t,e),"running"!==t&&"settled"!==t||n.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,simulationState:t,previousSimulationState:e})}(n,t,this.observationContext(e))}evictOverflow(e){if(!1===this.config.eviction)return{evicted:[],sedimented:[]};const t=Math.max(0,Math.floor(this.config.bodyLimit));if(!Number.isFinite(t))return{evicted:[],sedimented:[]};const n=this.liveBodyOrder.length-t;if(0>=n)return{evicted:[],sedimented:[]};const i=("sleeping-first"===this.config.eviction?this.sleepingFirstEvictionOrder():this.liveBodyOrder.slice()).slice(0,n);if(0===i.length)return{evicted:[],sedimented:[]};const o=this.absorbSediment(i,e);this.world.remove(i);const r=new Set(i);return this.liveBodyOrder=this.liveBodyOrder.filter(e=>!r.has(e)),this.removeActiveSensorPairsForBodies(r),{evicted:i,sedimented:o}}absorbSediment(e,t){const n=new Map(this.world.readState().map(e=>[e.id,e])),i=[];for(const o of e){const e=n.get(o);if(!e)continue;const r=this.sediment.add(e);r&&(i.push(o),this.emitObservation({type:"physics-sediment",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:o,datum:e.datum,x:e.x,y:e.y,binId:r.id,count:r.count,total:r.total},t))}return i}sleepingFirstEvictionOrder(){const e=new Map(this.world.readState().map(e=>[e.id,e.sleeping])),t=[],n=[];for(const i of this.liveBodyOrder)e.get(i)?t.push(i):n.push(i);return[...t,...n]}};function Mo(e,t,n){const i=new ko(e);return t?.length&&i.enqueue(t,n),i}function So(){return"undefined"!=typeof performance?performance.now():Date.now()}import*as Io from"react-dom/server";function Ao(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var Co={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Ro(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Do(e,t){const n="function"==typeof t?t(e):t;return{...Co,...n??{}}}function Po(e,t={}){const n=e.settle(t.maxSteps),i=e.readBodies(),o=e.snapshot(),r=function(e,t={}){return e.map(e=>function(e,t={}){const n=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),i={label:t.getBodyLabel?.(e)??Ro(e)},o={style:Do(e,t.bodyStyle),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}(e,t))}(i,t),s=function(e,t={}){const n=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),i=n.filter(e=>e.sleeping).length;return{bodyCount:n.length,sleepingCount:i,settled:"settled"===e.simulationState&&0===e.queue.length&&i===n.length,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:Ao(t.projectionRows)}}(o,{bodies:i,projectionRows:t.projectionRows,stepsRun:n});return{snapshot:o,bodies:i,sceneNodes:r,evidence:s,stepsRun:n}}import{jsx as $o,jsxs as Bo}from"react/jsx-runtime";function jo(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const i=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(i)&&i>0?i:1}function To(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=Wo(e.datum,t),i=Wo(e,t),o=n??i;if(null!=o&&(o+"").length>0)return o+""}return e.id}function No(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),i=Math.floor(n);return e[i]+(e[Math.ceil(n)]-e[i])*(n-i)}function Wo(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}function Eo(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Wo(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function zo(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),i=e.queueLayout??"lane",o=e.queueSlotSpacing??14,r=e.queueStiffness??.35,s=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,a=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},d=new Map,u=new Map,h=new Map,p=new Map,f=new Map,m=new Map,y=new Map,g=[];let b=0,x=new Map,v=new Map,w=0,k=0,M=0,S=null,I=0,A=0,C=0,R=0,D=0,P=0,$=0,B=0,j=0,T=0,N=0,W=0,E=-1,z=!1;function O(e,n){const i=n(e);return!!i&&i.activeRegionIds.includes(t)}function F(){W+=1}function L(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function q(n,i,o,r){const s={bodyId:n.id,jobId:i.jobId,visitId:i.visitId,visit:i.visit,remaining:i.work,total:i.work,queuedAt:i.queuedAt,sequence:r};return d.set(i.jobId,s),y.delete(n.id),m.set(n.id,i.jobId),A+=1,C+=i.work,F(),function(n,i,o){const r=L(i);e.onQueued?.(n,r),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:i.total,jobId:i.jobId,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,queueDepth:d.size})}(n,s,o),s}function Y(e){if(d.size>=s||0===u.size)return;const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(d.size>=s)break;const t=f.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),y.delete(n.bodyId),q(t,n,e,n.sequence)):u.delete(n.jobId)}}function H(){let e=0;for(const t of d.values())e+=t.remaining;return e}function G(){j=Math.max(j,d.size),T=Math.max(T,H())}function X(){const e=M-a,t=Math.max(0,Math.min(a,M-(S??M)));let i=0,o=0,r=0,s=0,c=0;for(const t of g){if(e>t.end)continue;i+=t.arrivals,o+=t.arrivalWork,r+=t.completions,s+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?o/t:0;return{seconds:t,arrivals:i,arrivalWork:o,completions:r,completedWork:s,processedWork:c,arrivalsPerSecond:t>0?i/t:0,throughputPerSecond:t>0?r/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:i=>{const o=i.controls.readBodies(),r=new Map,A=new Map;for(const t of o){if(r.set(t.id,t),!O(t.id,i.getRegionState))continue;if(!Eo(t,e.bodyFilter))continue;const n=To(t,e.jobKey),o=A.get(n)??[];o.push(t),A.set(n,o)}const C=Number.isFinite(i.dt)?Math.max(0,i.dt):0;if(!z){const e=Number.isFinite(i.elapsed)?Math.max(0,i.elapsed):C;M=Math.max(0,e-C),z=!0}const j=M,T=j+C;M=T,S=null==S?j:Math.min(S,j);const W={start:j,end:T,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},H=new Map;for(const[e,t]of A){const n=h.get(e)?.bodyId,i=t.find(e=>e.id===n)??t[0];H.set(e,i),f.set(e,i)}for(const[n,o]of h){if(H.has(n))continue;const s=d.get(n),a=r.get(o.bodyId)??f.get(n);if(s){d.delete(n),m.delete(s.bodyId),$+=1,B+=s.remaining,F();const r={...L(s),abandonedAt:M,remainingWork:s.remaining,queueSeconds:Math.max(0,M-s.queuedAt)};a&&e.onAbandoned?.(a,r),i.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:a?.datum,x:a?.x,y:a?.y,regionId:t,work:s.total,remainingWork:s.remaining,jobId:n,visitId:s.visitId,visit:s.visit,queuedAt:s.queuedAt,abandonedAt:M,queueSeconds:r.queueSeconds,queueDepth:d.size})}u.delete(n),y.delete(o.bodyId),h.delete(n),f.delete(n)}for(const[n,o]of H){if(h.has(n))continue;const r=(p.get(n)??0)+1;p.set(n,r);const a=jo(o,e.unitAccessor),c={bodyId:o.id,jobId:n,visitId:`${t}:${n}:${r}`,visit:r,regionId:t,work:a,queuedAt:M};h.set(n,c),I+=1,W.arrivals+=1,W.arrivalWork+=a;const l=b++;if(s>d.size)q(o,c,i,l);else{const s={...c,blockedAt:M,sequence:l};u.set(n,s),y.set(o.id,n),P+=1,F(),e.onBlocked?.(o,s),i.controls.recordObservation({type:"physics-capacity-blocked",bodyId:o.id,datum:o.datum,x:o.x,y:o.y,regionId:t,work:a,jobId:n,visitId:c.visitId,visit:r,queuedAt:M,blockedAt:M,queueDepth:d.size,blockedDepth:u.size})}}Y(i),G();const X=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);let _=n*C;for(const n of X){if(0>=_)break;const o=Math.min(n.remaining,_);if(n.remaining-=o,_-=o,R+=o,W.processedWork+=o,n.remaining>1e-6)continue;d.delete(n.jobId),m.delete(n.bodyId),k+=1,D+=n.total,W.completions+=1,W.completedWork+=n.total;const s=Math.max(0,M-n.queuedAt);N+=s,F();const a=r.get(n.bodyId);if(!a)continue;i.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...L(n),completedAt:M,queueSeconds:s};e.onProcessed?.(a,c),i.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:a.datum,x:a.x,y:a.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:M,queueSeconds:s,queueDepth:d.size})}Y(i),G(),function(){const e=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);x=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);v=new Map(t.map((e,t)=>[e.bodyId,t])),w=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&g.push(e);const t=M-a;for(;g.length>0&&t>g[0].end;)g.shift()}(W);const V=Math.floor(M/c);V!==E&&(E=V,F())},getSnapshot:()=>{const e=H(),i=function(){let e=0;for(const t of u.values())e+=t.work;return e}(),o=d.size,r=Array.from(d.values()).map(e=>Math.max(0,M-e.queuedAt)).sort((e,t)=>e-t),s=r.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:o,processedCount:k,unitsPerSecond:n,remainingWork:e,meanRemainingWork:o>0?e/o:0,waitingWork:e+i,blockedDepth:u.size,blockedWork:i,arrivalCount:I,admittedCount:A,admittedWork:C,processedWork:R,completedWork:D,blockedCount:P,abandonedCount:$,abandonedWork:B,peakQueueDepth:j,peakRemainingWork:T,queueAge:{count:r.length,meanSeconds:r.length>0?s/r.length:0,p50Seconds:No(r,.5),p95Seconds:No(r,.95),oldestSeconds:r.at(-1)??0},meanCompletedQueueSeconds:k>0?N/k:0,window:X(),simulatedAt:M,metricRevision:W}},bodyForce:e=>{if("none"===i)return null;const n=m.get(e.body.id),s=y.get(e.body.id),a=n?d.get(n):void 0,c=s?u.get(s):void 0;if(!a&&!c)return null;const l=a?x.get(e.body.id):v.get(e.body.id);if(null==l)return null;let h;const p=e.regions;if(p)for(let e=0;p.length>e;e+=1)if(p[e].id===t){const t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*o))-e.body.x)*r,y:(h.y-(l-((c?u.size:w)-1)/2)*o/Math.max(1,Math.sqrt(c?u.size:w))-e.body.y)*r*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function Oo(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}function Fo(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Oo(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function Lo(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),i=new Map,o=new Map,r=e.assignmentForce??.45,s=e.returnForce??.35,a=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,d=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=i.get(e);if(n)return n;const r=t.find(e=>!o.has(e.id));if(!r)return null;const s={resourceId:r.id,resourceBodyId:r.bodyId,caseBodyId:e,assignedAt:d};return i.set(e,s),o.set(r.id,s),u+=1,s},release:e=>{const t=i.get(e);return!!t&&(i.delete(e),o.delete(t.resourceId),u+=1,!0)},getAssignment:e=>i.get(e),tick:e=>{d=Math.max(d,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of i)l.has(e)&&l.has(t.resourceBodyId)||(i.delete(e),o.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(i.values()),simulatedAt:d,metricRevision:u}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=o.get(t.id),i=n?l.get(n.caseBodyId):void 0,a=n?r:s;return{x:((i?i.x+(c.x??0):t.home.x)-e.body.x)*a,y:((i?i.y+(c.y??0):t.home.y)-e.body.y)*a}}const d=i.get(e.body.id);if(!d||0>=a)return null;const u=l.get(d.resourceBodyId);return u?{x:(u.x-e.body.x)*a,y:(u.y-e.body.y)*a}:null}}}function qo(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):Oo(e.datum,t.deadlineAccessor)??Oo(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function Yo(e){const t=new Map;let n=0,i=0;function o(n){t.set(n.bodyId,n),i+=1,e.onStateChange?.({...n})}function r(e){const i=t.get(e);return!(!i||null!=i.completedAt||(o({...i,completedAt:n,state:"unhappy"===i.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const i=t.get(e);return!(!i||null!=i.completedAt||"unhappy"===i.state||(o({...i,state:"protected",protectedAt:n}),0))},complete:r,getCase:e=>t.get(e),tick:i=>{n=Math.max(n,i.elapsed);for(const s of i.controls.readBodies()){if(!Fo(s,e.bodyFilter))continue;if(!t.has(s.id)){const t=qo(s,e);o({bodyId:s.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const a=t.get(s.id);a&&null==a.completedAt&&(e.completionRegionId&&i.getRegionState(s.id)?.activeRegionIds.includes(e.completionRegionId)?r(s.id):"waiting"!==a.state||a.deadlineAt>n||o({...a,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),o=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:o("waiting"),protected:o("protected"),unhappy:o("unhappy"),resolved:o("resolved"),resolvedUnhappy:o("resolved-unhappy"),simulatedAt:n,metricRevision:i}}}}function Ho(e){const t=new Set;let n=0,i=0,o=0,r=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:s=>{n=Math.max(n,s.elapsed);const a=r;var c;c=n,r=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=s.controls.readBodies(),d=new Map(l.map(e=>[e.id,e]));for(const n of l){const i=s.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);i&&Fo(n,e.bodyFilter)&&(r||t.has(n.id)||(t.add(n.id),o+=1,e.onHeld?.(n)))}if(r&&!a){for(const n of t){const t=d.get(n);t&&(s.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),i+=1,e.onReleased?.(t))}t.clear(),o+=1}for(const e of t)d.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:r,blocked:t.size,released:i,simulatedAt:n,metricRevision:o}),bodyForce:n=>{if(r||!t.has(n.body.id))return null;const i=n.regions?.find(t=>t.id===e.regionId),o=i?.shape;if(!o||"aabb"!==o.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const s=e.holdForce??.4;return{x:(o.x-n.body.x)*s-.45*n.body.vx,y:(o.y-n.body.y)*s-.45*n.body.vy}}}}function Go(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Xo(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,i)=>{const o={result:e,controls:n,dt:i.dt,elapsed:i.elapsed,getRegionState:i.getRegionState};for(const e of t)e.tick(o)},bodyForce:e=>{let n=null;for(const i of t)i.bodyForce&&(n=Go(n,i.bodyForce(e)));return n}}}function _o(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:i=>{const o=i.controls.readBodies();for(const r of o){const o=i.getRegionState(r.id),s=o?.activeRegionIds.includes(e.fromRegionId);s?t.has(r.id)||(t.add(r.id),i.controls.applyImpulse(r.id,n.x??0,n.y??0),e.onPortal?.(r)):t.delete(r.id)}}}}import{useEffect as Vo,useRef as Uo}from"react";function Ko(){return"undefined"==typeof document||!document.hidden}import{jsx as Qo}from"react/jsx-runtime";var Zo="var(--semiotic-focus, #005fcc)";function Jo({active:e,hoverPoint:t,margin:n,size:i,shape:o="circle",width:r,height:s,pathData:a}){if(!e||!t)return null;const c=t.x+n.left,l=t.y+n.top;let d;if("geoarea"!==o&&"path"!==o||!a)if("rect"===o&&null!=r&&null!=s){const e=Math.max(r,4),t=Math.max(s,4);d=Qo("rect",{x:c-e/2-3,y:l-t/2-3,width:e+6,height:t+6,rx:3,fill:"none",stroke:Zo,strokeWidth:2,strokeDasharray:"4,2"})}else d=Qo("circle","wedge"===o?{cx:c,cy:l,r:12,fill:"none",stroke:Zo,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:c,cy:l,r:8,fill:"none",stroke:Zo,strokeWidth:2,strokeDasharray:"4,2"});else d=Qo("g",{transform:`translate(${n.left},${n.top})`,children:Qo("path",{d:a,fill:"none",stroke:Zo,strokeWidth:2.5,strokeDasharray:"6,3"})});return Qo("svg",{style:{position:"absolute",left:0,top:0,width:i[0],height:i[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:d})}import{memo as er,useEffect as tr,useRef as nr}from"react";var ir={sceneGeometry:0,layout:0,domain:0};function or(e){const{domain:t,layout:n,sceneGeometry:i}=e.revisions;return{domain:t,layout:n,sceneGeometry:i}}function rr(e,t){return{sceneGeometry:Math.max(e.sceneGeometry,t.sceneGeometry),layout:Math.max(e.layout,t.layout),domain:Math.max(e.domain,t.domain)}}var sr="production"!==process.env.NODE_ENV,ar={revisions:ir,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},cr=class{constructor(e="scene host"){this.hostName=e,this.lastConsumed=ir,this.lastObserved=ir,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(e){sr&&(this.lastObserved=rr(this.lastObserved,or(e)))}beforeCompute(e,t){if(!sr)return ar;const n=rr(or(e),this.lastObserved),i=function(e){return`${e.sceneGeometry}|${e.layout}|${e.domain}`}(n),o=!((r=n).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:n,signature:i,sawSignals:e.changed.has("scene-geometry")||e.changed.has("layout")||e.changed.has("domain"),wasUnconsumed:o,warnUnconsumed:!t&&o&&this.lastUnconsumedWarning!==i}}afterCompute(e,t,n){if(sr){if(t&&e.wasUnconsumed&&(this.lastConsumed=e.revisions),e.warnUnconsumed&&!t)return console.warn(`[semiotic] ${this.hostName} observed scene-affecting revisions without a scene rebuild: ${e.signature}.`),void(this.lastUnconsumedWarning=e.signature);t&&e.sawSignals&&!e.wasUnconsumed&&!n&&this.lastDuplicateWarning!==e.signature?(console.warn(`[semiotic] ${this.hostName} performed scene rebuild with unchanged scene revisions: ${e.signature}.`),this.lastDuplicateWarning=e.signature):t&&!e.sawSignals&&(this.lastDuplicateWarning="")}}},lr=er(function({store:e,diagnostics:t}){return tr(()=>{const n=()=>t.observeUpdateResult(e.getUpdateSnapshot());return n(),e.subscribeUpdateResult(n)},[t,e]),null});import*as dr from"react";import*as ur from"react";import{jsx as hr}from"react/jsx-runtime";var pr=ur.createContext(null);import{jsx as fr}from"react/jsx-runtime";var mr={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function yr({hoverPoint:e}){let t="";if(e){const n=e.data||e;t="object"==typeof n?"Data point: "+Object.entries(n).filter(([,e])=>"object"!=typeof e&&"function"!=typeof e).map(([e,t])=>`${e}: ${t}`).join(", "):"Data point: "+n}return fr("div",{"aria-live":"polite","aria-atomic":"true",style:mr,children:t})}import{jsx as gr,jsxs as br}from"react/jsx-runtime";function xr({summary:e}){return e?gr("div",{role:"note",style:mr,children:e}):null}function vr({tableId:e}){return gr("a",{href:"#"+e,style:mr,onClick:t=>{t.preventDefault();const n=document.getElementById(e);n&&requestAnimationFrame(()=>n.focus())},onFocus:e=>{Object.assign(e.currentTarget.style,{position:"absolute",width:"auto",height:"auto",overflow:"visible",clip:"auto",whiteSpace:"normal",padding:"4px 8px",background:"var(--semiotic-bg, #fff)",color:"var(--semiotic-text, #000)",border:"2px solid var(--semiotic-focus, #005fcc)",borderRadius:"4px",zIndex:"10",fontSize:"12px",top:"4px",left:"4px"})},onBlur:e=>{const t=e.currentTarget;t.removeAttribute("style"),Object.assign(t.style,mr)},children:"Skip to data table"})}import{curveMonotoneX as wr,curveMonotoneY as kr,curveCardinal as Mr,curveCatmullRom as Sr,curveStep as Ir,curveStepBefore as Ar,curveStepAfter as Cr,curveBasis as Rr,curveNatural as Dr}from"d3-shape";function Pr(e,t,n){if(null==t)return n;if(Ce(t)){const i=function(e,t){const n="undefined"!=typeof window&&window.devicePixelRatio||1,i=`${Re(e)}@${n}`,o=Pe.get(i);if(void 0!==o)return o;const r=function(e={},t){const{background:n="transparent",stroke:i="#000",lineWidth:o=1.5,spacing:r=6,angle:s=45}=e,a=Math.max(8,Math.ceil(2*r));let c;try{c=function(e){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(e,e):(Se||(Se=document.createElement("canvas")),Se.width=e,Se.height=e,Se)}(a)}catch{return null}const l=c.getContext("2d");if(!l)return null;n&&"transparent"!==n?(l.fillStyle=n,l.fillRect(0,0,a,a)):l.clearRect(0,0,a,a),l.strokeStyle=i,l.lineWidth=o,l.lineCap="square";const d=s*Math.PI/180;if(45===s||-45===s){const e=s>0?1:-1;for(let t=-a;2*a>=t;t+=r)l.beginPath(),l.moveTo(t,0),l.lineTo(t+e*a,a),l.stroke()}else{l.save(),l.translate(a/2,a/2),l.rotate(d);const e=2*a;for(let t=-e;e>=t;t+=r)l.beginPath(),l.moveTo(-e,t),l.lineTo(e,t),l.stroke();l.restore()}return(t||l).createPattern(c,"repeat")}({background:e.background,stroke:e.stroke,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle},t);return Pe.set(i,r),r}(t,e);return i||t.background&&X(e,t.background)||n}return"string"!=typeof t?t:X(e,t)||n}function $r(e,t,n){const i=function(e,t){if(null==t)return;const n=Pr(e,t,"");return""===n?void 0:n}(e,n.fill)??"#4e79a7",o=n.stroke,r=n.strokeWidth??0,s=n.opacity??1,a=n.fillOpacity??1,c=function(e,t){const n=t.mark;if(n)return n;const i=e.datum,o=i?.__physicsMark??i?.mark;return"circle"===o||"halo"===o||"faceted"===o||"pill"===o||"diamond"===o||"square"===o?o:"circle"===e.shape.type?"circle":"square"}(t,n),l="circle"===t.shape.type?n.r??t.shape.radius:Math.max(t.shape.width,t.shape.height)/2;if(e.save(),e.globalAlpha*=s,e.beginPath(),"pill"===c||"square"===c||"aabb"===t.shape.type){const n="pill"===c?2.4*l:"aabb"===t.shape.type?t.shape.width:1.7*l,i="pill"===c?1.35*l:"aabb"===t.shape.type?t.shape.height:1.7*l,o=t.x-n/2,r=t.y-i/2,s="pill"===c?i/2:Math.min(4,n/4);e.moveTo(o+s,r),e.arcTo(o+n,r,o+n,r+i,s),e.arcTo(o+n,r+i,o,r+i,s),e.arcTo(o,r+i,o,r,s),e.arcTo(o,r,o+n,r,s),e.closePath()}else if("diamond"===c)e.moveTo(t.x,t.y-l),e.lineTo(t.x+l,t.y),e.lineTo(t.x,t.y+l),e.lineTo(t.x-l,t.y),e.closePath();else if("faceted"===c){const n=6;for(let i=0;n>i;i+=1){const o=2*Math.PI*i/n-Math.PI/2,r=t.x+Math.cos(o)*l,s=t.y+Math.sin(o)*l;0===i?e.moveTo(r,s):e.lineTo(r,s)}e.closePath()}else e.arc(t.x,t.y,l,0,2*Math.PI);i&&(e.save(),e.globalAlpha*=a,e.fillStyle=i,e.fill(),e.restore()),"halo"===c&&(e.beginPath(),e.arc(t.x,t.y,1.35*l,0,2*Math.PI),e.strokeStyle=o??i,e.lineWidth=Math.max(1.5,r||1.5),e.globalAlpha*=.55,e.stroke(),e.globalAlpha/=.55),o&&r>0&&(e.strokeStyle=o,e.lineWidth=r,n.strokeDasharray&&e.setLineDash(n.strokeDasharray.split(/[,\s]+/).map(e=>Number(e)).filter(e=>Number.isFinite(e))),e.stroke()),e.restore()}function Br(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function jr(e){return e.sensorId??"stream-region-"+e.id}function Tr(e){const t=jr(e),n={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){const i=e.colliderThickness??8,o=e.shape.x-e.shape.width/2,r=e.shape.x+e.shape.width/2,s=e.shape.y-e.shape.height/2,a=e.shape.y+e.shape.height/2;return[{...n,id:t+"-top",shape:{type:"segment",x1:o,y1:s,x2:r,y2:s,thickness:i}},{...n,id:t+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...n,id:t+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:o,y2:a,thickness:i}},{...n,id:t+"-left",shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:i}}]}return e.collider?[{...n,id:t+"-collider",shape:e.shape}]:[]}function Nr(e){if(e)return{activeRegionIds:Array.from(e.activeRegionIds),regionIds:Array.from(e.regionIds),charges:{...e.charges},attributes:{...e.attributes},energy:e.energy}}function Wr(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}function Er(e){if(!1===e.semanticItem)return null;const t=e.shape,n=e.semanticItem??{},i="aabb"===t.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:t.x,y:t.y,width:t.width,height:t.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2,pathData:`M ${t.x1} ${t.y1} L ${t.x2} ${t.y2}`};return{...i,...n,id:n.id??i.id}}function zr(e){return e.some(e=>null!=e.force||null!=e.damping||null!=e.impulseOnEnter||null!=e.impulseOnExit)}function Or(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}var Fr=[];function Lr(e){const t=e.store.controls(),n=e.store.snapshot(),i=Math.max(0,e.result.steps*(n.config.fixedDt||1/60)),o=function(e,t,n,i){const o=Number.isFinite(i)?Math.max(0,i):0;if(0>=o||!zr(t))return!1;const r=new Map(t.map(e=>[e.id,e])),s=e.readBodies();let a=!1;for(const t of s){const i=n.get(t.id);if(!i||!i.activeRegionIds.size)continue;const s=Nr(i);if(s)for(const n of i.activeRegionIds){const i=r.get(n);if(!i)continue;const c=Wr(i.force,{body:t,region:i,regionState:s}),l=Number(i.damping??0),d=(c?.x??0)*o-(Number.isFinite(l)?t.vx*l*o:0),u=(c?.y??0)*o-(Number.isFinite(l)?t.vy*l*o:0);(d||u)&&(e.applyImpulse(t.id,d,u),a=!0)}}return a}(t,e.regionEffects,e.regionState,i),r=function(e,t,n,i,o,r){const s=Number.isFinite(r)?Math.max(0,r):0;if(0>=s||!t)return!1;const a=new Map(n.map(e=>[e.id,e])),c=e.readBodies();let l=!1;for(let n=0;c.length>n;n+=1){const r=c[n],d=i.get(r.id),u=Nr(d);let h=Fr;if(d&&d.activeRegionIds.size>0){const e=[];for(const t of d.activeRegionIds){const n=a.get(t);n&&e.push(n)}h=e}const p=Or(t,{body:r,bodies:c,index:n,regionState:u,regions:h,simulationState:o});if(!p)continue;const f=(p.x??0)*s,m=(p.y??0)*s;(f||m)&&(e.applyImpulse(r.id,f,m),l=!0)}return l}(t,e.bodyForces,e.regionEffects,e.regionState,n.simulationState,i);return e.composed&&e.composed.onTick(e.result,t,{dt:i,elapsed:e.result.elapsedSeconds,getRegionState:t=>Nr(e.regionState.get(t))}),e.onTick?.(e.result,t),{regionEffectsApplied:o,bodyForcesApplied:r,snapshot:n}}function qr(e,t,n,i,o,r,s,a,c,l){const d=function(e,t){return!!t?.isActive&&(t.predicate?.(e)??!0)}(e,o),u={selected:d,simulationState:t,regionState:r,regions:s},h="function"==typeof n?n(e,u):n,p=s.reduce((t,n)=>n.bodyStyle?{...t,..."function"==typeof n.bodyStyle?n.bodyStyle(e,u):n.bodyStyle}:t,{}),f=d?"function"==typeof i?i(e,u):i:void 0;return{fill:l?.color??a,stroke:l?.stroke??c,strokeWidth:l?.strokeWidth??1,opacity:l?.opacity??.9,...h,...p,...f}}import{useCallback as Yr}from"react";import*as Hr from"react";import{jsx as Gr,jsxs as Xr}from"react/jsx-runtime";var _r={border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},Vr="semiotic-accessible-data-table",Ur=Vr+" semiotic-accessible-data-table-hidden",Kr=Vr+" semiotic-accessible-data-table-visible",Qr={position:"absolute",top:0,left:0,right:0,zIndex:"var(--semiotic-data-table-z-index, var(--semiotic-overlay-z-index, 20))",padding:"14px 16px 12px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontFamily:"var(--semiotic-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif)",fontSize:13,lineHeight:1.5,color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",borderRadius:"var(--semiotic-border-radius, 0px) var(--semiotic-border-radius, 0px) 0 0"},Zr={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},Jr={position:"absolute",top:10,right:10,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",cursor:"pointer",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:13,lineHeight:1,padding:0,borderRadius:"var(--semiotic-border-radius, 4px)"},es={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},ts={textAlign:"left",padding:"5px 10px",borderBottom:"2px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))"},ns={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},is={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},os={marginTop:8,padding:"4px 10px",fontSize:12,cursor:"pointer",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",borderRadius:"var(--semiotic-border-radius, 4px)",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",fontFamily:"inherit"};function rs(e){return null==e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e?e+"":null}function ss(e){return{__semioticHoverData:!0,body:e,data:e.datum??e,id:e.id,type:"body",x:e.x,y:e.y}}function as(e){if("circle"===e.shape.type){const t=Math.max(4,2*e.shape.radius);return{height:t,shape:"circle",width:t}}return{height:e.shape.height,shape:"rect",width:e.shape.width}}function cs(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return e+""}return e.id}function ls(e){const t=ds(e.datum??e);return t.length?t.map(([e,t])=>`${e}: ${t}`).join(", "):"Physics body "+e.id}function ds(e){return e&&"object"==typeof e?Object.entries(e).map(([e,t])=>{if(e.startsWith("_"))return null;const n=rs(t);return null==n?null:[e,n]}).filter(e=>null!=e).slice(0,8):[]}function us({hover:e}){const t=ds(e.data);return Xr("div",{className:"semiotic-tooltip",style:He,children:[Gr("div",{style:{fontWeight:700,marginBottom:t.length?4:0},children:e.id}),t.map(([e,t])=>Xr("div",{children:[Xr("span",{style:{opacity:.72},children:[e,": "]}),Gr("span",{children:t})]},e))]})}function hs(e){return e.datum&&"object"==typeof e.datum?Object.entries(e.datum).map(([e,t])=>{const n=rs(t);return null==n?null:`${e}: ${n}`}).filter(e=>null!=e).slice(0,8).join(", "):""}function ps(e){const t=[`${e.length} semantic item${1===e.length?"":"s"}.`],n=new Map;for(const t of e)t.group&&n.set(t.group,(n.get(t.group)??0)+1);return n.size&&t.push(Array.from(n).map(([e,t])=>`${e}: ${t}`).join(", ")),t.join(" ")}function fs(e){const{chartTitle:t,items:n,tableId:i}=e,[o,r]=Hr.useState(!1),[s,a]=Hr.useState(5),c=ur.useContext(pr),l=c?.visible??!1,d=o||l,u=Hr.useRef(null),h="Data summary for "+(t??"physics chart");Hr.useEffect(()=>{d||a(5)},[d]);const p=Hr.useCallback(e=>{e.target===e.currentTarget&&(o||l||r(!0))},[o,l]),f=Hr.useCallback(e=>{l||u.current?.contains(e.relatedTarget)||r(!1)},[l]);if(!n.length)return Gr("span",{id:i,tabIndex:-1,style:_r});if(!d)return Gr("div",{id:i,className:Ur,role:"region","aria-label":h,tabIndex:-1,style:_r,onFocus:p,children:Xr("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",n.length," semantic items)"]})});const m=Math.min(s,n.length),y=n.slice(0,m),g=n.length-m;return Xr("div",{ref:u,id:i,className:Kr,role:"region","aria-label":h,tabIndex:-1,onBlur:f,style:Qr,children:[Gr("button",{type:"button",className:"semiotic-accessible-data-table-close","aria-label":"Close data summary",onClick:()=>{l&&c&&c.setVisible(!1),r(!1)},style:Jr,children:"×"}),Gr("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Zr,children:ps(n)}),Xr("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Semantic items for "+(t??"physics chart"),style:es,children:[Gr("caption",{className:"semiotic-accessible-data-table-caption",style:is,children:g>0?`First ${m} of ${n.length} semantic items`:`All ${n.length} semantic items`}),Gr("thead",{children:Xr("tr",{children:[Gr("th",{scope:"col",style:ts,children:"Item"}),Gr("th",{scope:"col",style:ts,children:"Description"}),Gr("th",{scope:"col",style:ts,children:"Group"}),Gr("th",{scope:"col",style:ts,children:"Position"}),Gr("th",{scope:"col",style:ts,children:"Data"})]})}),Gr("tbody",{children:y.map((e,t)=>Xr("tr",{children:[Gr("th",{scope:"row",style:ns,children:e.label}),Gr("td",{style:ns,children:e.description??e.label}),Gr("td",{style:ns,children:e.group??""}),Xr("td",{style:ns,children:[Math.round(e.x),", ",Math.round(e.y)]}),Gr("td",{style:ns,children:hs(e)})]},e.id??`${e.label}-${t}`))})]}),g>0?Xr("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:os,children:["Show ",Math.min(25,g)," more"," ",1===g?"row":"rows"," (",g," remaining)"]}):null]})}us.ownsChrome=!0;import{jsx as ms,jsxs as ys}from"react/jsx-runtime";var gs=[640,360],bs={top:0,right:0,bottom:0,left:0},xs=new Set(["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),vs="StreamPhysicsFrame",ws=s(r(function(e,t){const{accessibleTable:n=!0,annotations:i,onAnnotationActivate:r,autoPlaceAnnotations:s,background:h,backgroundGraphics:p,bodySemanticItemLimit:f=200,bodySemanticItems:m=!1,bodySemanticUpdateMs:y=200,bodyForces:g,bodyStyle:b,chartId:x,className:v,frameScheduler:w,clock:k,random:M,seed:S,color:I,config:A,controllers:C,continuous:R=!1,description:D,emphasis:P,chartMode:$,enableHover:B=!0,foregroundGraphics:j,hoverRadius:T=16,initialSpawns:N,initialSpawnPacing:W,legend:E,legendClickBehavior:z,legendHighlightedCategory:O,legendHoverBehavior:F,legendIsolatedCategories:L,legendLayout:q,legendPosition:Y,margin:H,onClick:G,onObservation:X,onRegionEvent:_,onSimulationExecutionChange:V,onBodyHover:U,onBodyPointerDown:K,onSemanticItemActivate:Q,onSemanticItemFocus:Z,onTick:te,opacity:ue,paused:pe=!1,regionEffects:fe=[],responsiveHeight:me,responsiveWidth:ye,selectedBodyStyle:ge={stroke:"#111827",strokeWidth:2,opacity:1},selection:be,semanticItems:xe=[],simulationExecution:ve="auto",size:we=gs,stroke:ke,strokeWidth:Me,summary:Se,suspendWhenHidden:Ie=!0,svgAnnotationRules:Ae,title:Ce,tooltipContent:Re,workerBodyThreshold:De=Vn,renderBody:Pe,beforePaint:$e,afterPaint:Be}=e,je=o.useMemo(()=>({color:I,stroke:ke,strokeWidth:Me,opacity:ue}),[I,ue,ke,Me]),Te=u(X);Te.current=X;const Ne=u(x);Ne.current=x;const We=u(new Map),Ee=u(fe);Ee.current=fe;const ze=u(g);ze.current=g;const Le=u(te);Le.current=te;const qe=o.useMemo(()=>Xo(C),[C]),Ye=u(qe);Ye.current=qe;const He=R||!!qe?.continuous,Ge=u(He);Ge.current=He;const Xe=o.useMemo(()=>{if(!g&&!qe?.bodyForce)return g;if(!qe?.bodyForce)return g;if(!g)return qe.bodyForce;const e=qe.bodyForce;return t=>{const n="function"==typeof g?g(t):g,i="function"==typeof e?e(t):e;return n||i?{x:(n?.x??0)+(i?.x??0),y:(n?.y??0)+(i?.y??0)}:null}},[g,qe]);ze.current=Xe;const _e=o.useMemo(()=>new Map(fe.map(e=>[jr(e),e])),[fe]),Ve=o.useMemo(()=>new Map(fe.map(e=>[e.id,e])),[fe]),Ue=o.useMemo(()=>fe.map(Er).filter(e=>null!=e),[fe]),[lt,dt]=o.useState([]),ut=o.useMemo(()=>lt.length||Ue.length?[...xe,...lt,...Ue]:xe,[lt,Ue,xe]),ht=o.useMemo(()=>zr(fe),[fe]),pt=!!Xe,ft=u(null),mt=u(k??So);mt.current=k??So;const yt=a((e,t,n)=>{const i=ft.current;if(!i||!n)return!1;const o=i.readBodies().find(t=>t.id===e),r=Nr(We.current.get(e));if(!o||!r)return!1;const s=Wr(n,{body:o,region:t,regionState:r});return!(!s||!s.x&&!s.y||(i.applyImpulse(e,s.x??0,s.y??0),0))},[]),gt=a((e,t,n)=>{if(!n.bodyId)return;const i=Nr(We.current.get(n.bodyId));if(!i)return;const o={bodyId:n.bodyId,datum:n.datum,observation:n,region:t,regionState:i,type:e};"region-enter"===e?t.onEnter?.(o):t.onExit?.(o),_?.(o)},[_]),bt=a(e=>{const t=e.sensorId?_e.get(e.sensorId):void 0;if(!t||!e.bodyId)return;const n=function(e,t){let n=e.get(t);return n||(n={activeRegionIds:new Set,attributes:{},charges:{},energy:0,regionIds:new Set},e.set(t,n)),n}(We.current,e.bodyId),i=ft.current?.readBodies().find(t=>t.id===e.bodyId),o=Nr(n),r=i&&o?{body:i,region:t,regionState:o}:null;if("physics-proximity-enter"===e.type){if(n.activeRegionIds.add(t.id),n.regionIds.add(t.id),n.energy+=t.energyDelta??0,r){!function(e,t,n){const i="function"==typeof e.attributes?e.attributes(t):e.attributes;i&&(n.attributes={...n.attributes,...i})}(t,r,n);const e=function(e,t){return void 0!==e.charge?"function"==typeof e.charge?e.charge(t):e.charge:"charge-gate"===e.kind?1:void 0}(t,r);void 0!==e&&(n.charges[t.id]=e)}yt(e.bodyId,t,t.impulseOnEnter),gt("region-enter",t,e)}else"physics-proximity-exit"===e.type&&(n.activeRegionIds.delete(t.id),yt(e.bodyId,t,t.impulseOnExit),gt("region-exit",t,e))},[yt,gt,_e]),xt=o.useMemo(()=>{if(!i?.length)return[];const e=i.filter(e=>"barrier"===e.physics||"sensor"===e.physics);return e.length?function(e=[],t={}){const n=t.idPrefix?t.idPrefix+"-":"",i=[];for(const o of e){if("barrier"!==o.physics&&"sensor"!==o.physics)continue;const e=o.axis??t.defaultAxis??"x",r=_n(o,t),s=o.colliderId??`${n}${o.id}`;let a;if("x"===e){const e=Xn(o.x),n=Xn(o.y1)??Xn(t.plotBounds?.y)??Xn(o.y),i=Xn(o.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??Xn(o.y);if(null==e||null==n||null==i)continue;a={type:"segment",x1:e,y1:n,x2:e,y2:i,thickness:r}}else{const e=Xn(o.y),n=Xn(o.x1)??Xn(t.plotBounds?.x)??Xn(o.x),i=Xn(o.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??Xn(o.x);if(null==e||null==n||null==i)continue;a={type:"segment",x1:n,y1:e,x2:i,y2:e,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===o.physics,..."barrier"!==o.physics||null==o.restitution&&null==t.barrierRestitution?{}:{restitution:Xn(o.restitution)??Xn(t.barrierRestitution)},..."barrier"!==o.physics||null==o.friction&&null==t.barrierFriction?{}:{friction:Xn(o.friction)??Xn(t.barrierFriction)}})}return i}(e,{idPrefix:x?x+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:we?.[0]??gs[0],height:we?.[1]??gs[1]}}):[]},[i,x,we]),vt=o.useMemo(()=>{const e=void 0===S||void 0!==A?.kernel?.seed?A:{...A,kernel:{...A?.kernel,seed:S}},t=fe.flatMap(e=>[{id:jr(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...Tr(e)]),n=Object.fromEntries(fe.map(e=>[jr(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),i=e?.observation,o=fe.length>0;return o||t.length>0||xt.length>0||null!=x||i?{...e,colliders:[...e?.colliders??[],...t,...xt],observation:{...i,chartId:x??i?.chartId,chartType:i?.chartType??vs,sensors:{...i?.sensors??{},...n},onObservation:e=>{o&&bt(e),i?.onObservation?.(e)}}}:e},[xt,x,A,bt,fe,S]);if(!ft.current){const e=Mo(vt,N,W);e.setPaused(pe),Ie&&e.setVisible(Ko()),ft.current=e}const wt=u(-1),kt=u(null),Mt=u(!0),St=nr(new cr("StreamPhysicsFrame")),It=u(""),At=d().replace(/:/g,""),Ct=u(!1),Rt=u(!1),Dt=u(0),Pt=u(!1),$t=u(null),Bt=u(!1),jt=J({sizeProp:we,responsiveWidth:ye,responsiveHeight:me,userMargin:H,marginDefault:bs,foregroundGraphics:j,backgroundGraphics:p,frameScheduler:w,clock:k,random:M,seed:S,paused:pe,suspendWhenHidden:Ie}),{margin:Tt,rafRef:Nt,reducedMotionRef:Wt,renderFnRef:Et,cancelRender:zt,resolvedBackground:Ot,resolvedForeground:Ft,responsiveRef:Lt,scheduleRender:qt,size:Yt,frameRuntime:Ht}=jt,Gt=u(Ht.now);Gt.current=Ht.now;const Xt=function(){const[e,t]=ie(!1);return re(()=>{t(!0)},[]),e}(),_t=function(){const e=oe(se,ae,ce);return ne(e).current}(),[Vt,Ut]=o.useState(null),[Kt,Qt]=o.useState(null),Zt=u(null),Jt=u(0),en=u(new Map),tn=At+"-physics-live",nn=a((e,t,n=!1)=>{if(!m)return void dt(e=>e.length?[]:e);const i=Gt.current();if(!n&&y>0&&y>i-Jt.current)return;Jt.current=i;const o=function(e,t,n,i){if(!n)return[];const o=Math.max(0,Math.floor(i));if(!o)return[];const r=[];for(let i=0;e.length>i&&o>r.length;i+=1){const o=e[i],s="function"==typeof n?n(o,{index:i,simulationState:t}):void 0;if(!1===s)continue;const a=as(o);r.push({datum:o.datum??o,description:ls(o),group:"body",label:cs(o),...a,...s??{},bodyId:s?.bodyId??o.id,id:s?.id??"body:"+o.id,x:s?.x??o.x,y:s?.y??o.y})}return r}(e,t,m,f);dt(e=>function(e,t){if(e.length!==t.length)return!0;for(let n=0;e.length>n;n+=1){const i=e[n],o=t[n];if(i.id!==o.id||i.label!==o.label||i.description!==o.description||i.group!==o.group||i.bodyId!==o.bodyId||Math.round(i.x)!==Math.round(o.x)||Math.round(i.y)!==Math.round(o.y))return!0}return!1}(e,o)?o:e)},[f,m,y]),on=a(e=>{if(!ut.length)return;const t=Math.max(0,Math.min(e,ut.length-1));wt.current=t;const n=ut[t];if(Zt.current=n.bodyId??null,Ut(n),Z?.(n),n.bodyId&&ft.current){const e=ft.current.readBodies().find(e=>e.id===n.bodyId);if(e){const t=ss(e);Qt(t),U?.(e,t)}}},[ut,U,Z]),rn=a(()=>{wt.current=-1,Zt.current=null,Ut(null),Z?.(null)},[Z]),sn=function({onObservationRef:e,chartIdRef:t,wallClockRef:n}){return Yr((i,o)=>{const r=e.current;if(!r)return;const s={timestamp:n.current(),chartType:"StreamPhysicsFrame",chartId:t.current};r("hover"===i||"click"===i?{...s,type:i,datum:o?.datum??{},x:o?.x??0,y:o?.y??0}:"focus"===i?{...s,type:i,datum:o?.datum??{},inputType:"touch"===o?.inputType?"pointer":o?.inputType??"keyboard"}:"activate"===i?{...s,type:i,datum:o?.datum??{},inputType:o?.inputType??"keyboard"}:{...s,type:i})},[t,e,n])}({onObservationRef:Te,chartIdRef:Ne,wallClockRef:mt}),an=a(()=>{Qt(e=>e?(U?.(null,null),sn("hover-end"),null):e)},[sn,U]),cn=a(e=>{if(!B||!ft.current)return;const t=e.currentTarget.getBoundingClientRect(),n=ft.current.hitTest(e.clientX-t.left,e.clientY-t.top,T);if(!n)return void an();const i=ss(n);Qt(e=>e&&e.id===i.id&&e.x===i.x&&e.y===i.y?e:(U?.(n,i),sn("hover",{datum:n.datum,x:n.x,y:n.y}),i))},[an,sn,B,T,U]),ln=a(e=>{rn();const t=ft.current,n=e.currentTarget.getBoundingClientRect(),i=e.clientX-n.left,o=e.clientY-n.top,r=t?t.hitTest(i,o,Math.max(16,T)):null;K?.(r,e),r?(sn("click",{datum:r.datum,x:r.x,y:r.y}),sn("activate",{datum:r.datum,inputType:"touch"===e.pointerType?"touch":"pointer"}),G?.(r.datum??null,{x:r.x,y:r.y,body:r})):(sn("click-end"),G?.(null,{x:i,y:o,body:null}),an())},[an,rn,sn,T,K,G]);c(()=>{if(!ut.length)return void rn();const e=wt.current;if(ut.length>e){if(e>=0){const t=ut[e];if(Zt.current=t.bodyId??null,Ut(e=>null!=e&&e.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t),t.bodyId&&ft.current){const e=ft.current.readBodies().find(e=>e.id===t.bodyId);if(e){const t=ss(e);Qt(e=>e?.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t)}}}}else on(ut.length-1)},[ut,rn,on]),c(()=>{B||an()},[an,B]);const dn=a(e=>{if(function(e){const t=e.target;return t instanceof Element&&t!==e.currentTarget&&null!=t.closest("button, a[href], input, select, textarea, summary, [contenteditable='true'], [role='button'], [role='link'], [role='checkbox'], [role='radio'], [role='switch']")}(e))return;if(!ut.length)return;if("Escape"===e.key)return e.preventDefault(),void rn();if(("Enter"===e.key||" "===e.key)&&wt.current>=0){e.preventDefault();const t=ut[wt.current];return sn("activate",{datum:t.datum??{id:t.id,label:t.label},inputType:"keyboard"}),void Q?.(t)}if(!xs.has(e.key))return;e.preventDefault();const t=wt.current;if(0>t){on(0);const e=ut[0];return void sn("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}const n=Math.max(1,Math.floor(.1*ut.length));let i=t;if("Home"===e.key?i=0:"End"===e.key?i=ut.length-1:"PageDown"===e.key?i=Math.min(ut.length-1,t+n):"PageUp"===e.key?i=Math.max(0,t-n):"ArrowRight"===e.key||"ArrowDown"===e.key?i=Math.min(ut.length-1,t+1):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(i=Math.max(0,t-1)),on(i),i!==t){const e=ut[i];sn("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}},[rn,sn,on,Q,ut]),[un,hn]=o.useState([]),pn=u(0),fn=!!i?.length&&i.some(e=>null!=e.pointId||null!=e.bodyId||"latest"===e.anchor),{canvasRef:mn}=function(e,t){return function(e){const{cancelRender:t,dirtyRef:n,frameRuntime:i,manageFrameRuntime:o,scheduleRender:r}=e,s=de(null),a=de(null),c=de(!1);return function(e){const{hydrated:t,wasHydratingFromSSR:n,storeRef:i,dirtyRef:o,renderFnRef:r,cancelRender:s,cleanup:a}=e;re(()=>{t&&n&&i.current?.cancelIntroAnimation?.(),o.current=!0,s?.(),r.current()},[t,n]);const c=ne(a);c.current=a,ee(()=>()=>c.current?.(),[])}({hydrated:e.hydrated,wasHydratingFromSSR:e.wasHydratingFromSSR,storeRef:e.storeRef,dirtyRef:e.dirtyRef,renderFnRef:e.renderFnRef,cancelRender:e.cancelRender,cleanup:e.cleanup}),le(()=>{if(!1!==o)return i.subscribe(()=>{i.isActive?(n.current=!0,r()):t()})},[t,n,i,o,r]),le(()=>{!c.current&&(c.current=!0,e.skipInitialCanvasPaintInvalidation)||(e.dirtyRef.current=!0,e.scheduleRender())},e.canvasPaintDependencies),{canvasRef:s,interactionCanvasRef:a}}({...t,renderFnRef:e.renderFnRef,scheduleRender:e.scheduleRender,cancelRender:e.cancelRender,frameRuntime:e.frameRuntime})}(jt,{hydrated:Xt,wasHydratingFromSSR:_t,storeRef:ft,dirtyRef:Mt,manageFrameRuntime:!1,skipInitialCanvasPaintInvalidation:!0,canvasPaintDependencies:[h,p,qt]}),yn=a(()=>{const e=mn.current,t=ft.current;if(!e||!t)return;const n=St.current.beforeCompute(t.getLastUpdateResult(),!1),i=function(){if("undefined"==typeof window)return 1;const e=window.devicePixelRatio||1,t=function(){if("undefined"==typeof window)return!1;const e="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,t=768>Math.min(window.innerWidth||1/0,window.innerHeight||1/0);return e||t}()?2:3;return Math.max(1,Math.min(e,t))}(),o=function(e,t,n,i){const o=e.getContext("2d");if(!o)return null;const r=Math.round(t[0]*i),s=Math.round(t[1]*i),a=r/t[0],c=s/t[1],l=t[0]+"px",d=t[1]+"px";return e.style.width!==l&&(e.style.width=l),e.style.height!==d&&(e.style.height=d),e.width===r&&e.height===s||(e.width=r,e.height=s),o.setTransform(a,0,0,c,0,0),o.translate(n.left,n.top),o}(e,Yt,Tt,i);if(!o)return void St.current.afterCompute(n,!1,!1);const r=function(e){const t=at(e,nt),n=at(e,Je),i=at(e,st),o=at(e,it),r=at(e,Ze),s=at(e,Qe),a=at(e,ot),c=at(e,rt),l=at(e,et),d=at(e,tt);return{annotationBackground:ct(s,.94),annotationStroke:r,annotationText:a,background:s,border:r,closedWindowFill:ct(n,.08),closedWindowStroke:ct(n,.55),danger:n,focus:l,grid:d,gutterFill:ct(c,.14),lateFill:i,openWindowFill:ct(t,.07),openWindowStroke:ct(t,.3),primary:t,selectedFill:i,selectedStroke:l,success:o,text:a,textSecondary:c,warning:i}}(o);o.clearRect(-Tt.left,-Tt.top,Yt[0],Yt[1]),p||"transparent"===h||(o.fillStyle=h??r.background,o.fillRect(-Tt.left,-Tt.top,Yt[0],Yt[1]));const s=t.snapshot(),a=t.readBodies();if(nn(a,s.simulationState),fn){const e=Gt.current();if(e-pn.current>=100){pn.current=e;const t=qn(a);hn(e=>e.length===t.length&&e.every((e,n)=>e.pointId===t[n].pointId&&Math.round(e.x)===Math.round(t[n].x)&&Math.round(e.y)===Math.round(t[n].y))?e:t)}}$e&&(o.save(),$e(o,a),o.restore());for(const e of a){const t=We.current.get(e.id),n=t?Array.from(t.activeRegionIds).map(e=>Ve.get(e)).filter(e=>null!=e):[],i=qr(e,s.simulationState,b,ge,be,Nr(t),n,r.primary,r.text,je);Pe?(o.save(),Pe(o,e,i),o.restore()):$r(o,e,i)}Be&&(o.save(),Be(o,a),o.restore()),function(e,t,n){let i=!1;for(const[o,r]of t){const s=Math.min(1,Math.max(0,(n-r.startedAt)/r.durationMs));if(s>=1){t.delete(o);continue}i=!0;const a=1-Math.pow(1-s,3),{body:c}=r,l=r.radius+28*a,d=1-s;e.save(),e.globalAlpha*=d,e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=2.4*d+.4,e.beginPath(),e.arc(c.x,c.y,l,0,2*Math.PI),e.stroke(),e.globalAlpha*=.18,e.beginPath(),e.arc(c.x,c.y,.52*l,0,2*Math.PI),e.fill(),e.restore(),e.save(),e.globalAlpha*=d,e.strokeStyle=r.color,e.lineWidth=1.8;for(let t=0;8>t;t+=1){const n=t*(Math.PI/4)+1.4*s,i=r.radius+5+12*a,o=r.radius+12+34*a;e.beginPath(),e.moveTo(c.x+Math.cos(n)*i,c.y+Math.sin(n)*i),e.lineTo(c.x+Math.cos(n)*o,c.y+Math.sin(n)*o),e.stroke()}e.restore()}}(o,en.current,Gt.current()),St.current.afterCompute(n,!0,!1),Mt.current=!1},[mn,St,Yt,Tt,p,h,nn,fn,$e,Be,b,ge,be,je,Pe,Ve]),gn=a((e,t)=>{const n=ft.current,i=`${ve}:${e}:${t??""}`;It.current!==i&&(It.current=i,V?.({execution:e,liveBodies:n?.liveBodyCount()??0,queuedBodies:n?.queueSize()??0,reason:t,requested:ve}))},[V,ve]),bn=a((e,t=!0)=>{Dt.current+=1,Ct.current=!1,Pt.current=!1,Bt.current=!1,$t.current?.terminate(),$t.current=null,t&&gn("sync",e)},[gn]),xn=a(()=>Xt?"undefined"==typeof window||"undefined"==typeof Worker?"worker unavailable":ht?"runtime region effects require sync":pt?"body forces require sync":qe?"physics controllers require sync":function(e){return!e||!e.engine&&Kn(e.sediment)&&(!(t=e.colliders)||t.every(e=>{const t=e.bodyFilter;return!t||"function"!=typeof t}));var t}(vt??{})?Jn(W)?Rt.current?"worker fallback":null:"spawn pacing is not worker-cloneable":"config is not worker-cloneable":"hydrating",[vt,qe,pt,ht,Xt,W]),vn=a(()=>{const e=ft.current,t=xn();if(!e||t)return{reason:t,useWorker:!1};const n=e.liveBodyCount(),i=e.queueSize(),o=function(e,t,n=0,i=Vn){return"sync"!==e&&("worker"===e||t+n>=i)}(ve,n,i,De);return{reason:o?"worker"===ve?"forced worker":"body threshold":"below threshold",useWorker:o}},[ve,De,xn]),wn=a(e=>{const t=ft.current;return t&&e.snapshot?(t.restore(e.snapshot),Mt.current=!0,t):t},[]),kn=a((e,t=!0)=>{const n=wn(e);if(!n)return;t&&te?.(e.result,n.controls()),yn();const i=n.snapshot();!e.result.shouldContinue&&en.current.size<=0||i.paused||!i.visible||Wt.current||qt()},[wn,te,yn,Wt,qt]),Mn=a(e=>{Rt.current=!0,bn("worker failed: "+((e instanceof Error?e.message:e+"")||"unknown error"))},[bn]),Sn=a(()=>{const e=ft.current;if(!e)return!1;const t=vn();if(!t.useWorker)return Ct.current||Bt.current?bn(t.reason??"sync fallback"):gn("sync",t.reason??"sync"),!1;if(Ct.current||Bt.current)return!0;const n=$t.current??new ni;$t.current=n,Bt.current=!0;const i=Dt.current+1;return Dt.current=i,n.initFromSnapshot(vt??{},e.snapshot()).then(e=>{if(Dt.current!==i)return;Bt.current=!1,Ct.current=!0,Rt.current=!1,wn(e),gn("worker",t.reason??"worker"),yn();const n=ft.current?.snapshot();e.result.shouldContinue&&n&&!n.paused&&n.visible&&!Wt.current&&(kt.current=null,qt())}).catch(e=>{Dt.current===i&&Mn(e)}),!0},[wn,vt,Mn,yn,Wt,gn,qt,bn,vn]),In=a(e=>"frame"===e.type||"removed"===e.type?e.frame:null,[]),An=a((e,t=!0)=>{const n=$t.current;if(!n||!Ct.current)return;const i=Dt.current;n.request(e).then(e=>{if(Dt.current!==i)return;const n=In(e);n&&kn(n,t)}).catch(Mn)},[kn,In,Mn]),Cn=a(()=>{const e=ft.current;if(!e)return;const t=Sn(),n=e.snapshot(),i=He||pt||ht||!!qe;n.paused||!n.visible||!e.hasPendingWork()&&!i||Wt.current?Et.current():t&&Bt.current||(kt.current=null,qt())},[qe,He,pt,ht,Wt,Et,qt,Sn]),Rn=a(()=>{zt(),Nt.current=null;const e=ft.current;if(!e)return;if(Ct.current&&$t.current){if(Pt.current)return;let t=0;if(!Wt.current){const e=Gt.current();t=null!==kt.current?(e-kt.current)/1e3:0,kt.current=e}const n=$t.current,i=Dt.current;return Pt.current=!0,void(Wt.current?n.settle():n.tick(t)).then(e=>{Pt.current=!1,Dt.current===i&&kn(e)}).catch(n=>{if(Pt.current=!1,Dt.current!==i)return;Mn(n);const o=Wt.current?e.settleWithObservations():e.tick(t);Lr({store:e,result:o,regionEffects:Ee.current,regionState:We.current,bodyForces:ze.current,composed:Ye.current,onTick:Le.current}),yn()})}let t;if(Wt.current)t=e.settleWithObservations();else{const n=Gt.current(),i=null!==kt.current?(n-kt.current)/1e3:0;kt.current=n,t=e.tick(i)}const n=Ye.current,{regionEffectsApplied:i,bodyForcesApplied:o,snapshot:r}=Lr({store:e,result:t,regionEffects:Ee.current,regionState:We.current,bodyForces:ze.current,composed:n,onTick:Le.current});yn(),(Ge.current||t.shouldContinue||i||o||n||en.current.size>0)&&!r.paused&&r.visible&&!Wt.current&&qt()},[kn,Mn,yn,zt,qt,Wt,Nt]);Et.current=Rn,c(()=>{Rt.current=!1,(Ct.current||Bt.current)&&bn("config changed",!1),ft.current?.updateConfig(vt??{}),Cn()},[vt,bn]),c(()=>{Rt.current=!1,Cn()},[Xt,ve,De]),function({cancelRender:e,frameRuntime:t,lastFrameTimeRef:n,paused:i,postWorkerCommand:o,requestRender:r,storeRef:s,suspendWhenHidden:a}){const c=Uo(o);c.current=o;const l=Uo(r);l.current=r,Vo(()=>{const o=s.current;o&&(t.setPaused(i),o.setPaused(i),i&&(n.current=null,e()),c.current({type:"setPaused",paused:i},!1),l.current())},[e,t,i]),Vo(()=>{if(!a){const e=s.current;return t.setVisible(!0),void(e&&!e.snapshot().visible&&(e.setVisible(!0),c.current({type:"setVisible",visible:!0},!1),l.current()))}if("undefined"==typeof document)return;const i=()=>{const i=s.current;if(!i)return;const o=Ko();t.setVisible(o),i.setVisible(o),o||(n.current=null,e()),c.current({type:"setVisible",visible:o},!1),l.current()};return i(),document.addEventListener("visibilitychange",i),()=>document.removeEventListener("visibilitychange",i)},[e,t,a])}({cancelRender:zt,frameRuntime:Ht,lastFrameTimeRef:kt,paused:pe,postWorkerCommand:An,requestRender:Cn,storeRef:ft,suspendWhenHidden:Ie}),c(()=>()=>bn("unmount",!1),[bn]),c(()=>{yn()},[yn]),l(t,()=>({...ft.current.controls(),applyImpulse:(e,t,n)=>{ft.current.applyImpulse(e,t,n),An({type:"applyImpulse",id:e,ix:t,iy:n}),Cn()},clear:()=>{ft.current.clear(),We.current.clear(),en.current.clear(),An({type:"clear"}),Cn()},clearRegionState:e=>{e?We.current.delete(e):We.current.clear(),Cn()},getData:()=>ft.current.readBodies(),getRegionState:e=>e?Nr(We.current.get(e)):function(e){const t={};return e.forEach((e,n)=>{const i=Nr(e);i&&(t[n]=i)}),t}(We.current),getStore:()=>ft.current,pause:()=>{Ht.setPaused(!0),kt.current=null,zt(),ft.current.setPaused(!0),An({type:"setPaused",paused:!0},!1),Cn()},push:(e,t)=>{ft.current.enqueue(e,t),Jn(t)?An({type:"enqueue",spawns:[e],pacing:t}):(Ct.current||Bt.current)&&bn("spawn pacing is not worker-cloneable"),Cn()},pushMany:(e,t)=>{ft.current.enqueue(e,t),Jn(t)?An({type:"enqueue",spawns:e,pacing:t}):(Ct.current||Bt.current)&&bn("spawn pacing is not worker-cloneable"),Cn()},popBodies:(e,t={})=>{const n=ft.current,i=new Map(n.readBodies().map(e=>[e.id,e])),o=n.remove(e),r=Gt.current();for(const e of o){const n=i.get(e);n&&(We.current.delete(e),en.current.set(e,{body:n,color:t.color??"#f59e0b",durationMs:Math.max(120,t.durationMs??520),radius:t.radius??Br(n),startedAt:r}),Zt.current===e&&(Zt.current=null,Ut(null)),Qt(t=>t?.id===e?null:t))}return o.length&&(An({type:"remove",ids:o}),Cn()),o},remove:e=>{const t=ft.current.remove(e);for(const t of e)We.current.delete(t);return An({type:"remove",ids:e}),Cn(),t},restore:e=>{ft.current.restore(e),We.current.clear(),en.current.clear(),An({type:"restore",snapshot:e},!1),Cn()},resume:()=>{Ht.setPaused(!1),kt.current=null,ft.current.setPaused(!1),An({type:"setPaused",paused:!1},!1),Cn()},settle:e=>{const t=ft.current.settle(e);return An({type:"settle",maxSteps:e}),Cn(),t},settleWithObservations:e=>{const t=ft.current.settleWithObservations(e);return An({type:"settle",maxSteps:e}),Cn(),t},step:e=>{const t=ft.current,n=t.tick(e);return Lr({store:t,result:n,regionEffects:Ee.current,regionState:We.current,bodyForces:ze.current,composed:Ye.current,onTick:Le.current}),An({type:"tick",deltaSeconds:e}),yn(),n}}),[zt,Ht,yn,An,Cn,bn]);const Dn=Fe||!Xt&&_t,Pn=["stream-physics-frame",$?"stream-physics-frame--mode-"+$:null,P?"stream-physics-frame--emphasis-"+P:null,v].filter(Boolean).join(" "),$n=D??("string"==typeof Ce?Ce:void 0)??"Physics chart",Bn=At+"-physics-table",jn=Math.max(1,Yt[0]-Tt.left-Tt.right),Tn=Math.max(1,Yt[1]-Tt.top-Tt.bottom),Nn=B&&Kt?Re?Re(Kt):ms(us,{hover:Kt}):null,Wn=Nn&&Kt?ms(Ke,{x:Kt.x-Tt.left,y:Kt.y-Tt.top,containerWidth:Math.max(1,Yt[0]-Tt.left-Tt.right),containerHeight:Math.max(1,Yt[1]-Tt.top-Tt.bottom),margin:Tt,className:"stream-physics-tooltip",children:Nn}):null;if(Dn){const e=ft.current??Mo(vt,N,W),t="string"==typeof Ce?Ce:void 0,{svg:n}=function(e,t={}){const{width:n=640,height:i=360,title:o,description:r,background:s,className:a,idPrefix:c="physics",...l}=t,d=Po(e,l),u=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(c),h=o?u+"-title":void 0,p=r?u+"-desc":void 0,f=[h,p].filter(Boolean).join(" ")||void 0;return{svg:Io.renderToStaticMarkup(Bo("svg",{xmlns:"http://www.w3.org/2000/svg",className:a??"stream-physics-frame",width:n,height:i,viewBox:`0 0 ${n} ${i}`,role:"img","aria-labelledby":f,children:[o&&$o("title",{id:h,children:o}),r&&$o("desc",{id:p,children:r}),s&&"transparent"!==s?$o("rect",{x:0,y:0,width:n,height:i,fill:s}):null,$o("g",{id:u+"-data-area",children:d.sceneNodes.map((e,t)=>Oe(e,t,u))})]})),scene:d,evidence:d.evidence}}(e,{width:Yt[0],height:Yt[1],title:t,description:D,background:"transparent"===h?void 0:h,className:"stream-physics-frame__svg",idPrefix:"physics-"+At});return ys("div",{ref:Lt,className:Pn,"data-semiotic-mode":$,role:"img","aria-label":$n,style:{width:Yt[0],height:Yt[1]},children:[ms(xr,{summary:Se}),ms("div",{dangerouslySetInnerHTML:{__html:n}})]})}return ys("div",{ref:Lt,className:Pn,"data-semiotic-mode":$,role:"group","aria-label":$n,"aria-describedby":Vt?tn:void 0,tabIndex:0,style:{position:"relative",width:Yt[0],height:Yt[1]},onKeyDown:dn,children:["production"!==process.env.NODE_ENV&&ft.current&&ms(lr,{store:ft.current,diagnostics:St.current}),n?ms(vr,{tableId:Bn}):null,n?ms(fs,{chartTitle:"string"==typeof Ce?Ce:$n,items:ut,tableId:Bn}):null,ms(xr,{summary:Se}),ms(yr,{hoverPoint:Kt}),ms("div",{id:tn,"aria-live":"polite","aria-atomic":"true",style:_r,children:Vt?Vt.description??Vt.label:""}),ys("div",{role:"img","aria-label":$n,style:{position:"relative",width:"100%",height:"100%"},children:[ms(he,{size:Yt,margin:Tt,children:Ot}),ms("canvas",{ref:mn,width:Yt[0],height:Yt[1],"aria-hidden":"true",onPointerDown:ln,onPointerMove:B?cn:void 0,onPointerLeave:B?an:void 0}),Ft,ms(Gn,{width:jn,height:Tn,totalWidth:Yt[0],totalHeight:Yt[1],margin:Tt,title:Ce,legend:E,legendPosition:Y,legendLayout:q,legendHoverBehavior:F,legendClickBehavior:z,legendHighlightedCategory:O,legendIsolatedCategories:L,pointNodes:un,annotations:i,onAnnotationActivate:r,onObservation:X,chartId:x,chartType:vs,autoPlaceAnnotations:s,svgAnnotationRules:Ae}),ms(Jo,{active:null!=Vt,hoverPoint:Vt?{x:Vt.x,y:Vt.y}:null,margin:Tt,size:Yt,shape:Vt?.shape,width:Vt?.width,height:Vt?.height,pathData:Vt?.pathData}),Wn]})]})}));ws.displayName="StreamPhysicsFrame";var ks=ws;function Ms(e){if(null==e)return()=>{};const t="function"==typeof e?e:t=>t[e];return e=>Ss(t(e))}function Ss(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isFinite(t)?t:void 0}}function Is(e,t,n){const i=null!=e.axis?n[e.axis]:null!=e.field?t[e.field]:n.value;if(void 0!==e.eq&&i!==e.eq)return!1;if(void 0!==e.ne&&i===e.ne)return!1;if(void 0!==e.in&&!e.in.includes(i))return!1;if(void 0===e.gt&&void 0===e.gte&&void 0===e.lt&&void 0===e.lte&&void 0===e.within&&void 0===e.outside)return!0;const o=Ss(i);if(void 0===o)return!1;if(void 0!==e.gt&&e.gt>=o)return!1;if(void 0!==e.gte&&e.gte>o)return!1;if(void 0!==e.lt&&o>=e.lt)return!1;if(void 0!==e.lte&&o>e.lte)return!1;if(void 0!==e.within){const[t,n]=e.within;if(t>o||o>n)return!1}if(void 0!==e.outside){const[t,n]=e.outside;if(o>=t&&n>=o)return!1}return!0}function As(e,t,n){const i=e.when;return void 0===i||!0===i||!1!==i&&("function"==typeof i?i(t,n):Is(i,t,n))}function Cs(e,t,n){if(!t||0===t.length)return{};let i={};for(const o of t){if(!As(o,e,n))continue;const t="function"==typeof o.style?o.style(e,n):o.style;t&&(i={...i,...t})}return i}function Rs(e,t,n,i=e=>e){const o=e??(()=>({}));return t&&0!==t.length?(e,r)=>{const s=i(e),a={...o(e,r)};return Object.assign(a,Cs(s,t,n(s,r))),a}:o}function Ds(e){const[t,n]=e;return{width:t,height:n,plot:{x:32,y:24,width:Math.max(80,t-64),height:Math.max(80,n-58)}}}function Ps(e){const t=(e??"")+"";if(!t)return"#4e79a7";const n=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let e=0;t.length>e;e+=1)i=31*i+t.charCodeAt(e)>>>0;return n[i%n.length]}function $s(e,t="#4e79a7",n){const i=n?.styleRules,o=!!i&&i.length>0,r=o?Ms(n?.valueAccessor):void 0;return n=>{const s=n.datum,a=s&&e?"function"==typeof e?e(s,0):s[e]:void 0,c={fill:null==a?t:Ps(a),stroke:"#111827",strokeWidth:1,opacity:.9};return o&&s&&Object.assign(c,Cs(s,i,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function Bs(e,t,n,i){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:n},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...i}}}function js(e,t,n){if(!e.length)return[];const i=Ds(t),o=i.plot.width/Math.max(1,e.length),r=Math.max(1,...e.map(e=>e.value)),s=.62*i.plot.height,a=i.plot.y+i.plot.height;return e.map((e,t)=>{const c=Math.max(8,e.value/r*s),l=`${n} ${e.label}: ${e.value}${null==e.secondary?"":`, ${e.secondary} secondary`}`;return{id:`${n}-${e.label}`,label:l,description:l,datum:e,x:i.plot.x+(t+.5)*o,y:a-c/2,shape:"rect",width:Math.max(12,.58*o),height:c,group:n}})}function Ts(e,t,n){return"function"==typeof n?n(e,t):e[n]}function Ns(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:null}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ws(e,t,n){return Math.max(t,Math.min(n,e))}function Es(e,t){const n=Ns(e);return null!=n&&n>0?n:t}function zs(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Os(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}import{scaleLinear as Fs}from"d3-scale";function Ls(e){const{data:t,valueAccessor:n,bins:i,ballRadius:o,seed:r,size:s,valueExtent:a}=e,c=Ds(s),l=t.map((e,t)=>Ns(Ts(e,t,n))).filter(e=>null!=e),d=function(e){if(!e)return;const t=Ns(e[0]),n=Ns(e[1]);return null!=t&&null!=n?t>n?[n,t]:[t,n]:void 0}(a),u=d?.[0]??(l.length?Math.min(...l):0),h=d?.[1]??(l.length?Math.max(...l):1),p=h===u?1:h-u,f=Fs().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:i},()=>0),y=[];t.forEach((e,t)=>{const r=Ns(Ts(e,t,n));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-u)/p*i)));m[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:f(s+.5),y:c.plot.y+o+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,value:r,bin:s}})});const g=c.plot.y+c.plot.height;return{config:Bs(r,[...eo({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...to({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:f,yTop:c.plot.y-400,yBottom:g,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[u,h]}}}import{scaleLinear as qs}from"d3-scale";function Ys(e){const{count:t,idPrefix:n,wallThickness:i,xScale:o,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const c=Math.min(r-1,a?.(t)??s),l=Math.max(1,r-c);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:o(t),y:c+l/2,width:i,height:l}}})}function Hs(e){const{data:t,timeAccessor:n,arrivalAccessor:i,windows:o,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:d=1}=e,u=Ds(c),h=t.map((e,t)=>Ns(Ts(e,t,n))).filter(e=>null!=e),p=Ns(l?.[0]),f=Ns(l?.[1]),m=h.length?Math.min(...h):0,y=h.length?Math.max(...h):m+o.size,g=Math.min(p??m,m),b=Math.max(f??y,y),x=Math.floor(g/o.size)*o.size,v=Math.max(1,Math.ceil((b-x+o.size)/o.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Ns(r?.value)??w-(r?.delay??o.size),M=Math.max(0,Math.min(v,Array.from({length:v},(e,t)=>t).reduce((e,t)=>x+(t+1)*o.size>k?e:e+1,0))),S=function(e,t){const n=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:n,height:e.plot.height},windowPlot:{x:e.plot.x+n,y:e.plot.y,width:Math.max(40,e.plot.width-n),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(u,s),I=x+v*o.size,A=qs().domain([x,I]).range([S.windowPlot.x,S.windowPlot.x+S.windowPlot.width]),C=Array.from({length:v},()=>({value:0,secondary:0})),R=[];t.forEach((e,t)=>{const r=Ns(Ts(e,t,n));if(null==r)return;const a=Ns(Ts(e,t,i))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-x)/o.size))),l=k>=x+(c+1)*o.size;C[c].value+=l?0:1,C[c].secondary+=l?1:0,R.push({id:(e.id??"event-"+t)+"",x:Math.max(S.windowPlot.x+s,Math.min(S.windowPlot.x+S.windowPlot.width-s,A(r))),y:u.plot.y+s+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...e,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const D=u.plot.y+u.plot.height,P=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const i=e.windowStart,o=e.windowStart+e.windowCount*e.windowSize,r=qs().domain([i,o]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+n*e.windowSize),a=e.windowPlot.x,c=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),l=e=>s===a?t:c+(e-a)/(s-a)*(t-c),d=[];for(let t=0;n>t;t+=1){const n=e.windowStart+t*e.windowSize,i=n+e.windowSize,o=r(n),s=r(i);d.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:o,y1:l(o),x2:s,y2:l(s)})}return d}({closedWindowCount:M,gutter:S.gutter,plot:u.plot,windowCount:v,windowPlot:S.windowPlot,windowSize:o.size,windowStart:x},u.plot.y+.28*u.plot.height);return{config:Bs(a,[...eo({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Ys({idPrefix:"eventdrop-window",count:v,xScale:e=>A(x+e*o.size),yTop:S.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>M)return null;const t=0===e?P[0]?.y1:P[e-1]?.y2??P[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?S.wallTop:t+1.25*s},yBottom:D,wallThickness:6}),...P.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:R,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:d},projectionRows:C.map((e,t)=>({label:`${x+t*o.size}-${x+(t+1)*o.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:S.gutter,lidSegments:P,lateCount:C.reduce((e,t)=>e+t.secondary,0),plot:u.plot,windowPlot:S.windowPlot,watermarkValue:k,windowCount:v,windowSize:o.size,windowStart:x}}}function Gs(e,t,n){const i=e.width/Math.max(1,t),o=Math.max(2,2*n),r=Math.min(.7*i,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(r/o));return{laneWidth:i,tubeWidth:r,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*i,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}function Xs(e){const{data:t,categoryAccessor:n,valueAccessor:i,unitValue:o,ballRadius:r,seed:s,size:a}=e,c=Es(o,1),l=Ds(a),d=[],u=new Map,h=new Map,p=[];function f(e){let t=u.get(e);return null==t&&(t=d.length,d.push(e),u.set(e,t)),t}t.forEach((e,t)=>{f((Ts(e,t,n)??"unknown")+"")});const m=Math.max(1,d.length),y=Gs(l.plot,m,r),g=Math.max(0,y.tubeWidth/2-r-1),b=d.map(()=>[]);t.forEach((e,t)=>{const o=(Ts(e,t,n)??"unknown")+"",s=f(o),a=i?Ns(Ts(e,t,i)):1,d=Math.max(0,Math.round((a??0)/c)),u=y.centerX(s);for(let n=0;d>n;n+=1){const i=h.get(o)??0,a=y.perRow>1?((y.perRow>1?i%y.perRow:0)/(y.perRow-1)*2-1)*g:0;h.set(o,i+1),b[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:u+a,y:l.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:o,unitIndex:n}})}});const x=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;x>e;e+=1)for(const t of b)t.length>e&&p.push(t[e]);const v=l.plot.y+l.plot.height,w=[...eo({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=l.plot.y-400;for(let e=0;m>e;e+=1){const t=y.centerX(e);for(const n of[-1,1])w.push({id:`pile-tube-${e}-${0>n?"l":"r"}`,shape:{type:"aabb",x:t+n*y.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:Bs(s,w,"PhysicsPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:h.get(e)??0}))}}import{scaleLinear as _s}from"d3-scale";function Vs(e){const{data:t,xAccessor:n,groupAccessor:i,radiusAccessor:o,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:d}=e,u=Ds(a),h=Os(s),p=[],f=[],m=new Map;t.forEach((e,t)=>{const s=Ns(Ts(e,t,n));if(null==s)return;const a=i?(Ts(e,t,i)??"All")+"":"All",c=o?Ns(Ts(e,t,o)):null,l=Ws(null!=c&&c>0?c:r,2,18);!function(e){let t=m.get(e);null==t&&(t=f.length,f.push(e),m.set(e,t))}(a),p.push({datum:e,index:t,value:s,group:a,radius:l})});const y=p.map(e=>e.value),g=c?Ns(c[0]):null,b=c?Ns(c[1]):null,x=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=g??x,k=b??v;if(w===k&&(w-=.5,k+=.5),w>k){const e=k;k=w,w=e}const M=Math.max(r,...p.map(e=>e.radius)),S=u.plot.x+M+8,I=u.plot.x+u.plot.width-M-8,A=_s().domain([w,k]).range([S,I]),C=Math.max(1,f.length),R=u.plot.y+Math.max(28,3*M),D=Math.max(0,u.plot.y+u.plot.height-Math.max(28,3*M)-R),P=e=>{const t=m.get(e)??0;return 1===C?u.plot.y+.54*u.plot.height:R+t/(C-1)*D},$=new Map,B=p.map((e,t)=>{$.set(e.group,($.get(e.group)??0)+1);const n=A(e.value),i=P(e.group),o=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:d?n+o:Ws(n+(t%9-4)*e.radius*2.5,S,I),y:d?i+r:u.plot.y-18-t%12*e.radius,vx:d?0:22*(h()-.5),vy:d?0:24+18*h(),mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:n,targetY:i},springs:[{target:{type:"point",x:n,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:Bs(s,eo({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*M),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:B,projectionRows:f.map(e=>({label:e,value:$.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[S,I],groups:f.map(e=>({label:e,y:P(e),count:$.get(e)??0})),plot:u.plot}}}function Us(e){if(Array.isArray(e)&&e.length>=2){const t=Ns(e[0]),n=Ns(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=Ns(t.x),i=Ns(t.y);return null!=n&&null!=i?{x:n,y:i}:null}return null}function Ks(e){return Array.isArray(e)?e.map(Us).filter(e=>null!=e):[]}function Qs(e,t,n){return"normalized"===n?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Ws(e.x,t.plot.x,t.plot.x+t.plot.width),y:Ws(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Zs(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}function Js(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=Ws(t,0,1)*Zs(e);let i=0;for(let t=1;e.length>t;t+=1){const o=e[t-1],r=e[t],s=Math.hypot(r.x-o.x,r.y-o.y);if(s>0){if(i+s>=n){const e=(n-i)/s;return{x:o.x+(r.x-o.x)*e,y:o.y+(r.y-o.y)*e}}i+=s}}return{...e[e.length-1]}}function ea(e,t){const n=Js(e,Math.max(0,t-.02)),i=Js(e,Math.min(1,t+.02)),o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{x:o/s,y:r/s}}function ta(e){const{coordinateMode:t,flowSpeed:n,links:i,maxParticles:o,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:d,pathAccessor:u,pathConstraint:h="path",reducedMotion:p,seed:f,size:m,sourceAccessor:y,targetAccessor:g,throughputAccessor:b}=e,x=Ds(m),v=Os(f),w=new Map,k=new Map,M=[];function S(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof r){const e=r(t,0);if(null!=e)return e+""}if("string"==typeof r&&null!=t[r])return t[r]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}c.forEach((e,t)=>{const n=(Ts(e,t,r)??e.id??t)+"",i=Ns(Ts(e,t,s)),o=Ns(Ts(e,t,a));if(null!=i&&null!=o){const e={x:i,y:o};w.set(n,e),M.push(e)}k.set(n,(e.label??e.name??n)+"")});const I=[];i.forEach((e,t)=>{const n=S(Ts(e,t,y)),i=S(Ts(e,t,g)),o=Math.max(0,Ns(Ts(e,t,b))??0),r=Ks(u?Ts(e,t,u):void 0),s=r.length?r:Ks(e.path??e.points??e.route);s.forEach(e=>M.push(e)),I.push({id:(e.id??`physical-flow-${n}-${i}-${t}`)+"",link:e,index:t,source:n,target:i,throughput:o,rawPath:s})});const A=(R=M,"normalized"===(C=t)||"pixels"===C?C:R.length>0&&R.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var C,R;const D=new Map;for(const[e,t]of w)D.set(e,Qs(t,x,A));const P=[];for(const e of I){let t=e.rawPath.map(e=>Qs(e,x,A));if(2>t.length){const n=D.get(e.source),i=D.get(e.target);n&&i&&(t=[n,i])}else D.has(e.source)||D.set(e.source,t[0]),D.has(e.target)||D.set(e.target,t[t.length-1]);t.length>=2&&e.throughput>0&&(k.has(e.source)||k.set(e.source,e.source),k.has(e.target)||k.set(e.target,e.target),P.push({...e,path:t,packetCount:0}))}const $=Es(d,.12),B=Math.max(1,Math.round(o)),j=P.map(e=>Math.max(1,Math.round(e.throughput*$))),T=j.reduce((e,t)=>e+t,0),N=T>B?B/T:1;P.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(j[t]*N))});let W=P.reduce((e,t)=>e+t.packetCount,0);for(;W>B;){const e=P.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>P[e].packetCount)?n:e,-1);if(-1===e)break;P[e].packetCount-=1,W-=1}const E=new Map,z=new Map,O=[],F=Es(n,90),L=Es(l,4);P.forEach((e,t)=>{E.set(e.target,(E.get(e.target)??0)+e.throughput),z.set(e.source,(z.get(e.source)??0)+e.throughput);const n=Zs(e.path);for(let i=0;e.packetCount>i;i+=1){const o=(i+.5)/e.packetCount,r=p?o:Ws(.12+.84*o+.04*(v()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*v())),a=Js(e.path,s),c=Js(e.path,r),l=ea(e.path,s),d={x:-l.y,y:l.x},u=(v()-.5)*L*1.5;O.push({id:`${e.id}-packet-${i}`,x:a.x+d.x*u,y:a.y+d.y*u,vx:p?0:l.x*F+10*(v()-.5),vy:p?0:l.y*F+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+i/32,shape:{type:"circle",radius:L},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:i,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:F,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*L,stiffness:26,damping:4.25}]:void 0})}});const q=Math.max(18,5*L),Y=Array.from(D,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:"physical-flow-node-"+zs(e),point:t})),H=Y.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:q,height:q}})),G=Object.fromEntries(Y.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),X=Bs(f,[...eo({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...H],"PhysicalFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*L),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});X.bodyLimit=B,X.eviction="oldest",X.observation={...X.observation,sensors:G};const _=Array.from(D,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+zs(e),incoming:E.get(e)??0,outgoing:z.get(e)??0})),V=P.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:X,initialSpawns:O,projectionRows:_.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:A,particleCount:O.length,totalThroughput:P.reduce((e,t)=>e+t.throughput,0),plot:x.plot,nodes:_,links:V}}}function na(e,t){if("region-enter"!==t.type)return e;const n=t.region.id,i=e[n]??{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;const o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function ia(e,t){return(t??Object.keys(e)).map(t=>e[t]).filter(e=>null!=e).map(e=>({label:e.label??e.id,value:e.count}))}function oa(e,t){const n=t instanceof Set?t:new Set(t);return e.map(e=>{const t=e.bodyIds??[],i=t.filter(e=>!n.has(e)),o=t.length-i.length,r=e.completion?.mode??"allMembersAbsorbed",s=e.completion?.valueByBodyId,a=e=>{const t=s?.[e];return Number.isFinite(t)&&Number(t)>=0?Number(t):1},c=t.reduce((e,t)=>e+a(t),0),l=t.reduce((e,t)=>e+(n.has(t)?a(t):0),0),d=e.completion?.threshold,u="threshold"===r?Number.isFinite(d)&&Number(d)>=0?Number(d):c:void 0;return{id:e.id,label:e.label??e.id,mode:r,complete:t.length>0&&("anyAbsorbed"===r?o>0:"threshold"===r?l>=(u??c):0===i.length),absorbed:o,total:t.length,absorbedValue:l,totalValue:c,threshold:u,missing:i}})}function ra(e,t,n){return Math.max(t,Math.min(n,e))}function sa(e,t,n={}){const i=n.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],r=ra(n.along??.5,.05,.95),s=n.jitterX??0,a=n.padY??20,c=o.x0+(o.x1-o.x0)*r+(2*i()-1)*s,l=Math.min(1,o.width/2),d=ra(c,o.x0+l,o.x1-l),u=e.boundaryY(d,"top")+a,h=e.boundaryY(d,"bottom")-a;return{x:d,y:h>u?u+i()*Math.max(1,h-u):e.midY}}function aa(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function ca(e,t,n){return Math.max(t,Math.min(n,e))}function la(e,t,n,i,o,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:i,y2:o,thickness:r.thickness??8}}}function da(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height)),o=e.padX??46,r=e.padY??72,s=o,a=n-o,c=r,l=i-Math.max(24,Math.round(.45*r)),d=(c+l)/2,u=Math.max(1,l-c),h=ca(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,m=ca(u*h+f,.06*u,.5*u),y=m/2,g=d-y,b=d+y,x=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,M=e.stages;if(!M.length)throw Error("processStageLayout requires at least one stage");const S=ca(e.centerStageIndex??Math.floor(M.length/2),0,M.length-1),I=function(e){const t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(M),A=a-s;let C=s;const R=M.map((e,t)=>{const n=C,i=t===M.length-1?a:C+(e.share??1)/I*A;return C=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:i,x:(n+i)/2,width:i-n,y:d,height:u}}),D=R[S],P=D.x0,$=D.x1,B=(e,n)=>{if("lane"===t)return"top"===n?c:l;if("funnel"===t){const t=ca((e-s)/Math.max(1,a-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if(P>=e){const t=ca((e-s)/Math.max(1,P-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if($>=e)return"top"===n?g:b;const i=ca((e-$)/Math.max(1,a-$),0,1);return"top"===n?g+(c-g)*i:b+(l-b)*i},j=R.map(e=>{const t=Math.min(B(e.x0,"top"),B(e.x1,"top")),n=Math.max(B(e.x0,"bottom"),B(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),T={thickness:k,friction:v,restitution:w},N=[];"lane"===t?N.push(la(x+"-top",s,c,a,c,T),la(x+"-bottom",s,l,a,l,T),la(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),la(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)})):"funnel"===t?N.push(la(x+"-top",s,c,a,g,T),la(x+"-bottom",s,l,a,b,T),la(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),la(x+"-right",a,g,a,b,{...T,thickness:Math.max(6,k)})):N.push(la(x+"-left-top",s,c,P,g,T),la(x+"-left-bottom",s,l,P,b,T),la(x+"-center-top",P,g,$,g,T),la(x+"-center-bottom",P,b,$,b,T),la(x+"-right-top",$,g,a,c,T),la(x+"-right-bottom",$,b,a,l,T),la(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),la(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)}));const W=e.membraneDampingScale??.5,E=s,z=Math.max(1,("bowtie"===t?P:a)-E),O=(e.membranes??[]).map(e=>{const t=E+ca(e.offset,0,1)*z,n=e.width??18+18*e.cost,i=u-16,o=d+.25*(e.wobble??0);return{...e,x:t,y:o,width:n,height:i}}),F=!1===e.includeMembraneRegions?[]:O.map(e=>pa({id:e.id,label:e.label??e.id,description:e.description??(e.label??e.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??W,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:i,padX:o,padY:r,left:s,right:a,topY:c,bottomY:l,midY:d,centerLeft:P,centerRight:$,pinchHeight:m,pinchTop:g,pinchBottom:b,stages:j,membranes:O,colliders:N,regionEffects:F,boundaryY:B}}function ua(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,i=e.width,o=e.height,{type:"aabb",x:t,y:n,width:i,height:o}),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:e.attributes,onEnter:e.onEnter,onExit:e.onExit};var t,n,i,o}function ha(e,t={}){const n=t.idPrefix??"stage",i=Math.max(0,t.insetX??0),o=Math.max(0,t.insetY??1);return e.stages.map(e=>{const r="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...ua({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*i),height:Math.max(1,e.height-2*o),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...r,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function pa(e){const t=e.dampingScale??.5,n=e.energyScale??1,i=ca(e.cost,0,2);return{...ua({...e,kind:e.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:i*t,energyDelta:-i*n}}function fa(e){return{...ua({...e,kind:e.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function ma(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...ua({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function ya(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,i=e.dampingPerUnit??.12,o=e.energyPerUnit??0;return{...ua({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*i,energyDelta:o?-t*o:void 0,force:e.force}}function ga(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...ua({...e,kind:e.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function ba(e){return{...ua({...e,kind:e.kind??"force-field",attributes:{primitive:"portal",targetStage:e.targetStage,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function xa(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...ua({...e,kind:e.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function va(e){return{...ua({...e,kind:e.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function wa(e){const t=e.x??e.anchor?.x??0,n=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function ka(e){const t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},i=[la(t+"-top",e.left,e.top,e.right,e.top,n),la(t+"-bottom",e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||i.push(la(t+"-left",e.left,e.top,e.left,e.bottom,n),la(t+"-right",e.right,e.top,e.right,e.bottom,n)),i}function Ma(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function Sa(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,i=Ds(n),o=Ws(e.ballRadius??6,2,18),r=e.seed??1,s=Os(r),a=e.idAccessor,c=e.stageAccessor??"stage",l=e.groupBy,d=e.groupLabelAccessor,u=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(l?"allAbsorbed":"none"),f=e.springStiffness??.28,m=e.springDamping??.72,y=!0===e.settle,g=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),b=da({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:g,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),x=new Map(b.stages.map((e,t)=>[e.id,t])),v=new Map(b.stages.map(e=>[e.id,e])),w=b.stages[0].id,k=b.stages[0],M=new Set(t.filter(e=>e.absorb).map(e=>e.id)),S=t.map(e=>{const t=v.get(e.id)??k;return function(e,t){const n={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return xa({...n,kind:e.kind??"sink",force:Ma(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(e.portal){const t=e.portal.force??e.force??{x:-40,y:0};return ba({...n,kind:e.kind??"force-field",force:Ma(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return ga({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Ma(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...n.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){const t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return ya({...n,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Ma(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?ma({...n,kind:e.kind??"force-field",force:Ma(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):va({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:b.midY,width:t.width,height:b.bottomY-b.topY})});S.unshift(ma({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const I=new Map;for(const e of b.stages)I.set(e.id,0);const A=[];e.data.forEach((e,t)=>{const n=(a?Ts(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",i=(Ts(e,t,c)??w)+"",r=x.has(i)?i:w;I.set(r,(I.get(r)??0)+1);const s=l?(Ts(e,t,l)??"")+"":void 0,p=s&&d?(Ts(e,t,d)??s)+"":s,f=u?Ns(Ts(e,t,u))??1:1,m=h?Ns(Ts(e,t,h)):null,y=Ws(null!=m&&m>0?m:o,2,18);A.push({datum:e,id:n,stageId:r,groupId:s||void 0,groupLabel:p||void 0,work:f,radius:y,index:t})});const C=new Map,R=new Map;for(const e of A){if(!e.groupId)continue;const t=C.get(e.groupId)??[];t.push(e.id),C.set(e.groupId,t),e.groupLabel&&R.set(e.groupId,e.groupLabel)}const D=Ws(e.groupAnchorAlong??.55,.15,.9),P=b.left+(b.right-b.left)*D,$=Array.from(C.keys()),B=$.map((e,n)=>{const i=C.get(e)??[],o=$.length>1?b.topY+28+n/Math.max(1,$.length-1)*(b.bottomY-b.topY-56):b.midY;return wa({id:e,label:R.get(e)??e,bodyIds:i,anchor:{x:P,y:o},x:P,y:o,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),j=oa(B,A.filter(e=>M.has(e.stageId)).map(e=>e.id)),T=new Map(B.map(e=>[e.id,e])),N=A.map((e,t)=>{const n=v.get(e.stageId)??k,i=n.x+(s()-.5)*Math.min(24,.2*n.width),o=b.boundaryY(i,"top")+e.radius+10,r=b.boundaryY(i,"bottom")-e.radius-10,a=r>o?o+s()*Math.max(1,r-o):b.midY,c=y?i:b.left+18+t%7*4,l=y?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,d=[{target:{type:"point",x:i,y:a},restLength:.45*e.radius,stiffness:f,damping:m}];if(e.groupId){const t=T.get(e.groupId);t?.anchor&&!M.has(e.stageId)&&d.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:c,y:l,vx:y?0:40+40*s(),vy:y?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:y?0:.03*t,springs:d,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),W={kernel:{seed:r,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:b.colliders,fixedDt:1/60,maxSubsteps:8},E=b.stages.map(e=>({label:e.label??e.id,value:I.get(e.id)??0})),z=t.map(e=>{const t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:I.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:W,initialSpawns:N,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:E,metadata:{kind:"process-flow",plot:i.plot,volume:b,stages:z,groups:B,groupCompletion:j,regionEffects:S}}}import{useImperativeHandle as Ia,useRef as Aa}from"react";function Ca(e,t){if(!t?.length)return[e];const n=t.filter(t=>{if(t.id===e||t.id.startsWith(e+"-"))return!0;const n=t.datum;return!(!n||"object"!=typeof n||null==n.id)&&n.id+""===e}).map(e=>e.id);return n.length?n:[e]}function Ra(e,t,n){if("function"==typeof n)return n(e,t)+"";if("string"==typeof n){const t=e[n];if(null!=t)return t+""}return null!=e&&"object"==typeof e&&"id"in e&&null!=e.id?e.id+"":"physics-row-"+t}function Da(e,t){const n=e?.getData().find(e=>e.id===t),i=n?.datum;if(i&&"object"==typeof i)return i}function Pa(e,t){const{frameRef:n,spawnDatum:i,seedRows:o,idAccessor:r,bodyIdsForSeed:s,seedSpawns:a}=t,c=Aa(new Map),l=Aa(new Map),d=Aa(""),u=o?o.map((e,t)=>Ra(e,t,r)).join("\0"):"";if(u!==d.current&&(d.current=u,o))for(let e=0;o.length>e;e+=1){const t=o[e],n=Ra(t,e,r);c.current.set(n,t),l.current.set(n,s?.(t,n,e)??Ca(n,a))}Ia(e,()=>{const e=c.current,t=l.current;function o(e,t){const n=i(e,t);return{datumId:n.datumId||Ra(e,t,r),spawns:n.spawns.map(e=>({...e,spawnAt:void 0}))}}function s(i){const o=[];for(const{datum:n,result:r}of i)e.set(r.datumId,n),t.set(r.datumId,r.spawns.map(e=>e.id)),o.push(...r.spawns);if(!o.length)return;const r=n.current;r?(r.pushMany(o),r.step(0)):"production"!==process.env.NODE_ENV&&console.warn("[semiotic/physics] push() called before the physics frame mounted (loading/empty early-return). Omit data for push mode and ensure the chart is mounted.")}function a(i){const o=e.get(i);if(o)return o;const r=t.get(i)??[i];for(const o of r){const r=Da(n.current,o);if(r)return e.set(i,r),t.has(i)||t.set(i,[o]),r}}return{push:t=>{s([{datum:t,result:o(t,e.size)}])},pushMany:t=>{const n=e.size;s(t.map((e,t)=>({datum:e,result:o(e,n+t)})))},remove:i=>{const o=Array.isArray(i)?i:[i],r=[],s=[];for(const n of o){const i=a(n);i&&r.push(i),e.delete(n),s.push(...t.get(n)??[n]),t.delete(n)}return s.length&&n.current?.remove(s),r},update:(i,r)=>{const c=Array.isArray(i)?i:[i],l=[];for(const i of c){const c=a(i);if(!c)continue;l.push(c);const d=t.get(i)??[i];n.current?.remove(d),e.delete(i),t.delete(i);const u=r(c);s([{datum:u,result:o(u,e.size)}])}return l},clear:()=>{e.clear(),t.clear(),d.current="",n.current?.clear()},getData:()=>{const t=n.current;if(!t)return Array.from(e.values());const i=t.getData().map(e=>e.datum).filter(e=>!!e&&"object"==typeof e);return i.length?i:Array.from(e.values())},getScales:()=>null,getCustomLayout:()=>n.current?.snapshot()??null,popBodies:(e,t)=>n.current?.popBodies(e,t)??[]}},[n,r,i])}import{useMemo as $a}from"react";import*as Ba from"react";import{jsx as ja,jsxs as Ta}from"react/jsx-runtime";function Na({componentName:e,message:t,diagnosticHint:n,width:i,height:o}){return ja("div",{role:"alert",style:{width:i,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"},children:Ta("div",{style:{textAlign:"center",maxWidth:400},children:[ja("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:e}),ja("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:t}),n&&ja("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:n})]})})}import{jsx as Wa}from"react/jsx-runtime";var Ea=class extends Ba.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t)}render(){if(this.state.error){const{fallback:e}=this.props,t=this.state.error;return"function"==typeof e?e(t):void 0!==e?e:Wa(Na,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}};import{jsx as za}from"react/jsx-runtime";function Oa({componentName:e,width:t,height:n,children:i}){return za(Ea,{fallback:i=>za(Na,{componentName:e,message:i.message,width:t,height:n}),children:i})}"undefined"!=typeof process&&process;var Fa={display:"flex",alignItems:"center",justifyContent:"center",color:"var(--semiotic-text-secondary, #666)",fontSize:13,fontFamily:"inherit",border:"1px dashed var(--semiotic-border, #ddd)",borderRadius:4,boxSizing:"border-box"},La={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};import{useMemo as qa,useCallback as Ya,useState as Ha,useId as Ga,useEffect as Xa,useRef as _a}from"react";import{scaleOrdinal as Va}from"d3-scale";function Ua(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function Ka(e,t,n){const i=e=>e.toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(n)}`}function Qa(e){const t=e.map(Ua),n=t.length-1;return e=>{if(0>=e){const[e,n,i]=t[0];return Ka(e,n,i)}if(e>=1){const[e,i,o]=t[n];return Ka(e,i,o)}const i=e*n,o=Math.floor(i),r=i-o,[s,a,c]=t[o],[l,d,u]=t[o+1];return Ka(Math.round(s+(l-s)*r),Math.round(a+(d-a)*r),Math.round(c+(u-c)*r))}}var Za=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],Ja=Qa(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),ec=Qa(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),tc=Qa(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),nc=Qa(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),ic=Qa(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),oc=Qa(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),rc={blues:Ja,reds:ec,greens:tc,viridis:Qa(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),oranges:nc,purples:ic,greys:oc,plasma:Qa(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:Qa(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:Qa(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:Qa(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:Qa(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])},sc=(Qa(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),Qa(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),Qa(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Qa(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Qa(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Qa(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Qa(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),{category10:Za,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...rc});function ac(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;const n=e[t];return"string"==typeof n&&n.length>0?n:void 0}function cc(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var lc={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function dc(e,t={}){const n=t.mobileSemantics?.interaction,i="number"==typeof n?.targetSize?n.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,o="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,r=!!n||void 0!==i,s=e&&"object"==typeof e?e:void 0;if(!1===e||!1===s?.enabled||void 0===e&&!o&&!r)return lc;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??i??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var uc={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function hc(e,t,n){if(!1!==t)return e;const i={...e};return"horizontal"===n?i.left=Math.min(i.left,15):i.bottom=Math.min(i.bottom,15),i}import{Fragment as pc,jsx as fc,jsxs as mc}from"react/jsx-runtime";var yc=new Set(["sample","mechanical"]);function gc(e,t,n){const i=n?.hasSimulationMode?function(e){const t=e=>"string"==typeof e&&yc.has(e);return e.simulationMode?{chartMode:t(e.mode)?void 0:e.mode,simulationMode:e.simulationMode}:t(e.mode)?{chartMode:void 0,simulationMode:e.mode}:{chartMode:e.mode,simulationMode:"sample"}}({mode:e.mode,simulationMode:e.simulationMode}):{chartMode:"sample"===e.mode||"mechanical"===e.mode?void 0:e.mode,simulationMode:"sample"},o=function(e,t,n){const i=uc[e||"primary"],o=e&&"primary"!==e||!n?.width?i.width:n.width,r=e&&"primary"!==e||!n?.height?i.height:n.height,s=function(e,t,n=e.responsiveRules){if(!Array.isArray(n)||0===n.length)return{props:e,matches:[]};const i=n.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){const{when:n}=e,i=t.width,o=t.height,r=function(e){if("number"==typeof e.height&&e.height>0)return e.width/e.height}(t),s=function(e){if("number"==typeof e.height&&e.height>0)return e.height>e.width?"portrait":"landscape"}(t);return!("number"==typeof n.minWidth&&n.minWidth>i||"number"==typeof n.maxWidth&&i>n.maxWidth||"number"==typeof n.minHeight&&("number"!=typeof o||n.minHeight>o)||"number"==typeof n.maxHeight&&("number"!=typeof o||o>n.maxHeight)||"number"==typeof n.minAspectRatio&&("number"!=typeof r||n.minAspectRatio>r)||"number"==typeof n.maxAspectRatio&&("number"!=typeof r||r>n.maxAspectRatio)||n.orientation&&s!==n.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:i.reduce((e,t)=>function(e,t){const n={...e,...t};for(const i of["margin","frameProps","mobileSemantics","style"])cc(e[i])&&cc(t[i])&&(n[i]={...e[i],...t[i]});return"string"==typeof e.className&&"string"==typeof t.className&&(n.className=`${e.className} ${t.className}`),n}(e,t.rule.transform),e),matches:i}}({...t,mode:e},{width:t.width??o,height:t.height??r}).props,a=s.mode||e,c=uc[a||"primary"],l="context"===a||"sparkline"===a,d=a&&"primary"!==a||!n?.width?c.width:n.width;return{width:s.width??d,height:s.height??(a&&"primary"!==a||!n?.height?c.height:n.height),showAxes:s.showAxes??c.showAxes,showGrid:s.showGrid??c.showGrid,enableHover:s.enableHover??(!!s.linkedHover||c.enableHover),showLegend:s.showLegend??c.showLegend,showLabels:s.showLabels??c.showLabels,title:l?void 0:s.title,description:s.description,summary:s.summary,accessibleTable:s.accessibleTable,xLabel:l?void 0:s.xLabel,yLabel:l?void 0:s.yLabel,categoryLabel:l?void 0:s.categoryLabel,valueLabel:l?void 0:s.valueLabel,marginDefaults:hc(c.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:l,mobileInteraction:dc(s.mobileInteraction,{mode:a,width:s.width??d,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}(i.chartMode,{width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:t[0],height:t[1]}),r=e.size?.[0],s=e.size?.[1],a=t[0],c=t[1],l=$a(()=>{return e=[a,c],(null!=r&&null!=s?[r,s]:void 0)??[o.width??e[0],o.height??e[1]];var e},[c,a,o.height,o.width,s,r]),d=o.compactMode?"sparkline"===i.chartMode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0};const u=e.showProjection??!o.compactMode,h=e.showChrome??!o.compactMode,p=wc(e.tooltip,void 0),f=void 0!==p.enableHover?p.enableHover:o.enableHover,m=o.compactMode?o.title:o.title??e.title,y=[e.className,i.chartMode&&"primary"!==i.chartMode?"semiotic-physics--"+i.chartMode:null].filter(Boolean).join(" ")||void 0;return{chartMode:i.chartMode,simulationMode:i.simulationMode,resolved:o,chartSize:l,margin:d,showProjection:u,showChrome:h,enableHover:f,title:m,description:o.description??e.description,summary:o.summary??e.summary,accessibleTable:o.accessibleTable??e.accessibleTable,className:y,compactMode:o.compactMode,mobileInteraction:o.mobileInteraction,mobileSemantics:o.mobileSemantics}}function bc(e){const[t,n]=e.size,i=function(e,t,n,i){if(!e)return null;if(!1===i)return null;if(null!=i)return za("div",{style:{width:t,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:i});const o=Math.min(5,Math.floor(n/40)),r=Math.max(8,Math.floor(n/(3*o))),s=Math.max(6,Math.floor(n/(2.5*o))),a=Math.floor((n-(o*(r+s)-s))/2);return za("div",{style:{width:t,height:n,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:o},(e,n)=>za("div",{className:"semiotic-loading-bar",style:{...La,position:"absolute",top:a+n*(r+s),left:Math.floor(.1*t),width:30+(37*n+13)%50+"%",height:r,opacity:.5+n%2*.2}},n))})}(e.loading,t,n,e.loadingContent);return i||function(e,t,n,i){return!1===i||null==e||Array.isArray(e)&&e.length>0?null:Array.isArray(e)?za("div",{style:{...Fa,width:t,height:n},children:i||"No data available"}):null}(e.data,t,n,e.emptyContent)}function xc(e,t,n){return fc(Oa,{componentName:e,width:t[0],height:t[1],children:n})}function vc(e,t){return e?t?n=>mc(pc,{children:["function"==typeof e?e(n):e,"function"==typeof t?t(n):t]}):e:t}function wc(e,t){return!1===e?{enableHover:!1}:{enableHover:t?.enableHover,tooltipContent:Ve(e)||t?.tooltipContent}}function kc(e,t,n,i){return{accessibleTable:i?.accessibleTable??e.accessibleTable??t?.accessibleTable,annotations:e.annotations??t?.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations??t?.autoPlaceAnnotations,background:e.background??t?.background,chartId:e.chartId??t?.chartId,chartMode:i?.chartMode??t?.chartMode,className:i?.className??e.className??t?.className,color:e.color??t?.color,description:i?.description??e.description??t?.description,emphasis:e.emphasis??t?.emphasis,enableHover:i?.enableHover??t?.enableHover,hoverRadius:e.hoverRadius??t?.hoverRadius,legend:e.legend??t?.legend,legendLayout:e.legendLayout??t?.legendLayout,legendPosition:e.legendPosition??t?.legendPosition,margin:i?.margin??t?.margin,onClick:null!=e.onClick?(t,n)=>{t&&e.onClick?.(t,{x:n.x,y:n.y})}:t?.onClick,onObservation:e.onObservation??t?.onObservation,onAnnotationActivate:t?.onAnnotationActivate,opacity:e.opacity??t?.opacity,semanticItems:t?.semanticItems??n,stroke:e.stroke??t?.stroke,strokeWidth:e.strokeWidth??t?.strokeWidth,summary:i?.summary??e.summary??t?.summary,svgAnnotationRules:e.svgAnnotationRules??t?.svgAnnotationRules,title:i?.title??e.title??t?.title}}import{Fragment as Mc,jsx as Sc,jsxs as Ic}from"react/jsx-runtime";var Ac=e(function(e,o){const{data:r,valueAccessor:s="value",styleRules:a,bins:c=21,ballRadius:l=6,colorBy:d,branchProbability:u=.5,emptyContent:h,frameProps:p,loading:f,loadingContent:m,mechanicalCount:y,paused:g,pegRows:b,referenceLines:x,responsiveHeight:v,responsiveWidth:w,seed:k=1,valueExtent:M}=e,S=gc(e,[700,420],{hasSimulationMode:!0}),{chartSize:I,simulationMode:A,showProjection:C,className:R,title:D,chartMode:P,margin:$,enableHover:B,description:j,summary:T,accessibleTable:N}=S,W=i(null),E=Math.max(1,Math.round(b??c-1)),z=n(()=>"mechanical"===A?[0,E]:function(e){if(!e)return;const t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?t>n?[n,t]:[t,n]:void 0}(M),[E,A,M]),O=n(()=>"mechanical"===A?function(e){const t=Math.max(2,Math.round(e.bins)),n=Math.max(1,Math.round(e.pegRows??t-1)),i=Math.max(1,Math.round(e.count??Math.max(64,4*t))),o=Ws(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Os(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:i},(e,t)=>{let i=0;for(let e=0;n>e;e+=1)r()<o&&(i+=1);const a=n/2;return{id:`${s}-${t}`,value:i,mechanical:!0,pegRows:n,branchProbability:o,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:c,branchProbability:u,count:y,pegRows:E,seed:k}):r??[],[c,u,r,y,E,k,A]),F=n(()=>Ls({data:O,valueAccessor:s,bins:c,ballRadius:l,seed:k,size:I,valueExtent:z}),[l,c,O,I,z,k,s]);Pa(o,{frameRef:W,spawnDatum:t((e,t)=>{const n=Ls({data:[e],valueAccessor:s,bins:c,ballRadius:l,seed:k+t+1,size:I,valueExtent:z}).initialSpawns[0]??{id:(e.id??"galton-push-"+t)+"",x:Ds(I).plot.x,y:Ds(I).plot.y,mass:1,shape:{type:"circle",radius:l},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[l,c,I,z,k,s]),seedRows:O,seedSpawns:F.initialSpawns});const L="mechanical"===A&&null==d?"side":d,q=n(()=>$s(L,"#4e79a7",{styleRules:a,valueAccessor:s}),[L,a,s]),Y=n(()=>js(F.projectionRows,I,"bin"),[I,F.projectionRows]),H=bc({data:"mechanical"===A?O:r,emptyContent:h,loading:f,loadingContent:m,size:I});if(H)return H;const G=function(e,t,n,i,o){const r=Array.isArray(o)?o:o?[o]:[];if(!1!==n||0!==r.length)return({size:o})=>{const s=[Number(o[0])||700,Number(o[1])||420],a=Ds(s),c=Math.max(2,Math.round(t)),l=a.plot.width/c,d=a.plot.y+a.plot.height,u=Math.max(1,...e.map(e=>e.value)),h=!1!==n,[p,f]=i?.valueExtent??[0,c],m=f===p?1:f-p,y=e.map((e,t)=>{const n=d-e.value/u*a.plot.height*.9;return`${0===t?"M":"L"} ${(a.plot.x+(t+.5)*l).toFixed(1)} ${n.toFixed(1)}`}).join(" ");return Ic("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:s[0],height:s[1],viewBox:`0 0 ${s[0]} ${s[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?Ic(Mc,{children:[Array.from({length:c+1},(e,t)=>{const n=a.plot.x+t*l;return Sc("line",{"data-testid":"galton-board-bin-wall",x1:n,x2:n,y1:a.plot.y,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+t)}),Sc("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),Sc("path",{d:y,fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>e.value>0?Sc("text",{x:a.plot.x+(t+.5)*l,y:Math.max(a.plot.y+10,d-e.value/u*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`):null)]}):null,r.map((e,t)=>{const n=Number(e.value);if(!Number.isFinite(n))return null;const i=a.plot.x+Math.max(0,Math.min(1,(n-p)/m))*a.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===e.labelPosition?Math.min(s[1]-8,d+16):a.plot.y+16;return Ic("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[Sc("line",{x1:i,x2:i,y1:a.plot.y+8,y2:d-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:Sc("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:r,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${n}`)})]})}}(F.projectionRows,c,C,F.metadata,x),X=wc(e.tooltip,p),_=kc(e,p,Y,{chartMode:P,className:R,title:D,description:j,summary:T,accessibleTable:N,enableHover:B,margin:$});return xc("GaltonBoardChart",I,Sc(ks,{...p,...X,..._,ref:W,config:F.config,foregroundGraphics:vc(G,p?.foregroundGraphics),initialSpawns:F.initialSpawns,initialSpawnPacing:F.initialSpawnPacing,paused:g,responsiveHeight:v,responsiveWidth:w,size:I,bodyStyle:q}))});import{forwardRef as Cc,useCallback as Rc,useMemo as Dc,useRef as Pc}from"react";import{jsx as $c,jsxs as Bc}from"react/jsx-runtime";var jc=Cc(function(e,t){const{arrivalAccessor:n="arrivalTime",ballRadius:i=7,colorBy:o,styleRules:r,data:s,emptyContent:a,frameProps:c,loading:l,loadingContent:d,paused:u,responsiveHeight:h,responsiveWidth:p,seed:f=1,timeAccessor:m="time",timeExtent:y,timeScale:g=1,watermark:b,windows:x={size:10}}=e,v=gc(e,[760,360]),{chartSize:w,showProjection:k,className:M,title:S,chartMode:I,margin:A,enableHover:C,description:R,summary:D,accessibleTable:P}=v,$=Pc(null),B=Dc(()=>s??[],[s]),j=Dc(()=>Hs({data:B,timeAccessor:m,arrivalAccessor:n,windows:x,watermark:b,ballRadius:i,seed:f,size:w,timeExtent:y,timeScale:g}),[n,i,w,B,f,m,y,g,b,x]),T=j.metadata;Pa(t,{frameRef:$,spawnDatum:Rc((e,t)=>{const o=T?function(e,t,n,i){const o=Ns(Ts(e,t,i.timeAccessor));if(null==o)return null;const r=Ns(Ts(e,t,i.arrivalAccessor))??o,{windowPlot:s,windowStart:a,windowCount:c,windowSize:l,watermarkValue:d}=n,u=a+c*l,h=qs().domain([a,u]).range([s.x,s.x+s.width]),p=Math.max(0,Math.min(c-1,Math.floor((o-a)/l))),f=d>=a+(p+1)*l,{ballRadius:m}=i;return{id:(e.id??"event-push-"+t)+"",x:Math.max(s.x+m,Math.min(s.x+s.width-m,h(o))),y:s.y+m+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,shape:{type:"circle",radius:m},datum:{...e,eventTime:o,arrivalTime:r,windowIndex:p,late:f}}}(e,t,T,{timeAccessor:m,arrivalAccessor:n,ballRadius:i}):null,r=o??{id:(e.id??"event-push-"+t)+"",x:Ds(w).plot.x,y:Ds(w).plot.y,mass:1,shape:{type:"circle",radius:i},datum:e};return{datumId:(e.id??r.id)+"",spawns:[r]}},[n,i,w,T,m]),seedRows:B,seedSpawns:j.initialSpawns});const N=Dc(()=>$s(o,"#4e79a7",{styleRules:r,valueAccessor:m}),[o,r,m]),W=Dc(()=>function(e,t,n){if(!t)return js(e,n,"window");const i=t.windowPlot.width/Math.max(1,e.length),o=Math.max(1,...e.map(e=>e.value+(e.secondary??0))),r=.62*t.windowPlot.height,s=t.windowPlot.y+t.windowPlot.height;return e.map((e,n)=>{const a=Math.max(8,(e.value+(e.secondary??0))/o*r),c=`window ${e.label}: ${e.value} on time${e.secondary?`, ${e.secondary} late`:""}`;return{id:"window-"+e.label,label:c,description:c,datum:e,x:t.windowPlot.x+(n+.5)*i,y:s-a/2,shape:"rect",width:Math.max(12,.58*i),height:a,group:"window"}})}(j.projectionRows,T,w),[w,j.projectionRows,T]),E=bc({data:s,emptyContent:a,loading:l,loadingContent:d,size:w});if(E)return E;const z=function(e,t,n){if(!1!==n&&t)return({size:n})=>{const i=[Number(n[0])||760,Number(n[1])||360],o=Ds(i),r=Math.max(1,t.windowCount),s=t.plot??o.plot,a=t.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=t.windowPlot??s,l=c.width/r,d=s.y+s.height,u=s.y+.48*s.height,h=t.lidSegments[0]?.y1??u,p=t.windowStart,f=t.windowStart+r*t.windowSize,m=c.x+Math.max(0,Math.min(1,f===p?0:(t.watermarkValue-p)/(f-p)))*c.width;return Bc("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[$c("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),a.width>0?Bc("g",{children:[$c("rect",{x:a.x,y:h,width:a.width,height:d-h,fill:"var(--semiotic-negative, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),$c("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(n,o)=>{const r=e[o],s=c.x+o*l,a=t.closedWindowCount>o,h=r?.secondary??0;return Bc("g",{children:[$c("rect",{x:s,y:u,width:l,height:d-u,fill:a?"var(--semiotic-negative, #e15759)":"var(--semiotic-accent, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?t.lidSegments.filter(e=>e.windowIndex===o).map(e=>$c("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,Bc("text",{x:s+l/2,y:u-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),$c("text",{x:s+l/2,y:Math.min(i[1]-8,d+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+o)}),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>$c("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),$c("line",{x1:s.x,x2:s.x+s.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),$c("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:s.y+8,y2:d,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),Bc("text",{x:Math.min(s.x+s.width-4,m+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]}),t.lateCount>0?Bc("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]}):null]})}}(j.projectionRows,j.metadata,k),O=wc(e.tooltip,c),F=kc(e,c,W,{chartMode:I,className:M,title:S,description:R,summary:D,accessibleTable:P,enableHover:C,margin:A});return xc("EventDropChart",w,$c(ks,{...c,...O,...F,ref:$,config:j.config,foregroundGraphics:vc(z,c?.foregroundGraphics),initialSpawns:j.initialSpawns,initialSpawnPacing:j.initialSpawnPacing,paused:u,responsiveHeight:h,responsiveWidth:p,size:w,bodyStyle:N}))});import{forwardRef as Tc,useCallback as Nc,useMemo as Wc,useRef as Ec}from"react";import{jsx as zc,jsxs as Oc}from"react/jsx-runtime";var Fc=Tc(function(e,t){const{ballRadius:n=8,categoryAccessor:i="category",colorBy:o,data:r,emptyContent:s,frameProps:a,loading:c,loadingContent:l,mechanicalCategories:d,mechanicalCount:u,paused:h,responsiveHeight:p,responsiveWidth:f,seed:m=1,unitValue:y=1,valueAccessor:g,styleRules:b}=e,x=gc(e,[700,380],{hasSimulationMode:!0}),{chartSize:v,simulationMode:w,showProjection:k,className:M,title:S,chartMode:I,margin:A,enableHover:C,description:R,summary:D,accessibleTable:P}=x,$=Ec(null),B="mechanical"===w&&null==g?"value":g,j=Wc(()=>"mechanical"===w?function(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),n=t.length?t:["Intake"],i=Math.max(n.length,Math.round(e.count??Math.max(48,12*n.length))),o=Es(e.unitValue,1),r=Os(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),c=a.reduce((e,t)=>e+t,0)||1,l=i-n.length,d=a.map(e=>e/c*l),u=d.map(e=>1+Math.floor(e));let h=i-u.reduce((e,t)=>e+t,0);const p=d.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%p.length)u[p[e].index]+=1,h-=1;return n.map((e,t)=>({id:`${s}-${t}`,category:e,value:u[t]*o,mechanical:!0,unitCount:u[t],unitValue:o,share:u[t]/i}))}({categories:d,count:u,seed:m,unitValue:y}):r??[],[r,d,u,m,w,y]),T=Wc(()=>Xs({data:j,categoryAccessor:i,valueAccessor:B,unitValue:y,ballRadius:n,seed:m,size:v}),[n,i,v,j,B,m,y]);Pa(t,{frameRef:$,spawnDatum:Nc((e,t)=>{const o=Xs({data:[e],categoryAccessor:i,valueAccessor:B,unitValue:y,ballRadius:n,seed:m+t+1,size:v}),r={id:(e.id??"pile-push-"+t)+"",x:Ds(v).plot.x,y:Ds(v).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e},s=o.initialSpawns.length?o.initialSpawns:[r];return{datumId:(e.id??s[0].id)+"",spawns:s}},[n,i,v,B,m,y]),seedRows:j,seedSpawns:T.initialSpawns});const N="mechanical"===w&&null==o?"category":o,W=Wc(()=>$s(N,"#4e79a7",{styleRules:b,valueAccessor:g}),[N,b,g]),E=Wc(()=>js(T.projectionRows,v,"category"),[v,T.projectionRows]),z=bc({data:"mechanical"===w?j:r,emptyContent:s,loading:c,loadingContent:l,size:v});if(z)return z;const O=function(e,t,n){if(!1!==n&&0!==e.length)return({size:n})=>{const i=[Number(n[0])||700,Number(n[1])||380],o=Ds(i),r=Gs(o.plot,e.length,t),s=o.plot.y+o.plot.height;return Oc("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[zc("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{const n=Math.min(o.plot.height,r.pileHeight(e.value)),a=r.tubeWidth,c=r.centerX(t),l=s-n;return Oc("g",{children:[zc("rect",{x:c-a/2,y:l,width:a,height:n,rx:3,fill:"var(--semiotic-accent, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),zc("text",{x:c,y:Math.max(o.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),zc("text",{x:c,y:Math.min(i[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)})]})}}(T.projectionRows,n,k),F=wc(e.tooltip,a),L=kc(e,a,E,{chartMode:I,className:M,title:S,description:R,summary:D,accessibleTable:P,enableHover:C,margin:A});return xc("PhysicsPileChart",v,zc(ks,{...a,...F,...L,ref:$,config:T.config,foregroundGraphics:vc(O,a?.foregroundGraphics),initialSpawns:T.initialSpawns,initialSpawnPacing:T.initialSpawnPacing,paused:h,responsiveHeight:p,responsiveWidth:f,size:v,bodyStyle:W}))});import{forwardRef as Lc,useCallback as qc,useMemo as Yc,useRef as Hc}from"react";var Gc=Object.freeze([]);function Xc(e){if(!e)return Gc;let t=!1;for(let n=0;e.length>n;n++){const i=e[n];if(null==i||"object"!=typeof i){t=!0;break}}if(!t)return e;const n=[];for(const t of e)null!=t&&"object"==typeof t&&n.push(t);return n}import{scaleLinear as _c}from"d3-scale";function Vc(e,t){const n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>n&&ac(n,e)||"#4e79a7":t=>{if(n){const e=ac(n,t);if(e)return e}let i=0;for(let e=0;t.length>e;e++)i=31*i+t.charCodeAt(e)|0;return e[Math.abs(i)%e.length]??"#4e79a7"}}function Uc(e,t){const n=t.config??{},i=(t.sensors??[]).map(e=>({...e,sensor:!0})),o=[...t.colliders??[],...i],r=[...e.colliders??[],...n.colliders??[],...o];return{...e,...n,observation:{...e.observation,...n.observation},...r.length>0&&{colliders:r}}}function Kc(e){const t=function(e,t,n){const i=e?.observation;return{...e,observation:{...i,chartId:t??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:n??i?.onObservation}}}(e.config,e.chartId,e.onObservation),n=function(e,t,n){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){const t=sc[e];if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:n}(e.colorScheme,e.themeCategorical,Za),i=Ds(e.size),o={data:e.data,scales:{x:_c().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:_c().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Vc(n,e.colorScheme),config:e.layoutConfig??{},world:new ko(t)},r=e.skipLayout?{}:e.layout(o)??{},s=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...i}=e,o=n.get(t)??[];o.push(i),n.set(t,o)}return e.map(e=>{const t=n.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Uc(t,r),context:o,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}import{jsx as Qc}from"react/jsx-runtime";var Zc=Lc(function(e,t){const{chartId:n,color:i,colorBy:o,colorScheme:r,config:s,controllers:a,data:c,emptyContent:l,frameProps:d={},layout:u,layoutConfig:h,loading:p,loadingContent:f,onObservation:m,opacity:y,paused:g,spawnDatum:b,stroke:x,strokeWidth:v,title:w,xExtent:k,yExtent:M}=e,S=gc(e,[700,380]),{chartSize:I,className:A,title:C,chartMode:R,margin:P,enableHover:$,description:B,summary:j,accessibleTable:N}=S,W=Hc(null),E=Hc(null),z=Hc(""),O=bc({data:c,emptyContent:l,loading:p,loadingContent:f,size:I}),F=null!=O,L=Yc(()=>Xc(c??[]),[c]),q=T(e=>e.theme),Y=Yc(()=>function(e){if(!e?.colors)return;const t=e.colors;return{primary:t.primary,secondary:t.secondary||t.primary,surface:t.surface||t.background,success:t.success,danger:t.danger,warning:t.warning,error:t.error,info:t.info,text:t.text,textSecondary:t.textSecondary,border:t.border,grid:t.grid}}(q)??{},[q]),H=q?.colors?.categorical??D.colors.categorical,G=Yc(()=>[I[0],I[1],L.length,L.map((e,t)=>(e.id??t)+"").join("|"),k?.join(",")??"",M?.join(",")??""].join("::"),[I,L,k,M]),X=Yc(()=>Kc({chartId:n,colorScheme:r,config:s,data:L,layout:u,layoutConfig:h,onObservation:m,semantic:Y,skipLayout:F,size:I,themeCategorical:H,xExtent:k,yExtent:M}),[n,I,r,s,u,h,m,L,Y,F,H,k,M]);z.current===G&&null!=E.current||(z.current=G,E.current=X.initialSpawns);const _=E.current,V=Yc(()=>{const e=[...X.result.controllers??[],...a??[],...d.controllers??[]];return e.length?e:void 0},[d.controllers,a,X.result.controllers]),U=Yc(()=>{const e=[...X.result.regionEffects??[],...d.regionEffects??[]];return e.length?e:void 0},[d.regionEffects,X.result.regionEffects]),K=qc(e=>{const t=e.datum,n=t&&o?function(e,t,n){return"function"==typeof n?n(e,0):e[n]}(t,0,o)+"":e.id;return{fill:i??X.context.resolveColor(n,t),stroke:x??"#111827",strokeWidth:v??1,opacity:y??.9}},[i,o,y,X.context,x,v]);Pa(t,{frameRef:W,spawnDatum:qc((e,t)=>{const i=e;if(b)return function(e,t,n){return Array.isArray(n)?{datumId:(e.id??n[0]?.id??"physics-custom-"+t)+"",spawns:n}:"spawns"in n?n:{datumId:(e.id??n.id??"physics-custom-"+t)+"",spawns:[n]}}(e,t,b(i,t,X.context));const o=Kc({chartId:n,colorScheme:r,config:s,data:[i],layout:u,layoutConfig:h,onObservation:m,semantic:Y,size:I,themeCategorical:H,xExtent:k,yExtent:M}),a=o.initialSpawns.length?o.initialSpawns:[{id:(e.id??"physics-custom-"+t)+"",x:o.context.dimensions.plot.x+o.context.dimensions.plot.width/2,y:o.context.dimensions.plot.y+12,mass:1,shape:{type:"circle",radius:5},datum:e}];return{datumId:(e.id??a[0].id)+"",spawns:a}},[n,I,r,s,b,u,h,m,X.context,Y,H,k,M]),seedRows:L,seedSpawns:_});const Q=qc((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]);if(O)return O;const Z=wc(e.tooltip,d),J=kc(e,d,X.result.semanticItems,{chartMode:R,className:A,title:C??w,description:B,summary:j,accessibleTable:N,enableHover:$,margin:P});return xc("PhysicsCustomChart",I,Qc(ks,{...d,...Z,...J,ref:W,backgroundGraphics:vc(d.backgroundGraphics,X.result.backgroundOverlays),bodyForces:X.result.bodyForces??d.bodyForces,bodyStyle:X.result.bodyStyle??d.bodyStyle??K,config:X.config,controllers:V,foregroundGraphics:vc(d.foregroundGraphics,X.result.overlays),initialSpawnPacing:X.initialSpawnPacing,initialSpawns:_,onBodyPointerDown:Q,paused:g,regionEffects:U,responsiveHeight:e.responsiveHeight,responsiveWidth:e.responsiveWidth,selectedBodyStyle:X.result.selectedBodyStyle??d.selectedBodyStyle,size:I}))});Zc.displayName="PhysicsCustomChart";import{forwardRef as Jc,useCallback as el,useMemo as tl,useRef as nl}from"react";import{jsx as il,jsxs as ol}from"react/jsx-runtime";function rl(e){return e.toLocaleString(void 0,Math.abs(e)>=1e3||.01>Math.abs(e)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}var sl=Jc(function(e,t){const{colorBy:n,styleRules:i,collisionIterations:o,data:r,emptyContent:s,frameProps:a,groupAccessor:c,loading:l,loadingContent:d,paused:u,pointRadius:h=5,radiusAccessor:p,responsiveHeight:f,responsiveWidth:m,seed:y=1,settle:g,xAccessor:b="x",xExtent:x}=e,v=gc(e,[700,360]),{chartSize:w,showProjection:k,className:M,title:S,chartMode:I,margin:A,enableHover:C,description:R,summary:D,accessibleTable:P}=v,$=nl(null),B=tl(()=>r??[],[r]),j=tl(()=>Vs({data:B,xAccessor:b,groupAccessor:c,radiusAccessor:p,pointRadius:h,seed:y,size:w,xExtent:x,collisionIterations:o,settle:g}),[B,w,o,c,h,p,y,g,b,x]);Pa(t,{frameRef:$,spawnDatum:el((e,t)=>{const n=Vs({data:[e],xAccessor:b,groupAccessor:c,radiusAccessor:p,pointRadius:h,seed:y+t+1,size:w,xExtent:x,collisionIterations:o,settle:g}).initialSpawns[0]??{id:(e.id??"collision-swarm-push-"+t)+"",x:Ds(w).plot.x,y:Ds(w).plot.y,mass:1,shape:{type:"circle",radius:h},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[w,o,c,h,p,y,g,b,x]),seedRows:B,seedSpawns:j.initialSpawns});const T=n??c,N=tl(()=>$s(T,"#4e79a7",{styleRules:i,valueAccessor:b}),[T,i,b]),W=bc({data:r,emptyContent:s,loading:l,loadingContent:d,size:w});if(W)return W;const E=function(e,t){if(!1!==t&&e)return({size:t})=>{const n=[Number(t[0])||700,Number(t[1])||360],i=Ds(n),o=i.plot.y+i.plot.height,[r,s]=e.xExtent,a=r+(s-r)/2,c=[{label:rl(r),x:e.xRange[0]},{label:rl(a),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:rl(s),x:e.xRange[1]}];return ol("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.map(e=>ol("g",{children:[il("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),il("text",{x:i.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),ol("text",{x:i.plot.x+i.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count]})]},e.label)),il("line",{x1:e.xRange[0],x2:e.xRange[1],y1:o,y2:o,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(e=>ol("g",{children:[il("line",{x1:e.x,x2:e.x,y1:o,y2:o+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),il("text",{x:e.x,y:Math.min(n[1]-8,o+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}(j.metadata,k),z=function(e){if(!e)return[];const t=Math.max(24,e.xRange[1]-e.xRange[0]),n=e.xRange[0]+t/2;return e.groups.map(e=>{const i=`${e.label} lane: ${e.count} points`;return{id:"collision-swarm-"+e.label,label:i,description:i,datum:e,x:n,y:e.y,shape:"rect",width:t,height:28,group:"lane"}})}(j.metadata),O=wc(e.tooltip,a),F=kc(e,a,z,{chartMode:I,className:M,title:S,description:R,summary:D,accessibleTable:P,enableHover:C,margin:A});return xc("CollisionSwarmChart",w,il(ks,{...a,...O,...F,ref:$,config:j.config,foregroundGraphics:vc(E,a?.foregroundGraphics),initialSpawns:j.initialSpawns,paused:u,responsiveHeight:f,responsiveWidth:m,size:w,bodyStyle:N}))});function al(e,t,n={}){return Number.isFinite(t)&&t>0?Number.isNaN(e)?"fresh":e===1/0?"expired":0>e||t*(n.fresh??1)>e?"fresh":t*(n.aging??1.5)>e?"aging":t*(n.stale??3)>e?"stale":"expired":"fresh"}function cl(e,t,n){if(null!=e)return"function"==typeof e?e(t,n):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}function ll(e){const{data:t,encoding:n}=e,i=[],o=new Map;return t.forEach((e,t)=>{const r=cl(n.id,e,t);if(null==r||""===r)throw Error(`[semiotic] Motion encoding row ${t} resolved an empty id.`);const s=r+"";if(o.has(s))throw Error(`[semiotic] Duplicate motion encoding id "${s}".`);const a=cl(n.process?.group,e,t),c=cl(n.process?.stage,e,t),l=cl(n.accessible?.group,e,t)??(null!=a?a+"":null!=c?c+"":void 0),d={};for(const i of Object.keys(n.evidence??{}))d[i]=cl(n.evidence?.[i],e,t);const u={id:s,datum:e,time:{arrival:cl(n.time?.arrival,e,t),basis:n.time?.basis,unit:n.time?.unit},placement:{x:cl(n.placement?.x,e,t),y:cl(n.placement?.y,e,t),lane:cl(n.placement?.lane,e,t),space:n.placement?.space},kinematics:{velocityX:cl(n.kinematics?.velocityX,e,t),velocityY:cl(n.kinematics?.velocityY,e,t),space:n.kinematics?.space},process:{group:a,stage:c,target:cl(n.process?.target,e,t),work:cl(n.process?.work,e,t)},evidence:d,accessible:{description:cl(n.accessible?.description,e,t),group:l,label:cl(n.accessible?.label,e,t)??s}};i.push(u),o.set(s,u)}),{rows:i,byId:o}}function dl(e){const t=e.now-e.arrival;return{age:t,progress:Number.isFinite(t)&&Number.isFinite(e.ttl)&&e.ttl>0?Math.max(0,t)/e.ttl:t===1/0&&Number.isFinite(e.ttl)&&e.ttl>0?1/0:0,lifecycle:al(t,e.ttl,e.thresholds)}}function ul(e){const t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||0>=e.extent)return 1;const n=Math.max(0,e.age);if("step"===e.type)return(e.threshold??.5*e.extent)>n?1:t;if("exponential"===e.type){const i=e.halfLife??e.extent/2;return t+Math.pow(.5,n/(i>0?i:e.extent/2))*(1-t)}return t+Math.max(0,Math.min(1,1-n/e.extent))*(1-t)}function hl(e,t){const n=Number.isFinite(e)?e:0,i=Number.isFinite(t)?t:0;return{velocityX:n,velocityY:i,speed:Math.hypot(n,i),direction:Math.atan2(i,n)}}function pl(e,t,n){return Number.isFinite(n)&&n>0?hl((t.x-e.x)/n,(t.y-e.y)/n):hl(0,0)}function fl(e){const{data:t,encoding:n,defaults:i={},scales:o}=e,r=ll({data:t,encoding:n}),s=[],a=new Map,c=[],l=[],d=new Map;return r.rows.forEach((e,t)=>{const{id:r,datum:u}=e,h=Math.max(0,cl(n.appearance?.size,u,t)??i.size??6),p=cl(n.appearance?.shape,u,t)??i.shape??{type:"circle",radius:h},f=e.placement.x??i.x??0,m=e.placement.y??i.y??0,y=o?.x?o.x(f):f,g=o?.y?o.y(m):m,b=cl(n.appearance?.color,u,t)??i.color,x=cl(n.appearance?.opacity,u,t)??i.opacity,v=cl(n.appearance?.stroke,u,t)??i.stroke,w=cl(n.appearance?.strokeWidth,u,t)??i.strokeWidth,k=cl(n.time?.spawnAt,u,t)??e.time.arrival,M=e.kinematics.velocityX,S=e.kinematics.velocityY,I=cl(n.dynamics?.mass,u,t)??i.mass??1,A=cl(n.dynamics?.friction,u,t),C=cl(n.dynamics?.restitution,u,t),R=cl(n.dynamics?.bodyCollisions,u,t),D={id:r,x:y,y:g,mass:I,shape:{...p},datum:u,...null!=k&&{spawnAt:k},...null!=M&&{vx:M},...null!=S&&{vy:S},...null!=A&&{friction:A},...null!=C&&{restitution:C},...null!=R&&{bodyCollisions:R}},P={...null!=b&&{fill:b},...null!=x&&{opacity:x},...null!=v&&{stroke:v},...null!=w&&{strokeWidth:w}},$={id:r,datum:u,appearance:{color:b,opacity:x,shape:p,size:h,stroke:v,strokeWidth:w},placement:{x:y,y:g,lane:e.placement.lane,space:n.placement?.space??"world"},time:{arrival:k,spawnAt:k,basis:n.time?.basis??"simulation",unit:n.time?.unit},kinematics:{velocityX:M,velocityY:S,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:R,friction:A,mass:I,restitution:C},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:D};s.push($),a.set(r,$),c.push(D),d.set(r,P),l.push({id:r,bodyId:r,label:e.accessible.label,description:e.accessible.description,datum:u,x:y,y:g,group:e.accessible.group})}),{rows:s,byId:a,spawns:c,semanticItems:l,bodyStyle:e=>d.get(e.id)??{}}}function ml(e){return t=>{const n=fl({data:t.data,encoding:e.encoding,defaults:e.defaults,scales:t.scales}),i=e.extend?.(t,n)??{};return{...i,initialSpawns:n.spawns,bodyStyle:n.bodyStyle,semanticItems:[...n.semanticItems,...i.semanticItems??[]]}}}import{forwardRef as yl,useCallback as gl,useEffect as bl,useImperativeHandle as xl,useMemo as vl,useRef as wl,useState as kl}from"react";function Ml(e,t={}){const n=t.id??"physics-process-boundary",i={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("segment"===e.type)return[{...i,id:n,shape:e}];const o=t.thickness??8,r=e.x-e.width/2,s=e.x+e.width/2,a=e.y-e.height/2,c=e.y+e.height/2;return[{...i,id:n+"-top",shape:{type:"segment",x1:r,y1:a,x2:s,y2:a,thickness:o}},{...i,id:n+"-right",shape:{type:"segment",x1:s,y1:a,x2:s,y2:c,thickness:o}},{...i,id:n+"-bottom",shape:{type:"segment",x1:s,y1:c,x2:r,y2:c,thickness:o}},{...i,id:n+"-left",shape:{type:"segment",x1:r,y1:c,x2:r,y2:a,thickness:o}}]}function Sl(e){if(!1===e.semanticItem)return null;const t=e.semanticItem??{},n=e.shape,i="aabb"===n.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:n.x,y:n.y,width:n.width,height:n.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(n.x1+n.x2)/2,y:(n.y1+n.y2)/2,pathData:`M ${n.x1} ${n.y1} L ${n.x2} ${n.y2}`};return{...i,...t,id:t.id??i.id}}function Il(e){return e.map(e=>({id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"stage",x:e.x??0,y:e.y??0,width:e.width,height:e.height}))}function Al(e){return e.flatMap(e=>{if(!1===e.semanticItem)return[];const t=e.semanticItem??{},n={id:e.id,label:e.label??e.id,description:e.description,datum:e.datum,group:e.group??e.state??"body group",x:e.x??0,y:e.y??0,width:e.width,height:e.height};return[{...n,...t,id:t.id??n.id}]})}var Cl="gauntlet-core",Rl="gauntlet-positive",Dl="gauntlet-negative";function Pl(e){return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:28,y2:e.floorY,thickness:8}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:e.width-30,y2:76,thickness:8}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:e.floorY,x2:e.width-30,y2:e.floorY,thickness:8}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-30,y1:76,x2:e.width-30,y2:e.floorY,thickness:8}}]}function $l(e,t,n,i){return n?"function"==typeof n?n(e,t):e[n]??i:i}function Bl(e){return e?.label??e?.id??"property"}function jl(e){return`gauntlet:${e}:core`}function Tl(e,t){return`gauntlet:${e}:positive:${t}`}function Nl(e,t,n){return`gauntlet:${e}:negative:${t}:${n}`}function Wl(e,t,n,i){const o=Math.max(2,n+2),r=80+o,s=i.floorY-o;return{x:Math.max(32+o,Math.min(i.width-30-4-o,e)),y:Math.max(r,Math.min(s,t))}}function El(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}function zl(e,t,n,i){const o=El(n),r=i?.(e,t,n)??{};return{...o,...r,startY:r.startY??r.routeY??o.startY,socketY:r.socketY??r.routeY??o.socketY,graveyardY:r.graveyardY??o.graveyardY}}function Ol(e,t){const n=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,n.indexOf(t));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:48+i%2*6}}function Fl(e,t,n){const i=e.activePositiveIds.reduce((e,n)=>e+(t.get(n)?.value??1),0),o=e.missingPositiveIds.length+e.poppedPositiveIds.length,r=e.negativeIds.reduce((e,t)=>e+(n.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*r-1.2*e.delay-5*o))}function Ll(e,t,n,i,o){const r=$l(e,t,n.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=i.map(e=>e.id),a=[...$l(e,t,n.positiveAccessor,s)],c=[...$l(e,t,n.negativeAccessor,[])].filter(e=>o.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...$l(e,t,n.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number($l(e,t,n.startTimeAccessor,0))||0),stage:"project filed",viability:$l(e,t,n.initialViability,100)}}function ql(e,t,n,i,o,r,s){const a=i.startX,c=i.startY+(i.startY===n.routeY?38*t:0),l=s?.(e,t,n,i)??{},d={__gauntlet:!0,kind:Cl,projectId:e.id,sourceDatum:e.datum},u=[{...l,id:jl(e.id),x:l.x??a,y:l.y??c,vx:l.vx??42,vy:l.vy??0,mass:l.mass??7,bodyCollisions:l.bodyCollisions??!0,shape:l.shape??{type:"circle",radius:28},spawnAt:l.spawnAt??e.startedAt,datum:d}],h=Wl(a,c,l.shape&&"radius"in l.shape&&Number(l.shape.radius)||28,n);u[0].x=h.x,u[0].y=h.y;for(const t of e.activePositiveIds){const i=o.get(t);if(!i)continue;const r=Ol(e.activePositiveIds,t),s=i.radius??10,a=Wl(h.x+Math.cos(r.angle)*r.radius,h.y+Math.sin(r.angle)*r.radius,s,n);u.push({id:Tl(e.id,t),x:a.x,y:a.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:l.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:Rl,projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:jl(e.id)},stiffness:.56,damping:.9,restLength:52+r.index%2*4,...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const o=r.get(t);o&&u.push(Yl(e,o,i,h.x,h.y,n,l.spawnAt??e.startedAt))}),u}function Yl(e,t,n,i,o,r,s){const a=t.radius??7.2,c=Wl(i-12+n%4*12,o+54+12*Math.floor(n/4),a,r);return{id:Nl(e.id,t.id,n),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:s,datum:{__gauntlet:!0,kind:Dl,projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:jl(e.id)},stiffness:.62,damping:.92,restLength:52+n%4*3,...t.spring??{}}]}}function Hl(e){return e?Array.isArray(e)?[...e]:Object.entries(e).flatMap(([e,t])=>Array.from({length:Math.max(0,Math.round(Number(t)||0))},()=>e)):[]}function Gl(e,t){return t?Array.isArray(t)?[...t]:t.ids?[...t.ids]:t.candidates?t.candidates.filter(t=>e.includes(t)).slice(0,t.count??1):[]:[]}function Xl(e,t){return Gl(e.activePositiveIds,t.popPositive)}function _l(e){const t=Number(e.budget),n=Number.isFinite(t)?Math.max(0,t):0,i=e.properties instanceof Map?e.properties:new Map(e.properties.map(e=>[e.id,e])),o=e.candidates?new Set(e.candidates):null,r=e.attachedIds.map((e,t)=>{const n=i.get(e),o=Number(n?.work??1),r=Number(n?.priority??t);return{id:e,index:t,priority:Number.isFinite(r)?r:t,work:Number.isFinite(o)&&o>0?o:1}}).filter(e=>!o||o.has(e.id)).sort((e,t)=>e.priority-t.priority||e.index-t.index),s=[],a=[];let c=0;for(const e of r)c+e.work>n+Number.EPSILON?a.push(e.id):(s.push(e.id),c+=e.work);return{ids:s,used:c,budget:n,remaining:Math.max(0,n-c),skippedIds:a}}function Vl(e,t){if(!t.from||!t.to||t.from===t.to)return{};const n=Math.max(0,Math.floor(Number(t.count??1)||0)),i=e.negativeIds.filter(e=>e===t.from).length,o=Math.min(n,i);return o?{addNegative:{[t.to]:o},popNegative:{ids:Array.from({length:o},()=>t.from)}}:{}}function Ul(e,t){const n=Gl(e.negativeIds,t.popNegative);if(!n.length)return[];const i=new Map;for(const e of n)i.set(e,(i.get(e)??0)+1);const o=[];return e.negativeIds.forEach((e,t)=>{const n=i.get(e)??0;n>0&&(o.push({propertyId:e,index:t}),i.set(e,n-1))}),o}function Kl(e,t,n){if(t.when&&!t.when(n))return e;let i={...e};const o=Xl(i,t);o.length&&(i={...i,activePositiveIds:i.activePositiveIds.filter(e=>!o.includes(e)),poppedPositiveIds:Array.from(new Set([...i.poppedPositiveIds,...o]))});const r=Ul(i,t);if(r.length){const e=new Set(r.map(e=>e.index));i={...i,negativeIds:i.negativeIds.filter((t,n)=>!e.has(n)),poppedNegativeIds:[...i.poppedNegativeIds,...r.map(e=>e.propertyId)]}}const s=Hl(t.addPositive);s.length&&(i={...i,activePositiveIds:Array.from(new Set([...i.activePositiveIds,...s])),missingPositiveIds:i.missingPositiveIds.filter(e=>!s.includes(e))});const a=Hl(t.addNegative);if(a.length&&(i={...i,negativeIds:[...i.negativeIds,...a]}),t.delayDelta&&(i={...i,delay:i.delay+t.delayDelta}),t.metricsDelta){const e={...i.metrics};for(const[n,i]of Object.entries(t.metricsDelta))e[n]=Number(e[n]??0)+i;i={...i,metrics:e}}return t.viabilityDelta&&(i={...i,viability:i.viability+t.viabilityDelta}),t.stage&&(i={...i,stage:t.stage}),t.outcome&&(i={...i,outcome:t.outcome}),i}function Ql(e,t){return{id:e.id,label:e.label??e.id,summary:e.summary??t.find(e=>e.summary)?.summary,time:e.time}}function Zl(e,t){return e.eventsApplied.includes(t.id)?e:{...e,eventsApplied:[...e.eventsApplied,t.id],eventHistory:[...e.eventHistory??[],t],lastEvent:t,stage:t.label??e.stage}}function Jl(e,t){const n=e.datum;return!(!n?.__gauntlet||n.projectId!==t||n.kind!==Dl)}function ed(e){const t=e.id.slice(e.id.lastIndexOf(":")+1),n=Number(t);return Number.isFinite(n)?n:-1}import{jsx as td,jsxs as nd}from"react/jsx-runtime";function id(e){const t=e.data;return t?.__gauntlet?nd("div",{className:"semiotic-tooltip",style:{background:"var(--semiotic-tooltip-bg, rgba(15, 23, 42, 0.94))",color:"var(--semiotic-tooltip-text, #f8fafc)",padding:"8px 12px",borderRadius:6,boxShadow:"var(--semiotic-tooltip-shadow, 0 8px 24px rgba(0,0,0,0.35))",maxWidth:280},children:[td("strong",{children:t.kind===Cl?"string"==typeof t.sourceDatum?.label?t.sourceDatum.label:t.projectId:Bl(t.property)}),td("div",{children:t.kind===Rl?"Positive property":t.kind===Dl?"Negative property":"Project core"})]}):null}function od(e,t,n){const i=t.datum;if(!i?.__gauntlet)return;const o="circle"===t.shape.type?t.shape.radius:8;if(e.save(),e.translate(t.x,t.y),i.kind===Cl)e.fillStyle=rd(e,n.fill,"#0f766e"),e.strokeStyle=rd(e,n.stroke,"#f8fafc"),e.lineWidth=2.4,e.beginPath(),e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke();else{const t=i.property;e.fillStyle=rd(e,n.fill??t?.color,"#38bdf8"),e.strokeStyle=rd(e,n.stroke,"#0f172a"),e.lineWidth=1.1,e.beginPath(),i.kind===Dl?e.rect(-o,-o,2*o,2*o):e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke(),e.fillStyle=rd(e,"var(--semiotic-background, #07111f)","#07111f"),e.font=`900 ${i.kind===Dl?9:8}px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(t?.short??t?.id?.slice(0,1).toUpperCase()??"?",0,.5)}e.restore()}function rd(e,t,n){if("string"!=typeof t)return n;if("function"!=typeof getComputedStyle||!e.canvas)return t||n;const i=t.startsWith("var(")?t.match(/var\((--[^,\s)]+)/)?.[1]:t.startsWith("--")?t:null;return i?getComputedStyle(e.canvas).getPropertyValue(i).trim()||n:t||n}function sd({layout:e,states:t}){return nd("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[td("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-accent, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),td("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-negative, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),td("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),e.gates.map(t=>nd("g",{children:[td("rect",{x:t.x-t.width/2,y:Math.max(80,e.routeY-180),width:t.width,height:Math.min(360,e.height-170),rx:12,fill:t.color??"var(--semiotic-accent, #38bdf8)",fillOpacity:.1,stroke:t.color??"var(--semiotic-accent, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),td("text",{x:t.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:t.label??t.id})]},t.id)),nd("g",{children:[td("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-positive, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-positive, #22c55e)",strokeWidth:1.5}),td("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),nd("g",{children:[td("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-negative, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-negative, #ef4444)",strokeOpacity:.7}),td("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),td("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function ad(e){const t=e.datum;return!!t?.__gauntlet&&(t.kind===Cl?{label:t.projectId+" project core",group:"project",description:"Project core carrying positive and negative properties."}:{label:`${Bl(t.property)} ${t.kind===Rl?"positive":"negative"} property`,group:t.kind===Rl?"positive property":"negative property",description:`${Bl(t.property)} attached to ${t.projectId}.`})}function cd({states:e,layout:t}){const n=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!n.length)return null;const i=Math.max(1,...n.map(e=>e.value)),o=Math.max(40,(t.width-80)/n.length);return nd("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[td("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),n.map((e,t)=>{const n=40+t*o,r=Math.max(2,e.value/i*28),s=/kill|crash|block|grave/i.test(e.outcome);return nd("g",{children:[td("rect",{x:n+.18*o,y:28-r+22,width:Math.max(10,.45*o),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),td("text",{x:n+.4*o,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}import{jsx as ld}from"react/jsx-runtime";import{createElement as dd}from"react";var ud=[],hd=yl(function(e,t){const{bodyGroups:n,coreBody:i,coreForceMode:o="route",crashDetection:r=!0,crashOffset:s=30,data:a,emptyContent:c,events:l,frameProps:d={},gates:u,initialSpawnPacing:h,loading:p,loadingContent:f,negativeProperties:m,onCapacityChange:y,onClick:g,onStateChange:b,outcome:x,paused:v,positiveProperties:w=ud,projectPlacement:k,responsiveHeight:M,responsiveWidth:S,showTethers:I=!0,terminalBehavior:A="outcome",viability:C}=e,R=wl(null),D=vl(()=>({idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor}),[e.idAccessor,e.initialViability,e.metricsAccessor,e.negativeAccessor,e.positiveAccessor,e.startTimeAccessor]),P=gc(e,[900,520]),{chartSize:$,showProjection:B,showChrome:j,className:T,title:N,chartMode:W,margin:E,enableHover:z,description:O,summary:F,accessibleTable:L}=P,q=bc({data:a,emptyContent:c,loading:p,loadingContent:f,size:$}),Y=vl(()=>Xc(a??[]),[a]),H=vl(()=>Y.map((e,t)=>$l(e,t,D.idAccessor,null!=e.id?e.id+"":"project-"+t)+"").join("|"),[Y,D.idAccessor]),G=vl(()=>new Map(w.map(e=>[e.id,e])),[w]),X=vl(()=>new Map(m.map(e=>[e.id,e])),[m]),_=vl(()=>function(e,t,n){const[i,o]=e,r=Math.round(.48*o),s=o-36,a=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,a.length),l=.22*i,d=c>1?(.78*i-l)/(c-1):0,u=Math.max(Math.round(.14*i),110);return{crashY:s-n,floorY:s,gates:a.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(l+t*d),width:e.width??Math.max(54,Math.round(.07*i))})),graveyardX:Math.round(.84*i),graveyardY:s-4,height:o,routeY:r,socketX:Math.round(.92*i),startX:u,width:i}}($,u,s),[$,s,u]),V=vl(()=>new Map(_.gates.map(e=>[e.id,e])),[_.gates]),U=vl(()=>_.gates.map(e=>({kind:"force-field",damping:.035,force:{x:12,y:0},semanticItem:!1,...e.regionEffect,id:"gauntlet-gate-"+e.id,label:e.label??e.id,description:e.description,bodyFilter:e.capacity?{property:"datum.kind",equals:Cl}:e.regionEffect?.bodyFilter,shape:{type:"aabb",x:e.x,y:_.routeY,width:e.capacity?e.capacity.sensorWidth??Math.max(96,6*e.width):Math.max(e.width,54),height:Math.min(360,_.height-170)}})),[_.gates,_.height,_.routeY]),[K,Q]=kl(()=>Y.map((e,t)=>{const n=Ll(e,t,D,w,X);return{...n,viability:C?.(n,{negativeProperties:X,positiveProperties:G})??Fl(n,G,X)}})),Z=wl(K),J=wl(0),ee=wl(new Map),te=wl([]),ne=wl(y);ne.current=y;const ie=vl(()=>function(e){const{dataKey:t,gates:n,statesRef:i,processedGateVisitsRef:o}=e;return n.flatMap(e=>e.capacity&&e.capacity.unitsPerSecond>0?[zo({id:`gauntlet-capacity-${t}-${e.id}`,regionId:"gauntlet-gate-"+e.id,unitsPerSecond:e.capacity.unitsPerSecond,bodyFilter:{property:"datum.kind",equals:Cl},maxQueue:e.capacity.maxQueue,queueLayout:e.capacity.queueLayout,queueSlotSpacing:e.capacity.queueSlotSpacing,queueStiffness:e.capacity.queueStiffness??24,releaseImpulse:{x:36,y:0},unitAccessor:t=>{const n=t.datum,o=n?.sourceDatum,r=e.capacity?.unitAccessor,s=i.current.find(e=>e.id===n?.projectId);let a;"function"==typeof r?a=s?r(s):void 0:r&&(a=o?.[r]);const c=Number(a??o?.reviewWork??o?.work??s?.metrics.reviewWork??o?.points);return Number.isFinite(c)&&c>0?c:1},onProcessed:t=>{const n=t.datum;if(!n?.projectId)return;const i=`${n.projectId}:${e.id}`;o.current.set(i,(o.current.get(i)??0)+1)}})]:[])}({dataKey:H,gates:_.gates,statesRef:Z,processedGateVisitsRef:ee}),[H,_.gates]),oe=vl(()=>[...ie,...d.controllers??[]],[ie,d.controllers]),re=wl(Y);re.current=Y;const se=wl(b);se.current=b;const ae=wl({negativeById:X,positiveById:G,positiveProperties:w,stateAccessors:D,viability:C});ae.current={negativeById:X,positiveById:G,positiveProperties:w,stateAccessors:D,viability:C};const ce=gl((e,t,n=0)=>{const i=ae.current,o=Ll(e,t,i.stateAccessors,i.positiveProperties,i.negativeById);return i.stateAccessors.startTimeAccessor||(o.startedAt=Math.max(0,n)),{...o,viability:i.viability?.(o,{negativeProperties:i.negativeById,positiveProperties:i.positiveById})??Fl(o,i.positiveById,i.negativeById)}},[]);bl(()=>{ee.current.clear(),te.current=[];const e=re.current.map((e,t)=>ce(e,t));Z.current=e,Q(e)},[ce,H]),bl(()=>{Z.current=K,se.current?.(K)},[K]);const le=gl(e=>[...("function"==typeof l?l(e,_):l)??[]].sort((e,t)=>e.time-t.time),[l,_]),de=gl((e,t,n)=>{if(!t.gateId||!V.get(t.gateId)?.capacity)return!0;const i=Number(t.gateVisit),o=Number.isFinite(i)&&i>0?Math.floor(i):n.filter(e=>e.gateId===t.gateId).findIndex(e=>e.id===t.id)+1;return o>0&&(ee.current.get(`${e.id}:${t.gateId}`)??0)>=o},[V]),ue=gl(()=>{if(!ie.length)return;const e=ie.flatMap(e=>{const t=e.getSnapshot?.();return t?[t]:[]});var t,n;(t=te.current).length===(n=e).length&&t.every((e,t)=>{const i=n[t];return!!i&&e.regionId===i.regionId&&e.queueDepth===i.queueDepth&&e.blockedDepth===i.blockedDepth&&e.processedCount===i.processedCount&&e.metricRevision===i.metricRevision})||(te.current=e,ne.current?.(e))},[ie]),he=vl(()=>K.flatMap((e,t)=>{const n=zl(e,t,_,k);return ql(e,t,_,n,G,X,i)}),[i,_,X,G,k,K]),pe=gl((e,t)=>{let n=!1;const i=Z.current.map(i=>{if(i.id!==e)return i;const o=t(i);return n=n||o!==i,o});n&&(Z.current=i,Q(i))},[]);xl(t,()=>function(e){const{statesRef:t,setStates:n,elapsedRef:i,frameRef:o,layout:r,projectPlacement:s,positiveById:a,negativeById:c,coreBody:l,createState:d}=e;return{push:e=>{const u=d(e,t.current.length,i.current),h=zl(u,t.current.length,r,s),p=ql(u,t.current.length,r,h,a,c,l),f=[...t.current,u];t.current=f,n(f),o.current?.pushMany(p),o.current?.step(0)},pushMany:e=>{const u=[...t.current],h=[],p=i.current;e.forEach(e=>{const t=d(e,u.length,p),n=zl(t,u.length,r,s);h.push(...ql(t,u.length,r,n,a,c,l)),u.push(t)}),t.current=u,n(u),h.length&&o.current?.pushMany(h),o.current?.step(0)},remove:e=>{const i=Array.isArray(e)?e:[e],r=[],s=[];for(const e of i){const n=t.current.find(t=>t.id===e);n&&(r.push(n.datum),s.push(jl(n.id),...n.activePositiveIds.map(e=>Tl(n.id,e))),n.negativeIds.forEach((e,t)=>{s.push(Nl(n.id,e,t))}))}return t.current=t.current.filter(e=>!i.includes(e.id)),n(t.current),o.current?.remove(s),r},update:(e,u)=>{const h=Array.isArray(e)?e:[e],p=[];for(const e of h){const n=t.current.find(t=>t.id===e);if(!n)continue;const h=t.current.findIndex(t=>t.id===e);p.push(n.datum);const f=u(n.datum),m=d(f,0>h?t.current.length:h,n.startedAt??i.current),y=zl(m,0>h?t.current.length:h,r,s);o.current?.remove([jl(n.id),...n.activePositiveIds.map(e=>Tl(n.id,e)),...n.negativeIds.map((e,t)=>Nl(n.id,e,t))]),o.current?.pushMany(ql(m,0>h?t.current.length:h,r,y,a,c,l)),t.current=t.current.map(t=>t.id===e?m:t)}return n(t.current),p},clear:()=>{t.current=[],n([]),o.current?.clear()},getData:()=>t.current.map(e=>e.datum),getScales:()=>null,getCustomLayout:()=>o.current?.snapshot()??null,popBodies:(e,t)=>o.current?.popBodies(e,t)??[]}}({statesRef:Z,setStates:Q,elapsedRef:J,frameRef:R,layout:_,projectPlacement:k,positiveById:G,negativeById:X,coreBody:i,createState:ce}),[i,ce,_,X,G,k]);const fe=gl((e,t,n)=>{!function(e){const{project:t,effect:n,controls:i,layout:o,positiveById:r,negativeById:s,coreBody:a,popBodies:c}=e,l=i.readBodies().find(e=>e.id===jl(t.id)),d=i.readBodies(),u=l?.x??o.startX,h=l?.y??o.routeY,p=function(e,t){let n=-1;for(const i of t)Jl(i,e.id)&&(n=Math.max(n,ed(i)));return Math.max(e.negativeIds.length,n+1)}(t,d),f=Hl(n.addNegative).flatMap((e,n)=>{const i=s.get(e);return i?[Yl(t,i,p+n,u,h,o)]:[]}),m=Hl(n.addPositive).flatMap(e=>{if(!r.get(e)||t.activePositiveIds.includes(e))return[];const n={...El(o),routeY:h,socketY:h,startX:u,startY:h};return ql({...t,activePositiveIds:[e],negativeIds:[]},0,o,n,r,s,a).filter(e=>e.id.includes(":positive:"))});(f.length||m.length)&&i.pushMany([...f,...m]);const y=Xl(t,n);for(const e of y){const n=r.get(e);c([Tl(t.id,e)],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??10)+3})}const g=Ul(t,n),b=function(e,t,n){const i=t.filter(t=>Jl(t,e.id)).sort((e,t)=>ed(e)-ed(t)||e.id.localeCompare(t.id)),o=new Set;return n.map(t=>{const n=i.find(e=>!o.has(e.id)&&e.datum.property?.id===t.propertyId);return n?(o.add(n.id),n.id):Nl(e.id,t.propertyId,t.index)})}(t,d,g);g.forEach((e,t)=>{const n=s.get(e.propertyId);c([b[t]],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??7)+3})})}({project:e,effect:t,controls:n,layout:_,positiveById:G,negativeById:X,coreBody:i,popBodies:(e,t)=>R.current?.popBodies(e,t)})},[i,_,X,G]),me=gl(({body:e,bodies:t})=>function(e){const{body:t,bodies:n,layout:i,states:o,projectPlacement:r,positiveById:s,negativeById:a,projectEvents:c,gateById:l,coreForceMode:d,terminalBehavior:u,elapsed:h}=e,p=t.datum;if(!p?.__gauntlet)return null;const f=o.findIndex(e=>e.id===p.projectId),m=0>f?void 0:o[f];if(!m)return null;const y=zl(m,f,i,r),g=n.find(e=>e.id===jl(m.id)),b=m.negativeIds.reduce((e,t)=>e+(a.get(t)?.load??1),0),x=m.killed?0:58;if(p.kind!==Cl){if(!g)return null;let e;const o=p.property;if(o?.target){const r=n.filter(e=>{const t=e.datum;return t?.__gauntlet&&t.projectId===m.id&&t.kind===p.kind}).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),s=Math.max(0,r.findIndex(e=>e.id===t.id));e=o.target({body:t,bodies:n,core:g,index:s,layout:i,placement:y,project:m})??{x:g.x,y:g.y}}else if(p.kind===Rl&&p.property){const t=Ol(m.activePositiveIds,p.property.id);e={x:g.x+Math.cos(t.angle)*t.radius,y:g.y+Math.sin(t.angle)*t.radius-2}}else{const i=n.filter(e=>e.datum?.kind===Dl&&e.datum.projectId===m.id).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),o=Math.max(0,i.findIndex(e=>e.id===t.id)),r=Math.floor(o/4);e={x:g.x+18*(o%4-(Math.min(4,i.length-4*r)-1)/2),y:g.y+54+13*r}}const r="circle"===t.shape.type?t.shape.radius:8;e=Wl(e.x,e.y,r,i);const s=Wl(t.x,t.y,r,i);if(Math.abs(s.x-t.x)>.5||Math.abs(s.y-t.y)>.5)return{x:48*(s.x-t.x)-6*t.vx,y:48*(s.y-t.y)-6*t.vy};const a=p.kind!==Rl||m.killed?0:3.2*(o?.buoyancy??o?.value??1),c=p.kind===Dl?{x:.22*(o?.pull?.x??-8),y:.22*(o?.pull?.y??22)}:{x:0,y:0};return{x:28*(e.x-t.x)-3*(t.vx-g.vx)+c.x+.01*x,y:28*(e.y-t.y)-3*(t.vy-g.vy)+c.y-a}}if(m.killed)return{x:44*((m.crashX??m.metrics.lastX??t.x)-t.x)-9*t.vx,y:160+12*b-1.6*t.vy};const v=c(m),w=function(e,t,n,i,o,r,s){if(t.killed)return{x:t.metrics.lastX??i.graveyardX,y:i.graveyardY};const a=o[o.length-1];if(!a)return{x:i.socketX,y:i.routeY};const c=o.find(n=>e>=n.time&&!t.eventsApplied.includes(n.id)&&!(!n.gateId||!r.get(n.gateId)?.capacity)),l=c?Math.min(e,c.time):e,d="built"===t.outcome||"built_diminished"===t.outcome;if(l>a.time+.85){if("hold-last"===s){const e=a.gateId?r.get(a.gateId):void 0;return{x:a.routeX??e?.x??i.socketX,y:a.routeY??i.routeY}}return d?{x:i.socketX,y:i.socketY}:{x:i.graveyardX,y:i.graveyardY-14}}const u=.85*t.delay+12*t.negativeIds.length+8*(t.poppedPositiveIds.length+t.missingPositiveIds.length),h=[{time:0,x:i.startX,y:i.startY},...o.map(e=>{const t=e.gateId?r.get(e.gateId):void 0;return{time:e.time,x:e.routeX??t?.x??i.startX,y:e.routeY??i.routeY+.28*Math.min(180,u)}})].sort((e,t)=>e.time-t.time);let p=h[0],f=h[h.length-1];for(let e=1;h.length>e;e+=1){if(h[e].time>=l){f=h[e];break}p=h[e]}const m=Math.max(0,Math.min(1,(l-p.time)/Math.max(.1,f.time-p.time))),y=m*m*(3-2*m);return{x:p.x+(f.x-p.x)*y,y:p.y+(f.y-p.y)*y+7*Math.sin(2.6*l)}}(Math.max(0,h-(m.startedAt??0)),m,0,y,v,l,u),k=m.activePositiveIds.reduce((e,t)=>e+(s.get(t)?.buoyancy??s.get(t)?.value??1),0);return"net"===d?{x:15*(w.x-t.x)-1.8*t.vx+.18*x,y:1.25*(y.routeY-t.y)-1.4*t.vy+32*(b-k)}:{x:15*(w.x-t.x)-1.8*t.vx+.18*x,y:15*(w.y-t.y)-1.8*t.vy+13*b-2.2*k}}({body:e,bodies:t,layout:_,states:Z.current,projectPlacement:k,positiveById:G,negativeById:X,projectEvents:le,gateById:V,coreForceMode:o,terminalBehavior:A,elapsed:J.current}),[o,V,_,X,G,le,k,A]),ye=gl((e,t)=>{!function(e,t,n){const{frameProps:i,elapsedRef:o,statesRef:r,crashDetection:s,layout:a,projectEvents:c,gateById:l,capacityEventReady:d,addBodiesForEffect:u,updateProjectState:h,viability:p,positiveById:f,negativeById:m,outcome:y,reportCapacity:g}=n;i.onTick?.(e,t),o.current=e.elapsedSeconds??t.snapshot().elapsedSeconds,g();for(const e of r.current){const n=t.readBodies().find(t=>t.id===jl(e.id));if(!n)continue;if(s&&!e.killed&&n.y+("circle"===n.shape.type?n.shape.radius:28)>=a.crashY){t.readBodies().forEach(n=>{const i=n.datum;i?.__gauntlet&&i.projectId===e.id&&t.applyImpulse(n.id,-n.vx*n.mass,0)}),h(e.id,e=>{const t={appliedAt:Math.max(0,o.current-(e.startedAt??0)),id:"gauntlet-crash-line",label:"Crash Line",summary:"The project hit the crash threshold; lift and forward motion shut off.",time:Math.max(0,o.current-(e.startedAt??0))};return{...e,crashX:n.x,eventHistory:[...e.eventHistory??[],t],killed:!0,lastEvent:t,metrics:{...e.metrics,lastX:n.x},outcome:"bad_design_crash",stage:"Crash Line",viability:Math.min(0,e.viability)}});continue}if(e.killed)continue;const i=Math.max(0,o.current-(e.startedAt??0)),r=c(e),g=r.filter(t=>i>=t.time&&!e.eventsApplied.includes(t.id)&&d(e,t,r));let b=e;for(const n of g){const o=n.gateId?l.get(n.gateId):void 0,r=n.effects??[];for(const e of r){const i={event:n,gate:o,negativeProperties:m,positiveProperties:f,project:b};e.when&&!e.when(i)||(u(b,e,t),b=Kl(b,e,i))}const s={...Ql(n,r),appliedAt:i};b=Zl(b,s),h(e.id,e=>{let t=Zl(e,s);if(t===e)return e;for(const e of r)t=Kl(t,e,{event:n,gate:o,negativeProperties:m,positiveProperties:f,project:t});const i=p?.(t,{negativeProperties:m,positiveProperties:f})??Fl(t,f,m);return t={...t,viability:i},n.final&&(t={...t,outcome:n.outcome??y?.(t,{layout:a,negativeProperties:m,positiveProperties:f})??(t.viability>20?"built":"approved_not_built")}),t})}}}(e,t,{frameProps:d,elapsedRef:J,statesRef:Z,crashDetection:r,layout:_,projectEvents:le,gateById:V,capacityEventReady:de,addBodiesForEffect:fe,updateProjectState:pe,viability:C,positiveById:G,negativeById:X,outcome:x,reportCapacity:ue})},[fe,de,r,d,V,_,X,x,G,le,ue,pe,C]),ge=gl((e,t)=>{const n="function"==typeof d.bodyStyle?d.bodyStyle(e,t):d.bodyStyle,i=e.datum;return i?.__gauntlet?{fill:i.kind===Cl?"var(--semiotic-accent, #0f766e)":i.property?.color??"var(--semiotic-accent, #38bdf8)",stroke:i.kind===Cl?"#f8fafc":"#0f172a",opacity:.96,...n}:n??{}},[d]),be=vl(()=>"function"==typeof n?n(K,_):n??[],[n,_,K]),xe=vl(()=>Al(be),[be]),ve=vl(()=>B?function(e,t){if(!e.length)return[];const n=Math.max(40,(t.width-80)/e.length);return e.map((e,t)=>{const i=`${e.id}: viability ${Math.round(e.viability)}, ${e.outcome||e.stage}`;return{id:"gauntlet-projection-"+e.id,label:i,description:i,datum:e,x:40+(t+.5)*n,y:28,shape:"rect",width:Math.max(16,.55*n),height:22,group:"settled projection"}})}(K,_):[],[_,B,K]),we=vl(()=>[...ve,...xe],[xe,ve]),ke=gl((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]),Me=gl((e,t)=>{g&&(e&&"object"==typeof e&&e.__gauntlet?g(e.sourceDatum,{x:t.x,y:t.y}):e&&g(e,{x:t.x,y:t.y}))},[g]),Se=gl((e,t)=>{d.beforePaint?.(e,t),I&&function(e,t){const n=new Map(t.filter(e=>e.datum?.kind===Cl).map(e=>[e.datum.projectId,e]));e.save(),e.lineWidth=1.1,e.setLineDash([3,4]);for(const i of t){const t=i.datum;if(!t?.__gauntlet||t.kind===Cl)continue;const o=n.get(t.projectId);o&&(e.globalAlpha=t.kind===Dl?.24:.36,e.strokeStyle=t.kind===Dl?"#d94a45":"#7a8794",e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke())}e.restore()}(e,t)},[d,I]),Ie=vl(()=>({fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7,...d.config?.kernel??{}},colliders:[...Pl(_),...d.config?.colliders??[]]}),[d.config?.colliders,d.config?.kernel,_]),Ae=vl(()=>[...U,...d.regionEffects??[]],[d.regionEffects,U]);if(q)return q;const Ce=wc(e.tooltip,d),Re=kc(e,d,we,{chartMode:W,className:T,title:N,description:O,summary:F,accessibleTable:L,enableHover:z,margin:E}),De=B?ld(cd,{states:K,layout:_}):void 0,Pe=vc(j?ld(sd,{layout:_,states:K}):void 0,d.backgroundGraphics),$e=vc(De,d.foregroundGraphics),Be=d.renderBody??od,je=Ce.tooltipContent??id;return xc("GauntletChart",$,dd(ks,{...d,...Ce,...Re,key:`${$[0]}x${$[1]}:${H}`,ref:R,accessibleTable:e.accessibleTable??d.accessibleTable,backgroundGraphics:Pe,bodyForces:me,bodySemanticItems:d.bodySemanticItems??ad,bodyStyle:ge,beforePaint:Se,onClick:g?Me:Re.onClick,config:Ie,controllers:oe,enableHover:Ce.enableHover??!0,foregroundGraphics:$e,hoverRadius:e.hoverRadius??d.hoverRadius??18,initialSpawns:he,initialSpawnPacing:h,onBodyPointerDown:ke,onTick:ye,paused:v,regionEffects:Ae,renderBody:Be,responsiveHeight:M,responsiveWidth:S,size:$,tooltipContent:je}))});hd.displayName="GauntletChart";var pd=hd;import{forwardRef as fd,useCallback as md,useMemo as yd,useRef as gd}from"react";import{jsx as bd,jsxs as xd}from"react/jsx-runtime";function vd(e){return e.toLocaleString(void 0,1e3>Math.abs(e)?{maximumFractionDigits:1}:{maximumFractionDigits:0})}function wd(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}function kd(e){if(!e||"object"!=typeof e)return null;const t=e,n=Number(t.x),i=Number(t.y);return Number.isFinite(n)&&Number.isFinite(i)?{x:n,y:i}:null}function Md(e){if(!e||"object"!=typeof e)return[];const t=e.flowPath;return Array.isArray(t)?t.map(kd).filter(e=>null!=e):[]}function Sd(e,t){if(2>t.length)return null;let n=0;const i=[];for(let e=1;t.length>e;e+=1){const o=Math.hypot(t[e].x-t[e-1].x,t[e].y-t[e-1].y);i.push(o),n+=o}if(0>=n)return null;let o=null,r=0;for(let s=1;t.length>s;s+=1){const a=t[s-1],c=t[s],l=i[s-1];if(0>=l)continue;const d=c.x-a.x,u=c.y-a.y,h=Math.max(0,Math.min(1,((e.x-a.x)*d+(e.y-a.y)*u)/(l*l))),p={x:a.x+d*h,y:a.y+u*h},f={distance:Math.hypot(e.x-p.x,e.y-p.y),point:p,progress:(r+h*l)/n,tangent:{x:d/l,y:u/l},totalLength:n};o&&f.distance>=o.distance||(o=f),r+=l}return o}function Id(e,t,n){if(0===e.length)return{x:0,y:0};if(1===e.length||0>=n)return{...e[0]};let i=0;const o=Math.max(0,Math.min(1,t))*n;for(let t=1;e.length>t;t+=1){const n=e[t-1],r=e[t],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(i+s>=o){const e=(o-i)/s;return{x:n.x+(r.x-n.x)*e,y:n.y+(r.y-n.y)*e}}i+=s}}return{...e[e.length-1]}}function Ad(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function Cd(e,t,n){const i=Math.hypot(e,t);if(n>=i||0>=i)return[e,t];const o=n/i;return[e*o,t*o]}function Rd(e,t,n){const i=Sd({...e,x:t[0].x,y:t[0].y},t),o=i?.tangent??{x:t[1].x-t[0].x,y:t[1].y-t[0].y},r=Math.hypot(o.x,o.y)||1,s=o.x/r,a=o.y/r,c=Ad(e),l=function(e,t){let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return(n%1e3/1e3-.5)*t*1.4}(e.id,c);return{id:e.id,x:t[0].x+-a*l,y:t[0].y+s*l,vx:s*n,vy:a*n,mass:e.mass,shape:e.shape,datum:{...e.datum&&"object"==typeof e.datum?e.datum:{},routeProgress:0}}}var Dd=fd(function(e,t){const{chartId:n,colorBy:i,coordinateMode:o="auto",data:r,edges:s,emptyContent:a,flowSpeed:c=90,frameProps:l,links:d,loading:u,loadingContent:h,maxParticles:p=180,nodeIdAccessor:f="id",nodeXAccessor:m="x",nodeYAccessor:y="y",nodes:g,onObservation:b,particleRadius:x=4,particleRate:v=.16,pathAccessor:w="path",pathConstraint:k="path",paused:M,reducedMotion:S=!1,responsiveHeight:I,responsiveWidth:A,seed:C=1,showNodeLabels:R=!0,showSensors:D=!1,showStaticFlow:P=!0,sourceAccessor:$="source",targetAccessor:B="target",throughputAccessor:j="value"}=e,T=gc(e,[760,420]),{chartSize:N,className:W,title:E,chartMode:z,margin:O,enableHover:F,description:L,summary:q,accessibleTable:Y}=T,H=gd(null),G=yd(()=>g??[],[g]),X=yd(()=>d??s??r??[],[r,s,d]),_=yd(()=>ta({nodes:G,links:X,nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:$,targetAccessor:B,throughputAccessor:j,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:S,seed:C,size:N}),[X,G,N,o,c,p,f,m,y,x,v,w,k,S,C,$,B,j]);Pa(t,{frameRef:H,spawnDatum:md((e,t)=>{const n=ta({nodes:G,links:[e],nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:$,targetAccessor:B,throughputAccessor:j,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:S,seed:C+t+1,size:N}),i={id:(e.id??"physical-flow-push-"+t)+"",x:Ds(N).plot.x,y:Ds(N).plot.y,mass:1,shape:{type:"circle",radius:x},datum:e},r=n.initialSpawns.length?n.initialSpawns:[i];return{datumId:(e.id??r[0].id)+"",spawns:r}},[G,N,o,c,p,f,m,y,x,v,w,k,S,C,$,B,j]),seedRows:X,seedSpawns:_.initialSpawns});const V=i??"source",U=yd(()=>$s(V,"#2563eb"),[V]),K=yd(()=>function(e,t,n){return{...e,observation:{...e.observation,chartId:t??e.observation?.chartId??"physical-flow",chartType:"PhysicalFlowChart",onObservation:n??e.observation?.onObservation}}}(_.config,n,b),[n,_.config,b]),Q=gd(l?.onTick);Q.current=l?.onTick;const Z=md((e,t)=>{S||"none"===k||function(e,t){const n=e.readBodies(),i=[],o=[];for(const r of n){const n=Md(r.datum);if(2>n.length)continue;const s=Sd(r,n);if(!s)continue;const a=r.datum,c=Number(a?.flowSpeed),l=Number.isFinite(c)&&c>0?c:t;if(s.progress>=.985||s.distance>Math.max(90,14*Ad(r))){i.push(r.id),o.push(Rd(r,n,l));continue}const d=Id(n,Math.min(1,s.progress+Math.max(.035,Math.min(.12,l/s.totalLength*.16))),s.totalLength),u=s.tangent,h=(u.x*l-r.vx)*r.mass*.16+(d.x-r.x)*r.mass*.045+(s.point.x-r.x)*r.mass*.08,p=(u.y*l-r.vy)*r.mass*.16+(d.y-r.y)*r.mass*.045+(s.point.y-r.y)*r.mass*.08,[f,m]=Cd(h,p,r.mass*l*.35);e.applyImpulse(r.id,f,m)}i.length&&e.remove(i),o.length&&e.pushMany(o)}(t,c),Q.current?.(e,t)},[c,k,S]),J=bc({data:null==d&&null==s&&null==r?void 0:X,emptyContent:a,loading:u,loadingContent:h,size:N});if(J)return J;const ee=function(e,t){const{showNodeLabels:n,showSensors:i,showStaticFlow:o}=t;if(e&&(o||i))return({size:t})=>{const r=[Number(t[0])||760,Number(t[1])||420],s=Math.max(1,...e.links.map(e=>e.throughput)),a=new Set(e.nodes.map(e=>e.sensorId));return xd("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[o?e.links.map(e=>{const t=3+e.throughput/s*16,n=e.path[Math.floor(e.path.length/2)];return xd("g",{children:[bd("path",{d:wd(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),bd("path",{d:wd(e.path),fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),n?bd("text",{x:n.x,y:n.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:vd(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>xd("g",{children:[i&&a.has(e.sensorId)?bd("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,o?bd("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,n?bd("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text-primary, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}(_.metadata,{showNodeLabels:R,showSensors:D,showStaticFlow:P}),te=(ne=_.metadata)?ne.links.map(e=>{const t=e.path[Math.floor(e.path.length/2)]??e.path[0],n=`${e.sourceLabel} to ${e.targetLabel}: ${vd(e.throughput)} throughput, ${e.packetCount} packets`;return{id:e.id,label:n,description:n,datum:e,x:t?.x??0,y:t?.y??0,shape:"path",pathData:wd(e.path),group:"flow"}}):[];var ne;const ie=wc(e.tooltip,l),oe=kc(e,l,te,{chartMode:z,className:W,title:E,description:L,summary:q,accessibleTable:Y,enableHover:F,margin:O});return xc("PhysicalFlowChart",N,bd(ks,{...l,...ie,...oe,ref:H,config:K,continuous:!S&&"none"!==k,foregroundGraphics:vc(ee,l?.foregroundGraphics),initialSpawns:_.initialSpawns,onTick:Z,paused:M||S,responsiveHeight:I,responsiveWidth:A,simulationExecution:"none"===k?l?.simulationExecution:"sync",size:N,bodyStyle:U,workerBodyThreshold:l?.workerBodyThreshold??1/0}))});Dd.displayName="PhysicalFlowChart";import{forwardRef as Pd,useCallback as $d,useEffect as Bd,useMemo as jd,useRef as Td,useState as Nd}from"react";import{Fragment as Wd,jsx as Ed,jsxs as zd}from"react/jsx-runtime";var Od={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}};function Fd(e,t,n){return Math.max(t,Math.min(n,e))}function Ld(e){return 6.2*e.length}function qd(e,t){const n=e.trim();if(t>=n.length)return n;if(1>=t)return n.slice(0,1);const i=n.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return i.length>1&&t>=i.length?i:t>3?n.slice(0,Math.max(1,t-2))+"..":n.slice(0,t).toUpperCase()}function Yd(e,t,n="auto"){const i=Math.max(1,Math.floor(t/6.2)),o="compact"===n?qd(e,i):"full"===n?e:Ld(e)>t?qd(e,i):e;return{text:o,textLength:Ld(o)>t?Math.max(4,t):void 0}}function Hd(e,t={}){const{showFlowSpine:n=!0,showStageCounts:i=!0,showCapacityBadges:o=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=t,{width:l,height:d,left:u,right:h,topY:p,bottomY:f,midY:m,stages:y,groups:g=[]}=e,b=f-p;return zd("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:d,viewBox:`0 0 ${l} ${d}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Ed("defs",{children:zd("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Ed("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Ed("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Ed("rect",{x:0,y:0,width:l,height:d,fill:"url(#semiotic-process-floor)"}),Ed("rect",{x:u-6,y:p-8,width:h-u+12,height:b+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),n?Ed("line",{x1:u+8,x2:h-8,y1:m,y2:m,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,y.map((e,t)=>{const n=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),r=Od[n],c=Math.max(12,e.width-8),l=Fd(c-8,22,88),u=Yd(e.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,g=function(e){if(null!=e.capacity){const t=null!=e.queueDepth?" · q "+e.queueDepth:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?e.capacity+"":e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}(e),x=Yd(g,Math.max(16,c-10),"auto"),v=o&&!1!==e.showBadge&&c>=32,w=null!=e.count?`n=${e.count}${null!=e.processed?" done "+e.processed:""}`:"",k=Yd(w,Math.max(16,c-8),"auto"),M=Math.max(30,p-15),S=M-13;return zd("g",{"data-stage":e.id,"data-role":n,children:[Ed("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:c,height:b-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===n?1:1.6}),y.length-1>t?Ed("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:r.accent,opacity:.85}):null,h?zd(Wd,{children:[Ed("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-l/2,y:S,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),zd("text",{x:e.x,y:M,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Ed("title",{children:e.label}),u.text]})]}):null,v?zd("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:x.textLength,lengthAdjust:x.textLength?"spacingAndGlyphs":void 0,children:[Ed("title",{children:g}),x.text]}):null,i&&null!=e.count?zd("text",{x:e.x,y:Math.min(d-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[Ed("title",{children:w}),k.text]}):null]},e.id)}),r?g.map((e,t)=>{const n=e.total??0,i=e.absorbed??0,o=e.complete??(n>0&&i>=n),r=!o&&n>0&&i/n>=.75,s=o?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=o?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=n>0?`${i}/${n}${o?" shipped":r?" almost":""}`:"feature "+(t+1),l=Fd(Math.max(54,Ld(e.label)+18,Ld(c)+16),54,104),d=Yd(e.label,l-12,"auto"),u=Yd(c,l-12,"auto");return zd("g",{"data-group":e.id,children:[Ed("rect",{x:e.x-l/2,y:e.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),zd("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[Ed("title",{children:e.label}),d.text]}),zd("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Ed("title",{children:c}),u.text]})]},e.id)}):null]})}import{jsx as Gd}from"react/jsx-runtime";var Xd=Pd(function(e,t){const{ballRadius:n=6,chromeOptions:i,colorBy:o,data:r,emptyContent:s,frameProps:a={},groupAnchorAlong:c,groupBy:l,groupCompletion:d,groupLabelAccessor:u,gravityX:h,gravityY:p,idAccessor:f,initialSpawnPacing:m,liveCapacity:y=!0,onCapacityChange:g,selection:b,bodyLimit:x,bodyMark:v,loading:w,loadingContent:k,paused:M,radiusAccessor:S,responsiveHeight:I,responsiveWidth:A,route:C="horizontal",seed:R=1,settle:D,springDamping:P,springStiffness:$,stageAccessor:B="stage",stages:j,workAccessor:T}=e,N=gc(e,[900,420]),{chartSize:W,showProjection:E,showChrome:z,className:O,title:F,chartMode:L,margin:q,enableHover:Y,description:H,summary:G,accessibleTable:X}=N,_=Td(null),V=jd(()=>Xc(r??[]),[r]),U=jd(()=>({data:V,stages:j,size:W,idAccessor:f,stageAccessor:B,groupBy:l,groupLabelAccessor:u,workAccessor:T,radiusAccessor:S,ballRadius:n,seed:R,route:C,groupCompletion:d,groupAnchorAlong:c,springStiffness:$,springDamping:P,gravityX:h,gravityY:p,settle:D}),[n,W,h,p,c,l,d,u,f,S,C,V,R,D,P,$,B,j,T]),K=jd(()=>Sa(U),[U]),Q=K.metadata;Pa(t,{frameRef:_,spawnDatum:$d((e,t)=>{const i=Sa({...U,data:[e],seed:R+t+1,settle:!0}).initialSpawns[0]??{id:(e.id??"process-flow-push-"+t)+"",x:Ds(W).plot.x,y:Ds(W).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e};return{datumId:(e.id??i.id)+"",spawns:[i]}},[n,U,W,R]),seedRows:V,seedSpawns:K.initialSpawns});const Z=jd(()=>$s(o),[o]),J=jd(()=>{if(!y)return a.controllers;const e=[...j.filter(e=>e.capacity&&e.capacity.unitsPerSecond>0).map(e=>{const t=e.capacity.unitsPerSecond;return zo({id:"process-capacity-"+e.id,regionId:"process-stage-"+e.id,unitsPerSecond:t,unitAccessor:e.capacity.unitAccessor??(T?"string"==typeof T?T:e=>{const t=e.datum;if(!t)return 1;try{return Number(T(t,0))||1}catch{return 1}}:"work"),releaseImpulse:{x:70+Math.min(40,2*t),y:0},queueLayout:"lane",continuous:!0})}),...a.controllers??[]];return e.length?e:void 0},[a.controllers,y,j,T]),[ee,te]=Nd({}),ne=Td(J);ne.current=J;const ie=Td(a.onTick);ie.current=a.onTick;const oe=!1!==z||null!=g;Bd(()=>{if(!g)return;const e=Object.values(ee);e.length&&g(e)},[ee,g]);const re=$d((e,t)=>{if(ie.current?.(e,t),!oe)return;const n=ne.current;if(!n?.length)return;const i={};for(const e of n){const t=e.getSnapshot?.();t&&"string"==typeof t.regionId&&(i[t.regionId]=t)}te(e=>function(e,t){const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const i of n){const n=e[i],o=t[i];if(!o)return!1;if(n.queueDepth!==o.queueDepth||n.blockedDepth!==o.blockedDepth||n.processedCount!==o.processedCount||n.unitsPerSecond!==o.unitsPerSecond||n.regionId!==o.regionId||n.metricRevision!==o.metricRevision)return!1}return!0}(e,i)?e:i)},[oe]),se=jd(()=>{const e=Z,t=a.bodyStyle;return v||t?(n,i)=>{const o="function"==typeof t?t(n,i):t;return{..."function"==typeof e?e(n):e,...o,mark:o?.mark??n.datum?.__physicsMark??n.datum?.mark??v}}:e},[v,Z,a.bodyStyle]),ae=bc({data:r,emptyContent:s,loading:w,loadingContent:k,size:W});if(ae)return ae;if(!j?.length)return xc("ProcessFlowChart",W,Gd("div",{role:"status",style:{width:W[0],height:W[1],display:"grid",placeItems:"center",color:"var(--semiotic-text-secondary, #64748b)"},children:"ProcessFlowChart requires a non-empty stages array."}));const ce=function(e,t,n={},i){if(!1===t||!e)return;const{volume:o,stages:r,groups:s,groupCompletion:a}=e,c=new Map(o.stages.map(e=>[e.id,e])),l=new Map(a.map(e=>[e.id,e]));return({size:e})=>{const t=Number(e[0])||o.width,a=Number(e[1])||o.height,d=r.map(e=>{const t=c.get(e.id),i=n["process-stage-"+e.id];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:i?.queueDepth,processed:i?.processedCount}}),u=s.map(e=>{const t=l.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return Hd({width:t,height:a,left:o.left,right:o.right,topY:o.topY,bottomY:o.bottomY,midY:o.midY,stages:d,groups:u},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}(Q,z,ee,i),le=function(e,t,n){if(!1===n||!t||0===e.length)return;const i=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:n})=>{const o=[Number(n[0])||t.volume.width,Number(n[1])||t.volume.height],r=Ds(o),s=Math.max(1,...e.map(e=>e.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return Gd("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,n)=>{const o=e[n];if(!o)return null;const r=i.get(t.id);if(!r)return null;const l=Math.max(2,o.value/s*a),d=Math.max(8,.35*r.width);return Gd("rect",{x:r.x-d/2,y:c,width:d,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}(K.projectionRows,Q,E),de=[...js(K.projectionRows,W,"stage"),...Al(Q?.groups??[])],ue=wc(e.tooltip,a),he=kc(e,a,de,{chartMode:L,className:O,title:F,description:H,summary:G,accessibleTable:X,enableHover:Y,margin:q}),pe=[...Q?.regionEffects??[],...a.regionEffects??[]];return xc("ProcessFlowChart",W,Gd(ks,{...a,...ue,...he,ref:_,controllers:J,regionEffects:pe,selection:b??a.selection,backgroundGraphics:vc(ce,a.backgroundGraphics),foregroundGraphics:vc(le,a.foregroundGraphics),initialSpawns:K.initialSpawns,initialSpawnPacing:m??K.initialSpawnPacing,onTick:re,paused:M,responsiveHeight:I,responsiveWidth:A,size:W,bodyStyle:se,config:{...K.config,...null!=x?{bodyLimit:x,eviction:"oldest"}:{},...a.config}}))});Xd.displayName="ProcessFlowChart";var _d=[.1,.5,.9],Vd=1e6;function Ud(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Kd(e,t,n,i,o){return"function"==typeof i?i(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,i??o)}function Qd(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Zd(e,t,n,i){const o=e.flatMap((e,o)=>{const r=Ud(Kd(e,o,t,n,"time")),s=Ud(Kd(e,o,t,i,"value"));return null==r||null==s?[]:[{time:Qd(r),value:s,index:o}]});o.sort((e,t)=>e.time-t.time||e.index-t.index);const r=[];for(const e of o){const t=r[r.length-1];t?.time===e.time?t.value=e.value:r.push({time:e.time,value:e.value})}return r}function Jd(e,t,n,i){if(!e.length)return null;const o=e[0],r=e[e.length-1];if(o.time>t)return"clamp"===i?o.value:null;if(t>r.time)return"clamp"===i?r.value:null;const s=function(e,t){let n=0,i=e.length;for(;i>n;){const o=n+i>>>1;t>e[o].time?n=o+1:i=o}return n}(e,t),a=e[s];if(a?.time===t)return a.value;const c=e[Math.max(0,s-1)];return"step"!==n&&a&&a.time!==c.time?c.value+(t-c.time)/(a.time-c.time)*(a.value-c.value):c.value}function eu(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,i=Math.floor(n),o=Math.ceil(n);return i===o?e[i]:e[i]+(e[o]-e[i])*(n-i)}function tu(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",i=function(e){const t=(e??_d).map(e=>{const t=Ud(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return Qd(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),o=function(e){if(Array.isArray(e)){if(e.length>Vd)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Ud).filter(e=>null!=e).map(Qd))).sort((e,t)=>e-t)}const t=e,n=Ud(t.start),i=Ud(t.end),o=Ud(t.step);if(null==n||null==i||null==o||0>=o||n>i)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const r=Math.floor((i-n)/o)+1;if(r>Vd)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const s=[],a=1e-10*Math.max(1,Math.abs(i),Math.abs(n));for(let e=0;r>e;e+=1){const t=n+e*o;if(t>i+a)break;s.push(Qd(Math.min(t,i)))}if(s.length&&a>=Math.abs(s[s.length-1]-i)||s.push(Qd(i)),s.length>Vd)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(s)).sort((e,t)=>e-t)}(e.sampleAt),r=e.runs.map(t=>Zd(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:o.map(e=>{const o=r.map(i=>Jd(i,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),s={};for(const e of i)s[e]=o.length?eu(o,e):null;return{time:e,count:o.length,min:o.length?o[0]:null,max:o.length?o[o.length-1]:null,median:o.length?eu(o,.5):null,quantiles:s}}),quantiles:i,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function nu(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function iu(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Ud(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const i=Qd(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,i))throw Error(`comparePhysicsTrace could not find quantile ${i} in the reference envelope`);return e.quantiles[i]??null}function ou(e,t,n){return t>e?"below":e>n?"above":"inside"}function ru(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const i=e.value-e.lower,o=t.value-t.lower,r=e.value-e.upper,s=t.value-t.upper,a=[0,1];for(const[e,t]of[[i,o],[r,s]])(0>e&&t>0||e>0&&0>t)&&a.push(-e/(t-e));a.sort((e,t)=>e-t);let c=0,l=0,d=0;for(let i=0;a.length-1>i;i+=1){const o=a[i],r=a[i+1];if(o>=r)continue;const s=(o+r)/2,u=(r-o)*n,h=ou(e.value+(t.value-e.value)*s,e.lower+(t.lower-e.lower)*s,e.upper+(t.upper-e.upper)*s);"below"===h?c+=u:"above"===h?d+=u:l+=u}return{below:c,inside:l,above:d,observed:n}}function su(e,t,n={}){const i=n.interpolation??t.interpolation,o=n.outsideDomain??t.outsideDomain,r=Zd(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),s=n.lower??nu(t,"lower"),a=n.upper??nu(t,"upper"),c=t.points.map(e=>{const t=Jd(r,e.time,i,o),n=iu(e,s),c=iu(e,a);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":ou(t,n,c)}});let l=0,d=0,u=0,h=0,p=null,f=0,m=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?d+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,p=e.time),n>f&&(f=n,m=e.time)}let y=0,g=0,b=0,x=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],o=Math.max(0,n.time-t.time);if(o>0){if("linear"===i){const e=ru(t,n);y+=e.below,g+=e.inside,b+=e.above,x+=e.observed;continue}"unobserved"!==t.status&&(x+=o,"below"===t.status?y+=o:"above"===t.status?b+=o:g+=o)}}const v=c[0]?.time,w=c[c.length-1]?.time,k=null==v||null==w?0:Math.max(0,w-v);return{points:c,sampleCount:c.length,observedSamples:l+d+u,belowSamples:l,insideSamples:d,aboveSamples:u,totalDuration:k,observedDuration:x,unobservedDuration:Math.max(0,k-x),belowDuration:y,insideDuration:g,aboveDuration:b,peakExcess:h,peakExcessAt:p,peakDeficit:f,peakDeficitAt:m}}function au(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function cu(e){const t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,au(e)]))}}function lu(e,t,n={}){if("region-enter"!==t.type)return e;const i=function(e,t){const n=t.stageId?.(e);if(n)return n;const i=e.region.metadata;if(i&&"object"==typeof i){const e=i.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),o=e.stages.findIndex(e=>e.id===i);if(0>o)return e;const r=n.entityId?.(t)??t.bodyId;if(!r)return e;const s=e.entities[r]??au(r),a=s.currentStageId?e.stages.findIndex(e=>e.id===s.currentStageId):-1,c=!s.visitedStageIds.includes(i),l=Number(t.observation.timestamp),d=Number.isFinite(l)?l:0,u={...s,currentStageId:i,furthestStageId:o>s.furthestStageIndex?i:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,o),visitedStageIds:c?[...s.visitedStageIds,i]:s.visitedStageIds,visitsByStage:{...s.visitsByStage,[i]:(s.visitsByStage[i]??0)+1},firstEnteredAt:c?{...s.firstEnteredAt,[i]:d}:s.firstEnteredAt,lastEnteredAt:{...s.lastEnteredAt,[i]:d},regressionCount:a>=0&&a>o?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(r)?e.bodyIds:[...e.bodyIds,r],entities:{...e.entities,[r]:u}}}function du(e){const t=e.bodyIds.map(t=>e.entities[t]??au(t)),n=t.length;let i=n;return e.stages.map((e,o)=>{const r=t.filter(e=>e.furthestStageIndex>=o).length,s=t.filter(t=>t.visitedStageIds.includes(e.id)).length,a=t.reduce((t,n)=>t+(n.visitsByStage[e.id]??0),0),c={id:e.id,label:e.label??e.id,reached:r,entered:s,total:n,conversion:n>0?r/n:0,fromPrevious:i>0?r/i:0,dropoff:Math.max(0,i-r),visits:a,repeatVisits:Math.max(0,a-s)};return i=r,c})}function uu(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function hu(e,t,n,i){const o="function"==typeof e?e(t,n):e;return Number.isFinite(o)?Number(o):i}function pu(e,t,n){return uu(e[t])??n}function fu(e,t){return"number"==typeof e?e:e?.[t]??0}function mu(e){const{band:t,idPrefix:n,plot:i,projection:o}=e,{includeBoundaryWalls:r=!0,includeInteriorWalls:s=!0,wallThickness:a=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const i of e.values){const o=e.scale(i);Number.isFinite(o)&&(n.add(Number(o)),n.add(Number(o)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=r?c.length-1:c.length-2,d=[];for(let e=r?0:1;l>=e;e+=1){if(!s&&e>0&&c.length-1>e)continue;const t=c[e];d.push({id:`${n}-wall-${e}`,shape:"x"===o?{type:"aabb",x:t,y:i.y+i.height/2,width:a,height:i.height}:{type:"aabb",x:i.x+i.width/2,y:t,width:i.width,height:a}})}return d}function yu(e){const{plot:t,idPrefix:n="physics-scale",bounds:i={},xBins:o,xBands:r,yBands:s}=e,a=[];if(!1!==i&&a.push(...eo(t,{idPrefix:n,...i})),o){const{idPrefix:e,yTop:i,yBottom:r,...s}=o;a.push(...to({...s,idPrefix:e??n+"-xbin",yTop:i??t.y,yBottom:r??t.y+t.height}))}return r&&a.push(...mu({band:r,idPrefix:r.idPrefix??n+"-xband",plot:t,projection:"x"})),s&&a.push(...mu({band:s,idPrefix:s.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function gu(e){const{plot:t,rows:n,columns:i=n+1,pegRadius:o=3,idPrefix:r="galton-peg",yStart:s=t.y+.18*t.height,yEnd:a=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:d=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(i));if(0===u)return[];const p=u>1?(a-s)/(u-1):0,f=t.width/h,m=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?f/2:0;for(let i=0;h>i;i+=1){const a=t.x+f*(i+.5)+n;t.x+o>a||a>t.x+t.width-o||m.push({id:`${r}-${e}-${i}`,shape:{type:"aabb",x:a,y:s+e*p,width:2*o,height:2*o},restitution:l,friction:d})}}return m}function bu(e,t={}){const{idPrefix:n="physics-token",radius:i=5,shape:o,mass:r,vx:s,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=ii(l),p=fu(d,"x"),f=fu(d,"y");return e.map((e,l)=>{const d=hu(t.x,e,l,pu(e,"x",0)),m=hu(t.y,e,l,pu(e,"y",0)),y=hu(i,e,l,5),g="function"==typeof o?o(e,l):o??{type:"circle",radius:y};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*p,y:m+(h()-.5)*f,vx:hu(s,e,l,0),vy:hu(a,e,l,0),mass:hu(r,e,l,1),spawnAt:hu(c,e,l,void 0),shape:g,datum:u?u(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function xu(e,t={}){const{idPrefix:n="sediment",collider:i=!0,colliderThickness:o=1,restitution:r=.05,friction:s=.2,...a}=t,c=zi(e,a),l=i?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+o/2,width:e.width,height:o},restitution:r,friction:s})):[];return{columns:c,colliders:l}}function vu(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:i=1,startAt:o=0,rebase:r=!0,sort:s=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return uu("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=a.length?Math.min(...a.map(e=>e.time)):0;return{initialSpawns:a.map(({spawn:e,time:t})=>({...e,spawnAt:o+(r?t-c:t)})).sort((e,t)=>s?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:o,timeAccessor:"spawnAt",timeScale:i}}}import{forwardRef as wu,useCallback as ku,useEffect as Mu,useImperativeHandle as Su,useMemo as Iu,useRef as Au,useState as Cu}from"react";function Ru(e,t,n={}){const i=new Set,o=[...e.get(t)??[]];let r=0;for(;o.length>r;){const t=o[r];if(r+=1,!i.has(t)){i.add(t);for(const n of e.get(t)??[])o.push(n)}}return n.includeStart&&i.add(t),i}function Du(e,t,n){return cl(n,e,t)}function Pu(e,t){return t>e?-1:e>t?1:0}function $u(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Bu(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function ju(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function Tu(e){const t=[],n=new Map,i=[],o=new Set;e.data.forEach((r,s)=>{const a=(Du(r,s,e.taskIDAccessor)??"")+"";if(!a)return void t.push({code:"duplicate-task-id",message:`Task row ${s} has an empty id.`,taskIDs:[]});if(n.has(a))return void t.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(Du(r,s,e.laneAccessor)??"Unassigned")+"";o.has(c)||(o.add(c),i.push(c));const l=Du(r,s,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(Pu),u=Du(r,s,e.blockerAccessor),h=Du(r,s,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(Du(r,s,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:s,datum:r,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:Du(r,s,e.startAccessor),end:Du(r,s,e.endAccessor),progress:ju(Du(r,s,e.progressAccessor)),status:h,completionTime:Du(r,s,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!Du(r,s,e.milestoneAccessor)})});const r=e.laneOrder?[...e.laneOrder,...i.filter(t=>!e.laneOrder?.includes(t))]:i,s=new Map(r.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=s.get(e.lane)??0;const a=new Map,c=new Map;for(const e of n.keys())a.set(e,[]),c.set(e,[]);const l=[],d=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of d)e.dependencyIDs.forEach((i,o)=>{const r=n.get(i);if(!r)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${i}".`,taskIDs:[e.id,i]});const s={id:$u(i,e.id),sourceID:i,targetID:e.id,sourceIndex:r.index,targetIndex:e.index,socketID:Bu(e.id,o),socketIndex:o};l.push(s),a.get(e.id)?.push(s),c.get(i)?.push(s),e.incomingEdgeIDs.push(s.id),e.socketIDs.push(s.socketID),r.outgoingEdgeIDs.push(s.id)});for(const e of a.values())e.sort((e,t)=>Pu(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=Bu(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>Pu(e.targetID,t.targetID));for(const e of n.values()){const t=a.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(c.get(e.id)??[]).map(e=>e.id)}const u=new Map,h=new Map;for(const e of n.keys())u.set(e,a.get(e)?.length??0),h.set(e,0);const p=[...n.keys()].filter(e=>0===u.get(e)).sort(Pu);let f=0;for(;p.length;){const e=p.shift();f+=1;for(const t of c.get(e)??[]){const n=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,n);const i=(u.get(t.targetID)??0)-1;if(u.set(t.targetID,i),0===i){const e=p.findIndex(e=>e>t.targetID);0>e?p.push(t.targetID):p.splice(e,0,t.targetID)}}}if(f!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(Pu);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let m=0;const y=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of y)e.level=h.get(e.id)??0,m=Math.max(m,e.level);return{nodes:y,edges:l,byID:n,incoming:a,outgoing:c,lanes:r,maxLevel:m,diagnostics:t,valid:0===t.length}}function Nu(e,t,n={}){const i=Math.max(240,t.width),o=Math.max(220,t.height),r=t.paddingX??48,s=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(i-2*r)/Math.max(1,e.lanes.length)),l=Math.max(76,(o-s-a)/Math.max(1,e.maxLevel+1)),d=Math.min(n.taskWidth??112,Math.max(58,.78*c)),u=Math.min(n.taskHeight??58,.64*l),h=n.socketRadius??5,p=Math.max(1,Math.round(n.gutterCount??3)),f=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=f.get(e)??[];n.push(t),f.set(e,n)}for(const e of f.values())e.sort((e,t)=>Pu(e.id,t.id));const m=e.nodes.map(e=>{const t=f.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id));return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:r+c*(e.laneIndex+.5),y:s+l*(e.level+.5)+(n-(t.length-1)/2)*Math.min(18,.3*u),width:d,height:u}}),y=new Map(m.map(e=>[e.taskID,e])),g=[],b=[];e.edges.forEach((t,n)=>{const i=y.get(t.sourceID),o=y.get(t.targetID);if(!i||!o)return;const r=e.incoming.get(t.targetID)??[],s=Math.min(.72*o.width,14*Math.max(1,r.length-1)),a=r.length>1?o.x-s/2+s*t.socketIndex/(r.length-1):o.x,c=o.y-o.height/2-h-2;g.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:a,y:c,radius:h});const l={x:i.x,y:i.y+i.height/2+3},d=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(n%p-(p-1)/2));var u;b.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(u=[l,{x:l.x,y:d},{x:a,y:d},{x:a,y:c}],u.filter((e,t)=>{const n=u[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const x=new Map(g.map(e=>[e.id,e])),v=new Map(b.map(e=>[e.edgeID,e]));return{tasks:m,sockets:g,routes:b,taskByID:y,socketByID:x,routeByEdgeID:v}}function Wu(e,t,n="all"){const i=Array.from(new Set(t)).sort(Pu),o=new Set,r=()=>i.every(e=>o.has(e));return{taskID:e,mode:n,incomingEdgeIDs:i,deliver:e=>i.includes(e)?(o.add(e),r()):r(),reset:(e=[])=>{o.clear();for(const t of e)i.includes(t)&&o.add(t)},isSatisfied:r,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...i],deliveredEdgeIDs:[...o].sort(Pu),satisfied:r()})}}function Eu(e){return e instanceof Date?e.getTime():Number(e)}function zu(e,t){const n=Eu("object"!=typeof t||t instanceof Date?t:t.currentTime),i=e.map((e,t)=>({event:e,index:t,time:Eu(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),o=new Set,r=new Map,s=new Set,a=new Set;for(const{event:e}of i)"task-completed"===e.type?(o.add(e.taskID),r.delete(e.taskID)):"task-blocked"===e.type?r.set(e.taskID,e.reason):"task-unblocked"===e.type?r.delete(e.taskID):"dependency-delivered"===e.type?s.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:i.map(e=>e.event),completedTaskIDs:o,blockedByTaskID:r,deliveredEdgeIDs:s,armedTaskIDs:a}}function Ou(e,t,n={}){const i=new Set(n.completedTaskIDs??[]),o=[...Ru(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(n.isComplete?n.isComplete(e):i.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),r=Array.from(new Set(o.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:o.length,affectedLaneCount:r.length,downstreamTaskIDs:o.map(e=>e.id),affectedLanes:r}}var Fu=[];function Lu(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function qu(e){if(null==e.completionTime)return null;const t=Lu(e.completionTime,NaN);return Number.isFinite(t)?t:null}function Yu(e,t,n,i){const o=new Set;for(const r of e.nodes){const s=e.incoming.get(r.id)??[];(i.has(r.id)||!n.has(r.id)&&s.every(e=>t.has(e.id)))&&o.add(r.id)}return o}function Hu(e,t,n,i){const o=e.nodes.map(qu).filter(e=>null!=e),r=o.length?Math.min(...o)-1:0,s="replay"!==t||i?n:r,a=new Set,c=new Map;for(const n of e.nodes){const e=qu(n);(null!=e&&s>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const l=new Set;if("replay"!==t||i)for(const t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:s,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:Yu(e,l,c,a),blockers:c,previewTaskID:null}}function Gu(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function Xu(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function _u(e){const t=Xu(e.body);if(!t||2>t.route.length)return null;const n=function(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}(t.route),i=function(e,t){let n=1/0,i=0,o=0;for(let r=1;t.length>r;r+=1){const s=t[r-1],a=t[r],c=a.x-s.x,l=a.y-s.y,d=c*c+l*l,u=Math.sqrt(d);if(0>=u)continue;const h=Math.max(0,Math.min(1,((e.x-s.x)*c+(e.y-s.y)*l)/d)),p=Math.hypot(e.x-(s.x+c*h),e.y-(s.y+l*h));n>p&&(n=p,i=o+h*u),o+=u}return i}(e.body,t.route),o=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let i=1;e.length>i;i+=1){const o=e[i-1],r=e[i],s=r.x-o.x,a=r.y-o.y,c=Math.hypot(s,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:o.x+s*e,y:o.y+a*e},tangent:{x:s/c,y:a/c}}}n+=c}}const i=e[e.length-2],o=e[e.length-1],r=o.x-i.x,s=o.y-i.y,a=Math.hypot(r,s)||1;return{point:o,tangent:{x:r/a,y:s/a}}}(t.route,Math.min(n,i+22));return{x:2.5*(78*o.tangent.x-e.body.vx)+8*(o.point.x-e.body.x),y:2.5*(78*o.tangent.y-e.body.vy)+8*(o.point.y-e.body.y)}}function Vu(e,t){const n=t.points[0]??{x:0,y:0},i=t.points[1]??n,o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:o/s*42,vy:r/s*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as Uu,jsxs as Ku}from"react/jsx-runtime";function Qu({machine:e,layout:t,runtime:n,downstreamSet:i,selectedSet:o,width:r,height:s,seed:a,reduced:c,onSelectTask:l}){return Ku("svg",{"aria-hidden":"true",width:r,height:s,viewBox:`0 0 ${r} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Uu("defs",{children:Uu("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Uu("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const i=t.tasks.filter(e=>e.laneIndex===n),o=i[0]?.x??0;return Ku("g",{children:[Uu("line",{x1:o,x2:o,y1:32,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Uu("text",{x:o,y:23,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),o=n.inFlight.has(e.edgeID),r=i.has(e.targetID)||i.has(e.sourceID),s=e.points.map(e=>`${e.x},${e.y}`).join(" ");return Uu("polyline",{points:s,fill:"none",stroke:r?"var(--semiotic-highlight, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:r?4:o?3:2,strokeOpacity:t||o||r?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return Ku("g",{children:[Uu("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-background, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&Uu("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const r=t.taskByID.get(e.id);if(!r)return null;const s=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=o.has(e.id)||u,p=i.has(e.id),f=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-muted, #75818a)"}(e,n),m=r.x-r.width/2,y=r.y-r.height/2,g=Math.max(2,r.height*e.progress);return Ku("g",{children:[Ku("g",{style:{transform:`rotate(${s?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[Uu("rect",{x:m,y:y,width:r.width,height:r.height,rx:e.milestone?12:4,fill:"var(--semiotic-background, #fff)",stroke:h||p?"var(--semiotic-highlight, #e08a1e)":f,strokeWidth:h?4:p?3:2}),Uu("rect",{x:m+3,y:y+r.height-g+1,width:r.width-6,height:Math.max(0,g-4),rx:2,fill:f,opacity:s?.86:.46})]}),d&&Ku("g",{opacity:u?.28:1,children:[Uu("line",{x1:m-8,x2:m+14,y1:r.y+9,y2:r.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Uu("circle",{cx:m-8,cy:r.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Ku("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Uu("rect",{x:m,y:y,width:r.width,height:r.height,fill:"transparent"}),Uu("text",{x:r.x,y:r.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),Ku("text",{x:r.x,y:r.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-muted, #5f6b72)",children:[Math.round(100*e.progress),"% · ",s?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as Zu,jsxs as Ju}from"react/jsx-runtime";var eh={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},th=wu(function(e,t){const{data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p,mode:f="snapshot",insight:m="blocker-amplification",currentTime:y,controls:g=!1,selectedTaskIDs:b,onSelectionChange:x,onObservation:v,reducedMotion:w,seed:k=31,width:M=920,height:S=620,responsiveWidth:I,responsiveHeight:A,title:C="Dependency chain reaction",description:R,className:D,accessibleTable:P=!0,enableHover:$=!0}=e,B=Au(null),[j,T]=Cu([]),N=b?Array.from(b):j,W=Iu(()=>new Set(N),[N]),E=Lu(y,1/0),z="settle"===w,O=Iu(()=>Tu({data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p}),[n,i,o,r,s,a,c,l,d,u,h,p]),F=Iu(()=>Nu(O,{width:M,height:S}),[O,M,S]),[L,q]=Cu(()=>Hu(O,f,E,z)),Y=Au(L),H=ku(e=>{Y.current=e,q(e)},[]),G=ku(e=>v?.(e),[v]);Mu(()=>{const e=Hu(O,f,E,z);B.current?.clear(),Y.current=e,q(e)},[O,f,E,z]);const X=ku(e=>{const t=W.has(e)?N.filter(t=>t!==e):[e];b||T(t),x?.(t)},[b,x,W,N]),_=ku(e=>{if(z)return;const t=Gu(Y.current),n=[];for(const i of O.outgoing.get(e)??[]){if(t.delivered.has(i.id)||t.inFlight.has(i.id))continue;const e=F.routeByEdgeID.get(i.id);e&&(t.inFlight.add(i.id),n.push(Vu(i,e)))}n.length&&(H(t),B.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[H,F,O,z]),V=ku((e,t)=>{const n=O.byID.get(e),i=Y.current;if(!n||i.completed.has(e))return;const o=Gu(i);o.completed.add(e),o.blockers.delete(e),o.armed.add(e),null!=t&&(o.currentTime=t),H(o),G({type:"task-completed",taskID:e,datum:n.datum}),_(e)},[H,G,O,_]),U=ku(e=>{const t=Gu(Y.current),n=[],i=[];for(const i of e){if(t.delivered.has(i))continue;const e=O.edges.find(e=>e.id===i);e&&(t.delivered.add(i),t.inFlight.delete(i),n.push(e))}for(const e of n){const n=O.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(O.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),i.push(n.id))}if(n.length){H(t);for(const e of n)G({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of i)G({type:"task-armed",taskID:e})}},[H,G,O]),K=ku((e,t)=>{const n=[],i=[];for(const e of t.readBodies()){const t=Xu(e);if(!t||Y.current.delivered.has(t.edgeID))continue;const o=t.route[t.route.length-1];o&&9>=Math.hypot(e.x-o.x,e.y-o.y)&&(n.push(t.edgeID),i.push(e.id))}i.length&&t.remove(i),n.length&&U(n)},[U]),Q=ku(()=>{const e=Gu(Y.current);for(const t of O.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=Yu(O,e.delivered,e.blockers,e.completed),e.playing=!1,B.current?.settle(),H(e),G({type:"machine-settled"})},[H,G,O]),Z=ku(()=>{const e=Gu(Y.current);e.playing=!1,H(e)},[H]),J=ku(()=>{const e=Y.current,t=O.nodes.map(e=>({node:e,time:qu(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void V(t.node.id,t.time);Z();const n=[...e.blockers.keys()].map(t=>Ou(O,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&G({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[G,O,Z,V]),ee=ku(()=>{if(z)return void Q();const e=Gu(Y.current);e.playing=!0,H(e)},[H,z,Q]);Mu(()=>{if(!L.playing||"replay"!==f||z)return;const e=window.setInterval(J,760);return()=>window.clearInterval(e)},[f,z,L.playing,J]);const te=ku(()=>{B.current?.clear(),H(Hu(O,f,E,z))},[H,O,f,E,z]),ne=ku(e=>{if(!O.byID.has(e))return;const t=Gu(Y.current);t.previewTaskID=e,H(t);const n=Ou(O,e,{completedTaskIDs:t.completed});G({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[H,G,O]),ie=ku(()=>{const e=Gu(Y.current);e.previewTaskID=null,H(e)},[H]),oe=ku((e,t)=>{if(!O.byID.has(e))return;const n=Gu(Y.current);n.blockers.set(e,t),n.armed.delete(e),H(n)},[H,O]),re=ku(e=>{if(!O.byID.has(e))return;const t=Gu(Y.current);t.blockers.delete(e),(O.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),H(t)},[H,O]),se=ku(e=>Ou(O,e,{completedTaskIDs:Y.current.completed}),[O]),ae=ku(()=>{const e=Y.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...N],tasks:O.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:O.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[O,N]);Su(t,()=>({play:ee,pause:Z,step:J,reset:te,settle:Q,previewResolve:ne,clearPreview:ie,completeTask:V,blockTask:oe,unblockTask:re,getAmplification:se,getMachineState:ae}),[oe,ie,se,ae,Z,V,ee,ne,te,Q,J,re]);const ce=L.previewTaskID??N[0]??null,le=ce?Ou(O,ce,{completedTaskIDs:L.completed}):null,de=Iu(()=>new Set(le?.downstreamTaskIDs??[]),[le?.downstreamTaskIDs]),ue=Iu(()=>function(e,t,n){return e.nodes.flatMap(i=>{const o=t.taskByID.get(i.id);if(!o)return[];const r=e.incoming.get(i.id)??[],s=r.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(i.id),c=n.completed.has(i.id)?"completed":a?"blocked: "+a:n.armed.has(i.id)?"armed":"waiting";return[{id:i.id,label:`${i.label}, ${i.lane}, ${Math.round(100*i.progress)}%, ${c}`,description:`${s} of ${r.length} prerequisites delivered.`,datum:i.datum,x:o.x,y:o.y,width:o.width,height:o.height,shape:"rect",group:i.lane}]})}(O,F,L),[F,O,L]),he=Iu(()=>Zu(Qu,{machine:O,layout:F,runtime:L,downstreamSet:de,selectedSet:W,width:M,height:S,seed:k,reduced:z,onSelectTask:X}),[de,S,F,O,z,L,k,X,W,M]),pe=Iu(()=>{const e=[...L.blockers.keys()].map(e=>Ou(O,e,{completedTaskIDs:L.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${O.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[O,L.blockers,L.completed]),fe=Iu(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:S,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:M-2,y1:0,x2:M-2,y2:S,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:M,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:S-2,x2:M,y2:S-2,thickness:4}}],[S,M]),me=!0===g?["play","pause","step","reset","settle"]:g||[];return Ju("div",O.valid?{className:D,style:{width:M,maxWidth:"100%",position:"relative"},children:[me.length>0&&Zu("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:me.map(e=>Zu("button",{type:"button",onClick:"play"===e?ee:"pause"===e?Z:"step"===e?J:"reset"===e?te:Q,"aria-pressed":"play"===e?L.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),Zu(ks,{ref:B,size:[M,S],responsiveWidth:I,responsiveHeight:A,title:C,description:R??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${pe}${le&&"blocker-amplification"===m?` Selected task reaches ${le.downstreamTaskCount} unfinished tasks across ${le.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:$,initialSpawns:Fu,bodyForces:_u,bodyStyle:{fill:"var(--semiotic-accent, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:ue,onSemanticItemActivate:e=>e.id&&X(e.id),foregroundGraphics:()=>he,paused:z,continuous:L.inFlight.size>0,onTick:K,config:{bodyLimit:Math.max(16,O.edges.length+4),colliders:fe,settleStepLimit:2200,kernel:{seed:k,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),P&&Ju("table",{style:eh,children:[Zu("caption",{children:pe}),Zu("thead",{children:Ju("tr",{children:[Zu("th",{children:"Task"}),Zu("th",{children:"Lane"}),Zu("th",{children:"Progress"}),Zu("th",{children:"State"}),Zu("th",{children:"Waiting on"}),Zu("th",{children:"Downstream reach"})]})}),Zu("tbody",{children:O.nodes.map(e=>{const t=Ou(O,e.id,{completedTaskIDs:L.completed});return Ju("tr",{children:[Zu("th",{scope:"row",children:e.label}),Zu("td",{children:e.lane}),Ju("td",{children:[Math.round(100*e.progress),"%"]}),Zu("td",{children:L.completed.has(e.id)?"Completed":L.blockers.has(e.id)?"Blocked":L.armed.has(e.id)?"Armed":"Waiting"}),Zu("td",{children:L.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!L.completed.has(e)).join(", ")||"None")}),Ju("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:D,role:"alert",style:{width:M,maxWidth:"100%"},children:[Zu("strong",{children:"ChainReactionChart could not compile this dependency graph."}),Zu("ul",{children:O.diagnostics.map((e,t)=>Zu("li",{children:e.message},`${e.code}-${t}`))})]})});th.displayName="ChainReactionChart";var nh=ks;export{Ai as BuiltInPhysicsEngineAdapter,th as ChainReactionChart,sl as CollisionSwarmChart,jc as EventDropChart,Ac as GaltonBoardChart,hd as GauntletChart,pd as GuantletChart,Dd as PhysicalFlowChart,Zc as PhysicsCustomChart,Fc as PhysicsPileChart,ko as PhysicsPipelineStore,Gn as PhysicsSVGOverlay,Ei as PhysicsSedimentAccumulator,Xd as ProcessFlowChart,ws as StreamPhysicsFrame,xa as absorbRegion,na as aggregateRegionCounts,vu as arrivalReplay,qn as bodiesToAnnotationAnchors,wa as bodyGroupSpec,Vs as buildCollisionSwarmPhysics,Hs as buildEventDropPhysics,Ls as buildGaltonBoardPhysics,ta as buildPhysicalFlowPhysics,Yn as buildPhysicsAnnotationContext,Xs as buildPhysicsPile,Sa as buildProcessFlowPhysics,Ou as calculateBlockerAmplification,ga as capacitatedRegion,fa as chargeGateRegion,yu as collidersFromScales,su as comparePhysicsTrace,Tu as compileDependencyMachine,ll as compileMotionEncoding,fl as compilePhysicsEncoding,Xo as composePhysicsControllers,Rs as composeStyleRules,zo as createCapacityQueueController,Ci as createDefaultPhysicsEngineAdapter,Ho as createDependencyGateController,Wu as createLogicalJoin,ml as createPhysicsEncodingLayout,_o as createPortalController,cu as createProcessJourneyLedger,Yo as createServiceLevelController,Lo as createServiceResourcePoolController,nh as default,pl as deriveMotionVector,Fi as evaluatePhysicsBodyBudget,va as forceFieldRegion,gu as galtonPegs,oa as groupCompletionRows,De as hatchFillId,$e as hatchPatternDef,Ce as isHatchFill,Ms as makeRuleValueResolver,Is as matchesThreshold,pa as membraneRegion,Hn as normalizePhysicsAnnotations,ul as opacityFromAge,Ml as physicsProcessBoundaryColliders,Al as physicsProcessGroupSemanticItems,Sl as physicsProcessRegionSemanticItem,Il as physicsProcessStageSemanticItems,tu as physicsReferenceEnvelope,_l as planGauntletPropertyWork,ba as portalRegion,ya as pressureFieldRegion,Hd as processChrome,du as processJourneyRows,ka as processLaneWalls,da as processStageLayout,ha as processStageRegions,aa as processVolumePolygons,ia as regionCountsToProjectionRows,Vl as replaceGauntletNegative,zu as replayStateTransitions,cl as resolveMotionAccessor,dl as resolveMotionAge,hl as resolveMotionVector,Cs as resolveStyleRules,Be as resolveSvgFill,Nu as routeDependencyTracks,ma as routeSurfaceRegion,As as ruleMatches,xu as sedimentBake,zi as sedimentHeightfield,bu as spawnFromTokens,sa as stageTargetInVolume,lu as updateProcessJourney};
2
+ import{createProcessJourneyLedger as e,processJourneyRows as t,updateProcessJourney as n}from"./chunk-chunk-YWZB3KPI.module.min.js";import{BuiltInPhysicsEngineAdapter as s,CollisionSwarmChart as i,EventDropChart as o,GaltonBoardChart as r,GauntletChart as a,GuantletChart as c,PhysicalFlowChart as l,PhysicsCustomChart as d,PhysicsPileChart as u,PhysicsPipelineStore as h,PhysicsSVGOverlay as m,PhysicsSedimentAccumulator as p,ProcessFlowChart as f,StreamPhysicsFrame as g,StreamPhysicsFrame_default as y,absorbRegion as k,aggregateRegionCounts as x,bodiesToAnnotationAnchors as b,bodyGroupSpec as v,buildCollisionSwarmPhysics as w,buildEventDropPhysics as I,buildGaltonBoardPhysics as D,buildPhysicalFlowPhysics as M,buildPhysicsAnnotationContext as A,buildPhysicsPile as T,buildProcessFlowPhysics as S,capacitatedRegion as C,chargeGateRegion as $,collidersFromPlotBounds as E,collidersFromXScaleBins as N,composePhysicsControllers as j,createCapacityQueueController as R,createDefaultPhysicsEngineAdapter as P,createDependencyGateController as W,createPortalController as B,createServiceLevelController as F,createServiceResourcePoolController as L,evaluatePhysicsBodyBudget as q,forceFieldRegion as O,groupCompletionRows as z,membraneRegion as U,normalizePhysicsAnnotations as Z,physicsProcessBoundaryColliders as H,physicsProcessGroupSemanticItems as X,physicsProcessRegionSemanticItem as Y,physicsProcessStageSemanticItems as J,planGauntletPropertyWork as K,portalRegion as V,pressureFieldRegion as G,processChrome as Q,processLaneWalls as _,processStageLayout as ee,processStageRegions as te,processVolumePolygons as ne,regionCountsToProjectionRows as se,replaceGauntletNegative as ie,routeSurfaceRegion as oe,sedimentHeightfield as re,stageTargetInVolume as ae}from"./chunk-chunk-Z5KXAVQD.module.min.js";import{mulberry32 as ce}from"./chunk-chunk-SIRIJ3DY.module.min.js";import{composeStyleRules as le,makeRuleValueResolver as de,matchesThreshold as ue,resolveStyleRules as he,ruleMatches as me}from"./chunk-chunk-EMO5NUGE.module.min.js";import"./chunk-chunk-SV4XAZ3Q.module.min.js";import"./chunk-chunk-STZFFTAN.module.min.js";import{compileMotionEncoding as pe,deriveMotionVector as fe,hatchFillId as ge,hatchPatternDef as ye,isHatchFill as ke,opacityFromAge as xe,resolveMotionAccessor as be,resolveMotionAge as ve,resolveMotionVector as we,resolveSvgFill as Ie}from"./chunk-chunk-ODUZEEBH.module.min.js";import"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-WCX6U47H.module.min.js";import"./chunk-chunk-KTWEBFMX.module.min.js";import"./chunk-chunk-ZCNBUZPL.module.min.js";import"./chunk-chunk-YHNZCPOZ.module.min.js";function De(e){const{data:t,encoding:n,defaults:s={},scales:i}=e,o=pe({data:t,encoding:n}),r=[],a=new Map,c=[],l=[],d=new Map;return o.rows.forEach((e,t)=>{const{id:o,datum:u}=e,h=Math.max(0,be(n.appearance?.size,u,t)??s.size??6),m=be(n.appearance?.shape,u,t)??s.shape??{type:"circle",radius:h},p=e.placement.x??s.x??0,f=e.placement.y??s.y??0,g=i?.x?i.x(p):p,y=i?.y?i.y(f):f,k=be(n.appearance?.color,u,t)??s.color,x=be(n.appearance?.opacity,u,t)??s.opacity,b=be(n.appearance?.stroke,u,t)??s.stroke,v=be(n.appearance?.strokeWidth,u,t)??s.strokeWidth,w=be(n.time?.spawnAt,u,t)??e.time.arrival,I=e.kinematics.velocityX,D=e.kinematics.velocityY,M=be(n.dynamics?.mass,u,t)??s.mass??1,A=be(n.dynamics?.friction,u,t),T=be(n.dynamics?.restitution,u,t),S=be(n.dynamics?.bodyCollisions,u,t),C={id:o,x:g,y:y,mass:M,shape:{...m},datum:u,...null!=w&&{spawnAt:w},...null!=I&&{vx:I},...null!=D&&{vy:D},...null!=A&&{friction:A},...null!=T&&{restitution:T},...null!=S&&{bodyCollisions:S}},$={...null!=k&&{fill:k},...null!=x&&{opacity:x},...null!=b&&{stroke:b},...null!=v&&{strokeWidth:v}},E={id:o,datum:u,appearance:{color:k,opacity:x,shape:m,size:h,stroke:b,strokeWidth:v},placement:{x:g,y:y,lane:e.placement.lane,space:n.placement?.space??"world"},time:{arrival:w,spawnAt:w,basis:n.time?.basis??"simulation",unit:n.time?.unit},kinematics:{velocityX:I,velocityY:D,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:S,friction:A,mass:M,restitution:T},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:C};r.push(E),a.set(o,E),c.push(C),d.set(o,$),l.push({id:o,bodyId:o,label:e.accessible.label,description:e.accessible.description,datum:u,x:g,y:y,group:e.accessible.group})}),{rows:r,byId:a,spawns:c,semanticItems:l,bodyStyle:e=>d.get(e.id)??{}}}function Me(e){return t=>{const n=De({data:t.data,encoding:e.encoding,defaults:e.defaults,scales:t.scales}),s=e.extend?.(t,n)??{};return{...s,initialSpawns:n.spawns,bodyStyle:n.bodyStyle,semanticItems:[...n.semanticItems,...s.semanticItems??[]]}}}var Ae=[.1,.5,.9],Te=1e6;function Se(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ce(e,t,n,s,i){return"function"==typeof s?s(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,s??i)}function $e(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Ee(e,t,n,s){const i=e.flatMap((e,i)=>{const o=Se(Ce(e,i,t,n,"time")),r=Se(Ce(e,i,t,s,"value"));return null==o||null==r?[]:[{time:$e(o),value:r,index:i}]});i.sort((e,t)=>e.time-t.time||e.index-t.index);const o=[];for(const e of i){const t=o[o.length-1];t?.time===e.time?t.value=e.value:o.push({time:e.time,value:e.value})}return o}function Ne(e,t,n,s){if(!e.length)return null;const i=e[0],o=e[e.length-1];if(i.time>t)return"clamp"===s?i.value:null;if(t>o.time)return"clamp"===s?o.value:null;const r=function(e,t){let n=0,s=e.length;for(;s>n;){const i=n+s>>>1;t>e[i].time?n=i+1:s=i}return n}(e,t),a=e[r];if(a?.time===t)return a.value;const c=e[Math.max(0,r-1)];return"step"!==n&&a&&a.time!==c.time?c.value+(t-c.time)/(a.time-c.time)*(a.value-c.value):c.value}function je(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,s=Math.floor(n),i=Math.ceil(n);return s===i?e[s]:e[s]+(e[i]-e[s])*(n-s)}function Re(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",s=function(e){const t=(e??Ae).map(e=>{const t=Se(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return $e(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),i=function(e){if(Array.isArray(e)){if(e.length>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Se).filter(e=>null!=e).map($e))).sort((e,t)=>e-t)}const t=e,n=Se(t.start),s=Se(t.end),i=Se(t.step);if(null==n||null==s||null==i||0>=i||n>s)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const o=Math.floor((s-n)/i)+1;if(o>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const r=[],a=1e-10*Math.max(1,Math.abs(s),Math.abs(n));for(let e=0;o>e;e+=1){const t=n+e*i;if(t>s+a)break;r.push($e(Math.min(t,s)))}if(r.length&&a>=Math.abs(r[r.length-1]-s)||r.push($e(s)),r.length>Te)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(r)).sort((e,t)=>e-t)}(e.sampleAt),o=e.runs.map(t=>Ee(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:i.map(e=>{const i=o.map(s=>Ne(s,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),r={};for(const e of s)r[e]=i.length?je(i,e):null;return{time:e,count:i.length,min:i.length?i[0]:null,max:i.length?i[i.length-1]:null,median:i.length?je(i,.5):null,quantiles:r}}),quantiles:s,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Pe(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function We(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Se(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const s=$e(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,s))throw Error(`comparePhysicsTrace could not find quantile ${s} in the reference envelope`);return e.quantiles[s]??null}function Be(e,t,n){return t>e?"below":e>n?"above":"inside"}function Fe(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const s=e.value-e.lower,i=t.value-t.lower,o=e.value-e.upper,r=t.value-t.upper,a=[0,1];for(const[e,t]of[[s,i],[o,r]])(0>e&&t>0||e>0&&0>t)&&a.push(-e/(t-e));a.sort((e,t)=>e-t);let c=0,l=0,d=0;for(let s=0;a.length-1>s;s+=1){const i=a[s],o=a[s+1];if(i>=o)continue;const r=(i+o)/2,u=(o-i)*n,h=Be(e.value+(t.value-e.value)*r,e.lower+(t.lower-e.lower)*r,e.upper+(t.upper-e.upper)*r);"below"===h?c+=u:"above"===h?d+=u:l+=u}return{below:c,inside:l,above:d,observed:n}}function Le(e,t,n={}){const s=n.interpolation??t.interpolation,i=n.outsideDomain??t.outsideDomain,o=Ee(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),r=n.lower??Pe(t,"lower"),a=n.upper??Pe(t,"upper"),c=t.points.map(e=>{const t=Ne(o,e.time,s,i),n=We(e,r),c=We(e,a);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":Be(t,n,c)}});let l=0,d=0,u=0,h=0,m=null,p=0,f=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?d+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,m=e.time),n>p&&(p=n,f=e.time)}let g=0,y=0,k=0,x=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],i=Math.max(0,n.time-t.time);if(i>0){if("linear"===s){const e=Fe(t,n);g+=e.below,y+=e.inside,k+=e.above,x+=e.observed;continue}"unobserved"!==t.status&&(x+=i,"below"===t.status?g+=i:"above"===t.status?k+=i:y+=i)}}const b=c[0]?.time,v=c[c.length-1]?.time,w=null==b||null==v?0:Math.max(0,v-b);return{points:c,sampleCount:c.length,observedSamples:l+d+u,belowSamples:l,insideSamples:d,aboveSamples:u,totalDuration:w,observedDuration:x,unobservedDuration:Math.max(0,w-x),belowDuration:g,insideDuration:y,aboveDuration:k,peakExcess:h,peakExcessAt:m,peakDeficit:p,peakDeficitAt:f}}function qe(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Oe(e,t,n,s){const i="function"==typeof e?e(t,n):e;return Number.isFinite(i)?Number(i):s}function ze(e,t,n){return qe(e[t])??n}function Ue(e,t){return"number"==typeof e?e:e?.[t]??0}function Ze(e){const{band:t,idPrefix:n,plot:s,projection:i}=e,{includeBoundaryWalls:o=!0,includeInteriorWalls:r=!0,wallThickness:a=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const s of e.values){const i=e.scale(s);Number.isFinite(i)&&(n.add(Number(i)),n.add(Number(i)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=o?c.length-1:c.length-2,d=[];for(let e=o?0:1;l>=e;e+=1){if(!r&&e>0&&c.length-1>e)continue;const t=c[e];d.push({id:`${n}-wall-${e}`,shape:"x"===i?{type:"aabb",x:t,y:s.y+s.height/2,width:a,height:s.height}:{type:"aabb",x:s.x+s.width/2,y:t,width:s.width,height:a}})}return d}function He(e){const{plot:t,idPrefix:n="physics-scale",bounds:s={},xBins:i,xBands:o,yBands:r}=e,a=[];if(!1!==s&&a.push(...E(t,{idPrefix:n,...s})),i){const{idPrefix:e,yTop:s,yBottom:o,...r}=i;a.push(...N({...r,idPrefix:e??n+"-xbin",yTop:s??t.y,yBottom:o??t.y+t.height}))}return o&&a.push(...Ze({band:o,idPrefix:o.idPrefix??n+"-xband",plot:t,projection:"x"})),r&&a.push(...Ze({band:r,idPrefix:r.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function Xe(e){const{plot:t,rows:n,columns:s=n+1,pegRadius:i=3,idPrefix:o="galton-peg",yStart:r=t.y+.18*t.height,yEnd:a=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:d=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(s));if(0===u)return[];const m=u>1?(a-r)/(u-1):0,p=t.width/h,f=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?p/2:0;for(let s=0;h>s;s+=1){const a=t.x+p*(s+.5)+n;t.x+i>a||a>t.x+t.width-i||f.push({id:`${o}-${e}-${s}`,shape:{type:"aabb",x:a,y:r+e*m,width:2*i,height:2*i},restitution:l,friction:d})}}return f}function Ye(e,t={}){const{idPrefix:n="physics-token",radius:s=5,shape:i,mass:o,vx:r,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=ce(l),m=Ue(d,"x"),p=Ue(d,"y");return e.map((e,l)=>{const d=Oe(t.x,e,l,ze(e,"x",0)),f=Oe(t.y,e,l,ze(e,"y",0)),g=Oe(s,e,l,5),y="function"==typeof i?i(e,l):i??{type:"circle",radius:g};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*m,y:f+(h()-.5)*p,vx:Oe(r,e,l,0),vy:Oe(a,e,l,0),mass:Oe(o,e,l,1),spawnAt:Oe(c,e,l,void 0),shape:y,datum:u?u(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function Je(e,t={}){const{idPrefix:n="sediment",collider:s=!0,colliderThickness:i=1,restitution:o=.05,friction:r=.2,...a}=t,c=re(e,a),l=s?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+i/2,width:e.width,height:i},restitution:o,friction:r})):[];return{columns:c,colliders:l}}function Ke(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:s=1,startAt:i=0,rebase:o=!0,sort:r=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return qe("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=a.length?Math.min(...a.map(e=>e.time)):0;return{initialSpawns:a.map(({spawn:e,time:t})=>({...e,spawnAt:i+(o?t-c:t)})).sort((e,t)=>r?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:i,timeAccessor:"spawnAt",timeScale:s}}}import{forwardRef as Ve,useCallback as Ge,useEffect as Qe,useImperativeHandle as _e,useMemo as et,useRef as tt,useState as nt}from"react";function st(e,t,n={}){const s=new Set,i=[...e.get(t)??[]];let o=0;for(;i.length>o;){const t=i[o];if(o+=1,!s.has(t)){s.add(t);for(const n of e.get(t)??[])i.push(n)}}return n.includeStart&&s.add(t),s}function it(e,t,n){return be(n,e,t)}function ot(e,t){return t>e?-1:e>t?1:0}function rt(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function at(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function ct(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function lt(e){const t=[],n=new Map,s=[],i=new Set;e.data.forEach((o,r)=>{const a=(it(o,r,e.taskIDAccessor)??"")+"";if(!a)return void t.push({code:"duplicate-task-id",message:`Task row ${r} has an empty id.`,taskIDs:[]});if(n.has(a))return void t.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(it(o,r,e.laneAccessor)??"Unassigned")+"";i.has(c)||(i.add(c),s.push(c));const l=it(o,r,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(ot),u=it(o,r,e.blockerAccessor),h=it(o,r,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(it(o,r,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:r,datum:o,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:it(o,r,e.startAccessor),end:it(o,r,e.endAccessor),progress:ct(it(o,r,e.progressAccessor)),status:h,completionTime:it(o,r,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!it(o,r,e.milestoneAccessor)})});const o=e.laneOrder?[...e.laneOrder,...s.filter(t=>!e.laneOrder?.includes(t))]:s,r=new Map(o.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=r.get(e.lane)??0;const a=new Map,c=new Map;for(const e of n.keys())a.set(e,[]),c.set(e,[]);const l=[],d=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of d)e.dependencyIDs.forEach((s,i)=>{const o=n.get(s);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${s}".`,taskIDs:[e.id,s]});const r={id:rt(s,e.id),sourceID:s,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:at(e.id,i),socketIndex:i};l.push(r),a.get(e.id)?.push(r),c.get(s)?.push(r),e.incomingEdgeIDs.push(r.id),e.socketIDs.push(r.socketID),o.outgoingEdgeIDs.push(r.id)});for(const e of a.values())e.sort((e,t)=>ot(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=at(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>ot(e.targetID,t.targetID));for(const e of n.values()){const t=a.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(c.get(e.id)??[]).map(e=>e.id)}const u=new Map,h=new Map;for(const e of n.keys())u.set(e,a.get(e)?.length??0),h.set(e,0);const m=[...n.keys()].filter(e=>0===u.get(e)).sort(ot);let p=0;for(;m.length;){const e=m.shift();p+=1;for(const t of c.get(e)??[]){const n=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,n);const s=(u.get(t.targetID)??0)-1;if(u.set(t.targetID,s),0===s){const e=m.findIndex(e=>e>t.targetID);0>e?m.push(t.targetID):m.splice(e,0,t.targetID)}}}if(p!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(ot);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let f=0;const g=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of g)e.level=h.get(e.id)??0,f=Math.max(f,e.level);return{nodes:g,edges:l,byID:n,incoming:a,outgoing:c,lanes:o,maxLevel:f,diagnostics:t,valid:0===t.length}}function dt(e,t,n={}){const s=Math.max(240,t.width),i=Math.max(220,t.height),o=t.paddingX??48,r=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(s-2*o)/Math.max(1,e.lanes.length)),l=Math.max(76,(i-r-a)/Math.max(1,e.maxLevel+1)),d=Math.min(n.taskWidth??112,Math.max(58,.78*c)),u=Math.min(n.taskHeight??58,.64*l),h=n.socketRadius??5,m=Math.max(1,Math.round(n.gutterCount??3)),p=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=p.get(e)??[];n.push(t),p.set(e,n)}for(const e of p.values())e.sort((e,t)=>ot(e.id,t.id));const f=e.nodes.map(e=>{const t=p.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id));return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:r+l*(e.level+.5)+(n-(t.length-1)/2)*Math.min(18,.3*u),width:d,height:u}}),g=new Map(f.map(e=>[e.taskID,e])),y=[],k=[];e.edges.forEach((t,n)=>{const s=g.get(t.sourceID),i=g.get(t.targetID);if(!s||!i)return;const o=e.incoming.get(t.targetID)??[],r=Math.min(.72*i.width,14*Math.max(1,o.length-1)),a=o.length>1?i.x-r/2+r*t.socketIndex/(o.length-1):i.x,c=i.y-i.height/2-h-2;y.push({id:t.socketID,edgeID:t.id,taskID:i.taskID,index:t.socketIndex,x:a,y:c,radius:h});const l={x:s.x,y:s.y+s.height/2+3},d=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(n%m-(m-1)/2));var u;k.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(u=[l,{x:l.x,y:d},{x:a,y:d},{x:a,y:c}],u.filter((e,t)=>{const n=u[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const x=new Map(y.map(e=>[e.id,e])),b=new Map(k.map(e=>[e.edgeID,e]));return{tasks:f,sockets:y,routes:k,taskByID:g,socketByID:x,routeByEdgeID:b}}function ut(e,t,n="all"){const s=Array.from(new Set(t)).sort(ot),i=new Set,o=()=>s.every(e=>i.has(e));return{taskID:e,mode:n,incomingEdgeIDs:s,deliver:e=>s.includes(e)?(i.add(e),o()):o(),reset:(e=[])=>{i.clear();for(const t of e)s.includes(t)&&i.add(t)},isSatisfied:o,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...s],deliveredEdgeIDs:[...i].sort(ot),satisfied:o()})}}function ht(e){return e instanceof Date?e.getTime():Number(e)}function mt(e,t){const n=ht("object"!=typeof t||t instanceof Date?t:t.currentTime),s=e.map((e,t)=>({event:e,index:t,time:ht(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),i=new Set,o=new Map,r=new Set,a=new Set;for(const{event:e}of s)"task-completed"===e.type?(i.add(e.taskID),o.delete(e.taskID)):"task-blocked"===e.type?o.set(e.taskID,e.reason):"task-unblocked"===e.type?o.delete(e.taskID):"dependency-delivered"===e.type?r.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:s.map(e=>e.event),completedTaskIDs:i,blockedByTaskID:o,deliveredEdgeIDs:r,armedTaskIDs:a}}function pt(e,t,n={}){const s=new Set(n.completedTaskIDs??[]),i=[...st(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(n.isComplete?n.isComplete(e):s.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),o=Array.from(new Set(i.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:i.length,affectedLaneCount:o.length,downstreamTaskIDs:i.map(e=>e.id),affectedLanes:o}}var ft=[];function gt(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function yt(e){if(null==e.completionTime)return null;const t=gt(e.completionTime,NaN);return Number.isFinite(t)?t:null}function kt(e,t,n,s){const i=new Set;for(const o of e.nodes){const r=e.incoming.get(o.id)??[];(s.has(o.id)||!n.has(o.id)&&r.every(e=>t.has(e.id)))&&i.add(o.id)}return i}function xt(e,t,n,s){const i=e.nodes.map(yt).filter(e=>null!=e),o=i.length?Math.min(...i)-1:0,r="replay"!==t||s?n:o,a=new Set,c=new Map;for(const n of e.nodes){const e=yt(n);(null!=e&&r>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const l=new Set;if("replay"!==t||s)for(const t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:r,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:kt(e,l,c,a),blockers:c,previewTaskID:null}}function bt(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function vt(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function wt(e){const t=vt(e.body);if(!t||2>t.route.length)return null;const n=function(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}(t.route),s=function(e,t){let n=1/0,s=0,i=0;for(let o=1;t.length>o;o+=1){const r=t[o-1],a=t[o],c=a.x-r.x,l=a.y-r.y,d=c*c+l*l,u=Math.sqrt(d);if(0>=u)continue;const h=Math.max(0,Math.min(1,((e.x-r.x)*c+(e.y-r.y)*l)/d)),m=Math.hypot(e.x-(r.x+c*h),e.y-(r.y+l*h));n>m&&(n=m,s=i+h*u),i+=u}return s}(e.body,t.route),i=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let s=1;e.length>s;s+=1){const i=e[s-1],o=e[s],r=o.x-i.x,a=o.y-i.y,c=Math.hypot(r,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:i.x+r*e,y:i.y+a*e},tangent:{x:r/c,y:a/c}}}n+=c}}const s=e[e.length-2],i=e[e.length-1],o=i.x-s.x,r=i.y-s.y,a=Math.hypot(o,r)||1;return{point:i,tangent:{x:o/a,y:r/a}}}(t.route,Math.min(n,s+22));return{x:2.5*(78*i.tangent.x-e.body.vx)+8*(i.point.x-e.body.x),y:2.5*(78*i.tangent.y-e.body.vy)+8*(i.point.y-e.body.y)}}function It(e,t){const n=t.points[0]??{x:0,y:0},s=t.points[1]??n,i=s.x-n.x,o=s.y-n.y,r=Math.hypot(i,o)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:i/r*42,vy:o/r*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as Dt,jsxs as Mt}from"react/jsx-runtime";function At({machine:e,layout:t,runtime:n,downstreamSet:s,selectedSet:i,width:o,height:r,seed:a,reduced:c,onSelectTask:l}){return Mt("svg",{"aria-hidden":"true",width:o,height:r,viewBox:`0 0 ${o} ${r}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Dt("defs",{children:Dt("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Dt("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const s=t.tasks.filter(e=>e.laneIndex===n),i=s[0]?.x??0;return Mt("g",{children:[Dt("line",{x1:i,x2:i,y1:32,y2:r-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Dt("text",{x:i,y:23,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),i=n.inFlight.has(e.edgeID),o=s.has(e.targetID)||s.has(e.sourceID),r=e.points.map(e=>`${e.x},${e.y}`).join(" ");return Dt("polyline",{points:r,fill:"none",stroke:o?"var(--semiotic-highlight, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:i?3:2,strokeOpacity:t||i||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return Mt("g",{children:[Dt("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-background, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&Dt("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const o=t.taskByID.get(e.id);if(!o)return null;const r=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=i.has(e.id)||u,m=s.has(e.id),p=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-muted, #75818a)"}(e,n),f=o.x-o.width/2,g=o.y-o.height/2,y=Math.max(2,o.height*e.progress);return Mt("g",{children:[Mt("g",{style:{transform:`rotate(${r?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[Dt("rect",{x:f,y:g,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-background, #fff)",stroke:h||m?"var(--semiotic-highlight, #e08a1e)":p,strokeWidth:h?4:m?3:2}),Dt("rect",{x:f+3,y:g+o.height-y+1,width:o.width-6,height:Math.max(0,y-4),rx:2,fill:p,opacity:r?.86:.46})]}),d&&Mt("g",{opacity:u?.28:1,children:[Dt("line",{x1:f-8,x2:f+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Dt("circle",{cx:f-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Mt("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Dt("rect",{x:f,y:g,width:o.width,height:o.height,fill:"transparent"}),Dt("text",{x:o.x,y:o.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),Mt("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-muted, #5f6b72)",children:[Math.round(100*e.progress),"% · ",r?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as Tt,jsxs as St}from"react/jsx-runtime";var Ct={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},$t=Ve(function(e,t){const{data:n,taskIDAccessor:s,labelAccessor:i,laneAccessor:o,dependencyAccessor:r,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:m,mode:p="snapshot",insight:f="blocker-amplification",currentTime:g,controls:k=!1,selectedTaskIDs:x,onSelectionChange:b,onObservation:v,reducedMotion:w,seed:I=31,width:D=920,height:M=620,responsiveWidth:A,responsiveHeight:T,title:S="Dependency chain reaction",description:C,className:$,accessibleTable:E=!0,enableHover:N=!0}=e,j=tt(null),[R,P]=nt([]),W=x?Array.from(x):R,B=et(()=>new Set(W),[W]),F=gt(g,1/0),L="settle"===w,q=et(()=>lt({data:n,taskIDAccessor:s,labelAccessor:i,laneAccessor:o,dependencyAccessor:r,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:m}),[n,s,i,o,r,a,c,l,d,u,h,m]),O=et(()=>dt(q,{width:D,height:M}),[q,D,M]),[z,U]=nt(()=>xt(q,p,F,L)),Z=tt(z),H=Ge(e=>{Z.current=e,U(e)},[]),X=Ge(e=>v?.(e),[v]);Qe(()=>{const e=xt(q,p,F,L);j.current?.clear(),Z.current=e,U(e)},[q,p,F,L]);const Y=Ge(e=>{const t=B.has(e)?W.filter(t=>t!==e):[e];x||P(t),b?.(t)},[x,b,B,W]),J=Ge(e=>{if(L)return;const t=bt(Z.current),n=[];for(const s of q.outgoing.get(e)??[]){if(t.delivered.has(s.id)||t.inFlight.has(s.id))continue;const e=O.routeByEdgeID.get(s.id);e&&(t.inFlight.add(s.id),n.push(It(s,e)))}n.length&&(H(t),j.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[H,O,q,L]),K=Ge((e,t)=>{const n=q.byID.get(e),s=Z.current;if(!n||s.completed.has(e))return;const i=bt(s);i.completed.add(e),i.blockers.delete(e),i.armed.add(e),null!=t&&(i.currentTime=t),H(i),X({type:"task-completed",taskID:e,datum:n.datum}),J(e)},[H,X,q,J]),V=Ge(e=>{const t=bt(Z.current),n=[],s=[];for(const s of e){if(t.delivered.has(s))continue;const e=q.edges.find(e=>e.id===s);e&&(t.delivered.add(s),t.inFlight.delete(s),n.push(e))}for(const e of n){const n=q.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(q.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),s.push(n.id))}if(n.length){H(t);for(const e of n)X({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of s)X({type:"task-armed",taskID:e})}},[H,X,q]),G=Ge((e,t)=>{const n=[],s=[];for(const e of t.readBodies()){const t=vt(e);if(!t||Z.current.delivered.has(t.edgeID))continue;const i=t.route[t.route.length-1];i&&9>=Math.hypot(e.x-i.x,e.y-i.y)&&(n.push(t.edgeID),s.push(e.id))}s.length&&t.remove(s),n.length&&V(n)},[V]),Q=Ge(()=>{const e=bt(Z.current);for(const t of q.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=kt(q,e.delivered,e.blockers,e.completed),e.playing=!1,j.current?.settle(),H(e),X({type:"machine-settled"})},[H,X,q]),_=Ge(()=>{const e=bt(Z.current);e.playing=!1,H(e)},[H]),ee=Ge(()=>{const e=Z.current,t=q.nodes.map(e=>({node:e,time:yt(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void K(t.node.id,t.time);_();const n=[...e.blockers.keys()].map(t=>pt(q,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&X({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[X,q,_,K]),te=Ge(()=>{if(L)return void Q();const e=bt(Z.current);e.playing=!0,H(e)},[H,L,Q]);Qe(()=>{if(!z.playing||"replay"!==p||L)return;const e=window.setInterval(ee,760);return()=>window.clearInterval(e)},[p,L,z.playing,ee]);const ne=Ge(()=>{j.current?.clear(),H(xt(q,p,F,L))},[H,q,p,F,L]),se=Ge(e=>{if(!q.byID.has(e))return;const t=bt(Z.current);t.previewTaskID=e,H(t);const n=pt(q,e,{completedTaskIDs:t.completed});X({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[H,X,q]),ie=Ge(()=>{const e=bt(Z.current);e.previewTaskID=null,H(e)},[H]),oe=Ge((e,t)=>{if(!q.byID.has(e))return;const n=bt(Z.current);n.blockers.set(e,t),n.armed.delete(e),H(n)},[H,q]),re=Ge(e=>{if(!q.byID.has(e))return;const t=bt(Z.current);t.blockers.delete(e),(q.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),H(t)},[H,q]),ae=Ge(e=>pt(q,e,{completedTaskIDs:Z.current.completed}),[q]),ce=Ge(()=>{const e=Z.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...W],tasks:q.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:q.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[q,W]);_e(t,()=>({play:te,pause:_,step:ee,reset:ne,settle:Q,previewResolve:se,clearPreview:ie,completeTask:K,blockTask:oe,unblockTask:re,getAmplification:ae,getMachineState:ce}),[oe,ie,ae,ce,_,K,te,se,ne,Q,ee,re]);const le=z.previewTaskID??W[0]??null,de=le?pt(q,le,{completedTaskIDs:z.completed}):null,ue=et(()=>new Set(de?.downstreamTaskIDs??[]),[de?.downstreamTaskIDs]),he=et(()=>function(e,t,n){return e.nodes.flatMap(s=>{const i=t.taskByID.get(s.id);if(!i)return[];const o=e.incoming.get(s.id)??[],r=o.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(s.id),c=n.completed.has(s.id)?"completed":a?"blocked: "+a:n.armed.has(s.id)?"armed":"waiting";return[{id:s.id,label:`${s.label}, ${s.lane}, ${Math.round(100*s.progress)}%, ${c}`,description:`${r} of ${o.length} prerequisites delivered.`,datum:s.datum,x:i.x,y:i.y,width:i.width,height:i.height,shape:"rect",group:s.lane}]})}(q,O,z),[O,q,z]),me=et(()=>Tt(At,{machine:q,layout:O,runtime:z,downstreamSet:ue,selectedSet:B,width:D,height:M,seed:I,reduced:L,onSelectTask:Y}),[ue,M,O,q,L,z,I,Y,B,D]),pe=et(()=>{const e=[...z.blockers.keys()].map(e=>pt(q,e,{completedTaskIDs:z.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${q.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[q,z.blockers,z.completed]),fe=et(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:M,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:D-2,y1:0,x2:D-2,y2:M,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:D,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:M-2,x2:D,y2:M-2,thickness:4}}],[M,D]),ge=!0===k?["play","pause","step","reset","settle"]:k||[];return St("div",q.valid?{className:$,style:{width:D,maxWidth:"100%",position:"relative"},children:[ge.length>0&&Tt("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:ge.map(e=>Tt("button",{type:"button",onClick:"play"===e?te:"pause"===e?_:"step"===e?ee:"reset"===e?ne:Q,"aria-pressed":"play"===e?z.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),Tt(y,{ref:j,size:[D,M],responsiveWidth:A,responsiveHeight:T,title:S,description:C??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${pe}${de&&"blocker-amplification"===f?` Selected task reaches ${de.downstreamTaskCount} unfinished tasks across ${de.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:N,initialSpawns:ft,bodyForces:wt,bodyStyle:{fill:"var(--semiotic-accent, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:he,onSemanticItemActivate:e=>e.id&&Y(e.id),foregroundGraphics:()=>me,paused:L,continuous:z.inFlight.size>0,onTick:G,config:{bodyLimit:Math.max(16,q.edges.length+4),colliders:fe,settleStepLimit:2200,kernel:{seed:I,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),E&&St("table",{style:Ct,children:[Tt("caption",{children:pe}),Tt("thead",{children:St("tr",{children:[Tt("th",{children:"Task"}),Tt("th",{children:"Lane"}),Tt("th",{children:"Progress"}),Tt("th",{children:"State"}),Tt("th",{children:"Waiting on"}),Tt("th",{children:"Downstream reach"})]})}),Tt("tbody",{children:q.nodes.map(e=>{const t=pt(q,e.id,{completedTaskIDs:z.completed});return St("tr",{children:[Tt("th",{scope:"row",children:e.label}),Tt("td",{children:e.lane}),St("td",{children:[Math.round(100*e.progress),"%"]}),Tt("td",{children:z.completed.has(e.id)?"Completed":z.blockers.has(e.id)?"Blocked":z.armed.has(e.id)?"Armed":"Waiting"}),Tt("td",{children:z.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!z.completed.has(e)).join(", ")||"None")}),St("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:$,role:"alert",style:{width:D,maxWidth:"100%"},children:[Tt("strong",{children:"ChainReactionChart could not compile this dependency graph."}),Tt("ul",{children:q.diagnostics.map((e,t)=>Tt("li",{children:e.message},`${e.code}-${t}`))})]})});$t.displayName="ChainReactionChart";var Et=y;export{s as BuiltInPhysicsEngineAdapter,$t as ChainReactionChart,i as CollisionSwarmChart,o as EventDropChart,r as GaltonBoardChart,a as GauntletChart,c as GuantletChart,l as PhysicalFlowChart,d as PhysicsCustomChart,u as PhysicsPileChart,h as PhysicsPipelineStore,m as PhysicsSVGOverlay,p as PhysicsSedimentAccumulator,f as ProcessFlowChart,g as StreamPhysicsFrame,k as absorbRegion,x as aggregateRegionCounts,Ke as arrivalReplay,b as bodiesToAnnotationAnchors,v as bodyGroupSpec,w as buildCollisionSwarmPhysics,I as buildEventDropPhysics,D as buildGaltonBoardPhysics,M as buildPhysicalFlowPhysics,A as buildPhysicsAnnotationContext,T as buildPhysicsPile,S as buildProcessFlowPhysics,pt as calculateBlockerAmplification,C as capacitatedRegion,$ as chargeGateRegion,He as collidersFromScales,Le as comparePhysicsTrace,lt as compileDependencyMachine,pe as compileMotionEncoding,De as compilePhysicsEncoding,j as composePhysicsControllers,le as composeStyleRules,R as createCapacityQueueController,P as createDefaultPhysicsEngineAdapter,W as createDependencyGateController,ut as createLogicalJoin,Me as createPhysicsEncodingLayout,B as createPortalController,e as createProcessJourneyLedger,F as createServiceLevelController,L as createServiceResourcePoolController,Et as default,fe as deriveMotionVector,q as evaluatePhysicsBodyBudget,O as forceFieldRegion,Xe as galtonPegs,z as groupCompletionRows,ge as hatchFillId,ye as hatchPatternDef,ke as isHatchFill,de as makeRuleValueResolver,ue as matchesThreshold,U as membraneRegion,Z as normalizePhysicsAnnotations,xe as opacityFromAge,H as physicsProcessBoundaryColliders,X as physicsProcessGroupSemanticItems,Y as physicsProcessRegionSemanticItem,J as physicsProcessStageSemanticItems,Re as physicsReferenceEnvelope,K as planGauntletPropertyWork,V as portalRegion,G as pressureFieldRegion,Q as processChrome,t as processJourneyRows,_ as processLaneWalls,ee as processStageLayout,te as processStageRegions,ne as processVolumePolygons,se as regionCountsToProjectionRows,ie as replaceGauntletNegative,mt as replayStateTransitions,be as resolveMotionAccessor,ve as resolveMotionAge,we as resolveMotionVector,he as resolveStyleRules,Ie as resolveSvgFill,dt as routeDependencyTracks,oe as routeSurfaceRegion,me as ruleMatches,Je as sedimentBake,re as sedimentHeightfield,Ye as spawnFromTokens,ae as stageTargetInVolume,n as updateProcessJourney};