semiotic 3.12.0 → 3.12.1

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 (256) hide show
  1. package/README.md +50 -46
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/behaviorContracts.cjs +1 -1
  4. package/ai/dist/diagnose-operation.js +3 -3
  5. package/ai/dist/mcp-server.js +1 -1
  6. package/ai/reference.md +15 -3
  7. package/ai/schema.json +908 -96
  8. package/ai/surface-manifest.json +1 -1
  9. package/ai/task-packets/compare-category-totals.json +5 -5
  10. package/ai/task-packets/compare-category-totals.md +2 -2
  11. package/ai/task-packets/correct-published-chart.json +5 -5
  12. package/ai/task-packets/correct-published-chart.md +2 -2
  13. package/ai/task-packets/index.json +6 -6
  14. package/ai/task-packets/update-live-chart.json +5 -5
  15. package/ai/task-packets/update-live-chart.md +2 -2
  16. package/dist/c-27DCB5T6.min.js +7 -7
  17. package/dist/c-2CKIGFD2.min.js +1 -1
  18. package/dist/c-3FATLOH4.min.js +1 -0
  19. package/dist/{c-STVM6CBI.min.js → c-4SCJKAWZ.min.js} +200 -200
  20. package/dist/c-5FUOKMH6.min.js +7 -0
  21. package/dist/c-AAIPWVQ5.min.js +6 -6
  22. package/dist/{c-2RG4WOVX.min.js → c-ALLF3Y77.min.js} +1 -1
  23. package/dist/{c-QMKQVCCZ.min.js → c-C5GXUHUO.min.js} +6 -6
  24. package/dist/c-C67QDKTU.min.js +34 -0
  25. package/dist/c-F76M77YC.min.js +1 -0
  26. package/dist/c-FEVXPKQH.min.js +1 -1
  27. package/dist/c-G42WVQO2.min.js +1 -0
  28. package/dist/c-G5A3YWTN.min.js +66 -0
  29. package/dist/c-H4HVKBU3.min.js +1 -0
  30. package/dist/c-HU3ASFKT.min.js +1 -0
  31. package/dist/c-I4FYCVJB.min.js +391 -0
  32. package/dist/{c-5L7JGWQW.min.js → c-IATPZOL7.min.js} +28 -28
  33. package/dist/c-IE5EBBP6.min.js +110 -0
  34. package/dist/c-IGONIKZL.min.js +1 -0
  35. package/dist/c-IKPM53JH.min.js +1 -0
  36. package/dist/c-IU4QZ7Y5.min.js +1 -1
  37. package/dist/{c-2ACLVPKF.min.js → c-K5VE57OI.min.js} +1 -1
  38. package/dist/c-KWJIBJ4R.min.js +1 -0
  39. package/dist/c-LIMFU6RD.min.js +1 -0
  40. package/dist/c-M4T43G76.min.js +1 -0
  41. package/dist/c-M7QUZZCE.min.js +1 -1
  42. package/dist/c-NVSINXE5.min.js +1 -0
  43. package/dist/{c-FAF6EV4E.min.js → c-NWRYV6ZF.min.js} +1 -1
  44. package/dist/c-O5GU2R5W.min.js +1 -0
  45. package/dist/c-OC7GNXGZ.min.js +1 -0
  46. package/dist/c-OV5F3DQP.min.js +1 -0
  47. package/dist/{c-5TAXHW7I.min.js → c-PJ5CAYAW.min.js} +1 -1
  48. package/dist/c-Q5LZRQGD.min.js +1 -0
  49. package/dist/c-QP3PXK3N.min.js +1 -0
  50. package/dist/c-SGZ7ZD2I.min.js +51 -0
  51. package/dist/c-SSKV5JPW.min.js +1 -1
  52. package/dist/c-THWTHWXU.min.js +37 -0
  53. package/dist/c-TRMNDRC4.min.js +41 -0
  54. package/dist/c-UP656CST.min.js +1 -1
  55. package/dist/c-USYOK5OX.min.js +1 -0
  56. package/dist/c-VI753KBO.min.js +1 -0
  57. package/dist/{c-TT4CTEBR.min.js → c-VLAAAFST.min.js} +1 -1
  58. package/dist/c-VSOQPII4.min.js +5 -5
  59. package/dist/c-WGDM4ZRP.min.js +26 -0
  60. package/dist/c-XCV7VUU3.min.js +87 -0
  61. package/dist/c-XGDZPYBI.min.js +1 -0
  62. package/dist/c-XI6CLZII.min.js +1 -0
  63. package/dist/{c-L4Q2YMXO.min.js → c-XLC7PKM7.min.js} +1 -1
  64. package/dist/{c-3YAGKCPU.min.js → c-YEB6Z35F.min.js} +1 -1
  65. package/dist/c-YWZBFG63.min.js +1 -0
  66. package/dist/c-ZMYO3NZU.min.js +2 -0
  67. package/dist/c-ZO36H5VH.min.js +48 -0
  68. package/dist/components/LinkedCharts.d.ts +6 -1
  69. package/dist/components/Tooltip/Tooltip.d.ts +11 -1
  70. package/dist/components/Tooltip/tooltipChrome.d.ts +8 -2
  71. package/dist/components/bundling/semioticVite.d.ts +24 -0
  72. package/dist/components/charts/physics/cruciblePhysics.d.ts +2 -2
  73. package/dist/components/charts/physics/gauntletPhysics.d.ts +2 -6
  74. package/dist/components/charts/physics/physicsHocUtils.d.ts +8 -1
  75. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +2 -0
  76. package/dist/components/charts/shared/chartSize.d.ts +58 -0
  77. package/dist/components/charts/shared/chartSizeDefaults.d.ts +189 -0
  78. package/dist/components/charts/shared/chartSizeDefaultsAtlas.d.ts +9 -0
  79. package/dist/components/charts/shared/chartSizeDefaultsNetwork.d.ts +29 -0
  80. package/dist/components/charts/shared/chartSizeDefaultsOrdinal.d.ts +13 -0
  81. package/dist/components/charts/shared/chartSizeDefaultsPhysics.d.ts +41 -0
  82. package/dist/components/charts/shared/chartSizeDefaultsValue.d.ts +19 -0
  83. package/dist/components/charts/shared/chartSizeDefaultsXY.d.ts +10 -0
  84. package/dist/components/charts/shared/networkPerspectiveWireSchema.d.ts +3 -0
  85. package/dist/components/charts/shared/useChartSetup.d.ts +3 -0
  86. package/dist/components/charts/shared/useCustomChartSetup.d.ts +4 -0
  87. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +2 -0
  88. package/dist/components/charts/shared/withChartWrapper.d.ts +6 -2
  89. package/dist/components/charts/value/BigNumber.d.ts +0 -8
  90. package/dist/components/charts/xy/minimapLayout.d.ts +10 -0
  91. package/dist/components/realtime/BinAccumulator.d.ts +5 -2
  92. package/dist/components/recipes/atlas/dependencyForestChartProps.d.ts +4 -4
  93. package/dist/components/recipes/atlas/flowCircuitChartProps.d.ts +177 -1
  94. package/dist/components/recipes/atlas/flowCircuitLayout.d.ts +3 -0
  95. package/dist/components/recipes/atlas/motifBraidChartProps.d.ts +2 -0
  96. package/dist/components/recipes/atlas/resolution/BoundaryLoomChart.d.ts +3 -0
  97. package/dist/components/recipes/atlas/resolution/ComponentCutaway.d.ts +16 -0
  98. package/dist/components/recipes/atlas/resolution/ResolutionAtlasChart.d.ts +3 -0
  99. package/dist/components/recipes/atlas/resolution/ResolutionGlyphs.d.ts +15 -0
  100. package/dist/components/recipes/atlas/resolution/ResolutionReader.d.ts +5 -0
  101. package/dist/components/recipes/atlas/resolution/appearance.d.ts +58 -0
  102. package/dist/components/recipes/atlas/resolution/boundaryLoomLayout.d.ts +4 -0
  103. package/dist/components/recipes/atlas/resolution/chartProps.d.ts +75 -0
  104. package/dist/components/recipes/atlas/resolution/componentCutawayLayout.d.ts +12 -0
  105. package/dist/components/recipes/atlas/resolution/cutawayContext.d.ts +23 -0
  106. package/dist/components/recipes/atlas/resolution/cutawayGraph.d.ts +4 -0
  107. package/dist/components/recipes/atlas/resolution/cycles.d.ts +7 -0
  108. package/dist/components/recipes/atlas/resolution/evidence.d.ts +43 -0
  109. package/dist/components/recipes/atlas/resolution/glyphs.d.ts +40 -0
  110. package/dist/components/recipes/atlas/resolution/identity.d.ts +4 -0
  111. package/dist/components/recipes/atlas/resolution/indexGraph.d.ts +32 -0
  112. package/dist/components/recipes/atlas/resolution/ownership.d.ts +25 -0
  113. package/dist/components/recipes/atlas/resolution/plan.d.ts +12 -0
  114. package/dist/components/recipes/atlas/resolution/ports.d.ts +44 -0
  115. package/dist/components/recipes/atlas/resolution/prepare.d.ts +4 -0
  116. package/dist/components/recipes/atlas/resolution/project.d.ts +70 -0
  117. package/dist/components/recipes/atlas/resolution/queries.d.ts +23 -0
  118. package/dist/components/recipes/atlas/resolution/resolutionAtlasLayout.d.ts +9 -0
  119. package/dist/components/recipes/atlas/resolution/rules.d.ts +14 -0
  120. package/dist/components/recipes/atlas/resolution/scene.d.ts +52 -0
  121. package/dist/components/recipes/atlas/resolution/selection.d.ts +3 -0
  122. package/dist/components/recipes/atlas/resolution/sets.d.ts +10 -0
  123. package/dist/components/recipes/atlas/resolution/types.d.ts +401 -0
  124. package/dist/components/recipes/atlas/resolution/validate.d.ts +4 -0
  125. package/dist/components/recipes/atlas/resolution/witnesses.d.ts +18 -0
  126. package/dist/components/recipes/atlas/resolution/worker.d.ts +34 -0
  127. package/dist/components/recipes/lineageDag.d.ts +4 -0
  128. package/dist/components/recipes/recipeUtils.d.ts +2 -0
  129. package/dist/components/recipes/transitDiagram.d.ts +2 -61
  130. package/dist/components/recipes/transitDiagramTypes.d.ts +65 -0
  131. package/dist/components/semiotic-ai.d.ts +2 -0
  132. package/dist/components/semiotic-experimental-network-resolution-react.d.ts +12 -0
  133. package/dist/components/semiotic-experimental-network-resolution.d.ts +13 -0
  134. package/dist/components/semiotic-geo.d.ts +1 -1
  135. package/dist/components/semiotic-network-perspective-core.d.ts +6 -0
  136. package/dist/components/semiotic-network.d.ts +1 -1
  137. package/dist/components/semiotic-ordinal.d.ts +1 -1
  138. package/dist/components/semiotic-physics.d.ts +1 -1
  139. package/dist/components/semiotic-realtime-core.d.ts +1 -1
  140. package/dist/components/semiotic-realtime-react.d.ts +2 -0
  141. package/dist/components/semiotic-utils-core.d.ts +3 -1
  142. package/dist/components/semiotic-vite.d.ts +2 -0
  143. package/dist/components/semiotic-xy.d.ts +3 -1
  144. package/dist/components/semiotic.d.ts +3 -1
  145. package/dist/components/server/renderToStaticSVG.d.ts +2 -1
  146. package/dist/components/server/serverChartConfigShared.d.ts +2 -0
  147. package/dist/components/store/LinkedCrosshairStore.d.ts +43 -11
  148. package/dist/components/store/themeCore.d.ts +2 -0
  149. package/dist/components/stream/frameKeyboardNavigation.d.ts +3 -1
  150. package/dist/components/stream/hoverUtils.d.ts +5 -0
  151. package/dist/components/stream/networkCustomLayout.d.ts +3 -0
  152. package/dist/components/stream/networkPerspective.d.ts +2 -0
  153. package/dist/components/stream/networkPerspectiveFit.d.ts +12 -1
  154. package/dist/components/stream/networkPerspectiveSolid.d.ts +1 -1
  155. package/dist/components/stream/networkSceneTypes.d.ts +4 -0
  156. package/dist/components/stream/networkTypes.d.ts +2 -0
  157. package/dist/components/stream/pipelineConfig.d.ts +2 -0
  158. package/dist/components/stream/pipelineDomainResolution.d.ts +4 -1
  159. package/dist/components/stream/types.d.ts +2 -0
  160. package/dist/components/stream/useFrame.d.ts +2 -0
  161. package/dist/components/stream/xySceneBuilders/types.d.ts +2 -0
  162. package/dist/controls.module.min.js +31 -31
  163. package/dist/geo.min.js +150 -150
  164. package/dist/geo.module.min.js +31 -31
  165. package/dist/network.module.min.js +1 -1
  166. package/dist/ordinal.module.min.js +1 -1
  167. package/dist/physics.module.min.js +1 -1
  168. package/dist/rough.module.min.js +1 -1
  169. package/dist/semiotic-ai-core.min.js +1 -1
  170. package/dist/semiotic-ai-core.module.min.js +1 -1
  171. package/dist/semiotic-ai.d.ts +2 -0
  172. package/dist/semiotic-ai.module.min.js +13 -13
  173. package/dist/semiotic-artifact-react.module.min.js +4 -4
  174. package/dist/semiotic-artifact.min.js +1 -1
  175. package/dist/semiotic-artifact.module.min.js +1 -1
  176. package/dist/semiotic-atlas-selection.module.min.js +1 -1
  177. package/dist/semiotic-atlas.module.min.js +10 -12
  178. package/dist/semiotic-client-cjs-shared.min.js +1078 -925
  179. package/dist/semiotic-client-glyph.module.min.js +2 -2
  180. package/dist/semiotic-client-shared.module.min.js +1 -1
  181. package/dist/semiotic-experimental-auxiliary.module.min.js +8 -9
  182. package/dist/semiotic-experimental-network-resolution-react.d.ts +12 -0
  183. package/dist/semiotic-experimental-network-resolution-react.min.js +2 -0
  184. package/dist/semiotic-experimental-network-resolution-react.module.min.js +89 -0
  185. package/dist/semiotic-experimental-network-resolution.d.ts +13 -0
  186. package/dist/semiotic-experimental-network-resolution.min.js +2 -0
  187. package/dist/semiotic-experimental-network-resolution.module.min.js +2 -0
  188. package/dist/semiotic-experimental-node-auxiliary.module.min.js +9 -10
  189. package/dist/semiotic-geo.d.ts +1 -1
  190. package/dist/semiotic-line.module.min.js +1 -1
  191. package/dist/semiotic-network-perspective-core.d.ts +6 -0
  192. package/dist/semiotic-network-perspective-core.min.js +1 -0
  193. package/dist/semiotic-network-perspective-core.module.min.js +1 -0
  194. package/dist/semiotic-network-perspective.module.min.js +1 -1
  195. package/dist/semiotic-network-placement.min.js +4 -0
  196. package/dist/semiotic-network-placement.module.min.js +4 -0
  197. package/dist/semiotic-network-zoom.module.min.js +1 -1
  198. package/dist/semiotic-network.d.ts +1 -1
  199. package/dist/semiotic-ordinal.d.ts +1 -1
  200. package/dist/semiotic-physics.d.ts +1 -1
  201. package/dist/semiotic-realtime-core.d.ts +1 -1
  202. package/dist/semiotic-realtime-core.module.min.js +1 -1
  203. package/dist/semiotic-realtime-react.d.ts +2 -0
  204. package/dist/semiotic-realtime-react.module.min.js +1 -1
  205. package/dist/semiotic-recipes-core-cjs-base.min.js +101 -106
  206. package/dist/semiotic-recipes-core.module.min.js +75 -76
  207. package/dist/semiotic-server-edge-node.module.min.js +391 -392
  208. package/dist/semiotic-server-edge.min.js +387 -388
  209. package/dist/semiotic-server-edge.module.min.js +371 -371
  210. package/dist/semiotic-server-node.min.js +387 -388
  211. package/dist/semiotic-server-node.module.min.js +1 -1
  212. package/dist/semiotic-utils-core.d.ts +3 -1
  213. package/dist/semiotic-utils-core.min.js +12 -11
  214. package/dist/semiotic-utils-core.module.min.js +12 -11
  215. package/dist/semiotic-value.module.min.js +4 -4
  216. package/dist/semiotic-vite.d.ts +2 -0
  217. package/dist/semiotic-vite.min.js +1 -0
  218. package/dist/semiotic-vite.module.min.js +1 -0
  219. package/dist/semiotic-xy.d.ts +3 -1
  220. package/dist/semiotic.d.ts +3 -1
  221. package/dist/semiotic.module.min.js +12 -12
  222. package/dist/server.min.js +387 -388
  223. package/dist/server.module.min.js +1 -1
  224. package/dist/xy.module.min.js +1 -1
  225. package/package.json +42 -13
  226. package/dist/c-2AB65V3L.min.js +0 -1
  227. package/dist/c-2U5JMOPN.min.js +0 -88
  228. package/dist/c-3DCTIRW4.min.js +0 -1
  229. package/dist/c-3OKFRTYM.min.js +0 -1
  230. package/dist/c-3VZHOPFW.min.js +0 -1
  231. package/dist/c-4ZSQIBC7.min.js +0 -1
  232. package/dist/c-5M4RUS7V.min.js +0 -34
  233. package/dist/c-6O5WWP7F.min.js +0 -1
  234. package/dist/c-73TOIYIW.min.js +0 -48
  235. package/dist/c-AE4M7BWH.min.js +0 -1
  236. package/dist/c-AEIK2NFW.min.js +0 -30
  237. package/dist/c-AFQSEIZ4.min.js +0 -4
  238. package/dist/c-BBX7DVVB.min.js +0 -51
  239. package/dist/c-CNYFCSG4.min.js +0 -5
  240. package/dist/c-E6QH2WYE.min.js +0 -1
  241. package/dist/c-GOMQWQJR.min.js +0 -1
  242. package/dist/c-GTYG4PDT.min.js +0 -1
  243. package/dist/c-H23GIKTK.min.js +0 -1
  244. package/dist/c-HQLUUSRJ.min.js +0 -1
  245. package/dist/c-HXUOFDSD.min.js +0 -64
  246. package/dist/c-L3LKYOLK.min.js +0 -1
  247. package/dist/c-MIKDFGKH.min.js +0 -1
  248. package/dist/c-OYSPTIAG.min.js +0 -1
  249. package/dist/c-PWPJNYQP.min.js +0 -1
  250. package/dist/c-QZ5SWKHC.min.js +0 -392
  251. package/dist/c-RXJH4IRX.min.js +0 -41
  252. package/dist/c-SN2D6QMH.min.js +0 -1
  253. package/dist/c-U5YGK6HL.min.js +0 -1
  254. package/dist/c-VIN5ASK2.min.js +0 -37
  255. package/dist/c-XZ3GASUJ.min.js +0 -1
  256. package/dist/c-ZLZZTH4I.min.js +0 -118
