semiotic 3.8.7 → 3.8.8

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 (206) hide show
  1. package/CLAUDE.md +2 -2
  2. package/README.md +56 -46
  3. package/ai/dist/mcp-server.js +28 -2
  4. package/ai/schema.json +124 -4
  5. package/ai/surface-manifest.json +1 -1
  6. package/ai/system-prompt.md +1 -1
  7. package/dist/{chunk-chartContainerDataAudit-JDSVSKGM.module.min.js → chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js} +1 -1
  8. package/dist/chunk-chunk-2B3AIKUZ.module.min.js +2 -0
  9. package/dist/chunk-chunk-2NVFEB7P.module.min.js +2 -0
  10. package/dist/chunk-chunk-3GCILWPB.module.min.js +2 -0
  11. package/dist/chunk-chunk-46KRGJQP.module.min.js +1 -0
  12. package/dist/{chunk-chunk-5SD6BHVW.module.min.js → chunk-chunk-4MLLQUGW.module.min.js} +1 -1
  13. package/dist/chunk-chunk-57RBPDBQ.module.min.js +2 -0
  14. package/dist/chunk-chunk-5VVNW5AZ.module.min.js +1 -0
  15. package/dist/chunk-chunk-66PCWJUG.module.min.js +1 -0
  16. package/dist/chunk-chunk-7LE56WAE.module.min.js +2 -0
  17. package/dist/chunk-chunk-7T25U75Z.module.min.js +2 -0
  18. package/dist/chunk-chunk-AF53TBSN.module.min.js +2 -0
  19. package/dist/chunk-chunk-BTZYH2IE.module.min.js +1 -0
  20. package/dist/chunk-chunk-BWV55BZK.module.min.js +2 -0
  21. package/dist/{chunk-chunk-FRO4TRXK.module.min.js → chunk-chunk-BZNOAHJV.module.min.js} +1 -1
  22. package/dist/chunk-chunk-CD6PVVS3.module.min.js +2 -0
  23. package/dist/chunk-chunk-DTSNLGRK.module.min.js +2 -0
  24. package/dist/{chunk-chunk-BNGBEY7N.module.min.js → chunk-chunk-FC3NZWYR.module.min.js} +1 -1
  25. package/dist/chunk-chunk-FEPXDKJP.module.min.js +1 -0
  26. package/dist/chunk-chunk-FJ76HWQZ.module.min.js +1 -0
  27. package/dist/chunk-chunk-FRGBMTZR.module.min.js +1 -0
  28. package/dist/chunk-chunk-G75OPF5N.module.min.js +2 -0
  29. package/dist/{chunk-chunk-NH4MEAKP.module.min.js → chunk-chunk-H5IFO6CU.module.min.js} +1 -1
  30. package/dist/chunk-chunk-HADHLMY5.module.min.js +1 -0
  31. package/dist/chunk-chunk-HBFA4NN6.module.min.js +1 -0
  32. package/dist/chunk-chunk-HCNDE26Q.module.min.js +2 -0
  33. package/dist/chunk-chunk-JJ4BSUYL.module.min.js +2 -0
  34. package/dist/chunk-chunk-JRHXQGEV.module.min.js +2 -0
  35. package/dist/chunk-chunk-L6FFYGYS.module.min.js +1 -0
  36. package/dist/{chunk-chunk-Z2AJERX5.module.min.js → chunk-chunk-LJDH3WV3.module.min.js} +1 -1
  37. package/dist/chunk-chunk-LSJUXBMF.module.min.js +1 -0
  38. package/dist/chunk-chunk-N3Q33XCB.module.min.js +2 -0
  39. package/dist/chunk-chunk-NWIGA3UK.module.min.js +1 -0
  40. package/dist/chunk-chunk-OG3TTJGJ.module.min.js +2 -0
  41. package/dist/{chunk-chunk-XEVJDUTH.module.min.js → chunk-chunk-OZK46A5U.module.min.js} +1 -1
  42. package/dist/chunk-chunk-PMR47KRY.module.min.js +2 -0
  43. package/dist/chunk-chunk-QQJNG23C.module.min.js +2 -0
  44. package/dist/{chunk-chunk-LG7YKJAK.module.min.js → chunk-chunk-RGJ6TKAH.module.min.js} +1 -1
  45. package/dist/{chunk-chunk-JWXLNZSM.module.min.js → chunk-chunk-SFLUSZ73.module.min.js} +1 -1
  46. package/dist/chunk-chunk-TCMHJWFJ.module.min.js +1 -0
  47. package/dist/{chunk-chunk-LVHDZAT3.module.min.js → chunk-chunk-UEZ6SHW5.module.min.js} +1 -1
  48. package/dist/chunk-chunk-VUWYT7DY.module.min.js +2 -0
  49. package/dist/{chunk-chunk-OI7R7EJB.module.min.js → chunk-chunk-W5HWGQMD.module.min.js} +1 -1
  50. package/dist/chunk-chunk-WFHZHWT7.module.min.js +1 -0
  51. package/dist/chunk-chunk-WGROBM3I.module.min.js +2 -0
  52. package/dist/{chunk-chunk-GU2EJIDJ.module.min.js → chunk-chunk-WSDJFBKX.module.min.js} +1 -1
  53. package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +2 -0
  54. package/dist/components/charts/index.d.ts +2 -2
  55. package/dist/components/charts/network/ProcessSankey.d.ts +105 -74
  56. package/dist/components/charts/network/processSankey/accessors.d.ts +7 -0
  57. package/dist/components/charts/network/processSankey/algorithm.d.ts +14 -193
  58. package/dist/components/charts/network/processSankey/axisChrome.d.ts +31 -0
  59. package/dist/components/charts/network/processSankey/bandPaths.d.ts +45 -0
  60. package/dist/components/charts/network/processSankey/buildScenes.d.ts +41 -3
  61. package/dist/components/charts/network/processSankey/fixtures.d.ts +17 -0
  62. package/dist/components/charts/network/processSankey/frameMargins.d.ts +11 -0
  63. package/dist/components/charts/network/processSankey/groupBonding.d.ts +13 -0
  64. package/dist/components/charts/network/processSankey/inventoryAtTime.d.ts +41 -0
  65. package/dist/components/charts/network/processSankey/labelPlacement.d.ts +34 -0
  66. package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +47 -0
  67. package/dist/components/charts/network/processSankey/layoutOrchestrator.d.ts +44 -0
  68. package/dist/components/charts/network/processSankey/layoutQualityProduct.d.ts +27 -0
  69. package/dist/components/charts/network/processSankey/massSimulation.d.ts +16 -0
  70. package/dist/components/charts/network/processSankey/ordering.d.ts +55 -0
  71. package/dist/components/charts/network/processSankey/orderingBond.d.ts +33 -0
  72. package/dist/components/charts/network/processSankey/orientation.d.ts +5 -0
  73. package/dist/components/charts/network/processSankey/packing.d.ts +8 -0
  74. package/dist/components/charts/network/processSankey/packingCache.d.ts +23 -0
  75. package/dist/components/charts/network/processSankey/processSankeyLayoutAsync.d.ts +27 -0
  76. package/dist/components/charts/network/processSankey/processSankeyLayoutWorkerClient.d.ts +72 -0
  77. package/dist/components/charts/network/processSankey/processSankeyTooltip.d.ts +26 -0
  78. package/dist/components/charts/network/processSankey/processSankeyTypes.d.ts +163 -0
  79. package/dist/components/charts/network/processSankey/ribbonInputs.d.ts +26 -2
  80. package/dist/components/charts/network/processSankey/ribbonRunway.d.ts +45 -0
  81. package/dist/components/charts/network/processSankey/streamingLayout.d.ts +23 -0
  82. package/dist/components/charts/network/processSankey/time.d.ts +11 -0
  83. package/dist/components/charts/network/processSankey/useProcessSankeyPush.d.ts +29 -0
  84. package/dist/components/charts/network/processSankey/useProcessSankeyScenes.d.ts +26 -0
  85. package/dist/components/charts/network/processSankey/validation.d.ts +33 -0
  86. package/dist/components/charts/shared/chartFamilySets.d.ts +1 -0
  87. package/dist/components/charts/shared/formatUtils.d.ts +12 -1
  88. package/dist/components/charts/shared/hatchFill.d.ts +2 -0
  89. package/dist/components/charts/shared/hooks.d.ts +1 -1
  90. package/dist/components/charts/shared/leastSquaresRegression.d.ts +31 -0
  91. package/dist/components/charts/shared/styleRules.d.ts +5 -1
  92. package/dist/components/charts/shared/useChartLegend.d.ts +6 -0
  93. package/dist/components/charts/shared/useChartSetup.d.ts +1 -1
  94. package/dist/components/charts/shared/validateProps.d.ts +2 -2
  95. package/dist/components/charts/shared/withChartWrapper.d.ts +0 -6
  96. package/dist/components/data/numericFieldProfiler.d.ts +2 -0
  97. package/dist/components/recipes/layout1d.d.ts +68 -0
  98. package/dist/components/semiotic-network.d.ts +2 -2
  99. package/dist/components/semiotic-recipes-core.d.ts +2 -0
  100. package/dist/components/semiotic.d.ts +2 -0
  101. package/dist/components/server/staticSVGChrome.d.ts +2 -1
  102. package/dist/components/store/createStore.d.ts +2 -0
  103. package/dist/components/stream/OrdinalPipelineStore.d.ts +3 -0
  104. package/dist/components/stream/PipelineStore.d.ts +5 -0
  105. package/dist/components/stream/accessorUtils.d.ts +21 -0
  106. package/dist/components/stream/frameKeyboardNavigation.d.ts +3 -2
  107. package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +3 -8
  108. package/dist/components/stream/layouts/index.d.ts +1 -1
  109. package/dist/components/stream/moduleWorkerSession.d.ts +67 -0
  110. package/dist/components/stream/networkTypes.d.ts +2 -0
  111. package/dist/components/stream/ordinalSceneBuilders/sceneBuilderMap.d.ts +2 -1
  112. package/dist/components/stream/physics/PhysicsKernel.d.ts +9 -0
  113. package/dist/components/stream/pipelineIntroCancellation.d.ts +6 -0
  114. package/dist/components/stream/pipelineTransitions.d.ts +15 -1
  115. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +16 -4
  116. package/dist/components/stream/renderers/symbolCanvasRenderer.d.ts +4 -0
  117. package/dist/components/stream/symbolPath.d.ts +8 -0
  118. package/dist/components/stream/types.d.ts +2 -0
  119. package/dist/components/stream/useCanvasFrameHost.d.ts +6 -0
  120. package/dist/components/stream/useSemanticFrameInteractions.d.ts +12 -3
  121. package/dist/components/stream/xyFrameAxisTypes.d.ts +4 -0
  122. package/dist/forceLayoutWorker.js +1 -1
  123. package/dist/geo.min.js +1 -1
  124. package/dist/geo.module.min.js +1 -1
  125. package/dist/network.min.js +1 -1
  126. package/dist/network.module.min.js +1 -1
  127. package/dist/ordinal.min.js +1 -1
  128. package/dist/ordinal.module.min.js +1 -1
  129. package/dist/physics.min.js +1 -1
  130. package/dist/physics.module.min.js +1 -1
  131. package/dist/physicsWorker.js +1 -1
  132. package/dist/processSankeyLayoutWorker.js +1 -0
  133. package/dist/realtime.min.js +1 -1
  134. package/dist/realtime.module.min.js +1 -1
  135. package/dist/semiotic-ai-core.min.js +1 -1
  136. package/dist/semiotic-ai-core.module.min.js +1 -1
  137. package/dist/semiotic-ai.min.js +1 -1
  138. package/dist/semiotic-ai.module.min.js +1 -1
  139. package/dist/semiotic-experimental-vacp.min.js +1 -1
  140. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  141. package/dist/semiotic-experimental.min.js +1 -1
  142. package/dist/semiotic-experimental.module.min.js +1 -1
  143. package/dist/semiotic-network.d.ts +2 -2
  144. package/dist/semiotic-realtime-core.min.js +1 -1
  145. package/dist/semiotic-realtime-core.module.min.js +1 -1
  146. package/dist/semiotic-recipes-core.d.ts +2 -0
  147. package/dist/semiotic-recipes-core.min.js +1 -1
  148. package/dist/semiotic-recipes-core.module.min.js +1 -1
  149. package/dist/semiotic-recipes.min.js +1 -1
  150. package/dist/semiotic-recipes.module.min.js +1 -1
  151. package/dist/semiotic-server-edge.min.js +1 -1
  152. package/dist/semiotic-server-edge.module.min.js +1 -1
  153. package/dist/semiotic-server-node.min.js +1 -1
  154. package/dist/semiotic-server-node.module.min.js +1 -1
  155. package/dist/semiotic-themes-core.module.min.js +1 -1
  156. package/dist/semiotic-themes-react.module.min.js +1 -1
  157. package/dist/semiotic-themes.module.min.js +1 -1
  158. package/dist/semiotic-utils-core.min.js +1 -1
  159. package/dist/semiotic-utils-core.module.min.js +1 -1
  160. package/dist/semiotic-utils-react.module.min.js +1 -1
  161. package/dist/semiotic-utils.min.js +1 -1
  162. package/dist/semiotic-utils.module.min.js +1 -1
  163. package/dist/semiotic-value.min.js +1 -1
  164. package/dist/semiotic-value.module.min.js +1 -1
  165. package/dist/semiotic.d.ts +2 -0
  166. package/dist/semiotic.min.js +1 -1
  167. package/dist/semiotic.module.min.js +1 -1
  168. package/dist/server.min.js +1 -1
  169. package/dist/server.module.min.js +1 -1
  170. package/dist/xy.min.js +1 -1
  171. package/dist/xy.module.min.js +1 -1
  172. package/package.json +4 -3
  173. package/dist/chunk-chunk-2YAZHXL4.module.min.js +0 -2
  174. package/dist/chunk-chunk-3NGIKFD6.module.min.js +0 -1
  175. package/dist/chunk-chunk-7TTBHSAG.module.min.js +0 -2
  176. package/dist/chunk-chunk-7ZDJSYKI.module.min.js +0 -2
  177. package/dist/chunk-chunk-BGHPD3RA.module.min.js +0 -1
  178. package/dist/chunk-chunk-BMRZ2SPU.module.min.js +0 -2
  179. package/dist/chunk-chunk-C7APLVQD.module.min.js +0 -2
  180. package/dist/chunk-chunk-DGWFBOGB.module.min.js +0 -1
  181. package/dist/chunk-chunk-DIVE2DRA.module.min.js +0 -2
  182. package/dist/chunk-chunk-DSNGDNJY.module.min.js +0 -1
  183. package/dist/chunk-chunk-FBUNUIPV.module.min.js +0 -2
  184. package/dist/chunk-chunk-G7QVPZUD.module.min.js +0 -2
  185. package/dist/chunk-chunk-GBPYV4FP.module.min.js +0 -2
  186. package/dist/chunk-chunk-KXAFCCDB.module.min.js +0 -2
  187. package/dist/chunk-chunk-LWITSR2O.module.min.js +0 -2
  188. package/dist/chunk-chunk-MX35T6RX.module.min.js +0 -2
  189. package/dist/chunk-chunk-NJETWX42.module.min.js +0 -2
  190. package/dist/chunk-chunk-NW25WGLS.module.min.js +0 -2
  191. package/dist/chunk-chunk-ONMLEXHR.module.min.js +0 -2
  192. package/dist/chunk-chunk-OY66GCE6.module.min.js +0 -1
  193. package/dist/chunk-chunk-PRDGLMJT.module.min.js +0 -2
  194. package/dist/chunk-chunk-PZFT457G.module.min.js +0 -1
  195. package/dist/chunk-chunk-Q3WW6JGR.module.min.js +0 -1
  196. package/dist/chunk-chunk-Q6XKQTOQ.module.min.js +0 -1
  197. package/dist/chunk-chunk-RJRM2E6P.module.min.js +0 -1
  198. package/dist/chunk-chunk-RPL7WYXI.module.min.js +0 -1
  199. package/dist/chunk-chunk-V3OAKG32.module.min.js +0 -1
  200. package/dist/chunk-chunk-WCX6U47H.module.min.js +0 -2
  201. package/dist/chunk-chunk-WLOIUMWG.module.min.js +0 -2
  202. package/dist/chunk-chunk-XEGXX4F7.module.min.js +0 -1
  203. package/dist/chunk-chunk-XFRBLXYM.module.min.js +0 -1
  204. package/dist/chunk-chunk-ZXYDYAB7.module.min.js +0 -2
  205. package/dist/chunk-statisticalOverlays-6MVAK5RW.module.min.js +0 -2
  206. package/dist/components/stream/renderers/networkSymbolRenderer.d.ts +0 -2
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{useChartSetup as t,useCustomChartScaffold as e}from"./chunk-chunk-VUWYT7DY.module.min.js";import{lineCanvasRenderer as n,resolveNodeColor as i}from"./chunk-chunk-AF53TBSN.module.min.js";import{RingBuffer as o,compactTimestampBufferForRemoval as r,computePulseIntensity as s,hasActivePulses as a,pointCanvasRenderer as c,pushWithTimestamp as l,refreshIdlePulse as u,setPulseState as h,useGeoKeyboardNavigation as d,useLegendCategoryEmission as p,useSemanticFrameInteractions as f}from"./chunk-chunk-QQJNG23C.module.min.js";import{needsDataCanvasPaint as m,needsInteractionCanvasPaint as g,paintCanvasBackground as y}from"./chunk-chunk-W5HWGQMD.module.min.js";import{StalenessBadge as v,attachUpdateResultStore as b,buildBaseMetadataProps as w,buildCustomBehaviorProps as P,composeOverlays as x,computeDecayOpacity as R,createCustomLayoutFailureDiagnostic as S,findHitPointInQuadtree as L,formatVal as A,getHitRadius as k,glyphCanvasRenderer as C,paintSceneWithBackend as D,renderPathPulse as j,renderSceneWithBackend as M,useConfigSync as T,useLayoutSelectionSync as B,useStableShallow as _,useStalenessCheck as I,warnCustomLayoutDiagnostics as N}from"./chunk-chunk-H5IFO6CU.module.min.js";import{wrapWithCustomLayoutSelection as E}from"./chunk-chunk-5UKL5W76.module.min.js";import{filterAnnotationsByStatus as F}from"./chunk-chunk-FC3NZWYR.module.min.js";import{buildResolveColor as O,resolveCustomLayoutPalette as W}from"./chunk-chunk-SFLUSZ73.module.min.js";import{AccessibleDataTable as z,AriaLiveTooltip as H,CanvasFrameBackground as G,FlippingTooltip as q,FocusRing as Z,STREAMING_PALETTE as Y,SceneRevisionDiagnosticsObserver as X,ScreenReaderSummary as U,SkipToTableLink as Q,TITLE_BASELINE as $,UpdateResultTracker as V,annotationLayout as K,coerceCanvasFill as J,computeCanvasAriaLabel as tt,computeEasing as et,computeRawProgress as nt,createDefaultAnnotationRules as it,defaultTooltipStyle as ot,filterSparseArray as rt,geoSceneNodeToSVG as st,getDevicePixelRatio as at,getPointerHitRadius as ct,isAnnotationActivationTarget as lt,isServerEnvironment as ut,lerp as ht,normalizeTooltip as dt,now as pt,observationInputType as ft,prepareCanvas as mt,renderAnnotationPass as gt,renderLegendFromConfig as yt,resolveCSSColor as vt,smartTooltipEntries as bt,useAnnotationActivationOptions as wt,useFrame as Pt,useFrameCanvasHost as xt,useSceneRevisionDiagnostics as Rt}from"./chunk-chunk-HCNDE26Q.module.min.js";import{getMax as St}from"./chunk-chunk-2NVFEB7P.module.min.js";import{resolveThemeSemanticColors as Lt}from"./chunk-chunk-PMR47KRY.module.min.js";import{glyphHitGeometry as At}from"./chunk-chunk-KTWEBFMX.module.min.js";import{SafeRender as kt,useHydration as Ct,useWasHydratingFromSSR as Dt}from"./chunk-chunk-ACLDBMRH.module.min.js";import{useRef as jt,useState as Mt,useEffect as Tt,useMemo as Bt,useCallback as _t,useImperativeHandle as It,forwardRef as Nt,memo as Et}from"react";import{geoPath as Ft}from"d3-geo";import{quadtree as Ot}from"d3-quadtree";import{geoMercator as Wt,geoEqualEarth as zt,geoAlbersUsa as Ht,geoOrthographic as Gt,geoNaturalEarth1 as qt,geoEquirectangular as Zt}from"d3-geo";var Yt={mercator:Wt,equalEarth:zt,albersUsa:Ht,orthographic:Gt,naturalEarth:qt,equirectangular:Zt};function Xt(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Ut(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Qt(t,e,n){return t?"function"==typeof t?{...n,...t(e)}:{...n,...t}:{...n}}function $t(t,e){if(2>t.length)return[t];const n=.4*e,i=[];let o=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>n?(2>o.length||i.push(o),o=[r]):o.push(r)}return 2>o.length||i.push(o),i}function Vt(t,e,n=24){const i=e[0]-t[0],o=e[1]-t[1],r=Math.sqrt(i*i+o*o);if(0===r)return[t,e];const s=-o/r,a=i/r,c=Math.min(.3*r,80),l=(t[0]+e[0])/2+s*c,u=(t[1]+e[1])/2+a*c,h=[];for(let i=0;n>=i;i++){const o=i/n,r=1-o;h.push([r*r*t[0]+2*r*o*l+o*o*e[0],r*r*t[1]+2*r*o*u+o*o*e[1]])}return h}function Kt(t,e){if(2>t.length)return t;const n=e/2+1,i=[];for(let e=0;t.length>e;e++){const o=t[e];let r,s;0===e?(r=t[1][0]-o[0],s=t[1][1]-o[1]):e===t.length-1?(r=o[0]-t[e-1][0],s=o[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;i.push([o[0]+s/a*n,o[1]+-r/a*n])}return i}function Jt(t,e,n,i,o){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const c=s/a,l=-r/a,u=o/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}import{scaleLinear as te}from"d3-scale";var ee=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ne=["scene-style","data-paint","accessibility","evidence"],ie=(t,e)=>({retainedData:t,invalidations:e}),oe=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],re=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],se=["scene-geometry","data-paint","accessibility","evidence"],ae=["scene-style","data-paint","accessibility","evidence"],ce=["overlay","accessibility","evidence"],le=[],ue={xAccessor:ie("rebuild",oe),yAccessor:ie("rebuild",oe),lineDataAccessor:ie("rebuild",oe),pointIdAccessor:ie("rebuild",se),lineIdAccessor:ie("rebuild",se),windowSize:ie("rebuild",oe),projection:ie("preserve",re),projectionExtent:ie("preserve",re),fitPadding:ie("preserve",re),lineType:ie("preserve",re),flowStyle:ie("preserve",re),graticule:ie("preserve",re),projectionTransform:ie("preserve",re),customLayout:ie("preserve",re),layoutConfig:ie("preserve",re),layoutMargin:ie("preserve",re),areaStyle:ie("preserve",ae),pointStyle:ie("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:ie("preserve",ae),colorScheme:ie("preserve",ae),themeCategorical:ie("preserve",ae),themeDiverging:ie("preserve",ae),themeSemantic:ie("preserve",ae),themeSequential:ie("preserve",ae),decay:ie("preserve",ae),pulse:ie("preserve",ae),layoutSelection:ie("preserve",ae),annotations:ie("preserve",ce),autoPlaceAnnotations:ie("preserve",ce),clock:ie("preserve",le),transition:ie("preserve",le),introAnimation:ie("preserve",le),onLayoutError:ie("preserve",le)},he=ie("preserve",re),de=class{constructor(){this.tracker=new V}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ee)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},ne):this.recordNoop("restyle")}recordConfig(t,e={}){const n=function(t){let e="preserve";const n=new Set;for(const i of t){const t=ue[i]??he;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)n.add(e)}return{retainedData:e,invalidations:n}}(t),i=new Set(n.invalidations);return e.retainedDataChanged&&i.add("data"),this.tracker.record({kind:"config",keys:t},i)}};import{geoDistance as pe,geoGraticule as fe,geoInterpolate as me}from"d3-geo";function ge(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var ye=class t{constructor(t){this.updateResults=new de,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:ge(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??pt()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),n=this.timestampBuffer?.toArray()??[],i=e.slice(-t),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new o(t),this.timestampBuffer=new o(t),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:ge(t.fitPadding)}:t}(t),n=this.config,i=this.getConfiguredWindowSize(),o=Object.keys(e).filter(t=>e[t]!==n[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==i;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(o,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),n=this.pointBuffer?this.pointBuffer.toArray():this.pointData,i=this.timestampBuffer?.toArray()??[],r=n.slice(-e),s=i.slice(-r.length),a=this.currentTime();this.pointBuffer=new o(e),this.timestampBuffer=new o(e),r.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(s[e]??a)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();l(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const n of t)l(this.pointBuffer,n,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const n="function"==typeof e?e:t=>t[e],i=new Set(Array.isArray(t)?t:[t]),o=[];return this.lineData=this.lineData.filter(t=>!i.has(n(t)+"")||(o.push(t),!1)),o.length>0?(this.version++,this.updateResults.recordData("remove",o.length)):this.updateResults.recordNoop("remove"),o}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const n="function"==typeof e?e:t=>t[e],i=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>i.has(n(t)+"");r(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!i.has(n(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const n of this.scene){const i=this._baseStyles.get(n)??n.style,o=e(n,t);n.style=o?{...i,...o}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,n=this.projection,i=this.geoPath,o=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return zt();if("string"==typeof t){const e=Yt[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),zt())}if("object"==typeof t&&"type"in t){const e=Yt[t.type],n=e?e():zt();return t.rotate&&"rotate"in n&&n.rotate(t.rotate),t.center&&"center"in n&&n.center(t.center),n}return t}(e.projection),this.geoPath=Ft(this.projection),this.fitProjection(t),this.geoPath=Ft(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(t,e)=>l([t,e]),invertedPoint:(t,e)=>l.invert?l.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=n,this.geoPath=i,this.scales=o,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,n=t.height/2,i=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:n}));i.length>0&&this.startTransition(i)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,n=this.config,i=[...this.areas],o=Xt(n.xAccessor,"lon"),r=Xt(n.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[o(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Ut(n.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[o(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==i.length){if(n.projectionExtent){const[[i,o],[r,s]]=n.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,o],[i,s],[r,s],[r,o],[i,o]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const i=n.fitPadding??0,o=Math.min(t.width,t.height);e.scale(o/2-o*i),e.translate([t.width/2,t.height/2])}else{const o=n.fitPadding??0,r=t.width*o,s=t.height*o;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:i})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const n=this.projection;if(!n)return;const i=this.geoPath,o=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*t.k),n.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=Ft(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=i,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const n=this.projection;if(!n)return;const i=this.geoPath,o=this.scales,r=n.scale(),s=[...n.translate()],a=this.currentZoom;n.scale(this.baseScale*t),n.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=Ft(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.scale(r),n.translate(s),this.currentZoom=a,this.geoPath=i,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const n=this.projection;if(!n||!n.rotate)return;const i=this.geoPath,o=this.scales,r=[...n.rotate()];n.rotate(t),this.geoPath=Ft(n),this.scales={projection:n,geoPath:this.geoPath,projectedPoint:(t,e)=>n([t,e]),invertedPoint:(t,e)=>n.invert?n.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(n.rotate(r),this.geoPath=i,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,n=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(n++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=n)return void(this._quadtree=null);const i=Array(n);let o=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(i[o++]=t);this._quadtree=Ot().x(t=>t.x).y(t=>t.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,n=this.projection,i=this.geoPath;if(e.customLayout&&this.scales){const n=e.layoutMargin??{top:0,right:0,bottom:0,left:0},i=W(e.colorScheme,e.themeCategorical,Y),o={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:n,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...i]},resolveColor:O(i,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(o)}catch(t){const n=null!==this.lastCustomLayoutResult,i=S("geo",t,n,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(i)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return n?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of s)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return N({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:n,areas:i,points:o,lines:r,layout:s}){const a=Xt(t.xAccessor,"lon"),c=Xt(t.yAccessor,"lat"),l=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),h=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),d=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,i=fe();e.step&&i.step(e.step);const o=n(i())||"";o&&l.push({type:"geoarea",pathData:o,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth||.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of i){const i=n(e);if(!i)continue;const o=n.centroid(e),r=n.bounds(e),s=n.area(e);l.push({type:"geoarea",pathData:i,centroid:o,bounds:r,screenArea:s,style:Qt(t.areaStyle,e,u),datum:e,interactive:!0})}const p=Ut(t.lineDataAccessor);for(const n of r){const i=p(n);if(!i||2>i.length)continue;let o=[];if("geo"===t.lineType){const t=Array(i.length);for(let e=0;i.length>e;e++)t[e]=[a(i[e]),c(i[e])];for(let n=0;t.length-1>n;n++){const i=t[n],r=t[n+1],s=pe(i,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=me(i,r);for(let t=0;a>=t;t++){if(n>0&&0===t)continue;const i=e(c(t/a));null!=i&&o.push(i)}}}else for(let t=0;i.length>t;t++){const n=i[t],r=e([a(n),c(n)]);null!=r&&o.push(r)}if(2>o.length)continue;const r=Qt(t.lineStyle,n,h),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==i.length||2>o.length||"arc"!==t.flowStyle?2!==i.length||2>o.length||"offset"!==t.flowStyle||(o="geo"===t.lineType?Kt(o,u):Jt(o[0],o[o.length-1],0,0,u)):o=Vt(o[0],o[o.length-1]);const d=$t(o,s.width);if(d.length>1)for(const t of d)2>t.length||l.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:n});else l.push({type:"line",path:2>o.length&&d[0]||o,style:r,datum:n})}const f=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,m=e.clipAngle?e.clipAngle()??0:0,g=m>0?m*Math.PI/180:null,y=e.rotate?e.rotate():[0,0,0],v="function"==typeof e.center?e.center():[0,0],b=[(v[0]??0)-y[0],(v[1]??0)-y[1]];for(const n of o){const i=a(n),o=c(n);if(null!=g&&pe([i,o],b)>g)continue;const r=e([i,o]);if(!r)continue;const s=t.pointStyle?t.pointStyle(n):{...d},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:n,pointId:f?f(n)+"":void 0};l.push(u)}return l}({config:e,projection:n,path:i,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const n=function(t,e,n,i){const o=t.filter(t=>"point"===t.type);if(2>o.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const c=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,l="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=o.find(t=>t.datum&&c(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const h=o.map(t=>t.datum?Number(l(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),d=St(h,1);i>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const n=t[e];"geoarea"===n.type&&n.interactive&&t.splice(e,1)}const p="strip"===a?function(t,e,n,i,o){const r=Math.max(3,Math.min(8,.35*o.height)),s=Math.max(1,o.width-2*r),a=o.height/2,c=te().domain([0,i]).range([0,s]);e.x=r,e.y=a;const l=[];for(const o of t){if(o===e)continue;if(!o.datum){o.x=r,o.y=a;continue}const t=Number(n(o.datum)),s=r+(isFinite(t)&&t>=0&&i>0?c(t):0);o.x=s,o.y=a,l.push({node:o,x:s})}l.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(o.height/2-1,6));let h=0;for(;l.length>h;){let t=h+1;for(;l.length>t&&3>Math.abs(l[t].x-l[h].x);)t++;const e=t-h;if(e>1&&u>0)for(let t=0;e>t;t++)l[h+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));h=t}return{cx:r,cy:a,maxCost:i,availableRadius:s,layout:"strip"}}(o,u,l,d,n):function(t,e,n,i,o,r){const s=e.x,a=e.y,c=r.width/2,l=r.height/2,u=Math.min(r.width,r.height)/2,h=te().domain([0,i]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,d=Math.atan2(u-a,t-s),p=Math.hypot(t-s,u-a),f=Number(n(r.datum)),m=isFinite(f)&&f>=0?i>0?h(f):0:p,g=c+Math.cos(d)*m,y=l+Math.sin(d)*m;r.x=t+(g-t)*o,r.y=u+(y-u)*o}return e.x=s+(c-s)*o,e.y=a+(l-a)*o,{cx:e.x,cy:e.y,maxCost:i,availableRadius:u,layout:"radial"}}(o,u,l,d,s,n),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of o)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const n of f){const i=n.datum?.source,o=n.datum?.target;if(null!=i&&null!=o){const r=t.get(i+""),s=t.get(o+"");if(r&&s)if("fractional"===e.lineMode&&n.path.length>2){const t=n.path[0],e=n.path[n.path.length-1],i=[r[0]-t[0],r[1]-t[1]],o=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;n.path.length>t;t++)a.push(a[t-1]+Math.hypot(n.path[t][0]-n.path[t-1][0],n.path[t][1]-n.path[t-1][1]));const c=a[a.length-1];n.path=n.path.map((t,e)=>{const r=c>0?a[e]/c:e/(n.path.length-1);return[t[0]+i[0]*(1-r)+o[0]*r,t[1]+i[1]*(1-r)+o[1]*r]})}else n.path=[r,s]}}}return p}(this.scene,t,e,this.areas.length);n&&(this.cartogramLayout=n)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const n=this.scene.filter(t=>"point"===t.type);for(let i=0;n.length>i;i++){const o=R(t,i,e);n[i]._decayOpacity=o,n[i].style={...n[i].style,opacity:o}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const n=this.scene.filter(t=>"point"===t.type),i=this.timestampBuffer.toArray(),o=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let a=!1;for(let c=0;n.length>c&&i.length>c;c++){const l=s(e,i[c],t);a=h(n[c],l,o,r)||a}return a}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&a(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const n=new Map;for(const e of t)"point"===e.type&&e.pointId&&n.set(e.pointId,[e.x,e.y]);const i=this.scene.filter(t=>"point"===t.type);let o=!1;for(const t of i)if(t.pointId){const e=n.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(o=!0))}for(const t of i)t.pointId&&!n.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},o=!0);o&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=nt(t,this.activeTransition),n=et(e),i=this.scene.filter(t=>"point"===t.type);for(const t of i){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=ht(t.x,t._targetX,n),t.y=ht(e,t._targetY,n)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*n})}if(e>=1){for(const t of i)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};ye.QUADTREE_THRESHOLD=500;var ve=ye;function be(t,e,n,i,o,r,s=0,a=i){if(r){const t=L(r,e,n,i,s);if(t)return t}else{let o=null,r=i;for(const s of t){if("point"!==s.type)continue;if(!1===s.interactive)continue;const t=s.x-e,a=s.y-n,c=Math.sqrt(t*t+a*a);k(s.r,i)>=c&&r>c&&(o=s,r=c)}if(o)return{node:o,distance:r}}let c=null,l=i;for(const o of t){if("glyph"!==o.type)continue;if(null==o.datum)continue;const t=At(o.glyph,o.size),r=o.x+t.centerDx-e,s=o.y+t.centerDy-n,a=Math.sqrt(r*r+s*s);k(t.radius,i)>=a&&l>a&&(c=o,l=a)}if(c)return{node:c,distance:l};for(let i=t.length-1;i>=0;i--){const r=t[i];if("geoarea"!==r.type)continue;const s=r;if(!1===s.interactive)continue;const[[a,c],[l,u]]=s.bounds;if(!(a>e||e>l||c>n||n>u)&&(s._cachedPath2D||(s._cachedPath2D=new Path2D(s.pathData)),o.isPointInPath(s._cachedPath2D,e,n)))return{node:s,distance:0}}let u=null,h=a;for(const i of t){if("line"!==i.type)continue;const t=i,{path:o}=t,r=Math.max((t.style.strokeWidth||2)+4,5,a);for(let i=0;o.length-1>i;i++){const[s,a]=o[i],[c,l]=o[i+1],d=we(e,n,s,a,c,l);r>=d&&h>d&&(u=t,h=d)}}return u?{node:u,distance:h}:null}function we(t,e,n,i,o,r){const s=o-n,a=r-i,c=s*s+a*a;if(0===c)return Math.sqrt((t-n)**2+(e-i)**2);let l=((t-n)*s+(e-i)*a)/c;return l=Math.max(0,Math.min(1,l)),Math.sqrt((t-(n+l*s))**2+(e-(i+l*a))**2)}b(ve);import{useMemo as Pe,useRef as xe}from"react";import{jsx as Re,jsxs as Se}from"react/jsx-runtime";function Le(t){const{width:e,height:n,totalWidth:i,totalHeight:o,margin:r,showAxes:s,title:a,legend:c,legendHoverBehavior:l,legendClickBehavior:u,legendHighlightedCategory:h,legendIsolatedCategories:d,legendPosition:p,legendLayout:f,foregroundGraphics:m,annotations:g,onAnnotationActivate:y,onObservation:v,chartId:b,chartType:w,autoPlaceAnnotations:P,svgAnnotationRules:x,pointNodes:R,geoProjection:S}=t,L=wt({onAnnotationActivate:y,onObservation:v,chartId:b,chartType:w}),A=xe([g?.length??0,new Map]),k=g?.length??0;A.current[0]!==k&&(A.current=[k,new Map]);const C=Pe(()=>{if(!g||0===g.length)return null;const t=F(g),i=S?t.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=S(Number(t.coordinates[0]),Number(t.coordinates[1]));return e?{...t,x:e[0],y:e[1]}:t}):t,o={scales:{x:t=>Number(t),y:t=>Number(t)},timeAxis:"x",width:e,height:n,frameType:"xy",pointNodes:R,stickyPositionCache:A.current[1]},r=P?K({annotations:i,context:o,..."object"==typeof P?P:{}}):i;return gt(r,it("xy",L),x,o)},[g,P,x,e,n,R,L,S]);return s||a||c||m||C&&C.length>0?Se("svg",{role:"img",width:i,height:o,overflow:"visible",style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Re("title",{children:"string"==typeof a?a:"XY Chart"}),Re("desc",{children:"string"==typeof a?a+" (XY data visualization)":"XY data visualization"}),Se("g",{transform:"translate("+r.left+","+r.top+")",children:[C,m]}),a&&"string"==typeof a?Re("text",{x:i/2,y:$,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)"},children:a}):a?Re("foreignObject",{x:0,y:0,width:i,height:r.top,children:a}):null,yt({legend:c,totalWidth:i,totalHeight:o,margin:r,legendPosition:p,title:a,legendLayout:f,legendHoverBehavior:l,legendClickBehavior:u,legendHighlightedCategory:h,legendIsolatedCategories:d})]}):null}import{zoom as Ae,zoomIdentity as ke}from"d3-zoom";import{select as Ce}from"d3-selection";function De([t,e,n]){const i=1<<n;return[t-Math.floor(t/i)*i,e,n]}function je(t,e,n,i,o){return"function"==typeof t?t(e,n,i,o):t.replace("{z}",e+"").replace("{x}",n+"").replace("{y}",i+"").replace("{r}",o>1?"@2x":"")}var Me=class{constructor(t=256){this.cache=new Map,this.limit=t}get(t){const e=this.cache.get(t);return e&&(e.lastUsed=performance.now()),e}set(t,e){this.cache.set(t,e),this.cache.size>this.limit&&this.evict()}evict(){for(;this.cache.size>this.limit;){let t,e=1/0;for(const[n,i]of this.cache)e>i.lastUsed&&(e=i.lastUsed,t=n);if(!t)break;{const e=this.cache.get(t);e&&(e.img.onload=null,e.img.onerror=null,e.img.src=""),this.cache.delete(t)}}}clear(){for(const t of this.cache.values())t.img.onload=null,t.img.onerror=null,t.img.src="";this.cache.clear()}};var Te=class{constructor(t){this.capacity=t,this.particles=Array(t);for(let e=0;t>e;e++)this.particles[e]={t:0,offset:0,lineIndex:0,active:!1,x:0,y:0}}spawn(t,e=Math.random){for(let n=0;this.capacity>n;n++){const i=this.particles[n];if(!i.active)return i.active=!0,i.t=0,i.offset=.6*(e()-.5),i.lineIndex=t,i.x=0,i.y=0,i}return null}step(t,e,n,i){for(let o=0;this.capacity>o;o++){const r=this.particles[o];if(!r.active)continue;const s=n[r.lineIndex];if(!s||2>s.length){r.active=!1;continue}if(r.t+=t*e,r.t>=1){r.active=!1;continue}const a=Be(s),c=_e(s,r.t*a),l=(i[r.lineIndex]||2)/2;r.x=c.x+c.nx*r.offset*l*2,r.y=c.y+c.ny*r.offset*l*2}}countForLine(t){let e=0;for(let n=0;this.capacity>n;n++)this.particles[n].active&&this.particles[n].lineIndex===t&&e++;return e}clear(){for(let t=0;this.capacity>t;t++)this.particles[t].active=!1}};function Be(t){let e=0;for(let n=1;t.length>n;n++){const i=t[n][0]-t[n-1][0],o=t[n][1]-t[n-1][1];e+=Math.sqrt(i*i+o*o)}return e}function _e(t,e){let n=0;for(let i=1;t.length>i;i++){const o=t[i][0]-t[i-1][0],r=t[i][1]-t[i-1][1],s=Math.sqrt(o*o+r*r);if(n+s>=e||i===t.length-1){const a=s>0?(e-n)/s:0,c=s>.001?s:1;return{x:t[i-1][0]+o*a,y:t[i-1][1]+r*a,nx:-r/c,ny:o/c}}n+=s}const i=t[t.length-1];return{x:i[0],y:i[1],nx:0,ny:0}}function Ie(t){if(!t)return;const e=[];for(const n of t)if("point"===n.type)e.push(n);else if("glyph"===n.type){const t=n,i=At(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+i.centerDx,y:t.y+i.centerDy,r:i.radius})}return e}import{jsx as Ne,jsxs as Ee}from"react/jsx-runtime";function Fe({data:t}){if(!t)return null;if(t.properties)return Ne("div",{className:"semiotic-tooltip",style:ot,children:Ne("div",{style:{fontWeight:600},children:t.properties.name||t.properties.NAME||t.properties.id||"Feature"})});const e=null!=t.data?t.data:t;if(!e||"object"!=typeof e)return null;const n=bt(e),i=null!=n.title?n.title+"":null;return null==i&&0===n.entries.length?null:Ee("div",{className:"semiotic-tooltip",style:ot,children:[null!=i&&Ne("div",{style:{fontWeight:600,marginBottom:n.entries.length?2:0},children:i}),n.entries.map(t=>Ee("div",{children:[Ee("span",{style:{opacity:.7},children:[t.key,": "]}),Ne("span",{style:{fontWeight:600},children:A(t.value)})]},t.key))]})}Fe.ownsChrome=!0;var Oe={top:10,right:10,bottom:10,left:10},We=null;function ze(){if(null!==We)return We;if("undefined"==typeof window)return!1;const t="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,e="undefined"!=typeof navigator&&"number"==typeof navigator.hardwareConcurrency&&4>=navigator.hardwareConcurrency,n="undefined"!=typeof navigator&&"number"==typeof navigator.deviceMemory&&4>=navigator.deviceMemory;return We=t||e||n}function He(){return ze()?12:30}var Ge={width:28,height:28,border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,background:"rgba(255,255,255,0.9)",color:"#333",fontSize:16,fontWeight:600,lineHeight:1,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:0,boxShadow:"0 1px 3px rgba(0,0,0,0.1)"};function qe(t){return"string"==typeof t?t:"object"==typeof t&&t&&"type"in t?t.type:null}function Ze(t){return t?t.getContext("2d"):null}import{jsx as Ye,jsxs as Xe}from"react/jsx-runtime";var Ue=Et(Nt(function(t,e){const{projection:o,projectionExtent:r,fitPadding:s,projectionTransform:a,areas:l,points:h,lines:b,customLayout:w,layoutConfig:P,layoutSelection:R,onLayoutError:S,xAccessor:L,yAccessor:A,lineDataAccessor:k,pointIdAccessor:N,lineIdAccessor:F,lineType:O="geo",flowStyle:W="basic",graticule:Y,zoomable:$,zoomExtent:V,onZoom:K,dragRotate:et,showParticles:nt,particleStyle:it,tileURL:ot,tileAttribution:ht,tileCacheSize:dt,size:pt,width:gt,height:yt,responsiveWidth:bt,responsiveHeight:wt,margin:St,className:At,background:kt,windowSize:Nt=500,renderMode:Et,areaStyle:Ft,pointStyle:Ot,lineStyle:Wt,colorScheme:zt,enableHover:Ht=!0,hoverAnnotation:Gt,tooltipContent:qt,allowTooltipOverflow:Zt=!1,customClickBehavior:Yt,customHoverBehavior:Xt,onObservation:Ut,annotationObservationCallback:Qt,chartId:$t,annotations:Vt,onAnnotationActivate:Kt,autoPlaceAnnotations:Jt,svgAnnotationRules:te,decay:ee,pulse:ne,transition:ie,animate:oe,staleness:re,frameScheduler:se,clock:ae,random:ce,seed:le,paused:ue=!1,suspendWhenHidden:he=!0,backgroundGraphics:de,foregroundGraphics:pe,title:fe,legend:me,legendPosition:ge,legendLayout:ye,legendHoverBehavior:we,legendClickBehavior:Pe,legendHighlightedCategory:xe,legendIsolatedCategories:Re,legendCategoryAccessor:Se,onCategoriesChange:Be,showAxes:_e,accessibleTable:Ne=!0,description:Ee,summary:We}=t,{customHoverBehavior:Ue,customClickBehavior:Qe,hasClickBehavior:$e}=f({customHoverBehavior:Xt,customClickBehavior:Yt,onObservation:Ut,chartId:$t,chartType:"StreamGeoFrame"}),Ve=pt||[gt||600,yt||400],Ke=jt(!0),Je=Pt({sizeProp:Ve,responsiveWidth:bt,responsiveHeight:wt,userMargin:St,marginDefault:Oe,title:fe,legend:me,legendPosition:ge,foregroundGraphics:pe,backgroundGraphics:de,animate:oe,transitionProp:ie,frameScheduler:se,clock:ae,random:ce,seed:le,paused:ue,suspendWhenHidden:he,themeDirtyRef:Ke}),{reducedMotionRef:tn,responsiveRef:en,size:nn,margin:on,adjustedWidth:rn,adjustedHeight:sn,resolvedForeground:an,resolvedBackground:cn,transition:ln,introEnabled:un,tableId:hn,frameRuntime:dn,rafRef:pn,renderFnRef:fn,scheduleRender:mn,currentTheme:gn}=Je,yn=Ct(),vn=Dt(),bn=Bt(()=>Array.isArray(l)?rt(l):l,[l]),wn=Bt(()=>rt(h),[h]),Pn=Bt(()=>rt(b),[b]),xn=Bt(()=>null!=et?et:"orthographic"===qe(o),[et,o]),Rn=Bt(()=>({projection:o,projectionExtent:r,fitPadding:s,xAccessor:L,yAccessor:A,lineDataAccessor:k,lineType:O,flowStyle:W,areaStyle:Ft,pointStyle:Ot,lineStyle:Wt,colorScheme:zt,themeSemantic:Lt(gn),themeSequential:gn?.colors?.sequential,themeDiverging:gn?.colors?.diverging,themeCategorical:gn?.colors?.categorical,graticule:Y,projectionTransform:a,windowSize:Nt,clock:dn.now,decay:ee,pulse:ne,transition:ln,introAnimation:un,annotations:Vt,pointIdAccessor:N,lineIdAccessor:F,customLayout:w,layoutConfig:P,onLayoutError:S,layoutMargin:on}),[o,r,s,L,A,k,O,W,Ft,Ot,Wt,zt,gn,Y,a,Nt,dn.now,ee,ne,ln,un,Vt,N,F,w,P,S,on]),Sn=_(Rn),Ln=jt(null);Ln.current||(Ln.current=new ve(Sn));const An=jt(null),kn=jt(null),Cn=jt(null);ot&&!Cn.current&&(Cn.current=new Me(dt||256));const Dn=jt(Vt),jn=jt(null),Mn=jt(ke),Tn=jt(!1),Bn=jt(null),_n=_t(t=>{Bn.current=t,en&&"object"==typeof en&&(en.current=t)},[en]),In=jt(null),Nn=jt(null),En=jt(null),Fn=jt(0);if(nt&&!En.current){const t=it?.maxPerLine??He();En.current=new Te(50*t)}const On=jt(null),Wn=jt(null),zn=jt(!1),Hn=jt(!1),Gn=Rt("StreamGeoFrame"),qn=jt(void 0),[Zn,Yn]=Mt(null),[,Xn]=Mt(0),Un=jt(0),[Qn,$n]=Mt(!1),Vn=p(Ln,Se,Be,t=>t.getPoints());T(Ln,Sn,Ke,mn),B(Ln,R,Ke,mn),Tt(()=>{const t=Ln.current;t&&(bn&&t.setAreas(bn),h&&t.setPoints(wn),b&&t.setLines(Pn),Ke.current=!0,mn())},[bn,h,wn,b,Pn,mn]);const Kn=_t(t=>{null!=t&&"object"==typeof t&&(Ln.current?.pushPoint(t),Ke.current=!0,mn())},[mn]),Jn=_t(t=>{const e=rt(t);0!==e.length&&(Ln.current?.pushMany(e),Ke.current=!0,mn())},[mn]),ti=_t(t=>{null!=t&&"object"==typeof t&&(Ln.current?.pushLine(t),Ke.current=!0,mn())},[mn]),ei=_t(t=>{const e=rt(t);0!==e.length&&(Ln.current?.pushManyLines(e),Ke.current=!0,mn())},[mn]),ni=_t(()=>{Ln.current?.clear(),Ke.current=!0,mn()},[mn]);It(e,()=>({push:Kn,pushMany:Jn,removePoint:t=>{const e=Ln.current?.removePoint(t)??[];return e.length>0&&(Ke.current=!0,mn()),e},pushLine:ti,pushManyLines:ei,removeLine:t=>{const e=Ln.current?.removeLine(t)??[];return e.length>0&&(Ke.current=!0,mn()),e},getLines:()=>Ln.current?.getLines()??[],clear:ni,getProjection:()=>Ln.current?.scales?.projection??null,getGeoPath:()=>Ln.current?.scales?.geoPath??null,getCartogramLayout:()=>Ln.current?.cartogramLayout??null,getCustomLayout:()=>Ln.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>Ln.current?.lastCustomLayoutFailure??null,getZoom:()=>Mn.current.k,resetZoom:()=>{const t=Bn.current;t&&jn.current&&Ce(t).call(jn.current.transform,ke)},getData:()=>Ln.current?.getPoints()??[]}),[Kn,Jn,ti,ei,ni,mn]);const{hoverHandlerRef:ii,onPointerMove:oi,onPointerLeave:ri}=Je,{canvasRef:si,interactionCanvasRef:ai}=xt(Je,{hydrated:yn,wasHydratingFromSSR:vn,storeRef:Ln,dirtyRef:Ke,cleanup:()=>Cn.current?.clear(),canvasPaintDependencies:[rn,sn,kt,de,Et,mn]});Tt(()=>{ii.current=t=>{if(!Ht)return;const e=Ln.current;if(!e||!e.scene.length)return;const n=si.current;if(!n)return;const i=n.getBoundingClientRect(),o=t.clientX-i.left-on.left,r=t.clientY-i.top-on.top;if(0>o||o>rn||0>r||r>sn)return On.current=null,Wn.current=null,Yn(null),Ue?.(null),void mn();kn.current||(kn.current="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(1,1):document.createElement("canvas"));const s=Ze(kn.current);if(!s)return;const a=ct(30,t.pointerType),c=ct(6,t.pointerType),l=be(e.scene,o,r,a,s,e.quadtree,e.maxPointRadius,c);if(l){const t=l.node,e=t.datum,n=Array.isArray(e)?null:e?.properties?e:e?.data||e;let i,s;"point"===t.type?(i=t.x,s=t.y):"geoarea"===t.type?(i=t.centroid[0],s=t.centroid[1]):(i=o,s=r);const a={...n,...n?.properties||{},data:n,properties:n?.properties,__semioticHoverData:!0,x:i,y:s};On.current=a,Wn.current=t,Yn(a),Ue?.(a),mn()}else On.current&&(On.current=null,Wn.current=null,Yn(null),Ue?.(null),mn())}},[Ht,rn,sn,on,Ue,mn,ii,si]),Je.hoverLeaveRef.current=()=>{On.current=null,Wn.current=null,Yn(null),Ue?.(null),mn()};const ci=_t(t=>{if(lt(t.target))return;if(!Qe)return;const e=Ln.current;if(!e||!e.scene.length)return void Qe(null);const n=t.currentTarget.getBoundingClientRect(),i=t.clientX-n.left-on.left,o=t.clientY-n.top-on.top;if(0>i||i>rn||0>o||o>sn)return void Qe(null);kn.current||(kn.current="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(1,1):document.createElement("canvas"));const r=Ze(kn.current);if(!r)return void Qe(null);const s=ct(30,qn.current),a=ct(6,qn.current),c=be(e.scene,i,o,s,r,e.quadtree,e.maxPointRadius,a);if(c){const t=c.node.datum,e=Array.isArray(t)?null:t?.properties?t:t?.data||t,n=e?.properties?{...e,...e.properties}:e;return void Qe({...n,data:e,properties:e?.properties,__semioticHoverData:!0,x:i,y:o,time:i,value:o},{type:"activate",inputType:ft(qn.current)})}Qe(null)},[sn,rn,Qe,on]),{kbFocusIndexRef:li,focusedNavPointRef:ui,onKeyDown:hi}=d({storeRef:Ln,hoverRef:On,hoveredNodeRef:Wn,setHoverPoint:Yn,customHoverBehavior:Ue,customClickBehavior:Qe,scheduleRender:mn}),di=_t(t=>{qn.current=t.pointerType,li.current=-1,ui.current=null,oi(t)},[ui,li,oi]),pi=_t(t=>{qn.current=t.pointerType},[]);fn.current=()=>{if(pn.current=null,!dn.isActive)return;const t=si.current,e=Ln.current;if(!t||!e)return;const o=dn.now();let r=!1;const s=Nn.current;let a=!1;s&&(Nn.current=null,e.applyRotation(s,{width:rn,height:sn}),a=!0);const l=e.advanceTransition(tn.current?o+1e6:o),h=!tn.current&&l,d=Gn.current.beforeCompute(e.getLastUpdateResult(),h);let p=!1;if(Ke.current&&!l){const n={width:rn,height:sn},i=e.hasProjection(),o=xn&&i?e.getRotation():null;e.computeScene(n);const r=Mn.current,s=1!==r.k||0!==r.x||0!==r.y;xn&&o?s?(e.setRotation(o),e.applyZoomScale(r.k,n)):e.applyRotation(o,n):s&&e.applyZoomTransform(r,n),Ke.current=!1,p=!0,t.setAttribute("aria-label",tt(e.scene,"Geographic chart")),Vn()}Gn.current.afterCompute(d,p,!1);const f=at(),v=nt&&!tn.current&&!!En.current,b=e.consumeStylePaintPending(),w=u(e,o,p,Hn),P=m({dirtyOrRebuilt:p,transitioning:h,continuous:v,liveEncoding:w.changed,forced:a||b});if(ot&&Cn.current){const t=An.current;if(t&&e.scales?.projection){const n=mt(t,nn,on,f);if(n){n.clearRect(-on.left,-on.top,nn[0],nn[1]),n.save(),n.beginPath(),n.rect(0,0,rn,sn),n.clip();const t=function(t,e){const{tileURL:n,projection:i,width:o,height:r,tileCache:s,onTileLoad:a}=e,c=i.scale(),l=i.translate(),u=function(t){const{size:e,scale:n,translate:i,clampX:o=!0,clampY:r=!0}=t,s=Math.max(Math.log(n)/Math.LN2-8,0),a=Math.round(s),c=1<<a,l=Math.pow(2,s-a+8),u=i[0]-n/2,h=i[1]-n/2,d=Math.max(o?0:-1/0,Math.floor((0-u)/l)),p=Math.min(o?c:1/0,Math.ceil((e[0]-u)/l)),f=Math.max(r?0:-1/0,Math.floor((0-h)/l)),m=Math.min(r?c:1/0,Math.ceil((e[1]-h)/l)),g=[];for(let t=f;m>t;++t)for(let e=d;p>e;++e)g.push([e,t,a]);return{tiles:g,translate:[u/l,h/l],scale:l}}({size:[o,r],scale:2*c*Math.PI,translate:l}),h=at();let d=!0;for(const e of u.tiles){const[i,o,r]=De(e),c=`${r}/${i}/${o}`;let l=s.get(c);if(!l){const t=new Image;t.crossOrigin="anonymous";const e={img:t,loaded:!1,key:c,lastUsed:performance.now()};s.set(c,e),t.onload=()=>{e.loaded=!0,a?.()},t.onerror=()=>{e.loaded=!0},t.src=je(n,r,i,o,h),l=e}if(!l.loaded){d=!1;continue}const p=u.scale;t.drawImage(l.img,(e[0]+u.translate[0])*p-.5,(e[1]+u.translate[1])*p-.5,p+1,p+1)}return d}(n,{tileURL:ot,projection:e.scales.projection,width:rn,height:sn,tileCache:Cn.current,onTileLoad:()=>mn()});n.restore(),t||(r=!0)}}}if(P){const i=mt(t,nn,on,f);if(!i)return;i.clearRect(-on.left,-on.top,nn[0],nn[1]),ot||y(i,{background:kt,hasBackgroundGraphics:!!de,width:rn,height:sn}),i.save(),i.beginPath(),i.rect(0,0,rn,sn),i.clip();const s=e.scene,a=e.scales,l={width:rn,height:sn};if(D({context:i,nodes:s,renderMode:Et,pixelRatio:f,paintBuiltIn:t=>{!function(t,e){const n=e.filter(t=>"geoarea"===t.type);for(const e of n){if(!e.pathData)continue;e._cachedPath2D||(e._cachedPath2D=new Path2D(e.pathData));const n=e._cachedPath2D,i=J(t,e.style.fill)||"#e0e0e0";if("none"!==i&&(t.fillStyle=i,t.globalAlpha=(e._decayOpacity??1)*(e.style.fillOpacity??1),t.fill(n)),e.style.stroke&&"none"!==e.style.stroke){if(t.strokeStyle=vt(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||.5,t.globalAlpha=e._decayOpacity??1,e.style.strokeDasharray){const n=e.style.strokeDasharray.split(",").map(Number);t.setLineDash(n)}else t.setLineDash([]);t.stroke(n)}j(t,e,n),t.globalAlpha=1,t.setLineDash([])}}(i,t),n(i,t,a,l),c(i,t,a,l),C(i,t,a,l)}}),v&&En.current){const t=En.current,e=s.filter(t=>"line"===t.type);if(e.length>0){const n=it||{},s=.3*(n.speedMultiplier??1),a=n.maxPerLine??He(),c=n.spawnRate??(ze()?.06:.15),l=n.radius??2,u=n.opacity??.7,h=o/1e3,d=Fn.current>0?Math.min(h-Fn.current,.1):.016;Fn.current=h;const p=e.map(t=>t.path),f=e.map(t=>t.style.strokeWidth||2);for(let n=0;e.length>n;n++)dn.random()<c&&t.countForLine(n)<a&&t.spawn(n,dn.random);t.step(d,s,p,f),i.globalAlpha=u;for(let o=0;t.particles.length>o;o++){const r=t.particles[o];if(!r.active)continue;const s=e[r.lineIndex],a="function"==typeof n.color?n.color(s?.datum??{}):"source"!==n.color&&n.color?n.color:s?.style.stroke||"#fff";i.beginPath(),i.arc(r.x,r.y,l,0,2*Math.PI),i.fillStyle=a,i.fill()}i.globalAlpha=1,r=!0}}i.restore()}const x=Wn.current,R=!(!x||"geoarea"!==x.type&&"point"!==x.type),S=g(R,zn.current),L=ai.current;if(L&&S){const t=mt(L,nn,on,f);if(t){if(t.clearRect(-on.left,-on.top,nn[0],nn[1]),x&&"geoarea"===x.type){const e=new Path2D(x.pathData);t.fillStyle="rgba(255, 255, 255, 0.3)",t.fill(e),t.strokeStyle="rgba(0, 0, 0, 0.5)",t.lineWidth=2,t.stroke(e)}if(x&&"point"===x.type){const e=x,n="object"==typeof Gt?Gt:void 0,o=n?.pointColor||i(x);t.beginPath(),t.arc(e.x,e.y,e.r+3,0,2*Math.PI),o?(t.save(),t.globalAlpha=.4,t.fillStyle=o,t.fill(),t.restore()):(t.fillStyle="rgba(255, 255, 255, 0.4)",t.fill()),t.strokeStyle=o||"rgba(0, 0, 0, 0.5)",t.lineWidth=2,t.stroke()}}zn.current=R}const A=Vt!==Dn.current;A&&(Dn.current=Vt),(p||A||h&&Vt&&Vt.length>0)&&(p||A||o-Un.current>=33)&&(Xn(t=>t+1),Un.current=o),(h||null!=e.activeTransition||w.pending||r)&&mn()},I(re,Ln,Ke,mn,Qn,$n),Tt(()=>{if("production"!==process.env.NODE_ENV&&ot){const t=qe(o);t&&"mercator"!==t&&console.warn(`[StreamGeoFrame] tileURL is set but projection is "${t}". Raster tiles use Web Mercator and will not align with other projections.`)}},[ot,o]),Tt(()=>{const t=Bn.current;if(!$||!t)return jn.current&&t&&(Ce(t).on(".zoom",null),jn.current=null),void(t&&Ce(t).on("mousedown.rotate",null).on("touchstart.rotate",null));const[e,n]=V||[1,8],i={width:rn,height:sn};if(xn){let o=Mn.current.k;const r=t=>{o=Math.max(e,Math.min(n,t)),Mn.current=ke.scale(o);const r=Ln.current;r&&(r.applyZoomScale(o,i),Ke.current=!1,mn(),r.scales?.projection&&K?.({projection:r.scales.projection,zoom:r.currentZoom}))};jn.current={scaleBy:(t,e)=>r(o*e),transform:(t,e)=>r(e?.k??1)};const s=t=>{t.preventDefault(),r(o*(0>t.deltaY?1.1:1/1.1))},a=t=>{const e=t.target;e&&(e.closest("button")||e.closest(".stream-geo-zoom-controls"))||(t.preventDefault(),r(1.5*o))};t.addEventListener("wheel",s,{passive:!1}),t.addEventListener("dblclick",a);const c=.4,l=e=>{if(0!==e.button)return;const n=e.target;if(n.closest("button")||n.closest(".stream-geo-zoom-controls"))return;const i=Ln.current;if(!i)return;const o=i.getRotation();In.current={x:e.clientX,y:e.clientY,rotation:[...o]},t.setPointerCapture(e.pointerId),e.preventDefault()},u=t=>{const e=In.current;e&&(Nn.current=[e.rotation[0]+(t.clientX-e.x)*c,Math.max(-90,Math.min(90,e.rotation[1]-(t.clientY-e.y)*c)),e.rotation[2]],mn())},h=e=>{if(!In.current)return;In.current=null,t.releasePointerCapture(e.pointerId);const n=Nn.current;if(n){Nn.current=null;const t=Ln.current;t&&(t.applyRotation(n,i),mn())}const o=Ln.current;o?.scales?.projection&&K?.({projection:o.scales.projection,zoom:o.currentZoom})};return t.addEventListener("pointerdown",l),t.addEventListener("pointermove",u),t.addEventListener("pointerup",h),t.addEventListener("pointercancel",h),()=>{t.removeEventListener("wheel",s),t.removeEventListener("dblclick",a),t.removeEventListener("pointerdown",l),t.removeEventListener("pointermove",u),t.removeEventListener("pointerup",h),t.removeEventListener("pointercancel",h),jn.current=null}}const o=Ae().scaleExtent([e,n]).extent([[0,0],[nn[0],nn[1]]]).translateExtent([[-1/0,-1/0],[1/0,1/0]]).on("zoom",t=>{const e=t.transform;Mn.current=e,Tn.current=!0;const n=Ln.current;n&&(n.applyZoomTransform(e,i),Ke.current=!1,mn())}).on("end",t=>{Mn.current=t.transform,Tn.current=!1;const e=Ln.current;e?.scales?.projection&&K?.({projection:e.scales.projection,zoom:e.currentZoom})});return jn.current=o,Ce(t).call(o),()=>{Ce(t).on(".zoom",null)}},[$,V,xn,nn,rn,sn,on,K,mn]);const fi=Ht&&!1!==Gt,mi=fi&&Zn?qt?qt(Zn):Ye(Fe,{data:Zn}):null,gi=mi?Ye(q,{x:Zn.x,y:Zn.y,containerWidth:rn,containerHeight:sn,margin:on,className:"stream-frame-tooltip",zIndex:10,children:mi}):null;if(ut||!yn&&vn){const t=Ln.current;t&&(bn||h||b)&&(bn&&t.setAreas(bn),h&&t.setPoints(wn),b&&t.setLines(Pn),t.computeScene({width:rn,height:sn}));const e=t?.scene??[];return Xe("div",{ref:_n,className:"stream-geo-frame"+(At?" "+At:""),role:"img","aria-label":Ee||("string"==typeof fe?fe:"Geographic chart"),style:{position:"relative",width:bt?"100%":nn[0],height:wt?"100%":nn[1]},children:[Ye(U,{summary:We}),Xe("svg",{xmlns:"http://www.w3.org/2000/svg",width:nn[0],height:nn[1],style:{position:"absolute",left:0,top:0},children:[Ye("g",{transform:`translate(${on.left},${on.top})`,children:cn}),Xe("g",{transform:`translate(${on.left},${on.top})`,children:[kt&&Ye("rect",{x:0,y:0,width:rn,height:sn,fill:kt}),e.map((t,e)=>M({node:t,index:e,renderMode:Et,fallback:()=>st(t,e)}))]})]}),Ye(Le,{width:rn,height:sn,totalWidth:nn[0],totalHeight:nn[1],margin:on,showAxes:!1,title:fe,legend:me,legendPosition:ge,legendLayout:ye,legendHoverBehavior:we,legendClickBehavior:Pe,legendHighlightedCategory:xe,legendIsolatedCategories:Re,foregroundGraphics:x(an,E(Ln.current?.customLayoutOverlays,R??null)),annotations:Vt,onAnnotationActivate:Kt,onObservation:Qt??Ut,chartId:$t,chartType:"StreamGeoFrame",autoPlaceAnnotations:Jt,svgAnnotationRules:te,pointNodes:Ie(e),geoProjection:Ln.current?.scales?.projectedPoint})]})}return Xe("div",{ref:_n,className:"stream-geo-frame"+(At?" "+At:""),role:"group","aria-label":Ee||("string"==typeof fe?fe:"Geographic chart"),tabIndex:0,style:{position:"relative",width:bt?"100%":nn[0],height:wt?"100%":nn[1],overflow:Zt?"visible":"hidden",...$?{touchAction:"none"}:{}},onKeyDown:hi,children:["production"!==process.env.NODE_ENV&&Ln.current&&Ye(X,{store:Ln.current,diagnostics:Gn.current}),Ne&&Ye(Q,{tableId:hn}),Ne&&Ye(z,{scene:Ln.current?.scene??[],chartType:"Geographic chart",tableId:hn,chartTitle:"string"==typeof fe?fe:void 0}),Ye(U,{summary:We}),Ye(H,{hoverPoint:Zn}),Xe("div",{role:"img","aria-label":Ee||("string"==typeof fe?fe:"Geographic chart"),style:{position:"relative",width:"100%",height:"100%"},onPointerMove:fi?di:void 0,onPointerLeave:fi?ri:void 0,onPointerDown:fi||$e?pi:void 0,onClick:$e?ci:void 0,children:[Ye(G,{size:nn,margin:on,children:cn}),ot&&Ye("canvas",{ref:An,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),Ye("canvas",{ref:si,"aria-label":tt(Ln.current?.scene??[],"Geographic chart"),style:{position:"absolute",left:0,top:0}}),Ye("canvas",{ref:ai,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),Ye(Le,{width:rn,height:sn,totalWidth:nn[0],totalHeight:nn[1],margin:on,showAxes:_e,title:fe,legend:me,legendPosition:ge,legendLayout:ye,legendHoverBehavior:we,legendClickBehavior:Pe,legendHighlightedCategory:xe,legendIsolatedCategories:Re,foregroundGraphics:x(an,E(Ln.current?.customLayoutOverlays,R??null)),annotations:Vt,onAnnotationActivate:Kt,onObservation:Qt??Ut,chartId:$t,chartType:"StreamGeoFrame",autoPlaceAnnotations:Jt,svgAnnotationRules:te,pointNodes:Ie(Ln.current?.scene),geoProjection:Ln.current?.scales?.projectedPoint}),re?.showBadge&&Ye(v,{isStale:Qn,position:re.badgePosition}),$&&Xe("div",{className:"stream-geo-zoom-controls",style:{position:"absolute",bottom:on.bottom+8,left:on.left+8,display:"flex",flexDirection:"column",gap:2,zIndex:2},children:[Ye("button",{type:"button","aria-label":"Zoom in",onClick:t=>{t.stopPropagation();const e=Bn.current,n=jn.current;e&&n?.scaleBy&&n.scaleBy(Ce(e),1.5)},style:Ge,children:"+"}),Ye("button",{type:"button","aria-label":"Zoom out",onClick:t=>{t.stopPropagation();const e=Bn.current,n=jn.current;e&&n?.scaleBy&&n.scaleBy(Ce(e),1/1.5)},style:Ge,children:"−"})]}),ht&&Ye("div",{className:"stream-geo-tile-attribution",style:{position:"absolute",bottom:on.bottom+2,right:on.right+4,fontSize:10,color:"rgba(0,0,0,0.6)",background:"rgba(255,255,255,0.7)",padding:"1px 4px",borderRadius:2,pointerEvents:"none",zIndex:2},children:ht}),Ye(Z,{active:li.current>=0,hoverPoint:Zn,margin:on,size:nn,shape:ui.current?.shape,width:ui.current?.w,height:ui.current?.h,pathData:ui.current?.pathData}),gi]})]})}));Ue.displayName="StreamGeoFrame";var Qe=Ue;import{forwardRef as $e,useMemo as Ve}from"react";import{jsx as Ke}from"react/jsx-runtime";var Je=$e(function(n,i){const{points:o,areas:r,lines:s,layout:a,layoutConfig:c,onLayoutError:l,projection:u="equirectangular",xAccessor:h="lon",yAccessor:d="lat",lineDataAccessor:p,colorBy:f,colorScheme:m,tooltip:g,annotations:y,margin:v,selection:b,linkedHover:x,onObservation:R,onClick:S,chartId:L,loading:A,loadingContent:k,emptyContent:C,className:D,frameProps:j={}}=n,{frameRef:M,resolved:T,normalizedMargin:B}=e({imperativeRef:i,imperativeVariant:"geo-points",margin:v,width:n.width,height:n.height,enableHover:n.enableHover,title:n.title,description:n.description,summary:n.summary,accessibleTable:n.accessibleTable,mode:n.mode,mobileInteraction:n.mobileInteraction,mobileSemantics:n.mobileSemantics,responsiveRules:n.responsiveRules}),_=Ve(()=>rt(o),[o]),I=Ve(()=>rt(r),[r]),N=Ve(()=>rt(s),[s]),E=Ve(()=>[..._,...N,...I],[_,N,I]),F=t({data:E,rawData:void 0!==o||void 0!==s||void 0!==r?E:void 0,colorBy:f,colorScheme:m,legendInteraction:void 0,selection:b,linkedHover:x,fallbackFields:"string"==typeof f?[f]:[],unwrapData:!1,onObservation:R,onClick:S,mobileInteraction:n.mobileInteraction,mobileSemantics:n.mobileSemantics,chartType:"GeoCustomChart",chartId:L,showLegend:!1,userMargin:B,marginDefaults:T.marginDefaults,loading:A,loadingContent:k,emptyContent:C,width:T.width,height:T.height,hasTitle:!!T.title}),O=F.effectiveSelectionHook,W=Ve(()=>O?.isActive?{isActive:!0,predicate:O.predicate}:null,[O?.isActive,O?.predicate]);if(F.earlyReturn)return F.earlyReturn;const{width:z,height:H,enableHover:G,title:q,description:Z,summary:Y,accessibleTable:X}=T,U=dt(g),Q={projection:u,...null!=o&&{points:_},...null!=r&&{areas:I},...null!=s&&{lines:N},xAccessor:h,yAccessor:d,...null!=p&&{lineDataAccessor:p},customLayout:a,layoutConfig:c,onLayoutError:l,layoutSelection:W,colorBy:f,colorScheme:m,size:[z,H],responsiveWidth:n.responsiveWidth,responsiveHeight:n.responsiveHeight,margin:F.margin,enableHover:G,...w({title:q,description:Z,summary:Y,accessibleTable:X,className:D,animate:n.animate,autoPlaceAnnotations:n.autoPlaceAnnotations}),...!1===g?{tooltipContent:()=>null}:U?{tooltipContent:U}:{},...P({linkedHover:x,selection:b,onObservation:R,onClick:S,hoverHighlight:!1,mobileInteraction:F.mobileInteraction,customHoverBehavior:F.customHoverBehavior,customClickBehavior:F.customClickBehavior,linkedHoverInClickPredicate:!1}),...y&&y.length>0&&{annotations:y},...j};return Ke(kt,{componentName:"GeoCustomChart",width:z,height:H,children:Ke(Qe,{ref:M,...Q})})});Je.displayName="GeoCustomChart";export{Qe as StreamGeoFrame_default,Je as GeoCustomChart};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{StreamPhysicsFrame_default as e}from"./chunk-chunk-NW25WGLS.module.min.js";import{resolveMotionAccessor as t}from"./chunk-chunk-5SD6BHVW.module.min.js";function n(e,t,n={}){const s=new Set,o=[...e.get(t)??[]];let i=0;for(;o.length>i;){const t=o[i];if(i+=1,!s.has(t)){s.add(t);for(const n of e.get(t)??[])o.push(n)}}return n.includeStart&&s.add(t),s}function s(e,n,s){return t(s,e,n)}function o(e,t){return t>e?-1:e>t?1:0}function i(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function r(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function a(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function c(e){const t=[],n=new Map,c=[],d=new Set;e.data.forEach((i,r)=>{const l=(s(i,r,e.taskIDAccessor)??"")+"";if(!l)return void t.push({code:"duplicate-task-id",message:`Task row ${r} has an empty id.`,taskIDs:[]});if(n.has(l))return void t.push({code:"duplicate-task-id",message:`Task id "${l}" occurs more than once.`,taskIDs:[l]});const h=(s(i,r,e.laneAccessor)??"Unassigned")+"";d.has(h)||(d.add(h),c.push(h));const m=s(i,r,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(m,e=>e+""))).sort(o),p=s(i,r,e.blockerAccessor),g=s(i,r,e.statusAccessor)??(p?"blocked":"waiting");n.set(l,{id:l,label:(s(i,r,e.labelAccessor)??l)+"",lane:h,laneIndex:0,level:0,index:r,datum:i,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:s(i,r,e.startAccessor),end:s(i,r,e.endAccessor),progress:a(s(i,r,e.progressAccessor)),status:g,completionTime:s(i,r,e.completionTimeAccessor),blockerReason:p||void 0,milestone:!!s(i,r,e.milestoneAccessor)})});const l=e.laneOrder?[...e.laneOrder,...c.filter(t=>!e.laneOrder?.includes(t))]:c,h=new Map(l.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=h.get(e.lane)??0;const m=new Map,u=new Map;for(const e of n.keys())m.set(e,[]),u.set(e,[]);const p=[],g=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of g)e.dependencyIDs.forEach((s,o)=>{const a=n.get(s);if(!a)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${s}".`,taskIDs:[e.id,s]});const c={id:i(s,e.id),sourceID:s,targetID:e.id,sourceIndex:a.index,targetIndex:e.index,socketID:r(e.id,o),socketIndex:o};p.push(c),m.get(e.id)?.push(c),u.get(s)?.push(c),e.incomingEdgeIDs.push(c.id),e.socketIDs.push(c.socketID),a.outgoingEdgeIDs.push(c.id)});for(const e of m.values())e.sort((e,t)=>o(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=r(e.targetID,t)});for(const e of u.values())e.sort((e,t)=>o(e.targetID,t.targetID));for(const e of n.values()){const t=m.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(u.get(e.id)??[]).map(e=>e.id)}const f=new Map,y=new Map;for(const e of n.keys())f.set(e,m.get(e)?.length??0),y.set(e,0);const k=[...n.keys()].filter(e=>0===f.get(e)).sort(o);let I=0;for(;k.length;){const e=k.shift();I+=1;for(const t of u.get(e)??[]){const n=Math.max(y.get(t.targetID)??0,(y.get(e)??0)+1);y.set(t.targetID,n);const s=(f.get(t.targetID)??0)-1;if(f.set(t.targetID,s),0===s){const e=k.findIndex(e=>e>t.targetID);0>e?k.push(t.targetID):k.splice(e,0,t.targetID)}}}if(I!==n.size){const e=[...n.keys()].filter(e=>(f.get(e)??0)>0).sort(o);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let x=0;const D=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of D)e.level=y.get(e.id)??0,x=Math.max(x,e.level);return{nodes:D,edges:p,byID:n,incoming:m,outgoing:u,lanes:l,maxLevel:x,diagnostics:t,valid:0===t.length}}function d(e,t,n={}){const s=Math.max(240,t.width),i=Math.max(220,t.height),r=t.paddingX??48,a=t.paddingTop??48,c=t.paddingBottom??44,d=Math.max(70,(s-2*r)/Math.max(1,e.lanes.length)),l=Math.max(76,(i-a-c)/Math.max(1,e.maxLevel+1)),h=Math.min(n.taskWidth??112,Math.max(58,.78*d)),m=Math.min(n.taskHeight??58,.64*l),u=n.socketRadius??5,p=Math.max(1,Math.round(n.gutterCount??3)),g=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=g.get(e)??[];n.push(t),g.set(e,n)}for(const e of g.values())e.sort((e,t)=>o(e.id,t.id));const f=.86*l,y=e.nodes.map(e=>{const t=g.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,s=(o=t.length)>1?Math.max(22,Math.min(m,(f-4*(o-1))/o)):m;var o;return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:r+d*(e.laneIndex+.5),y:a+l*(e.level+.5)+n*(s+4),width:h,height:s}}),k=new Map(y.map(e=>[e.taskID,e])),I=[],x=[];e.edges.forEach((t,n)=>{const s=k.get(t.sourceID),o=k.get(t.targetID);if(!s||!o)return;const i=e.incoming.get(t.targetID)??[],r=Math.min(.72*o.width,14*Math.max(1,i.length-1)),a=i.length>1?o.x-r/2+r*t.socketIndex/(i.length-1):o.x,c=o.y-o.height/2-u-2;I.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:a,y:c,radius:u});const d={x:s.x,y:s.y+s.height/2+3},l=Math.min(c-10,d.y+.48*Math.max(18,c-d.y)+7*(n%p-(p-1)/2));var h;x.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(h=[d,{x:d.x,y:l},{x:a,y:l},{x:a,y:c}],h.filter((e,t)=>{const n=h[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const D=new Map(I.map(e=>[e.id,e])),v=new Map(x.map(e=>[e.edgeID,e]));return{tasks:y,sockets:I,routes:x,taskByID:k,socketByID:D,routeByEdgeID:v}}function l(e,t,n="all"){const s=Array.from(new Set(t)).sort(o),i=new Set,r=()=>s.every(e=>i.has(e));return{taskID:e,mode:n,incomingEdgeIDs:s,deliver:e=>s.includes(e)?(i.add(e),r()):r(),reset:(e=[])=>{i.clear();for(const t of e)s.includes(t)&&i.add(t)},isSatisfied:r,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...s],deliveredEdgeIDs:[...i].sort(o),satisfied:r()})}}function h(e){return e instanceof Date?e.getTime():Number(e)}function m(e,t){const n=h("object"!=typeof t||t instanceof Date?t:t.currentTime),s=e.map((e,t)=>({event:e,index:t,time:h(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),o=new Set,i=new Map,r=new Set,a=new Set;for(const{event:e}of s)"task-completed"===e.type?(o.add(e.taskID),i.delete(e.taskID)):"task-blocked"===e.type?i.set(e.taskID,e.reason):"task-unblocked"===e.type?i.delete(e.taskID):"dependency-delivered"===e.type?r.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:s.map(e=>e.event),completedTaskIDs:o,blockedByTaskID:i,deliveredEdgeIDs:r,armedTaskIDs:a}}function u(e,t,s={}){const o=new Set(s.completedTaskIDs??[]),i=[...n(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(s.isComplete?s.isComplete(e):o.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),r=Array.from(new Set(i.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:i.length,affectedLaneCount:r.length,downstreamTaskIDs:i.map(e=>e.id),affectedLanes:r}}import{forwardRef as p,useCallback as g,useEffect as f,useImperativeHandle as y,useMemo as k,useRef as I,useState as x}from"react";var D=[];function v(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function b(e){if(null==e.completionTime)return null;const t=v(e.completionTime,NaN);return Number.isFinite(t)?t:null}function w(e,t,n,s){const o=new Set;for(const i of e.nodes){const r=e.incoming.get(i.id)??[];(s.has(i.id)||!n.has(i.id)&&r.every(e=>t.has(e.id)))&&o.add(i.id)}return o}function T(e,t,n,s){const o=e.nodes.map(b).filter(e=>null!=e),i=o.length?Math.min(...o)-1:0,r="replay"!==t||s?n:i,a=new Set,c=new Map;for(const n of e.nodes){const e=b(n);(null!=e&&r>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const d=new Set;if("replay"!==t||s)for(const t of e.edges)a.has(t.sourceID)&&d.add(t.id);return{currentTime:r,playing:!1,completed:a,delivered:d,inFlight:new Set,armed:w(e,d,c,a),blockers:c,previewTaskID:null}}function M(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function S(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function A(e){const t=S(e.body);if(!t||2>t.route.length)return null;const n=function(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}(t.route),s=function(e,t){let n=1/0,s=0,o=0;for(let i=1;t.length>i;i+=1){const r=t[i-1],a=t[i],c=a.x-r.x,d=a.y-r.y,l=c*c+d*d,h=Math.sqrt(l);if(0>=h)continue;const m=Math.max(0,Math.min(1,((e.x-r.x)*c+(e.y-r.y)*d)/l)),u=Math.hypot(e.x-(r.x+c*m),e.y-(r.y+d*m));n>u&&(n=u,s=o+m*h),o+=h}return s}(e.body,t.route),o=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let s=1;e.length>s;s+=1){const o=e[s-1],i=e[s],r=i.x-o.x,a=i.y-o.y,c=Math.hypot(r,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:o.x+r*e,y:o.y+a*e},tangent:{x:r/c,y:a/c}}}n+=c}}const s=e[e.length-2],o=e[e.length-1],i=o.x-s.x,r=o.y-s.y,a=Math.hypot(i,r)||1;return{point:o,tangent:{x:i/a,y:r/a}}}(t.route,Math.min(n,s+22));return{x:2.5*(78*o.tangent.x-e.body.vx)+8*(o.point.x-e.body.x),y:2.5*(78*o.tangent.y-e.body.vy)+8*(o.point.y-e.body.y)}}function C(e,t){const n=t.points[0]??{x:0,y:0},s=t.points[1]??n,o=s.x-n.x,i=s.y-n.y,r=Math.hypot(o,i)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:o/r*42,vy:i/r*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as $,jsxs as L}from"react/jsx-runtime";function E({machine:e,layout:t,runtime:n,downstreamSet:s,selectedSet:o,width:i,height:r,seed:a,reduced:c,onSelectTask:d}){const l=t.tasks.length?Math.min(...t.tasks.map(e=>e.y-e.height/2)):60,h=Math.max(20,l-12),m=Math.max(26,l-6);return L("svg",{"aria-hidden":"true",width:i,height:r,viewBox:`0 0 ${i} ${r}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[$("defs",{children:$("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:$("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const s=t.tasks.filter(e=>e.laneIndex===n),o=s[0]?.x??0;return L("g",{children:[$("line",{x1:o,x2:o,y1:m,y2:r-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),$("text",{x:o,y:h,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),o=n.inFlight.has(e.edgeID),i=s.has(e.targetID)||s.has(e.sourceID),r=e.points.map(e=>`${e.x},${e.y}`).join(" ");return $("polyline",{points:r,fill:"none",stroke:i?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:i?4:o?3:2,strokeOpacity:t||o||i?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return L("g",{children:[$("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&$("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const i=t.taskByID.get(e.id);if(!i)return null;const r=n.completed.has(e.id),l=n.blockers.has(e.id),h=n.previewTaskID===e.id,m=o.has(e.id)||h,u=s.has(e.id),p=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,n),g=i.x-i.width/2,f=i.y-i.height/2,y=Math.max(2,i.height*e.progress);return L("g",{children:[L("g",{style:{transform:`rotate(${r?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[$("rect",{x:g,y:f,width:i.width,height:i.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:m||u?"var(--semiotic-selection-color, #e08a1e)":p,strokeWidth:m?4:u?3:2}),$("rect",{x:g+3,y:f+i.height-y+1,width:i.width-6,height:Math.max(0,y-4),rx:2,fill:p,opacity:r?.86:.46})]}),l&&L("g",{opacity:h?.28:1,children:[$("line",{x1:g-8,x2:g+14,y1:i.y+9,y2:i.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),$("circle",{cx:g-8,cy:i.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),L("g",{onPointerDown:()=>d(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[$("rect",{x:g,y:f,width:i.width,height:i.height,fill:"transparent"}),$("text",{x:i.x,y:i.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),L("text",{x:i.x,y:i.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% · ",r?"done":l?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as W,jsxs as N}from"react/jsx-runtime";var B={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},F=p(function(t,n){const{data:s,taskIDAccessor:o,labelAccessor:i,laneAccessor:r,dependencyAccessor:a,startAccessor:l,endAccessor:h,progressAccessor:m,statusAccessor:p,completionTimeAccessor:$,blockerAccessor:L,milestoneAccessor:F,mode:j="snapshot",insight:R="blocker-amplification",currentTime:z,controls:O=!1,selectedTaskIDs:H,onSelectionChange:P,onObservation:U,reducedMotion:q,seed:G=31,width:V=920,height:X=620,responsiveWidth:J,responsiveHeight:K,title:Q="Dependency chain reaction",description:Y,className:Z,accessibleTable:_=!0,enableHover:ee=!0}=t,te=I(null),[ne,se]=x([]),oe=H?Array.from(H):ne,ie=k(()=>new Set(oe),[oe]),re=v(z,1/0),ae="settle"===q,ce=k(()=>c({data:s,taskIDAccessor:o,labelAccessor:i,laneAccessor:r,dependencyAccessor:a,startAccessor:l,endAccessor:h,progressAccessor:m,statusAccessor:p,completionTimeAccessor:$,blockerAccessor:L,milestoneAccessor:F}),[s,o,i,r,a,l,h,m,p,$,L,F]),de=k(()=>d(ce,{width:V,height:X}),[ce,V,X]),[le,he]=x(()=>T(ce,j,re,ae)),me=I(le),ue=g(e=>{me.current=e,he(e)},[]),pe=g(e=>U?.(e),[U]);f(()=>{const e=T(ce,j,re,ae);te.current?.clear(),me.current=e,he(e)},[ce,j,re,ae]);const ge=g(e=>{const t=ie.has(e)?oe.filter(t=>t!==e):[e];H||se(t),P?.(t)},[H,P,ie,oe]),fe=g(e=>{if(ae)return;const t=M(me.current),n=[];for(const s of ce.outgoing.get(e)??[]){if(t.delivered.has(s.id)||t.inFlight.has(s.id))continue;const e=de.routeByEdgeID.get(s.id);e&&(t.inFlight.add(s.id),n.push(C(s,e)))}n.length&&(ue(t),te.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[ue,de,ce,ae]),ye=g((e,t)=>{const n=ce.byID.get(e),s=me.current;if(!n||s.completed.has(e))return;const o=M(s);o.completed.add(e),o.blockers.delete(e),o.armed.add(e),null!=t&&(o.currentTime=t),ue(o),pe({type:"task-completed",taskID:e,datum:n.datum}),fe(e)},[ue,pe,ce,fe]),ke=g(e=>{const t=M(me.current),n=[],s=[];for(const s of e){if(t.delivered.has(s))continue;const e=ce.edges.find(e=>e.id===s);e&&(t.delivered.add(s),t.inFlight.delete(s),n.push(e))}for(const e of n){const n=ce.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(ce.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),s.push(n.id))}if(n.length){ue(t);for(const e of n)pe({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of s)pe({type:"task-armed",taskID:e})}},[ue,pe,ce]),Ie=g((e,t)=>{const n=[],s=[];for(const e of t.readBodies()){const t=S(e);if(!t||me.current.delivered.has(t.edgeID))continue;const o=t.route[t.route.length-1];o&&9>=Math.hypot(e.x-o.x,e.y-o.y)&&(n.push(t.edgeID),s.push(e.id))}s.length&&t.remove(s),n.length&&ke(n)},[ke]),xe=g(()=>{const e=M(me.current);for(const t of ce.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=w(ce,e.delivered,e.blockers,e.completed),e.playing=!1,te.current?.settle(),ue(e),pe({type:"machine-settled"})},[ue,pe,ce]),De=g(()=>{const e=M(me.current);e.playing=!1,ue(e)},[ue]),ve=g(()=>{const e=me.current,t=ce.nodes.map(e=>({node:e,time:b(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void ye(t.node.id,t.time);De();const n=[...e.blockers.keys()].map(t=>u(ce,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&pe({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[pe,ce,De,ye]),be=g(()=>{if(ae)return void xe();const e=M(me.current);e.playing=!0,ue(e)},[ue,ae,xe]);f(()=>{if(!le.playing||"replay"!==j||ae)return;const e=window.setInterval(ve,760);return()=>window.clearInterval(e)},[j,ae,le.playing,ve]);const we=g(()=>{te.current?.clear(),ue(T(ce,j,re,ae))},[ue,ce,j,re,ae]),Te=g(e=>{if(!ce.byID.has(e))return;const t=M(me.current);t.previewTaskID=e,ue(t);const n=u(ce,e,{completedTaskIDs:t.completed});pe({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[ue,pe,ce]),Me=g(()=>{const e=M(me.current);e.previewTaskID=null,ue(e)},[ue]),Se=g((e,t)=>{if(!ce.byID.has(e))return;const n=M(me.current);n.blockers.set(e,t),n.armed.delete(e),ue(n)},[ue,ce]),Ae=g(e=>{if(!ce.byID.has(e))return;const t=M(me.current);t.blockers.delete(e),(ce.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),ue(t)},[ue,ce]),Ce=g(e=>u(ce,e,{completedTaskIDs:me.current.completed}),[ce]),$e=g(()=>{const e=me.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...oe],tasks:ce.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:ce.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[ce,oe]);y(n,()=>({play:be,pause:De,step:ve,reset:we,settle:xe,previewResolve:Te,clearPreview:Me,completeTask:ye,blockTask:Se,unblockTask:Ae,getAmplification:Ce,getMachineState:$e}),[Se,Me,Ce,$e,De,ye,be,Te,we,xe,ve,Ae]);const Le=le.previewTaskID??oe[0]??null,Ee=Le?u(ce,Le,{completedTaskIDs:le.completed}):null,We=k(()=>new Set(Ee?.downstreamTaskIDs??[]),[Ee?.downstreamTaskIDs]),Ne=k(()=>function(e,t,n){return e.nodes.flatMap(s=>{const o=t.taskByID.get(s.id);if(!o)return[];const i=e.incoming.get(s.id)??[],r=i.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(s.id),c=n.completed.has(s.id)?"completed":a?"blocked: "+a:n.armed.has(s.id)?"armed":"waiting";return[{id:s.id,label:`${s.label}, ${s.lane}, ${Math.round(100*s.progress)}%, ${c}`,description:`${r} of ${i.length} prerequisites delivered.`,datum:s.datum,x:o.x,y:o.y,width:o.width,height:o.height,shape:"rect",group:s.lane}]})}(ce,de,le),[de,ce,le]),Be=k(()=>W(E,{machine:ce,layout:de,runtime:le,downstreamSet:We,selectedSet:ie,width:V,height:X,seed:G,reduced:ae,onSelectTask:ge}),[We,X,de,ce,ae,le,G,ge,ie,V]),Fe=k(()=>{const e=[...le.blockers.keys()].map(e=>u(ce,e,{completedTaskIDs:le.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${ce.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[ce,le.blockers,le.completed]),je=k(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:X,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:V-2,y1:0,x2:V-2,y2:X,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:V,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:X-2,x2:V,y2:X-2,thickness:4}}],[X,V]),Re=!0===O?["play","pause","step","reset","settle"]:O||[];return N("div",ce.valid?{className:Z,style:{width:V,maxWidth:"100%",position:"relative"},children:[Re.length>0&&W("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:Re.map(e=>W("button",{type:"button",onClick:"play"===e?be:"pause"===e?De:"step"===e?ve:"reset"===e?we:xe,"aria-pressed":"play"===e?le.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),W(e,{ref:te,size:[V,X],responsiveWidth:J,responsiveHeight:K,title:Q,description:Y??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${Fe}${Ee&&"blocker-amplification"===R?` Selected task reaches ${Ee.downstreamTaskCount} unfinished tasks across ${Ee.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:ee,initialSpawns:D,bodyForces:A,bodyStyle:{fill:"var(--semiotic-primary, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:Ne,onSemanticItemActivate:e=>e.id&&ge(e.id),foregroundGraphics:()=>Be,paused:ae,continuous:le.inFlight.size>0,onTick:Ie,config:{bodyLimit:Math.max(16,ce.edges.length+4),colliders:je,settleStepLimit:2200,kernel:{seed:G,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),_&&N("table",{style:B,children:[W("caption",{children:Fe}),W("thead",{children:N("tr",{children:[W("th",{children:"Task"}),W("th",{children:"Lane"}),W("th",{children:"Progress"}),W("th",{children:"State"}),W("th",{children:"Waiting on"}),W("th",{children:"Downstream reach"})]})}),W("tbody",{children:ce.nodes.map(e=>{const t=u(ce,e.id,{completedTaskIDs:le.completed});return N("tr",{children:[W("th",{scope:"row",children:e.label}),W("td",{children:e.lane}),N("td",{children:[Math.round(100*e.progress),"%"]}),W("td",{children:le.completed.has(e.id)?"Completed":le.blockers.has(e.id)?"Blocked":le.armed.has(e.id)?"Armed":"Waiting"}),W("td",{children:le.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!le.completed.has(e)).join(", ")||"None")}),N("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:Z,role:"alert",style:{width:V,maxWidth:"100%"},children:[W("strong",{children:"ChainReactionChart could not compile this dependency graph."}),W("ul",{children:ce.diagnostics.map((e,t)=>W("li",{children:e.message},`${e.code}-${t}`))})]})});F.displayName="ChainReactionChart";export{c as compileDependencyMachine,d as routeDependencyTracks,l as createLogicalJoin,m as replayStateTransitions,u as calculateBlockerAmplification,F as ChainReactionChart};
2
+ import{StreamPhysicsFrame_default as e}from"./chunk-chunk-JJ4BSUYL.module.min.js";import{resolveMotionAccessor as t}from"./chunk-chunk-4MLLQUGW.module.min.js";function n(e,t,n={}){const s=new Set,o=[...e.get(t)??[]];let i=0;for(;o.length>i;){const t=o[i];if(i+=1,!s.has(t)){s.add(t);for(const n of e.get(t)??[])o.push(n)}}return n.includeStart&&s.add(t),s}function s(e,n,s){return t(s,e,n)}function o(e,t){return t>e?-1:e>t?1:0}function i(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function r(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function a(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function c(e){const t=[],n=new Map,c=[],d=new Set;e.data.forEach((i,r)=>{const l=(s(i,r,e.taskIDAccessor)??"")+"";if(!l)return void t.push({code:"duplicate-task-id",message:`Task row ${r} has an empty id.`,taskIDs:[]});if(n.has(l))return void t.push({code:"duplicate-task-id",message:`Task id "${l}" occurs more than once.`,taskIDs:[l]});const h=(s(i,r,e.laneAccessor)??"Unassigned")+"";d.has(h)||(d.add(h),c.push(h));const m=s(i,r,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(m,e=>e+""))).sort(o),p=s(i,r,e.blockerAccessor),g=s(i,r,e.statusAccessor)??(p?"blocked":"waiting");n.set(l,{id:l,label:(s(i,r,e.labelAccessor)??l)+"",lane:h,laneIndex:0,level:0,index:r,datum:i,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:s(i,r,e.startAccessor),end:s(i,r,e.endAccessor),progress:a(s(i,r,e.progressAccessor)),status:g,completionTime:s(i,r,e.completionTimeAccessor),blockerReason:p||void 0,milestone:!!s(i,r,e.milestoneAccessor)})});const l=e.laneOrder?[...e.laneOrder,...c.filter(t=>!e.laneOrder?.includes(t))]:c,h=new Map(l.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=h.get(e.lane)??0;const m=new Map,u=new Map;for(const e of n.keys())m.set(e,[]),u.set(e,[]);const p=[],g=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of g)e.dependencyIDs.forEach((s,o)=>{const a=n.get(s);if(!a)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${s}".`,taskIDs:[e.id,s]});const c={id:i(s,e.id),sourceID:s,targetID:e.id,sourceIndex:a.index,targetIndex:e.index,socketID:r(e.id,o),socketIndex:o};p.push(c),m.get(e.id)?.push(c),u.get(s)?.push(c),e.incomingEdgeIDs.push(c.id),e.socketIDs.push(c.socketID),a.outgoingEdgeIDs.push(c.id)});for(const e of m.values())e.sort((e,t)=>o(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=r(e.targetID,t)});for(const e of u.values())e.sort((e,t)=>o(e.targetID,t.targetID));for(const e of n.values()){const t=m.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(u.get(e.id)??[]).map(e=>e.id)}const f=new Map,y=new Map;for(const e of n.keys())f.set(e,m.get(e)?.length??0),y.set(e,0);const k=[...n.keys()].filter(e=>0===f.get(e)).sort(o);let I=0;for(;k.length;){const e=k.shift();I+=1;for(const t of u.get(e)??[]){const n=Math.max(y.get(t.targetID)??0,(y.get(e)??0)+1);y.set(t.targetID,n);const s=(f.get(t.targetID)??0)-1;if(f.set(t.targetID,s),0===s){const e=k.findIndex(e=>e>t.targetID);0>e?k.push(t.targetID):k.splice(e,0,t.targetID)}}}if(I!==n.size){const e=[...n.keys()].filter(e=>(f.get(e)??0)>0).sort(o);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let x=0;const D=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of D)e.level=y.get(e.id)??0,x=Math.max(x,e.level);return{nodes:D,edges:p,byID:n,incoming:m,outgoing:u,lanes:l,maxLevel:x,diagnostics:t,valid:0===t.length}}function d(e,t,n={}){const s=Math.max(240,t.width),i=Math.max(220,t.height),r=t.paddingX??48,a=t.paddingTop??48,c=t.paddingBottom??44,d=Math.max(70,(s-2*r)/Math.max(1,e.lanes.length)),l=Math.max(76,(i-a-c)/Math.max(1,e.maxLevel+1)),h=Math.min(n.taskWidth??112,Math.max(58,.78*d)),m=Math.min(n.taskHeight??58,.64*l),u=n.socketRadius??5,p=Math.max(1,Math.round(n.gutterCount??3)),g=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=g.get(e)??[];n.push(t),g.set(e,n)}for(const e of g.values())e.sort((e,t)=>o(e.id,t.id));const f=.86*l,y=e.nodes.map(e=>{const t=g.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,s=(o=t.length)>1?Math.max(22,Math.min(m,(f-4*(o-1))/o)):m;var o;return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:r+d*(e.laneIndex+.5),y:a+l*(e.level+.5)+n*(s+4),width:h,height:s}}),k=new Map(y.map(e=>[e.taskID,e])),I=[],x=[];e.edges.forEach((t,n)=>{const s=k.get(t.sourceID),o=k.get(t.targetID);if(!s||!o)return;const i=e.incoming.get(t.targetID)??[],r=Math.min(.72*o.width,14*Math.max(1,i.length-1)),a=i.length>1?o.x-r/2+r*t.socketIndex/(i.length-1):o.x,c=o.y-o.height/2-u-2;I.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:a,y:c,radius:u});const d={x:s.x,y:s.y+s.height/2+3},l=Math.min(c-10,d.y+.48*Math.max(18,c-d.y)+7*(n%p-(p-1)/2));var h;x.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(h=[d,{x:d.x,y:l},{x:a,y:l},{x:a,y:c}],h.filter((e,t)=>{const n=h[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const D=new Map(I.map(e=>[e.id,e])),v=new Map(x.map(e=>[e.edgeID,e]));return{tasks:y,sockets:I,routes:x,taskByID:k,socketByID:D,routeByEdgeID:v}}function l(e,t,n="all"){const s=Array.from(new Set(t)).sort(o),i=new Set,r=()=>s.every(e=>i.has(e));return{taskID:e,mode:n,incomingEdgeIDs:s,deliver:e=>s.includes(e)?(i.add(e),r()):r(),reset:(e=[])=>{i.clear();for(const t of e)s.includes(t)&&i.add(t)},isSatisfied:r,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...s],deliveredEdgeIDs:[...i].sort(o),satisfied:r()})}}function h(e){return e instanceof Date?e.getTime():Number(e)}function m(e,t){const n=h("object"!=typeof t||t instanceof Date?t:t.currentTime),s=e.map((e,t)=>({event:e,index:t,time:h(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),o=new Set,i=new Map,r=new Set,a=new Set;for(const{event:e}of s)"task-completed"===e.type?(o.add(e.taskID),i.delete(e.taskID)):"task-blocked"===e.type?i.set(e.taskID,e.reason):"task-unblocked"===e.type?i.delete(e.taskID):"dependency-delivered"===e.type?r.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:s.map(e=>e.event),completedTaskIDs:o,blockedByTaskID:i,deliveredEdgeIDs:r,armedTaskIDs:a}}function u(e,t,s={}){const o=new Set(s.completedTaskIDs??[]),i=[...n(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(s.isComplete?s.isComplete(e):o.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),r=Array.from(new Set(i.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:i.length,affectedLaneCount:r.length,downstreamTaskIDs:i.map(e=>e.id),affectedLanes:r}}import{forwardRef as p,useCallback as g,useEffect as f,useImperativeHandle as y,useMemo as k,useRef as I,useState as x}from"react";var D=[];function v(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function b(e){if(null==e.completionTime)return null;const t=v(e.completionTime,NaN);return Number.isFinite(t)?t:null}function w(e,t,n,s){const o=new Set;for(const i of e.nodes){const r=e.incoming.get(i.id)??[];(s.has(i.id)||!n.has(i.id)&&r.every(e=>t.has(e.id)))&&o.add(i.id)}return o}function T(e,t,n,s){const o=e.nodes.map(b).filter(e=>null!=e),i=o.length?Math.min(...o)-1:0,r="replay"!==t||s?n:i,a=new Set,c=new Map;for(const n of e.nodes){const e=b(n);(null!=e&&r>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const d=new Set;if("replay"!==t||s)for(const t of e.edges)a.has(t.sourceID)&&d.add(t.id);return{currentTime:r,playing:!1,completed:a,delivered:d,inFlight:new Set,armed:w(e,d,c,a),blockers:c,previewTaskID:null}}function M(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function S(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function A(e){const t=S(e.body);if(!t||2>t.route.length)return null;const n=function(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}(t.route),s=function(e,t){let n=1/0,s=0,o=0;for(let i=1;t.length>i;i+=1){const r=t[i-1],a=t[i],c=a.x-r.x,d=a.y-r.y,l=c*c+d*d,h=Math.sqrt(l);if(0>=h)continue;const m=Math.max(0,Math.min(1,((e.x-r.x)*c+(e.y-r.y)*d)/l)),u=Math.hypot(e.x-(r.x+c*m),e.y-(r.y+d*m));n>u&&(n=u,s=o+m*h),o+=h}return s}(e.body,t.route),o=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let s=1;e.length>s;s+=1){const o=e[s-1],i=e[s],r=i.x-o.x,a=i.y-o.y,c=Math.hypot(r,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:o.x+r*e,y:o.y+a*e},tangent:{x:r/c,y:a/c}}}n+=c}}const s=e[e.length-2],o=e[e.length-1],i=o.x-s.x,r=o.y-s.y,a=Math.hypot(i,r)||1;return{point:o,tangent:{x:i/a,y:r/a}}}(t.route,Math.min(n,s+22));return{x:2.5*(78*o.tangent.x-e.body.vx)+8*(o.point.x-e.body.x),y:2.5*(78*o.tangent.y-e.body.vy)+8*(o.point.y-e.body.y)}}function C(e,t){const n=t.points[0]??{x:0,y:0},s=t.points[1]??n,o=s.x-n.x,i=s.y-n.y,r=Math.hypot(o,i)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:o/r*42,vy:i/r*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}import{jsx as $,jsxs as L}from"react/jsx-runtime";function E({machine:e,layout:t,runtime:n,downstreamSet:s,selectedSet:o,width:i,height:r,seed:a,reduced:c,onSelectTask:d}){const l=t.tasks.length?Math.min(...t.tasks.map(e=>e.y-e.height/2)):60,h=Math.max(20,l-12),m=Math.max(26,l-6);return L("svg",{"aria-hidden":"true",width:i,height:r,viewBox:`0 0 ${i} ${r}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[$("defs",{children:$("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:$("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const s=t.tasks.filter(e=>e.laneIndex===n),o=s[0]?.x??0;return L("g",{children:[$("line",{x1:o,x2:o,y1:m,y2:r-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),$("text",{x:o,y:h,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),o=n.inFlight.has(e.edgeID),i=s.has(e.targetID)||s.has(e.sourceID),r=e.points.map(e=>`${e.x},${e.y}`).join(" ");return $("polyline",{points:r,fill:"none",stroke:i?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:i?4:o?3:2,strokeOpacity:t||o||i?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return L("g",{children:[$("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&$("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const i=t.taskByID.get(e.id);if(!i)return null;const r=n.completed.has(e.id),l=n.blockers.has(e.id),h=n.previewTaskID===e.id,m=o.has(e.id)||h,u=s.has(e.id),p=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,n),g=i.x-i.width/2,f=i.y-i.height/2,y=Math.max(2,i.height*e.progress);return L("g",{children:[L("g",{style:{transform:`rotate(${r?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[$("rect",{x:g,y:f,width:i.width,height:i.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:m||u?"var(--semiotic-selection-color, #e08a1e)":p,strokeWidth:m?4:u?3:2}),$("rect",{x:g+3,y:f+i.height-y+1,width:i.width-6,height:Math.max(0,y-4),rx:2,fill:p,opacity:r?.86:.46})]}),l&&L("g",{opacity:h?.28:1,children:[$("line",{x1:g-8,x2:g+14,y1:i.y+9,y2:i.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),$("circle",{cx:g-8,cy:i.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),L("g",{onPointerDown:()=>d(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[$("rect",{x:g,y:f,width:i.width,height:i.height,fill:"transparent"}),$("text",{x:i.x,y:i.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),L("text",{x:i.x,y:i.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% · ",r?"done":l?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}import{jsx as W,jsxs as B}from"react/jsx-runtime";var F={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},N=p(function(t,n){const{data:s,taskIDAccessor:o,labelAccessor:i,laneAccessor:r,dependencyAccessor:a,startAccessor:l,endAccessor:h,progressAccessor:m,statusAccessor:p,completionTimeAccessor:$,blockerAccessor:L,milestoneAccessor:N,mode:j="snapshot",insight:R="blocker-amplification",currentTime:z,controls:O=!1,selectedTaskIDs:U,onSelectionChange:H,onObservation:P,reducedMotion:q,seed:G=31,width:J=920,height:Q=620,responsiveWidth:V,responsiveHeight:X,title:Y="Dependency chain reaction",description:K,className:Z,accessibleTable:_=!0,enableHover:ee=!0}=t,te=I(null),[ne,se]=x([]),oe=U?Array.from(U):ne,ie=k(()=>new Set(oe),[oe]),re=v(z,1/0),ae="settle"===q,ce=k(()=>c({data:s,taskIDAccessor:o,labelAccessor:i,laneAccessor:r,dependencyAccessor:a,startAccessor:l,endAccessor:h,progressAccessor:m,statusAccessor:p,completionTimeAccessor:$,blockerAccessor:L,milestoneAccessor:N}),[s,o,i,r,a,l,h,m,p,$,L,N]),de=k(()=>d(ce,{width:J,height:Q}),[ce,J,Q]),[le,he]=x(()=>T(ce,j,re,ae)),me=I(le),ue=g(e=>{me.current=e,he(e)},[]),pe=g(e=>P?.(e),[P]);f(()=>{const e=T(ce,j,re,ae);te.current?.clear(),me.current=e,he(e)},[ce,j,re,ae]);const ge=g(e=>{const t=ie.has(e)?oe.filter(t=>t!==e):[e];U||se(t),H?.(t)},[U,H,ie,oe]),fe=g(e=>{if(ae)return;const t=M(me.current),n=[];for(const s of ce.outgoing.get(e)??[]){if(t.delivered.has(s.id)||t.inFlight.has(s.id))continue;const e=de.routeByEdgeID.get(s.id);e&&(t.inFlight.add(s.id),n.push(C(s,e)))}n.length&&(ue(t),te.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[ue,de,ce,ae]),ye=g((e,t)=>{const n=ce.byID.get(e),s=me.current;if(!n||s.completed.has(e))return;const o=M(s);o.completed.add(e),o.blockers.delete(e),o.armed.add(e),null!=t&&(o.currentTime=t),ue(o),pe({type:"task-completed",taskID:e,datum:n.datum}),fe(e)},[ue,pe,ce,fe]),ke=g(e=>{const t=M(me.current),n=[],s=[];for(const s of e){if(t.delivered.has(s))continue;const e=ce.edges.find(e=>e.id===s);e&&(t.delivered.add(s),t.inFlight.delete(s),n.push(e))}for(const e of n){const n=ce.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(ce.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),s.push(n.id))}if(n.length){ue(t);for(const e of n)pe({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of s)pe({type:"task-armed",taskID:e})}},[ue,pe,ce]),Ie=g((e,t)=>{const n=[],s=[];for(const e of t.readBodies()){const t=S(e);if(!t||me.current.delivered.has(t.edgeID))continue;const o=t.route[t.route.length-1];o&&9>=Math.hypot(e.x-o.x,e.y-o.y)&&(n.push(t.edgeID),s.push(e.id))}s.length&&t.remove(s),n.length&&ke(n)},[ke]),xe=g(()=>{const e=M(me.current);for(const t of ce.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=w(ce,e.delivered,e.blockers,e.completed),e.playing=!1,te.current?.settle(),ue(e),pe({type:"machine-settled"})},[ue,pe,ce]),De=g(()=>{const e=M(me.current);e.playing=!1,ue(e)},[ue]),ve=g(()=>{const e=me.current,t=ce.nodes.map(e=>({node:e,time:b(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void ye(t.node.id,t.time);De();const n=[...e.blockers.keys()].map(t=>u(ce,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&pe({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[pe,ce,De,ye]),be=g(()=>{if(ae)return void xe();const e=M(me.current);e.playing=!0,ue(e)},[ue,ae,xe]);f(()=>{if(!le.playing||"replay"!==j||ae)return;const e=window.setInterval(ve,760);return()=>window.clearInterval(e)},[j,ae,le.playing,ve]);const we=g(()=>{te.current?.clear(),ue(T(ce,j,re,ae))},[ue,ce,j,re,ae]),Te=g(e=>{if(!ce.byID.has(e))return;const t=M(me.current);t.previewTaskID=e,ue(t);const n=u(ce,e,{completedTaskIDs:t.completed});pe({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[ue,pe,ce]),Me=g(()=>{const e=M(me.current);e.previewTaskID=null,ue(e)},[ue]),Se=g((e,t)=>{if(!ce.byID.has(e))return;const n=M(me.current);n.blockers.set(e,t),n.armed.delete(e),ue(n)},[ue,ce]),Ae=g(e=>{if(!ce.byID.has(e))return;const t=M(me.current);t.blockers.delete(e),(ce.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),ue(t)},[ue,ce]),Ce=g(e=>u(ce,e,{completedTaskIDs:me.current.completed}),[ce]),$e=g(()=>{const e=me.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...oe],tasks:ce.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:ce.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[ce,oe]);y(n,()=>({play:be,pause:De,step:ve,reset:we,settle:xe,previewResolve:Te,clearPreview:Me,completeTask:ye,blockTask:Se,unblockTask:Ae,getAmplification:Ce,getMachineState:$e}),[Se,Me,Ce,$e,De,ye,be,Te,we,xe,ve,Ae]);const Le=le.previewTaskID??oe[0]??null,Ee=Le?u(ce,Le,{completedTaskIDs:le.completed}):null,We=k(()=>new Set(Ee?.downstreamTaskIDs??[]),[Ee?.downstreamTaskIDs]),Be=k(()=>function(e,t,n){return e.nodes.flatMap(s=>{const o=t.taskByID.get(s.id);if(!o)return[];const i=e.incoming.get(s.id)??[],r=i.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(s.id),c=n.completed.has(s.id)?"completed":a?"blocked: "+a:n.armed.has(s.id)?"armed":"waiting";return[{id:s.id,label:`${s.label}, ${s.lane}, ${Math.round(100*s.progress)}%, ${c}`,description:`${r} of ${i.length} prerequisites delivered.`,datum:s.datum,x:o.x,y:o.y,width:o.width,height:o.height,shape:"rect",group:s.lane}]})}(ce,de,le),[de,ce,le]),Fe=k(()=>W(E,{machine:ce,layout:de,runtime:le,downstreamSet:We,selectedSet:ie,width:J,height:Q,seed:G,reduced:ae,onSelectTask:ge}),[We,Q,de,ce,ae,le,G,ge,ie,J]),Ne=k(()=>{const e=[...le.blockers.keys()].map(e=>u(ce,e,{completedTaskIDs:le.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${ce.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[ce,le.blockers,le.completed]),je=k(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:Q,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:J-2,y1:0,x2:J-2,y2:Q,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:J,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:Q-2,x2:J,y2:Q-2,thickness:4}}],[Q,J]),Re=!0===O?["play","pause","step","reset","settle"]:O||[];return B("div",ce.valid?{className:Z,style:{width:J,maxWidth:"100%",position:"relative"},children:[Re.length>0&&W("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:Re.map(e=>W("button",{type:"button",onClick:"play"===e?be:"pause"===e?De:"step"===e?ve:"reset"===e?we:xe,"aria-pressed":"play"===e?le.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),W(e,{ref:te,size:[J,Q],responsiveWidth:V,responsiveHeight:X,title:Y,description:K??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${Ne}${Ee&&"blocker-amplification"===R?` Selected task reaches ${Ee.downstreamTaskCount} unfinished tasks across ${Ee.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:ee,initialSpawns:D,bodyForces:A,bodyStyle:{fill:"var(--semiotic-primary, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:Be,onSemanticItemActivate:e=>e.id&&ge(e.id),foregroundGraphics:()=>Fe,paused:ae,continuous:le.inFlight.size>0,onTick:Ie,config:{bodyLimit:Math.max(16,ce.edges.length+4),colliders:je,settleStepLimit:2200,kernel:{seed:G,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),_&&B("table",{style:F,children:[W("caption",{children:Ne}),W("thead",{children:B("tr",{children:[W("th",{children:"Task"}),W("th",{children:"Lane"}),W("th",{children:"Progress"}),W("th",{children:"State"}),W("th",{children:"Waiting on"}),W("th",{children:"Downstream reach"})]})}),W("tbody",{children:ce.nodes.map(e=>{const t=u(ce,e.id,{completedTaskIDs:le.completed});return B("tr",{children:[W("th",{scope:"row",children:e.label}),W("td",{children:e.lane}),B("td",{children:[Math.round(100*e.progress),"%"]}),W("td",{children:le.completed.has(e.id)?"Completed":le.blockers.has(e.id)?"Blocked":le.armed.has(e.id)?"Armed":"Waiting"}),W("td",{children:le.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!le.completed.has(e)).join(", ")||"None")}),B("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:Z,role:"alert",style:{width:J,maxWidth:"100%"},children:[W("strong",{children:"ChainReactionChart could not compile this dependency graph."}),W("ul",{children:ce.diagnostics.map((e,t)=>W("li",{children:e.message},`${e.code}-${t}`))})]})});N.displayName="ChainReactionChart";export{c as compileDependencyMachine,d as routeDependencyTracks,l as createLogicalJoin,m as replayStateTransitions,u as calculateBlockerAmplification,N as ChainReactionChart};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{resolveCSSColor as t,resolveCanvasFill as l,symbolPathString as e}from"./chunk-chunk-HCNDE26Q.module.min.js";var o=new Map;function r(r,s,a,n,i,y){if(0>=s.size)return;const c=function(t,l,r){try{if(r)return new Path2D(r);const s=`${t??"circle"}:${Math.round(l)}`;let a=o.get(s);return a||(a=new Path2D(e(t,l)),o.size>256&&o.clear(),o.set(s,a)),a}catch{return null}}(s.symbolType,s.size,s.path);if(!c)return;r.save(),r.translate(a,n),s.rotation&&r.rotate(s.rotation);const f=(s.style.opacity??1)*(s._decayOpacity??1);s.style.fill&&(r.globalAlpha=i*f*(s.style.fillOpacity??1),r.fillStyle=l(r,s.style.fill,y),r.fill(c)),s.style.stroke&&"none"!==s.style.stroke&&(r.globalAlpha=i*f,r.strokeStyle=t(r,s.style.stroke)||s.style.stroke,r.lineWidth=s.style.strokeWidth??1,r.stroke(c)),r.restore()}var s=(t,l)=>{const e=t.globalAlpha;for(const o of l)"symbol"===o.type&&r(t,o,o.x,o.y,e,"#4e79a7");t.globalAlpha=e};function a(t,l){const e=t.globalAlpha;for(const o of l)"symbol"===o.type&&r(t,o,o.cx,o.cy,e,"#007bff");t.globalAlpha=e}export{s as symbolCanvasRenderer,a as networkSymbolRenderer};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{SafeRender as e,useWasHydratingFromSSR as t}from"./chunk-chunk-ACLDBMRH.module.min.js";import{useReducedMotion as i}from"./chunk-chunk-YHNZCPOZ.module.min.js";function n(e,t={}){if("function"==typeof e)return e;const i=t.locale??"en-US";if("currency"===e){const e=t.precision??2,n=new Intl.NumberFormat(i,{style:"currency",currency:t.currency??"USD",maximumFractionDigits:e,minimumFractionDigits:e});return e=>n.format(e)}if("percent"===e){const e=new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("compact"===e){const e=new Intl.NumberFormat(i,{notation:"compact",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("duration"===e)return e=>r(e);const n=new Intl.NumberFormat(i,{notation:t.notation??"standard",maximumFractionDigits:t.precision??0,minimumFractionDigits:0});return e=>n.format(e)}function r(e){if(!Number.isFinite(e))return e+"";const t=0>e?"-":"",i=Math.abs(e);if(1e3>i)return`${t}${Math.round(i)}ms`;const n=i/1e3;if(60>n)return`${t}${r=n,Math.round(100*r)/100+""}s`;var r;const a=n/60;if(60>a){const e=Math.floor(a),i=Math.round(n-60*e);return 0===i?`${t}${e}m`:`${t}${e}m ${i}s`}const l=a/60;if(24>l){const e=Math.floor(l),i=Math.round(a-60*e);return 0===i?`${t}${e}h`:`${t}${e}h ${i}m`}const o=Math.floor(l/24),s=Math.round(l-24*o);return 0===s?`${t}${o}d`:`${t}${o}d ${s}h`}function a(e,t,i){return`${t??""}${e}${i??""}`}function l(e,t){return Number.isFinite(e)?0===e?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}function o(e,t,i="en-US",n=1){if(!Number.isFinite(e)||!Number.isFinite(t))return null;if(0===e)return null;const r=(t-e)/Math.abs(e);return new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:n,minimumFractionDigits:0,signDisplay:"exceptZero"}).format(r)}function s(e,t){if(!t||0===t.length)return null;if(!Number.isFinite(e))return null;const i=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at);let n=null;for(const t of i){if(t.at>e)break;n=t}return n}function u(e,t){return t||("neutral"===e?"var(--semiotic-text, currentColor)":`var(--semiotic-${e}, currentColor)`)}function c(e,t){const i=t.padding??1;if(0===e.length)return{line:"",area:"",points:[]};if(1===e.length){const e=t.width/2,i=t.height/2;return{line:`M${e},${i}`,area:"",points:[{x:e,y:i}]}}const n=t.yMin??e.reduce((e,t)=>Number.isFinite(t)&&e>t?t:e,1/0),r=(t.yMax??e.reduce((e,t)=>Number.isFinite(t)&&t>e?t:e,-1/0))-n||1,a=Math.max(0,t.width-2*i),l=Math.max(0,t.height-2*i),o=a/(e.length-1),s=[];let u="";for(let t=0;e.length>t;t++){const a=e[t];if(!Number.isFinite(a))continue;const c=i+t*o,m=i+l-(a-n)/r*l;u+=`${0===s.length?"M":"L"}${c.toFixed(2)},${m.toFixed(2)}`,s.push({x:c,y:m})}if(0===s.length)return{line:"",area:"",points:[]};const c=s[0],m=i+l;return{line:u,area:`${u} L${s[s.length-1].x.toFixed(2)},${m.toFixed(2)} L${c.x.toFixed(2)},${m.toFixed(2)} Z`,points:s}}import{forwardRef as m,useCallback as d,useEffect as h,useImperativeHandle as b,useMemo as p,useRef as f,useState as g}from"react";import{useMemo as v}from"react";import{Fragment as y,jsx as x,jsxs as w}from"react/jsx-runtime";var N={tile:{width:280,height:184,align:"start",labelSize:13,captionSize:11,valueSize:40,deltaSize:13,padding:{top:14,right:16,bottom:14,left:16},background:"var(--semiotic-surface, transparent)",border:!0,showHeader:!0,showDelta:!0,showTrend:!0,showChart:!0,chartSize:44},presentation:{width:540,height:320,align:"center",labelSize:18,captionSize:14,valueSize:96,deltaSize:18,padding:{top:32,right:32,bottom:32,left:32},background:"var(--semiotic-surface, transparent)",border:!0,showHeader:!0,showDelta:!0,showTrend:!0,showChart:!0,chartSize:80},inline:{width:void 0,height:void 0,align:"inherit",labelSize:0,captionSize:0,valueSize:0,deltaSize:0,padding:{top:0,right:0,bottom:0,left:0},background:"transparent",border:!1,showHeader:!1,showDelta:!0,showTrend:!1,showChart:!1,chartSize:0},thumbnail:{width:96,height:56,align:"center",labelSize:0,captionSize:0,valueSize:22,deltaSize:0,padding:{top:4,right:6,bottom:4,left:6},background:"transparent",border:!1,showHeader:!1,showDelta:!1,showTrend:!1,showChart:!1,chartSize:0}};function F(e,t,i){return void 0===e?i:"function"==typeof e?e(t):e}function S(e){return"positive"===e?"var(--semiotic-success, currentColor)":"negative"===e?"var(--semiotic-danger, currentColor)":"var(--semiotic-text-secondary, currentColor)"}function $(e){return"positive"===e?"▲":"negative"===e?"▼":"■"}var _=m((r,o)=>{const{value:c,label:m,caption:_,format:z,locale:D,currency:C,precision:I,prefix:k,suffix:L,unit:T,comparison:j,target:B,delta:H,deltaFormat:V,showDeltaPercent:W,direction:P,sentiment:R,thresholds:A,windowSize:U=60,mode:Z="tile",align:q,width:E,height:O,padding:Y,emphasis:X,color:G,background:J,borderColor:K,borderRadius:Q,className:ee,style:te,animate:ie,stalenessThreshold:ne,staleLabel:re,headerSlot:ae,valueSlot:le,deltaSlot:oe,trendSlot:se,chartSlot:ue,chartSize:ce,footerSlot:me,onClick:de,onObservation:he,chartId:be,description:pe,summary:fe,loading:ge,loadingContent:ve,emptyContent:ye}=r,xe=N[Z]??N.tile,we=q??xe.align,Ne=E??xe.width,Fe=O??xe.height,Se=i(),$e=t(),[_e,ze]=g([]),[De,Me]=g(null),[Ce,Ie]=g(null),[ke,Le]=g(null),Te=f([]),je=f(null),Be=f(c);h(()=>{Be.current=c},[c]);const He=f(U);h(()=>{He.current=U},[U]);const Ve=d(e=>{const t="number"==typeof e?{value:e,time:Date.now()}:{time:Date.now(),...e},i="number"==typeof t.time?t.time:t.time instanceof Date?t.time.getTime():Date.now();return{...t,time:i}},[]),We=d(e=>{if(0===e.length)return;const t=He.current,i=e.map(Ve);let n=Te.current.concat(i);n.length>t&&(n=n.slice(n.length-t)),Te.current=n;const r=i[i.length-1];je.current=r.value,ze(n),Me(r.value);for(let e=i.length-1;e>=0;e--){const t=i[e].comparison;if(null!=t){Ie(t);break}}Le(r.time)},[Ve]),Pe=d(e=>We([e]),[We]);b(o,()=>({push:e=>Pe(e),pushMany:e=>We(e),clear:()=>{Te.current=[],je.current=null,ze([]),Me(null),Ie(null),Le(null)},getValue:()=>je.current??(Number.isFinite(Be.current)?Be.current:null),getData:()=>Te.current.slice()}),[Pe,We]);const Re=De??c,Ae=null==Re||"number"!=typeof Re||!Number.isFinite(Re),Ue=p(()=>n(z??"number",{locale:D,currency:C,precision:I}),[z,D,C,I]),Ze=p(()=>n(V??z??"number",{locale:D,currency:C,precision:null==V&&null==z?0:I}),[V,z,D,C,I]),qe=ie??!1,Ee=("object"!=typeof qe||!1!==qe.intro)&&!!qe,Oe=Number.isFinite(Re)?Re:0,Ye=function(e,t,i,n=e){const[r,a]=g(()=>n),l=f(n),o=f(null),s=f(e),u=f(0),c=!!t,m="object"==typeof t?t.duration:void 0,d="number"==typeof m&&Number.isFinite(m)?Math.max(0,m):300,b="object"==typeof t&&"linear"===t.easing?"linear":"ease-out",p=f(e);return h(()=>{const t=e=>{l.current=e,a(e)};if(!Number.isFinite(e))return void t(e);if(!c||i)return void t(e);if(0===d)return void t(e);s.current=l.current,p.current=e,u.current="undefined"!=typeof performance?performance.now():Date.now();const n="linear"===b?e=>e:e=>1-Math.pow(1-e,3),r=e=>{const i=Math.min(1,(e-u.current)/d),a=n(i);t(s.current+(p.current-s.current)*a),1>i?o.current=requestAnimationFrame(r):(o.current=null,t(p.current))};return o.current=requestAnimationFrame(r),()=>{null!=o.current&&cancelAnimationFrame(o.current),o.current=null}},[c,d,b,i,e]),r}(Oe,qe,Se,f(!Ee||Se||$e?Oe:0).current),Xe=qe?Ye:Number.isFinite(Re)?Re:0,Ge=p(()=>s(Number.isFinite(Re)?Re:NaN,A),[Re,A]),Je=Ge?Ge.level:"neutral",Ke=G??u(Je,Ge?.color),Qe=Ce??j?.value??null,et=null!=H?H:null!=Qe&&Number.isFinite(Re)?Re-Qe:null,tt=function(e,t,i){if(i&&"auto"!==i)return i;if(null==e||0===e||!Number.isFinite(e))return"neutral";const n=t??"higher-is-better";return"neutral"===n?"neutral":("higher-is-better"===n?e>0:0>e)?"positive":"negative"}(et,j?.direction??B?.direction??P,R),it=null!=et&&Number.isFinite(et)?l(et,Ze):null,nt=p(()=>new Intl.NumberFormat(D??"en-US",{style:"percent",maximumFractionDigits:1,minimumFractionDigits:0,signDisplay:"exceptZero"}),[D]),rt=null!=Qe&&Number.isFinite(Re)&&(W??1)&&0!==Qe?nt.format((Re-Qe)/Math.abs(Qe)):null,at=function({target:e,value:t,format:i,locale:r,currency:a,precision:l}){const o=v(()=>new Intl.NumberFormat(r??"en-US",{style:"percent",maximumFractionDigits:0}),[r]),s=v(()=>n(e?.format??i??"number",{locale:r,currency:a,precision:l}),[e?.format,i,r,a,l]);return v(()=>{if(!e||!Number.isFinite(e.value))return null;const i="number"==typeof t&&Number.isFinite(t)&&0!==e.value?o.format(t/e.value):null,n=s(e.value);return{label:e.label,percent:i,formattedValue:n,text:i?e.label?`${i} of ${e.label} (${n})`:`${i} of ${n}`:e.label?`target ${e.label} (${n})`:"target "+n}},[e,t,s,o])}({target:B,value:Re,format:z,locale:D,currency:C,precision:I}),lt=at?.percent??null,ot=at?.text??null,st=function(e,t){const[i,n]=g(!1);return h(()=>{if(!t||null==e)return void n(!1);const i=()=>{n(Date.now()-e>=t)};i();const r=setInterval(i,Math.max(250,Math.floor(t/4)));return()=>clearInterval(r)},[e,t]),i}(ke,ne),ut=Number.isFinite(Xe)?a(Ue(Xe),k,L):"",ct={value:Ae?null:Re,formattedValue:ut,level:Je,color:Ke,delta:et,deltaFormatted:it,deltaPercent:rt,sentiment:tt,isStale:st,pushBuffer:_e},mt=pe??function(e){const t=[];if(e.label&&t.push(e.label+":"),t.push(e.unit?`${e.formattedValue} ${e.unit}`:e.formattedValue),e.deltaFormatted){const i=e.delta,n=null!=i&&Number.isFinite(i)&&0!==i?i>0?"up":"down":"change";t.push(`${n} ${e.deltaFormatted}${e.deltaPercent?` (${e.deltaPercent})`:""}${e.comparisonLabel?" from "+e.comparisonLabel:""}`)}return e.targetText&&t.push(e.targetText),e.thresholdLabel&&t.push(e.thresholdLabel),e.stale&&t.push(e.staleLabel??"stale"),t.join(", ")}({label:m,formattedValue:Number.isFinite(Re)?a(Ue(Re),k,L):"",unit:T,comparisonLabel:j?.label,delta:et,deltaFormatted:it,deltaPercent:rt,targetText:ot,thresholdLabel:Ge?.label,stale:st,staleLabel:re}),dt="number"==typeof Y?{top:Y,right:Y,bottom:Y,left:Y}:{...xe.padding,...Y??{}},ht="end"===we?"flex-end":"center"===we?"center":"start"===we?"flex-start":"inherit",bt={position:"relative",boxSizing:"border-box",width:Ne,height:Fe,padding:`${dt.top}px ${dt.right}px ${dt.bottom}px ${dt.left}px`,background:J??xe.background,border:xe.border?"1px solid "+(K??"var(--semiotic-border, #e2e2e2)"):void 0,borderRadius:"number"==typeof Q?Q+"px":Q??"var(--semiotic-border-radius, 8px)",display:"inline"===Z?"inline-flex":"flex",flexDirection:"column",alignItems:"inherit"===ht?void 0:ht,textAlign:we,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",color:"var(--semiotic-text, #111)",opacity:st?.55:1,transition:"opacity 240ms ease-out",gridColumn:"primary"===X?"span 2":void 0,cursor:de?"pointer":void 0,...te},pt=d(e=>{const t=e.currentTarget.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top,r={value:Ae?NaN:Re,level:Je,delta:et};de&&de(r,{x:i,y:n}),he&&he({type:"click",datum:r,x:i,y:n,chartType:"BigNumber",chartId:be,timestamp:Date.now()})},[de,he,be,Ae,Re,Je,et]),ft="inline"===Z?"span":"div",gt=["semiotic-bignumber","semiotic-bignumber--mode-"+Z,"semiotic-bignumber--level-"+Je,"semiotic-bignumber--sentiment-"+tt,st?"semiotic-bignumber--stale":null,ee].filter(Boolean).join(" "),vt="positive"===tt?"up":"negative"===tt?"down":"flat";if(ge){const e="number"==typeof Ne?Ne:280,t="number"==typeof Fe?Fe:160;return x(ft,{role:"status","aria-live":"polite","aria-busy":"true",className:gt+" semiotic-bignumber--loading",style:{...bt,opacity:1},children:ve??x(M,{width:e,height:t,mode:Z})})}return Ae?!1===ye?null:x(ft,{role:"status","aria-label":m?m+": no value":"no value",className:gt+" semiotic-bignumber--empty",style:{...bt,color:"var(--semiotic-text-secondary, #666)",fontSize:13,alignItems:"center",justifyContent:"center"},children:ye??"—"}):x(e,{componentName:"BigNumber",width:"number"==typeof Ne?Ne:280,height:"number"==typeof Fe?Fe:160,children:w(ft,{role:"group","aria-label":mt,"data-chart":"BigNumber","data-mode":Z,"data-level":Je,"data-stale":st?"true":void 0,"data-sentiment":tt,className:gt,style:bt,onClick:de||he?pt:void 0,children:[xe.showHeader&&(m||_||ae)?x("div",{className:"semiotic-bignumber__header",style:{display:"flex",flexDirection:"column",gap:2,marginBottom:6,paddingRight:xe.showChart&&null!=ue?(ce??xe.chartSize)+8:0},children:F(ae,ct,w(y,{children:[m?x("span",{className:"semiotic-bignumber__label",style:{fontSize:xe.labelSize,color:"var(--semiotic-text-secondary, #6b7280)",fontWeight:500,letterSpacing:.2},children:m}):null,_?x("span",{className:"semiotic-bignumber__caption",style:{fontSize:xe.captionSize,color:"var(--semiotic-text-secondary, #9ca3af)"},children:_}):null]}))}):null,F(le,ct,w(ft,{className:"semiotic-bignumber__value semiotic-bignumber__value--"+Je,style:{display:"inline"===Z?"inline-flex":"flex",alignItems:"baseline",gap:6,fontVariantNumeric:"tabular-nums",fontWeight:600,color:Ke,fontSize:xe.valueSize||void 0,lineHeight:1.05},children:[x("span",{className:"semiotic-bignumber__value-text",children:ut}),T?x("span",{className:"semiotic-bignumber__unit",style:{fontSize:xe.valueSize?Math.max(11,Math.round(.32*xe.valueSize)):"0.75em",color:"var(--semiotic-text-secondary, #9ca3af)",fontWeight:500},children:T}):null]})),xe.showDelta&&(it||at||j)?x(ft,{className:"semiotic-bignumber__delta semiotic-bignumber__delta--"+vt,style:{display:"inline"===Z?"inline-flex":"flex",flexWrap:"wrap",gap:8,alignItems:"baseline",marginTop:"inline"===Z?0:6,fontSize:xe.deltaSize||void 0,color:"var(--semiotic-text-secondary, #6b7280)"},children:F(oe,ct,w(y,{children:[it?w("span",{className:"semiotic-bignumber__delta-row semiotic-bignumber__delta-row--"+vt,style:{display:"inline-flex",alignItems:"center",gap:4,color:S(tt),fontWeight:600},children:[x("span",{"aria-hidden":"true",className:"semiotic-bignumber__arrow semiotic-bignumber__arrow--"+vt,children:$(tt)}),x("span",{className:"semiotic-bignumber__delta-amount",children:it}),rt?w("span",{className:"semiotic-bignumber__delta-percent",style:{fontWeight:500},children:["(",rt,")"]}):null]}):null,j?.label?x("span",{className:"semiotic-bignumber__comparison-label",children:j.label}):null,at?w("span",{className:"semiotic-bignumber__target",style:{display:"inline-flex",alignItems:"baseline",gap:4},children:[it||j?.label?x("span",{"aria-hidden":"true",className:"semiotic-bignumber__separator",children:"·"}):null,x("span",{className:"semiotic-bignumber__target-percent",style:{fontWeight:500,color:"var(--semiotic-text, #111)"},children:lt}),w("span",{className:"semiotic-bignumber__target-value",children:["of ",at.formattedValue,at.label?" "+at.label:""]})]}):null]}))}):null,xe.showChart&&null!=ue?x("div",{className:"semiotic-bignumber__chart",style:{position:"absolute",top:dt.top,right:dt.right,width:ce??xe.chartSize,height:ce??xe.chartSize,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:x("div",{style:{pointerEvents:"auto",lineHeight:0},children:F(ue,ct,null)})}):null,xe.showTrend&&null!=se?x("div",{className:"semiotic-bignumber__trend",style:{position:"absolute",left:dt.left,right:dt.right,bottom:dt.bottom+(null!=me?28:0)},children:F(se,ct,null)}):null,null!=me?x(ft,{className:"semiotic-bignumber__footer",style:{position:"absolute",left:dt.left,right:dt.right,bottom:dt.bottom,fontSize:xe.deltaSize||void 0,color:"var(--semiotic-text-secondary, #9ca3af)"},children:F(me,ct,null)}):null,fe?x("span",{style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0},children:fe}):null]})})});_.displayName="BigNumber";var z=_,D=z;function M(e){const t=Math.floor(.45*e.width),i=Math.floor(.6*e.width),n=(e,t)=>x("div",{style:{width:e,height:t,background:"var(--semiotic-border, #e0e0e0)",borderRadius:4,opacity:.55}});return w("div",{style:{display:"flex",flexDirection:"column",gap:10,justifyContent:"center",width:"100%",height:"100%"},children:["thumbnail"!==e.mode&&"inline"!==e.mode?n(t,10):null,n(i,"presentation"===e.mode?48:28),"tile"===e.mode||"presentation"===e.mode?n(Math.floor(.35*e.width),8):null]})}export{n as buildFormatter,r as formatDuration,l as formatSignedDelta,o as formatDeltaPercent,s as resolveThreshold,u as colorForLevel,c as buildSparklinePath,z as BigNumber,D as BigNumber_default};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{bandFromAge as e}from"./chunk-chunk-7ZDJSYKI.module.min.js";function n(e,n){const t={...e};return n.provenance&&(t.provenance=n.provenance),n.lifecycle&&(t.lifecycle=n.lifecycle),t}function t(){return(new Date).toISOString()}function r(e,n={}){const r=e.provenance;return{...e,provenance:{...r,...n,createdAt:n.createdAt??r?.createdAt??t()}}}function c(e){if(null==e)return null;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const n=Date.parse(e);return Number.isFinite(n)?n:null}function l(e){const n=c(e?.now);if(null!=n)return n;const t=e?.dataExtent;if(t)if(Array.isArray(t)){const e=c(t[t.length-1]);if(null!=e)return e}else if("max"in t){const e=c(t.max);if(null!=e)return e}return Date.now()}function o(n,t,r={}){const l=n?.lifecycle?.freshness,o=c(n?.provenance?.createdAt),s=function(e){if(null==e)return null;if("number"==typeof e)return e;const n=function(e){const n=/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/.exec(e);return n?1e3*(3600*(24*parseInt(n[1]||"0",10)+parseInt(n[2]||"0",10))+60*parseInt(n[3]||"0",10)+parseInt(n[4]||"0",10)):0}(e);return n>0?n:null}(n?.lifecycle?.ttlHint);return null==o||null==s?l??"fresh":e(t-o,s,r)}function s(e,n={}){const t=l(n);return e.map(e=>{const r=o(e,t,n.thresholds);return{...e,lifecycle:{...e.lifecycle,freshness:r}}})}var a={fresh:null,aging:.55,stale:.35,expired:.2},u={fresh:null,aging:null,stale:"4 4",expired:"2 4"};function i(e,n,t){return e&&t in e?e[t]:n[t]}function f(e,n={}){const t=l(n),r=!0===n.showExpiredAnnotations,c=[];for(const l of e){const e=o(l,t,n.thresholds);if("expired"===e&&!r)continue;const s=i(n.opacity,a,e),f=i(n.strokeDasharray,u,e),p=n.labelSuffix?.[e],d={...l,lifecycle:{...l.lifecycle,freshness:e}};null!=s&&null==d.opacity&&(d.opacity=s),null!=f&&null==d.strokeDasharray&&(d.strokeDasharray=f),p&&"string"==typeof d.label&&(d.label=d.label+p);const y=l.lifecycle?.anchor;y&&null==d.anchor&&(d.anchor=y),c.push(d)}return c}var p={proposed:.7,accepted:null,disputed:.7,retracted:.25},d={proposed:"3 3",accepted:null,disputed:"2 3",retracted:"2 4"},y={proposed:" (proposed)",accepted:"",disputed:" (?)",retracted:""};function h(e,n,t){return e&&t in e?e[t]:n[t]}function b(e,n={}){const t=!0===n.showRetractedAnnotations,r=!0===n.showSupersededAnnotations,c=new Set;for(const n of e){const e=n?.lifecycle?.supersedes;e&&"retracted"!==n?.lifecycle?.status&&c.add(e)}return e.filter(e=>{if("retracted"===e?.lifecycle?.status&&!t)return!1;const n=e?.provenance?.stableId;return!(n&&c.has(n)&&!r)})}function m(e,n={}){const t=[];for(const r of b(e,n)){const e=r?.lifecycle?.status;if(!e){t.push(r);continue}const c=h(n.opacity,p,e),l=h(n.strokeDasharray,d,e),o=n.labelSuffix?.[e]??y[e],s={...r};null!=c&&(s.opacity=("number"==typeof s.opacity?s.opacity:1)*c),null!=l&&null==s.strokeDasharray&&(s.strokeDasharray=l),o&&"string"==typeof s.label&&(s.label=s.label+o),t.push(s)}return t}export{n as withProvenance,t as currentTimestamp,r as withCurrentProvenance,o as annotationFreshnessFor,s as computeAnnotationFreshness,f as applyAnnotationLifecycle,b as filterAnnotationsByStatus,m as applyAnnotationStatus};
2
+ import{bandFromAge as e}from"./chunk-chunk-HCNDE26Q.module.min.js";function n(e,n){const t={...e};return n.provenance&&(t.provenance=n.provenance),n.lifecycle&&(t.lifecycle=n.lifecycle),t}function t(){return(new Date).toISOString()}function r(e,n={}){const r=e.provenance;return{...e,provenance:{...r,...n,createdAt:n.createdAt??r?.createdAt??t()}}}function c(e){if(null==e)return null;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const n=Date.parse(e);return Number.isFinite(n)?n:null}function l(e){const n=c(e?.now);if(null!=n)return n;const t=e?.dataExtent;if(t)if(Array.isArray(t)){const e=c(t[t.length-1]);if(null!=e)return e}else if("max"in t){const e=c(t.max);if(null!=e)return e}return Date.now()}function o(n,t,r={}){const l=n?.lifecycle?.freshness,o=c(n?.provenance?.createdAt),s=function(e){if(null==e)return null;if("number"==typeof e)return e;const n=function(e){const n=/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/.exec(e);return n?1e3*(3600*(24*parseInt(n[1]||"0",10)+parseInt(n[2]||"0",10))+60*parseInt(n[3]||"0",10)+parseInt(n[4]||"0",10)):0}(e);return n>0?n:null}(n?.lifecycle?.ttlHint);return null==o||null==s?l??"fresh":e(t-o,s,r)}function s(e,n={}){const t=l(n);return e.map(e=>{const r=o(e,t,n.thresholds);return{...e,lifecycle:{...e.lifecycle,freshness:r}}})}var a={fresh:null,aging:.55,stale:.35,expired:.2},u={fresh:null,aging:null,stale:"4 4",expired:"2 4"};function i(e,n,t){return e&&t in e?e[t]:n[t]}function f(e,n={}){const t=l(n),r=!0===n.showExpiredAnnotations,c=[];for(const l of e){const e=o(l,t,n.thresholds);if("expired"===e&&!r)continue;const s=i(n.opacity,a,e),f=i(n.strokeDasharray,u,e),p=n.labelSuffix?.[e],d={...l,lifecycle:{...l.lifecycle,freshness:e}};null!=s&&null==d.opacity&&(d.opacity=s),null!=f&&null==d.strokeDasharray&&(d.strokeDasharray=f),p&&"string"==typeof d.label&&(d.label=d.label+p);const y=l.lifecycle?.anchor;y&&null==d.anchor&&(d.anchor=y),c.push(d)}return c}var p={proposed:.7,accepted:null,disputed:.7,retracted:.25},d={proposed:"3 3",accepted:null,disputed:"2 3",retracted:"2 4"},y={proposed:" (proposed)",accepted:"",disputed:" (?)",retracted:""};function h(e,n,t){return e&&t in e?e[t]:n[t]}function b(e,n={}){const t=!0===n.showRetractedAnnotations,r=!0===n.showSupersededAnnotations,c=new Set;for(const n of e){const e=n?.lifecycle?.supersedes;e&&"retracted"!==n?.lifecycle?.status&&c.add(e)}return e.filter(e=>{if("retracted"===e?.lifecycle?.status&&!t)return!1;const n=e?.provenance?.stableId;return!(n&&c.has(n)&&!r)})}function m(e,n={}){const t=[];for(const r of b(e,n)){const e=r?.lifecycle?.status;if(!e){t.push(r);continue}const c=h(n.opacity,p,e),l=h(n.strokeDasharray,d,e),o=n.labelSuffix?.[e]??y[e],s={...r};null!=c&&(s.opacity=("number"==typeof s.opacity?s.opacity:1)*c),null!=l&&null==s.strokeDasharray&&(s.strokeDasharray=l),o&&"string"==typeof s.label&&(s.label=s.label+o),t.push(s)}return t}export{n as withProvenance,t as currentTimestamp,r as withCurrentProvenance,o as annotationFreshnessFor,s as computeAnnotationFreshness,f as applyAnnotationLifecycle,b as filterAnnotationsByStatus,m as applyAnnotationStatus};
@@ -0,0 +1 @@
1
+ import{mulberry32 as t}from"./chunk-chunk-SIRIJ3DY.module.min.js";import{UpdateResultTracker as e}from"./chunk-chunk-LSJUXBMF.module.min.js";function i(t){const{desired:e,minGaps:i,weights:s}=t,n=e.length;if(0===n)return[];if(i.length!==Math.max(0,n-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const o=Array(n).fill(0);for(let t=1;n>t;t++)o[t]=o[t-1]+Math.max(0,Number.isFinite(i[t-1])?i[t-1]:0);const r=[];for(let t=0;n>t;t++){const i=Math.max(Number.EPSILON,Number.isFinite(s?.[t])?s[t]:1),n=(Number.isFinite(e[t])?e[t]:0)-o[t];for(r.push({start:t,end:t,weight:i,mean:n});r.length>1;){const t=r[r.length-1],e=r[r.length-2];if(t.mean>=e.mean)break;const i=e.weight+t.weight;r.splice(r.length-2,2,{start:e.start,end:t.end,weight:i,mean:(e.mean*e.weight+t.mean*t.weight)/i})}}const a=Number.isFinite(t.min)?t.min:-1/0,d=Number.isFinite(t.max)?t.max-o[n-1]:1/0,h=a>d?a:d,c=Array(n);for(const t of r){const e=Math.max(a,Math.min(h,t.mean));for(let i=t.start;t.end>=i;i++)c[i]=e+o[i]}return c}function s(t,e){let i=0,s=t.length-1,n=-1;for(;s>=i;){const o=i+s>>>1;t[o].at>e?s=o-1:(n=o,i=o+1)}return 0>n?{at:e,before:0,after:0}:t[n]}function n(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const i=[],n=[0];for(let o=0;t.length-1>o;o++){const r=t[o],a=t[o+1],d=[...new Set([...r.map(t=>t.at),...a.map(t=>t.at)])].sort((t,e)=>t-e);let h=0;for(const t of d){const e=s(r,t),i=s(a,t);h=Math.max(h,e.after+i.before)}i.push(h),n.push(n[n.length-1]+h+e)}return{adjacentClearance:i,positions:n}}function o(t,e,i,s={}){let n=[...t];if(1>=n.length)return n;let o=[...n],r=i(n),a=1;const d=Math.max(0,s.passes??6),h=Math.max(1,s.maxEvaluations??1/0);for(let t=0;d>t&&h>a;t++){const t=new Map(n.map((t,e)=>[t,e])),d=new Map,h=new Map;for(const i of e){const e=t.get(i.source),s=t.get(i.target);if(null==e||null==s)continue;const n=Number.isFinite(i.weight)&&i.weight>0?i.weight:1;d.set(i.source,(d.get(i.source)??0)+s*n),h.set(i.source,(h.get(i.source)??0)+n),d.set(i.target,(d.get(i.target)??0)+e*n),h.set(i.target,(h.get(i.target)??0)+n)}n=n.map((t,e)=>({item:t,index:e,barycenter:(d.get(t)??e)/(h.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(s.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const c=i(n);if(a++,r>c)r=c,o=[...n];else if(c===r)break}return o}function r(t,e,i={}){const s=[...t];if(1>=s.length)return s;let n=e(s),o=1;const r=Math.max(0,i.passes??6),a=Math.max(1,i.maxEvaluations??1/0);for(let t=0;r>t&&a>o;t++){let t=!1;for(let i=0;s.length-1>i&&a>o;i++){[s[i],s[i+1]]=[s[i+1],s[i]];const r=e(s);o++,n>r?(n=r,t=!0):[s[i],s[i+1]]=[s[i+1],s[i]]}if(!t)break}return s}function a(t,e,i={}){const s=[...t],n=s.length;if(1>=n||n>(i.maxItems??8))return s;const o=Math.max(1,i.maxEvaluations??1/0);let r=0,a=[...s],d=1/0;const h=()=>{if(r>=o)return;const t=e(s);r++,d>t&&(d=t,a=[...s])};h();const c=Array(n).fill(0);let l=0;for(;n>l&&o>r;)if(l>c[l]){const t=l%2==0?0:c[l];[s[t],s[l]]=[s[l],s[t]],h(),c[l]++,l=0}else c[l]=0,l++;return a}function d(t,e,i=()=>!0){let s=0;for(let n=0;t.length>n;n++){const[o,r]=e(t[n]);for(let a=n+1;t.length>a;a++){if(!i(t[n],t[a]))continue;const[d,h]=e(t[a]);0>(o-d)*(r-h)&&s++}}return s}function h(t,e){if("region-enter"!==e.type)return t;const i=e.region.id,s=t[i]??{id:i,label:e.region.label??i,count:0,bodyIds:[]};if(s.bodyIds.includes(e.bodyId))return t;const n=[...s.bodyIds,e.bodyId];return{...t,[i]:{...s,count:n.length,bodyIds:n}}}function c(t,e){return(e??Object.keys(t)).map(e=>t[e]).filter(t=>null!=t).map(t=>({label:t.label??t.id,value:t.count}))}function l(t,e){const i=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],s=e.filter(t=>!i.has(t)),n=e.length-s.length,o=t.completion?.mode??"allMembersAbsorbed",r=t.completion?.valueByBodyId,a=t=>{const e=r?.[t];return Number.isFinite(e)&&Number(e)>=0?Number(e):1},d=e.reduce((t,e)=>t+a(e),0),h=e.reduce((t,e)=>t+(i.has(e)?a(e):0),0),c=t.completion?.threshold,l="threshold"===o?Number.isFinite(c)&&Number(c)>=0?Number(c):d:void 0;return{id:t.id,label:t.label??t.id,mode:o,complete:e.length>0&&("anyAbsorbed"===o?n>0:"threshold"===o?h>=(l??d):0===s.length),absorbed:n,total:e.length,absorbedValue:h,totalValue:d,threshold:l,missing:s}})}function u(t,e,i){return Math.max(e,Math.min(i,t))}function p(t,e,i={}){const s=i.random??Math.random,n=t.stages.find(t=>t.id===e)??t.stages[t.stages.length-1],o=u(i.along??.5,.05,.95),r=i.jitterX??0,a=i.padY??20,d=n.x0+(n.x1-n.x0)*o+(2*s()-1)*r,h=Math.min(1,n.width/2),c=u(d,n.x0+h,n.x1-h),l=t.boundaryY(c,"top")+a,p=t.boundaryY(c,"bottom")-a;return{x:c,y:p>l?l+s()*Math.max(1,p-l):t.midY}}function m(t){return"bowtie"===t.shape?[{id:"incoming",role:"incoming",points:[[t.left,t.topY],[t.centerLeft,t.pinchTop],[t.centerLeft,t.pinchBottom],[t.left,t.bottomY]]},{id:"center",role:"center",points:[[t.centerLeft,t.pinchTop],[t.centerRight,t.pinchTop],[t.centerRight,t.pinchBottom],[t.centerLeft,t.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[t.centerRight,t.pinchTop],[t.right,t.topY],[t.right,t.bottomY],[t.centerRight,t.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[t.left,t.topY],[t.right,"funnel"===t.shape?t.pinchTop:t.topY],[t.right,"funnel"===t.shape?t.pinchBottom:t.bottomY],[t.left,t.bottomY]]}]}function f(t,e,i){return Math.max(e,Math.min(i,t))}function y(t,e,i,s,n,o={}){return{id:t,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:e,y1:i,x2:s,y2:n,thickness:o.thickness??8}}}function v(t){const e=t.shape??"lane",i=Math.max(1,Math.round(t.width)),s=Math.max(1,Math.round(t.height)),n=t.padX??46,o=t.padY??72,r=n,a=i-n,d=o,h=s-Math.max(24,Math.round(.45*o)),c=(d+h)/2,l=Math.max(1,h-d),u=f(t.pinchRatio??.18,.06,.5),p=Number(t.pinchHeightOffset??0),m=Number.isFinite(p)?p:0,v=f(l*u+m,.06*l,.5*l),g=v/2,b=c-g,S=c+g,w=t.idPrefix??"process",I=t.friction??.58,M=t.restitution??.18,B=t.wallThickness??8,k=t.stages;if(!k.length)throw Error("processStageLayout requires at least one stage");const O=f(t.centerStageIndex??Math.floor(k.length/2),0,k.length-1),q=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(k),T=a-r;let C=r;const D=k.map((t,e)=>{const i=C,s=e===k.length-1?a:C+(t.share??1)/q*T;return C=s,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:i,x1:s,x:(i+s)/2,width:s-i,y:c,height:l}}),A=D[O],R=A.x0,E=A.x1,Y=(t,i)=>{if("lane"===e)return"top"===i?d:h;if("funnel"===e){const e=f((t-r)/Math.max(1,a-r),0,1);return"top"===i?d+(b-d)*e:h+(S-h)*e}if(R>=t){const e=f((t-r)/Math.max(1,R-r),0,1);return"top"===i?d+(b-d)*e:h+(S-h)*e}if(E>=t)return"top"===i?b:S;const s=f((t-E)/Math.max(1,a-E),0,1);return"top"===i?b+(d-b)*s:S+(h-S)*s},F=D.map(t=>{const e=Math.min(Y(t.x0,"top"),Y(t.x1,"top")),i=Math.max(Y(t.x0,"bottom"),Y(t.x1,"bottom"));return{...t,y:(e+i)/2,height:Math.max(1,i-e)}}),P={thickness:B,friction:I,restitution:M},N=[];"lane"===e?N.push(y(w+"-top",r,d,a,d,P),y(w+"-bottom",r,h,a,h,P),y(w+"-left",r,d,r,h,{...P,thickness:Math.max(6,B-2)}),y(w+"-right",a,d,a,h,{...P,thickness:Math.max(6,B)})):"funnel"===e?N.push(y(w+"-top",r,d,a,b,P),y(w+"-bottom",r,h,a,S,P),y(w+"-left",r,d,r,h,{...P,thickness:Math.max(6,B-2)}),y(w+"-right",a,b,a,S,{...P,thickness:Math.max(6,B)})):N.push(y(w+"-left-top",r,d,R,b,P),y(w+"-left-bottom",r,h,R,S,P),y(w+"-center-top",R,b,E,b,P),y(w+"-center-bottom",R,S,E,S,P),y(w+"-right-top",E,b,a,d,P),y(w+"-right-bottom",E,S,a,h,P),y(w+"-left",r,d,r,h,{...P,thickness:Math.max(6,B-2)}),y(w+"-right",a,d,a,h,{...P,thickness:Math.max(6,B)}));const L=t.membraneDampingScale??.5,X=r,j=Math.max(1,("bowtie"===e?R:a)-X),K=(t.membranes??[]).map(t=>{const e=X+f(t.offset,0,1)*j,i=t.width??18+18*t.cost,s=l-16,n=c+.25*(t.wobble??0);return{...t,x:e,y:n,width:i,height:s}}),$=!1===t.includeMembraneRegions?[]:K.map(t=>x({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??L,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:i,height:s,padX:n,padY:o,left:r,right:a,topY:d,bottomY:h,midY:c,centerLeft:R,centerRight:E,pinchHeight:v,pinchTop:b,pinchBottom:S,stages:F,membranes:K,colliders:N,regionEffects:$,boundaryY:Y}}function g(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,i=t.y,s=t.width,n=t.height,{type:"aabb",x:e,y:i,width:s,height:n}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,i,s,n}function b(t,e={}){const i=e.idPrefix??"stage",s=Math.max(0,e.insetX??0),n=Math.max(0,e.insetY??1);return t.stages.map(t=>{const o="function"==typeof e.metadata?e.metadata(t):e.metadata??{};return{...g({id:i?`${i}:${t.id}`:t.id,label:t.label??t.id,description:t.description,kind:"region",x:t.x,y:t.y,width:Math.max(1,t.width-2*s),height:Math.max(1,t.height-2*n),bodyFilter:e.bodyFilter,semanticItem:e.semanticItem,attributes:{primitive:"processStage",stageId:t.id,stageIndex:t.index},metadata:{...o,primitive:"processStage",stageId:t.id,stageIndex:t.index}})}})}function x(t){const e=t.dampingScale??.5,i=t.energyScale??1,s=f(t.cost,0,2);return{...g({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:s,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:s*e,energyDelta:-s*i}}function S(t){return{...g({...t,kind:t.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),charge:t.charge??!0,energyDelta:t.energyDelta,impulseOnEnter:t.impulseOnEnter}}function w(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...g({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function I(t){const e=t.pressure??t.occupancy??0,i=t.baseDamping??.08,s=t.dampingPerUnit??.12,n=t.energyPerUnit??0;return{...g({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:i+e*s,energyDelta:n?-e*n:void 0,force:t.force}}function M(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...g({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}function B(t){return{...g({...t,kind:t.kind??"force-field",attributes:{primitive:"portal",targetStage:t.targetStage,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,impulseOnEnter:t.impulseOnEnter,damping:t.damping??.08}}function k(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...g({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}function O(t){return{...g({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}function q(t){const e=t.x??t.anchor?.x??0,i=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:i,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:i},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}function T(t){const e=t.idPrefix??"lane",i={thickness:t.thickness??8,friction:t.friction??.5,restitution:t.restitution??.16},s=[y(e+"-top",t.left,t.top,t.right,t.top,i),y(e+"-bottom",t.left,t.bottom,t.right,t.bottom,i)];return t.openEnds||s.push(y(e+"-left",t.left,t.top,t.left,t.bottom,i),y(e+"-right",t.right,t.top,t.right,t.bottom,i)),s}var C={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},D=1e-9,A=.005;function R(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function E(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function Y(t,e,i){return Math.max(e,Math.min(i,t))}function F(t,e,i){return Math.min(t??i,e??i)}function P(t,e,i){return Y(Math.max(t??i,e??i),0,1)}function N(t){return 0>t?-1:1}function L(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,i=t.shape.height/2;return{minX:t.x-e,minY:t.y-i,maxX:t.x+e,maxY:t.y+i}}function X(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,i=e.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}const i=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-i,minY:Math.min(e.y1,e.y2)-i,maxX:Math.max(e.x1,e.x2)+i,maxY:Math.max(e.y1,e.y2)+i}}function j(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function K(t,e,i,s,n,o,r,a){const d=n-t,h=(i+r)/2-Math.abs(d);if(0>=h)return null;const c=o-e,l=(s+a)/2-Math.abs(c);return l>0?l>h?{nx:N(d),ny:0,penetration:h}:{nx:0,ny:N(c),penetration:l}:null}function $(t,e,i,s,n,o,r){const a=o/2,d=r/2,h=t-Y(t,s-a,s+a),c=e-Y(e,n-d,n+d),l=h*h+c*c;if(l>i*i)return null;if(D>=l){const o=Math.abs(t-(s-a)),r=Math.abs(t-(s+a)),h=Math.abs(e-(n-d)),c=Math.abs(e-(n+d)),l=Math.min(o,r,h,c);return l===o?{nx:-1,ny:0,penetration:i+o}:l===r?{nx:1,ny:0,penetration:i+r}:l===h?{nx:0,ny:-1,penetration:i+h}:{nx:0,ny:1,penetration:i+c}}const u=Math.sqrt(l);return{nx:h/u,ny:c/u,penetration:i-u}}function H(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,i,s,n,o){const r=s-t,a=n-e,d=i+o,h=r*r+a*a;if(h>=d*d)return null;if(D>=h)return{nx:1,ny:0,penetration:d};const c=Math.sqrt(h);return{nx:r/c,ny:a/c,penetration:d-c}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return K(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const i=$(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return i?{nx:-i.nx,ny:-i.ny,penetration:i.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?$(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function W(t,e){const i=e.shape;return"aabb"===i.type?"circle"===t.shape.type?$(t.x,t.y,t.shape.radius,i.x,i.y,i.width,i.height):K(i.x,i.y,i.width,i.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,i,s,n,o,r,a=0){const d=o-s,h=r-n,c=d*d+h*h,l=c>D?Y(((t-s)*d+(e-n)*h)/c,0,1):0,u=i+a/2,p=t-(s+d*l),m=e-(n+h*l),f=p*p+m*m;if(f>=u*u)return null;if(D>=f){const t=Math.sqrt(c);return t>D?{nx:-h/t,ny:d/t,penetration:u}:{nx:1,ny:0,penetration:u}}const y=Math.sqrt(f);return{nx:p/y,ny:m/y,penetration:u-y}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,i.x1,i.y1,i.x2,i.y2,i.thickness??0)}function z(t,e){return`${t}\0${e}`}function G(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function U(t){return{id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,bodyCollisions:t.bodyCollisions,shape:R(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function V(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function J(t){return{id:t.id,shape:E(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:V(t.bodyFilter),index:t.index}}function Q(t,e){if(!e)return;let i=t;for(const t of e.split(".")){if(null==i||"object"!=typeof i)return;i=i[t]}return i}function Z(t,e){return!!e?.some(e=>Object.is(t,e))}function _(t,e){if(!e)return!0;if("function"==typeof e)return e(t);const i=Q(t,e.property);return!("equals"in e&&!Object.is(i,e.equals)||"notEquals"in e&&Object.is(i,e.notEquals)||e.oneOf&&!Z(i,e.oneOf)||e.notOneOf&&Z(i,e.notOneOf))}function tt(t,e){return _(e,t.bodyFilter)}var et=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...C,...e},this.random=t(this.options.seed)}init(e={}){this.options={...C,...e},this.random=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(D,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:R(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))G(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:E(e.shape),bodyFilter:V(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,i){const s=this.bodies.get(t);s&&(s.vx+=e/s.mass,s.vy+=i/s.mass,this.wake(s))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const i=this.sortedBodies();for(const t of i)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const s=this.options.maxVelocity;for(const t of i)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,s>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>s){const i=s/e;t.vx*=i,t.vy*=i}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const n=this.bodyPairKeys(i),o=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(i,n,0===t),this.resolveColliders(i,o,0===t);this.updateSensors(i),this.updateSleeping(i,e)}settle(t=1200,e=this.options.fixedDt){let i=0;for(;t>i&&!this.allSleeping();)this.step(e),i+=1;return i}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:R(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(G)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(U),colliders:this.sortedColliders().map(J),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=t(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const t of e.bodies){const e=U(t);this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(const t of e.colliders){const e=J(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(const t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});const e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const i=this.bodies.get(e.bodyId);if(!i||i.sleeping)continue;const s="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!s)continue;const n=s.x-i.x,o=s.y-i.y,r=Math.sqrt(n*n+o*o);if(D>=r)continue;const a=n/r,d=o/r,h=(r-e.restLength)*e.stiffness+((("vx"in s?s.vx:0)-i.vx)*a+(("vy"in s?s.vy:0)-i.vy)*d)*e.damping;i.vx+=h*a*t/i.mass,i.vy+=h*d*t/i.mass}}resolveBodyPairs(t,e,i){for(const s of e){const[e,n]=s.split(":").map(Number),o=t[e],r=t[n];if(!o||!r)continue;const a=H(o,r);a&&(this.resolveDynamicCollision(o,r,a),i&&this.lastEvents.push({type:"contact",bodyId:o.id,otherId:r.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),i=new Map;for(let s=0;t.length>s;s+=1){if(!1===t[s].bodyCollisions)continue;const n=L(t[s]),o=Math.floor(n.minX/e),r=Math.floor(n.maxX/e),a=Math.floor(n.minY/e),d=Math.floor(n.maxY/e);for(let t=o;r>=t;t+=1)for(let e=a;d>=e;e+=1){const n=`${t}:${e}`,o=i.get(n);o?o.push(s):i.set(n,[s])}}const s=new Set;for(const e of Array.from(i.keys()).sort()){const n=i.get(e)??[];n.sort((t,e)=>t-e);for(let e=0;n.length>e;e+=1)for(let i=e+1;n.length>i;i+=1){const o=n[e],r=n[i];!1!==t[o].bodyCollisions&&!1!==t[r].bodyCollisions&&j(L(t[o]),L(t[r]))&&s.add(`${o}:${r}`)}}return Array.from(s).sort((t,e)=>{const[i,s]=t.split(":").map(Number),[n,o]=e.split(":").map(Number);return i===n?s-o:i-n})}resolveDynamicCollision(t,e,i){t.sleeping&&this.contactOpposesGravity(i.nx,i.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-i.nx,-i.ny)&&this.supportedThisStep.add(t.id);const s=t.sleeping?0:1/t.mass,n=e.sleeping?0:1/e.mass,o=s+n;if(D>=o)return;const r=Math.max(0,i.penetration-A)/o;t.x-=i.nx*r*s,t.y-=i.ny*r*s,e.x+=i.nx*r*n,e.y+=i.ny*r*n;const a=(e.vx-t.vx)*i.nx+(e.vy-t.vy)*i.ny;if(a>0)return;const d=Math.abs(a),h=-(1+F(t.restitution,e.restitution,this.options.restitution))*a/o,c=h*i.nx,l=h*i.ny;t.vx-=c*s,t.vy-=l*s,e.vx+=c*n,e.vy+=l*n,this.applyFriction(t,e,i,h,s,n),d>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,i,s,n,o){const r=-i.ny,a=i.nx,d=(e.vx-t.vx)*r+(e.vy-t.vy)*a,h=n+o;if(D>=Math.abs(d)||D>=h)return;const c=P(t.friction,e.friction,this.options.friction),l=Y(-d/h,-s*c,s*c),u=l*r,p=l*a;t.vx-=u*n,t.vy-=p*n,e.vx+=u*o,e.vy+=p*o}resolveColliders(t,e,i){for(const s of t)for(const t of e){if(!tt(t,s))continue;if(!j(L(s),X(t)))continue;const e=W(s,t);e&&(this.resolveStaticCollision(s,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(s.id),i&&this.lastEvents.push({type:"contact",bodyId:s.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,i){t.x+=i.nx*Math.max(0,i.penetration-A),t.y+=i.ny*Math.max(0,i.penetration-A);const s=t.vx*i.nx+t.vy*i.ny;if(0>s){const n=F(t.restitution,e.restitution,this.options.restitution);t.vx-=(1+n)*s*i.nx,t.vy-=(1+n)*s*i.ny;const o=-i.ny,r=i.nx,a=t.vx*o+t.vy*r,d=P(t.friction,e.friction,this.options.friction);t.vx-=a*o*d,t.vy-=a*r*d}}updateSensors(t){const e=new Set,i=this.sortedColliders().filter(t=>t.sensor);for(const s of t){const t=L(s);for(const n of i){if(!tt(n,s))continue;if(!j(t,X(n)))continue;if(!W(s,n))continue;const i=z(n.id,s.id);e.add(i),this.activeSensors.has(i)||this.lastEvents.push({type:"sensor-enter",bodyId:s.id,sensorId:n.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:i,bodyId:s}=G(t);this.lastEvents.push({type:"sensor-exit",bodyId:s,sensorId:i})}this.activeSensors=e}updateSleeping(t,e){const i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const s of t)Math.sqrt(s.vx*s.vx+s.vy*s.vy)>=this.options.sleepSpeed||Math.sqrt((s.x-s.prevX)*(s.x-s.prevX)+(s.y-s.prevY)*(s.y-s.prevY))>=this.options.sleepSpeed*e||i&&!this.supportedThisStep.has(s.id)?s.sleeping?this.wake(s):s.sleepTime=0:(s.sleepTime+=e,s.sleeping||this.options.sleepAfter>s.sleepTime||(s.sleeping=!0,s.vx=0,s.vy=0,this.lastEvents.push({type:"sleep",bodyId:s.id})))}contactOpposesGravity(t,e){const{x:i,y:s}=this.options.gravity,n=Math.hypot(i,s);return 1e-9>=n||-.2>(t*i+e*s)/n}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},it=["binId","targetBin","category","windowIndex","lane","group"];function st(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const i=e-t.mean;t.mean+=i/t.count,t.m2+=i*(e-t.mean)}function nt(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function ot(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function rt(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function at(t,e,i){return"function"==typeof t?t(e,i):"string"==typeof t?rt(e,t):void 0}function dt(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function ht(t){const e=nt(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:nt(t.x),y:nt(t.y),value:e}}var ct=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const i=dt(at(this.config.binAccessor,t,e))??function(t){for(const e of it){const i=dt(rt(t,e));if(i)return i}return"sediment"}(t),s=dt(at(this.config.labelAccessor,t,e))??i,n=function(t,e,i){if("number"==typeof t)return t;const s="function"==typeof t?t(e,i):"string"==typeof t?rt(e,t):1,n="number"==typeof s?s:Number(s);return Number.isFinite(n)?n:1}(this.config.valueAccessor,t,e),o=Math.max(0,Math.floor(this.config.retainBodyIds??12));let r=this.bins.get(i);return r||(r={id:i,label:s,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(i,r)),r.label=s,r.lastBodyId=t.id,r.lastDatum=t.datum,st(r.x,t.x),st(r.y,t.y),st(r.value,n),o>0&&(r.bodyIds.push(t.id),r.bodyIds.length>o&&(r.bodyIds=r.bodyIds.slice(r.bodyIds.length-o))),ht(r)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(ht)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:ot(e.x),y:ot(e.y),value:ot(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function lt(t,e={}){const{baselineY:i=0,binWidth:s=24,gap:n=2,maxHeight:o=80,value:r="count",x:a}=e,d=Math.max(1,...t.map(t=>t[r]));return t.map((t,e)=>{const h=Math.max(0,t[r]/d*o),c=a?.(t,e)??e*(s+n);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:c,y:i-h,width:s,height:h,meanX:t.x.mean,meanY:t.y.mean}})}var ut={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},pt={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function mt(t={},e=pt){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function ft(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function yt(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function vt(t,e){if(null!=t[e])return t[e];const i=t.datum;return i&&"object"==typeof i?i[e]:void 0}function gt(t){return{...ft(t),sequence:t.sequence,spawnAt:t.spawnAt}}function bt(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function xt(t){return!1!==t&&{...t}}function St(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function wt(t){return{...t,gravity:{...t.gravity}}}function It(t,e,i,s){if("circle"===t.shape.type){const n=t.x-e,o=t.y-i,r=t.shape.radius+s,a=n*n+o*o;return a>r*r?null:a}const n=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),o=Math.max(Math.abs(i-t.y)-t.shape.height/2,0),r=n*n+o*o;return r>s*s?null:r}function Mt(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Bt(t,e={}){const{idPrefix:i="plot",includeFloor:s=!0,includeCeiling:n=!1,includeLeftWall:o=!0,includeRightWall:r=!0,wallThickness:a=20,floorThickness:d=a}=e,h=[],c=t.x+t.width/2,l=t.y+t.height/2;return s&&h.push({id:i+"-floor",shape:{type:"aabb",x:c,y:t.y+t.height+d/2,width:t.width+2*a,height:d}}),n&&h.push({id:i+"-ceiling",shape:{type:"aabb",x:c,y:t.y-d/2,width:t.width+2*a,height:d}}),o&&h.push({id:i+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:l,width:a,height:t.height+2*d}}),r&&h.push({id:i+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:l,width:a,height:t.height+2*d}}),h}function kt(t){const{idPrefix:e="bin",count:i,domainStart:s,domainStep:n,xScale:o,yTop:r,yBottom:a,wallThickness:d=4,includeBoundaryWalls:h=!0,includeInteriorWalls:c=!0,closedBefore:l,lidY:u=r,lidThickness:p=Math.max(2,d)}=t,m=[],f=r+(a-r)/2,y=Math.abs(a-r),v=h?i:i-1;if(c||h)for(let t=h?0:1;v>=t;t+=1){if(!c&&t>0&&i>t)continue;const r=o(s+t*n);m.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:r,y:f,width:d,height:y}})}if(null!=l)for(let t=0;i>t;t+=1){const i=s+t*n,r=i+n;if(r>=l)continue;const a=o(i),h=o(r);m.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,h)+d/2,y1:u,x2:Math.max(a,h)-d/2,y2:u,thickness:p}})}return m}var Ot=class{constructor(t={}){this.id="builtin",this.capabilities={...(new et).capabilities,engine:"builtin"},this.world=new et(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function qt(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new Ot(t)}(e)}function Tt(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}import{quadtree as Ct}from"d3-quadtree";var Dt=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,i,s,n,o=0){const r=this.ensure(t,e);if(!r)return null;let a=null,d=1/0;const h=Math.max(0,o)+this.maxSearchRadius,c=s-h,l=s+h,u=n-h,p=n+h;return r.visit((t,e,r,h,m)=>{if(c>h||e>l||u>m||r>p)return!0;if(t.length)return!1;let f=t;for(;f;){const t=f.data;if(t){const e=It(t,s,n,Math.max(0,o));null!=e&&(d>e||e===d&&i.indexOf(t.id)>i.indexOf(a?.id??""))&&(a=t,d=e)}f=f.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const i=t.readState();return 0===i.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=i.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=Ct().x(t=>t.x).y(t=>t.y).addAll(i),this.revision=e,this.tree)}},At=["data","scene-geometry","data-paint","accessibility","evidence"],Rt=["scene-geometry","data-paint","accessibility","evidence"],Et=["overlay","accessibility","evidence"],Yt=(t,e)=>({retainedData:t,invalidations:e}),Ft=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Pt=["scene-geometry","data-paint","accessibility","evidence"],Nt=[],Lt={engine:Yt("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:Yt("preserve",Pt),colliders:Yt("preserve",Pt),sediment:Yt("preserve",Pt),bodyBudget:Yt("preserve",Ft),bodyLimit:Yt("preserve",Ft),eviction:Yt("preserve",Ft),fixedDt:Yt("preserve",Nt),maxDeltaSeconds:Yt("preserve",Nt),maxSubsteps:Yt("preserve",Nt),settleStepLimit:Yt("preserve",Nt),timeScale:Yt("preserve",Nt),observation:Yt("preserve",Nt)},Xt=Yt("preserve",Ft);function jt(t){let e="preserve";const i=new Set;for(const s of t){const t=Lt[s]??Xt;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)i.add(e)}return{retainedData:e,invalidations:i}}var Kt=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function $t(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&Kt.every(i=>t[i]===e[i])}function Ht(t,e,i,s){return t||!e?"paused":i||!s?"running":"settled"}var Wt=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,i){if(i>0)return void(this.seconds=0);const s=t.readState(this.scratch),n=this.speed*this.speed;let o=!0;for(const t of s)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=n){o=!1;break}this.seconds=o?this.seconds+Math.max(0,e):0}},zt=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new Dt,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new e,this.simulationState="settled",this.visible=!0,this.quiescence=new Wt;const{bodyBudget:i,colliders:s,engine:n,kernel:o,observation:r,sediment:a,...d}=t;this.config={...ut,...d},this.configInput={...t},this.bodyBudget=i??{},this.engineInput=n,this.observation=mt(r),this.sediment=new ct(a??!1),this.world=qt(n,{fixedDt:this.config.fixedDt,...o}),this.quiescence.setKernelOptions(o),s&&this.world.setColliders(bt(s))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(i=>"kernel"===i?!$t(t.kernel,e.kernel):t[i]!==e[i])}(t,this.configInput),{colliders:i,bodyBudget:s,engine:n,kernel:o,observation:r,sediment:a,...d}=t;if(this.config={...this.config,...d},void 0!==s&&(this.bodyBudget=s,!1===s&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=qt(n,t.options),this.world.restore(t),this.revision+=1}if(o&&!$t(o,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...o,gravity:{...t.options.gravity,...o.gravity}};this.world.restore({...t,options:e}),this.quiescence.setKernelOptions(e),this.revision+=1}r&&(this.observation=mt(r,this.observation)),this.sediment.updateConfig(a),i&&(this.world.setColliders(bt(i)),this.revision+=1),this.configInput={...this.configInput,...t};const h=jt(e);this.updateResults.record({kind:"config",keys:e},h.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(bt(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},jt(["colliders"]).invalidations)}enqueue(t,e){const i=Array.isArray(t)?t:[t],s=e?function(t,e={}){const i=yt(e.startAt)??0,s=e.pacing??"immediate";if("arrival"===s){const s=t.map((t,i)=>function(t,e,i){return"function"==typeof i?yt(i(t,e)):"string"==typeof i?yt(vt(t,i)):yt(t.spawnAt)??yt(vt(t,"arrivalTime"))??yt(vt(t,"timestamp"))??yt(vt(t,"time"))??yt(vt(t,"eventTime"))}(t,i,e.timeAccessor)),n=s.filter(t=>null!=t),o=n.length>0?Math.min(...n):0,r=yt(e.timeScale)??1,a=r>0?r:1;return t.map((t,e)=>{const n=s[e],r=null==n?0:Math.max(0,n-o);return{...ft(t),spawnAt:i+r/a}})}if("object"==typeof s){const e=yt(s.ratePerSec);if(e&&e>0)return t.map((t,s)=>({...ft(t),spawnAt:i+s/e}))}return t.map(t=>({...ft(t),spawnAt:i}))}(i,{...e,startAt:e.startAt??this.elapsedSeconds}):i;for(const t of s)this.queue.push({...ft(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(St),s.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:s.length},s.length?At:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(ft(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},At)}materializeDueSpawns(){const t=this.revision,e=[],i=[];return this.spawnDue(e,i),0===e.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?At:[])),e}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},At)}tick(t){const e=this.revision,i=[],s=[],n=[],o=[],r=[];if(this.paused||!this.visible){const t=this.result(0,i,s,n,o,r,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(i,r);const d=this.observeBodyBudget(r),h=this.evictOverflow(r);s.push(...h.evicted),n.push(...h.sedimented),this.syncSimulationState(r),this.accumulator+=a;let c=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>c;){this.world.step(this.config.fixedDt);const t=this.world.events();o.push(...t),this.observeKernelEvents(t,r),this.observeSensorTransitions(r),this.accumulator-=this.config.fixedDt,c+=1}c===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,i.length),(c>0||i.length>0||s.length>0||n.length>0||o.length>0)&&(this.revision+=1);const l=this.result(c,i,s,n,o,r,void 0,d);return this.updateResults.record({kind:"tick",count:c},this.revision!==e?i.length||s.length||n.length?At:Rt:[]),l}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const i=this.revision,s=[],n=[],o=[],r=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,s,n,o,r,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(s,a);const d=this.observeBodyBudget(a),h=this.evictOverflow(a);n.push(...h.evicted),o.push(...h.sedimented),this.syncSimulationState(a),s.length>0&&this.quiescence.reset();const c=e?{spawned:s,evicted:n,sedimented:o,events:r,observations:a}:{spawned:s},{steps:l,budget:u}=function(t,e,i){let s,n=0;for(;e>n&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,i.observations),e.length>0){i.spawned.push(...e),s=t.observeBodyBudget(i.observations);const n=t.evictOverflow(i.observations);i.evicted?.push(...n.evicted),i.sedimented?.push(...n.sedimented)}t.step(t.fixedDt);const o=t.drainEvents();i.events&&(i.events.push(...o),t.observeKernelEvents(o,i.observations),t.observeSensorTransitions(i.observations)),n+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:n,budget:s}}(this.settleHost(),t,c),p=s.length+n.length+o.length>0;(l>0||p||r.length>0)&&(this.revision+=1);const m=this.result(l,s,n,o,r,a??[],void 0,u??d);return this.updateResults.record({kind:"settle",count:l},this.revision===i?[]:p?At:Rt),m}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return lt(this.readSediment(),t)}hitTest(t,e,i=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,i)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:i,chartId:s,...n}=t,o={...n,timestamp:e??this.elapsedSeconds,chartType:i??this.observation.chartType,chartId:s??this.observation.chartId};return this.emitObservation(o),this.updateResults.record({kind:"update",count:1},["evidence"]),o}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?Et:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?Et:[])}remove(t){const e=new Set(t),i=new Set(this.liveBodyOrder),s=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const n=t.filter(t=>i.has(t)||s.has(t));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?At:[]),n}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Rt),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Rt)}applyImpulse(t,e,i){this.world.applyImpulse(t,e,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},Rt)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,i,s)=>t.applyImpulse(e,i,s),clear:()=>t.clear(),hitTest:(e,i,s)=>t.hitTest(e,i,s),pause:()=>t.setPaused(!0),push:(e,i)=>t.enqueue(e,i),pushMany:(e,i)=>t.enqueue(e,i),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:xt(this.bodyBudget),config:{...this.config,kernel:wt(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(gt),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:xt(t.bodyBudget??{}),kernel:wt(t.world.options)},this.bodyBudget=xt(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(gt).sort(St),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??Ht(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},At)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const i=this.queue.shift();if(!i)return;this.spawnOne(i,e),t.push(i.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const i=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:i?.datum??t.datum,x:i?.x??t.x,y:i?.y??t.y},e)}result(t,e,i,s,n,o,r,a=this.evaluateBodyBudget()){this.syncSimulationState(o);const d=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:r??(this.queue.length>0||!this.atRest()),sleeping:d,sedimented:s,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,i){if(0===e.length)return;const s=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=s.get(t.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,i){const s=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===s.size&&0===e.size)return s;const n=new Map(t.readState().map(t=>[t.id,t])),o=(t,e)=>{const{sensorId:s,bodyId:o}=Mt(e),r=i.observation.sensors[s],a=n.get(o);i.emit({type:"enter"===t?r?.enterType??"physics-bin-enter":r?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:o,datum:a?.datum,x:a?.x,y:a?.y,sensorId:s,binId:r?.binId??s})};for(const t of Array.from(s).sort())e.has(t)||o("enter",t);for(const t of Array.from(e).sort())s.has(t)||o("exit",t);return s}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const i of t)e.has(Mt(i).bodyId)&&t.delete(i)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return function(t){const e=Math.max(0,Math.floor(t.liveBodies)),i=Math.max(0,Math.floor(t.queuedBodies??0)),s=e+i,n=Tt(t.bodyLimit),o=Tt(t.engineMaxBodiesHint),r=function(t,e,i){if(!1===i)return;const s=Tt(i?.warnAt);return null!=s?s:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(n,o,t.options),a=null==n?0:Math.max(0,e-n),d=a>0?"overflow":null==r||r>s?"ok":"warning";return{action:"overflow"!==d?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:o,liveBodies:e,overflow:a,projectedBodies:s,queuedBodies:i,state:d,warnAt:r}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const i=`${e.state}:${e.action}`;return i===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=i,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=Ht(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const i=this.simulationState;this.simulationState=e,function(t,e,i){i.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||i.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:e,previousSimulationState:t})}(i,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:i,liveBodyOrder:s}=function(t,e,i,s,n,o){const r={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===i)return r;const a=Math.max(0,Math.floor(s));if(!Number.isFinite(a))return r;const d=n.length-a;if(0>=d)return r;const h=function(t,e,i){if("sleeping-first"!==e)return i.slice();const s=new Map(t.readState().map(t=>[t.id,t.sleeping])),n=[],o=[];for(const t of i)s.get(t)?n.push(t):o.push(t);return[...n,...o]}(t,i,n),c=h.slice(0,d);if(0===c.length)return r;const l=function(t,e,i,s){const n=new Map(t.readState().map(t=>[t.id,t])),o=[];for(const t of i){const i=n.get(t);if(!i)continue;const r=e.add(i);r&&(o.push(t),s.emit({type:"physics-sediment",timestamp:s.elapsedSeconds,chartType:s.observation.chartType,chartId:s.observation.chartId,bodyId:t,datum:i.datum,x:i.x,y:i.y,binId:r.id,count:r.count,total:r.total}))}return o}(t,e,c,o);t.remove(c);const u=new Set(c);return{evicted:c,sedimented:l,liveBodyOrder:n.filter(t=>!u.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=s,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:i}}};export{i as placeWithMinGap,n as packBandsBySilhouette,o as orderByBarycenter,r as refineByAdjacentSwaps,a as orderExactSmall,d as countPairwiseCrossings,Q as valueAtPath,_ as matchesPhysicsBodyFilter,lt as sedimentHeightfield,Bt as collidersFromPlotBounds,kt as collidersFromXScaleBins,zt as PhysicsPipelineStore,h as aggregateRegionCounts,c as regionCountsToProjectionRows,l as groupCompletionRows,p as stageTargetInVolume,m as processVolumePolygons,v as processStageLayout,b as processStageRegions,x as membraneRegion,S as chargeGateRegion,w as routeSurfaceRegion,I as pressureFieldRegion,M as capacitatedRegion,B as portalRegion,k as absorbRegion,O as forceFieldRegion,q as bodyGroupSpec,T as processLaneWalls};
@@ -0,0 +1 @@
1
+ import{resolveNodeSizeFn as e}from"./chunk-chunk-LSJUXBMF.module.min.js";function r(e){if("undefined"!=typeof DOMException)return new DOMException(e+" aborted","AbortError");const r=Error(e+" aborted");return r.name="AbortError",r}function t(e){const r=Error(e.message);return r.name=e.name??"Error",e.stack&&(r.stack=e.stack),r}var n=class{constructor(e){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.options=e,this.worker=e.createWorker(),this.worker.onmessage=e=>{const r=this.options.parseMessage(e.data),t=r.requestId,n=null!=t?this.pending.get(t):this.pending.values().next().value;if(n){if(null!=t)this.pending.delete(t);else{for(const e of this.pending.values())e!==n&&(e.cleanup(),e.reject(Error(this.options.name+" worker response missing requestId")));this.pending.clear()}n.cleanup(),r.ok?n.resolve(r.payload):n.reject(r.error)}},this.worker.onerror=e=>{this.rejectAll(Error(e.message||this.options.name+" worker failed")),this.terminate()}}get isDead(){return this.dead}request(e,t){if(this.dead)return Promise.reject(Error(this.options.name+" worker session is closed"));if(t?.aborted)return Promise.reject(r(this.options.name));const n=this.nextRequestId;this.nextRequestId+=1;const s=this.options.encodeRequest?.(n,e)??{requestId:n,request:e};return new Promise((e,o)=>{const i=()=>{this.pending.delete(n),t?.removeEventListener("abort",i),o(r(this.options.name))},a=()=>t?.removeEventListener("abort",i);this.pending.set(n,{cleanup:a,reject:o,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(s)}catch(e){this.pending.delete(n),a(),o(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error(this.options.name+" worker terminated")),this.worker.terminate())}rejectAll(e){for(const r of this.pending.values())r.cleanup(),r.reject(e);this.pending.clear()}};function s(e,r,t,n,s=4e4){return"sync"!==e&&("worker"===e||n*(r+t)>=s)}function o(){return"undefined"!=typeof window&&"undefined"!=typeof Worker}function i(r,t,n,s,o){const i=e(n.nodeSize,n.nodeSizeRange,r);return{kind:"frame",nodes:r.map(e=>{const r=o?.get(e.id);return{id:e.id,x:0!==e.x||0!==e.y?e.x:r?.x??0,y:0!==e.x||0!==e.y?e.y:r?.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:e.value,__forceRadius:i(e)}}),edges:t.map(e=>{const r="string"==typeof e.source?e.source:e.source.id,t="string"==typeof e.target?e.target:e.target.id,n=e.data?.weight,s="number"==typeof n&&Number.isFinite(n)?n:e.value;return{source:r,target:t,value:e.value,y0:0,y1:0,sankeyWidth:0,weight:s}}),config:{chartType:"force",iterations:n.iterations,forceStrength:n.forceStrength,seed:n.seed},size:s}}var a=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):function(e){if("undefined"!=typeof __filename){const r=__filename.replace(/\\/g,"/"),t=r.startsWith("/")?r:"/"+r;return new URL("./"+e,"file:"+t)}throw Error("Cannot resolve module worker asset: "+e)}("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.session=new n({name:"Force layout",createWorker:()=>e,parseMessage:e=>{const r=e,{requestId:n,error:s}=function(e){return e&&"object"==typeof e?{requestId:e.requestId,error:e.error}:{}}(r);return s?{requestId:n,ok:!1,error:t(s)}:{requestId:n,ok:!0,payload:{positions:r.positions??{}}}}})}get isDead(){return this.session.isDead}request(e,r){return this.session.request(e,r)}terminate(){this.session.terminate()}},u=function(){let e=null;return{get:()=>(e&&!e.isDead||(e=new a),e),resetForTest:()=>{if(e){try{e.terminate()}catch{}e=null}}}}();function c(e,r){return o()?u.get().request(e,r):Promise.reject(Error("Web Workers are unavailable"))}export{s as shouldUseForceWorker,o as canUseForceWorker,i as createFrameForceWorkerRequest,c as runForceLayoutWorker};