semiotic 3.8.5 → 3.8.7

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 (277) hide show
  1. package/CLAUDE.md +37 -10
  2. package/README.md +83 -56
  3. package/ai/behaviorContracts.cjs +88 -3
  4. package/ai/componentMetadata.cjs +5 -10
  5. package/ai/dist/mcp-server.js +99 -10
  6. package/ai/examples.md +198 -9
  7. package/ai/schema.json +2002 -165
  8. package/ai/surface-manifest.json +14 -10
  9. package/ai/system-prompt.md +9 -3
  10. package/dist/{chunk-chartContainerDataAudit-74TLKIP6.module.min.js → chunk-chartContainerDataAudit-JDSVSKGM.module.min.js} +1 -1
  11. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +1 -0
  12. package/dist/chunk-chunk-2YAZHXL4.module.min.js +2 -0
  13. package/dist/chunk-chunk-3NGIKFD6.module.min.js +1 -0
  14. package/dist/{chunk-chunk-G7WFWHAD.module.min.js → chunk-chunk-4ITOQRXM.module.min.js} +1 -1
  15. package/dist/chunk-chunk-5SD6BHVW.module.min.js +2 -0
  16. package/dist/chunk-chunk-6V5VQVCT.module.min.js +2 -0
  17. package/dist/chunk-chunk-7TTBHSAG.module.min.js +2 -0
  18. package/dist/chunk-chunk-7ZDJSYKI.module.min.js +2 -0
  19. package/dist/chunk-chunk-BGHPD3RA.module.min.js +1 -0
  20. package/dist/chunk-chunk-BMRZ2SPU.module.min.js +2 -0
  21. package/dist/chunk-chunk-BNGBEY7N.module.min.js +2 -0
  22. package/dist/chunk-chunk-C7APLVQD.module.min.js +2 -0
  23. package/dist/chunk-chunk-DGWFBOGB.module.min.js +1 -0
  24. package/dist/chunk-chunk-DIVE2DRA.module.min.js +2 -0
  25. package/dist/chunk-chunk-FBUNUIPV.module.min.js +2 -0
  26. package/dist/chunk-chunk-FQPKOAIH.module.min.js +2 -0
  27. package/dist/chunk-chunk-FRO4TRXK.module.min.js +2 -0
  28. package/dist/chunk-chunk-G7QVPZUD.module.min.js +2 -0
  29. package/dist/chunk-chunk-GBPYV4FP.module.min.js +2 -0
  30. package/dist/chunk-chunk-GU2EJIDJ.module.min.js +2 -0
  31. package/dist/chunk-chunk-J5QD4RAM.module.min.js +2 -0
  32. package/dist/{chunk-chunk-LJLS6DY7.module.min.js → chunk-chunk-JWXLNZSM.module.min.js} +1 -1
  33. package/dist/chunk-chunk-KXAFCCDB.module.min.js +2 -0
  34. package/dist/chunk-chunk-LG7YKJAK.module.min.js +2 -0
  35. package/dist/{chunk-chunk-I36PJ4OC.module.min.js → chunk-chunk-LVHDZAT3.module.min.js} +1 -1
  36. package/dist/chunk-chunk-LWITSR2O.module.min.js +2 -0
  37. package/dist/chunk-chunk-MX35T6RX.module.min.js +2 -0
  38. package/dist/chunk-chunk-NH4MEAKP.module.min.js +2 -0
  39. package/dist/chunk-chunk-NJETWX42.module.min.js +2 -0
  40. package/dist/chunk-chunk-NW25WGLS.module.min.js +2 -0
  41. package/dist/{chunk-chunk-TMWIZL3K.module.min.js → chunk-chunk-OI7R7EJB.module.min.js} +1 -1
  42. package/dist/chunk-chunk-ONMLEXHR.module.min.js +2 -0
  43. package/dist/chunk-chunk-OY66GCE6.module.min.js +1 -0
  44. package/dist/chunk-chunk-PZFT457G.module.min.js +1 -0
  45. package/dist/chunk-chunk-Q3WW6JGR.module.min.js +1 -0
  46. package/dist/chunk-chunk-Q6XKQTOQ.module.min.js +1 -0
  47. package/dist/chunk-chunk-RJRM2E6P.module.min.js +1 -0
  48. package/dist/chunk-chunk-RPL7WYXI.module.min.js +1 -0
  49. package/dist/chunk-chunk-SV4XAZ3Q.module.min.js +1 -0
  50. package/dist/chunk-chunk-TSCFL235.module.min.js +1 -0
  51. package/dist/chunk-chunk-UOQRPGPK.module.min.js +2 -0
  52. package/dist/chunk-chunk-V3OAKG32.module.min.js +1 -0
  53. package/dist/chunk-chunk-WLOIUMWG.module.min.js +2 -0
  54. package/dist/chunk-chunk-XEGXX4F7.module.min.js +1 -0
  55. package/dist/chunk-chunk-XFRBLXYM.module.min.js +1 -0
  56. package/dist/chunk-chunk-Z2AJERX5.module.min.js +2 -0
  57. package/dist/chunk-chunk-ZXYDYAB7.module.min.js +2 -0
  58. package/dist/components/ai/SemioticVACPBridge.d.ts +22 -0
  59. package/dist/components/ai/chartCapabilities.d.ts +5 -3
  60. package/dist/components/ai/conversationArc.d.ts +2 -176
  61. package/dist/components/ai/conversationArcTypes.d.ts +202 -0
  62. package/dist/components/ai/readerGrounding.d.ts +12 -0
  63. package/dist/components/ai/vacpAdapter.d.ts +13 -0
  64. package/dist/components/ai/vacpAdapterActions.d.ts +2 -0
  65. package/dist/components/ai/vacpAdapterModel.d.ts +7 -0
  66. package/dist/components/ai/vacpAdapterRuntime.d.ts +26 -0
  67. package/dist/components/ai/vacpAdapterState.d.ts +3 -0
  68. package/dist/components/ai/vacpAdapterTypes.d.ts +169 -0
  69. package/dist/components/ai/vacpTypes.d.ts +160 -0
  70. package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
  71. package/dist/components/charts/geo/DistanceCartogram.d.ts +1 -1
  72. package/dist/components/charts/index.d.ts +7 -4
  73. package/dist/components/charts/ordinal/BarChart.d.ts +7 -14
  74. package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
  75. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -0
  76. package/dist/components/charts/ordinal/StackedBarChart.d.ts +3 -0
  77. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +4 -14
  78. package/dist/components/charts/physics/ChainReactionChart.capability.d.ts +9 -0
  79. package/dist/components/charts/physics/ChainReactionChart.d.ts +29 -0
  80. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +1 -1
  81. package/dist/components/charts/physics/EventDropChart.d.ts +7 -2
  82. package/dist/components/charts/physics/GaltonBoardChart.d.ts +1 -1
  83. package/dist/components/charts/physics/{PhysicsPileChart.capability.d.ts → PacketFlowChart.capability.d.ts} +1 -1
  84. package/dist/components/charts/physics/{PhysicalFlowChart.d.ts → PacketFlowChart.d.ts} +22 -6
  85. package/dist/components/charts/physics/PhysicsCustomChart.d.ts +1 -1
  86. package/dist/components/charts/physics/ProcessFlowChart.d.ts +7 -4
  87. package/dist/components/charts/physics/{PhysicalFlowChart.capability.d.ts → UnitPileChart.capability.d.ts} +1 -1
  88. package/dist/components/charts/physics/{PhysicsPileChart.d.ts → UnitPileChart.d.ts} +19 -6
  89. package/dist/components/charts/physics/crucibleChartProps.d.ts +1 -1
  90. package/dist/components/charts/physics/crucibleChartUtils.d.ts +9 -0
  91. package/dist/components/charts/physics/gauntletChartProps.d.ts +6 -1
  92. package/dist/components/charts/physics/gauntletTerminal.d.ts +61 -0
  93. package/dist/components/charts/physics/packetFlowSemantics.d.ts +6 -0
  94. package/dist/components/charts/physics/physicsHocUtils.d.ts +45 -2
  95. package/dist/components/charts/shared/auditAccessibilityStyles.d.ts +9 -0
  96. package/dist/components/charts/shared/chartSpecCore.d.ts +2 -4
  97. package/dist/components/charts/shared/gaugeGradient.d.ts +4 -8
  98. package/dist/components/charts/shared/gradient.d.ts +35 -0
  99. package/dist/components/charts/shared/hatchFill.d.ts +3 -10
  100. package/dist/components/charts/shared/hooks.d.ts +2 -50
  101. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  102. package/dist/components/charts/shared/streamPropsHelpers.d.ts +1 -2
  103. package/dist/components/charts/shared/useChartLegend.d.ts +65 -0
  104. package/dist/components/charts/shared/useChartSetup.d.ts +12 -0
  105. package/dist/components/charts/shared/useCustomChartSetup.d.ts +6 -1
  106. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +1 -0
  107. package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
  108. package/dist/components/charts/xy/AreaChart.d.ts +25 -42
  109. package/dist/components/charts/xy/BumpChart.capability.d.ts +11 -0
  110. package/dist/components/charts/xy/BumpChart.d.ts +161 -0
  111. package/dist/components/charts/xy/DifferenceChart.d.ts +3 -10
  112. package/dist/components/charts/xy/Heatmap.d.ts +3 -0
  113. package/dist/components/charts/xy/LineChart.d.ts +6 -8
  114. package/dist/components/data/portability/capabilityBinding.d.ts +41 -0
  115. package/dist/components/data/portability/index.d.ts +2 -0
  116. package/dist/components/geometry/bumpRibbonGeometry.d.ts +36 -0
  117. package/dist/components/legendLayout.d.ts +75 -1
  118. package/dist/components/recipes/geographicDotGrid.d.ts +82 -0
  119. package/dist/components/recipes/geographicGrid.d.ts +100 -0
  120. package/dist/components/recipes/physics.d.ts +2 -0
  121. package/dist/components/recipes/physicsStageGeography.d.ts +137 -0
  122. package/dist/components/semiotic-ai.d.ts +6 -4
  123. package/dist/components/semiotic-experimental-vacp.d.ts +11 -0
  124. package/dist/components/semiotic-experimental.d.ts +6 -3
  125. package/dist/components/semiotic-geo.d.ts +5 -0
  126. package/dist/components/semiotic-network.d.ts +1 -0
  127. package/dist/components/semiotic-ordinal.d.ts +2 -0
  128. package/dist/components/semiotic-physics.d.ts +10 -6
  129. package/dist/components/semiotic-realtime-core.d.ts +1 -0
  130. package/dist/components/semiotic-recipes-core.d.ts +6 -1
  131. package/dist/components/semiotic-server-edge.d.ts +1 -1
  132. package/dist/components/semiotic-server.d.ts +1 -1
  133. package/dist/components/semiotic-xy.d.ts +4 -0
  134. package/dist/components/semiotic.d.ts +4 -4
  135. package/dist/components/server/renderEvidence.d.ts +1 -1
  136. package/dist/components/server/renderToStaticSVG.d.ts +2 -1
  137. package/dist/components/server/serverChartConfigHeatmap.d.ts +6 -0
  138. package/dist/components/server/serverChartConfigNetworkStyles.d.ts +12 -0
  139. package/dist/components/server/serverChartConfigShared.d.ts +16 -0
  140. package/dist/components/server/serverChartConfigs.d.ts +3 -2
  141. package/dist/components/server/serverChartConfigsPhysics.d.ts +2 -2
  142. package/dist/components/server/serverChartConfigsXY.d.ts +1 -1
  143. package/dist/components/server/staticLegend.d.ts +10 -2
  144. package/dist/components/server/staticSVGChrome.d.ts +14 -6
  145. package/dist/components/server/staticValue.d.ts +8 -0
  146. package/dist/components/stream/GeoSVGOverlay.d.ts +4 -10
  147. package/dist/components/stream/NetworkSVGOverlay.d.ts +2 -6
  148. package/dist/components/stream/OrdinalSVGOverlay.d.ts +2 -6
  149. package/dist/components/stream/SVGOverlay.d.ts +2 -6
  150. package/dist/components/stream/StalenessBadge.d.ts +2 -6
  151. package/dist/components/stream/geoPipelineConfig.d.ts +10 -0
  152. package/dist/components/stream/geoTypes.d.ts +3 -6
  153. package/dist/components/stream/legendRenderer.d.ts +10 -6
  154. package/dist/components/stream/ordinalTypes.d.ts +7 -31
  155. package/dist/components/stream/physics/PhysicsEvidence.d.ts +37 -0
  156. package/dist/components/stream/physics/PhysicsKernel.d.ts +1 -0
  157. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +9 -0
  158. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +2 -6
  159. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +5 -0
  160. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +2 -6
  161. package/dist/components/stream/physics/physicsFramePipelineConfig.d.ts +19 -0
  162. package/dist/components/stream/physics/physicsPipelineSettle.d.ts +52 -0
  163. package/dist/components/stream/physics/physicsRegionRuntime.d.ts +23 -0
  164. package/dist/components/stream/pipelineConfig.d.ts +7 -15
  165. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +9 -69
  166. package/dist/components/stream/renderers/cornerRadii.d.ts +2 -9
  167. package/dist/components/stream/renderers/thresholdLineSegments.d.ts +12 -0
  168. package/dist/components/stream/sceneToSVGShared.d.ts +3 -5
  169. package/dist/components/stream/types.d.ts +34 -56
  170. package/dist/components/stream/xySceneBuilders/areaGradient.d.ts +4 -20
  171. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -6
  172. package/dist/components/types/legendTypes.d.ts +31 -6
  173. package/dist/controls.min.js +1 -1
  174. package/dist/controls.module.min.js +1 -1
  175. package/dist/geo.min.js +1 -1
  176. package/dist/geo.module.min.js +1 -1
  177. package/dist/network.min.js +1 -1
  178. package/dist/network.module.min.js +1 -1
  179. package/dist/ordinal.min.js +1 -1
  180. package/dist/ordinal.module.min.js +1 -1
  181. package/dist/physics.min.js +1 -1
  182. package/dist/physics.module.min.js +1 -1
  183. package/dist/physicsWorker.js +1 -1
  184. package/dist/realtime.min.js +1 -1
  185. package/dist/realtime.module.min.js +1 -1
  186. package/dist/semiotic-ai-core.min.js +1 -1
  187. package/dist/semiotic-ai-core.module.min.js +1 -1
  188. package/dist/semiotic-ai.d.ts +6 -4
  189. package/dist/semiotic-ai.min.js +1 -1
  190. package/dist/semiotic-ai.module.min.js +1 -1
  191. package/dist/semiotic-data.module.min.js +1 -1
  192. package/dist/semiotic-experimental-vacp.d.ts +11 -0
  193. package/dist/semiotic-experimental-vacp.min.js +1 -0
  194. package/dist/semiotic-experimental-vacp.module.min.js +1 -0
  195. package/dist/semiotic-experimental.d.ts +6 -3
  196. package/dist/semiotic-experimental.min.js +2 -1
  197. package/dist/semiotic-experimental.module.min.js +2 -1
  198. package/dist/semiotic-geo.d.ts +5 -0
  199. package/dist/semiotic-network.d.ts +1 -0
  200. package/dist/semiotic-ordinal.d.ts +2 -0
  201. package/dist/semiotic-physics.d.ts +10 -6
  202. package/dist/semiotic-realtime-core.d.ts +1 -0
  203. package/dist/semiotic-realtime-core.min.js +1 -1
  204. package/dist/semiotic-realtime-core.module.min.js +1 -1
  205. package/dist/semiotic-recipes-core.d.ts +6 -1
  206. package/dist/semiotic-recipes-core.min.js +1 -1
  207. package/dist/semiotic-recipes-core.module.min.js +1 -1
  208. package/dist/semiotic-recipes.min.js +1 -1
  209. package/dist/semiotic-recipes.module.min.js +1 -1
  210. package/dist/semiotic-server-edge.d.ts +1 -1
  211. package/dist/semiotic-server-edge.min.js +1 -1
  212. package/dist/semiotic-server-edge.module.min.js +1 -1
  213. package/dist/semiotic-server-node.min.js +1 -1
  214. package/dist/semiotic-server-node.module.min.js +1 -1
  215. package/dist/semiotic-server.d.ts +1 -1
  216. package/dist/semiotic-utils-core.min.js +1 -1
  217. package/dist/semiotic-utils-core.module.min.js +1 -1
  218. package/dist/semiotic-utils.min.js +1 -1
  219. package/dist/semiotic-utils.module.min.js +1 -1
  220. package/dist/semiotic-xy.d.ts +4 -0
  221. package/dist/semiotic.d.ts +4 -4
  222. package/dist/semiotic.min.js +1 -1
  223. package/dist/semiotic.module.min.js +1 -1
  224. package/dist/server.min.js +1 -1
  225. package/dist/server.module.min.js +1 -1
  226. package/dist/xy.min.js +1 -1
  227. package/dist/xy.module.min.js +1 -1
  228. package/package.json +18 -2
  229. package/spec/README.md +94 -2
  230. package/spec/bindings/README.md +14 -3
  231. package/spec/v0.1/examples/annotation-provenance-reviewed-revision.json +27 -0
  232. package/spec/v0.1/examples/annotation-provenance-watcher-threshold.json +21 -0
  233. package/spec/v0.1/examples/audience-profile-executive-review.json +24 -0
  234. package/spec/v0.1/examples/audience-profile-incident-operators.json +42 -0
  235. package/spec/v0.1/examples/chart-capability-bar-comparison.json +48 -0
  236. package/spec/v0.1/examples/chart-capability-service-flow.json +54 -0
  237. package/dist/chunk-chunk-4AANPFOX.module.min.js +0 -2
  238. package/dist/chunk-chunk-5I3UZV4Q.module.min.js +0 -2
  239. package/dist/chunk-chunk-5RKXZQ2P.module.min.js +0 -1
  240. package/dist/chunk-chunk-74CCPVXB.module.min.js +0 -1
  241. package/dist/chunk-chunk-7ALTGHK6.module.min.js +0 -1
  242. package/dist/chunk-chunk-ANYDWOZF.module.min.js +0 -1
  243. package/dist/chunk-chunk-AVBI6GDT.module.min.js +0 -1
  244. package/dist/chunk-chunk-BANTPINB.module.min.js +0 -2
  245. package/dist/chunk-chunk-C4YA6TDR.module.min.js +0 -1
  246. package/dist/chunk-chunk-C57LR3YG.module.min.js +0 -1
  247. package/dist/chunk-chunk-CKMD5NV3.module.min.js +0 -2
  248. package/dist/chunk-chunk-CO5KQMGH.module.min.js +0 -1
  249. package/dist/chunk-chunk-CWQ5YIHX.module.min.js +0 -2
  250. package/dist/chunk-chunk-E6TXX6MI.module.min.js +0 -1
  251. package/dist/chunk-chunk-GMQ5AYTD.module.min.js +0 -1
  252. package/dist/chunk-chunk-JCG72SGW.module.min.js +0 -2
  253. package/dist/chunk-chunk-K3DMEW22.module.min.js +0 -1
  254. package/dist/chunk-chunk-KT2VAZMZ.module.min.js +0 -1
  255. package/dist/chunk-chunk-L6EA5V3G.module.min.js +0 -2
  256. package/dist/chunk-chunk-LJPCLYSC.module.min.js +0 -2
  257. package/dist/chunk-chunk-LRIFN2HK.module.min.js +0 -1
  258. package/dist/chunk-chunk-N5DDKCCF.module.min.js +0 -1
  259. package/dist/chunk-chunk-NEVE562N.module.min.js +0 -1
  260. package/dist/chunk-chunk-NLO44TOS.module.min.js +0 -2
  261. package/dist/chunk-chunk-PZJ2SBLL.module.min.js +0 -2
  262. package/dist/chunk-chunk-QSQVBIJA.module.min.js +0 -1
  263. package/dist/chunk-chunk-QUJ6TTLY.module.min.js +0 -1
  264. package/dist/chunk-chunk-RBIDBUT4.module.min.js +0 -2
  265. package/dist/chunk-chunk-RCF52Z42.module.min.js +0 -2
  266. package/dist/chunk-chunk-RFLAG356.module.min.js +0 -1
  267. package/dist/chunk-chunk-RPU4IZAV.module.min.js +0 -2
  268. package/dist/chunk-chunk-SKMBCFIL.module.min.js +0 -2
  269. package/dist/chunk-chunk-TAE7W424.module.min.js +0 -2
  270. package/dist/chunk-chunk-TUBMTZMU.module.min.js +0 -2
  271. package/dist/chunk-chunk-UFFEXJQY.module.min.js +0 -1
  272. package/dist/chunk-chunk-XSCHTS4D.module.min.js +0 -2
  273. package/dist/chunk-chunk-XXWSHGPL.module.min.js +0 -2
  274. package/dist/chunk-chunk-ZOAQDIJO.module.min.js +0 -1
  275. package/dist/chunk-chunk-ZXIXAPRE.module.min.js +0 -2
  276. package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +0 -1
  277. package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +0 -1
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{opacityFromAge as t}from"./chunk-chunk-5SD6BHVW.module.min.js";import{bandFromAge as e,defaultTooltipStyle as n,normalizeTooltip as r,resolveCanvasFill as o}from"./chunk-chunk-7ZDJSYKI.module.min.js";import{drawGlyphParts as a,glyphFractionClipRect as s,glyphHitGeometry as l,glyphPlacement as i}from"./chunk-chunk-KTWEBFMX.module.min.js";import{jsx as c,jsxs as u}from"react/jsx-runtime";function f(t){return"string"==typeof t?t:"value"}function h(t){return null==t?"–":"number"==typeof t?Math.abs(t)>9999?t.toLocaleString():t+"":t instanceof Date?t.toLocaleDateString():t+""}function d(t,e){if(!e)return h(t);try{const n=e(t);return null==n?h(t):n}catch{return h(t)}}function p(t,e){return"function"==typeof e?e(t):t[e]}function y(t,e){if(!t)return[];const n=[];return(Array.isArray(t)?t:[t]).forEach((t,r)=>{const o="string"==typeof t?.y0Accessor?t.y0Accessor:"low",a="string"==typeof t?.y1Accessor?t.y1Accessor:"high";n.push({label:o,accessor:t=>t.bands?.[r]?.y0??(0===r?t.band?.y0:void 0),format:e}),n.push({label:a,accessor:t=>t.bands?.[r]?.y1??(0===r?t.band?.y1:void 0),format:e})}),n}function g(t){const e=t.find(t=>"title"===t.role),r=t.filter(t=>"title"!==t.role);return t=>{const o=t.data;if(!o)return null;const a=e?d(p(o,e.accessor),e.format):null;return u("div",{className:"semiotic-tooltip",style:n,children:[null!=a&&c("div",{style:{fontWeight:"bold",marginBottom:r.length>0?4:0},children:a}),r.map((t,e)=>{const n=d(p(o,t.accessor),t.format);return u("div",{style:e>0?{marginTop:2}:void 0,children:[u("span",{style:{opacity:.7},children:[t.label,": "]}),c("span",{children:n})]},e)})]})}}function m({categoryAccessor:t,valueAccessor:e,groupAccessor:r,groupLabel:o,pieData:a=!1,valueFormat:s}){return l=>{const i=a?l.data?.[0]||l.data||l:l.data||l,y=p(i,t),g=p(i,e),m=r?p(i,r):void 0;return u("div",{className:"semiotic-tooltip",style:n,children:[c("div",{style:{fontWeight:"bold"},children:h(y)}),c("div",{style:{marginTop:4},children:d(g,s)}),null!=m&&u("div",{style:{marginTop:2,opacity:.8},children:[o||f(r),": ",h(m)]})]})}}import*as x from"react";function b(...t){const e=t.filter(t=>null!=t);return 0===e.length?null:1===e.length?e[0]:x.createElement(x.Fragment,null,...e)}import{useEffect as v,useRef as w}from"react";function A(t,e,n,r){v(()=>{t.current?.updateConfig(e),n.current=!0,r()},[e,r,t,n])}function k(t,e,n,r){const o=w(null);v(()=>{const a=t.current;if(!a)return;const s=e??null;o.current!==s&&(o.current=s,a.setLayoutSelection(s),a.hasCustomRestyle?a.restyleScene(s):n.current=!0,r())},[e,r,t,n])}var _={fresh:1,aging:.7,stale:.45,expired:.25},I={alpha:1,band:"fresh",isStale:!1};function M(t,n){if(!t||0>=n)return I;const r=null!=t.threshold&&t.threshold>0?t.threshold:5e3,o=t.graded;if(o){const t="object"==typeof o?o:{},a=e(n,r,t.thresholds);return{alpha:{..._,...t.opacities??{}}[a],band:a,isStale:"fresh"!==a}}return n>r?{alpha:t.dimOpacity??.5,band:"stale",isStale:!0}:I}import{useEffect as S,useRef as O}from"react";function D(t,e,n,r,o,a){const s=O("fresh");S(()=>{if(!t)return;const l=setInterval(()=>{const l=e.current;if(!l||0===l.lastIngestTime)return;const i="undefined"!=typeof performance?performance.now():Date.now(),c=M(t,i-l.lastIngestTime);c.band===s.current&&c.isStale===o||(s.current=c.band,c.isStale!==o&&a(c.isStale),n.current=!0,r())},1e3);return()=>clearInterval(l)},[t,o,r,e,a,n])}import{jsx as R}from"react/jsx-runtime";function E({isStale:t,position:e}){return R("div",{className:"stream-staleness-badge",style:{position:"absolute",..."top-left"===e?{top:4,left:4}:"bottom-left"===e?{bottom:4,left:4}:"bottom-right"===e?{bottom:4,right:4}:{top:4,right:4},padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",zIndex:3,background:t?"#dc3545":"#28a745",color:"white"},children:t?"STALE":"LIVE"})}import{useRef as P}from"react";function j(t){const e=P(t);return function(t,e){if(Object.is(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return L(t,e);if(!T(t)||!T(e))return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){if(!Object.prototype.hasOwnProperty.call(e,r))return!1;const n=t[r],o=e[r];if(!Object.is(n,o))if(Array.isArray(n)&&Array.isArray(o)){if(!L(n,o))return!1}else{if(!T(n)||!T(o))return!1;if(!C(n,o))return!1}}return!0}(e.current,t)||(e.current=t),e.current}function C(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){if(!Object.prototype.hasOwnProperty.call(e,r))return!1;if(!Object.is(t[r],e[r]))return!1}return!0}function L(t,e){if(t.length!==e.length)return!1;for(let n=0;t.length>n;n++)if(!Object.is(t[n],e[n]))return!1;return!0}function T(t){if(null===t||"object"!=typeof t)return!1;if(Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function z(t,e,n,r,l){if(0>=e.size)return;const c=e.glyph;if(!c||!c.parts?.length)return;const u=i(c,e.size);if(0>=u.scale)return;const f=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=f)return;const h=e=>{const n=o(t,e,e);return"string"==typeof n?n:e},d=e.color??("string"==typeof e.style.fill?e.style.fill:void 0);t.save(),t.translate(n,r),e.rotation&&t.rotate(e.rotation),t.translate(u.offsetX,u.offsetY),t.scale(u.scale,u.scale),t.globalAlpha=l*f*(e.style.fillOpacity??1);const p=s(c,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");p&&e.ghostColor&&a(t,c,d,e.accent,e.ghostColor,h),p&&(t.beginPath(),t.rect(p.x,p.y,p.width,p.height),t.clip()),a(t,c,d,e.accent,void 0,h),t.restore()}var H=(t,e)=>{const n=t.globalAlpha;for(const r of e)"glyph"===r.type&&z(t,r,r.x,r.y,n);t.globalAlpha=n};function W(t,e){const n=t.globalAlpha;for(const r of e)"glyph"===r.type&&z(t,r,r.cx,r.cy,n);t.globalAlpha=n}var $=new Set;function B(t,e){const n="function"==typeof t?t(e.datum??null,e):t;return(r=n)&&"object"==typeof r&&"string"==typeof r.id&&"function"==typeof r.cacheKey&&"function"==typeof r.drawCanvas&&"function"==typeof r.renderStaticSVG?n:void 0;var r}function G(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const n=`${t}:${e}`;$.has(n)||($.add(n),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}function N(t){const{context:e,nodes:n,renderMode:r,pixelRatio:o,paintBuiltIn:a}=t;if(!r||"sketchy"===r)return void a(n);let s=[];const l=()=>{s.length&&(a(s),s=[])};for(const t of n){const n=B(r,t);if(!n){s.push(t);continue}let i;l(),e.save();try{i=n.drawCanvas({context:e,node:t,style:t.style??{},pixelRatio:o})}finally{e.restore()}i||(G(n.id,t.type??"unknown"),a([t]))}l()}function U(t){const{node:e,index:n,renderMode:r,fallback:o}=t,a=B(r,e);if(!a)return o();const s=a.renderStaticSVG({node:e,style:e.style??{},key:`${a.id}-${n}`});return null!=s?s:(G(a.id,e.type??"unknown"),o())}function V(t){const e=new Map;for(const n of t){const t=n.group??"_default";let r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}for(const t of e.values()){t.sort((t,e)=>t.x-e.x||t.y-e.y);for(let e=0;t.length>e;e++)t[e]._groupIndex=e}const n=Array.from(e.keys()).sort((t,n)=>{const r=e.get(t),o=e.get(n);return(r.length>0?r[0].y:0)-(o.length>0?o[0].y:0)}),r=Array.from(e.values()).flat();r.sort((t,e)=>t.x-e.x||t.y-e.y);const o=new Map;for(let t=0;r.length>t;t++){r[t]._flatIndex=t;const e=r[t].datum?.id;null!=e&&o.set(e+"",t)}return{flat:r,groups:n,byGroup:e,idToIdx:o}}function F(t,e){if(0===t.flat.length)return{flatIndex:-1,group:"_default",indexInGroup:-1};const n=Math.max(0,Math.min(e,t.flat.length-1)),r=t.flat[n];return{flatIndex:n,group:r.group??"_default",indexInGroup:r._groupIndex??0}}function Y(t,e,n){const{group:r,indexInGroup:o}=e,a=n.byGroup.get(r);switch(t){case"ArrowRight":return a.length-1>o?a[o+1]._flatIndex:e.flatIndex;case"ArrowLeft":return o>0?a[o-1]._flatIndex:e.flatIndex;case"ArrowDown":{const t=n.groups.indexOf(r);return n.groups.length-1>t?K(n,n.groups[t+1],a[o]):e.flatIndex}case"ArrowUp":{const t=n.groups.indexOf(r);return t>0?K(n,n.groups[t-1],a[o]):e.flatIndex}case"PageDown":return Math.min(e.flatIndex+Math.max(1,Math.floor(.1*n.flat.length)),n.flat.length-1);case"PageUp":return Math.max(e.flatIndex-Math.max(1,Math.floor(.1*n.flat.length)),0);case"Home":return 0;case"End":return n.flat.length-1;case"Escape":return-1;default:return null}}function K(t,e,n){const r=t.byGroup.get(e);let o=0,a=Math.abs(r[0].x-n.x);for(let t=1;r.length>t;t++){const e=Math.abs(r[t].x-n.x);a>e&&(a=e,o=t)}return r[o]._flatIndex}function X(t){const e=[];for(const n of t)switch(n.type){case"point":e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"symbol":if(0>=n.size)break;e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});break;case"glyph":{if(0>=n.size||null==n.datum)break;const t=l(n.glyph,n.size);e.push({x:n.x+t.centerDx,y:n.y+t.centerDy,datum:n.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:"_default"});break}case"line":{const t=n,r=Array.isArray(t.datum)?t.datum:[],o=t.group??"_default";for(let n=0;t.path.length>n&&r.length>n;n++)e.push({x:t.path[n][0],y:t.path[n][1],datum:r[n],shape:"circle",group:o});break}case"area":{const t=n,r=Array.isArray(t.datum)?t.datum:[],o=t.group??"_default";for(let n=0;t.topPath.length>n&&r.length>n;n++)e.push({x:t.topPath[n][0],y:t.topPath[n][1],datum:r[n],shape:"circle",group:o});break}case"rect":e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:n.group??"_default"});break;case"heatcell":e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}function q(t){const e=[];for(const n of t)if("rect"===n.type&&null!=n.x){if(null==n.datum)continue;e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:n.group??n.datum?.category??""})}else if("point"===n.type)e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"});else if("symbol"===n.type){if(0>=n.size)continue;e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle",group:"_default"})}else if("glyph"===n.type){if(0>=n.size||null==n.datum)continue;const t=l(n.glyph,n.size);e.push({x:n.x+t.centerDx,y:n.y+t.centerDy,datum:n.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:"_default"})}else if("wedge"===n.type&&null!=n.cx){if(null===n.datum)continue;const t=((n.startAngle||0)+(n.endAngle||0))/2,r=((n.innerRadius||0)+(n.outerRadius||50))/2;e.push({x:n.cx+Math.cos(t)*r,y:n.cy+Math.sin(t)*r,datum:n.datum,shape:"wedge",group:"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}function J(t){const e=[];for(const n of t)if("circle"===n.type&&null!=n.cx){if(0>=n.r)continue;e.push({x:n.cx,y:n.cy,datum:n.datum,shape:"circle",group:n.datum?.id??"_default"})}else if("rect"===n.type&&null!=n.x){if(0>=n.w||0>=n.h)continue;e.push({x:n.x+n.w/2,y:n.y+n.h/2,datum:n.datum,shape:"rect",w:n.w,h:n.h,group:n.datum?.id??"_default"})}else if("arc"===n.type&&null!=n.cx)e.push({x:n.cx,y:n.cy,datum:n.datum,shape:"circle",group:n.datum?.id??"_default"});else if("symbol"===n.type&&null!=n.cx){if(0>=n.size)continue;e.push({x:n.cx,y:n.cy,datum:n.datum,shape:"circle",group:n.datum?.id??"_default"})}else if("glyph"===n.type&&null!=n.cx){if(0>=n.size||null==n.datum)continue;const t=l(n.glyph,n.size);e.push({x:n.cx+t.centerDx,y:n.cy+t.centerDy,datum:n.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:n.datum?.id??"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}function Z(t,e,n,r,o){const a=n.flat[e.flatIndex];if(!a)return Y(t,e,n);const s=a.datum?.id;switch(t){case"ArrowRight":case"ArrowLeft":case"ArrowDown":case"ArrowUp":{const r=function(t,e,n){let r=null,o=1/0;for(let a=0;t.flat.length>a;a++){const s=t.flat[a];if(s===e)continue;const l=s.x-e.x,i=s.y-e.y;let c=!1;switch(n){case"right":c=l>0&&Math.abs(l)>=Math.abs(i);break;case"left":c=0>l&&Math.abs(l)>=Math.abs(i);break;case"down":c=i>0&&Math.abs(i)>=Math.abs(l);break;case"up":c=0>i&&Math.abs(i)>=Math.abs(l)}if(!c)continue;const u=l*l+i*i;o>u&&(o=u,r=a)}return r}(n,a,"ArrowRight"===t?"right":"ArrowLeft"===t?"left":"ArrowDown"===t?"down":"up")??e.flatIndex;return r!==e.flatIndex&&(o.current=-1),r}case"Enter":{if(null==s)return e.flatIndex;const t=function(t,e){const n=t+"",r=[];for(const t of e){const e=t.datum??t,o=Q(e.source),a=Q(e.target),s=null!=o,l=null!=a;s&&o+""===n&&l?r.push(a+""):l&&a+""===n&&s&&r.push(o+"")}return r}(s,r);if(0===t.length)return e.flatIndex;const a=n.idToIdx.get(t[(o.current+1)%t.length])??-1;return 0>a?e.flatIndex:(o.current=-1,a)}default:{const r=Y(t,e,n);return null!==r&&r!==e.flatIndex&&(o.current=-1),r}}}function Q(t){return"object"==typeof t&&null!==t&&"id"in t?t.id:t}function tt(t){const e=[];for(const n of t)if("point"===n.type&&null!=n.x)e.push({x:n.x,y:n.y,datum:n.datum,shape:"circle"});else if("glyph"===n.type){if(0>=n.size||null==n.datum)continue;const t=l(n.glyph,n.size);e.push({x:n.x+t.centerDx,y:n.y+t.centerDy,datum:n.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight})}else"geoarea"===n.type&&n.centroid&&!1!==n.interactive&&e.push({x:n.centroid[0],y:n.centroid[1],datum:n.datum,shape:"geoarea",pathData:n.pathData});return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}function et(t,e,n){switch(t){case"ArrowRight":case"ArrowDown":return n-1>e?e+1:e;case"ArrowLeft":case"ArrowUp":return e>0?e-1:e;case"PageDown":return Math.min(e+Math.max(1,Math.floor(.1*n)),n-1);case"PageUp":return Math.max(e-Math.max(1,Math.floor(.1*n)),0);case"Home":return 0;case"End":return n-1;case"Escape":return-1;default:return null}}function nt(t){return{data:t.datum||{},x:t.x,y:t.y,__semioticHoverData:!0}}function rt(t){const{title:e,description:n,summary:r,accessibleTable:o,className:a,animate:s,axisExtent:l,autoPlaceAnnotations:i}=t,c={};return e&&(c.title=e),n&&(c.description=n),r&&(c.summary=r),void 0!==o&&(c.accessibleTable=o),a&&(c.className=a),null!=s&&(c.animate=s),void 0!==l&&(c.axisExtent=l),void 0!==i&&(c.autoPlaceAnnotations=i),c}function ot(t){const{linkedHover:e,selection:n,onObservation:r,onClick:o,hoverRadius:a,hoverHighlight:s,forceHoverBehavior:l,forceClickBehavior:i,mobileInteraction:c,customHoverBehavior:u,customClickBehavior:f,linkedHoverInClickPredicate:h=!0}=t,d={};r&&(d.annotationObservationCallback=r);const p=c?.enabled?Math.max(a??30,Math.ceil((c.targetSize||44)/2),24):a;return(l||e||r||o||s)&&(d.customHoverBehavior=u),f&&(i||(h?r||o||e:r||o)||c?.enabled&&(c.tapToSelect||c.tapToLockTooltip)&&(e||s||n))&&(d.customClickBehavior=f),null!=p&&(d.hoverRadius=p),d}function at(t){const{tooltip:e,defaultTooltipContent:n}=t;return{tooltipContent:!1===e?()=>null:r(e)||n}}function st(e,n,r){if(1>=r)return 1;const o=r-1;return t({age:o-n,extent:o,type:e.type,halfLife:e.halfLife??r/2,threshold:e.stepThreshold??.5*r,minOpacity:e.minOpacity??.1})}function lt(t){const e=new Map;for(let n=0;t.length>n;n++)e.set(t[n],n);return e}function it(t,e,n,r=lt(n)){const o=n.length;if(o>1)for(const n of e){if("line"===n.type){const e=Array.isArray(n.datum)?n.datum:[];if(2>e.length)continue;const a=Array(e.length);let s=!1;for(let n=0;e.length>n;n++){const l=r.get(e[n]);null!=l?(a[n]=st(t,l,o),1>a[n]&&(s=!0)):a[n]=1}s&&(n._decayOpacities=a);continue}if("area"===n.type){const e=Array.isArray(n.datum)?n.datum:[],a=n.topPath?n.topPath.length:e.length;if(2>a)continue;if(e.length===a){const s=Array(a);let l=!1;for(let n=0;e.length>n;n++){const a=r.get(e[n]);null!=a?(s[n]=st(t,a,o),1>s[n]&&(l=!0)):s[n]=1}l&&(n._decayOpacities=s)}else{let s=1;for(const n of e){const e=r.get(n);if(null!=e){const n=st(t,e,o);s>n&&(s=n)}}if(1>s){const t=Array(a);t.fill(s),n._decayOpacities=t}}continue}const e=r.get(n.datum);if(null==e)continue;const a=st(t,e,o);"heatcell"===n.type?n.style={opacity:a}:"candlestick"===n.type?n._decayOpacity=a:n.style={...n.style,opacity:(n.style?.opacity??1)*a}}}function ct(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:n,overlays:r,warned:o}=t;ut(r)&&0===n.length&&ft(o,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),n.length>0&&n.every(t=>null==t.datum)&&ft(o,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function ut(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(ut))}function ft(t,e,n){t.has(e)||(t.add(e),console.warn(n))}function ht(t,e,n,r){const o=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),a="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:a,message:`Semiotic ${t} ${a} failed: ${o.message}`,error:o,recovery:n?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:n,affectedRevision:r}}var dt=new WeakMap;function pt(){return this.updateResults.last}function yt(){return this.updateResults.last}function gt(t){return this.updateResults.subscribe(t)}function mt(t){this.config.layoutSelection=t}function xt(){dt.set(this,!0)}function bt(){const t=!0===dt.get(this);return dt.delete(this),t}function vt(t){Object.assign(t.prototype,{getLastUpdateResult:pt,getUpdateSnapshot:yt,subscribeUpdateResult:gt,setLayoutSelection:mt,markStylePaintPending:xt,consumeStylePaintPending:bt})}function wt(t,e,n){return n.x>t||t>n.x+n.w||n.y>e||e>n.y+n.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:n.x+n.w/2,cy:n.y+n.h/2}}function At(t,e=30){return Math.max((t??4)+5,12,e)}function kt(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function _t(t,e){const n=kt(t);if(!n)return!1;const r=kt(e);return!r||n.getFullYear()!==r.getFullYear()||n.getMonth()!==r.getMonth()}function It(t){let e=t%(2*Math.PI);return 0>e&&(e+=2*Math.PI),e}function Mt(t,e,n,r,o,a=t=>t.x,s=t=>t.y,l=t=>t.r){const i=Math.max(r,o+5,12),c=e-i,u=e+i,f=n-i,h=n+i;let d=null,p=1/0;return t.visit((t,o,i,y,g)=>{if(o>u||c>y||i>h||f>g)return!0;if(!t.length){let o=t;do{const t=o.data,i=a(t)-e,c=s(t)-n,u=Math.sqrt(i*i+c*c);At(l(t),r)>=u&&p>u&&(d=t,p=u),o=o.next}while(o)}return!1}),d?{node:d,distance:p}:null}function St(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function Ot(t,e,n=.3){St(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h))}function Dt(t,e,n=.6){if(!St(e))return;const r=e.r+(e._pulseGlowRadius??4)*e._pulseIntensity,o=e.cx??e.x??0,a=e.cy??e.y??0;t.beginPath(),t.arc(o,a,r,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=e._pulseIntensity*n,t.stroke()}function Rt(t,e,n,r=.35){St(e)&&(t.globalAlpha=e._pulseIntensity*r,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",n?t.fill(n):t.fill())}export{st as computeDecayOpacity,lt as buildDatumIndexMap,it as applyDecay,ct as warnCustomLayoutDiagnostics,ht as createCustomLayoutFailureDiagnostic,vt as attachUpdateResultStore,b as composeOverlays,A as useConfigSync,k as useLayoutSelectionSync,wt as hitTestRect,At as getHitRadius,_t as isTimeLandmark,It as normalizeAngle,Mt as findHitPointInQuadtree,M as resolveStaleness,D as useStalenessCheck,E as StalenessBadge,j as useStableShallow,Ot as renderRectPulse,Dt as renderCirclePulse,Rt as renderPathPulse,H as glyphCanvasRenderer,W as networkGlyphRenderer,N as paintSceneWithBackend,U as renderSceneWithBackend,f as accessorName,h as formatVal,y as bandTooltipFields,g as buildDefaultTooltip,m as buildOrdinalTooltip,V as buildNavGraph,F as resolvePosition,Y as nextGraphIndex,X as extractXYNavPoints,q as extractOrdinalNavPoints,J as extractNetworkNavPoints,Z as nextNetworkIndex,tt as extractGeoNavPoints,et as nextIndex,nt as navPointToHover,rt as buildBaseMetadataProps,ot as buildCustomBehaviorProps,at as buildTooltipProps};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ function n(n,t){return n===t}function t(n,t){if("function"==typeof n)return t=>+n(t);const o=n||t;return n=>+n[o]}function o(n,t){if("function"==typeof n)return n;const o=n||t;return n=>n[o]}function r(n,t){return"function"==typeof n?n:n?t=>t[n]+"":t?n=>n[t]+"":void 0}export{n as accessorsEquivalent,t as resolveAccessor,o as resolveRawAccessor,r as resolveStringAccessor};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{mulberry32 as e}from"./chunk-chunk-SIRIJ3DY.module.min.js";import{makeRuleValueResolver as t,resolveStyleRules as n}from"./chunk-chunk-EMO5NUGE.module.min.js";import{commonJsWorkerModuleUrl as i}from"./chunk-chunk-SV4XAZ3Q.module.min.js";import{buildResolveColor as o,resolveCustomLayoutPalette as r}from"./chunk-chunk-JWXLNZSM.module.min.js";import{ANNOTATION_DISCLOSURE_REVEAL_CSS as s,AriaLiveTooltip as a,CanvasFrameBackground as c,FlippingTooltip as l,FocusRing as d,SceneRevisionDiagnosticsObserver as u,ScreenReaderSummary as h,SkipToTableLink as p,UpdateResultTracker as m,annotationLayout as f,coerceCanvasFill as y,createDefaultAnnotationRules as g,defaultTooltipStyle as b,filterSparseArray as v,getDevicePixelRatio as x,isInteractiveKeyboardTarget as w,isServerEnvironment as S,normalizeTooltip as M,prepareCanvas as k,renderAnnotationPass as I,renderLegendFromConfig as A,resolveCSSColor as B,schemeCategory10 as C,useAnnotationActivationOptions as P,useChartMode as R,useChartSelection as T,useDataSummary as q,useFrame as O,useFrameCanvasHost as E,useSceneRevisionDiagnostics as F,xySceneNodeToSVG as j}from"./chunk-chunk-7ZDJSYKI.module.min.js";import{LIGHT_THEME as D,resolveThemeSemanticColors as N,useThemeSelector as z}from"./chunk-chunk-WCX6U47H.module.min.js";import{SafeRender as W,renderEmptyState as $,renderLoadingState as L,useHydration as H,useWasHydratingFromSSR as Y}from"./chunk-chunk-ACLDBMRH.module.min.js";var X={annotationBackground:"rgba(248, 250, 252, 0.94)",annotationStroke:"#334155",annotationText:"#0f172a",background:"#f8fafc",border:"#334155",closedWindowFill:"rgba(220, 38, 38, 0.08)",closedWindowStroke:"rgba(220, 38, 38, 0.55)",danger:"#dc2626",focus:"#f97316",grid:"#cbd5e1",gutterFill:"rgba(71, 85, 105, 0.14)",lateFill:"#f97316",openWindowFill:"rgba(14, 165, 233, 0.07)",openWindowStroke:"rgba(14, 165, 233, 0.3)",primary:"#0ea5e9",selectedFill:"#f97316",selectedStroke:"#7c2d12",success:"#22c55e",text:"#0f172a",textSecondary:"#475569",warning:"#f97316"},V={background:{names:["--semiotic-bg","--surface-1","--surface-0"],fallback:"#f8fafc"},border:{names:["--semiotic-border","--surface-3"],fallback:X.border},danger:{names:["--semiotic-danger","--viz-4"],fallback:X.danger},focus:{names:["--semiotic-focus","--accent","--viz-9"],fallback:X.focus},grid:{names:["--semiotic-grid","--surface-3"],fallback:X.grid},primary:{names:["--semiotic-primary","--accent","--viz-5"],fallback:"#0ea5e9"},success:{names:["--semiotic-success","--viz-2"],fallback:"#22c55e"},text:{names:["--semiotic-text","--text-primary"],fallback:X.text},textSecondary:{names:["--semiotic-text-secondary","--text-secondary"],fallback:"#475569"},warning:{names:["--semiotic-warning","--viz-9","--viz-3"],fallback:"#f97316"}};function _(e,t){const n=e.canvas;if("function"!=typeof getComputedStyle||!n)return t.fallback;const i=getComputedStyle(n);for(const n of t.names){const t=i.getPropertyValue(n).trim();if(t)return B(e,t)??t}return t.fallback}function U(e,t){const n=Math.max(0,Math.min(1,t)),i=e.trim(),o=i.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);if(o){const[,e,t,i]=o;return U(`#${e}${e}${t}${t}${i}${i}`,n)}const r=i.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(r){const[,e,t,i]=r;return`rgba(${parseInt(e,16)}, ${parseInt(t,16)}, ${parseInt(i,16)}, ${n})`}const s=i.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);if(s)return`rgba(${s[1]}, ${n})`;const a=i.match(/^rgba\s*\(\s*([^,]+,\s*[^,]+,\s*[^,]+),\s*[^)]+\)$/i);return a?`rgba(${a[1]}, ${n})`:i}function K(e){const t=_(e,V.primary),n=_(e,V.danger),i=_(e,V.warning),o=_(e,V.success),r=_(e,V.border),s=_(e,V.background),a=_(e,V.text),c=_(e,V.textSecondary),l=_(e,V.focus),d=_(e,V.grid);return{annotationBackground:U(s,.94),annotationStroke:r,annotationText:a,background:s,border:r,closedWindowFill:U(n,.08),closedWindowStroke:U(n,.55),danger:n,focus:l,grid:d,gutterFill:U(c,.14),lateFill:i,openWindowFill:U(t,.07),openWindowStroke:U(t,.3),primary:t,selectedFill:i,selectedStroke:l,success:o,text:a,textSecondary:c,warning:i}}import*as G from"react";import{scaleLinear as Q}from"d3-scale";import{Fragment as Z,jsx as J,jsxs as ee}from"react/jsx-runtime";function te(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function ne(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,te(e))}))}function ie(e){const{width:t,height:n,pointNodes:i=[],data:o}=e;return{scales:{x:Q().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:Q().domain([0,Math.max(1,n)]).range([0,Math.max(1,n)])},width:t,height:n,frameType:"network",pointNodes:i,data:o,xAccessor:"x",yAccessor:"y"}}function oe(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}function re(e){const{width:t,height:n,totalWidth:i,totalHeight:o,margin:r,title:a,legend:c,legendHoverBehavior:l,legendClickBehavior:d,legendHighlightedCategory:u,legendIsolatedCategories:h,legendPosition:p="right",legendLayout:m,pointNodes:y=[],annotations:b,onAnnotationActivate:v,onObservation:x,chartId:w,chartType:S,autoPlaceAnnotations:M,svgAnnotationRules:k,children:B}=e,C=P({onAnnotationActivate:v,onObservation:x,chartId:w,chartType:S}),R=G.useMemo(()=>oe(b),[b]),T=G.useMemo(()=>ie({width:t,height:n,pointNodes:y}),[n,y,t]),q=G.useMemo(()=>R&&M?f({annotations:R,context:T,..."object"==typeof M?M:{}}):R,[T,M,R]),O=G.useMemo(()=>g("network",C),[C]),E=q?I(q,O,k,T):null,F=!0===q?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return ee(Z,{children:[F?J("style",{children:s},"physics-annotation-disclosure-style"):null,ee("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[ee("g",{transform:`translate(${r.left},${r.top})`,children:[E,B]}),a&&"string"==typeof a?J("text",{x:i/2,y:16,textAnchor:"middle",fontWeight:600,fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:a}):a?J("foreignObject",{x:0,y:0,width:i,height:Math.max(r.top,28),children:a}):null,c?A({legend:c,totalWidth:i,totalHeight:o,margin:r,legendPosition:p,legendLayout:m,title:a,legendHoverBehavior:l,legendClickBehavior:d,legendHighlightedCategory:u,legendIsolatedCategories:h}):null]})]})}var se={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},ae=1e-9,ce=.005;function le(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function de(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 ue(e,t,n){return Math.max(t,Math.min(n,e))}function he(e){return 0>e?-1:1}function pe(e){if("circle"===e.shape.type){const t=e.shape.radius;return{minX:e.x-t,minY:e.y-t,maxX:e.x+t,maxY:e.y+t}}const t=e.shape.width/2,n=e.shape.height/2;return{minX:e.x-t,minY:e.y-n,maxX:e.x+t,maxY:e.y+n}}function me(e){const t=e.shape;if("aabb"===t.type){const e=t.width/2,n=t.height/2;return{minX:t.x-e,minY:t.y-n,maxX:t.x+e,maxY:t.y+n}}const n=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-n,minY:Math.min(t.y1,t.y2)-n,maxX:Math.max(t.x1,t.x2)+n,maxY:Math.max(t.y1,t.y2)+n}}function fe(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function ye(e,t,n,i,o,r,s,a){const c=o-e,l=(n+s)/2-Math.abs(c);if(0>=l)return null;const d=r-t,u=(i+a)/2-Math.abs(d);return u>0?u>l?{nx:he(c),ny:0,penetration:l}:{nx:0,ny:he(d),penetration:u}:null}function ge(e,t,n,i,o,r,s){const a=r/2,c=s/2;let l=e-ue(e,i-a,i+a),d=t-ue(t,o-c,o+c);const u=l*l+d*d;if(u>n*n)return null;if(ae>=u){const r=Math.abs(e-(i-a)),s=Math.abs(e-(i+a)),u=Math.abs(t-(o-c)),h=Math.abs(t-(o+c)),p=Math.min(r,s,u,h);return p===r?(l=-1,d=0,{nx:l,ny:d,penetration:n+r}):p===s?(l=1,d=0,{nx:l,ny:d,penetration:n+s}):p===u?(l=0,d=-1,{nx:l,ny:d,penetration:n+u}):(l=0,d=1,{nx:l,ny:d,penetration:n+h})}const h=Math.sqrt(u);return{nx:l/h,ny:d/h,penetration:n-h}}function be(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,i,o,r){const s=i-e,a=o-t,c=n+r,l=s*s+a*a;if(l>=c*c)return null;if(ae>=l)return{nx:1,ny:0,penetration:c};const d=Math.sqrt(l);return{nx:s/d,ny:a/d,penetration:c-d}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return ye(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);if("circle"===e.shape.type&&"aabb"===t.shape.type){const n=ge(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height);return n?{nx:-n.nx,ny:-n.ny,penetration:n.penetration}:null}return"aabb"===e.shape.type&&"circle"===t.shape.type?ge(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function ve(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?ge(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):ye(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,i,o,r,s,a=0){const c=r-i,l=s-o,d=c*c+l*l,u=d>ae?ue(((e-i)*c+(t-o)*l)/d,0,1):0,h=n+a/2,p=e-(i+c*u),m=t-(o+l*u),f=p*p+m*m;if(f>=h*h)return null;if(ae>=f){const e=Math.sqrt(d);return e>ae?{nx:-l/e,ny:c/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(f);return{nx:p/y,ny:m/y,penetration:h-y}}(e.x,e.y,"circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2,n.x1,n.y1,n.x2,n.y2,n.thickness??0)}function xe(e,t){return`${e}\0${t}`}function we(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Se(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,shape:le(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Me(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 ke(e){return{id:e.id,shape:de(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Me(e.bodyFilter),index:e.index}}function Ie(e,t){return!!t?.some(t=>Object.is(e,t))}function Ae(e,t){const n=e.bodyFilter;if(!n)return!0;if("function"==typeof n)return n(t);const i=function(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(t,n.property);return!("equals"in n&&!Object.is(i,n.equals)||"notEquals"in n&&Object.is(i,n.notEquals)||n.oneOf&&!Ie(i,n.oneOf)||n.notOneOf&&Ie(i,n.notOneOf))}var Be=class{constructor(t={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...se,...t},this.random=e(this.options.seed)}init(t={}){this.options={...se,...t},this.random=e(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){const t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(ae,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:le(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(const t of e){this.bodies.delete(t);for(const e of Array.from(this.activeSensors))we(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const t of e)this.colliders.set(t.id,{...t,shape:de(t.shape),bodyFilter:Me(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){const t=e.id??"spring-"+this.nextSpringIndex;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,n){const i=this.bodies.get(e);i&&(i.vx+=t/i.mass,i.vy+=n/i.mass,this.wake(i))}step(e=this.options.fixedDt){const t=Math.max(0,e);if(this.lastEvents=[],0===t)return;const n=this.sortedBodies();for(const e of n)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);const i=this.options.maxVelocity;for(const e of n)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=this.options.velocityDamping,e.vy*=this.options.velocityDamping,i>0){const t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>i){const n=i/t;e.vx*=n,e.vy*=n}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear();const o=this.bodyPairKeys(n),r=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,o,0===e),this.resolveColliders(n,r,0===e);this.updateSensors(n),this.updateSleeping(n,t)}settle(e=1200,t=this.options.fixedDt){let n=0;for(;e>n&&!this.allSleeping();)this.step(t),n+=1;return n}readState(e=[]){e.length=0;for(const t of this.sortedBodies())e.push({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:le(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(we)}allSleeping(){for(const e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Se),colliders:this.sortedColliders().map(ke),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(t){this.options={...t.options,gravity:{...t.options.gravity}},this.random=e(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(t.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const e of t.bodies){const t=Se(e);this.bodies.set(t.id,t),this.nextBodyIndex=Math.max(this.nextBodyIndex,t.index+1)}this.nextColliderIndex=0;for(const e of t.colliders){const t=ke(e);this.colliders.set(t.id,t),this.nextColliderIndex=Math.max(this.nextColliderIndex,t.index+1)}this.nextSpringIndex=0;for(const e of t.springs){this.springs.set(e.id,{...e,target:{...e.target}});const t=/^spring-(\d+)$/.exec(e.id);t&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(t[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(const t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){const n=this.bodies.get(t.bodyId);if(!n||n.sleeping)continue;const i="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!i)continue;const o=i.x-n.x,r=i.y-n.y,s=Math.sqrt(o*o+r*r);if(ae>=s)continue;const a=o/s,c=r/s,l=(s-t.restLength)*t.stiffness+((("vx"in i?i.vx:0)-n.vx)*a+(("vy"in i?i.vy:0)-n.vy)*c)*t.damping;n.vx+=l*a*e/n.mass,n.vy+=l*c*e/n.mass}}resolveBodyPairs(e,t,n){for(const i of t){const[t,o]=i.split(":").map(Number),r=e[t],s=e[o];if(!r||!s)continue;const a=be(r,s);a&&(this.resolveDynamicCollision(r,s,a),n&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(e){const t=Math.max(1,this.options.cellSize),n=new Map;for(let i=0;e.length>i;i+=1){if(!1===e[i].bodyCollisions)continue;const o=pe(e[i]),r=Math.floor(o.minX/t),s=Math.floor(o.maxX/t),a=Math.floor(o.minY/t),c=Math.floor(o.maxY/t);for(let e=r;s>=e;e+=1)for(let t=a;c>=t;t+=1){const o=`${e}:${t}`,r=n.get(o);r?r.push(i):n.set(o,[i])}}const i=new Set;for(const t of Array.from(n.keys()).sort()){const o=n.get(t)??[];o.sort((e,t)=>e-t);for(let t=0;o.length>t;t+=1)for(let n=t+1;o.length>n;n+=1){const r=o[t],s=o[n];!1!==e[r].bodyCollisions&&!1!==e[s].bodyCollisions&&fe(pe(e[r]),pe(e[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((e,t)=>{const[n,i]=e.split(":").map(Number),[o,r]=t.split(":").map(Number);return n===o?i-r:n-o})}resolveDynamicCollision(e,t,n){e.sleeping&&this.contactOpposesGravity(n.nx,n.ny)&&this.supportedThisStep.add(t.id),t.sleeping&&this.contactOpposesGravity(-n.nx,-n.ny)&&this.supportedThisStep.add(e.id);const i=e.sleeping?0:1/e.mass,o=t.sleeping?0:1/t.mass,r=i+o;if(ae>=r)return;const s=Math.max(0,n.penetration-ce)/r;e.x-=n.nx*s*i,e.y-=n.ny*s*i,t.x+=n.nx*s*o,t.y+=n.ny*s*o;const a=(t.vx-e.vx)*n.nx+(t.vy-e.vy)*n.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution))*a/r,d=l*n.nx,u=l*n.ny;e.vx-=d*i,e.vy-=u*i,t.vx+=d*o,t.vy+=u*o,this.applyFriction(e,t,n,l,i,o),c>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,i,o,r){const s=-n.ny,a=n.nx,c=(t.vx-e.vx)*s+(t.vy-e.vy)*a,l=o+r;if(ae>=Math.abs(c)||ae>=l)return;const d=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction))),u=ue(-c/l,-i*d,i*d),h=u*s,p=u*a;e.vx-=h*o,e.vy-=p*o,t.vx+=h*r,t.vy+=p*r}resolveColliders(e,t,n){for(const i of e)for(const e of t){if(!Ae(e,i))continue;if(!fe(pe(i),me(e)))continue;const t=ve(i,e);t&&(this.resolveStaticCollision(i,e,t),this.contactOpposesGravity(t.nx,t.ny)&&this.supportedThisStep.add(i.id),n&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:e.id,sensor:!1}))}}resolveStaticCollision(e,t,n){e.x+=n.nx*Math.max(0,n.penetration-ce),e.y+=n.ny*Math.max(0,n.penetration-ce);const i=e.vx*n.nx+e.vy*n.ny;if(0>i){const o=Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution);e.vx-=(1+o)*i*n.nx,e.vy-=(1+o)*i*n.ny;const r=-n.ny,s=n.nx,a=e.vx*r+e.vy*s,c=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction)));e.vx-=a*r*c,e.vy-=a*s*c}}updateSensors(e){const t=new Set,n=this.sortedColliders().filter(e=>e.sensor);for(const i of e){const e=pe(i);for(const o of n){if(!Ae(o,i))continue;if(!fe(e,me(o)))continue;if(!ve(i,o))continue;const n=xe(o.id,i.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:o.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:i}=we(e);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:n})}this.activeSensors=t}updateSleeping(e,t){const n=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of e)Math.sqrt(i.vx*i.vx+i.vy*i.vy)>=this.options.sleepSpeed||Math.sqrt((i.x-i.prevX)*(i.x-i.prevX)+(i.y-i.prevY)*(i.y-i.prevY))>=this.options.sleepSpeed*t||n&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=t,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}contactOpposesGravity(e,t){const{x:n,y:i}=this.options.gravity,o=Math.hypot(n,i);return 1e-9>=o||-.2>(e*n+t*i)/o}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Ce=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Be).capabilities,engine:"builtin"},this.world=new Be(e)}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Pe(e={}){return new Ce(e)}function Re(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):Pe(t)}var Te=["binId","targetBin","category","windowIndex","lane","group"];function qe(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);const n=t-e.mean;e.mean+=n/e.count,e.m2+=n*(t-e.mean)}function Oe(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 Ee(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:1/0,max:e.count>0?e.max:-1/0}}function Fe(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function je(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?Fe(t,e):void 0}function De(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function Ne(e){const t=Oe(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:Oe(e.x),y:Oe(e.y),value:t}}var ze=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;const t=this.nextIndex;this.nextIndex+=1;const n=De(je(this.config.binAccessor,e,t))??function(e){for(const t of Te){const n=De(Fe(e,t));if(n)return n}return"sediment"}(e),i=De(je(this.config.labelAccessor,e,t))??n,o=function(e,t,n){if("number"==typeof e)return e;const i="function"==typeof e?e(t,n):"string"==typeof e?Fe(t,e):1,o="number"==typeof i?i:Number(i);return Number.isFinite(o)?o:1}(this.config.valueAccessor,e,t),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(n);return s||(s={id:n,label:i,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(n,s)),s.label=i,s.lastBodyId=e.id,s.lastDatum=e.datum,qe(s.x,e.x),qe(s.y,e.y),qe(s.value,o),r>0&&(s.bodyIds.push(e.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Ne(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Ne)}restore(e=[]){this.bins.clear();for(const t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Ee(t.x),y:Ee(t.y),value:Ee(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){const e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function We(e,t={}){const{baselineY:n=0,binWidth:i=24,gap:o=2,maxHeight:r=80,value:s="count",x:a}=t,c=Math.max(1,...e.map(e=>e[s]));return e.map((e,t)=>{const l=Math.max(0,e[s]/c*r),d=a?.(e,t)??t*(i+o);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:d,y:n-l,width:i,height:l,meanX:e.x.mean,meanY:e.y.mean}})}function $e(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}function Le(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),i=t+n,o=$e(e.bodyLimit),r=$e(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const i=$e(n?.warnAt);return null!=i?i:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(o,r,e.options),a=null==o?0:Math.max(0,t-o),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:o,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:i,queuedBodies:n,state:c,warnAt:s}}var He={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Ye={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Xe(e={},t=Ye){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 Ve(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function _e(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:void 0}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Ue(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Ke(e,t={}){const n=_e(t.startAt)??0,i=t.pacing??"immediate";if("arrival"===i){const i=e.map((e,n)=>function(e,t,n){return"function"==typeof n?_e(n(e,t)):"string"==typeof n?_e(Ue(e,n)):_e(e.spawnAt)??_e(Ue(e,"arrivalTime"))??_e(Ue(e,"timestamp"))??_e(Ue(e,"time"))??_e(Ue(e,"eventTime"))}(e,n,t.timeAccessor)),o=i.filter(e=>null!=e),r=o.length>0?Math.min(...o):0,s=_e(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const o=i[t],s=null==o?0:Math.max(0,o-r);return{...Ve(e),spawnAt:n+s/a}})}if("object"==typeof i){const t=_e(i.ratePerSec);if(t&&t>0)return e.map((e,i)=>({...Ve(e),spawnAt:n+i/t}))}return e.map(e=>({...Ve(e),spawnAt:n}))}function Ge(e){return{...Ve(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Qe(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 Ze(e){return!1!==e&&{...e}}function Je(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function et(e){return{...e,gravity:{...e.gravity}}}function tt(e,t,n,i){if("circle"===e.shape.type){const o=e.x-t,r=e.y-n,s=e.shape.radius+i,a=o*o+r*r;return a>s*s?null:a}const o=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),r=Math.max(Math.abs(n-e.y)-e.shape.height/2,0),s=o*o+r*r;return s>i*i?null:s}function nt(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function it(e,t={}){const{idPrefix:n="plot",includeFloor:i=!0,includeCeiling:o=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=t,l=[],d=e.x+e.width/2,u=e.y+e.height/2;return i&&l.push({id:n+"-floor",shape:{type:"aabb",x:d,y:e.y+e.height+c/2,width:e.width+2*a,height:c}}),o&&l.push({id:n+"-ceiling",shape:{type:"aabb",x:d,y:e.y-c/2,width:e.width+2*a,height:c}}),r&&l.push({id:n+"-left-wall",shape:{type:"aabb",x:e.x-a/2,y:u,width:a,height:e.height+2*c}}),s&&l.push({id:n+"-right-wall",shape:{type:"aabb",x:e.x+e.width+a/2,y:u,width:a,height:e.height+2*c}}),l}function ot(e){const{idPrefix:t="bin",count:n,domainStart:i,domainStep:o,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:d=!0,closedBefore:u,lidY:h=s,lidThickness:p=Math.max(2,c)}=e,m=[],f=s+(a-s)/2,y=Math.abs(a-s),g=l?n:n-1;if(d||l)for(let e=l?0:1;g>=e;e+=1){if(!d&&e>0&&n>e)continue;const s=r(i+e*o);m.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:f,width:c,height:y}})}if(null!=u)for(let e=0;n>e;e+=1){const n=i+e*o,s=n+o;if(s>=u)continue;const a=r(n),l=r(s);m.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:p}})}return m}import{quadtree as rt}from"d3-quadtree";var st=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,i,o,r=0){const s=this.ensure(e,t);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,d=i-l,u=i+l,h=o-l,p=o+l;return s.visit((e,t,s,l,m)=>{if(d>l||t>u||h>m||s>p)return!0;if(e.length)return!1;let f=e;for(;f;){const e=f.data;if(e){const t=tt(e,i,o,Math.max(0,r));null!=t&&(c>t||t===c&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,c=t)}f=f.next}return!1}),a}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;const n=e.readState();return 0===n.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=n.reduce((e,t)=>Math.max(e,function(e){return"circle"===e.shape.type?e.shape.radius:Math.hypot(e.shape.width,e.shape.height)/2}(t)),0),this.tree=rt().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},at=["data","scene-geometry","data-paint","accessibility","evidence"],ct=["scene-geometry","data-paint","accessibility","evidence"],lt=["overlay","accessibility","evidence"],dt=(e,t)=>({retainedData:e,invalidations:t}),ut=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ht=["scene-geometry","data-paint","accessibility","evidence"],pt=[],mt={engine:dt("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:dt("preserve",ht),colliders:dt("preserve",ht),sediment:dt("preserve",ht),bodyBudget:dt("preserve",ut),bodyLimit:dt("preserve",ut),eviction:dt("preserve",ut),fixedDt:dt("preserve",pt),maxDeltaSeconds:dt("preserve",pt),maxSubsteps:dt("preserve",pt),settleStepLimit:dt("preserve",pt),timeScale:dt("preserve",pt),observation:dt("preserve",pt)},ft=dt("preserve",ut);function yt(e){let t="preserve";const n=new Set;for(const i of e){const e=mt[i]??ft;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}var gt=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function bt(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&gt.every(n=>e[n]===t[n])}function vt(e,t,n,i){return e||!t?"paused":n||!i?"running":"settled"}var xt=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=function(e){const t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,n){if(n>0)return void(this.seconds=0);const i=e.readState(this.scratch),o=this.speed*this.speed;let r=!0;for(const e of i)if(!e.sleeping&&e.vx*e.vx+e.vy*e.vy>=o){r=!1;break}this.seconds=r?this.seconds+Math.max(0,t):0}},wt=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new st,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new m,this.simulationState="settled",this.visible=!0,this.quiescence=new xt;const{bodyBudget:t,colliders:n,engine:i,kernel:o,observation:r,sediment:s,...a}=e;this.config={...He,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=i,this.observation=Xe(r),this.sediment=new ze(s??!1),this.world=Re(i,{fixedDt:this.config.fixedDt,...o}),this.quiescence.setKernelOptions(o),n&&this.world.setColliders(Qe(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!bt(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:i,engine:o,kernel:r,observation:s,sediment:a,...c}=e;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),o&&o!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=o,this.world=Re(o,e.options),this.world.restore(e),this.revision+=1}if(r&&!bt(r,this.configInput.kernel)){const e=this.world.snapshot(),t={...e.options,...r,gravity:{...e.options.gravity,...r.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}s&&(this.observation=Xe(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(Qe(n)),this.revision+=1),this.configInput={...this.configInput,...e};const l=yt(t);this.updateResults.record({kind:"config",keys:t},l.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Qe(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},yt(["colliders"]).invalidations)}enqueue(e,t){const n=Array.isArray(e)?e:[e],i=t?Ke(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of i)this.queue.push({...Ve(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Je),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?at:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Ve(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},at)}materializeDueSpawns(){const e=this.revision,t=[],n=[];return this.spawnDue(t,n),0===t.length||(this.observeBodyBudget(n),this.evictOverflow(n),this.syncSimulationState(n),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?at:[])),t}clear(){const e=this.world.snapshot().options;this.world.init({...e,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},at)}tick(e){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}const a=Math.max(0,Math.min(e,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(n,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),o.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let d=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>d;){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,d+=1}d===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,n.length),(d>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const u=this.result(d,n,i,o,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:d},this.revision!==t?n.length||i.length||o.length?at:ct:[]),u}settle(e=this.config.settleStepLimit){return this.runSettle(e,!1).steps}settleWithObservations(e=this.config.settleStepLimit){return this.runSettle(e,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),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){const n=this.revision,i=[],o=[],r=[],s=[],a=t?[]:void 0;if(t&&(this.paused||!this.visible)){const e=this.result(0,i,o,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(i,a);const c=this.observeBodyBudget(a),l=this.evictOverflow(a);o.push(...l.evicted),r.push(...l.sedimented),this.syncSimulationState(a),i.length>0&&this.quiescence.reset();const d=t?{spawned:i,evicted:o,sedimented:r,events:s,observations:a}:{spawned:i},{steps:u,budget:h}=function(e,t,n){let i,o=0;for(;t>o&&(e.queueSize()>0||!e.atRest());){e.advanceTime(e.fixedDt);const t=[];if(e.spawnDue(t,n.observations),t.length>0){n.spawned.push(...t),i=e.observeBodyBudget(n.observations);const o=e.evictOverflow(n.observations);n.evicted?.push(...o.evicted),n.sedimented?.push(...o.sedimented)}e.step(e.fixedDt);const r=e.drainEvents();n.events&&(n.events.push(...r),e.observeKernelEvents(r,n.observations),e.observeSensorTransitions(n.observations)),o+=1,e.refreshQuiescence(e.fixedDt,t.length)}return{steps:o,budget:i}}(this.settleHost(),e,d),p=i.length+o.length+r.length>0;(u>0||p||s.length>0)&&(this.revision+=1);const m=this.result(u,i,o,r,s,a??[],void 0,h??c);return this.updateResults.record({kind:"settle",count:u},this.revision===n?[]:p?at:ct),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 We(this.readSediment(),e)}hitTest(e,t,n=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}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){const{timestamp:t,chartType:n,chartId:i,...o}=e,r={...o,timestamp:t??this.elapsedSeconds,chartType:n??this.observation.chartType,chartId:i??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?lt:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?lt:[])}remove(e){const t=new Set(e),n=new Set(this.liveBodyOrder),i=new Set(this.queue.map(e=>e.id));this.queue=this.queue.filter(e=>!t.has(e.id)),this.liveBodyOrder=this.liveBodyOrder.filter(e=>!t.has(e)),this.world.remove(e),this.removeActiveSensorPairsForBodies(t);const o=e.filter(e=>n.has(e)||i.has(e));return o.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:o,count:o.length},o.length?at:[]),o}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},ct),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},ct)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},ct)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,n,i)=>e.applyImpulse(t,n,i),clear:()=>e.clear(),hitTest:(t,n,i)=>e.hitTest(t,n,i),pause:()=>e.setPaused(!0),push:(t,n)=>e.enqueue(t,n),pushMany:(t,n)=>e.enqueue(t,n),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}snapshot(){const e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Ze(this.bodyBudget),config:{...this.config,kernel:et(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Ge),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.config={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale},this.configInput={...e.config,bodyBudget:Ze(e.bodyBudget??{}),kernel:et(e.world.options)},this.bodyBudget=Ze(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(Ge).sort(Je),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??vt(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"},at)}spawnDue(e,t){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const n=this.queue.shift();if(!n)return;this.spawnOne(n,t),e.push(n.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(const t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});const n=this.world.readState().find(t=>t.id===e.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:e.id,datum:n?.datum??e.datum,x:n?.x??e.x,y:n?.y??e.y},t)}result(e,t,n,i,o,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:o,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:i,spawned:t,steps:e}}observeKernelEvents(e,t){!function(e,t,n){if(0===t.length)return;const i=new Map(e.readState().map(e=>[e.id,e]));for(const e of t){if("sleep"!==e.type)continue;const t=i.get(e.bodyId);n.emit({type:"physics-settle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,n){const i=new Set(e.activeSensorPairs().map(e=>`${e.sensorId}\0${e.bodyId}`));if(0===i.size&&0===t.size)return i;const o=new Map(e.readState().map(e=>[e.id,e])),r=(e,t)=>{const{sensorId:i,bodyId:r}=nt(t),s=n.observation.sensors[i],a=o.get(r);n.emit({type:"enter"===e?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:i,binId:s?.binId??i})};for(const e of Array.from(i).sort())t.has(e)||r("enter",e);for(const e of Array.from(t).sort())i.has(e)||r("exit",e);return i}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(nt(n).bodyId)&&e.delete(n)}(this.activeSensorPairs,e)}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return Le({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){const t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;const n=`${t.state}:${t.action}`;return n===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=n,this.emitObservation({type:"overflow"===t.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:t.action,bodyLimit:t.bodyLimit,engineMaxBodiesHint:t.engineMaxBodiesHint,liveBodies:t.liveBodies,overflow:t.overflow,projectedBodies:t.projectedBodies,queuedBodies:t.queuedBodies,warnAt:t.warnAt},e)),t}syncSimulationState(e){const t=vt(this.paused,this.visible,this.queue.length>0,this.atRest());if(t===this.simulationState)return;const n=this.simulationState;this.simulationState=t,function(e,t,n){n.observation.onSimulationStateChange?.(t,e),"running"!==t&&"settled"!==t||n.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,simulationState:t,previousSimulationState:e})}(n,t,this.observationContext(e))}evictOverflow(e){const{evicted:t,sedimented:n,liveBodyOrder:i}=function(e,t,n,i,o,r){const s={evicted:[],sedimented:[],liveBodyOrder:o};if(!1===n)return s;const a=Math.max(0,Math.floor(i));if(!Number.isFinite(a))return s;const c=o.length-a;if(0>=c)return s;const l=function(e,t,n){if("sleeping-first"!==t)return n.slice();const i=new Map(e.readState().map(e=>[e.id,e.sleeping])),o=[],r=[];for(const e of n)i.get(e)?o.push(e):r.push(e);return[...o,...r]}(e,n,o),d=l.slice(0,c);if(0===d.length)return s;const u=function(e,t,n,i){const o=new Map(e.readState().map(e=>[e.id,e])),r=[];for(const e of n){const n=o.get(e);if(!n)continue;const s=t.add(n);s&&(r.push(e),i.emit({type:"physics-sediment",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e,datum:n.datum,x:n.x,y:n.y,binId:s.id,count:s.count,total:s.total}))}return r}(e,t,d,r);e.remove(d);const h=new Set(d);return{evicted:d,sedimented:u,liveBodyOrder:o.filter(e=>!h.has(e))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=i,this.removeActiveSensorPairsForBodies(new Set(t))),{evicted:t,sedimented:n}}};function St(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}function Mt(e,t={}){const n=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),i=n.filter(e=>e.sleeping).length,o=e.queue.length,r=e.sediment.reduce((e,t)=>e+t.count,0),s="settled"===e.simulationState&&0===o&&i===n.length,a=[];o>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const c=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,n,i){const o=e-(t+n+i);return{charge:e,live:t,queued:n,sedimented:i,unaccounted:o,balanced:0===o}}(t.charge,n.length,o,r):void 0;return c&&!c.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:n.length,sleepingCount:i,settled:s,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:St(t.projectionRows),queuedCount:o,sedimentedCount:r,...c?{ledger:c}:{},warnings:a}}var kt={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function It(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function At(e,t){const n="function"==typeof t?t(e):t;return{...kt,...n??{}}}function Bt(e,t={}){const n=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),i={label:t.getBodyLabel?.(e)??It(e)},o={style:At(e,t.bodyStyle),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}function Ct(e,t={}){return e.map(e=>Bt(e,t))}function Pt(e,t={}){const n=e.settle(t.maxSteps),i=e.readBodies(),o=e.snapshot();return{snapshot:o,bodies:i,sceneNodes:Ct(i,t),evidence:Mt(o,{bodies:i,projectionRows:t.projectionRows,stepsRun:n,charge:t.charge}),stepsRun:n}}import*as Rt from"react-dom/server";import{jsx as Tt,jsxs as qt}from"react/jsx-runtime";var Ot={top:0,right:0,bottom:0,left:0};function Et(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function Ft(e,t={}){const{width:n=640,height:i=360,title:o,description:r,background:s,backgroundGraphics:a,className:c,foregroundGraphics:l,idPrefix:d="physics",margin:u,renderBodySVG:h,...p}=t,m=Pt(e,p),f={...Ot,...u},y=[n,i],g=Et(a,y,f),b=Et(l,y,f),v=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(d),x=o?v+"-title":void 0,w=r?v+"-desc":void 0,S=[x,w].filter(Boolean).join(" ")||void 0;return{svg:Rt.renderToStaticMarkup(qt("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:n,height:i,viewBox:`0 0 ${n} ${i}`,role:"img","aria-labelledby":S,children:[o&&Tt("title",{id:x,children:o}),r&&Tt("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?Tt("rect",{x:0,y:0,width:n,height:i,fill:s}):null,g,Tt("g",{id:v+"-data-area",children:m.sceneNodes.map((e,t)=>{const n=m.bodies[t];return(n&&h?h(n,e.style??{},t,v):void 0)??j(e,t,v)})}),b]})),scene:m,evidence:m.evidence}}function jt(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const i=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(i)&&i>0?i:1}function Dt(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=zt(e.datum,t),i=zt(e,t),o=n??i;if(null!=o&&(o+"").length>0)return o+""}return e.id}function Nt(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),i=Math.floor(n);return e[i]+(e[Math.ceil(n)]-e[i])*(n-i)}function zt(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}function Wt(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=zt(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function $t(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),i=e.queueLayout??"lane",o=e.queueSlotSpacing??14,r=e.queueStiffness??.35,s=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,a=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},d=new Map,u=new Map,h=new Map,p=new Map,m=new Map,f=new Map,y=new Map,g=[];let b=0,v=new Map,x=new Map,w=0,S=0,M=0,k=null,I=0,A=0,B=0,C=0,P=0,R=0,T=0,q=0,O=0,E=0,F=0,j=0,D=-1,N=!1;function z(e,n){const i=n(e);return!!i&&i.activeRegionIds.includes(t)}function W(){j+=1}function $(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function L(n,i,o,r){const s={bodyId:n.id,jobId:i.jobId,visitId:i.visitId,visit:i.visit,remaining:i.work,total:i.work,queuedAt:i.queuedAt,sequence:r};return d.set(i.jobId,s),y.delete(n.id),f.set(n.id,i.jobId),A+=1,B+=i.work,W(),function(n,i,o){const r=$(i);e.onQueued?.(n,r),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:i.total,jobId:i.jobId,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,queueDepth:d.size})}(n,s,o),s}function H(e){if(d.size>=s||0===u.size)return;const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(d.size>=s)break;const t=m.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),y.delete(n.bodyId),L(t,n,e,n.sequence)):u.delete(n.jobId)}}function Y(){let e=0;for(const t of d.values())e+=t.remaining;return e}function X(){O=Math.max(O,d.size),E=Math.max(E,Y())}function V(){const e=M-a,t=Math.max(0,Math.min(a,M-(k??M)));let i=0,o=0,r=0,s=0,c=0;for(const t of g){if(e>t.end)continue;i+=t.arrivals,o+=t.arrivalWork,r+=t.completions,s+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?o/t:0;return{seconds:t,arrivals:i,arrivalWork:o,completions:r,completedWork:s,processedWork:c,arrivalsPerSecond:t>0?i/t:0,throughputPerSecond:t>0?r/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:i=>{const o=i.controls.readBodies(),r=new Map,A=new Map;for(const t of o){if(r.set(t.id,t),!z(t.id,i.getRegionState))continue;if(!Wt(t,e.bodyFilter))continue;const n=Dt(t,e.jobKey),o=A.get(n)??[];o.push(t),A.set(n,o)}const B=Number.isFinite(i.dt)?Math.max(0,i.dt):0;if(!N){const e=Number.isFinite(i.elapsed)?Math.max(0,i.elapsed):B;M=Math.max(0,e-B),N=!0}const O=M,E=O+B;M=E,k=null==k?O:Math.min(k,O);const j={start:O,end:E,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},Y=new Map;for(const[e,t]of A){const n=h.get(e)?.bodyId,i=t.find(e=>e.id===n)??t[0];Y.set(e,i),m.set(e,i)}for(const[n,o]of h){if(Y.has(n))continue;const s=d.get(n),a=r.get(o.bodyId)??m.get(n);if(s){d.delete(n),f.delete(s.bodyId),T+=1,q+=s.remaining,W();const r={...$(s),abandonedAt:M,remainingWork:s.remaining,queueSeconds:Math.max(0,M-s.queuedAt)};a&&e.onAbandoned?.(a,r),i.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:a?.datum,x:a?.x,y:a?.y,regionId:t,work:s.total,remainingWork:s.remaining,jobId:n,visitId:s.visitId,visit:s.visit,queuedAt:s.queuedAt,abandonedAt:M,queueSeconds:r.queueSeconds,queueDepth:d.size})}u.delete(n),y.delete(o.bodyId),h.delete(n),m.delete(n)}for(const[n,o]of Y){if(h.has(n))continue;const r=(p.get(n)??0)+1;p.set(n,r);const a=jt(o,e.unitAccessor),c={bodyId:o.id,jobId:n,visitId:`${t}:${n}:${r}`,visit:r,regionId:t,work:a,queuedAt:M};h.set(n,c),I+=1,j.arrivals+=1,j.arrivalWork+=a;const l=b++;if(s>d.size)L(o,c,i,l);else{const s={...c,blockedAt:M,sequence:l};u.set(n,s),y.set(o.id,n),R+=1,W(),e.onBlocked?.(o,s),i.controls.recordObservation({type:"physics-capacity-blocked",bodyId:o.id,datum:o.datum,x:o.x,y:o.y,regionId:t,work:a,jobId:n,visitId:c.visitId,visit:r,queuedAt:M,blockedAt:M,queueDepth:d.size,blockedDepth:u.size})}}H(i),X();const V=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);let _=n*B;for(const n of V){if(0>=_)break;const o=Math.min(n.remaining,_);if(n.remaining-=o,_-=o,C+=o,j.processedWork+=o,n.remaining>1e-6)continue;d.delete(n.jobId),f.delete(n.bodyId),S+=1,P+=n.total,j.completions+=1,j.completedWork+=n.total;const s=Math.max(0,M-n.queuedAt);F+=s,W();const a=r.get(n.bodyId);if(!a)continue;i.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...$(n),completedAt:M,queueSeconds:s};e.onProcessed?.(a,c),i.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:a.datum,x:a.x,y:a.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:M,queueSeconds:s,queueDepth:d.size})}H(i),X(),function(){const e=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);v=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);x=new Map(t.map((e,t)=>[e.bodyId,t])),w=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&g.push(e);const t=M-a;for(;g.length>0&&t>g[0].end;)g.shift()}(j);const U=Math.floor(M/c);U!==D&&(D=U,W())},getSnapshot:()=>{const e=Y(),i=function(){let e=0;for(const t of u.values())e+=t.work;return e}(),o=d.size,r=Array.from(d.values()).map(e=>Math.max(0,M-e.queuedAt)).sort((e,t)=>e-t),s=r.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:o,processedCount:S,unitsPerSecond:n,remainingWork:e,meanRemainingWork:o>0?e/o:0,waitingWork:e+i,blockedDepth:u.size,blockedWork:i,arrivalCount:I,admittedCount:A,admittedWork:B,processedWork:C,completedWork:P,blockedCount:R,abandonedCount:T,abandonedWork:q,peakQueueDepth:O,peakRemainingWork:E,queueAge:{count:r.length,meanSeconds:r.length>0?s/r.length:0,p50Seconds:Nt(r,.5),p95Seconds:Nt(r,.95),oldestSeconds:r.at(-1)??0},meanCompletedQueueSeconds:S>0?F/S:0,window:V(),simulatedAt:M,metricRevision:j}},bodyForce:e=>{if("none"===i)return null;const n=f.get(e.body.id),s=y.get(e.body.id),a=n?d.get(n):void 0,c=s?u.get(s):void 0;if(!a&&!c)return null;const l=a?v.get(e.body.id):x.get(e.body.id);if(null==l)return null;let h;const p=e.regions;if(p)for(let e=0;p.length>e;e+=1)if(p[e].id===t){const t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*o))-e.body.x)*r,y:(h.y-(l-((c?u.size:w)-1)/2)*o/Math.max(1,Math.sqrt(c?u.size:w))-e.body.y)*r*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function Lt(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}function Ht(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Lt(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function Yt(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),i=new Map,o=new Map,r=e.assignmentForce??.45,s=e.returnForce??.35,a=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,d=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=i.get(e);if(n)return n;const r=t.find(e=>!o.has(e.id));if(!r)return null;const s={resourceId:r.id,resourceBodyId:r.bodyId,caseBodyId:e,assignedAt:d};return i.set(e,s),o.set(r.id,s),u+=1,s},release:e=>{const t=i.get(e);return!!t&&(i.delete(e),o.delete(t.resourceId),u+=1,!0)},getAssignment:e=>i.get(e),tick:e=>{d=Math.max(d,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of i)l.has(e)&&l.has(t.resourceBodyId)||(i.delete(e),o.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(i.values()),simulatedAt:d,metricRevision:u}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=o.get(t.id),i=n?l.get(n.caseBodyId):void 0,a=n?r:s;return{x:((i?i.x+(c.x??0):t.home.x)-e.body.x)*a,y:((i?i.y+(c.y??0):t.home.y)-e.body.y)*a}}const d=i.get(e.body.id);if(!d||0>=a)return null;const u=l.get(d.resourceBodyId);return u?{x:(u.x-e.body.x)*a,y:(u.y-e.body.y)*a}:null}}}function Xt(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):Lt(e.datum,t.deadlineAccessor)??Lt(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function Vt(e){const t=new Map;let n=0,i=0;function o(n){t.set(n.bodyId,n),i+=1,e.onStateChange?.({...n})}function r(e){const i=t.get(e);return!(!i||null!=i.completedAt||(o({...i,completedAt:n,state:"unhappy"===i.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const i=t.get(e);return!(!i||null!=i.completedAt||"unhappy"===i.state||(o({...i,state:"protected",protectedAt:n}),0))},complete:r,getCase:e=>t.get(e),tick:i=>{n=Math.max(n,i.elapsed);for(const s of i.controls.readBodies()){if(!Ht(s,e.bodyFilter))continue;if(!t.has(s.id)){const t=Xt(s,e);o({bodyId:s.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const a=t.get(s.id);a&&null==a.completedAt&&(e.completionRegionId&&i.getRegionState(s.id)?.activeRegionIds.includes(e.completionRegionId)?r(s.id):"waiting"!==a.state||a.deadlineAt>n||o({...a,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),o=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:o("waiting"),protected:o("protected"),unhappy:o("unhappy"),resolved:o("resolved"),resolvedUnhappy:o("resolved-unhappy"),simulatedAt:n,metricRevision:i}}}}function _t(e){const t=new Set;let n=0,i=0,o=0,r=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:s=>{n=Math.max(n,s.elapsed);const a=r;var c;c=n,r=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=s.controls.readBodies(),d=new Map(l.map(e=>[e.id,e]));for(const n of l){const i=s.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);i&&Ht(n,e.bodyFilter)&&(r||t.has(n.id)||(t.add(n.id),o+=1,e.onHeld?.(n)))}if(r&&!a){for(const n of t){const t=d.get(n);t&&(s.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),i+=1,e.onReleased?.(t))}t.clear(),o+=1}for(const e of t)d.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:r,blocked:t.size,released:i,simulatedAt:n,metricRevision:o}),bodyForce:n=>{if(r||!t.has(n.body.id))return null;const i=n.regions?.find(t=>t.id===e.regionId),o=i?.shape;if(!o||"aabb"!==o.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const s=e.holdForce??.4;return{x:(o.x-n.body.x)*s-.45*n.body.vx,y:(o.y-n.body.y)*s-.45*n.body.vy}}}}function Ut(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Kt(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,i)=>{const o={result:e,controls:n,dt:i.dt,elapsed:i.elapsed,getRegionState:i.getRegionState};for(const e of t)e.tick(o)},bodyForce:e=>{let n=null;for(const i of t)i.bodyForce&&(n=Ut(n,i.bodyForce(e)));return n}}}function Gt(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:i=>{const o=i.controls.readBodies();for(const r of o){const o=i.getRegionState(r.id),s=o?.activeRegionIds.includes(e.fromRegionId);s?t.has(r.id)||(t.add(r.id),i.controls.applyImpulse(r.id,n.x??0,n.y??0),e.onPortal?.(r)):t.delete(r.id)}}}}function Qt(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function Zt(e,t){const n="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,Qt(e.thickness)??Qt(n)??Qt(t.thickness)??4)}function Jt(e=[],t={}){const n=t.idPrefix?t.idPrefix+"-":"",i=[];for(const o of e){if("barrier"!==o.physics&&"sensor"!==o.physics)continue;const e=o.axis??t.defaultAxis??"x",r=Zt(o,t),s=o.colliderId??`${n}${o.id}`;let a;if("x"===e){const e=Qt(o.x),n=Qt(o.y1)??Qt(t.plotBounds?.y)??Qt(o.y),i=Qt(o.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??Qt(o.y);if(null==e||null==n||null==i)continue;a={type:"segment",x1:e,y1:n,x2:e,y2:i,thickness:r}}else{const e=Qt(o.y),n=Qt(o.x1)??Qt(t.plotBounds?.x)??Qt(o.x),i=Qt(o.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??Qt(o.x);if(null==e||null==n||null==i)continue;a={type:"segment",x1:n,y1:e,x2:i,y2:e,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===o.physics,..."barrier"!==o.physics||null==o.restitution&&null==t.barrierRestitution?{}:{restitution:Qt(o.restitution)??Qt(t.barrierRestitution)},..."barrier"!==o.physics||null==o.friction&&null==t.barrierFriction?{}:{friction:Qt(o.friction)??Qt(t.barrierFriction)}})}return i}function en(e,t){if(0===e.length||0===t.length)return[];const n=new Map(t.map(e=>[e.id,e]));return e.flatMap(e=>{const t=n.get(e.bodyId);if(!t)return[];const i=e.dx??18,o=e.dy??-24;return[{...e,anchorX:t.x,anchorY:t.y,labelX:t.x+i,labelY:t.y+o,body:t}]})}function tn(e=[],t=[]){return{bodyCount:t.length,barrierCount:e.filter(e=>"barrier"===e.physics).length,sensorCount:e.filter(e=>"sensor"===e.physics).length,staticCount:e.length,totalCount:e.length+t.length}}import*as nn from"react";import{forwardRef as on,memo as rn,useCallback as sn,useEffect as an,useImperativeHandle as cn,useId as ln,useRef as dn}from"react";var un=2500;function hn(e){return"function"==typeof e}function pn(e){return void 0===e||!1===e||!hn(e.binAccessor)&&!hn(e.labelAccessor)&&!hn(e.valueAccessor)}function mn(e){if(void 0!==e){if(!1===e)return!1;if(!pn(e))throw new TypeError("Physics worker sediment config only supports string or numeric accessors");return{binAccessor:"string"==typeof e.binAccessor?e.binAccessor:void 0,labelAccessor:"string"==typeof e.labelAccessor?e.labelAccessor:void 0,valueAccessor:"string"==typeof e.valueAccessor||"number"==typeof e.valueAccessor?e.valueAccessor:void 0,retainBodyIds:e.retainBodyIds}}}function fn(e){if(e)return{chartId:e.chartId,chartType:e.chartType,sensors:e.sensors}}function yn(e){return function(e){return!hn(e?.timeAccessor)}(e)}function gn(e={}){if(e.engine)throw new TypeError("Physics workers use the built-in kernel adapter");const{engine:t,observation:n,sediment:i,...o}=e;return{...o,observation:fn(n),sediment:mn(i)}}function bn(){if("undefined"!=typeof DOMException)return new DOMException("Physics worker request aborted","AbortError");const e=Error("Physics worker request aborted");return e.name="AbortError",e}var vn=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./physicsWorker.js",import.meta.url):i("physicsWorker.js");return new Worker(e,{type:"module",name:"semiotic-physics"})}()){this.nextRequestId=1,this.pending=new Map,this.worker=e,this.worker.onmessage=e=>{const t=e.data,n=this.pending.get(t.requestId);n&&(this.pending.delete(t.requestId),n.cleanup(),t.ok?n.resolve(t.payload):n.reject(function(e){const t=Error(e.error.message);return t.name=e.error.name??"Error",e.error.stack&&(t.stack=e.error.stack),t}(t)))},this.worker.onerror=e=>{this.rejectAll(Error(e.message||"Physics worker failed")),this.worker.terminate()}}request(e,t){if(t?.aborted)return Promise.reject(bn());const n=this.nextRequestId;this.nextRequestId+=1;const i={command:e,requestId:n};return new Promise((e,o)=>{const r=()=>{this.pending.delete(n),t?.removeEventListener("abort",r),o(bn())},s=()=>t?.removeEventListener("abort",r);this.pending.set(n,{cleanup:s,reject:o,resolve:e}),t?.addEventListener("abort",r,{once:!0});try{this.worker.postMessage(i)}catch(e){this.pending.delete(n),s(),o(e)}})}async init(e,t,n,i){if(!yn(n))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const o=await this.request({type:"init",config:gn(e),initialSpawns:t,initialSpawnPacing:n},i);if("frame"!==o.type)throw Error("Physics worker returned a non-frame init response");return o.frame}async restore(e,t){const n=await this.request({type:"restore",snapshot:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame restore response");return n.frame}async initFromSnapshot(e,t,n){const i=await this.request({type:"init",config:gn(e),snapshot:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame init response");return i.frame}async enqueue(e,t,n){if(!yn(t))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const i=await this.request({type:"enqueue",spawns:e,pacing:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame enqueue response");return i.frame}async tick(e,t){const n=await this.request({type:"tick",deltaSeconds:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame tick response");return n.frame}async settle(e,t){const n=await this.request({type:"settle",maxSteps:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame settle response");return n.frame}async snapshot(e){const t=await this.request({type:"snapshot"},e);if("snapshot"!==t.type)throw Error("Physics worker returned a non-snapshot response");return t.snapshot}async remove(e,t){const n=await this.request({type:"remove",ids:e},t);if("removed"!==n.type)throw Error("Physics worker returned a non-remove response");return{frame:n.frame,removed:n.removed}}terminate(){this.rejectAll(Error("Physics worker terminated")),this.worker.terminate()}rejectAll(e){for(const[t,n]of this.pending)this.pending.delete(t),n.cleanup(),n.reject(e)}};function xn(e,t,n){const i=new wt(e);return t?.length&&(i.enqueue(t,n),i.materializeDueSpawns()),i}function wn(){return"undefined"!=typeof performance?performance.now():Date.now()}import{useEffect as Sn,useRef as Mn}from"react";function kn(){return"undefined"==typeof document||!document.hidden}function In(e,t,n){const i=y(e,n.fill)??"#4e79a7",o=n.stroke,r=n.strokeWidth??0,s=n.opacity??1,a=n.fillOpacity??1,c=function(e,t){const n=t.mark;if(n)return n;const i=e.datum,o=i?.__physicsMark??i?.mark;return"circle"===o||"halo"===o||"faceted"===o||"pill"===o||"diamond"===o||"square"===o?o:"circle"===e.shape.type?"circle":"square"}(t,n),l="circle"===t.shape.type?n.r??t.shape.radius:Math.max(t.shape.width,t.shape.height)/2;if(e.save(),e.globalAlpha*=s,e.beginPath(),"pill"===c||"square"===c||"aabb"===t.shape.type){const n="pill"===c?2.4*l:"aabb"===t.shape.type?t.shape.width:1.7*l,i="pill"===c?1.35*l:"aabb"===t.shape.type?t.shape.height:1.7*l,o=t.x-n/2,r=t.y-i/2,s="pill"===c?i/2:Math.min(4,n/4);e.moveTo(o+s,r),e.arcTo(o+n,r,o+n,r+i,s),e.arcTo(o+n,r+i,o,r+i,s),e.arcTo(o,r+i,o,r,s),e.arcTo(o,r,o+n,r,s),e.closePath()}else if("diamond"===c)e.moveTo(t.x,t.y-l),e.lineTo(t.x+l,t.y),e.lineTo(t.x,t.y+l),e.lineTo(t.x-l,t.y),e.closePath();else if("faceted"===c){const n=6;for(let i=0;n>i;i+=1){const o=2*Math.PI*i/n-Math.PI/2,r=t.x+Math.cos(o)*l,s=t.y+Math.sin(o)*l;0===i?e.moveTo(r,s):e.lineTo(r,s)}e.closePath()}else e.arc(t.x,t.y,l,0,2*Math.PI);i&&(e.save(),e.globalAlpha*=a,e.fillStyle=i,e.fill(),e.restore()),"halo"===c&&(e.beginPath(),e.arc(t.x,t.y,1.35*l,0,2*Math.PI),e.strokeStyle=o??i,e.lineWidth=Math.max(1.5,r||1.5),e.globalAlpha*=.55,e.stroke(),e.globalAlpha/=.55),o&&r>0&&(e.strokeStyle=o,e.lineWidth=r,n.strokeDasharray&&e.setLineDash(n.strokeDasharray.split(/[,\s]+/).map(e=>Number(e)).filter(e=>Number.isFinite(e))),e.stroke()),e.restore()}function An(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function Bn(e){return e.sensorId??"stream-region-"+e.id}function Cn(e){const t=Bn(e),n={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){const i=e.colliderThickness??8,o=e.shape.x-e.shape.width/2,r=e.shape.x+e.shape.width/2,s=e.shape.y-e.shape.height/2,a=e.shape.y+e.shape.height/2;return[{...n,id:t+"-top",shape:{type:"segment",x1:o,y1:s,x2:r,y2:s,thickness:i}},{...n,id:t+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...n,id:t+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:o,y2:a,thickness:i}},{...n,id:t+"-left",shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:i}}]}return e.collider?[{...n,id:t+"-collider",shape:e.shape}]:[]}function Pn(e){if(e)return{activeRegionIds:Array.from(e.activeRegionIds),regionIds:Array.from(e.regionIds),charges:{...e.charges},attributes:{...e.attributes},energy:e.energy}}function Rn(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}function Tn(e){if(!1===e.semanticItem)return null;const t=e.shape,n=e.semanticItem??{},i="aabb"===t.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:t.x,y:t.y,width:t.width,height:t.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2,pathData:`M ${t.x1} ${t.y1} L ${t.x2} ${t.y2}`};return{...i,...n,id:n.id??i.id}}function qn(e){return e.some(e=>null!=e.force||null!=e.damping||null!=e.impulseOnEnter||null!=e.impulseOnExit)}function On(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}var En=[];function Fn(e){const t=e.store.controls(),n=e.store.snapshot(),i=Math.max(0,e.result.steps*(n.config.fixedDt||1/60)),o=function(e,t,n,i){const o=Number.isFinite(i)?Math.max(0,i):0;if(0>=o||!qn(t))return!1;const r=new Map(t.map(e=>[e.id,e])),s=e.readBodies();let a=!1;for(const t of s){const i=n.get(t.id);if(!i||!i.activeRegionIds.size)continue;const s=Pn(i);if(s)for(const n of i.activeRegionIds){const i=r.get(n);if(!i)continue;const c=Rn(i.force,{body:t,region:i,regionState:s}),l=Number(i.damping??0),d=(c?.x??0)*o-(Number.isFinite(l)?t.vx*l*o:0),u=(c?.y??0)*o-(Number.isFinite(l)?t.vy*l*o:0);(d||u)&&(e.applyImpulse(t.id,d,u),a=!0)}}return a}(t,e.regionEffects,e.regionState,i),r=function(e,t,n,i,o,r){const s=Number.isFinite(r)?Math.max(0,r):0;if(0>=s||!t)return!1;const a=new Map(n.map(e=>[e.id,e])),c=e.readBodies();let l=!1;for(let n=0;c.length>n;n+=1){const r=c[n],d=i.get(r.id),u=Pn(d);let h=En;if(d&&d.activeRegionIds.size>0){const e=[];for(const t of d.activeRegionIds){const n=a.get(t);n&&e.push(n)}h=e}const p=On(t,{body:r,bodies:c,index:n,regionState:u,regions:h,simulationState:o});if(!p)continue;const m=(p.x??0)*s,f=(p.y??0)*s;(m||f)&&(e.applyImpulse(r.id,m,f),l=!0)}return l}(t,e.bodyForces,e.regionEffects,e.regionState,n.simulationState,i);return e.composed&&e.composed.onTick(e.result,t,{dt:i,elapsed:e.result.elapsedSeconds,getRegionState:t=>Pn(e.regionState.get(t))}),e.onTick?.(e.result,t),{regionEffectsApplied:o,bodyForcesApplied:r,snapshot:n}}function jn(e,t,n,i,o,r,s,a,c,l){const d=function(e,t){return!!t?.isActive&&(t.predicate?.(e)??!0)}(e,o),u={selected:d,simulationState:t,regionState:r,regions:s},h="function"==typeof n?n(e,u):n,p=s.reduce((t,n)=>n.bodyStyle?{...t,..."function"==typeof n.bodyStyle?n.bodyStyle(e,u):n.bodyStyle}:t,{}),m=d?"function"==typeof i?i(e,u):i:void 0;return{fill:l?.color??a,stroke:l?.stroke??c,strokeWidth:l?.strokeWidth??1,opacity:l?.opacity??.9,...h,...p,...m}}import{useCallback as Dn}from"react";import*as Nn from"react";import{jsx as zn,jsxs as Wn}from"react/jsx-runtime";var $n={border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},Ln="semiotic-accessible-data-table",Hn=Ln+" semiotic-accessible-data-table-hidden",Yn=Ln+" semiotic-accessible-data-table-visible",Xn={position:"absolute",top:0,left:0,right:0,zIndex:"var(--semiotic-data-table-z-index, var(--semiotic-overlay-z-index, 20))",padding:"14px 16px 12px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontFamily:"var(--semiotic-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif)",fontSize:13,lineHeight:1.5,color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",borderRadius:"var(--semiotic-border-radius, 0px) var(--semiotic-border-radius, 0px) 0 0"},Vn={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},_n={position:"absolute",top:10,right:10,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",cursor:"pointer",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:13,lineHeight:1,padding:0,borderRadius:"var(--semiotic-border-radius, 4px)"},Un={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},Kn={textAlign:"left",padding:"5px 10px",borderBottom:"2px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))"},Gn={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},Qn={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},Zn={marginTop:8,padding:"4px 10px",fontSize:12,cursor:"pointer",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",borderRadius:"var(--semiotic-border-radius, 4px)",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",fontFamily:"inherit"};function Jn(e){return null==e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e?e+"":null}function ei(e){return{__semioticHoverData:!0,body:e,data:e.datum??e,id:e.id,type:"body",x:e.x,y:e.y}}function ti(e){if("circle"===e.shape.type){const t=Math.max(4,2*e.shape.radius);return{height:t,shape:"circle",width:t}}return{height:e.shape.height,shape:"rect",width:e.shape.width}}function ni(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return e+""}return e.id}function ii(e){const t=oi(e.datum??e);return t.length?t.map(([e,t])=>`${e}: ${t}`).join(", "):"Physics body "+e.id}function oi(e){return e&&"object"==typeof e?Object.entries(e).map(([e,t])=>{if(e.startsWith("_"))return null;const n=Jn(t);return null==n?null:[e,n]}).filter(e=>null!=e).slice(0,8):[]}function ri({hover:e}){const t=oi(e.data);return Wn("div",{className:"semiotic-tooltip",style:b,children:[zn("div",{style:{fontWeight:700,marginBottom:t.length?4:0},children:e.id}),t.map(([e,t])=>Wn("div",{children:[Wn("span",{style:{opacity:.72},children:[e,": "]}),zn("span",{children:t})]},e))]})}function si(e){return e.datum&&"object"==typeof e.datum?Object.entries(e.datum).map(([e,t])=>{const n=Jn(t);return null==n?null:`${e}: ${n}`}).filter(e=>null!=e).slice(0,8).join(", "):""}function ai(e){const t=[`${e.length} semantic item${1===e.length?"":"s"}.`],n=new Map;for(const t of e)t.group&&n.set(t.group,(n.get(t.group)??0)+1);return n.size&&t.push(Array.from(n).map(([e,t])=>`${e}: ${t}`).join(", ")),t.join(" ")}function ci(e){const{chartTitle:t,items:n,tableId:i}=e,[o,r]=Nn.useState(!1),[s,a]=Nn.useState(5),c=q(),l=c?.visible??!1,d=o||l,u=Nn.useRef(null),h="Data summary for "+(t??"physics chart");Nn.useEffect(()=>{d||a(5)},[d]);const p=Nn.useCallback(e=>{e.target===e.currentTarget&&(o||l||r(!0))},[o,l]),m=Nn.useCallback(e=>{l||u.current?.contains(e.relatedTarget)||r(!1)},[l]);if(!n.length)return zn("span",{id:i,tabIndex:-1,style:$n});if(!d)return zn("div",{id:i,className:Hn,role:"region","aria-label":h,tabIndex:-1,style:$n,onFocus:p,children:Wn("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",n.length," semantic items)"]})});const f=Math.min(s,n.length),y=n.slice(0,f),g=n.length-f;return Wn("div",{ref:u,id:i,className:Yn,role:"region","aria-label":h,tabIndex:-1,onBlur:m,style:Xn,children:[zn("button",{type:"button",className:"semiotic-accessible-data-table-close","aria-label":"Close data summary",onClick:()=>{l&&c&&c.setVisible(!1),r(!1)},style:_n,children:"×"}),zn("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Vn,children:ai(n)}),Wn("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Semantic items for "+(t??"physics chart"),style:Un,children:[zn("caption",{className:"semiotic-accessible-data-table-caption",style:Qn,children:g>0?`First ${f} of ${n.length} semantic items`:`All ${n.length} semantic items`}),zn("thead",{children:Wn("tr",{children:[zn("th",{scope:"col",style:Kn,children:"Item"}),zn("th",{scope:"col",style:Kn,children:"Description"}),zn("th",{scope:"col",style:Kn,children:"Group"}),zn("th",{scope:"col",style:Kn,children:"Position"}),zn("th",{scope:"col",style:Kn,children:"Data"})]})}),zn("tbody",{children:y.map((e,t)=>Wn("tr",{children:[zn("th",{scope:"row",style:Gn,children:e.label}),zn("td",{style:Gn,children:e.description??e.label}),zn("td",{style:Gn,children:e.group??""}),Wn("td",{style:Gn,children:[Math.round(e.x),", ",Math.round(e.y)]}),zn("td",{style:Gn,children:si(e)})]},e.id??`${e.label}-${t}`))})]}),g>0?Wn("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:Zn,children:["Show ",Math.min(25,g)," more"," ",1===g?"row":"rows"," (",g," remaining)"]}):null]})}ri.ownsChrome=!0;import{jsx as li,jsxs as di}from"react/jsx-runtime";var ui=[640,360],hi={top:0,right:0,bottom:0,left:0},pi=new Set(["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),mi="StreamPhysicsFrame",fi=rn(on(function(e,t){const{accessibleTable:n=!0,annotations:i,onAnnotationActivate:o,autoPlaceAnnotations:r,background:s,backgroundGraphics:m,bodySemanticItemLimit:f=200,bodySemanticItems:y=!1,bodySemanticUpdateMs:g=200,bodyForces:b,bodyStyle:v,chartId:M,className:I,frameScheduler:A,clock:B,random:C,seed:P,color:R,config:T,controllers:q,continuous:j=!1,description:D,emphasis:N,chartMode:z,enableHover:W=!0,foregroundGraphics:$,hoverRadius:L=16,initialSpawns:X,initialSpawnPacing:V,legend:_,legendClickBehavior:U,legendHighlightedCategory:G,legendHoverBehavior:Q,legendIsolatedCategories:Z,legendLayout:J,legendPosition:ee,margin:te,onClick:ie,onObservation:oe,onRegionEvent:se,onSimulationExecutionChange:ae,onBodyHover:ce,onBodyPointerDown:le,onSemanticItemActivate:de,onSemanticItemFocus:ue,onTick:he,opacity:pe,paused:me=!1,regionEffects:fe=[],responsiveHeight:ye,responsiveWidth:ge,selectedBodyStyle:be={stroke:"#111827",strokeWidth:2,opacity:1},selection:ve,semanticItems:xe=[],simulationExecution:we="auto",size:Se=ui,stroke:Me,strokeWidth:ke,summary:Ie,suspendWhenHidden:Ae=!0,svgAnnotationRules:Be,title:Ce,tooltipContent:Pe,workerBodyThreshold:Re=un,renderBody:Te,beforePaint:qe,afterPaint:Oe}=e,Ee=nn.useMemo(()=>({color:R,stroke:Me,strokeWidth:ke,opacity:pe}),[R,pe,Me,ke]),Fe=dn(oe);Fe.current=oe;const je=dn(M);je.current=M;const De=dn(new Map),Ne=dn(fe);Ne.current=fe;const ze=dn(b);ze.current=b;const We=dn(he);We.current=he;const $e=nn.useMemo(()=>Kt(q),[q]),Le=dn($e);Le.current=$e;const He=j||!!$e?.continuous,Ye=dn(He);Ye.current=He;const Xe=nn.useMemo(()=>{if(!b&&!$e?.bodyForce)return b;if(!$e?.bodyForce)return b;if(!b)return $e.bodyForce;const e=$e.bodyForce;return t=>{const n="function"==typeof b?b(t):b,i="function"==typeof e?e(t):e;return n||i?{x:(n?.x??0)+(i?.x??0),y:(n?.y??0)+(i?.y??0)}:null}},[b,$e]);ze.current=Xe;const Ve=nn.useMemo(()=>new Map(fe.map(e=>[Bn(e),e])),[fe]),_e=nn.useMemo(()=>new Map(fe.map(e=>[e.id,e])),[fe]),Ue=nn.useMemo(()=>fe.map(Tn).filter(e=>null!=e),[fe]),[Ke,Ge]=nn.useState([]),Qe=nn.useMemo(()=>Ke.length||Ue.length?[...xe,...Ke,...Ue]:xe,[Ke,Ue,xe]),Ze=nn.useMemo(()=>qn(fe),[fe]),Je=!!Xe,et=dn(null),tt=dn(B??wn);tt.current=B??wn;const nt=sn((e,t,n)=>{const i=et.current;if(!i||!n)return!1;const o=i.readBodies().find(t=>t.id===e),r=Pn(De.current.get(e));if(!o||!r)return!1;const s=Rn(n,{body:o,region:t,regionState:r});return!(!s||!s.x&&!s.y||(i.applyImpulse(e,s.x??0,s.y??0),0))},[]),it=sn((e,t,n)=>{if(!n.bodyId)return;const i=Pn(De.current.get(n.bodyId));if(!i)return;const o={bodyId:n.bodyId,datum:n.datum,observation:n,region:t,regionState:i,type:e};"region-enter"===e?t.onEnter?.(o):t.onExit?.(o),se?.(o)},[se]),ot=sn(e=>{const t=e.sensorId?Ve.get(e.sensorId):void 0;if(!t||!e.bodyId)return;const n=function(e,t){let n=e.get(t);return n||(n={activeRegionIds:new Set,attributes:{},charges:{},energy:0,regionIds:new Set},e.set(t,n)),n}(De.current,e.bodyId),i=et.current?.readBodies().find(t=>t.id===e.bodyId),o=Pn(n),r=i&&o?{body:i,region:t,regionState:o}:null;if("physics-proximity-enter"===e.type){if(n.activeRegionIds.add(t.id),n.regionIds.add(t.id),n.energy+=t.energyDelta??0,r){!function(e,t,n){const i="function"==typeof e.attributes?e.attributes(t):e.attributes;i&&(n.attributes={...n.attributes,...i})}(t,r,n);const e=function(e,t){return void 0!==e.charge?"function"==typeof e.charge?e.charge(t):e.charge:"charge-gate"===e.kind?1:void 0}(t,r);void 0!==e&&(n.charges[t.id]=e)}nt(e.bodyId,t,t.impulseOnEnter),it("region-enter",t,e)}else"physics-proximity-exit"===e.type&&(n.activeRegionIds.delete(t.id),nt(e.bodyId,t,t.impulseOnExit),it("region-exit",t,e))},[nt,it,Ve]),rt=nn.useMemo(()=>function({annotations:e,chartId:t,chartType:n,config:i,onRegionObservation:o,regionEffects:r,seed:s,size:a}){const c=Jt((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?t+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),l=void 0===s||void 0!==i?.kernel?.seed?i:{...i,kernel:{...i?.kernel,seed:s}},d=r.flatMap(e=>[{id:Bn(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...Cn(e)]),u=Object.fromEntries(r.map(e=>[Bn(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=l?.observation,p=r.length>0;return p||d.length>0||c.length>0||null!=t||h?{...l,colliders:[...l?.colliders??[],...d,...c],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??n,sensors:{...h?.sensors??{},...u},onObservation:e=>{p&&o(e),h?.onObservation?.(e)}}}:l}({annotations:i,chartId:M,chartType:mi,config:T,onRegionObservation:ot,regionEffects:fe,seed:P,size:Se}),[i,M,T,ot,fe,P,Se]);if(!et.current){const e=xn(rt,X,V);e.setPaused(me),Ae&&e.setVisible(kn()),et.current=e}const st=dn(-1),at=dn(null),ct=dn(!0),lt=F("StreamPhysicsFrame"),dt=dn(""),ut=ln().replace(/:/g,""),ht=dn(!1),pt=dn(!1),mt=dn(0),ft=dn(!1),yt=dn(!1),gt=dn(null),bt=dn(!1),vt=O({sizeProp:Se,responsiveWidth:ge,responsiveHeight:ye,userMargin:te,marginDefault:hi,foregroundGraphics:$,backgroundGraphics:m,frameScheduler:A,clock:B,random:C,seed:P,paused:me,suspendWhenHidden:Ae}),{margin:xt,rafRef:wt,reducedMotion:St,reducedMotionRef:Mt,renderFnRef:kt,cancelRender:It,resolvedBackground:At,resolvedForeground:Bt,responsiveRef:Ct,scheduleRender:Pt,size:Rt,frameRuntime:Tt}=vt,qt=dn(Tt.now);qt.current=Tt.now;const Ot=H(),Et=Y(),[jt,Dt]=nn.useState(null),[Nt,zt]=nn.useState(null),Wt=dn(null),$t=dn(0),Lt=dn(new Map),Ht=ut+"-physics-live",Yt=sn((e,t,n=!1)=>{if(!y)return void Ge(e=>e.length?[]:e);const i=qt.current();if(!n&&g>0&&g>i-$t.current)return;$t.current=i;const o=function(e,t,n,i){if(!n)return[];const o=Math.max(0,Math.floor(i));if(!o)return[];const r=[];for(let i=0;e.length>i&&o>r.length;i+=1){const o=e[i],s="function"==typeof n?n(o,{index:i,simulationState:t}):void 0;if(!1===s)continue;const a=ti(o);r.push({datum:o.datum??o,description:ii(o),group:"body",label:ni(o),...a,...s??{},bodyId:s?.bodyId??o.id,id:s?.id??"body:"+o.id,x:s?.x??o.x,y:s?.y??o.y})}return r}(e,t,y,f);Ge(e=>function(e,t){if(e.length!==t.length)return!0;for(let n=0;e.length>n;n+=1){const i=e[n],o=t[n];if(i.id!==o.id||i.label!==o.label||i.description!==o.description||i.group!==o.group||i.bodyId!==o.bodyId||Math.round(i.x)!==Math.round(o.x)||Math.round(i.y)!==Math.round(o.y))return!0}return!1}(e,o)?o:e)},[f,y,g]),Xt=sn(e=>{if(!Qe.length)return;const t=Math.max(0,Math.min(e,Qe.length-1));st.current=t;const n=Qe[t];if(Wt.current=n.bodyId??null,Dt(n),ue?.(n),n.bodyId&&et.current){const e=et.current.readBodies().find(e=>e.id===n.bodyId);if(e){const t=ei(e);zt(t),ce?.(e,t)}}},[Qe,ce,ue]),Vt=sn(()=>{st.current=-1,Wt.current=null,Dt(null),ue?.(null)},[ue]),_t=function({onObservationRef:e,chartIdRef:t,wallClockRef:n}){return Dn((i,o)=>{const r=e.current;if(!r)return;const s={timestamp:n.current(),chartType:"StreamPhysicsFrame",chartId:t.current};r("hover"===i||"click"===i?{...s,type:i,datum:o?.datum??{},x:o?.x??0,y:o?.y??0}:"focus"===i?{...s,type:i,datum:o?.datum??{},inputType:"touch"===o?.inputType?"pointer":o?.inputType??"keyboard"}:"activate"===i?{...s,type:i,datum:o?.datum??{},inputType:o?.inputType??"keyboard"}:{...s,type:i})},[t,e,n])}({onObservationRef:Fe,chartIdRef:je,wallClockRef:tt}),Ut=sn(()=>{zt(e=>e?(ce?.(null,null),_t("hover-end"),null):e)},[_t,ce]),Gt=sn(e=>{if(!W||!et.current)return;const t=e.currentTarget.getBoundingClientRect(),n=et.current.hitTest(e.clientX-t.left,e.clientY-t.top,L);if(!n)return void Ut();const i=ei(n);zt(e=>e&&e.id===i.id&&e.x===i.x&&e.y===i.y?e:(ce?.(n,i),_t("hover",{datum:n.datum,x:n.x,y:n.y}),i))},[Ut,_t,W,L,ce]),Qt=sn(e=>{Vt();const t=et.current,n=e.currentTarget.getBoundingClientRect(),i=e.clientX-n.left,o=e.clientY-n.top,r=t?t.hitTest(i,o,Math.max(16,L)):null;le?.(r,e),r?(_t("click",{datum:r.datum,x:r.x,y:r.y}),_t("activate",{datum:r.datum,inputType:"touch"===e.pointerType?"touch":"pointer"}),ie?.(r.datum??null,{x:r.x,y:r.y,body:r})):(_t("click-end"),ie?.(null,{x:i,y:o,body:null}),Ut())},[Ut,Vt,_t,L,le,ie]);an(()=>{if(!Qe.length)return void Vt();const e=st.current;if(Qe.length>e){if(e>=0){const t=Qe[e];if(Wt.current=t.bodyId??null,Dt(e=>null!=e&&e.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t),t.bodyId&&et.current){const e=et.current.readBodies().find(e=>e.id===t.bodyId);if(e){const t=ei(e);zt(e=>e?.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t)}}}}else Xt(Qe.length-1)},[Qe,Vt,Xt]),an(()=>{W||Ut()},[Ut,W]);const Zt=sn(e=>{if(w(e))return;if(!Qe.length)return;if("Escape"===e.key)return e.preventDefault(),void Vt();if(("Enter"===e.key||" "===e.key)&&st.current>=0){e.preventDefault();const t=Qe[st.current];return _t("activate",{datum:t.datum??{id:t.id,label:t.label},inputType:"keyboard"}),void de?.(t)}if(!pi.has(e.key))return;e.preventDefault();const t=st.current;if(0>t){Xt(0);const e=Qe[0];return void _t("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}const n=Math.max(1,Math.floor(.1*Qe.length));let i=t;if("Home"===e.key?i=0:"End"===e.key?i=Qe.length-1:"PageDown"===e.key?i=Math.min(Qe.length-1,t+n):"PageUp"===e.key?i=Math.max(0,t-n):"ArrowRight"===e.key||"ArrowDown"===e.key?i=Math.min(Qe.length-1,t+1):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(i=Math.max(0,t-1)),Xt(i),i!==t){const e=Qe[i];_t("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}},[Vt,_t,Xt,de,Qe]),[en,tn]=nn.useState([]),on=dn(0),rn=!!i?.length&&i.some(e=>null!=e.pointId||null!=e.bodyId||"latest"===e.anchor),{canvasRef:hn}=E(vt,{hydrated:Ot,wasHydratingFromSSR:Et,storeRef:et,dirtyRef:ct,manageFrameRuntime:!1,skipInitialCanvasPaintInvalidation:!0,canvasPaintDependencies:[s,m,Pt]}),mn=sn(()=>{const e=hn.current,t=et.current;if(!e||!t)return;const n=lt.current.beforeCompute(t.getLastUpdateResult(),!1),i=x(),o=k(e,Rt,xt,i);if(!o)return void lt.current.afterCompute(n,!1,!1);const r=K(o);o.clearRect(-xt.left,-xt.top,Rt[0],Rt[1]),m||"transparent"===s||(o.fillStyle=s??r.background,o.fillRect(-xt.left,-xt.top,Rt[0],Rt[1]));const a=t.snapshot(),c=t.readBodies();if(Yt(c,a.simulationState),rn){const e=qt.current();if(e-on.current>=100){on.current=e;const t=ne(c);tn(e=>e.length===t.length&&e.every((e,n)=>e.pointId===t[n].pointId&&Math.round(e.x)===Math.round(t[n].x)&&Math.round(e.y)===Math.round(t[n].y))?e:t)}}qe&&(o.save(),qe(o,c),o.restore());for(const e of c){const t=De.current.get(e.id),n=t?Array.from(t.activeRegionIds).map(e=>_e.get(e)).filter(e=>null!=e):[],i=jn(e,a.simulationState,v,be,ve,Pn(t),n,r.primary,r.text,Ee);Te?(o.save(),Te(o,e,i),o.restore()):In(o,e,i)}Oe&&(o.save(),Oe(o,c),o.restore()),function(e,t,n){let i=!1;for(const[o,r]of t){const s=Math.min(1,Math.max(0,(n-r.startedAt)/r.durationMs));if(s>=1){t.delete(o);continue}i=!0;const a=1-Math.pow(1-s,3),{body:c}=r,l=r.scale>0?r.scale:1,d=(r.radius+28*a)*l,u=1-s;e.save(),e.globalAlpha*=u,e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=Math.max(.5,(2.4*u+.4)*l),e.beginPath(),e.arc(c.x,c.y,d,0,2*Math.PI),e.stroke(),e.globalAlpha*=.18,e.beginPath(),e.arc(c.x,c.y,.52*d,0,2*Math.PI),e.fill(),e.restore(),e.save(),e.globalAlpha*=u,e.strokeStyle=r.color,e.lineWidth=Math.max(.5,1.8*l);for(let t=0;8>t;t+=1){const n=t*(Math.PI/4)+1.4*s,i=(r.radius+5+12*a)*l,o=(r.radius+12+34*a)*l;e.beginPath(),e.moveTo(c.x+Math.cos(n)*i,c.y+Math.sin(n)*i),e.lineTo(c.x+Math.cos(n)*o,c.y+Math.sin(n)*o),e.stroke()}e.restore()}}(o,Lt.current,qt.current()),lt.current.afterCompute(n,!0,!1),ct.current=!1},[hn,lt,Rt,xt,m,s,Yt,rn,qe,Oe,v,be,ve,Ee,Te,_e]),fn=sn((e,t)=>{const n=et.current,i=`${we}:${e}:${t??""}`;dt.current!==i&&(dt.current=i,ae?.({execution:e,liveBodies:n?.liveBodyCount()??0,queuedBodies:n?.queueSize()??0,reason:t,requested:we}))},[ae,we]),gn=sn((e,t=!0)=>{mt.current+=1,ht.current=!1,ft.current=!1,yt.current=!1,bt.current=!1,gt.current?.terminate(),gt.current=null,t&&fn("sync",e)},[fn]),bn=sn(()=>Ot?"undefined"==typeof window||"undefined"==typeof Worker?"worker unavailable":Ze?"runtime region effects require sync":Je?"body forces require sync":$e?"physics controllers require sync":function(e){return!e||!e.engine&&pn(e.sediment)&&(!(t=e.colliders)||t.every(e=>{const t=e.bodyFilter;return!t||"function"!=typeof t}));var t}(rt??{})?yn(V)?pt.current?"worker fallback":null:"spawn pacing is not worker-cloneable":"config is not worker-cloneable":"hydrating",[rt,$e,Je,Ze,Ot,V]),On=sn(()=>{const e=et.current,t=bn();if(!e||t)return{reason:t,useWorker:!1};const n=e.liveBodyCount(),i=e.queueSize(),o=function(e,t,n=0,i=un){return"sync"!==e&&("worker"===e||t+n>=i)}(we,n,i,Re);return{reason:o?"worker"===we?"forced worker":"body threshold":"below threshold",useWorker:o}},[we,Re,bn]),En=sn(e=>{const t=et.current;return t&&e.snapshot?(t.restore(e.snapshot),ct.current=!0,t):t},[]),Nn=sn((e,t=!0)=>{const n=En(e);if(!n)return;t&&he?.(e.result,n.controls()),mn();const i=n.snapshot();!e.result.shouldContinue&&Lt.current.size<=0||i.paused||!i.visible||Mt.current||Pt()},[En,he,mn,Mt,Pt]),zn=sn(e=>{pt.current=!0,gn("worker failed: "+((e instanceof Error?e.message:e+"")||"unknown error"))},[gn]),Wn=sn(()=>{const e=et.current;if(!e)return!1;const t=On();if(!t.useWorker)return ht.current||bt.current?gn(t.reason??"sync fallback"):fn("sync",t.reason??"sync"),!1;if(ht.current||bt.current)return!0;const n=gt.current??new vn;gt.current=n,bt.current=!0;const i=mt.current+1;return mt.current=i,n.initFromSnapshot(rt??{},e.snapshot()).then(e=>{if(mt.current!==i)return;bt.current=!1,ht.current=!0,pt.current=!1,En(e),fn("worker",t.reason??"worker"),mn();const n=et.current?.snapshot();e.result.shouldContinue&&n&&!n.paused&&n.visible&&!Mt.current&&(at.current=null,Pt())}).catch(e=>{mt.current===i&&zn(e)}),!0},[En,rt,zn,mn,Mt,fn,Pt,gn,On]),Ln=sn(e=>"frame"===e.type||"removed"===e.type?e.frame:null,[]),Hn=sn((e,t=!0)=>{const n=gt.current;if(!n||!ht.current)return;const i=mt.current;n.request(e).then(e=>{if(mt.current!==i)return;const n=Ln(e);n&&Nn(n,t)}).catch(zn)},[Nn,Ln,zn]),Yn=sn(()=>{const e=et.current;if(!e)return;const t=Wn(),n=e.snapshot(),i=He||Je||Ze||!!$e;n.paused||!n.visible||!e.hasPendingWork()&&!i||Mt.current?kt.current():t&&bt.current||Pt()},[$e,He,Je,Ze,Mt,kt,Pt,Wn]),Xn=sn(()=>{It(),wt.current=null;const e=et.current;if(!e)return;const t=Mt.current;if(t&&(at.current=null),ht.current&&gt.current){if(ft.current)return void(yt.current=!0);let n=0;if(!t){const e=qt.current();n=null!==at.current?(e-at.current)/1e3:0,at.current=e}const i=gt.current,o=mt.current;return ft.current=!0,void(t?i.settle():i.tick(n)).then(e=>{ft.current=!1;const t=yt.current;yt.current=!1,mt.current===o&&(Nn(e),t&&Yn())}).catch(i=>{ft.current=!1;const r=yt.current;if(yt.current=!1,mt.current!==o)return;zn(i);const s=t?e.settleWithObservations():e.tick(n);Fn({store:e,result:s,regionEffects:Ne.current,regionState:De.current,bodyForces:ze.current,composed:Le.current,onTick:We.current}),mn(),r&&Yn()})}const n=Le.current,i=t=>Fn({store:e,result:t,composed:n,regionEffects:Ne.current,regionState:De.current,bodyForces:ze.current,onTick:We.current});let o;if(t)o=function(e,t,n=4){let i,o=!1,r=!1,s=0;do{const n=e.settleWithObservations(),a=t(n);o=o||a.regionEffectsApplied,r=r||a.bodyForcesApplied,i={...a,regionEffectsApplied:o,bodyForcesApplied:r,result:n},s+=1}while(n>s&&e.hasPendingWork());return i}(e,i);else{const t=qt.current(),n=at.current;at.current=t;const r=e.tick(null===n?0:(t-n)/1e3);o={...i(r),result:r}}const{result:r,regionEffectsApplied:s,bodyForcesApplied:a,snapshot:c}=o;mn(),(Ye.current||r.shouldContinue||s||a||n||Lt.current.size>0)&&!c.paused&&c.visible&&!Mt.current&&Pt()},[Nn,zn,mn,It,Yn,Pt,Mt,wt]);kt.current=Xn,an(()=>{pt.current=!1,(ht.current||bt.current)&&gn("config changed",!1),et.current?.updateConfig(rt??{}),Yn()},[rt,gn]),an(()=>{pt.current=!1,Yn()},[Ot,we,Re]),an(()=>{Yn()},[St,Yn]),function({cancelRender:e,frameRuntime:t,lastFrameTimeRef:n,paused:i,postWorkerCommand:o,requestRender:r,storeRef:s,suspendWhenHidden:a}){const c=Mn(o);c.current=o;const l=Mn(r);l.current=r,Sn(()=>{const o=s.current;o&&(t.setPaused(i),o.setPaused(i),i&&(n.current=null,e()),c.current({type:"setPaused",paused:i},!1),l.current())},[e,t,i]),Sn(()=>{if(!a){const e=s.current;return t.setVisible(!0),void(e&&!e.snapshot().visible&&(e.setVisible(!0),c.current({type:"setVisible",visible:!0},!1),l.current()))}if("undefined"==typeof document)return;const i=()=>{const i=s.current;if(!i)return;const o=kn();t.setVisible(o),i.setVisible(o),o||(n.current=null,e()),c.current({type:"setVisible",visible:o},!1),l.current()};return i(),document.addEventListener("visibilitychange",i),()=>document.removeEventListener("visibilitychange",i)},[e,t,a])}({cancelRender:It,frameRuntime:Tt,lastFrameTimeRef:at,paused:me,postWorkerCommand:Hn,requestRender:Yn,storeRef:et,suspendWhenHidden:Ae}),an(()=>()=>gn("unmount",!1),[gn]),an(()=>{mn()},[mn]),cn(t,()=>({...et.current.controls(),applyImpulse:(e,t,n)=>{et.current.applyImpulse(e,t,n),Hn({type:"applyImpulse",id:e,ix:t,iy:n}),Yn()},clear:()=>{et.current.clear(),De.current.clear(),Lt.current.clear(),Hn({type:"clear"}),Yn()},clearRegionState:e=>{e?De.current.delete(e):De.current.clear(),Yn()},getData:()=>et.current.readBodies(),getRegionState:e=>e?Pn(De.current.get(e)):function(e){const t={};return e.forEach((e,n)=>{const i=Pn(e);i&&(t[n]=i)}),t}(De.current),getStore:()=>et.current,pause:()=>{Tt.setPaused(!0),at.current=null,It(),et.current.setPaused(!0),Hn({type:"setPaused",paused:!0},!1),Yn()},push:(e,t)=>{et.current.enqueue(e,t),yn(t)?Hn({type:"enqueue",spawns:[e],pacing:t}):(ht.current||bt.current)&&gn("spawn pacing is not worker-cloneable"),Yn()},pushMany:(e,t)=>{et.current.enqueue(e,t),yn(t)?Hn({type:"enqueue",spawns:e,pacing:t}):(ht.current||bt.current)&&gn("spawn pacing is not worker-cloneable"),Yn()},popBodies:(e,t={})=>{const n=et.current,i=new Map(n.readBodies().map(e=>[e.id,e])),o=n.remove(e),r=qt.current();for(const e of o){const n=i.get(e);n&&(De.current.delete(e),Lt.current.set(e,{body:n,color:t.color??"#f59e0b",durationMs:Math.max(120,t.durationMs??520),radius:t.radius??An(n),scale:null!=t.scale&&t.scale>0?t.scale:1,startedAt:r}),Wt.current===e&&(Wt.current=null,Dt(null)),zt(t=>t?.id===e?null:t))}return o.length&&(Hn({type:"remove",ids:o}),Yn()),o},remove:e=>{const t=et.current.remove(e);for(const t of e)De.current.delete(t);return Hn({type:"remove",ids:e}),Yn(),t},restore:e=>{et.current.restore(e),De.current.clear(),Lt.current.clear(),Hn({type:"restore",snapshot:e},!1),Yn()},resume:()=>{Tt.setPaused(!1),at.current=null,et.current.setPaused(!1),Hn({type:"setPaused",paused:!1},!1),Yn()},settle:e=>{const t=et.current.settle(e);return Hn({type:"settle",maxSteps:e}),Yn(),t},settleWithObservations:e=>{const t=et.current.settleWithObservations(e);return Hn({type:"settle",maxSteps:e}),Yn(),t},step:e=>{const t=et.current,n=t.tick(e);return Fn({store:t,result:n,regionEffects:Ne.current,regionState:De.current,bodyForces:ze.current,composed:Le.current,onTick:We.current}),Hn({type:"tick",deltaSeconds:e}),mn(),n}}),[It,Tt,mn,Hn,Yn,gn]);const Vn=S||!Ot&&Et,_n=["stream-physics-frame",z?"stream-physics-frame--mode-"+z:null,N?"stream-physics-frame--emphasis-"+N:null,I].filter(Boolean).join(" "),Un=D??("string"==typeof Ce?Ce:void 0)??"Physics chart",Kn=ut+"-physics-table",Gn=Math.max(1,Rt[0]-xt.left-xt.right),Qn=Math.max(1,Rt[1]-xt.top-xt.bottom),Zn=W&&Nt?Pe?Pe(Nt):li(ri,{hover:Nt}):null,Jn=Zn&&Nt?li(l,{x:Nt.x-xt.left,y:Nt.y-xt.top,containerWidth:Math.max(1,Rt[0]-xt.left-xt.right),containerHeight:Math.max(1,Rt[1]-xt.top-xt.bottom),margin:xt,className:"stream-physics-tooltip",children:Zn}):null;if(Vn){const e=et.current??xn(rt,X,V),t="string"==typeof Ce?Ce:void 0,{svg:n}=Ft(e,{width:Rt[0],height:Rt[1],title:t,description:D,background:m||"transparent"===s?void 0:s,backgroundGraphics:At,className:"stream-physics-frame__svg",foregroundGraphics:Bt,idPrefix:"physics-"+ut,margin:xt});return di("div",{ref:Ct,className:_n,"data-semiotic-mode":z,role:"img","aria-label":Un,style:{width:Rt[0],height:Rt[1]},children:[li(h,{summary:Ie}),li("div",{dangerouslySetInnerHTML:{__html:n}})]})}return di("div",{ref:Ct,className:_n,"data-semiotic-mode":z,role:"group","aria-label":Un,"aria-describedby":jt?Ht:void 0,tabIndex:0,style:{position:"relative",width:Rt[0],height:Rt[1]},onKeyDown:Zt,children:["production"!==process.env.NODE_ENV&&et.current&&li(u,{store:et.current,diagnostics:lt.current}),n?li(p,{tableId:Kn}):null,n?li(ci,{chartTitle:"string"==typeof Ce?Ce:Un,items:Qe,tableId:Kn}):null,li(h,{summary:Ie}),li(a,{hoverPoint:Nt}),li("div",{id:Ht,"aria-live":"polite","aria-atomic":"true",style:$n,children:jt?jt.description??jt.label:""}),di("div",{role:"img","aria-label":Un,style:{position:"relative",width:"100%",height:"100%"},children:[li(c,{size:Rt,margin:xt,children:At}),li("canvas",{ref:hn,width:Rt[0],height:Rt[1],"aria-hidden":"true",style:{position:"absolute",left:0,top:0,display:"block"},onPointerDown:Qt,onPointerMove:W?Gt:void 0,onPointerLeave:W?Ut:void 0}),Bt,li(re,{width:Gn,height:Qn,totalWidth:Rt[0],totalHeight:Rt[1],margin:xt,title:Ce,legend:_,legendPosition:ee,legendLayout:J,legendHoverBehavior:Q,legendClickBehavior:U,legendHighlightedCategory:G,legendIsolatedCategories:Z,pointNodes:en,annotations:i,onAnnotationActivate:o,onObservation:oe,chartId:M,chartType:mi,autoPlaceAnnotations:r,svgAnnotationRules:Be}),li(d,{active:null!=jt,hoverPoint:jt?{x:jt.x,y:jt.y}:null,margin:xt,size:Rt,shape:jt?.shape,width:jt?.width,height:jt?.height,pathData:jt?.pathData}),Jn]})]})}));fi.displayName="StreamPhysicsFrame";var yi=fi;import{scaleLinear as gi}from"d3-scale";function bi(e){const[t,n]=e,i=160>t||116>n,o=i?Math.min(12,Math.max(2,.08*t)):32,r=i?Math.min(8,Math.max(2,.12*n)):24,s=i?r:34;return{width:t,height:n,plot:{x:o,y:r,width:Math.max(1,t-2*o),height:Math.max(1,n-r-s)}}}function vi(e){const t=(e??"")+"";if(!t)return"#4e79a7";const n=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let e=0;t.length>e;e+=1)i=31*i+t.charCodeAt(e)>>>0;return n[i%n.length]}function xi(e,i="#4e79a7",o){const r=o?.styleRules,s=!!r&&r.length>0,a=s?t(o?.valueAccessor):void 0;return t=>{const o=t.datum,c=o&&e?"function"==typeof e?e(o,0):o[e]:void 0,l={fill:null==c?i:vi(c),stroke:"#111827",strokeWidth:1,opacity:.9};return s&&o&&Object.assign(l,n(o,r,{value:a?a(o):void 0,category:null==c?void 0:c+""})),l}}function wi(e,t,n,i){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:n},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...i}}}function Si(e,t,n){if(!e.length)return[];const i=bi(t),o=i.plot.width/Math.max(1,e.length),r=Math.max(1,...e.map(e=>e.value)),s=.62*i.plot.height,a=i.plot.y+i.plot.height;return e.map((e,t)=>{const c=Math.max(8,e.value/r*s),l=`${n} ${e.label}: ${e.value}${null==e.secondary?"":`, ${e.secondary} secondary`}`;return{id:`${n}-${e.label}`,label:l,description:l,datum:e,x:i.plot.x+(t+.5)*o,y:a-c/2,shape:"rect",width:Math.max(12,.58*o),height:c,group:n}})}function Mi(e,t,n){return"function"==typeof n?n(e,t):e[n]}function ki(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:null}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ii(e,t,n){return Math.max(t,Math.min(n,e))}function Ai(e,t){const n=ki(e);return null!=n&&n>0?n:t}function Bi(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Ci(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function Pi(e){const t=Math.max(2,Math.round(e.bins)),n=Math.max(1,Math.round(e.pegRows??t-1)),i=Math.max(1,Math.round(e.count??Math.max(64,4*t))),o=Ii(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Ci(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:i},(e,t)=>{let i=0;for(let e=0;n>e;e+=1)r()<o&&(i+=1);const a=n/2;return{id:`${s}-${t}`,value:i,mechanical:!0,pegRows:n,branchProbability:o,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}function Ri(e){const{data:t,valueAccessor:n,bins:i,ballRadius:o,seed:r,size:s,valueExtent:a}=e,c=bi(s),l=t.map((e,t)=>ki(Mi(e,t,n))).filter(e=>null!=e),d=function(e){if(!e)return;const t=ki(e[0]),n=ki(e[1]);return null!=t&&null!=n?t>n?[n,t]:[t,n]:void 0}(a),u=d?.[0]??(l.length?Math.min(...l):0),h=d?.[1]??(l.length?Math.max(...l):1),p=h===u?1:h-u,m=gi().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),f=Array.from({length:i},()=>0),y=[];t.forEach((e,t)=>{const r=ki(Mi(e,t,n));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-u)/p*i)));f[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:m(s+.5),y:c.plot.y+o+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,value:r,bin:s}})});const g=c.plot.y+c.plot.height;return{config:wi(r,[...it({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...ot({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:m,yTop:c.plot.y-400,yBottom:g,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:f.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[u,h]}}}import{scaleLinear as Ti}from"d3-scale";function qi(e){const{count:t,idPrefix:n,wallThickness:i,xScale:o,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const c=Math.min(r-1,a?.(t)??s),l=Math.max(1,r-c);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:o(t),y:c+l/2,width:i,height:l}}})}function Oi(e){const{data:t,timeAccessor:n,arrivalAccessor:i,windows:o,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:d=1}=e,u=bi(c),h=t.map((e,t)=>ki(Mi(e,t,n))).filter(e=>null!=e),p=ki(l?.[0]),m=ki(l?.[1]),f=h.length?Math.min(...h):0,y=h.length?Math.max(...h):f+o.size,g=Math.min(p??f,f),b=Math.max(m??y,y),v=Math.floor(g/o.size)*o.size,x=Math.max(1,Math.ceil((b-v+o.size)/o.size)),w=h.length?Math.max(...h):0,S="function"==typeof r?r(w):ki(r?.value)??w-(r?.delay??o.size),M=Math.max(0,Math.min(x,Array.from({length:x},(e,t)=>t).reduce((e,t)=>v+(t+1)*o.size>S?e:e+1,0))),k=function(e,t){const n=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:n,height:e.plot.height},windowPlot:{x:e.plot.x+n,y:e.plot.y,width:Math.max(40,e.plot.width-n),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(u,s),I=v+x*o.size,A=Ti().domain([v,I]).range([k.windowPlot.x,k.windowPlot.x+k.windowPlot.width]),B=Array.from({length:x},()=>({value:0,secondary:0})),C=[];t.forEach((e,t)=>{const r=ki(Mi(e,t,n));if(null==r)return;const a=ki(Mi(e,t,i))??r,c=Math.max(0,Math.min(x-1,Math.floor((r-v)/o.size))),l=S>=v+(c+1)*o.size;B[c].value+=l?0:1,B[c].secondary+=l?1:0,C.push({id:(e.id??"event-"+t)+"",x:Math.max(k.windowPlot.x+s,Math.min(k.windowPlot.x+k.windowPlot.width-s,A(r))),y:u.plot.y+s+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...e,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const P=u.plot.y+u.plot.height,R=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const i=e.windowStart,o=e.windowStart+e.windowCount*e.windowSize,r=Ti().domain([i,o]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+n*e.windowSize),a=e.windowPlot.x,c=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),l=e=>s===a?t:c+(e-a)/(s-a)*(t-c),d=[];for(let t=0;n>t;t+=1){const n=e.windowStart+t*e.windowSize,i=n+e.windowSize,o=r(n),s=r(i);d.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:o,y1:l(o),x2:s,y2:l(s)})}return d}({closedWindowCount:M,gutter:k.gutter,plot:u.plot,windowCount:x,windowPlot:k.windowPlot,windowSize:o.size,windowStart:v},u.plot.y+.28*u.plot.height);return{config:wi(a,[...it({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...qi({idPrefix:"eventdrop-window",count:x,xScale:e=>A(v+e*o.size),yTop:k.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>M)return null;const t=0===e?R[0]?.y1:R[e-1]?.y2??R[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?k.wallTop:t+1.25*s},yBottom:P,wallThickness:6}),...R.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:C,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:d},projectionRows:B.map((e,t)=>({label:`${v+t*o.size}-${v+(t+1)*o.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:k.gutter,lidSegments:R,lateCount:B.reduce((e,t)=>e+t.secondary,0),plot:u.plot,windowPlot:k.windowPlot,watermarkValue:S,windowCount:x,windowSize:o.size,windowStart:v}}}function Ei(e,t,n,i){const o=ki(Mi(e,t,i.timeAccessor));if(null==o)return null;const r=ki(Mi(e,t,i.arrivalAccessor))??o,{windowPlot:s,windowStart:a,windowCount:c,windowSize:l,watermarkValue:d}=n,u=a+c*l,h=Ti().domain([a,u]).range([s.x,s.x+s.width]),p=Math.max(0,Math.min(c-1,Math.floor((o-a)/l))),m=d>=a+(p+1)*l,{ballRadius:f}=i;return{id:(e.id??"event-push-"+t)+"",x:Math.max(s.x+f,Math.min(s.x+s.width-f,h(o))),y:s.y+f+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,shape:{type:"circle",radius:f},datum:{...e,eventTime:o,arrivalTime:r,windowIndex:p,late:m}}}function Fi(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),n=t.length?t:["Intake"],i=Math.max(n.length,Math.round(e.count??Math.max(48,12*n.length))),o=Ai(e.unitValue,1),r=Ci(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),c=a.reduce((e,t)=>e+t,0)||1,l=i-n.length,d=a.map(e=>e/c*l),u=d.map(e=>1+Math.floor(e));let h=i-u.reduce((e,t)=>e+t,0);const p=d.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%p.length)u[p[e].index]+=1,h-=1;return n.map((e,t)=>({id:`${s}-${t}`,category:e,value:u[t]*o,mechanical:!0,unitCount:u[t],unitValue:o,share:u[t]/i}))}function ji(e,t,n){const i=e.width/Math.max(1,t),o=Math.max(2,2*n),r=Math.min(.7*i,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(r/o));return{laneWidth:i,tubeWidth:r,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*i,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}function Di(e){const{data:t,categoryAccessor:n,valueAccessor:i,unitValue:o,ballRadius:r,seed:s,size:a}=e,c=Ai(o,1),l=bi(a),d=[],u=new Map,h=new Map,p=[];function m(e){let t=u.get(e);return null==t&&(t=d.length,d.push(e),u.set(e,t)),t}t.forEach((e,t)=>{m((Mi(e,t,n)??"unknown")+"")});const f=Math.max(1,d.length),y=ji(l.plot,f,r),g=Math.max(0,y.tubeWidth/2-r-1),b=d.map(()=>[]);t.forEach((e,t)=>{const o=(Mi(e,t,n)??"unknown")+"",s=m(o),a=i?ki(Mi(e,t,i)):1,d=Math.max(0,Math.round((a??0)/c)),u=y.centerX(s);for(let n=0;d>n;n+=1){const i=h.get(o)??0,a=y.perRow>1?((y.perRow>1?i%y.perRow:0)/(y.perRow-1)*2-1)*g:0;h.set(o,i+1),b[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:u+a,y:l.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:o,unitIndex:n}})}});const v=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;v>e;e+=1)for(const t of b)t.length>e&&p.push(t[e]);const x=l.plot.y+l.plot.height,w=[...it({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],S=l.plot.y-400;for(let e=0;f>e;e+=1){const t=y.centerX(e);for(const n of[-1,1])w.push({id:`pile-tube-${e}-${0>n?"l":"r"}`,shape:{type:"aabb",x:t+n*y.tubeWidth/2,y:(S+x)/2,width:6,height:x-S}})}return{config:wi(s,w,"UnitPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:h.get(e)??0}))}}import{scaleLinear as Ni}from"d3-scale";function zi(e){const{data:t,xAccessor:n,groupAccessor:i,radiusAccessor:o,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:d}=e,u=bi(a),h=Ci(s),p=[],m=[],f=new Map;t.forEach((e,t)=>{const s=ki(Mi(e,t,n));if(null==s)return;const a=i?(Mi(e,t,i)??"All")+"":"All",c=o?ki(Mi(e,t,o)):null,l=Ii(null!=c&&c>0?c:r,2,18);!function(e){let t=f.get(e);null==t&&(t=m.length,m.push(e),f.set(e,t))}(a),p.push({datum:e,index:t,value:s,group:a,radius:l})});const y=p.map(e=>e.value),g=c?ki(c[0]):null,b=c?ki(c[1]):null,v=y.length?Math.min(...y):0,x=y.length?Math.max(...y):1;let w=g??v,S=b??x;if(w===S&&(w-=.5,S+=.5),w>S){const e=S;S=w,w=e}const M=Math.max(r,...p.map(e=>e.radius)),k=u.plot.x+M+8,I=u.plot.x+u.plot.width-M-8,A=Ni().domain([w,S]).range([k,I]),B=Math.max(1,m.length),C=Math.min(Math.max(28,3*M),u.plot.height/4),P=u.plot.y+C,R=Math.max(0,u.plot.y+u.plot.height-C-P),T=e=>{const t=f.get(e)??0;return 1===B?u.plot.y+.54*u.plot.height:P+t/(B-1)*R},q=new Map,O=p.map((e,t)=>{q.set(e.group,(q.get(e.group)??0)+1);const n=A(e.value),i=T(e.group),o=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:d?n+o:Ii(n+(t%9-4)*e.radius*2.5,k,I),y:d?i+r:u.plot.y-18-t%12*e.radius,vx:d?0:22*(h()-.5),vy:d?0:24+18*h(),mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:n,targetY:i},springs:[{target:{type:"point",x:n,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:wi(s,it({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*M),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:O,projectionRows:m.map(e=>({label:e,value:q.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,S],xRange:[k,I],groups:m.map(e=>({label:e,y:T(e),count:q.get(e)??0})),plot:u.plot}}}function Wi(e){if(Array.isArray(e)&&e.length>=2){const t=ki(e[0]),n=ki(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=ki(t.x),i=ki(t.y);return null!=n&&null!=i?{x:n,y:i}:null}return null}function $i(e){return Array.isArray(e)?e.map(Wi).filter(e=>null!=e):[]}function Li(e,t,n){return"normalized"===n?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Ii(e.x,t.plot.x,t.plot.x+t.plot.width),y:Ii(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Hi(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}function Yi(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=Ii(t,0,1)*Hi(e);let i=0;for(let t=1;e.length>t;t+=1){const o=e[t-1],r=e[t],s=Math.hypot(r.x-o.x,r.y-o.y);if(s>0){if(i+s>=n){const e=(n-i)/s;return{x:o.x+(r.x-o.x)*e,y:o.y+(r.y-o.y)*e}}i+=s}}return{...e[e.length-1]}}function Xi(e,t){const n=Yi(e,Math.max(0,t-.02)),i=Yi(e,Math.min(1,t+.02)),o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{x:o/s,y:r/s}}function Vi(e){const{coordinateMode:t,flowSpeed:n,links:i,maxParticles:o,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:d,pathAccessor:u,pathConstraint:h="path",reducedMotion:p,seed:m,size:f,sourceAccessor:y,targetAccessor:g,throughputAccessor:b}=e,v=bi(f),x=Ci(m),w=new Map,S=new Map,M=[];function k(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof r){const e=r(t,0);if(null!=e)return e+""}if("string"==typeof r&&null!=t[r])return t[r]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}c.forEach((e,t)=>{const n=(Mi(e,t,r)??e.id??t)+"",i=ki(Mi(e,t,s)),o=ki(Mi(e,t,a));if(null!=i&&null!=o){const e={x:i,y:o};w.set(n,e),M.push(e)}S.set(n,(e.label??e.name??n)+"")});const I=[];i.forEach((e,t)=>{const n=k(Mi(e,t,y)),i=k(Mi(e,t,g)),o=Math.max(0,ki(Mi(e,t,b))??0),r=$i(u?Mi(e,t,u):void 0),s=r.length?r:$i(e.path??e.points??e.route);s.forEach(e=>M.push(e)),I.push({id:(e.id??`physical-flow-${n}-${i}-${t}`)+"",link:e,index:t,source:n,target:i,throughput:o,rawPath:s})});const A=(C=M,"normalized"===(B=t)||"pixels"===B?B:C.length>0&&C.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var B,C;const P=new Map;for(const[e,t]of w)P.set(e,Li(t,v,A));const R=[];for(const e of I){let t=e.rawPath.map(e=>Li(e,v,A));if(2>t.length){const n=P.get(e.source),i=P.get(e.target);n&&i&&(t=[n,i])}else P.has(e.source)||P.set(e.source,t[0]),P.has(e.target)||P.set(e.target,t[t.length-1]);t.length>=2&&e.throughput>0&&(S.has(e.source)||S.set(e.source,e.source),S.has(e.target)||S.set(e.target,e.target),R.push({...e,path:t,packetCount:0}))}const T=Ai(d,.12),q=Math.max(1,Math.round(o)),O=R.map(e=>Math.max(1,Math.round(e.throughput*T))),E=O.reduce((e,t)=>e+t,0),F=E>q?q/E:1;R.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(O[t]*F))});let j=R.reduce((e,t)=>e+t.packetCount,0);for(;j>q;){const e=R.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>R[e].packetCount)?n:e,-1);if(-1===e)break;R[e].packetCount-=1,j-=1}const D=new Map,N=new Map,z=[],W=Ai(n,90),$=Ai(l,4);R.forEach((e,t)=>{D.set(e.target,(D.get(e.target)??0)+e.throughput),N.set(e.source,(N.get(e.source)??0)+e.throughput);const n=Hi(e.path);for(let i=0;e.packetCount>i;i+=1){const o=(i+.5)/e.packetCount,r=p?o:Ii(.12+.84*o+.04*(x()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*x())),a=Yi(e.path,s),c=Yi(e.path,r),l=Xi(e.path,s),d={x:-l.y,y:l.x},u=(x()-.5)*$*1.5;z.push({id:`${e.id}-packet-${i}`,x:a.x+d.x*u,y:a.y+d.y*u,vx:p?0:l.x*W+10*(x()-.5),vy:p?0:l.y*W+10*(x()-.5),mass:.8,spawnAt:p?0:.04*t+i/32,shape:{type:"circle",radius:$},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:i,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:W,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*$,stiffness:26,damping:4.25}]:void 0})}});const L=Math.max(18,5*$),H=Array.from(P,([e,t])=>({nodeId:e,label:S.get(e)??e,sensorId:"physical-flow-node-"+Bi(e),point:t})),Y=H.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:L,height:L}})),X=Object.fromEntries(H.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),V=wi(m,[...it({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...Y],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*$),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});V.bodyLimit=q,V.eviction="oldest",V.observation={...V.observation,sensors:X};const _=Array.from(P,([e,t])=>({id:e,label:S.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+Bi(e),incoming:D.get(e)??0,outgoing:N.get(e)??0})),U=R.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:V,initialSpawns:z,projectionRows:_.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:A,particleCount:z.length,totalThroughput:R.reduce((e,t)=>e+t.throughput,0),plot:v.plot,nodes:_,links:U}}}function _i(e,t){if("region-enter"!==t.type)return e;const n=t.region.id,i=e[n]??{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;const o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function Ui(e,t){return(t??Object.keys(e)).map(t=>e[t]).filter(e=>null!=e).map(e=>({label:e.label??e.id,value:e.count}))}function Ki(e,t){const n=t instanceof Set?t:new Set(t);return e.map(e=>{const t=e.bodyIds??[],i=t.filter(e=>!n.has(e)),o=t.length-i.length,r=e.completion?.mode??"allMembersAbsorbed",s=e.completion?.valueByBodyId,a=e=>{const t=s?.[e];return Number.isFinite(t)&&Number(t)>=0?Number(t):1},c=t.reduce((e,t)=>e+a(t),0),l=t.reduce((e,t)=>e+(n.has(t)?a(t):0),0),d=e.completion?.threshold,u="threshold"===r?Number.isFinite(d)&&Number(d)>=0?Number(d):c:void 0;return{id:e.id,label:e.label??e.id,mode:r,complete:t.length>0&&("anyAbsorbed"===r?o>0:"threshold"===r?l>=(u??c):0===i.length),absorbed:o,total:t.length,absorbedValue:l,totalValue:c,threshold:u,missing:i}})}function Gi(e,t,n){return Math.max(t,Math.min(n,e))}function Qi(e,t,n={}){const i=n.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],r=Gi(n.along??.5,.05,.95),s=n.jitterX??0,a=n.padY??20,c=o.x0+(o.x1-o.x0)*r+(2*i()-1)*s,l=Math.min(1,o.width/2),d=Gi(c,o.x0+l,o.x1-l),u=e.boundaryY(d,"top")+a,h=e.boundaryY(d,"bottom")-a;return{x:d,y:h>u?u+i()*Math.max(1,h-u):e.midY}}function Zi(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function Ji(e,t,n){return Math.max(t,Math.min(n,e))}function eo(e,t,n,i,o,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:i,y2:o,thickness:r.thickness??8}}}function to(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height)),o=e.padX??46,r=e.padY??72,s=o,a=n-o,c=r,l=i-Math.max(24,Math.round(.45*r)),d=(c+l)/2,u=Math.max(1,l-c),h=Ji(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),m=Number.isFinite(p)?p:0,f=Ji(u*h+m,.06*u,.5*u),y=f/2,g=d-y,b=d+y,v=e.idPrefix??"process",x=e.friction??.58,w=e.restitution??.18,S=e.wallThickness??8,M=e.stages;if(!M.length)throw Error("processStageLayout requires at least one stage");const k=Ji(e.centerStageIndex??Math.floor(M.length/2),0,M.length-1),I=function(e){const t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(M),A=a-s;let B=s;const C=M.map((e,t)=>{const n=B,i=t===M.length-1?a:B+(e.share??1)/I*A;return B=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:i,x:(n+i)/2,width:i-n,y:d,height:u}}),P=C[k],R=P.x0,T=P.x1,q=(e,n)=>{if("lane"===t)return"top"===n?c:l;if("funnel"===t){const t=Ji((e-s)/Math.max(1,a-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if(R>=e){const t=Ji((e-s)/Math.max(1,R-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if(T>=e)return"top"===n?g:b;const i=Ji((e-T)/Math.max(1,a-T),0,1);return"top"===n?g+(c-g)*i:b+(l-b)*i},O=C.map(e=>{const t=Math.min(q(e.x0,"top"),q(e.x1,"top")),n=Math.max(q(e.x0,"bottom"),q(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),E={thickness:S,friction:x,restitution:w},F=[];"lane"===t?F.push(eo(v+"-top",s,c,a,c,E),eo(v+"-bottom",s,l,a,l,E),eo(v+"-left",s,c,s,l,{...E,thickness:Math.max(6,S-2)}),eo(v+"-right",a,c,a,l,{...E,thickness:Math.max(6,S)})):"funnel"===t?F.push(eo(v+"-top",s,c,a,g,E),eo(v+"-bottom",s,l,a,b,E),eo(v+"-left",s,c,s,l,{...E,thickness:Math.max(6,S-2)}),eo(v+"-right",a,g,a,b,{...E,thickness:Math.max(6,S)})):F.push(eo(v+"-left-top",s,c,R,g,E),eo(v+"-left-bottom",s,l,R,b,E),eo(v+"-center-top",R,g,T,g,E),eo(v+"-center-bottom",R,b,T,b,E),eo(v+"-right-top",T,g,a,c,E),eo(v+"-right-bottom",T,b,a,l,E),eo(v+"-left",s,c,s,l,{...E,thickness:Math.max(6,S-2)}),eo(v+"-right",a,c,a,l,{...E,thickness:Math.max(6,S)}));const j=e.membraneDampingScale??.5,D=s,N=Math.max(1,("bowtie"===t?R:a)-D),z=(e.membranes??[]).map(e=>{const t=D+Ji(e.offset,0,1)*N,n=e.width??18+18*e.cost,i=u-16,o=d+.25*(e.wobble??0);return{...e,x:t,y:o,width:n,height:i}}),W=!1===e.includeMembraneRegions?[]:z.map(e=>oo({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??j,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:i,padX:o,padY:r,left:s,right:a,topY:c,bottomY:l,midY:d,centerLeft:R,centerRight:T,pinchHeight:f,pinchTop:g,pinchBottom:b,stages:O,membranes:z,colliders:F,regionEffects:W,boundaryY:q}}function no(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,i=e.width,o=e.height,{type:"aabb",x:t,y:n,width:i,height:o}),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:e.attributes,onEnter:e.onEnter,onExit:e.onExit};var t,n,i,o}function io(e,t={}){const n=t.idPrefix??"stage",i=Math.max(0,t.insetX??0),o=Math.max(0,t.insetY??1);return e.stages.map(e=>{const r="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...no({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*i),height:Math.max(1,e.height-2*o),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...r,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function oo(e){const t=e.dampingScale??.5,n=e.energyScale??1,i=Ji(e.cost,0,2);return{...no({...e,kind:e.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:i*t,energyDelta:-i*n}}function ro(e){return{...no({...e,kind:e.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function so(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...no({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function ao(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,i=e.dampingPerUnit??.12,o=e.energyPerUnit??0;return{...no({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*i,energyDelta:o?-t*o:void 0,force:e.force}}function co(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...no({...e,kind:e.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function lo(e){return{...no({...e,kind:e.kind??"force-field",attributes:{primitive:"portal",targetStage:e.targetStage,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function uo(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...no({...e,kind:e.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function ho(e){return{...no({...e,kind:e.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function po(e){const t=e.x??e.anchor?.x??0,n=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function mo(e){const t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},i=[eo(t+"-top",e.left,e.top,e.right,e.top,n),eo(t+"-bottom",e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||i.push(eo(t+"-left",e.left,e.top,e.left,e.bottom,n),eo(t+"-right",e.right,e.top,e.right,e.bottom,n)),i}function fo(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function yo(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,i=bi(n),o=Ii(e.ballRadius??6,2,18),r=e.seed??1,s=Ci(r),a=e.idAccessor,c=e.stageAccessor??"stage",l=e.groupBy,d=e.groupLabelAccessor,u=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(l?"allAbsorbed":"none"),m=e.springStiffness??.28,f=e.springDamping??.72,y=!0===e.settle,g=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),b=to({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:g,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),v=new Map(b.stages.map((e,t)=>[e.id,t])),x=new Map(b.stages.map(e=>[e.id,e])),w=b.stages[0].id,S=b.stages[0],M=new Set(t.filter(e=>e.absorb).map(e=>e.id)),k=t.map(e=>{const t=x.get(e.id)??S;return function(e,t){const n={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return uo({...n,kind:e.kind??"sink",force:fo(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(e.portal){const t=e.portal.force??e.force??{x:-40,y:0};return lo({...n,kind:e.kind??"force-field",force:fo(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return co({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:fo(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...n.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){const t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return ao({...n,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:fo(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?so({...n,kind:e.kind??"force-field",force:fo(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):ho({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:b.midY,width:t.width,height:b.bottomY-b.topY})});k.unshift(so({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const I=new Map;for(const e of b.stages)I.set(e.id,0);const A=[];e.data.forEach((e,t)=>{const n=(a?Mi(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",i=(Mi(e,t,c)??w)+"",r=v.has(i)?i:w;I.set(r,(I.get(r)??0)+1);const s=l?(Mi(e,t,l)??"")+"":void 0,p=s&&d?(Mi(e,t,d)??s)+"":s,m=u?ki(Mi(e,t,u))??1:1,f=h?ki(Mi(e,t,h)):null,y=Ii(null!=f&&f>0?f:o,2,18);A.push({datum:e,id:n,stageId:r,groupId:s||void 0,groupLabel:p||void 0,work:m,radius:y,index:t})});const B=new Map,C=new Map;for(const e of A){if(!e.groupId)continue;const t=B.get(e.groupId)??[];t.push(e.id),B.set(e.groupId,t),e.groupLabel&&C.set(e.groupId,e.groupLabel)}const P=Ii(e.groupAnchorAlong??.55,.15,.9),R=b.left+(b.right-b.left)*P,T=Array.from(B.keys()),q=T.map((e,n)=>{const i=B.get(e)??[],o=T.length>1?b.topY+28+n/Math.max(1,T.length-1)*(b.bottomY-b.topY-56):b.midY;return po({id:e,label:C.get(e)??e,bodyIds:i,anchor:{x:R,y:o},x:R,y:o,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),O=Ki(q,A.filter(e=>M.has(e.stageId)).map(e=>e.id)),E=new Map(q.map(e=>[e.id,e])),F=A.map((e,t)=>{const n=x.get(e.stageId)??S,i=n.x+(s()-.5)*Math.min(24,.2*n.width),o=b.boundaryY(i,"top")+e.radius+10,r=b.boundaryY(i,"bottom")-e.radius-10,a=r>o?o+s()*Math.max(1,r-o):b.midY,c=y?i:b.left+18+t%7*4,l=y?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,d=[{target:{type:"point",x:i,y:a},restLength:.45*e.radius,stiffness:m,damping:f}];if(e.groupId){const t=E.get(e.groupId);t?.anchor&&!M.has(e.stageId)&&d.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:c,y:l,vx:y?0:40+40*s(),vy:y?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:y?0:.03*t,springs:d,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),j={kernel:{seed:r,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:b.colliders,fixedDt:1/60,maxSubsteps:8},D=b.stages.map(e=>({label:e.label??e.id,value:I.get(e.id)??0})),N=t.map(e=>{const t=x.get(e.id)??S;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:I.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:j,initialSpawns:F,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:D,metadata:{kind:"process-flow",plot:i.plot,volume:b,stages:N,groups:q,groupCompletion:O,regionEffects:k}}}import{forwardRef as go,useCallback as bo,useMemo as vo,useRef as xo}from"react";import{useImperativeHandle as wo,useRef as So}from"react";function Mo(e,t){if(!t?.length)return[e];const n=t.filter(t=>{if(t.id===e||t.id.startsWith(e+"-"))return!0;const n=t.datum;return!(!n||"object"!=typeof n||null==n.id)&&n.id+""===e}).map(e=>e.id);return n.length?n:[e]}function ko(e,t,n){if("function"==typeof n)return n(e,t)+"";if("string"==typeof n){const t=e[n];if(null!=t)return t+""}return null!=e&&"object"==typeof e&&"id"in e&&null!=e.id?e.id+"":"physics-row-"+t}function Io(e,t){const n=e?.getData().find(e=>e.id===t),i=n?.datum;if(i&&"object"==typeof i)return i}function Ao(e,t){const{frameRef:n,spawnDatum:i,seedRows:o,idAccessor:r,bodyIdsForSeed:s,seedSpawns:a}=t,c=So(new Map),l=So(new Map),d=So(""),u=o?o.map((e,t)=>ko(e,t,r)).join("\0"):"";if(u!==d.current&&(d.current=u,o))for(let e=0;o.length>e;e+=1){const t=o[e],n=ko(t,e,r);c.current.set(n,t),l.current.set(n,s?.(t,n,e)??Mo(n,a))}wo(e,()=>{const e=c.current,t=l.current;function o(e,t){const n=i(e,t);return{datumId:n.datumId||ko(e,t,r),spawns:n.spawns.map(e=>({...e,spawnAt:void 0}))}}function s(i){const o=[];for(const{datum:n,result:r}of i)e.set(r.datumId,n),t.set(r.datumId,r.spawns.map(e=>e.id)),o.push(...r.spawns);if(!o.length)return;const r=n.current;r?(r.pushMany(o),r.step(0)):"production"!==process.env.NODE_ENV&&console.warn("[semiotic/physics] push() called before the physics frame mounted (loading/empty early-return). Omit data for push mode and ensure the chart is mounted.")}function a(i){const o=e.get(i);if(o)return o;const r=t.get(i)??[i];for(const o of r){const r=Io(n.current,o);if(r)return e.set(i,r),t.has(i)||t.set(i,[o]),r}}return{push:t=>{s([{datum:t,result:o(t,e.size)}])},pushMany:t=>{const n=e.size;s(t.map((e,t)=>({datum:e,result:o(e,n+t)})))},remove:i=>{const o=Array.isArray(i)?i:[i],r=[],s=[];for(const n of o){const i=a(n);i&&r.push(i),e.delete(n),s.push(...t.get(n)??[n]),t.delete(n)}return s.length&&n.current?.remove(s),r},update:(i,r)=>{const c=Array.isArray(i)?i:[i],l=[];for(const i of c){const c=a(i);if(!c)continue;l.push(c);const d=t.get(i)??[i];n.current?.remove(d),e.delete(i),t.delete(i);const u=r(c);s([{datum:u,result:o(u,e.size)}])}return l},clear:()=>{e.clear(),t.clear(),d.current="",n.current?.clear()},getData:()=>{const t=n.current;if(!t)return Array.from(e.values());const i=t.getData().map(e=>e.datum).filter(e=>!!e&&"object"==typeof e);return i.length?i:Array.from(e.values())},getScales:()=>null,getCustomLayout:()=>n.current?.snapshot()??null,popBodies:(e,t)=>n.current?.popBodies(e,t)??[]}},[n,r,i])}import{useCallback as Bo,useEffect as Co,useMemo as Po,useRef as Ro,useState as To}from"react";import{Fragment as qo,jsx as Oo,jsxs as Eo}from"react/jsx-runtime";function Fo(e){return!!e&&"string"==typeof e.name}function jo(e,t=!1){if(!e?.datum)return null;const n=e.datum,i=n.sourceDatum;return t&&i&&"object"==typeof i?i:n}function Do(e){const{selection:t,linkedHover:n,colorBy:i,chartType:o,chartId:r,onBodyHover:s,fallbackFields:a,unwrapSourceDatum:c}=e,l="string"==typeof i?i:void 0,d=Fo(t)?t:void 0,{activeSelectionHook:u,customHoverBehavior:h}=T({selection:d,linkedHover:n,fallbackFields:l?[l]:a,onObservation:e.onObservation,onClick:e.onClick,chartType:o,chartId:r,colorByField:l}),p=Fo(t)?null:t??null,m=Po(()=>{if(p)return p;if(!u?.isActive)return null;const e=u.predicate;return{isActive:!0,predicate:t=>{const n=jo(t,c);return null!=n&&e(n)}}},[u?.isActive,u?.predicate,p,c]),f=Po(()=>{if(n||s)return(e,t)=>{if(s?.(e,t),!n)return;const i=jo(e,c);h(i&&t?{...t,data:i}:null)}},[h,s,n,c]);return Po(()=>({selection:m,onBodyHover:f}),[f,m])}var No=new Set(["sample","mechanical"]);function zo(e,t,n,i){const[o,r]=To(0),s=Ro(null),a=Ro(!1),c=function(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:null}(t),l=Ro(c),d=Ro(!!n),u=Ro(i);l.current=c,d.current=!!n,u.current=i;const h=Bo(()=>{null!=s.current&&(clearTimeout(s.current),s.current=null)},[]),p=Bo(()=>{h();const e=l.current;null!=e&&!d.current&&a.current&&(s.current=setTimeout(()=>{s.current=null,a.current=!1,u.current?.(),r(e=>e+1)},e))},[h]);Co(()=>{null==c||n?h():a.current&&p()},[h,c,n,p]),Co(()=>h,[h]);const m=e?.observation?.onSimulationStateChange,f=Bo((e,t)=>{if(m?.(e,t),"running"===e)return a.current=!1,void h();"settled"===e&&"running"===t&&(a.current=!0,p())},[h,m,p]);return{config:Po(()=>null==c?e:{...e,observation:{...e?.observation,onSimulationStateChange:f}},[e,c,f]),rerunKey:o}}function Wo(e,t,n){const i=n?.hasSimulationMode?function(e){const t=e=>"string"==typeof e&&No.has(e);return e.simulationMode?{chartMode:t(e.mode)?void 0:e.mode,simulationMode:e.simulationMode}:t(e.mode)?{chartMode:void 0,simulationMode:e.mode}:{chartMode:e.mode,simulationMode:"sample"}}({mode:e.mode,simulationMode:e.simulationMode}):{chartMode:"sample"===e.mode||"mechanical"===e.mode?void 0:e.mode,simulationMode:"sample"},o=R(i.chartMode,{width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:t[0],height:t[1]}),r=e.size?.[0],s=e.size?.[1],a=t[0],c=t[1],l=Po(()=>{return e=[a,c],(null!=r&&null!=s?[r,s]:void 0)??[o.width??e[0],o.height??e[1]];var e},[c,a,o.height,o.width,s,r]),d=o.compactMode?"sparkline"===i.chartMode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0};const u=e.showProjection??!o.compactMode,h=e.showChrome??!o.compactMode,p=Yo(e.tooltip,void 0),m=void 0!==p.enableHover?p.enableHover:o.enableHover,f=o.compactMode?o.title:o.title??e.title,y=[e.className,i.chartMode&&"primary"!==i.chartMode?"semiotic-physics--"+i.chartMode:null].filter(Boolean).join(" ")||void 0;return{chartMode:i.chartMode,simulationMode:i.simulationMode,resolved:o,chartSize:l,margin:d,showProjection:u,showChrome:h,enableHover:m,title:f,description:o.description??e.description,summary:o.summary??e.summary,accessibleTable:o.accessibleTable??e.accessibleTable,className:y,compactMode:o.compactMode,mobileInteraction:o.mobileInteraction,mobileSemantics:o.mobileSemantics}}function $o(e){const[t,n]=e.size;return L(e.loading,t,n,e.loadingContent)||$(e.data,t,n,e.emptyContent)}function Lo(e,t,n){return Oo(W,{componentName:e,width:t[0],height:t[1],children:n})}function Ho(e,t){return e?t?n=>Eo(qo,{children:["function"==typeof e?e(n):e,"function"==typeof t?t(n):t]}):e:t}function Yo(e,t){return!1===e?{enableHover:!1}:{enableHover:t?.enableHover,tooltipContent:M(e)||t?.tooltipContent}}function Xo(e,t,n,i){return{accessibleTable:i?.accessibleTable??e.accessibleTable??t?.accessibleTable,annotations:e.annotations??t?.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations??t?.autoPlaceAnnotations,background:e.background??t?.background,chartId:e.chartId??t?.chartId,chartMode:i?.chartMode??t?.chartMode,className:i?.className??e.className??t?.className,color:e.color??t?.color,description:i?.description??e.description??t?.description,emphasis:e.emphasis??t?.emphasis,enableHover:i?.enableHover??t?.enableHover,hoverRadius:e.hoverRadius??t?.hoverRadius,legend:e.legend??t?.legend,legendLayout:e.legendLayout??t?.legendLayout,legendPosition:e.legendPosition??t?.legendPosition,margin:i?.margin??t?.margin,onClick:null!=e.onClick?(t,n)=>{t&&e.onClick?.(t,{x:n.x,y:n.y})}:t?.onClick,onObservation:e.onObservation??t?.onObservation,onAnnotationActivate:t?.onAnnotationActivate,opacity:e.opacity??t?.opacity,selection:i?.selection??t?.selection,semanticItems:t?.semanticItems??n,stroke:e.stroke??t?.stroke,strokeWidth:e.strokeWidth??t?.strokeWidth,summary:i?.summary??e.summary??t?.summary,svgAnnotationRules:e.svgAnnotationRules??t?.svgAnnotationRules,title:i?.title??e.title??t?.title}}import{scaleLinear as Vo}from"d3-scale";function _o(e,t){const n=t.config??{},i=(t.sensors??[]).map(e=>({...e,sensor:!0})),o=[...t.colliders??[],...i],r=[...e.colliders??[],...n.colliders??[],...o];return{...e,...n,observation:{...e.observation,...n.observation},...r.length>0&&{colliders:r}}}function Uo(e){const t=function(e,t,n){const i=e?.observation;return{...e,observation:{...i,chartId:t??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:n??i?.onObservation}}}(e.config,e.chartId,e.onObservation),n=r(e.colorScheme,e.themeCategorical,C),i=bi(e.size),s={data:e.data,scales:{x:Vo().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:Vo().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:o(n,e.colorScheme),config:e.layoutConfig??{},world:new wt(t)},a=e.skipLayout?{}:e.layout(s)??{},c=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...i}=e,o=n.get(t)??[];o.push(i),n.set(t,o)}return e.map(e=>{const t=n.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...a.initialSpawns??a.bodies??[]],a.constraints);return{config:_o(t,a),context:s,initialSpawnPacing:a.initialSpawnPacing,initialSpawns:c,result:a}}import{jsx as Ko}from"react/jsx-runtime";var Go=go(function(e,t){const{chartId:n,color:i,colorBy:o,colorScheme:r,config:s,controllers:a,data:c,emptyContent:l,frameProps:d={},layout:u,layoutConfig:h,loading:p,loadingContent:m,onObservation:f,opacity:y,paused:g,spawnDatum:b,stroke:x,strokeWidth:w,title:S,xExtent:M,yExtent:k}=e,I=Wo(e,[700,380]),{chartSize:A,className:B,title:C,chartMode:P,margin:R,enableHover:T,description:q,summary:O,accessibleTable:E}=I,F=xo(null),j=xo(null),W=xo(""),{selection:$,onBodyHover:L}=Do({selection:e.selection,linkedHover:e.linkedHover,colorBy:o,chartType:"PhysicsCustomChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:d?.onBodyHover}),H=$o({data:c,emptyContent:l,loading:p,loadingContent:m,size:A}),Y=null!=H,X=vo(()=>v(c??[]),[c]),V=z(e=>e.theme),_=vo(()=>N(V)??{},[V]),U=V?.colors?.categorical??D.colors.categorical,K=vo(()=>[A[0],A[1],X.length,X.map((e,t)=>(e.id??t)+"").join("|"),M?.join(",")??"",k?.join(",")??""].join("::"),[A,X,M,k]),G=vo(()=>Uo({chartId:n,colorScheme:r,config:s,data:X,layout:u,layoutConfig:h,onObservation:f,semantic:_,skipLayout:Y,size:A,themeCategorical:U,xExtent:M,yExtent:k}),[n,A,r,s,u,h,f,X,_,Y,U,M,k]);W.current===K&&null!=j.current||(W.current=K,j.current=G.initialSpawns);const Q=j.current,Z=vo(()=>{const e=[...G.result.controllers??[],...a??[],...d.controllers??[]];return e.length?e:void 0},[d.controllers,a,G.result.controllers]),J=vo(()=>{const e=[...G.result.regionEffects??[],...d.regionEffects??[]];return e.length?e:void 0},[d.regionEffects,G.result.regionEffects]),ee=bo(e=>{const t=e.datum,n=t&&o?function(e,t,n){return"function"==typeof n?n(e,0):e[n]}(t,0,o)+"":e.id;return{fill:i??G.context.resolveColor(n,t),stroke:x??"#111827",strokeWidth:w??1,opacity:y??.9}},[i,o,y,G.context,x,w]);Ao(t,{frameRef:F,spawnDatum:bo((e,t)=>{const i=e;if(b)return function(e,t,n){return Array.isArray(n)?{datumId:(e.id??n[0]?.id??"physics-custom-"+t)+"",spawns:n}:"spawns"in n?n:{datumId:(e.id??n.id??"physics-custom-"+t)+"",spawns:[n]}}(e,t,b(i,t,G.context));const o=Uo({chartId:n,colorScheme:r,config:s,data:[i],layout:u,layoutConfig:h,onObservation:f,semantic:_,size:A,themeCategorical:U,xExtent:M,yExtent:k}),a=o.initialSpawns.length?o.initialSpawns:[{id:(e.id??"physics-custom-"+t)+"",x:o.context.dimensions.plot.x+o.context.dimensions.plot.width/2,y:o.context.dimensions.plot.y+12,mass:1,shape:{type:"circle",radius:5},datum:e}];return{datumId:(e.id??a[0].id)+"",spawns:a}},[n,A,r,s,b,u,h,f,G.context,_,U,M,k]),seedRows:X,seedSpawns:Q});const te=bo((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]);if(H)return H;const ne=Yo(e.tooltip,d),ie=Xo(e,d,G.result.semanticItems,{selection:$,chartMode:P,className:B,title:C??S,description:q,summary:O,accessibleTable:E,enableHover:T,margin:R});return Lo("PhysicsCustomChart",A,Ko(yi,{...d,...ne,...ie,ref:F,onBodyHover:L,backgroundGraphics:Ho(d.backgroundGraphics,G.result.backgroundOverlays),bodyForces:G.result.bodyForces??d.bodyForces,bodyStyle:G.result.bodyStyle??d.bodyStyle??ee,config:G.config,controllers:Z,foregroundGraphics:Ho(d.foregroundGraphics,G.result.overlays),initialSpawnPacing:G.initialSpawnPacing,initialSpawns:Q,onBodyPointerDown:te,paused:g,regionEffects:J,responsiveHeight:e.responsiveHeight,responsiveWidth:e.responsiveWidth,selectedBodyStyle:G.result.selectedBodyStyle??d.selectedBodyStyle,size:A}))});Go.displayName="PhysicsCustomChart";export{X as DEFAULT_PHYSICS_CANVAS_THEME,U as physicsCanvasColorWithAlpha,K as resolvePhysicsCanvasTheme,ne as bodiesToAnnotationAnchors,ie as buildPhysicsAnnotationContext,oe as normalizePhysicsAnnotations,re as PhysicsSVGOverlay,Ce as BuiltInPhysicsEngineAdapter,Pe as createDefaultPhysicsEngineAdapter,ze as PhysicsSedimentAccumulator,We as sedimentHeightfield,Le as evaluatePhysicsBodyBudget,Ke as schedulePhysicsSpawns,it as collidersFromPlotBounds,ot as collidersFromXScaleBins,wt as PhysicsPipelineStore,Mt as buildPhysicsSettledEvidence,Bt as physicsBodyToXYSceneNode,Ct as physicsBodiesToXYSceneNodes,Pt as buildPhysicsSettledScene,Ft as renderPhysicsSettledSVG,$t as createCapacityQueueController,Yt as createServiceResourcePoolController,Vt as createServiceLevelController,_t as createDependencyGateController,Kt as composePhysicsControllers,Gt as createPortalController,Jt as collidersFromPhysicsAnnotations,en as resolvePhysicsBodyAnnotations,tn as summarizePhysicsAnnotations,fi as StreamPhysicsFrame,yi as StreamPhysicsFrame_default,bi as physicsChartArea,xi as styleFromColorAccessor,Si as projectionRowsToSemanticItems,Pi as generateGaltonMechanicalSamples,Ri as buildGaltonBoardPhysics,Oi as buildEventDropPhysics,Ei as placeEventDropSpawn,Fi as generatePhysicsPileMechanicalSamples,ji as pileTubeGeometry,Di as buildPhysicsPile,zi as buildCollisionSwarmPhysics,Vi as buildPhysicalFlowPhysics,_i as aggregateRegionCounts,Ui as regionCountsToProjectionRows,Ki as groupCompletionRows,Qi as stageTargetInVolume,Zi as processVolumePolygons,to as processStageLayout,io as processStageRegions,oo as membraneRegion,ro as chargeGateRegion,so as routeSurfaceRegion,ao as pressureFieldRegion,co as capacitatedRegion,lo as portalRegion,uo as absorbRegion,ho as forceFieldRegion,po as bodyGroupSpec,mo as processLaneWalls,yo as buildProcessFlowPhysics,Ao as usePhysicsHocHandle,Do as usePhysicsSelection,zo as usePhysicsRerun,Wo as usePhysicsChartMode,$o as renderPhysicsChartState,Lo as renderPhysicsFrame,Ho as composePhysicsFrameGraphics,Yo as resolvePhysicsTooltipProps,Xo as resolvePhysicsFrameSharedProps,Go as PhysicsCustomChart};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{resolveCSSColor as n}from"./chunk-chunk-CWQ5YIHX.module.min.js";function r(n){const{background:r,hasBackgroundGraphics:t=!1,themeBackground:c=""}=n;return"transparent"===r||t?null:r||(c&&"transparent"!==c?c:"")||null}function t(t,c){const{background:o,hasBackgroundGraphics:u=!1,themeBackground:i="",x:a=0,y:e=0,width:d,height:h}=c,s=r({background:o,hasBackgroundGraphics:u,themeBackground:i});if(!s)return!1;const g=n(t,s);return!!g&&(t.fillStyle=g,t.fillRect(a,e,d,h),!0)}function c(n){return!!(n.dirtyOrRebuilt||n.transitioning||n.animationTicked||n.continuous||n.liveEncoding||n.forced)}function o(n,r){return n||r}export{r as resolveCanvasBackground,t as paintCanvasBackground,c as needsDataCanvasPaint,o as needsInteractionCanvasPaint};
2
+ import{resolveCSSColor as n}from"./chunk-chunk-7ZDJSYKI.module.min.js";function r(n){const{background:r,hasBackgroundGraphics:t=!1,themeBackground:c=""}=n;return"transparent"===r||t?null:r||(c&&"transparent"!==c?c:"")||null}function t(t,c){const{background:o,hasBackgroundGraphics:u=!1,themeBackground:i="",x:a=0,y:e=0,width:d,height:h}=c,s=r({background:o,hasBackgroundGraphics:u,themeBackground:i});if(!s)return!1;const g=n(t,s);return!!g&&(t.fillStyle=g,t.fillRect(a,e,d,h),!0)}function c(n){return!!(n.dirtyOrRebuilt||n.transitioning||n.animationTicked||n.continuous||n.liveEncoding||n.forced)}function o(n,r){return n||r}export{r as resolveCanvasBackground,t as paintCanvasBackground,c as needsDataCanvasPaint,o as needsInteractionCanvasPaint};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{buildNavGraph as t,extractGeoNavPoints as e,extractOrdinalNavPoints as r,extractXYNavPoints as n,navPointToHover as i,nextGraphIndex as s,nextIndex as o,renderCirclePulse as c,resolvePosition as u}from"./chunk-chunk-NH4MEAKP.module.min.js";import{emitClickObservations as a,emitHoverObservations as l,isInteractiveKeyboardTarget as f,resolveCanvasFill as h}from"./chunk-chunk-7ZDJSYKI.module.min.js";var p=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const r of t){const t=this.push(r);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let r=0;this._size>r;r++)t(this.buffer[(e+r)%this._capacity],r)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let r=0;this._size>r;r++)t[r]=this.buffer[(e+r)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let r=0,n=[];e.length>t&&(r=e.length-t,n=e.slice(0,r)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=r;e.length>t;t++)this.push(e[t]);return n}update(t,e){const r=[],n=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const s=(n+i)%this._capacity,o=this.buffer[s];if(t(o)){let t;t="object"!=typeof o||null===o?o:Array.isArray(o)?[...o]:{...o},r.push(t),this.buffer[s]=e(o)}}return r}remove(t){const e=[],r=[];if(this.forEach(n=>{t(n)?r.push(n):e.push(n)}),0===r.length)return r;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return r}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}};function y(t,e,r,n){return"function"==typeof e.style?e.style(n||{},r):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(r,n)}function d(t,e,r,n){if(!t.scales)return null;const i=[],s=[];for(const r of e){const e=t.getX(r);if(!Number.isFinite(e))continue;const o=n.getTop(r),c=n.getBottom(r);if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t.scales.x(e),a=t.scales.y(o),l=t.scales.y(c);Number.isFinite(u)&&Number.isFinite(a)&&Number.isFinite(l)&&(i.push([u,a]),s.push([u,l]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:s,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:y(t,n,r,e[0]),datum:e,group:r,interactive:n.interactive}}function v(t){const e=[],r=[];if(!t)return{perSeries:e,aggregate:r};for(const n of t)n.perSeries?e.push(n):r.push(n);return{perSeries:e,aggregate:r}}function _(t,e,r){const n=[];for(const i of r){const r=d(t,e,"__ribbon_aggregate",i);r&&n.push(r)}return n}function g(t,e,r,n){const i=[];for(const s of n){const n=d(t,e,r,s);n&&i.push(n)}return i}function m(t,e){if(!t)return{};if(!e||0===e.length)return t;const r=[];for(const n of e){if("band"!==n.kind)continue;const e=n.getTop(t),i=n.getBottom(t);Number.isFinite(i)&&Number.isFinite(e)&&r.push({y0:i,y1:e})}return 0===r.length?t:{...t,band:r[0],bands:r}}function b(t,e,r,n){const i=n.current,s=!0===t.lastCustomLayoutFailure?.preservedLastGoodScene,o=!s&&t.hasActivePulsesAt(e),c=!(r||s||!o&&!i)&&t.refreshPulse(e);return n.current=o,{changed:c,pending:o}}import{useCallback as k,useRef as z}from"react";function A(t,e,r,n){const i=z({accessor:e,onChange:r,readData:n}),s=z([]);return i.current={accessor:e,onChange:r,readData:n},k(()=>{const{accessor:e,onChange:r,readData:n}=i.current;if(!r||!e)return;const o=function(t,e){if(!e)return[];const r=new Set,n=[];for(const i of t){if(!i||"object"!=typeof i)continue;const t="function"==typeof e?e(i):i[e];if(null==t)continue;const s=t+"";r.has(s)||(r.add(s),n.push(s))}return n}(t.current?n(t.current):[],e);(function(t,e){if(t.length!==e.length)return!1;for(let r=0;t.length>r;r++)if(t[r]!==e[r])return!1;return!0})(o,s.current)||(s.current=o,r(o))},[t])}var w=(t,e,r,n)=>{const i=e.filter(t=>"point"===t.type);if(0!==i.length){t.save();try{const e=t.globalAlpha;for(const r of i)t.beginPath(),t.arc(r.x,r.y,r.r,0,2*Math.PI),t.globalAlpha=e*(r.style.opacity??r.style.fillOpacity??1),t.fillStyle=h(t,r.style.fill,"#4e79a7"),t.fill(),r.style.stroke&&"none"!==r.style.stroke&&(t.strokeStyle=h(t,r.style.stroke,r.style.stroke),t.lineWidth=r.style.strokeWidth||1,t.stroke()),c(t,r)}finally{t.restore()}}};import{useCallback as R}from"react";function x({customHoverBehavior:t,customClickBehavior:e,onObservation:r,chartId:n,chartType:i}){return{customHoverBehavior:R((e,s)=>{t?.(e,s),l({onObservation:r,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:i,chartId:n,context:s})},[n,i,t,r]),customClickBehavior:R((t,s)=>{e?.(t,s),a({onObservation:r,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:i,chartId:n,context:s})},[n,i,e,r]),hasClickBehavior:!(!e&&!r)}}import{useCallback as D,useRef as P}from"react";function C({storeRef:e,hoverRef:r,hoveredNodeRef:n,setHoverPoint:i,customHoverBehavior:o,customClickBehavior:c,scheduleRender:a,extractPoints:l,toHover:h}){const p=P(-1),y=P(null),d=P(null),v=D(v=>{if(f(v))return;const _=e.current;if(!_)return;const g=()=>{p.current=-1,y.current=null,r.current=null,n&&(n.current=null),i(null),o(null),a()};if(0===_.scene.length)return void(0>p.current||g());let m;if(d.current?.version===_.version)m=d.current.graph;else{const e=l(_.scene);if(0===e.length)return void(0>p.current||g());m=t(e),d.current={version:_.version,graph:m}}let b=p.current;if(m.flat.length>b||(g(),b=-1),("Enter"===v.key||" "===v.key)&&b>=0)return v.preventDefault(),void c(h(m.flat[b],_),{type:"activate",inputType:"keyboard"});if(0>b){if("Escape"===v.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(v.key))return;v.preventDefault(),p.current=0;const t=m.flat[0];y.current=t;const e=h(t,_);return r.current=e,i(e),o(e,{type:"focus",inputType:"keyboard"}),void a()}const k=s(v.key,u(m,b),m);if(null===k)return;if(v.preventDefault(),0>k)return void g();p.current=k;const z=m.flat[k];y.current=z;const A=h(z,_);r.current=A,i(A),o(A,{type:"focus",inputType:"keyboard"}),a()},[c,o,l,r,n,a,i,e,h]);return{kbFocusIndexRef:p,focusedNavPointRef:y,onKeyDown:v}}function B(t){return C({...t,extractPoints:n,toHover:(t,e)=>i({...t,datum:m(t.datum,e.resolvedRibbons)})})}function N({chartType:t,oAccessor:e,rAccessor:n,...s}){return C({...s,extractPoints:r,toHover:r=>({...i(r),__oAccessor:"string"==typeof e?e:void 0,__rAccessor:"string"==typeof n?n:void 0,__chartType:t})})}function H(t){const e=t.datum;return{...e||{},...e?.properties||{},data:e,properties:e?.properties,x:t.x,y:t.y,__semioticHoverData:!0}}function T({storeRef:t,hoverRef:r,hoveredNodeRef:n,setHoverPoint:i,customHoverBehavior:s,customClickBehavior:c,scheduleRender:u}){const a=P(-1),l=P(null),h=D(h=>{if(f(h))return;const p=t.current;if(!p)return;const y=()=>{a.current=-1,l.current=null,r.current=null,n&&(n.current=null),i(null),s(null),u()};if(0===p.scene.length)return void(0>a.current||y());const d=e(p.scene);if(0===d.length)return void(0>a.current||y());let v=a.current;if(d.length>v||(y(),v=-1),("Enter"===h.key||" "===h.key)&&v>=0)return h.preventDefault(),void c(H(d[v]),{type:"activate",inputType:"keyboard"});const _=o(h.key,0>v?-1:v,d.length);if(null===_)return;if(h.preventDefault(),0>_)return void y();const g=0>v?0:_;a.current=g;const m=d[g];l.current=m;const b=H(m);r.current=b,i(b),s(b,{type:"focus",inputType:"keyboard"}),u()},[c,s,r,n,u,i,t]);return{kbFocusIndexRef:a,focusedNavPointRef:l,onKeyDown:h}}function E(t,e,r){const n=t.duration??500,i=r-e;return n>i?1-i/n:0}function F(t,e,r,n,i,s=("undefined"!=typeof performance?performance.now():Date.now())){const o=t.color??"rgba(255,255,255,0.6)",c=t.glowRadius??4;let u=!1;const a=i??(()=>{const t=new Map;for(let e=0;r.length>e;e++)t.set(r[e],e);return t})();for(const r of e){if("line"===r.type)continue;if("area"===r.type){const e=Array.isArray(r.datum)?r.datum:[r.datum];let i=0,c=!1;for(const r of e){const e=a.get(r);if(null==e)continue;c=!0;const o=n.get(e);if(null==o)continue;const u=E(t,o,s);u>i&&(i=u)}c&&(u=I(r,i,o)||u);continue}const e=a.get(r.datum);if(null==e)continue;const i=n.get(e);u=I(r,null==i?0:E(t,i,s),o,c)||u}return u}function I(t,e,r,n){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==r&&(t._pulseColor=r,i=!0),t._pulseGlowRadius!==n&&(t._pulseGlowRadius=n,i=!0),i):(0!==t._pulseIntensity&&(t._pulseIntensity=0,i=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,i=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,i=!0),i)}function S(t,e,r=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const n=t.duration??500,i=e.peek();return null!=i&&n>r-i}function j(t,e,r){e>t.capacity&&(t.resize(e),r&&e>r.capacity&&r.resize(e))}function G(t,e){const r=new p(t.capacity);return t.forEach(()=>r.push(e)),r}function O(t,e,r,n){const i=t.push(e);return r&&r.push(n),i}function K(t,e,r){if(!e||0===e.size)return;const n=new Set;if(t.forEach((t,e)=>{r(t)&&n.add(e)}),0===n.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)n.has(t)||e.push(i[t])}export{p as RingBuffer,E as computePulseIntensity,F as applyPulse,I as setPulseState,S as hasActivePulses,v as partitionRibbons,_ as buildAggregateRibbons,g as buildPerSeriesRibbons,m as enrichDatumWithBand,j as ensureRingBufferCapacity,G as createTimestampBufferForData,O as pushWithTimestamp,K as compactTimestampBufferForRemoval,b as refreshIdlePulse,A as useLegendCategoryEmission,w as pointCanvasRenderer,x as useSemanticFrameInteractions,B as useXYKeyboardNavigation,N as useOrdinalKeyboardNavigation,T as useGeoKeyboardNavigation};
@@ -0,0 +1 @@
1
+ import{createStore as t}from"./chunk-chunk-DSNGDNJY.module.min.js";var e=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const i of t){const t=this.push(i);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)t(this.buffer[(e+i)%this._capacity],i)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)t[i]=this.buffer[(e+i)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let i=0,n=[];e.length>t&&(i=e.length-t,n=e.slice(0,i)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=i;e.length>t;t++)this.push(e[t]);return n}update(t,e){const i=[],n=(this.head-this._size+this._capacity)%this._capacity;for(let r=0;this._size>r;r++){const a=(n+r)%this._capacity,o=this.buffer[a];if(t(o)){let t;t="object"!=typeof o||null===o?o:Array.isArray(o)?[...o]:{...o},i.push(t),this.buffer[a]=e(o)}}return i}remove(t){const e=[],i=[];if(this.forEach(n=>{t(n)?i.push(n):e.push(n)}),0===i.length)return i;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return i}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},i=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(t){Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}evict(t){t!==this._min&&t!==this._max||(this._dirty=!0)}recalculate(t,e){this._min=1/0,this._max=-1/0;for(const i of t){const t=e?e(i):i;Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function n(t,e,i){return i.x>t||t>i.x+i.w||i.y>e||e>i.y+i.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:i.x+i.w/2,cy:i.y+i.h/2}}function r(t,e=30){return Math.max((t??4)+5,12,e)}function a(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function o(t,e){const i=a(t);if(!i)return!1;const n=a(e);return!n||i.getFullYear()!==n.getFullYear()||i.getMonth()!==n.getMonth()}function s(t){let e=t%(2*Math.PI);return 0>e&&(e+=2*Math.PI),e}function l(t){return{type:"hatch",background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle}}var c=null;function u(t={},e){const{background:i="transparent",stroke:n="#000",lineWidth:r=1.5,spacing:a=6,angle:o=45}=t,s={background:i,stroke:n,lineWidth:r,spacing:a,angle:o},u=Math.max(8,Math.ceil(2*a));let h;try{h=function(t){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(t,t):(c||(c=document.createElement("canvas")),c.width=t,c.height=t,c)}(u)}catch{return l(s)}const f=h.getContext("2d");if(!f)return l(s);i&&"transparent"!==i?(f.fillStyle=i,f.fillRect(0,0,u,u)):f.clearRect(0,0,u,u),f.strokeStyle=n,f.lineWidth=r,f.lineCap="square";const p=o*Math.PI/180;if(45===o||-45===o){const t=o>0?1:-1;for(let e=-u;2*u>=e;e+=a)f.beginPath(),f.moveTo(e,0),f.lineTo(e+t*u,u),f.stroke()}else{f.save(),f.translate(u/2,u/2),f.rotate(p);const t=2*u;for(let e=-t;t>=e;e+=a)f.beginPath(),f.moveTo(-t,e),f.lineTo(t,e),f.stroke();f.restore()}return(e||f).createPattern(h,"repeat")}import{jsx as h,jsxs as f}from"react/jsx-runtime";function p(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function d(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}function y(t,e){let i=2166136261;const n=d(e);for(let t=0;n.length>t;t++)i^=n.charCodeAt(t),i=Math.imul(i,16777619);return`${t}-hatch-${(i>>>0).toString(36)}`}var m=new Map;function b(t,e){const i="undefined"!=typeof window&&window.devicePixelRatio||1,n=`${d(t)}@${i}`,r=m.get(n);if(void 0!==r)return r;const a=u({background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle},e),o=p(a)?null:a;return m.set(n,o),o}function g(t,e){const{background:i="transparent",stroke:n="#000",lineWidth:r=1.5,spacing:a=6,angle:o=45,lineOpacity:s=1}=t,l=Math.max(8,Math.ceil(2*a));return f("pattern",{id:e,width:l,height:l,patternUnits:"userSpaceOnUse",patternTransform:0!==o?`rotate(${o})`:void 0,children:[i&&"transparent"!==i&&h("rect",{width:l,height:l,fill:i}),h("line",{x1:0,y1:0,x2:0,y2:l,stroke:n,strokeWidth:r,strokeOpacity:s}),h("line",{x1:a,y1:0,x2:a,y2:l,stroke:n,strokeWidth:r,strokeOpacity:s})]},e)}function v(t,e,i="#4e79a7"){if(p(t)){const i=y(e,t);return{fill:`url(#${i})`,def:g(t,i)}}return t&&"string"==typeof t?{fill:t}:{fill:i}}function _(t,e){return"touch"===e?Math.max(t,24):t}function x(t){return Array.isArray(t)?t[0]:t}function k(t,e,i,n){return{data:x(t),x:e,y:i,__semioticHoverData:!0,...n}}var w=["name","label","title"],N=["type","kind","category","group","class","status","role","shape"],A=["value","amount","total","count","weight","score"],z=new Set(["x","y","z","x0","x1","y0","y1","r","cx","cy","radius","layer","row","rowindex","col","column","depth","index","order","sankeywidth","coincidentpoints","sourcelinks","targetlinks","parent","children","fx","fy","vx","vy"]);function O(t,e){for(const i of e){const e=t.find(t=>t.lower===i);if(e)return e}}function W(t,e={}){if(!t||"object"!=typeof t)return{entries:[]};const i=e.maxEntries??6,n=!1!==e.skipPositional,r=[];for(const[e,i]of Object.entries(t)){if(e.startsWith("_"))continue;if("data"===e)continue;if(n&&z.has(e.toLowerCase()))continue;if(null==i)continue;const t=typeof i;("string"===t||"number"===t||"boolean"===t||i instanceof Date)&&r.push({key:e,lower:e.toLowerCase(),value:i})}if(0===r.length)return{entries:[]};let a=r.findIndex(t=>w.includes(t.lower));const o=a>=0;0>a&&(a=r.findIndex(t=>"id"===t.lower)),0>a&&(a=r.findIndex(t=>"string"==typeof t.value));const s=0>a?void 0:r[a];let l=r.filter((t,e)=>e!==a);o&&(l=l.filter(t=>"id"!==t.lower));const c=O(l,N),u=O(l,A),h=new Set(N),f=new Set(A),p=[];c&&p.push({key:c.key,value:c.value}),u&&p.push({key:u.key,value:u.value});for(const t of l){if(p.length>=i)break;t!==c&&t!==u&&(h.has(t.lower)||f.has(t.lower)||p.push({key:t.key,value:t.value}))}return{titleKey:s?.key,title:s?.value,entries:p}}import{jsx as S,jsxs as j}from"react/jsx-runtime";var M={background:"var(--semiotic-tooltip-bg, rgba(0, 0, 0, 0.85))",color:"var(--semiotic-tooltip-text, white)",padding:"8px 12px",borderRadius:"var(--semiotic-tooltip-radius, 6px)",fontSize:"var(--semiotic-tooltip-font-size, 14px)",fontFamily:"var(--semiotic-font-family, inherit)",lineHeight:"1.5",boxShadow:"var(--semiotic-tooltip-shadow, 0 2px 8px rgba(0, 0, 0, 0.15))",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function C(t,e){return"function"==typeof e?e(t):t[e]}function E(t,e){if(e)return e(t);if(null==t)return"";if("number"==typeof t){if(!Number.isFinite(t))return t+"";const e=Number.isInteger(t)?t:parseFloat(t.toPrecision(6));return Math.abs(e)>9999?e.toLocaleString():e+""}return t instanceof Date?t.toLocaleDateString():"object"==typeof t&&null!==t?void 0!==t.id?t.id+"":void 0!==t.name?t.name+"":JSON.stringify(t):t+""}function I(t={}){const{fields:e,title:i,format:n,style:r={},className:a=""}=t;return t=>{if(!t||"object"!=typeof t)return null;let o;const s=[];if(i){const e=C(t,i);o=E(e,n)}if(e&&e.length>0)e.forEach(e=>{let i,r,a;"string"==typeof e?(i=e,r=e,a=n):(i=e.label,r=e.accessor||e.key||"",a=e.format||n);const o=C(t,r);s.push({label:i,value:E(o,a)})});else if(!i){const e=["value","y","name","id","label"];for(const i of e)if(void 0!==t[i]){o=E(t[i],n);break}if(!o){const e=Object.keys(t).filter(t=>!t.startsWith("_"));e.length>0&&(o=E(t[e[0]],n))}}const l={...M,...r};return j("div",{className:("semiotic-tooltip "+a).trim(),style:l,children:[o&&S("div",{style:{fontWeight:s.length>0?"bold":"normal"},children:o}),s.map((t,e)=>j("div",{style:{marginTop:0===e&&o?"4px":0},children:[t.label&&j("span",{children:[t.label,": "]}),t.value]},e))]})}}function D(){return t=>{const e=t.allSeries;if(!e||0===e.length)return S("div",{className:"semiotic-tooltip",style:M,children:S("div",{children:E(t.data?.value??t.data?.y)})});const i=t.xValue??t.data?.time??t.data?.x;return j("div",{className:"semiotic-tooltip",style:M,children:[null!=i&&S("div",{style:{fontWeight:600,marginBottom:4,fontSize:"0.9em",borderBottom:"1px solid var(--semiotic-border, #eee)",paddingBottom:4},children:E(i)}),e.map((t,e)=>j("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"1px 0"},children:[S("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:t.color,flexShrink:0}}),S("span",{style:{flex:1,fontSize:"0.85em"},children:t.group}),S("span",{style:{fontWeight:500,fontSize:"0.85em"},children:E(t.value)})]},e))]})}}function T(t){if(!0!==t){if("function"==typeof t){const e=t;return t=>{let i=x(!0===t?.__semioticHoverData||t&&void 0!==t.data&&"number"==typeof t.x&&"number"==typeof t.y&&t&&("node"===t.type||"edge"===t.type||void 0!==t.nodeOrEdge||void 0!==t.allSeries||void 0!==t.stats||void 0!==t.__chartType)?t.data??{}:t);if(!i)return null;if(("node"===t?.nodeOrEdge&&"number"==typeof i?.x0&&"number"==typeof i?.x1||"edge"===t?.nodeOrEdge&&"number"==typeof i?.sankeyWidth)&&i.data&&"object"==typeof i.data&&(i=i.data),!i)return null;const n=e(i);return null==n?null:S("div",{className:"semiotic-tooltip",style:M,children:n})}}return!1!==t&&void 0!==t&&("object"==typeof t&&null!==t&&("fields"in t||"title"in t)?I(t):"multi"===t?("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip="multi" reached normalizeTooltip — prefer charts that set tooltipMode (LineChart, AreaChart, StackedAreaChart, DifferenceChart). Rendering MultiLineTooltip content as a fallback.'),function(t={}){const{fields:e=[],title:i,format:n,style:r={},className:a="",showLabels:o=!0,separator:s=": "}=t;return t=>{if(!t||"object"!=typeof t)return null;const l=[];if(i){const e=C(t,i);l.push({value:E(e,n)})}if(e&&Array.isArray(e)&&e.length>0)e.forEach(e=>{let i,r,a;"string"==typeof e?(i=e,r=e,a=n):(i=e.label,r=e.accessor||e.key||"",a=e.format||n);const s=E(C(t,r),a);l.push({label:o?i:void 0,value:s})});else{const e=W(t,{skipPositional:!1});null!=e.title&&l.push({label:void 0,value:E(e.title,n),bold:!0}),e.entries.forEach(t=>{l.push({label:o?t.key:void 0,value:E(t.value,n)})})}const c={...M,...r};return Array.isArray(l)&&0!==l.length?S("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+a).trim(),style:c,children:l.map((t,e)=>j("div",{style:{marginBottom:l.length-1>e?"4px":0,fontWeight:t.bold?"bold":void 0},children:[t.label&&j("strong",{children:[t.label,s]}),t.value]},e))}):null}}()):I())}}function R(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function P(t,e){const{when:i}=t,n=e.width,r=e.height,a=function(t){if("number"==typeof t.height&&t.height>0)return t.width/t.height}(e),o=function(t){if("number"==typeof t.height&&t.height>0)return t.height>t.width?"portrait":"landscape"}(e);return!("number"==typeof i.minWidth&&i.minWidth>n||"number"==typeof i.maxWidth&&n>i.maxWidth||"number"==typeof i.minHeight&&("number"!=typeof r||i.minHeight>r)||"number"==typeof i.maxHeight&&("number"!=typeof r||r>i.maxHeight)||"number"==typeof i.minAspectRatio&&("number"!=typeof a||i.minAspectRatio>a)||"number"==typeof i.maxAspectRatio&&("number"!=typeof a||a>i.maxAspectRatio)||i.orientation&&o!==i.orientation)}function F(t,e,i=t.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:t,matches:[]};const n=i.map((t,e)=>({rule:t,index:e})).filter(t=>P(t.rule,e)).sort((t,e)=>("number"==typeof t.rule.priority?t.rule.priority:t.index)-("number"==typeof e.rule.priority?e.rule.priority:e.index));return{props:n.reduce((t,e)=>function(t,e){const i={...t,...e};for(const n of["margin","frameProps","mobileSemantics","style"])R(t[n])&&R(e[n])&&(i[n]={...t[n],...e[n]});return"string"==typeof t.className&&"string"==typeof e.className&&(i.className=`${t.className} ${e.className}`),i}(t,e.rule.transform),t),matches:n}}var $=/^\d{4}-\d{1,2}$/;function L(t){const e=t.trim();if(!e||!Number.isNaN(Number(e)))return NaN;const i=$.test(e)?e+"-01":e;if(i===e&&10>e.length)return NaN;const n=Date.parse(i);return Number.isFinite(n)?n:NaN}function B(t){return t instanceof Date?t.getTime():"string"==typeof t?L(t):+t}import*as H from"react";var[V,Y]=t(t=>({observations:[],maxObservations:100,version:0,pushObservation(e){t(t=>{const i=t.observations;return i.push(e),i.length>t.maxObservations&&i.shift(),{version:t.version+1}})},clearObservations(){t(()=>({observations:[],version:0}))}}));function J(t){const e=Y(t=>t.pushObservation),i=H.useCallback(i=>{t.onObservation?.(i),e?.(i)},[t,e]);return H.useMemo(()=>({...t,onObservation:i}),[i,t])}function U(t){const e=t.provenance,i=t.id??t.stableId??e?.stableId;return null==i||""===i?void 0:i+""}function q(t,e={}){const i=U(t);return{"data-semiotic-annotation-widget":"",...i?{"data-semiotic-annotation-id":i}:{},onClickCapture(n){const r=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(n);e.onAnnotationActivate?.({annotation:t,annotationId:i,chartId:e.chartId,inputType:r}),i&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:i,inputType:r,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}function G(t){return t instanceof Element&&null!=t.closest("[data-semiotic-annotation-widget]")}function K(t){const e={};if(null==t||"object"!=typeof t)return e;for(const[i,n]of Object.entries(t))i.startsWith("_")||null!=n&&""!==n&&("number"==typeof n?Number.isFinite(n)&&(e[i]=n):"string"==typeof n?e[i]=n:"boolean"==typeof n?e[i]=n+"":n instanceof Date&&(e[i]=n.toISOString().slice(0,10)));return e}function Q(t){return t&&"object"==typeof t?t:{}}function X(t){return Q(t.accessibility).tableFields??t.accessibleDatum??t.datum}function Z(t){const e=[];if(!Array.isArray(t))return e;const i=t.some(t=>t&&("line"===t.type||"area"===t.type));for(const n of t)if(n&&"object"==typeof n&&null!==n.datum)try{switch(n.type){case"point":if(i)break;e.push({label:"Point",values:K(X(n))});break;case"line":case"area":{const t=X(n),i=Array.isArray(t)?t:[],r="line"===n.type?"Line point":"Area point";for(const t of i)e.push({label:r,values:K(t)});break}case"rect":{const t=X(n),i=null!=t&&"object"==typeof t?t:{},r=i.category??n.group??"",a=i.value??i.__aggregateValue??i.total,o=K(i);null==o.category&&""!==r&&(o.category=r+""),null==o.value&&null!=a&&(o.value="number"==typeof a||"string"==typeof a?a:a+""),e.push({label:"Bar",values:o});break}case"heatcell":{const t=K(X(n));null==t.value&&"number"==typeof n.value&&Number.isFinite(n.value)&&(t.value=n.value),e.push({label:"Cell",values:t});break}case"wedge":{const t=X(n),i=K(t);if(null==i.category){const e=Q(t),n=e.category??e.label;null!=n&&(i.category=n+"")}e.push({label:"Wedge",values:i});break}case"circle":e.push({label:"Node",values:K(X(n))});break;case"arc":e.push({label:"Arc",values:K(X(n))});break;case"candlestick":e.push({label:"Candlestick",values:K(X(n))});break;case"geoarea":{const t=Q(X(n)),i=K(t);if(null==i.name){const e=Q(t.properties).name??t.name;null!=e&&(i.name=e+"")}e.push({label:"Region",values:i});break}}}catch{}return e}export{e as RingBuffer,i as IncrementalExtent,L as parseDateLikeString,B as coerceDateLikeValue,n as hitTestRect,r as getHitRadius,o as isTimeLandmark,s as normalizeAngle,u as createHatchPattern,p as isHatchFill,d as hatchFillKey,y as hatchFillId,b as resolveHatchCanvasPattern,g as hatchPatternDef,v as resolveSvgFill,Y as useObservationSelector,J as useAnnotationActivationOptions,U as annotationStableId,q as annotationActivationProps,G as isAnnotationActivationTarget,Z as extractAllRows,_ as getPointerHitRadius,k as buildHoverData,W as smartTooltipEntries,M as defaultTooltipStyle,D as MultiPointTooltip,T as normalizeTooltip,P as responsiveRuleMatches,F as resolveResponsiveRules};