semiotic 3.10.0 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +55 -59
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/componentMetadata.cjs +3 -1
  4. package/ai/dist/mcp-server.js +45 -45
  5. package/ai/examples.md +67 -0
  6. package/ai/reference.md +75 -1
  7. package/ai/schema.json +5199 -1
  8. package/ai/surface-manifest.json +24 -3
  9. package/ai/task-packets/compare-category-totals.json +6 -6
  10. package/ai/task-packets/compare-category-totals.md +3 -3
  11. package/ai/task-packets/correct-published-chart.json +6 -6
  12. package/ai/task-packets/correct-published-chart.md +3 -3
  13. package/ai/task-packets/index.json +6 -6
  14. package/ai/task-packets/update-live-chart.json +6 -6
  15. package/ai/task-packets/update-live-chart.md +3 -3
  16. package/dist/c-2RL2QPZJ.min.js +1 -0
  17. package/dist/c-45CQWZZ6.min.js +1 -0
  18. package/dist/{c-PP6VY3QU.min.js → c-4BRHKVKV.min.js} +1 -1
  19. package/dist/c-7DVPSB5C.min.js +1 -0
  20. package/dist/{c-XDQKXPX4.min.js → c-A7OGOFSL.min.js} +1 -1
  21. package/dist/{c-AZKPVBOC.min.js → c-AH5HWZWS.min.js} +1 -1
  22. package/dist/c-B7GW7IHJ.min.js +1 -0
  23. package/dist/{c-ROEHCIGV.min.js → c-C3TZLTZK.min.js} +1 -1
  24. package/dist/c-CGQAQWBV.min.js +1 -0
  25. package/dist/c-DIPEYUOW.min.js +1 -0
  26. package/dist/{c-WNGH47HF.min.js → c-E72OTUZU.min.js} +1 -1
  27. package/dist/{c-DY2676CR.min.js → c-EUMPMDCS.min.js} +1 -1
  28. package/dist/c-EZZT2WAE.min.js +1 -0
  29. package/dist/c-FHBVFCQB.min.js +1 -0
  30. package/dist/{c-E32M6XW5.min.js → c-G4HCO2IQ.min.js} +1 -1
  31. package/dist/{c-ZYPXQF7B.min.js → c-G5VIJEOK.min.js} +1 -1
  32. package/dist/c-GHVOXAYH.min.js +1 -0
  33. package/dist/{c-EBOQ7ER7.min.js → c-HP4ZFM47.min.js} +1 -1
  34. package/dist/{c-IDJV3CZK.min.js → c-HYDTS5OP.min.js} +1 -1
  35. package/dist/c-IK33LNZ6.min.js +1 -0
  36. package/dist/c-IK3PZHRY.min.js +1 -0
  37. package/dist/{c-JO2UGTCP.min.js → c-J6DVC236.min.js} +1 -1
  38. package/dist/{c-MXCP7GNZ.min.js → c-JIMJF6F6.min.js} +1 -1
  39. package/dist/{c-4FN7Q6VQ.min.js → c-KKPMHAZC.min.js} +1 -1
  40. package/dist/c-L6WNDBHV.min.js +1 -0
  41. package/dist/c-LDEX5OFW.min.js +1 -0
  42. package/dist/{c-CPSPZH6A.min.js → c-LESEUVC5.min.js} +1 -1
  43. package/dist/c-MB6CV5NC.min.js +1 -0
  44. package/dist/{c-OO5QLMJC.min.js → c-MOKJOIPE.min.js} +1 -1
  45. package/dist/{c-BNG5ECK5.min.js → c-N3FXLRNT.min.js} +1 -1
  46. package/dist/c-N5NPTJVJ.min.js +1 -0
  47. package/dist/{c-DE5Q3U2X.min.js → c-NHBL4J67.min.js} +1 -1
  48. package/dist/{c-LMGSSD2E.min.js → c-ODG6TFSY.min.js} +1 -1
  49. package/dist/{c-HXDKPIKR.min.js → c-PSKKFZNP.min.js} +1 -1
  50. package/dist/{c-NYZ2QNAM.min.js → c-R2P4RR7Q.min.js} +1 -1
  51. package/dist/{c-KCRJGUHP.min.js → c-RFC7UAG7.min.js} +1 -1
  52. package/dist/c-SGAURYHG.min.js +1 -0
  53. package/dist/{c-DK662R77.min.js → c-SJMWU6UX.min.js} +1 -1
  54. package/dist/c-STIIGQOD.min.js +1 -0
  55. package/dist/c-T2ASIJVZ.min.js +1 -0
  56. package/dist/c-TX3THUTO.min.js +1 -0
  57. package/dist/{c-55BAJ333.min.js → c-TX7XJM3Z.min.js} +1 -1
  58. package/dist/c-UMXSJIOV.min.js +1 -0
  59. package/dist/{c-JLGRHXGZ.min.js → c-VRSXMLYF.min.js} +1 -1
  60. package/dist/c-VSLWSAN2.min.js +1 -0
  61. package/dist/{c-33QOXEUG.min.js → c-WCBRPILW.min.js} +1 -1
  62. package/dist/{c-WH2O53VI.min.js → c-WGHT7OCY.min.js} +1 -1
  63. package/dist/c-WWCW3APR.min.js +1 -0
  64. package/dist/c-Y6PYUMFU.min.js +1 -0
  65. package/dist/c-ZIVPFTOC.min.js +1 -0
  66. package/dist/components/charts/shared/chartDataProps.d.ts +3 -0
  67. package/dist/components/charts/shared/chartSpecAtlasSchemas.d.ts +5 -0
  68. package/dist/components/charts/shared/chartSpecCore.d.ts +4 -0
  69. package/dist/components/charts/shared/chartSpecsAtlas.d.ts +2 -0
  70. package/dist/components/charts/shared/hooks.d.ts +3 -1
  71. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  72. package/dist/components/recipes/atlas/DependencyForestChart.d.ts +20 -0
  73. package/dist/components/recipes/atlas/DependencyMatrix.d.ts +7 -0
  74. package/dist/components/recipes/atlas/FlowCircuitChart.d.ts +20 -0
  75. package/dist/components/recipes/atlas/MotifBraidChart.d.ts +17 -0
  76. package/dist/components/recipes/atlas/atlasChartOptions.d.ts +11 -0
  77. package/dist/components/recipes/atlas/braid.d.ts +62 -0
  78. package/dist/components/recipes/atlas/capsules.d.ts +18 -0
  79. package/dist/components/recipes/atlas/compare.d.ts +4 -0
  80. package/dist/components/recipes/atlas/completeness.d.ts +2 -0
  81. package/dist/components/recipes/atlas/dependencyForest.d.ts +32 -0
  82. package/dist/components/recipes/atlas/dependencyForestChartProps.d.ts +58 -0
  83. package/dist/components/recipes/atlas/dependencyForestLayout.d.ts +17 -0
  84. package/dist/components/recipes/atlas/dependencyQueries.d.ts +20 -0
  85. package/dist/components/recipes/atlas/dependencyTypes.d.ts +21 -0
  86. package/dist/components/recipes/atlas/directedGraph.d.ts +9 -0
  87. package/dist/components/recipes/atlas/entityCounts.d.ts +3 -0
  88. package/dist/components/recipes/atlas/flowCircuit.d.ts +32 -0
  89. package/dist/components/recipes/atlas/flowCircuitChartProps.d.ts +72 -0
  90. package/dist/components/recipes/atlas/flowCircuitChrome.d.ts +18 -0
  91. package/dist/components/recipes/atlas/flowCircuitGeometry.d.ts +11 -0
  92. package/dist/components/recipes/atlas/flowCircuitLayout.d.ts +20 -0
  93. package/dist/components/recipes/atlas/flowCircuitSemantics.d.ts +26 -0
  94. package/dist/components/recipes/atlas/flowCircuitTape.d.ts +22 -0
  95. package/dist/components/recipes/atlas/flowCircuitTypes.d.ts +144 -0
  96. package/dist/components/recipes/atlas/forests.d.ts +11 -0
  97. package/dist/components/recipes/atlas/ids.d.ts +6 -0
  98. package/dist/components/recipes/atlas/index.d.ts +26 -0
  99. package/dist/components/recipes/atlas/ledger.d.ts +7 -0
  100. package/dist/components/recipes/atlas/motifBraidChartProps.d.ts +51 -0
  101. package/dist/components/recipes/atlas/motifBraidGeometry.d.ts +5 -0
  102. package/dist/components/recipes/atlas/motifBraidLayout.d.ts +11 -0
  103. package/dist/components/recipes/atlas/motifs.d.ts +3 -0
  104. package/dist/components/recipes/atlas/prefixForest.d.ts +9 -0
  105. package/dist/components/recipes/atlas/prepare.d.ts +14 -0
  106. package/dist/components/recipes/atlas/prepareAsync.d.ts +7 -0
  107. package/dist/components/recipes/atlas/profile.d.ts +19 -0
  108. package/dist/components/recipes/atlas/publish.d.ts +10 -0
  109. package/dist/components/recipes/atlas/queries.d.ts +34 -0
  110. package/dist/components/recipes/atlas/requiredPaths.d.ts +9 -0
  111. package/dist/components/recipes/atlas/rootedForest.d.ts +4 -0
  112. package/dist/components/recipes/atlas/sections.d.ts +3 -0
  113. package/dist/components/recipes/atlas/support.d.ts +7 -0
  114. package/dist/components/recipes/atlas/types.d.ts +278 -0
  115. package/dist/components/recipes/atlas/validate.d.ts +12 -0
  116. package/dist/components/semiotic-atlas-core.d.ts +20 -0
  117. package/dist/components/semiotic-atlas.d.ts +8 -0
  118. package/dist/components/semiotic-recipes-core.d.ts +9 -0
  119. package/dist/components/server/serverChartConfigs.d.ts +3 -0
  120. package/dist/components/server/serverChartConfigsAtlas.d.ts +4 -0
  121. package/dist/components/stream/NetworkPipelineStore.d.ts +1 -0
  122. package/dist/components/stream/canvasSetup.d.ts +1 -2
  123. package/dist/components/stream/fontLoading.d.ts +4 -0
  124. package/dist/components/stream/networkCustomLayout.d.ts +8 -0
  125. package/dist/components/stream/networkCustomLayoutCache.d.ts +12 -0
  126. package/dist/components/stream/networkPipelineConfig.d.ts +0 -7
  127. package/dist/components/stream/physics/physicsSemanticUI.d.ts +2 -0
  128. package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +3 -1
  129. package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +2 -0
  130. package/dist/components/stream/shallowEqual.d.ts +2 -0
  131. package/dist/components/stream/useEnsureCustomXYRenderers.d.ts +4 -2
  132. package/dist/geo.min.js +1 -1
  133. package/dist/geo.module.min.js +1 -1
  134. package/dist/network.module.min.js +1 -1
  135. package/dist/ordinal.module.min.js +1 -1
  136. package/dist/physics.module.min.js +1 -1
  137. package/dist/rough.module.min.js +1 -1
  138. package/dist/semiotic-access.module.min.js +1 -1
  139. package/dist/semiotic-ai-core.min.js +1 -1
  140. package/dist/semiotic-ai-core.module.min.js +1 -1
  141. package/dist/semiotic-ai.module.min.js +1 -1
  142. package/dist/semiotic-artifact.min.js +1 -1
  143. package/dist/semiotic-artifact.module.min.js +1 -1
  144. package/dist/semiotic-atlas-core.d.ts +20 -0
  145. package/dist/semiotic-atlas-core.min.js +1 -0
  146. package/dist/semiotic-atlas-core.module.min.js +1 -0
  147. package/dist/semiotic-atlas-selection.module.min.js +2 -0
  148. package/dist/semiotic-atlas.d.ts +8 -0
  149. package/dist/semiotic-atlas.min.js +2 -0
  150. package/dist/semiotic-atlas.module.min.js +2 -0
  151. package/dist/semiotic-client-cjs-shared.min.js +1 -1
  152. package/dist/semiotic-evidence.min.js +1 -1
  153. package/dist/semiotic-evidence.module.min.js +1 -1
  154. package/dist/semiotic-experimental-auxiliary.module.min.js +1 -1
  155. package/dist/semiotic-experimental-node-auxiliary.module.min.js +1 -1
  156. package/dist/semiotic-experimental-react-shared.module.min.js +1 -1
  157. package/dist/semiotic-experimental-vacp.min.js +1 -1
  158. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  159. package/dist/semiotic-line.module.min.js +1 -1
  160. package/dist/semiotic-realtime-core.module.min.js +1 -1
  161. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -1
  162. package/dist/semiotic-recipes-core.d.ts +9 -0
  163. package/dist/semiotic-recipes-core.module.min.js +1 -1
  164. package/dist/semiotic-server-edge-node.module.min.js +1 -1
  165. package/dist/semiotic-server-edge.min.js +1 -1
  166. package/dist/semiotic-server-edge.module.min.js +1 -1
  167. package/dist/semiotic-server-node.min.js +1 -1
  168. package/dist/semiotic-server-node.module.min.js +1 -1
  169. package/dist/semiotic-text.min.js +1 -1
  170. package/dist/semiotic-text.module.min.js +1 -1
  171. package/dist/semiotic-utils-core.min.js +1 -1
  172. package/dist/semiotic-utils-core.module.min.js +1 -1
  173. package/dist/semiotic.module.min.js +1 -1
  174. package/dist/server.min.js +1 -1
  175. package/dist/server.module.min.js +1 -1
  176. package/dist/xy.module.min.js +1 -1
  177. package/package.json +16 -1
  178. package/dist/c-447VIMRO.min.js +0 -1
  179. package/dist/c-553QUDKA.min.js +0 -1
  180. package/dist/c-7HP7MB2I.min.js +0 -1
  181. package/dist/c-7NBU5ZKS.min.js +0 -1
  182. package/dist/c-CCTGN5CK.min.js +0 -1
  183. package/dist/c-GSZRZRD6.min.js +0 -1
  184. package/dist/c-GWX7JGMF.min.js +0 -1
  185. package/dist/c-ITKX3RC5.min.js +0 -1
  186. package/dist/c-JG2JCQLP.min.js +0 -1
  187. package/dist/c-LYVKDBQJ.min.js +0 -1
  188. package/dist/c-NG7BLZTR.min.js +0 -1
  189. package/dist/c-PYNW54D2.min.js +0 -1
  190. package/dist/c-TIXX5CAU.min.js +0 -1
  191. /package/dist/{c-OOVX2JPQ.min.js → c-UC7SIU2W.min.js} +0 -0
@@ -1 +1 @@
1
- function e(e,t,r){let n=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,o=e=>Number.isFinite(e)?Math.max(0,e):0,i=e.reduce((e,t)=>e+(o(t.weight)>0?1:0),0),a=i>0?Math.min(Math.max(0,Math.floor(r?.minPerCategory??0)),Math.floor(n/i)):0,l=e.reduce((e,t)=>e+o(t.weight),0);if(0>=n||0>=l)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));let s=e.map(e=>{let t=o(e.weight),r=t/l*n;return{...e,exact:r,cells:t>0?Math.max(a,Math.floor(r)):0,remainder:r-Math.floor(r)}}),c=s.reduce((e,t)=>e+t.cells,0);for(;c>n;){let e=s.filter(e=>e.cells>a).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,c--}let u=s.filter(e=>o(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||o(t.weight)-o(e.weight)||e.key.localeCompare(t.key));for(let e=0;n>c;e++)u[e%u.length].cells++,c++;return s}function t(e,t,r,n){let o=new Set;return e.map((e,i)=>{let a=t(e,i)+"",l=Number(r(e,i));if(!a)throw Error(`${n} snapshot contains an empty id at index ${i}.`);if(o.has(a))throw Error(`${n} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(l)||0>l)throw Error(`${n} snapshot value for "${a}" must be a finite non-negative number.`);return o.add(a),{id:a,value:l}})}function r(e,r,n){let o=n.afterId??n.beforeId,i=n.afterValue??n.beforeValue,a=null==n.epsilon||0>n.epsilon?1e-9:n.epsilon,l=t(e,n.beforeId,n.beforeValue,"Before"),s=t(r,o,i,"After"),c=new Map(l.map(e=>[e.id,e.value])),u=new Map(s.map(e=>[e.id,e.value])),d=l.reduce((e,t)=>e+t.value,0),h=s.reduce((e,t)=>e+t.value,0),f=a>=Math.abs(d-h);if(!f&&!n.allowImbalance)throw Error(`Snapshot totals must match (before ${d}, after ${h}). Pass allowImbalance to inspect residuals.`);let m=[],p=[...l.map(e=>e.id),...s.map(e=>e.id).filter(e=>!c.has(e))];for(let e of p){let t=Math.min(c.get(e)??0,u.get(e)??0);t>a&&m.push({sourceId:e,targetId:e,value:t,kind:"stay"})}let g=l.map(e=>({id:e.id,value:e.value-(u.get(e.id)??0)})).filter(e=>e.value>a),y=s.map(e=>({id:e.id,value:e.value-(c.get(e.id)??0)})).filter(e=>e.value>a),x=0,b=0;for(;g.length>x&&y.length>b;){let e=g[x],t=y[b],r=Math.min(e.value,t.value);r>a&&m.push({sourceId:e.id,targetId:t.id,value:r,kind:"move"}),e.value-=r,t.value-=r,a>=e.value&&(x+=1),a>=t.value&&(b+=1)}return{flows:m,beforeTotal:d,afterTotal:h,balanced:f,unmatchedBefore:g.slice(x).filter(e=>e.value>a).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:y.slice(b).filter(e=>e.value>a).map(({id:e,value:t})=>({id:e,value:t}))}}function n(e){return Number.isFinite(e)?Math.max(0,e):0}function o(e,t){let r=Number(t.unit),o=n(e),i=t.maxUnits??1/0,a=t.minFraction??0;if(0>=r||0>=i||0>=o)return{units:[],unit:r>0?r:0,total:o,shown:0,overflow:o>0&&!(i>0)};let l=Math.ceil(o/r-1e-6),s=Math.min(i,l),c=l>i,u=[];for(let e=0;s>e;e+=1){let t=e*r,n=Math.min(1,Math.max(0,(Math.min(o,t+r)-t)/r));1e-6>1-n&&(n=1),u.push({index:e,fraction:n,start:t,end:t+n*r,value:n*r})}let d=u[u.length-1];d&&a>d.fraction&&1>d.fraction&&u.pop();let h=u.reduce((e,t)=>e+t.value,0);return{units:u,unit:r,total:o,shown:h,overflow:c}}function i(e,t,r){let i=o(e,r),a=Math.max(n(t),i.total);if(i.total>=a)return{...i,rangeUnits:[],rangeTotal:i.total};let l=o(a,{unit:r.unit,maxUnits:r.maxUnits}),s=l.unit>0?i.total/l.unit:0,c=Math.floor(s+1e-6),u=Math.min(1,Math.max(0,s-c));1e-6>u&&(u=0);let d=[];for(let e of l.units)if(e.index>=c){if(e.index===c&&u>0){e.fraction-u>1e-6&&d.push({...e,startFraction:u,start:e.index*l.unit+u*l.unit,value:(e.fraction-u)*l.unit});continue}d.push({...e,startFraction:0})}return{...i,overflow:i.overflow||l.overflow,rangeUnits:d,rangeTotal:a}}function a(e,t,r={}){let n=r.iterations??260,o=r.repulsion??5200,i=r.linkDistance??165,a=r.linkStrength??.045,l=r.centerStrength??.018,s=r.damping??.84,c=r.nodeRadius??12,u=r.nodePadding??3,d=r.inset??.06,h=ii(r.seed??1),f=new Map;for(let t of e)f.set(t.id,0);for(let e of t)f.set(e.source,(f.get(e.source)??0)+1),f.set(e.target,(f.get(e.target)??0)+1);let m=500,p=e.map(e=>({id:e.id,data:e,x:200+600*h(),y:200+600*h()})),g=new Set(e.map(e=>e.id)),y=t.filter(e=>g.has(e.source)&&g.has(e.target)).map(e=>({source:e.source,target:e.target}));if(n>0){let e=qi(p).randomSource(h).alphaDecay(1-Math.pow(.001,1/n)).velocityDecay(Math.max(0,Math.min(1,1-s))).force("charge",Pi().strength(e=>{let t=f.get(e.id)??0;return 2.5*-Math.sqrt(o)*Math.sqrt(t+1)})).force("collide",Li(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Wi(m,m).strength(.8)).force("x",Di(m).strength(l)).force("y",Vi(m).strength(l));y.length>0&&e.force("link",Ti(y).id(e=>e.id).distance(i).strength(e=>{let t="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(f.get("string"==typeof e.source?e.source:e.source.id)??1,f.get(t)??1));return a/.045/r})),e.stop();for(let t=0;n>t;t+=1)e.tick()}let x=1/0,b=1/0,M=-1/0,w=-1/0;for(let e of p){let t=e.x??m,r=e.y??m;x>t&&(x=t),b>r&&(b=r),t>M&&(M=t),r>w&&(w=r)}let v=M-x,k=w-b,$={};for(let e of p)Object.defineProperty($,e.id,{value:{x:0===v?.5:d+((e.x??m)-x)/v*(1-2*d),y:0===k?.5:d+((e.y??m)-b)/k*(1-2*d)},enumerable:!0,configurable:!0,writable:!0});return $}function l(e){return e?e.map(Number).filter(Number.isFinite):[]}function s(e){if("fixed-denominator"===e.countStrategy)return 1/0;let t=e.maxTokens??1/0;return t>0?Math.floor(t):0}function c(e){let t=e.unitValue??e.unit,r=e.icon??e.token;return{...e,...null!=t&&{unitValue:t},...null!=r&&{icon:r}}}function u(e){if(e.samples)return l(e.samples);if(!e.data||!e.valueAccessor)return[];let t=e.valueAccessor;return e.data.map(e=>"function"==typeof t?t(e):Number(e[t])).filter(Number.isFinite)}function d(e,t,r,n={}){return{index:t,tokenType:e.tokenType,tokenSemantics:e.tokenSemantics,countStrategy:e.countStrategy,fraction:1,startFraction:0,value:r,start:t,end:t+r,unitValue:e.unitValue,unitMeaning:e.unitMeaning,...n}}function h(e,t){let r,n,a,h,f,p,g,y=c(t),x=function(e){return"number"==typeof e?{value:e}:Array.isArray(e)?{samples:l(e),data:e}:e}(e),b=0,M=!1;if("unitized"===y.countStrategy){f=y.unitValue??1;let e={unit:f,maxUnits:y.maxTokens,minFraction:y.minFraction},t=null==x.rangeValue?o(ai(x.value),e):i(ai(x.value),ai(x.rangeValue),e);r=t.units.map(e=>d(y,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:t.unit})),n=t.total,b=t.shown,M=t.overflow,null!=x.rangeValue&&(p=t.rangeTotal,g=t.rangeUnits.map(e=>d(y,e.index,e.value,{fraction:e.fraction,startFraction:e.startFraction,start:e.start,end:e.end,unitValue:t.unit,range:"scenario"})))}else if("fixed-denominator"===y.countStrategy){h=Math.floor(ai(x.denominator??y.denominator)),a=ai(x.numerator??y.numerator??x.value);let e=Math.min(h,Math.max(0,Math.round(a)));r=Array.from({length:h},(t,r)=>d(y,r,1,{highlighted:e>r,start:r,end:r+1})),n=h,b=r.length,M=!1}else if("quantile"===y.countStrategy){let e=u(x).sort((e,t)=>e-t),t=Math.max(0,Math.floor(y.tokenCount??50)),o=e.length>0?Math.min(t,s(y)):0;r=Array.from({length:o},(t,r)=>{let n=(r+.5)/o,i=function(e,t){let r=e.length;if(0===r)return 0;if(1===r)return e[0];let n=(r-1)*Math.min(1,Math.max(0,t)),o=Math.floor(n),i=n-o;return e[o]*(1-i)+e[Math.ceil(n)]*i}(e,n);return d(y,r,i,{sample:i,quantile:n,start:i,end:i})}),n=e.length,b=r.length,M=e.length>0&&t>r.length}else if("sample"===y.countStrategy||"posterior-sample"===y.countStrategy||"random-sample"===y.countStrategy){let e=u(x),t=Math.min(e.length,Math.max(0,Math.floor(y.tokenCount??e.length))),o=Math.min(t,s(y));r=("random-sample"===y.countStrategy?function(e,t=1){let r=Array.from({length:e},(e,t)=>t),n=ii(Math.floor(t)||1);for(let e=r.length-1;e>0;e-=1){let t=Math.floor(n()*(e+1)),o=r[e];r[e]=r[t],r[t]=o}return r}(e.length,y.seed).slice(0,o):Array.from({length:o},(t,r)=>Math.floor(r/Math.max(1,o-1)*(e.length-1)))).map((t,r)=>{let n=e[t];return d(y,r,n,{sample:n,start:n,end:n})}),n=e.length,b=r.length,M=t>r.length}else{let e=x.data;if(e&&null==x.value)r=e.map((e,t)=>d(y,t,1,{datum:e})),n=e.length;else{let e=o(ai(x.value),{unit:1,maxUnits:y.maxTokens,minFraction:y.minFraction});r=e.units.map(e=>d(y,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:1})),n=e.total,b=e.shown,M=e.overflow}if(e&&null==x.value){let e=function(e,t){let r=s(t);return e.length>r?{tokens:e.slice(0,r),overflow:!0}:{tokens:e,overflow:!1}}(r,y);r=e.tokens,b=r.length,M=e.overflow}}return{tokens:r,encoding:y,total:n,shown:b,overflow:M,numerator:a,denominator:h,unitValue:f,rangeTotal:p,rangeTokens:g,diagnostics:m(y,{visibleTokens:r.length+(g?.length??0)})}}function f(e,t={}){let r=Array.isArray(e)?e:e.tokens,n=r.length;if(0===n)return[];let o=t.flow??"row",i=t.cellWidth??16,a=t.cellHeight??i,l=t.gutter??2,s=t.anchor??[.5,.5],c=Math.max(1,Math.floor(t.columns??Math.ceil(t.rows?n/t.rows:Math.sqrt(n)))),u=Math.max(1,Math.floor(t.rows??Math.ceil(n/c))),d="row"===o?Math.max(u,Math.ceil(n/c)):u,h="column"===o?Math.max(c,Math.ceil(n/u)):c,f=t.x??0,m=t.y??0;return r.map((e,r)=>{let n,p;return"column"===o?(p=Math.floor(r/u),n=r%u):(n=Math.floor(r/c),p=r%c),"left"===t.columnDirection&&(p=h-1-p),"up"===t.rowDirection&&(n=d-1-n),{...e,row:n,column:p,x:f+p*(i+l)+s[0]*i,y:m+n*(a+l)+s[1]*a}})}function m(e,t={}){let r=[],n=e.tokenSemantics,o=e.countStrategy,i=t.maxRecommendedTokens??("fixed-denominator"!==o||ai(e.denominator)>100?80:100);return n||r.push({code:"TOKEN_SEMANTICS_UNCLEAR",severity:"warning",message:"Every tokenized encoding should state what one token represents."}),o||r.push({code:"MISSING_COUNT_STRATEGY",severity:"warning",message:"Every tokenized encoding should state how token counts are produced."}),("icon"===e.tokenType||"glyph"===e.tokenType)&&("icon-only"===e.labelPolicy||"token-only"===e.labelPolicy)&&r.push({code:"ICON_ONLY_LABELS",severity:"warning",message:"Icons should supplement text labels, not replace them."}),null!=t.visibleTokens&&t.visibleTokens>i&&r.push({code:"TOO_MANY_VISIBLE_TOKENS",severity:"warning",message:`This encoding renders ${t.visibleTokens} visible tokens. Consider unitizing, sampling, or a hybrid bar/token view.`}),"decorative"===n&&("icon"===e.tokenType||"glyph"===e.tokenType)&&r.push({code:"DECORATIVE_PICTOGRAPHS",severity:"warning",message:"Decorative pictographs can harm recall and speed when they do not clarify the data."}),"unitized-measure"===n&&o&&"unitized"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Unitized measures should use the unitized count strategy so each token has a stable value."}),"risk-case"===n&&o&&"fixed-denominator"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Risk cases are usually clearest as a fixed-denominator natural frequency."}),("possible-outcome"===n||"posterior-sample"===n||"hypothetical-case"===n)&&o&&"quantile"!==o&&"sample"!==o&&"posterior-sample"!==o&&"random-sample"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Outcome/sample tokens should come from quantiles or samples, not from a unitized magnitude."}),"unitized-measure"===n&&"unitized"===o&&null==e.unitValue&&null==e.unit&&r.push({code:"MISSING_UNIT_VALUE",severity:"warning",message:"Unitized measures should set unitValue so each token has a declared value."}),"unitized-measure"===n&&"unitized"===o&&!e.unitMeaning&&r.push({code:"MISSING_UNIT_MEANING",severity:"info",message:"Add unitMeaning so readers know what one full token represents."}),r}function p(e){return"measure"===e?"precise-comparison":"estimate probability"===e?"probability-estimation":"understand risk"===e?"risk-communication":"remember"===e?"memory":"decide"===e?"support-decision":e}function g(e){let t=p(e);return"precise-comparison"===t?["compare-categories","rank"]:"probability-estimation"===t?["distribution"]:"risk-communication"===t?["part-to-whole","distribution"]:"frequency-reasoning"===t?["distribution","compare-categories"]:"memory"===t||"editorial-engagement"===t?["compare-categories"]:"public-explanation"===t||"support-decision"===t?["distribution","compare-categories"]:["compare-categories"]}function y(e){let t=p(e.taskIntent),r="small"===(n=e.availableSpace)?25:"large"===n?100:50;var n;if("precise-comparison"===t)return{recommendedEncoding:"bar-or-line",rationale:"Use continuous position/length encodings when precise magnitude comparison is the primary task.",warnings:[],alternatives:["hybrid-bar-token","unitized-measure"]};if("probability-estimation"===t){let e={tokenType:"dot",tokenSemantics:"possible-outcome",countStrategy:"quantile",tokenCount:r,layout:"dotplot",labelPolicy:"text-plus-token"};return{recommendedEncoding:"quantile-dotplot",tokenEncoding:e,rationale:"This task asks readers to estimate probability from a distribution. Quantile tokens turn probability mass into countable possible outcomes.",warnings:m(e),alternatives:["cdf-with-threshold","density-with-threshold"]}}if("risk-communication"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"risk-case",countStrategy:"fixed-denominator",denominator:100,layout:"waffle",labelPolicy:"text-plus-token"};return{recommendedEncoding:"fixed-denominator-icon-array",tokenEncoding:t,rationale:"Risk is often clearer as natural frequency: highlighted cases out of a fixed denominator.",warnings:m(t,{visibleTokens:100,maxRecommendedTokens:100}),alternatives:["labeled-percent","bar-with-risk-threshold"]}}if("memory"===t||"editorial-engagement"===t){let t={tokenType:e.concreteEntity?"glyph":"icon",icon:e.concreteEntity,tokenSemantics:"unitized-measure",countStrategy:"unitized",unitValue:1,layout:"grid",labelPolicy:"text-plus-token",unitMeaning:e.concreteEntity?"one token represents a unit of "+e.concreteEntity:"one token represents one unit"};return{recommendedEncoding:"semantic-isotype",tokenEncoding:t,rationale:"Semantic tokens are useful when the chart needs to make a topic concrete and memorable.",warnings:m(t),alternatives:["labeled-bar","hybrid-bar-token"]}}if("frequency-reasoning"===t||"public-explanation"===t||"support-decision"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"distribution"===e.dataType?"possible-outcome":"unitized-measure",countStrategy:"distribution"===e.dataType?"quantile":"unitized",unitValue:"distribution"===e.dataType?void 0:1,tokenCount:r,layout:"distribution"===e.dataType?"dotplot":"bar-segment",labelPolicy:"text-plus-token",unitMeaning:"distribution"===e.dataType?void 0:"one token represents one unit interval"};return{recommendedEncoding:"hybrid-continuous-token",tokenEncoding:t,rationale:"A hybrid view preserves measurement while adding countable tokens for explanation and decisions.",warnings:m(t),alternatives:["bar-or-line","quantile-dotplot","fixed-denominator-icon-array"]}}return{recommendedEncoding:"bar-or-line",rationale:"Use continuous encodings unless the task needs frequency, risk, memory, or outcome reasoning.",warnings:[],alternatives:["unitized-measure","quantile-dotplot","fixed-denominator-icon-array"]}}function x(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function b(e,t,r){return"function"==typeof e?e(t)??r:e??r}function M(e,t){return"function"==typeof e?e(t):e}function w(e){return e.sample??e.value??e.index}function v(e,t){return void 0!==t.datum?b(t.datum,e,null):e.datum??null}function k(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?b(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):b(t.color,e,Ji):b(t.inactiveColor,e,ea),stroke:"none",...M(t.style,e)??{}}}function $(e,t){let r=M(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:v(e,t),accessibleDatum:M(t.accessibleDatum,e),accessibility:M(t.accessibility,e),pointId:r,_transitionKey:r}}function A({input:e,encoding:t,options:r={}}){if(!x(e)&&!t)throw Error("tokenLayer requires an encoding when input is not a TokenSet.");let n=x(e)?{...e,encoding:c(e.encoding)}:h(e,t),o=function(e,t){let r=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){let r=t.positionToken;return r?e.map((t,n)=>{let o=r(t,n,e);return{...t,x:o.x,y:o.y,row:o.row??n,column:o.column??0}}):[]}(r,t);let n=t.layout??e.encoding.layout??"grid";if("quantile-strip"===n)return function(e,t){if(0===e.length)return[];let r=t.x??0,n=t.y??0,o=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.gutter??2,a=Math.max(1,Math.floor(t.rows??1)),l=e.map(w),s=Math.min(...l),c=Math.max(...l)-s||1;return e.map((l,u)=>{let d=w(l),h=u%a,f=t.valueToX?t.valueToX(d,l):r+(d-s)/c*(t.width??12*Math.max(1,e.length-1)),m=t.valueToY?t.valueToY(d,l):n+h*(o+i);return{...l,x:f,y:m,row:h,column:u}})}(r,t);if("dotplot"===n)return function(e,t){if(0===e.length)return[];let r=t.x??0,n=t.y??0,o="number"==typeof t.tokenSize?t.tokenSize:12,i=t.gutter??2,a=t.cellWidth??o+i,l=t.cellHeight??o+i,s=e.map(w),c=Math.min(...s),u=Math.max(...s)-c||1,d=new Map;return e.map(o=>{let i=w(o),s=t.valueToX?t.valueToX(i,o):r+(i-c)/u*(t.width??Math.max(1,e.length-1)*a),h=Math.round((s-r)/Math.max(1,a)),f=d.get(h)??0;d.set(h,f+1);let m=t.valueToY?t.valueToY(i,o):n+f*l;return{...o,x:r+h*a,y:m,row:f,column:h}})}(r,t);if("bar-segment"===n){if(!t.valueToX)throw Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];let r=t.y??0,n=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),o=t.anchor??[.5,.5];return e.map((e,i)=>{let a=Number.isFinite(e.start)?e.start:w(e),l=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,s=t.valueToY?t.valueToY(l,e):r+o[1]*n;return{...e,x:t.valueToX(l,e),y:s,row:0,column:i}})}(r,t)}if("beeswarm"===n||"small-multiple"===n)throw Error(`tokenLayer layout "${n}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);let o="number"==typeof t.tokenSize?t.tokenSize:void 0,i=t.cellWidth??o??12,a=t.cellHeight??o??i,l="row"===n?Math.max(1,r.length):"column"===n||"stack"===n?1:"waffle"===n&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,r){if(t.columns)return t.columns;if(t.width&&r>0){let e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(r+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(r,t,i);return f(r,{...t,columns:l,cellWidth:i,cellHeight:a})}(n,r).filter(e=>!r.include||r.include(e));return{tokenSet:n,positionedTokens:o,nodes:o.map(e=>function(e,t,r){if("dot"===r.tokenType)return function(e,t){let r=b(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:b(t.radius,e,r/2),style:k(e,t),...$(e,t)}}(e,t);let n=M(t.glyph,e)??function(e){if(e)return Zi[e]}(r.icon);if(n)return function(e,t,r){let n=k(e,r),o=b(r.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:o,glyph:t,color:(n.fill??Ji)+"",accent:b(r.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:1>e.fraction?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:b(r.fractionDirection,e,"horizontal"),ghostColor:1>e.fraction?M(r.ghostColor,e)??ea:void 0,rotation:M(r.rotation,e),style:n,...$(e,r)}}(e,n,t);let o=(i=r.icon)&&ta.has(i)?i:void 0;var i;return function(e,t){let r=b(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,r/2)**2,symbolType:b(t.symbolType,e,"circle"),path:M(t.symbolPath,e),rotation:M(t.rotation,e),style:k(e,t),...$(e,t)}}(e,o&&null==t.symbolType?{...t,symbolType:o}:t)}(e,r,n.encoding))}}function S(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function I(e,t){let r=S(e,t);return"string"==typeof r&&r.length>0?r:void 0}function C(e,t){if(sa.has(t))return I(e,t)}function N(e,t){if("function"==typeof e)return e;let r=e??t;return e=>e[r]}function z(e,t,r){return[111.32*(e-r.lon)*Math.cos((t+r.lat)/2*(Math.PI/180)),110.574*(t-r.lat)]}function F(e){let t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function E(e){return sa.has(e)?e:"monument"}function j(e,t){let r=F(t.gridSize),n=Math.max(1,t.gridRadiusKm??75),o=2*n/r,i=Math.floor(r/2),a=N(t.idAccessor,"id"),l=N(t.nameAccessor,"name"),s=N(t.longitudeAccessor,"lon"),c=N(t.latitudeAccessor,"lat"),u=N(t.kindAccessor,"kind"),d=t.candidatePriorityAccessor?N(t.candidatePriorityAccessor,"priority"):()=>0,h=new Map,f=null;for(let m of e){let e=Number(s(m)),p=Number(c(m));if(!Number.isFinite(e)||!Number.isFinite(p))continue;let g=(a(m)??`${e},${p}`)+"",y=(l(m)??g)+"",x=E(u(m)),[b,M]=z(e,p,t.center);if(Math.abs(b)>n||Math.abs(M)>n)continue;let w=Math.min(r-1,Math.max(0,Math.floor((b+n)/o))),v=Math.min(r-1,Math.max(0,Math.floor((n-M)/o))),k=(w+.5)*o-n,$=n-(v+.5)*o,A={...m,id:g,name:y,kind:x,lon:e,lat:p,distanceKm:Math.sqrt(b*b+M*M),row:v,column:w,cellDistanceSq:(b-k)**2+(M-$)**2,candidatePriority:Number(d(m))||0};(null!=t.centerId&&g===t.centerId||!f&&"city"===x||!f&&v===i&&w===i)&&(f=A);let S=`${v}:${w}`,I=h.get(S)??[];I.push(A),h.set(S,I)}let m=new Map;f&&m.set("city",1);let p=[];for(let e=0;r>e;e++)for(let t=0;r>t;t++){let r,a,l=`tile-${e}-${t}`,s=(t+.5)*o-n,c=n-(e+.5)*o;if(e===i&&t===i&&f){r=f;let n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id).sort((e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||e.name.localeCompare(t.name));a=[f,...n]}else{let n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id);n.sort((e,t)=>{let r=e.candidatePriority-t.candidatePriority;if(0!==r)return r;let n=m.get(e.kind)??0,i=m.get(t.kind)??0,a=o*o*.35;return e.cellDistanceSq+n*a-(t.cellDistanceSq+i*a)||e.name.localeCompare(t.name)}),r=n[0]??null,a=n}r&&m.set(r.kind,(m.get(r.kind)??0)+1),p.push({id:l,row:e,column:t,centerXKm:s,centerYKm:c,terrainIndex:Math.abs((17*e+31*t)%ia.length),landmark:r,landmarks:a})}return p}function O({tiles:e,tileWidth:t,tileHeight:r,sprites:n,resourceSize:o,citySize:i,showCityLabel:a}){let l=Ei(),s=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return na("g",{"aria-hidden":"true",pointerEvents:"none",children:[s.map(e=>{let a=e.landmark,s="city"===a.kind?i:o,c=e.y+r/2,u=l.isActive&&!l.predicate(a)?.28:1;return na("g",{opacity:u,children:[ra("ellipse",{cx:e.x,cy:e.y+.15*r,rx:.28*s,ry:.1*s,fill:"#17251d",opacity:.32}),ra(W,{kind:a.kind,href:C(n,a.kind),x:e.x-s/2,y:c-s,size:s}),e.landmarks.length>1&&ra(R,{x:e.x+.3*t,y:e.y-.19*r,count:e.landmarks.length-1,tileHeight:r})]},a.id)}),a&&s.filter(e=>"city"===e.landmark?.kind).map(e=>{let t=e.landmark.name.toUpperCase(),n=Math.max(56,6.4*t.length+14);return na("g",{transform:`translate(${e.x},${e.y+.72*r})`,children:[ra("rect",{x:-n/2,y:-7,width:n,height:14,rx:1,fill:"#17251d",opacity:.92}),ra("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},e.landmark.id+"-label")})]})}function R({x:e,y:t,count:r,tileHeight:n}){let o=Math.max(10,Math.min(15,.34*n)),i="+"+r,a=Math.max(o,i.length*o*.58);return na("g",{transform:`translate(${e},${t})`,children:[ra("rect",{x:-a/2,y:-o/2,width:a,height:o,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),ra("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*o),fontWeight:700,children:i})]})}function W({kind:e,href:t,x:r,y:n,size:o}){if(t)return ra("image",{href:t,x:r,y:n,width:o,height:o,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});let i=ha[e];return ra("svg",{x:r,y:n,width:o,height:o,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:da[e].flatMap((e,t)=>[...e].map((e,r)=>"."===e?null:ra("rect",{x:r,y:t,width:1,height:1,fill:i[e]},`${t}-${r}`)))})}function L(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function T(e,t,r){return Math.max(t,Math.min(r,e))}function P(e){let t=1/0,r=-1/0;for(let n of e)Number.isFinite(n)&&(t>n&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}function q(e,t){let r=t[1]-t[0];return 0===r?.5:(e-t[0])/r}function D(e,t={}){let r=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===r.length)return[];let n=T(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),o=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8,i=L(t.columns)??Math.max(1,Math.ceil(Math.sqrt(r.length*o/n))),a=L(t.rows)??Math.max(1,Math.ceil(r.length/(i*n)));r.length>i*a&&(null!=t.columns&&null==t.rows?a=Math.ceil(r.length/i):null!=t.rows&&null==t.columns?i=Math.ceil(r.length/a):a=Math.ceil(r.length/i));let l=P(r.map(e=>e.x)),s=P(r.map(e=>e.y)),c=r.map(e=>({...e,desiredColumn:q(e.x,l)*Math.max(0,i-1),desiredRow:q(e.y,s)*Math.max(0,a-1)})),u=(i-1)/2,d=(a-1)/2;c.sort((e,t)=>(t.desiredColumn-u)**2+(t.desiredRow-d)**2-((e.desiredColumn-u)**2+(e.desiredRow-d)**2)||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index);let h=new Set;for(let e=0;a>e;e+=1)for(let t=0;i>t;t+=1)h.add(e*i+t);let f=[];for(let e of c){let t=-1,r=1/0;for(let n of h){let o=(n%i-e.desiredColumn)**2+(Math.floor(n/i)-e.desiredRow)**2;(r>o||o===r&&t>n)&&(t=n,r=o)}0>t||(h.delete(t),f.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/i),column:t%i,index:e.index}))}return f.sort((e,t)=>e.index-t.index),f.map(({index:e,...t})=>t)}function V(e,t,r=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(let t of r)if(null!=e[t])return e[t]}function B(e){return e.map(([e,t],r)=>`${0===r?"M":"L"}${e},${t}`).join("")+"Z"}function H(e,t,r){let n=[];for(let o=0;6>o;o+=1){let i=-Math.PI/2+o*(Math.PI/3);n.push([e+Math.cos(i)*r,t+Math.sin(i)*r])}return B(n)}function Y({marks:e,color:t,fontSize:r,fontFamily:n,fontWeight:o}){let i=Ei();return fa("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{let a=!i.isActive||i.predicate(e.datum);return fa("text",{x:e.x,y:e.y,fill:t,fontFamily:n,fontSize:r,fontWeight:o,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}function G(e,t,r){return Math.max(t,Math.min(r,e))}function _(e){if(Number.isFinite(e)&&Number(e)>0)return Number(e)}function X(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function K(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function U(e,t){let r=K(e);return(e.id??r.id??r.name??"feature-"+t)+""}function Q(e,t,r,n){return[Math.ceil((e-r)/n-.5),Math.floor((t-r)/n-.5)]}function Z(e){if(!e)return 0;let t=Ma.get(e);if(t)return t;let r=wa;return wa+=1,Ma.set(e,r),r}function J(e,t){return!t||!(t[0][1]>e[1]||e[1]>t[1][1]||(r=e[0],n=t[0][0],o=t[1][0],n>o?n>r&&r>o:n>r||r>o));var r,n,o}function ee(e,t){for(let r of e){let{feature:e,index:n}=r;if(e.geometry&&J(t,r.bounds))try{if(ga(e,t))return{feature:e,index:n}}catch{}}return null}function te(e,t,r,n={}){let o=e.filter((e,t)=>e.geometry&&(!n.featureFilter||n.featureFilter(e,t))),i=function(e,t){if(0===e.length)return null;let r=t.bounds({type:"FeatureCollection",features:e});return Number.isFinite(r[0][0])&&Number.isFinite(r[0][1])&&Number.isFinite(r[1][0])&&Number.isFinite(r[1][1])?r:null}(o,t.geoPath);if(!i)return{dots:[],cellSize:10,features:o};let a=Math.max(0,n.layoutPadding??0),l=[[G(i[0][0],a,Math.max(a,r.width-a)),G(i[0][1],a,Math.max(a,r.height-a))],[G(i[1][0],a,Math.max(a,r.width-a)),G(i[1][1],a,Math.max(a,r.height-a))]],s=Math.max(0,l[1][0]-l[0][0]),c=Math.max(0,l[1][1]-l[0][1]);if(0===s||0===c)return{dots:[],cellSize:10,features:o};let u=_(n.columns),d=Math.max(2,u?s/u:_(n.cellSize)??10),h=Math.max(100,Math.round(_(n.maxSamples)??25e3)),f=Math.ceil(s/d)*Math.ceil(c/d);f>h&&(d*=Math.sqrt(f/h));let m=n.gridOrigin?.[0]??0,p=n.gridOrigin?.[1]??0,[g,y]=Q(l[0][0],l[1][0],m,d),[x,b]=Q(l[0][1],l[1][1],p,d),M=[],w=function(e){return e.map((e,t)=>{if(ba.has(e))return{feature:e,index:t,bounds:ba.get(e)??null};try{let r=pa(e);return ba.set(e,r),{feature:e,index:t,bounds:r}}catch{return ba.set(e,null),{feature:e,index:t,bounds:null}}})}(o);for(let e=x;b>=e;e+=1){let r=p+(e+.5)*d;for(let o=g;y>=o;o+=1){let i=t.invertedPoint(m+(o+.5)*d,r);if(!i||!Number.isFinite(i[0])||!Number.isFinite(i[1]))continue;let a=ee(w,i);if(!a)continue;let l={...K(a.feature),featureId:U(a.feature,a.index),featureIndex:a.index,gridRow:e,gridColumn:o,longitude:i[0],latitude:i[1],dotIndex:M.length};n.dotFilter&&!n.dotFilter(l,M.length)||M.push(l)}}return{dots:M,cellSize:d,features:o}}function re(e){return Math.round(1e4*e)/1e4}function ne(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${re(Number(e[0]))},${re(Number(e[1]))}`:"null"}function oe(e,t){let r=e[t];return"function"==typeof r?r.call(e):void 0}function ie(e){return"number"==typeof e&&Number.isFinite(e)?re(e)+"":null===e?"null":"unavailable"}function ae(e){let t=e.scales.projection;return[ie(oe(t,"scale")),ne(oe(t,"translate")),ne(oe(t,"center")),(r=oe(t,"rotate"),Array.isArray(r)&&r.every(Number.isFinite)?r.map(e=>re(Number(e))).join(","):"unavailable"),ie(oe(t,"clipAngle")),ie(oe(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,r])=>ne(e.scales.projectedPoint(t,r)))].join("|");var r}function le(e){return e.map(([e,t],r)=>`${0===r?"M":"L"}${e},${t}`).join("")+"Z"}function se(e,t,r){return le([[e-r,t-r],[e+r,t-r],[e+r,t+r],[e-r,t+r]])}function ce(e,t,r){return le(Array.from({length:6},(n,o)=>{let i=-Math.PI/2+o*(Math.PI/3);return[e+Math.cos(i)*r,t+Math.sin(i)*r]}))}function ue(e,t){let r="function"==typeof t?t(e):e[t];return Sa(r)?r:void 0}function de(e){return[...e].sort((e,t)=>e.localeCompare(t))}function he(e,t,r){let n=new Map([[e,0]]),o=[e];for(;o.length>0;){let e=o.shift(),i=n.get(e);for(let a of de(r.get(e)??[]))!t.has(a)||n.has(a)||(n.set(a,i+1),o.push(a))}return n}function fe(e,t,r){return[...he(e,t,r).entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))[0][0]}function me(e,t,r){let n=new Set(e),o=e.filter(e=>1>=(t.get(e)?.size??0))[0]??e[0],i=he(r&&n.has(r)?r:fe(fe(o,n,t),n,t),n,t),a=Math.max(0,...i.values()),l=Array.from({length:a+1},()=>[]);for(let t of e)l[i.get(t)??0].push(t);l.forEach(e=>e.sort((e,t)=>e.localeCompare(t)));let s=(e,r)=>{let n=new Map(l[r].map((e,t)=>[e,t])),o=e=>{let r=[...t.get(e)??[]].map(e=>n.get(e)).filter(e=>null!=e);return 0===r.length?1/0:r.reduce((e,t)=>e+t,0)/r.length};l[e].sort((e,t)=>o(e)-o(t)||e.localeCompare(t))};for(let e=0;4>e;e+=1){for(let e=1;l.length>e;e+=1)s(e,e-1);for(let e=l.length-2;e>=0;e-=1)s(e,e+1)}return l}function pe(e,t,r,n={}){let o=Math.max(0,n.padding??36),i=Math.max(0,n.componentGap??26),a=n.xAccessor??"x",l=n.yAccessor??"y",s=e.map(e=>({...e,authoredX:ue(e.data,a),authoredY:ue(e.data,l)})),c=s.length>0&&s.every(e=>Sa(e.authoredX)&&Sa(e.authoredY)),u="authored"===n.layoutMode||"automatic"!==n.layoutMode&&c,d=[];if(u&&!c&&d.push("Authored transit layout requested, but at least one station has no finite x/y position; using automatic topology layout."),!u||!c){!c&&"automatic"!==n.layoutMode&&d.push("Complete station positions were not supplied; using the deterministic automatic topology layout.");let a=function(e,t,r,n,o,i){let a=function(e,t){let r=new Map(e.map(e=>[e,new Set]));for(let e of t)!r.has(e.source)||!r.has(e.target)||(r.get(e.source)?.add(e.target),r.get(e.target)?.add(e.source));return r}(e.map(e=>e.id),t),l=function(e){let t=new Set(e.keys()),r=[];for(;t.size>0;){let n=de(t)[0],o=[n],i=[];for(t.delete(n);o.length>0;){let r=o.shift();i.push(r);for(let n of de(e.get(r)??[]))t.has(n)&&(t.delete(n),o.push(n))}r.push(i.sort((e,t)=>e.localeCompare(t)))}return r.sort((e,t)=>t.length-e.length||e[0].localeCompare(t[0]))}(a),s=new Map(e.map(e=>[e.id,e.data])),c=new Map,u=Math.max(0,r.width),d=Math.max(0,r.height),h=Math.min(n,u/2),f=Math.min(n,d/2),m=Math.max(0,d-2*f),p=l.length>1?Math.min(o,m/l.length):0,g=Math.max(0,m-p*Math.max(0,l.length-1)),y=l.reduce((e,t)=>e+Math.sqrt(t.length),0),x=f;for(let e of l){let t=g*(Math.sqrt(e.length)/y),r=me(e,a,i),n=Math.max(0,u-2*h);r.forEach((e,o)=>{let i=1===r.length?u/2:h+o/(r.length-1)*n;e.forEach((r,n)=>{c.set(r,{id:r,x:i,y:1===e.length?x+t/2:x+n/(e.length-1)*t,data:s.get(r)})})}),x+=t+p}return c}(e,t,r,o,i,n.rootId);if("right-to-left"===n.direction)for(let e of a.values())e.x=r.width-e.x;return{positions:a,mode:"automatic",warnings:d,projectAuthoredPoint:e=>e}}let h=s.map(e=>e.authoredX),f=s.map(e=>e.authoredY),m=Math.min(...h),p=Math.max(...h),g=Math.min(...f),y=Math.max(...f),x=Math.max(1,r.width-2*o),b=Math.max(1,r.height-2*o),M=e=>({x:p===m?r.width/2:o+(e.x-m)/(p-m)*x,y:y===g?r.height/2:o+(e.y-g)/(y-g)*b}),w=new Map;for(let e of s){let t=M({x:e.authoredX,y:e.authoredY});w.set(e.id,{id:e.id,...t,data:e.data})}return{positions:w,mode:"authored",warnings:d,projectAuthoredPoint:M}}function ge(e,t){let r=t.x-e.x,n=t.y-e.y,o=Math.abs(r),i=Math.abs(n);if(.001>o||.001>i||.001>Math.abs(o-i))return[e,t];let a=Math.sign(r),l=Math.sign(n);if(o>i){let r=(o-i)/2;return[e,{x:e.x+a*r,y:e.y},{x:t.x-a*r,y:t.y},t]}let s=(i-o)/2;return[e,{x:e.x,y:e.y+l*s},{x:t.x,y:t.y-l*s},t]}function ye(e,t){if(0===t||2>e.length)return e.map(e=>({...e}));let r=(e,t)=>{let r=t.x-e.x,n=t.y-e.y,o=Math.hypot(r,n)||1;return{x:-n/o,y:r/o}};return e.map((n,o)=>{let i=o>0?r(e[o-1],n):null,a=e.length-1>o?r(n,e[o+1]):null;if(!i||!a){let e=a??i??{x:0,y:0};return{x:n.x+e.x*t,y:n.y+e.y*t}}let l=i.x+a.x,s=i.y+a.y,c=Math.hypot(l,s);if(.001>c)return{x:n.x+a.x*t,y:n.y+a.y*t};l/=c,s/=c;let u=l*a.x+s*a.y;if(.001>Math.abs(u))return{x:n.x+a.x*t,y:n.y+a.y*t};let d=4*Math.abs(t),h=Math.max(-d,Math.min(d,t/u));return{x:n.x+l*h,y:n.y+s*h}})}function xe(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let r=Math.max(0,t),n=`M${e[0].x},${e[0].y}`;for(let t=1;e.length-1>t;t+=1){let o=e[t-1],i=e[t],a=e[t+1],l=Math.hypot(i.x-o.x,i.y-o.y),s=Math.hypot(a.x-i.x,a.y-i.y),c=Math.min(r,l/2,s/2);if(.001>=c){n+=` L${i.x},${i.y}`;continue}let u={x:i.x+(o.x-i.x)/l*c,y:i.y+(o.y-i.y)/l*c},d={x:i.x+(a.x-i.x)/s*c,y:i.y+(a.y-i.y)/s*c};n+=` L${u.x},${u.y} Q${i.x},${i.y} ${d.x},${d.y}`}let o=e[e.length-1];return`${n} L${o.x},${o.y}`}function be(e){return Fi(e)??e}function Me(e){return"string"==typeof e?e:e.id}function we(e,t){let r,n=t.lineAccessor;return r="function"==typeof n?n(e.data):"string"==typeof n?e.data[n]:e.data.lines??e.data.line??e.data.route??e.data.group,function(e){let t=(Array.isArray(e)?e:null==e?[]:[e]).map(e=>"object"==typeof e?{...e,id:e.id+""}:{id:e+""});return t.length>0?t:[{id:"network"}]}(r)}function ve(e,t,r){let n=t.sourceColorAccessor,o="function"==typeof n?n(e.data):"string"==typeof n?e.data[n]:e.data.color;return"string"==typeof o&&o?o:r(e.id)}function ke(e,t,r,n){if(e.color)return e.color;let o=r.lineColors&&Object.prototype.hasOwnProperty.call(r.lineColors,e.id)?r.lineColors[e.id]:void 0;if("string"==typeof o&&o)return o;let i=r.lineColorAccessor,a="function"==typeof i?i(t.data):"string"==typeof i?t.data[i]:t.data.color;return"string"==typeof a?a:n(e.id)}function $e(e,t){let r=new Map((t.lineOrder??[]).map((e,t)=>[e,t]));return[...e].sort((e,t)=>(r.get(e)??1/0)-(r.get(t)??1/0)||e.localeCompare(t))}function Ae(e,t){let r=new Map((e.authoredOrder??t.lineOrder??[]).map((e,t)=>[e,t]));return[...e.lines.values()].sort((e,t)=>(r.get(e.descriptor.id)??1/0)-(r.get(t.descriptor.id)??1/0)||e.descriptor.id.localeCompare(t.descriptor.id))}function Se(e,t,r,n){if("authored"!==t.mode)return null;let o=e.data[r.pointsAccessor??"points"];if(!Array.isArray(o))return null;let i=o.map(e=>"number"==typeof e.x&&"number"==typeof e.y?t.projectAuthoredPoint({x:e.x,y:e.y}):null).filter(e=>null!=e);return 0===i.length?null:n?i.reverse():i}function Ie(e,t){return qo(r=>{for(let[t,n]of Object.entries(e.data))r(t,n);r("source",e.source),r("target",e.target),r("lineId",t.id),r("lineLabel",t.label??t.id)})}function Ce(e,t,r,n,o,i){if(!1===i.showLabels)return[];let a=i.labelFontSize??11,l=[],s=[],c=[...e].sort((e,t)=>(r.get(t.id)?.size??0)-(r.get(e.id)?.size??0)||e.id.localeCompare(t.id));for(let e of c){let r=t.get(e.id);if(!r)continue;let c=("function"==typeof i.labelAccessor?i.labelAccessor(e.data):xi(e.data,i.labelAccessor??"label",e.id)+"")||e.id,u=Math.max(2*a,c.length*a*.58),d=1.25*a,h=Math.max(i.interchangeRadius??7,n.get(e.id)??i.stationRadius??4)+5,f=[{x:r.x+h,y:r.y,anchor:"start",left:r.x+h},{x:r.x-h,y:r.y,anchor:"end",left:r.x-h-u},{x:r.x,y:r.y-h,anchor:"middle",left:r.x-u/2},{x:r.x,y:r.y+h,anchor:"middle",left:r.x-u/2}].map((e,t)=>{let r={left:e.left,right:e.left+u,top:e.y-d/2,bottom:e.y+d/2},n=l.filter(e=>{return(n=e).right>(t=r).left&&t.right>n.left&&n.bottom>t.top&&t.bottom>n.top;var t,n}).length;return{candidate:e,box:r,score:1e4*n+10*(Math.max(0,-r.left)+Math.max(0,r.right-o.width)+Math.max(0,-r.top)+Math.max(0,r.bottom-o.height))+t}}).sort((e,t)=>e.score-t.score)[0];l.push(f.box),s.push({x:f.candidate.x,y:f.candidate.y,text:c,anchor:f.candidate.anchor,baseline:"middle",fontSize:a,fill:i.labelColor??"var(--semiotic-text, #222)",stroke:"var(--semiotic-bg, white)",strokeWidth:3,paintOrder:"stroke"})}return s}function Ne(e,t,r){return(t.x-e.x)*(r.y-e.y)-(t.y-e.y)*(r.x-e.x)}function ze(e){return(1e-12>Math.abs(e)?0:e)+""}function Fe(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:(e.storeName??"")+"",slotIndex:e.slotIndex??t}):[]}function Ee(e,t){return Number.isFinite(e)?Wo(e,0,1):t}function je(e,t){return e.length>t?e.slice(0,Math.max(1,t-1))+"…":e}function Oe(e,t,r,n,o,i,a,l){let s=t-n/2,c=r-o/2,u={fill:i,stroke:a,strokeWidth:l};switch(e){case"diamond":return Ra("polygon",{points:`${t},${c} ${t+n/2},${r} ${t},${r+o/2} ${s},${r}`,...u});case"circle":return Ra("circle",{cx:t,cy:r,r:Math.min(n,o)/2,...u});case"stadium":case"round":return Ra("rect",{x:s,y:c,width:n,height:o,rx:"stadium"===e?o/2:8,ry:"stadium"===e?o/2:8,...u});case"hexagon":{let e=Math.min(.18*n,16);return Ra("polygon",{points:`${s+e},${c} ${t+n/2-e},${c} ${t+n/2},${r} ${t+n/2-e},${r+o/2} ${s+e},${r+o/2} ${s},${r}`,...u})}case"cylinder":{let e=Math.min(.16*o,8),t=`M${s},${c+e} a${n/2},${e} 0 0 1 ${n},0`;return Wa("g",{children:[Ra("path",{d:`M${s},${c+e} a${n/2},${e} 0 0 0 ${n},0 v${o-2*e} a${n/2},${e} 0 0 1 ${-n},0 z`,...u}),Ra("path",{d:t,fill:"none",stroke:a,strokeWidth:l})]})}case"subroutine":{let e=Math.min(8,.08*n);return Wa("g",{children:[Ra("rect",{x:s,y:c,width:n,height:o,rx:3,...u}),Ra("line",{x1:s+e,y1:c,x2:s+e,y2:c+o,stroke:a,strokeWidth:l}),Ra("line",{x1:s+n-e,y1:c,x2:s+n-e,y2:c+o,stroke:a,strokeWidth:l})]})}default:return Ra("rect",{x:s,y:c,width:n,height:o,rx:4,...u})}}function Re(e,t,r={}){let n=r.fingerprintRounds??3,o=[],i=new Set;for(let t of e)null==t.id||i.has(t.id)||(i.add(t.id),o.push(t.id));let{outAdj:a,inAdj:l,undirected:s}=De(o,t),c=Ve(o,a,l,s,n).map(e=>({ids:e.ids,nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:qe(e)})),u=new Map;for(let e of c){let t=u.get(e.motif);t?t.count+=1:u.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:c,motifs:[...u.values()].sort((e,t)=>t.count-e.count),directedCount:c.filter(e=>e.directed).length,branchingCount:c.filter(e=>!e.directed).length}}function We(e){let t=2166136261;for(let r=0;e.length>r;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function Le(e){return"string"==typeof e?e:e?.id}function Te(e,t,r,n,o){let i=new Set(e),a=new Map;for(let n of e){let e=0,o=0;for(let e of t.get(n)??[])i.has(e)&&(o+=1);for(let t of r.get(n)??[])i.has(t)&&(e+=1);a.set(n,`${e}:${o}`)}for(let n=0;o>n;n+=1){let n=new Map;for(let o of e){let e=[];for(let r of t.get(o)??[])i.has(r)&&e.push(a.get(r));let l=[];for(let e of r.get(o)??[])i.has(e)&&l.push(a.get(e));e.sort(),l.sort(),n.set(o,We(`${a.get(o)}>${e.join(",")}<${l.join(",")}`))}a=n}let l=e.map(e=>a.get(e)).sort();return We(`${e.length}#${n}#${l.join(";")}`)}function Pe(e,t,r,n,o,i,a){function l(e){let t=0,r=0;for(let n of o.get(e)??[]){let e=m.get(n);p.has(n)&&e&&(t+=e.x,r+=1)}return r>0?t/r:i.x+h/2}let{layer:s,layerCount:c}=function(e,t){let r=new Set(e),n=new Map,o=new Set,i=e=>{let a=n.get(e);if(void 0!==a)return a;if(o.has(e))return 0;o.add(e);let l=0;for(let n of t.get(e)??[])r.has(n)&&(l=Math.max(l,1+i(n)));return o.delete(e),n.set(e,l),l},a=0;for(let t of e)a=Math.max(a,i(t));let l=new Map;for(let t of e)l.set(t,a-n.get(t));return{layer:l,layerCount:a+1}}(e.ids,n),u=Array.from({length:c},()=>[]);for(let t of e.ids)u[s.get(t)].push(t);let d=.14*Math.min(i.width,i.height),h=Math.max(1,i.width-2*d),f=Math.max(1,i.height-2*d),m=new Map,p=new Set(e.ids);for(let e=0;c>e;e+=1){let t=u[e];e>0&&(t=[...t].sort((e,t)=>l(e)-l(t)));let r=t.length,n=i.y+d+(1===c?.5:e/(c-1))*f;t.forEach((e,t)=>{m.set(e,{x:i.x+d+(1===r?.5:t/(r-1))*h,y:n})})}let g=u.reduce((e,t)=>Math.max(e,t.length),1),y=Wo(Math.min(a,h/(2.4*g),f/(2.4*c)),1.4,a),x=e.ids.map(e=>{let n=m.get(e);return{id:e,cx:n.x,cy:n.y,r:y,datum:t.get(e)??Do({id:e}),category:r.get(e)??""}}),b=[];for(let t of e.ids){let e=m.get(t);for(let r of n.get(t)??[]){if(!p.has(r))continue;let t=m.get(r);b.push({x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:x,edges:b}}function qe(e){let{nodeCount:t,edgeCount:r,sinkCount:n,sourceCount:o}=e;return 1===t?"isolate":2===t&&1===r?"pair":1===o&&1===n&&r===t-1?"chain of "+t:e.directed&&1===o&&r>t-1?"diamond / mesh":e.directed?`converging (${t})`:"branching → "+n}function De(e,t){let r=new Set(e),n=new Map,o=new Map,i=new Map;for(let t of e)n.set(t,new Set),o.set(t,new Set),i.set(t,new Set);for(let e of t){let t=e.source,a=e.target;!r.has(t)||!r.has(a)||t===a||n.get(t).has(a)||(n.get(t).add(a),o.get(a).add(t),i.get(t).add(a),i.get(a).add(t))}return{outAdj:n,inAdj:o,undirected:i}}function Ve(e,t,r,n,o){let i=new Set,a=[];for(let l of e){if(i.has(l))continue;let e=[l];i.add(l);let s=[];for(;e.length;){let t=e.pop();s.push(t);for(let r of n.get(t)??[])i.has(r)||(i.add(r),e.push(r))}let c=new Set(s),u=0,d=0,h=0;for(let e of s){let n=0,o=0;for(let r of t.get(e)??[])c.has(r)&&(n+=1);for(let t of r.get(e)??[])c.has(t)&&(o+=1);h+=n,0===n&&(u+=1),0===o&&(d+=1)}a.push({ids:s,nodeCount:s.length,edgeCount:h,sinkCount:u,sourceCount:d,directed:1===u,motif:Te(s,t,r,h,o)})}return a}function Be(e,t,r){return e?Pe(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,r,3):null}function He(e){return Fi(e)??e}function Ye(e){return"string"==typeof e?e:e.id}function Ge(e,t){let r=Number(e);return Number.isFinite(r)&&r>0?r:t}function _e(e){return Math.round(100*e)/100+""}function Xe(e,t){if(2>e.length)return"";let r=`M${_e(e[0][0])},${_e(e[0][1])}`;for(let n=1;e.length-1>n;n+=1){let o=e[n-1],i=e[n],a=e[n+1],l=Math.hypot(i[0]-o[0],i[1]-o[1]),s=Math.hypot(a[0]-i[0],a[1]-i[1]),c=Math.min(t,l/2,s/2);if(0>=c){r+=`L${_e(i[0])},${_e(i[1])}`;continue}let u=[(i[0]-o[0])/l,(i[1]-o[1])/l],d=[(a[0]-i[0])/s,(a[1]-i[1])/s],h=[i[0]-u[0]*c,i[1]-u[1]*c],f=[i[0]+d[0]*c,i[1]+d[1]*c];r+=`L${_e(h[0])},${_e(h[1])}Q${_e(i[0])},${_e(i[1])} ${_e(f[0])},${_e(f[1])}`}let n=e[e.length-1];return`${r}L${_e(n[0])},${_e(n[1])}`}function Ke(e,t,r,n,o=.92*n){let i=Math.cos(r),a=Math.sin(r),l=-a,s=[e+i*n*.56,t+a*n*.56],c=e-i*n*.44,u=t-a*n*.44,d=[c+l*o*.5,u+i*o*.5],h=[c-l*o*.5,u-i*o*.5];return`M${_e(s[0])},${_e(s[1])}L${_e(d[0])},${_e(d[1])}L${_e(h[0])},${_e(h[1])}Z`}function Ue(e,t){return`${t}\0${e}`}function Qe(e,t){return Math.max(1,e-2*Math.max(0,t.portPadding??4))}function Ze(e,t,r){if(1>=e)return 0;let n=Math.max(0,r.flowGap??.75),o=Qe(t,r);return Math.min(n,Math.max(0,(o-Math.min(.1,o))/(e-1)))}function Je(e,t,r){let n="function"==typeof t?t(e):xi(e,t,r);return null==n||""===n?r:n+""}function et(e,t){let r="function"==typeof t?t(e):xi(e,t,void 0);if(null!=r){if("object"==typeof r){let e=r.id;return null==e?void 0:e+""}return r+""}}function tt(e,t){let r="function"==typeof t?t(e):xi(e,t,1);return Number(r)}function rt(e,t){if(!t.has(e))return t.add(e),e;let r=2;for(;t.has(`${e}-${r}`);)r+=1;let n=`${e}-${r}`;return t.add(n),n}function nt(e,t,r={}){let n=r.nodeIdAccessor??"id",o=r.groupAccessor??"group",i=r.labelAccessor??"label",a=r.sourceAccessor??"source",l=r.targetAccessor??"target",s=r.valueAccessor??"value",c=new Set(r.expandedGroups??[]),u=r.includeInternalFlows??!0,d=[],h=new Map,f=new Map;for(let t of e){let e=Je(t,n,d.length+"");if(h.has(e))continue;let r=Je(t,i,e),a=Je(t,o,e),l={id:e,label:r,group:a,datum:t};d.push(l),h.set(e,l);let s=f.get(a);s?s.push(l):f.set(a,[l])}let m=new Set(d.map(e=>e.id)),p=[],g=new Map,y=new Map,x=[];for(let[e,t]of f){if(!c.has(e)&&(!0===r.collapseSingletons||t.length>1)){let n=rt(`${r.groupIdPrefix??"group:"}${e}`,m),o={id:n,label:e,group:e,aggregate:!0,memberIds:t.map(e=>e.id),memberCount:t.length,internalValue:0,incomingValue:0,outgoingValue:0};p.push(o),g.set(n,o);for(let e of t)y.set(e.id,n);x.push({group:e,nodeId:n,label:e,collapsed:!0,memberIds:[...o.memberIds],internalValue:0,incomingValue:0,outgoingValue:0});continue}for(let r of t){let t={...r.datum,id:r.id,label:r.label,group:e,aggregate:!1,memberIds:[r.id],memberCount:1,internalValue:0,incomingValue:0,outgoingValue:0};p.push(t),g.set(t.id,t),y.set(r.id,t.id)}x.push({group:e,nodeId:null,label:e,collapsed:!1,memberIds:t.map(e=>e.id),internalValue:0,incomingValue:0,outgoingValue:0})}let b=new Map(x.map(e=>[e.group,e])),M=new Map,w=0;for(let e of t){let t=et(e,a),r=et(e,l),n=tt(e,s),o=null==t?void 0:y.get(t),i=null==r?void 0:y.get(r);if(!(o&&i&&Number.isFinite(n)&&n>0)){w+=1;continue}let c=h.get(t)?.group,u=h.get(r)?.group;if(c&&u&&c===u){let e=b.get(c);e&&(e.internalValue+=n)}else{if(c){let e=b.get(c);e&&(e.outgoingValue+=n)}if(u){let e=b.get(u);e&&(e.incomingValue+=n)}}let d=M.get(o);d||(d=new Map,M.set(o,d));let f=d.get(i);f?(f.value+=n,f.edgeCount+=1,f.memberEdges.push(e)):d.set(i,{source:o,target:i,value:n,edgeCount:1,internal:o===i,memberEdges:[e]})}let v=[...M.values()].flatMap(e=>[...e.values()]);for(let e of v){let t=g.get(e.source),r=g.get(e.target);e.internal?t&&(t.internalValue+=e.value):(t&&(t.outgoingValue+=e.value),r&&(r.incomingValue+=e.value))}return{nodes:p,edges:u?v:v.filter(e=>!e.internal),groups:x,omittedEdgeCount:w}}function ot(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();let t=e+"",r=Number(t);if(!Number.isNaN(r)&&""!==t.trim())return r;let n=Date.parse(t);return Number.isNaN(n)?NaN:n}function it(e,t,r){return t>e?t:e>r?r:e}function at(e){let t=2166136261,r=e=>{for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619)};for(let n of e)r(n.id),r(n.col),r(n.row),t^=Math.round(8*n.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function lt(e,t,r){let n=new Set,o=[];for(let t of e)r(t)&&!n.has(t)&&(n.add(t),o.push(t));for(let e of t)n.has(e)||o.push(e);return o}function st(e,t){return e.topRadius+(t-e.height)/e.height*(e.topRadius-e.bottomRadius)}function ct(e,t){return function(e,t,r){return Math.PI*r/3*(e*e+e*t+t*t)}(st(e,t),e.bottomRadius,t)}function ut(e,t){let r=(e.topRadius+e.bottomRadius)/2,n=Math.PI*r*r,o=t/n,i=t-ct(e,o),a=0;for(;100>a&&Math.abs(i)>1e-4;)o+=i/n,i=t-ct(e,o),a++;return o}function dt(e,t){let r=43758.5453*Math.sin(12.9898*e+78.233);return 2*(r-Math.floor(r)-.5)*t}function ht(e,t){if(t>e||2*t>e)return[{x:0,y:0}];let r=[],n=e=>{let o=Math.floor(2*Math.PI*e/(2*t));1>o&&(o=1);let i=0*e;Math.hypot(1*e-e*Math.cos(2*Math.PI/o),i-e*Math.sin(2*Math.PI/o))<2*t&&o>1&&o--;for(let t=0;o>t;t++)r.push({x:e*Math.cos(2*t*Math.PI/o),y:e*Math.sin(2*t*Math.PI/o)});let a=e-2*t;t>a?e>2*t&&r.push({x:0,y:0}):n(a)};return n(e-t),r}function ft(e,t,r){let n=[],o=r,i=0;for(;o>0&&60>i;){let r=t*(1+2*i),a=ht(st(e,r),t),l=a.length-o,s=l>1?a.slice(Math.floor(l/2),Math.floor(l/2)+o):a,c=e.height-r;if(s.forEach((e,t)=>{n.push({x:e.x+dt(97*i+t,.15),z:c+dt(31*i+t,.05)})}),o-=s.length,i++,0===s.length)break}return{pearls:n,layers:i}}function mt(e,t,r,n){if(0>=n)return[];let o=function(e,t,r){let n=r,o=0;for(;n>0&&60>o;){let r=st(e,t+.875*(1+2*o));n-=Math.max(1,Math.floor(2*r/rl)),o++}return o}(e,t,n),i=Math.max(t,r-o*rl)+.875,a=[],l=0;for(let t=0;o>t&&n>l;t++){let r=i+rl*t,o=st(e,r),s=Math.max(1,Math.floor(2*o/rl)),c=(2*o-s*rl)/(s+1),u=-o+c,d=e.height-r-.875-.1;for(let e=0;s>e&&n>l;e++)a.push({cx:u+(c+rl)*e+.875,cy:d+.875,rotation:dt(53*t+e,10)}),l++}return a}function pt(e,t){let r=Number(e);return Number.isFinite(r)?r:t}function gt(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function yt(e,t={}){let r=t.fuels??il,n=!0===t.includeZero,o=[];for(let t of e)if(t&&"number"==typeof t.t)for(let e of r){let r=gt(t.fuels?.[e]);!n&&0>=r||o.push({t:t.t,fuel:e,fuelLabel:al[e],mw:r,ba:t.ba})}return o}function xt(e){let t=[];for(let r of e){if(!r||"number"!=typeof r.t)continue;let e=gt(r.demandMw),n=r.forecastMw;"number"!=typeof n||!Number.isFinite(n)||t.push({t:r.t,a:e,b:n,demandMw:e,forecastMw:n,errorMw:e-n,ba:r.ba})}return t}function bt(e){let t=gt(e.demand);if(0>=t)return 0;let r=gt(e.capacityOrNetGen),n=gt(e.interchange);return(r+(0>n?-n:0)-t)/t*100}function Mt(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{let t=gt(e.demandMw),r=gt(e.netGenMw),n=bt({demand:t,capacityOrNetGen:r,interchange:e.interchangeMw});return{t:e.t,ba:e.ba,reserveMarginPct:n,netLoadMw:t,demandMw:t,netGenMw:r}})}function wt(e={},t={}){let{watch:r,comfortable:n}={...ll,...e},o=t.field,i=o?{field:o}:{},a=t.tightHatch??{type:"hatch",background:"var(--semiotic-danger, #c2410c)",stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9};return[{id:"reserve-comfortable",label:`Comfortable (≥ ${n}%)`,when:{...i,gte:n},style:{fill:t.comfortableFill??"var(--semiotic-success, #16a34a)",fillOpacity:.85}},{id:"reserve-watch",label:`Watch (< ${n}%, ≥ ${r}%)`,when:{...i,lt:n,gte:r},style:{fill:t.watchFill??"var(--semiotic-warning, #d97706)",fillOpacity:.9}},{id:"reserve-tight",label:`Tight (< ${r}%)`,when:{...i,lt:r},style:{fill:a,stroke:t.tightFill??"var(--semiotic-danger, #c2410c)",strokeWidth:1,fillOpacity:1}}]}function vt(e={}){let{tight:t,watch:r,comfortable:n}={...ll,...e};return[{type:"band",y0:-50,y1:t,label:"Tight",color:"var(--semiotic-danger, #c2410c)",fillOpacity:.12,emphasis:"secondary"},{type:"band",y0:t,y1:r,label:"Watch",color:"var(--semiotic-warning, #d97706)",fillOpacity:.1,emphasis:"secondary"},{type:"band",y0:r,y1:Math.max(n+30,40),label:"Headroom",color:"var(--semiotic-success, #16a34a)",fillOpacity:.06,emphasis:"secondary"}]}function kt(e,t){if(!e.length)return null;let r=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!r.length)return null;let n=r[r.length-1];if("number"==typeof t&&Number.isFinite(t)){let e=r.filter(e=>t>=e.t);n=e.length?e[e.length-1]:r[0]}let o=gt(n.demandMw),i=gt(n.netGenMw),a="number"==typeof n.forecastMw&&Number.isFinite(n.forecastMw)?n.forecastMw:null,l=bt({demand:o,capacityOrNetGen:i,interchange:n.interchangeMw}),s={},c=null,u=0,d=0;for(let e of il){let t=gt(n.fuels?.[e]);0>=t||(d+=t,s[e]=t,t>u&&(u=t,c=e))}if(d>0)for(let e of Object.keys(s))s[e]=s[e]/d;return{t:n.t,ba:n.ba,demandMw:o,forecastMw:a,forecastErrorMw:null==a?null:o-a,netGenMw:i,reserveMarginPct:l,topFuel:c,topFuelShare:d>0?u/d:0,topFuelMw:u,fuelShares:s}}function $t(e,t={}){let r=t.now??Date.now(),n=t.author??"system",o=t.source??"authored-scenario";return e.map(e=>{let t=(e.start+e.end)/2,i=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:t,y:e.y??e.value,note:e.note,provenance:{author:n,authorKind:"system",source:o,basis:"rule",confidence:.85,createdAt:i,stableId:e.id,dataVersion:e.start+""},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:r}})}function At(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function St(e,t=0){return Number.isFinite(e)?e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})+" MW":"—"}function It(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}function Ct(e,t){if("function"==typeof e)return e;let r=e??t;return e=>Number(e[r])}function Nt(e,t={}){let r=Ct(t.start,"start"),n=Ct(t.end,"end"),o=!1===t.sort?e.slice():e.slice().sort((e,t)=>r(e)-r(t)||n(t)-n(e)),i=new cl;return{packed:o.map(e=>({item:e,track:i.assign(r(e),n(e))})),trackCount:Math.max(1,i.count)}}function zt(e,t){let r=Ct(t.start,"start"),n=Ct(t.end,"end"),[o,i]=t.domain,a=t.step??1,l="half-open"===t.bounds;if(o>i)return[];let s=(i-o)/a>Math.log2(e.length+1),c=[],u=[];if(s){for(let t of e){let e=r(t),o=n(t);o>=e&&(c.push(e),u.push(o))}c.sort((e,t)=>e-t),u.sort((e,t)=>e-t)}let d=0,h=0,f=[];for(let t=o;i>=t;t+=a){let o=0;if(s){for(;c.length>d&&t>=c[d];)d++;for(;u.length>h&&(l?t>=u[h]:t>u[h]);)h++;o=d-h}else for(let i of e){let e=r(i),a=n(i);t>=e&&(l?a>t:a>=t)&&o++}f.push({value:t,count:o})}return f}function Ft(e){return"function"==typeof e?e:t=>t[e]}function Et(e,t,r){let n=r?.orientation??"vertical",o=r?.bend??0,i=r?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===n){if(i>Math.abs(t.y-e.y)){let r=e.x>t.x?-1:1,n=a(e.x,t.x)+r*(22+Math.abs(o));return`M${e.x},${e.y} Q${n},${a(e.y,t.y)} ${t.x},${t.y}`}let r=a(e.y,t.y)+o;return`M${e.x},${e.y} C${e.x},${r} ${t.x},${r} ${t.x},${t.y}`}if(i>Math.abs(t.x-e.x)){let r=e.y>t.y?-1:1,n=a(e.y,t.y)+r*(22+Math.abs(o));return`M${e.x},${e.y} Q${a(e.x,t.x)},${n} ${t.x},${t.y}`}let l=a(e.x,t.x)+o;return`M${e.x},${e.y} C${l},${e.y} ${l},${t.y} ${t.x},${t.y}`}function jt(e,t,r){if("vertical"===(r?.orientation??"vertical")){let r=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${r} L${t.x},${r} L${t.x},${t.y}`}let n=(e.x+t.x)/2;return`M${e.x},${e.y} L${n},${e.y} L${n},${t.y} L${t.x},${t.y}`}function Ot(e,t,r){if("vertical"===(r?.orientation??"vertical")){let r=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(r?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(r?-t.height/2:t.height/2)}}}let n=t.cx>=e.cx;return{from:{x:e.cx+(n?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(n?-t.width/2:t.width/2),y:t.cy}}}function Rt(e,t){let r=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*r:(e-((t?.count??1)-1)/2)*r}function Wt(e,t){let r=1-t,n=r*r*r,o=3*r*r*t,i=3*r*t*t,a=t*t*t;return{x:n*e.p0.x+o*e.p1.x+i*e.p2.x+a*e.p3.x,y:n*e.p0.y+o*e.p1.y+i*e.p2.y+a*e.p3.y}}function Lt(e,t){let r=1-t,n=3*r*r,o=6*r*t,i=3*t*t;return{x:n*(e.p1.x-e.p0.x)+o*(e.p2.x-e.p1.x)+i*(e.p3.x-e.p2.x),y:n*(e.p1.y-e.p0.y)+o*(e.p2.y-e.p1.y)+i*(e.p3.y-e.p2.y)}}function Tt(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function Pt(e,t){let r=t?.axis??"x",n=t?.padding??0,o=t?.strength??.5,i="x"===r?"y":"x",a="x"===r?"width":"height",l="x"===r?"height":"width",s=new Map;for(let t of e)s.set(t.id,0);for(let t=0;e.length>t;t++)for(let c=t+1;e.length>c;c++){let u=e[t],d=e[c];if(Math.abs(u[i]-d[i])>(u[l]+d[l])/2+n)continue;let h=d[r]-u[r]||(d.id>u.id?-.5:.5),f=(u[a]+d[a])/2+n-Math.abs(h);if(0>=f)continue;let m=f*o*Math.sign(h);s.set(u.id,(s.get(u.id)??0)-m),s.set(d.id,(s.get(d.id)??0)+m)}return s}function qt(e,t){if("function"==typeof e)return e;let r=e??t;return e=>xi(e,r,void 0)}function Dt(e,t,r,n){let o=n.fixedAxis??"y",i=e=>qt(n.sourceAccessor,"source")(e)+"",a=e=>qt(n.targetAccessor,"target")(e)+"",l=n.size??(()=>dl),s=n.iterations??180,c=n.attraction??.012,u=n.anchorStrength??.003,d=n.collisionStrength??.12,h=n.collisionPadding??15,f=n.edgePadding??42,m=n.fixedPadding??16,p=n.damping??.72,g=n.spread??1,[y,x]=n.fixedDomain,b=x-y||1,M=("y"===o?r.y:r.x)+m,w=("y"===o?r.y+r.height:r.x+r.width)-m,v=("y"===o?r.x:r.y)+f,k=("y"===o?r.x+r.width:r.y+r.height)-f,$=Math.max(1,k-v),A=e.map(e=>{let t=Fi(e)??e,r=(c=e,qt(n.idAccessor,"id")(c)+""),{width:o,height:i}=l(t),a=(e=>Number(qt(n.fixedAccessor,"fixed")(e)))(e),s=v+function(e){let t=2166136261;for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0)/4294967295}(r)*$;var c,u;return{data:t,id:r,width:o,height:i,fixedValue:a,fixed:(u=a,M+(u-y)/b*(w-M)),free:s,anchor:s}}),S=new Map(A.map(e=>[e.id,e])),I=e=>"y"===o?e.width:e.height;for(let e=0;s>e;e++){let e=new Map;for(let t of A)e.set(t.id,0);for(let r of t){let t=S.get(i(r)),n=S.get(a(r));if(!t||!n)continue;let o=(n.free-t.free)*c;e.set(t.id,(e.get(t.id)??0)+o),e.set(n.id,(e.get(n.id)??0)-o)}for(let t of A)e.set(t.id,(e.get(t.id)??0)+(t.anchor-t.free)*u);let r=Pt(A.map(e=>({id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height})),{axis:"y"===o?"x":"y",padding:h,strength:d});for(let t of A)e.set(t.id,(e.get(t.id)??0)+(r.get(t.id)??0));for(let t of A){t.free+=(e.get(t.id)??0)*p;let r=I(t)/2;t.free=Math.max(v+r,Math.min(k-r,t.free))}}if(1!==g){let e=(v+k)/2;for(let t of A){let r=I(t)/2;t.free=Math.max(v+r,Math.min(k-r,e+(t.free-e)*g))}}let C=A.map(e=>({data:e.data,id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:C,byId:new Map(C.map(e=>[e.id,e]))}}function Vt(e){let t=Number(e.segmentDomain?.[0]),r=Number(e.segmentDomain?.[1]),n=Number.isFinite(t)?t:0,o=Number.isFinite(r)?r:n,i=n>o?-1:1,a=Math.abs(o-n),l=Number(e.currentSegment),s=Number.isFinite(l)?Wo((l-n)*i,0,a):0,c=(e,t)=>{let r=Number(e);return Number.isFinite(r)?Wo(r,0,1):t},u=c(e.oldestOpacity,.25),d=c(e.currentOpacity,1),h=c(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{let t=Number(e);if(!Number.isFinite(t))return h;let r=(t-n)*i;if(r>s)return h;if(0===s)return d;let o=Wo(r/s,0,1);return u+(d-u)*o}}}function Bt(e){let t=2166136261;for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0)/4294967295}function Ht(e){let t=0;for(let r of e)t+=gl[r]??.6;return t}function Yt(e,t){return Math.max(8,Ht(e)*t*1.05+1)}function Gt(e,t,r){for(let n of t)if((e.w+n.w)/2+r>Math.abs(e.x-n.x)&&(e.h+n.h)/2+r>Math.abs(e.y-n.y))return!0;return!1}function _t(e){let t=[],r=e.segHi-e.segLo||1;for(let n=0;e.tickCount>n;n++)t.push(e.segLo+r*n/Math.max(1,e.tickCount-1));return ml("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[fl("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,r)=>{let n=e.segToY(t);return ml("g",{children:[fl("line",{x1:e.x-4,y1:n,x2:e.x,y2:n,stroke:e.color,strokeWidth:1,opacity:.6}),fl("text",{x:e.x-7,y:n,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},"wt-tick-"+r)}),e.label&&fl("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}function Xt(e){return null==e?void 0:e+""}function Kt(e){let t=Xt(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...xl,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function Ut(e){return Kt(e)}function Qt(e){let[[t,r],[n,o]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((n-t)*(o-r)),style:{...xl,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function Zt(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...xl,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:Xt(e.id)}}function Jt(e){let t=Xt(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...xl,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...xl,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function er(e){let t={style:{...xl,cursor:e.cursor},datum:e.datum,id:Xt(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?{type:e.type??"curved",pathD:e.pathD,...t}:{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function tr(e,t,r={}){let{coord:n,step:o=1,equals:i=Object.is,truthyOnly:a=!1}=r,l=[],s=t=>n?n(e[t],t):t,c=(e,t,r)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=n?null==r||s(r)-s(t)>o?s(t)+o:s(r):t+1,l.push(e)},u=null;for(let r=0;e.length>r;r++){let l=t(e[r],r);if(a&&!l){u&&(c(u,u.endIndex,r),u=null);continue}let d=!n||0>=r||s(r)-s(r-1)<=o;u&&d&&i(u.value,l)?u.endIndex=r:(u&&c(u,u.endIndex,r),u={value:l,start:s(r),end:s(r),count:1,startIndex:r,endIndex:r})}return u&&c(u,u.endIndex,null),l}function rr(e,t,r=0){return t>0?((e-r)%t+t)%t+r:e}function nr(e,t,r){if(0>=r)return t-e;let n=(t-e)%r;return n>r/2?n-=r:-r/2>n&&(n+=r),n}function or(e,t,r){return t>r?e>=t||r>=e:e>=t&&r>=e}function ir(e,t,r,n){return r>n?[...e.filter(e=>t(e)>=r),...e.filter(e=>t(e)<=n)]:e.filter(e=>or(t(e),r,n))}function ar(e,t){let r=Math.max(0,t.width),n=t.y,o=Math.min(74,Math.max(34,.08*r)),i=t.paddingLeft??o,a=e.length>1?Math.max(0,r-i-(t.paddingRight??o))/(e.length-1):0,l=new Map;return e.forEach((e,t)=>{l.set(e.id,{id:e.id,x:i+a*t,y:n,index:t})}),l}function lr(e,t){let r=Math.max(0,t.width),n=t.y,o=Math.min(74,Math.max(34,.08*r)),i=t.paddingLeft??o,a=t.paddingRight??o,l=t.gap??8,s=!1!==t.distribute,c=t.estimateWidth??(e=>sr(e.label??e.id)),u=e.map((e,t)=>Math.max(1,c(e,t))),d=u.reduce((e,t)=>e+t,0)+l*Math.max(0,e.length-1),h=Math.max(0,r-i-a),f=s&&e.length>1?Math.max(0,h-d)/(e.length-1):0,m=new Map,p=i;return!s&&1===e.length&&(p=i+Math.max(0,(h-u[0])/2)),e.forEach((e,t)=>{let r=u[t];m.set(e.id,{id:e.id,x:p+r/2,y:n,index:t,width:r}),p+=r+l+f}),m}function sr(e,t=38,r=7.4,n=20){return Math.max(t,((e??"")+"").length*r+n)}function cr(e){let t=e.map(e=>{let t=Math.min(e.a,e.b),r=Math.max(e.a,e.b);return{span:e,a:t,b:r,width:r-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),r=new cl,n=t.map(e=>{let t=r.assign(e.a,e.b);return{span:e.span,level:t}}),o=Math.max(0,r.count-1);return{packed:n,maxLevel:o,levelCount:n.length?o+1:1}}function ur(e){let t=e.labelRoom??18,r=Math.max(48,e.baselineY-e.ceilingY-28),n=Math.max(1,e.levelCount),o=Math.min(42,Math.max(26,.18*r)),i=Math.max(24,r-o-t);return{arcLift:o,levelStep:Math.min(72,Math.max(28,n>1?i/Math.max(1,n-1):i))}}function dr(e,t,r,n,o={}){let i=r-(o.footLift??26);return`M${e} ${i}Q${(e+t)/2} ${n} ${t} ${i}`}function hr(e,t,r){return e-r.arcLift-t*r.levelStep}function fr(e,t=mr){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};let r=e.map(e=>new Set(e.map(e=>t(e)))),n=new Set;for(let e of r[0])r.every(t=>t.has(e))&&n.add(e);let o=[],i=new Set;for(let r of e[0]){let e=t(r);n.has(e)&&!i.has(e)&&(o.push(r),i.add(e))}return{shared:o,exclusive:e.map(e=>e.filter(e=>!n.has(t(e))))}}function mr(e){return null==e||"object"!=typeof e?e+"":null!=e.id?e.id+"":`${(e.sourceTokenId??e.source)+""}|${(e.targetTokenId??e.target)+""}|${(e.relation??e.label??"")+""}`}function pr(e,t,r){let n=r?.center?.x??0,o=r?.center?.y??0;return{x:n+Math.sin(e)*t,y:o-Math.cos(e)*t}}function gr(e,t,r){return(Math.atan2(e-(r?.center?.x??0),-(t-(r?.center?.y??0)))+wl)%wl}function yr(e,t){let[r,n]=e,o=n-r||1,i=t?.startAngle??0,a=t?.endAngle??wl;return e=>i+(e-r)/o*(a-i)}function xr(e,t){let[r,n]=e,[o,i]=t,a=n-r||1;return e=>o+(e-r)/a*(i-o)}function br(e,t,r,n,o){let i=o?.center,a=(e,t)=>{let{x:r,y:n}=pr(e,t,{center:i});return`${Mr(r)},${Mr(n)}`},l=Math.max(0,r),s=Math.max(l,n),c=Math.abs(t-e),u=e>t?0:1;if(c>=wl-1e-6){let e=i?.x??0,t=i?.y??0,r=`${Mr(e)},${Mr(t-s)}`,n=`${Mr(e)},${Mr(t+s)}`,o=`M${r} A${Mr(s)},${Mr(s)} 0 1 1 ${n} A${Mr(s)},${Mr(s)} 0 1 1 ${r} Z`;if(l>0){let r=`${Mr(e)},${Mr(t-l)}`,n=`${Mr(e)},${Mr(t+l)}`;o+=` M${r} A${Mr(l)},${Mr(l)} 0 1 0 ${n} A${Mr(l)},${Mr(l)} 0 1 0 ${r} Z`}return o}let d=c>Math.PI?1:0,h=a(e,s),f=a(t,s);if(0>=l){let e=i?.x??0,t=i?.y??0;return`M${Mr(e)},${Mr(t)} L${h} A${Mr(s)},${Mr(s)} 0 ${d} ${u} ${f} Z`}let m=a(t,l),p=a(e,l);return`M${h} A${Mr(s)},${Mr(s)} 0 ${d} ${u} ${f} L${m} A${Mr(l)},${Mr(l)} 0 ${d} ${1===u?0:1} ${p} Z`}function Mr(e){return Math.round(1e3*e)/1e3}function wr(e,t){return{x:e.x+t.x,y:e.y+t.y}}function vr(e,t){return{x:e.x-t.x,y:e.y-t.y}}function kr(e,t){return{x:e.x*t,y:e.y*t}}function $r(e){return Math.hypot(e.x,e.y)}function Ar(e){let t=$r(e)||1;return{x:e.x/t,y:e.y/t}}function Sr(e,t){let r=Ci(e,100);return r>0?t/r*100*(t/r):Math.PI*t*t}function Ir(e){let t=[],r=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(r.length>0){let n=e.colorType??"fill",o=r.map(([e,t])=>({label:e,color:t}));t.push({type:n,label:e.colorLabel??"",items:o,styleFn:"line"===n?e=>({stroke:e.color??$l,strokeWidth:2,fill:"none"}):e=>({fill:e.color??$l,stroke:e.color??$l})})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){let r=e.symbolColor??$l,n=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:r}));t.push({label:e.symbolLabel??"",items:n,styleFn:()=>({}),type:e=>{let t=e.shape;return vl("path",{d:Ni(t,Sr(t,7)),transform:"translate(8,8)",fill:e.color??r})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){let r=e.sizeRadius,n=e.sizeFormat??(e=>e+""),o=e.sizeColor??$l,i=e.sizeStops.map(e=>({label:n(e),r:Math.max(.5,r(e)),color:o}));t.push({label:e.sizeLabel??"",items:i,styleFn:()=>({}),type:e=>vl("circle",{cx:8,cy:8,r:e.r,fill:e.color??o})})}return t}function Cr(e){let t=e.orientation??"vertical",r=e.swatchSize??14,n=e.gap??8,o=e.labelGap??6,i=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",l=r+n,s=0,c=[];return e.entries.forEach((e,u)=>{c.push(kl("g",{transform:`translate(${"vertical"===t?0:s},${"vertical"===t?s:0})`,children:[Nr(e,r,e.color??e.line??a,a),vl("text",{x:r+o,y:r/2,dominantBaseline:"middle",fontSize:i,fill:a,children:e.label})]},"legend-"+u)),s+="vertical"===t?l:r+o+e.label.length*i*.58+n+8}),vl("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:c},e.keyId)}function Nr(e,t,r,n){if(e.shape){let n=Sr(e.shape,t/2-1);return vl("path",{d:Ni(e.shape,n),transform:`translate(${t/2},${t/2})`,fill:r})}if(e.hatch){let r=e.color??n;return kl("g",{children:[vl("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,n)=>vl("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:r,strokeWidth:1,opacity:.7},n))}),vl("rect",{width:t,height:t,fill:"none",stroke:r,strokeWidth:1,opacity:.5,rx:2})]})}return vl("rect",e.line?{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}:{width:t,height:t,rx:2,fill:r})}function zr(e){let t=e,r=[Or(t,["datum","data"]),Or(t,["datum"]),Or(t,["data","data"]),Or(t,["data"]),Or(t,["node","datum","data"]),Or(t,["node","datum"]),e];for(let e of r){if(!Rr(e))continue;let t={};for(let[r,n]of Object.entries(e))r.startsWith("_")||"function"==typeof n||(t[r]=n);if(Object.keys(t).length>0)return t}return null}function Fr(e,t={}){let r=zr(e);if(!r)return[];let n=new Set(Al);if(t.excludeKeys)for(let e of t.excludeKeys)n.add(e);let o=[];for(let[e,i]of Object.entries(r))if((t.includeInternal||!e.startsWith("_"))&&!n.has(e)&&(t.includeEmpty||null!=i&&""!==i)&&"function"!=typeof i&&(o.push({key:e,label:jr(e,t.labels),value:i,formatted:t.valueFormat?t.valueFormat(i,e,r):Er(i)}),o.length>=(t.maxEntries??8)))break;return o}function Er(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?e+"":e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return e.length+" items";if("object"==typeof e)try{return JSON.stringify(e)}catch{return e+""}return e+""}function jr(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){let r=t[e];if("string"==typeof r&&r.length>0)return r}return e}function Or(e,t){let r=e;for(let e of t){if(!Rr(r))return;r=r[e]}return r}function Rr(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Wr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Lr(e,t){return Wr(e,t)?e[t]:void 0}function Tr(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function Pr(){return Object.create(null)}function qr(e,t){let r=new Map;for(let t of e)r.set(t.id,new Set);for(let e of t)r.has(e.source)||r.set(e.source,new Set),r.has(e.target)||r.set(e.target,new Set),r.get(e.source).add(e.target),r.get(e.target).add(e.source);return r}function Dr(e,t){let r={};for(let t of e)Tr(r,t.id,0);for(let e of t)Tr(r,e.source,(Lr(r,e.source)??0)+1),Tr(r,e.target,(Lr(r,e.target)??0)+1);return r}function Vr(e,t){let r={};Tr(r,t,0);let n=[t],o=0;for(;n.length>o;){let t=n[o];o+=1;for(let o of e.get(t)||[])Wr(r,o)||(Tr(r,o,r[t]+1),n.push(o))}return r}function Br(e,t,r,n){if(r===n)return r?[r]:[];let o=qr(e,t),i=Pr();i[r]=null;let a=[r],l=0;for(;a.length>l;){let e=a[l];if(l+=1,e===n)break;for(let t of o.get(e)||[])Wr(i,t)||(i[t]=e,a.push(t))}if(!Wr(i,n))return[];let s=[],c=n;for(;null!=c;)s.unshift(c),c=i[c];return s}function Hr(e,t,r,n=1){let o=qr(e,t);if(!o.has(r))return new Set;let i=Vr(o,r),a=new Set;for(let e of Object.keys(i))n>=i[e]&&a.add(e);return a}function Yr(e,t){let r=qr(e,t),n={};for(let t of e)Tr(n,t.id,0);for(let t of e.map(e=>e.id)){let o=[],i=Pr(),a=Pr(),l=Pr();for(let t of e)i[t.id]=[],a[t.id]=0,l[t.id]=-1;a[t]=1,l[t]=0;let s=[t],c=0;for(;s.length>c;){let e=s[c];c+=1,o.push(e);for(let t of r.get(e)||[])0>l[t]&&(l[t]=l[e]+1,s.push(t)),l[t]===l[e]+1&&(a[t]+=a[e],i[t].push(e))}let u=Pr();for(let t of e)u[t.id]=0;for(;o.length;){let e=o.pop();for(let t of i[e])u[t]+=a[t]/a[e]*(1+u[e]);e!==t&&Tr(n,e,(Lr(n,e)??0)+u[e])}}for(let e of Object.keys(n))Tr(n,e,n[e]/2);return n}function Gr(e,t){let r=qr(e,t),n={};for(let t of e){let e=Vr(r,t.id),o=0,i=0;for(let t of Object.keys(e))o+=e[t],i+=1;Tr(n,t.id,o>0?(i-1)/o:0)}return n}function _r(e,t){let r=qr(e,t),n={};for(let t of e){let e=[...r.get(t.id)||[]],o=e.length;if(2>o){Tr(n,t.id,0);continue}let i=0;for(let t=0;e.length>t;t+=1)for(let n=t+1;e.length>n;n+=1)r.get(e[t])?.has(e[n])&&(i+=1);Tr(n,t.id,2*i/(o*(o-1)))}return n}function Xr(e){let t=0;for(let r of Object.keys(e))e[r]>t&&(t=e[r]);let r={};for(let n of Object.keys(e))Tr(r,n,t>0?e[n]/t:0);return r}function Kr(e,t,r,n={}){let o=qr(e,t),i=Pr();for(let t of e)i[t.id]=Vr(o,t.id);let a=n.minHops??4,l=n.startThreshold??.08,s=n.maxThreshold??.2,c=new Set,u=0;for(;0===c.size&&40>u;){for(let t=0;e.length>t;t+=1)for(let n=t+1;e.length>n;n+=1){let o=e[t].id,s=e[n].id,u=Lr(r,o),d=Lr(r,s);if(!u||!d)continue;let h=u.x-d.x,f=u.y-d.y;(void 0===i[o][s]?1/0:i[o][s])>=a&&l>Math.sqrt(h*h+f*f)&&(c.add(o),c.add(s))}0===c.size&&(l+=.02,l>s&&(l=n.startThreshold??.08,a=Math.max(2,a-1))),u+=1}return{problemIds:c,threshold:l,minHops:a}}function Ur(e){if("u">typeof DOMException)return new DOMException(e+" aborted","AbortError");let t=Error(e+" aborted");return t.name="AbortError",t}function Qr(e){let t=Error(e.message);return t.name=e.name??"Error",e.stack&&(t.stack=e.stack),t}function Zr(){return"u">typeof window&&"u">typeof Worker}async function Jr(e,t,r={}){let{execution:n="auto",signal:o,workerThreshold:i,nodeRadius:l,...s}=r,c=s.iterations??260;if(!Zr()||!function(e,t,r,n,o=4e4){return"sync"!==e&&("worker"===e||n*(t+r)>=o)}(n,e.length,t.length,c,i))return a(e,t,{...s,nodeRadius:l});let u={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:s,nodeRadii:"function"==typeof l?Object.fromEntries(e.map(e=>[e.id,l(e)])):null==l?void 0:Object.fromEntries(e.map(e=>[e.id,l]))};try{return(await function(e,t){return Zr()?Cl.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(u,o)).positions}catch(r){if("AbortError"===r?.name)throw r;return a(e,t,{...s,nodeRadius:l})}}function en(e,t,r){return Math.max(t,Math.min(r,e))}function tn(e,t,r={}){let n=r.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],i=en(r.along??.5,.05,.95),a=r.jitterX??0,l=r.padY??20,s=o.x0+(o.x1-o.x0)*i+(2*n()-1)*a,c=Math.min(1,o.width/2),u=en(s,o.x0+c,o.x1-c),d=e.boundaryY(u,"top")+l,h=e.boundaryY(u,"bottom")-l;return{x:u,y:h>d?d+n()*Math.max(1,h-d):e.midY}}function rn(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function nn(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function on(e,t,r,n,o){return"function"==typeof n?n(e,t,r):function(e,t){let r=e;for(let e of t.split(".")){if(null==r||"object"!=typeof r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}(e,n??o)}function an(e){let t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function ln(e,t,r,n){let o=e.flatMap((e,o)=>{let i=nn(on(e,o,t,r,"time")),a=nn(on(e,o,t,n,"value"));return null==i||null==a?[]:[{time:an(i),value:a,index:o}]});o.sort((e,t)=>e.time-t.time||e.index-t.index);let i=[];for(let e of o){let t=i[i.length-1];t?.time===e.time?t.value=e.value:i.push({time:e.time,value:e.value})}return i}function sn(e,t,r,n){if(!e.length)return null;let o=e[0],i=e[e.length-1];if(o.time>t)return"clamp"===n?o.value:null;if(t>i.time)return"clamp"===n?i.value:null;let a=function(e,t){let r=0,n=e.length;for(;n>r;){let o=r+n>>>1;t>e[o].time?r=o+1:n=o}return r}(e,t),l=e[a];if(l?.time===t)return l.value;let s=e[Math.max(0,a-1)];return"step"!==r&&l&&l.time!==s.time?s.value+(t-s.time)/(l.time-s.time)*(l.value-s.value):s.value}function cn(e,t){if(1===e.length)return e[0];let r=(e.length-1)*t,n=Math.floor(r),o=Math.ceil(r);return n===o?e[n]:e[n]+(e[o]-e[n])*(r-n)}function un(e){let t=e.interpolation??"step",r=e.outsideDomain??"omit",n=function(e){let t=(e??Nl).map(e=>{let t=nn(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return an(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),o=function(e){if(Array.isArray(e)){if(e.length>zl)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(nn).filter(e=>null!=e).map(an))).sort((e,t)=>e-t)}let t=e,r=nn(t.start),n=nn(t.end),o=nn(t.step);if(null==r||null==n||null==o||0>=o||r>n)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");let i=Math.floor((n-r)/o)+1;if(i>zl)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");let a=[],l=1e-10*Math.max(1,Math.abs(n),Math.abs(r));for(let e=0;i>e;e+=1){let t=r+e*o;if(t>n+l)break;a.push(an(Math.min(t,n)))}if((!a.length||Math.abs(a[a.length-1]-n)>l)&&a.push(an(n)),a.length>zl)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),i=e.runs.map(t=>ln(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:o.map(e=>{let o=i.map(n=>sn(n,e,t,r)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(let e of n)a[e]=o.length?cn(o,e):null;return{time:e,count:o.length,min:o.length?o[0]:null,max:o.length?o[o.length-1]:null,median:o.length?cn(o,.5):null,quantiles:a}}),quantiles:n,interpolation:t,outsideDomain:r,runCount:e.runs.length}}function dn(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function hn(e,t){if("min"===t||"median"===t||"max"===t)return e[t];let r=nn(t);if(null==r||0>r||r>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);let n=an(r);if(!Object.prototype.hasOwnProperty.call(e.quantiles,n))throw Error(`comparePhysicsTrace could not find quantile ${n} in the reference envelope`);return e.quantiles[n]??null}function fn(e,t,r){return t>e?"below":e>r?"above":"inside"}function mn(e,t){let r=Math.max(0,t.time-e.time);if(0>=r||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};let n=e.value-e.lower,o=t.value-t.lower,i=e.value-e.upper,a=t.value-t.upper,l=[0,1];for(let[e,t]of[[n,o],[i,a]])(0>e&&t>0||e>0&&0>t)&&l.push(-e/(t-e));l.sort((e,t)=>e-t);let s=0,c=0,u=0;for(let n=0;l.length-1>n;n+=1){let o=l[n],i=l[n+1];if(o>=i)continue;let a=(o+i)/2,d=(i-o)*r,h=fn(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?s+=d:"above"===h?u+=d:c+=d}return{below:s,inside:c,above:u,observed:r}}function pn(e,t,r={}){let n=r.interpolation??t.interpolation,o=r.outsideDomain??t.outsideDomain,i=ln(e,r.traceId??"trace",r.timeAccessor,r.valueAccessor),a=r.lower??dn(t,"lower"),l=r.upper??dn(t,"upper"),s=t.points.map(e=>{let t=sn(i,e.time,n,o),r=hn(e,a),s=hn(e,l);if(null!=r&&null!=s&&r>s)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:r,upper:s,status:null==t||null==r||null==s?"unobserved":fn(t,r,s)}}),c=0,u=0,d=0,h=0,f=null,m=0,p=null;for(let e of s){if("below"===e.status?c+=1:"inside"===e.status?u+=1:"above"===e.status&&(d+=1),null==e.value||null==e.lower||null==e.upper)continue;let t=Math.max(0,e.value-e.upper),r=Math.max(0,e.lower-e.value);t>h&&(h=t,f=e.time),r>m&&(m=r,p=e.time)}let g=0,y=0,x=0,b=0;for(let e=0;s.length-1>e;e+=1){let t=s[e],r=s[e+1],o=Math.max(0,r.time-t.time);if(o>0){if("linear"===n){let e=mn(t,r);g+=e.below,y+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=o,"below"===t.status?g+=o:"above"===t.status?x+=o:y+=o)}}let M=s[0]?.time,w=s[s.length-1]?.time,v=null==M||null==w?0:Math.max(0,w-M);return{points:s,sampleCount:s.length,observedSamples:c+u+d,belowSamples:c,insideSamples:u,aboveSamples:d,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:g,insideDuration:y,aboveDuration:x,peakExcess:h,peakExcessAt:f,peakDeficit:m,peakDeficitAt:p}}function gn(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function yn(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function xn(e){return!!yn(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&yn(e.visitsByStage)&&yn(e.firstEnteredAt)&&yn(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function bn(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function Mn(e){let t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,bn(e)]))}}function wn(e,t,r={}){if("region-enter"!==t.type)return e;let n=function(e,t){let r=t.stageId?.(e);if(r)return r;let n=e.region.metadata;if(n&&"object"==typeof n&&Object.prototype.hasOwnProperty.call(n,"stageId")){let e=n.stageId;if("string"==typeof e)return e}return e.region.id}(t,r),o=e.stages.findIndex(e=>e.id===n);if(0>o)return e;let i=r.entityId?.(t)??t.bodyId;if(!i)return e;let a=gn(e.entities,i),l=xn(a)?a:bn(i),s=l.currentStageId?e.stages.findIndex(e=>e.id===l.currentStageId):-1,c=!l.visitedStageIds.includes(n),u=Number(t.observation.timestamp),d=Number.isFinite(u)?u:0,h=gn(l.visitsByStage,n),f="number"==typeof h&&Number.isFinite(h)?h:0,m={...l,currentStageId:n,furthestStageId:o>l.furthestStageIndex?n:l.furthestStageId,furthestStageIndex:Math.max(l.furthestStageIndex,o),visitedStageIds:c?[...l.visitedStageIds,n]:l.visitedStageIds,visitsByStage:{...l.visitsByStage,[n]:f+1},firstEnteredAt:c?{...l.firstEnteredAt,[n]:d}:l.firstEnteredAt,lastEnteredAt:{...l.lastEnteredAt,[n]:d},regressionCount:s>=0&&s>o?l.regressionCount+1:l.regressionCount};return{...e,bodyIds:e.bodyIds.includes(i)?e.bodyIds:[...e.bodyIds,i],entities:{...e.entities,[i]:m}}}function vn(e){let t=e.bodyIds.map(t=>{let r=gn(e.entities,t);return xn(r)?r:bn(t)}),r=t.length,n=r;return e.stages.map((e,o)=>{let i=t.filter(e=>e.furthestStageIndex>=o).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,l=t.reduce((t,r)=>{let n=gn(r.visitsByStage,e.id);return t+("number"==typeof n&&Number.isFinite(n)?n:0)},0),s={id:e.id,label:e.label??e.id,reached:i,entered:a,total:r,conversion:r>0?i/r:0,fromPrevious:n>0?i/n:0,dropoff:Math.max(0,n-i),visits:l,repeatVisits:Math.max(0,l-a)};return n=i,s})}function kn(e,t){if("function"==typeof t){let r=t(e);return Number.isFinite(r)&&r>0?Number(r):1}let r=e.datum;if(t&&r&&"object"==typeof r){let e=Number(r[t]);if(Number.isFinite(e)&&e>0)return e}let n=Number(r?.work??r?.reviewWork??r?.value);return Number.isFinite(n)&&n>0?n:1}function $n(e,t){if("function"==typeof t){let r=t(e);if(null!=r&&(r+"").length>0)return r+""}else if(t){let r=ji(e.datum,t),n=ji(e,t),o=r??n;if(null!=o&&(o+"").length>0)return o+""}return e.id}function An(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];let r=Math.max(0,Math.min(1,t))*(e.length-1),n=Math.floor(r);return e[n]+(e[Math.ceil(r)]-e[n])*(r-n)}function Sn(e){function t(e,t){let r=t(e);return!!r&&r.activeRegionIds.includes(c)}function r(){H+=1}function n(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:c,work:e.total,queuedAt:e.queuedAt}}function o(t,o,i,a){let l={bodyId:t.id,jobId:o.jobId,visitId:o.visitId,visit:o.visit,remaining:o.work,total:o.work,queuedAt:o.queuedAt,sequence:a};return x.set(o.jobId,l),$.delete(t.id),k.set(t.id,o.jobId),O+=1,R+=o.work,r(),function(t,r,o){let i=n(r);e.onQueued?.(t,i),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:t.id,datum:t.datum,x:t.x,y:t.y,regionId:c,work:r.total,jobId:r.jobId,visitId:r.visitId,visit:r.visit,queuedAt:r.queuedAt,queueDepth:x.size})}(t,l,i),l}function i(e){if(x.size>=m||0===b.size)return;let t=Array.from(b.values()).sort((e,t)=>e.sequence-t.sequence);for(let r of t){if(x.size>=m)break;let t=v.get(r.jobId);t&&M.has(r.jobId)?(b.delete(r.jobId),$.delete(r.bodyId),o(t,r,e,r.sequence)):b.delete(r.jobId)}}function a(){let e=0;for(let t of x.values())e+=t.remaining;return e}function l(){D=Math.max(D,x.size),V=Math.max(V,a())}function s(){let e=F-p,t=Math.max(0,Math.min(p,F-(E??F))),r=0,n=0,o=0,i=0,a=0;for(let t of A){if(e>t.end)continue;r+=t.arrivals,n+=t.arrivalWork,o+=t.completions,i+=t.completedWork;let l=t.end-t.start;a+=l>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/l):t.processedWork}let l=t>0?n/t:0;return{seconds:t,arrivals:r,arrivalWork:n,completions:o,completedWork:i,processedWork:a,arrivalsPerSecond:t>0?r/t:0,throughputPerSecond:t>0?o/t:0,utilization:t>0&&u>0?Math.max(0,Math.min(1,a/(u*t))):0,pressure:u>0?l/u:0}}let c=e.regionId,u=Math.max(0,e.unitsPerSecond),d=e.queueLayout??"lane",h=e.queueSlotSpacing??14,f=e.queueStiffness??.35,m=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,p=Math.max(.25,e.metricWindowSeconds??30),g=Math.max(1/60,e.snapshotIntervalSeconds??.25),y=e.releaseImpulse??{x:90,y:0},x=new Map,b=new Map,M=new Map,w=new Map,v=new Map,k=new Map,$=new Map,A=[],S=0,I=new Map,C=new Map,N=0,z=0,F=0,E=null,j=0,O=0,R=0,W=0,L=0,T=0,P=0,q=0,D=0,V=0,B=0,H=0,Y=-1,G=!1;return{id:e.id??"capacity-queue:"+c,continuous:!1!==e.continuous,tick:a=>{let s=a.controls.readBodies(),d=new Map,h=new Map;for(let r of s){if(d.set(r.id,r),!t(r.id,a.getRegionState)||!ri(r,e.bodyFilter))continue;let n=$n(r,e.jobKey),o=h.get(n)??[];o.push(r),h.set(n,o)}let f=Number.isFinite(a.dt)?Math.max(0,a.dt):0;if(!G){let e=Number.isFinite(a.elapsed)?Math.max(0,a.elapsed):f;F=Math.max(0,e-f),G=!0}let O=F,R=O+f;F=R,E=null==E?O:Math.min(E,O);let D={start:O,end:R,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},V=new Map;for(let[e,t]of h){let r=M.get(e)?.bodyId,n=t.find(e=>e.id===r)??t[0];V.set(e,n),v.set(e,n)}for(let[t,o]of M){if(V.has(t))continue;let i=x.get(t),l=d.get(o.bodyId)??v.get(t);if(i){x.delete(t),k.delete(i.bodyId),P+=1,q+=i.remaining,r();let s={...n(i),abandonedAt:F,remainingWork:i.remaining,queueSeconds:Math.max(0,F-i.queuedAt)};l&&e.onAbandoned?.(l,s),a.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:l?.datum,x:l?.x,y:l?.y,regionId:c,work:i.total,remainingWork:i.remaining,jobId:t,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,abandonedAt:F,queueSeconds:s.queueSeconds,queueDepth:x.size})}b.delete(t),$.delete(o.bodyId),M.delete(t),v.delete(t)}for(let[t,n]of V){if(M.has(t))continue;let i=(w.get(t)??0)+1;w.set(t,i);let l=kn(n,e.unitAccessor),s={bodyId:n.id,jobId:t,visitId:`${c}:${t}:${i}`,visit:i,regionId:c,work:l,queuedAt:F};M.set(t,s),j+=1,D.arrivals+=1,D.arrivalWork+=l;let u=S++;if(m>x.size)o(n,s,a,u);else{let o={...s,blockedAt:F,sequence:u};b.set(t,o),$.set(n.id,t),T+=1,r(),e.onBlocked?.(n,o),a.controls.recordObservation({type:"physics-capacity-blocked",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:c,work:l,jobId:t,visitId:s.visitId,visit:i,queuedAt:F,blockedAt:F,queueDepth:x.size,blockedDepth:b.size})}}i(a),l();let H=Array.from(x.values()).sort((e,t)=>e.sequence-t.sequence),_=u*f;for(let t of H){if(0>=_)break;let o=Math.min(t.remaining,_);if(t.remaining-=o,_-=o,W+=o,D.processedWork+=o,t.remaining>1e-6)continue;x.delete(t.jobId),k.delete(t.bodyId),z+=1,L+=t.total,D.completions+=1,D.completedWork+=t.total;let i=Math.max(0,F-t.queuedAt);B+=i,r();let l=d.get(t.bodyId);if(!l)continue;a.controls.applyImpulse(t.bodyId,y.x??0,y.y??0);let s={...n(t),completedAt:F,queueSeconds:i};e.onProcessed?.(l,s),a.controls.recordObservation({type:"physics-capacity-processed",bodyId:t.bodyId,datum:l.datum,x:l.x,y:l.y,regionId:c,work:t.total,jobId:t.jobId,visitId:t.visitId,visit:t.visit,queuedAt:t.queuedAt,completedAt:F,queueSeconds:i,queueDepth:x.size})}i(a),l(),function(){let e=Array.from(x.values()).sort((e,t)=>e.sequence-t.sequence);I=new Map(e.map((e,t)=>[e.bodyId,t]));let t=Array.from(b.values()).sort((e,t)=>e.sequence-t.sequence);C=new Map(t.map((e,t)=>[e.bodyId,t])),N=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&A.push(e);let t=F-p;for(;A.length>0&&t>A[0].end;)A.shift()}(D);let X=Math.floor(F/g);X!==Y&&(Y=X,r())},getSnapshot:()=>{let e=a(),t=function(){let e=0;for(let t of b.values())e+=t.work;return e}(),r=x.size,n=Array.from(x.values()).map(e=>Math.max(0,F-e.queuedAt)).sort((e,t)=>e-t),o=n.reduce((e,t)=>e+t,0);return{regionId:c,queueDepth:r,processedCount:z,unitsPerSecond:u,remainingWork:e,meanRemainingWork:r>0?e/r:0,waitingWork:e+t,blockedDepth:b.size,blockedWork:t,arrivalCount:j,admittedCount:O,admittedWork:R,processedWork:W,completedWork:L,blockedCount:T,abandonedCount:P,abandonedWork:q,peakQueueDepth:D,peakRemainingWork:V,queueAge:{count:n.length,meanSeconds:n.length>0?o/n.length:0,p50Seconds:An(n,.5),p95Seconds:An(n,.95),oldestSeconds:n.at(-1)??0},meanCompletedQueueSeconds:z>0?B/z:0,window:s(),simulatedAt:F,metricRevision:H}},bodyForce:e=>{if("none"===d)return null;let t=k.get(e.body.id),r=$.get(e.body.id),n=t?x.get(t):void 0,o=r?b.get(r):void 0;if(!n&&!o)return null;let i=n?I.get(e.body.id):C.get(e.body.id);if(null==i)return null;let a,l=e.regions;if(l)for(let e=0;l.length>e;e+=1)if(l[e].id===c){let t=l[e].shape;t&&"aabb"===t.type&&(a=t);break}return a?{x:((o?a.x-.44*a.width:a.x-.22*a.width-i*(.15*h))-e.body.x)*f,y:(a.y-(i-((o?b.size:N)-1)/2)*h/Math.max(1,Math.sqrt(o?b.size:N))-e.body.y)*f*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function In(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Cn(e){if(!e?.length)return null;let t=e.slice(),r=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:r,onTick:(e,r,n)=>{let o={result:e,controls:r,dt:n.dt,elapsed:n.elapsed,getRegionState:n.getRegionState};for(let e of t)e.tick(o)},bodyForce:e=>{let r=null;for(let n of t)n.bodyForce&&(r=In(r,n.bodyForce(e)));return r}}}function Nn(e){let t=new Set,r=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:n=>{let o=n.controls.readBodies();for(let i of o)n.getRegionState(i.id)?.activeRegionIds.includes(e.fromRegionId)?t.has(i.id)||(t.add(i.id),n.controls.applyImpulse(i.id,r.x??0,r.y??0),e.onPortal?.(i)):t.delete(i.id)}}}function zn(e){let t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),r=new Map(t.map(e=>[e.bodyId,e])),n=new Map,o=new Map,i=e.assignmentForce??.45,a=e.returnForce??.35,l=e.caseAttraction??.08,s=e.assignmentOffset??{x:0,y:0},c=new Map,u=0,d=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{let r=n.get(e);if(r)return r;let i=t.find(e=>!o.has(e.id));if(!i)return null;let a={resourceId:i.id,resourceBodyId:i.bodyId,caseBodyId:e,assignedAt:u};return n.set(e,a),o.set(i.id,a),d+=1,a},release:e=>{let t=n.get(e);return!!t&&(n.delete(e),o.delete(t.resourceId),d+=1,!0)},getAssignment:e=>n.get(e),tick:e=>{u=Math.max(u,e.elapsed),c=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(let[e,t]of n)c.has(e)&&c.has(t.resourceBodyId)||(n.delete(e),o.delete(t.resourceId),d+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(n.values()),simulatedAt:u,metricRevision:d}),bodyForce:e=>{let t=r.get(e.body.id);if(t){let r=o.get(t.id),n=r?c.get(r.caseBodyId):void 0,l=r?i:a;return{x:((n?n.x+(s.x??0):t.home.x)-e.body.x)*l,y:((n?n.y+(s.y??0):t.home.y)-e.body.y)*l}}let u=n.get(e.body.id);if(!u||0>=l)return null;let d=c.get(u.resourceBodyId);return d?{x:(d.x-e.body.x)*l,y:(d.y-e.body.y)*l}:null}}}function Fn(e,t){let r="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):ji(e.datum,t.deadlineAccessor)??ji(e,t.deadlineAccessor);return Number.isFinite(Number(r))?Math.max(0,Number(r)):0}function En(e){function t(t){n.set(t.bodyId,t),i+=1,e.onStateChange?.({...t})}function r(e){let r=n.get(e);return!(!r||null!=r.completedAt||(t({...r,completedAt:o,state:"unhappy"===r.state?"resolved-unhappy":"resolved"}),0))}let n=new Map,o=0,i=0;return{id:e.id??"service-level",continuous:!0,protect:e=>{let r=n.get(e);return!(!r||null!=r.completedAt||"unhappy"===r.state||(t({...r,state:"protected",protectedAt:o}),0))},complete:r,getCase:e=>n.get(e),tick:i=>{o=Math.max(o,i.elapsed);for(let a of i.controls.readBodies()){if(!ri(a,e.bodyFilter))continue;if(!n.has(a.id)){let r=Fn(a,e);t({bodyId:a.id,openedAt:o,deadlineAt:o+r,state:"waiting"})}let l=n.get(a.id);l&&null==l.completedAt&&(e.completionRegionId&&i.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?r(a.id):"waiting"===l.state&&o>=l.deadlineAt&&t({...l,state:"unhappy"}))}},getSnapshot:()=>{let e=Array.from(n.values()),t=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:t("waiting"),protected:t("protected"),unhappy:t("unhappy"),resolved:t("resolved"),resolvedUnhappy:t("resolved-unhappy"),simulatedAt:o,metricRevision:i}}}}function jn(e){let t=new Set,r=0,n=0,o=0,i=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:a=>{r=Math.max(r,a.elapsed);let l=i;var s;s=r,i=e.isOpen?e.isOpen(s):null!=e.opensAt&&s>=e.opensAt;let c=a.controls.readBodies(),u=new Map(c.map(e=>[e.id,e]));for(let r of c)!a.getRegionState(r.id)?.activeRegionIds.includes(e.regionId)||!ri(r,e.bodyFilter)||!i&&!t.has(r.id)&&(t.add(r.id),o+=1,e.onHeld?.(r));if(i&&!l){for(let r of t){let t=u.get(r);t&&(a.controls.applyImpulse(r,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),n+=1,e.onReleased?.(t))}t.clear(),o+=1}for(let e of t)u.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:i,blocked:t.size,released:n,simulatedAt:r,metricRevision:o}),bodyForce:r=>{if(i||!t.has(r.body.id))return null;let n=r.regions?.find(t=>t.id===e.regionId)?.shape;if(!n||"aabb"!==n.type)return{x:.8*-r.body.vx,y:.8*-r.body.vy};let o=e.holdForce??.4;return{x:(n.x-r.body.x)*o-.45*r.body.vx,y:(n.y-r.body.y)*o-.45*r.body.vy}}}}function On(e){let[t,r]=e.size,n=e.flow??Fl,o=null==(w=e.padding)?{top:El,right:El,bottom:El,left:El}:"number"==typeof w?{top:w,right:w,bottom:w,left:w}:{top:w.top??0,right:w.right??0,bottom:w.bottom??0,left:w.left??0},i=Math.max(.05,Math.min(1,e.channelRatio??Wl)),a={x:o.left,y:o.top,width:Math.max(1,t-o.left-o.right),height:Math.max(1,r-o.top-o.bottom)},l="down"===n?a.height:a.width,s=l*Math.max(0,e.chargeExtent??jl),c=l*Math.max(0,e.projectionExtent??Rl),u=l*Math.max(0,e.destinationExtent??Ol),d=Math.max(0,l-s-u-c),h=function(e){return"number"==typeof e?Array.from({length:Math.max(1,Math.round(e))},(e,t)=>({id:"bin-"+t,label:t+""})):0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??t+""}))}(e.destinations),f=("down"===n?a.width:a.height)/h.length,m="down"===n?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),p=m(0,s),g=m(s,d),y=s+d,x=m(y,u),b=m(y+u,c),M=h.map((e,t)=>{let r=t*f,o=f*i,l=(f-o)/2;return"down"===n?{id:e.id,label:e.label,order:t,x:a.x+r+l,y:x.y,width:o,height:x.height,centerX:a.x+(t+.5)*f,centerY:x.y+x.height/2}:{id:e.id,label:e.label,order:t,x:x.x,y:a.y+r+l,width:x.width,height:o,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*f}});var w;return{width:t,height:r,flow:n,charge:p,apparatus:g,destinations:M,projection:b}}function Rn(e,t){return e.destinations.find(e=>e.id===t)}function Wn(e,t,r){let{charge:n,flow:o}=e,i=Math.max(1,r),a=(t%i+.5)/i;return"down"===o?{x:n.x+n.width*a,y:n.y+n.height/2}:{x:n.x+n.width/2,y:n.y+n.height*a}}function Ln(e,t={}){let r=t.thickness??4,n=t.idPrefix??"stage",{destinations:o,flow:i,width:a,height:l}=e,s=[];if(o.length>0){let t=o[0];if("down"===i){let i=t.y+t.height;s.push({id:n+"-floor",shape:{type:"segment",x1:e.charge.x,y1:i,x2:e.charge.x+e.charge.width,y2:i,thickness:r}});for(let e=1;o.length>e;e+=1){let a=o[e].centerX-(o[e].centerX-o[e-1].centerX)/2;s.push({id:`${n}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:i,thickness:r}})}}else{let i=t.x+t.width;s.push({id:n+"-floor",shape:{type:"segment",x1:i,y1:e.charge.y,x2:i,y2:e.charge.y+e.charge.height,thickness:r}});for(let e=1;o.length>e;e+=1){let a=o[e].centerY-(o[e].centerY-o[e-1].centerY)/2;s.push({id:`${n}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:i,y2:a,thickness:r}})}}}return!1!==t.walls&&s.push({id:n+"-wall-left",shape:{type:"segment",x1:1,y1:0,x2:1,y2:l,thickness:r}},{id:n+"-wall-right",shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:l,thickness:r}}),s}function Tn(e,t={}){return`${t.charge??"bodies"} enter at the ${"down"===e.flow?"top":"left"}, travel ${"down"===e.flow?"downward":"left to right"} through ${t.apparatus??"the apparatus"}, and come to rest in ${e.destinations.length} ${t.destination??"destinations"}: ${e.destinations.map(e=>e.label).join(", ")}.`}function Pn(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function qn(e,t,r,n){let o="function"==typeof e?e(t,r):e;return Number.isFinite(o)?Number(o):n}function Dn(e,t,r){return Pn(e[t])??r}function Vn(e,t){return"number"==typeof e?e:e?.[t]??0}function Bn(e){let{band:t,idPrefix:r,plot:n,projection:o}=e,{includeBoundaryWalls:i=!0,includeInteriorWalls:a=!0,wallThickness:l=4}=t,s=function(e){let t=e.bandwidth??e.scale.bandwidth?.()??0,r=new Set;for(let n of e.values){let o=e.scale(n);Number.isFinite(o)&&(r.add(Number(o)),r.add(Number(o)+t))}return Array.from(r).sort((e,t)=>e-t)}(t);if(2>s.length)return[];let c=i?s.length-1:s.length-2,u=[];for(let e=i?0:1;c>=e;e+=1){if(!a&&e>0&&s.length-1>e)continue;let t=s[e];u.push({id:`${r}-wall-${e}`,shape:"x"===o?{type:"aabb",x:t,y:n.y+n.height/2,width:l,height:n.height}:{type:"aabb",x:n.x+n.width/2,y:t,width:n.width,height:l}})}return u}function Hn(e){let{plot:t,idPrefix:r="physics-scale",bounds:n={},xBins:o,xBands:i,yBands:a}=e,l=[];if(!1!==n&&l.push(...Lo(t,{idPrefix:r,...n})),o){let{idPrefix:e,yTop:n,yBottom:i,...a}=o;l.push(...To({...a,idPrefix:e??r+"-xbin",yTop:n??t.y,yBottom:i??t.y+t.height}))}return i&&l.push(...Bn({band:i,idPrefix:i.idPrefix??r+"-xband",plot:t,projection:"x"})),a&&l.push(...Bn({band:a,idPrefix:a.idPrefix??r+"-yband",plot:t,projection:"y"})),l}function Yn(e){let{plot:t,rows:r,columns:n=r+1,pegRadius:o=3,idPrefix:i="galton-peg",yStart:a=t.y+.18*t.height,yEnd:l=t.y+.58*t.height,stagger:s=!0,restitution:c=.2,friction:u=.04}=e,d=Math.max(0,Math.floor(r)),h=Math.max(1,Math.floor(n));if(0===d)return[];let f=d>1?(l-a)/(d-1):0,m=t.width/h,p=[];for(let e=0;d>e;e+=1){let r=s&&e%2==1?m/2:0;for(let n=0;h>n;n+=1){let l=t.x+m*(n+.5)+r;t.x+o>l||l>t.x+t.width-o||p.push({id:`${i}-${e}-${n}`,shape:{type:"aabb",x:l,y:a+e*f,width:2*o,height:2*o},restitution:c,friction:u})}}return p}function Gn(e,t={}){let{idPrefix:r="physics-token",radius:n=5,shape:o,mass:i,vx:a,vy:l,spawnAt:s,seed:c=1,jitter:u,datum:d}=t,h=ii(c),f=Vn(u,"x"),m=Vn(u,"y");return e.map((e,c)=>{let u=qn(t.x,e,c,Dn(e,"x",0)),p=qn(t.y,e,c,Dn(e,"y",0)),g=qn(n,e,c,5),y="function"==typeof o?o(e,c):o??{type:"circle",radius:g};return{id:`${r}-${e.index??c}`,x:u+(h()-.5)*f,y:p+(h()-.5)*m,vx:qn(a,e,c,0),vy:qn(l,e,c,0),mass:qn(i,e,c,1),spawnAt:qn(s,e,c,void 0),shape:y,datum:d?d(e,c):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;let{spawnAt:t,...r}=e;return r})}function _n(e,t={}){let{idPrefix:r="sediment",collider:n=!0,colliderThickness:o=1,restitution:i=.05,friction:a=.2,...l}=t,s=$i(e,l),c=n?s.filter(e=>e.height>0).map(e=>({id:`${r}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+o/2,width:e.width,height:o},restitution:i,friction:a})):[];return{columns:s,colliders:c}}function Xn(e,t={}){let{timeAccessor:r="arrivalTime",timeScale:n=1,startAt:o=0,rebase:i=!0,sort:a=!0}=t,l=e.map((e,t)=>({spawn:e,time:function(e,t,r){return Pn("function"==typeof r?r(e,t):e[r]??e.datum?.[r])}(e,t,r)??e.spawnAt??t})),s=l.length?Math.min(...l.map(e=>e.time)):0;return{initialSpawns:l.map(({spawn:e,time:t})=>({...e,spawnAt:o+(i?t-s:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:o,timeAccessor:"spawnAt",timeScale:n}}}function Kn(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function Un(e,t,r="group"){let n=Dr(e,t),o=e=>"function"==typeof r?r(e):e[r]??0;return e.slice().sort((e,t)=>{let r=o(e),i=o(t);return i>r?-1:r>i?1:(n[t.id]||0)-(n[e.id]||0)}).map(e=>e.id)}function Qn(e,t={}){let r=t.baseline??.62,n=t.inset??.06,o={},i=e.length;return e.forEach((e,t)=>{Kn(o,e,{x:i>1?n+t/(i-1)*(1-2*n):.5,y:r})}),o}function Zn(e,t,r=.55){return`M${e.x},${e.y} Q${(e.x+t.x)/2},${e.y-Math.abs(t.x-e.x)*r} ${t.x},${t.y}`}function Jn(e,t={}){let r=t.radius??.42,n=t.center?.x??.5,o=t.center?.y??.5,i=t.startAngle??0,a={},l=e.length;return e.forEach((e,t)=>{let s=i+t/l*Math.PI*2-Math.PI/2;Kn(a,e,{x:n+Math.cos(s)*r,y:o+Math.sin(s)*r})}),a}function eo(e,t,r={}){let n=(r.order??Un(e,t,r.groupAccessor??"group")).slice(),o=new Map(n.map((e,t)=>[e,t])),i=new Map;for(let e of t){if(!o.has(e.source)||!o.has(e.target)||e.source===e.target)continue;let t=e.target>e.source?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;i.set(t,(i.get(t)||0)+(e.value??1))}let a=[],l=0;for(let[e,t]of i){let[r,n]=e.split("\0"),i=o.get(r),s=o.get(n);t>l&&(l=t),a.push({row:i,col:s,source:r,target:n,value:t}),a.push({row:s,col:i,source:n,target:r,value:t})}return{order:n,cells:a,size:n.length,maxValue:l}}function to(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function ro(e){if("string"!=typeof e)return;let t=e.trim();return t.length?t:void 0}function no(e,t){let r=to(e.note)?e.note:void 0;return t?ro(e.mobileText)||ro(e.shortText)||ro(e.label)||ro(r?.mobileText)||ro(r?.shortText)||ro(r?.label)||ro(r?.title):ro(e.label)||ro(e.mobileText)||ro(e.shortText)||ro(r?.label)||ro(r?.title)}function oo(e,t,r){let n=function(e,t,r){if(!r)return;let n="function"==typeof r?r(e,t):e[r];return"number"==typeof n&&Number.isFinite(n)?n:void 0}(e,t,r.priorityAccessor);if(void 0!==n)return n;let o=1e3-t,i=((e.emphasis??"")+"").toLowerCase();("primary"===i||"critical"===i)&&(o+=1e4),"secondary"===i&&(o-=1e3),"high"===e.priority&&(o+=5e3),"low"===e.priority&&(o-=1500),"number"==typeof e.priority&&(o+=100*e.priority);let a=to(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(o+=100*a.confidence);let l=to(e.lifecycle)?e.lifecycle:void 0,s=((l?.freshness??"")+"").toLowerCase();return("expired"===s||"stale"===s)&&(o-=3e3),o}function io(e,t){if(!t)return e;let r=no(e,!0);return r&&"string"==typeof e.label?{...e,label:r}:e}function ao(e,t={}){let r=Array.isArray(e)?e.filter(to):[],n=t.active??(null==t.width||(t.breakpoint??480)>=t.width),o=t.strategy??"hybrid",i=!1!==t.preferShortText,a=!1!==t.preservePrimary,l=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===o?1:2)),s=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!n||"plot"===o)return{active:n,strategy:o,budget:r.length,visible:i?r.map(e=>io(e,i)):r,deferred:[],calloutList:[],hidden:[]};let c=[],u=r.map((e,r)=>({annotation:e,index:r,priority:oo(e,r,t)})).filter(e=>!!Qo(e.annotation)||(c.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),d=a?u.filter(e=>"primary"===((e.annotation.emphasis??"")+"").toLowerCase()):[],h=new Set(d.map(e=>e.index)),f=u.filter(e=>!h.has(e.index)),m=[...d,...f].slice(0,Math.max(l,s)),p=new Set(m.map(e=>e.index)),g=u.filter(e=>!p.has(e.index)),y=[...c,...m.sort((e,t)=>e.index-t.index).map(e=>io(e.annotation,i))],x=g.sort((e,t)=>e.index-t.index).map(e=>e.annotation),b=Math.max(0,t.maxCalloutItems??6),M=g.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,r,n){let o=no(e,n);if(!o)return null;let i=ro(e.id)||ro(e.key)||ro(e.pointId)||"annotation-"+(t+1),a=to(e.provenance)?ro(e.provenance.source)||ro(e.provenance.authorKind):void 0;return{id:i,label:o,shortLabel:ro(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:r,annotation:e}}(e.annotation,e.index,e.priority,i)).filter(e=>!!e).slice(0,b),w=new Set(M.map(e=>e.annotation)),v=x.filter(e=>!w.has(e));return{active:n,strategy:o,budget:l,visible:y,deferred:x,calloutList:M,hidden:v}}function lo(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function so(e,t){let r=!1!==t.keepAxes,n=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:n,bottom:r?44:12,left:r?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:n,bottom:r?42:14,left:r?44:14}}function co(e,t,r,n={}){let o={...r},i={mode:!1===t.mode?void 0:"mobile",...o,margin:so(e,t),...n},a=Object.fromEntries(Object.entries(o).filter(([,e])=>void 0!==e)),l=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),s=function(e,t){let r=t.targetSize??44,n=[],o=t.standardControls,i=e=>!0===o||"all"===o||o===e||Array.isArray(o)&&o.includes(e);return i("brush")&&n.push("range-inputs","clear-brush"),i("zoom")&&n.push("zoom-buttons","reset-view"),i("legend")&&n.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:r,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:r,...n.length>0&&{alternatives:n}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),c=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:e+"-mobile",description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...l,mobileInteraction:c,mobileSemantics:s}}],mobileInteraction:c,mobileSemantics:s}}function uo(e={}){let t=lo(e);return co("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function ho(e={}){let t=lo(e);return co("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function fo(e={}){return co("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function mo(e={}){let t=lo(e);return co("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function po(e={}){let t=lo(e);return co("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function go(e={}){return co("geo",e,{showLegend:e.showLegend??!1})}function yo(e={}){return co("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function xo(e,t={}){switch(e){case"line":return uo(t);case"area":return ho(t);case"ordinal":return fo(t);case"scatter":return mo(t);case"network":return po(t);case"geo":return go(t);case"small-multiple":return yo(t)}}function bo(e={}){let t=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:e.targetSize??44,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:t,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:t}}import{DEFAULT_AREA_PER_ANNOTATION as Mo,DEFAULT_GLYPH_ANCHOR as wo,DEFAULT_GLYPH_VIEWBOX as vo,LayoutCache as ko,SYMBOL_SEQUENCE as $o,absorbRegion as Ao,aggregateRegionCounts as So,annotationBudget as Io,annotationDensity as Co,annotationLayout as No,bandLabel as zo,bodyGroupSpec as Fo,boundsOf as Eo,calendarLayout as jo,capacitatedRegion as Oo,chargeGateRegion as Ro,clamp as Wo,collidersFromPlotBounds as Lo,collidersFromXScaleBins as To,countPairwiseCrossings as Po,createSafeDatum as qo,datumFromFields as Do,dimFor as Vo,forceFieldRegion as Bo,glyphExtent as Ho,glyphFractionClipRect as Yo,glyphPlacement as Go,groupBy as _o,groupCompletionRows as Xo,hatchFill as Ko,hullFromBoxes as Uo,isNoteAnnotation as Qo,linearAxis as Zo,makeShade as Jo,markCallout as ei,matchesHighlight as ti,matchesPhysicsBodyFilter as ri,mean as ni,membraneRegion as oi,mulberry32 as ii,nonNegativeFinite as ai,orderByBarycenter as li,orderExactSmall as si,packBandsBySilhouette as ci,parallelCoordinatesLayout as ui,placeWithMinGap as di,portalRegion as hi,pressureFieldRegion as fi,processChrome as mi,processLaneWalls as pi,processStageLayout as gi,processStageRegions as yi,readField as xi,refineByAdjacentSwaps as bi,regionCountsToProjectionRows as Mi,resolveAccessor as wi,roundedEnclosure as vi,routeSurfaceRegion as ki,sedimentHeightfield as $i,shade as Ai,signatureKey as Si,stableGlyphId as Ii,symbolExtent as Ci,symbolPathString as Ni,symbolRadius as zi,unwrapDatum as Fi,useCustomLayoutSelection as Ei,valueAtPath as ji,withAlpha as Oi}from"./c-JG2JCQLP.min.js";import"./c-QA3HMQJP.min.js";var Ri=e=>{let t=e.config,r=t.rows??10,n=t.columns??10,o=t.gutter??2,i=r*n;if(0>=r||0>=n||0>=i)return{nodes:[]};let{plot:a}=e.dimensions;if(0>=a.width||0>=a.height)return{nodes:[]};let l=(a.width-o*(n-1))/n,s=(a.height-o*(r-1))/r;if(0>=l||0>=s)return{nodes:[]};let c=(null==(f=t.categoryAccessor)?null:"function"==typeof f?f:e=>e[f])??(()=>"_default"),u=function(e){return null==e?null:"function"==typeof e?e:t=>Number(t[e])}(t.valueAccessor)??(()=>1),d=new Map,h=[];var f;for(let t of e.data){let e=c(t)+"",r=Number(u(t)),n=Number.isFinite(r)?Math.max(0,r):0;d.has(e)||h.push(e),d.set(e,(d.get(e)??0)+n)}let m,p=Array.from(d.values()).reduce((e,t)=>e+t,0);if(0>=p)return{nodes:[]};if(t.categoryOrder&&t.categoryOrder.length>0){let e=new Set,r=[];for(let n of t.categoryOrder)d.has(n)&&!e.has(n)&&(e.add(n),r.push(n));m=[...r,...h.filter(t=>!e.has(t))]}else m=h;if(0===m.length)return{nodes:[]};let g=m.map(e=>({cat:e,exact:(d.get(e)??0)/p*i})).map(e=>({...e,count:Math.floor(e.exact)})),y=g.reduce((e,t)=>e+t.count,0),x=g.map((e,t)=>({i:t,rem:e.exact-e.count})).sort((e,t)=>t.rem-e.rem);for(let e=0;i-y>e;e++)g[x[e%x.length].i].count+=1;let b="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",M="string"==typeof t.valueAccessor?t.valueAccessor:"value",w=(e,t,r)=>qo(n=>{n("category",e),n("value",d.get(e)??0),n("share",(d.get(e)??0)/p),"category"!==b&&n(b,e),"value"!==M&&n(M,d.get(e)??0),n("cells",r),n("_waffleCategory",e),n("_waffleIndex",t)}),v=[],k=0;for(let t of g){let i=e.resolveColor(t.cat);for(let e=0;t.count>e;e++)v.push({type:"rect",x:a.x+k%n*(l+o),y:a.y+(r-1-Math.floor(k/n))*(s+o),w:l,h:s,style:{fill:i,stroke:"none"},datum:w(t.cat,k,t.count),group:t.cat,_transitionKey:`waffle-${t.cat}-${e}`}),k++}return{nodes:v}};import{forceCenter as Wi,forceCollide as Li,forceLink as Ti,forceManyBody as Pi,forceSimulation as qi,forceX as Di,forceY as Vi}from"d3-force";var Bi="#334155",Hi="#f8fafc",Yi="#cbd5e1",Gi={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},_i={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},Xi={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},Ki={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},Ui="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",Qi={viewBox:[18,40],anchor:[.5,1],parts:[{d:Ui,fill:"color",stroke:"color",strokeWidth:1.4}]},Zi={server:Gi,chip:_i,bolt:Xi,bus:Ki,person:Qi},Ji="var(--semiotic-primary, #4e79a7)",ea="var(--semiotic-border, #d1d5db)",ta=new Set($o);import{jsx as ra,jsxs as na}from"react/jsx-runtime";var oa={resource:32,city:64},ia=["#739b58","#83a964","#668d52","#8baa68"],aa={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},la={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},sa=new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]),ca=new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]),ua=e=>{let t=F(e.config.gridSize),r=Math.max(20,e.config.tileWidth??80),n=Math.max(10,e.config.tileHeight??40),o=e.config.terrainColors?.length?e.config.terrainColors:ia,i=e.dimensions.width/2,a=(e.dimensions.height-t*n)/2+n/2,l=j(e.points,e.config).map(e=>({...e,x:i+r/2*(e.column-e.row),y:a+(e.column+e.row)*(n/2)}));return{nodes:l.map(t=>{let i=function(e,t){let r=S(e,t),n=function(e){return ca.has(e)?e:void 0}("string"==typeof r?r:S(r,"kind"));if(!n)return;if("string"==typeof r)return{kind:n};let o=S(r,"coverage"),i="number"==typeof o&&Number.isFinite(o)?Math.max(0,Math.min(1,o)):void 0,a=I(r,"fill");return{kind:n,...null==i?{}:{coverage:i},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":i?.kind??"land",l=i?.fill??I(e.config.terrainPalette,a)??I(aa,a)??aa.land,s=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:i?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:(c=a,I(la,c)??la.land),kind:"terrain",terrainKind:a,terrainCoverage:i?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};var c,u,d,h,f;return{type:"geoarea",pathData:(u=t.x,d=t.y,h=r,f=n,`M${u},${d-f/2}L${u+h/2},${d}L${u},${d+f/2}L${u-h/2},${d}Z`),centroid:[t.x,t.y],bounds:[[t.x-r/2,t.y-n/2],[t.x+r/2,t.y+n/2]],screenArea:r*n/2,style:{fill:i||"urban"===a?l:o[t.terrainIndex%o.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:s,group:t.landmark?.kind??a,interactive:!0}}),overlays:ra(O,{tiles:l,tileWidth:r,tileHeight:n,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??32,citySize:e.config.citySpriteSize??64,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}},da={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},ha={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};import{jsx as fa}from"react/jsx-runtime";var ma=e=>{let t=e.config,r=t.source??"auto",n="areas"===r||"auto"===r&&e.areas.length>0,o=(n?function(e){return e.areas.map((t,r)=>{let n=function(e,t){let r=e.properties&&"object"==typeof e.properties?e.properties:{},n=e.id??r.id??r.name??"area-"+t;return{...r,id:n+""}}(t,r),o=e.scales.geoPath.centroid(t),i=Number.isFinite(o[0])&&Number.isFinite(o[1])?e.scales.invertedPoint(o[0],o[1]):null;return{datum:{...n,gridLongitude:i?.[0],gridLatitude:i?.[1]},x:o[0],y:o[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t}))).filter((e,r)=>!t.filter||t.filter(e.datum,r)),i=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;let r=e.map(e=>({datum:e,x:Number(V(e,t.columnAccessor)),y:Number(V(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return r.length!==e.length?null:r.map(e=>({...e,row:e.y,column:e.x}))}(o.map(e=>e.datum),t),a=n?o:function(e){return e.points.map(t=>{let r=Number(V(t,e.config.longitudeAccessor,["lon","longitude"])),n=Number(V(t,e.config.latitudeAccessor,["lat","latitude"])),o=Number.isFinite(r)&&Number.isFinite(n)?e.scales.projectedPoint(r,n):null;return{datum:t,x:o?.[0]??NaN,y:o?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:o.map(e=>e.datum)}),l=i??D(a,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===l.length)return{nodes:[]};let s=P(l.map(e=>e.row)),c=P(l.map(e=>e.column)),u=Math.max(1,Math.round(s[1]-s[0])+1),d=Math.max(1,Math.round(c[1]-c[0])+1),h=Math.max(0,t.layoutPadding??8),f=Math.max(1,e.dimensions.width-2*h)/d,m=Math.max(1,e.dimensions.height-2*h)/u,p=(e.dimensions.width-f*d)/2,g=(e.dimensions.height-m*u)/2,y=T(t.cellPadding??.12,0,.8),x=Math.max(1,.5*Math.min(f,m)*(1-y)),b=t.sizeAccessor?l.map(e=>Number(V(e.datum,t.sizeAccessor))):[],M=t.sizeDomain??P(b),w=t.sizeRange??[.36,1],v=T(Math.min(w[0],w[1]),.05,1),k=T(Math.max(w[0],w[1]),v,1),$=l.map((r,n)=>{let o={...r.datum,gridRow:r.row,gridColumn:r.column},i=(V(o,t.idAccessor,["id","key","name"])??"grid-"+n)+"",a=(V(o,t.labelAccessor,["abbr","code","label","name","id"])??i)+"",l=Math.max(1,t.maxLabelLength??4),u=a.length>l?a.slice(0,l):a,d=V(o,t.categoryAccessor),h=null==d?void 0:d+"",y=V(o,t.fillAccessor),b=null!=y?y+"":h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",w=t.sizeAccessor?Number(V(o,t.sizeAccessor)):NaN,$=t.sizeAccessor&&Number.isFinite(w)?Math.sqrt(T(q(w,M),0,1)):1,A=x*(v+$*(k-v)),S="function"==typeof t.markStyle?t.markStyle(o,n):t.markStyle;return{datum:o,id:i,label:u,category:h,row:r.row,column:r.column,x:p+(r.column-c[0]+.5)*f,y:g+(r.row-s[0]+.5)*m,radius:A,style:{fill:b,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...S}}}),A=t.shape??"circle";return{nodes:$.map(e=>{return"circle"===A?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===A?H(e.x,e.y,e.radius):(t=e.x,r=e.y,n=e.radius,B([[t-n,r-n],[t+n,r-n],[t+n,r+n],[t-n,r+n]])),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===A?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0};var t,r,n}),overlays:!1===t.showLabels?null:fa(Y,{marks:$,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??T(.23*Math.min(f,m),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};import{geoBounds as pa,geoContains as ga}from"d3-geo";import{jsx as ya}from"react/jsx-runtime";var xa=new WeakMap,ba=new WeakMap,Ma=new WeakMap,wa=1,va=e=>{let t=function(e){let t=xa.get(e.areas);t||(t=new Map,xa.set(e.areas,t));let r=function(e){let t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",Z(t.featureFilter),Z(t.dotFilter),ae(e)].join("::")}(e),n=t.get(r);if(n)return n;let o=te(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){let e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(r,o),o}(e),r=e.config,n=r.shape??"circle",o=Math.max(.5,_(r.dotRadius)??t.cellSize*G(r.radiusRatio??.24,.05,.5)),i=r.gridOrigin?.[0]??0,a=r.gridOrigin?.[1]??0;return{nodes:t.dots.map((l,s)=>{let c=i+(l.gridColumn+.5)*t.cellSize,u=a+(l.gridRow+.5)*t.cellSize,d=X(l,r.categoryAccessor),h=X(l,r.fillAccessor),f={fill:null!=h?h+"":null!=d?e.resolveColor(d+""):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof r.markStyle?r.markStyle(l,s):r.markStyle},m=`dot-${l.gridRow}-${l.gridColumn}`;return"circle"===n?{type:"point",x:c,y:u,r:o,style:f,datum:l,interactive:!1,pointId:m,_transitionKey:m}:{type:"geoarea",pathData:"hexagon"===n?ce(c,u,o):se(c,u,o),centroid:[c,u],bounds:[[c-o,u-o],[c+o,u+o]],screenArea:"hexagon"===n?3*Math.sqrt(3)*o*o/2:(2*o)**2,style:f,datum:l,group:l.featureId,interactive:!1}}),overlays:r.showOutline?ya("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,n)=>{let o=e.scales.geoPath(t);return o?ya("path",{d:o,fill:"none",stroke:r.outlineStyle?.stroke??"currentColor",strokeOpacity:r.outlineStyle?.opacity??r.outlineStyle?.fillOpacity??.22,strokeWidth:r.outlineStyle?.strokeWidth??.7,strokeDasharray:r.outlineStyle?.strokeDasharray,strokeLinecap:r.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},U(t,n)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},ka=e=>{let t=e.config,r=t.nodeWidth??80,n=t.nodeHeight??30,o=t.orientation??"vertical",i=t.edgeCurve??"curved",a=!1!==t.showLabels,l=t.labelAccessor??"id",s="function"==typeof l?l:e=>xi(e,l,e.id??"")+"",c=new Map,u=[],d=[],h=e=>{let t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??r,h:("number"==typeof t.height?t.height:e.height)??n}};for(let r of e.nodes){let{x:n,y:o,w:i,h:l}=h(r);null==n||null==o||(c.set(r.id,{x:n,y:o,w:i,h:l}),u.push({type:"rect",x:n-i/2,y:o-l/2,w:i,h:l,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`,strokeWidth:1.5},datum:r,id:r.id,label:s(r)+""}),a&&d.push({x:n,y:o,text:s(r)+"",anchor:"middle",baseline:"middle",fontSize:11}))}let f=[];for(let t of e.edges){let r="string"==typeof t.target?t.target:t.target.id,n=c.get("string"==typeof t.source?t.source:t.source.id),a=c.get(r);if(!n||!a)continue;let l="vertical"===o?{x:n.x,y:n.y+n.h/2}:{x:n.x+n.w/2,y:n.y},s="vertical"===o?{x:a.x,y:a.y-a.h/2}:{x:a.x-a.w/2,y:a.y};if("line"===i)f.push({type:"line",x1:l.x,y1:l.y,x2:s.x,y2:s.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t});else{let r=(l.y+s.y)/2,n=(l.x+s.x)/2;f.push({type:"curved",pathD:"vertical"===o?`M${l.x},${l.y} C${l.x},${r} ${s.x},${r} ${s.x},${s.y}`:`M${l.x},${l.y} C${n},${l.y} ${n},${s.y} ${s.x},${s.y}`,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t})}}return{sceneNodes:u,sceneEdges:f,labels:d}},$a=e=>{let t=e.config,r=t.nodeWidth??100,n=t.nodeHeight??36,o=t.edgeStyle??"polyline",i=!1!==t.showLabels,a=t.labelAccessor??"label",l="function"==typeof a?a:e=>xi(e,a,e.id??"")+"",s=new Map,c=[],u=[],d=e=>{let t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??r,h:("number"==typeof t.height?t.height:e.height)??n}};for(let r of e.nodes){let{x:n,y:o,w:a,h:h}=d(r);null==n||null==o||(s.set(r.id,{x:n,y:o,w:a,h:h}),c.push({type:"rect",x:n-a/2,y:o-h/2,w:a,h:h,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,strokeWidth:1.5},datum:r,id:r.id,label:l(r)+""}),i&&u.push({x:n,y:o,text:l(r)+"",anchor:"middle",baseline:"middle",fontSize:11}))}let h=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`,f=[];for(let t of e.edges){let e="string"==typeof t.target?t.target:t.target.id,r=s.get("string"==typeof t.source?t.source:t.source.id),n=s.get(e);if(!r||!n)continue;let i=t.data??{},a=Array.isArray(i.points)?i.points:t.points;if(a&&a.length>=2)if("smooth"!==o||3>a.length){let e="M"+a.map(e=>`${e.x},${e.y}`).join(" L ");f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else{let e=`M${a[0].x},${a[0].y}`;for(let t=1;a.length-1>t;t++)e+=` Q${a[t].x},${a[t].y} ${(a[t].x+a[t+1].x)/2},${(a[t].y+a[t+1].y)/2}`;let r=a[a.length-1];e+=` T${r.x},${r.y}`,f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else f.push({type:"line",x1:r.x,y1:r.y,x2:n.x,y2:n.y,style:{stroke:h,strokeWidth:1},datum:t})}return{sceneNodes:c,sceneEdges:f,labels:u}};import{createElement as Aa}from"react";var Sa=e=>"number"==typeof e&&Number.isFinite(e),Ia=e=>{let t=e.config??{},r=t.mode??"primary",n=t.dimOpacity??.14,o=t=>e.selection?.isActive&&!e.selection.predicate(t)?n:1,i=e.nodes.map(e=>({id:e.id,data:be(e),wrapper:e})).sort((e,t)=>e.id.localeCompare(t.id)),a=e.edges.map(e=>({source:Me(e.source),target:Me(e.target),data:be(e),wrapper:e})).sort((e,t)=>e.source.localeCompare(t.source)||e.target.localeCompare(t.target)),l=pe(i,a,e.dimensions.plot,t),s="source-rooted"===t.lineMode?function(e,t,r,n){let o=new Set(e.map(e=>e.id)),i=new Map(e.map(e=>[e.id,0])),a=new Map(e.map(e=>[e.id,[]]));for(let e of t)!o.has(e.source)||!o.has(e.target)||(i.set(e.target,(i.get(e.target)??0)+1),a.get(e.source)?.push(e));for(let e of a.values())e.sort((e,t)=>e.target.localeCompare(t.target)||e.source.localeCompare(t.source));let l=e.filter(e=>0===(i.get(e.id)??0)).sort((e,t)=>e.id.localeCompare(t.id)),s=new Map,c=new Map(e.map(e=>[e.id,new Map]));for(let e of l){let t="function"==typeof r.labelAccessor?r.labelAccessor(e.data):xi(e.data,r.labelAccessor??"label",e.id),o={id:e.id,label:t+"",color:ve(e,r,n)},i=new Set,l=[e.id];for(;l.length>0;){let e=l.shift();if(!i.has(e)){i.add(e),c.get(e)?.set(o.id,o);for(let t of a.get(e)??[]){let e=s.get(t);e||(e=new Map,s.set(t,e)),e.set(o.id,o),i.has(t.target)||l.push(t.target)}}}}let u=e=>[...e].sort((e,t)=>e.id.localeCompare(t.id));return{byEdge:new Map(t.map(e=>[e,u(s.get(e)?.values()??[])])),byNode:new Map(e.map(e=>[e.id,u(c.get(e.id)?.values()??[])]))}}(i,a,t,e.resolveColor):void 0,c=function(e,t,r){let n=new Map;for(let o of e){let e=o.target>o.source?`${o.source}\0${o.target}`:`${o.target}\0${o.source}`,i=n.get(e);i||(i={key:e,source:o.source,target:o.target,lines:new Map},n.set(e,i));let a=o.data.lineOrder;Array.isArray(a)&&(i.authoredOrder=a.map(String));let l=r?.byEdge.get(o)??we(o,t);for(let e of l)i.lines.has(e.id)||i.lines.set(e.id,{descriptor:e,edge:o})}return[...n.values()].sort((e,t)=>e.key.localeCompare(t.key))}(a,t,s),u=new Map(i.map(e=>[e.id,new Set])),d=new Map;if(s)for(let[e,t]of s.byNode)for(let r of t)u.get(e)?.add(r.id),r.color&&d.set(r.id,r.color);let h=Math.max(1,t.lineWidth??("primary"===r?6:"compact"===r?3.5:2)),f=Math.max(0,t.lineGap??("primary"===r?2:"compact"===r?1:.5)),m=new Map,p=[];for(let r of c){let n=l.positions.get(r.source),i=l.positions.get(r.target);if(!n||!i)continue;let a=Ae(r,t),s=(a.length-1)/2*(h+f)+h/2;for(let e of[r.source,r.target])m.set(e,Math.max(m.get(e)??0,s));a.forEach((s,c)=>{u.get(r.source)?.add(s.descriptor.id),u.get(r.target)?.add(s.descriptor.id);let m=Se(s.edge,l,t,s.edge.source!==r.source),g=ye(m?[n,...m,i]:ge(n,i),(c-(a.length-1)/2)*(h+f)),y=Ie(s.edge,s.descriptor),x=ke(s.descriptor,s.edge,t,e.resolveColor);d.has(s.descriptor.id)||d.set(s.descriptor.id,x),p.push({type:"curved",id:`${r.key}:${s.descriptor.id}`,label:`${s.descriptor.label??s.descriptor.id}: ${s.edge.source} to ${s.edge.target}`,pathD:xe(g,t.cornerRadius??10),style:{fill:"none",stroke:x,strokeWidth:h,strokeLinecap:"round",opacity:o(y)},datum:y,accessibleDatum:y,accessibility:{label:`${s.descriptor.label??s.descriptor.id}, ${s.edge.source} to ${s.edge.target}`,tableFields:{line:s.descriptor.label??s.descriptor.id,source:s.edge.source,target:s.edge.target}}})})}let g=new Map,y=[],x=[],b=e=>(("function"==typeof t.labelAccessor?t.labelAccessor(e.data):xi(e.data,t.labelAccessor??"label",e.id))||e.id)+"";if("minimap"===r){let r=new Map;for(let e of i){let t=l.positions.get(e.id);if(!t)continue;let n=`${t.x}\0${t.y}`,o=r.get(n);o||(o={x:t.x,y:t.y,nodes:[],lineIds:new Set,bundleRadius:0},r.set(n,o)),o.nodes.push(e);for(let t of u.get(e.id)??[])o.lineIds.add(t);o.bundleRadius=Math.max(o.bundleRadius,m.get(e.id)??0)}let n=[...r.values()].sort((e,t)=>e.x-t.x||e.y-t.y||e.nodes[0].id.localeCompare(t.nodes[0].id));for(let r of n){let n=$e(r.lineIds,t),i=n.length>1||r.nodes.length>1||r.nodes.some(e=>!0===e.data.interchange||!0===e.data.transfer),a=i?t.interchangeRadius??Math.max(5,r.bundleRadius):t.stationRadius??Math.max(3.5,r.bundleRadius);for(let e of r.nodes)g.set(e.id,a);let l=r.nodes.map(b).join(" / "),s=r.nodes.map(e=>e.id).join("--"),c=1===r.nodes.length?r.nodes[0].data:qo(e=>{e("id",s),e("label",l),e("stationIds",r.nodes.map(e=>e.id)),e("stations",r.nodes.map(e=>e.data)),e("lineIds",n),e("interchange",i)}),u={label:`${l}${i?", interchange":""}`,tableFields:{station:l,lines:n.join(", ")}};n.length>1?(n.forEach((t,i)=>{let l={type:"arc",cx:r.x,cy:r.y,innerR:0,outerR:a,startAngle:-Math.PI/2+i/n.length*Math.PI*2,endAngle:-Math.PI/2+(i+1)/n.length*Math.PI*2,style:{fill:d.get(t)??e.resolveColor(t),stroke:"none",opacity:o(c)},datum:null,id:`${s}:${t}`};y.push(l)}),y.push({type:"circle",cx:r.x,cy:r.y,r:a,style:{fill:"transparent",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:o(c)},datum:c,accessibleDatum:c,accessibility:u,id:s,label:l})):y.push({type:"circle",cx:r.x,cy:r.y,r:a,style:{fill:(n[0]&&d.get(n[0]))??t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:o(c)},datum:c,accessibleDatum:c,accessibility:u,id:s,label:l})}}else for(let e of i){let n=l.positions.get(e.id);if(!n)continue;let i=$e(u.get(e.id)??[],t),a=i.length>1||!0===e.data.interchange||!0===e.data.transfer,s=a?t.interchangeRadius??Math.max("primary"===r?7:5,m.get(e.id)??0):t.stationRadius??("primary"===r?4:2.75);g.set(e.id,s);let c=b(e);if(y.push({type:"circle",cx:n.x,cy:n.y,r:s,style:null!=t.renderStation?{fill:"transparent",stroke:"transparent"}:{fill:t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:a?"primary"===r?3:2:1.5,opacity:o(e.data)},datum:e.data,accessibleDatum:e.data,accessibility:{label:`${c}${a?", interchange":""}`,tableFields:{station:c,lines:i.join(", ")}},id:e.id,label:c}),t.renderStation){let l=t.renderStation({station:e.data,x:n.x,y:n.y,radius:s,lineIds:i,interchange:a,mode:r});null!=l&&x.push(Aa("g",{key:e.id,opacity:o(e.data),style:{pointerEvents:"none"}},l))}}let M=x.length>0?Aa("g",{className:"transit-diagram-stations"},...x):void 0,w={sceneEdges:p,sceneNodes:y,overlays:M,labels:Ce(i,l.positions,u,g,e.dimensions.plot,"primary"===r?t:{...t,showLabels:!1})};return x.length>0||"minimap"===r?w:{...w,restyle:(e,t)=>t?.isActive&&!t.predicate(e.datum)?{opacity:n}:{opacity:1},restyleEdge:(e,t)=>t?.isActive&&!t.predicate(e.datum)?{opacity:n}:{opacity:1}}};import{jsx as Ca,jsxs as Na}from"react/jsx-runtime";import{jsx as za,jsxs as Fa}from"react/jsx-runtime";var Ea={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},ja={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"},Oa=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.layerAccessor??"x",o=t.rowAccessor??"y",i=t.partitionAccessor??"partition",a=t.semanticAccessor??"semantic",l=t.labelAccessor??"label",s=t.storesAccessor??"stores",c=t.backEdgeAccessor??"isBackEdge",u=t.edgeTypeAccessor??"edgeType",d={...Ea,...t.partitionColors},h={...ja,...t.edgeColors},f=t.accentColor??"var(--semiotic-focus, #ffcc33)",m=t.borderColor??"var(--semiotic-border, #555)",p=t.dimOpacity??.14,g=t.edgeOpacity??.5,y=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,M=t.storeChipColor??"var(--semiotic-info, #6a8caf)",w=t.hullGroupAccessor,v=t.layerCount,k=t.maxLayerSize;if(null==v||null==k){let t=0,r=new Map;for(let o of e.nodes){let e=Math.round(Number(xi(o,n,0)));t=Math.max(t,e),r.set(e,(r.get(e)??0)+1)}v=v??t+1,k=k??Math.max(1,...r.values())}let $=r.width/Math.max(1,v),A=r.height/Math.max(1,k),S=Math.min(t.nodeWidth??172,Math.max(8,$-(t.minGapX??26))),I=Math.min(t.nodeHeight??54,Math.max(8,A-(t.minGapY??18))),C=t.lod&&"auto"!==t.lod?t.lod:16>S?"dot":48>S?"icon":108>S?"compact":"full";if("dot"===C){let e=Math.min(S,I,11);S=e,I=e}let N=Math.max(1,r.width-S),z=Math.max(1,r.height-I),F=Math.max(1,k-1),E=e=>r.x+S/2+(v>1?e/(v-1):.5)*N,j=e=>r.y+I/2+(e+F/2)/F*z,O=t.reachableIds?new Set(t.reachableIds):null,R=t.selectedId??null,W=e.selection,L=new Map,T=new Map,P=[],q=null==w?null:new Map,D=[];for(let t of e.nodes){let e=t.id,r=Number(xi(t,n,0)),c=Number(xi(t,o,0)),u=xi(t,i,"processor")+"",h=xi(t,a,"processor")+"",g=xi(t,l,e)+"",y=Fe(xi(t,s,[])),x=t.data??t,b=E(r),M=j(c);L.set(e,{cx:b,cy:M});let v=O?O.has(e):null,k=W?.isActive?W.predicate(x):null,$=null!==v?!v:null!==k&&!k;T.set(e,$);let A=null!=R&&e===R,N=$&&!A?p:1,z=Object.prototype.hasOwnProperty.call(d,u)?d[u]:d.unknown;if("dot"===C?P.push({type:"circle",cx:b,cy:M,r:S/2,style:{fill:z,opacity:N,stroke:A?f:"transparent",strokeWidth:A?2:0},datum:t,id:e,label:g}):(P.push({type:"rect",x:b-S/2,y:M-I/2,w:S,h:I,style:{fill:z,opacity:N,stroke:A?f:m,strokeWidth:A?3:1},datum:t,id:e,label:g}),D.push({id:e,cx:b,cy:M,partition:u,semantic:h,label:g,stores:y,opacity:N,selected:A,node:x})),q&&null!=w){let r=xi(t,w,null);if(null!=r){let t=r+"",n=q.get(t)??[];n.push({id:e,x:b-S/2,y:M-I/2,w:S,h:I}),q.set(t,n)}}}let V=[];for(let t of e.edges){let e="string"==typeof t.source?t.source:t.source.id,r="string"==typeof t.target?t.target:t.target.id,n=L.get(e),o=L.get(r);if(!n||!o)continue;let i,a=!!xi(t,c,!1),l=xi(t,u,"internal")+"",s=T.get(e)||T.get(r)?Math.min(g,1.4*p):g,d=a?h.back:Object.prototype.hasOwnProperty.call(h,l)?h[l]:h.internal;if(a){let e=n.cx,t=n.cy+I/2,r=o.cx,a=o.cy+I/2,l=Math.max(48,.28*Math.abs(e-r))+I;i=`M${e},${t} C${e},${t+l} ${r},${a+l} ${r},${a}`}else{let e=n.cx+S/2,t=n.cy,r=o.cx-S/2,a=o.cy,l=(e+r)/2;i=`M${e},${t} C${l},${t} ${l},${a} ${r},${a}`}let f={type:"curved",pathD:i,style:{stroke:d,strokeWidth:a?x:y,fill:"none",opacity:s,...a?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:t};V.push(f)}let B=0===D.length?null:za("g",{className:"lineage-dag-glyphs",children:D.map(e=>function(e,t){let{w:r,h:n,lod:o}=t,i="icon"===o?Math.min(r,n):Math.min(n-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",l="icon"===o?0:8+i+8,s=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:i,color:a,node:e.node}):function(e,t,r){let n=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return Fa("g",{children:[za("rect",{width:r,height:r,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),za("text",{x:r/2,y:r/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*r,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:n})]})}(e.semantic,e.partition,i),c="full"===o,u="icon"!==o,d="full"===o&&t.showChips&&e.stores.length>0;return Fa("g",{transform:`translate(${e.cx-r/2}, ${e.cy-n/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[za("g",{transform:`translate(${"icon"===o?(r-i)/2:8}, ${(n-i)/2})`,children:s}),u&&za("foreignObject",{x:l,y:c?n/2-12:n/2-9,width:Math.max(8,r-l-8),height:18,style:{pointerEvents:"none"},children:za("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===o?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),c&&za("text",{x:l,y:n/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),d&&e.stores.map((e,r)=>za("rect",{x:l+15*r,y:n-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:za("title",{children:e.storeName})},e.storeName+r))]},e.id)}(e,{w:S,h:I,lod:C,partColors:d,chipColor:M,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel}))}),H=q&&q.size>0?function(e,t){let r=Array.from(e.entries()).sort(([e],[t])=>t>e?-1:e>t?1:0);return Ca("g",{className:"lineage-dag-hulls","aria-hidden":"true",style:{pointerEvents:"none"},children:r.map(([e,r])=>{let n=function(e,t){if(0===t||3>e.length)return e;let r=0>e.reduce((t,r,n)=>{let o=e[(n+1)%e.length];return t+r.x*o.y-o.x*r.y},0)?-1:1;return e.map((n,o)=>{let i=e[(o-1+e.length)%e.length],a=e[(o+1)%e.length],l=Math.hypot(n.x-i.x,n.y-i.y)||1,s=Math.hypot(a.x-n.x,a.y-n.y)||1,c=r>0?{x:(n.y-i.y)/l,y:-(n.x-i.x)/l}:{x:-(n.y-i.y)/l,y:(n.x-i.x)/l},u=r>0?{x:(a.y-n.y)/s,y:-(a.x-n.x)/s}:{x:-(a.y-n.y)/s,y:(a.x-n.x)/s},d={x:c.x+u.x,y:c.y+u.y},h=Math.hypot(d.x,d.y);if(1e-9>h)return{x:n.x+u.x*t,y:n.y+u.y*t};let f=d.x/h,m=d.y/h,p=t/Math.max(1e-6,f*u.x+m*u.y);return{x:n.x+f*p,y:n.y+m*p}})}(function(e){let t=e.slice().sort((e,t)=>e.x-t.x||e.y-t.y).filter((e,t,r)=>0===t||e.x!==r[t-1].x||e.y!==r[t-1].y);if(2>=t.length)return t;let r=[];for(let e of t){for(;r.length>=2&&0>=Ne(r[r.length-2],r[r.length-1],e);)r.pop();r.push(e)}let n=[];for(let e=t.length-1;e>=0;e--){let r=t[e];for(;n.length>=2&&0>=Ne(n[n.length-2],n[n.length-1],r);)n.pop();n.push(r)}return r.pop(),n.pop(),r.concat(n)}(r.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding),o=function(e,t){if(0===e.length)return"";if(3>e.length||0===t)return e.map((e,t)=>`${0===t?"M":"L"}${ze(e.x)},${ze(e.y)}`).join(" ")+" Z";let r=e.map((r,n)=>{let o=e[(n-1+e.length)%e.length],i=e[(n+1)%e.length],a=Math.hypot(o.x-r.x,o.y-r.y)||1,l=Math.hypot(i.x-r.x,i.y-r.y)||1,s=Math.min(t,a/2,l/2);return{point:r,incoming:{x:r.x+(o.x-r.x)/a*s,y:r.y+(o.y-r.y)/a*s},outgoing:{x:r.x+(i.x-r.x)/l*s,y:r.y+(i.y-r.y)/l*s}}}),n=r[0].outgoing,o=`M${ze(n.x)},${ze(n.y)}`;for(let e=1;r.length>e;e++){let t=r[e];o+=` L${ze(t.incoming.x)},${ze(t.incoming.y)}`,o+=` Q${ze(t.point.x)},${ze(t.point.y)} ${ze(t.outgoing.x)},${ze(t.outgoing.y)}`}let i=r[0];return o+=` L${ze(i.incoming.x)},${ze(i.incoming.y)}`,o+=` Q${ze(i.point.x)},${ze(i.point.y)} ${ze(i.outgoing.x)},${ze(i.outgoing.y)} Z`,o}(n,t.radius),i=Object.prototype.hasOwnProperty.call(t.colors??{},e)?t.colors?.[e]??t.resolveColor(e):t.resolveColor(e),a=r.every(e=>!0===t.dimById.get(e.id)&&e.id!==t.selectedId),l=Math.min(...n.map(e=>e.x)),s=Math.min(...n.map(e=>e.y)),c=t.label?.(e);return Na("g",{"data-lineage-hull":e,opacity:a?t.dimOpacity:void 0,children:[Ca("path",{className:"lineage-dag-hull",d:o,fill:i,fillOpacity:t.fillOpacity,stroke:i,strokeOpacity:t.strokeOpacity,strokeWidth:1,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"none"}}),c?Ca("text",{className:"lineage-dag-hull-label",x:l+8,y:s+14,fill:i,fillOpacity:Math.max(t.strokeOpacity,.7),fontSize:11,fontWeight:600,style:{pointerEvents:"none"},children:c}):null]},e)})})}(q,{colors:t.hullColors,padding:null==t.hullPadding?16:ai(t.hullPadding),radius:null==t.hullRadius?12:ai(t.hullRadius),fillOpacity:Ee(t.hullFillOpacity,.08),strokeOpacity:Ee(t.hullStrokeOpacity,.4),label:t.hullLabel,resolveColor:e.resolveColor,dimById:T,selectedId:R,dimOpacity:p}):null;return H?{sceneNodes:P,sceneEdges:V,backgrounds:H,overlays:B}:{sceneNodes:P,sceneEdges:V,overlays:B}};import{jsx as Ra,jsxs as Wa}from"react/jsx-runtime";var La={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"},Ta=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.direction??"TD",o="LR"===n||"RL"===n,i="BT"===n||"RL"===n,a=t.layerAccessor??"layer",l=t.rowAccessor??"row",s=t.labelAccessor??"label",c=t.shapeAccessor??"shape",u=t.edgeLabelAccessor??"label",d=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",f=t.textColor??"var(--semiotic-text, #e6e6e6)",m=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",p=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};let g=new Map,y=0;for(let t of e.nodes){let e=Math.round(Number(xi(t,a,0)));y=Math.max(y,e);let r=g.get(e)||[];r.push(t),g.set(e,r)}let x=y+1,b=1;for(let e of g.values())e.sort((e,t)=>Number(xi(e,l,0))-Number(xi(t,l,0))),b=Math.max(b,e.length);let M=o?r.width:r.height,w=o?r.height:r.width,v=M/x,k=w/(b+1),$=Math.max(44,Math.min(t.nodeWidth??150,o?v-36:.92*k)),A=Math.max(26,Math.min(t.nodeHeight??46,o?.7*k:.5*v)),S=(o?$:A)/2+6,I=Math.max(1,M-2*S),C=e=>(o?r.x:r.y)+S+(x>1?(i?x-1-e:e)/(x-1)*I:I/2),N=new Map,z=[],F=[];for(let[e,t]of g)t.forEach((n,i)=>{let a=C(e),l=(o?r.y:r.x)+(i+1)/(t.length+1)*w,u=o?a:l,m=o?l:a,g=xi(n,c,"rect")+"",y=xi(n,s,n.id)+"";N.set(n.id,{cx:u,cy:m,shape:g}),z.push({type:"rect",x:u-$/2,y:m-A/2,w:$,h:A,style:{fill:"transparent",stroke:"transparent"},datum:{id:n.id,name:y,type:La[g]??"process",shape:g},id:n.id,label:y}),F.push(Wa("g",{children:[Oe(g,u,m,$,A,d,"diamond"===g?p:h,1.5),Ra("text",{x:u,y:m,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:f,style:{pointerEvents:"none"},children:je(y,Math.max(4,Math.floor(($-12)/7)))})]},"n-"+n.id))});let E=[];return e.edges.forEach((e,t)=>{let r="string"==typeof e.target?e.target:e.target.id,n=N.get("string"==typeof e.source?e.source:e.source.id),i=N.get(r);if(!n||!i)return;let a=o?n.cx+$/2:n.cx,l=o?n.cy:n.cy+A/2,s=o?i.cx-$/2:i.cx,c=o?i.cy:i.cy-A/2,d=o?`M${a},${l} C${(a+s)/2},${l} ${(a+s)/2},${c} ${s},${c}`:`M${a},${l} C${a},${(l+c)/2} ${s},${(l+c)/2} ${s},${c}`,p=Math.atan2(c-l,s-a),g=s-9*Math.cos(p),y=c-9*Math.sin(p),x=4.5*-Math.sin(p),b=4.5*Math.cos(p),M=`${s},${c} ${g+x},${y+b} ${g-x},${y-b}`,w=xi(e,u,void 0),v=(a+s)/2,k=(l+c)/2;E.push(Wa("g",{children:[Ra("path",{d:d,fill:"none",stroke:m,strokeWidth:1.4}),Ra("polygon",{points:M,fill:m}),"string"==typeof w&&w.length>0&&Wa("g",{children:[Ra("rect",{x:v-6.5*w.length/2-4,y:k-9,width:6.5*w.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),Ra("text",{x:v,y:k,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:f,style:{pointerEvents:"none"},children:w})]})]},"e-"+t))}),{sceneNodes:z,overlays:Wa("g",{className:"mermaid-dag",children:[E,F]})}};import{jsx as Pa,jsxs as qa}from"react/jsx-runtime";var Da=new ko(8),Va=e=>{let t=e.config||{},r=e.dimensions.plot;if(!e.nodes.length)return{sceneNodes:[]};let n=t.sourceAccessor??"source",o=t.targetAccessor??"target",i=t.labelAccessor??"label",a=t.categoryAccessor??"category",l=t.nodeRadius??4,s=t.cellGap??16,c=t.bandGap??22,u=t.headerHeight??34,d=t.minCellForFull??38,h=t.maxCellSize??120,f=t.minCellSize??12,m=t.fingerprintRounds??3,p=!1!==t.groupByMotif,g=t.sort??"frequency",y=new Map,x=new Map,b=[];for(let t of e.nodes){let e=t.id;null==e||y.has(e)||(b.push(e),y.set(e,t.data??t),x.set(e,xi(t,a,"")+""))}let M=[];for(let t of e.edges){let e=Le(t.source??xi(t,n,void 0)),r=Le(t.target??xi(t,o,void 0));null==e||null==r||M.push({source:e,target:r})}let{outAdj:w,inAdj:v,undirected:k}=De(b,M),$=Ve(b,w,v,k,m),A=new Map;if(p)for(let e of $){let t=A.get(e.motif);t?t.push(e):A.set(e.motif,[e])}else A.set("all",[...$].sort((e,t)=>t.nodeCount-e.nodeCount));let S=[...A.entries()];S.sort((e,t)=>"size"===g?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===g?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);let I=We(b.join(",")+"|"+[...w.entries()].map(([e,t])=>e+">"+[...t].sort().join(".")).join(";")),C=Si([Math.round(r.x),Math.round(r.y),Math.round(r.width),Math.round(r.height),s,c,u,d,h,f,m,p,g,l,S.map(([e,t])=>e+":"+t.length).join(","),I]),N=Da.getOrCompute(C,()=>function(e,t){let{plot:r}=t,n=Math.max(40,r.width),{cell:o,cols:i}=(()=>{for(let o=t.maxCellSize;o>=t.minCellSize;o-=2){let i=Math.max(1,Math.floor((n+t.cellGap)/(o+t.cellGap))),a=0;for(let[,r]of e)a+=t.headerHeight+Math.ceil(r.length/i)*(o+t.cellGap)+t.bandGap;if(r.height>=a)return{cell:o,cols:i}}return{cell:t.minCellSize,cols:Math.max(1,Math.floor((n+t.cellGap)/(t.minCellSize+t.cellGap)))}})(),a=[],l=[],s=r.y;for(let[c,u]of e){let e=Math.ceil(u.length/i),d=s,h=d+t.headerHeight,f=o>=t.minCellForFull;u.forEach((e,n)=>{let l=r.x+n%i*(o+t.cellGap),s=h+Math.floor(n/i)*(o+t.cellGap);if(f){let r=Pe(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,{x:l,y:s,width:o,height:o},t.nodeRadius);a.push({component:e,lod:"full",cx:l+o/2,cy:s+o/2,glyphR:0,nodes:r.nodes,edges:r.edges})}else a.push({component:e,lod:"glyph",cx:l+o/2,cy:s+o/2,glyphR:Math.max(2.5,.36*o),nodes:[],edges:[]})});let m=Be(u[0],t,{x:r.x,y:d+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});l.push({motif:c,descriptor:qe(u[0]),count:u.length,directed:u[0].directed,x:r.x,y:d,width:n,height:t.headerHeight+e*(o+t.cellGap),exemplar:m}),s=h+e*(o+t.cellGap)+t.bandGap}return{cells:a,bands:l}}(S,{plot:r,cellGap:s,bandGap:c,headerHeight:u,minCellForFull:d,maxCellSize:h,minCellSize:f,nodeRadius:l,nodeDatum:y,nodeCategory:x,outAdj:w,inAdj:v})),z=e.theme.semantic||{},F=t.convergeColor??z.info??"#4c78a8",E=t.branchColor??z.warning??"#e8853a",j=t.edgeColor??z.border??"#9aa0aa",O=t.colorMode??"directedness",R={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},W=t=>"motif"===O?e.resolveColor(t.motif):"category"===O||t.directed?F:E,L=[],T=[];for(let t of N.cells){let r=t.component,n=W(r);if("full"===t.lod){for(let e of t.edges)T.push({type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:j,strokeWidth:1,opacity:.5},datum:null});for(let r of t.nodes){let t="category"===O&&r.category?e.resolveColor(r.category):n,o={type:"symbol",cx:r.cx,cy:r.cy,size:Math.PI*r.r*r.r,symbolType:"circle",style:{fill:t,opacity:Vo(r.datum,R)},datum:r.datum,id:r.id,label:xi(r.datum,i,r.id)+""};L.push(o)}}else{let e=Do({id:`motif-${r.motif}-${t.cx.toFixed(0)}-${t.cy.toFixed(0)}`,motif:r.motif,shape:qe(r),nodes:r.nodeCount,edges:r.edgeCount,sinks:r.sinkCount,sources:r.sourceCount,directedness:r.directed?"converging":"branching"}),o={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:r.directed?"circle":"diamond",style:{fill:n,opacity:Vo(e,R),stroke:j,strokeWidth:.75},datum:e,id:e.id+"",label:qe(r)};L.push(o)}}return{sceneNodes:L,sceneEdges:T,overlays:function(e,t){let r=[];for(let n of e){let e=n.directed?t.convergeColor:t.branchColor;if(r.push(vi({keyId:"band-"+n.motif,x:n.x-6,y:n.y-4,width:n.width+12,height:n.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})),t.showExemplars&&n.exemplar){let o=n.exemplar;r.push(qa("g",{style:{pointerEvents:"none"},children:[o.edges.map((e,r)=>Pa("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},"exe-"+r)),o.nodes.map(t=>Pa("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},"exn-"+t.id))]},"ex-"+n.motif))}if(t.showBandLabels){let e=n.x+(t.showExemplars?48:4);r.push(Pa("text",{x:e,y:n.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:n.descriptor},"bl-"+n.motif)),r.push(Pa("text",{x:e,y:n.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${n.count} · ${n.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},"bc-"+n.motif))}}if(t.showLegend){let e=t.plot.x+t.plot.width-168,i=t.plot.y-2;r.push(qa("g",{style:{pointerEvents:"none"},children:[Pa("circle",{cx:e,cy:i,r:5,fill:t.convergeColor}),Pa("text",{x:e+10,y:i+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),Pa("path",{d:(n=e,o=i+18,`M${n},${o-5} L${n+5},${o} L${n},${o+5} L${n-5},${o} Z`),fill:t.branchColor}),Pa("text",{x:e+10,y:i+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}var n,o;return Pa("g",{className:"net-ensemble-overlays",children:r})}(N.bands,{convergeColor:F,branchColor:E,edgeColor:j,plot:r,showBandLabels:!1!==t.showBandLabels,showExemplars:!1!==t.showExemplars,showLegend:!1!==t.showLegend&&"directedness"===O,textColor:z.text??"var(--semiotic-text, #1a1a1a)",subText:z.textSecondary??"var(--semiotic-text-secondary, #888)"})}};import*as Ba from"react";var Ha=e=>{let t=e.config??{},r=e.dimensions.plot,n=e.nodes.map((e,t)=>({id:e.id,datum:He(e),inputIndex:t})),o=new Map(n.map(e=>[e.id,e.inputIndex])),i=new Map((t.order??[]).map((e,t)=>[e+"",t]));if(n.sort((e,t)=>{let r=i.get(e.id),n=i.get(t.id);return null!=r&&null!=n?r-n:null!=r?-1:null!=n?1:(o.get(e.id)??0)-(o.get(t.id)??0)}),0===n.length)return{sceneNodes:[],sceneEdges:[],labels:[]};let a=Math.max(0,t.padding??18),l=Math.max(1,Math.min(r.width,r.height)-2*a),s=Math.min(Math.max(1,t.maxCellSize??120),l/n.length),c=s*n.length,u=r.x+(r.width-c)/2,d=r.y+(r.height-c)/2,h=Math.max(4,Math.min(.76*s,t.nodeSize??.56*s)),f=h/2,m=n.map((e,r)=>{let n="function"==typeof t.labelAccessor?t.labelAccessor(e.datum):xi(e.datum,t.labelAccessor??"label",e.id)+"";return{id:e.id,label:n,datum:e.datum,index:r,cx:u+(r+.5)*s,cy:d+(r+.5)*s}}),p=new Map(m.map(e=>[e.id,e])),g=new Map(m.map(e=>[e.id,e.index])),y=function(e,t,r){let n=new Map;for(let o of e){let e=Ye(o.source),i=Ye(o.target),a=t.get(e),l=t.get(i);if(null==a||null==l)continue;let s=He(o),c=Ge("function"==typeof r.valueAccessor?r.valueAccessor(s):xi(s,r.valueAccessor??"value",o.value??1),0);if(0>=c)continue;let u=n.get(e);u||(u=new Map,n.set(e,u));let d=u.get(i);d?(d.value+=c,d.edgeCount+=1,d.memberEdges.push(s)):u.set(i,{key:`${a}-${l}`,source:e,target:i,sourceIndex:a,targetIndex:l,value:c,edgeCount:1,memberEdges:[s],datum:s,width:1,color:""})}let o=[...n.values()].flatMap(e=>[...e.values()]);for(let e of o)e.datum=qo(t=>{for(let[r,n]of Object.entries(e.memberEdges[0]??{}))t(r,n);t("source",e.source),t("target",e.target),t("value",e.value),t("edgeCount",e.edgeCount),t("internal",e.source===e.target),t("memberEdges",e.memberEdges)});return o}(e.edges,g,t),x=function(e,t,r){let n=new Map,o=(e,t)=>{let r=n.get(e);r?r.push(t):n.set(e,[t])};for(let t of e)o(Ue(t.source,t.sourceIndex>t.targetIndex?"out-left":"out-right"),t),o(Ue(t.target,t.targetIndex>t.sourceIndex?"in-top":"in-bottom"),t);for(let[e,t]of n){let r=e.startsWith("out-");t.sort((e,t)=>(r?e.targetIndex:e.sourceIndex)-(r?t.targetIndex:t.sourceIndex)||e.key.localeCompare(t.key))}let i=Qe(t,r),a=null==r.flowScale?1/0:Math.max(0,r.flowScale);if(null==r.flowScale){for(let e of n.values()){let n=e.reduce((e,t)=>e+t.value,0),o=Ze(e.length,t,r);n>0&&(a=Math.min(a,Math.max(.1,i-o*Math.max(0,e.length-1))/n))}Number.isFinite(a)||(a=1)}let l=Math.max(0,r.minFlowWidth??1.25),s=Math.max(l,r.maxFlowWidth??1/0);for(let t of e)t.width=Math.min(s,Math.max(l,t.value*a));let c=1;for(let e of n.values()){let n=e.reduce((e,t)=>e+t.width,0),o=Ze(e.length,t,r);n>0&&(c=Math.min(c,Math.max(.1,i-o*Math.max(0,e.length-1))/n))}if(1>c)for(let t of e)t.width*=c;return n}(y,h,t),b=function(e,t,r,n){let o=new Map;for(let[i,a]of e){let e=i.slice(i.indexOf("\0")+1),l=t.get(e);if(!l)continue;let s=i.startsWith("out-")?l.cy:l.cx,c=Ze(a.length,r,n),u=s-(a.reduce((e,t)=>e+t.width,0)+c*Math.max(0,a.length-1))/2;for(let e of a){let t=u+e.width/2,r=i.startsWith("out-");o.set(`${e.key}:${r?"source":"target"}`,t),u+=e.width+c}}return o}(x,p,h,t),M=e.theme.semantic.info??e.theme.semantic.primary??e.resolveColor("adjacency-flow"),w=e.theme.semantic.text??"var(--semiotic-text, currentColor)",v=e.theme.semantic.surface??"var(--semiotic-bg, white)",k=e.theme.semantic.border??"var(--semiotic-border, currentColor)",$=e.theme.semantic.grid??k,A=e.theme.semantic.primary??e.resolveColor("adjacency-flow-node"),S=t.valueFormat??(e=>Math.round(100*e)/100+""),I=Math.max(0,Math.min(t.cornerRadius??10,.22*s)),C=new Map(m.map(e=>[e.id,0])),N=new Map(m.map(e=>[e.id,0])),z=[],F=[],E=[];for(let r of y){let n=p.get(r.source),o=p.get(r.target);if(!n||!o)continue;C.set(n.id,(C.get(n.id)??0)+r.value),N.set(o.id,(N.get(o.id)??0)+r.value);let i=t.colorMode??"single",a="function"==typeof t.edgeColor?t.edgeColor(r.datum):void 0;r.color=a??("string"==typeof t.edgeColor?t.edgeColor:void 0)??("source"===i?e.resolveColor(r.source):"target"===i?e.resolveColor(r.target):"edge"===i?e.resolveColor(`${r.source}→${r.target}`):M);let l,c,h,m,g,y,x,k=b.get(r.key+":source")??n.cy,$=b.get(r.key+":target")??o.cx;if(r.targetIndex>r.sourceIndex){let e=[n.cx+f,k],t=[$,o.cy-f];l=[e,[t[0],e[1]],t],c=t[0],h=e[1]+.68*(t[1]-e[1]),m=Math.PI/2,g=t[0]-I-4,y=e[1]-r.width/2-3,x="end"}else if(r.sourceIndex>r.targetIndex){let e=[n.cx-f,k],i=[$,o.cy+f];l=[e,[i[0],e[1]],i],c=i[0],h=e[1]+.68*(i[1]-e[1]),m=-Math.PI/2,g=i[0]+I+4,y=e[1]+r.width/2+(t.valueFontSize??10),x="start"}else{let e=u+(n.index+1)*s,t=d+(n.index+1)*s,i=Math.max(2,Math.min(6,.07*s)),a=Math.max(n.cx+f+2,e-i),p=Math.max(n.cy+f+2,t-i),b=[n.cx+f,k],M=[$,o.cy+f];l=[b,[a,b[1]],[a,p],[M[0],p],M],c=(a+M[0])/2,h=p,m=Math.PI,g=a-3,y=p-r.width/2-3,x="end"}let A=Xe(l,I);if(E.push({type:"curved",id:"adjacency-flow-"+r.key,label:`${n.label} to ${o.label}: ${S(r.value,r.datum)}`,pathD:A,style:{fill:"none",stroke:r.color,strokeWidth:r.width,opacity:.82,cursor:"pointer"},datum:r.datum,accessibleDatum:r.datum,accessibility:{label:`${n.label} to ${o.label}, ${S(r.value,r.datum)}`,tableFields:{source:n.label,target:o.label,value:r.value,edges:r.edgeCount}}}),(t.showValues??!0)&&F.push({x:g,y:y,text:S(r.value,r.datum),anchor:x,fontSize:t.valueFontSize??Math.max(7,Math.min(10,.14*s)),fontWeight:650,fill:w,stroke:v,strokeWidth:3,paintOrder:"stroke"}),t.showArrows??!0){let e=Math.min(Math.max(0,t.arrowSize??14),Math.max(0,r.width-2));if(2>=e)continue;z.push(Ba.createElement("path",{key:"arrow-"+r.key,className:"semiotic-adjacency-flow-arrow",d:Ke(c,h,m,Math.max(3,1.08*e),e),fill:t.arrowColor??"var(--semiotic-adjacency-flow-arrow-fill, rgba(255, 255, 255, 0.72))",stroke:"none","data-edge-width":r.width,"data-arrow-width":e,"aria-hidden":!0,focusable:!1,pointerEvents:"none",opacity:1}))}}let j=m.map(r=>{let n=("function"==typeof t.nodeColor?t.nodeColor(r.datum,r.index):void 0)??("string"==typeof t.nodeColor?t.nodeColor:"source"===(t.colorMode??"single")?e.resolveColor(r.id):A);return{type:"rect",id:r.id,label:r.label,x:r.cx-f,y:r.cy-f,w:h,h:h,style:{fill:n,stroke:t.nodeStroke??k,strokeWidth:1.25,cursor:"pointer"},datum:r.datum,accessibleDatum:r.datum,accessibility:{label:`${r.label}, step ${r.index+1}`,tableFields:{step:r.index+1,node:r.label,incoming:N.get(r.id)??0,outgoing:C.get(r.id)??0}}}}),O=Math.max(2,t.maxLabelLength??14),R=m.map(e=>{return{x:e.cx,y:e.cy,text:(r=e.label,n=O,r.length>n?r.slice(0,Math.max(1,n-1))+"…":r),anchor:"middle",baseline:"middle",fontSize:t.labelFontSize??Math.max(6,Math.min(15,.34*h,h/Math.max(1.8,.62*e.label.length))),fontWeight:750,fill:t.nodeTextColor??v};var r,n}),W=null;if(t.showGrid??!0){let e=[];for(let t=0;m.length>=t;t+=1){let r=u+t*s,n=d+t*s;e.push(Ba.createElement("line",{key:"grid-v-"+t,x1:r,y1:d,x2:r,y2:d+c,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}),Ba.createElement("line",{key:"grid-h-"+t,x1:u,y1:n,x2:u+c,y2:n,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}))}W=Ba.createElement(Ba.Fragment,null,...e)}return{sceneEdges:E,sceneNodes:j,labels:[...F,...R],backgrounds:W,overlays:Ba.createElement(Ba.Fragment,null,...z)}};import{jsx as Ya,jsxs as Ga}from"react/jsx-runtime";var _a=new ko(12),Xa=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.columnAccessor??"column",o=t.rowAccessor??"row",i=t.sizeAccessor,a=t.colorAccessor,l=t.symbolAccessor,s=t.shadeAccessor,c=t.markerAccessor,u=t.iconAccessor,d=t.defaultSymbol??"circle",[h,f]=t.sizeRange??[2,8],m=t.shadeStrength??.72,p=t.shadeReverse??!1,g=t.rowMode??"banded",y=t.cellSizing??"proportional",x=t.proportionExponent??1,b=t.columnGap??16,M=t.rowGap??12,w=t.packPadding??1,v=t.iterations??12,k=!1!==t.showEnclosures,$=!1!==t.showColumnHeaders,A=!1!==t.showRowLabels,S=$?t.headerHeight??26:0,I=A?t.labelWidth??66:0,C=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,N=r.x+I,z=r.y+S,F=Math.max(1,r.width-I),E=Math.max(1,r.height-S-C),j=[];for(let t of e.nodes){let e=t.data??t;j.push({id:t.id,col:xi(t,n,"—")+"",row:xi(t,o,"—")+"",sizeVal:i?Number(xi(t,i,1)):1,colorKey:a?xi(t,a,"")+"":"",symVal:l?xi(t,l,"")+"":"",shadeVal:s?ot(xi(t,s,null)):NaN,marker:!!c&&!!xi(t,c,!1),iconVal:u?xi(t,u,"")+"":"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===j.length)return{sceneNodes:[]};let O=1/0,R=-1/0;if(i)for(let e of j)Number.isFinite(e.sizeVal)&&(O>e.sizeVal&&(O=e.sizeVal),e.sizeVal>R&&(R=e.sizeVal));t.sizeDomain&&([O,R]=t.sizeDomain),(!Number.isFinite(O)||!Number.isFinite(R))&&(O=0,R=1);let W=e=>{if(O>=R)return(h+f)/2;let t=Math.sqrt(it((e-O)/(R-O),0,1));return h+t*(f-h)},L=1/0,T=-1/0;if(s)for(let e of j)Number.isFinite(e.shadeVal)&&(L>e.shadeVal&&(L=e.shadeVal),e.shadeVal>T&&(T=e.shadeVal));t.shadeDomain&&([L,T]=t.shadeDomain);let P=e=>{if(!s||!Number.isFinite(e)||L>=T)return.5;let t=it((e-L)/(T-L),0,1);return p?1-t:t},q=t.colorMap,D=new Map,V=(t,r)=>{let n=D.get(t);if(!n){let r=q&&Object.prototype.hasOwnProperty.call(q,t)&&"string"==typeof q[t]&&q[t]?q[t]:e.resolveColor(t);n=Jo(r,m),D.set(t,n)}return n(r)},B=new Map;if(t.symbolMap)for(let[e,r]of Object.entries(t.symbolMap))B.set(e,r);let H=0,Y=t.iconMap,G=e=>u&&Y&&Object.prototype.hasOwnProperty.call(Y,e)?Y[e]??null:null,_=e=>u?"circle":(e=>{if(!l)return d;let t=B.get(e);return t||(t=$o[H%$o.length],H++,B.set(e,t)),t})(e.symVal),X=t.maxAreaFraction??.4,K=0,U=Array(j.length),Q=Array(j.length);for(let e=0;j.length>e;e++){let t=j[e],r=W(t.sizeVal);U[e]=r,t.baseShape=_(t),t.iconShape=G(t.iconVal);let n=Ci(t.baseShape,Math.PI*r*r);Q[e]=n,K+=Math.PI*n*n}let Z=X*F*E,J=K>Z?Math.sqrt(Z/K):1;for(let e=0;j.length>e;e++){let t=j[e],r=U[e]*J;t.size=Math.PI*r*r,t.packR=Q[e]*J}let ee=new Map,te=new Map;for(let e of j)ee.set(e.col,(ee.get(e.col)??0)+1),te.set(e.row,(te.get(e.row)??0)+1);let re=t.columnOrder?.filter(e=>ee.has(e))??[...ee.keys()].sort((e,t)=>(ee.get(t)??0)-(ee.get(e)??0)),ne=t.rowOrder?.filter(e=>te.has(e))??[...te.keys()].sort((e,t)=>(te.get(t)??0)-(te.get(e)??0)),oe=Si([Math.round(r.x),Math.round(r.y),Math.round(r.width),Math.round(r.height),S,I,C,g,y,x,b,M,w,v,h,f,O,R,X,re.join(","),ne.join(","),j.length,at(j)]),ie=_a.getOrCompute(oe,()=>function(e,t){let r=new Map;for(let t of e){let e=r.get(t.col);e||(e=[],r.set(t.col,e)),e.push(t)}let n=t.columnOrder.filter(e=>r.has(e)),o=Math.max(1,t.innerW-t.columnGap*Math.max(0,n.length-1)),i=t.proportionExponent,a=n.map(e=>Math.pow(r.get(e).length,i)),l=a.reduce((e,t)=>e+t,0)||1,s=e=>"uniform"===t.cellSizing?o/n.length:a[e]/l*o,c=new Map,u=[],d=t.innerX;for(let e=0;n.length>e;e++)u.push({col:n[e],x:d,w:s(e)}),d+=s(e)+t.columnGap;let h=1,f=new Map,m=[],p=(e,t,r,n)=>{let o=f.get(e);o||(o={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,o)),o.minX>t-n&&(o.minX=t-n),t+n>o.maxX&&(o.maxX=t+n),o.minY>r-n&&(o.minY=r-n),r+n>o.maxY&&(o.maxY=r+n)},g=(e,r,n,o,i,a)=>{let l=e.map(e=>({id:e.id,r:e.packR})),s=function(e,t,r,n,o,i,a,l){let s=t+n/2,c=r+o/2,u=new Map,d=e.length;if(0===d)return u;if(1===d)return u.set(e[0].id,{px:s,py:c}),u;let h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(l),f=new Float64Array(d),m=0;for(let t=0;d>t;t++)f[t]=e[t].r+i,f[t]>m&&(m=f[t]);let p=Math.max(1,Math.round(Math.sqrt(d*n/Math.max(1,o)))),g=new Float64Array(d),y=new Float64Array(d),x=n/p,b=o/Math.ceil(d/p);for(let e=0;d>e;e++){let n=e%p,o=Math.floor(e/p);g[e]=t+(n+.3+.4*h())*x,y[e]=r+(o+.3+.4*h())*b}let M=Math.max(0,Math.min(a,14)),w=Math.max(1,2*m),v=new Map,k=Math.max(1,Math.ceil(n/w)+3),$=(e,t)=>(t+1)*k+(e+1);for(let e=0;M>e;e++){v.clear();for(let e=0;d>e;e++){let n=$(Math.floor((g[e]-t)/w),Math.floor((y[e]-r)/w)),o=v.get(n);o?o.push(e):v.set(n,[e])}for(let e=0;d>e;e++){let n=Math.floor((g[e]-t)/w),o=Math.floor((y[e]-r)/w);for(let t=-1;1>=t;t++)for(let r=-1;1>=r;r++){let i=v.get($(n+t,o+r));if(i)for(let t=0;i.length>t;t++){let r=i[t];if(e>=r)continue;let n=g[r]-g[e],o=y[r]-y[e],a=f[e]+f[r],l=n*n+o*o;if(a*a>l)if(l>1e-9){let t=Math.sqrt(l),i=(a-t)/2;n/=t,o/=t,g[e]-=n*i,y[e]-=o*i,g[r]+=n*i,y[r]+=o*i}else{let t=2.39996323*e;g[e]+=Math.cos(t)*f[e],y[e]+=Math.sin(t)*f[e]}}}}for(let e=0;d>e;e++){let i=f[e],a=t+i,l=t+n-i,u=r+i,d=r+o-i;g[e]=l>a?it(g[e],a,l):s,y[e]=d>u?it(y[e],u,d):c}}for(let t=0;d>t;t++)u.set(e[t].id,{px:g[t],py:y[t]});return u}(l,r,n,o,i,t.packPadding,t.iterations,h++),u=1/0,d=1/0,f=-1/0,m=-1/0;for(let e of l){let t=s.get(e.id);c.set(e.id,{px:t.px,py:t.py}),p(a,t.px,t.py,e.r),u>t.px-e.r&&(u=t.px-e.r),t.px+e.r>f&&(f=t.px+e.r),d>t.py-e.r&&(d=t.py-e.r),t.py+e.r>m&&(m=t.py+e.r)}return Number.isFinite(u)?{x:u-Ka,y:d-Ka,w:f-u+2*Ka,h:m-d+2*Ka}:null};if("banded"===t.rowMode){let o=new Map;for(let t of e)o.set(t.row,(o.get(t.row)??0)+1);let a=t.rowOrder.filter(e=>o.has(e)),l=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),s=a.map(e=>Math.pow(o.get(e),i)),d=s.reduce((e,t)=>e+t,0)||1,h=new Map,m=t.innerY+t.innerH;for(let e=0;a.length>e;e++){let r="uniform"===t.cellSizing?l/a.length:s[e]/d*l,n=m-r;h.set(a[e],{y:n,h:r}),m=n-t.rowGap}n.forEach((e,t)=>{let n=_o(r.get(e),e=>e.row);for(let e of a){let r=n.get(e),o=h.get(e);!r||!o||g(r,u[t].x,o.y,u[t].w,o.h,e)}});let p=[],y=new Map;for(let e of a){let t=h.get(e);y.set(e,t.y+t.h/2);let r=f.get(e);r&&Number.isFinite(r.minX)&&p.push({x:r.minX-Ka,y:r.minY-Ka,w:r.maxX-r.minX+2*Ka,h:r.maxY-r.minY+2*Ka})}return{positions:c,enclosures:p,colBands:u,rowLabelY:y}}let y=new Map;n.forEach((e,n)=>{let o=_o(r.get(e),e=>e.row),a=t.rowOrder.filter(e=>o.has(e)),l=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),s=a.map(e=>Math.pow(o.get(e).length,i)),c=s.reduce((e,t)=>e+t,0)||1,d=t.innerY+t.innerH;a.forEach((e,r)=>{let i="uniform"===t.cellSizing?l/a.length:s[r]/c*l,h=d-i,f=g(o.get(e),u[n].x,h,u[n].w,i,e);if(f){m.push(f);let t=y.get(e)??{sum:0,n:0};t.sum+=f.y+f.h/2,t.n+=1,y.set(e,t)}d=h-t.rowGap})});let x=new Map;for(let[e,t]of y)x.set(e,t.sum/t.n);return{positions:c,enclosures:m,colBands:u,rowLabelY:x}}(j,{columnOrder:re,rowOrder:ne,innerX:N,innerY:z,innerW:F,innerH:E,rowMode:g,cellSizing:y,proportionExponent:x,columnGap:b,rowGap:M,packPadding:w,iterations:v})),ae=e.selection,le=ae?.isActive?ae.predicate:null,se=t.highlight??null,ce=t.dimOpacity??.16,ue=t.markStroke,de=t.markStrokeWidth??0,he=t.markerColor??"#ffffff",fe=t.iconColor??"rgba(255,255,255,0.92)",me=t.iconStrokeWidth??1,pe=t.iconScale??.72,ge=[],ye=[],xe=[];for(let e of j){let t=ie.positions.get(e.id);if(!t)continue;let r=Vo(e.datum,{highlight:se,predicate:le,dimOpacity:ce}),n={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:V(e.colorKey,P(e.shadeVal)),opacity:r,...ue?{stroke:ue,strokeWidth:de}:{}},datum:e.datum,id:e.id,label:e.id+""};if(ge.push(n),e.iconShape){let n=Math.sqrt(e.size/Math.PI)*pe,o=Ci(e.iconShape,100);xe.push({x:t.px,y:t.py,size:o>0?n/o*100*(n/o):Math.PI*n*n,shape:e.iconShape,opacity:r})}e.marker&&r>ce+.001&&ye.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}let be=[];if(t.callouts&&t.callouts.length>0){let e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",n=r.y+r.height-(C>0?.45*C:9),o=[];for(let e=0;t.callouts.length>e;e++){let r=t.callouts[e],n=j.find(e=>e.datum[r.field]+""==r.value+"");if(!n)continue;let i=ie.positions.get(n.id);i&&o.push({c:r,ci:e,px:i.px,py:i.py,markR:Math.sqrt(n.size/Math.PI)})}let i=o.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;i.forEach((e,t)=>{a.set(e.ci,N+(t+.5)/i.length*F)});for(let t of o){let o=t.c,i=a.get(t.ci)??t.px,l=n,s=o.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof o.at&&o.at?(i=o.at.x,l=o.at.y):"number"==typeof o.at&&(l=r.y+o.at*r.height),be.push({keyId:"callout-"+t.ci,markX:t.px,markY:t.py,labelX:i,labelY:l,label:o.label,connector:s,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}let Me=function(e,t){let r=t.columnLabel??(e=>e),n=t.rowLabel??(e=>e);return Ga("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[t.showEnclosures&&e.enclosures.map((e,r)=>vi({keyId:"enc-"+r,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity})),t.iconMarks.length>0&&Ya("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,r)=>Ya("path",{d:Ni(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity},"ic-"+r))}),t.markerDots.length>0&&Ya("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,r)=>Ya("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor},"mk-"+r))}),t.showColumnHeaders&&e.colBands.map((e,n)=>zo({keyId:"col-"+n,text:r(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor})),t.showRowLabels&&[...e.rowLabelY].map(([e,r])=>zo({keyId:"row-"+e,text:n(e),x:t.labelX,y:r,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor})),t.callouts.map(e=>ei(e))]})}(ie,{markerDots:ye,markerColor:he,iconMarks:xe,iconColor:fe,iconStrokeWidth:me,callouts:be,plot:r,showEnclosures:k,showColumnHeaders:$,showRowLabels:A,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:r.y+.62*S,labelX:r.x+I-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel});return{sceneNodes:ge,overlays:Me}},Ka=4;import*as Ua from"react";var Qa=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height)return{nodes:[]};let n=wi(t.categoryAccessor),o=wi(t.stackBy),i=e=>{let r="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],n=Number(r);return Number.isFinite(n)&&n>0?n:0},a=t.gutter??2,l="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",s="string"==typeof t.stackBy?t.stackBy:"stack",c="string"==typeof t.valueAccessor?t.valueAccessor:"value",u=(e,t,r)=>qo(n=>{n("category",e),n("stack",t),n("value",r),"category"!==l&&n(l,e),"stack"!==s&&n(s,t),"value"!==c&&n(c,r)}),d=!1!==t.showCategoryLabels,h=Math.max(0,r.height-(t.labelPadding??(d?22:0))),f=[],m=new Map,p=[],g=new Set,y=new Map;for(let t of e.data){let e=n(t)+"",r=o(t)+"",a=i(t);m.has(e)||(f.push(e),m.set(e,0),y.set(e,new Map)),g.has(r)||(g.add(r),p.push(r)),m.set(e,(m.get(e)??0)+a);let l=y.get(e);l.set(r,(l.get(r)??0)+a)}let x=t.categoryOrder?lt(t.categoryOrder,f,e=>m.has(e)):f,b=t.stackOrder?lt(t.stackOrder,p,()=>!0):p,M=x.reduce((e,t)=>e+(m.get(t)??0),0);if(0>=M)return{nodes:[]};let w=Math.max(0,r.width-a*Math.max(0,x.length-1)),v=[],k=[],$=r.x;for(let t of x){let n=m.get(t)??0,o=n/M*w;if(0>=o)continue;k.push({cat:t,x:$,w:o});let i=y.get(t),l=r.y;for(let r of b){let a=i.get(r)??0;if(0>=a)continue;let s=a/n*h;v.push({type:"rect",x:$,y:l,w:o,h:s,style:{fill:e.resolveColor(r),stroke:"none"},datum:u(t,r,a),group:r}),l+=s}$+=o+a}return{nodes:v,overlays:d&&k.length>0?function(e,t,r){let n=e.map((e,n)=>zo({keyId:"marimekko-label-"+n,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:r}));return Ua.createElement(Ua.Fragment,null,...n)}(k,r.y+h+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null}};import*as Za from"react";var Ja=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length)return{nodes:[]};let n=t.rowHeight??28,o=t.rowGap??12,i=!1!==t.showLabels,a=i?t.labelWidth??120:0,l=!1!==t.showTicks,s=l?14:0,c=t.tickFormat??(e=>e.toLocaleString()),u=r.x+a,d=Math.max(0,r.width-a);if(0>=d)return{nodes:[]};let h=wi(t.categoryAccessor),f=e=>{let t=Number(e);return Number.isFinite(t)&&t>0?t:0},m=e=>f("function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor]),p=e=>f("function"==typeof t.targetAccessor?t.targetAccessor(e):e[t.targetAccessor]),g=e=>{let r="function"==typeof t.rangesAccessor?t.rangesAccessor(e):e[t.rangesAccessor];return Array.isArray(r)?r.map(f).sort((e,t)=>e-t):[]},y="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",x="string"==typeof t.valueAccessor?t.valueAccessor:"value",b="string"==typeof t.targetAccessor?t.targetAccessor:"target",M=t.actualColor??e.theme.semantic.primary??"#3b6cb1",w=e.theme.semantic.text??"currentColor",v=t.targetColor??`var(--semiotic-text, ${w})`,k=[`var(--semiotic-surface, ${e.theme.semantic.surface??"#e8eaed"})`,`var(--semiotic-grid, ${e.theme.semantic.grid??"#cdd1d6"})`,`var(--semiotic-border, ${e.theme.semantic.border??"#a3a8af"})`],$=`var(--semiotic-text, ${w})`,A=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,S=[],I=[];for(let t=0;e.data.length>t;t++){let i=e.data[t],a=g(i),l=m(i),c=p(i),f=Math.max(l,c,...a.length?a:[0]);if(0>=f)continue;let w=r.y+t*(n+o+s);if(w+n+s>r.y+r.height)break;I.push({yTop:w,label:h(i),actual:l,target:c,maxVal:f});let $=e=>u+e/f*d,A=h(i),C=e=>qo(t=>{t("metric",A),"metric"!==y&&t(y,A),e(t)}),N=u;for(let e=0;a.length>e;e++){let t=$(a[e]),r=t-N;r>0&&S.push({type:"rect",x:N,y:w,w:r,h:n,style:{fill:k[Math.min(e,k.length-1)],stroke:"none"},datum:C(t=>{t("range",e),t("rangeValue",a[e]),t("kind","range")}),group:"range-"+e}),N=t}let z=Math.max(6,Math.floor(.45*n));S.push({type:"rect",x:u,y:w+(n-z)/2,w:$(l)-u,h:z,style:{fill:M,stroke:"none"},datum:C(e=>{e("value",l),e("kind","actual"),"value"!==x&&e(x,l)}),group:"actual"});let F=3,E=Math.floor(.8*n);S.push({type:"rect",x:$(c)-F/2,y:w+(n-E)/2,w:F,h:E,style:{fill:v,stroke:"none"},datum:C(e=>{e("target",c),e("kind","target"),"target"!==b&&e(b,c)}),group:"target"})}let C=[];for(let e=0;I.length>e;e++){let t=I[e];if(i&&C.push(zo({keyId:"bullet-label-"+e,text:t.label,x:r.x+a-8,y:t.yTop+n/2,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:$})),l){let r=t.yTop+n+2;for(let n=0;5>n;n++){let o=t.maxVal*n/4,i=u+o/t.maxVal*d;C.push(Za.createElement("line",{key:`bullet-tick-${e}-${n}`,x1:i,x2:i,y1:r,y2:r+3,stroke:A,strokeWidth:1}),zo({keyId:`bullet-ticktext-${e}-${n}`,text:c(o),x:i,y:r+12,anchor:0===n?"start":4===n?"end":"middle",baseline:"auto",fontSize:10,color:A}))}}}return{nodes:S,overlays:C.length>0?Za.createElement(Za.Fragment,null,...C):null}};import{jsx as el,jsxs as tl}from"react/jsx-runtime";var rl=1.75,nl="#222222",ol=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height)return{nodes:[]};let n=wi(t.categoryAccessor??"name"),o=wi(t.teaVolumeAccessor??"teaVolume"),i=wi(t.bobaVolumeAccessor??"bobaVolume"),a=wi(t.iceVolumeAccessor??"iceVolume"),l=wi(t.cupHeightAccessor??"cupHeight"),s=wi(t.cupTopRadiusAccessor??"cupTopRadius"),c=wi(t.cupBottomRadiusAccessor??"cupBottomRadius"),u=wi(t.bobaRadiusAccessor??"bobaRadius"),d=t.cupWidthRatio??.82,h=e.scales.o,f=h.bandwidth(),m=Math.max(1,r.height-26-8),p=r.y+8,g=[],y=[];for(let t of e.data){let r=n(t)+"",x=h(r);if(null==x)continue;let b={height:pt(l(t),15.5),topRadius:pt(s(t),4.75),bottomRadius:pt(c(t),3.75)},M=pt(u(t),.6),w=Math.max(0,pt(o(t),450)),v=Math.max(0,pt(i(t),110)),k=Math.max(0,pt(a(t),135)),$=Math.PI*M*M,A=Math.floor(v/$),S=A*$,I=Math.floor(k/5.359375),C=I*rl*rl*rl,N=w+S+C,z=ut(b,N),F=Math.min(b.height,Math.max(0,z)),E=st(b,F),{pearls:j,layers:O}=ft(b,M,A),R=F,W=mt(b,O*M*2,R,I),L=b.height-20.32,T=Math.min(0,L),P=Math.min(f*d/(2*(b.topRadius+1)),m/(b.height-T)),q=x+f/2,D=e=>q+e*P,V=e=>p+(e-T)*P,B=D(-(b.topRadius+1)),H=D(b.topRadius+1),Y=V(T),G=V(b.height),_=Do({name:r,teaVolume:w,bobaVolume:Math.round(S),iceVolume:Math.round(C),totalVolume:Math.round(N),numBobas:A,numIce:I,kind:"boba cup"});g.push({type:"rect",x:B,y:Y,w:Math.max(1,H-B),h:Math.max(1,G-Y),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:_,group:r,_transitionKey:"boba-"+Ii(r)});let X=b.height-R,K=Ii(r),U=e.resolveColor(r);y.push(tl("g",{children:[w>0?el("path",{d:`M${D(-E)},${V(X)} L${D(-b.bottomRadius)},${V(b.height)} L${D(b.bottomRadius)},${V(b.height)} L${D(E)},${V(X)} z`,fill:"#D2B799"}):null,j.map((e,t)=>el("circle",{cx:D(e.x),cy:V(e.z),r:M*P,fill:"#222222",opacity:.5},"p-"+t)),W.map((e,t)=>el("rect",{x:D(e.cx)-.95*rl*P/2,y:V(e.cy)-.95*rl*P/2,width:.95*rl*P,height:.95*rl*P,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${D(e.cx)} ${V(e.cy)})`},"i-"+t)),el("path",{d:`M${D(-b.topRadius)},${V(0)} L${D(-b.bottomRadius)},${V(b.height)} L${D(b.bottomRadius)},${V(b.height)} L${D(b.topRadius)},${V(0)}`,fill:"none",stroke:nl,strokeWidth:2.5}),el("line",{x1:D(-(b.topRadius+1)),y1:V(0),x2:D(b.topRadius+1),y2:V(0),stroke:nl,strokeWidth:3,strokeLinecap:"round"}),w>0?el("path",{d:`M${D(-.635)},${V(L)} L${D(-.635)},${V(b.height-.4)} L${D(.635)},${V(b.height-1.27-.4)} L${D(.635)},${V(L)} z`,fill:"#4F91CB",stroke:nl,strokeWidth:1,opacity:.78}):null,el("text",{x:q,y:G+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:r}),el("text",{x:q,y:G+30,textAnchor:"middle",fontSize:10,fill:U,children:`${A} pearls · ${Math.round(N)} cm³`})]},"boba-"+K))}return{nodes:g,overlays:el("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:y})}},il=["naturalGas","coal","nuclear","hydro","wind","solar","other"],al={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},ll={tight:5,watch:12,comfortable:20};import*as sl from"react";var cl=class{constructor(){this.count=0,this.capacity=1,this.tree=new Float64Array(2).fill(NaN)}assign(e,t){let r;if(this.tree[1]>e)r=this.count++,r===this.capacity&&this.grow();else{let t=1;for(;this.capacity>t;)t*=2,e>=this.tree[t]||t++;r=t-this.capacity}let n=this.capacity+r;for(this.tree[n]=t;n>1;){n=Math.floor(n/2);let e=this.minimum(n);if(this.tree[n]===e)break;this.tree[n]=e}return r}minimum(e){let t=this.tree[2*e],r=this.tree[2*e+1];return r>=t||Number.isNaN(r)?t:r}grow(){let e=this.tree,t=this.capacity;this.capacity*=2,this.tree=new Float64Array(2*this.capacity).fill(NaN),this.tree.set(e.subarray(t),this.capacity);for(let e=this.capacity-1;e>0;e--)this.tree[e]=this.minimum(e)}},ul=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length||!t?.domain)return{nodes:[]};let n=Ft(t.laneAccessor),o=Ft(t.startAccessor),i=Ft(t.endAccessor),a=t.idAccessor?Ft(t.idAccessor):null,l=t.unit??0,s=t.barGap??1.5,c=Math.max(0,t.minBarWidth??2),u=t.minBarHeight??3.5,d=t.maxBarHeight??10,h=t.lanePadding??7,f=t.cornerRadius??2,m=t.bottomInset??0,p=t.color??((t,r)=>e.resolveColor(r)),[g,y]=t.domain,x=y-g||1,b=e=>r.x+(e-g)/x*r.width,M=e.scales?.o?.domain?.()??[],w=t.lanes??(M.length>0?M:[...new Set(e.data.map(n))]),v=Math.max(0,r.height-m)/Math.max(1,w.length),k=e=>b(o(e)),$=e=>Math.max(k(e)+c,b(i(e)+l)),A=[];w.forEach((t,o)=>{let i=r.y+o*v,l=e.data.filter(e=>n(e)===t);if(0===l.length)return;let{packed:c,trackCount:m}=Nt(l,{start:k,end:$}),g=new Map,y=new Map;for(let{item:e,track:t}of c){let r=y.get(t);r?r.push(e):y.set(t,[e])}for(let e of y.values()){e.sort((e,t)=>k(e)-k(t));for(let t=0;e.length-1>t;t++)g.set(e[t],k(e[t+1]))}let x=(v-2*h)/m,b=Math.min(d,Math.max(Math.min(u,x),x-s));for(let{item:e,track:r}of c){let n=k(e),o=g.get(e),l=$(e)-n;A.push({type:"rect",x:n,y:i+h+r*x,w:void 0!==o&&n+l>o-1?Math.max(1,o-1-n):l,h:b,cornerRadii:f>0?{tl:f,tr:f,br:f,bl:f}:void 0,style:{fill:p(e,t),stroke:"none"},datum:e,group:t,_transitionKey:a?a(e)+"":void 0})}});let S=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,I=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,C=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,N=[];(t.periods??[]).forEach((e,t)=>{let n=b(e.start),o=Math.max(1,b(e.end+l)-n);N.push(sl.createElement("rect",{key:"period-"+t,x:n,y:r.y,width:o,height:r.height,fill:C,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&N.push(zo({keyId:"period-label-"+t,text:e.name,x:n+4,y:r.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:I}))});let z=!1!==t.showLaneLabels,F=t.laneLabelGap??12;if(w.forEach((e,t)=>{let n=r.y+t*v;N.push(sl.createElement("line",{key:"lane-sep-"+t,x1:r.x,x2:r.x+r.width,y1:n,y2:n,stroke:C,opacity:.45})),z&&N.push(zo({keyId:"lane-label-"+t,text:e,x:r.x-F,y:n+v/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:S}))}),!1!==t.showAxis){let e=t.axisTicks??Array.from({length:8},(e,t)=>Math.round(g+t/7*x));N.push(Zo({keyId:"interval-axis",scale:b,ticks:e,orient:"top",offset:r.y,tickLength:0,gridLength:r.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:I}))}return{nodes:A,overlays:sl.createElement(sl.Fragment,null,...N)}},dl={width:60,height:34},hl=e=>{let{plot:t}=e.dimensions;if(0>=t.width||0>=t.height||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};let r=e.config.fixedAxis??"y",{positioned:n,byId:o}=Dt(e.nodes,e.edges,t,e.config),i=n.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[];e.edges.forEach((t,n)=>{let i=o.get((s=t,("function"==typeof e.config.sourceAccessor?e.config.sourceAccessor(s):xi(s,e.config.sourceAccessor??"source",void 0))+"")),l=o.get((t=>("function"==typeof e.config.targetAccessor?e.config.targetAccessor(t):xi(t,e.config.targetAccessor??"target",void 0))+"")(t));var s;if(!i||!l)return;let{from:c,to:u}=Ot({cx:i.x,cy:i.y,width:i.width,height:i.height},{cx:l.x,cy:l.y,width:l.width,height:l.height},{orientation:"y"===r?"vertical":"horizontal"});a.push({type:"curved",pathD:Et(c,u,{orientation:"y"===r?"vertical":"horizontal",bend:Rt(n,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:Fi(t)??t})});let l=n.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:i,sceneEdges:a,labels:l}};import{jsx as fl,jsxs as ml}from"react/jsx-runtime";var pl=1.15,gl={a:.556,b:.556,c:.5,d:.556,e:.556,f:.278,g:.556,h:.556,i:.222,j:.222,k:.5,l:.222,m:.833,n:.556,o:.556,p:.556,q:.556,r:.333,s:.5,t:.278,u:.556,v:.5,w:.722,x:.5,y:.5,z:.5,"'":.191,"-":.333,".":.278," ":.278},yl=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length)return{nodes:[]};let n=wi(t.textAccessor),o=e=>{let r=Number(wi(t.weightAccessor)(e));return Number.isFinite(r)&&r>0?r:0},i=wi(t.columnAccessor),a=e=>Number(wi(t.segmentAccessor)(e)),l=t.minFontSize??11,s=t.maxFontSize??42,c=t.columnGutter??18,u=t.collisionPadding??2,d=!1!==t.showColumnLabels,h=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>Math.round(e)+""),p=t.rotate??0,g=!0===t.repeatWords,y=!1!==t.scaleToFit,x=t.packingDensity??.6,b="string"==typeof t.textAccessor?t.textAccessor:"word",M="string"==typeof t.weightAccessor?t.weightAccessor:"weight",w="string"==typeof t.columnAccessor?t.columnAccessor:"column",v="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",k=[],$=new Map,A=1/0,S=-1/0;for(let t=0;e.data.length>t;t++){let r=e.data[t],l=i(r)+"",s=n(r)+"",c=o(r),u=a(r);!s||!Number.isFinite(u)||($.has(l)||(k.push(l),$.set(l,[])),$.get(l).push({col:l,text:s,weight:c,segment:u,datum:r,dataIndex:t}),A>u&&(A=u),u>S&&(S=u))}if(0===k.length)return{nodes:[]};if(!g)for(let[e,t]of $){let r=new Map;for(let e of t){let t=r.get(e.text);(!t||e.weight>t.weight)&&r.set(e.text,e)}$.set(e,[...r.values()])}let I=1/0,C=-1/0;for(let e of $.values())for(let t of e)I>t.weight&&(I=t.weight),t.weight>C&&(C=t.weight);if(!Number.isFinite(I))return{nodes:[]};let N=t.columnOrder?[...t.columnOrder.filter(e=>$.has(e)),...k.filter(e=>!t.columnOrder.includes(e))]:k,z=new Map(N.map(r=>[r,t.columnColor?.(r)||e.resolveColor(r)])),[F,E]=t.segmentDomain??[A,S],j=E-F||1,O=C-I||1,R=d?22:0,W=h?52:0,L=r.x+W,T=r.y+R,P=Math.max(0,r.width-W),q=Math.max(0,r.height-R),D=N.length,V=D>0?Math.max(0,P-c*Math.max(0,D-1))/D:0,B=T+14,H=T+q-14,Y=e=>B+(e-F)/j*(H-B),G=V*q,_=1/0,X=1/0,K=N.map((e,r)=>{let n=z.get(e),o=($.get(e)??[]).map(e=>{let o={word:e.text,column:e.col,weight:e.weight,segment:e.segment,datum:e.datum,dataIndex:e.dataIndex,columnIndex:r,resolvedColumnColor:n},i=t.wordOpacity?Number(t.wordOpacity(o)):1,a=t.wordColor?.(o);return{text:e.text,weight:e.weight,segment:e.segment,baseFont:(c=e.weight,l+Math.sqrt((c-I)/O)*(s-l)),opacity:Number.isFinite(i)?Wo(i,0,1):0,color:a||n,info:o};var c});if(0===o.length)return null;let i=0;for(let e of o){let t=1.05*Ht(e.text);i+=t*pl*e.baseFont*e.baseFont,X=Math.min(X,(V-8-1)/(t*e.baseFont))}return i>0&&(_=Math.min(_,Math.sqrt(x*G/i))),{col:e,colLeft:L+r*(V+c),center:L+r*(V+c)+V/2,rows:o}}).filter(e=>null!==e),U=e=>{let t=[],r=0;for(let n of K){if(0>=V)continue;let o=n.colLeft+4,i=n.colLeft+V-4,a=n.rows.map((t,r)=>{let o=Math.max(5,e*t.baseFont),i=`${n.col}::${t.text}::${r}`;return{id:i,text:t.text,weight:t.weight,segment:t.segment,font:o,w:Yt(t.text,o),h:o*pl+2,anchorY:Y(t.segment),seed:(Bt(i)-.5)*Math.min(.5*V,80),opacity:t.opacity,color:t.color,info:t.info}}).sort((e,t)=>t.font-e.font||(t.id>e.id?-1:1)),l=[];for(let e of a){let a=e.w/2,s=e.h/2,c=Wo(n.center+e.seed,o+a,i-a),d=e.anchorY,h=c,f=Wo(d,B+s,H-s),m=!1;for(let t=0;2600>t;t++){let r=3.2*Math.sqrt(t),n=2.399963229728653*t,p={x:Wo(c+r*Math.cos(n),o+a,i-a),y:Wo(d+r*Math.sin(n),B+s,H-s),w:e.w,h:e.h};if(!Gt(p,l,u)){h=p.x,f=p.y,m=!0;break}}m||r++,l.push({x:h,y:f,w:e.w,h:e.h});let g=Math.sqrt((e.weight-I)/O),y=p>0?2*(Bt(e.id+"r")-.5)*p:0;t.push({id:e.id,text:e.text,x:h,y:f,fontSize:e.font,rotation:y,color:e.color,opacity:e.opacity,datum:qo(t=>{for(let r of Object.keys(e.info.datum))t(r,e.info.datum[r]);t("word",e.text),t("weight",e.weight),t("column",n.col),t("segment",e.segment),"word"!==b&&t(b,e.text),"weight"!==M&&t(M,e.weight),"column"!==w&&t(w,n.col),"segment"!==v&&t(v,e.segment),t("__strength",.5+.5*g)})})}}return{placed:t,unplaced:r}},Q=y?Math.min(1,_,X):Math.min(1,X),Z=U(Q);if(y)for(let e=0;6>e&&Z.unplaced>0&&Q>.1;e++)Q*=.88,Z=U(Q);let J=Z.placed.filter(e=>e.opacity>0);return{nodes:J.map(e=>{let t=Yt(e.text,e.fontSize)/2,r=e.fontSize*pl/2;return{type:"rect",x:e.x-t,y:e.y-r,w:2*t,h:2*r,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:e.datum.column+"",_transitionKey:e.id}}),overlays:ml("g",{className:"semiotic-word-trails",children:[h&&_t({x:r.x+W-10,yTop:B,yBot:H,segLo:F,segHi:E,segToY:Y,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:r.x}),d&&N.map((e,t)=>V>0?fl("text",{x:L+t*(V+c)+V/2,y:r.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:z.get(e),style:{pointerEvents:"none"},children:e},"wt-col-"+t):null),J.map(e=>fl("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},"wt-"+e.id))]})}},xl={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},bl=8,Ml=tr,wl=2*Math.PI;import{jsx as vl,jsxs as kl}from"react/jsx-runtime";var $l="var(--semiotic-text, currentColor)",Al=new Set(["rows"]),Sl=class{constructor(e){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.options=e,this.worker=e.createWorker(),this.worker.onmessage=e=>{let t=this.options.parseMessage(e.data),r=t.requestId,n=null!=r?this.pending.get(r):this.pending.values().next().value;if(n){if(null!=r)this.pending.delete(r);else{for(let e of this.pending.values())e!==n&&(e.cleanup(),e.reject(Error(this.options.name+" worker response missing requestId")));this.pending.clear()}if(n.cleanup(),!t.ok)return void n.reject(t.error);n.resolve(t.payload)}},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(Ur(this.options.name));let r=this.nextRequestId;this.nextRequestId+=1;let n=this.options.encodeRequest?.(r,e)??{requestId:r,request:e};return new Promise((e,o)=>{let i=()=>{let e=1===this.pending.size;this.pending.delete(r),t?.removeEventListener("abort",i),o(Ur(this.options.name)),this.options.terminateOnAbort&&e&&this.terminate()},a=()=>t?.removeEventListener("abort",i);this.pending.set(r,{cleanup:a,reject:o,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(n)}catch(e){this.pending.delete(r),a(),o(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error(this.options.name+" worker terminated")),this.worker.terminate())}rejectAll(e){for(let t of this.pending.values())t.cleanup(),t.reject(e);this.pending.clear()}},Il=class{constructor(e=function(){let e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):function(e){if("u">typeof __filename){let t=__filename.replace(/\\/g,"/"),r=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+r)}throw Error("Cannot resolve module worker asset: "+e)}("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.session=new Sl({name:"Force layout",createWorker:()=>e,terminateOnAbort:!0,parseMessage:e=>{let t=e,{requestId:r,error:n}=function(e){return e&&"object"==typeof e?{requestId:e.requestId,error:e.error}:{}}(t);return n?{requestId:r,ok:!1,error:Qr(n)}:{requestId:r,ok:!0,payload:{positions:t.positions??{}}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},Cl=function(){let e=null;return{get:()=>((!e||e.isDead)&&(e=new Il),e),resetForTest:()=>{if(e){try{e.terminate()}catch{}e=null}}}}(),Nl=[.1,.5,.9],zl=1e6,Fl="down",El=24,jl=.12,Ol=.55,Rl=0,Wl=1;export{Mo as DEFAULT_AREA_PER_ANNOTATION,wo as DEFAULT_GLYPH_ANCHOR,vo as DEFAULT_GLYPH_VIEWBOX,bl as DEFAULT_HIT_RADIUS,oa as DEFAULT_ISOMETRIC_SPRITE_SIZES,il as GRID_FUEL_KEYS,al as GRID_FUEL_LABELS,ko as LayoutCache,$o as SYMBOL_SEQUENCE,wl as TAU,Ao as absorbRegion,zt as activeCountOverDomain,wr as addPoints,Ha as adjacencyFlowLayout,eo as adjacencyMatrix,nt as aggregateAdjacencyFlow,So as aggregateRegionCounts,e as allocateCells,Re as analyzeNetEnsemble,yr as angleScale,Io as annotationBudget,Co as annotationDensity,No as annotationLayout,Qn as arcLayout,Zn as arcPath,Xn as arrivalReplay,hl as axisFixedForceLayout,Dt as axisFixedForcePositions,r as balanceSnapshotsToFlows,zo as bandLabel,Yr as betweenness,Vr as bfsDistances,ol as bobaLayout,Fo as bodyGroupSpec,Eo as boundsOf,Ot as boxEdgeAnchors,qr as buildAdjacency,Fr as buildTooltipEntries,Ja as bulletLayout,jo as calendarLayout,Oo as capacitatedRegion,Ro as chargeGateRegion,Jn as circularLayout,Wo as clamp,Gr as closeness,_r as clustering,Hn as collidersFromScales,pn as comparePhysicsTrace,Cn as composePhysicsControllers,pe as computeTransitDiagramPositions,Po as countPairwiseCrossings,Sn as createCapacityQueueController,jn as createDependencyGateController,Nn as createPortalController,Mn as createProcessJourneyLedger,En as createServiceLevelController,zn as createServiceResourcePoolController,Tt as cubicPath,Wt as cubicPoint,Lt as cubicTangent,Et as curvedEdgePath,or as cyclicRangeContains,$a as dagreLayout,Dr as degree,xt as demandForecastRows,Tn as describePhysicsStageGeography,m as diagnoseTokenEncoding,Vo as dimFor,Hr as egoNetwork,sr as estimateLabelWidth,zr as extractTooltipDatum,Rt as fanOutBend,ka as flextreeLayout,Bo as forceFieldRegion,a as forceLayout,Jr as forceLayoutAsync,St as formatMw,It as formatReservePct,Er as formatTooltipValue,Yn as galtonPegs,h as generateTokens,Qt as geoAreaHitTarget,Ut as geoHitTarget,va as geographicDotGridLayout,ma as geographicGridLayout,Ho as glyphExtent,Yo as glyphFractionClipRect,Go as glyphPlacement,$t as gridEventAnnotations,D as gridifyGeographicPoints,_o as groupBy,Xo as groupCompletionRows,Ko as hatchFill,Kt as hitTargetPoint,Zt as hitTargetRect,Uo as hullFromBoxes,ul as intervalLanesLayout,ua as isometricLandmarkLayout,Xi as isotypeBoltGlyph,Ki as isotypeBusGlyph,_i as isotypeChipGlyph,Yi as isotypeGhost,Bi as isotypeInk,Zi as isotypeNetworkGlyphs,Hi as isotypePaper,Qi as isotypePersonGlyph,Ui as isotypePersonPath,Gi as isotypeServerGlyph,lr as layoutChipStrip,ar as layoutSequence,f as layoutTokenGrid,Ir as legendGroupsFrom,Cr as legendSwatches,Oa as lineageDagLayout,Zo as linearAxis,Jo as makeShade,Qa as marimekkoLayout,ei as markCallout,ti as matchesHighlight,ni as mean,oi as membraneRegion,Ta as mermaidDagLayout,ao as mobileAnnotationStrategy,ho as mobileAreaChartRecipe,bo as mobileBrushAlternatives,xo as mobileChartFamilyRecipe,go as mobileGeoChartRecipe,uo as mobileLineChartRecipe,po as mobileNetworkChartRecipe,fo as mobileOrdinalChartRecipe,mo as mobileScatterplotRecipe,yo as mobileSmallMultipleRecipe,ii as mulberry32,Va as netEnsembleLayout,er as networkEdgeHitTarget,Jt as networkHitTarget,ai as nonNegativeFinite,Ar as normalizePoint,Xr as normalizeScores,c as normalizeTokenEncoding,ge as octilinearRoute,ye as offsetTransitPath,li as orderByBarycenter,Un as orderByGroupDegree,si as orderExactSmall,jt as orthogonalEdgePath,ci as packBandsBySilhouette,Nt as packIntervals,cr as packSpanLevels,Xa as packedClusterMatrix,ui as parallelCoordinatesLayout,fr as partitionSharedEdges,Wn as physicsChargePoint,Rn as physicsDestination,un as physicsReferenceEnvelope,Ln as physicsStageColliders,On as physicsStageGeography,di as placeWithMinGap,$r as pointMagnitude,pr as polarToXY,hi as portalRegion,fi as pressureFieldRegion,mi as processChrome,vn as processJourneyRows,pi as processLaneWalls,gi as processStageLayout,yi as processStageRegions,rn as processVolumePolygons,Kr as proximityProblem,xr as radiusScale,xi as readField,Pt as rectCollide,bi as refineByAdjacentSwaps,Mi as regionCountsToProjectionRows,vt as reserveAnnotationBands,bt as reserveMarginPct,Mt as reserveSeries,br as ringArcPath,vi as roundedEnclosure,xe as roundedTransitPath,ki as routeSurfaceRegion,Ml as runLengthEncode,tr as runs,te as sampleGeographicDotGrid,ur as scaleArcBand,kr as scalePoint,_n as sedimentBake,ir as selectCyclicRange,j as selectIsometricLandmarks,Ai as shade,nr as shortestArcDelta,Br as shortestPath,Si as signatureKey,dr as spanArcPath,hr as spanArcPeakY,Gn as spawnFromTokens,yt as stackFuelSeries,tn as stageTargetInVolume,vr as subtractPoints,y as suggestTokenEncoding,kt as summarizeOperatingPoint,Ci as symbolExtent,Ni as symbolPathString,zi as symbolRadius,wt as thresholdBandsForReserve,At as tightestHours,A as tokenLayer,g as tokenTaskIntentToCapabilityIntents,Ia as transitDiagramLayout,o as unitize,i as unitizeRange,Fi as unwrapDatum,wn as updateProcessJourney,Ri as waffleLayout,Oi as withAlpha,yl as wordTrailsLayout,Vt as wordTrailsProgressiveReveal,rr as wrapValue,gr as xyToAngle};
1
+ function e(e,t,r){let n=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,o=e=>Number.isFinite(e)?Math.max(0,e):0,i=e.reduce((e,t)=>e+(o(t.weight)>0?1:0),0),a=i>0?Math.min(Math.max(0,Math.floor(r?.minPerCategory??0)),Math.floor(n/i)):0,l=e.reduce((e,t)=>e+o(t.weight),0);if(0>=n||0>=l)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));let s=e.map(e=>{let t=o(e.weight),r=t/l*n;return{...e,exact:r,cells:t>0?Math.max(a,Math.floor(r)):0,remainder:r-Math.floor(r)}}),c=s.reduce((e,t)=>e+t.cells,0);for(;c>n;){let e=s.filter(e=>e.cells>a).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,c--}let u=s.filter(e=>o(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||o(t.weight)-o(e.weight)||e.key.localeCompare(t.key));for(let e=0;n>c;e++)u[e%u.length].cells++,c++;return s}function t(e,t,r,n){let o=new Set;return e.map((e,i)=>{let a=t(e,i)+"",l=Number(r(e,i));if(!a)throw Error(`${n} snapshot contains an empty id at index ${i}.`);if(o.has(a))throw Error(`${n} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(l)||0>l)throw Error(`${n} snapshot value for "${a}" must be a finite non-negative number.`);return o.add(a),{id:a,value:l}})}function r(e,r,n){let o=n.afterId??n.beforeId,i=n.afterValue??n.beforeValue,a=null==n.epsilon||0>n.epsilon?1e-9:n.epsilon,l=t(e,n.beforeId,n.beforeValue,"Before"),s=t(r,o,i,"After"),c=new Map(l.map(e=>[e.id,e.value])),u=new Map(s.map(e=>[e.id,e.value])),d=l.reduce((e,t)=>e+t.value,0),h=s.reduce((e,t)=>e+t.value,0),f=a>=Math.abs(d-h);if(!f&&!n.allowImbalance)throw Error(`Snapshot totals must match (before ${d}, after ${h}). Pass allowImbalance to inspect residuals.`);let m=[],p=[...l.map(e=>e.id),...s.map(e=>e.id).filter(e=>!c.has(e))];for(let e of p){let t=Math.min(c.get(e)??0,u.get(e)??0);t>a&&m.push({sourceId:e,targetId:e,value:t,kind:"stay"})}let g=l.map(e=>({id:e.id,value:e.value-(u.get(e.id)??0)})).filter(e=>e.value>a),y=s.map(e=>({id:e.id,value:e.value-(c.get(e.id)??0)})).filter(e=>e.value>a),x=0,b=0;for(;g.length>x&&y.length>b;){let e=g[x],t=y[b],r=Math.min(e.value,t.value);r>a&&m.push({sourceId:e.id,targetId:t.id,value:r,kind:"move"}),e.value-=r,t.value-=r,a>=e.value&&(x+=1),a>=t.value&&(b+=1)}return{flows:m,beforeTotal:d,afterTotal:h,balanced:f,unmatchedBefore:g.slice(x).filter(e=>e.value>a).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:y.slice(b).filter(e=>e.value>a).map(({id:e,value:t})=>({id:e,value:t}))}}function n(e){return Number.isFinite(e)?Math.max(0,e):0}function o(e,t){let r=Number(t.unit),o=n(e),i=t.maxUnits??1/0,a=t.minFraction??0;if(0>=r||0>=i||0>=o)return{units:[],unit:r>0?r:0,total:o,shown:0,overflow:o>0&&!(i>0)};let l=Math.ceil(o/r-1e-6),s=Math.min(i,l),c=l>i,u=[];for(let e=0;s>e;e+=1){let t=e*r,n=Math.min(1,Math.max(0,(Math.min(o,t+r)-t)/r));1e-6>1-n&&(n=1),u.push({index:e,fraction:n,start:t,end:t+n*r,value:n*r})}let d=u[u.length-1];d&&a>d.fraction&&1>d.fraction&&u.pop();let h=u.reduce((e,t)=>e+t.value,0);return{units:u,unit:r,total:o,shown:h,overflow:c}}function i(e,t,r){let i=o(e,r),a=Math.max(n(t),i.total);if(i.total>=a)return{...i,rangeUnits:[],rangeTotal:i.total};let l=o(a,{unit:r.unit,maxUnits:r.maxUnits}),s=l.unit>0?i.total/l.unit:0,c=Math.floor(s+1e-6),u=Math.min(1,Math.max(0,s-c));1e-6>u&&(u=0);let d=[];for(let e of l.units)if(e.index>=c){if(e.index===c&&u>0){e.fraction-u>1e-6&&d.push({...e,startFraction:u,start:e.index*l.unit+u*l.unit,value:(e.fraction-u)*l.unit});continue}d.push({...e,startFraction:0})}return{...i,overflow:i.overflow||l.overflow,rangeUnits:d,rangeTotal:a}}function a(e,t,r={}){let n=r.iterations??260,o=r.repulsion??5200,i=r.linkDistance??165,a=r.linkStrength??.045,l=r.centerStrength??.018,s=r.damping??.84,c=r.nodeRadius??12,u=r.nodePadding??3,d=r.inset??.06,h=ei(r.seed??1),f=new Map;for(let t of e)f.set(t.id,0);for(let e of t)f.set(e.source,(f.get(e.source)??0)+1),f.set(e.target,(f.get(e.target)??0)+1);let m=500,p=e.map(e=>({id:e.id,data:e,x:200+600*h(),y:200+600*h()})),g=new Set(e.map(e=>e.id)),y=t.filter(e=>g.has(e.source)&&g.has(e.target)).map(e=>({source:e.source,target:e.target}));if(n>0){let e=Li(p).randomSource(h).alphaDecay(1-Math.pow(.001,1/n)).velocityDecay(Math.max(0,Math.min(1,1-s))).force("charge",Ti().strength(e=>{let t=f.get(e.id)??0;return 2.5*-Math.sqrt(o)*Math.sqrt(t+1)})).force("collide",Ri(e=>(e=>"function"==typeof c?c(e.data):c)(e)+u).strength(.9).iterations(2)).force("center",Oi(m,m).strength(.8)).force("x",Pi(m).strength(l)).force("y",qi(m).strength(l));y.length>0&&e.force("link",Wi(y).id(e=>e.id).distance(i).strength(e=>{let t="string"==typeof e.target?e.target:e.target.id,r=Math.max(1,Math.min(f.get("string"==typeof e.source?e.source:e.source.id)??1,f.get(t)??1));return a/.045/r})),e.stop();for(let t=0;n>t;t+=1)e.tick()}let x=1/0,b=1/0,w=-1/0,M=-1/0;for(let e of p){let t=e.x??m,r=e.y??m;x>t&&(x=t),b>r&&(b=r),t>w&&(w=t),r>M&&(M=r)}let v=w-x,k=M-b,$={};for(let e of p)Object.defineProperty($,e.id,{value:{x:0===v?.5:d+((e.x??m)-x)/v*(1-2*d),y:0===k?.5:d+((e.y??m)-b)/k*(1-2*d)},enumerable:!0,configurable:!0,writable:!0});return $}function l(e){return e?e.map(Number).filter(Number.isFinite):[]}function s(e){if("fixed-denominator"===e.countStrategy)return 1/0;let t=e.maxTokens??1/0;return t>0?Math.floor(t):0}function c(e){let t=e.unitValue??e.unit,r=e.icon??e.token;return{...e,...null!=t&&{unitValue:t},...null!=r&&{icon:r}}}function u(e){if(e.samples)return l(e.samples);if(!e.data||!e.valueAccessor)return[];let t=e.valueAccessor;return e.data.map(e=>"function"==typeof t?t(e):Number(e[t])).filter(Number.isFinite)}function d(e,t,r,n={}){return{index:t,tokenType:e.tokenType,tokenSemantics:e.tokenSemantics,countStrategy:e.countStrategy,fraction:1,startFraction:0,value:r,start:t,end:t+r,unitValue:e.unitValue,unitMeaning:e.unitMeaning,...n}}function h(e,t){let r,n,a,h,f,p,g,y=c(t),x=function(e){return"number"==typeof e?{value:e}:Array.isArray(e)?{samples:l(e),data:e}:e}(e),b=0,w=!1;if("unitized"===y.countStrategy){f=y.unitValue??1;let e={unit:f,maxUnits:y.maxTokens,minFraction:y.minFraction},t=null==x.rangeValue?o(ti(x.value),e):i(ti(x.value),ti(x.rangeValue),e);r=t.units.map(e=>d(y,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:t.unit})),n=t.total,b=t.shown,w=t.overflow,null!=x.rangeValue&&(p=t.rangeTotal,g=t.rangeUnits.map(e=>d(y,e.index,e.value,{fraction:e.fraction,startFraction:e.startFraction,start:e.start,end:e.end,unitValue:t.unit,range:"scenario"})))}else if("fixed-denominator"===y.countStrategy){h=Math.floor(ti(x.denominator??y.denominator)),a=ti(x.numerator??y.numerator??x.value);let e=Math.min(h,Math.max(0,Math.round(a)));r=Array.from({length:h},(t,r)=>d(y,r,1,{highlighted:e>r,start:r,end:r+1})),n=h,b=r.length,w=!1}else if("quantile"===y.countStrategy){let e=u(x).sort((e,t)=>e-t),t=Math.max(0,Math.floor(y.tokenCount??50)),o=e.length>0?Math.min(t,s(y)):0;r=Array.from({length:o},(t,r)=>{let n=(r+.5)/o,i=function(e,t){let r=e.length;if(0===r)return 0;if(1===r)return e[0];let n=(r-1)*Math.min(1,Math.max(0,t)),o=Math.floor(n),i=n-o;return e[o]*(1-i)+e[Math.ceil(n)]*i}(e,n);return d(y,r,i,{sample:i,quantile:n,start:i,end:i})}),n=e.length,b=r.length,w=e.length>0&&t>r.length}else if("sample"===y.countStrategy||"posterior-sample"===y.countStrategy||"random-sample"===y.countStrategy){let e=u(x),t=Math.min(e.length,Math.max(0,Math.floor(y.tokenCount??e.length))),o=Math.min(t,s(y));r=("random-sample"===y.countStrategy?function(e,t=1){let r=Array.from({length:e},(e,t)=>t),n=ei(Math.floor(t)||1);for(let e=r.length-1;e>0;e-=1){let t=Math.floor(n()*(e+1)),o=r[e];r[e]=r[t],r[t]=o}return r}(e.length,y.seed).slice(0,o):Array.from({length:o},(t,r)=>Math.floor(r/Math.max(1,o-1)*(e.length-1)))).map((t,r)=>{let n=e[t];return d(y,r,n,{sample:n,start:n,end:n})}),n=e.length,b=r.length,w=t>r.length}else{let e=x.data;if(e&&null==x.value)r=e.map((e,t)=>d(y,t,1,{datum:e})),n=e.length;else{let e=o(ti(x.value),{unit:1,maxUnits:y.maxTokens,minFraction:y.minFraction});r=e.units.map(e=>d(y,e.index,e.value,{fraction:e.fraction,start:e.start,end:e.end,unitValue:1})),n=e.total,b=e.shown,w=e.overflow}if(e&&null==x.value){let e=function(e,t){let r=s(t);return e.length>r?{tokens:e.slice(0,r),overflow:!0}:{tokens:e,overflow:!1}}(r,y);r=e.tokens,b=r.length,w=e.overflow}}return{tokens:r,encoding:y,total:n,shown:b,overflow:w,numerator:a,denominator:h,unitValue:f,rangeTotal:p,rangeTokens:g,diagnostics:m(y,{visibleTokens:r.length+(g?.length??0)})}}function f(e,t={}){let r=Array.isArray(e)?e:e.tokens,n=r.length;if(0===n)return[];let o=t.flow??"row",i=t.cellWidth??16,a=t.cellHeight??i,l=t.gutter??2,s=t.anchor??[.5,.5],c=Math.max(1,Math.floor(t.columns??Math.ceil(t.rows?n/t.rows:Math.sqrt(n)))),u=Math.max(1,Math.floor(t.rows??Math.ceil(n/c))),d="row"===o?Math.max(u,Math.ceil(n/c)):u,h="column"===o?Math.max(c,Math.ceil(n/u)):c,f=t.x??0,m=t.y??0;return r.map((e,r)=>{let n,p;return"column"===o?(p=Math.floor(r/u),n=r%u):(n=Math.floor(r/c),p=r%c),"left"===t.columnDirection&&(p=h-1-p),"up"===t.rowDirection&&(n=d-1-n),{...e,row:n,column:p,x:f+p*(i+l)+s[0]*i,y:m+n*(a+l)+s[1]*a}})}function m(e,t={}){let r=[],n=e.tokenSemantics,o=e.countStrategy,i=t.maxRecommendedTokens??("fixed-denominator"!==o||ti(e.denominator)>100?80:100);return n||r.push({code:"TOKEN_SEMANTICS_UNCLEAR",severity:"warning",message:"Every tokenized encoding should state what one token represents."}),o||r.push({code:"MISSING_COUNT_STRATEGY",severity:"warning",message:"Every tokenized encoding should state how token counts are produced."}),("icon"===e.tokenType||"glyph"===e.tokenType)&&("icon-only"===e.labelPolicy||"token-only"===e.labelPolicy)&&r.push({code:"ICON_ONLY_LABELS",severity:"warning",message:"Icons should supplement text labels, not replace them."}),null!=t.visibleTokens&&t.visibleTokens>i&&r.push({code:"TOO_MANY_VISIBLE_TOKENS",severity:"warning",message:`This encoding renders ${t.visibleTokens} visible tokens. Consider unitizing, sampling, or a hybrid bar/token view.`}),"decorative"===n&&("icon"===e.tokenType||"glyph"===e.tokenType)&&r.push({code:"DECORATIVE_PICTOGRAPHS",severity:"warning",message:"Decorative pictographs can harm recall and speed when they do not clarify the data."}),"unitized-measure"===n&&o&&"unitized"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Unitized measures should use the unitized count strategy so each token has a stable value."}),"risk-case"===n&&o&&"fixed-denominator"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Risk cases are usually clearest as a fixed-denominator natural frequency."}),("possible-outcome"===n||"posterior-sample"===n||"hypothetical-case"===n)&&o&&"quantile"!==o&&"sample"!==o&&"posterior-sample"!==o&&"random-sample"!==o&&r.push({code:"TOKEN_STRATEGY_MISMATCH",severity:"warning",message:"Outcome/sample tokens should come from quantiles or samples, not from a unitized magnitude."}),"unitized-measure"===n&&"unitized"===o&&null==e.unitValue&&null==e.unit&&r.push({code:"MISSING_UNIT_VALUE",severity:"warning",message:"Unitized measures should set unitValue so each token has a declared value."}),"unitized-measure"===n&&"unitized"===o&&!e.unitMeaning&&r.push({code:"MISSING_UNIT_MEANING",severity:"info",message:"Add unitMeaning so readers know what one full token represents."}),r}function p(e){return"measure"===e?"precise-comparison":"estimate probability"===e?"probability-estimation":"understand risk"===e?"risk-communication":"remember"===e?"memory":"decide"===e?"support-decision":e}function g(e){let t=p(e);return"precise-comparison"===t?["compare-categories","rank"]:"probability-estimation"===t?["distribution"]:"risk-communication"===t?["part-to-whole","distribution"]:"frequency-reasoning"===t?["distribution","compare-categories"]:"memory"===t||"editorial-engagement"===t?["compare-categories"]:"public-explanation"===t||"support-decision"===t?["distribution","compare-categories"]:["compare-categories"]}function y(e){let t=p(e.taskIntent),r="small"===(n=e.availableSpace)?25:"large"===n?100:50;var n;if("precise-comparison"===t)return{recommendedEncoding:"bar-or-line",rationale:"Use continuous position/length encodings when precise magnitude comparison is the primary task.",warnings:[],alternatives:["hybrid-bar-token","unitized-measure"]};if("probability-estimation"===t){let e={tokenType:"dot",tokenSemantics:"possible-outcome",countStrategy:"quantile",tokenCount:r,layout:"dotplot",labelPolicy:"text-plus-token"};return{recommendedEncoding:"quantile-dotplot",tokenEncoding:e,rationale:"This task asks readers to estimate probability from a distribution. Quantile tokens turn probability mass into countable possible outcomes.",warnings:m(e),alternatives:["cdf-with-threshold","density-with-threshold"]}}if("risk-communication"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"risk-case",countStrategy:"fixed-denominator",denominator:100,layout:"waffle",labelPolicy:"text-plus-token"};return{recommendedEncoding:"fixed-denominator-icon-array",tokenEncoding:t,rationale:"Risk is often clearer as natural frequency: highlighted cases out of a fixed denominator.",warnings:m(t,{visibleTokens:100,maxRecommendedTokens:100}),alternatives:["labeled-percent","bar-with-risk-threshold"]}}if("memory"===t||"editorial-engagement"===t){let t={tokenType:e.concreteEntity?"glyph":"icon",icon:e.concreteEntity,tokenSemantics:"unitized-measure",countStrategy:"unitized",unitValue:1,layout:"grid",labelPolicy:"text-plus-token",unitMeaning:e.concreteEntity?"one token represents a unit of "+e.concreteEntity:"one token represents one unit"};return{recommendedEncoding:"semantic-isotype",tokenEncoding:t,rationale:"Semantic tokens are useful when the chart needs to make a topic concrete and memorable.",warnings:m(t),alternatives:["labeled-bar","hybrid-bar-token"]}}if("frequency-reasoning"===t||"public-explanation"===t||"support-decision"===t){let t={tokenType:e.concreteEntity?"icon":"dot",icon:e.concreteEntity,tokenSemantics:"distribution"===e.dataType?"possible-outcome":"unitized-measure",countStrategy:"distribution"===e.dataType?"quantile":"unitized",unitValue:"distribution"===e.dataType?void 0:1,tokenCount:r,layout:"distribution"===e.dataType?"dotplot":"bar-segment",labelPolicy:"text-plus-token",unitMeaning:"distribution"===e.dataType?void 0:"one token represents one unit interval"};return{recommendedEncoding:"hybrid-continuous-token",tokenEncoding:t,rationale:"A hybrid view preserves measurement while adding countable tokens for explanation and decisions.",warnings:m(t),alternatives:["bar-or-line","quantile-dotplot","fixed-denominator-icon-array"]}}return{recommendedEncoding:"bar-or-line",rationale:"Use continuous encodings unless the task needs frequency, risk, memory, or outcome reasoning.",warnings:[],alternatives:["unitized-measure","quantile-dotplot","fixed-denominator-icon-array"]}}function x(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function b(e,t,r){return"function"==typeof e?e(t)??r:e??r}function w(e,t){return"function"==typeof e?e(t):e}function M(e){return e.sample??e.value??e.index}function v(e,t){return void 0!==t.datum?b(t.datum,e,null):e.datum??null}function k(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?b(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):b(t.color,e,Qi):b(t.inactiveColor,e,Zi),stroke:"none",...w(t.style,e)??{}}}function $(e,t){let r=w(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:v(e,t),accessibleDatum:w(t.accessibleDatum,e),accessibility:w(t.accessibility,e),pointId:r,_transitionKey:r}}function A({input:e,encoding:t,options:r={}}){if(!x(e)&&!t)throw Error("tokenLayer requires an encoding when input is not a TokenSet.");let n=x(e)?{...e,encoding:c(e.encoding)}:h(e,t),o=function(e,t){let r=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){let r=t.positionToken;return r?e.map((t,n)=>{let o=r(t,n,e);return{...t,x:o.x,y:o.y,row:o.row??n,column:o.column??0}}):[]}(r,t);let n=t.layout??e.encoding.layout??"grid";if("quantile-strip"===n)return function(e,t){if(0===e.length)return[];let r=t.x??0,n=t.y??0,o=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.gutter??2,a=Math.max(1,Math.floor(t.rows??1)),l=e.map(M),s=Math.min(...l),c=Math.max(...l)-s||1;return e.map((l,u)=>{let d=M(l),h=u%a,f=t.valueToX?t.valueToX(d,l):r+(d-s)/c*(t.width??12*Math.max(1,e.length-1)),m=t.valueToY?t.valueToY(d,l):n+h*(o+i);return{...l,x:f,y:m,row:h,column:u}})}(r,t);if("dotplot"===n)return function(e,t){if(0===e.length)return[];let r=t.x??0,n=t.y??0,o="number"==typeof t.tokenSize?t.tokenSize:12,i=t.gutter??2,a=t.cellWidth??o+i,l=t.cellHeight??o+i,s=e.map(M),c=Math.min(...s),u=Math.max(...s)-c||1,d=new Map;return e.map(o=>{let i=M(o),s=t.valueToX?t.valueToX(i,o):r+(i-c)/u*(t.width??Math.max(1,e.length-1)*a),h=Math.round((s-r)/Math.max(1,a)),f=d.get(h)??0;d.set(h,f+1);let m=t.valueToY?t.valueToY(i,o):n+f*l;return{...o,x:r+h*a,y:m,row:f,column:h}})}(r,t);if("bar-segment"===n){if(!t.valueToX)throw Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];let r=t.y??0,n=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),o=t.anchor??[.5,.5];return e.map((e,i)=>{let a=Number.isFinite(e.start)?e.start:M(e),l=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,s=t.valueToY?t.valueToY(l,e):r+o[1]*n;return{...e,x:t.valueToX(l,e),y:s,row:0,column:i}})}(r,t)}if("beeswarm"===n||"small-multiple"===n)throw Error(`tokenLayer layout "${n}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);let o="number"==typeof t.tokenSize?t.tokenSize:void 0,i=t.cellWidth??o??12,a=t.cellHeight??o??i,l="row"===n?Math.max(1,r.length):"column"===n||"stack"===n?1:"waffle"===n&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,r){if(t.columns)return t.columns;if(t.width&&r>0){let e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(r+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(r,t,i);return f(r,{...t,columns:l,cellWidth:i,cellHeight:a})}(n,r).filter(e=>!r.include||r.include(e));return{tokenSet:n,positionedTokens:o,nodes:o.map(e=>function(e,t,r){if("dot"===r.tokenType)return function(e,t){let r=b(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:b(t.radius,e,r/2),style:k(e,t),...$(e,t)}}(e,t);let n=w(t.glyph,e)??function(e){if(e)return Ui[e]}(r.icon);if(n)return function(e,t,r){let n=k(e,r),o=b(r.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:o,glyph:t,color:(n.fill??Qi)+"",accent:b(r.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:1>e.fraction?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:b(r.fractionDirection,e,"horizontal"),ghostColor:1>e.fraction?w(r.ghostColor,e)??Zi:void 0,rotation:w(r.rotation,e),style:n,...$(e,r)}}(e,n,t);let o=(i=r.icon)&&Ji.has(i)?i:void 0;var i;return function(e,t){let r=b(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,r/2)**2,symbolType:b(t.symbolType,e,"circle"),path:w(t.symbolPath,e),rotation:w(t.rotation,e),style:k(e,t),...$(e,t)}}(e,o&&null==t.symbolType?{...t,symbolType:o}:t)}(e,r,n.encoding))}}function S(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function I(e,t){let r=S(e,t);return"string"==typeof r&&r.length>0?r:void 0}function C(e,t){if(aa.has(t))return I(e,t)}function N(e,t){if("function"==typeof e)return e;let r=e??t;return e=>e[r]}function z(e,t,r){return[111.32*(e-r.lon)*Math.cos((t+r.lat)/2*(Math.PI/180)),110.574*(t-r.lat)]}function F(e){let t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function E(e){return aa.has(e)?e:"monument"}function j(e,t){let r=F(t.gridSize),n=Math.max(1,t.gridRadiusKm??75),o=2*n/r,i=Math.floor(r/2),a=N(t.idAccessor,"id"),l=N(t.nameAccessor,"name"),s=N(t.longitudeAccessor,"lon"),c=N(t.latitudeAccessor,"lat"),u=N(t.kindAccessor,"kind"),d=t.candidatePriorityAccessor?N(t.candidatePriorityAccessor,"priority"):()=>0,h=new Map,f=null;for(let m of e){let e=Number(s(m)),p=Number(c(m));if(!Number.isFinite(e)||!Number.isFinite(p))continue;let g=(a(m)??`${e},${p}`)+"",y=(l(m)??g)+"",x=E(u(m)),[b,w]=z(e,p,t.center);if(Math.abs(b)>n||Math.abs(w)>n)continue;let M=Math.min(r-1,Math.max(0,Math.floor((b+n)/o))),v=Math.min(r-1,Math.max(0,Math.floor((n-w)/o))),k=(M+.5)*o-n,$=n-(v+.5)*o,A={...m,id:g,name:y,kind:x,lon:e,lat:p,distanceKm:Math.sqrt(b*b+w*w),row:v,column:M,cellDistanceSq:(b-k)**2+(w-$)**2,candidatePriority:Number(d(m))||0};(null!=t.centerId&&g===t.centerId||!f&&"city"===x||!f&&v===i&&M===i)&&(f=A);let S=`${v}:${M}`,I=h.get(S)??[];I.push(A),h.set(S,I)}let m=new Map;f&&m.set("city",1);let p=[];for(let e=0;r>e;e++)for(let t=0;r>t;t++){let r,a,l=`tile-${e}-${t}`,s=(t+.5)*o-n,c=n-(e+.5)*o;if(e===i&&t===i&&f){r=f;let n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id).sort((e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||e.name.localeCompare(t.name));a=[f,...n]}else{let n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id);n.sort((e,t)=>{let r=e.candidatePriority-t.candidatePriority;if(0!==r)return r;let n=m.get(e.kind)??0,i=m.get(t.kind)??0,a=o*o*.35;return e.cellDistanceSq+n*a-(t.cellDistanceSq+i*a)||e.name.localeCompare(t.name)}),r=n[0]??null,a=n}r&&m.set(r.kind,(m.get(r.kind)??0)+1),p.push({id:l,row:e,column:t,centerXKm:s,centerYKm:c,terrainIndex:Math.abs((17*e+31*t)%na.length),landmark:r,landmarks:a})}return p}function O({tiles:e,tileWidth:t,tileHeight:r,sprites:n,resourceSize:o,citySize:i,showCityLabel:a}){let l=zi(),s=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return ta("g",{"aria-hidden":"true",pointerEvents:"none",children:[s.map(e=>{let a=e.landmark,s="city"===a.kind?i:o,c=e.y+r/2,u=l.isActive&&!l.predicate(a)?.28:1;return ta("g",{opacity:u,children:[ea("ellipse",{cx:e.x,cy:e.y+.15*r,rx:.28*s,ry:.1*s,fill:"#17251d",opacity:.32}),ea(W,{kind:a.kind,href:C(n,a.kind),x:e.x-s/2,y:c-s,size:s}),e.landmarks.length>1&&ea(R,{x:e.x+.3*t,y:e.y-.19*r,count:e.landmarks.length-1,tileHeight:r})]},a.id)}),a&&s.filter(e=>"city"===e.landmark?.kind).map(e=>{let t=e.landmark.name.toUpperCase(),n=Math.max(56,6.4*t.length+14);return ta("g",{transform:`translate(${e.x},${e.y+.72*r})`,children:[ea("rect",{x:-n/2,y:-7,width:n,height:14,rx:1,fill:"#17251d",opacity:.92}),ea("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},e.landmark.id+"-label")})]})}function R({x:e,y:t,count:r,tileHeight:n}){let o=Math.max(10,Math.min(15,.34*n)),i="+"+r,a=Math.max(o,i.length*o*.58);return ta("g",{transform:`translate(${e},${t})`,children:[ea("rect",{x:-a/2,y:-o/2,width:a,height:o,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),ea("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*o),fontWeight:700,children:i})]})}function W({kind:e,href:t,x:r,y:n,size:o}){if(t)return ea("image",{href:t,x:r,y:n,width:o,height:o,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});let i=ua[e];return ea("svg",{x:r,y:n,width:o,height:o,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:ca[e].flatMap((e,t)=>[...e].map((e,r)=>"."===e?null:ea("rect",{x:r,y:t,width:1,height:1,fill:i[e]},`${t}-${r}`)))})}function T(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function L(e,t,r){return Math.max(t,Math.min(r,e))}function P(e){let t=1/0,r=-1/0;for(let n of e)Number.isFinite(n)&&(t>n&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}function q(e,t){let r=t[1]-t[0];return 0===r?.5:(e-t[0])/r}function D(e,t={}){let r=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===r.length)return[];let n=L(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),o=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8,i=T(t.columns)??Math.max(1,Math.ceil(Math.sqrt(r.length*o/n))),a=T(t.rows)??Math.max(1,Math.ceil(r.length/(i*n)));r.length>i*a&&(null!=t.columns&&null==t.rows?a=Math.ceil(r.length/i):null!=t.rows&&null==t.columns?i=Math.ceil(r.length/a):a=Math.ceil(r.length/i));let l=P(r.map(e=>e.x)),s=P(r.map(e=>e.y)),c=r.map(e=>({...e,desiredColumn:q(e.x,l)*Math.max(0,i-1),desiredRow:q(e.y,s)*Math.max(0,a-1)})),u=(i-1)/2,d=(a-1)/2;c.sort((e,t)=>(t.desiredColumn-u)**2+(t.desiredRow-d)**2-((e.desiredColumn-u)**2+(e.desiredRow-d)**2)||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index);let h=new Set;for(let e=0;a>e;e+=1)for(let t=0;i>t;t+=1)h.add(e*i+t);let f=[];for(let e of c){let t=-1,r=1/0;for(let n of h){let o=(n%i-e.desiredColumn)**2+(Math.floor(n/i)-e.desiredRow)**2;(r>o||o===r&&t>n)&&(t=n,r=o)}0>t||(h.delete(t),f.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/i),column:t%i,index:e.index}))}return f.sort((e,t)=>e.index-t.index),f.map(({index:e,...t})=>t)}function V(e,t,r=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(let t of r)if(null!=e[t])return e[t]}function B(e){return e.map(([e,t],r)=>`${0===r?"M":"L"}${e},${t}`).join("")+"Z"}function H(e,t,r){let n=[];for(let o=0;6>o;o+=1){let i=-Math.PI/2+o*(Math.PI/3);n.push([e+Math.cos(i)*r,t+Math.sin(i)*r])}return B(n)}function Y({marks:e,color:t,fontSize:r,fontFamily:n,fontWeight:o}){let i=zi();return da("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{let a=!i.isActive||i.predicate(e.datum);return da("text",{x:e.x,y:e.y,fill:t,fontFamily:n,fontSize:r,fontWeight:o,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}function G(e,t,r){return Math.max(t,Math.min(r,e))}function _(e){if(Number.isFinite(e)&&Number(e)>0)return Number(e)}function X(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function K(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function U(e,t){let r=K(e);return(e.id??r.id??r.name??"feature-"+t)+""}function Q(e,t,r,n){return[Math.ceil((e-r)/n-.5),Math.floor((t-r)/n-.5)]}function Z(e){if(!e)return 0;let t=xa.get(e);if(t)return t;let r=ba;return ba+=1,xa.set(e,r),r}function J(e,t){return!t||!(t[0][1]>e[1]||e[1]>t[1][1]||(r=e[0],n=t[0][0],o=t[1][0],n>o?n>r&&r>o:n>r||r>o));var r,n,o}function ee(e,t){for(let r of e){let{feature:e,index:n}=r;if(e.geometry&&J(t,r.bounds))try{if(ma(e,t))return{feature:e,index:n}}catch{}}return null}function te(e,t,r,n={}){let o=e.filter((e,t)=>e.geometry&&(!n.featureFilter||n.featureFilter(e,t))),i=function(e,t){if(0===e.length)return null;let r=t.bounds({type:"FeatureCollection",features:e});return Number.isFinite(r[0][0])&&Number.isFinite(r[0][1])&&Number.isFinite(r[1][0])&&Number.isFinite(r[1][1])?r:null}(o,t.geoPath);if(!i)return{dots:[],cellSize:10,features:o};let a=Math.max(0,n.layoutPadding??0),l=[[G(i[0][0],a,Math.max(a,r.width-a)),G(i[0][1],a,Math.max(a,r.height-a))],[G(i[1][0],a,Math.max(a,r.width-a)),G(i[1][1],a,Math.max(a,r.height-a))]],s=Math.max(0,l[1][0]-l[0][0]),c=Math.max(0,l[1][1]-l[0][1]);if(0===s||0===c)return{dots:[],cellSize:10,features:o};let u=_(n.columns),d=Math.max(2,u?s/u:_(n.cellSize)??10),h=Math.max(100,Math.round(_(n.maxSamples)??25e3)),f=Math.ceil(s/d)*Math.ceil(c/d);f>h&&(d*=Math.sqrt(f/h));let m=n.gridOrigin?.[0]??0,p=n.gridOrigin?.[1]??0,[g,y]=Q(l[0][0],l[1][0],m,d),[x,b]=Q(l[0][1],l[1][1],p,d),w=[],M=function(e){return e.map((e,t)=>{if(ya.has(e))return{feature:e,index:t,bounds:ya.get(e)??null};try{let r=fa(e);return ya.set(e,r),{feature:e,index:t,bounds:r}}catch{return ya.set(e,null),{feature:e,index:t,bounds:null}}})}(o);for(let e=x;b>=e;e+=1){let r=p+(e+.5)*d;for(let o=g;y>=o;o+=1){let i=t.invertedPoint(m+(o+.5)*d,r);if(!i||!Number.isFinite(i[0])||!Number.isFinite(i[1]))continue;let a=ee(M,i);if(!a)continue;let l={...K(a.feature),featureId:U(a.feature,a.index),featureIndex:a.index,gridRow:e,gridColumn:o,longitude:i[0],latitude:i[1],dotIndex:w.length};n.dotFilter&&!n.dotFilter(l,w.length)||w.push(l)}}return{dots:w,cellSize:d,features:o}}function re(e){return Math.round(1e4*e)/1e4}function ne(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${re(Number(e[0]))},${re(Number(e[1]))}`:"null"}function oe(e,t){let r=e[t];return"function"==typeof r?r.call(e):void 0}function ie(e){return"number"==typeof e&&Number.isFinite(e)?re(e)+"":null===e?"null":"unavailable"}function ae(e){let t=e.scales.projection;return[ie(oe(t,"scale")),ne(oe(t,"translate")),ne(oe(t,"center")),(r=oe(t,"rotate"),Array.isArray(r)&&r.every(Number.isFinite)?r.map(e=>re(Number(e))).join(","):"unavailable"),ie(oe(t,"clipAngle")),ie(oe(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,r])=>ne(e.scales.projectedPoint(t,r)))].join("|");var r}function le(e){return e.map(([e,t],r)=>`${0===r?"M":"L"}${e},${t}`).join("")+"Z"}function se(e,t,r){return le([[e-r,t-r],[e+r,t-r],[e+r,t+r],[e-r,t+r]])}function ce(e,t,r){return le(Array.from({length:6},(n,o)=>{let i=-Math.PI/2+o*(Math.PI/3);return[e+Math.cos(i)*r,t+Math.sin(i)*r]}))}function ue(e,t){return"function"==typeof t.labelAccessor?t.labelAccessor(e.data):pi(e.data,t.labelAccessor??"label",e.id)}function de(e){return"string"==typeof e?e:e.id}function he(e,t){let r,n=t.lineAccessor;return r="function"==typeof n?n(e.data):"string"==typeof n?e.data[n]:e.data.lines??e.data.line??e.data.route??e.data.group,function(e){let t=(Array.isArray(e)?e:null==e?[]:[e]).map(e=>"object"==typeof e?{...e,id:e.id+""}:{id:e+""});return t.length>0?t:[{id:"network"}]}(r)}function fe(e,t,r){let n=t.sourceColorAccessor,o="function"==typeof n?n(e.data):"string"==typeof n?e.data[n]:e.data.color;return"string"==typeof o&&o?o:r(e.id)}function me(e,t,r,n){if(e.color)return e.color;let o=r.lineColors&&Object.prototype.hasOwnProperty.call(r.lineColors,e.id)?r.lineColors[e.id]:void 0;if("string"==typeof o&&o)return o;let i=r.lineColorAccessor,a="function"==typeof i?i(t.data):"string"==typeof i?t.data[i]:t.data.color;return"string"==typeof a?a:n(e.id)}function pe(e,t){let r=new Map((t.lineOrder??[]).map((e,t)=>[e,t]));return[...e].sort((e,t)=>(r.get(e)??1/0)-(r.get(t)??1/0)||e.localeCompare(t))}function ge(e,t){let r=new Map((e.authoredOrder??t.lineOrder??[]).map((e,t)=>[e,t]));return[...e.lines.values()].sort((e,t)=>(r.get(e.descriptor.id)??1/0)-(r.get(t.descriptor.id)??1/0)||e.descriptor.id.localeCompare(t.descriptor.id))}function ye(e,t,r,n){if("authored"!==t.mode)return null;let o=e.data[r.pointsAccessor??"points"];if(!Array.isArray(o))return null;let i=o.map(e=>"number"==typeof e.x&&"number"==typeof e.y?t.projectAuthoredPoint({x:e.x,y:e.y}):null).filter(e=>null!=e);return 0===i.length?null:n?i.reverse():i}function xe(e,t){return Oo(r=>{for(let[t,n]of Object.entries(e.data))r(t,n);r("source",e.source),r("target",e.target),r("lineId",t.id),r("lineLabel",t.label??t.id)})}function be(e,t,r,n,o,i){if(!1===i.showLabels)return[];let a=i.labelFontSize??11,l=[],s=[],c=[...e].sort((e,t)=>(r.get(t.id)?.size??0)-(r.get(e.id)?.size??0)||e.id.localeCompare(t.id));for(let e of c){let r=t.get(e.id);if(!r)continue;let c=("function"==typeof i.labelAccessor?i.labelAccessor(e.data):pi(e.data,i.labelAccessor??"label",e.id)+"")||e.id,u=Math.max(2*a,c.length*a*.58),d=1.25*a,h=Math.max(i.interchangeRadius??7,n.get(e.id)??i.stationRadius??4)+5,f=[{x:r.x+h,y:r.y,anchor:"start",left:r.x+h},{x:r.x-h,y:r.y,anchor:"end",left:r.x-h-u},{x:r.x,y:r.y-h,anchor:"middle",left:r.x-u/2},{x:r.x,y:r.y+h,anchor:"middle",left:r.x-u/2}].map((e,t)=>{let r={left:e.left,right:e.left+u,top:e.y-d/2,bottom:e.y+d/2},n=l.filter(e=>{return(n=e).right>(t=r).left&&t.right>n.left&&n.bottom>t.top&&t.bottom>n.top;var t,n}).length;return{candidate:e,box:r,score:1e4*n+10*(Math.max(0,-r.left)+Math.max(0,r.right-o.width)+Math.max(0,-r.top)+Math.max(0,r.bottom-o.height))+t}}).sort((e,t)=>e.score-t.score)[0];l.push(f.box),s.push({x:f.candidate.x,y:f.candidate.y,text:c,anchor:f.candidate.anchor,baseline:"middle",fontSize:a,fill:i.labelColor??"var(--semiotic-text, #222)",stroke:"var(--semiotic-bg, white)",strokeWidth:3,paintOrder:"stroke"})}return s}function we(e,t,r){return(t.x-e.x)*(r.y-e.y)-(t.y-e.y)*(r.x-e.x)}function Me(e){return(1e-12>Math.abs(e)?0:e)+""}function ve(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:(e.storeName??"")+"",slotIndex:e.slotIndex??t}):[]}function ke(e,t){return Number.isFinite(e)?No(e,0,1):t}async function $e(e,t,r={}){let{prepareNetworkAtlas:n}=await(import("./c-IK33LNZ6.min.js"));return n(e,t,r)}async function Ae(e){let{prepareMotifBraid:t}=await(import("./c-Y6PYUMFU.min.js"));return t(e)}function Se(e,t){return e.length>t?e.slice(0,Math.max(1,t-1))+"…":e}function Ie(e,t,r,n,o,i,a,l){let s=t-n/2,c=r-o/2,u={fill:i,stroke:a,strokeWidth:l};switch(e){case"diamond":return Ea("polygon",{points:`${t},${c} ${t+n/2},${r} ${t},${r+o/2} ${s},${r}`,...u});case"circle":return Ea("circle",{cx:t,cy:r,r:Math.min(n,o)/2,...u});case"stadium":case"round":return Ea("rect",{x:s,y:c,width:n,height:o,rx:"stadium"===e?o/2:8,ry:"stadium"===e?o/2:8,...u});case"hexagon":{let e=Math.min(.18*n,16);return Ea("polygon",{points:`${s+e},${c} ${t+n/2-e},${c} ${t+n/2},${r} ${t+n/2-e},${r+o/2} ${s+e},${r+o/2} ${s},${r}`,...u})}case"cylinder":{let e=Math.min(.16*o,8),t=`M${s},${c+e} a${n/2},${e} 0 0 1 ${n},0`;return ja("g",{children:[Ea("path",{d:`M${s},${c+e} a${n/2},${e} 0 0 0 ${n},0 v${o-2*e} a${n/2},${e} 0 0 1 ${-n},0 z`,...u}),Ea("path",{d:t,fill:"none",stroke:a,strokeWidth:l})]})}case"subroutine":{let e=Math.min(8,.08*n);return ja("g",{children:[Ea("rect",{x:s,y:c,width:n,height:o,rx:3,...u}),Ea("line",{x1:s+e,y1:c,x2:s+e,y2:c+o,stroke:a,strokeWidth:l}),Ea("line",{x1:s+n-e,y1:c,x2:s+n-e,y2:c+o,stroke:a,strokeWidth:l})]})}default:return Ea("rect",{x:s,y:c,width:n,height:o,rx:4,...u})}}function Ce(e,t,r={}){let n=r.fingerprintRounds??3,o=[],i=new Set;for(let t of e)null==t.id||i.has(t.id)||(i.add(t.id),o.push(t.id));let{outAdj:a,inAdj:l,undirected:s}=Oe(o,t),c=Re(o,a,l,s,n).map(e=>({ids:e.ids,nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:je(e)})),u=new Map;for(let e of c){let t=u.get(e.motif);t?t.count+=1:u.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:c,motifs:[...u.values()].sort((e,t)=>t.count-e.count),directedCount:c.filter(e=>e.directed).length,branchingCount:c.filter(e=>!e.directed).length}}function Ne(e){let t=2166136261;for(let r=0;e.length>r;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function ze(e){return"string"==typeof e?e:e?.id}function Fe(e,t,r,n,o){let i=new Set(e),a=new Map;for(let n of e){let e=0,o=0;for(let e of t.get(n)??[])i.has(e)&&(o+=1);for(let t of r.get(n)??[])i.has(t)&&(e+=1);a.set(n,`${e}:${o}`)}for(let n=0;o>n;n+=1){let n=new Map;for(let o of e){let e=[];for(let r of t.get(o)??[])i.has(r)&&e.push(a.get(r));let l=[];for(let e of r.get(o)??[])i.has(e)&&l.push(a.get(e));e.sort(),l.sort(),n.set(o,Ne(`${a.get(o)}>${e.join(",")}<${l.join(",")}`))}a=n}let l=e.map(e=>a.get(e)).sort();return Ne(`${e.length}#${n}#${l.join(";")}`)}function Ee(e,t,r,n,o,i,a){function l(e){let t=0,r=0;for(let n of o.get(e)??[]){let e=m.get(n);p.has(n)&&e&&(t+=e.x,r+=1)}return r>0?t/r:i.x+h/2}let{layer:s,layerCount:c}=function(e,t){let r=new Set(e),n=new Map,o=new Set,i=e=>{let a=n.get(e);if(void 0!==a)return a;if(o.has(e))return 0;o.add(e);let l=0;for(let n of t.get(e)??[])r.has(n)&&(l=Math.max(l,1+i(n)));return o.delete(e),n.set(e,l),l},a=0;for(let t of e)a=Math.max(a,i(t));let l=new Map;for(let t of e)l.set(t,a-n.get(t));return{layer:l,layerCount:a+1}}(e.ids,n),u=Array.from({length:c},()=>[]);for(let t of e.ids)u[s.get(t)].push(t);let d=.14*Math.min(i.width,i.height),h=Math.max(1,i.width-2*d),f=Math.max(1,i.height-2*d),m=new Map,p=new Set(e.ids);for(let e=0;c>e;e+=1){let t=u[e];e>0&&(t=[...t].sort((e,t)=>l(e)-l(t)));let r=t.length,n=i.y+d+(1===c?.5:e/(c-1))*f;t.forEach((e,t)=>{m.set(e,{x:i.x+d+(1===r?.5:t/(r-1))*h,y:n})})}let g=u.reduce((e,t)=>Math.max(e,t.length),1),y=No(Math.min(a,h/(2.4*g),f/(2.4*c)),1.4,a),x=e.ids.map(e=>{let n=m.get(e);return{id:e,cx:n.x,cy:n.y,r:y,datum:t.get(e)??Ro({id:e}),category:r.get(e)??""}}),b=[];for(let t of e.ids){let e=m.get(t);for(let r of n.get(t)??[]){if(!p.has(r))continue;let t=m.get(r);b.push({x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:x,edges:b}}function je(e){let{nodeCount:t,edgeCount:r,sinkCount:n,sourceCount:o}=e;return 1===t?"isolate":2===t&&1===r?"pair":1===o&&1===n&&r===t-1?"chain of "+t:e.directed&&1===o&&r>t-1?"diamond / mesh":e.directed?`converging (${t})`:"branching → "+n}function Oe(e,t){let r=new Set(e),n=new Map,o=new Map,i=new Map;for(let t of e)n.set(t,new Set),o.set(t,new Set),i.set(t,new Set);for(let e of t){let t=e.source,a=e.target;!r.has(t)||!r.has(a)||t===a||n.get(t).has(a)||(n.get(t).add(a),o.get(a).add(t),i.get(t).add(a),i.get(a).add(t))}return{outAdj:n,inAdj:o,undirected:i}}function Re(e,t,r,n,o){let i=new Set,a=[];for(let l of e){if(i.has(l))continue;let e=[l];i.add(l);let s=[];for(;e.length;){let t=e.pop();s.push(t);for(let r of n.get(t)??[])i.has(r)||(i.add(r),e.push(r))}let c=new Set(s),u=0,d=0,h=0;for(let e of s){let n=0,o=0;for(let r of t.get(e)??[])c.has(r)&&(n+=1);for(let t of r.get(e)??[])c.has(t)&&(o+=1);h+=n,0===n&&(u+=1),0===o&&(d+=1)}a.push({ids:s,nodeCount:s.length,edgeCount:h,sinkCount:u,sourceCount:d,directed:1===u,motif:Fe(s,t,r,h,o)})}return a}function We(e,t,r){return e?Ee(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,r,3):null}function Te(e){return Ni(e)??e}function Le(e){return"string"==typeof e?e:e.id}function Pe(e,t){let r=Number(e);return Number.isFinite(r)&&r>0?r:t}function qe(e){return Math.round(100*e)/100+""}function De(e,t){if(2>e.length)return"";let r=`M${qe(e[0][0])},${qe(e[0][1])}`;for(let n=1;e.length-1>n;n+=1){let o=e[n-1],i=e[n],a=e[n+1],l=Math.hypot(i[0]-o[0],i[1]-o[1]),s=Math.hypot(a[0]-i[0],a[1]-i[1]),c=Math.min(t,l/2,s/2);if(0>=c){r+=`L${qe(i[0])},${qe(i[1])}`;continue}let u=[(i[0]-o[0])/l,(i[1]-o[1])/l],d=[(a[0]-i[0])/s,(a[1]-i[1])/s],h=[i[0]-u[0]*c,i[1]-u[1]*c],f=[i[0]+d[0]*c,i[1]+d[1]*c];r+=`L${qe(h[0])},${qe(h[1])}Q${qe(i[0])},${qe(i[1])} ${qe(f[0])},${qe(f[1])}`}let n=e[e.length-1];return`${r}L${qe(n[0])},${qe(n[1])}`}function Ve(e,t,r,n,o=.92*n){let i=Math.cos(r),a=Math.sin(r),l=-a,s=[e+i*n*.56,t+a*n*.56],c=e-i*n*.44,u=t-a*n*.44,d=[c+l*o*.5,u+i*o*.5],h=[c-l*o*.5,u-i*o*.5];return`M${qe(s[0])},${qe(s[1])}L${qe(d[0])},${qe(d[1])}L${qe(h[0])},${qe(h[1])}Z`}function Be(e,t){return`${t}\0${e}`}function He(e,t){return Math.max(1,e-2*Math.max(0,t.portPadding??4))}function Ye(e,t,r){if(1>=e)return 0;let n=Math.max(0,r.flowGap??.75),o=He(t,r);return Math.min(n,Math.max(0,(o-Math.min(.1,o))/(e-1)))}function Ge(e,t,r){let n="function"==typeof t?t(e):pi(e,t,r);return null==n||""===n?r:n+""}function _e(e,t){let r="function"==typeof t?t(e):pi(e,t,void 0);if(null!=r){if("object"==typeof r){let e=r.id;return null==e?void 0:e+""}return r+""}}function Xe(e,t){let r="function"==typeof t?t(e):pi(e,t,1);return Number(r)}function Ke(e,t){if(!t.has(e))return t.add(e),e;let r=2;for(;t.has(`${e}-${r}`);)r+=1;let n=`${e}-${r}`;return t.add(n),n}function Ue(e,t,r={}){let n=r.nodeIdAccessor??"id",o=r.groupAccessor??"group",i=r.labelAccessor??"label",a=r.sourceAccessor??"source",l=r.targetAccessor??"target",s=r.valueAccessor??"value",c=new Set(r.expandedGroups??[]),u=r.includeInternalFlows??!0,d=[],h=new Map,f=new Map;for(let t of e){let e=Ge(t,n,d.length+"");if(h.has(e))continue;let r=Ge(t,i,e),a=Ge(t,o,e),l={id:e,label:r,group:a,datum:t};d.push(l),h.set(e,l);let s=f.get(a);s?s.push(l):f.set(a,[l])}let m=new Set(d.map(e=>e.id)),p=[],g=new Map,y=new Map,x=[];for(let[e,t]of f){if(!c.has(e)&&(!0===r.collapseSingletons||t.length>1)){let n=Ke(`${r.groupIdPrefix??"group:"}${e}`,m),o={id:n,label:e,group:e,aggregate:!0,memberIds:t.map(e=>e.id),memberCount:t.length,internalValue:0,incomingValue:0,outgoingValue:0};p.push(o),g.set(n,o);for(let e of t)y.set(e.id,n);x.push({group:e,nodeId:n,label:e,collapsed:!0,memberIds:[...o.memberIds],internalValue:0,incomingValue:0,outgoingValue:0});continue}for(let r of t){let t={...r.datum,id:r.id,label:r.label,group:e,aggregate:!1,memberIds:[r.id],memberCount:1,internalValue:0,incomingValue:0,outgoingValue:0};p.push(t),g.set(t.id,t),y.set(r.id,t.id)}x.push({group:e,nodeId:null,label:e,collapsed:!1,memberIds:t.map(e=>e.id),internalValue:0,incomingValue:0,outgoingValue:0})}let b=new Map(x.map(e=>[e.group,e])),w=new Map,M=0;for(let e of t){let t=_e(e,a),r=_e(e,l),n=Xe(e,s),o=null==t?void 0:y.get(t),i=null==r?void 0:y.get(r);if(!(o&&i&&Number.isFinite(n)&&n>0)){M+=1;continue}let c=h.get(t)?.group,u=h.get(r)?.group;if(c&&u&&c===u){let e=b.get(c);e&&(e.internalValue+=n)}else{if(c){let e=b.get(c);e&&(e.outgoingValue+=n)}if(u){let e=b.get(u);e&&(e.incomingValue+=n)}}let d=w.get(o);d||(d=new Map,w.set(o,d));let f=d.get(i);f?(f.value+=n,f.edgeCount+=1,f.memberEdges.push(e)):d.set(i,{source:o,target:i,value:n,edgeCount:1,internal:o===i,memberEdges:[e]})}let v=[...w.values()].flatMap(e=>[...e.values()]);for(let e of v){let t=g.get(e.source),r=g.get(e.target);e.internal?t&&(t.internalValue+=e.value):(t&&(t.outgoingValue+=e.value),r&&(r.incomingValue+=e.value))}return{nodes:p,edges:u?v:v.filter(e=>!e.internal),groups:x,omittedEdgeCount:M}}function Qe(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();let t=e+"",r=Number(t);if(!Number.isNaN(r)&&""!==t.trim())return r;let n=Date.parse(t);return Number.isNaN(n)?NaN:n}function Ze(e,t,r){return t>e?t:e>r?r:e}function Je(e){let t=2166136261,r=e=>{for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619)};for(let n of e)r(n.id),r(n.col),r(n.row),t^=Math.round(8*n.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function et(e,t,r){let n=new Set,o=[];for(let t of e)r(t)&&!n.has(t)&&(n.add(t),o.push(t));for(let e of t)n.has(e)||o.push(e);return o}function tt(e,t){return e.topRadius+(t-e.height)/e.height*(e.topRadius-e.bottomRadius)}function rt(e,t){return function(e,t,r){return Math.PI*r/3*(e*e+e*t+t*t)}(tt(e,t),e.bottomRadius,t)}function nt(e,t){let r=(e.topRadius+e.bottomRadius)/2,n=Math.PI*r*r,o=t/n,i=t-rt(e,o),a=0;for(;100>a&&Math.abs(i)>1e-4;)o+=i/n,i=t-rt(e,o),a++;return o}function ot(e,t){let r=43758.5453*Math.sin(12.9898*e+78.233);return 2*(r-Math.floor(r)-.5)*t}function it(e,t){if(t>e||2*t>e)return[{x:0,y:0}];let r=[],n=e=>{let o=Math.floor(2*Math.PI*e/(2*t));1>o&&(o=1);let i=0*e;Math.hypot(1*e-e*Math.cos(2*Math.PI/o),i-e*Math.sin(2*Math.PI/o))<2*t&&o>1&&o--;for(let t=0;o>t;t++)r.push({x:e*Math.cos(2*t*Math.PI/o),y:e*Math.sin(2*t*Math.PI/o)});let a=e-2*t;t>a?e>2*t&&r.push({x:0,y:0}):n(a)};return n(e-t),r}function at(e,t,r){let n=[],o=r,i=0;for(;o>0&&60>i;){let r=t*(1+2*i),a=it(tt(e,r),t),l=a.length-o,s=l>1?a.slice(Math.floor(l/2),Math.floor(l/2)+o):a,c=e.height-r;if(s.forEach((e,t)=>{n.push({x:e.x+ot(97*i+t,.15),z:c+ot(31*i+t,.05)})}),o-=s.length,i++,0===s.length)break}return{pearls:n,layers:i}}function lt(e,t,r,n){if(0>=n)return[];let o=function(e,t,r){let n=r,o=0;for(;n>0&&60>o;){let r=tt(e,t+.875*(1+2*o));n-=Math.max(1,Math.floor(2*r/Ja)),o++}return o}(e,t,n),i=Math.max(t,r-o*Ja)+.875,a=[],l=0;for(let t=0;o>t&&n>l;t++){let r=i+Ja*t,o=tt(e,r),s=Math.max(1,Math.floor(2*o/Ja)),c=(2*o-s*Ja)/(s+1),u=-o+c,d=e.height-r-.875-.1;for(let e=0;s>e&&n>l;e++)a.push({cx:u+(c+Ja)*e+.875,cy:d+.875,rotation:ot(53*t+e,10)}),l++}return a}function st(e,t){let r=Number(e);return Number.isFinite(r)?r:t}function ct(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function ut(e,t={}){let r=t.fuels??rl,n=!0===t.includeZero,o=[];for(let t of e)if(t&&"number"==typeof t.t)for(let e of r){let r=ct(t.fuels?.[e]);!n&&0>=r||o.push({t:t.t,fuel:e,fuelLabel:nl[e],mw:r,ba:t.ba})}return o}function dt(e){let t=[];for(let r of e){if(!r||"number"!=typeof r.t)continue;let e=ct(r.demandMw),n=r.forecastMw;"number"!=typeof n||!Number.isFinite(n)||t.push({t:r.t,a:e,b:n,demandMw:e,forecastMw:n,errorMw:e-n,ba:r.ba})}return t}function ht(e){let t=ct(e.demand);if(0>=t)return 0;let r=ct(e.capacityOrNetGen),n=ct(e.interchange);return(r+(0>n?-n:0)-t)/t*100}function ft(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{let t=ct(e.demandMw),r=ct(e.netGenMw),n=ht({demand:t,capacityOrNetGen:r,interchange:e.interchangeMw});return{t:e.t,ba:e.ba,reserveMarginPct:n,netLoadMw:t,demandMw:t,netGenMw:r}})}function mt(e={},t={}){let{watch:r,comfortable:n}={...ol,...e},o=t.field,i=o?{field:o}:{},a=t.tightHatch??{type:"hatch",background:"var(--semiotic-danger, #c2410c)",stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9};return[{id:"reserve-comfortable",label:`Comfortable (≥ ${n}%)`,when:{...i,gte:n},style:{fill:t.comfortableFill??"var(--semiotic-success, #16a34a)",fillOpacity:.85}},{id:"reserve-watch",label:`Watch (< ${n}%, ≥ ${r}%)`,when:{...i,lt:n,gte:r},style:{fill:t.watchFill??"var(--semiotic-warning, #d97706)",fillOpacity:.9}},{id:"reserve-tight",label:`Tight (< ${r}%)`,when:{...i,lt:r},style:{fill:a,stroke:t.tightFill??"var(--semiotic-danger, #c2410c)",strokeWidth:1,fillOpacity:1}}]}function pt(e={}){let{tight:t,watch:r,comfortable:n}={...ol,...e};return[{type:"band",y0:-50,y1:t,label:"Tight",color:"var(--semiotic-danger, #c2410c)",fillOpacity:.12,emphasis:"secondary"},{type:"band",y0:t,y1:r,label:"Watch",color:"var(--semiotic-warning, #d97706)",fillOpacity:.1,emphasis:"secondary"},{type:"band",y0:r,y1:Math.max(n+30,40),label:"Headroom",color:"var(--semiotic-success, #16a34a)",fillOpacity:.06,emphasis:"secondary"}]}function gt(e,t){if(!e.length)return null;let r=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!r.length)return null;let n=r[r.length-1];if("number"==typeof t&&Number.isFinite(t)){let e=r.filter(e=>t>=e.t);n=e.length?e[e.length-1]:r[0]}let o=ct(n.demandMw),i=ct(n.netGenMw),a="number"==typeof n.forecastMw&&Number.isFinite(n.forecastMw)?n.forecastMw:null,l=ht({demand:o,capacityOrNetGen:i,interchange:n.interchangeMw}),s={},c=null,u=0,d=0;for(let e of rl){let t=ct(n.fuels?.[e]);0>=t||(d+=t,s[e]=t,t>u&&(u=t,c=e))}if(d>0)for(let e of Object.keys(s))s[e]=s[e]/d;return{t:n.t,ba:n.ba,demandMw:o,forecastMw:a,forecastErrorMw:null==a?null:o-a,netGenMw:i,reserveMarginPct:l,topFuel:c,topFuelShare:d>0?u/d:0,topFuelMw:u,fuelShares:s}}function yt(e,t={}){let r=t.now??Date.now(),n=t.author??"system",o=t.source??"authored-scenario";return e.map(e=>{let t=(e.start+e.end)/2,i=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:t,y:e.y??e.value,note:e.note,provenance:{author:n,authorKind:"system",source:o,basis:"rule",confidence:.85,createdAt:i,stableId:e.id,dataVersion:e.start+""},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:r}})}function xt(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function bt(e,t=0){return Number.isFinite(e)?e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})+" MW":"—"}function wt(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}function Mt(e,t){if("function"==typeof e)return e;let r=e??t;return e=>Number(e[r])}function vt(e,t={}){let r=Mt(t.start,"start"),n=Mt(t.end,"end"),o=!1===t.sort?e.slice():e.slice().sort((e,t)=>r(e)-r(t)||n(t)-n(e)),i=new al;return{packed:o.map(e=>({item:e,track:i.assign(r(e),n(e))})),trackCount:Math.max(1,i.count)}}function kt(e,t){let r=Mt(t.start,"start"),n=Mt(t.end,"end"),[o,i]=t.domain,a=t.step??1,l="half-open"===t.bounds;if(o>i)return[];let s=(i-o)/a>Math.log2(e.length+1),c=[],u=[];if(s){for(let t of e){let e=r(t),o=n(t);o>=e&&(c.push(e),u.push(o))}c.sort((e,t)=>e-t),u.sort((e,t)=>e-t)}let d=0,h=0,f=[];for(let t=o;i>=t;t+=a){let o=0;if(s){for(;c.length>d&&t>=c[d];)d++;for(;u.length>h&&(l?t>=u[h]:t>u[h]);)h++;o=d-h}else for(let i of e){let e=r(i),a=n(i);t>=e&&(l?a>t:a>=t)&&o++}f.push({value:t,count:o})}return f}function $t(e){return"function"==typeof e?e:t=>t[e]}function At(e,t,r){let n=r?.orientation??"vertical",o=r?.bend??0,i=r?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===n){if(i>Math.abs(t.y-e.y)){let r=e.x>t.x?-1:1,n=a(e.x,t.x)+r*(22+Math.abs(o));return`M${e.x},${e.y} Q${n},${a(e.y,t.y)} ${t.x},${t.y}`}let r=a(e.y,t.y)+o;return`M${e.x},${e.y} C${e.x},${r} ${t.x},${r} ${t.x},${t.y}`}if(i>Math.abs(t.x-e.x)){let r=e.y>t.y?-1:1,n=a(e.y,t.y)+r*(22+Math.abs(o));return`M${e.x},${e.y} Q${a(e.x,t.x)},${n} ${t.x},${t.y}`}let l=a(e.x,t.x)+o;return`M${e.x},${e.y} C${l},${e.y} ${l},${t.y} ${t.x},${t.y}`}function St(e,t,r){if("vertical"===(r?.orientation??"vertical")){let r=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${r} L${t.x},${r} L${t.x},${t.y}`}let n=(e.x+t.x)/2;return`M${e.x},${e.y} L${n},${e.y} L${n},${t.y} L${t.x},${t.y}`}function It(e,t,r){if("vertical"===(r?.orientation??"vertical")){let r=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(r?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(r?-t.height/2:t.height/2)}}}let n=t.cx>=e.cx;return{from:{x:e.cx+(n?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(n?-t.width/2:t.width/2),y:t.cy}}}function Ct(e,t){let r=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*r:(e-((t?.count??1)-1)/2)*r}function Nt(e,t){let r=1-t,n=r*r*r,o=3*r*r*t,i=3*r*t*t,a=t*t*t;return{x:n*e.p0.x+o*e.p1.x+i*e.p2.x+a*e.p3.x,y:n*e.p0.y+o*e.p1.y+i*e.p2.y+a*e.p3.y}}function zt(e,t){let r=1-t,n=3*r*r,o=6*r*t,i=3*t*t;return{x:n*(e.p1.x-e.p0.x)+o*(e.p2.x-e.p1.x)+i*(e.p3.x-e.p2.x),y:n*(e.p1.y-e.p0.y)+o*(e.p2.y-e.p1.y)+i*(e.p3.y-e.p2.y)}}function Ft(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function Et(e,t){let r=t?.axis??"x",n=t?.padding??0,o=t?.strength??.5,i="x"===r?"y":"x",a="x"===r?"width":"height",l="x"===r?"height":"width",s=new Map;for(let t of e)s.set(t.id,0);for(let t=0;e.length>t;t++)for(let c=t+1;e.length>c;c++){let u=e[t],d=e[c];if(Math.abs(u[i]-d[i])>(u[l]+d[l])/2+n)continue;let h=d[r]-u[r]||(d.id>u.id?-.5:.5),f=(u[a]+d[a])/2+n-Math.abs(h);if(0>=f)continue;let m=f*o*Math.sign(h);s.set(u.id,(s.get(u.id)??0)-m),s.set(d.id,(s.get(d.id)??0)+m)}return s}function jt(e,t){if("function"==typeof e)return e;let r=e??t;return e=>pi(e,r,void 0)}function Ot(e,t,r,n){let o=n.fixedAxis??"y",i=e=>jt(n.sourceAccessor,"source")(e)+"",a=e=>jt(n.targetAccessor,"target")(e)+"",l=n.size??(()=>sl),s=n.iterations??180,c=n.attraction??.012,u=n.anchorStrength??.003,d=n.collisionStrength??.12,h=n.collisionPadding??15,f=n.edgePadding??42,m=n.fixedPadding??16,p=n.damping??.72,g=n.spread??1,[y,x]=n.fixedDomain,b=x-y||1,w=("y"===o?r.y:r.x)+m,M=("y"===o?r.y+r.height:r.x+r.width)-m,v=("y"===o?r.x:r.y)+f,k=("y"===o?r.x+r.width:r.y+r.height)-f,$=Math.max(1,k-v),A=e.map(e=>{let t=Ni(e)??e,r=(c=e,jt(n.idAccessor,"id")(c)+""),{width:o,height:i}=l(t),a=(e=>Number(jt(n.fixedAccessor,"fixed")(e)))(e),s=v+function(e){let t=2166136261;for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0)/4294967295}(r)*$;var c,u;return{data:t,id:r,width:o,height:i,fixedValue:a,fixed:(u=a,w+(u-y)/b*(M-w)),free:s,anchor:s}}),S=new Map(A.map(e=>[e.id,e])),I=e=>"y"===o?e.width:e.height;for(let e=0;s>e;e++){let e=new Map;for(let t of A)e.set(t.id,0);for(let r of t){let t=S.get(i(r)),n=S.get(a(r));if(!t||!n)continue;let o=(n.free-t.free)*c;e.set(t.id,(e.get(t.id)??0)+o),e.set(n.id,(e.get(n.id)??0)-o)}for(let t of A)e.set(t.id,(e.get(t.id)??0)+(t.anchor-t.free)*u);let r=Et(A.map(e=>({id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height})),{axis:"y"===o?"x":"y",padding:h,strength:d});for(let t of A)e.set(t.id,(e.get(t.id)??0)+(r.get(t.id)??0));for(let t of A){t.free+=(e.get(t.id)??0)*p;let r=I(t)/2;t.free=Math.max(v+r,Math.min(k-r,t.free))}}if(1!==g){let e=(v+k)/2;for(let t of A){let r=I(t)/2;t.free=Math.max(v+r,Math.min(k-r,e+(t.free-e)*g))}}let C=A.map(e=>({data:e.data,id:e.id,x:"y"===o?e.free:e.fixed,y:"y"===o?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:C,byId:new Map(C.map(e=>[e.id,e]))}}function Rt(e){let t=Number(e.segmentDomain?.[0]),r=Number(e.segmentDomain?.[1]),n=Number.isFinite(t)?t:0,o=Number.isFinite(r)?r:n,i=n>o?-1:1,a=Math.abs(o-n),l=Number(e.currentSegment),s=Number.isFinite(l)?No((l-n)*i,0,a):0,c=(e,t)=>{let r=Number(e);return Number.isFinite(r)?No(r,0,1):t},u=c(e.oldestOpacity,.25),d=c(e.currentOpacity,1),h=c(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{let t=Number(e);if(!Number.isFinite(t))return h;let r=(t-n)*i;if(r>s)return h;if(0===s)return d;let o=No(r/s,0,1);return u+(d-u)*o}}}function Wt(e){let t=2166136261;for(let r=0;e.length>r;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0)/4294967295}function Tt(e){let t=0;for(let r of e)t+=fl[r]??.6;return t}function Lt(e,t){return Math.max(8,Tt(e)*t*1.05+1)}function Pt(e,t,r){for(let n of t)if((e.w+n.w)/2+r>Math.abs(e.x-n.x)&&(e.h+n.h)/2+r>Math.abs(e.y-n.y))return!0;return!1}function qt(e){let t=[],r=e.segHi-e.segLo||1;for(let n=0;e.tickCount>n;n++)t.push(e.segLo+r*n/Math.max(1,e.tickCount-1));return dl("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[ul("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,r)=>{let n=e.segToY(t);return dl("g",{children:[ul("line",{x1:e.x-4,y1:n,x2:e.x,y2:n,stroke:e.color,strokeWidth:1,opacity:.6}),ul("text",{x:e.x-7,y:n,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},"wt-tick-"+r)}),e.label&&ul("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}function Dt(e){return null==e?void 0:e+""}function Vt(e){let t=Dt(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...pl,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function Bt(e){return Vt(e)}function Ht(e){let[[t,r],[n,o]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((n-t)*(o-r)),style:{...pl,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function Yt(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...pl,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:Dt(e.id)}}function Gt(e){let t=Dt(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...pl,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...pl,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function _t(e){let t={style:{...pl,cursor:e.cursor},datum:e.datum,id:Dt(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?{type:e.type??"curved",pathD:e.pathD,...t}:{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function Xt(e,t,r={}){let{coord:n,step:o=1,equals:i=Object.is,truthyOnly:a=!1}=r,l=[],s=t=>n?n(e[t],t):t,c=(e,t,r)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=n?null==r||s(r)-s(t)>o?s(t)+o:s(r):t+1,l.push(e)},u=null;for(let r=0;e.length>r;r++){let l=t(e[r],r);if(a&&!l){u&&(c(u,u.endIndex,r),u=null);continue}let d=!n||0>=r||s(r)-s(r-1)<=o;u&&d&&i(u.value,l)?u.endIndex=r:(u&&c(u,u.endIndex,r),u={value:l,start:s(r),end:s(r),count:1,startIndex:r,endIndex:r})}return u&&c(u,u.endIndex,null),l}function Kt(e,t,r=0){return t>0?((e-r)%t+t)%t+r:e}function Ut(e,t,r){if(0>=r)return t-e;let n=(t-e)%r;return n>r/2?n-=r:-r/2>n&&(n+=r),n}function Qt(e,t,r){return t>r?e>=t||r>=e:e>=t&&r>=e}function Zt(e,t,r,n){return r>n?[...e.filter(e=>t(e)>=r),...e.filter(e=>t(e)<=n)]:e.filter(e=>Qt(t(e),r,n))}function Jt(e,t){let r=Math.max(0,t.width),n=t.y,o=Math.min(74,Math.max(34,.08*r)),i=t.paddingLeft??o,a=e.length>1?Math.max(0,r-i-(t.paddingRight??o))/(e.length-1):0,l=new Map;return e.forEach((e,t)=>{l.set(e.id,{id:e.id,x:i+a*t,y:n,index:t})}),l}function er(e,t){let r=Math.max(0,t.width),n=t.y,o=Math.min(74,Math.max(34,.08*r)),i=t.paddingLeft??o,a=t.paddingRight??o,l=t.gap??8,s=!1!==t.distribute,c=t.estimateWidth??(e=>tr(e.label??e.id)),u=e.map((e,t)=>Math.max(1,c(e,t))),d=u.reduce((e,t)=>e+t,0)+l*Math.max(0,e.length-1),h=Math.max(0,r-i-a),f=s&&e.length>1?Math.max(0,h-d)/(e.length-1):0,m=new Map,p=i;return!s&&1===e.length&&(p=i+Math.max(0,(h-u[0])/2)),e.forEach((e,t)=>{let r=u[t];m.set(e.id,{id:e.id,x:p+r/2,y:n,index:t,width:r}),p+=r+l+f}),m}function tr(e,t=38,r=7.4,n=20){return Math.max(t,((e??"")+"").length*r+n)}function rr(e){let t=e.map(e=>{let t=Math.min(e.a,e.b),r=Math.max(e.a,e.b);return{span:e,a:t,b:r,width:r-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),r=new al,n=t.map(e=>{let t=r.assign(e.a,e.b);return{span:e.span,level:t}}),o=Math.max(0,r.count-1);return{packed:n,maxLevel:o,levelCount:n.length?o+1:1}}function nr(e){let t=e.labelRoom??18,r=Math.max(48,e.baselineY-e.ceilingY-28),n=Math.max(1,e.levelCount),o=Math.min(42,Math.max(26,.18*r)),i=Math.max(24,r-o-t);return{arcLift:o,levelStep:Math.min(72,Math.max(28,n>1?i/Math.max(1,n-1):i))}}function or(e,t,r,n,o={}){let i=r-(o.footLift??26);return`M${e} ${i}Q${(e+t)/2} ${n} ${t} ${i}`}function ir(e,t,r){return e-r.arcLift-t*r.levelStep}function ar(e,t=lr){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};let r=e.map(e=>new Set(e.map(e=>t(e)))),n=new Set;for(let e of r[0])r.every(t=>t.has(e))&&n.add(e);let o=[],i=new Set;for(let r of e[0]){let e=t(r);n.has(e)&&!i.has(e)&&(o.push(r),i.add(e))}return{shared:o,exclusive:e.map(e=>e.filter(e=>!n.has(t(e))))}}function lr(e){return null==e||"object"!=typeof e?e+"":null!=e.id?e.id+"":`${(e.sourceTokenId??e.source)+""}|${(e.targetTokenId??e.target)+""}|${(e.relation??e.label??"")+""}`}function sr(e,t,r){let n=r?.center?.x??0,o=r?.center?.y??0;return{x:n+Math.sin(e)*t,y:o-Math.cos(e)*t}}function cr(e,t,r){return(Math.atan2(e-(r?.center?.x??0),-(t-(r?.center?.y??0)))+xl)%xl}function ur(e,t){let[r,n]=e,o=n-r||1,i=t?.startAngle??0,a=t?.endAngle??xl;return e=>i+(e-r)/o*(a-i)}function dr(e,t){let[r,n]=e,[o,i]=t,a=n-r||1;return e=>o+(e-r)/a*(i-o)}function hr(e,t,r,n,o){let i=o?.center,a=(e,t)=>{let{x:r,y:n}=sr(e,t,{center:i});return`${fr(r)},${fr(n)}`},l=Math.max(0,r),s=Math.max(l,n),c=Math.abs(t-e),u=e>t?0:1;if(c>=xl-1e-6){let e=i?.x??0,t=i?.y??0,r=`${fr(e)},${fr(t-s)}`,n=`${fr(e)},${fr(t+s)}`,o=`M${r} A${fr(s)},${fr(s)} 0 1 1 ${n} A${fr(s)},${fr(s)} 0 1 1 ${r} Z`;if(l>0){let r=`${fr(e)},${fr(t-l)}`,n=`${fr(e)},${fr(t+l)}`;o+=` M${r} A${fr(l)},${fr(l)} 0 1 0 ${n} A${fr(l)},${fr(l)} 0 1 0 ${r} Z`}return o}let d=c>Math.PI?1:0,h=a(e,s),f=a(t,s);if(0>=l){let e=i?.x??0,t=i?.y??0;return`M${fr(e)},${fr(t)} L${h} A${fr(s)},${fr(s)} 0 ${d} ${u} ${f} Z`}let m=a(t,l),p=a(e,l);return`M${h} A${fr(s)},${fr(s)} 0 ${d} ${u} ${f} L${m} A${fr(l)},${fr(l)} 0 ${d} ${1===u?0:1} ${p} Z`}function fr(e){return Math.round(1e3*e)/1e3}function mr(e,t){return{x:e.x+t.x,y:e.y+t.y}}function pr(e,t){return{x:e.x-t.x,y:e.y-t.y}}function gr(e,t){return{x:e.x*t,y:e.y*t}}function yr(e){return Math.hypot(e.x,e.y)}function xr(e){let t=yr(e)||1;return{x:e.x/t,y:e.y/t}}function br(e,t){let r=Si(e,100);return r>0?t/r*100*(t/r):Math.PI*t*t}function wr(e){let t=[],r=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(r.length>0){let n=e.colorType??"fill",o=r.map(([e,t])=>({label:e,color:t}));t.push({type:n,label:e.colorLabel??"",items:o,styleFn:"line"===n?e=>({stroke:e.color??Ml,strokeWidth:2,fill:"none"}):e=>({fill:e.color??Ml,stroke:e.color??Ml})})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){let r=e.symbolColor??Ml,n=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:r}));t.push({label:e.symbolLabel??"",items:n,styleFn:()=>({}),type:e=>{let t=e.shape;return bl("path",{d:Ii(t,br(t,7)),transform:"translate(8,8)",fill:e.color??r})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){let r=e.sizeRadius,n=e.sizeFormat??(e=>e+""),o=e.sizeColor??Ml,i=e.sizeStops.map(e=>({label:n(e),r:Math.max(.5,r(e)),color:o}));t.push({label:e.sizeLabel??"",items:i,styleFn:()=>({}),type:e=>bl("circle",{cx:8,cy:8,r:e.r,fill:e.color??o})})}return t}function Mr(e){let t=e.orientation??"vertical",r=e.swatchSize??14,n=e.gap??8,o=e.labelGap??6,i=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",l=r+n,s=0,c=[];return e.entries.forEach((e,u)=>{c.push(wl("g",{transform:`translate(${"vertical"===t?0:s},${"vertical"===t?s:0})`,children:[vr(e,r,e.color??e.line??a,a),bl("text",{x:r+o,y:r/2,dominantBaseline:"middle",fontSize:i,fill:a,children:e.label})]},"legend-"+u)),s+="vertical"===t?l:r+o+e.label.length*i*.58+n+8}),bl("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:c},e.keyId)}function vr(e,t,r,n){if(e.shape){let n=br(e.shape,t/2-1);return bl("path",{d:Ii(e.shape,n),transform:`translate(${t/2},${t/2})`,fill:r})}if(e.hatch){let r=e.color??n;return wl("g",{children:[bl("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,n)=>bl("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:r,strokeWidth:1,opacity:.7},n))}),bl("rect",{width:t,height:t,fill:"none",stroke:r,strokeWidth:1,opacity:.5,rx:2})]})}return bl("rect",e.line?{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}:{width:t,height:t,rx:2,fill:r})}function kr(e){let t=e,r=[Ir(t,["datum","data"]),Ir(t,["datum"]),Ir(t,["data","data"]),Ir(t,["data"]),Ir(t,["node","datum","data"]),Ir(t,["node","datum"]),e];for(let e of r){if(!Cr(e))continue;let t={};for(let[r,n]of Object.entries(e))r.startsWith("_")||"function"==typeof n||(t[r]=n);if(Object.keys(t).length>0)return t}return null}function $r(e,t={}){let r=kr(e);if(!r)return[];let n=new Set(vl);if(t.excludeKeys)for(let e of t.excludeKeys)n.add(e);let o=[];for(let[e,i]of Object.entries(r))if((t.includeInternal||!e.startsWith("_"))&&!n.has(e)&&(t.includeEmpty||null!=i&&""!==i)&&"function"!=typeof i&&(o.push({key:e,label:Sr(e,t.labels),value:i,formatted:t.valueFormat?t.valueFormat(i,e,r):Ar(i)}),o.length>=(t.maxEntries??8)))break;return o}function Ar(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?e+"":e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return e.length+" items";if("object"==typeof e)try{return JSON.stringify(e)}catch{return e+""}return e+""}function Sr(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){let r=t[e];if("string"==typeof r&&r.length>0)return r}return e}function Ir(e,t){let r=e;for(let e of t){if(!Cr(r))return;r=r[e]}return r}function Cr(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Nr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function zr(e,t){return Nr(e,t)?e[t]:void 0}function Fr(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function Er(){return Object.create(null)}function jr(e,t){let r=new Map;for(let t of e)r.set(t.id,new Set);for(let e of t)r.has(e.source)||r.set(e.source,new Set),r.has(e.target)||r.set(e.target,new Set),r.get(e.source).add(e.target),r.get(e.target).add(e.source);return r}function Or(e,t){let r={};for(let t of e)Fr(r,t.id,0);for(let e of t)Fr(r,e.source,(zr(r,e.source)??0)+1),Fr(r,e.target,(zr(r,e.target)??0)+1);return r}function Rr(e,t){let r={};Fr(r,t,0);let n=[t],o=0;for(;n.length>o;){let t=n[o];o+=1;for(let o of e.get(t)||[])Nr(r,o)||(Fr(r,o,r[t]+1),n.push(o))}return r}function Wr(e,t,r,n){if(r===n)return r?[r]:[];let o=jr(e,t),i=Er();i[r]=null;let a=[r],l=0;for(;a.length>l;){let e=a[l];if(l+=1,e===n)break;for(let t of o.get(e)||[])Nr(i,t)||(i[t]=e,a.push(t))}if(!Nr(i,n))return[];let s=[],c=n;for(;null!=c;)s.unshift(c),c=i[c];return s}function Tr(e,t,r,n=1){let o=jr(e,t);if(!o.has(r))return new Set;let i=Rr(o,r),a=new Set;for(let e of Object.keys(i))n>=i[e]&&a.add(e);return a}function Lr(e,t){let r=jr(e,t),n={};for(let t of e)Fr(n,t.id,0);for(let t of e.map(e=>e.id)){let o=[],i=Er(),a=Er(),l=Er();for(let t of e)i[t.id]=[],a[t.id]=0,l[t.id]=-1;a[t]=1,l[t]=0;let s=[t],c=0;for(;s.length>c;){let e=s[c];c+=1,o.push(e);for(let t of r.get(e)||[])0>l[t]&&(l[t]=l[e]+1,s.push(t)),l[t]===l[e]+1&&(a[t]+=a[e],i[t].push(e))}let u=Er();for(let t of e)u[t.id]=0;for(;o.length;){let e=o.pop();for(let t of i[e])u[t]+=a[t]/a[e]*(1+u[e]);e!==t&&Fr(n,e,(zr(n,e)??0)+u[e])}}for(let e of Object.keys(n))Fr(n,e,n[e]/2);return n}function Pr(e,t){let r=jr(e,t),n={};for(let t of e){let e=Rr(r,t.id),o=0,i=0;for(let t of Object.keys(e))o+=e[t],i+=1;Fr(n,t.id,o>0?(i-1)/o:0)}return n}function qr(e,t){let r=jr(e,t),n={};for(let t of e){let e=[...r.get(t.id)||[]],o=e.length;if(2>o){Fr(n,t.id,0);continue}let i=0;for(let t=0;e.length>t;t+=1)for(let n=t+1;e.length>n;n+=1)r.get(e[t])?.has(e[n])&&(i+=1);Fr(n,t.id,2*i/(o*(o-1)))}return n}function Dr(e){let t=0;for(let r of Object.keys(e))e[r]>t&&(t=e[r]);let r={};for(let n of Object.keys(e))Fr(r,n,t>0?e[n]/t:0);return r}function Vr(e,t,r,n={}){let o=jr(e,t),i=Er();for(let t of e)i[t.id]=Rr(o,t.id);let a=n.minHops??4,l=n.startThreshold??.08,s=n.maxThreshold??.2,c=new Set,u=0;for(;0===c.size&&40>u;){for(let t=0;e.length>t;t+=1)for(let n=t+1;e.length>n;n+=1){let o=e[t].id,s=e[n].id,u=zr(r,o),d=zr(r,s);if(!u||!d)continue;let h=u.x-d.x,f=u.y-d.y;(void 0===i[o][s]?1/0:i[o][s])>=a&&l>Math.sqrt(h*h+f*f)&&(c.add(o),c.add(s))}0===c.size&&(l+=.02,l>s&&(l=n.startThreshold??.08,a=Math.max(2,a-1))),u+=1}return{problemIds:c,threshold:l,minHops:a}}function Br(e){if("u">typeof DOMException)return new DOMException(e+" aborted","AbortError");let t=Error(e+" aborted");return t.name="AbortError",t}function Hr(e){let t=Error(e.message);return t.name=e.name??"Error",e.stack&&(t.stack=e.stack),t}function Yr(){return"u">typeof window&&"u">typeof Worker}async function Gr(e,t,r={}){let{execution:n="auto",signal:o,workerThreshold:i,nodeRadius:l,...s}=r,c=s.iterations??260;if(!Yr()||!function(e,t,r,n,o=4e4){return"sync"!==e&&("worker"===e||n*(t+r)>=o)}(n,e.length,t.length,c,i))return a(e,t,{...s,nodeRadius:l});let u={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:s,nodeRadii:"function"==typeof l?Object.fromEntries(e.map(e=>[e.id,l(e)])):null==l?void 0:Object.fromEntries(e.map(e=>[e.id,l]))};try{return(await function(e,t){return Yr()?Al.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(u,o)).positions}catch(r){if("AbortError"===r?.name)throw r;return a(e,t,{...s,nodeRadius:l})}}function _r(e,t,r){return Math.max(t,Math.min(r,e))}function Xr(e,t,r={}){let n=r.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],i=_r(r.along??.5,.05,.95),a=r.jitterX??0,l=r.padY??20,s=o.x0+(o.x1-o.x0)*i+(2*n()-1)*a,c=Math.min(1,o.width/2),u=_r(s,o.x0+c,o.x1-c),d=e.boundaryY(u,"top")+l,h=e.boundaryY(u,"bottom")-l;return{x:u,y:h>d?d+n()*Math.max(1,h-d):e.midY}}function Kr(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function Ur(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Qr(e,t,r,n,o){return"function"==typeof n?n(e,t,r):function(e,t){let r=e;for(let e of t.split(".")){if(null==r||"object"!=typeof r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}(e,n??o)}function Zr(e){let t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Jr(e,t,r,n){let o=e.flatMap((e,o)=>{let i=Ur(Qr(e,o,t,r,"time")),a=Ur(Qr(e,o,t,n,"value"));return null==i||null==a?[]:[{time:Zr(i),value:a,index:o}]});o.sort((e,t)=>e.time-t.time||e.index-t.index);let i=[];for(let e of o){let t=i[i.length-1];t?.time===e.time?t.value=e.value:i.push({time:e.time,value:e.value})}return i}function en(e,t,r,n){if(!e.length)return null;let o=e[0],i=e[e.length-1];if(o.time>t)return"clamp"===n?o.value:null;if(t>i.time)return"clamp"===n?i.value:null;let a=function(e,t){let r=0,n=e.length;for(;n>r;){let o=r+n>>>1;t>e[o].time?r=o+1:n=o}return r}(e,t),l=e[a];if(l?.time===t)return l.value;let s=e[Math.max(0,a-1)];return"step"!==r&&l&&l.time!==s.time?s.value+(t-s.time)/(l.time-s.time)*(l.value-s.value):s.value}function tn(e,t){if(1===e.length)return e[0];let r=(e.length-1)*t,n=Math.floor(r),o=Math.ceil(r);return n===o?e[n]:e[n]+(e[o]-e[n])*(r-n)}function rn(e){let t=e.interpolation??"step",r=e.outsideDomain??"omit",n=function(e){let t=(e??Sl).map(e=>{let t=Ur(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return Zr(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),o=function(e){if(Array.isArray(e)){if(e.length>Il)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Ur).filter(e=>null!=e).map(Zr))).sort((e,t)=>e-t)}let t=e,r=Ur(t.start),n=Ur(t.end),o=Ur(t.step);if(null==r||null==n||null==o||0>=o||r>n)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");let i=Math.floor((n-r)/o)+1;if(i>Il)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");let a=[],l=1e-10*Math.max(1,Math.abs(n),Math.abs(r));for(let e=0;i>e;e+=1){let t=r+e*o;if(t>n+l)break;a.push(Zr(Math.min(t,n)))}if((!a.length||Math.abs(a[a.length-1]-n)>l)&&a.push(Zr(n)),a.length>Il)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),i=e.runs.map(t=>Jr(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:o.map(e=>{let o=i.map(n=>en(n,e,t,r)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(let e of n)a[e]=o.length?tn(o,e):null;return{time:e,count:o.length,min:o.length?o[0]:null,max:o.length?o[o.length-1]:null,median:o.length?tn(o,.5):null,quantiles:a}}),quantiles:n,interpolation:t,outsideDomain:r,runCount:e.runs.length}}function nn(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function on(e,t){if("min"===t||"median"===t||"max"===t)return e[t];let r=Ur(t);if(null==r||0>r||r>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);let n=Zr(r);if(!Object.prototype.hasOwnProperty.call(e.quantiles,n))throw Error(`comparePhysicsTrace could not find quantile ${n} in the reference envelope`);return e.quantiles[n]??null}function an(e,t,r){return t>e?"below":e>r?"above":"inside"}function ln(e,t){let r=Math.max(0,t.time-e.time);if(0>=r||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};let n=e.value-e.lower,o=t.value-t.lower,i=e.value-e.upper,a=t.value-t.upper,l=[0,1];for(let[e,t]of[[n,o],[i,a]])(0>e&&t>0||e>0&&0>t)&&l.push(-e/(t-e));l.sort((e,t)=>e-t);let s=0,c=0,u=0;for(let n=0;l.length-1>n;n+=1){let o=l[n],i=l[n+1];if(o>=i)continue;let a=(o+i)/2,d=(i-o)*r,h=an(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?s+=d:"above"===h?u+=d:c+=d}return{below:s,inside:c,above:u,observed:r}}function sn(e,t,r={}){let n=r.interpolation??t.interpolation,o=r.outsideDomain??t.outsideDomain,i=Jr(e,r.traceId??"trace",r.timeAccessor,r.valueAccessor),a=r.lower??nn(t,"lower"),l=r.upper??nn(t,"upper"),s=t.points.map(e=>{let t=en(i,e.time,n,o),r=on(e,a),s=on(e,l);if(null!=r&&null!=s&&r>s)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:r,upper:s,status:null==t||null==r||null==s?"unobserved":an(t,r,s)}}),c=0,u=0,d=0,h=0,f=null,m=0,p=null;for(let e of s){if("below"===e.status?c+=1:"inside"===e.status?u+=1:"above"===e.status&&(d+=1),null==e.value||null==e.lower||null==e.upper)continue;let t=Math.max(0,e.value-e.upper),r=Math.max(0,e.lower-e.value);t>h&&(h=t,f=e.time),r>m&&(m=r,p=e.time)}let g=0,y=0,x=0,b=0;for(let e=0;s.length-1>e;e+=1){let t=s[e],r=s[e+1],o=Math.max(0,r.time-t.time);if(o>0){if("linear"===n){let e=ln(t,r);g+=e.below,y+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=o,"below"===t.status?g+=o:"above"===t.status?x+=o:y+=o)}}let w=s[0]?.time,M=s[s.length-1]?.time,v=null==w||null==M?0:Math.max(0,M-w);return{points:s,sampleCount:s.length,observedSamples:c+u+d,belowSamples:c,insideSamples:u,aboveSamples:d,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:g,insideDuration:y,aboveDuration:x,peakExcess:h,peakExcessAt:f,peakDeficit:m,peakDeficitAt:p}}function cn(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function un(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function dn(e){return!!un(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&un(e.visitsByStage)&&un(e.firstEnteredAt)&&un(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function hn(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function fn(e){let t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,hn(e)]))}}function mn(e,t,r={}){if("region-enter"!==t.type)return e;let n=function(e,t){let r=t.stageId?.(e);if(r)return r;let n=e.region.metadata;if(n&&"object"==typeof n&&Object.prototype.hasOwnProperty.call(n,"stageId")){let e=n.stageId;if("string"==typeof e)return e}return e.region.id}(t,r),o=e.stages.findIndex(e=>e.id===n);if(0>o)return e;let i=r.entityId?.(t)??t.bodyId;if(!i)return e;let a=cn(e.entities,i),l=dn(a)?a:hn(i),s=l.currentStageId?e.stages.findIndex(e=>e.id===l.currentStageId):-1,c=!l.visitedStageIds.includes(n),u=Number(t.observation.timestamp),d=Number.isFinite(u)?u:0,h=cn(l.visitsByStage,n),f="number"==typeof h&&Number.isFinite(h)?h:0,m={...l,currentStageId:n,furthestStageId:o>l.furthestStageIndex?n:l.furthestStageId,furthestStageIndex:Math.max(l.furthestStageIndex,o),visitedStageIds:c?[...l.visitedStageIds,n]:l.visitedStageIds,visitsByStage:{...l.visitsByStage,[n]:f+1},firstEnteredAt:c?{...l.firstEnteredAt,[n]:d}:l.firstEnteredAt,lastEnteredAt:{...l.lastEnteredAt,[n]:d},regressionCount:s>=0&&s>o?l.regressionCount+1:l.regressionCount};return{...e,bodyIds:e.bodyIds.includes(i)?e.bodyIds:[...e.bodyIds,i],entities:{...e.entities,[i]:m}}}function pn(e){let t=e.bodyIds.map(t=>{let r=cn(e.entities,t);return dn(r)?r:hn(t)}),r=t.length,n=r;return e.stages.map((e,o)=>{let i=t.filter(e=>e.furthestStageIndex>=o).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,l=t.reduce((t,r)=>{let n=cn(r.visitsByStage,e.id);return t+("number"==typeof n&&Number.isFinite(n)?n:0)},0),s={id:e.id,label:e.label??e.id,reached:i,entered:a,total:r,conversion:r>0?i/r:0,fromPrevious:n>0?i/n:0,dropoff:Math.max(0,n-i),visits:l,repeatVisits:Math.max(0,l-a)};return n=i,s})}function gn(e,t){if("function"==typeof t){let r=t(e);return Number.isFinite(r)&&r>0?Number(r):1}let r=e.datum;if(t&&r&&"object"==typeof r){let e=Number(r[t]);if(Number.isFinite(e)&&e>0)return e}let n=Number(r?.work??r?.reviewWork??r?.value);return Number.isFinite(n)&&n>0?n:1}function yn(e,t){if("function"==typeof t){let r=t(e);if(null!=r&&(r+"").length>0)return r+""}else if(t){let r=Fi(e.datum,t),n=Fi(e,t),o=r??n;if(null!=o&&(o+"").length>0)return o+""}return e.id}function xn(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];let r=Math.max(0,Math.min(1,t))*(e.length-1),n=Math.floor(r);return e[n]+(e[Math.ceil(r)]-e[n])*(r-n)}function bn(e){function t(e,t){let r=t(e);return!!r&&r.activeRegionIds.includes(c)}function r(){H+=1}function n(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:c,work:e.total,queuedAt:e.queuedAt}}function o(t,o,i,a){let l={bodyId:t.id,jobId:o.jobId,visitId:o.visitId,visit:o.visit,remaining:o.work,total:o.work,queuedAt:o.queuedAt,sequence:a};return x.set(o.jobId,l),$.delete(t.id),k.set(t.id,o.jobId),O+=1,R+=o.work,r(),function(t,r,o){let i=n(r);e.onQueued?.(t,i),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:t.id,datum:t.datum,x:t.x,y:t.y,regionId:c,work:r.total,jobId:r.jobId,visitId:r.visitId,visit:r.visit,queuedAt:r.queuedAt,queueDepth:x.size})}(t,l,i),l}function i(e){if(x.size>=m||0===b.size)return;let t=Array.from(b.values()).sort((e,t)=>e.sequence-t.sequence);for(let r of t){if(x.size>=m)break;let t=v.get(r.jobId);t&&w.has(r.jobId)?(b.delete(r.jobId),$.delete(r.bodyId),o(t,r,e,r.sequence)):b.delete(r.jobId)}}function a(){let e=0;for(let t of x.values())e+=t.remaining;return e}function l(){D=Math.max(D,x.size),V=Math.max(V,a())}function s(){let e=F-p,t=Math.max(0,Math.min(p,F-(E??F))),r=0,n=0,o=0,i=0,a=0;for(let t of A){if(e>t.end)continue;r+=t.arrivals,n+=t.arrivalWork,o+=t.completions,i+=t.completedWork;let l=t.end-t.start;a+=l>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/l):t.processedWork}let l=t>0?n/t:0;return{seconds:t,arrivals:r,arrivalWork:n,completions:o,completedWork:i,processedWork:a,arrivalsPerSecond:t>0?r/t:0,throughputPerSecond:t>0?o/t:0,utilization:t>0&&u>0?Math.max(0,Math.min(1,a/(u*t))):0,pressure:u>0?l/u:0}}let c=e.regionId,u=Math.max(0,e.unitsPerSecond),d=e.queueLayout??"lane",h=e.queueSlotSpacing??14,f=e.queueStiffness??.35,m=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,p=Math.max(.25,e.metricWindowSeconds??30),g=Math.max(1/60,e.snapshotIntervalSeconds??.25),y=e.releaseImpulse??{x:90,y:0},x=new Map,b=new Map,w=new Map,M=new Map,v=new Map,k=new Map,$=new Map,A=[],S=0,I=new Map,C=new Map,N=0,z=0,F=0,E=null,j=0,O=0,R=0,W=0,T=0,L=0,P=0,q=0,D=0,V=0,B=0,H=0,Y=-1,G=!1;return{id:e.id??"capacity-queue:"+c,continuous:!1!==e.continuous,tick:a=>{let s=a.controls.readBodies(),d=new Map,h=new Map;for(let r of s){if(d.set(r.id,r),!t(r.id,a.getRegionState)||!Uo(r,e.bodyFilter))continue;let n=yn(r,e.jobKey),o=h.get(n)??[];o.push(r),h.set(n,o)}let f=Number.isFinite(a.dt)?Math.max(0,a.dt):0;if(!G){let e=Number.isFinite(a.elapsed)?Math.max(0,a.elapsed):f;F=Math.max(0,e-f),G=!0}let O=F,R=O+f;F=R,E=null==E?O:Math.min(E,O);let D={start:O,end:R,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},V=new Map;for(let[e,t]of h){let r=w.get(e)?.bodyId,n=t.find(e=>e.id===r)??t[0];V.set(e,n),v.set(e,n)}for(let[t,o]of w){if(V.has(t))continue;let i=x.get(t),l=d.get(o.bodyId)??v.get(t);if(i){x.delete(t),k.delete(i.bodyId),P+=1,q+=i.remaining,r();let s={...n(i),abandonedAt:F,remainingWork:i.remaining,queueSeconds:Math.max(0,F-i.queuedAt)};l&&e.onAbandoned?.(l,s),a.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:l?.datum,x:l?.x,y:l?.y,regionId:c,work:i.total,remainingWork:i.remaining,jobId:t,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,abandonedAt:F,queueSeconds:s.queueSeconds,queueDepth:x.size})}b.delete(t),$.delete(o.bodyId),w.delete(t),v.delete(t)}for(let[t,n]of V){if(w.has(t))continue;let i=(M.get(t)??0)+1;M.set(t,i);let l=gn(n,e.unitAccessor),s={bodyId:n.id,jobId:t,visitId:`${c}:${t}:${i}`,visit:i,regionId:c,work:l,queuedAt:F};w.set(t,s),j+=1,D.arrivals+=1,D.arrivalWork+=l;let u=S++;if(m>x.size)o(n,s,a,u);else{let o={...s,blockedAt:F,sequence:u};b.set(t,o),$.set(n.id,t),L+=1,r(),e.onBlocked?.(n,o),a.controls.recordObservation({type:"physics-capacity-blocked",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:c,work:l,jobId:t,visitId:s.visitId,visit:i,queuedAt:F,blockedAt:F,queueDepth:x.size,blockedDepth:b.size})}}i(a),l();let H=Array.from(x.values()).sort((e,t)=>e.sequence-t.sequence),_=u*f;for(let t of H){if(0>=_)break;let o=Math.min(t.remaining,_);if(t.remaining-=o,_-=o,W+=o,D.processedWork+=o,t.remaining>1e-6)continue;x.delete(t.jobId),k.delete(t.bodyId),z+=1,T+=t.total,D.completions+=1,D.completedWork+=t.total;let i=Math.max(0,F-t.queuedAt);B+=i,r();let l=d.get(t.bodyId);if(!l)continue;a.controls.applyImpulse(t.bodyId,y.x??0,y.y??0);let s={...n(t),completedAt:F,queueSeconds:i};e.onProcessed?.(l,s),a.controls.recordObservation({type:"physics-capacity-processed",bodyId:t.bodyId,datum:l.datum,x:l.x,y:l.y,regionId:c,work:t.total,jobId:t.jobId,visitId:t.visitId,visit:t.visit,queuedAt:t.queuedAt,completedAt:F,queueSeconds:i,queueDepth:x.size})}i(a),l(),function(){let e=Array.from(x.values()).sort((e,t)=>e.sequence-t.sequence);I=new Map(e.map((e,t)=>[e.bodyId,t]));let t=Array.from(b.values()).sort((e,t)=>e.sequence-t.sequence);C=new Map(t.map((e,t)=>[e.bodyId,t])),N=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&A.push(e);let t=F-p;for(;A.length>0&&t>A[0].end;)A.shift()}(D);let X=Math.floor(F/g);X!==Y&&(Y=X,r())},getSnapshot:()=>{let e=a(),t=function(){let e=0;for(let t of b.values())e+=t.work;return e}(),r=x.size,n=Array.from(x.values()).map(e=>Math.max(0,F-e.queuedAt)).sort((e,t)=>e-t),o=n.reduce((e,t)=>e+t,0);return{regionId:c,queueDepth:r,processedCount:z,unitsPerSecond:u,remainingWork:e,meanRemainingWork:r>0?e/r:0,waitingWork:e+t,blockedDepth:b.size,blockedWork:t,arrivalCount:j,admittedCount:O,admittedWork:R,processedWork:W,completedWork:T,blockedCount:L,abandonedCount:P,abandonedWork:q,peakQueueDepth:D,peakRemainingWork:V,queueAge:{count:n.length,meanSeconds:n.length>0?o/n.length:0,p50Seconds:xn(n,.5),p95Seconds:xn(n,.95),oldestSeconds:n.at(-1)??0},meanCompletedQueueSeconds:z>0?B/z:0,window:s(),simulatedAt:F,metricRevision:H}},bodyForce:e=>{if("none"===d)return null;let t=k.get(e.body.id),r=$.get(e.body.id),n=t?x.get(t):void 0,o=r?b.get(r):void 0;if(!n&&!o)return null;let i=n?I.get(e.body.id):C.get(e.body.id);if(null==i)return null;let a,l=e.regions;if(l)for(let e=0;l.length>e;e+=1)if(l[e].id===c){let t=l[e].shape;t&&"aabb"===t.type&&(a=t);break}return a?{x:((o?a.x-.44*a.width:a.x-.22*a.width-i*(.15*h))-e.body.x)*f,y:(a.y-(i-((o?b.size:N)-1)/2)*h/Math.max(1,Math.sqrt(o?b.size:N))-e.body.y)*f*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function wn(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Mn(e){if(!e?.length)return null;let t=e.slice(),r=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:r,onTick:(e,r,n)=>{let o={result:e,controls:r,dt:n.dt,elapsed:n.elapsed,getRegionState:n.getRegionState};for(let e of t)e.tick(o)},bodyForce:e=>{let r=null;for(let n of t)n.bodyForce&&(r=wn(r,n.bodyForce(e)));return r}}}function vn(e){let t=new Set,r=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:n=>{let o=n.controls.readBodies();for(let i of o)n.getRegionState(i.id)?.activeRegionIds.includes(e.fromRegionId)?t.has(i.id)||(t.add(i.id),n.controls.applyImpulse(i.id,r.x??0,r.y??0),e.onPortal?.(i)):t.delete(i.id)}}}function kn(e){let t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),r=new Map(t.map(e=>[e.bodyId,e])),n=new Map,o=new Map,i=e.assignmentForce??.45,a=e.returnForce??.35,l=e.caseAttraction??.08,s=e.assignmentOffset??{x:0,y:0},c=new Map,u=0,d=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{let r=n.get(e);if(r)return r;let i=t.find(e=>!o.has(e.id));if(!i)return null;let a={resourceId:i.id,resourceBodyId:i.bodyId,caseBodyId:e,assignedAt:u};return n.set(e,a),o.set(i.id,a),d+=1,a},release:e=>{let t=n.get(e);return!!t&&(n.delete(e),o.delete(t.resourceId),d+=1,!0)},getAssignment:e=>n.get(e),tick:e=>{u=Math.max(u,e.elapsed),c=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(let[e,t]of n)c.has(e)&&c.has(t.resourceBodyId)||(n.delete(e),o.delete(t.resourceId),d+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(n.values()),simulatedAt:u,metricRevision:d}),bodyForce:e=>{let t=r.get(e.body.id);if(t){let r=o.get(t.id),n=r?c.get(r.caseBodyId):void 0,l=r?i:a;return{x:((n?n.x+(s.x??0):t.home.x)-e.body.x)*l,y:((n?n.y+(s.y??0):t.home.y)-e.body.y)*l}}let u=n.get(e.body.id);if(!u||0>=l)return null;let d=c.get(u.resourceBodyId);return d?{x:(d.x-e.body.x)*l,y:(d.y-e.body.y)*l}:null}}}function $n(e,t){let r="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):Fi(e.datum,t.deadlineAccessor)??Fi(e,t.deadlineAccessor);return Number.isFinite(Number(r))?Math.max(0,Number(r)):0}function An(e){function t(t){n.set(t.bodyId,t),i+=1,e.onStateChange?.({...t})}function r(e){let r=n.get(e);return!(!r||null!=r.completedAt||(t({...r,completedAt:o,state:"unhappy"===r.state?"resolved-unhappy":"resolved"}),0))}let n=new Map,o=0,i=0;return{id:e.id??"service-level",continuous:!0,protect:e=>{let r=n.get(e);return!(!r||null!=r.completedAt||"unhappy"===r.state||(t({...r,state:"protected",protectedAt:o}),0))},complete:r,getCase:e=>n.get(e),tick:i=>{o=Math.max(o,i.elapsed);for(let a of i.controls.readBodies()){if(!Uo(a,e.bodyFilter))continue;if(!n.has(a.id)){let r=$n(a,e);t({bodyId:a.id,openedAt:o,deadlineAt:o+r,state:"waiting"})}let l=n.get(a.id);l&&null==l.completedAt&&(e.completionRegionId&&i.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?r(a.id):"waiting"===l.state&&o>=l.deadlineAt&&t({...l,state:"unhappy"}))}},getSnapshot:()=>{let e=Array.from(n.values()),t=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:t("waiting"),protected:t("protected"),unhappy:t("unhappy"),resolved:t("resolved"),resolvedUnhappy:t("resolved-unhappy"),simulatedAt:o,metricRevision:i}}}}function Sn(e){let t=new Set,r=0,n=0,o=0,i=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:a=>{r=Math.max(r,a.elapsed);let l=i;var s;s=r,i=e.isOpen?e.isOpen(s):null!=e.opensAt&&s>=e.opensAt;let c=a.controls.readBodies(),u=new Map(c.map(e=>[e.id,e]));for(let r of c)!a.getRegionState(r.id)?.activeRegionIds.includes(e.regionId)||!Uo(r,e.bodyFilter)||!i&&!t.has(r.id)&&(t.add(r.id),o+=1,e.onHeld?.(r));if(i&&!l){for(let r of t){let t=u.get(r);t&&(a.controls.applyImpulse(r,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),n+=1,e.onReleased?.(t))}t.clear(),o+=1}for(let e of t)u.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:i,blocked:t.size,released:n,simulatedAt:r,metricRevision:o}),bodyForce:r=>{if(i||!t.has(r.body.id))return null;let n=r.regions?.find(t=>t.id===e.regionId)?.shape;if(!n||"aabb"!==n.type)return{x:.8*-r.body.vx,y:.8*-r.body.vy};let o=e.holdForce??.4;return{x:(n.x-r.body.x)*o-.45*r.body.vx,y:(n.y-r.body.y)*o-.45*r.body.vy}}}}function In(e){let[t,r]=e.size,n=e.flow??Cl,o=null==(M=e.padding)?{top:Nl,right:Nl,bottom:Nl,left:Nl}:"number"==typeof M?{top:M,right:M,bottom:M,left:M}:{top:M.top??0,right:M.right??0,bottom:M.bottom??0,left:M.left??0},i=Math.max(.05,Math.min(1,e.channelRatio??jl)),a={x:o.left,y:o.top,width:Math.max(1,t-o.left-o.right),height:Math.max(1,r-o.top-o.bottom)},l="down"===n?a.height:a.width,s=l*Math.max(0,e.chargeExtent??zl),c=l*Math.max(0,e.projectionExtent??El),u=l*Math.max(0,e.destinationExtent??Fl),d=Math.max(0,l-s-u-c),h=function(e){return"number"==typeof e?Array.from({length:Math.max(1,Math.round(e))},(e,t)=>({id:"bin-"+t,label:t+""})):0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??t+""}))}(e.destinations),f=("down"===n?a.width:a.height)/h.length,m="down"===n?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),p=m(0,s),g=m(s,d),y=s+d,x=m(y,u),b=m(y+u,c),w=h.map((e,t)=>{let r=t*f,o=f*i,l=(f-o)/2;return"down"===n?{id:e.id,label:e.label,order:t,x:a.x+r+l,y:x.y,width:o,height:x.height,centerX:a.x+(t+.5)*f,centerY:x.y+x.height/2}:{id:e.id,label:e.label,order:t,x:x.x,y:a.y+r+l,width:x.width,height:o,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*f}});var M;return{width:t,height:r,flow:n,charge:p,apparatus:g,destinations:w,projection:b}}function Cn(e,t){return e.destinations.find(e=>e.id===t)}function Nn(e,t,r){let{charge:n,flow:o}=e,i=Math.max(1,r),a=(t%i+.5)/i;return"down"===o?{x:n.x+n.width*a,y:n.y+n.height/2}:{x:n.x+n.width/2,y:n.y+n.height*a}}function zn(e,t={}){let r=t.thickness??4,n=t.idPrefix??"stage",{destinations:o,flow:i,width:a,height:l}=e,s=[];if(o.length>0){let t=o[0];if("down"===i){let i=t.y+t.height;s.push({id:n+"-floor",shape:{type:"segment",x1:e.charge.x,y1:i,x2:e.charge.x+e.charge.width,y2:i,thickness:r}});for(let e=1;o.length>e;e+=1){let a=o[e].centerX-(o[e].centerX-o[e-1].centerX)/2;s.push({id:`${n}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:i,thickness:r}})}}else{let i=t.x+t.width;s.push({id:n+"-floor",shape:{type:"segment",x1:i,y1:e.charge.y,x2:i,y2:e.charge.y+e.charge.height,thickness:r}});for(let e=1;o.length>e;e+=1){let a=o[e].centerY-(o[e].centerY-o[e-1].centerY)/2;s.push({id:`${n}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:i,y2:a,thickness:r}})}}}return!1!==t.walls&&s.push({id:n+"-wall-left",shape:{type:"segment",x1:1,y1:0,x2:1,y2:l,thickness:r}},{id:n+"-wall-right",shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:l,thickness:r}}),s}function Fn(e,t={}){return`${t.charge??"bodies"} enter at the ${"down"===e.flow?"top":"left"}, travel ${"down"===e.flow?"downward":"left to right"} through ${t.apparatus??"the apparatus"}, and come to rest in ${e.destinations.length} ${t.destination??"destinations"}: ${e.destinations.map(e=>e.label).join(", ")}.`}function En(e){let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function jn(e,t,r,n){let o="function"==typeof e?e(t,r):e;return Number.isFinite(o)?Number(o):n}function On(e,t,r){return En(e[t])??r}function Rn(e,t){return"number"==typeof e?e:e?.[t]??0}function Wn(e){let{band:t,idPrefix:r,plot:n,projection:o}=e,{includeBoundaryWalls:i=!0,includeInteriorWalls:a=!0,wallThickness:l=4}=t,s=function(e){let t=e.bandwidth??e.scale.bandwidth?.()??0,r=new Set;for(let n of e.values){let o=e.scale(n);Number.isFinite(o)&&(r.add(Number(o)),r.add(Number(o)+t))}return Array.from(r).sort((e,t)=>e-t)}(t);if(2>s.length)return[];let c=i?s.length-1:s.length-2,u=[];for(let e=i?0:1;c>=e;e+=1){if(!a&&e>0&&s.length-1>e)continue;let t=s[e];u.push({id:`${r}-wall-${e}`,shape:"x"===o?{type:"aabb",x:t,y:n.y+n.height/2,width:l,height:n.height}:{type:"aabb",x:n.x+n.width/2,y:t,width:n.width,height:l}})}return u}function Tn(e){let{plot:t,idPrefix:r="physics-scale",bounds:n={},xBins:o,xBands:i,yBands:a}=e,l=[];if(!1!==n&&l.push(...zo(t,{idPrefix:r,...n})),o){let{idPrefix:e,yTop:n,yBottom:i,...a}=o;l.push(...Fo({...a,idPrefix:e??r+"-xbin",yTop:n??t.y,yBottom:i??t.y+t.height}))}return i&&l.push(...Wn({band:i,idPrefix:i.idPrefix??r+"-xband",plot:t,projection:"x"})),a&&l.push(...Wn({band:a,idPrefix:a.idPrefix??r+"-yband",plot:t,projection:"y"})),l}function Ln(e){let{plot:t,rows:r,columns:n=r+1,pegRadius:o=3,idPrefix:i="galton-peg",yStart:a=t.y+.18*t.height,yEnd:l=t.y+.58*t.height,stagger:s=!0,restitution:c=.2,friction:u=.04}=e,d=Math.max(0,Math.floor(r)),h=Math.max(1,Math.floor(n));if(0===d)return[];let f=d>1?(l-a)/(d-1):0,m=t.width/h,p=[];for(let e=0;d>e;e+=1){let r=s&&e%2==1?m/2:0;for(let n=0;h>n;n+=1){let l=t.x+m*(n+.5)+r;t.x+o>l||l>t.x+t.width-o||p.push({id:`${i}-${e}-${n}`,shape:{type:"aabb",x:l,y:a+e*f,width:2*o,height:2*o},restitution:c,friction:u})}}return p}function Pn(e,t={}){let{idPrefix:r="physics-token",radius:n=5,shape:o,mass:i,vx:a,vy:l,spawnAt:s,seed:c=1,jitter:u,datum:d}=t,h=ei(c),f=Rn(u,"x"),m=Rn(u,"y");return e.map((e,c)=>{let u=jn(t.x,e,c,On(e,"x",0)),p=jn(t.y,e,c,On(e,"y",0)),g=jn(n,e,c,5),y="function"==typeof o?o(e,c):o??{type:"circle",radius:g};return{id:`${r}-${e.index??c}`,x:u+(h()-.5)*f,y:p+(h()-.5)*m,vx:jn(a,e,c,0),vy:jn(l,e,c,0),mass:jn(i,e,c,1),spawnAt:jn(s,e,c,void 0),shape:y,datum:d?d(e,c):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;let{spawnAt:t,...r}=e;return r})}function qn(e,t={}){let{idPrefix:r="sediment",collider:n=!0,colliderThickness:o=1,restitution:i=.05,friction:a=.2,...l}=t,s=vi(e,l),c=n?s.filter(e=>e.height>0).map(e=>({id:`${r}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+o/2,width:e.width,height:o},restitution:i,friction:a})):[];return{columns:s,colliders:c}}function Dn(e,t={}){let{timeAccessor:r="arrivalTime",timeScale:n=1,startAt:o=0,rebase:i=!0,sort:a=!0}=t,l=e.map((e,t)=>({spawn:e,time:function(e,t,r){return En("function"==typeof r?r(e,t):e[r]??e.datum?.[r])}(e,t,r)??e.spawnAt??t})),s=l.length?Math.min(...l.map(e=>e.time)):0;return{initialSpawns:l.map(({spawn:e,time:t})=>({...e,spawnAt:o+(i?t-s:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:o,timeAccessor:"spawnAt",timeScale:n}}}function Vn(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function Bn(e,t,r="group"){let n=Or(e,t),o=e=>"function"==typeof r?r(e):e[r]??0;return e.slice().sort((e,t)=>{let r=o(e),i=o(t);return i>r?-1:r>i?1:(n[t.id]||0)-(n[e.id]||0)}).map(e=>e.id)}function Hn(e,t={}){let r=t.baseline??.62,n=t.inset??.06,o={},i=e.length;return e.forEach((e,t)=>{Vn(o,e,{x:i>1?n+t/(i-1)*(1-2*n):.5,y:r})}),o}function Yn(e,t,r=.55){return`M${e.x},${e.y} Q${(e.x+t.x)/2},${e.y-Math.abs(t.x-e.x)*r} ${t.x},${t.y}`}function Gn(e,t={}){let r=t.radius??.42,n=t.center?.x??.5,o=t.center?.y??.5,i=t.startAngle??0,a={},l=e.length;return e.forEach((e,t)=>{let s=i+t/l*Math.PI*2-Math.PI/2;Vn(a,e,{x:n+Math.cos(s)*r,y:o+Math.sin(s)*r})}),a}function _n(e,t,r={}){let n=(r.order??Bn(e,t,r.groupAccessor??"group")).slice(),o=new Map(n.map((e,t)=>[e,t])),i=new Map;for(let e of t){if(!o.has(e.source)||!o.has(e.target)||e.source===e.target)continue;let t=e.target>e.source?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;i.set(t,(i.get(t)||0)+(e.value??1))}let a=[],l=0;for(let[e,t]of i){let[r,n]=e.split("\0"),i=o.get(r),s=o.get(n);t>l&&(l=t),a.push({row:i,col:s,source:r,target:n,value:t}),a.push({row:s,col:i,source:n,target:r,value:t})}return{order:n,cells:a,size:n.length,maxValue:l}}function Xn(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function Kn(e){if("string"!=typeof e)return;let t=e.trim();return t.length?t:void 0}function Un(e,t){let r=Xn(e.note)?e.note:void 0;return t?Kn(e.mobileText)||Kn(e.shortText)||Kn(e.label)||Kn(r?.mobileText)||Kn(r?.shortText)||Kn(r?.label)||Kn(r?.title):Kn(e.label)||Kn(e.mobileText)||Kn(e.shortText)||Kn(r?.label)||Kn(r?.title)}function Qn(e,t,r){let n=function(e,t,r){if(!r)return;let n="function"==typeof r?r(e,t):e[r];return"number"==typeof n&&Number.isFinite(n)?n:void 0}(e,t,r.priorityAccessor);if(void 0!==n)return n;let o=1e3-t,i=((e.emphasis??"")+"").toLowerCase();("primary"===i||"critical"===i)&&(o+=1e4),"secondary"===i&&(o-=1e3),"high"===e.priority&&(o+=5e3),"low"===e.priority&&(o-=1500),"number"==typeof e.priority&&(o+=100*e.priority);let a=Xn(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(o+=100*a.confidence);let l=Xn(e.lifecycle)?e.lifecycle:void 0,s=((l?.freshness??"")+"").toLowerCase();return("expired"===s||"stale"===s)&&(o-=3e3),o}function Zn(e,t){if(!t)return e;let r=Un(e,!0);return r&&"string"==typeof e.label?{...e,label:r}:e}function Jn(e,t={}){let r=Array.isArray(e)?e.filter(Xn):[],n=t.active??(null==t.width||(t.breakpoint??480)>=t.width),o=t.strategy??"hybrid",i=!1!==t.preferShortText,a=!1!==t.preservePrimary,l=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===o?1:2)),s=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!n||"plot"===o)return{active:n,strategy:o,budget:r.length,visible:i?r.map(e=>Zn(e,i)):r,deferred:[],calloutList:[],hidden:[]};let c=[],u=r.map((e,r)=>({annotation:e,index:r,priority:Qn(e,r,t)})).filter(e=>!!Yo(e.annotation)||(c.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),d=a?u.filter(e=>"primary"===((e.annotation.emphasis??"")+"").toLowerCase()):[],h=new Set(d.map(e=>e.index)),f=u.filter(e=>!h.has(e.index)),m=[...d,...f].slice(0,Math.max(l,s)),p=new Set(m.map(e=>e.index)),g=u.filter(e=>!p.has(e.index)),y=[...c,...m.sort((e,t)=>e.index-t.index).map(e=>Zn(e.annotation,i))],x=g.sort((e,t)=>e.index-t.index).map(e=>e.annotation),b=Math.max(0,t.maxCalloutItems??6),w=g.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,r,n){let o=Un(e,n);if(!o)return null;let i=Kn(e.id)||Kn(e.key)||Kn(e.pointId)||"annotation-"+(t+1),a=Xn(e.provenance)?Kn(e.provenance.source)||Kn(e.provenance.authorKind):void 0;return{id:i,label:o,shortLabel:Kn(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:r,annotation:e}}(e.annotation,e.index,e.priority,i)).filter(e=>!!e).slice(0,b),M=new Set(w.map(e=>e.annotation)),v=x.filter(e=>!M.has(e));return{active:n,strategy:o,budget:l,visible:y,deferred:x,calloutList:w,hidden:v}}function eo(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function to(e,t){let r=!1!==t.keepAxes,n=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:n,bottom:r?44:12,left:r?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:n,bottom:r?42:14,left:r?44:14}}function ro(e,t,r,n={}){let o={...r},i={mode:!1===t.mode?void 0:"mobile",...o,margin:to(e,t),...n},a=Object.fromEntries(Object.entries(o).filter(([,e])=>void 0!==e)),l=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),s=function(e,t){let r=t.targetSize??44,n=[],o=t.standardControls,i=e=>!0===o||"all"===o||o===e||Array.isArray(o)&&o.includes(e);return i("brush")&&n.push("range-inputs","clear-brush"),i("zoom")&&n.push("zoom-buttons","reset-view"),i("legend")&&n.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:r,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:r,...n.length>0&&{alternatives:n}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),c=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:e+"-mobile",description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...l,mobileInteraction:c,mobileSemantics:s}}],mobileInteraction:c,mobileSemantics:s}}function no(e={}){let t=eo(e);return ro("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function oo(e={}){let t=eo(e);return ro("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function io(e={}){return ro("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function ao(e={}){let t=eo(e);return ro("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function lo(e={}){let t=eo(e);return ro("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function so(e={}){return ro("geo",e,{showLegend:e.showLegend??!1})}function co(e={}){return ro("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function uo(e,t={}){switch(e){case"line":return no(t);case"area":return oo(t);case"ordinal":return io(t);case"scatter":return ao(t);case"network":return lo(t);case"geo":return so(t);case"small-multiple":return co(t)}}function ho(e={}){let t=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:e.targetSize??44,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:t,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:t}}import{DEFAULT_AREA_PER_ANNOTATION as fo,DEFAULT_GLYPH_ANCHOR as mo,DEFAULT_GLYPH_VIEWBOX as po,LayoutCache as go,SYMBOL_SEQUENCE as yo,absorbRegion as xo,aggregateRegionCounts as bo,annotationBudget as wo,annotationDensity as Mo,annotationLayout as vo,bandLabel as ko,bodyGroupSpec as $o,boundsOf as Ao,calendarLayout as So,capacitatedRegion as Io,chargeGateRegion as Co,clamp as No,collidersFromPlotBounds as zo,collidersFromXScaleBins as Fo,computeTransitDiagramPositions as Eo,countPairwiseCrossings as jo,createSafeDatum as Oo,datumFromFields as Ro,dimFor as Wo,forceFieldRegion as To,glyphExtent as Lo,glyphFractionClipRect as Po,glyphPlacement as qo,groupBy as Do,groupCompletionRows as Vo,hatchFill as Bo,hullFromBoxes as Ho,isNoteAnnotation as Yo,linearAxis as Go,makeShade as _o,markCallout as Xo,matchesHighlight as Ko,matchesPhysicsBodyFilter as Uo,mean as Qo,membraneRegion as Zo,motifBraidLayout as Jo,mulberry32 as ei,nonNegativeFinite as ti,octilinearRoute as ri,offsetTransitPath as ni,orderByBarycenter as oi,orderExactSmall as ii,packBandsBySilhouette as ai,parallelCoordinatesLayout as li,placeWithMinGap as si,portalRegion as ci,pressureFieldRegion as ui,processChrome as di,processLaneWalls as hi,processStageLayout as fi,processStageRegions as mi,readField as pi,refineByAdjacentSwaps as gi,regionCountsToProjectionRows as yi,resolveAccessor as xi,roundedEnclosure as bi,roundedTransitPath as wi,routeSurfaceRegion as Mi,sedimentHeightfield as vi,shade as ki,signatureKey as $i,stableGlyphId as Ai,symbolExtent as Si,symbolPathString as Ii,symbolRadius as Ci,unwrapDatum as Ni,useCustomLayoutSelection as zi,valueAtPath as Fi,withAlpha as Ei}from"./c-IK3PZHRY.min.js";import"./c-QA3HMQJP.min.js";var ji=e=>{let t=e.config,r=t.rows??10,n=t.columns??10,o=t.gutter??2,i=r*n;if(0>=r||0>=n||0>=i)return{nodes:[]};let{plot:a}=e.dimensions;if(0>=a.width||0>=a.height)return{nodes:[]};let l=(a.width-o*(n-1))/n,s=(a.height-o*(r-1))/r;if(0>=l||0>=s)return{nodes:[]};let c=(null==(f=t.categoryAccessor)?null:"function"==typeof f?f:e=>e[f])??(()=>"_default"),u=function(e){return null==e?null:"function"==typeof e?e:t=>Number(t[e])}(t.valueAccessor)??(()=>1),d=new Map,h=[];var f;for(let t of e.data){let e=c(t)+"",r=Number(u(t)),n=Number.isFinite(r)?Math.max(0,r):0;d.has(e)||h.push(e),d.set(e,(d.get(e)??0)+n)}let m,p=Array.from(d.values()).reduce((e,t)=>e+t,0);if(0>=p)return{nodes:[]};if(t.categoryOrder&&t.categoryOrder.length>0){let e=new Set,r=[];for(let n of t.categoryOrder)d.has(n)&&!e.has(n)&&(e.add(n),r.push(n));m=[...r,...h.filter(t=>!e.has(t))]}else m=h;if(0===m.length)return{nodes:[]};let g=m.map(e=>({cat:e,exact:(d.get(e)??0)/p*i})).map(e=>({...e,count:Math.floor(e.exact)})),y=g.reduce((e,t)=>e+t.count,0),x=g.map((e,t)=>({i:t,rem:e.exact-e.count})).sort((e,t)=>t.rem-e.rem);for(let e=0;i-y>e;e++)g[x[e%x.length].i].count+=1;let b="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",w="string"==typeof t.valueAccessor?t.valueAccessor:"value",M=(e,t,r)=>Oo(n=>{n("category",e),n("value",d.get(e)??0),n("share",(d.get(e)??0)/p),"category"!==b&&n(b,e),"value"!==w&&n(w,d.get(e)??0),n("cells",r),n("_waffleCategory",e),n("_waffleIndex",t)}),v=[],k=0;for(let t of g){let i=e.resolveColor(t.cat);for(let e=0;t.count>e;e++)v.push({type:"rect",x:a.x+k%n*(l+o),y:a.y+(r-1-Math.floor(k/n))*(s+o),w:l,h:s,style:{fill:i,stroke:"none"},datum:M(t.cat,k,t.count),group:t.cat,_transitionKey:`waffle-${t.cat}-${e}`}),k++}return{nodes:v}};import{forceCenter as Oi,forceCollide as Ri,forceLink as Wi,forceManyBody as Ti,forceSimulation as Li,forceX as Pi,forceY as qi}from"d3-force";var Di="#334155",Vi="#f8fafc",Bi="#cbd5e1",Hi={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},Yi={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},Gi={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},_i={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},Xi="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",Ki={viewBox:[18,40],anchor:[.5,1],parts:[{d:Xi,fill:"color",stroke:"color",strokeWidth:1.4}]},Ui={server:Hi,chip:Yi,bolt:Gi,bus:_i,person:Ki},Qi="var(--semiotic-primary, #4e79a7)",Zi="var(--semiotic-border, #d1d5db)",Ji=new Set(yo);import{jsx as ea,jsxs as ta}from"react/jsx-runtime";var ra={resource:32,city:64},na=["#739b58","#83a964","#668d52","#8baa68"],oa={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},ia={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},aa=new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]),la=new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]),sa=e=>{let t=F(e.config.gridSize),r=Math.max(20,e.config.tileWidth??80),n=Math.max(10,e.config.tileHeight??40),o=e.config.terrainColors?.length?e.config.terrainColors:na,i=e.dimensions.width/2,a=(e.dimensions.height-t*n)/2+n/2,l=j(e.points,e.config).map(e=>({...e,x:i+r/2*(e.column-e.row),y:a+(e.column+e.row)*(n/2)}));return{nodes:l.map(t=>{let i=function(e,t){let r=S(e,t),n=function(e){return la.has(e)?e:void 0}("string"==typeof r?r:S(r,"kind"));if(!n)return;if("string"==typeof r)return{kind:n};let o=S(r,"coverage"),i="number"==typeof o&&Number.isFinite(o)?Math.max(0,Math.min(1,o)):void 0,a=I(r,"fill");return{kind:n,...null==i?{}:{coverage:i},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":i?.kind??"land",l=i?.fill??I(e.config.terrainPalette,a)??I(oa,a)??oa.land,s=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:i?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:(c=a,I(ia,c)??ia.land),kind:"terrain",terrainKind:a,terrainCoverage:i?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};var c,u,d,h,f;return{type:"geoarea",pathData:(u=t.x,d=t.y,h=r,f=n,`M${u},${d-f/2}L${u+h/2},${d}L${u},${d+f/2}L${u-h/2},${d}Z`),centroid:[t.x,t.y],bounds:[[t.x-r/2,t.y-n/2],[t.x+r/2,t.y+n/2]],screenArea:r*n/2,style:{fill:i||"urban"===a?l:o[t.terrainIndex%o.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:s,group:t.landmark?.kind??a,interactive:!0}}),overlays:ea(O,{tiles:l,tileWidth:r,tileHeight:n,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??32,citySize:e.config.citySpriteSize??64,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}},ca={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},ua={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};import{jsx as da}from"react/jsx-runtime";var ha=e=>{let t=e.config,r=t.source??"auto",n="areas"===r||"auto"===r&&e.areas.length>0,o=(n?function(e){return e.areas.map((t,r)=>{let n=function(e,t){let r=e.properties&&"object"==typeof e.properties?e.properties:{},n=e.id??r.id??r.name??"area-"+t;return{...r,id:n+""}}(t,r),o=e.scales.geoPath.centroid(t),i=Number.isFinite(o[0])&&Number.isFinite(o[1])?e.scales.invertedPoint(o[0],o[1]):null;return{datum:{...n,gridLongitude:i?.[0],gridLatitude:i?.[1]},x:o[0],y:o[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t}))).filter((e,r)=>!t.filter||t.filter(e.datum,r)),i=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;let r=e.map(e=>({datum:e,x:Number(V(e,t.columnAccessor)),y:Number(V(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return r.length!==e.length?null:r.map(e=>({...e,row:e.y,column:e.x}))}(o.map(e=>e.datum),t),a=n?o:function(e){return e.points.map(t=>{let r=Number(V(t,e.config.longitudeAccessor,["lon","longitude"])),n=Number(V(t,e.config.latitudeAccessor,["lat","latitude"])),o=Number.isFinite(r)&&Number.isFinite(n)?e.scales.projectedPoint(r,n):null;return{datum:t,x:o?.[0]??NaN,y:o?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:o.map(e=>e.datum)}),l=i??D(a,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===l.length)return{nodes:[]};let s=P(l.map(e=>e.row)),c=P(l.map(e=>e.column)),u=Math.max(1,Math.round(s[1]-s[0])+1),d=Math.max(1,Math.round(c[1]-c[0])+1),h=Math.max(0,t.layoutPadding??8),f=Math.max(1,e.dimensions.width-2*h)/d,m=Math.max(1,e.dimensions.height-2*h)/u,p=(e.dimensions.width-f*d)/2,g=(e.dimensions.height-m*u)/2,y=L(t.cellPadding??.12,0,.8),x=Math.max(1,.5*Math.min(f,m)*(1-y)),b=t.sizeAccessor?l.map(e=>Number(V(e.datum,t.sizeAccessor))):[],w=t.sizeDomain??P(b),M=t.sizeRange??[.36,1],v=L(Math.min(M[0],M[1]),.05,1),k=L(Math.max(M[0],M[1]),v,1),$=l.map((r,n)=>{let o={...r.datum,gridRow:r.row,gridColumn:r.column},i=(V(o,t.idAccessor,["id","key","name"])??"grid-"+n)+"",a=(V(o,t.labelAccessor,["abbr","code","label","name","id"])??i)+"",l=Math.max(1,t.maxLabelLength??4),u=a.length>l?a.slice(0,l):a,d=V(o,t.categoryAccessor),h=null==d?void 0:d+"",y=V(o,t.fillAccessor),b=null!=y?y+"":h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",M=t.sizeAccessor?Number(V(o,t.sizeAccessor)):NaN,$=t.sizeAccessor&&Number.isFinite(M)?Math.sqrt(L(q(M,w),0,1)):1,A=x*(v+$*(k-v)),S="function"==typeof t.markStyle?t.markStyle(o,n):t.markStyle;return{datum:o,id:i,label:u,category:h,row:r.row,column:r.column,x:p+(r.column-c[0]+.5)*f,y:g+(r.row-s[0]+.5)*m,radius:A,style:{fill:b,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...S}}}),A=t.shape??"circle";return{nodes:$.map(e=>{return"circle"===A?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===A?H(e.x,e.y,e.radius):(t=e.x,r=e.y,n=e.radius,B([[t-n,r-n],[t+n,r-n],[t+n,r+n],[t-n,r+n]])),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===A?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0};var t,r,n}),overlays:!1===t.showLabels?null:da(Y,{marks:$,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??L(.23*Math.min(f,m),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};import{geoBounds as fa,geoContains as ma}from"d3-geo";import{jsx as pa}from"react/jsx-runtime";var ga=new WeakMap,ya=new WeakMap,xa=new WeakMap,ba=1,wa=e=>{let t=function(e){let t=ga.get(e.areas);t||(t=new Map,ga.set(e.areas,t));let r=function(e){let t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",Z(t.featureFilter),Z(t.dotFilter),ae(e)].join("::")}(e),n=t.get(r);if(n)return n;let o=te(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){let e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(r,o),o}(e),r=e.config,n=r.shape??"circle",o=Math.max(.5,_(r.dotRadius)??t.cellSize*G(r.radiusRatio??.24,.05,.5)),i=r.gridOrigin?.[0]??0,a=r.gridOrigin?.[1]??0;return{nodes:t.dots.map((l,s)=>{let c=i+(l.gridColumn+.5)*t.cellSize,u=a+(l.gridRow+.5)*t.cellSize,d=X(l,r.categoryAccessor),h=X(l,r.fillAccessor),f={fill:null!=h?h+"":null!=d?e.resolveColor(d+""):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof r.markStyle?r.markStyle(l,s):r.markStyle},m=`dot-${l.gridRow}-${l.gridColumn}`;return"circle"===n?{type:"point",x:c,y:u,r:o,style:f,datum:l,interactive:!1,pointId:m,_transitionKey:m}:{type:"geoarea",pathData:"hexagon"===n?ce(c,u,o):se(c,u,o),centroid:[c,u],bounds:[[c-o,u-o],[c+o,u+o]],screenArea:"hexagon"===n?3*Math.sqrt(3)*o*o/2:(2*o)**2,style:f,datum:l,group:l.featureId,interactive:!1}}),overlays:r.showOutline?pa("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,n)=>{let o=e.scales.geoPath(t);return o?pa("path",{d:o,fill:"none",stroke:r.outlineStyle?.stroke??"currentColor",strokeOpacity:r.outlineStyle?.opacity??r.outlineStyle?.fillOpacity??.22,strokeWidth:r.outlineStyle?.strokeWidth??.7,strokeDasharray:r.outlineStyle?.strokeDasharray,strokeLinecap:r.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},U(t,n)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},Ma=e=>{let t=e.config,r=t.nodeWidth??80,n=t.nodeHeight??30,o=t.orientation??"vertical",i=t.edgeCurve??"curved",a=!1!==t.showLabels,l=t.labelAccessor??"id",s="function"==typeof l?l:e=>pi(e,l,e.id??"")+"",c=new Map,u=[],d=[],h=e=>{let t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??r,h:("number"==typeof t.height?t.height:e.height)??n}};for(let r of e.nodes){let{x:n,y:o,w:i,h:l}=h(r);null==n||null==o||(c.set(r.id,{x:n,y:o,w:i,h:l}),u.push({type:"rect",x:n-i/2,y:o-l/2,w:i,h:l,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`,strokeWidth:1.5},datum:r,id:r.id,label:s(r)+""}),a&&d.push({x:n,y:o,text:s(r)+"",anchor:"middle",baseline:"middle",fontSize:11}))}let f=[];for(let t of e.edges){let r="string"==typeof t.target?t.target:t.target.id,n=c.get("string"==typeof t.source?t.source:t.source.id),a=c.get(r);if(!n||!a)continue;let l="vertical"===o?{x:n.x,y:n.y+n.h/2}:{x:n.x+n.w/2,y:n.y},s="vertical"===o?{x:a.x,y:a.y-a.h/2}:{x:a.x-a.w/2,y:a.y};if("line"===i)f.push({type:"line",x1:l.x,y1:l.y,x2:s.x,y2:s.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t});else{let r=(l.y+s.y)/2,n=(l.x+s.x)/2;f.push({type:"curved",pathD:"vertical"===o?`M${l.x},${l.y} C${l.x},${r} ${s.x},${r} ${s.x},${s.y}`:`M${l.x},${l.y} C${n},${l.y} ${n},${s.y} ${s.x},${s.y}`,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t})}}return{sceneNodes:u,sceneEdges:f,labels:d}},va=e=>{let t=e.config,r=t.nodeWidth??100,n=t.nodeHeight??36,o=t.edgeStyle??"polyline",i=!1!==t.showLabels,a=t.labelAccessor??"label",l="function"==typeof a?a:e=>pi(e,a,e.id??"")+"",s=new Map,c=[],u=[],d=e=>{let t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??r,h:("number"==typeof t.height?t.height:e.height)??n}};for(let r of e.nodes){let{x:n,y:o,w:a,h:h}=d(r);null==n||null==o||(s.set(r.id,{x:n,y:o,w:a,h:h}),c.push({type:"rect",x:n-a/2,y:o-h/2,w:a,h:h,style:{fill:t.nodeFill??e.resolveColor(r.id),stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,strokeWidth:1.5},datum:r,id:r.id,label:l(r)+""}),i&&u.push({x:n,y:o,text:l(r)+"",anchor:"middle",baseline:"middle",fontSize:11}))}let h=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`,f=[];for(let t of e.edges){let e="string"==typeof t.target?t.target:t.target.id,r=s.get("string"==typeof t.source?t.source:t.source.id),n=s.get(e);if(!r||!n)continue;let i=t.data??{},a=Array.isArray(i.points)?i.points:t.points;if(a&&a.length>=2)if("smooth"!==o||3>a.length){let e="M"+a.map(e=>`${e.x},${e.y}`).join(" L ");f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else{let e=`M${a[0].x},${a[0].y}`;for(let t=1;a.length-1>t;t++)e+=` Q${a[t].x},${a[t].y} ${(a[t].x+a[t+1].x)/2},${(a[t].y+a[t+1].y)/2}`;let r=a[a.length-1];e+=` T${r.x},${r.y}`,f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else f.push({type:"line",x1:r.x,y1:r.y,x2:n.x,y2:n.y,style:{stroke:h,strokeWidth:1},datum:t})}return{sceneNodes:c,sceneEdges:f,labels:u}};import{createElement as ka}from"react";var $a=e=>{let t=e.config??{},r=t.mode??"primary",n=t.dimOpacity??.14,o=(t,r=e.selection)=>r?.isActive&&!r.predicate(t)?n:1,i=e.nodes.map(e=>({id:e.id,data:Ni(e),wrapper:e})).sort((e,t)=>e.id.localeCompare(t.id)),a=e.edges.map(e=>({source:de(e.source),target:de(e.target),data:Ni(e),wrapper:e})).sort((e,t)=>e.source.localeCompare(t.source)||e.target.localeCompare(t.target)),l=Eo(i,a,e.dimensions.plot,t),s="source-rooted"===t.lineMode?function(e,t,r,n){let o=new Set(e.map(e=>e.id)),i=new Map(e.map(e=>[e.id,0])),a=new Map(e.map(e=>[e.id,[]]));for(let e of t)!o.has(e.source)||!o.has(e.target)||(i.set(e.target,(i.get(e.target)??0)+1),a.get(e.source)?.push(e));let l=e.filter(e=>0===(i.get(e.id)??0)),s=new Map,c=new Map(e.map(e=>[e.id,new Map]));for(let e of l){let t={id:e.id,label:ue(e,r)+"",color:fe(e,r,n)},o=new Set,i=[e.id];for(;i.length>0;){let e=i.shift();if(!o.has(e)){o.add(e),c.get(e)?.set(t.id,t);for(let r of a.get(e)??[]){let e=s.get(r);e||(e=new Map,s.set(r,e)),e.set(t.id,t),o.has(r.target)||i.push(r.target)}}}}let u=e=>[...e].sort((e,t)=>e.id.localeCompare(t.id));return{byEdge:new Map(t.map(e=>[e,u(s.get(e)?.values()??[])])),byNode:new Map(e.map(e=>[e.id,u(c.get(e.id)?.values()??[])]))}}(i,a,t,e.resolveColor):void 0,c=function(e,t,r){let n=new Map;for(let o of e){let e=o.target>o.source?`${o.source}\0${o.target}`:`${o.target}\0${o.source}`,i=n.get(e);i||(i={key:e,source:o.source,target:o.target,lines:new Map},n.set(e,i));let a=o.data.lineOrder;Array.isArray(a)&&(i.authoredOrder=a.map(String));let l=r?.byEdge.get(o)??he(o,t);for(let e of l)i.lines.has(e.id)||i.lines.set(e.id,{descriptor:e,edge:o})}return[...n.values()].sort((e,t)=>e.key.localeCompare(t.key))}(a,t,s),u=new Map(i.map(e=>[e.id,new Set])),d=new Map;if(s)for(let[e,t]of s.byNode)for(let r of t)u.get(e)?.add(r.id),r.color&&d.set(r.id,r.color);let h=Math.max(1,t.lineWidth??("primary"===r?6:"compact"===r?3.5:2)),f=Math.max(0,t.lineGap??("primary"===r?2:"compact"===r?1:.5)),m=new Map,p=[];for(let r of c){let n=l.positions.get(r.source),i=l.positions.get(r.target);if(!n||!i)continue;let a=ge(r,t),s=(a.length-1)/2*(h+f)+h/2;for(let e of[r.source,r.target])m.set(e,Math.max(m.get(e)??0,s));a.forEach((s,c)=>{u.get(r.source)?.add(s.descriptor.id),u.get(r.target)?.add(s.descriptor.id);let m=ye(s.edge,l,t,s.edge.source!==r.source),g=m?[n,...m,i]:ri(n,i),y=ni(g,(c-(a.length-1)/2)*(h+f)),x=xe(s.edge,s.descriptor),b=me(s.descriptor,s.edge,t,e.resolveColor);d.has(s.descriptor.id)||d.set(s.descriptor.id,b),p.push({type:"curved",id:`${r.key}:${s.descriptor.id}`,label:`${s.descriptor.label??s.descriptor.id}: ${s.edge.source} to ${s.edge.target}`,pathD:wi(y,t.cornerRadius??10),style:{fill:"none",stroke:b,strokeWidth:h,strokeLinecap:"round",opacity:o(x)},datum:x,accessibleDatum:x,accessibility:{label:`${s.descriptor.label??s.descriptor.id}, ${s.edge.source} to ${s.edge.target}`,tableFields:{line:s.descriptor.label??s.descriptor.id,source:s.edge.source,target:s.edge.target}}})})}let g=new Map,y=[],x=[],b=e=>(ue(e,t)||e.id)+"";if("minimap"===r){let r=new Map;for(let e of i){let t=l.positions.get(e.id);if(!t)continue;let n=`${t.x}\0${t.y}`,o=r.get(n);o||(o={x:t.x,y:t.y,nodes:[],lineIds:new Set,bundleRadius:0},r.set(n,o)),o.nodes.push(e);for(let t of u.get(e.id)??[])o.lineIds.add(t);o.bundleRadius=Math.max(o.bundleRadius,m.get(e.id)??0)}let n=[...r.values()].sort((e,t)=>e.x-t.x||e.y-t.y||e.nodes[0].id.localeCompare(t.nodes[0].id));for(let r of n){let n=pe(r.lineIds,t),i=n.length>1||r.nodes.length>1||r.nodes.some(e=>!0===e.data.interchange||!0===e.data.transfer),a=i?t.interchangeRadius??Math.max(5,r.bundleRadius):t.stationRadius??Math.max(3.5,r.bundleRadius);for(let e of r.nodes)g.set(e.id,a);let l=r.nodes.map(b).join(" / "),s=r.nodes.map(e=>e.id).join("--"),c=1===r.nodes.length?r.nodes[0].data:Oo(e=>{e("id",s),e("label",l),e("stationIds",r.nodes.map(e=>e.id)),e("stations",r.nodes.map(e=>e.data)),e("lineIds",n),e("interchange",i)}),u={label:`${l}${i?", interchange":""}`,tableFields:{station:l,lines:n.join(", ")}};n.length>1?(n.forEach((t,i)=>{let l={type:"arc",cx:r.x,cy:r.y,innerR:0,outerR:a,startAngle:-Math.PI/2+i/n.length*Math.PI*2,endAngle:-Math.PI/2+(i+1)/n.length*Math.PI*2,style:{fill:d.get(t)??e.resolveColor(t),stroke:"none",opacity:o(c)},datum:null,id:`${s}:${t}`};y.push(l)}),y.push({type:"circle",cx:r.x,cy:r.y,r:a,style:{fill:"transparent",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:o(c)},datum:c,accessibleDatum:c,accessibility:u,id:s,label:l})):y.push({type:"circle",cx:r.x,cy:r.y,r:a,style:{fill:(n[0]&&d.get(n[0]))??t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:o(c)},datum:c,accessibleDatum:c,accessibility:u,id:s,label:l})}}else for(let e of i){let n=l.positions.get(e.id);if(!n)continue;let i=pe(u.get(e.id)??[],t),a=i.length>1||!0===e.data.interchange||!0===e.data.transfer,s=a?t.interchangeRadius??Math.max("primary"===r?7:5,m.get(e.id)??0):t.stationRadius??("primary"===r?4:2.75);g.set(e.id,s);let c=b(e);if(y.push({type:"circle",cx:n.x,cy:n.y,r:s,style:null!=t.renderStation?{fill:"transparent",stroke:"transparent"}:{fill:t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:a?"primary"===r?3:2:1.5,opacity:o(e.data)},datum:e.data,accessibleDatum:e.data,accessibility:{label:`${c}${a?", interchange":""}`,tableFields:{station:c,lines:i.join(", ")}},id:e.id,label:c}),t.renderStation){let l=t.renderStation({station:e.data,x:n.x,y:n.y,radius:s,lineIds:i,interchange:a,mode:r});null!=l&&x.push(ka("g",{key:e.id,opacity:o(e.data),style:{pointerEvents:"none"}},l))}}let w=x.length>0?ka("g",{className:"transit-diagram-stations"},...x):void 0,M={sceneEdges:p,sceneNodes:y,overlays:w,labels:be(i,l.positions,u,g,e.dimensions.plot,"primary"===r?t:{...t,showLabels:!1})};if(x.length>0||"minimap"===r)return M;let v=(e,t)=>({opacity:o(e.datum,t)});return{...M,restyle:v,restyleEdge:v}};import{jsx as Aa,jsxs as Sa}from"react/jsx-runtime";import{jsx as Ia,jsxs as Ca}from"react/jsx-runtime";var Na={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},za={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"},Fa=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.layerAccessor??"x",o=t.rowAccessor??"y",i=t.partitionAccessor??"partition",a=t.semanticAccessor??"semantic",l=t.labelAccessor??"label",s=t.storesAccessor??"stores",c=t.backEdgeAccessor??"isBackEdge",u=t.edgeTypeAccessor??"edgeType",d={...Na,...t.partitionColors},h={...za,...t.edgeColors},f=t.accentColor??"var(--semiotic-focus, #ffcc33)",m=t.borderColor??"var(--semiotic-border, #555)",p=t.dimOpacity??.14,g=t.edgeOpacity??.5,y=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,w=t.storeChipColor??"var(--semiotic-info, #6a8caf)",M=t.hullGroupAccessor,v=t.layerCount,k=t.maxLayerSize;if(null==v||null==k){let t=0,r=new Map;for(let o of e.nodes){let e=Math.round(Number(pi(o,n,0)));t=Math.max(t,e),r.set(e,(r.get(e)??0)+1)}v=v??t+1,k=k??Math.max(1,...r.values())}let $=r.width/Math.max(1,v),A=r.height/Math.max(1,k),S=Math.min(t.nodeWidth??172,Math.max(8,$-(t.minGapX??26))),I=Math.min(t.nodeHeight??54,Math.max(8,A-(t.minGapY??18))),C=t.lod&&"auto"!==t.lod?t.lod:16>S?"dot":48>S?"icon":108>S?"compact":"full";if("dot"===C){let e=Math.min(S,I,11);S=e,I=e}let N=Math.max(1,r.width-S),z=Math.max(1,r.height-I),F=Math.max(1,k-1),E=e=>r.x+S/2+(v>1?e/(v-1):.5)*N,j=e=>r.y+I/2+(e+F/2)/F*z,O=t.reachableIds?new Set(t.reachableIds):null,R=t.selectedId??null,W=e.selection,T=new Map,L=new Map,P=[],q=null==M?null:new Map,D=[];for(let t of e.nodes){let e=t.id,r=Number(pi(t,n,0)),c=Number(pi(t,o,0)),u=pi(t,i,"processor")+"",h=pi(t,a,"processor")+"",g=pi(t,l,e)+"",y=ve(pi(t,s,[])),x=t.data??t,b=E(r),w=j(c);T.set(e,{cx:b,cy:w});let v=O?O.has(e):null,k=W?.isActive?W.predicate(x):null,$=null!==v?!v:null!==k&&!k;L.set(e,$);let A=null!=R&&e===R,N=$&&!A?p:1,z=Object.prototype.hasOwnProperty.call(d,u)?d[u]:d.unknown;if("dot"===C?P.push({type:"circle",cx:b,cy:w,r:S/2,style:{fill:z,opacity:N,stroke:A?f:"transparent",strokeWidth:A?2:0},datum:t,id:e,label:g}):(P.push({type:"rect",x:b-S/2,y:w-I/2,w:S,h:I,style:{fill:z,opacity:N,stroke:A?f:m,strokeWidth:A?3:1},datum:t,id:e,label:g}),D.push({id:e,cx:b,cy:w,partition:u,semantic:h,label:g,stores:y,opacity:N,selected:A,node:x})),q&&null!=M){let r=pi(t,M,null);if(null!=r){let t=r+"",n=q.get(t)??[];n.push({id:e,x:b-S/2,y:w-I/2,w:S,h:I}),q.set(t,n)}}}let V=[];for(let t of e.edges){let e="string"==typeof t.source?t.source:t.source.id,r="string"==typeof t.target?t.target:t.target.id,n=T.get(e),o=T.get(r);if(!n||!o)continue;let i,a=!!pi(t,c,!1),l=pi(t,u,"internal")+"",s=L.get(e)||L.get(r)?Math.min(g,1.4*p):g,d=a?h.back:Object.prototype.hasOwnProperty.call(h,l)?h[l]:h.internal;if(a){let e=n.cx,t=n.cy+I/2,r=o.cx,a=o.cy+I/2,l=Math.max(48,.28*Math.abs(e-r))+I;i=`M${e},${t} C${e},${t+l} ${r},${a+l} ${r},${a}`}else{let e=n.cx+S/2,t=n.cy,r=o.cx-S/2,a=o.cy,l=(e+r)/2;i=`M${e},${t} C${l},${t} ${l},${a} ${r},${a}`}let f={type:"curved",pathD:i,style:{stroke:d,strokeWidth:a?x:y,fill:"none",opacity:s,...a?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:t};V.push(f)}let B=0===D.length?null:Ia("g",{className:"lineage-dag-glyphs",children:D.map(e=>function(e,t){let{w:r,h:n,lod:o}=t,i="icon"===o?Math.min(r,n):Math.min(n-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",l="icon"===o?0:8+i+8,s=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:i,color:a,node:e.node}):function(e,t,r){let n=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return Ca("g",{children:[Ia("rect",{width:r,height:r,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),Ia("text",{x:r/2,y:r/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*r,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:n})]})}(e.semantic,e.partition,i),c="full"===o,u="icon"!==o,d="full"===o&&t.showChips&&e.stores.length>0;return Ca("g",{transform:`translate(${e.cx-r/2}, ${e.cy-n/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[Ia("g",{transform:`translate(${"icon"===o?(r-i)/2:8}, ${(n-i)/2})`,children:s}),u&&Ia("foreignObject",{x:l,y:c?n/2-12:n/2-9,width:Math.max(8,r-l-8),height:18,style:{pointerEvents:"none"},children:Ia("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===o?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),c&&Ia("text",{x:l,y:n/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),d&&e.stores.map((e,r)=>Ia("rect",{x:l+15*r,y:n-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:Ia("title",{children:e.storeName})},e.storeName+r))]},e.id)}(e,{w:S,h:I,lod:C,partColors:d,chipColor:w,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel}))}),H=q&&q.size>0?function(e,t){let r=Array.from(e.entries()).sort(([e],[t])=>t>e?-1:e>t?1:0);return Aa("g",{className:"lineage-dag-hulls","aria-hidden":"true",style:{pointerEvents:"none"},children:r.map(([e,r])=>{let n=function(e,t){if(0===t||3>e.length)return e;let r=0>e.reduce((t,r,n)=>{let o=e[(n+1)%e.length];return t+r.x*o.y-o.x*r.y},0)?-1:1;return e.map((n,o)=>{let i=e[(o-1+e.length)%e.length],a=e[(o+1)%e.length],l=Math.hypot(n.x-i.x,n.y-i.y)||1,s=Math.hypot(a.x-n.x,a.y-n.y)||1,c=r>0?{x:(n.y-i.y)/l,y:-(n.x-i.x)/l}:{x:-(n.y-i.y)/l,y:(n.x-i.x)/l},u=r>0?{x:(a.y-n.y)/s,y:-(a.x-n.x)/s}:{x:-(a.y-n.y)/s,y:(a.x-n.x)/s},d={x:c.x+u.x,y:c.y+u.y},h=Math.hypot(d.x,d.y);if(1e-9>h)return{x:n.x+u.x*t,y:n.y+u.y*t};let f=d.x/h,m=d.y/h,p=t/Math.max(1e-6,f*u.x+m*u.y);return{x:n.x+f*p,y:n.y+m*p}})}(function(e){let t=e.slice().sort((e,t)=>e.x-t.x||e.y-t.y).filter((e,t,r)=>0===t||e.x!==r[t-1].x||e.y!==r[t-1].y);if(2>=t.length)return t;let r=[];for(let e of t){for(;r.length>=2&&0>=we(r[r.length-2],r[r.length-1],e);)r.pop();r.push(e)}let n=[];for(let e=t.length-1;e>=0;e--){let r=t[e];for(;n.length>=2&&0>=we(n[n.length-2],n[n.length-1],r);)n.pop();n.push(r)}return r.pop(),n.pop(),r.concat(n)}(r.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding),o=function(e,t){if(0===e.length)return"";if(3>e.length||0===t)return e.map((e,t)=>`${0===t?"M":"L"}${Me(e.x)},${Me(e.y)}`).join(" ")+" Z";let r=e.map((r,n)=>{let o=e[(n-1+e.length)%e.length],i=e[(n+1)%e.length],a=Math.hypot(o.x-r.x,o.y-r.y)||1,l=Math.hypot(i.x-r.x,i.y-r.y)||1,s=Math.min(t,a/2,l/2);return{point:r,incoming:{x:r.x+(o.x-r.x)/a*s,y:r.y+(o.y-r.y)/a*s},outgoing:{x:r.x+(i.x-r.x)/l*s,y:r.y+(i.y-r.y)/l*s}}}),n=r[0].outgoing,o=`M${Me(n.x)},${Me(n.y)}`;for(let e=1;r.length>e;e++){let t=r[e];o+=` L${Me(t.incoming.x)},${Me(t.incoming.y)}`,o+=` Q${Me(t.point.x)},${Me(t.point.y)} ${Me(t.outgoing.x)},${Me(t.outgoing.y)}`}let i=r[0];return o+=` L${Me(i.incoming.x)},${Me(i.incoming.y)}`,o+=` Q${Me(i.point.x)},${Me(i.point.y)} ${Me(i.outgoing.x)},${Me(i.outgoing.y)} Z`,o}(n,t.radius),i=Object.prototype.hasOwnProperty.call(t.colors??{},e)?t.colors?.[e]??t.resolveColor(e):t.resolveColor(e),a=r.every(e=>!0===t.dimById.get(e.id)&&e.id!==t.selectedId),l=Math.min(...n.map(e=>e.x)),s=Math.min(...n.map(e=>e.y)),c=t.label?.(e);return Sa("g",{"data-lineage-hull":e,opacity:a?t.dimOpacity:void 0,children:[Aa("path",{className:"lineage-dag-hull",d:o,fill:i,fillOpacity:t.fillOpacity,stroke:i,strokeOpacity:t.strokeOpacity,strokeWidth:1,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"none"}}),c?Aa("text",{className:"lineage-dag-hull-label",x:l+8,y:s+14,fill:i,fillOpacity:Math.max(t.strokeOpacity,.7),fontSize:11,fontWeight:600,style:{pointerEvents:"none"},children:c}):null]},e)})})}(q,{colors:t.hullColors,padding:null==t.hullPadding?16:ti(t.hullPadding),radius:null==t.hullRadius?12:ti(t.hullRadius),fillOpacity:ke(t.hullFillOpacity,.08),strokeOpacity:ke(t.hullStrokeOpacity,.4),label:t.hullLabel,resolveColor:e.resolveColor,dimById:L,selectedId:R,dimOpacity:p}):null;return H?{sceneNodes:P,sceneEdges:V,backgrounds:H,overlays:B}:{sceneNodes:P,sceneEdges:V,overlays:B}};import{jsx as Ea,jsxs as ja}from"react/jsx-runtime";var Oa={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"},Ra=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.direction??"TD",o="LR"===n||"RL"===n,i="BT"===n||"RL"===n,a=t.layerAccessor??"layer",l=t.rowAccessor??"row",s=t.labelAccessor??"label",c=t.shapeAccessor??"shape",u=t.edgeLabelAccessor??"label",d=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",f=t.textColor??"var(--semiotic-text, #e6e6e6)",m=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",p=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};let g=new Map,y=0;for(let t of e.nodes){let e=Math.round(Number(pi(t,a,0)));y=Math.max(y,e);let r=g.get(e)||[];r.push(t),g.set(e,r)}let x=y+1,b=1;for(let e of g.values())e.sort((e,t)=>Number(pi(e,l,0))-Number(pi(t,l,0))),b=Math.max(b,e.length);let w=o?r.width:r.height,M=o?r.height:r.width,v=w/x,k=M/(b+1),$=Math.max(44,Math.min(t.nodeWidth??150,o?v-36:.92*k)),A=Math.max(26,Math.min(t.nodeHeight??46,o?.7*k:.5*v)),S=(o?$:A)/2+6,I=Math.max(1,w-2*S),C=e=>(o?r.x:r.y)+S+(x>1?(i?x-1-e:e)/(x-1)*I:I/2),N=new Map,z=[],F=[];for(let[e,t]of g)t.forEach((n,i)=>{let a=C(e),l=(o?r.y:r.x)+(i+1)/(t.length+1)*M,u=o?a:l,m=o?l:a,g=pi(n,c,"rect")+"",y=pi(n,s,n.id)+"";N.set(n.id,{cx:u,cy:m,shape:g}),z.push({type:"rect",x:u-$/2,y:m-A/2,w:$,h:A,style:{fill:"transparent",stroke:"transparent"},datum:{id:n.id,name:y,type:Oa[g]??"process",shape:g},id:n.id,label:y}),F.push(ja("g",{children:[Ie(g,u,m,$,A,d,"diamond"===g?p:h,1.5),Ea("text",{x:u,y:m,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:f,style:{pointerEvents:"none"},children:Se(y,Math.max(4,Math.floor(($-12)/7)))})]},"n-"+n.id))});let E=[];return e.edges.forEach((e,t)=>{let r="string"==typeof e.target?e.target:e.target.id,n=N.get("string"==typeof e.source?e.source:e.source.id),i=N.get(r);if(!n||!i)return;let a=o?n.cx+$/2:n.cx,l=o?n.cy:n.cy+A/2,s=o?i.cx-$/2:i.cx,c=o?i.cy:i.cy-A/2,d=o?`M${a},${l} C${(a+s)/2},${l} ${(a+s)/2},${c} ${s},${c}`:`M${a},${l} C${a},${(l+c)/2} ${s},${(l+c)/2} ${s},${c}`,p=Math.atan2(c-l,s-a),g=s-9*Math.cos(p),y=c-9*Math.sin(p),x=4.5*-Math.sin(p),b=4.5*Math.cos(p),w=`${s},${c} ${g+x},${y+b} ${g-x},${y-b}`,M=pi(e,u,void 0),v=(a+s)/2,k=(l+c)/2;E.push(ja("g",{children:[Ea("path",{d:d,fill:"none",stroke:m,strokeWidth:1.4}),Ea("polygon",{points:w,fill:m}),"string"==typeof M&&M.length>0&&ja("g",{children:[Ea("rect",{x:v-6.5*M.length/2-4,y:k-9,width:6.5*M.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),Ea("text",{x:v,y:k,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:f,style:{pointerEvents:"none"},children:M})]})]},"e-"+t))}),{sceneNodes:z,overlays:ja("g",{className:"mermaid-dag",children:[E,F]})}};import{jsx as Wa,jsxs as Ta}from"react/jsx-runtime";var La=new go(8),Pa=e=>{let t=e.config||{},r=e.dimensions.plot;if(!e.nodes.length)return{sceneNodes:[]};let n=t.sourceAccessor??"source",o=t.targetAccessor??"target",i=t.labelAccessor??"label",a=t.categoryAccessor??"category",l=t.nodeRadius??4,s=t.cellGap??16,c=t.bandGap??22,u=t.headerHeight??34,d=t.minCellForFull??38,h=t.maxCellSize??120,f=t.minCellSize??12,m=t.fingerprintRounds??3,p=!1!==t.groupByMotif,g=t.sort??"frequency",y=new Map,x=new Map,b=[];for(let t of e.nodes){let e=t.id;null==e||y.has(e)||(b.push(e),y.set(e,t.data??t),x.set(e,pi(t,a,"")+""))}let w=[];for(let t of e.edges){let e=ze(t.source??pi(t,n,void 0)),r=ze(t.target??pi(t,o,void 0));null==e||null==r||w.push({source:e,target:r})}let{outAdj:M,inAdj:v,undirected:k}=Oe(b,w),$=Re(b,M,v,k,m),A=new Map;if(p)for(let e of $){let t=A.get(e.motif);t?t.push(e):A.set(e.motif,[e])}else A.set("all",[...$].sort((e,t)=>t.nodeCount-e.nodeCount));let S=[...A.entries()];S.sort((e,t)=>"size"===g?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===g?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);let I=Ne(b.join(",")+"|"+[...M.entries()].map(([e,t])=>e+">"+[...t].sort().join(".")).join(";")),C=$i([Math.round(r.x),Math.round(r.y),Math.round(r.width),Math.round(r.height),s,c,u,d,h,f,m,p,g,l,S.map(([e,t])=>e+":"+t.length).join(","),I]),N=La.getOrCompute(C,()=>function(e,t){let{plot:r}=t,n=Math.max(40,r.width),{cell:o,cols:i}=(()=>{for(let o=t.maxCellSize;o>=t.minCellSize;o-=2){let i=Math.max(1,Math.floor((n+t.cellGap)/(o+t.cellGap))),a=0;for(let[,r]of e)a+=t.headerHeight+Math.ceil(r.length/i)*(o+t.cellGap)+t.bandGap;if(r.height>=a)return{cell:o,cols:i}}return{cell:t.minCellSize,cols:Math.max(1,Math.floor((n+t.cellGap)/(t.minCellSize+t.cellGap)))}})(),a=[],l=[],s=r.y;for(let[c,u]of e){let e=Math.ceil(u.length/i),d=s,h=d+t.headerHeight,f=o>=t.minCellForFull;u.forEach((e,n)=>{let l=r.x+n%i*(o+t.cellGap),s=h+Math.floor(n/i)*(o+t.cellGap);if(f){let r=Ee(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,{x:l,y:s,width:o,height:o},t.nodeRadius);a.push({component:e,lod:"full",cx:l+o/2,cy:s+o/2,glyphR:0,nodes:r.nodes,edges:r.edges})}else a.push({component:e,lod:"glyph",cx:l+o/2,cy:s+o/2,glyphR:Math.max(2.5,.36*o),nodes:[],edges:[]})});let m=We(u[0],t,{x:r.x,y:d+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});l.push({motif:c,descriptor:je(u[0]),count:u.length,directed:u[0].directed,x:r.x,y:d,width:n,height:t.headerHeight+e*(o+t.cellGap),exemplar:m}),s=h+e*(o+t.cellGap)+t.bandGap}return{cells:a,bands:l}}(S,{plot:r,cellGap:s,bandGap:c,headerHeight:u,minCellForFull:d,maxCellSize:h,minCellSize:f,nodeRadius:l,nodeDatum:y,nodeCategory:x,outAdj:M,inAdj:v})),z=e.theme.semantic||{},F=t.convergeColor??z.info??"#4c78a8",E=t.branchColor??z.warning??"#e8853a",j=t.edgeColor??z.border??"#9aa0aa",O=t.colorMode??"directedness",R={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},W=t=>"motif"===O?e.resolveColor(t.motif):"category"===O||t.directed?F:E,T=[],L=[];for(let t of N.cells){let r=t.component,n=W(r);if("full"===t.lod){for(let e of t.edges)L.push({type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:j,strokeWidth:1,opacity:.5},datum:null});for(let r of t.nodes){let t="category"===O&&r.category?e.resolveColor(r.category):n,o={type:"symbol",cx:r.cx,cy:r.cy,size:Math.PI*r.r*r.r,symbolType:"circle",style:{fill:t,opacity:Wo(r.datum,R)},datum:r.datum,id:r.id,label:pi(r.datum,i,r.id)+""};T.push(o)}}else{let e=Ro({id:`motif-${r.motif}-${t.cx.toFixed(0)}-${t.cy.toFixed(0)}`,motif:r.motif,shape:je(r),nodes:r.nodeCount,edges:r.edgeCount,sinks:r.sinkCount,sources:r.sourceCount,directedness:r.directed?"converging":"branching"}),o={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:r.directed?"circle":"diamond",style:{fill:n,opacity:Wo(e,R),stroke:j,strokeWidth:.75},datum:e,id:e.id+"",label:je(r)};T.push(o)}}return{sceneNodes:T,sceneEdges:L,overlays:function(e,t){let r=[];for(let n of e){let e=n.directed?t.convergeColor:t.branchColor;if(r.push(bi({keyId:"band-"+n.motif,x:n.x-6,y:n.y-4,width:n.width+12,height:n.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})),t.showExemplars&&n.exemplar){let o=n.exemplar;r.push(Ta("g",{style:{pointerEvents:"none"},children:[o.edges.map((e,r)=>Wa("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},"exe-"+r)),o.nodes.map(t=>Wa("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},"exn-"+t.id))]},"ex-"+n.motif))}if(t.showBandLabels){let e=n.x+(t.showExemplars?48:4);r.push(Wa("text",{x:e,y:n.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:n.descriptor},"bl-"+n.motif)),r.push(Wa("text",{x:e,y:n.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${n.count} · ${n.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},"bc-"+n.motif))}}if(t.showLegend){let e=t.plot.x+t.plot.width-168,i=t.plot.y-2;r.push(Ta("g",{style:{pointerEvents:"none"},children:[Wa("circle",{cx:e,cy:i,r:5,fill:t.convergeColor}),Wa("text",{x:e+10,y:i+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),Wa("path",{d:(n=e,o=i+18,`M${n},${o-5} L${n+5},${o} L${n},${o+5} L${n-5},${o} Z`),fill:t.branchColor}),Wa("text",{x:e+10,y:i+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}var n,o;return Wa("g",{className:"net-ensemble-overlays",children:r})}(N.bands,{convergeColor:F,branchColor:E,edgeColor:j,plot:r,showBandLabels:!1!==t.showBandLabels,showExemplars:!1!==t.showExemplars,showLegend:!1!==t.showLegend&&"directedness"===O,textColor:z.text??"var(--semiotic-text, #1a1a1a)",subText:z.textSecondary??"var(--semiotic-text-secondary, #888)"})}};import*as qa from"react";var Da=e=>{let t=e.config??{},r=e.dimensions.plot,n=e.nodes.map((e,t)=>({id:e.id,datum:Te(e),inputIndex:t})),o=new Map(n.map(e=>[e.id,e.inputIndex])),i=new Map((t.order??[]).map((e,t)=>[e+"",t]));if(n.sort((e,t)=>{let r=i.get(e.id),n=i.get(t.id);return null!=r&&null!=n?r-n:null!=r?-1:null!=n?1:(o.get(e.id)??0)-(o.get(t.id)??0)}),0===n.length)return{sceneNodes:[],sceneEdges:[],labels:[]};let a=Math.max(0,t.padding??18),l=Math.max(1,Math.min(r.width,r.height)-2*a),s=Math.min(Math.max(1,t.maxCellSize??120),l/n.length),c=s*n.length,u=r.x+(r.width-c)/2,d=r.y+(r.height-c)/2,h=Math.max(4,Math.min(.76*s,t.nodeSize??.56*s)),f=h/2,m=n.map((e,r)=>{let n="function"==typeof t.labelAccessor?t.labelAccessor(e.datum):pi(e.datum,t.labelAccessor??"label",e.id)+"";return{id:e.id,label:n,datum:e.datum,index:r,cx:u+(r+.5)*s,cy:d+(r+.5)*s}}),p=new Map(m.map(e=>[e.id,e])),g=new Map(m.map(e=>[e.id,e.index])),y=function(e,t,r){let n=new Map;for(let o of e){let e=Le(o.source),i=Le(o.target),a=t.get(e),l=t.get(i);if(null==a||null==l)continue;let s=Te(o),c=Pe("function"==typeof r.valueAccessor?r.valueAccessor(s):pi(s,r.valueAccessor??"value",o.value??1),0);if(0>=c)continue;let u=n.get(e);u||(u=new Map,n.set(e,u));let d=u.get(i);d?(d.value+=c,d.edgeCount+=1,d.memberEdges.push(s)):u.set(i,{key:`${a}-${l}`,source:e,target:i,sourceIndex:a,targetIndex:l,value:c,edgeCount:1,memberEdges:[s],datum:s,width:1,color:""})}let o=[...n.values()].flatMap(e=>[...e.values()]);for(let e of o)e.datum=Oo(t=>{for(let[r,n]of Object.entries(e.memberEdges[0]??{}))t(r,n);t("source",e.source),t("target",e.target),t("value",e.value),t("edgeCount",e.edgeCount),t("internal",e.source===e.target),t("memberEdges",e.memberEdges)});return o}(e.edges,g,t),x=function(e,t,r){let n=new Map,o=(e,t)=>{let r=n.get(e);r?r.push(t):n.set(e,[t])};for(let t of e)o(Be(t.source,t.sourceIndex>t.targetIndex?"out-left":"out-right"),t),o(Be(t.target,t.targetIndex>t.sourceIndex?"in-top":"in-bottom"),t);for(let[e,t]of n){let r=e.startsWith("out-");t.sort((e,t)=>(r?e.targetIndex:e.sourceIndex)-(r?t.targetIndex:t.sourceIndex)||e.key.localeCompare(t.key))}let i=He(t,r),a=null==r.flowScale?1/0:Math.max(0,r.flowScale);if(null==r.flowScale){for(let e of n.values()){let n=e.reduce((e,t)=>e+t.value,0),o=Ye(e.length,t,r);n>0&&(a=Math.min(a,Math.max(.1,i-o*Math.max(0,e.length-1))/n))}Number.isFinite(a)||(a=1)}let l=Math.max(0,r.minFlowWidth??1.25),s=Math.max(l,r.maxFlowWidth??1/0);for(let t of e)t.width=Math.min(s,Math.max(l,t.value*a));let c=1;for(let e of n.values()){let n=e.reduce((e,t)=>e+t.width,0),o=Ye(e.length,t,r);n>0&&(c=Math.min(c,Math.max(.1,i-o*Math.max(0,e.length-1))/n))}if(1>c)for(let t of e)t.width*=c;return n}(y,h,t),b=function(e,t,r,n){let o=new Map;for(let[i,a]of e){let e=i.slice(i.indexOf("\0")+1),l=t.get(e);if(!l)continue;let s=i.startsWith("out-")?l.cy:l.cx,c=Ye(a.length,r,n),u=s-(a.reduce((e,t)=>e+t.width,0)+c*Math.max(0,a.length-1))/2;for(let e of a){let t=u+e.width/2,r=i.startsWith("out-");o.set(`${e.key}:${r?"source":"target"}`,t),u+=e.width+c}}return o}(x,p,h,t),w=e.theme.semantic.info??e.theme.semantic.primary??e.resolveColor("adjacency-flow"),M=e.theme.semantic.text??"var(--semiotic-text, currentColor)",v=e.theme.semantic.surface??"var(--semiotic-bg, white)",k=e.theme.semantic.border??"var(--semiotic-border, currentColor)",$=e.theme.semantic.grid??k,A=e.theme.semantic.primary??e.resolveColor("adjacency-flow-node"),S=t.valueFormat??(e=>Math.round(100*e)/100+""),I=Math.max(0,Math.min(t.cornerRadius??10,.22*s)),C=new Map(m.map(e=>[e.id,0])),N=new Map(m.map(e=>[e.id,0])),z=[],F=[],E=[];for(let r of y){let n=p.get(r.source),o=p.get(r.target);if(!n||!o)continue;C.set(n.id,(C.get(n.id)??0)+r.value),N.set(o.id,(N.get(o.id)??0)+r.value);let i=t.colorMode??"single",a="function"==typeof t.edgeColor?t.edgeColor(r.datum):void 0;r.color=a??("string"==typeof t.edgeColor?t.edgeColor:void 0)??("source"===i?e.resolveColor(r.source):"target"===i?e.resolveColor(r.target):"edge"===i?e.resolveColor(`${r.source}→${r.target}`):w);let l,c,h,m,g,y,x,k=b.get(r.key+":source")??n.cy,$=b.get(r.key+":target")??o.cx;if(r.targetIndex>r.sourceIndex){let e=[n.cx+f,k],t=[$,o.cy-f];l=[e,[t[0],e[1]],t],c=t[0],h=e[1]+.68*(t[1]-e[1]),m=Math.PI/2,g=t[0]-I-4,y=e[1]-r.width/2-3,x="end"}else if(r.sourceIndex>r.targetIndex){let e=[n.cx-f,k],i=[$,o.cy+f];l=[e,[i[0],e[1]],i],c=i[0],h=e[1]+.68*(i[1]-e[1]),m=-Math.PI/2,g=i[0]+I+4,y=e[1]+r.width/2+(t.valueFontSize??10),x="start"}else{let e=u+(n.index+1)*s,t=d+(n.index+1)*s,i=Math.max(2,Math.min(6,.07*s)),a=Math.max(n.cx+f+2,e-i),p=Math.max(n.cy+f+2,t-i),b=[n.cx+f,k],w=[$,o.cy+f];l=[b,[a,b[1]],[a,p],[w[0],p],w],c=(a+w[0])/2,h=p,m=Math.PI,g=a-3,y=p-r.width/2-3,x="end"}let A=De(l,I);if(E.push({type:"curved",id:"adjacency-flow-"+r.key,label:`${n.label} to ${o.label}: ${S(r.value,r.datum)}`,pathD:A,style:{fill:"none",stroke:r.color,strokeWidth:r.width,opacity:.82,cursor:"pointer"},datum:r.datum,accessibleDatum:r.datum,accessibility:{label:`${n.label} to ${o.label}, ${S(r.value,r.datum)}`,tableFields:{source:n.label,target:o.label,value:r.value,edges:r.edgeCount}}}),(t.showValues??!0)&&F.push({x:g,y:y,text:S(r.value,r.datum),anchor:x,fontSize:t.valueFontSize??Math.max(7,Math.min(10,.14*s)),fontWeight:650,fill:M,stroke:v,strokeWidth:3,paintOrder:"stroke"}),t.showArrows??!0){let e=Math.min(Math.max(0,t.arrowSize??14),Math.max(0,r.width-2));if(2>=e)continue;z.push(qa.createElement("path",{key:"arrow-"+r.key,className:"semiotic-adjacency-flow-arrow",d:Ve(c,h,m,Math.max(3,1.08*e),e),fill:t.arrowColor??"var(--semiotic-adjacency-flow-arrow-fill, rgba(255, 255, 255, 0.72))",stroke:"none","data-edge-width":r.width,"data-arrow-width":e,"aria-hidden":!0,focusable:!1,pointerEvents:"none",opacity:1}))}}let j=m.map(r=>{let n=("function"==typeof t.nodeColor?t.nodeColor(r.datum,r.index):void 0)??("string"==typeof t.nodeColor?t.nodeColor:"source"===(t.colorMode??"single")?e.resolveColor(r.id):A);return{type:"rect",id:r.id,label:r.label,x:r.cx-f,y:r.cy-f,w:h,h:h,style:{fill:n,stroke:t.nodeStroke??k,strokeWidth:1.25,cursor:"pointer"},datum:r.datum,accessibleDatum:r.datum,accessibility:{label:`${r.label}, step ${r.index+1}`,tableFields:{step:r.index+1,node:r.label,incoming:N.get(r.id)??0,outgoing:C.get(r.id)??0}}}}),O=Math.max(2,t.maxLabelLength??14),R=m.map(e=>{return{x:e.cx,y:e.cy,text:(r=e.label,n=O,r.length>n?r.slice(0,Math.max(1,n-1))+"…":r),anchor:"middle",baseline:"middle",fontSize:t.labelFontSize??Math.max(6,Math.min(15,.34*h,h/Math.max(1.8,.62*e.label.length))),fontWeight:750,fill:t.nodeTextColor??v};var r,n}),W=null;if(t.showGrid??!0){let e=[];for(let t=0;m.length>=t;t+=1){let r=u+t*s,n=d+t*s;e.push(qa.createElement("line",{key:"grid-v-"+t,x1:r,y1:d,x2:r,y2:d+c,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}),qa.createElement("line",{key:"grid-h-"+t,x1:u,y1:n,x2:u+c,y2:n,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}))}W=qa.createElement(qa.Fragment,null,...e)}return{sceneEdges:E,sceneNodes:j,labels:[...F,...R],backgrounds:W,overlays:qa.createElement(qa.Fragment,null,...z)}};import{jsx as Va,jsxs as Ba}from"react/jsx-runtime";var Ha=new go(12),Ya=e=>{let t=e.config||{},r=e.dimensions.plot,n=t.columnAccessor??"column",o=t.rowAccessor??"row",i=t.sizeAccessor,a=t.colorAccessor,l=t.symbolAccessor,s=t.shadeAccessor,c=t.markerAccessor,u=t.iconAccessor,d=t.defaultSymbol??"circle",[h,f]=t.sizeRange??[2,8],m=t.shadeStrength??.72,p=t.shadeReverse??!1,g=t.rowMode??"banded",y=t.cellSizing??"proportional",x=t.proportionExponent??1,b=t.columnGap??16,w=t.rowGap??12,M=t.packPadding??1,v=t.iterations??12,k=!1!==t.showEnclosures,$=!1!==t.showColumnHeaders,A=!1!==t.showRowLabels,S=$?t.headerHeight??26:0,I=A?t.labelWidth??66:0,C=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,N=r.x+I,z=r.y+S,F=Math.max(1,r.width-I),E=Math.max(1,r.height-S-C),j=[];for(let t of e.nodes){let e=t.data??t;j.push({id:t.id,col:pi(t,n,"—")+"",row:pi(t,o,"—")+"",sizeVal:i?Number(pi(t,i,1)):1,colorKey:a?pi(t,a,"")+"":"",symVal:l?pi(t,l,"")+"":"",shadeVal:s?Qe(pi(t,s,null)):NaN,marker:!!c&&!!pi(t,c,!1),iconVal:u?pi(t,u,"")+"":"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===j.length)return{sceneNodes:[]};let O=1/0,R=-1/0;if(i)for(let e of j)Number.isFinite(e.sizeVal)&&(O>e.sizeVal&&(O=e.sizeVal),e.sizeVal>R&&(R=e.sizeVal));t.sizeDomain&&([O,R]=t.sizeDomain),(!Number.isFinite(O)||!Number.isFinite(R))&&(O=0,R=1);let W=e=>{if(O>=R)return(h+f)/2;let t=Math.sqrt(Ze((e-O)/(R-O),0,1));return h+t*(f-h)},T=1/0,L=-1/0;if(s)for(let e of j)Number.isFinite(e.shadeVal)&&(T>e.shadeVal&&(T=e.shadeVal),e.shadeVal>L&&(L=e.shadeVal));t.shadeDomain&&([T,L]=t.shadeDomain);let P=e=>{if(!s||!Number.isFinite(e)||T>=L)return.5;let t=Ze((e-T)/(L-T),0,1);return p?1-t:t},q=t.colorMap,D=new Map,V=(t,r)=>{let n=D.get(t);if(!n){let r=q&&Object.prototype.hasOwnProperty.call(q,t)&&"string"==typeof q[t]&&q[t]?q[t]:e.resolveColor(t);n=_o(r,m),D.set(t,n)}return n(r)},B=new Map;if(t.symbolMap)for(let[e,r]of Object.entries(t.symbolMap))B.set(e,r);let H=0,Y=t.iconMap,G=e=>u&&Y&&Object.prototype.hasOwnProperty.call(Y,e)?Y[e]??null:null,_=e=>u?"circle":(e=>{if(!l)return d;let t=B.get(e);return t||(t=yo[H%yo.length],H++,B.set(e,t)),t})(e.symVal),X=t.maxAreaFraction??.4,K=0,U=Array(j.length),Q=Array(j.length);for(let e=0;j.length>e;e++){let t=j[e],r=W(t.sizeVal);U[e]=r,t.baseShape=_(t),t.iconShape=G(t.iconVal);let n=Si(t.baseShape,Math.PI*r*r);Q[e]=n,K+=Math.PI*n*n}let Z=X*F*E,J=K>Z?Math.sqrt(Z/K):1;for(let e=0;j.length>e;e++){let t=j[e],r=U[e]*J;t.size=Math.PI*r*r,t.packR=Q[e]*J}let ee=new Map,te=new Map;for(let e of j)ee.set(e.col,(ee.get(e.col)??0)+1),te.set(e.row,(te.get(e.row)??0)+1);let re=t.columnOrder?.filter(e=>ee.has(e))??[...ee.keys()].sort((e,t)=>(ee.get(t)??0)-(ee.get(e)??0)),ne=t.rowOrder?.filter(e=>te.has(e))??[...te.keys()].sort((e,t)=>(te.get(t)??0)-(te.get(e)??0)),oe=$i([Math.round(r.x),Math.round(r.y),Math.round(r.width),Math.round(r.height),S,I,C,g,y,x,b,w,M,v,h,f,O,R,X,re.join(","),ne.join(","),j.length,Je(j)]),ie=Ha.getOrCompute(oe,()=>function(e,t){let r=new Map;for(let t of e){let e=r.get(t.col);e||(e=[],r.set(t.col,e)),e.push(t)}let n=t.columnOrder.filter(e=>r.has(e)),o=Math.max(1,t.innerW-t.columnGap*Math.max(0,n.length-1)),i=t.proportionExponent,a=n.map(e=>Math.pow(r.get(e).length,i)),l=a.reduce((e,t)=>e+t,0)||1,s=e=>"uniform"===t.cellSizing?o/n.length:a[e]/l*o,c=new Map,u=[],d=t.innerX;for(let e=0;n.length>e;e++)u.push({col:n[e],x:d,w:s(e)}),d+=s(e)+t.columnGap;let h=1,f=new Map,m=[],p=(e,t,r,n)=>{let o=f.get(e);o||(o={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,o)),o.minX>t-n&&(o.minX=t-n),t+n>o.maxX&&(o.maxX=t+n),o.minY>r-n&&(o.minY=r-n),r+n>o.maxY&&(o.maxY=r+n)},g=(e,r,n,o,i,a)=>{let l=e.map(e=>({id:e.id,r:e.packR})),s=function(e,t,r,n,o,i,a,l){let s=t+n/2,c=r+o/2,u=new Map,d=e.length;if(0===d)return u;if(1===d)return u.set(e[0].id,{px:s,py:c}),u;let h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(l),f=new Float64Array(d),m=0;for(let t=0;d>t;t++)f[t]=e[t].r+i,f[t]>m&&(m=f[t]);let p=Math.max(1,Math.round(Math.sqrt(d*n/Math.max(1,o)))),g=new Float64Array(d),y=new Float64Array(d),x=n/p,b=o/Math.ceil(d/p);for(let e=0;d>e;e++){let n=e%p,o=Math.floor(e/p);g[e]=t+(n+.3+.4*h())*x,y[e]=r+(o+.3+.4*h())*b}let w=Math.max(0,Math.min(a,14)),M=Math.max(1,2*m),v=new Map,k=Math.max(1,Math.ceil(n/M)+3),$=(e,t)=>(t+1)*k+(e+1);for(let e=0;w>e;e++){v.clear();for(let e=0;d>e;e++){let n=$(Math.floor((g[e]-t)/M),Math.floor((y[e]-r)/M)),o=v.get(n);o?o.push(e):v.set(n,[e])}for(let e=0;d>e;e++){let n=Math.floor((g[e]-t)/M),o=Math.floor((y[e]-r)/M);for(let t=-1;1>=t;t++)for(let r=-1;1>=r;r++){let i=v.get($(n+t,o+r));if(i)for(let t=0;i.length>t;t++){let r=i[t];if(e>=r)continue;let n=g[r]-g[e],o=y[r]-y[e],a=f[e]+f[r],l=n*n+o*o;if(a*a>l)if(l>1e-9){let t=Math.sqrt(l),i=(a-t)/2;n/=t,o/=t,g[e]-=n*i,y[e]-=o*i,g[r]+=n*i,y[r]+=o*i}else{let t=2.39996323*e;g[e]+=Math.cos(t)*f[e],y[e]+=Math.sin(t)*f[e]}}}}for(let e=0;d>e;e++){let i=f[e],a=t+i,l=t+n-i,u=r+i,d=r+o-i;g[e]=l>a?Ze(g[e],a,l):s,y[e]=d>u?Ze(y[e],u,d):c}}for(let t=0;d>t;t++)u.set(e[t].id,{px:g[t],py:y[t]});return u}(l,r,n,o,i,t.packPadding,t.iterations,h++),u=1/0,d=1/0,f=-1/0,m=-1/0;for(let e of l){let t=s.get(e.id);c.set(e.id,{px:t.px,py:t.py}),p(a,t.px,t.py,e.r),u>t.px-e.r&&(u=t.px-e.r),t.px+e.r>f&&(f=t.px+e.r),d>t.py-e.r&&(d=t.py-e.r),t.py+e.r>m&&(m=t.py+e.r)}return Number.isFinite(u)?{x:u-Ga,y:d-Ga,w:f-u+2*Ga,h:m-d+2*Ga}:null};if("banded"===t.rowMode){let o=new Map;for(let t of e)o.set(t.row,(o.get(t.row)??0)+1);let a=t.rowOrder.filter(e=>o.has(e)),l=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),s=a.map(e=>Math.pow(o.get(e),i)),d=s.reduce((e,t)=>e+t,0)||1,h=new Map,m=t.innerY+t.innerH;for(let e=0;a.length>e;e++){let r="uniform"===t.cellSizing?l/a.length:s[e]/d*l,n=m-r;h.set(a[e],{y:n,h:r}),m=n-t.rowGap}n.forEach((e,t)=>{let n=Do(r.get(e),e=>e.row);for(let e of a){let r=n.get(e),o=h.get(e);!r||!o||g(r,u[t].x,o.y,u[t].w,o.h,e)}});let p=[],y=new Map;for(let e of a){let t=h.get(e);y.set(e,t.y+t.h/2);let r=f.get(e);r&&Number.isFinite(r.minX)&&p.push({x:r.minX-Ga,y:r.minY-Ga,w:r.maxX-r.minX+2*Ga,h:r.maxY-r.minY+2*Ga})}return{positions:c,enclosures:p,colBands:u,rowLabelY:y}}let y=new Map;n.forEach((e,n)=>{let o=Do(r.get(e),e=>e.row),a=t.rowOrder.filter(e=>o.has(e)),l=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),s=a.map(e=>Math.pow(o.get(e).length,i)),c=s.reduce((e,t)=>e+t,0)||1,d=t.innerY+t.innerH;a.forEach((e,r)=>{let i="uniform"===t.cellSizing?l/a.length:s[r]/c*l,h=d-i,f=g(o.get(e),u[n].x,h,u[n].w,i,e);if(f){m.push(f);let t=y.get(e)??{sum:0,n:0};t.sum+=f.y+f.h/2,t.n+=1,y.set(e,t)}d=h-t.rowGap})});let x=new Map;for(let[e,t]of y)x.set(e,t.sum/t.n);return{positions:c,enclosures:m,colBands:u,rowLabelY:x}}(j,{columnOrder:re,rowOrder:ne,innerX:N,innerY:z,innerW:F,innerH:E,rowMode:g,cellSizing:y,proportionExponent:x,columnGap:b,rowGap:w,packPadding:M,iterations:v})),ae=e.selection,le=ae?.isActive?ae.predicate:null,se=t.highlight??null,ce=t.dimOpacity??.16,ue=t.markStroke,de=t.markStrokeWidth??0,he=t.markerColor??"#ffffff",fe=t.iconColor??"rgba(255,255,255,0.92)",me=t.iconStrokeWidth??1,pe=t.iconScale??.72,ge=[],ye=[],xe=[];for(let e of j){let t=ie.positions.get(e.id);if(!t)continue;let r=Wo(e.datum,{highlight:se,predicate:le,dimOpacity:ce}),n={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:V(e.colorKey,P(e.shadeVal)),opacity:r,...ue?{stroke:ue,strokeWidth:de}:{}},datum:e.datum,id:e.id,label:e.id+""};if(ge.push(n),e.iconShape){let n=Math.sqrt(e.size/Math.PI)*pe,o=Si(e.iconShape,100);xe.push({x:t.px,y:t.py,size:o>0?n/o*100*(n/o):Math.PI*n*n,shape:e.iconShape,opacity:r})}e.marker&&r>ce+.001&&ye.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}let be=[];if(t.callouts&&t.callouts.length>0){let e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",n=r.y+r.height-(C>0?.45*C:9),o=[];for(let e=0;t.callouts.length>e;e++){let r=t.callouts[e],n=j.find(e=>e.datum[r.field]+""==r.value+"");if(!n)continue;let i=ie.positions.get(n.id);i&&o.push({c:r,ci:e,px:i.px,py:i.py,markR:Math.sqrt(n.size/Math.PI)})}let i=o.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;i.forEach((e,t)=>{a.set(e.ci,N+(t+.5)/i.length*F)});for(let t of o){let o=t.c,i=a.get(t.ci)??t.px,l=n,s=o.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof o.at&&o.at?(i=o.at.x,l=o.at.y):"number"==typeof o.at&&(l=r.y+o.at*r.height),be.push({keyId:"callout-"+t.ci,markX:t.px,markY:t.py,labelX:i,labelY:l,label:o.label,connector:s,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}let we=function(e,t){let r=t.columnLabel??(e=>e),n=t.rowLabel??(e=>e);return Ba("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[t.showEnclosures&&e.enclosures.map((e,r)=>bi({keyId:"enc-"+r,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity})),t.iconMarks.length>0&&Va("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,r)=>Va("path",{d:Ii(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity},"ic-"+r))}),t.markerDots.length>0&&Va("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,r)=>Va("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor},"mk-"+r))}),t.showColumnHeaders&&e.colBands.map((e,n)=>ko({keyId:"col-"+n,text:r(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor})),t.showRowLabels&&[...e.rowLabelY].map(([e,r])=>ko({keyId:"row-"+e,text:n(e),x:t.labelX,y:r,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor})),t.callouts.map(e=>Xo(e))]})}(ie,{markerDots:ye,markerColor:he,iconMarks:xe,iconColor:fe,iconStrokeWidth:me,callouts:be,plot:r,showEnclosures:k,showColumnHeaders:$,showRowLabels:A,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:r.y+.62*S,labelX:r.x+I-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel});return{sceneNodes:ge,overlays:we}},Ga=4;import*as _a from"react";var Xa=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height)return{nodes:[]};let n=xi(t.categoryAccessor),o=xi(t.stackBy),i=e=>{let r="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],n=Number(r);return Number.isFinite(n)&&n>0?n:0},a=t.gutter??2,l="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",s="string"==typeof t.stackBy?t.stackBy:"stack",c="string"==typeof t.valueAccessor?t.valueAccessor:"value",u=(e,t,r)=>Oo(n=>{n("category",e),n("stack",t),n("value",r),"category"!==l&&n(l,e),"stack"!==s&&n(s,t),"value"!==c&&n(c,r)}),d=!1!==t.showCategoryLabels,h=Math.max(0,r.height-(t.labelPadding??(d?22:0))),f=[],m=new Map,p=[],g=new Set,y=new Map;for(let t of e.data){let e=n(t)+"",r=o(t)+"",a=i(t);m.has(e)||(f.push(e),m.set(e,0),y.set(e,new Map)),g.has(r)||(g.add(r),p.push(r)),m.set(e,(m.get(e)??0)+a);let l=y.get(e);l.set(r,(l.get(r)??0)+a)}let x=t.categoryOrder?et(t.categoryOrder,f,e=>m.has(e)):f,b=t.stackOrder?et(t.stackOrder,p,()=>!0):p,w=x.reduce((e,t)=>e+(m.get(t)??0),0);if(0>=w)return{nodes:[]};let M=Math.max(0,r.width-a*Math.max(0,x.length-1)),v=[],k=[],$=r.x;for(let t of x){let n=m.get(t)??0,o=n/w*M;if(0>=o)continue;k.push({cat:t,x:$,w:o});let i=y.get(t),l=r.y;for(let r of b){let a=i.get(r)??0;if(0>=a)continue;let s=a/n*h;v.push({type:"rect",x:$,y:l,w:o,h:s,style:{fill:e.resolveColor(r),stroke:"none"},datum:u(t,r,a),group:r}),l+=s}$+=o+a}return{nodes:v,overlays:d&&k.length>0?function(e,t,r){let n=e.map((e,n)=>ko({keyId:"marimekko-label-"+n,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:r}));return _a.createElement(_a.Fragment,null,...n)}(k,r.y+h+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null}};import*as Ka from"react";var Ua=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length)return{nodes:[]};let n=t.rowHeight??28,o=t.rowGap??12,i=!1!==t.showLabels,a=i?t.labelWidth??120:0,l=!1!==t.showTicks,s=l?14:0,c=t.tickFormat??(e=>e.toLocaleString()),u=r.x+a,d=Math.max(0,r.width-a);if(0>=d)return{nodes:[]};let h=xi(t.categoryAccessor),f=e=>{let t=Number(e);return Number.isFinite(t)&&t>0?t:0},m=e=>f("function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor]),p=e=>f("function"==typeof t.targetAccessor?t.targetAccessor(e):e[t.targetAccessor]),g=e=>{let r="function"==typeof t.rangesAccessor?t.rangesAccessor(e):e[t.rangesAccessor];return Array.isArray(r)?r.map(f).sort((e,t)=>e-t):[]},y="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",x="string"==typeof t.valueAccessor?t.valueAccessor:"value",b="string"==typeof t.targetAccessor?t.targetAccessor:"target",w=t.actualColor??e.theme.semantic.primary??"#3b6cb1",M=e.theme.semantic.text??"currentColor",v=t.targetColor??`var(--semiotic-text, ${M})`,k=[`var(--semiotic-surface, ${e.theme.semantic.surface??"#e8eaed"})`,`var(--semiotic-grid, ${e.theme.semantic.grid??"#cdd1d6"})`,`var(--semiotic-border, ${e.theme.semantic.border??"#a3a8af"})`],$=`var(--semiotic-text, ${M})`,A=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,S=[],I=[];for(let t=0;e.data.length>t;t++){let i=e.data[t],a=g(i),l=m(i),c=p(i),f=Math.max(l,c,...a.length?a:[0]);if(0>=f)continue;let M=r.y+t*(n+o+s);if(M+n+s>r.y+r.height)break;I.push({yTop:M,label:h(i),actual:l,target:c,maxVal:f});let $=e=>u+e/f*d,A=h(i),C=e=>Oo(t=>{t("metric",A),"metric"!==y&&t(y,A),e(t)}),N=u;for(let e=0;a.length>e;e++){let t=$(a[e]),r=t-N;r>0&&S.push({type:"rect",x:N,y:M,w:r,h:n,style:{fill:k[Math.min(e,k.length-1)],stroke:"none"},datum:C(t=>{t("range",e),t("rangeValue",a[e]),t("kind","range")}),group:"range-"+e}),N=t}let z=Math.max(6,Math.floor(.45*n));S.push({type:"rect",x:u,y:M+(n-z)/2,w:$(l)-u,h:z,style:{fill:w,stroke:"none"},datum:C(e=>{e("value",l),e("kind","actual"),"value"!==x&&e(x,l)}),group:"actual"});let F=3,E=Math.floor(.8*n);S.push({type:"rect",x:$(c)-F/2,y:M+(n-E)/2,w:F,h:E,style:{fill:v,stroke:"none"},datum:C(e=>{e("target",c),e("kind","target"),"target"!==b&&e(b,c)}),group:"target"})}let C=[];for(let e=0;I.length>e;e++){let t=I[e];if(i&&C.push(ko({keyId:"bullet-label-"+e,text:t.label,x:r.x+a-8,y:t.yTop+n/2,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:$})),l){let r=t.yTop+n+2;for(let n=0;5>n;n++){let o=t.maxVal*n/4,i=u+o/t.maxVal*d;C.push(Ka.createElement("line",{key:`bullet-tick-${e}-${n}`,x1:i,x2:i,y1:r,y2:r+3,stroke:A,strokeWidth:1}),ko({keyId:`bullet-ticktext-${e}-${n}`,text:c(o),x:i,y:r+12,anchor:0===n?"start":4===n?"end":"middle",baseline:"auto",fontSize:10,color:A}))}}}return{nodes:S,overlays:C.length>0?Ka.createElement(Ka.Fragment,null,...C):null}};import{jsx as Qa,jsxs as Za}from"react/jsx-runtime";var Ja=1.75,el="#222222",tl=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height)return{nodes:[]};let n=xi(t.categoryAccessor??"name"),o=xi(t.teaVolumeAccessor??"teaVolume"),i=xi(t.bobaVolumeAccessor??"bobaVolume"),a=xi(t.iceVolumeAccessor??"iceVolume"),l=xi(t.cupHeightAccessor??"cupHeight"),s=xi(t.cupTopRadiusAccessor??"cupTopRadius"),c=xi(t.cupBottomRadiusAccessor??"cupBottomRadius"),u=xi(t.bobaRadiusAccessor??"bobaRadius"),d=t.cupWidthRatio??.82,h=e.scales.o,f=h.bandwidth(),m=Math.max(1,r.height-26-8),p=r.y+8,g=[],y=[];for(let t of e.data){let r=n(t)+"",x=h(r);if(null==x)continue;let b={height:st(l(t),15.5),topRadius:st(s(t),4.75),bottomRadius:st(c(t),3.75)},w=st(u(t),.6),M=Math.max(0,st(o(t),450)),v=Math.max(0,st(i(t),110)),k=Math.max(0,st(a(t),135)),$=Math.PI*w*w,A=Math.floor(v/$),S=A*$,I=Math.floor(k/5.359375),C=I*Ja*Ja*Ja,N=M+S+C,z=nt(b,N),F=Math.min(b.height,Math.max(0,z)),E=tt(b,F),{pearls:j,layers:O}=at(b,w,A),R=F,W=lt(b,O*w*2,R,I),T=b.height-20.32,L=Math.min(0,T),P=Math.min(f*d/(2*(b.topRadius+1)),m/(b.height-L)),q=x+f/2,D=e=>q+e*P,V=e=>p+(e-L)*P,B=D(-(b.topRadius+1)),H=D(b.topRadius+1),Y=V(L),G=V(b.height),_=Ro({name:r,teaVolume:M,bobaVolume:Math.round(S),iceVolume:Math.round(C),totalVolume:Math.round(N),numBobas:A,numIce:I,kind:"boba cup"});g.push({type:"rect",x:B,y:Y,w:Math.max(1,H-B),h:Math.max(1,G-Y),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:_,group:r,_transitionKey:"boba-"+Ai(r)});let X=b.height-R,K=Ai(r),U=e.resolveColor(r);y.push(Za("g",{children:[M>0?Qa("path",{d:`M${D(-E)},${V(X)} L${D(-b.bottomRadius)},${V(b.height)} L${D(b.bottomRadius)},${V(b.height)} L${D(E)},${V(X)} z`,fill:"#D2B799"}):null,j.map((e,t)=>Qa("circle",{cx:D(e.x),cy:V(e.z),r:w*P,fill:"#222222",opacity:.5},"p-"+t)),W.map((e,t)=>Qa("rect",{x:D(e.cx)-.95*Ja*P/2,y:V(e.cy)-.95*Ja*P/2,width:.95*Ja*P,height:.95*Ja*P,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${D(e.cx)} ${V(e.cy)})`},"i-"+t)),Qa("path",{d:`M${D(-b.topRadius)},${V(0)} L${D(-b.bottomRadius)},${V(b.height)} L${D(b.bottomRadius)},${V(b.height)} L${D(b.topRadius)},${V(0)}`,fill:"none",stroke:el,strokeWidth:2.5}),Qa("line",{x1:D(-(b.topRadius+1)),y1:V(0),x2:D(b.topRadius+1),y2:V(0),stroke:el,strokeWidth:3,strokeLinecap:"round"}),M>0?Qa("path",{d:`M${D(-.635)},${V(T)} L${D(-.635)},${V(b.height-.4)} L${D(.635)},${V(b.height-1.27-.4)} L${D(.635)},${V(T)} z`,fill:"#4F91CB",stroke:el,strokeWidth:1,opacity:.78}):null,Qa("text",{x:q,y:G+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:r}),Qa("text",{x:q,y:G+30,textAnchor:"middle",fontSize:10,fill:U,children:`${A} pearls · ${Math.round(N)} cm³`})]},"boba-"+K))}return{nodes:g,overlays:Qa("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:y})}},rl=["naturalGas","coal","nuclear","hydro","wind","solar","other"],nl={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},ol={tight:5,watch:12,comfortable:20};import*as il from"react";var al=class{constructor(){this.count=0,this.capacity=1,this.tree=new Float64Array(2).fill(NaN)}assign(e,t){let r;if(this.tree[1]>e)r=this.count++,r===this.capacity&&this.grow();else{let t=1;for(;this.capacity>t;)t*=2,e>=this.tree[t]||t++;r=t-this.capacity}let n=this.capacity+r;for(this.tree[n]=t;n>1;){n=Math.floor(n/2);let e=this.minimum(n);if(this.tree[n]===e)break;this.tree[n]=e}return r}minimum(e){let t=this.tree[2*e],r=this.tree[2*e+1];return r>=t||Number.isNaN(r)?t:r}grow(){let e=this.tree,t=this.capacity;this.capacity*=2,this.tree=new Float64Array(2*this.capacity).fill(NaN),this.tree.set(e.subarray(t),this.capacity);for(let e=this.capacity-1;e>0;e--)this.tree[e]=this.minimum(e)}},ll=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length||!t?.domain)return{nodes:[]};let n=$t(t.laneAccessor),o=$t(t.startAccessor),i=$t(t.endAccessor),a=t.idAccessor?$t(t.idAccessor):null,l=t.unit??0,s=t.barGap??1.5,c=Math.max(0,t.minBarWidth??2),u=t.minBarHeight??3.5,d=t.maxBarHeight??10,h=t.lanePadding??7,f=t.cornerRadius??2,m=t.bottomInset??0,p=t.color??((t,r)=>e.resolveColor(r)),[g,y]=t.domain,x=y-g||1,b=e=>r.x+(e-g)/x*r.width,w=e.scales?.o?.domain?.()??[],M=t.lanes??(w.length>0?w:[...new Set(e.data.map(n))]),v=Math.max(0,r.height-m)/Math.max(1,M.length),k=e=>b(o(e)),$=e=>Math.max(k(e)+c,b(i(e)+l)),A=[];M.forEach((t,o)=>{let i=r.y+o*v,l=e.data.filter(e=>n(e)===t);if(0===l.length)return;let{packed:c,trackCount:m}=vt(l,{start:k,end:$}),g=new Map,y=new Map;for(let{item:e,track:t}of c){let r=y.get(t);r?r.push(e):y.set(t,[e])}for(let e of y.values()){e.sort((e,t)=>k(e)-k(t));for(let t=0;e.length-1>t;t++)g.set(e[t],k(e[t+1]))}let x=(v-2*h)/m,b=Math.min(d,Math.max(Math.min(u,x),x-s));for(let{item:e,track:r}of c){let n=k(e),o=g.get(e),l=$(e)-n;A.push({type:"rect",x:n,y:i+h+r*x,w:void 0!==o&&n+l>o-1?Math.max(1,o-1-n):l,h:b,cornerRadii:f>0?{tl:f,tr:f,br:f,bl:f}:void 0,style:{fill:p(e,t),stroke:"none"},datum:e,group:t,_transitionKey:a?a(e)+"":void 0})}});let S=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,I=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,C=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,N=[];(t.periods??[]).forEach((e,t)=>{let n=b(e.start),o=Math.max(1,b(e.end+l)-n);N.push(il.createElement("rect",{key:"period-"+t,x:n,y:r.y,width:o,height:r.height,fill:C,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&N.push(ko({keyId:"period-label-"+t,text:e.name,x:n+4,y:r.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:I}))});let z=!1!==t.showLaneLabels,F=t.laneLabelGap??12;if(M.forEach((e,t)=>{let n=r.y+t*v;N.push(il.createElement("line",{key:"lane-sep-"+t,x1:r.x,x2:r.x+r.width,y1:n,y2:n,stroke:C,opacity:.45})),z&&N.push(ko({keyId:"lane-label-"+t,text:e,x:r.x-F,y:n+v/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:S}))}),!1!==t.showAxis){let e=t.axisTicks??Array.from({length:8},(e,t)=>Math.round(g+t/7*x));N.push(Go({keyId:"interval-axis",scale:b,ticks:e,orient:"top",offset:r.y,tickLength:0,gridLength:r.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:I}))}return{nodes:A,overlays:il.createElement(il.Fragment,null,...N)}},sl={width:60,height:34},cl=e=>{let{plot:t}=e.dimensions;if(0>=t.width||0>=t.height||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};let r=e.config.fixedAxis??"y",{positioned:n,byId:o}=Ot(e.nodes,e.edges,t,e.config),i=n.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[];e.edges.forEach((t,n)=>{let i=o.get((s=t,("function"==typeof e.config.sourceAccessor?e.config.sourceAccessor(s):pi(s,e.config.sourceAccessor??"source",void 0))+"")),l=o.get((t=>("function"==typeof e.config.targetAccessor?e.config.targetAccessor(t):pi(t,e.config.targetAccessor??"target",void 0))+"")(t));var s;if(!i||!l)return;let{from:c,to:u}=It({cx:i.x,cy:i.y,width:i.width,height:i.height},{cx:l.x,cy:l.y,width:l.width,height:l.height},{orientation:"y"===r?"vertical":"horizontal"});a.push({type:"curved",pathD:At(c,u,{orientation:"y"===r?"vertical":"horizontal",bend:Ct(n,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:Ni(t)??t})});let l=n.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:i,sceneEdges:a,labels:l}};import{jsx as ul,jsxs as dl}from"react/jsx-runtime";var hl=1.15,fl={a:.556,b:.556,c:.5,d:.556,e:.556,f:.278,g:.556,h:.556,i:.222,j:.222,k:.5,l:.222,m:.833,n:.556,o:.556,p:.556,q:.556,r:.333,s:.5,t:.278,u:.556,v:.5,w:.722,x:.5,y:.5,z:.5,"'":.191,"-":.333,".":.278," ":.278},ml=e=>{let t=e.config,{plot:r}=e.dimensions;if(0>=r.width||0>=r.height||0===e.data.length)return{nodes:[]};let n=xi(t.textAccessor),o=e=>{let r=Number(xi(t.weightAccessor)(e));return Number.isFinite(r)&&r>0?r:0},i=xi(t.columnAccessor),a=e=>Number(xi(t.segmentAccessor)(e)),l=t.minFontSize??11,s=t.maxFontSize??42,c=t.columnGutter??18,u=t.collisionPadding??2,d=!1!==t.showColumnLabels,h=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>Math.round(e)+""),p=t.rotate??0,g=!0===t.repeatWords,y=!1!==t.scaleToFit,x=t.packingDensity??.6,b="string"==typeof t.textAccessor?t.textAccessor:"word",w="string"==typeof t.weightAccessor?t.weightAccessor:"weight",M="string"==typeof t.columnAccessor?t.columnAccessor:"column",v="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",k=[],$=new Map,A=1/0,S=-1/0;for(let t=0;e.data.length>t;t++){let r=e.data[t],l=i(r)+"",s=n(r)+"",c=o(r),u=a(r);!s||!Number.isFinite(u)||($.has(l)||(k.push(l),$.set(l,[])),$.get(l).push({col:l,text:s,weight:c,segment:u,datum:r,dataIndex:t}),A>u&&(A=u),u>S&&(S=u))}if(0===k.length)return{nodes:[]};if(!g)for(let[e,t]of $){let r=new Map;for(let e of t){let t=r.get(e.text);(!t||e.weight>t.weight)&&r.set(e.text,e)}$.set(e,[...r.values()])}let I=1/0,C=-1/0;for(let e of $.values())for(let t of e)I>t.weight&&(I=t.weight),t.weight>C&&(C=t.weight);if(!Number.isFinite(I))return{nodes:[]};let N=t.columnOrder?[...t.columnOrder.filter(e=>$.has(e)),...k.filter(e=>!t.columnOrder.includes(e))]:k,z=new Map(N.map(r=>[r,t.columnColor?.(r)||e.resolveColor(r)])),[F,E]=t.segmentDomain??[A,S],j=E-F||1,O=C-I||1,R=d?22:0,W=h?52:0,T=r.x+W,L=r.y+R,P=Math.max(0,r.width-W),q=Math.max(0,r.height-R),D=N.length,V=D>0?Math.max(0,P-c*Math.max(0,D-1))/D:0,B=L+14,H=L+q-14,Y=e=>B+(e-F)/j*(H-B),G=V*q,_=1/0,X=1/0,K=N.map((e,r)=>{let n=z.get(e),o=($.get(e)??[]).map(e=>{let o={word:e.text,column:e.col,weight:e.weight,segment:e.segment,datum:e.datum,dataIndex:e.dataIndex,columnIndex:r,resolvedColumnColor:n},i=t.wordOpacity?Number(t.wordOpacity(o)):1,a=t.wordColor?.(o);return{text:e.text,weight:e.weight,segment:e.segment,baseFont:(c=e.weight,l+Math.sqrt((c-I)/O)*(s-l)),opacity:Number.isFinite(i)?No(i,0,1):0,color:a||n,info:o};var c});if(0===o.length)return null;let i=0;for(let e of o){let t=1.05*Tt(e.text);i+=t*hl*e.baseFont*e.baseFont,X=Math.min(X,(V-8-1)/(t*e.baseFont))}return i>0&&(_=Math.min(_,Math.sqrt(x*G/i))),{col:e,colLeft:T+r*(V+c),center:T+r*(V+c)+V/2,rows:o}}).filter(e=>null!==e),U=e=>{let t=[],r=0;for(let n of K){if(0>=V)continue;let o=n.colLeft+4,i=n.colLeft+V-4,a=n.rows.map((t,r)=>{let o=Math.max(5,e*t.baseFont),i=`${n.col}::${t.text}::${r}`;return{id:i,text:t.text,weight:t.weight,segment:t.segment,font:o,w:Lt(t.text,o),h:o*hl+2,anchorY:Y(t.segment),seed:(Wt(i)-.5)*Math.min(.5*V,80),opacity:t.opacity,color:t.color,info:t.info}}).sort((e,t)=>t.font-e.font||(t.id>e.id?-1:1)),l=[];for(let e of a){let a=e.w/2,s=e.h/2,c=No(n.center+e.seed,o+a,i-a),d=e.anchorY,h=c,f=No(d,B+s,H-s),m=!1;for(let t=0;2600>t;t++){let r=3.2*Math.sqrt(t),n=2.399963229728653*t,p={x:No(c+r*Math.cos(n),o+a,i-a),y:No(d+r*Math.sin(n),B+s,H-s),w:e.w,h:e.h};if(!Pt(p,l,u)){h=p.x,f=p.y,m=!0;break}}m||r++,l.push({x:h,y:f,w:e.w,h:e.h});let g=Math.sqrt((e.weight-I)/O),y=p>0?2*(Wt(e.id+"r")-.5)*p:0;t.push({id:e.id,text:e.text,x:h,y:f,fontSize:e.font,rotation:y,color:e.color,opacity:e.opacity,datum:Oo(t=>{for(let r of Object.keys(e.info.datum))t(r,e.info.datum[r]);t("word",e.text),t("weight",e.weight),t("column",n.col),t("segment",e.segment),"word"!==b&&t(b,e.text),"weight"!==w&&t(w,e.weight),"column"!==M&&t(M,n.col),"segment"!==v&&t(v,e.segment),t("__strength",.5+.5*g)})})}}return{placed:t,unplaced:r}},Q=y?Math.min(1,_,X):Math.min(1,X),Z=U(Q);if(y)for(let e=0;6>e&&Z.unplaced>0&&Q>.1;e++)Q*=.88,Z=U(Q);let J=Z.placed.filter(e=>e.opacity>0);return{nodes:J.map(e=>{let t=Lt(e.text,e.fontSize)/2,r=e.fontSize*hl/2;return{type:"rect",x:e.x-t,y:e.y-r,w:2*t,h:2*r,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:e.datum.column+"",_transitionKey:e.id}}),overlays:dl("g",{className:"semiotic-word-trails",children:[h&&qt({x:r.x+W-10,yTop:B,yBot:H,segLo:F,segHi:E,segToY:Y,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:r.x}),d&&N.map((e,t)=>V>0?ul("text",{x:T+t*(V+c)+V/2,y:r.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:z.get(e),style:{pointerEvents:"none"},children:e},"wt-col-"+t):null),J.map(e=>ul("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},"wt-"+e.id))]})}},pl={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},gl=8,yl=Xt,xl=2*Math.PI;import{jsx as bl,jsxs as wl}from"react/jsx-runtime";var Ml="var(--semiotic-text, currentColor)",vl=new Set(["rows"]),kl=class{constructor(e){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.options=e,this.worker=e.createWorker(),this.worker.onmessage=e=>{let t=this.options.parseMessage(e.data),r=t.requestId,n=null!=r?this.pending.get(r):this.pending.values().next().value;if(n){if(null!=r)this.pending.delete(r);else{for(let e of this.pending.values())e!==n&&(e.cleanup(),e.reject(Error(this.options.name+" worker response missing requestId")));this.pending.clear()}if(n.cleanup(),!t.ok)return void n.reject(t.error);n.resolve(t.payload)}},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(Br(this.options.name));let r=this.nextRequestId;this.nextRequestId+=1;let n=this.options.encodeRequest?.(r,e)??{requestId:r,request:e};return new Promise((e,o)=>{let i=()=>{let e=1===this.pending.size;this.pending.delete(r),t?.removeEventListener("abort",i),o(Br(this.options.name)),this.options.terminateOnAbort&&e&&this.terminate()},a=()=>t?.removeEventListener("abort",i);this.pending.set(r,{cleanup:a,reject:o,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(n)}catch(e){this.pending.delete(r),a(),o(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error(this.options.name+" worker terminated")),this.worker.terminate())}rejectAll(e){for(let t of this.pending.values())t.cleanup(),t.reject(e);this.pending.clear()}},$l=class{constructor(e=function(){let e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):function(e){if("u">typeof __filename){let t=__filename.replace(/\\/g,"/"),r=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+r)}throw Error("Cannot resolve module worker asset: "+e)}("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.session=new kl({name:"Force layout",createWorker:()=>e,terminateOnAbort:!0,parseMessage:e=>{let t=e,{requestId:r,error:n}=function(e){return e&&"object"==typeof e?{requestId:e.requestId,error:e.error}:{}}(t);return n?{requestId:r,ok:!1,error:Hr(n)}:{requestId:r,ok:!0,payload:{positions:t.positions??{}}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},Al=function(){let e=null;return{get:()=>((!e||e.isDead)&&(e=new $l),e),resetForTest:()=>{if(e){try{e.terminate()}catch{}e=null}}}}(),Sl=[.1,.5,.9],Il=1e6,Cl="down",Nl=24,zl=.12,Fl=.55,El=0,jl=1;export{fo as DEFAULT_AREA_PER_ANNOTATION,mo as DEFAULT_GLYPH_ANCHOR,po as DEFAULT_GLYPH_VIEWBOX,gl as DEFAULT_HIT_RADIUS,ra as DEFAULT_ISOMETRIC_SPRITE_SIZES,rl as GRID_FUEL_KEYS,nl as GRID_FUEL_LABELS,go as LayoutCache,yo as SYMBOL_SEQUENCE,xl as TAU,xo as absorbRegion,kt as activeCountOverDomain,mr as addPoints,Da as adjacencyFlowLayout,_n as adjacencyMatrix,Ue as aggregateAdjacencyFlow,bo as aggregateRegionCounts,e as allocateCells,Ce as analyzeNetEnsemble,ur as angleScale,wo as annotationBudget,Mo as annotationDensity,vo as annotationLayout,Hn as arcLayout,Yn as arcPath,Dn as arrivalReplay,cl as axisFixedForceLayout,Ot as axisFixedForcePositions,r as balanceSnapshotsToFlows,ko as bandLabel,Lr as betweenness,Rr as bfsDistances,tl as bobaLayout,$o as bodyGroupSpec,Ao as boundsOf,It as boxEdgeAnchors,jr as buildAdjacency,$r as buildTooltipEntries,Ua as bulletLayout,So as calendarLayout,Io as capacitatedRegion,Co as chargeGateRegion,Gn as circularLayout,No as clamp,Pr as closeness,qr as clustering,Tn as collidersFromScales,sn as comparePhysicsTrace,Mn as composePhysicsControllers,Eo as computeTransitDiagramPositions,jo as countPairwiseCrossings,bn as createCapacityQueueController,Sn as createDependencyGateController,vn as createPortalController,fn as createProcessJourneyLedger,An as createServiceLevelController,kn as createServiceResourcePoolController,Ft as cubicPath,Nt as cubicPoint,zt as cubicTangent,At as curvedEdgePath,Qt as cyclicRangeContains,va as dagreLayout,Or as degree,dt as demandForecastRows,Fn as describePhysicsStageGeography,m as diagnoseTokenEncoding,Wo as dimFor,Tr as egoNetwork,tr as estimateLabelWidth,kr as extractTooltipDatum,Ct as fanOutBend,Ma as flextreeLayout,To as forceFieldRegion,a as forceLayout,Gr as forceLayoutAsync,bt as formatMw,wt as formatReservePct,Ar as formatTooltipValue,Ln as galtonPegs,h as generateTokens,Ht as geoAreaHitTarget,Bt as geoHitTarget,wa as geographicDotGridLayout,ha as geographicGridLayout,Lo as glyphExtent,Po as glyphFractionClipRect,qo as glyphPlacement,yt as gridEventAnnotations,D as gridifyGeographicPoints,Do as groupBy,Vo as groupCompletionRows,Bo as hatchFill,Vt as hitTargetPoint,Yt as hitTargetRect,Ho as hullFromBoxes,ll as intervalLanesLayout,sa as isometricLandmarkLayout,Gi as isotypeBoltGlyph,_i as isotypeBusGlyph,Yi as isotypeChipGlyph,Bi as isotypeGhost,Di as isotypeInk,Ui as isotypeNetworkGlyphs,Vi as isotypePaper,Ki as isotypePersonGlyph,Xi as isotypePersonPath,Hi as isotypeServerGlyph,er as layoutChipStrip,Jt as layoutSequence,f as layoutTokenGrid,wr as legendGroupsFrom,Mr as legendSwatches,Fa as lineageDagLayout,Go as linearAxis,_o as makeShade,Xa as marimekkoLayout,Xo as markCallout,Ko as matchesHighlight,Qo as mean,Zo as membraneRegion,Ra as mermaidDagLayout,Jn as mobileAnnotationStrategy,oo as mobileAreaChartRecipe,ho as mobileBrushAlternatives,uo as mobileChartFamilyRecipe,so as mobileGeoChartRecipe,no as mobileLineChartRecipe,lo as mobileNetworkChartRecipe,io as mobileOrdinalChartRecipe,ao as mobileScatterplotRecipe,co as mobileSmallMultipleRecipe,Jo as motifBraidLayout,ei as mulberry32,Pa as netEnsembleLayout,_t as networkEdgeHitTarget,Gt as networkHitTarget,ti as nonNegativeFinite,xr as normalizePoint,Dr as normalizeScores,c as normalizeTokenEncoding,ri as octilinearRoute,ni as offsetTransitPath,oi as orderByBarycenter,Bn as orderByGroupDegree,ii as orderExactSmall,St as orthogonalEdgePath,ai as packBandsBySilhouette,vt as packIntervals,rr as packSpanLevels,Ya as packedClusterMatrix,li as parallelCoordinatesLayout,ar as partitionSharedEdges,Nn as physicsChargePoint,Cn as physicsDestination,rn as physicsReferenceEnvelope,zn as physicsStageColliders,In as physicsStageGeography,si as placeWithMinGap,yr as pointMagnitude,sr as polarToXY,ci as portalRegion,Ae as prepareMotifBraid,$e as prepareNetworkAtlasAsync,ui as pressureFieldRegion,di as processChrome,pn as processJourneyRows,hi as processLaneWalls,fi as processStageLayout,mi as processStageRegions,Kr as processVolumePolygons,Vr as proximityProblem,dr as radiusScale,pi as readField,Et as rectCollide,gi as refineByAdjacentSwaps,yi as regionCountsToProjectionRows,pt as reserveAnnotationBands,ht as reserveMarginPct,ft as reserveSeries,hr as ringArcPath,bi as roundedEnclosure,wi as roundedTransitPath,Mi as routeSurfaceRegion,yl as runLengthEncode,Xt as runs,te as sampleGeographicDotGrid,nr as scaleArcBand,gr as scalePoint,qn as sedimentBake,Zt as selectCyclicRange,j as selectIsometricLandmarks,ki as shade,Ut as shortestArcDelta,Wr as shortestPath,$i as signatureKey,or as spanArcPath,ir as spanArcPeakY,Pn as spawnFromTokens,ut as stackFuelSeries,Xr as stageTargetInVolume,pr as subtractPoints,y as suggestTokenEncoding,gt as summarizeOperatingPoint,Si as symbolExtent,Ii as symbolPathString,Ci as symbolRadius,mt as thresholdBandsForReserve,xt as tightestHours,A as tokenLayer,g as tokenTaskIntentToCapabilityIntents,$a as transitDiagramLayout,o as unitize,i as unitizeRange,Ni as unwrapDatum,mn as updateProcessJourney,ji as waffleLayout,Ei as withAlpha,ml as wordTrailsLayout,Rt as wordTrailsProgressiveReveal,Kt as wrapValue,cr as xyToAngle};