@@ -0,0 +1,26 @@
1
+ import{c as e}from"./c-5CI6XDJG.min.js";import{a as t}from"./c-RHDOOQ4X.min.js";function i(e){let{desired:t,minGaps:i,weights:n}=e,s=t.length;if(0===s)return[];if(i.length!==Math.max(0,s-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let r=new Array(s).fill(0);for(let e=1;e<s;e++)r[e]=r[e-1]+Math.max(0,Number.isFinite(i[e-1])?i[e-1]:0);let o=[];for(let e=0;e<s;e++){let i=Math.max(Number.EPSILON,Number.isFinite(n?.[e])?n[e]:1),s=(Number.isFinite(t[e])?t[e]:0)-r[e];for(o.push({start:e,end:e,weight:i,mean:s});o.length>1;){let e=o[o.length-1],t=o[o.length-2];if(t.mean<=e.mean)break;let i=t.weight+e.weight;o.splice(o.length-2,2,{start:t.start,end:e.end,weight:i,mean:(t.mean*t.weight+e.mean*e.weight)/i})}}let a=Number.isFinite(e.min)?e.min:-1/0,l=Number.isFinite(e.max)?e.max-r[s-1]:1/0,h=l<a?a:l,d=new Array(s);for(let e of o){let t=Math.max(a,Math.min(h,e.mean));for(let i=e.start;i<=e.end;i++)d[i]=t+r[i]}return d}function n(e,t,i){return Math.max(t,Math.min(i,e))}var s=/* @__PURE__ */new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function r(e){return"string"==typeof e?.type?e.type:""}function o(e){return!!e&&"object"==typeof e&&s.has(r(e))}var a=2e4;function l(e){return o(e)}function h(e){return"primary"===e?.emphasis||!0===e?.defensive}function d(e,t,i={}){if("number"==typeof i.maxAnnotations&&Number.isFinite(i.maxAnnotations))return Math.max(0,Math.floor(i.maxAnnotations));if(!(e>0&&t>0))return 1/0;let n=i.areaPerAnnotation&&i.areaPerAnnotation>0?i.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/n))}function u(e){let t,i=e?.emphasis;t="primary"===i?100:"secondary"===i?10:50;let s=e?.provenance?.confidence;switch("number"==typeof s&&Number.isFinite(s)&&(t+=15*n(s,0,1)),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}function c(e){let{annotations:t,width:i,height:n}=e,s=Math.max(0,e.minVisible??1),r=d(i,n,e),o=t.map((e,t)=>({annotation:e,index:t,note:l(e)})),a=o.filter(e=>e.note);if(0===a.length||a.length<=r)return{visible:t.slice(),deferred:[],budget:r};let c=a.filter(e=>h(e.annotation)),p=a.filter(e=>!h(e.annotation)).sort((e,t)=>u(t.annotation)-u(e.annotation)||e.index-t.index),f=Math.max(0,r-c.length),y=Math.max(0,s-c.length),m=Math.min(p.length,Math.max(f,y)),x=/* @__PURE__ */new Set([...c.map(e=>e.index),...p.slice(0,m).map(e=>e.index)]),g=[],v=[];for(let{annotation:e,index:t,note:i}of o)!i||x.has(t)?g.push(e):v.push(e);return{visible:g,deferred:v,budget:r}}function p(e,t){let i=t.scales?.x??t.scales?.time;return i?null!=e.x?i(e.x):t.xAccessor&&null!=e[t.xAccessor]?i(e[t.xAccessor]):null:null}function f(e,t){let i=t.scales?.y??t.scales?.value;return i?null!=e.y?i(e.y):t.yAccessor&&null!=e[t.yAccessor]?i(e[t.yAccessor]):null:null}function y(e){let t=e.data;if(!t||0===t.length)return null;let i=t[t.length-1],n=e.scales?.x??e.scales?.time,s=e.scales?.y??e.scales?.value;if(!n||!s)return null;let r=e.xAccessor||"x",o=e.yAccessor||"y",a=i[r],l=i[o];return null==a||null==l?null:{x:n(a),y:s(l)}}function m(e){return null==e?null:String(e)}function x(e){return m(e.provenance?.stableId??e.stableId)}function g(e){return m(e.stableId??e.id??e.provenance?.stableId)}function v(e,t,i){return t.stickyPositionCache?.set(e,i),i}function b(e,t,i){let n=x(e);if(!n)return null;let s=i.pointNodes?.find(e=>m(e.pointId)===n);if(s)return v(t,i,{x:s.x,y:s.y});let r=i.data?.find(e=>g(e)===n);if(!r)return null;let o=p(r,i),a=f(r,i);return null==o||null==a?null:v(t,i,{x:o,y:a})}function w(e,t,i){let n=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===n){if(null!=e.pointId&&i.pointNodes&&i.pointNodes.length>0)for(let n=i.pointNodes.length-1;n>=0;n--){let s=i.pointNodes[n];if(s.pointId===e.pointId)return v(t,i,{x:s.x,y:s.y})}let n=y(i);return n?v(t,i,n):null}if("semantic"===n){let n=b(e,t,i);if(n)return n}let s=null,r=null;if(null!=e.pointId&&i.pointNodes){let t=i.pointNodes.find(t=>t.pointId===e.pointId);t&&(s=t.x,r=t.y)}if((null==s||null==r)&&(s=p(e,i),r=f(e,i)),null!=s&&null!=r)return v(t,i,{x:s,y:r});if("sticky"===n){let e=i.stickyPositionCache?.get(t);if(e)return e}return null}function S(e,t,i,n=50){let s=i.width||0,r=i.height||0;return e>=-n&&e<=s+n&&t>=-n&&t<=r+n}function M(e){return{label:e.label,title:e.title,wrap:e.wrap||120,noWrap:"function"==typeof e._noteLayout?e.noWrap:void 0,_noteLayout:e._noteLayout}}function I(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}function k(e,t,i){if(!e)return[];let n=Math.max(1,Math.floor(t/i)),s=[],r="";for(let t of e.split(/\s+/))t&&(r&&r.length+1+t.length>n?(s.push(r),r=t):r=r?`${r} ${t}`:t);return r&&s.push(r),s}var B=32,O=6,A=4,$=8,T=72;function C(e){return"number"==typeof e.dx||"number"==typeof e.dy}function N(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}function P(e){let t=e?.familiarity;if(!t)return 3;let i=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===i.length?3:i.reduce((e,t)=>e+t,0)/i.length}function q(e){if(!e)return 1;let t=P(e);return t<=2?1.5:t>=4?.6:1}var F={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function D(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let i="string"==typeof t.source?Object.prototype.hasOwnProperty.call(F,t.source)?F[t.source]:t.source:null,n="number"==typeof t.confidence&&Number.isFinite(t.confidence)?`${Math.round(100*Math.max(0,Math.min(1,t.confidence)))}%`:null;if(!i&&!n||null!=e.label&&"string"!=typeof e.label)return e;let s=[i,n].filter(Boolean).join(" · "),r="string"==typeof e.label?e.label:"";return r.includes(`(${s})`)?e:{...e,label:r?`${r} (${s})`:`(${s})`}}function Y(e,t){let i=!1,n=e.map(e=>R(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(i=!0,{...e,cohesion:t}):e);return i?n:e}function E(e){if(!R(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,i="string"==typeof e.shortText?e.shortText:void 0,n=t??i;return!n||"string"!=typeof e.label&&null!=e.label?e:{...e,label:n}}function L(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,i="number"==typeof e.dy?e.dy:0;return Math.hypot(t,i)<8?e:{...e,_redundantConnector:!0}}function R(e){return o(e)}function X(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=I(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let i="number"==typeof e.wrap?e.wrap:120,n=[...k("string"==typeof e.title?e.title:void 0,i,7),...k("string"==typeof e.label?e.label:void 0,i,7)],s=n.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(i,7*s)+10),height:Math.max(18,16*n.length+6)}}function j(e,t,i,n,s){let r=e+i,o=t+n;return Math.abs(i)>Math.abs(n)?{x:i>=0?r+4:r-s.width-4,y:n<0?o-s.height:o,width:s.width,height:s.height}:{x:i>=0?r:r-s.width,y:n<0?o-s.height-4:o+4,width:s.width,height:s.height}}function W(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function z(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 G(e,t,i,n){let s=Math.max(0,n-e.x),r=Math.max(0,n-e.y),o=Math.max(0,e.x+e.width-(t-n)),a=Math.max(0,e.y+e.height-(i-n));return(s+o)*e.height+(r+a)*e.width}function V(e){let 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}]}function _(e,t){return(e.pointNodes||[]).map(e=>{let i=Math.max(1,e.r||1)+t;return{x:e.x-i,y:e.y-i,width:2*i,height:2*i}})}function H(e,t,i,n,s,r,o,a){let l=W(e,o),h=.4*Math.hypot(t.dx,t.dy)+80*G(l,s,r,a);for(let e of i)h+=12*z(l,e);for(let e of n)h+=4*z(l,e);return h}function U(e,t,i){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};let n=e.pointId??e.nodeId;if(null!=n&&i.pointNodes){let e=i.pointNodes.find(e=>e.pointId===n);if(e)return{x:e.x,y:e.y}}let s=e.coordinates,r=i.scales?.geoProjection;if(Array.isArray(s)&&s.length>=2&&r){let e=s[0],t=s[1];if("number"==typeof e&&"number"==typeof t){let i=r([e,t]);if(i&&"number"==typeof i[0]&&"number"==typeof i[1])return{x:i[0],y:i[1]}}}return i.scales||"number"!=typeof e.x||"number"!=typeof e.y?w(e,t,i):{x:e.x,y:e.y}}function K(e){let{annotations:t,context:i,defaultOffset:n=B,notePadding:s=O,markPadding:r=A,edgePadding:o=$,preserveManualOffsets:a=!0,routeLongConnectors:l=!0,connectorThreshold:h=T,density:u,progressiveDisclosure:p=!1,redundantCues:f=!1,responsive:y,mobile:m,cohesion:x,audience:g}=e,v=i.width||0,b=i.height||0,w="object"==typeof m?m:{},S=w.breakpoint??480,M=!!m&&v<=S,I=M&&!1!==w.preferShortText?t.map(E):t,k=M&&!u?{maxAnnotations:w.maxAnnotations??("callout-list"===w.strategy?1:2),minVisible:w.minVisible??1}:u,P=p||M&&(!1!==w.progressiveDisclosure||"callout-list"===w.strategy),F=M&&!y?w.responsive??{minWidth:S}:y,z=M&&!x?w.cohesion:x;if(0===I.length||v<=0||b<=0)return I.slice();let G=[],K=_(i,r),Q=!1,Z=I.map((e,t)=>{if(!R(e))return e;let r=U(e,t,i);if(!r)return e;let d=X(!0===e.defensive?D(e):e);if(a&&C(e)){let t=N(e),i="number"==typeof e.dx?e.dx:t.dx,n="number"==typeof e.dy?e.dy:t.dy;return G.push(W(j(r.x,r.y,i,n,d),s)),e}let u=null,c=1/0;for(let e of V(n)){let t=H(j(r.x,r.y,e.dx,e.dy,d),e,G,K,v,b,s,o);t<c&&(u=e,c=t)}if(!u)return e;let p=W(j(r.x,r.y,u.dx,u.dy,d),s);G.push(p);let f=Math.hypot(u.dx,u.dy),y=l&&f>=h&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return Q=!0,{...e,dx:u.dx,dy:u.dy,...y?{connector:y}:{}}}),J=Q?Z:I.slice(),ee=J;if(f){let e=!1,t=J.map(t=>{let i=L(t);return i!==t&&(e=!0),i});ee=e?t:J}{let e=!1,t=ee.map(t=>{if(!0!==t?.defensive)return t;let i=D(t);return i!==t&&(e=!0),i});ee=e?t:ee}let te,ie=/* @__PURE__ */new Set;if(k){let e="object"==typeof k?k:{},t=q(g),i=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??d(v,b,e))*t))},{deferred:n}=c({annotations:ee,width:v,height:b,...i});for(let e of n)ie.add(e)}if(F){let e="object"==typeof F&&"number"==typeof F.minWidth?F.minWidth:480;if(v<=e)for(let e of ee)R(e)&&"secondary"===e.emphasis&&ie.add(e)}if(ie.size>0)for(let e of ee)!0===e?.defensive&&ie.delete(e);return te=0===ie.size?ee:P?ee.map(e=>ie.has(e)?{...e,_annotationDeferred:!0}:e):ee.filter(e=>!ie.has(e)),z?Y(te,z):te}import{interpolateRgb as Q}from"d3-interpolate";var Z=864e5,J=e=>{let t=e.config,{plot:i}=e.dimensions;if(i.width<=0||i.height<=0)return{nodes:[]};let n=e=>{let i="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];return i instanceof Date?i:new Date(i)},s=e=>{let i="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return Number(i)},r=/* @__PURE__ */new Map,o=null;for(let t of e.data){let e=n(t);if(!isFinite(e.getTime()))continue;null==o&&(o=e.getUTCFullYear());let i=ee(e),a=s(t);r.set(i,(r.get(i)??0)+(Number.isFinite(a)?a:0))}let a=t.year??o??/* @__PURE__ */(new Date).getUTCFullYear(),l=1/0,h=-1/0;for(let e of r.values())e<l&&(l=e),e>h&&(h=e);l===1/0&&(l=0,h=0);let[d,u]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],c=e=>{if(h===l)return d;let t=(e-l)/(h-l);return Q(d,u)(t)},p=t.gutter??2,f=t.labelInset??0,y=i.width-f,m=i.height,x=Math.min((y-53*p)/54,(m-6*p)/7);if(x<=0)return{nodes:[]};let g=new Date(Date.UTC(a,0,1)),v=g.getUTCDay(),b=new Date(g.getTime()-v*Z),w=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let n=new Date(b.getTime()+(7*e+t)*Z);if(n.getUTCFullYear()!==a)continue;let s=ee(n),o=r.get(s),l=null==o?d:c(o);w.push({type:"rect",x:i.x+f+e*(x+p),y:i.y+t*(x+p),w:x,h:x,style:{fill:l,stroke:"none"},datum:{date:n,value:o??0}})}return{nodes:w}};function ee(e){return`${e.getUTCFullYear()}-${te(e.getUTCMonth()+1)}-${te(e.getUTCDate())}`}function te(e){return e<10?`0${e}`:String(e)}import{interpolateLab as ie}from"d3-interpolate";function ne(e){return"function"==typeof e?e:t=>t[e]}function se(e,t,i){let n=e?.data,s=n?n[t]:void 0;if(null!=s)return s;let r=e?.[t];return r??i}function re(e){if(null==e)return null;let t=e;return t.data??t.datum??e}function oe(e,t){let i=/* @__PURE__ */new Map;for(let n of e){let e=t(n),s=i.get(e);s?s.push(n):i.set(e,[n])}return i}function ae(e){let t=/* @__PURE__ */Object.create(null);return e((e,i)=>{t[e]=i}),t}function le(e,t){if(!t)return!0;let i=Array.isArray(t)?t:[t],n=e;for(let e of i)if(null!=e.value&&String(n[e.field])!==String(e.value))return!1;return!0}function he(e,t={}){let i=t.baseOpacity??1;return t.highlight||t.predicate?!le(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,i+(t.brighten??0)):i}function de(e){return e.join("|")}var ue=class{constructor(e=12){this.maxSize=e,this.store=/* @__PURE__ */new Map}get(e){return this.store.get(e)}set(e,t){this.store.size>=this.maxSize&&this.store.clear(),this.store.set(e,t)}getOrCompute(e,t){let i=this.store.get(e);if(void 0!==i)return i;let n=t();return this.set(e,n),n}clear(){this.store.clear()}get size(){return this.store.size}};function ce(e,t=.72){let i=ie(e,"#ffffff"),n=ie(e,"#000000"),s=ie(e,e)(0);return e=>{let r=e<0?0:e>1?1:e;return.5===r?s:r<.5?i(2*(.5-r)*t):n(2*(r-.5)*t)}}function pe(e,t,i=.72){return ce(e,i)(t)}function fe(e){return ae(t=>{for(let[i,n]of Object.entries(e))t(i,n)})}function ye(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"item"}function me(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):0}function xe(e){if(0===e.length)return 0;let t=0;for(let i of e)t+=i;return t/e.length}function ge(e,t){let i=n(t,0,1),s=e.trim().replace(/^#/,""),r=3===s.length?s.split("").map(e=>e+e).join(""):s;return/^[0-9a-fA-F]{6}$/.test(r)?`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${i})`:e}function ve(e,t){return e<t?-1:e>t?1:0}import{jsx as be,jsxs as we}from"react/jsx-runtime";function Se(e){/* */
2
+ return be("rect",{className:e.className,x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height),rx:e.radius??10,ry:e.radius??10,fill:e.fill??"none",stroke:e.stroke,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray,opacity:e.opacity??.6,style:{pointerEvents:"none"}},e.keyId)}function Me(e,t=0){let i=1/0,n=1/0,s=-1/0,r=-1/0;for(let t of e){let e=t.r??0;t.x-e<i&&(i=t.x-e),t.x+e>s&&(s=t.x+e),t.y-e<n&&(n=t.y-e),t.y+e>r&&(r=t.y+e)}return Number.isFinite(i)?{x:i-t,y:n-t,width:s-i+2*t,height:r-n+2*t}:null}function Ie(e,t=0){if(!e.length)return null;let i="number"==typeof t?t:t.x??0,n="number"==typeof t?t:t.y??0,s=1/0,r=1/0,o=-1/0,a=-1/0;for(let t of e){if(!(Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)))continue;let e=Math.max(0,t.width),i=Math.max(0,t.height);t.x<s&&(s=t.x),t.y<r&&(r=t.y),t.x+e>o&&(o=t.x+e),t.y+i>a&&(a=t.y+i)}return Number.isFinite(s)?{x:s-i,y:r-n,width:o-s+2*i,height:a-r+2*n}:null}function ke(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:/* @__PURE__ */be("text",{className:e.className,x:e.x,y:e.y,textAnchor:e.anchor??"middle",dominantBaseline:e.baseline??"middle",fontSize:t,fontWeight:e.fontWeight,fill:e.color,style:{pointerEvents:"none"},children:e.text},e.keyId)}function Be(e){let t=e.spacing??8,i=e.color??"currentColor";return{def:/* @__PURE__ */be("pattern",{id:e.id,width:t,height:t,patternUnits:"userSpaceOnUse",patternTransform:`rotate(${e.angle??45})`,children:/* @__PURE__ */be("line",{x1:0,y1:0,x2:0,y2:t,stroke:i,strokeWidth:e.strokeWidth??1,opacity:e.opacity??.5})},e.id),fill:`url(#${e.id})`}}function Oe(e){let t=e.orient??"bottom",i="bottom"===t||"top"===t,n=e.offset??0,s=e.tickLength??6,r=e.gridLength??0,o=e.labelGap??4,a=e.fontSize??11,l=e.color??"var(--semiotic-text-secondary, #888)",h=e.gridColor??l,d=e.format??(e=>String(e)),u="top"===t||"left"===t?-1:1,c=e.ticks.length-1,p=e.ticks.map((p,f)=>{let y,m=e.scale(p),x=n+u*s,g=n-u*r,v=x+u*o;y=e.labelAnchor?e.labelAnchor:i?e.edgeAnchor&&0===f?"start":e.edgeAnchor&&f===c?"end":"middle":"left"===t?"end":"start";let b=i?"top"===t?"auto":"hanging":"middle",w=i?{x:m,y:v}:{x:v,y:m};/* */
3
+ return we("g",{children:[(s>0||r>0)&&/* @__PURE__ */be("line",{...i?{x1:m,x2:m,y1:x,y2:g}:{x1:x,x2:g,y1:m,y2:m},stroke:r>0?h:l,strokeWidth:1,strokeDasharray:r>0?e.gridDasharray:void 0,opacity:r>0?.7:1}),
4
+ /* @__PURE__ */be("text",{x:w.x,y:w.y,textAnchor:y,dominantBaseline:b,fontSize:a,fontWeight:e.fontWeight,fill:l,children:d(p)})]},`tick-${p}-${f}`)});/* */
5
+ return be("g",{className:e.className,style:{pointerEvents:"none"},children:p},e.keyId)}function Ae(e){let t,i=e.stroke??"var(--semiotic-text, #f4f4f8)",n=e.strokeWidth??1,s=e.markRadius??0,r=e.labelX-e.markX,o=e.labelY-e.markY,a=Math.hypot(r,o)||1,l=e.markX+r/a*s,h=e.markY+o/a*s;return t="elbow"===e.connector?`M${l},${h} L${l},${e.labelY} L${e.labelX},${e.labelY}`:"curve"===e.connector?`M${l},${h} Q${(l+e.labelX)/2},${h} ${e.labelX},${e.labelY}`:`M${l},${h} L${e.labelX},${e.labelY}`,/* @__PURE__ */we("g",{className:e.className,style:{pointerEvents:"none"},children:[s>0&&/* @__PURE__ */be("circle",{cx:e.markX,cy:e.markY,r:s,fill:"none",stroke:i,strokeWidth:n}),
6
+ /* @__PURE__ */be("path",{d:t,fill:"none",stroke:i,strokeWidth:n}),
7
+ /* @__PURE__ */be("text",{x:e.labelX,y:e.labelY,textAnchor:e.labelAnchor??"middle",dominantBaseline:e.labelBaseline??"hanging",fontSize:e.fontSize??11,fontWeight:e.fontWeight,fill:e.color??i,children:e.label})]},e.keyId)}import*as $e from"react";import{scaleLinear as Te}from"d3-scale";var Ce=e=>{let t=e.config,{plot:i}=e.dimensions,n=t.fields??[];if(n.length<2||i.width<=0||i.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let s=/* @__PURE__ */Object.create(null);for(let i of n){let n=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,i)?t.domains[i]:void 0;if(Array.isArray(n)&&n.length>=2&&"number"==typeof n[0]&&Number.isFinite(n[0])&&"number"==typeof n[1]&&Number.isFinite(n[1])){s[i]=[n[0],n[1]];continue}let r=1/0,o=-1/0;for(let t of e.data){let e=Number(t[i]);Number.isFinite(e)&&(e<r&&(r=e),e>o&&(o=e))}if(Number.isFinite(r)&&Number.isFinite(o))if(r===o){let e=Math.max(.01*Math.abs(r),.5);s[i]=[r-e,o+e]}else s[i]=[r,o];else s[i]=[0,1]}let r=!1!==t.showAxes,o=r?t.axisLabelPadding??24:8,a=r?18:8,l=n.map(e=>Te().domain(s[e]).range([i.y+i.height-a,i.y+o])),h=n.map((e,t)=>1===n.length?i.x+i.width/2:i.x+t/(n.length-1)*i.width),d=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,u=t.opacity??.45,c=t.strokeWidth??1.25,p=e.theme.semantic.primary??"#3b6cb1",f=t.dimmedOpacity??.08,y=t.highlightFn,m=[],x=[];for(let i of e.data){let s=d?e.resolveColor(String(d(i))):p,r=!y||y(i),o=he(i,{predicate:y,baseOpacity:u,dimOpacity:f,brighten:.4}),a=r?x:m;for(let e=0;e<n.length-1;e++){let t=Number(i[n[e]]),d=Number(i[n[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(d))continue;let u={type:"connector",x1:h[e],y1:l[e](t),x2:h[e+1],y2:l[e+1](d),style:{stroke:s,strokeWidth:y&&r?c+.75:c,opacity:o,fill:"none"},datum:i};a.push(u)}if(t.showPoints)for(let e=0;e<n.length;e++){let t=Number(i[n[e]]);if(!Number.isFinite(t))continue;let r={type:"point",x:h[e],y:l[e](t),r:2.5,style:{fill:s,stroke:"none",opacity:Math.min(1,o+.3)},datum:i};a.push(r)}}let g=null;if(r){let r=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,d=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,u=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,c=i.y+o,p=i.y+i.height-a,f=[];for(let e=0;e<n.length;e++){let a=n[e],y=h[e],m=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,a)?t.tickFormat[a]:void 0,x="function"==typeof m?m:e=>e.toLocaleString();f.push($e.createElement("line",{key:`pc-axis-line-${e}`,x1:y,x2:y,y1:c,y2:p,stroke:r,strokeWidth:1})),f.push(ke({keyId:`pc-axis-label-${e}`,text:a,x:y,y:i.y+o-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:d}));let[g,v]=s[a],b=5;for(let t=0;t<b;t++){let i=g+(v-g)*t/(b-1),n=l[e](i);f.push($e.createElement("line",{key:`pc-tick-${e}-${t}`,x1:y-3,x2:y+3,y1:n,y2:n,stroke:r,strokeWidth:1}),ke({keyId:`pc-ticktext-${e}-${t}`,text:x(i),x:y+6,y:n+3,anchor:"start",baseline:"auto",fontSize:10,color:u}))}}g=$e.createElement($e.Fragment,null,...f)}return{nodes:m.concat(x),overlays:g}};function Ne(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function Pe(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&(null==t.label||"string"==typeof t.label)&&"number"==typeof t.count&&Number.isFinite(t.count)&&Array.isArray(t.bodyIds)&&t.bodyIds.every(e=>"string"==typeof e)}function qe(e,t){if("region-enter"!==t.type)return e;let i=t.region.id,n=Ne(e,i),s=Pe(n)?n:{id:i,label:t.region.label??i,count:0,bodyIds:[]};if(s.bodyIds.includes(t.bodyId))return e;let r=[...s.bodyIds,t.bodyId];return{...e,[i]:{...s,count:r.length,bodyIds:r}}}function Fe(e,t){return(t??Object.keys(e)).map(t=>Ne(e,t)).filter(Pe).map(e=>({label:e.label??e.id,value:e.count}))}function De(e,t){let i=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],n=t.filter(e=>!i.has(e)),s=t.length-n.length,r=e.completion?.mode??"allMembersAbsorbed",o=e.completion?.valueByBodyId,a=e=>{let t=o?Ne(o,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},l=t.reduce((e,t)=>e+a(t),0),h=t.reduce((e,t)=>e+(i.has(t)?a(t):0),0),d=e.completion?.threshold,u="threshold"===r?Number.isFinite(d)&&Number(d)>=0?Number(d):l:void 0,c=t.length>0&&("anyAbsorbed"===r?s>0:"threshold"===r?h>=(u??l):0===n.length);return{id:e.id,label:e.label??e.id,mode:r,complete:c,absorbed:s,total:t.length,absorbedValue:h,totalValue:l,threshold:u,missing:n}})}function Ye(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}function Ee(e,t,i,n,s,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:i,x2:n,y2:s,thickness:r.thickness??8}}}function Le(e,t,i,n){return{type:"aabb",x:e,y:t,width:i,height:n}}function Re(e){let t=e.shape??"lane",i=Math.max(1,Math.round(e.width)),s=Math.max(1,Math.round(e.height)),r=e.padX??46,o=e.padY??72,a=r,l=i-r,h=o,d=s-Math.max(24,Math.round(.45*o)),u=(h+d)/2,c=Math.max(1,d-h),p=n(e.pinchRatio??.18,.06,.5),f=Number(e.pinchHeightOffset??0),y=Number.isFinite(f)?f:0,m=n(c*p+y,.06*c,.5*c),x=m/2,g=u-x,v=u+x,b=e.idPrefix??"process",w=e.friction??.58,S=e.restitution??.18,M=e.wallThickness??8,I=e.stages;if(!I.length)throw new Error("processStageLayout requires at least one stage");let k=n(e.centerStageIndex??Math.floor(I.length/2),0,I.length-1),B=Ye(I),O=l-a,A=a,$=I.map((e,t)=>{let i=(e.share??1)/B*O,n=A,s=t===I.length-1?l:A+i;return A=s,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:s,x:(n+s)/2,width:s-n,y:u,height:c}}),T=$[k],C=T.x0,N=T.x1,P=(e,i)=>{if("lane"===t)return"top"===i?h:d;if("funnel"===t){let t=n((e-a)/Math.max(1,l-a),0,1);return"top"===i?h+(g-h)*t:d+(v-d)*t}if(e<=C){let t=n((e-a)/Math.max(1,C-a),0,1);return"top"===i?h+(g-h)*t:d+(v-d)*t}if(e<=N)return"top"===i?g:v;let s=n((e-N)/Math.max(1,l-N),0,1);return"top"===i?g+(h-g)*s:v+(d-v)*s},q=$.map(e=>{let t=Math.min(P(e.x0,"top"),P(e.x1,"top")),i=Math.max(P(e.x0,"bottom"),P(e.x1,"bottom"));return{...e,y:(t+i)/2,height:Math.max(1,i-t)}}),F={thickness:M,friction:w,restitution:S},D=[];"lane"===t?D.push(Ee(`${b}-top`,a,h,l,h,F),Ee(`${b}-bottom`,a,d,l,d,F),Ee(`${b}-left`,a,h,a,d,{...F,thickness:Math.max(6,M-2)}),Ee(`${b}-right`,l,h,l,d,{...F,thickness:Math.max(6,M)})):"funnel"===t?D.push(Ee(`${b}-top`,a,h,l,g,F),Ee(`${b}-bottom`,a,d,l,v,F),Ee(`${b}-left`,a,h,a,d,{...F,thickness:Math.max(6,M-2)}),Ee(`${b}-right`,l,g,l,v,{...F,thickness:Math.max(6,M)})):D.push(Ee(`${b}-left-top`,a,h,C,g,F),Ee(`${b}-left-bottom`,a,d,C,v,F),Ee(`${b}-center-top`,C,g,N,g,F),Ee(`${b}-center-bottom`,C,v,N,v,F),Ee(`${b}-right-top`,N,g,l,h,F),Ee(`${b}-right-bottom`,N,v,l,d,F),Ee(`${b}-left`,a,h,a,d,{...F,thickness:Math.max(6,M-2)}),Ee(`${b}-right`,l,h,l,d,{...F,thickness:Math.max(6,M)}));let Y=e.membraneDampingScale??.5,E=a,L=Math.max(1,("bowtie"===t?C:l)-E),R=(e.membranes??[]).map(e=>{let t=E+n(e.offset,0,1)*L,i=e.width??18+18*e.cost,s=c-16,r=u+.25*(e.wobble??0);return{...e,x:t,y:r,width:i,height:s}}),X=!1===e.includeMembraneRegions?[]:R.map(e=>ze({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??Y,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:i,height:s,padX:r,padY:o,left:a,right:l,topY:h,bottomY:d,midY:u,centerLeft:C,centerRight:N,pinchHeight:m,pinchTop:g,pinchBottom:v,stages:q,membranes:R,colliders:D,regionEffects:X,boundaryY:P}}function Xe(e,t,i){return"function"==typeof t?n=>({...i,...t(n),primitive:e}):{...i,...t,primitive:e}}function je(e,t,i,n){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:Le(e.x,e.y,e.width,e.height),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:i?Xe(i,e.attributes,n):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function We(e,t={}){let i=t.idPrefix??"stage",n=Math.max(0,t.insetX??0),s=Math.max(0,t.insetY??1);return e.stages.map(e=>{let r="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...je({id:i?`${i}:${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*n),height:Math.max(1,e.height-2*s),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 ze(e){let t=e.dampingScale??.5,i=e.energyScale??1,s=n(e.cost,0,2);return{...je(e,"membrane","membrane",{membraneCost:s}),damping:s*t,energyDelta:-s*i}}function Ge(e){return{...je(e,"charge-gate","chargeGate"),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function Ve(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...je(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function _e(e){let t=e.pressure??e.occupancy??0,i=e.baseDamping??.08,n=e.dampingPerUnit??.12,s=e.energyPerUnit??0;return{...je(e,"membrane","pressureField",{pressure:t}),damping:i+t*n,energyDelta:s?-t*s:void 0,force:e.force}}function He(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...je(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function Ue(e){return{...je(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function Ke(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...je(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function Qe(e){return{...je(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function Ze(e){let t=e.x??e.anchor?.x??0,i=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:i,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:i},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function Je(e){let t=e.idPrefix??"lane",i={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},n=[Ee(`${t}-top`,e.left,e.top,e.right,e.top,i),Ee(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,i)];return e.openEnds||n.push(Ee(`${t}-left`,e.left,e.top,e.left,e.bottom,i),Ee(`${t}-right`,e.right,e.top,e.right,e.bottom,i)),n}import{Fragment as et,jsx as tt,jsxs as it}from"react/jsx-runtime";var nt={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 st(e){return 6.2*e.length}function rt(e,t){let i=e.trim();if(i.length<=t)return i;if(t<=1)return i.slice(0,1);let n=i.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return n.length>1&&n.length<=t?n:t<=3?i.slice(0,t).toUpperCase():`${i.slice(0,Math.max(1,t-2))}..`}function ot(e,t,i="auto"){let n=Math.max(1,Math.floor(t/6.2)),s="compact"===i?rt(e,n):"full"===i||st(e)<=t?e:rt(e,n);return{text:s,textLength:st(s)>t?Math.max(4,t):void 0}}function at(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}function lt(e){if(null!=e.capacity){let t=null!=e.queueDepth?` · q ${e.queueDepth}`:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?String(e.capacity):e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}function ht(e,t={}){let{showFlowSpine:i=!0,showStageCounts:s=!0,showCapacityBadges:r=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:l=!1,testId:h="process-flow-chrome"}=t,{width:d,height:u,left:c,right:p,topY:f,bottomY:y,midY:m,stages:x,groups:g=[]}=e,v=y-f;/* */
8
+ return it("svg",{"aria-hidden":"true","data-testid":h,"data-outline-stages":l?"true":void 0,width:d,height:u,viewBox:`0 0 ${d} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",l?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[
9
+ /* @__PURE__ */tt("defs",{children:/* @__PURE__ */it("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[
10
+ /* @__PURE__ */tt("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),
11
+ /* @__PURE__ */tt("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),
12
+ /* @__PURE__ */tt("rect",{x:0,y:0,width:d,height:u,fill:"url(#semiotic-process-floor)"}),
13
+ /* @__PURE__ */tt("rect",{x:c-6,y:f-8,width:p-c+12,height:v+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}),i?/* @__PURE__ */tt("line",{x1:c+8,x2:p-8,y1:m,y2:m,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,x.map((e,t)=>{let i=at(e),o=nt[i],h=Math.max(12,e.width-8),d=n(h-8,22,88),c=Math.max(8,d-10),p=ot(e.label,c,a),g="none"!==a&&h-8>=22,b=lt(e),w=ot(b,Math.max(16,h-10),"auto"),S=r&&!1!==e.showBadge&&h>=32,M=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",I=ot(M,Math.max(16,h-8),"auto"),k=Math.max(30,f-15),B=k-13;/* */
14
+ return it("g",{"data-stage":e.id,"data-role":i,children:[
15
+ /* @__PURE__ */tt("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:f+6,width:h,height:v-12,rx:10,fill:l?"none":o.fill,stroke:o.stroke,strokeWidth:l?1.85:"flow"===i?1:1.6}),t<x.length-1?/* @__PURE__ */tt("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:o.accent,opacity:.85}):null,g?/* @__PURE__ */it(et,{children:[
16
+ /* @__PURE__ */tt("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-d/2,y:B,width:d,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),
17
+ /* @__PURE__ */it("text",{x:e.x,y:k,textAnchor:"middle",fill:o.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:p.textLength,lengthAdjust:p.textLength?"spacingAndGlyphs":void 0,children:[
18
+ /* @__PURE__ */tt("title",{children:e.label}),p.text]})]}):null,S?/* @__PURE__ */it("text",{x:e.x,y:f+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:w.textLength,lengthAdjust:w.textLength?"spacingAndGlyphs":void 0,children:[
19
+ /* @__PURE__ */tt("title",{children:b}),w.text]}):null,s&&null!=e.count?/* @__PURE__ */it("text",{x:e.x,y:Math.min(u-8,y+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:I.textLength,lengthAdjust:I.textLength?"spacingAndGlyphs":void 0,children:[
20
+ /* @__PURE__ */tt("title",{children:M}),I.text]}):null]},e.id)}),o?g.map((e,t)=>{let i=e.total??0,s=e.absorbed??0,r=e.complete??(i>0&&s>=i),o=!r&&i>0&&s/i>=.75,a=r?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",l=r?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",h=i>0?`${s}/${i}${r?" shipped":o?" almost":""}`:`feature ${t+1}`,d=n(Math.max(54,st(e.label)+18,st(h)+16),54,104),u=ot(e.label,d-12,"auto"),c=ot(h,d-12,"auto");/* */
21
+ return it("g",{"data-group":e.id,children:[
22
+ /* @__PURE__ */tt("rect",{x:e.x-d/2,y:e.y-22,width:d,height:44,rx:10,fill:a,stroke:l,strokeWidth:1.5}),
23
+ /* @__PURE__ */it("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[
24
+ /* @__PURE__ */tt("title",{children:e.label}),u.text]}),
25
+ /* @__PURE__ */it("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:l,fontSize:9,fontWeight:700,textLength:c.textLength,lengthAdjust:c.textLength?"spacingAndGlyphs":void 0,children:[
26
+ /* @__PURE__ */tt("title",{children:h}),c.text]})]},e.id)}):null]})}var dt=e=>"number"==typeof e&&Number.isFinite(e);function ut(e,t){let i="function"==typeof t?t(e):e[t];return dt(i)?i:void 0}function ct(e){return[...e].sort((e,t)=>ve(e,t))}function pt(e,t){let i=new Map(e.map(e=>[e,/* @__PURE__ */new Set]));for(let e of t)!i.has(e.source)||!i.has(e.target)||(i.get(e.source)?.add(e.target),i.get(e.target)?.add(e.source));return i}function ft(e){let t=new Set(e.keys()),i=[];for(let n of ct(t)){if(!t.has(n))continue;let s=[n],r=[];t.delete(n);for(let i=0;i<s.length;i++){let n=s[i];r.push(n);for(let i of ct(e.get(n)??[]))t.has(i)&&(t.delete(i),s.push(i))}i.push(r.sort((e,t)=>ve(e,t)))}return i.sort((e,t)=>t.length-e.length||ve(e[0],t[0]))}function yt(e,t,i){let n=/* @__PURE__ */new Map([[e,0]]),s=[e];for(let e=0;e<s.length;e++){let r=s[e],o=n.get(r);for(let e of ct(i.get(r)??[]))!t.has(e)||n.has(e)||(n.set(e,o+1),s.push(e))}return n}function mt(e,t,i){let n=yt(e,t,i),s=e,r=-1;for(let[e,t]of n)(t>r||t===r&&ve(e,s)<0)&&(s=e,r=t);return s}function xt(e,t,i){let n=new Set(e),s=e.filter(e=>(t.get(e)?.size??0)<=1)[0]??e[0],r=yt(i&&n.has(i)?i:mt(mt(s,n,t),n,t),n,t),o=0;for(let e of r.values())o=Math.max(o,e);let a=Array.from({length:o+1},()=>[]);for(let t of e)a[r.get(t)??0].push(t);a.forEach(e=>e.sort((e,t)=>ve(e,t)));let l=(e,i)=>{let n=new Map(a[i].map((e,t)=>[e,t])),s=e=>{let i=[...t.get(e)??[]].map(e=>n.get(e)).filter(e=>null!=e);return 0===i.length?Number.POSITIVE_INFINITY:i.reduce((e,t)=>e+t,0)/i.length},r=new Map(a[e].map(e=>[e,s(e)]));a[e].sort((e,t)=>r.get(e)-r.get(t)||ve(e,t))};for(let e=0;e<4;e+=1){for(let e=1;e<a.length;e+=1)l(e,e-1);for(let e=a.length-2;e>=0;e-=1)l(e,e+1)}return a}function gt(e,t,i,n,s,r){let o=pt(e.map(e=>e.id),t),a=ft(o),l=new Map(e.map(e=>[e.id,e.data])),h=/* @__PURE__ */new Map,d=Math.max(0,i.width),u=Math.max(0,i.height),c=Math.min(n,d/2),p=Math.min(n,u/2),f=Math.max(0,u-2*p),y=a.length>1?Math.min(s,f/a.length):0,m=Math.max(0,f-y*Math.max(0,a.length-1)),x=a.reduce((e,t)=>e+Math.sqrt(t.length),0),g=p;for(let e of a){let t=m*(Math.sqrt(e.length)/x),i=xt(e,o,r),n=Math.max(0,d-2*c);i.forEach((e,s)=>{let r=1===i.length?d/2:c+s/(i.length-1)*n;e.forEach((i,n)=>{let s=1===e.length?g+t/2:g+n/(e.length-1)*t;h.set(i,{id:i,x:r,y:s,data:l.get(i)})})}),g+=t+y}return h}function vt(e,t,i,n={}){let s=Math.max(0,n.padding??36),r=Math.max(0,n.componentGap??26),o=n.xAccessor??"x",a=n.yAccessor??"y",l=e.map(e=>({...e,authoredX:ut(e.data,o),authoredY:ut(e.data,a)})),h=l.length>0&&l.every(e=>dt(e.authoredX)&&dt(e.authoredY)),d="authored"===n.layoutMode||"automatic"!==n.layoutMode&&h,u=[];if(d&&!h&&u.push("Authored transit layout requested, but at least one station has no finite x/y position; using automatic topology layout."),!d||!h){!h&&"automatic"!==n.layoutMode&&u.push("Complete station positions were not supplied; using the deterministic automatic topology layout.");let o=gt(e,t,i,s,r,n.rootId);if("right-to-left"===n.direction)for(let e of o.values())e.x=i.width-e.x;return{positions:o,mode:"automatic",warnings:u,projectAuthoredPoint:e=>e}}let c=1/0,p=-1/0,f=1/0,y=-1/0;for(let e of l)c=Math.min(c,e.authoredX),p=Math.max(p,e.authoredX),f=Math.min(f,e.authoredY),y=Math.max(y,e.authoredY);let m=Math.max(1,i.width-2*s),x=Math.max(1,i.height-2*s),g=e=>({x:p===c?i.width/2:s+(e.x-c)/(p-c)*m,y:y===f?i.height/2:s+(e.y-f)/(y-f)*x}),v=/* @__PURE__ */new Map;for(let e of l){let t=g({x:e.authoredX,y:e.authoredY});v.set(e.id,{id:e.id,...t,data:e.data})}return{positions:v,mode:"authored",warnings:u,projectAuthoredPoint:g}}function bt(e,t){let i=t.x-e.x,n=t.y-e.y,s=Math.abs(i),r=Math.abs(n);if(s<.001||r<.001||Math.abs(s-r)<.001)return[e,t];let o=Math.sign(i),a=Math.sign(n);if(s>r){let i=(s-r)/2;return[e,{x:e.x+o*i,y:e.y},{x:t.x-o*i,y:t.y},t]}let l=(r-s)/2;return[e,{x:e.x,y:e.y+a*l},{x:t.x,y:t.y-a*l},t]}function wt(e,t){if(0===t||e.length<2)return e.map(e=>({...e}));let i=(e,t)=>{let i=t.x-e.x,n=t.y-e.y,s=Math.hypot(i,n)||1;return{x:-n/s,y:i/s}};return e.map((n,s)=>{let r=s>0?i(e[s-1],n):null,o=s<e.length-1?i(n,e[s+1]):null;if(!r||!o){let e=o??r??{x:0,y:0};return{x:n.x+e.x*t,y:n.y+e.y*t}}let a=r.x+o.x,l=r.y+o.y,h=Math.hypot(a,l);if(h<.001)return{x:n.x+o.x*t,y:n.y+o.y*t};a/=h,l/=h;let d=a*o.x+l*o.y;if(Math.abs(d)<.001)return{x:n.x+o.x*t,y:n.y+o.y*t};let u=4*Math.abs(t),c=t/d,p=Math.max(-u,Math.min(u,c));return{x:n.x+a*p,y:n.y+l*p}})}function St(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let i=Math.max(0,t),n=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let s=e[t-1],r=e[t],o=e[t+1],a=Math.hypot(r.x-s.x,r.y-s.y),l=Math.hypot(o.x-r.x,o.y-r.y),h=Math.min(i,a/2,l/2);if(h<=.001){n+=` L${r.x},${r.y}`;continue}let d={x:r.x+(s.x-r.x)/a*h,y:r.y+(s.y-r.y)/a*h},u={x:r.x+(o.x-r.x)/l*h,y:r.y+(o.y-r.y)/l*h};n+=` L${d.x},${d.y} Q${r.x},${r.y} ${u.x},${u.y}`}let s=e[e.length-1];return`${n} L${s.x},${s.y}`}var Mt=(e,t,i)=>({x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}),It=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function kt(e){let t=[e[0]];for(let i=1;i<e.length-1;i++){let n=e[i-1],s=e[i],r=e[i+1],o=It(n,s),a=It(s,r),l=Math.min(8,o/2,a/2);if(0===l)continue;let h=Mt(s,n,l/o),d=Mt(s,r,l/a);t.push(h);for(let e=1;e<=12;e++){let i=e/12;t.push(Mt(Mt(h,s,i),Mt(s,d,i),i))}}return t.push(e[e.length-1]),t.filter((e,i)=>0===i||It(t[i-1],e)>1e-8)}function Bt(e,t,i){if(e.length<2)return"";let n=kt(e);if(n.length<2)return"";let s=[0];for(let e=1;e<n.length;e++)s.push(s[e-1]+It(n[e-1],n[e]));let r=s[s.length-1],o=wt(n,1),a=[1,-1].map(e=>n.map((n,a)=>{let l=t+(i-t)*s[a]/r;return Mt(n,o[a],e*l/2)}));return[...a[0],...a[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function Ot(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let i=t+e/2;return t+=e+3,i})}var At={viewBox:[24,24],parts:[{d:"M5,0 H19 Q24,0 24,5 V19 Q24,24 19,24 H5 Q0,24 0,19 V5 Q0,0 5,0 Z",stroke:"accent"}]};function $t(e){let t="";return e.split(">").map((e,i)=>t=i?`${t}>${e}`:e)}function Tt(e){let t=/* @__PURE__ */new Map;for(let i of e){let e=$t(i.signature);i.nodePath.forEach((n,s)=>{let r=e[s],o=t.get(r);o||(o={id:r,state:n,depth:s+1,signatures:/* @__PURE__ */new Set},t.set(r,o)),o.signatures.add(i.signature)})}return[...t.values()]}var Ct=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,Nt=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),Pt=t=>{let i=t.config.braid,n=t.dimensions.plot,s=i.atlas.spec.comparison?.partitions??[...new Set(i.groups.map(e=>e.partition))],r=i.groups.filter(e=>s.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],l=[];if(0===r.length)return{sceneNodes:a,sceneEdges:o,labels:l};let h=new Set(r.map(e=>e.signature)),d=[...i.signatureOrder.filter(e=>h.delete(e)),...h],u=new Map(d.map((e,t)=>[e,t])),c=[...r].sort((e,t)=>u.get(e.signature)-u.get(t.signature)),p=s.map(e=>c.filter(t=>t.partition===e)),f=Tt(c),y=e(f.map(e=>e.depth)),m=r.map(t=>e(t.stepEntityCounts??[t.entityCount])),x=e(m),g=e=>e<=0?0:Math.max(1,10*e/x),v=new Map(r.map((e,t)=>[e.id,g(m[t])])),b=n.height/s.length,{semantic:w}=t.theme,S=(e,t,i,n={})=>l.push({x:e,y:t,text:i,fill:w.text??"#333",fontSize:10,anchor:"middle",...n}),M={sourceRevision:i.atlas.provenance.sourceRevision,analysisRevision:i.atlas.analysisRevision,relationScopeId:"directed-admitted"},I=new Map(f.map(t=>{let i=p.map(e=>e.reduce((e,i)=>e+(t.signatures.has(i.signature)?v.get(i.id)+3:0),5));return[t.id,e(i,24)]})),k=e([...I.values()],24),B=Math.min(n.width/4,k/2+16),O=(n.width-2*B)/Math.max(y-1,1),A=e=>n.x+B+(e-1)*O,$=48+k/2,T=22+k/2,C=(e,t)=>e+$+(u.get(t)+.5)*Math.max(0,b-$-T)/d.length,N=(e,i,n,s,r)=>{let a=Ct(i,s),l=Ct(i,r),h=g(a),d=g(l);if(0===h&&0===d)return;let u=h!==d,c=t.resolveColor(i.signature);o.push({type:"curved",id:n,pathD:u?Bt(e,h,d):St(e,8),style:{fill:u?c:"none",fillOpacity:1,stroke:u?"none":c,strokeWidth:u?0:h},datum:{...M,id:n,kind:"braid-track",nodeId:i.nodePath[r],fromNodeId:i.nodePath[s],groupId:i.id,signature:i.signature,partition:i.partition,entityCount:i.entityCount,fromStep:s,toStep:r,fromCount:a,toCount:l,falseRoot:!1},accessibleDatum:{journey:i.nodePath.join(" → "),partition:i.partition??"all",fromStep:s+1,toStep:r+1,fromCount:a,toCount:l}})};return s.forEach((e,t)=>{let i=n.y+t*b,s=p[t];if(e&&S(n.x+8,i+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===s.length)return;for(let e=1;e<=y;e++)S(A(e),i+34,`Step ${e}`);let r=/* @__PURE__ */new Map;for(let t of f){let n=s.filter(e=>t.signatures.has(e.signature));if(0===n.length)continue;let o=A(t.depth),l=xe([...t.signatures].map(e=>C(i,e))),h=Ot(n.map(e=>v.get(e.id)));r.set(t.id,new Map(n.map((e,t)=>[e.id,{x:o,y:l+h[t],offset:h[t]}])));let d=I.get(t.id),u={state:t.state,step:t.depth,partition:e??"all"},c=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:c,cx:o,cy:l,size:d,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:At,accent:w.border??"#888",style:{fill:w.surface??"#fff"},datum:{...M,id:c,nodeId:t.state,kind:"braid-step",prefixId:t.id,...u},accessibleDatum:u}),S(o,l+d/2+12,t.state,{anchorPoint:[o,l]})}for(let t of s){let i=$t(t.signature);for(let n=1;n<i.length;n++){let s=r.get(i[n-1]).get(t.id),o=r.get(i[n]).get(t.id),a=(s.x+o.x)/2-Math.sign(o.y-s.y)*o.offset,l=Math.abs(s.y-o.y)<1e-8?[s,o]:[s,{x:a,y:s.y},{x:a,y:o.y},o];N(l,t,`step:${e??"all"}:${i[n]}:${t.id}`,n-1,n)}}}),{sceneNodes:a,sceneEdges:o,labels:l,restyle:Nt,restyleEdge:Nt}};function qt(e,t){let i=0,n=e.length-1,s=-1;for(;i<=n;){let r=i+n>>>1;e[r].at<=t?(s=r,i=r+1):n=r-1}return s<0?{at:t,before:0,after:0}:e[s]}function Ft(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let i=[],n=[0];for(let s=0;s<e.length-1;s++){let r=e[s],o=e[s+1],a=[.../* @__PURE__ */new Set([...r.map(e=>e.at),...o.map(e=>e.at)])].sort((e,t)=>e-t),l=0;for(let e of a){let t=qt(r,e),i=qt(o,e);l=Math.max(l,t.after+i.before)}i.push(l),n.push(n[n.length-1]+l+t)}return{adjacentClearance:i,positions:n}}function Dt(e,t,i,n={}){let s=[...e];if(s.length<=1)return s;let r=[...s],o=i(s),a=1,l=Math.max(0,n.passes??6),h=Math.max(1,n.maxEvaluations??1/0);for(let e=0;e<l&&a<h;e++){let e=new Map(s.map((e,t)=>[e,t])),l=/* @__PURE__ */new Map,h=/* @__PURE__ */new Map;for(let i of t){let t=e.get(i.source),n=e.get(i.target);if(null==t||null==n)continue;let s=Number.isFinite(i.weight)&&i.weight>0?i.weight:1;l.set(i.source,(l.get(i.source)??0)+n*s),h.set(i.source,(h.get(i.source)??0)+s),l.set(i.target,(l.get(i.target)??0)+t*s),h.set(i.target,(h.get(i.target)??0)+s)}s=s.map((e,t)=>({item:e,index:t,barycenter:(l.get(e)??t)/(h.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(n.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let d=i(s);if(a++,d<o)o=d,r=[...s];else if(d===o)break}return r}function Yt(e,t,i={}){let n=[...e];if(n.length<=1)return n;let s=t(n),r=1,o=Math.max(0,i.passes??6),a=Math.max(1,i.maxEvaluations??1/0);for(let e=0;e<o&&r<a;e++){let e=!1;for(let i=0;i<n.length-1&&r<a;i++){[n[i],n[i+1]]=[n[i+1],n[i]];let o=t(n);r++,o<s?(s=o,e=!0):[n[i],n[i+1]]=[n[i+1],n[i]]}if(!e)break}return n}function Et(e,t,i={}){let n=[...e],s=n.length;if(s<=1||s>(i.maxItems??8))return n;let r=Math.max(1,i.maxEvaluations??1/0),o=0,a=[...n],l=1/0,h=()=>{if(o>=r)return;let e=t(n);o++,e<l&&(l=e,a=[...n])};h();let d=new Array(s).fill(0),u=0;for(;u<s&&o<r;)if(d[u]<u){let e=u%2==0?0:d[u];[n[e],n[u]]=[n[u],n[e]],h(),d[u]++,u=0}else d[u]=0,u++;return a}function Lt(e,t,i=()=>!0){let n=0;for(let s=0;s<e.length;s++){let[r,o]=t(e[s]);for(let a=s+1;a<e.length;a++){if(!i(e[s],e[a]))continue;let[l,h]=t(e[a]);(r-l)*(o-h)<0&&n++}}return n}import*as Rt from"react";import{jsx as Xt}from"react/jsx-runtime";var jt,Wt={isActive:!1,predicate:()=>!0};function zt(){let e=(jt??(jt=Rt.createContext(null)),jt);return Rt.useContext(e)??Wt}function Gt(e,t){let i=/* @__PURE__ */new Map;for(let t of e)i.set(t.id,/* @__PURE__ */new Set);for(let e of t)i.has(e.source)||i.set(e.source,/* @__PURE__ */new Set),i.has(e.target)||i.set(e.target,/* @__PURE__ */new Set),i.get(e.source).add(e.target);return i}function Vt(e,t,i={}){let n=/* @__PURE__ */new Set,s=[...e.get(t)??[]];for(let t=0;t<s.length;t++){let i=s[t];n.has(i)||(n.add(i),s.push(...e.get(i)??[]))}return i.includeStart&&n.add(t),n}function _t(e){let t=e.fixedPosition;Number.isFinite(t?.x)&&(e.x=e.prevX=t.x,e.vx=0),Number.isFinite(t?.y)&&(e.y=e.prevY=t.y,e.vy=0)}function Ht(e){if(!e)return;let t=Number.isFinite(e.x)?e.x:void 0,i=Number.isFinite(e.y)?e.y:void 0;return null==t&&null==i?void 0:{x:t,y:i}}function Ut(e,t,i){let n,s="x"===i?"y":"x",r=Math.abs(t[i]-e[i]),o=t[s]-e[s],a=(e,t)=>"circle"===e.shape.type?e.shape.radius:("x"===t?e.shape.width:e.shape.height)/2;if("circle"===e.shape.type&&"circle"===t.shape.type){let i=e.shape.radius+t.shape.radius;n=Math.sqrt(Math.max(0,i*i-r*r))}else if("aabb"===e.shape.type&&"aabb"===t.shape.type)n=a(e,s)+a(t,s);else{let o="circle"===e.shape.type?e:t,l="aabb"===e.shape.type?e:t,h=a(o,i),d=Math.max(0,r-a(l,i));n=a(l,s)+Math.sqrt(Math.max(0,h*h-d*d))}let l=o<0?-1:1;return{nx:"x"===s?l:0,ny:"y"===s?l:0,penetration:Math.max(0,n-Math.abs(o))}}function Kt(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function Qt(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 Zt(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,...e.fixedPosition?{fixedPosition:Ht(e.fixedPosition)}:{},shape:Kt(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Jt(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 ei(e){return{id:e.id,shape:Qt(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Jt(e.bodyFilter),index:e.index}}function ti(e,t,i){if("aabb"!==t.type)return null;let n=e.x-e.prevX,s=e.y-e.prevY;if(0===n&&0===s)return null;let r="circle"===e.shape.type?e.shape.radius:e.shape.width/2,o="circle"===e.shape.type?e.shape.radius:e.shape.height/2,a=t.x-t.width/2,l=t.x+t.width/2,h=t.y-t.height/2,d=t.y+t.height/2;if(Math.max(e.x,e.prevX)+r<a||Math.min(e.x,e.prevX)-r>l||Math.max(e.y,e.prevY)+o<h||Math.min(e.y,e.prevY)-o>d)return null;let u="circle"===e.shape.type?0:r,c="circle"===e.shape.type?0:o,p=1/0,f=null,y=(e,t,n,s,r,o,a,l,h,d,u)=>{let c,y,m;if(n>0&&t+s<=r+i&&e+s>r)c=Math.max(0,(r-s-t)/n),y=e+s-r,m=-1;else{if(!(n<0&&t-s>=o-i&&e-s<o))return;c=Math.max(0,(o+s-t)/n),y=o-(e-s),m=1}let x=a+l*c;c<p&&x>=h&&x<=d&&(p=c,f={nx:u?m:0,ny:u?0:m,penetration:y})};return y(e.x,e.prevX,n,r,a,l,e.prevY,s,h-c,d+c,!0),y(e.y,e.prevY,s,o,h,d,e.prevX,n,a-u,l+u,!1),f}function ii(e,t){return Math.abs(e.x-t.x)<=t.padding&&Math.abs(e.y-t.y)<=t.padding}function ni(e,t){let i=si(e),n=[];for(let e=0;e<t.length;e++)ai(i,t[e].bounds)&&n.push(e);return{bounds:i,indexes:n}}function si(e,t=!0){let i="circle"===e.shape.type?e.shape.radius:e.shape.width/2,n="circle"===e.shape.type?e.shape.radius:e.shape.height/2,s=t?Math.max(.005,Math.min(i,n)):0;return{x:e.x,y:e.y,padding:s,minX:Math.min(e.x,e.prevX)-i-s,minY:Math.min(e.y,e.prevY)-n-s,maxX:Math.max(e.x,e.prevX)+i+s,maxY:Math.max(e.y,e.prevY)+n+s}}function ri(e){let t="circle"===e.shape.type?e.shape.radius:e.shape.width/2,i="circle"===e.shape.type?e.shape.radius:e.shape.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}function oi(e){let t=e.shape;if("aabb"===t.type)return ri({x:t.x,y:t.y,shape:t});let i=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-i,minY:Math.min(t.y1,t.y2)-i,maxX:Math.max(t.x1,t.x2)+i,maxY:Math.max(t.y1,t.y2)+i}}function ai(e,t){return e.minX<=t.maxX&&e.maxX>=t.minX&&e.minY<=t.maxY&&e.maxY>=t.minY}function li(e,t,i={x:0,y:0}){let n=1,s=e.map(e=>{let t=si(e,!(e.sleeping&&e.x===e.prevX&&e.y===e.prevY));return!1!==e.bodyCollisions&&(n=Math.max(n,t.maxX-t.minX,t.maxY-t.minY)),t}),r=Math.max(1,Math.min(t,n)),o=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){if(!1===e[t].bodyCollisions)continue;let i=s[t];i.cellX=Math.floor(i.minX/r),i.cellY=Math.floor(i.minY/r);for(let e=i.cellX;e<=Math.floor(i.maxX/r);e+=1){let n=o.get(e);n||o.set(e,n=/* @__PURE__ */new Map);for(let e=i.cellY;e<=Math.floor(i.maxY/r);e+=1){let i=n.get(e);i?i.push(t):n.set(e,[t])}}}let a=[];for(let[e,t]of o)for(let[i,n]of t)for(let t=0;t<n.length;t+=1)for(let r=t+1;r<n.length;r+=1){let o=n[t],l=n[r],h=s[o],d=s[l];e!==Math.max(h.cellX,d.cellX)||i!==Math.max(h.cellY,d.cellY)||ai(h,d)&&a.push([o,l])}let l=e.map(e=>e.x*i.x+e.y*i.y);return a.sort(([e,t],[i,n])=>Math.max(l[i],l[n])-Math.max(l[e],l[t])||(e===i?t-n:e-i)),{pairs:a,coversPositions:()=>e.every((e,t)=>!1===e.bodyCollisions||ii(e,s[t]))}}function hi(e,t){if("circle"!==e.shape.type||"circle"!==t.shape.type)return null;let i=e.shape.radius+t.shape.radius;if(i<=0)return null;let n=t.prevX-e.prevX,s=t.prevY-e.prevY,r=t.x-e.x-n,o=t.y-e.y-s,a=r*r+o*o,l=2*(n*r+s*o),h=n*n+s*s-i*i;if(h<-1e-5||a<=1e-12||l>=0)return null;let d=l*l-4*a*h;if(d<0)return null;let u=(-l-Math.sqrt(d))/(2*a);if(u<0||u>1)return null;let c=(n+u*r)/i,p=(s+u*o)/i,f=i-((t.x-e.x)*c+(t.y-e.y)*p);return f>0?{nx:c,ny:p,penetration:f}:null}var di={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},ui=1e-9,ci=.005;function pi(e,t,i){return Math.max(t,Math.min(i,e))}function fi(e,t,i){return Math.min(e??i,t??i)}function yi(e,t,i){return pi(Math.max(e??i,t??i),0,1)}function mi(e){return e<0?-1:1}function xi(e){return e.sleeping&&e.x===e.prevX&&e.y===e.prevY}function gi(e,t,i,n,s,r){let o=n-e,a=s-t,l=i+r,h=o*o+a*a;if(h>=l*l)return null;if(h<=ui)return{nx:1,ny:0,penetration:l};let d=Math.sqrt(h);return{nx:o/d,ny:a/d,penetration:l-d}}function vi(e,t,i,n,s,r,o,a){let l=s-e,h=(i+o)/2-Math.abs(l);if(h<=0)return null;let d=r-t,u=(n+a)/2-Math.abs(d);return u<=0?null:h<u?{nx:mi(l),ny:0,penetration:h}:{nx:0,ny:mi(d),penetration:u}}function bi(e,t,i,n,s,r,o){let a=r/2,l=o/2,h=e-pi(e,n-a,n+a),d=t-pi(t,s-l,s+l),u=h*h+d*d;if(u>i*i)return null;if(u<=ui){let r=Math.abs(e-(n-a)),o=Math.abs(e-(n+a)),h=Math.abs(t-(s-l)),d=Math.abs(t-(s+l)),u=Math.min(r,o,h,d);return u===r?{nx:-1,ny:0,penetration:i+r}:u===o?{nx:1,ny:0,penetration:i+o}:u===h?{nx:0,ny:-1,penetration:i+h}:{nx:0,ny:1,penetration:i+d}}let c=Math.sqrt(u);return{nx:h/c,ny:d/c,penetration:i-c}}function wi(e,t,i,n,s,r,o,a=0){let l=r-n,h=o-s,d=l*l+h*h,u=d<=ui?0:pi(((e-n)*l+(t-s)*h)/d,0,1),c=i+a/2,p=e-(n+l*u),f=t-(s+h*u),y=p*p+f*f;if(y>=c*c)return null;if(y<=ui){let e=Math.sqrt(d);return e<=ui?{nx:1,ny:0,penetration:c}:{nx:-h/e,ny:l/e,penetration:c}}let m=Math.sqrt(y);return{nx:p/m,ny:f/m,penetration:c-m}}function Si(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return gi(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return vi(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);let i="circle"===e.shape.type?e:t,n=i===e?t:e;if("circle"!==i.shape.type||"aabb"!==n.shape.type)return null;let s=bi(i.x,i.y,i.shape.radius,n.x,n.y,n.shape.width,n.shape.height);return s&&i===e&&(s.nx=-s.nx,s.ny=-s.ny),s}function Mi(e,t){let i=t.shape;if("aabb"===i.type)return"circle"===e.shape.type?bi(e.x,e.y,e.shape.radius,i.x,i.y,i.width,i.height):vi(i.x,i.y,i.width,i.height,e.x,e.y,e.shape.width,e.shape.height);let n="circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2;return wi(e.x,e.y,n,i.x1,i.y1,i.x2,i.y2,i.thickness??0)}function Ii(e,t){return`${e}\0${t}`}function ki(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Bi(e,t){if(!t)return;let i=e;for(let e of t.split(".")){if(null==i||"object"!=typeof i||!Object.prototype.hasOwnProperty.call(i,e))return;i=i[e]}return i}function Oi(e,t){return!!t?.some(t=>Object.is(e,t))}function Ai(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let i=Bi(e,t.property);return!("equals"in t&&!Object.is(i,t.equals)||"notEquals"in t&&Object.is(i,t.notEquals)||t.oneOf&&!Oi(i,t.oneOf)||t.notOneOf&&Oi(i,t.notOneOf))}function $i(e,t){return Ai(t,e.bodyFilter)}var Ti=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=/* @__PURE__ */new Map,this.colliders=/* @__PURE__ */new Map,this.springs=/* @__PURE__ */new Map,this.activeSensors=/* @__PURE__ */new Set,this.supportedThisStep=/* @__PURE__ */new Set,this.supportDependents=/* @__PURE__ */new Map,this.supportContactsThisStep=/* @__PURE__ */new Set,this.reboundingThisStep=/* @__PURE__ */new Set,this.interpenetratingThisStep=/* @__PURE__ */new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...di,...e},this.random=t(this.options.seed)}init(e={}){this.options={...di,...e},this.random=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){let 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(ui,e.mass??1),bodyCollisions:e.bodyCollisions??!0,...e.fixedPosition?{fixedPosition:Ht(e.fixedPosition)}:{},shape:Kt(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};_t(t),this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(let t of e){this.bodies.delete(t);for(let e of Array.from(this.activeSensors))ki(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(let t of e)this.colliders.set(t.id,{...t,shape:Qt(t.shape),bodyFilter:Jt(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){let 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,i){let n=this.bodies.get(e);n&&(n.vx+=t/n.mass,n.vy+=i/n.mass,_t(n),this.wake(n))}step(e=this.options.fixedDt){let t=Math.max(0,e);if(this.lastEvents=[],0===t)return;this.reboundingThisStep.clear();let i=this.sortedBodies();for(let e of i)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);let n=this.options.maxVelocity;for(let e of i)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,_t(e),n>0){let t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>n){let i=n/t;e.vx*=i,e.vy*=i}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear(),this.supportDependents.clear(),this.supportContactsThisStep.clear(),this.interpenetratingThisStep.clear();let s=this.sortedColliders().filter(e=>!e.sensor).map(e=>({collider:e,bounds:oi(e)})),r=s.some(({collider:e})=>e.bodyFilter)?void 0:new Array(i.length);this.resolveColliders(i,s,!1,r);let o=r&&i.map(xi),a=li(i,this.options.cellSize,this.options.gravity);for(let e=0;e<this.options.collisionIterations;e+=1){e>0&&!a.coversPositions()&&(a=li(i,this.options.cellSize,this.options.gravity));let t=this.resolveBodyPairs(i,a.pairs,0===e,o),n=this.resolveColliders(i,s,0===e,r);if(r&&!t&&!n)break}a.coversPositions()||(a=li(i,this.options.cellSize,this.options.gravity));for(let[e,t]of a.pairs){let n=Si(i[e],i[t]);n&&n.penetration>.02&&(this.interpenetratingThisStep.add(i[e].id),this.interpenetratingThisStep.add(i[t].id))}let l=Array.from(this.supportedThisStep);for(let e=0;e<l.length;e+=1)for(let t of this.supportDependents.get(l[e])??[])this.supportedThisStep.has(t)||(this.supportedThisStep.add(t),l.push(t));this.reconcileSupportedVelocity(i,t),this.updateSensors(i),this.updateSleeping(i,t)}settle(e=1200,t=this.options.fixedDt){let i=0;for(;i<e&&!this.allSleeping();)this.step(t),i+=1;return i}readState(e=[]){e.length=0;for(let 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,...t.fixedPosition?{fixedPosition:Ht(t.fixedPosition)}:{},shape:Kt(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(ki)}allSleeping(){for(let 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(Zt),colliders:this.sortedColliders().map(ei),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=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(let t of e.bodies){let e=Zt(t);_t(e),this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(let t of e.colliders){let e=ei(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(let t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});let 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(let t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){let i=this.bodies.get(t.bodyId);if(!i||i.sleeping)continue;let n="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!n)continue;let s=n.x-i.x,r=n.y-i.y,o=s*s+r*r,a=Math.sqrt(o);if(a<=ui)continue;let l=s/a,h=r/a,d="vx"in n?n.vx:0,u="vy"in n?n.vy:0,c=(d-i.vx)*l+(u-i.vy)*h,p=(a-t.restLength)*t.stiffness+c*t.damping;i.vx+=p*l*e/i.mass,i.vy+=p*h*e/i.mass}}resolveBodyPairs(e,t,i,n){let s=!1;for(let[r,o]of t){let t=e[r],a=e[o];if(!t||!a)continue;if(!i&&n?.[r]&&n[o]&&xi(t)&&xi(a)){s=!0;continue}let l=hi(t,a)??Si(t,a);l&&(s=!0,this.resolveDynamicCollision(t,a,l),i&&this.lastEvents.push({type:"contact",bodyId:t.id,otherId:a.id,sensor:!1}))}return s}resolveDynamicCollision(e,t,i){(e.fixedPosition||t.fixedPosition)&&(!e.sleeping&&null==e.fixedPosition?.x||!t.sleeping&&null==t.fixedPosition?.x?(e.sleeping||null!=e.fixedPosition?.y)&&(t.sleeping||null!=t.fixedPosition?.y)&&(i=Ut(e,t,"y")):i=Ut(e,t,"x"));let n=this.options.gravity,s=Math.hypot(n.x,n.y),r=this.contactOpposesGravity(i.nx,i.ny,s),o=this.contactOpposesGravity(-i.nx,-i.ny,s);r&&(e.sleeping&&this.supportedThisStep.add(t.id),this.addSupportContact(e.id,t.id)),o&&(t.sleeping&&this.supportedThisStep.add(e.id),this.addSupportContact(t.id,e.id));let a=e.sleeping?0:1/e.mass,l=t.sleeping?0:1/t.mass,h=null==e.fixedPosition?.x?a:0,d=null==e.fixedPosition?.y?a:0,u=null==t.fixedPosition?.x?l:0,c=null==t.fixedPosition?.y?l:0,p=e.fixedPosition||t.fixedPosition?i.nx**2*(h+u)+i.ny**2*(d+c):a+l;if(p<=ui)return;let f=this.supportedThisStep.has(e.id)&&r&&!t.sleeping&&!t.fixedPosition,y=this.supportedThisStep.has(t.id)&&o&&!e.sleeping&&!e.fixedPosition,m=s>1,x=m&&f?0:h,g=m&&f?0:d,v=m&&!f&&y?0:u,b=m&&!f&&y?0:c,w=i.nx**2*(x+v)+i.ny**2*(g+b),S=Math.max(0,i.penetration-ci)/Math.max(ui,w);e.x-=i.nx*S*x,e.y-=i.ny*S*g,t.x+=i.nx*S*v,t.y+=i.ny*S*b,m&&f&&this.supportedThisStep.add(t.id),m&&y&&this.supportedThisStep.add(e.id);let M=t.vx-e.vx,I=t.vy-e.vy,k=M*i.nx+I*i.ny;if(k>0)return;let B=Math.abs(k),O=fi(e.restitution,t.restitution,this.options.restitution),A=e.vx*n.x+e.vy*n.y,$=t.vx*n.x+t.vy*n.y,T=-(1+O)*k/p,C=T*i.nx,N=T*i.ny;e.vx-=C*h,e.vy-=N*d,t.vx+=C*u,t.vy+=N*c,this.applyFriction(e,t,i,T,h,d,u,c),O>0&&(A>=0&&e.vx*n.x+e.vy*n.y<0&&this.reboundingThisStep.add(e.id),$>=0&&t.vx*n.x+t.vy*n.y<0&&this.reboundingThisStep.add(t.id)),B>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,i,n,s,r,o,a){let l=-i.ny,h=i.nx,d=(t.vx-e.vx)*l+(t.vy-e.vy)*h,u=e.fixedPosition||t.fixedPosition?l**2*(s+o)+h**2*(r+a):s+o;if(Math.abs(d)<=ui||u<=ui)return;let c=yi(e.friction,t.friction,this.options.friction),p=pi(-d/u,-n*c,n*c),f=p*l,y=p*h;e.vx-=f*s,e.vy-=y*r,t.vx+=f*o,t.vy+=y*a}resolveColliders(e,t,i,n){if(0===t.length)return!1;let s=!1;for(let r=0;r<e.length;r++){let o=e[r],a=n?.[r];n&&(!a||!ii(o,a.bounds))&&(n[r]=a=ni(o,t));let l=0;for(;l<(a?a.indexes.length:t.length);){let e=a?a.indexes[l++]:l++,{collider:h,bounds:d}=t[e];if(!$i(h,o))continue;let u=ti(o,h.shape,ci+ui);if(!u&&!ai(ri(o),d))continue;let c=u??Mi(o,h);if(c&&(s=!0,this.resolveStaticCollision(o,h,c),this.contactOpposesGravity(c.nx,c.ny)&&this.supportedThisStep.add(o.id),i&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:h.id,sensor:!1}),a&&n&&!ii(o,a.bounds)))for(n[r]=a=ni(o,t),l=0;l<a.indexes.length&&a.indexes[l]<=e;)l++}}return s}resolveStaticCollision(e,t,i){e.x+=i.nx*Math.max(0,i.penetration-ci),e.y+=i.ny*Math.max(0,i.penetration-ci);let n=e.vx*i.nx+e.vy*i.ny;if(n<0){let s=fi(e.restitution,t.restitution,this.options.restitution),r=this.options.gravity,o=e.vx*r.x+e.vy*r.y;e.vx-=(1+s)*n*i.nx,e.vy-=(1+s)*n*i.ny;let a=-i.ny,l=i.nx,h=e.vx*a+e.vy*l,d=yi(e.friction,t.friction,this.options.friction);e.vx-=h*a*d,e.vy-=h*l*d,s>0&&o>=0&&e.vx*r.x+e.vy*r.y<0&&this.reboundingThisStep.add(e.id)}_t(e)}updateSensors(e){let t=this.sortedColliders().filter(e=>e.sensor);if(0===t.length&&0===this.activeSensors.size)return;let i=/* @__PURE__ */new Set;for(let n of e){let e=ri(n);for(let s of t){if(!$i(s,n)||!ai(e,oi(s))||!Mi(n,s))continue;let t=Ii(s.id,n.id);i.add(t),this.activeSensors.has(t)||this.lastEvents.push({type:"sensor-enter",bodyId:n.id,sensorId:s.id})}}for(let e of Array.from(this.activeSensors).sort()){if(i.has(e))continue;let{sensorId:t,bodyId:n}=ki(e);this.lastEvents.push({type:"sensor-exit",bodyId:n,sensorId:t})}this.activeSensors=i}updateSleeping(e,t){let i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(let n of e){let e=Math.sqrt(n.vx*n.vx+n.vy*n.vy),s=Math.sqrt((n.x-n.prevX)*(n.x-n.prevX)+(n.y-n.prevY)*(n.y-n.prevY));e<this.options.sleepSpeed&&s<this.options.sleepSpeed*t&&!this.interpenetratingThisStep.has(n.id)&&(!i||this.supportedThisStep.has(n.id))?(n.sleepTime+=t,!n.sleeping&&n.sleepTime>=this.options.sleepAfter&&(n.sleeping=!0,n.vx=0,n.vy=0,this.lastEvents.push({type:"sleep",bodyId:n.id}))):n.sleeping?this.wake(n):n.sleepTime=0}}addSupportContact(e,t){let i=this.supportDependents.get(e);i?.has(t)||(this.supportContactsThisStep.add(e),this.supportContactsThisStep.add(t),i||(i=/* @__PURE__ */new Set,this.supportDependents.set(e,i)),i.add(t))}reconcileSupportedVelocity(e,t){let i=this.options.gravity;if(!(Math.hypot(i.x,i.y)<=1))for(let n of e)n.sleeping||!this.supportedThisStep.has(n.id)||!this.supportContactsThisStep.has(n.id)||this.reboundingThisStep.has(n.id)&&n.vx*i.x+n.vy*i.y<0||(n.vx=(n.x-n.prevX)/t,n.vy=(n.y-n.prevY)/t,_t(n))}contactOpposesGravity(e,t,i){let{x:n,y:s}=this.options.gravity;return i??(i=Math.hypot(n,s)),i<=1e-9||(e*n+t*s)/i<-.2}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Ci=["binId","targetBin","category","windowIndex","lane","group"];function Ni(){return{count:0,total:0,mean:0,m2:0,min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}}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);let i=t-e.mean;e.mean+=i/e.count;let n=t-e.mean;e.m2+=i*n}function qi(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 Fi(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:Number.POSITIVE_INFINITY,max:e.count>0?e.max:Number.NEGATIVE_INFINITY}}function Di(e,t){let i=e;if(null!=i[t])return i[t];let n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Yi(e,t,i){return"function"==typeof e?e(t,i):"string"==typeof e?Di(t,e):void 0}function Ei(e,t,i){if("number"==typeof e)return e;let n="function"==typeof e?e(t,i):"string"==typeof e?Di(t,e):1,s="number"==typeof n?n:Number(n);return Number.isFinite(s)?s:1}function Li(e){if(null==e)return;let t=String(e);return t.trim()?t:void 0}function Ri(e){for(let t of Ci){let i=Li(Di(e,t));if(i)return i}return"sediment"}function Xi(e){let t=qi(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:qi(e.x),y:qi(e.y),value:t}}var ji=class{constructor(e=!1){this.bins=/* @__PURE__ */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;let t=this.nextIndex;this.nextIndex+=1;let i=Li(Yi(this.config.binAccessor,e,t))??Ri(e),n=Li(Yi(this.config.labelAccessor,e,t))??i,s=Ei(this.config.valueAccessor,e,t),r=Math.max(0,Math.floor(this.config.retainBodyIds??12)),o=this.bins.get(i);return o||(o={id:i,label:n,bodyIds:[],x:Ni(),y:Ni(),value:Ni()},this.bins.set(i,o)),o.label=n,o.lastBodyId=e.id,o.lastDatum=e.datum,Pi(o.x,e.x),Pi(o.y,e.y),Pi(o.value,s),r>0&&(o.bodyIds.push(e.id),o.bodyIds.length>r&&(o.bodyIds=o.bodyIds.slice(o.bodyIds.length-r))),Xi(o)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Xi)}restore(e=[]){this.bins.clear();for(let 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:Fi(t.x),y:Fi(t.y),value:Fi(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){let 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 Wi(e,t={}){let{baselineY:i=0,binWidth:n=24,gap:s=2,maxHeight:r=80,value:o="count",x:a}=t,l=e.reduce((e,t)=>Math.max(e,t[o]),1);return e.map((e,t)=>{let h=Math.max(0,e[o]/l*r),d=a?.(e,t)??t*(n+s);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:d,y:i-h,width:n,height:h,meanX:e.x.mean,meanY:e.y.mean}})}var zi={bodyLimit:Number.POSITIVE_INFINITY,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Gi={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Vi(e={},t=Gi){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 _i(e){return{...e,shape:{...e.shape},...e.fixedPosition?{fixedPosition:{...e.fixedPosition}}:{},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Hi(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:void 0}let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Ui(e,t){let i=e;if(null!=i[t])return i[t];let n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Ki(e,t,i){return"function"==typeof i?Hi(i(e,t)):"string"==typeof i?Hi(Ui(e,i)):Hi(e.spawnAt)??Hi(Ui(e,"arrivalTime"))??Hi(Ui(e,"timestamp"))??Hi(Ui(e,"time"))??Hi(Ui(e,"eventTime"))}function Qi(e,t={}){let i=Hi(t.startAt)??0,n=t.pacing??"immediate";if("arrival"===n){let n=1/0,s=e.map((e,i)=>{let s=Ki(e,i,t.timeAccessor);return null!=s&&(n=Math.min(n,s)),s}),r=Hi(t.timeScale)??1,o=r>0?r:1;return e.map((e,t)=>{let r=s[t],a=null==r?0:Math.max(0,r-n);return{..._i(e),spawnAt:i+a/o}})}if("object"==typeof n){let t=Hi(n.ratePerSec);if(t&&t>0)return e.map((e,n)=>({..._i(e),spawnAt:i+n/t}))}return e.map(e=>({..._i(e),spawnAt:i}))}function Zi(e){return{..._i(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Ji(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 en(e){return!1!==e&&{...e}}function tn(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function nn(e){return{...e,gravity:{...e.gravity}}}function sn(e,t,i,n){if("circle"===e.shape.type){let s=e.x-t,r=e.y-i,o=e.shape.radius+n,a=s*s+r*r;return a<=o*o?a:null}let s=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),r=Math.max(Math.abs(i-e.y)-e.shape.height/2,0),o=s*s+r*r;return o<=n*n?o:null}function rn(e,t){return`${e}\0${t}`}function on(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function an(e,t={}){let{idPrefix:i="plot",includeFloor:n=!0,includeCeiling:s=!1,includeLeftWall:r=!0,includeRightWall:o=!0,wallThickness:a=20,floorThickness:l=a}=t,h=[],d=e.x+e.width/2,u=e.y+e.height/2,c=(e,t,n,s,r)=>{h.push({id:`${i}-${e}`,shape:{type:"aabb",x:t,y:n,width:s,height:r}})};return n&&c("floor",d,e.y+e.height+l/2,e.width+2*a,l),s&&c("ceiling",d,e.y-l/2,e.width+2*a,l),r&&c("left-wall",e.x-a/2,u,a,e.height+2*l),o&&c("right-wall",e.x+e.width+a/2,u,a,e.height+2*l),h}function ln(e){let{idPrefix:t="bin",count:i,domainStart:n,domainStep:s,xScale:r,yTop:o,yBottom:a,wallThickness:l=4,includeBoundaryWalls:h=!0,includeInteriorWalls:d=!0,closedBefore:u,lidY:c=o,lidThickness:p=Math.max(2,l)}=e,f=[],y=o+(a-o)/2,m=Math.abs(a-o),x=h?i:i-1;if(d||h)for(let e=h?0:1;e<=x;e+=1){if(!d&&e>0&&e<i)continue;let o=r(n+e*s);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:o,y:y,width:l,height:m}})}if(null!=u)for(let e=0;e<i;e+=1){let i=n+e*s,o=i+s;if(o>=u)continue;let a=r(i),h=r(o);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,h)+l/2,y1:c,x2:Math.max(a,h)-l/2,y2:c,thickness:p}})}return f}var hn=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Ti).capabilities,engine:"builtin"},this.world=new Ti(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,i){this.world.applyImpulse(e,t,i)}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 dn(e={}){return new hn(e)}function un(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):dn(t)}function cn(e){let t=Number(e);if(Number.isFinite(t)&&!(t<=0))return Math.floor(t)}function pn(e,t,i){if(!1===i)return;let n=cn(i?.warnAt);return null!=n?n:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}function fn(e){let t=Math.max(0,Math.floor(e.liveBodies)),i=Math.max(0,Math.floor(e.queuedBodies??0)),n=t+i,s=cn(e.bodyLimit),r=cn(e.engineMaxBodiesHint),o=pn(s,r,e.options),a=null==s?0:Math.max(0,t-s),l=a>0?"overflow":null!=o&&n>=o?"warning":"ok";return{action:"overflow"!==l?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:s,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:n,queuedBodies:i,state:l,warnAt:o}}var yn={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 mn(e,t){let i={...e};for(let e of t)i[yn[e]]++;return i}function xn(e,t,i){let n=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:n,revisions:mn(i,n)}}var gn=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=xn({kind:"initialize"},[],this.revisions),this.listeners=/* @__PURE__ */new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){let i=xn(e,t,this.revisions);this.revisions=i.revisions,this.latest=i;for(let e of[...this.listeners])e();return i}};import{quadtree as vn}from"d3-quadtree";var bn=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,i,n,s,r=0,o){let a=this.ensure(e,t);if(!a)return null;let l=null,h=Number.POSITIVE_INFINITY,d=Math.max(0,o?.searchRadius??Math.max(0,r)+this.maxSearchRadius),u=n-d,c=n+d,p=s-d,f=s+d;return a.visit((e,t,a,d,y)=>{if(d<u||t>c||y<p||a>f)return!0;if(e.length)return!1;let m=e;for(;m;){let e=m.data;if(e&&(!o?.include||o.include(e))){let t=o?.distanceSquared?o.distanceSquared(e,n,s):sn(e,n,s,Math.max(0,r));null!=t&&(t<h||t===h&&i.indexOf(e.id)>i.indexOf(l?.id??""))&&(l=e,h=t)}m=m.next}return!1}),l}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;let i=e.readState();return 0===i.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=i.reduce((e,t)=>{return Math.max(e,"circle"===(i=t).shape.type?i.shape.radius:Math.hypot(i.shape.width,i.shape.height)/2);var i},0),this.tree=vn().x(e=>e.x).y(e=>e.y).addAll(i),this.revision=t,this.tree)}},wn=["data","scene-geometry","data-paint","accessibility","evidence"],Sn=["scene-geometry","data-paint","accessibility","evidence"],Mn=["overlay","accessibility","evidence"],In=(e,t)=>({retainedData:e,invalidations:t}),kn=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Bn=["scene-geometry","data-paint","accessibility","evidence"],On=[],An={engine:/* @__PURE__ */In("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:/* @__PURE__ */In("preserve",Bn),colliders:/* @__PURE__ */In("preserve",Bn),sediment:/* @__PURE__ */In("preserve",Bn),bodyBudget:/* @__PURE__ */In("preserve",kn),bodyLimit:/* @__PURE__ */In("preserve",kn),eviction:/* @__PURE__ */In("preserve",kn),fixedDt:/* @__PURE__ */In("preserve",On),maxDeltaSeconds:/* @__PURE__ */In("preserve",On),maxSubsteps:/* @__PURE__ */In("preserve",On),settleStepLimit:/* @__PURE__ */In("preserve",On),timeScale:/* @__PURE__ */In("preserve",On),observation:/* @__PURE__ */In("preserve",On)},$n=/* @__PURE__ */In("preserve",kn);function Tn(e){let t="preserve",i=/* @__PURE__ */new Set;for(let n of e){let e=An[n]??$n;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var Cn=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Nn(e,t){return e===t||!(!e||!t||e.gravity?.x!==t.gravity?.x||e.gravity?.y!==t.gravity?.y)&&Cn.every(i=>e[i]===t[i])}function Pn(e,t){return Object.keys(e).filter(i=>"kernel"===i?!Nn(e.kernel,t.kernel):e[i]!==t[i])}function qn(e,t,i){if(!t.some(e=>"sleep"===e.type))return;let n=new Map(e.readState().map(e=>[e.id,e]));for(let e of t){if("sleep"!==e.type)continue;let t=n.get(e.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}function Fn(e,t,i){let n=new Set(e.activeSensorPairs().map(e=>rn(e.sensorId,e.bodyId))),s=n.size!==t.size;if(!s)for(let e of n)if(!t.has(e)){s=!0;break}if(!s)return n;let r=new Map(e.readState().map(e=>[e.id,e])),o=(e,t)=>{let{sensorId:n,bodyId:s}=on(t),o=i.observation.sensors[n],a=r.get(s);i.emit({type:"enter"===e?o?.enterType??"physics-bin-enter":o?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:s,datum:a?.datum,x:a?.x,y:a?.y,sensorId:n,binId:o?.binId??n})};for(let e of Array.from(n).sort())t.has(e)||o("enter",e);for(let e of Array.from(t).sort())n.has(e)||o("exit",e);return n}function Dn(e,t){for(let i of e)t.has(on(i).bodyId)&&e.delete(i)}function Yn(e,t,i,n){return e||!t?"paused":i||!n?"running":"settled"}function En(e,t,i){i.observation.onSimulationStateChange?.(t,e),("running"===t||"settled"===t)&&i.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:t,previousSimulationState:e})}function Ln(e,t){t.emit({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:t.elapsedSeconds,chartType:t.observation.chartType,chartId:t.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt})}function Rn(e,t,i){if("sleeping-first"!==t)return i.slice();let n=new Map(e.readState().map(e=>[e.id,e.sleeping])),s=[],r=[];for(let e of i)n.get(e)?s.push(e):r.push(e);return[...s,...r]}function Xn(e,t,i,n){let s=new Map(e.readState().map(e=>[e.id,e])),r=[];for(let e of i){let i=s.get(e);if(!i)continue;let o=t.add(i);o&&(r.push(e),n.emit({type:"physics-sediment",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:e,datum:i.datum,x:i.x,y:i.y,binId:o.id,count:o.count,total:o.total}))}return r}function jn(e,t,i,n,s,r){let o={evicted:[],sedimented:[],liveBodyOrder:s};if(!1===i)return o;let a=Math.max(0,Math.floor(n));if(!Number.isFinite(a))return o;let l=s.length-a;if(l<=0)return o;let h=Rn(e,i,s).slice(0,l);if(0===h.length)return o;let d=Xn(e,t,h,r);e.remove(h);let u=new Set(h);return{evicted:h,sedimented:d,liveBodyOrder:s.filter(e=>!u.has(e))}}function Wn(e){let t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}var zn=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=Wn(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,i){if(i>0)return void(this.seconds=0);if(e.allSleeping())return void(this.seconds+=Math.max(0,t));let n=e.readState(this.scratch),s=this.speed*this.speed,r=!0;for(let e of n){if(e.sleeping)continue;let i=e.x-e.prevX,n=e.y-e.prevY;if(e.vx*e.vx+e.vy*e.vy>=s||t>0&&i*i+n*n>=s*t*t){r=!1;break}}this.seconds=r?this.seconds+Math.max(0,t):0}};function Gn(e,t,i=!1){if(!e)return;let n=["spawned","evicted","sedimented","events","observations"],s={spawned:0,evicted:0,sedimented:0,events:0,observations:0},r=r=>{let o=t(r),a={...o};n.forEach(e=>{a[e]=o[e].slice(s[e]),s[e]=o[e].length}),(0!==r||i||!n.every(e=>0===a[e].length))&&e.onStep(a)};return r(0),()=>r(1)}function Vn(e,t,i,n={}){let s,r=0,o=0,a=t+(n.drainArrivals?Math.max(0,Math.ceil(((e.lastArrival()??e.elapsed())-e.elapsed())/e.fixedDt)):0);for(;r+o<a&&!n.shouldStop?.()&&(!1===n.stopAtRest||e.queueSize()>0||!e.atRest()||n.continueWhile?.());){let t=e.nextArrival(),l=n.skipIdle&&null!=t&&e.atRest()?Math.min(Math.max(0,Math.floor((t-e.elapsed())/e.fixedDt)-1),Math.max(0,a-r-o-1)):0;l>0&&(e.advanceTime(l*e.fixedDt),o+=l),e.step(e.fixedDt),e.advanceTime(e.fixedDt);let h=e.drainEvents();i.events&&(i.events.push(...h),e.observeKernelEvents(h,i.observations),e.observeSensorTransitions(i.observations));let d=[];if(e.spawnDue(d,i.observations),d.length>0){i.spawned.push(...d),s=e.observeBodyBudget(i.observations);let t=e.evictOverflow(i.observations);i.evicted?.push(...t.evicted),i.sedimented?.push(...t.sedimented)}r+=1,e.refreshQuiescence(e.fixedDt,d.length),n.afterStep?.()}return{steps:r,budget:s}}var _n=class{constructor(e={}){this.activeSensorPairs=/* @__PURE__ */new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new bn,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.observedInitialBoundary=!1,this.updateResults=new gn,this.simulationState="settled",this.visible=!0,this.quiescence=new zn;let{bodyBudget:t,colliders:i,engine:n,kernel:s,observation:r,sediment:o,...a}=e;this.config={...zi,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=n,this.observation=Vi(r),this.sediment=new ji(o??!1),this.world=un(n,{fixedDt:this.config.fixedDt,...s}),this.quiescence.setKernelOptions(s),i&&this.world.setColliders(Ji(i))}updateConfig(e){let t=Pn(e,this.configInput),{colliders:i,bodyBudget:n,engine:s,kernel:r,observation:o,sediment:a,...l}=e;if(this.config={...this.config,...l},void 0!==n&&(this.bodyBudget=n,!1===n&&(this.bodyBudgetObservationKey="ok")),s&&s!==this.engineInput){let e=this.world.snapshot();this.world.dispose(),this.engineInput=s,this.world=un(s,e.options),this.world.restore(e),this.revision+=1}if(r&&!Nn(r,this.configInput.kernel)){let e=this.world.snapshot(),t={...e.options,...r,gravity:{...e.options.gravity,...r.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}o&&(this.observation=Vi(o,this.observation)),this.sediment.updateConfig(a),i&&(this.world.setColliders(Ji(i)),this.revision+=1),this.configInput={...this.configInput,...e};let h=Tn(t);this.updateResults.record({kind:"config",keys:t},h.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Ji(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Tn(["colliders"]).invalidations)}enqueue(e,t){let i=Array.isArray(e)?e:[e],n=t?Qi(i,{...t,startAt:t.startAt??this.elapsedSeconds}):i;for(let e of n)this.queue.push({..._i(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(tn),n.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:n.length},n.length?wn:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(_i(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},wn)}materializeDueSpawns(){let e=this.revision,t=[],i=[];return this.spawnDue(t,i),0===t.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?wn:[])),t}clear(){this.observedInitialBoundary=!1;let 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.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},wn)}tick(e,t){let i=this.revision,n=[],s=[],r=[],o=[],a=[];if(this.paused||!this.visible){let e=this.result(0,n,s,r,o,a,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}let l=Math.max(0,Math.min(Number.isFinite(e)?e:0,this.config.maxDeltaSeconds))*this.config.timeScale;this.spawnDue(n,a);let h=this.observeBodyBudget(a),d=this.evictOverflow(a);s.push(...d.evicted),r.push(...d.sedimented),this.syncSimulationState(a),n.length>0&&this.quiescence.reset(),this.accumulator+=l;let u=this.stepObserver(t,{spawned:n,evicted:s,sedimented:r,events:o,observations:a}),c=l>0?Math.floor((this.accumulator+1e-9*this.config.fixedDt)/this.config.fixedDt):0,{steps:p,budget:f}=Vn(this.settleHost(),Math.min(c,this.config.maxSubsteps),{spawned:n,evicted:s,sedimented:r,events:o,observations:a},{stopAtRest:!1,shouldStop:()=>this.paused||!this.visible,afterStep:u});this.accumulator=Math.max(0,this.accumulator-p*this.config.fixedDt),p===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(p>0||n.length>0||s.length>0||r.length>0||o.length>0)&&(this.revision+=1);let y=this.result(p,n,s,r,o,a,void 0,f??h);return this.updateResults.record({kind:"tick",count:p},this.revision!==i?n.length||s.length||r.length?wn:Sn:[]),y}settle(e){return this.runSettle(e,!1).steps}settleWithObservations(e,t){return this.runSettle(e,!0,t)}stepObserver(e,t){let i=!this.observedInitialBoundary;return e&&(this.observedInitialBoundary=!0),Gn(e,e=>(e&&(this.revision+=1),this.result(e,t.spawned,t.evicted,t.sedimented,t.events,t.observations)),i)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),elapsed:()=>this.elapsedSeconds,nextArrival:()=>this.queue[0]?.spawnAt,lastArrival:()=>this.queue.at(-1)?.spawnAt,advanceTime:e=>{this.elapsedSeconds+=e},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>this.observeKernelEvents(e,t),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t,i){let n=this.revision,s=[],r=[],o=[],a=[],l=t?[]:void 0;if(t&&(this.paused||!this.visible)){let e=this.result(0,s,r,o,a,l??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(s,l);let h=this.observeBodyBudget(l),d=this.evictOverflow(l);r.push(...d.evicted),o.push(...d.sedimented),this.syncSimulationState(l),s.length>0&&this.quiescence.reset();let u=t?{spawned:s,evicted:r,sedimented:o,events:a,observations:l}:{spawned:s},c=this.stepObserver(i,{spawned:s,evicted:r,sedimented:o,events:a,observations:l??[]}),{steps:p,budget:f}=Vn(this.settleHost(),e??this.config.settleStepLimit,u,{afterStep:c,continueWhile:i?.continueWhile,shouldStop:t?()=>this.paused||!this.visible:void 0,drainArrivals:void 0===e,skipIdle:void 0===e&&!i}),y=s.length+r.length+o.length>0;(p>0||y||a.length>0)&&(this.revision+=1);let m=this.result(p,s,r,o,a,l??[],void 0,f??h);return this.updateResults.record({kind:"settle",count:p},this.revision===n?[]:y?wn:Sn),m}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return Wi(this.readSediment(),e)}hitTest(e,t,i=0,n){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,i,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){let{timestamp:t,chartType:i,chartId:n,...s}=e,r={...s,timestamp:t??this.elapsedSeconds,chartType:i??this.observation.chartType,chartId:n??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){let t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?Mn:[])}setVisible(e){let t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?Mn:[])}remove(e){let t=new Set(e),i=new Set(this.liveBodyOrder),n=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);let s=e.filter(e=>i.has(e)||n.has(e));return s.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:s,count:s.length},s.length?wn:[]),s}setConstraint(e){let t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Sn),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Sn)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},Sn)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,i,n)=>e.applyImpulse(t,i,n),clear:()=>e.clear(),hitTest:(t,i,n)=>e.hitTest(t,i,n),pause:()=>e.setPaused(!0),push:(t,i)=>e.enqueue(t,i),pushMany:(t,i)=>e.enqueue(t,i),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(){let e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:en(this.bodyBudget),config:{...this.config,kernel:nn(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Zi),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.observedInitialBoundary=!1;let t=this.simulationState;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:en(e.bodyBudget??{}),kernel:nn(e.world.options)},this.bodyBudget=en(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(Zi).sort(tn),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??Yn(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"},wn),this.simulationState!==t&&this.observation.onSimulationStateChange?.(this.simulationState,t)}spawnDue(e,t){for(;this.queue.length>0&&this.queue[0].spawnAt<=this.elapsedSeconds+1e-9*this.config.fixedDt;){let i=this.queue.shift();if(!i)return;this.spawnOne(i,t),e.push(i.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(/* @__PURE__ */new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(let t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});if(!t&&!this.observation.onObservation)return;let i=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:i?.datum??e.datum,x:i?.x??e.x,y:i?.y??e.y},t)}result(e,t,i,n,s,r,o,a=this.evaluateBodyBudget()){this.syncSimulationState(r);let l=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:i,events:s,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:o??(!this.paused&&this.visible&&(this.queue.length>0||!this.atRest())),sleeping:l,sedimented:n,spawned:t,steps:e}}observeKernelEvents(e,t){qn(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=Fn(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){Dn(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 fn({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){let t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;let i=`${t.state}:${t.action}`;return i===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=i,Ln(t,this.observationContext(e))),t}syncSimulationState(e){let t=Yn(this.paused,this.visible,this.queue.length>0,this.atRest());if(t===this.simulationState)return;let i=this.simulationState;this.simulationState=t,En(i,t,this.observationContext(e))}evictOverflow(e){let{evicted:t,sedimented:i,liveBodyOrder:n}=jn(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=n,this.removeActiveSensorPairsForBodies(new Set(t))),{evicted:t,sedimented:i}}};export{zt as a,gn as b,i as c,M as d,I as e,k as f,p as g,f as h,w as i,S as j,o as k,n as l,a as m,d as n,c as o,K as p,Gt as q,Vt as r,J as s,ne as t,se as u,re as v,oe as w,ae as x,le as y,he as z,de as A,ue as B,ce as C,pe as D,fe as E,ye as F,me as G,xe as H,ge as I,ve as J,Se as K,Me as L,Ie as M,ke as N,Be as O,Oe as P,Ae as Q,Ce as R,Bi as S,Ai as T,Wi as U,an as V,ln as W,_n as X,qe as Y,Fe as Z,De as _,Re as $,We as aa,ze as ba,Ge as ca,Ve as da,_e as ea,He as fa,Ue as ga,Ke as ha,Qe as ia,Ze as ja,Je as ka,ht as la,vt as ma,bt as na,wt as oa,St as pa,Pt as qa,Ft as ra,Dt as sa,Yt as ta,Et as ua,Lt as va};