semiotic 3.13.1 → 3.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +20 -21
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/reference.md +1 -1
  4. package/ai/schema.json +1 -1
  5. package/ai/surface-manifest.json +1 -1
  6. package/ai/task-packets/compare-category-totals.json +5 -5
  7. package/ai/task-packets/compare-category-totals.md +2 -2
  8. package/ai/task-packets/correct-published-chart.json +5 -5
  9. package/ai/task-packets/correct-published-chart.md +2 -2
  10. package/ai/task-packets/index.json +6 -6
  11. package/ai/task-packets/update-live-chart.json +5 -5
  12. package/ai/task-packets/update-live-chart.md +2 -2
  13. package/dist/c-27SDQN3J.min.js +1 -0
  14. package/dist/{c-N2TVSOYL.min.js → c-4EUQNA7N.min.js} +2 -2
  15. package/dist/c-5EPR4KFB.min.js +1 -0
  16. package/dist/c-5HTUQRJT.min.js +1 -0
  17. package/dist/{c-XORVM6C5.min.js → c-5KZ3NO6X.min.js} +1 -1
  18. package/dist/c-5NAU4JAY.min.js +1 -0
  19. package/dist/c-73ORHEHO.min.js +1 -0
  20. package/dist/{c-ZWJDTDEV.min.js → c-AMQAAW7G.min.js} +1 -1
  21. package/dist/c-BQWX6NBX.min.js +1 -0
  22. package/dist/c-BR2TOCUN.min.js +1 -0
  23. package/dist/c-BRBTXINY.min.js +1 -0
  24. package/dist/c-C3Z7ZRAA.min.js +1 -0
  25. package/dist/c-C4WRRUZ5.min.js +1 -0
  26. package/dist/c-CXDAWBOW.min.js +1 -0
  27. package/dist/c-DHNROAXY.min.js +1 -0
  28. package/dist/{c-OSLNYZ3Q.min.js → c-DJ6DT5BL.min.js} +16 -16
  29. package/dist/c-DNBFFE3P.min.js +1 -0
  30. package/dist/{c-4P2EM44G.min.js → c-H5THWQI4.min.js} +3 -3
  31. package/dist/{c-XZJWL7UL.min.js → c-HOMJ3C6B.min.js} +1 -1
  32. package/dist/c-HR5AH3MA.min.js +1 -0
  33. package/dist/c-HTL37JCD.min.js +1 -0
  34. package/dist/{c-VZNIIKL6.min.js → c-JDI7HKEM.min.js} +1 -1
  35. package/dist/{c-RAIBDXDV.min.js → c-JDU4Y4IW.min.js} +1 -1
  36. package/dist/{c-ENRZPF5E.min.js → c-JS2D7A2P.min.js} +1 -1
  37. package/dist/c-L6OT4OVA.min.js +1 -0
  38. package/dist/c-LDGV6TDQ.min.js +1 -0
  39. package/dist/c-LW3GP7RY.min.js +1 -0
  40. package/dist/{c-I54V24WG.min.js → c-MSZ3ZDAP.min.js} +1 -1
  41. package/dist/{c-W5ATXREF.min.js → c-NB2UEX5C.min.js} +1 -1
  42. package/dist/{c-XOGN3524.min.js → c-NBBYSAQY.min.js} +2 -2
  43. package/dist/c-OMTJIC3P.min.js +1 -0
  44. package/dist/{c-HGWITEJI.min.js → c-OOR2LN4A.min.js} +1 -1
  45. package/dist/c-OU7A3IUL.min.js +1 -0
  46. package/dist/{c-2M2OPWVA.min.js → c-PNLTF6YG.min.js} +33 -33
  47. package/dist/c-QVKOXC3S.min.js +1 -0
  48. package/dist/{c-OIJL2WZH.min.js → c-TBMFC5CR.min.js} +1 -1
  49. package/dist/c-TFESQSWE.min.js +1 -0
  50. package/dist/c-TX53234M.min.js +1 -0
  51. package/dist/c-TZBEQ5UY.min.js +1 -0
  52. package/dist/c-UALVQIIJ.min.js +1 -0
  53. package/dist/{c-62JIVHK5.min.js → c-WFSEQ2XG.min.js} +1 -1
  54. package/dist/{c-4YPPVFZH.min.js → c-XF5ILLBG.min.js} +1 -1
  55. package/dist/c-YCBCZFOC.min.js +1 -0
  56. package/dist/c-YQHGEETR.min.js +2 -0
  57. package/dist/c-ZBSL4Y32.min.js +1 -0
  58. package/dist/c-ZMB3VTD4.min.js +1 -0
  59. package/dist/components/charts/shared/types.d.ts +1 -1
  60. package/dist/components/recipes/atlas/resolution/appearance.d.ts +1 -1
  61. package/dist/components/recipes/atlas/resolution/scene.d.ts +1 -1
  62. package/dist/components/semiotic-network-zoom.d.ts +1 -1
  63. package/dist/components/store/ThemeStore.d.ts +4 -1
  64. package/dist/components/store/themeCore.d.ts +2 -0
  65. package/dist/components/stream/mediaQuery.d.ts +2 -0
  66. package/dist/components/stream/networkEdgeHitIndex.d.ts +6 -2
  67. package/dist/components/stream/networkZoom/ZoomableNetworkCustomChart.d.ts +6 -4
  68. package/dist/components/stream/networkZoom/gestures.d.ts +5 -0
  69. package/dist/components/stream/networkZoom/types.d.ts +10 -0
  70. package/dist/components/stream/pipelineTransitionTypes.d.ts +3 -5
  71. package/dist/components/stream/pipelineTransitionUtils.d.ts +4 -0
  72. package/dist/components/stream/pipelineTransitions.d.ts +1 -13
  73. package/dist/components/stream/renderers/networkArcRenderer.d.ts +1 -3
  74. package/dist/components/stream/renderers/networkCircleRenderer.d.ts +1 -3
  75. package/dist/components/stream/renderers/networkPrimitiveRenderer.d.ts +5 -0
  76. package/dist/components/stream/renderers/networkRectRenderer.d.ts +1 -3
  77. package/dist/components/stream/renderers/renderPulse.d.ts +8 -14
  78. package/dist/components/stream/sceneToSVGShared.d.ts +9 -0
  79. package/dist/components/stream/shallowEqual.d.ts +2 -0
  80. package/dist/components/stream/useMediaPreferences.d.ts +1 -4
  81. package/dist/geo.min.js +152 -152
  82. package/dist/geo.module.min.js +1 -1
  83. package/dist/network.module.min.js +1 -1
  84. package/dist/ordinal.module.min.js +1 -1
  85. package/dist/physics.module.min.js +1 -1
  86. package/dist/semiotic-ai.module.min.js +2 -2
  87. package/dist/semiotic-atlas-selection.module.min.js +1 -1
  88. package/dist/semiotic-client-cjs-shared.min.js +1018 -1025
  89. package/dist/semiotic-client-shared.module.min.js +1 -1
  90. package/dist/semiotic-experimental-auxiliary.module.min.js +2 -2
  91. package/dist/semiotic-experimental-network-resolution-react.module.min.js +1 -1
  92. package/dist/semiotic-experimental-node-auxiliary.module.min.js +3 -3
  93. package/dist/semiotic-line.module.min.js +1 -1
  94. package/dist/semiotic-network-zoom.d.ts +1 -1
  95. package/dist/semiotic-network-zoom.min.js +7 -7
  96. package/dist/semiotic-network-zoom.module.min.js +1 -1
  97. package/dist/semiotic-realtime-core.module.min.js +1 -1
  98. package/dist/semiotic-server-edge-node.module.min.js +2 -2
  99. package/dist/semiotic-server-edge.min.js +394 -397
  100. package/dist/semiotic-server-edge.module.min.js +3 -3
  101. package/dist/semiotic-server-node.min.js +394 -397
  102. package/dist/semiotic-themes-core.min.js +2 -2
  103. package/dist/semiotic-themes-core.module.min.js +1 -1
  104. package/dist/semiotic-themes.min.js +2 -2
  105. package/dist/semiotic-themes.module.min.js +1 -1
  106. package/dist/semiotic-utils-core.min.js +11 -11
  107. package/dist/semiotic-utils-core.module.min.js +3 -3
  108. package/dist/semiotic-value.module.min.js +1 -1
  109. package/dist/semiotic.module.min.js +1 -1
  110. package/dist/server.min.js +394 -397
  111. package/dist/server.module.min.js +3 -3
  112. package/dist/xy.module.min.js +1 -1
  113. package/package.json +1 -1
  114. package/dist/c-3UXQGCQT.min.js +0 -1
  115. package/dist/c-4RVDKSMQ.min.js +0 -1
  116. package/dist/c-6WJKNYIG.min.js +0 -1
  117. package/dist/c-AQUX6L2O.min.js +0 -1
  118. package/dist/c-BR5QDUCR.min.js +0 -1
  119. package/dist/c-C3YQVUB6.min.js +0 -1
  120. package/dist/c-COP4OISO.min.js +0 -1
  121. package/dist/c-FAOZZE77.min.js +0 -1
  122. package/dist/c-HBLICBM6.min.js +0 -1
  123. package/dist/c-I4BEWAKT.min.js +0 -1
  124. package/dist/c-IDCFMBA4.min.js +0 -2
  125. package/dist/c-KLJDKRD5.min.js +0 -1
  126. package/dist/c-LEICSI5V.min.js +0 -1
  127. package/dist/c-MOK4RWNO.min.js +0 -1
  128. package/dist/c-NHZ2E3CI.min.js +0 -1
  129. package/dist/c-OWRVBUSL.min.js +0 -1
  130. package/dist/c-QIVKWHDL.min.js +0 -1
  131. package/dist/c-QUAEYF34.min.js +0 -1
  132. package/dist/c-RDFFLRKC.min.js +0 -1
  133. package/dist/c-RTU5425Z.min.js +0 -1
  134. package/dist/c-SU6Z75M2.min.js +0 -1
  135. package/dist/c-SWVXFUDL.min.js +0 -1
  136. package/dist/c-TC47SNSI.min.js +0 -1
  137. package/dist/c-VLWWXOM5.min.js +0 -1
  138. package/dist/c-VNFIRKU5.min.js +0 -1
  139. package/dist/c-WFX456JK.min.js +0 -5
  140. package/dist/c-WSWMQDFZ.min.js +0 -1
  141. package/dist/c-YGTMWEEF.min.js +0 -1
  142. package/dist/c-ZDCTFRA6.min.js +0 -1
@@ -1,3 +1,3 @@
1
- import{b as e}from"./c-ZMYO3NZU.min.js";import{a as t,b as i,c as r,d as n,k as o}from"./c-QIVKWHDL.min.js";import{a,b as s}from"./c-ASTHXHRY.min.js";import{a as l,b as c,c as u,d,e as h,f as p,g as f,h as g,q as m,s as y}from"./c-YQEVPOMV.min.js";import{a as x}from"./c-YWZBFG63.min.js";import{a as b}from"./c-CBRSDPFG.min.js";import{B as v,a as w,b as k,e as S,f as A,h as M,z as $}from"./c-FAOZZE77.min.js";import{A as _,B as P,C as I,D as T,E as L,F as C,G as R,H as N,I as D,a as F,d as E,i as O,j as z,k as B,l as j,m as W,n as Y,o as q,p as X,q as G,r as V,s as H,t as U,u as Z,v as K,w as Q,x as J,y as ee,z as te}from"./c-2AURU3I6.min.js";import{a as ie,b as re,c as ne,e as oe,f as ae,g as se}from"./c-F5V47CBH.min.js";import{a as le,b as ce,c as ue}from"./c-5H6IMPPV.min.js";function de(e){let t=e?.find(e=>"bottom"===e.orient),i=e?.find(e=>"top"===e.orient),r=e?.find(e=>"left"===e.orient),n=e?.find(e=>"right"===e.orient);return{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n,xAxis:t??i,yAxis:r??n,xOrient:t||!i?"bottom":"top",yOrient:r||!n?"left":"right"}}function he(e){let t=6;for(let i=1;i<e.length;i++){let r=Math.abs(e[i]-e[i-1]);if(r>0&&Number.isFinite(r)){let n=Math.max(Math.abs(e[i]),Math.abs(e[i-1]));t=Math.max(t,Math.ceil(Math.log10(n/r))+1)}}let i=Math.min(17,t);return e=>Number.isInteger(e)?String(e):String(Number(e.toPrecision(i)))}function pe(...e){let t;for(let i of e)i&&(t=fe(t)&&fe(i)?{legendGroups:[...t.legendGroups,...i.legendGroups],legendDistance:i.legendDistance??t.legendDistance}:i);return t}function fe(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function ge(e){return"object"==typeof e&&null!==e&&"gradient"in e}function me(e){return"string"==typeof e&&e.length>0}function ye(e,t){let i=t?36:0;return e.top>=i?e:{...e,top:i}}function xe(e,t){return ye(e,me(t))}function be(e,t,i,r,n=8){let o="left"===r||"right"===r,a=r,s="left"===r?"right":"right"===r?"left":"top"===r?"bottom":"top",l=Math.max(0,(o?i[0]:i[1])-n),c=Math.max(t[a],l-e[s]);e[a]>c&&(e[a]=c)}function ve(e){return Math.ceil(7*e.length)}function we(e,t){if(fe(e)){let i=Re(t),r=100;for(let t of e.legendGroups){t.label&&(r=Math.max(r,ve(t.label)));for(let e of t.items)r=Math.max(r,i.swatchSize+i.labelGap+ve(e.label))}return r}if(ge(e)){let{gradient:t}=e,i=t.format||he(t.domain),r=Math.max(ve(i(t.domain[0])),ve(i(t.domain[1]))),n=t.label?ve(t.label):0;return Math.max(100,19+r,n)}return 100}function ke(e){return(fe(e)||ge(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):10}function Se(e,t){return null!=e?.sideGutter?Math.max(0,e.sideGutter):t?.hasAxis?t.hasAxisLabel?$e:Me:0}function Ae(e){return Math.max(0,e?.edgeGutter??3)}var Me=34,$e=70;function _e(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?64:46:22:0}function Pe(e){let{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n}=de(e.axes),o=!(i&&!t||!1===t?.visible),a=!!i&&!t&&!1!==i.visible,s=!(n&&!r||!1===r?.visible),l=!!n&&!1!==n.visible,c=!1!==e.showAxes;return{hasAxis:c&&o,hasAxisLabel:c&&o&&!!(t?.label??e.xLabel),rotatedTicks:c&&o&&(e.rotatedTicks??!!t?.autoRotate),topAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??e.xLabel),rotatedTicks:c&&(e.rotatedTicks??!!i?.autoRotate)}:void 0,leftAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(r?.label??e.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??e.yLabelRight??e.yLabel)}:void 0}}function Ie(e,t,i){if(ge(e))return e.gradient.label?46:26;if(!fe(e))return 20;let r=Re(i),n=Math.max(1,i?.maxWidth??t),o=r.rowHeight;for(let t of e.legendGroups){let e=0,i=0;for(let o of t.items){let t=r.swatchSize+r.labelGap+ve(o.label),a=0===i?t:i+r.itemGap+t;i>0&&a>n?(e+=1,i=t):i=a}t.items.length>0&&(e+=1),o=Math.max(o,e*r.rowHeight,t.label?ve(t.label):0)}return o+(e.legendGroups.length>1?16:0)}function Te(e,t,i){return we(e,t)+ke(e)+Se(t,i)+Ae(t)}function Le(e,t){let{legend:i}=t;if(!i)return;let r=t.position??"right",n=Ie(i,Math.max(1,t.size[0]-e.left-e.right),t.legendLayout)+ke(i)+_e("bottom"===r?t.axisChrome:"top"===r?t.axisChrome?.topAxis:void 0,t.legendLayout)+("top"===r&&t.hasTitle?24:0),o=Math.max(t.minimumMargin??0,"top"===r?t.hasTitle?58:34:0);"right"===r?e.right=Math.max(e.right,o,Te(i,t.legendLayout,t.axisChrome?.rightAxis)):"left"===r?e.left=Math.max(e.left,o,Te(i,t.legendLayout,t.axisChrome?.leftAxis)):"top"===r?e.top=Math.max(e.top,o,n):e.bottom=Math.max(e.bottom,o,n)}function Ce(e,t){let i=t.position??"right",r="top"===i||"bottom"===i,n=Math.max(0,t.totalWidth-t.margin.left-t.margin.right),o=Math.max(1,r?t.legendLayout?.maxWidth??n:t.reservedWidth??we(e,t.legendLayout)),a=ke(e),s=Se(t.legendLayout,"left"===i?t.axisChrome?.leftAxis:t.axisChrome?.rightAxis),l=Ae(t.legendLayout),c=Ie(e,n,t.legendLayout),u=_e(t.axisChrome,t.legendLayout),d=_e(t.axisChrome?.topAxis,t.legendLayout);if("left"===i)return{x:Math.max(l,t.margin.left-s-o-a),y:t.margin.top,width:o,height:c};if("top"===i)return{x:t.margin.left,y:t.margin.top-d-a-c,width:o,height:c};if("bottom"===i){let e=t.totalHeight-t.margin.bottom;return{x:t.margin.left,y:Math.max(e+a,Math.min(e+u+a,t.totalHeight-c)),width:o,height:c}}return{x:Math.min(t.totalWidth-o-l,t.totalWidth-t.margin.right+s+a),y:t.margin.top,width:o,height:c}}function Re(e){let t=Math.max(1,e?.swatchSize??16),i=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:i,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}function Ne(e,t){let i=24;return e.map(({hasLabel:e,itemCount:r})=>{i+=5;let n,o=i;i+=8,e&&(i+=16,n=i,i+=8);let a=i;return i+=r*t+8,{lineY:o,labelY:n,itemsY:a,endY:i}})}function De(e,t,i=!1){let r={...e};for(let e of t??[])!1===e.visible&&("top"!==e.orient||!i)&&(r[e.orient]=0);return r}var Fe=/\s+([^\s=<>/'"]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function Ee(e){let t=0;for(;t<e.length;){let i=/^\s+/.exec(e.slice(t));i&&(t+=i[0].length);let r=e.startsWith("\x3c!--",t)?"--\x3e":e.startsWith("<?",t)?"?>":void 0;if(r){let i=e.indexOf(r,t+2);if(i<0)return;t=i+r.length;continue}if(/^<!DOCTYPE\s/i.test(e.slice(t))){let i="",r=0,n=t+9;for(;n<e.length;n+=1){let t=e[n];if(i)t===i&&(i="");else if(e.startsWith("\x3c!--",n)){let t=e.indexOf("--\x3e",n+4);if(t<0)return;n=t+2}else if('"'===t||"'"===t)i=t;else if("["===t)r+=1;else if("]"===t)r-=1;else if(">"===t&&0===r)break}if(n===e.length)return;t=n+1;continue}break}let i=/^<((?:[A-Za-z_][\w.-]*:)?svg)(?=[\s/>])((?:[^<>"']|"[^"]*"|'[^']*')*)>/i.exec(e.slice(t));if(!i)return;let r=i[2].endsWith("/"),n=r?i[2].slice(0,-1):i[2];return n.replace(Fe,"").trim()?void 0:{start:t,end:t+i[0].length,name:i[1],attributes:n,selfClosing:r}}function Oe(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;")}function ze(e){return e.replace(/&(amp|quot|apos|lt|gt|#\d+|#x[\da-fA-F]+);/g,(e,t)=>{if(!t.startsWith("#"))return{amp:"&",quot:'"',apos:"'",lt:"<",gt:">"}[t];let i=t.startsWith("#x")?parseInt(t.slice(2),16):Number(t.slice(1));return i>0&&i<=1114111?String.fromCodePoint(i):e})}function Be(e){return ze(e.replace(/\r\n|[\t\r\n]/g," "))}function je(e,t){for(let i of e.attributes.matchAll(Fe))if(i[1]===t)return Be(i[2]??i[3])}function We(e,t){let i=Ee(e)?.start??0;return e.slice(0,i)+e.slice(i).replace(/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,(e,i)=>i?e.replace(Fe,(e,i,r,n)=>{let o=t(i,Be(r??n));return void 0===o?e:` ${i}="${Oe(o)}"`}):e)}function Ye(e,t){let i=Ee(e);if(!i)return e;let r=new Map(Object.entries(t)),n=i.attributes.replace(Fe,(e,t)=>{let i=r.get(t);return void 0===i?e:(r.delete(t),` ${t}="${Oe(i)}"`)});for(let[e,t]of r)n+=` ${e}="${Oe(t)}"`;return`${e.slice(0,i.start)}<${i.name}${n}${i.selfClosing?"/":""}>${e.slice(i.end)}`}function qe(e,t,i,r){let n=e=>i.get(e)??e;return"id"===e?n(t):/^(?:xlink:?)?href$/i.test(e)?"#"===t[0]?`#${n(t.slice(1))}`:t:/^(?:aria-(?:labelledby|describedby|controls|owns|activedescendant|details|errormessage)|for|htmlFor|list|form|headers|itemref|popovertarget)$/.test(e)?t.replace(/\S+/g,n):/^(?:fill|stroke|clip-?path|mask|filter|marker-?(?:start|mid|end)|style|cursor)$/i.test(e)?r?r(t,i):t.replace(/url\(\s*(["']?)#([^\s"')]+)\1\s*\)/g,(e,t,i)=>{let r=n(i);return r===i?e:`url(#${r})`}):t}var Xe=/\\(?:([\da-fA-F]{1,6})(?:\r\n|[\t\n\f\r ])?|([^\n\r\f]))/g,Ge=/\/\*[\s\S]*?(?:\*\/|$)|(?<![\w-])url\(\s*(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|(?:\\[\s\S]|[^()"'\\])*)\s*\)|"(?:\\[\s\S]|[^"\\])*(?:"|$)|'(?:\\[\s\S]|[^'\\])*(?:'|$)|#((?:[\w\u0080-\uffff-]|\\(?:[\da-fA-F]{1,6}[\t\n\f\r ]?|[^\n\r\f]))+)|\\[\s\S]|[()[\]{};]/gi;function Ve(e){return e.replace(Xe,(e,t,i)=>{if(!t)return i;let r=parseInt(t,16);return r>0&&r<=1114111&&!(r>=55296&&r<=57343)?String.fromCodePoint(r):"�"})}function He(e){return e.replace(/(^\d)|[^\w\u0080-\uffff-]/g,(e,t)=>{let i=e.charCodeAt(0);return i<32||127===i||t?`\\${i.toString(16)} `:`\\${e}`})}function Ue(e,t,i=!1){return e.replace(Ge,(e,r)=>{if(void 0!==r){let n=i&&t.get(Ve(r));return n?`#${He(n)}`:e}if(!/^url\(/i.test(e))return e;let n=e.slice(4,-1).trim(),o=/^["']/.test(n)?n[0]:"",a=Ve(o?n.slice(1,-1):n),s=a.startsWith("#")&&t.get(a.slice(1));return s?`url(${o}#${He(s)}${o})`:e})}function Ze(e,t){return function(e,t){let i,r=/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,n="",o=0;for(r.lastIndex=Ee(e)?.start??0;i=r.exec(e);){let a=i[1];if(!a||!/^(?:[\w.-]+:)?style$/i.test(a)||/\/\s*>$/.test(i[0]))continue;let s=r.lastIndex,l=new RegExp(`</${a.replace(/\./g,"\\.")}\\s*>`,"ig");l.lastIndex=s;let c=l.exec(e);if(!c)continue;let u=e.slice(s,c.index),d=/^(\s*<!\[CDATA\[)([\s\S]*)(\]\]>\s*)$/.exec(u),h=d?d[2]:ze(u),p=t(h);n+=e.slice(o,s)+(p===h?u:d?`${d[1]}${p}${d[3]}`:p.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/\]\]>/g,"]]&gt;")),o=c.index,r.lastIndex=l.lastIndex}return n+e.slice(o)}(We(e,(e,i)=>{let r=qe(e,i,t,Ue);return r===i?void 0:r}),e=>function(e,t){let i=0,r=0,n="";for(let o of e.matchAll(Ge)){let a=o[0];if("("===a||"["===a)r++;else if(")"===a||"]"===a)r--;else if(0===r&&/[{};]/.test(a)&&1===a.length){let r=e.slice(i,o.index),s=/^(?:\s|\/\*[\s\S]*?\*\/)*@([\w-]+)/.exec(r);n+=Ue(r,t,"{"===a&&(!s||"scope"===s[1].toLowerCase()))+a,i=o.index+1}}return n+Ue(e.slice(i),t)}(e,t))}function Ke(e,t){let i=new Map;return We(e,(e,r)=>{"id"===e&&i.set(r,r.startsWith(`${t}-`)?r:`${t}-${r}`)}),Ze(e,i)}function Qe(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}function Je(e,t){let i=Ee(e);if(!i)return t;let r=e=>{let r=je(i,e),n=r&&/^[0-9]+(?:\.[0-9]+)?$/.test(r)?Number(r):NaN;return Number.isFinite(n)&&n>0?n:t[e]};return{width:r("width"),height:r("height")}}function et(e,t){let i=Ee(e);return i?Ye(e,{width:"100%",height:"100%",...void 0===je(i,"viewBox")?{viewBox:`0 0 ${t.width} ${t.height}`}:{},...void 0===je(i,"preserveAspectRatio")?{preserveAspectRatio:"xMidYMid meet"}:{}}):e}function tt(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var it={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function rt(e,t={}){let i=t.mobileSemantics?.interaction,r="number"==typeof i?.targetSize?i.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,n="mobile"===t.mode||"number"==typeof t.width&&t.width<=480,o=!!i||void 0!==r,a=e&&"object"==typeof e?e:void 0;if(!1===e||!1===a?.enabled||void 0===e&&!n&&!o)return it;let s=a??{};return{enabled:!0,tapToSelect:s.tapToSelect??!0,tapToLockTooltip:s.tapToLockTooltip??!0,clearSelection:s.clearSelection??"backgroundTap",targetSize:s.targetSize??r??44,snap:s.snap??"nearestDatum",brushHandleSize:s.brushHandleSize??44,standardControls:s.standardControls??!1}}var nt={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function ot(e,t,i){if(!1!==t)return e;let r={...e};return"horizontal"===i?r.left=Math.min(r.left,15):r.bottom=Math.min(r.bottom,15),r}var at={width:900,height:520},st={width:900,height:520},lt={width:920,height:440},ct={width:980,height:860},ut={MultiAxisLineChart:{width:800,height:400},PieChart:{width:400,height:400},DonutChart:{width:400,height:400},GaugeChart:{width:300,height:250},ForceDirectedGraph:{width:600,height:600},SankeyDiagram:{width:800,height:600},ChordDiagram:{width:600,height:600},TreeDiagram:{width:600,height:600},Treemap:{width:600,height:600},CirclePack:{width:600,height:600},OrbitDiagram:{width:600,height:600},GaltonBoardChart:{width:700,height:420},UnitPileChart:{width:700,height:380},CollisionSwarmChart:{width:700,height:360},EventDropChart:{width:760,height:360},PacketFlowChart:{width:760,height:420},ProcessFlowChart:{width:900,height:420},PhysicsCustomChart:{width:700,height:380},GauntletChart:at,CrucibleChart:st,ChainReactionChart:{width:920,height:620},DependencyForestChart:lt,FlowCircuitChart:ct};function dt(e){return["MinimapChart","ProcessSankey","ChainReactionChart","DependencyForestChart","FlowCircuitChart"].includes(e)}function ht(e){return e instanceof Date?`date:${e.getTime()}`:`${typeof e}:${String(e)}`}var pt={kind:"rank-competition"};function ft(e,t,i,r){let n=e??t;return"function"==typeof n?n(i,r):i[String(n)]}var gt=/*#__PURE__*/Symbol.for("semiotic.semantic-viability"),mt=globalThis;function yt(){return mt[gt]}function xt(e){return"string"==typeof e?.code&&e.code.length>0&&("warning"===e.severity||"error"===e.severity)&&"string"==typeof e.message&&e.message.length>0}function bt(e,t,i){if(e.semanticDiagnostics=[],e.semanticStatus="not-assessed",e.empty)return;let r,n=function(e){return function(e){return yt()?.has(e)??!1}(e)?function(e){return yt()?.get(e)}(e):"BumpChart"===e?pt:void 0}(t);if(n){try{let t="function"==typeof n?n(i,e):function(e){let t=new Map;(Array.isArray(e.data)?e.data:[]).forEach((i,r)=>{if(!Number.isFinite(Number(ft(e.yAccessor,"y",i,r))))return;let n=ht(ft(e.xAccessor,"x",i,r)),o=t.get(n)??new Set;o.add(String(ft(e.lineBy,"series",i,r))),t.set(n,o)});let i=Array.from(t.values(),e=>e.size).sort((e,t)=>e-t);if(0===i.length)return[];let r=Math.floor(i.length/2),n={columns:i.length,median:i.length%2?i[r]:(i[r-1]+i[r])/2,max:i[i.length-1],contestedColumns:i.filter(e=>e>=2).length},o=n.max<2;return!o&&n.contestedColumns>=2&&n.median>=2?[]:[{code:o?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:o?"error":"warning",message:o?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...n}}]}(i);r=Array.from(t).filter(xt)}catch{return void(e.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||e.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}e.semanticDiagnostics=r,e.semanticStatus=r.some(e=>"error"===e.severity)?"degenerate":r.some(e=>"warning"===e.severity)?"degraded":"meaningful";for(let t of r)e.warnings.includes(t.code)||e.warnings.push(t.code)}}import*as vt from"react-dom/server";function wt(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;let n=Number(r);return Number.isFinite(n)?n:null}function kt(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;if(r instanceof Date)return Number.isFinite(r.getTime())?r:null;if("string"==typeof r){let e=z(r);if(Number.isFinite(e))return new Date(e)}let n=Number(r);return Number.isFinite(n)?n:null}import*as St from"react";var At=Object.freeze([]);function Mt(e){if(!e)return At;for(let t of e)if(null==t||"object"!=typeof t)return e.filter(e=>null!=e&&"object"==typeof e);return e}import{scaleOrdinal as $t}from"d3-scale";function _t(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function Pt(e,t,i){let r=e=>e.toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function It(e){let t=e.map(_t),i=t.length-1;return e=>{if(Number.isNaN(e)&&(e=0),e<=0){let[e,i,r]=t[0];return Pt(e,i,r)}if(e>=1){let[e,r,n]=t[i];return Pt(e,r,n)}let r=e*i,n=Math.floor(r),o=r-n,[a,s,l]=t[n],[c,u,d]=t[n+1];return Pt(Math.round(a+(c-a)*o),Math.round(s+(u-s)*o),Math.round(l+(d-l)*o))}}var Tt=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],Lt=/*#__PURE__*/It(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),Ct=/*#__PURE__*/It(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),Rt=/*#__PURE__*/It(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Nt=/*#__PURE__*/It(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Dt=/*#__PURE__*/It(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),Ft=/*#__PURE__*/It(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Et=/*#__PURE__*/It(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),Ot={blues:Lt,reds:Ct,greens:Rt,viridis:Et,oranges:Nt,purples:Dt,greys:Ft,plasma:/*#__PURE__*/It(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:/*#__PURE__*/It(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:/*#__PURE__*/It(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:/*#__PURE__*/It(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:/*#__PURE__*/It(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])};function zt(e){return e&&Object.prototype.hasOwnProperty.call(Ot,e)?Ot[e]:Lt}var Bt=/*#__PURE__*/It(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),jt=/*#__PURE__*/It(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),Wt=/*#__PURE__*/It(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Yt=/*#__PURE__*/It(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),qt=/*#__PURE__*/It(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Xt=/*#__PURE__*/It(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Gt=/*#__PURE__*/It(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),Vt={category10:Tt,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...Ot},Ht=Tt,Ut="#007bff";function Zt(e,t,i=Ht){if(e&&"object"==typeof e&&!Array.isArray(e)){let t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){let t=Object.prototype.hasOwnProperty.call(Vt,e)?Vt[e]:void 0;if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:i}var Kt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Qt=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],Jt=/*#__PURE__*/new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function ei(e,t,i){if("function"==typeof t){let r=t(e);return i&&r&&"string"==typeof r&&!function(e){let t=e.toLowerCase();return t.startsWith("#")||t.startsWith("rgb")||t.startsWith("hsl")||Jt.has(t)}(r)?i(r):r}let r=String(e?.[t]);return i?i(r):Ht[Math.abs(function(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i),t&=t;return Math.abs(t)}(r))%Ht.length]}function ti(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;let i=e[t];return"string"==typeof i&&i.length>0?i:void 0}function ii(e,t,i="category10"){if(i&&"object"==typeof i&&!Array.isArray(i)){let e=i;return t=>ti(e,t)??"#999"}let r=Array.from(new Set(e.map(e=>e?.[t]).filter(e=>null!=e).map(e=>String(e)))),n=r.every(e=>!isNaN(Number(e)));if(Array.isArray(i))return $t().domain(r).range(i).unknown("#999");let o=Object.prototype.hasOwnProperty.call(Vt,i)?Vt[i]:Vt.category10;if(n&&"function"==typeof o){let e=-1/0;for(let t of r){let i=Number(t);i>e&&(e=i)}return t=>o(0===e?0:Number(t)/e)}{let e=Array.isArray(o)?o:Ht;return $t().domain(r).range(e).unknown("#999")}}function ri(e,t,i=[3,20],r){let n;if(n="function"==typeof t?t(e):e?.[t],!r)return n;let[o,a]=r,[s,l]=i;if(a===o)return(s+l)/2;let c=(n-o)/(a-o);return c<0?c=0:c>1&&(c=1),s+c*(l-s)}function ni(e,t,i,r,n){if(e)return e;if(i&&"object"==typeof i&&!Array.isArray(i)){let e=ti(i,r);if(e)return e}let o;if(Array.isArray(i))o=i;else if(t&&t.length>0)o=t;else if("string"==typeof i){let e=Vt[i];Array.isArray(e)&&(o=e)}return o&&0!==o.length?null!=r?(n.has(r)||n.set(r,n.size),o[n.get(r)%o.length]):o[0]:Ut}function oi(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function ai(e,t){if(!oi(t))return e??((...e)=>({}));let i={};return void 0!==t.stroke&&(i.stroke=t.stroke),void 0!==t.strokeWidth&&(i.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(i.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...i}):(...e)=>({...i})}function si(e){let{lineWidth:t=2,colorBy:i,colorScale:r,color:n,resolveStroke:o,fillArea:a,areaOpacity:s=.3,styleRules:l,ruleContext:c}=e;return(e,u)=>{let d,h={strokeWidth:t},p=!0===a||Array.isArray(a)&&null!=u&&a.includes(u);return o?d=o(e,u):i?r&&(d=ei(e,i,r)):d=n||Ut,void 0!==d&&(h.stroke=d,p&&(h.fill=d,h.fillOpacity=s)),l?.length&&Object.assign(h,oe(e,l,c?c(e,u):{value:void 0,category:u})),h}}function li(e){if("A"===e.__diffWinner||"B"===e.__diffWinner)return e.__diffWinner;let t=String(e.__diffSegment??"");return"line-A"===t||t.endsWith("-A")?"A":"B"}function ci(e,t){return ae(e,t,e=>{let t=Number(e.__x),i=Number(e.__y);return{value:Number.isFinite(i)?i:void 0,x:Number.isFinite(t)?t:void 0,y:Number.isFinite(i)?i:void 0,category:li(e)}},e=>e.__sourceDatum?{...e.__sourceDatum,...e}:e)}function ui(e){let{seriesAColor:t,seriesBColor:i,areaOpacity:r,styleRules:n}=e;return ci(e=>({fill:"A"===li(e)?t:i,stroke:"none",fillOpacity:r}),n)}function di(e){let{seriesAColor:t,seriesBColor:i,lineWidth:r,styleRules:n}=e;return ci(e=>({stroke:"A"===li(e)?t:i,strokeWidth:r,fill:"none"}),n)}var hi={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function pi(e,t=hi){if(e)return!0===e?t:"stops"in e?Array.isArray(e.stops)?e:void 0:"colorStops"in e?Array.isArray(e.colorStops)?{stops:e.colorStops.map(({offset:e,color:t})=>({offset:e,color:t}))}:void 0:{stops:[{offset:0,opacity:e.topOpacity??t.stops[0]?.opacity??.8},{offset:1,opacity:e.bottomOpacity??t.stops.at(-1)?.opacity??.05}]}}function fi(e){return e?pi(e):void 0}function gi(e){return{...e.extent&&{extent:e.extent},stops:e.stops.map(e=>({...e,offset:1-e.offset})).sort((e,t)=>e.offset-t.offset)}}function mi(e,t,i){return"function"==typeof e?e(i):i[e||t]}function yi(e){return e instanceof Date?e.getTime():Number(e)}function xi(e,t){return Et(1===t?.5:e/(t-1))}function bi(e){let t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}function vi(e,t){let i=function(e){if(!e)return;let t="boolean"==typeof e?{}:"string"==typeof e?{method:e}:e;return{type:"trend",method:t.method??"linear",...null!=t.bandwidth&&{bandwidth:t.bandwidth},...null!=t.order&&{order:t.order},...null!=t.color&&{color:t.color},...null!=t.strokeWidth&&{strokeWidth:t.strokeWidth},...null!=t.strokeDasharray&&{strokeDasharray:t.strokeDasharray},...null!=t.label&&{label:t.label}}}(t),r=Array.isArray(e)?e:void 0;return i?[i,...r??[]]:r}function wi(e,t){let i="dark"===t?A:S;return{...k({...w(i),...e,mode:t,colors:{...i.colors,...e.colors,categorical:[...e.colors?.categorical??i.colors.categorical]},typography:{...i.typography,...e.typography},...e.tooltip?{tooltip:{...i.tooltip,...e.tooltip}}:{}}),mode:"auto"}}var ki={background:"bg",primary:"primary",secondary:"secondary",surface:"surface",text:"text",textSecondary:"text-secondary",grid:"grid",border:"border",cellBorder:"cell-border",focus:"focus",selection:"selection-color",annotation:"annotation-color",success:"success",danger:"danger",warning:"warning",error:"error",info:"info"},Si=/*#__PURE__*/new Set,Ai=/*#__PURE__*/new WeakMap;function Mi(e,t){let i=Ai.get(e);return i?function(e,t){let i=t=>Object.entries(v(wi(e,t))).map(([e,t])=>`${e}:${t}`).join(";");return`${t}{${i("light")}}@media (prefers-color-scheme:dark){${t}{${i("dark")}}}`}(i,t):void 0}function $i(e){if(!e)return w(S);if("string"==typeof e)return $(e)||(function(e){Si.has(e)||(Si.add(e),console.warn(`[Semiotic] Unknown theme preset "${e}". Falling back to light theme.`))}(e),w(S));if("auto"===e.mode){let t=function(e){let t=wi(e,"light"),i={...t.colors};for(let[e,t]of Object.entries(ki)){let r=i[e];"string"==typeof r&&(i[e]=`var(--semiotic-${t}, ${r})`)}let r=Object.keys(v(t)).filter(e=>e.startsWith("--semiotic-category-"));return i.categorical=t.colors.categorical.map((e,t)=>`var(${r[t]}, ${e})`),{...t,colors:i}}(e);return Ai.set(t,e),t}let t="dark"===e.mode?A:S,i={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return w(k(i))}function _i(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,legendFontFamily:e.typography.legendFontFamily??e.typography.fontFamily,legendFontWeight:e.typography.legendFontWeight,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,titleFontFamily:e.typography.titleFontFamily??e.typography.fontFamily,titleFontWeight:e.typography.titleFontWeight??"bold",tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function Pi(e){if(!e.axes)return[{orient:"bottom",visible:!1!==e.showTimeAxis},{orient:"left",visible:!1!==e.showValueAxis}];let t=(...t)=>e.axes.some(e=>t.includes(e.orient)),i=!1===e.showTimeAxis&&!t("bottom","top"),r=!1===e.showValueAxis&&!t("left","right");return i||r?[...e.axes,...i?[{orient:"bottom",visible:!1}]:[],...r?[{orient:"left",visible:!1}]:[]]:e.axes}function Ii(e){return e instanceof Date&&(e=e.getTime()),"string"==typeof e&&""!==e.trim()&&(e=Number(e)),"number"==typeof e&&Number.isFinite(e)?e:null}function Ti(e){let t=[];for(let[i,r]of e){let e=Ii(i),n=Ii(r);null!==e&&null!==n&&t.push([e,n])}return t.sort((e,t)=>e[0]-t[0])}function Li(){return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN}}function Ci(e){let t=Ti(e);if(!t.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let i=t[0][0],r=t.reduce((e,[r])=>e+(r-i)/t.length,0),n=t.reduce((e,[,i])=>e+i/t.length,0),o=0,a=0;for(let[e,s]of t){let t=e-i-r;o+=t*t,a+=t*(s-n)}let s=0===o?0:a/o,l=e=>n+s*(e-i-r);return{points:t.map(([e])=>[e,l(e)]),parameterCount:2,leverage:e=>1/t.length+(o>0?(e-i-r)**2/o:0),predict:l}}function Ri(e,t=2){let i=Ti(e);if(!Number.isInteger(t)||t<0||t>=i.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let r=i[0][0]/2+i[i.length-1][0]/2,n=Math.max(Math.abs(i[0][0]-r),Math.abs(i[i.length-1][0]-r))||1,o=i.map(([e])=>(e-r)/n),a=[],s=Array.from({length:t+1},()=>Array(t+1).fill(0));for(let e=0;e<=t;e++){let t=o.map(t=>t**e);for(let i=0;i<2;i++)for(let i=0;i<e;i++){let r=t.reduce((e,t,r)=>e+t*a[i][r],0);s[i][e]+=r;for(let e=0;e<t.length;e++)t[e]-=r*a[i][e]}let r=Math.sqrt(t.reduce((e,t)=>e+t*t,0));if(!Number.isFinite(r)||r<=Number.EPSILON*i.length)return Li();s[e][e]=r,a.push(t.map(e=>e/r))}let l=a.map(e=>e.reduce((e,t,r)=>e+t*i[r][1],0));for(let e=t;e>=0;e--){for(let i=e+1;i<=t;i++)l[e]-=s[e][i]*l[i];l[e]/=s[e][e]}let c=e=>{let i=(e-r)/n,o=0;for(let e=t;e>=0;e--)o=o*i+l[e];return o};return{points:i.map(([e])=>[e,c(e)]),parameterCount:t+1,predict:c,leverage:e=>{let i=(e-r)/n,o=[];for(let e=0;e<=t;e++){let t=i**e;for(let i=0;i<e;i++)t-=s[i][e]*o[i];o.push(t/s[e][e])}return o.reduce((e,t)=>e+t*t,0)}}}import{scaleLinear as Ni}from"d3-scale";function Di(e,t=.3){if(!Number.isFinite(t)||t<0||t>1)return[];let i=Ti(e),r=i.length;if(r<2)return i;let n=i.map(e=>e[0]),o=i.map(e=>e[1]),a=0,s=Math.min(r,Math.max(2,Math.ceil(t*r)))-1,l=[];for(let e=0;e<r;e++){let t=n[e],i=0,c=r-1;for(;s<r-1&&Math.abs(n[s+1]-t)<=Math.abs(n[a]-t);)a++,s++;let u=Math.max(Math.abs(n[a]-t),Math.abs(n[s]-t)),d=u||1;u>0&&(i=a,c=s);let h=0,p=0,f=0,g=0,m=0;for(let e=i;e<=c;e++){let i=Math.abs(n[e]-t)/d,r=i<1?Math.pow(1-Math.pow(i,3),3):0;if(0===r)continue;h+=r;let a=(n[e]-t)/d;p+=r*a,f+=r*o[e],g+=r*a*a,m+=r*a*o[e]}if(0===h){l.push([t,o[e]]);continue}let y=h*g-p*p;if(Math.abs(y)<1e-12)l.push([t,f/h]);else{let e=(f-(h*m-p*f)/y*p)/h;l.push([t,e])}}return l}function Fi(e,t){if(e.length<3||e[0][0]===e[e.length-1][0])return null;let i="polynomial"===t.method?Ri(e,t.order??2):Ci(e);if(!i.points.length)return null;let r="loess"===t.method?function(e,t=.3){let i=new Map(Di(e,t));return i.size<2?null:Ni().domain([...i.keys()]).range([...i.values()])}(e,t.bandwidth):i.predict;if(!r)return null;let{se:n}=function(e,t,i=2){let r=e.length,n=e.reduce((e,[i,r])=>e+(r-t(i))**2,0);return{se:Math.sqrt(n/Math.max(r-i,1))}}(e,r,i.parameterCount),o=function(e){return e>=.99?2.576:e>=.95?1.96:e>=.9?1.645:1}(t.confidence??.95),a=e[e.length-1][0],s=(a-e[0][0])/(e.length-1);return{predict:r,forecast:(e,t=a)=>!Number.isInteger(e)||e<=0?[]:Array.from({length:e},(e,a)=>{let l=t+(a+1)*s,c=r(l),u=n*o*Math.sqrt(1+i.leverage(l));return{x:l,y:c,upper:c+u,lower:c-u}})}}var Ei="__forecastSegment",Oi="__forecastOpacity";function zi(e,t,i,r){let n=t.uncertaintyOpacity,o=t.confidenceAccessor;if(!n&&!o)return;let a="object"==typeof n?n:{},s=a.min??.15,l=a.max??1;if(o){let t="function"==typeof o?o:e=>e[o];for(let i of e){let e=t(i);if(null!=e&&Number.isFinite(e)){let t=Math.max(0,Math.min(1,e));i[Oi]=s+t*(l-s)}}return}let c=e.map(e=>{let t=i(e),n=r(e);return null!=t&&null!=n&&Number.isFinite(t)&&Number.isFinite(n)?Math.abs(t-n):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;let[d,h]=le(u),p=h-d;e.forEach((e,t)=>{let i=c[t];if(!Number.isFinite(i))return;let r=p>0?(i-d)/p:0;e[Oi]=l-r*(l-s)})}function Bi(e,t){return"function"==typeof t?t(e):!!e[t]}function ji(e){return[{type:"anomaly-band",threshold:e.threshold??2,showBand:!1!==e.showBand,fill:e.bandColor||"#6366f1",fillOpacity:e.bandOpacity??.1,anomalyColor:e.anomalyColor||"#ef4444",anomalyRadius:e.anomalyRadius??6,label:e.label}]}function Wi(e,t,i,r,n){let o=r._groupBy;if(o&&e.length){let a="function"==typeof o?o:e=>e[o],s=new Map;for(let t of e){let e=a(t),i=s.get(e);i?i.push(t):s.set(e,[t])}let l=[],c=[];for(let[e,o]of s){let s=Wi(o,t,i,{...r,_groupBy:void 0},n);for(let e of s.processedData)l.push(e);for(let t of s.annotations)if("x-threshold"===t.type)c.some(e=>"x-threshold"===e.type)||c.push(t);else{let i=t.filter;c.push({...t,filter:t=>{let r=a(t);return(r===e||Object.is(r,e))&&(!i||i(t))}})}}return{processedData:l,annotations:c}}return function(e){return!!(e.isTraining||e.isForecast||e.isAnomaly||e.upperBounds||e.lowerBounds)}(r)?function(e,t,i,r,n){let{isTraining:o,isForecast:a,isAnomaly:s,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:f}=r,g=e.map(e=>{let t="observed";return a&&Bi(e,a)?t="forecast":o&&Bi(e,o)&&(t="training"),{...e,[Ei]:t}}),m=[];for(let e=0;e<g.length;e++)m.push(g[e]),e<g.length-1&&g[e][Ei]!==g[e+1][Ei]&&(m.push({...g[e+1],[Ei]:g[e][Ei]}),m.push({...g[e],[Ei]:g[e+1][Ei]}));if(r.trainUnderline){let e=[];for(let t of m)"training"===t[Ei]&&e.push({...t,[Ei]:"training-base"});m.unshift(...e)}let y=[];if(l&&c){let e="string"==typeof l?l:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(let i of m)"function"==typeof l&&(i[e]=l(i)),"function"==typeof c&&(i[t]=c(i));y.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:f})}if(r.uncertaintyOpacity||r.confidenceAccessor){let e=l?"function"==typeof l?l:e=>e[l]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};zi(m.filter(e=>"forecast"===e[Ei]),r,e,t)}if(s){let e=r.anomalyStyle,t={type:"highlight",filter:e=>Bi(e,s)};e?(t.style=e,t.r=p):"function"==typeof h?(t.style=e=>{let t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=p):(t.color=h,t.r=p,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),y.push(t)}return n&&y.push(...ji(n)),{processedData:m,annotations:y}}(e,0,0,r,n):function(e,t,i,r,n){let{trainEnd:o,steps:a=10,color:s="#6366f1",bandOpacity:l=.15,label:c}=r;if(null===Ii(o))return{processedData:e,annotations:[]};let u=[],d=[];for(let i of[...e].sort((e,i)=>(Ii(e[t])??1/0)-(Ii(i[t])??1/0))){let e=Ii(i[t]);null!==e&&e<=o?u.push({...i,[Ei]:"training"}):d.push({...i,[Ei]:"observed"})}let h=Ti(u.map(e=>[e[t],e[i]])),p=[],f=[];if(h.length>=3&&Number.isInteger(a)&&a>0){let n=Fi(h,r);if(n){let o=e.map(e=>Ii(e[t])).filter(e=>null!==e),h=ue(o),g=e.some(e=>e[t]instanceof Date);for(let{x:e,y:r,upper:o,lower:s}of n.forecast(a,h))f.push({...d[d.length-1]??u[u.length-1],[t]:g?new Date(e):e,[i]:r,[Ei]:"forecast",__forecastUpper:o,__forecastLower:s});zi(f,r,e=>e.__forecastUpper,e=>e.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:s,fillOpacity:l,label:c})}}p.push({type:"x-threshold",x:o,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),n&&p.push(...ji(n));let g=[];if(g.push(...u),u.length>0&&d.length>0&&g.push({...u[u.length-1],[Ei]:"observed"}),g.push(...d),f.length>0){let e=d.length>0?d[d.length-1]:u[u.length-1];e&&g.push({...e,[Ei]:"forecast"}),g.push(...f)}return{processedData:g,annotations:p}}(e,t,i,r,n)}var Yi="__semiotic_resolvedX",qi="__semiotic_resolvedY",Xi="__compoundGroup";function Gi(e,t,i){let r=e[t],n=e[i];return null==r||null==n||Number.isNaN(r)||Number.isNaN(n)}function Vi(e){let t=e.xAccessor||"x",i=e.yAccessor||"y",r=e.lineBy,n=e.colorBy||r,o=Array.isArray(e.data)?Mt(e.data).filter(e=>!!e&&"object"==typeof e):[],a=function(e,t,i){let r="function"==typeof t,n="function"==typeof i,o=r?Yi:t,a=n?qi:i;return r||n?{xKey:o,yKey:a,rows:e.map(e=>{let o={...e};return r&&(o[Yi]=t(e)),n&&(o[qi]=i(e)),o})}:{rows:e,xKey:o,yKey:a}}(o,t,i);o=a.rows;let s,l,c=a.xKey,u=a.yKey,d=Array.isArray(e.annotations)?[...e.annotations]:[],h="string"==typeof r||"function"==typeof r?r:void 0,p=e.baseLineStyle;if(e.forecast){let t=Wi(o,c,u,!r||"string"!=typeof r&&"function"!=typeof r?e.forecast:{...e.forecast,_groupBy:r},e.anomaly);if(o=t.processedData,d.push(...t.annotations),s=function(e,t,i){if(!i)return;let r=[t,i.upperBounds??"__forecastUpper",i.lowerBounds??"__forecastLower"].map(e=>"function"==typeof e?e:t=>t[e]),n=!(!i.upperBounds&&!i.lowerBounds),o=1/0,a=-1/0;for(let t of e){let e=r[1](t),i=r[2](t);(null!=e||null!=i)&&(n=!0);for(let n of[Number(r[0](t)),e,i])"number"==typeof n&&Number.isFinite(n)&&(o=Math.min(o,n),a=Math.max(a,n))}return n&&o<=a?[o,a]:void 0}(o,u,e.forecast),!r||"string"!=typeof r&&"function"!=typeof r?h=Ei:(o=o.map(e=>({...e,[Xi]:`${"function"==typeof r?r(e):e[r]}__${e[Ei]||"observed"}`})),h=Xi),e.baseLineStyle){let t=function(e,t){let i=t.trainDasharray??"8,4",r=t.forecastDasharray??"4,4",n=t.color||"#6366f1",o=t.trainOpacity,a=t.forecastOpacity,s=t.trainStroke,l=t.trainLinecap,c=t.trainUnderline;return t=>{let u=e(t),d=t[Ei];if("training"===d){let e=u.stroke;return"darken"===s?e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)*(1-t)),n=Math.round(parseInt(i[2],16)*(1-t)),o=Math.round(parseInt(i[3],16)*(1-t));return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):s&&(e=s),{...u,stroke:e,strokeDasharray:i,...l&&{strokeLinecap:l},...null!=o&&{strokeOpacity:o}}}if("training-base"===d){let e=u.stroke||"#666";return"lighten"===c&&(e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)+(255-parseInt(i[1],16))*t),n=Math.round(parseInt(i[2],16)+(255-parseInt(i[2],16))*t),o=Math.round(parseInt(i[3],16)+(255-parseInt(i[3],16))*t);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}(e,.4)),{...u,stroke:e,strokeDasharray:void 0}}if("forecast"===d){let e=t[Oi]??a;return{...u,stroke:n,strokeDasharray:r,...null!=e&&{strokeOpacity:e}}}return u}}(t=>e.baseLineStyle(t),e.forecast);p=e=>t(e)}}else e.anomaly&&d.push(...ji(e.anomaly));if(e.gapStrategy){if("function"==typeof h){let e=h;o=o.map(t=>({...t,__semiotic_gapGroup:e(t)})),h="__semiotic_gapGroup"}let t="string"==typeof h?h:void 0,i=function(e,t,i,r,n){let o=new Map;for(let t of e){let e=n?String(t[n]??""):"__single";o.has(e)||o.set(e,[]),o.get(e).push(t)}if("interpolate"===t){let e=[];for(let[,t]of o)for(let n of t)Gi(n,i,r)||e.push(n);return{rows:e,groupKey:n}}if("zero"===t){let e=[];for(let[,t]of o)for(let n of t)Gi(n,i,r)?e.push({...n,[r]:0}):e.push(n);return{rows:e,groupKey:n}}let a=[],s="_gapSegment";for(let[e,t]of o){let n=0,o=[],l=()=>{if(0===o.length)return;let t="__single"===e?`__seg${n}`:`${e}__seg${n}`;for(let e of o)a.push({...e,[s]:t});o=[],n++};for(let e of t)Gi(e,i,r)?l():o.push(e);l()}return{rows:a,groupKey:s}}(o,e.gapStrategy,c,u,t);o=i.rows,i.groupKey&&(h=i.groupKey)}if(e.directLabel){let t=function(e,t,i,r,n,o,a,s){if(!t||!i)return{annotations:[]};let l="object"==typeof t?t:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof i?i:e=>e[i],h=ii(e.map(e=>({__lbl:String(d(e)??"")})),"__lbl",o??a),p=function(e,t,i="x",r="y"){let n="function"==typeof i?i:e=>e[i],o="function"==typeof r?r:e=>e[r],a="function"==typeof t.colorBy?t.colorBy:e=>e[t.colorBy],s=new Map;for(let i of e){let e=a(i)??(i.parentLine&&a(i.parentLine));if(null==e||""===String(e))continue;let r=String(e),o=s.get(r);(!o||("end"===t.position?Number(n(i))>Number(n(o)):Number(n(i))<Number(n(o))))&&s.set(r,i)}return[...s].map(([e,a])=>({type:"text",label:e,["string"==typeof i?i:"x"]:n(a),["string"==typeof r?r:"y"]:o(a),x:n(a),y:o(a),_directLabel:{id:e,position:t.position},color:t.color(e),fontSize:t.fontSize}))}(e,{position:c,fontSize:u,colorBy:i,color:e=>h?h(e):s||Ut},r,n),f=p.reduce((e,t)=>Math.max(e,Array.from(String(t.label)).length*(.65*u)),0)+10;return{annotations:p,marginExtra:"end"===c?{right:f}:{left:f}}}(o,e.directLabel,"string"==typeof n||"function"==typeof n?n:void 0,c,u,e.colorScheme,e.themeCategorical,e.color);d.push(...t.annotations),l=t.marginExtra}return{data:o,xAccessor:"function"==typeof t?c:t,yAccessor:"function"==typeof i?u:i,groupAccessor:h,colorAccessor:n,annotations:d,lineStyle:p,yExtent:s,marginExtra:l}}function Hi(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=$i(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrScatterColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrScatterColorBy:t(e)})):o,u=t?ii(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[3,15],p=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],f=p.length?le(p):void 0,g=re(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?ei(e,t,u):"string"==typeof n.color?n.color:Ut,fillOpacity:"number"==typeof n.pointOpacity?n.pointOpacity:.8,r:d?ri(e,d,h,f):"number"==typeof n.pointRadius?n.pointRadius:5};return m?.length&&Object.assign(i,oe(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}var Ui={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Vi({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:$i(r.theme).colors.categorical}),a=vi(o.annotations,n.regression);return{chartType:"scatter",data:o.data,xAccessor:o.xAccessor,yAccessor:o.yAccessor,colorAccessor:t,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,...a&&a.length>0&&{annotations:a},...o.yExtent&&!r.yExtent&&{yExtent:o.yExtent},sizeRange:n.sizeRange||[3,15],pointStyle:r.pointStyle||Hi(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function Zi(e,t,i,r){if(!i.categoryAccessor)return;let n=function(e,t){if(!t)return[];let i=new Set,r=[];for(let n of e){if(!n||"object"!=typeof n)continue;let e="function"==typeof t?t(n):n[t],o=String(e);i.has(o)||(i.add(o),r.push(o))}return r}(e,i.categoryAccessor),o=i.colors,a="explicit-then-alpha"===r?[...Object.keys(o??{}).filter(e=>n.includes(e)),...n.filter(e=>!Object.hasOwn(o??{},e)).sort()]:n,s=$i(t.theme).colors.categorical,l=s?.length?s:Kt;return Object.fromEntries(a.map((e,t)=>[e,o&&ti(o,e)||i.fill||l[t%l.length]]))}var Ki={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=vi(r.annotations,n.regression);return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:i,...r,...o&&{annotations:o},pointStyle:r.pointStyle||Qi(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function Qi(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=$i(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrBubbleColorBy:t(e)})):o,u=t?ii(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[5,40],p=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],f=p.length?le(p):void 0,g=re(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?ei(e,t,u):"string"==typeof n.color?n.color:Ut,fillOpacity:"number"==typeof n.bubbleOpacity?n.bubbleOpacity:.6,r:d?ri(e,d,h,f):h[0],stroke:n.bubbleStrokeColor??"white",strokeWidth:n.bubbleStrokeWidth??1};return m?.length&&Object.assign(i,oe(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}import{useMemo as Ji,useCallback as er,useState as tr,useId as ir,useEffect as rr,useRef as nr}from"react";var or="__semioticSelectionData";function ar(e,t){return t?.length&&Object.defineProperty(e,or,{configurable:!0,enumerable:!1,value:t}),e}function sr(e){return e?.[or]}function lr(e){return e.parentLine?ar({...e.parentLine,...e},sr(e)):e}function cr(e){return ar({...e[0]},e.map(lr))}function ur(e){return!!e&&sr(e)?.[0]===e}var dr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function hr(e){let t=new Date(e instanceof Date?e.valueOf():e);return`${dr[t.getUTCMonth()]} ${t.getUTCDate()}`}function pr(e){let t=Math.abs(e[1]-e[0]);return t<864e5?e=>{let i=new Date(e instanceof Date?e.valueOf():e),r=`${String(i.getUTCHours()).padStart(2,"0")}:${String(i.getUTCMinutes()).padStart(2,"0")}`;return t<3e5&&(r+=`:${String(i.getUTCSeconds()).padStart(2,"0")}`),t<1e4&&(r+=`.${String(i.getUTCMilliseconds()).padStart(3,"0")}`),r}:t<3156e7?hr:t<1578e8?e=>{let t=new Date(e instanceof Date?e.valueOf():e);return`${dr[t.getUTCMonth()]} ${t.getUTCFullYear()}`}:e=>String(new Date(e instanceof Date?e.valueOf():e).getUTCFullYear())}function fr(e,t,i){return"function"==typeof e?e(t,i):t[e]}function gr(e,t){if(!e?.length)return;let i=new Map(t.map((e,t)=>[ht(e),t]));return e.map(e=>{let t={...e},r=r=>{if(!(r in e))return;let n=i.get(ht(e[r]));void 0!==n&&(t[r]=n)};return r("x"),r("x0"),r("x1"),"string"==typeof e.type&&("x-threshold"===e.type||"x"===e.type)&&r("value"),t})}function mr(e){let t="number"==typeof e?e:"string"==typeof e&&""!==e.trim()?Number(e):NaN;return Number.isFinite(t)?Math.max(0,Math.floor(t)):void 0}function yr(e){return"string"==typeof e&&""!==e.trim()?e:void 0}function xr(e,t={}){let i=t.xAccessor??"x",r=t.yAccessor??"y",n=t.lineBy??"series",o=t.rankDirection??"descending",a=[],s=new Map,l=new Map,c=[],u=new Map,d=1/0,h=-1/0;e.forEach((e,t)=>{let o=fr(i,e,t),p=ht(o),f=s.get(p);null==f&&(f=a.length,s.set(p,f),a.push(o),l.set(f,[]));let g=String(fr(n,e,t));u.has(g)||(u.set(g,c.length),c.push(g));let m=Number(fr(r,e,t));Number.isFinite(m)&&(d=Math.min(d,m),h=Math.max(h,m),l.get(f)?.push({datum:e,inputIndex:t,series:g,value:m}))});let p=[],f=new Map,g=new Map;for(let e=0;e<a.length;e++){let t=l.get(e)??[];t.sort((e,t)=>("descending"===o?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,i)=>{let r=i+1;p.push({datum:t.datum,xIndex:e,xValue:a[e],series:t.series,value:t.value,rank:r}),f.set(t.series,(f.get(t.series)??0)+r),g.set(t.series,(g.get(t.series)??0)+1)})}let m=c.length+1,y=[...c].sort((e,t)=>{let i=g.get(e)??0,r=g.get(t)??0;return((f.get(e)??0)+(a.length-i)*m)/Math.max(1,a.length)-((f.get(t)??0)+(a.length-r)*m)/Math.max(1,a.length)||(u.get(e)??0)-(u.get(t)??0)}),x=null==t.highlightTop?y.length:Math.max(0,Math.floor(t.highlightTop)),b=new Set(y.slice(0,x));return{data:p.map(e=>{let t=b.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:a,seriesOrder:c,overallOrder:y,valueExtent:d===1/0?[0,0]:[d,h]}}import*as br from"react";import{jsx as vr}from"react/jsx-runtime";var wr,kr={isActive:!1,predicate:()=>!0};function Sr(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function Ar(e,t,i,r,n){let o=1-n;return 3*o*o*(t-e)+6*o*n*(i-t)+3*n*n*(r-i)}function Mr(e,t,i,r,n){let o=[],a=(e.x+t.x)/2;for(let s=0;s<=n;s++){let l,c,u,d,h=s/n;"linear"===r?(l=e.x+(t.x-e.x)*h,c=e.y+(t.y-e.y)*h,u=t.x-e.x,d=t.y-e.y):(l=Sr(e.x,a,a,t.x,h),c=Sr(e.y,e.y,t.y,t.y,h),u=Ar(e.x,a,a,t.x,h),d=Ar(e.y,e.y,t.y,t.y,h)),o.push({x:l,y:c,dx:u,dy:d,radius:e.radius+(t.radius-e.radius)*h,datumIndex:h<.5?i:i+1})}return o}function $r(e,t){let i=e.length-1,r=Math.sign(e[i][0]-e[t][0])||1,n=r*e[i][0],o=r*e[t][0];for(let a=t+1;a<i;a++){let t=Math.max(o,Math.min(n,r*e[a][0]));e[a][0]=r*t,o=t}for(let r=t;r<i;r++){let t=r;for(;t<i&&e[t+1][0]===e[r][0];)t++;for(let i=r+1;i<t;i++)e[i][1]=e[r][1]+(e[t][1]-e[r][1])*(i-r)/(t-r);r=t}let a=1e-6*(n-r*e[t][0])/(i-t);o=r*e[t][0];for(let s=t+1;s<i;s++){let t=Math.max(o+a,Math.min(r*e[s][0],n-(i-s)*a));e[s][0]=r*t,o=t}}function _r(e,t={}){let i=[],r=[],n=[];if(e.length<2)return{topPath:i,bottomPath:r,datumIndices:n};let o=t.curve??"smooth",a=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;t<e.length-1;t++){let s=Math.max(0,i.length-1),l=Mr(e[t],e[t+1],t,o,a);for(let e=0===t?0:1;e<l.length;e++){let t=l[e],o=Math.hypot(t.dx,t.dy)||1,a=-t.dy/o,s=t.dx/o,c=Math.max(0,t.radius);i.push([t.x+a*c,t.y+s*c]),r.push([t.x-a*c,t.y-s*c]),n.push(t.datumIndex)}$r(i,s),$r(r,s)}return{topPath:i,bottomPath:r,datumIndices:n}}var Pr={top:20,bottom:48,left:48},Ir=[[/[mwMW@%…]/,.95],[/[ijlI'.,|\s]/,.28],[/[frt():;/[\]{}*`!\\-]/,.39]];function Tr(e,t){let i=0;for(let t of e)i+=(t.codePointAt(0)??0)>=11904?1.1:Ir.find(([e])=>e.test(t))?.[1]??(t.toLowerCase()!==t?.75:.62);return i*t*1.05}function Lr(e){let t=e.fontSize??12,i=!0===e.showLabels?"end":e.showLabels,r="end"===i||"both"===i||"auto"===i,n="start"===i||"both"===i,o=e.labels.reduce((e,i)=>Math.max(e,Tr(i,t)),0),a=Math.round(e.width*(e.maxSideFraction??.38)),s=Tr(String(Math.max(1,e.rankCount)),t),l=e.showAxes?8+s+6:8,c={start:l+4+(e.showAxes&&e.yLabel?24:0),end:12},u=e.legendSide?Te({legendGroups:[{label:"",styleFn:()=>({}),items:e.labels.map(e=>({label:e}))}]},{sideGutter:0}):0,d=Tr("MMM",t),h=(t,i)=>Math.min(i+o,e.legendSide===t?Math.max(i+d,a-u):a),p={start:n?h("left",c.start):0,end:r?h("right",c.end):0},f=!1===e.showLabels?24:110;return{margin:{...Pr,right:Math.max(f,p.end),left:Math.max(Pr.left,p.start)},startLabelOffset:l,chrome:c,room:p,labelWidth:o,fontSize:t,hasStart:n,hasEnd:r}}import{jsx as Cr,jsxs as Rr}from"react/jsx-runtime";function Nr({datum:e,x:t,y:i,side:r,color:n,highlighted:o,labelStyle:a,offset:s,budget:l,fontSize:c}){let u=function(){let e=(wr??(wr=br.createContext(null)),wr);return br.useContext(e)??kr}(),d=u.isActive&&!u.predicate(e),h="function"==typeof a?a(e.__bumpRaw):a,p=null==l?{text:e.__bumpSeries,truncated:!1}:function(e,t,i){if(Tr(e,i)<=t)return{text:e,truncated:!1};let r=Array.from(e),n=r.length-1;for(;n>0&&Tr(`${r.slice(0,n).join("")}…`,i)>t;)n--;return{text:`${r.slice(0,n).join("").trimEnd()}…`,truncated:!0}}(e.__bumpSeries,l,c);return Rr("text",{className:"semiotic-bump-label",x:t+("end"===r?s:-s),y:i,dy:"0.35em",textAnchor:"end"===r?"start":"end",fill:n,fillOpacity:d?.16:1,fontWeight:o?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...h},children:[p.truncated&&Cr("title",{children:e.__bumpSeries}),p.text]})}function Dr(e,t,i){let[r,n]=t,[o,a]=i;return n===r?(o+a)/2:o+(a-o)*Math.max(0,Math.min(1,(e-r)/(n-r)))}function Fr(e){let t=e.__bumpXValue instanceof Date?e.__bumpXValue.getTime():Number(e.__bumpXValue);return{value:e.__bumpValue,x:Number.isFinite(t)?t:void 0,y:e.__bumpValue,category:e.__bumpSeries}}function Er(e){let t=e.config,i=new Map;for(let t of e.data){let e=i.get(t.__bumpSeries)??[];e.push(t),i.set(t.__bumpSeries,e)}let r=t.seriesOrder.filter(e=>i.has(e)).sort((e,r)=>(i.get(e)?.[0]?.__bumpHighlighted?1:0)-(i.get(r)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(r)),n=[],o=[],a=[];for(let o of r){let r=(i.get(o)??[]).sort((e,t)=>e.x-t.x);if(r.length<2)continue;let s=r[0].__bumpHighlighted,l=(t.colorMap&&ti(t.colorMap,o))??e.resolveColor(r[0].__bumpSeries,r[0]),c=t.color??(s?l:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??l),u=r.map(i=>({x:e.scales.x(i.x),y:e.scales.y(i.y),radius:t.ribbon?Dr(i.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=_r(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:s?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(h,oe(r[0].__bumpRaw,t.styleRules,Fr(r[0]))),t.areaStyle&&Object.assign(h,t.areaStyle(r[0].__bumpRaw)??{}),void 0!==t.stroke&&(h.stroke=t.stroke),void 0!==t.strokeWidth&&(h.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(h.opacity=t.opacity),n.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,_hitArea:!0,style:h,datum:d.datumIndices.map(e=>r[e]),accessibleDatum:r.map(e=>e.__bumpRaw),accessibility:{label:`${o} ranking trajectory`,tableFields:r.map(e=>e.__bumpRaw)},group:o,interactive:!0}),t.showPoints&&r.forEach((e,i)=>{let r={fill:c,stroke:"none",opacity:s?1:.75};t.styleRules?.length&&Object.assign(r,oe(e.__bumpRaw,t.styleRules,Fr(e))),t.pointStyle&&Object.assign(r,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(r.stroke=t.stroke),void 0!==t.strokeWidth&&(r.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(r.opacity=t.opacity),n.push({type:"point",x:u[i].x,y:u[i].y,r:r.r??t.pointRadius,style:r,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${o}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${o}:${e.x}`})});let p=!0===t.showLabels?"end":t.showLabels,f=(e,i,r)=>{let n=null==t.labelPriorityAccessor?void 0:"function"==typeof t.labelPriorityAccessor?t.labelPriorityAccessor(e.__bumpRaw):Number(e.__bumpRaw[t.labelPriorityAccessor]);a.push({id:`${o}\0${r}`,datum:e,x:u[i].x,y:u[i].y,side:r,rank:e.__bumpRank,highlighted:s,priority:Number.isFinite(n)?n:void 0,color:"string"==typeof h.fill?h.fill:c})};("start"===p||"both"===p)&&f(r[0],0,"start"),("end"===p||"both"===p||"auto"===p)&&f(r.at(-1),r.length-1,"end")}let s=!0===t.showLabels?"end":t.showLabels,l=function(e,t,i,r){let n=Math.max(1,Math.floor(t/18)),o="auto"===i?Number.isFinite(r)&&(r??0)>=0?Math.min(n,Math.floor(r)):n:1/0,a=e.map((e,t)=>({candidate:e,index:t})).sort((e,t)=>{let i=e.candidate.priority??0;return(t.candidate.priority??0)-i||Number(t.candidate.highlighted)-Number(e.candidate.highlighted)||e.candidate.rank-t.candidate.rank||e.index-t.index}),s=[];for(let{candidate:e}of a){if(s.length>=o)break;s.some(t=>t.side===e.side&&Math.abs(t.y-e.y)<14)||s.push(e)}return new Set(s.map(e=>e.id))}(a,e.dimensions.plot.height,"auto"!==s||"auto",t.maxLabels);for(let e of a)l.has(e.id)&&o.push(Cr(Nr,{datum:e.datum,x:e.x,y:e.y,side:e.side,color:e.color,highlighted:e.highlighted,labelStyle:t.labelStyle,offset:"end"===e.side?8:t.startLabelOffset??8,budget:t.labelBudget?.[e.side],fontSize:t.labelFontSize??12},e.id));return{nodes:n,overlays:o.length?Cr("g",{className:"semiotic-bump-labels",children:o}):void 0,restyle:(e,t)=>{let i=function(e){let t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&i&&!t.predicate(i))return{opacity:.14}}}}function Or(e){return Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[]}function zr(e){return{xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineBy:e.lineBy,rankDirection:e.rankDirection,highlightTop:mr(e.highlightTop)}}function Br(e,t,i,r,n,o){let a=t.labelStyle,s=o.position??"right";return{legendSide:!0!==o.show||"left"!==s&&"right"!==s?void 0:s,labels:e,showLabels:t.showLabels??!0,width:i,showAxes:r,rankCount:e.length,yLabel:"string"==typeof n?n:"Rank",fontSize:"object"==typeof a&&"number"==typeof a?.fontSize?a.fontSize:12}}var jr={frameType:"xy",layout:{modeDefaults:{showGrid:!0},margin:(e,t)=>{let{seriesOrder:i}=xr(Or(e.data),zr(e));return Lr(Br(i,e,t.width,t.showAxes,e.yLabel,{show:e.showLegend,position:e.legendPosition})).margin}},buildProps:(e,t,i,r,n)=>{let o=xr(Or(e),zr(n)),[a]=r.size??[600,400],s=Lr(Br(o.seriesOrder,n,a,!1!==r.showAxes,r.yLabel,{show:r.showLegend,position:r.legendPosition})),l=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]),c=r.margin,u={...c,...s.hasEnd&&!l.has("right")&&{right:Math.max(c.right,s.margin.right)},...s.hasStart&&!l.has("left")&&{left:Math.max(c.left,s.margin.left)}},d=function(e,t){let i={start:t.hasStart?Math.max(0,Math.min(e.left,t.room.start)-t.chrome.start):0,end:t.hasEnd?Math.max(0,Math.min(e.right,t.room.end)-t.chrome.end):0};return{budget:i,sideGutter:{...t.hasStart&&{left:t.chrome.start+Math.min(i.start,t.labelWidth)},...t.hasEnd&&{right:t.chrome.end+Math.min(i.end,t.labelWidth)}}}}(u,s),h=r.legendPosition??"right",p=r.legendLayout,f=!0!==r.showLegend||"left"!==h&&"right"!==h?void 0:d.sideGutter[h],g=Math.max(1,o.seriesOrder.length),m=$i(r.theme),y=function(e){let{seriesOrder:t,overallOrder:i,highlightTop:r,color:n,colorScheme:o,neutralColor:a,themeCategorical:s,themeNeutral:l}=e;if(null==r&&null==n)return o;let c="string"==typeof o?[...Zt(o,s)]:o,u=null==r?i.length:Math.max(0,Math.floor(r)),d=new Set(i.slice(0,u)),h=new Map,p={};for(let e of t)Object.defineProperty(p,e,{configurable:!0,enumerable:!0,writable:!0,value:n??(d.has(e)?ni(void 0,s,c,e,h):a??l??"#b8bec8")});return p}({seriesOrder:o.seriesOrder,overallOrder:o.overallOrder,highlightTop:mr(n.highlightTop),color:yr(n.color),colorScheme:i,neutralColor:yr(n.neutralColor),themeCategorical:m.colors.categorical,themeNeutral:m.colors.textSecondary}),x={ribbon:!0===n.ribbon,curve:"linear"===n.curve?"linear":"smooth",samplesPerSegment:"number"==typeof n.samplesPerSegment?n.samplesPerSegment:12,ribbonSizeRange:Array.isArray(n.ribbonSizeRange)?n.ribbonSizeRange:[4,28],valueExtent:o.valueExtent,seriesOrder:o.seriesOrder,lineWidth:"number"==typeof n.lineWidth?n.lineWidth:3,ribbonOpacity:"number"==typeof n.ribbonOpacity?n.ribbonOpacity:.82,lineOpacity:"number"==typeof n.lineOpacity?n.lineOpacity:.9,neutralColor:yr(n.neutralColor),color:yr(n.color),colorMap:y&&"object"==typeof y&&!Array.isArray(y)?y:void 0,stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0,styleRules:n.styleRules,areaStyle:r.areaStyle,pointStyle:r.pointStyle,labelStyle:n.labelStyle,showPoints:!0===n.showPoints,pointRadius:"number"==typeof n.pointRadius?n.pointRadius:3,showLabels:n.showLabels??!0,labelPriorityAccessor:n.labelPriorityAccessor,maxLabels:"number"==typeof n.maxLabels?n.maxLabels:void 0,startLabelOffset:s.startLabelOffset,labelBudget:d.budget,labelFontSize:s.fontSize},b=function(e,t){let i=t=>e[Math.max(0,Math.min(e.length-1,Math.round(Number(t))))],r=e.every(e=>"number"==typeof e||e instanceof Date),n=t?void 0:function(e){let t=e.filter(e=>e instanceof Date&&Number.isFinite(e.valueOf()));if(0===t.length)return;let i=t.every(e=>e.valueOf()%864e5==0),r=i&&t.every(e=>1===e.getUTCDate());if(r&&t.every(e=>0===e.getUTCMonth()))return e=>String(e.getUTCFullYear());if(r)return e=>`${hr(e).split(" ")[0]} ${e.getUTCFullYear()}`;let n=t.map(e=>e.valueOf()),o=le(n);if(i){let e=new Date(o[0]).getUTCFullYear()===new Date(o[1]).getUTCFullYear();return t=>e?hr(t):`${hr(t)}, ${t.getUTCFullYear()}`}return pr(o)}(e);return(o,a,s)=>{if(0===e.length)return"";let l=i(o);return t?t(l,a,s&&r?s.map(e=>Number(i(e).valueOf())):void 0):l instanceof Date&&n?n(l):String(l)}}(o.xValues,r.xFormat),v=o.xValues.map((e,t)=>t),w=Array.from({length:g},(e,t)=>t+1),k=r.axes??[{orient:"left",tickValues:w,tickFormat:e=>String(e),label:r.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:v,tickFormat:b,label:r.xLabel,tickAnchor:"edges"}];return{...r,margin:u,...null!=f&&null==p?.sideGutter&&{legendLayout:{...p,sideGutter:f}},chartType:"custom",data:o.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,o.xValues.length-1)],yExtent:[g+.5,.5],customLayout:Er,layoutConfig:x,colorAccessor:"__bumpSeries",colorScheme:y,xFormat:b,axes:k,axisExtent:"exact",showAxes:r.showAxes??!0,showLegend:r.showLegend??!1,annotations:gr(r.annotations,o.xValues)}}},Wr="__ma_unitized",Yr="__ma_series";function qr(e,t){let i=ie(e),r=t.map((e,t)=>({label:e.label||`Series ${t+1}`,readY:ie(e.yAccessor)}));return(e,t)=>{let n=String(e[Yr]??t??""),o=(r.find(e=>e.label===n)??r[0])?.readY(e);return{value:o,x:i(e),y:o,category:n||void 0}}}var Xr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Array.isArray(n.series)?n.series:[],s=function(e,t,i){let r=Zt(t,i,Ht),n=t&&"object"==typeof t&&!Array.isArray(t)?t:null;return e.map((e,t)=>{if("string"==typeof e.color&&e.color.length>0)return e.color;let i=e.label||`Series ${t+1}`,o=n?.[i];return"string"==typeof o&&o.length>0?o:r[t%r.length]})}(a,i,$i(r.theme).colors.categorical),l=2===a.length,c=a.map(e=>e.extent||function(e,t){let i="function"==typeof t?t:e=>Number(e[t||"y"]),r=1/0,n=-1/0;for(let t of e){let e=i(t);"number"==typeof e&&Number.isFinite(e)&&(e<r&&(r=e),e>n&&(n=e))}if(!Number.isFinite(r)||!Number.isFinite(n))return[0,1];if(r===n){let e=0===r?1:.1*Math.abs(r);return[r-e,n+e]}return[r,n]}(o,e.yAccessor)),u=[];for(let e of o)a.forEach((t,i)=>{let r=("function"==typeof t.yAccessor?t.yAccessor:e=>e[t.yAccessor])(e);if(null==r||!Number.isFinite(Number(r)))return;let n=Number(r),o=c[i],a=o[1]-o[0]||1;u.push({...e,[Wr]:l?(n-o[0])/a:n,[Yr]:t.label||`Series ${i+1}`})});let d=(e,t)=>i=>{let r=e[0]+i*(e[1]-e[0]);return"function"==typeof t?t(r):Number.isInteger(r)?String(r):r.toFixed(1)},h=l?[{orient:"left",label:a[0].label,tickFormat:d(c[0],a[0].format)},{orient:"right",label:a[1].label,tickFormat:d(c[1],a[1].format)},{orient:"bottom"}]:void 0,p=new Map;a.forEach((e,t)=>{p.set(e.label||`Series ${t+1}`,s[t])});let f=ai(si({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,resolveStroke:e=>p.get(String(e[Yr]??""))||s[0],styleRules:n.styleRules,ruleContext:qr(n.xAccessor,a)}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0});return{chartType:"line",data:u,xAccessor:n.xAccessor||"x",yAccessor:Wr,groupAccessor:Yr,colorAccessor:Yr,...h&&{axes:h},...l&&{yExtent:[0,1]},...r,curve:n.curve||r.curve||"monotoneX",showLegend:r.showLegend??!0,colorScheme:s,lineStyle:f}}},Gr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.xAccessor||"x",s="function"==typeof a?a:e=>e[a],l=o.some(e=>{let t=s(e);return!("number"==typeof t&&Number.isFinite(t)||t instanceof Date)}),c=l?o.map((e,t)=>({...e,__waterfallX:t,__waterfallTick:String(s(e)??t)})):o,u=n.styleRules?ae(void 0,n.styleRules,re(n.xAccessor,n.yAccessor)):void 0,d=u?e=>{let t=u(e),i="function"==typeof r.areaStyle?r.areaStyle(e):r.areaStyle;return i?{...t,...i}:t}:void 0;return{chartType:"waterfall",data:c,xAccessor:l?"__waterfallX":a,yAccessor:n.yAccessor||"y",waterfallStyle:{positiveColor:n.positiveColor,negativeColor:n.negativeColor,connectorStroke:n.connectorStroke,connectorWidth:n.connectorWidth,gap:n.gap,stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity},...r,...d&&{areaStyle:d},...l&&{axes:r.axes??[{orient:"bottom",tickValues:c.map((e,t)=>t)}],xFormat:e=>{let t=o[Number(e)]?s(o[Number(e)]):e,i=n.xFormat??r.xFormat;return"function"==typeof i?i(t):String(t??e)}}}}};function Vr(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=$i(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrAreaColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrAreaColorBy:t(e)})):o,u=t?ii(c,l,s):void 0,d=!1!==n.showLine,h="number"==typeof n.lineWidth?n.lineWidth:2,p="number"==typeof n.areaOpacity?n.areaOpacity:.7,f=ie(n.yAccessor),g=n.styleRules;return(e,i)=>{let r=t&&u?ei(e,t,u):"string"==typeof n.color?n.color:Ut,o={fill:r,fillOpacity:p,stroke:d?r:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(o,oe(e,g,{value:f(e),category:i})),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}function Hr(e,t,i,r,n){if(!n.showPoints)return;let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=$i(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrPointColorBy:t(e)})):o,u=t?ii(c,l,s):void 0,d="number"==typeof n.pointRadius?n.pointRadius:3;return e=>{let i=t&&u?ei(e,t,u):"string"==typeof n.color?n.color:Ut;return{r:d,fill:i,stroke:"none"}}}var Ur={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.lineBy,a=n.fillArea,s=Array.isArray(a)?"mixed":a?"area":"line",l=$i(r.theme).colors.categorical,c=function(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=$i(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrLineColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrLineColorBy:t(e)})):o,u=t?ii(c,l,s):void 0,d=re(n.xAccessor,n.yAccessor);return ai(si({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof n.color?n.color:void 0,fillArea:n.fillArea,areaOpacity:"number"==typeof n.areaOpacity?n.areaOpacity:.3,styleRules:n.styleRules,ruleContext:d}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0})}(e,o,i,r,n),u=Vi({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.lineBy,colorBy:o,colorScheme:i,color:"string"==typeof n.color?n.color:void 0,forecast:n.forecast,anomaly:n.anomaly,gapStrategy:n.gapStrategy,directLabel:n.directLabel,annotations:r.annotations,themeCategorical:l,baseLineStyle:c}),d=r.pointStyle||Hr(u.data,u.colorAccessor,i,r,n),h=r.margin,p=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]);u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&!p.has("right")&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&!p.has("left")&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});let f=(!n.directLabel||void 0!==r.showLegend)&&(r.showLegend??!!u.colorAccessor);return{chartType:s,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:i,lineStyle:u.lineStyle||c,...Array.isArray(a)&&{areaGroups:a},...a&&null!=n.areaOpacity&&{areaOpacity:n.areaOpacity},...null!=n.band&&{band:n.band},...r,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!r.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},Zr={frameType:"xy",layout:{margin:(e,t)=>function(e,t,i,r=!1){let n=Pe({axes:t,showAxes:i});return{...De(e,t,r),...!n.hasAxis&&{bottom:0},...!n.leftAxis?.hasAxis&&{left:0}}}(t.marginDefaults,Pi(e),t.showAxes,!!t.title)},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?Mt(e):[],a=n.timeAccessor||"time",s=n.valueAccessor||"value",l=n.categoryAccessor,c=Zi(o,r,n,"explicit-then-alpha"),u=n.valueExtent||r.yExtent,d={...bi(n),...void 0!==n.cursor&&{cursor:n.cursor}},h={...d,...void 0!==n.fill&&{fill:n.fill},...void 0!==n.gap&&{gap:n.gap},...Array.isArray(n.valueBands)&&{valueBands:n.valueBands}},p=ae(void 0,n.styleRules,e=>{let t=e.categoryValue??e.total,i="number"==typeof t&&Number.isFinite(t)?t:void 0,r=Number(e.binStart),n=Number(e.binEnd);return{value:i,x:Number.isFinite(r)&&Number.isFinite(n)?(r+n)/2:void 0,y:i,category:null==e.category?void 0:String(e.category)}});return{chartType:"bar",data:o,...r,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,o.length),arrowOfTime:n.arrowOfTime||"right",timeAccessor:e=>kt(e,a,"time")??NaN,valueAccessor:e=>wt(e,s,"value")??NaN,xExtent:n.timeExtent||r.xExtent,yExtent:u,invertY:"down"===n.direction,axes:Pi({...n,axes:r.axes??n.axes}),extentPadding:n.extentPadding??r.extentPadding,binSize:n.binSize,binAlign:n.binAlign,categoryAccessor:l,barColors:c||r.barColors,colorScheme:c||r.colorScheme,barStyle:r.barStyle||h,areaStyle:r.areaStyle||(e=>({...p(e),...!l&&void 0!==n.fill&&{fill:n.fill},...d})),showLegend:r.showLegend??!!l}}},Kr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a=Vi({data:Array.isArray(e)?Mt(e):[],xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.areaBy,forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:$i(r.theme).colors.categorical}),s=function({data:e,safeData:t,areaBy:i,lineDataAccessor:r}){if(null==e)return[];let n,o=void 0!==t[0]?.[r];if(!o&&!i)return t;if(o)n=t;else{let e=t.reduce((e,t)=>{let n="function"==typeof i?i(t):t[i],o=String(n);if(!e[o]){let t={[r]:[]};"string"==typeof i&&(t[i]=n),e[o]=t}return e[o][r].push(t),e},{});n=Object.values(e)}return n.flatMap(e=>{let t=Array.isArray(e[r])?e[r]:[];return"string"==typeof i?t.map(t=>({...t,[i]:t[i]??e[i]})):t})}({data:e,safeData:a.data,areaBy:n.areaBy,lineDataAccessor:n.lineDataAccessor||"coordinates"}),l=function(e){if(e)return Array.isArray(e)?{stops:e.map(({at:e,color:t,opacity:i})=>({offset:e/100,color:t,...null!=i&&{opacity:i}}))}:Array.isArray(e.stops)?e:void 0}(n.semanticGradient),c=l?.stops.length?function(e){return{...gi(e),extent:"domain"}}(l):pi(r.gradientFill),u=!1!==n.semanticLine?function(e){let t=e?.stops.filter(e=>"string"==typeof e.color&&Number.isFinite(e.offset)).map(({offset:e,color:t,opacity:i})=>({offset:Math.max(0,Math.min(1,e)),color:t,...Number.isFinite(i)&&{opacity:Math.max(0,Math.min(1,i))}})).sort((e,t)=>e.offset-t.offset);if(!t?.length)return;let i=t[0];return i.offset>0?[{...i,offset:0},...t]:t}(l):void 0,d=r.pointStyle||Hr(s,o,i,r,n);return{chartType:"area",data:s,xAccessor:a.xAccessor,yAccessor:a.yAccessor,y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||void 0,colorAccessor:o,colorScheme:i,...r,...a.annotations.length>0&&{annotations:a.annotations},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:r.lineStyle||Vr(s,o,i,r,n),...d&&{pointStyle:d}}}},Qr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xAccessor||"x",a=n.seriesAAccessor||"a",s=n.seriesBAccessor||"b",l=e=>yi(mi(o,"x",e)),c=e=>yi(mi(a,"a",e)),u=e=>yi(mi(s,"b",e)),d=n.seriesAColor||"var(--semiotic-danger, #dc2626)",h=n.seriesBColor||"var(--semiotic-info, #2563eb)",p=n.areaOpacity??.6,f=n.lineWidth??1.5,g=!1!==n.showLines,m=!1!==r.showLegend,y=n.seriesALabel||"A",x=n.seriesBLabel||"B",b=r.legendPosition||"right",v=function(e,t,i,r){if(!e.length)return[];let n=e.filter(e=>Number.isFinite(t(e))).sort((e,i)=>t(e)-t(i)),o=[],a=0,s=null,l=null,c=[],u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${a}-${e}`,h=e=>o.push(e),p=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;e<n.length;e++){let o=n[e],f=t(o),g=i(o),m=r(o);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(m))continue;let y=u(g,m);if(null!==y){if(null==s){s=y;for(let e of c)p(e,s);c=[],h({__x:f,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:f,a:g,b:m,w:y};continue}if(l&&l.w!==y){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{let i=g-l.a-(m-l.b);if(0!==i){let r=(l.b-l.a)/i,n=Math.max(0,Math.min(1,r));e=l.x+n*(f-l.x),t=l.a+n*(g-l.a)}else e=l.x,t=l.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t}),a++,s=y,h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t});for(let e=1;e<c.length;e++)p(c[e],s)}else for(let e of c)p(e,s);c=[],h({__x:f,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:f,a:g,b:m,w:y}}else c.push({x:f,y:g,datum:o})}for(let e of c)p(e,s??"A");return o}(Array.isArray(e)?e:[],l,c,u),w=[];if(g&&Array.isArray(e)){let t=e.filter(e=>Number.isFinite(l(e))).sort((e,t)=>l(e)-l(t));for(let e of t){let t=l(e),i=c(e),r=u(e);Number.isFinite(i)&&w.push({__x:t,__y:i,__diffSegment:"line-A",__diffWinner:"A",__sourceDatum:e}),Number.isFinite(r)&&w.push({__x:t,__y:r,__diffSegment:"line-B",__diffWinner:"B",__sourceDatum:e})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:ui({seriesAColor:d,seriesBColor:h,areaOpacity:p,styleRules:n.styleRules}),lineStyle:di({seriesAColor:d,seriesBColor:h,lineWidth:f,styleRules:n.styleRules}),curve:n.curve||"linear",...r,...m&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:y,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Jr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a="string"==typeof o&&Array.isArray(e)?ii(e,o,i):void 0,s="number"==typeof n.areaOpacity?n.areaOpacity:.7,l=r.lineStyle||(e=>{let t=null==o?void 0:ei(e,o,a),i=n.showLine??!0,r=n.stroke??t,l=n.strokeWidth??n.lineWidth??2,c={fill:n.color??t,stroke:i?r:"none",...i?{strokeWidth:l}:{},fillOpacity:s,...null==n.opacity?{}:{opacity:n.opacity}},u=n.styleRules;if(u?.length){let t=ie(n.yAccessor),i=o?String("function"==typeof o?o(e)??"":e[o]??""):void 0;Object.assign(c,oe(e,u,{value:t(e),category:i}))}return c}),c=n.normalize?"zero":n.baseline??"zero",u=r.pointStyle||Hr(e,o,i,r,n);return{chartType:"stackedarea",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:o,colorScheme:i,normalize:n.normalize,baseline:c,stackOrder:n.stackOrder,lineStyle:l,...r,...u&&{pointStyle:u},curve:r.curve??n.curve??"monotoneX",showLegend:r.showLegend??!!o}}},en={frameType:"xy",buildProps:(e,t,i,r,n)=>{let[o]=r.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...r,...!r.pointStyle&&Array.isArray(n.styleRules)&&n.styleRules.length>0&&{pointStyle:ae(void 0,n.styleRules,re(n.xAccessor||"x",n.closeAccessor||n.highAccessor||"high"))},scalePadding:r.scalePadding??Math.max(2,Math.min(12,Math.round(o/40))),extentPadding:r.extentPadding??(o<=200?.02:.1)}}},tn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xCenter,a=n.yCenter,s=n.quadrants,l=n.centerlineStyle||{},c=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,f=St.createElement,g=s?[(e,t,i)=>{if(!t?.x||!t?.y)return null;let r=i.width,n=i.height,l=null!=o?t.x(o):r/2,g=null!=a?t.y(a):n/2;if(null!=o&&!Number.isFinite(l)||null!=a&&!Number.isFinite(g))return null;let m=Math.max(0,Math.min(r,l)),y=Math.max(0,Math.min(n,g)),x=[{c:s.topLeft,x:0,y:0,w:m,h:y},{c:s.topRight,x:m,y:0,w:r-m,h:y},{c:s.bottomLeft,x:0,y:y,w:m,h:n-y},{c:s.bottomRight,x:m,y:y,w:r-m,h:n-y}],b=c?[f("text",{key:"ltl",x:8,y:8+u,fill:s.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.topLeft.label),f("text",{key:"ltr",x:r-8,y:8+u,fill:s.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.topRight.label),f("text",{key:"lbl",x:8,y:n-8,fill:s.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.bottomLeft.label),f("text",{key:"lbr",x:r-8,y:n-8,fill:s.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.bottomRight.label)]:[];return f(St.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?f("rect",{key:`qf-${t}`,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),f("line",{key:"vc",x1:m,y1:0,x2:m,y2:n,stroke:d,strokeWidth:h,strokeDasharray:p}),f("line",{key:"hc",x1:0,y1:y,x2:r,y2:y,stroke:d,strokeWidth:h,strokeDasharray:p}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[3,15],colorScheme:i,pointStyle:r.pointStyle||n.pointStyle||Hi(e,t,i,r,n),...r,showLegend:r.showLegend??!!t,...g&&{svgPreRenderers:g}}}},rn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};let i=t.xAccessor||"x",r=t.yAccessor||"y",n=t.orderAccessor?[...e].sort((e,i)=>null==e||"object"!=typeof e?1:null==i||"object"!=typeof i?-1:yi(mi(t.orderAccessor,"order",e))-yi(mi(t.orderAccessor,"order",i))):e,o=new WeakMap,a=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=yi(mi(i,"x",e)),n=yi(mi(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&a++}let s=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=yi(mi(i,"x",e)),n=yi(mi(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&o.set(e,{idx:s++,total:a})}return{data:n,orderMap:o}}(e,n),a=Vi({data:o.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:$i(r.theme).colors.categorical}),s=vi(a.annotations,n.regression),l=n.pointRadius??4,c=re(n.xAccessor,n.yAccessor),u=n.styleRules,d=[e=>{let t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(t.length<2)return null;let i=[];for(let e=0;e<t.length-1;e++){let r=t[e],n=t[e+1],o=xi(e,t.length);t.length<100&&i.push(St.createElement("line",{key:`halo-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),i.push(St.createElement("line",{key:`segment-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:o,strokeWidth:l,strokeLinecap:"round"}))}return St.createElement(St.Fragment,null,...i)}];return{chartType:"scatter",data:a.data,xAccessor:a.xAccessor,yAccessor:a.yAccessor,colorAccessor:t,colorScheme:i,pointStyle:ai(e=>{let t=o.orderMap.get(e),i=t?.idx??0,r=t?.total??1,n={fill:r>0?xi(i,r):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(n,oe(e,u,c(e))),n},bi(n)),...r,...s&&s.length>0&&{annotations:s},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},svgPreRenderers:d}}};function nn(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}var on={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:void 0,a=Number.isFinite(n.cellBorderWidth)?Math.max(0,n.cellBorderWidth):1,s=ae(()=>({stroke:n.cellBorderColor??"#fff",strokeWidth:a}),n.styleRules,function(e,t,i){let r=ie(e),n=ie(t),o=ie(i);return e=>{let t="string"==typeof e.agg&&"number"==typeof e.count&&"number"==typeof e.xCenter&&"number"==typeof e.yCenter;return{value:t?nn(e.value):o(e),x:t?nn(e.xCenter):r(e),y:t?nn(e.yCenter):n(e)}}}(n.xAccessor,n.yAccessor,n.valueAccessor)),l=("string"==typeof o?.colorScheme?o.colorScheme:void 0)??i,c=null!=o&&Object.hasOwn(o,"heatmapColorScale"),u=o?.heatmapColorScale,d=c?"function"==typeof u?u:void 0:"custom"===l&&"function"==typeof n.customColorScale?n.customColorScale:void 0;return{chartType:"heatmap",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,showValues:n.showValues,heatmapValueFormat:n.valueFormat,...n.heatmapAggregation&&{heatmapAggregation:n.heatmapAggregation},...null!=n.heatmapXBins&&{heatmapXBins:n.heatmapXBins},...null!=n.heatmapYBins&&{heatmapYBins:n.heatmapYBins},areaStyle:s,...r,...void 0!==l&&{colorScheme:l},...d&&{heatmapColorScale:d}}}};import*as an from"react";import{renderToStaticMarkup as sn}from"react-dom/server";function ln(e){return"string"==typeof e||"number"==typeof e?String(e):Array.isArray(e)?e.map(ln).join(""):an.isValidElement(e)?"string"!=typeof e.type&&e.type!==an.Fragment?ze(sn(e).replace(/<!--[\s\S]*?-->|<(?:[^<>"']|"[^"]*"|'[^']*')*>/g,"")):ln(e.props.children):""}function cn(e){return"string"==typeof e||"number"==typeof e?e:Array.isArray(e)?e.map((e,t)=>an.createElement(an.Fragment,{key:t},cn(e))):!an.isValidElement(e)||"tspan"!==e.type&&e.type!==an.Fragment?ln(e):an.cloneElement(e,void 0,cn(e.props.children))}import*as un from"react-dom/server";import*as dn from"react";import*as hn from"react-dom/server";function pn(e,t,i="start"){let r="center"===i?t/2:0;return Math.floor((e+r)/t)*t-r}function fn(e,t,i,r,n,o=!1,a="start"){let s=new Map;for(let l of e){let e=t(l),c=i(l);if(null==e||null==c||Number.isNaN(e)||Number.isNaN(c))continue;let u=pn(e,r,a),d=s.get(u);if(d||(d={start:u,end:u+r,total:0,categories:new Map,...o?{rows:[],categoryRows:new Map}:{}},s.set(u,d)),d.total+=c,d.rows?.push(l),n){let e=n(l);if(d.categories.set(e,(d.categories.get(e)||0)+c),d.categoryRows){let t=d.categoryRows.get(e);t||(t=[],d.categoryRows.set(e,t)),t.push(l)}}}return s}var gn=class{constructor(e){if(this._capacity=e,this.head=0,this._size=0,e<1)throw new Error("RingBuffer capacity must be at least 1");this.buffer=new Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){let t=[];for(let i of e){let e=this.push(i);void 0!==e&&t.push(e)}return t}get(e){if(e<0||e>=this._size)return;let t=(this.head-this._size+e+this._capacity)%this._capacity;return this.buffer[t]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let e=0;return{next:()=>e>=this._size?{done:!0,value:void 0}:{done:!1,value:this.get(e++)}}}forEach(e){let t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e(this.buffer[(t+i)%this._capacity],i)}toArray(){let e=new Array(this._size),t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e[i]=this.buffer[(t+i)%this._capacity];return e}resize(e){if(e<1)throw new Error("RingBuffer capacity must be at least 1");let t=this.toArray(),i=0,r=[];t.length>e&&(i=t.length-e,r=t.slice(0,i)),this._capacity=e,this.buffer=new Array(e),this.head=0,this._size=0;for(let e=i;e<t.length;e++)this.push(t[e]);return r}update(e,t){let i=[],r=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;n<this._size;n++){let o=(r+n)%this._capacity,a=this.buffer[o];if(e(a)){let e;e="object"!=typeof a||null===a?a:Array.isArray(a)?[...a]:{...a},i.push(e),this.buffer[o]=t(a)}}return i}remove(e){let t=[],i=[];if(this.forEach(r=>{e(r)?i.push(r):t.push(r)}),0===i.length)return i;this.buffer=new Array(this._capacity),this.head=0,this._size=0;for(let e of t)this.push(e);return i}clear(){this.buffer=new Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},mn=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}evict(e){(e===this._min||e===this._max)&&(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(let i of e){let e=t?t(i):i;Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function yn(e){return new Set(Array.isArray(e)?e:[e])}function xn(e,t,i){if(i<=1)return 1;let r=i-1;return function(e){let t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||e.extent<=0)return 1;let i=Math.max(0,e.age);if("step"===e.type)return i<(e.threshold??.5*e.extent)?1:t;if("exponential"===e.type){let r=e.halfLife??e.extent/2,n=r>0?r:e.extent/2;return t+Math.pow(.5,i/n)*(1-t)}return t+Math.max(0,Math.min(1,1-i/e.extent))*(1-t)}({age:r-t,extent:r,type:e.type,halfLife:e.halfLife??i/2,threshold:e.stepThreshold??.5*i,minOpacity:e.minOpacity??.1})}function bn(e){let t=new Map;for(let i=0;i<e.length;i++)t.set(e[i],i);return t}function vn(e,t,i){let r=e.duration??500,n=i-t;return n>=r?0:1-n/r}function wn(e,t,i,r){let n=!1;return t>0?(e._pulseIntensity!==t&&(e._pulseIntensity=t,n=!0),e._pulseColor!==i&&(e._pulseColor=i,n=!0),e._pulseGlowRadius!==r&&(e._pulseGlowRadius=r,n=!0),n):(0!==e._pulseIntensity&&(e._pulseIntensity=0,n=!0),void 0!==e._pulseColor&&(e._pulseColor=void 0,n=!0),void 0!==e._pulseGlowRadius&&(e._pulseGlowRadius=void 0,n=!0),n)}function kn(e,t,i=(typeof performance<"u"?performance.now():Date.now())){if(!t||0===t.size)return!1;let r=e.duration??500,n=t.peek();return null!=n&&i-n<r}var Sn=null;function An(){return Sn}var Mn=/*#__PURE__*/Object.create(null);function $n(e){Mn[e.chartType]=e}function _n(e){return Mn[e]}var Pn=typeof window>"u"||typeof document>"u",In=/*#__PURE__*/new Set;function Tn(e){if("production"===process.env.NODE_ENV)return;let{label:t,nodes:i,overlays:r,warned:n}=e;Ln(r)&&0===i.length&&Cn(n,"overlay-only",`[semiotic] ${t} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),i.length>0&&i.every(e=>null==e.datum)&&Cn(n,"null-datums",`[semiotic] ${t} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Ln(e){return null!=e&&!1!==e&&""!==e&&(!Array.isArray(e)||e.some(Ln))}function Cn(e,t,i){e.has(t)||(e.add(t),console.warn(i))}function Rn(e){try{return{kind:"success",result:e.run()}}catch(t){let i=e.hasPreviousResult,r=function(e,t,i,r){let n=function(e){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Custom layout threw."};if("string"==typeof e)return{name:"Error",message:e};if(null==e)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:String(e)}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(t),o="network"===e?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:e,source:o,message:`Semiotic ${e} ${o} failed: ${n.message}`,error:n,recovery:i?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:i,affectedRevision:r}}(e.family,t,i,e.revision);"production"!==process.env.NODE_ENV&&console.error(`[semiotic] ${e.logLabel} threw:`,t);try{e.onLayoutError?.(r)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return{kind:"failure",diagnostic:r,preservedLastGoodScene:i}}}function Nn(e,t){let i="function"==typeof e?e:i=>i[e||t];return e=>{let t=i(e);return null==t?Number.NaN:+t}}function Dn(e){let t=[],i=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode,r=Nn(i&&e.valueAccessor||e.yAccessor,i?"value":"y");if(e.boundsAccessor){let i=X(e.boundsAccessor,"bounds");t.push({kind:"bounds",getTop:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t+n:t},getBottom:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t-n:t},style:e.boundsStyle,perSeries:!0,interactive:!1})}if(e.band){let i=Array.isArray(e.band)?e.band:[e.band];for(let e of i)t.push({kind:"band",getTop:Nn(e.y1Accessor,"y1"),getBottom:Nn(e.y0Accessor,"y0"),style:e.style,perSeries:!1!==e.perSeries,interactive:!0===e.interactive})}return t}import{scaleLinear as Fn,scaleLog as En,scaleSymlog as On,scaleTime as zn,scaleUtc as Bn}from"d3-scale";function jn(e,t,i,r,n,o){let a=[];for(let o of e){let e=i(o),s=r(o),l=n?n(o):0;if(!Number.isFinite(e)||!Number.isFinite(s)||!Number.isFinite(l))continue;let c=t.x(e),u=t.y(s),d=n?t.y(l):0;!Number.isFinite(c)||!Number.isFinite(u)||!Number.isFinite(d)||a.push({x:c,y:u,bottom:d,raw:s,datum:o})}a.sort((e,t)=>e.x-t.x);let s=new Array(a.length),l=n?new Array(a.length):[],c=new Array(a.length),u=new Array(a.length),d=o?new Array(a.length):void 0;for(let e=0;e<a.length;e++){let t=a[e];s[e]=[t.x,t.y],n&&(l[e]=[t.x,t.bottom]),c[e]=t.raw,u[e]=t.datum,d&&o&&(d[e]=String(o(t.datum)))}return d?{topPath:s,bottomPath:l,rawValues:c,datum:u,pathIds:d}:{topPath:s,bottomPath:l,rawValues:c,datum:u}}function Wn(e,t,i,r,n,o,a){let{topPath:s,rawValues:l,datum:c,pathIds:u}=jn(e,t,i,r,void 0,a),d={type:"line",path:s,rawValues:l,style:n,datum:c,group:o};return u&&(d.pathIds=u),d}function Yn(e,t,i,r,n,o,a,s,l){return{type:"area",...jn(e,t,i,r,s??(()=>n),l),style:o,group:a}}function qn(e,t,i,r){let n=new Map;if("silhouette"===r)for(let r of e){let e=0;for(let n of t)e+=i(n,r)||0;n.set(r,-e/2)}else if("wiggle"===r){e.length>0&&n.set(e[0],0);for(let r=1;r<e.length;r++){let o=e[r-1],a=e[r],s=0,l=0,c=0;for(let e of t){let t=i(e,a)||0;s+=(2*c+t)*(t-(i(e,o)||0)),l+=t,c+=t}let u=n.get(o)??0,d=l>0?s/(2*l):0;n.set(a,u-d)}if(e.length>0){let r=0;for(let o of e){let e=0;for(let r of t)e+=i(r,o)||0;r+=(n.get(o)??0)+e/2}let o=r/e.length;for(let t of e)n.set(t,(n.get(t)??0)-o)}}else for(let t of e)n.set(t,0);return n}function Xn(e,t,i,r,n,o,a){let s=i(e),l=r(e);if(!Number.isFinite(s)||!Number.isFinite(l))return null;let c={type:"point",x:t.x(s),y:t.y(l),r:n,style:o,datum:e};return void 0!==a&&(c.pointId=a),c}function Gn(e,t,i,r,n,o,a,s){let l=i(e),c=r(e);if(!Number.isFinite(l)||!Number.isFinite(c))return null;let u={type:"symbol",x:t.x(l),y:t.y(c),size:n,symbolType:o,style:a,datum:e};return void 0!==s&&(u.pointId=s),u}function Vn(e,t,i,r,n,o,a){return{type:"rect",x:e,y:t,w:i,h:r,style:n,datum:o,group:a}}function Hn(e,t,i,r,n,o,a){let s={type:"heatcell",x:e,y:t,w:i,h:r,fill:n,datum:o};return void 0!==a?.value&&(s.value=a.value),a?.showValues&&(s.showValues=!0,a.valueFormat&&(s.valueFormat=a.valueFormat)),s}function Un(e,t){return t?[t[0]??e[0],t[1]??e[1]]:e}function Zn(e){let{config:t,groups:i,getX:r,getY:n}=e,o="exact"===(t.yAxisExtent??t.axisExtent),a=o?"exact":"pad",s="log"===t.yScaleType?"log":"lin",l=t.normalize?`${e.bufferSize}:${e.ingestVersion}:norm:${t.stackOrder??"key"}:${a}:${s}`:`${e.bufferSize}:${e.ingestVersion}:${t.baseline??"zero"}:${t.stackOrder??"key"}:${a}:${s}`;if(e.stackExtentCache&&e.stackExtentCache.key===l)return{yDomain:e.stackExtentCache.yDomain,stackExtentCache:e.stackExtentCache};let c=new Map,u=new Set,d=new Map,h=new Map;for(let e of i){let t=new Map,i=0;for(let o of e.data){let e=r(o),a=n(o);if(!Number.isFinite(e)||!Number.isFinite(a))continue;t.set(e,(t.get(e)||0)+a),u.add(e),i+=a;let s=(d.get(e)||0)+a;d.set(e,s)}c.set(e.key,t),h.set(e.key,i)}let p,f=t.stackOrder??"key",g=(e,t)=>e<t?-1:e>t?1:0;if("input"===f)p=i.map(e=>e.key);else if("insideOut"===f){let e=[...i].map(e=>e.key).sort((e,t)=>{let i=(h.get(t)??0)-(h.get(e)??0);return 0!==i?i:g(e,t)}),t=[],r=[],n=0,o=0;for(let i of e)n<o?(t.push(i),n+=h.get(i)??0):(r.push(i),o+=h.get(i)??0);p=[...r.reverse(),...t]}else p="asc"===f?i.map(e=>e.key).sort((e,t)=>{let i=(h.get(e)??0)-(h.get(t)??0);return 0!==i?i:g(e,t)}):"desc"===f?i.map(e=>e.key).sort((e,t)=>{let i=(h.get(t)??0)-(h.get(e)??0);return 0!==i?i:g(e,t)}):i.map(e=>e.key).sort(g);if(t.normalize)for(let e of c.values())for(let[t,i]of e)e.set(t,i/(d.get(t)||1));let m,y=t.normalize?"zero":t.baseline,x="log"===t.yScaleType?[]:null,b=e=>{x&&(x.length>0&&x[x.length-1]===e||x.push(e))},v=e=>{let t={key:l,yDomain:e};return x&&(t.plottedY=x),{yDomain:e,stackExtentCache:t}};if("wiggle"===y||"silhouette"===y){let e=Array.from(u).sort((e,t)=>e-t),i=qn(e,p,(e,t)=>c.get(e)?.get(t)||0,y),r=1/0,n=-1/0,a=e=>{b(e),e<r&&(r=e),e>n&&(n=e)};for(let t of e){let e=i.get(t)??0;a(e);for(let i of p){let r=c.get(i)?.get(t)||0;0!==r&&(e+=r,a(e))}}(!Number.isFinite(r)||!Number.isFinite(n))&&(r=0,n=0);let s=n-r,l=o?0:s>0?s*t.extentPadding:1;return v([r-l,n+l])}if("diverging"===y){let e=Array.from(u).sort((e,t)=>e-t),i=0,r=0,n=e=>{b(e),e<i&&(i=e),e>r&&(r=e)};for(let t of e){let e=0,i=0;for(let r of p){let o=c.get(r)?.get(t)||0;0!==o&&(o>0?(e+=o,n(e)):(i+=o,n(i)))}}let a=r-i,s=o?0:a>0?a*t.extentPadding:1;return v([i-s,r+s])}{let e=Array.from(u).sort((e,t)=>e-t),i=0,r=0;for(let t of e){let e=0;for(let n of p){let o=c.get(n)?.get(t)||0;0!==o&&(e+=o,b(e),e<i&&(i=e),e>r&&(r=e))}}let n=r-i,a=o?0:n>0?n*t.extentPadding:1;return m=t.normalize?[0,o?1:1+t.extentPadding]:[i<0?i-a:0,r+a],v(m)}}function Kn(e,t,i){let r=[],n=0;for(let o of e){let e=i(o),a=t(o);null==e||Number.isNaN(e)||null==a||!isFinite(a)||(n+=e,r.push(n))}return r}function Qn(e,t,i,r){if(e[0]!==1/0&&e[1]!==-1/0)return e;let n=i?.[0],o=i?.[1],a="number"==typeof n&&Number.isFinite(n),s="number"==typeof o&&Number.isFinite(o);return a||s?"log"===r&&a&&!s&&n>0?[n,10*n]:[a?n:s&&o>0?0:t[0],s?o:a&&n>0?0:t[1]]:t}function Jn(e,t,i){let r=e[0]<=e[1],n=r?e[0]:e[1],o=r?e[1]:e[0],a=n>0&&Number.isFinite(n),s=o>0&&Number.isFinite(o);if(a&&s)return e;let l=new Set;if(i)for(let e of i)null!=e&&e>0&&Number.isFinite(e)&&l.add(e);if(!t){if(s&&l.has(o)){let e=o/10;return r?[e,o]:[o,e]}return r?[1,10]:[10,1]}let c=a?n:t.min,u=s?o:t.max;return u>c||(s&&l.has(o)?c=u/10:u=10*c),r?[c,u]:[u,c]}function eo(e){let t=1/0,i=-1/0,r=!1;for(let n of e)if(Number.isFinite(n)){if(!(n>0)){r=!0;continue}n<t&&(t=n),n>i&&(i=n)}return{positive:Number.isFinite(t)?{min:t,max:i}:null,droppedNonPositive:r}}function to(e,t,i){if("log"===e){let e=Jn(t,null);return e[0]===e[1]&&e[0]>0&&Number.isFinite(e[0])&&(e=[e[0],10*e[0]]),En().domain(e).range(i).clamp(!0)}return"symlog"===e?On().domain(t).range(i):"time"===e||"utc"===e?("utc"===e?Bn():zn()).domain([new Date(t[0]),new Date(t[1])]).range(i):Fn().domain(t).range(i)}function io(e,t){return e&&"object"==typeof e&&!Array.isArray(e)?ti(e,t):void 0}function ro(e,t,i){t<=e.capacity||(e.resize(t),i&&t>i.capacity&&i.resize(t))}function no(e,t){let i=new gn(e.capacity);return e.forEach(()=>i.push(t)),i}function oo(e,t,i,r){let n=e.push(t);return i&&i.push(r),n}function ao(e,t,i){if(!t||0===t.size)return;let r=new Set;if(e.forEach((e,t)=>{i(e)&&r.add(t)}),0===r.size)return;let n=t.toArray();t.clear();for(let e=0;e<n.length;e++)r.has(e)||t.push(n[e])}var so=/*#__PURE__*/new WeakMap,lo=class{getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}setLayoutSelection(e){this.config.layoutSelection=e}markStylePaintPending(){so.set(this,!0)}consumeStylePaintPending(){let e=!0===so.get(this);return so.delete(this),e}},co={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function uo(e,t){let i={...e};for(let e of t)i[co[e]]++;return i}function ho(e,t,i){let r=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:r,revisions:uo(i,r)}}var po=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=ho({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){let i=ho(e,t,this.revisions);this.revisions=i.revisions,this.latest=i;for(let e of[...this.listeners])e();return i}},fo=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],go=["scene-style","data-paint","accessibility","evidence"],mo=(e,t)=>({retainedData:e,invalidations:t}),yo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],bo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],vo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wo=["scene-geometry","data-paint","accessibility","evidence"],ko=["scene-style","data-paint","accessibility","evidence"],So=["overlay","accessibility","evidence"],Ao=[],Mo={chartType:/*#__PURE__*/mo("rebuild",yo),runtimeMode:/*#__PURE__*/mo("rebuild",yo),xAccessor:/*#__PURE__*/mo("rebuild",yo),yAccessor:/*#__PURE__*/mo("rebuild",yo),timeAccessor:/*#__PURE__*/mo("rebuild",yo),valueAccessor:/*#__PURE__*/mo("rebuild",yo),y0Accessor:/*#__PURE__*/mo("rebuild",yo),boundsAccessor:/*#__PURE__*/mo("rebuild",yo),band:/*#__PURE__*/mo("rebuild",yo),openAccessor:/*#__PURE__*/mo("rebuild",yo),highAccessor:/*#__PURE__*/mo("rebuild",yo),lowAccessor:/*#__PURE__*/mo("rebuild",yo),closeAccessor:/*#__PURE__*/mo("rebuild",yo),candlestickRangeMode:/*#__PURE__*/mo("rebuild",yo),accessorRevision:/*#__PURE__*/mo("rebuild",yo),groupAccessor:/*#__PURE__*/mo("rebuild",xo),categoryAccessor:/*#__PURE__*/mo("rebuild",xo),lineDataAccessor:/*#__PURE__*/mo("rebuild",xo),colorAccessor:/*#__PURE__*/mo("rebuild",ko),sizeAccessor:/*#__PURE__*/mo("rebuild",wo),symbolAccessor:/*#__PURE__*/mo("rebuild",wo),pointIdAccessor:/*#__PURE__*/mo("rebuild",wo),xScaleType:/*#__PURE__*/mo("preserve",bo),yScaleType:/*#__PURE__*/mo("preserve",bo),xExtent:/*#__PURE__*/mo("preserve",bo),invertY:/*#__PURE__*/mo("preserve",bo),yExtent:/*#__PURE__*/mo("preserve",bo),extentPadding:/*#__PURE__*/mo("preserve",bo),scalePadding:/*#__PURE__*/mo("preserve",bo),axisExtent:/*#__PURE__*/mo("preserve",bo),yAxisExtent:/*#__PURE__*/mo("preserve",bo),binSize:/*#__PURE__*/mo("preserve",bo),binAlign:/*#__PURE__*/mo("preserve",bo),normalize:/*#__PURE__*/mo("preserve",bo),heatmapAggregation:/*#__PURE__*/mo("preserve",bo),heatmapXBins:/*#__PURE__*/mo("preserve",bo),heatmapYBins:/*#__PURE__*/mo("preserve",bo),arrowOfTime:/*#__PURE__*/mo("preserve",vo),baseline:/*#__PURE__*/mo("preserve",vo),stackOrder:/*#__PURE__*/mo("preserve",vo),sizeRange:/*#__PURE__*/mo("preserve",vo),curve:/*#__PURE__*/mo("preserve",vo),areaGroups:/*#__PURE__*/mo("preserve",vo),customLayout:/*#__PURE__*/mo("preserve",vo),layoutConfig:/*#__PURE__*/mo("preserve",vo),layoutMargin:/*#__PURE__*/mo("preserve",vo),symbolMap:/*#__PURE__*/mo("preserve",wo),showValues:/*#__PURE__*/mo("preserve",wo),heatmapValueFormat:/*#__PURE__*/mo("preserve",wo),trackHoverRows:/*#__PURE__*/mo("preserve",wo),lineStyle:/*#__PURE__*/mo("preserve",ko),pointStyle:/*#__PURE__*/mo("preserve",ko),areaStyle:/*#__PURE__*/mo("preserve",ko),barStyle:/*#__PURE__*/mo("preserve",ko),swarmStyle:/*#__PURE__*/mo("preserve",ko),waterfallStyle:/*#__PURE__*/mo("preserve",ko),candlestickStyle:/*#__PURE__*/mo("preserve",ko),boundsStyle:/*#__PURE__*/mo("preserve",ko),gradientFill:/*#__PURE__*/mo("preserve",ko),lineGradient:/*#__PURE__*/mo("preserve",ko),semanticLineStops:/*#__PURE__*/mo("preserve",ko),colorScheme:/*#__PURE__*/mo("preserve",ko),themeCategorical:/*#__PURE__*/mo("preserve",ko),themeSemantic:/*#__PURE__*/mo("preserve",ko),themeSequential:/*#__PURE__*/mo("preserve",ko),themeDiverging:/*#__PURE__*/mo("preserve",ko),barColors:/*#__PURE__*/mo("preserve",ko),decay:/*#__PURE__*/mo("preserve",ko),pulse:/*#__PURE__*/mo("preserve",ko),staleness:/*#__PURE__*/mo("preserve",ko),layoutSelection:/*#__PURE__*/mo("preserve",ko),annotations:/*#__PURE__*/mo("preserve",So),windowSize:/*#__PURE__*/mo("preserve",Ao),windowMode:/*#__PURE__*/mo("preserve",Ao),maxCapacity:/*#__PURE__*/mo("preserve",Ao),clock:/*#__PURE__*/mo("preserve",Ao),transition:/*#__PURE__*/mo("preserve",Ao),introAnimation:/*#__PURE__*/mo("preserve",Ao),onLayoutError:/*#__PURE__*/mo("preserve",Ao)},$o=/*#__PURE__*/mo("preserve",vo),_o=class{constructor(){this.tracker=new po}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},fo)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},go):this.recordNoop("restyle")}recordConfig(e,t=!1){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(Mo,r)?Mo[r]:$o;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t?new Set([...i.invalidations,...wo]):i.invalidations)}};import{quadtree as Po}from"d3-quadtree";var Io=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(e,t){if("scatter"!==e&&"bubble"!==e&&"custom"!==e)return void this.clear();let i=0,r=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(i++,e.r>r&&(r=e.r));if(this.maxRadius=r,i<=500)return void(this.tree=null);let n=new Array(i),o=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(n[o++]=e);this.tree=Po().x(e=>e.x).y(e=>e.y).addAll(n)}},To=class extends lo{constructor(e){super(),this.xExtent=new mn,this.yExtent=new mn,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new _o,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.xTypeDetected=!1,this._warnedNonPositiveLogX=!1,this._warnedNonPositiveLogY=!1,this.spatialIndex=new Io,this._lastBoundedInsertsRef=null,this.applyPulse=(e,t,i)=>!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,n,o=(typeof performance<"u"?performance.now():Date.now())){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1,c=n??(()=>{let e=new Map;for(let t=0;t<i.length;t++)e.set(i[t],t);return e})();for(let i of t){if("line"===i.type)continue;if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[i.datum],n=0,s=!1;for(let i of t){let t=c.get(i);if(null==t)continue;s=!0;let a=r.get(t);if(null==a)continue;let l=vn(e,a,o);l>n&&(n=l)}s&&(l=wn(i,n,a)||l);continue}let t=c.get(i.datum);if(null==t)continue;let n=r.get(t);l=wn(i,null==n?0:vn(e,n,o),a,s)||l}return l}(this.config.pulse,e,t,this.timestampBuffer,this.getDatumIndexMap(t),i),this.config=e,this.buffer=new gn(e.windowSize),this.growingCap=e.windowSize;let t=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode;if(this.resolveXAccessor(),this.getY=t?X(e.valueAccessor||e.yAccessor,"value"):X(e.yAccessor,"y"),this.getGroup=V(e.groupAccessor),this.getCategory=V(e.categoryAccessor),this.getSize=e.sizeAccessor?X(e.sizeAccessor,"size"):void 0,this.getColor=V(e.colorAccessor),this.getSymbol=V(e.symbolAccessor),this.getY0=e.y0Accessor?X(e.y0Accessor,"y0"):void 0,this.resolvedRibbons=Dn(e),this.getPointId=V(e.pointIdAccessor),"candlestick"===e.chartType){let t=null!=e.openAccessor,i=null!=e.closeAccessor;this.getOpen=t?X(e.openAccessor,"open"):void 0,this.getHigh=X(e.highAccessor,"high"),this.getLow=X(e.lowAccessor,"low"),this.getClose=i?X(e.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!i}e.pulse&&(this.timestampBuffer=new gn(e.windowSize))}currentTime(){return this.config.clock?.()??n()}resolveXAccessor(e=this.buffer){let t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=t&&this.config.timeAccessor||this.config.xAccessor,r=G(i,t?"time":"x");this.xIsDate=!1,this.xTypeDetected=!1;for(let t of e){let e=r(t);if(null==e||""===e)continue;let i=e instanceof Date&&Number.isFinite(e.getTime())||"string"==typeof e&&Number.isFinite(z(e));if(i||Number.isFinite(Number(e))){this.xIsDate=i,this.xTypeDetected=!0;break}}this.getX=this.xIsDate?e=>B(r(e)):e=>+r(e)}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=no(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(e)),void this.yExtent.push(this.getLow(e));this.yExtent.push(this.getY(e)),this.getY0&&this.yExtent.push(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.push(i),Number.isFinite(r)&&this.yExtent.push(r)}}evictDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(e)),void this.yExtent.evict(this.getLow(e));this.yExtent.evict(this.getY(e)),this.getY0&&this.yExtent.evict(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.evict(i),Number.isFinite(r)&&this.yExtent.evict(r)}}rebuildYExtent(){this.yExtent.clear();for(let e of this.buffer)this.pushDatumYExtent(e)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(let e of this.buffer)this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e)}ingest(e){if(e.bounded&&this._lastBoundedInsertsRef===e.inserts)return this.updateResults.recordNoop("replace"),!1;let t=this.currentTime();if(this.lastIngestTime=t,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,e.bounded){this._lastBoundedInsertsRef=e.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),this.resolveXAccessor(e.inserts);let i=e.totalSize||e.inserts.length;ro(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)oo(this.buffer,i,this.timestampBuffer,t),this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i)}else{this.xTypeDetected||this.resolveXAccessor(e.inserts);for(let i of e.inserts){if("growing"===this.config.windowMode&&this.buffer.full){let e=this.config.maxCapacity??1e5;this.growingCap<e&&(this.growingCap=Math.min(2*this.growingCap,e),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"!==process.env.NODE_ENV&&!this.growingCapacityWarned&&this.growingCap>=5e4&&(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${e}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}let e=oo(this.buffer,i,this.timestampBuffer,t);this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i),null!=e&&(this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e))}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.lastLayout;if(!(e.width>0&&e.height>0&&Number.isFinite(e.width)&&Number.isFinite(e.height)))return void(this.needsFullRebuild=!0);if(!this.needsFullRebuild&&!t.customLayout&&!this.activeTransition&&"bar"!==t.chartType&&"waterfall"!==t.chartType&&"candlestick"!==t.chartType&&this.lastLayout&&this.lastLayout.width>0&&this.lastLayout.height>0&&this.scene.length>0&&this.scales&&(this.config.scalePadding??0)<=0&&(this.lastLayout.width!==e.width||this.lastLayout.height!==e.height))return this.scales=function(e,t,i,r){let n=r.width/i.width,o=r.height/i.height;for(let t of e)switch(t.type){case"line":for(let e of t.path)e[0]*=n,e[1]*=o;break;case"area":for(let e of t.topPath)e[0]*=n,e[1]*=o;for(let e of t.bottomPath)e[0]*=n,e[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*n,y:t.clipRect.y*o,width:t.clipRect.width*n,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(e=>({...e,y:e.y*o,height:e.height*o})));break;case"point":case"symbol":case"glyph":t.x*=n,t.y*=o;break;case"rect":case"heatcell":t.x*=n,t.y*=o,t.w*=n,t.h*=o}return{x:t.x.copy().range(t.x.range().map(e=>e*n)),y:t.y.copy().range(t.y.range().map(e=>e*o))}}(this.scene,this.scales,this.lastLayout,e),this.lastLayout={width:e.width,height:e.height},this.spatialIndex.rebuild(t.chartType,this.scene),void this.version++;this.xExtent.dirty&&this.xExtent.recalculate(i,this.getX),this.yExtent.dirty&&this.rebuildYExtent();let o=this.getBufferArray(),a=this.xExtent.extent,s=this.yExtent.extent,l="waterfall"===t.chartType&&i.size>0?function(e,t,i,r,n){let o=Array.from(new Set(e.map(t).filter(e=>Number.isFinite(e)))).sort((e,t)=>e-t);if(o.length<2)return Un(i,r);let a=o[0],s=o[1],l=o[o.length-1],c=o[o.length-2];return Un("log"===n&&a>0?[a/Math.sqrt(s/a),l*Math.sqrt(l/c)]:[a-(s-a)/2,l+(l-c)/2],r)}(o,this.getX,a,t.xExtent,t.xScaleType):Un(a,t.xExtent);"bar"===t.chartType&&t.binSize&&"center"===t.binAlign&&(l=function(e,t,i){return e.every(Number.isFinite)?Un([pn(e[0],t,"center"),pn(e[1],t,"center")+t],i):Un(e,i)}(a,t.binSize,t.xExtent));let c=Un(s,t.yExtent),u=!(!(h=t.yExtent)||null==h[0]||null==h[1]),d="exact"===(t.yAxisExtent??t.axisExtent);var h;if("stackedarea"===t.chartType&&!u&&i.size>0){let e=Zn({config:t,groups:this.groupData(o),getX:this.getX,getY:this.getY,bufferSize:i.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=e.yDomain,this._stackExtentCache=e.stackExtentCache}else"bar"===t.chartType&&t.binSize&&!u&&i.size>0?c=function(e,t,i,r,n,o,a,s="start"){let[l,c]=function(e,t,i,r,n,o="start"){let a=fn(e,t,i,r,n,!1,o);if(0===a.size)return[0,0];let s=0,l=0;for(let e of a.values()){let t=0,i=0;if(n&&e.categories.size>0)for(let r of e.categories.values())r<0?t+=r:r>0&&(i+=r);else t=Math.min(0,e.total),i=Math.max(0,e.total);t<s&&(s=t),i>l&&(l=i)}return[s,l]}(e,t,i,r,n,s);if(0===l&&0===c)return[0,0];let u=a?0:(c-l)*o;return[l<0?l-u:0,c+u]}(i,this.getX,this.getY,t.binSize,this.getCategory,t.extentPadding,d,t.binAlign):"waterfall"===t.chartType&&!u&&i.size>0?c=function(e,t,i,r,n){let o=0,a=0;for(let r of Kn(e,t,i))r<o&&(o=r),r>a&&(a=r);let s=a-o,l=n?0:s>0?s*r:1;return[Math.min(0,o-Math.abs(l)),Math.max(0,a+Math.abs(l))]}(i,this.getX,this.getY,t.extentPadding,d):!u&&c[0]!==1/0&&(c=function(e,t,i){if(!i.length)return e;let[r,n]=e;for(let e of t)for(let t of i){let i=t.getTop(e),o=t.getBottom(e);Number.isFinite(i)&&(i<r&&(r=i),i>n&&(n=i)),Number.isFinite(o)&&(o<r&&(r=o),o>n&&(n=o))}return[r,n]}(c,o,this.resolvedRibbons),c=function(e,t){let i=e[1]-e[0],r=t.exactMode?0:i>0?i*t.extentPadding:1,n=[null!=t.userMin?e[0]:e[0]-r,null!=t.userMax?e[1]:e[1]+r];if("log"===t.yScaleType&&n[0]<=0&&t.dataYDomain[0]>0&&!t.exactMode){let e=1+t.extentPadding;null==t.userMin&&(n[0]=t.dataYDomain[0]/e)}return n}(c,{exactMode:d,extentPadding:t.extentPadding,userMin:t.yExtent?.[0],userMax:t.yExtent?.[1],yScaleType:t.yScaleType,dataYDomain:s}));if(c=function(e,t,i){if(!t||i)return e;let r=t[0],n=t[1];return null==r&&null==n?e:[r??e[0],n??e[1]]}(c,t.yExtent,!!u),({xDomain:l,yDomain:c}=function(e,t,i,r){return{xDomain:Qn(e,"time"===i?[0,864e5]:[0,1],r?.x,i),yDomain:Qn(t,[0,1],r?.y,r?.yScaleType)}}(l,c,t.xScaleType,{x:t.xExtent,y:t.yExtent,yScaleType:t.yScaleType})),"log"===(t.xScaleType??(this.xIsDate?"utc":void 0))){let e=this.positiveAxisSamples(this.getX);l=Jn(l,e.positive,t.xExtent),this.warnDroppedLogSamples("x",e.droppedNonPositive)}if("log"===t.yScaleType){let e=eo(this.plottedAggregateY(i,o)||function(e){let t=[];if("candlestick"===e.chartType&&e.getHigh&&e.getLow){let i=e.getHigh,r=e.getLow,n=e.getOpen,o=e.getClose,a=null!=n&&null!=o;for(let s of e.data)t.push(i(s),r(s)),a&&t.push(n(s),o(s));return t}for(let i of e.data){t.push(e.getY(i)),e.getY0&&t.push(e.getY0(i));for(let r of e.ribbons){let e=r.getTop(i),n=r.getBottom(i);Number.isFinite(e)&&t.push(e),Number.isFinite(n)&&t.push(n)}}return t}({chartType:t.chartType,data:i,getY:this.getY,getY0:this.getY0,getHigh:this.getHigh,getLow:this.getLow,getOpen:this.getOpen,getClose:this.getClose,ribbons:this.resolvedRibbons}));c=Jn(c,e.positive,t.yExtent),this.warnDroppedLogSamples("y",e.droppedNonPositive)}this.scales=function(e){let{config:t,layout:i,xDomain:r}=e,n=t.xScaleType??(e.xIsDate?"utc":void 0),o=t.invertY?[e.yDomain[1],e.yDomain[0]]:e.yDomain,a="streaming"===t.runtimeMode,s=t.scalePadding||0,l=Math.max(0,Math.min(s,Math.min(i.width,i.height)/2-1));return a?{x:to(n,r,"left"===t.arrowOfTime?[i.width-l,l]:[l,i.width-l]),y:to(t.yScaleType,o,[i.height-l,l])}:{x:to(n,r,[l,i.width-l]),y:to(t.yScaleType,o,[i.height-l,l])}}({config:t,layout:e,xDomain:l,yDomain:c,xIsDate:this.xIsDate}),this._customLayoutFailedThisBuild=!1;let p=this.buildSceneNodes(e,o);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);let f=this.config.transition?An():null;f&&this.scene.length>0&&this.snapshotPositions(),this.scene=p,this.config.decay&&this.applyDecay(this.scene,o),this.config.pulse&&this.applyPulse(this.scene,o,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&f&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),f&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:e.width,height:e.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}buildSceneNodes(e,t){let{config:i,scales:r}=this;if(!r)return[];if(i.customLayout){let n=i.layoutMargin??{top:0,right:0,bottom:0,left:0},o={data:t,scales:r,dimensions:{width:e.width,height:e.height,margin:n,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:i.themeSemantic??{},categorical:i.themeCategorical??Kt},resolveColor:(e,t)=>{let r=this.resolveGroupColor(e);if(r)return r;let n=this.resolveLineStyle(e,t);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:i.themeSemantic?.primary??"#4e79a7"},config:i.layoutConfig??{},selection:i.layoutSelection??null},a=Rn({family:"xy",logLabel:"customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:i.onLayoutError,run:()=>i.customLayout(o)});if("failure"===a.kind)return this.lastCustomLayoutFailure=a.diagnostic,this._customLayoutFailedThisBuild=!0,a.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let s=a.result;this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null;let l=s.nodes??[];if(this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of l)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(l,i.layoutSelection??null)}return Tn({label:"customLayout",nodes:l,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),l}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===t.length)return[];let n={scales:r,config:i,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(e,t)=>this.resolveLineStyle(e,t),resolveAreaStyle:(e,t)=>this.resolveAreaStyle(e,t),resolveBoundsStyle:(e,t)=>this.resolveBoundsStyle(e,t),resolveColorMap:e=>this.resolveColorMap(e),resolveGroupColor:e=>this.resolveGroupColor(e),groupData:e=>this.groupData(e),barCategoryCache:this._barCategoryCache},o=(a=i.chartType,Mn[a]?.buildScene);var a;if(!o)return function(e){_n(e)||Pn&&(In.has(e)||(In.add(e),console.warn(`[semiotic] StreamXYFrame: no XY plugin registered for "${e}" during SSR. Import a chart HOC, or call registerBuiltInXYPlugins() from "semiotic/xy" or "semiotic/realtime/core" before render.`)))}(i.chartType),[];let s=function(e){return Array.isArray(e)?{nodes:e,binBoundaries:[]}:{nodes:e.nodes,binBoundaries:e.binBoundaries}}(o(n,t,e));return"bar"===i.chartType&&(this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=s.binBoundaries),s.nodes}resolveBoundsStyle(e,t){return function(e,t,i,r){let n=e.boundsStyle;if("function"==typeof n)return n(i||{},t);if(n&&"object"==typeof n)return n;let o=r(t,i);return{fill:o.stroke||e.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,...null!=o.opacity&&{opacity:o.opacity},stroke:"none",cursor:o.cursor}}(this.config,e,t,(e,t)=>this.resolveLineStyle(e,t))}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:xn(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;let t=bn(e);return this._datumIndexCache={version:this._ingestVersion,map:t},t}applyDecay(e,t){this.config.decay&&function(e,t,i,r=bn(i)){let n=i.length;if(!(n<=1))for(let i of t){if("line"===i.type){let t=Array.isArray(i.datum)?i.datum:[];if(t.length<2)continue;let o=new Array(t.length),a=!1;for(let i=0;i<t.length;i++){let s=r.get(t[i]);null!=s?(o[i]=xn(e,s,n),o[i]<1&&(a=!0)):o[i]=1}a&&(i._decayOpacities=o);continue}if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[],o=i.topPath?i.topPath.length:t.length;if(o<2)continue;if(t.length===o){let a=new Array(o),s=!1;for(let i=0;i<t.length;i++){let o=r.get(t[i]);null!=o?(a[i]=xn(e,o,n),a[i]<1&&(s=!0)):a[i]=1}s&&(i._decayOpacities=a)}else{let a=1;for(let i of t){let t=r.get(i);if(null!=t){let i=xn(e,t,n);i<a&&(a=i)}}if(a<1){let e=new Array(o);e.fill(a),i._decayOpacities=e}}continue}let t=r.get(i.datum);if(null==t)continue;let o=xn(e,t,n);if("candlestick"===i.type)i._decayOpacity=o;else{let e=i.style?.opacity??1;i.style={...i.style,opacity:e*o}}}}(this.config.decay,e,t,this.getDatumIndexMap(t))}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&kn(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory,getPointId:this.getPointId}}get hasRenderedOnce(){return this._hasRenderedOnce}snapshotPositions(){An()?.snapshotPositions(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();let e=this.scales?.y(0)??0,t=An();if(t)for(let i=0;i<this.scene.length;i++){let r=this.scene[i],n=t.getNodeIdentity(this.transitionContext,r,i);n&&("point"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,r:0,opacity:0}):"rect"===r.type?this.prevPositionMap.set(n,{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}):"heatcell"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:0}):"line"===r.type?(r._introClipFraction=0,this.prevPathMap.set(n,{path:r.path.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})):"area"===r.type&&(r._introClipFraction=0,this.prevPathMap.set(n,{topPath:r.topPath.map(e=>[e[0],e[1]]),bottomPath:r.bottomPath.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})))}}startTransition(){let e=An();if(!this.config.transition||!e)return;let t=e.startTransition(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(e){let t=An();if(!this.activeTransition||!this.config.transition||!t)return!1;let i={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},r=t.advanceTransition(e,this.config.transition,i,this.prevPositionMap,this.prevPathMap);return this.scene=i.scene,this.exitNodes=i.exitNodes,this.activeTransition=i.activeTransition,r}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("glyph"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("rect"===t.type||"heatcell"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0);else if("candlestick"===t.type)void 0!==t._targetX&&(t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0);else if("line"===t.type||"area"===t.type){if(t._introClipFraction=void 0,"line"===t.type&&t._targetPath){for(let e=0;e<t.path.length;e++)t.path[e]=t._targetPath[e];t._prevPath=void 0,t._targetPath=void 0}if("area"===t.type){if(t._targetTopPath)for(let e=0;e<t.topPath.length;e++)t.topPath[e]=t._targetTopPath[e];if(t._targetBottomPath)for(let e=0;e<t.bottomPath.length;e++)t.bottomPath[e]=t._targetBottomPath[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(e){let{result:t,cache:i}=function(e,t,i,r){if(r&&r.version===i&&r.group===t&&r.data===e)return{result:r.result,cache:r};let n;if(t){let i=new Map;for(let r of e){let e=t(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}n=Array.from(i.entries()).map(([e,t])=>({key:e,data:t}))}else n=[{key:"_default",data:e}];return{result:n,cache:{version:i,group:t,data:e,result:n}}}(e,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=i,t}resolveColorMap(e){let{map:t,cache:i}=function(e,t,i,r,n){if(n&&n.version===r)return{map:n.map,cache:n};let o=new Set;if(t)for(let i of e){let e=t(i);e&&o.add(e)}let a=Array.from(o).sort(),s=a.join("\0");if(n&&n.key===s){let e={...n,version:r};return{map:e.map,cache:e}}let l=Zt(i.colorScheme,i.themeCategorical,Kt),c=new Map;for(let e=0;e<a.length;e++)c.set(a[e],io(i.colorScheme,a[e])??l[e%l.length]);return{map:c,cache:{key:s,map:c,version:r}}}(e,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=i,t}resolveLineStyle(e,t){return function(e,t,i,r){let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.stroke&&t){let i=r(t);if(i)return{...e,stroke:i}}return e}let o=e.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||o||"#007bff",strokeWidth:n.strokeWidth??2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity,cursor:n.cursor}:{stroke:r(t)||o||"#007bff",strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveAreaStyle(e,t){return function(e,t,i,r){if(e.areaStyle){let n=e.areaStyle(i||{});if(n&&!n.fill&&t){let e=r(t);if(e)return{...n,fill:e,stroke:n.stroke||e}}return n}let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.fill&&t){let i=r(t);if(i)return{...e,fill:i,stroke:e.stroke||i}}return e}let o=e.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||o||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||o||"#4e79a7",strokeWidth:n.strokeWidth??2,cursor:n.cursor};let a=r(t)||o||"#4e79a7";return{fill:a,fillOpacity:.7,stroke:a,strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveGroupColor(e){let{color:t,groupColorCounter:i}=function(e){let{group:t,colorMapCache:i,groupColorMap:r,groupColorMapCap:n,config:o}=e,{groupColorCounter:a}=e,s=io(o.colorScheme,t);if(s)return{color:s,groupColorCounter:a};if(i){let e=i.map.get(t);if(e)return{color:e,groupColorCounter:a}}let l=r.get(t);if(l)return{color:l,groupColorCounter:a};let c=Zt(o.colorScheme,o.themeCategorical,Kt);if(0===c.length)return{color:null,groupColorCounter:a};let u=c[a%c.length];if(a++,r.set(t,u),r.size>n){let e=r.keys().next().value;void 0!==e&&r.delete(e)}return{color:u,groupColorCounter:a}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:1e3,config:this.config});return this._groupColorCounter=i,t}getBufferArray(){return(this._bufferDirty||!this._bufferArrayCache)&&(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(e){if(!this.getPointId)throw new Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&An()&&this.snapshotPositions();let t=yn(e),i=this.getPointId,r=e=>t.has(i(e));ao(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getPointId)throw new Error("update() requires pointIdAccessor to be configured");let i=yn(e),r=this.getPointId,n=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.buffer.forEach((e,t)=>{n.has(t)&&(this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.dirty&&this.xExtent.recalculate(this.buffer,this.getX),this.yExtent.dirty&&this.rebuildYExtent(),this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}positiveAxisSamples(e){let t=[];for(let i of this.buffer)t.push(e(i));return eo(t)}plottedAggregateY(e,t){let i=this.config;if("bar"===i.chartType&&i.binSize)return function(e,t,i,r,n,o="start",a=[]){let s=fn(e,t,i,r,n,!1,o),l=[];if(!n){for(let e of s.values())l.push(e.total);return l}let c=new Set;for(let e of s.values())for(let t of e.categories.keys())c.add(t);let u=new Set(a),d=[...a.filter(e=>c.has(e)),...Array.from(c).filter(e=>!u.has(e)).sort()];for(let e of s.values()){if(0===e.categories.size){l.push(e.total);continue}let t=0;for(let i of d){let r=e.categories.get(i);null==r||0===r||(t+=r,l.push(t))}}return l}(e,this.getX,this.getY,i.binSize,this.getCategory,i.binAlign,i.barColors?Object.keys(i.barColors):[]);if("stackedarea"===i.chartType&&e.size>0){let r=Zn({config:i,groups:this.groupData(t),getX:this.getX,getY:this.getY,bufferSize:e.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});return this._stackExtentCache=r.stackExtentCache,r.stackExtentCache.plottedY??null}return"waterfall"===i.chartType&&e.size>0?Kn(e,this.getX,this.getY):null}warnDroppedLogSamples(e,t){if(t){if("x"===e){if(this._warnedNonPositiveLogX)return;this._warnedNonPositiveLogX=!0}else{if(this._warnedNonPositiveLogY)return;this._warnedNonPositiveLogY=!0}console.warn(`Semiotic log ${e} scale clamped non-positive values to the positive domain edge.`)}}clear(){this.buffer.clear(),this.resolveXAccessor(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in e||"colorScheme"in e)&&(this._barCategoryCache=null),("normalize"in e||"extentPadding"in e||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e||"boundsAccessor"in e||"band"in e||"y0Accessor"in e||"openAccessor"in e||"highAccessor"in e||"lowAccessor"in e||"closeAccessor"in e||"groupAccessor"in e||"categoryAccessor"in e||"chartType"in e||"runtimeMode"in e)&&(this._stackExtentCache=null);let r=!1,n=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let o="chartType"in e&&e.chartType!==t.chartType||"runtimeMode"in e&&e.runtimeMode!==t.runtimeMode;if(o||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){let e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=e&&this.config.timeAccessor||this.config.xAccessor,a=e&&t.timeAccessor||t.xAccessor,s=e&&this.config.valueAccessor||this.config.yAccessor,l=e&&t.valueAccessor||t.yAccessor,c=o||!q(i,a),u=o||!q(s,l);(c||u)&&(c&&this.resolveXAccessor(),this.getY=e?X(this.config.valueAccessor||this.config.yAccessor,"value"):X(this.config.yAccessor,"y"),u&&this.resolvedRibbons.some(e=>"bounds"===e.kind)&&(this.resolvedRibbons=Dn(this.config)),r=!0,n=!0)}if("groupAccessor"in e&&!q(e.groupAccessor,t.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?V(this.config.groupAccessor):void 0,r=!0),"categoryAccessor"in e&&!q(e.categoryAccessor,t.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?V(this.config.categoryAccessor):void 0,r=!0),"sizeAccessor"in e&&!q(e.sizeAccessor,t.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?X(this.config.sizeAccessor,"size"):void 0,r=!0),"symbolAccessor"in e&&!q(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?V(this.config.symbolAccessor):void 0,r=!0),"colorAccessor"in e&&!q(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?V(this.config.colorAccessor):void 0,r=!0),"y0Accessor"in e&&!q(e.y0Accessor,t.y0Accessor)&&(this.getY0=this.config.y0Accessor?X(this.config.y0Accessor,"y0"):void 0,r=!0,n=!0),("boundsAccessor"in e&&!q(e.boundsAccessor,t.boundsAccessor)||"band"in e&&e.band!==t.band||"boundsStyle"in e&&e.boundsStyle!==t.boundsStyle)&&(this.resolvedRibbons=Dn(this.config),r=!0,n=!0),"pointIdAccessor"in e&&!q(e.pointIdAccessor,t.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?V(this.config.pointIdAccessor):void 0,r=!0),"candlestick"===this.config.chartType&&(o||"openAccessor"in e&&!q(e.openAccessor,t.openAccessor)||"closeAccessor"in e&&!q(e.closeAccessor,t.closeAccessor)||"highAccessor"in e&&!q(e.highAccessor,t.highAccessor)||"lowAccessor"in e&&!q(e.lowAccessor,t.lowAccessor))){let e=null!=this.config.openAccessor,t=null!=this.config.closeAccessor;this.getOpen=e?X(this.config.openAccessor,"open"):void 0,this.getHigh=X(this.config.highAccessor,"high"),this.getLow=X(this.config.lowAccessor,"low"),this.getClose=t?X(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!t,r=!0,n=!0}if("accessorRevision"in e&&e.accessorRevision!==t.accessorRevision&&(this.resolveXAccessor(),r=!0,n=!0),!r){let i=Object.keys(e).filter(e=>!e.endsWith("Accessor")&&"timeAccessor"!==e&&"valueAccessor"!==e);for(let n of i)if(e[n]!==t[n]){r=!0;break}}r&&(n&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(i,("bar"===this.config.chartType||"heatmap"===this.config.chartType)&&!this.config.trackHoverRows&&ur(t.areaStyle)!==ur(this.config.areaStyle))}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function Lo(e,t,i,r){return"function"==typeof t.style?t.style(r||{},i):t.style&&"object"==typeof t.style?t.style:e.resolveBoundsStyle(i,r)}function Co(e,t,i,r){if(!e.scales)return null;let{topPath:n,bottomPath:o,datum:a,pathIds:s}=jn(t,e.scales,e.getX,r.getTop,r.getBottom,e.getPointId);return n.length<2?null:{type:"area",topPath:n,bottomPath:o,...s&&{pathIds:s},...e.config.curve&&"linear"!==e.config.curve&&{curve:e.config.curve},style:Lo(e,r,i,cr(t)),datum:a,group:i,interactive:r.interactive}}function Ro(e){let t=[],i=[];if(!e)return{perSeries:t,aggregate:i};for(let r of e)r.perSeries?t.push(r):i.push(r);return{perSeries:t,aggregate:i}}function No(e,t,i){let r=[];for(let n of i){let i=Co(e,t,"__ribbon_aggregate",n);i&&r.push(i)}return r}function Do(e,t,i,r){let n=[];for(let o of r){let r=Co(e,t,i,o);r&&n.push(r)}return n}function Fo(e,t,i,r){if(!e.config.pointStyle)return;let n=r??e.getY;for(let r of t){let t=e.resolveGroupColor(r.key);for(let o of r.data){let r=e.config.pointStyle(o);!r.fill&&t&&(r={...r,fill:t});let a=r.r??3,s=e.getPointId?String(e.getPointId(o)):void 0,l=Xn(o,e.scales,e.getX,n,a,r,s);l&&i.push(l)}}}function Eo(e){return"threshold"===e.type&&"string"==typeof e.color&&"number"==typeof e.value}function Oo(e){return pi(e)}function zo(e,t){if("domain"!==e.extent)return;let[i,r]=t.domain(),n=t(r),o=t(i);return Number.isFinite(n)&&Number.isFinite(o)?[n,o]:void 0}function Bo(e,t){let i=[],r="bubble"===e.config.chartType?10:5,n=e.config.sizeRange||[3,15],o=null;if(e.getSize&&!e.config.pointStyle){let i=t.map(t=>e.getSize(t)).filter(e=>null!=e&&!Number.isNaN(e));if(i.length>0){let e=1/0,t=-1/0;for(let r of i)r<e&&(e=r),r>t&&(t=r);o=i=>e===t?(n[0]+n[1])/2:n[0]+(i-e)/(t-e)*(n[1]-n[0])}}let a=e.getColor?e.resolveColorMap(t):null,s=e.config.themeSemantic?.primary||"#4e79a7",l=e.getSymbol,c=l?u(l,e.config.symbolMap):null;for(let n of t){let t=e.config.pointStyle?e.config.pointStyle(n):{fill:s,opacity:.8},l=t.r||r;if(o&&e.getSize){let t=e.getSize(n);null!=t&&!Number.isNaN(t)&&(l=o(t))}if(a&&e.getColor&&!t.fill){let i=e.getColor(n);i&&a.has(i)&&(t={...t,fill:a.get(i)})}let u=e.getPointId?String(e.getPointId(n)):void 0;if(c){let r=c(n),o=Gn(n,e.scales,e.getX,e.getY,Math.PI*l*l,r,t,u);o&&i.push(o)}else{let r=Xn(n,e.scales,e.getX,e.getY,l,t,u);r&&i.push(r)}}return i}import{scaleLinear as jo}from"d3-scale";var Wo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandTicks"),Yo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandCopy"),qo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandKeys"),Xo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandKeyIndex"),Go=/*#__PURE__*/Symbol.for("semiotic.heatmapBandDirection");function Vo(e){if(!e)return null;let t=e[Wo];return t&&t.length>0?t:null}function Ho(e,t){Object.defineProperty(e,Wo,{value:t,enumerable:!1,configurable:!0});let i=e;if("function"==typeof i.copy&&!i[Yo]){let e=i.copy;Object.defineProperty(i,Yo,{value:!0}),i.copy=function(){return Ho(e.call(this),t)}}return e}function Uo(e,t,i){return Ho(jo().domain(i??[-.5,Math.max(e.length-.5,.5)]).range(t),e.map((e,t)=>({value:t,label:e})))}function Zo(e,t){let i=[-.5,Math.max(e.length-.5,.5)],r=function(e){return 0===e.length?null:e.every(e=>"number"==typeof e&&Number.isFinite(e))?e.slice():e.every(e=>e instanceof Date&&Number.isFinite(e.getTime()))?e.map(e=>e.getTime()):null}(e);if(!t||!r)return i;let n=(e,t)=>null!=e&&Number.isFinite(e)?ta(r,e)??t:t,o=n(t[0],i[0]),a=n(t[1],i[1]);return o===a?i:[o,a]}function Ko(e,t){if(t instanceof Date){let i=t.getTime();return Number.isFinite(i)?e.find(e=>e.label instanceof Date&&e.label.getTime()===i)?.value??null:null}if("number"==typeof t&&Number.isFinite(t)){let i=e.find(e=>"number"==typeof e.label&&e.label===t);return i?i.value:e.find(e=>e.label instanceof Date&&e.label.getTime()===t)?.value??null}return"string"==typeof t?e.find(e=>"string"==typeof e.label&&e.label===t)?.value??null:null}function Qo(e,t){if(!e)return null;let i=Vo(e);if(!i)return e(t);let r=Ko(i,t);return null==r?null:e(r)}function Jo(e,t,i){if("function"!=typeof e)return null;if(null==t){let t=e.domain?.()?.[i];if(null==t)return null;let r=e(t instanceof Date?t.getTime():Number(t));return Number.isFinite(r)?r:null}let r=Qo(e,t);return null!=r&&Number.isFinite(r)?r:null}function ea(e,t){return"number"==typeof t&&Number.isFinite(t)?function(e,t){let i=t instanceof Date?t.getTime():t;if(!e||!Number.isFinite(i))return null;let r=Vo(e);if(!r)return e(i);let n=function(e){let t=e;if(qo in t)return t[qo]??null;let i=null;return e.every(e=>"number"==typeof e.label&&Number.isFinite(e.label))?i=e.map(e=>e.label):e.every(e=>e.label instanceof Date&&Number.isFinite(e.label.getTime()))&&(i=e.map(e=>e.label.getTime())),Object.defineProperty(t,qo,{value:i}),i}(r);if(!n)return e(i);let o=function(e,t){let i=e,r=i[Xo];if(r)return r;let n=new Map;for(let e=0;e<t.length;e++)n.set(t[e],e);return Object.defineProperty(i,Xo,{value:n}),n}(r,n).get(i);if(null!=o)return e(o);let a=ta(n,i);return null==a?null:e(a)}(e,t):Qo(e,t)}function ta(e,t){if(e.length<2)return 1===e.length?t-e[0]:null;let i=function(e){let t=e,i=t[Go];if(null!=i)return i;let r=0;for(let t=1;t<e.length;t++){let i=e[t]-e[t-1];if(0===i){r=0;break}let n=i>0?1:-1;if(0===r)r=n;else if(r!==n){r=0;break}}return Object.defineProperty(t,Go,{value:r}),r}(e);if(1===i||-1===i)return function(e,t,i){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;(1===i?e[o]<t:e[o]>t)?r=o+1:n=o}if(0===r)return(t-e[0])/(e[1]-e[0]);let o=e.length-1;return r>=e.length?o+(t-e[o])/(e[o]-e[o-1]):r-1+(t-e[r-1])/(e[r]-e[r-1])}(e,t,i);for(let i=0;i<e.length-1;i++){let r=e[i],n=e[i+1];if(r===n)continue;let o=Math.min(r,n),a=Math.max(r,n);if(t>=o&&t<=a)return i+(t-r)/(n-r)}let r=e[1]-e[0];if(0!==r&&(t-e[0])/r<0)return(t-e[0])/r;let n=e.length-1,o=e[n]-e[n-1];return 0!==o&&(t-e[n])/o>0?n+(t-e[n])/o:null}var ia=/*#__PURE__*/new Map;function ra(e,t,i){return t===i?Math.floor(128):Math.min(Math.floor(255*(e-t)/(i-t)+.5),255)}function na(e){let t=Object.prototype.hasOwnProperty.call(Ot,e)?e:"blues",i=ia.get(t);if(i)return i;i=new Array(256);let r=zt(t);for(let e=0;e<256;e++)i[e]=r(e/255);return ia.set(t,i),i}function oa(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?{key:t,label:e,numeric:!0,temporal:!0}:{key:"Invalid Date",label:"Invalid Date",numeric:!1,temporal:!1}}return"number"==typeof e&&Number.isFinite(e)?{key:e,label:e,numeric:!0,temporal:!1}:{key:String(e),label:String(e),numeric:!1,temporal:!1}}function aa(e,t){let i=t.map((e,t)=>({label:e,previous:t})).sort((e,t)=>sa(e.label)-sa(t.label)),r=new Map;i.forEach((e,t)=>r.set(e.previous,t));let n=Array.from(e.keys());e.clear();for(let t=0;t<n.length;t++)e.set(n[t],r.get(t));t.length=i.length;for(let e=0;e<i.length;e++)t[e]=i[e].label}function sa(e){return e instanceof Date?e.getTime():Number(e)}function la(e,t,i){let r=i.config.areaStyle?.(t);return r&&("string"==typeof r.fill&&(e.fill=r.fill),e.style=r),e}function ca(e,t,i){let r=Math.max(1,Math.floor(e.config.heatmapXBins??20)),n=Math.max(1,Math.floor(e.config.heatmapYBins??20)),o=e.config.heatmapAggregation??"count",a=X(e.config.valueAccessor,"value");if(!e.scales||0===t.length)return[];let[s,l]=e.scales.x.domain(),[c,u]=e.scales.y.domain(),d=(l-s||1)/r,h=(u-c||1)/n,p=r*n;if(p>1e6)return[];let f=new Int32Array(p),g=new Float64Array(p),m=e.config.trackHoverRows||ur(e.config.areaStyle)?new Map:void 0;for(let i=0;i<t.length;i++){let o=t[i],l=e.getX(o),u=e.getY(o);if(!isFinite(l)||!isFinite(u))continue;let p=Math.min(Math.floor((l-s)/d),r-1),y=Math.min(Math.floor((u-c)/h),n-1);if(p<0||y<0)continue;let x=y*r+p;f[x]++;let b=a(o);if(g[x]+=isFinite(b)?b:0,m){let e=m.get(x);e||(e=[],m.set(x,e)),e.push(o)}}let y=1/0,x=-1/0;for(let e=0;e<p;e++){if(0===f[e])continue;let t;switch(o){case"sum":t=g[e];break;case"mean":t=g[e]/f[e];break;default:t=f[e]}t<y&&(y=t),t>x&&(x=t)}if(!isFinite(y))return[];let b=e.config.heatmapColorScale,v="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",w=b?void 0:na(v),k=i.width/r,S=i.height/n,A=e.config.showValues,M=e.config.heatmapValueFormat,$=[];for(let t=0;t<n;t++){let i=t*r;for(let a=0;a<r;a++){let r,l=i+a;if(0===f[l])continue;switch(o){case"sum":r=g[l];break;case"mean":r=g[l]/f[l];break;default:r=f[l]}let u=ra(r,y,x),p=b?b(r):w[u],v=A?{value:r,showValues:!0,valueFormat:M}:{value:r},_=s+(a+.5)*d,P=c+(t+.5)*h,I=ar({xi:a,yi:t,value:r,count:f[l],sum:g[l],xCenter:_,yCenter:P,agg:o},m?.get(l));$.push(la(Hn(a*k,(n-1-t)*S,k,S,p,I,v),I,e))}}return $}function ua(e,t,i,r){let n=Math.min(t,i),o=Math.max(t,i);if(!(o>n))return[];let a=[],s=-1/0;for(let t of e){let e=Math.max(s,n),i=Math.min(t.upTo,o);if(i>e&&a.push({from:e,to:i,fill:t.fill}),s=t.upTo,s>=o)break}return s<o&&a.push({from:Math.max(s,n),to:o,fill:r}),a}var da={line:function(e,t){let i=e.groupData(t),r=[],n=e.config.annotations?.filter(Eo).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Ro(e.ribbons);if(o.length>0&&r.push(...No(e,t,o)),n.length>0)for(let t of i)r.push(...Do(e,t.data,t.key,n))}for(let t of i){let i=e.resolveLineStyle(t.key,cr(t.data)),o=Wn(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);n&&n.length>0&&(o.colorThresholds=n),e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),r.push(o)}return Fo(e,i,r),r},area:function(e,t){let i=e.groupData(t),r=[];if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Ro(e.ribbons);if(o.length>0&&r.push(...No(e,t,o)),n.length>0)for(let t of i)r.push(...Do(e,t.data,t.key,n))}let n=e.scales.y.domain(),o=n[0],a=e.config.semanticLineStops?.filter(e=>Number.isFinite(e.offset)).map(e=>({value:n[0]+Math.max(0,Math.min(1,e.offset))*(n[1]-n[0]),color:e.color,opacity:e.opacity,thresholdType:"greater"})).sort((e,t)=>e.value-t.value),s=a&&a.length>0?(()=>{let t=a.reduce((e,t)=>(e.at(-1)?.value===t.value?e[e.length-1]=t:e.push(t),e),[]),i=[{from:n[0],to:t[0].value,color:t[0].color,opacity:t[0].opacity}];for(let e=0;e<t.length;e++)i.push({from:t[e].value,to:t[e+1]?.value??n[1],color:t[e].color,opacity:t[e].opacity});return i.map(({from:t,to:i,color:r,opacity:n})=>{let o=e.scales.y(t),a=e.scales.y(i);return{y:Math.min(o,a),height:Math.abs(a-o),color:r,...null!=n&&{opacity:n}}}).filter(e=>e.height>0)})():void 0,l=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i){let i=e.resolveAreaStyle(t.key,cr(t.data)),n=Yn(t.data,e.scales,e.getX,e.getY,o,i,t.key,l,e.getPointId),c=Oo(e.config.gradientFill);if(c){n.fillGradient=c;let t=zo(c,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),a&&a.length>0&&(n.colorThresholds=a,n.strokeColorBands=s),r.push(n)}return Fo(e,i,r),r},stackedarea:function(e,t){let i=e.groupData(t),r=e.config.stackOrder??"key",n=()=>i.sort((e,t)=>e.key<t.key?-1:e.key>t.key?1:0);if("input"!==r)if("key"===r)n();else if("asc"===r||"desc"===r||"insideOut"===r){let t=new Map;for(let r of i){let i=0;for(let t of r.data){let r=e.getX(t),n=e.getY(t);Number.isFinite(r)&&Number.isFinite(n)&&(i+=n)}t.set(r.key,i)}let n=(e,t)=>e<t?-1:e>t?1:0;if("asc"===r)i.sort((e,i)=>{let r=(t.get(e.key)??0)-(t.get(i.key)??0);return 0!==r?r:n(e.key,i.key)});else if("desc"===r)i.sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)});else{let e=[...i].sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)}),r=[],o=[],a=0,s=0;for(let i of e)a<s?(r.push(i),a+=t.get(i.key)??0):(o.push(i),s+=t.get(i.key)??0);i.length=0,i.push(...o.reverse(),...r)}}else n();let o=e.config.curve&&"linear"!==e.config.curve?e.config.curve:void 0,a=e.config.normalize?"zero":e.config.baseline??"zero",{nodes:s,stackedTops:l}=function(e,t,i,r,n,o,a,s="zero",l){let c=new Set,u=new Map;for(let t of e){let e=new Map;for(let n of t.data){let t=i(n),o=r(n);if(!Number.isFinite(t)||(c.add(t),!Number.isFinite(o)))continue;let a=e.get(t);a?(a.value+=o,a.sources?a.sources.push(n):a.sources=[a.datum,n]):e.set(t,{value:o,datum:n})}u.set(t.key,e)}let d,h=Array.from(c).sort((e,t)=>e-t);if(o){d=new Map;for(let t of h){let i=0;for(let r of e)i+=u.get(r.key)?.get(t)?.value||0;d.set(t,i||1)}}let p=qn(h,e.map(e=>e.key),(e,t)=>u.get(e)?.get(t)?.value||0,s),f="diverging"===s&&!o,g=[],m=new Map,y=new Map,x=new Map,b=new Map;for(let e of h)y.set(e,p.get(e)??0),x.set(e,0),b.set(e,0);for(let i of e){let e=u.get(i.key),r=new Map,s=[],c=[],p=[],v=[],w=[],k=l?[]:void 0,S=!1,A=()=>{if(0!==s.length){if(s.length>=2){let e=S?s.map((e,t)=>t).sort((e,t)=>s[e][0]-s[t][0]):void 0,t=e?e.map(e=>v[e]):v,r={type:"area",topPath:e?e.map(e=>s[e]):s,bottomPath:e?e.map(e=>c[e]):c,rawValues:e?e.map(e=>p[e]):p,style:n(i.key,cr(i.data)),datum:t,accessibleDatum:e?e.map(e=>w[e]):w,group:i.key};k&&(r.pathIds=e?e.map(e=>k[e]):k),a&&(r.curve=a),g.push(r)}s=[],c=[],p=[],v=[],w=[],k=l?[]:void 0,S=!1}};for(let n of h){let a,l,u=e.get(n),h=void 0!==u,g=u?.value??0;if(o&&h&&(g/=d.get(n)),!h||!Number.isFinite(g)||0===g){A();continue}f?g>0?(a=x.get(n),l=a+g,x.set(n,l)):(a=b.get(n),l=a+g,b.set(n,l)):(a=y.get(n),l=a+g,y.set(n,l));let m=t.x(n),M=t.y(a),$=t.y(l);if(!Number.isFinite(m)||!Number.isFinite(M)||!Number.isFinite($)){A();continue}let _=u.sources,P=u.value,I=_?{..._[0],__aggregateValue:P,__aggregateCount:_.length,__aggregateRows:_}:u.datum;s.length>0&&m<s[s.length-1][0]&&(S=!0),s.push([m,$]),c.push([m,M]),v.push(I),p.push(P),k&&k.push(`x:${n}`),w.push(_?{x:n,value:P,group:i.key,observations:_.length}:I),r.set(n,l)}A(),m.set(i.key,r)}return{nodes:g,stackedTops:m}}(i,e.scales,e.getX,e.getY,(t,i)=>e.resolveAreaStyle(t,i),e.config.normalize,o,a,e.getPointId),c=s;if(e.config.pointStyle){let t=new WeakMap;for(let r of i){let i=l.get(r.key);if(i)for(let n of r.data){let r=e.getX(n),o=e.getY(n);null!=r&&!Number.isNaN(r)&&null!=o&&!Number.isNaN(o)&&i.has(r)&&t.set(n,i.get(r))}}Fo(e,i,c,i=>t.get(i)??e.getY(i))}return c},mixed:function(e,t){let i=e.groupData(t),r=[],n=e.config.areaGroups||new Set;if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Ro(e.ribbons);if(o.length>0&&r.push(...No(e,t,o)),n.length>0)for(let t of i)r.push(...Do(e,t.data,t.key,n))}let o=e.scales.y.domain()[0],a=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i)if(n.has(t.key)){let i=e.resolveAreaStyle(t.key,cr(t.data)),n=Yn(t.data,e.scales,e.getX,e.getY,o,i,t.key,a,e.getPointId),s=Oo(e.config.gradientFill);if(s){n.fillGradient=s;let t=zo(s,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}else{let i=e.resolveLineStyle(t.key,cr(t.data)),n=Wn(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}return Fo(e,i,r),r},scatter:Bo,bubble:Bo,heatmap:function(e,t,i){if(e.config.heatmapAggregation)return ca(e,t,i);if(0===t.length)return[];let r=X(e.config.valueAccessor,"value"),n=G(e.config.xAccessor,"x"),o=G(e.config.yAccessor,"y"),a=new Map,s=new Map,l=[],c=[],u=new Array(t.length),d=new Array(t.length),h=!0,p=!0,f=!0,g=!0;for(let e=0;e<t.length;e++){let i=t[e],r=oa(n(i)),m=oa(o(i));u[e]=r.key,d[e]=m.key,r.numeric?r.temporal&&(h=!1):(h=!1,f=!1),m.numeric?m.temporal&&(p=!1):(p=!1,g=!1),a.has(r.key)||(a.set(r.key,a.size),l.push(r.label)),s.has(m.key)||(s.set(m.key,s.size),c.push(m.label))}let m=a.size,y=s.size;if(0===m||0===y)return[];let x=4096;if(h&&p&&m*y>x&&t.length>x){let r=new Set;for(let n=0;n<t.length;n++){let o=a.get(u[n]),l=s.get(d[n]);if(void 0!==o&&void 0!==l&&(r.add(l*m+o),r.size>x))return ca({...e,config:{...e.config,heatmapAggregation:e.config.valueAccessor?"mean":"count"}},t,i)}}f&&aa(a,l),g&&aa(s,c);let b=new Float64Array(t.length),v=new Float64Array(t.length),w=new Array(t.length),k=new Map,S=0;for(let e=0;e<t.length;e++){let i=t[e],n=a.get(u[e]),o=s.get(d[e]);if(void 0===n||void 0===o)continue;let l,c=r(i),h=o*m+n,p=k.get(h);void 0!==p?l=p:(l=S++,k.set(h,l)),b[l]=h,v[l]=c,w[l]=i}let A=1/0,M=-1/0;for(let e=0;e<S;e++){let t=v[e];isFinite(t)&&(t<A&&(A=t),t>M&&(M=t))}if(!isFinite(A)||!isFinite(M))return[];let $="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",_=e.config.heatmapColorScale,P=_?void 0:na($),I=e.config.showValues,T=Uo(l,[0,i.width],Zo(l,e.config.xExtent)),L=Zo(c,e.config.yExtent),C=Uo(c,[i.height,0],e.config.invertY?[L[1],L[0]]:L),R=(e,t)=>{let i=e(t-.5),r=e(t+.5);return[Math.min(i,r),Math.abs(r-i)]},N=e.config.heatmapValueFormat,D=[];for(let t=0;t<S;t++){let i=v[t];if(!isFinite(i))continue;let r=b[t],n=r%m,o=(r-n)/m,a=ra(i,A,M),s=_?_(i):P[a],l=I?{value:i,showValues:!0,valueFormat:N}:{value:i},c=w[t],[u,d]=R(T,n),[h,p]=R(C,o);D.push(la(Hn(u,h,d,p,s,c,l),c,e))}return e.scales&&m>0&&y>0&&(e.scales.x=T,e.scales.y=C),D},bar:function(e,t){if(!e.config.binSize)return{nodes:[],binBoundaries:[]};let i=fn(t,e.getX,e.getY,e.config.binSize,e.getCategory,!!e.config.trackHoverRows||ur(e.config.areaStyle),e.config.binAlign);if(0===i.size)return{nodes:[],binBoundaries:[]};let r=null;if(e.getCategory){let t=new Set;for(let e of i.values())for(let i of e.categories.keys())t.add(i);let n=e.config.barColors?Object.keys(e.config.barColors):[],o=new Set(n),a=Array.from(t).filter(e=>!o.has(e)).sort(),s=n.filter(e=>t.has(e)),l=s.join("\0")+""+a.join("\0");e.barCategoryCache&&e.barCategoryCache.key===l?r=e.barCategoryCache.order:(r=[...s,...a],e.barCategoryCache={key:l,order:r})}let n=[],o=e.scales,[a,s]=o.x.domain(),l=e.config.barStyle,c=e.config.themeSemantic?.primary,u=l?.gap,d="number"==typeof u&&u>=0?u:1,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.cursor);let p=function(e){if(!Array.isArray(e))return;let t=e.filter(e=>!!e&&("string"==typeof e.fill||"object"==typeof e.fill&&null!==e.fill)),i=t.filter(e=>"number"==typeof e.upTo&&Number.isFinite(e.upTo)).map(e=>({upTo:e.upTo,fill:e.fill})).sort((e,t)=>e.upTo-t.upTo),r=t.find(e=>"number"!=typeof e.upTo||!Number.isFinite(e.upTo)),n=r?[...i,{upTo:1/0,fill:r.fill}]:i;return n.length>0?n:void 0}(l?.valueBands);for(let t of i.values()){let i=Math.max(t.start,a),u=Math.min(t.end,s);if(i>=u)continue;let f=o.x(i),g=o.x(u),m=Math.abs(g-f),y=m>d+1?d:0,x=Math.min(f,g)+y/2,b=Math.max(m-y,1);if(!(b<=0))if(r&&t.categories.size>0){let i=ar(r.flatMap(e=>{let i=t.categories.get(e)||0;return 0===i?[]:[ar({category:e,value:i},t.categoryRows?.get(e))]}),t.rows),a=0;for(let{category:r,value:s}of i){let u=o.y(a),d=o.y(a+s),p=Math.min(u,d),f=Math.abs(u-d),g=(e.config.barColors?ti(e.config.barColors,r):void 0)??l?.fill??c??"#4e79a7",m=ar({binStart:t.start,binEnd:t.end,total:t.total,category:r,categoryValue:s,categories:i},t.categoryRows?.get(r)),y=e.config.areaStyle?.(m)??{};n.push(Vn(x,p,b,f,{fill:g,...h,...y},m,r)),a+=s}}else{let i=o.y(0),r=o.y(t.total),a=Math.min(i,r),s=Math.abs(i-r),u=l?.fill||c||"#007bff",d=ar({binStart:t.start,binEnd:t.end,total:t.total},t.rows),f=e.config.areaStyle?.(d)??{},g=Vn(x,a,b,s,{fill:u,...h,...f},d);if(p){let e=g.style.fill,i="string"==typeof e||"object"==typeof e&&null!==e&&"hatch"===e.type?e:void 0,r=ua(p,0,t.total,i);r.length>0&&(g.fillBands=r.map(e=>({y0:o.y(e.from),y1:o.y(e.to),fill:e.fill??u})))}n.push(g)}}let f=new Set;for(let e of i.values())f.add(e.start),f.add(e.end);return{nodes:n,binBoundaries:Array.from(f).sort((e,t)=>e-t)}},swarm:function(e,t){let i=[],r=e.config.swarmStyle||{},n=r.radius??3,o=r.fill??e.config.themeSemantic?.primary??"#007bff",a=r.opacity??.7,s=r.stroke,l=r.strokeWidth,c=r.cursor;for(let r of t){let t=e.getX(r),u=e.getY(r);if(null==u||Number.isNaN(u))continue;let d=e.scales.x(t),h=e.scales.y(u),p=o;if(e.getCategory){let t=String(e.getCategory(r));p=(e.config.barColors?ti(e.config.barColors,t):void 0)??p}let{r:f,...g}=e.config.pointStyle?.(r)??{},m={type:"point",x:d,y:h,r:f??n,style:{fill:p,opacity:a,stroke:s,strokeWidth:l,cursor:c,...g},datum:r};e.getPointId&&(m.pointId=String(e.getPointId(r))),i.push(m)}return i},waterfall:function(e,t,i){let r=[],n=e.scales,o=e.config.waterfallStyle,a=t.filter(t=>{let i=e.getY(t),r=e.getX(t);return null!=i&&!Number.isNaN(i)&&null!=r&&isFinite(r)});if(0===a.length)return r;let s=o?.positiveColor??e.config.themeSemantic?.success??"#28a745",l=o?.negativeColor??e.config.themeSemantic?.danger??"#dc3545",c=o?.gap??1,u=o?.stroke,d=o?.strokeWidth,h=o?.opacity,p=0;for(let t=0;t<a.length;t++){let f=a[t],g=e.getX(f),m=e.getY(f),y=p+m,x=n.x(g),b=t>0?n.x(e.getX(a[t-1])):void 0,v=t<a.length-1?n.x(e.getX(a[t+1])):void 0,w=null!=b?(b+x)/2:null!=v?x-(v-x)/2:x-i.width/20,k=null!=v?(x+v)/2:null!=b?x+(x-b)/2:x+i.width/20,S=Math.min(w,k)+c/2,A=Math.max(w,k)-c/2-S;if(A<=0){p=y;continue}let M=n.y(p),$=n.y(y),_=Math.min(M,$),P=Math.abs(M-$),I=m>=0?s:l,T={...f,baseline:p,cumEnd:y,delta:m,_connectorStroke:o?.connectorStroke,_connectorWidth:o?.connectorWidth},L={fill:I,stroke:u,strokeWidth:d,opacity:h,cursor:o?.cursor,...e.config.areaStyle?.(T)};r.push(Vn(S,_,A,P,L,T)),p=y}return r},candlestick:function(e,t,i){if(!e.getHigh||!e.getLow||!e.scales)return[];let r=e.config.candlestickRangeMode??!1;if(!(r||e.getOpen&&e.getClose))return[];let n=[],o=e.config.candlestickStyle||{},a=o.rangeColor||"#6366f1",s=r?a:o.upColor||"#28a745",l=r?a:o.downColor||"#dc3545",c=r?a:o.wickColor||"#333",u=o.wickWidth||(r?2:1),d=o.bodyWidth??0;if(null==o.bodyWidth){let i=t.map(t=>e.getX(t)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);if(i.length>1){let t=1/0,r=e.scales.x(i[0]);for(let n=1;n<i.length;n++){let o=e.scales.x(i[n]),a=Math.abs(o-r);a>0&&a<t&&(t=a),r=o}d=t!==1/0?Math.max(2,Math.min(.6*t,20)):6}else d=6}for(let a of t){let t=e.getX(a);if(null==t||Number.isNaN(t))continue;let h=e.getHigh(a),p=e.getLow(a);if(null==h||Number.isNaN(h)||null==p||Number.isNaN(p))continue;let f=r?h:e.getOpen(a),g=r?p:e.getClose(a);if(!r&&(null==f||Number.isNaN(f)||null==g||Number.isNaN(g)))continue;let m=g>=f,y=e.config.pointStyle?.(a)??{},x="string"==typeof y.fill?y.fill:void 0,b="string"==typeof y.stroke?y.stroke:void 0,v="number"==typeof y.strokeWidth?y.strokeWidth:void 0,w="number"==typeof y.opacity?y.opacity:"number"==typeof y.fillOpacity?y.fillOpacity:void 0,k={type:"candlestick",x:e.scales.x(t),openY:e.scales.y(f),closeY:e.scales.y(g),highY:e.scales.y(h),lowY:e.scales.y(p),bodyWidth:d,upColor:x&&m?x:s,downColor:x&&!m?x:l,wickColor:b??(r&&x?x:c),wickWidth:v??u,isUp:m,style:{cursor:o.cursor,...y,...void 0!==w&&{opacity:w}},datum:a};r&&(k.isRange=!0,k.dotRadius=Math.max(2,Math.min(d/2,.12*i.height))),n.push(k)}return n},custom:()=>[]};function ha(){for(let e of Object.keys(da))_n(e)||$n({chartType:e,buildScene:da[e],canvasRenderers:[]})}function pa(e){let t=e.parts.filter(e=>null!=e),i={};for(let e of t)for(let[t,r]of Object.entries(e.markCountByType))i[t]=(i[t]??0)+r;for(let[t,r]of Object.entries(e.additionalMarkCountByType??{}))r>0&&(i[t]=(i[t]??0)+r);let r=Object.values(i).reduce((e,t)=>e+t,0),n=0===r,o=Array.from(new Set([...t.flatMap(e=>e.warnings),...e.extraWarnings??[],...n?["EMPTY_SCENE"]:[]])),a="string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${r} marks`;return{component:"",frameType:e.frameType,status:n?"empty":"ok",empty:n,markCount:r,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:t.reduce((e,t)=>e+t.annotationCount,0),ariaLabel:a,warnings:o,semanticStatus:"not-assessed",semanticDiagnostics:[]}}function fa(e){let t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function ga(e){if(!e||e.length<2)return;let t=fa(e[0]),i=fa(e[e.length-1]);return null!==t&&null!==i?[t,i]:void 0}function ma(e){let{count:t,byType:i}=function(e){let t={};for(let i of e){let e="string"==typeof i?.type&&i.type.length>0?i.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),r=0===t,n=[...e.extraWarnings??[]];r&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),e.annotationRender&&e.annotationRender.unrenderedCount>0&&!n.includes("UNRENDERED_ANNOTATIONS")&&n.push("UNRENDERED_ANNOTATIONS");let o=Array.isArray(e.annotations)?e.annotations.length:0,a=e.annotationRender?.renderedCount??o,s="string"==typeof e.description&&e.description||ln(e.title)||`${e.frameType} chart, ${t} marks`,l=e.margin,c=l?{x:l.left,y:l.top,width:Math.max(1,e.width-l.left-l.right),height:Math.max(1,e.height-l.top-l.bottom)}:void 0;return{component:"",frameType:e.frameType,status:r?"empty":"ok",empty:r,markCount:t,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:a,...e.annotationRender?.layout?{layout:e.annotationRender.layout}:{},...e.annotationRender?{annotationInputCount:e.annotationRender.inputCount,unrenderedAnnotationCount:e.annotationRender.unrenderedCount,...e.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:e.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:s,warnings:n,semanticStatus:"not-assessed",semanticDiagnostics:[],...l?{margin:l}:{},...c?{plot:c}:{}}}import*as ya from"react";import{area as xa,line as ba}from"d3-shape";import{jsx as va,jsxs as wa}from"react/jsx-runtime";function ka(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function Sa(e,t){let{background:i="transparent",stroke:r="#000",lineWidth:n=1.5,spacing:o=6,angle:a=45,lineOpacity:s=1}=e,l=function(e){let t=Number.isFinite(e)&&e>0?e:6;return{width:Math.max(8,t),height:t,lineY:t/2}}(o);return wa("pattern",{id:t,width:l.width,height:l.height,patternUnits:"userSpaceOnUse",patternTransform:0!==a?`rotate(${a})`:void 0,children:[i&&"transparent"!==i&&"none"!==i&&va("rect",{width:l.width,height:l.height,fill:i}),va("line",{x1:0,y1:l.lineY,x2:l.width,y2:l.lineY,stroke:r,strokeWidth:n,...1!==s?{strokeOpacity:s}:{}})]},t)}import{curveMonotoneX as Aa,curveMonotoneY as Ma,curveCardinal as $a,curveCatmullRom as _a,curveStep as Pa,curveStepBefore as Ia,curveStepAfter as Ta,curveBasis as La,curveNatural as Ca}from"d3-shape";function Ra(e){switch(e){case"monotoneX":return Aa;case"monotoneY":return Ma;case"cardinal":return $a;case"catmullRom":return _a;case"step":return Pa;case"stepBefore":return Ia;case"stepAfter":return Ta;case"basis":return La;case"natural":return Ca;default:return null}}function Na(e,t,i){let r=i;for(let i of t)"lesser"===i.thresholdType?e<i.value&&(r=i.color):e>i.value&&(r=i.color);return r}import*as Da from"react";import{jsx as Fa,jsxs as Ea}from"react/jsx-runtime";var Oa={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function za(e,t="#4e79a7"){return ka(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function Ba(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`s_${t}`:t}function ja(e,t,i,r){let n=e.glyph;if(!n?.parts?.length||e.size<=0)return null;let o=d(n,e.size);if(o.scale<=0)return null;let a=`translate(${t},${i})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${o.offsetX},${o.offsetY}) scale(${o.scale})`,s=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),l=f(n,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),c=l?Ba(`${r}-clip`):void 0,u=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),h=t=>n.parts.map((i,r)=>{let n=t?"none"===i.fill?void 0:t:p(i.fill,s,e.accent),o=t?i.stroke&&"none"!==i.stroke?t:void 0:p(i.stroke??"none",s,e.accent);return n||o?Fa("path",{d:i.d,fill:n??"none",stroke:o,strokeWidth:o?i.strokeWidth??1:void 0,strokeLinecap:i.strokeLinecap,strokeLinejoin:i.strokeLinejoin,opacity:i.opacity},r):null});return Ea("g",{transform:a,opacity:1===u?void 0:u,children:[l&&c&&Fa("clipPath",{id:c,children:Fa("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&e.ghostColor?Fa("g",{children:h(e.ghostColor)}):null,l&&c?Fa("g",{clipPath:`url(#${c})`,children:h()}):h()]},r)}function Wa(e,t){let i=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return i.length<2?null:i.map((e,t)=>Fa("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}function Ya(e,t,i){let r=l(e.symbolType,e.size,e.path),n=e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`;return Fa("path",{d:r,transform:n,fill:e.style.fill?za(e.style.fill):"none",fillOpacity:e.style.fillOpacity,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},`${i??""}symbol-${t}`)}function qa(e,t,i){let r="point"===e.type,n=r?"circle":"rect",o=r?{cx:e.x,cy:e.y,r:e.r}:{x:e.x,y:e.y,width:e.w,height:e.h},a=`${i?`${i}-`:""}${r?"point":"xyrect"}-${t}-hatch`;if(!r&&e.fillBands&&e.fillBands.length>0)return function(e,t,i){let r=e.y,n=e.y+e.h,o=[],a=[];e.fillBands.forEach((t,s)=>{let l,c=Math.max(Math.min(t.y0,t.y1),r),u=Math.min(Math.max(t.y0,t.y1),n);if(u>c){if(ka(t.fill)){let e=`${i}-band-${s}`;o.push(Sa(t.fill,e)),l=`url(#${e})`}else l=za(t.fill);a.push(Fa("rect",{x:e.x,y:c,width:e.w,height:u-c,fill:l},s))}});let s=e.style.stroke&&"none"!==e.style.stroke;return Ea("g",{opacity:e.style.opacity,children:[o.length>0&&Fa("defs",{children:o}),a,s&&Fa("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},`rect-${t}`)}(e,t,a);let s=ka(e.style.fill)?Sa(e.style.fill,a):void 0;return Ea(Da.Fragment,{children:[s&&Fa("defs",{children:s}),Da.createElement(n,{...o,fill:s?`url(#${a})`:za(e.style.fill),opacity:r?e.style.opacity??e.style.fillOpacity??.8:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},`${e.type}-${t}`)}import*as Xa from"react";import{jsx as Ga}from"react/jsx-runtime";function Va(e){if(!1!==e?.interactive)return e?.style?.cursor}function Ha(e,t,i){let r=Va(t);return r&&null!=e&&!1!==e?Ga("g",{style:{cursor:r},"data-semiotic-mark-cursor":r,children:e},i):e}import{jsx as Ua,jsxs as Za}from"react/jsx-runtime";function Ka(e,t,i,r){if(!e||t.length<2)return null;let n=Wa(e.stops,r);return n?Ua("linearGradient",{id:i,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:n}):null}function Qa(e,t,i,r=30){let n=function(e,t,i,r=30){switch(e.type){case"line":{let r=e;if(0===r.path.length)return null;let n=Ra(r.curve),o=n?ba().x(([e])=>e).y(([,e])=>e).curve(n)(r.path)??"":"M"+r.path.map(([e,t])=>`${e},${t}`).join("L"),a=Ba(`${i?`${i}-`:""}line-${t}-stroke-gradient`),s=function(e){return"string"==typeof e&&"none"===e.trim().toLowerCase()}(r.style.stroke),l=s?null:Ka(r.strokeGradient,r.path,a,r.style.stroke||"#4e79a7");return Za(ya.Fragment,{children:[l&&Ua("defs",{children:l}),Ua("path",{d:o,fill:"none",stroke:l?`url(#${a})`:s?"none":r.style.stroke||"#4e79a7",strokeWidth:s?0:r.style.strokeWidth??2,strokeDasharray:r.style.strokeDasharray,opacity:r.style.opacity})]},`line-${t}`)}case"area":{let n=e;if(0===n.topPath.length)return null;let o=Ra(n.curve),a=o&&n.topPath.length>=2&&n.bottomPath.length>=2?xa().x(([e])=>e).y0((e,t)=>n.bottomPath[t][1]).y1(([,e])=>e).curve(o)(n.topPath)??"":`M${n.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...n.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`,s=`${i?`${i}-`:""}area-${t}-hatch`,l=ka(n.style.fill)?Sa(n.style.fill,s):void 0,c=Ba(`${i?`${i}-`:""}area-${t}-gradient`),u=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=1/0,n=-1/0;if(e.fillGradientSpan)[r,n]=e.fillGradientSpan;else{for(let[,t]of e.topPath)r=Math.min(r,t);for(let[,t]of e.bottomPath)n=Math.max(n,t)}if(!Number.isFinite(r)||!Number.isFinite(n))return null;let o=Wa(i.stops,za(e.style.fill));return o?Ua("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:r,x2:0,y2:n,children:o}):null}(n,c),d=u?`url(#${c})`:l?`url(#${s})`:za(n.style.fill),h=u?void 0:n.style.fillOpacity??.7,p=o?ba().x(([e])=>e).y(([,e])=>e).curve(o)(n.topPath)??"":"M"+n.topPath.map(([e,t])=>`${e},${t}`).join("L"),f=Va(n),g=f&&r>=0?Ua("path",{d:p,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*r),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:f},"data-semiotic-mark-cursor":f,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${t}-cursor-target`):null,m=Ba(`${i?`${i}-`:""}area-${t}-stroke-gradient`),y=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),x=!!n.strokeColorBands?.length,b=y||x?null:Ka(n.strokeGradient,n.topPath,m,n.style.stroke||"#4e79a7"),v=n.style.strokeWidth??2,w=1/0,k=-1/0;for(let[e]of n.topPath)e<w&&(w=e),e>k&&(k=e);let S=x?n.strokeColorBands.map((e,r)=>Ba(`${i?`${i}-`:""}area-${t}-stroke-band-${r}`)):[],A=x?n.strokeColorBands.map((e,t)=>Ua("clipPath",{id:S[t],children:Ua("rect",{x:w-v,y:e.y,width:k-w+2*v,height:e.height})},S[t])):null,M=n.style.stroke&&"none"!==n.style.stroke?x?n.strokeColorBands.map((e,i)=>Ua("path",{d:p,fill:"none",stroke:e.color??za(n.style.stroke),strokeWidth:v,opacity:(n.style.opacity??1)*(e.opacity??1),clipPath:`url(#${S[i]})`},`area-${t}-stroke-band-${i}`)):y?function(e,t,i,r){if(e.length<2||t.length!==e.length||0===i.length)return[];let n=[],o=(e,t,i)=>{let r=n[n.length-1];r?.color===e?r.path.push(i):n.push({color:e,path:[t,i]})};for(let n=1;n<e.length;n++){let[a,s]=e[n-1],[l,c]=e[n],u=t[n-1],d=t[n]-u,h=[0,...0===d?[]:i.map(({value:e})=>(e-u)/d).filter(e=>e>0&&e<1&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,i)=>0===t||e!==i[t-1]),1];for(let e=1;e<h.length;e++){let t=h[e-1],n=h[e];o(Na(u+d*((t+n)/2),i,r),[a+(l-a)*t,s+(c-s)*t],[a+(l-a)*n,s+(c-s)*n])}}return n}(n.topPath,n.rawValues,n.colorThresholds,za(n.style.stroke)).map((e,i)=>Ua("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:v,opacity:n.style.opacity},`area-${t}-threshold-${i}`)):Ua("path",{d:p,fill:"none",stroke:b?`url(#${m})`:za(n.style.stroke),strokeWidth:v,opacity:n.style.opacity}):null;if(n.clipRect){let e=`${i?`${i}-`:""}area-clip-${t}`;return Za("g",{children:[Za("defs",{children:[u,!u&&l,b,A,Ua("clipPath",{id:e,children:Ua("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),Za("g",{clipPath:`url(#${e})`,children:[Ua("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]})]},`area-${t}`)}return Za(ya.Fragment,{children:[(u||l||b||A)&&Za("defs",{children:[u,!u&&l,b,A]}),Ua("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]},`area-${t}`)}case"point":case"rect":return qa(e,t,i);case"symbol":return Ya(e,t);case"glyph":{let r=e;return ja(r,r.x,r.y,`${i??""}glyph-${r.pointId??t}`)}case"heatcell":{let i=e,r={x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill,stroke:i.style?.stroke,strokeWidth:i.style?.strokeWidth,...null!=i.style?.opacity&&{opacity:i.style.opacity}};if(i.showValues&&null!=i.value&&i.w>=20&&i.h>=20){let e=i.valueFormat?i.valueFormat(i.value):Number.isInteger(i.value)?String(i.value):Math.abs(i.value)>=100?i.value.toFixed(0):Math.abs(i.value)>=1?i.value.toFixed(1):i.value.toPrecision(3),[n,o,a]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(i.fill),s=.299*n+.587*o+.114*a>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h)));return Za("g",{children:[Ua("rect",{...r}),Ua("text",{className:"semiotic-heatmap-value",x:i.x+i.w/2,y:i.y+i.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:`${l}px`,fontFamily:"var(--semiotic-font-family, sans-serif)",children:e})]},`heatcell-${t}`)}return Ua("rect",{...r},`heatcell-${t}`)}case"candlestick":{let r=e,n=`${i?`${i}-`:""}candle-${t}-hatch`,o=ka(r.style?.fill)?Sa(r.style.fill,n):void 0,a=o?`url(#${n})`:void 0,{fill:s,...l}=r.style??{};if(r.isRange){let e=r.dotRadius??Math.max(2,r.bodyWidth/2),i=a??r.wickColor;return Za(ya.Fragment,{children:[o&&Ua("defs",{children:o}),Za("g",{style:l,children:[Ua("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),Ua("circle",{cx:r.x,cy:r.highY,r:e,fill:i,opacity:r.style?.opacity}),Ua("circle",{cx:r.x,cy:r.lowY,r:e,fill:i,opacity:r.style?.opacity})]})]},`candle-${t}`)}let c=Math.min(r.openY,r.closeY),u=Math.max(Math.abs(r.openY-r.closeY),1),d=r.isUp?r.upColor:r.downColor,h=a??d;return Za(ya.Fragment,{children:[o&&Ua("defs",{children:o}),Za("g",{style:l,children:[Ua("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),Ua("rect",{x:r.x-r.bodyWidth/2,y:c,width:r.bodyWidth,height:u,fill:h,stroke:a?r.wickColor:d,strokeWidth:1,opacity:r.style?.opacity})]})]},`candle-${t}`)}default:return null}}(e,t,i,r);return"area"===e.type?n:Ha(n,e,`xy-cursor-${t}`)}var Ja=/*#__PURE__*/new Set;function es(e){let{node:t,index:i,renderMode:r,fallback:n}=e,o=function(e,t){let i="function"==typeof e?e(t.datum??null,t):e;return function(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&"function"==typeof t.cacheKey&&"function"==typeof t.drawCanvas&&"function"==typeof t.renderStaticSVG}(i)?i:void 0}(r,t);if(!o)return{element:n(),renderedByBackend:!1};let a=o.renderStaticSVG({node:t,style:t.style??{},key:`${o.id}-${i}`});return null!=a?{element:Ha(a,t,`${o.id}-${i}-cursor`),renderedByBackend:!0}:(function(e,t){if("production"===process.env.NODE_ENV)return;let i=`${e}:${t}`;Ja.has(i)||(Ja.add(i),console.warn(`[Semiotic] Render backend "${e}" does not support scene node "${t}"; using the built-in renderer.`))}(o.id,t.type??"unknown"),{element:n(),renderedByBackend:!1})}function ts(e){let t=[];return e.nodes.forEach((i,r)=>{let n=es({node:i,index:r,renderMode:e.renderMode,fallback:()=>e.fallback(i,r)});null!==n.element&&void 0!==n.element&&!1!==n.element&&t.push({node:i,index:r,...n})}),t}import{scaleOrdinal as is}from"d3-scale";import{jsx as rs,jsxs as ns}from"react/jsx-runtime";function os(e,t,i){if(t&&"object"==typeof t&&!Array.isArray(t)){let e=t;return t=>ti(e,t)??"#999"}let r=Array.isArray(t)?t:i.colors.categorical.length>0?i.colors.categorical:Tt;return is().domain(e).range(r)}function as(e,t,i){if(0===e.length)return;let r=os(e,t,i);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:r(e.label)})}]}}function ss(e){return"left"===e?"start":"right"===e?"end":e??"start"}function ls(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function cs(e){return e.typography.legendFontFamily??e.typography.fontFamily}function us(e){return e.typography.legendFontWeight}function ds(e,t,i,r){let n=ls(r);return t+i+Math.ceil(e.length*n*.58)}function hs(e){let{categories:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,itemGap:c,rowHeight:u}=Re(a),d=s+l,h="top"===r||"bottom"===r,p=Math.max(s,n-o.left-o.right),f=t.map(e=>ds(e,s,l,i));if(h){let e=Math.max(s,a?.maxWidth??p),i=[],r=0,n=0;f.forEach((t,o)=>{let a=0===n?t:n+c+t;n>0&&a>e?(i.push({start:r,end:o,width:n}),r=o,n=t):n=a}),t.length>0&&i.push({start:r,end:t.length,width:n});let o=ss(a?.align),l=[];return i.forEach((i,r)=>{let n="center"===o?Math.max(0,(e-i.width)/2):"end"===o?Math.max(0,e-i.width):0;for(let e=i.start;e<i.end;e++)l.push({category:t[e],width:f[e],x:n,y:r*u}),n+=f[e]+c}),{items:l,width:i.reduce((e,t)=>Math.max(e,t.width),0),height:i.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}let g=f.reduce((e,t)=>Math.max(e,t),0);return{items:t.map((e,t)=>({category:e,width:f[t],x:0,y:t*u})),width:g,height:t.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}function ps(e,t){if(!t||!e||0===e.length)return[];let i="function"==typeof t?t:e=>e[t],r=new Set;for(let t of e){let e=i(t);null!=e&&r.add(String(e))}return Array.from(r)}import*as fs from"react";var gs=(e,t)=>({width:Array.from(e).length*t.size*.65,height:1.2*t.size,ascent:.9*t.size,source:"estimated"});function ms(e){let{desired:t,minGaps:i,weights:r}=e,n=t.length;if(0===n)return[];if(i.length!==Math.max(0,n-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let o=new Array(n).fill(0);for(let e=1;e<n;e++)o[e]=o[e-1]+Math.max(0,Number.isFinite(i[e-1])?i[e-1]:0);let a=[];for(let e=0;e<n;e++){let i=Math.max(Number.EPSILON,Number.isFinite(r?.[e])?r[e]:1),n=(Number.isFinite(t[e])?t[e]:0)-o[e];for(a.push({start:e,end:e,weight:i,mean:n});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.mean<=e.mean)break;let i=t.weight+e.weight;a.splice(a.length-2,2,{start:t.start,end:e.end,weight:i,mean:(t.mean*t.weight+e.mean*e.weight)/i})}}let s=Number.isFinite(e.min)?e.min:-1/0,l=Number.isFinite(e.max)?e.max-o[n-1]:1/0,c=l<s?s:l,u=new Array(n);for(let e of a){let t=Math.max(s,Math.min(c,e.mean));for(let i=e.start;i<=e.end;i++)u[i]=t+o[i]}return u}var ys={INVALID_PROJECTION:"Check endpoint values and the scale domain, especially log-scale values.",INSUFFICIENT_SPACE:"Increase chart height or the label-side margin, or reduce the label font size.",TIED_ENDPOINTS:"Use connectors or a legend to distinguish series sharing an endpoint.",LABEL_OMITTED:"Consult the accessible series list; increase the label rail space to restore visible labels.",ESTIMATED_METRICS:"Load the intended font and remeasure before asserting collision-free text.",RENDER_FAILURE:"Inspect the annotation renderer; the placed label did not produce a node.",UNSUPPORTED_GEOMETRY:"Inspect custom-rendered text; its geometry has not been measured by the label solver.",LABEL_COLLISION:"Increase spacing or shorten the affected labels.",LABEL_OVERFLOW:"Increase the allocated bounds or shorten the affected labels."};import{jsx as xs,jsxs as bs}from"react/jsx-runtime";function vs(e){return"string"==typeof e&&e.includes("var(")}var ws=/^\s*var\(\s*--[^,)\s]+\s*(?:,\s*([\s\S]*))?\)\s*$/;function ks(e){let t=ws.exec(e);if(!t)return vs(e)?void 0:e;let i=t[1]?.trim();return i?ks(i):void 0}import{jsx as Ss,jsxs as As}from"react/jsx-runtime";var Ms="var(--semiotic-bg, #ffffff)";function $s(e,t){return String(e).length*t*.6}function _s(e){let{x:t,y:i,text:r,fill:n,fontSize:o=12,fontWeight:a,fontFamily:s,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{...e,type:e.type??"halo"}}(u),p=e=>Ss("text",{x:t,y:i,textAnchor:l,dominantBaseline:c,fill:n,fontSize:o,fontWeight:a,fontFamily:s,className:d,...e?{style:{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}}:{},children:r});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??Ms,strokeWidth:h.haloWidth??3});let f,g,m=h.padding??{x:6,y:3},y="number"==typeof m?m:m.x,x="number"==typeof m?m:m.y,b=$s(r,o),v=b+2*y,w=o+2*x;f="middle"===l?t-b/2-y:"end"===l?t-b-y:t-y,g="middle"===c||"central"===c?i-w/2:"hanging"===c||"text-before-edge"===c?i-x:i-.8*o-x;let k=h.fill??Ms,S={};return vs(k)&&(S.fill=k),vs(h.stroke)&&(S.stroke=h.stroke),As("g",{className:d,children:[Ss("rect",{x:f,y:g,width:v,height:w,rx:h.radius??3,ry:h.radius??3,fill:vs(k)?ks(k):k,fillOpacity:h.opacity??.85,stroke:vs(h.stroke)?ks(h.stroke):h.stroke,strokeWidth:h.strokeWidth,...S.fill||S.stroke?{style:S}:{}}),p()]})}import{jsx as Ps}from"react/jsx-runtime";function Is(e,t,i){if(!e)return null;let r="object"==typeof e?e:{};return Ps("circle",{className:"semiotic-threshold-end-cap",cx:t[0],cy:t[1],r:Math.max(0,r.radius??4),fill:r.fill??i})}import{jsx as Ts,jsxs as Ls}from"react/jsx-runtime";function Cs({ann:e,position:t,vertical:i,width:r,height:n,color:o,fontSize:a=12,fontFamily:s,bold:l,background:c,dash:u="6,3",labelGap:d=4}){let h=e.labelPosition,p=t>.6*r,f=i?t+(p?-4:4):"left"===h?4:"center"===h?r/2:r-4,g=i?"bottom"===h?n-4:"center"===h?n/2:16:t<20?Math.min(n-4,t+16):t-d,m=i?p?"end":"start":"left"===h?"start":"center"===h?"middle":"end",y=i?[t,0]:[0,t],x=i?[t,n]:[r,t];return Ls("g",{opacity:e.opacity,children:[Ts("line",{x1:y[0],y1:y[1],x2:x[0],y2:x[1],stroke:o,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||u}),Is(e.endCap,y,o),e.label&&Ts(_s,{x:f,y:g,text:e.label,textAnchor:m,fill:e.labelColor??o,fontSize:a,fontFamily:s,fontWeight:l?"bold":void 0,background:c??e.labelBackground??"halo"})]})}function Rs(e){return{label:e.label,title:e.title,wrap:e.wrap||120,noWrap:"function"==typeof e._noteLayout?e.noWrap:void 0,_noteLayout:e._noteLayout}}function Ns(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}function Ds(e,t,i){if(!e)return[];let r=Math.max(1,Math.floor(t/i)),n=[],o="";for(let t of e.split(/\s+/))t&&(o&&o.length+1+t.length>r?(n.push(o),o=t):o=o?`${o} ${t}`:t);return o&&n.push(o),n}import{jsx as Fs,jsxs as Es}from"react/jsx-runtime";function Os(e,t,i,r){return"curly"===e?r?`M0,0 C${.6*i},0 ${.4*i},${t/2} ${i},${t/2} C${.4*i},${t/2} ${.6*i},${t} 0,${t}`:`M0,0 C0,${.6*i} ${t/2},${.4*i} ${t/2},${i} C${t/2},${.4*i} ${t},${.6*i} ${t},0`:r?`M0,0 L${i},0 L${i},${t} L0,${t}`:`M0,0 L0,${i} L${t},${i} L${t},0`}function zs(e,t,i,r){if(!e)return Fs("g",{className:"annotation-note"});let{label:n,title:o,orientation:a,align:s,wrap:l=120,noWrap:c}=e;if(!n&&!o)return Fs("g",{className:"annotation-note"});let u=a;u||(u=Math.abs(t)>Math.abs(i)?"leftRight":"topBottom");let d="topBottom"===u,h="leftRight"===u,p=s;(!p||"dynamic"===p)&&(p=d?t>=0?"left":"right":i>=0?"top":"bottom");let f="start";d?"right"===p?f="end":"middle"===p&&(f="middle"):f=t>=0?"start":"end";let g=e.useHTML||e.html,m=g?void 0:Ns(e),y=m?.lineHeight??16,x=m?.titleLines??(o?c?[o]:Ds(o,l,8):[]),b=m?.labelLines??(n?c?[n]:Ds(n,l,8):[]),v=x.length+b.length,w=h?"end"===f?-4:4:0,k=[],S=r||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";if(g){let e=l,t=Math.max(y,v*y+(o&&n?2:0)),i="end"===f?w-e:"middle"===f?w-e/2:w,r="end"===f?"right":"middle"===f?"center":"left";k.push(Fs("foreignObject",{className:"annotation-note-html",x:i,y:-y,width:e,height:t+y,style:{overflow:"visible"},children:Es("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:S,fontSize:"12px",lineHeight:`${y}px`,overflow:"visible",textAlign:r,whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[o&&Fs("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:o}),n&&Fs("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html"))}else for(let e of[!0,!1]){let t=e?x:b;if(0===t.length)continue;let i="annotation-note-"+(e?"title":"label");k.push(Fs("text",{className:i,fill:S,textAnchor:f,fontWeight:e?m?.titleFontWeight??"bold":void 0,y:e?void 0:x.length*y,children:t.map((e,t)=>Fs("tspan",{x:w,dy:0===t?0:y,children:e},t))},i))}let A=null;if((o||n)&&(0!==t||0!==i)){let e=d?m?m.width:Math.min(l,120):(x.length+b.length+(b.length>0?1:0))*y,t=d?f:p,i="end"===t||"bottom"===t?-e:"middle"===t?-e/2:0;A=Fs("line",{className:"note-line",x1:d?i:0,x2:d?i+e:0,y1:d?0:i,y2:d?0:i+e,stroke:r||"var(--semiotic-text-secondary, currentColor)"})}let M=Math.max(0,v-1)*y,$=b.length>0&&x.length>0?2:0,_=0;(d||h)&&(_=h&&"middle"===p?-(M+y+$)/2+y/2:i<0||h&&"bottom"===p?-(M+2):2+y);let P=0!==_?`translate(0,${_})`:void 0;return Es("g",{className:"annotation-note",transform:`translate(${t},${i})`,...m?.textProps,children:[Fs("g",{className:"annotation-note-content",transform:P,children:k}),A]})}function Bs(e,t,i,r,n){let o=null,a=i||"var(--semiotic-text-secondary, currentColor)";switch(e){case"callout-circle":{let e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&(o=Fs("circle",{r:e,fill:"none",stroke:a},"subject-circle"));break}case"callout-rect":{let e=t?.width||0,i=t?.height||0;(e>0||i>0)&&(o=Fs("rect",{width:e,height:i,fill:"none",stroke:a},"subject-rect"));break}case"callout-custom":o=t?.custom;break;case"xy-threshold":{let e=r||0,i=n||0,s=0,l=0,c=0,u=0;if(void 0!==t?.x)s=l=(t.x||0)-e,c=(t.y1||0)-i,u=(t.y2||0)-i;else if(void 0!==t?.y)c=u=(t.y||0)-i,s=(t.x1||0)-e,l=(t.x2||0)-e;else if(void 0!==t?.x1||void 0!==t?.x2)s=(t.x1||0)-e,l=(t.x2||0)-e;else{if(void 0===t?.y1&&void 0===t?.y2)break;c=(t.y1||0)-i,u=(t.y2||0)-i}o=Fs("line",{x1:s,y1:c,x2:l,y2:u,stroke:a,strokeDasharray:"5,5"},"threshold-line");break}case"bracket":{let e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&(o=Fs("path",{d:Os(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:a},"bracket-path"));break}}return Fs("g",{className:"annotation-subject",children:o})}function js(e,t,i,r,n,o){let a,s,l=0,c=0;if("callout-circle"!==n&&"label"!==n||!o?.radius){if("callout-rect"===n&&o){let i=o.width||0,r=o.height||0;if(i>0||r>0){let n=i/2,o=r/2,a=e-n,s=t-o;if(0!==a||0!==s){let e=Math.abs(a),t=Math.abs(s),u=i/2,d=r/2,h=e*d>t*u?u/e:d/t;l=n+a*h,c=o+s*h}}}else if("bracket"===n&&o){let e=o.width,t=o.height,i=o.depth||30;void 0!==e?(l=e/2,c=i):void 0!==t&&(l=i,c=t/2)}}else{let i=(o.radius||0)+(o.radiusPadding||0);if(i>0&&(0!==e||0!==t)){let r=Math.atan2(t,e);l=Math.cos(r)*i,c=Math.sin(r)*i}}let u=e-l,d=t-c,h=Math.hypot(u,d);if(h>.5){let n=r||"var(--semiotic-text-secondary, currentColor)",o="curve"===i?.type,p=Math.atan2(d,u);if(o){let r=(l+e)/2,o=(c+t)/2,s=-d/h,f=u/h,g=(i?.curve??.25)*h,m=r+s*g,y=o+f*g;a=Fs("path",{className:"connector-curve",d:`M${l},${c}Q${m},${y} ${e},${t}`,fill:"none",stroke:n},"connector-line"),p=Math.atan2(y-c,m-l)}else a=Fs("line",{x1:l,y1:c,x2:e,y2:t,stroke:n},"connector-line");if("arrow"===i?.end){let e=.08888888888888889*Math.PI,t=l+10*Math.cos(p+e),i=c+10*Math.sin(p+e),r=l+10*Math.cos(p-e),o=c+10*Math.sin(p-e);s=Fs("path",{d:`M${l},${c}L${t},${i}L${r},${o}Z`,fill:n,stroke:"none"},"connector-arrow")}}return Es("g",{className:"annotation-connector",children:[a,s]})}function Ws(e){let{x:t=0,y:i=0,dx:r,dy:n,nx:o,ny:a,note:s,connector:l,subject:c,type:u,color:d,className:h,disable:p,opacity:f,strokeDasharray:g,events:m={},"data-testid":y}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(i)?i[0]??0:i,v=Array.isArray(p)?p:[],w=r||0,k=n||0;null!=o&&(w=o-x),null!=a&&(k=a-b);let S="string"==typeof u?u:"label";if("bracket"===S&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;let e=c.depth||30;k=e+(e>=0?5:-5)}else if(void 0!==c.height){let e=c.depth||30;w=e+(e>=0?5:-5),k=c.height/2}return Es("g",{className:`annotation ${h||""}`.trim(),transform:`translate(${x},${b})`,"data-testid":y,...null!=f&&{opacity:f},...g&&{strokeDasharray:g},...m,children:[!v.includes("connector")&&js(w,k,l,d,S,c),!v.includes("subject")&&Bs(S,c,d,x,b),!v.includes("note")&&zs(s,w,k,d)]})}function Ys(e){let{noteData:t}=e,{screenCoordinates:i}=t,r="string"==typeof t.type?t.type:"label",n=t.eventListeners||t.events||{};if(t.coordinates&&i){let e=t.nx||i[0][0]+(t.dx??0),n=t.ny||i[0][1]+(t.dy??0),o=i.map((i,o)=>{let a=Object.assign({},t,{note:0===o?t.note:{label:""},x:i[0],y:i[1],nx:e,ny:n});return Fs(Ws,{"data-testid":"semiotic-annotation",...a,type:r},`multi-annotation-${o}`)});return Fs("g",{children:o})}let o=t.note||{title:"none",label:t.label},a=`${o.label}-${o.title}-${t.i}`;return Fs(Ws,{"data-testid":"semiotic-annotation",events:n,...t,type:r},a)}import{jsx as qs}from"react/jsx-runtime";var Xs={secondary:0,primary:3};function Gs(e){return!0===e?._annotationDeferred}function Vs(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Hs(e){return"primary"===e?.emphasis||"secondary"===e?.emphasis?e.emphasis:null}function Us(e){let t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function Zs(e){return Math.max(.72,.95-.06*e)}function Ks(e){let t=e.map((e,t)=>({p:e,i:t,emphasis:Hs(e.annotation),confidence:Us(e.annotation),readingOrder:null,rank:1})),i=t.some(e=>null!=e.emphasis||null!=e.confidence),r=e.some(e=>Gs(e.annotation)),n=e.some(e=>null!=Vs(e.annotation)),o=e.some(e=>"layer"===Vs(e.annotation));if(!i&&!r&&!n)return e.map(e=>e.node);let a=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);a.forEach((e,t)=>{e.readingOrder=t,e.rank=2-t/Math.max(1,a.length)});for(let e of t)e.emphasis&&(e.rank=Xs[e.emphasis]);let s=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{let{p:t,i:i,emphasis:r,readingOrder:n}=e,o=Gs(t.annotation),a=t.node;if("primary"===r||"secondary"===r||null!=n){let e=null==r&&null!=n;a=qs("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":`annotation-emphasis annotation-emphasis--${r}`,..."secondary"===r?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:Zs(n),"data-annotation-reading-order":n}:{},children:t.node},`annotation-emphasis-${i}`)}let s=Vs(t.annotation);return s&&(a=qs("g",{className:`annotation-cohesion--${s}`,children:a},`annotation-cohesion-${i}`)),o&&(a=qs("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:a},`annotation-deferred-${i}`)),a});return r&&s.unshift(qs("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),o&&s.unshift(qs("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),s}function Qs(e,t){let i=t.scales?.x??t.scales?.time;return i?null!=e.x?Qo(i,e.x):t.xAccessor&&null!=e[t.xAccessor]?Qo(i,e[t.xAccessor]):null:null}function Js(e,t){let i=t.scales?.y??t.scales?.value;return i?null!=e.y?Qo(i,e.y):t.yAccessor&&null!=e[t.yAccessor]?Qo(i,e[t.yAccessor]):null:null}function el(e){return null==e?null:String(e)}function tl(e,t,i){return t.stickyPositionCache?.set(e,i),i}function il(e,t,i){let r=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===r){if(null!=e.pointId&&i.pointNodes&&i.pointNodes.length>0)for(let r=i.pointNodes.length-1;r>=0;r--){let n=i.pointNodes[r];if(n.pointId===e.pointId)return tl(t,i,{x:n.x,y:n.y})}let r=function(e){let t=e.data;if(!t||0===t.length)return null;let i=t[t.length-1],r=e.scales?.x??e.scales?.time,n=e.scales?.y??e.scales?.value;if(!r||!n)return null;let o=e.xAccessor||"x",a=e.yAccessor||"y",s=i[o],l=i[a];if(null==s||null==l)return null;let c=Qo(r,s),u=Qo(n,l);return null==c||null==u?null:{x:c,y:u}}(i);return r?tl(t,i,r):null}if("semantic"===r){let r=function(e,t,i){let r=function(e){return el(e.provenance?.stableId??e.stableId)}(e);if(!r)return null;let n=i.pointNodes?.find(e=>el(e.pointId)===r);if(n)return tl(t,i,{x:n.x,y:n.y});let o=i.data?.find(e=>function(e){return el(e.stableId??e.id??e.provenance?.stableId)}(e)===r);if(!o)return null;let a=Qs(o,i),s=Js(o,i);return null==a||null==s?null:tl(t,i,{x:a,y:s})}(e,t,i);if(r)return r}let n=null,o=null;if(null!=e.pointId&&i.pointNodes){let t=i.pointNodes.find(t=>t.pointId===e.pointId);t&&(n=t.x,o=t.y)}if((null==n||null==o)&&(n=Qs(e,i),o=Js(e,i)),null!=n&&null!=o)return tl(t,i,{x:n,y:o});if("sticky"===r){let e=i.stickyPositionCache?.get(t);if(e)return e}return null}var rl=/*#__PURE__*/new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function nl(e){return!!e&&"object"==typeof e&&rl.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function ol(e,t,i){return Math.max(t,Math.min(i,e))}function al(e){return nl(e)}function sl(e){return"primary"===e?.emphasis||!0===e?.defensive}function ll(e,t,i={}){if("number"==typeof i.maxAnnotations&&Number.isFinite(i.maxAnnotations))return Math.max(0,Math.floor(i.maxAnnotations));if(!(e>0&&t>0))return 1/0;let r=i.areaPerAnnotation&&i.areaPerAnnotation>0?i.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/r))}function cl(e){let t,i=e?.emphasis;t="primary"===i?100:"secondary"===i?10:50;let r=e?.provenance?.confidence;switch("number"==typeof r&&Number.isFinite(r)&&(t+=15*ol(r,0,1)),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}var ul=32,dl=6,hl=4,pl=8,fl=72,gl={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function ml(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let i="string"==typeof t.source?Object.prototype.hasOwnProperty.call(gl,t.source)?gl[t.source]:t.source:null,r="number"==typeof t.confidence&&Number.isFinite(t.confidence)?`${Math.round(100*Math.max(0,Math.min(1,t.confidence)))}%`:null;if(!i&&!r||null!=e.label&&"string"!=typeof e.label)return e;let n=[i,r].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${n})`)?e:{...e,label:o?`${o} (${n})`:`(${n})`}}function yl(e){if(!xl(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,i="string"==typeof e.shortText?e.shortText:void 0,r=t??i;return!r||"string"!=typeof e.label&&null!=e.label?e:{...e,label:r}}function xl(e){return nl(e)}function bl(e,t,i,r,n){let o=e+i,a=t+r;return Math.abs(i)>Math.abs(r)?{x:i>=0?o+4:o-n.width-4,y:r<0?a-n.height:a,width:n.width,height:n.height}:{x:i>=0?o:o-n.width,y:r<0?a-n.height-4:a+4,width:n.width,height:n.height}}function vl(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function wl(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function kl(e,t,i,r,n,o,a,s){let l=vl(e,a),c=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,i,r){let n=Math.max(0,r-e.x),o=Math.max(0,r-e.y),a=Math.max(0,e.x+e.width-(t-r)),s=Math.max(0,e.y+e.height-(i-r));return(n+a)*e.height+(o+s)*e.width}(l,n,o,s);for(let e of i)c+=12*wl(l,e);for(let e of r)c+=4*wl(l,e);return c}function Sl(e){let{annotations:t,context:i,defaultOffset:r=ul,notePadding:n=dl,markPadding:o=hl,edgePadding:a=pl,preserveManualOffsets:s=!0,routeLongConnectors:l=!0,connectorThreshold:c=fl,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:g,audience:m}=e,y=i.width||0,x=i.height||0,b="object"==typeof f?f:{},v=b.breakpoint??480,w=!!f&&y<=v,k=w&&!1!==b.preferShortText?t.map(yl):t,S=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!p?b.responsive??{minWidth:v}:p,$=w&&!g?b.cohesion:g;if(0===k.length||y<=0||x<=0)return k.slice();let _=[],P=function(e,t){return(e.pointNodes||[]).map(e=>{let i=Math.max(1,e.r||1)+t;return{x:e.x-i,y:e.y-i,width:2*i,height:2*i}})}(i,o),I=!1,T=k.map((e,t)=>{if(!xl(e))return e;let o=function(e,t,i){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};let r=e.pointId??e.nodeId;if(null!=r&&i.pointNodes){let e=i.pointNodes.find(e=>e.pointId===r);if(e)return{x:e.x,y:e.y}}let n=e.coordinates,o=i.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&o){let e=n[0],t=n[1];if("number"==typeof e&&"number"==typeof t){let i=o([e,t]);if(i&&"number"==typeof i[0]&&"number"==typeof i[1])return{x:i[0],y:i[1]}}}return i.scales||"number"!=typeof e.x||"number"!=typeof e.y?il(e,t,i):{x:e.x,y:e.y}}(e,t,i);if(!o)return e;let u=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=Ns(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let i="number"==typeof e.wrap?e.wrap:120,r=[...Ds("string"==typeof e.title?e.title:void 0,i,7),...Ds("string"==typeof e.label?e.label:void 0,i,7)],n=r.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(i,7*n)+10),height:Math.max(18,16*r.length+6)}}(!0===e.defensive?ml(e):e);if(s&&function(e){return"number"==typeof e.dx||"number"==typeof e.dy}(e)){let t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e),i="number"==typeof e.dx?e.dx:t.dx,r="number"==typeof e.dy?e.dy:t.dy;return _.push(vl(bl(o.x,o.y,i,r,u),n)),e}let d=null,h=1/0;for(let e of function(e){let t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}(r)){let t=kl(bl(o.x,o.y,e.dx,e.dy,u),e,_,P,y,x,n,a);t<h&&(d=e,h=t)}if(!d)return e;let p=vl(bl(o.x,o.y,d.dx,d.dy,u),n);_.push(p);let f=Math.hypot(d.dx,d.dy),g=l&&f>=c&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return I=!0,{...e,dx:d.dx,dy:d.dy,...g?{connector:g}:{}}}),L=I?T:k.slice(),C=L;if(h){let e=!1,t=L.map(t=>{let i=function(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,i="number"==typeof e.dy?e.dy:0;return Math.hypot(t,i)<8?e:{...e,_redundantConnector:!0}}(t);return i!==t&&(e=!0),i});C=e?t:L}{let e=!1,t=C.map(t=>{if(!0!==t?.defensive)return t;let i=ml(t);return i!==t&&(e=!0),i});C=e?t:C}let R,N=new Set;if(S){let e="object"==typeof S?S:{},t=function(e){if(!e)return 1;let t=function(e){let t=e?.familiarity;if(!t)return 3;let i=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===i.length?3:i.reduce((e,t)=>e+t,0)/i.length}(e);return t<=2?1.5:t>=4?.6:1}(m),i=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??ll(y,x,e))*t))},{deferred:r}=function(e){let{annotations:t,width:i,height:r}=e,n=Math.max(0,e.minVisible??1),o=ll(i,r,e),a=t.map((e,t)=>({annotation:e,index:t,note:al(e)})),s=a.filter(e=>e.note);if(0===s.length||s.length<=o)return{visible:t.slice(),deferred:[],budget:o};let l=s.filter(e=>sl(e.annotation)),c=s.filter(e=>!sl(e.annotation)).sort((e,t)=>cl(t.annotation)-cl(e.annotation)||e.index-t.index),u=Math.max(0,o-l.length),d=Math.max(0,n-l.length),h=Math.min(c.length,Math.max(u,d)),p=new Set([...l.map(e=>e.index),...c.slice(0,h).map(e=>e.index)]),f=[],g=[];for(let{annotation:e,index:t,note:i}of a)!i||p.has(t)?f.push(e):g.push(e);return{visible:f,deferred:g,budget:o}}({annotations:C,width:y,height:x,...i});for(let e of r)N.add(e)}if(M){let e="object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:480;if(y<=e)for(let e of C)xl(e)&&"secondary"===e.emphasis&&N.add(e)}if(N.size>0)for(let e of C)!0===e?.defensive&&N.delete(e);return R=0===N.size?C:A?C.map(e=>N.has(e)?{...e,_annotationDeferred:!0}:e):C.filter(e=>!N.has(e)),$?function(e,t){let i=!1,r=e.map(e=>xl(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(i=!0,{...e,cohesion:t}):e);return i?r:e}(R,$):R}function Al(e,t,i,r){let n=function(e,t,i="#4e79a7"){if(ka(e)){let i=function(e,t){return`${e}-hatch-${b(function(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}(t)).toString(36)}`}(t,e);return{fill:`url(#${i})`,def:Sa(e,i)}}return e&&"string"==typeof e?{fill:e}:{fill:i}}(e.fill??e.color,t,r),o="string"==typeof e.fill&&e.fill?e.fill:"string"==typeof e.color&&e.color?e.color:r;return function(e,t,i,r){let n=function(e,t,i){if(!e||"object"!=typeof e)return;let r=e;if(!Array.isArray(r.stops))return;let n=r.stops.flatMap(e=>{if(!e||"object"!=typeof e)return[];let{offset:t,color:r,opacity:n}=e;return"number"==typeof t&&Number.isFinite(t)?[{offset:Math.max(0,Math.min(1,t)),color:"string"==typeof r&&r?r:i,opacity:"number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):void 0}]:[]}).sort((e,t)=>e.offset-t.offset);return n.length?{direction:"horizontal"===r.direction?"horizontal":"vertical"===r.direction?"vertical":t,stops:n}:void 0}(e,i,r);if(!n)return;let{direction:o,stops:a}=n,s=`${t}-gradient`;return{fill:`url(#${s})`,def:va("linearGradient",{id:s,x1:0,y1:0,x2:"horizontal"===o?"100%":0,y2:"vertical"===o?"100%":0,children:a.map((e,t)=>va("stop",{offset:100*e.offset+"%",stopColor:e.color,stopOpacity:e.opacity},`${e.offset}-${t}`))},s)}}(e.gradient,t,i,o)??n}var Ml=/*#__PURE__*/new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function $l(e,t,i){let r=e.position,n="string"==typeof r&&Ml.has(r)?r:"bottom-left",o=n.endsWith("left")?"left":n.endsWith("right")?"right":"center",a=n.startsWith("top")?"top":n.startsWith("bottom")?"bottom":"middle",s="top"===a?0:"bottom"===a?i:i/2;return{x:("left"===o?0:"right"===o?t:t/2)+("number"==typeof e.dx&&Number.isFinite(e.dx)?e.dx:0),y:s+("number"==typeof e.dy&&Number.isFinite(e.dy)?e.dy:0),textAnchor:"start"===e.textAnchor||"middle"===e.textAnchor||"end"===e.textAnchor?e.textAnchor:"left"===o?"start":"right"===o?"end":"middle",dominantBaseline:"auto"===e.dominantBaseline||"middle"===e.dominantBaseline||"hanging"===e.dominantBaseline?e.dominantBaseline:"top"===a?"hanging":"bottom"===a?"auto":"middle"}}function _l(e,t,i,r){return{...$l(e,t,i),fill:e.fill??e.color??r.fill,fontSize:e.fontSize??r.fontSize,fontFamily:e.fontFamily??r.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,letterSpacing:e.letterSpacing,opacity:e.opacity,className:e.className,style:{pointerEvents:"none"}}}import{jsx as Pl}from"react/jsx-runtime";var Il={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Tl({annotation:e,width:t,height:i,defaults:r=Il}){let n=e.label??e.text;return null==n?null:Pl("text",{..._l(e,t,i,r),children:n})}var Ll="http://www.w3.org/1999/xhtml";function Cl(e="semiotic"){let t=Symbol.for("semiotic.svg-instance"),i=globalThis,r=(i[t]??0)+1;return i[t]=r,`${e}-${r}`}function Rl(e,t){let i=`${Cl(`${e}-pending`)}_`,r=t(i).split(i);if(1===r.length)return r[0];let n,o=2654435769;for(let e of r)n=b("\0",b(e,n)),o=b("\0",b(e,o));return r.join(`${e}-${n.toString(36)}${o.toString(36)}`)}import{packEnclose as Nl}from"d3-hierarchy";import{area as Dl,curveBasis as Fl,curveCardinal as El,curveCatmullRom as Ol,curveLinear as zl,curveMonotoneX as Bl,curveMonotoneY as jl,curveStep as Wl,curveStepAfter as Yl,curveStepBefore as ql}from"d3-shape";import*as Xl from"react";function Gl(e,t={}){let i=function(e){let t=e.provenance,i=e.id??e.stableId??t?.stableId;return null==i||""===i?void 0:String(i)}(e);return{"data-semiotic-annotation-widget":"",...i?{"data-semiotic-annotation-id":i}:{},onClickCapture(r){let n=function(e){let t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(r);t.onAnnotationActivate?.({annotation:e,annotationId:i,chartId:t.chartId,inputType:n}),i&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:i,inputType:n,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}function Vl(e,t){return vs(e)?ks(e)??t:e}function Hl(e,t,i){let r=e.labelBackground,n=t.colors.background,o=n&&"transparent"!==n?n:t.colors.surface||n;return void 0===r?"none"===i?"none":{type:"halo",fill:o}:!1===r||"none"===r?"none":!0===r||"halo"===r?{type:"halo",fill:o}:"box"===r?{type:"box",fill:o}:{...r,fill:Vl(r.fill,o)??o,...void 0!==r.stroke?{stroke:Vl(r.stroke,t.colors.border)}:{}}}import{jsx as Ul,jsxs as Zl}from"react/jsx-runtime";function Kl(e,t){let i=ea(e,t);return null!=i&&Number.isFinite(i)?i:Number.NaN}var Ql={linear:zl,monotoneX:Bl,monotoneY:jl,step:Wl,stepAfter:Yl,stepBefore:ql,basis:Fl,cardinal:El,catmullRom:Ol};import{jsx as Jl,jsxs as ec}from"react/jsx-runtime";function tc(e,t){return e.color||t.colors.annotation||t.colors.text}function ic(e,t,i){return t.x?null!=e.x?Qo(t.x,e.x):i&&null!=e[i]?Qo(t.x,e[i]):null:"number"==typeof e.x?e.x:null}function rc(e,t,i){return t.y?null!=e.y?Qo(t.y,e.y):i&&null!=e[i]?Qo(t.y,e[i]):null:"number"==typeof e.y?e.y:null}function nc(e){let{annotations:t}=e;if(!t||0===t.length)return e.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;let i=Y(t).filter(e=>!e._directLabel),r=e.scales.geoProjection,n=r?i.map(e=>{if(!Array.isArray(e.coordinates)||e.coordinates.length<2)return e;let t=r([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):i,o=!!r&&!e.scales.x&&!e.scales.y,a=e=>Number(e),s=e.scales.x??(o?a:void 0),l=e.scales.y??(o?a:void 0),c=e.frameType??(e.projection?"ordinal":r||e.scales.x||e.scales.y?"xy":"network"),u="horizontal"===e.projection,d=e.projection?u?"horizontal":"vertical":void 0,h="vertical"===e.projection||u,p=e.scales.o,f=p?e=>(p(e)??0)+(p.bandwidth?.()??0)/2:void 0,g={scales:{x:(h?u?e.scales.r:f:void 0)??s,y:(h?u?f:e.scales.r:void 0)??l,time:h?e.scales.r:s,value:h?e.scales.r:l,o:p,...r?{geoProjection:r}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,pointNodes:e.pointNodes,frameType:c,...d?{projection:d}:{}},m=function(e,t){let i=e.filter(e=>e._directLabel);if(!i.length)return{node:null};let r=i[0]._directLabel.position,n=t.measure??gs,o=i.map(e=>({family:t.fontFamily||"sans-serif",version:t.fontVersion??0,weight:400,size:e.fontSize||11})),a=i.map((e,i)=>{let r=(e,t)=>{if(null==e||!t)return NaN;try{return t(Number(e))}catch{return NaN}};return{id:String(e._directLabel.id),anchor:{x:r(e.x,t.scales?.x),y:r(e.y,t.scales?.y)},measurement:n(String(e.label),o[i])}}),s=Math.max(0,(t.margin?.["end"===r?"right":"left"]??0)-10),l=function(e,t,i="end",r=2){let n,o=new Map,a=new Map,s=(e,t)=>{let i=a.get(e)??{count:0,labelIds:[]};i.count++,i.labelIds.length<20&&i.labelIds.push(t),a.set(e,i)},l=(e,t)=>{o.set(e,{id:e,status:"omitted",reason:t}),s(t,e),s("LABEL_OMITTED",e)},c=[...e].sort((e,t)=>(Number.isFinite(e.anchor.y)?e.anchor.y:1/0)-(Number.isFinite(t.anchor.y)?t.anchor.y:1/0)||(e.id<t.id?-1:e.id>t.id?1:0)),u=[],d=0;for(let e of c){let{id:i,anchor:o,measurement:a}=e;if("estimated"===a.source&&s("ESTIMATED_METRICS",i),![o.x,o.y,a.width,a.height,a.ascent].every(Number.isFinite)||a.width<0||a.height<=0){l(i,"INVALID_PROJECTION");continue}n===o.y&&s("TIED_ENDPOINTS",i),n=o.y;let c=a.height+(u.length?r:0);![t.x,t.y,t.width,t.height,r].every(Number.isFinite)||r<0||a.width>t.width||d+c>t.height?l(i,"INSUFFICIENT_SPACE"):(u.push(e),d+=c)}let h=ms({desired:u.map(e=>e.anchor.y-e.measurement.height/2),minGaps:u.slice(0,-1).map(e=>e.measurement.height+r),min:t.y,max:t.y+t.height-(u.at(-1)?.measurement.height??0)});u.forEach((e,r)=>{let n={x:"end"===i?t.x:t.x+t.width-e.measurement.width,y:h[r],width:e.measurement.width,height:e.measurement.height},a="end"===i?n.x:n.x+n.width,s=n.y+n.height/2,l={x:a-e.anchor.x,y:s-e.anchor.y};o.set(e.id,{id:e.id,status:"placed",box:n,offset:l,...Math.abs(l.y)>.01||Math.abs(l.x)>6.01?{connector:{x1:e.anchor.x,y1:e.anchor.y,x2:a,y2:s}}:{}})});let p=e.map(e=>o.get(e.id)),f=p.filter(e=>"placed"===e.status&&Math.abs(e.offset.y)>.01),g=p.filter(e=>"omitted"===e.status),m=e.filter(e=>"estimated"===e.measurement.source).length;return{dispositions:p,evidence:{status:m||g.length?"incomplete":"complete",requested:e.length,rendered:u.length,displaced:f.length,omitted:g.length,omittedIds:g.slice(0,20).map(e=>e.id),displacedIds:f.slice(0,20).map(e=>e.id),measurement:{measured:e.length-m,estimated:m},collisions:0,overflows:0,fallback:"accessible-series-list",findings:[...a].map(([e,t])=>({code:e,...t,remedy:ys[e]})),coverage:{directLabels:"assessed",axisLabels:"not-assessed"}}}}(a,{x:"end"===r?t.width+6:-s-6,y:0,width:s,height:t.height},r),c=l.dispositions.map((e,r)=>{if("omitted"===e.status)return null;let n=e.box,s=e.connector,c=i[r],u=bs("g",{"data-direct-label-id":e.id,children:[s&&xs("line",{...s,stroke:c.color,strokeWidth:.75}),xs("text",{x:n.x+(a[r].measurement.left??0),y:n.y+a[r].measurement.ascent,fontFamily:o[r].family,fontWeight:o[r].weight,fontSize:o[r].size,fill:c.color,textAnchor:"start",children:c.label})]},e.id),d=t.renderLabel?t.renderLabel({...c,dx:n.x+(a[r].measurement.left??0)-a[r].anchor.x,dy:n.y+a[r].measurement.ascent-a[r].anchor.y,fontFamily:o[r].family},r,u):u;if(!d){let t=l.evidence;t.rendered--,t.omitted++,t.omittedIds.length<20&&t.omittedIds.push(e.id),Math.abs(e.offset.y)>.01&&t.displaced--,t.displacedIds=t.displacedIds.filter(t=>t!==e.id);for(let i of["RENDER_FAILURE","LABEL_OMITTED"]){let r=t.findings.find(e=>e.code===i);r||(r={code:i,count:0,labelIds:[],remedy:ys[i]},t.findings.push(r)),r.count++,r.labelIds.length<20&&r.labelIds.push(e.id)}}if(d!==u&&(l.evidence.status="incomplete",d)){let t=l.evidence.findings.find(e=>"UNSUPPORTED_GEOMETRY"===e.code);t||(t={code:"UNSUPPORTED_GEOMETRY",count:0,labelIds:[],remedy:ys.UNSUPPORTED_GEOMETRY},l.evidence.findings.push(t)),t.count++,t.labelIds.length<20&&t.labelIds.push(e.id)}return d?xs(fs.Fragment,{children:d},e.id):null}),u=xs("g",{role:"list","aria-label":"Series endpoints","data-direct-label-fallback":"accessible-series-list",children:i.map((e,t)=>xs("g",{role:"listitem","aria-label":`${e.label}: x ${String(e.x)}, y ${String(e.y)}`,children:xs("title",{children:`${e.label}: x ${String(e.x)}, y ${String(e.y)}`})},a[t].id))});return{evidence:l.evidence,node:bs("g",{className:"semiotic-direct-labels","data-label-layout":JSON.stringify(l.evidence),children:[c,u]},"direct-labels")}}(t,{...e.layout,scales:e.scales,margin:e.margin,fontFamily:e.theme.typography.fontFamily,measure:e.labelMeasurer,...e.svgAnnotationRules?{renderLabel:(t,i,r)=>e.svgAnnotationRules(t,i,g)??r}:{}}),y=e.autoPlaceAnnotations?Sl({annotations:n,context:g,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):n,x=function(e,t,i,r){let n=[];return e.forEach((e,o)=>{let a;a=i?i(e,o,r)??t(e,o,r):t(e,o,r),a&&n.push({node:a,annotation:e})}),{nodes:Ks(n),renderedAnnotations:n.map(e=>e.annotation)}}(y,(t,i,r)=>function(e,t,i,r){let{scales:n,layout:o,theme:a,xAccessor:s,yAccessor:l}=i;switch(e.type){case"frame-text":return Jl(Tl,{annotation:e,width:o.width,height:o.height,defaults:{fill:a.colors.text,fontSize:11,fontFamily:a.typography.fontFamily}},`ann-frame-text-${t}`);case"y-threshold":{let r=e.value??e.y;if(null==r)return null;let s=tc(e,a),l=e.label,c=e.strokeDasharray||"6,4",u=e.strokeWidth??1.5;if("horizontal"===i.projection&&n.r){let i=n.r(r);return null==i?null:ec("g",{opacity:e.opacity,children:[Jl("line",{x1:i,y1:0,x2:i,y2:o.height,stroke:s,strokeWidth:u,strokeDasharray:c}),Is(e.endCap,[i,0],s),l&&Jl(_s,{x:i+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??s,fontFamily:a.typography.fontFamily,text:l,background:Hl(e,a,"halo")})]},`ann-ythresh-${t}`)}let d=n.y?Qo(n.y,r):n.r?n.r(r):null;return null==d?null:Jl(Cs,{ann:e,position:d,vertical:!1,width:o.width,height:o.height,color:s,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:Hl(e,a,"halo"),dash:"6,4",labelGap:6},`ann-ythresh-${t}`)}case"x-threshold":{let r=e.value??e.x;if(null==r)return null;let s="horizontal"===i.projection&&n.r?n.r(r):n.x?Qo(n.x,r):null;if(null==s)return null;let l=tc(e,a);return Jl(Cs,{ann:e,position:s,vertical:!0,width:o.width,height:o.height,color:l,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:Hl(e,a,"halo"),dash:"6,4"},`ann-xthresh-${t}`)}case"band":{if("function"!=typeof n.y)return null;let r=Jo(n.y,e.y0,0),s=Jo(n.y,e.y1,1);if(null!=e.y0&&null==r||null!=e.y1&&null==s)return null;let l=r??0,c=s??o.height,u=Math.min(l,c),d=Math.abs(c-l),h=Al(e,`ssr-band-${t}`,"vertical",a.colors.primary||tc(e,a)),p=e.fillOpacity??.1,f=!0===i.underLayerBands&&"under"===e.layer;return ec("g",{opacity:e.opacity,children:[!f&&h.def&&Jl("defs",{children:h.def}),!f&&Jl("rect",{x:0,y:u,width:o.width,height:d,fill:h.fill,fillOpacity:p}),e.label&&Jl(_s,{x:o.width-4,y:Math.max(u,0)+16,textAnchor:"end",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||tc(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:Hl(e,a,"halo")})]},`ann-band-${t}`)}case"x-band":{if("function"!=typeof n.x)return null;let r=Jo(n.x,e.x0,0),s=Jo(n.x,e.x1,1);if(null!=e.x0&&null==r||null!=e.x1&&null==s)return null;let l=r??0,c=s??o.width,u=Math.min(l,c),d=Math.abs(c-l),h=Al(e,`ssr-xband-${t}`,"horizontal",a.colors.primary||tc(e,a)),p=e.fillOpacity??.1,f=!0===i.underLayerBands&&"under"===e.layer;return ec("g",{opacity:e.opacity,children:[!f&&h.def&&Jl("defs",{children:h.def}),!f&&Jl("rect",{x:u,y:0,width:d,height:o.height,fill:h.fill,fillOpacity:p}),e.label&&Jl(_s,{x:u+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||tc(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:Hl(e,a,"halo")})]},`ann-xband-${t}`)}case"category-highlight":{if(null==e.category||!n.o)return null;let r=n.o(String(e.category));if(null==r)return null;let s=n.o.bandwidth?n.o.bandwidth():40,l=tc(e,a),c=e.opacity??.1,u=e.label;return"horizontal"===i.projection?ec("g",{children:[Jl("rect",{x:0,y:r,width:o.width,height:s,fill:l,opacity:c}),u&&Jl(_s,{x:12,y:r+s/2,dominantBaseline:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:Hl(e,a,"none")})]},`ann-cathighlight-${t}`):ec("g",{children:[Jl("rect",{x:r,y:0,width:s,height:o.height,fill:l,opacity:c}),u&&Jl(_s,{x:r+s/2,y:16,textAnchor:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:Hl(e,a,"none")})]},`ann-cathighlight-${t}`)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{let i=function(e,t,i,r){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){let i=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(i)return{x:i[0],y:i[1]}}return{x:ic(e,t,i),y:rc(e,t,r)}}(e,n,s,l),o=null==i.x||null==i.y?il(e,t,r):null,c=i.x??o?.x??null,u=i.y??o?.y??null;if(null==c||null==u)return null;let d="text"===e.type,h=e.dx??(d?0:30),p=e.dy??(d?0:-30),f=e.color||a.colors.text;if(!d){let i="callout"===e.type?"callout-circle":e.type,r="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return Jl(Ys,{noteData:{x:c,y:u,dx:h,dy:p,note:Rs(e),type:i,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:f,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},`ann-label-${t}`)}return Jl("g",{children:Jl("text",{x:c+h,y:u+p,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||a.typography.labelSize,fill:f,fontFamily:a.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},`ann-label-${t}`)}default:return null}}(t,i,e,r)??function(e,t,i,r){let n=e.color||r?.colors.textSecondary||"#666",o=r?Hl(e,r,"none"):e.labelBackground??"none";switch(e.type){case"enclose":{let r=(e.coordinates||[]).map(e=>({x:Qs({...e,type:"point"},i),y:Js({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=Nl(r),s=e.padding||10;return Zl("g",{children:[Ul("circle",{cx:a.x,cy:a.y,r:a.r+s,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Ul(_s,{x:a.x,y:a.y-a.r-s-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"rect-enclose":{let r=(e.coordinates||[]).map(e=>({x:Qs({...e,type:"point"},i),y:Js({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=e.padding||10,[s,l]=le(r.map(e=>e.x)),[c,u]=le(r.map(e=>e.y)),d=s-a,h=l+a,p=c-a;return Zl("g",{children:[Ul("rect",{x:d,y:p,width:h-d,height:u+a-p,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Ul(_s,{x:(d+h)/2,y:p-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"highlight":{let r=i.data||[],n="function"==typeof e.filter?r.filter(e.filter):e.field&&null!=e.value?r.filter(t=>t[e.field]===e.value):[],o={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return Ul("g",{children:n.map((t,r)=>{let n=Qs(t,i),a=Js(t,i);if(null==n||null==a)return null;let s="function"==typeof e.r?e.r(t):e.r||6,l="function"==typeof e.style?e.style(t):e.style||o;return Ul("circle",{cx:n,cy:a,r:s,...l},`hl-${r}`)})},`ann-${t}`)}case"bracket":{let r=Qs(e,i),n=Js(e,i);return Ul(Ys,{noteData:{x:r??0,y:n??0,dx:e.dx||0,dy:e.dy||0,note:Rs(e),type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},`ann-${t}`)}case"trend":{let r=function(e,t){let i=t.scales?.x??t.scales?.time,r=t.scales?.y??t.scales?.value;if(!i||!r)return[];let n=t.data||[],o=t.xAccessor||"x",a=t.yAccessor||"y",s="horizontal"===t.projection,l="ordinal"===t.frameType;l&&s&&([o,a]=[a,o]);let c=e=>ea(i,e)??Number.NaN,u=e=>ea(r,e)??Number.NaN,d=s?u:c,h=l?t.scales?.o?.domain().map(String)??[...new Set(n.filter(e=>null!=e[o]).map(e=>String(e[o])))].sort((e,t)=>d(e)-d(t)):[],p=new Map(h.map((e,t)=>[e,t])),f=Ti(n.map(e=>[l?null==e[o]?void 0:p.get(String(e[o])):e[o],e[a]]));return f.length<2?[]:("loess"===e.method?Di(f,e.bandwidth??.3):("polynomial"===e.method?Ri(f,e.order??2):Ci(f)).points).map(([e,t])=>{if(!l)return[c(e),u(t)];let i=d(h[e]);return s?[c(t),i]:[i,u(t)]}).filter(([e,t])=>Number.isFinite(e)&&Number.isFinite(t))}(e,i);if(r.length<2)return null;let n=r.map(([e,t])=>`${e},${t}`).join(" "),o=e.color||"#6366f1",[a,s]=r[r.length-1];return Zl("g",{children:[Ul("polyline",{points:n,fill:"none",stroke:o,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Ul("text",{x:a+4,y:s-4,fill:o,fontSize:11,children:e.label})]},`ann-${t}`)}case"envelope":{let r=i.data||[];if(r.length<2)return null;let n=i.xAccessor||"x",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=e=>Kl(o,e),l=e=>Kl(a,e),c=e.upperAccessor||"upperBounds",u=e.lowerAccessor||"lowerBounds",d=e.filter,h=r.filter(e=>null!=e[c]&&null!=e[u]&&(!d||d(e))).sort((e,t)=>e[n]-t[n]);if(h.length<2)return null;let p=Ql[i.curve||"linear"]||zl,f=Dl().x(e=>s(e[n])).y0(e=>l(e[u])).y1(e=>l(e[c])).curve(p)(h);if(!f)return null;let g=e.fill||"#6366f1",m=h[h.length-1];return Zl("g",{children:[Ul("path",{d:f,fill:g,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&Ul("text",{x:s(m[n])+4,y:l(m[c])-4,fill:g,fontSize:11,children:e.label})]},`ann-${t}`)}case"anomaly-band":{let r=(i.data||[]).filter(t=>!e.filter||e.filter(t));if(r.length<2)return null;let n=i.yAccessor||"y",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=e=>Kl(a,e),l=r.map(e=>Ii(e[n])).filter(e=>null!==e);if(l.length<2)return null;let c=l.reduce((e,t)=>e+t,0)/l.length,u=l.reduce((e,t)=>e+(t-c)**2,0)/l.length,d=Math.sqrt(u),h=e.threshold??2,p=c-h*d,f=s(c+h*d),g=s(p),m=e.fill||"#6366f1",y=e.anomalyColor||"#ef4444",x=e.anomalyRadius??6,b=r.filter(e=>{let t=Ii(e[n]);return null!=t&&Math.abs(t-c)>h*d});return Zl("g",{children:[!1!==e.showBand&&Ul("rect",{x:0,y:Math.min(f,g),width:i.width||0,height:Math.abs(g-f),fill:m,fillOpacity:e.fillOpacity??.1}),b.map((e,t)=>{let r=Qs(e,i),n=Js(e,i);return null==r||null==n?null:Ul("circle",{cx:r,cy:n,r:x,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},`anomaly-${t}`)}),e.label&&Ul("text",{x:(i.width||0)-4,y:Math.min(f,g)-4,textAnchor:"end",fill:m,fontSize:11,children:e.label})]},`ann-${t}`)}case"forecast":{let r=i.data||[],n=i.xAccessor||"x",o=i.yAccessor||"y",a=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!a||!s)return null;let l=e=>Kl(a,e),c=e=>Kl(s,e),u=Ti(r.map(e=>[e[n],e[o]])),d=Fi(u,e);if(!d)return null;let{predict:h}=d,p=u[u.length-1][0],f=d.forecast(e.steps??5);if(!f.length)return null;let g=Dl().x(e=>l(e.x)).y0(e=>c(e.lower)).y1(e=>c(e.upper))(f);if(!g)return null;let m=f.map(e=>`${l(e.x)},${c(e.y)}`).join(" "),y=e.fill||"#6366f1",x=e.strokeColor||"#6366f1",b=f[f.length-1];return Zl("g",{children:[Ul("path",{d:g,fill:y,fillOpacity:e.fillOpacity??.15,stroke:"none"}),Ul("polyline",{points:`${l(p)},${c(h(p))} ${m}`,fill:"none",stroke:x,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&b&&Ul("text",{x:l(b.x)+4,y:c(b.y)-4,fill:x,fontSize:11,children:e.label})]},`ann-${t}`)}case"widget":{let r,n;if(null!=e.px&&null!=e.py)r=e.px,n=e.py;else{let o=il(e,t,i);if(!o)return null;r=o.x,n=o.y}if(!function(e,t,i,r=50){let n=i.width||0,o=i.height||0;return e>=-r&&e<=n+r&&t>=-r&&t<=o+r}(r,n,i))return null;let o=e.width??32,a=e.height??32,s=e.content??Ul("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return Ul("foreignObject",{x:r+(e.dx??0)-o/2,y:n+(e.dy??0)-a/2,width:o,height:a,style:{overflow:"visible",pointerEvents:"auto"},children:Ul("div",{xmlns:Ll,...Gl(e),style:{width:o,height:a,display:"flex",alignItems:"center",justifyContent:"center"},children:s})},`ann-${t}`)}default:return null}}(t,i,r,e.theme),e.svgAnnotationRules,g),b=m.node?[...x.nodes,m.node]:x.nodes,v=new Map;for(let e of x.renderedAnnotations){let t="string"==typeof e.type?e.type:"unknown";v.set(t,(v.get(t)??0)+1)}m.evidence&&v.set("text",(v.get("text")??0)+m.evidence.rendered);let w=[];for(let e of t){let t="string"==typeof e.type?e.type:"unknown",i=v.get(t)??0;i>0?v.set(t,i-1):w.push(t)}e.onRender?.({inputCount:t.length,eligibleCount:y.length,renderedCount:x.renderedAnnotations.length+(m.evidence?.rendered??0),...m.evidence?{layout:m.evidence}:{},unrenderedCount:w.length,unrenderedTypes:w});let k=e.idPrefix?`${e.idPrefix}-`:"";return b.length>0?Jl("g",{id:`${k}annotations`,className:"semiotic-annotations",children:b}):null}import{jsx as oc}from"react/jsx-runtime";function ac(e,t,i,r="right",n,o){if(null==e||!1===e)return null;let{x:a,y:s}=Ce(e,{totalWidth:t[0],totalHeight:t[1],margin:i,position:r,legendLayout:n,axisChrome:o});return oc("g",{transform:`translate(${a}, ${s})`,children:e})}function sc(e){let t=String(e).replace(/[^a-zA-Z0-9_-]/g,"_"),i=/^[A-Za-z_]/.test(t)?t:`c${t}`,r=`${i}-semiotic-title`,n=`${i}-semiotic-desc`;return{titleId:r,descId:n,labelledBy:`${r} ${n}`}}import*as lc from"react";function cc(e,t,i){if("edges"===e){if(t)return"start";if(i)return"end"}return"middle"}function uc(e,t,i){if("edges"===e){if(t)return"hanging";if(i)return"auto"}return"middle"}function dc(e){if(0===e.length)return{min:null,max:null};let t=1/0,i=-1/0;for(let r of e)r.pixel<t&&(t=r.pixel),r.pixel>i&&(i=r.pixel);return{min:t,max:i}}function hc(e){if(e)return"object"==typeof e?e.strokeDasharray:"dashed"===e?"6,4":"dotted"===e?"2,4":e}function pc(e,t){return e&&"string"!=typeof e?{stroke:e.stroke??t.stroke,strokeWidth:e.strokeWidth??t.strokeWidth,...null!=e.strokeOpacity&&{strokeOpacity:e.strokeOpacity},...e.strokeDasharray&&{strokeDasharray:e.strokeDasharray}}:{...t,..."string"==typeof e&&{strokeDasharray:hc(e)}}}function fc(e,t,i){if("left"===e||"right"===e){let r="left"===e?i:0,n="left"===e?-1:1,o=Math.ceil(t/8),a=`M0,${r}`;for(let e=0;e<o;e++){let i=8*e+4,o=8*(e+1);a+=`L${Math.min(i,t)},${r+4*n}`,a+=`L${Math.min(o,t)},${r}`}return a}let r="bottom"===e?0:t,n="bottom"===e?1:-1,o=Math.ceil(i/8),a=`M${r},0`;for(let e=0;e<o;e++){let t=8*e+4,o=8*(e+1);a+=`L${r+4*n},${Math.min(t,i)}`,a+=`L${r},${Math.min(o,i)}`}return a}function gc(e,t,i){return"exact"===i?function(e,t){let i=e.domain(),r=i[0],n=i[i.length-1],o=r instanceof Date,a=r instanceof Date?r.getTime():r,s=n instanceof Date?n.getTime():n;if(t<2||a===s)return o?[new Date(a),new Date(s)]:[a,s];let l=(s-a)/(t-1),c=new Array(t);for(let e=0;e<t;e++){let i=e===t-1?s:a+e*l;c[e]=o?new Date(i):i}return c}(e,t):e.ticks(t)}import{jsx as mc}from"react/jsx-runtime";function yc(e){return"string"==typeof e||"number"==typeof e}function xc(e){let{label:t,x:i,y:r,textAlign:n,fontSize:o,fontFamily:a,color:s}=e;return mc("foreignObject",{x:i,y:r,width:60,height:24,style:{overflow:"visible"},children:mc("div",{xmlns:Ll,style:{color:s,fontFamily:a,fontSize:o,textAlign:n,userSelect:"none"},children:t})})}function bc(e){return e instanceof Date?e:"number"==typeof e&&e>1e9?new Date(e):null}function vc(e){return e.dataValue??e.value}function wc(e){return"string"==typeof e||"number"==typeof e?6.5*String(e).length:60}function kc(e){let{scale:t,axis:i,size:r,horizontal:n=!1,axisExtent:o}=e,a=i?.extent??o,s=t.domain(),l=function(e){return e?.ticks??e?.tickCount??5}(i),c=Math.max(2,Math.floor(r/(n?70:30))),u="exact"===a?Math.max(2,l):Math.min(l,c),d=Vo(t),h=d&&i?.tickValues?i.tickValues.flatMap(e=>{let t=Ko(d,e);return null==t?[]:[{requested:e,index:t}]}):null,p=h?h.map(e=>e.requested):d?0===u?[]:d.map(e=>e.value):(i?.tickValues??gc(t,u,a)).filter(e=>"string"!=typeof e),f=!h&&d?new Map(d.map(e=>[e.value,e.label])):null,g=e=>f?.get(Number(e))??e,m=p.map(e=>{let t=g(e);return t instanceof Date?t.valueOf():"number"==typeof t?t:Number(t)}),y=i?.tickFormat||e.format||(d?function(e){let t=e.map(e=>e.label);if(t.length>0&&t.every(e=>e instanceof Date)){let e=1/0,i=-1/0;for(let r=0;r<t.length;r++){let n=t[r].getTime();n<e&&(e=n),n>i&&(i=n)}let r=pr([e,i]);return e=>e instanceof Date||"number"==typeof e&&Number.isFinite(e)?r(e):String(e)}if(t.every(e=>"number"==typeof e&&Number.isFinite(e))){let e=he(t);return t=>e("number"==typeof t?t:Number(t))}return e=>String(e)}(d):s[0]instanceof Date||p[0]instanceof Date?pr([s[0].valueOf(),s[s.length-1].valueOf()]):he(m)),x=(e,t)=>{let i=g(e);return n?y(i,t,m):y(i)},b=p.flatMap((e,i)=>{let r;if(h)r=t(h[i].index);else{if("string"==typeof e)return[];r=t(e)}let n={value:e,pixel:r,label:x(e,i)};return d&&(n.dataValue=h?h[i].requested:d[i].label),[n]}),v=!h&&d?b.filter(e=>e.pixel>=0&&e.pixel<=r):b,w=22;if(n){let e=v.reduce((e,t)=>Math.max(e,wc(t.label)),0);w=i?.autoRotate?Math.max(20,Math.min(e+8,55)):Math.max(55,e+8)}let k=n&&(i?.tickFormat||e.format)?e=>{let t=e.map(e=>{let t=g(e.value);return t instanceof Date?t.valueOf():Number(t)});return e.map((e,i)=>({...e,label:y(g(e.value),i,t)}))}:void 0,S=function(e,t){if(e.length<=2)return e;let i=[e[0]];for(let r=1;r<e.length-1;r++)Math.abs(e[r].pixel-i[i.length-1].pixel)>=t&&i.push(e[r]);let r=e[e.length-1];return Math.abs(r.pixel-i[i.length-1].pixel)>=t?i.push(r):i[i.length-1]=r,i}(v,w);if(k&&(S=k(S)),S.length>1&&(S=S.filter((e,t)=>0===t||!function(e,t){return!("string"!=typeof e&&"number"!=typeof e||"string"!=typeof t&&"number"!=typeof t||String(e)!==String(t))}(e.label,S[t-1].label))),i?.includeMax&&!d&&S.length>0&&"exact"!==a&&!i.tickValues){let e=s[s.length-1];if(null!=e){let i=t(e),r=Math.abs(i-S[S.length-1].pixel);if(r>1){let t=x(e,S.length);r<w&&S.length>1&&(S=S.slice(0,-1)),S=[...S,{value:e,pixel:i,label:t}]}}}return k?k(S):S}function Sc(e,t,i,r){if(!e)return!1;let n=vc(t);return"function"==typeof e?e(n,i):function(e,t){let i=bc(e);if(!i)return!1;let r=bc(t);return!r||i.getFullYear()!==r.getFullYear()||i.getMonth()!==r.getMonth()}(n,i>0?vc(r[i-1]):void 0)}import{jsx as Ac,jsxs as Mc}from"react/jsx-runtime";function $c(e){let t=e._idPrefix??e.chartId;if(null==t||""===t)return null;let i=String(t).replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(i)?i:`c${i}`}function _c(e){return $c(e)??Cl()}function Pc(e,t){let i=$c(e);return i?t(i):Rl("semiotic",t)}function Ic(e,t,i){return pe(e.showLegend&&!e.__legendIncludesAutomatic?as(t,e.colorScheme,i):void 0,e.legend)}var Tc={right:110,left:110,top:50,bottom:80};function Lc(e,t){if(e.__autoLegendMargin)return Tc[t]}function Cc(e,t){let i={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,axisChrome:t.axisChrome,legendDistance:fe(e)||ge(e)?e.legendDistance:void 0};return fe(e)?function(e){if(!e.legendGroups.some(e=>e.items.some(()=>!0)))return null;let t=function(e){let{legendGroups:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,rowHeight:c}=Re(a),u=s+l,d=Math.max(12,ls(i)),h="top"===r||"bottom"===r,p=Math.max(s,n-o.left-o.right);if(h){let r=Math.max(s,a?.maxWidth??p),n=ss(a?.align),o=0,l=0,c=[];for(let n of t){let t=n.items.map(e=>e.label),u=hs({...e,categories:t,legendLayout:{...a,maxWidth:Math.max(s,r-d-8),align:"start"}}),h=n.label?d:0,p=n.label?ds(n.label,0,0,i):0,f=h>0?h+8:0,g=f+u.width,m=Math.max(u.height,p);c.push({group:n,x:o,y:0,itemOffsetX:f,itemOffsetY:0,width:g,height:m,items:u.items}),o+=g+12,l=Math.max(l,m)}let h=c.length>0?o-12:0,f=h>r?0:"center"===n?Math.max(0,(r-h)/2):"end"===n?Math.max(0,r-h):0;return{groups:c.map(e=>({...e,x:e.x+f})),width:h,height:l,swatchSize:s,labelOffset:u,swatchRadius:0}}let f=Ne(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c);return{groups:[],width:t.reduce((e,t)=>t.items.reduce((e,t)=>Math.max(e,ds(t.label,s,l,i)),Math.max(e,t.label?ds(t.label,0,0,i):0)),0),height:f.at(-1)?.endY??0,swatchSize:s,labelOffset:u,swatchRadius:0}}(e),i="top"===e.position||"bottom"===e.position,r={legendGroups:e.legendGroups,legendDistance:e.legendDistance},n=e.reservedWidth??we(r,e.legendLayout),o=e.theme.colors.grid||e.theme.colors.textSecondary,{x:a,y:s}=Ce(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n});if(!i){let i=Ne(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)),r=e.legendGroups.flatMap((r,o)=>{let a=i[o],s=r.type??"fill",l=[rs("line",{x1:0,y1:a.lineY,x2:n,y2:a.lineY,stroke:"gray"},`legend-group-neatline-${o}`)];return r.label&&null!=a.labelY&&l.push(rs("text",{y:a.labelY,fontSize:ls(e.theme),fill:e.theme.colors.text,fontFamily:cs(e.theme),children:r.label},`legend-group-label-${o}`)),l.push(rs("g",{transform:`translate(0,${a.itemsY})`,children:r.items.map((i,n)=>{let a=r.styleFn(i,n),l="function"==typeof s?s(i):"line"===s?rs("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:a}):rs("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:a});return ns("g",{transform:`translate(0,${n*Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)})`,children:[l,rs("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:ls(e.theme),fill:e.theme.colors.text,fontFamily:cs(e.theme),children:i.label})]},`legend-${o}-${n}`)})},`legend-group-${o}`)),l});return rs("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"vertical",fontWeight:us(e.theme),children:r})}let l=t.groups.flatMap((i,r)=>{let{group:n}=i,a=n.type??"fill",s=[];if(n.label&&s.push(rs("text",{transform:`translate(${i.x},${i.y}) rotate(90)`,textAnchor:"start",fontSize:ls(e.theme),fill:e.theme.colors.text,fontFamily:cs(e.theme),children:n.label},`legend-group-label-${r}`)),s.push(...i.items.map((o,s)=>{let l=n.items[s],c=n.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?rs("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:c}):rs("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:c});return ns("g",{transform:`translate(${i.x+i.itemOffsetX+o.x},${i.y+i.itemOffsetY+o.y})`,children:[u,rs("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:ls(e.theme),fill:e.theme.colors.text,fontFamily:cs(e.theme),children:o.category})]},`legend-${r}-${s}`)})),r<t.groups.length-1){let e=i.x+i.width+6;s.push(rs("line",{x1:e,y1:0,x2:e,y2:t.height,stroke:o},`legend-group-separator-${r}`))}return s});return rs("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"horizontal",fontWeight:us(e.theme),children:l})}({...i,legendGroups:e.legendGroups}):ge(e)?function(e){let t=function(e){let t="top"===e.position||"bottom"===e.position,i=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??i,200),height:e.gradient.label?46:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?126:108,swatchSize:14}}(e),i="top"===e.position||"bottom"===e.position,r={gradient:e.gradient,legendDistance:e.legendDistance},n=we(r),o=(e.idPrefix?`${e.idPrefix}-`:"")+"semiotic-static-gradient-legend",a=e.gradient.format||he(e.gradient.domain),{x:s,y:l}=Ce(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n}),c=Array.from({length:17},(t,r)=>{let n=r/16,o=i?e.gradient.domain[0]+n*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-n*(e.gradient.domain[1]-e.gradient.domain[0]);return rs("stop",{offset:n,stopColor:e.gradient.colorFn(o)},r)});if(i){let i=e.gradient.label?12:void 0,r=e.gradient.label?18:0;return ns("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:us(e.theme),children:[rs("defs",{children:rs("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),e.gradient.label&&rs("text",{x:t.width/2,y:i,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:cs(e.theme),children:e.gradient.label}),rs("rect",{x:0,y:r,width:t.width,height:12,fill:`url(#${o})`,rx:2}),rs("text",{x:0,y:r+12+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:cs(e.theme),children:a(e.gradient.domain[0])}),rs("text",{x:t.width,y:r+12+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:cs(e.theme),children:a(e.gradient.domain[1])})]})}let u=e.gradient.label?12:void 0,d=e.gradient.label?18:0;return ns("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:us(e.theme),children:[rs("defs",{children:rs("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),e.gradient.label&&rs("text",{x:0,y:u,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:cs(e.theme),children:e.gradient.label}),rs("rect",{x:0,y:d,width:14,height:100,fill:`url(#${o})`,rx:2}),rs("text",{x:19,y:d+10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:cs(e.theme),children:a(e.gradient.domain[1])}),rs("text",{x:19,y:d+100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:cs(e.theme),children:a(e.gradient.domain[0])})]})}({...i,gradient:e.gradient}):null}function Rc(e,t){let{props:i,categories:r,theme:n,size:o,hasTitle:a}=t,s=i.legendPosition||"right",l={...e},c={theme:n,position:s,size:o,hasTitle:a,legendLayout:i.legendLayout,axisChrome:i.axisChrome,minimumMargin:Lc(i,s)};if(void 0!==i.legend&&null!==i.legend){let t=Ic(i,r,n);null!=t&&!1!==t&&function(e,t){let i=t.position||"right";Le(e,{legend:t.legend,position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...c,legend:t})}else i.showLegend&&r.length>0&&function(e,t){if(0===t.categories.length)return;let i=t.position||"right";Le(e,{legend:as(t.categories,t.colorScheme,t.theme),position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...c,categories:r,colorScheme:i.colorScheme});return be(e,l,o,s),s}function Nc(e){let{props:t,categories:i,theme:r,size:n,margin:o,hasTitle:a}=e,s=t.legendPosition||"right",l={theme:r,position:s,size:n,margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(void 0!==t.legend&&null!==t.legend){let e=Ic(t,i,r);return lc.isValidElement(e)?ac(e,n,o,s,t.legendLayout,t.axisChrome):Cc(e,l)||(fe(e)||ge(e)?null:ac(e??null,n,o,s,t.legendLayout,t.axisChrome))}return t.showLegend&&0!==i.length?function(e){let{categories:t,colorScheme:i,theme:r,position:n="right",totalWidth:o,totalHeight:a,margin:s}=e;if(!t||0===t.length)return null;let l=os(t,i,r),c="top"===n||"bottom"===n,u=hs(e),d={...as(t,i,r),legendDistance:e.legendDistance},h=e.reservedWidth??we(d,e.legendLayout),{x:p,y:f}=Ce(d,{totalWidth:o,totalHeight:a,margin:s,position:n,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:h}),g=c?void 0:Ne([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??22))[0],m=u.items.map((e,t)=>ns("g",{transform:`translate(${e.x},${e.y+(g?.itemsY??0)})`,children:[rs("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),rs("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:ls(r),fill:r.colors.text,fontFamily:cs(r),children:e.category})]},`legend-${t}`));return ns("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:us(r),children:[g&&rs("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),m]})}({categories:i,colorScheme:t.colorScheme,theme:r,position:s,totalWidth:n[0],totalHeight:n[1],margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function Dc(e,t){let i=_i(t.theme),r=Mi(t.theme,`[data-semiotic-auto="${t.idPrefix??"chart"}"]`),n=t.background??i.background,o=t.idPrefix?`${t.idPrefix}-`:"",a=ln(t.title),s=t.idPrefix?sc(t.idPrefix):{titleId:"semiotic-title",descId:"semiotic-desc"},l=a?s.titleId:void 0,c=t.description?s.descId:void 0,u=[l,c].filter(Boolean).join(" ")||void 0;return Mc("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,"data-semiotic-auto":r?t.idPrefix??"chart":void 0,role:"img","aria-labelledby":u,"aria-label":t.description||a||`${t.className.match(/stream-(\w+)-frame/)?.[1]??"data"} chart, ${t.markCount??0} marks`,style:{fontFamily:i.fontFamily},children:[r&&Ac("style",{children:r}),a&&Ac("title",{id:l,children:a}),t.description&&Ac("desc",{id:c,children:t.description}),t.defs&&Ac("defs",{children:t.defs}),n&&"transparent"!==n&&Ac("rect",{x:0,y:0,width:t.width,height:t.height,fill:n}),Ac("g",{id:`${o}data-area`,transform:t.innerTransform,children:e}),a&&Ac("text",{id:`${o}chart-title`,x:t.width/2,y:22,textAnchor:"middle",fontSize:i.titleFontSize,fontWeight:i.titleFontWeight,fill:i.text,fontFamily:i.titleFontFamily,children:cn(t.title)}),t.legend&&Ac("g",{id:`${o}legend`,children:t.legend}),t.outerElements]})}import{jsx as Fc,jsxs as Ec}from"react/jsx-runtime";import*as Oc from"react";import{jsx as zc,jsxs as Bc}from"react/jsx-runtime";function jc(e){return"under"===e.layer&&("band"===e.type||"x-band"===e.type)}function Wc(e,t,i,r){return"function"==typeof e?e({size:t,margin:i,scales:r}):e}var Yc={top:50,right:40,bottom:60,left:70},qc={top:20,right:80,bottom:20,left:80},Xc={top:40,right:40,bottom:40,left:40},Gc=/*#__PURE__*/new Set(["chord","force","circlepack","orbit"]);import{jsx as Vc,jsxs as Hc}from"react/jsx-runtime";import{Fragment as Uc,jsx as Zc,jsxs as Kc}from"react/jsx-runtime";function Qc(e,t){let i=$i(e.theme),r=Yc,n=e.size||[500,300],o=xe({...r,...e.margin},ln(e.title)),a=me(ln(e.title)),s=function(e,t){if(!t||0===e.length||!e.some(e=>null!=e&&"object"==typeof e&&Array.isArray(e[t])))return e;let i=[];for(let r of e){if(null==r||"object"!=typeof r)continue;let e=r[t];if(!Array.isArray(e))continue;let n=r.label??r.id??r.key;for(let t of e)null==t||"object"!=typeof t||i.push(null==n?t:{...t,_lineGroup:n})}return i}(Mt(e.data),e.lineDataAccessor),l=e.showLegend?ps(s,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[],c=Pe({showAxes:e.showAxes,xLabel:e.xLabel,yLabel:e.yLabel,yLabelRight:e.yLabelRight,axes:e.axes});Rc(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=Nc({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),p="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),f=e.colorScheme||i.colors.categorical,g=(e.axes?.find(e=>"left"===e.orient)??e.axes?.find(e=>"right"===e.orient))?.extent??e.axisExtent,m={chartType:e.chartType,runtimeMode:p?"streaming":"bounded",windowSize:e.windowSize??e.capacity??200,windowMode:e.windowMode??e.capacityMode??"sliding",arrowOfTime:p?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:e.xAccessor,yAccessor:e.yAccessor,timeAccessor:p?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor||(e.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,invertY:e.invertY,axisExtent:e.axisExtent,yAxisExtent:g,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,binAlign:e.binAlign,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:pi(e.gradientFill),lineGradient:fi(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:f,themeCategorical:i.colors.categorical,themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging,themeSemantic:M(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat,heatmapColorScale:e.heatmapColorScale,heatmapAggregation:e.heatmapAggregation,heatmapXBins:e.heatmapXBins,heatmapYBins:e.heatmapYBins,pointIdAccessor:e.pointIdAccessor,onLayoutError:e.onLayoutError},y=new To(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Wc(e.backgroundGraphics,n,o,y.scales),b=Wc(e.foregroundGraphics,n,o,y.scales),v=function(e=[]){let t=e.filter(e=>e._directLabel);return t.length?` Series endpoints: ${t.map(e=>`${e.label}: x ${String(e.x)}, y ${String(e.y)}`).join("; ")}.`:""}(e.annotations),w=v?`${e.description||e.title||"Line chart."}${v}`:e.description;if(!y.scales){let r,a=e.annotations?nc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=ma({frameType:"xy",width:n[0],height:n[1],marks:[],title:e.title,description:w,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?Kc(Uc,{children:[x,a,b]}):null;return hn.renderToStaticMarkup(Dc(l,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:w,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let k,S=e._idPrefix,A=ts({nodes:y.scene,renderMode:e.renderMode,fallback:(t,i)=>Qa(t,i,S,e.hoverRadius??30)}),$=!y.xIsDate||e.xFormat||e.tickFormatTime||Vo(y.scales.x)?e:{...e,xFormat:pr(y.scales.x.domain().map(e=>e.valueOf()))},_=e.showGrid?function(e,t,i,r,n,o,a){let{grid:s}=_i(i),l=r?`${r}-`:"",c=o?.find(e=>"bottom"===e.orient),u=o?.find(e=>"top"===e.orient),d=o?.find(e=>"left"===e.orient),h=o?.find(e=>"right"===e.orient),p=c??u,f=d??h,g=kc({scale:e.x,axis:p,size:t.width,horizontal:!0,format:a?.xFormat||a?.tickFormatTime,axisExtent:n}),m=kc({scale:e.y,axis:f,size:t.height,format:a?.yFormat||a?.tickFormatValue,axisExtent:n}),y=!1!==p?.grid,x=!1!==f?.grid,b=hc(p?.gridStyle),v=hc(f?.gridStyle),w=pc(p?.gridStyle,{stroke:s,strokeWidth:.5}),k=pc(f?.gridStyle,{stroke:s,strokeWidth:.5});return Ec("g",{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:[y&&g.map((e,i)=>Fc("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:t.height,...w,strokeDasharray:b??w.strokeDasharray},`gx-${i}`)),x&&m.map((e,i)=>Fc("line",{x1:0,y1:e.pixel,x2:t.width,y2:e.pixel,...k,strokeDasharray:v??k.strokeDasharray},`gy-${i}`))]})}(y.scales,{width:d,height:h},i,S,e.axisExtent,e.axes,$):null,P=A.map(e=>e.element),I=`${_c(e)}-plot-clip`,T=!1!==e.showAxes,L=T?function(e,t,i,r,n,o,a,s=!1){let l=_i(r),c=i.legendPosition??"right",u=Se(i.legendLayout,a?.leftAxis),d=Se(i.legendLayout,a?.rightAxis),h=s&&"left"===c&&u>0?u:o?.left??i.margin?.left??40,p=s&&"right"===c&&d>0?d:o?.right??i.margin?.right??40,{xAxis:f,yAxis:g,xOrient:m,yOrient:y}=de(i.axes),x="top"===m?0:t.height,b="right"===y?t.width:0,v="top"===m?-1:1,w="right"===y?1:-1,k=kc({scale:e.x,axis:f,size:t.width,horizontal:!0,format:i.xFormat||i.tickFormatTime,axisExtent:i.axisExtent}),S=kc({scale:e.y,axis:g,size:t.height,format:i.yFormat||i.tickFormatValue,axisExtent:i.axisExtent}),A=!(!f?.autoRotate||!function(e){for(let t=1;t<e.length;t++){let i=e[t-1],r=e[t];if(Math.abs(r.pixel-i.pixel)<(wc(i.label)+wc(r.label))/2+8)return!0}return!1}(k)),M=dc(k),$=dc(S),_=f?.label??i.xLabel,P=g?.label??("right"===y?i.yLabelRight??i.yLabel:i.yLabel),I=pc(f?.axisStyle,{stroke:l.border,strokeWidth:1}),T=pc(g?.axisStyle,{stroke:l.border,strokeWidth:1}),L="right"===y?t.width+p-15:15-h;return Mc("g",{id:(n?`${n}-`:"")+"axes",className:"stream-axes",children:[!1!==f?.visible&&Mc("g",{className:`semiotic-axis semiotic-axis-${m}`,"data-orient":m,children:[!1!==f?.baseline&&!f?.jaggedBase&&Ac("line",{x1:0,y1:x,x2:t.width,y2:x,...I}),f?.jaggedBase&&Ac("path",{d:fc(m,t.width,t.height),fill:"none",...I}),k.map((e,t)=>{let i=Sc(f?.landmarkTicks,e,t,k);return Mc("g",{transform:`translate(${e.pixel},${x})`,children:[Ac("line",{y2:5*v,...I}),yc(e.label)?Ac("text",{y:v*(A?12:18),textAnchor:A?"end":cc(f?.tickAnchor,e.pixel===M.min,e.pixel===M.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:A?"top"===m?"rotate(45)":"rotate(-45)":void 0,children:e.label}):xc({label:e.label,x:-30,y:"top"===m?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`xtick-${t}`)}),_&&Ac("text",{x:t.width/2,y:"top"===m?-(A?58:40):t.height+(A?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:_})]}),!1!==g?.visible&&Mc("g",{className:`semiotic-axis semiotic-axis-${y}`,"data-orient":y,children:[!1!==g?.baseline&&!g?.jaggedBase&&Ac("line",{x1:b,y1:0,x2:b,y2:t.height,...T}),g?.jaggedBase&&Ac("path",{d:fc(y,t.width,t.height),fill:"none",...T}),S.map((e,t)=>{let i=Sc(g?.landmarkTicks,e,t,S);return Mc("g",{transform:`translate(${b},${e.pixel})`,children:[Ac("line",{x2:5*w,...T}),yc(e.label)?Ac("text",{x:8*w,textAnchor:"right"===y?"start":"end",dominantBaseline:uc(g?.tickAnchor,e.pixel===$.min,e.pixel===$.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:e.label}):xc({label:e.label,x:"right"===y?8:-68,y:-12,textAlign:"right"===y?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`ytick-${t}`)}),P&&Ac("text",{x:L,y:t.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===y?90:-90}, ${L}, ${t.height/2})`,children:P})]})]})}(y.scales,{width:d,height:h},$,i,S,o,c,!!u):null,C=T?function(e){let{scales:t,layout:i,props:r,theme:n,leftAxis:o,rightAxis:a,margin:s,axisChrome:l,hasRenderedLegend:c}=e;if(!o||!a||!1===a.visible)return null;let u=_i(n),d=kc({scale:t.y,axis:a,size:i.height,format:r.yFormat||r.tickFormatValue,axisExtent:r.axisExtent}),h=dc(d),p=a.label??r.yLabelRight,f=pc(a.axisStyle,{stroke:u.border,strokeWidth:1}),g=r.legendPosition??"right",m=Se(r.legendLayout,l?.rightAxis),y=c&&"right"===g&&m>0?m:s.right,x=i.width+y-15;return Hc("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==a.baseline&&!a.jaggedBase&&Vc("line",{x1:i.width,y1:0,x2:i.width,y2:i.height,...f}),a.jaggedBase&&Vc("path",{d:fc("right",i.width,i.height),fill:"none",...f}),d.map((e,t)=>{let r=Sc(a.landmarkTicks,e,t,d);return Hc("g",{transform:`translate(${i.width},${e.pixel})`,children:[Vc("line",{x2:5,...f}),yc(e.label)?Vc("text",{x:8,textAnchor:"start",dominantBaseline:uc(a.tickAnchor,e.pixel===h.min,e.pixel===h.max),fontWeight:r?600:400,fontSize:r?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):xc({label:e.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},`ytick-r-${t}`)}),p&&Vc("text",{x:x,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${x}, ${i.height/2})`,children:p})]})}({scales:y.scales,layout:{width:d,height:h},props:e,theme:i,leftAxis:e.axes?.find(e=>"left"===e.orient),rightAxis:e.axes?.find(e=>"right"===e.orient),margin:o,axisChrome:c,hasRenderedLegend:!!u}):null,R=e.annotations?nc({annotations:e.annotations,margin:o,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.scales.y},layout:{width:d,height:h},theme:i,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:S,underLayerBands:!0,onRender:e=>{k=e}}):null;t&&(t.evidence=ma({frameType:"xy",width:n[0],height:n[1],marks:A.map(e=>e.node),title:e.title,description:w,annotations:e.annotations,annotationRender:k,xDomain:ga(y.scales.x?.domain?.()),yDomain:ga(y.scales.y?.domain?.()),legendItems:l.length>0?l.length:void 0,margin:o}));let N=e.svgPreRenderers&&y.scales?e.svgPreRenderers.map((e,t)=>{try{return Zc(dn.Fragment,{children:e(y.scene,y.scales,{width:d,height:h})},`pre-${t}`)}catch(e){return"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] SVG pre-renderer ${t} failed.`,e),null}}).filter(Boolean):null,D=Y(e.annotations??[]).filter(jc),F=D.length>0?function(e,t="under-band",i="var(--semiotic-primary, #6366f1)"){return(r,n,o)=>e.map((e,r)=>{let a=function(e,t,i,r){let n="band"===e.type,o=n?t.y:t.x;if("function"!=typeof o)return null;let a=n?e.y0:e.x0,s=n?e.y1:e.x1,l=Jo(o,a,0),c=Jo(o,s,1);if(null!=a&&null==l||null!=s&&null==c)return null;let u=l??0,d=c??(n?r:i);if(!Number.isFinite(u)||!Number.isFinite(d))return null;let h=n?r:i,p=Math.min(h,Math.max(0,Math.min(u,d))),f=Math.max(0,Math.min(h,Math.max(u,d))-p);return n?{x:0,y:p,width:i,height:f}:{x:p,y:0,width:f,height:r}}(e,n,o.width,o.height);if(!a)return null;let s=Al(e,`${t}-${r}`,function(e){return"band"===e.type?"vertical":"horizontal"}(e),i);return Bc("g",{opacity:e.opacity,children:[s.def&&zc("defs",{children:s.def}),zc("rect",{...a,fill:s.fill,fillOpacity:e.fillOpacity??.1})]},`${t}-${r}`)})}(D,`${_c(e)}-under-band`,i.colors.primary||i.colors.annotation||i.colors.text)(y.scene,y.scales,{width:d,height:h}):null,E=Kc(Uc,{children:[x,N,_,Zc("defs",{children:Zc("clipPath",{id:I,children:Zc("rect",{x:0,y:0,width:d,height:h})})}),Kc("g",{clipPath:`url(#${I})`,children:[F,P]}),L,C,R,b,y.customLayoutOverlays]});return hn.renderToStaticMarkup(Dc(E,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:w,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,markCount:A.length,idPrefix:e._idPrefix}))}ha();import*as Jc from"react-dom/server";import{jsx as eu,jsxs as tu}from"react/jsx-runtime";function iu({machine:e,layout:t,runtime:i,downstreamSet:r,selectedSet:n,width:o,height:a,seed:s,reduced:l,onSelectTask:c}){let u=t.tasks.length?t.tasks.reduce((e,t)=>Math.min(e,t.y-t.height/2),1/0):60,d=Math.max(20,u-12),h=Math.max(26,u-6);return tu("svg",{"aria-hidden":"true",width:o,height:a,viewBox:`0 0 ${o} ${a}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[eu("defs",{children:eu("filter",{id:`chain-shadow-${s}`,x:"-20%",y:"-20%",width:"140%",height:"150%",children:eu("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,i)=>{let r=t.tasks.filter(e=>e.laneIndex===i)[0]?.x??0;return tu("g",{children:[eu("line",{x1:r,x2:r,y1:h,y2:a-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),eu("text",{x:r,y:d,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{let t=i.delivered.has(e.edgeID),n=i.inFlight.has(e.edgeID),o=r.has(e.targetID)||r.has(e.sourceID),a=e.points.map(e=>`${e.x},${e.y}`).join(" ");return eu("polyline",{points:a,fill:"none",stroke:o?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:n?3:2,strokeOpacity:t||n||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{let t=i.delivered.has(e.edgeID);return tu("g",{children:[eu("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&eu("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{let o=t.taskByID.get(e.id);if(!o)return null;let a=i.completed.has(e.id),u=i.blockers.has(e.id),d=i.previewTaskID===e.id,h=n.has(e.id)||d,p=r.has(e.id),f=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,i),g=o.x-o.width/2,m=o.y-o.height/2,y=Math.max(2,o.height*e.progress);return tu("g",{children:[tu("g",{style:{transform:`rotate(${a?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:l?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+s+")"},children:[eu("rect",{x:g,y:m,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||p?"var(--semiotic-selection-color, #e08a1e)":f,strokeWidth:h?4:p?3:2}),eu("rect",{x:g+3,y:m+o.height-y+1,width:o.width-6,height:Math.max(0,y-4),rx:2,fill:f,opacity:a?.86:.46})]}),u&&tu("g",{opacity:d?.28:1,children:[eu("line",{x1:g-8,x2:g+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),eu("circle",{cx:g-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),tu("g",{onPointerDown:()=>c(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[eu("rect",{x:g,y:m,width:o.width,height:o.height,fill:"transparent"}),eu("text",{x:o.x,y:o.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?`${e.label.slice(0,22)}…`:e.label}),tu("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% ·"," ",a?"done":u?"blocked":i.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}function ru(e,t=0){if(e instanceof Date)return e.getTime();let i=Number(e);return Number.isFinite(i)?i:t}function nu(e){if(null==e.completionTime)return null;let t=ru(e.completionTime,Number.NaN);return Number.isFinite(t)?t:null}function ou(e,t,i,r){let n=new Set;for(let o of e.nodes){let a=e.incoming.get(o.id)??[];(r.has(o.id)||!i.has(o.id)&&a.every(e=>t.has(e.id)))&&n.add(o.id)}return n}function au(e,t,i={}){let r=new Set,n=[...e.get(t)??[]];for(let t=0;t<n.length;t++){let i=n[t];r.has(i)||(r.add(i),n.push(...e.get(i)??[]))}return i.includeStart&&r.add(t),r}function su(e,t,i){return function(e,t,i){if(null!=e)return"function"==typeof e?e(t,i):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}(i,e,t)}function lu(e,t){return e<t?-1:e>t?1:0}function cu(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function uu(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function du(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function hu(e){return e.filter((t,i)=>{let r=e[i-1];return!r||r.x!==t.x||r.y!==t.y})}function pu(e,t,i={}){let r=new Set(i.completedTaskIDs??[]),n=function(e,t){let i=new Map;for(let t of e)i.set(t.id,new Set);for(let e of t)i.has(e.source)||i.set(e.source,new Set),i.has(e.target)||i.set(e.target,new Set),i.get(e.source).add(e.target);return i}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),o=[...au(n,t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(i.isComplete?i.isComplete(e):r.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),a=Array.from(new Set(o.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:o.length,affectedLaneCount:a.length,downstreamTaskIDs:o.map(e=>e.id),affectedLanes:a}}import{jsx as fu,jsxs as gu}from"react/jsx-runtime";import*as mu from"react-dom/server";var yu=e=>Math.max(6,Math.round(2*e/3)),xu=(e,t,i)=>Math.min(i,Math.max(t,e)),bu=e=>Number(e.toPrecision(15));function vu(e){if(!Number.isFinite(e))return"";let t=Math.round(100*e)/100;return String(Object.is(t,-0)?0:t)}function wu(e,t,i,r=1.2*i,n){return"y"===t?e.length*r:n??ue(e.map(e=>Array.from(e).length),0)*i*.6}function ku(e){return e.__composite}function Su(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function Au(e,t,i,r){return e.replace(/^<svg\b/,`<svg x="${t}" y="${i}" data-semiotic-composite-part="${r}"`)}function Mu(e,t){for(let i of e){let e=i?.[t];if(Array.isArray(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1])return e}}import{jsx as $u,jsxs as _u}from"react/jsx-runtime";var Pu=e=>!0===e?{}:e&&"object"==typeof e?e:null,Iu=e=>"string"==typeof e?e:void 0;function Tu(e){return t=>{try{let i="function"==typeof e?e(t):void 0;return"string"==typeof i?i:vu(t)}catch{return vu(t)}}}function Lu(e,t,i,r,n,o,a){let s=[.35,.65].map(e=>"x"===a?{x1:t-r/2+r*e,x2:t-r/2+r*e,y1:i-.2*n,y2:i+.2*n}:{x1:t-.2*r,x2:t+.2*r,y1:i-n/2+n*e,y2:i-n/2+n*e});return _u("g",{className:"semiotic-brush-handle","data-semiotic-brush-part":e,children:[$u("rect",{x:t-r/2+.5,y:i-n/2+.5,width:r-1,height:n-1,rx:o.radius,fill:o.fill,stroke:o.stroke,strokeWidth:1}),s.map((e,t)=>$u("line",{...e,stroke:o.grip,strokeWidth:1},t))]},e)}import{jsx as Cu,jsxs as Ru}from"react/jsx-runtime";import{jsx as Nu,jsxs as Du}from"react/jsx-runtime";var Fu={top:4,bottom:4,left:4,right:4};function Eu(e,t,i,r,n){return{__composite:{data:e,colorBy:t,colorScheme:i,common:r,rest:n}}}function Ou(e,t){return Math.max(1,Math.floor(Su(e,t)))}var zu={frameType:"xy",buildProps:Eu,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=ku(e),[s,l]=o.size??[600,400],c=a.minimap&&"object"==typeof a.minimap?a.minimap:{},u=Su(c.height,60),d=o.margin,h=c.margin&&"object"==typeof c.margin?c.margin:{},p=function(e){let t=e.handles&&"object"==typeof e.handles?e.handles:e.handles?{}:null,i="number"==typeof t?.size&&Number.isFinite(t.size)?t.size:12;return{top:t?.move?Math.ceil(yu(i)/2)+2:0,bottom:e.showExtentLabels?34:20}}(c),f={top:Su(h.top,p.top),right:Su(h.right,Su(d?.right,20)),bottom:Su(h.bottom,p.bottom),left:Su(h.left,Su(d?.left,40))},g=u+f.top+f.bottom,m=a.frameProps&&"object"==typeof a.frameProps?a.frameProps:{},y={...a,xAccessor:a.xAccessor||"x",yAccessor:a.yAccessor||"y"},x="y"===c.brushDirection?"y":"x",b={...o,size:[s,l],xExtent:m.xExtent??("x"===x?a.brushExtent:void 0)??o.xExtent,yExtent:m.yExtent??("y"===x?a.brushExtent:void 0)??a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-detail`},v=Ur.buildProps(i,r,n,b,y);Object.assign(v,m);let w={...o,size:[s,g],margin:f,title:void 0,description:`${String(o.description??o.title??"Chart")} overview minimap`,showAxes:c.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:c.background,xExtent:void 0,yExtent:a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-overview`};delete w.lineStyle,delete w.pointStyle;let k={...y,fillArea:!1,lineWidth:1,showPoints:!1,directLabel:!1,forecast:void 0,anomaly:void 0,band:void 0},S=Ur.buildProps(i,r,n,w,k);S.chartType=a.fillArea?"area":"line","function"==typeof c.lineStyle&&(S.lineStyle=c.lineStyle);let A={},M={},$=Qc(v,A),_=Qc(S,M),P=!0===a.renderBefore,I=P?0:l,T=[Au($,0,P?g:0,"detail"),Au(_,0,I,"overview")].join(""),L=l+g,C=$i(o.theme),R=_i(C),N=ln(o.title)||void 0,D="string"==typeof o.description?o.description:N||"Chart with overview minimap",F=_c(o),E=N?`${F}-title`:void 0,O=`${F}-description`,z=Array.isArray(a.brushExtent)&&a.brushExtent.length>=2?[Number(a.brushExtent[0]),Number(a.brushExtent[1])]:null,B="x"===x?M.evidence?.xDomain:M.evidence?.yDomain,j=B?function(e){let{theme:t,config:i,direction:r,plot:n,margin:o}=e,a=function({domain:e,scale:t,orientation:i,reverse:r=!1}){if(t){let e=t.range().map(Number),i=t.domain().map(Number),r=Math.min(e[0],e[e.length-1]),n=Math.max(e[0],e[e.length-1])-r,o=Math.min(i[0],i[i.length-1]),a=Math.max(i[0],i[i.length-1]);if(![r,n,o,a].every(Number.isFinite)||n<=0||a<=o)return null;let s=Math.abs(t(o)-r)<=Math.abs(t(a)-r);return{min:o,max:a,toFraction:e=>(t(e)-r)/n,fromFraction:e=>e<=0?s?o:a:e>=1?s?a:o:xu(bu(Number(t.invert(r+e*n))),o,a)}}if(!e)return null;let n=Math.min(Number(e[0]),Number(e[1])),o=Math.max(Number(e[0]),Number(e[1]));if(!Number.isFinite(n)||!Number.isFinite(o)||o<=n)return null;let a=o-n,s="x"===i?!r:r;return{min:n,max:o,toFraction:e=>{let t=(e-n)/a;return s?t:1-t},fromFraction:e=>e<=0?s?n:o:e>=1?s?o:n:bu(s?n+e*a:o-e*a)}}({domain:e.domain,orientation:r});if(!a)return null;let s=Pu(i.handles),l=function(e,t){if(!e||e.length<2)return null;let i=Number(e[0]),r=Number(e[1]);return Number.isFinite(i)&&Number.isFinite(r)?[xu(Math.min(i,r),t.min,t.max),xu(Math.max(i,r),t.min,t.max)]:null}(e.extent,a)??(s?[a.min,a.max]:null);if(!l)return null;let c=Pu(i.brushStyle)??{},u=function(e){let t=e.colors.selection??e.colors.primary;return{fill:t,fillOpacity:.2,stroke:t,strokeWidth:1}}(t),d=t.colors.surface??t.colors.background,h="x"===r?n.width:n.height,[p,f]=[a.toFraction(l[0]),a.toFraction(l[1])].sort((e,t)=>e-t),g=(e,t)=>"x"===r?{x:n.x+e*h,y:n.y,width:(t-e)*h,height:n.height}:{x:n.x,y:n.y+e*h,width:n.width,height:(t-e)*h},m=[],y=Pu(c.mask);if(y)for(let[e,t]of[[0,p],[f,1]])m.push($u("rect",{className:"semiotic-brush-mask","data-semiotic-brush-part":"mask",...g(e,t),fill:Iu(y.fill)??d,opacity:Su(y.opacity,.6)},`mask-${e}`));let x=Su(c.strokeWidth,1),b=g(p,f);if(m.push($u("rect",{className:"selection","data-semiotic-brush-part":"selection",x:b.x+x/2,y:b.y+x/2,width:Math.max(0,b.width-x),height:Math.max(0,b.height-x),fill:Iu(c.fill)??u.fill,fillOpacity:Su(c.fillOpacity,.2),stroke:Iu(c.stroke)??u.stroke,strokeWidth:x},"selection")),s){let e=Su(s.size,12),t=yu(e),i={fill:Iu(s.fill)??d,stroke:Iu(s.stroke)??u.stroke,grip:u.stroke,radius:Su(s.radius,3)};for(let[o,a]of[["start",p],["end",f]])m.push("x"===r?Lu(o,n.x+a*h,n.y+n.height/2,t,2*e,i,"x"):Lu(o,n.x+n.width/2,n.y+a*h,2*e,t,i,"y"));if(s.move){let o=(p+f)/2;m.push("x"===r?Lu("move",n.x+o*h,n.y,2*e,t,i,"x"):Lu("move",n.x,n.y+o*h,t,2*e,i,"y"))}}if(i.showExtentLabels){let s=function(e){let{value:t,track:i,length:r,orientation:n,format:o,fontSize:a,labelWidth:s,showDomainLabels:l}=e,c=e.lineHeight??1.2*a,u=e.gap??6,[d,h]=e.bounds??[0,r],p=(e,t,r=i.toFraction(t))=>{let l=o(t),u=l.split("\n");return{kind:e,value:t,text:l,lines:u,fraction:r,size:wu(u,n,a,c,s)}},f=(e,t)=>{let i=e.fraction*r,n=t;"before"===n&&i-e.size<d?n="after":"after"===n&&i+e.size>h&&(n="before");let o="before"===n?i-e.size:i;return{...e,placement:n,row:0,from:o,to:o+e.size}},g=p("start",t[0]),m=p("end",t[1]),[y,x]=g.fraction<=m.fraction?[g,m]:[m,g],b=f(y,"before"),v=f(x,"after");b.to+u>v.from&&(v.row=1);let w=[b,v];if(!l)return w;let k=w.filter(e=>0===e.row),S=e=>{let t=i.fromFraction(e),n=p(t===i.min?"domain-start":"domain-end",t,e),o=0===e?0:r-n.size;return{...n,placement:0===e?"after":"before",row:0,from:o,to:o+n.size}};return[...[S(0),S(1)].filter(e=>e.from>=d&&e.to<=h&&k.every(t=>e.to+u<=t.from||t.to+u<=e.from)),...w]}({value:l,track:a,length:h,orientation:r,format:Tu(i.extentLabelFormat??e.axisFormat),fontSize:11,bounds:"x"===r?[-o.left,n.width+o.right]:[-o.top,n.height+o.bottom]}),c=13.2*ue(s.map(e=>e.lines.length),1);for(let e of s){let i="before"===e.placement,o="x"===r?n.x+e.fraction*h:n.x+n.width+4,a="x"===r?n.y+n.height+4+e.row*c:n.y+e.from;m.push($u("text",{className:"semiotic-brush-label","data-semiotic-brush-label":e.kind,x:o,y:a+10.45,fill:t.colors.textSecondary,fontFamily:t.typography.fontFamily,fontSize:11,textAnchor:"x"===r&&i?"end":"start",children:e.lines.map((e,t)=>$u("tspan",{x:o,dy:0===t?0:13.2,children:e},t))},`label-${e.kind}`))}}return $u("g",{className:"semiotic-minimap-brush",children:m})}({theme:C,config:c,direction:x,domain:B,extent:z&&z.every(Number.isFinite)?z:null,plot:{x:f.left,y:I+f.top,width:Math.max(0,s-f.left-f.right),height:u},margin:f,axisFormat:"x"===x?o.xFormat:o.yFormat}):null,W=mu.renderToStaticMarkup(Ru("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:s,height:L,role:"img","aria-labelledby":[E,O].filter(Boolean).join(" "),style:{fontFamily:R.fontFamily},children:[N&&Cu("title",{id:E,children:N}),Cu("desc",{id:O,children:D}),Cu("g",{dangerouslySetInnerHTML:{__html:T}}),j]}));if(t){let e=[A.evidence,M.evidence];t.evidence=pa({frameType:"xy",width:s,height:L,parts:e,title:N,description:D,xDomain:Mu(e,"xDomain"),yDomain:Mu(e,"yDomain")})}return W}};function Bu(e,t){return String("function"==typeof t?t(e):e[t])}var ju={frameType:"physics",buildProps:Eu,renderStatic:function(e,t){let{data:i,common:r,rest:n}=function(e){return e.__composite}(e),o=function(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}(i),[a,s]=r.size??[920,620],l=ln(r.title)||"Dependency chain reaction",c=function(e){let t=[],i=new Map,r=[],n=new Set;e.data.forEach((o,a)=>{let s=String(su(o,a,e.taskIDAccessor)??"");if(!s)return void t.push({code:"duplicate-task-id",message:`Task row ${a} has an empty id.`,taskIDs:[]});if(i.has(s))return void t.push({code:"duplicate-task-id",message:`Task id "${s}" occurs more than once.`,taskIDs:[s]});let l=String(su(o,a,e.laneAccessor)??"Unassigned");n.has(l)||(n.add(l),r.push(l));let c=su(o,a,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(c,e=>String(e)))).sort(lu),d=su(o,a,e.blockerAccessor),h=su(o,a,e.statusAccessor)??(d?"blocked":"waiting");i.set(s,{id:s,label:String(su(o,a,e.labelAccessor)??s),lane:l,laneIndex:0,level:0,index:a,datum:o,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:su(o,a,e.startAccessor),end:su(o,a,e.endAccessor),progress:du(su(o,a,e.progressAccessor)),status:h,completionTime:su(o,a,e.completionTimeAccessor),blockerReason:d||void 0,milestone:!!su(o,a,e.milestoneAccessor)})});let o=e.laneOrder?[...e.laneOrder,...r.filter(t=>!e.laneOrder?.includes(t))]:r,a=new Map(o.map((e,t)=>[e,t]));for(let e of i.values())e.laneIndex=a.get(e.lane)??0;let s=new Map,l=new Map;for(let e of i.keys())s.set(e,[]),l.set(e,[]);let c=[],u=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of u)e.dependencyIDs.forEach((r,n)=>{let o=i.get(r);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${r}".`,taskIDs:[e.id,r]});let a={id:cu(r,e.id),sourceID:r,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:uu(e.id,n),socketIndex:n};c.push(a),s.get(e.id)?.push(a),l.get(r)?.push(a),e.incomingEdgeIDs.push(a.id),e.socketIDs.push(a.socketID),o.outgoingEdgeIDs.push(a.id)});for(let e of s.values())e.sort((e,t)=>lu(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=uu(e.targetID,t)});for(let e of l.values())e.sort((e,t)=>lu(e.targetID,t.targetID));for(let e of i.values()){let t=s.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(l.get(e.id)??[]).map(e=>e.id)}let d=new Map,h=new Map;for(let e of i.keys())d.set(e,s.get(e)?.length??0),h.set(e,0);let p=[...i.keys()].filter(e=>0===d.get(e)).sort(lu),f=0;for(;p.length;){let e=p.shift();f+=1;for(let t of l.get(e)??[]){let i=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,i);let r=(d.get(t.targetID)??0)-1;if(d.set(t.targetID,r),0===r){let e=p.findIndex(e=>e>t.targetID);e<0?p.push(t.targetID):p.splice(e,0,t.targetID)}}}if(f!==i.size){let e=[...i.keys()].filter(e=>(d.get(e)??0)>0).sort(lu);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let g=0,m=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of m)e.level=h.get(e.id)??0,g=Math.max(g,e.level);return{nodes:m,edges:c,byID:i,incoming:s,outgoing:l,lanes:o,maxLevel:g,diagnostics:t,valid:0===t.length}}({data:o,taskIDAccessor:n.taskIDAccessor,labelAccessor:n.labelAccessor,laneAccessor:n.laneAccessor,dependencyAccessor:n.dependencyAccessor,startAccessor:n.startAccessor,endAccessor:n.endAccessor,progressAccessor:n.progressAccessor,statusAccessor:n.statusAccessor,completionTimeAccessor:n.completionTimeAccessor,blockerAccessor:n.blockerAccessor,milestoneAccessor:n.milestoneAccessor}),u=$i(r.theme),d=_i(u),h=_c(r),p=`${h}-title`,f=`${h}-description`;if(!c.valid){let e=c.diagnostics.map(e=>e.message).join(" "),i=Jc.renderToStaticMarkup(gu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${p} ${f}`,style:{fontFamily:d.fontFamily},children:[fu("title",{id:p,children:l}),fu("desc",{id:f,children:e}),fu("rect",{width:a,height:s,fill:d.background}),fu("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:d.text,children:l}),c.diagnostics.map((e,t)=>fu("text",{x:24,y:72+22*t,fontSize:12,fill:u.colors.error,children:e.message},`${e.code}-${t}`))]}));return t&&(t.evidence=pa({frameType:"physics",width:a,height:s,parts:[],title:l,description:e,nodeCount:c.nodes.length,edgeCount:c.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),i}let g=function(e,t,i={}){let r=Math.max(240,t.width),n=Math.max(220,t.height),o=t.paddingX??48,a=t.paddingTop??48,s=t.paddingBottom??44,l=Math.max(1,e.lanes.length),c=Math.max(70,(r-2*o)/l),u=Math.max(1,e.maxLevel+1),d=Math.max(76,(n-a-s)/u),h=Math.min(i.taskWidth??112,Math.max(58,.78*c)),p=Math.min(i.taskHeight??58,.64*d),f=i.socketRadius??5,g=Math.max(1,Math.round(i.gutterCount??3)),m=new Map;for(let t of e.nodes){let e=`${t.laneIndex}:${t.level}`,i=m.get(e)??[];i.push(t),m.set(e,i)}for(let e of m.values())e.sort((e,t)=>lu(e.id,t.id));let y=.86*d,x=e.nodes.map(e=>{let t=m.get(`${e.laneIndex}:${e.level}`)??[e],i=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,r=(e=>e<=1?p:Math.max(22,Math.min(p,(y-4*(e-1))/e)))(t.length),n=i*(r+4);return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:a+d*(e.level+.5)+n,width:h,height:r}}),b=new Map(x.map(e=>[e.taskID,e])),v=[],w=[];e.edges.forEach((t,i)=>{let r=b.get(t.sourceID),n=b.get(t.targetID);if(!r||!n)return;let o=e.incoming.get(t.targetID)??[],a=Math.min(.72*n.width,14*Math.max(1,o.length-1)),s=o.length<=1?n.x:n.x-a/2+a*t.socketIndex/(o.length-1),l=n.y-n.height/2-f-2,c={id:t.socketID,edgeID:t.id,taskID:n.taskID,index:t.socketIndex,x:s,y:l,radius:f};v.push(c);let u={x:r.x,y:r.y+r.height/2+3},d=Math.max(18,l-u.y),h=7*(i%g-(g-1)/2),p=Math.min(l-10,u.y+.48*d+h);w.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:hu([u,{x:u.x,y:p},{x:s,y:p},{x:s,y:l}])})});let k=new Map(v.map(e=>[e.id,e])),S=new Map(w.map(e=>[e.edgeID,e]));return{tasks:x,sockets:v,routes:w,taskByID:b,socketByID:k,routeByEdgeID:S}}(c,{width:a,height:s}),m=function(e,t,i){let r=e.nodes.map(nu).filter(e=>null!=e),n=(r.length&&r.reduce((e,t)=>Math.min(e,t),1/0),i),o=new Set,a=new Map;for(let t of e.nodes){let e=nu(t),i=null!=e&&e<=n,r="done"===t.status&&!0;(i||r)&&o.add(t.id),t.blockerReason&&!o.has(t.id)&&a.set(t.id,t.blockerReason)}let s=new Set;for(let t of e.edges)o.has(t.sourceID)&&s.add(t.id);return{currentTime:n,playing:!1,completed:o,delivered:s,inFlight:new Set,armed:ou(e,s,a,o),blockers:a,previewTaskID:null}}(c,0,ru(n.currentTime,1/0)),y=Array.isArray(n.selectedTaskIDs)?n.selectedTaskIDs.map(String):[],x=new Set(y),b=y[0]??null,w=b&&"none"!==n.insight?pu(c,b,{completedTaskIDs:m.completed}):null,k=new Set(w?.downstreamTaskIDs??[]),S=function(e){return"number"==typeof e&&Number.isFinite(e)?e:31}(n.seed),A=function(e,t,i){let r="string"==typeof i?i:"Tasks are arranged by workstream and dependency depth. Completed tasks deliver their authored prerequisites; task completion remains an explicit data event.",n=[...t.blockers.keys()].map(i=>{let r=pu(e,i,{completedTaskIDs:t.completed});return`${e.byID.get(i)?.label??i} affects ${r.downstreamTaskCount} unfinished tasks across ${r.affectedLaneCount} lanes.`}).join(" ");return n?`${r} ${n}`:`${r} No explicit blockers are active.`}(c,m,r.description),M=Jc.renderToStaticMarkup(fu(iu,{machine:c,layout:g,runtime:m,downstreamSet:k,selectedSet:x,width:a,height:s,seed:S,reduced:!0,onSelectTask:()=>{}})),$=void 0===r.theme?{}:v(u),_=Jc.renderToStaticMarkup(gu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${p} ${f}`,style:{...$,fontFamily:d.fontFamily},children:[fu("title",{id:p,children:l}),fu("desc",{id:f,children:A}),fu("rect",{width:a,height:s,fill:d.background}),fu("text",{x:a/2,y:22,textAnchor:"middle",fontSize:d.titleFontSize,fontFamily:d.titleFontFamily,fontWeight:d.titleFontWeight,fill:d.text,children:l}),fu("g",{dangerouslySetInnerHTML:{__html:M}})]}));return t&&(t.evidence=pa({frameType:"physics",width:a,height:s,parts:[],additionalMarkCountByType:{task:c.nodes.length,dependency:c.edges.length},title:l,description:A,categories:c.lanes,nodeCount:c.nodes.length,edgeCount:c.edges.length})),_}},Wu={LineChart:Ur,BumpChart:jr,AreaChart:Kr,DifferenceChart:Qr,StackedAreaChart:Jr,Scatterplot:Ui,BubbleChart:Ki,Heatmap:on,QuadrantChart:tn,MultiAxisLineChart:Xr,WaterfallChart:Gr,CandlestickChart:en,ConnectedScatterplot:rn,ScatterplotMatrix:{frameType:"xy",buildProps:Eu,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=ku(e),s=function(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}(i),l=Array.isArray(a.fields)?a.fields.filter(e=>"string"==typeof e):[],c=a.fieldLabels&&"object"==typeof a.fieldLabels?a.fieldLabels:{},u=Ou(a.cellSize,150),d=Math.max(0,Su(a.cellGap,4)),h=Math.max(0,Su(a.pointRadius,2)),p=Math.max(0,Math.min(1,Su(a.pointOpacity,.5))),f=Ou(a.histogramBins,20),g="string"==typeof a.diagonal?a.diagonal:"histogram",m=40+l.length*u+l.length*d,y=l.length*u+40+l.length*d,x=$i(o.theme),b=_i(x),v=function(e,t,i,r){if(!t)return{categories:[],color:()=>Ut};let n=Array.from(new Set(e.map(e=>Bu(e,t)))),o="string"==typeof t?t:"__semioticSplomColor",a=ii("function"==typeof t?e.map(e=>({...e,[o]:Bu(e,t)})):e,o,i??r.colors.categorical);return{categories:n,color:e=>ei(e,t,a)}}(s,r,n,x),w=a.showLegend??!!r,k=ln(o.title)||void 0,S="string"==typeof o.description?o.description:`Scatterplot matrix comparing ${l.length} fields`,A=k?28:0,M=w?v.categories:[],$=0,_=0,P=M.map(e=>{let t=(e=>Math.max(72,30+7*e.length))(e);$>0&&$+t>m&&(_+=1,$=0);let i={label:e,x:$,y:24*_};return $+=t,i}),I=M.length?24*(_+1)+4:0,T=A+I,L=T+y,C=[],R=[],N=0;l.forEach((e,t)=>{l.forEach((i,n)=>{let l=40+d+n*(u+d),m=T+t*(u+d);if(t===n){let t=function(e){let{data:t,field:i,label:r,cellSize:n,bins:o,diagonal:a,colorBy:s,color:l,x:c,y:u}=e;if("label"===a)return{visibleBars:0,svg:un.renderToStaticMarkup(Nu("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:Nu("text",{x:n/2,y:n/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333",children:r})}))};let d=t.map(e=>Number(e[i])).filter(Number.isFinite),[h,p]=d.length?le(d):[0,0],f=(p-h)/o||1,g=Array.from({length:o},()=>new Map);for(let e of t){let t=Number(e[i]);if(!Number.isFinite(t))continue;let r=Math.max(0,Math.min(o-1,Math.floor((t-h)/f))),n=s?Bu(e,s):"__all",a=g[r];a.set(n,[...a.get(n)??[],e])}let m=g.map(e=>Array.from(e.values()).reduce((e,t)=>e+t.length,0)),y=ue(m,1),x=0,b=g.flatMap((e,t)=>{let i=0;return Array.from(e.entries()).flatMap(([e,r])=>{if(0===r.length)return[];x+=1;let a=r.length/y*(n-24),c=i;return i+=a,Nu("rect",{x:t/o*n,y:n-c-a,width:Math.max(n/o-1,1),height:a,fill:s?l(r[0]):Ut,opacity:.6},`${t}-${e}`)})});return{visibleBars:x,svg:un.renderToStaticMarkup(Du("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:[Nu("text",{x:n/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:r}),b]}))}}({data:s,field:e,label:ti(c,e)??e,cellSize:u,bins:f,diagonal:g,colorBy:r,color:v.color,x:l,y:m});return N+=t.visibleBars,void R.push(t.svg)}let y={},x=Qc({chartType:"scatter",data:s,size:[u,u],xAccessor:i,yAccessor:e,pointStyle:ae(e=>({r:h,opacity:p,fill:v.color(e)}),a.styleRules,re(i,e)),margin:Fu,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${ti(c,i)??i} versus ${ti(c,e)??e} scatterplot`,theme:o.theme,_idPrefix:`${String(o._idPrefix??"splom")}-${t}-${n}`},y);C.push(y.evidence),R.push(Au(x,l,m,`cell-${e}-${i}`))})});let D=_c(o),F=k?`${D}-title`:void 0,E=`${D}-description`,O=un.renderToStaticMarkup(Du("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:m,height:L,role:"img","aria-labelledby":[F,E].filter(Boolean).join(" "),style:{fontFamily:b.fontFamily},children:[k&&Nu("title",{id:F,children:k}),Nu("desc",{id:E,children:S}),Nu("rect",{width:m,height:L,fill:b.background}),k&&Nu("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:b.text,children:k}),P.map(e=>{let t=s.find(t=>r&&Bu(t,r)===e.label),i=t?v.color(t):Ut;return Du("g",{transform:`translate(${e.x},${A+e.y})`,children:[Nu("circle",{cx:5,cy:8,r:5,fill:i}),Nu("text",{x:14,y:12,fontSize:11,fill:b.text,children:e.label})]},e.label)}),l.map((e,t)=>{let i=T+t*(u+d)+u/2;return Nu("text",{x:20,y:i,transform:`rotate(-90 20 ${i})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:ti(c,e)??e},`row-${e}`)}),l.map((e,t)=>Nu("text",{x:40+d+t*(u+d)+u/2,y:T+l.length*(u+d)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:ti(c,e)??e},`column-${e}`)),Nu("g",{dangerouslySetInnerHTML:{__html:R.join("")}})]}));return t&&(t.evidence=pa({frameType:"xy",width:m,height:L,parts:C,additionalMarkCountByType:N>0?{histogram:N}:void 0,title:k,description:S,categories:v.categories.length?v.categories:void 0,legendItems:M.length||void 0})),O}},MinimapChart:zu},Yu=class e{constructor(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}push(e){if(!Number.isFinite(e))return;this._count+=1;let t=e-this._mean;this._mean+=t/this._count;let i=e-this._mean;this._m2+=t*i,e<this._min&&(this._min=e),e>this._max&&(this._max=e)}merge(e){if(0===e._count)return;if(0===this._count)return this._count=e._count,this._mean=e._mean,this._m2=e._m2,this._min=e._min,void(this._max=e._max);let t=this._count+e._count,i=e._mean-this._mean;this._mean+=i*e._count/t,this._m2+=e._m2+i*i*this._count*e._count/t,this._count=t,e._min<this._min&&(this._min=e._min),e._max>this._max&&(this._max=e._max)}clear(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}clone(){let t=new e;return t.merge(this),t}get count(){return this._count}get mean(){return this._mean}get sum(){return this._mean*this._count}get variance(){return this._count<2?0:this._m2/this._count}get stddev(){return Math.sqrt(this.variance)}get sampleVariance(){return this._count<2?0:this._m2/(this._count-1)}get sampleStddev(){return Math.sqrt(this.sampleVariance)}get min(){return this._min}get max(){return this._max}},qu=class e{constructor(e=10){let t=Math.max(4,Math.min(16,Math.floor(e)));this.p=t,this.m=1<<t,this.registers=new Uint8Array(this.m),this.alpha=.7213/(1+1.079/this.m),this.harmonicSum=this.m,this.zeros=this.m}add(e){let t=function(e){let t=b(e);return t^=t>>>16,t=Math.imul(t,2146121005),t^=t>>>15,t=Math.imul(t,2221713035),t^=t>>>16,t>>>0}(String(e)),i=t>>>32-this.p,r=Math.min(Math.clz32(t<<this.p),32-this.p)+1;this.updateRegister(i,r)}updateRegister(e,t){let i=this.registers[e];t<=i||(this.registers[e]=t,this.harmonicSum+=2**-t-2**-i,0===i&&this.zeros--)}merge(e){if(e.m===this.m)for(let t=0;t<this.m;t++)this.updateRegister(t,e.registers[t])}clone(){let t=new e(this.p);return t.registers.set(this.registers),t.harmonicSum=this.harmonicSum,t.zeros=this.zeros,t}count(){let e=this.alpha*this.m*this.m/this.harmonicSum;return e<=2.5*this.m&&this.zeros>0?Math.round(this.m*Math.log(this.m/this.zeros)):Math.round(e)}},Xu=class e{constructor(e=100){this.centroids=[],this.total=0,this.pending=0,this.compression=Math.max(20,e)}push(e){Number.isFinite(e)&&(this.centroids.push({mean:e,weight:1}),this.total+=1,this.pending++,this.pending>=2*this.compression&&this.compress())}merge(e){if(0===e.total)return;let t=0===this.total,i=e.centroids.length;for(let t=0;t<i;t++)this.centroids.push({...e.centroids[t]});this.total+=e.total,this.pending=t&&this.compression===e.compression?e.pending:this.pending+i,t||this.compress()}clone(){let t=new e(this.compression);return t.merge(this),t}quantile(e){if(0===this.total||Number.isNaN(e))return Number.NaN;let t=Math.min(1,Math.max(0,e));this.compress();let i=t*this.total,r=this.centroids[0].weight/2;if(i<=r)return this.centroids[0].mean;for(let e=1;e<this.centroids.length;e++){let t=this.centroids[e-1],n=this.centroids[e],o=(t.weight+n.weight)/2,a=r+o;if(i<=a){let e=(i-r)/o;return t.mean+(n.mean-t.mean)*e}r=a}return this.centroids[this.centroids.length-1].mean}get count(){return this.total}compress(){if(0===this.pending||(this.pending=0,this.centroids.length<=1))return;this.centroids.sort((e,t)=>e.mean-t.mean);let e=0,t=0,i=this.total,r=this.compression;for(let n=1;n<this.centroids.length;n++){let o=this.centroids[e],a=this.centroids[n],s=(t+o.weight/2)/i,l=4*i*s*(1-s)/r;if(o.weight+a.weight<=Math.max(1,l)){let e=o.weight+a.weight;o.mean=(o.mean*o.weight+a.mean*a.weight)/e,o.weight=e}else t+=o.weight,this.centroids[++e]=a}this.centroids.length=e+1}};function Gu(e){let t=Math.round(1e3*e)/10;return`p${String(t).replace(".","_")}`}function Vu(e,t){let i=e[0],r=e.pop();if(e.length>0){let i=0;for(;2*i+1<e.length;){let n=2*i+1;if(n+1<e.length&&t(e[n+1],e[n])<0&&n++,t(r,e[n])<=0)break;e[i]=e[n],i=n}e[i]=r}return i}var Hu=(e,t)=>e-t,Uu=class{constructor(e,t){this.stats=new Yu,this.digest=e?new Xu:null,this.hll=t?new qu:null}push(e,t){this.stats.push(e),this.digest?.push(e),this.hll&&this.hll.add(t??e)}merge(e){this.stats.merge(e.stats),this.digest?.merge(e.digest),this.hll?.merge(e.hll)}},Zu=class{constructor(e){this.windows=new Map,this.starts=[],this.sessions=[],this.latest=-1/0,this.type=e.window??"tumbling",this.size=e.size;let t=e.hop??e.size;this.hop=t>0&&t<=e.size?t:e.size,this.gap=e.gap??e.size,this.retain=null!=e.retain&&e.retain>0?e.retain:1/0,this.percentiles=e.percentiles??[],this.wantDistinct=!0===e.distinct}newBucket(){return new Uu(this.percentiles.length>0,this.wantDistinct)}push(e,t,i){!Number.isFinite(e)||!Number.isFinite(t)||(e>this.latest&&(this.latest=e),"session"===this.type?this.pushSession(e,t,i):this.pushFixed(e,t,i),this.prune())}pushFixed(e,t,i){if("tumbling"===this.type||this.hop>=this.size){let r=Math.floor(e/this.size)*this.size;return void this.bump(r,t,i)}let r=this.hop,n=Math.floor(e/r);for(let o=Math.floor((e-this.size)/r)+1;o<=n;o++)this.bump(o*r,t,i)}bump(e,t,i){let r=this.windows.get(e);if(!r){if(this.windows.size>=this.retain&&e<this.starts[0])return;r=this.newBucket(),this.windows.set(e,r),this.retain!==1/0&&function(e,t,i){let r=e.length;for(e.push(t);r>0;){let n=r-1>>>1;if(i(e[n],t)<=0)break;e[r]=e[n],r=n}e[r]=t}(this.starts,e,Hu)}r.push(t,i)}pushSession(e,t,i){let r=e-this.gap,n=e+this.gap,o=0,a=this.sessions.length,s=this.sessions[a-1];if(!s||e>=s.end)o=a,s&&s.end>=r&&s.start<=n&&o--;else for(;o<a;){let e=o+a>>>1;this.sessions[e].end<r?o=e+1:a=e}let l=this.sessions[o];if(!l||l.start>n){let r=this.newBucket();return r.push(t,i),void this.sessions.splice(o,0,{start:e,end:e,bucket:r})}l.bucket.push(t,i),l.start=Math.min(l.start,e),l.end=Math.max(l.end,e);let c=o+1;for(;c<this.sessions.length&&this.sessions[c].start<=n;){let e=this.sessions[c++];l.bucket.merge(e.bucket),l.end=Math.max(l.end,e.end)}c>o+1&&this.sessions.splice(o+1,c-o-1)}prune(){if(this.retain!==1/0){if("session"===this.type)return void(this.sessions.length>this.retain&&this.sessions.splice(0,this.sessions.length-this.retain));for(;this.windows.size>this.retain;)this.windows.delete(Vu(this.starts,Hu))}}emit(){if("session"===this.type)return this.sessions.map(e=>{let t=this.latest-e.end<this.gap;return this.row(e.start,e.end,e.bucket,t)});let e=[];for(let[t,i]of this.windows){let r=t+this.size;e.push(this.row(t,r,i,this.latest<r))}return e.sort((e,t)=>e.start-t.start),e}row(e,t,i,r){let n=i.stats,o={start:e,end:t,count:n.count,mean:n.mean,sum:n.sum,min:n.min,max:n.max,stddev:n.stddev,partial:r};if(i.digest){let e={};for(let t of this.percentiles)e[Gu(t)]=i.digest.quantile(t);o.percentiles=e}return i.hll&&(o.distinct=i.hll.count()),o}get windowCount(){return"session"===this.type?this.sessions.length:this.windows.size}get watermark(){return this.latest}clear(){this.windows.clear(),this.starts=[],this.sessions=[],this.latest=-1/0}};function Ku(e,t){switch(t){case"distinct":return e.distinct??0;case"p50":case"p95":case"p99":return e.percentiles?.[t]??Number.NaN;default:return e[t]??e.mean}}var Qu={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},Ju=/(\d+(?:\.\d+)?)(ms|s|m|h|d)/g;function ed(e){if("number"==typeof e)return Number.isFinite(e)&&e>0?e:null;if("string"!=typeof e)return null;let t=e.trim();if(""===t)return null;Ju.lastIndex=0;let i,r=0,n=0;for(;null!==(i=Ju.exec(t));){let e=parseFloat(i[1]),t=Qu[i[2]];if(null==t||!Number.isFinite(e))return null;r+=e*t,n+=i[0].length}return n!==t.length?null:r>0?r:null}var td="time",id="value",rd="__aggLower",nd="__aggUpper",od="__aggPartial",ad="count",sd="__aggStart",ld="__aggEnd";function cd(e,t){let i=t.stat??"mean",r=t.band??"none",n=t.sigma??1;return e.emit().map(e=>{let t={[td]:(e.start+e.end)/2,[id]:Ku(e,i),[ad]:e.count,[od]:e.partial,[sd]:e.start,[ld]:e.end},o=function(e,t,i,r=1){if("none"===t)return null;if("minmax"===t)return[e.min,e.max];let n=Ku(e,i),o=e.stddev*r;return[n-o,n+o]}(e,r,i,n);return o&&(t[rd]=o[0],t[nd]=o[1]),t})}function ud(e){return"none"!==(e.band??"none")}var dd="__aggSeries",hd=class{constructor(e,t){this.config=e,this.seriesAccessor=t,this.groups=new Map}push(e,t,i){let r=kt(e,t,"time"),n=wt(e,i,"value");if(null==r||null==n)return;let o=null==this.seriesAccessor?"":String("function"==typeof this.seriesAccessor?this.seriesAccessor(e):e[this.seriesAccessor]),a=this.groups.get(o);if(!a){if(a=function(e){let t=e.window??"tumbling",i=ed("session"===t?e.gap??e.size:e.size);if(null==i)return null;let r=null!=e.hop?ed(e.hop):void 0,n=null!=e.gap?ed(e.gap):void 0;return new Zu({window:t,size:i,hop:r??void 0,gap:n??void 0,retain:e.retain,percentiles:e.percentiles,distinct:e.distinct})}(this.config),!a)return;this.groups.set(o,a)}a.push(+r,n)}emit(e){let t=[];for(let[i,r]of this.groups)for(let n of cd(r,e))t.push(null==this.seriesAccessor?n:{...n,[dd]:i});return t}clear(){this.groups.clear()}};function pd(e,t,i){return e??i??Math.max(t?.length??0,200)}function fd(e){let t=e.timeAccessor||"time",i=e.valueAccessor||"value";return{timeAccessor:e=>kt(e,t,"time")??NaN,valueAccessor:e=>wt(e,i,"value")??NaN}}function gd(e,t,i){return{runtimeMode:"streaming",windowMode:i.windowMode??i.capacityMode??"sliding",windowSize:pd(i.windowSize,e,i.capacity),arrowOfTime:i.arrowOfTime??"right",...fd(i),xExtent:i.timeExtent??t.xExtent,yExtent:i.valueExtent??t.yExtent,extentPadding:i.extentPadding??t.extentPadding,tickFormatTime:i.tickFormatTime,tickFormatValue:i.tickFormatValue}}var md={RealtimeLineChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=function(e,t){let i=Array.isArray(e)?Mt(e):[],r=t.aggregate;if(!r)return i;let n=new hd(r,t.seriesAccessor);for(let e of i)n.push(e,t.timeAccessor,t.valueAccessor);return n.emit(r)}(e,n),a=n.aggregate,s=n.aggregate?{timeAccessor:"time",valueAccessor:"value"}:fd(n),l=ae(()=>({stroke:"#007bff",strokeWidth:2}),n.styleRules,re(s.timeAccessor,s.valueAccessor));return{chartType:"line",data:o,...r,...gd(o,r,n),...s,groupAccessor:a&&null!=n.seriesAccessor?dd:n.seriesAccessor,...a&&{windowMode:"growing",windowSize:Math.max(1,a.retain??Math.max(o.length,600)),band:ud(a)?{y0Accessor:rd,y1Accessor:nd,perSeries:null!=n.seriesAccessor}:void 0},lineStyle:r.lineStyle||(e=>({...l(e),...bi(n),...null!=n.strokeDasharray&&{strokeDasharray:n.strokeDasharray},...null!=n.cursor&&{cursor:n.cursor}}))}}},RealtimeHistogram:/*#__PURE__*/Object.assign({},Zr,{buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?Mt(e):[];return{...Zr.buildProps(o,t,i,r,n),...gd(o,r,n)}}}),TemporalHistogram:Zr,RealtimeSwarmChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?Mt(e):[],a=Zi(o,r,n,"discovery"),s=ae(void 0,n.styleRules,re(n.timeAccessor??"time",n.valueAccessor??"value"));return{chartType:"swarm",data:o,...r,...gd(o,r,n),categoryAccessor:n.categoryAccessor,colorScheme:a||i||r.colorScheme,barColors:a,yScaleType:n.yScaleType,swarmStyle:{...bi(n),fill:n.fill,radius:n.radius,cursor:n.cursor},pointStyle:e=>({...s(e),..."function"==typeof n.pointStyle?n.pointStyle(e):{},..."function"==typeof r.pointStyle?r.pointStyle(e):r.pointStyle})}}},RealtimeWaterfallChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?Mt(e):[],a=Gr.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value"});return{...a,...gd(o,r,n),waterfallStyle:{...a.waterfallStyle,cursor:n.cursor}}}},RealtimeHeatmap:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?Mt(e):[];return{...on.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value",heatmapAggregation:n.aggregation??"count",cellBorderWidth:0}),...gd(o,r,n),categoryAccessor:n.categoryAccessor}}}};import{useMemo as yd,useCallback as xd,useRef as bd}from"react";var vd={RdBu:Bt,PiYG:jt,PRGn:Wt,BrBG:Yt,RdYlBu:qt,RdYlGn:Xt,Spectral:Gt},wd="__likert_neutral_neg",kd="__likert_neutral_pos";function Sd(e,t){if("function"==typeof e)return e;let i=e||t;return e=>e[i]}import{jsx as Ad,jsxs as Md}from"react/jsx-runtime";function $d({value:e,min:t,max:i,radius:r,innerRadius:n,showScaleLabels:o,label:a}){let s=function(e,t,i){let r=Math.max(16,.3*t);if(null==i||i<=0)return r;let n=$s(e,r),o=2*i*.8;return n<=o?r:r*o/n}(e,r,n),l=.7*s+11;return Md("g",{textAnchor:"middle",children:[Ad("text",{y:0,dominantBaseline:"central",fontSize:s,fontWeight:700,fill:"var(--semiotic-text, #333)",children:e}),o&&Md("text",{y:l,fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:[t," – ",i]}),null!=a&&""!==a&&Ad("text",{y:l+(o?14:0),fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:a})]})}function _d(e){return Math.max(0,Math.min(1,e))}function Pd(e){let t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let i=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i){let e=[Number(i[1]),Number(i[2]),Number(i[3])];if(e.every(Number.isFinite))return e}return null}function Id(e,t,i){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function Td(e,t,i){let r=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:_d(e.offset),color:e.color??i,opacity:null==e.opacity?1:_d(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===r.length)return"#999999";let n=e=>{if(1===e.opacity)return e.color;let t=Pd(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===r.length)return n(r[0]);let o=_d(t);if(o<=r[0].offset)return n(r[0]);if(o>=r[r.length-1].offset)return n(r[r.length-1]);for(let e=0;e<r.length-1;e++){let t=r[e],i=r[e+1];if(o<t.offset||o>i.offset)continue;let a=i.offset-t.offset,s=a<=0?0:(o-t.offset)/a,l=Pd(t.color),c=Pd(i.color);if(!l||!c)return n(s<.5?t:i);let[u,d,h]=l,[p,f,g]=c,m=u+(p-u)*s,y=d+(f-d)*s,x=h+(g-h)*s,b=t.opacity+(i.opacity-t.opacity)*s;return 1===b?Id(m,y,x):`rgba(${Math.round(m)},${Math.round(y)},${Math.round(x)},${b})`}return n(r[r.length-1])}function Ld(e,t,i){return null==i?`${e}-${t}`:`${e}-${t}-${i}`}function Cd(e=240){let t=e*Math.PI/180,i=360-e,r=180+i/2,n=r*Math.PI/180;return{sweepRad:t,gapDeg:i,startAngleDeg:r,startAngleRad:n,offsetRad:-Math.PI/2+n}}import{Fragment as Rd,jsx as Nd,jsxs as Dd}from"react/jsx-runtime";function Fd(e){return pi(e)}function Ed(e,t,i,r,n,o){let a=$i(r.theme).colors.categorical,s=i??r.colorScheme,l=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",u="function"==typeof t?l.map(e=>({...e,__ssrColorBy:t(e)})):l,d=t?ii(u,c,s??a):void 0,h=ni("string"==typeof n.color?n.color:void 0,a,s,void 0,new Map),p=o??ie(n.valueAccessor??"value"),f=n.styleRules,g=r.pieceStyle;return(e,i)=>{let r={fill:t&&d?ei(e,t,d):h};return f?.length&&Object.assign(r,oe(e,f,{value:p(e,i),category:i})),"function"==typeof g?Object.assign(r,g(e,i)||{}):g&&"object"==typeof g&&Object.assign(r,g),void 0!==n.stroke&&(r.stroke=n.stroke),void 0!==n.strokeWidth&&(r.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(r.opacity=n.opacity),r}}function Od(e,t,i,r,n,o="median",a=.8){let s=ie(n.valueAccessor??"value"),l=Ed(e,t,i,r,n,e=>"number"==typeof e[o]?e[o]:s(e));return(e,t)=>{let i=l(e,t);return void 0===i.fillOpacity&&(i.fillOpacity=a),void 0===i.stroke&&(i.stroke=i.fill),i}}function zd(e,t,i,r,n){return Od(e,t,i,r,n,"median",.6)}function Bd(e,t,i,r,n){let o=Ed(e,t,i,r,n),a="number"==typeof n.dotRadius?n.dotRadius:5;return(e,t)=>({r:a,fillOpacity:.8,...o(e,t)})}function jd(e,t,i,r,n){let o=Ed(e,t,i,r,n),a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=n.sizeBy,l=Array.isArray(n.sizeRange)?n.sizeRange:[3,8],c=s?a.map(e=>"function"==typeof s?s(e):Number(e[s])).filter(Number.isFinite):[],u=c.length?le(c):void 0,d="number"==typeof n.pointRadius?n.pointRadius:4,h="number"==typeof n.pointOpacity?n.pointOpacity:.7;return(e,t)=>({r:s?ri(e,s,l,u):d,fillOpacity:h,...o(e,t)})}var Wd={BarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=vi(r.annotations,n.regression);return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,colorAccessor:t,colorScheme:i,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,...o&&{annotations:o},gradientFill:Fd(r.gradientFill),pieceStyle:Ed(e,t,i,r,n)}}},StackedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.stackBy;return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Fd(r.gradientFill),pieceStyle:Ed(e,o,i,r,n),showLegend:r.showLegend??!!o}}},GroupedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.groupBy;return{chartType:"clusterbar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Fd(r.gradientFill),pieceStyle:Ed(e,o,i,r,n),showLegend:r.showLegend??!!o}}},SwarmPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"swarm",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},barPadding:n.categoryPadding??20,colorAccessor:t,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,sizeRange:n.sizeRange||[3,8],pieceStyle:jd(e,t,i,r,n),showLegend:r.showLegend??!!t})},BoxPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"boxplot",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},colorAccessor:t,colorScheme:i,...null!=n.showOutliers&&{showOutliers:n.showOutliers},...null!=n.outlierRadius&&{outlierRadius:n.outlierRadius},...r,summaryStyle:Od(e,t,i,r,n)})},Histogram:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.valueAccessor||"value",s=o.map(e=>Number("function"==typeof a?a(e):e[a])).filter(Number.isFinite),l=s.length?le(s):void 0;return{chartType:"histogram",data:e,oAccessor:n.categoryAccessor||(e=>null==e.category?"All":String(e.category)),rAccessor:a,projection:"horizontal",bins:n.bins??25,normalize:n.relative??!1,colorAccessor:t,colorScheme:i,barPadding:n.categoryPadding??20,...n.valueExtent?{rExtent:n.valueExtent}:l?{rExtent:l}:{},...r,summaryStyle:Od(e,t,i,r,n,"count")}}},ViolinPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"violin",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===n.orientation?"horizontal":"vertical",bins:n.bins??25,showIQR:n.showIQR??!0,barPadding:n.categoryPadding??20,colorScheme:i,...r,summaryStyle:zd(e,t,i,r,n),showLegend:r.showLegend??!!t,...n.valueExtent&&{rExtent:n.valueExtent}})},RidgelinePlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"ridgeline",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},bins:n.bins??20,amplitude:n.amplitude??1.5,barPadding:n.categoryPadding??5,oSort:n.oSort??!1,...r,summaryStyle:Od(e,t,i,r,n,"median",.5),showLegend:r.showLegend??!!t})},DotPlot:{frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,i,r,n)=>{let o=vi(r.annotations,n.regression);return{chartType:"point",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??"auto",barPadding:n.categoryPadding??10,...r,...o&&{annotations:o},pieceStyle:Bd(e,t,i,r,n),showGrid:r.showGrid??!0,showLegend:r.showLegend??!!t}}},PieChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=ie(n.valueAccessor??"value");return{chartType:"pie",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:Ed(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)}),showLegend:r.showLegend??!!o}}},DonutChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=ie(n.valueAccessor??"value");return{chartType:"donut",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",margin:r.margin??{top:50,right:40,bottom:60,left:70},innerRadius:n.innerRadius??60,colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:Ed(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)})}}},GaugeChart:{frameType:"ordinal",renderOverlay:function(e,{theme:t}){let i=e.__gauge;if(!i)return null;let r=Math.max(i.gMin,Math.min(i.gMax,i.value??i.gMin)),n=i.gMax===i.gMin?0:(r-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.needleColor||t.colors.text,s=i.showScaleLabels?(i.thresholds||[]).filter(e=>e.value>i.gMin&&e.value<i.gMax):[];return Dd(Rd,{children:[i.showNeedle&&Dd(Rd,{children:[Nd("line",{x1:i.centerX,y1:i.centerY,x2:i.centerX+i.needleLength*Math.cos(o),y2:i.centerY+i.needleLength*Math.sin(o),stroke:a,strokeWidth:2.5,strokeLinecap:"round"}),Nd("circle",{cx:i.centerX,cy:i.centerY,r:4,fill:a})]}),null!=i.contextValue&&Nd("text",{x:i.centerX,y:i.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:i.valueFontSize,fontWeight:700,fill:a,children:i.contextValue}),s.map((e,r)=>{let n=i.gMax===i.gMin?0:(e.value-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.innerRadius-1,s=i.radius+1,l=i.radius+10,c=((o+Math.PI/2)/(2*Math.PI)*12+12)%12,u=c>=11||c<1?"middle":c<5?"start":c<7?"middle":"end",d=c>=11||c<1?"auto":c<5?"middle":c<7?"hanging":"middle";return Dd("g",{children:[Nd("line",{x1:i.centerX+Math.cos(o)*a,y1:i.centerY+Math.sin(o)*a,x2:i.centerX+Math.cos(o)*s,y2:i.centerY+Math.sin(o)*s,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),Nd("text",{x:i.centerX+Math.cos(o)*l,y:i.centerY+Math.sin(o)*l,textAnchor:u,dominantBaseline:d,fill:t.colors.textSecondary,fontSize:10,children:e.label||String(e.value)})]},`gauge-label-${r}`)})]})},buildProps:(e,t,i,r,n)=>{let o=n.min??0,a=n.max??100,s=n.sweep??240,l=n.arcWidth??.3,c=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:d}=Cd(s),h=r.__resolvedMode??n.mode,p="context"===h||"sparkline"===h,f=n.showScaleLabels??!p,g=n.thresholds,m=fi(r.gradientFill),y=function(e){let{min:t,max:i,value:r,thresholds:n,fillColor:o,backgroundColor:a,fillZones:s,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=e,d=Math.max(t,Math.min(i,r)),h=i-t||1,p=(d-t)/h,f=n&&n.length>0?[...n].sort((e,t)=>e.value-t.value):[{value:i,color:o||"#007bff"}];f=f.map(e=>({...e,value:Math.max(t,Math.min(i,e.value))})),f[f.length-1].value<i&&f.push({value:i,color:f[f.length-1].color});let g=!!c&&c.stops.length>=2,m=[],y=new Map,x=[];if(g){let e=s?p:1,t=Ld("bg",0);if(m.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(t,{fill:a,opacity:.4}),e>0){let t=Math.max(1,Math.floor(u)),i=Math.max(1,Math.min(t,Math.round(e*t))),r=[];for(let t=0;t<i;t++){let n=e*(t+.5)/i;r.push(Td(c.stops,n,o||f[0]?.color||"#007bff"))}let n=Ld("fill",0);m.push({category:n,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:r}}),y.set(n,{fill:r[0]||a})}}else{let e=t;for(let n=0;n<f.length;n++){let o=f[n],l=(o.value-e)/h,c=(e-t)/h,u=(o.value-t)/h,g=s?Math.min(p,u):u,x=Math.max(0,g-c),b=s?Math.max(0,l-x):0;if(x>0){let a=Ld("fill",n);m.push({category:a,value:x,_zone:o.label||`Zone ${n+1}`,_isFill:!0,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:e,segmentEnd:t+g*h,filled:!0}}),y.set(a,{fill:o.color})}if(b>0){let s=Ld("bg",n);m.push({category:s,value:b,_zone:o.label||`Zone ${n+1}`,_isFill:!1,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:Math.max(e,d),segmentEnd:o.value,filled:!1}}),y.set(s,{fill:a,opacity:.4})}e=o.value}}if(l&&n&&n.length>0)for(let e of n)e.value>t&&e.value<i&&x.push({type:"gauge-label",value:e.value,label:e.label||String(e.value)});return{gaugeData:m,pieceStyle:(e,t)=>{let i=t||e.category;return y.get(i)||{fill:a}},gaugeAnnotations:x}}({min:o,max:a,value:n.value,thresholds:g,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:f,gradientFill:m}),x=n.styleRules,[b,v]=r.size||[300,250],w=function(e=240){let{sweepRad:t,offsetRad:i}=Cd(e),r=[[Math.cos(i),Math.sin(i)],[Math.cos(i+t),Math.sin(i+t)],[0,0]];for(let e=0;e<2*Math.PI;e+=Math.PI/2)((e-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)<=t+.001&&r.push([Math.cos(e),Math.sin(e)]);let n=r.map(e=>e[0]),o=r.map(e=>e[1]),[a,s]=le(n),[l,c]=le(o);return{minX:a,maxX:s,minY:l,maxY:c,width:s-a,height:c-l,cx:(a+s)/2,cy:(l+c)/2}}(s),k=Math.min(10,Math.max(1,Math.min(b,v)/12)),S=Math.max(4,Math.min((b-2*k)/w.width,(v-2*k)/w.height)-2),A=Math.max(0,Math.min(S-1.5,S*(1-l))),M=b/2-w.cx*S,$=v/2-w.cy*S,_=2*(S+4),P=Math.max(o,Math.min(a,n.value??o)),I="function"==typeof n.valueFormat?n.valueFormat(P):String(Math.round(P)),T=n.centerContent??r.centerContent,L=function({centerContent:e,centerLabel:t,value:i,min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,valueFormat:l,compact:c}){if(null!=e){let s="function"==typeof e?e(i,r,n):e;return"string"==typeof s||"number"==typeof s?$d({value:String(s),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:!1,label:t}):s}return c?null:$d({value:l?l(i):String(Math.round(i)),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,label:t})}({centerContent:T,centerLabel:"string"==typeof n.centerLabel?n.centerLabel:void 0,value:P,min:o,max:a,radius:S,innerRadius:A,showScaleLabels:f,valueFormat:"function"==typeof n.valueFormat?n.valueFormat:void 0,compact:p});return{chartType:"donut",data:y.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:A,sweepAngle:s,startAngle:d,oSort:!1,pieceStyle:ai((e,t)=>{let i={...y.pieceStyle(e,t)};return x?.length&&Object.assign(i,oe(e,x,{value:"number"==typeof e.value?e.value:void 0,category:t??(null==e.category?void 0:String(e.category))})),i},bi(n)),...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...r,size:[b,v],margin:{top:$-_/2,bottom:v-$-_/2,left:M-_/2,right:b-M-_/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(r.annotations)?r.annotations:[],...y.gaugeAnnotations],__gauge:{gMin:o,gMax:a,sweep:s,arcWidth:l,value:P,startAngleDeg:d,thresholds:g,centerX:M,centerY:$,radius:S,innerRadius:A,showScaleLabels:f,needleLength:A>20?A-8:S-1,showNeedle:c,needleColor:n.needleColor,..."context"===h&&null==T&&{contextValue:I,contextValueY:$-.2*A,valueFontSize:Math.max(12,Math.min(22,.28*S))}}}}},FunnelChart:{frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="vertical"===n.orientation,a=t||n.categoryAccessor;return{chartType:o?"bar-funnel":"funnel",data:e,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:a,categoryAccessor:n.categoryAccessor,projection:o?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!o&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:o?40:0,colorScheme:i,...r,showAxes:o&&!1!==r.showAxes,showGrid:o,pieceStyle:Ed(e,a,i,r,n),showLabels:n.showLabels??!0}}},RadarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=n.seriesAccessor||t||"__radar",a=t||("__radar"===o?void 0:o),s=Bd(e,a,i,r,{...n,dotRadius:n.pointRadius??4});return{chartType:"point",projection:"radial",data:e,oAccessor:n.categoryAccessor||"attribute",rAccessor:n.valueAccessor||"value",colorAccessor:a,colorScheme:i,connectorAccessor:o,connectorStyle:e=>{let t=s(e),i="string"==typeof t.fill?t.fill:void 0;return{fill:i,fillOpacity:.15,stroke:i,strokeWidth:2,opacity:.7}},pieceStyle:s,rExtent:n.valueExtent||[0],oLabel:"",...r,...n.categoryFormat&&{oFormat:n.categoryFormat},showLegend:r.showLegend??!!a}}},SwimlaneChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:o,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...null!=n.trackFill&&{trackFill:n.trackFill},...n.valueExtent&&{rExtent:n.valueExtent},...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Fd(r.gradientFill),pieceStyle:Ed(e,o,i,r,n),showLegend:r.showLegend??!!o,barPadding:n.barPadding??40}}},LikertChart:{frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.levels)&&n.levels.length>=2?n.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],a="vertical"!==n.orientation,s=function(e,t,i,r,n,o,a={}){let s=new Map,l=new Set(t);for(let a of e){let e=i(a);s.has(e)||s.set(e,new Map);let c=s.get(e);if(r){let e=r(a);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}let i=e-1;if(i<0||i>=t.length)continue;let n=t[i];c.set(n,(c.get(n)||0)+1)}else if(n&&o){let e=n(a),t=o(a);if(!l.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}let c=[];for(let[e,i]of s){let r=0;for(let e of t)r+=i.get(e)||0;if(0!==r)for(let n=0;n<t.length;n++){let o=t[n],s=i.get(o)||0,l={};a.category&&(l[a.category]=e),a.level&&(l[a.level]=o),a.count&&(l[a.count]=s),a.score&&(l[a.score]=n+1),c.push({...l,__likertCategory:e,__likertLevel:o,__likertLevelLabel:o,__likertCount:s,__likertPct:s/r*100,__likertLevelIndex:n})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],o,Sd(n.categoryAccessor,"question"),n.levelAccessor?null:Sd(n.valueAccessor,"score"),n.levelAccessor?Sd(n.levelAccessor,"level"):null,n.levelAccessor?Sd(n.countAccessor,"count"):null,{category:"string"==typeof n.categoryAccessor?n.categoryAccessor:void 0,level:"string"==typeof n.levelAccessor?n.levelAccessor:void 0,count:"string"==typeof n.countAccessor?n.countAccessor:void 0,score:n.levelAccessor||"string"!=typeof n.valueAccessor?void 0:n.valueAccessor});a&&(s=function(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=new Map;for(let t of e){let e=o.get(t.__likertCategory)||[];e.push(t),o.set(t.__likertCategory,e)}let a=[];for(let[,e]of o){let t,o,s=new Map;for(let i of e)i.__likertLevel===wd?t=i:i.__likertLevel===kd?o=i:s.set(i.__likertLevelIndex,i);r&&t&&a.push(t);for(let e=n-1;e>=0;e--){let t=s.get(e);t&&a.push(t)}r&&o&&a.push(o);for(let e=r?n+1:n;e<i;e++){let t=s.get(e);t&&a.push(t)}}return a}(function(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=[];for(let t of e){let e=t.__likertLevelIndex;if(r&&e===n){let e=t.__likertPct/2;o.push({...t,__likertLevel:wd,__likertPct:-e}),o.push({...t,__likertLevel:kd,__likertPct:e})}else e<n?o.push({...t,__likertPct:-t.__likertPct}):o.push(t)}return o}(s,o),o));let l=$i(r.theme).colors.diverging,c=Array.isArray(i)&&i.length>=o.length?i:function(e,t){if(e<=0)return[];if(t&&Object.prototype.hasOwnProperty.call(vd,t)){let i=vd[t];if(1===e)return[i(.5)];let r=[];for(let t=0;t<e;t++)r.push(i(t/(e-1)));return r}let i=["#da1e28","#ff8389","#ffb3b8"],r=["#a6c8ff","#4589ff","#0043ce"],n="#a8a8a8";if(1===e)return[n];let o=e%2!=0,a=Math.floor(e/2),s=[];for(let e=0;e<a;e++)s.push(i[Math.min(Math.floor(e*i.length/a),i.length-1)]);o&&s.push(n);for(let e=0;e<a;e++)s.push(r[Math.min(Math.floor(e*r.length/a),r.length-1)]);return s}(o.length,l),u=new Map(o.map((e,t)=>[e,c[t]||"#888"])),d=o.length%2&&u.get(o[Math.floor(o.length/2)])||"#888",h="function"==typeof n.valueFormat?n.valueFormat:e=>`${Math.abs(Number(e)).toFixed(0)}%`,p=pe(!1===r.showLegend?void 0:{legendGroups:[{label:"",items:o.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},r.legend),f=n.styleRules,g=r.pieceStyle;return{chartType:"bar",data:s,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:a?"horizontal":"vertical",barPadding:n.barPadding,showGrid:r.showGrid,oLabel:n.categoryLabel,rLabel:n.valueLabel||(a?void 0:"Percentage"),rFormat:h,...n.categoryFormat&&{oFormat:n.categoryFormat},...n.valueExtent&&{rExtent:n.valueExtent},...r,pieceStyle:ai((e,t)=>{let i=e.__likertLevel||e.data?.__likertLevel,r=e.__likertLevelLabel||e.data?.__likertLevelLabel,n=e.__likertPct??e.data?.__likertPct,o={fill:i===wd||i===kd?d:u.get(String(r||i))||"#888"};return f?.length&&Object.assign(o,oe(e,f,{value:"number"==typeof n?n:void 0,category:t??(null==r?void 0:String(r))})),"function"==typeof g?Object.assign(o,g(e,t)||{}):g&&"object"==typeof g&&Object.assign(o,g),o},bi(n)),showLegend:r.showLegend??!0,legendPosition:r.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}}};import{interpolateRgb as Yd}from"d3-interpolate";var qd=e=>{let t=e.config,{plot:i}=e.dimensions;if(i.width<=0||i.height<=0)return{nodes:[]};let r="utc"===t.timeZone,n=(e,t,i)=>{let n=new Date(0);return r?(n.setUTCFullYear(e,t,i),n.setUTCHours(0,0,0,0)):(n.setFullYear(e,t,i),n.setHours(0,0,0,0)),n},o=e=>r?e.getUTCFullYear():e.getFullYear(),a=e=>`${o(e)}-${Xd(r?e.getUTCMonth()+1:e.getMonth()+1)}-${Xd(r?e.getUTCDate():e.getDate())}`,s=e=>{let i="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];if(i instanceof Date)return i;if("string"==typeof i&&/^\d{4}-\d{2}-\d{2}$/.test(i)){let[e,t,r]=i.split("-").map(Number);return n(e,t-1,r)}return new Date(i)},l=e=>{let i="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return null==i?NaN:Number(i)},c=new Map,u=null;for(let t of e.data){let e=s(t);if(!isFinite(e.getTime()))continue;null==u&&(u=o(e));let i=a(e),r=l(t);Number.isFinite(r)&&c.set(i,(c.get(i)??0)+r)}let d=t.year??u??o(new Date),h=1/0,p=-1/0;for(let[e,t]of c)e.startsWith(`${d}-`)&&(t<h&&(h=t),t>p&&(p=t));h===1/0&&(h=0,p=0);let[f,g]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],m=t.missingColor??e.theme.semantic.grid??"#d1d5db",y=e=>{if(p===h)return f;let t=(e-h)/(p-h);return Yd(f,g)(t)},x=t.gutter??2,b=t.labelInset??0,v=i.width-b,w=i.height,k=Math.min((v-53*x)/54,(w-6*x)/7);if(k<=0)return{nodes:[]};let S=n(d,0,1),A=((r?S.getUTCDay():S.getDay())-(t.weekStart??0)+7)%7,M=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let r=n(d,0,1-A+7*e+t);if(o(r)!==d)continue;let s=a(r),l=c.get(s),u=null==l?m:y(l);M.push({type:"rect",x:i.x+b+e*(k+x),y:i.y+t*(k+x),w:k,h:k,style:{fill:u,stroke:"none"},datum:{date:r,value:l??null,missing:null==l}})}return{nodes:M}};function Xd(e){return e<10?`0${e}`:String(e)}import{createElement as Gd,Fragment as Vd}from"react";import{scaleLinear as Hd}from"d3-scale";import{interpolateLab as Ud}from"d3-interpolate";function Zd(e,t={}){let i=t.baseOpacity??1;return t.highlight||t.predicate?!function(e,t){if(!t)return!0;let i=Array.isArray(t)?t:[t],r=e;for(let e of i)if(null!=e.value&&String(r[e.field])!==String(e.value))return!1;return!0}(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,i+(t.brighten??0)):i}function Kd(e){if(0===e.length)return 0;let t=0;for(let i of e)t+=i;return t/e.length}import{jsx as Qd,jsxs as Jd}from"react/jsx-runtime";function eh(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:Qd("text",{className:e.className,x:e.x,y:e.y,textAnchor:e.anchor??"middle",dominantBaseline:e.baseline??"middle",fontSize:t,fontWeight:e.fontWeight,fill:e.color,style:{pointerEvents:"none"},children:e.text},e.keyId)}var th=e=>{let t=e.config,{plot:i}=e.dimensions,r=t.fields??[];if(r.length<2||i.width<=0||i.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let n=Object.create(null);for(let i of r){let r=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,i)?t.domains[i]:void 0;if(Array.isArray(r)&&r.length>=2&&"number"==typeof r[0]&&Number.isFinite(r[0])&&"number"==typeof r[1]&&Number.isFinite(r[1])){n[i]=[r[0],r[1]];continue}let o=1/0,a=-1/0;for(let t of e.data){let e=Number(t[i]);Number.isFinite(e)&&(e<o&&(o=e),e>a&&(a=e))}if(Number.isFinite(o)&&Number.isFinite(a))if(o===a){let e=Math.max(.01*Math.abs(o),.5);n[i]=[o-e,a+e]}else n[i]=[o,a];else n[i]=[0,1]}let o=!1!==t.showAxes,a=o?t.axisLabelPadding??24:8,s=o?18:8,l=r.map(e=>Hd().domain(n[e]).range([i.y+i.height-s,i.y+a])),c=r.map((e,t)=>1===r.length?i.x+i.width/2:i.x+t/(r.length-1)*i.width),u=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,d=t.opacity??.45,h=t.strokeWidth??1.25,p=e.theme.semantic.primary??"#3b6cb1",f=t.dimmedOpacity??.08,g=t.highlightFn,m=[],y=[];for(let i of e.data){let n=u?e.resolveColor(String(u(i))):p,o=!g||g(i),a=Zd(i,{predicate:g,baseOpacity:d,dimOpacity:f,brighten:.4}),s=o?y:m;for(let e=0;e<r.length-1;e++){let t=Number(i[r[e]]),u=Number(i[r[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(u))continue;let d={type:"connector",x1:c[e],y1:l[e](t),x2:c[e+1],y2:l[e+1](u),style:{stroke:n,strokeWidth:g&&o?h+.75:h,opacity:a,fill:"none"},datum:i};s.push(d)}if(t.showPoints)for(let e=0;e<r.length;e++){let t=Number(i[r[e]]);if(!Number.isFinite(t))continue;let o={type:"point",x:c[e],y:l[e](t),r:2.5,style:{fill:n,stroke:"none",opacity:Math.min(1,a+.3)},datum:i};s.push(o)}}let x=null;if(o){let o=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,u=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,d=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=i.y+a,p=i.y+i.height-s,f=[];for(let e=0;e<r.length;e++){let s=r[e],g=c[e],m=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,s)?t.tickFormat[s]:void 0,y="function"==typeof m?m:e=>e.toLocaleString();f.push(Gd("line",{key:`pc-axis-line-${e}`,x1:g,x2:g,y1:h,y2:p,stroke:o,strokeWidth:1})),f.push(eh({keyId:`pc-axis-label-${e}`,text:s,x:g,y:i.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:u}));let[x,b]=n[s],v=5;for(let t=0;t<v;t++){let i=x+(b-x)*t/(v-1),r=l[e](i);f.push(Gd("line",{key:`pc-tick-${e}-${t}`,x1:g-3,x2:g+3,y1:r,y2:r,stroke:o,strokeWidth:1}),eh({keyId:`pc-ticktext-${e}-${t}`,text:y(i),x:g+6,y:r+3,anchor:"start",baseline:"auto",fontSize:10,color:d}))}}x=Gd(Vd,null,...f)}return{nodes:m.concat(y),overlays:x}},ih={frameType:"xy",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1,showLegend:r.showLegend??!!t})},rh={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1})},nh={frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,i,r,n)=>({chartType:"force",nodes:n.nodes||e||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:t,colorScheme:i,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...r})},oh={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({...rh.buildProps(e,t,i,r,n),customLayout:th,showAxes:!1})},ah={frameType:"xy",buildProps:(e,t,i,r,n)=>({...ih.buildProps(e,t,i,r,n),customLayout:qd,showAxes:!1})},sh={annotationBackground:"rgba(248, 250, 252, 0.94)",annotationStroke:"#334155",annotationText:"#0f172a",background:"#f8fafc",border:"#334155",closedWindowFill:"rgba(220, 38, 38, 0.08)",closedWindowStroke:"rgba(220, 38, 38, 0.55)",danger:"#dc2626",focus:"#f97316",grid:"#cbd5e1",gutterFill:"rgba(71, 85, 105, 0.14)",lateFill:"#f97316",openWindowFill:"rgba(14, 165, 233, 0.07)",openWindowStroke:"rgba(14, 165, 233, 0.3)",primary:"#0ea5e9",selectedFill:"#f97316",selectedStroke:"#7c2d12",success:"#22c55e",text:"#0f172a",textSecondary:"#475569",warning:"#f97316"},lh={background:{names:["--semiotic-bg","--surface-1","--surface-0"],fallback:sh.background},border:{names:["--semiotic-border","--surface-3"],fallback:sh.border},danger:{names:["--semiotic-danger","--viz-4"],fallback:sh.danger},focus:{names:["--semiotic-focus","--accent","--viz-9"],fallback:sh.focus},grid:{names:["--semiotic-grid","--surface-3"],fallback:sh.grid},primary:{names:["--semiotic-primary","--accent","--viz-5"],fallback:sh.primary},success:{names:["--semiotic-success","--viz-2"],fallback:sh.success},text:{names:["--semiotic-text","--text-primary"],fallback:sh.text},textSecondary:{names:["--semiotic-text-secondary","--text-secondary"],fallback:sh.textSecondary},warning:{names:["--semiotic-warning","--viz-9","--viz-3"],fallback:sh.warning}};function ch(e){let t=Object.fromEntries(Object.entries(e??{}).filter(([,e])=>null!=e).map(([e,t])=>[`--semiotic-physics-${e}`,t]));for(let i of Object.keys(lh))null!=e?.[i]&&(t[lh[i].names[0]]=e[i]);return t}var uh={annotationBackground:["background",.94],annotationStroke:["border"],annotationText:["text"],closedWindowFill:["danger",.08],closedWindowStroke:["danger",.55],gutterFill:["textSecondary",.14],lateFill:["warning"],openWindowFill:["primary",.07],openWindowStroke:["primary",.3],selectedFill:["warning"],selectedStroke:["focus"]};function dh(e){let t=lh[e],i=uh[e],r=sh[e];if(t)r=t.names.reduceRight((e,t)=>`var(${t}, ${e})`,t.fallback);else if(i){let e=dh(i[0]);r=null==i[1]?e:`color-mix(in srgb, ${e} ${100*i[1]}%, transparent)`}return`var(--semiotic-physics-${e}, ${r})`}import{jsx as hh,jsxs as ph}from"react/jsx-runtime";import*as fh from"react";import{jsx as gh,jsxs as mh}from"react/jsx-runtime";function yh(e,t,i,r="physics"){let n=function(e,t){let i=t.mark;if(i)return i;let r=e.datum,n=r?.__physicsMark??r?.mark;return"circle"===n||"halo"===n||"faceted"===n||"pill"===n||"diamond"===n||"square"===n||"triangle"===n||"hexagon"===n?n:"circle"===e.shape.type?"circle":"square"}(e,t),o="circle"===e.shape.type?t.r??e.shape.radius:Math.max(e.shape.width,e.shape.height)/2,a=function(e,t){return"function"==typeof t.glyph?t.glyph(e.datum&&"object"==typeof e.datum?e.datum:{}):t.glyph}(e,t);if(a)return ja({glyph:a,size:2*o,style:t,color:"string"==typeof t.fill?t.fill:void 0,accent:t.stroke},e.x,e.y,`physics-body-${i}`);let s=`${r}-body-${i}-hatch`,l=ka(t.fill)?Sa(t.fill,s):void 0,c=e=>l?mh(fh.Fragment,{children:[gh("defs",{children:l}),e]},`physics-body-${i}`):fh.cloneElement(e,{key:`physics-body-${i}`}),u={fill:l?`url(#${s})`:za(t.fill),stroke:t.stroke,strokeWidth:t.strokeWidth,opacity:t.opacity,fillOpacity:t.fillOpacity,strokeDasharray:t.strokeDasharray};if("circle"!==n||t.r){if("pill"===n||"square"===n||"aabb"===e.shape.type){let t="pill"===n?2.4*o:"aabb"===e.shape.type?e.shape.width:1.7*o,i="pill"===n?1.35*o:"aabb"===e.shape.type?e.shape.height:1.7*o;return c(gh("rect",{x:e.x-t/2,y:e.y-i/2,width:t,height:i,rx:"pill"===n?i/2:Math.min(4,t/4),...u}))}if("triangle"===n||"hexagon"===n||"faceted"===n||"diamond"===n){let t=function(e,t,i,r){return Array.from({length:r},(n,o)=>{let a=2*Math.PI*o/r-Math.PI/2;return[e+Math.cos(a)*i,t+Math.sin(a)*i]})}(e.x,e.y,o,"triangle"===n?3:"diamond"===n?4:6);return c(gh("path",{d:`${t.map(([e,t],i)=>`${i?"L":"M"}${e},${t}`).join("")}Z`,...u}))}return c(mh("g",{children:[gh("circle",{cx:e.x,cy:e.y,r:o,...u}),"halo"===n&&(t.strokeWidth??0)>0&&gh("circle",{cx:e.x,cy:e.y,r:1.35*o,fill:"none",stroke:t.stroke??u.fill,strokeWidth:Math.max(1.5,t.strokeWidth??1.5),opacity:.55*(t.opacity??1)})]}))}}import{jsx as xh,jsxs as bh}from"react/jsx-runtime";function vh(e,t){let i=e?.find(e=>e.id===String(t));return i?{...i.color?{fill:i.color}:{},...i.mark?{mark:i.mark}:{},...i.glyph?{glyph:i.glyph}:{}}:{}}function wh(e=[],t={},i){if("none"===t.side)return[];let r=e.filter(e=>!1!==e.visible),n=Math.max(48,t.tileSize??80),o=Math.max(1,r.length);return r.map((e,r)=>({source:e,x:"top"===t.side?(r+.5)*i[0]/o:"right"===t.side?i[0]-n/2:n/2,y:"top"===t.side?n/2+24:(r+.5)*i[1]/o}))}function kh(e,t,i,r){let n=wh(e,t,i);return n.length?xh("svg",{width:i[0],height:i[1],style:{position:"absolute",inset:0,pointerEvents:"none"},"data-testid":"event-drop-source-rail",children:n.map(({source:e,x:t,y:i},n)=>{let o={id:e.id,x:t,y:i-6,prevX:t,prevY:i-6,vx:0,vy:0,angle:0,mass:1,shape:{type:"circle",radius:12},sleeping:!0},a={fill:e.color??dh("primary"),mark:e.mark,glyph:e.glyph,r:12},s=`${e.label} ${!1===e.active?"off":"on"}`;return bh("g",{role:r?"button":"img",tabIndex:r?0:void 0,"aria-label":s,"aria-pressed":r?!1!==e.active:void 0,style:{pointerEvents:"auto",cursor:r?"pointer":void 0},onClick:()=>r?.(e),onKeyDown:t=>{r&&("Enter"===t.key||" "===t.key)&&(t.preventDefault(),r(e))},children:[xh("title",{children:e.description??s}),xh("rect",{x:t-24,y:i-30,width:48,height:54,rx:6,fill:dh("background"),stroke:dh("border")}),xh("g",{opacity:!1===e.active?.35:1,children:yh(o,a,n)}),xh("text",{x:t,y:i+18,textAnchor:"middle",fill:dh("text"),fontSize:10,children:e.label})]},e.id)})}):null}var Sh=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];function Ah(e,t,i){let r="object"==typeof t?"cycle"===t.window?Sh:t.window:void 0,n="object"==typeof t?void 0:t,o=Q(n,dh("primary"),i),a=new Map(e?.map(e=>[e.id,Q(n,e.color??dh("primary"),i)]));return t=>{let n=String(t.datum?.source??"");if(r?.length){let o=Number(t.datum?.windowIndex??0),a=r[(o%r.length+r.length)%r.length];return{...vh(e,n),...Q(void 0,a,i)(t)}}return{...vh(e,n),...(a.get(n)??o)(t)}}}import*as Mh from"react";import{scaleLinear as $h}from"d3-scale";function _h(e){return{...e,points:e.points.map(e=>({...e}))}}function Ph(e){if(!Number.isFinite(e.durationSeconds)||e.durationSeconds<=0||!Array.isArray(e.points)||e.points.length<2||e.points.some(e=>!e||!Number.isFinite(e.x)||!Number.isFinite(e.y))||null!=e.elapsedSeconds&&(!Number.isFinite(e.elapsedSeconds)||e.elapsedSeconds<0||e.elapsedSeconds>e.durationSeconds))throw new RangeError("Physics travel requires two finite points, a positive duration and valid elapsed seconds")}function Ih(e,t){return e&&"object"==typeof e&&"__phase"in e&&e.__phase!==t?{...e,__phase:t}:e}function Th(e){return e&&"object"==typeof e&&"late"in e&&e.late?"late":"board"}function Lh(e){let t=0;for(let i=1;i<e.length;i++)t+=Math.hypot(e[i].x-e[i-1].x,e[i].y-e[i-1].y);return t}function Ch(e,t){let i=e.travel;if(!i)return!1;let r=Math.min(i.durationSeconds,(i.elapsedSeconds??0)+t);i.elapsedSeconds=r;let n=Lh(i.points)*r/i.durationSeconds,o=i.points[i.points.length-1];for(let e=1;e<i.points.length;e++){let t=i.points[e-1],r=i.points[e],a=Math.hypot(r.x-t.x,r.y-t.y);if(a>0&&n<a){o={x:t.x+(r.x-t.x)*n/a,y:t.y+(r.y-t.y)*n/a};break}n-=a}if(e.x=o.x,e.y=o.y,e.vx=e.vy=0,r<i.durationSeconds-1e-9)return!1;let a=i.points[i.points.length-1];return e.x=e.prevX=a.x,e.y=e.prevY=a.y,delete e.travel,e.datum=Ih(e.datum,Th(e.datum)),!0}function Rh(e,t){if(!Number.isFinite(e))throw new RangeError(`${t} must be finite`)}function Nh(e,t){if(Rh(e,t),e<=0)throw new RangeError(`${t} must be positive`)}function Dh(e,t){if(!Array.isArray(e))throw new RangeError(`${t} must be an array`)}function Fh(e,t){Dh(e,t);for(let i of e)if("string"!=typeof i)throw new RangeError(`${t} must contain strings`)}function Eh(e){if(!e||!e.shape||"circle"!==e.shape.type&&"aabb"!==e.shape.type)throw new RangeError("Physics bodies require a circle or aabb shape");let t=`Physics body ${e.id}`;Rh(e.x,`${t}.x`),Rh(e.y,`${t}.y`);for(let i of["vx","vy","angle","restitution","friction"])null!=e[i]&&Rh(e[i],`${t}.${i}`);if(null!=e.mass&&Nh(e.mass,`${t}.mass`),e.travel&&(Ph(e.travel),e.fixedPosition))throw new RangeError("Physics travel cannot use fixedPosition");"circle"===e.shape.type?Nh(e.shape.radius,`${t}.radius`):(Nh(e.shape.width,`${t}.width`),Nh(e.shape.height,`${t}.height`))}function Oh(e){for(let t of["restLength","stiffness","damping"])null!=e[t]&&Rh(e[t],`Physics spring.${t}`);"point"===e.target.type&&(Rh(e.target.x,"Physics spring.target.x"),Rh(e.target.y,"Physics spring.target.y"))}function zh(e){Eh(e),null!=e.spawnAt&&Rh(e.spawnAt,`Physics body ${e.id}.spawnAt`);for(let t of e.springs??[])Oh({...t,bodyId:e.id})}function Bh(e){for(let t of e){if(!t?.shape||"segment"!==t.shape.type&&"aabb"!==t.shape.type)throw new RangeError("Physics colliders require a segment or aabb shape");let e=t.shape;if("segment"===e.type)for(let i of["x1","y1","x2","y2"])Rh(e[i],`Physics collider ${t.id}.${i}`);else for(let i of["x","y","width","height"])Rh(e[i],`Physics collider ${t.id}.${i}`);for(let[e,i]of Object.entries(t.shape))"type"!==e&&null!=i&&Rh(i,`Physics collider ${t.id}.${e}`);for(let e of["restitution","friction"])null!=t[e]&&Rh(t[e],`Physics collider ${t.id}.${e}`)}}function jh(e){for(let[t,i]of Object.entries(e))"gravity"!==t&&null!=i&&Rh(i,`Physics option ${t}`);e.gravity&&(Rh(e.gravity.x,"Physics gravity.x"),Rh(e.gravity.y,"Physics gravity.y"));for(let t of["fixedDt","cellSize"])null!=e[t]&&Nh(e[t],`Physics option ${t}`);if(null!=e.velocityDamping&&e.velocityDamping<0)throw new RangeError("Physics velocityDamping must be nonnegative")}function Wh(e){Fh(e.activeSensors,"Physics activeSensors"),Dh(e.bodies,"Physics bodies"),Dh(e.colliders,"Physics colliders"),Dh(e.springs,"Physics springs"),jh(e.options);for(let t of e.bodies){Eh(t);for(let e of["prevX","prevY","sleepTime","index"])Rh(t[e],`Physics body ${t.id}.${e}`)}Bh(e.colliders);for(let t of e.springs)Oh(t);null!=e.randomState&&Rh(e.randomState,"Physics randomState")}function Yh(e){e.kernel&&jh(e.kernel),e.viewTransform&&(Rh(e.viewTransform.x,"Physics viewTransform.x"),Rh(e.viewTransform.y,"Physics viewTransform.y")),e.colliders&&Bh(e.colliders),null!=e.fixedDt&&Nh(e.fixedDt,"Physics fixedDt");for(let t of["maxDeltaSeconds","maxSubsteps","settleStepLimit","timeScale"])if(null!=e[t]&&(Rh(e[t],`Physics ${t}`),e[t]<0))throw new RangeError(`Physics ${t} must be nonnegative`)}function qh(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(i in e!=i in t||!Object.is(e[i],t[i]))return!1;return!0}function Xh(e,t){return e===t||!(!e||!t||e.length!==t.length)&&e.every((e,i)=>{let r=t[i],n=e.shape,o=r.shape,a="segment"===n.type&&"segment"===o.type?n.x1===o.x1&&n.y1===o.y1&&n.x2===o.x2&&n.y2===o.y2&&(n.thickness??0)===(o.thickness??0):"aabb"===n.type&&"aabb"===o.type&&n.x===o.x&&n.y===o.y&&n.width===o.width&&n.height===o.height;return e.id===r.id&&e.sensor===r.sensor&&e.friction===r.friction&&e.restitution===r.restitution&&function(e,t){return e===t||!(!e||!t||"function"==typeof e||"function"==typeof t)&&e.property===t.property&&"equals"in e=="equals"in t&&"notEquals"in e=="notEquals"in t&&Object.is(e.equals,t.equals)&&Object.is(e.notEquals,t.notEquals)&&qh(e.oneOf,t.oneOf)&&qh(e.notOneOf,t.notOneOf)}(e.bodyFilter,r.bodyFilter)&&a})}function Gh(e,t){return!!t?.some(t=>Object.is(e,t))}function Vh(e){let t=e.fixedPosition;Number.isFinite(t?.x)&&(e.x=e.prevX=t.x,e.vx=0),Number.isFinite(t?.y)&&(e.y=e.prevY=t.y,e.vy=0)}function Hh(e){if(!e)return;let t=Number.isFinite(e.x)?e.x:void 0,i=Number.isFinite(e.y)?e.y:void 0;return null==t&&null==i?void 0:{x:t,y:i}}function Uh(e,t,i){let r,n="x"===i?"y":"x",o=Math.abs(t[i]-e[i]),a=t[n]-e[n],s=(e,t)=>"circle"===e.shape.type?e.shape.radius:("x"===t?e.shape.width:e.shape.height)/2;if("circle"===e.shape.type&&"circle"===t.shape.type){let i=e.shape.radius+t.shape.radius;r=Math.sqrt(Math.max(0,i*i-o*o))}else if("aabb"===e.shape.type&&"aabb"===t.shape.type)r=s(e,n)+s(t,n);else{let a="circle"===e.shape.type?e:t,l="aabb"===e.shape.type?e:t,c=s(a,i),u=Math.max(0,o-s(l,i));r=s(l,n)+Math.sqrt(Math.max(0,c*c-u*u))}let l=a<0?-1:1;return{nx:"x"===n?l:0,ny:"y"===n?l:0,penetration:Math.max(0,r-Math.abs(a))}}function Zh(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function Kh(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function Qh(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,...e.travel?{travel:_h(e.travel)}:{},...e.fixedPosition?{fixedPosition:Hh(e.fixedPosition)}:{},shape:Zh(e.shape),sleeping:e.sleeping,datum:e.datum}}function Jh(e){return{...Qh(e),index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function ep(e){return e&&"function"!=typeof e?{property:e.property,..."equals"in e?{equals:e.equals}:{},..."notEquals"in e?{notEquals:e.notEquals}:{},oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function tp(e){return{id:e.id,shape:Kh(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:ep(e.bodyFilter),index:e.index}}function ip(e,t,i){let r=i.length>2,n=1/0,o=i[0][0],a=i[0][1],s=1,l=0;for(let c=0;c<i.length;c++){let[u,d]=i[c],[h,p]=i[(c+1)%i.length],f=h-u,g=p-d,m=Math.hypot(f,g);if(m<=1e-9)continue;let y=g/m,x=-f/m;(e-u)*y+(t-d)*x>0&&(r=!1);let b=Math.max(0,Math.min(1,((e-u)*f+(t-d)*g)/(m*m))),v=u+b*f,w=d+b*g,k=(e-v)**2+(t-w)**2;k<n&&(n=k,o=v,a=w,s=y,l=x)}let c=Math.hypot(e-o,t-a);return!r&&c>1e-9&&(s=(e-o)/c,l=(t-a)/c),{distance:r?-c:c,nx:s,ny:l}}function rp(e,t,i,r){let n=e.x-e.prevX,o=e.y-e.prevY,a=n*n+o*o;if(a<=1e-18||0===i&&!function(e,t){let i=0,r=1,n=e.x-e.prevX,o=e.y-e.prevY;for(let a=0;a<t.length;a++){let[s,l]=t[a],[c,u]=t[(a+1)%t.length],d=u-l,h=s-c;if(Math.hypot(d,h)<=1e-9)continue;let p=(e.prevX-s)*d+(e.prevY-l)*h,f=n*d+o*h;if(f<0)i=Math.max(i,-p/f);else if(f>0)r=Math.min(r,-p/f);else if(p>=0)return!1;if(i>=r)return!1}return i<r}(e,t)||ip(e.prevX,e.prevY,t).distance<i-r)return null;let s=1/0,l=null,c=(t,r,a,c,u)=>{if(t<0||t>1||t>s||t===s&&l&&Math.abs(r)<=Math.abs(l.nx)||n*r+o*a>=0)return;let d=i-((e.x-c)*r+(e.y-u)*a);d<=0||(s=t,l={nx:0===r?0:r,ny:0===a?0:a,penetration:d})};for(let s=0;s<t.length;s++){let[l,u]=t[s],[d,h]=t[(s+1)%t.length],p=d-l,f=h-u,g=Math.hypot(p,f);if(g>1e-9){let t=f/g,a=-p/g,s=n*t+o*a,d=(e.prevX-l)*t+(e.prevY-u)*a-i;if(s<0&&d>=-r){let i=Math.max(0,-d/s),r=((e.prevX+i*n-l)*p+(e.prevY+i*o-u)*f)/g;r>=0&&r<=g&&c(i,t,a,l,u)}}if(i<=0)continue;let m=e.prevX-l,y=e.prevY-u,x=m*n+y*o,b=x*x-a*(m*m+y*y-i*i);if(x>=0||b<0)continue;let v=Math.max(0,(-x-Math.sqrt(b))/a),w=m+v*n,k=y+v*o,S=Math.hypot(w,k);S>1e-9&&c(v,w/S,k/S,l,u)}return l}function np(e,t,i){if("aabb"!==t.type||e.x===e.prevX&&e.y===e.prevY)return null;let r="circle"===e.shape.type?e.shape.radius:0,n=(t.width+("aabb"===e.shape.type?e.shape.width:0))/2,o=(t.height+("aabb"===e.shape.type?e.shape.height:0))/2,a=t.x-n,s=t.x+n,l=t.y-o,c=t.y+o;return Math.max(e.x,e.prevX)+r<a||Math.min(e.x,e.prevX)-r>s||Math.max(e.y,e.prevY)+r<l||Math.min(e.y,e.prevY)-r>c?null:rp(e,[[a,l],[s,l],[s,c],[a,c]],r,i)}function op(e,t,i=0,r=!1){let n=function(e,t){let{x1:i,y1:r,x2:n,y2:o}=t;if("circle"===e.shape.type)return[[i,r],[n,o]];(i>n||i===n&&r>o)&&(i=t.x2,r=t.y2,n=t.x1,o=t.y1);let a=e.shape.width/2,s=e.shape.height/2*(o>=r?1:-1),l=[[i-a,r-s],[i+a,r-s],[n+a,o-s],[n+a,o+s],[n-a,o+s],[i-a,r+s]];return s<0?l.reverse():l}(e,t),o=(t.thickness??0)/2+("circle"===e.shape.type?e.shape.radius:0);if(r){let t=rp(e,n,o,i);if(t)return t}let a=ip(e.x,e.y,n),s=o-a.distance;return s>0?{nx:a.nx,ny:a.ny,penetration:s}:null}function ap(e,t){return Math.abs(e.x-t.x)<=t.padding&&Math.abs(e.y-t.y)<=t.padding}function sp(e,t){let i=lp(e),r=[];for(let e=0;e<t.length;e++)dp(i,t[e].bounds)&&r.push(e);return{bounds:i,indexes:r}}function lp(e,t=!0){let i="circle"===e.shape.type?e.shape.radius:e.shape.width/2,r="circle"===e.shape.type?e.shape.radius:e.shape.height/2,n=t?Math.max(.005,Math.min(i,r)):0;return{x:e.x,y:e.y,padding:n,minX:Math.min(e.x,e.prevX)-i-n,minY:Math.min(e.y,e.prevY)-r-n,maxX:Math.max(e.x,e.prevX)+i+n,maxY:Math.max(e.y,e.prevY)+r+n}}function cp(e){let t="circle"===e.shape.type?e.shape.radius:e.shape.width/2,i="circle"===e.shape.type?e.shape.radius:e.shape.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}function up(e){let t=e.shape;if("aabb"===t.type)return cp({x:t.x,y:t.y,shape:t});let i=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-i,minY:Math.min(t.y1,t.y2)-i,maxX:Math.max(t.x1,t.x2)+i,maxY:Math.max(t.y1,t.y2)+i}}function dp(e,t){return e.minX<=t.maxX&&e.maxX>=t.minX&&e.minY<=t.maxY&&e.maxY>=t.minY}function hp(e,t,i={x:0,y:0}){let r=1,n=e.map(e=>{let t=lp(e,!(e.sleeping&&e.x===e.prevX&&e.y===e.prevY));return!1!==e.bodyCollisions&&(r=Math.max(r,t.maxX-t.minX,t.maxY-t.minY)),t}),o=Math.max(1,Math.min(t,r)),a=new Map;for(let t=0;t<e.length;t+=1){if(!1===e[t].bodyCollisions)continue;let i=n[t];i.cellX=Math.floor(i.minX/o),i.cellY=Math.floor(i.minY/o);for(let e=i.cellX;e<=Math.floor(i.maxX/o);e+=1){let r=a.get(e);r||a.set(e,r=new Map);for(let e=i.cellY;e<=Math.floor(i.maxY/o);e+=1){let i=r.get(e);i?i.push(t):r.set(e,[t])}}}let s=[];for(let[e,t]of a)for(let[i,r]of t)for(let t=0;t<r.length;t+=1)for(let o=t+1;o<r.length;o+=1){let a=r[t],l=r[o],c=n[a],u=n[l];e!==Math.max(c.cellX,u.cellX)||i!==Math.max(c.cellY,u.cellY)||dp(c,u)&&s.push([a,l])}let l=e.map(e=>e.x*i.x+e.y*i.y);return s.sort(([e,t],[i,r])=>Math.max(l[i],l[r])-Math.max(l[e],l[t])||(e===i?t-r:e-i)),{pairs:s,coversPositions:()=>e.every((e,t)=>!1===e.bodyCollisions||ap(e,n[t]))}}function pp(e,t){if("circle"!==e.shape.type||"circle"!==t.shape.type)return null;let i=e.shape.radius+t.shape.radius;if(i<=0)return null;let r=t.prevX-e.prevX,n=t.prevY-e.prevY,o=t.x-e.x-r,a=t.y-e.y-n,s=o*o+a*a,l=2*(r*o+n*a),c=r*r+n*n-i*i;if(c<-1e-5||s<=1e-12||l>=0)return null;let u=l*l-4*s*c;if(u<0)return null;let d=(-l-Math.sqrt(u))/(2*s);if(d<0||d>1)return null;let h=(r+d*o)/i,p=(n+d*a)/i,f=i-((t.x-e.x)*h+(t.y-e.y)*p);return f>0?{nx:h,ny:p,penetration:f}:null}var fp={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},gp=1e-9,mp=.005;function yp(e,t,i){return Math.max(t,Math.min(i,e))}function xp(e,t,i){return Math.min(e??i,t??i)}function bp(e,t,i){return yp(Math.max(e??i,t??i),0,1)}function vp(e){return e<0?-1:1}function wp(e){return e.sleeping&&e.x===e.prevX&&e.y===e.prevY}function kp(e,t,i,r,n,o,a,s){let l=n-e,c=(i+a)/2-Math.abs(l);if(c<=0)return null;let u=o-t,d=(r+s)/2-Math.abs(u);return d<=0?null:c<d?{nx:vp(l),ny:0,penetration:c}:{nx:0,ny:vp(u),penetration:d}}function Sp(e,t,i,r,n,o,a){let s=o/2,l=a/2,c=e-yp(e,r-s,r+s),u=t-yp(t,n-l,n+l),d=c*c+u*u;if(d>i*i)return null;if(d<=gp){let o=Math.abs(e-(r-s)),a=Math.abs(e-(r+s)),c=Math.abs(t-(n-l)),u=Math.abs(t-(n+l)),d=Math.min(o,a,c,u);return d===o?{nx:-1,ny:0,penetration:i+o}:d===a?{nx:1,ny:0,penetration:i+a}:d===c?{nx:0,ny:-1,penetration:i+c}:{nx:0,ny:1,penetration:i+u}}let h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:i-h}}function Ap(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,i,r,n,o){let a=r-e,s=n-t,l=i+o,c=a*a+s*s;if(c>=l*l)return null;if(c<=gp)return{nx:1,ny:0,penetration:l};let u=Math.sqrt(c);return{nx:a/u,ny:s/u,penetration:l-u}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return kp(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);let i="circle"===e.shape.type?e:t,r=i===e?t:e;if("circle"!==i.shape.type||"aabb"!==r.shape.type)return null;let n=Sp(i.x,i.y,i.shape.radius,r.x,r.y,r.shape.width,r.shape.height);return n&&i===e&&(n.nx=-n.nx,n.ny=-n.ny),n}function Mp(e,t){let i=t.shape;return"aabb"===i.type?"circle"===e.shape.type?Sp(e.x,e.y,e.shape.radius,i.x,i.y,i.width,i.height):kp(i.x,i.y,i.width,i.height,e.x,e.y,e.shape.width,e.shape.height):op(e,i)}function $p(e,t){return`${e}\0${t}`}function _p(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Pp(e,t){return function(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let i=function(e,t){if(!t)return;let i=e;for(let e of t.split(".")){if(null==i||"object"!=typeof i||!Object.prototype.hasOwnProperty.call(i,e))return;i=i[e]}return i}(e,t.property);return!("equals"in t&&!Object.is(i,t.equals)||"notEquals"in t&&Object.is(i,t.notEquals)||t.oneOf&&!Gh(i,t.oneOf)||t.notOneOf&&Gh(i,t.notOneOf))}(t,e.bodyFilter)}var Ip=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.supportDependents=new Map,this.supportContactsThisStep=new Set,this.reboundingThisStep=new Set,this.interpenetratingThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,jh(e),this.options={...fp,...e},this.random=Z(this.options.seed)}init(e={}){jh(e),this.options={...fp,...e},this.random=Z(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){Eh(e);let t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(gp,e.mass??1),bodyCollisions:e.bodyCollisions??!0,...e.fixedPosition?{fixedPosition:Hh(e.fixedPosition)}:{},...e.travel?{travel:_h(e.travel)}:{},shape:Zh(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};t.travel&&Ch(t,0),Vh(t),this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(let t of e){this.bodies.delete(t);for(let e of Array.from(this.activeSensors))_p(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){if(Bh(e),!Xh(e,this.sortedColliders())){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(let t of e)this.colliders.set(t.id,{...t,shape:Kh(t.shape),bodyFilter:ep(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}}setConstraint(e){Oh(e);let t=e.id??`spring-${this.nextSpringIndex}`;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,i){if(!Number.isFinite(t)||!Number.isFinite(i))throw new RangeError("Physics impulses must be finite");let r=this.bodies.get(e);r&&(r.vx+=t/r.mass,r.vy+=i/r.mass,Vh(r),this.wake(r))}step(e=this.options.fixedDt){let t=Number.isFinite(e)?Math.max(0,e):0;if(this.lastEvents=[],0===t)return;this.reboundingThisStep.clear();let i=this.sortedBodies(),r=i.some(e=>e.travel)?i.filter(e=>!e.travel):i;for(let e of i)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);let n=this.options.maxVelocity,o=this.options.velocityDamping**(120*t);for(let e of r)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=o,e.vy*=o,Vh(e),n>0){let t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>n){let i=n/t;e.vx*=i,e.vy*=i}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear(),this.supportDependents.clear(),this.supportContactsThisStep.clear(),this.interpenetratingThisStep.clear();let a=this.sortedColliders().filter(e=>!e.sensor).map(e=>({collider:e,bounds:up(e)})),s=a.some(({collider:e})=>e.bodyFilter)?void 0:new Array(r.length),l=new Set,c=new Set;this.resolveColliders(r,a,l,s);let u=s&&r.map(wp),d=hp(r,this.options.cellSize,this.options.gravity);for(let e=0;e<this.options.collisionIterations;e+=1){e>0&&!d.coversPositions()&&(d=hp(r,this.options.cellSize,this.options.gravity));let t=this.resolveBodyPairs(r,d.pairs,c,0===e,u),i=this.resolveColliders(r,a,l,s);if(s&&!t&&!i)break}d.coversPositions()||(d=hp(r,this.options.cellSize,this.options.gravity));for(let[e,t]of d.pairs){let i=Ap(r[e],r[t]);i&&i.penetration>.02&&(this.interpenetratingThisStep.add(r[e].id),this.interpenetratingThisStep.add(r[t].id))}let h=Array.from(this.supportedThisStep);for(let e=0;e<h.length;e+=1)for(let t of this.supportDependents.get(h[e])??[])this.supportedThisStep.has(t)||(this.supportedThisStep.add(t),h.push(t));this.reconcileSupportedVelocity(r,t),this.updateSensors(r),this.updateSleeping(r,t);for(let e of i)Ch(e,t)&&this.lastEvents.push({type:"travel-end",bodyId:e.id})}settle(e=1200,t=this.options.fixedDt){let i=0;for(;i<e&&!this.allSleeping();)this.step(t),i+=1;return i}readState(e=[]){e.length=0;for(let t of this.sortedBodies())e.push(Qh(t));return e}readBody(e){let t=this.bodies.get(e);return t?Qh(t):void 0}workerSleepTimes(e){return Float32Array.from(e,e=>this.bodies.get(e)?.sleepTime??0)}applyWorkerMotion(e){e.ids.forEach((t,i)=>{let r=this.bodies.get(t);r&&(r.prevX=e.previousPositions?.[2*i]??r.x,r.prevY=e.previousPositions?.[2*i+1]??r.y,r.x=e.positions[2*i],r.y=e.positions[2*i+1],r.vx=e.velocities[2*i],r.vy=e.velocities[2*i+1],r.sleeping=1===e.sleeping[i],r.sleepTime=e.sleepTimes?.[i]??(r.sleeping?this.options.sleepAfter:0),r.travel&&e.travelElapsed&&(r.travel.elapsedSeconds=e.travelElapsed[i]),r.datum=Ih(r.datum,r.travel?"travel":r.sleeping?"settled":Th(r.datum)))}),this.lastEvents=e.result.events,e.state&&(this.activeSensors=new Set(e.state.activeSensorPairs))}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(_p)}allSleeping(){for(let e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{randomState:this.random.getState(),options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Jh),colliders:this.sortedColliders().map(tp),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){Wh(e),this.options={...e.options,gravity:{...e.options.gravity}},this.random=Z(e.randomState??this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(let t of e.bodies){let e=Jh(t);Vh(e),this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(let t of e.colliders){let e=tp(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(let t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});let e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(let t of Array.from(this.springs.values()).sort((e,t)=>e.id<t.id?-1:e.id>t.id?1:0)){let i=this.bodies.get(t.bodyId);if(!i||i.sleeping||i.travel)continue;let r="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!r)continue;let n=r.x-i.x,o=r.y-i.y,a=n*n+o*o,s=Math.sqrt(a);if(s<=gp)continue;let l=n/s,c=o/s,u="vx"in r?r.vx:0,d="vy"in r?r.vy:0,h=(u-i.vx)*l+(d-i.vy)*c,p=(s-t.restLength)*t.stiffness+h*t.damping;i.vx+=p*l*e/i.mass,i.vy+=p*c*e/i.mass}}resolveBodyPairs(e,t,i,r,n){let o=!1;for(let[a,s]of t){let t=e[a],l=e[s];if(!t||!l)continue;if(!r&&n?.[a]&&n[s]&&wp(t)&&wp(l)){o=!0;continue}let c=pp(t,l)??Ap(t,l);if(!c)continue;o=!0,this.resolveDynamicCollision(t,l,c);let u=a*e.length+s;i.has(u)||(i.add(u),this.lastEvents.push({type:"contact",bodyId:t.id,otherId:l.id,sensor:!1}))}return o}resolveDynamicCollision(e,t,i){(e.fixedPosition||t.fixedPosition)&&(!e.sleeping&&null==e.fixedPosition?.x||!t.sleeping&&null==t.fixedPosition?.x?(e.sleeping||null!=e.fixedPosition?.y)&&(t.sleeping||null!=t.fixedPosition?.y)&&(i=Uh(e,t,"y")):i=Uh(e,t,"x"));let r=this.options.gravity,n=Math.hypot(r.x,r.y),o=this.contactOpposesGravity(i.nx,i.ny,n),a=this.contactOpposesGravity(-i.nx,-i.ny,n);o&&(e.sleeping&&this.supportedThisStep.add(t.id),this.addSupportContact(e.id,t.id)),a&&(t.sleeping&&this.supportedThisStep.add(e.id),this.addSupportContact(t.id,e.id));let s=e.sleeping?0:1/e.mass,l=t.sleeping?0:1/t.mass,c=null==e.fixedPosition?.x?s:0,u=null==e.fixedPosition?.y?s:0,d=null==t.fixedPosition?.x?l:0,h=null==t.fixedPosition?.y?l:0,p=e.fixedPosition||t.fixedPosition?i.nx**2*(c+d)+i.ny**2*(u+h):s+l;if(p<=gp)return;let f=this.supportedThisStep.has(e.id)&&o&&!t.sleeping&&!t.fixedPosition,g=this.supportedThisStep.has(t.id)&&a&&!e.sleeping&&!e.fixedPosition,m=n>1,y=m&&f?0:c,x=m&&f?0:u,b=m&&!f&&g?0:d,v=m&&!f&&g?0:h,w=i.nx**2*(y+b)+i.ny**2*(x+v),k=Math.max(0,i.penetration-mp)/Math.max(gp,w);e.x-=i.nx*k*y,e.y-=i.ny*k*x,t.x+=i.nx*k*b,t.y+=i.ny*k*v,m&&f&&this.supportedThisStep.add(t.id),m&&g&&this.supportedThisStep.add(e.id);let S=t.vx-e.vx,A=t.vy-e.vy,M=S*i.nx+A*i.ny;if(M>0)return;let $=Math.abs(M),_=xp(e.restitution,t.restitution,this.options.restitution),P=e.vx*r.x+e.vy*r.y,I=t.vx*r.x+t.vy*r.y,T=-(1+_)*M/p,L=T*i.nx,C=T*i.ny;e.vx-=L*c,e.vy-=C*u,t.vx+=L*d,t.vy+=C*h,this.applyFriction(e,t,i,T,c,u,d,h),_>0&&(P>=0&&e.vx*r.x+e.vy*r.y<0&&this.reboundingThisStep.add(e.id),I>=0&&t.vx*r.x+t.vy*r.y<0&&this.reboundingThisStep.add(t.id)),$>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,i,r,n,o,a,s){let l=-i.ny,c=i.nx,u=(t.vx-e.vx)*l+(t.vy-e.vy)*c,d=e.fixedPosition||t.fixedPosition?l**2*(n+a)+c**2*(o+s):n+a;if(Math.abs(u)<=gp||d<=gp)return;let h=bp(e.friction,t.friction,this.options.friction),p=yp(-u/d,-r*h,r*h),f=p*l,g=p*c;e.vx-=f*n,e.vy-=g*o,t.vx+=f*a,t.vy+=g*s}resolveColliders(e,t,i,r){if(0===t.length)return!1;let n=!1;for(let o=0;o<e.length;o++){let a=e[o],s=r?.[o];r&&(!s||!ap(a,s.bounds))&&(r[o]=s=sp(a,t));let l=0;for(;l<(s?s.indexes.length:t.length);){let e=s?s.indexes[l++]:l++,{collider:c,bounds:u}=t[e];if(!Pp(c,a))continue;let d="segment"===c.shape.type?op(a,c.shape,mp+gp,!0):np(a,c.shape,mp+gp)??(dp(cp(a),u)?Mp(a,c):null);if(!d)continue;n=!0,this.resolveStaticCollision(a,c,d),this.contactOpposesGravity(d.nx,d.ny)&&this.supportedThisStep.add(a.id);let h=o*t.length+e;if(i.has(h)||(i.add(h),this.lastEvents.push({type:"contact",bodyId:a.id,otherId:c.id,sensor:!1})),s&&r&&!ap(a,s.bounds))for(r[o]=s=sp(a,t),l=0;l<s.indexes.length&&s.indexes[l]<=e;)l++}}return n}resolveStaticCollision(e,t,i){e.x+=i.nx*Math.max(0,i.penetration-mp),e.y+=i.ny*Math.max(0,i.penetration-mp);let r=e.vx*i.nx+e.vy*i.ny;if(r<0){let n=xp(e.restitution,t.restitution,this.options.restitution),o=this.options.gravity,a=e.vx*o.x+e.vy*o.y;e.vx-=(1+n)*r*i.nx,e.vy-=(1+n)*r*i.ny;let s=-i.ny,l=i.nx,c=e.vx*s+e.vy*l,u=bp(e.friction,t.friction,this.options.friction)*-(1+n)*r,d=yp(c,-u,u);e.vx-=d*s,e.vy-=d*l,n>0&&a>=0&&e.vx*o.x+e.vy*o.y<0&&this.reboundingThisStep.add(e.id)}Vh(e)}updateSensors(e){let t=this.sortedColliders().filter(e=>e.sensor);if(0===t.length&&0===this.activeSensors.size)return;let i=new Set;for(let r of e){let e=cp(r);for(let n of t){if(!Pp(n,r)||!dp(e,up(n))||!Mp(r,n))continue;let t=$p(n.id,r.id);i.add(t),this.activeSensors.has(t)||this.lastEvents.push({type:"sensor-enter",bodyId:r.id,sensorId:n.id})}}for(let e of Array.from(this.activeSensors).sort()){if(i.has(e))continue;let{sensorId:t,bodyId:r}=_p(e);this.lastEvents.push({type:"sensor-exit",bodyId:r,sensorId:t})}this.activeSensors=i}updateSleeping(e,t){let i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(let r of e){let e=Math.sqrt(r.vx*r.vx+r.vy*r.vy),n=Math.sqrt((r.x-r.prevX)*(r.x-r.prevX)+(r.y-r.prevY)*(r.y-r.prevY));e<this.options.sleepSpeed&&n<this.options.sleepSpeed*t&&!this.interpenetratingThisStep.has(r.id)&&(!i||this.supportedThisStep.has(r.id))?(r.sleepTime+=t,!r.sleeping&&r.sleepTime>=this.options.sleepAfter&&(r.sleeping=!0,r.vx=0,r.vy=0,r.datum=Ih(r.datum,"settled"),this.lastEvents.push({type:"sleep",bodyId:r.id}))):r.sleeping?this.wake(r):r.sleepTime=0}}addSupportContact(e,t){let i=this.supportDependents.get(e);i?.has(t)||(this.supportContactsThisStep.add(e),this.supportContactsThisStep.add(t),i||(i=new Set,this.supportDependents.set(e,i)),i.add(t))}reconcileSupportedVelocity(e,t){let i=this.options.gravity;if(!(Math.hypot(i.x,i.y)<=1))for(let r of e)r.sleeping||!this.supportedThisStep.has(r.id)||!this.supportContactsThisStep.has(r.id)||this.reboundingThisStep.has(r.id)&&r.vx*i.x+r.vy*i.y<0||(r.vx=(r.x-r.prevX)/t,r.vy=(r.y-r.prevY)/t,Vh(r))}contactOpposesGravity(e,t,i){let{x:r,y:n}=this.options.gravity;return i??(i=Math.hypot(r,n)),i<=1e-9||(e*r+t*n)/i<-.2}wake(e){e.travel||(e.datum=Ih(e.datum,Th(e.datum))),e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Tp=class{constructor(e={}){this.id="builtin",this.world=new Ip(e),this.capabilities={...this.world.capabilities,engine:"builtin"}}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}readBody(e){return this.world.readBody(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}workerSleepTimes(e){return this.world.workerSleepTimes(e)}applyWorkerMotion(e){this.world.applyWorkerMotion(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Lp(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):function(e={}){return new Tp(e)}(t)}var Cp=["binId","targetBin","category","windowIndex","lane","group"];function Rp(){return{count:0,total:0,mean:0,m2:0,min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}}function Np(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);let i=t-e.mean;e.mean+=i/e.count;let r=t-e.mean;e.m2+=i*r}function Dp(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Fp(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:Number.POSITIVE_INFINITY,max:e.count>0?e.max:Number.NEGATIVE_INFINITY}}function Ep(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function Op(e,t,i){return"function"==typeof e?e(t,i):"string"==typeof e?Ep(t,e):void 0}function zp(e){if(null==e)return;let t=String(e);return t.trim()?t:void 0}function Bp(e){let t=Dp(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:Dp(e.x),y:Dp(e.y),value:t}}var jp=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;let t=this.nextIndex;this.nextIndex+=1;let i=zp(Op(this.config.binAccessor,e,t))??function(e){for(let t of Cp){let i=zp(Ep(e,t));if(i)return i}return"sediment"}(e),r=zp(Op(this.config.labelAccessor,e,t))??i,n=function(e,t,i){if("number"==typeof e)return e;let r="function"==typeof e?e(t,i):"string"==typeof e?Ep(t,e):1,n="number"==typeof r?r:Number(r);return Number.isFinite(n)?n:1}(this.config.valueAccessor,e,t),o=Math.max(0,Math.floor(this.config.retainBodyIds??12)),a=this.bins.get(i);return a||(a={id:i,label:r,bodyIds:[],x:Rp(),y:Rp(),value:Rp()},this.bins.set(i,a)),a.label=r,a.lastBodyId=e.id,a.lastDatum=e.datum,Np(a.x,e.x),Np(a.y,e.y),Np(a.value,n),o>0&&(a.bodyIds.push(e.id),a.bodyIds.length>o&&(a.bodyIds=a.bodyIds.slice(a.bodyIds.length-o))),Bp(a)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Bp)}restore(e=[]){this.bins.clear();for(let t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Fp(t.x),y:Fp(t.y),value:Fp(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){let e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function Wp(e){let t=Number(e);if(Number.isFinite(t)&&!(t<=0))return Math.floor(t)}var Yp={bodyLimit:Number.POSITIVE_INFINITY,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1,viewTransform:{x:0,y:0}};function qp(e,t,i){return{...e,timestamp:e.timestamp??t,chartType:e.chartType??i.chartType,chartId:e.chartId??i.chartId}}var Xp={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Gp(e={},t=Xp){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function Vp(e){return{...e,shape:{...e.shape},...e.travel?{travel:_h(e.travel)}:{},...e.fixedPosition?{fixedPosition:{...e.fixedPosition}}:{},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Hp(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:void 0}let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Up(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function Zp(e){return{...Vp(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Kp(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function Qp(e){return!1!==e&&{...e}}function Jp(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function ef(e){return{...e,gravity:{...e.gravity}}}function tf(e,t,i,r){if("circle"===e.shape.type){let n=e.x-t,o=e.y-i,a=e.shape.radius+r,s=n*n+o*o;return s<=a*a?s:null}let n=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),o=Math.max(Math.abs(i-e.y)-e.shape.height/2,0),a=n*n+o*o;return a<=r*r?a:null}function rf(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function nf(e,t={}){let{idPrefix:i="plot",includeFloor:r=!0,includeCeiling:n=!1,includeLeftWall:o=!0,includeRightWall:a=!0,wallThickness:s=20,floorThickness:l=s}=t,c=[],u=e.x+e.width/2,d=e.y+e.height/2,h=(e,t,r,n,o)=>{c.push({id:`${i}-${e}`,shape:{type:"aabb",x:t,y:r,width:n,height:o}})};return r&&h("floor",u,e.y+e.height+l/2,e.width+2*s,l),n&&h("ceiling",u,e.y-l/2,e.width+2*s,l),o&&h("left-wall",e.x-s/2,d,s,e.height+2*l),a&&h("right-wall",e.x+e.width+s/2,d,s,e.height+2*l),c}function of(e){let{idPrefix:t="bin",count:i,domainStart:r,domainStep:n,xScale:o,yTop:a,yBottom:s,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=a,lidThickness:p=Math.max(2,l)}=e,f=[],g=a+(s-a)/2,m=Math.abs(s-a),y=c?i:i-1;if(u||c)for(let e=c?0:1;e<=y;e+=1){if(!u&&e>0&&e<i)continue;let a=o(r+e*n);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:a,y:g,width:l,height:m}})}if(null!=d)for(let e=0;e<i;e+=1){let i=r+e*n,a=i+n;if(a>=d)continue;let s=o(i),c=o(a);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(s,c)+l/2,y1:h,x2:Math.max(s,c)-l/2,y2:h,thickness:p}})}return f}import{quadtree as af}from"d3-quadtree";var sf=class{constructor(){this.order=new Map,this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,i,r,n,o=0,a){let s=this.ensure(e,t,i);if(!s)return null;let l=null,c=Number.POSITIVE_INFINITY,u=Math.max(0,a?.searchRadius??Math.max(0,o)+this.maxSearchRadius),d=r-u,h=r+u,p=n-u,f=n+u;return s.visit((e,t,i,s,u)=>{if(s<d||t>h||u<p||i>f)return!0;if(e.length)return!1;let g=e;for(;g;){let e=g.data;if(e&&(!a?.include||a.include(e))){let t=a?.distanceSquared?a.distanceSquared(e,r,n):tf(e,r,n,Math.max(0,o));null!=t&&(t<c||t===c&&(this.order.get(e.id)??-1)>(this.order.get(l?.id??"")??-1))&&(l=e,c=t)}g=g.next}return!1}),l}ensure(e,t,i){if(this.tree&&this.revision===t)return this.tree;this.order=new Map(Array.from(i,(e,t)=>[e,t]));let r=e.readState();return 0===r.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=r.reduce((e,t)=>{return Math.max(e,"circle"===(i=t).shape.type?i.shape.radius:Math.hypot(i.shape.width,i.shape.height)/2);var i},0),this.tree=af().x(e=>e.x).y(e=>e.y).addAll(r),this.revision=t,this.tree)}};function lf(e){return{...e,...e.viewTransform&&{viewTransform:{...e.viewTransform}},...e.colliders&&{colliders:Kp(e.colliders)},...e.kernel&&{kernel:{...e.kernel,...e.kernel.gravity&&{gravity:{...e.kernel.gravity}}}}}}var cf=["data","scene-geometry","data-paint","accessibility","evidence"],uf=["scene-geometry","data-paint","accessibility","evidence"],df=["overlay","accessibility","evidence"],hf=(e,t)=>({retainedData:e,invalidations:t}),pf=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ff=["scene-geometry","data-paint","accessibility","evidence"],gf=[],mf={engine:/*#__PURE__*/hf("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:/*#__PURE__*/hf("preserve",ff),colliders:/*#__PURE__*/hf("preserve",ff),sediment:/*#__PURE__*/hf("preserve",ff),bodyBudget:/*#__PURE__*/hf("preserve",pf),bodyLimit:/*#__PURE__*/hf("preserve",pf),eviction:/*#__PURE__*/hf("preserve",pf),fixedDt:/*#__PURE__*/hf("preserve",gf),maxDeltaSeconds:/*#__PURE__*/hf("preserve",gf),maxSubsteps:/*#__PURE__*/hf("preserve",gf),settleStepLimit:/*#__PURE__*/hf("preserve",gf),timeScale:/*#__PURE__*/hf("preserve",gf),observation:/*#__PURE__*/hf("preserve",gf)},yf=/*#__PURE__*/hf("preserve",pf);function xf(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(mf,r)?mf[r]:yf;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var bf=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function vf(e,t){return e===t||!(!e||!t||e.gravity?.x!==t.gravity?.x||e.gravity?.y!==t.gravity?.y)&&bf.every(i=>e[i]===t[i])}function wf(e,t){if(e.readBody){if(!t)return t=>e.readBody(t);let i=new Map;for(let r of t)i.has(r)||i.set(r,e.readBody(r));return e=>i.get(e)}let i=new Map(e.readState().map(e=>[e.id,e]));return e=>i.get(e)}function kf(e,t){for(let i of e)t.has(rf(i).bodyId)&&e.delete(i)}function Sf(e,t,i,r){return e||!t?"paused":i||!r?"running":"settled"}var Af=class{constructor(){this.heap=[]}get length(){return this.heap.length}firstArrival(){return this.heap[0]?.spawnAt}lastArrival(){return this.latest}push(e){this.latest=Math.max(this.latest??-1/0,e.spawnAt);let t=this.heap.length;for(this.heap.push(e);t>0;){let i=t-1>>>1;if(Jp(this.heap[i],e)<=0)break;this.heap[t]=this.heap[i],t=i}this.heap[t]=e}shift(){let e=this.heap[0],t=this.heap.pop();if(0===this.heap.length)return this.latest=void 0,e;if(!t)return e;let i=0;for(;2*i+1<this.heap.length;){let e=2*i+1;if(e+1<this.heap.length&&Jp(this.heap[e+1],this.heap[e])<0&&(e+=1),Jp(t,this.heap[e])<=0)break;this.heap[i]=this.heap[e],i=e}return this.heap[i]=t,e}clear(){this.heap=[],this.latest=void 0}remove(e){let t=new Set,i=this.heap.filter(i=>!e.has(i.id)||(t.add(i.id),!1));return t.size&&this.restore(i),t}sorted(){return this.heap.slice().sort(Jp)}restore(e){this.clear();for(let t of e)this.push(t)}},Mf={};function $f(e){let t=Mf[e];if(!t)throw new Error(`Physics ${e} configuration requires registerPhysicsLivePrograms() from semiotic/physics before a PhysicsPipelineStore is created or restored with it.`);return t}var _f=class e{configure(e,t){!1===e.emitters?this.emitters=void 0:e.emitters&&(this.emitters?this.emitters.update(e.emitters):this.emitters=$f("emitters").create(e.emitters)),!1===e.eventDrop?this.eventDrop=void 0:e.eventDrop&&(this.eventDrop?this.eventDrop.update(e.eventDrop,t):this.eventDrop=$f("eventDrop").create(e.eventDrop),t.setColliders(this.eventDrop.colliders()))}backlog(){return!!this.eventDrop?.backlog()}ownsClock(){return!(!this.eventDrop&&!this.emitters?.pending())}pending(){return this.backlog()||!(!this.emitters?.pending()&&!this.eventDrop?.continuous())}snapshot(){return{...this.emitters&&{emitters:this.emitters.snapshot()},...this.eventDrop&&{eventDrop:this.eventDrop.snapshot()}}}static restore(t){let i=new e;return t.emitters&&(i.emitters=$f("emitters").restore(t.emitters)),t.eventDrop&&(i.eventDrop=$f("eventDrop").restore(t.eventDrop)),i}},Pf=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=function(e){let t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,i){if(i>0)return void(this.seconds=0);if(e.allSleeping())return void(this.seconds+=Math.max(0,t));let r=e.readState(this.scratch),n=this.speed*this.speed,o=!0;for(let e of r){if(e.travel){o=!1;break}if(e.sleeping)continue;let i=e.x-e.prevX,r=e.y-e.prevY;if(e.vx*e.vx+e.vy*e.vy>=n||t>0&&i*i+r*r>=n*t*t){o=!1;break}}this.seconds=o?this.seconds+Math.max(0,t):0}};function If(e,t,i,r={}){let n,o=0,a=0,s=t+(r.drainArrivals?Math.max(0,Math.ceil(((e.lastArrival()??e.elapsed())-e.elapsed())/e.fixedDt)):0);for(;o+a<s&&!r.shouldStop?.()&&(!1===r.stopAtRest||e.queueSize()>0||!e.atRest()||r.continueWhile?.());){let t=e.nextArrival(),l=r.skipIdle&&null!=t&&e.atRest()?Math.min(Math.max(0,Math.floor((t-e.elapsed())/e.fixedDt)-1),Math.max(0,s-o-a-1)):0;l>0&&(e.advanceTime(l*e.fixedDt),a+=l),e.step(e.fixedDt),e.advanceTime(e.fixedDt);let c=e.drainEvents();i.events&&(i.events.push(...c),e.observeKernelEvents(c,i.observations),e.observeSensorTransitions(i.observations));let u=[];if(e.spawnDue(u,i.observations),u.length>0){i.spawned.push(...u),n=e.observeBodyBudget(i.observations);let t=e.evictOverflow(i.observations);i.evicted?.push(...t.evicted),i.sedimented?.push(...t.sedimented)}o+=1,e.refreshQuiescence(e.fixedDt,u.length),r.afterStep?.()}return{steps:o,budget:n}}var Tf=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new sf,this.elapsedSeconds=0,this.liveBodyOrder=new Set,this.nextSequence=0,this.paused=!1,this.queue=new Af,this.revision=0,this.observedInitialBoundary=!1,this.updateResults=new po,this.simulationState="settled",this.visible=!0,this.quiescence=new Pf,this.programs=new _f,Yh(e);let{bodyBudget:t,colliders:i,engine:r,kernel:n,observation:o,sediment:a,emitters:s,eventDrop:l,...c}=e;this.config={...Yp,...c,viewTransform:{...c.viewTransform??Yp.viewTransform}},this.configInput=lf(e),this.bodyBudget=t??{},this.engineInput=r,this.observation=Gp(o),this.sediment=new jp(a??!1),this.world=Lp(r,{fixedDt:this.config.fixedDt,...n}),this.quiescence.setKernelOptions(n),i&&this.world.setColliders(Kp(i)),this.programs.configure({emitters:s,eventDrop:l},this.world)}updateConfig(e){Yh(e);let t=function(e,t){return Object.keys(e).filter(i=>"viewTransform"===i?e.viewTransform?.x!==t.viewTransform?.x||e.viewTransform?.y!==t.viewTransform?.y:"colliders"===i?!Xh(e.colliders,t.colliders):"kernel"===i?!vf(e.kernel,t.kernel):e[i]!==t[i])}(e,this.configInput),{colliders:i,bodyBudget:r,engine:n,kernel:o,observation:a,sediment:s,emitters:l,eventDrop:c,...u}=e;if(this.programs.configure({emitters:l,eventDrop:c},this.world),this.config={...this.config,...u,viewTransform:{...u.viewTransform??this.config.viewTransform}},t.includes("eventDrop")&&(this.revision+=1),void 0!==r&&(this.bodyBudget=r,!1===r&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){let e=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=Lp(n,e.options),this.world.restore(e),this.revision+=1}if(o&&!vf(o,this.configInput.kernel)){let e=this.world.snapshot(),t={...e.options,...o,gravity:{...e.options.gravity,...o.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}a&&(this.observation=Gp(a,this.observation)),this.sediment.updateConfig(s),i&&t.includes("colliders")&&(this.world.setColliders(Kp(i)),this.revision+=1),this.configInput=lf({...this.configInput,...e});let d=xf(t);this.updateResults.record({kind:"config",keys:t},d.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Kp(e)),this.configInput={...this.configInput,colliders:Kp(e)},this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},xf(["colliders"]).invalidations)}enqueue(e,t){let i=function(e,t,i,r,n){let o=Array.isArray(t)?t:[t];for(let e of o)zh(e);let a=i?function(e,t={}){let i=Hp(t.startAt)??0,r=t.pacing??"immediate";if("arrival"===r){let r=1/0,n=e.map((e,i)=>{let n=function(e,t,i){return"function"==typeof i?Hp(i(e,t)):"string"==typeof i?Hp(Up(e,i)):Hp(e.spawnAt)??Hp(Up(e,"arrivalTime"))??Hp(Up(e,"timestamp"))??Hp(Up(e,"time"))??Hp(Up(e,"eventTime"))}(e,i,t.timeAccessor);return null!=n&&(r=Math.min(r,n)),n}),o=Hp(t.timeScale)??1,a=o>0?o:1;return e.map((e,t)=>{let o=n[t],s=null==o?0:Math.max(0,o-r);return{...Vp(e),spawnAt:i+s/a}})}if("object"==typeof r){let t=Hp(r.ratePerSec);if(t&&t>0)return e.map((e,r)=>({...Vp(e),spawnAt:i+r/t}))}return e.map(e=>({...Vp(e),spawnAt:i}))}(o,{...i,startAt:i.startAt??r}):o;if(i)for(let e of a)zh(e);for(let t of a)e.push({...Vp(t),sequence:n++,spawnAt:t.spawnAt??r});return a.length}(this.queue,e,t,this.elapsedSeconds,this.nextSequence);this.nextSequence+=i,i>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i},i?cf:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Vp(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},cf)}materializeDueSpawns(){let e=this.revision,t=[],i=[];return this.spawnDue(t,i),0===t.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?cf:[])),t}clear(){this.observedInitialBoundary=!1;let{options:e,colliders:t}=this.world.snapshot();this.world.init({...e,fixedDt:this.config.fixedDt}),this.world.setColliders(t),this.activeSensorPairs.clear(),this.liveBodyOrder.clear(),this.queue.clear(),this.accumulator=0,this.elapsedSeconds=0,this.programs=new _f,this.programs.configure(this.configInput,this.world),this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},cf)}tick(e,t){let i=this.revision,r=[],n=[],o=[],a=[],s=[];if(this.paused||!this.visible){let e=this.result(0,r,n,o,a,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}let l=Math.max(0,Math.min(Number.isFinite(e)?e:0,this.config.maxDeltaSeconds))*this.config.timeScale;this.spawnDue(r,s);let c=this.observeBodyBudget(s),u=this.evictOverflow(s);n.push(...u.evicted),o.push(...u.sedimented),this.syncSimulationState(s),r.length>0&&this.quiescence.reset(),this.accumulator+=l;let d=this.stepObserver(t,{spawned:r,evicted:n,sedimented:o,events:a,observations:s}),h=l>0?Math.floor((this.accumulator+1e-9*this.config.fixedDt)/this.config.fixedDt):0,{steps:p,budget:f}=If(this.settleHost(),Math.min(h,this.config.maxSubsteps),{spawned:r,evicted:n,sedimented:o,events:a,observations:s},{stopAtRest:!1,shouldStop:()=>this.paused||!this.visible,afterStep:d});this.accumulator=Math.max(0,this.accumulator-p*this.config.fixedDt),p===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(p>0||r.length>0||n.length>0||o.length>0||a.length>0)&&(this.revision+=1);let g=this.result(p,r,n,o,a,s,void 0,f??c);return this.updateResults.record({kind:"tick",count:p},this.revision!==i?r.length||n.length||o.length?cf:uf:[]),g}settle(e){return this.runSettle(e,!1).steps}settleWithObservations(e,t){return this.runSettle(e,!0,t)}stepObserver(e,t){let i=!this.observedInitialBoundary;return e&&(this.observedInitialBoundary=!0),function(e,t,i=!1){if(!e)return;let r=["spawned","evicted","sedimented","events","observations"],n={spawned:0,evicted:0,sedimented:0,events:0,observations:0},o=o=>{let a=t(o),s={...a};r.forEach(e=>{s[e]=a[e].slice(n[e]),n[e]=a[e].length}),(0!==o||i||!r.every(e=>0===s[e].length))&&e.onStep(s)};return o(0),()=>o(1)}(e,e=>(e&&(this.revision+=1),this.result(e,t.spawned,t.evicted,t.sedimented,t.events,t.observations)),i)}settleHost(e=!1){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length+Number(e?this.programs.backlog():this.programs.ownsClock()),atRest:()=>this.atRest(),elapsed:()=>this.elapsedSeconds,nextArrival:()=>this.queue.firstArrival(),lastArrival:()=>function(e,t,i){let r=e;for(let i of t)i.travel&&(r=Math.max(r,e+i.travel.durationSeconds-(i.travel.elapsedSeconds??0)));for(let e of i)r=Math.max(r,e.spawnAt+(e.travel?e.travel.durationSeconds-(e.travel.elapsedSeconds??0):0));return r}(this.elapsedSeconds,this.readBodies(),this.queue.sorted()),advanceTime:t=>{this.elapsedSeconds+=t;let i=this.programs.emitters?.advance(t,e);i?.length&&this.enqueue(i)},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>function(e,t,i){let r=t.filter(e=>"sleep"===e.type);if(0===r.length)return;let n=wf(e,r.map(e=>e.bodyId));for(let e of r){let t=n(e.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t)),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t,i){let r=this.revision,n=[],o=[],a=[],s=[],l=t?[]:void 0;if(t&&(this.paused||!this.visible)){let e=this.result(0,n,o,a,s,l??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,l);let c=this.observeBodyBudget(l),u=this.evictOverflow(l);o.push(...u.evicted),a.push(...u.sedimented),this.syncSimulationState(l),n.length>0&&this.quiescence.reset();let d=t?{spawned:n,evicted:o,sedimented:a,events:s,observations:l}:{spawned:n},h=this.stepObserver(i,{spawned:n,evicted:o,sedimented:a,events:s,observations:l??[]}),{steps:p,budget:f}=If(this.settleHost(void 0===e),e??this.config.settleStepLimit,d,{afterStep:h,continueWhile:i?.continueWhile,shouldStop:t?()=>this.paused||!this.visible:void 0,drainArrivals:void 0===e,skipIdle:void 0===e&&!i&&!this.programs.pending()}),g=n.length+o.length+a.length>0;(p>0||g||s.length>0)&&(this.revision+=1);let m=this.result(p,n,o,a,s,l??[],void 0,f??c);return this.updateResults.record({kind:"settle",count:p},this.revision===r?[]:g?cf:uf),m}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return function(e,t={}){let{baselineY:i=0,binWidth:r=24,gap:n=2,maxHeight:o=80,value:a="count",x:s}=t,l=e.reduce((e,t)=>Math.max(e,t[a]),1);return e.map((e,t)=>{let c=Math.max(0,e[a]/l*o),u=s?.(e,t)??t*(r+n);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:u,y:i-c,width:r,height:c,meanX:e.x.mean,meanY:e.y.mean}})}(this.readSediment(),e)}hitTest(e,t,i=0,r){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,i,r)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()||this.programs.pending()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.size}elapsed(){return this.elapsedSeconds}recordObservation(e){let t=qp(e,this.elapsedSeconds,this.observation);return this.emitObservation(t),this.updateResults.record({kind:"update",count:1},["evidence"]),t}recordLifecycleObservation(e){return this.updateResults.record({kind:"update",count:1},["evidence"]),qp(e,this.elapsedSeconds,this.observation)}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){let t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?df:[])}setVisible(e){let t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?df:[])}remove(e){let t=new Set(e),i=new Set(this.liveBodyOrder),r=this.queue.remove(t);for(let t of e)this.liveBodyOrder.delete(t);this.world.remove(e),kf(this.activeSensorPairs,t);let n=e.filter(e=>i.has(e)||r.has(e));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?cf:[]),n}setConstraint(e){let t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},uf),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},uf)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},uf)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,i,r)=>e.applyImpulse(t,i,r),clear:()=>e.clear(),hitTest:(t,i,r)=>e.hitTest(t,i,r),pause:()=>e.setPaused(!0),push:(t,i)=>e.enqueue(t,i),pushMany:(t,i)=>e.enqueue(t,i),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}runtimeState(){return{elapsedSeconds:this.elapsedSeconds,timeScale:this.config.timeScale,fixedDt:this.config.fixedDt,paused:this.paused,visible:this.visible,simulationState:this.simulationState}}eventDropState(){return this.programs.eventDrop?{metadata:this.programs.eventDrop.metadata(),viewTransform:this.programs.eventDrop.viewTransform(),lifecycleEvents:[]}:void 0}viewTransform(){return this.programs.eventDrop?.viewTransform()??{...this.config.viewTransform}}isEventDropLive(){return!!this.programs.eventDrop}enqueueSequence(){return this.nextSequence}workerLiveDelta(){return this.programs.eventDrop?.drainWorkerDelta()}workerStructure(){return{world:this.world.snapshot(),queue:this.queue.sorted().map(Zp),liveBodyOrder:Array.from(this.liveBodyOrder),sediment:this.readSediment()}}workerState(){return{...this.programs.emitters&&{emitterProgress:this.programs.emitters.progress()},nextSequence:this.nextSequence,accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs),elapsedSeconds:this.elapsedSeconds,paused:this.paused,revision:this.revision,simulationState:this.simulationState,visible:this.visible}}workerSleepTimes(e){return this.world.workerSleepTimes?.(e)}applyWorkerFrame(e){if(e.snapshot){let t=this.configInput;return this.restore(e.snapshot),void(this.configInput=t)}if(!e.state||!this.world.applyWorkerMotion)throw new Error("Physics worker motion frame requires a built-in mirror");e.structure?(this.world.restore(e.structure.world),this.queue.restore(e.structure.queue.map(Zp)),this.liveBodyOrder=new Set(e.structure.liveBodyOrder),this.sediment.restore(e.structure.sediment),this.bodySpatialIndex=new sf):(e.state.revision!==this.revision||e.state.elapsedSeconds!==this.elapsedSeconds)&&this.world.applyWorkerMotion(e),e.live&&this.programs.eventDrop?.applyWorkerDelta(e.live,this.world);let t=this.simulationState,{emitterProgress:i,...r}=e.state;i&&this.programs.emitters?.restoreProgress(i),Object.assign(this,r,{activeSensorPairs:new Set(e.state.activeSensorPairs)}),this.updateResults.record({kind:"tick"},uf),t!==this.simulationState&&this.observation.onSimulationStateChange?.(this.simulationState,t)}snapshot(){let e=this.world.snapshot();return{...this.workerState(),nextSequence:this.nextSequence,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Qp(this.bodyBudget),config:{...this.config,viewTransform:{...this.config.viewTransform},kernel:ef(e.options)},queue:this.queue.sorted().map(Zp),sediment:this.readSediment(),liveBodyOrder:Array.from(this.liveBodyOrder),world:e,...this.programs.snapshot()}}restore(e){!function(e){if(Fh(e.activeSensorPairs,"Physics activeSensorPairs"),Fh(e.liveBodyOrder,"Physics liveBodyOrder"),Dh(e.queue,"Physics queue"),null!=e.sediment){Dh(e.sediment,"Physics sediment");for(let t of e.sediment){if(!t)throw new RangeError("Physics sediment requires bin records");Fh(t.bodyIds,"Physics sediment.bodyIds"),Rh(t.count,"Physics sediment.count");for(let e of["x","y","value"]){let i=t[e];if(!i)throw new RangeError("Physics sediment requires statistics");for(let t of["count","total","mean","min","max","variance"])Rh(i[t],`Physics sediment.${e}.${t}`)}}}Yh(e.config),Wh(e.world);for(let t of e.queue)zh(t),Rh(t.sequence,"Physics queue sequence");if(Rh(e.elapsedSeconds,"Physics elapsedSeconds"),Rh(e.accumulator,"Physics accumulator"),null!=e.nextSequence&&(!Number.isSafeInteger(e.nextSequence)||e.nextSequence<0||e.queue.some(t=>t.sequence>=e.nextSequence)))throw new RangeError("Physics nextSequence must exceed queued sequence numbers")}(e);let t=_f.restore(e);this.bodySpatialIndex=new sf,this.programs=t,this.observedInitialBoundary=!1;let i=this.simulationState;Object.assign(this,function(e){let t={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale,viewTransform:{...e.config.viewTransform??{x:0,y:0}}};return{config:t,configInput:lf({...t,bodyBudget:Qp(e.bodyBudget??{}),kernel:ef(e.world.options),...e.emitters&&{emitters:e.emitters.options},...e.eventDrop&&{eventDrop:e.eventDrop.config}}),bodyBudget:Qp(e.bodyBudget??{}),activeSensorPairs:new Set(e.activeSensorPairs),accumulator:e.accumulator,elapsedSeconds:e.elapsedSeconds,paused:e.paused,revision:e.revision,visible:e.visible,liveBodyOrder:new Set(e.liveBodyOrder),nextSequence:e.nextSequence??e.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,simulationState:e.simulationState??Sf(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping))}}(e)),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.queue.restore(e.queue.map(Zp)),this.sediment.restore(e.sediment??[]),this.world.restore(e.world),this.updateResults.record({kind:"restore"},cf),this.simulationState!==i&&this.observation.onSimulationStateChange?.(this.simulationState,i)}spawnDue(e,t){for(;this.queue.length>0&&this.queue.firstArrival()<=this.elapsedSeconds+1e-9*this.config.fixedDt;){let i=this.queue.shift();if(!i)return;this.spawnOne(i,t),e.push(i.id)}if(this.programs.eventDrop){let e=this.programs.eventDrop.advance(this.world,this.elapsedSeconds);e.length&&this.remove(e);for(let e of this.programs.eventDrop.ledger.drainEvents())this.emitObservation(qp(e,this.elapsedSeconds,this.observation),t)}}spawnOne(e,t){this.programs.eventDrop&&(e=this.programs.eventDrop.prepare(e,this.elapsedSeconds)),zh(e),this.liveBodyOrder.delete(e.id)&&kf(this.activeSensorPairs,new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.add(e.id);for(let t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});!t&&!this.observation.onObservation||function(e,t,i){let r=wf(e)(t.id);i.emit({type:"physics-spawn",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t.id,datum:r?.datum??t.datum,x:r?.x??t.x,y:r?.y??t.y})}(this.world,e,this.observationContext(t))}result(e,t,i,r,n,o,a,s=this.evaluateBodyBudget()){this.syncSimulationState(o);let l=this.world.allSleeping();return{budget:s,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:a??(!this.paused&&this.visible&&this.hasPendingWork()),sleeping:l,sedimented:r,spawned:t,steps:e}}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,i){let r=new Set(e.activeSensorPairs().map(e=>function(e,t){return`${e}\0${t}`}(e.sensorId,e.bodyId))),n=r.size!==t.size;if(!n)for(let e of r)if(!t.has(e)){n=!0;break}if(!n)return r;let o=Array.from(r).filter(e=>!t.has(e)).sort(),a=Array.from(t).filter(e=>!r.has(e)).sort(),s=wf(e,[...o,...a].map(e=>rf(e).bodyId)),l=(e,t)=>{let{sensorId:r,bodyId:n}=rf(t),o=i.observation.sensors[r],a=s(n);i.emit({type:"enter"===e?o?.enterType??"physics-bin-enter":o?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:n,datum:a?.datum,x:a?.x,y:a?.y,sensorId:r,binId:o?.binId??r})};for(let e of o)l("enter",e);for(let e of a)l("exit",e);return r}(this.world,this.activeSensorPairs,this.observationContext(e))}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return function(e){let t=Math.max(0,Math.floor(e.liveBodies)),i=Math.max(0,Math.floor(e.queuedBodies??0)),r=t+i,n=Wp(e.bodyLimit),o=Wp(e.engineMaxBodiesHint),a=function(e,t,i){if(!1===i)return;let r=Wp(i?.warnAt);return null!=r?r:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(n,o,e.options),s=null==n?0:Math.max(0,t-n),l=s>0?"overflow":null!=a&&r>=a?"warning":"ok";return{action:"overflow"!==l?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:o,liveBodies:t,overflow:s,projectedBodies:r,queuedBodies:i,state:l,warnAt:a}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.size,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){let t=this.evaluateBodyBudget();return this.bodyBudgetObservationKey=function(e,t,i,r){if(!t||"ok"===e.state)return"ok";let n=`${e.state}:${e.action}`;return n!==i&&function(e,t){t.emit({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:t.elapsedSeconds,chartType:t.observation.chartType,chartId:t.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt})}(e,r),n}(t,!1!==this.bodyBudget,this.bodyBudgetObservationKey,this.observationContext(e)),t}syncSimulationState(e){let t=Sf(this.paused,this.visible,this.queue.length>0||this.programs.pending(),this.atRest());if(t===this.simulationState)return;let i=this.simulationState;this.simulationState=t,function(e,t,i){i.observation.onSimulationStateChange?.(t,e),("running"===t||"settled"===t)&&i.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:t,previousSimulationState:e})}(i,t,this.observationContext(e))}evictOverflow(e){let{evicted:t,sedimented:i,liveBodyOrder:r}=function(e,t,i,r,n,o){let a={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===i)return a;let s=Math.max(0,Math.floor(r));if(!Number.isFinite(s))return a;let l=n.size-s;if(l<=0)return a;let c=function(e,t,i){if("sleeping-first"!==t)return Array.from(i);let r=new Map(e.readState().map(e=>[e.id,e.sleeping])),n=[],o=[];for(let e of i)r.get(e)?n.push(e):o.push(e);return[...n,...o]}(e,i,n).slice(0,l);if(0===c.length)return a;let u=function(e,t,i,r){if(!t.isEnabled())return[];let n=wf(e,i),o=[];for(let e of i){let i=n(e);if(!i)continue;let a=t.add(i);a&&(o.push(e),r.emit({type:"physics-sediment",timestamp:r.elapsedSeconds,chartType:r.observation.chartType,chartId:r.observation.chartId,bodyId:e,datum:i.datum,x:i.x,y:i.y,binId:a.id,count:a.count,total:a.total}))}return o}(e,t,c,o);e.remove(c);let d=new Set(c);return{evicted:c,sedimented:u,liveBodyOrder:new Set(Array.from(n).filter(e=>!d.has(e)))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=r,kf(this.activeSensorPairs,new Set(t))),{evicted:t,sedimented:i}}};import{scaleLinear as Lf}from"d3-scale";function Cf(e){return function(e,t,i=!1){let{data:r,timeAccessor:n,arrivalAccessor:o,windows:a,watermark:s,watermarkAtArrivalAccessor:l,ballRadius:c,seed:u,size:d,timeExtent:h,timeScale:p=1}=e,{events:f,watermarkValue:g,ledger:m,lifecycleEvents:y}=t??R({data:r,timeAccessor:n,arrivalAccessor:o,watermark:s,watermarkAtArrivalAccessor:l,sourceAccessor:e.sourceAccessor,sourceIds:e.sources?.map(e=>e.id),windowSize:a.size}),x=new Map(m.map(e=>[e.start,e])),b=K(d);if(e.sources?.some(e=>!1!==e.visible)&&"none"!==e.sourceRail?.side){let t=Math.max(48,e.sourceRail?.tileSize??80);"top"===e.sourceRail?.side?(b.plot.y+=t,b.plot.height=Math.max(1,b.plot.height-t)):("right"===e.sourceRail?.side||(b.plot.x+=t),b.plot.width=Math.max(1,b.plot.width-t))}let v=f.length?1/0:0,w=f.length?1/0:0,k=f.length?-1/0:a.size;for(let e of f)v=Math.min(v,e.arrivalTime),w=Math.min(w,e.eventTime),k=Math.max(k,e.eventTime);let S=e.timeUnit??(f.some(e=>Math.abs(e.eventTime)>1e5||Math.abs(e.arrivalTime)>1e5)?"ms":"s"),A="ms"===S?.001:1,M=te(h?.[0]),$=te(h?.[1]),_=i?M??w:Math.min(M??w,w),P=i?$??k:Math.max($??k,k),I=Math.floor(_/a.size)*a.size,T=Math.max(1,Math.ceil((P-I+a.size)/a.size)),L=function(e,t){let i=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:i,height:e.plot.height},windowPlot:{x:e.plot.x+i,y:e.plot.y,width:Math.max(40,e.plot.width-i),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(b,c),C=I+T*a.size,N=Lf().domain([I,C]).range([L.windowPlot.x,L.windowPlot.x+L.windowPlot.width]),D=0,F=Array.from({length:T},(e,t)=>(I+(t+1)*a.size<=g&&D++,{value:0,secondary:0})),E=[];f.forEach(({datum:t,index:i,eventTime:r,arrivalTime:n,watermarkAtArrival:o,late:s})=>{let l=Math.max(0,Math.min(T-1,Math.floor((r-I)/a.size)));F[l].value+=s?0:1,F[l].secondary+=s?1:0,E.push({id:String(t.id??`event-${i}`),x:Nf(r,l,s,{windowStart:I,windowSize:a.size,gutter:L.gutter,closedWindowCount:D,windowPlot:L.windowPlot,windowCount:T},c),y:b.plot.y+c+2,vx:0,vy:0,mass:1,friction:.02,spawnAt:n,shape:{type:"circle",radius:c},datum:{...t,eventTime:r,arrivalTime:n,windowIndex:l,windowId:`${I+l*a.size}-${I+(l+1)*a.size}`,source:String(ee(t,i,e.sourceAccessor??"source")??""),watermarkAtArrival:o,late:s}})});let O=b.plot.y+b.plot.height,z=b.plot.y+.28*b.plot.height,B={closedWindowCount:D,gutter:L.gutter,plot:b.plot,windowCount:T,windowPlot:L.windowPlot,windowSize:a.size,windowStart:I},j=function(e,t){let i=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!i)return[];let r=e.windowStart,n=e.windowStart+e.windowCount*e.windowSize,o=Lf().domain([r,n]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),a=o(e.windowStart+i*e.windowSize),s=e.windowPlot.x,l=Math.max(18,Math.min(.3*e.windowPlot.height,a-s)),c=t+l,u=e=>a===s?t:c+(e-s)/(a-s)*(t-c),d=[];for(let t=0;t<i;t+=1){let i=e.windowStart+t*e.windowSize,r=i+e.windowSize,n=o(i),a=o(r);d.push({id:`eventdrop-lid-${t}`,windowIndex:t,x1:n,y1:u(n),x2:a,y2:u(a)})}return d}(B,z);for(let e of E){let t=e.datum;e.y=Rf({...B,lidSegments:j},t.windowIndex,t.late,c)}let W=function(e){let{count:t,idPrefix:i,wallThickness:r,xScale:n,yBottom:o,yTop:a,yTopForIndex:s}=e;return Array.from({length:t+1},(e,t)=>{let l=Math.min(o-1,s?.(t)??a),c=Math.max(1,o-l);return{id:`${i}-wall-${t}`,shape:{type:"aabb",x:n(t),y:l+c/2,width:r,height:c}}})}({idPrefix:"eventdrop-window",count:T,xScale:e=>N(I+e*a.size),yTop:L.wallTop,yTopForIndex:e=>{let t=(e=>{if(e<0||e>D)return null;let t=0===e?j[0]?.y1:j[e-1]?.y2??j[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?L.wallTop:t+1.25*c},yBottom:O,wallThickness:6}),Y=[...nf({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...W,...j.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*c)},friction:.02,restitution:.01}))];return function(e,t){let i=t.arrival;if(i&&"drop"!==i){if("travel"!==i.mode)throw new RangeError("arrival.mode must be travel");if(null!=i.history&&"present"!==i.history&&"travel"!==i.history)throw new RangeError("arrival.history must be present or travel");for(let e of[i.durationMs,i.speedPxPerSec])if(null!=e&&(!Number.isFinite(e)||e<=0))throw new RangeError("Travel duration and speed must be finite and positive");if(null!=i.durationMs&&null!=i.speedPxPerSec)throw new RangeError("Choose arrival.durationMs or arrival.speedPxPerSec");if(null!=i.path&&"function"!=typeof i.path&&"straight"!==i.path&&"connector"!==i.path)throw new RangeError("arrival.path must be straight, connector or a callback")}let r=new Map(wh(t.sources,t.sourceRail,t.size).map(({source:e,x:t,y:i})=>[e.id,{x:t,y:i-6}])),n=Number.isFinite(t.timeScale)&&t.timeScale>0?t.timeScale:1,o=[];for(let a of e){let e=a.datum;i&&"drop"!==i&&(e.__phase=e.late?"late":"board");let s=e.windowIndex<t.closedWindowCount,l=(!i||"drop"===i||"travel"!==i.history)&&(s&&!e.late||!s&&e.late);l&&o.push(a);let c=(l?t.firstArrival:e.arrivalTime)*t.secondsPerUnit;a.__eventDropSpawnTime=c;let u=r.get(e.source);if(!i||"drop"===i||!u||l)continue;let d={x:a.x,y:a.y},h="function"==typeof i.path?i.path({...u},{...d}):"connector"===i.path?[u,{x:u.x,y:Math.min(u.y,d.y)-24},{x:d.x,y:Math.min(u.y,d.y)-24},d]:[u,d];if(Ph({points:h,durationSeconds:1}),h[0].x!==u.x||h[0].y!==u.y||h.at(-1).x!==d.x||h.at(-1).y!==d.y)throw new RangeError("Travel paths must start at the source and end at the board entry");let p=null!=i.speedPxPerSec?Math.max(1/120,Lh(h)/i.speedPxPerSec):(i.durationMs??800)/1e3;a.travel={points:h.map(e=>({...e})),durationSeconds:p/n,elapsedSeconds:0},a.x=u.x,a.y=u.y,a.__eventDropSpawnTime=c-p,e.__phase="travel"}if(i&&"drop"!==i&&null!=i.speedPxPerSec){let t=e.reduce((e,t)=>Math.max(e,t.travel?.durationSeconds??0),0);for(let i of e)i.travel&&(i.__eventDropSpawnTime+=(i.travel.durationSeconds-t)*n,i.travel.durationSeconds=t)}let a=e.reduce((e,t)=>Math.min(e,t.__eventDropSpawnTime),1/0);for(let e of o)e.__eventDropSpawnTime=a}(E,{...e,secondsPerUnit:A,timeScale:p,firstArrival:v,closedWindowCount:D}),{config:J(u,Y,"EventDropChart",{friction:.08}),initialSpawns:E,initialSpawnPacing:{pacing:"arrival",timeAccessor:"__eventDropSpawnTime",timeScale:p},projectionRows:F.map((e,t)=>({label:`${I+t*a.size}-${I+(t+1)*a.size}`,value:e.value,secondary:e.secondary,...x.get(I+t*a.size)})),metadata:{kind:"event-drop",closedWindowCount:D,gutter:L.gutter,lidSegments:j,lateCount:F.reduce((e,t)=>e+t.secondary,0),plot:b.plot,windowPlot:L.windowPlot,windowWalls:W.map(({id:e,shape:t})=>({id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height})),watermarkValue:g,windowCount:T,windowSize:a.size,windowStart:I,ledger:m,lifecycleEvents:y,timeUnit:S,eventTimeFrontier:f.length?k:0,arrivalFrontier:f.reduce((e,t)=>Math.max(e,t.arrivalTime),0)}}}(e)}function Rf(e,t,i,r){let{windowPlot:n,lidSegments:o}=e,a=o[t];return i&&!a?Math.min(n.y+n.height-r,n.y+.48*n.height+2*r+4):!i&&a?Math.min(n.y+n.height-r,Math.max(a.y1,a.y2)+2*r+4):n.y+r+2}function Nf(e,t,i,r,n){let{windowPlot:o,windowCount:a,windowStart:s,windowSize:l}=r;if(i&&t>=r.closedWindowCount)return r.gutter.x+r.gutter.width/2;let c=o.width/a,u=i?o.x:o.x+t*c,d=i?o.x+o.width:u+c,h=Math.min((d-u)/2,n+(i?0:3)),p=o.x+(e-s)/l*c;return Math.max(u+h,Math.min(d-h,p))}function Df(e,t,i){let r=Math.max(1,t),n=e.width/r,o=Math.max(2,2*i),a=Math.min(.7*n,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(a/o));return{laneWidth:n,tubeWidth:a,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*n,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}import{scaleLinear as Ff}from"d3-scale";function Ef(e,t,i,r){let n=(t+i)/2,o=[];for(let a of e){let s=o.filter(e=>Math.abs(a.x-e.x)<a.radius+e.radius+.5),l=[n];for(let e of s){let t=a.radius+e.radius+.5,i=Math.sqrt(t**2-(a.x-e.x)**2);l.push(e.y-i,e.y+i)}let c=r()<.5?-1:1;l.sort((e,t)=>Math.abs(e-n)-Math.abs(t-n)||c*(e-t));let u=l.find(e=>e-a.radius>=t&&e+a.radius<=i&&s.every(t=>(a.x-t.x)**2+(e-t.y)**2>=(a.radius+t.radius+.5)**2-1e-6));if(null==u){let r=e.reduce((e,t)=>Math.max(e,t.radius),-1/0),o=Math.max(0,i-t-2*r);return{positions:e.map((t,i)=>n+(1===e.length?0:i/(e.length-1)-.5)*o),overlapping:!0,entryOffset:0}}o.push({...a,y:u})}return{positions:o.map(e=>e.y),overlapping:!1,entryOffset:Math.max(0,o.reduce((e,i)=>Math.min(e,i.y-i.radius-t),36))}}function Of(e){if(Array.isArray(e)&&e.length>=2){let t=te(e[0]),i=te(e[1]);return null!=t&&null!=i?{x:t,y:i}:null}if(e&&"object"==typeof e){let t=e,i=te(t.x),r=te(t.y);return null!=i&&null!=r?{x:i,y:r}:null}return null}function zf(e){return Array.isArray(e)?e.map(Of).filter(e=>null!=e):[]}function Bf(e,t,i){return"normalized"===i?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:_(e.x,t.plot.x,t.plot.x+t.plot.width),y:_(e.y,t.plot.y,t.plot.y+t.plot.height)}}function jf(e){let t=0;for(let i=1;i<e.length;i+=1){let r=e[i].x-e[i-1].x,n=e[i].y-e[i-1].y;t+=Math.hypot(r,n)}return t}function Wf(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};let i=_(t,0,1)*jf(e),r=0;for(let t=1;t<e.length;t+=1){let n=e[t-1],o=e[t],a=Math.hypot(o.x-n.x,o.y-n.y);if(!(a<=0)){if(r+a>=i){let e=(i-r)/a;return{x:n.x+(o.x-n.x)*e,y:n.y+(o.y-n.y)*e}}r+=a}}return{...e[e.length-1]}}function Yf(e,t){let i=Wf(e,Math.max(0,t-.02)),r=Wf(e,Math.min(1,t+.02)),n=r.x-i.x,o=r.y-i.y,a=Math.hypot(n,o)||1;return{x:n/a,y:o/a}}function qf(e,t,i,r,n,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:i,x2:r,y2:n,thickness:o.thickness??8}}}function Xf(e,t,i,r){return{type:"aabb",x:e,y:t,width:i,height:r}}function Gf(e){let t=e.shape??"lane",i=Math.max(1,Math.round(e.width)),r=Math.max(1,Math.round(e.height)),n=e.padX??46,o=e.padY??72,a=n,s=i-n,l=o,c=r-Math.max(24,Math.round(.45*o)),u=(l+c)/2,d=Math.max(1,c-l),h=ol(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,g=ol(d*h+f,.06*d,.5*d),m=g/2,y=u-m,x=u+m,b=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,S=e.stages;if(!S.length)throw new Error("processStageLayout requires at least one stage");let A=ol(e.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(S),$=s-a,_=a,P=S.map((e,t)=>{let i=(e.share??1)/M*$,r=_,n=t===S.length-1?s:_+i;return _=n,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:r,x1:n,x:(r+n)/2,width:n-r,y:u,height:d}}),I=P[A],T=I.x0,L=I.x1,C=(e,i)=>{if("lane"===t)return"top"===i?l:c;if("funnel"===t){let t=ol((e-a)/Math.max(1,s-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=T){let t=ol((e-a)/Math.max(1,T-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=L)return"top"===i?y:x;let r=ol((e-L)/Math.max(1,s-L),0,1);return"top"===i?y+(l-y)*r:x+(c-x)*r},R=P.map(e=>{let t=Math.min(C(e.x0,"top"),C(e.x1,"top")),i=Math.max(C(e.x0,"bottom"),C(e.x1,"bottom"));return{...e,y:(t+i)/2,height:Math.max(1,i-t)}}),N={thickness:k,friction:v,restitution:w},D=[];"lane"===t?D.push(qf(`${b}-top`,a,l,s,l,N),qf(`${b}-bottom`,a,c,s,c,N),qf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),qf(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,k)})):"funnel"===t?D.push(qf(`${b}-top`,a,l,s,y,N),qf(`${b}-bottom`,a,c,s,x,N),qf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),qf(`${b}-right`,s,y,s,x,{...N,thickness:Math.max(6,k)})):D.push(qf(`${b}-left-top`,a,l,T,y,N),qf(`${b}-left-bottom`,a,c,T,x,N),qf(`${b}-center-top`,T,y,L,y,N),qf(`${b}-center-bottom`,T,x,L,x,N),qf(`${b}-right-top`,L,y,s,l,N),qf(`${b}-right-bottom`,L,x,s,c,N),qf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),qf(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,k)}));let F=e.membraneDampingScale??.5,E=a,O=Math.max(1,("bowtie"===t?T:s)-E),z=(e.membranes??[]).map(e=>{let t=E+ol(e.offset,0,1)*O,i=e.width??18+18*e.cost,r=d-16,n=u+.25*(e.wobble??0);return{...e,x:t,y:n,width:i,height:r}}),B=!1===e.includeMembraneRegions?[]:z.map(e=>function(e){let t=e.dampingScale??.5,i=e.energyScale??1,r=ol(e.cost,0,2);return{...Hf(e,"membrane","membrane",{membraneCost:r}),damping:r*t,energyDelta:-r*i}}({id:e.id,label:e.label??e.id,description:e.description??`${e.label??e.id} is a permeable region. It taxes energy and damps velocity while bodies overlap it.`,x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??F,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:i,height:r,padX:n,padY:o,left:a,right:s,topY:l,bottomY:c,midY:u,centerLeft:T,centerRight:L,pinchHeight:g,pinchTop:y,pinchBottom:x,stages:R,membranes:z,colliders:D,regionEffects:B,boundaryY:C}}function Vf(e,t,i){return"function"==typeof t?r=>({...i,...t(r),primitive:e}):{...i,...t,primitive:e}}function Hf(e,t,i,r){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:Xf(e.x,e.y,e.width,e.height),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:i?Vf(i,e.attributes,r):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function Uf(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...Hf(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function Zf(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}import{scaleLinear as Kf}from"d3-scale";function Qf(e,t,i){return Zt(e,t,i)}function Jf(e,t){let i=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>i&&ti(i,e)||"#4e79a7":t=>{if(i){let e=ti(i,t);if(e)return e}let r=0;for(let e=0;e<t.length;e++)r=31*r+t.charCodeAt(e)|0;return e[Math.abs(r)%e.length]??"#4e79a7"}}function eg(e,t){let i=t.config??{},r=(t.sensors??[]).map(e=>({...e,sensor:!0})),n=[...t.colliders??[],...r],o=[...e.colliders??[],...i.colliders??[],...n];return{...e,...i,observation:{...e.observation,...i.observation},...o.length>0&&{colliders:o}}}function tg(e){let t=sg(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function ig(e,t,i,r){return i?"function"==typeof i?i(e,t):e[i]??r:r}function rg(e){return`gauntlet:${e}:core`}function ng(e,t){return`gauntlet:${e}:positive:${t}`}function og(e,t,i){return`gauntlet:${e}:negative:${t}:${i}`}at.width,at.height;var ag={left:28,top:76,rightInset:30,thickness:8};function sg(e){let t=e.height??e.floorY+36;if(!(e.width<220||t<160))return ag;let i=Math.max(1,Math.min(e.width,t)),r=Math.max(2,.04*e.width);return{left:r,top:Math.max(2,.08*t),rightInset:r,thickness:Math.max(1,Math.min(4,.04*i))}}function lg(e){let t=e.height??e.floorY+36;return Math.max(.12,Math.min(1,e.width/500,t/260))}function cg(e,t,i,r){let n=sg(r),o=Math.max(2,i+2),a=n.left+n.thickness/2+o,s=r.width-n.rightInset-n.thickness/2-o,l=n.top+n.thickness/2+o,c=r.floorY-o,u=(e,t,i)=>t<=i?Math.max(t,Math.min(i,e)):(t+i)/2;return{x:u(e,a,s),y:u(t,l,c)}}function ug(e,t,i=1){let r=[...e].sort((e,t)=>e.localeCompare(t)),n=Math.max(0,r.indexOf(t)),o=r.length>1?n/(r.length-1):.5;return{angle:.82*-Math.PI+o*Math.PI*.64,index:n,radius:(48+n%2*6)*i}}function dg(e,t,i){let r=e.activePositiveIds.reduce((e,i)=>e+(t.get(i)?.value??1),0),n=e.missingPositiveIds.length+e.poppedPositiveIds.length,o=e.negativeIds.reduce((e,t)=>e+(i.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*r-8*o-1.2*e.delay-5*n))}function hg(e){let t=function(e,t,i){let[r,n]=e,o=r<220||n<160,a=Math.round(.48*n),s=o?n-Math.max(3,Math.min(12,.1*n)):n-36,l=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,l.length),u=.22*r,d=c<=1?0:(.78*r-u)/(c-1),h=o?Math.max(Math.round(.12*r),.08*r+6):Math.max(Math.round(.14*r),110);return{crashY:s-(o?Math.min(i,Math.max(3,.22*n)):i),floorY:s,gates:l.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(o?8:54,Math.round(.07*r))})),graveyardX:Math.round(r*(o?.72:.84)),graveyardY:s-4,height:n,routeY:a,socketX:Math.round(r*(o?.82:.92)),startX:h,width:r}}(e.size??[900,520],e.gates,e.crashOffset??30),i=e.positiveProperties??[],r=new Map(i.map(e=>[e.id,e])),n=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),o={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},a=(e.data??[]).map((t,a)=>{let s=function(e,t,i,r,n){let o=String(ig(e,t,i.idAccessor,null!=e.id?String(e.id):`project-${t}`)),a=r.map(e=>e.id),s=[...ig(e,t,i.positiveAccessor,a)],l=[...ig(e,t,i.negativeAccessor,[])].filter(e=>n.has(e));return{id:o,activePositiveIds:s,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...ig(e,t,i.metricsAccessor,{})},missingPositiveIds:a.filter(e=>!s.includes(e)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(ig(e,t,i.startTimeAccessor,0))||0),stage:"project filed",viability:ig(e,t,i.initialViability,100)}}(t,a,o,i,n);return{...s,viability:e.viability?.(s,{negativeProperties:n,positiveProperties:r})??dg(s,r,n)}}),s=a.flatMap((i,o)=>{let a=function(e,t,i,r){let n=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(i),o=r?.(e,t,i)??{};return{...n,...o,startY:o.startY??o.routeY??n.startY,socketY:o.socketY??o.routeY??n.socketY,graveyardY:o.graveyardY??n.graveyardY}}(i,o,t,e.projectPlacement);return function(e,t,i,r,n,o,a){let s=lg(i),l=Math.max(3,28*s),c=r.startX,u=r.startY+(r.startY===i.routeY?38*t*s:0),d=a?.(e,t,i,r)??{},h=d.x??c,p=d.y??u,f={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...d,id:rg(e.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??e.startedAt,datum:f}],m=cg(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,i);g[0].x=m.x,g[0].y=m.y;for(let t of e.activePositiveIds){let r=n.get(t);if(!r)continue;let o=ug(e.activePositiveIds,t,s),a=r.radius??Math.max(2,10*s),l=cg(m.x+Math.cos(o.angle)*o.radius,m.y+Math.sin(o.angle)*o.radius,a,i);g.push({id:ng(e.id,t),x:l.x,y:l.y,vx:18*Math.cos(o.angle),vy:18*Math.sin(o.angle),mass:r.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:r,sourceDatum:e.datum},springs:!1===r.spring?[]:[{target:{type:"body",bodyId:rg(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+o.index%2*4)*s),...r.spring??{}}]})}return e.negativeIds.forEach((t,r)=>{let n=o.get(t);n&&g.push(function(e,t,i,r,n,o,a){let s=lg(o),l=t.radius??Math.max(2,7.2*s),c=cg(r+(i%4*12-12)*s,n+(54+12*Math.floor(i/4))*s,l,o);return{id:og(e.id,t.id,i),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:a,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:rg(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+i%4*3)*s),...t.spring??{}}]}}(e,n,r,m.x,m.y,i,d.spawnAt??e.startedAt))}),g}(i,o,t,a,r,n,e.coreBody)});return{layout:t,states:a,initialSpawns:s,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:tg(t)}}}function pg(e=[]){let t=Object.create(null);for(let[i,r]of e)t[i]=r;return t}function fg(...e){let t=pg();for(let i of e)for(let[e,r]of Object.entries(i??{}))t[e]=r;return t}function gg(e){return fg(e)}function mg(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function yg(e){let t=pg(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:gg(t.initialMetrics),metrics:gg(t.metrics),productIds:[...t.productIds],history:mg(t.history)}])),i=pg(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:gg(t.metrics),sourceIds:[...t.sourceIds],history:mg(t.history)}])),r=pg(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?gg(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:i,relations:r,input:{amount:e.input.amount,metrics:gg(e.input.metrics)},metrics:gg(e.metrics),loss:{amount:e.loss.amount,metrics:gg(e.loss.metrics)},history:mg(e.history)}}var xg=1e-9;function bg(e,t){return e<t?-1:e>t?1:0}function vg(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function wg(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(bg)}function kg(e,t){return e?Object.entries(e).flatMap(([e,i])=>Number.isFinite(i)?[]:[vg("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function Sg(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}function Ag(e,t,i="selector"){let r=[],n=Object.values(e.components),o=new Set(n.map(e=>e.id)),a=(t.ids??[]).filter(e=>!o.has(e));if(a.length&&r.push(vg("error","unknown-component",`Selector references unknown component id${1===a.length?"":"s"}: ${a.join(", ")}.`,`${i}.ids`,a)),void 0!==t.count&&(!Number.isInteger(t.count)||t.count<0)&&r.push(vg("error","invalid-selector-count","Selector count must be a non-negative integer.",`${i}.count`)),r.some(e=>"error"===e.severity))return{ids:[],diagnostics:r};let s=t.ids?new Set(t.ids):null,l=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null,d=n.filter(e=>!s||s.has(e.id)).filter(e=>!l||l.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(bg);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||r.push(vg("warning","empty-selector","Selector matched no source components.",i)),{ids:d,diagnostics:r}}function Mg(e,t,i={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...i}}function $g(e,t){let i={...t,eventId:e.event.id};e.materializations.push(i),e.observations.push({...i,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function _g(e,t,i){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(vg("error","unknown-outlet",`Unknown outlet "${t}".`,i,[t])),1))}function Pg(e,t,i){let r=wg(t);t.length||e.diagnostics.push(vg("error","empty-source-list","A product requires at least one source component.",i)),r.length&&e.diagnostics.push(vg("error","duplicate-source",`Source ids may appear only once: ${r.join(", ")}.`,i,r));let n=t.filter(t=>!e.state.components[t]);n.length&&e.diagnostics.push(vg("error","unknown-component",`Unknown source component id${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n));let o=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);o.length&&e.diagnostics.push(vg("error","source-already-assigned",`Source component${1===o.length?" is":"s are"} already assigned: ${o.join(", ")}.`,i,o));let a=t.filter(t=>"consumed"===e.state.components[t]?.status&&!o.includes(t));return a.length&&e.diagnostics.push(vg("error","source-unavailable",`Consumed source component${1===a.length?" is":"s are"} unavailable: ${a.join(", ")}.`,i,a)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function Ig(e,t,i,r,n){let o=r?.amount??0;(!Number.isFinite(o)||o<0||o>t+xg)&&e.diagnostics.push(vg("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",`${n}.amount`)),e.diagnostics.push(...kg(r?.metrics,`${n}.metrics`));for(let[t,o]of Object.entries(r?.metrics??{}))(o<0||o>Number(i[t]??0)+xg)&&e.diagnostics.push(vg("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${n}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function Tg(e,t,i,r,n,o,a){let s=o&&void 0!==e.amount?e.amount:i;return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:s,metrics:o&&e.metrics?fg(r,e.metrics):gg(r),status:o?"complete":"forming",sourceIds:[...t],outletId:o?e.outletId??(n.outletIds.has("product")?"product":void 0):void 0,createdByEventId:n.event.id,createdAt:n.context.appliedAt,completedByEventId:o?n.event.id:void 0,completedAt:o?n.context.appliedAt:void 0,history:[a]}}function Lg(e,t,i,r){void 0!==t.amount&&Math.abs(t.amount-i)>xg&&e.diagnostics.push(vg("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${i}.`,r,[t.id]))}function Cg(e,t,i){let r=`events.${e.event.id}.effects.${i}`,n=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(vg("error","invalid-component-state",`set-state cannot assign "${String(t.state)}".`,`${r}.state`)),e.diagnostics.push(...kg(t.metricsDelta,`${r}.metricsDelta`)),_g(e,t.outletId,`${r}.outletId`);let i=Ag(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(vg("error","source-already-assigned",`Assigned source components cannot be retargeted: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=Mg(e,t,{sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0});for(let e of i.ids){let i=n.components[e];i.status=t.state,i.outletId=t.outletId,i.reason=t.reason,t.metricsDelta&&Sg(i.metrics,t.metricsDelta),i.history.push(a)}return n.history.push(a),void(i.ids.length&&$g(e,{type:"retarget-component",sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){let{relation:i}=t;(!i.id||n.relations[i.id])&&e.diagnostics.push(vg("error","duplicate-relation",`Relation id "${i.id}" is missing or already active.`,`${r}.relation.id`,[i.id]));let o=function(e,t,i){let r=wg(t),n=t.filter(t=>!e.state.components[t]);return t.length<2&&e.diagnostics.push(vg("error","insufficient-relation-sources","A relation requires at least two source components.",i)),r.length&&e.diagnostics.push(vg("error","duplicate-source",`Relation source ids must be unique: ${r.join(", ")}.`,i,r)),n.length&&e.diagnostics.push(vg("error","unknown-component",`Relation references unknown source component${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,i.sourceIds,`${r}.relation.sourceIds`);if(e.diagnostics.push(...kg(i.metrics,`${r}.relation.metrics`)),!o||e.diagnostics.some(e=>"error"===e.severity))return;n.relations[i.id]={...i,sourceIds:[...i.sourceIds],metrics:i.metrics?gg(i.metrics):void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};let a=Mg(e,t,{sourceIds:[...i.sourceIds],relationIds:[i.id]});return n.history.push(a),void $g(e,{type:"activate-relation",sourceIds:[...i.sourceIds],relationIds:[i.id]})}if("resolve-relation"===t.type){let i=wg(t.relationIds),o=t.relationIds.filter(e=>!n.relations[e]),a=t.relationIds.filter(e=>"resolved"===n.relations[e]?.status);if(i.length&&e.diagnostics.push(vg("error","duplicate-relation","Relation ids must be unique.",`${r}.relationIds`,i)),o.length&&e.diagnostics.push(vg("error","unknown-relation",`Unknown relation: ${o.join(", ")}.`,`${r}.relationIds`,o)),a.length&&e.diagnostics.push(vg("error","resolved-relation",`Relation is already resolved: ${a.join(", ")}.`,`${r}.relationIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let i of t.relationIds){let r=n.relations[i];r.status="resolved",r.resolution=t.resolution,r.resolvedByEventId=e.event.id,r.resolvedAt=e.context.appliedAt,r.reason=t.reason}let s=Mg(e,t,{relationIds:[...t.relationIds]});return n.history.push(s),void $g(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){let i=e.productDefinitions.get(t.productId);i||e.diagnostics.push(vg("error","unknown-product",`Product "${t.productId}" has no declared mold.`,`${r}.productId`,[t.productId]));let o=n.products[t.productId];"combine"===t.type&&o&&e.diagnostics.push(vg("error","duplicate-product",`Product "${t.productId}" has already been formed.`,`${r}.productId`,[t.productId])),"contribute"===t.type&&(!o||"forming"!==o.status)&&e.diagnostics.push(vg("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,`${r}.productId`,[t.productId]));let a=Pg(e,t.sourceIds,`${r}.sourceIds`),s="contribute"===t.type&&o?[...o.sourceIds,...t.sourceIds]:t.sourceIds,l=function(e,t,i,r){if(!t?.length)return[];let n=wg(t),o=t.filter(t=>!e.state.relations[t]),a=t.filter(t=>"resolved"===e.state.relations[t]?.status),s=new Set(i),l=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!s.has(e)));return n.length&&e.diagnostics.push(vg("error","duplicate-relation","Basis relations must be unique.",r,n)),o.length&&e.diagnostics.push(vg("error","unknown-relation",`Unknown basis relation: ${o.join(", ")}.`,r,o)),a.length&&e.diagnostics.push(vg("error","resolved-relation",`Basis relation is already resolved: ${a.join(", ")}.`,r,a)),l.length&&e.diagnostics.push(vg("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,r,l)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,s,`${r}.basisRelationIds`);if(!a||!l||!i||e.diagnostics.some(e=>"error"===e.severity))return;let c=a.reduce((e,t)=>e+t.amount,0),u=function(e){let t=pg();for(let i of e)Sg(t,i.metrics);return t}(a);if(!Ig(e,c,u,t.loss,`${r}.loss`))return;let d=c-(t.loss?.amount??0);!function(e,t,i){e.state.loss.amount+=i?.amount??0;for(let[r,n]of Object.entries(i?.metrics??{}))t[r]=Number(t[r]??0)-n,e.state.loss.metrics[r]=Number(e.state.loss.metrics[r]??0)+n}(e,u,t.loss);let h,p="combine"===t.type&&!1!==t.complete,f=Mg(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});if("combine"===t.type){if(p&&Lg(e,i,d,`${r}.productId`),h=Tg(i,t.sourceIds,d,u,e,p,f),p&&!_g(e,h.outletId,`${r}.productId`))return;n.products[t.productId]=h}else h=o,h.sourceIds.push(...t.sourceIds),h.amount+=d,Sg(h.metrics,u),h.history.push(f);for(let e of a)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(f);return n.history.push(f),function(e,t){if(t.length){for(let i of t)i.status="resolved",i.resolution="combined",i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt;$g(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,l),$g(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:h.outletId?[h.outletId]:void 0}),void(p&&$g(e,{type:"complete-product",sourceIds:[...h.sourceIds],productIds:[h.id],outletIds:h.outletId?[h.outletId]:void 0}))}if("complete-product"===t.type){let i=n.products[t.productId];return i?void function(e,t,i,r,n,o){let a=e.productDefinitions.get(t.id),s=i??a?.outletId??(e.outletIds.has("product")?"product":void 0);if(!_g(e,s,`${o}.outletId`))return;if("complete"===t.status)return void e.diagnostics.push(vg("error","product-already-complete",`Product "${t.id}" is already complete.`,o,[t.id]));a&&(Lg(e,a,t.amount,`${o}.productId`),void 0!==a.amount&&(t.amount=a.amount),a.metrics&&(t.metrics=fg(t.metrics,a.metrics))),t.status="complete",t.outletId=s,t.reason=r,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;let l=Mg(e,n,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0});t.history.push(l),e.state.history.push(l),$g(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0})}(e,i,t.outletId,t.reason,t,r):void e.diagnostics.push(vg("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,`${r}.productId`,[t.productId]))}if("split"===t.type){let i=Pg(e,[t.sourceId],`${r}.sourceId`);t.products.length||e.diagnostics.push(vg("error","empty-split","A split requires at least one product allocation.",`${r}.products`));let o=t.products.map(e=>e.productId),a=wg(o);a.length&&e.diagnostics.push(vg("error","duplicate-product","Split product ids must be unique.",`${r}.products`,a));let s=o.map(t=>e.productDefinitions.get(t)),l=o.filter((e,t)=>!s[t]),c=o.filter(e=>n.products[e]);l.length&&e.diagnostics.push(vg("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,`${r}.products`,l)),c.length&&e.diagnostics.push(vg("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,`${r}.products`,c));for(let[i,n]of t.products.entries())void 0!==n.amount&&(!Number.isFinite(n.amount)||n.amount<0)&&e.diagnostics.push(vg("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${r}.products.${i}.amount`)),e.diagnostics.push(...kg(n.metrics,`${r}.products.${i}.metrics`));if(!i?.length||e.diagnostics.some(e=>"error"===e.severity))return;let u=i[0];if(!Ig(e,u.amount,u.metrics,t.loss,`${r}.loss`))return;let d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??s[t]?.amount),p=h.filter(e=>void 0!==e).length;if(0!==p&&p!==h.length)return void e.diagnostics.push(vg("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",`${r}.products`));let f=p?h:t.products.map(()=>d/t.products.length),g=f.reduce((e,t)=>e+t,0);if(Math.abs(g-d)>xg)return void e.diagnostics.push(vg("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,`${r}.products`));let m=gg(u.metrics);for(let[e,i]of Object.entries(t.loss?.metrics??{}))m[e]=Number(m[e]??0)-i;let y=Mg(e,t,{sourceIds:[u.id],productIds:o});if(t.products.forEach((i,o)=>{let a=s[o],l=d>xg?f[o]/d:1/t.products.length,c=pg(Object.entries(m).map(([e,t])=>[e,t*l])),h=i.metrics??a.metrics??c,p=Tg({...a,amount:f[o],metrics:h},[u.id],f[o],gg(h),e,!0,y);_g(e,p.outletId,`${r}.products.${o}.productId`)&&(n.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=o,u.status="consumed",u.outletId=void 0,u.history.push(y),n.loss.amount+=t.loss?.amount??0;for(let[e,i]of Object.entries(t.loss?.metrics??{}))n.loss.metrics[e]=Number(n.loss.metrics[e]??0)+i;n.history.push(y),$g(e,{type:"split-source",sourceIds:[u.id],productIds:o});for(let t of o)$g(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:n.products[t].outletId?[n.products[t].outletId]:void 0});return}if("eject"===t.type){_g(e,t.outletId,`${r}.outletId`);let i=Ag(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(vg("error","source-already-assigned",`Assigned source components cannot be ejected: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=Mg(e,t,{sourceIds:i.ids,outletIds:[t.outletId]});for(let e of i.ids){let i=n.components[e];i.status=t.state??"ejected",i.outletId=t.outletId,i.reason=t.reason,i.history.push(a)}return n.history.push(a),void(i.ids.length&&$g(e,{type:"retarget-component",sourceIds:i.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...kg(t.metricsDelta,`${r}.metricsDelta`)),e.diagnostics.some(e=>"error"===e.severity))return;let i,o;if("run"===t.target)Sg(n.metrics,t.metricsDelta);else if("components"in t.target){let o=Ag(n,t.target.components,`${r}.target.components`);if(e.diagnostics.push(...o.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;i=o.ids;for(let e of o.ids)Sg(n.components[e].metrics,t.metricsDelta)}else{o=[...t.target.productIds];let i=wg(o),a=o.filter(e=>!n.products[e]);if(i.length&&e.diagnostics.push(vg("error","duplicate-product","Metric target product ids must be unique.",`${r}.target.productIds`,i)),a.length&&e.diagnostics.push(vg("error","unknown-product-state",`Metric target product has not formed: ${a.join(", ")}.`,`${r}.target.productIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let e of o)Sg(n.products[e].metrics,t.metricsDelta)}return void n.history.push(Mg(e,t,{sourceIds:i,productIds:o}))}t.outcome.trim()?(n.outcome=t.outcome,n.summary=t.summary,n.history.push(Mg(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(vg("error","invalid-outcome","Outcome must be a non-empty string.",`${r}.outcome`))}function Rg(e,t,i){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[vg("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,`events.${t.id}`,[t.id])]};let r=yg(e),n={state:r,event:t,context:i,productDefinitions:new Map(i.products.map(e=>[e.id,e])),outletIds:new Set(i.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(let[i,r]of t.effects.entries())if(Cg(n,r,i),n.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:n.diagnostics};return r.elapsed=Math.max(r.elapsed,i.appliedAt),r.phaseId=i.phaseId,r.eventsApplied.push(t.id),n.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:i.phaseId,authoredAt:i.authoredAt,appliedAt:i.appliedAt}),{applied:!0,state:r,materializations:n.materializations,observations:n.observations,diagnostics:n.diagnostics}}var Ng=st.width,Dg=st.height,Fg=[Ng,Dg],Eg=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Og=/*#__PURE__*/new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),zg=1e-9;function Bg(e,t){return e<t?-1:e>t?1:0}function jg(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function Wg(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(Bg)}function Yg(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function qg(e,t,i,r,n,o){if(!i)return r;try{return("function"==typeof i?i(e,t):e[i])??r}catch(e){return n.push(jg("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:String(e)}.`,o)),r}}function Xg(e,t,i){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(jg("error","invalid-metrics","Metrics must be a numeric object.",i)),pg();let r=pg();for(let[n,o]of Object.entries(e)){let e=Yg(o);null!=e?r[n]=e:t.push(jg("error","invalid-metric",`Metric "${n}" must be finite.`,`${i}.${n}`))}return r}function Gg(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Vg(e){let{id:t,orientation:i,fixed:r,start:n,end:o,openings:a,thickness:s,friction:l,restitution:c}=e,u=function(e,t,i){let r=i.map(([i,r])=>[Math.max(e,Math.min(i,r)),Math.min(t,Math.max(i,r))]).filter(([e,t])=>t>e+zg).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),n=[],o=e;for(let[e,t]of r)e>o+zg&&n.push([o,e]),o=Math.max(o,t);return t>o+zg&&n.push([o,t]),n}(n,o,a);return u.map(([e,n],o)=>({id:1===u.length?t:`${t}:${o}`,friction:l,restitution:c,shape:"horizontal"===i?{type:"segment",x1:e,y1:r,x2:n,y2:r,thickness:s}:{type:"segment",x1:r,y1:e,x2:r,y2:n,thickness:s}}))}function Hg(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?b(e):1}function Ug(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:Hg(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Zg(e){return`crucible:component:${encodeURIComponent(e)}`}function Kg(e){return`crucible:product:${encodeURIComponent(e)}`}function Qg(e,t,i,r){if(void 0!==i&&Number.isFinite(i)&&i>0)return i;let[n,o]=t;if(o-n<=zg)return(r[0]+r[1])/2;let a=Math.sqrt(Math.max(0,e-n)/(o-n));return r[0]+(r[1]-r[0])*a}function Jg(e,t){let i=Math.max(.25,Math.min(1,t.width/900,t.height/520)),r=e?.[0]??7*i,n=e?.[1]??18*i,o=Math.max(1,Math.min(r,n));return[o,Math.max(o,Math.max(r,n))]}function em(e,t){if(!e)return[];let i=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),r=Math.max(1,Math.ceil(e/i));return Array.from({length:e},(e,n)=>({x:t.x+(n%i+.5)*(t.width/i),y:t.y+(Math.floor(n/i)+.5)*(t.height/r)}))}function tm(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function im(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function rm(e,t,i={}){let r=Object.values(e.products).sort((e,t)=>Bg(e.id,t.id)),n=Object.values(e.components).sort((e,t)=>Bg(e.id,t.id)),o=le([...n.map(e=>e.amount),...r.map(e=>e.amount)]),a=Jg(i.radiusRange,t),s=function(e,t){let i=new Map;for(let t of e){let e=t.outletId??"__chamber__",r=i.get(e)??[];r.push(t),i.set(e,r)}let r=new Map;for(let[e,n]of i){n.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||Bg(e.id,t.id));let i=em(n.length,im(t,"__chamber__"===e?void 0:e));n.forEach((e,t)=>r.set(e.id,i[t]))}return r}(r,t),l=r.map(e=>{let r=s.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},n=1.28*Qg(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:Kg(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.018),bodyCollisions:!1,shape:{type:"circle",radius:n},datum:l}}),c=new Map;for(let e of n.filter(e=>!e.productIds.length)){let t=tm(e)??"__chamber__",i=c.get(t)??[];i.push(e),c.set(t,i)}let u=new Map;for(let[e,i]of c){let r=em(i.length,im(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>u.set(e.id,r[t]))}return[...n.map(e=>{let r=u.get(e.id);if(e.productIds.length){let i=e.productIds.map(e=>s.get(e)).filter(e=>!!e);if(i.length){r={x:i.reduce((e,t)=>e+t.x,0)/i.length,y:i.reduce((e,t)=>e+t.y,0)/i.length};let n=b(e.id)/4294967295*Math.PI*2,o=Math.min(20,Math.max(4,.012*t.width));r={x:r.x+Math.cos(n)*o,y:r.y+Math.sin(n)*o}}}r??(r={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});let n=Qg(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Zg(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.015),shape:{type:"circle",radius:n},datum:l}}),...l]}var nm=rm;function om(e){return Array.isArray(e)?e.map(om):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>Bg(e,t)).map(([e,t])=>[e,om(t)])):e}function am(e,t=e.duration){let i=function(e,t){let i=Yg(t)??0,r=Math.max(0,Math.min(e.duration,i));if(!e.phases.length)return{elapsed:r,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};let n=r>=e.duration-zg,o=n?e.phases[e.phases.length-1]:e.phases.find(e=>r>=e.start&&r<e.end)??e.phases[0];return{elapsed:r,phaseId:o.id,phaseIndex:o.index,phaseElapsed:n?o.duration:Math.max(0,r-o.start),complete:n}}(e,t),r=yg(e.initialState),n=[],o=[],a=[];for(let t of e.events){if(t.authoredAt>i.elapsed+zg)break;let s=Rg(r,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});n.push(...s.diagnostics),o.push(...s.materializations),a.push(...s.observations),s.applied&&(r=s.state)}return r.elapsed=i.elapsed,r.phaseId=i.phaseId,r.phaseIndex=i.phaseIndex,r.phaseElapsed=i.phaseElapsed,r.complete=i.complete,i.complete&&"in_process"===r.outcome&&(r.outcome="complete"),r.playing=!1,{state:r,diagnostics:n,materializations:o,observations:a}}function sm(e){let t=function(e){let t=[];e.length||t.push(jg("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));let i=Wg(e.map(e=>e.id));i.length&&t.push(jg("error","duplicate-phase-id",`Phase ids must be unique: ${i.join(", ")}.`,"phases",i));let r=0;return{phases:e.map((e,i)=>{let n=Yg(e.duration),o=null!=n&&n>0?n:0;e.id.trim()||t.push(jg("error","invalid-phase-id","Phase ids may not be empty.",`phases.${i}.id`)),(null==n||n<=0)&&t.push(jg("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${i}.duration`,[e.id])),void 0!==e.intensity&&!Number.isFinite(e.intensity)&&t.push(jg("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${i}.intensity`,[e.id]));let a={...e,duration:o,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:i,start:r,end:r+o};return r=a.end,a}),diagnostics:t}}(e.phases),i=t.phases.at(-1)?.end??0,r=Gg(e.outlets??Eg),n=(e.products??[]).map(e=>({...e,metrics:e.metrics?fg(e.metrics):void 0})),o=function(e,t,i){let r=[],n=Wg(e.map(e=>e.id));n.length&&r.push(jg("error","duplicate-event-id",`Event ids must be unique: ${n.join(", ")}.`,"events",n));let o=[];return e.forEach((e,n)=>{let a,s,l;if(e.id.trim()||r.push(jg("error","invalid-event-id","Event ids may not be empty.",`events.${n}.id`)),"time"in e.at&&void 0!==e.at.time){let o=Yg(e.at.time);if(null==o||o<0||o>i+zg)return void r.push(jg("error","event-time-out-of-range",`Event time must fall between 0 and ${i}.`,`events.${n}.at.time`,[e.id]));a=Math.max(0,Math.min(i,o));let c=function(e,t,i){let r=e.find(e=>Math.abs(e.start-i)<=zg);if(r)return{phase:r,boundaryRank:1};let n=e.find(e=>i>=e.start&&i<e.end);return n?{phase:n,boundaryRank:0}:Math.abs(i-t)<=zg&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,i,a);s=c.phase,l=c.boundaryRank}else{if(s=t.find(t=>t.id===e.at.phaseId),!s)return void r.push(jg("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${n}.at.phaseId`,[e.id,e.at.phaseId]));let i=e.at.progress??0;if(!Number.isFinite(i)||i<0||i>1)return void r.push(jg("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${n}.at.progress`,[e.id]));a=s.start+s.duration*i,l=0===i?1:0}s?o.push({...e,index:n,authoredAt:a,phaseId:s.id,phaseIndex:s.index,boundaryRank:l}):r.push(jg("error","event-without-phase","Event could not be assigned to a phase.",`events.${n}.at`,[e.id]))}),o.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:o,diagnostics:r}}(e.events??[],t.phases,i),a=function(e){let t=[],i=pg(),r=[],n=0,o=pg();e.data.forEach((a,s)=>{let l=String(a.id??`component-${s}`),c=qg(a,s,e.idAccessor,l,t,`data.${s}.id`),u=String(c??l).trim();if(!u)return void t.push(jg("error","invalid-component-id","Component ids may not be empty.",`data.${s}.id`));r.push(u);let d=Yg(qg(a,s,e.amountAccessor,1,t,`data.${s}.amount`)),h=null!=d&&d>=0?d:0;(null==d||d<0)&&t.push(jg("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${s}.amount`,[u]));let p=Xg(qg(a,s,e.metricsAccessor,{},t,`data.${s}.metrics`),t,`data.${s}.metrics`),f=qg(a,s,e.initialStateAccessor,"active",t,`data.${s}.status`),g=Og.has(f)?f:"active";Og.has(f)||t.push(jg("error","invalid-component-status",`Unknown component status "${String(f)}".`,`data.${s}.status`,[u]));let m=String(qg(a,s,e.labelAccessor,String(a.label??a.name??u),t,`data.${s}.label`)),y=String(qg(a,s,e.categoryAccessor,"component",t,`data.${s}.category`));Object.hasOwn(i,u)||(i[u]={id:u,label:m,category:y,datum:a,status:g,initialAmount:h,amount:h,initialMetrics:fg(p),metrics:fg(p),productIds:[],history:[]},n+=h,function(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}(o,p))});let a=Wg(r);a.length&&t.push(jg("error","duplicate-component-id",`Component ids must be unique: ${a.join(", ")}.`,"data",a));let s=Xg(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:i,products:pg(),relations:pg(),input:{amount:n,metrics:o},metrics:s,loss:{amount:0,metrics:pg()},history:[]},diagnostics:t}}(e),s=function(e=Fg,t=Eg){let i=Math.max(1,Yg(e[0])??Ng),r=Math.max(1,Yg(e[1])??Dg),n=i<360||r<260,o=n?Math.max(4,.035*Math.min(i,r)):20,a=n?Math.max(10,.075*r):34,s={x:o,y:o,width:Math.max(1,i-2*o),height:a},l=n?Math.max(16,.14*r):Math.min(78,.16*r),c={x:o,y:r-o-l,width:Math.max(1,i-2*o),height:l},u=n?Math.max(12,.08*i):Math.min(150,.17*i),d=s.y+s.height+(n?12:38),h=c.y-(n?10:34),p={x:u,y:d,width:Math.max(24,i-2*u),height:Math.max(24,h-d)},f=Math.max(18,Math.min(.32*p.width,n?84:180)),g={x:p.x+(p.width-f)/2,y:p.y-(n?10:24),width:f,height:n?12:28},m=Gg(t),y={left:m.filter(e=>"left"===(e.side??"bottom")),right:m.filter(e=>"right"===e.side),bottom:m.filter(e=>"bottom"===(e.side??"bottom"))},x=[],b=(e,t)=>{let r=Math.max(8,u-1.5*o),a=p.height/Math.max(1,t.length);t.forEach((t,s)=>{x.push({...t,side:e,x:"left"===e?o:i-o-r,y:p.y+s*a,width:r,height:Math.max(8,a-(n?2:8))})})};b("left",y.left),b("right",y.right);let v=p.width/Math.max(1,y.bottom.length);return y.bottom.forEach((e,t)=>{x.push({...e,side:"bottom",x:p.x+t*v,y:p.y+p.height+(n?2:7),width:Math.max(8,v-(n?2:8)),height:Math.max(8,c.y-p.y-p.height-(n?4:12))})}),x.sort((e,t)=>m.findIndex(t=>t.id===e.id)-m.findIndex(e=>e.id===t.id)),{width:i,height:r,phaseRail:s,chamber:p,mouth:g,projection:c,outlets:x}}(e.size??Fg,r),l=function(e){let{chamber:t,mouth:i}=e,r=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),n=Math.max(t.x,i.x),o=Math.min(t.x+t.width,i.x+i.width),a={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},s=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:n,y2:t.y,thickness:r}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:o,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:r}}];s.push(...Vg({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:a.left.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Vg({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:a.right.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Vg({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:a.bottom.map(e=>[e.x,e.x+e.width]),thickness:r,friction:.5,restitution:.08}));for(let t of e.outlets)s.push({id:`crucible:outlet:${encodeURIComponent(t.id)}`,sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return s}(s),c=function(e,t){let i=[],r=new Set(t.map(e=>e.id)),n=Wg(t.map(e=>e.id)),o=Wg(e.map(e=>e.id));return n.length&&i.push(jg("error","duplicate-outlet-id",`Outlet ids must be unique: ${n.join(", ")}.`,"outlets",n)),o.length&&i.push(jg("error","duplicate-product-id",`Product ids must be unique: ${o.join(", ")}.`,"products",o)),t.forEach((e,t)=>{e.id.trim()||i.push(jg("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0!==e.order&&!Number.isFinite(e.order)&&i.push(jg("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||i.push(jg("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0!==e.amount&&(!Number.isFinite(e.amount)||e.amount<0)&&i.push(jg("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0!==e.outletId&&!r.has(e.outletId)&&i.push(jg("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Xg(e.metrics??{},i,`products.${t}.metrics`)}),i}(n,r),u=function(e){return JSON.stringify(om(e))}({seed:e.seed??1,components:Object.values(a.state.components).sort((e,t)=>Bg(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})=>({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})),products:n,outlets:r,events:o.events.map(({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s})=>({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s}))}),d=function(e,t,i={}){let r=Object.values(e.components).sort((e,t)=>Bg(e.id,t.id)),n=le(r.map(e=>e.amount)),o=Jg(i.radiusRange,t),a=Z(Hg(i.seed)),s=t.mouth.x+t.mouth.width/2,l=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return r.map((e,t)=>{let d=t/Math.max(1,r.length)*Math.PI*2+.18*(a()-.5),h=Qg(e.amount,n,i.bodyRadius,o),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Zg(e.id),x:s+Math.cos(d)*c*(.45+.45*a()),y:l+Math.sin(d)*u*(.45+.45*a()),vx:24*(a()-.5),vy:18*(a()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(a.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),h=[...t.diagnostics,...o.diagnostics,...a.diagnostics,...c],p={phases:t.phases,events:o.events,products:n,outlets:r,duration:i,initialState:a.state,terminalState:a.state,layout:s,colliders:l,config:Ug(e.seed,l),initialSpawns:d,terminalSpawns:[],semanticKey:u,diagnostics:h},f=am(p),g=Object.values(f.state.products).filter(e=>"forming"===e.status).map(e=>e.id),m=g.length?[jg("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=f.state,p.terminalSpawns=nm(f.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p.diagnostics=[...h,...f.diagnostics,...m],p}import*as lm from"react";import{jsx as cm,jsxs as um}from"react/jsx-runtime";function dm(e){return Number.isFinite(e)?Math.abs(e)>=1e3?e.toLocaleString():Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):"0"}function hm(e,t,i,r){let n=e.datum;if(!n?.__crucible)return;let o="circle"===e.shape.type?e.shape.radius:8,a="string"==typeof t.fill?t.fill:"product"===n.kind?"#b8792d":"#356b63",s="string"==typeof t.stroke?t.stroke:"#26323a",l="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=r?`${r}-crucible-body-${i}`:`crucible-body-${i}`;if("product"===n.kind){let t=Array.from({length:6},(t,i)=>{let r=-Math.PI/2+i/6*Math.PI*2;return`${e.x+Math.cos(r)*o},${e.y+Math.sin(r)*o}`}).join(" "),i=`${u}-glow`;return um(lm.Fragment,{children:[cm("defs",{children:cm("filter",{id:i,x:"-60%",y:"-60%",width:"220%",height:"220%",children:cm("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:a,floodOpacity:"0.8"})})}),cm("polygon",{points:t,fill:a,stroke:s,strokeWidth:l,opacity:c,filter:`url(#${i})`}),cm("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*o),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return um(lm.Fragment,{children:[cm("circle",{cx:e.x,cy:e.y,r:o,fill:a,stroke:s,strokeWidth:l,opacity:c}),cm("circle",{cx:e.x-.25*o,cy:e.y-.28*o,r:Math.max(1,.18*o),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as pm,jsx as fm,jsxs as gm}from"react/jsx-runtime";var mm="var(--semiotic-text, #26323a)",ym="var(--semiotic-text-secondary, #6c7377)",xm="var(--semiotic-primary, #b8792d)",bm="var(--semiotic-danger, #9f3d35)",vm="var(--semiotic-success, #356b63)";function wm(e){let{x:t,y:i,width:r,height:n}=e.chamber,o=Math.min(.14*r,48),a=i+n;return[`M ${t} ${i}`,`L ${t+o} ${a-.16*n}`,`Q ${t+r/2} ${a+.1*n} ${t+r-o} ${a-.16*n}`,`L ${t+r} ${i}`].join(" ")}function km({layout:e,phases:t,state:i,compact:r=!1}){let n=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return gm("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[gm("defs",{children:[gm("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[fm("stop",{offset:"0",stopColor:xm,stopOpacity:"0.03"}),fm("stop",{offset:"0.66",stopColor:xm,stopOpacity:"0.1"}),fm("stop",{offset:"1",stopColor:bm,stopOpacity:"0.18"})]}),fm("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:fm("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:mm,strokeOpacity:"0.08",strokeWidth:"1"})})]}),fm("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:mm,strokeOpacity:"0.52",strokeWidth:r?1:2.2}),fm("path",{d:wm(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),fm("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:mm,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:r?2:5}),r?null:fm("g",{"data-testid":"crucible-phase-rail",children:t.map((r,o)=>{let a=t.slice(0,o).reduce((e,t)=>e+Math.max(0,t.duration),0),s=e.phaseRail.x+a/n*e.phaseRail.width,l=Math.max(0,r.duration)/n*e.phaseRail.width,c=r.id===i.phaseId,u=i.phaseIndex>o||i.complete;return gm("g",{children:[fm("rect",{x:s,y:e.phaseRail.y,width:Math.max(1,l-2),height:e.phaseRail.height,rx:2,fill:c?r.color??xm:u?vm:mm,fillOpacity:c?.68:u?.28:.09}),l>=46?fm("text",{x:s+l/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?mm:ym,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(r.label??r.id).toUpperCase()}):null]},r.id)})}),e.outlets.map(e=>gm("g",{children:[fm("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?bm:vm),fillOpacity:"0.1",stroke:e.color??("left"===e.side?bm:vm),strokeDasharray:"3 3",strokeOpacity:"0.62"}),r?null:fm("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:ym,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function Sm({rows:e,layout:t,projection:i,amountLabel:r}){if(!e.length)return null;let n=i.measure??"count",o=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,n))),a=o.reduce((e,t)=>Math.max(e,t),1),s=t.projection.width/Math.max(1,e.length),l=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-l-5);return fm("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,i)=>{let u=o[i],d=Math.max(u>0?2:0,u/a*c),h=t.projection.x+i*s+.18*s,p=t.projection.y+c-d;return gm("g",{children:[fm("rect",{x:h,y:p,width:Math.max(3,.64*s),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?bm:"complete"===e.status?xm:vm,fillOpacity:"0.68"}),l>4&&s>=34?gm(pm,{children:[fm("text",{x:h+.32*s,y:t.projection.y+c+10,fill:ym,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?`${e.label.slice(0,12)}…`:e.label}),gm("text",{x:h+.32*s,y:t.projection.y+c+19,fill:mm,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[dm(u),"amount"===n&&r?` ${r}`:""]})]}):null]},e.key)})})}function Am(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}import{Fragment as Mm,jsx as $m,jsxs as _m}from"react/jsx-runtime";function Pm(e,t,i,r,n){let o=Array.isArray(n)?n:n?[n]:[];if(!1!==i||0!==o.length)return({size:n})=>{let a=[Number(n[0])||700,Number(n[1])||420],s=K(a),l=Math.max(2,Math.round(t)),c=s.plot.width/l,u=s.plot.y+s.plot.height,d=e.reduce((e,t)=>Math.max(e,t.value),1),h=!1!==i,[p,f]=r?.valueExtent??[0,l],g=f===p?1:f-p,m=e.map((e,t)=>{let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;return`${0===t?"M":"L"} ${i.toFixed(1)} ${r.toFixed(1)}`}).join(" ");return _m("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:a[0],height:a[1],viewBox:`0 0 ${a[0]} ${a[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?_m(Mm,{children:[Array.from({length:l+1},(e,t)=>{let i=s.plot.x+t*c;return $m("line",{"data-testid":"galton-board-bin-wall",x1:i,x2:i,y1:s.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},`bin-wall-${t}`)}),$m("line",{x1:s.plot.x,x2:s.plot.x+s.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),$m("path",{d:m,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>{if(e.value<=0)return null;let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;return $m("text",{x:i,y:Math.max(s.plot.y+10,r-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`)})]}):null,o.map((e,t)=>{let i=Number(e.value);if(!Number.isFinite(i))return null;let r=Math.max(0,Math.min(1,(i-p)/g)),n=s.plot.x+r*s.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",l="bottom"===e.labelPosition?Math.min(a[1]-8,u+16):s.plot.y+16;return _m("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[$m("line",{x1:n,x2:n,y1:s.plot.y+8,y2:u-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:$m("text",{x:Math.min(s.plot.x+s.plot.width-4,n+6),y:l,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${i}`)})]})}}function Im(e,t,i,r){if(!1!==i&&!1!==r?.show&&t)return({size:i})=>{let r=[Number(i[0])||760,Number(i[1])||360],n=K(r),o=Math.max(1,t.windowCount),a=t.plot??n.plot,s=t.gutter??{x:a.x,y:a.y,width:0,height:a.height},l=t.windowPlot??a,c=l.width/o,u=a.y+a.height,d=a.y+.48*a.height,h=t.lidSegments[0]?.y1??d,p=t.windowStart,f=t.windowStart+o*t.windowSize,g=f===p?0:(t.watermarkValue-p)/(f-p),m=l.x+Math.max(0,Math.min(1,g))*l.width;return _m("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[$m("rect",{x:a.x,y:a.y,width:a.width,height:a.height,fill:"none",stroke:dh("border"),strokeOpacity:.7,strokeWidth:1}),s.width>0?$m("g",{children:_m("text",{x:s.x+s.width/2,y:h-8,textAnchor:"middle",fill:dh("lateFill"),fontSize:10,fontWeight:700,children:[t.lateCount," late"]})}):null,Array.from({length:o},(i,n)=>{let o=e[n],a=l.x+n*c,s=n<t.closedWindowCount;return _m("g",{children:[s?t.lidSegments.filter(e=>e.windowIndex===n).map(e=>$m("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:dh("closedWindowStroke"),strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,$m("text",{x:a+c/2,y:d-8,textAnchor:"middle",fill:dh("textSecondary"),fontSize:10,fontWeight:700,children:o?.value??0}),_m("text",{x:a+c/2,y:Math.min(r[1]-8,u+16),textAnchor:"middle",fill:dh("textSecondary"),fontSize:10,children:[c<45?$m("title",{children:o?.label??""}):null,c<45?t.windowStart+n*t.windowSize:o?.label??""]})]},`window-${n}`)}),t.windowWalls?.map(({id:e,...t})=>$m("rect",{...t,fill:dh("border"),fillOpacity:.68},e)),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>$m("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:dh("closedWindowStroke"),strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),$m("line",{x1:a.x,x2:a.x+a.width,y1:u,y2:u,stroke:dh("border"),strokeWidth:1.5}),$m("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:a.y+8,y2:u,stroke:dh("warning"),strokeDasharray:"5 4",strokeWidth:2}),_m("text",{x:Math.min(a.x+a.width-4,m+6),y:a.y+16,fill:dh("warning"),fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]})]})}}function Tm(e,t,i,r=1){if(!1!==i&&0!==e.length)return({size:i})=>{let n=[Number(i[0])||700,Number(i[1])||380],o=K(n),a=Df(o.plot,e.length,t),s=o.plot.y+o.plot.height;return _m("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[$m("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{let i=Math.min(o.plot.height,a.pileHeight(e.value/r)),l=a.tubeWidth,c=a.centerX(t),u=s-i;return _m("g",{children:[$m("rect",{x:c-l/2,y:u,width:l,height:i,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),$m("text",{x:c,y:Math.max(o.plot.y+12,u-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),$m("text",{x:c,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)}),$m("text",{x:n[0]/2,y:n[1]-2,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:`Full circle = ${r}; partial circles scaled by area`})]})}}function Lm(e){return Math.abs(e)>=1e3||Math.abs(e)<.01?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:2})}function Cm(e,t){if(!1!==t&&e)return({size:t})=>{let i=[Number(t[0])||700,Number(t[1])||360],r=K(i),n=r.plot.y+r.plot.height,[o,a]=e.xExtent,s=o+(a-o)/2,l=[{label:Lm(o),x:e.xRange[0]},{label:Lm(s),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:Lm(a),x:e.xRange[1]}];return _m("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.some(e=>e.overlapping)?$m("text",{"data-testid":"collision-swarm-overlap-warning",x:r.plot.x,y:Math.max(10,r.plot.y-9),fill:"var(--semiotic-warning, #b45309)",fontSize:10,children:i[0]<360?"Points overlap":"Points overlap. Reduce radius or increase height."}):null,e.groups.map(e=>_m("g",{children:[$m("line",{x1:r.plot.x,x2:r.plot.x+r.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),$m("text",{x:r.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),_m("text",{x:r.plot.x+r.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count,e.overlapping?" · overlaps":""]})]},e.label)),$m("line",{x1:e.xRange[0],x2:e.xRange[1],y1:n,y2:n,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(e=>_m("g",{children:[$m("line",{x1:e.x,x2:e.x,y1:n,y2:n+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),$m("text",{x:e.x,y:Math.min(i[1]-8,n+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}import{createElement as Rm}from"react";import{Children as Nm,cloneElement as Dm,isValidElement as Fm,useId as Em}from"react";function Om({children:e}){let t=Em().replace(/[^\w-]/g,"_"),i=new Map,r=(e,t=!1)=>{let o={...e};for(let[e,a]of Object.entries(o))o[e]="children"!==e||t?"style"===e&&!t&&a&&"object"==typeof a?r(a,!0):"string"==typeof a?qe(t?"style":e,a,i):a:n(a);return o},n=(e,o=!1)=>"object"!=typeof e?e:Nm.map(e,e=>Fm(e)?o?("string"==typeof e.props.id&&i.set(e.props.id,`${t}-${e.props.id}`),n(e.props.children,!0),e):Dm(e,r(e.props)):e);return n(e,!0),n(e)}import{Fragment as zm,jsx as Bm,jsxs as jm}from"react/jsx-runtime";var Wm={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}};function Ym(e){return 6.2*e.length}function qm(e,t){let i=e.trim();if(i.length<=t)return i;if(t<=1)return i.slice(0,1);let r=i.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return r.length>1&&r.length<=t?r:t<=3?i.slice(0,t).toUpperCase():`${i.slice(0,Math.max(1,t-2))}..`}function Xm(e,t,i="auto"){let r=Math.max(1,Math.floor(t/6.2)),n="compact"===i?qm(e,r):"full"===i||Ym(e)<=t?e:qm(e,r);return{text:n,textLength:Ym(n)>t?Math.max(4,t):void 0}}import{jsx as Gm}from"react/jsx-runtime";function Vm(e,t,i={},r){if(!1===t||!e)return;let{volume:n,stages:o,groups:a,groupCompletion:s}=e,l=new Map(n.stages.map(e=>[e.id,e])),c=new Map(s.map(e=>[e.id,e]));return({size:e})=>{let t=Number(e[0])||n.width,s=Number(e[1])||n.height,u=o.map(e=>{let t=l.get(e.id),r=i[`process-stage-${e.id}`];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:r?.queueDepth,processed:r?.processedCount}}),d=a.map(e=>{let t=c.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return function(e,t={}){let{showFlowSpine:i=!0,showStageCounts:r=!0,showCapacityBadges:n=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:s=!1,testId:l="process-flow-chrome"}=t,{width:c,height:u,left:d,right:h,topY:p,bottomY:f,midY:g,stages:m,groups:y=[]}=e,x=f-p;return Rm(Om,null,jm("svg",{"aria-hidden":"true","data-testid":l,"data-outline-stages":s?"true":void 0,width:c,height:u,viewBox:`0 0 ${c} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",s?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Bm("defs",{children:jm("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Bm("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Bm("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Bm("rect",{x:0,y:0,width:c,height:u,fill:"url(#semiotic-process-floor)"}),Bm("rect",{x:d-6,y:p-8,width:h-d+12,height:x+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),i?Bm("line",{x1:d+8,x2:h-8,y1:g,y2:g,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,m.map((e,t)=>{let i=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),o=Wm[i],l=Math.max(12,e.width-8),c=ol(l-8,22,88),d=Math.max(8,c-10),h=Xm(e.label,d,a),y="none"!==a&&l-8>=22,b=function(e){if(null!=e.capacity){let t=null!=e.queueDepth?` · q ${e.queueDepth}`:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?String(e.capacity):e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}(e),v=Xm(b,Math.max(16,l-10),"auto"),w=n&&!1!==e.showBadge&&l>=32,k=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",S=Xm(k,Math.max(16,l-8),"auto"),A=Math.max(30,p-15),M=A-13;return jm("g",{"data-stage":e.id,"data-role":i,children:[Bm("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:l,height:x-12,rx:10,fill:s?"none":o.fill,stroke:o.stroke,strokeWidth:s?1.85:"flow"===i?1:1.6}),t<m.length-1?Bm("polygon",{points:`${e.x1-2},${g-7} ${e.x1+8},${g} ${e.x1-2},${g+7}`,fill:o.accent,opacity:.85}):null,y?jm(zm,{children:[Bm("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-c/2,y:M,width:c,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),jm("text",{x:e.x,y:A,textAnchor:"middle",fill:o.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:h.textLength,lengthAdjust:h.textLength?"spacingAndGlyphs":void 0,children:[Bm("title",{children:e.label}),h.text]})]}):null,w?jm("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:v.textLength,lengthAdjust:v.textLength?"spacingAndGlyphs":void 0,children:[Bm("title",{children:b}),v.text]}):null,r&&null!=e.count?jm("text",{x:e.x,y:Math.min(u-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:S.textLength,lengthAdjust:S.textLength?"spacingAndGlyphs":void 0,children:[Bm("title",{children:k}),S.text]}):null]},e.id)}),o?y.map((e,t)=>{let i=e.total??0,r=e.absorbed??0,n=e.complete??(i>0&&r>=i),o=!n&&i>0&&r/i>=.75,a=n?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",s=n?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",l=i>0?`${r}/${i}${n?" shipped":o?" almost":""}`:`feature ${t+1}`,c=ol(Math.max(54,Ym(e.label)+18,Ym(l)+16),54,104),u=Xm(e.label,c-12,"auto"),d=Xm(l,c-12,"auto");return jm("g",{"data-group":e.id,children:[Bm("rect",{x:e.x-c/2,y:e.y-22,width:c,height:44,rx:10,fill:a,stroke:s,strokeWidth:1.5}),jm("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Bm("title",{children:e.label}),u.text]}),jm("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:s,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[Bm("title",{children:l}),d.text]})]},e.id)}):null]}))}({width:t,height:s,left:n.left,right:n.right,topY:n.topY,bottomY:n.bottomY,midY:n.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...r})}}function Hm(e,t,i){if(!1===i||!t||0===e.length)return;let r=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:i})=>{let n=[Number(i[0])||t.volume.width,Number(i[1])||t.volume.height],o=K(n),a=e.reduce((e,t)=>Math.max(e,t.value),1),s=Math.min(48,.18*o.plot.height),l=o.plot.y+6;return Gm("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,i)=>{let n=e[i];if(!n)return null;let o=r.get(t.id);if(!o)return null;let c=Math.max(2,n.value/a*s),u=Math.max(8,.35*o.width);return Gm("rect",{x:o.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}function Um(e){return Math.abs(e)>=1e3?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:1})}function Zm(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}import{jsx as Km,jsxs as Qm}from"react/jsx-runtime";function Jm(e,t){let{showNodeLabels:i,showSensors:r,showStaticFlow:n}=t;if(e&&(n||r||i))return({size:t})=>{let o=[Number(t[0])||760,Number(t[1])||420],a=e.links.reduce((e,t)=>Math.max(e,t.throughput),1),s=new Set(e.nodes.map(e=>e.sensorId));return Qm("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[n?e.links.map(e=>{let t=3+e.throughput/a*16,i=e.path[Math.floor(e.path.length/2)];return Qm("g",{children:[Km("path",{d:Zm(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),Km("path",{d:Zm(e.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),i?Km("text",{x:i.x,y:i.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:Um(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>Qm("g",{children:[r&&s.has(e.sensorId)?Km("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,n?Km("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,i?Km("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}import{Fragment as ey,jsx as ty,jsxs as iy}from"react/jsx-runtime";function ry({layout:e,compact:t,showLabels:i}){let r=t?Math.round(.14*e.height):Math.max(80,e.routeY-180),n=t?Math.max(6,Math.round(.72*e.height)):Math.min(360,e.height-170);return ty(ey,{children:e.gates.map(o=>iy("g",{children:[ty("rect",{x:o.x-o.width/2,y:r,width:o.width,height:n,rx:t?2:12,fill:o.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:o.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),i?ty("text",{x:o.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:o.label??o.id}):null]},o.id))})}function ny({layout:e,states:t,compact:i=!1}){return i?ty("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:ty(ry,{layout:e,compact:!0,showLabels:!1})}):iy("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ty("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),ty("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),ty("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),ty(ry,{layout:e,compact:!1,showLabels:!0}),iy("g",{children:[ty("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),ty("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),iy("g",{children:[ty("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),ty("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),ty("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function oy({states:e,layout:t}){let i=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!i.length)return null;let r=i.reduce((e,t)=>Math.max(e,t.value),1),n=Math.max(40,(t.width-80)/i.length);return iy("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ty("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),i.map((e,t)=>{let i=40+t*n,o=Math.max(2,e.value/r*28),a=/kill|crash|block|grave/i.test(e.outcome);return iy("g",{children:[ty("rect",{x:i+.18*n,y:28-o+22,width:Math.max(10,.45*n),height:o,rx:2,fill:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),ty("text",{x:i+.4*n,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}var ay={margin:(e,t)=>function(e,t){return e?"sparkline"===t?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}}(t.compactMode,e.mode)};function sy(e,t){return e?t?i=>Mh.createElement(Mh.Fragment,null,"function"==typeof e?e(i):e,"function"==typeof t?t(i):t):e:t}function ly(e,t,i){let r=t[i];return"boolean"==typeof r?r:!0!==e.__compactMode}var cy=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function uy(e){return cy[b(e)%cy.length]}var dy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a=n.bins??21,s=n.seed??1,l=Math.max(1,Math.round(n.pegRows??a-1)),c="mechanical"===(n.simulationMode??n.mode),u=function(e){let{data:t,valueAccessor:i,ballRadius:r,seed:n,size:o,valueExtent:a}=e,s=Number.isFinite(e.bins)?Math.max(1,Math.floor(e.bins)):1;if(!(Number.isFinite(r)&&r>0))throw new RangeError("Galton ballRadius must be finite and positive");let{rows:l}=C(t,"galton"),c=K(o),u=l.map((e,t)=>te(ee(e,t,i))).filter(e=>null!=e),d=I(a),[h,p]=d??(u.length?le(u):[0,1]),f=p===h?1:p-h,g=$h().domain([0,s]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:s},()=>0),y=[];l.forEach((e,t)=>{let n=te(ee(e,t,i));if(null==n)return;let o=Math.max(0,Math.min(s-1,Math.floor((n-h)/f*s)));m[o]+=1,y.push({id:String(e.id??`galton-${t}`),x:g(o+.5),y:c.plot.y+r+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,value:n,bin:o}})});let x=c.plot.y+c.plot.height,b=[...nf({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...of({idPrefix:"galton-bin",count:s,domainStart:0,domainStep:1,xScale:g,yTop:c.plot.y-400,yBottom:x,wallThickness:6})];return{config:J(n,b,"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:String(t+1),value:e})),metadata:{kind:"galton-board",bins:s,plot:c.plot,valueExtent:[h,p]}}}({data:c?L({bins:a,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:l,seed:s}):Array.isArray(e)?e:[],valueAccessor:n.valueAccessor||"value",bins:a,ballRadius:n.ballRadius??("sparkline"===n.mode?1.5:"context"===n.mode?4:6),seed:s,size:o,valueExtent:c?[0,l]:n.valueExtent});return{...r,config:u.config,initialSpawns:u.initialSpawns,initialSpawnPacing:u.initialSpawnPacing,projectionRows:u.projectionRows,foregroundGraphics:sy(Pm(u.projectionRows,a,ly(r,n,"showProjection"),u.metadata,n.referenceLines),r.foregroundGraphics),bodyStyle:Q(t||n.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},hy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{if(n.live||n.emitters)throw new Error("Live EventDrop requires React. Use finite replay data or export a saved physics snapshot.");let o=r.size??[600,400],a=Cf({data:Array.isArray(e)?e:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",arrival:n.arrival,watermarkAtArrivalAccessor:n.watermarkAtArrivalAccessor,sources:n.sources,sourceAccessor:n.sourceAccessor,sourceRail:n.sourceRail,timeUnit:n.timeUnit,windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??7,seed:n.seed??1,size:o,timeExtent:n.timeExtent,timeScale:n.timeScale??1}),s=function(e,t,i){if(!e||!1===t||!1===i?.show)return;let{plot:r,windowPlot:n,gutter:o,windowCount:a,windowSize:s,windowStart:l}=e,c=r.y+.48*r.height,u=r.y+r.height,d=e.lidSegments[0]?.y1??c,h=new Map(e.ledger?.map(e=>[e.start,e]));return ph("g",{"data-testid":"event-drop-window-background","aria-hidden":"true",children:[hh("rect",{x:o.x,y:d,width:o.width,height:u-d,fill:dh("gutterFill")}),Array.from({length:a},(t,r)=>{let o=r<e.closedWindowCount,d=l+r*s,p=d+s,f=h.get(d)??{windowId:`${d}-${p}`,start:d,end:p,accepted:0,late:0,bySource:{},open:!o},g="function"==typeof i?.fill?i.fill(f):i?.fill;return hh("rect",{x:n.x+r*n.width/a,y:c,width:n.width/a,height:u-c,fill:g??dh(o?"closedWindowFill":"openWindowFill")},d)})]})}(a.metadata,ly(r,n,"showProjection"),n.windowChrome);return{...r,backgroundGraphics:sy(r.backgroundGraphics,s),backgroundGraphicsBackdrop:r.backgroundGraphicsBackdrop??(s&&!r.backgroundGraphics?r.background??dh("background"):void 0),config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,eventDropMetadata:a.metadata,foregroundGraphics:sy(Im(a.projectionRows,a.metadata,ly(r,n,"showProjection"),n.windowChrome),sy(kh(n.sources,n.sourceRail,o),r.foregroundGraphics)),bodyStyle:Ah(n.sources,t||n.colorBy,{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},py={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a="mechanical"===(n.simulationMode??n.mode),s=function(e){let{data:t,categoryAccessor:i,valueAccessor:r,unitValue:n,ballRadius:o,seed:a,size:s}=e,l=P(n,1),{rows:c}=C(t,"pile"),u=K(s),d=[],h=new Map,p=new Map,f=[];function g(e){let t=h.get(e);return null==t&&(t=d.length,d.push(e),h.set(e,t)),t}c.forEach((e,t)=>{g(String(ee(e,t,i)??"unknown"))});let m=Math.max(1,d.length),y=Df(u.plot,m,o),x=Math.max(0,y.tubeWidth/2-o-1),b=d.map(()=>[]);c.forEach((e,t)=>{let n=String(ee(e,t,i)??"unknown"),a=g(n),s=r?te(ee(e,t,r)):1,c=Math.max(0,s??0);p.set(n,(p.get(n)??0)+c);let d=D(c,l),h=y.centerX(a);for(let i=0;i<d;i+=1){let r=b[a].length,s=i===d-1?c-i*l:l,p=Math.min(1,s/l),f=y.perRow>1?r%y.perRow:0,g=y.perRow>1?(f/(y.perRow-1)*2-1)*x:0;b[a].push({id:`${String(e.id??`pile-${t}`)}-${i}`,x:h+g,y:u.plot.y+o+2,vx:(i%3-1)*o/2,vy:0,mass:1,shape:{type:"circle",radius:o*Math.sqrt(p)},datum:{...e,category:n,unitIndex:i,unitValue:l,representedValue:s,unitFraction:p}})}});let v=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;e<v;e+=1)for(let t of b)e<t.length&&f.push(t[e]);let w=u.plot.y+u.plot.height,k=[...nf({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],S=u.plot.y-400;for(let e=0;e<m;e+=1){let t=y.centerX(e);for(let i of[-1,1])k.push({id:`pile-tube-${e}-${i<0?"l":"r"}`,shape:{type:"aabb",x:t+i*(y.tubeWidth+6)/2,y:(S+w)/2,width:6,height:w-S}})}return{config:J(a,k,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:p.get(e)??0}))}}({data:a?N({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(a?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??8,seed:n.seed??1,size:o});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,foregroundGraphics:sy(Tm(s.projectionRows,n.ballRadius??8,ly(r,n,"showProjection"),Number.isFinite(n.unitValue)&&n.unitValue>0?n.unitValue:1),r.foregroundGraphics),bodyStyle:Q(t||n.colorBy||(a?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},fy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,360],a=function(e){let{data:t,xAccessor:i,groupAccessor:r,radiusAccessor:n,pointRadius:o,seed:a,size:s,xExtent:l,collisionIterations:c,settle:u}=e,{rows:d}=C(t,"collision-swarm"),h=K(s),p=Z(a),f=[],g=[],m=new Map;d.forEach((e,t)=>{let a=te(ee(e,t,i));if(null==a)return;let s=r?String(ee(e,t,r)??"All"):"All",l=n?te(ee(e,t,n)):null,c=_(null!=l&&l>0?l:o,2,18);(function(e){let t=m.get(e);null==t&&(t=g.length,g.push(e),m.set(e,t))})(s),f.push({datum:e,index:t,value:a,group:s,radius:c})});let y=l?te(l[0]):null,x=l?te(l[1]):null,b=f.reduce((e,t)=>Math.min(e,t.value),f.length?1/0:0),v=f.reduce((e,t)=>Math.max(e,t.value),f.length?-1/0:1),w=y??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){let e=k;k=w,w=e}let S=f.reduce((e,t)=>Math.max(e,t.radius),o),A=h.plot.x+S+8,M=h.plot.x+h.plot.width-S-8,$=Ff().domain([w,k]).range([A,M]),P=Math.max(1,g.length),I=h.plot.height/P,T=Math.min(6,.05*I),L=e=>h.plot.y+((m.get(e)??0)+.5)*I,R=new Map,N=new Set,D=new Map;for(let e of g){let t=f.filter(t=>t.group===e),i=L(e),r=t.map(e=>({x:$(e.value),radius:e.radius})),n=Ef(r,i-I/2+T,i+I/2-T,p);R.set(e,t.length),n.overlapping&&N.add(e),t.forEach((e,t)=>D.set(e.index,{x:r[t].x,y:n.positions[t],entryOffset:n.entryOffset}))}let F=f.map((e,t)=>{let i=D.get(e.index),r=i.x,n=i.y,o=N.has(e.group);return{id:String(e.datum.id??`collision-swarm-${t}`),x:r,y:n-(u?0:i.entryOffset),vx:0,vy:0,fixedPosition:{x:r},bodyCollisions:!o,mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:r,targetY:n,overlapping:o},springs:[{target:{type:"point",x:r,y:n},restLength:0,stiffness:34,damping:12}]}}),E=nf({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20});return{config:J(a,E,"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:F,projectionRows:g.map(e=>({label:e,value:R.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:g.map(e=>({label:e,y:L(e),count:R.get(e)??0,overlapping:N.has(e)})),plot:h.plot}}}({data:Array.isArray(e)?e:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:o,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:sy(Cm(a.metadata,ly(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:Q(t||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},gy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,420],a=Array.isArray(n.stages)?n.stages:[],s=function(e){let t=e.stages;if(!t.length)throw new Error("buildProcessFlowPhysics requires at least one stage");let i=e.size,r=K(i),n=_(e.ballRadius??6,2,18),o=e.seed??1,a=Z(o),s=e.idAccessor,l=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(c?"allAbsorbed":"none"),f=e.springStiffness??.28,g=e.springDamping??.72,m=!0===e.settle,y=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),x=Gf({width:i[0],height:i[1],shape:"lane",padX:Math.max(28,r.plot.x),padY:Math.max(36,r.plot.y+8),stages:y,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,k=x.stages[0],S=new Set(t.filter(e=>e.absorb).map(e=>e.id)),A=t.map(e=>{let t=v.get(e.id)??k;return function(e,t){let i={id:`process-stage-${e.id}`,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return function(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...Hf(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}({...i,kind:e.kind??"sink",force:Zf(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...i.attributes,primitive:"absorb"}});if(e.portal){let t=e.portal.force??e.force??{x:-40,y:0};return function(e){return{...Hf(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}({...i,kind:e.kind??"force-field",force:Zf(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...i.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){let t=Math.max(.1,e.capacity.unitsPerSecond);return function(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...Hf(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}({...i,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Zf(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...i.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){let t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return function(e){let t=e.pressure??e.occupancy??0,i=e.baseDamping??.08,r=e.dampingPerUnit??.12,n=e.energyPerUnit??0;return{...Hf(e,"membrane","pressureField",{pressure:t}),damping:i+t*r,energyDelta:n?-t*n:void 0,force:e.force}}({...i,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Zf(e.force,8),attributes:{...i.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?Uf({...i,kind:e.kind??"force-field",force:Zf(e.force,14),damping:e.damping??.02,attributes:{...i.attributes,primitive:"routeSurface"}}):function(e){return{...Hf(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}({...i,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...i.attributes,primitive:"forceField"}})}(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});A.unshift(Uf({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));let M=new Map;for(let e of x.stages)M.set(e.id,0);let $=[];e.data.forEach((e,t)=>{let i=String(s?ee(e,t,s)??e.id??`process-flow-${t}`:e.id??`process-flow-${t}`),r=String(ee(e,t,l)??w),o=b.has(r)?r:w;M.set(o,(M.get(o)??0)+1);let a=c?String(ee(e,t,c)??""):void 0,p=a&&u?String(ee(e,t,u)??a):a,f=d?te(ee(e,t,d))??1:1,g=h?te(ee(e,t,h)):null,m=_(null!=g&&g>0?g:n,2,18);$.push({datum:e,id:i,stageId:o,groupId:a||void 0,groupLabel:p||void 0,work:f,radius:m,index:t})});let P=new Map,I=new Map;for(let e of $){if(!e.groupId)continue;let t=P.get(e.groupId)??[];t.push(e.id),P.set(e.groupId,t),e.groupLabel&&I.set(e.groupId,e.groupLabel)}let T=_(e.groupAnchorAlong??.55,.15,.9),L=x.left+(x.right-x.left)*T,C=Array.from(P.keys()),R=C.map((e,i)=>{let r=P.get(e)??[],n=C.length<=1?x.midY:x.topY+28+i/Math.max(1,C.length-1)*(x.bottomY-x.topY-56);return function(e){let t=e.x??e.anchor?.x??0,i=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:i,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:i},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}({id:e,label:I.get(e)??e,bodyIds:r,anchor:{x:L,y:n},x:L,y:n,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),N=function(e,t){let i=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],r=t.filter(e=>!i.has(e)),n=t.length-r.length,o=e.completion?.mode??"allMembersAbsorbed",a=e.completion?.valueByBodyId,s=e=>{let t=a?function(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}(a,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},l=t.reduce((e,t)=>e+s(t),0),c=t.reduce((e,t)=>e+(i.has(t)?s(t):0),0),u=e.completion?.threshold,d="threshold"===o?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0,h=t.length>0&&("anyAbsorbed"===o?n>0:"threshold"===o?c>=(d??l):0===r.length);return{id:e.id,label:e.label??e.id,mode:o,complete:h,absorbed:n,total:t.length,absorbedValue:c,totalValue:l,threshold:d,missing:r}})}(R,$.filter(e=>S.has(e.stageId)).map(e=>e.id)),D=new Map(R.map(e=>[e.id,e])),F=$.map((e,t)=>{let i=v.get(e.stageId)??k,r=i.x+(a()-.5)*Math.min(24,.2*i.width),n=x.boundaryY(r,"top")+e.radius+10,o=x.boundaryY(r,"bottom")-e.radius-10,s=o<=n?x.midY:n+a()*Math.max(1,o-n),l=m?r:x.left+18+t%7*4,c=m?s:x.midY+(a()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:r,y:s},restLength:.45*e.radius,stiffness:f,damping:g}];if(e.groupId){let t=D.get(e.groupId);t?.anchor&&!S.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:l,y:c,vx:m?0:40+40*a(),vy:m?0:20*(a()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:m?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),E={kernel:{seed:o,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},O=x.stages.map(e=>({label:e.label??e.id,value:M.get(e.id)??0})),z=t.map(e=>{let t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:M.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:E,initialSpawns:F,initialSpawnPacing:m?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:O,metadata:{kind:"process-flow",plot:r.plot,volume:x,stages:z,groups:R,groupCompletion:N,regionEffects:A}}}({data:Array.isArray(e)?e:[],stages:a,size:o,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),l=s.metadata;return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,regionEffects:l?.regionEffects,backgroundGraphics:sy(Vm(s.metadata,ly(r,n,"showChrome"),{},n.chromeOptions),r.backgroundGraphics),foregroundGraphics:sy(Hm(s.projectionRows,s.metadata,ly(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:Q(t||n.colorBy||n.groupBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.workAccessor||n.stageAccessor||"stage"})}}},my={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=hg({data:Array.isArray(e)?e:[],size:o,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...r,config:a.config,initialSpawns:a.initialSpawns,projectionRows:[],backgroundGraphics:sy(ly(r,n,"showChrome")?Mh.createElement(ny,{layout:a.layout,states:a.states,compact:!0===r.__compactMode}):void 0,r.backgroundGraphics),foregroundGraphics:sy(ly(r,n,"showProjection")?Mh.createElement(oy,{layout:a.layout,states:a.states}):void 0,r.foregroundGraphics),bodyStyle:Q(t||n.colorBy)}}},yy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=sm({data:Array.isArray(e)?e:[],phases:Array.isArray(n.phases)?n.phases:[],products:Array.isArray(n.products)?n.products:void 0,outlets:Array.isArray(n.outlets)?n.outlets:void 0,events:Array.isArray(n.events)?n.events:void 0,idAccessor:n.idAccessor,labelAccessor:n.labelAccessor,categoryAccessor:n.categoryAccessor,amountAccessor:n.amountAccessor,metricsAccessor:n.metricsAccessor,initialStateAccessor:n.initialStateAccessor,metrics:n.metrics,size:o,seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange}),s="snapshot"===n.playback?function(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,Yg(t)??0));let i=e.phases.find(e=>e.id===t.phaseId);if(!i)return e.duration;let r=Math.max(0,Math.min(1,Yg(t.progress??0)??0));return i.start+i.duration*r}(a,n.snapshotAt):a.duration,l=am(a,s).state,c=n.projection&&"object"==typeof n.projection?n.projection:{groupBy:"outlet",measure:"count"},u=function(e,t={}){let i=t.groupBy??"outlet",r=new Map,n=e=>{let t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},i),n=r.get(t);if(n)return n.count+=1,n.amount+=e.amount,void Sg(n.metrics,e.metrics);r.set(t,{key:t,label:"product"===i&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:gg(e.metrics),status:"status"===i?e.status:void 0,outletId:"outlet"===i?e.outletId:void 0,category:"category"===i?e.category:void 0,productId:"product"===i&&"product"===e.kind?e.id:void 0})};for(let t of Object.values(e.components))t.productIds.length||"consumed"===t.status||n({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(let t of Object.values(e.products))n({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});let o=new Map((t.order??[]).map((e,t)=>[e,t]));return[...r.values()].sort((e,t)=>(o.get(e.key)??Number.MAX_SAFE_INTEGER)-(o.get(t.key)??Number.MAX_SAFE_INTEGER)||bg(e.key,t.key))}(l,c),d=c.measure??"count",h=function(e,t={}){let i=t.bodies??[],r=Math.max(0,t.recentBodyLimit??6),n=new Map;for(let e of i){let i=t.getContainerId?.(e);if(!i)continue;let r=n.get(i);r?r.push(e):n.set(i,[e])}let o=e.map(e=>{let i=n.get(e.id)??[],o=Math.max(0,Math.floor(e.count??i.length)),a=i.slice(Math.max(0,i.length-r)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??Am(e),datum:e.datum}));return{id:e.id,label:e.label,count:o,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:i.map(e=>e.id),recentBodies:a,metadata:e.metadata}}),a=o.reduce((e,t)=>e+t.count,0);return o.map(e=>({...e,share:a>0?e.count/a:0}))}(u.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===d||"amount"===d?e.amount:Number(e.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?n.amountLabel??"amount":d,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),p={seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange},f=t??n.colorBy??"category",g=!1===n.showChrome?null:Mh.createElement(km,{layout:a.layout,phases:a.phases,state:l,compact:o[0]<520||o[1]<360}),m=!1===n.showProjection?null:Mh.createElement(Sm,{rows:u,layout:a.layout,projection:c,amountLabel:n.amountLabel});return{...r,config:a.config,initialSpawns:rm(l,a.layout,p),projectionRows:h,bodyStyle:e=>function(e,t,i,r){let n=e.datum,o={stroke:r.stroke??("product"===n?.kind?"#fffaf0":"#26323a"),strokeWidth:r.strokeWidth??("product"===n?.kind?1.8:1.1),opacity:r.opacity??.96};if(!n?.__crucible)return{...o,fill:r.color??"#b8792d"};if("product"===n.kind){let e=t.products[n.semanticId];return{...o,fill:r.color??e?.color??uy(e?.id??n.semanticId)}}let a,s=t.components[n.semanticId];return s?(a="status"===i?s.status:"outlet"===i?s.outletId??"in chamber":"product"===i?s.productIds[0]??"unalloyed":"category"===i||null==i?s.category:String("function"==typeof i?i(s.datum)??"unassigned":s.datum[String(i)]??"unassigned"),{...o,fill:r.color??uy(a)}):{...o,fill:r.color??"#356b63"}}(e,l,f,n),getBodyLabel:e=>function(e,t){let i=e.datum;if(i?.__crucible)return"product"===i.kind?t.products[i.semanticId]?.label:t.components[i.semanticId]?.label}(e,l),renderBodySVG:hm,backgroundGraphics:sy(g,r.backgroundGraphics),foregroundGraphics:sy(m,r.foregroundGraphics)}}},xy={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[760,420],a=function(e){let{coordinateMode:t,flowSpeed:i,links:r,maxParticles:n,nodeIdAccessor:o,nodeXAccessor:a,nodeYAccessor:s,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:p,seed:f,size:g,sourceAccessor:m,targetAccessor:y,throughputAccessor:x}=e,b=K(g),v=Z(f),w=new Map,k=new Map,S=[];function A(e){if(e&&"object"==typeof e){let t=e;if("function"==typeof o){let e=o(t,0);if(null!=e)return String(e)}if("string"==typeof o&&null!=t[o])return String(t[o]);if(null!=t.id)return String(t.id)}return String(e??"unknown")}l.forEach((e,t)=>{let i=String(ee(e,t,o)??e.id??t),r=te(ee(e,t,a)),n=te(ee(e,t,s));if(null!=r&&null!=n){let e={x:r,y:n};w.set(i,e),S.push(e)}k.set(i,String(e.label??e.name??i))});let M=[];r.forEach((e,t)=>{let i=A(ee(e,t,m)),r=A(ee(e,t,y)),n=Math.max(0,te(ee(e,t,x))??0),o=zf(d?ee(e,t,d):void 0),a=o.length?o:zf(e.path??e.points??e.route);a.forEach(e=>S.push(e)),M.push({id:String(e.id??`physical-flow-${i}-${r}-${t}`),link:e,index:t,source:i,target:r,throughput:n,rawPath:a})});let $=function(e,t){return"normalized"===e||"pixels"===e?e:t.length>0&&t.every(e=>e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1)?"normalized":"pixels"}(t,S),I=new Map;for(let[e,t]of w)I.set(e,Bf(t,b,$));let L=[];for(let e of M){let t=e.rawPath.map(e=>Bf(e,b,$));if(t.length>=2)I.has(e.source)||I.set(e.source,t[0]),I.has(e.target)||I.set(e.target,t[t.length-1]);else{let i=I.get(e.source),r=I.get(e.target);i&&r&&(t=[i,r])}t.length<2||e.throughput<=0||(k.has(e.source)||k.set(e.source,e.source),k.has(e.target)||k.set(e.target,e.target),L.push({...e,path:t,packetCount:0}))}let C=P(u,.12),R=Math.max(1,Math.round(n)),N=L.map(e=>Math.max(1,Math.round(e.throughput*C))),D=N.reduce((e,t)=>e+t,0),F=D>R?R/D:1;L.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(N[t]*F))});let E=L.reduce((e,t)=>e+t.packetCount,0);for(;E>R;){let e=L.reduce((e,t,i)=>t.packetCount<=1?e:-1===e||t.packetCount>L[e].packetCount?i:e,-1);if(-1===e)break;L[e].packetCount-=1,E-=1}let O=new Map,z=new Map,B=[],j=P(i,90),W=P(c,4);L.forEach((e,t)=>{O.set(e.target,(O.get(e.target)??0)+e.throughput),z.set(e.source,(z.get(e.source)??0)+e.throughput);let i=jf(e.path);for(let r=0;r<e.packetCount;r+=1){let n=(r+.5)/e.packetCount,o=p?n:_(.12+.84*n+.04*(v()-.5),.04,.98),a=p?o:Math.max(0,o-(.18+.12*v())),s=Wf(e.path,a),l=Wf(e.path,o),c=Yf(e.path,a),u={x:-c.y,y:c.x},d=(v()-.5)*W*1.5,f=`${e.id}-packet-${r}`;B.push({id:f,x:s.x+u.x*d,y:s.y+u.y*d,vx:p?0:c.x*j+10*(v()-.5),vy:p?0:c.y*j+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+r/32,shape:{type:"circle",radius:W},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:r,packetCount:e.packetCount,routeProgress:o,flowPath:e.path,flowPathLength:i,flowRouteId:e.id,flowSpeed:j,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});let Y=Math.max(18,5*W),q=Array.from(I,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:`physical-flow-node-${T(e)}`,point:t})),X=q.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:Y,height:Y}})),G=Object.fromEntries(q.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),V=[...nf({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],H=J(f,V,"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=R,H.eviction="oldest",H.observation={...H.observation,sensors:G};let U=Array.from(I,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:`physical-flow-node-${T(e)}`,incoming:O.get(e)??0,outgoing:z.get(e)??0})),Q=L.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:H,initialSpawns:B,projectionRows:U.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:$,particleCount:B.length,totalThroughput:L.reduce((e,t)=>e+t.throughput,0),plot:b.plot,nodes:U,links:Q}}}({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(e)?e:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:o});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:sy(Jm(a.metadata,{showNodeLabels:!1!==n.showNodeLabels,showSensors:!1!==n.showSensors,showStaticFlow:!1!==n.showStaticFlow}),r.foregroundGraphics),bodyStyle:Q(t||n.colorBy||"source")}}},by={frameType:"physics",layout:ay,buildProps:(e,t,i,r,n)=>{let o=r.size??[700,380],a=$i(r.theme),s=function(e){let t=function(e,t,i){let r=e?.observation;return{...e,observation:{...r,chartId:t??r?.chartId??"physics-custom",chartType:r?.chartType??"PhysicsCustomChart",onObservation:i??r?.onObservation}}}(e.config,e.chartId,e.onObservation),i=Qf(e.colorScheme,e.themeCategorical,Tt),r=K(e.size),n={data:e.data,scales:{x:Kf().domain(e.xExtent??[0,1]).range([r.plot.x,r.plot.x+r.plot.width]),y:Kf().domain(e.yExtent??[0,1]).range([r.plot.y+r.plot.height,r.plot.y])},dimensions:r,theme:{semantic:e.semantic,categorical:[...i]},resolveColor:Jf(i,e.colorScheme),config:e.layoutConfig??{},world:new Tf(t)},o=e.skipLayout?{}:e.layout(n)??{},a=function(e,t){if(!t?.length)return e;let i=new Map;for(let e of t){let{bodyId:t,...r}=e,n=i.get(t)??[];n.push(r),i.set(t,n)}return e.map(e=>{let t=i.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...o.initialSpawns??o.bodies??[]],o.constraints);return{config:eg(t,o),context:n,initialSpawnPacing:o.initialSpawnPacing,initialSpawns:a,result:o}}({chartId:n.chartId,colorScheme:i,config:n.config,data:Array.isArray(e)?e:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:M(a)??{},size:o,themeCategorical:a.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:[],bodyStyle:s.result.bodyStyle??Q(t||n.colorBy),backgroundGraphics:sy(r.backgroundGraphics,s.result.backgroundOverlays),foregroundGraphics:sy(r.foregroundGraphics,s.result.overlays)}}};function vy(e){return e&&{fields:["nodeId"],..."object"==typeof e?e:{name:"string"==typeof e?e:"hover"}}}function wy(e){let t=e.roles.occurrence;return"string"==typeof t?[t]:e.entityIds}function ky(e,t=[],i){let r=void 0===i?void 0:new Set("string"==typeof i?[i]:i),n=t.filter(e=>!e.missingPrehistory&&void 0!==e.partition&&r?.has(e.partition)),o=new Set(n.map(e=>e.id)),a=new Set(n.map(e=>e.entityId)),s=new Map,l=0;for(let t of e){if(void 0!==i&&"string"==typeof t.roles.occurrence&&!o.has(t.roles.occurrence))continue;let e=Object.entries(t.entityWeights);0===e.length&&void 0===i&&(l+=t.entityCount);for(let[t,r]of e)(void 0===i||a.has(t))&&s.set(t,r)}return[...s.values()].reduce((e,t)=>e+t,l)}function Sy(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}function Ay(e,t){return e.slice(0,t+1).map(e=>e.replaceAll("%","%25").replaceAll(">","%3E")).join(">")}function My(e,t,i){return e.entries.find(e=>e.measureId===t&&e.subjectId===i)}function $y(e,t,i){return 0===i||1e4*e%i!=0?Math.round((t-e)/Math.max(i,1)*1e4):1e4*(t-e)/i}function _y(e,t={}){let i=t.templates??["repeated-state-episode"],r="ordinal"===e.spec.coordinate.kind?e.spec.coordinate.sectionIds:[],n=void 0!==t.partition?function(e,t){let i=e.spec.comparison?.denominatorMeasureId??e.spec.motifs.denominatorRef??"assigned";return My(e.ledger,i,t)?.value}(e,t.partition)??0:e.spec.comparison?e.comparison?.rows.reduce((e,t)=>e+t.assigned,0)??0:e.ledger.entries.find(t=>"global"===t.subjectKind&&t.measureId===e.spec.motifs.denominatorRef)?.value??0,o=i=>ky(i,e.source.occurrences,t.partition??e.spec.comparison?.partitions),a=[],s=e.motifs.incompleteCandidates.length>0;for(let l of i)for(let i of r){let r=e.motifs.matches.filter(e=>e.template===l),c=o(r.filter(e=>e.completionSectionId===i)),u=o(r.filter(e=>e.intersectSectionIds.includes(i)));a.push({template:l,sectionId:i,partition:t.partition,completionCount:c,intersectionCount:u,denominator:n,status:s?"incomplete":"exact"})}return{templates:i,sections:r,cells:a}}function Py(e){return e.entityCount??1}function Iy(e){if(!e.missingPrehistory)return{id:`group:${e.id}`,occurrenceId:e.id,partition:e.partition,nodePath:e.nodePath,entityCount:Py(e),...e.stepEntityCounts&&{stepEntityCounts:[...e.stepEntityCounts]},signature:Ay(e.nodePath,e.nodePath.length-1)}}function Ty(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let i=Math.max(0,t),r=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let n=e[t-1],o=e[t],a=e[t+1],s=Math.hypot(o.x-n.x,o.y-n.y),l=Math.hypot(a.x-o.x,a.y-o.y),c=Math.min(i,s/2,l/2);if(c<=.001){r+=` L${o.x},${o.y}`;continue}let u={x:o.x+(n.x-o.x)/s*c,y:o.y+(n.y-o.y)/s*c},d={x:o.x+(a.x-o.x)/l*c,y:o.y+(a.y-o.y)/l*c};r+=` L${u.x},${u.y} Q${o.x},${o.y} ${d.x},${d.y}`}let n=e[e.length-1];return`${r} L${n.x},${n.y}`}var Ly=(e,t,i)=>({x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}),Cy=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function Ry(e,t,i){if(e.length<2)return"";let r=function(e){let t=[e[0]];for(let i=1;i<e.length-1;i++){let r=e[i-1],n=e[i],o=e[i+1],a=Cy(r,n),s=Cy(n,o),l=Math.min(8,a/2,s/2);if(0===l)continue;let c=Ly(n,r,l/a),u=Ly(n,o,l/s);t.push(c);for(let e=1;e<=12;e++){let i=e/12;t.push(Ly(Ly(c,n,i),Ly(n,u,i),i))}}return t.push(e[e.length-1]),t.filter((e,i)=>0===i||Cy(t[i-1],e)>1e-8)}(e);if(r.length<2)return"";let n=[0];for(let e=1;e<r.length;e++)n.push(n[e-1]+Cy(r[e-1],r[e]));let o=n[n.length-1],a=function(e){if(e.length<2)return e.map(e=>({...e}));let t=(e,t)=>{let i=t.x-e.x,r=t.y-e.y,n=Math.hypot(i,r)||1;return{x:-r/n,y:i/n}};return e.map((i,r)=>{let n=r>0?t(e[r-1],i):null,o=r<e.length-1?t(i,e[r+1]):null;if(!n||!o){let e=o??n??{x:0,y:0};return{x:i.x+1*e.x,y:i.y+1*e.y}}let a=n.x+o.x,s=n.y+o.y,l=Math.hypot(a,s);if(l<.001)return{x:i.x+1*o.x,y:i.y+1*o.y};a/=l,s/=l;let c=a*o.x+s*o.y;if(Math.abs(c)<.001)return{x:i.x+1*o.x,y:i.y+1*o.y};let u=4*Math.abs(1),d=1/c,h=Math.max(-u,Math.min(u,d));return{x:i.x+a*h,y:i.y+s*h}})}(r),s=[1,-1].map(e=>r.map((r,s)=>{let l=t+(i-t)*n[s]/o;return Ly(r,a[s],e*l/2)}));return[...s[0],...s[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function Ny(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let i=t+e/2;return t+=e+3,i})}var Dy={viewBox:[24,24],parts:[{d:"M5,0 H19 Q24,0 24,5 V19 Q24,24 19,24 H5 Q0,24 0,19 V5 Q0,0 5,0 Z",stroke:"accent"}]};function Fy(e){let t="";return e.split(">").map((e,i)=>t=i?`${t}>${e}`:e)}var Ey=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,Oy=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),zy=e=>{let t=e.config.braid,i=e.dimensions.plot,r=t.atlas.spec.comparison?.partitions??[...new Set(t.groups.map(e=>e.partition))],n=t.groups.filter(e=>r.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],s=[];if(0===n.length)return{sceneNodes:a,sceneEdges:o,labels:s};let l=new Set(n.map(e=>e.signature)),c=[...t.signatureOrder.filter(e=>l.delete(e)),...l],u=new Map(c.map((e,t)=>[e,t])),d=[...n].sort((e,t)=>u.get(e.signature)-u.get(t.signature)),h=r.map(e=>d.filter(t=>t.partition===e)),p=function(e){let t=new Map;for(let i of e){let e=Fy(i.signature);i.nodePath.forEach((r,n)=>{let o=e[n],a=t.get(o);a||(a={id:o,state:r,depth:n+1,signatures:new Set},t.set(o,a)),a.signatures.add(i.signature)})}return[...t.values()]}(d),f=ue(p.map(e=>e.depth)),g=n.map(e=>ue(e.stepEntityCounts??[e.entityCount])),m=ue(g),y=e=>e<=0?0:Math.max(1,10*e/m),x=new Map(n.map((e,t)=>[e.id,y(g[t])])),b=i.height/r.length,{semantic:v}=e.theme,w=(e,t,i,r={})=>s.push({x:e,y:t,text:i,fill:v.text??"#333",fontSize:10,anchor:"middle",...r}),k={sourceRevision:t.atlas.provenance.sourceRevision,analysisRevision:t.atlas.analysisRevision,relationScopeId:"directed-admitted"},S=new Map(p.map(e=>{let t=h.map(t=>t.reduce((t,i)=>t+(e.signatures.has(i.signature)?x.get(i.id)+3:0),5));return[e.id,ue(t,24)]})),A=ue([...S.values()],24),M=Math.min(i.width/4,A/2+16),$=(i.width-2*M)/Math.max(f-1,1),_=e=>i.x+M+(e-1)*$,P=48+A/2,I=22+A/2,T=(e,t)=>e+P+(u.get(t)+.5)*Math.max(0,b-P-I)/c.length,L=(t,i,r,n,a)=>{let s=Ey(i,n),l=Ey(i,a),c=y(s),u=y(l);if(0===c&&0===u)return;let d=c!==u,h=e.resolveColor(i.signature);o.push({type:"curved",id:r,pathD:d?Ry(t,c,u):Ty(t,8),style:{fill:d?h:"none",fillOpacity:1,stroke:d?"none":h,strokeWidth:d?0:c},datum:{...k,id:r,kind:"braid-track",nodeId:i.nodePath[a],fromNodeId:i.nodePath[n],groupId:i.id,signature:i.signature,partition:i.partition,entityCount:i.entityCount,fromStep:n,toStep:a,fromCount:s,toCount:l,falseRoot:!1},accessibleDatum:{journey:i.nodePath.join(" → "),partition:i.partition??"all",fromStep:n+1,toStep:a+1,fromCount:s,toCount:l}})};return r.forEach((e,t)=>{let r=i.y+t*b,n=h[t];if(e&&w(i.x+8,r+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===n.length)return;for(let e=1;e<=f;e++)w(_(e),r+34,`Step ${e}`);let o=new Map;for(let t of p){let i=n.filter(e=>t.signatures.has(e.signature));if(0===i.length)continue;let s=_(t.depth),l=Kd([...t.signatures].map(e=>T(r,e))),c=Ny(i.map(e=>x.get(e.id)));o.set(t.id,new Map(i.map((e,t)=>[e.id,{x:s,y:l+c[t],offset:c[t]}])));let u=S.get(t.id),d={state:t.state,step:t.depth,partition:e??"all"},h=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:h,cx:s,cy:l,size:u,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:Dy,accent:v.border??"#888",style:{fill:v.surface??"#fff"},datum:{...k,id:h,nodeId:t.state,kind:"braid-step",prefixId:t.id,...d},accessibleDatum:d}),w(s,l+u/2+12,t.state,{anchorPoint:[s,l]})}for(let t of n){let i=Fy(t.signature);for(let r=1;r<i.length;r++){let n=o.get(i[r-1]).get(t.id),a=o.get(i[r]).get(t.id),s=(n.x+a.x)/2-Math.sign(a.y-n.y)*a.offset,l=Math.abs(n.y-a.y)<1e-8?[n,a]:[n,{x:s,y:n.y},{x:s,y:a.y},a];L(l,t,`step:${e??"all"}:${i[r]}:${t.id}`,r-1,r)}}}),{sceneNodes:a,sceneEdges:o,labels:s,restyle:Oy,restyleEdge:Oy}};import*as By from"react";import{NetworkPerspectiveGround as jy}from"./semiotic-network-placement.module.min.js";function Wy(e,t){let i=new Set,r=[t];for(;r.length;){let t=r.pop();if(i.has(t))continue;i.add(t);let n=Sy(e.children,t);Array.isArray(n)&&r.push(...n)}return i}var Yy=e=>{let{forest:t,selection:i,reading:r="organize"}=e.config,{atlas:n}=t,o=e.dimensions.plot,a=e.theme.semantic.text??"#273442",s=e.config.colors?.backbone??e.theme.semantic.textSecondary??"#8995a3",l=e.config.colors?.residual??e.theme.semantic.warning??"#b66631",c=e.config.colors?.required??e.theme.semantic.primary??"#3983a5",u=i?.analysisRevision===n.analysisRevision&&"directed-admitted"===i.relationScopeId&&n.source.nodes.some(e=>e.id===i.nodeId)?i.nodeId:void 0,d=new Map;for(let i of t.order)if(e.config.collapsedNodeIds?.includes(i)&&!d.has(i))for(let e of Wy(t,i))e!==i&&d.set(e,i);let h=t.order.filter(e=>!d.has(e)),p=new Map(n.source.nodes.map(e=>[e.id,e])),f=new Map;for(let e of d.values())f.set(e,(f.get(e)??0)+1);let g=new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source;if(t===(d.get(e.target)??e.target)&&(e.source!==t||e.target!==t)){let i=g.get(t);i?i.push(e.id):g.set(t,[e.id])}}let m=[...n.sections.sectionIds];n.source.nodes.some(e=>!e.sectionId)&&m.push("Unsectioned");let y=new Map(n.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),x=m.map(e=>h.filter(t=>y.get(t)===e)),b=new Map,v=[],w=[],k=[],S=[],A=(e,t,i,r=11,n)=>v.push({x:e,y:t,text:i,fill:a,anchor:"middle",fontSize:r,...n?{anchorPoint:n}:{}}),M=Math.max(16,Math.min(94,o.width/Math.max(1,m.length)-20));x.forEach((e,t)=>{let i=o.x+o.width*(t+.5)/m.length;A(i,o.y+18,m[t],12),e.forEach((t,r)=>{let n=o.y+58+(r+.5)*Math.max(40,o.height-110)/Math.max(1,e.length);b.set(t,{x:i,y:n})})});for(let t of h){let i=b.get(t),r=p.get(t),o=f.get(t)??0,a=g.get(t)??[],d=n.requiredPaths?.unreachableNodeIds.includes(t),h=r.completeness&&"known"!==r.completeness,m=h?"Unknown upstream":d?"Unreachable from roots":void 0;w.push({type:"glyph",id:t,cx:i.x,cy:i.y,size:34,glyph:{viewBox:[M,34],parts:[{d:`M6,0 H${M-6} Q${M},0 ${M},6 V28 Q${M},34 ${M-6},34 H6 Q0,34 0,28 V6 Q0,0 6,0 Z`,stroke:"accent"}]},accent:u===t?c:h?l:s,style:{fill:e.theme.semantic.surface??"#fff",strokeWidth:u===t?2.5:1},label:t,datum:{...r,nodeId:t,kind:"dependency-node",sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",hiddenCount:o,internalEdgeIds:a},accessibleDatum:{node:t,section:y.get(t),status:m??"Admitted",hiddenCount:o,internalEdges:a.join(", ")}});let x=[i.x,i.y];A(i.x,i.y+4,o?`${t} +${o}`:t,12,x),m?A(i.x,i.y+30,m,9,x):o&&A(i.x,i.y+30,`${a.length} internal links`,9,x)}let $,_=new Set(t.forest.backboneEdgeIds),P=new Set(e.config.highlightedEdgeIds),I=new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source,i=d.get(e.target)??e.target;if(t===i&&(e.source!==t||e.target!==i))continue;let r=b.get(t),a=b.get(i),u=JSON.stringify([t,i]),h=12*(I.get(u)??0);I.set(u,(I.get(u)??0)+1);let p,f,g=_.has(e.id),y=P.has(e.id)?c:g?s:l,x=a.x>r.x,v=r.x+(x?M/2:-M/2),w=a.x+(x?-M/2:M/2),A=[...b.values()].filter(e=>e.x>Math.min(r.x,a.x)&&e.x<Math.max(r.x,a.x));if(t===i)p=`M${r.x-14},${r.y-17} C${r.x-35-h},${r.y-64-h} ${r.x+35+h},${r.y-64-h} ${r.x+14},${r.y-17}`,f=1;else if(r.x===a.x){let e=a.y>r.y?1:-1,t=r.x+e*M/2,i=t+e*(32+h);p=`M${t},${r.y} C${i},${r.y} ${i},${a.y} ${t},${a.y}`,f=1===e?2:0}else if(A.length){let e=Math.min(r.y,a.y,ce(A.map(e=>e.y)))-17-26-h,t=(o.width/m.length-M)/2*(x?1:-1);p=`M${v},${r.y} C${v+t},${r.y} ${v},${e} ${v+t},${e} H${w-t} C${w},${e} ${w-t},${a.y} ${w},${a.y}`,f=x?0:2}else if(x){let e=(v+w)/2;p=`M${v},${r.y} C${e},${r.y-h} ${e},${a.y-h} ${w},${a.y}`,f=0}else{let e=Math.min(r.y,a.y)-48-h;p=`M${v},${r.y} C${v-25},${e} ${w+25},${e} ${w},${a.y}`,f=2}k.push({type:"curved",id:e.id,pathD:p,style:{stroke:y,strokeWidth:P.has(e.id)?3:g?1.3:2,fill:"none"},datum:{...e,sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",kind:"dependency-edge",edgeClass:g?"backbone":"residual"},accessibleDatum:{edge:e.id,source:e.source,target:e.target,display:g?"backbone":"residual cross-link"}});let $=t===i?r.x+14:r.x===a.x?r.x+(a.y>r.y?M/2:-M/2):w,T=t===i?r.y-17:a.y;S.push(By.createElement("path",{key:`arrow:${e.id}`,"data-dependency-edge":e.id,"data-source":e.source,"data-target":e.target,d:"M-6,-3 L0,0 L-6,3",fill:"none",stroke:y,transform:`translate(${$},${T}) rotate(${90*f})`}))}if("required-paths"===r&&u){let e=function(e,t){let i=[],r=Sy(e.requiredChildren,t);if(void 0===r)return i;if(!Array.isArray(r))throw new Error("Invalid required-path dominator children");let n=[...r],o=new Set([t]);for(;n.length;){let t=n.pop(),r=Sy(e.requiredChildren,t);if("string"!=typeof t||o.has(t)||!Array.isArray(r))throw new Error("Invalid required-path dominator chain");o.add(t),i.push(t);for(let e of r)n.push(e)}return i.sort()}(t,u),i=[...new Set(e.map(e=>d.get(e)??e))].filter(e=>e!==u&&b.has(e));if(i.length){let e=i.map(e=>b.get(e)),t=ue(e.map(e=>e.x))+M/2+8,r=ce(e.map(e=>e.y))-23,n=ue(e.map(e=>e.y))+23;$={x:t-7,y:r,width:7,height:n-r,z:"top"},S.push(By.createElement("path",{key:"required-bracket",d:`M${t-7},${r} H${t} V${n} H${t-7}`,fill:"none",stroke:c,strokeWidth:2,"data-kind":"dominator-bracket"}))}A(o.x+o.width/2,o.y+o.height-16,e.length?`${u} lies on all admitted paths to ${e.join(", ")}${"incomplete"===n.requiredPaths?.status?" · incomplete scope":""}`:n.requiredPaths?`${u}: no other required targets in the admitted graph`:"Required paths have not been prepared")}let T=new Map(w.map(e=>[e.id,e.datum]));return{sceneNodes:w,sceneEdges:k,labels:v,restyle:(e,t)=>({opacity:t?.isActive&&!t.predicate(e.datum)?.2:1}),restyleEdge:(e,t)=>({opacity:t?.isActive&&![e.datum,T.get(String(e.datum?.source)),T.get(String(e.datum?.target))].some(e=>e&&t.predicate(e))?.2:1}),overlays:By.createElement("g",{"aria-hidden":!0},By.createElement(jy,{z:"top"},...S)),perspective:"manual",...e.perspective&&$?{perspectiveBounds:[$]}:{}}};import*as qy from"react";import{NetworkPerspectiveGround as Xy}from"./semiotic-network-placement.module.min.js";import*as Gy from"react";var Vy=Gy.createElement,Hy={observed:"#387e98",modeled:"#946344",residual:"#a56537",muted:"#778796",alarm:"#bb5149"},Uy=e=>null===e?"unmeasured":e>=1e6?`${Number((e/1e6).toFixed(2))}m`:e>=1e3?`${Number((e/1e3).toFixed(1))}k`:Number.isInteger(e)?String(e):String(Number(e.toPrecision(3))),Zy={stage:"M-5,0 H5",distributor:"M-5,0 H0 M0,0 L6,-5 M0,0 H6 M0,0 L6,5",queue:"M-6,-5 V5 H6 V-5 M-3,2 H3",retry:"M-5,2 A5,5 0 1,1 4,3 M4,-1 V4 H0","join-all":"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M2,-5 V5",selector:"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M1,-4 L5,0 L1,4",dependency:"M-5,-5 H5 V5 H-5 Z M-2,-2 L2,2 M-2,2 L2,-2",junction:"M0,-6 L6,0 L0,6 L-6,0 Z"},Ky={stage:"stage",distributor:"distributor",queue:"FIFO queue",retry:"retry episode","join-all":"all-member join",selector:"first success",dependency:"dependency gate",junction:"unclassified junction"};function Qy(e,t,i,r,n,o=Hy,a){let s=Object.values(t.entry.nodes).reduce((e,t)=>Math.max(e,t.queued??0),0)||1;return e.modules.map(e=>{let{module:l,x:c,y:u,width:d,height:h,queue:p}=e,f=t.entry.nodes[l.nodeId],g=n===l.nodeId?i:(f.queued??0)>0?o.alarm:o.muted,m=c+d/2,y="records"===l.semantics.unit?"rec":"attempts"===l.semantics.unit?"att":"roots",x=null!==f.capacity?`${Uy(f.completions)} / ${Uy(f.capacity)} ${y}/s`:null!==f.completions?`${Uy(f.completions)} ${y}/s complete`:`${Uy(f.arrivals)} ${y}/s offered`;return Vy("g",{key:l.id,"data-circuit-module":l.nodeId,"data-module-kind":l.kind,opacity:a?.(l.nodeId),"data-queued":f.queued??"unmeasured"},Vy("rect",{x:c,y:u,width:d,height:h,fill:"none",stroke:g,strokeWidth:n===l.nodeId?2.5:1}),Vy("path",{d:Zy[l.kind],transform:`translate(${c+10},${u+12})`,stroke:g,fill:"none",strokeWidth:1.4}),Vy("text",{x:m+5,y:u+16,textAnchor:"middle",fontSize:d<110?9:11,fontWeight:600,fill:r},l.semantics.label),Vy("text",{x:m,y:u+28,textAnchor:"middle",fontSize:8,fill:r},Ky[l.kind]),Vy("text",{x:m,y:u+41,textAnchor:"middle",fontSize:d<110?7:9,fill:r},x),Vy("text",{x:m,y:u+h-13,textAnchor:"middle",fontSize:8,fill:r},`Queue ${Uy(f.queued)}`),null!==f.queued?Vy("rect",{...p,width:p.width*f.queued/s,fill:g,"data-circuit-gauge":"queue"}):null,Vy("rect",{...e.sensor,fill:i,"data-circuit-sensor":l.nodeId}),l.semantics.dependencyNodeIds?.length?Vy("text",{x:m,y:u-8,fontSize:8,textAnchor:"middle",fill:r,"data-circuit-dependency":l.nodeId},`Requires ${l.semantics.dependencyNodeIds.join(", ")}`):null)})}function Jy(e,t,i,r,n,o){let{history:a}=e,s=e.modules.find(e=>e.module.nodeId===o)?.module,l="records"===t.unit?"queued":"attempts",c=t.entries.map(e=>s?e.nodes[s.nodeId]["records"===t.unit?"queued":"arrivals"]:e.totals[l]),u=c.reduce((e,t)=>Math.max(e,t??0),0)||1,d=t.entries[0].at,h=t.entries[t.entries.length-1].at,p=h>d?h-d:1,f=e=>a.x+(e-d)/p*a.width,g="",m=!1;for(let[e,i]of t.entries.entries()){if(null===c[e]){m=!1;continue}let t=a.y+a.height-c[e]/u*a.height;g+=`${m?" H":"M"}${f(i.at)}${m?` V${t}`:`,${t}`}`,m=!0}return Vy("g",{"data-circuit-history":l,"data-history-module":s?.nodeId},Vy("text",{x:a.x,y:a.y-9,fill:n,fontSize:10},s?`${s.semantics.label} · ${"queued"===l?`queued ${s.semantics.unit}`:`offered ${s.semantics.unit}/s`} · aggregate observations`:"queued"===l?"Queued records · aggregate observations":"Offered attempts/s · aggregate observations"),Vy("path",{d:g,fill:"none",stroke:r,strokeWidth:2}),Vy("line",{x1:f(i.observedAt),x2:f(i.observedAt),y1:a.y,y2:a.y+a.height,stroke:n,strokeDasharray:"3 3","data-circuit-cursor":i.observedAt}),...t.entries.map(e=>Vy("text",{key:e.id,x:f(e.at),y:a.y+a.height+14,textAnchor:"middle",fontSize:9,fill:n},`${e.at}s`)))}function ex(e,t,i,r){return{id:r.nodeId,nodeId:r.nodeId,kind:"circuit-module",moduleKind:r.kind,label:r.semantics.label,unit:r.semantics.unit,sourceRevision:t.sourceRevision,analysisRevision:e.atlas.analysisRevision,relationScopeId:"directed-admitted",editionId:t.id,editionKind:t.kind,synthetic:t.synthetic,mode:i.mode,observedAt:i.observedAt,...i.entry.nodes[r.nodeId]}}var tx=e=>null===e?"unmeasured":String(e),ix=qy.createElement,rx=e=>ox(e,!1),nx=e=>ox(e,!0);function ox(e,t){let{circuit:i,edition:r,reading:n,selection:o}=e.config;if(n.editionId!==r.id||r.analysisRevision!==i.atlas.analysisRevision)throw new Error("Circuit render inputs must share an edition and analysis revision");let a=function(e,t,i){if(!Number.isFinite(t)||!Number.isFinite(i)||t<360||i<300)throw new Error("Circuit geometry needs at least 360 × 300 pixels");let r=[...e.atlas.sections.sectionIds];e.atlas.source.nodes.some(e=>!e.sectionId)&&r.push("Unsectioned");let n=Gf({width:t,height:i-110,padX:22,padY:70,stages:r.map(e=>({id:e})),shape:"lane"}),o=new Map(e.atlas.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),a=n.stages.flatMap(t=>{let r=e.order.filter(e=>o.get(e)===t.id),n=(i-235)/Math.max(1,r.length);if(r.length&&n<78)throw new Error("Increase circuit height to keep every module readable");return r.map((i,r)=>{let o=e.modules.find(e=>e.nodeId===i),a=Math.max(68,Math.min(142,t.width-56)),s=Math.min(68,n-10),l=t.x-a/2,c=95+(r+.5)*n-s/2;return{module:o,x:l,y:c,width:a,height:s,queue:{x:l+8,y:c+s-8,width:a-16,height:4},sensor:{x:l+a-5,y:c+s/2-4,width:8,height:8}}})}),s=new Map(a.map(e=>[e.module.nodeId,e])),l=new Set(e.residualEdgeIds),c=0,u=e.atlas.source.edges.map(e=>{let t,i=s.get(e.source),n=s.get(e.target),a=n.x>i.x,u=n.x===i.x,d=(t,i)=>{let r=t.module.ports.filter(e=>e.direction===i),n=r.findIndex(t=>t.edgeId===e.id);return t.y+10+(n+.5)*(t.height-20)/r.length},h={x:i.x+(a||u?i.width:0),y:d(i,"out")},p={x:n.x+(a?0:n.width),y:d(n,"in")};if(u){let r=h.x+18+5*c++;t=e.source===e.target?[h,{x:r,y:h.y},{x:r,y:i.y-15},{x:p.x-8,y:i.y-15},{x:p.x-8,y:i.y}]:[h,{x:r,y:h.y},{x:r,y:p.y},p]}else if(!a||Math.abs(r.indexOf(o.get(e.source))-r.indexOf(o.get(e.target)))>1){let e=a?1:-1,i=62+7*c++;t=[h,{x:h.x+16*e,y:h.y},{x:h.x+16*e,y:i},{x:p.x-16*e,y:i},{x:p.x-16*e,y:p.y},p]}else{let e=(h.x+p.x)/2;t=[h,{x:e,y:h.y},{x:e,y:p.y},p]}return{edgeId:e.id,source:e.source,target:e.target,residual:l.has(e.id),points:t,pathD:Zm(t)}});return{width:t,height:i,modules:a,routes:u,sections:n.stages.map(e=>({id:e.id,x:e.x})),history:{x:42,y:i-88,width:t-84,height:46}}}(i,e.dimensions.width,e.dimensions.height),s=e.theme.semantic.text??"#273442",l=e.theme.semantic.surface??"#fff",c=function(e,t={}){return{observed:t.observed??e.info??e.primary??Hy.observed,modeled:t.modeled??e.secondary??Hy.modeled,residual:t.residual??e.warning??Hy.residual,muted:t.muted??e.textSecondary??Hy.muted,alarm:t.alarm??e.danger??Hy.alarm}}(e.theme.semantic,e.config.colors),u="modeled"===r.kind?c.modeled:c.observed,d={width:a.width,height:a.height,viewBox:`0 0 ${a.width} ${a.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},"aria-hidden":!0},h=o?.analysisRevision===i.atlas.analysisRevision&&"directed-admitted"===o.relationScopeId?o.nodeId:void 0,p=n.entry.flows.reduce((e,t)=>Math.max(e,t.perSecond??0),0)||1,f=new Map(n.entry.flows.map(e=>[e.edgeId,e])),g=new Map(i.modules.map(e=>[e.nodeId,ex(i,r,n,e)])),m=t=>e.config.layoutSelection?.isActive&&!e.config.layoutSelection.predicate(g.get(t))?.2:1,y=Math.max(0,Math.min(200,Math.floor(e.config.particleBudget??24))),x=Z(e.config.placementSeed??1),b=a.routes.filter(e=>(f.get(e.edgeId)?.perSecond??0)>0),v=e.config.reducedMotion?[]:Array.from({length:b.length?y:0},(e,t)=>{let i=b[t%b.length],r=function(e,t){let i=e.slice(1).map((t,i)=>Math.hypot(t.x-e[i].x,t.y-e[i].y)),r=i.reduce((e,t)=>e+t,0),n=Math.max(0,Math.min(1,t))*r;for(let t=0;t<i.length;t++){if(n<=i[t]){let r=i[t]?n/i[t]:0;return{x:e[t].x+(e[t+1].x-e[t].x)*r,y:e[t].y+(e[t+1].y-e[t].y)*r}}n-=i[t]}return e[e.length-1]}(i.points,(x()+n.requestedTime/10)%1);return ix("circle",{key:`cue:${t}`,cx:r.x,cy:r.y,r:2.3,fill:s,opacity:Math.max(m(i.source),m(i.target)),"data-circuit-particle":i.edgeId})}),w=a.modules.map(e=>({id:e.module.nodeId,x:e.x+e.width/2,y:e.y+e.height/2,fixedPosition:{x:e.x+e.width/2,y:e.y+e.height/2},shape:{type:"aabb",width:e.width,height:e.height},bodyCollisions:!1,datum:ex(i,r,n,e.module)})),k=[],S=function(e,t,i,r){return[...t.modules.map(t=>{let n=ex(e,i,r,t.module);return{id:n.id,bodyId:n.id,datum:n,x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height,shape:"rect",label:`${n.label}: ${n.moduleKind}`,description:`${n.label}. ${i.kind} at ${r.observedAt}s. Arrivals ${tx(n.arrivals)} ${n.unit}/s; completions ${tx(n.completions)} ${n.unit}/s; installed capacity ${tx(n.capacity)} ${n.unit}/s; queue ${tx(n.queued)} ${n.unit}. Measurement status: ${n.status}. Individual timings unavailable.`,group:"circuit modules"}}),...t.routes.map(t=>{let n=r.entry.flows.find(e=>e.edgeId===t.edgeId),o=t.points[Math.floor(t.points.length/2)];return{id:`pipe:${t.edgeId}`,x:o.x,y:o.y,shape:"path",pathData:t.pathD,label:`${t.source} → ${t.target}: ${tx(n.perSecond)} ${n.unit}/s`,description:`Original edge ${t.edgeId}. ${t.residual?"Residual link":"Display backbone"}. ${i.kind} at ${r.observedAt}s; transferred volume ${tx(n.perSecond)} ${n.unit}/s.`,group:"original pipes",datum:{id:t.edgeId,kind:"circuit-pipe",source:t.source,target:t.target,analysisRevision:e.atlas.analysisRevision,sourceRevision:i.sourceRevision,relationScopeId:"directed-admitted",editionId:i.id,editionKind:i.kind,observedAt:r.observedAt,...n}}})]}(i,a,r,n),A=t?new Map(S.map(e=>[e.id,e])):null,M={bodies:w,config:{kernel:{gravity:{x:0,y:0},seed:e.config.placementSeed??1,sleepAfter:.01},bodyBudget:!1,bodyLimit:w.length,eviction:!1,sediment:!1,settleStepLimit:4},bodyStyle:e=>({fill:l,stroke:c.muted,strokeWidth:1,opacity:m(e.id)}),colliders:a.modules.flatMap(e=>function(e){let t=e.idPrefix??"lane",i={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},r=[qf(`${t}-top`,e.left,e.top,e.right,e.top,i),qf(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,i)];return e.openEnds||r.push(qf(`${t}-left`,e.left,e.top,e.left,e.bottom,i),qf(`${t}-right`,e.right,e.top,e.right,e.bottom,i)),r}({idPrefix:`queue:${e.module.nodeId}`,left:e.queue.x,right:e.queue.x+e.queue.width,top:e.queue.y,bottom:e.queue.y+e.queue.height,thickness:1,openEnds:!0})),sensors:a.modules.map(e=>({id:`sensor:${e.module.nodeId}`,shape:{type:"aabb",x:e.sensor.x+e.sensor.width/2,y:e.sensor.y+e.sensor.height/2,width:e.sensor.width,height:e.sensor.height}})),semanticItems:S,backgroundOverlays:ix("svg",d,...a.routes.map(i=>{let r=f.get(i.edgeId),n=i.points[i.points.length-1],o=i.points[i.points.length-2],l=a.modules.find(e=>e.module.nodeId===i.source),d=a.modules.find(e=>e.module.nodeId===i.target),h=l.module.ports.filter(e=>"out"===e.direction).length<d.module.ports.filter(e=>"in"===e.direction).length,g=h?i.points[0]:n,y=h?g.x>=l.x+l.width:g.x>d.x,x=180*Math.atan2(n.y-o.y,n.x-o.x)/Math.PI,b=e.config.highlightedEdgeIds?.includes(i.edgeId),v=b?s:i.residual?c.residual:u,w="records"===r.unit?"rec":"attempts"===r.unit?"att":"roots";if(t){let e=A.get(`pipe:${i.edgeId}`);k.push({type:"curved",pathD:i.pathD,datum:e.datum,id:i.edgeId,label:e.label,accessibility:{label:`${e.label}. ${e.description}`},style:{stroke:v,strokeWidth:null===r.perSecond?1.5:1+r.perSecond/p*7,strokeDasharray:null===r.perSecond?"4 3":void 0,fill:"none",opacity:(0===r.perSecond?.35:.75)*Math.max(m(i.source),m(i.target))}})}return ix("g",{key:i.edgeId,"data-circuit-edge":i.edgeId,opacity:Math.max(m(i.source),m(i.target)),"data-source":i.source,"data-target":i.target,"data-flow":r.perSecond??"unmeasured","data-highlighted":b||void 0,"data-unit":`${r.unit}/s`},ix("title",null,`${i.edgeId}: ${i.source} → ${i.target}; ${r.perSecond??"unmeasured"} ${r.unit}/s`),!t&&ix("path",{d:i.pathD,stroke:v,strokeWidth:null===r.perSecond?1.5:1+r.perSecond/p*7,strokeDasharray:null===r.perSecond?"4 3":void 0,strokeLinejoin:"round",fill:"none",opacity:0===r.perSecond?.35:.75}),ix("path",{d:"M-5,-3 L0,0 L-5,3",transform:`translate(${n.x},${n.y}) rotate(${x})`,fill:"none",stroke:v}),ix("text",{x:g.x+(y?5:-5),y:g.y-7,textAnchor:y?"start":"end",fontSize:8,fill:s},`${null===r.perSecond?"?":Uy(r.perSecond)} ${w}/s`))})),overlays:ix("svg",{...d,"data-circuit-edition":r.kind,"data-circuit-time":n.observedAt},...a.sections.map(e=>ix("text",{key:e.id,x:e.x,y:43,textAnchor:"middle",fontSize:11,fill:s},e.id)),...Qy(a,n,u,s,h,c,m),...v,Jy(a,r,n,u,s,h),...t?[]:a.routes.map(e=>ix("path",{key:`hit:${e.edgeId}`,d:e.pathD,fill:"none",stroke:"transparent",strokeWidth:12,pointerEvents:"stroke","data-semiotic-semantic-id":`pipe:${e.edgeId}`})),ix("text",{x:a.width/2,y:a.height-8,textAnchor:"middle",fontSize:9,fill:s},`${"modeled"===r.kind?"Modeled":"Observed"} · ${n.observedAt}s · pipe width = transferred volume/s · individual timings unavailable`))};if(!t)return M;let $=e=>e.props.children;return{sceneNodes:w.map(e=>{let t=A.get(e.id);return{type:"rect",id:e.id,x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,datum:e.datum,label:t.label,accessibility:{label:`${t.label}. ${t.description}`},style:{fill:l,stroke:c.muted,strokeWidth:1,opacity:m(e.id)}}}),sceneEdges:k,overlays:ix(Xy,{z:"top"},$(M.backgroundOverlays),$(M.overlays)),perspective:"manual",perspectiveBounds:[{x:0,y:0,width:a.width,height:a.height,z:"top"}]}}import{scaleLinear as ax}from"d3-scale";function sx(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function lx(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,sx(e))}))}function cx(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:String(e.bodyId)}):e}function ux(e){return"circuit-pipe"===e.kind?`${e.source} → ${e.target}: ${e.perSecond??"unmeasured"} ${e.unit}/s`:`${e.label??e.id??"Circuit"}: ${e.completions??"unmeasured"} ${e.unit??"units"}/s completed; queue ${e.queued??"unmeasured"}`}function dx({width:e=ct.width,height:t=ct.height,title:i,description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,annotations:u,frameProps:d,perspective:h,networkFrameProps:p,linkedSelection:f,onSelectNode:g,tooltip:m=ux,...y}){return{key:JSON.stringify([y.circuit.atlas.analysisRevision,y.circuit.order,y.circuit.backboneEdgeIds,e,t]),data:y.circuit.modules.map(e=>ex(y.circuit,y.edition,y.reading,e)),layout:rx,layoutConfig:y,width:e,height:t,chartId:a,className:s,onObservation:l,linkedHover:vy(c),annotations:u,frameProps:d,paused:!0,title:i??y.edition.label,description:r??`${y.edition.label}. ${y.edition.kind} aggregate interval tape at ${y.reading.observedAt} seconds. Pipe widths encode transferred volume per second in their labeled units; module readouts separate completions, capacity and queue stock. Individual timings are unavailable.`,summary:n??y.edition.assumptions.join(" "),accessibleTable:o,tooltip:m}}import*as hx from"react-dom/server";var px=/*#__PURE__*/Object.create(null);function fx(e,t){px[e]=t}function gx(e,t){var i=e.get(t);if(!i)throw new Error("missing: "+t);return i}function mx(e){return e.y0-e.y1>0?"up":"down"}function yx(e,t){return t(e.source)==t(e.target)}function xx(e){return e.target.x0-e.source.x1}function bx(e,t){var i=wx(e),r=xx(t)/Math.tan(i);return"up"==mx(e)?e.y1-r:e.y1+r}function vx(e,t){var i=wx(e),r=xx(t)/Math.tan(i);return"up"==mx(e)?e.y1+r:e.y1-r}function wx(e){var t=Math.abs(e.y1-e.y0),i=Math.abs(e.target.x0-e.source.x1);return Math.atan(i/t)}function kx(e){return Ax(e.source)}function Sx(e){return Ax(e.target)}function Ax(e){return(e.y0+e.y1)/2}function Mx(e){return e.virtual?0:e.value}function $x(e,t){var i=0;e.sourceLinks.forEach(function(e){i=e.circular&&!yx(e,t)?i+1:i});var r=0;return e.targetLinks.forEach(function(e){r=e.circular&&!yx(e,t)?r+1:r}),i+r}function _x(e){return e.target.depth}function Px(e,t){return e.sourceLinks.length?e.depth:t-1}function Ix(e,t){return e.y0-t.y0}function Tx(e,t){return t.y0-e.y0}function Lx(e,t){return e.y1-t.y1}function Cx(e,t){return t.y1-e.y1}function Rx(e,t){return Dx(e.source,t.source)||e.index-t.index}function Nx(e,t){return Dx(e.target,t.target)||e.index-t.index}function Dx(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function Fx(e,t){return Ex(e)==Ex(t)?"bottom"==e.circularLinkType?Tx(e,t):Ix(e,t):Ex(t)-Ex(e)}function Ex(e){return e.target.column-e.source.column}function Ox(e,t){return zx(e)==zx(t)}function zx(e){return e.y0-e.y1>0?"up":"down"}import{min as Bx}from"d3-array";var jx=class{constructor(e){this.size=e,this.maximum=new Float64Array(4*e),this.floor=new Float64Array(4*e)}query(e,t){let i=(r,n,o)=>{if(e<=n&&o<=t)return this.maximum[r];let a=n+o>>>1;return Math.max(this.floor[r],e<=a?i(2*r,n,a):0,t>a?i(2*r+1,a+1,o):0)};return i(1,0,this.size-1)}reserve(e,t,i){let r=(n,o,a)=>{if(this.maximum[n]=Math.max(this.maximum[n],i),e<=o&&a<=t)return void(this.floor[n]=Math.max(this.floor[n],i));let s=o+a>>>1;e<=s&&r(2*n,o,s),t>s&&r(2*n+1,s+1,a)};r(1,0,this.size-1)}};function Wx(e,t,i,r,n){let o=e;o.links.forEach(function(e){e.circular&&(e._circularWidth=e.width,e._circularStub=!1)});var a=Bx(o.links,function(e){return e.source.y0});o.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=o.links.filter(function(e){return e.circular}),l=new Map,c=new Map;s.forEach(function(e){l.set(e.source,(l.get(e.source)||0)+1),c.set(e.target,(c.get(e.target)||0)+1)});var u=new Set(s.filter(function(e){return yx(e,t)&&1===l.get(e.source)&&1===c.get(e.target)}));return["top","bottom"].forEach(function(e){var t=s.filter(function(t){return t.circularLinkType===e});(function(e,t,i){if(0!==e.length){e.sort(Fx);var r=Array.from(new Set(e.flatMap(function(e){return[e.source.column,e.target.column]}))).sort(function(e,t){return e-t}),n=new Map(r.map(function(e,t){return[e,t]})),o=new jx(r.length);e.forEach(function(e){var r=n.get(e.source.column),a=n.get(e.target.column),s=Math.min(r,a),l=Math.max(r,a),c=t.has(e)?0:o.query(s,l);e.circularPathData.verticalBuffer=c+e._circularWidth/2,o.reserve(s,l,c+e._circularWidth+i)})}})(t.slice(),u,i),["source","target"].forEach(function(n){var o=new Map;t.forEach(function(e){var t=e[n].column;o.has(t)||o.set(t,[]),o.get(t).push(e)}),o.forEach(function(t){t.sort("source"===n?"bottom"===e?Tx:Ix:"bottom"===e?Cx:Lx);var o=0,a="source"===n?"right":"left";t.forEach(function(e,t){e.circularPathData[a+"SmallArcRadius"]=r+e._circularWidth/2+o,e.circularPathData[a+"LargeArcRadius"]=r+e._circularWidth/2+t*i+o,o+=e._circularWidth})})})}),o.links.forEach(function(e){e.circular&&(e.circularPathData.arcRadius=e._circularWidth+r,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,u.has(e)?(e.circularPathData.rightSmallArcRadius=r+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=r+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=r+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=r+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)):"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(o.y1,e.source.y1,e.target.y1)+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=a-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius),e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer),e.circular?e.path=function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):e.path=function(e){var t=e.source.x1,i=e.y0,r=e.target.x0,n=e.y1,o=(t+r)/2;return"M"+t+","+i+"C"+o+","+i+" "+o+","+n+" "+r+","+n}(e)}),o}import{min as Yx,max as qx,sum as Xx,mean as Gx,group as Vx,groups as Hx}from"d3-array";function Ux(e){return function(){return e}}function Zx(e){return e.index}function Kx(e){return e.nodes}function Qx(e){return e.links}function Jx(e,t,i){var r=Hx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});r.forEach(function(n,o){var a=n.length;if(t)n.sort(t);else if(o>0){var s=new Map;n.forEach(function(e,t){var i=function(e){var t=0,i=0;return e.targetLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=Ax(e.source)*r,t+=r}}),e.sourceLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=Ax(e.target)*r,t+=r}}),t>0?i/t:NaN}(e);s.set(e,{bc:i,idx:t})}),n.sort(function(e,t){var i=s.get(e),r=s.get(t),n=i.bc,o=r.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(n)||isNaN(o)?isNaN(n)?isNaN(o)?i.idx-r.idx:1:-1:n-o})}else n.sort(function(e,t){return e.circularLinkType==t.circularLinkType?$x(t,i)-$x(e,i):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});n.forEach(function(t,n){t.depth==r.length-1&&1==a||0==t.depth&&1==a?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==$x(t,i)?(t.y0=e.y1/2+n,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+n,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-n,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/a*n,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-a/2+n,t.y1=t.y0+t.value*e.ky)})})}function eb(e,t,i,r,n,o){var a=Hx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var s=1,l=o;l>0;--l)c(s*=.99,i),u();function c(t,i){var r=a.length;a.forEach(function(n){var o=n.length,a=n[0].depth;n.forEach(function(n){var s;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&$x(n,i)>0){var l=Gx(n.sourceLinks,Sx),c=Gx(n.targetLinks,kx),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Ax(n))*t*.3;n.y0+=d,n.y1+=d}}else if(0==a&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(a==r-1&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)s=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+s;else{var h=Gx(n.sourceLinks,Sx),p=Gx(n.targetLinks,kx),f=((h&&p?(h+p)/2:h||p)-Ax(n))*t;n.y0+=f,n.y1+=f}})})}function u(){a.forEach(function(i){var o,a,s,l=e.y0,c=i.length;for(t?i.sort(t):i.sort(Dx),s=0;s<c;++s)(a=l-(o=i[s]).y0)>0&&(o.y0+=a,o.y1+=a),l=o.y1+r;if((a=l-r-e.y1)>0)for(l=o.y0-=a,o.y1-=a,s=c-2;s>=0;--s)(a=(o=i[s]).y1+n-l)>0&&(o.y0-=a,o.y1-=a),l=o.y0})}}function tb(e){e.nodes.forEach(function(e){e.sourceLinks.sort(Nx),e.targetLinks.sort(Rx)}),e.nodes.forEach(function(e){var t=e.y0,i=t,r=e.y1,n=r;e.sourceLinks.forEach(function(e){e.circular?(e.y0=r-e.width/2,r-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=n-e.width/2,n-=e.width):(e.y1=i+e.width/2,i+=e.width)})})}function ib(){var e=0,t=0,i=1,r=1,n=24,o=8,a=null,s=Zx,l=Px,c=void 0,u=32,d=2,h=Kx,p=Qx;function f(){var f={nodes:h.apply(null,arguments),links:p.apply(null,arguments)};return function(h){h.x0=e,h.y0=t,h.x1=i,h.y1=r,h.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var i=function(e,t){var i=new Map;return Vx(e,t).forEach(function(e,t){i.set(t,e[0])}),i}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var r=e.source,n=e.target;"object"!=typeof r&&(r=e.source=gx(i,r)),"object"!=typeof n&&(n=e.target=gx(i,n)),r.sourceLinks.push(e),n.targetLinks.push(e)})}(h,s),function(e,t,i){var r=0,n=null==t?function(e,t,i){let r=e.length,n=Array.from({length:r},()=>[]),o=Array.from({length:r},()=>[]),a=new Int32Array(r),s=new Int32Array(r),l=new Float64Array(r),c=new Float64Array(t.length),u=new Int32Array(r),d=e.map(e=>{let t=i(e);return`${typeof t}:${String(t)}`}),h=0;for(let e of t)e.source.index!==e.target.index&&Number.isFinite(e.value)&&(h=Math.max(h,e.value));let p=(e,t)=>d[e]<d[t]?-1:d[e]>d[t]?1:0;t.map((e,t)=>t).sort((e,i)=>p(t[e].source.index,t[i].source.index)||p(t[e].target.index,t[i].target.index)||t[e].value-t[i].value).forEach(e=>{let i=t[e],r=i.source.index,u=i.target.index;if(r===u)return;let d=Number.isFinite(i.value)&&h>0?Math.max(0,i.value)/h:0;c[e]=d,o[r].push(e),n[u].push(e),s[r]++,a[u]++,l[r]+=d,l[u]-=d});let f=e.map(e=>e.index),g=Int32Array.from(f),m=e=>0===s[e]?2:0===a[e]?1:0,y=(e,t)=>{let i=m(e),r=m(t);return i!==r?i>r:0===i&&l[e]!==l[t]?l[e]>l[t]:d[e]<d[t]||d[e]===d[t]&&e<t},x=(e,t)=>{let i=f[e];f[e]=f[t],f[t]=i,g[f[e]]=e,g[i]=t},b=(e,t=!1)=>{let i=g[e];for(;!t&&i>0;){let t=i-1>>>1;if(!y(e,f[t]))break;x(i,t),i=t}for(;2*i+1<f.length;){let t=2*i+1;if(t+1<f.length&&y(f[t+1],f[t])&&t++,!y(f[t],e))break;x(i,t),i=t}};for(let e=(f.length>>>1)-1;e>=0;e--)b(f[e],!0);let v=0,w=r-1;for(;f.length;){let e=f[0];u[e]=0===s[e]?w--:v++;let i=f.pop();g[e]=-1,f.length&&(f[0]=i,g[i]=0,b(i));for(let i of o[e]){let e=t[i].target.index;g[e]<0||(a[e]--,l[e]+=c[i],b(e))}for(let i of n[e]){let e=t[i].source.index;g[e]<0||(s[e]--,l[e]-=c[i],b(e))}}return u}(e.nodes,e.links,i):null;e.nodes.forEach(function(e){delete e.circularLinkType}),e.links.forEach(function(e){delete e.circularLinkID,delete e.circularLinkType,delete e.circularPathData,delete e._circularWidth,delete e._circularStub,e.circular=n?n[e.source.index]>=n[e.target.index]:!(t(e.source)<t(e.target)),e.circular&&(e.circularLinkID=r++)})}(h,c,s),function(e,t){var i=0,r=0;e.links.forEach(function(e){e.circular&&(e.source.circularLinkType||e.target.circularLinkType?e.circularLinkType=e.source.circularLinkType?e.source.circularLinkType:e.target.circularLinkType:e.circularLinkType=i<r?"top":"bottom","top"==e.circularLinkType?i++:r++,e.source.circularLinkType=e.circularLinkType,e.target.circularLinkType=e.circularLinkType)}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),yx(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(h,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(Xx(e.sourceLinks,Mx),Xx(e.targetLinks,Mx)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(h),function(e,t,i){if(null!=t&&e.nodes.length){e.nodes.sort(function(e,i){return t(e)<t(i)?-1:1});var r=0,n=t(e.nodes[0]);e.nodes.forEach(function(e){r=t(e)==n?r:r+1,n=t(e)==n?n:t(e),e.column=r})}var o=new Int32Array(e.nodes.length),a=[],s=1;e.nodes.forEach(function(e){e.depth=e.height=0,e.targetLinks.forEach(function(t){t.circular||o[e.index]++}),0===o[e.index]&&a.push(e)});for(var l=0;l<a.length;l++){var c=a[l];s=Math.max(s,c.depth+1),c.sourceLinks.forEach(function(e){e.circular||(e.target.depth=Math.max(e.target.depth,c.depth+1),0===--o[e.target.index]&&a.push(e.target))})}for(l=a.length-1;l>=0;l--)(c=a[l]).sourceLinks.forEach(function(e){e.circular||(c.height=Math.max(c.height,e.target.height+1))});e.nodes.forEach(function(e){e.column=null==t?i(e,s):e.column})}(h,c,l);var p=o;if(null!==a){var f=Hx(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=qx(f,function(e){return e.length});g>1&&(p=Math.max(1,(r-t)*a/(g-1)))}(function(e,t,i){var r=Hx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var n=Yx(r,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/Xx(t,function(e){return e.value})});e.ky=n,e.links.forEach(function(t){t.width=t.value*e.ky});var o=qx(e.nodes,function(e){return e.column});o>0?e.nodes.forEach(function(t){t.x0=e.x0+t.column*((e.x1-e.x0-i)/o),t.x1=t.x0+i}):e.nodes.forEach(function(t){t.x0=e.x0,t.x1=t.x0+i})})(h,p,n),Jx(h,c,s),eb(h,c,s,p,p,u),tb(h),Jx(h,c,s),eb(h,c,s,p,p,u),tb(h),function(e){let t=e;t.nodes.forEach(function(e){e.y+(e.y1-e.y0)>t.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-t.y1));var i=e.sourceLinks.slice().sort(function(e,t){return e.index-t.index});i.length>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!Ox(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var i=bx(t,e);return e.y1-i}if(t.target.column>e.target.column)return bx(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var r=e.y0;i.forEach(function(e){e.y0=r+e.width/2,r+=e.width});for(var n=0,o=i.length-1;o>=0;o--){var a=i[o];"bottom"==a.circularLinkType&&(a.y0=e.y1-n-a.width/2),n+=a.width}})}(h),function(e){e.nodes.forEach(function(e){var t=e.targetLinks.slice().sort(function(e,t){return e.index-t.index});t.length>1&&t.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!Ox(e,t))return e.y0-t.y0;if(t.source.column<e.source.column){var i=vx(t,e);return e.y0-i}if(e.source.column<t.source.column)return vx(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;t.forEach(function(e){e.y1=i+e.width/2,i+=e.width});for(var r=0,n=t.length-1;n>=0;n--){var o=t[n];"bottom"==o.circularLinkType&&(o.y1=e.y1-r-o.width/2),r+=o.width}})}(h),function(e){var t=e.nodes,i=e.links,r=!1,n=!1;if(i.forEach(function(e){"top"==e.circularLinkType?r=!0:"bottom"==e.circularLinkType&&(n=!0)}),0==r||0==n){let r=function(t){return(t-o)/(a-o)*(e.y1-e.y0)+e.y0};var o=Yx(t,function(e){return e.y0}),a=qx(t,function(e){return e.y1}),s=a-o,l=(e.y1-e.y0)/s;l<1?(t.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1)}),i.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,i=r(e.y0)-e.y0;e.y0=r(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+i}),e.targetLinks.forEach(function(e){e.y1=e.y1+i})})}}(h),Wx(h,s,d,10,8)}(f),f}return f.update=function(e){return tb(e),Wx(e,s,d,10,8),e},f.nodeWidth=function(e){return arguments.length?(n=+e,f):n},f.nodePadding=function(e){return arguments.length?(o=+e,f):o},f.nodePaddingRatio=function(e){return arguments.length?(a=+e,f):a},f.nodes=function(e){return arguments.length?(h="function"==typeof e?e:Ux(e),f):h},f.links=function(e){return arguments.length?(p="function"==typeof e?e:Ux(e),f):p},f.nodeId=function(e){return arguments.length?(s="function"==typeof e?e:Ux(e),f):s},f.nodeAlign=function(e){return arguments.length?(l="function"==typeof e?e:Ux(e),f):l},f.nodeSort=function(e){return arguments.length?(c=e,f):c},f.iterations=function(e){return arguments.length?(u=+e,f):u},f.circularLinkGap=function(e){return arguments.length?(d=+e,f):d},f.extent=function(n){return arguments.length?(e=+n[0][0],t=+n[0][1],i=+n[1][0],r=+n[1][1],f):[[e,t],[i,r]]},f.size=function(n){return arguments.length?(e=t=0,i=+n[0],r=+n[1],f):[i-e,r-t]},f}import{interpolateNumber as rb}from"d3-interpolate";function nb(e){let{sx:t,sTop:i,sBot:r,tx:n,tTop:o,tBot:a,cp1X:s,cp2X:l}=e,c=(i+r)/2,u=(o+a)/2;return{pathD:[`M${t},${i}`,`C${s},${i} ${l},${o} ${n},${o}`,`L${n},${a}`,`C${l},${a} ${s},${r} ${t},${r}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:s,y:c},{x:l,y:u},{x:n,y:u}],halfWidth:(r-i)/2}}}var ob=e=>{let{source:t,target:i}=e;if("string"==typeof t||"string"==typeof i)return null;if("down"===e.direction){let r=e.y0-e.sankeyWidth/2,n=e.y1-e.sankeyWidth/2,o=e.y1+e.sankeyWidth/2,a=e.y0+e.sankeyWidth/2,s=t.x1,l=i.x0,c=rb(s,l),u=c(.5),d=c(.5);return`M${r},${s}C${r},${u} ${n},${d} ${n},${l}L${o},${l}C${o},${d} ${a},${u} ${a},${s}Z`}let r=e.sankeyWidth/2,n=rb(t.x1,i.x0),{pathD:o}=nb({sx:t.x1,sTop:e.y0-r,sBot:e.y0+r,tx:i.x0,tTop:e.y1-r,tBot:e.y1+r,cp1X:n(.5),cp2X:n(.5)});return o};function ab(e){let t=e.circularPathData;if(!t)return null;let i=e.sankeyWidth/2,r="bottom"===e.circularLinkType?1:-1,n=1===r?1:0,o="down"===e.direction,a=(e,t)=>o?`${t},${e}`:`${e},${t}`,s=(e,t,i,r,n)=>`A${o?t:e},${o?e:t} 0 0 ${o?1-i:i} ${a(r,n)}`,{sourceX:l,sourceY:c,targetX:u,targetY:d,rightInnerExtent:h,leftInnerExtent:p,rightFullExtent:f,leftFullExtent:g,verticalFullExtent:m,verticalRightInnerExtent:y,verticalLeftInnerExtent:x,rightLargeArcRadius:b,rightSmallArcRadius:v,leftLargeArcRadius:w,leftSmallArcRadius:k}=t;return`M${a(l,c-r*i)}L${a(h,c-r*i)}`+s(b+i,v+i,n,f+i,c+r*v)+`L${a(f+i,y)}`+s(b+i,b+i,n,h,m+r*i)+`L${a(p,m+r*i)}`+s(w+i,w+i,n,g-i,x)+`L${a(g-i,d+r*k)}`+s(w+i,k+i,n,p,d-r*i)+`L${a(u,d-r*i)}L${a(u,d+r*i)}L${a(p,d+r*i)}`+s(w-i,k-i,1-n,g+i,d+r*k)+`L${a(g+i,x)}`+s(w-i,w-i,1-n,p,m-r*i)+`L${a(h,m-r*i)}`+s(b-i,b-i,1-n,f-i,y)+`L${a(f-i,c+r*v)}`+s(b-i,v-i,1-n,h,c+r*i)+`L${a(l,c+r*i)}Z`}var sb=/*#__PURE__*/new Set,lb=/*#__PURE__*/new WeakMap;function cb(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let i=lb.get(e);if(i){let e=i.get(t);if(e)return e}else i=new Map,lb.set(e,i);let r=new Proxy(e,{get(e,i,r){if("string"==typeof i&&!(i in e)&&e.data&&i in e.data){let e=`${t}:${i}`;sb.has(e)||(sb.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${i}" on the wrapper object, but it only exists on ".data". Use d.data.${i} (or d.data?.${i}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,i,r)}});return i.set(t,r),r}var ub={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(_x))-1:0},justify:Px},db={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeAlign||"justify",a=i.nodeWidth??15,s=i.nodePaddingRatio??.05,l=i.iterations??300;for(let e of t)e.sankeyWidth=0,e.circular=!1,delete e.circularPathData,delete e._circularWidth,delete e._circularStub;for(let t of e)t.value=0,t.width=t.height=0,t.x0=t.x1=t.y0=t.y1=0,t.sourceLinks=[],t.targetLinks=[];let c=new Set(e.map(e=>e.id)),u=new Set,d=t.filter(e=>{let t=U(e.source),i=U(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!c.has(t)||!c.has(i)||(u.add(t),u.add(i),0))}).map(e=>({...e,source:U(e.source),target:U(e.target)}));if(0===d.length)return;let h,p=e.filter(e=>u.has(e.id)).map(e=>({...e}));h="down"===n?[[0,0],[r[1],r[0]]]:[[0,0],[r[0],r[1]]];let f=ib().extent(h).links(d).nodes(p).nodeAlign(ub[o]||Px).nodeId(e=>e.id).nodeWidth(a).iterations(l);f.nodePaddingRatio&&f.nodePaddingRatio(s),f();{let e=1/0,t=-1/0,i=1/0,r=-1/0;for(let n of p)n.x0<e&&(e=n.x0),n.x1>t&&(t=n.x1),n.y0<i&&(i=n.y0),n.y1>r&&(r=n.y1);for(let n of d){if(!n.circular||!n.circularPathData)continue;let o=n.circularPathData,a=(n._circularWidth??n.width??0)/2;o.leftFullExtent-a<e&&(e=o.leftFullExtent-a),o.rightFullExtent+a>t&&(t=o.rightFullExtent+a),o.verticalFullExtent-a<i&&(i=o.verticalFullExtent-a),o.verticalFullExtent+a>r&&(r=o.verticalFullExtent+a)}let n=t-e,o=r-i,a=h[1][0],s=h[1][1];if(n>0&&o>0&&(e<0||i<0||t>a||r>s)){let t=a/n,r=s/o,l=Math.min(t,r),c=-e*l+(a-n*l)/2,u=-i*l+(s-o*l)/2;for(let e of p)e.x0=e.x0*l+c,e.x1=e.x1*l+c,e.y0=e.y0*l+u,e.y1=e.y1*l+u;for(let e of d)if(e.y0=e.y0*l+u,e.y1=e.y1*l+u,e.width=(e.width??0)*l,e._circularWidth&&(e._circularWidth*=l),e.circular&&e.circularPathData){let t=e.circularPathData;t.sourceX=t.sourceX*l+c,t.targetX=t.targetX*l+c,t.sourceY=t.sourceY*l+u,t.targetY=t.targetY*l+u,t.rightFullExtent=t.rightFullExtent*l+c,t.leftFullExtent=t.leftFullExtent*l+c,t.verticalFullExtent=t.verticalFullExtent*l+u,t.rightInnerExtent=t.rightInnerExtent*l+c,t.leftInnerExtent=t.leftInnerExtent*l+c,t.verticalRightInnerExtent=t.verticalRightInnerExtent*l+u,t.verticalLeftInnerExtent=t.verticalLeftInnerExtent*l+u,t.rightSmallArcRadius*=l,t.rightLargeArcRadius*=l,t.leftSmallArcRadius*=l,t.leftLargeArcRadius*=l,t.sourceWidth*=l,t.rightNodeBuffer*=l,t.leftNodeBuffer*=l,t.arcRadius*=l}}}let g=new Map;for(let t of e)g.set(t.id,t);for(let e of p){let t=g.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}let m=new Map;for(let e of t)if(e._edgeKey)m.set(e._edgeKey,e);else{let t=U(e.source),i=U(e.target);m.set(`${t}\0${i}`,e)}for(let e of d){let t=U(e.source),i=U(e.target),r=e._edgeKey?m.get(e._edgeKey):m.get(`${t}\0${i}`);if(r){r.y0=e.y0,r.y1=e.y1,r.sankeyWidth=e.width??0,r.circular=!!e.circular,r.circularPathData=e.circularPathData,r._circularWidth=e._circularWidth,r._circularStub=e._circularStub,r.path=e.path,r.circularLinkType=e.circularLinkType,r.direction=n;let o=g.get(t),a=g.get(i);o&&(r.source=o),a&&(r.target=a)}}},buildScene(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeStyle,a=i.edgeStyle,s=i.edgeOpacity??.5,l=i.edgeColorBy||"source",c=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Tt,u=new Map;e.forEach((e,t)=>{u.set(e.id,c[t%c.length])});let d=[],h=[],p=[],f=new Map;for(let t of e){let e=t.x1-t.x0,i=t.y1-t.y0;if(t.value<=0||e<=0||i<=0)continue;let r=o?o(cb(t,"nodeStyle")):{},a={fill:r.fill||u.get(t.id)||"#4d430c",stroke:r.stroke,strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor};f.set(t.id,("string"==typeof a.fill?a.fill:null)||u.get(t.id)||"#4d430c");let s={...t.data,value:t.data?.value??t.value};"down"===n?d.push({type:"rect",x:t.y0,y:t.x0,w:i,h:e,style:a,accessibleDatum:s,datum:t,id:t.id,label:t.id}):d.push({type:"rect",x:t.x0,y:t.y0,w:e,h:i,style:a,accessibleDatum:s,datum:t,id:t.id,label:t.id})}let g=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let e of g){if(!(e.value>0)||!e.sankeyWidth||e.sankeyWidth<=0)continue;let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof l?l(e)||n:"target"===l?f.get(r.id)||u.get(r.id)||n:f.get(t.id)||u.get(t.id)||n;let o,c=a?a(cb(e,"edgeStyle")):{};if(o=e.circular&&e.circularPathData?ab(e):ob(e),!o)continue;let d={fill:c.fill||n,fillOpacity:c.fillOpacity??s,stroke:c.stroke||"none",strokeWidth:c.strokeWidth,strokeOpacity:c.strokeOpacity,opacity:c.opacity,cursor:c.cursor};h.push({type:"bezier",pathD:o,bezierCache:e.bezier,style:d,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=H(i.nodeLabel);for(let i of e){let e=i.x1-i.x0,o=i.y1-i.y0;if(i.value<=0||e<=0||o<=0)continue;let a,s,l,c=t?t(i):i.id;if(c){if("down"===n)a=i.y0+(i.y1-i.y0)/2,s=i.x1+14,l="start";else{let t=r[0]/2;i.x0+e/2<t?(a=i.x0-6,l="end"):(a=i.x1+6,l="start"),s=i.y0+o/2}p.push({x:a,y:s,text:String(c),anchor:"down"===n?"middle":l,baseline:"middle",fontSize:11})}}}return{sceneNodes:d,sceneEdges:h,labels:p}}};import{forceSimulation as hb,forceCenter as pb,forceX as fb,forceY as gb,forceLink as mb,forceManyBody as yb,forceCollide as xb}from"d3-force";import{scaleLinear as bb}from"d3-scale";function vb(e,t,i){if(i.some(e=>null!=e.__forceRadius))return e=>e.__forceRadius??8;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;let r=t||[5,20],n=[];for(let t of i){let i=t.data?.[e];"number"==typeof i&&n.push(i)}if(0===n.length)return()=>r[0];let[o,a]=le(n);if(o===a)return()=>(r[0]+r[1])/2;let s=bb().domain([o,a]).range(r).clamp(!0);return t=>{let i=t.data?.[e];return null==i||"number"!=typeof i?r[0]:s(i)}}var wb={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let n=i.forceStrength??.1,o=r[0]/2,a=r[1]/2,s=Math.max(.1,Math.min(1,Math.min(r[0],r[1])/200)),l=Math.min(.5,.06+1.8*(1-s)),c=i.__previousPositions,u=0,d=[];for(let t of e){let e=!1!==t.__hasPosition&&Number.isFinite(t.x)&&Number.isFinite(t.y),i=c?.get(t.id);e?u++:i?(t.x=i.x,t.y=i.y,u++):d.push(t)}let h=e.length>0?d.length/e.length:1,p=u>0&&h<=.3;if(p){let i=new Map;for(let t of e)i.set(t.id,t);for(let e of d){let r=kb(e.id,t,i);if(r.length>0){let t=0,i=0;for(let e of r)t+=e.x,i+=e.y;let n=Sb(e.id),o=n%360*(Math.PI/180),a=(10+n%20)*s;e.x=t/r.length+a*Math.cos(o),e.y=i/r.length+a*Math.sin(o)}else{let t=Sb(e.id),i=t%360*(Math.PI/180),r=(15+t%30)*s;e.x=o+r*Math.cos(i),e.y=a+r*Math.sin(i)}}}else{let t=Math.PI*(3-Math.sqrt(5));for(let i=0;i<e.length;i++){let r=e[i];if(!1===r.__hasPosition||!Number.isFinite(r.x)||!Number.isFinite(r.y)){let e=10*Math.sqrt(i+.5)*s,n=i*t;r.x=o+e*Math.cos(n),r.y=a+e*Math.sin(n)}}}for(let t of e)t.__hasPosition=!0;let f=e.length,g=i.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(f-30)))),m=i.__skipForceSimulation||0===i.iterations?0:p?40:g,y=vb(i.nodeSize,i.nodeSizeRange,e);if(m>0){let c=new Map,u=new Map;for(let t of e)c.set(t.id,0),u.set(t.id,t);for(let e of t){let t=U(e.source),i=U(e.target);c.set(t,(c.get(t)??0)+1),c.set(i,(c.get(i)??0)+1)}let d=mb().strength(e=>{let t=function(e){let t=e.data?.weight??e.weight;return"number"==typeof t&&Number.isFinite(t)?t:Number.isFinite(e.value)?e.value:1}(e),i=U(e.source),r=U(e.target),o=Math.max(1,Math.min(c.get(i)??1,c.get(r)??1)),a=t&&t>0?Math.sqrt(t):1;return Math.min(2.5,a*n/(.1*o))}).distance(e=>{let t="string"==typeof e.source?u.get(e.source):e.source,i="string"==typeof e.target?u.get(e.target):e.target,r=(t?y(t):0)+(i?y(i):0)+Math.max(6,12*s);return Math.max(16,40*s,r)}).id(e=>e.id),h=hb();if((void 0!==i.random||void 0!==i.seed)&&h.randomSource(i.random??function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(i.seed)),h.force("charge",yb().strength(e=>{let t=c.get(e.id)??0;return-15*s*y(e)*Math.sqrt(t+1)})).force("collide",xb(e=>y(e)+3*s).strength(.9).iterations(2)).force("center",pb(o,a).strength(.8)).force("x",fb(o).strength(l)).force("y",gb(a).strength(l)).force("bounds",function(e,t,i=2,r=.6){let n=[],o=o=>{let a=r*Math.max(o,.2);for(let r of n){let n=r.x??e[0]/2,o=r.y??e[1]/2,s=r.vx??0,l=r.vy??0,c=t(r)+i,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),h=Math.min(e[1]/2,c),p=Math.max(e[1]/2,e[1]-c),f=n+s,g=o+l;f<u?r.vx=s+(u-f)*a:f>d&&(r.vx=s+(d-f)*a),g<h?r.vy=l+(h-g)*a:g>p&&(r.vy=l+(p-g)*a)}};return o.initialize=e=>{n=e},o}(r,y)),h.nodes(e),t.length>0){let e=t.map(e=>({...e,source:U(e.source),target:U(e.target)}));d.links(e),h.force("link",d)}p?h.alpha(.3):h.alpha()<.1&&h.alpha(1),h.stop();for(let e=0;e<m;++e)h.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=y(t),i=m>0?2:0,n=Math.min(r[0]/2,e+i),o=Math.min(r[1]/2,e+i);t.x=Math.max(n,Math.min(r[0]-n,t.x)),t.y=Math.max(o,Math.min(r[1]-o,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let x=new Map;for(let t of e)x.set(t.id,t);for(let e of t){if("string"==typeof e.source){let t=x.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=x.get(e.target);t&&(e.target=t)}}},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=vb(i.nodeSize,i.nodeSizeRange,e),s=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Tt,l=new Map;e.forEach((e,t)=>{l.set(e.id,s[t%s.length])});let c=[],u=[],d=[];for(let t of e){if(null==t.x||null==t.y)continue;let e=a(cb(t,"nodeSize")),r=n?n(cb(t,"nodeStyle")):{},o={fill:r.fill||l.get(t.id)||i.themeSemantic?.primary||"#007bff",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??2,opacity:r.opacity,cursor:r.cursor};c.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,accessibleDatum:t.data,datum:t,id:t.id,label:t.id})}let h=new Map;for(let t of e)h.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:h.get(e.source),r="object"==typeof e.target?e.target:h.get(e.target);if(!t||!r||null==t.x||null==t.y||null==r.x||null==r.y)continue;let n=o?o(cb(e,"edgeStyle")):{},a={stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor};u.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:a,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=H(i.nodeLabel);for(let i of e){if(null==i.x||null==i.y)continue;let e=t?t(i):i.id;if(!e)continue;let r=a(cb(i,"nodeSize"));d.push({x:i.x,y:i.y-r-4,text:String(e),anchor:"middle",baseline:"auto",fontSize:11,anchorPoint:[i.x,i.y]})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function kb(e,t,i){let r=[];for(let n of t){let t=U(n.source),o=U(n.target),a=null;if(t===e?a=o:o===e&&(a=t),a){let e=i.get(a);e&&(0!==e.x||0!==e.y)&&r.push({x:e.x,y:e.y})}}return r}function Sb(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return Math.abs(t)}import{chord as Ab,ribbon as Mb}from"d3-chord";import{arc as $b}from"d3-shape";var _b=Tt,Pb={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,i,r){for(let t of e)delete t.__arcData;for(let e of t)delete e.__chordData,delete e.__chordEdges;if(0===e.length)return;let{padAngle:n=.01,groupWidth:o=20,sortGroups:a}=i,s=Math.min(r[0],r[1])/2,l=s-o,c=r[0]/2,u=r[1]/2,d=new Map(e.map(e=>[e.id,e])),h=new Set,p=t.filter(e=>{let t=U(e.source),i=U(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!d.has(t)||!d.has(i)||(h.add(t),h.add(i),0))}),f=e.filter(e=>h.has(e.id)),g=f.length;if(0===g)return;let m=new Map(f.map((e,t)=>[e.id,t])),y=Array.from({length:g},()=>new Array(g).fill(0)),x=new Map;for(let e of p){let t=U(e.source),i=U(e.target),r=m.get(t),n=m.get(i);y[r][n]+=e.value;let o=r<=n?`${r}\0${n}`:`${n}\0${r}`,a=x.get(o);a?a.push(e):x.set(o,[e])}let b=Math.min(Number.isFinite(n)?Math.max(0,n):.01,Math.PI/g),v=Ab().padAngle(b);a&&v.sortGroups(a);let w=v(y),k=w.groups,S=$b().innerRadius(l).outerRadius(s);for(let e of k){let t=f[e.index],i={innerRadius:l,outerRadius:s,startAngle:e.startAngle,endAngle:e.endAngle},r=S.centroid(i);t.x=r[0]+c,t.y=r[1]+u,t.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}for(let e of t){let t=U(e.source),i=U(e.target),r=d.get(t),n=d.get(i);r&&(e.source=r),n&&(e.target=n)}for(let e of w){let t=e.source.index,i=e.target.index,r=t<=i?`${t}\0${i}`:`${i}\0${t}`,n=x.get(r);for(let t of n)t.__chordData=e,t.__chordEdges=n}},buildScene(e,t,i,r){let{groupWidth:n=20,edgeOpacity:o=.5}=i,a=Math.min(r[0],r[1])/2,s=a-n,l=r[0]/2,c=r[1]/2,u=i.nodeStyle,d=i.edgeStyle,h=i.edgeColorBy||"source",p=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:_b,f=new Map;e.forEach((e,t)=>{f.set(e.id,p[t%p.length])});let g=Mb().radius(s),m=[],y=[],x=[];for(let t=0;t<e.length;t++){let i=e[t],r=i.__arcData;if(!r)continue;let n=u?u(cb(i,"nodeStyle")):{},o={fill:("string"==typeof n.fill?n.fill:void 0)||f.get(i.id)||p[t%p.length],stroke:n.stroke||"black",strokeWidth:n.strokeWidth??1,opacity:n.opacity,cursor:n.cursor};m.push({type:"arc",cx:l,cy:c,innerR:s,outerR:a,startAngle:r.startAngle-Math.PI/2,endAngle:r.endAngle-Math.PI/2,style:o,accessibleDatum:i.data,datum:i,id:i.id,label:i.id})}let b=new Set,v=e.filter(e=>e.__arcData);for(let e of t){let t=e.__chordData;if(!t||b.has(t))continue;b.add(t);let r=v[t.source.index].id;for(let t of e.__chordEdges||[])U(t.source)===r&&(e=t);let n=g(t);if(!n)continue;let a=Ib(n,l,c),s=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",u=d?d(cb(e,"edgeStyle")):{};if(d)s=("string"==typeof u.fill?u.fill:void 0)||s;else{let t="object"==typeof e.source?e.source:null,i="object"==typeof e.target?e.target:null;"target"===h&&i?s=f.get(i.id)||s:t&&(s=f.get(t.id)||s)}let p={fill:s,fillOpacity:u.fillOpacity??o,stroke:u.stroke||"none",strokeWidth:u.strokeWidth,strokeOpacity:u.strokeOpacity,opacity:u.opacity,cursor:u.cursor};y.push({type:"ribbon",pathD:a,style:p,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=H(i.nodeLabel),r=a+12;for(let i of e){let e=i.__arcData;if(!e)continue;let n=t?t(i):i.id;if(!n)continue;let o=(e.startAngle+e.endAngle)/2,a=o-Math.PI/2,s=l+Math.cos(a)*r,u=c+Math.sin(a)*r,d=o>Math.PI?"end":"start";x.push({x:s,y:u,text:String(n),anchor:d,baseline:"middle",fontSize:11})}}return{sceneNodes:m,sceneEdges:y,labels:x}}};function Ib(e,t,i){let r=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!r)return e;let n=[],o=0;for(;o<r.length;){let e=r[o];if("M"===e||"L"===e||"C"===e||"Q"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(String(Number(r[o])+t)),o++,o<r.length&&!isNaN(Number(r[o]))&&(n.push(String(Number(r[o])+i)),o++);else if("A"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&(n.push(String(Number(r[o])+t)),o++),o<r.length&&(n.push(String(Number(r[o])+i)),o++);else"Z"===e||"z"===e?(n.push(e),o++):(n.push(r[o]),o++)}return n.join(" ")}import{hierarchy as Tb,tree as Lb,cluster as Cb,treemap as Rb,pack as Nb,partition as Db,treemapBinary as Fb}from"d3-hierarchy";var Eb=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Ob(e){let[t,i,r]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[0,2,4].map(e=>parseInt(t.slice(e,e+2),16))}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*i+.114*r>150?"#222":"#fff"}function zb(e){if(e)return"function"==typeof e?e:t=>t[e]}function Bb(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function jb(e){let t=new Map(e.map(e=>[e,0]));return e.map(e=>{let i=t.get(e),r=e;for(;i>0&&t.has(r);)r=`${e}__${i++}`;return t.set(e,i||1),t.set(r,1),r})}function Wb(e,t,i){if(t.colorByDepth&&void 0!==e.depth){let i=function(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:Eb}(t);return i[e.depth%i.length]}return i||function(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}(t)}function Yb(e,t,i){return{fill:Wb(e,t,i.fill),stroke:i.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity,cursor:i.cursor}}function qb(e){return!e.__hierarchyNode?.children?.length}function Xb(e,t,i,r,n){let o=(e+i)/2,a=(t+r)/2;return"horizontal"===n?`M ${e},${t} C ${o},${t} ${o},${r} ${i},${r}`:"radial"===n?`M ${e},${t} Q ${o},${t} ${o},${a} T ${i},${r}`:`M ${e},${t} C ${e},${a} ${i},${a} ${i},${r}`}var Gb={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;if(!n)return;let o=i.chartType,a=zb(i.childrenAccessor),s=Tb(n,a),l=[];s.eachBefore(e=>l.push(e));let c=jb(l.map((e,t)=>function(e,t,i){let r=t.nodeIDAccessor,n=e.data;return String("function"==typeof r?r(n):"string"==typeof r&&void 0!==n[r]?n[r]:void 0!==n.name?n.name:void 0!==n.id?n.id:`node-${i}`)}(e,i,t)));s.sum(function(e="value"){let t="function"==typeof e?e:t=>t[e];return e=>{let i=t(e),r="string"==typeof i?Number(i):i;return Number.isFinite(r)&&r>0?r:0}}(i.hierarchySum)).sort((e,t)=>t.value-e.value);let[u,d]=r;switch(o){case"tree":case"cluster":!function(e,t,i,r){let n=t.treeOrientation||"vertical",o="cluster"===t.chartType?Cb():Lb();if("horizontal"===n)o.size([r,i]);else if("radial"===n){let e=Math.min(i,r)/2;o.size([2*Math.PI,.8*e])}else o.size([i,r]);o(e)}(s,i,u,d);break;case"treemap":case"partition":!function(e,t,i,r){let n="treemap"===t.chartType,o=n?Rb().tile(Fb):Db();o.size([i,r]).padding(t.padding??(n?4:1)),"paddingTop"in o&&t.paddingTop>0&&o.paddingTop(t.paddingTop),o(e)}(s,i,u,d);break;case"circlepack":!function(e,t,i,r){let n=t.padding??4,o=Nb().size([i,r]).padding(n);e.leaves().some(e=>e.value)||o.radius(()=>0).padding(0),o(e)}(s,i,u,d)}let h=s.descendants();e.length=0,t.length=0;let p=new Map(l.map((e,t)=>[e,{id:c[t],x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:e.value,depth:e.depth,data:e.data,createdByFrame:!0}]));for(let t of h){let r=p.get(t);"tree"===o||"cluster"===o?Vb(r,t,i):"treemap"===o||"partition"===o?Hb(r,t):"circlepack"===o&&Ub(r,t),r.__hierarchyNode=t,e.push(r)}if("tree"===o||"cluster"===o)for(let e of h)if(e.parent){let i=p.get(e.parent),r=p.get(e);t.push({source:i,target:r,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,i,r){let n=i.chartType,o=i.nodeStyle||(()=>({})),a=i.edgeStyle||(()=>({}));switch(n){case"tree":case"cluster":return function(e,t,i,r,n,o){let a=[],s=[],l=[],c=i.treeOrientation||"vertical",u="radial"===c,d=r[0]/2,h=r[1]/2,{nodeSize:p}=i,f="number"==typeof p?p:5;for(let t of e){let e=t.x,r=t.y;u&&(e+=d,r+=h);let o=Yb(t,i,n(cb(t,"nodeStyle")));a.push({type:"circle",cx:e,cy:r,r:f,style:o,accessibleDatum:{...t.data,value:t.data?.value??t.value},datum:t,id:t.id,label:t.id,depth:t.depth})}let g=i.edgeOpacity??.5;for(let e of t){let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=t.x,a=t.y,l=r.x,p=r.y;u&&(n+=d,a+=h,l+=d,p+=h);let f=Xb(n,a,l,p,c),m=o(cb(e,"edgeStyle")),y={fill:"none",stroke:m.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:m.strokeWidth??1.5,opacity:m.opacity??g,cursor:m.cursor};s.push({type:"curved",pathD:f,style:y,datum:e})}if(!1!==i.showLabels){let t=Bb(i.nodeLabel);for(let i of e){let e=t?t(i):i.id;if(!e)continue;let r,n,o,a=i.x,s=i.y;if(u&&(a+=d,s+=h),u){let e=a-d,t=s-h,i=Math.sqrt(e*e+t*t);i>0?(r=a+e/i*10,n=s+t/i*10,o=e>=0?"start":"end"):(r=a,n=s-12,o="middle")}else"horizontal"===c?(qb(i)?(r=a+f+6,o="start"):(r=a-f-6,o="end"),n=s):(r=a,n=s+f+14,o="middle");l.push({x:r,y:n,text:String(e),anchor:o,baseline:"middle",fontSize:11,anchorPoint:[a,s]})}}return{sceneNodes:a,sceneEdges:s,labels:l}}(e,t,i,r,o,a);case"treemap":case"partition":return function(e,t,i){let r=[],n=[];for(let n of e){let e=n.x1-n.x0,o=n.y1-n.y0;if(e<=0||o<=0)continue;let a=i(cb(n,"nodeStyle")),s=Yb(n,t,a);s.fillOpacity=a.fillOpacity,s.strokeOpacity=a.strokeOpacity,r.push({type:"rect",x:n.x0,y:n.y0,w:e,h:o,style:s,accessibleDatum:{...n.data,value:n.data?.value??n.value},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=Bb(t.nodeLabel),o=t.labelMode||"leaf",a="partition"===t.chartType;for(let s of e){let e=s.x1-s.x0,l=s.y1-s.y0;if(e<=0||l<=0)continue;let c=qb(s);if(!a&&("leaf"===o&&!c||"parent"===o&&c))continue;let u=r?r(s):s.id;if(!u)continue;if(e<(c?30:40)||l<(c?16:14))continue;let d=Wb(s,t,i(cb(s,"nodeStyle")).fill),h="string"==typeof d?Ob(d):t.themeSemantic?.text??"#000";c?n.push({x:s.x0+e/2,y:s.y0+l/2,text:String(u),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,l)/6)),fill:h}):n.push({x:s.x0+4,y:s.y0+12,text:String(u),anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:r,sceneEdges:[],labels:n}}(e,i,o);case"circlepack":return function(e,t,i){let r=[],n=[];for(let n of e){let e=n.__radius??5;if(e<=0)continue;let o=Yb(n,t,i(cb(n,"nodeStyle")));o.opacity??(o.opacity=.7),r.push({type:"circle",cx:n.x,cy:n.y,r:e,style:o,accessibleDatum:{...n.data,value:n.data?.value??n.value},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=Bb(t.nodeLabel);for(let o of e){let e=o.__radius??5,a=r?r(o):o.id;if(!a||e<15)continue;let s=qb(o),l=Wb(o,t,i(cb(o,"nodeStyle")).fill);if(s){let i="string"==typeof l?Ob(l):t.themeSemantic?.text??"#000";n.push({x:o.x,y:o.y,text:String(a),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:i})}else n.push({x:o.x,y:o.y-e+14,text:String(a),anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:r,sceneEdges:[],labels:n}}(e,i,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Vb(e,t,i){let r=i.treeOrientation||"vertical";if("radial"===r){let i=t.x,r=t.y;e.x=r*Math.cos(i-Math.PI/2),e.y=r*Math.sin(i-Math.PI/2)}else"horizontal"===r?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);Zb(e,5)}function Hb(e,t){e.x0=t.x0,e.y0=t.y0,e.x1=e.value?t.x1:t.x0,e.y1=e.value?t.y1:t.y0,e.x=(e.x0+e.x1)/2,e.y=(e.y0+e.y1)/2,e.width=e.x1-e.x0,e.height=e.y1-e.y0}function Ub(e,t){let i=t.r??0;e.x=t.x,e.y=t.y,Zb(e,i),e.__radius=i}function Zb(e,t){e.x0=e.x-t,e.x1=e.x+t,e.y0=e.y-t,e.y1=e.y+t,e.width=2*t,e.height=2*t}var Kb=/*#__PURE__*/new WeakMap;import{pie as Qb}from"d3-shape";function Jb(e,t){if(!e)return[];let i=[],r=e=>{i.push(e);let n="function"==typeof t?t(e):e[t];n&&Array.isArray(n)&&n.forEach(r)};return r(e),i}function ev(e,t,i,r){if(e&&e.length>0)return e;let n=new Set;return t.forEach(e=>{let t="function"==typeof i?i(e):e[i],o="function"==typeof r?r(e):e[r];n.add(t),n.add(o)}),Array.from(n).map(e=>({id:e}))}function tv(e){return function(e,t){let i=Kb.get(e);return i||(i=new Map,Kb.set(e,i)),i.has(t)||i.set(t,{metaMap:new Map,startTime:typeof performance<"u"?performance.now():Date.now()}),i.get(t)}(e,"orbit")}var iv={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;n&&function(e,t,i,r,n){let o=zb(i.childrenAccessor||"children"),a=function(e){if("function"==typeof e)return e;let t=e||"name";return e=>String(e[t]??"")}(i.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(i.orbitMode),l=i.orbitSize??2.95,c=i.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=tv(i);h.metaMap.clear(),r.length=0,n.length=0;let p=jb(Jb(e,o).map(e=>String(a(e)))),f=0,g=t[0]/2,m=t[1]/2,y=Math.min(t[0],t[1])/2*.85,x=p[f++],b={id:x,x:g,y:m,x0:g,x1:g,y0:m,y1:m,width:0,height:0,value:0,depth:0,data:e};r.push(b),h.metaMap.set(x,{ring:y,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,i,a,l,c,g,m){let y=o(t);if(!y?.length)return;let x=y.length,b=0,v=0,w=0;for(;v<x;)v+=s[Math.min(w,s.length-1)],w++,b++;let k=0;for(let x=0;x<b;x++){let v=s[Math.min(x,s.length-1)],w=y.slice(k,k+v);if(!w.length)break;let S=(x+1)/b,A={id:i,depth:g,data:t,parentId:i},M=m?c/u(A)*S:c*S,$=Qb().value(e=>o(e)?.length?4:1).sort(null)(w),_=d(A);for(let t=0;t<w.length;t++){let o=($[t].startAngle+$[t].endAngle)/2,s=w[t],c=p[f++],u=a+M*Math.sin(o),d=l+M*Math.cos(o)*_,m={id:c,x:u,y:d,x0:u,x1:u,y0:d,y1:d,width:0,height:0,value:0,depth:g,data:s};r.push(m),h.metaMap.set(c,{ring:M,angle:o,depth:g,parentId:i,eccentricity:_}),n.push({source:i,target:c,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:i,target:c}}),e(s,c,u,d,M,g+1,!0)}k+=v}}(e,x,g,m,y,1,!1)}(n,r,i,e,t)},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=i.nodeSize,s="number"==typeof a?()=>a:"function"==typeof a?a:()=>6,l=[],c=[],u=[];if(!1!==i.orbitShowRings){let t=tv(i),r=new Map;for(let t of e)r.set(t.id,t);let n=new Map;for(let[,e]of t.metaMap){if(!e.parentId)continue;let t=r.get(e.parentId);if(!t)continue;let i=`${e.parentId}:${e.ring}`;n.has(i)||n.set(i,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}let o=48,a={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:i,ecc:r}]of n)for(let n=0;n<o;n++){let s=n/o*Math.PI*2,l=(n+1)/o*Math.PI*2;c.push({type:"line",x1:e+i*Math.sin(s),y1:t+i*Math.cos(s)*r,x2:e+i*Math.sin(l),y2:t+i*Math.cos(l)*r,style:a,interactive:!1,datum:null})}}for(let t of e){if(null==t.x||null==t.y)continue;let e=s(cb(t,"nodeSize")),r=n?n(cb(t,"nodeStyle")):{},o={fill:r.fill||i.themeSemantic?.primary||"#6366f1",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??(0===(t.depth??0)?1:.85),cursor:r.cursor};l.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,accessibleDatum:t.data,datum:t,id:t.id,label:t.id,depth:t.depth})}let d=new Map;for(let t of e)d.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:d.get(e.source),i="object"==typeof e.target?e.target:d.get(e.target);if(!t||!i||null==t.x||null==i.x)continue;let r=o?o(cb(e,"edgeStyle")):{},n={stroke:r.stroke||"rgba(128,128,128,0.35)",strokeWidth:r.strokeWidth??.5,opacity:r.opacity??1,cursor:r.cursor};c.push({type:"line",x1:t.x,y1:t.y,x2:i.x,y2:i.y,style:n,datum:e})}if(i.showLabels){let t=i.nodeLabel;for(let i of e){let e=s(cb(i,"nodeSize"));if(e<=4)continue;let r="function"==typeof t?t(i):t?i.data?.[t]??i.id:i.id;u.push({x:i.x,y:i.y+e+12,text:String(r),anchor:"middle",fontSize:10,fill:"currentColor",anchorPoint:[i.x,i.y]})}}return{sceneNodes:l,sceneEdges:c,labels:u}},tick:(e,t,i,r,n)=>!1!==i.orbitAnimated&&(function(e,t){let i=tv(t),r=t.orbitSpeed??.25,n=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),o=((typeof performance<"u"?performance.now():Date.now())-i.startTime)/1e3,a=r*(Math.PI/6),s=new Map;for(let t of e)s.set(t.id,t);for(let t of e){let e=i.metaMap.get(t.id);if(!e||!e.parentId)continue;let r=s.get(e.parentId);if(!r)continue;let l={id:t.id,depth:e.depth,data:t.data,parentId:e.parentId},c=e.angle+o*a*n(l);t.x=r.x+e.ring*Math.sin(c),t.y=r.y+e.ring*Math.cos(c)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,i),!0)};import*as rv from"react";import{arc as nv}from"d3-shape";import{jsx as ov,jsxs as av}from"react/jsx-runtime";function sv(e,t,i="slab-face"){let r=e.style.fill;return(e.style.opacity??1)<=0||(e.style.fillOpacity??1)<=0||"string"==typeof r&&/^\s*(none|transparent)\s*$|^rgba\(.*,\s*0(\.0+)?\s*\)$|^#[\da-f]{3}0$|^#[\da-f]{6}00$/i.test(r)?null:e.faces?.map((r,n)=>ov("path",{"data-perspective-part":i,"data-perspective-face":n,d:r.pathD,fill:"string"==typeof e.style.fill?a(e.style.fill,r.shade):t,fillOpacity:e.style.fillOpacity,opacity:e.style.opacity},`face-${n}`))}function lv(e,t){return Ha(function(e,t){switch(e.type){case"line":{let i=e;return ov("line",{"data-perspective-part":i._perspectivePart,x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}case"bezier":{let i=e,r=`net-bezier-${t}-hatch`,n=ka(i.style.fill)?Sa(i.style.fill,r):void 0;return av(rv.Fragment,{children:[n&&ov("defs",{children:n}),ov("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:n?`url(#${r})`:za(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"ribbon":{let i=e,r=`net-ribbon-${t}-hatch`,n=ka(i.style.fill)?Sa(i.style.fill,r):void 0;return av(rv.Fragment,{children:[n&&ov("defs",{children:n}),ov("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:n?`url(#${r})`:za(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"curved":{let i=e;return ov("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:za(i.style.fill,"none"),fillOpacity:i.style.fill&&"none"!==i.style.fill?i.style.fillOpacity??.1:void 0,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}default:return null}}(e,t),e,`network-edge-cursor-${t}`)}function cv(e){let t=e.id??e.datum?.id??e.datum?.data?.id??e.datum?.data?.name;return null==t?void 0:String(t)}function uv(e){if("glyph"===e.type&&e.glyph&&"number"==typeof e.size){let t=e.cx??e.x,i=e.cy??e.y;if("number"!=typeof t||"number"!=typeof i)return null;let r=g(e.glyph,e.size);return{x:t+r.centerDx,y:i+r.centerDy,r:Math.max(1,r.radius)}}let t=e.cx??(null!=e.x&&null!=e.w?e.x+e.w/2:e.x),i=e.cy??(null!=e.y&&null!=e.h?e.y+e.h/2:e.y);return"number"!=typeof t||"number"!=typeof i?null:{x:t,y:i,r:"number"==typeof e.r?Math.max(1,e.r):"number"==typeof e.outerR?Math.max(1,e.outerR):"number"==typeof e.size?Math.max(1,c(e.size)):Math.max(1,e.w??0,e.h??0)/2}}function dv(e){if(!e)return;let t=[];for(let i of e){let e=uv(i);e&&t.push({pointId:cv(i),...e})}return t}function hv(e,t=!1){return function(e){return e?._semioticCamera}(e)?.transformRef(t)}import{jsx as pv}from"react/jsx-runtime";var fv={x:0,y:0,k:1};function gv({view:e,width:t,height:i,children:r}){if(!e)return r;let{x:n,y:o,k:a}=function(e){return e&&Number.isFinite(e.k)&&e.k>0&&Number.isFinite(e.x)&&Number.isFinite(e.y)?e:fv}(e);return pv("svg",{role:"presentation",width:t,height:i,overflow:"hidden","data-network-view":"",children:pv("g",{ref:hv(e),transform:`translate(${n},${o}) scale(${a})`,children:r})})}function mv(e,t,i){return"function"==typeof t?t(e):e[t??i]}function yv(e){let t=null==e?NaN:Number(e);return Number.isFinite(t)?t:1}function xv(e,t){return null!=e?String(e):("production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Missing network ${t} ID; skipping this datum.`),null)}import{Fragment as bv,jsx as vv,jsxs as wv}from"react/jsx-runtime";function kv(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Sv([e,t]){return{id:e,__hasPosition:Number.isFinite(t.x)&&Number.isFinite(t.y),x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t,createdByFrame:!0}}function Av(e){return{...e,y0:0,y1:0,sankeyWidth:0}}y(s),fx("sankey",db),fx("force",wb),fx("chord",Pb),fx("tree",Gb),fx("cluster",Gb),fx("treemap",Gb),fx("circlepack",Gb),fx("partition",Gb),fx("orbit",iv);var Mv=/*#__PURE__*/new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function $v(e){return e.map(e=>{let t=e.datum&&"object"==typeof e.datum?e.datum:{},i=t.data&&"object"==typeof t.data?t.data:t,r="cx"in e?e.cx:e.x+e.w/2,n="cy"in e?e.cy:e.y+e.h/2;return{...i,...null==i.id&&null!=e.id?{id:e.id}:{},x:r,y:n}})}function _v(t,i){let r=$i(t.theme),n=t.chartType||"force",o=t.size||[500,500],a=function(e){return Gc.has(e)?Xc:qc}(n),s=xe({...a,...t.margin},ln(t.title)),c=me(ln(t.title)),u=t.showLegend?(()=>{let e="string"==typeof(i=t.colorBy)||"function"==typeof i?t.colorBy:void 0;var i;if(!e)return[];let r=Mt(t.nodes||[]);if(r.length>0)return ps(r,e);if(Mv.has(n)&&t.data)return ps(Jb(t.data,t.childrenAccessor||"children"),e);let o=Array.isArray(t.edges)?Mt(t.edges):[];if(0===o.length)return[];let a=kv(t.sourceAccessor,"source"),s=kv(t.targetAccessor,"target"),l=Array.from(new Set(o.flatMap(e=>[a(e),s(e)]).filter(e=>null!=e).map(String)));return ps(l.map(e=>({id:e})),e)})():[];Rc(s,{props:t,categories:u,theme:r,size:o,hasTitle:c});let d,h=Nc({props:t,categories:u,theme:r,size:o,margin:s,hasTitle:c}),p=Math.max(1,o[0]-s.left-s.right),f=Math.max(1,o[1]-s.top-s.bottom),g=Wc(t.backgroundGraphics,o,s,null),y=Wc(t.foregroundGraphics,o,s,null),b=(e,n=[],a=[])=>(i&&(i.evidence=ma({frameType:"network",width:o[0],height:o[1],marks:[...n.map(({node:e})=>({type:`node:${e.type??"node"}`})),...a.map(({node:e})=>({type:`edge:${e.type??"edge"}`}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:d,nodeCount:n.length,edgeCount:a.length,margin:s})),hx.renderToStaticMarkup(Dc(vv(gv,{view:t.viewTransform,width:p,height:f,children:e}),{width:o[0],height:o[1],className:"stream-network-frame"+(t.className?` ${t.className}`:""),title:t.title,description:t.description,background:t.background,theme:r,innerTransform:`translate(${s.left},${s.top})`,innerWidth:p,innerHeight:f,legend:h,markCount:n.length+a.length,idPrefix:t._idPrefix}))),v=e=>{let i=e=>Number(e);return t.annotations?nc({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:i,y:i},layout:{width:p,height:f},theme:r,frameType:"network",annotationData:e&&$v(e),pointNodes:e&&dv(e),idPrefix:t._idPrefix,onRender:e=>{d=e}}):null},w=()=>{let e=v(),i=g||y||t.annotations?wv(bv,{children:[g,e,y]}):null;return b(i)},k=function(e){return px[e]}(n);if(!k&&!t.customNetworkLayout)throw new Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);let S,A,$={chartType:n,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,edgeIdAccessor:t.edgeIdAccessor,edgeIdentity:t.edgeIdentity,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||r.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig,perspective:t.perspective},_=x(t.perspective);if(Mv.has(n)){let e=t.data||t.edges;if(!e||Array.isArray(e))return w();$.__hierarchyRoot=e,S=[],A=[]}else{let e=Mt(t.nodes||[]),i=Array.isArray(t.edges)?Mt(t.edges):[];if(0===e.length&&0===i.length&&!t.customNetworkLayout)return w();let r=function(e,t,i){let r=new Map;for(let t of e){let e=xv(mv(t,i.nodeIDAccessor,"id"),"node");null!==e&&(r.has(e)&&"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Duplicate network node ID "${e}"; using the last datum.`),r.set(e,t))}let n=[],o=new Set;return t.forEach((e,t)=>{let a="id"===i.edgeIdentity?function(e,t){let i=mv(e,t.edgeIdAccessor,"id");if("string"!=typeof i||!i)throw new Error("IDENTITY_EDGE_ID: edgeIdentity=id requires nonempty string edge IDs.");return JSON.stringify(["id",i])}(e,i):void 0;if(a&&o.has(a))throw new Error("IDENTITY_DUPLICATE_EDGE: repeated edge ID in bounded graph.");a&&o.add(a);let s=function(e,t){let i=xv(mv(e,t.sourceAccessor,"source"),"source"),r=xv(mv(e,t.targetAccessor,"target"),"target");if(null===i||null===r){if("id"===t.edgeIdentity)throw new Error("ENDPOINT_OWNER: explicit-ID edges require both owners.");return null}return{source:i,target:r,value:yv(mv(e,t.valueAccessor,"value")),data:e}}(e,i);if(s){for(let e of[s.source,s.target])r.has(e)||r.set(e,{id:e});n.push({...s,_edgeKey:a??`${s.source}\0${s.target}\0${t}`})}}),{nodes:r,edges:n}}(e,i,$);S=Array.from(r.nodes,Sv),A=r.edges.map(Av)}let P,I,T=[],L=[],C=[],R=null,N=null;if($.customNetworkLayout){let e=$.colorScheme,i=Qf(e,r.colors.categorical,Tt),n=Jf(i,e),o={nodes:S,edges:A,dimensions:{width:p,height:f,plot:{x:0,y:0,width:p,height:f}},theme:{sequential:r.colors.sequential,selectionOpacity:r.colors.selectionOpacity,semantic:r.colors,categorical:[...i]},resolveColor:n,config:$.layoutConfig??{},selection:t.layoutSelection??null,perspective:_?.config??null},a=$.customNetworkLayout(o);P=a.perspective,T=a.sceneNodes??[],L=a.sceneEdges??[],function({nodes:e,edges:t,restyle:i,restyleEdge:r,baseStyles:n,selection:o}){if(i)for(let t of e){let e=n.get(t)??t.style,r=i(t,o);t.style=r?{...e,...r}:e}if(r)for(let e of t){let t=n.get(e)??e.style,i=r(e,o);e.style=i?{...t,...i}:t}}({nodes:T,edges:L,restyle:a.restyle,restyleEdge:a.restyleEdge,selection:t.layoutSelection??null,baseStyles:new WeakMap}),C=a.labels??[],R=a.backgrounds??null,N=a.overlays??null,I=a.perspectiveBounds}else if(k){k.computeLayout(S,A,$,[p,f]);let e=k.buildScene(S,A,$,[p,f]);T=e.sceneNodes,L=e.sceneEdges,C=e.labels}let D=[],F=_?(()=>{let e=m({sceneNodes:T,sceneEdges:L,labels:C,bounds:I,size:[p,f],perspective:_,chartType:n,theme:M(r)});return T=e.sceneNodes,L=e.sceneEdges,C=e.labels,D=e.underlay,e.frame})():null,E=ts({nodes:L,renderMode:t.renderMode,fallback:(e,t)=>lv(e,t)}),O=ts({nodes:T,renderMode:t.renderMode,fallback:(e,t)=>function(e,t){return Ha(function(e,t){switch(e.type){case"circle":{let i=e,r=ka(i.style.fill)?Sa(i.style.fill,`net-circle-${t}-hatch`):void 0,n={fill:r?`url(#net-circle-${t}-hatch)`:za(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity};return av(rv.Fragment,{children:[r&&ov("defs",{children:r}),i.pathD&&sv(i,n.fill,i._perspectiveToken?"token-rim":"slab-face"),i.pathD?ov("path",{"data-perspective-part":i._perspectiveToken?"token-top":"slab-top",d:i.pathD,...n}):ov("circle",{cx:i.cx,cy:i.cy,r:i.r,...n})]},`net-circle-${t}`)}case"rect":{let i=e,r=ka(i.style.fill)?Sa(i.style.fill,`net-rect-${t}-hatch`):void 0,n={fill:r?`url(#net-rect-${t}-hatch)`:za(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity};return av(rv.Fragment,{children:[r&&ov("defs",{children:r}),i.pathD&&sv(i,n.fill),i.pathD?ov("path",{"data-perspective-part":"slab-top",d:i.pathD,...n}):ov("rect",{x:i.x,y:i.y,width:i.w,height:i.h,...n})]},`net-rect-${t}`)}case"arc":{let i=e,r=i.pathD?"":nv().innerRadius(i.innerR).outerRadius(i.outerR).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2)(Oa)||"",n=ka(i.style.fill)?Sa(i.style.fill,`net-arc-${t}-hatch`):void 0;return av(rv.Fragment,{children:[n&&ov("defs",{children:n}),i.pathD&&sv(i,n?`url(#net-arc-${t}-hatch)`:za(i.style.fill)),ov("path",{d:i.pathD??r,"data-perspective-part":i.pathD?"slab-top":void 0,transform:i.pathD?void 0:`translate(${i.cx},${i.cy})`,fill:n?`url(#net-arc-${t}-hatch)`:za(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity})]},`net-arc-${t}`)}case"symbol":{let i=e,r=l(i.symbolType,i.size,i.path),n=i.rotation?`translate(${i.cx},${i.cy}) rotate(${180*i.rotation/Math.PI})`:`translate(${i.cx},${i.cy})`,o=ov("path",{"data-perspective-part":i._perspectiveToken?"token-top":void 0,d:r,transform:n,fill:i.style.fill?za(i.style.fill):"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity},`net-symbol-${t}`);return i.faces?.length?av(rv.Fragment,{children:[sv(i,i.style.fill?za(i.style.fill):void 0,"token-rim"),o]},`net-symbol-${t}`):o}case"glyph":{let i=e;return ja(i,i.cx,i.cy,`net-glyph-${i.id??t}`)}default:return null}}(e,t),e,`network-node-cursor-${t}`)}(e,t)}),z=E.map(e=>e.element),B=O.map(e=>e.element),j=_i(r),W=C.map((e,t)=>function(e,t,i="middle",r="auto"){return ov("text",{x:e.x,y:e.y,textAnchor:e.anchor||i,dominantBaseline:e.baseline||r,fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,transform:e.rotate?`rotate(${Math.round(180*e.rotate/Math.PI*100)/100} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},`net-label-${t}`)}({...e,fill:e.fill||j.text},t)).filter(Boolean),Y=v(T),q=wv(bv,{children:[g,e(R,F,P),D.map((e,t)=>lv(e,t)),z,B,W,Y,e(y,F),e(N,F,P)]});return b(q,O,E)}function Pv(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var Iv={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Tv(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}function Lv(e,t,i){let r="function"==typeof t?t(e,i):t;return{...Iv,...r??{}}}function Cv(e,t={},i="settled"){return e.map((e,r)=>function(e,t={},i={index:0,simulationState:"settled"}){let r=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),n={label:t.getBodyLabel?.(e)??Tv(e)},o={style:Lv(e,t.bodyStyle,i),datum:r,accessibleDatum:r,accessibility:n,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}(e,t,{index:r,simulationState:i}))}import{jsx as Rv,jsxs as Nv}from"react/jsx-runtime";function Dv(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`physics-${t}`:t}function Fv(e){return`${Dv(e)}-svg`}var Ev={top:0,right:0,bottom:0,left:0};function Ov(e,t,i){return"function"==typeof e?e({size:t,margin:i}):e}import*as zv from"react-dom/server.browser";function Bv(e,t={}){let{element:i,scene:r,evidence:n}=function(e,t={}){let{decorative:i=!1,width:r=640,height:n=360,title:o,description:a,background:s,backgroundGraphics:l,backgroundGraphicsBackdrop:c,className:u,foregroundGraphics:d,idPrefix:h="physics",margin:p,style:f,renderBodySVG:g,renderChrome:m,...y}=t,x=function(e,t={}){let i=e.settle(t.maxSteps),r=e.readBodies(),n=e.snapshot(),o=Cv(r,t,n.simulationState),a=function(e,t={}){let i=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),r=i.filter(e=>e.sleeping).length,n=e.queue.length,o=e.sediment.reduce((e,t)=>e+t.count,0),a="settled"===e.simulationState&&0===n&&r===i.length,s=[];a||s.push("PHYSICS_NOT_SETTLED"),n>0&&s.push("PHYSICS_QUEUE_UNDRAINED");let l=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,i,r){let n=e-(t+i+r);return{charge:e,live:t,queued:i,sedimented:r,unaccounted:n,balanced:0===n}}(t.charge,i.length,n,o):void 0;return l&&!l.balanced&&s.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:i.length,sleepingCount:r,settled:a,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:Pv(t.projectionRows),queuedCount:n,sedimentedCount:o,...l?{ledger:l}:{},warnings:s}}(n,{bodies:r,projectionRows:t.projectionRows,stepsRun:i,charge:t.charge});return{snapshot:n,bodies:r,sceneNodes:o,evidence:a,stepsRun:i}}(e,y),b={...Ev,...p},v=[r,n],w=Ov(l,v,b),k=Ov(d,v,b),S=Dv(h),A=o?`${S}-title`:void 0,M=a?`${S}-desc`:void 0,$=[A,M].filter(Boolean).join(" ")||void 0,_=b.left||b.top?`translate(${b.left},${b.top})`:void 0,P=Math.max(1,r-b.left-b.right),I=Math.max(1,n-b.top-b.bottom),T=`${S}-plot-clip`,L=e.viewTransform(),C=_&&null!=w?Rv("g",{transform:_,children:w}):w;return{element:Nv("svg",{xmlns:"http://www.w3.org/2000/svg",id:Fv(S),className:u??"stream-physics-frame",width:r,height:n,viewBox:`0 0 ${r} ${n}`,role:i?"presentation":"img","aria-labelledby":i?void 0:$,"aria-label":i?void 0:a||o||`physics chart, ${x.sceneNodes.length} marks`,style:f,children:[!i&&o&&Rv("title",{id:A,children:o}),!i&&a&&Rv("desc",{id:M,children:a}),Rv("defs",{children:Rv("clipPath",{id:T,children:Rv("rect",{width:P,height:I})})}),c&&"transparent"!==c?Rv("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:r,height:n,fill:c}):null,!l&&s&&"transparent"!==s?Rv("rect",{x:0,y:0,width:r,height:n,fill:s}):null,C,Rv("g",{id:`${S}-data-area`,transform:_,clipPath:`url(#${T})`,children:Rv("g",{transform:L.x||L.y?`translate(${L.x},${L.y})`:void 0,children:x.sceneNodes.map((e,t)=>{let i=x.bodies[t],r=(i&&g?g(i,e.style??{},t,S):void 0)??(i?yh(i,e.style??{},t,S):void 0);return null!=r?Ha(r,e,t):Ha("point"===e.type||"rect"===e.type?qa(e,t,S):null,e,`xy-cursor-${t}`)})})}),k,m?.(x)]}),scene:x,evidence:x.evidence}}(e,t);return{svg:zv.renderToStaticMarkup(i),scene:r,evidence:n}}function jv(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function Wv(e,t){let i="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,jv(e.thickness)??jv(i)??jv(t.thickness)??4)}function Yv(e){return e.sensorId??`stream-region-${e.id}`}function qv(e){let t=Yv(e),i={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){let r=e.colliderThickness??8,n=e.shape.x-e.shape.width/2,o=e.shape.x+e.shape.width/2,a=e.shape.y-e.shape.height/2,s=e.shape.y+e.shape.height/2;return[{...i,id:`${t}-top`,shape:{type:"segment",x1:n,y1:a,x2:o,y2:a,thickness:r}},{...i,id:`${t}-right`,shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:r}},{...i,id:`${t}-bottom`,shape:{type:"segment",x1:o,y1:s,x2:n,y2:s,thickness:r}},{...i,id:`${t}-left`,shape:{type:"segment",x1:n,y1:s,x2:n,y2:a,thickness:r}}]}return e.collider?[{...i,id:`${t}-collider`,shape:e.shape}]:[]}import{jsx as Xv,jsxs as Gv}from"react/jsx-runtime";import{Fragment as Vv,jsx as Hv,jsxs as Uv}from"react/jsx-runtime";var Zv={top:0,right:0,bottom:0,left:0};function Kv(e,t){let i=e.size??[e.width??600,e.height??400],r=$i(e.theme),n=e.physicsTheme?{...r,colors:{...r.colors,...Object.fromEntries(Object.entries(e.physicsTheme).filter(([e,t])=>e in r.colors&&null!=t))}}:r,o=void 0===e.theme||"auto"===r.mode?{}:v(r),a=e.bodyStyle,s=!1,l=e.legendPosition??"right",c=ye({...Zv,...e.margin},s);if(e.legend){let t={...c};Le(c,{legend:e.legend,position:l,size:i,hasTitle:s,legendLayout:e.legendLayout}),be(c,t,i,l)}let u,d=[Math.max(1,i[0]-c.left-c.right),Math.max(1,i[1]-c.top-c.bottom)],h=function({annotations:e,chartId:t,chartType:i,config:r,onRegionObservation:n,regionEffects:o,seed:a,size:s}){let l=function(e=[],t={}){let i=t.idPrefix?`${t.idPrefix}-`:"",r=[];for(let n of e){if("barrier"!==n.physics&&"sensor"!==n.physics)continue;let e,o=n.axis??t.defaultAxis??"x",a=Wv(n,t),s=n.colliderId??`${i}${n.id}`;if("x"===o){let i=jv(n.x),r=jv(n.y1)??jv(t.plotBounds?.y)??jv(n.y),o=jv(n.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??jv(n.y);if(null==i||null==r||null==o)continue;e={type:"segment",x1:i,y1:r,x2:i,y2:o,thickness:a}}else{let i=jv(n.y),r=jv(n.x1)??jv(t.plotBounds?.x)??jv(n.x),o=jv(n.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??jv(n.x);if(null==i||null==r||null==o)continue;e={type:"segment",x1:r,y1:i,x2:o,y2:i,thickness:a}}r.push({id:s,shape:e,sensor:"sensor"===n.physics,..."barrier"!==n.physics||null==n.restitution&&null==t.barrierRestitution?{}:{restitution:jv(n.restitution)??jv(t.barrierRestitution)},..."barrier"!==n.physics||null==n.friction&&null==t.barrierFriction?{}:{friction:jv(n.friction)??jv(t.barrierFriction)}})}return r}((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?`${t}-ann`:"physics-ann",plotBounds:{x:0,y:0,width:s[0],height:s[1]}}),c=void 0===a||void 0!==r?.kernel?.seed?r:{...r,kernel:{...r?.kernel,seed:a}},u=o.flatMap(e=>[{id:Yv(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...qv(e)]),d=Object.fromEntries(o.map(e=>[Yv(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,p=o.length>0,f=u.length>0||l.length>0;return p||f||null!=t||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??i,sensors:{...h?.sensors??{},...d},onObservation:e=>{p&&n(e),h?.onObservation?.(e)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:d}),p=new Tf(h);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);let f=Bv(p,{...e,title:ln(e.title)||void 0,width:i[0],height:i[1],background:e.background??e.physicsTheme?.background??r.colors.background,bodyStyle:(t,i)=>({fill:e.physicsTheme?.primary??r.colors.primary,stroke:e.physicsTheme?.text??r.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof a?a(t,i):a,..."function"==typeof e.frameBodyStyle?e.frameBodyStyle(t,{selected:!1,simulationState:i.simulationState}):e.frameBodyStyle}),style:{...o,...ch(e.physicsTheme),fontFamily:r.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{let o=function(e,t,i,r,n){let o=Math.max(1,i[0]-r.left-r.right),a=_i(n),s=void 0===t.theme?14:a.titleFontSize,l=Math.max(1,i[1]-r.top-r.bottom),c=cx(t.annotations),u=function(e){let{width:t,height:i,pointNodes:r=[],data:n}=e;return{scales:{x:ax().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:ax().domain([0,Math.max(1,i)]).range([0,Math.max(1,i)])},width:t,height:i,frameType:"network",pointNodes:r,data:n,xAccessor:"x",yAccessor:"y"}}({width:o,height:l,pointNodes:lx(e.bodies)}),d=u.scales?.x,h=u.scales?.y;if(!d||!h)throw new Error("Physics annotation context requires pixel scales");let p,f=nc({annotations:c,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{x:d,y:h},layout:{width:o,height:l},theme:n,frameType:"network",xAccessor:u.xAccessor,yAccessor:u.yAccessor,pointNodes:u.pointNodes,svgAnnotationRules:t.svgAnnotationRules,onRender:e=>{p=e}}),g=t.legend?Cc(t.legend,{theme:n,position:t.legendPosition,size:[i[0],i[1]],margin:r,hasTitle:!!t.title,legendLayout:t.legendLayout})??ac(t.legend,i,r,t.legendPosition,t.legendLayout):null;return{annotationRender:p,node:Gv("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i[0],height:i[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Xv("g",{transform:`translate(${r.left},${r.top})`,children:f}),ln(t.title)&&Xv("text",{className:"semiotic-chart-title",x:i[0]/2,y:22,textAnchor:"middle",fill:a.text,fontSize:s,fontFamily:a.titleFontFamily,fontWeight:a.titleFontWeight,children:cn(t.title)}),g]})}}(t,e,i,c,n);u=o.annotationRender;let a=Mi(r,`#${Fv(e.idPrefix??e._idPrefix??"physics")}`);return Uv(Vv,{children:[a&&Hv("style",{children:a}),o.node]})}});if(t&&(t.evidence=ma({frameType:"physics",width:i[0],height:i[1],marks:f.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===f.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...f.scene.evidence.warnings]}),e.eventDropMetadata)){let i=e.eventDropMetadata;Object.assign(t.evidence,{watermarkValue:i.watermarkValue,openWindows:i.windowCount-i.closedWindowCount,closedWindows:i.closedWindowCount,lateCount:i.lateCount})}return f.svg}function Qv(e,t,i){return{frameType:e.frameType,layout:{...e.layout,...i&&{margin:i}},buildProps:(i,r,n,o,a)=>{let[s,l]=o.size,c=t({...a,...o,width:s,height:l,colorScheme:n});return e.buildProps(c.data,r,n,{...o,...null!=c.annotations&&{annotations:c.annotations},...c.frameProps,title:c.title,description:c.description,summary:c.summary,accessibleTable:c.accessibleTable},{...a,...c})}}}var Jv=Qv(nh,function({atlas:e,linkedHover:t,...i},r=function(e){let t=e.prefixForest;if(!t)return{atlas:e,groups:[],signatureOrder:[],ribbons:[],capsules:[],profile:_y(e),differences:[],prefixForest:{kind:"observed-prefix",rootIds:[],nodes:[],order:[]},sceneSeeds:{nodes:[],edges:[]}};let i=(e.source.occurrences??[]).map(Iy).filter(e=>!!e),r=new Map;for(let e of i){let i=t.order.indexOf(e.signature),n=r.get(e.signature),o=-1===i?t.order.length:i;(null==n||o<n)&&r.set(e.signature,o)}let n=[...new Set(i.map(e=>e.signature))].sort((e,t)=>{let i=(r.get(e)??0)-(r.get(t)??0);return 0!==i?i:e.localeCompare(t)}),o=[];for(let e of i)for(let t=0;t<e.nodePath.length-1;t++){let i=Ay(e.nodePath,t),r=Ay(e.nodePath,t+1);o.push({id:`ribbon:${e.id}:${t}`,groupId:e.id,partition:e.partition,fromPrefixId:i,toPrefixId:r,fromState:e.nodePath[t],toState:e.nodePath[t+1],entityCount:e.stepEntityCounts?.[t]??e.entityCount,...e.stepEntityCounts&&{toEntityCount:e.stepEntityCounts[t+1]}})}let a=function(e,t={}){let i=new Set(t.templates??["repeated-state-episode"]),r=e.filter(e=>i.has(e.template)).map(e=>{let t="string"==typeof e.roles.state?e.roles.state:e.nodePath[0],i=e.nodePath[e.nodePath.length-1];return{id:`capsule:${e.id}`,matchId:e.id,template:e.template,entryState:t,exitState:i,entityCount:e.entityCount,occurrenceIds:wy(e),selected:!1}}).sort((e,t)=>t.entityCount!==e.entityCount?t.entityCount-e.entityCount:e.id.localeCompare(t.id)),n=new Set;for(let e of r)if(!e.occurrenceIds.some(e=>n.has(e))){e.selected=!0;for(let t of e.occurrenceIds)n.add(t)}return r}(e.motifs.matches),s=e.comparison??function(e){let t=e.spec.comparison;if(!t)return;let i=t.partitions.map(i=>{let r=My(e.ledger,t.denominatorMeasureId,i)?.value??0,n={};return n["repeated-state-episode"]=ky(e.motifs.matches.filter(e=>"repeated-state-episode"===e.template),e.source.occurrences,i),{partition:i,assigned:r,motifUsers:n,outcomes:{purchases:My(e.ledger,"purchases",i)?.value??0}}});return{partitions:[...t.partitions],denominatorMeasureId:t.denominatorMeasureId,referencePartition:t.referencePartition,rows:i}}(e),l=[];if(s&&s.partitions.length>=2){let e=s.rows[0],t=s.rows[1],i=Math.min(e.assigned,t.assigned)||e.assigned,r=e.motifUsers["repeated-state-episode"]??0,n=t.motifUsers["repeated-state-episode"]??0;l.push({motif:"repeated-state-episode",leftPartition:e.partition,rightPartition:t.partition,leftCount:r,rightCount:n,deltaCount:n-r,deltaBps:$y(r,n,i),denominator:i}),l.push({motif:"purchases",leftPartition:e.partition,rightPartition:t.partition,leftCount:e.outcomes.purchases??0,rightCount:t.outcomes.purchases??0,deltaCount:(t.outcomes.purchases??0)-(e.outcomes.purchases??0),deltaBps:$y(e.outcomes.purchases??0,t.outcomes.purchases??0,i),denominator:i})}let c={nodes:i.map(e=>({id:e.id,partition:e.partition,signature:e.signature})),edges:o.map(e=>({id:e.id,source:e.fromPrefixId,target:e.toPrefixId}))};return{atlas:e,groups:i,signatureOrder:n,ribbons:o,capsules:a,profile:_y(e),differences:l,prefixForest:t,sceneSeeds:c}}(e)){return{...i,linkedHover:vy(t),title:i.title??e.spec.dataRevision,description:i.description??"Motif Braid. Labeled squares show successive journey steps; parallel strands split at diverging prefixes and taper with per-step traffic.",summary:i.summary??`${r.groups.length} supported journey groups. Counts use ${e.spec.motifs.countUnit}; overlapping motifs do not partition the population. Source revision: ${e.provenance.sourceRevision}.`,accessibleTable:i.accessibleTable??!0,nodes:r.sceneSeeds.nodes,edges:r.sceneSeeds.edges,layout:zy,layoutConfig:{braid:r}}}),ew=Qv(nh,function({width:e=lt.width,height:t=lt.height,title:i="Dependency X-Ray",description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,linkedSelection:u,annotations:d,frameProps:h,perspective:p,onSelectNode:f,tooltip:g,...m}){return{nodes:m.forest.sceneSeeds.nodes,edges:m.forest.sceneSeeds.edges,layout:Yy,layoutConfig:m,nodeIDAccessor:"id",sourceAccessor:"source",targetAccessor:"target",width:e,height:t,title:i,chartId:a,className:s,onObservation:l,linkedHover:vy(c),selection:u,annotations:d,frameProps:h,perspective:p,tooltip:g,animate:!1,margin:{top:12,right:24,bottom:12,left:12},description:r??`Sections organize the admitted directed graph. Backbone links organize the drawing; residual links retain other original edges. Brackets describe required paths, separately from transport. Roots: ${m.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Completeness: ${m.forest.atlas.requiredPaths?.status??"not prepared"}.`,summary:n??`Roots: ${m.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Required-path completeness: ${m.forest.atlas.requiredPaths?.status??"not prepared"}. ${m.forest.residual.originalEdgeIds.length} original edges retained.`,accessibleTable:o}},{top:12,right:24,bottom:12,left:12}),tw=Qv(by,dx),iw=Qv(nh,function(e){let{key:t,data:i,layout:r,paused:n,frameProps:o,...a}=dx(e);return{...a,annotations:cx(a.annotations),nodes:i,edges:e.circuit.atlas.source.edges,layout:nx,perspective:e.perspective,margin:0,frameProps:{...e.frameProps&&{background:e.frameProps.background,backgroundGraphics:e.frameProps.backgroundGraphics,foregroundGraphics:e.frameProps.foregroundGraphics},...e.networkFrameProps}}}),rw={...tw,resolveFrameType:e=>e._projectedCircuit?"network":"physics",buildProps:(...e)=>{let t=x(e[4].perspective);return{...(t?iw:tw).buildProps(...e),_projectedCircuit:!!t}},renderStatic:(e,t)=>e._projectedCircuit?_v(e,t):Kv(e,t)};import{scaleTime as nw}from"d3-scale";var ow={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function aw(e="static"){return ow[e]??ow.static}var sw=/*#__PURE__*/new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function lw(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:sw.has(e.kind)?"fatal":"warn"}function cw(e,t,i="static"){if("strip"!==aw(i).invalidSystemTime)return e;let r=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===r.size?e:e.map(e=>{if(!r.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}function uw(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function dw(e,t){let i=0,r=e.length-1,n=-1;for(;i<=r;){let o=i+r>>>1;e[o].at<=t?(n=o,i=o+1):r=o-1}return n<0?{at:t,before:0,after:0}:e[n]}function hw(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let i=[],r=[0];for(let n=0;n<e.length-1;n++){let o=e[n],a=e[n+1],s=[...new Set([...o.map(e=>e.at),...a.map(e=>e.at)])].sort((e,t)=>e-t),l=0;for(let e of s){let t=dw(o,e),i=dw(a,e);l=Math.max(l,t.after+i.before)}i.push(l),r.push(r[r.length-1]+l+t)}return{adjacentClearance:i,positions:r}}function pw(e,t,i,r={}){let n=[...e];if(n.length<=1)return n;let o=[...n],a=i(n),s=1,l=Math.max(0,r.passes??6),c=Math.max(1,r.maxEvaluations??1/0);for(let e=0;e<l&&s<c;e++){let e=new Map(n.map((e,t)=>[e,t])),l=new Map,c=new Map;for(let i of t){let t=e.get(i.source),r=e.get(i.target);if(null==t||null==r)continue;let n=Number.isFinite(i.weight)&&i.weight>0?i.weight:1;l.set(i.source,(l.get(i.source)??0)+r*n),c.set(i.source,(c.get(i.source)??0)+n),l.set(i.target,(l.get(i.target)??0)+t*n),c.set(i.target,(c.get(i.target)??0)+n)}n=n.map((e,t)=>({item:e,index:t,barycenter:(l.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(r.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let u=i(n);if(s++,u<a)a=u,o=[...n];else if(u===a)break}return o}function fw(e,t,i={}){let r=[...e];if(r.length<=1)return r;let n=t(r),o=1,a=Math.max(0,i.passes??6),s=Math.max(1,i.maxEvaluations??1/0);for(let e=0;e<a&&o<s;e++){let e=!1;for(let i=0;i<r.length-1&&o<s;i++){[r[i],r[i+1]]=[r[i+1],r[i]];let a=t(r);o++,a<n?(n=a,e=!0):[r[i],r[i+1]]=[r[i+1],r[i]]}if(!e)break}return r}function gw(e,t,i={}){let r=[...e],n=r.length;if(n<=1||n>(i.maxItems??8))return r;let o=Math.max(1,i.maxEvaluations??1/0),a=0,s=[...r],l=1/0,c=()=>{if(a>=o)return;let e=t(r);a++,e<l&&(l=e,s=[...r])};c();let u=new Array(n).fill(0),d=0;for(;d<n&&a<o;)if(u[d]<d){let e=d%2==0?0:u[d];[r[e],r[d]]=[r[d],r[e]],c(),u[d]++,d=0}else u[d]=0,d++;return s}function mw(){return Object.create(null)}function yw(e,t){return e<t?-1:e>t?1:0}function xw(e){return e.occupants.map(e=>e.id).sort(yw).join("\0")}function bw(e,t,i=0){return e.slice(0,-1).map((r,n)=>{let o=e[n+1];return null!=r.group&&r.group===o.group?i:t})}function vw(e,t){return e.map(e=>{let i=new Map;for(let r of e.occupants){let e=t[r.id];if(e)for(let t of e.samples){let e=i.get(t.t)??{before:0,after:0},r=t.boundaryOffset??0;i.set(t.t,{before:Math.max(e.before,t.topMass-r),after:Math.max(e.after,t.botMass+r)})}}return[...i].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function ww(e,t,i){if(0===e.length)return[];let{padding:r,plotH:n,valueScale:o}=i,a=i.stackValueScale??o,s=bw(e,r,i.groupPadding??0),l=[r+e[0].peak.topPeak*a];for(let i=1;i<e.length;i++)l.push(l[i-1]+t[i-1]*a+s[i-1]);let c=l[l.length-1]+e[e.length-1].peak.botPeak*a+r;if(c>n&&c>0){let e=n/c;for(let t=0;t<l.length;t++)l[t]*=e}return l}function kw(e,t){let i=(e.boundaryOffset??0)*t,r=e.value*t;if("out"===e.kind){let n=e.sideMassBefore*t;return i+("top"===e.side?r/2-n:n-r/2)}let n=e.sideMassAfter*t;return i+("top"===e.side?r/2-n:n-r/2)}function Sw(e,t,i,r,n,o){let a=o.adjacentClearance?[...o.adjacentClearance]:hw(vw(r,i)).adjacentClearance,s=ww(r,a,o),l="hug"===o.lanePlacement?function(e,t,i,r,n,o,a){let s=e.length;if(0===s)return[];let{padding:l,plotH:c,valueScale:u}=a,d=bw(e,l,a.groupPadding??0),h=n.map((e,t)=>e*u+d[t]),p=l+e[0].peak.topPeak*u,f=c-l-e[s-1].peak.botPeak*u;if(f-p<=h.reduce((e,t)=>e+t,0)+1e-6)return ww(e,n,a);let g=1===s?[(p+f)/2]:[...o];for(let e=0;e<12;e++){let e=new Array(s).fill(0),n=new Array(s).fill(0);for(let o of i){let i=t[o.source],a=t[o.target];if(null==i||null==a||i===a)continue;let s=r[o.source]?.localAttachments.get(o.id),l=r[o.target]?.localAttachments.get(o.id);if(!s||!l)continue;let c=o.value>0&&Number.isFinite(o.value)?o.value:1,d=kw(s,u),h=kw(l,u);e[i]+=(g[a]+h-d)*c,n[i]+=c,e[a]+=(g[i]+d-h)*c,n[a]+=c}let o=ms({desired:g.map((t,i)=>0===n[i]?t:.45*t+e[i]/n[i]*.55),minGaps:h,weights:n.map(e=>Math.max(1,e)),min:p,max:f}),a=0;for(let e=0;e<s;e++)a=Math.max(a,Math.abs(o[e]-g[e]));if(g=o,a<.01)break}return g}(r,n,t,i,a,s,o):[...s];if("hug"===o.lanePlacement){let i=t=>{let i=mw();for(let r of e)i[r.id]=t[n[r.id]];return i};Aw(i(l),t)>Aw(i(s),t)+1e-6&&(l=[...s])}let c=mw();for(let t of e)c[t.id]=l[n[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],r=i[t.id];!Number.isFinite(e)||!r||(u=Math.min(u,e-r.topPeak*o.valueScale),d=Math.max(d,e+r.botPeak*o.valueScale))}return{adjacentClearance:a,centerlines:c,slotCenter:l,stackCenter:s,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&o.plotH>0?Math.max(0,Math.min(1,(d-u)/o.plotH)):0}}function Aw(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];Number.isFinite(t)&&Number.isFinite(n)&&(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}function Mw(e,t){let i=e?.samples;if(!i||0===i.length||t<i[0].t)return{top:0,bot:0};let r=0,n=i.length-1,o=0;for(;r<=n;){let e=r+n>>>1;i[e].t<=t?(o=e,r=e+1):n=e-1}let a=i[o].boundaryOffset??0;return{top:i[o].topMass-a,bot:i[o].botMass+a}}function $w(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function _w(e,t){let i=0,r=1;for(let n=0;n<28;n++){let n=(i+r)/2;$w(0,t,t,1,n)<e?i=n:r=n}return(i+r)/2}function Pw(e,t,i){let r=t+kw(e,i),n=e.value*i/2;return[r-n,r+n]}function Iw(e,t,i,r){return Math.max(0,Math.min(t,r)-Math.max(e,i))/Math.max(1e-9,t-e)}function Tw(e,t,i,r,n,o,a){let{valueScale:s,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5,d=0;for(let a of e){let e=r[a.source],h=r[a.target];if(null==e||null==h||Math.abs(e-h)<2)continue;let p=t[a.source]?.localAttachments.get(a.id),f=t[a.target]?.localAttachments.get(a.id);if(!p||!f)continue;let g=Math.max(a.startTime,l?.[0]??-1/0),m=Math.min(a.endTime,l?.[1]??1/0);if(!(m>g))continue;let[y,x]=Pw(p,n[a.source],s),[b,v]=Pw(f,n[a.target],s),w=Math.min(e,h)+1,k=Math.max(e,h)-1;for(let e=w;e<=k;e++){let r=i[e];if(!r)continue;let l=[g,m];if("quality"===c)for(let e of r.occupants)for(let i of t[e.id]?.samples??[])i.t>g&&i.t<m&&l.push(i.t);let h=e=>{let i=_w((e-g)/(m-g),u),l=$w(y,y,b,b,i),c=$w(x,x,v,v,i),d=0;for(let i of r.occupants){if(i.id===a.source||i.id===a.target)continue;let r=o[i.id];if(null!=r?.start&&e<r.start||null!=r?.end&&e>r.end)continue;let u=Mw(t[i.id],e),h=n[i.id];d=Math.max(d,Iw(l,c,h-u.top*s,h+u.bot*s))}return d},p=[...new Set(l)].sort((e,t)=>e-t),f=0;for(let e=0;e<p.length-1;e++){let t=p[e],i=p[e+1]-t;f+=(h(t+.25*i)+h(t+.5*i)+h(t+.75*i))/3*i}d+=f/(m-g)*(a.value>0?a.value:1)}}return d}function Lw(e,t,i,r,n,o,a,s,l,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:Aw(a,i),transitOcclusion:Tw(i,r,n,o,a,s,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Cw(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Rw(e,t){return e.map(e=>({t:Cw(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function Nw(e,t,i){let r=t+(e.boundaryOffset??0)*i,n=e.value*i;if("out"===e.kind){let t=e.sideMassBefore*i;if("top"===e.side){let e=r-t;return[e,e+n]}let o=r+t;return[o-n,o]}let o=e.sideMassAfter*i;if("top"===e.side){let e=r-o;return[e,e+n]}let a=r+o;return[a-n,a]}function Dw(e,t,i,r,n="temporal"){let o=t.incoming[e.id],a=t.outgoing[e.id],s=[];for(let e of o)s.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:i.get(e.id).targetSide});for(let e of a)s.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:i.get(e.id).sourceSide});let l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{s.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(l[e.kind]??99)-(l[t.kind]??99)||((e,t)=>{if(!r||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let i=r.get(e.edge.id)?.target,n=r.get(t.edge.id)?.target;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?i-n:n-i:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let i=r.get(e.edge.id)?.source,n=r.get(t.edge.id)?.source;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?n-i:i-n:0}return 0})(e,t)||yw(e.edge?.id??"",t.edge?.id??"")||yw(e.side,t.side)||e.delta-t.delta)},u=s.length?ce(s.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let p=null,f=0;for(let e of s)e.time!==p&&(p=e.time,f=0),e.sequence=f++;let g=e=>({time:e.time,phase:0,sequence:e.sequence??0}),m=[],y=0,x=0;for(let e of s)if("out"===e.kind){let t=Math.abs(e.delta),i=t-("top"===e.side?y:x);if(i>0){let t="top"===e.side?"bot":"top",r=Math.min(i,"top"===t?y:x);if(r>0){let n=g(e);m.push({...n,delta:-r,kind:"transfer-out",side:t}),m.push({...n,delta:+r,kind:"transfer-in",side:e.side}),"top"===t?y-=r:x-=r,"top"===e.side?y+=r:x+=r,i-=r}i>0&&null!==h&&(m.push({time:h,delta:+i,kind:"create",side:e.side}),"top"===e.side?y+=i:x+=i)}"top"===e.side?y-=t:x-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?y+=t:x+=t}s.push(...m),c();let b=0,v=0,w=0,k=0,S=0,A=0,M=[],$=new Map,_=e=>{M.push({t:e,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},P=()=>{k=Math.max(k,b+v),S=Math.max(S,b-w),A=Math.max(A,v+w)};for(let e of s){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&_(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?b:v,i=t+e.delta;$.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:i,kind:e.kind,value:Math.abs(e.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===e.side?b+=e.delta:v+=e.delta,"transfer-in"===e.kind?(w+="top"===e.side?e.delta:-e.delta,P(),_(e.time)):"transfer-out"!==e.kind&&(P(),"out"===e.kind&&b+v<=1e-12&&(w=0),_(e.time))}let I=[],T=0;for(;T<M.length;){let e=T;for(;e+1<M.length&&M[e+1].t===M[T].t;)e++;I.push(M[T]);for(let t=T+1;t<=e;t++){let e=I[I.length-1];(M[t].topMass!==e.topMass||M[t].botMass!==e.botMass||(M[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&I.push(M[t])}T=e+1}let L=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,C=null;for(let e of a)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime&&(null===C||e.systemInTime<C)&&(C=e.systemInTime);let R=null;for(let e of o)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===R||e.systemOutTime>R)&&(R=e.systemOutTime);if(I.length>0){let e=I[I.length-1],t=Math.max(L??-1/0,R??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&I.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let i,r=I[0],n=I.find(e=>e.topMass+e.botMass>0),o=1/0;null!=d&&Number.isFinite(d)&&d<r.t&&r.topMass+r.botMass>0&&(o=d,i=r),n&&null!=C&&Number.isFinite(C)&&C<n.t&&C<o&&(o=C,i=n),i&&Number.isFinite(o)&&I.unshift({t:o,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let N=I;if("max"===n&&null!=d&&null!=L&&L>d){let e,t=0;for(let i of I){let r=i.topMass+i.botMass;r>t&&(t=r,e=i)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};N=[...I.filter(e=>e.t<d),{t:d,...t},{t:L,...t},...I.filter(e=>e.t>L)]}}return{samples:N,peak:k,topPeak:S,botPeak:A,localAttachments:$}}var Fw=(e,t)=>{let i=0,r=e.length;for(;i<r;){let n=i+r>>>1;e[n]<t?i=n+1:r=n}return i},Ew=class{constructor(e){this.coordinates=[...new Set(e)].sort((e,t)=>e-t),this.tree=new Int32Array(this.coordinates.length+1)}add(e,t){for(let i=Fw(this.coordinates,e)+1;i<this.tree.length;i+=i&-i)this.tree[i]+=t}below(e){let t=0;for(let i=Fw(this.coordinates,e);i>0;i-=i&-i)t+=this.tree[i];return t}};function Ow(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.max(e.startTime,t.startTime)<Math.min(e.endTime,t.endTime)}var zw=class{constructor(e,t,i){this.size=i,this.routes=[],this.outgoing=Array.from({length:i},()=>[]),this.incoming=Array.from({length:i},()=>[]);let r=new Map,n=new Map;for(let e of t.keys())n.set(e,n.size);this.nodeCount=n.size;for(let i of e){let e=t.get(i.source),o=t.get(i.target);if(void 0===e||void 0===o||!(i.startTime<i.endTime))continue;let a=n.get(i.source),s=n.get(i.target),l=`${a}:${s}`;r.has(l)||r.set(l,r.size);let c=this.routes.length;this.routes.push({edge:i,source:e,target:o,sourceNode:a,targetNode:s,pair:r.get(l),reverse:-1}),this.outgoing[e].push(c),this.incoming[o].push(c)}for(let e of this.routes)e.reverse=r.get(`${e.targetNode}:${e.sourceNode}`)??-1;if(this.events=this.routes.flatMap((e,t)=>[{time:e.edge.startTime,route:t,delta:1},{time:e.edge.endTime,route:t,delta:-1}]).sort((e,t)=>e.time-t.time||e.delta-t.delta||e.route-t.route),this.smallPairs=this.routes.length<=80?[]:null,this.smallPairs)for(let e=0;e<this.routes.length;e++)for(let t=e+1;t<this.routes.length;t++)Ow(this.routes[e].edge,this.routes[t].edge)&&this.smallPairs.push([e,t]);this.work=this.smallPairs?.length??1/0}crossing(e,t,i){return(i[e.source]-i[t.source])*(i[e.target]-i[t.target])<0?1:0}count(e){if(this.smallPairs){let t=0;for(let[i,r]of this.smallPairs)t+=this.crossing(this.routes[i],this.routes[r],e);return t}let t=Array.from({length:this.size+1},()=>[]);for(let i of this.routes){let r=e[i.source],n=e[i.target];for(let e=r+1;e<=this.size;e+=e&-e)t[e].push(n)}let i=t.map(e=>new Ew(e)),r=new Int32Array(4*this.nodeCount),n=new Int32Array(this.routes.length),o=(e,t)=>{let r=0;for(let n=e;n>0;n-=n&-n)r+=i[n].below(t);return r},a=0;for(let t of this.events){let s=this.routes[t.route],l=e[s.source],c=e[s.target];1===t.delta&&(a+=o(l,this.size)-o(l,c+1)+o(this.size,c)-o(l+1,c),l!==c&&(a-=r[4*s.sourceNode+(l<c?1:0)],a-=r[4*s.targetNode+(l<c?2:3)],s.reverse>=0&&(a+=n[s.reverse])));for(let e=l+1;e<=this.size;e+=e&-e)i[e].add(c,t.delta);l!==c&&(r[4*s.sourceNode+(l<c?3:2)]+=t.delta,r[4*s.targetNode+(l<c?0:1)]+=t.delta),n[s.pair]+=t.delta}return a}swapDelta(e,t,i){let r=0,n=0,o=r=>i[r===e?t:r===t?e:r],a=(e,t)=>{let a=this.routes[e],s=this.routes[t];if(!Ow(a.edge,s.edge))return;n++;let l=(o(a.source)-o(s.source))*(o(a.target)-o(s.target))<0?1:0;r+=l-this.crossing(a,s,i)};for(let i of this.outgoing[e])for(let e of this.outgoing[t])a(i,e);for(let i of this.incoming[e])for(let r of this.incoming[t]){let n=this.routes[i],o=this.routes[r];n.source===e&&o.source===t||n.source===t&&o.source===e||a(i,r)}return{delta:r,evaluations:n}}};function Bw(e){let t=mw();return e.forEach((e,i)=>{for(let r of e.occupants)t[r.id]=i}),t}function jw(e,t,i){e.length=i.length;for(let t=0;t<i.length;t++)e[t]=i[t];let r=Bw(i);for(let e of Object.keys(t))delete t[e];Object.assign(t,r)}function Ww(e){let t=new Map,i=[];e.forEach((e,r)=>{if(!e.group)return void i.push({anchor:r,stableId:xw(e),slots:[e]});let n=t.get(e.group)??{indexes:[],slots:[]};n.indexes.push(r),n.slots.push(e),t.set(e.group,n)});for(let[e,r]of t)i.push({anchor:r.indexes.reduce((e,t)=>e+t,0)/r.indexes.length,stableId:`${e}\0${r.slots.map(xw).join("\0")}`,slots:r.slots});return i.sort((e,t)=>e.anchor-t.anchor||yw(e.stableId,t.stableId))}function Yw(e){return e.some(e=>e.group)?Ww(e).flatMap(e=>e.slots):[...e]}function qw(e){return e.flatMap(e=>e.slots)}function Xw(e,t,i){let r=new Map;return e.forEach((e,t)=>{for(let i of e.slots)r.set(i,t)}),e.map((e,n)=>{if(e.slots.length<=1)return e;let o=new Map;for(let t of e.slots)o.set(t,0);for(let e of t){let t=r.get(e.source),i=r.get(e.target);if(null==t||null==i)continue;let a=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===n&&i!==n){let t=i>n?1:-1;o.set(e.source,(o.get(e.source)??0)+a*t)}else if(i===n&&t!==n){let i=t>n?1:-1;o.set(e.target,(o.get(e.target)??0)+a*i)}}let a=[...e.slots].sort((e,t)=>(o.get(e)??0)-(o.get(t)??0)||i(e,t));return{...e,slots:a}})}function Gw(e,t){e.some(e=>e.group)&&jw(e,t,Yw(e))}function Vw(e,t){let i=[...new Set(Object.values(e))].sort((e,t)=>e-t),r=new Map(i.map((e,t)=>[e,t])),n=new Map(Object.entries(e).map(([e,t])=>[e,r.get(t)]));return new zw(t,n,i.length).count(i.map((e,t)=>t))}function Hw(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];null==t||null==n||(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}var Uw=e=>{let t=1;for(let i=2;i<=e;i++)t*=i;return t},Zw=828*Uw(8),Kw=3e3;function Qw(e){let t=new Array(e.length),i=Math.floor((e.length-1)/2),r=i-1,n=i+1;e.length>0&&(t[i]=e[0]);for(let i=1;i<e.length;i++)i%2==1&&n<e.length?t[n++]=e[i]:r>=0?t[r--]=e[i]:t[n++]=e[i];return t}function Jw(e,t,i){let r=i(e),n=r,o=[...e],a=Math.floor((e.length-1)/2);for(let s of t){let t=e.indexOf(s);if(t===a)continue;e.splice(t,1),e.splice(a,0,s);let l=i(e);l<=r?(r=l,l<n&&(o=[...e],n=l)):(e.splice(a,1),e.splice(t,0,s))}return o}function ek(e,t,i,r,n,o,a){let s=[...n],l=new Map(n.map(e=>[e,xw(e)])),c=new Map;for(let e of n)for(let t of e.occupants)c.set(t.id,e);let u=new Map,d=[];for(let e of t){let t=c.get(e.source),i=c.get(e.target);!t||!i||(u.set(e,[t,i]),t!==i&&d.push({source:t,target:i,weight:e.value}))}let h=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),p=a.plotH/Math.max(1,n.length),f=n.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),g=Math.max(1,h)*(Math.max(1,a.plotH)+p*Math.max(f,n.length)+1e-6*Math.max(1,n.length-1))+1,m=4*p,y={fullCrossing:0,localCrossing:0},x=new Map,b=(e,t)=>{let r=x.get(e);r||(r=new Map,x.set(e,r));let n=r.get(t);if(null!=n)return n;let o=function(e,t,i){return hw(vw([e,t],i)).adjacentClearance[0]??0}(e,t,i);return r.set(t,o),o},v=new Map(n.map((e,t)=>[e,t])),w=new zw(t,new Map([...c].map(([e,t])=>[e,v.get(t)])),n.length),k=e=>{let t=new Int32Array(n.length);for(let i=0;i<e.length;i++)t[v.get(e[i])]=i;return t},S=new Map([...u].map(([e,[t,i]])=>[e,{source:v.get(t),target:v.get(i),weight:e.value>0?e.value:1}])),A=[...S.values()],M=new Map,$=new Map,_=new Map,P=(e,t,i)=>{e.has(t)||e.set(t,new Set),e.get(t).add(i)};for(let e of t)P(M,e.source,e.target),P($,e.target,e.source),P(_,e.source,e.target),P(_,e.target,e.source);let I=t.flatMap(e=>{if(!(e=>1===M.get(e.source)?.size&&M.get(e.source).has(e.target)||1===_.get(e.source)?.size||1===_.get(e.target)?.size)(e))return[];let t=S.get(e);return t&&t.source!==t.target?[t]:[]}),T=e=>{let t=0;for(let i of I)t+=Math.max(0,Math.abs(e[i.source]-e[i.target])-1)*i.weight;return t*m},L=e=>T(k(e)),C=new Int32Array(n.length),R=new Float64Array(n.length),N=new Float64Array(n.length+1),D=e=>{for(let t=0;t<e.length;t++)C[v.get(e[t])]=t;let t=w.count(C);if(e.length>0){let t=v.get(e[0]);R[t]=a.padding+e[0].peak.topPeak*a.valueScale;for(let t=1;t<e.length;t++){let i=v.get(e[t-1]),r=v.get(e[t]);R[r]=R[i]+b(e[t-1],e[t])*a.valueScale+a.padding}let i=v.get(e[e.length-1]),r=R[i]+e[e.length-1].peak.botPeak*a.valueScale+a.padding;if(r>a.plotH&&r>0){let e=a.plotH/r;for(let t=0;t<R.length;t++)R[t]*=e}}N[0]=0;for(let t=0;t<e.length;t++)N[t+1]=N[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0,r=0,n=0;for(let e of A){let t=C[e.source],o=C[e.target];if(i+=Math.abs(t-o)*e.weight,r+=Math.abs(R[e.source]-R[e.target])*e.weight,Math.abs(t-o)>=2){let i=Math.min(t,o)+1,r=Math.max(t,o);n+=(N[r]-N[i])*e.weight}}return t*g+r+n*p+T(C)+1e-6*i},F=(n,o,s)=>{let l=o;null==l&&(l=w.count(k(n)),y.fullCrossing++);let{map:c,geometry:u,weightedLength:d,pixelLength:h}=(r=>{let n=Bw(r),o=r.slice(0,-1).map((e,t)=>b(e,r[t+1])),s=Sw(e,t,i,r,n,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:o});return{map:n,geometry:s,weightedLength:Hw(n,t),pixelLength:Aw(s.centerlines,t)}})(n),f=s?Tw(t,i,n,c,u.centerlines,r,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:s}):((e,i)=>{let r=new Array(e.length+1).fill(0);for(let t=0;t<e.length;t++)r[t+1]=r[t]+e[t].peak.topPeak+e[t].peak.botPeak;let n=0;for(let e of t){let t=i[e.source],o=i[e.target];if(null==t||null==o||Math.abs(t-o)<2)continue;let a=Math.min(t,o)+1;n+=(r[Math.max(t,o)]-r[a])*(e.value>0?e.value:1)}return n})(n,c);return{crossings:l,weightedLength:d,pixelLength:h,transitOcclusion:f,cost:l*g+h+f*p+L(n)+1e-6*d}},E=(e,t,i="quality")=>F(e,t,i),O=[...s],z=(e,t)=>yw(l.get(e),l.get(t)),B=function(e){let t=new Set;for(let i of e)if(i.group){if(t.has(i.group))return!0;t.add(i.group)}return!1}(O),j=(e,t,i,r=Kw)=>{let n=t(e);for(let o=0;o<i&&r>0;o++){let i=!1,a=Array.from({length:e.length-1},(e,t)=>t);o%2==1&&a.reverse();for(let o of a){if(r--<=0)break;let a=e[o],s=e[o+1],l=w.swapDelta(v.get(a),v.get(s),k(e));[e[o],e[o+1]]=[s,a],y.localCrossing+=l.evaluations;let c=t(e,n.crossings+l.delta);c.cost<n.cost?(n=c,i=!0):[e[o],e[o+1]]=[a,s]}if(!i)break}return e},W=e=>{let t=(e=>{let t=pw(e,d,e=>F(e).cost,{passes:6,compare:z,maxEvaluations:Kw});return j(t,F,6)})(e);if((e.length<=8?Uw(e.length)*(e.length+A.length+w.work):1/0)>Zw)return t;let i=gw(e,D,{maxItems:8,maxEvaluations:5e4}),r=E(i),n=E(t);return r.crossings!==n.crossings&&r.crossings<n.crossings?i:t},Y=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),q=(e,t)=>Y(t)-Y(e)||yw(e.stableId,t.stableId),X=(e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||z(e,t),G="geometry-refine"===a.mode;if(G||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder?G||"inside-out"!==a.laneOrder||(O=B?qw(Qw([...Ww(O)].sort(q))):Qw([...O].sort(X))):O=B?(e=>{let t=Ww(e);if(t.length<=1)return qw(t);let i=e=>F(qw(e)).cost;t=Ww(W(e)),t=Xw(t,d,z);let r=function(e,t){let i=new Map;for(let t of e)for(let e of t.slots)i.set(e,t);let r=new Map;for(let e of t){let t=i.get(e.source),n=i.get(e.target);if(!t||!n||t===n)continue;let o=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,a=t.stableId<n.stableId?`${t.stableId}\0${n.stableId}`:`${n.stableId}\0${t.stableId}`,s=r.get(a);s?s.weight=(s.weight??0)+o:r.set(a,{source:t,target:n,weight:o})}return[...r.values()]}(t,d);if(t=pw(t,r,i,{passes:6,compare:(e,t)=>yw(e.stableId,t.stableId),maxEvaluations:Kw}),t=fw(t,i,{passes:8,maxEvaluations:Kw}),(t.length<=8?Uw(t.length)*(t.length+A.length+w.work):1/0)<=Zw){let e=gw(t,e=>D(qw(e)),{maxItems:8,maxEvaluations:5e4}),i=qw(e),r=qw(t),n=E(i),o=E(r);n.crossings!==o.crossings?t=n.crossings<o.crossings?e:t:n.cost<o.cost&&(t=e)}return t=Xw(t,d,z),qw(t)})(O):W(O),!G&&"crossing-min+inside-out"===a.laneOrder&&O.length>1)if(B){let e=Ww(O);O=qw(Jw(e,[...e].sort(q),e=>F(qw(e)).cost))}else O=Jw(O,[...O].sort(X),e=>F(e).cost);if((G||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&O.length>1)if(B){let e=fw(Ww(O),e=>E(qw(e),void 0,"score").cost,{passes:6});e=Xw(e,d,z),O=qw(e)}else j(O,(e,t)=>E(e,t,"score"),1,1/0);let V=Yw(s);O=Yw(O);let H=E(O),U=E(V);if(G){let e=L(V),t=L(O);(H.crossings>U.crossings||H.crossings===U.crossings&&t>e+1e-9||H.cost>U.cost)&&(O=V,H=U)}else H.cost>U.cost&&(O=V,H=U);let Z=function({order:e,after:t,nodes:i,edges:r,outgoingPartners:n,incomingPartners:o,slotForNode:a,averageGap:s,evaluate:l}){let c=(i,n)=>{let o=[...new Set(n.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),a=e.indexOf(i),c=o[0],u=o[o.length-1];if(o.length<3||!o.includes(a)||u-c+1!==o.length||Math.abs(2*a-c-u)<=1)return;let d=[...e];d.splice(a,1),d.splice(c+u>>1,0,i);let h=Yw(d),p=l(h),f=new Set(i.occupants.map(e=>e.id)),g=new Set(n.flatMap(e=>e.occupants.map(e=>e.id))),m=r.reduce((e,t)=>f.has(t.source)&&g.has(t.target)||f.has(t.target)&&g.has(t.source)?e+(t.value>0?t.value:1):e,0),y=Math.abs(2*a-c-u)*s*Math.max(1,m);(function(e,t,i=0){return e.crossings<t.crossings||e.crossings===t.crossings&&e.cost<=t.cost+i})(p,t,y)&&(e=h,t=p)};for(let[e,t]of n)!o.has(e)&&t.size>=3&&c(a.get(e),[...t].map(e=>a.get(e)));for(let e of i){let t=a.get(e.id);!e.group&&t.group&&(o.get(e.id)?.size??0)>=3&&c(t,[...o.get(e.id)??[]].map(e=>a.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,i)=>i.indexOf(e)===t))}return{order:e,after:t}}({order:O,after:H,nodes:e,edges:t,outgoingPartners:M,incomingPartners:$,slotForNode:c,averageGap:p,evaluate:E});return O=Z.order,H=Z.after,jw(n,o,O),{before:U,after:H,initialOrder:s.map(e=>l.get(e)),evaluations:y}}function tk(e,t,i){let r=e.map(e=>{let r=e.occupants.map(e=>({id:e.id,end:i[e.id]?.end??e.end})),n=0,o=0;for(let e of r){let i=t[e.id];n=Math.max(n,i?.topPeak||0),o=Math.max(o,i?.botPeak||0)}return{occupants:r,peak:{topPeak:n,botPeak:o},...null!=e.group?{group:e.group}:{}}}),n=mw();return r.forEach((e,t)=>{for(let i of e.occupants)n[i.id]=t}),{slots:r,slotByNode:n}}var ik=/*#__PURE__*/new Map,rk=1e5,nk=1e-9;function ok(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(e.end<=t.start||t.end<=e.start)}function ak(e,t){return yw(e,t)<=0?`${e}\0${t}`:`${t}\0${e}`}function sk(e){let t=new Map,i=new Map;for(let r of e)i.has(r.source)||i.set(r.source,new Set),t.has(r.target)||t.set(r.target,new Set),i.get(r.source).add(r.target),t.get(r.target).add(r.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...i].map(([e,t])=>[e,t.size]))}}function lk(e){let t=new Map,i=new Map,r=(e,t,i,r)=>{let n=e.get(t);n||(n=new Map,e.set(t,n)),n.set(i,(n.get(i)??0)+r)};for(let n of e){let e=n.value>0&&Number.isFinite(n.value)?n.value:1;r(t,n.source,n.target,e),r(i,n.target,n.source,e)}let n=new Map,o=e=>{if(n.has(e))return;let r=t.get(e),o=i.get(e),a=new Map;for(let[e,t]of r??[])a.set(e,(a.get(e)??0)+t);for(let[e,t]of o??[])a.set(e,(a.get(e)??0)+t);if(1===a.size){let[t,i]=[...a][0];n.set(e,{partner:t,weight:i})}};for(let t of e)o(t.source),o(t.target);return n}function ck(e,t,i){let r=i.get(e),n=i.get(t);return!r||!n||r.partner===n.partner||r.partner===t||n.partner===e}function uk(e,t,i){return!!i.has(e)&&t.some(t=>!ck(e,t,i))}function dk(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function hk(e,t,i,r){if(e.length<=12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>new Map),a=sk(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=dk(e,a);o[t].set(i,(o[t].get(i)??0)+r),o[i].set(t,(o[i].get(t)??0)+r)}let s=lk(i),l=e.map(e=>s.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map),u=0;for(let i=0;i<e.length-1&&u<5e4;i++)if(s.has(e[i]))for(let r=i+1;r<e.length;r++){if(!s.has(e[r])||t.conflicts(e[i],e[r]))continue;u++;let n=Math.min(l[i],l[r])||Math.max(l[i],l[r]),o=ck(e[i],e[r],s)?n:-n;if(!(Math.abs(o)<=nk)&&(c[i].set(r,o),c[r].set(i,o),u>=5e4))break}let d=[...r.assignment],h=Array.from({length:r.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));let p=(e,t,i)=>{let r=d[t],n=d[i],o=0,a=new Set;for(let s of[t,i])for(let[l,c]of e[s]){let e=s<l?`${s}:${l}`:`${l}:${s}`;if(a.has(e))continue;a.add(e);let u=d[s]===d[l],h=(s===t?n:r)===(l===t?n:l===i?r:d[l]);u!==h&&(o+=h?c:-c)}return o},f=(e,t,i)=>{let r=0;for(let[n,o]of e[t]){let e=d[t]===d[n],a=i===d[n];e!==a&&(r+=a?o:-o)}return r},g=(e,t)=>e>nk||Math.abs(e)<=nk&&t>nk,m=(e,t,i,r)=>e>i+nk||Math.abs(e-i)<=nk&&t>r+nk,y=0;for(let i=0;i<32&&y<rk;i++){let i=null,r=-1,n=-1,a=-1,s=-1/0,l=-1/0;for(let u=0;u<e.length;u++){for(let p=0;p<h.length&&!(y++>=rk);p++){if(p===d[u]||!h[p].every(i=>!t.conflicts(e[u],e[i])))continue;let y=f(o,u,p),x=f(c,u,p);g(y,x)&&m(y,x,s,l)&&(i="move",r=u,n=-1,a=p,s=y,l=x)}if(y>=rk)break}for(let u=0;u<e.length-1;u++){for(let f=u+1;f<e.length&&!(y++>=rk);f++){let y=d[u],x=d[f];if(y===x||!h[x].every(i=>i===f||!t.conflicts(e[u],e[i]))||!h[y].every(i=>i===u||!t.conflicts(e[f],e[i])))continue;let b=p(o,u,f),v=p(c,u,f);g(b,v)&&m(b,v,s,l)&&(i="swap",r=u,n=f,a=-1,s=b,l=v)}if(y>=rk)break}if(null==i||-1===r)break;if("move"===i){let e=d[r];h[e].splice(h[e].indexOf(r),1),h[a].push(r),d[r]=a;continue}let u=d[r],x=d[n];h[u].splice(h[u].indexOf(r),1,n),h[x].splice(h[x].indexOf(n),1,r),d[r]=x,d[n]=u}return d}function pk(e,t){let i=1/0,r=-1/0;for(let t of e?.samples??[])t.topMass+t.botMass<=1e-9||(i=Math.min(i,t.t),r=Math.max(r,t.t));return Number.isFinite(i)&&Number.isFinite(r)?(null!=t.start&&(i=Math.max(i,t.start)),null!=t.end&&(r=Math.min(r,t.end)),r>=i?{start:i,end:r}:{start:null,end:null}):{start:null,end:null}}function fk(e,t,i,r){let n=function(e,t,i,r){return`${e.map(e=>{let t=i[e.id],n=r[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,n?.start??"",n?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,i,r),o=function(e){return ik.get(e)}(n);if(o)return tk(o.slots,i,r);let a=mw();for(let t of e)a[t.id]=pk(i[t.id],r[t.id]);let s=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,i)=>t[e.id].start-t[i.id].start||t[e.id].end-t[i.id].end||yw(e.id,i.id)).map(e=>e.id)}(e,a),l=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=lk(t),d=function(e,t,i,r,n,o){let a=new Set,s=new Map(e.map(e=>[e,new Set])),l=new Map(e.map(e=>[e,new Set]));for(let e of r)a.add(ak(e.source,e.target)),s.get(e.target)?.add(e.source),l.get(e.source)?.add(e.target);let c=new Map,u=new Set,d=(e,t)=>{for(let i=0;i<e.length;i++)for(let r=i+1;r<e.length;r++){let n=ak(e[i],e[r]);t instanceof Map?t.set(n,[e[i],e[r]]):t.add(n)}};for(let e of l.values())d([...e],c);for(let e of s.values())d([...e],u);let h=new Set;for(let[e,[r,n]]of c)u.has(e)&&(ok(t[r],t[n])||ok(i[r],i[n])&&(h.add(r),h.add(n)));return{conflicts:(e,i)=>{let r=n.get(e),s=n.get(i);return!((null==r||null==s||r===s)&&(null!=r==(null!=s)||a.has(ak(e,i))||o.has(e)&&o.has(i)&&ck(e,i,o))&&!ok(t[e],t[i])&&(!h.has(e)&&!h.has(i)||a.has(ak(e,i))))}}}(s,a,r,t,c,u),h=function(e,t,i=new Map){let r=[],n=[];for(let o of e){let e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e))&&!uk(o,e,i));-1===e&&!i.has(o)&&(e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e)))),-1===e&&(e=r.length,r.push([])),r[e].push(o),n.push(e)}return{assignment:n,slotCount:r.length}}(s,d,u),p=function(e,t,i,r){if(0===e.length||e.length>12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>new Float64Array(e.length)),a=Array.from({length:e.length},()=>new Map),s=Array.from({length:e.length},()=>new Map),l=sk(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=dk(e,l);o[t][i]+=r,o[i][t]+=r,s[t].set(i,(s[t].get(i)??0)+r),a[i].set(t,(a[i].get(t)??0)+r)}let c=lk(i),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++){for(let[e,r]of a[t])d[t][i]+=Math.min(r,a[i].get(e)??0);for(let[e,r]of s[t])d[t][i]+=Math.min(r,s[i].get(e)??0);if(c.has(e[t])&&c.has(e[i])){let r=Math.min(u[t],u[i])||Math.max(u[t],u[i]);d[t][i]+=ck(e[t],e[i],c)?r:-r}d[i][t]=d[t][i]}let h=[...r.assignment],p=(t=>{let i=0,r=0;for(let n=0;n<e.length;n++)for(let a=n+1;a<e.length;a++)t[n]===t[a]&&(i+=o[n][a],r+=d[n][a]);return{flow:i,affinity:r}})(h),f=0,g=new Array(e.length).fill(-1),m=Array.from({length:r.slotCount},()=>[]),y=(i,n,a,s)=>{if(f>=75e3)return;if(i===e.length)return f++,void((a>p.flow||a===p.flow&&s>p.affinity||a===p.flow&&s===p.affinity&&function(e,t){for(let i=0;i<Math.min(e.length,t.length);i++)if(e[i]!==t[i])return e[i]<t[i];return e.length<t.length}(g,h))&&(h=[...g],p={flow:a,affinity:s}));let l=Math.min(n+1,r.slotCount-1);for(let r=0;r<=l;r++){if(m[r].some(r=>t.conflicts(e[i],e[r])))continue;let l=0,c=0;for(let e of m[r])l+=o[i][e],c+=d[i][e];if(g[i]=r,m[r].push(i),y(i+1,Math.max(n,r),a+l,s+c),m[r].pop(),g[i]=-1,f>=75e3)return}};return g[0]=0,m[0].push(0),y(1,0,0,0),h}(s,d,t,{...h,assignment:hk(s,d,t,h)}),f=new Map,g=p.map(e=>(f.has(e)||f.set(e,f.size),f.get(e))),m=Array.from({length:f.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y=mw();s.forEach((e,t)=>{let i=g[t],r=m[i];r.occupants.push({id:e,end:a[e].end??-1/0});let n=l.get(e)?.group;n&&(r.group=n),y[e]=i});for(let t of[...e].sort((e,t)=>yw(e.id,t.id)))null==y[t.id]&&(m[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(let e of m){e.occupants.sort((e,t)=>(a[e.id].start??1/0)-(a[t.id].start??1/0)||yw(e.id,t.id));for(let t of e.occupants){let r=i[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,r?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,r?.botPeak||0)}}let x={slots:m,slotByNode:y};return function(e,t){for(ik.has(e)&&ik.delete(e),ik.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(mw(),t.slotByNode)});ik.size>12;){let e=ik.keys().next().value;if(null==e)break;ik.delete(e)}}(n,x),x}function gk(e){return e.topMass+e.botMass}function mk(e){let t=new Map;for(let i of e.samples){if(Number.isNaN(i.t))continue;let e=t.get(i.t);e||(e=[],t.set(i.t,e)),e.push(i)}let i=0,r=-1/0;return n=>{n>=r||(i=0),r=n;let o=t.get(n);if(o){let e=o.reduce((e,t)=>gk(t)>=gk(e)?t:e,o[0]);return{exact:o,sample:e}}for(;i<e.samples.length&&!(e.samples[i].t>n);)i++;return{exact:o,sample:e.samples[i-1]??null}}}function yk(e,t,i,r,n,o,a=0){let s=new Map;for(let i of e){if(!i.group||!t[i.id])continue;let e=s.get(i.group)??[];e.push(i),s.set(i.group,e)}if(0===s.size||!(o>0))return t;let l=function(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]))}(t);for(let[e,c]of s){let s=i.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===s.length)continue;let u=s[0].slot,d=s.at(-1).slot,h=n[u.occupants[0]?.id],p=n[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;let f=(h-u.peak.topPeak*o+(p+d.peak.botPeak*o))/2,g=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),m=new Map;for(let e of c)m.set(e.id,new Map);let y=new Map(c.map(e=>[e.id,mk(t[e.id])]));for(let e of g){let t=new Map;for(let i of c){let{sample:n}=y.get(i.id)(e);if(!n||gk(n)<=1e-9)continue;let o=r[i.id];if(null==o)continue;let a=t.get(o)??[];a.push({node:i,sample:n}),t.set(o,a)}let i=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:ue(t.map(({sample:e})=>gk(e)))}));if(0===i.length)continue;let s=f-(i.reduce((e,t)=>e+t.mass,0)*o+Math.max(0,a)*Math.max(0,i.length-1))/2;for(let t of i){for(let{node:i,sample:r}of t.active){let t=(s-n[i.id])/o+r.topMass-(r.boundaryOffset??0);m.get(i.id).set(e,t)}s+=t.mass*o+Math.max(0,a)}}for(let e of c){let i=t[e.id],r=l[e.id],n=m.get(e.id),o=y.get(e.id),a=[];for(let e of g){let t=n.get(e),{exact:i,sample:r}=o(e);i?a.push(...i.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!r||gk(r)<=1e-9||a.push({...r,t:e,boundaryOffset:(r.boundaryOffset??0)+t})}r.samples=a,r.localAttachments=new Map([...i.localAttachments].map(([e,t])=>{let i=n.get(t.time);return[e,{...t,...null!=i?{boundaryOffset:(t.boundaryOffset??0)+i}:{}}]}))}}return l}function xk(e,t,i,r,n){let{plotH:o,padding:a,valueScale:s,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:f}=n,g=mw(),m=mw();for(let t of e)g[t.id]=i[t.id].topPeak||0,m[t.id]=i[t.id].botPeak||0;let y="half"===u,x=mw();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,i=Array.isArray(t.xExtent)?t.xExtent[1]:null,n=null!=e&&Number.isFinite(e)?e:1/0,o=null!=i&&Number.isFinite(i)?i:-1/0;for(let e of r.outgoing[t.id]){e.startTime<n&&(n=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<n&&(n=e.systemInTime);let t=y?(e.startTime+e.endTime)/2:e.endTime;t>o&&(o=t)}for(let e of r.incoming[t.id]){let t=y?(e.startTime+e.endTime)/2:e.startTime;t<n&&(n=t),e.endTime>o&&(o=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>o&&(o=e.systemOutTime)}x[t.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(o)?o:null}}let b=mw(),v=[],w=[];if(n.frozenSlots){let e=tk(n.frozenSlots,i,x);v=e.slots,b=e.slotByNode,w=v.map(xw)}else if("reuse"===l){let r=fk(e,t,i,x);v=r.slots,b=r.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:x[e.id]?.end??-1/0}],peak:{topPeak:g[e.id],botPeak:m[e.id]},...e.group?{group:e.group}:{}}),b[e.id]=t});Gw(v,b),0===w.length&&(w=v.map(xw));let k=null;n.frozenSlots||(n.fixedSlotOrder?function(e,t,i){let r=new Map(i.map((e,t)=>[e,t]));jw(e,t,[...e].sort((e,t)=>(r.get(xw(e))??1/0)-(r.get(xw(t))??1/0)||yw(xw(e),xw(t))))}(v,b,n.fixedSlotOrder):n.runOrdering&&c&&"insertion"!==c&&(k=ek(e,t,i,x,v,b,{plotH:o,padding:a,valueScale:s,groupPadding:h,laneOrder:c,ribbonLane:p,domain:f}))),Gw(v,b);let S=Sw(e,t,i,v,b,{plotH:o,padding:a,valueScale:s,stackValueScale:n.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,$=k?.after.crossings??null,_=k?.before.weightedLength??null,P=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(xw),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:$,lengthBefore:_,lengthAfter:P}}function bk(e,t,i){let{plotH:r,pairing:n="temporal",packing:o="reuse",laneOrder:a="crossing-min",lifetimeMode:s="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=i,f=Number.isFinite(d)?Math.max(0,d):0,g=function(e,t){let i=mw(),r=mw();for(let t of e)i[t.id]=[],r[t.id]=[];for(let e of t)r[e.source]&&r[e.source].push(e),i[e.target]&&i[e.target].push(e);return{incoming:i,outgoing:r}}(e,t),m=function(e,t,i,r="temporal"){let n="temporal"===r?(e,t)=>e.endTime-t.endTime||yw(e.id,t.id):(e,t)=>t.value-e.value||yw(e.id,t.id),o="temporal"===r?(e,t)=>e.startTime-t.startTime||yw(e.id,t.id):(e,t)=>t.value-e.value||yw(e.id,t.id),a=new Map;for(let e of t)a.set(e.id,{});let s=(e,t)=>{let i=new Map;for(let r of e){let e=r[t];i.has(e)||i.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let n=i.get(e);n.edges.push(r),n.total+=r.value,n.earliestStart=Math.min(n.earliestStart,r.startTime),n.latestEnd=Math.max(n.latestEnd,r.endTime)}let a=[...i.values()];"temporal"===r?a.sort((e,i)=>"target"===t?e.earliestStart-i.earliestStart||yw(e.partner,i.partner):e.latestEnd-i.latestEnd||yw(e.partner,i.partner)):a.sort((e,t)=>t.total-e.total||yw(e.partner,t.partner));for(let e of a)e.edges.sort("target"===t?o:n);return a};for(let t of e){let e=i.outgoing[t.id],r=i.incoming[t.id];if(0===r.length)s(e,"target").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).sourceSide=i});else if(0===e.length)s(r,"source").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).targetSide=i});else{let t=s(r,"source"),i=s(e,"target"),n=Math.max(t.length,i.length);for(let e=0;e<n;e++){let r=e%2==0?"top":"bot";if(t[e])for(let i of t[e].edges)a.get(i.id).targetSide=r;if(i[e])for(let t of i[e].edges)a.get(t.id).sourceSide=r}}}return a}(e,t,g,n),y=mw();for(let t of e)y[t.id]=Dw(t,g,m,void 0,u);let x=xk(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,runOrdering:!0,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),b=x.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=new Set;for(let e of t){let t=x.slotByNode[e.source],i=x.slotByNode[e.target];if(void 0===t||void 0===i)continue;let r=m.get(e.id);t!==i?i<t?(r.sourceSide="top",r.targetSide="bot"):(r.sourceSide="bot",r.targetSide="top"):(v.add(e.id),r.sourceSide="bot",r.targetSide="bot")}for(let t of e){let e=g.outgoing[t.id],i=g.incoming[t.id],r=new Set(e.map(e=>m.get(e.id).sourceSide)),n=new Set(i.map(e=>m.get(e.id).targetSide));if(1===r.size&&i.length>0){let e=[...r][0];for(let t of i)x.slotByNode[t.source]===x.slotByNode[t.target]&&(m.get(t.id).targetSide=e)}if(1===n.size&&e.length>0){let t=[...n][0];for(let i of e)x.slotByNode[i.source]===x.slotByNode[i.target]&&(m.get(i.id).sourceSide=t)}}(function(e,t,i){let r=new Map,n=[];for(let t of e)n.push({time:t.startTime,kind:"out",edge:t}),n.push({time:t.endTime,kind:"in",edge:t});n.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||yw(e.edge.id,t.edge.id));let o=e=>{let t=r.get(e);return t||(t={top:0,bot:0},r.set(e,t)),t},a=(e,t,i)=>{let r="top"===t?"bot":"top",n=Math.min(i,e[t]);e[t]-=n;let o=i-n;o>0&&(e[r]=Math.max(0,e[r]-o))};for(let e of n){let{edge:r}=e;if("in"===e.kind){let e=t.get(r.id)?.targetSide??"bot";o(r.target)[e]+=r.value;continue}let n=o(r.source),s=t.get(r.id),l=s.sourceSide??"bot";if(i[r.source]===i[r.target]){let e=n.top>=r.value,t=n.bot>=r.value;e!==t?l=e?"top":"bot":!e&&!t&&n.top!==n.bot&&(l=n.top>n.bot?"top":"bot"),s.sourceSide=l,s.targetSide=l}a(n,l,r.value)}})(t,m,x.slotByNode),function(e,t,i,r){for(let n of e){let e=t.incoming[n.id],o=t.outgoing[n.id];if(0===e.length||0===o.length)continue;let a=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let r of e)"top"===i.get(r.id).targetSide?t.inTop+=r.value:t.inBot+=r.value;for(let e of o)"top"===i.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},s=(e,t)=>{let n=a(),s="top"===e?n.outTop-n.inTop:n.outBot-n.inBot,l="top"===t?n.inTop-n.outTop:n.inBot-n.outBot;if(s<=0||l<=0)return!1;let c=Math.min(s,l),u=o.filter(t=>!r.has(t.id)&&i.get(t.id).sourceSide===e&&t.value<=c).sort((e,t)=>t.value-e.value||yw(e.id,t.id));return 0!==u.length&&(i.get(u[0].id).sourceSide=t,!0)},l=o.length+1;for(;l-- >0&&(s("top","bot")||s("bot","top")););}}(e,g,m,v),y=mw();for(let t of e)y[t.id]=Dw(t,g,m,void 0,u);let w=xk(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),k=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((e,t,i)=>e+(null!=t.group&&t.group===w.slots[i+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*r-S*f)/A),$=2*M+bw(w.slots,M,f).reduce((e,t)=>e+t,0),_=k>0?Math.max(0,(r-$)/k):1,P=Number.isFinite(l)&&l>0?Math.min(_,l):_,I=xk(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_}),T=Number.isFinite(l)&&l>0&&l+1e-12<_;if("insertion"!==a&&("hug"===c||T)&&I.slots.length>1&&(ek(e,t,y,I.laneLifetime,I.slots,I.slotByNode,{plotH:r,padding:M,valueScale:P,groupPadding:f,laneOrder:a,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),I=xk(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:I.slots,fixedSlotOrder:I.slots.map(xw),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_})),function(e,t){let i=(e,i)=>{for(let r of e){let e=new Map;for(let n of r){let r=`${("out"===i?t.get(n.id)?.sourceSide:t.get(n.id)?.targetSide)??""}\0${"out"===i?n.startTime:n.endTime}`,o="out"===i?`${n.target}\0${n.endTime}`:`${n.source}\0${n.startTime}`,a=e.get(r);if(null!=a&&a!==o)return!0;e.set(r,o)}}return!1};return i(Object.values(e.outgoing),"out")||i(Object.values(e.incoming),"in")}(g,m)){let i=function(e,t,i,r){let n=new Map;for(let o of e){let e=t[o.source]?.localAttachments.get(o.id),a=t[o.target]?.localAttachments.get(o.id),s=i[o.source],l=i[o.target];if(!(e&&a&&Number.isFinite(s)&&Number.isFinite(l)))continue;let c=Nw(e,s,r),u=Nw(a,l,r);n.set(o.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return n}(t,y,I.centerlines,P);y=mw();for(let t of e)y[t.id]=Dw(t,g,m,i,u);I=xk(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:I.slots,fixedSlotOrder:I.slots.map(xw),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_})}let L=new Map(x.initialSlotOrder.map((e,t)=>[e,t])),C=[...I.slots].sort((e,t)=>(L.get(xw(e))??1/0)-(L.get(xw(t))??1/0)||yw(xw(e),xw(t))),R=mw();C.forEach((e,t)=>{for(let i of e.occupants)R[i.id]=t});let N=Sw(e,t,y,C,R,{plotH:r,padding:M,valueScale:P,stackValueScale:_,lanePlacement:"stack",groupPadding:f}),D=yk(e,y,C,R,N.centerlines,P,f),F=Lw(Vw(R,t),Hw(R,t),t,D,C,R,N.centerlines,I.laneLifetime,P,N.verticalUtilization,h,p);y=yk(e,y,I.slots,I.slotByNode,I.centerlines,P,f);let E=Lw(Vw(I.slotByNode,t),Hw(I.slotByNode,t),t,y,I.slots,I.slotByNode,I.centerlines,I.laneLifetime,P,I.verticalUtilization,h,p);return{nodeData:y,sides:m,valueScale:P,padding:M,compressedPadding:M<12,centerlines:I.centerlines,laneLifetime:I.laneLifetime,slots:I.slots,slotByNode:I.slotByNode,crossingsBefore:"insertion"===a?null:F.crossings,crossingsAfter:"insertion"===a?null:E.crossings,lengthBefore:"insertion"===a?null:F.weightedLength,lengthAfter:"insertion"===a?null:E.weightedLength,layoutQualityBefore:F,layoutQuality:E}}function vk(e){return j(e)}function wk(e,t,i,r,n,o,a,s,l={}){let c,u,d,h,p=n,f=e=>s?Math.max(s[0],Math.min(s[1],e)):e,g=o(f(e.time)),m=o(f(i.time)),y=e.value*p,x=i.value*p,b=t+(e.boundaryOffset??0)*p,v=r+(i.boundaryOffset??0)*p,w=e.sideMassBefore*p,k=i.sideMassAfter*p;"top"===e.side?(c=b-w,u=c+y):(u=b+w,c=u-y),"top"===i.side?(d=v-k,h=d+x):(h=v+k,d=h-x);let S=l.sourceRunwayStart,A=l.minRun,M=(c+u)/2,$=(d+h)/2,_=Math.abs($-M),P=m-g,I="number"==typeof S&&Number.isFinite(S),T="number"==typeof A&&Number.isFinite(A)&&A>0;if(I&&_>1e-9&&P>0&&("auto"===A||T)){let t="source"===a?.85:"target"===a?.15:.5,i=1.5*Math.min(t*t,(1-t)*(1-t)),r="auto"===A?Math.min(144,Math.sqrt(8*_/i)):A;if(r>P){let t=o(f(Math.min(S,e.time)));if(Number.isFinite(t)){let e=Math.min(g,t);g=Math.min(g,Math.max(e,m-r))}}}let L="source"===a?g+.85*(m-g):"target"===a?g+.15*(m-g):(g+m)/2;return{sx:g,sTop:c,sBot:u,tx:m,tTop:d,tBot:h,cp1X:L,cp2X:L}}function kk(e){return Math.max(18,11*e.length*.58)}function Sk(e){let t=1.22*kk(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function Ak(e,t){let i=e.labelX-kk(e.labelText),r=t.labelX-kk(t.labelText);return i<=t.labelX+3&&r<=e.labelX+3}var Mk=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function $k(e){return e.replace(Mk,(e,t,i)=>`${i},${t}`)}function _k(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function Pk(e){return{...e,pathD:$k(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function Ik(e,t=function(e){let{nodes:t,edges:i,domain:r,usageMode:n="static"}=e,o=function(e,t,i,r={}){let n=aw(r.usageMode??"static"),o=[],a=new Set;for(let t of e)a.has(t.id)&&o.push({kind:"duplicate-node",id:t.id,severity:n.duplicateIds}),a.add(t.id);let s=new Set,l=Array.isArray(i)&&2===i.length,c=l&&Number.isFinite(i[0])&&Number.isFinite(i[1]),u=c&&i[0]<=i[1];(!l||!c||!u)&&o.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[0]<=t.xExtent[1]||o.push({kind:"invalid-node-time",id:t.id}));for(let e of t)s.has(e.id)&&o.push({kind:"duplicate-edge",id:e.id,severity:n.duplicateIds}),s.add(e.id),a.has(e.source)||o.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),a.has(e.target)||o.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&o.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||e.value<=0)&&o.push({kind:"invalid-value",id:e.id}),e.endTime<e.startTime&&o.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):o.push({kind:"invalid-edge-time",id:e.id});return o}(t,i,r,{usageMode:n}),{fatal:a,warnings:s}=function(e){let t=[],i=[];for(let r of e)"fatal"===lw(r)?t.push(r):i.push(r);return{fatal:t,warnings:i}}(o),l=cw(i,o,n);return{layout:a.length?null:bk(t,l,{plotH:"vertical"===e.orientation?e.plotW:e.plotH,...e.layoutOpts,ribbonLane:e.ribbonLane,domain:r}),issues:a,warnings:s}}(e)){let{nodes:i,edges:r,domain:n,plotW:o,plotH:a,ribbonLane:s,ribbonMinRun:l=0,edgeOpacity:c,colorOf:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:p,maxLabels:f,selectionDatum:g="raw",styleRules:m,colorBy:y,valueAccessor:x,usageMode:b="static"}=e,v="vertical"===d?a:o,w="vertical"===d?o:a,{layout:k,issues:S,warnings:A}=t,M=cw(r,[...S,...A],b),$=nw().domain(n).range([0,v]);if(!k)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:$};let{centerlines:_,nodeData:P,valueScale:I}=k,T=ne(y,x),L=[],C=[],R=0===l?new Map:function(e,t,i){let r=new Set(t.map(e=>e.target)),n=new Map(e.map(e=>[e.id,e])),o=new Map;for(let e of t){if(r.has(e.source))continue;let t=o.get(e.source)??[];t.push(e),o.set(e.source,t)}let a=new Map;for(let t of e){if(!t.group)continue;let e=a.get(t.group)??[];e.push(t),a.set(t.group,e)}let s=new Set;for(let[e,t]of a){let i=t.flatMap(e=>o.get(e.id)??[]),n=new Set(i.map(e=>e.startTime));i.length>0&&1===n.size&&t.every(e=>{let t=e.xExtent?.[0],n=i[0].startTime;return!r.has(e.id)&&(o.get(e.id)?.length??0)>0&&Number.isFinite(t)&&t<n})&&s.add(e)}let l=new Map;for(let[e,t]of o){let r=n.get(e);if(r?.group&&!s.has(r.group))continue;let o=r?.xExtent?.[0],a=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=a[0]?.startTime-1,u=null;for(let e=0;e<a.length;){let t=a[e].startTime,r=e+1;for(;r<a.length&&a[r].startTime===t;)r++;for(let t=e;t<r;t++){let e=a[t],r=Number.isFinite(o)&&o<e.startTime,n=Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime;if(!r&&!n)continue;let s=i[0];r&&(s=Math.max(s,o)),n&&(s=Math.max(s,e.systemInTime)),!r&&n&&Number.isFinite(c)&&(s=Math.max(s,c)),null!=u&&(s=Math.max(s,u)),s<e.startTime&&l.set(e.id,s)}u=t,e=r}}for(let[e,t]of a){if(!s.has(e))continue;let i=t.flatMap(e=>o.get(e.id)??[]);if(!i.every(e=>l.has(e.id))){for(let e of i)l.delete(e.id);continue}let r=ue(i.map(e=>l.get(e.id)));for(let e of i)l.set(e.id,r)}return l}(i,M,n),N=new Map(i.filter(e=>e.group).map(e=>[e.id,e.group])),D=new Map;for(let e of M){let t=P[e.source]?.localAttachments.get(e.id),i=P[e.target]?.localAttachments.get(e.id);!t||!i||D.set(e.id,wk(t,_[e.source],i,_[e.target],I,$,s,n,{minRun:l,sourceRunwayStart:R.get(e.id)}))}let F=function(e,t,i,r,n,o){let a=new Map(t),s=new Map;for(let t of e){let e=o?.get(t.source),i=null==e?`node:${t.source}`:`group:${e}`,r=s.get(i)??new Map,n=r.get(t.startTime)??[];n.push(t),r.set(t.startTime,n),s.set(i,r)}for(let e of s.values())for(let[o,s]of e){if(!s.some(e=>i.has(e.id)))continue;let e=s.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let l=r(o),c=ce(e.map(e=>e.sx));if(!(c<l-1e-9))continue;let u=ue(s.map(e=>{let t=i.get(e.id);return null==t?l:Math.min(l,r(t))})),d=Math.min(l,Math.max(c,u));for(let e of s){let i=t.get(e.id),r="source"===n?.85:"target"===n?.15:.5,o=d+(i.tx-d)*r;a.set(e.id,{...i,sx:d,cp1X:o,cp2X:o})}}return a}(M,D,R,$,s,N),E=function(e,t,i,r,n){let o=new Map;for(let a of e){if(!i.has(a.id))continue;let e=t.get(a.id);if(!(e&&e.sx<r(a.startTime)-1e-9))continue;let s=n(e.sx);Number.isFinite(s)&&s<a.startTime&&o.set(a.id,s)}return o}(M,F,R,$,e=>n[0]+e/v*(n[1]-n[0])),O=function(e,t,i){let r=new Map,n=new Map;for(let[e,t]of i??[]){let i=n.get(t)??[];i.push(e),n.set(t,i)}for(let o of e){let e=t.get(o.id);if(!(null!=e&&Number.isFinite(e)&&e<o.startTime))continue;let a=i?.get(o.source),s=null==a?[o.source]:n.get(a)??[o.source];for(let t of s){let i=r.get(t)??new Map,n=i.get(o.startTime);i.set(o.startTime,null==n?e:Math.min(n,e)),r.set(t,i)}}return r}(M,E,N);i.forEach((e,t)=>{let i=P[e.id];if(!i||0===i.samples.length)return;let r=function(e,t){return t&&0!==t.size?e.map(e=>{let i=t.get(e.t);return null==i?e:{...e,t:i}}):e}(i.samples,O.get(e.id)),o=function(e,t,i,r,n){if(0===e.length)return null;let o=Rw(e,n),a=e=>t+(o[e].boundaryOffset??0)*i,s=e=>a(e)-o[e].topMass*i,l=e=>a(e)+o[e].botMass*i,c=`M${r(o[0].t)},${s(0)}`;for(let e=1;e<o.length;e++)c+=` L${r(o[e].t)},${s(e)}`;c+=` L${r(o[o.length-1].t)},${l(o.length-1)}`;for(let e=o.length-2;e>=0;e--)c+=` L${r(o[e].t)},${l(e)}`;return c+" Z"}(r,_[e.id],I,$,n);if(!o)return;let a,s,l=Rw(r,n),c=l.find(e=>e.topMass+e.botMass>0)||l[0],h=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*I/2,p=_[e.id]+h,f=u(e.id,t),g=f,y=.5,x=e.__raw??e;if(m&&m.length>0){let e=oe(x,m,T(x));"string"==typeof e.fill?f=e.fill:null!=e.fill&&ka(e.fill)&&(s=e.fill,f=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:f),"string"==typeof e.stroke&&(g=e.stroke),"number"==typeof e.strokeWidth&&(y=e.strokeWidth),"number"==typeof e.fillOpacity&&(a=e.fillOpacity),"number"==typeof e.opacity&&null==a&&(a=e.opacity)}let b=function(e,t,i,r,n,o){let a=i.nodeData[e];if(!a||0===a.samples.length)return[];let s=i.valueScale,l=i.centerlines[e],c=Rw(a.samples,n),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=r(u.t),p=r(d.t),f=e=>r(Cw(e,n)),g=[],m=(e,t,i,r)=>`M${e},${t} L${i},${t} L${i},${r} L${e},${r} Z`;for(let i of t){if(i.source===e&&null!=i.systemInTime&&Number.isFinite(i.systemInTime)){let e=a.localAttachments.get(i.id),t=o?.get(i.id)??i.startTime;if(e&&"out"===e.kind&&i.systemInTime<t){let r=f(i.systemInTime),o=f(t),a=null!=n&&i.systemInTime<n[0],c=a?r:r-20,u=a?Math.min(o,r+20):r,d=Math.max(h,c);if(o>d){let[t,i]=Nw(e,l,s);g.push({pathD:m(d,t,o,i),x0:c,x1:u,from:0,to:1})}}}if(i.target===e&&null!=i.systemOutTime&&Number.isFinite(i.systemOutTime)){let e=a.localAttachments.get(i.id);if(e&&"in"===e.kind&&i.systemOutTime>i.endTime){let t=f(i.systemOutTime),r=f(i.endTime),n=t+20,o=Math.min(p,n);if(o>r){let[i,a]=Nw(e,l,s);g.push({pathD:m(r,i,o,a),x0:t,x1:n,from:1,to:0})}}}}return g}(e.id,M,k,$,n,E);L.push({id:e.id,pathD:o,fill:f,stroke:g,strokeWidth:y,...null!=a&&{fillOpacity:a},...s&&{hatchFill:s},...b.length>0&&{gradientStubs:b},rawDatum:x,labelX:$("vertical"===d&&e.xExtent?e.xExtent[0]:c.t)-4,labelY:p,labelText:e.label??e.id})});let z=new Map;i.forEach((e,t)=>z.set(e.id,t)),M.forEach(e=>{let t=F.get(e.id);if(!t)return;let i=z.get(e.source)??0,r=u(e.source,i),{pathD:n,bezier:o}=nb(t),a=e.__raw??e,s="function"==typeof c?Number(c(a)):c,l=Number.isFinite(s)?Math.max(0,Math.min(1,s)):.35;C.push({id:e.id,pathD:n,fill:r,opacity:l,rawDatum:a,bezier:o})});let B=function(e,t,i){let r=e.map(e=>({...e})),n=new Map;for(let e of r){let i=t[e.id];if(null==i)continue;let r=n.get(i)??[];r.push(e),n.set(i,r)}let o=e=>{if(e.length<2)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=(e.length-1)/2;e.forEach((e,n)=>{e.labelY=Math.max(8,Math.min(i-8,t+16*(n-r)))})};for(let e of n.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=-1/0;for(let r of e){let e=r.labelX-kk(r.labelText);t.length>0&&e>i+3&&(o(t),t=[],i=-1/0),t.push(r),i=Math.max(i,r.labelX)}o(t)}return function(e,t){let i=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;e<3;e+=1){for(let e=0;e<i.length;e+=1){let t=8;for(let r=0;r<e;r+=1)Ak(i[e],i[r])&&(t=Math.max(t,i[r].labelY+16));i[e].labelY=Math.max(i[e].labelY,t)}for(let e=i.length-1;e>=0;e-=1){let r=t-8;for(let t=e+1;t<i.length;t+=1)Ak(i[e],i[t])&&(r=Math.min(r,i[t].labelY-16));i[e].labelY=Math.min(i[e].labelY,r)}}}(r,i),r}(L,k.slotByNode,w).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:$k(e.pathD),gradientStubs:e.gradientStubs?.map(Pk),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),j="vertical"===d?function(e,t,i){let r=e.map(e=>({...e}));for(let e of r){let i=1.22*kk(e.labelText)+4;e.labelX=i>=t-4?t/2:Math.max(i/2+2,Math.min(t-i/2-2,e.labelX))}let n=[],o=[...r].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of o){let t=n[n.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?n.push([e]):t.push(e)}for(let e of n){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=new Map;for(let i of e){let[e,n]=Sk(i),o=t.findIndex(t=>e>t+8);-1===o&&(o=t.length),t[o]=n,r.set(i,o)}let n=e.reduce((e,t)=>e+t.labelY,0)/e.length,o=n<14*t.length+8;for(let t of e){let e=r.get(t)??0;t.labelY=o?Math.min(i-8,12+14*e):Math.max(8,n-14*e)}}return r}(B,o,a):B,W=new Map;if(null!=p)for(let e of i){let t=e.__raw??e,i="function"==typeof p?p(t):Number(t[p]);Number.isFinite(i)&&W.set(e.id,i)}let Y=function(e,t,i,r,n={}){if(!1===r)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===r)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let o=Math.max(1,t*i),a=Math.max(4,Math.min(e.length,Math.floor(o/14e3)));Number.isFinite(n.maxLabels)&&n.maxLabels>=0&&(a=Math.min(a,Math.floor(n.maxLabels)));let s=e.map((e,t)=>{let i=n.priorityById?.get(e.id),r=Math.abs(e.labelY);return{band:e,index:t,score:null!=i&&Number.isFinite(i)?1e6*i+kk(e.labelText):kk(e.labelText)+.01*r}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(s.slice(0,a).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(j,o,a,h,{...W.size>0&&{priorityById:W},...null!=f&&{maxLabels:f}});return{layout:k,layoutConfig:{bands:Y,ribbons:C.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:$k(e.pathD),bezier:_k(e.bezier)}}(e,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:A,xScale:$}}function Tk(e,t,i,r="horizontal"){return"vertical"===r?{top:e?38:t?28:16,right:24,bottom:24,left:i?72:24}:{top:e?30:t?24:8,right:80,bottom:i?28:8,left:80}}import{scaleLinear as Lk,scaleUtc as Ck}from"d3-scale";import{Fragment as Rk,jsx as Nk,jsxs as Dk}from"react/jsx-runtime";var Fk="var(--semiotic-grid, #94a3b8)",Ek="var(--semiotic-text-secondary, #475569)",Ok="var(--semiotic-text-secondary, #94a3b8)";function zk(e,t,i){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,i))}var Bk=e=>{let{bands:t=[],ribbons:i=[],showLabels:r=!0,selectionDatum:n="raw"}=e.config,o=e.selection??null,a=[];for(let e of i){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},i=!zk(t,o,n);a.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:i?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!zk({__kind:"band",data:e.rawDatum,id:e.id},o,n);for(let i=0;i<e.gradientStubs.length;i++){let r=e.gradientStubs[i];a.push({type:"bezier",pathD:r.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:r.x0,x1:r.x1,...null!=r.y0&&{y0:r.y0},...null!=r.y1&&{y1:r.y1},from:r.from,to:r.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${i}`}})}}for(let e of t){let t=!!(e.gradientStubs&&e.gradientStubs.length>0),i={__kind:"band",data:e.rawDatum,id:e.id},r=!zk(i,o,n),s=e.fillOpacity??.86,l=e.hatchFill??e.fill;a.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:l,fillOpacity:r?.22:s},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...r&&t?{opacity:.22}:{}},datum:i})}let s=r?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),i=e.labelText.trim().length>0,r=t&&o?.isActive&&zk({__kind:"band",data:e.rawDatum,id:e.id},o,n),a=i?e.labelText:r?e.labelFullText:"";return a.trim()?[{x:e.labelX,y:e.labelY,text:a,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:a,labels:s}},jk=(e,t,i,r,n)=>({data:e,nodeIDAccessor:n.nodeIdAccessor??n.nodeIDAccessor??"name",childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:t,colorByDepth:n.colorByDepth,showLabels:n.showLabels,colorScheme:i,...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}),Wk=(e,t,i,r,n)=>{let o=$i(r.theme).colors.categorical,a=new Map,s=Jb(e??null,n.childrenAccessor??"children"),l="function"==typeof t?t:null,c=l?"__hierarchyColor":"string"==typeof t?t:void 0,u=l?s.map(e=>({__hierarchyColor:l(e)})):s,d=t&&c?ii(u,c,i??r.colorScheme??o):void 0;return e=>{if(n.colorByDepth)return Qt[Number(e?.depth||0)%Qt.length];let r=e?.data||e;return t?ei(l?{__hierarchyColor:l(r)}:r,c,d??void 0):ni(void 0,o,i,void 0,a)}};function Yk(e,t,i,r){let n=ae(e,r.styleRules,ne(t,r.valueAccessor),e=>e?.data||e),o=i.nodeStyle||r.nodeStyle;return ai(o?"function"==typeof o?e=>({...n(e),...o(e)??{}}):e=>({...n(e),...o}):n,bi(r))}var qk={MotifBraidChart:Jv,DependencyForestChart:ew,ForceDirectedGraph:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=function(e){if(void 0!==e.edgeStyle)return e.edgeStyle;let{edgeWidth:t,edgeColor:i,edgeOpacity:r}=e,n=e.strokeWidth??1;return void 0!==t||void 0!==i||void 0!==r||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?o=>{let a=o?.data||o,s=n;if("number"==typeof t)s=t;else if("function"==typeof t)s=t(a);else if("string"==typeof t){let e=a?.[t],i="number"==typeof e?e:Number(e);s=Number.isFinite(i)&&i>0?i:n}return{stroke:i??e.stroke??"#999",strokeWidth:s,opacity:r??e.opacity??.6}}:void 0}(n),a=$i(r.theme).colors.categorical,s=new Map,l=Array.isArray(n.nodes)?n.nodes:[],c="string"==typeof t?t:"__ssrForceColorBy",u=t?ii("function"==typeof t?l.map(e=>({...e,__ssrForceColorBy:t(e)})):l,c,i??r.colorScheme??a):void 0,d=n.nodeStyle??(e=>({fill:t?ei(e?.data||e,t,u):ni(void 0,a,i,void 0,s),..."number"==typeof n.nodeSize&&{r:n.nodeSize}})),h=se(n.styleRules,t,"number"==typeof n.nodeSize?void 0:n.nodeSize),p=ai(h?(e,t)=>({...d(e),...h(e,t)}):d,{stroke:n.nodeStroke??n.stroke,strokeWidth:n.nodeStrokeWidth??n.strokeWidth,opacity:n.opacity});return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:t,colorScheme:i,iterations:n.iterations,forceStrength:n.forceStrength,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize??8,nodeSizeRange:n.nodeSizeRange,nodeStyle:p,edgeStyle:o,...r,showLabels:r.showLabels??n.showLabels??!1,showLegend:(r.showLegend??!!t)&&!!t}}},SankeyDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.nodes)?n.nodes:ev([],Array.isArray(n.edges)?n.edges:[],n.sourceAccessor||"source",n.targetAccessor||"target"),a=$i(r.theme).colors.categorical,s=new Map,l="string"==typeof t?t:"__ssrSankeyColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrSankeyColorBy:t(e)})):o,u=t?ii(c,l,i??r.colorScheme??a):void 0,d=e=>({fill:t?ei(e?.data||e,t,u):ni(void 0,a,i,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=se(n.styleRules,t,n.valueAccessor),p=h?(e,t)=>({...d(e),...h(e,t)}):d,f=function({edgeColorBy:e,colorBy:t,colorScale:i,nodeStyleFn:r,edgeOpacity:n,baseStyle:o={}}){return a=>{let s={fillOpacity:n,...o};if("function"==typeof e)s.fill=e(a);else if("source"===e){let e="object"==typeof a.source?a.source:null;t&&e?s.fill=ei(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else if("target"===e){let e="object"==typeof a.target?a.target:null;t&&e?s.fill=ei(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else"gradient"===e&&(s.fill="#999",s.fillOpacity=.7*n);return s}}({edgeColorBy:n.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:p,edgeOpacity:n.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:t,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:ai(n.nodeStyle||p,bi(n)),edgeStyle:ai(n.edgeStyle||f,bi(n)),colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t}}},ProcessSankey:{frameType:"network",layout:{margin:e=>Tk(!!e.title,!!e.showQualityReadout,!Array.isArray(e.axisTicks)||e.axisTicks.length>0,"vertical"===e.orientation?"vertical":"horizontal")},buildProps:(e,t,i,r,n)=>{let o=n.sourceAccessor||"source",a=n.targetAccessor||"target",s=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",c=n.startTimeAccessor||"startTime",u=n.endTimeAccessor||"endTime",d=n.systemInTimeAccessor,h=n.systemOutTimeAccessor,p=n.xExtentAccessor||"xExtent",f=n.groupBy,g=n.edgeIdAccessor||"id",m=(e,t)=>"function"==typeof e?e(t):t[e],y=Array.isArray(n.edges)?n.edges:[],x=Array.isArray(n.nodes)?n.nodes:[],b=x.length>0?x:ev([],y,o,a),v=[vk(n.domain?.[0]),vk(n.domain?.[1])],w=b.map(e=>{let t=String(m(l,e)),i=m(p,e),r=n.nodeLabel?m(n.nodeLabel,e):t,o={id:t,label:null==r?t:String(r),__raw:e},a=f?m(f,e):null;if(null!=a&&""!==String(a)&&(o.group=String(a)),Array.isArray(i)&&2===i.length){let e=vk(i[0]),t=vk(i[1]);Number.isFinite(e)&&Number.isFinite(t)&&(o.xExtent=[e,t])}return o}),k=y.map((e,t)=>{let i=m(g,e),r={id:null!=i?String(i):`${m(o,e)}-${m(a,e)}-${t}`,source:String(m(o,e)),target:String(m(a,e)),value:Number(m(s,e)),startTime:vk(m(c,e)),endTime:vk(m(u,e)),__raw:e};if(d){let t=vk(m(d,e));Number.isFinite(t)&&(r.systemInTime=t)}if(h){let t=vk(m(h,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),[S,A]=r.size??[600,400],M=r.margin,$="vertical"===n.orientation?"vertical":"horizontal",_=!Array.isArray(n.axisTicks)||n.axisTicks.length>0,P={...Tk(!!r.title,!!n.showQualityReadout,_,$),...M},I=(r.showLegend??!!t)&&!!t,T=r.legendPosition??"right";if(I){let e="left"===T||"top"===T||"bottom"===T?T:"right",t={...P};"right"===e?P.right=Math.max(P.right,140):"left"===e?P.left=Math.max(P.left,140):"top"===e?P.top=Math.max(P.top,50):P.bottom=Math.max(P.bottom,80),be(P,t,[S,A],e)}let L=P,C=Math.max(1,S-L.left-L.right),R=Math.max(1,A-L.top-L.bottom),N=Zt(i,$i(r.theme).colors.categorical,Tt),D="function"==typeof t?t:null,F=D?b.map(e=>({_cat:D(e)})):b,E=D?"_cat":"string"==typeof t?t:void 0,O=i??[...N],z=E?ii(F,E,O):null,B=new Map;for(let e of w)B.set(e.id,e.__raw);let j=(e,i)=>{if(t&&B.has(e)){let i=B.get(e);return D?ei({_cat:D(i)},"_cat",z??void 0):ei(i,"string"==typeof t?t:"id",z??void 0)}return N[i%N.length]},Y=pe(I&&t?(()=>{let e=new Map;b.forEach((i,r)=>{let n=m(t,i),o=null==n?"":String(n);!o||e.has(o)||e.set(o,{label:o,color:j(String(m(l,i)),r)})});let i=Array.from(e.values());return i.length>0?{legendGroups:[{type:"fill",label:"",items:i,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,r.legend),q=!1!==n.showLabels&&("auto"!==n.showLabels||"auto"),{layout:X,layoutConfig:G,issues:V,xScale:H}=Ik({nodes:w,edges:k,domain:v,plotW:C,plotH:R,orientation:$,ribbonLane:n.ribbonLane||"both",ribbonMinRun:"auto"===n.ribbonMinRun||"number"==typeof n.ribbonMinRun?n.ribbonMinRun:0,edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:j,showLabels:q,styleRules:n.styleRules,colorBy:t,valueAccessor:s,layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half",maxValueScale:"number"==typeof n.maxValueScale?n.maxValueScale:void 0,lanePlacement:n.lanePlacement||"stack",nodeSizing:n.nodeSizing||"temporal",groupPadding:"number"==typeof n.groupPadding?n.groupPadding:0}});if(V.length>0){let e=V.map(uw).join("; ");throw new Error(`ProcessSankey: data invalid — ${e}`)}let U=X?function(e){let t=e.layout,i=e.nodes,r=e.orientation,n=e.plotW,o=e.plotH,a=e.timelineExtent,s=e.showQualityReadout??!1,l=e.showLaneRails??!1,c=(e.warnings??[]).slice(0,3),u=e.timeFormat,d=e.colorOf,h=e.toTime,p=e.xScale,f=function(e){return W(e)}(e.domain),{centerlines:g,laneLifetime:m,nodeData:y,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=t,A=null,M=null,$=1/0,_=-1/0;for(let e of i){let t=m[e.id];if(!t||null===t.start||null===t.end)continue;let i=p(t.start),r=p(t.end);$=Math.min($,t.start),_=Math.max(_,t.end),(null===A||i<A)&&(A=i),(null===M||r>M)&&(M=r)}let P=e=>Math.max(0,Math.min(a,e)),I=P(A??0),T=Math.max(I,P(M??a)),L=[Math.max(h(e.domain[0]),$),Math.min(h(e.domain[1]),_)],C=Math.max(2,Math.min(8,Math.floor(a/90))),R=Ck().domain(L),N=e.axisTicks??(Number.isFinite(L[0])&&Number.isFinite(L[1])?(f?R.ticks(C):Lk().domain(L).ticks(C)).map(e=>({date:e})):[]),D=e=>{if(null!=e.label)return e.label;let t=h(e.date),i=f?new Date(t):t;return u?u(i):f?R.tickFormat()(i):String(t)},F=N.map((e,t)=>({tick:e,index:t,coordinate:p(h(e.date))})).filter(({coordinate:e})=>e>=I-.5&&e<=T+.5),E=null!==(w??null)&&null!=k&&null!=S,O=s&&(E||c.length>0)?Dk("g",{fill:Ok,fontSize:10,textAnchor:"end",children:[E&&Dk(Rk,{children:[Dk("text",{x:n,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),Dk("text",{x:n,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),c.map((e,t)=>Dk("text",{x:n,y:E?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},`warn-${t}`))]}):null,z=s&&b?Nk("text",{x:n,y:"vertical"===r?-3:2,fontSize:10,fill:Ok,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,B=(e,t)=>d?d(e,t):Fk;return Dk("g","vertical"===r?{children:[O,z,F.map(({index:e,coordinate:t})=>Nk("line",{x1:0,y1:t,x2:n,y2:t,stroke:Fk,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=p(i.start),l=p(i.end),c=B(e.id,t);return Dk("g",{children:[Nk("line",{x1:a,y1:s,x2:a,y2:l,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Nk("line",{x1:a-4,y1:s,x2:a+4,y2:s,stroke:c,strokeOpacity:.5}),Nk("line",{x1:a-4,y1:l,x2:a+4,y2:l,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),Nk("line",{x1:-4,y1:I,x2:-4,y2:T,stroke:Fk}),F.map(({tick:e,index:t,coordinate:i})=>{let r=D(e);return Dk("g",{transform:`translate(-4,${i})`,children:[Nk("line",{x2:-6,stroke:Fk}),Nk("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Ek,children:r})]},t)})]}:{children:[O,z,F.map(({index:e,coordinate:t})=>Nk("line",{x1:t,y1:0,x2:t,y2:o,stroke:Fk,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=p(i.start),l=p(i.end),c=B(e.id,t);return Dk("g",{children:[Nk("line",{x1:s,y1:a,x2:l,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),Nk("line",{x1:s,y1:a-4,x2:s,y2:a+4,stroke:c,strokeOpacity:.5}),Nk("line",{x1:l,y1:a-4,x2:l,y2:a+4,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),Nk("line",{x1:I,y1:o+4,x2:T,y2:o+4,stroke:Fk}),F.map(({tick:e,index:t,coordinate:i})=>{let r=D(e);return Dk("g",{transform:`translate(${i},${o+4})`,children:[Nk("line",{y2:6,stroke:Fk}),Nk("text",{y:20,textAnchor:"middle",fontSize:11,fill:Ek,children:r})]},t)})]})}({layout:X,nodes:w,orientation:$,plotW:C,plotH:R,timelineExtent:"vertical"===$?R:C,domain:n.domain,axisTicks:Array.isArray(n.axisTicks)?n.axisTicks.map(e=>({date:e.date,label:e.label})):void 0,showQualityReadout:!!n.showQualityReadout,showLaneRails:!!n.showLaneRails,timeFormat:"function"==typeof n.timeFormat?e=>n.timeFormat(e):void 0,colorOf:j,toTime:e=>vk(e),xScale:e=>Number(H(e))}):void 0;return{chartType:"force",nodes:b,edges:y,customNetworkLayout:Bk,layoutConfig:G,sourceAccessor:o,targetAccessor:a,valueAccessor:s,nodeIDAccessor:l,colorBy:t,colorScheme:i,...U&&{backgroundGraphics:U},...r,showLegend:I,...Y&&{legend:Y,legendPosition:T},__legendIncludesAutomatic:!0,margin:L}}},ChordDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.styleRules)&&n.styleRules.length>0;if(!(t||o||r.nodeStyle||n.nodeStyle||oi(bi(n))))return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t};let a=Array.isArray(n.edges)?n.edges:[],s=Array.isArray(n.nodes)&&n.nodes.length>0?n.nodes:ev([],a,n.sourceAccessor||"source",n.targetAccessor||"target"),l=$i(r.theme).colors.categorical,c=Zt(i,l),u="string"==typeof t?t:"__ssrChordColorBy",d="function"==typeof t?s.map(e=>({...e,__ssrChordColorBy:t(e)})):s,h=t?ii(d,u,i??r.colorScheme??l):void 0,p=new Map,f=n.nodeIdAccessor||n.nodeIDAccessor||"id",g=(e,i)=>{let r,o=e?.data||e;if(t)r=ei(o,t,h);else{let t=String(e.id??o?.[f]??"");p.has(t)||p.set(t,p.size);let n=e.index??i??p.get(t);r=c[n%c.length]}return{fill:r,stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},m=se(n.styleRules,t,n.valueAccessor),y=m?(e,t)=>({...g(e,t),...m(e,t)}):g;return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,nodeStyle:ai(n.nodeStyle||y,bi(n)),...r,showLegend:(r.showLegend??!!t)&&!!t}}},TreeDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Wk(e,t,i,r,n),a=!1!==n.showLabels;return{chartType:n.layout??"tree",orientation:n.orientation,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...jk(e,t,i,r,n),nodeStyle:Yk(e=>({fill:o(e),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),t,r,n)}}},Treemap:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Wk(e,t,i,r,n),a=n.showLabels??r.showLabels,s=n.labelMode,l=void 0!==n.paddingTop?n.paddingTop:r.paddingTop,c=void 0!==l?l:!a||"parent"!==s&&"all"!==s?void 0:18;return{chartType:"treemap",labelMode:s,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...null!=c&&{paddingTop:c},...jk(e,t,i,r,n),nodeStyle:Yk(e=>({fill:o(e),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}),t,r,n)}}},CirclePack:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Wk(e,t,i,r,n);return{chartType:"circlepack",nodeLabel:n.showLabels??r.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...jk(e,t,i,r,n),nodeStyle:Yk(e=>({fill:o(e),fillOpacity:n.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}),t,r,n)}}},OrbitDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=e??n.data,a=n.childrenAccessor||"children",s=n.nodeIdAccessor||n.nodeIDAccessor||"name",l=$i(r.theme).colors.categorical,c=i??r.colorScheme??l,u=Zt(c,l),d=Jb(o,a),h="__ssrOrbitColorBy",p="function"==typeof t?t:null,f=t?ii(p?d.map(e=>({[h]:p(e)})):d,p?h:t,c):void 0,g=ae(e=>{let i=e.data||e,r=Number(e.depth??0);return{fill:n.colorByDepth?0===r?u[0]:Qt[r%Qt.length]:t?p?ei({[h]:p(i)},h,f):ei(i,t,f):u[0],stroke:"#fff",strokeWidth:1,opacity:0===r?1:.85}},n.styleRules,ne(t,"value"),e=>e?.data||e);return{chartType:"orbit",data:o,childrenAccessor:a,nodeIDAccessor:s,colorBy:t,colorScheme:c,colorByDepth:n.colorByDepth??!1,nodeSize:n.nodeRadius??6,nodeLabel:n.showLabels?s:void 0,showLabels:n.showLabels??!1,orbitMode:n.orbitMode??"flat",orbitSize:n.orbitSize??2.95,orbitSpeed:n.speed??.25,orbitRevolution:n.revolution,orbitRevolutionStyle:n.revolutionStyle,orbitEccentricity:n.eccentricity??1,orbitShowRings:n.showRings??!0,orbitAnimated:!1,nodeStyle:ai(g,bi(n)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}}}},Xk={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};function Gk(e,t,i){let[r,n]=i;if(!t)return r;let[o,a]=t,s=a>o?a-o:0,l=Number(e),c=Number.isFinite(l)?l:o,u=s>0?(c-o)/s:0;return r+Math.max(0,Math.min(1,u))*(n-r)}function Vk(e){let{valueAccessor:t,valueDomain:i,edgeWidthRange:r,resolveStroke:n,edgeOpacity:o,edgeLinecap:a,styleRules:s}=e,l=ie(t);return ae(e=>({stroke:n(e),strokeWidth:Gk(e[t],i,r),strokeLinecap:a,opacity:o,fillOpacity:0}),s,e=>({value:l(e)}))}import{scaleSequential as Hk}from"d3-scale";function Uk(e,t,i,r){let n,o,a=Array.isArray(e)?e:[];if(t){let e="string"==typeof t?t:"__geoColorBy",r="string"==typeof t?a:a.map(e=>({...e,__geoColorBy:t(e)}));n=ii(r,e,i)}if(r.sizeBy){let e="function"==typeof r.sizeBy?r.sizeBy:e=>e?.[r.sizeBy],t=a.map(e).filter(e=>null!=e&&isFinite(e));t.length>0&&(o=le(t))}return e=>({fill:t&&n?ei(e,t,n):Ut,fillOpacity:r.fillOpacity,stroke:"#fff",strokeWidth:r.strokeWidth,r:r.sizeBy?ri(e,r.sizeBy,r.sizeRange,o):r.pointRadius??6})}function Zk(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}var Kk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="string"==typeof i?i:"blues",a=function(e,t,i){if(!Array.isArray(e))return;let r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0,n=1/0,o=-1/0;for(let t of e){let e=r(t);null==e||!isFinite(e)||(e<n&&(n=e),e>o&&(o=e))}let a=[Number.isFinite(n)?n:0,Number.isFinite(o)?o:1],s=Hk(zt(i)).domain(a);return{domain:a,colorScale:e=>s(e),valueAccessor:r}}(n.areas,n.valueAccessor,o),s=n.areaStyle??function(e,t){if(e)return i=>{let r=e.valueAccessor(i);return{fill:null!=r&&isFinite(r)?e.colorScale(r):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:t}}}(a,n.areaOpacity??1),l=e=>"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0,c=n.styleRules?ae(s,n.styleRules,e=>({value:l(e)}),Zk):s,u=!1!==r.showLegend&&a?{gradient:{colorFn:a.colorScale,domain:a.domain,label:"string"==typeof n.valueAccessor?n.valueAccessor:"value"}}:void 0;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:c,valueAccessor:n.valueAccessor,colorScheme:o,graticule:n.graticule,fitPadding:n.fitPadding,...r,...void 0===r.legend&&u?{legend:u}:{}}}},Qk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=n.pointStyle??Uk(o,t,i,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),s=n.styleRules?ae(a,n.styleRules,ne(t,n.sizeBy)):a;return{points:o,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle||Xk,pointStyle:s,sizeBy:n.sizeBy,colorBy:t,colorScheme:i,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...r}}},Jk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=r.__resolvedMode??n.mode,s="sparkline"===a,l=n.pointStyle??Uk(o,t,i,{pointRadius:"number"==typeof n.pointRadius?n.pointRadius:s?1.5:5,fillOpacity:.85,strokeWidth:1}),c=n.nodeIdAccessor||"id",u=n.cartogramLayout||(s?"strip":"radial"),d="strip"===u,h=n.styleRules?ae(l,n.styleRules,ne(t)):l;return{points:o,lines:n.lines,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",pointStyle:e=>{let t="function"==typeof h?h(e):h,i="function"==typeof c?c(e):e[c],r=null!=i&&String(i)===String(n.center),o="number"==typeof t.r?t.r:5;return{...t,fillOpacity:r?1:t.fillOpacity??.8,stroke:r?"var(--semiotic-text, #222)":t.stroke??"#fff",strokeWidth:r?1.25:t.strokeWidth??1,r:r?1.35*o:o}},colorBy:t,colorScheme:i,projection:n.projection||"mercator",graticule:n.graticule,fitPadding:n.fitPadding,projectionTransform:{center:n.center,centerAccessor:c,costAccessor:n.costAccessor,strength:n.strength??1,lineMode:n.lineMode||"straight",layout:u},...r,cartogramChrome:{showRings:n.showRings??!0,showNorth:n.showNorth??(!d&&!s),showRingLabels:n.showRingLabels??(!d&&"context"!==a&&!s),costLabel:n.costLabel}}}},eS={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=(Array.isArray(e)?e:null)||n.flows||[],a=n.nodes||[],s=n.nodeIdAccessor||"id",l=n.valueAccessor||"value",c=n.xAccessor||"lon",u=n.yAccessor||"lat",d="function"==typeof c?c:e=>e[c],h="function"==typeof u?u:e=>e[u],p=a.map(e=>({...e,x:d(e),y:h(e)})),f=new Map;for(let e of p)f.set(String(e[s]),e);let g=n.edgeColorBy??t,m="function"==typeof g,y=o.map(e=>{if(!e||null==e.source||null==e.target)return null;let t=f.get(String(e.source)),i=f.get(String(e.target));return t&&i?{...e,coordinates:[{x:t.x,y:t.y},{x:i.x,y:i.y}]}:null}).filter(Boolean),x="__flowMapEdgeColor",b=g?m?ii(y.map(e=>({[x]:g(e)})),x,i||"category10"):ii(y,g,i||"category10"):null,v=y.map(e=>Number(e[l]??0)).filter(e=>Number.isFinite(e)),w=v.length>0?le(v):void 0,[k,S]=n.edgeWidthRange??[1,8],A=n.edgeOpacity??.6,M=n.edgeLinecap??"round";return{lines:y,points:p,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle||Xk,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:i,lineStyle:Vk({valueAccessor:l,valueDomain:w,edgeWidthRange:[k,S],resolveStroke:e=>g&&b?ei(e,g,b):"#007bff",edgeOpacity:A,edgeLinecap:M,styleRules:n.styleRules}),pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...r}}},tS={FlowCircuitChart:rw,GaltonBoardChart:dy,EventDropChart:hy,UnitPileChart:py,CollisionSwarmChart:fy,PacketFlowChart:xy,ProcessFlowChart:gy,GauntletChart:my,CrucibleChart:yy,ChainReactionChart:ju},iS=/*#__PURE__*/Object.assign({Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,i,r,n)=>({chartType:"line",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||t,colorAccessor:t,...r,showAxes:!1,margin:r.margin,showLegend:!1,showGrid:!1,title:void 0})},XYCustomChart:ih,OrdinalCustomChart:rh,ParallelCoordinatesRecipe:oh,CalendarHeatmapRecipe:ah,NetworkCustomChart:nh,ChoroplethMap:Kk,ProportionalSymbolMap:Qk,FlowMap:eS,DistanceCartogram:Jk,GeoCustomChart:{frameType:"geo",buildProps:(e,t,i,r,n)=>({points:n.points||e||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r})},PhysicsCustomChart:by},
2
- /*#__PURE__*/Object.assign({},Wu,md,Wd),
3
- /*#__PURE__*/Object.assign({},qk,tS));import*as rS from"react";import{jsx as nS}from"react/jsx-runtime";var oS=/*#__PURE__*/new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function aS(e){if(Array.isArray(e))return e.length>0&&e.every(aS);if(!rS.isValidElement(e))return!1;if(e.type===rS.Fragment){let t=rS.Children.toArray(e.props.children);return t.length>0&&t.every(aS)}return"string"==typeof e.type&&oS.has(e.type)}import*as sS from"react-dom/server";import{scaleBand as lS,scaleLinear as cS}from"d3-scale";var uS=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,i){if(t&&"function"==typeof e.pieceStyle){let r=e.pieceStyle(t,i);return r&&!r.fill&&i?{...r,fill:this.getColorFromScheme(e,i)}:r}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&i?{fill:ti(e.barColors,i)??"#007bff"}:{fill:i?this.getColorFromScheme(e,i):"#007bff"}}resolveSummaryStyle(e,t,i){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,i):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){let i=this.colorSchemeMap.get(t);if(i)return i;let r=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||Kt,n=r[this.colorSchemeIndex%r.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,n),n}};function dS(e,t,i){let{scales:r,config:n,getConnector:o,getO:a}=e;if(!o||!r)return[];let s=[],{projection:l}=r,c=new Map;for(let e of t){if("point"!==e.type&&"rect"!==e.type)continue;let t=e.datum;if(!t)continue;let i,r,n=o(t);n&&("point"===e.type?(i=e.x,r=e.y):(i=e.x+e.w/2,r=e.y+("vertical"===l?0:e.h/2)),c.has(n)||c.set(n,[]),c.get(n).push({x:i,y:r,datum:t,category:a(t)}))}let u=new Map(r.o.domain().map((e,t)=>[e,t])),d=n.connectorStyle,h={stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5},p=e=>"function"==typeof d?d(e):d||h,f=(e,t,i)=>{s.push({type:"connector",x1:e.x,y1:e.y,x2:t.x,y2:t.y,style:p(e.datum),datum:e.datum,group:i})};for(let[e,t]of c)if(!(t.length<2)){t.sort((e,t)=>(u.get(e.category)??-1)-(u.get(t.category)??-1));for(let i=0;i<t.length-1;i++)f(t[i],t[i+1],e);"radial"===l&&t.length>=3&&f(t[t.length-1],t[0],e)}return s}function hS(e,t,i,r=!1){let n=new Map;for(let r of e){let e=t(r);if(!Number.isFinite(e))continue;let o=i?i(r):"_default",a=n.get(o);a||(a={total:0,value:0,pieces:[]},n.set(o,a)),a.total+=e,a.pieces.push(r)}let o=0;for(let e of n.values())o+=Math.abs(e.total);for(let e of n.values())e.value=r&&o>0?e.total/o:e.total;return n}function pS(e,t,i,r=!1){let n=new Set;return{steps:e.map(e=>{let o=hS(e.pieceData,t,i,r),a=0;for(let[e,t]of o)n.add(e),a+=t.total;return{col:e,groups:o,stepTotal:a}}),keys:[...n]}}function fS(e,t,i){let r="function"==typeof e?e(i?t.w:t.h):e;return"number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0}function gS(e){let t=e.getSymbol;return t?u(t,e.config.symbolMap):null}function mS(e,t,i,r,n,o,a){t?e.push({type:"symbol",x:r,y:n,size:Math.PI*o*o,symbolType:t(i),style:a,datum:i}):e.push({type:"point",x:r,y:n,r:o,style:a,datum:i})}function yS(e,t){let{scales:i,columns:r,config:n,resolvePieceStyle:o,getR:a}=e,s=[],l=Math.min(t.width,t.height)/2-4,c="donut"===n.chartType?n.innerRadius||60:0,u=-Math.PI/2+(n.startAngle||0)*Math.PI/180,d=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,h=null!=n.sweepAngle&&n.sweepAngle<360,p=Object.values(r),f=p.some(e=>{let t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),g=p.length,m=h&&!f&&g>1&&(n.cornerRadius??0)>0;for(let e=0;e<p.length;e++){let t=p[e],i=t.pieceData[0],r="number"==typeof i?._pctStart?i._pctStart:t.pctStart,h="number"==typeof i?._pct?i._pct:t.pct,f=u+r*d,g=u+(r+h)*d,y=o(t.pieceData[0],t.name),x=0===e,b=e===p.length-1,v={type:"wedge",cx:0,cy:0,innerRadius:c,outerRadius:l,startAngle:f,endAngle:g,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:i?._nonInteractive?null:t.pieceData,accessibleDatum:{...1===t.pieceData.length?t.pieceData[0]:{},category:t.name,value:t.pieceData.reduce((e,t)=>e+a(t),0),percent:100*h,count:t.pieceData.length,...t.pieceData[0]?.__gaugeAccessibleDatum},category:t.name};i?._roundedEnds?v.roundedEnds=i._roundedEnds:m&&(v.roundedEnds={start:x,end:b}),i?._gradientBand&&(v._gradientBand=i._gradientBand),s.push(v)}return s}import{quantileSorted as xS}from"d3-array";function bS(e,t,i){return{...e[0],...i,category:t,data:e}}function vS(e){let t=e.length,i=e[0],r=e[t-1];return{n:t,min:i,q1:xS(e,.25)??i,median:xS(e,.5)??(i+r)/2,q3:xS(e,.75)??r,max:r,mean:e.reduce((e,t)=>e+t,0)/t}}function wS(e,t,i,r,n){let o=new Array(n).fill(0);for(let a of e)a<t||a>i||o[Math.min(Math.floor((a-t)/r),n-1)]++;return o}import{scaleLinear as kS}from"d3-scale";var SS={bar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getStack:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,h="horizontal"===c,p=n.normalize,{steps:f,keys:g}=pS(Object.values(r),o,a,p);for(let{col:e,groups:t}of f){let i=0,r=0;for(let n of g){let o=t.get(n);if(!o)continue;let c=o.value,p=s(o.pieces[0],a?n:e.name),f={...o.pieces[0],__aggregateValue:o.total,__pieceCount:o.pieces.length,category:e.name};if(d){let t=l(c>=0?i+c:r),o=c>=0?l(i)-l(i+c):l(r+c)-l(r);u.push(Vn(e.x,t,e.width,Math.abs(o),p,f,n)),c>=0?i+=c:r+=c}else if(h){let t=l(c>=0?i:r+c),o=c>=0?l(i+c)-l(i):l(r)-l(r+c);u.push(Vn(t,e.x,Math.abs(o),e.width,p,f,n)),c>=0?i+=c:r+=c}}}let m="vertical"===c;for(let e of u){if("rect"!==e.type)continue;let t=e.datum?.__aggregateValue??0;e.roundedEdge=m?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}if(void 0!==n.roundedTop){let e=new Map;for(let t of u){if("rect"!==t.type)continue;let i=t.datum?.category||"";e.has(i)||e.set(i,[]),e.get(i).push(t)}for(let t of e.values()){if(0===t.length)continue;let e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),i=t.filter(e=>(e.datum?.__aggregateValue??0)<0);if(e.length>0){let t=m?e.reduce((e,t)=>e.y<t.y?e:t):e.reduce((e,t)=>e.x+e.w>t.x+t.w?e:t),i=fS(n.roundedTop,t,m);i>0&&(t.roundedTop=i)}if(i.length>0){let e=m?i.reduce((e,t)=>e.y+e.h>t.y+t.h?e:t):i.reduce((e,t)=>e.x<t.x?e:t),t=fS(n.roundedTop,e,m);t>0&&(e.roundedTop=t)}}}return u},clusterbar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getGroup:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,{steps:h,keys:p}=pS(Object.values(r),o,a),f=p.length||1;for(let{col:e,groups:t}of h){let i=e.width/f,r=.2*i,n=i-r;for(let a=0;a<p.length;a++){let c=t.get(p[a])?.pieces||[];for(let t of c){let c=o(t),h=s(t,p[a]);if(d){let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(Vn(o,Math.min(s,d),n,Math.abs(s-d),h,t,p[a]))}else{let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(Vn(Math.min(s,d),o,Math.abs(d-s),n,h,t,p[a]))}}}}for(let e of u){if("rect"!==e.type||null==e.datum)continue;let t=o(e.datum),i=fS(n.roundedTop,e,d);i>0&&(e.roundedTop=i),e.roundedEdge=d?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}return u},point:function(e,t){let{scales:i,columns:r,getR:n,multiScales:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d="radial"===l,h=o.length>0,p=gS(e),f=2*Math.PI,g=-Math.PI/2;for(let e of Object.values(r))for(let t of e.pieceData){let i,r,l=t.__rIndex??0,m=t.__rValue??n(t),y=h&&o[l]||s,x=a(t,e.name),b=x.r||5;if(d){let t=g+(e.pctStart+e.pct/2)*f,n=y(m);i=Math.cos(t)*n,r=Math.sin(t)*n}else u?(i=e.middle,r=y(m)):(i=y(m),r=e.middle);mS(c,p,t,i,r,b,x)}return c},swarm:function(e,t){let{scales:i,columns:r,getR:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="vertical"===s,u=gS(e);for(let e of Object.values(r)){let t=e.width/2;for(let i=0;i<e.pieceData.length;i++){let r=e.pieceData[i],s=n(r),d=o(r,e.name),h=d.r||4,p=(7919*i%100/100-.5)*t*.8;mS(l,u,r,c?e.middle+p:a(s),c?a(s):e.middle+p,h,d)}}return l},pie:yS,donut:yS,boxplot:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=!1!==n.showOutliers;for(let t of Object.values(r)){let i=t.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===i.length)continue;let r=vS(i),{min:n,max:l,q1:h,median:p,q3:f}=r,g=f-h,m=h-1.5*g,y=f+1.5*g,x=i.find(e=>e>=m)??n,b=l;for(let e=i.length-1;e>=0;e--)if(i[e]<=y){b=i[e];break}r.min=x,r.max=b;let v=a(bS(t.pieceData,t.name,r),t.name),w=[];if(d)for(let e of t.pieceData){let i=o(e);if(i<m||i>y){let r=u?t.middle:s(i),n=u?s(i):t.middle;w.push({px:r,py:n,value:i,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:s(x),q1Pos:s(h),medianPos:s(p),q3Pos:s(f),maxPos:s(b),stats:r,style:v,datum:t.pieceData,category:t.name,outliers:w}),d)for(let t of w)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:v.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:v.cursor},datum:t.datum})}return c},violin:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=n.bins||20,h=!1!==n.showIQR;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/d||1,p=wS(t,r,n,l,d),f=ue(p,1),g=e.width/2*.9;if(u){i=`M ${e.middle} ${s(r)}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${e.middle+o} ${n}`}i+=` L ${e.middle} ${s(n)}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${e.middle-o} ${n}`}i+=" Z"}else{i=`M ${s(r)} ${e.middle}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${n} ${e.middle-o}`}i+=` L ${s(n)} ${e.middle}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${n} ${e.middle+o}`}i+=" Z"}let m,y=vS(t),x=a(bS(e.pieceData,e.name,y),e.name);h&&t.length>=4&&(m={q1Pos:s(y.q1),medianPos:s(y.median),q3Pos:s(y.q3),centerPos:e.middle,isVertical:u});let b=u?{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))}:{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:y,style:x,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s}=i,l=[],c=n.bins||25,u=n.normalize,d=s.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;let[i,r]=le(t),n=null!=h&&isFinite(h)?h:i,d=null!=p&&isFinite(p)?p:r,f=(d-n)/c||1,g=wS(t,n,d,f,c),m=t.length,y=ue(g,1);for(let t=0;t<c;t++){if(0===g[t])continue;let i=(u?g[t]/m:g[t]/y)*e.width*.9,r=s(n+t*f),o=s(n+(t+1)*f),c=Math.min(r,o),d=Math.abs(o-r),h=e.x+e.width-i,p={...e.pieceData[0],bin:t,count:g[t],range:[n+t*f,n+(t+1)*f],category:e.name,data:e.pieceData},x=a(p,e.name);l.push(Vn(c,h,d,i,x,p,e.name))}}return l},ridgeline:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u=n.bins||20,d="horizontal"===l,h=n.amplitude||1.5;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/u||1,p=wS(t,r,n,l,u),f=ue(p,1),g=vS(t),m=a(bS(e.pieceData,e.name,g),e.name),y=e.width*h;if(d){let t=e.x+e.width;i=`M ${s(r)} ${t}`;for(let e=0;e<u;e++)i+=` L ${s(r+(e+.5)*l)} ${t-p[e]/f*y}`;i+=` L ${s(n)} ${t} Z`}else{let t=e.x;i=`M ${t} ${s(r)}`;for(let e=0;e<u;e++){let n=s(r+(e+.5)*l);i+=` L ${t+p[e]/f*y} ${n}`}i+=` L ${t} ${s(n)} Z`}let x=d?{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width}:{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:x,stats:g,style:{...m,fillOpacity:m.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){let{scales:i,columns:r,getRawRange:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="horizontal"===s;for(let e of Object.values(r))for(let t of e.pieceData){let i=n(t);if(!i)continue;let[r,s]=i,u=o(t,e.name);if(c){let i=a(Math.min(r,s)),n=a(Math.max(r,s));l.push(Vn(i,e.x,n-i,e.width,u,t,e.name))}else{let i=a(Math.max(r,s)),n=a(Math.min(r,s));l.push(Vn(e.x,i,e.width,n-i,u,t,e.name))}}return l},funnel:function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o}=e,a=[],s=t.width/2,l=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>i[e]).filter(Boolean);if(0===c.length)return a;let{steps:u,keys:d}=pS(c,r,n),h=d.length>1&&"_default"!==d[0],p=0;if(!h)for(let{stepTotal:e}of u)e>p&&(p=e);if(h)for(let e of u){let t=0,i=0;for(let r=0;r<d.length;r++){let n=e.groups.get(d[r]);n&&(r%2==0?t+=n.total:i+=n.total)}let r=Math.max(t,i);r>p&&(p=r)}if(0===p)return a;let f=u[0].stepTotal,g=h?.95*s:.9*t.width,m=kS().domain([0,p]).range([0,g]),y=e.config.connectorOpacity??.3,x=new Map;for(let t=0;t<u.length;t++){let i=u[t],r=i.col,n=0===t,c=r.x,p=r.width,g=.55*p,b=c+(p-g)/2,v=new Map;if(h){let e=0;for(let t of d){let r=i.groups.get(t);r&&(e+=m(r.total))}let t=s,c=s;for(let h=0;h<d.length;h++){let p=d[h],f=i.groups.get(p);if(!f)continue;let y=m(f.total),x=h%2==0,w=x?t:c-y;x?t+=y:c-=y;let k=o(f.pieces[0],p),S=u[0].groups.get(p)?.total??0,A=S>0?f.total/S*100:0,M={...f.pieces[0],__funnelValue:f.total,__funnelPercent:A,__funnelStep:r.name,__funnelIsFirstStep:n,__aggregateValue:f.total,__pieceCount:f.pieces.length,category:p};l&&(0===h&&(M.__funnelStepLabel=r.name,M.__funnelStepLabelX=s,M.__funnelStepLabelY=b,M.__funnelRowWidth=e),M.__funnelValueLabelX=w+y/2,M.__funnelValueLabelY=b,M.__funnelBarW=y),a.push(Vn(w,b,y,g,k,M,p)),v.set(p,{x:w,y:b,w:y,h:g})}}else{let e=i.stepTotal,t=m(e),c=s-t/2,u=d[0],h="_default"!==u,p=i.groups.get(u)?.pieces[0]??r.pieceData[0],y=h?u:r.name,x=o(p,y),w=f>0?e/f*100:0,k={...p,__funnelValue:e,__funnelPercent:w,__funnelStep:r.name,__funnelIsFirstStep:n,category:h?u:r.name};l&&(k.__funnelStepLabel=r.name,k.__funnelStepLabelX=s,k.__funnelStepLabelY=b,k.__funnelRowWidth=t,k.__funnelValueLabelX=s,k.__funnelValueLabelY=b,k.__funnelBarW=t),a.push(Vn(c,b,t,g,x,k,y)),v.set(u,{x:c,y:b,w:t,h:g})}if(t>0&&x.size>0){let t=h?d:[d[0]];for(let n of t){let t=x.get(n),s=v.get(n);if(!t||!s)continue;let l=(()=>{let e=i.groups.get(n),t="_default"===n?r.name:n;return o(e?e.pieces[0]:r.pieceData[0],t)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[s.x+s.w,s.y],[s.x,s.y]],style:{fill:l.fill||e.config.themeSemantic?.secondary||"#999",opacity:y,cursor:l.cursor},datum:i.groups.get(n)?.pieces[0]??r.pieceData[0],category:"_default"===n?r.name:n};a.push(c)}}x=v}return a},"bar-funnel":function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o,scales:a}=e,s=[],l=a.o.domain().map(e=>i[e]).filter(Boolean);if(0===l.length)return s;let{steps:c,keys:u}=pS(l,r,n),d=u.length>1&&"_default"!==u[0],h=a.r,p=d?u.length:1,f=d?.15:0;for(let e=0;e<c.length;e++){let t=c[e],i=t.col,r=0===e,n=e>0?c[e-1]:null,a=i.width/p,l=a*f,g=a-l;for(let e=0;e<u.length;e++){let p=u[e],f=t.groups.get(p);if(!f)continue;let m=f.total,y=c[0].groups.get(p)?.total??0,x=y>0?m/y*100:0,b=n?.groups.get(p)?.total??m,v=r?0:Math.max(0,b-m),w=i.x+e*a+l/2,k=h(m),S=h(0),A=S-k,M=o(f.pieces[0],d?p:i.name),$={...f.pieces[0],__barFunnelValue:m,__barFunnelPercent:x,__barFunnelIsFirstStep:r,__barFunnelIsDropoff:!1,__barFunnelStep:i.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===p?void 0:p,category:d?p:i.name,__barFunnelLabelX:w+g/2,__barFunnelLabelY:h(m+v)};if(s.push(Vn(w,Math.min(k,S),g,Math.abs(A),M,$,d?p:i.name)),v>0){let e=h(m+v),t=k-e,r={...M},n={...f.pieces[0],__barFunnelValue:v,__barFunnelPercent:y>0?v/y*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:i.name,__barFunnelCategory:"_default"===p?void 0:p,category:d?p:i.name};s.push(Vn(w,e,g,t,r,n,d?p:i.name))}}}return s},swimlane:function(e,t){let{scales:i,columns:r,getR:n,getStack:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="horizontal"===l,d=e.config.gradientFill,h=u?"left":"bottom",p=new Map,f=t=>{let i=p.get(t);if(void 0!==i)return i;let r="function"==typeof e.config.roundedTop?e.config.roundedTop(t.width):e.config.roundedTop,n="number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0;return p.set(t,n),n},g=e.config.trackFill;if(g){let e="string"==typeof g?g:g.color,t="string"==typeof g?1:g.opacity??1,[i,n]=s.range(),o=Math.min(i,n),a=Math.abs(n-i);for(let i of Object.values(r)){let r={fill:e,opacity:t},n=u?Vn(o,i.x,a,i.width,r,null,"__track__"):Vn(i.x,o,i.width,a,r,null,"__track__"),s=f(i);s>0&&(n.cornerRadii={tl:s,tr:s,br:s,bl:s}),c.push(n)}}for(let e of Object.values(r)){let t=0,i=c.length,r=f(e);for(let i of e.pieceData){let r=Math.abs(n(i));if(0===r)continue;let l,p=o?o(i):e.name,f=a(i,p);if(u){let n=s(t),o=s(t+r);l=Vn(n,e.x,o-n,e.width,f,i,p)}else{let n=s(t+r),o=s(t);l=Vn(e.x,n,e.width,o-n,f,i,p)}d&&(l.fillGradient=d,l.roundedEdge=h),c.push(l),t+=r}if(r>0&&c.length>i){let e=c.slice(i),t=e[0],n=e[e.length-1];1===e.length?t.cornerRadii={tl:r,tr:r,br:r,bl:r}:u?(t.cornerRadii={tl:r,bl:r},n.cornerRadii={tr:r,br:r}):(t.cornerRadii={bl:r,br:r},n.cornerRadii={tl:r,tr:r})}}return c}},AS=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],MS=["scene-style","data-paint","accessibility","evidence"],$S=(e,t)=>({retainedData:e,invalidations:t}),_S=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],PS=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],IS=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],TS=["scene-geometry","data-paint","accessibility","evidence"],LS=["scene-style","data-paint","accessibility","evidence"],CS=[],RS={chartType:/*#__PURE__*/$S("rebuild",_S),runtimeMode:/*#__PURE__*/$S("rebuild",_S),categoryAccessor:/*#__PURE__*/$S("rebuild",_S),valueAccessor:/*#__PURE__*/$S("rebuild",_S),oAccessor:/*#__PURE__*/$S("rebuild",_S),rAccessor:/*#__PURE__*/$S("rebuild",_S),stackBy:/*#__PURE__*/$S("rebuild",_S),groupBy:/*#__PURE__*/$S("rebuild",_S),timeAccessor:/*#__PURE__*/$S("rebuild",_S),accessorRevision:/*#__PURE__*/$S("rebuild",_S),colorAccessor:/*#__PURE__*/$S("rebuild",LS),symbolAccessor:/*#__PURE__*/$S("rebuild",TS),connectorAccessor:/*#__PURE__*/$S("rebuild",TS),dataIdAccessor:/*#__PURE__*/$S("rebuild",TS),projection:/*#__PURE__*/$S("preserve",PS),extentPadding:/*#__PURE__*/$S("preserve",PS),axisExtent:/*#__PURE__*/$S("preserve",PS),rExtent:/*#__PURE__*/$S("preserve",PS),oExtent:/*#__PURE__*/$S("preserve",PS),multiAxis:/*#__PURE__*/$S("preserve",PS),normalize:/*#__PURE__*/$S("preserve",PS),bins:/*#__PURE__*/$S("preserve",PS),oSort:/*#__PURE__*/$S("preserve",IS),barPadding:/*#__PURE__*/$S("preserve",IS),roundedTop:/*#__PURE__*/$S("preserve",IS),baselinePadding:/*#__PURE__*/$S("preserve",IS),innerRadius:/*#__PURE__*/$S("preserve",IS),cornerRadius:/*#__PURE__*/$S("preserve",IS),startAngle:/*#__PURE__*/$S("preserve",IS),sweepAngle:/*#__PURE__*/$S("preserve",IS),trackFill:/*#__PURE__*/$S("preserve",IS),showOutliers:/*#__PURE__*/$S("preserve",IS),showIQR:/*#__PURE__*/$S("preserve",IS),amplitude:/*#__PURE__*/$S("preserve",IS),connectorOpacity:/*#__PURE__*/$S("preserve",IS),showLabels:/*#__PURE__*/$S("preserve",IS),dynamicColumnWidth:/*#__PURE__*/$S("rebuild",IS),customLayout:/*#__PURE__*/$S("preserve",IS),layoutConfig:/*#__PURE__*/$S("preserve",IS),layoutMargin:/*#__PURE__*/$S("preserve",IS),symbolMap:/*#__PURE__*/$S("preserve",TS),pieceStyle:/*#__PURE__*/$S("preserve",LS),summaryStyle:/*#__PURE__*/$S("preserve",LS),connectorStyle:/*#__PURE__*/$S("preserve",LS),gradientFill:/*#__PURE__*/$S("preserve",LS),colorScheme:/*#__PURE__*/$S("preserve",LS),themeCategorical:/*#__PURE__*/$S("preserve",LS),themeSemantic:/*#__PURE__*/$S("preserve",LS),themeSequential:/*#__PURE__*/$S("preserve",LS),themeDiverging:/*#__PURE__*/$S("preserve",LS),barColors:/*#__PURE__*/$S("preserve",LS),decay:/*#__PURE__*/$S("preserve",LS),pulse:/*#__PURE__*/$S("preserve",LS),staleness:/*#__PURE__*/$S("preserve",LS),layoutSelection:/*#__PURE__*/$S("preserve",LS),windowSize:/*#__PURE__*/$S("preserve",CS),windowMode:/*#__PURE__*/$S("preserve",CS),clock:/*#__PURE__*/$S("preserve",CS),transition:/*#__PURE__*/$S("preserve",CS),introAnimation:/*#__PURE__*/$S("preserve",CS),onLayoutError:/*#__PURE__*/$S("preserve",CS)},NS=/*#__PURE__*/$S("preserve",IS),DS=class{constructor(){this.tracker=new po}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},AS)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},MS):this.recordNoop("restyle")}recordConfig(e){let t=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(RS,r)?RS[r]:NS;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as FS}from"d3-quadtree";var ES=class extends lo{constructor(e){super(),this.rExtent=new mn,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new DS,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new uS,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new gn(e.windowSize),this.getO=V(e.categoryAccessor||e.oAccessor,"category");let t="streaming"===e.runtimeMode,i=e.valueAccessor||e.rAccessor;Array.isArray(i)?(this.rAccessors=i.map(e=>X(e,"value")),this.getR=this.rAccessors[0],this.rExtents=i.map(()=>new mn)):(t&&e.timeAccessor,this.getR=X(i,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=V(e.stackBy),this.getGroup=V(e.groupBy),this.getColor=V(e.colorAccessor),this.getSymbol=V(e.symbolAccessor),this.getConnector=V(e.connectorAccessor),this.getDataId=V(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new gn(e.windowSize))}syncPulseTimestampBuffer(){var e,t,i,r;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,i=this.timestampBuffer,r=this.currentTime(),e?null!=i&&i.capacity===t.capacity&&i.size===t.size?i:no(t,r):null)}currentTime(){return this.config.clock?.()??n()}ingest(e){let t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear();let i=e.totalSize||e.inserts.length;ro(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)oo(this.buffer,i,this.timestampBuffer,t),this.categories.add(this.getO(i)),this.pushValueExtent(i)}else{this._hasStreamingData=!0;for(let i of e.inserts){let e=oo(this.buffer,i,this.timestampBuffer,t);this.categories.add(this.getO(i)),this.pushValueExtent(i),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){let t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;let i="function"==typeof t?t(e):e[t];return Array.isArray(i)&&i.length>=2?[+i[0],+i[1]]:null}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.multiScales,o=this.columns;if(0===i.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&("timeline"===t.chartType?(this.rExtent.clear(),i.forEach(e=>this.pushValueExtent(e))):this.rExtent.recalculate(i,this.getR));let a,s,l=this.getBufferArray(),c=t.projection||"vertical",u=t.oExtent||this.resolveCategories(l),d=this.computeValueDomain(l,u),h="vertical"===c,p="horizontal"===c,f="radial"===c,g=null!=t.barPadding?t.barPadding/(h?e.width:e.height):.1,m=Math.min(.9,Math.max(0,g));if(f){a=lS().domain(u).range([0,1]).padding(0);let i=Math.min(e.width,e.height)/2,r=t.innerRadius||0;s=cS().domain(d).range([r,i])}else p?(a=lS().domain(u).range([0,e.height]).padding(m),s=cS().domain(d).range([0,e.width])):(a=lS().domain(u).range([0,e.width]).padding(m),s=cS().domain(d).range([e.height,0]));this.scales={o:a,r:s,projection:c},this.rAccessors.length>1&&t.multiAxis?this.multiScales=this.rAccessors.map((r,n)=>{let o=this.rExtents[n];o.dirty&&o.recalculate(i,r);let[a,s]=o.extent;a===1/0&&(a=0,s=1);let l=t.extentPadding??.05,c=s-a,u=c>0?c*l:1;return a-=u,s+=u,a>0&&(a=0),p?cS().domain([a,s]).range([0,e.width]):cS().domain([a,s]).range([e.height,0])}):this.multiScales=[];let y=l;this.rAccessors.length>1&&(y=l.flatMap(e=>this.rAccessors.map((t,i)=>({...e,__rIndex:i,__rValue:t(e),__rName:this.resolveRAccessorName(i)})))),this.columns=this.buildColumns(y,u,a,c,e),this._customLayoutFailedThisBuild=!1;let x=this.buildSceneNodes(y,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.multiScales=n,this.columns=o):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=x,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,l),this.config.pulse&&this.applyPulse(this.scene,l),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){let t=this.config.valueAccessor||this.config.rAccessor,i=Array.isArray(t)?t[e]:t;return"string"==typeof i?i:`value${e}`}resolveCategories(e){let t=this.config.oSort,i="streaming"===this.config.runtimeMode||this._hasStreamingData,r="auto"===t?void 0:t,n=null;if(i){n=new Set;for(let t of e)n.add(this.getO(t))}let o=n?Array.from(this.categories).filter(e=>n.has(e)):Array.from(this.categories);if(i&&void 0===r){let e=Math.max(50,3*n.size);if(this.categories.size>e){let t=this.categories.size-e;for(let e of this.categories){if(t<=0)break;n.has(e)||(this.categories.delete(e),t--)}}return o}if(!1===r)return o;if("function"==typeof r)return o.sort(r);let a=new Map;for(let t of e){let e=this.getO(t);a.set(e,(a.get(e)||0)+Math.abs(this.getR(t)))}return"asc"===r?o.sort((e,t)=>(a.get(e)||0)-(a.get(t)||0)):o.sort((e,t)=>(a.get(t)||0)-(a.get(e)||0))}computeValueDomain(e,t){return function(e){let{data:t,chartType:i,projection:r,normalize:n,rExtent:o,extentPadding:a=.05,baselinePadding:s,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=e,p=a;if("radial"===r&&("pie"===i||"donut"===i))return[0,1];let f=0,g=0;if("bar"===i||"bar-funnel"===i){let e=new Map;for(let i of t){let t=c(i);e.has(t)||e.set(t,[]),e.get(t).push(i)}for(let t of e.values()){let e=hS(t,u,d,"bar"===i&&n),r=0,o=0;for(let{value:t}of e.values())"bar-funnel"===i?(r=Math.max(r,t),o=Math.min(o,t)):t>=0?r+=t:o+=t;g=Math.max(g,r),f=Math.min(f,o)}}else if("swimlane"===i){let e=new Map;for(let i of t){let t=c(i),r=Math.abs(u(i));e.set(t,(e.get(t)||0)+r)}for(let t of e.values())t>g&&(g=t)}else if("clusterbar"===i)for(let e of t){let t=u(e);Number.isFinite(t)&&(t>g&&(g=t),t<f&&(f=t))}else{let e=h[0],t=h[1];e!==1/0&&(f=e),t!==-1/0&&(g=t)}o&&(null!=o[0]&&(f=o[0]),null!=o[1]&&(g=o[1]));let m="bar"===i||"clusterbar"===i||"bar-funnel"===i||"swimlane"===i;if(m&&(null!=o?.[0]||null!=o?.[1]||(f>0&&(f=0),g<0&&(g=0))),"bar-funnel"!==i&&"exact"!==l){let e=g-f,t=e>0?e*p:1,r=m&&!s&&0===f,n=m&&!s&&0===g||"swimlane"===i;null==o?.[0]&&!r&&(f-=t),null==o?.[1]&&!n&&(g+=t)}return[f,g]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,i,r,n){return function(e){let{data:t,oExtent:i,oScale:r,projection:n,layout:o,dynamicColumnWidth:a,getO:s,getR:l}=e,c=Object.create(null),u=new Map;for(let e of t){let t=s(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===n)for(let e of t)d+=Math.abs(l(e));let h=null;if(a&&"radial"!==n){h=new Map;let e=0;for(let t of i){let i,r=u.get(t)||[];i="string"==typeof a?r.reduce((e,t)=>{let i=Number(t[a]);return e+(Number.isFinite(i)?i:0)},0):a(r);let n=Number.isFinite(i)?Math.max(0,i):0;h.set(t,n),e=Math.max(e,n)}let t="horizontal"===n?o.height:o.width,s=r.padding()*r.step()*Math.max(0,i.length-1),l=Math.max(0,t-s);if(e>0){let t=0;for(let i of h.values())t+=i/e;for(let[i,r]of h)h.set(i,r/e/t*l)}}let p=0,f=0;for(let e of i){let t,i,n=u.get(e)||[],o=n.reduce((e,t)=>e+Math.abs(l(t)),0),a=d>0?o/d:0;h?(t=f,i=h.get(e)??r.bandwidth(),f+=i+r.padding()*r.step()):(t=r(e)??0,i=r.bandwidth()),c[e]={name:e,x:t,y:0,width:i,middle:t+i/2,padding:r.padding()*r.step(),pieceData:n,pct:a,pctStart:p},p+=a}return c}({data:e,oExtent:t,oScale:i,projection:r,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){let i=this.buildLayoutContext(e,t),r=Rn({family:"ordinal",logLabel:"ordinal customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:this.config.onLayoutError,run:()=>this.config.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let n=r.result;this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;let o=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of o)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(o,this.config.layoutSelection??null)}return Tn({label:"ordinal customLayout",nodes:o,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),o}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;let i=this.getSceneContext(),r=SS[this.config.chartType],n=r?r(i,t):[];return this.getConnector&&this.scales&&(n=[...dS(i,n),...n]),n}buildLayoutContext(e,t){let i=this.config,r=i.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Qf(i.colorScheme,i.themeCategorical,Kt),o=this.scales,a="radial"===o.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height};return{data:e,scales:{o:o.o,r:o.r,projection:o.projection},dimensions:{width:t.width,height:t.height,margin:r,plot:a},theme:{semantic:i.themeSemantic??{},categorical:[...n]},resolveColor:Jf(n,i.colorScheme),config:i.layoutConfig??{},selection:i.layoutSelection??null}}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:xn(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;let t=bn(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;let t=function(e,t){let i="function"==typeof t,r=i?null:t||"category",n=new Map;for(let o=0;o<e.length;o++){let a=e[o],s=i?t(a):a[r],l=n.get(s);l?l.push(o):n.set(s,[o])}return n}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){let e=function(e){let t=0,i=0;for(let r of e)"point"===r.type&&!1!==r.interactive&&(t++,r.r>i&&(i=r.r));if(t<=500)return{quadtree:null,maxRadius:i};let r=new Array(t),n=0;for(let t of e)"point"===t.type&&!1!==t.interactive&&(r[n++]=t);return{maxRadius:i,quadtree:FS().x(e=>e.x).y(e=>e.y).addAll(r)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;let i=t.length;if(i<=1)return;let r=this.getDatumIndexMap(t);for(let t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type||!t.datum)continue;let e=r.get(t.datum);if(null==e)continue;let n=this.computeDecayOpacity(e,i),o=t.style?.opacity??1;t.style={...t.style,opacity:o*n}}}applyPulse(e,t,i=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,n,o){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1;for(let c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){let t=c.category;if(!t)continue;let r=0;for(let a of n(t)??[]){let t=i.get(a);null!=t&&(r=Math.max(r,vn(e,t,o)))}l=wn(c,r,a)||l;continue}if(null==c.datum)continue;let t=r.get(c.datum);if(null==t)continue;let u=i.get(t);l=wn(c,null==u?0:vn(e,u,o),a,s)||l}return l}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),i)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&kn(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();let e,t=new Map,i=this.scales?.r(0)??0,r="horizontal"!==this.scales?.projection;for(let n=0;n<this.scene.length;n++){let o=this.scene[n],a=this.getNodeKey(o,t);a&&("rect"===o.type?r?this.prevPositionMap.set(a,{x:o.x,y:i,w:o.w,h:0,opacity:o.style.opacity??1}):this.prevPositionMap.set(a,{x:i,y:o.y,w:0,h:o.h,opacity:o.style.opacity??1}):"point"===o.type?this.prevPositionMap.set(a,{x:o.x,y:o.y,r:0,opacity:0}):"wedge"===o.type&&(void 0===e&&(e=o.startAngle),this.prevPositionMap.set(a,{x:o.cx,y:o.cy,startAngle:e,endAngle:e,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){let i=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,r=t.get(i)||0;return t.set(i,r+1),`${i}:${r}`}if("rect"===e.type){let i=e.datum?null!=e.datum.category&&""!==e.datum.category?String(e.datum.category):String(this.getO(e.datum)??""):"",r=`r:${e.group||""}:${i}`,n=t.get(r)||0;return t.set(r,n+1),0===n?r:`${r}:${n}`}return"wedge"===e.type?`w:${e.category??""}`:null}snapshotPositions(){this.prevPositionMap.clear();let e=new Map;for(let t=0;t<this.scene.length;t++){let i=this.scene[t],r=this.getNodeKey(i,e);r&&("point"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,r:i.r,opacity:i.style.opacity??i.style.fillOpacity}):"rect"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:i.style.opacity??i.style.fillOpacity}):"wedge"===i.type&&this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:i.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;let e=this.config.transition.duration??300;if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1,i=new Set,r=new Map;for(let e=0;e<this.scene.length;e++){let n=this.scene[e],o=this.getNodeKey(n,r);if(!o)continue;n._transitionKey=o;let a=this.prevPositionMap.get(o);if("point"===n.type)a?(i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.x!==n.x||a.y!==n.y||void 0!==a.r&&a.r!==n.r)&&(n._targetX=n.x,n._targetY=n.y,n._targetR=n.r,n.x=a.x,n.y=a.y,void 0!==a.r&&(n.r=a.r),t=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetR=n.r,n.r=0,n.style={...n.style,opacity:0},t=!0);else if("rect"===n.type)a?(i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.x!==n.x||a.y!==n.y||a.w!==n.w||a.h!==n.h)&&(n._targetX=n.x,n._targetY=n.y,n._targetW=n.w,n._targetH=n.h,n.x=a.x,n.y=a.y,n.w=a.w??n.w,n.h=a.h??n.h,t=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n.style={...n.style,opacity:0},t=!0);else if("wedge"===n.type)if(a)i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.startAngle!==n.startAngle||a.endAngle!==n.endAngle)&&(n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle,n.startAngle=a.startAngle,n.endAngle=a.endAngle,t=!0);else{n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle;let e=n.startAngle;n.startAngle=e,n.endAngle=e,n.style={...n.style,opacity:0},this.prevPositionMap.set(o,{x:n.cx,y:n.cy,startAngle:e,endAngle:e,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(let[e,r]of this.prevPositionMap)if(!i.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:r.x,y:r.y,r:r.r??3,style:{opacity:r.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:r.x,y:r.y,w:r.w??0,h:r.h??0,style:{opacity:r.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){let t=((r.startAngle??0)+(r.endAngle??0))/2,i={type:"wedge",cx:r.x,cy:r.y,innerRadius:r.innerRadius??0,outerRadius:r.outerRadius??100,startAngle:r.startAngle??0,endAngle:r.endAngle??0,style:{opacity:r.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(i)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;let n=i(e,this.activeTransition),o="linear"===this.config.transition?.easing?"linear":"ease-out-cubic",a=t(n,o);for(let e of this.scene){let t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),n=i?i.opacity??1:0;e.style.opacity=r(n,e._targetOpacity,a)}let i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=r(i.x,e._targetX,a),e.y=r(i.y,e._targetY,a)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=r(i.r,e._targetR,a))}else if("rect"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),n=i?i.opacity??1:0;e.style.opacity=r(n,e._targetOpacity,a)}if(void 0===e._targetX)continue;let i=this.prevPositionMap.get(t);if(!i)continue;e.x=r(i.x,e._targetX,a),e.y=r(i.y,e._targetY,a),void 0!==i.w&&(e.w=r(i.w,e._targetW,a),e.h=r(i.h,e._targetH,a))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),n=i?i.opacity??1:0;e.style={...e.style,opacity:r(n,e._targetOpacity,a)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){let i=this.prevPositionMap.get(t);i&&void 0!==i.startAngle&&(e.startAngle=r(i.startAngle,e._targetStartAngle,a),e.endAngle=r(i.endAngle,e._targetEndAngle,a))}}}if(n>=1){for(let e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}"point"===t.type?void 0!==t._targetX?(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0):void 0!==t._targetR&&(t.r=t._targetR,t._targetR=void 0):"rect"===t.type?void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0):"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw new Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();let t=yn(e),i=this.getDataId,r=e=>t.has(i(e));ao(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getDataId)throw new Error("update() requires dataIdAccessor to be configured");let i=yn(e),r=this.getDataId,n=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),n.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!q(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!q(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!q(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let r=!1;if("categoryAccessor"in e||"oAccessor"in e){let e=this.config.categoryAccessor||this.config.oAccessor,i=t.categoryAccessor||t.oAccessor;q(e,i)||(this.getO=V(this.config.categoryAccessor||this.config.oAccessor,"category"),r=!0)}let n=!1;if("valueAccessor"in e||"rAccessor"in e){let e=this.config.valueAccessor||this.config.rAccessor,i=t.valueAccessor||t.rAccessor,r=Array.isArray(e)?e:[e],o=Array.isArray(i)?i:[i];if(n=r.length!==o.length||r.some((e,t)=>!q(e,o[t])),n){let e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>X(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new mn)):(this.getR=X(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!q(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?V(this.config.stackBy):void 0),"groupBy"in e&&!q(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?V(this.config.groupBy):void 0),"colorAccessor"in e&&!q(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?V(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!q(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?V(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!q(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?V(this.config.connectorAccessor):void 0);let o="accessorRevision"in e&&e.accessorRevision!==t.accessorRevision;(r||n||o)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(i)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function OS(e,t,i,r){return"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:i,fn:e}:"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:r,fn:t}:{key:void 0,fn:null}}function zS(e,t,i){return r=>{if(!r||!i||!e.fn&&!t.fn)return r;let n=!1,o=r.map(i=>{let r=e.fn&&e.key&&!(e.key in i),o=t.fn&&t.key&&!(t.key in i);if(!r&&!o)return i;n=!0;let a={...i};return r&&(a[e.key]=e.fn(i)),o&&(a[t.key]=t.fn(i)),a});return n?o:r}}import*as BS from"react";import*as jS from"react";import{arc as WS}from"d3-shape";var YS=(e,t)=>({x:e*Math.cos(t),y:e*Math.sin(t)});function qS(e){let{innerRadius:t,outerRadius:i,startAngle:r,endAngle:n}=e,o=t<=0;if(!((e.cornerRadius??0)>0&&(e.roundStart||e.roundEnd))){if(o){let e=YS(i,r),t=YS(i,n),o=n-r>Math.PI?1:0;return`M0,0 L${e.x},${e.y} A${i},${i} 0 ${o} 1 ${t.x},${t.y} Z`}let e=YS(i,r),a=YS(i,n),s=YS(t,n),l=YS(t,r),c=n-r>Math.PI?1:0;return`M${e.x},${e.y} A${i},${i} 0 ${c} 1 ${a.x},${a.y} L${s.x},${s.y} A${t},${t} 0 ${c} 0 ${l.x},${l.y} Z`}let a=i-t,s=Math.max(0,Math.min(e.cornerRadius??0,a/2));if(0===s)return qS({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let l=Math.asin(Math.min(1,s/Math.max(1e-9,i-s))),c=o?0:Math.asin(Math.min(1,s/Math.max(1e-9,t+s))),u=n-r,d=e.roundStart&&e.roundEnd?u/2:u,h=!!e.roundStart&&l<d,p=!!e.roundEnd&&l<d;if(!h&&!p)return qS({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let f=r+(h?l:0),g=n-(p?l:0),m=r+(h?c:0),y=n-(p?c:0),x=YS(i,f),b=YS(i,g),v=(i-s)*Math.cos(l),w=YS(v,r),k=YS(v,n),S=o?null:YS(t,y),A=o?null:YS(t,m),M=o?0:(t+s)*Math.cos(c),$=o?null:YS(M,r),_=o?null:YS(M,n),P=g-f>Math.PI?1:0,I=o?0:y-m>Math.PI?1:0,T="";if(h)T+=`M${w.x},${w.y}`,T+=` A${s},${s} 0 0 1 ${x.x},${x.y}`;else{let e=YS(i,r);T+=`M${e.x},${e.y}`}if(p)T+=` A${i},${i} 0 ${P} 1 ${b.x},${b.y}`,T+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{let e=YS(i,n);T+=` A${i},${i} 0 ${P} 1 ${e.x},${e.y}`}if(o)T+=" L0,0";else{if(p)T+=` L${_.x},${_.y}`,T+=` A${s},${s} 0 0 1 ${S.x},${S.y}`;else{let e=YS(t,n);T+=` L${e.x},${e.y}`}if(h)T+=` A${t},${t} 0 ${I} 0 ${A.x},${A.y}`,T+=` A${s},${s} 0 0 1 ${$.x},${$.y}`;else{let e=YS(t,r);T+=` A${t},${t} 0 ${I} 0 ${e.x},${e.y}`}}return T+=" Z",T}import{jsx as XS,jsxs as GS}from"react/jsx-runtime";function VS(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${(e/1e3).toFixed(0)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function HS(e,t){let i=e.datum;if(!i)return null;let r=[],n=i.__funnelStepLabel,o=Number(i.__funnelStepLabelX),a=Number(i.__funnelStepLabelY),s=Number(i.__funnelRowWidth);"string"==typeof n&&Number.isFinite(o)&&Number.isFinite(a)&&(!Number.isFinite(s)||8.4*n.length+16<=s)&&r.push(XS("text",{x:o,y:a+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-step`));let l=Number(i.__funnelValue),c=Number(i.__funnelValueLabelX),u=Number(i.__funnelValueLabelY),d=Number(i.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){let e=Number(i.__funnelPercent),n=!0!==i.__funnelIsFirstStep&&Number.isFinite(e)?`${VS(l)} (${Math.abs(e-Math.round(e))<.05?Math.round(e):e.toFixed(1)}%)`:VS(l);7.8*n.length+16>d&&(n=VS(l)),7.8*n.length+16<=d&&r.push(XS("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-value`))}return r.length?XS("g",{children:r},`${t}-funnel-labels`):null}function US(e,t,i){return Ha(function(e,t,i){let r=("category"in e?e.category:void 0)||("group"in e?e.group:void 0)||"",n=i=>`ord-${e.type}-${r}-${t}-${i}`,o=`ord-${e.type}-${r}-${t}`;switch(e.type){case"rect":{let t,i,r=e,n=`${Ba(o)}-grad`,a=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=e.x,n=e.y,o=e.x,a=e.y+e.h;"bottom"===e.roundedEdge?(n=e.y+e.h,a=e.y):"right"===e.roundedEdge?(r=e.x+e.w,n=e.y,o=e.x,a=e.y):"left"===e.roundedEdge&&(r=e.x,n=e.y,o=e.x+e.w,a=e.y);let s=Wa(i.stops,za(e.style.fill));return s?Fa("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:r,y1:n,x2:o,y2:a,children:s}):null}(r,n);if(a)i=`url(#${n})`;else if(ka(r.style.fill)){let e=`${Ba(o)}-hatch`;t=Sa(r.style.fill,e),i=`url(#${e})`}else i=za(r.style.fill);let s=a||t?GS("defs",{children:[a,t]}):null;if(r.cornerRadii&&function(e){return(e.tl??0)>0||(e.tr??0)>0||(e.br??0)>0||(e.bl??0)>0}(r.cornerRadii)){let e=function(e){let{x:t,y:i,w:r,h:n}=e,{tl:o,tr:a,br:s,bl:l}=function(e){let t=e.cornerRadii;if(!t)return{tl:0,tr:0,br:0,bl:0};let i=Math.min(e.w,e.h)/2,r=e=>Math.max(0,Math.min(e??0,i));return{tl:r(t.tl),tr:r(t.tr),br:r(t.br),bl:r(t.bl)}}(e),c=`M${t+o},${i}`;return c+=` L${t+r-a},${i}`,a>0&&(c+=` A${a},${a} 0 0 1 ${t+r},${i+a}`),c+=` L${t+r},${i+n-s}`,s>0&&(c+=` A${s},${s} 0 0 1 ${t+r-s},${i+n}`),c+=` L${t+l},${i+n}`,l>0&&(c+=` A${l},${l} 0 0 1 ${t},${i+n-l}`),c+=` L${t},${i+o}`,o>0&&(c+=` A${o},${o} 0 0 1 ${t+o},${i}`),c+=" Z",c}(r);return GS(jS.Fragment,{children:[s,XS("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},o)}if(r.roundedTop&&r.roundedTop>0){let e,t=Math.min(r.roundedTop,r.w/2,r.h/2),{x:n,y:a,w:l,h:c}=r;switch(r.roundedEdge){case"right":e=`M${n},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n},${a+c} Z`;break;case"left":e=`M${n+l},${a} L${n+t},${a} A${t},${t} 0 0 0 ${n},${a+t} L${n},${a+c-t} A${t},${t} 0 0 0 ${n+t},${a+c} L${n+l},${a+c} Z`;break;case"bottom":e=`M${n},${a} L${n+l},${a} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n+t},${a+c} A${t},${t} 0 0 1 ${n},${a+c-t} Z`;break;default:e=`M${n},${a+c} L${n},${a+t} A${t},${t} 0 0 1 ${n+t},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c} Z`}return GS(jS.Fragment,{children:[s,XS("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},o)}return GS(jS.Fragment,{children:[s,XS("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth}),HS(r,o)]},o)}case"point":{let t=e;return XS("circle",{cx:t.x,cy:t.y,r:t.r,fill:za(t.style.fill),opacity:t.style.opacity??t.style.fillOpacity??.8,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},o)}case"symbol":return Ya(e,t,i);case"glyph":{let r=e;return ja(r,r.x,r.y,`${i??""}ord-glyph-${r.pointId??t}`)}case"wedge":{let r,n=e;if(n._gradientBand&&n._gradientBand.colors.length>0){let e=Ba(`${i?`${i}-`:""}gauge-grad-${n.category||o}-${t}`),{clipPath:r,slices:a}=function(e){let t=qS({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,cornerRadius:e.cornerRadius,roundStart:e.roundStart,roundEnd:e.roundEnd}),i=[],r=e.colors;if(r.length>0){let t=(e.endAngle-e.startAngle)/r.length;for(let n=0;n<r.length;n++){let o=e.startAngle+n*t;i.push({d:qS({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:o,endAngle:e.endAngle}),color:r[n]})}}return{clipPath:t,slices:i}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return GS("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[XS("defs",{children:XS("clipPath",{id:e,children:XS("path",{d:r})})}),XS("g",{clipPath:`url(#${e})`,children:a.map((e,t)=>XS("path",{d:e.d,fill:za(e.color)},t))}),n.style.stroke&&"none"!==n.style.stroke&&XS("path",{d:r,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},o)}if(n.roundedEnds)r=qS({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{let e=WS().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&e.cornerRadius(n.cornerRadius),r=e(Oa)||""}return XS("path",{d:r,transform:`translate(${n.cx},${n.cy})`,fill:za(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},o)}case"boxplot":{let t=e,i=t.columnWidth/2,r=t.style.strokeWidth??1;return"vertical"===t.projection?GS("g",{children:[XS("line",{x1:t.x,y1:t.minPos,x2:t.x,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("rect",{x:t.x-i,y:Math.min(t.q1Pos,t.q3Pos),width:t.columnWidth,height:Math.abs(t.q3Pos-t.q1Pos),fill:za(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("line",{x1:t.x-i,y1:t.medianPos,x2:t.x+i,y2:t.medianPos,stroke:t.style.stroke||"#333",strokeWidth:2*r}),XS("line",{x1:t.x-.5*i,y1:t.minPos,x2:t.x+.5*i,y2:t.minPos,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("line",{x1:t.x-.5*i,y1:t.maxPos,x2:t.x+.5*i,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r})]},o):GS("g",{children:[XS("line",{x1:t.minPos,y1:t.y,x2:t.maxPos,y2:t.y,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("rect",{x:Math.min(t.q1Pos,t.q3Pos),y:t.y-i,width:Math.abs(t.q3Pos-t.q1Pos),height:t.columnWidth,fill:za(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("line",{x1:t.medianPos,y1:t.y-i,x2:t.medianPos,y2:t.y+i,stroke:t.style.stroke||"#333",strokeWidth:2*r}),XS("line",{x1:t.minPos,y1:t.y-.5*i,x2:t.minPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r}),XS("line",{x1:t.maxPos,y1:t.y-.5*i,x2:t.maxPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r})]},o)}case"violin":{let t=e,i=[XS("path",{d:t.pathString,transform:t.translateX||t.translateY?`translate(${t.translateX},${t.translateY})`:void 0,fill:za(t.style.fill),fillOpacity:t.style.fillOpacity??t.style.opacity??.6,stroke:t.style.stroke||"#333",strokeWidth:t.style.strokeWidth??1},n("path"))];if(t.iqrLine&&t.bounds){let e=t.bounds,r=e.x+e.width/2,o=e.y+e.height/2;t.iqrLine.isVertical?i.push(XS("line",{x1:r,y1:t.iqrLine.q1Pos,x2:r,y2:t.iqrLine.q3Pos,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),XS("circle",{cx:r,cy:t.iqrLine.medianPos,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med"))):i.push(XS("line",{x1:t.iqrLine.q1Pos,y1:o,x2:t.iqrLine.q3Pos,y2:o,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),XS("circle",{cx:t.iqrLine.medianPos,cy:o,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med")))}return XS("g",{children:i},o)}case"connector":{let t=e,i=t.style.fill&&"none"!==t.style.fill?za(t.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return XS("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||i,strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity??.5},o)}case"trapezoid":{let t=e,i=t.points.map(e=>`${e[0]},${e[1]}`).join(" ");return XS("polygon",{points:i,fill:za(t.style.fill,"#999"),opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},o)}default:return null}}(e,t,i),e,`ordinal-cursor-${t}`)}import{jsx as ZS,jsxs as KS}from"react/jsx-runtime";function QS(e){return"connector"===e.node.type}function JS(e,t,i,r){if(e.length<2)return null;let n=e[0].node,o=n.style.fill;if(!o||"none"===o)return null;let a=Ba(`${t?`${t}-`:""}connector-${i}-${r}-hatch`),s=ka(o)?Sa(o,a):null,l=[`${n.x1},${n.y1}`,...e.map(({node:e})=>`${e.x2},${e.y2}`)].join(" ");return Ha(KS(BS.Fragment,{children:[s&&ZS("defs",{children:s}),ZS("polygon",{points:l,fill:s?`url(#${a})`:za(o,"#999"),opacity:n.style.fillOpacity??n.style.opacity??.3,"data-semiotic-connector-fill":n.group||"_default"})]}),n,`ordinal-connector-fill-${i}-${r}`)}function eA(e,t,i){let r=new Map;for(let t of e){if(!QS(t))continue;let e=t.node.group||"_default",i=r.get(e);i?i.push(t):r.set(e,[t])}if(0===r.size)return;let n=Array.from(r.values()).map((e,r)=>KS("g",{children:[JS(e,t,i,r),e.map(e=>e.element)]},`ordinal-connectors-${i}-${r}`)),o=e[0],a=QS(o)?null:o.element;for(let e of r.values())for(let t of e)t.element=null;o.element=KS(BS.Fragment,{children:[n,a]},`ordinal-connector-run-${i}`)}function tA(e){let t=ts({nodes:e.nodes,renderMode:e.renderMode,fallback:(t,i)=>US(t,i,e.idPrefix)}),i=0;for(let r=0;r<t.length;){if(t[r].renderedByBackend){r++;continue}let n=r+1;for(;n<t.length&&!t[n].renderedByBackend;)n++;eA(t.slice(r,n),e.idPrefix,i++),r=n}return t}var iA={stroke:"rgba(255,255,255,0.5)",lineWidth:1.5,spacing:6,angle:45,lineOpacity:1};import{Fragment as rA,jsx as nA,jsxs as oA}from"react/jsx-runtime";function aA(e,t){let i=$i(e.theme),r=Yc,n=e.size||[500,400],o=xe({...r,...e.margin},ln(e.title)),a=me(ln(e.title)),s=Mt(e.data),l=e.showLegend?ps(s,e.colorAccessor||e.stackBy||e.groupBy):[],c=function(e){let t=e.projection??"vertical",i=!1!==e.showAxes&&"radial"!==t;return{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasValueLabel:e.hasCategoryLabel),leftAxis:{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasCategoryLabel:e.hasValueLabel)}}}({showAxes:e.showAxes,projection:e.projection,hasCategoryLabel:!(!e.categoryLabel&&!e.oLabel),hasValueLabel:!(!e.valueLabel&&!e.rLabel)});Rc(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=Nc({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),p=e.projection||"vertical",f="radial"===p,g=e.colorScheme||i.colors.categorical,m={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:p,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:pi(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:g,themeCategorical:i.colors.categorical,themeSemantic:M(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors},y=new ES(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Wc(e.backgroundGraphics,n,o,y.scales),b=Wc(e.foregroundGraphics,n,o,y.scales);if(!y.scales){let r,a=e.annotations?nc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,projection:p,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=ma({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?oA(rA,{children:[x,a,b,y.customLayoutOverlays]}):null;return sS.renderToStaticMarkup(Dc(l,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let v=e._idPrefix,w=e.showGrid?function(e,t,i,r,n,o){let a=e.scales;if(!a||"radial"===a.projection)return null;let{grid:s}=_i(i),l=r?`${r}-`:"",c="vertical"===a.projection,u=o??gc(a.r,5,n);return Ac("g",c?{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);return Ac("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:s,strokeWidth:.5},`gr-${i}`)})}:{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);return Ac("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},`gr-${i}`)})})}(y,{width:d,height:h},i,v,e.axisExtent,e.rTickValues):null,k=null;if(y.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){let t=_c(e),i=new Set;for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";i.add(t)}k=Array.from(i).map((e,i)=>function(e){let{id:t,...i}=e;return Sa({type:"hatch",...i},t)}({...iA,id:`funnel-hatch-${t}-${i}`,background:e}));let r=new Map;Array.from(i).forEach((e,i)=>r.set(e,`funnel-hatch-${t}-${i}`));for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";e.style={...e.style,fill:`url(#${r.get(t)})`}}}let S,A=tA({nodes:y.scene,renderMode:e.renderMode,idPrefix:v}),$=A.map(e=>e.element),_=!1!==e.showAxes?function(e,t,i,r,n,o,a,s=!1){let l=e.scales;if(!l||"radial"===l.projection)return null;let c=_i(r),u="vertical"===l.projection,d=e.columns,h=i.categoryFormat||i.oFormat,p=i.valueFormat||i.rFormat,f=i.categoryLabel||i.oLabel,g=i.valueLabel||i.rLabel,m=i.legendPosition??"right",y=Se(i.legendLayout,a?.leftAxis),x=s&&"left"===m&&y>0?y:o?.left??i.margin?.left??40,b=Object.values(d).map((e,t)=>({pixel:e.middle,label:h?h(e.name,t):e.name})),v=i.rTickValues??gc(l.r,5,i.axisExtent),w=p||he(v),k=v.map(e=>({pixel:l.r(e),label:w(e)}));return oA("g",u?{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[nA("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,i)=>oA("g",{transform:`translate(${e.pixel},${t.height})`,children:[nA("line",{y2:5,stroke:c.border,strokeWidth:1}),yc(e.label)?nA("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):xc({label:e.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oxtick-${i}`)),f&&nA("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:f}),nA("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),k.map((e,t)=>oA("g",{transform:`translate(0,${e.pixel})`,children:[nA("line",{x2:-5,stroke:c.border,strokeWidth:1}),nA("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oytick-${t}`)),g&&nA("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:g})]}:{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[nA("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),k.map((e,i)=>oA("g",{transform:`translate(${e.pixel},${t.height})`,children:[nA("line",{y2:5,stroke:c.border,strokeWidth:1}),nA("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oxtick-${i}`)),g&&nA("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),nA("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,t)=>oA("g",{transform:`translate(0,${e.pixel})`,children:[nA("line",{x2:-5,stroke:c.border,strokeWidth:1}),yc(e.label)?nA("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):xc({label:e.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oytick-${t}`)),f&&nA("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:f})]})}(y,{width:d,height:h},e,i,v,o,c,!!u):null,P=e.categoryAccessor??e.oAccessor??"category",I=e.valueAccessor??e.rAccessor??"value",T="horizontal"===p,L=OS(T?I:P,void 0,"__semiotic_resolvedO",""),C=OS(T?P:I,void 0,"__semiotic_resolvedR",""),R=e.annotations?nc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:zS(L,C,e.annotations.length>0)(s),scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:d,height:h},theme:i,projection:p,xAccessor:L.key,yAccessor:C.key,idPrefix:v,onRender:e=>{S=e}}):null;if(t){let i=y.scales.o?.domain?.();t.evidence=ma({frameType:"ordinal",width:n[0],height:n[1],marks:A.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:S,yDomain:ga(y.scales.r?.domain?.()),categories:Array.isArray(i)?i.map(String):void 0,margin:o})}let N=f&&null!=e.centerContent?function(e,t,i,r){if(("string"==typeof e||"number"==typeof e)&&(e=nS("text",{fill:"currentColor",...r,children:e})),!aS(e))return null;if(!rS.isValidElement(e)||e.type===rS.Fragment)return nS("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:e});let n=e,o="text"===n.type?rS.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return nS("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:o})}(e.centerContent,o.left+d/2,o.top+h/2,{fill:i.colors.text,fontFamily:i.typography.fontFamily,fontSize:i.typography.titleSize}):null,D=f&&null!=e.centerContent?N??nA("foreignObject",{x:o.left,y:o.top,width:d,height:h,pointerEvents:"none",children:nA("div",{xmlns:Ll,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null,F=oA(rA,{children:[w,$,_,R,b,y.customLayoutOverlays]}),E=oA(rA,f?{children:[x?nA("g",{transform:`translate(${-d/2},${-h/2})`,children:x}):null,F]}:{children:[x,F]});return sS.renderToStaticMarkup(Dc(E,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:f?`translate(${o.left+d/2},${o.top+h/2})`:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,defs:k,outerElements:D,markCount:A.length,idPrefix:e._idPrefix}))}import*as sA from"react-dom/server";import{geoPath as lA}from"d3-geo";var cA=/*#__PURE__*/new WeakMap;function uA(e,t){cA.set(e,t)}function dA(e,t){let i,r=new Map;return e.map(e=>{let n=cA.get(e);if(void 0!==n)return n;if(!i){let e=new Map;i=e,t.forEach((t,i)=>{let r=e.get(t);r?r.push(i):e.set(t,[i])})}let o=r.get(e.datum)??0;return r.set(e.datum,o+1),i.get(e.datum)?.[o]??-1})}import{geoPath as hA}from"d3-geo";function pA(e){return{projection:e,geoPath:hA(e),projectedPoint:(t,i)=>e([t,i]),invertedPoint:(t,i)=>e.invert?.([t,i])??null}}import{geoPath as fA}from"d3-geo";import{quadtree as gA}from"d3-quadtree";import{geoMercator as mA,geoEqualEarth as yA,geoAlbersUsa as xA,geoOrthographic as bA,geoNaturalEarth1 as vA,geoEquirectangular as wA}from"d3-geo";var kA={mercator:mA,equalEarth:yA,albersUsa:xA,orthographic:bA,naturalEarth:vA,equirectangular:wA};function SA(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function AA(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function MA(e,t,i){return e?"function"==typeof e?{...i,...e(t)}:{...i,...e}:{...i}}function $A(e,t){if(e.length<2)return[e];let i=.4*t,r=[],n=[e[0]];for(let t=1;t<e.length;t++){let o=e[t-1],a=e[t];Math.abs(a[0]-o[0])>i?(n.length>=2&&r.push(n),n=[a]):n.push(a)}return n.length>=2&&r.push(n),r}function _A(e,t,i=24){let r=t[0]-e[0],n=t[1]-e[1],o=Math.sqrt(r*r+n*n);if(0===o)return[e,t];let a=-n/o,s=r/o,l=Math.min(.3*o,80),c=(e[0]+t[0])/2+a*l,u=(e[1]+t[1])/2+s*l,d=[];for(let r=0;r<=i;r++){let n=r/i,o=1-n,a=o*o*e[0]+2*o*n*c+n*n*t[0],s=o*o*e[1]+2*o*n*u+n*n*t[1];d.push([a,s])}return d}function PA(e,t){if(e.length<2)return e;let i=t/2+1,r=[];for(let t=0;t<e.length;t++){let n,o,a=e[t];0===t?(n=e[1][0]-a[0],o=e[1][1]-a[1]):t===e.length-1?(n=a[0]-e[t-1][0],o=a[1]-e[t-1][1]):(n=e[t+1][0]-e[t-1][0],o=e[t+1][1]-e[t-1][1]);let s=Math.sqrt(n*n+o*o)||1,l=o/s,c=-n/s;r.push([a[0]+l*i,a[1]+c*i])}return r}function IA(e,t,i,r,n){let o=t[0]-e[0],a=t[1]-e[1],s=Math.sqrt(o*o+a*a);if(0===s)return[e,t];let l=a/s,c=-o/s,u=n/2+1;return[[e[0]+l*u,e[1]+c*u],[t[0]+l*u,t[1]+c*u]]}import{scaleLinear as TA}from"d3-scale";var LA=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],CA=["scene-style","data-paint","accessibility","evidence"],RA=(e,t)=>({retainedData:e,invalidations:t}),NA=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],DA=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],FA=["scene-geometry","data-paint","accessibility","evidence"],EA=["scene-style","data-paint","accessibility","evidence"],OA=["scene-geometry","scene-style","data-paint","accessibility","evidence"],zA=["overlay","accessibility","evidence"],BA=[],jA={xAccessor:/*#__PURE__*/RA("rebuild",NA),yAccessor:/*#__PURE__*/RA("rebuild",NA),lineDataAccessor:/*#__PURE__*/RA("rebuild",NA),pointIdAccessor:/*#__PURE__*/RA("rebuild",FA),lineIdAccessor:/*#__PURE__*/RA("rebuild",FA),windowSize:/*#__PURE__*/RA("rebuild",NA),projection:/*#__PURE__*/RA("preserve",DA),projectionExtent:/*#__PURE__*/RA("preserve",DA),fitPadding:/*#__PURE__*/RA("preserve",DA),lineType:/*#__PURE__*/RA("preserve",DA),flowStyle:/*#__PURE__*/RA("preserve",DA),graticule:/*#__PURE__*/RA("preserve",DA),projectionTransform:/*#__PURE__*/RA("preserve",DA),customLayout:/*#__PURE__*/RA("preserve",DA),layoutConfig:/*#__PURE__*/RA("preserve",DA),layoutMargin:/*#__PURE__*/RA("preserve",DA),areaStyle:/*#__PURE__*/RA("preserve",EA),pointStyle:/*#__PURE__*/RA("preserve",OA),lineStyle:/*#__PURE__*/RA("preserve",EA),colorScheme:/*#__PURE__*/RA("preserve",EA),themeCategorical:/*#__PURE__*/RA("preserve",EA),themeDiverging:/*#__PURE__*/RA("preserve",EA),themeSemantic:/*#__PURE__*/RA("preserve",EA),themeSequential:/*#__PURE__*/RA("preserve",EA),decay:/*#__PURE__*/RA("preserve",EA),pulse:/*#__PURE__*/RA("preserve",EA),layoutSelection:/*#__PURE__*/RA("preserve",EA),annotations:/*#__PURE__*/RA("preserve",zA),autoPlaceAnnotations:/*#__PURE__*/RA("preserve",zA),clock:/*#__PURE__*/RA("preserve",BA),transition:/*#__PURE__*/RA("preserve",BA),introAnimation:/*#__PURE__*/RA("preserve",BA),onLayoutError:/*#__PURE__*/RA("preserve",BA)},WA=/*#__PURE__*/RA("preserve",DA),YA=class{constructor(){this.tracker=new po}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},LA)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},CA):this.recordNoop("restyle")}recordConfig(e,t={}){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(jA,r)?jA[r]:WA;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e),r=new Set(i.invalidations);return t.retainedDataChanged&&r.add("data"),this.tracker.record({kind:"config",keys:e},r)}};import{geoDistance as qA,geoGraticule as XA,geoInterpolate as GA}from"d3-geo";function VA(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&e<.5)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${String(e)}.`)}var HA=class extends lo{constructor(e){var t;super(),this.updateResults=new YA,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=(t=e,{...t,fitPadding:VA(t.fitPadding)})}currentTime(){return this.config.clock?.()??n()}getConfiguredWindowSize(){let e=this.config.windowSize??500;if(!Number.isInteger(e)||e<1)throw new Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){let t=this.pointBuffer.toArray(),i=this.timestampBuffer?.toArray()??[],r=t.slice(-e),n=i.slice(-r.length),o=this.currentTime();this.pointBuffer=new gn(e),this.timestampBuffer=new gn(e),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(n[t]??o)})}this.retainNewestLines(e)}updateConfig(e){let t="fitPadding"in(o=e)?{...o,fitPadding:VA(o.fitPadding)}:o,i=this.config,r=this.getConfiguredWindowSize(),n=Object.keys(t).filter(e=>t[e]!==i[e]);var o;this.config={...this.config,...t};let a=this.getConfiguredWindowSize(),s=this.streaming&&a!==r;s&&(this.resizeStreamingWindow(a),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});let t=this.getConfiguredWindowSize(),i=this.pointBuffer?this.pointBuffer.toArray():this.pointData,r=this.timestampBuffer?.toArray()??[],n=i.slice(-t),o=r.slice(-n.length),a=this.currentTime();this.pointBuffer=new gn(t),this.timestampBuffer=new gn(t),n.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(o[t]??a)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();oo(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();for(let i of e)oo(this.pointBuffer,i,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");let t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(let e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){let{lineIdAccessor:t}=this.config;if(!t)throw new Error("removeLine() requires lineIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]),n=[];return this.lineData=this.lineData.filter(e=>!r.has(String(i(e)))||(n.push(e),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(e){let{pointIdAccessor:t}=this.config;if(!t)throw new Error("removePoint() requires pointIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){let e=e=>r.has(String(i(e)));ao(this.pointBuffer,this.timestampBuffer,e);let t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{let e=[];return this.pointData=this.pointData.filter(t=>!r.has(String(i(t)))||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){let t=this._customRestyle;if(t){for(let i of this.scene){let r=this._baseStyles.get(i)??i.style,n=t(i,e);i.style=n?{...r,...n}:r}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}rebuildProjectedScene(e,t){this._customLayoutFailedThisBuild=!1;let i=this.buildSceneNodes(e);return this._customLayoutFailedThisBuild?(this.lastCustomLayoutFailure?.preservedLastGoodScene?t():(this.scene=[],this.rebuildQuadtree()),!1):(this.scene=i,this.rebuildQuadtree(),!0)}computeScene(e){let{config:t}=this,i=this.projection,r=this.geoPath,n=this.scales,o=this.baseScale,a=[...this.baseTranslate],s=[...this.baseRotation],l=this.scene;this.projection=function(e){if(!e)return yA();if("string"==typeof e){let t=kA[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),yA())}if("object"==typeof e&&"type"in e){let t=kA[e.type],i=t?t():yA();return e.rotate&&"rotate"in i&&i.rotate(e.rotate),e.center&&"center"in i&&i.center(e.center),i}return e}(t.projection),this.geoPath=fA(this.projection),this.fitProjection(e),this.geoPath=fA(this.projection);let c=this.projection;if(this.scales=pA(c),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(e,()=>{this.projection=i,this.geoPath=r,this.scales=n,this.baseScale=o,this.baseTranslate=a,this.baseRotation=s})){if(t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){let t=e.width/2,i=e.height/2,r=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:i}));r.length>0&&this.startTransition(r)}this._hasRenderedOnce=!0,t.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(e){let t=this.projection,i=this.config,r=[...this.areas],n=SA(i.xAccessor,"lon"),o=SA(i.yAccessor,"lat"),a=this.getPoints();if(a.length>0){let e=a.map(e=>[n(e),o(e)]).filter(e=>e.every(Number.isFinite));r.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}let s=AA(i.lineDataAccessor);for(let e of this.lineData){let t=s(e);if(t&&t.length>0){let e=t.map(e=>[n(e),o(e)]);r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==r.length){if(i.projectionExtent){let[[r,n],[o,a]]=i.projectionExtent,s={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[r,n],[r,a],[o,a],[o,n],[r,n]]]}};t.fitExtent([[0,0],[e.width,e.height]],s)}else if(t.clipAngle&&(t.clipAngle()??0)>0){let r=i.fitPadding??0,n=Math.min(e.width,e.height),o=n/2-n*r;t.scale(o),t.translate([e.width/2,e.height/2])}else{let n={type:"FeatureCollection",features:r},o=i.fitPadding??0,a=e.width*o,s=e.height*o;t.fitExtent([[a,s],[e.width-a,e.height-s]],n),function(e,t,i){if(Number.isFinite(e.scale())&&e.translate().every(Number.isFinite))return;e.scale(Math.max(1,Math.min(i.width,i.height)/(2*Math.PI))),e.translate([i.width/2,i.height/2]);let r=lA(e).bounds(t);if(!r.flat().every(Number.isFinite))return;let n=e.translate();e.translate([n[0]+i.width/2-(r[0][0]+r[1][0])/2,n[1]+i.height/2-(r[0][1]+r[1][1])/2])}(t,n,e)}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e.k),i.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=fA(i),this.scales=pA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e),i.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=fA(i),this.scales=pA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){let i=this.projection;if(!i||!i.rotate)return;let r=this.geoPath,n=this.scales,o=[...i.rotate()];i.rotate(e),this.geoPath=fA(i),this.scales=pA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.rotate(o),this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){let t=this.projection;!t||!t.rotate||t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,t=0;for(let i of this.scene)"point"===i.type&&!1!==i.interactive&&(t++,i.r>e&&(e=i.r));if(this._maxPointRadius=e,t<=500)return void(this._quadtree=null);let i=new Array(t),r=0;for(let e of this.scene)"point"===e.type&&!1!==e.interactive&&(i[r++]=e);this._quadtree=gA().x(e=>e.x).y(e=>e.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;let{config:t}=this,i=this.projection,r=this.geoPath;if(t.customLayout&&this.scales){let i=t.layoutMargin??{top:0,right:0,bottom:0,left:0},r=Qf(t.colorScheme,t.themeCategorical,Kt),n={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:i,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...r]},resolveColor:Jf(r,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null},o=Rn({family:"geo",logLabel:"geo customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:t.onLayoutError,run:()=>t.customLayout(n)});if("failure"===o.kind)return this.lastCustomLayoutFailure=o.diagnostic,this._customLayoutFailedThisBuild=!0,o.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let a=o.result,s=a.nodes??[];if(this.customLayoutOverlays=a.overlays??null,this.lastCustomLayoutResult=a,this.lastCustomLayoutFailure=null,this._customRestyle=a.restyle,this.hasCustomRestyle=!!a.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle)for(let e of s){this._baseStyles.set(e,e.style);let i=a.restyle?.(e,t.layoutSelection??null);i&&(e.style={...e.style,...i})}return Tn({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:i,areas:r,points:n,lines:o,layout:a}){let s=SA(e.xAccessor,"lon"),l=SA(e.yAccessor,"lat"),c=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){let t=!0===e.graticule?{}:e.graticule,r=XA();t.step&&r.step(t.step);let n=i(r())||"";n&&c.push({type:"geoarea",pathData:n,centroid:[a.width/2,a.height/2],bounds:[[0,0],[a.width,a.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth??.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(let t of r){let r=i(t);if(!r)continue;let n=i.centroid(t),o=i.bounds(t),a=i.area(t);c.push({type:"geoarea",pathData:r,centroid:n,bounds:o,screenArea:a,style:MA(e.areaStyle,t,u),datum:t,interactive:!0})}let p=AA(e.lineDataAccessor);for(let i of o){let r=p(i);if(!r||r.length<2)continue;let n=[];if("geo"===e.lineType){let e=new Array(r.length);for(let t=0;t<r.length;t++)e[t]=[s(r[t]),l(r[t])];for(let i=0;i<e.length-1;i++){let r=e[i],o=e[i+1],a=qA(r,o)||0,s=Math.max(2,Math.ceil(a/(Math.PI/180))),l=GA(r,o);for(let e=0;e<=s;e++){if(i>0&&0===e)continue;let r=t(l(e/s));null!=r&&n.push(r)}}}else for(let e=0;e<r.length;e++){let i=r[e],o=t([s(i),l(i)]);null!=o&&n.push(o)}if(n.length<2)continue;let o=MA(e.lineStyle,i,d),u="number"==typeof o.strokeWidth?o.strokeWidth:1;2===r.length&&n.length>=2&&"arc"===e.flowStyle?n=_A(n[0],n[n.length-1]):2===r.length&&n.length>=2&&"offset"===e.flowStyle&&(n="geo"===e.lineType?PA(n,u):IA(n[0],n[n.length-1],0,0,u));let h=$A(n,a.width);if(h.length<=1)c.push({type:"line",path:n.length>=2?n:h[0]||n,style:o,datum:i});else for(let e of h)e.length<2||c.push({type:"line",path:e,style:{...o,_edgeFade:!0},datum:i})}let f=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,g=t.clipAngle?t.clipAngle()??0:0,m=g>0?g*Math.PI/180:null,y=t.rotate?t.rotate():[0,0,0],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-y[0],(x[1]??0)-y[1]];for(let[i,r]of n.entries()){let n=s(r),o=l(r);if(!Number.isFinite(n)||!Number.isFinite(o)||null!=m&&qA([n,o],b)>m)continue;let a=t([n,o]);if(!a||!Number.isFinite(a[0])||!Number.isFinite(a[1]))continue;let u=e.pointStyle?e.pointStyle(r):{...h},d={type:"point",x:a[0],y:a[1],r:u.r||4,style:u,datum:r,pointId:f?String(f(r)):void 0};uA(d,i),c.push(d)}return c}({config:t,projection:i,path:r,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){let i=function(e,t,i,r){let n=e.filter(e=>"point"===e.type);if(n.length<2)return null;let o=t.strength??1,a=Number.isFinite(o)?Math.max(0,Math.min(1,o)):1,s="strip"===t.layout?"strip":"radial";if("radial"===s&&0===a)return null;let l=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=n.find(e=>e.datum&&String(l(e.datum))===String(t.center));if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;let d=n.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),h=ue(d,1);r>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){let i=e[t];"geoarea"===i.type&&i.interactive&&e.splice(t,1)}let p="strip"===s?function(e,t,i,r,n){let o=Math.max(3,Math.min(8,.35*n.height)),a=Math.max(1,n.width-2*o),s=n.height/2,l=TA().domain([0,r]).range([0,a]);t.x=o,t.y=s;let c=[];for(let n of e){if(n===t)continue;if(!n.datum){n.x=o,n.y=s;continue}let e=Number(i(n.datum)),a=o+(isFinite(e)&&e>=0&&r>0?l(e):0);n.x=a,n.y=s,c.push({node:n,x:a})}c.sort((e,t)=>e.x-t.x);let u=Math.max(0,Math.min(n.height/2-1,6)),d=0;for(;d<c.length;){let e=d+1;for(;e<c.length&&Math.abs(c[e].x-c[d].x)<3;)e++;let t=e-d;if(t>1&&u>0)for(let e=0;e<t;e++){let i=e-(t-1)/2,r=Math.min(2.5,2*u/Math.max(1,t-1));c[d+e].node.y=s+i*r}d=e}return{cx:o,cy:s,maxCost:r,availableRadius:a,layout:"strip"}}(n,u,c,h,i):function(e,t,i,r,n,o){let a=t.x,s=t.y,l=o.width/2,c=o.height/2,u=Math.min(o.width,o.height)/2,d=TA().domain([0,r]).range([0,u]);for(let o of e){if(o===t||!o.datum)continue;let e=o.x,u=o.y,h=Math.atan2(u-s,e-a),p=Math.hypot(e-a,u-s),f=Number(i(o.datum)),g=isFinite(f)&&f>=0?r>0?d(f):0:p,m=l+Math.cos(h)*g,y=c+Math.sin(h)*g;o.x=e+(m-e)*n,o.y=u+(y-u)*n}return t.x=a+(l-a)*n,t.y=s+(c-s)*n,{cx:t.x,cy:t.y,maxCost:r,availableRadius:u,layout:"radial"}}(n,u,c,h,a,i),f=e.filter(e=>"line"===e.type);if(f.length>0){let e=new Map;for(let t of n)null!=t.pointId&&e.set(String(t.pointId),[t.x,t.y]);for(let i of f){let r=i.datum?.source,n=i.datum?.target;if(null!=r&&null!=n){let o=e.get(String(r)),a=e.get(String(n));if(o&&a)if("fractional"===t.lineMode&&i.path.length>2){let e=i.path[0],t=i.path[i.path.length-1],r=[o[0]-e[0],o[1]-e[1]],n=[a[0]-t[0],a[1]-t[1]],s=[0];for(let e=1;e<i.path.length;e++)s.push(s[e-1]+Math.hypot(i.path[e][0]-i.path[e-1][0],i.path[e][1]-i.path[e-1][1]));let l=s[s.length-1];i.path=i.path.map((e,t)=>{let o=l>0?s[t]/l:t/(i.path.length-1);return[e[0]+r[0]*(1-o)+n[0]*o,e[1]+r[1]*(1-o)+n[1]*o]})}else i.path=[o,a]}}}return p}(this.scene,e,t,this.areas.length);i&&(this.cartogramLayout=i)}applyDecay(){let e=this.config.decay;if(!e||!this.pointBuffer)return;let t=this.pointBuffer.size;if(0===t)return;let i=this.scene.filter(e=>"point"===e.type),r=dA(i,this.getPoints());for(let n=0;n<i.length;n++){if(r[n]<0)continue;let o=xn(e,r[n],t);i[n]._decayOpacity=o,i[n].style={...i[n].style,opacity:o}}}applyPulse(e=this.currentTime()){let t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;let i=this.scene.filter(e=>"point"===e.type),r=this.timestampBuffer.toArray(),n=dA(i,this.getPoints()),o=t.color||"rgba(255,255,255,0.6)",a=t.glowRadius??4,s=!1;for(let l=0;l<i.length;l++){let c=r[n[l]];if(void 0===c)continue;let u=vn(t,c,e);s=wn(i[l],u,o,a)||s}return s}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&kn(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){let t=this.config.transition?.duration??300;if(t<=0)return;let i=new Map;for(let t of e)"point"===t.type&&t.pointId&&i.set(t.pointId,[t.x,t.y]);let r=this.scene.filter(e=>"point"===e.type),n=!1;for(let e of r)if(e.pointId){let t=i.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(n=!0))}for(let e of r)e.pointId&&!i.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??e.style?.fillOpacity??1,e.style={...e.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(let e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(e){if(!this.activeTransition)return!1;let n=i(e,this.activeTransition),o=t(n,this.config.transition?.easing),a=this.scene.filter(e=>"point"===e.type);for(let e of a){if(null!=e._targetX&&null!=e._targetY){let t=e.x,i=e.y;e.x=r(t,e._targetX,o),e.y=r(i,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(n>=1){for(let e of a)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};import*as UA from"react";import{jsx as ZA,jsxs as KA}from"react/jsx-runtime";function QA(e){if(!e)return;let t=[];for(let i of e)if("point"===i.type)t.push(i);else if("glyph"===i.type){let e=i,r=g(e.glyph,e.size);t.push({pointId:e.pointId,x:e.x+r.centerDx,y:e.y+r.centerDy,r:r.radius})}return t}import{jsx as JA,jsxs as eM}from"react/jsx-runtime";function tM({bottomMargin:e,costLabel:t,layout:{cx:i,cy:r,maxCost:n,availableRadius:o,layout:a},ringStyle:s,ringValues:l,showNorth:c,showRingLabels:u,showRings:d}){let h="strip"===a,p={stroke:h?"var(--semiotic-border, #999)":"#999",strokeWidth:h?1:.8,strokeDasharray:h?"none":"4,3",labelColor:"var(--semiotic-text-secondary, #777)",labelSize:h?8:10,...s};return eM("g",h?{children:[JA("line",{x1:i,y1:r,x2:i+o,y2:r,stroke:p.stroke,strokeWidth:p.strokeWidth,strokeLinecap:"round",opacity:.85}),JA("line",{x1:i,y1:r-3.5,x2:i,y2:r+3.5,stroke:p.stroke,strokeWidth:p.strokeWidth,opacity:.9}),d&&l.map(a=>{let s=i+(n>0?a/n*o:0);return eM("g",{children:[JA("line",{x1:s,y1:r-2.5,x2:s,y2:r+2.5,stroke:p.stroke,strokeWidth:.9,opacity:.65}),u&&eM("text",{x:s,y:r+Math.min(10,(e??2)+8),textAnchor:"middle",fontSize:p.labelSize,fill:p.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[a,t?` ${t}`:""]})]},a)})]}:{children:[l.map(e=>{let a=e/n*o;return eM("g",{children:[JA("circle",{cx:i,cy:r,r:a,fill:"none",stroke:p.stroke,strokeWidth:p.strokeWidth,strokeDasharray:p.strokeDasharray,opacity:.5}),u&&eM("text",{x:i+a+3,y:r-2,fontSize:p.labelSize,fill:p.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[e,t?` ${t}`:""]})]},e)}),c&&eM("g",{transform:"translate(24, 24)",children:[JA("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),JA("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),JA("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),JA("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),JA("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),JA("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}import{Fragment as iM,jsx as rM,jsxs as nM}from"react/jsx-runtime";function oM(e,t){let i=$i(e.theme),r=e.size||[e.width||600,e.height||400],n=xe({top:10,right:10,bottom:10,left:10,...e.margin},ln(e.title)),o=me(ln(e.title)),a=Array.isArray(e.areas)?Mt(e.areas):e.areas,s=Mt(e.points),l=Mt(e.lines),c=e.showLegend?(()=>{let t="string"==typeof(r=e.colorBy)||"function"==typeof r?e.colorBy:void 0,i=s.length>0?s:Array.isArray(a)&&a.length>0?"string"==typeof t?a.map(e=>({...e.properties||{},...e})):a:[];var r;return ps(i,t)})():[];Rc(n,{props:e,categories:c,theme:i,size:r,hasTitle:o});let u=Nc({props:e,categories:c,theme:i,size:r,margin:n,hasTitle:o}),d=Math.max(1,r[0]-n.left-n.right),h=Math.max(1,r[1]-n.top-n.bottom),p={projection:e.projection||"equalEarth",projectionExtent:e.projectionExtent,xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineIdAccessor:e.lineIdAccessor,lineType:e.lineType,flowStyle:e.flowStyle,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,colorScheme:e.colorScheme,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutSelection:e.layoutSelection,layoutMargin:n,onLayoutError:e.onLayoutError,themeCategorical:i.colors.categorical,themeSemantic:M(i),themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging},f=new HA(p);if(a){if("string"==typeof a)throw new Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${a}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${a}')\` before calling renderGeoToStaticSVG.`);f.setAreas(a)}e.points&&f.setPoints(s),e.lines&&f.setLines(l),f.computeScene({width:d,height:h});let g,m=Wc(e.backgroundGraphics,r,n,f.scales),y=Wc(e.foregroundGraphics,r,n,f.scales),x=ts({nodes:f.scene,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){return Ha(function(e,t){switch(e.type){case"geoarea":{let i=e;if(!i.pathData)return null;let r=ka(i.style.fill)?Sa(i.style.fill,`geoarea-${t}-hatch`):void 0;return KA(UA.Fragment,{children:[r&&ZA("defs",{children:r}),ZA("path",{d:i.pathData,fill:r?`url(#geoarea-${t}-hatch)`:za(i.style.fill,"#e0e0e0"),fillOpacity:i.style.fillOpacity??1,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth??.5,strokeDasharray:i.style.strokeDasharray,opacity:(i.style.opacity??1)*(i._decayOpacity??1)})]},`geoarea-${t}`)}case"point":{let i=e,r=ka(i.style.fill)?Sa(i.style.fill,`geopoint-${t}-hatch`):void 0;return KA(UA.Fragment,{children:[r&&ZA("defs",{children:r}),ZA("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#geopoint-${t}-hatch)`:za(i.style.fill),fillOpacity:i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i._decayOpacity??i.style.opacity??1})]},`point-${t}`)}case"line":{let i=e;if(i.path.length<2)return null;let r="M"+i.path.map(e=>`${e[0]},${e[1]}`).join("L");return ZA("path",{d:r,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth??1.5,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity??1},`line-${t}`)}case"glyph":{let i=e;return ja(i,i.x,i.y,`geo-glyph-${i.pointId??t}`)}default:return null}}(e,t),e,`geo-cursor-${t}`)}(e,t)}),b=x.map(e=>e.element),v=x.length>0&&e.cartogramChrome,w=f.cartogramLayout&&v?rM(tM,{layout:{...f.cartogramLayout,layout:f.cartogramLayout.layout??"radial"},ringValues:aM(f.cartogramLayout.maxCost,v.showRings),showRings:v.showRings??!0,showNorth:v.showNorth??!0,showRingLabels:v.showRingLabels??!0,costLabel:"string"==typeof v.costLabel?v.costLabel:void 0}):null,k=e.annotations?nc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([e,t])=>f.scales.projectedPoint(e,t):void 0},layout:{width:d,height:h},theme:i,pointNodes:QA(f.scene),idPrefix:e._idPrefix,onRender:e=>{g=e}}):null;t&&(t.evidence=ma({frameType:"geo",width:r[0],height:r[1],marks:x.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:g,legendItems:c.length>0?c.length:null!=e.legend?1:void 0,margin:n}));let S=nM(iM,{children:[m,b,k,w,y,f.customLayoutOverlays]});return sA.renderToStaticMarkup(Dc(S,{width:r[0],height:r[1],className:"stream-geo-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,markCount:x.length,idPrefix:e._idPrefix}))}function aM(e,t){if(!1===t||e<=0)return[];if(Array.isArray(t))return t.filter(t=>t>0&&t<=e);let i="number"==typeof t?t:Math.min(5,Math.max(2,Math.ceil(e/5))),r=e/i,n=[];for(let e=1;e<=i;e++)n.push(Math.round(r*e*10)/10);return n}import*as sM from"react-dom/server";function lM(e,t,i,r){return 0===i?`${e}${t}`:`${e}${t} ${i}${r}`}import{jsx as cM,jsxs as uM}from"react/jsx-runtime";var dM={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function hM(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}var pM={BigNumber:function(e,t){let i="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",r=dM[i],n=hM(e.width,r.width),o=hM(e.height,r.height),a="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):r.padding,s="center"===e.align||"end"===e.align||"start"===e.align?e.align:r.align,l="center"===s?"middle":"end"===s?"end":"start",c="center"===s?n/2:"end"===s?n-a:a,u=$i(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=function(e,t={}){if("function"==typeof e)return e;let i=t.locale??"en-US",r=t.currency??"USD";if("currency"===e){let e=t.precision??2,n=new Intl.NumberFormat(i,{style:"currency",currency:r,maximumFractionDigits:e,minimumFractionDigits:e});return e=>n.format(e)}if("percent"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("compact"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{notation:"compact",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("duration"===e)return e=>function(e){if(!Number.isFinite(e))return String(e);let t=e<0?"-":"",i=Math.abs(e),r=Math.round(i);if(r<1e3)return`${t}${r}ms`;let n=Math.round(i/10)/100;if(n<60)return`${t}${function(e){return String(Math.round(100*e)/100)}(n)}s`;let o=Math.round(i/1e3);if(o<3600)return`${t}${lM(Math.floor(o/60),"m",o%60,"s")}`;let a=Math.round(i/6e4);if(a<1440)return`${t}${lM(Math.floor(a/60),"h",a%60,"m")}`;let s=Math.round(i/36e5);return`${t}${lM(Math.floor(s/24),"d",s%24,"h")}`}(e);let n=t.precision??0,o=new Intl.NumberFormat(i,{notation:t.notation??"standard",maximumFractionDigits:n,minimumFractionDigits:0});return e=>o.format(e)}("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),p=void 0===d?"No value":function(e,t,i){return`${t??""}${e}${i??""}`}(h(d),"string"==typeof e.prefix?e.prefix:void 0,"string"==typeof e.suffix?e.suffix:void 0),f=void 0===d?void 0:function(e,t){if(!t||0===t.length||!Number.isFinite(e))return null;let i=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at),r=null;for(let t of i){if(!(e>=t.at))break;r=t}return r}(d,e.thresholds),g=f?.level??"neutral",m="string"==typeof e.color?e.color:function(e,t,i){return t||("success"===e?i.colors.success??"#2ca02c":"warning"===e?i.colors.warning??"#b26a00":"danger"===e?i.colors.danger??"#d62728":"info"===e?i.colors.info??i.colors.primary:i.colors.text)}(g,f?.color,u),y="string"==typeof e.label?e.label:void 0,x="string"==typeof e.caption?e.caption:void 0,b="string"==typeof e.unit?e.unit:void 0,v=void 0===d?void 0:function(e,t,i){let r=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,n=r&&"number"==typeof r.value&&Number.isFinite(r.value)?r.value:void 0,o=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===n?void 0:t-n);if(void 0!==o)return`${function(e,t){return Number.isFinite(e)?function(e,t){return 0===e||t(Math.abs(e))===t(0)}(e,t)?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}(o,i)}${r&&"string"==typeof r.label?` ${r.label}`:""}`}(e,d,h),w=void 0===d?void 0:function(e,t,i){let r=e.target&&"object"==typeof e.target?e.target:void 0;if(!r||"number"!=typeof r.value||!Number.isFinite(r.value))return;let n="string"==typeof r.label?` ${r.label}`:"";return 0===r.value?`target ${i(r.value)}${n}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/r.value)} of ${i(r.value)}${n}`}(e,d,h),k=[v,w,f?.label].filter(Boolean).join(" · "),S="string"==typeof e.description&&e.description||[y,p,b,k].filter(Boolean).join(", "),A="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,M="string"==typeof e.borderColor?e.borderColor:u.colors.border,$=a+r.labelSize,_=$+r.captionSize+4,P=r.showHeader&&(y||x)?x?_+10:$+14:a,I="presentation"===i?o/2+.32*r.valueSize:"thumbnail"===i?o/2+.34*r.valueSize:Math.min(o-a-(k?26:4),P+r.valueSize),T=c+("start"===l?Math.max(r.valueSize,p.length*r.valueSize*.55):0),L=String(e._idPrefix??"bignumber").replace(/[^A-Za-z0-9_-]/g,"_"),C=Mi(u,`[data-semiotic-auto="${L}"]`),R=sM.renderToStaticMarkup(uM("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:o,viewBox:`0 0 ${n} ${o}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber","data-semiotic-auto":C?L:void 0,children:[C&&cM("style",{children:C}),cM("title",{children:y??p}),"string"==typeof e.description&&cM("desc",{children:e.description}),cM("rect",{x:r.border?.5:0,y:r.border?.5:0,width:r.border?n-1:n,height:r.border?o-1:o,rx:r.border?8:0,fill:A,stroke:r.border?M:"none"}),r.showHeader&&y&&cM("text",{x:c,y:$,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.labelSize,fontWeight:600,fill:u.colors.text,children:y}),r.showHeader&&x&&cM("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.captionSize,fill:u.colors.textSecondary,children:x}),cM("text",{x:c,y:I,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:m,"data-mark-type":"value",children:p}),b&&void 0!==d&&"start"===l&&cM("text",{x:T+6,y:I,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*r.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),r.showDetail&&k&&cM("text",{x:c,y:Math.min(o-a,I+r.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.detailSize,fill:u.colors.textSecondary,children:k})]}));return t&&(t.evidence=ma({frameType:"value",width:n,height:o,marks:void 0===d?[]:[{type:"value"}],title:y,description:S})),R}};function fM(e,t,i){return pM[e](t,i)}import*as gM from"react-dom/server";import{jsx as mM,jsxs as yM}from"react/jsx-runtime";import{Fragment as xM,jsx as bM}from"react/jsx-runtime";function vM(e,t){return Pc(t,i=>function(e,t,i){let r;switch(e){case"xy":r=Qc(t);break;case"ordinal":r=aA(t);break;case"network":r=_v(t);break;case"geo":r=oM(t);break;case"physics":r=Kv(t);break;default:throw new Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}return Ke(r,i)}(e,{...t,_idPrefix:i},i))}function wM(e){return vM("xy",e)}function kM(e){return vM("ordinal",e)}function SM(e){return vM("network",e)}function AM(e){return vM("geo",e)}var MM=/*#__PURE__*/new Set(["d","transform","gradientTransform","patternTransform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-dasharray","stroke-dashoffset","font-size","letter-spacing"]),$M=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function _M(e,t){let i=Number(e);if(!Number.isFinite(i))return e;let r=10**t,n=Math.round((i+Number.EPSILON)*r)/r;return String(n)}function PM(e,t,i=0,r=!1){let n,o=new RegExp($M.source,$M.flags),a="",s=0,l=!1,c=0,u=!1,d=0;for(;n=o.exec(e);){let h=e.slice(s,n.index);r&&/[a-df-z]/i.test(h)&&(u=/a[^a-df-z]*$/i.test(h),d=0);let p=n[0],f=d++%7;if(u&&(3===f||4===f)){if(p=p[0],"0"!==p&&"1"!==p)return e;o.lastIndex=n.index+1}l&&0===h.length?a+=" ":a+=h,a+=_M(p,c++<i?Math.max(8,t):t),s=n.index+p.length,l=!0}return a+e.slice(s)}function IM(e,t){let i=function(e){if(Number.isFinite(e))return Math.max(0,Math.min(8,Math.floor(e)))}(t);return void 0===i?e:We(e,(e,t)=>{if(MM.has(e)&&!/\b(?:var|calc|url)\(/i.test(t))return"transform"===e||"gradientTransform"===e||"patternTransform"===e?t.replace(/(matrix|translate|scale|rotate|skewX|skewY)\(([^)]*)\)/g,(e,t,r)=>`${t}(${PM(r,i,"matrix"===t?4:"scale"===t?2:"translate"===t?0:1)})`):PM(t,e.startsWith("stroke-")?Math.max(2,i):i,0,"d"===e)})}var TM=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations","perspective"],LM=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function CM(e,t){let i={};for(let r of t)void 0!==e[r]&&(i[r]=e[r]);return i}function RM(e,t,i){return DM(e,t,i).svg}function NM(e,t,i){let r={},{svg:n,frameType:o}=DM(e,t,i,r),a=r.evidence??ma({frameType:o,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]}),s=t.theme;if("string"==typeof s&&!$(s)&&a.warnings.push("UNKNOWN_THEME"),a.component=e,a.sceneHashVersion=2,a.sceneHash=function(e,t){let i=new Map;return We(e,(e,t)=>{"id"===e&&!i.has(t)&&i.set(t,`\0scene-${i.size}`)}),F({kind:"semiotic.rendered-svg-scene",version:2,svg:Ze(e,i),frameType:t.frameType,width:t.width,height:t.height,margin:t.margin,plot:t.plot,xDomain:t.xDomain,yDomain:t.yDomain,categories:t.categories})}(n,a),bt(a,e,t),i?.artifactContract){let r=E(i.artifactContract,{excludeEvidenceSamples:!0});r.contract&&(a.artifactContract=r.contract),a.artifactTransfer=r.transfer,a.artifactBinding="0.1"===r.contract?.contractVersion&&"invalid"!==r.transfer.status?O(r.contract,t,e):{status:"unknown",mismatchPaths:[],unknownPaths:["artifactContract"]}}return{svg:n,evidence:a}}function DM(e,t,i,r){let n="xy";return{svg:Pc(t,o=>{let a=function(e,t,i,r,n){if(Object.prototype.hasOwnProperty.call(pM,e))return{svg:IM(Ke(fM(e,t,n),i),r?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(iS,e))throw new Error(`Unknown chart component: "${e}". Run \`npx -p semiotic semiotic-ai --list\` for supported chart types.`);let o,a=iS[e],s=a.layout?.mode??(!dt(e)&&function(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(nt,e)}(t.mode)?t.mode:void 0),l=function(e,t,i){let r=nt[e||"primary"],n=e&&"primary"!==e||!i?.width?r.width:i.width,o=e&&"primary"!==e||!i?.height?r.height:i.height,a=function(e,t,i=e.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:e,matches:[]};let r=i.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){let{when:i}=e,r=t.width,n=t.height,o=function(e){if(!("number"!=typeof e.height||e.height<=0))return e.width/e.height}(t),a=function(e){if(!("number"!=typeof e.height||e.height<=0))return e.width>=e.height?"landscape":"portrait"}(t);return!("number"==typeof i.minWidth&&r<i.minWidth||"number"==typeof i.maxWidth&&r>i.maxWidth||"number"==typeof i.minHeight&&("number"!=typeof n||n<i.minHeight)||"number"==typeof i.maxHeight&&("number"!=typeof n||n>i.maxHeight)||"number"==typeof i.minAspectRatio&&("number"!=typeof o||o<i.minAspectRatio)||"number"==typeof i.maxAspectRatio&&("number"!=typeof o||o>i.maxAspectRatio)||i.orientation&&a!==i.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:r.reduce((e,t)=>function(e,t){let i={...e,...t};for(let r of["margin","frameProps","mobileSemantics","style"])tt(e[r])&&tt(t[r])&&(i[r]={...e[r],...t[r]});return"string"==typeof e.className&&"string"==typeof t.className&&(i.className=`${e.className} ${t.className}`),i}(e,t.rule.transform),e),matches:r}}({...t,mode:e},{width:t.width??n,height:t.height??o}).props,s=a.mode||e||"primary",l=nt[s],c="context"===s||"sparkline"===s,u="primary"===s&&i?.width?i.width:l.width,d="primary"===s&&i?.height?i.height:l.height;return{mode:s,width:a.width??u,height:a.height??d,showAxes:a.showAxes??l.showAxes,showGrid:a.showGrid??l.showGrid,enableHover:a.enableHover??(!!a.linkedHover||l.enableHover),showLegend:a.showLegend??l.showLegend,showLabels:a.showLabels??l.showLabels,title:c?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:c?void 0:a.xLabel,yLabel:c?void 0:a.yLabel,categoryLabel:c?void 0:a.categoryLabel,valueLabel:c?void 0:a.valueLabel,marginDefaults:ot(l.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:c,mobileInteraction:rt(a.mobileInteraction,{mode:s,width:a.width??u,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(s,{...a.layout?.modeDefaults,...CM(t,LM),...dt(e)&&{responsiveRules:void 0}},function(e){return Object.prototype.hasOwnProperty.call(ut,e)?ut[e]:void 0}(e)??a.layout?.primarySize),{data:c,theme:u,background:d,className:h,annotations:p,margin:f,colorScheme:g,colorBy:m,legendPosition:y,...x}=t,{width:b,height:v}=l,w=[b,v],k=x.frameProps||{},S=a.layout?.margin,A="function"==typeof S?S(t,l):S??l.marginDefaults,M="xy"===a.frameType?De(A,x.axes??k.axes,!!l.title):A,$=void 0!==f?f:k.margin,_=function(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};let t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}($),P="number"==typeof $?{top:$,right:$,bottom:$,left:$}:{...M,..._},I=CM(x,TM),T=e=>k[e]??l[e],L={...k,...I,theme:u,title:l.title,description:l.description,showAxes:T("showAxes"),showLegend:T("showLegend"),showLabels:T("showLabels"),showGrid:T("showGrid"),xLabel:T("xLabel"),yLabel:T("yLabel"),categoryLabel:T("categoryLabel"),valueLabel:T("valueLabel"),background:d??k.background,className:h,annotations:p,size:w,margin:P,__resolvedMode:l.mode,__compactMode:l.compactMode,__explicitMarginSides:"number"==typeof $?["top","right","bottom","left"]:Object.keys(_??{}),__autoLegendMargin:!0,...void 0!==g&&{colorScheme:g},...void 0!==y&&{legendPosition:y},_idPrefix:x._idPrefix},C=a.buildProps(c,m,g,L,x);if(a.renderStatic)o=a.renderStatic(C,n);else switch(a.frameType){case"xy":o=Qc(C,n);break;case"ordinal":o=aA(C,n);break;case"network":o=_v(C,n);break;case"geo":o=oM(C,n);break;case"physics":o=Kv({...C,physicsTheme:k.theme,frameBodyStyle:k.bodyStyle},n)}let R=a.renderOverlay?.(C,{theme:$i(u)});if(null!=R){let e=vt.renderToStaticMarkup(bM(xM,{children:R})),t=o.lastIndexOf("</svg>");o=t<0?`${o}${e}`:`${o.slice(0,t)}${e}${o.slice(t)}`}return{svg:IM(Ke(o,i),r?.precision),frameType:a.resolveFrameType?.(C)??a.frameType}}(e,{...t,_idPrefix:o},o,i,r);return n=a.frameType,a.svg}),frameType:n}}function FM(e,t={}){return function(e,t,i){return Rl("dashboard",r=>function(e,t,i,r){let{title:n,subtitle:o,theme:a,width:s,height:l,layout:c={},background:u}=t,d=_i($i(a)),h=Qe(s,1200),p=Math.max(1,Math.floor(Qe(c.columns,2))),f=Math.min("number"==typeof c.gap&&Number.isFinite(c.gap)&&c.gap>=0?c.gap:16,h/(p+1)),g=0;n&&(g+=30),o&&(g+=20),g>0&&(g+=10);let m=h-f,y=Math.floor((m-f*(p-1))/p),x=[],b=0,v=g+f,w=0;for(let t of e){let e=Math.min(Math.max(1,Math.floor(Qe(t.colSpan,1))),p),n=y*e+f*(e-1),o=Qe(t.props.height,300);b+e>p&&(v+=w+f,b=0,w=0);let s=f/2+b*(y+f),l={...t.props,width:n,height:o,theme:a,_idPrefix:`${r}-chart-${x.length}${t.props._idPrefix?`-${String(t.props._idPrefix).replace(/[^a-zA-Z0-9_-]/g,"_")}`:""}`},c=t.component?i.chart(t.component,l):t.frameType?i.frame(t.frameType,l):gM.renderToStaticMarkup(mM("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:o})),u=Je(c,{width:n,height:o}),d=Math.max(o,u.height);x.push({x:s,y:v,width:n,height:d,svg:c,svgDimensions:u}),w=Math.max(w,d),b+=e}let k=Qe(l,v+w+f),S=x.map((e,t)=>mM("g",{transform:`translate(${e.x},${e.y})`,dangerouslySetInnerHTML:{__html:Ye(et(e.svg,e.svgDimensions),{width:String(e.width),height:String(e.height),role:"group"})}},`dashboard-chart-${t}`));return gM.renderToStaticMarkup(yM("svg",{xmlns:"http://www.w3.org/2000/svg",width:h,height:k,role:"group","aria-label":n||"Dashboard","aria-describedby":o?`${r}-desc`:void 0,style:{fontFamily:d.fontFamily},children:[n&&mM("title",{children:n}),o&&mM("desc",{id:`${r}-desc`,children:o}),u&&mM("rect",{x:0,y:0,width:h,height:k,fill:u}),n&&mM("text",{x:h/2,y:24,textAnchor:"middle",fontSize:d.titleFontSize+4,fontWeight:d.titleFontWeight,fill:d.text,fontFamily:d.titleFontFamily,children:n}),o&&mM("text",{x:h/2,y:n?46:20,textAnchor:"middle",fontSize:d.labelSize,fill:d.textSecondary,fontFamily:d.fontFamily,children:o}),S]}))}(e,t,i,r))}(e,t,{chart:RM,frame:vM})}var EM=2*Math.PI,OM=e=>(e%EM+EM)%EM;function zM(e,t){let i=1-t;return i**3*e[0]+3*i*i*t*e[1]+3*i*t*t*e[2]+t**3*e[3]}function BM(e,t){let i=e.map(e=>e[0]),r=e.map(e=>e[1]);t(i[0],r[0]),t(i[3],r[3]);for(let e of[i,r]){let n=-e[0]+3*e[1]-3*e[2]+e[3],o=2*(e[0]-2*e[1]+e[2]),a=e[1]-e[0],s=Math.abs(n)<1e-12?0===o?[]:[-a/o]:o*o-4*n*a<0?[]:[(-o+Math.sqrt(o*o-4*n*a))/(2*n),(-o-Math.sqrt(o*o-4*n*a))/(2*n)];for(let e of s)e>0&&e<1&&t(zM(i,e),zM(r,e))}}function jM(e,t,i,r){let[n,o]=i.map(Math.abs);if(r(...e),r(...t),0===n||0===o||e[0]===t[0]&&e[1]===t[1])return;let a=i[2]*Math.PI/180,s=Math.cos(a),l=Math.sin(a),c=(e[0]-t[0])/2,u=(e[1]-t[1])/2,d=s*c+l*u,h=-l*c+s*u,p=Math.hypot(d/n,h/o);p>1&&(n*=p,o*=p);let f=(d/n)**2+(h/o)**2,g=(i[3]===i[4]?-1:1)*Math.sqrt(Math.max(0,(1-f)/f)),m=g*n*h/o,y=-g*o*d/n,x=s*m-l*y+(e[0]+t[0])/2,b=l*m+s*y+(e[1]+t[1])/2,v=Math.atan2((h-y)/o,(d-m)/n),w=Math.atan2((-h-y)/o,(-d-m)/n),k=i[4]?OM(w-v):-OM(v-w),S=Math.atan2(-o*l,n*s),A=Math.atan2(o*s,n*l);for(let e of[S,S+Math.PI,A,A+Math.PI])OM(k>=0?e-v:v-e)<=Math.abs(k)+1e-12&&r(x+n*s*Math.cos(e)-o*l*Math.sin(e),b+n*l*Math.cos(e)+o*s*Math.sin(e))}function WM(e){let t=0,i="",r="",n=[0,0],o=[0,0],a=[0,0],s=1/0,l=1/0,c=-1/0,u=-1/0,d=(e,t)=>{s=Math.min(s,e),l=Math.min(l,t),c=Math.max(c,e),u=Math.max(u,t)},h=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t++},p=(i=!1)=>{h();let r=i?/^[01]/.exec(e.slice(t)):/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));return r?(t+=r[0].length,Number(r[0])):NaN};for(;t<e.length&&(h(),t!==e.length);){/[a-z]/i.test(e[t])&&(i=e[t++]);let s=i.toUpperCase(),l=i!==s;if(!r&&"M"!==s)return null;if("Z"===s){d(...n),d(...o),n=[...o],r="Z",i="";continue}let c={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7}[s];if(!c)return null;let u=Array.from({length:c},(e,t)=>p("A"===s&&(3===t||4===t)));if(!u.every(Number.isFinite))return null;let h=e=>[u[e]+(l?n[0]:0),u[e+1]+(l?n[1]:0)],f="H"===s?[u[0]+(l?n[0]:0),n[1]]:"V"===s?[n[0],u[0]+(l?n[1]:0)]:h(c-2),g=[2*n[0]-a[0],2*n[1]-a[1]];if("C"===s||"S"===s){let e="C"===s?h(0):/[CS]/.test(r)?g:n;a=h(c-4),BM([n,e,a,f],d)}else"Q"===s||"T"===s?(a="Q"===s?h(0):/[QT]/.test(r)?g:n,BM([n,[n[0]+2*(a[0]-n[0])/3,n[1]+2*(a[1]-n[1])/3],[f[0]+2*(a[0]-f[0])/3,f[1]+2*(a[1]-f[1])/3],f],d)):"A"===s?jM(n,f,u,d):"M"!==s&&(d(...n),d(...f));n=f,"M"===s&&(o=[...f],i=l?"l":"L"),r=s}return[s,l,c,u].every(Number.isFinite)?{x:s,y:l,w:c-s,h:u-l}:null}function YM(e){return[e.x,e.y,e.width,e.height].every(Number.isFinite)&&e.width>0&&e.height>0}function qM(e,t){let i,{width:r,height:n,view:o="fit",padding:a,bounds:s}=t;if(![r,n].every(e=>Number.isFinite(e)&&e>0))throw new Error("exportNetworkViewSVG requires finite positive width and height");if("fit"===o){let t=s??function(e){if(!e)return null;let t=[...e.htmlMarks??[]];for(let i of e.sceneNodes??[]){if("rect"===i.type){t.push({x:i.x,y:i.y,width:i.w,height:i.h});continue}let e;if("glyph"===i.type)e=h(i.glyph,i.size);else if("circle"===i.type)e=i.r;else if("arc"===i.type)e=i.outerR;else if(i.path||i.symbolType&&"circle"!==i.symbolType){let t=WM(l(i.symbolType,i.size,i.path));e=t?Math.hypot(Math.max(Math.abs(t.x),Math.abs(t.x+t.w)),Math.max(Math.abs(t.y),Math.abs(t.y+t.h))):c(i.size)}else e=c(i.size);t.push({x:i.cx-e,y:i.cy-e,width:2*e,height:2*e})}return function(e){let t=1/0,i=1/0,r=-1/0,n=-1/0;for(let o of e)!o||!YM(o)||(t=Math.min(t,o.x),i=Math.min(i,o.y),r=Math.max(r,o.x+o.width),n=Math.max(n,o.y+o.height));return t<1/0?{x:t,y:i,width:r-t,height:n-i}:null}(t)}(e);if(t&&!YM(t))throw new Error("exportNetworkViewSVG bounds must be finite with positive width and height");i=t?function(e,t,i,r=[Number.MIN_VALUE,Number.MAX_VALUE]){if(!YM(e)||t.width<=0||t.height<=0)return null;let{top:n,right:o,bottom:a,left:s}=function(e,t=0){let i=e=>Number.isFinite(e)?Math.max(0,e):t;if("object"!=typeof e||null===e){let t=i(e??void 0);return{top:t,right:t,bottom:t,left:t}}return{top:i(e.top),right:i(e.right),bottom:i(e.bottom),left:i(e.left)}}(i,24),l=Math.max(r[0],Math.min(r[1],Math.max(1,t.width-(s+o))/e.width,Math.max(1,t.height-(n+a))/e.height));return{k:l,x:t.x+(t.width+(s-o))/2-(e.x+e.width/2)*l,y:t.y+(t.height+(n-a))/2-(e.y+e.height/2)*l}}(t,{x:0,y:0,width:r,height:n},a)??void 0:void 0}else"identity"!==o&&(i=o);return Ye(RM("NetworkCustomChart",{width:r,height:n,margin:0,nodes:[],edges:[],layout:()=>({...e,restyle:void 0,restyleEdge:void 0}),frameProps:{viewTransform:i}}),{viewBox:`0 0 ${r} ${n}`})}import*as XM from"react-dom/server";import{jsx as GM,jsxs as VM}from"react/jsx-runtime";function HM(e,t,i,r={}){let{stepSize:n,windowSize:o,frameCount:a,xExtent:s,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=r,p=i.width||600,f=i.height||400,g=$i(i.theme),m={...i,...s&&{xExtent:s},...l&&{yExtent:l}};if(!t||0===t.length)return[];let y=a||Math.min(60,Math.max(10,t.length)),x=n||Math.max(1,Math.ceil(t.length/y)),b=[];for(let e=x;e<=t.length;e+=x)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);let v=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),w=xe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),k=Math.max(1,p-w.left-w.right),S=Math.max(1,f-w.top-w.bottom),A=[];if(v)for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,s=t.slice(a,n),l={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:i.projection||"vertical",oAccessor:i.oAccessor||i.categoryAccessor||"category",rAccessor:i.rAccessor||i.valueAccessor||"value",colorAccessor:i.colorAccessor||i.colorBy,stackBy:i.stackBy,groupBy:i.groupBy,connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,barPadding:i.barPadding,innerRadius:i.innerRadius,normalize:i.normalize,bins:i.bins,colorScheme:i.colorScheme||g.colors.categorical,...h&&{decay:h}},c=new ES(l);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:k,height:S}),c.scene.length>0&&A.push(JM(c.scene,"ordinal",p,f,g,m,A.length))}else for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,y=t.slice(a,n),x={chartType:e,windowSize:y.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:i.colorAccessor||i.colorBy,groupAccessor:i.groupAccessor||i.lineBy,lineDataAccessor:i.lineDataAccessor,xExtent:s,yExtent:l,colorScheme:i.colorScheme||g.colors.categorical,lineStyle:i.lineStyle,pointStyle:i.pointStyle,areaStyle:i.areaStyle,sizeAccessor:i.sizeAccessor||i.sizeBy,sizeRange:i.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},v=new To(x);if(v.ingest({inserts:y,bounded:!0}),v.computeScene({width:k,height:S}),0===v.scene.length)continue;let w=v.scales?.y;if(A.push(JM(v.scene,"xy",p,f,g,m,A.length,w)),c>0&&r>0&&v.activeTransition){let e=c*(1e3/u);for(let t=1;t<=c;t++){let i=t/c,r=v.activeTransition.startTime+i*e;v.advanceTransition(r),A.push(JM(v.scene,"xy",p,f,g,m,A.length,w))}}}return A}function UM(e,t,i={}){return t.map((t,r)=>{try{return RM(e,{...i,...t})}catch(n){return"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Failed to render snapshot ${r} for ${e}.`,n),`<svg xmlns="http://www.w3.org/2000/svg" width="${Qe(t.width,Qe(i.width,600))}" height="${Qe(t.height,Qe(i.height,400))}"></svg>`}})}function ZM(e,t,i,r){let n=sc(`${e}-${t}`),o="string"==typeof i&&i.length>0?i:void 0,a="string"==typeof r&&r.length>0?r:void 0,s=o?n.titleId:void 0,l=a?n.descId:void 0;return{titleText:o,descText:a,titleId:s,descId:l,labelledBy:[s,l].filter(Boolean).join(" ")||void 0}}function KM(e,t,i){let r=t.size??[t.width??600,t.height??400],n=$i(t.theme),o=_i(n),a=t.background||n.colors.background,s=t.idPrefix??"physics-gif",l=ZM(s,i,t.title,t.description),{titleId:c,descId:u,labelledBy:d}=l,h=e.readBodies(),p=e.viewTransform(),f=Cv(h,{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),g=VM("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,role:"img","aria-labelledby":d,style:{fontFamily:o.fontFamily},children:[t.title&&GM("title",{id:c,children:t.title}),t.description&&GM("desc",{id:u,children:t.description}),a&&"transparent"!==a?GM("rect",{x:0,y:0,width:r[0],height:r[1],fill:a}):null,GM("g",{id:`${s}-frame-${i}`,transform:p.x||p.y?`translate(${p.x},${p.y})`:void 0,children:f.map((e,t)=>yh(h[t],e.style??{},t,`${s}-${i}`)??Qa(e,t,`${s}-${i}`))})]});return XM.renderToStaticMarkup(g)}function QM(e,t={}){let{fps:i=12,frameCount:r,durationSeconds:n=2,includeInitialFrame:o=!0,stepDt:a,stepsPerFrame:s,background:l}=t,c=Math.max(.001,a??e.config?.fixedDt??1/120),u=s??Math.max(1,Math.round(1/Math.max(1,i)/c)),d=r??Math.max(1,Math.ceil(n*Math.max(1,i))),h=l?{...e,background:l}:e,p=new Tf(e.config);e.initialSpawns?.length&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);let f=[];for(o&&(p.tick(0),f.push(KM(p,h,0)));f.length<d;){for(let e=0;e<u;e+=1)p.tick(c);f.push(KM(p,h,f.length))}return f}function JM(e,t,i,r,n,o,a,s){let l=_i(n),c=xe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),u="ordinal"===t&&"radial"===o.projection,d=u?c.left+(i-c.left-c.right)/2:c.left,h=u?c.top+(r-c.top-c.bottom)/2:c.top,p=function(e,t){let i=e.background||t.colors.background;return i&&"transparent"!==i?i:null}(o,n),f=o.renderMode,g="ordinal"===t?tA({nodes:e,renderMode:f,idPrefix:o.idPrefix}).map(e=>e.element):e.map((e,t)=>function(e){return es(e).element}({node:e,index:t,renderMode:f,fallback:()=>Qa(e,t)})).filter(Boolean),m="xy"===t?function(e,t,i,r,n,o){if(!e||0===e.length)return null;let a=_i(r),s=[];for(let r=0;r<e.length;r++){let l=e[r];if("y-threshold"===l.type&&null!=l.value){let e=null;if(o)e=o(l.value);else if(n){let[t,r]=n,o=r-t;if(0===o)continue;e=i-(l.value-t)/o*i}if(null==e)continue;let c=l.color||a.primary,u=l.strokeDasharray||"6,4",d=l.strokeWidth??1.5,h=l.labelPosition||"right";s.push(VM("g",{children:[GM("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:d,strokeDasharray:u}),l.label&&GM("text",{x:"left"===h?4:"center"===h?t/2:t-4,y:e<20?Math.min(i-4,e+16):e-5,textAnchor:"left"===h?"start":"center"===h?"middle":"end",fontSize:a.tickSize,fill:l.labelColor??c,fontFamily:a.fontFamily,children:l.label})]},`ann-${r}`))}}return s}(o.annotations,Math.max(1,i-c.left-c.right),Math.max(1,r-c.top-c.bottom),n,o.yExtent,s):null,{titleText:y,descText:x,titleId:b,descId:v,labelledBy:w}=ZM(function(e){return"string"==typeof e.idPrefix&&e.idPrefix.length>0?e.idPrefix:_c(e)}(o),a,o.title,o.description),k=VM("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,role:"img","aria-labelledby":w,style:{fontFamily:l.fontFamily},children:[y&&GM("title",{id:b,children:y}),x&&GM("desc",{id:v,children:x}),p&&GM("rect",{x:0,y:0,width:i,height:r,fill:p}),VM("g",{transform:`translate(${d},${h})`,children:[m,g]}),y&&GM("text",{x:i/2,y:22,textAnchor:"middle",fontSize:l.titleFontSize,fontWeight:l.titleFontWeight,fill:l.text,fontFamily:l.titleFontFamily,children:y})]});return XM.renderToStaticMarkup(k)}ha(),Sn=o;export{qM as exportNetworkViewSVG,HM as generateFrameSVGs,UM as generateFrameSequence,QM as generatePhysicsFrameSVGs,RM as renderChart,NM as renderChartWithEvidence,FM as renderDashboard,AM as renderGeoToStaticSVG,SM as renderNetworkToStaticSVG,kM as renderOrdinalToStaticSVG,vM as renderToStaticSVG,wM as renderXYToStaticSVG,$i as resolveTheme,IM as serializeSvgPrecision,_i as themeStyles};
1
+ import{b as e}from"./c-ZMYO3NZU.min.js";import{a as t,b as i,c as r,d as n,e as o,l as a}from"./c-BQWX6NBX.min.js";import{a as s,b as l}from"./c-ASTHXHRY.min.js";import{a as c,b as u,c as d,d as h,e as p,f,g,h as m,q as y,s as x}from"./c-YQEVPOMV.min.js";import{a as b}from"./c-YWZBFG63.min.js";import{a as v}from"./c-CBRSDPFG.min.js";import{A as w,C as S,a as k,b as A,e as M,f as $,h as _,i as P}from"./c-LW3GP7RY.min.js";import{A as I,B as T,C as L,D as C,E as R,F as N,G as D,H as F,I as E,a as O,d as z,i as B,j,k as W,l as Y,m as q,n as X,o as G,p as V,q as H,r as U,s as Z,t as K,u as Q,v as J,w as ee,x as te,y as ie,z as re}from"./c-2AURU3I6.min.js";import{a as ne,b as oe,c as ae,e as se,f as le,g as ce}from"./c-F5V47CBH.min.js";import{a as ue,b as de,c as he}from"./c-5H6IMPPV.min.js";function pe(e){let t=e?.find(e=>"bottom"===e.orient),i=e?.find(e=>"top"===e.orient),r=e?.find(e=>"left"===e.orient),n=e?.find(e=>"right"===e.orient);return{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n,xAxis:t??i,yAxis:r??n,xOrient:t||!i?"bottom":"top",yOrient:r||!n?"left":"right"}}function fe(e){let t=6;for(let i=1;i<e.length;i++){let r=Math.abs(e[i]-e[i-1]);if(r>0&&Number.isFinite(r)){let n=Math.max(Math.abs(e[i]),Math.abs(e[i-1]));t=Math.max(t,Math.ceil(Math.log10(n/r))+1)}}let i=Math.min(17,t);return e=>Number.isInteger(e)?String(e):String(Number(e.toPrecision(i)))}function ge(...e){let t;for(let i of e)i&&(t=me(t)&&me(i)?{legendGroups:[...t.legendGroups,...i.legendGroups],legendDistance:i.legendDistance??t.legendDistance}:i);return t}function me(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function ye(e){return"object"==typeof e&&null!==e&&"gradient"in e}function xe(e){return"string"==typeof e&&e.length>0}function be(e,t){let i=t?36:0;return e.top>=i?e:{...e,top:i}}function ve(e,t){return be(e,xe(t))}function we(e,t,i,r,n=8){let o="left"===r||"right"===r,a=r,s="left"===r?"right":"right"===r?"left":"top"===r?"bottom":"top",l=Math.max(0,(o?i[0]:i[1])-n),c=Math.max(t[a],l-e[s]);e[a]>c&&(e[a]=c)}function Se(e){return Math.ceil(7*e.length)}function ke(e,t){if(me(e)){let i=De(t),r=100;for(let t of e.legendGroups){t.label&&(r=Math.max(r,Se(t.label)));for(let e of t.items)r=Math.max(r,i.swatchSize+i.labelGap+Se(e.label))}return r}if(ye(e)){let{gradient:t}=e,i=t.format||fe(t.domain),r=Math.max(Se(i(t.domain[0])),Se(i(t.domain[1]))),n=t.label?Se(t.label):0;return Math.max(100,19+r,n)}return 100}function Ae(e){return(me(e)||ye(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):10}function Me(e,t){return null!=e?.sideGutter?Math.max(0,e.sideGutter):t?.hasAxis?t.hasAxisLabel?Pe:_e:0}function $e(e){return Math.max(0,e?.edgeGutter??3)}var _e=34,Pe=70;function Ie(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?64:46:22:0}function Te(e){let{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n}=pe(e.axes),o=!(i&&!t||!1===t?.visible),a=!!i&&!t&&!1!==i.visible,s=!(n&&!r||!1===r?.visible),l=!!n&&!1!==n.visible,c=!1!==e.showAxes;return{hasAxis:c&&o,hasAxisLabel:c&&o&&!!(t?.label??e.xLabel),rotatedTicks:c&&o&&(e.rotatedTicks??!!t?.autoRotate),topAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??e.xLabel),rotatedTicks:c&&(e.rotatedTicks??!!i?.autoRotate)}:void 0,leftAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(r?.label??e.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??e.yLabelRight??e.yLabel)}:void 0}}function Le(e,t,i){if(ye(e))return e.gradient.label?46:26;if(!me(e))return 20;let r=De(i),n=Math.max(1,i?.maxWidth??t),o=r.rowHeight;for(let t of e.legendGroups){let e=0,i=0;for(let o of t.items){let t=r.swatchSize+r.labelGap+Se(o.label),a=0===i?t:i+r.itemGap+t;i>0&&a>n?(e+=1,i=t):i=a}t.items.length>0&&(e+=1),o=Math.max(o,e*r.rowHeight,t.label?Se(t.label):0)}return o+(e.legendGroups.length>1?16:0)}function Ce(e,t,i){return ke(e,t)+Ae(e)+Me(t,i)+$e(t)}function Re(e,t){let{legend:i}=t;if(!i)return;let r=t.position??"right",n=Le(i,Math.max(1,t.size[0]-e.left-e.right),t.legendLayout)+Ae(i)+Ie("bottom"===r?t.axisChrome:"top"===r?t.axisChrome?.topAxis:void 0,t.legendLayout)+("top"===r&&t.hasTitle?24:0),o=Math.max(t.minimumMargin??0,"top"===r?t.hasTitle?58:34:0);"right"===r?e.right=Math.max(e.right,o,Ce(i,t.legendLayout,t.axisChrome?.rightAxis)):"left"===r?e.left=Math.max(e.left,o,Ce(i,t.legendLayout,t.axisChrome?.leftAxis)):"top"===r?e.top=Math.max(e.top,o,n):e.bottom=Math.max(e.bottom,o,n)}function Ne(e,t){let i=t.position??"right",r="top"===i||"bottom"===i,n=Math.max(0,t.totalWidth-t.margin.left-t.margin.right),o=Math.max(1,r?t.legendLayout?.maxWidth??n:t.reservedWidth??ke(e,t.legendLayout)),a=Ae(e),s=Me(t.legendLayout,"left"===i?t.axisChrome?.leftAxis:t.axisChrome?.rightAxis),l=$e(t.legendLayout),c=Le(e,n,t.legendLayout),u=Ie(t.axisChrome,t.legendLayout),d=Ie(t.axisChrome?.topAxis,t.legendLayout);if("left"===i)return{x:Math.max(l,t.margin.left-s-o-a),y:t.margin.top,width:o,height:c};if("top"===i)return{x:t.margin.left,y:t.margin.top-d-a-c,width:o,height:c};if("bottom"===i){let e=t.totalHeight-t.margin.bottom;return{x:t.margin.left,y:Math.max(e+a,Math.min(e+u+a,t.totalHeight-c)),width:o,height:c}}return{x:Math.min(t.totalWidth-o-l,t.totalWidth-t.margin.right+s+a),y:t.margin.top,width:o,height:c}}function De(e){let t=Math.max(1,e?.swatchSize??16),i=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:i,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}function Fe(e,t){let i=24;return e.map(({hasLabel:e,itemCount:r})=>{i+=5;let n,o=i;i+=8,e&&(i+=16,n=i,i+=8);let a=i;return i+=r*t+8,{lineY:o,labelY:n,itemsY:a,endY:i}})}function Ee(e,t,i=!1){let r={...e};for(let e of t??[])!1===e.visible&&("top"!==e.orient||!i)&&(r[e.orient]=0);return r}var Oe=/\s+([^\s=<>/'"]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function ze(e){let t=0;for(;t<e.length;){let i=/^\s+/.exec(e.slice(t));i&&(t+=i[0].length);let r=e.startsWith("\x3c!--",t)?"--\x3e":e.startsWith("<?",t)?"?>":void 0;if(r){let i=e.indexOf(r,t+2);if(i<0)return;t=i+r.length;continue}if(/^<!DOCTYPE\s/i.test(e.slice(t))){let i="",r=0,n=t+9;for(;n<e.length;n+=1){let t=e[n];if(i)t===i&&(i="");else if(e.startsWith("\x3c!--",n)){let t=e.indexOf("--\x3e",n+4);if(t<0)return;n=t+2}else if('"'===t||"'"===t)i=t;else if("["===t)r+=1;else if("]"===t)r-=1;else if(">"===t&&0===r)break}if(n===e.length)return;t=n+1;continue}break}let i=/^<((?:[A-Za-z_][\w.-]*:)?svg)(?=[\s/>])((?:[^<>"']|"[^"]*"|'[^']*')*)>/i.exec(e.slice(t));if(!i)return;let r=i[2].endsWith("/"),n=r?i[2].slice(0,-1):i[2];return n.replace(Oe,"").trim()?void 0:{start:t,end:t+i[0].length,name:i[1],attributes:n,selfClosing:r}}function Be(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;")}function je(e){return e.replace(/&(amp|quot|apos|lt|gt|#\d+|#x[\da-fA-F]+);/g,(e,t)=>{if(!t.startsWith("#"))return{amp:"&",quot:'"',apos:"'",lt:"<",gt:">"}[t];let i=t.startsWith("#x")?parseInt(t.slice(2),16):Number(t.slice(1));return i>0&&i<=1114111?String.fromCodePoint(i):e})}function We(e){return je(e.replace(/\r\n|[\t\r\n]/g," "))}function Ye(e,t){for(let i of e.attributes.matchAll(Oe))if(i[1]===t)return We(i[2]??i[3])}function qe(e,t){let i=ze(e)?.start??0;return e.slice(0,i)+e.slice(i).replace(/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,(e,i)=>i?e.replace(Oe,(e,i,r,n)=>{let o=t(i,We(r??n));return void 0===o?e:` ${i}="${Be(o)}"`}):e)}function Xe(e,t){let i=ze(e);if(!i)return e;let r=new Map(Object.entries(t)),n=i.attributes.replace(Oe,(e,t)=>{let i=r.get(t);return void 0===i?e:(r.delete(t),` ${t}="${Be(i)}"`)});for(let[e,t]of r)n+=` ${e}="${Be(t)}"`;return`${e.slice(0,i.start)}<${i.name}${n}${i.selfClosing?"/":""}>${e.slice(i.end)}`}function Ge(e,t,i,r){let n=e=>i.get(e)??e;return"id"===e?n(t):/^(?:xlink:?)?href$/i.test(e)?"#"===t[0]?`#${n(t.slice(1))}`:t:/^(?:aria-(?:labelledby|describedby|controls|owns|activedescendant|details|errormessage)|for|htmlFor|list|form|headers|itemref|popovertarget)$/.test(e)?t.replace(/\S+/g,n):/^(?:fill|stroke|clip-?path|mask|filter|marker-?(?:start|mid|end)|style|cursor)$/i.test(e)?r?r(t,i):t.replace(/url\(\s*(["']?)#([^\s"')]+)\1\s*\)/g,(e,t,i)=>{let r=n(i);return r===i?e:`url(#${r})`}):t}var Ve=/\\(?:([\da-fA-F]{1,6})(?:\r\n|[\t\n\f\r ])?|([^\n\r\f]))/g,He=/\/\*[\s\S]*?(?:\*\/|$)|(?<![\w-])url\(\s*(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|(?:\\[\s\S]|[^()"'\\])*)\s*\)|"(?:\\[\s\S]|[^"\\])*(?:"|$)|'(?:\\[\s\S]|[^'\\])*(?:'|$)|#((?:[\w\u0080-\uffff-]|\\(?:[\da-fA-F]{1,6}[\t\n\f\r ]?|[^\n\r\f]))+)|\\[\s\S]|[()[\]{};]/gi;function Ue(e){return e.replace(Ve,(e,t,i)=>{if(!t)return i;let r=parseInt(t,16);return r>0&&r<=1114111&&!(r>=55296&&r<=57343)?String.fromCodePoint(r):"�"})}function Ze(e){return e.replace(/(^\d)|[^\w\u0080-\uffff-]/g,(e,t)=>{let i=e.charCodeAt(0);return i<32||127===i||t?`\\${i.toString(16)} `:`\\${e}`})}function Ke(e,t,i=!1){return e.replace(He,(e,r)=>{if(void 0!==r){let n=i&&t.get(Ue(r));return n?`#${Ze(n)}`:e}if(!/^url\(/i.test(e))return e;let n=e.slice(4,-1).trim(),o=/^["']/.test(n)?n[0]:"",a=Ue(o?n.slice(1,-1):n),s=a.startsWith("#")&&t.get(a.slice(1));return s?`url(${o}#${Ze(s)}${o})`:e})}function Qe(e,t){return function(e,t){let i,r=/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,n="",o=0;for(r.lastIndex=ze(e)?.start??0;i=r.exec(e);){let a=i[1];if(!a||!/^(?:[\w.-]+:)?style$/i.test(a)||/\/\s*>$/.test(i[0]))continue;let s=r.lastIndex,l=new RegExp(`</${a.replace(/\./g,"\\.")}\\s*>`,"ig");l.lastIndex=s;let c=l.exec(e);if(!c)continue;let u=e.slice(s,c.index),d=/^(\s*<!\[CDATA\[)([\s\S]*)(\]\]>\s*)$/.exec(u),h=d?d[2]:je(u),p=t(h);n+=e.slice(o,s)+(p===h?u:d?`${d[1]}${p}${d[3]}`:p.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/\]\]>/g,"]]&gt;")),o=c.index,r.lastIndex=l.lastIndex}return n+e.slice(o)}(qe(e,(e,i)=>{let r=Ge(e,i,t,Ke);return r===i?void 0:r}),e=>function(e,t){let i=0,r=0,n="";for(let o of e.matchAll(He)){let a=o[0];if("("===a||"["===a)r++;else if(")"===a||"]"===a)r--;else if(0===r&&/[{};]/.test(a)&&1===a.length){let r=e.slice(i,o.index),s=/^(?:\s|\/\*[\s\S]*?\*\/)*@([\w-]+)/.exec(r);n+=Ke(r,t,"{"===a&&(!s||"scope"===s[1].toLowerCase()))+a,i=o.index+1}}return n+Ke(e.slice(i),t)}(e,t))}function Je(e,t){let i=new Map;return qe(e,(e,r)=>{"id"===e&&i.set(r,r.startsWith(`${t}-`)?r:`${t}-${r}`)}),Qe(e,i)}function et(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}function tt(e,t){let i=ze(e);if(!i)return t;let r=e=>{let r=Ye(i,e),n=r&&/^[0-9]+(?:\.[0-9]+)?$/.test(r)?Number(r):NaN;return Number.isFinite(n)&&n>0?n:t[e]};return{width:r("width"),height:r("height")}}function it(e,t){let i=ze(e);return i?Xe(e,{width:"100%",height:"100%",...void 0===Ye(i,"viewBox")?{viewBox:`0 0 ${t.width} ${t.height}`}:{},...void 0===Ye(i,"preserveAspectRatio")?{preserveAspectRatio:"xMidYMid meet"}:{}}):e}function rt(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var nt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function ot(e,t={}){let i=t.mobileSemantics?.interaction,r="number"==typeof i?.targetSize?i.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,n="mobile"===t.mode||"number"==typeof t.width&&t.width<=480,o=!!i||void 0!==r,a=e&&"object"==typeof e?e:void 0;if(!1===e||!1===a?.enabled||void 0===e&&!n&&!o)return nt;let s=a??{};return{enabled:!0,tapToSelect:s.tapToSelect??!0,tapToLockTooltip:s.tapToLockTooltip??!0,clearSelection:s.clearSelection??"backgroundTap",targetSize:s.targetSize??r??44,snap:s.snap??"nearestDatum",brushHandleSize:s.brushHandleSize??44,standardControls:s.standardControls??!1}}var at={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function st(e,t,i){if(!1!==t)return e;let r={...e};return"horizontal"===i?r.left=Math.min(r.left,15):r.bottom=Math.min(r.bottom,15),r}var lt={width:900,height:520},ct={width:900,height:520},ut={width:920,height:440},dt={width:980,height:860},ht={MultiAxisLineChart:{width:800,height:400},PieChart:{width:400,height:400},DonutChart:{width:400,height:400},GaugeChart:{width:300,height:250},ForceDirectedGraph:{width:600,height:600},SankeyDiagram:{width:800,height:600},ChordDiagram:{width:600,height:600},TreeDiagram:{width:600,height:600},Treemap:{width:600,height:600},CirclePack:{width:600,height:600},OrbitDiagram:{width:600,height:600},GaltonBoardChart:{width:700,height:420},UnitPileChart:{width:700,height:380},CollisionSwarmChart:{width:700,height:360},EventDropChart:{width:760,height:360},PacketFlowChart:{width:760,height:420},ProcessFlowChart:{width:900,height:420},PhysicsCustomChart:{width:700,height:380},GauntletChart:lt,CrucibleChart:ct,ChainReactionChart:{width:920,height:620},DependencyForestChart:ut,FlowCircuitChart:dt};function pt(e){return["MinimapChart","ProcessSankey","ChainReactionChart","DependencyForestChart","FlowCircuitChart"].includes(e)}function ft(e){return e instanceof Date?`date:${e.getTime()}`:`${typeof e}:${String(e)}`}var gt={kind:"rank-competition"};function mt(e,t,i,r){let n=e??t;return"function"==typeof n?n(i,r):i[String(n)]}var yt=/*#__PURE__*/Symbol.for("semiotic.semantic-viability"),xt=globalThis;function bt(){return xt[yt]}function vt(e){return"string"==typeof e?.code&&e.code.length>0&&("warning"===e.severity||"error"===e.severity)&&"string"==typeof e.message&&e.message.length>0}function wt(e,t,i){if(e.semanticDiagnostics=[],e.semanticStatus="not-assessed",e.empty)return;let r,n=function(e){return function(e){return bt()?.has(e)??!1}(e)?function(e){return bt()?.get(e)}(e):"BumpChart"===e?gt:void 0}(t);if(n){try{let t="function"==typeof n?n(i,e):function(e){let t=new Map;(Array.isArray(e.data)?e.data:[]).forEach((i,r)=>{if(!Number.isFinite(Number(mt(e.yAccessor,"y",i,r))))return;let n=ft(mt(e.xAccessor,"x",i,r)),o=t.get(n)??new Set;o.add(String(mt(e.lineBy,"series",i,r))),t.set(n,o)});let i=Array.from(t.values(),e=>e.size).sort((e,t)=>e-t);if(0===i.length)return[];let r=Math.floor(i.length/2),n={columns:i.length,median:i.length%2?i[r]:(i[r-1]+i[r])/2,max:i[i.length-1],contestedColumns:i.filter(e=>e>=2).length},o=n.max<2;return!o&&n.contestedColumns>=2&&n.median>=2?[]:[{code:o?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:o?"error":"warning",message:o?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...n}}]}(i);r=Array.from(t).filter(vt)}catch{return void(e.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||e.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}e.semanticDiagnostics=r,e.semanticStatus=r.some(e=>"error"===e.severity)?"degenerate":r.some(e=>"warning"===e.severity)?"degraded":"meaningful";for(let t of r)e.warnings.includes(t.code)||e.warnings.push(t.code)}}import*as St from"react-dom/server";function kt(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;let n=Number(r);return Number.isFinite(n)?n:null}function At(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;if(r instanceof Date)return Number.isFinite(r.getTime())?r:null;if("string"==typeof r){let e=j(r);if(Number.isFinite(e))return new Date(e)}let n=Number(r);return Number.isFinite(n)?n:null}import*as Mt from"react";var $t=Object.freeze([]);function _t(e){if(!e)return $t;for(let t of e)if(null==t||"object"!=typeof t)return e.filter(e=>null!=e&&"object"==typeof e);return e}import{scaleOrdinal as Pt}from"d3-scale";function It(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function Tt(e,t,i){let r=e=>e.toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function Lt(e){let t=e.map(It),i=t.length-1;return e=>{if(Number.isNaN(e)&&(e=0),e<=0){let[e,i,r]=t[0];return Tt(e,i,r)}if(e>=1){let[e,r,n]=t[i];return Tt(e,r,n)}let r=e*i,n=Math.floor(r),o=r-n,[a,s,l]=t[n],[c,u,d]=t[n+1];return Tt(Math.round(a+(c-a)*o),Math.round(s+(u-s)*o),Math.round(l+(d-l)*o))}}var Ct=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],Rt=/*#__PURE__*/Lt(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),Nt=/*#__PURE__*/Lt(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),Dt=/*#__PURE__*/Lt(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Ft=/*#__PURE__*/Lt(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Et=/*#__PURE__*/Lt(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),Ot=/*#__PURE__*/Lt(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),zt=/*#__PURE__*/Lt(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),Bt={blues:Rt,reds:Nt,greens:Dt,viridis:zt,oranges:Ft,purples:Et,greys:Ot,plasma:/*#__PURE__*/Lt(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:/*#__PURE__*/Lt(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:/*#__PURE__*/Lt(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:/*#__PURE__*/Lt(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:/*#__PURE__*/Lt(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])};function jt(e){return e&&Object.prototype.hasOwnProperty.call(Bt,e)?Bt[e]:Rt}var Wt=/*#__PURE__*/Lt(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),Yt=/*#__PURE__*/Lt(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),qt=/*#__PURE__*/Lt(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Xt=/*#__PURE__*/Lt(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Gt=/*#__PURE__*/Lt(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Vt=/*#__PURE__*/Lt(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Ht=/*#__PURE__*/Lt(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),Ut={category10:Ct,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...Bt},Zt=Ct,Kt="#007bff";function Qt(e,t,i=Zt){if(e&&"object"==typeof e&&!Array.isArray(e)){let t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){let t=Object.prototype.hasOwnProperty.call(Ut,e)?Ut[e]:void 0;if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:i}var Jt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],ei=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],ti=/*#__PURE__*/new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function ii(e,t,i){if("function"==typeof t){let r=t(e);return i&&r&&"string"==typeof r&&!function(e){let t=e.toLowerCase();return t.startsWith("#")||t.startsWith("rgb")||t.startsWith("hsl")||ti.has(t)}(r)?i(r):r}let r=String(e?.[t]);return i?i(r):Zt[Math.abs(function(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i),t&=t;return Math.abs(t)}(r))%Zt.length]}function ri(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;let i=e[t];return"string"==typeof i&&i.length>0?i:void 0}function ni(e,t,i="category10"){if(i&&"object"==typeof i&&!Array.isArray(i)){let e=i;return t=>ri(e,t)??"#999"}let r=Array.from(new Set(e.map(e=>e?.[t]).filter(e=>null!=e).map(e=>String(e)))),n=r.every(e=>!isNaN(Number(e)));if(Array.isArray(i))return Pt().domain(r).range(i).unknown("#999");let o=Object.prototype.hasOwnProperty.call(Ut,i)?Ut[i]:Ut.category10;if(n&&"function"==typeof o){let e=-1/0;for(let t of r){let i=Number(t);i>e&&(e=i)}return t=>o(0===e?0:Number(t)/e)}{let e=Array.isArray(o)?o:Zt;return Pt().domain(r).range(e).unknown("#999")}}function oi(e,t,i=[3,20],r){let n;if(n="function"==typeof t?t(e):e?.[t],!r)return n;let[o,a]=r,[s,l]=i;if(a===o)return(s+l)/2;let c=(n-o)/(a-o);return c<0?c=0:c>1&&(c=1),s+c*(l-s)}function ai(e,t,i,r,n){if(e)return e;if(i&&"object"==typeof i&&!Array.isArray(i)){let e=ri(i,r);if(e)return e}let o;if(Array.isArray(i))o=i;else if(t&&t.length>0)o=t;else if("string"==typeof i){let e=Ut[i];Array.isArray(e)&&(o=e)}return o&&0!==o.length?null!=r?(n.has(r)||n.set(r,n.size),o[n.get(r)%o.length]):o[0]:Kt}function si(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function li(e,t){if(!si(t))return e??((...e)=>({}));let i={};return void 0!==t.stroke&&(i.stroke=t.stroke),void 0!==t.strokeWidth&&(i.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(i.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...i}):(...e)=>({...i})}function ci(e){let{lineWidth:t=2,colorBy:i,colorScale:r,color:n,resolveStroke:o,fillArea:a,areaOpacity:s=.3,styleRules:l,ruleContext:c}=e;return(e,u)=>{let d,h={strokeWidth:t},p=!0===a||Array.isArray(a)&&null!=u&&a.includes(u);return o?d=o(e,u):i?r&&(d=ii(e,i,r)):d=n||Kt,void 0!==d&&(h.stroke=d,p&&(h.fill=d,h.fillOpacity=s)),l?.length&&Object.assign(h,se(e,l,c?c(e,u):{value:void 0,category:u})),h}}function ui(e){if("A"===e.__diffWinner||"B"===e.__diffWinner)return e.__diffWinner;let t=String(e.__diffSegment??"");return"line-A"===t||t.endsWith("-A")?"A":"B"}function di(e,t){return le(e,t,e=>{let t=Number(e.__x),i=Number(e.__y);return{value:Number.isFinite(i)?i:void 0,x:Number.isFinite(t)?t:void 0,y:Number.isFinite(i)?i:void 0,category:ui(e)}},e=>e.__sourceDatum?{...e.__sourceDatum,...e}:e)}function hi(e){let{seriesAColor:t,seriesBColor:i,areaOpacity:r,styleRules:n}=e;return di(e=>({fill:"A"===ui(e)?t:i,stroke:"none",fillOpacity:r}),n)}function pi(e){let{seriesAColor:t,seriesBColor:i,lineWidth:r,styleRules:n}=e;return di(e=>({stroke:"A"===ui(e)?t:i,strokeWidth:r,fill:"none"}),n)}var fi={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function gi(e,t=fi){if(e)return!0===e?t:"stops"in e?Array.isArray(e.stops)?e:void 0:"colorStops"in e?Array.isArray(e.colorStops)?{stops:e.colorStops.map(({offset:e,color:t})=>({offset:e,color:t}))}:void 0:{stops:[{offset:0,opacity:e.topOpacity??t.stops[0]?.opacity??.8},{offset:1,opacity:e.bottomOpacity??t.stops.at(-1)?.opacity??.05}]}}function mi(e){return e?gi(e):void 0}function yi(e){return{...e.extent&&{extent:e.extent},stops:e.stops.map(e=>({...e,offset:1-e.offset})).sort((e,t)=>e.offset-t.offset)}}function xi(e,t,i){return"function"==typeof e?e(i):i[e||t]}function bi(e){return e instanceof Date?e.getTime():Number(e)}function vi(e,t){return zt(1===t?.5:e/(t-1))}function wi(e){let t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}function Si(e,t){let i=function(e){if(!e)return;let t="boolean"==typeof e?{}:"string"==typeof e?{method:e}:e;return{type:"trend",method:t.method??"linear",...null!=t.bandwidth&&{bandwidth:t.bandwidth},...null!=t.order&&{order:t.order},...null!=t.color&&{color:t.color},...null!=t.strokeWidth&&{strokeWidth:t.strokeWidth},...null!=t.strokeDasharray&&{strokeDasharray:t.strokeDasharray},...null!=t.label&&{label:t.label}}}(t),r=Array.isArray(e)?e:void 0;return i?[i,...r??[]]:r}function ki(e,t){var i;let r="dark"===t?$:M,n=P(r,e);(i=n.colors).categorical??(i.categorical=r.colors.categorical);let o=k(A({...n,mode:t}));return o.mode="auto",o}var Ai={background:"bg",primary:"primary",secondary:"secondary",surface:"surface",text:"text",textSecondary:"text-secondary",grid:"grid",border:"border",cellBorder:"cell-border",focus:"focus",selection:"selection-color",annotation:"annotation-color",success:"success",danger:"danger",warning:"warning",error:"error",info:"info"},Mi=/*#__PURE__*/new Set,$i=/*#__PURE__*/new WeakMap;function _i(e,t){let i=$i.get(e);return i?function(e,t){let i=t=>Object.entries(S(ki(e,t))).map(([e,t])=>`${e}:${t}`).join(";");return`${t}{${i("light")}}@media (prefers-color-scheme:dark){${t}{${i("dark")}}}`}(i,t):void 0}function Pi(e){if(!e)return k(M);if("string"==typeof e)return w(e)||(function(e){Mi.has(e)||(Mi.add(e),console.warn(`[Semiotic] Unknown theme preset "${e}". Falling back to light theme.`))}(e),k(M));if("auto"===e.mode){let t=function(e){let t=ki(e,"light"),i={...t.colors};for(let[e,t]of Object.entries(Ai)){let r=i[e];"string"==typeof r&&(i[e]=`var(--semiotic-${t}, ${r})`)}return S(t),i.categorical=t.colors.categorical.map((e,t)=>`var(--semiotic-category-${t+1}, ${e})`),{...t,colors:i}}(e);return $i.set(t,e),t}let t="dark"===e.mode?$:M;return k(A(P(t,e)))}function Ii(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,legendFontFamily:e.typography.legendFontFamily??e.typography.fontFamily,legendFontWeight:e.typography.legendFontWeight,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,titleFontFamily:e.typography.titleFontFamily??e.typography.fontFamily,titleFontWeight:e.typography.titleFontWeight??"bold",tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function Ti(e){if(!e.axes)return[{orient:"bottom",visible:!1!==e.showTimeAxis},{orient:"left",visible:!1!==e.showValueAxis}];let t=(...t)=>e.axes.some(e=>t.includes(e.orient)),i=!1===e.showTimeAxis&&!t("bottom","top"),r=!1===e.showValueAxis&&!t("left","right");return i||r?[...e.axes,...i?[{orient:"bottom",visible:!1}]:[],...r?[{orient:"left",visible:!1}]:[]]:e.axes}function Li(e){return e instanceof Date&&(e=e.getTime()),"string"==typeof e&&""!==e.trim()&&(e=Number(e)),"number"==typeof e&&Number.isFinite(e)?e:null}function Ci(e){let t=[];for(let[i,r]of e){let e=Li(i),n=Li(r);null!==e&&null!==n&&t.push([e,n])}return t.sort((e,t)=>e[0]-t[0])}function Ri(){return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN}}function Ni(e){let t=Ci(e);if(!t.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let i=t[0][0],r=t.reduce((e,[r])=>e+(r-i)/t.length,0),n=t.reduce((e,[,i])=>e+i/t.length,0),o=0,a=0;for(let[e,s]of t){let t=e-i-r;o+=t*t,a+=t*(s-n)}let s=0===o?0:a/o,l=e=>n+s*(e-i-r);return{points:t.map(([e])=>[e,l(e)]),parameterCount:2,leverage:e=>1/t.length+(o>0?(e-i-r)**2/o:0),predict:l}}function Di(e,t=2){let i=Ci(e);if(!Number.isInteger(t)||t<0||t>=i.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let r=i[0][0]/2+i[i.length-1][0]/2,n=Math.max(Math.abs(i[0][0]-r),Math.abs(i[i.length-1][0]-r))||1,o=i.map(([e])=>(e-r)/n),a=[],s=Array.from({length:t+1},()=>Array(t+1).fill(0));for(let e=0;e<=t;e++){let t=o.map(t=>t**e);for(let i=0;i<2;i++)for(let i=0;i<e;i++){let r=t.reduce((e,t,r)=>e+t*a[i][r],0);s[i][e]+=r;for(let e=0;e<t.length;e++)t[e]-=r*a[i][e]}let r=Math.sqrt(t.reduce((e,t)=>e+t*t,0));if(!Number.isFinite(r)||r<=Number.EPSILON*i.length)return Ri();s[e][e]=r,a.push(t.map(e=>e/r))}let l=a.map(e=>e.reduce((e,t,r)=>e+t*i[r][1],0));for(let e=t;e>=0;e--){for(let i=e+1;i<=t;i++)l[e]-=s[e][i]*l[i];l[e]/=s[e][e]}let c=e=>{let i=(e-r)/n,o=0;for(let e=t;e>=0;e--)o=o*i+l[e];return o};return{points:i.map(([e])=>[e,c(e)]),parameterCount:t+1,predict:c,leverage:e=>{let i=(e-r)/n,o=[];for(let e=0;e<=t;e++){let t=i**e;for(let i=0;i<e;i++)t-=s[i][e]*o[i];o.push(t/s[e][e])}return o.reduce((e,t)=>e+t*t,0)}}}import{scaleLinear as Fi}from"d3-scale";function Ei(e,t=.3){if(!Number.isFinite(t)||t<0||t>1)return[];let i=Ci(e),r=i.length;if(r<2)return i;let n=i.map(e=>e[0]),o=i.map(e=>e[1]),a=0,s=Math.min(r,Math.max(2,Math.ceil(t*r)))-1,l=[];for(let e=0;e<r;e++){let t=n[e],i=0,c=r-1;for(;s<r-1&&Math.abs(n[s+1]-t)<=Math.abs(n[a]-t);)a++,s++;let u=Math.max(Math.abs(n[a]-t),Math.abs(n[s]-t)),d=u||1;u>0&&(i=a,c=s);let h=0,p=0,f=0,g=0,m=0;for(let e=i;e<=c;e++){let i=Math.abs(n[e]-t)/d,r=i<1?Math.pow(1-Math.pow(i,3),3):0;if(0===r)continue;h+=r;let a=(n[e]-t)/d;p+=r*a,f+=r*o[e],g+=r*a*a,m+=r*a*o[e]}if(0===h){l.push([t,o[e]]);continue}let y=h*g-p*p;if(Math.abs(y)<1e-12)l.push([t,f/h]);else{let e=(f-(h*m-p*f)/y*p)/h;l.push([t,e])}}return l}function Oi(e,t){if(e.length<3||e[0][0]===e[e.length-1][0])return null;let i="polynomial"===t.method?Di(e,t.order??2):Ni(e);if(!i.points.length)return null;let r="loess"===t.method?function(e,t=.3){let i=new Map(Ei(e,t));return i.size<2?null:Fi().domain([...i.keys()]).range([...i.values()])}(e,t.bandwidth):i.predict;if(!r)return null;let{se:n}=function(e,t,i=2){let r=e.length,n=e.reduce((e,[i,r])=>e+(r-t(i))**2,0);return{se:Math.sqrt(n/Math.max(r-i,1))}}(e,r,i.parameterCount),o=function(e){return e>=.99?2.576:e>=.95?1.96:e>=.9?1.645:1}(t.confidence??.95),a=e[e.length-1][0],s=(a-e[0][0])/(e.length-1);return{predict:r,forecast:(e,t=a)=>!Number.isInteger(e)||e<=0?[]:Array.from({length:e},(e,a)=>{let l=t+(a+1)*s,c=r(l),u=n*o*Math.sqrt(1+i.leverage(l));return{x:l,y:c,upper:c+u,lower:c-u}})}}var zi="__forecastSegment",Bi="__forecastOpacity";function ji(e,t,i,r){let n=t.uncertaintyOpacity,o=t.confidenceAccessor;if(!n&&!o)return;let a="object"==typeof n?n:{},s=a.min??.15,l=a.max??1;if(o){let t="function"==typeof o?o:e=>e[o];for(let i of e){let e=t(i);if(null!=e&&Number.isFinite(e)){let t=Math.max(0,Math.min(1,e));i[Bi]=s+t*(l-s)}}return}let c=e.map(e=>{let t=i(e),n=r(e);return null!=t&&null!=n&&Number.isFinite(t)&&Number.isFinite(n)?Math.abs(t-n):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;let[d,h]=ue(u),p=h-d;e.forEach((e,t)=>{let i=c[t];if(!Number.isFinite(i))return;let r=p>0?(i-d)/p:0;e[Bi]=l-r*(l-s)})}function Wi(e,t){return"function"==typeof t?t(e):!!e[t]}function Yi(e){return[{type:"anomaly-band",threshold:e.threshold??2,showBand:!1!==e.showBand,fill:e.bandColor||"#6366f1",fillOpacity:e.bandOpacity??.1,anomalyColor:e.anomalyColor||"#ef4444",anomalyRadius:e.anomalyRadius??6,label:e.label}]}function qi(e,t,i,r,n){let o=r._groupBy;if(o&&e.length){let a="function"==typeof o?o:e=>e[o],s=new Map;for(let t of e){let e=a(t),i=s.get(e);i?i.push(t):s.set(e,[t])}let l=[],c=[];for(let[e,o]of s){let s=qi(o,t,i,{...r,_groupBy:void 0},n);for(let e of s.processedData)l.push(e);for(let t of s.annotations)if("x-threshold"===t.type)c.some(e=>"x-threshold"===e.type)||c.push(t);else{let i=t.filter;c.push({...t,filter:t=>{let r=a(t);return(r===e||Object.is(r,e))&&(!i||i(t))}})}}return{processedData:l,annotations:c}}return function(e){return!!(e.isTraining||e.isForecast||e.isAnomaly||e.upperBounds||e.lowerBounds)}(r)?function(e,t,i,r,n){let{isTraining:o,isForecast:a,isAnomaly:s,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:f}=r,g=e.map(e=>{let t="observed";return a&&Wi(e,a)?t="forecast":o&&Wi(e,o)&&(t="training"),{...e,[zi]:t}}),m=[];for(let e=0;e<g.length;e++)m.push(g[e]),e<g.length-1&&g[e][zi]!==g[e+1][zi]&&(m.push({...g[e+1],[zi]:g[e][zi]}),m.push({...g[e],[zi]:g[e+1][zi]}));if(r.trainUnderline){let e=[];for(let t of m)"training"===t[zi]&&e.push({...t,[zi]:"training-base"});m.unshift(...e)}let y=[];if(l&&c){let e="string"==typeof l?l:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(let i of m)"function"==typeof l&&(i[e]=l(i)),"function"==typeof c&&(i[t]=c(i));y.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:f})}if(r.uncertaintyOpacity||r.confidenceAccessor){let e=l?"function"==typeof l?l:e=>e[l]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};ji(m.filter(e=>"forecast"===e[zi]),r,e,t)}if(s){let e=r.anomalyStyle,t={type:"highlight",filter:e=>Wi(e,s)};e?(t.style=e,t.r=p):"function"==typeof h?(t.style=e=>{let t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=p):(t.color=h,t.r=p,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),y.push(t)}return n&&y.push(...Yi(n)),{processedData:m,annotations:y}}(e,0,0,r,n):function(e,t,i,r,n){let{trainEnd:o,steps:a=10,color:s="#6366f1",bandOpacity:l=.15,label:c}=r;if(null===Li(o))return{processedData:e,annotations:[]};let u=[],d=[];for(let i of[...e].sort((e,i)=>(Li(e[t])??1/0)-(Li(i[t])??1/0))){let e=Li(i[t]);null!==e&&e<=o?u.push({...i,[zi]:"training"}):d.push({...i,[zi]:"observed"})}let h=Ci(u.map(e=>[e[t],e[i]])),p=[],f=[];if(h.length>=3&&Number.isInteger(a)&&a>0){let n=Oi(h,r);if(n){let o=e.map(e=>Li(e[t])).filter(e=>null!==e),h=he(o),g=e.some(e=>e[t]instanceof Date);for(let{x:e,y:r,upper:o,lower:s}of n.forecast(a,h))f.push({...d[d.length-1]??u[u.length-1],[t]:g?new Date(e):e,[i]:r,[zi]:"forecast",__forecastUpper:o,__forecastLower:s});ji(f,r,e=>e.__forecastUpper,e=>e.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:s,fillOpacity:l,label:c})}}p.push({type:"x-threshold",x:o,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),n&&p.push(...Yi(n));let g=[];if(g.push(...u),u.length>0&&d.length>0&&g.push({...u[u.length-1],[zi]:"observed"}),g.push(...d),f.length>0){let e=d.length>0?d[d.length-1]:u[u.length-1];e&&g.push({...e,[zi]:"forecast"}),g.push(...f)}return{processedData:g,annotations:p}}(e,t,i,r,n)}var Xi="__semiotic_resolvedX",Gi="__semiotic_resolvedY",Vi="__compoundGroup";function Hi(e,t,i){let r=e[t],n=e[i];return null==r||null==n||Number.isNaN(r)||Number.isNaN(n)}function Ui(e){let t=e.xAccessor||"x",i=e.yAccessor||"y",r=e.lineBy,n=e.colorBy||r,o=Array.isArray(e.data)?_t(e.data).filter(e=>!!e&&"object"==typeof e):[],a=function(e,t,i){let r="function"==typeof t,n="function"==typeof i,o=r?Xi:t,a=n?Gi:i;return r||n?{xKey:o,yKey:a,rows:e.map(e=>{let o={...e};return r&&(o[Xi]=t(e)),n&&(o[Gi]=i(e)),o})}:{rows:e,xKey:o,yKey:a}}(o,t,i);o=a.rows;let s,l,c=a.xKey,u=a.yKey,d=Array.isArray(e.annotations)?[...e.annotations]:[],h="string"==typeof r||"function"==typeof r?r:void 0,p=e.baseLineStyle;if(e.forecast){let t=qi(o,c,u,!r||"string"!=typeof r&&"function"!=typeof r?e.forecast:{...e.forecast,_groupBy:r},e.anomaly);if(o=t.processedData,d.push(...t.annotations),s=function(e,t,i){if(!i)return;let r=[t,i.upperBounds??"__forecastUpper",i.lowerBounds??"__forecastLower"].map(e=>"function"==typeof e?e:t=>t[e]),n=!(!i.upperBounds&&!i.lowerBounds),o=1/0,a=-1/0;for(let t of e){let e=r[1](t),i=r[2](t);(null!=e||null!=i)&&(n=!0);for(let n of[Number(r[0](t)),e,i])"number"==typeof n&&Number.isFinite(n)&&(o=Math.min(o,n),a=Math.max(a,n))}return n&&o<=a?[o,a]:void 0}(o,u,e.forecast),!r||"string"!=typeof r&&"function"!=typeof r?h=zi:(o=o.map(e=>({...e,[Vi]:`${"function"==typeof r?r(e):e[r]}__${e[zi]||"observed"}`})),h=Vi),e.baseLineStyle){let t=function(e,t){let i=t.trainDasharray??"8,4",r=t.forecastDasharray??"4,4",n=t.color||"#6366f1",o=t.trainOpacity,a=t.forecastOpacity,s=t.trainStroke,l=t.trainLinecap,c=t.trainUnderline;return t=>{let u=e(t),d=t[zi];if("training"===d){let e=u.stroke;return"darken"===s?e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)*(1-t)),n=Math.round(parseInt(i[2],16)*(1-t)),o=Math.round(parseInt(i[3],16)*(1-t));return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):s&&(e=s),{...u,stroke:e,strokeDasharray:i,...l&&{strokeLinecap:l},...null!=o&&{strokeOpacity:o}}}if("training-base"===d){let e=u.stroke||"#666";return"lighten"===c&&(e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)+(255-parseInt(i[1],16))*t),n=Math.round(parseInt(i[2],16)+(255-parseInt(i[2],16))*t),o=Math.round(parseInt(i[3],16)+(255-parseInt(i[3],16))*t);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}(e,.4)),{...u,stroke:e,strokeDasharray:void 0}}if("forecast"===d){let e=t[Bi]??a;return{...u,stroke:n,strokeDasharray:r,...null!=e&&{strokeOpacity:e}}}return u}}(t=>e.baseLineStyle(t),e.forecast);p=e=>t(e)}}else e.anomaly&&d.push(...Yi(e.anomaly));if(e.gapStrategy){if("function"==typeof h){let e=h;o=o.map(t=>({...t,__semiotic_gapGroup:e(t)})),h="__semiotic_gapGroup"}let t="string"==typeof h?h:void 0,i=function(e,t,i,r,n){let o=new Map;for(let t of e){let e=n?String(t[n]??""):"__single";o.has(e)||o.set(e,[]),o.get(e).push(t)}if("interpolate"===t){let e=[];for(let[,t]of o)for(let n of t)Hi(n,i,r)||e.push(n);return{rows:e,groupKey:n}}if("zero"===t){let e=[];for(let[,t]of o)for(let n of t)Hi(n,i,r)?e.push({...n,[r]:0}):e.push(n);return{rows:e,groupKey:n}}let a=[],s="_gapSegment";for(let[e,t]of o){let n=0,o=[],l=()=>{if(0===o.length)return;let t="__single"===e?`__seg${n}`:`${e}__seg${n}`;for(let e of o)a.push({...e,[s]:t});o=[],n++};for(let e of t)Hi(e,i,r)?l():o.push(e);l()}return{rows:a,groupKey:s}}(o,e.gapStrategy,c,u,t);o=i.rows,i.groupKey&&(h=i.groupKey)}if(e.directLabel){let t=function(e,t,i,r,n,o,a,s){if(!t||!i)return{annotations:[]};let l="object"==typeof t?t:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof i?i:e=>e[i],h=ni(e.map(e=>({__lbl:String(d(e)??"")})),"__lbl",o??a),p=function(e,t,i="x",r="y"){let n="function"==typeof i?i:e=>e[i],o="function"==typeof r?r:e=>e[r],a="function"==typeof t.colorBy?t.colorBy:e=>e[t.colorBy],s=new Map;for(let i of e){let e=a(i)??(i.parentLine&&a(i.parentLine));if(null==e||""===String(e))continue;let r=String(e),o=s.get(r);(!o||("end"===t.position?Number(n(i))>Number(n(o)):Number(n(i))<Number(n(o))))&&s.set(r,i)}return[...s].map(([e,a])=>({type:"text",label:e,["string"==typeof i?i:"x"]:n(a),["string"==typeof r?r:"y"]:o(a),x:n(a),y:o(a),_directLabel:{id:e,position:t.position},color:t.color(e),fontSize:t.fontSize}))}(e,{position:c,fontSize:u,colorBy:i,color:e=>h?h(e):s||Kt},r,n),f=p.reduce((e,t)=>Math.max(e,Array.from(String(t.label)).length*(.65*u)),0)+10;return{annotations:p,marginExtra:"end"===c?{right:f}:{left:f}}}(o,e.directLabel,"string"==typeof n||"function"==typeof n?n:void 0,c,u,e.colorScheme,e.themeCategorical,e.color);d.push(...t.annotations),l=t.marginExtra}return{data:o,xAccessor:"function"==typeof t?c:t,yAccessor:"function"==typeof i?u:i,groupAccessor:h,colorAccessor:n,annotations:d,lineStyle:p,yExtent:s,marginExtra:l}}function Zi(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Pi(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrScatterColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrScatterColorBy:t(e)})):o,u=t?ni(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[3,15],p=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],f=p.length?ue(p):void 0,g=oe(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?ii(e,t,u):"string"==typeof n.color?n.color:Kt,fillOpacity:"number"==typeof n.pointOpacity?n.pointOpacity:.8,r:d?oi(e,d,h,f):"number"==typeof n.pointRadius?n.pointRadius:5};return m?.length&&Object.assign(i,se(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}var Ki={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Ui({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:Pi(r.theme).colors.categorical}),a=Si(o.annotations,n.regression);return{chartType:"scatter",data:o.data,xAccessor:o.xAccessor,yAccessor:o.yAccessor,colorAccessor:t,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,...a&&a.length>0&&{annotations:a},...o.yExtent&&!r.yExtent&&{yExtent:o.yExtent},sizeRange:n.sizeRange||[3,15],pointStyle:r.pointStyle||Zi(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function Qi(e,t,i,r){if(!i.categoryAccessor)return;let n=function(e,t){if(!t)return[];let i=new Set,r=[];for(let n of e){if(!n||"object"!=typeof n)continue;let e="function"==typeof t?t(n):n[t],o=String(e);i.has(o)||(i.add(o),r.push(o))}return r}(e,i.categoryAccessor),o=i.colors,a="explicit-then-alpha"===r?[...Object.keys(o??{}).filter(e=>n.includes(e)),...n.filter(e=>!Object.hasOwn(o??{},e)).sort()]:n,s=Pi(t.theme).colors.categorical,l=s?.length?s:Jt;return Object.fromEntries(a.map((e,t)=>[e,o&&ri(o,e)||i.fill||l[t%l.length]]))}var Ji={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Si(r.annotations,n.regression);return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:i,...r,...o&&{annotations:o},pointStyle:r.pointStyle||er(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function er(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Pi(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrBubbleColorBy:t(e)})):o,u=t?ni(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[5,40],p=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],f=p.length?ue(p):void 0,g=oe(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?ii(e,t,u):"string"==typeof n.color?n.color:Kt,fillOpacity:"number"==typeof n.bubbleOpacity?n.bubbleOpacity:.6,r:d?oi(e,d,h,f):h[0],stroke:n.bubbleStrokeColor??"white",strokeWidth:n.bubbleStrokeWidth??1};return m?.length&&Object.assign(i,se(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}import{useMemo as tr,useCallback as ir,useState as rr,useId as nr,useEffect as or,useRef as ar}from"react";var sr="__semioticSelectionData";function lr(e,t){return t?.length&&Object.defineProperty(e,sr,{configurable:!0,enumerable:!1,value:t}),e}function cr(e){return e?.[sr]}function ur(e){return e.parentLine?lr({...e.parentLine,...e},cr(e)):e}function dr(e){return lr({...e[0]},e.map(ur))}function hr(e){return!!e&&cr(e)?.[0]===e}var pr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function fr(e){let t=new Date(e instanceof Date?e.valueOf():e);return`${pr[t.getUTCMonth()]} ${t.getUTCDate()}`}function gr(e){let t=Math.abs(e[1]-e[0]);return t<864e5?e=>{let i=new Date(e instanceof Date?e.valueOf():e),r=`${String(i.getUTCHours()).padStart(2,"0")}:${String(i.getUTCMinutes()).padStart(2,"0")}`;return t<3e5&&(r+=`:${String(i.getUTCSeconds()).padStart(2,"0")}`),t<1e4&&(r+=`.${String(i.getUTCMilliseconds()).padStart(3,"0")}`),r}:t<3156e7?fr:t<1578e8?e=>{let t=new Date(e instanceof Date?e.valueOf():e);return`${pr[t.getUTCMonth()]} ${t.getUTCFullYear()}`}:e=>String(new Date(e instanceof Date?e.valueOf():e).getUTCFullYear())}function mr(e,t,i){return"function"==typeof e?e(t,i):t[e]}function yr(e,t){if(!e?.length)return;let i=new Map(t.map((e,t)=>[ft(e),t]));return e.map(e=>{let t={...e},r=r=>{if(!(r in e))return;let n=i.get(ft(e[r]));void 0!==n&&(t[r]=n)};return r("x"),r("x0"),r("x1"),"string"==typeof e.type&&("x-threshold"===e.type||"x"===e.type)&&r("value"),t})}function xr(e){let t="number"==typeof e?e:"string"==typeof e&&""!==e.trim()?Number(e):NaN;return Number.isFinite(t)?Math.max(0,Math.floor(t)):void 0}function br(e){return"string"==typeof e&&""!==e.trim()?e:void 0}function vr(e,t={}){let i=t.xAccessor??"x",r=t.yAccessor??"y",n=t.lineBy??"series",o=t.rankDirection??"descending",a=[],s=new Map,l=new Map,c=[],u=new Map,d=1/0,h=-1/0;e.forEach((e,t)=>{let o=mr(i,e,t),p=ft(o),f=s.get(p);null==f&&(f=a.length,s.set(p,f),a.push(o),l.set(f,[]));let g=String(mr(n,e,t));u.has(g)||(u.set(g,c.length),c.push(g));let m=Number(mr(r,e,t));Number.isFinite(m)&&(d=Math.min(d,m),h=Math.max(h,m),l.get(f)?.push({datum:e,inputIndex:t,series:g,value:m}))});let p=[],f=new Map,g=new Map;for(let e=0;e<a.length;e++){let t=l.get(e)??[];t.sort((e,t)=>("descending"===o?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,i)=>{let r=i+1;p.push({datum:t.datum,xIndex:e,xValue:a[e],series:t.series,value:t.value,rank:r}),f.set(t.series,(f.get(t.series)??0)+r),g.set(t.series,(g.get(t.series)??0)+1)})}let m=c.length+1,y=[...c].sort((e,t)=>{let i=g.get(e)??0,r=g.get(t)??0;return((f.get(e)??0)+(a.length-i)*m)/Math.max(1,a.length)-((f.get(t)??0)+(a.length-r)*m)/Math.max(1,a.length)||(u.get(e)??0)-(u.get(t)??0)}),x=null==t.highlightTop?y.length:Math.max(0,Math.floor(t.highlightTop)),b=new Set(y.slice(0,x));return{data:p.map(e=>{let t=b.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:a,seriesOrder:c,overallOrder:y,valueExtent:d===1/0?[0,0]:[d,h]}}import*as wr from"react";import{jsx as Sr}from"react/jsx-runtime";var kr,Ar={isActive:!1,predicate:()=>!0};function Mr(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function $r(e,t,i,r,n){let o=1-n;return 3*o*o*(t-e)+6*o*n*(i-t)+3*n*n*(r-i)}function _r(e,t,i,r,n){let o=[],a=(e.x+t.x)/2;for(let s=0;s<=n;s++){let l,c,u,d,h=s/n;"linear"===r?(l=e.x+(t.x-e.x)*h,c=e.y+(t.y-e.y)*h,u=t.x-e.x,d=t.y-e.y):(l=Mr(e.x,a,a,t.x,h),c=Mr(e.y,e.y,t.y,t.y,h),u=$r(e.x,a,a,t.x,h),d=$r(e.y,e.y,t.y,t.y,h)),o.push({x:l,y:c,dx:u,dy:d,radius:e.radius+(t.radius-e.radius)*h,datumIndex:h<.5?i:i+1})}return o}function Pr(e,t){let i=e.length-1,r=Math.sign(e[i][0]-e[t][0])||1,n=r*e[i][0],o=r*e[t][0];for(let a=t+1;a<i;a++){let t=Math.max(o,Math.min(n,r*e[a][0]));e[a][0]=r*t,o=t}for(let r=t;r<i;r++){let t=r;for(;t<i&&e[t+1][0]===e[r][0];)t++;for(let i=r+1;i<t;i++)e[i][1]=e[r][1]+(e[t][1]-e[r][1])*(i-r)/(t-r);r=t}let a=1e-6*(n-r*e[t][0])/(i-t);o=r*e[t][0];for(let s=t+1;s<i;s++){let t=Math.max(o+a,Math.min(r*e[s][0],n-(i-s)*a));e[s][0]=r*t,o=t}}function Ir(e,t={}){let i=[],r=[],n=[];if(e.length<2)return{topPath:i,bottomPath:r,datumIndices:n};let o=t.curve??"smooth",a=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;t<e.length-1;t++){let s=Math.max(0,i.length-1),l=_r(e[t],e[t+1],t,o,a);for(let e=0===t?0:1;e<l.length;e++){let t=l[e],o=Math.hypot(t.dx,t.dy)||1,a=-t.dy/o,s=t.dx/o,c=Math.max(0,t.radius);i.push([t.x+a*c,t.y+s*c]),r.push([t.x-a*c,t.y-s*c]),n.push(t.datumIndex)}Pr(i,s),Pr(r,s)}return{topPath:i,bottomPath:r,datumIndices:n}}var Tr={top:20,bottom:48,left:48},Lr=[[/[mwMW@%…]/,.95],[/[ijlI'.,|\s]/,.28],[/[frt():;/[\]{}*`!\\-]/,.39]];function Cr(e,t){let i=0;for(let t of e)i+=(t.codePointAt(0)??0)>=11904?1.1:Lr.find(([e])=>e.test(t))?.[1]??(t.toLowerCase()!==t?.75:.62);return i*t*1.05}function Rr(e){let t=e.fontSize??12,i=!0===e.showLabels?"end":e.showLabels,r="end"===i||"both"===i||"auto"===i,n="start"===i||"both"===i,o=e.labels.reduce((e,i)=>Math.max(e,Cr(i,t)),0),a=Math.round(e.width*(e.maxSideFraction??.38)),s=Cr(String(Math.max(1,e.rankCount)),t),l=e.showAxes?8+s+6:8,c={start:l+4+(e.showAxes&&e.yLabel?24:0),end:12},u=e.legendSide?Ce({legendGroups:[{label:"",styleFn:()=>({}),items:e.labels.map(e=>({label:e}))}]},{sideGutter:0}):0,d=Cr("MMM",t),h=(t,i)=>Math.min(i+o,e.legendSide===t?Math.max(i+d,a-u):a),p={start:n?h("left",c.start):0,end:r?h("right",c.end):0},f=!1===e.showLabels?24:110;return{margin:{...Tr,right:Math.max(f,p.end),left:Math.max(Tr.left,p.start)},startLabelOffset:l,chrome:c,room:p,labelWidth:o,fontSize:t,hasStart:n,hasEnd:r}}import{jsx as Nr,jsxs as Dr}from"react/jsx-runtime";function Fr({datum:e,x:t,y:i,side:r,color:n,highlighted:o,labelStyle:a,offset:s,budget:l,fontSize:c}){let u=function(){let e=(kr??(kr=wr.createContext(null)),kr);return wr.useContext(e)??Ar}(),d=u.isActive&&!u.predicate(e),h="function"==typeof a?a(e.__bumpRaw):a,p=null==l?{text:e.__bumpSeries,truncated:!1}:function(e,t,i){if(Cr(e,i)<=t)return{text:e,truncated:!1};let r=Array.from(e),n=r.length-1;for(;n>0&&Cr(`${r.slice(0,n).join("")}…`,i)>t;)n--;return{text:`${r.slice(0,n).join("").trimEnd()}…`,truncated:!0}}(e.__bumpSeries,l,c);return Dr("text",{className:"semiotic-bump-label",x:t+("end"===r?s:-s),y:i,dy:"0.35em",textAnchor:"end"===r?"start":"end",fill:n,fillOpacity:d?.16:1,fontWeight:o?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...h},children:[p.truncated&&Nr("title",{children:e.__bumpSeries}),p.text]})}function Er(e,t,i){let[r,n]=t,[o,a]=i;return n===r?(o+a)/2:o+(a-o)*Math.max(0,Math.min(1,(e-r)/(n-r)))}function Or(e){let t=e.__bumpXValue instanceof Date?e.__bumpXValue.getTime():Number(e.__bumpXValue);return{value:e.__bumpValue,x:Number.isFinite(t)?t:void 0,y:e.__bumpValue,category:e.__bumpSeries}}function zr(e){let t=e.config,i=new Map;for(let t of e.data){let e=i.get(t.__bumpSeries)??[];e.push(t),i.set(t.__bumpSeries,e)}let r=t.seriesOrder.filter(e=>i.has(e)).sort((e,r)=>(i.get(e)?.[0]?.__bumpHighlighted?1:0)-(i.get(r)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(r)),n=[],o=[],a=[];for(let o of r){let r=(i.get(o)??[]).sort((e,t)=>e.x-t.x);if(r.length<2)continue;let s=r[0].__bumpHighlighted,l=(t.colorMap&&ri(t.colorMap,o))??e.resolveColor(r[0].__bumpSeries,r[0]),c=t.color??(s?l:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??l),u=r.map(i=>({x:e.scales.x(i.x),y:e.scales.y(i.y),radius:t.ribbon?Er(i.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=Ir(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:s?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(h,se(r[0].__bumpRaw,t.styleRules,Or(r[0]))),t.areaStyle&&Object.assign(h,t.areaStyle(r[0].__bumpRaw)??{}),void 0!==t.stroke&&(h.stroke=t.stroke),void 0!==t.strokeWidth&&(h.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(h.opacity=t.opacity),n.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,_hitArea:!0,style:h,datum:d.datumIndices.map(e=>r[e]),accessibleDatum:r.map(e=>e.__bumpRaw),accessibility:{label:`${o} ranking trajectory`,tableFields:r.map(e=>e.__bumpRaw)},group:o,interactive:!0}),t.showPoints&&r.forEach((e,i)=>{let r={fill:c,stroke:"none",opacity:s?1:.75};t.styleRules?.length&&Object.assign(r,se(e.__bumpRaw,t.styleRules,Or(e))),t.pointStyle&&Object.assign(r,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(r.stroke=t.stroke),void 0!==t.strokeWidth&&(r.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(r.opacity=t.opacity),n.push({type:"point",x:u[i].x,y:u[i].y,r:r.r??t.pointRadius,style:r,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${o}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${o}:${e.x}`})});let p=!0===t.showLabels?"end":t.showLabels,f=(e,i,r)=>{let n=null==t.labelPriorityAccessor?void 0:"function"==typeof t.labelPriorityAccessor?t.labelPriorityAccessor(e.__bumpRaw):Number(e.__bumpRaw[t.labelPriorityAccessor]);a.push({id:`${o}\0${r}`,datum:e,x:u[i].x,y:u[i].y,side:r,rank:e.__bumpRank,highlighted:s,priority:Number.isFinite(n)?n:void 0,color:"string"==typeof h.fill?h.fill:c})};("start"===p||"both"===p)&&f(r[0],0,"start"),("end"===p||"both"===p||"auto"===p)&&f(r.at(-1),r.length-1,"end")}let s=!0===t.showLabels?"end":t.showLabels,l=function(e,t,i,r){let n=Math.max(1,Math.floor(t/18)),o="auto"===i?Number.isFinite(r)&&(r??0)>=0?Math.min(n,Math.floor(r)):n:1/0,a=e.map((e,t)=>({candidate:e,index:t})).sort((e,t)=>{let i=e.candidate.priority??0;return(t.candidate.priority??0)-i||Number(t.candidate.highlighted)-Number(e.candidate.highlighted)||e.candidate.rank-t.candidate.rank||e.index-t.index}),s=[];for(let{candidate:e}of a){if(s.length>=o)break;s.some(t=>t.side===e.side&&Math.abs(t.y-e.y)<14)||s.push(e)}return new Set(s.map(e=>e.id))}(a,e.dimensions.plot.height,"auto"!==s||"auto",t.maxLabels);for(let e of a)l.has(e.id)&&o.push(Nr(Fr,{datum:e.datum,x:e.x,y:e.y,side:e.side,color:e.color,highlighted:e.highlighted,labelStyle:t.labelStyle,offset:"end"===e.side?8:t.startLabelOffset??8,budget:t.labelBudget?.[e.side],fontSize:t.labelFontSize??12},e.id));return{nodes:n,overlays:o.length?Nr("g",{className:"semiotic-bump-labels",children:o}):void 0,restyle:(e,t)=>{let i=function(e){let t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&i&&!t.predicate(i))return{opacity:.14}}}}function Br(e){return Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[]}function jr(e){return{xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineBy:e.lineBy,rankDirection:e.rankDirection,highlightTop:xr(e.highlightTop)}}function Wr(e,t,i,r,n,o){let a=t.labelStyle,s=o.position??"right";return{legendSide:!0!==o.show||"left"!==s&&"right"!==s?void 0:s,labels:e,showLabels:t.showLabels??!0,width:i,showAxes:r,rankCount:e.length,yLabel:"string"==typeof n?n:"Rank",fontSize:"object"==typeof a&&"number"==typeof a?.fontSize?a.fontSize:12}}var Yr={frameType:"xy",layout:{modeDefaults:{showGrid:!0},margin:(e,t)=>{let{seriesOrder:i}=vr(Br(e.data),jr(e));return Rr(Wr(i,e,t.width,t.showAxes,e.yLabel,{show:e.showLegend,position:e.legendPosition})).margin}},buildProps:(e,t,i,r,n)=>{let o=vr(Br(e),jr(n)),[a]=r.size??[600,400],s=Rr(Wr(o.seriesOrder,n,a,!1!==r.showAxes,r.yLabel,{show:r.showLegend,position:r.legendPosition})),l=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]),c=r.margin,u={...c,...s.hasEnd&&!l.has("right")&&{right:Math.max(c.right,s.margin.right)},...s.hasStart&&!l.has("left")&&{left:Math.max(c.left,s.margin.left)}},d=function(e,t){let i={start:t.hasStart?Math.max(0,Math.min(e.left,t.room.start)-t.chrome.start):0,end:t.hasEnd?Math.max(0,Math.min(e.right,t.room.end)-t.chrome.end):0};return{budget:i,sideGutter:{...t.hasStart&&{left:t.chrome.start+Math.min(i.start,t.labelWidth)},...t.hasEnd&&{right:t.chrome.end+Math.min(i.end,t.labelWidth)}}}}(u,s),h=r.legendPosition??"right",p=r.legendLayout,f=!0!==r.showLegend||"left"!==h&&"right"!==h?void 0:d.sideGutter[h],g=Math.max(1,o.seriesOrder.length),m=Pi(r.theme),y=function(e){let{seriesOrder:t,overallOrder:i,highlightTop:r,color:n,colorScheme:o,neutralColor:a,themeCategorical:s,themeNeutral:l}=e;if(null==r&&null==n)return o;let c="string"==typeof o?[...Qt(o,s)]:o,u=null==r?i.length:Math.max(0,Math.floor(r)),d=new Set(i.slice(0,u)),h=new Map,p={};for(let e of t)Object.defineProperty(p,e,{configurable:!0,enumerable:!0,writable:!0,value:n??(d.has(e)?ai(void 0,s,c,e,h):a??l??"#b8bec8")});return p}({seriesOrder:o.seriesOrder,overallOrder:o.overallOrder,highlightTop:xr(n.highlightTop),color:br(n.color),colorScheme:i,neutralColor:br(n.neutralColor),themeCategorical:m.colors.categorical,themeNeutral:m.colors.textSecondary}),x={ribbon:!0===n.ribbon,curve:"linear"===n.curve?"linear":"smooth",samplesPerSegment:"number"==typeof n.samplesPerSegment?n.samplesPerSegment:12,ribbonSizeRange:Array.isArray(n.ribbonSizeRange)?n.ribbonSizeRange:[4,28],valueExtent:o.valueExtent,seriesOrder:o.seriesOrder,lineWidth:"number"==typeof n.lineWidth?n.lineWidth:3,ribbonOpacity:"number"==typeof n.ribbonOpacity?n.ribbonOpacity:.82,lineOpacity:"number"==typeof n.lineOpacity?n.lineOpacity:.9,neutralColor:br(n.neutralColor),color:br(n.color),colorMap:y&&"object"==typeof y&&!Array.isArray(y)?y:void 0,stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0,styleRules:n.styleRules,areaStyle:r.areaStyle,pointStyle:r.pointStyle,labelStyle:n.labelStyle,showPoints:!0===n.showPoints,pointRadius:"number"==typeof n.pointRadius?n.pointRadius:3,showLabels:n.showLabels??!0,labelPriorityAccessor:n.labelPriorityAccessor,maxLabels:"number"==typeof n.maxLabels?n.maxLabels:void 0,startLabelOffset:s.startLabelOffset,labelBudget:d.budget,labelFontSize:s.fontSize},b=function(e,t){let i=t=>e[Math.max(0,Math.min(e.length-1,Math.round(Number(t))))],r=e.every(e=>"number"==typeof e||e instanceof Date),n=t?void 0:function(e){let t=e.filter(e=>e instanceof Date&&Number.isFinite(e.valueOf()));if(0===t.length)return;let i=t.every(e=>e.valueOf()%864e5==0),r=i&&t.every(e=>1===e.getUTCDate());if(r&&t.every(e=>0===e.getUTCMonth()))return e=>String(e.getUTCFullYear());if(r)return e=>`${fr(e).split(" ")[0]} ${e.getUTCFullYear()}`;let n=t.map(e=>e.valueOf()),o=ue(n);if(i){let e=new Date(o[0]).getUTCFullYear()===new Date(o[1]).getUTCFullYear();return t=>e?fr(t):`${fr(t)}, ${t.getUTCFullYear()}`}return gr(o)}(e);return(o,a,s)=>{if(0===e.length)return"";let l=i(o);return t?t(l,a,s&&r?s.map(e=>Number(i(e).valueOf())):void 0):l instanceof Date&&n?n(l):String(l)}}(o.xValues,r.xFormat),v=o.xValues.map((e,t)=>t),w=Array.from({length:g},(e,t)=>t+1),S=r.axes??[{orient:"left",tickValues:w,tickFormat:e=>String(e),label:r.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:v,tickFormat:b,label:r.xLabel,tickAnchor:"edges"}];return{...r,margin:u,...null!=f&&null==p?.sideGutter&&{legendLayout:{...p,sideGutter:f}},chartType:"custom",data:o.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,o.xValues.length-1)],yExtent:[g+.5,.5],customLayout:zr,layoutConfig:x,colorAccessor:"__bumpSeries",colorScheme:y,xFormat:b,axes:S,axisExtent:"exact",showAxes:r.showAxes??!0,showLegend:r.showLegend??!1,annotations:yr(r.annotations,o.xValues)}}},qr="__ma_unitized",Xr="__ma_series";function Gr(e,t){let i=ne(e),r=t.map((e,t)=>({label:e.label||`Series ${t+1}`,readY:ne(e.yAccessor)}));return(e,t)=>{let n=String(e[Xr]??t??""),o=(r.find(e=>e.label===n)??r[0])?.readY(e);return{value:o,x:i(e),y:o,category:n||void 0}}}var Vr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Array.isArray(n.series)?n.series:[],s=function(e,t,i){let r=Qt(t,i,Zt),n=t&&"object"==typeof t&&!Array.isArray(t)?t:null;return e.map((e,t)=>{if("string"==typeof e.color&&e.color.length>0)return e.color;let i=e.label||`Series ${t+1}`,o=n?.[i];return"string"==typeof o&&o.length>0?o:r[t%r.length]})}(a,i,Pi(r.theme).colors.categorical),l=2===a.length,c=a.map(e=>e.extent||function(e,t){let i="function"==typeof t?t:e=>Number(e[t||"y"]),r=1/0,n=-1/0;for(let t of e){let e=i(t);"number"==typeof e&&Number.isFinite(e)&&(e<r&&(r=e),e>n&&(n=e))}if(!Number.isFinite(r)||!Number.isFinite(n))return[0,1];if(r===n){let e=0===r?1:.1*Math.abs(r);return[r-e,n+e]}return[r,n]}(o,e.yAccessor)),u=[];for(let e of o)a.forEach((t,i)=>{let r=("function"==typeof t.yAccessor?t.yAccessor:e=>e[t.yAccessor])(e);if(null==r||!Number.isFinite(Number(r)))return;let n=Number(r),o=c[i],a=o[1]-o[0]||1;u.push({...e,[qr]:l?(n-o[0])/a:n,[Xr]:t.label||`Series ${i+1}`})});let d=(e,t)=>i=>{let r=e[0]+i*(e[1]-e[0]);return"function"==typeof t?t(r):Number.isInteger(r)?String(r):r.toFixed(1)},h=l?[{orient:"left",label:a[0].label,tickFormat:d(c[0],a[0].format)},{orient:"right",label:a[1].label,tickFormat:d(c[1],a[1].format)},{orient:"bottom"}]:void 0,p=new Map;a.forEach((e,t)=>{p.set(e.label||`Series ${t+1}`,s[t])});let f=li(ci({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,resolveStroke:e=>p.get(String(e[Xr]??""))||s[0],styleRules:n.styleRules,ruleContext:Gr(n.xAccessor,a)}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0});return{chartType:"line",data:u,xAccessor:n.xAccessor||"x",yAccessor:qr,groupAccessor:Xr,colorAccessor:Xr,...h&&{axes:h},...l&&{yExtent:[0,1]},...r,curve:n.curve||r.curve||"monotoneX",showLegend:r.showLegend??!0,colorScheme:s,lineStyle:f}}},Hr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.xAccessor||"x",s="function"==typeof a?a:e=>e[a],l=o.some(e=>{let t=s(e);return!("number"==typeof t&&Number.isFinite(t)||t instanceof Date)}),c=l?o.map((e,t)=>({...e,__waterfallX:t,__waterfallTick:String(s(e)??t)})):o,u=n.styleRules?le(void 0,n.styleRules,oe(n.xAccessor,n.yAccessor)):void 0,d=u?e=>{let t=u(e),i="function"==typeof r.areaStyle?r.areaStyle(e):r.areaStyle;return i?{...t,...i}:t}:void 0;return{chartType:"waterfall",data:c,xAccessor:l?"__waterfallX":a,yAccessor:n.yAccessor||"y",waterfallStyle:{positiveColor:n.positiveColor,negativeColor:n.negativeColor,connectorStroke:n.connectorStroke,connectorWidth:n.connectorWidth,gap:n.gap,stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity},...r,...d&&{areaStyle:d},...l&&{axes:r.axes??[{orient:"bottom",tickValues:c.map((e,t)=>t)}],xFormat:e=>{let t=o[Number(e)]?s(o[Number(e)]):e,i=n.xFormat??r.xFormat;return"function"==typeof i?i(t):String(t??e)}}}}};function Ur(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Pi(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrAreaColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrAreaColorBy:t(e)})):o,u=t?ni(c,l,s):void 0,d=!1!==n.showLine,h="number"==typeof n.lineWidth?n.lineWidth:2,p="number"==typeof n.areaOpacity?n.areaOpacity:.7,f=ne(n.yAccessor),g=n.styleRules;return(e,i)=>{let r=t&&u?ii(e,t,u):"string"==typeof n.color?n.color:Kt,o={fill:r,fillOpacity:p,stroke:d?r:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(o,se(e,g,{value:f(e),category:i})),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}function Zr(e,t,i,r,n){if(!n.showPoints)return;let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Pi(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrPointColorBy:t(e)})):o,u=t?ni(c,l,s):void 0,d="number"==typeof n.pointRadius?n.pointRadius:3;return e=>{let i=t&&u?ii(e,t,u):"string"==typeof n.color?n.color:Kt;return{r:d,fill:i,stroke:"none"}}}var Kr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.lineBy,a=n.fillArea,s=Array.isArray(a)?"mixed":a?"area":"line",l=Pi(r.theme).colors.categorical,c=function(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Pi(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrLineColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrLineColorBy:t(e)})):o,u=t?ni(c,l,s):void 0,d=oe(n.xAccessor,n.yAccessor);return li(ci({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof n.color?n.color:void 0,fillArea:n.fillArea,areaOpacity:"number"==typeof n.areaOpacity?n.areaOpacity:.3,styleRules:n.styleRules,ruleContext:d}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0})}(e,o,i,r,n),u=Ui({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.lineBy,colorBy:o,colorScheme:i,color:"string"==typeof n.color?n.color:void 0,forecast:n.forecast,anomaly:n.anomaly,gapStrategy:n.gapStrategy,directLabel:n.directLabel,annotations:r.annotations,themeCategorical:l,baseLineStyle:c}),d=r.pointStyle||Zr(u.data,u.colorAccessor,i,r,n),h=r.margin,p=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]);u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&!p.has("right")&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&!p.has("left")&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});let f=(!n.directLabel||void 0!==r.showLegend)&&(r.showLegend??!!u.colorAccessor);return{chartType:s,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:i,lineStyle:u.lineStyle||c,...Array.isArray(a)&&{areaGroups:a},...a&&null!=n.areaOpacity&&{areaOpacity:n.areaOpacity},...null!=n.band&&{band:n.band},...r,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!r.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},Qr={frameType:"xy",layout:{margin:(e,t)=>function(e,t,i,r=!1){let n=Te({axes:t,showAxes:i});return{...Ee(e,t,r),...!n.hasAxis&&{bottom:0},...!n.leftAxis?.hasAxis&&{left:0}}}(t.marginDefaults,Ti(e),t.showAxes,!!t.title)},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?_t(e):[],a=n.timeAccessor||"time",s=n.valueAccessor||"value",l=n.categoryAccessor,c=Qi(o,r,n,"explicit-then-alpha"),u=n.valueExtent||r.yExtent,d={...wi(n),...void 0!==n.cursor&&{cursor:n.cursor}},h={...d,...void 0!==n.fill&&{fill:n.fill},...void 0!==n.gap&&{gap:n.gap},...Array.isArray(n.valueBands)&&{valueBands:n.valueBands}},p=le(void 0,n.styleRules,e=>{let t=e.categoryValue??e.total,i="number"==typeof t&&Number.isFinite(t)?t:void 0,r=Number(e.binStart),n=Number(e.binEnd);return{value:i,x:Number.isFinite(r)&&Number.isFinite(n)?(r+n)/2:void 0,y:i,category:null==e.category?void 0:String(e.category)}});return{chartType:"bar",data:o,...r,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,o.length),arrowOfTime:n.arrowOfTime||"right",timeAccessor:e=>At(e,a,"time")??NaN,valueAccessor:e=>kt(e,s,"value")??NaN,xExtent:n.timeExtent||r.xExtent,yExtent:u,invertY:"down"===n.direction,axes:Ti({...n,axes:r.axes??n.axes}),extentPadding:n.extentPadding??r.extentPadding,binSize:n.binSize,binAlign:n.binAlign,categoryAccessor:l,barColors:c||r.barColors,colorScheme:c||r.colorScheme,barStyle:r.barStyle||h,areaStyle:r.areaStyle||(e=>({...p(e),...!l&&void 0!==n.fill&&{fill:n.fill},...d})),showLegend:r.showLegend??!!l}}},Jr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a=Ui({data:Array.isArray(e)?_t(e):[],xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.areaBy,forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:Pi(r.theme).colors.categorical}),s=function({data:e,safeData:t,areaBy:i,lineDataAccessor:r}){if(null==e)return[];let n,o=void 0!==t[0]?.[r];if(!o&&!i)return t;if(o)n=t;else{let e=t.reduce((e,t)=>{let n="function"==typeof i?i(t):t[i],o=String(n);if(!e[o]){let t={[r]:[]};"string"==typeof i&&(t[i]=n),e[o]=t}return e[o][r].push(t),e},{});n=Object.values(e)}return n.flatMap(e=>{let t=Array.isArray(e[r])?e[r]:[];return"string"==typeof i?t.map(t=>({...t,[i]:t[i]??e[i]})):t})}({data:e,safeData:a.data,areaBy:n.areaBy,lineDataAccessor:n.lineDataAccessor||"coordinates"}),l=function(e){if(e)return Array.isArray(e)?{stops:e.map(({at:e,color:t,opacity:i})=>({offset:e/100,color:t,...null!=i&&{opacity:i}}))}:Array.isArray(e.stops)?e:void 0}(n.semanticGradient),c=l?.stops.length?function(e){return{...yi(e),extent:"domain"}}(l):gi(r.gradientFill),u=!1!==n.semanticLine?function(e){let t=e?.stops.filter(e=>"string"==typeof e.color&&Number.isFinite(e.offset)).map(({offset:e,color:t,opacity:i})=>({offset:Math.max(0,Math.min(1,e)),color:t,...Number.isFinite(i)&&{opacity:Math.max(0,Math.min(1,i))}})).sort((e,t)=>e.offset-t.offset);if(!t?.length)return;let i=t[0];return i.offset>0?[{...i,offset:0},...t]:t}(l):void 0,d=r.pointStyle||Zr(s,o,i,r,n);return{chartType:"area",data:s,xAccessor:a.xAccessor,yAccessor:a.yAccessor,y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||void 0,colorAccessor:o,colorScheme:i,...r,...a.annotations.length>0&&{annotations:a.annotations},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:r.lineStyle||Ur(s,o,i,r,n),...d&&{pointStyle:d}}}},en={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xAccessor||"x",a=n.seriesAAccessor||"a",s=n.seriesBAccessor||"b",l=e=>bi(xi(o,"x",e)),c=e=>bi(xi(a,"a",e)),u=e=>bi(xi(s,"b",e)),d=n.seriesAColor||"var(--semiotic-danger, #dc2626)",h=n.seriesBColor||"var(--semiotic-info, #2563eb)",p=n.areaOpacity??.6,f=n.lineWidth??1.5,g=!1!==n.showLines,m=!1!==r.showLegend,y=n.seriesALabel||"A",x=n.seriesBLabel||"B",b=r.legendPosition||"right",v=function(e,t,i,r){if(!e.length)return[];let n=e.filter(e=>Number.isFinite(t(e))).sort((e,i)=>t(e)-t(i)),o=[],a=0,s=null,l=null,c=[],u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${a}-${e}`,h=e=>o.push(e),p=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;e<n.length;e++){let o=n[e],f=t(o),g=i(o),m=r(o);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(m))continue;let y=u(g,m);if(null!==y){if(null==s){s=y;for(let e of c)p(e,s);c=[],h({__x:f,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:f,a:g,b:m,w:y};continue}if(l&&l.w!==y){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{let i=g-l.a-(m-l.b);if(0!==i){let r=(l.b-l.a)/i,n=Math.max(0,Math.min(1,r));e=l.x+n*(f-l.x),t=l.a+n*(g-l.a)}else e=l.x,t=l.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t}),a++,s=y,h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t});for(let e=1;e<c.length;e++)p(c[e],s)}else for(let e of c)p(e,s);c=[],h({__x:f,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:f,a:g,b:m,w:y}}else c.push({x:f,y:g,datum:o})}for(let e of c)p(e,s??"A");return o}(Array.isArray(e)?e:[],l,c,u),w=[];if(g&&Array.isArray(e)){let t=e.filter(e=>Number.isFinite(l(e))).sort((e,t)=>l(e)-l(t));for(let e of t){let t=l(e),i=c(e),r=u(e);Number.isFinite(i)&&w.push({__x:t,__y:i,__diffSegment:"line-A",__diffWinner:"A",__sourceDatum:e}),Number.isFinite(r)&&w.push({__x:t,__y:r,__diffSegment:"line-B",__diffWinner:"B",__sourceDatum:e})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:hi({seriesAColor:d,seriesBColor:h,areaOpacity:p,styleRules:n.styleRules}),lineStyle:pi({seriesAColor:d,seriesBColor:h,lineWidth:f,styleRules:n.styleRules}),curve:n.curve||"linear",...r,...m&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:y,color:d},{label:x,color:h}]}]},legendPosition:b}}}},tn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a="string"==typeof o&&Array.isArray(e)?ni(e,o,i):void 0,s="number"==typeof n.areaOpacity?n.areaOpacity:.7,l=r.lineStyle||(e=>{let t=null==o?void 0:ii(e,o,a),i=n.showLine??!0,r=n.stroke??t,l=n.strokeWidth??n.lineWidth??2,c={fill:n.color??t,stroke:i?r:"none",...i?{strokeWidth:l}:{},fillOpacity:s,...null==n.opacity?{}:{opacity:n.opacity}},u=n.styleRules;if(u?.length){let t=ne(n.yAccessor),i=o?String("function"==typeof o?o(e)??"":e[o]??""):void 0;Object.assign(c,se(e,u,{value:t(e),category:i}))}return c}),c=n.normalize?"zero":n.baseline??"zero",u=r.pointStyle||Zr(e,o,i,r,n);return{chartType:"stackedarea",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:o,colorScheme:i,normalize:n.normalize,baseline:c,stackOrder:n.stackOrder,lineStyle:l,...r,...u&&{pointStyle:u},curve:r.curve??n.curve??"monotoneX",showLegend:r.showLegend??!!o}}},rn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let[o]=r.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...r,...!r.pointStyle&&Array.isArray(n.styleRules)&&n.styleRules.length>0&&{pointStyle:le(void 0,n.styleRules,oe(n.xAccessor||"x",n.closeAccessor||n.highAccessor||"high"))},scalePadding:r.scalePadding??Math.max(2,Math.min(12,Math.round(o/40))),extentPadding:r.extentPadding??(o<=200?.02:.1)}}},nn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xCenter,a=n.yCenter,s=n.quadrants,l=n.centerlineStyle||{},c=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,f=Mt.createElement,g=s?[(e,t,i)=>{if(!t?.x||!t?.y)return null;let r=i.width,n=i.height,l=null!=o?t.x(o):r/2,g=null!=a?t.y(a):n/2;if(null!=o&&!Number.isFinite(l)||null!=a&&!Number.isFinite(g))return null;let m=Math.max(0,Math.min(r,l)),y=Math.max(0,Math.min(n,g)),x=[{c:s.topLeft,x:0,y:0,w:m,h:y},{c:s.topRight,x:m,y:0,w:r-m,h:y},{c:s.bottomLeft,x:0,y:y,w:m,h:n-y},{c:s.bottomRight,x:m,y:y,w:r-m,h:n-y}],b=c?[f("text",{key:"ltl",x:8,y:8+u,fill:s.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.topLeft.label),f("text",{key:"ltr",x:r-8,y:8+u,fill:s.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.topRight.label),f("text",{key:"lbl",x:8,y:n-8,fill:s.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.bottomLeft.label),f("text",{key:"lbr",x:r-8,y:n-8,fill:s.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.bottomRight.label)]:[];return f(Mt.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?f("rect",{key:`qf-${t}`,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),f("line",{key:"vc",x1:m,y1:0,x2:m,y2:n,stroke:d,strokeWidth:h,strokeDasharray:p}),f("line",{key:"hc",x1:0,y1:y,x2:r,y2:y,stroke:d,strokeWidth:h,strokeDasharray:p}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[3,15],colorScheme:i,pointStyle:r.pointStyle||n.pointStyle||Zi(e,t,i,r,n),...r,showLegend:r.showLegend??!!t,...g&&{svgPreRenderers:g}}}},on={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};let i=t.xAccessor||"x",r=t.yAccessor||"y",n=t.orderAccessor?[...e].sort((e,i)=>null==e||"object"!=typeof e?1:null==i||"object"!=typeof i?-1:bi(xi(t.orderAccessor,"order",e))-bi(xi(t.orderAccessor,"order",i))):e,o=new WeakMap,a=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=bi(xi(i,"x",e)),n=bi(xi(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&a++}let s=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=bi(xi(i,"x",e)),n=bi(xi(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&o.set(e,{idx:s++,total:a})}return{data:n,orderMap:o}}(e,n),a=Ui({data:o.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:Pi(r.theme).colors.categorical}),s=Si(a.annotations,n.regression),l=n.pointRadius??4,c=oe(n.xAccessor,n.yAccessor),u=n.styleRules,d=[e=>{let t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(t.length<2)return null;let i=[];for(let e=0;e<t.length-1;e++){let r=t[e],n=t[e+1],o=vi(e,t.length);t.length<100&&i.push(Mt.createElement("line",{key:`halo-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),i.push(Mt.createElement("line",{key:`segment-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:o,strokeWidth:l,strokeLinecap:"round"}))}return Mt.createElement(Mt.Fragment,null,...i)}];return{chartType:"scatter",data:a.data,xAccessor:a.xAccessor,yAccessor:a.yAccessor,colorAccessor:t,colorScheme:i,pointStyle:li(e=>{let t=o.orderMap.get(e),i=t?.idx??0,r=t?.total??1,n={fill:r>0?vi(i,r):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(n,se(e,u,c(e))),n},wi(n)),...r,...s&&s.length>0&&{annotations:s},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},svgPreRenderers:d}}};function an(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}var sn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:void 0,a=Number.isFinite(n.cellBorderWidth)?Math.max(0,n.cellBorderWidth):1,s=le(()=>({stroke:n.cellBorderColor??"#fff",strokeWidth:a}),n.styleRules,function(e,t,i){let r=ne(e),n=ne(t),o=ne(i);return e=>{let t="string"==typeof e.agg&&"number"==typeof e.count&&"number"==typeof e.xCenter&&"number"==typeof e.yCenter;return{value:t?an(e.value):o(e),x:t?an(e.xCenter):r(e),y:t?an(e.yCenter):n(e)}}}(n.xAccessor,n.yAccessor,n.valueAccessor)),l=("string"==typeof o?.colorScheme?o.colorScheme:void 0)??i,c=null!=o&&Object.hasOwn(o,"heatmapColorScale"),u=o?.heatmapColorScale,d=c?"function"==typeof u?u:void 0:"custom"===l&&"function"==typeof n.customColorScale?n.customColorScale:void 0;return{chartType:"heatmap",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,showValues:n.showValues,heatmapValueFormat:n.valueFormat,...n.heatmapAggregation&&{heatmapAggregation:n.heatmapAggregation},...null!=n.heatmapXBins&&{heatmapXBins:n.heatmapXBins},...null!=n.heatmapYBins&&{heatmapYBins:n.heatmapYBins},areaStyle:s,...r,...void 0!==l&&{colorScheme:l},...d&&{heatmapColorScale:d}}}};import*as ln from"react";import{renderToStaticMarkup as cn}from"react-dom/server";function un(e){return"string"==typeof e||"number"==typeof e?String(e):Array.isArray(e)?e.map(un).join(""):ln.isValidElement(e)?"string"!=typeof e.type&&e.type!==ln.Fragment?je(cn(e).replace(/<!--[\s\S]*?-->|<(?:[^<>"']|"[^"]*"|'[^']*')*>/g,"")):un(e.props.children):""}function dn(e){return"string"==typeof e||"number"==typeof e?e:Array.isArray(e)?e.map((e,t)=>ln.createElement(ln.Fragment,{key:t},dn(e))):!ln.isValidElement(e)||"tspan"!==e.type&&e.type!==ln.Fragment?un(e):ln.cloneElement(e,void 0,dn(e.props.children))}import*as hn from"react-dom/server";import*as pn from"react";import*as fn from"react-dom/server";function gn(e,t,i="start"){let r="center"===i?t/2:0;return Math.floor((e+r)/t)*t-r}function mn(e,t,i,r,n,o=!1,a="start"){let s=new Map;for(let l of e){let e=t(l),c=i(l);if(null==e||null==c||Number.isNaN(e)||Number.isNaN(c))continue;let u=gn(e,r,a),d=s.get(u);if(d||(d={start:u,end:u+r,total:0,categories:new Map,...o?{rows:[],categoryRows:new Map}:{}},s.set(u,d)),d.total+=c,d.rows?.push(l),n){let e=n(l);if(d.categories.set(e,(d.categories.get(e)||0)+c),d.categoryRows){let t=d.categoryRows.get(e);t||(t=[],d.categoryRows.set(e,t)),t.push(l)}}}return s}var yn=class{constructor(e){if(this._capacity=e,this.head=0,this._size=0,e<1)throw new Error("RingBuffer capacity must be at least 1");this.buffer=new Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){let t=[];for(let i of e){let e=this.push(i);void 0!==e&&t.push(e)}return t}get(e){if(e<0||e>=this._size)return;let t=(this.head-this._size+e+this._capacity)%this._capacity;return this.buffer[t]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let e=0;return{next:()=>e>=this._size?{done:!0,value:void 0}:{done:!1,value:this.get(e++)}}}forEach(e){let t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e(this.buffer[(t+i)%this._capacity],i)}toArray(){let e=new Array(this._size),t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e[i]=this.buffer[(t+i)%this._capacity];return e}resize(e){if(e<1)throw new Error("RingBuffer capacity must be at least 1");let t=this.toArray(),i=0,r=[];t.length>e&&(i=t.length-e,r=t.slice(0,i)),this._capacity=e,this.buffer=new Array(e),this.head=0,this._size=0;for(let e=i;e<t.length;e++)this.push(t[e]);return r}update(e,t){let i=[],r=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;n<this._size;n++){let o=(r+n)%this._capacity,a=this.buffer[o];if(e(a)){let e;e="object"!=typeof a||null===a?a:Array.isArray(a)?[...a]:{...a},i.push(e),this.buffer[o]=t(a)}}return i}remove(e){let t=[],i=[];if(this.forEach(r=>{e(r)?i.push(r):t.push(r)}),0===i.length)return i;this.buffer=new Array(this._capacity),this.head=0,this._size=0;for(let e of t)this.push(e);return i}clear(){this.buffer=new Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},xn=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}evict(e){(e===this._min||e===this._max)&&(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(let i of e){let e=t?t(i):i;Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function bn(e){return new Set(Array.isArray(e)?e:[e])}function vn(e,t,i){if(i<=1)return 1;let r=i-1;return function(e){let t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||e.extent<=0)return 1;let i=Math.max(0,e.age);if("step"===e.type)return i<(e.threshold??.5*e.extent)?1:t;if("exponential"===e.type){let r=e.halfLife??e.extent/2,n=r>0?r:e.extent/2;return t+Math.pow(.5,i/n)*(1-t)}return t+Math.max(0,Math.min(1,1-i/e.extent))*(1-t)}({age:r-t,extent:r,type:e.type,halfLife:e.halfLife??i/2,threshold:e.stepThreshold??.5*i,minOpacity:e.minOpacity??.1})}function wn(e){let t=new Map;for(let i=0;i<e.length;i++)t.set(e[i],i);return t}function Sn(e,t,i){let r=e.duration??500,n=i-t;return n>=r?0:1-n/r}function kn(e,t,i,r){let n=!1;return t>0?(e._pulseIntensity!==t&&(e._pulseIntensity=t,n=!0),e._pulseColor!==i&&(e._pulseColor=i,n=!0),e._pulseGlowRadius!==r&&(e._pulseGlowRadius=r,n=!0),n):(0!==e._pulseIntensity&&(e._pulseIntensity=0,n=!0),void 0!==e._pulseColor&&(e._pulseColor=void 0,n=!0),void 0!==e._pulseGlowRadius&&(e._pulseGlowRadius=void 0,n=!0),n)}function An(e,t,i=(typeof performance<"u"?performance.now():Date.now())){if(!t||0===t.size)return!1;let r=e.duration??500,n=t.peek();return null!=n&&i-n<r}var Mn=null;function $n(){return Mn}var _n=/*#__PURE__*/Object.create(null);function Pn(e){_n[e.chartType]=e}function In(e){return _n[e]}var Tn=typeof window>"u"||typeof document>"u",Ln=/*#__PURE__*/new Set;function Cn(e){if("production"===process.env.NODE_ENV)return;let{label:t,nodes:i,overlays:r,warned:n}=e;Rn(r)&&0===i.length&&Nn(n,"overlay-only",`[semiotic] ${t} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),i.length>0&&i.every(e=>null==e.datum)&&Nn(n,"null-datums",`[semiotic] ${t} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Rn(e){return null!=e&&!1!==e&&""!==e&&(!Array.isArray(e)||e.some(Rn))}function Nn(e,t,i){e.has(t)||(e.add(t),console.warn(i))}function Dn(e){try{return{kind:"success",result:e.run()}}catch(t){let i=e.hasPreviousResult,r=function(e,t,i,r){let n=function(e){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Custom layout threw."};if("string"==typeof e)return{name:"Error",message:e};if(null==e)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:String(e)}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(t),o="network"===e?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:e,source:o,message:`Semiotic ${e} ${o} failed: ${n.message}`,error:n,recovery:i?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:i,affectedRevision:r}}(e.family,t,i,e.revision);"production"!==process.env.NODE_ENV&&console.error(`[semiotic] ${e.logLabel} threw:`,t);try{e.onLayoutError?.(r)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return{kind:"failure",diagnostic:r,preservedLastGoodScene:i}}}function Fn(e,t){let i="function"==typeof e?e:i=>i[e||t];return e=>{let t=i(e);return null==t?Number.NaN:+t}}function En(e){let t=[],i=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode,r=Fn(i&&e.valueAccessor||e.yAccessor,i?"value":"y");if(e.boundsAccessor){let i=V(e.boundsAccessor,"bounds");t.push({kind:"bounds",getTop:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t+n:t},getBottom:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t-n:t},style:e.boundsStyle,perSeries:!0,interactive:!1})}if(e.band){let i=Array.isArray(e.band)?e.band:[e.band];for(let e of i)t.push({kind:"band",getTop:Fn(e.y1Accessor,"y1"),getBottom:Fn(e.y0Accessor,"y0"),style:e.style,perSeries:!1!==e.perSeries,interactive:!0===e.interactive})}return t}import{scaleLinear as On,scaleLog as zn,scaleSymlog as Bn,scaleTime as jn,scaleUtc as Wn}from"d3-scale";function Yn(e,t,i,r,n,o){let a=[];for(let o of e){let e=i(o),s=r(o),l=n?n(o):0;if(!Number.isFinite(e)||!Number.isFinite(s)||!Number.isFinite(l))continue;let c=t.x(e),u=t.y(s),d=n?t.y(l):0;!Number.isFinite(c)||!Number.isFinite(u)||!Number.isFinite(d)||a.push({x:c,y:u,bottom:d,raw:s,datum:o})}a.sort((e,t)=>e.x-t.x);let s=new Array(a.length),l=n?new Array(a.length):[],c=new Array(a.length),u=new Array(a.length),d=o?new Array(a.length):void 0;for(let e=0;e<a.length;e++){let t=a[e];s[e]=[t.x,t.y],n&&(l[e]=[t.x,t.bottom]),c[e]=t.raw,u[e]=t.datum,d&&o&&(d[e]=String(o(t.datum)))}return d?{topPath:s,bottomPath:l,rawValues:c,datum:u,pathIds:d}:{topPath:s,bottomPath:l,rawValues:c,datum:u}}function qn(e,t,i,r,n,o,a){let{topPath:s,rawValues:l,datum:c,pathIds:u}=Yn(e,t,i,r,void 0,a),d={type:"line",path:s,rawValues:l,style:n,datum:c,group:o};return u&&(d.pathIds=u),d}function Xn(e,t,i,r,n,o,a,s,l){return{type:"area",...Yn(e,t,i,r,s??(()=>n),l),style:o,group:a}}function Gn(e,t,i,r){let n=new Map;if("silhouette"===r)for(let r of e){let e=0;for(let n of t)e+=i(n,r)||0;n.set(r,-e/2)}else if("wiggle"===r){e.length>0&&n.set(e[0],0);for(let r=1;r<e.length;r++){let o=e[r-1],a=e[r],s=0,l=0,c=0;for(let e of t){let t=i(e,a)||0;s+=(2*c+t)*(t-(i(e,o)||0)),l+=t,c+=t}let u=n.get(o)??0,d=l>0?s/(2*l):0;n.set(a,u-d)}if(e.length>0){let r=0;for(let o of e){let e=0;for(let r of t)e+=i(r,o)||0;r+=(n.get(o)??0)+e/2}let o=r/e.length;for(let t of e)n.set(t,(n.get(t)??0)-o)}}else for(let t of e)n.set(t,0);return n}function Vn(e,t,i,r,n,o,a){let s=i(e),l=r(e);if(!Number.isFinite(s)||!Number.isFinite(l))return null;let c={type:"point",x:t.x(s),y:t.y(l),r:n,style:o,datum:e};return void 0!==a&&(c.pointId=a),c}function Hn(e,t,i,r,n,o,a,s){let l=i(e),c=r(e);if(!Number.isFinite(l)||!Number.isFinite(c))return null;let u={type:"symbol",x:t.x(l),y:t.y(c),size:n,symbolType:o,style:a,datum:e};return void 0!==s&&(u.pointId=s),u}function Un(e,t,i,r,n,o,a){return{type:"rect",x:e,y:t,w:i,h:r,style:n,datum:o,group:a}}function Zn(e,t,i,r,n,o,a){let s={type:"heatcell",x:e,y:t,w:i,h:r,fill:n,datum:o};return void 0!==a?.value&&(s.value=a.value),a?.showValues&&(s.showValues=!0,a.valueFormat&&(s.valueFormat=a.valueFormat)),s}function Kn(e,t){return t?[t[0]??e[0],t[1]??e[1]]:e}function Qn(e){let{config:t,groups:i,getX:r,getY:n}=e,o="exact"===(t.yAxisExtent??t.axisExtent),a=o?"exact":"pad",s="log"===t.yScaleType?"log":"lin",l=t.normalize?`${e.bufferSize}:${e.ingestVersion}:norm:${t.stackOrder??"key"}:${a}:${s}`:`${e.bufferSize}:${e.ingestVersion}:${t.baseline??"zero"}:${t.stackOrder??"key"}:${a}:${s}`;if(e.stackExtentCache&&e.stackExtentCache.key===l)return{yDomain:e.stackExtentCache.yDomain,stackExtentCache:e.stackExtentCache};let c=new Map,u=new Set,d=new Map,h=new Map;for(let e of i){let t=new Map,i=0;for(let o of e.data){let e=r(o),a=n(o);if(!Number.isFinite(e)||!Number.isFinite(a))continue;t.set(e,(t.get(e)||0)+a),u.add(e),i+=a;let s=(d.get(e)||0)+a;d.set(e,s)}c.set(e.key,t),h.set(e.key,i)}let p,f=t.stackOrder??"key",g=(e,t)=>e<t?-1:e>t?1:0;if("input"===f)p=i.map(e=>e.key);else if("insideOut"===f){let e=[...i].map(e=>e.key).sort((e,t)=>{let i=(h.get(t)??0)-(h.get(e)??0);return 0!==i?i:g(e,t)}),t=[],r=[],n=0,o=0;for(let i of e)n<o?(t.push(i),n+=h.get(i)??0):(r.push(i),o+=h.get(i)??0);p=[...r.reverse(),...t]}else p="asc"===f?i.map(e=>e.key).sort((e,t)=>{let i=(h.get(e)??0)-(h.get(t)??0);return 0!==i?i:g(e,t)}):"desc"===f?i.map(e=>e.key).sort((e,t)=>{let i=(h.get(t)??0)-(h.get(e)??0);return 0!==i?i:g(e,t)}):i.map(e=>e.key).sort(g);if(t.normalize)for(let e of c.values())for(let[t,i]of e)e.set(t,i/(d.get(t)||1));let m,y=t.normalize?"zero":t.baseline,x="log"===t.yScaleType?[]:null,b=e=>{x&&(x.length>0&&x[x.length-1]===e||x.push(e))},v=e=>{let t={key:l,yDomain:e};return x&&(t.plottedY=x),{yDomain:e,stackExtentCache:t}};if("wiggle"===y||"silhouette"===y){let e=Array.from(u).sort((e,t)=>e-t),i=Gn(e,p,(e,t)=>c.get(e)?.get(t)||0,y),r=1/0,n=-1/0,a=e=>{b(e),e<r&&(r=e),e>n&&(n=e)};for(let t of e){let e=i.get(t)??0;a(e);for(let i of p){let r=c.get(i)?.get(t)||0;0!==r&&(e+=r,a(e))}}(!Number.isFinite(r)||!Number.isFinite(n))&&(r=0,n=0);let s=n-r,l=o?0:s>0?s*t.extentPadding:1;return v([r-l,n+l])}if("diverging"===y){let e=Array.from(u).sort((e,t)=>e-t),i=0,r=0,n=e=>{b(e),e<i&&(i=e),e>r&&(r=e)};for(let t of e){let e=0,i=0;for(let r of p){let o=c.get(r)?.get(t)||0;0!==o&&(o>0?(e+=o,n(e)):(i+=o,n(i)))}}let a=r-i,s=o?0:a>0?a*t.extentPadding:1;return v([i-s,r+s])}{let e=Array.from(u).sort((e,t)=>e-t),i=0,r=0;for(let t of e){let e=0;for(let n of p){let o=c.get(n)?.get(t)||0;0!==o&&(e+=o,b(e),e<i&&(i=e),e>r&&(r=e))}}let n=r-i,a=o?0:n>0?n*t.extentPadding:1;return m=t.normalize?[0,o?1:1+t.extentPadding]:[i<0?i-a:0,r+a],v(m)}}function Jn(e,t,i){let r=[],n=0;for(let o of e){let e=i(o),a=t(o);null==e||Number.isNaN(e)||null==a||!isFinite(a)||(n+=e,r.push(n))}return r}function eo(e,t,i,r){if(e[0]!==1/0&&e[1]!==-1/0)return e;let n=i?.[0],o=i?.[1],a="number"==typeof n&&Number.isFinite(n),s="number"==typeof o&&Number.isFinite(o);return a||s?"log"===r&&a&&!s&&n>0?[n,10*n]:[a?n:s&&o>0?0:t[0],s?o:a&&n>0?0:t[1]]:t}function to(e,t,i){let r=e[0]<=e[1],n=r?e[0]:e[1],o=r?e[1]:e[0],a=n>0&&Number.isFinite(n),s=o>0&&Number.isFinite(o);if(a&&s)return e;let l=new Set;if(i)for(let e of i)null!=e&&e>0&&Number.isFinite(e)&&l.add(e);if(!t){if(s&&l.has(o)){let e=o/10;return r?[e,o]:[o,e]}return r?[1,10]:[10,1]}let c=a?n:t.min,u=s?o:t.max;return u>c||(s&&l.has(o)?c=u/10:u=10*c),r?[c,u]:[u,c]}function io(e){let t=1/0,i=-1/0,r=!1;for(let n of e)if(Number.isFinite(n)){if(!(n>0)){r=!0;continue}n<t&&(t=n),n>i&&(i=n)}return{positive:Number.isFinite(t)?{min:t,max:i}:null,droppedNonPositive:r}}function ro(e,t,i){if("log"===e){let e=to(t,null);return e[0]===e[1]&&e[0]>0&&Number.isFinite(e[0])&&(e=[e[0],10*e[0]]),zn().domain(e).range(i).clamp(!0)}return"symlog"===e?Bn().domain(t).range(i):"time"===e||"utc"===e?("utc"===e?Wn():jn()).domain([new Date(t[0]),new Date(t[1])]).range(i):On().domain(t).range(i)}function no(e,t){return e&&"object"==typeof e&&!Array.isArray(e)?ri(e,t):void 0}function oo(e,t,i){t<=e.capacity||(e.resize(t),i&&t>i.capacity&&i.resize(t))}function ao(e,t){let i=new yn(e.capacity);return e.forEach(()=>i.push(t)),i}function so(e,t,i,r){let n=e.push(t);return i&&i.push(r),n}function lo(e,t,i){if(!t||0===t.size)return;let r=new Set;if(e.forEach((e,t)=>{i(e)&&r.add(t)}),0===r.size)return;let n=t.toArray();t.clear();for(let e=0;e<n.length;e++)r.has(e)||t.push(n[e])}var co=/*#__PURE__*/new WeakMap,uo=class{getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}setLayoutSelection(e){this.config.layoutSelection=e}markStylePaintPending(){co.set(this,!0)}consumeStylePaintPending(){let e=!0===co.get(this);return co.delete(this),e}},ho={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function po(e,t){let i={...e};for(let e of t)i[ho[e]]++;return i}function fo(e,t,i){let r=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:r,revisions:po(i,r)}}var go=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=fo({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){let i=fo(e,t,this.revisions);this.revisions=i.revisions,this.latest=i;for(let e of[...this.listeners])e();return i}},mo=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],yo=["scene-style","data-paint","accessibility","evidence"],xo=(e,t)=>({retainedData:e,invalidations:t}),bo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],vo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],So=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ko=["scene-geometry","data-paint","accessibility","evidence"],Ao=["scene-style","data-paint","accessibility","evidence"],Mo=["overlay","accessibility","evidence"],$o=[],_o={chartType:/*#__PURE__*/xo("rebuild",bo),runtimeMode:/*#__PURE__*/xo("rebuild",bo),xAccessor:/*#__PURE__*/xo("rebuild",bo),yAccessor:/*#__PURE__*/xo("rebuild",bo),timeAccessor:/*#__PURE__*/xo("rebuild",bo),valueAccessor:/*#__PURE__*/xo("rebuild",bo),y0Accessor:/*#__PURE__*/xo("rebuild",bo),boundsAccessor:/*#__PURE__*/xo("rebuild",bo),band:/*#__PURE__*/xo("rebuild",bo),openAccessor:/*#__PURE__*/xo("rebuild",bo),highAccessor:/*#__PURE__*/xo("rebuild",bo),lowAccessor:/*#__PURE__*/xo("rebuild",bo),closeAccessor:/*#__PURE__*/xo("rebuild",bo),candlestickRangeMode:/*#__PURE__*/xo("rebuild",bo),accessorRevision:/*#__PURE__*/xo("rebuild",bo),groupAccessor:/*#__PURE__*/xo("rebuild",vo),categoryAccessor:/*#__PURE__*/xo("rebuild",vo),lineDataAccessor:/*#__PURE__*/xo("rebuild",vo),colorAccessor:/*#__PURE__*/xo("rebuild",Ao),sizeAccessor:/*#__PURE__*/xo("rebuild",ko),symbolAccessor:/*#__PURE__*/xo("rebuild",ko),pointIdAccessor:/*#__PURE__*/xo("rebuild",ko),xScaleType:/*#__PURE__*/xo("preserve",wo),yScaleType:/*#__PURE__*/xo("preserve",wo),xExtent:/*#__PURE__*/xo("preserve",wo),invertY:/*#__PURE__*/xo("preserve",wo),yExtent:/*#__PURE__*/xo("preserve",wo),extentPadding:/*#__PURE__*/xo("preserve",wo),scalePadding:/*#__PURE__*/xo("preserve",wo),axisExtent:/*#__PURE__*/xo("preserve",wo),yAxisExtent:/*#__PURE__*/xo("preserve",wo),binSize:/*#__PURE__*/xo("preserve",wo),binAlign:/*#__PURE__*/xo("preserve",wo),normalize:/*#__PURE__*/xo("preserve",wo),heatmapAggregation:/*#__PURE__*/xo("preserve",wo),heatmapXBins:/*#__PURE__*/xo("preserve",wo),heatmapYBins:/*#__PURE__*/xo("preserve",wo),arrowOfTime:/*#__PURE__*/xo("preserve",So),baseline:/*#__PURE__*/xo("preserve",So),stackOrder:/*#__PURE__*/xo("preserve",So),sizeRange:/*#__PURE__*/xo("preserve",So),curve:/*#__PURE__*/xo("preserve",So),areaGroups:/*#__PURE__*/xo("preserve",So),customLayout:/*#__PURE__*/xo("preserve",So),layoutConfig:/*#__PURE__*/xo("preserve",So),layoutMargin:/*#__PURE__*/xo("preserve",So),symbolMap:/*#__PURE__*/xo("preserve",ko),showValues:/*#__PURE__*/xo("preserve",ko),heatmapValueFormat:/*#__PURE__*/xo("preserve",ko),trackHoverRows:/*#__PURE__*/xo("preserve",ko),lineStyle:/*#__PURE__*/xo("preserve",Ao),pointStyle:/*#__PURE__*/xo("preserve",Ao),areaStyle:/*#__PURE__*/xo("preserve",Ao),barStyle:/*#__PURE__*/xo("preserve",Ao),swarmStyle:/*#__PURE__*/xo("preserve",Ao),waterfallStyle:/*#__PURE__*/xo("preserve",Ao),candlestickStyle:/*#__PURE__*/xo("preserve",Ao),boundsStyle:/*#__PURE__*/xo("preserve",Ao),gradientFill:/*#__PURE__*/xo("preserve",Ao),lineGradient:/*#__PURE__*/xo("preserve",Ao),semanticLineStops:/*#__PURE__*/xo("preserve",Ao),colorScheme:/*#__PURE__*/xo("preserve",Ao),themeCategorical:/*#__PURE__*/xo("preserve",Ao),themeSemantic:/*#__PURE__*/xo("preserve",Ao),themeSequential:/*#__PURE__*/xo("preserve",Ao),themeDiverging:/*#__PURE__*/xo("preserve",Ao),barColors:/*#__PURE__*/xo("preserve",Ao),decay:/*#__PURE__*/xo("preserve",Ao),pulse:/*#__PURE__*/xo("preserve",Ao),staleness:/*#__PURE__*/xo("preserve",Ao),layoutSelection:/*#__PURE__*/xo("preserve",Ao),annotations:/*#__PURE__*/xo("preserve",Mo),windowSize:/*#__PURE__*/xo("preserve",$o),windowMode:/*#__PURE__*/xo("preserve",$o),maxCapacity:/*#__PURE__*/xo("preserve",$o),clock:/*#__PURE__*/xo("preserve",$o),transition:/*#__PURE__*/xo("preserve",$o),introAnimation:/*#__PURE__*/xo("preserve",$o),onLayoutError:/*#__PURE__*/xo("preserve",$o)},Po=/*#__PURE__*/xo("preserve",So),Io=class{constructor(){this.tracker=new go}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},mo)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},yo):this.recordNoop("restyle")}recordConfig(e,t=!1){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(_o,r)?_o[r]:Po;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t?new Set([...i.invalidations,...ko]):i.invalidations)}};import{quadtree as To}from"d3-quadtree";var Lo=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(e,t){if("scatter"!==e&&"bubble"!==e&&"custom"!==e)return void this.clear();let i=0,r=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(i++,e.r>r&&(r=e.r));if(this.maxRadius=r,i<=500)return void(this.tree=null);let n=new Array(i),o=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(n[o++]=e);this.tree=To().x(e=>e.x).y(e=>e.y).addAll(n)}},Co=class extends uo{constructor(e){super(),this.xExtent=new xn,this.yExtent=new xn,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new Io,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.xTypeDetected=!1,this._warnedNonPositiveLogX=!1,this._warnedNonPositiveLogY=!1,this.spatialIndex=new Lo,this._lastBoundedInsertsRef=null,this.applyPulse=(e,t,i)=>!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,n,o=(typeof performance<"u"?performance.now():Date.now())){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1,c=n??(()=>{let e=new Map;for(let t=0;t<i.length;t++)e.set(i[t],t);return e})();for(let i of t){if("line"===i.type)continue;if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[i.datum],n=0,s=!1;for(let i of t){let t=c.get(i);if(null==t)continue;s=!0;let a=r.get(t);if(null==a)continue;let l=Sn(e,a,o);l>n&&(n=l)}s&&(l=kn(i,n,a)||l);continue}let t=c.get(i.datum);if(null==t)continue;let n=r.get(t);l=kn(i,null==n?0:Sn(e,n,o),a,s)||l}return l}(this.config.pulse,e,t,this.timestampBuffer,this.getDatumIndexMap(t),i),this.config=e,this.buffer=new yn(e.windowSize),this.growingCap=e.windowSize;let t=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode;if(this.resolveXAccessor(),this.getY=t?V(e.valueAccessor||e.yAccessor,"value"):V(e.yAccessor,"y"),this.getGroup=U(e.groupAccessor),this.getCategory=U(e.categoryAccessor),this.getSize=e.sizeAccessor?V(e.sizeAccessor,"size"):void 0,this.getColor=U(e.colorAccessor),this.getSymbol=U(e.symbolAccessor),this.getY0=e.y0Accessor?V(e.y0Accessor,"y0"):void 0,this.resolvedRibbons=En(e),this.getPointId=U(e.pointIdAccessor),"candlestick"===e.chartType){let t=null!=e.openAccessor,i=null!=e.closeAccessor;this.getOpen=t?V(e.openAccessor,"open"):void 0,this.getHigh=V(e.highAccessor,"high"),this.getLow=V(e.lowAccessor,"low"),this.getClose=i?V(e.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!i}e.pulse&&(this.timestampBuffer=new yn(e.windowSize))}currentTime(){return this.config.clock?.()??o()}resolveXAccessor(e=this.buffer){let t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=t&&this.config.timeAccessor||this.config.xAccessor,r=H(i,t?"time":"x");this.xIsDate=!1,this.xTypeDetected=!1;for(let t of e){let e=r(t);if(null==e||""===e)continue;let i=e instanceof Date&&Number.isFinite(e.getTime())||"string"==typeof e&&Number.isFinite(j(e));if(i||Number.isFinite(Number(e))){this.xIsDate=i,this.xTypeDetected=!0;break}}this.getX=this.xIsDate?e=>W(r(e)):e=>+r(e)}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=ao(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(e)),void this.yExtent.push(this.getLow(e));this.yExtent.push(this.getY(e)),this.getY0&&this.yExtent.push(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.push(i),Number.isFinite(r)&&this.yExtent.push(r)}}evictDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(e)),void this.yExtent.evict(this.getLow(e));this.yExtent.evict(this.getY(e)),this.getY0&&this.yExtent.evict(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.evict(i),Number.isFinite(r)&&this.yExtent.evict(r)}}rebuildYExtent(){this.yExtent.clear();for(let e of this.buffer)this.pushDatumYExtent(e)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(let e of this.buffer)this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e)}ingest(e){if(e.bounded&&this._lastBoundedInsertsRef===e.inserts)return this.updateResults.recordNoop("replace"),!1;let t=this.currentTime();if(this.lastIngestTime=t,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,e.bounded){this._lastBoundedInsertsRef=e.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),this.resolveXAccessor(e.inserts);let i=e.totalSize||e.inserts.length;oo(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)so(this.buffer,i,this.timestampBuffer,t),this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i)}else{this.xTypeDetected||this.resolveXAccessor(e.inserts);for(let i of e.inserts){if("growing"===this.config.windowMode&&this.buffer.full){let e=this.config.maxCapacity??1e5;this.growingCap<e&&(this.growingCap=Math.min(2*this.growingCap,e),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"!==process.env.NODE_ENV&&!this.growingCapacityWarned&&this.growingCap>=5e4&&(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${e}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}let e=so(this.buffer,i,this.timestampBuffer,t);this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i),null!=e&&(this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e))}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.lastLayout;if(!(e.width>0&&e.height>0&&Number.isFinite(e.width)&&Number.isFinite(e.height)))return void(this.needsFullRebuild=!0);if(!this.needsFullRebuild&&!t.customLayout&&!this.activeTransition&&"bar"!==t.chartType&&"waterfall"!==t.chartType&&"candlestick"!==t.chartType&&this.lastLayout&&this.lastLayout.width>0&&this.lastLayout.height>0&&this.scene.length>0&&this.scales&&(this.config.scalePadding??0)<=0&&(this.lastLayout.width!==e.width||this.lastLayout.height!==e.height))return this.scales=function(e,t,i,r){let n=r.width/i.width,o=r.height/i.height;for(let t of e)switch(t.type){case"line":for(let e of t.path)e[0]*=n,e[1]*=o;break;case"area":for(let e of t.topPath)e[0]*=n,e[1]*=o;for(let e of t.bottomPath)e[0]*=n,e[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*n,y:t.clipRect.y*o,width:t.clipRect.width*n,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(e=>({...e,y:e.y*o,height:e.height*o})));break;case"point":case"symbol":case"glyph":t.x*=n,t.y*=o;break;case"rect":case"heatcell":t.x*=n,t.y*=o,t.w*=n,t.h*=o}return{x:t.x.copy().range(t.x.range().map(e=>e*n)),y:t.y.copy().range(t.y.range().map(e=>e*o))}}(this.scene,this.scales,this.lastLayout,e),this.lastLayout={width:e.width,height:e.height},this.spatialIndex.rebuild(t.chartType,this.scene),void this.version++;this.xExtent.dirty&&this.xExtent.recalculate(i,this.getX),this.yExtent.dirty&&this.rebuildYExtent();let o=this.getBufferArray(),a=this.xExtent.extent,s=this.yExtent.extent,l="waterfall"===t.chartType&&i.size>0?function(e,t,i,r,n){let o=Array.from(new Set(e.map(t).filter(e=>Number.isFinite(e)))).sort((e,t)=>e-t);if(o.length<2)return Kn(i,r);let a=o[0],s=o[1],l=o[o.length-1],c=o[o.length-2];return Kn("log"===n&&a>0?[a/Math.sqrt(s/a),l*Math.sqrt(l/c)]:[a-(s-a)/2,l+(l-c)/2],r)}(o,this.getX,a,t.xExtent,t.xScaleType):Kn(a,t.xExtent);"bar"===t.chartType&&t.binSize&&"center"===t.binAlign&&(l=function(e,t,i){return e.every(Number.isFinite)?Kn([gn(e[0],t,"center"),gn(e[1],t,"center")+t],i):Kn(e,i)}(a,t.binSize,t.xExtent));let c=Kn(s,t.yExtent),u=!(!(h=t.yExtent)||null==h[0]||null==h[1]),d="exact"===(t.yAxisExtent??t.axisExtent);var h;if("stackedarea"===t.chartType&&!u&&i.size>0){let e=Qn({config:t,groups:this.groupData(o),getX:this.getX,getY:this.getY,bufferSize:i.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=e.yDomain,this._stackExtentCache=e.stackExtentCache}else"bar"===t.chartType&&t.binSize&&!u&&i.size>0?c=function(e,t,i,r,n,o,a,s="start"){let[l,c]=function(e,t,i,r,n,o="start"){let a=mn(e,t,i,r,n,!1,o);if(0===a.size)return[0,0];let s=0,l=0;for(let e of a.values()){let t=0,i=0;if(n&&e.categories.size>0)for(let r of e.categories.values())r<0?t+=r:r>0&&(i+=r);else t=Math.min(0,e.total),i=Math.max(0,e.total);t<s&&(s=t),i>l&&(l=i)}return[s,l]}(e,t,i,r,n,s);if(0===l&&0===c)return[0,0];let u=a?0:(c-l)*o;return[l<0?l-u:0,c+u]}(i,this.getX,this.getY,t.binSize,this.getCategory,t.extentPadding,d,t.binAlign):"waterfall"===t.chartType&&!u&&i.size>0?c=function(e,t,i,r,n){let o=0,a=0;for(let r of Jn(e,t,i))r<o&&(o=r),r>a&&(a=r);let s=a-o,l=n?0:s>0?s*r:1;return[Math.min(0,o-Math.abs(l)),Math.max(0,a+Math.abs(l))]}(i,this.getX,this.getY,t.extentPadding,d):!u&&c[0]!==1/0&&(c=function(e,t,i){if(!i.length)return e;let[r,n]=e;for(let e of t)for(let t of i){let i=t.getTop(e),o=t.getBottom(e);Number.isFinite(i)&&(i<r&&(r=i),i>n&&(n=i)),Number.isFinite(o)&&(o<r&&(r=o),o>n&&(n=o))}return[r,n]}(c,o,this.resolvedRibbons),c=function(e,t){let i=e[1]-e[0],r=t.exactMode?0:i>0?i*t.extentPadding:1,n=[null!=t.userMin?e[0]:e[0]-r,null!=t.userMax?e[1]:e[1]+r];if("log"===t.yScaleType&&n[0]<=0&&t.dataYDomain[0]>0&&!t.exactMode){let e=1+t.extentPadding;null==t.userMin&&(n[0]=t.dataYDomain[0]/e)}return n}(c,{exactMode:d,extentPadding:t.extentPadding,userMin:t.yExtent?.[0],userMax:t.yExtent?.[1],yScaleType:t.yScaleType,dataYDomain:s}));if(c=function(e,t,i){if(!t||i)return e;let r=t[0],n=t[1];return null==r&&null==n?e:[r??e[0],n??e[1]]}(c,t.yExtent,!!u),({xDomain:l,yDomain:c}=function(e,t,i,r){return{xDomain:eo(e,"time"===i?[0,864e5]:[0,1],r?.x,i),yDomain:eo(t,[0,1],r?.y,r?.yScaleType)}}(l,c,t.xScaleType,{x:t.xExtent,y:t.yExtent,yScaleType:t.yScaleType})),"log"===(t.xScaleType??(this.xIsDate?"utc":void 0))){let e=this.positiveAxisSamples(this.getX);l=to(l,e.positive,t.xExtent),this.warnDroppedLogSamples("x",e.droppedNonPositive)}if("log"===t.yScaleType){let e=io(this.plottedAggregateY(i,o)||function(e){let t=[];if("candlestick"===e.chartType&&e.getHigh&&e.getLow){let i=e.getHigh,r=e.getLow,n=e.getOpen,o=e.getClose,a=null!=n&&null!=o;for(let s of e.data)t.push(i(s),r(s)),a&&t.push(n(s),o(s));return t}for(let i of e.data){t.push(e.getY(i)),e.getY0&&t.push(e.getY0(i));for(let r of e.ribbons){let e=r.getTop(i),n=r.getBottom(i);Number.isFinite(e)&&t.push(e),Number.isFinite(n)&&t.push(n)}}return t}({chartType:t.chartType,data:i,getY:this.getY,getY0:this.getY0,getHigh:this.getHigh,getLow:this.getLow,getOpen:this.getOpen,getClose:this.getClose,ribbons:this.resolvedRibbons}));c=to(c,e.positive,t.yExtent),this.warnDroppedLogSamples("y",e.droppedNonPositive)}this.scales=function(e){let{config:t,layout:i,xDomain:r}=e,n=t.xScaleType??(e.xIsDate?"utc":void 0),o=t.invertY?[e.yDomain[1],e.yDomain[0]]:e.yDomain,a="streaming"===t.runtimeMode,s=t.scalePadding||0,l=Math.max(0,Math.min(s,Math.min(i.width,i.height)/2-1));return a?{x:ro(n,r,"left"===t.arrowOfTime?[i.width-l,l]:[l,i.width-l]),y:ro(t.yScaleType,o,[i.height-l,l])}:{x:ro(n,r,[l,i.width-l]),y:ro(t.yScaleType,o,[i.height-l,l])}}({config:t,layout:e,xDomain:l,yDomain:c,xIsDate:this.xIsDate}),this._customLayoutFailedThisBuild=!1;let p=this.buildSceneNodes(e,o);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);let f=this.config.transition?$n():null;f&&this.scene.length>0&&this.snapshotPositions(),this.scene=p,this.config.decay&&this.applyDecay(this.scene,o),this.config.pulse&&this.applyPulse(this.scene,o,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&f&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),f&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:e.width,height:e.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}buildSceneNodes(e,t){let{config:i,scales:r}=this;if(!r)return[];if(i.customLayout){let n=i.layoutMargin??{top:0,right:0,bottom:0,left:0},o={data:t,scales:r,dimensions:{width:e.width,height:e.height,margin:n,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:i.themeSemantic??{},categorical:i.themeCategorical??Jt},resolveColor:(e,t)=>{let r=this.resolveGroupColor(e);if(r)return r;let n=this.resolveLineStyle(e,t);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:i.themeSemantic?.primary??"#4e79a7"},config:i.layoutConfig??{},selection:i.layoutSelection??null},a=Dn({family:"xy",logLabel:"customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:i.onLayoutError,run:()=>i.customLayout(o)});if("failure"===a.kind)return this.lastCustomLayoutFailure=a.diagnostic,this._customLayoutFailedThisBuild=!0,a.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let s=a.result;this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null;let l=s.nodes??[];if(this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of l)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(l,i.layoutSelection??null)}return Cn({label:"customLayout",nodes:l,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),l}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===t.length)return[];let n={scales:r,config:i,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(e,t)=>this.resolveLineStyle(e,t),resolveAreaStyle:(e,t)=>this.resolveAreaStyle(e,t),resolveBoundsStyle:(e,t)=>this.resolveBoundsStyle(e,t),resolveColorMap:e=>this.resolveColorMap(e),resolveGroupColor:e=>this.resolveGroupColor(e),groupData:e=>this.groupData(e),barCategoryCache:this._barCategoryCache},o=(a=i.chartType,_n[a]?.buildScene);var a;if(!o)return function(e){In(e)||Tn&&(Ln.has(e)||(Ln.add(e),console.warn(`[semiotic] StreamXYFrame: no XY plugin registered for "${e}" during SSR. Import a chart HOC, or call registerBuiltInXYPlugins() from "semiotic/xy" or "semiotic/realtime/core" before render.`)))}(i.chartType),[];let s=function(e){return Array.isArray(e)?{nodes:e,binBoundaries:[]}:{nodes:e.nodes,binBoundaries:e.binBoundaries}}(o(n,t,e));return"bar"===i.chartType&&(this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=s.binBoundaries),s.nodes}resolveBoundsStyle(e,t){return function(e,t,i,r){let n=e.boundsStyle;if("function"==typeof n)return n(i||{},t);if(n&&"object"==typeof n)return n;let o=r(t,i);return{fill:o.stroke||e.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,...null!=o.opacity&&{opacity:o.opacity},stroke:"none",cursor:o.cursor}}(this.config,e,t,(e,t)=>this.resolveLineStyle(e,t))}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:vn(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;let t=wn(e);return this._datumIndexCache={version:this._ingestVersion,map:t},t}applyDecay(e,t){this.config.decay&&function(e,t,i,r=wn(i)){let n=i.length;if(!(n<=1))for(let i of t){if("line"===i.type){let t=Array.isArray(i.datum)?i.datum:[];if(t.length<2)continue;let o=new Array(t.length),a=!1;for(let i=0;i<t.length;i++){let s=r.get(t[i]);null!=s?(o[i]=vn(e,s,n),o[i]<1&&(a=!0)):o[i]=1}a&&(i._decayOpacities=o);continue}if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[],o=i.topPath?i.topPath.length:t.length;if(o<2)continue;if(t.length===o){let a=new Array(o),s=!1;for(let i=0;i<t.length;i++){let o=r.get(t[i]);null!=o?(a[i]=vn(e,o,n),a[i]<1&&(s=!0)):a[i]=1}s&&(i._decayOpacities=a)}else{let a=1;for(let i of t){let t=r.get(i);if(null!=t){let i=vn(e,t,n);i<a&&(a=i)}}if(a<1){let e=new Array(o);e.fill(a),i._decayOpacities=e}}continue}let t=r.get(i.datum);if(null==t)continue;let o=vn(e,t,n);if("candlestick"===i.type)i._decayOpacity=o;else{let e=i.style?.opacity??1;i.style={...i.style,opacity:e*o}}}}(this.config.decay,e,t,this.getDatumIndexMap(t))}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&An(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory,getPointId:this.getPointId}}get hasRenderedOnce(){return this._hasRenderedOnce}snapshotPositions(){$n()?.snapshotPositions(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();let e=this.scales?.y(0)??0,t=$n();if(t)for(let i=0;i<this.scene.length;i++){let r=this.scene[i],n=t.getNodeIdentity(this.transitionContext,r,i);n&&("point"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,r:0,opacity:0}):"rect"===r.type?this.prevPositionMap.set(n,{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}):"heatcell"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:0}):"line"===r.type?(r._introClipFraction=0,this.prevPathMap.set(n,{path:r.path.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})):"area"===r.type&&(r._introClipFraction=0,this.prevPathMap.set(n,{topPath:r.topPath.map(e=>[e[0],e[1]]),bottomPath:r.bottomPath.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})))}}startTransition(){let e=$n();if(!this.config.transition||!e)return;let t=e.startTransition(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(e){let t=$n();if(!this.activeTransition||!this.config.transition||!t)return!1;let i={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},r=t.advanceTransition(e,this.config.transition,i,this.prevPositionMap,this.prevPathMap);return this.scene=i.scene,this.exitNodes=i.exitNodes,this.activeTransition=i.activeTransition,r}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("glyph"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("rect"===t.type||"heatcell"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0);else if("candlestick"===t.type)void 0!==t._targetX&&(t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0);else if("line"===t.type||"area"===t.type){if(t._introClipFraction=void 0,"line"===t.type&&t._targetPath){for(let e=0;e<t.path.length;e++)t.path[e]=t._targetPath[e];t._prevPath=void 0,t._targetPath=void 0}if("area"===t.type){if(t._targetTopPath)for(let e=0;e<t.topPath.length;e++)t.topPath[e]=t._targetTopPath[e];if(t._targetBottomPath)for(let e=0;e<t.bottomPath.length;e++)t.bottomPath[e]=t._targetBottomPath[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(e){let{result:t,cache:i}=function(e,t,i,r){if(r&&r.version===i&&r.group===t&&r.data===e)return{result:r.result,cache:r};let n;if(t){let i=new Map;for(let r of e){let e=t(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}n=Array.from(i.entries()).map(([e,t])=>({key:e,data:t}))}else n=[{key:"_default",data:e}];return{result:n,cache:{version:i,group:t,data:e,result:n}}}(e,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=i,t}resolveColorMap(e){let{map:t,cache:i}=function(e,t,i,r,n){if(n&&n.version===r)return{map:n.map,cache:n};let o=new Set;if(t)for(let i of e){let e=t(i);e&&o.add(e)}let a=Array.from(o).sort(),s=a.join("\0");if(n&&n.key===s){let e={...n,version:r};return{map:e.map,cache:e}}let l=Qt(i.colorScheme,i.themeCategorical,Jt),c=new Map;for(let e=0;e<a.length;e++)c.set(a[e],no(i.colorScheme,a[e])??l[e%l.length]);return{map:c,cache:{key:s,map:c,version:r}}}(e,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=i,t}resolveLineStyle(e,t){return function(e,t,i,r){let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.stroke&&t){let i=r(t);if(i)return{...e,stroke:i}}return e}let o=e.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||o||"#007bff",strokeWidth:n.strokeWidth??2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity,cursor:n.cursor}:{stroke:r(t)||o||"#007bff",strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveAreaStyle(e,t){return function(e,t,i,r){if(e.areaStyle){let n=e.areaStyle(i||{});if(n&&!n.fill&&t){let e=r(t);if(e)return{...n,fill:e,stroke:n.stroke||e}}return n}let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.fill&&t){let i=r(t);if(i)return{...e,fill:i,stroke:e.stroke||i}}return e}let o=e.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||o||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||o||"#4e79a7",strokeWidth:n.strokeWidth??2,cursor:n.cursor};let a=r(t)||o||"#4e79a7";return{fill:a,fillOpacity:.7,stroke:a,strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveGroupColor(e){let{color:t,groupColorCounter:i}=function(e){let{group:t,colorMapCache:i,groupColorMap:r,groupColorMapCap:n,config:o}=e,{groupColorCounter:a}=e,s=no(o.colorScheme,t);if(s)return{color:s,groupColorCounter:a};if(i){let e=i.map.get(t);if(e)return{color:e,groupColorCounter:a}}let l=r.get(t);if(l)return{color:l,groupColorCounter:a};let c=Qt(o.colorScheme,o.themeCategorical,Jt);if(0===c.length)return{color:null,groupColorCounter:a};let u=c[a%c.length];if(a++,r.set(t,u),r.size>n){let e=r.keys().next().value;void 0!==e&&r.delete(e)}return{color:u,groupColorCounter:a}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:1e3,config:this.config});return this._groupColorCounter=i,t}getBufferArray(){return(this._bufferDirty||!this._bufferArrayCache)&&(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(e){if(!this.getPointId)throw new Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&$n()&&this.snapshotPositions();let t=bn(e),i=this.getPointId,r=e=>t.has(i(e));lo(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getPointId)throw new Error("update() requires pointIdAccessor to be configured");let i=bn(e),r=this.getPointId,n=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.buffer.forEach((e,t)=>{n.has(t)&&(this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.dirty&&this.xExtent.recalculate(this.buffer,this.getX),this.yExtent.dirty&&this.rebuildYExtent(),this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}positiveAxisSamples(e){let t=[];for(let i of this.buffer)t.push(e(i));return io(t)}plottedAggregateY(e,t){let i=this.config;if("bar"===i.chartType&&i.binSize)return function(e,t,i,r,n,o="start",a=[]){let s=mn(e,t,i,r,n,!1,o),l=[];if(!n){for(let e of s.values())l.push(e.total);return l}let c=new Set;for(let e of s.values())for(let t of e.categories.keys())c.add(t);let u=new Set(a),d=[...a.filter(e=>c.has(e)),...Array.from(c).filter(e=>!u.has(e)).sort()];for(let e of s.values()){if(0===e.categories.size){l.push(e.total);continue}let t=0;for(let i of d){let r=e.categories.get(i);null==r||0===r||(t+=r,l.push(t))}}return l}(e,this.getX,this.getY,i.binSize,this.getCategory,i.binAlign,i.barColors?Object.keys(i.barColors):[]);if("stackedarea"===i.chartType&&e.size>0){let r=Qn({config:i,groups:this.groupData(t),getX:this.getX,getY:this.getY,bufferSize:e.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});return this._stackExtentCache=r.stackExtentCache,r.stackExtentCache.plottedY??null}return"waterfall"===i.chartType&&e.size>0?Jn(e,this.getX,this.getY):null}warnDroppedLogSamples(e,t){if(t){if("x"===e){if(this._warnedNonPositiveLogX)return;this._warnedNonPositiveLogX=!0}else{if(this._warnedNonPositiveLogY)return;this._warnedNonPositiveLogY=!0}console.warn(`Semiotic log ${e} scale clamped non-positive values to the positive domain edge.`)}}clear(){this.buffer.clear(),this.resolveXAccessor(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in e||"colorScheme"in e)&&(this._barCategoryCache=null),("normalize"in e||"extentPadding"in e||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e||"boundsAccessor"in e||"band"in e||"y0Accessor"in e||"openAccessor"in e||"highAccessor"in e||"lowAccessor"in e||"closeAccessor"in e||"groupAccessor"in e||"categoryAccessor"in e||"chartType"in e||"runtimeMode"in e)&&(this._stackExtentCache=null);let r=!1,n=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let o="chartType"in e&&e.chartType!==t.chartType||"runtimeMode"in e&&e.runtimeMode!==t.runtimeMode;if(o||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){let e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=e&&this.config.timeAccessor||this.config.xAccessor,a=e&&t.timeAccessor||t.xAccessor,s=e&&this.config.valueAccessor||this.config.yAccessor,l=e&&t.valueAccessor||t.yAccessor,c=o||!G(i,a),u=o||!G(s,l);(c||u)&&(c&&this.resolveXAccessor(),this.getY=e?V(this.config.valueAccessor||this.config.yAccessor,"value"):V(this.config.yAccessor,"y"),u&&this.resolvedRibbons.some(e=>"bounds"===e.kind)&&(this.resolvedRibbons=En(this.config)),r=!0,n=!0)}if("groupAccessor"in e&&!G(e.groupAccessor,t.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?U(this.config.groupAccessor):void 0,r=!0),"categoryAccessor"in e&&!G(e.categoryAccessor,t.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?U(this.config.categoryAccessor):void 0,r=!0),"sizeAccessor"in e&&!G(e.sizeAccessor,t.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?V(this.config.sizeAccessor,"size"):void 0,r=!0),"symbolAccessor"in e&&!G(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?U(this.config.symbolAccessor):void 0,r=!0),"colorAccessor"in e&&!G(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?U(this.config.colorAccessor):void 0,r=!0),"y0Accessor"in e&&!G(e.y0Accessor,t.y0Accessor)&&(this.getY0=this.config.y0Accessor?V(this.config.y0Accessor,"y0"):void 0,r=!0,n=!0),("boundsAccessor"in e&&!G(e.boundsAccessor,t.boundsAccessor)||"band"in e&&e.band!==t.band||"boundsStyle"in e&&e.boundsStyle!==t.boundsStyle)&&(this.resolvedRibbons=En(this.config),r=!0,n=!0),"pointIdAccessor"in e&&!G(e.pointIdAccessor,t.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?U(this.config.pointIdAccessor):void 0,r=!0),"candlestick"===this.config.chartType&&(o||"openAccessor"in e&&!G(e.openAccessor,t.openAccessor)||"closeAccessor"in e&&!G(e.closeAccessor,t.closeAccessor)||"highAccessor"in e&&!G(e.highAccessor,t.highAccessor)||"lowAccessor"in e&&!G(e.lowAccessor,t.lowAccessor))){let e=null!=this.config.openAccessor,t=null!=this.config.closeAccessor;this.getOpen=e?V(this.config.openAccessor,"open"):void 0,this.getHigh=V(this.config.highAccessor,"high"),this.getLow=V(this.config.lowAccessor,"low"),this.getClose=t?V(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!t,r=!0,n=!0}if("accessorRevision"in e&&e.accessorRevision!==t.accessorRevision&&(this.resolveXAccessor(),r=!0,n=!0),!r){let i=Object.keys(e).filter(e=>!e.endsWith("Accessor")&&"timeAccessor"!==e&&"valueAccessor"!==e);for(let n of i)if(e[n]!==t[n]){r=!0;break}}r&&(n&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(i,("bar"===this.config.chartType||"heatmap"===this.config.chartType)&&!this.config.trackHoverRows&&hr(t.areaStyle)!==hr(this.config.areaStyle))}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function Ro(e,t,i,r){return"function"==typeof t.style?t.style(r||{},i):t.style&&"object"==typeof t.style?t.style:e.resolveBoundsStyle(i,r)}function No(e,t,i,r){if(!e.scales)return null;let{topPath:n,bottomPath:o,datum:a,pathIds:s}=Yn(t,e.scales,e.getX,r.getTop,r.getBottom,e.getPointId);return n.length<2?null:{type:"area",topPath:n,bottomPath:o,...s&&{pathIds:s},...e.config.curve&&"linear"!==e.config.curve&&{curve:e.config.curve},style:Ro(e,r,i,dr(t)),datum:a,group:i,interactive:r.interactive}}function Do(e){let t=[],i=[];if(!e)return{perSeries:t,aggregate:i};for(let r of e)r.perSeries?t.push(r):i.push(r);return{perSeries:t,aggregate:i}}function Fo(e,t,i){let r=[];for(let n of i){let i=No(e,t,"__ribbon_aggregate",n);i&&r.push(i)}return r}function Eo(e,t,i,r){let n=[];for(let o of r){let r=No(e,t,i,o);r&&n.push(r)}return n}function Oo(e,t,i,r){if(!e.config.pointStyle)return;let n=r??e.getY;for(let r of t){let t=e.resolveGroupColor(r.key);for(let o of r.data){let r=e.config.pointStyle(o);!r.fill&&t&&(r={...r,fill:t});let a=r.r??3,s=e.getPointId?String(e.getPointId(o)):void 0,l=Vn(o,e.scales,e.getX,n,a,r,s);l&&i.push(l)}}}function zo(e){return"threshold"===e.type&&"string"==typeof e.color&&"number"==typeof e.value}function Bo(e){return gi(e)}function jo(e,t){if("domain"!==e.extent)return;let[i,r]=t.domain(),n=t(r),o=t(i);return Number.isFinite(n)&&Number.isFinite(o)?[n,o]:void 0}function Wo(e,t){let i=[],r="bubble"===e.config.chartType?10:5,n=e.config.sizeRange||[3,15],o=null;if(e.getSize&&!e.config.pointStyle){let i=t.map(t=>e.getSize(t)).filter(e=>null!=e&&!Number.isNaN(e));if(i.length>0){let e=1/0,t=-1/0;for(let r of i)r<e&&(e=r),r>t&&(t=r);o=i=>e===t?(n[0]+n[1])/2:n[0]+(i-e)/(t-e)*(n[1]-n[0])}}let a=e.getColor?e.resolveColorMap(t):null,s=e.config.themeSemantic?.primary||"#4e79a7",l=e.getSymbol,c=l?d(l,e.config.symbolMap):null;for(let n of t){let t=e.config.pointStyle?e.config.pointStyle(n):{fill:s,opacity:.8},l=t.r||r;if(o&&e.getSize){let t=e.getSize(n);null!=t&&!Number.isNaN(t)&&(l=o(t))}if(a&&e.getColor&&!t.fill){let i=e.getColor(n);i&&a.has(i)&&(t={...t,fill:a.get(i)})}let u=e.getPointId?String(e.getPointId(n)):void 0;if(c){let r=c(n),o=Hn(n,e.scales,e.getX,e.getY,Math.PI*l*l,r,t,u);o&&i.push(o)}else{let r=Vn(n,e.scales,e.getX,e.getY,l,t,u);r&&i.push(r)}}return i}import{scaleLinear as Yo}from"d3-scale";var qo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandTicks"),Xo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandCopy"),Go=/*#__PURE__*/Symbol.for("semiotic.heatmapBandKeys"),Vo=/*#__PURE__*/Symbol.for("semiotic.heatmapBandKeyIndex"),Ho=/*#__PURE__*/Symbol.for("semiotic.heatmapBandDirection");function Uo(e){if(!e)return null;let t=e[qo];return t&&t.length>0?t:null}function Zo(e,t){Object.defineProperty(e,qo,{value:t,enumerable:!1,configurable:!0});let i=e;if("function"==typeof i.copy&&!i[Xo]){let e=i.copy;Object.defineProperty(i,Xo,{value:!0}),i.copy=function(){return Zo(e.call(this),t)}}return e}function Ko(e,t,i){return Zo(Yo().domain(i??[-.5,Math.max(e.length-.5,.5)]).range(t),e.map((e,t)=>({value:t,label:e})))}function Qo(e,t){let i=[-.5,Math.max(e.length-.5,.5)],r=function(e){return 0===e.length?null:e.every(e=>"number"==typeof e&&Number.isFinite(e))?e.slice():e.every(e=>e instanceof Date&&Number.isFinite(e.getTime()))?e.map(e=>e.getTime()):null}(e);if(!t||!r)return i;let n=(e,t)=>null!=e&&Number.isFinite(e)?ra(r,e)??t:t,o=n(t[0],i[0]),a=n(t[1],i[1]);return o===a?i:[o,a]}function Jo(e,t){if(t instanceof Date){let i=t.getTime();return Number.isFinite(i)?e.find(e=>e.label instanceof Date&&e.label.getTime()===i)?.value??null:null}if("number"==typeof t&&Number.isFinite(t)){let i=e.find(e=>"number"==typeof e.label&&e.label===t);return i?i.value:e.find(e=>e.label instanceof Date&&e.label.getTime()===t)?.value??null}return"string"==typeof t?e.find(e=>"string"==typeof e.label&&e.label===t)?.value??null:null}function ea(e,t){if(!e)return null;let i=Uo(e);if(!i)return e(t);let r=Jo(i,t);return null==r?null:e(r)}function ta(e,t,i){if("function"!=typeof e)return null;if(null==t){let t=e.domain?.()?.[i];if(null==t)return null;let r=e(t instanceof Date?t.getTime():Number(t));return Number.isFinite(r)?r:null}let r=ea(e,t);return null!=r&&Number.isFinite(r)?r:null}function ia(e,t){return"number"==typeof t&&Number.isFinite(t)?function(e,t){let i=t instanceof Date?t.getTime():t;if(!e||!Number.isFinite(i))return null;let r=Uo(e);if(!r)return e(i);let n=function(e){let t=e;if(Go in t)return t[Go]??null;let i=null;return e.every(e=>"number"==typeof e.label&&Number.isFinite(e.label))?i=e.map(e=>e.label):e.every(e=>e.label instanceof Date&&Number.isFinite(e.label.getTime()))&&(i=e.map(e=>e.label.getTime())),Object.defineProperty(t,Go,{value:i}),i}(r);if(!n)return e(i);let o=function(e,t){let i=e,r=i[Vo];if(r)return r;let n=new Map;for(let e=0;e<t.length;e++)n.set(t[e],e);return Object.defineProperty(i,Vo,{value:n}),n}(r,n).get(i);if(null!=o)return e(o);let a=ra(n,i);return null==a?null:e(a)}(e,t):ea(e,t)}function ra(e,t){if(e.length<2)return 1===e.length?t-e[0]:null;let i=function(e){let t=e,i=t[Ho];if(null!=i)return i;let r=0;for(let t=1;t<e.length;t++){let i=e[t]-e[t-1];if(0===i){r=0;break}let n=i>0?1:-1;if(0===r)r=n;else if(r!==n){r=0;break}}return Object.defineProperty(t,Ho,{value:r}),r}(e);if(1===i||-1===i)return function(e,t,i){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;(1===i?e[o]<t:e[o]>t)?r=o+1:n=o}if(0===r)return(t-e[0])/(e[1]-e[0]);let o=e.length-1;return r>=e.length?o+(t-e[o])/(e[o]-e[o-1]):r-1+(t-e[r-1])/(e[r]-e[r-1])}(e,t,i);for(let i=0;i<e.length-1;i++){let r=e[i],n=e[i+1];if(r===n)continue;let o=Math.min(r,n),a=Math.max(r,n);if(t>=o&&t<=a)return i+(t-r)/(n-r)}let r=e[1]-e[0];if(0!==r&&(t-e[0])/r<0)return(t-e[0])/r;let n=e.length-1,o=e[n]-e[n-1];return 0!==o&&(t-e[n])/o>0?n+(t-e[n])/o:null}var na=/*#__PURE__*/new Map;function oa(e,t,i){return t===i?Math.floor(128):Math.min(Math.floor(255*(e-t)/(i-t)+.5),255)}function aa(e){let t=Object.prototype.hasOwnProperty.call(Bt,e)?e:"blues",i=na.get(t);if(i)return i;i=new Array(256);let r=jt(t);for(let e=0;e<256;e++)i[e]=r(e/255);return na.set(t,i),i}function sa(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?{key:t,label:e,numeric:!0,temporal:!0}:{key:"Invalid Date",label:"Invalid Date",numeric:!1,temporal:!1}}return"number"==typeof e&&Number.isFinite(e)?{key:e,label:e,numeric:!0,temporal:!1}:{key:String(e),label:String(e),numeric:!1,temporal:!1}}function la(e,t){let i=t.map((e,t)=>({label:e,previous:t})).sort((e,t)=>ca(e.label)-ca(t.label)),r=new Map;i.forEach((e,t)=>r.set(e.previous,t));let n=Array.from(e.keys());e.clear();for(let t=0;t<n.length;t++)e.set(n[t],r.get(t));t.length=i.length;for(let e=0;e<i.length;e++)t[e]=i[e].label}function ca(e){return e instanceof Date?e.getTime():Number(e)}function ua(e,t,i){let r=i.config.areaStyle?.(t);return r&&("string"==typeof r.fill&&(e.fill=r.fill),e.style=r),e}function da(e,t,i){let r=Math.max(1,Math.floor(e.config.heatmapXBins??20)),n=Math.max(1,Math.floor(e.config.heatmapYBins??20)),o=e.config.heatmapAggregation??"count",a=V(e.config.valueAccessor,"value");if(!e.scales||0===t.length)return[];let[s,l]=e.scales.x.domain(),[c,u]=e.scales.y.domain(),d=(l-s||1)/r,h=(u-c||1)/n,p=r*n;if(p>1e6)return[];let f=new Int32Array(p),g=new Float64Array(p),m=e.config.trackHoverRows||hr(e.config.areaStyle)?new Map:void 0;for(let i=0;i<t.length;i++){let o=t[i],l=e.getX(o),u=e.getY(o);if(!isFinite(l)||!isFinite(u))continue;let p=Math.min(Math.floor((l-s)/d),r-1),y=Math.min(Math.floor((u-c)/h),n-1);if(p<0||y<0)continue;let x=y*r+p;f[x]++;let b=a(o);if(g[x]+=isFinite(b)?b:0,m){let e=m.get(x);e||(e=[],m.set(x,e)),e.push(o)}}let y=1/0,x=-1/0;for(let e=0;e<p;e++){if(0===f[e])continue;let t;switch(o){case"sum":t=g[e];break;case"mean":t=g[e]/f[e];break;default:t=f[e]}t<y&&(y=t),t>x&&(x=t)}if(!isFinite(y))return[];let b=e.config.heatmapColorScale,v="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",w=b?void 0:aa(v),S=i.width/r,k=i.height/n,A=e.config.showValues,M=e.config.heatmapValueFormat,$=[];for(let t=0;t<n;t++){let i=t*r;for(let a=0;a<r;a++){let r,l=i+a;if(0===f[l])continue;switch(o){case"sum":r=g[l];break;case"mean":r=g[l]/f[l];break;default:r=f[l]}let u=oa(r,y,x),p=b?b(r):w[u],v=A?{value:r,showValues:!0,valueFormat:M}:{value:r},_=s+(a+.5)*d,P=c+(t+.5)*h,I=lr({xi:a,yi:t,value:r,count:f[l],sum:g[l],xCenter:_,yCenter:P,agg:o},m?.get(l));$.push(ua(Zn(a*S,(n-1-t)*k,S,k,p,I,v),I,e))}}return $}function ha(e,t,i,r){let n=Math.min(t,i),o=Math.max(t,i);if(!(o>n))return[];let a=[],s=-1/0;for(let t of e){let e=Math.max(s,n),i=Math.min(t.upTo,o);if(i>e&&a.push({from:e,to:i,fill:t.fill}),s=t.upTo,s>=o)break}return s<o&&a.push({from:Math.max(s,n),to:o,fill:r}),a}var pa={line:function(e,t){let i=e.groupData(t),r=[],n=e.config.annotations?.filter(zo).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Do(e.ribbons);if(o.length>0&&r.push(...Fo(e,t,o)),n.length>0)for(let t of i)r.push(...Eo(e,t.data,t.key,n))}for(let t of i){let i=e.resolveLineStyle(t.key,dr(t.data)),o=qn(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);n&&n.length>0&&(o.colorThresholds=n),e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),r.push(o)}return Oo(e,i,r),r},area:function(e,t){let i=e.groupData(t),r=[];if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Do(e.ribbons);if(o.length>0&&r.push(...Fo(e,t,o)),n.length>0)for(let t of i)r.push(...Eo(e,t.data,t.key,n))}let n=e.scales.y.domain(),o=n[0],a=e.config.semanticLineStops?.filter(e=>Number.isFinite(e.offset)).map(e=>({value:n[0]+Math.max(0,Math.min(1,e.offset))*(n[1]-n[0]),color:e.color,opacity:e.opacity,thresholdType:"greater"})).sort((e,t)=>e.value-t.value),s=a&&a.length>0?(()=>{let t=a.reduce((e,t)=>(e.at(-1)?.value===t.value?e[e.length-1]=t:e.push(t),e),[]),i=[{from:n[0],to:t[0].value,color:t[0].color,opacity:t[0].opacity}];for(let e=0;e<t.length;e++)i.push({from:t[e].value,to:t[e+1]?.value??n[1],color:t[e].color,opacity:t[e].opacity});return i.map(({from:t,to:i,color:r,opacity:n})=>{let o=e.scales.y(t),a=e.scales.y(i);return{y:Math.min(o,a),height:Math.abs(a-o),color:r,...null!=n&&{opacity:n}}}).filter(e=>e.height>0)})():void 0,l=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i){let i=e.resolveAreaStyle(t.key,dr(t.data)),n=Xn(t.data,e.scales,e.getX,e.getY,o,i,t.key,l,e.getPointId),c=Bo(e.config.gradientFill);if(c){n.fillGradient=c;let t=jo(c,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),a&&a.length>0&&(n.colorThresholds=a,n.strokeColorBands=s),r.push(n)}return Oo(e,i,r),r},stackedarea:function(e,t){let i=e.groupData(t),r=e.config.stackOrder??"key",n=()=>i.sort((e,t)=>e.key<t.key?-1:e.key>t.key?1:0);if("input"!==r)if("key"===r)n();else if("asc"===r||"desc"===r||"insideOut"===r){let t=new Map;for(let r of i){let i=0;for(let t of r.data){let r=e.getX(t),n=e.getY(t);Number.isFinite(r)&&Number.isFinite(n)&&(i+=n)}t.set(r.key,i)}let n=(e,t)=>e<t?-1:e>t?1:0;if("asc"===r)i.sort((e,i)=>{let r=(t.get(e.key)??0)-(t.get(i.key)??0);return 0!==r?r:n(e.key,i.key)});else if("desc"===r)i.sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)});else{let e=[...i].sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)}),r=[],o=[],a=0,s=0;for(let i of e)a<s?(r.push(i),a+=t.get(i.key)??0):(o.push(i),s+=t.get(i.key)??0);i.length=0,i.push(...o.reverse(),...r)}}else n();let o=e.config.curve&&"linear"!==e.config.curve?e.config.curve:void 0,a=e.config.normalize?"zero":e.config.baseline??"zero",{nodes:s,stackedTops:l}=function(e,t,i,r,n,o,a,s="zero",l){let c=new Set,u=new Map;for(let t of e){let e=new Map;for(let n of t.data){let t=i(n),o=r(n);if(!Number.isFinite(t)||(c.add(t),!Number.isFinite(o)))continue;let a=e.get(t);a?(a.value+=o,a.sources?a.sources.push(n):a.sources=[a.datum,n]):e.set(t,{value:o,datum:n})}u.set(t.key,e)}let d,h=Array.from(c).sort((e,t)=>e-t);if(o){d=new Map;for(let t of h){let i=0;for(let r of e)i+=u.get(r.key)?.get(t)?.value||0;d.set(t,i||1)}}let p=Gn(h,e.map(e=>e.key),(e,t)=>u.get(e)?.get(t)?.value||0,s),f="diverging"===s&&!o,g=[],m=new Map,y=new Map,x=new Map,b=new Map;for(let e of h)y.set(e,p.get(e)??0),x.set(e,0),b.set(e,0);for(let i of e){let e=u.get(i.key),r=new Map,s=[],c=[],p=[],v=[],w=[],S=l?[]:void 0,k=!1,A=()=>{if(0!==s.length){if(s.length>=2){let e=k?s.map((e,t)=>t).sort((e,t)=>s[e][0]-s[t][0]):void 0,t=e?e.map(e=>v[e]):v,r={type:"area",topPath:e?e.map(e=>s[e]):s,bottomPath:e?e.map(e=>c[e]):c,rawValues:e?e.map(e=>p[e]):p,style:n(i.key,dr(i.data)),datum:t,accessibleDatum:e?e.map(e=>w[e]):w,group:i.key};S&&(r.pathIds=e?e.map(e=>S[e]):S),a&&(r.curve=a),g.push(r)}s=[],c=[],p=[],v=[],w=[],S=l?[]:void 0,k=!1}};for(let n of h){let a,l,u=e.get(n),h=void 0!==u,g=u?.value??0;if(o&&h&&(g/=d.get(n)),!h||!Number.isFinite(g)||0===g){A();continue}f?g>0?(a=x.get(n),l=a+g,x.set(n,l)):(a=b.get(n),l=a+g,b.set(n,l)):(a=y.get(n),l=a+g,y.set(n,l));let m=t.x(n),M=t.y(a),$=t.y(l);if(!Number.isFinite(m)||!Number.isFinite(M)||!Number.isFinite($)){A();continue}let _=u.sources,P=u.value,I=_?{..._[0],__aggregateValue:P,__aggregateCount:_.length,__aggregateRows:_}:u.datum;s.length>0&&m<s[s.length-1][0]&&(k=!0),s.push([m,$]),c.push([m,M]),v.push(I),p.push(P),S&&S.push(`x:${n}`),w.push(_?{x:n,value:P,group:i.key,observations:_.length}:I),r.set(n,l)}A(),m.set(i.key,r)}return{nodes:g,stackedTops:m}}(i,e.scales,e.getX,e.getY,(t,i)=>e.resolveAreaStyle(t,i),e.config.normalize,o,a,e.getPointId),c=s;if(e.config.pointStyle){let t=new WeakMap;for(let r of i){let i=l.get(r.key);if(i)for(let n of r.data){let r=e.getX(n),o=e.getY(n);null!=r&&!Number.isNaN(r)&&null!=o&&!Number.isNaN(o)&&i.has(r)&&t.set(n,i.get(r))}}Oo(e,i,c,i=>t.get(i)??e.getY(i))}return c},mixed:function(e,t){let i=e.groupData(t),r=[],n=e.config.areaGroups||new Set;if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=Do(e.ribbons);if(o.length>0&&r.push(...Fo(e,t,o)),n.length>0)for(let t of i)r.push(...Eo(e,t.data,t.key,n))}let o=e.scales.y.domain()[0],a=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i)if(n.has(t.key)){let i=e.resolveAreaStyle(t.key,dr(t.data)),n=Xn(t.data,e.scales,e.getX,e.getY,o,i,t.key,a,e.getPointId),s=Bo(e.config.gradientFill);if(s){n.fillGradient=s;let t=jo(s,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}else{let i=e.resolveLineStyle(t.key,dr(t.data)),n=qn(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}return Oo(e,i,r),r},scatter:Wo,bubble:Wo,heatmap:function(e,t,i){if(e.config.heatmapAggregation)return da(e,t,i);if(0===t.length)return[];let r=V(e.config.valueAccessor,"value"),n=H(e.config.xAccessor,"x"),o=H(e.config.yAccessor,"y"),a=new Map,s=new Map,l=[],c=[],u=new Array(t.length),d=new Array(t.length),h=!0,p=!0,f=!0,g=!0;for(let e=0;e<t.length;e++){let i=t[e],r=sa(n(i)),m=sa(o(i));u[e]=r.key,d[e]=m.key,r.numeric?r.temporal&&(h=!1):(h=!1,f=!1),m.numeric?m.temporal&&(p=!1):(p=!1,g=!1),a.has(r.key)||(a.set(r.key,a.size),l.push(r.label)),s.has(m.key)||(s.set(m.key,s.size),c.push(m.label))}let m=a.size,y=s.size;if(0===m||0===y)return[];let x=4096;if(h&&p&&m*y>x&&t.length>x){let r=new Set;for(let n=0;n<t.length;n++){let o=a.get(u[n]),l=s.get(d[n]);if(void 0!==o&&void 0!==l&&(r.add(l*m+o),r.size>x))return da({...e,config:{...e.config,heatmapAggregation:e.config.valueAccessor?"mean":"count"}},t,i)}}f&&la(a,l),g&&la(s,c);let b=new Float64Array(t.length),v=new Float64Array(t.length),w=new Array(t.length),S=new Map,k=0;for(let e=0;e<t.length;e++){let i=t[e],n=a.get(u[e]),o=s.get(d[e]);if(void 0===n||void 0===o)continue;let l,c=r(i),h=o*m+n,p=S.get(h);void 0!==p?l=p:(l=k++,S.set(h,l)),b[l]=h,v[l]=c,w[l]=i}let A=1/0,M=-1/0;for(let e=0;e<k;e++){let t=v[e];isFinite(t)&&(t<A&&(A=t),t>M&&(M=t))}if(!isFinite(A)||!isFinite(M))return[];let $="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",_=e.config.heatmapColorScale,P=_?void 0:aa($),I=e.config.showValues,T=Ko(l,[0,i.width],Qo(l,e.config.xExtent)),L=Qo(c,e.config.yExtent),C=Ko(c,[i.height,0],e.config.invertY?[L[1],L[0]]:L),R=(e,t)=>{let i=e(t-.5),r=e(t+.5);return[Math.min(i,r),Math.abs(r-i)]},N=e.config.heatmapValueFormat,D=[];for(let t=0;t<k;t++){let i=v[t];if(!isFinite(i))continue;let r=b[t],n=r%m,o=(r-n)/m,a=oa(i,A,M),s=_?_(i):P[a],l=I?{value:i,showValues:!0,valueFormat:N}:{value:i},c=w[t],[u,d]=R(T,n),[h,p]=R(C,o);D.push(ua(Zn(u,h,d,p,s,c,l),c,e))}return e.scales&&m>0&&y>0&&(e.scales.x=T,e.scales.y=C),D},bar:function(e,t){if(!e.config.binSize)return{nodes:[],binBoundaries:[]};let i=mn(t,e.getX,e.getY,e.config.binSize,e.getCategory,!!e.config.trackHoverRows||hr(e.config.areaStyle),e.config.binAlign);if(0===i.size)return{nodes:[],binBoundaries:[]};let r=null;if(e.getCategory){let t=new Set;for(let e of i.values())for(let i of e.categories.keys())t.add(i);let n=e.config.barColors?Object.keys(e.config.barColors):[],o=new Set(n),a=Array.from(t).filter(e=>!o.has(e)).sort(),s=n.filter(e=>t.has(e)),l=s.join("\0")+""+a.join("\0");e.barCategoryCache&&e.barCategoryCache.key===l?r=e.barCategoryCache.order:(r=[...s,...a],e.barCategoryCache={key:l,order:r})}let n=[],o=e.scales,[a,s]=o.x.domain(),l=e.config.barStyle,c=e.config.themeSemantic?.primary,u=l?.gap,d="number"==typeof u&&u>=0?u:1,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.cursor);let p=function(e){if(!Array.isArray(e))return;let t=e.filter(e=>!!e&&("string"==typeof e.fill||"object"==typeof e.fill&&null!==e.fill)),i=t.filter(e=>"number"==typeof e.upTo&&Number.isFinite(e.upTo)).map(e=>({upTo:e.upTo,fill:e.fill})).sort((e,t)=>e.upTo-t.upTo),r=t.find(e=>"number"!=typeof e.upTo||!Number.isFinite(e.upTo)),n=r?[...i,{upTo:1/0,fill:r.fill}]:i;return n.length>0?n:void 0}(l?.valueBands);for(let t of i.values()){let i=Math.max(t.start,a),u=Math.min(t.end,s);if(i>=u)continue;let f=o.x(i),g=o.x(u),m=Math.abs(g-f),y=m>d+1?d:0,x=Math.min(f,g)+y/2,b=Math.max(m-y,1);if(!(b<=0))if(r&&t.categories.size>0){let i=lr(r.flatMap(e=>{let i=t.categories.get(e)||0;return 0===i?[]:[lr({category:e,value:i},t.categoryRows?.get(e))]}),t.rows),a=0;for(let{category:r,value:s}of i){let u=o.y(a),d=o.y(a+s),p=Math.min(u,d),f=Math.abs(u-d),g=(e.config.barColors?ri(e.config.barColors,r):void 0)??l?.fill??c??"#4e79a7",m=lr({binStart:t.start,binEnd:t.end,total:t.total,category:r,categoryValue:s,categories:i},t.categoryRows?.get(r)),y=e.config.areaStyle?.(m)??{};n.push(Un(x,p,b,f,{fill:g,...h,...y},m,r)),a+=s}}else{let i=o.y(0),r=o.y(t.total),a=Math.min(i,r),s=Math.abs(i-r),u=l?.fill||c||"#007bff",d=lr({binStart:t.start,binEnd:t.end,total:t.total},t.rows),f=e.config.areaStyle?.(d)??{},g=Un(x,a,b,s,{fill:u,...h,...f},d);if(p){let e=g.style.fill,i="string"==typeof e||"object"==typeof e&&null!==e&&"hatch"===e.type?e:void 0,r=ha(p,0,t.total,i);r.length>0&&(g.fillBands=r.map(e=>({y0:o.y(e.from),y1:o.y(e.to),fill:e.fill??u})))}n.push(g)}}let f=new Set;for(let e of i.values())f.add(e.start),f.add(e.end);return{nodes:n,binBoundaries:Array.from(f).sort((e,t)=>e-t)}},swarm:function(e,t){let i=[],r=e.config.swarmStyle||{},n=r.radius??3,o=r.fill??e.config.themeSemantic?.primary??"#007bff",a=r.opacity??.7,s=r.stroke,l=r.strokeWidth,c=r.cursor;for(let r of t){let t=e.getX(r),u=e.getY(r);if(null==u||Number.isNaN(u))continue;let d=e.scales.x(t),h=e.scales.y(u),p=o;if(e.getCategory){let t=String(e.getCategory(r));p=(e.config.barColors?ri(e.config.barColors,t):void 0)??p}let{r:f,...g}=e.config.pointStyle?.(r)??{},m={type:"point",x:d,y:h,r:f??n,style:{fill:p,opacity:a,stroke:s,strokeWidth:l,cursor:c,...g},datum:r};e.getPointId&&(m.pointId=String(e.getPointId(r))),i.push(m)}return i},waterfall:function(e,t,i){let r=[],n=e.scales,o=e.config.waterfallStyle,a=t.filter(t=>{let i=e.getY(t),r=e.getX(t);return null!=i&&!Number.isNaN(i)&&null!=r&&isFinite(r)});if(0===a.length)return r;let s=o?.positiveColor??e.config.themeSemantic?.success??"#28a745",l=o?.negativeColor??e.config.themeSemantic?.danger??"#dc3545",c=o?.gap??1,u=o?.stroke,d=o?.strokeWidth,h=o?.opacity,p=0;for(let t=0;t<a.length;t++){let f=a[t],g=e.getX(f),m=e.getY(f),y=p+m,x=n.x(g),b=t>0?n.x(e.getX(a[t-1])):void 0,v=t<a.length-1?n.x(e.getX(a[t+1])):void 0,w=null!=b?(b+x)/2:null!=v?x-(v-x)/2:x-i.width/20,S=null!=v?(x+v)/2:null!=b?x+(x-b)/2:x+i.width/20,k=Math.min(w,S)+c/2,A=Math.max(w,S)-c/2-k;if(A<=0){p=y;continue}let M=n.y(p),$=n.y(y),_=Math.min(M,$),P=Math.abs(M-$),I=m>=0?s:l,T={...f,baseline:p,cumEnd:y,delta:m,_connectorStroke:o?.connectorStroke,_connectorWidth:o?.connectorWidth},L={fill:I,stroke:u,strokeWidth:d,opacity:h,cursor:o?.cursor,...e.config.areaStyle?.(T)};r.push(Un(k,_,A,P,L,T)),p=y}return r},candlestick:function(e,t,i){if(!e.getHigh||!e.getLow||!e.scales)return[];let r=e.config.candlestickRangeMode??!1;if(!(r||e.getOpen&&e.getClose))return[];let n=[],o=e.config.candlestickStyle||{},a=o.rangeColor||"#6366f1",s=r?a:o.upColor||"#28a745",l=r?a:o.downColor||"#dc3545",c=r?a:o.wickColor||"#333",u=o.wickWidth||(r?2:1),d=o.bodyWidth??0;if(null==o.bodyWidth){let i=t.map(t=>e.getX(t)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);if(i.length>1){let t=1/0,r=e.scales.x(i[0]);for(let n=1;n<i.length;n++){let o=e.scales.x(i[n]),a=Math.abs(o-r);a>0&&a<t&&(t=a),r=o}d=t!==1/0?Math.max(2,Math.min(.6*t,20)):6}else d=6}for(let a of t){let t=e.getX(a);if(null==t||Number.isNaN(t))continue;let h=e.getHigh(a),p=e.getLow(a);if(null==h||Number.isNaN(h)||null==p||Number.isNaN(p))continue;let f=r?h:e.getOpen(a),g=r?p:e.getClose(a);if(!r&&(null==f||Number.isNaN(f)||null==g||Number.isNaN(g)))continue;let m=g>=f,y=e.config.pointStyle?.(a)??{},x="string"==typeof y.fill?y.fill:void 0,b="string"==typeof y.stroke?y.stroke:void 0,v="number"==typeof y.strokeWidth?y.strokeWidth:void 0,w="number"==typeof y.opacity?y.opacity:"number"==typeof y.fillOpacity?y.fillOpacity:void 0,S={type:"candlestick",x:e.scales.x(t),openY:e.scales.y(f),closeY:e.scales.y(g),highY:e.scales.y(h),lowY:e.scales.y(p),bodyWidth:d,upColor:x&&m?x:s,downColor:x&&!m?x:l,wickColor:b??(r&&x?x:c),wickWidth:v??u,isUp:m,style:{cursor:o.cursor,...y,...void 0!==w&&{opacity:w}},datum:a};r&&(S.isRange=!0,S.dotRadius=Math.max(2,Math.min(d/2,.12*i.height))),n.push(S)}return n},custom:()=>[]};function fa(){for(let e of Object.keys(pa))In(e)||Pn({chartType:e,buildScene:pa[e],canvasRenderers:[]})}function ga(e){let t=e.parts.filter(e=>null!=e),i={};for(let e of t)for(let[t,r]of Object.entries(e.markCountByType))i[t]=(i[t]??0)+r;for(let[t,r]of Object.entries(e.additionalMarkCountByType??{}))r>0&&(i[t]=(i[t]??0)+r);let r=Object.values(i).reduce((e,t)=>e+t,0),n=0===r,o=Array.from(new Set([...t.flatMap(e=>e.warnings),...e.extraWarnings??[],...n?["EMPTY_SCENE"]:[]])),a="string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${r} marks`;return{component:"",frameType:e.frameType,status:n?"empty":"ok",empty:n,markCount:r,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:t.reduce((e,t)=>e+t.annotationCount,0),ariaLabel:a,warnings:o,semanticStatus:"not-assessed",semanticDiagnostics:[]}}function ma(e){let t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function ya(e){if(!e||e.length<2)return;let t=ma(e[0]),i=ma(e[e.length-1]);return null!==t&&null!==i?[t,i]:void 0}function xa(e){let{count:t,byType:i}=function(e){let t={};for(let i of e){let e="string"==typeof i?.type&&i.type.length>0?i.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),r=0===t,n=[...e.extraWarnings??[]];r&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),e.annotationRender&&e.annotationRender.unrenderedCount>0&&!n.includes("UNRENDERED_ANNOTATIONS")&&n.push("UNRENDERED_ANNOTATIONS");let o=Array.isArray(e.annotations)?e.annotations.length:0,a=e.annotationRender?.renderedCount??o,s="string"==typeof e.description&&e.description||un(e.title)||`${e.frameType} chart, ${t} marks`,l=e.margin,c=l?{x:l.left,y:l.top,width:Math.max(1,e.width-l.left-l.right),height:Math.max(1,e.height-l.top-l.bottom)}:void 0;return{component:"",frameType:e.frameType,status:r?"empty":"ok",empty:r,markCount:t,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:a,...e.annotationRender?.layout?{layout:e.annotationRender.layout}:{},...e.annotationRender?{annotationInputCount:e.annotationRender.inputCount,unrenderedAnnotationCount:e.annotationRender.unrenderedCount,...e.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:e.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:s,warnings:n,semanticStatus:"not-assessed",semanticDiagnostics:[],...l?{margin:l}:{},...c?{plot:c}:{}}}import*as ba from"react";import{area as va,line as wa}from"d3-shape";import{jsx as Sa,jsxs as ka}from"react/jsx-runtime";function Aa(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function Ma(e,t){let{background:i="transparent",stroke:r="#000",lineWidth:n=1.5,spacing:o=6,angle:a=45,lineOpacity:s=1}=e,l=function(e){let t=Number.isFinite(e)&&e>0?e:6;return{width:Math.max(8,t),height:t,lineY:t/2}}(o);return ka("pattern",{id:t,width:l.width,height:l.height,patternUnits:"userSpaceOnUse",patternTransform:0!==a?`rotate(${a})`:void 0,children:[i&&"transparent"!==i&&"none"!==i&&Sa("rect",{width:l.width,height:l.height,fill:i}),Sa("line",{x1:0,y1:l.lineY,x2:l.width,y2:l.lineY,stroke:r,strokeWidth:n,...1!==s?{strokeOpacity:s}:{}})]},t)}import{curveMonotoneX as $a,curveMonotoneY as _a,curveCardinal as Pa,curveCatmullRom as Ia,curveStep as Ta,curveStepBefore as La,curveStepAfter as Ca,curveBasis as Ra,curveNatural as Na}from"d3-shape";function Da(e){switch(e){case"monotoneX":return $a;case"monotoneY":return _a;case"cardinal":return Pa;case"catmullRom":return Ia;case"step":return Ta;case"stepBefore":return La;case"stepAfter":return Ca;case"basis":return Ra;case"natural":return Na;default:return null}}function Fa(e,t,i){let r=i;for(let i of t)"lesser"===i.thresholdType?e<i.value&&(r=i.color):e>i.value&&(r=i.color);return r}import*as Ea from"react";import{jsx as Oa,jsxs as za}from"react/jsx-runtime";var Ba={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function ja(e){return{opacity:e.opacity,fillOpacity:e.fillOpacity,strokeOpacity:e.strokeOpacity,stroke:e.stroke,strokeWidth:e.strokeWidth}}function Wa(e,t="#4e79a7"){return Aa(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function Ya(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`s_${t}`:t}function qa(e,t,i,r){let n=e.glyph;if(!n?.parts?.length||e.size<=0)return null;let o=h(n,e.size);if(o.scale<=0)return null;let a=`translate(${t},${i})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${o.offsetX},${o.offsetY}) scale(${o.scale})`,s=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),l=g(n,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),c=l?Ya(`${r}-clip`):void 0,u=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),d=t=>n.parts.map((i,r)=>{let n=t?"none"===i.fill?void 0:t:f(i.fill,s,e.accent),o=t?i.stroke&&"none"!==i.stroke?t:void 0:f(i.stroke??"none",s,e.accent);return n||o?Oa("path",{d:i.d,fill:n??"none",stroke:o,strokeWidth:o?i.strokeWidth??1:void 0,strokeLinecap:i.strokeLinecap,strokeLinejoin:i.strokeLinejoin,opacity:i.opacity},r):null});return za("g",{transform:a,opacity:1===u?void 0:u,children:[l&&c&&Oa("clipPath",{id:c,children:Oa("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&e.ghostColor?Oa("g",{children:d(e.ghostColor)}):null,l&&c?Oa("g",{clipPath:`url(#${c})`,children:d()}):d()]},r)}function Xa(e,t){let i=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return i.length<2?null:i.map((e,t)=>Oa("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}function Ga(e,t,i){let r=c(e.symbolType,e.size,e.path),n=e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`;return Oa("path",{d:r,transform:n,fill:e.style.fill?Wa(e.style.fill):"none",...ja(e.style),opacity:(e.style.opacity??1)*(e._decayOpacity??1)},`${i??""}symbol-${t}`)}function Va(e,t,i="",r="point"){let n=`${i?`${i}-`:""}${r}-${t}-hatch`,o=Aa(e.style.fill)?Ma(e.style.fill,n):void 0;return za(Ea.Fragment,{children:[o&&Oa("defs",{children:o}),Oa("circle",{cx:e.x,cy:e.y,r:e.r,fill:o?`url(#${n})`:Wa(e.style.fill),...ja(e.style),opacity:(e.style.opacity??1)*(e._decayOpacity??1)})]},`${i}${r}-${t}`)}function Ha(e,t,i){if("point"===e.type)return Va(e,t,i);let r=`${i?`${i}-`:""}xyrect-${t}-hatch`;if(e.fillBands&&e.fillBands.length>0)return function(e,t,i){let r=e.y,n=e.y+e.h,o=[],a=[];e.fillBands.forEach((t,s)=>{let l,c=Math.max(Math.min(t.y0,t.y1),r),u=Math.min(Math.max(t.y0,t.y1),n);if(u>c){if(Aa(t.fill)){let e=`${i}-band-${s}`;o.push(Ma(t.fill,e)),l=`url(#${e})`}else l=Wa(t.fill);a.push(Oa("rect",{x:e.x,y:c,width:e.w,height:u-c,fill:l,fillOpacity:e.style.fillOpacity},s))}});let s=e.style.stroke&&"none"!==e.style.stroke;return za("g",{opacity:e.style.opacity,children:[o.length>0&&Oa("defs",{children:o}),a,s&&Oa("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:e.style.stroke,strokeWidth:e.style.strokeWidth,strokeOpacity:e.style.strokeOpacity})]},`rect-${t}`)}(e,t,r);let n=Aa(e.style.fill)?Ma(e.style.fill,r):void 0;return za(Ea.Fragment,{children:[n&&Oa("defs",{children:n}),Oa("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:n?`url(#${r})`:Wa(e.style.fill),...ja(e.style)})]},`${e.type}-${t}`)}import*as Ua from"react";import{jsx as Za}from"react/jsx-runtime";function Ka(e){if(!1!==e?.interactive)return e?.style?.cursor}function Qa(e,t,i){let r=Ka(t);return r&&null!=e&&!1!==e?Za("g",{style:{cursor:r},"data-semiotic-mark-cursor":r,children:e},i):e}import{jsx as Ja,jsxs as es}from"react/jsx-runtime";function ts(e,t,i,r){if(!e||t.length<2)return null;let n=Xa(e.stops,r);return n?Ja("linearGradient",{id:i,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:n}):null}function is(e,t,i,r=30){let n=function(e,t,i,r=30){switch(e.type){case"line":{let r=e;if(0===r.path.length)return null;let n=Da(r.curve),o=n?wa().x(([e])=>e).y(([,e])=>e).curve(n)(r.path)??"":"M"+r.path.map(([e,t])=>`${e},${t}`).join("L"),a=Ya(`${i?`${i}-`:""}line-${t}-stroke-gradient`),s=function(e){return"string"==typeof e&&"none"===e.trim().toLowerCase()}(r.style.stroke),l=s?null:ts(r.strokeGradient,r.path,a,r.style.stroke||"#4e79a7");return es(ba.Fragment,{children:[l&&Ja("defs",{children:l}),Ja("path",{d:o,fill:"none",stroke:l?`url(#${a})`:s?"none":r.style.stroke||"#4e79a7",strokeWidth:s?0:r.style.strokeWidth??2,strokeDasharray:r.style.strokeDasharray,opacity:r.style.opacity,strokeOpacity:r.style.strokeOpacity})]},`line-${t}`)}case"area":{let n=e;if(0===n.topPath.length)return null;let o=Da(n.curve),a=o&&n.topPath.length>=2&&n.bottomPath.length>=2?va().x(([e])=>e).y0((e,t)=>n.bottomPath[t][1]).y1(([,e])=>e).curve(o)(n.topPath)??"":`M${n.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...n.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`,s=`${i?`${i}-`:""}area-${t}-hatch`,l=Aa(n.style.fill)?Ma(n.style.fill,s):void 0,c=Ya(`${i?`${i}-`:""}area-${t}-gradient`),u=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=1/0,n=-1/0;if(e.fillGradientSpan)[r,n]=e.fillGradientSpan;else{for(let[,t]of e.topPath)r=Math.min(r,t);for(let[,t]of e.bottomPath)n=Math.max(n,t)}if(!Number.isFinite(r)||!Number.isFinite(n))return null;let o=Xa(i.stops,Wa(e.style.fill));return o?Ja("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:r,x2:0,y2:n,children:o}):null}(n,c),d=u?`url(#${c})`:l?`url(#${s})`:Wa(n.style.fill),h=u?void 0:n.style.fillOpacity??.7,p=o?wa().x(([e])=>e).y(([,e])=>e).curve(o)(n.topPath)??"":"M"+n.topPath.map(([e,t])=>`${e},${t}`).join("L"),f=Ka(n),g=f&&r>=0?Ja("path",{d:p,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*r),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:f},"data-semiotic-mark-cursor":f,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${t}-cursor-target`):null,m=Ya(`${i?`${i}-`:""}area-${t}-stroke-gradient`),y=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),x=!!n.strokeColorBands?.length,b=y||x?null:ts(n.strokeGradient,n.topPath,m,n.style.stroke||"#4e79a7"),v=n.style.strokeWidth??2,w=1/0,S=-1/0;for(let[e]of n.topPath)e<w&&(w=e),e>S&&(S=e);let k=x?n.strokeColorBands.map((e,r)=>Ya(`${i?`${i}-`:""}area-${t}-stroke-band-${r}`)):[],A=x?n.strokeColorBands.map((e,t)=>Ja("clipPath",{id:k[t],children:Ja("rect",{x:w-v,y:e.y,width:S-w+2*v,height:e.height})},k[t])):null,M=n.style.stroke&&"none"!==n.style.stroke?x?n.strokeColorBands.map((e,i)=>Ja("path",{d:p,fill:"none",stroke:e.color??Wa(n.style.stroke),strokeWidth:v,opacity:(n.style.opacity??1)*(e.opacity??1),strokeOpacity:n.style.strokeOpacity,clipPath:`url(#${k[i]})`},`area-${t}-stroke-band-${i}`)):y?function(e,t,i,r){if(e.length<2||t.length!==e.length||0===i.length)return[];let n=[],o=(e,t,i)=>{let r=n[n.length-1];r?.color===e?r.path.push(i):n.push({color:e,path:[t,i]})};for(let n=1;n<e.length;n++){let[a,s]=e[n-1],[l,c]=e[n],u=t[n-1],d=t[n]-u,h=[0,...0===d?[]:i.map(({value:e})=>(e-u)/d).filter(e=>e>0&&e<1&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,i)=>0===t||e!==i[t-1]),1];for(let e=1;e<h.length;e++){let t=h[e-1],n=h[e];o(Fa(u+d*((t+n)/2),i,r),[a+(l-a)*t,s+(c-s)*t],[a+(l-a)*n,s+(c-s)*n])}}return n}(n.topPath,n.rawValues,n.colorThresholds,Wa(n.style.stroke)).map((e,i)=>Ja("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:v,opacity:n.style.opacity,strokeOpacity:n.style.strokeOpacity},`area-${t}-threshold-${i}`)):Ja("path",{d:p,fill:"none",stroke:b?`url(#${m})`:Wa(n.style.stroke),strokeWidth:v,opacity:n.style.opacity,strokeOpacity:n.style.strokeOpacity}):null;if(n.clipRect){let e=`${i?`${i}-`:""}area-clip-${t}`;return es("g",{children:[es("defs",{children:[u,!u&&l,b,A,Ja("clipPath",{id:e,children:Ja("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),es("g",{clipPath:`url(#${e})`,children:[Ja("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]})]},`area-${t}`)}return es(ba.Fragment,{children:[(u||l||b||A)&&es("defs",{children:[u,!u&&l,b,A]}),Ja("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]},`area-${t}`)}case"point":case"rect":return Ha(e,t,i);case"symbol":return Ga(e,t);case"glyph":{let r=e;return qa(r,r.x,r.y,`${i??""}glyph-${r.pointId??t}`)}case"heatcell":{let i=e,r={x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill,...ja(i.style??{})};if(i.showValues&&null!=i.value&&i.w>=20&&i.h>=20){let e=i.valueFormat?i.valueFormat(i.value):Number.isInteger(i.value)?String(i.value):Math.abs(i.value)>=100?i.value.toFixed(0):Math.abs(i.value)>=1?i.value.toFixed(1):i.value.toPrecision(3),[n,o,a]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(i.fill),s=.299*n+.587*o+.114*a>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h)));return es("g",{children:[Ja("rect",{...r}),Ja("text",{className:"semiotic-heatmap-value",x:i.x+i.w/2,y:i.y+i.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:`${l}px`,fontFamily:"var(--semiotic-font-family, sans-serif)",children:e})]},`heatcell-${t}`)}return Ja("rect",{...r},`heatcell-${t}`)}case"candlestick":{let r=e,n=`${i?`${i}-`:""}candle-${t}-hatch`,o=Aa(r.style?.fill)?Ma(r.style.fill,n):void 0,a=o?`url(#${n})`:void 0,{fill:s,...l}=r.style??{};if(l.opacity=(r.style?.opacity??1)*(r._decayOpacity??1),r.isRange){let e=r.dotRadius??Math.max(2,r.bodyWidth/2),i=a??r.wickColor;return es(ba.Fragment,{children:[o&&Ja("defs",{children:o}),es("g",{style:l,children:[Ja("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth}),Ja("circle",{cx:r.x,cy:r.highY,r:e,fill:i}),Ja("circle",{cx:r.x,cy:r.lowY,r:e,fill:i})]})]},`candle-${t}`)}let c=Math.min(r.openY,r.closeY),u=Math.max(Math.abs(r.openY-r.closeY),1),d=r.isUp?r.upColor:r.downColor,h=a??d;return es(ba.Fragment,{children:[o&&Ja("defs",{children:o}),es("g",{style:l,children:[Ja("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth}),Ja("rect",{x:r.x-r.bodyWidth/2,y:c,width:r.bodyWidth,height:u,fill:h,stroke:a?r.wickColor:d,strokeWidth:1})]})]},`candle-${t}`)}default:return null}}(e,t,i,r);return"area"===e.type?n:Qa(n,e,`xy-cursor-${t}`)}var rs=/*#__PURE__*/new Set;function ns(e){let{node:t,index:i,renderMode:r,fallback:n}=e,o=function(e,t){let i="function"==typeof e?e(t.datum??null,t):e;return function(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&"function"==typeof t.cacheKey&&"function"==typeof t.drawCanvas&&"function"==typeof t.renderStaticSVG}(i)?i:void 0}(r,t);if(!o)return{element:n(),renderedByBackend:!1};let a=o.renderStaticSVG({node:t,style:t.style??{},key:`${o.id}-${i}`});return null!=a?{element:Qa(a,t,`${o.id}-${i}-cursor`),renderedByBackend:!0}:(function(e,t){if("production"===process.env.NODE_ENV)return;let i=`${e}:${t}`;rs.has(i)||(rs.add(i),console.warn(`[Semiotic] Render backend "${e}" does not support scene node "${t}"; using the built-in renderer.`))}(o.id,t.type??"unknown"),{element:n(),renderedByBackend:!1})}function os(e){let t=[];return e.nodes.forEach((i,r)=>{let n=ns({node:i,index:r,renderMode:e.renderMode,fallback:()=>e.fallback(i,r)});null!==n.element&&void 0!==n.element&&!1!==n.element&&t.push({node:i,index:r,...n})}),t}import{scaleOrdinal as as}from"d3-scale";import{jsx as ss,jsxs as ls}from"react/jsx-runtime";function cs(e,t,i){if(t&&"object"==typeof t&&!Array.isArray(t)){let e=t;return t=>ri(e,t)??"#999"}let r=Array.isArray(t)?t:i.colors.categorical.length>0?i.colors.categorical:Ct;return as().domain(e).range(r)}function us(e,t,i){if(0===e.length)return;let r=cs(e,t,i);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:r(e.label)})}]}}function ds(e){return"left"===e?"start":"right"===e?"end":e??"start"}function hs(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function ps(e){return e.typography.legendFontFamily??e.typography.fontFamily}function fs(e){return e.typography.legendFontWeight}function gs(e,t,i,r){let n=hs(r);return t+i+Math.ceil(e.length*n*.58)}function ms(e){let{categories:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,itemGap:c,rowHeight:u}=De(a),d=s+l,h="top"===r||"bottom"===r,p=Math.max(s,n-o.left-o.right),f=t.map(e=>gs(e,s,l,i));if(h){let e=Math.max(s,a?.maxWidth??p),i=[],r=0,n=0;f.forEach((t,o)=>{let a=0===n?t:n+c+t;n>0&&a>e?(i.push({start:r,end:o,width:n}),r=o,n=t):n=a}),t.length>0&&i.push({start:r,end:t.length,width:n});let o=ds(a?.align),l=[];return i.forEach((i,r)=>{let n="center"===o?Math.max(0,(e-i.width)/2):"end"===o?Math.max(0,e-i.width):0;for(let e=i.start;e<i.end;e++)l.push({category:t[e],width:f[e],x:n,y:r*u}),n+=f[e]+c}),{items:l,width:i.reduce((e,t)=>Math.max(e,t.width),0),height:i.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}let g=f.reduce((e,t)=>Math.max(e,t),0);return{items:t.map((e,t)=>({category:e,width:f[t],x:0,y:t*u})),width:g,height:t.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}function ys(e,t){if(!t||!e||0===e.length)return[];let i="function"==typeof t?t:e=>e[t],r=new Set;for(let t of e){let e=i(t);null!=e&&r.add(String(e))}return Array.from(r)}import*as xs from"react";var bs=(e,t)=>({width:Array.from(e).length*t.size*.65,height:1.2*t.size,ascent:.9*t.size,source:"estimated"});function vs(e){let{desired:t,minGaps:i,weights:r}=e,n=t.length;if(0===n)return[];if(i.length!==Math.max(0,n-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let o=new Array(n).fill(0);for(let e=1;e<n;e++)o[e]=o[e-1]+Math.max(0,Number.isFinite(i[e-1])?i[e-1]:0);let a=[];for(let e=0;e<n;e++){let i=Math.max(Number.EPSILON,Number.isFinite(r?.[e])?r[e]:1),n=(Number.isFinite(t[e])?t[e]:0)-o[e];for(a.push({start:e,end:e,weight:i,mean:n});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.mean<=e.mean)break;let i=t.weight+e.weight;a.splice(a.length-2,2,{start:t.start,end:e.end,weight:i,mean:(t.mean*t.weight+e.mean*e.weight)/i})}}let s=Number.isFinite(e.min)?e.min:-1/0,l=Number.isFinite(e.max)?e.max-o[n-1]:1/0,c=l<s?s:l,u=new Array(n);for(let e of a){let t=Math.max(s,Math.min(c,e.mean));for(let i=e.start;i<=e.end;i++)u[i]=t+o[i]}return u}var ws={INVALID_PROJECTION:"Check endpoint values and the scale domain, especially log-scale values.",INSUFFICIENT_SPACE:"Increase chart height or the label-side margin, or reduce the label font size.",TIED_ENDPOINTS:"Use connectors or a legend to distinguish series sharing an endpoint.",LABEL_OMITTED:"Consult the accessible series list; increase the label rail space to restore visible labels.",ESTIMATED_METRICS:"Load the intended font and remeasure before asserting collision-free text.",RENDER_FAILURE:"Inspect the annotation renderer; the placed label did not produce a node.",UNSUPPORTED_GEOMETRY:"Inspect custom-rendered text; its geometry has not been measured by the label solver.",LABEL_COLLISION:"Increase spacing or shorten the affected labels.",LABEL_OVERFLOW:"Increase the allocated bounds or shorten the affected labels."};import{jsx as Ss,jsxs as ks}from"react/jsx-runtime";function As(e){return"string"==typeof e&&e.includes("var(")}var Ms=/^\s*var\(\s*--[^,)\s]+\s*(?:,\s*([\s\S]*))?\)\s*$/;function $s(e){let t=Ms.exec(e);if(!t)return As(e)?void 0:e;let i=t[1]?.trim();return i?$s(i):void 0}import{jsx as _s,jsxs as Ps}from"react/jsx-runtime";var Is="var(--semiotic-bg, #ffffff)";function Ts(e,t){return String(e).length*t*.6}function Ls(e){let{x:t,y:i,text:r,fill:n,fontSize:o=12,fontWeight:a,fontFamily:s,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{...e,type:e.type??"halo"}}(u),p=e=>_s("text",{x:t,y:i,textAnchor:l,dominantBaseline:c,fill:n,fontSize:o,fontWeight:a,fontFamily:s,className:d,...e?{style:{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}}:{},children:r});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??Is,strokeWidth:h.haloWidth??3});let f,g,m=h.padding??{x:6,y:3},y="number"==typeof m?m:m.x,x="number"==typeof m?m:m.y,b=Ts(r,o),v=b+2*y,w=o+2*x;f="middle"===l?t-b/2-y:"end"===l?t-b-y:t-y,g="middle"===c||"central"===c?i-w/2:"hanging"===c||"text-before-edge"===c?i-x:i-.8*o-x;let S=h.fill??Is,k={};return As(S)&&(k.fill=S),As(h.stroke)&&(k.stroke=h.stroke),Ps("g",{className:d,children:[_s("rect",{x:f,y:g,width:v,height:w,rx:h.radius??3,ry:h.radius??3,fill:As(S)?$s(S):S,fillOpacity:h.opacity??.85,stroke:As(h.stroke)?$s(h.stroke):h.stroke,strokeWidth:h.strokeWidth,...k.fill||k.stroke?{style:k}:{}}),p()]})}import{jsx as Cs}from"react/jsx-runtime";function Rs(e,t,i){if(!e)return null;let r="object"==typeof e?e:{};return Cs("circle",{className:"semiotic-threshold-end-cap",cx:t[0],cy:t[1],r:Math.max(0,r.radius??4),fill:r.fill??i})}import{jsx as Ns,jsxs as Ds}from"react/jsx-runtime";function Fs({ann:e,position:t,vertical:i,width:r,height:n,color:o,fontSize:a=12,fontFamily:s,bold:l,background:c,dash:u="6,3",labelGap:d=4}){let h=e.labelPosition,p=t>.6*r,f=i?t+(p?-4:4):"left"===h?4:"center"===h?r/2:r-4,g=i?"bottom"===h?n-4:"center"===h?n/2:16:t<20?Math.min(n-4,t+16):t-d,m=i?p?"end":"start":"left"===h?"start":"center"===h?"middle":"end",y=i?[t,0]:[0,t],x=i?[t,n]:[r,t];return Ds("g",{opacity:e.opacity,children:[Ns("line",{x1:y[0],y1:y[1],x2:x[0],y2:x[1],stroke:o,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||u}),Rs(e.endCap,y,o),e.label&&Ns(Ls,{x:f,y:g,text:e.label,textAnchor:m,fill:e.labelColor??o,fontSize:a,fontFamily:s,fontWeight:l?"bold":void 0,background:c??e.labelBackground??"halo"})]})}function Es(e){return{label:e.label,title:e.title,wrap:e.wrap||120,noWrap:"function"==typeof e._noteLayout?e.noWrap:void 0,_noteLayout:e._noteLayout}}function Os(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}function zs(e,t,i){if(!e)return[];let r=Math.max(1,Math.floor(t/i)),n=[],o="";for(let t of e.split(/\s+/))t&&(o&&o.length+1+t.length>r?(n.push(o),o=t):o=o?`${o} ${t}`:t);return o&&n.push(o),n}import{jsx as Bs,jsxs as js}from"react/jsx-runtime";function Ws(e,t,i,r){return"curly"===e?r?`M0,0 C${.6*i},0 ${.4*i},${t/2} ${i},${t/2} C${.4*i},${t/2} ${.6*i},${t} 0,${t}`:`M0,0 C0,${.6*i} ${t/2},${.4*i} ${t/2},${i} C${t/2},${.4*i} ${t},${.6*i} ${t},0`:r?`M0,0 L${i},0 L${i},${t} L0,${t}`:`M0,0 L0,${i} L${t},${i} L${t},0`}function Ys(e,t,i,r){if(!e)return Bs("g",{className:"annotation-note"});let{label:n,title:o,orientation:a,align:s,wrap:l=120,noWrap:c}=e;if(!n&&!o)return Bs("g",{className:"annotation-note"});let u=a;u||(u=Math.abs(t)>Math.abs(i)?"leftRight":"topBottom");let d="topBottom"===u,h="leftRight"===u,p=s;(!p||"dynamic"===p)&&(p=d?t>=0?"left":"right":i>=0?"top":"bottom");let f="start";d?"right"===p?f="end":"middle"===p&&(f="middle"):f=t>=0?"start":"end";let g=e.useHTML||e.html,m=g?void 0:Os(e),y=m?.lineHeight??16,x=m?.titleLines??(o?c?[o]:zs(o,l,8):[]),b=m?.labelLines??(n?c?[n]:zs(n,l,8):[]),v=x.length+b.length,w=h?"end"===f?-4:4:0,S=[],k=r||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";if(g){let e=l,t=Math.max(y,v*y+(o&&n?2:0)),i="end"===f?w-e:"middle"===f?w-e/2:w,r="end"===f?"right":"middle"===f?"center":"left";S.push(Bs("foreignObject",{className:"annotation-note-html",x:i,y:-y,width:e,height:t+y,style:{overflow:"visible"},children:js("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:k,fontSize:"12px",lineHeight:`${y}px`,overflow:"visible",textAlign:r,whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[o&&Bs("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:o}),n&&Bs("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html"))}else for(let e of[!0,!1]){let t=e?x:b;if(0===t.length)continue;let i="annotation-note-"+(e?"title":"label");S.push(Bs("text",{className:i,fill:k,textAnchor:f,fontWeight:e?m?.titleFontWeight??"bold":void 0,y:e?void 0:x.length*y,children:t.map((e,t)=>Bs("tspan",{x:w,dy:0===t?0:y,children:e},t))},i))}let A=null;if((o||n)&&(0!==t||0!==i)){let e=d?m?m.width:Math.min(l,120):(x.length+b.length+(b.length>0?1:0))*y,t=d?f:p,i="end"===t||"bottom"===t?-e:"middle"===t?-e/2:0;A=Bs("line",{className:"note-line",x1:d?i:0,x2:d?i+e:0,y1:d?0:i,y2:d?0:i+e,stroke:r||"var(--semiotic-text-secondary, currentColor)"})}let M=Math.max(0,v-1)*y,$=b.length>0&&x.length>0?2:0,_=0;(d||h)&&(_=h&&"middle"===p?-(M+y+$)/2+y/2:i<0||h&&"bottom"===p?-(M+2):2+y);let P=0!==_?`translate(0,${_})`:void 0;return js("g",{className:"annotation-note",transform:`translate(${t},${i})`,...m?.textProps,children:[Bs("g",{className:"annotation-note-content",transform:P,children:S}),A]})}function qs(e,t,i,r,n){let o=null,a=i||"var(--semiotic-text-secondary, currentColor)";switch(e){case"callout-circle":{let e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&(o=Bs("circle",{r:e,fill:"none",stroke:a},"subject-circle"));break}case"callout-rect":{let e=t?.width||0,i=t?.height||0;(e>0||i>0)&&(o=Bs("rect",{width:e,height:i,fill:"none",stroke:a},"subject-rect"));break}case"callout-custom":o=t?.custom;break;case"xy-threshold":{let e=r||0,i=n||0,s=0,l=0,c=0,u=0;if(void 0!==t?.x)s=l=(t.x||0)-e,c=(t.y1||0)-i,u=(t.y2||0)-i;else if(void 0!==t?.y)c=u=(t.y||0)-i,s=(t.x1||0)-e,l=(t.x2||0)-e;else if(void 0!==t?.x1||void 0!==t?.x2)s=(t.x1||0)-e,l=(t.x2||0)-e;else{if(void 0===t?.y1&&void 0===t?.y2)break;c=(t.y1||0)-i,u=(t.y2||0)-i}o=Bs("line",{x1:s,y1:c,x2:l,y2:u,stroke:a,strokeDasharray:"5,5"},"threshold-line");break}case"bracket":{let e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&(o=Bs("path",{d:Ws(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:a},"bracket-path"));break}}return Bs("g",{className:"annotation-subject",children:o})}function Xs(e,t,i,r,n,o){let a,s,l=0,c=0;if("callout-circle"!==n&&"label"!==n||!o?.radius){if("callout-rect"===n&&o){let i=o.width||0,r=o.height||0;if(i>0||r>0){let n=i/2,o=r/2,a=e-n,s=t-o;if(0!==a||0!==s){let e=Math.abs(a),t=Math.abs(s),u=i/2,d=r/2,h=e*d>t*u?u/e:d/t;l=n+a*h,c=o+s*h}}}else if("bracket"===n&&o){let e=o.width,t=o.height,i=o.depth||30;void 0!==e?(l=e/2,c=i):void 0!==t&&(l=i,c=t/2)}}else{let i=(o.radius||0)+(o.radiusPadding||0);if(i>0&&(0!==e||0!==t)){let r=Math.atan2(t,e);l=Math.cos(r)*i,c=Math.sin(r)*i}}let u=e-l,d=t-c,h=Math.hypot(u,d);if(h>.5){let n=r||"var(--semiotic-text-secondary, currentColor)",o="curve"===i?.type,p=Math.atan2(d,u);if(o){let r=(l+e)/2,o=(c+t)/2,s=-d/h,f=u/h,g=(i?.curve??.25)*h,m=r+s*g,y=o+f*g;a=Bs("path",{className:"connector-curve",d:`M${l},${c}Q${m},${y} ${e},${t}`,fill:"none",stroke:n},"connector-line"),p=Math.atan2(y-c,m-l)}else a=Bs("line",{x1:l,y1:c,x2:e,y2:t,stroke:n},"connector-line");if("arrow"===i?.end){let e=.08888888888888889*Math.PI,t=l+10*Math.cos(p+e),i=c+10*Math.sin(p+e),r=l+10*Math.cos(p-e),o=c+10*Math.sin(p-e);s=Bs("path",{d:`M${l},${c}L${t},${i}L${r},${o}Z`,fill:n,stroke:"none"},"connector-arrow")}}return js("g",{className:"annotation-connector",children:[a,s]})}function Gs(e){let{x:t=0,y:i=0,dx:r,dy:n,nx:o,ny:a,note:s,connector:l,subject:c,type:u,color:d,className:h,disable:p,opacity:f,strokeDasharray:g,events:m={},"data-testid":y}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(i)?i[0]??0:i,v=Array.isArray(p)?p:[],w=r||0,S=n||0;null!=o&&(w=o-x),null!=a&&(S=a-b);let k="string"==typeof u?u:"label";if("bracket"===k&&c&&0===w&&0===S)if(void 0!==c.width){w=c.width/2;let e=c.depth||30;S=e+(e>=0?5:-5)}else if(void 0!==c.height){let e=c.depth||30;w=e+(e>=0?5:-5),S=c.height/2}return js("g",{className:`annotation ${h||""}`.trim(),transform:`translate(${x},${b})`,"data-testid":y,...null!=f&&{opacity:f},...g&&{strokeDasharray:g},...m,children:[!v.includes("connector")&&Xs(w,S,l,d,k,c),!v.includes("subject")&&qs(k,c,d,x,b),!v.includes("note")&&Ys(s,w,S,d)]})}function Vs(e){let{noteData:t}=e,{screenCoordinates:i}=t,r="string"==typeof t.type?t.type:"label",n=t.eventListeners||t.events||{};if(t.coordinates&&i){let e=t.nx||i[0][0]+(t.dx??0),n=t.ny||i[0][1]+(t.dy??0),o=i.map((i,o)=>{let a=Object.assign({},t,{note:0===o?t.note:{label:""},x:i[0],y:i[1],nx:e,ny:n});return Bs(Gs,{"data-testid":"semiotic-annotation",...a,type:r},`multi-annotation-${o}`)});return Bs("g",{children:o})}let o=t.note||{title:"none",label:t.label},a=`${o.label}-${o.title}-${t.i}`;return Bs(Gs,{"data-testid":"semiotic-annotation",events:n,...t,type:r},a)}import{jsx as Hs}from"react/jsx-runtime";var Us={secondary:0,primary:3};function Zs(e){return!0===e?._annotationDeferred}function Ks(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Qs(e){return"primary"===e?.emphasis||"secondary"===e?.emphasis?e.emphasis:null}function Js(e){let t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function el(e){return Math.max(.72,.95-.06*e)}function tl(e){let t=e.map((e,t)=>({p:e,i:t,emphasis:Qs(e.annotation),confidence:Js(e.annotation),readingOrder:null,rank:1})),i=t.some(e=>null!=e.emphasis||null!=e.confidence),r=e.some(e=>Zs(e.annotation)),n=e.some(e=>null!=Ks(e.annotation)),o=e.some(e=>"layer"===Ks(e.annotation));if(!i&&!r&&!n)return e.map(e=>e.node);let a=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);a.forEach((e,t)=>{e.readingOrder=t,e.rank=2-t/Math.max(1,a.length)});for(let e of t)e.emphasis&&(e.rank=Us[e.emphasis]);let s=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{let{p:t,i:i,emphasis:r,readingOrder:n}=e,o=Zs(t.annotation),a=t.node;if("primary"===r||"secondary"===r||null!=n){let e=null==r&&null!=n;a=Hs("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":`annotation-emphasis annotation-emphasis--${r}`,..."secondary"===r?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:el(n),"data-annotation-reading-order":n}:{},children:t.node},`annotation-emphasis-${i}`)}let s=Ks(t.annotation);return s&&(a=Hs("g",{className:`annotation-cohesion--${s}`,children:a},`annotation-cohesion-${i}`)),o&&(a=Hs("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:a},`annotation-deferred-${i}`)),a});return r&&s.unshift(Hs("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),o&&s.unshift(Hs("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),s}function il(e,t){let i=t.scales?.x??t.scales?.time;return i?null!=e.x?ea(i,e.x):t.xAccessor&&null!=e[t.xAccessor]?ea(i,e[t.xAccessor]):null:null}function rl(e,t){let i=t.scales?.y??t.scales?.value;return i?null!=e.y?ea(i,e.y):t.yAccessor&&null!=e[t.yAccessor]?ea(i,e[t.yAccessor]):null:null}function nl(e){return null==e?null:String(e)}function ol(e,t,i){return t.stickyPositionCache?.set(e,i),i}function al(e,t,i){let r=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===r){if(null!=e.pointId&&i.pointNodes&&i.pointNodes.length>0)for(let r=i.pointNodes.length-1;r>=0;r--){let n=i.pointNodes[r];if(n.pointId===e.pointId)return ol(t,i,{x:n.x,y:n.y})}let r=function(e){let t=e.data;if(!t||0===t.length)return null;let i=t[t.length-1],r=e.scales?.x??e.scales?.time,n=e.scales?.y??e.scales?.value;if(!r||!n)return null;let o=e.xAccessor||"x",a=e.yAccessor||"y",s=i[o],l=i[a];if(null==s||null==l)return null;let c=ea(r,s),u=ea(n,l);return null==c||null==u?null:{x:c,y:u}}(i);return r?ol(t,i,r):null}if("semantic"===r){let r=function(e,t,i){let r=function(e){return nl(e.provenance?.stableId??e.stableId)}(e);if(!r)return null;let n=i.pointNodes?.find(e=>nl(e.pointId)===r);if(n)return ol(t,i,{x:n.x,y:n.y});let o=i.data?.find(e=>function(e){return nl(e.stableId??e.id??e.provenance?.stableId)}(e)===r);if(!o)return null;let a=il(o,i),s=rl(o,i);return null==a||null==s?null:ol(t,i,{x:a,y:s})}(e,t,i);if(r)return r}let n=null,o=null;if(null!=e.pointId&&i.pointNodes){let t=i.pointNodes.find(t=>t.pointId===e.pointId);t&&(n=t.x,o=t.y)}if((null==n||null==o)&&(n=il(e,i),o=rl(e,i)),null!=n&&null!=o)return ol(t,i,{x:n,y:o});if("sticky"===r){let e=i.stickyPositionCache?.get(t);if(e)return e}return null}var sl=/*#__PURE__*/new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function ll(e){return!!e&&"object"==typeof e&&sl.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}function cl(e,t,i){return Math.max(t,Math.min(i,e))}function ul(e){return ll(e)}function dl(e){return"primary"===e?.emphasis||!0===e?.defensive}function hl(e,t,i={}){if("number"==typeof i.maxAnnotations&&Number.isFinite(i.maxAnnotations))return Math.max(0,Math.floor(i.maxAnnotations));if(!(e>0&&t>0))return 1/0;let r=i.areaPerAnnotation&&i.areaPerAnnotation>0?i.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/r))}function pl(e){let t,i=e?.emphasis;t="primary"===i?100:"secondary"===i?10:50;let r=e?.provenance?.confidence;switch("number"==typeof r&&Number.isFinite(r)&&(t+=15*cl(r,0,1)),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}var fl=32,gl=6,ml=4,yl=8,xl=72,bl={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function vl(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let i="string"==typeof t.source?Object.prototype.hasOwnProperty.call(bl,t.source)?bl[t.source]:t.source:null,r="number"==typeof t.confidence&&Number.isFinite(t.confidence)?`${Math.round(100*Math.max(0,Math.min(1,t.confidence)))}%`:null;if(!i&&!r||null!=e.label&&"string"!=typeof e.label)return e;let n=[i,r].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${n})`)?e:{...e,label:o?`${o} (${n})`:`(${n})`}}function wl(e){if(!Sl(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,i="string"==typeof e.shortText?e.shortText:void 0,r=t??i;return!r||"string"!=typeof e.label&&null!=e.label?e:{...e,label:r}}function Sl(e){return ll(e)}function kl(e,t,i,r,n){let o=e+i,a=t+r;return Math.abs(i)>Math.abs(r)?{x:i>=0?o+4:o-n.width-4,y:r<0?a-n.height:a,width:n.width,height:n.height}:{x:i>=0?o:o-n.width,y:r<0?a-n.height-4:a+4,width:n.width,height:n.height}}function Al(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Ml(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function $l(e,t,i,r,n,o,a,s){let l=Al(e,a),c=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,i,r){let n=Math.max(0,r-e.x),o=Math.max(0,r-e.y),a=Math.max(0,e.x+e.width-(t-r)),s=Math.max(0,e.y+e.height-(i-r));return(n+a)*e.height+(o+s)*e.width}(l,n,o,s);for(let e of i)c+=12*Ml(l,e);for(let e of r)c+=4*Ml(l,e);return c}function _l(e){let{annotations:t,context:i,defaultOffset:r=fl,notePadding:n=gl,markPadding:o=ml,edgePadding:a=yl,preserveManualOffsets:s=!0,routeLongConnectors:l=!0,connectorThreshold:c=xl,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:g,audience:m}=e,y=i.width||0,x=i.height||0,b="object"==typeof f?f:{},v=b.breakpoint??480,w=!!f&&y<=v,S=w&&!1!==b.preferShortText?t.map(wl):t,k=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!p?b.responsive??{minWidth:v}:p,$=w&&!g?b.cohesion:g;if(0===S.length||y<=0||x<=0)return S.slice();let _=[],P=function(e,t){return(e.pointNodes||[]).map(e=>{let i=Math.max(1,e.r||1)+t;return{x:e.x-i,y:e.y-i,width:2*i,height:2*i}})}(i,o),I=!1,T=S.map((e,t)=>{if(!Sl(e))return e;let o=function(e,t,i){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};let r=e.pointId??e.nodeId;if(null!=r&&i.pointNodes){let e=i.pointNodes.find(e=>e.pointId===r);if(e)return{x:e.x,y:e.y}}let n=e.coordinates,o=i.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&o){let e=n[0],t=n[1];if("number"==typeof e&&"number"==typeof t){let i=o([e,t]);if(i&&"number"==typeof i[0]&&"number"==typeof i[1])return{x:i[0],y:i[1]}}}return i.scales||"number"!=typeof e.x||"number"!=typeof e.y?al(e,t,i):{x:e.x,y:e.y}}(e,t,i);if(!o)return e;let u=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=Os(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let i="number"==typeof e.wrap?e.wrap:120,r=[...zs("string"==typeof e.title?e.title:void 0,i,7),...zs("string"==typeof e.label?e.label:void 0,i,7)],n=r.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(i,7*n)+10),height:Math.max(18,16*r.length+6)}}(!0===e.defensive?vl(e):e);if(s&&function(e){return"number"==typeof e.dx||"number"==typeof e.dy}(e)){let t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}(e),i="number"==typeof e.dx?e.dx:t.dx,r="number"==typeof e.dy?e.dy:t.dy;return _.push(Al(kl(o.x,o.y,i,r,u),n)),e}let d=null,h=1/0;for(let e of function(e){let t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}(r)){let t=$l(kl(o.x,o.y,e.dx,e.dy,u),e,_,P,y,x,n,a);t<h&&(d=e,h=t)}if(!d)return e;let p=Al(kl(o.x,o.y,d.dx,d.dy,u),n);_.push(p);let f=Math.hypot(d.dx,d.dy),g=l&&f>=c&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return I=!0,{...e,dx:d.dx,dy:d.dy,...g?{connector:g}:{}}}),L=I?T:S.slice(),C=L;if(h){let e=!1,t=L.map(t=>{let i=function(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,i="number"==typeof e.dy?e.dy:0;return Math.hypot(t,i)<8?e:{...e,_redundantConnector:!0}}(t);return i!==t&&(e=!0),i});C=e?t:L}{let e=!1,t=C.map(t=>{if(!0!==t?.defensive)return t;let i=vl(t);return i!==t&&(e=!0),i});C=e?t:C}let R,N=new Set;if(k){let e="object"==typeof k?k:{},t=function(e){if(!e)return 1;let t=function(e){let t=e?.familiarity;if(!t)return 3;let i=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===i.length?3:i.reduce((e,t)=>e+t,0)/i.length}(e);return t<=2?1.5:t>=4?.6:1}(m),i=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??hl(y,x,e))*t))},{deferred:r}=function(e){let{annotations:t,width:i,height:r}=e,n=Math.max(0,e.minVisible??1),o=hl(i,r,e),a=t.map((e,t)=>({annotation:e,index:t,note:ul(e)})),s=a.filter(e=>e.note);if(0===s.length||s.length<=o)return{visible:t.slice(),deferred:[],budget:o};let l=s.filter(e=>dl(e.annotation)),c=s.filter(e=>!dl(e.annotation)).sort((e,t)=>pl(t.annotation)-pl(e.annotation)||e.index-t.index),u=Math.max(0,o-l.length),d=Math.max(0,n-l.length),h=Math.min(c.length,Math.max(u,d)),p=new Set([...l.map(e=>e.index),...c.slice(0,h).map(e=>e.index)]),f=[],g=[];for(let{annotation:e,index:t,note:i}of a)!i||p.has(t)?f.push(e):g.push(e);return{visible:f,deferred:g,budget:o}}({annotations:C,width:y,height:x,...i});for(let e of r)N.add(e)}if(M){let e="object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:480;if(y<=e)for(let e of C)Sl(e)&&"secondary"===e.emphasis&&N.add(e)}if(N.size>0)for(let e of C)!0===e?.defensive&&N.delete(e);return R=0===N.size?C:A?C.map(e=>N.has(e)?{...e,_annotationDeferred:!0}:e):C.filter(e=>!N.has(e)),$?function(e,t){let i=!1,r=e.map(e=>Sl(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(i=!0,{...e,cohesion:t}):e);return i?r:e}(R,$):R}function Pl(e,t,i,r){let n=function(e,t,i="#4e79a7"){if(Aa(e)){let i=function(e,t){return`${e}-hatch-${v(function(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}(t)).toString(36)}`}(t,e);return{fill:`url(#${i})`,def:Ma(e,i)}}return e&&"string"==typeof e?{fill:e}:{fill:i}}(e.fill??e.color,t,r),o="string"==typeof e.fill&&e.fill?e.fill:"string"==typeof e.color&&e.color?e.color:r;return function(e,t,i,r){let n=function(e,t,i){if(!e||"object"!=typeof e)return;let r=e;if(!Array.isArray(r.stops))return;let n=r.stops.flatMap(e=>{if(!e||"object"!=typeof e)return[];let{offset:t,color:r,opacity:n}=e;return"number"==typeof t&&Number.isFinite(t)?[{offset:Math.max(0,Math.min(1,t)),color:"string"==typeof r&&r?r:i,opacity:"number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):void 0}]:[]}).sort((e,t)=>e.offset-t.offset);return n.length?{direction:"horizontal"===r.direction?"horizontal":"vertical"===r.direction?"vertical":t,stops:n}:void 0}(e,i,r);if(!n)return;let{direction:o,stops:a}=n,s=`${t}-gradient`;return{fill:`url(#${s})`,def:Sa("linearGradient",{id:s,x1:0,y1:0,x2:"horizontal"===o?"100%":0,y2:"vertical"===o?"100%":0,children:a.map((e,t)=>Sa("stop",{offset:100*e.offset+"%",stopColor:e.color,stopOpacity:e.opacity},`${e.offset}-${t}`))},s)}}(e.gradient,t,i,o)??n}var Il=/*#__PURE__*/new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Tl(e,t,i){let r=e.position,n="string"==typeof r&&Il.has(r)?r:"bottom-left",o=n.endsWith("left")?"left":n.endsWith("right")?"right":"center",a=n.startsWith("top")?"top":n.startsWith("bottom")?"bottom":"middle",s="top"===a?0:"bottom"===a?i:i/2;return{x:("left"===o?0:"right"===o?t:t/2)+("number"==typeof e.dx&&Number.isFinite(e.dx)?e.dx:0),y:s+("number"==typeof e.dy&&Number.isFinite(e.dy)?e.dy:0),textAnchor:"start"===e.textAnchor||"middle"===e.textAnchor||"end"===e.textAnchor?e.textAnchor:"left"===o?"start":"right"===o?"end":"middle",dominantBaseline:"auto"===e.dominantBaseline||"middle"===e.dominantBaseline||"hanging"===e.dominantBaseline?e.dominantBaseline:"top"===a?"hanging":"bottom"===a?"auto":"middle"}}function Ll(e,t,i,r){return{...Tl(e,t,i),fill:e.fill??e.color??r.fill,fontSize:e.fontSize??r.fontSize,fontFamily:e.fontFamily??r.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,letterSpacing:e.letterSpacing,opacity:e.opacity,className:e.className,style:{pointerEvents:"none"}}}import{jsx as Cl}from"react/jsx-runtime";var Rl={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Nl({annotation:e,width:t,height:i,defaults:r=Rl}){let n=e.label??e.text;return null==n?null:Cl("text",{...Ll(e,t,i,r),children:n})}var Dl="http://www.w3.org/1999/xhtml";function Fl(e="semiotic"){let t=Symbol.for("semiotic.svg-instance"),i=globalThis,r=(i[t]??0)+1;return i[t]=r,`${e}-${r}`}function El(e,t){let i=`${Fl(`${e}-pending`)}_`,r=t(i).split(i);if(1===r.length)return r[0];let n,o=2654435769;for(let e of r)n=v("\0",v(e,n)),o=v("\0",v(e,o));return r.join(`${e}-${n.toString(36)}${o.toString(36)}`)}import{packEnclose as Ol}from"d3-hierarchy";import{area as zl,curveBasis as Bl,curveCardinal as jl,curveCatmullRom as Wl,curveLinear as Yl,curveMonotoneX as ql,curveMonotoneY as Xl,curveStep as Gl,curveStepAfter as Vl,curveStepBefore as Hl}from"d3-shape";import*as Ul from"react";function Zl(e,t={}){let i=function(e){let t=e.provenance,i=e.id??e.stableId??t?.stableId;return null==i||""===i?void 0:String(i)}(e);return{"data-semiotic-annotation-widget":"",...i?{"data-semiotic-annotation-id":i}:{},onClickCapture(r){let n=function(e){let t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(r);t.onAnnotationActivate?.({annotation:e,annotationId:i,chartId:t.chartId,inputType:n}),i&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:i,inputType:n,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}function Kl(e,t){return As(e)?$s(e)??t:e}function Ql(e,t,i){let r=e.labelBackground,n=t.colors.background,o=n&&"transparent"!==n?n:t.colors.surface||n;return void 0===r?"none"===i?"none":{type:"halo",fill:o}:!1===r||"none"===r?"none":!0===r||"halo"===r?{type:"halo",fill:o}:"box"===r?{type:"box",fill:o}:{...r,fill:Kl(r.fill,o)??o,...void 0!==r.stroke?{stroke:Kl(r.stroke,t.colors.border)}:{}}}import{jsx as Jl,jsxs as ec}from"react/jsx-runtime";function tc(e,t){let i=ia(e,t);return null!=i&&Number.isFinite(i)?i:Number.NaN}var ic={linear:Yl,monotoneX:ql,monotoneY:Xl,step:Gl,stepAfter:Vl,stepBefore:Hl,basis:Bl,cardinal:jl,catmullRom:Wl};import{jsx as rc,jsxs as nc}from"react/jsx-runtime";function oc(e,t){return e.color||t.colors.annotation||t.colors.text}function ac(e,t,i){return t.x?null!=e.x?ea(t.x,e.x):i&&null!=e[i]?ea(t.x,e[i]):null:"number"==typeof e.x?e.x:null}function sc(e,t,i){return t.y?null!=e.y?ea(t.y,e.y):i&&null!=e[i]?ea(t.y,e[i]):null:"number"==typeof e.y?e.y:null}function lc(e){let{annotations:t}=e;if(!t||0===t.length)return e.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;let i=X(t).filter(e=>!e._directLabel),r=e.scales.geoProjection,n=r?i.map(e=>{if(!Array.isArray(e.coordinates)||e.coordinates.length<2)return e;let t=r([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):i,o=!!r&&!e.scales.x&&!e.scales.y,a=e=>Number(e),s=e.scales.x??(o?a:void 0),l=e.scales.y??(o?a:void 0),c=e.frameType??(e.projection?"ordinal":r||e.scales.x||e.scales.y?"xy":"network"),u="horizontal"===e.projection,d=e.projection?u?"horizontal":"vertical":void 0,h="vertical"===e.projection||u,p=e.scales.o,f=p?e=>(p(e)??0)+(p.bandwidth?.()??0)/2:void 0,g={scales:{x:(h?u?e.scales.r:f:void 0)??s,y:(h?u?f:e.scales.r:void 0)??l,time:h?e.scales.r:s,value:h?e.scales.r:l,o:p,...r?{geoProjection:r}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,pointNodes:e.pointNodes,frameType:c,...d?{projection:d}:{}},m=function(e,t){let i=e.filter(e=>e._directLabel);if(!i.length)return{node:null};let r=i[0]._directLabel.position,n=t.measure??bs,o=i.map(e=>({family:t.fontFamily||"sans-serif",version:t.fontVersion??0,weight:400,size:e.fontSize||11})),a=i.map((e,i)=>{let r=(e,t)=>{if(null==e||!t)return NaN;try{return t(Number(e))}catch{return NaN}};return{id:String(e._directLabel.id),anchor:{x:r(e.x,t.scales?.x),y:r(e.y,t.scales?.y)},measurement:n(String(e.label),o[i])}}),s=Math.max(0,(t.margin?.["end"===r?"right":"left"]??0)-10),l=function(e,t,i="end",r=2){let n,o=new Map,a=new Map,s=(e,t)=>{let i=a.get(e)??{count:0,labelIds:[]};i.count++,i.labelIds.length<20&&i.labelIds.push(t),a.set(e,i)},l=(e,t)=>{o.set(e,{id:e,status:"omitted",reason:t}),s(t,e),s("LABEL_OMITTED",e)},c=[...e].sort((e,t)=>(Number.isFinite(e.anchor.y)?e.anchor.y:1/0)-(Number.isFinite(t.anchor.y)?t.anchor.y:1/0)||(e.id<t.id?-1:e.id>t.id?1:0)),u=[],d=0;for(let e of c){let{id:i,anchor:o,measurement:a}=e;if("estimated"===a.source&&s("ESTIMATED_METRICS",i),![o.x,o.y,a.width,a.height,a.ascent].every(Number.isFinite)||a.width<0||a.height<=0){l(i,"INVALID_PROJECTION");continue}n===o.y&&s("TIED_ENDPOINTS",i),n=o.y;let c=a.height+(u.length?r:0);![t.x,t.y,t.width,t.height,r].every(Number.isFinite)||r<0||a.width>t.width||d+c>t.height?l(i,"INSUFFICIENT_SPACE"):(u.push(e),d+=c)}let h=vs({desired:u.map(e=>e.anchor.y-e.measurement.height/2),minGaps:u.slice(0,-1).map(e=>e.measurement.height+r),min:t.y,max:t.y+t.height-(u.at(-1)?.measurement.height??0)});u.forEach((e,r)=>{let n={x:"end"===i?t.x:t.x+t.width-e.measurement.width,y:h[r],width:e.measurement.width,height:e.measurement.height},a="end"===i?n.x:n.x+n.width,s=n.y+n.height/2,l={x:a-e.anchor.x,y:s-e.anchor.y};o.set(e.id,{id:e.id,status:"placed",box:n,offset:l,...Math.abs(l.y)>.01||Math.abs(l.x)>6.01?{connector:{x1:e.anchor.x,y1:e.anchor.y,x2:a,y2:s}}:{}})});let p=e.map(e=>o.get(e.id)),f=p.filter(e=>"placed"===e.status&&Math.abs(e.offset.y)>.01),g=p.filter(e=>"omitted"===e.status),m=e.filter(e=>"estimated"===e.measurement.source).length;return{dispositions:p,evidence:{status:m||g.length?"incomplete":"complete",requested:e.length,rendered:u.length,displaced:f.length,omitted:g.length,omittedIds:g.slice(0,20).map(e=>e.id),displacedIds:f.slice(0,20).map(e=>e.id),measurement:{measured:e.length-m,estimated:m},collisions:0,overflows:0,fallback:"accessible-series-list",findings:[...a].map(([e,t])=>({code:e,...t,remedy:ws[e]})),coverage:{directLabels:"assessed",axisLabels:"not-assessed"}}}}(a,{x:"end"===r?t.width+6:-s-6,y:0,width:s,height:t.height},r),c=l.dispositions.map((e,r)=>{if("omitted"===e.status)return null;let n=e.box,s=e.connector,c=i[r],u=ks("g",{"data-direct-label-id":e.id,children:[s&&Ss("line",{...s,stroke:c.color,strokeWidth:.75}),Ss("text",{x:n.x+(a[r].measurement.left??0),y:n.y+a[r].measurement.ascent,fontFamily:o[r].family,fontWeight:o[r].weight,fontSize:o[r].size,fill:c.color,textAnchor:"start",children:c.label})]},e.id),d=t.renderLabel?t.renderLabel({...c,dx:n.x+(a[r].measurement.left??0)-a[r].anchor.x,dy:n.y+a[r].measurement.ascent-a[r].anchor.y,fontFamily:o[r].family},r,u):u;if(!d){let t=l.evidence;t.rendered--,t.omitted++,t.omittedIds.length<20&&t.omittedIds.push(e.id),Math.abs(e.offset.y)>.01&&t.displaced--,t.displacedIds=t.displacedIds.filter(t=>t!==e.id);for(let i of["RENDER_FAILURE","LABEL_OMITTED"]){let r=t.findings.find(e=>e.code===i);r||(r={code:i,count:0,labelIds:[],remedy:ws[i]},t.findings.push(r)),r.count++,r.labelIds.length<20&&r.labelIds.push(e.id)}}if(d!==u&&(l.evidence.status="incomplete",d)){let t=l.evidence.findings.find(e=>"UNSUPPORTED_GEOMETRY"===e.code);t||(t={code:"UNSUPPORTED_GEOMETRY",count:0,labelIds:[],remedy:ws.UNSUPPORTED_GEOMETRY},l.evidence.findings.push(t)),t.count++,t.labelIds.length<20&&t.labelIds.push(e.id)}return d?Ss(xs.Fragment,{children:d},e.id):null}),u=Ss("g",{role:"list","aria-label":"Series endpoints","data-direct-label-fallback":"accessible-series-list",children:i.map((e,t)=>Ss("g",{role:"listitem","aria-label":`${e.label}: x ${String(e.x)}, y ${String(e.y)}`,children:Ss("title",{children:`${e.label}: x ${String(e.x)}, y ${String(e.y)}`})},a[t].id))});return{evidence:l.evidence,node:ks("g",{className:"semiotic-direct-labels","data-label-layout":JSON.stringify(l.evidence),children:[c,u]},"direct-labels")}}(t,{...e.layout,scales:e.scales,margin:e.margin,fontFamily:e.theme.typography.fontFamily,measure:e.labelMeasurer,...e.svgAnnotationRules?{renderLabel:(t,i,r)=>e.svgAnnotationRules(t,i,g)??r}:{}}),y=e.autoPlaceAnnotations?_l({annotations:n,context:g,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):n,x=function(e,t,i,r){let n=[];return e.forEach((e,o)=>{let a;a=i?i(e,o,r)??t(e,o,r):t(e,o,r),a&&n.push({node:a,annotation:e})}),{nodes:tl(n),renderedAnnotations:n.map(e=>e.annotation)}}(y,(t,i,r)=>function(e,t,i,r){let{scales:n,layout:o,theme:a,xAccessor:s,yAccessor:l}=i;switch(e.type){case"frame-text":return rc(Nl,{annotation:e,width:o.width,height:o.height,defaults:{fill:a.colors.text,fontSize:11,fontFamily:a.typography.fontFamily}},`ann-frame-text-${t}`);case"y-threshold":{let r=e.value??e.y;if(null==r)return null;let s=oc(e,a),l=e.label,c=e.strokeDasharray||"6,4",u=e.strokeWidth??1.5;if("horizontal"===i.projection&&n.r){let i=n.r(r);return null==i?null:nc("g",{opacity:e.opacity,children:[rc("line",{x1:i,y1:0,x2:i,y2:o.height,stroke:s,strokeWidth:u,strokeDasharray:c}),Rs(e.endCap,[i,0],s),l&&rc(Ls,{x:i+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??s,fontFamily:a.typography.fontFamily,text:l,background:Ql(e,a,"halo")})]},`ann-ythresh-${t}`)}let d=n.y?ea(n.y,r):n.r?n.r(r):null;return null==d?null:rc(Fs,{ann:e,position:d,vertical:!1,width:o.width,height:o.height,color:s,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:Ql(e,a,"halo"),dash:"6,4",labelGap:6},`ann-ythresh-${t}`)}case"x-threshold":{let r=e.value??e.x;if(null==r)return null;let s="horizontal"===i.projection&&n.r?n.r(r):n.x?ea(n.x,r):null;if(null==s)return null;let l=oc(e,a);return rc(Fs,{ann:e,position:s,vertical:!0,width:o.width,height:o.height,color:l,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:Ql(e,a,"halo"),dash:"6,4"},`ann-xthresh-${t}`)}case"band":{if("function"!=typeof n.y)return null;let r=ta(n.y,e.y0,0),s=ta(n.y,e.y1,1);if(null!=e.y0&&null==r||null!=e.y1&&null==s)return null;let l=r??0,c=s??o.height,u=Math.min(l,c),d=Math.abs(c-l),h=Pl(e,`ssr-band-${t}`,"vertical",a.colors.primary||oc(e,a)),p=e.fillOpacity??.1,f=!0===i.underLayerBands&&"under"===e.layer;return nc("g",{opacity:e.opacity,children:[!f&&h.def&&rc("defs",{children:h.def}),!f&&rc("rect",{x:0,y:u,width:o.width,height:d,fill:h.fill,fillOpacity:p}),e.label&&rc(Ls,{x:o.width-4,y:Math.max(u,0)+16,textAnchor:"end",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||oc(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ql(e,a,"halo")})]},`ann-band-${t}`)}case"x-band":{if("function"!=typeof n.x)return null;let r=ta(n.x,e.x0,0),s=ta(n.x,e.x1,1);if(null!=e.x0&&null==r||null!=e.x1&&null==s)return null;let l=r??0,c=s??o.width,u=Math.min(l,c),d=Math.abs(c-l),h=Pl(e,`ssr-xband-${t}`,"horizontal",a.colors.primary||oc(e,a)),p=e.fillOpacity??.1,f=!0===i.underLayerBands&&"under"===e.layer;return nc("g",{opacity:e.opacity,children:[!f&&h.def&&rc("defs",{children:h.def}),!f&&rc("rect",{x:u,y:0,width:d,height:o.height,fill:h.fill,fillOpacity:p}),e.label&&rc(Ls,{x:u+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||oc(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ql(e,a,"halo")})]},`ann-xband-${t}`)}case"category-highlight":{if(null==e.category||!n.o)return null;let r=n.o(String(e.category));if(null==r)return null;let s=n.o.bandwidth?n.o.bandwidth():40,l=oc(e,a),c=e.opacity??.1,u=e.label;return"horizontal"===i.projection?nc("g",{children:[rc("rect",{x:0,y:r,width:o.width,height:s,fill:l,opacity:c}),u&&rc(Ls,{x:12,y:r+s/2,dominantBaseline:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:Ql(e,a,"none")})]},`ann-cathighlight-${t}`):nc("g",{children:[rc("rect",{x:r,y:0,width:s,height:o.height,fill:l,opacity:c}),u&&rc(Ls,{x:r+s/2,y:16,textAnchor:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:Ql(e,a,"none")})]},`ann-cathighlight-${t}`)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{let i=function(e,t,i,r){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){let i=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(i)return{x:i[0],y:i[1]}}return{x:ac(e,t,i),y:sc(e,t,r)}}(e,n,s,l),o=null==i.x||null==i.y?al(e,t,r):null,c=i.x??o?.x??null,u=i.y??o?.y??null;if(null==c||null==u)return null;let d="text"===e.type,h=e.dx??(d?0:30),p=e.dy??(d?0:-30),f=e.color||a.colors.text;if(!d){let i="callout"===e.type?"callout-circle":e.type,r="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return rc(Vs,{noteData:{x:c,y:u,dx:h,dy:p,note:Es(e),type:i,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:f,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},`ann-label-${t}`)}return rc("g",{children:rc("text",{x:c+h,y:u+p,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||a.typography.labelSize,fill:f,fontFamily:a.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},`ann-label-${t}`)}default:return null}}(t,i,e,r)??function(e,t,i,r){let n=e.color||r?.colors.textSecondary||"#666",o=r?Ql(e,r,"none"):e.labelBackground??"none";switch(e.type){case"enclose":{let r=(e.coordinates||[]).map(e=>({x:il({...e,type:"point"},i),y:rl({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=Ol(r),s=e.padding||10;return ec("g",{children:[Jl("circle",{cx:a.x,cy:a.y,r:a.r+s,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Jl(Ls,{x:a.x,y:a.y-a.r-s-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"rect-enclose":{let r=(e.coordinates||[]).map(e=>({x:il({...e,type:"point"},i),y:rl({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=e.padding||10,[s,l]=ue(r.map(e=>e.x)),[c,u]=ue(r.map(e=>e.y)),d=s-a,h=l+a,p=c-a;return ec("g",{children:[Jl("rect",{x:d,y:p,width:h-d,height:u+a-p,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Jl(Ls,{x:(d+h)/2,y:p-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"highlight":{let r=i.data||[],n="function"==typeof e.filter?r.filter(e.filter):e.field&&null!=e.value?r.filter(t=>t[e.field]===e.value):[],o={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return Jl("g",{children:n.map((t,r)=>{let n=il(t,i),a=rl(t,i);if(null==n||null==a)return null;let s="function"==typeof e.r?e.r(t):e.r||6,l="function"==typeof e.style?e.style(t):e.style||o;return Jl("circle",{cx:n,cy:a,r:s,...l},`hl-${r}`)})},`ann-${t}`)}case"bracket":{let r=il(e,i),n=rl(e,i);return Jl(Vs,{noteData:{x:r??0,y:n??0,dx:e.dx||0,dy:e.dy||0,note:Es(e),type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},`ann-${t}`)}case"trend":{let r=function(e,t){let i=t.scales?.x??t.scales?.time,r=t.scales?.y??t.scales?.value;if(!i||!r)return[];let n=t.data||[],o=t.xAccessor||"x",a=t.yAccessor||"y",s="horizontal"===t.projection,l="ordinal"===t.frameType;l&&s&&([o,a]=[a,o]);let c=e=>ia(i,e)??Number.NaN,u=e=>ia(r,e)??Number.NaN,d=s?u:c,h=l?t.scales?.o?.domain().map(String)??[...new Set(n.filter(e=>null!=e[o]).map(e=>String(e[o])))].sort((e,t)=>d(e)-d(t)):[],p=new Map(h.map((e,t)=>[e,t])),f=Ci(n.map(e=>[l?null==e[o]?void 0:p.get(String(e[o])):e[o],e[a]]));return f.length<2?[]:("loess"===e.method?Ei(f,e.bandwidth??.3):("polynomial"===e.method?Di(f,e.order??2):Ni(f)).points).map(([e,t])=>{if(!l)return[c(e),u(t)];let i=d(h[e]);return s?[c(t),i]:[i,u(t)]}).filter(([e,t])=>Number.isFinite(e)&&Number.isFinite(t))}(e,i);if(r.length<2)return null;let n=r.map(([e,t])=>`${e},${t}`).join(" "),o=e.color||"#6366f1",[a,s]=r[r.length-1];return ec("g",{children:[Jl("polyline",{points:n,fill:"none",stroke:o,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Jl("text",{x:a+4,y:s-4,fill:o,fontSize:11,children:e.label})]},`ann-${t}`)}case"envelope":{let r=i.data||[];if(r.length<2)return null;let n=i.xAccessor||"x",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=e=>tc(o,e),l=e=>tc(a,e),c=e.upperAccessor||"upperBounds",u=e.lowerAccessor||"lowerBounds",d=e.filter,h=r.filter(e=>null!=e[c]&&null!=e[u]&&(!d||d(e))).sort((e,t)=>e[n]-t[n]);if(h.length<2)return null;let p=ic[i.curve||"linear"]||Yl,f=zl().x(e=>s(e[n])).y0(e=>l(e[u])).y1(e=>l(e[c])).curve(p)(h);if(!f)return null;let g=e.fill||"#6366f1",m=h[h.length-1];return ec("g",{children:[Jl("path",{d:f,fill:g,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&Jl("text",{x:s(m[n])+4,y:l(m[c])-4,fill:g,fontSize:11,children:e.label})]},`ann-${t}`)}case"anomaly-band":{let r=(i.data||[]).filter(t=>!e.filter||e.filter(t));if(r.length<2)return null;let n=i.yAccessor||"y",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=e=>tc(a,e),l=r.map(e=>Li(e[n])).filter(e=>null!==e);if(l.length<2)return null;let c=l.reduce((e,t)=>e+t,0)/l.length,u=l.reduce((e,t)=>e+(t-c)**2,0)/l.length,d=Math.sqrt(u),h=e.threshold??2,p=c-h*d,f=s(c+h*d),g=s(p),m=e.fill||"#6366f1",y=e.anomalyColor||"#ef4444",x=e.anomalyRadius??6,b=r.filter(e=>{let t=Li(e[n]);return null!=t&&Math.abs(t-c)>h*d});return ec("g",{children:[!1!==e.showBand&&Jl("rect",{x:0,y:Math.min(f,g),width:i.width||0,height:Math.abs(g-f),fill:m,fillOpacity:e.fillOpacity??.1}),b.map((e,t)=>{let r=il(e,i),n=rl(e,i);return null==r||null==n?null:Jl("circle",{cx:r,cy:n,r:x,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},`anomaly-${t}`)}),e.label&&Jl("text",{x:(i.width||0)-4,y:Math.min(f,g)-4,textAnchor:"end",fill:m,fontSize:11,children:e.label})]},`ann-${t}`)}case"forecast":{let r=i.data||[],n=i.xAccessor||"x",o=i.yAccessor||"y",a=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!a||!s)return null;let l=e=>tc(a,e),c=e=>tc(s,e),u=Ci(r.map(e=>[e[n],e[o]])),d=Oi(u,e);if(!d)return null;let{predict:h}=d,p=u[u.length-1][0],f=d.forecast(e.steps??5);if(!f.length)return null;let g=zl().x(e=>l(e.x)).y0(e=>c(e.lower)).y1(e=>c(e.upper))(f);if(!g)return null;let m=f.map(e=>`${l(e.x)},${c(e.y)}`).join(" "),y=e.fill||"#6366f1",x=e.strokeColor||"#6366f1",b=f[f.length-1];return ec("g",{children:[Jl("path",{d:g,fill:y,fillOpacity:e.fillOpacity??.15,stroke:"none"}),Jl("polyline",{points:`${l(p)},${c(h(p))} ${m}`,fill:"none",stroke:x,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&b&&Jl("text",{x:l(b.x)+4,y:c(b.y)-4,fill:x,fontSize:11,children:e.label})]},`ann-${t}`)}case"widget":{let r,n;if(null!=e.px&&null!=e.py)r=e.px,n=e.py;else{let o=al(e,t,i);if(!o)return null;r=o.x,n=o.y}if(!function(e,t,i,r=50){let n=i.width||0,o=i.height||0;return e>=-r&&e<=n+r&&t>=-r&&t<=o+r}(r,n,i))return null;let o=e.width??32,a=e.height??32,s=e.content??Jl("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return Jl("foreignObject",{x:r+(e.dx??0)-o/2,y:n+(e.dy??0)-a/2,width:o,height:a,style:{overflow:"visible",pointerEvents:"auto"},children:Jl("div",{xmlns:Dl,...Zl(e),style:{width:o,height:a,display:"flex",alignItems:"center",justifyContent:"center"},children:s})},`ann-${t}`)}default:return null}}(t,i,r,e.theme),e.svgAnnotationRules,g),b=m.node?[...x.nodes,m.node]:x.nodes,v=new Map;for(let e of x.renderedAnnotations){let t="string"==typeof e.type?e.type:"unknown";v.set(t,(v.get(t)??0)+1)}m.evidence&&v.set("text",(v.get("text")??0)+m.evidence.rendered);let w=[];for(let e of t){let t="string"==typeof e.type?e.type:"unknown",i=v.get(t)??0;i>0?v.set(t,i-1):w.push(t)}e.onRender?.({inputCount:t.length,eligibleCount:y.length,renderedCount:x.renderedAnnotations.length+(m.evidence?.rendered??0),...m.evidence?{layout:m.evidence}:{},unrenderedCount:w.length,unrenderedTypes:w});let S=e.idPrefix?`${e.idPrefix}-`:"";return b.length>0?rc("g",{id:`${S}annotations`,className:"semiotic-annotations",children:b}):null}import{jsx as cc}from"react/jsx-runtime";function uc(e,t,i,r="right",n,o){if(null==e||!1===e)return null;let{x:a,y:s}=Ne(e,{totalWidth:t[0],totalHeight:t[1],margin:i,position:r,legendLayout:n,axisChrome:o});return cc("g",{transform:`translate(${a}, ${s})`,children:e})}function dc(e){let t=String(e).replace(/[^a-zA-Z0-9_-]/g,"_"),i=/^[A-Za-z_]/.test(t)?t:`c${t}`,r=`${i}-semiotic-title`,n=`${i}-semiotic-desc`;return{titleId:r,descId:n,labelledBy:`${r} ${n}`}}import*as hc from"react";function pc(e,t,i){if("edges"===e){if(t)return"start";if(i)return"end"}return"middle"}function fc(e,t,i){if("edges"===e){if(t)return"hanging";if(i)return"auto"}return"middle"}function gc(e){if(0===e.length)return{min:null,max:null};let t=1/0,i=-1/0;for(let r of e)r.pixel<t&&(t=r.pixel),r.pixel>i&&(i=r.pixel);return{min:t,max:i}}function mc(e){if(e)return"object"==typeof e?e.strokeDasharray:"dashed"===e?"6,4":"dotted"===e?"2,4":e}function yc(e,t){return e&&"string"!=typeof e?{stroke:e.stroke??t.stroke,strokeWidth:e.strokeWidth??t.strokeWidth,...null!=e.strokeOpacity&&{strokeOpacity:e.strokeOpacity},...e.strokeDasharray&&{strokeDasharray:e.strokeDasharray}}:{...t,..."string"==typeof e&&{strokeDasharray:mc(e)}}}function xc(e,t,i){if("left"===e||"right"===e){let r="left"===e?i:0,n="left"===e?-1:1,o=Math.ceil(t/8),a=`M0,${r}`;for(let e=0;e<o;e++){let i=8*e+4,o=8*(e+1);a+=`L${Math.min(i,t)},${r+4*n}`,a+=`L${Math.min(o,t)},${r}`}return a}let r="bottom"===e?0:t,n="bottom"===e?1:-1,o=Math.ceil(i/8),a=`M${r},0`;for(let e=0;e<o;e++){let t=8*e+4,o=8*(e+1);a+=`L${r+4*n},${Math.min(t,i)}`,a+=`L${r},${Math.min(o,i)}`}return a}function bc(e,t,i){return"exact"===i?function(e,t){let i=e.domain(),r=i[0],n=i[i.length-1],o=r instanceof Date,a=r instanceof Date?r.getTime():r,s=n instanceof Date?n.getTime():n;if(t<2||a===s)return o?[new Date(a),new Date(s)]:[a,s];let l=(s-a)/(t-1),c=new Array(t);for(let e=0;e<t;e++){let i=e===t-1?s:a+e*l;c[e]=o?new Date(i):i}return c}(e,t):e.ticks(t)}import{jsx as vc}from"react/jsx-runtime";function wc(e){return"string"==typeof e||"number"==typeof e}function Sc(e){let{label:t,x:i,y:r,textAlign:n,fontSize:o,fontFamily:a,color:s}=e;return vc("foreignObject",{x:i,y:r,width:60,height:24,style:{overflow:"visible"},children:vc("div",{xmlns:Dl,style:{color:s,fontFamily:a,fontSize:o,textAlign:n,userSelect:"none"},children:t})})}function kc(e){return e instanceof Date?e:"number"==typeof e&&e>1e9?new Date(e):null}function Ac(e){return e.dataValue??e.value}function Mc(e){return"string"==typeof e||"number"==typeof e?6.5*String(e).length:60}function $c(e){let{scale:t,axis:i,size:r,horizontal:n=!1,axisExtent:o}=e,a=i?.extent??o,s=t.domain(),l=function(e){return e?.ticks??e?.tickCount??5}(i),c=Math.max(2,Math.floor(r/(n?70:30))),u="exact"===a?Math.max(2,l):Math.min(l,c),d=Uo(t),h=d&&i?.tickValues?i.tickValues.flatMap(e=>{let t=Jo(d,e);return null==t?[]:[{requested:e,index:t}]}):null,p=h?h.map(e=>e.requested):d?0===u?[]:d.map(e=>e.value):(i?.tickValues??bc(t,u,a)).filter(e=>"string"!=typeof e),f=!h&&d?new Map(d.map(e=>[e.value,e.label])):null,g=e=>f?.get(Number(e))??e,m=p.map(e=>{let t=g(e);return t instanceof Date?t.valueOf():"number"==typeof t?t:Number(t)}),y=i?.tickFormat||e.format||(d?function(e){let t=e.map(e=>e.label);if(t.length>0&&t.every(e=>e instanceof Date)){let e=1/0,i=-1/0;for(let r=0;r<t.length;r++){let n=t[r].getTime();n<e&&(e=n),n>i&&(i=n)}let r=gr([e,i]);return e=>e instanceof Date||"number"==typeof e&&Number.isFinite(e)?r(e):String(e)}if(t.every(e=>"number"==typeof e&&Number.isFinite(e))){let e=fe(t);return t=>e("number"==typeof t?t:Number(t))}return e=>String(e)}(d):s[0]instanceof Date||p[0]instanceof Date?gr([s[0].valueOf(),s[s.length-1].valueOf()]):fe(m)),x=(e,t)=>{let i=g(e);return n?y(i,t,m):y(i)},b=p.flatMap((e,i)=>{let r;if(h)r=t(h[i].index);else{if("string"==typeof e)return[];r=t(e)}let n={value:e,pixel:r,label:x(e,i)};return d&&(n.dataValue=h?h[i].requested:d[i].label),[n]}),v=!h&&d?b.filter(e=>e.pixel>=0&&e.pixel<=r):b,w=22;if(n){let e=v.reduce((e,t)=>Math.max(e,Mc(t.label)),0);w=i?.autoRotate?Math.max(20,Math.min(e+8,55)):Math.max(55,e+8)}let S=n&&(i?.tickFormat||e.format)?e=>{let t=e.map(e=>{let t=g(e.value);return t instanceof Date?t.valueOf():Number(t)});return e.map((e,i)=>({...e,label:y(g(e.value),i,t)}))}:void 0,k=function(e,t){if(e.length<=2)return e;let i=[e[0]];for(let r=1;r<e.length-1;r++)Math.abs(e[r].pixel-i[i.length-1].pixel)>=t&&i.push(e[r]);let r=e[e.length-1];return Math.abs(r.pixel-i[i.length-1].pixel)>=t?i.push(r):i[i.length-1]=r,i}(v,w);if(S&&(k=S(k)),k.length>1&&(k=k.filter((e,t)=>0===t||!function(e,t){return!("string"!=typeof e&&"number"!=typeof e||"string"!=typeof t&&"number"!=typeof t||String(e)!==String(t))}(e.label,k[t-1].label))),i?.includeMax&&!d&&k.length>0&&"exact"!==a&&!i.tickValues){let e=s[s.length-1];if(null!=e){let i=t(e),r=Math.abs(i-k[k.length-1].pixel);if(r>1){let t=x(e,k.length);r<w&&k.length>1&&(k=k.slice(0,-1)),k=[...k,{value:e,pixel:i,label:t}]}}}return S?S(k):k}function _c(e,t,i,r){if(!e)return!1;let n=Ac(t);return"function"==typeof e?e(n,i):function(e,t){let i=kc(e);if(!i)return!1;let r=kc(t);return!r||i.getFullYear()!==r.getFullYear()||i.getMonth()!==r.getMonth()}(n,i>0?Ac(r[i-1]):void 0)}import{jsx as Pc,jsxs as Ic}from"react/jsx-runtime";function Tc(e){let t=e._idPrefix??e.chartId;if(null==t||""===t)return null;let i=String(t).replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(i)?i:`c${i}`}function Lc(e){return Tc(e)??Fl()}function Cc(e,t){let i=Tc(e);return i?t(i):El("semiotic",t)}function Rc(e,t,i){return ge(e.showLegend&&!e.__legendIncludesAutomatic?us(t,e.colorScheme,i):void 0,e.legend)}var Nc={right:110,left:110,top:50,bottom:80};function Dc(e,t){if(e.__autoLegendMargin)return Nc[t]}function Fc(e,t){let i={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,axisChrome:t.axisChrome,legendDistance:me(e)||ye(e)?e.legendDistance:void 0};return me(e)?function(e){if(!e.legendGroups.some(e=>e.items.some(()=>!0)))return null;let t=function(e){let{legendGroups:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,rowHeight:c}=De(a),u=s+l,d=Math.max(12,hs(i)),h="top"===r||"bottom"===r,p=Math.max(s,n-o.left-o.right);if(h){let r=Math.max(s,a?.maxWidth??p),n=ds(a?.align),o=0,l=0,c=[];for(let n of t){let t=n.items.map(e=>e.label),u=ms({...e,categories:t,legendLayout:{...a,maxWidth:Math.max(s,r-d-8),align:"start"}}),h=n.label?d:0,p=n.label?gs(n.label,0,0,i):0,f=h>0?h+8:0,g=f+u.width,m=Math.max(u.height,p);c.push({group:n,x:o,y:0,itemOffsetX:f,itemOffsetY:0,width:g,height:m,items:u.items}),o+=g+12,l=Math.max(l,m)}let h=c.length>0?o-12:0,f=h>r?0:"center"===n?Math.max(0,(r-h)/2):"end"===n?Math.max(0,r-h):0;return{groups:c.map(e=>({...e,x:e.x+f})),width:h,height:l,swatchSize:s,labelOffset:u,swatchRadius:0}}let f=Fe(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c);return{groups:[],width:t.reduce((e,t)=>t.items.reduce((e,t)=>Math.max(e,gs(t.label,s,l,i)),Math.max(e,t.label?gs(t.label,0,0,i):0)),0),height:f.at(-1)?.endY??0,swatchSize:s,labelOffset:u,swatchRadius:0}}(e),i="top"===e.position||"bottom"===e.position,r={legendGroups:e.legendGroups,legendDistance:e.legendDistance},n=e.reservedWidth??ke(r,e.legendLayout),o=e.theme.colors.grid||e.theme.colors.textSecondary,{x:a,y:s}=Ne(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n});if(!i){let i=Fe(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)),r=e.legendGroups.flatMap((r,o)=>{let a=i[o],s=r.type??"fill",l=[ss("line",{x1:0,y1:a.lineY,x2:n,y2:a.lineY,stroke:"gray"},`legend-group-neatline-${o}`)];return r.label&&null!=a.labelY&&l.push(ss("text",{y:a.labelY,fontSize:hs(e.theme),fill:e.theme.colors.text,fontFamily:ps(e.theme),children:r.label},`legend-group-label-${o}`)),l.push(ss("g",{transform:`translate(0,${a.itemsY})`,children:r.items.map((i,n)=>{let a=r.styleFn(i,n),l="function"==typeof s?s(i):"line"===s?ss("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:a}):ss("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:a});return ls("g",{transform:`translate(0,${n*Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)})`,children:[l,ss("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:hs(e.theme),fill:e.theme.colors.text,fontFamily:ps(e.theme),children:i.label})]},`legend-${o}-${n}`)})},`legend-group-${o}`)),l});return ss("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"vertical",fontWeight:fs(e.theme),children:r})}let l=t.groups.flatMap((i,r)=>{let{group:n}=i,a=n.type??"fill",s=[];if(n.label&&s.push(ss("text",{transform:`translate(${i.x},${i.y}) rotate(90)`,textAnchor:"start",fontSize:hs(e.theme),fill:e.theme.colors.text,fontFamily:ps(e.theme),children:n.label},`legend-group-label-${r}`)),s.push(...i.items.map((o,s)=>{let l=n.items[s],c=n.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?ss("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:c}):ss("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:c});return ls("g",{transform:`translate(${i.x+i.itemOffsetX+o.x},${i.y+i.itemOffsetY+o.y})`,children:[u,ss("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:hs(e.theme),fill:e.theme.colors.text,fontFamily:ps(e.theme),children:o.category})]},`legend-${r}-${s}`)})),r<t.groups.length-1){let e=i.x+i.width+6;s.push(ss("line",{x1:e,y1:0,x2:e,y2:t.height,stroke:o},`legend-group-separator-${r}`))}return s});return ss("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"horizontal",fontWeight:fs(e.theme),children:l})}({...i,legendGroups:e.legendGroups}):ye(e)?function(e){let t=function(e){let t="top"===e.position||"bottom"===e.position,i=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??i,200),height:e.gradient.label?46:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?126:108,swatchSize:14}}(e),i="top"===e.position||"bottom"===e.position,r={gradient:e.gradient,legendDistance:e.legendDistance},n=ke(r),o=(e.idPrefix?`${e.idPrefix}-`:"")+"semiotic-static-gradient-legend",a=e.gradient.format||fe(e.gradient.domain),{x:s,y:l}=Ne(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n}),c=Array.from({length:17},(t,r)=>{let n=r/16,o=i?e.gradient.domain[0]+n*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-n*(e.gradient.domain[1]-e.gradient.domain[0]);return ss("stop",{offset:n,stopColor:e.gradient.colorFn(o)},r)});if(i){let i=e.gradient.label?12:void 0,r=e.gradient.label?18:0;return ls("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:fs(e.theme),children:[ss("defs",{children:ss("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),e.gradient.label&&ss("text",{x:t.width/2,y:i,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:ps(e.theme),children:e.gradient.label}),ss("rect",{x:0,y:r,width:t.width,height:12,fill:`url(#${o})`,rx:2}),ss("text",{x:0,y:r+12+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:ps(e.theme),children:a(e.gradient.domain[0])}),ss("text",{x:t.width,y:r+12+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:ps(e.theme),children:a(e.gradient.domain[1])})]})}let u=e.gradient.label?12:void 0,d=e.gradient.label?18:0;return ls("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:fs(e.theme),children:[ss("defs",{children:ss("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),e.gradient.label&&ss("text",{x:0,y:u,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:ps(e.theme),children:e.gradient.label}),ss("rect",{x:0,y:d,width:14,height:100,fill:`url(#${o})`,rx:2}),ss("text",{x:19,y:d+10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:ps(e.theme),children:a(e.gradient.domain[1])}),ss("text",{x:19,y:d+100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:ps(e.theme),children:a(e.gradient.domain[0])})]})}({...i,gradient:e.gradient}):null}function Ec(e,t){let{props:i,categories:r,theme:n,size:o,hasTitle:a}=t,s=i.legendPosition||"right",l={...e},c={theme:n,position:s,size:o,hasTitle:a,legendLayout:i.legendLayout,axisChrome:i.axisChrome,minimumMargin:Dc(i,s)};if(void 0!==i.legend&&null!==i.legend){let t=Rc(i,r,n);null!=t&&!1!==t&&function(e,t){let i=t.position||"right";Re(e,{legend:t.legend,position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...c,legend:t})}else i.showLegend&&r.length>0&&function(e,t){if(0===t.categories.length)return;let i=t.position||"right";Re(e,{legend:us(t.categories,t.colorScheme,t.theme),position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...c,categories:r,colorScheme:i.colorScheme});return we(e,l,o,s),s}function Oc(e){let{props:t,categories:i,theme:r,size:n,margin:o,hasTitle:a}=e,s=t.legendPosition||"right",l={theme:r,position:s,size:n,margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(void 0!==t.legend&&null!==t.legend){let e=Rc(t,i,r);return hc.isValidElement(e)?uc(e,n,o,s,t.legendLayout,t.axisChrome):Fc(e,l)||(me(e)||ye(e)?null:uc(e??null,n,o,s,t.legendLayout,t.axisChrome))}return t.showLegend&&0!==i.length?function(e){let{categories:t,colorScheme:i,theme:r,position:n="right",totalWidth:o,totalHeight:a,margin:s}=e;if(!t||0===t.length)return null;let l=cs(t,i,r),c="top"===n||"bottom"===n,u=ms(e),d={...us(t,i,r),legendDistance:e.legendDistance},h=e.reservedWidth??ke(d,e.legendLayout),{x:p,y:f}=Ne(d,{totalWidth:o,totalHeight:a,margin:s,position:n,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:h}),g=c?void 0:Fe([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??22))[0],m=u.items.map((e,t)=>ls("g",{transform:`translate(${e.x},${e.y+(g?.itemsY??0)})`,children:[ss("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),ss("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:hs(r),fill:r.colors.text,fontFamily:ps(r),children:e.category})]},`legend-${t}`));return ls("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:fs(r),children:[g&&ss("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),m]})}({categories:i,colorScheme:t.colorScheme,theme:r,position:s,totalWidth:n[0],totalHeight:n[1],margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function zc(e,t){let i=Ii(t.theme),r=_i(t.theme,`[data-semiotic-auto="${t.idPrefix??"chart"}"]`),n=t.background??i.background,o=t.idPrefix?`${t.idPrefix}-`:"",a=un(t.title),s=t.idPrefix?dc(t.idPrefix):{titleId:"semiotic-title",descId:"semiotic-desc"},l=a?s.titleId:void 0,c=t.description?s.descId:void 0,u=[l,c].filter(Boolean).join(" ")||void 0;return Ic("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,"data-semiotic-auto":r?t.idPrefix??"chart":void 0,role:"img","aria-labelledby":u,"aria-label":t.description||a||`${t.className.match(/stream-(\w+)-frame/)?.[1]??"data"} chart, ${t.markCount??0} marks`,style:{fontFamily:i.fontFamily},children:[r&&Pc("style",{children:r}),a&&Pc("title",{id:l,children:a}),t.description&&Pc("desc",{id:c,children:t.description}),t.defs&&Pc("defs",{children:t.defs}),n&&"transparent"!==n&&Pc("rect",{x:0,y:0,width:t.width,height:t.height,fill:n}),Pc("g",{id:`${o}data-area`,transform:t.innerTransform,children:e}),a&&Pc("text",{id:`${o}chart-title`,x:t.width/2,y:22,textAnchor:"middle",fontSize:i.titleFontSize,fontWeight:i.titleFontWeight,fill:i.text,fontFamily:i.titleFontFamily,children:dn(t.title)}),t.legend&&Pc("g",{id:`${o}legend`,children:t.legend}),t.outerElements]})}import{jsx as Bc,jsxs as jc}from"react/jsx-runtime";import*as Wc from"react";import{jsx as Yc,jsxs as qc}from"react/jsx-runtime";function Xc(e){return"under"===e.layer&&("band"===e.type||"x-band"===e.type)}function Gc(e,t,i,r){return"function"==typeof e?e({size:t,margin:i,scales:r}):e}var Vc={top:50,right:40,bottom:60,left:70},Hc={top:20,right:80,bottom:20,left:80},Uc={top:40,right:40,bottom:40,left:40},Zc=/*#__PURE__*/new Set(["chord","force","circlepack","orbit"]);import{jsx as Kc,jsxs as Qc}from"react/jsx-runtime";import{Fragment as Jc,jsx as eu,jsxs as tu}from"react/jsx-runtime";function iu(e,t){let i=Pi(e.theme),r=Vc,n=e.size||[500,300],o=ve({...r,...e.margin},un(e.title)),a=xe(un(e.title)),s=function(e,t){if(!t||0===e.length||!e.some(e=>null!=e&&"object"==typeof e&&Array.isArray(e[t])))return e;let i=[];for(let r of e){if(null==r||"object"!=typeof r)continue;let e=r[t];if(!Array.isArray(e))continue;let n=r.label??r.id??r.key;for(let t of e)null==t||"object"!=typeof t||i.push(null==n?t:{...t,_lineGroup:n})}return i}(_t(e.data),e.lineDataAccessor),l=e.showLegend?ys(s,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[],c=Te({showAxes:e.showAxes,xLabel:e.xLabel,yLabel:e.yLabel,yLabelRight:e.yLabelRight,axes:e.axes});Ec(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=Oc({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),p="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),f=e.colorScheme||i.colors.categorical,g=(e.axes?.find(e=>"left"===e.orient)??e.axes?.find(e=>"right"===e.orient))?.extent??e.axisExtent,m={chartType:e.chartType,runtimeMode:p?"streaming":"bounded",windowSize:e.windowSize??e.capacity??200,windowMode:e.windowMode??e.capacityMode??"sliding",arrowOfTime:p?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:e.xAccessor,yAccessor:e.yAccessor,timeAccessor:p?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor||(e.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,invertY:e.invertY,axisExtent:e.axisExtent,yAxisExtent:g,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,binAlign:e.binAlign,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:gi(e.gradientFill),lineGradient:mi(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:f,themeCategorical:i.colors.categorical,themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging,themeSemantic:_(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat,heatmapColorScale:e.heatmapColorScale,heatmapAggregation:e.heatmapAggregation,heatmapXBins:e.heatmapXBins,heatmapYBins:e.heatmapYBins,pointIdAccessor:e.pointIdAccessor,onLayoutError:e.onLayoutError},y=new Co(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Gc(e.backgroundGraphics,n,o,y.scales),b=Gc(e.foregroundGraphics,n,o,y.scales),v=function(e=[]){let t=e.filter(e=>e._directLabel);return t.length?` Series endpoints: ${t.map(e=>`${e.label}: x ${String(e.x)}, y ${String(e.y)}`).join("; ")}.`:""}(e.annotations),w=v?`${e.description||e.title||"Line chart."}${v}`:e.description;if(!y.scales){let r,a=e.annotations?lc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=xa({frameType:"xy",width:n[0],height:n[1],marks:[],title:e.title,description:w,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?tu(Jc,{children:[x,a,b]}):null;return fn.renderToStaticMarkup(zc(l,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:w,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let S,k=e._idPrefix,A=os({nodes:y.scene,renderMode:e.renderMode,fallback:(t,i)=>is(t,i,k,e.hoverRadius??30)}),M=!y.xIsDate||e.xFormat||e.tickFormatTime||Uo(y.scales.x)?e:{...e,xFormat:gr(y.scales.x.domain().map(e=>e.valueOf()))},$=e.showGrid?function(e,t,i,r,n,o,a){let{grid:s}=Ii(i),l=r?`${r}-`:"",c=o?.find(e=>"bottom"===e.orient),u=o?.find(e=>"top"===e.orient),d=o?.find(e=>"left"===e.orient),h=o?.find(e=>"right"===e.orient),p=c??u,f=d??h,g=$c({scale:e.x,axis:p,size:t.width,horizontal:!0,format:a?.xFormat||a?.tickFormatTime,axisExtent:n}),m=$c({scale:e.y,axis:f,size:t.height,format:a?.yFormat||a?.tickFormatValue,axisExtent:n}),y=!1!==p?.grid,x=!1!==f?.grid,b=mc(p?.gridStyle),v=mc(f?.gridStyle),w=yc(p?.gridStyle,{stroke:s,strokeWidth:.5}),S=yc(f?.gridStyle,{stroke:s,strokeWidth:.5});return jc("g",{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:[y&&g.map((e,i)=>Bc("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:t.height,...w,strokeDasharray:b??w.strokeDasharray},`gx-${i}`)),x&&m.map((e,i)=>Bc("line",{x1:0,y1:e.pixel,x2:t.width,y2:e.pixel,...S,strokeDasharray:v??S.strokeDasharray},`gy-${i}`))]})}(y.scales,{width:d,height:h},i,k,e.axisExtent,e.axes,M):null,P=A.map(e=>e.element),I=`${Lc(e)}-plot-clip`,T=!1!==e.showAxes,L=T?function(e,t,i,r,n,o,a,s=!1){let l=Ii(r),c=i.legendPosition??"right",u=Me(i.legendLayout,a?.leftAxis),d=Me(i.legendLayout,a?.rightAxis),h=s&&"left"===c&&u>0?u:o?.left??i.margin?.left??40,p=s&&"right"===c&&d>0?d:o?.right??i.margin?.right??40,{xAxis:f,yAxis:g,xOrient:m,yOrient:y}=pe(i.axes),x="top"===m?0:t.height,b="right"===y?t.width:0,v="top"===m?-1:1,w="right"===y?1:-1,S=$c({scale:e.x,axis:f,size:t.width,horizontal:!0,format:i.xFormat||i.tickFormatTime,axisExtent:i.axisExtent}),k=$c({scale:e.y,axis:g,size:t.height,format:i.yFormat||i.tickFormatValue,axisExtent:i.axisExtent}),A=!(!f?.autoRotate||!function(e){for(let t=1;t<e.length;t++){let i=e[t-1],r=e[t];if(Math.abs(r.pixel-i.pixel)<(Mc(i.label)+Mc(r.label))/2+8)return!0}return!1}(S)),M=gc(S),$=gc(k),_=f?.label??i.xLabel,P=g?.label??("right"===y?i.yLabelRight??i.yLabel:i.yLabel),I=yc(f?.axisStyle,{stroke:l.border,strokeWidth:1}),T=yc(g?.axisStyle,{stroke:l.border,strokeWidth:1}),L="right"===y?t.width+p-15:15-h;return Ic("g",{id:(n?`${n}-`:"")+"axes",className:"stream-axes",children:[!1!==f?.visible&&Ic("g",{className:`semiotic-axis semiotic-axis-${m}`,"data-orient":m,children:[!1!==f?.baseline&&!f?.jaggedBase&&Pc("line",{x1:0,y1:x,x2:t.width,y2:x,...I}),f?.jaggedBase&&Pc("path",{d:xc(m,t.width,t.height),fill:"none",...I}),S.map((e,t)=>{let i=_c(f?.landmarkTicks,e,t,S);return Ic("g",{transform:`translate(${e.pixel},${x})`,children:[Pc("line",{y2:5*v,...I}),wc(e.label)?Pc("text",{y:v*(A?12:18),textAnchor:A?"end":pc(f?.tickAnchor,e.pixel===M.min,e.pixel===M.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:A?"top"===m?"rotate(45)":"rotate(-45)":void 0,children:e.label}):Sc({label:e.label,x:-30,y:"top"===m?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`xtick-${t}`)}),_&&Pc("text",{x:t.width/2,y:"top"===m?-(A?58:40):t.height+(A?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:_})]}),!1!==g?.visible&&Ic("g",{className:`semiotic-axis semiotic-axis-${y}`,"data-orient":y,children:[!1!==g?.baseline&&!g?.jaggedBase&&Pc("line",{x1:b,y1:0,x2:b,y2:t.height,...T}),g?.jaggedBase&&Pc("path",{d:xc(y,t.width,t.height),fill:"none",...T}),k.map((e,t)=>{let i=_c(g?.landmarkTicks,e,t,k);return Ic("g",{transform:`translate(${b},${e.pixel})`,children:[Pc("line",{x2:5*w,...T}),wc(e.label)?Pc("text",{x:8*w,textAnchor:"right"===y?"start":"end",dominantBaseline:fc(g?.tickAnchor,e.pixel===$.min,e.pixel===$.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:e.label}):Sc({label:e.label,x:"right"===y?8:-68,y:-12,textAlign:"right"===y?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`ytick-${t}`)}),P&&Pc("text",{x:L,y:t.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===y?90:-90}, ${L}, ${t.height/2})`,children:P})]})]})}(y.scales,{width:d,height:h},M,i,k,o,c,!!u):null,C=T?function(e){let{scales:t,layout:i,props:r,theme:n,leftAxis:o,rightAxis:a,margin:s,axisChrome:l,hasRenderedLegend:c}=e;if(!o||!a||!1===a.visible)return null;let u=Ii(n),d=$c({scale:t.y,axis:a,size:i.height,format:r.yFormat||r.tickFormatValue,axisExtent:r.axisExtent}),h=gc(d),p=a.label??r.yLabelRight,f=yc(a.axisStyle,{stroke:u.border,strokeWidth:1}),g=r.legendPosition??"right",m=Me(r.legendLayout,l?.rightAxis),y=c&&"right"===g&&m>0?m:s.right,x=i.width+y-15;return Qc("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==a.baseline&&!a.jaggedBase&&Kc("line",{x1:i.width,y1:0,x2:i.width,y2:i.height,...f}),a.jaggedBase&&Kc("path",{d:xc("right",i.width,i.height),fill:"none",...f}),d.map((e,t)=>{let r=_c(a.landmarkTicks,e,t,d);return Qc("g",{transform:`translate(${i.width},${e.pixel})`,children:[Kc("line",{x2:5,...f}),wc(e.label)?Kc("text",{x:8,textAnchor:"start",dominantBaseline:fc(a.tickAnchor,e.pixel===h.min,e.pixel===h.max),fontWeight:r?600:400,fontSize:r?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):Sc({label:e.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},`ytick-r-${t}`)}),p&&Kc("text",{x:x,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${x}, ${i.height/2})`,children:p})]})}({scales:y.scales,layout:{width:d,height:h},props:e,theme:i,leftAxis:e.axes?.find(e=>"left"===e.orient),rightAxis:e.axes?.find(e=>"right"===e.orient),margin:o,axisChrome:c,hasRenderedLegend:!!u}):null,R=e.annotations?lc({annotations:e.annotations,margin:o,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.scales.y},layout:{width:d,height:h},theme:i,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:k,underLayerBands:!0,onRender:e=>{S=e}}):null;t&&(t.evidence=xa({frameType:"xy",width:n[0],height:n[1],marks:A.map(e=>e.node),title:e.title,description:w,annotations:e.annotations,annotationRender:S,xDomain:ya(y.scales.x?.domain?.()),yDomain:ya(y.scales.y?.domain?.()),legendItems:l.length>0?l.length:void 0,margin:o}));let N=e.svgPreRenderers&&y.scales?e.svgPreRenderers.map((e,t)=>{try{return eu(pn.Fragment,{children:e(y.scene,y.scales,{width:d,height:h})},`pre-${t}`)}catch(e){return"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] SVG pre-renderer ${t} failed.`,e),null}}).filter(Boolean):null,D=X(e.annotations??[]).filter(Xc),F=D.length>0?function(e,t="under-band",i="var(--semiotic-primary, #6366f1)"){return(r,n,o)=>e.map((e,r)=>{let a=function(e,t,i,r){let n="band"===e.type,o=n?t.y:t.x;if("function"!=typeof o)return null;let a=n?e.y0:e.x0,s=n?e.y1:e.x1,l=ta(o,a,0),c=ta(o,s,1);if(null!=a&&null==l||null!=s&&null==c)return null;let u=l??0,d=c??(n?r:i);if(!Number.isFinite(u)||!Number.isFinite(d))return null;let h=n?r:i,p=Math.min(h,Math.max(0,Math.min(u,d))),f=Math.max(0,Math.min(h,Math.max(u,d))-p);return n?{x:0,y:p,width:i,height:f}:{x:p,y:0,width:f,height:r}}(e,n,o.width,o.height);if(!a)return null;let s=Pl(e,`${t}-${r}`,function(e){return"band"===e.type?"vertical":"horizontal"}(e),i);return qc("g",{opacity:e.opacity,children:[s.def&&Yc("defs",{children:s.def}),Yc("rect",{...a,fill:s.fill,fillOpacity:e.fillOpacity??.1})]},`${t}-${r}`)})}(D,`${Lc(e)}-under-band`,i.colors.primary||i.colors.annotation||i.colors.text)(y.scene,y.scales,{width:d,height:h}):null,E=tu(Jc,{children:[x,N,$,eu("defs",{children:eu("clipPath",{id:I,children:eu("rect",{x:0,y:0,width:d,height:h})})}),tu("g",{clipPath:`url(#${I})`,children:[F,P]}),L,C,R,b,y.customLayoutOverlays]});return fn.renderToStaticMarkup(zc(E,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:w,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,markCount:A.length,idPrefix:e._idPrefix}))}fa();import*as ru from"react-dom/server";import{jsx as nu,jsxs as ou}from"react/jsx-runtime";function au({machine:e,layout:t,runtime:i,downstreamSet:r,selectedSet:n,width:o,height:a,seed:s,reduced:l,onSelectTask:c}){let u=t.tasks.length?t.tasks.reduce((e,t)=>Math.min(e,t.y-t.height/2),1/0):60,d=Math.max(20,u-12),h=Math.max(26,u-6);return ou("svg",{"aria-hidden":"true",width:o,height:a,viewBox:`0 0 ${o} ${a}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[nu("defs",{children:nu("filter",{id:`chain-shadow-${s}`,x:"-20%",y:"-20%",width:"140%",height:"150%",children:nu("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,i)=>{let r=t.tasks.filter(e=>e.laneIndex===i)[0]?.x??0;return ou("g",{children:[nu("line",{x1:r,x2:r,y1:h,y2:a-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),nu("text",{x:r,y:d,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{let t=i.delivered.has(e.edgeID),n=i.inFlight.has(e.edgeID),o=r.has(e.targetID)||r.has(e.sourceID),a=e.points.map(e=>`${e.x},${e.y}`).join(" ");return nu("polyline",{points:a,fill:"none",stroke:o?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:n?3:2,strokeOpacity:t||n||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{let t=i.delivered.has(e.edgeID);return ou("g",{children:[nu("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&nu("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{let o=t.taskByID.get(e.id);if(!o)return null;let a=i.completed.has(e.id),u=i.blockers.has(e.id),d=i.previewTaskID===e.id,h=n.has(e.id)||d,p=r.has(e.id),f=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,i),g=o.x-o.width/2,m=o.y-o.height/2,y=Math.max(2,o.height*e.progress);return ou("g",{children:[ou("g",{style:{transform:`rotate(${a?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:l?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+s+")"},children:[nu("rect",{x:g,y:m,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||p?"var(--semiotic-selection-color, #e08a1e)":f,strokeWidth:h?4:p?3:2}),nu("rect",{x:g+3,y:m+o.height-y+1,width:o.width-6,height:Math.max(0,y-4),rx:2,fill:f,opacity:a?.86:.46})]}),u&&ou("g",{opacity:d?.28:1,children:[nu("line",{x1:g-8,x2:g+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),nu("circle",{cx:g-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),ou("g",{onPointerDown:()=>c(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[nu("rect",{x:g,y:m,width:o.width,height:o.height,fill:"transparent"}),nu("text",{x:o.x,y:o.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?`${e.label.slice(0,22)}…`:e.label}),ou("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% ·"," ",a?"done":u?"blocked":i.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}function su(e,t=0){if(e instanceof Date)return e.getTime();let i=Number(e);return Number.isFinite(i)?i:t}function lu(e){if(null==e.completionTime)return null;let t=su(e.completionTime,Number.NaN);return Number.isFinite(t)?t:null}function cu(e,t,i,r){let n=new Set;for(let o of e.nodes){let a=e.incoming.get(o.id)??[];(r.has(o.id)||!i.has(o.id)&&a.every(e=>t.has(e.id)))&&n.add(o.id)}return n}function uu(e,t,i={}){let r=new Set,n=[...e.get(t)??[]];for(let t=0;t<n.length;t++){let i=n[t];r.has(i)||(r.add(i),n.push(...e.get(i)??[]))}return i.includeStart&&r.add(t),r}function du(e,t,i){return function(e,t,i){if(null!=e)return"function"==typeof e?e(t,i):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}(i,e,t)}function hu(e,t){return e<t?-1:e>t?1:0}function pu(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function fu(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function gu(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function mu(e){return e.filter((t,i)=>{let r=e[i-1];return!r||r.x!==t.x||r.y!==t.y})}function yu(e,t,i={}){let r=new Set(i.completedTaskIDs??[]),n=function(e,t){let i=new Map;for(let t of e)i.set(t.id,new Set);for(let e of t)i.has(e.source)||i.set(e.source,new Set),i.has(e.target)||i.set(e.target,new Set),i.get(e.source).add(e.target);return i}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),o=[...uu(n,t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(i.isComplete?i.isComplete(e):r.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),a=Array.from(new Set(o.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:o.length,affectedLaneCount:a.length,downstreamTaskIDs:o.map(e=>e.id),affectedLanes:a}}import{jsx as xu,jsxs as bu}from"react/jsx-runtime";import*as vu from"react-dom/server";var wu=e=>Math.max(6,Math.round(2*e/3)),Su=(e,t,i)=>Math.min(i,Math.max(t,e)),ku=e=>Number(e.toPrecision(15));function Au(e){if(!Number.isFinite(e))return"";let t=Math.round(100*e)/100;return String(Object.is(t,-0)?0:t)}function Mu(e,t,i,r=1.2*i,n){return"y"===t?e.length*r:n??he(e.map(e=>Array.from(e).length),0)*i*.6}function $u(e){return e.__composite}function _u(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function Pu(e,t,i,r){return e.replace(/^<svg\b/,`<svg x="${t}" y="${i}" data-semiotic-composite-part="${r}"`)}function Iu(e,t){for(let i of e){let e=i?.[t];if(Array.isArray(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1])return e}}import{jsx as Tu,jsxs as Lu}from"react/jsx-runtime";var Cu=e=>!0===e?{}:e&&"object"==typeof e?e:null,Ru=e=>"string"==typeof e?e:void 0;function Nu(e){return t=>{try{let i="function"==typeof e?e(t):void 0;return"string"==typeof i?i:Au(t)}catch{return Au(t)}}}function Du(e,t,i,r,n,o,a){let s=[.35,.65].map(e=>"x"===a?{x1:t-r/2+r*e,x2:t-r/2+r*e,y1:i-.2*n,y2:i+.2*n}:{x1:t-.2*r,x2:t+.2*r,y1:i-n/2+n*e,y2:i-n/2+n*e});return Lu("g",{className:"semiotic-brush-handle","data-semiotic-brush-part":e,children:[Tu("rect",{x:t-r/2+.5,y:i-n/2+.5,width:r-1,height:n-1,rx:o.radius,fill:o.fill,stroke:o.stroke,strokeWidth:1}),s.map((e,t)=>Tu("line",{...e,stroke:o.grip,strokeWidth:1},t))]},e)}import{jsx as Fu,jsxs as Eu}from"react/jsx-runtime";import{jsx as Ou,jsxs as zu}from"react/jsx-runtime";var Bu={top:4,bottom:4,left:4,right:4};function ju(e,t,i,r,n){return{__composite:{data:e,colorBy:t,colorScheme:i,common:r,rest:n}}}function Wu(e,t){return Math.max(1,Math.floor(_u(e,t)))}var Yu={frameType:"xy",buildProps:ju,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=$u(e),[s,l]=o.size??[600,400],c=a.minimap&&"object"==typeof a.minimap?a.minimap:{},u=_u(c.height,60),d=o.margin,h=c.margin&&"object"==typeof c.margin?c.margin:{},p=function(e){let t=e.handles&&"object"==typeof e.handles?e.handles:e.handles?{}:null,i="number"==typeof t?.size&&Number.isFinite(t.size)?t.size:12;return{top:t?.move?Math.ceil(wu(i)/2)+2:0,bottom:e.showExtentLabels?34:20}}(c),f={top:_u(h.top,p.top),right:_u(h.right,_u(d?.right,20)),bottom:_u(h.bottom,p.bottom),left:_u(h.left,_u(d?.left,40))},g=u+f.top+f.bottom,m=a.frameProps&&"object"==typeof a.frameProps?a.frameProps:{},y={...a,xAccessor:a.xAccessor||"x",yAccessor:a.yAccessor||"y"},x="y"===c.brushDirection?"y":"x",b={...o,size:[s,l],xExtent:m.xExtent??("x"===x?a.brushExtent:void 0)??o.xExtent,yExtent:m.yExtent??("y"===x?a.brushExtent:void 0)??a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-detail`},v=Kr.buildProps(i,r,n,b,y);Object.assign(v,m);let w={...o,size:[s,g],margin:f,title:void 0,description:`${String(o.description??o.title??"Chart")} overview minimap`,showAxes:c.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:c.background,xExtent:void 0,yExtent:a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-overview`};delete w.lineStyle,delete w.pointStyle;let S={...y,fillArea:!1,lineWidth:1,showPoints:!1,directLabel:!1,forecast:void 0,anomaly:void 0,band:void 0},k=Kr.buildProps(i,r,n,w,S);k.chartType=a.fillArea?"area":"line","function"==typeof c.lineStyle&&(k.lineStyle=c.lineStyle);let A={},M={},$=iu(v,A),_=iu(k,M),P=!0===a.renderBefore,I=P?0:l,T=[Pu($,0,P?g:0,"detail"),Pu(_,0,I,"overview")].join(""),L=l+g,C=Pi(o.theme),R=Ii(C),N=un(o.title)||void 0,D="string"==typeof o.description?o.description:N||"Chart with overview minimap",F=Lc(o),E=N?`${F}-title`:void 0,O=`${F}-description`,z=Array.isArray(a.brushExtent)&&a.brushExtent.length>=2?[Number(a.brushExtent[0]),Number(a.brushExtent[1])]:null,B="x"===x?M.evidence?.xDomain:M.evidence?.yDomain,j=B?function(e){let{theme:t,config:i,direction:r,plot:n,margin:o}=e,a=function({domain:e,scale:t,orientation:i,reverse:r=!1}){if(t){let e=t.range().map(Number),i=t.domain().map(Number),r=Math.min(e[0],e[e.length-1]),n=Math.max(e[0],e[e.length-1])-r,o=Math.min(i[0],i[i.length-1]),a=Math.max(i[0],i[i.length-1]);if(![r,n,o,a].every(Number.isFinite)||n<=0||a<=o)return null;let s=Math.abs(t(o)-r)<=Math.abs(t(a)-r);return{min:o,max:a,toFraction:e=>(t(e)-r)/n,fromFraction:e=>e<=0?s?o:a:e>=1?s?a:o:Su(ku(Number(t.invert(r+e*n))),o,a)}}if(!e)return null;let n=Math.min(Number(e[0]),Number(e[1])),o=Math.max(Number(e[0]),Number(e[1]));if(!Number.isFinite(n)||!Number.isFinite(o)||o<=n)return null;let a=o-n,s="x"===i?!r:r;return{min:n,max:o,toFraction:e=>{let t=(e-n)/a;return s?t:1-t},fromFraction:e=>e<=0?s?n:o:e>=1?s?o:n:ku(s?n+e*a:o-e*a)}}({domain:e.domain,orientation:r});if(!a)return null;let s=Cu(i.handles),l=function(e,t){if(!e||e.length<2)return null;let i=Number(e[0]),r=Number(e[1]);return Number.isFinite(i)&&Number.isFinite(r)?[Su(Math.min(i,r),t.min,t.max),Su(Math.max(i,r),t.min,t.max)]:null}(e.extent,a)??(s?[a.min,a.max]:null);if(!l)return null;let c=Cu(i.brushStyle)??{},u=function(e){let t=e.colors.selection??e.colors.primary;return{fill:t,fillOpacity:.2,stroke:t,strokeWidth:1}}(t),d=t.colors.surface??t.colors.background,h="x"===r?n.width:n.height,[p,f]=[a.toFraction(l[0]),a.toFraction(l[1])].sort((e,t)=>e-t),g=(e,t)=>"x"===r?{x:n.x+e*h,y:n.y,width:(t-e)*h,height:n.height}:{x:n.x,y:n.y+e*h,width:n.width,height:(t-e)*h},m=[],y=Cu(c.mask);if(y)for(let[e,t]of[[0,p],[f,1]])m.push(Tu("rect",{className:"semiotic-brush-mask","data-semiotic-brush-part":"mask",...g(e,t),fill:Ru(y.fill)??d,opacity:_u(y.opacity,.6)},`mask-${e}`));let x=_u(c.strokeWidth,1),b=g(p,f);if(m.push(Tu("rect",{className:"selection","data-semiotic-brush-part":"selection",x:b.x+x/2,y:b.y+x/2,width:Math.max(0,b.width-x),height:Math.max(0,b.height-x),fill:Ru(c.fill)??u.fill,fillOpacity:_u(c.fillOpacity,.2),stroke:Ru(c.stroke)??u.stroke,strokeWidth:x},"selection")),s){let e=_u(s.size,12),t=wu(e),i={fill:Ru(s.fill)??d,stroke:Ru(s.stroke)??u.stroke,grip:u.stroke,radius:_u(s.radius,3)};for(let[o,a]of[["start",p],["end",f]])m.push("x"===r?Du(o,n.x+a*h,n.y+n.height/2,t,2*e,i,"x"):Du(o,n.x+n.width/2,n.y+a*h,2*e,t,i,"y"));if(s.move){let o=(p+f)/2;m.push("x"===r?Du("move",n.x+o*h,n.y,2*e,t,i,"x"):Du("move",n.x,n.y+o*h,t,2*e,i,"y"))}}if(i.showExtentLabels){let s=function(e){let{value:t,track:i,length:r,orientation:n,format:o,fontSize:a,labelWidth:s,showDomainLabels:l}=e,c=e.lineHeight??1.2*a,u=e.gap??6,[d,h]=e.bounds??[0,r],p=(e,t,r=i.toFraction(t))=>{let l=o(t),u=l.split("\n");return{kind:e,value:t,text:l,lines:u,fraction:r,size:Mu(u,n,a,c,s)}},f=(e,t)=>{let i=e.fraction*r,n=t;"before"===n&&i-e.size<d?n="after":"after"===n&&i+e.size>h&&(n="before");let o="before"===n?i-e.size:i;return{...e,placement:n,row:0,from:o,to:o+e.size}},g=p("start",t[0]),m=p("end",t[1]),[y,x]=g.fraction<=m.fraction?[g,m]:[m,g],b=f(y,"before"),v=f(x,"after");b.to+u>v.from&&(v.row=1);let w=[b,v];if(!l)return w;let S=w.filter(e=>0===e.row),k=e=>{let t=i.fromFraction(e),n=p(t===i.min?"domain-start":"domain-end",t,e),o=0===e?0:r-n.size;return{...n,placement:0===e?"after":"before",row:0,from:o,to:o+n.size}};return[...[k(0),k(1)].filter(e=>e.from>=d&&e.to<=h&&S.every(t=>e.to+u<=t.from||t.to+u<=e.from)),...w]}({value:l,track:a,length:h,orientation:r,format:Nu(i.extentLabelFormat??e.axisFormat),fontSize:11,bounds:"x"===r?[-o.left,n.width+o.right]:[-o.top,n.height+o.bottom]}),c=13.2*he(s.map(e=>e.lines.length),1);for(let e of s){let i="before"===e.placement,o="x"===r?n.x+e.fraction*h:n.x+n.width+4,a="x"===r?n.y+n.height+4+e.row*c:n.y+e.from;m.push(Tu("text",{className:"semiotic-brush-label","data-semiotic-brush-label":e.kind,x:o,y:a+10.45,fill:t.colors.textSecondary,fontFamily:t.typography.fontFamily,fontSize:11,textAnchor:"x"===r&&i?"end":"start",children:e.lines.map((e,t)=>Tu("tspan",{x:o,dy:0===t?0:13.2,children:e},t))},`label-${e.kind}`))}}return Tu("g",{className:"semiotic-minimap-brush",children:m})}({theme:C,config:c,direction:x,domain:B,extent:z&&z.every(Number.isFinite)?z:null,plot:{x:f.left,y:I+f.top,width:Math.max(0,s-f.left-f.right),height:u},margin:f,axisFormat:"x"===x?o.xFormat:o.yFormat}):null,W=vu.renderToStaticMarkup(Eu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:s,height:L,role:"img","aria-labelledby":[E,O].filter(Boolean).join(" "),style:{fontFamily:R.fontFamily},children:[N&&Fu("title",{id:E,children:N}),Fu("desc",{id:O,children:D}),Fu("g",{dangerouslySetInnerHTML:{__html:T}}),j]}));if(t){let e=[A.evidence,M.evidence];t.evidence=ga({frameType:"xy",width:s,height:L,parts:e,title:N,description:D,xDomain:Iu(e,"xDomain"),yDomain:Iu(e,"yDomain")})}return W}};function qu(e,t){return String("function"==typeof t?t(e):e[t])}var Xu={frameType:"physics",buildProps:ju,renderStatic:function(e,t){let{data:i,common:r,rest:n}=function(e){return e.__composite}(e),o=function(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}(i),[a,s]=r.size??[920,620],l=un(r.title)||"Dependency chain reaction",c=function(e){let t=[],i=new Map,r=[],n=new Set;e.data.forEach((o,a)=>{let s=String(du(o,a,e.taskIDAccessor)??"");if(!s)return void t.push({code:"duplicate-task-id",message:`Task row ${a} has an empty id.`,taskIDs:[]});if(i.has(s))return void t.push({code:"duplicate-task-id",message:`Task id "${s}" occurs more than once.`,taskIDs:[s]});let l=String(du(o,a,e.laneAccessor)??"Unassigned");n.has(l)||(n.add(l),r.push(l));let c=du(o,a,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(c,e=>String(e)))).sort(hu),d=du(o,a,e.blockerAccessor),h=du(o,a,e.statusAccessor)??(d?"blocked":"waiting");i.set(s,{id:s,label:String(du(o,a,e.labelAccessor)??s),lane:l,laneIndex:0,level:0,index:a,datum:o,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:du(o,a,e.startAccessor),end:du(o,a,e.endAccessor),progress:gu(du(o,a,e.progressAccessor)),status:h,completionTime:du(o,a,e.completionTimeAccessor),blockerReason:d||void 0,milestone:!!du(o,a,e.milestoneAccessor)})});let o=e.laneOrder?[...e.laneOrder,...r.filter(t=>!e.laneOrder?.includes(t))]:r,a=new Map(o.map((e,t)=>[e,t]));for(let e of i.values())e.laneIndex=a.get(e.lane)??0;let s=new Map,l=new Map;for(let e of i.keys())s.set(e,[]),l.set(e,[]);let c=[],u=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of u)e.dependencyIDs.forEach((r,n)=>{let o=i.get(r);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${r}".`,taskIDs:[e.id,r]});let a={id:pu(r,e.id),sourceID:r,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:fu(e.id,n),socketIndex:n};c.push(a),s.get(e.id)?.push(a),l.get(r)?.push(a),e.incomingEdgeIDs.push(a.id),e.socketIDs.push(a.socketID),o.outgoingEdgeIDs.push(a.id)});for(let e of s.values())e.sort((e,t)=>hu(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=fu(e.targetID,t)});for(let e of l.values())e.sort((e,t)=>hu(e.targetID,t.targetID));for(let e of i.values()){let t=s.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(l.get(e.id)??[]).map(e=>e.id)}let d=new Map,h=new Map;for(let e of i.keys())d.set(e,s.get(e)?.length??0),h.set(e,0);let p=[...i.keys()].filter(e=>0===d.get(e)).sort(hu),f=0;for(;p.length;){let e=p.shift();f+=1;for(let t of l.get(e)??[]){let i=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,i);let r=(d.get(t.targetID)??0)-1;if(d.set(t.targetID,r),0===r){let e=p.findIndex(e=>e>t.targetID);e<0?p.push(t.targetID):p.splice(e,0,t.targetID)}}}if(f!==i.size){let e=[...i.keys()].filter(e=>(d.get(e)??0)>0).sort(hu);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let g=0,m=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of m)e.level=h.get(e.id)??0,g=Math.max(g,e.level);return{nodes:m,edges:c,byID:i,incoming:s,outgoing:l,lanes:o,maxLevel:g,diagnostics:t,valid:0===t.length}}({data:o,taskIDAccessor:n.taskIDAccessor,labelAccessor:n.labelAccessor,laneAccessor:n.laneAccessor,dependencyAccessor:n.dependencyAccessor,startAccessor:n.startAccessor,endAccessor:n.endAccessor,progressAccessor:n.progressAccessor,statusAccessor:n.statusAccessor,completionTimeAccessor:n.completionTimeAccessor,blockerAccessor:n.blockerAccessor,milestoneAccessor:n.milestoneAccessor}),u=Pi(r.theme),d=Ii(u),h=Lc(r),p=`${h}-title`,f=`${h}-description`;if(!c.valid){let e=c.diagnostics.map(e=>e.message).join(" "),i=ru.renderToStaticMarkup(bu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${p} ${f}`,style:{fontFamily:d.fontFamily},children:[xu("title",{id:p,children:l}),xu("desc",{id:f,children:e}),xu("rect",{width:a,height:s,fill:d.background}),xu("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:d.text,children:l}),c.diagnostics.map((e,t)=>xu("text",{x:24,y:72+22*t,fontSize:12,fill:u.colors.error,children:e.message},`${e.code}-${t}`))]}));return t&&(t.evidence=ga({frameType:"physics",width:a,height:s,parts:[],title:l,description:e,nodeCount:c.nodes.length,edgeCount:c.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),i}let g=function(e,t,i={}){let r=Math.max(240,t.width),n=Math.max(220,t.height),o=t.paddingX??48,a=t.paddingTop??48,s=t.paddingBottom??44,l=Math.max(1,e.lanes.length),c=Math.max(70,(r-2*o)/l),u=Math.max(1,e.maxLevel+1),d=Math.max(76,(n-a-s)/u),h=Math.min(i.taskWidth??112,Math.max(58,.78*c)),p=Math.min(i.taskHeight??58,.64*d),f=i.socketRadius??5,g=Math.max(1,Math.round(i.gutterCount??3)),m=new Map;for(let t of e.nodes){let e=`${t.laneIndex}:${t.level}`,i=m.get(e)??[];i.push(t),m.set(e,i)}for(let e of m.values())e.sort((e,t)=>hu(e.id,t.id));let y=.86*d,x=e.nodes.map(e=>{let t=m.get(`${e.laneIndex}:${e.level}`)??[e],i=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,r=(e=>e<=1?p:Math.max(22,Math.min(p,(y-4*(e-1))/e)))(t.length),n=i*(r+4);return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:a+d*(e.level+.5)+n,width:h,height:r}}),b=new Map(x.map(e=>[e.taskID,e])),v=[],w=[];e.edges.forEach((t,i)=>{let r=b.get(t.sourceID),n=b.get(t.targetID);if(!r||!n)return;let o=e.incoming.get(t.targetID)??[],a=Math.min(.72*n.width,14*Math.max(1,o.length-1)),s=o.length<=1?n.x:n.x-a/2+a*t.socketIndex/(o.length-1),l=n.y-n.height/2-f-2,c={id:t.socketID,edgeID:t.id,taskID:n.taskID,index:t.socketIndex,x:s,y:l,radius:f};v.push(c);let u={x:r.x,y:r.y+r.height/2+3},d=Math.max(18,l-u.y),h=7*(i%g-(g-1)/2),p=Math.min(l-10,u.y+.48*d+h);w.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:mu([u,{x:u.x,y:p},{x:s,y:p},{x:s,y:l}])})});let S=new Map(v.map(e=>[e.id,e])),k=new Map(w.map(e=>[e.edgeID,e]));return{tasks:x,sockets:v,routes:w,taskByID:b,socketByID:S,routeByEdgeID:k}}(c,{width:a,height:s}),m=function(e,t,i){let r=e.nodes.map(lu).filter(e=>null!=e),n=(r.length&&r.reduce((e,t)=>Math.min(e,t),1/0),i),o=new Set,a=new Map;for(let t of e.nodes){let e=lu(t),i=null!=e&&e<=n,r="done"===t.status&&!0;(i||r)&&o.add(t.id),t.blockerReason&&!o.has(t.id)&&a.set(t.id,t.blockerReason)}let s=new Set;for(let t of e.edges)o.has(t.sourceID)&&s.add(t.id);return{currentTime:n,playing:!1,completed:o,delivered:s,inFlight:new Set,armed:cu(e,s,a,o),blockers:a,previewTaskID:null}}(c,0,su(n.currentTime,1/0)),y=Array.isArray(n.selectedTaskIDs)?n.selectedTaskIDs.map(String):[],x=new Set(y),b=y[0]??null,v=b&&"none"!==n.insight?yu(c,b,{completedTaskIDs:m.completed}):null,w=new Set(v?.downstreamTaskIDs??[]),k=function(e){return"number"==typeof e&&Number.isFinite(e)?e:31}(n.seed),A=function(e,t,i){let r="string"==typeof i?i:"Tasks are arranged by workstream and dependency depth. Completed tasks deliver their authored prerequisites; task completion remains an explicit data event.",n=[...t.blockers.keys()].map(i=>{let r=yu(e,i,{completedTaskIDs:t.completed});return`${e.byID.get(i)?.label??i} affects ${r.downstreamTaskCount} unfinished tasks across ${r.affectedLaneCount} lanes.`}).join(" ");return n?`${r} ${n}`:`${r} No explicit blockers are active.`}(c,m,r.description),M=ru.renderToStaticMarkup(xu(au,{machine:c,layout:g,runtime:m,downstreamSet:w,selectedSet:x,width:a,height:s,seed:k,reduced:!0,onSelectTask:()=>{}})),$=void 0===r.theme?{}:S(u),_=ru.renderToStaticMarkup(bu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${p} ${f}`,style:{...$,fontFamily:d.fontFamily},children:[xu("title",{id:p,children:l}),xu("desc",{id:f,children:A}),xu("rect",{width:a,height:s,fill:d.background}),xu("text",{x:a/2,y:22,textAnchor:"middle",fontSize:d.titleFontSize,fontFamily:d.titleFontFamily,fontWeight:d.titleFontWeight,fill:d.text,children:l}),xu("g",{dangerouslySetInnerHTML:{__html:M}})]}));return t&&(t.evidence=ga({frameType:"physics",width:a,height:s,parts:[],additionalMarkCountByType:{task:c.nodes.length,dependency:c.edges.length},title:l,description:A,categories:c.lanes,nodeCount:c.nodes.length,edgeCount:c.edges.length})),_}},Gu={LineChart:Kr,BumpChart:Yr,AreaChart:Jr,DifferenceChart:en,StackedAreaChart:tn,Scatterplot:Ki,BubbleChart:Ji,Heatmap:sn,QuadrantChart:nn,MultiAxisLineChart:Vr,WaterfallChart:Hr,CandlestickChart:rn,ConnectedScatterplot:on,ScatterplotMatrix:{frameType:"xy",buildProps:ju,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=$u(e),s=function(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}(i),l=Array.isArray(a.fields)?a.fields.filter(e=>"string"==typeof e):[],c=a.fieldLabels&&"object"==typeof a.fieldLabels?a.fieldLabels:{},u=Wu(a.cellSize,150),d=Math.max(0,_u(a.cellGap,4)),h=Math.max(0,_u(a.pointRadius,2)),p=Math.max(0,Math.min(1,_u(a.pointOpacity,.5))),f=Wu(a.histogramBins,20),g="string"==typeof a.diagonal?a.diagonal:"histogram",m=40+l.length*u+l.length*d,y=l.length*u+40+l.length*d,x=Pi(o.theme),b=Ii(x),v=function(e,t,i,r){if(!t)return{categories:[],color:()=>Kt};let n=Array.from(new Set(e.map(e=>qu(e,t)))),o="string"==typeof t?t:"__semioticSplomColor",a=ni("function"==typeof t?e.map(e=>({...e,[o]:qu(e,t)})):e,o,i??r.colors.categorical);return{categories:n,color:e=>ii(e,t,a)}}(s,r,n,x),w=a.showLegend??!!r,S=un(o.title)||void 0,k="string"==typeof o.description?o.description:`Scatterplot matrix comparing ${l.length} fields`,A=S?28:0,M=w?v.categories:[],$=0,_=0,P=M.map(e=>{let t=(e=>Math.max(72,30+7*e.length))(e);$>0&&$+t>m&&(_+=1,$=0);let i={label:e,x:$,y:24*_};return $+=t,i}),I=M.length?24*(_+1)+4:0,T=A+I,L=T+y,C=[],R=[],N=0;l.forEach((e,t)=>{l.forEach((i,n)=>{let l=40+d+n*(u+d),m=T+t*(u+d);if(t===n){let t=function(e){let{data:t,field:i,label:r,cellSize:n,bins:o,diagonal:a,colorBy:s,color:l,x:c,y:u}=e;if("label"===a)return{visibleBars:0,svg:hn.renderToStaticMarkup(Ou("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:Ou("text",{x:n/2,y:n/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333",children:r})}))};let d=t.map(e=>Number(e[i])).filter(Number.isFinite),[h,p]=d.length?ue(d):[0,0],f=(p-h)/o||1,g=Array.from({length:o},()=>new Map);for(let e of t){let t=Number(e[i]);if(!Number.isFinite(t))continue;let r=Math.max(0,Math.min(o-1,Math.floor((t-h)/f))),n=s?qu(e,s):"__all",a=g[r];a.set(n,[...a.get(n)??[],e])}let m=g.map(e=>Array.from(e.values()).reduce((e,t)=>e+t.length,0)),y=he(m,1),x=0,b=g.flatMap((e,t)=>{let i=0;return Array.from(e.entries()).flatMap(([e,r])=>{if(0===r.length)return[];x+=1;let a=r.length/y*(n-24),c=i;return i+=a,Ou("rect",{x:t/o*n,y:n-c-a,width:Math.max(n/o-1,1),height:a,fill:s?l(r[0]):Kt,opacity:.6},`${t}-${e}`)})});return{visibleBars:x,svg:hn.renderToStaticMarkup(zu("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:[Ou("text",{x:n/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:r}),b]}))}}({data:s,field:e,label:ri(c,e)??e,cellSize:u,bins:f,diagonal:g,colorBy:r,color:v.color,x:l,y:m});return N+=t.visibleBars,void R.push(t.svg)}let y={},x=iu({chartType:"scatter",data:s,size:[u,u],xAccessor:i,yAccessor:e,pointStyle:le(e=>({r:h,opacity:p,fill:v.color(e)}),a.styleRules,oe(i,e)),margin:Bu,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${ri(c,i)??i} versus ${ri(c,e)??e} scatterplot`,theme:o.theme,_idPrefix:`${String(o._idPrefix??"splom")}-${t}-${n}`},y);C.push(y.evidence),R.push(Pu(x,l,m,`cell-${e}-${i}`))})});let D=Lc(o),F=S?`${D}-title`:void 0,E=`${D}-description`,O=hn.renderToStaticMarkup(zu("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:m,height:L,role:"img","aria-labelledby":[F,E].filter(Boolean).join(" "),style:{fontFamily:b.fontFamily},children:[S&&Ou("title",{id:F,children:S}),Ou("desc",{id:E,children:k}),Ou("rect",{width:m,height:L,fill:b.background}),S&&Ou("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:b.text,children:S}),P.map(e=>{let t=s.find(t=>r&&qu(t,r)===e.label),i=t?v.color(t):Kt;return zu("g",{transform:`translate(${e.x},${A+e.y})`,children:[Ou("circle",{cx:5,cy:8,r:5,fill:i}),Ou("text",{x:14,y:12,fontSize:11,fill:b.text,children:e.label})]},e.label)}),l.map((e,t)=>{let i=T+t*(u+d)+u/2;return Ou("text",{x:20,y:i,transform:`rotate(-90 20 ${i})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:ri(c,e)??e},`row-${e}`)}),l.map((e,t)=>Ou("text",{x:40+d+t*(u+d)+u/2,y:T+l.length*(u+d)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:ri(c,e)??e},`column-${e}`)),Ou("g",{dangerouslySetInnerHTML:{__html:R.join("")}})]}));return t&&(t.evidence=ga({frameType:"xy",width:m,height:L,parts:C,additionalMarkCountByType:N>0?{histogram:N}:void 0,title:S,description:k,categories:v.categories.length?v.categories:void 0,legendItems:M.length||void 0})),O}},MinimapChart:Yu},Vu=class e{constructor(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}push(e){if(!Number.isFinite(e))return;this._count+=1;let t=e-this._mean;this._mean+=t/this._count;let i=e-this._mean;this._m2+=t*i,e<this._min&&(this._min=e),e>this._max&&(this._max=e)}merge(e){if(0===e._count)return;if(0===this._count)return this._count=e._count,this._mean=e._mean,this._m2=e._m2,this._min=e._min,void(this._max=e._max);let t=this._count+e._count,i=e._mean-this._mean;this._mean+=i*e._count/t,this._m2+=e._m2+i*i*this._count*e._count/t,this._count=t,e._min<this._min&&(this._min=e._min),e._max>this._max&&(this._max=e._max)}clear(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}clone(){let t=new e;return t.merge(this),t}get count(){return this._count}get mean(){return this._mean}get sum(){return this._mean*this._count}get variance(){return this._count<2?0:this._m2/this._count}get stddev(){return Math.sqrt(this.variance)}get sampleVariance(){return this._count<2?0:this._m2/(this._count-1)}get sampleStddev(){return Math.sqrt(this.sampleVariance)}get min(){return this._min}get max(){return this._max}},Hu=class e{constructor(e=10){let t=Math.max(4,Math.min(16,Math.floor(e)));this.p=t,this.m=1<<t,this.registers=new Uint8Array(this.m),this.alpha=.7213/(1+1.079/this.m),this.harmonicSum=this.m,this.zeros=this.m}add(e){let t=function(e){let t=v(e);return t^=t>>>16,t=Math.imul(t,2146121005),t^=t>>>15,t=Math.imul(t,2221713035),t^=t>>>16,t>>>0}(String(e)),i=t>>>32-this.p,r=Math.min(Math.clz32(t<<this.p),32-this.p)+1;this.updateRegister(i,r)}updateRegister(e,t){let i=this.registers[e];t<=i||(this.registers[e]=t,this.harmonicSum+=2**-t-2**-i,0===i&&this.zeros--)}merge(e){if(e.m===this.m)for(let t=0;t<this.m;t++)this.updateRegister(t,e.registers[t])}clone(){let t=new e(this.p);return t.registers.set(this.registers),t.harmonicSum=this.harmonicSum,t.zeros=this.zeros,t}count(){let e=this.alpha*this.m*this.m/this.harmonicSum;return e<=2.5*this.m&&this.zeros>0?Math.round(this.m*Math.log(this.m/this.zeros)):Math.round(e)}},Uu=class e{constructor(e=100){this.centroids=[],this.total=0,this.pending=0,this.compression=Math.max(20,e)}push(e){Number.isFinite(e)&&(this.centroids.push({mean:e,weight:1}),this.total+=1,this.pending++,this.pending>=2*this.compression&&this.compress())}merge(e){if(0===e.total)return;let t=0===this.total,i=e.centroids.length;for(let t=0;t<i;t++)this.centroids.push({...e.centroids[t]});this.total+=e.total,this.pending=t&&this.compression===e.compression?e.pending:this.pending+i,t||this.compress()}clone(){let t=new e(this.compression);return t.merge(this),t}quantile(e){if(0===this.total||Number.isNaN(e))return Number.NaN;let t=Math.min(1,Math.max(0,e));this.compress();let i=t*this.total,r=this.centroids[0].weight/2;if(i<=r)return this.centroids[0].mean;for(let e=1;e<this.centroids.length;e++){let t=this.centroids[e-1],n=this.centroids[e],o=(t.weight+n.weight)/2,a=r+o;if(i<=a){let e=(i-r)/o;return t.mean+(n.mean-t.mean)*e}r=a}return this.centroids[this.centroids.length-1].mean}get count(){return this.total}compress(){if(0===this.pending||(this.pending=0,this.centroids.length<=1))return;this.centroids.sort((e,t)=>e.mean-t.mean);let e=0,t=0,i=this.total,r=this.compression;for(let n=1;n<this.centroids.length;n++){let o=this.centroids[e],a=this.centroids[n],s=(t+o.weight/2)/i,l=4*i*s*(1-s)/r;if(o.weight+a.weight<=Math.max(1,l)){let e=o.weight+a.weight;o.mean=(o.mean*o.weight+a.mean*a.weight)/e,o.weight=e}else t+=o.weight,this.centroids[++e]=a}this.centroids.length=e+1}};function Zu(e){let t=Math.round(1e3*e)/10;return`p${String(t).replace(".","_")}`}function Ku(e,t){let i=e[0],r=e.pop();if(e.length>0){let i=0;for(;2*i+1<e.length;){let n=2*i+1;if(n+1<e.length&&t(e[n+1],e[n])<0&&n++,t(r,e[n])<=0)break;e[i]=e[n],i=n}e[i]=r}return i}var Qu=(e,t)=>e-t,Ju=class{constructor(e,t){this.stats=new Vu,this.digest=e?new Uu:null,this.hll=t?new Hu:null}push(e,t){this.stats.push(e),this.digest?.push(e),this.hll&&this.hll.add(t??e)}merge(e){this.stats.merge(e.stats),this.digest?.merge(e.digest),this.hll?.merge(e.hll)}},ed=class{constructor(e){this.windows=new Map,this.starts=[],this.sessions=[],this.latest=-1/0,this.type=e.window??"tumbling",this.size=e.size;let t=e.hop??e.size;this.hop=t>0&&t<=e.size?t:e.size,this.gap=e.gap??e.size,this.retain=null!=e.retain&&e.retain>0?e.retain:1/0,this.percentiles=e.percentiles??[],this.wantDistinct=!0===e.distinct}newBucket(){return new Ju(this.percentiles.length>0,this.wantDistinct)}push(e,t,i){!Number.isFinite(e)||!Number.isFinite(t)||(e>this.latest&&(this.latest=e),"session"===this.type?this.pushSession(e,t,i):this.pushFixed(e,t,i),this.prune())}pushFixed(e,t,i){if("tumbling"===this.type||this.hop>=this.size){let r=Math.floor(e/this.size)*this.size;return void this.bump(r,t,i)}let r=this.hop,n=Math.floor(e/r);for(let o=Math.floor((e-this.size)/r)+1;o<=n;o++)this.bump(o*r,t,i)}bump(e,t,i){let r=this.windows.get(e);if(!r){if(this.windows.size>=this.retain&&e<this.starts[0])return;r=this.newBucket(),this.windows.set(e,r),this.retain!==1/0&&function(e,t,i){let r=e.length;for(e.push(t);r>0;){let n=r-1>>>1;if(i(e[n],t)<=0)break;e[r]=e[n],r=n}e[r]=t}(this.starts,e,Qu)}r.push(t,i)}pushSession(e,t,i){let r=e-this.gap,n=e+this.gap,o=0,a=this.sessions.length,s=this.sessions[a-1];if(!s||e>=s.end)o=a,s&&s.end>=r&&s.start<=n&&o--;else for(;o<a;){let e=o+a>>>1;this.sessions[e].end<r?o=e+1:a=e}let l=this.sessions[o];if(!l||l.start>n){let r=this.newBucket();return r.push(t,i),void this.sessions.splice(o,0,{start:e,end:e,bucket:r})}l.bucket.push(t,i),l.start=Math.min(l.start,e),l.end=Math.max(l.end,e);let c=o+1;for(;c<this.sessions.length&&this.sessions[c].start<=n;){let e=this.sessions[c++];l.bucket.merge(e.bucket),l.end=Math.max(l.end,e.end)}c>o+1&&this.sessions.splice(o+1,c-o-1)}prune(){if(this.retain!==1/0){if("session"===this.type)return void(this.sessions.length>this.retain&&this.sessions.splice(0,this.sessions.length-this.retain));for(;this.windows.size>this.retain;)this.windows.delete(Ku(this.starts,Qu))}}emit(){if("session"===this.type)return this.sessions.map(e=>{let t=this.latest-e.end<this.gap;return this.row(e.start,e.end,e.bucket,t)});let e=[];for(let[t,i]of this.windows){let r=t+this.size;e.push(this.row(t,r,i,this.latest<r))}return e.sort((e,t)=>e.start-t.start),e}row(e,t,i,r){let n=i.stats,o={start:e,end:t,count:n.count,mean:n.mean,sum:n.sum,min:n.min,max:n.max,stddev:n.stddev,partial:r};if(i.digest){let e={};for(let t of this.percentiles)e[Zu(t)]=i.digest.quantile(t);o.percentiles=e}return i.hll&&(o.distinct=i.hll.count()),o}get windowCount(){return"session"===this.type?this.sessions.length:this.windows.size}get watermark(){return this.latest}clear(){this.windows.clear(),this.starts=[],this.sessions=[],this.latest=-1/0}};function td(e,t){switch(t){case"distinct":return e.distinct??0;case"p50":case"p95":case"p99":return e.percentiles?.[t]??Number.NaN;default:return e[t]??e.mean}}var id={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},rd=/(\d+(?:\.\d+)?)(ms|s|m|h|d)/g;function nd(e){if("number"==typeof e)return Number.isFinite(e)&&e>0?e:null;if("string"!=typeof e)return null;let t=e.trim();if(""===t)return null;rd.lastIndex=0;let i,r=0,n=0;for(;null!==(i=rd.exec(t));){let e=parseFloat(i[1]),t=id[i[2]];if(null==t||!Number.isFinite(e))return null;r+=e*t,n+=i[0].length}return n!==t.length?null:r>0?r:null}var od="time",ad="value",sd="__aggLower",ld="__aggUpper",cd="__aggPartial",ud="count",dd="__aggStart",hd="__aggEnd";function pd(e,t){let i=t.stat??"mean",r=t.band??"none",n=t.sigma??1;return e.emit().map(e=>{let t={[od]:(e.start+e.end)/2,[ad]:td(e,i),[ud]:e.count,[cd]:e.partial,[dd]:e.start,[hd]:e.end},o=function(e,t,i,r=1){if("none"===t)return null;if("minmax"===t)return[e.min,e.max];let n=td(e,i),o=e.stddev*r;return[n-o,n+o]}(e,r,i,n);return o&&(t[sd]=o[0],t[ld]=o[1]),t})}function fd(e){return"none"!==(e.band??"none")}var gd="__aggSeries",md=class{constructor(e,t){this.config=e,this.seriesAccessor=t,this.groups=new Map}push(e,t,i){let r=At(e,t,"time"),n=kt(e,i,"value");if(null==r||null==n)return;let o=null==this.seriesAccessor?"":String("function"==typeof this.seriesAccessor?this.seriesAccessor(e):e[this.seriesAccessor]),a=this.groups.get(o);if(!a){if(a=function(e){let t=e.window??"tumbling",i=nd("session"===t?e.gap??e.size:e.size);if(null==i)return null;let r=null!=e.hop?nd(e.hop):void 0,n=null!=e.gap?nd(e.gap):void 0;return new ed({window:t,size:i,hop:r??void 0,gap:n??void 0,retain:e.retain,percentiles:e.percentiles,distinct:e.distinct})}(this.config),!a)return;this.groups.set(o,a)}a.push(+r,n)}emit(e){let t=[];for(let[i,r]of this.groups)for(let n of pd(r,e))t.push(null==this.seriesAccessor?n:{...n,[gd]:i});return t}clear(){this.groups.clear()}};function yd(e,t,i){return e??i??Math.max(t?.length??0,200)}function xd(e){let t=e.timeAccessor||"time",i=e.valueAccessor||"value";return{timeAccessor:e=>At(e,t,"time")??NaN,valueAccessor:e=>kt(e,i,"value")??NaN}}function bd(e,t,i){return{runtimeMode:"streaming",windowMode:i.windowMode??i.capacityMode??"sliding",windowSize:yd(i.windowSize,e,i.capacity),arrowOfTime:i.arrowOfTime??"right",...xd(i),xExtent:i.timeExtent??t.xExtent,yExtent:i.valueExtent??t.yExtent,extentPadding:i.extentPadding??t.extentPadding,tickFormatTime:i.tickFormatTime,tickFormatValue:i.tickFormatValue}}var vd={RealtimeLineChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=function(e,t){let i=Array.isArray(e)?_t(e):[],r=t.aggregate;if(!r)return i;let n=new md(r,t.seriesAccessor);for(let e of i)n.push(e,t.timeAccessor,t.valueAccessor);return n.emit(r)}(e,n),a=n.aggregate,s=n.aggregate?{timeAccessor:"time",valueAccessor:"value"}:xd(n),l=le(()=>({stroke:"#007bff",strokeWidth:2}),n.styleRules,oe(s.timeAccessor,s.valueAccessor));return{chartType:"line",data:o,...r,...bd(o,r,n),...s,groupAccessor:a&&null!=n.seriesAccessor?gd:n.seriesAccessor,...a&&{windowMode:"growing",windowSize:Math.max(1,a.retain??Math.max(o.length,600)),band:fd(a)?{y0Accessor:sd,y1Accessor:ld,perSeries:null!=n.seriesAccessor}:void 0},lineStyle:r.lineStyle||(e=>({...l(e),...wi(n),...null!=n.strokeDasharray&&{strokeDasharray:n.strokeDasharray},...null!=n.cursor&&{cursor:n.cursor}}))}}},RealtimeHistogram:/*#__PURE__*/Object.assign({},Qr,{buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?_t(e):[];return{...Qr.buildProps(o,t,i,r,n),...bd(o,r,n)}}}),TemporalHistogram:Qr,RealtimeSwarmChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?_t(e):[],a=Qi(o,r,n,"discovery"),s=le(void 0,n.styleRules,oe(n.timeAccessor??"time",n.valueAccessor??"value"));return{chartType:"swarm",data:o,...r,...bd(o,r,n),categoryAccessor:n.categoryAccessor,colorScheme:a||i||r.colorScheme,barColors:a,yScaleType:n.yScaleType,swarmStyle:{...wi(n),fill:n.fill,radius:n.radius,cursor:n.cursor},pointStyle:e=>({...s(e),..."function"==typeof n.pointStyle?n.pointStyle(e):{},..."function"==typeof r.pointStyle?r.pointStyle(e):r.pointStyle})}}},RealtimeWaterfallChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?_t(e):[],a=Hr.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value"});return{...a,...bd(o,r,n),waterfallStyle:{...a.waterfallStyle,cursor:n.cursor}}}},RealtimeHeatmap:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?_t(e):[];return{...sn.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value",heatmapAggregation:n.aggregation??"count",cellBorderWidth:0}),...bd(o,r,n),categoryAccessor:n.categoryAccessor}}}};import{useMemo as wd,useCallback as Sd,useRef as kd}from"react";var Ad={RdBu:Wt,PiYG:Yt,PRGn:qt,BrBG:Xt,RdYlBu:Gt,RdYlGn:Vt,Spectral:Ht},Md="__likert_neutral_neg",$d="__likert_neutral_pos";function _d(e,t){if("function"==typeof e)return e;let i=e||t;return e=>e[i]}import{jsx as Pd,jsxs as Id}from"react/jsx-runtime";function Td({value:e,min:t,max:i,radius:r,innerRadius:n,showScaleLabels:o,label:a}){let s=function(e,t,i){let r=Math.max(16,.3*t);if(null==i||i<=0)return r;let n=Ts(e,r),o=2*i*.8;return n<=o?r:r*o/n}(e,r,n),l=.7*s+11;return Id("g",{textAnchor:"middle",children:[Pd("text",{y:0,dominantBaseline:"central",fontSize:s,fontWeight:700,fill:"var(--semiotic-text, #333)",children:e}),o&&Id("text",{y:l,fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:[t," – ",i]}),null!=a&&""!==a&&Pd("text",{y:l+(o?14:0),fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:a})]})}function Ld(e){return Math.max(0,Math.min(1,e))}function Cd(e){let t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let i=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i){let e=[Number(i[1]),Number(i[2]),Number(i[3])];if(e.every(Number.isFinite))return e}return null}function Rd(e,t,i){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function Nd(e,t,i){let r=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:Ld(e.offset),color:e.color??i,opacity:null==e.opacity?1:Ld(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===r.length)return"#999999";let n=e=>{if(1===e.opacity)return e.color;let t=Cd(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===r.length)return n(r[0]);let o=Ld(t);if(o<=r[0].offset)return n(r[0]);if(o>=r[r.length-1].offset)return n(r[r.length-1]);for(let e=0;e<r.length-1;e++){let t=r[e],i=r[e+1];if(o<t.offset||o>i.offset)continue;let a=i.offset-t.offset,s=a<=0?0:(o-t.offset)/a,l=Cd(t.color),c=Cd(i.color);if(!l||!c)return n(s<.5?t:i);let[u,d,h]=l,[p,f,g]=c,m=u+(p-u)*s,y=d+(f-d)*s,x=h+(g-h)*s,b=t.opacity+(i.opacity-t.opacity)*s;return 1===b?Rd(m,y,x):`rgba(${Math.round(m)},${Math.round(y)},${Math.round(x)},${b})`}return n(r[r.length-1])}function Dd(e,t,i){return null==i?`${e}-${t}`:`${e}-${t}-${i}`}function Fd(e=240){let t=e*Math.PI/180,i=360-e,r=180+i/2,n=r*Math.PI/180;return{sweepRad:t,gapDeg:i,startAngleDeg:r,startAngleRad:n,offsetRad:-Math.PI/2+n}}import{Fragment as Ed,jsx as Od,jsxs as zd}from"react/jsx-runtime";function Bd(e){return gi(e)}function jd(e,t,i,r,n,o){let a=Pi(r.theme).colors.categorical,s=i??r.colorScheme,l=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",u="function"==typeof t?l.map(e=>({...e,__ssrColorBy:t(e)})):l,d=t?ni(u,c,s??a):void 0,h=ai("string"==typeof n.color?n.color:void 0,a,s,void 0,new Map),p=o??ne(n.valueAccessor??"value"),f=n.styleRules,g=r.pieceStyle;return(e,i)=>{let r={fill:t&&d?ii(e,t,d):h};return f?.length&&Object.assign(r,se(e,f,{value:p(e,i),category:i})),"function"==typeof g?Object.assign(r,g(e,i)||{}):g&&"object"==typeof g&&Object.assign(r,g),void 0!==n.stroke&&(r.stroke=n.stroke),void 0!==n.strokeWidth&&(r.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(r.opacity=n.opacity),r}}function Wd(e,t,i,r,n,o="median",a=.8){let s=ne(n.valueAccessor??"value"),l=jd(e,t,i,r,n,e=>"number"==typeof e[o]?e[o]:s(e));return(e,t)=>{let i=l(e,t);return void 0===i.fillOpacity&&(i.fillOpacity=a),void 0===i.stroke&&(i.stroke=i.fill),i}}function Yd(e,t,i,r,n){return Wd(e,t,i,r,n,"median",.6)}function qd(e,t,i,r,n){let o=jd(e,t,i,r,n),a="number"==typeof n.dotRadius?n.dotRadius:5;return(e,t)=>({r:a,fillOpacity:.8,...o(e,t)})}function Xd(e,t,i,r,n){let o=jd(e,t,i,r,n),a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=n.sizeBy,l=Array.isArray(n.sizeRange)?n.sizeRange:[3,8],c=s?a.map(e=>"function"==typeof s?s(e):Number(e[s])).filter(Number.isFinite):[],u=c.length?ue(c):void 0,d="number"==typeof n.pointRadius?n.pointRadius:4,h="number"==typeof n.pointOpacity?n.pointOpacity:.7;return(e,t)=>({r:s?oi(e,s,l,u):d,fillOpacity:h,...o(e,t)})}var Gd={BarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=Si(r.annotations,n.regression);return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,colorAccessor:t,colorScheme:i,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,...o&&{annotations:o},gradientFill:Bd(r.gradientFill),pieceStyle:jd(e,t,i,r,n)}}},StackedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.stackBy;return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Bd(r.gradientFill),pieceStyle:jd(e,o,i,r,n),showLegend:r.showLegend??!!o}}},GroupedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.groupBy;return{chartType:"clusterbar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Bd(r.gradientFill),pieceStyle:jd(e,o,i,r,n),showLegend:r.showLegend??!!o}}},SwarmPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"swarm",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},barPadding:n.categoryPadding??20,colorAccessor:t,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,sizeRange:n.sizeRange||[3,8],pieceStyle:Xd(e,t,i,r,n),showLegend:r.showLegend??!!t})},BoxPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"boxplot",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},colorAccessor:t,colorScheme:i,...null!=n.showOutliers&&{showOutliers:n.showOutliers},...null!=n.outlierRadius&&{outlierRadius:n.outlierRadius},...r,summaryStyle:Wd(e,t,i,r,n)})},Histogram:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.valueAccessor||"value",s=o.map(e=>Number("function"==typeof a?a(e):e[a])).filter(Number.isFinite),l=s.length?ue(s):void 0;return{chartType:"histogram",data:e,oAccessor:n.categoryAccessor||(e=>null==e.category?"All":String(e.category)),rAccessor:a,projection:"horizontal",bins:n.bins??25,normalize:n.relative??!1,colorAccessor:t,colorScheme:i,barPadding:n.categoryPadding??20,...n.valueExtent?{rExtent:n.valueExtent}:l?{rExtent:l}:{},...r,summaryStyle:Wd(e,t,i,r,n,"count")}}},ViolinPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"violin",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===n.orientation?"horizontal":"vertical",bins:n.bins??25,showIQR:n.showIQR??!0,barPadding:n.categoryPadding??20,colorScheme:i,...r,summaryStyle:Yd(e,t,i,r,n),showLegend:r.showLegend??!!t,...n.valueExtent&&{rExtent:n.valueExtent}})},RidgelinePlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"ridgeline",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},bins:n.bins??20,amplitude:n.amplitude??1.5,barPadding:n.categoryPadding??5,oSort:n.oSort??!1,...r,summaryStyle:Wd(e,t,i,r,n,"median",.5),showLegend:r.showLegend??!!t})},DotPlot:{frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,i,r,n)=>{let o=Si(r.annotations,n.regression);return{chartType:"point",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??"auto",barPadding:n.categoryPadding??10,...r,...o&&{annotations:o},pieceStyle:qd(e,t,i,r,n),showGrid:r.showGrid??!0,showLegend:r.showLegend??!!t}}},PieChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=ne(n.valueAccessor??"value");return{chartType:"pie",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:jd(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)}),showLegend:r.showLegend??!!o}}},DonutChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=ne(n.valueAccessor??"value");return{chartType:"donut",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",margin:r.margin??{top:50,right:40,bottom:60,left:70},innerRadius:n.innerRadius??60,colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:jd(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)})}}},GaugeChart:{frameType:"ordinal",renderOverlay:function(e,{theme:t}){let i=e.__gauge;if(!i)return null;let r=Math.max(i.gMin,Math.min(i.gMax,i.value??i.gMin)),n=i.gMax===i.gMin?0:(r-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.needleColor||t.colors.text,s=i.showScaleLabels?(i.thresholds||[]).filter(e=>e.value>i.gMin&&e.value<i.gMax):[];return zd(Ed,{children:[i.showNeedle&&zd(Ed,{children:[Od("line",{x1:i.centerX,y1:i.centerY,x2:i.centerX+i.needleLength*Math.cos(o),y2:i.centerY+i.needleLength*Math.sin(o),stroke:a,strokeWidth:2.5,strokeLinecap:"round"}),Od("circle",{cx:i.centerX,cy:i.centerY,r:4,fill:a})]}),null!=i.contextValue&&Od("text",{x:i.centerX,y:i.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:i.valueFontSize,fontWeight:700,fill:a,children:i.contextValue}),s.map((e,r)=>{let n=i.gMax===i.gMin?0:(e.value-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.innerRadius-1,s=i.radius+1,l=i.radius+10,c=((o+Math.PI/2)/(2*Math.PI)*12+12)%12,u=c>=11||c<1?"middle":c<5?"start":c<7?"middle":"end",d=c>=11||c<1?"auto":c<5?"middle":c<7?"hanging":"middle";return zd("g",{children:[Od("line",{x1:i.centerX+Math.cos(o)*a,y1:i.centerY+Math.sin(o)*a,x2:i.centerX+Math.cos(o)*s,y2:i.centerY+Math.sin(o)*s,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),Od("text",{x:i.centerX+Math.cos(o)*l,y:i.centerY+Math.sin(o)*l,textAnchor:u,dominantBaseline:d,fill:t.colors.textSecondary,fontSize:10,children:e.label||String(e.value)})]},`gauge-label-${r}`)})]})},buildProps:(e,t,i,r,n)=>{let o=n.min??0,a=n.max??100,s=n.sweep??240,l=n.arcWidth??.3,c=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:d}=Fd(s),h=r.__resolvedMode??n.mode,p="context"===h||"sparkline"===h,f=n.showScaleLabels??!p,g=n.thresholds,m=mi(r.gradientFill),y=function(e){let{min:t,max:i,value:r,thresholds:n,fillColor:o,backgroundColor:a,fillZones:s,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=e,d=Math.max(t,Math.min(i,r)),h=i-t||1,p=(d-t)/h,f=n&&n.length>0?[...n].sort((e,t)=>e.value-t.value):[{value:i,color:o||"#007bff"}];f=f.map(e=>({...e,value:Math.max(t,Math.min(i,e.value))})),f[f.length-1].value<i&&f.push({value:i,color:f[f.length-1].color});let g=!!c&&c.stops.length>=2,m=[],y=new Map,x=[];if(g){let e=s?p:1,t=Dd("bg",0);if(m.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(t,{fill:a,opacity:.4}),e>0){let t=Math.max(1,Math.floor(u)),i=Math.max(1,Math.min(t,Math.round(e*t))),r=[];for(let t=0;t<i;t++){let n=e*(t+.5)/i;r.push(Nd(c.stops,n,o||f[0]?.color||"#007bff"))}let n=Dd("fill",0);m.push({category:n,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:r}}),y.set(n,{fill:r[0]||a})}}else{let e=t;for(let n=0;n<f.length;n++){let o=f[n],l=(o.value-e)/h,c=(e-t)/h,u=(o.value-t)/h,g=s?Math.min(p,u):u,x=Math.max(0,g-c),b=s?Math.max(0,l-x):0;if(x>0){let a=Dd("fill",n);m.push({category:a,value:x,_zone:o.label||`Zone ${n+1}`,_isFill:!0,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:e,segmentEnd:t+g*h,filled:!0}}),y.set(a,{fill:o.color})}if(b>0){let s=Dd("bg",n);m.push({category:s,value:b,_zone:o.label||`Zone ${n+1}`,_isFill:!1,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:Math.max(e,d),segmentEnd:o.value,filled:!1}}),y.set(s,{fill:a,opacity:.4})}e=o.value}}if(l&&n&&n.length>0)for(let e of n)e.value>t&&e.value<i&&x.push({type:"gauge-label",value:e.value,label:e.label||String(e.value)});return{gaugeData:m,pieceStyle:(e,t)=>{let i=t||e.category;return y.get(i)||{fill:a}},gaugeAnnotations:x}}({min:o,max:a,value:n.value,thresholds:g,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:f,gradientFill:m}),x=n.styleRules,[b,v]=r.size||[300,250],w=function(e=240){let{sweepRad:t,offsetRad:i}=Fd(e),r=[[Math.cos(i),Math.sin(i)],[Math.cos(i+t),Math.sin(i+t)],[0,0]];for(let e=0;e<2*Math.PI;e+=Math.PI/2)((e-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)<=t+.001&&r.push([Math.cos(e),Math.sin(e)]);let n=r.map(e=>e[0]),o=r.map(e=>e[1]),[a,s]=ue(n),[l,c]=ue(o);return{minX:a,maxX:s,minY:l,maxY:c,width:s-a,height:c-l,cx:(a+s)/2,cy:(l+c)/2}}(s),S=Math.min(10,Math.max(1,Math.min(b,v)/12)),k=Math.max(4,Math.min((b-2*S)/w.width,(v-2*S)/w.height)-2),A=Math.max(0,Math.min(k-1.5,k*(1-l))),M=b/2-w.cx*k,$=v/2-w.cy*k,_=2*(k+4),P=Math.max(o,Math.min(a,n.value??o)),I="function"==typeof n.valueFormat?n.valueFormat(P):String(Math.round(P)),T=n.centerContent??r.centerContent,L=function({centerContent:e,centerLabel:t,value:i,min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,valueFormat:l,compact:c}){if(null!=e){let s="function"==typeof e?e(i,r,n):e;return"string"==typeof s||"number"==typeof s?Td({value:String(s),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:!1,label:t}):s}return c?null:Td({value:l?l(i):String(Math.round(i)),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,label:t})}({centerContent:T,centerLabel:"string"==typeof n.centerLabel?n.centerLabel:void 0,value:P,min:o,max:a,radius:k,innerRadius:A,showScaleLabels:f,valueFormat:"function"==typeof n.valueFormat?n.valueFormat:void 0,compact:p});return{chartType:"donut",data:y.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:A,sweepAngle:s,startAngle:d,oSort:!1,pieceStyle:li((e,t)=>{let i={...y.pieceStyle(e,t)};return x?.length&&Object.assign(i,se(e,x,{value:"number"==typeof e.value?e.value:void 0,category:t??(null==e.category?void 0:String(e.category))})),i},wi(n)),...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...r,size:[b,v],margin:{top:$-_/2,bottom:v-$-_/2,left:M-_/2,right:b-M-_/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(r.annotations)?r.annotations:[],...y.gaugeAnnotations],__gauge:{gMin:o,gMax:a,sweep:s,arcWidth:l,value:P,startAngleDeg:d,thresholds:g,centerX:M,centerY:$,radius:k,innerRadius:A,showScaleLabels:f,needleLength:A>20?A-8:k-1,showNeedle:c,needleColor:n.needleColor,..."context"===h&&null==T&&{contextValue:I,contextValueY:$-.2*A,valueFontSize:Math.max(12,Math.min(22,.28*k))}}}}},FunnelChart:{frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="vertical"===n.orientation,a=t||n.categoryAccessor;return{chartType:o?"bar-funnel":"funnel",data:e,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:a,categoryAccessor:n.categoryAccessor,projection:o?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!o&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:o?40:0,colorScheme:i,...r,showAxes:o&&!1!==r.showAxes,showGrid:o,pieceStyle:jd(e,a,i,r,n),showLabels:n.showLabels??!0}}},RadarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=n.seriesAccessor||t||"__radar",a=t||("__radar"===o?void 0:o),s=qd(e,a,i,r,{...n,dotRadius:n.pointRadius??4});return{chartType:"point",projection:"radial",data:e,oAccessor:n.categoryAccessor||"attribute",rAccessor:n.valueAccessor||"value",colorAccessor:a,colorScheme:i,connectorAccessor:o,connectorStyle:e=>{let t=s(e),i="string"==typeof t.fill?t.fill:void 0;return{fill:i,fillOpacity:.15,stroke:i,strokeWidth:2,opacity:.7}},pieceStyle:s,rExtent:n.valueExtent||[0],oLabel:"",...r,...n.categoryFormat&&{oFormat:n.categoryFormat},showLegend:r.showLegend??!!a}}},SwimlaneChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:o,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...null!=n.trackFill&&{trackFill:n.trackFill},...n.valueExtent&&{rExtent:n.valueExtent},...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Bd(r.gradientFill),pieceStyle:jd(e,o,i,r,n),showLegend:r.showLegend??!!o,barPadding:n.barPadding??40}}},LikertChart:{frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.levels)&&n.levels.length>=2?n.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],a="vertical"!==n.orientation,s=function(e,t,i,r,n,o,a={}){let s=new Map,l=new Set(t);for(let a of e){let e=i(a);s.has(e)||s.set(e,new Map);let c=s.get(e);if(r){let e=r(a);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}let i=e-1;if(i<0||i>=t.length)continue;let n=t[i];c.set(n,(c.get(n)||0)+1)}else if(n&&o){let e=n(a),t=o(a);if(!l.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}let c=[];for(let[e,i]of s){let r=0;for(let e of t)r+=i.get(e)||0;if(0!==r)for(let n=0;n<t.length;n++){let o=t[n],s=i.get(o)||0,l={};a.category&&(l[a.category]=e),a.level&&(l[a.level]=o),a.count&&(l[a.count]=s),a.score&&(l[a.score]=n+1),c.push({...l,__likertCategory:e,__likertLevel:o,__likertLevelLabel:o,__likertCount:s,__likertPct:s/r*100,__likertLevelIndex:n})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],o,_d(n.categoryAccessor,"question"),n.levelAccessor?null:_d(n.valueAccessor,"score"),n.levelAccessor?_d(n.levelAccessor,"level"):null,n.levelAccessor?_d(n.countAccessor,"count"):null,{category:"string"==typeof n.categoryAccessor?n.categoryAccessor:void 0,level:"string"==typeof n.levelAccessor?n.levelAccessor:void 0,count:"string"==typeof n.countAccessor?n.countAccessor:void 0,score:n.levelAccessor||"string"!=typeof n.valueAccessor?void 0:n.valueAccessor});a&&(s=function(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=new Map;for(let t of e){let e=o.get(t.__likertCategory)||[];e.push(t),o.set(t.__likertCategory,e)}let a=[];for(let[,e]of o){let t,o,s=new Map;for(let i of e)i.__likertLevel===Md?t=i:i.__likertLevel===$d?o=i:s.set(i.__likertLevelIndex,i);r&&t&&a.push(t);for(let e=n-1;e>=0;e--){let t=s.get(e);t&&a.push(t)}r&&o&&a.push(o);for(let e=r?n+1:n;e<i;e++){let t=s.get(e);t&&a.push(t)}}return a}(function(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=[];for(let t of e){let e=t.__likertLevelIndex;if(r&&e===n){let e=t.__likertPct/2;o.push({...t,__likertLevel:Md,__likertPct:-e}),o.push({...t,__likertLevel:$d,__likertPct:e})}else e<n?o.push({...t,__likertPct:-t.__likertPct}):o.push(t)}return o}(s,o),o));let l=Pi(r.theme).colors.diverging,c=Array.isArray(i)&&i.length>=o.length?i:function(e,t){if(e<=0)return[];if(t&&Object.prototype.hasOwnProperty.call(Ad,t)){let i=Ad[t];if(1===e)return[i(.5)];let r=[];for(let t=0;t<e;t++)r.push(i(t/(e-1)));return r}let i=["#da1e28","#ff8389","#ffb3b8"],r=["#a6c8ff","#4589ff","#0043ce"],n="#a8a8a8";if(1===e)return[n];let o=e%2!=0,a=Math.floor(e/2),s=[];for(let e=0;e<a;e++)s.push(i[Math.min(Math.floor(e*i.length/a),i.length-1)]);o&&s.push(n);for(let e=0;e<a;e++)s.push(r[Math.min(Math.floor(e*r.length/a),r.length-1)]);return s}(o.length,l),u=new Map(o.map((e,t)=>[e,c[t]||"#888"])),d=o.length%2&&u.get(o[Math.floor(o.length/2)])||"#888",h="function"==typeof n.valueFormat?n.valueFormat:e=>`${Math.abs(Number(e)).toFixed(0)}%`,p=ge(!1===r.showLegend?void 0:{legendGroups:[{label:"",items:o.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},r.legend),f=n.styleRules,g=r.pieceStyle;return{chartType:"bar",data:s,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:a?"horizontal":"vertical",barPadding:n.barPadding,showGrid:r.showGrid,oLabel:n.categoryLabel,rLabel:n.valueLabel||(a?void 0:"Percentage"),rFormat:h,...n.categoryFormat&&{oFormat:n.categoryFormat},...n.valueExtent&&{rExtent:n.valueExtent},...r,pieceStyle:li((e,t)=>{let i=e.__likertLevel||e.data?.__likertLevel,r=e.__likertLevelLabel||e.data?.__likertLevelLabel,n=e.__likertPct??e.data?.__likertPct,o={fill:i===Md||i===$d?d:u.get(String(r||i))||"#888"};return f?.length&&Object.assign(o,se(e,f,{value:"number"==typeof n?n:void 0,category:t??(null==r?void 0:String(r))})),"function"==typeof g?Object.assign(o,g(e,t)||{}):g&&"object"==typeof g&&Object.assign(o,g),o},wi(n)),showLegend:r.showLegend??!0,legendPosition:r.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}}};import{interpolateRgb as Vd}from"d3-interpolate";var Hd=e=>{let t=e.config,{plot:i}=e.dimensions;if(i.width<=0||i.height<=0)return{nodes:[]};let r="utc"===t.timeZone,n=(e,t,i)=>{let n=new Date(0);return r?(n.setUTCFullYear(e,t,i),n.setUTCHours(0,0,0,0)):(n.setFullYear(e,t,i),n.setHours(0,0,0,0)),n},o=e=>r?e.getUTCFullYear():e.getFullYear(),a=e=>`${o(e)}-${Ud(r?e.getUTCMonth()+1:e.getMonth()+1)}-${Ud(r?e.getUTCDate():e.getDate())}`,s=e=>{let i="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];if(i instanceof Date)return i;if("string"==typeof i&&/^\d{4}-\d{2}-\d{2}$/.test(i)){let[e,t,r]=i.split("-").map(Number);return n(e,t-1,r)}return new Date(i)},l=e=>{let i="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return null==i?NaN:Number(i)},c=new Map,u=null;for(let t of e.data){let e=s(t);if(!isFinite(e.getTime()))continue;null==u&&(u=o(e));let i=a(e),r=l(t);Number.isFinite(r)&&c.set(i,(c.get(i)??0)+r)}let d=t.year??u??o(new Date),h=1/0,p=-1/0;for(let[e,t]of c)e.startsWith(`${d}-`)&&(t<h&&(h=t),t>p&&(p=t));h===1/0&&(h=0,p=0);let[f,g]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],m=t.missingColor??e.theme.semantic.grid??"#d1d5db",y=e=>{if(p===h)return f;let t=(e-h)/(p-h);return Vd(f,g)(t)},x=t.gutter??2,b=t.labelInset??0,v=i.width-b,w=i.height,S=Math.min((v-53*x)/54,(w-6*x)/7);if(S<=0)return{nodes:[]};let k=n(d,0,1),A=((r?k.getUTCDay():k.getDay())-(t.weekStart??0)+7)%7,M=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let r=n(d,0,1-A+7*e+t);if(o(r)!==d)continue;let s=a(r),l=c.get(s),u=null==l?m:y(l);M.push({type:"rect",x:i.x+b+e*(S+x),y:i.y+t*(S+x),w:S,h:S,style:{fill:u,stroke:"none"},datum:{date:r,value:l??null,missing:null==l}})}return{nodes:M}};function Ud(e){return e<10?`0${e}`:String(e)}import{createElement as Zd,Fragment as Kd}from"react";import{scaleLinear as Qd}from"d3-scale";import{interpolateLab as Jd}from"d3-interpolate";function eh(e,t={}){let i=t.baseOpacity??1;return t.highlight||t.predicate?!function(e,t){if(!t)return!0;let i=Array.isArray(t)?t:[t],r=e;for(let e of i)if(null!=e.value&&String(r[e.field])!==String(e.value))return!1;return!0}(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,i+(t.brighten??0)):i}function th(e){if(0===e.length)return 0;let t=0;for(let i of e)t+=i;return t/e.length}import{jsx as ih,jsxs as rh}from"react/jsx-runtime";function nh(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:ih("text",{className:e.className,x:e.x,y:e.y,textAnchor:e.anchor??"middle",dominantBaseline:e.baseline??"middle",fontSize:t,fontWeight:e.fontWeight,fill:e.color,style:{pointerEvents:"none"},children:e.text},e.keyId)}var oh=e=>{let t=e.config,{plot:i}=e.dimensions,r=t.fields??[];if(r.length<2||i.width<=0||i.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let n=Object.create(null);for(let i of r){let r=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,i)?t.domains[i]:void 0;if(Array.isArray(r)&&r.length>=2&&"number"==typeof r[0]&&Number.isFinite(r[0])&&"number"==typeof r[1]&&Number.isFinite(r[1])){n[i]=[r[0],r[1]];continue}let o=1/0,a=-1/0;for(let t of e.data){let e=Number(t[i]);Number.isFinite(e)&&(e<o&&(o=e),e>a&&(a=e))}if(Number.isFinite(o)&&Number.isFinite(a))if(o===a){let e=Math.max(.01*Math.abs(o),.5);n[i]=[o-e,a+e]}else n[i]=[o,a];else n[i]=[0,1]}let o=!1!==t.showAxes,a=o?t.axisLabelPadding??24:8,s=o?18:8,l=r.map(e=>Qd().domain(n[e]).range([i.y+i.height-s,i.y+a])),c=r.map((e,t)=>1===r.length?i.x+i.width/2:i.x+t/(r.length-1)*i.width),u=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,d=t.opacity??.45,h=t.strokeWidth??1.25,p=e.theme.semantic.primary??"#3b6cb1",f=t.dimmedOpacity??.08,g=t.highlightFn,m=[],y=[];for(let i of e.data){let n=u?e.resolveColor(String(u(i))):p,o=!g||g(i),a=eh(i,{predicate:g,baseOpacity:d,dimOpacity:f,brighten:.4}),s=o?y:m;for(let e=0;e<r.length-1;e++){let t=Number(i[r[e]]),u=Number(i[r[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(u))continue;let d={type:"connector",x1:c[e],y1:l[e](t),x2:c[e+1],y2:l[e+1](u),style:{stroke:n,strokeWidth:g&&o?h+.75:h,opacity:a,fill:"none"},datum:i};s.push(d)}if(t.showPoints)for(let e=0;e<r.length;e++){let t=Number(i[r[e]]);if(!Number.isFinite(t))continue;let o={type:"point",x:c[e],y:l[e](t),r:2.5,style:{fill:n,stroke:"none",opacity:Math.min(1,a+.3)},datum:i};s.push(o)}}let x=null;if(o){let o=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,u=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,d=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=i.y+a,p=i.y+i.height-s,f=[];for(let e=0;e<r.length;e++){let s=r[e],g=c[e],m=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,s)?t.tickFormat[s]:void 0,y="function"==typeof m?m:e=>e.toLocaleString();f.push(Zd("line",{key:`pc-axis-line-${e}`,x1:g,x2:g,y1:h,y2:p,stroke:o,strokeWidth:1})),f.push(nh({keyId:`pc-axis-label-${e}`,text:s,x:g,y:i.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:u}));let[x,b]=n[s],v=5;for(let t=0;t<v;t++){let i=x+(b-x)*t/(v-1),r=l[e](i);f.push(Zd("line",{key:`pc-tick-${e}-${t}`,x1:g-3,x2:g+3,y1:r,y2:r,stroke:o,strokeWidth:1}),nh({keyId:`pc-ticktext-${e}-${t}`,text:y(i),x:g+6,y:r+3,anchor:"start",baseline:"auto",fontSize:10,color:d}))}}x=Zd(Kd,null,...f)}return{nodes:m.concat(y),overlays:x}},ah={frameType:"xy",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1,showLegend:r.showLegend??!!t})},sh={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1})},lh={frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,i,r,n)=>({chartType:"force",nodes:n.nodes||e||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:t,colorScheme:i,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...r})},ch={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({...sh.buildProps(e,t,i,r,n),customLayout:oh,showAxes:!1})},uh={frameType:"xy",buildProps:(e,t,i,r,n)=>({...ah.buildProps(e,t,i,r,n),customLayout:Hd,showAxes:!1})},dh={annotationBackground:"rgba(248, 250, 252, 0.94)",annotationStroke:"#334155",annotationText:"#0f172a",background:"#f8fafc",border:"#334155",closedWindowFill:"rgba(220, 38, 38, 0.08)",closedWindowStroke:"rgba(220, 38, 38, 0.55)",danger:"#dc2626",focus:"#f97316",grid:"#cbd5e1",gutterFill:"rgba(71, 85, 105, 0.14)",lateFill:"#f97316",openWindowFill:"rgba(14, 165, 233, 0.07)",openWindowStroke:"rgba(14, 165, 233, 0.3)",primary:"#0ea5e9",selectedFill:"#f97316",selectedStroke:"#7c2d12",success:"#22c55e",text:"#0f172a",textSecondary:"#475569",warning:"#f97316"},hh={background:{names:["--semiotic-bg","--surface-1","--surface-0"],fallback:dh.background},border:{names:["--semiotic-border","--surface-3"],fallback:dh.border},danger:{names:["--semiotic-danger","--viz-4"],fallback:dh.danger},focus:{names:["--semiotic-focus","--accent","--viz-9"],fallback:dh.focus},grid:{names:["--semiotic-grid","--surface-3"],fallback:dh.grid},primary:{names:["--semiotic-primary","--accent","--viz-5"],fallback:dh.primary},success:{names:["--semiotic-success","--viz-2"],fallback:dh.success},text:{names:["--semiotic-text","--text-primary"],fallback:dh.text},textSecondary:{names:["--semiotic-text-secondary","--text-secondary"],fallback:dh.textSecondary},warning:{names:["--semiotic-warning","--viz-9","--viz-3"],fallback:dh.warning}};function ph(e){let t=Object.fromEntries(Object.entries(e??{}).filter(([,e])=>null!=e).map(([e,t])=>[`--semiotic-physics-${e}`,t]));for(let i of Object.keys(hh))null!=e?.[i]&&(t[hh[i].names[0]]=e[i]);return t}var fh={annotationBackground:["background",.94],annotationStroke:["border"],annotationText:["text"],closedWindowFill:["danger",.08],closedWindowStroke:["danger",.55],gutterFill:["textSecondary",.14],lateFill:["warning"],openWindowFill:["primary",.07],openWindowStroke:["primary",.3],selectedFill:["warning"],selectedStroke:["focus"]};function gh(e){let t=hh[e],i=fh[e],r=dh[e];if(t)r=t.names.reduceRight((e,t)=>`var(${t}, ${e})`,t.fallback);else if(i){let e=gh(i[0]);r=null==i[1]?e:`color-mix(in srgb, ${e} ${100*i[1]}%, transparent)`}return`var(--semiotic-physics-${e}, ${r})`}import{jsx as mh,jsxs as yh}from"react/jsx-runtime";import*as xh from"react";import{jsx as bh,jsxs as vh}from"react/jsx-runtime";function wh(e,t,i,r="physics"){let n=function(e,t){let i=t.mark;if(i)return i;let r=e.datum,n=r?.__physicsMark??r?.mark;return"circle"===n||"halo"===n||"faceted"===n||"pill"===n||"diamond"===n||"square"===n||"triangle"===n||"hexagon"===n?n:"circle"===e.shape.type?"circle":"square"}(e,t),o="circle"===e.shape.type?t.r??e.shape.radius:Math.max(e.shape.width,e.shape.height)/2,a=function(e,t){return"function"==typeof t.glyph?t.glyph(e.datum&&"object"==typeof e.datum?e.datum:{}):t.glyph}(e,t);if(a)return qa({glyph:a,size:2*o,style:t,color:"string"==typeof t.fill?t.fill:void 0,accent:t.stroke},e.x,e.y,`physics-body-${i}`);let s=`${r}-body-${i}-hatch`,l=Aa(t.fill)?Ma(t.fill,s):void 0,c=e=>l?vh(xh.Fragment,{children:[bh("defs",{children:l}),e]},`physics-body-${i}`):xh.cloneElement(e,{key:`physics-body-${i}`}),u={fill:l?`url(#${s})`:Wa(t.fill),stroke:t.stroke,strokeWidth:t.strokeWidth,opacity:t.opacity,fillOpacity:t.fillOpacity,strokeDasharray:t.strokeDasharray};if("circle"!==n||t.r){if("pill"===n||"square"===n||"aabb"===e.shape.type){let t="pill"===n?2.4*o:"aabb"===e.shape.type?e.shape.width:1.7*o,i="pill"===n?1.35*o:"aabb"===e.shape.type?e.shape.height:1.7*o;return c(bh("rect",{x:e.x-t/2,y:e.y-i/2,width:t,height:i,rx:"pill"===n?i/2:Math.min(4,t/4),...u}))}if("triangle"===n||"hexagon"===n||"faceted"===n||"diamond"===n){let t=function(e,t,i,r){return Array.from({length:r},(n,o)=>{let a=2*Math.PI*o/r-Math.PI/2;return[e+Math.cos(a)*i,t+Math.sin(a)*i]})}(e.x,e.y,o,"triangle"===n?3:"diamond"===n?4:6);return c(bh("path",{d:`${t.map(([e,t],i)=>`${i?"L":"M"}${e},${t}`).join("")}Z`,...u}))}return c(vh("g",{children:[bh("circle",{cx:e.x,cy:e.y,r:o,...u}),"halo"===n&&(t.strokeWidth??0)>0&&bh("circle",{cx:e.x,cy:e.y,r:1.35*o,fill:"none",stroke:t.stroke??u.fill,strokeWidth:Math.max(1.5,t.strokeWidth??1.5),opacity:.55*(t.opacity??1)})]}))}}import{jsx as Sh,jsxs as kh}from"react/jsx-runtime";function Ah(e,t){let i=e?.find(e=>e.id===String(t));return i?{...i.color?{fill:i.color}:{},...i.mark?{mark:i.mark}:{},...i.glyph?{glyph:i.glyph}:{}}:{}}function Mh(e=[],t={},i){if("none"===t.side)return[];let r=e.filter(e=>!1!==e.visible),n=Math.max(48,t.tileSize??80),o=Math.max(1,r.length);return r.map((e,r)=>({source:e,x:"top"===t.side?(r+.5)*i[0]/o:"right"===t.side?i[0]-n/2:n/2,y:"top"===t.side?n/2+24:(r+.5)*i[1]/o}))}function $h(e,t,i,r){let n=Mh(e,t,i);return n.length?Sh("svg",{width:i[0],height:i[1],style:{position:"absolute",inset:0,pointerEvents:"none"},"data-testid":"event-drop-source-rail",children:n.map(({source:e,x:t,y:i},n)=>{let o={id:e.id,x:t,y:i-6,prevX:t,prevY:i-6,vx:0,vy:0,angle:0,mass:1,shape:{type:"circle",radius:12},sleeping:!0},a={fill:e.color??gh("primary"),mark:e.mark,glyph:e.glyph,r:12},s=`${e.label} ${!1===e.active?"off":"on"}`;return kh("g",{role:r?"button":"img",tabIndex:r?0:void 0,"aria-label":s,"aria-pressed":r?!1!==e.active:void 0,style:{pointerEvents:"auto",cursor:r?"pointer":void 0},onClick:()=>r?.(e),onKeyDown:t=>{r&&("Enter"===t.key||" "===t.key)&&(t.preventDefault(),r(e))},children:[Sh("title",{children:e.description??s}),Sh("rect",{x:t-24,y:i-30,width:48,height:54,rx:6,fill:gh("background"),stroke:gh("border")}),Sh("g",{opacity:!1===e.active?.35:1,children:wh(o,a,n)}),Sh("text",{x:t,y:i+18,textAnchor:"middle",fill:gh("text"),fontSize:10,children:e.label})]},e.id)})}):null}var _h=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];function Ph(e,t,i){let r="object"==typeof t?"cycle"===t.window?_h:t.window:void 0,n="object"==typeof t?void 0:t,o=ee(n,gh("primary"),i),a=new Map(e?.map(e=>[e.id,ee(n,e.color??gh("primary"),i)]));return t=>{let n=String(t.datum?.source??"");if(r?.length){let o=Number(t.datum?.windowIndex??0),a=r[(o%r.length+r.length)%r.length];return{...Ah(e,n),...ee(void 0,a,i)(t)}}return{...Ah(e,n),...(a.get(n)??o)(t)}}}import*as Ih from"react";import{scaleLinear as Th}from"d3-scale";function Lh(e){return{...e,points:e.points.map(e=>({...e}))}}function Ch(e){if(!Number.isFinite(e.durationSeconds)||e.durationSeconds<=0||!Array.isArray(e.points)||e.points.length<2||e.points.some(e=>!e||!Number.isFinite(e.x)||!Number.isFinite(e.y))||null!=e.elapsedSeconds&&(!Number.isFinite(e.elapsedSeconds)||e.elapsedSeconds<0||e.elapsedSeconds>e.durationSeconds))throw new RangeError("Physics travel requires two finite points, a positive duration and valid elapsed seconds")}function Rh(e,t){return e&&"object"==typeof e&&"__phase"in e&&e.__phase!==t?{...e,__phase:t}:e}function Nh(e){return e&&"object"==typeof e&&"late"in e&&e.late?"late":"board"}function Dh(e){let t=0;for(let i=1;i<e.length;i++)t+=Math.hypot(e[i].x-e[i-1].x,e[i].y-e[i-1].y);return t}function Fh(e,t){let i=e.travel;if(!i)return!1;let r=Math.min(i.durationSeconds,(i.elapsedSeconds??0)+t);i.elapsedSeconds=r;let n=Dh(i.points)*r/i.durationSeconds,o=i.points[i.points.length-1];for(let e=1;e<i.points.length;e++){let t=i.points[e-1],r=i.points[e],a=Math.hypot(r.x-t.x,r.y-t.y);if(a>0&&n<a){o={x:t.x+(r.x-t.x)*n/a,y:t.y+(r.y-t.y)*n/a};break}n-=a}if(e.x=o.x,e.y=o.y,e.vx=e.vy=0,r<i.durationSeconds-1e-9)return!1;let a=i.points[i.points.length-1];return e.x=e.prevX=a.x,e.y=e.prevY=a.y,delete e.travel,e.datum=Rh(e.datum,Nh(e.datum)),!0}function Eh(e,t){if(!Number.isFinite(e))throw new RangeError(`${t} must be finite`)}function Oh(e,t){if(Eh(e,t),e<=0)throw new RangeError(`${t} must be positive`)}function zh(e,t){if(!Array.isArray(e))throw new RangeError(`${t} must be an array`)}function Bh(e,t){zh(e,t);for(let i of e)if("string"!=typeof i)throw new RangeError(`${t} must contain strings`)}function jh(e){if(!e||!e.shape||"circle"!==e.shape.type&&"aabb"!==e.shape.type)throw new RangeError("Physics bodies require a circle or aabb shape");let t=`Physics body ${e.id}`;Eh(e.x,`${t}.x`),Eh(e.y,`${t}.y`);for(let i of["vx","vy","angle","restitution","friction"])null!=e[i]&&Eh(e[i],`${t}.${i}`);if(null!=e.mass&&Oh(e.mass,`${t}.mass`),e.travel&&(Ch(e.travel),e.fixedPosition))throw new RangeError("Physics travel cannot use fixedPosition");"circle"===e.shape.type?Oh(e.shape.radius,`${t}.radius`):(Oh(e.shape.width,`${t}.width`),Oh(e.shape.height,`${t}.height`))}function Wh(e){for(let t of["restLength","stiffness","damping"])null!=e[t]&&Eh(e[t],`Physics spring.${t}`);"point"===e.target.type&&(Eh(e.target.x,"Physics spring.target.x"),Eh(e.target.y,"Physics spring.target.y"))}function Yh(e){jh(e),null!=e.spawnAt&&Eh(e.spawnAt,`Physics body ${e.id}.spawnAt`);for(let t of e.springs??[])Wh({...t,bodyId:e.id})}function qh(e){for(let t of e){if(!t?.shape||"segment"!==t.shape.type&&"aabb"!==t.shape.type)throw new RangeError("Physics colliders require a segment or aabb shape");let e=t.shape;if("segment"===e.type)for(let i of["x1","y1","x2","y2"])Eh(e[i],`Physics collider ${t.id}.${i}`);else for(let i of["x","y","width","height"])Eh(e[i],`Physics collider ${t.id}.${i}`);for(let[e,i]of Object.entries(t.shape))"type"!==e&&null!=i&&Eh(i,`Physics collider ${t.id}.${e}`);for(let e of["restitution","friction"])null!=t[e]&&Eh(t[e],`Physics collider ${t.id}.${e}`)}}function Xh(e){for(let[t,i]of Object.entries(e))"gravity"!==t&&null!=i&&Eh(i,`Physics option ${t}`);e.gravity&&(Eh(e.gravity.x,"Physics gravity.x"),Eh(e.gravity.y,"Physics gravity.y"));for(let t of["fixedDt","cellSize"])null!=e[t]&&Oh(e[t],`Physics option ${t}`);if(null!=e.velocityDamping&&e.velocityDamping<0)throw new RangeError("Physics velocityDamping must be nonnegative")}function Gh(e){Bh(e.activeSensors,"Physics activeSensors"),zh(e.bodies,"Physics bodies"),zh(e.colliders,"Physics colliders"),zh(e.springs,"Physics springs"),Xh(e.options);for(let t of e.bodies){jh(t);for(let e of["prevX","prevY","sleepTime","index"])Eh(t[e],`Physics body ${t.id}.${e}`)}qh(e.colliders);for(let t of e.springs)Wh(t);null!=e.randomState&&Eh(e.randomState,"Physics randomState")}function Vh(e){e.kernel&&Xh(e.kernel),e.viewTransform&&(Eh(e.viewTransform.x,"Physics viewTransform.x"),Eh(e.viewTransform.y,"Physics viewTransform.y")),e.colliders&&qh(e.colliders),null!=e.fixedDt&&Oh(e.fixedDt,"Physics fixedDt");for(let t of["maxDeltaSeconds","maxSubsteps","settleStepLimit","timeScale"])if(null!=e[t]&&(Eh(e[t],`Physics ${t}`),e[t]<0))throw new RangeError(`Physics ${t} must be nonnegative`)}function Hh(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(i in e!=i in t||!Object.is(e[i],t[i]))return!1;return!0}function Uh(e,t){return e===t||!(!e||!t||e.length!==t.length)&&e.every((e,i)=>{let r=t[i],n=e.shape,o=r.shape,a="segment"===n.type&&"segment"===o.type?n.x1===o.x1&&n.y1===o.y1&&n.x2===o.x2&&n.y2===o.y2&&(n.thickness??0)===(o.thickness??0):"aabb"===n.type&&"aabb"===o.type&&n.x===o.x&&n.y===o.y&&n.width===o.width&&n.height===o.height;return e.id===r.id&&e.sensor===r.sensor&&e.friction===r.friction&&e.restitution===r.restitution&&function(e,t){return e===t||!(!e||!t||"function"==typeof e||"function"==typeof t)&&e.property===t.property&&"equals"in e=="equals"in t&&"notEquals"in e=="notEquals"in t&&Object.is(e.equals,t.equals)&&Object.is(e.notEquals,t.notEquals)&&Hh(e.oneOf,t.oneOf)&&Hh(e.notOneOf,t.notOneOf)}(e.bodyFilter,r.bodyFilter)&&a})}function Zh(e,t){return!!t?.some(t=>Object.is(e,t))}function Kh(e){let t=e.fixedPosition;Number.isFinite(t?.x)&&(e.x=e.prevX=t.x,e.vx=0),Number.isFinite(t?.y)&&(e.y=e.prevY=t.y,e.vy=0)}function Qh(e){if(!e)return;let t=Number.isFinite(e.x)?e.x:void 0,i=Number.isFinite(e.y)?e.y:void 0;return null==t&&null==i?void 0:{x:t,y:i}}function Jh(e,t,i){let r,n="x"===i?"y":"x",o=Math.abs(t[i]-e[i]),a=t[n]-e[n],s=(e,t)=>"circle"===e.shape.type?e.shape.radius:("x"===t?e.shape.width:e.shape.height)/2;if("circle"===e.shape.type&&"circle"===t.shape.type){let i=e.shape.radius+t.shape.radius;r=Math.sqrt(Math.max(0,i*i-o*o))}else if("aabb"===e.shape.type&&"aabb"===t.shape.type)r=s(e,n)+s(t,n);else{let a="circle"===e.shape.type?e:t,l="aabb"===e.shape.type?e:t,c=s(a,i),u=Math.max(0,o-s(l,i));r=s(l,n)+Math.sqrt(Math.max(0,c*c-u*u))}let l=a<0?-1:1;return{nx:"x"===n?l:0,ny:"y"===n?l:0,penetration:Math.max(0,r-Math.abs(a))}}function ep(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function tp(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function ip(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,...e.travel?{travel:Lh(e.travel)}:{},...e.fixedPosition?{fixedPosition:Qh(e.fixedPosition)}:{},shape:ep(e.shape),sleeping:e.sleeping,datum:e.datum}}function rp(e){return{...ip(e),index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function np(e){return e&&"function"!=typeof e?{property:e.property,..."equals"in e?{equals:e.equals}:{},..."notEquals"in e?{notEquals:e.notEquals}:{},oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function op(e){return{id:e.id,shape:tp(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:np(e.bodyFilter),index:e.index}}function ap(e,t,i){let r=i.length>2,n=1/0,o=i[0][0],a=i[0][1],s=1,l=0;for(let c=0;c<i.length;c++){let[u,d]=i[c],[h,p]=i[(c+1)%i.length],f=h-u,g=p-d,m=Math.hypot(f,g);if(m<=1e-9)continue;let y=g/m,x=-f/m;(e-u)*y+(t-d)*x>0&&(r=!1);let b=Math.max(0,Math.min(1,((e-u)*f+(t-d)*g)/(m*m))),v=u+b*f,w=d+b*g,S=(e-v)**2+(t-w)**2;S<n&&(n=S,o=v,a=w,s=y,l=x)}let c=Math.hypot(e-o,t-a);return!r&&c>1e-9&&(s=(e-o)/c,l=(t-a)/c),{distance:r?-c:c,nx:s,ny:l}}function sp(e,t,i,r){let n=e.x-e.prevX,o=e.y-e.prevY,a=n*n+o*o;if(a<=1e-18||0===i&&!function(e,t){let i=0,r=1,n=e.x-e.prevX,o=e.y-e.prevY;for(let a=0;a<t.length;a++){let[s,l]=t[a],[c,u]=t[(a+1)%t.length],d=u-l,h=s-c;if(Math.hypot(d,h)<=1e-9)continue;let p=(e.prevX-s)*d+(e.prevY-l)*h,f=n*d+o*h;if(f<0)i=Math.max(i,-p/f);else if(f>0)r=Math.min(r,-p/f);else if(p>=0)return!1;if(i>=r)return!1}return i<r}(e,t)||ap(e.prevX,e.prevY,t).distance<i-r)return null;let s=1/0,l=null,c=(t,r,a,c,u)=>{if(t<0||t>1||t>s||t===s&&l&&Math.abs(r)<=Math.abs(l.nx)||n*r+o*a>=0)return;let d=i-((e.x-c)*r+(e.y-u)*a);d<=0||(s=t,l={nx:0===r?0:r,ny:0===a?0:a,penetration:d})};for(let s=0;s<t.length;s++){let[l,u]=t[s],[d,h]=t[(s+1)%t.length],p=d-l,f=h-u,g=Math.hypot(p,f);if(g>1e-9){let t=f/g,a=-p/g,s=n*t+o*a,d=(e.prevX-l)*t+(e.prevY-u)*a-i;if(s<0&&d>=-r){let i=Math.max(0,-d/s),r=((e.prevX+i*n-l)*p+(e.prevY+i*o-u)*f)/g;r>=0&&r<=g&&c(i,t,a,l,u)}}if(i<=0)continue;let m=e.prevX-l,y=e.prevY-u,x=m*n+y*o,b=x*x-a*(m*m+y*y-i*i);if(x>=0||b<0)continue;let v=Math.max(0,(-x-Math.sqrt(b))/a),w=m+v*n,S=y+v*o,k=Math.hypot(w,S);k>1e-9&&c(v,w/k,S/k,l,u)}return l}function lp(e,t,i){if("aabb"!==t.type||e.x===e.prevX&&e.y===e.prevY)return null;let r="circle"===e.shape.type?e.shape.radius:0,n=(t.width+("aabb"===e.shape.type?e.shape.width:0))/2,o=(t.height+("aabb"===e.shape.type?e.shape.height:0))/2,a=t.x-n,s=t.x+n,l=t.y-o,c=t.y+o;return Math.max(e.x,e.prevX)+r<a||Math.min(e.x,e.prevX)-r>s||Math.max(e.y,e.prevY)+r<l||Math.min(e.y,e.prevY)-r>c?null:sp(e,[[a,l],[s,l],[s,c],[a,c]],r,i)}function cp(e,t,i=0,r=!1){let n=function(e,t){let{x1:i,y1:r,x2:n,y2:o}=t;if("circle"===e.shape.type)return[[i,r],[n,o]];(i>n||i===n&&r>o)&&(i=t.x2,r=t.y2,n=t.x1,o=t.y1);let a=e.shape.width/2,s=e.shape.height/2*(o>=r?1:-1),l=[[i-a,r-s],[i+a,r-s],[n+a,o-s],[n+a,o+s],[n-a,o+s],[i-a,r+s]];return s<0?l.reverse():l}(e,t),o=(t.thickness??0)/2+("circle"===e.shape.type?e.shape.radius:0);if(r){let t=sp(e,n,o,i);if(t)return t}let a=ap(e.x,e.y,n),s=o-a.distance;return s>0?{nx:a.nx,ny:a.ny,penetration:s}:null}function up(e,t){return Math.abs(e.x-t.x)<=t.padding&&Math.abs(e.y-t.y)<=t.padding}function dp(e,t){let i=hp(e),r=[];for(let e=0;e<t.length;e++)gp(i,t[e].bounds)&&r.push(e);return{bounds:i,indexes:r}}function hp(e,t=!0){let i="circle"===e.shape.type?e.shape.radius:e.shape.width/2,r="circle"===e.shape.type?e.shape.radius:e.shape.height/2,n=t?Math.max(.005,Math.min(i,r)):0;return{x:e.x,y:e.y,padding:n,minX:Math.min(e.x,e.prevX)-i-n,minY:Math.min(e.y,e.prevY)-r-n,maxX:Math.max(e.x,e.prevX)+i+n,maxY:Math.max(e.y,e.prevY)+r+n}}function pp(e){let t="circle"===e.shape.type?e.shape.radius:e.shape.width/2,i="circle"===e.shape.type?e.shape.radius:e.shape.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}function fp(e){let t=e.shape;if("aabb"===t.type)return pp({x:t.x,y:t.y,shape:t});let i=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-i,minY:Math.min(t.y1,t.y2)-i,maxX:Math.max(t.x1,t.x2)+i,maxY:Math.max(t.y1,t.y2)+i}}function gp(e,t){return e.minX<=t.maxX&&e.maxX>=t.minX&&e.minY<=t.maxY&&e.maxY>=t.minY}function mp(e,t,i={x:0,y:0}){let r=1,n=e.map(e=>{let t=hp(e,!(e.sleeping&&e.x===e.prevX&&e.y===e.prevY));return!1!==e.bodyCollisions&&(r=Math.max(r,t.maxX-t.minX,t.maxY-t.minY)),t}),o=Math.max(1,Math.min(t,r)),a=new Map;for(let t=0;t<e.length;t+=1){if(!1===e[t].bodyCollisions)continue;let i=n[t];i.cellX=Math.floor(i.minX/o),i.cellY=Math.floor(i.minY/o);for(let e=i.cellX;e<=Math.floor(i.maxX/o);e+=1){let r=a.get(e);r||a.set(e,r=new Map);for(let e=i.cellY;e<=Math.floor(i.maxY/o);e+=1){let i=r.get(e);i?i.push(t):r.set(e,[t])}}}let s=[];for(let[e,t]of a)for(let[i,r]of t)for(let t=0;t<r.length;t+=1)for(let o=t+1;o<r.length;o+=1){let a=r[t],l=r[o],c=n[a],u=n[l];e!==Math.max(c.cellX,u.cellX)||i!==Math.max(c.cellY,u.cellY)||gp(c,u)&&s.push([a,l])}let l=e.map(e=>e.x*i.x+e.y*i.y);return s.sort(([e,t],[i,r])=>Math.max(l[i],l[r])-Math.max(l[e],l[t])||(e===i?t-r:e-i)),{pairs:s,coversPositions:()=>e.every((e,t)=>!1===e.bodyCollisions||up(e,n[t]))}}function yp(e,t){if("circle"!==e.shape.type||"circle"!==t.shape.type)return null;let i=e.shape.radius+t.shape.radius;if(i<=0)return null;let r=t.prevX-e.prevX,n=t.prevY-e.prevY,o=t.x-e.x-r,a=t.y-e.y-n,s=o*o+a*a,l=2*(r*o+n*a),c=r*r+n*n-i*i;if(c<-1e-5||s<=1e-12||l>=0)return null;let u=l*l-4*s*c;if(u<0)return null;let d=(-l-Math.sqrt(u))/(2*s);if(d<0||d>1)return null;let h=(r+d*o)/i,p=(n+d*a)/i,f=i-((t.x-e.x)*h+(t.y-e.y)*p);return f>0?{nx:h,ny:p,penetration:f}:null}var xp={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},bp=1e-9,vp=.005;function wp(e,t,i){return Math.max(t,Math.min(i,e))}function Sp(e,t,i){return Math.min(e??i,t??i)}function kp(e,t,i){return wp(Math.max(e??i,t??i),0,1)}function Ap(e){return e<0?-1:1}function Mp(e){return e.sleeping&&e.x===e.prevX&&e.y===e.prevY}function $p(e,t,i,r,n,o,a,s){let l=n-e,c=(i+a)/2-Math.abs(l);if(c<=0)return null;let u=o-t,d=(r+s)/2-Math.abs(u);return d<=0?null:c<d?{nx:Ap(l),ny:0,penetration:c}:{nx:0,ny:Ap(u),penetration:d}}function _p(e,t,i,r,n,o,a){let s=o/2,l=a/2,c=e-wp(e,r-s,r+s),u=t-wp(t,n-l,n+l),d=c*c+u*u;if(d>i*i)return null;if(d<=bp){let o=Math.abs(e-(r-s)),a=Math.abs(e-(r+s)),c=Math.abs(t-(n-l)),u=Math.abs(t-(n+l)),d=Math.min(o,a,c,u);return d===o?{nx:-1,ny:0,penetration:i+o}:d===a?{nx:1,ny:0,penetration:i+a}:d===c?{nx:0,ny:-1,penetration:i+c}:{nx:0,ny:1,penetration:i+u}}let h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:i-h}}function Pp(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,i,r,n,o){let a=r-e,s=n-t,l=i+o,c=a*a+s*s;if(c>=l*l)return null;if(c<=bp)return{nx:1,ny:0,penetration:l};let u=Math.sqrt(c);return{nx:a/u,ny:s/u,penetration:l-u}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return $p(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);let i="circle"===e.shape.type?e:t,r=i===e?t:e;if("circle"!==i.shape.type||"aabb"!==r.shape.type)return null;let n=_p(i.x,i.y,i.shape.radius,r.x,r.y,r.shape.width,r.shape.height);return n&&i===e&&(n.nx=-n.nx,n.ny=-n.ny),n}function Ip(e,t){let i=t.shape;return"aabb"===i.type?"circle"===e.shape.type?_p(e.x,e.y,e.shape.radius,i.x,i.y,i.width,i.height):$p(i.x,i.y,i.width,i.height,e.x,e.y,e.shape.width,e.shape.height):cp(e,i)}function Tp(e,t){return`${e}\0${t}`}function Lp(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Cp(e,t){return function(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let i=function(e,t){if(!t)return;let i=e;for(let e of t.split(".")){if(null==i||"object"!=typeof i||!Object.prototype.hasOwnProperty.call(i,e))return;i=i[e]}return i}(e,t.property);return!("equals"in t&&!Object.is(i,t.equals)||"notEquals"in t&&Object.is(i,t.notEquals)||t.oneOf&&!Zh(i,t.oneOf)||t.notOneOf&&Zh(i,t.notOneOf))}(t,e.bodyFilter)}var Rp=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.supportDependents=new Map,this.supportContactsThisStep=new Set,this.reboundingThisStep=new Set,this.interpenetratingThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,Xh(e),this.options={...xp,...e},this.random=Q(this.options.seed)}init(e={}){Xh(e),this.options={...xp,...e},this.random=Q(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){jh(e);let t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(bp,e.mass??1),bodyCollisions:e.bodyCollisions??!0,...e.fixedPosition?{fixedPosition:Qh(e.fixedPosition)}:{},...e.travel?{travel:Lh(e.travel)}:{},shape:ep(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};t.travel&&Fh(t,0),Kh(t),this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(let t of e){this.bodies.delete(t);for(let e of Array.from(this.activeSensors))Lp(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){if(qh(e),!Uh(e,this.sortedColliders())){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(let t of e)this.colliders.set(t.id,{...t,shape:tp(t.shape),bodyFilter:np(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}}setConstraint(e){Wh(e);let t=e.id??`spring-${this.nextSpringIndex}`;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,i){if(!Number.isFinite(t)||!Number.isFinite(i))throw new RangeError("Physics impulses must be finite");let r=this.bodies.get(e);r&&(r.vx+=t/r.mass,r.vy+=i/r.mass,Kh(r),this.wake(r))}step(e=this.options.fixedDt){let t=Number.isFinite(e)?Math.max(0,e):0;if(this.lastEvents=[],0===t)return;this.reboundingThisStep.clear();let i=this.sortedBodies(),r=i.some(e=>e.travel)?i.filter(e=>!e.travel):i;for(let e of i)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);let n=this.options.maxVelocity,o=this.options.velocityDamping**(120*t);for(let e of r)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=o,e.vy*=o,Kh(e),n>0){let t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>n){let i=n/t;e.vx*=i,e.vy*=i}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear(),this.supportDependents.clear(),this.supportContactsThisStep.clear(),this.interpenetratingThisStep.clear();let a=this.sortedColliders().filter(e=>!e.sensor).map(e=>({collider:e,bounds:fp(e)})),s=a.some(({collider:e})=>e.bodyFilter)?void 0:new Array(r.length),l=new Set,c=new Set;this.resolveColliders(r,a,l,s);let u=s&&r.map(Mp),d=mp(r,this.options.cellSize,this.options.gravity);for(let e=0;e<this.options.collisionIterations;e+=1){e>0&&!d.coversPositions()&&(d=mp(r,this.options.cellSize,this.options.gravity));let t=this.resolveBodyPairs(r,d.pairs,c,0===e,u),i=this.resolveColliders(r,a,l,s);if(s&&!t&&!i)break}d.coversPositions()||(d=mp(r,this.options.cellSize,this.options.gravity));for(let[e,t]of d.pairs){let i=Pp(r[e],r[t]);i&&i.penetration>.02&&(this.interpenetratingThisStep.add(r[e].id),this.interpenetratingThisStep.add(r[t].id))}let h=Array.from(this.supportedThisStep);for(let e=0;e<h.length;e+=1)for(let t of this.supportDependents.get(h[e])??[])this.supportedThisStep.has(t)||(this.supportedThisStep.add(t),h.push(t));this.reconcileSupportedVelocity(r,t),this.updateSensors(r),this.updateSleeping(r,t);for(let e of i)Fh(e,t)&&this.lastEvents.push({type:"travel-end",bodyId:e.id})}settle(e=1200,t=this.options.fixedDt){let i=0;for(;i<e&&!this.allSleeping();)this.step(t),i+=1;return i}readState(e=[]){e.length=0;for(let t of this.sortedBodies())e.push(ip(t));return e}readBody(e){let t=this.bodies.get(e);return t?ip(t):void 0}workerSleepTimes(e){return Float32Array.from(e,e=>this.bodies.get(e)?.sleepTime??0)}applyWorkerMotion(e){e.ids.forEach((t,i)=>{let r=this.bodies.get(t);r&&(r.prevX=e.previousPositions?.[2*i]??r.x,r.prevY=e.previousPositions?.[2*i+1]??r.y,r.x=e.positions[2*i],r.y=e.positions[2*i+1],r.vx=e.velocities[2*i],r.vy=e.velocities[2*i+1],r.sleeping=1===e.sleeping[i],r.sleepTime=e.sleepTimes?.[i]??(r.sleeping?this.options.sleepAfter:0),r.travel&&e.travelElapsed&&(r.travel.elapsedSeconds=e.travelElapsed[i]),r.datum=Rh(r.datum,r.travel?"travel":r.sleeping?"settled":Nh(r.datum)))}),this.lastEvents=e.result.events,e.state&&(this.activeSensors=new Set(e.state.activeSensorPairs))}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Lp)}allSleeping(){for(let e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{randomState:this.random.getState(),options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(rp),colliders:this.sortedColliders().map(op),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){Gh(e),this.options={...e.options,gravity:{...e.options.gravity}},this.random=Q(e.randomState??this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(let t of e.bodies){let e=rp(t);Kh(e),this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(let t of e.colliders){let e=op(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(let t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});let e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(let t of Array.from(this.springs.values()).sort((e,t)=>e.id<t.id?-1:e.id>t.id?1:0)){let i=this.bodies.get(t.bodyId);if(!i||i.sleeping||i.travel)continue;let r="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!r)continue;let n=r.x-i.x,o=r.y-i.y,a=n*n+o*o,s=Math.sqrt(a);if(s<=bp)continue;let l=n/s,c=o/s,u="vx"in r?r.vx:0,d="vy"in r?r.vy:0,h=(u-i.vx)*l+(d-i.vy)*c,p=(s-t.restLength)*t.stiffness+h*t.damping;i.vx+=p*l*e/i.mass,i.vy+=p*c*e/i.mass}}resolveBodyPairs(e,t,i,r,n){let o=!1;for(let[a,s]of t){let t=e[a],l=e[s];if(!t||!l)continue;if(!r&&n?.[a]&&n[s]&&Mp(t)&&Mp(l)){o=!0;continue}let c=yp(t,l)??Pp(t,l);if(!c)continue;o=!0,this.resolveDynamicCollision(t,l,c);let u=a*e.length+s;i.has(u)||(i.add(u),this.lastEvents.push({type:"contact",bodyId:t.id,otherId:l.id,sensor:!1}))}return o}resolveDynamicCollision(e,t,i){(e.fixedPosition||t.fixedPosition)&&(!e.sleeping&&null==e.fixedPosition?.x||!t.sleeping&&null==t.fixedPosition?.x?(e.sleeping||null!=e.fixedPosition?.y)&&(t.sleeping||null!=t.fixedPosition?.y)&&(i=Jh(e,t,"y")):i=Jh(e,t,"x"));let r=this.options.gravity,n=Math.hypot(r.x,r.y),o=this.contactOpposesGravity(i.nx,i.ny,n),a=this.contactOpposesGravity(-i.nx,-i.ny,n);o&&(e.sleeping&&this.supportedThisStep.add(t.id),this.addSupportContact(e.id,t.id)),a&&(t.sleeping&&this.supportedThisStep.add(e.id),this.addSupportContact(t.id,e.id));let s=e.sleeping?0:1/e.mass,l=t.sleeping?0:1/t.mass,c=null==e.fixedPosition?.x?s:0,u=null==e.fixedPosition?.y?s:0,d=null==t.fixedPosition?.x?l:0,h=null==t.fixedPosition?.y?l:0,p=e.fixedPosition||t.fixedPosition?i.nx**2*(c+d)+i.ny**2*(u+h):s+l;if(p<=bp)return;let f=this.supportedThisStep.has(e.id)&&o&&!t.sleeping&&!t.fixedPosition,g=this.supportedThisStep.has(t.id)&&a&&!e.sleeping&&!e.fixedPosition,m=n>1,y=m&&f?0:c,x=m&&f?0:u,b=m&&!f&&g?0:d,v=m&&!f&&g?0:h,w=i.nx**2*(y+b)+i.ny**2*(x+v),S=Math.max(0,i.penetration-vp)/Math.max(bp,w);e.x-=i.nx*S*y,e.y-=i.ny*S*x,t.x+=i.nx*S*b,t.y+=i.ny*S*v,m&&f&&this.supportedThisStep.add(t.id),m&&g&&this.supportedThisStep.add(e.id);let k=t.vx-e.vx,A=t.vy-e.vy,M=k*i.nx+A*i.ny;if(M>0)return;let $=Math.abs(M),_=Sp(e.restitution,t.restitution,this.options.restitution),P=e.vx*r.x+e.vy*r.y,I=t.vx*r.x+t.vy*r.y,T=-(1+_)*M/p,L=T*i.nx,C=T*i.ny;e.vx-=L*c,e.vy-=C*u,t.vx+=L*d,t.vy+=C*h,this.applyFriction(e,t,i,T,c,u,d,h),_>0&&(P>=0&&e.vx*r.x+e.vy*r.y<0&&this.reboundingThisStep.add(e.id),I>=0&&t.vx*r.x+t.vy*r.y<0&&this.reboundingThisStep.add(t.id)),$>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,i,r,n,o,a,s){let l=-i.ny,c=i.nx,u=(t.vx-e.vx)*l+(t.vy-e.vy)*c,d=e.fixedPosition||t.fixedPosition?l**2*(n+a)+c**2*(o+s):n+a;if(Math.abs(u)<=bp||d<=bp)return;let h=kp(e.friction,t.friction,this.options.friction),p=wp(-u/d,-r*h,r*h),f=p*l,g=p*c;e.vx-=f*n,e.vy-=g*o,t.vx+=f*a,t.vy+=g*s}resolveColliders(e,t,i,r){if(0===t.length)return!1;let n=!1;for(let o=0;o<e.length;o++){let a=e[o],s=r?.[o];r&&(!s||!up(a,s.bounds))&&(r[o]=s=dp(a,t));let l=0;for(;l<(s?s.indexes.length:t.length);){let e=s?s.indexes[l++]:l++,{collider:c,bounds:u}=t[e];if(!Cp(c,a))continue;let d="segment"===c.shape.type?cp(a,c.shape,vp+bp,!0):lp(a,c.shape,vp+bp)??(gp(pp(a),u)?Ip(a,c):null);if(!d)continue;n=!0,this.resolveStaticCollision(a,c,d),this.contactOpposesGravity(d.nx,d.ny)&&this.supportedThisStep.add(a.id);let h=o*t.length+e;if(i.has(h)||(i.add(h),this.lastEvents.push({type:"contact",bodyId:a.id,otherId:c.id,sensor:!1})),s&&r&&!up(a,s.bounds))for(r[o]=s=dp(a,t),l=0;l<s.indexes.length&&s.indexes[l]<=e;)l++}}return n}resolveStaticCollision(e,t,i){e.x+=i.nx*Math.max(0,i.penetration-vp),e.y+=i.ny*Math.max(0,i.penetration-vp);let r=e.vx*i.nx+e.vy*i.ny;if(r<0){let n=Sp(e.restitution,t.restitution,this.options.restitution),o=this.options.gravity,a=e.vx*o.x+e.vy*o.y;e.vx-=(1+n)*r*i.nx,e.vy-=(1+n)*r*i.ny;let s=-i.ny,l=i.nx,c=e.vx*s+e.vy*l,u=kp(e.friction,t.friction,this.options.friction)*-(1+n)*r,d=wp(c,-u,u);e.vx-=d*s,e.vy-=d*l,n>0&&a>=0&&e.vx*o.x+e.vy*o.y<0&&this.reboundingThisStep.add(e.id)}Kh(e)}updateSensors(e){let t=this.sortedColliders().filter(e=>e.sensor);if(0===t.length&&0===this.activeSensors.size)return;let i=new Set;for(let r of e){let e=pp(r);for(let n of t){if(!Cp(n,r)||!gp(e,fp(n))||!Ip(r,n))continue;let t=Tp(n.id,r.id);i.add(t),this.activeSensors.has(t)||this.lastEvents.push({type:"sensor-enter",bodyId:r.id,sensorId:n.id})}}for(let e of Array.from(this.activeSensors).sort()){if(i.has(e))continue;let{sensorId:t,bodyId:r}=Lp(e);this.lastEvents.push({type:"sensor-exit",bodyId:r,sensorId:t})}this.activeSensors=i}updateSleeping(e,t){let i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(let r of e){let e=Math.sqrt(r.vx*r.vx+r.vy*r.vy),n=Math.sqrt((r.x-r.prevX)*(r.x-r.prevX)+(r.y-r.prevY)*(r.y-r.prevY));e<this.options.sleepSpeed&&n<this.options.sleepSpeed*t&&!this.interpenetratingThisStep.has(r.id)&&(!i||this.supportedThisStep.has(r.id))?(r.sleepTime+=t,!r.sleeping&&r.sleepTime>=this.options.sleepAfter&&(r.sleeping=!0,r.vx=0,r.vy=0,r.datum=Rh(r.datum,"settled"),this.lastEvents.push({type:"sleep",bodyId:r.id}))):r.sleeping?this.wake(r):r.sleepTime=0}}addSupportContact(e,t){let i=this.supportDependents.get(e);i?.has(t)||(this.supportContactsThisStep.add(e),this.supportContactsThisStep.add(t),i||(i=new Set,this.supportDependents.set(e,i)),i.add(t))}reconcileSupportedVelocity(e,t){let i=this.options.gravity;if(!(Math.hypot(i.x,i.y)<=1))for(let r of e)r.sleeping||!this.supportedThisStep.has(r.id)||!this.supportContactsThisStep.has(r.id)||this.reboundingThisStep.has(r.id)&&r.vx*i.x+r.vy*i.y<0||(r.vx=(r.x-r.prevX)/t,r.vy=(r.y-r.prevY)/t,Kh(r))}contactOpposesGravity(e,t,i){let{x:r,y:n}=this.options.gravity;return i??(i=Math.hypot(r,n)),i<=1e-9||(e*r+t*n)/i<-.2}wake(e){e.travel||(e.datum=Rh(e.datum,Nh(e.datum))),e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Np=class{constructor(e={}){this.id="builtin",this.world=new Rp(e),this.capabilities={...this.world.capabilities,engine:"builtin"}}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}readBody(e){return this.world.readBody(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}workerSleepTimes(e){return this.world.workerSleepTimes(e)}applyWorkerMotion(e){this.world.applyWorkerMotion(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Dp(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):function(e={}){return new Np(e)}(t)}var Fp=["binId","targetBin","category","windowIndex","lane","group"];function Ep(){return{count:0,total:0,mean:0,m2:0,min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}}function Op(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);let i=t-e.mean;e.mean+=i/e.count;let r=t-e.mean;e.m2+=i*r}function zp(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Bp(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:Number.POSITIVE_INFINITY,max:e.count>0?e.max:Number.NEGATIVE_INFINITY}}function jp(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function Wp(e,t,i){return"function"==typeof e?e(t,i):"string"==typeof e?jp(t,e):void 0}function Yp(e){if(null==e)return;let t=String(e);return t.trim()?t:void 0}function qp(e){let t=zp(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:zp(e.x),y:zp(e.y),value:t}}var Xp=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;let t=this.nextIndex;this.nextIndex+=1;let i=Yp(Wp(this.config.binAccessor,e,t))??function(e){for(let t of Fp){let i=Yp(jp(e,t));if(i)return i}return"sediment"}(e),r=Yp(Wp(this.config.labelAccessor,e,t))??i,n=function(e,t,i){if("number"==typeof e)return e;let r="function"==typeof e?e(t,i):"string"==typeof e?jp(t,e):1,n="number"==typeof r?r:Number(r);return Number.isFinite(n)?n:1}(this.config.valueAccessor,e,t),o=Math.max(0,Math.floor(this.config.retainBodyIds??12)),a=this.bins.get(i);return a||(a={id:i,label:r,bodyIds:[],x:Ep(),y:Ep(),value:Ep()},this.bins.set(i,a)),a.label=r,a.lastBodyId=e.id,a.lastDatum=e.datum,Op(a.x,e.x),Op(a.y,e.y),Op(a.value,n),o>0&&(a.bodyIds.push(e.id),a.bodyIds.length>o&&(a.bodyIds=a.bodyIds.slice(a.bodyIds.length-o))),qp(a)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(qp)}restore(e=[]){this.bins.clear();for(let t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Bp(t.x),y:Bp(t.y),value:Bp(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){let e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function Gp(e){let t=Number(e);if(Number.isFinite(t)&&!(t<=0))return Math.floor(t)}var Vp={bodyLimit:Number.POSITIVE_INFINITY,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1,viewTransform:{x:0,y:0}};function Hp(e,t,i){return{...e,timestamp:e.timestamp??t,chartType:e.chartType??i.chartType,chartId:e.chartId??i.chartId}}var Up={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Zp(e={},t=Up){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function Kp(e){return{...e,shape:{...e.shape},...e.travel?{travel:Lh(e.travel)}:{},...e.fixedPosition?{fixedPosition:{...e.fixedPosition}}:{},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Qp(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:void 0}let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Jp(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function ef(e){return{...Kp(e),sequence:e.sequence,spawnAt:e.spawnAt}}function tf(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function rf(e){return!1!==e&&{...e}}function nf(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function of(e){return{...e,gravity:{...e.gravity}}}function af(e,t,i,r){if("circle"===e.shape.type){let n=e.x-t,o=e.y-i,a=e.shape.radius+r,s=n*n+o*o;return s<=a*a?s:null}let n=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),o=Math.max(Math.abs(i-e.y)-e.shape.height/2,0),a=n*n+o*o;return a<=r*r?a:null}function sf(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function lf(e,t={}){let{idPrefix:i="plot",includeFloor:r=!0,includeCeiling:n=!1,includeLeftWall:o=!0,includeRightWall:a=!0,wallThickness:s=20,floorThickness:l=s}=t,c=[],u=e.x+e.width/2,d=e.y+e.height/2,h=(e,t,r,n,o)=>{c.push({id:`${i}-${e}`,shape:{type:"aabb",x:t,y:r,width:n,height:o}})};return r&&h("floor",u,e.y+e.height+l/2,e.width+2*s,l),n&&h("ceiling",u,e.y-l/2,e.width+2*s,l),o&&h("left-wall",e.x-s/2,d,s,e.height+2*l),a&&h("right-wall",e.x+e.width+s/2,d,s,e.height+2*l),c}function cf(e){let{idPrefix:t="bin",count:i,domainStart:r,domainStep:n,xScale:o,yTop:a,yBottom:s,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=a,lidThickness:p=Math.max(2,l)}=e,f=[],g=a+(s-a)/2,m=Math.abs(s-a),y=c?i:i-1;if(u||c)for(let e=c?0:1;e<=y;e+=1){if(!u&&e>0&&e<i)continue;let a=o(r+e*n);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:a,y:g,width:l,height:m}})}if(null!=d)for(let e=0;e<i;e+=1){let i=r+e*n,a=i+n;if(a>=d)continue;let s=o(i),c=o(a);f.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(s,c)+l/2,y1:h,x2:Math.max(s,c)-l/2,y2:h,thickness:p}})}return f}import{quadtree as uf}from"d3-quadtree";var df=class{constructor(){this.order=new Map,this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,i,r,n,o=0,a){let s=this.ensure(e,t,i);if(!s)return null;let l=null,c=Number.POSITIVE_INFINITY,u=Math.max(0,a?.searchRadius??Math.max(0,o)+this.maxSearchRadius),d=r-u,h=r+u,p=n-u,f=n+u;return s.visit((e,t,i,s,u)=>{if(s<d||t>h||u<p||i>f)return!0;if(e.length)return!1;let g=e;for(;g;){let e=g.data;if(e&&(!a?.include||a.include(e))){let t=a?.distanceSquared?a.distanceSquared(e,r,n):af(e,r,n,Math.max(0,o));null!=t&&(t<c||t===c&&(this.order.get(e.id)??-1)>(this.order.get(l?.id??"")??-1))&&(l=e,c=t)}g=g.next}return!1}),l}ensure(e,t,i){if(this.tree&&this.revision===t)return this.tree;this.order=new Map(Array.from(i,(e,t)=>[e,t]));let r=e.readState();return 0===r.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=r.reduce((e,t)=>{return Math.max(e,"circle"===(i=t).shape.type?i.shape.radius:Math.hypot(i.shape.width,i.shape.height)/2);var i},0),this.tree=uf().x(e=>e.x).y(e=>e.y).addAll(r),this.revision=t,this.tree)}};function hf(e){return{...e,...e.viewTransform&&{viewTransform:{...e.viewTransform}},...e.colliders&&{colliders:tf(e.colliders)},...e.kernel&&{kernel:{...e.kernel,...e.kernel.gravity&&{gravity:{...e.kernel.gravity}}}}}}var pf=["data","scene-geometry","data-paint","accessibility","evidence"],ff=["scene-geometry","data-paint","accessibility","evidence"],gf=["overlay","accessibility","evidence"],mf=(e,t)=>({retainedData:e,invalidations:t}),yf=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xf=["scene-geometry","data-paint","accessibility","evidence"],bf=[],vf={engine:/*#__PURE__*/mf("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:/*#__PURE__*/mf("preserve",xf),colliders:/*#__PURE__*/mf("preserve",xf),sediment:/*#__PURE__*/mf("preserve",xf),bodyBudget:/*#__PURE__*/mf("preserve",yf),bodyLimit:/*#__PURE__*/mf("preserve",yf),eviction:/*#__PURE__*/mf("preserve",yf),fixedDt:/*#__PURE__*/mf("preserve",bf),maxDeltaSeconds:/*#__PURE__*/mf("preserve",bf),maxSubsteps:/*#__PURE__*/mf("preserve",bf),settleStepLimit:/*#__PURE__*/mf("preserve",bf),timeScale:/*#__PURE__*/mf("preserve",bf),observation:/*#__PURE__*/mf("preserve",bf)},wf=/*#__PURE__*/mf("preserve",yf);function Sf(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(vf,r)?vf[r]:wf;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var kf=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Af(e,t){return e===t||!(!e||!t||e.gravity?.x!==t.gravity?.x||e.gravity?.y!==t.gravity?.y)&&kf.every(i=>e[i]===t[i])}function Mf(e,t){if(e.readBody){if(!t)return t=>e.readBody(t);let i=new Map;for(let r of t)i.has(r)||i.set(r,e.readBody(r));return e=>i.get(e)}let i=new Map(e.readState().map(e=>[e.id,e]));return e=>i.get(e)}function $f(e,t){for(let i of e)t.has(sf(i).bodyId)&&e.delete(i)}function _f(e,t,i,r){return e||!t?"paused":i||!r?"running":"settled"}var Pf=class{constructor(){this.heap=[]}get length(){return this.heap.length}firstArrival(){return this.heap[0]?.spawnAt}lastArrival(){return this.latest}push(e){this.latest=Math.max(this.latest??-1/0,e.spawnAt);let t=this.heap.length;for(this.heap.push(e);t>0;){let i=t-1>>>1;if(nf(this.heap[i],e)<=0)break;this.heap[t]=this.heap[i],t=i}this.heap[t]=e}shift(){let e=this.heap[0],t=this.heap.pop();if(0===this.heap.length)return this.latest=void 0,e;if(!t)return e;let i=0;for(;2*i+1<this.heap.length;){let e=2*i+1;if(e+1<this.heap.length&&nf(this.heap[e+1],this.heap[e])<0&&(e+=1),nf(t,this.heap[e])<=0)break;this.heap[i]=this.heap[e],i=e}return this.heap[i]=t,e}clear(){this.heap=[],this.latest=void 0}remove(e){let t=new Set,i=this.heap.filter(i=>!e.has(i.id)||(t.add(i.id),!1));return t.size&&this.restore(i),t}sorted(){return this.heap.slice().sort(nf)}restore(e){this.clear();for(let t of e)this.push(t)}},If={};function Tf(e){let t=If[e];if(!t)throw new Error(`Physics ${e} configuration requires registerPhysicsLivePrograms() from semiotic/physics before a PhysicsPipelineStore is created or restored with it.`);return t}var Lf=class e{configure(e,t){!1===e.emitters?this.emitters=void 0:e.emitters&&(this.emitters?this.emitters.update(e.emitters):this.emitters=Tf("emitters").create(e.emitters)),!1===e.eventDrop?this.eventDrop=void 0:e.eventDrop&&(this.eventDrop?this.eventDrop.update(e.eventDrop,t):this.eventDrop=Tf("eventDrop").create(e.eventDrop),t.setColliders(this.eventDrop.colliders()))}backlog(){return!!this.eventDrop?.backlog()}ownsClock(){return!(!this.eventDrop&&!this.emitters?.pending())}pending(){return this.backlog()||!(!this.emitters?.pending()&&!this.eventDrop?.continuous())}snapshot(){return{...this.emitters&&{emitters:this.emitters.snapshot()},...this.eventDrop&&{eventDrop:this.eventDrop.snapshot()}}}static restore(t){let i=new e;return t.emitters&&(i.emitters=Tf("emitters").restore(t.emitters)),t.eventDrop&&(i.eventDrop=Tf("eventDrop").restore(t.eventDrop)),i}},Cf=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=function(e){let t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,i){if(i>0)return void(this.seconds=0);if(e.allSleeping())return void(this.seconds+=Math.max(0,t));let r=e.readState(this.scratch),n=this.speed*this.speed,o=!0;for(let e of r){if(e.travel){o=!1;break}if(e.sleeping)continue;let i=e.x-e.prevX,r=e.y-e.prevY;if(e.vx*e.vx+e.vy*e.vy>=n||t>0&&i*i+r*r>=n*t*t){o=!1;break}}this.seconds=o?this.seconds+Math.max(0,t):0}};function Rf(e,t,i,r={}){let n,o=0,a=0,s=t+(r.drainArrivals?Math.max(0,Math.ceil(((e.lastArrival()??e.elapsed())-e.elapsed())/e.fixedDt)):0);for(;o+a<s&&!r.shouldStop?.()&&(!1===r.stopAtRest||e.queueSize()>0||!e.atRest()||r.continueWhile?.());){let t=e.nextArrival(),l=r.skipIdle&&null!=t&&e.atRest()?Math.min(Math.max(0,Math.floor((t-e.elapsed())/e.fixedDt)-1),Math.max(0,s-o-a-1)):0;l>0&&(e.advanceTime(l*e.fixedDt),a+=l),e.step(e.fixedDt),e.advanceTime(e.fixedDt);let c=e.drainEvents();i.events&&(i.events.push(...c),e.observeKernelEvents(c,i.observations),e.observeSensorTransitions(i.observations));let u=[];if(e.spawnDue(u,i.observations),u.length>0){i.spawned.push(...u),n=e.observeBodyBudget(i.observations);let t=e.evictOverflow(i.observations);i.evicted?.push(...t.evicted),i.sedimented?.push(...t.sedimented)}o+=1,e.refreshQuiescence(e.fixedDt,u.length),r.afterStep?.()}return{steps:o,budget:n}}var Nf=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new df,this.elapsedSeconds=0,this.liveBodyOrder=new Set,this.nextSequence=0,this.paused=!1,this.queue=new Pf,this.revision=0,this.observedInitialBoundary=!1,this.updateResults=new go,this.simulationState="settled",this.visible=!0,this.quiescence=new Cf,this.programs=new Lf,Vh(e);let{bodyBudget:t,colliders:i,engine:r,kernel:n,observation:o,sediment:a,emitters:s,eventDrop:l,...c}=e;this.config={...Vp,...c,viewTransform:{...c.viewTransform??Vp.viewTransform}},this.configInput=hf(e),this.bodyBudget=t??{},this.engineInput=r,this.observation=Zp(o),this.sediment=new Xp(a??!1),this.world=Dp(r,{fixedDt:this.config.fixedDt,...n}),this.quiescence.setKernelOptions(n),i&&this.world.setColliders(tf(i)),this.programs.configure({emitters:s,eventDrop:l},this.world)}updateConfig(e){Vh(e);let t=function(e,t){return Object.keys(e).filter(i=>"viewTransform"===i?e.viewTransform?.x!==t.viewTransform?.x||e.viewTransform?.y!==t.viewTransform?.y:"colliders"===i?!Uh(e.colliders,t.colliders):"kernel"===i?!Af(e.kernel,t.kernel):e[i]!==t[i])}(e,this.configInput),{colliders:i,bodyBudget:r,engine:n,kernel:o,observation:a,sediment:s,emitters:l,eventDrop:c,...u}=e;if(this.programs.configure({emitters:l,eventDrop:c},this.world),this.config={...this.config,...u,viewTransform:{...u.viewTransform??this.config.viewTransform}},t.includes("eventDrop")&&(this.revision+=1),void 0!==r&&(this.bodyBudget=r,!1===r&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){let e=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=Dp(n,e.options),this.world.restore(e),this.revision+=1}if(o&&!Af(o,this.configInput.kernel)){let e=this.world.snapshot(),t={...e.options,...o,gravity:{...e.options.gravity,...o.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}a&&(this.observation=Zp(a,this.observation)),this.sediment.updateConfig(s),i&&t.includes("colliders")&&(this.world.setColliders(tf(i)),this.revision+=1),this.configInput=hf({...this.configInput,...e});let d=Sf(t);this.updateResults.record({kind:"config",keys:t},d.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(tf(e)),this.configInput={...this.configInput,colliders:tf(e)},this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Sf(["colliders"]).invalidations)}enqueue(e,t){let i=function(e,t,i,r,n){let o=Array.isArray(t)?t:[t];for(let e of o)Yh(e);let a=i?function(e,t={}){let i=Qp(t.startAt)??0,r=t.pacing??"immediate";if("arrival"===r){let r=1/0,n=e.map((e,i)=>{let n=function(e,t,i){return"function"==typeof i?Qp(i(e,t)):"string"==typeof i?Qp(Jp(e,i)):Qp(e.spawnAt)??Qp(Jp(e,"arrivalTime"))??Qp(Jp(e,"timestamp"))??Qp(Jp(e,"time"))??Qp(Jp(e,"eventTime"))}(e,i,t.timeAccessor);return null!=n&&(r=Math.min(r,n)),n}),o=Qp(t.timeScale)??1,a=o>0?o:1;return e.map((e,t)=>{let o=n[t],s=null==o?0:Math.max(0,o-r);return{...Kp(e),spawnAt:i+s/a}})}if("object"==typeof r){let t=Qp(r.ratePerSec);if(t&&t>0)return e.map((e,r)=>({...Kp(e),spawnAt:i+r/t}))}return e.map(e=>({...Kp(e),spawnAt:i}))}(o,{...i,startAt:i.startAt??r}):o;if(i)for(let e of a)Yh(e);for(let t of a)e.push({...Kp(t),sequence:n++,spawnAt:t.spawnAt??r});return a.length}(this.queue,e,t,this.elapsedSeconds,this.nextSequence);this.nextSequence+=i,i>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i},i?pf:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Kp(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},pf)}materializeDueSpawns(){let e=this.revision,t=[],i=[];return this.spawnDue(t,i),0===t.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?pf:[])),t}clear(){this.observedInitialBoundary=!1;let{options:e,colliders:t}=this.world.snapshot();this.world.init({...e,fixedDt:this.config.fixedDt}),this.world.setColliders(t),this.activeSensorPairs.clear(),this.liveBodyOrder.clear(),this.queue.clear(),this.accumulator=0,this.elapsedSeconds=0,this.programs=new Lf,this.programs.configure(this.configInput,this.world),this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},pf)}tick(e,t){let i=this.revision,r=[],n=[],o=[],a=[],s=[];if(this.paused||!this.visible){let e=this.result(0,r,n,o,a,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}let l=Math.max(0,Math.min(Number.isFinite(e)?e:0,this.config.maxDeltaSeconds))*this.config.timeScale;this.spawnDue(r,s);let c=this.observeBodyBudget(s),u=this.evictOverflow(s);n.push(...u.evicted),o.push(...u.sedimented),this.syncSimulationState(s),r.length>0&&this.quiescence.reset(),this.accumulator+=l;let d=this.stepObserver(t,{spawned:r,evicted:n,sedimented:o,events:a,observations:s}),h=l>0?Math.floor((this.accumulator+1e-9*this.config.fixedDt)/this.config.fixedDt):0,{steps:p,budget:f}=Rf(this.settleHost(),Math.min(h,this.config.maxSubsteps),{spawned:r,evicted:n,sedimented:o,events:a,observations:s},{stopAtRest:!1,shouldStop:()=>this.paused||!this.visible,afterStep:d});this.accumulator=Math.max(0,this.accumulator-p*this.config.fixedDt),p===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(p>0||r.length>0||n.length>0||o.length>0||a.length>0)&&(this.revision+=1);let g=this.result(p,r,n,o,a,s,void 0,f??c);return this.updateResults.record({kind:"tick",count:p},this.revision!==i?r.length||n.length||o.length?pf:ff:[]),g}settle(e){return this.runSettle(e,!1).steps}settleWithObservations(e,t){return this.runSettle(e,!0,t)}stepObserver(e,t){let i=!this.observedInitialBoundary;return e&&(this.observedInitialBoundary=!0),function(e,t,i=!1){if(!e)return;let r=["spawned","evicted","sedimented","events","observations"],n={spawned:0,evicted:0,sedimented:0,events:0,observations:0},o=o=>{let a=t(o),s={...a};r.forEach(e=>{s[e]=a[e].slice(n[e]),n[e]=a[e].length}),(0!==o||i||!r.every(e=>0===s[e].length))&&e.onStep(s)};return o(0),()=>o(1)}(e,e=>(e&&(this.revision+=1),this.result(e,t.spawned,t.evicted,t.sedimented,t.events,t.observations)),i)}settleHost(e=!1){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length+Number(e?this.programs.backlog():this.programs.ownsClock()),atRest:()=>this.atRest(),elapsed:()=>this.elapsedSeconds,nextArrival:()=>this.queue.firstArrival(),lastArrival:()=>function(e,t,i){let r=e;for(let i of t)i.travel&&(r=Math.max(r,e+i.travel.durationSeconds-(i.travel.elapsedSeconds??0)));for(let e of i)r=Math.max(r,e.spawnAt+(e.travel?e.travel.durationSeconds-(e.travel.elapsedSeconds??0):0));return r}(this.elapsedSeconds,this.readBodies(),this.queue.sorted()),advanceTime:t=>{this.elapsedSeconds+=t;let i=this.programs.emitters?.advance(t,e);i?.length&&this.enqueue(i)},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>function(e,t,i){let r=t.filter(e=>"sleep"===e.type);if(0===r.length)return;let n=Mf(e,r.map(e=>e.bodyId));for(let e of r){let t=n(e.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t)),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t,i){let r=this.revision,n=[],o=[],a=[],s=[],l=t?[]:void 0;if(t&&(this.paused||!this.visible)){let e=this.result(0,n,o,a,s,l??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,l);let c=this.observeBodyBudget(l),u=this.evictOverflow(l);o.push(...u.evicted),a.push(...u.sedimented),this.syncSimulationState(l),n.length>0&&this.quiescence.reset();let d=t?{spawned:n,evicted:o,sedimented:a,events:s,observations:l}:{spawned:n},h=this.stepObserver(i,{spawned:n,evicted:o,sedimented:a,events:s,observations:l??[]}),{steps:p,budget:f}=Rf(this.settleHost(void 0===e),e??this.config.settleStepLimit,d,{afterStep:h,continueWhile:i?.continueWhile,shouldStop:t?()=>this.paused||!this.visible:void 0,drainArrivals:void 0===e,skipIdle:void 0===e&&!i&&!this.programs.pending()}),g=n.length+o.length+a.length>0;(p>0||g||s.length>0)&&(this.revision+=1);let m=this.result(p,n,o,a,s,l??[],void 0,f??c);return this.updateResults.record({kind:"settle",count:p},this.revision===r?[]:g?pf:ff),m}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return function(e,t={}){let{baselineY:i=0,binWidth:r=24,gap:n=2,maxHeight:o=80,value:a="count",x:s}=t,l=e.reduce((e,t)=>Math.max(e,t[a]),1);return e.map((e,t)=>{let c=Math.max(0,e[a]/l*o),u=s?.(e,t)??t*(r+n);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:u,y:i-c,width:r,height:c,meanX:e.x.mean,meanY:e.y.mean}})}(this.readSediment(),e)}hitTest(e,t,i=0,r){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,i,r)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()||this.programs.pending()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.size}elapsed(){return this.elapsedSeconds}recordObservation(e){let t=Hp(e,this.elapsedSeconds,this.observation);return this.emitObservation(t),this.updateResults.record({kind:"update",count:1},["evidence"]),t}recordLifecycleObservation(e){return this.updateResults.record({kind:"update",count:1},["evidence"]),Hp(e,this.elapsedSeconds,this.observation)}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){let t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?gf:[])}setVisible(e){let t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?gf:[])}remove(e){let t=new Set(e),i=new Set(this.liveBodyOrder),r=this.queue.remove(t);for(let t of e)this.liveBodyOrder.delete(t);this.world.remove(e),$f(this.activeSensorPairs,t);let n=e.filter(e=>i.has(e)||r.has(e));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?pf:[]),n}setConstraint(e){let t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},ff),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},ff)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},ff)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,i,r)=>e.applyImpulse(t,i,r),clear:()=>e.clear(),hitTest:(t,i,r)=>e.hitTest(t,i,r),pause:()=>e.setPaused(!0),push:(t,i)=>e.enqueue(t,i),pushMany:(t,i)=>e.enqueue(t,i),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}runtimeState(){return{elapsedSeconds:this.elapsedSeconds,timeScale:this.config.timeScale,fixedDt:this.config.fixedDt,paused:this.paused,visible:this.visible,simulationState:this.simulationState}}eventDropState(){return this.programs.eventDrop?{metadata:this.programs.eventDrop.metadata(),viewTransform:this.programs.eventDrop.viewTransform(),lifecycleEvents:[]}:void 0}viewTransform(){return this.programs.eventDrop?.viewTransform()??{...this.config.viewTransform}}isEventDropLive(){return!!this.programs.eventDrop}enqueueSequence(){return this.nextSequence}workerLiveDelta(){return this.programs.eventDrop?.drainWorkerDelta()}workerStructure(){return{world:this.world.snapshot(),queue:this.queue.sorted().map(ef),liveBodyOrder:Array.from(this.liveBodyOrder),sediment:this.readSediment()}}workerState(){return{...this.programs.emitters&&{emitterProgress:this.programs.emitters.progress()},nextSequence:this.nextSequence,accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs),elapsedSeconds:this.elapsedSeconds,paused:this.paused,revision:this.revision,simulationState:this.simulationState,visible:this.visible}}workerSleepTimes(e){return this.world.workerSleepTimes?.(e)}applyWorkerFrame(e){if(e.snapshot){let t=this.configInput;return this.restore(e.snapshot),void(this.configInput=t)}if(!e.state||!this.world.applyWorkerMotion)throw new Error("Physics worker motion frame requires a built-in mirror");e.structure?(this.world.restore(e.structure.world),this.queue.restore(e.structure.queue.map(ef)),this.liveBodyOrder=new Set(e.structure.liveBodyOrder),this.sediment.restore(e.structure.sediment),this.bodySpatialIndex=new df):(e.state.revision!==this.revision||e.state.elapsedSeconds!==this.elapsedSeconds)&&this.world.applyWorkerMotion(e),e.live&&this.programs.eventDrop?.applyWorkerDelta(e.live,this.world);let t=this.simulationState,{emitterProgress:i,...r}=e.state;i&&this.programs.emitters?.restoreProgress(i),Object.assign(this,r,{activeSensorPairs:new Set(e.state.activeSensorPairs)}),this.updateResults.record({kind:"tick"},ff),t!==this.simulationState&&this.observation.onSimulationStateChange?.(this.simulationState,t)}snapshot(){let e=this.world.snapshot();return{...this.workerState(),nextSequence:this.nextSequence,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:rf(this.bodyBudget),config:{...this.config,viewTransform:{...this.config.viewTransform},kernel:of(e.options)},queue:this.queue.sorted().map(ef),sediment:this.readSediment(),liveBodyOrder:Array.from(this.liveBodyOrder),world:e,...this.programs.snapshot()}}restore(e){!function(e){if(Bh(e.activeSensorPairs,"Physics activeSensorPairs"),Bh(e.liveBodyOrder,"Physics liveBodyOrder"),zh(e.queue,"Physics queue"),null!=e.sediment){zh(e.sediment,"Physics sediment");for(let t of e.sediment){if(!t)throw new RangeError("Physics sediment requires bin records");Bh(t.bodyIds,"Physics sediment.bodyIds"),Eh(t.count,"Physics sediment.count");for(let e of["x","y","value"]){let i=t[e];if(!i)throw new RangeError("Physics sediment requires statistics");for(let t of["count","total","mean","min","max","variance"])Eh(i[t],`Physics sediment.${e}.${t}`)}}}Vh(e.config),Gh(e.world);for(let t of e.queue)Yh(t),Eh(t.sequence,"Physics queue sequence");if(Eh(e.elapsedSeconds,"Physics elapsedSeconds"),Eh(e.accumulator,"Physics accumulator"),null!=e.nextSequence&&(!Number.isSafeInteger(e.nextSequence)||e.nextSequence<0||e.queue.some(t=>t.sequence>=e.nextSequence)))throw new RangeError("Physics nextSequence must exceed queued sequence numbers")}(e);let t=Lf.restore(e);this.bodySpatialIndex=new df,this.programs=t,this.observedInitialBoundary=!1;let i=this.simulationState;Object.assign(this,function(e){let t={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale,viewTransform:{...e.config.viewTransform??{x:0,y:0}}};return{config:t,configInput:hf({...t,bodyBudget:rf(e.bodyBudget??{}),kernel:of(e.world.options),...e.emitters&&{emitters:e.emitters.options},...e.eventDrop&&{eventDrop:e.eventDrop.config}}),bodyBudget:rf(e.bodyBudget??{}),activeSensorPairs:new Set(e.activeSensorPairs),accumulator:e.accumulator,elapsedSeconds:e.elapsedSeconds,paused:e.paused,revision:e.revision,visible:e.visible,liveBodyOrder:new Set(e.liveBodyOrder),nextSequence:e.nextSequence??e.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,simulationState:e.simulationState??_f(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping))}}(e)),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.queue.restore(e.queue.map(ef)),this.sediment.restore(e.sediment??[]),this.world.restore(e.world),this.updateResults.record({kind:"restore"},pf),this.simulationState!==i&&this.observation.onSimulationStateChange?.(this.simulationState,i)}spawnDue(e,t){for(;this.queue.length>0&&this.queue.firstArrival()<=this.elapsedSeconds+1e-9*this.config.fixedDt;){let i=this.queue.shift();if(!i)return;this.spawnOne(i,t),e.push(i.id)}if(this.programs.eventDrop){let e=this.programs.eventDrop.advance(this.world,this.elapsedSeconds);e.length&&this.remove(e);for(let e of this.programs.eventDrop.ledger.drainEvents())this.emitObservation(Hp(e,this.elapsedSeconds,this.observation),t)}}spawnOne(e,t){this.programs.eventDrop&&(e=this.programs.eventDrop.prepare(e,this.elapsedSeconds)),Yh(e),this.liveBodyOrder.delete(e.id)&&$f(this.activeSensorPairs,new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.add(e.id);for(let t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});!t&&!this.observation.onObservation||function(e,t,i){let r=Mf(e)(t.id);i.emit({type:"physics-spawn",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t.id,datum:r?.datum??t.datum,x:r?.x??t.x,y:r?.y??t.y})}(this.world,e,this.observationContext(t))}result(e,t,i,r,n,o,a,s=this.evaluateBodyBudget()){this.syncSimulationState(o);let l=this.world.allSleeping();return{budget:s,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:a??(!this.paused&&this.visible&&this.hasPendingWork()),sleeping:l,sedimented:r,spawned:t,steps:e}}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,i){let r=new Set(e.activeSensorPairs().map(e=>function(e,t){return`${e}\0${t}`}(e.sensorId,e.bodyId))),n=r.size!==t.size;if(!n)for(let e of r)if(!t.has(e)){n=!0;break}if(!n)return r;let o=Array.from(r).filter(e=>!t.has(e)).sort(),a=Array.from(t).filter(e=>!r.has(e)).sort(),s=Mf(e,[...o,...a].map(e=>sf(e).bodyId)),l=(e,t)=>{let{sensorId:r,bodyId:n}=sf(t),o=i.observation.sensors[r],a=s(n);i.emit({type:"enter"===e?o?.enterType??"physics-bin-enter":o?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:n,datum:a?.datum,x:a?.x,y:a?.y,sensorId:r,binId:o?.binId??r})};for(let e of o)l("enter",e);for(let e of a)l("exit",e);return r}(this.world,this.activeSensorPairs,this.observationContext(e))}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return function(e){let t=Math.max(0,Math.floor(e.liveBodies)),i=Math.max(0,Math.floor(e.queuedBodies??0)),r=t+i,n=Gp(e.bodyLimit),o=Gp(e.engineMaxBodiesHint),a=function(e,t,i){if(!1===i)return;let r=Gp(i?.warnAt);return null!=r?r:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(n,o,e.options),s=null==n?0:Math.max(0,t-n),l=s>0?"overflow":null!=a&&r>=a?"warning":"ok";return{action:"overflow"!==l?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:o,liveBodies:t,overflow:s,projectedBodies:r,queuedBodies:i,state:l,warnAt:a}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.size,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){let t=this.evaluateBodyBudget();return this.bodyBudgetObservationKey=function(e,t,i,r){if(!t||"ok"===e.state)return"ok";let n=`${e.state}:${e.action}`;return n!==i&&function(e,t){t.emit({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:t.elapsedSeconds,chartType:t.observation.chartType,chartId:t.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt})}(e,r),n}(t,!1!==this.bodyBudget,this.bodyBudgetObservationKey,this.observationContext(e)),t}syncSimulationState(e){let t=_f(this.paused,this.visible,this.queue.length>0||this.programs.pending(),this.atRest());if(t===this.simulationState)return;let i=this.simulationState;this.simulationState=t,function(e,t,i){i.observation.onSimulationStateChange?.(t,e),("running"===t||"settled"===t)&&i.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:t,previousSimulationState:e})}(i,t,this.observationContext(e))}evictOverflow(e){let{evicted:t,sedimented:i,liveBodyOrder:r}=function(e,t,i,r,n,o){let a={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===i)return a;let s=Math.max(0,Math.floor(r));if(!Number.isFinite(s))return a;let l=n.size-s;if(l<=0)return a;let c=function(e,t,i){if("sleeping-first"!==t)return Array.from(i);let r=new Map(e.readState().map(e=>[e.id,e.sleeping])),n=[],o=[];for(let e of i)r.get(e)?n.push(e):o.push(e);return[...n,...o]}(e,i,n).slice(0,l);if(0===c.length)return a;let u=function(e,t,i,r){if(!t.isEnabled())return[];let n=Mf(e,i),o=[];for(let e of i){let i=n(e);if(!i)continue;let a=t.add(i);a&&(o.push(e),r.emit({type:"physics-sediment",timestamp:r.elapsedSeconds,chartType:r.observation.chartType,chartId:r.observation.chartId,bodyId:e,datum:i.datum,x:i.x,y:i.y,binId:a.id,count:a.count,total:a.total}))}return o}(e,t,c,o);e.remove(c);let d=new Set(c);return{evicted:c,sedimented:u,liveBodyOrder:new Set(Array.from(n).filter(e=>!d.has(e)))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=r,$f(this.activeSensorPairs,new Set(t))),{evicted:t,sedimented:i}}};import{scaleLinear as Df}from"d3-scale";function Ff(e){return function(e,t,i=!1){let{data:r,timeAccessor:n,arrivalAccessor:o,windows:a,watermark:s,watermarkAtArrivalAccessor:l,ballRadius:c,seed:u,size:d,timeExtent:h,timeScale:p=1}=e,{events:f,watermarkValue:g,ledger:m,lifecycleEvents:y}=t??D({data:r,timeAccessor:n,arrivalAccessor:o,watermark:s,watermarkAtArrivalAccessor:l,sourceAccessor:e.sourceAccessor,sourceIds:e.sources?.map(e=>e.id),windowSize:a.size}),x=new Map(m.map(e=>[e.start,e])),b=J(d);if(e.sources?.some(e=>!1!==e.visible)&&"none"!==e.sourceRail?.side){let t=Math.max(48,e.sourceRail?.tileSize??80);"top"===e.sourceRail?.side?(b.plot.y+=t,b.plot.height=Math.max(1,b.plot.height-t)):("right"===e.sourceRail?.side||(b.plot.x+=t),b.plot.width=Math.max(1,b.plot.width-t))}let v=f.length?1/0:0,w=f.length?1/0:0,S=f.length?-1/0:a.size;for(let e of f)v=Math.min(v,e.arrivalTime),w=Math.min(w,e.eventTime),S=Math.max(S,e.eventTime);let k=e.timeUnit??(f.some(e=>Math.abs(e.eventTime)>1e5||Math.abs(e.arrivalTime)>1e5)?"ms":"s"),A="ms"===k?.001:1,M=re(h?.[0]),$=re(h?.[1]),_=i?M??w:Math.min(M??w,w),P=i?$??S:Math.max($??S,S),I=Math.floor(_/a.size)*a.size,T=Math.max(1,Math.ceil((P-I+a.size)/a.size)),L=function(e,t){let i=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:i,height:e.plot.height},windowPlot:{x:e.plot.x+i,y:e.plot.y,width:Math.max(40,e.plot.width-i),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(b,c),C=I+T*a.size,R=Df().domain([I,C]).range([L.windowPlot.x,L.windowPlot.x+L.windowPlot.width]),N=0,F=Array.from({length:T},(e,t)=>(I+(t+1)*a.size<=g&&N++,{value:0,secondary:0})),E=[];f.forEach(({datum:t,index:i,eventTime:r,arrivalTime:n,watermarkAtArrival:o,late:s})=>{let l=Math.max(0,Math.min(T-1,Math.floor((r-I)/a.size)));F[l].value+=s?0:1,F[l].secondary+=s?1:0,E.push({id:String(t.id??`event-${i}`),x:Of(r,l,s,{windowStart:I,windowSize:a.size,gutter:L.gutter,closedWindowCount:N,windowPlot:L.windowPlot,windowCount:T},c),y:b.plot.y+c+2,vx:0,vy:0,mass:1,friction:.02,spawnAt:n,shape:{type:"circle",radius:c},datum:{...t,eventTime:r,arrivalTime:n,windowIndex:l,windowId:`${I+l*a.size}-${I+(l+1)*a.size}`,source:String(ie(t,i,e.sourceAccessor??"source")??""),watermarkAtArrival:o,late:s}})});let O=b.plot.y+b.plot.height,z=b.plot.y+.28*b.plot.height,B={closedWindowCount:N,gutter:L.gutter,plot:b.plot,windowCount:T,windowPlot:L.windowPlot,windowSize:a.size,windowStart:I},j=function(e,t){let i=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!i)return[];let r=e.windowStart,n=e.windowStart+e.windowCount*e.windowSize,o=Df().domain([r,n]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),a=o(e.windowStart+i*e.windowSize),s=e.windowPlot.x,l=Math.max(18,Math.min(.3*e.windowPlot.height,a-s)),c=t+l,u=e=>a===s?t:c+(e-s)/(a-s)*(t-c),d=[];for(let t=0;t<i;t+=1){let i=e.windowStart+t*e.windowSize,r=i+e.windowSize,n=o(i),a=o(r);d.push({id:`eventdrop-lid-${t}`,windowIndex:t,x1:n,y1:u(n),x2:a,y2:u(a)})}return d}(B,z);for(let e of E){let t=e.datum;e.y=Ef({...B,lidSegments:j},t.windowIndex,t.late,c)}let W=function(e){let{count:t,idPrefix:i,wallThickness:r,xScale:n,yBottom:o,yTop:a,yTopForIndex:s}=e;return Array.from({length:t+1},(e,t)=>{let l=Math.min(o-1,s?.(t)??a),c=Math.max(1,o-l);return{id:`${i}-wall-${t}`,shape:{type:"aabb",x:n(t),y:l+c/2,width:r,height:c}}})}({idPrefix:"eventdrop-window",count:T,xScale:e=>R(I+e*a.size),yTop:L.wallTop,yTopForIndex:e=>{let t=(e=>{if(e<0||e>N)return null;let t=0===e?j[0]?.y1:j[e-1]?.y2??j[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?L.wallTop:t+1.25*c},yBottom:O,wallThickness:6}),Y=[...lf({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...W,...j.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*c)},friction:.02,restitution:.01}))];return function(e,t){let i=t.arrival;if(i&&"drop"!==i){if("travel"!==i.mode)throw new RangeError("arrival.mode must be travel");if(null!=i.history&&"present"!==i.history&&"travel"!==i.history)throw new RangeError("arrival.history must be present or travel");for(let e of[i.durationMs,i.speedPxPerSec])if(null!=e&&(!Number.isFinite(e)||e<=0))throw new RangeError("Travel duration and speed must be finite and positive");if(null!=i.durationMs&&null!=i.speedPxPerSec)throw new RangeError("Choose arrival.durationMs or arrival.speedPxPerSec");if(null!=i.path&&"function"!=typeof i.path&&"straight"!==i.path&&"connector"!==i.path)throw new RangeError("arrival.path must be straight, connector or a callback")}let r=new Map(Mh(t.sources,t.sourceRail,t.size).map(({source:e,x:t,y:i})=>[e.id,{x:t,y:i-6}])),n=Number.isFinite(t.timeScale)&&t.timeScale>0?t.timeScale:1,o=[];for(let a of e){let e=a.datum;i&&"drop"!==i&&(e.__phase=e.late?"late":"board");let s=e.windowIndex<t.closedWindowCount,l=(!i||"drop"===i||"travel"!==i.history)&&(s&&!e.late||!s&&e.late);l&&o.push(a);let c=(l?t.firstArrival:e.arrivalTime)*t.secondsPerUnit;a.__eventDropSpawnTime=c;let u=r.get(e.source);if(!i||"drop"===i||!u||l)continue;let d={x:a.x,y:a.y},h="function"==typeof i.path?i.path({...u},{...d}):"connector"===i.path?[u,{x:u.x,y:Math.min(u.y,d.y)-24},{x:d.x,y:Math.min(u.y,d.y)-24},d]:[u,d];if(Ch({points:h,durationSeconds:1}),h[0].x!==u.x||h[0].y!==u.y||h.at(-1).x!==d.x||h.at(-1).y!==d.y)throw new RangeError("Travel paths must start at the source and end at the board entry");let p=null!=i.speedPxPerSec?Math.max(1/120,Dh(h)/i.speedPxPerSec):(i.durationMs??800)/1e3;a.travel={points:h.map(e=>({...e})),durationSeconds:p/n,elapsedSeconds:0},a.x=u.x,a.y=u.y,a.__eventDropSpawnTime=c-p,e.__phase="travel"}if(i&&"drop"!==i&&null!=i.speedPxPerSec){let t=e.reduce((e,t)=>Math.max(e,t.travel?.durationSeconds??0),0);for(let i of e)i.travel&&(i.__eventDropSpawnTime+=(i.travel.durationSeconds-t)*n,i.travel.durationSeconds=t)}let a=e.reduce((e,t)=>Math.min(e,t.__eventDropSpawnTime),1/0);for(let e of o)e.__eventDropSpawnTime=a}(E,{...e,secondsPerUnit:A,timeScale:p,firstArrival:v,closedWindowCount:N}),{config:te(u,Y,"EventDropChart",{friction:.08}),initialSpawns:E,initialSpawnPacing:{pacing:"arrival",timeAccessor:"__eventDropSpawnTime",timeScale:p},projectionRows:F.map((e,t)=>({label:`${I+t*a.size}-${I+(t+1)*a.size}`,value:e.value,secondary:e.secondary,...x.get(I+t*a.size)})),metadata:{kind:"event-drop",closedWindowCount:N,gutter:L.gutter,lidSegments:j,lateCount:F.reduce((e,t)=>e+t.secondary,0),plot:b.plot,windowPlot:L.windowPlot,windowWalls:W.map(({id:e,shape:t})=>({id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height})),watermarkValue:g,windowCount:T,windowSize:a.size,windowStart:I,ledger:m,lifecycleEvents:y,timeUnit:k,eventTimeFrontier:f.length?S:0,arrivalFrontier:f.reduce((e,t)=>Math.max(e,t.arrivalTime),0)}}}(e)}function Ef(e,t,i,r){let{windowPlot:n,lidSegments:o}=e,a=o[t];return i&&!a?Math.min(n.y+n.height-r,n.y+.48*n.height+2*r+4):!i&&a?Math.min(n.y+n.height-r,Math.max(a.y1,a.y2)+2*r+4):n.y+r+2}function Of(e,t,i,r,n){let{windowPlot:o,windowCount:a,windowStart:s,windowSize:l}=r;if(i&&t>=r.closedWindowCount)return r.gutter.x+r.gutter.width/2;let c=o.width/a,u=i?o.x:o.x+t*c,d=i?o.x+o.width:u+c,h=Math.min((d-u)/2,n+(i?0:3)),p=o.x+(e-s)/l*c;return Math.max(u+h,Math.min(d-h,p))}function zf(e,t,i){let r=Math.max(1,t),n=e.width/r,o=Math.max(2,2*i),a=Math.min(.7*n,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(a/o));return{laneWidth:n,tubeWidth:a,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*n,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}import{scaleLinear as Bf}from"d3-scale";function jf(e,t,i,r){let n=(t+i)/2,o=[];for(let a of e){let s=o.filter(e=>Math.abs(a.x-e.x)<a.radius+e.radius+.5),l=[n];for(let e of s){let t=a.radius+e.radius+.5,i=Math.sqrt(t**2-(a.x-e.x)**2);l.push(e.y-i,e.y+i)}let c=r()<.5?-1:1;l.sort((e,t)=>Math.abs(e-n)-Math.abs(t-n)||c*(e-t));let u=l.find(e=>e-a.radius>=t&&e+a.radius<=i&&s.every(t=>(a.x-t.x)**2+(e-t.y)**2>=(a.radius+t.radius+.5)**2-1e-6));if(null==u){let r=e.reduce((e,t)=>Math.max(e,t.radius),-1/0),o=Math.max(0,i-t-2*r);return{positions:e.map((t,i)=>n+(1===e.length?0:i/(e.length-1)-.5)*o),overlapping:!0,entryOffset:0}}o.push({...a,y:u})}return{positions:o.map(e=>e.y),overlapping:!1,entryOffset:Math.max(0,o.reduce((e,i)=>Math.min(e,i.y-i.radius-t),36))}}function Wf(e){if(Array.isArray(e)&&e.length>=2){let t=re(e[0]),i=re(e[1]);return null!=t&&null!=i?{x:t,y:i}:null}if(e&&"object"==typeof e){let t=e,i=re(t.x),r=re(t.y);return null!=i&&null!=r?{x:i,y:r}:null}return null}function Yf(e){return Array.isArray(e)?e.map(Wf).filter(e=>null!=e):[]}function qf(e,t,i){return"normalized"===i?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:I(e.x,t.plot.x,t.plot.x+t.plot.width),y:I(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Xf(e){let t=0;for(let i=1;i<e.length;i+=1){let r=e[i].x-e[i-1].x,n=e[i].y-e[i-1].y;t+=Math.hypot(r,n)}return t}function Gf(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};let i=I(t,0,1)*Xf(e),r=0;for(let t=1;t<e.length;t+=1){let n=e[t-1],o=e[t],a=Math.hypot(o.x-n.x,o.y-n.y);if(!(a<=0)){if(r+a>=i){let e=(i-r)/a;return{x:n.x+(o.x-n.x)*e,y:n.y+(o.y-n.y)*e}}r+=a}}return{...e[e.length-1]}}function Vf(e,t){let i=Gf(e,Math.max(0,t-.02)),r=Gf(e,Math.min(1,t+.02)),n=r.x-i.x,o=r.y-i.y,a=Math.hypot(n,o)||1;return{x:n/a,y:o/a}}function Hf(e,t,i,r,n,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:i,x2:r,y2:n,thickness:o.thickness??8}}}function Uf(e,t,i,r){return{type:"aabb",x:e,y:t,width:i,height:r}}function Zf(e){let t=e.shape??"lane",i=Math.max(1,Math.round(e.width)),r=Math.max(1,Math.round(e.height)),n=e.padX??46,o=e.padY??72,a=n,s=i-n,l=o,c=r-Math.max(24,Math.round(.45*o)),u=(l+c)/2,d=Math.max(1,c-l),h=cl(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,g=cl(d*h+f,.06*d,.5*d),m=g/2,y=u-m,x=u+m,b=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,S=e.wallThickness??8,k=e.stages;if(!k.length)throw new Error("processStageLayout requires at least one stage");let A=cl(e.centerStageIndex??Math.floor(k.length/2),0,k.length-1),M=function(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(k),$=s-a,_=a,P=k.map((e,t)=>{let i=(e.share??1)/M*$,r=_,n=t===k.length-1?s:_+i;return _=n,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:r,x1:n,x:(r+n)/2,width:n-r,y:u,height:d}}),I=P[A],T=I.x0,L=I.x1,C=(e,i)=>{if("lane"===t)return"top"===i?l:c;if("funnel"===t){let t=cl((e-a)/Math.max(1,s-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=T){let t=cl((e-a)/Math.max(1,T-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=L)return"top"===i?y:x;let r=cl((e-L)/Math.max(1,s-L),0,1);return"top"===i?y+(l-y)*r:x+(c-x)*r},R=P.map(e=>{let t=Math.min(C(e.x0,"top"),C(e.x1,"top")),i=Math.max(C(e.x0,"bottom"),C(e.x1,"bottom"));return{...e,y:(t+i)/2,height:Math.max(1,i-t)}}),N={thickness:S,friction:v,restitution:w},D=[];"lane"===t?D.push(Hf(`${b}-top`,a,l,s,l,N),Hf(`${b}-bottom`,a,c,s,c,N),Hf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,S-2)}),Hf(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,S)})):"funnel"===t?D.push(Hf(`${b}-top`,a,l,s,y,N),Hf(`${b}-bottom`,a,c,s,x,N),Hf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,S-2)}),Hf(`${b}-right`,s,y,s,x,{...N,thickness:Math.max(6,S)})):D.push(Hf(`${b}-left-top`,a,l,T,y,N),Hf(`${b}-left-bottom`,a,c,T,x,N),Hf(`${b}-center-top`,T,y,L,y,N),Hf(`${b}-center-bottom`,T,x,L,x,N),Hf(`${b}-right-top`,L,y,s,l,N),Hf(`${b}-right-bottom`,L,x,s,c,N),Hf(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,S-2)}),Hf(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,S)}));let F=e.membraneDampingScale??.5,E=a,O=Math.max(1,("bowtie"===t?T:s)-E),z=(e.membranes??[]).map(e=>{let t=E+cl(e.offset,0,1)*O,i=e.width??18+18*e.cost,r=d-16,n=u+.25*(e.wobble??0);return{...e,x:t,y:n,width:i,height:r}}),B=!1===e.includeMembraneRegions?[]:z.map(e=>function(e){let t=e.dampingScale??.5,i=e.energyScale??1,r=cl(e.cost,0,2);return{...Qf(e,"membrane","membrane",{membraneCost:r}),damping:r*t,energyDelta:-r*i}}({id:e.id,label:e.label??e.id,description:e.description??`${e.label??e.id} is a permeable region. It taxes energy and damps velocity while bodies overlap it.`,x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??F,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:i,height:r,padX:n,padY:o,left:a,right:s,topY:l,bottomY:c,midY:u,centerLeft:T,centerRight:L,pinchHeight:g,pinchTop:y,pinchBottom:x,stages:R,membranes:z,colliders:D,regionEffects:B,boundaryY:C}}function Kf(e,t,i){return"function"==typeof t?r=>({...i,...t(r),primitive:e}):{...i,...t,primitive:e}}function Qf(e,t,i,r){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:Uf(e.x,e.y,e.width,e.height),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:i?Kf(i,e.attributes,r):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function Jf(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...Qf(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function eg(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}import{scaleLinear as tg}from"d3-scale";function ig(e,t,i){return Qt(e,t,i)}function rg(e,t){let i=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>i&&ri(i,e)||"#4e79a7":t=>{if(i){let e=ri(i,t);if(e)return e}let r=0;for(let e=0;e<t.length;e++)r=31*r+t.charCodeAt(e)|0;return e[Math.abs(r)%e.length]??"#4e79a7"}}function ng(e,t){let i=t.config??{},r=(t.sensors??[]).map(e=>({...e,sensor:!0})),n=[...t.colliders??[],...r],o=[...e.colliders??[],...i.colliders??[],...n];return{...e,...i,observation:{...e.observation,...i.observation},...o.length>0&&{colliders:o}}}function og(e){let t=dg(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function ag(e,t,i,r){return i?"function"==typeof i?i(e,t):e[i]??r:r}function sg(e){return`gauntlet:${e}:core`}function lg(e,t){return`gauntlet:${e}:positive:${t}`}function cg(e,t,i){return`gauntlet:${e}:negative:${t}:${i}`}lt.width,lt.height;var ug={left:28,top:76,rightInset:30,thickness:8};function dg(e){let t=e.height??e.floorY+36;if(!(e.width<220||t<160))return ug;let i=Math.max(1,Math.min(e.width,t)),r=Math.max(2,.04*e.width);return{left:r,top:Math.max(2,.08*t),rightInset:r,thickness:Math.max(1,Math.min(4,.04*i))}}function hg(e){let t=e.height??e.floorY+36;return Math.max(.12,Math.min(1,e.width/500,t/260))}function pg(e,t,i,r){let n=dg(r),o=Math.max(2,i+2),a=n.left+n.thickness/2+o,s=r.width-n.rightInset-n.thickness/2-o,l=n.top+n.thickness/2+o,c=r.floorY-o,u=(e,t,i)=>t<=i?Math.max(t,Math.min(i,e)):(t+i)/2;return{x:u(e,a,s),y:u(t,l,c)}}function fg(e,t,i=1){let r=[...e].sort((e,t)=>e.localeCompare(t)),n=Math.max(0,r.indexOf(t)),o=r.length>1?n/(r.length-1):.5;return{angle:.82*-Math.PI+o*Math.PI*.64,index:n,radius:(48+n%2*6)*i}}function gg(e,t,i){let r=e.activePositiveIds.reduce((e,i)=>e+(t.get(i)?.value??1),0),n=e.missingPositiveIds.length+e.poppedPositiveIds.length,o=e.negativeIds.reduce((e,t)=>e+(i.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*r-8*o-1.2*e.delay-5*n))}function mg(e){let t=function(e,t,i){let[r,n]=e,o=r<220||n<160,a=Math.round(.48*n),s=o?n-Math.max(3,Math.min(12,.1*n)):n-36,l=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,l.length),u=.22*r,d=c<=1?0:(.78*r-u)/(c-1),h=o?Math.max(Math.round(.12*r),.08*r+6):Math.max(Math.round(.14*r),110);return{crashY:s-(o?Math.min(i,Math.max(3,.22*n)):i),floorY:s,gates:l.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(o?8:54,Math.round(.07*r))})),graveyardX:Math.round(r*(o?.72:.84)),graveyardY:s-4,height:n,routeY:a,socketX:Math.round(r*(o?.82:.92)),startX:h,width:r}}(e.size??[900,520],e.gates,e.crashOffset??30),i=e.positiveProperties??[],r=new Map(i.map(e=>[e.id,e])),n=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),o={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},a=(e.data??[]).map((t,a)=>{let s=function(e,t,i,r,n){let o=String(ag(e,t,i.idAccessor,null!=e.id?String(e.id):`project-${t}`)),a=r.map(e=>e.id),s=[...ag(e,t,i.positiveAccessor,a)],l=[...ag(e,t,i.negativeAccessor,[])].filter(e=>n.has(e));return{id:o,activePositiveIds:s,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...ag(e,t,i.metricsAccessor,{})},missingPositiveIds:a.filter(e=>!s.includes(e)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(ag(e,t,i.startTimeAccessor,0))||0),stage:"project filed",viability:ag(e,t,i.initialViability,100)}}(t,a,o,i,n);return{...s,viability:e.viability?.(s,{negativeProperties:n,positiveProperties:r})??gg(s,r,n)}}),s=a.flatMap((i,o)=>{let a=function(e,t,i,r){let n=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(i),o=r?.(e,t,i)??{};return{...n,...o,startY:o.startY??o.routeY??n.startY,socketY:o.socketY??o.routeY??n.socketY,graveyardY:o.graveyardY??n.graveyardY}}(i,o,t,e.projectPlacement);return function(e,t,i,r,n,o,a){let s=hg(i),l=Math.max(3,28*s),c=r.startX,u=r.startY+(r.startY===i.routeY?38*t*s:0),d=a?.(e,t,i,r)??{},h=d.x??c,p=d.y??u,f={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...d,id:sg(e.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??e.startedAt,datum:f}],m=pg(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,i);g[0].x=m.x,g[0].y=m.y;for(let t of e.activePositiveIds){let r=n.get(t);if(!r)continue;let o=fg(e.activePositiveIds,t,s),a=r.radius??Math.max(2,10*s),l=pg(m.x+Math.cos(o.angle)*o.radius,m.y+Math.sin(o.angle)*o.radius,a,i);g.push({id:lg(e.id,t),x:l.x,y:l.y,vx:18*Math.cos(o.angle),vy:18*Math.sin(o.angle),mass:r.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:r,sourceDatum:e.datum},springs:!1===r.spring?[]:[{target:{type:"body",bodyId:sg(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+o.index%2*4)*s),...r.spring??{}}]})}return e.negativeIds.forEach((t,r)=>{let n=o.get(t);n&&g.push(function(e,t,i,r,n,o,a){let s=hg(o),l=t.radius??Math.max(2,7.2*s),c=pg(r+(i%4*12-12)*s,n+(54+12*Math.floor(i/4))*s,l,o);return{id:cg(e.id,t.id,i),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:a,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:sg(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+i%4*3)*s),...t.spring??{}}]}}(e,n,r,m.x,m.y,i,d.spawnAt??e.startedAt))}),g}(i,o,t,a,r,n,e.coreBody)});return{layout:t,states:a,initialSpawns:s,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:og(t)}}}function yg(e=[]){let t=Object.create(null);for(let[i,r]of e)t[i]=r;return t}function xg(...e){let t=yg();for(let i of e)for(let[e,r]of Object.entries(i??{}))t[e]=r;return t}function bg(e){return xg(e)}function vg(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function wg(e){let t=yg(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:bg(t.initialMetrics),metrics:bg(t.metrics),productIds:[...t.productIds],history:vg(t.history)}])),i=yg(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:bg(t.metrics),sourceIds:[...t.sourceIds],history:vg(t.history)}])),r=yg(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?bg(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:i,relations:r,input:{amount:e.input.amount,metrics:bg(e.input.metrics)},metrics:bg(e.metrics),loss:{amount:e.loss.amount,metrics:bg(e.loss.metrics)},history:vg(e.history)}}var Sg=1e-9;function kg(e,t){return e<t?-1:e>t?1:0}function Ag(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function Mg(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(kg)}function $g(e,t){return e?Object.entries(e).flatMap(([e,i])=>Number.isFinite(i)?[]:[Ag("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function _g(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}function Pg(e,t,i="selector"){let r=[],n=Object.values(e.components),o=new Set(n.map(e=>e.id)),a=(t.ids??[]).filter(e=>!o.has(e));if(a.length&&r.push(Ag("error","unknown-component",`Selector references unknown component id${1===a.length?"":"s"}: ${a.join(", ")}.`,`${i}.ids`,a)),void 0!==t.count&&(!Number.isInteger(t.count)||t.count<0)&&r.push(Ag("error","invalid-selector-count","Selector count must be a non-negative integer.",`${i}.count`)),r.some(e=>"error"===e.severity))return{ids:[],diagnostics:r};let s=t.ids?new Set(t.ids):null,l=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null,d=n.filter(e=>!s||s.has(e.id)).filter(e=>!l||l.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(kg);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||r.push(Ag("warning","empty-selector","Selector matched no source components.",i)),{ids:d,diagnostics:r}}function Ig(e,t,i={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...i}}function Tg(e,t){let i={...t,eventId:e.event.id};e.materializations.push(i),e.observations.push({...i,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function Lg(e,t,i){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(Ag("error","unknown-outlet",`Unknown outlet "${t}".`,i,[t])),1))}function Cg(e,t,i){let r=Mg(t);t.length||e.diagnostics.push(Ag("error","empty-source-list","A product requires at least one source component.",i)),r.length&&e.diagnostics.push(Ag("error","duplicate-source",`Source ids may appear only once: ${r.join(", ")}.`,i,r));let n=t.filter(t=>!e.state.components[t]);n.length&&e.diagnostics.push(Ag("error","unknown-component",`Unknown source component id${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n));let o=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);o.length&&e.diagnostics.push(Ag("error","source-already-assigned",`Source component${1===o.length?" is":"s are"} already assigned: ${o.join(", ")}.`,i,o));let a=t.filter(t=>"consumed"===e.state.components[t]?.status&&!o.includes(t));return a.length&&e.diagnostics.push(Ag("error","source-unavailable",`Consumed source component${1===a.length?" is":"s are"} unavailable: ${a.join(", ")}.`,i,a)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function Rg(e,t,i,r,n){let o=r?.amount??0;(!Number.isFinite(o)||o<0||o>t+Sg)&&e.diagnostics.push(Ag("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",`${n}.amount`)),e.diagnostics.push(...$g(r?.metrics,`${n}.metrics`));for(let[t,o]of Object.entries(r?.metrics??{}))(o<0||o>Number(i[t]??0)+Sg)&&e.diagnostics.push(Ag("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${n}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function Ng(e,t,i,r,n,o,a){let s=o&&void 0!==e.amount?e.amount:i;return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:s,metrics:o&&e.metrics?xg(r,e.metrics):bg(r),status:o?"complete":"forming",sourceIds:[...t],outletId:o?e.outletId??(n.outletIds.has("product")?"product":void 0):void 0,createdByEventId:n.event.id,createdAt:n.context.appliedAt,completedByEventId:o?n.event.id:void 0,completedAt:o?n.context.appliedAt:void 0,history:[a]}}function Dg(e,t,i,r){void 0!==t.amount&&Math.abs(t.amount-i)>Sg&&e.diagnostics.push(Ag("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${i}.`,r,[t.id]))}function Fg(e,t,i){let r=`events.${e.event.id}.effects.${i}`,n=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(Ag("error","invalid-component-state",`set-state cannot assign "${String(t.state)}".`,`${r}.state`)),e.diagnostics.push(...$g(t.metricsDelta,`${r}.metricsDelta`)),Lg(e,t.outletId,`${r}.outletId`);let i=Pg(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(Ag("error","source-already-assigned",`Assigned source components cannot be retargeted: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=Ig(e,t,{sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0});for(let e of i.ids){let i=n.components[e];i.status=t.state,i.outletId=t.outletId,i.reason=t.reason,t.metricsDelta&&_g(i.metrics,t.metricsDelta),i.history.push(a)}return n.history.push(a),void(i.ids.length&&Tg(e,{type:"retarget-component",sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){let{relation:i}=t;(!i.id||n.relations[i.id])&&e.diagnostics.push(Ag("error","duplicate-relation",`Relation id "${i.id}" is missing or already active.`,`${r}.relation.id`,[i.id]));let o=function(e,t,i){let r=Mg(t),n=t.filter(t=>!e.state.components[t]);return t.length<2&&e.diagnostics.push(Ag("error","insufficient-relation-sources","A relation requires at least two source components.",i)),r.length&&e.diagnostics.push(Ag("error","duplicate-source",`Relation source ids must be unique: ${r.join(", ")}.`,i,r)),n.length&&e.diagnostics.push(Ag("error","unknown-component",`Relation references unknown source component${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,i.sourceIds,`${r}.relation.sourceIds`);if(e.diagnostics.push(...$g(i.metrics,`${r}.relation.metrics`)),!o||e.diagnostics.some(e=>"error"===e.severity))return;n.relations[i.id]={...i,sourceIds:[...i.sourceIds],metrics:i.metrics?bg(i.metrics):void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};let a=Ig(e,t,{sourceIds:[...i.sourceIds],relationIds:[i.id]});return n.history.push(a),void Tg(e,{type:"activate-relation",sourceIds:[...i.sourceIds],relationIds:[i.id]})}if("resolve-relation"===t.type){let i=Mg(t.relationIds),o=t.relationIds.filter(e=>!n.relations[e]),a=t.relationIds.filter(e=>"resolved"===n.relations[e]?.status);if(i.length&&e.diagnostics.push(Ag("error","duplicate-relation","Relation ids must be unique.",`${r}.relationIds`,i)),o.length&&e.diagnostics.push(Ag("error","unknown-relation",`Unknown relation: ${o.join(", ")}.`,`${r}.relationIds`,o)),a.length&&e.diagnostics.push(Ag("error","resolved-relation",`Relation is already resolved: ${a.join(", ")}.`,`${r}.relationIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let i of t.relationIds){let r=n.relations[i];r.status="resolved",r.resolution=t.resolution,r.resolvedByEventId=e.event.id,r.resolvedAt=e.context.appliedAt,r.reason=t.reason}let s=Ig(e,t,{relationIds:[...t.relationIds]});return n.history.push(s),void Tg(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){let i=e.productDefinitions.get(t.productId);i||e.diagnostics.push(Ag("error","unknown-product",`Product "${t.productId}" has no declared mold.`,`${r}.productId`,[t.productId]));let o=n.products[t.productId];"combine"===t.type&&o&&e.diagnostics.push(Ag("error","duplicate-product",`Product "${t.productId}" has already been formed.`,`${r}.productId`,[t.productId])),"contribute"===t.type&&(!o||"forming"!==o.status)&&e.diagnostics.push(Ag("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,`${r}.productId`,[t.productId]));let a=Cg(e,t.sourceIds,`${r}.sourceIds`),s="contribute"===t.type&&o?[...o.sourceIds,...t.sourceIds]:t.sourceIds,l=function(e,t,i,r){if(!t?.length)return[];let n=Mg(t),o=t.filter(t=>!e.state.relations[t]),a=t.filter(t=>"resolved"===e.state.relations[t]?.status),s=new Set(i),l=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!s.has(e)));return n.length&&e.diagnostics.push(Ag("error","duplicate-relation","Basis relations must be unique.",r,n)),o.length&&e.diagnostics.push(Ag("error","unknown-relation",`Unknown basis relation: ${o.join(", ")}.`,r,o)),a.length&&e.diagnostics.push(Ag("error","resolved-relation",`Basis relation is already resolved: ${a.join(", ")}.`,r,a)),l.length&&e.diagnostics.push(Ag("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,r,l)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,s,`${r}.basisRelationIds`);if(!a||!l||!i||e.diagnostics.some(e=>"error"===e.severity))return;let c=a.reduce((e,t)=>e+t.amount,0),u=function(e){let t=yg();for(let i of e)_g(t,i.metrics);return t}(a);if(!Rg(e,c,u,t.loss,`${r}.loss`))return;let d=c-(t.loss?.amount??0);!function(e,t,i){e.state.loss.amount+=i?.amount??0;for(let[r,n]of Object.entries(i?.metrics??{}))t[r]=Number(t[r]??0)-n,e.state.loss.metrics[r]=Number(e.state.loss.metrics[r]??0)+n}(e,u,t.loss);let h,p="combine"===t.type&&!1!==t.complete,f=Ig(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});if("combine"===t.type){if(p&&Dg(e,i,d,`${r}.productId`),h=Ng(i,t.sourceIds,d,u,e,p,f),p&&!Lg(e,h.outletId,`${r}.productId`))return;n.products[t.productId]=h}else h=o,h.sourceIds.push(...t.sourceIds),h.amount+=d,_g(h.metrics,u),h.history.push(f);for(let e of a)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(f);return n.history.push(f),function(e,t){if(t.length){for(let i of t)i.status="resolved",i.resolution="combined",i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt;Tg(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,l),Tg(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:h.outletId?[h.outletId]:void 0}),void(p&&Tg(e,{type:"complete-product",sourceIds:[...h.sourceIds],productIds:[h.id],outletIds:h.outletId?[h.outletId]:void 0}))}if("complete-product"===t.type){let i=n.products[t.productId];return i?void function(e,t,i,r,n,o){let a=e.productDefinitions.get(t.id),s=i??a?.outletId??(e.outletIds.has("product")?"product":void 0);if(!Lg(e,s,`${o}.outletId`))return;if("complete"===t.status)return void e.diagnostics.push(Ag("error","product-already-complete",`Product "${t.id}" is already complete.`,o,[t.id]));a&&(Dg(e,a,t.amount,`${o}.productId`),void 0!==a.amount&&(t.amount=a.amount),a.metrics&&(t.metrics=xg(t.metrics,a.metrics))),t.status="complete",t.outletId=s,t.reason=r,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;let l=Ig(e,n,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0});t.history.push(l),e.state.history.push(l),Tg(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0})}(e,i,t.outletId,t.reason,t,r):void e.diagnostics.push(Ag("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,`${r}.productId`,[t.productId]))}if("split"===t.type){let i=Cg(e,[t.sourceId],`${r}.sourceId`);t.products.length||e.diagnostics.push(Ag("error","empty-split","A split requires at least one product allocation.",`${r}.products`));let o=t.products.map(e=>e.productId),a=Mg(o);a.length&&e.diagnostics.push(Ag("error","duplicate-product","Split product ids must be unique.",`${r}.products`,a));let s=o.map(t=>e.productDefinitions.get(t)),l=o.filter((e,t)=>!s[t]),c=o.filter(e=>n.products[e]);l.length&&e.diagnostics.push(Ag("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,`${r}.products`,l)),c.length&&e.diagnostics.push(Ag("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,`${r}.products`,c));for(let[i,n]of t.products.entries())void 0!==n.amount&&(!Number.isFinite(n.amount)||n.amount<0)&&e.diagnostics.push(Ag("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${r}.products.${i}.amount`)),e.diagnostics.push(...$g(n.metrics,`${r}.products.${i}.metrics`));if(!i?.length||e.diagnostics.some(e=>"error"===e.severity))return;let u=i[0];if(!Rg(e,u.amount,u.metrics,t.loss,`${r}.loss`))return;let d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??s[t]?.amount),p=h.filter(e=>void 0!==e).length;if(0!==p&&p!==h.length)return void e.diagnostics.push(Ag("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",`${r}.products`));let f=p?h:t.products.map(()=>d/t.products.length),g=f.reduce((e,t)=>e+t,0);if(Math.abs(g-d)>Sg)return void e.diagnostics.push(Ag("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,`${r}.products`));let m=bg(u.metrics);for(let[e,i]of Object.entries(t.loss?.metrics??{}))m[e]=Number(m[e]??0)-i;let y=Ig(e,t,{sourceIds:[u.id],productIds:o});if(t.products.forEach((i,o)=>{let a=s[o],l=d>Sg?f[o]/d:1/t.products.length,c=yg(Object.entries(m).map(([e,t])=>[e,t*l])),h=i.metrics??a.metrics??c,p=Ng({...a,amount:f[o],metrics:h},[u.id],f[o],bg(h),e,!0,y);Lg(e,p.outletId,`${r}.products.${o}.productId`)&&(n.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=o,u.status="consumed",u.outletId=void 0,u.history.push(y),n.loss.amount+=t.loss?.amount??0;for(let[e,i]of Object.entries(t.loss?.metrics??{}))n.loss.metrics[e]=Number(n.loss.metrics[e]??0)+i;n.history.push(y),Tg(e,{type:"split-source",sourceIds:[u.id],productIds:o});for(let t of o)Tg(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:n.products[t].outletId?[n.products[t].outletId]:void 0});return}if("eject"===t.type){Lg(e,t.outletId,`${r}.outletId`);let i=Pg(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(Ag("error","source-already-assigned",`Assigned source components cannot be ejected: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=Ig(e,t,{sourceIds:i.ids,outletIds:[t.outletId]});for(let e of i.ids){let i=n.components[e];i.status=t.state??"ejected",i.outletId=t.outletId,i.reason=t.reason,i.history.push(a)}return n.history.push(a),void(i.ids.length&&Tg(e,{type:"retarget-component",sourceIds:i.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...$g(t.metricsDelta,`${r}.metricsDelta`)),e.diagnostics.some(e=>"error"===e.severity))return;let i,o;if("run"===t.target)_g(n.metrics,t.metricsDelta);else if("components"in t.target){let o=Pg(n,t.target.components,`${r}.target.components`);if(e.diagnostics.push(...o.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;i=o.ids;for(let e of o.ids)_g(n.components[e].metrics,t.metricsDelta)}else{o=[...t.target.productIds];let i=Mg(o),a=o.filter(e=>!n.products[e]);if(i.length&&e.diagnostics.push(Ag("error","duplicate-product","Metric target product ids must be unique.",`${r}.target.productIds`,i)),a.length&&e.diagnostics.push(Ag("error","unknown-product-state",`Metric target product has not formed: ${a.join(", ")}.`,`${r}.target.productIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let e of o)_g(n.products[e].metrics,t.metricsDelta)}return void n.history.push(Ig(e,t,{sourceIds:i,productIds:o}))}t.outcome.trim()?(n.outcome=t.outcome,n.summary=t.summary,n.history.push(Ig(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(Ag("error","invalid-outcome","Outcome must be a non-empty string.",`${r}.outcome`))}function Eg(e,t,i){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[Ag("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,`events.${t.id}`,[t.id])]};let r=wg(e),n={state:r,event:t,context:i,productDefinitions:new Map(i.products.map(e=>[e.id,e])),outletIds:new Set(i.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(let[i,r]of t.effects.entries())if(Fg(n,r,i),n.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:n.diagnostics};return r.elapsed=Math.max(r.elapsed,i.appliedAt),r.phaseId=i.phaseId,r.eventsApplied.push(t.id),n.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:i.phaseId,authoredAt:i.authoredAt,appliedAt:i.appliedAt}),{applied:!0,state:r,materializations:n.materializations,observations:n.observations,diagnostics:n.diagnostics}}var Og=ct.width,zg=ct.height,Bg=[Og,zg],jg=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Wg=/*#__PURE__*/new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Yg=1e-9;function qg(e,t){return e<t?-1:e>t?1:0}function Xg(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function Gg(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(qg)}function Vg(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Hg(e,t,i,r,n,o){if(!i)return r;try{return("function"==typeof i?i(e,t):e[i])??r}catch(e){return n.push(Xg("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:String(e)}.`,o)),r}}function Ug(e,t,i){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(Xg("error","invalid-metrics","Metrics must be a numeric object.",i)),yg();let r=yg();for(let[n,o]of Object.entries(e)){let e=Vg(o);null!=e?r[n]=e:t.push(Xg("error","invalid-metric",`Metric "${n}" must be finite.`,`${i}.${n}`))}return r}function Zg(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Kg(e){let{id:t,orientation:i,fixed:r,start:n,end:o,openings:a,thickness:s,friction:l,restitution:c}=e,u=function(e,t,i){let r=i.map(([i,r])=>[Math.max(e,Math.min(i,r)),Math.min(t,Math.max(i,r))]).filter(([e,t])=>t>e+Yg).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),n=[],o=e;for(let[e,t]of r)e>o+Yg&&n.push([o,e]),o=Math.max(o,t);return t>o+Yg&&n.push([o,t]),n}(n,o,a);return u.map(([e,n],o)=>({id:1===u.length?t:`${t}:${o}`,friction:l,restitution:c,shape:"horizontal"===i?{type:"segment",x1:e,y1:r,x2:n,y2:r,thickness:s}:{type:"segment",x1:r,y1:e,x2:r,y2:n,thickness:s}}))}function Qg(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?v(e):1}function Jg(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:Qg(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function em(e){return`crucible:component:${encodeURIComponent(e)}`}function tm(e){return`crucible:product:${encodeURIComponent(e)}`}function im(e,t,i,r){if(void 0!==i&&Number.isFinite(i)&&i>0)return i;let[n,o]=t;if(o-n<=Yg)return(r[0]+r[1])/2;let a=Math.sqrt(Math.max(0,e-n)/(o-n));return r[0]+(r[1]-r[0])*a}function rm(e,t){let i=Math.max(.25,Math.min(1,t.width/900,t.height/520)),r=e?.[0]??7*i,n=e?.[1]??18*i,o=Math.max(1,Math.min(r,n));return[o,Math.max(o,Math.max(r,n))]}function nm(e,t){if(!e)return[];let i=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),r=Math.max(1,Math.ceil(e/i));return Array.from({length:e},(e,n)=>({x:t.x+(n%i+.5)*(t.width/i),y:t.y+(Math.floor(n/i)+.5)*(t.height/r)}))}function om(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function am(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function sm(e,t,i={}){let r=Object.values(e.products).sort((e,t)=>qg(e.id,t.id)),n=Object.values(e.components).sort((e,t)=>qg(e.id,t.id)),o=ue([...n.map(e=>e.amount),...r.map(e=>e.amount)]),a=rm(i.radiusRange,t),s=function(e,t){let i=new Map;for(let t of e){let e=t.outletId??"__chamber__",r=i.get(e)??[];r.push(t),i.set(e,r)}let r=new Map;for(let[e,n]of i){n.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||qg(e.id,t.id));let i=nm(n.length,am(t,"__chamber__"===e?void 0:e));n.forEach((e,t)=>r.set(e.id,i[t]))}return r}(r,t),l=r.map(e=>{let r=s.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},n=1.28*im(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:tm(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.018),bodyCollisions:!1,shape:{type:"circle",radius:n},datum:l}}),c=new Map;for(let e of n.filter(e=>!e.productIds.length)){let t=om(e)??"__chamber__",i=c.get(t)??[];i.push(e),c.set(t,i)}let u=new Map;for(let[e,i]of c){let r=nm(i.length,am(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>u.set(e.id,r[t]))}return[...n.map(e=>{let r=u.get(e.id);if(e.productIds.length){let i=e.productIds.map(e=>s.get(e)).filter(e=>!!e);if(i.length){r={x:i.reduce((e,t)=>e+t.x,0)/i.length,y:i.reduce((e,t)=>e+t.y,0)/i.length};let n=v(e.id)/4294967295*Math.PI*2,o=Math.min(20,Math.max(4,.012*t.width));r={x:r.x+Math.cos(n)*o,y:r.y+Math.sin(n)*o}}}r??(r={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});let n=im(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:em(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.015),shape:{type:"circle",radius:n},datum:l}}),...l]}var lm=sm;function cm(e){return Array.isArray(e)?e.map(cm):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>qg(e,t)).map(([e,t])=>[e,cm(t)])):e}function um(e,t=e.duration){let i=function(e,t){let i=Vg(t)??0,r=Math.max(0,Math.min(e.duration,i));if(!e.phases.length)return{elapsed:r,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};let n=r>=e.duration-Yg,o=n?e.phases[e.phases.length-1]:e.phases.find(e=>r>=e.start&&r<e.end)??e.phases[0];return{elapsed:r,phaseId:o.id,phaseIndex:o.index,phaseElapsed:n?o.duration:Math.max(0,r-o.start),complete:n}}(e,t),r=wg(e.initialState),n=[],o=[],a=[];for(let t of e.events){if(t.authoredAt>i.elapsed+Yg)break;let s=Eg(r,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});n.push(...s.diagnostics),o.push(...s.materializations),a.push(...s.observations),s.applied&&(r=s.state)}return r.elapsed=i.elapsed,r.phaseId=i.phaseId,r.phaseIndex=i.phaseIndex,r.phaseElapsed=i.phaseElapsed,r.complete=i.complete,i.complete&&"in_process"===r.outcome&&(r.outcome="complete"),r.playing=!1,{state:r,diagnostics:n,materializations:o,observations:a}}function dm(e){let t=function(e){let t=[];e.length||t.push(Xg("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));let i=Gg(e.map(e=>e.id));i.length&&t.push(Xg("error","duplicate-phase-id",`Phase ids must be unique: ${i.join(", ")}.`,"phases",i));let r=0;return{phases:e.map((e,i)=>{let n=Vg(e.duration),o=null!=n&&n>0?n:0;e.id.trim()||t.push(Xg("error","invalid-phase-id","Phase ids may not be empty.",`phases.${i}.id`)),(null==n||n<=0)&&t.push(Xg("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${i}.duration`,[e.id])),void 0!==e.intensity&&!Number.isFinite(e.intensity)&&t.push(Xg("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${i}.intensity`,[e.id]));let a={...e,duration:o,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:i,start:r,end:r+o};return r=a.end,a}),diagnostics:t}}(e.phases),i=t.phases.at(-1)?.end??0,r=Zg(e.outlets??jg),n=(e.products??[]).map(e=>({...e,metrics:e.metrics?xg(e.metrics):void 0})),o=function(e,t,i){let r=[],n=Gg(e.map(e=>e.id));n.length&&r.push(Xg("error","duplicate-event-id",`Event ids must be unique: ${n.join(", ")}.`,"events",n));let o=[];return e.forEach((e,n)=>{let a,s,l;if(e.id.trim()||r.push(Xg("error","invalid-event-id","Event ids may not be empty.",`events.${n}.id`)),"time"in e.at&&void 0!==e.at.time){let o=Vg(e.at.time);if(null==o||o<0||o>i+Yg)return void r.push(Xg("error","event-time-out-of-range",`Event time must fall between 0 and ${i}.`,`events.${n}.at.time`,[e.id]));a=Math.max(0,Math.min(i,o));let c=function(e,t,i){let r=e.find(e=>Math.abs(e.start-i)<=Yg);if(r)return{phase:r,boundaryRank:1};let n=e.find(e=>i>=e.start&&i<e.end);return n?{phase:n,boundaryRank:0}:Math.abs(i-t)<=Yg&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,i,a);s=c.phase,l=c.boundaryRank}else{if(s=t.find(t=>t.id===e.at.phaseId),!s)return void r.push(Xg("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${n}.at.phaseId`,[e.id,e.at.phaseId]));let i=e.at.progress??0;if(!Number.isFinite(i)||i<0||i>1)return void r.push(Xg("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${n}.at.progress`,[e.id]));a=s.start+s.duration*i,l=0===i?1:0}s?o.push({...e,index:n,authoredAt:a,phaseId:s.id,phaseIndex:s.index,boundaryRank:l}):r.push(Xg("error","event-without-phase","Event could not be assigned to a phase.",`events.${n}.at`,[e.id]))}),o.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:o,diagnostics:r}}(e.events??[],t.phases,i),a=function(e){let t=[],i=yg(),r=[],n=0,o=yg();e.data.forEach((a,s)=>{let l=String(a.id??`component-${s}`),c=Hg(a,s,e.idAccessor,l,t,`data.${s}.id`),u=String(c??l).trim();if(!u)return void t.push(Xg("error","invalid-component-id","Component ids may not be empty.",`data.${s}.id`));r.push(u);let d=Vg(Hg(a,s,e.amountAccessor,1,t,`data.${s}.amount`)),h=null!=d&&d>=0?d:0;(null==d||d<0)&&t.push(Xg("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${s}.amount`,[u]));let p=Ug(Hg(a,s,e.metricsAccessor,{},t,`data.${s}.metrics`),t,`data.${s}.metrics`),f=Hg(a,s,e.initialStateAccessor,"active",t,`data.${s}.status`),g=Wg.has(f)?f:"active";Wg.has(f)||t.push(Xg("error","invalid-component-status",`Unknown component status "${String(f)}".`,`data.${s}.status`,[u]));let m=String(Hg(a,s,e.labelAccessor,String(a.label??a.name??u),t,`data.${s}.label`)),y=String(Hg(a,s,e.categoryAccessor,"component",t,`data.${s}.category`));Object.hasOwn(i,u)||(i[u]={id:u,label:m,category:y,datum:a,status:g,initialAmount:h,amount:h,initialMetrics:xg(p),metrics:xg(p),productIds:[],history:[]},n+=h,function(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}(o,p))});let a=Gg(r);a.length&&t.push(Xg("error","duplicate-component-id",`Component ids must be unique: ${a.join(", ")}.`,"data",a));let s=Ug(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:i,products:yg(),relations:yg(),input:{amount:n,metrics:o},metrics:s,loss:{amount:0,metrics:yg()},history:[]},diagnostics:t}}(e),s=function(e=Bg,t=jg){let i=Math.max(1,Vg(e[0])??Og),r=Math.max(1,Vg(e[1])??zg),n=i<360||r<260,o=n?Math.max(4,.035*Math.min(i,r)):20,a=n?Math.max(10,.075*r):34,s={x:o,y:o,width:Math.max(1,i-2*o),height:a},l=n?Math.max(16,.14*r):Math.min(78,.16*r),c={x:o,y:r-o-l,width:Math.max(1,i-2*o),height:l},u=n?Math.max(12,.08*i):Math.min(150,.17*i),d=s.y+s.height+(n?12:38),h=c.y-(n?10:34),p={x:u,y:d,width:Math.max(24,i-2*u),height:Math.max(24,h-d)},f=Math.max(18,Math.min(.32*p.width,n?84:180)),g={x:p.x+(p.width-f)/2,y:p.y-(n?10:24),width:f,height:n?12:28},m=Zg(t),y={left:m.filter(e=>"left"===(e.side??"bottom")),right:m.filter(e=>"right"===e.side),bottom:m.filter(e=>"bottom"===(e.side??"bottom"))},x=[],b=(e,t)=>{let r=Math.max(8,u-1.5*o),a=p.height/Math.max(1,t.length);t.forEach((t,s)=>{x.push({...t,side:e,x:"left"===e?o:i-o-r,y:p.y+s*a,width:r,height:Math.max(8,a-(n?2:8))})})};b("left",y.left),b("right",y.right);let v=p.width/Math.max(1,y.bottom.length);return y.bottom.forEach((e,t)=>{x.push({...e,side:"bottom",x:p.x+t*v,y:p.y+p.height+(n?2:7),width:Math.max(8,v-(n?2:8)),height:Math.max(8,c.y-p.y-p.height-(n?4:12))})}),x.sort((e,t)=>m.findIndex(t=>t.id===e.id)-m.findIndex(e=>e.id===t.id)),{width:i,height:r,phaseRail:s,chamber:p,mouth:g,projection:c,outlets:x}}(e.size??Bg,r),l=function(e){let{chamber:t,mouth:i}=e,r=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),n=Math.max(t.x,i.x),o=Math.min(t.x+t.width,i.x+i.width),a={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},s=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:n,y2:t.y,thickness:r}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:o,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:r}}];s.push(...Kg({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:a.left.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Kg({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:a.right.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Kg({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:a.bottom.map(e=>[e.x,e.x+e.width]),thickness:r,friction:.5,restitution:.08}));for(let t of e.outlets)s.push({id:`crucible:outlet:${encodeURIComponent(t.id)}`,sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return s}(s),c=function(e,t){let i=[],r=new Set(t.map(e=>e.id)),n=Gg(t.map(e=>e.id)),o=Gg(e.map(e=>e.id));return n.length&&i.push(Xg("error","duplicate-outlet-id",`Outlet ids must be unique: ${n.join(", ")}.`,"outlets",n)),o.length&&i.push(Xg("error","duplicate-product-id",`Product ids must be unique: ${o.join(", ")}.`,"products",o)),t.forEach((e,t)=>{e.id.trim()||i.push(Xg("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0!==e.order&&!Number.isFinite(e.order)&&i.push(Xg("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||i.push(Xg("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0!==e.amount&&(!Number.isFinite(e.amount)||e.amount<0)&&i.push(Xg("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0!==e.outletId&&!r.has(e.outletId)&&i.push(Xg("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Ug(e.metrics??{},i,`products.${t}.metrics`)}),i}(n,r),u=function(e){return JSON.stringify(cm(e))}({seed:e.seed??1,components:Object.values(a.state.components).sort((e,t)=>qg(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})=>({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})),products:n,outlets:r,events:o.events.map(({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s})=>({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s}))}),d=function(e,t,i={}){let r=Object.values(e.components).sort((e,t)=>qg(e.id,t.id)),n=ue(r.map(e=>e.amount)),o=rm(i.radiusRange,t),a=Q(Qg(i.seed)),s=t.mouth.x+t.mouth.width/2,l=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return r.map((e,t)=>{let d=t/Math.max(1,r.length)*Math.PI*2+.18*(a()-.5),h=im(e.amount,n,i.bodyRadius,o),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:em(e.id),x:s+Math.cos(d)*c*(.45+.45*a()),y:l+Math.sin(d)*u*(.45+.45*a()),vx:24*(a()-.5),vy:18*(a()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(a.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),h=[...t.diagnostics,...o.diagnostics,...a.diagnostics,...c],p={phases:t.phases,events:o.events,products:n,outlets:r,duration:i,initialState:a.state,terminalState:a.state,layout:s,colliders:l,config:Jg(e.seed,l),initialSpawns:d,terminalSpawns:[],semanticKey:u,diagnostics:h},f=um(p),g=Object.values(f.state.products).filter(e=>"forming"===e.status).map(e=>e.id),m=g.length?[Xg("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=f.state,p.terminalSpawns=lm(f.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p.diagnostics=[...h,...f.diagnostics,...m],p}import*as hm from"react";import{jsx as pm,jsxs as fm}from"react/jsx-runtime";function gm(e){return Number.isFinite(e)?Math.abs(e)>=1e3?e.toLocaleString():Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):"0"}function mm(e,t,i,r){let n=e.datum;if(!n?.__crucible)return;let o="circle"===e.shape.type?e.shape.radius:8,a="string"==typeof t.fill?t.fill:"product"===n.kind?"#b8792d":"#356b63",s="string"==typeof t.stroke?t.stroke:"#26323a",l="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=r?`${r}-crucible-body-${i}`:`crucible-body-${i}`;if("product"===n.kind){let t=Array.from({length:6},(t,i)=>{let r=-Math.PI/2+i/6*Math.PI*2;return`${e.x+Math.cos(r)*o},${e.y+Math.sin(r)*o}`}).join(" "),i=`${u}-glow`;return fm(hm.Fragment,{children:[pm("defs",{children:pm("filter",{id:i,x:"-60%",y:"-60%",width:"220%",height:"220%",children:pm("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:a,floodOpacity:"0.8"})})}),pm("polygon",{points:t,fill:a,stroke:s,strokeWidth:l,opacity:c,filter:`url(#${i})`}),pm("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*o),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return fm(hm.Fragment,{children:[pm("circle",{cx:e.x,cy:e.y,r:o,fill:a,stroke:s,strokeWidth:l,opacity:c}),pm("circle",{cx:e.x-.25*o,cy:e.y-.28*o,r:Math.max(1,.18*o),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as ym,jsx as xm,jsxs as bm}from"react/jsx-runtime";var vm="var(--semiotic-text, #26323a)",wm="var(--semiotic-text-secondary, #6c7377)",Sm="var(--semiotic-primary, #b8792d)",km="var(--semiotic-danger, #9f3d35)",Am="var(--semiotic-success, #356b63)";function Mm(e){let{x:t,y:i,width:r,height:n}=e.chamber,o=Math.min(.14*r,48),a=i+n;return[`M ${t} ${i}`,`L ${t+o} ${a-.16*n}`,`Q ${t+r/2} ${a+.1*n} ${t+r-o} ${a-.16*n}`,`L ${t+r} ${i}`].join(" ")}function $m({layout:e,phases:t,state:i,compact:r=!1}){let n=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return bm("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[bm("defs",{children:[bm("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[xm("stop",{offset:"0",stopColor:Sm,stopOpacity:"0.03"}),xm("stop",{offset:"0.66",stopColor:Sm,stopOpacity:"0.1"}),xm("stop",{offset:"1",stopColor:km,stopOpacity:"0.18"})]}),xm("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:xm("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:vm,strokeOpacity:"0.08",strokeWidth:"1"})})]}),xm("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:vm,strokeOpacity:"0.52",strokeWidth:r?1:2.2}),xm("path",{d:Mm(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),xm("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:vm,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:r?2:5}),r?null:xm("g",{"data-testid":"crucible-phase-rail",children:t.map((r,o)=>{let a=t.slice(0,o).reduce((e,t)=>e+Math.max(0,t.duration),0),s=e.phaseRail.x+a/n*e.phaseRail.width,l=Math.max(0,r.duration)/n*e.phaseRail.width,c=r.id===i.phaseId,u=i.phaseIndex>o||i.complete;return bm("g",{children:[xm("rect",{x:s,y:e.phaseRail.y,width:Math.max(1,l-2),height:e.phaseRail.height,rx:2,fill:c?r.color??Sm:u?Am:vm,fillOpacity:c?.68:u?.28:.09}),l>=46?xm("text",{x:s+l/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?vm:wm,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(r.label??r.id).toUpperCase()}):null]},r.id)})}),e.outlets.map(e=>bm("g",{children:[xm("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?km:Am),fillOpacity:"0.1",stroke:e.color??("left"===e.side?km:Am),strokeDasharray:"3 3",strokeOpacity:"0.62"}),r?null:xm("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:wm,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function _m({rows:e,layout:t,projection:i,amountLabel:r}){if(!e.length)return null;let n=i.measure??"count",o=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,n))),a=o.reduce((e,t)=>Math.max(e,t),1),s=t.projection.width/Math.max(1,e.length),l=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-l-5);return xm("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,i)=>{let u=o[i],d=Math.max(u>0?2:0,u/a*c),h=t.projection.x+i*s+.18*s,p=t.projection.y+c-d;return bm("g",{children:[xm("rect",{x:h,y:p,width:Math.max(3,.64*s),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?km:"complete"===e.status?Sm:Am,fillOpacity:"0.68"}),l>4&&s>=34?bm(ym,{children:[xm("text",{x:h+.32*s,y:t.projection.y+c+10,fill:wm,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?`${e.label.slice(0,12)}…`:e.label}),bm("text",{x:h+.32*s,y:t.projection.y+c+19,fill:vm,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[gm(u),"amount"===n&&r?` ${r}`:""]})]}):null]},e.key)})})}function Pm(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}import{Fragment as Im,jsx as Tm,jsxs as Lm}from"react/jsx-runtime";function Cm(e,t,i,r,n){let o=Array.isArray(n)?n:n?[n]:[];if(!1!==i||0!==o.length)return({size:n})=>{let a=[Number(n[0])||700,Number(n[1])||420],s=J(a),l=Math.max(2,Math.round(t)),c=s.plot.width/l,u=s.plot.y+s.plot.height,d=e.reduce((e,t)=>Math.max(e,t.value),1),h=!1!==i,[p,f]=r?.valueExtent??[0,l],g=f===p?1:f-p,m=e.map((e,t)=>{let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;return`${0===t?"M":"L"} ${i.toFixed(1)} ${r.toFixed(1)}`}).join(" ");return Lm("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:a[0],height:a[1],viewBox:`0 0 ${a[0]} ${a[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?Lm(Im,{children:[Array.from({length:l+1},(e,t)=>{let i=s.plot.x+t*c;return Tm("line",{"data-testid":"galton-board-bin-wall",x1:i,x2:i,y1:s.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},`bin-wall-${t}`)}),Tm("line",{x1:s.plot.x,x2:s.plot.x+s.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),Tm("path",{d:m,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>{if(e.value<=0)return null;let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;return Tm("text",{x:i,y:Math.max(s.plot.y+10,r-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`)})]}):null,o.map((e,t)=>{let i=Number(e.value);if(!Number.isFinite(i))return null;let r=Math.max(0,Math.min(1,(i-p)/g)),n=s.plot.x+r*s.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",l="bottom"===e.labelPosition?Math.min(a[1]-8,u+16):s.plot.y+16;return Lm("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[Tm("line",{x1:n,x2:n,y1:s.plot.y+8,y2:u-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:Tm("text",{x:Math.min(s.plot.x+s.plot.width-4,n+6),y:l,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${i}`)})]})}}function Rm(e,t,i,r){if(!1!==i&&!1!==r?.show&&t)return({size:i})=>{let r=[Number(i[0])||760,Number(i[1])||360],n=J(r),o=Math.max(1,t.windowCount),a=t.plot??n.plot,s=t.gutter??{x:a.x,y:a.y,width:0,height:a.height},l=t.windowPlot??a,c=l.width/o,u=a.y+a.height,d=a.y+.48*a.height,h=t.lidSegments[0]?.y1??d,p=t.windowStart,f=t.windowStart+o*t.windowSize,g=f===p?0:(t.watermarkValue-p)/(f-p),m=l.x+Math.max(0,Math.min(1,g))*l.width;return Lm("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Tm("rect",{x:a.x,y:a.y,width:a.width,height:a.height,fill:"none",stroke:gh("border"),strokeOpacity:.7,strokeWidth:1}),s.width>0?Tm("g",{children:Lm("text",{x:s.x+s.width/2,y:h-8,textAnchor:"middle",fill:gh("lateFill"),fontSize:10,fontWeight:700,children:[t.lateCount," late"]})}):null,Array.from({length:o},(i,n)=>{let o=e[n],a=l.x+n*c,s=n<t.closedWindowCount;return Lm("g",{children:[s?t.lidSegments.filter(e=>e.windowIndex===n).map(e=>Tm("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:gh("closedWindowStroke"),strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,Tm("text",{x:a+c/2,y:d-8,textAnchor:"middle",fill:gh("textSecondary"),fontSize:10,fontWeight:700,children:o?.value??0}),Lm("text",{x:a+c/2,y:Math.min(r[1]-8,u+16),textAnchor:"middle",fill:gh("textSecondary"),fontSize:10,children:[c<45?Tm("title",{children:o?.label??""}):null,c<45?t.windowStart+n*t.windowSize:o?.label??""]})]},`window-${n}`)}),t.windowWalls?.map(({id:e,...t})=>Tm("rect",{...t,fill:gh("border"),fillOpacity:.68},e)),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>Tm("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:gh("closedWindowStroke"),strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),Tm("line",{x1:a.x,x2:a.x+a.width,y1:u,y2:u,stroke:gh("border"),strokeWidth:1.5}),Tm("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:a.y+8,y2:u,stroke:gh("warning"),strokeDasharray:"5 4",strokeWidth:2}),Lm("text",{x:Math.min(a.x+a.width-4,m+6),y:a.y+16,fill:gh("warning"),fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]})]})}}function Nm(e,t,i,r=1){if(!1!==i&&0!==e.length)return({size:i})=>{let n=[Number(i[0])||700,Number(i[1])||380],o=J(n),a=zf(o.plot,e.length,t),s=o.plot.y+o.plot.height;return Lm("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Tm("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{let i=Math.min(o.plot.height,a.pileHeight(e.value/r)),l=a.tubeWidth,c=a.centerX(t),u=s-i;return Lm("g",{children:[Tm("rect",{x:c-l/2,y:u,width:l,height:i,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),Tm("text",{x:c,y:Math.max(o.plot.y+12,u-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),Tm("text",{x:c,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)}),Tm("text",{x:n[0]/2,y:n[1]-2,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:`Full circle = ${r}; partial circles scaled by area`})]})}}function Dm(e){return Math.abs(e)>=1e3||Math.abs(e)<.01?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:2})}function Fm(e,t){if(!1!==t&&e)return({size:t})=>{let i=[Number(t[0])||700,Number(t[1])||360],r=J(i),n=r.plot.y+r.plot.height,[o,a]=e.xExtent,s=o+(a-o)/2,l=[{label:Dm(o),x:e.xRange[0]},{label:Dm(s),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:Dm(a),x:e.xRange[1]}];return Lm("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.some(e=>e.overlapping)?Tm("text",{"data-testid":"collision-swarm-overlap-warning",x:r.plot.x,y:Math.max(10,r.plot.y-9),fill:"var(--semiotic-warning, #b45309)",fontSize:10,children:i[0]<360?"Points overlap":"Points overlap. Reduce radius or increase height."}):null,e.groups.map(e=>Lm("g",{children:[Tm("line",{x1:r.plot.x,x2:r.plot.x+r.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),Tm("text",{x:r.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),Lm("text",{x:r.plot.x+r.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count,e.overlapping?" · overlaps":""]})]},e.label)),Tm("line",{x1:e.xRange[0],x2:e.xRange[1],y1:n,y2:n,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(e=>Lm("g",{children:[Tm("line",{x1:e.x,x2:e.x,y1:n,y2:n+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),Tm("text",{x:e.x,y:Math.min(i[1]-8,n+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}import{createElement as Em}from"react";import{Children as Om,cloneElement as zm,isValidElement as Bm,useId as jm}from"react";function Wm({children:e}){let t=jm().replace(/[^\w-]/g,"_"),i=new Map,r=(e,t=!1)=>{let o={...e};for(let[e,a]of Object.entries(o))o[e]="children"!==e||t?"style"===e&&!t&&a&&"object"==typeof a?r(a,!0):"string"==typeof a?Ge(t?"style":e,a,i):a:n(a);return o},n=(e,o=!1)=>"object"!=typeof e?e:Om.map(e,e=>Bm(e)?o?("string"==typeof e.props.id&&i.set(e.props.id,`${t}-${e.props.id}`),n(e.props.children,!0),e):zm(e,r(e.props)):e);return n(e,!0),n(e)}import{Fragment as Ym,jsx as qm,jsxs as Xm}from"react/jsx-runtime";var Gm={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}};function Vm(e){return 6.2*e.length}function Hm(e,t){let i=e.trim();if(i.length<=t)return i;if(t<=1)return i.slice(0,1);let r=i.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return r.length>1&&r.length<=t?r:t<=3?i.slice(0,t).toUpperCase():`${i.slice(0,Math.max(1,t-2))}..`}function Um(e,t,i="auto"){let r=Math.max(1,Math.floor(t/6.2)),n="compact"===i?Hm(e,r):"full"===i||Vm(e)<=t?e:Hm(e,r);return{text:n,textLength:Vm(n)>t?Math.max(4,t):void 0}}import{jsx as Zm}from"react/jsx-runtime";function Km(e,t,i={},r){if(!1===t||!e)return;let{volume:n,stages:o,groups:a,groupCompletion:s}=e,l=new Map(n.stages.map(e=>[e.id,e])),c=new Map(s.map(e=>[e.id,e]));return({size:e})=>{let t=Number(e[0])||n.width,s=Number(e[1])||n.height,u=o.map(e=>{let t=l.get(e.id),r=i[`process-stage-${e.id}`];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:r?.queueDepth,processed:r?.processedCount}}),d=a.map(e=>{let t=c.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return function(e,t={}){let{showFlowSpine:i=!0,showStageCounts:r=!0,showCapacityBadges:n=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:s=!1,testId:l="process-flow-chrome"}=t,{width:c,height:u,left:d,right:h,topY:p,bottomY:f,midY:g,stages:m,groups:y=[]}=e,x=f-p;return Em(Wm,null,Xm("svg",{"aria-hidden":"true","data-testid":l,"data-outline-stages":s?"true":void 0,width:c,height:u,viewBox:`0 0 ${c} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",s?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[qm("defs",{children:Xm("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[qm("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),qm("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),qm("rect",{x:0,y:0,width:c,height:u,fill:"url(#semiotic-process-floor)"}),qm("rect",{x:d-6,y:p-8,width:h-d+12,height:x+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),i?qm("line",{x1:d+8,x2:h-8,y1:g,y2:g,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,m.map((e,t)=>{let i=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),o=Gm[i],l=Math.max(12,e.width-8),c=cl(l-8,22,88),d=Math.max(8,c-10),h=Um(e.label,d,a),y="none"!==a&&l-8>=22,b=function(e){if(null!=e.capacity){let t=null!=e.queueDepth?` · q ${e.queueDepth}`:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?String(e.capacity):e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}(e),v=Um(b,Math.max(16,l-10),"auto"),w=n&&!1!==e.showBadge&&l>=32,S=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",k=Um(S,Math.max(16,l-8),"auto"),A=Math.max(30,p-15),M=A-13;return Xm("g",{"data-stage":e.id,"data-role":i,children:[qm("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:l,height:x-12,rx:10,fill:s?"none":o.fill,stroke:o.stroke,strokeWidth:s?1.85:"flow"===i?1:1.6}),t<m.length-1?qm("polygon",{points:`${e.x1-2},${g-7} ${e.x1+8},${g} ${e.x1-2},${g+7}`,fill:o.accent,opacity:.85}):null,y?Xm(Ym,{children:[qm("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-c/2,y:M,width:c,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),Xm("text",{x:e.x,y:A,textAnchor:"middle",fill:o.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:h.textLength,lengthAdjust:h.textLength?"spacingAndGlyphs":void 0,children:[qm("title",{children:e.label}),h.text]})]}):null,w?Xm("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:v.textLength,lengthAdjust:v.textLength?"spacingAndGlyphs":void 0,children:[qm("title",{children:b}),v.text]}):null,r&&null!=e.count?Xm("text",{x:e.x,y:Math.min(u-8,f+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[qm("title",{children:S}),k.text]}):null]},e.id)}),o?y.map((e,t)=>{let i=e.total??0,r=e.absorbed??0,n=e.complete??(i>0&&r>=i),o=!n&&i>0&&r/i>=.75,a=n?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",s=n?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",l=i>0?`${r}/${i}${n?" shipped":o?" almost":""}`:`feature ${t+1}`,c=cl(Math.max(54,Vm(e.label)+18,Vm(l)+16),54,104),u=Um(e.label,c-12,"auto"),d=Um(l,c-12,"auto");return Xm("g",{"data-group":e.id,children:[qm("rect",{x:e.x-c/2,y:e.y-22,width:c,height:44,rx:10,fill:a,stroke:s,strokeWidth:1.5}),Xm("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[qm("title",{children:e.label}),u.text]}),Xm("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:s,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[qm("title",{children:l}),d.text]})]},e.id)}):null]}))}({width:t,height:s,left:n.left,right:n.right,topY:n.topY,bottomY:n.bottomY,midY:n.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...r})}}function Qm(e,t,i){if(!1===i||!t||0===e.length)return;let r=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:i})=>{let n=[Number(i[0])||t.volume.width,Number(i[1])||t.volume.height],o=J(n),a=e.reduce((e,t)=>Math.max(e,t.value),1),s=Math.min(48,.18*o.plot.height),l=o.plot.y+6;return Zm("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,i)=>{let n=e[i];if(!n)return null;let o=r.get(t.id);if(!o)return null;let c=Math.max(2,n.value/a*s),u=Math.max(8,.35*o.width);return Zm("rect",{x:o.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}function Jm(e){return Math.abs(e)>=1e3?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:1})}function ey(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}import{jsx as ty,jsxs as iy}from"react/jsx-runtime";function ry(e,t){let{showNodeLabels:i,showSensors:r,showStaticFlow:n}=t;if(e&&(n||r||i))return({size:t})=>{let o=[Number(t[0])||760,Number(t[1])||420],a=e.links.reduce((e,t)=>Math.max(e,t.throughput),1),s=new Set(e.nodes.map(e=>e.sensorId));return iy("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[n?e.links.map(e=>{let t=3+e.throughput/a*16,i=e.path[Math.floor(e.path.length/2)];return iy("g",{children:[ty("path",{d:ey(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),ty("path",{d:ey(e.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),i?ty("text",{x:i.x,y:i.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:Jm(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>iy("g",{children:[r&&s.has(e.sensorId)?ty("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,n?ty("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,i?ty("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}import{Fragment as ny,jsx as oy,jsxs as ay}from"react/jsx-runtime";function sy({layout:e,compact:t,showLabels:i}){let r=t?Math.round(.14*e.height):Math.max(80,e.routeY-180),n=t?Math.max(6,Math.round(.72*e.height)):Math.min(360,e.height-170);return oy(ny,{children:e.gates.map(o=>ay("g",{children:[oy("rect",{x:o.x-o.width/2,y:r,width:o.width,height:n,rx:t?2:12,fill:o.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:o.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),i?oy("text",{x:o.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:o.label??o.id}):null]},o.id))})}function ly({layout:e,states:t,compact:i=!1}){return i?oy("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:oy(sy,{layout:e,compact:!0,showLabels:!1})}):ay("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[oy("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),oy("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),oy("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),oy(sy,{layout:e,compact:!1,showLabels:!0}),ay("g",{children:[oy("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),oy("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),ay("g",{children:[oy("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),oy("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),oy("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function cy({states:e,layout:t}){let i=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!i.length)return null;let r=i.reduce((e,t)=>Math.max(e,t.value),1),n=Math.max(40,(t.width-80)/i.length);return ay("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[oy("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),i.map((e,t)=>{let i=40+t*n,o=Math.max(2,e.value/r*28),a=/kill|crash|block|grave/i.test(e.outcome);return ay("g",{children:[oy("rect",{x:i+.18*n,y:28-o+22,width:Math.max(10,.45*n),height:o,rx:2,fill:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),oy("text",{x:i+.4*n,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}var uy={margin:(e,t)=>function(e,t){return e?"sparkline"===t?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}}(t.compactMode,e.mode)};function dy(e,t){return e?t?i=>Ih.createElement(Ih.Fragment,null,"function"==typeof e?e(i):e,"function"==typeof t?t(i):t):e:t}function hy(e,t,i){let r=t[i];return"boolean"==typeof r?r:!0!==e.__compactMode}var py=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function fy(e){return py[v(e)%py.length]}var gy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a=n.bins??21,s=n.seed??1,l=Math.max(1,Math.round(n.pegRows??a-1)),c="mechanical"===(n.simulationMode??n.mode),u=function(e){let{data:t,valueAccessor:i,ballRadius:r,seed:n,size:o,valueExtent:a}=e,s=Number.isFinite(e.bins)?Math.max(1,Math.floor(e.bins)):1;if(!(Number.isFinite(r)&&r>0))throw new RangeError("Galton ballRadius must be finite and positive");let{rows:l}=N(t,"galton"),c=J(o),u=l.map((e,t)=>re(ie(e,t,i))).filter(e=>null!=e),d=L(a),[h,p]=d??(u.length?ue(u):[0,1]),f=p===h?1:p-h,g=Th().domain([0,s]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:s},()=>0),y=[];l.forEach((e,t)=>{let n=re(ie(e,t,i));if(null==n)return;let o=Math.max(0,Math.min(s-1,Math.floor((n-h)/f*s)));m[o]+=1,y.push({id:String(e.id??`galton-${t}`),x:g(o+.5),y:c.plot.y+r+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,value:n,bin:o}})});let x=c.plot.y+c.plot.height,b=[...lf({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...cf({idPrefix:"galton-bin",count:s,domainStart:0,domainStep:1,xScale:g,yTop:c.plot.y-400,yBottom:x,wallThickness:6})];return{config:te(n,b,"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:String(t+1),value:e})),metadata:{kind:"galton-board",bins:s,plot:c.plot,valueExtent:[h,p]}}}({data:c?R({bins:a,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:l,seed:s}):Array.isArray(e)?e:[],valueAccessor:n.valueAccessor||"value",bins:a,ballRadius:n.ballRadius??("sparkline"===n.mode?1.5:"context"===n.mode?4:6),seed:s,size:o,valueExtent:c?[0,l]:n.valueExtent});return{...r,config:u.config,initialSpawns:u.initialSpawns,initialSpawnPacing:u.initialSpawnPacing,projectionRows:u.projectionRows,foregroundGraphics:dy(Cm(u.projectionRows,a,hy(r,n,"showProjection"),u.metadata,n.referenceLines),r.foregroundGraphics),bodyStyle:ee(t||n.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},my={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{if(n.live||n.emitters)throw new Error("Live EventDrop requires React. Use finite replay data or export a saved physics snapshot.");let o=r.size??[600,400],a=Ff({data:Array.isArray(e)?e:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",arrival:n.arrival,watermarkAtArrivalAccessor:n.watermarkAtArrivalAccessor,sources:n.sources,sourceAccessor:n.sourceAccessor,sourceRail:n.sourceRail,timeUnit:n.timeUnit,windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??7,seed:n.seed??1,size:o,timeExtent:n.timeExtent,timeScale:n.timeScale??1}),s=function(e,t,i){if(!e||!1===t||!1===i?.show)return;let{plot:r,windowPlot:n,gutter:o,windowCount:a,windowSize:s,windowStart:l}=e,c=r.y+.48*r.height,u=r.y+r.height,d=e.lidSegments[0]?.y1??c,h=new Map(e.ledger?.map(e=>[e.start,e]));return yh("g",{"data-testid":"event-drop-window-background","aria-hidden":"true",children:[mh("rect",{x:o.x,y:d,width:o.width,height:u-d,fill:gh("gutterFill")}),Array.from({length:a},(t,r)=>{let o=r<e.closedWindowCount,d=l+r*s,p=d+s,f=h.get(d)??{windowId:`${d}-${p}`,start:d,end:p,accepted:0,late:0,bySource:{},open:!o},g="function"==typeof i?.fill?i.fill(f):i?.fill;return mh("rect",{x:n.x+r*n.width/a,y:c,width:n.width/a,height:u-c,fill:g??gh(o?"closedWindowFill":"openWindowFill")},d)})]})}(a.metadata,hy(r,n,"showProjection"),n.windowChrome);return{...r,backgroundGraphics:dy(r.backgroundGraphics,s),backgroundGraphicsBackdrop:r.backgroundGraphicsBackdrop??(s&&!r.backgroundGraphics?r.background??gh("background"):void 0),config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,eventDropMetadata:a.metadata,foregroundGraphics:dy(Rm(a.projectionRows,a.metadata,hy(r,n,"showProjection"),n.windowChrome),dy($h(n.sources,n.sourceRail,o),r.foregroundGraphics)),bodyStyle:Ph(n.sources,t||n.colorBy,{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},yy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a="mechanical"===(n.simulationMode??n.mode),s=function(e){let{data:t,categoryAccessor:i,valueAccessor:r,unitValue:n,ballRadius:o,seed:a,size:s}=e,l=T(n,1),{rows:c}=N(t,"pile"),u=J(s),d=[],h=new Map,p=new Map,f=[];function g(e){let t=h.get(e);return null==t&&(t=d.length,d.push(e),h.set(e,t)),t}c.forEach((e,t)=>{g(String(ie(e,t,i)??"unknown"))});let m=Math.max(1,d.length),y=zf(u.plot,m,o),x=Math.max(0,y.tubeWidth/2-o-1),b=d.map(()=>[]);c.forEach((e,t)=>{let n=String(ie(e,t,i)??"unknown"),a=g(n),s=r?re(ie(e,t,r)):1,c=Math.max(0,s??0);p.set(n,(p.get(n)??0)+c);let d=E(c,l),h=y.centerX(a);for(let i=0;i<d;i+=1){let r=b[a].length,s=i===d-1?c-i*l:l,p=Math.min(1,s/l),f=y.perRow>1?r%y.perRow:0,g=y.perRow>1?(f/(y.perRow-1)*2-1)*x:0;b[a].push({id:`${String(e.id??`pile-${t}`)}-${i}`,x:h+g,y:u.plot.y+o+2,vx:(i%3-1)*o/2,vy:0,mass:1,shape:{type:"circle",radius:o*Math.sqrt(p)},datum:{...e,category:n,unitIndex:i,unitValue:l,representedValue:s,unitFraction:p}})}});let v=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;e<v;e+=1)for(let t of b)e<t.length&&f.push(t[e]);let w=u.plot.y+u.plot.height,S=[...lf({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=u.plot.y-400;for(let e=0;e<m;e+=1){let t=y.centerX(e);for(let i of[-1,1])S.push({id:`pile-tube-${e}-${i<0?"l":"r"}`,shape:{type:"aabb",x:t+i*(y.tubeWidth+6)/2,y:(k+w)/2,width:6,height:w-k}})}return{config:te(a,S,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:p.get(e)??0}))}}({data:a?F({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(a?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??8,seed:n.seed??1,size:o});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,foregroundGraphics:dy(Nm(s.projectionRows,n.ballRadius??8,hy(r,n,"showProjection"),Number.isFinite(n.unitValue)&&n.unitValue>0?n.unitValue:1),r.foregroundGraphics),bodyStyle:ee(t||n.colorBy||(a?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},xy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,360],a=function(e){let{data:t,xAccessor:i,groupAccessor:r,radiusAccessor:n,pointRadius:o,seed:a,size:s,xExtent:l,collisionIterations:c,settle:u}=e,{rows:d}=N(t,"collision-swarm"),h=J(s),p=Q(a),f=[],g=[],m=new Map;d.forEach((e,t)=>{let a=re(ie(e,t,i));if(null==a)return;let s=r?String(ie(e,t,r)??"All"):"All",l=n?re(ie(e,t,n)):null,c=I(null!=l&&l>0?l:o,2,18);(function(e){let t=m.get(e);null==t&&(t=g.length,g.push(e),m.set(e,t))})(s),f.push({datum:e,index:t,value:a,group:s,radius:c})});let y=l?re(l[0]):null,x=l?re(l[1]):null,b=f.reduce((e,t)=>Math.min(e,t.value),f.length?1/0:0),v=f.reduce((e,t)=>Math.max(e,t.value),f.length?-1/0:1),w=y??b,S=x??v;if(w===S&&(w-=.5,S+=.5),w>S){let e=S;S=w,w=e}let k=f.reduce((e,t)=>Math.max(e,t.radius),o),A=h.plot.x+k+8,M=h.plot.x+h.plot.width-k-8,$=Bf().domain([w,S]).range([A,M]),_=Math.max(1,g.length),P=h.plot.height/_,T=Math.min(6,.05*P),L=e=>h.plot.y+((m.get(e)??0)+.5)*P,C=new Map,R=new Set,D=new Map;for(let e of g){let t=f.filter(t=>t.group===e),i=L(e),r=t.map(e=>({x:$(e.value),radius:e.radius})),n=jf(r,i-P/2+T,i+P/2-T,p);C.set(e,t.length),n.overlapping&&R.add(e),t.forEach((e,t)=>D.set(e.index,{x:r[t].x,y:n.positions[t],entryOffset:n.entryOffset}))}let F=f.map((e,t)=>{let i=D.get(e.index),r=i.x,n=i.y,o=R.has(e.group);return{id:String(e.datum.id??`collision-swarm-${t}`),x:r,y:n-(u?0:i.entryOffset),vx:0,vy:0,fixedPosition:{x:r},bodyCollisions:!o,mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:r,targetY:n,overlapping:o},springs:[{target:{type:"point",x:r,y:n},restLength:0,stiffness:34,damping:12}]}}),E=lf({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20});return{config:te(a,E,"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*k),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:F,projectionRows:g.map(e=>({label:e,value:C.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,S],xRange:[A,M],groups:g.map(e=>({label:e,y:L(e),count:C.get(e)??0,overlapping:R.has(e)})),plot:h.plot}}}({data:Array.isArray(e)?e:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:o,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:dy(Fm(a.metadata,hy(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:ee(t||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},by={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,420],a=Array.isArray(n.stages)?n.stages:[],s=function(e){let t=e.stages;if(!t.length)throw new Error("buildProcessFlowPhysics requires at least one stage");let i=e.size,r=J(i),n=I(e.ballRadius??6,2,18),o=e.seed??1,a=Q(o),s=e.idAccessor,l=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(c?"allAbsorbed":"none"),f=e.springStiffness??.28,g=e.springDamping??.72,m=!0===e.settle,y=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),x=Zf({width:i[0],height:i[1],shape:"lane",padX:Math.max(28,r.plot.x),padY:Math.max(36,r.plot.y+8),stages:y,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,S=x.stages[0],k=new Set(t.filter(e=>e.absorb).map(e=>e.id)),A=t.map(e=>{let t=v.get(e.id)??S;return function(e,t){let i={id:`process-stage-${e.id}`,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return function(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...Qf(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}({...i,kind:e.kind??"sink",force:eg(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...i.attributes,primitive:"absorb"}});if(e.portal){let t=e.portal.force??e.force??{x:-40,y:0};return function(e){return{...Qf(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}({...i,kind:e.kind??"force-field",force:eg(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...i.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){let t=Math.max(.1,e.capacity.unitsPerSecond);return function(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...Qf(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}({...i,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:eg(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...i.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){let t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return function(e){let t=e.pressure??e.occupancy??0,i=e.baseDamping??.08,r=e.dampingPerUnit??.12,n=e.energyPerUnit??0;return{...Qf(e,"membrane","pressureField",{pressure:t}),damping:i+t*r,energyDelta:n?-t*n:void 0,force:e.force}}({...i,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:eg(e.force,8),attributes:{...i.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?Jf({...i,kind:e.kind??"force-field",force:eg(e.force,14),damping:e.damping??.02,attributes:{...i.attributes,primitive:"routeSurface"}}):function(e){return{...Qf(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}({...i,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...i.attributes,primitive:"forceField"}})}(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});A.unshift(Jf({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));let M=new Map;for(let e of x.stages)M.set(e.id,0);let $=[];e.data.forEach((e,t)=>{let i=String(s?ie(e,t,s)??e.id??`process-flow-${t}`:e.id??`process-flow-${t}`),r=String(ie(e,t,l)??w),o=b.has(r)?r:w;M.set(o,(M.get(o)??0)+1);let a=c?String(ie(e,t,c)??""):void 0,p=a&&u?String(ie(e,t,u)??a):a,f=d?re(ie(e,t,d))??1:1,g=h?re(ie(e,t,h)):null,m=I(null!=g&&g>0?g:n,2,18);$.push({datum:e,id:i,stageId:o,groupId:a||void 0,groupLabel:p||void 0,work:f,radius:m,index:t})});let _=new Map,P=new Map;for(let e of $){if(!e.groupId)continue;let t=_.get(e.groupId)??[];t.push(e.id),_.set(e.groupId,t),e.groupLabel&&P.set(e.groupId,e.groupLabel)}let T=I(e.groupAnchorAlong??.55,.15,.9),L=x.left+(x.right-x.left)*T,C=Array.from(_.keys()),R=C.map((e,i)=>{let r=_.get(e)??[],n=C.length<=1?x.midY:x.topY+28+i/Math.max(1,C.length-1)*(x.bottomY-x.topY-56);return function(e){let t=e.x??e.anchor?.x??0,i=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:i,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:i},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}({id:e,label:P.get(e)??e,bodyIds:r,anchor:{x:L,y:n},x:L,y:n,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),N=function(e,t){let i=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],r=t.filter(e=>!i.has(e)),n=t.length-r.length,o=e.completion?.mode??"allMembersAbsorbed",a=e.completion?.valueByBodyId,s=e=>{let t=a?function(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}(a,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},l=t.reduce((e,t)=>e+s(t),0),c=t.reduce((e,t)=>e+(i.has(t)?s(t):0),0),u=e.completion?.threshold,d="threshold"===o?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0,h=t.length>0&&("anyAbsorbed"===o?n>0:"threshold"===o?c>=(d??l):0===r.length);return{id:e.id,label:e.label??e.id,mode:o,complete:h,absorbed:n,total:t.length,absorbedValue:c,totalValue:l,threshold:d,missing:r}})}(R,$.filter(e=>k.has(e.stageId)).map(e=>e.id)),D=new Map(R.map(e=>[e.id,e])),F=$.map((e,t)=>{let i=v.get(e.stageId)??S,r=i.x+(a()-.5)*Math.min(24,.2*i.width),n=x.boundaryY(r,"top")+e.radius+10,o=x.boundaryY(r,"bottom")-e.radius-10,s=o<=n?x.midY:n+a()*Math.max(1,o-n),l=m?r:x.left+18+t%7*4,c=m?s:x.midY+(a()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:r,y:s},restLength:.45*e.radius,stiffness:f,damping:g}];if(e.groupId){let t=D.get(e.groupId);t?.anchor&&!k.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:l,y:c,vx:m?0:40+40*a(),vy:m?0:20*(a()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:m?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),E={kernel:{seed:o,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},O=x.stages.map(e=>({label:e.label??e.id,value:M.get(e.id)??0})),z=t.map(e=>{let t=v.get(e.id)??S;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:M.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:E,initialSpawns:F,initialSpawnPacing:m?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:O,metadata:{kind:"process-flow",plot:r.plot,volume:x,stages:z,groups:R,groupCompletion:N,regionEffects:A}}}({data:Array.isArray(e)?e:[],stages:a,size:o,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),l=s.metadata;return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,regionEffects:l?.regionEffects,backgroundGraphics:dy(Km(s.metadata,hy(r,n,"showChrome"),{},n.chromeOptions),r.backgroundGraphics),foregroundGraphics:dy(Qm(s.projectionRows,s.metadata,hy(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:ee(t||n.colorBy||n.groupBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.workAccessor||n.stageAccessor||"stage"})}}},vy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=mg({data:Array.isArray(e)?e:[],size:o,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...r,config:a.config,initialSpawns:a.initialSpawns,projectionRows:[],backgroundGraphics:dy(hy(r,n,"showChrome")?Ih.createElement(ly,{layout:a.layout,states:a.states,compact:!0===r.__compactMode}):void 0,r.backgroundGraphics),foregroundGraphics:dy(hy(r,n,"showProjection")?Ih.createElement(cy,{layout:a.layout,states:a.states}):void 0,r.foregroundGraphics),bodyStyle:ee(t||n.colorBy)}}},wy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=dm({data:Array.isArray(e)?e:[],phases:Array.isArray(n.phases)?n.phases:[],products:Array.isArray(n.products)?n.products:void 0,outlets:Array.isArray(n.outlets)?n.outlets:void 0,events:Array.isArray(n.events)?n.events:void 0,idAccessor:n.idAccessor,labelAccessor:n.labelAccessor,categoryAccessor:n.categoryAccessor,amountAccessor:n.amountAccessor,metricsAccessor:n.metricsAccessor,initialStateAccessor:n.initialStateAccessor,metrics:n.metrics,size:o,seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange}),s="snapshot"===n.playback?function(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,Vg(t)??0));let i=e.phases.find(e=>e.id===t.phaseId);if(!i)return e.duration;let r=Math.max(0,Math.min(1,Vg(t.progress??0)??0));return i.start+i.duration*r}(a,n.snapshotAt):a.duration,l=um(a,s).state,c=n.projection&&"object"==typeof n.projection?n.projection:{groupBy:"outlet",measure:"count"},u=function(e,t={}){let i=t.groupBy??"outlet",r=new Map,n=e=>{let t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},i),n=r.get(t);if(n)return n.count+=1,n.amount+=e.amount,void _g(n.metrics,e.metrics);r.set(t,{key:t,label:"product"===i&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:bg(e.metrics),status:"status"===i?e.status:void 0,outletId:"outlet"===i?e.outletId:void 0,category:"category"===i?e.category:void 0,productId:"product"===i&&"product"===e.kind?e.id:void 0})};for(let t of Object.values(e.components))t.productIds.length||"consumed"===t.status||n({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(let t of Object.values(e.products))n({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});let o=new Map((t.order??[]).map((e,t)=>[e,t]));return[...r.values()].sort((e,t)=>(o.get(e.key)??Number.MAX_SAFE_INTEGER)-(o.get(t.key)??Number.MAX_SAFE_INTEGER)||kg(e.key,t.key))}(l,c),d=c.measure??"count",h=function(e,t={}){let i=t.bodies??[],r=Math.max(0,t.recentBodyLimit??6),n=new Map;for(let e of i){let i=t.getContainerId?.(e);if(!i)continue;let r=n.get(i);r?r.push(e):n.set(i,[e])}let o=e.map(e=>{let i=n.get(e.id)??[],o=Math.max(0,Math.floor(e.count??i.length)),a=i.slice(Math.max(0,i.length-r)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??Pm(e),datum:e.datum}));return{id:e.id,label:e.label,count:o,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:i.map(e=>e.id),recentBodies:a,metadata:e.metadata}}),a=o.reduce((e,t)=>e+t.count,0);return o.map(e=>({...e,share:a>0?e.count/a:0}))}(u.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===d||"amount"===d?e.amount:Number(e.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?n.amountLabel??"amount":d,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),p={seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange},f=t??n.colorBy??"category",g=!1===n.showChrome?null:Ih.createElement($m,{layout:a.layout,phases:a.phases,state:l,compact:o[0]<520||o[1]<360}),m=!1===n.showProjection?null:Ih.createElement(_m,{rows:u,layout:a.layout,projection:c,amountLabel:n.amountLabel});return{...r,config:a.config,initialSpawns:sm(l,a.layout,p),projectionRows:h,bodyStyle:e=>function(e,t,i,r){let n=e.datum,o={stroke:r.stroke??("product"===n?.kind?"#fffaf0":"#26323a"),strokeWidth:r.strokeWidth??("product"===n?.kind?1.8:1.1),opacity:r.opacity??.96};if(!n?.__crucible)return{...o,fill:r.color??"#b8792d"};if("product"===n.kind){let e=t.products[n.semanticId];return{...o,fill:r.color??e?.color??fy(e?.id??n.semanticId)}}let a,s=t.components[n.semanticId];return s?(a="status"===i?s.status:"outlet"===i?s.outletId??"in chamber":"product"===i?s.productIds[0]??"unalloyed":"category"===i||null==i?s.category:String("function"==typeof i?i(s.datum)??"unassigned":s.datum[String(i)]??"unassigned"),{...o,fill:r.color??fy(a)}):{...o,fill:r.color??"#356b63"}}(e,l,f,n),getBodyLabel:e=>function(e,t){let i=e.datum;if(i?.__crucible)return"product"===i.kind?t.products[i.semanticId]?.label:t.components[i.semanticId]?.label}(e,l),renderBodySVG:mm,backgroundGraphics:dy(g,r.backgroundGraphics),foregroundGraphics:dy(m,r.foregroundGraphics)}}},Sy={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[760,420],a=function(e){let{coordinateMode:t,flowSpeed:i,links:r,maxParticles:n,nodeIdAccessor:o,nodeXAccessor:a,nodeYAccessor:s,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:p,seed:f,size:g,sourceAccessor:m,targetAccessor:y,throughputAccessor:x}=e,b=J(g),v=Q(f),w=new Map,S=new Map,k=[];function A(e){if(e&&"object"==typeof e){let t=e;if("function"==typeof o){let e=o(t,0);if(null!=e)return String(e)}if("string"==typeof o&&null!=t[o])return String(t[o]);if(null!=t.id)return String(t.id)}return String(e??"unknown")}l.forEach((e,t)=>{let i=String(ie(e,t,o)??e.id??t),r=re(ie(e,t,a)),n=re(ie(e,t,s));if(null!=r&&null!=n){let e={x:r,y:n};w.set(i,e),k.push(e)}S.set(i,String(e.label??e.name??i))});let M=[];r.forEach((e,t)=>{let i=A(ie(e,t,m)),r=A(ie(e,t,y)),n=Math.max(0,re(ie(e,t,x))??0),o=Yf(d?ie(e,t,d):void 0),a=o.length?o:Yf(e.path??e.points??e.route);a.forEach(e=>k.push(e)),M.push({id:String(e.id??`physical-flow-${i}-${r}-${t}`),link:e,index:t,source:i,target:r,throughput:n,rawPath:a})});let $=function(e,t){return"normalized"===e||"pixels"===e?e:t.length>0&&t.every(e=>e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1)?"normalized":"pixels"}(t,k),_=new Map;for(let[e,t]of w)_.set(e,qf(t,b,$));let P=[];for(let e of M){let t=e.rawPath.map(e=>qf(e,b,$));if(t.length>=2)_.has(e.source)||_.set(e.source,t[0]),_.has(e.target)||_.set(e.target,t[t.length-1]);else{let i=_.get(e.source),r=_.get(e.target);i&&r&&(t=[i,r])}t.length<2||e.throughput<=0||(S.has(e.source)||S.set(e.source,e.source),S.has(e.target)||S.set(e.target,e.target),P.push({...e,path:t,packetCount:0}))}let L=T(u,.12),R=Math.max(1,Math.round(n)),N=P.map(e=>Math.max(1,Math.round(e.throughput*L))),D=N.reduce((e,t)=>e+t,0),F=D>R?R/D:1;P.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(N[t]*F))});let E=P.reduce((e,t)=>e+t.packetCount,0);for(;E>R;){let e=P.reduce((e,t,i)=>t.packetCount<=1?e:-1===e||t.packetCount>P[e].packetCount?i:e,-1);if(-1===e)break;P[e].packetCount-=1,E-=1}let O=new Map,z=new Map,B=[],j=T(i,90),W=T(c,4);P.forEach((e,t)=>{O.set(e.target,(O.get(e.target)??0)+e.throughput),z.set(e.source,(z.get(e.source)??0)+e.throughput);let i=Xf(e.path);for(let r=0;r<e.packetCount;r+=1){let n=(r+.5)/e.packetCount,o=p?n:I(.12+.84*n+.04*(v()-.5),.04,.98),a=p?o:Math.max(0,o-(.18+.12*v())),s=Gf(e.path,a),l=Gf(e.path,o),c=Vf(e.path,a),u={x:-c.y,y:c.x},d=(v()-.5)*W*1.5,f=`${e.id}-packet-${r}`;B.push({id:f,x:s.x+u.x*d,y:s.y+u.y*d,vx:p?0:c.x*j+10*(v()-.5),vy:p?0:c.y*j+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+r/32,shape:{type:"circle",radius:W},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:r,packetCount:e.packetCount,routeProgress:o,flowPath:e.path,flowPathLength:i,flowRouteId:e.id,flowSpeed:j,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});let Y=Math.max(18,5*W),q=Array.from(_,([e,t])=>({nodeId:e,label:S.get(e)??e,sensorId:`physical-flow-node-${C(e)}`,point:t})),X=q.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:Y,height:Y}})),G=Object.fromEntries(q.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),V=[...lf({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],H=te(f,V,"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=R,H.eviction="oldest",H.observation={...H.observation,sensors:G};let U=Array.from(_,([e,t])=>({id:e,label:S.get(e)??e,x:t.x,y:t.y,sensorId:`physical-flow-node-${C(e)}`,incoming:O.get(e)??0,outgoing:z.get(e)??0})),Z=P.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:H,initialSpawns:B,projectionRows:U.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:$,particleCount:B.length,totalThroughput:P.reduce((e,t)=>e+t.throughput,0),plot:b.plot,nodes:U,links:Z}}}({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(e)?e:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:o});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:dy(ry(a.metadata,{showNodeLabels:!1!==n.showNodeLabels,showSensors:!1!==n.showSensors,showStaticFlow:!1!==n.showStaticFlow}),r.foregroundGraphics),bodyStyle:ee(t||n.colorBy||"source")}}},ky={frameType:"physics",layout:uy,buildProps:(e,t,i,r,n)=>{let o=r.size??[700,380],a=Pi(r.theme),s=function(e){let t=function(e,t,i){let r=e?.observation;return{...e,observation:{...r,chartId:t??r?.chartId??"physics-custom",chartType:r?.chartType??"PhysicsCustomChart",onObservation:i??r?.onObservation}}}(e.config,e.chartId,e.onObservation),i=ig(e.colorScheme,e.themeCategorical,Ct),r=J(e.size),n={data:e.data,scales:{x:tg().domain(e.xExtent??[0,1]).range([r.plot.x,r.plot.x+r.plot.width]),y:tg().domain(e.yExtent??[0,1]).range([r.plot.y+r.plot.height,r.plot.y])},dimensions:r,theme:{semantic:e.semantic,categorical:[...i]},resolveColor:rg(i,e.colorScheme),config:e.layoutConfig??{},world:new Nf(t)},o=e.skipLayout?{}:e.layout(n)??{},a=function(e,t){if(!t?.length)return e;let i=new Map;for(let e of t){let{bodyId:t,...r}=e,n=i.get(t)??[];n.push(r),i.set(t,n)}return e.map(e=>{let t=i.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...o.initialSpawns??o.bodies??[]],o.constraints);return{config:ng(t,o),context:n,initialSpawnPacing:o.initialSpawnPacing,initialSpawns:a,result:o}}({chartId:n.chartId,colorScheme:i,config:n.config,data:Array.isArray(e)?e:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:_(a)??{},size:o,themeCategorical:a.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:[],bodyStyle:s.result.bodyStyle??ee(t||n.colorBy),backgroundGraphics:dy(r.backgroundGraphics,s.result.backgroundOverlays),foregroundGraphics:dy(r.foregroundGraphics,s.result.overlays)}}};function Ay(e){return e&&{fields:["nodeId"],..."object"==typeof e?e:{name:"string"==typeof e?e:"hover"}}}function My(e){let t=e.roles.occurrence;return"string"==typeof t?[t]:e.entityIds}function $y(e,t=[],i){let r=void 0===i?void 0:new Set("string"==typeof i?[i]:i),n=t.filter(e=>!e.missingPrehistory&&void 0!==e.partition&&r?.has(e.partition)),o=new Set(n.map(e=>e.id)),a=new Set(n.map(e=>e.entityId)),s=new Map,l=0;for(let t of e){if(void 0!==i&&"string"==typeof t.roles.occurrence&&!o.has(t.roles.occurrence))continue;let e=Object.entries(t.entityWeights);0===e.length&&void 0===i&&(l+=t.entityCount);for(let[t,r]of e)(void 0===i||a.has(t))&&s.set(t,r)}return[...s.values()].reduce((e,t)=>e+t,l)}function _y(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}function Py(e,t){return e.slice(0,t+1).map(e=>e.replaceAll("%","%25").replaceAll(">","%3E")).join(">")}function Iy(e,t,i){return e.entries.find(e=>e.measureId===t&&e.subjectId===i)}function Ty(e,t,i){return 0===i||1e4*e%i!=0?Math.round((t-e)/Math.max(i,1)*1e4):1e4*(t-e)/i}function Ly(e,t={}){let i=t.templates??["repeated-state-episode"],r="ordinal"===e.spec.coordinate.kind?e.spec.coordinate.sectionIds:[],n=void 0!==t.partition?function(e,t){let i=e.spec.comparison?.denominatorMeasureId??e.spec.motifs.denominatorRef??"assigned";return Iy(e.ledger,i,t)?.value}(e,t.partition)??0:e.spec.comparison?e.comparison?.rows.reduce((e,t)=>e+t.assigned,0)??0:e.ledger.entries.find(t=>"global"===t.subjectKind&&t.measureId===e.spec.motifs.denominatorRef)?.value??0,o=i=>$y(i,e.source.occurrences,t.partition??e.spec.comparison?.partitions),a=[],s=e.motifs.incompleteCandidates.length>0;for(let l of i)for(let i of r){let r=e.motifs.matches.filter(e=>e.template===l),c=o(r.filter(e=>e.completionSectionId===i)),u=o(r.filter(e=>e.intersectSectionIds.includes(i)));a.push({template:l,sectionId:i,partition:t.partition,completionCount:c,intersectionCount:u,denominator:n,status:s?"incomplete":"exact"})}return{templates:i,sections:r,cells:a}}function Cy(e){return e.entityCount??1}function Ry(e){if(!e.missingPrehistory)return{id:`group:${e.id}`,occurrenceId:e.id,partition:e.partition,nodePath:e.nodePath,entityCount:Cy(e),...e.stepEntityCounts&&{stepEntityCounts:[...e.stepEntityCounts]},signature:Py(e.nodePath,e.nodePath.length-1)}}function Ny(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let i=Math.max(0,t),r=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let n=e[t-1],o=e[t],a=e[t+1],s=Math.hypot(o.x-n.x,o.y-n.y),l=Math.hypot(a.x-o.x,a.y-o.y),c=Math.min(i,s/2,l/2);if(c<=.001){r+=` L${o.x},${o.y}`;continue}let u={x:o.x+(n.x-o.x)/s*c,y:o.y+(n.y-o.y)/s*c},d={x:o.x+(a.x-o.x)/l*c,y:o.y+(a.y-o.y)/l*c};r+=` L${u.x},${u.y} Q${o.x},${o.y} ${d.x},${d.y}`}let n=e[e.length-1];return`${r} L${n.x},${n.y}`}var Dy=(e,t,i)=>({x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}),Fy=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function Ey(e,t,i){if(e.length<2)return"";let r=function(e){let t=[e[0]];for(let i=1;i<e.length-1;i++){let r=e[i-1],n=e[i],o=e[i+1],a=Fy(r,n),s=Fy(n,o),l=Math.min(8,a/2,s/2);if(0===l)continue;let c=Dy(n,r,l/a),u=Dy(n,o,l/s);t.push(c);for(let e=1;e<=12;e++){let i=e/12;t.push(Dy(Dy(c,n,i),Dy(n,u,i),i))}}return t.push(e[e.length-1]),t.filter((e,i)=>0===i||Fy(t[i-1],e)>1e-8)}(e);if(r.length<2)return"";let n=[0];for(let e=1;e<r.length;e++)n.push(n[e-1]+Fy(r[e-1],r[e]));let o=n[n.length-1],a=function(e){if(e.length<2)return e.map(e=>({...e}));let t=(e,t)=>{let i=t.x-e.x,r=t.y-e.y,n=Math.hypot(i,r)||1;return{x:-r/n,y:i/n}};return e.map((i,r)=>{let n=r>0?t(e[r-1],i):null,o=r<e.length-1?t(i,e[r+1]):null;if(!n||!o){let e=o??n??{x:0,y:0};return{x:i.x+1*e.x,y:i.y+1*e.y}}let a=n.x+o.x,s=n.y+o.y,l=Math.hypot(a,s);if(l<.001)return{x:i.x+1*o.x,y:i.y+1*o.y};a/=l,s/=l;let c=a*o.x+s*o.y;if(Math.abs(c)<.001)return{x:i.x+1*o.x,y:i.y+1*o.y};let u=4*Math.abs(1),d=1/c,h=Math.max(-u,Math.min(u,d));return{x:i.x+a*h,y:i.y+s*h}})}(r),s=[1,-1].map(e=>r.map((r,s)=>{let l=t+(i-t)*n[s]/o;return Dy(r,a[s],e*l/2)}));return[...s[0],...s[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function Oy(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let i=t+e/2;return t+=e+3,i})}var zy={viewBox:[24,24],parts:[{d:"M5,0 H19 Q24,0 24,5 V19 Q24,24 19,24 H5 Q0,24 0,19 V5 Q0,0 5,0 Z",stroke:"accent"}]};function By(e){let t="";return e.split(">").map((e,i)=>t=i?`${t}>${e}`:e)}var jy=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,Wy=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),Yy=e=>{let t=e.config.braid,i=e.dimensions.plot,r=t.atlas.spec.comparison?.partitions??[...new Set(t.groups.map(e=>e.partition))],n=t.groups.filter(e=>r.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],s=[];if(0===n.length)return{sceneNodes:a,sceneEdges:o,labels:s};let l=new Set(n.map(e=>e.signature)),c=[...t.signatureOrder.filter(e=>l.delete(e)),...l],u=new Map(c.map((e,t)=>[e,t])),d=[...n].sort((e,t)=>u.get(e.signature)-u.get(t.signature)),h=r.map(e=>d.filter(t=>t.partition===e)),p=function(e){let t=new Map;for(let i of e){let e=By(i.signature);i.nodePath.forEach((r,n)=>{let o=e[n],a=t.get(o);a||(a={id:o,state:r,depth:n+1,signatures:new Set},t.set(o,a)),a.signatures.add(i.signature)})}return[...t.values()]}(d),f=he(p.map(e=>e.depth)),g=n.map(e=>he(e.stepEntityCounts??[e.entityCount])),m=he(g),y=e=>e<=0?0:Math.max(1,10*e/m),x=new Map(n.map((e,t)=>[e.id,y(g[t])])),b=i.height/r.length,{semantic:v}=e.theme,w=(e,t,i,r={})=>s.push({x:e,y:t,text:i,fill:v.text??"#333",fontSize:10,anchor:"middle",...r}),S={sourceRevision:t.atlas.provenance.sourceRevision,analysisRevision:t.atlas.analysisRevision,relationScopeId:"directed-admitted"},k=new Map(p.map(e=>{let t=h.map(t=>t.reduce((t,i)=>t+(e.signatures.has(i.signature)?x.get(i.id)+3:0),5));return[e.id,he(t,24)]})),A=he([...k.values()],24),M=Math.min(i.width/4,A/2+16),$=(i.width-2*M)/Math.max(f-1,1),_=e=>i.x+M+(e-1)*$,P=48+A/2,I=22+A/2,T=(e,t)=>e+P+(u.get(t)+.5)*Math.max(0,b-P-I)/c.length,L=(t,i,r,n,a)=>{let s=jy(i,n),l=jy(i,a),c=y(s),u=y(l);if(0===c&&0===u)return;let d=c!==u,h=e.resolveColor(i.signature);o.push({type:"curved",id:r,pathD:d?Ey(t,c,u):Ny(t,8),style:{fill:d?h:"none",fillOpacity:1,stroke:d?"none":h,strokeWidth:d?0:c},datum:{...S,id:r,kind:"braid-track",nodeId:i.nodePath[a],fromNodeId:i.nodePath[n],groupId:i.id,signature:i.signature,partition:i.partition,entityCount:i.entityCount,fromStep:n,toStep:a,fromCount:s,toCount:l,falseRoot:!1},accessibleDatum:{journey:i.nodePath.join(" → "),partition:i.partition??"all",fromStep:n+1,toStep:a+1,fromCount:s,toCount:l}})};return r.forEach((e,t)=>{let r=i.y+t*b,n=h[t];if(e&&w(i.x+8,r+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===n.length)return;for(let e=1;e<=f;e++)w(_(e),r+34,`Step ${e}`);let o=new Map;for(let t of p){let i=n.filter(e=>t.signatures.has(e.signature));if(0===i.length)continue;let s=_(t.depth),l=th([...t.signatures].map(e=>T(r,e))),c=Oy(i.map(e=>x.get(e.id)));o.set(t.id,new Map(i.map((e,t)=>[e.id,{x:s,y:l+c[t],offset:c[t]}])));let u=k.get(t.id),d={state:t.state,step:t.depth,partition:e??"all"},h=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:h,cx:s,cy:l,size:u,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:zy,accent:v.border??"#888",style:{fill:v.surface??"#fff"},datum:{...S,id:h,nodeId:t.state,kind:"braid-step",prefixId:t.id,...d},accessibleDatum:d}),w(s,l+u/2+12,t.state,{anchorPoint:[s,l]})}for(let t of n){let i=By(t.signature);for(let r=1;r<i.length;r++){let n=o.get(i[r-1]).get(t.id),a=o.get(i[r]).get(t.id),s=(n.x+a.x)/2-Math.sign(a.y-n.y)*a.offset,l=Math.abs(n.y-a.y)<1e-8?[n,a]:[n,{x:s,y:n.y},{x:s,y:a.y},a];L(l,t,`step:${e??"all"}:${i[r]}:${t.id}`,r-1,r)}}}),{sceneNodes:a,sceneEdges:o,labels:s,restyle:Wy,restyleEdge:Wy}};import*as qy from"react";import{NetworkPerspectiveGround as Xy}from"./semiotic-network-placement.module.min.js";function Gy(e,t){let i=new Set,r=[t];for(;r.length;){let t=r.pop();if(i.has(t))continue;i.add(t);let n=_y(e.children,t);Array.isArray(n)&&r.push(...n)}return i}var Vy=e=>{let{forest:t,selection:i,reading:r="organize"}=e.config,{atlas:n}=t,o=e.dimensions.plot,a=e.theme.semantic.text??"#273442",s=e.config.colors?.backbone??e.theme.semantic.textSecondary??"#8995a3",l=e.config.colors?.residual??e.theme.semantic.warning??"#b66631",c=e.config.colors?.required??e.theme.semantic.primary??"#3983a5",u=i?.analysisRevision===n.analysisRevision&&"directed-admitted"===i.relationScopeId&&n.source.nodes.some(e=>e.id===i.nodeId)?i.nodeId:void 0,d=new Map;for(let i of t.order)if(e.config.collapsedNodeIds?.includes(i)&&!d.has(i))for(let e of Gy(t,i))e!==i&&d.set(e,i);let h=t.order.filter(e=>!d.has(e)),p=new Map(n.source.nodes.map(e=>[e.id,e])),f=new Map;for(let e of d.values())f.set(e,(f.get(e)??0)+1);let g=new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source;if(t===(d.get(e.target)??e.target)&&(e.source!==t||e.target!==t)){let i=g.get(t);i?i.push(e.id):g.set(t,[e.id])}}let m=[...n.sections.sectionIds];n.source.nodes.some(e=>!e.sectionId)&&m.push("Unsectioned");let y=new Map(n.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),x=m.map(e=>h.filter(t=>y.get(t)===e)),b=new Map,v=[],w=[],S=[],k=[],A=(e,t,i,r=11,n)=>v.push({x:e,y:t,text:i,fill:a,anchor:"middle",fontSize:r,...n?{anchorPoint:n}:{}}),M=Math.max(16,Math.min(94,o.width/Math.max(1,m.length)-20));x.forEach((e,t)=>{let i=o.x+o.width*(t+.5)/m.length;A(i,o.y+18,m[t],12),e.forEach((t,r)=>{let n=o.y+58+(r+.5)*Math.max(40,o.height-110)/Math.max(1,e.length);b.set(t,{x:i,y:n})})});for(let t of h){let i=b.get(t),r=p.get(t),o=f.get(t)??0,a=g.get(t)??[],d=n.requiredPaths?.unreachableNodeIds.includes(t),h=r.completeness&&"known"!==r.completeness,m=h?"Unknown upstream":d?"Unreachable from roots":void 0;w.push({type:"glyph",id:t,cx:i.x,cy:i.y,size:34,glyph:{viewBox:[M,34],parts:[{d:`M6,0 H${M-6} Q${M},0 ${M},6 V28 Q${M},34 ${M-6},34 H6 Q0,34 0,28 V6 Q0,0 6,0 Z`,stroke:"accent"}]},accent:u===t?c:h?l:s,style:{fill:e.theme.semantic.surface??"#fff",strokeWidth:u===t?2.5:1},label:t,datum:{...r,nodeId:t,kind:"dependency-node",sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",hiddenCount:o,internalEdgeIds:a},accessibleDatum:{node:t,section:y.get(t),status:m??"Admitted",hiddenCount:o,internalEdges:a.join(", ")}});let x=[i.x,i.y];A(i.x,i.y+4,o?`${t} +${o}`:t,12,x),m?A(i.x,i.y+30,m,9,x):o&&A(i.x,i.y+30,`${a.length} internal links`,9,x)}let $,_=new Set(t.forest.backboneEdgeIds),P=new Set(e.config.highlightedEdgeIds),I=new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source,i=d.get(e.target)??e.target;if(t===i&&(e.source!==t||e.target!==i))continue;let r=b.get(t),a=b.get(i),u=JSON.stringify([t,i]),h=12*(I.get(u)??0);I.set(u,(I.get(u)??0)+1);let p,f,g=_.has(e.id),y=P.has(e.id)?c:g?s:l,x=a.x>r.x,v=r.x+(x?M/2:-M/2),w=a.x+(x?-M/2:M/2),A=[...b.values()].filter(e=>e.x>Math.min(r.x,a.x)&&e.x<Math.max(r.x,a.x));if(t===i)p=`M${r.x-14},${r.y-17} C${r.x-35-h},${r.y-64-h} ${r.x+35+h},${r.y-64-h} ${r.x+14},${r.y-17}`,f=1;else if(r.x===a.x){let e=a.y>r.y?1:-1,t=r.x+e*M/2,i=t+e*(32+h);p=`M${t},${r.y} C${i},${r.y} ${i},${a.y} ${t},${a.y}`,f=1===e?2:0}else if(A.length){let e=Math.min(r.y,a.y,de(A.map(e=>e.y)))-17-26-h,t=(o.width/m.length-M)/2*(x?1:-1);p=`M${v},${r.y} C${v+t},${r.y} ${v},${e} ${v+t},${e} H${w-t} C${w},${e} ${w-t},${a.y} ${w},${a.y}`,f=x?0:2}else if(x){let e=(v+w)/2;p=`M${v},${r.y} C${e},${r.y-h} ${e},${a.y-h} ${w},${a.y}`,f=0}else{let e=Math.min(r.y,a.y)-48-h;p=`M${v},${r.y} C${v-25},${e} ${w+25},${e} ${w},${a.y}`,f=2}S.push({type:"curved",id:e.id,pathD:p,style:{stroke:y,strokeWidth:P.has(e.id)?3:g?1.3:2,fill:"none"},datum:{...e,sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",kind:"dependency-edge",edgeClass:g?"backbone":"residual"},accessibleDatum:{edge:e.id,source:e.source,target:e.target,display:g?"backbone":"residual cross-link"}});let $=t===i?r.x+14:r.x===a.x?r.x+(a.y>r.y?M/2:-M/2):w,T=t===i?r.y-17:a.y;k.push(qy.createElement("path",{key:`arrow:${e.id}`,"data-dependency-edge":e.id,"data-source":e.source,"data-target":e.target,d:"M-6,-3 L0,0 L-6,3",fill:"none",stroke:y,transform:`translate(${$},${T}) rotate(${90*f})`}))}if("required-paths"===r&&u){let e=function(e,t){let i=[],r=_y(e.requiredChildren,t);if(void 0===r)return i;if(!Array.isArray(r))throw new Error("Invalid required-path dominator children");let n=[...r],o=new Set([t]);for(;n.length;){let t=n.pop(),r=_y(e.requiredChildren,t);if("string"!=typeof t||o.has(t)||!Array.isArray(r))throw new Error("Invalid required-path dominator chain");o.add(t),i.push(t);for(let e of r)n.push(e)}return i.sort()}(t,u),i=[...new Set(e.map(e=>d.get(e)??e))].filter(e=>e!==u&&b.has(e));if(i.length){let e=i.map(e=>b.get(e)),t=he(e.map(e=>e.x))+M/2+8,r=de(e.map(e=>e.y))-23,n=he(e.map(e=>e.y))+23;$={x:t-7,y:r,width:7,height:n-r,z:"top"},k.push(qy.createElement("path",{key:"required-bracket",d:`M${t-7},${r} H${t} V${n} H${t-7}`,fill:"none",stroke:c,strokeWidth:2,"data-kind":"dominator-bracket"}))}A(o.x+o.width/2,o.y+o.height-16,e.length?`${u} lies on all admitted paths to ${e.join(", ")}${"incomplete"===n.requiredPaths?.status?" · incomplete scope":""}`:n.requiredPaths?`${u}: no other required targets in the admitted graph`:"Required paths have not been prepared")}let T=new Map(w.map(e=>[e.id,e.datum]));return{sceneNodes:w,sceneEdges:S,labels:v,restyle:(e,t)=>({opacity:t?.isActive&&!t.predicate(e.datum)?.2:1}),restyleEdge:(e,t)=>({opacity:t?.isActive&&![e.datum,T.get(String(e.datum?.source)),T.get(String(e.datum?.target))].some(e=>e&&t.predicate(e))?.2:1}),overlays:qy.createElement("g",{"aria-hidden":!0},qy.createElement(Xy,{z:"top"},...k)),perspective:"manual",...e.perspective&&$?{perspectiveBounds:[$]}:{}}};import*as Hy from"react";import{NetworkPerspectiveGround as Uy}from"./semiotic-network-placement.module.min.js";import*as Zy from"react";var Ky=Zy.createElement,Qy={observed:"#387e98",modeled:"#946344",residual:"#a56537",muted:"#778796",alarm:"#bb5149"},Jy=e=>null===e?"unmeasured":e>=1e6?`${Number((e/1e6).toFixed(2))}m`:e>=1e3?`${Number((e/1e3).toFixed(1))}k`:Number.isInteger(e)?String(e):String(Number(e.toPrecision(3))),ex={stage:"M-5,0 H5",distributor:"M-5,0 H0 M0,0 L6,-5 M0,0 H6 M0,0 L6,5",queue:"M-6,-5 V5 H6 V-5 M-3,2 H3",retry:"M-5,2 A5,5 0 1,1 4,3 M4,-1 V4 H0","join-all":"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M2,-5 V5",selector:"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M1,-4 L5,0 L1,4",dependency:"M-5,-5 H5 V5 H-5 Z M-2,-2 L2,2 M-2,2 L2,-2",junction:"M0,-6 L6,0 L0,6 L-6,0 Z"},tx={stage:"stage",distributor:"distributor",queue:"FIFO queue",retry:"retry episode","join-all":"all-member join",selector:"first success",dependency:"dependency gate",junction:"unclassified junction"};function ix(e,t,i,r,n,o=Qy,a){let s=Object.values(t.entry.nodes).reduce((e,t)=>Math.max(e,t.queued??0),0)||1;return e.modules.map(e=>{let{module:l,x:c,y:u,width:d,height:h,queue:p}=e,f=t.entry.nodes[l.nodeId],g=n===l.nodeId?i:(f.queued??0)>0?o.alarm:o.muted,m=c+d/2,y="records"===l.semantics.unit?"rec":"attempts"===l.semantics.unit?"att":"roots",x=null!==f.capacity?`${Jy(f.completions)} / ${Jy(f.capacity)} ${y}/s`:null!==f.completions?`${Jy(f.completions)} ${y}/s complete`:`${Jy(f.arrivals)} ${y}/s offered`;return Ky("g",{key:l.id,"data-circuit-module":l.nodeId,"data-module-kind":l.kind,opacity:a?.(l.nodeId),"data-queued":f.queued??"unmeasured"},Ky("rect",{x:c,y:u,width:d,height:h,fill:"none",stroke:g,strokeWidth:n===l.nodeId?2.5:1}),Ky("path",{d:ex[l.kind],transform:`translate(${c+10},${u+12})`,stroke:g,fill:"none",strokeWidth:1.4}),Ky("text",{x:m+5,y:u+16,textAnchor:"middle",fontSize:d<110?9:11,fontWeight:600,fill:r},l.semantics.label),Ky("text",{x:m,y:u+28,textAnchor:"middle",fontSize:8,fill:r},tx[l.kind]),Ky("text",{x:m,y:u+41,textAnchor:"middle",fontSize:d<110?7:9,fill:r},x),Ky("text",{x:m,y:u+h-13,textAnchor:"middle",fontSize:8,fill:r},`Queue ${Jy(f.queued)}`),null!==f.queued?Ky("rect",{...p,width:p.width*f.queued/s,fill:g,"data-circuit-gauge":"queue"}):null,Ky("rect",{...e.sensor,fill:i,"data-circuit-sensor":l.nodeId}),l.semantics.dependencyNodeIds?.length?Ky("text",{x:m,y:u-8,fontSize:8,textAnchor:"middle",fill:r,"data-circuit-dependency":l.nodeId},`Requires ${l.semantics.dependencyNodeIds.join(", ")}`):null)})}function rx(e,t,i,r,n,o){let{history:a}=e,s=e.modules.find(e=>e.module.nodeId===o)?.module,l="records"===t.unit?"queued":"attempts",c=t.entries.map(e=>s?e.nodes[s.nodeId]["records"===t.unit?"queued":"arrivals"]:e.totals[l]),u=c.reduce((e,t)=>Math.max(e,t??0),0)||1,d=t.entries[0].at,h=t.entries[t.entries.length-1].at,p=h>d?h-d:1,f=e=>a.x+(e-d)/p*a.width,g="",m=!1;for(let[e,i]of t.entries.entries()){if(null===c[e]){m=!1;continue}let t=a.y+a.height-c[e]/u*a.height;g+=`${m?" H":"M"}${f(i.at)}${m?` V${t}`:`,${t}`}`,m=!0}return Ky("g",{"data-circuit-history":l,"data-history-module":s?.nodeId},Ky("text",{x:a.x,y:a.y-9,fill:n,fontSize:10},s?`${s.semantics.label} · ${"queued"===l?`queued ${s.semantics.unit}`:`offered ${s.semantics.unit}/s`} · aggregate observations`:"queued"===l?"Queued records · aggregate observations":"Offered attempts/s · aggregate observations"),Ky("path",{d:g,fill:"none",stroke:r,strokeWidth:2}),Ky("line",{x1:f(i.observedAt),x2:f(i.observedAt),y1:a.y,y2:a.y+a.height,stroke:n,strokeDasharray:"3 3","data-circuit-cursor":i.observedAt}),...t.entries.map(e=>Ky("text",{key:e.id,x:f(e.at),y:a.y+a.height+14,textAnchor:"middle",fontSize:9,fill:n},`${e.at}s`)))}function nx(e,t,i,r){return{id:r.nodeId,nodeId:r.nodeId,kind:"circuit-module",moduleKind:r.kind,label:r.semantics.label,unit:r.semantics.unit,sourceRevision:t.sourceRevision,analysisRevision:e.atlas.analysisRevision,relationScopeId:"directed-admitted",editionId:t.id,editionKind:t.kind,synthetic:t.synthetic,mode:i.mode,observedAt:i.observedAt,...i.entry.nodes[r.nodeId]}}var ox=e=>null===e?"unmeasured":String(e),ax=Hy.createElement,sx=e=>cx(e,!1),lx=e=>cx(e,!0);function cx(e,t){let{circuit:i,edition:r,reading:n,selection:o}=e.config;if(n.editionId!==r.id||r.analysisRevision!==i.atlas.analysisRevision)throw new Error("Circuit render inputs must share an edition and analysis revision");let a=function(e,t,i){if(!Number.isFinite(t)||!Number.isFinite(i)||t<360||i<300)throw new Error("Circuit geometry needs at least 360 × 300 pixels");let r=[...e.atlas.sections.sectionIds];e.atlas.source.nodes.some(e=>!e.sectionId)&&r.push("Unsectioned");let n=Zf({width:t,height:i-110,padX:22,padY:70,stages:r.map(e=>({id:e})),shape:"lane"}),o=new Map(e.atlas.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),a=n.stages.flatMap(t=>{let r=e.order.filter(e=>o.get(e)===t.id),n=(i-235)/Math.max(1,r.length);if(r.length&&n<78)throw new Error("Increase circuit height to keep every module readable");return r.map((i,r)=>{let o=e.modules.find(e=>e.nodeId===i),a=Math.max(68,Math.min(142,t.width-56)),s=Math.min(68,n-10),l=t.x-a/2,c=95+(r+.5)*n-s/2;return{module:o,x:l,y:c,width:a,height:s,queue:{x:l+8,y:c+s-8,width:a-16,height:4},sensor:{x:l+a-5,y:c+s/2-4,width:8,height:8}}})}),s=new Map(a.map(e=>[e.module.nodeId,e])),l=new Set(e.residualEdgeIds),c=0,u=e.atlas.source.edges.map(e=>{let t,i=s.get(e.source),n=s.get(e.target),a=n.x>i.x,u=n.x===i.x,d=(t,i)=>{let r=t.module.ports.filter(e=>e.direction===i),n=r.findIndex(t=>t.edgeId===e.id);return t.y+10+(n+.5)*(t.height-20)/r.length},h={x:i.x+(a||u?i.width:0),y:d(i,"out")},p={x:n.x+(a?0:n.width),y:d(n,"in")};if(u){let r=h.x+18+5*c++;t=e.source===e.target?[h,{x:r,y:h.y},{x:r,y:i.y-15},{x:p.x-8,y:i.y-15},{x:p.x-8,y:i.y}]:[h,{x:r,y:h.y},{x:r,y:p.y},p]}else if(!a||Math.abs(r.indexOf(o.get(e.source))-r.indexOf(o.get(e.target)))>1){let e=a?1:-1,i=62+7*c++;t=[h,{x:h.x+16*e,y:h.y},{x:h.x+16*e,y:i},{x:p.x-16*e,y:i},{x:p.x-16*e,y:p.y},p]}else{let e=(h.x+p.x)/2;t=[h,{x:e,y:h.y},{x:e,y:p.y},p]}return{edgeId:e.id,source:e.source,target:e.target,residual:l.has(e.id),points:t,pathD:ey(t)}});return{width:t,height:i,modules:a,routes:u,sections:n.stages.map(e=>({id:e.id,x:e.x})),history:{x:42,y:i-88,width:t-84,height:46}}}(i,e.dimensions.width,e.dimensions.height),s=e.theme.semantic.text??"#273442",l=e.theme.semantic.surface??"#fff",c=function(e,t={}){return{observed:t.observed??e.info??e.primary??Qy.observed,modeled:t.modeled??e.secondary??Qy.modeled,residual:t.residual??e.warning??Qy.residual,muted:t.muted??e.textSecondary??Qy.muted,alarm:t.alarm??e.danger??Qy.alarm}}(e.theme.semantic,e.config.colors),u="modeled"===r.kind?c.modeled:c.observed,d={width:a.width,height:a.height,viewBox:`0 0 ${a.width} ${a.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},"aria-hidden":!0},h=o?.analysisRevision===i.atlas.analysisRevision&&"directed-admitted"===o.relationScopeId?o.nodeId:void 0,p=n.entry.flows.reduce((e,t)=>Math.max(e,t.perSecond??0),0)||1,f=new Map(n.entry.flows.map(e=>[e.edgeId,e])),g=new Map(i.modules.map(e=>[e.nodeId,nx(i,r,n,e)])),m=t=>e.config.layoutSelection?.isActive&&!e.config.layoutSelection.predicate(g.get(t))?.2:1,y=Math.max(0,Math.min(200,Math.floor(e.config.particleBudget??24))),x=Q(e.config.placementSeed??1),b=a.routes.filter(e=>(f.get(e.edgeId)?.perSecond??0)>0),v=e.config.reducedMotion?[]:Array.from({length:b.length?y:0},(e,t)=>{let i=b[t%b.length],r=function(e,t){let i=e.slice(1).map((t,i)=>Math.hypot(t.x-e[i].x,t.y-e[i].y)),r=i.reduce((e,t)=>e+t,0),n=Math.max(0,Math.min(1,t))*r;for(let t=0;t<i.length;t++){if(n<=i[t]){let r=i[t]?n/i[t]:0;return{x:e[t].x+(e[t+1].x-e[t].x)*r,y:e[t].y+(e[t+1].y-e[t].y)*r}}n-=i[t]}return e[e.length-1]}(i.points,(x()+n.requestedTime/10)%1);return ax("circle",{key:`cue:${t}`,cx:r.x,cy:r.y,r:2.3,fill:s,opacity:Math.max(m(i.source),m(i.target)),"data-circuit-particle":i.edgeId})}),w=a.modules.map(e=>({id:e.module.nodeId,x:e.x+e.width/2,y:e.y+e.height/2,fixedPosition:{x:e.x+e.width/2,y:e.y+e.height/2},shape:{type:"aabb",width:e.width,height:e.height},bodyCollisions:!1,datum:nx(i,r,n,e.module)})),S=[],k=function(e,t,i,r){return[...t.modules.map(t=>{let n=nx(e,i,r,t.module);return{id:n.id,bodyId:n.id,datum:n,x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height,shape:"rect",label:`${n.label}: ${n.moduleKind}`,description:`${n.label}. ${i.kind} at ${r.observedAt}s. Arrivals ${ox(n.arrivals)} ${n.unit}/s; completions ${ox(n.completions)} ${n.unit}/s; installed capacity ${ox(n.capacity)} ${n.unit}/s; queue ${ox(n.queued)} ${n.unit}. Measurement status: ${n.status}. Individual timings unavailable.`,group:"circuit modules"}}),...t.routes.map(t=>{let n=r.entry.flows.find(e=>e.edgeId===t.edgeId),o=t.points[Math.floor(t.points.length/2)];return{id:`pipe:${t.edgeId}`,x:o.x,y:o.y,shape:"path",pathData:t.pathD,label:`${t.source} → ${t.target}: ${ox(n.perSecond)} ${n.unit}/s`,description:`Original edge ${t.edgeId}. ${t.residual?"Residual link":"Display backbone"}. ${i.kind} at ${r.observedAt}s; transferred volume ${ox(n.perSecond)} ${n.unit}/s.`,group:"original pipes",datum:{id:t.edgeId,kind:"circuit-pipe",source:t.source,target:t.target,analysisRevision:e.atlas.analysisRevision,sourceRevision:i.sourceRevision,relationScopeId:"directed-admitted",editionId:i.id,editionKind:i.kind,observedAt:r.observedAt,...n}}})]}(i,a,r,n),A=t?new Map(k.map(e=>[e.id,e])):null,M={bodies:w,config:{kernel:{gravity:{x:0,y:0},seed:e.config.placementSeed??1,sleepAfter:.01},bodyBudget:!1,bodyLimit:w.length,eviction:!1,sediment:!1,settleStepLimit:4},bodyStyle:e=>({fill:l,stroke:c.muted,strokeWidth:1,opacity:m(e.id)}),colliders:a.modules.flatMap(e=>function(e){let t=e.idPrefix??"lane",i={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},r=[Hf(`${t}-top`,e.left,e.top,e.right,e.top,i),Hf(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,i)];return e.openEnds||r.push(Hf(`${t}-left`,e.left,e.top,e.left,e.bottom,i),Hf(`${t}-right`,e.right,e.top,e.right,e.bottom,i)),r}({idPrefix:`queue:${e.module.nodeId}`,left:e.queue.x,right:e.queue.x+e.queue.width,top:e.queue.y,bottom:e.queue.y+e.queue.height,thickness:1,openEnds:!0})),sensors:a.modules.map(e=>({id:`sensor:${e.module.nodeId}`,shape:{type:"aabb",x:e.sensor.x+e.sensor.width/2,y:e.sensor.y+e.sensor.height/2,width:e.sensor.width,height:e.sensor.height}})),semanticItems:k,backgroundOverlays:ax("svg",d,...a.routes.map(i=>{let r=f.get(i.edgeId),n=i.points[i.points.length-1],o=i.points[i.points.length-2],l=a.modules.find(e=>e.module.nodeId===i.source),d=a.modules.find(e=>e.module.nodeId===i.target),h=l.module.ports.filter(e=>"out"===e.direction).length<d.module.ports.filter(e=>"in"===e.direction).length,g=h?i.points[0]:n,y=h?g.x>=l.x+l.width:g.x>d.x,x=180*Math.atan2(n.y-o.y,n.x-o.x)/Math.PI,b=e.config.highlightedEdgeIds?.includes(i.edgeId),v=b?s:i.residual?c.residual:u,w="records"===r.unit?"rec":"attempts"===r.unit?"att":"roots";if(t){let e=A.get(`pipe:${i.edgeId}`);S.push({type:"curved",pathD:i.pathD,datum:e.datum,id:i.edgeId,label:e.label,accessibility:{label:`${e.label}. ${e.description}`},style:{stroke:v,strokeWidth:null===r.perSecond?1.5:1+r.perSecond/p*7,strokeDasharray:null===r.perSecond?"4 3":void 0,fill:"none",opacity:(0===r.perSecond?.35:.75)*Math.max(m(i.source),m(i.target))}})}return ax("g",{key:i.edgeId,"data-circuit-edge":i.edgeId,opacity:Math.max(m(i.source),m(i.target)),"data-source":i.source,"data-target":i.target,"data-flow":r.perSecond??"unmeasured","data-highlighted":b||void 0,"data-unit":`${r.unit}/s`},ax("title",null,`${i.edgeId}: ${i.source} → ${i.target}; ${r.perSecond??"unmeasured"} ${r.unit}/s`),!t&&ax("path",{d:i.pathD,stroke:v,strokeWidth:null===r.perSecond?1.5:1+r.perSecond/p*7,strokeDasharray:null===r.perSecond?"4 3":void 0,strokeLinejoin:"round",fill:"none",opacity:0===r.perSecond?.35:.75}),ax("path",{d:"M-5,-3 L0,0 L-5,3",transform:`translate(${n.x},${n.y}) rotate(${x})`,fill:"none",stroke:v}),ax("text",{x:g.x+(y?5:-5),y:g.y-7,textAnchor:y?"start":"end",fontSize:8,fill:s},`${null===r.perSecond?"?":Jy(r.perSecond)} ${w}/s`))})),overlays:ax("svg",{...d,"data-circuit-edition":r.kind,"data-circuit-time":n.observedAt},...a.sections.map(e=>ax("text",{key:e.id,x:e.x,y:43,textAnchor:"middle",fontSize:11,fill:s},e.id)),...ix(a,n,u,s,h,c,m),...v,rx(a,r,n,u,s,h),...t?[]:a.routes.map(e=>ax("path",{key:`hit:${e.edgeId}`,d:e.pathD,fill:"none",stroke:"transparent",strokeWidth:12,pointerEvents:"stroke","data-semiotic-semantic-id":`pipe:${e.edgeId}`})),ax("text",{x:a.width/2,y:a.height-8,textAnchor:"middle",fontSize:9,fill:s},`${"modeled"===r.kind?"Modeled":"Observed"} · ${n.observedAt}s · pipe width = transferred volume/s · individual timings unavailable`))};if(!t)return M;let $=e=>e.props.children;return{sceneNodes:w.map(e=>{let t=A.get(e.id);return{type:"rect",id:e.id,x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,datum:e.datum,label:t.label,accessibility:{label:`${t.label}. ${t.description}`},style:{fill:l,stroke:c.muted,strokeWidth:1,opacity:m(e.id)}}}),sceneEdges:S,overlays:ax(Uy,{z:"top"},$(M.backgroundOverlays),$(M.overlays)),perspective:"manual",perspectiveBounds:[{x:0,y:0,width:a.width,height:a.height,z:"top"}]}}import{scaleLinear as ux}from"d3-scale";function dx(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function hx(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,dx(e))}))}function px(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:String(e.bodyId)}):e}function fx(e){return"circuit-pipe"===e.kind?`${e.source} → ${e.target}: ${e.perSecond??"unmeasured"} ${e.unit}/s`:`${e.label??e.id??"Circuit"}: ${e.completions??"unmeasured"} ${e.unit??"units"}/s completed; queue ${e.queued??"unmeasured"}`}function gx({width:e=dt.width,height:t=dt.height,title:i,description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,annotations:u,frameProps:d,perspective:h,networkFrameProps:p,linkedSelection:f,onSelectNode:g,tooltip:m=fx,...y}){return{key:JSON.stringify([y.circuit.atlas.analysisRevision,y.circuit.order,y.circuit.backboneEdgeIds,e,t]),data:y.circuit.modules.map(e=>nx(y.circuit,y.edition,y.reading,e)),layout:sx,layoutConfig:y,width:e,height:t,chartId:a,className:s,onObservation:l,linkedHover:Ay(c),annotations:u,frameProps:d,paused:!0,title:i??y.edition.label,description:r??`${y.edition.label}. ${y.edition.kind} aggregate interval tape at ${y.reading.observedAt} seconds. Pipe widths encode transferred volume per second in their labeled units; module readouts separate completions, capacity and queue stock. Individual timings are unavailable.`,summary:n??y.edition.assumptions.join(" "),accessibleTable:o,tooltip:m}}import*as mx from"react-dom/server";var yx=/*#__PURE__*/Object.create(null);function xx(e,t){yx[e]=t}function bx(e,t){var i=e.get(t);if(!i)throw new Error("missing: "+t);return i}function vx(e){return e.y0-e.y1>0?"up":"down"}function wx(e,t){return t(e.source)==t(e.target)}function Sx(e){return e.target.x0-e.source.x1}function kx(e,t){var i=Mx(e),r=Sx(t)/Math.tan(i);return"up"==vx(e)?e.y1-r:e.y1+r}function Ax(e,t){var i=Mx(e),r=Sx(t)/Math.tan(i);return"up"==vx(e)?e.y1+r:e.y1-r}function Mx(e){var t=Math.abs(e.y1-e.y0),i=Math.abs(e.target.x0-e.source.x1);return Math.atan(i/t)}function $x(e){return Px(e.source)}function _x(e){return Px(e.target)}function Px(e){return(e.y0+e.y1)/2}function Ix(e){return e.virtual?0:e.value}function Tx(e,t){var i=0;e.sourceLinks.forEach(function(e){i=e.circular&&!wx(e,t)?i+1:i});var r=0;return e.targetLinks.forEach(function(e){r=e.circular&&!wx(e,t)?r+1:r}),i+r}function Lx(e){return e.target.depth}function Cx(e,t){return e.sourceLinks.length?e.depth:t-1}function Rx(e,t){return e.y0-t.y0}function Nx(e,t){return t.y0-e.y0}function Dx(e,t){return e.y1-t.y1}function Fx(e,t){return t.y1-e.y1}function Ex(e,t){return zx(e.source,t.source)||e.index-t.index}function Ox(e,t){return zx(e.target,t.target)||e.index-t.index}function zx(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function Bx(e,t){return jx(e)==jx(t)?"bottom"==e.circularLinkType?Nx(e,t):Rx(e,t):jx(t)-jx(e)}function jx(e){return e.target.column-e.source.column}function Wx(e,t){return Yx(e)==Yx(t)}function Yx(e){return e.y0-e.y1>0?"up":"down"}import{min as qx}from"d3-array";var Xx=class{constructor(e){this.size=e,this.maximum=new Float64Array(4*e),this.floor=new Float64Array(4*e)}query(e,t){let i=(r,n,o)=>{if(e<=n&&o<=t)return this.maximum[r];let a=n+o>>>1;return Math.max(this.floor[r],e<=a?i(2*r,n,a):0,t>a?i(2*r+1,a+1,o):0)};return i(1,0,this.size-1)}reserve(e,t,i){let r=(n,o,a)=>{if(this.maximum[n]=Math.max(this.maximum[n],i),e<=o&&a<=t)return void(this.floor[n]=Math.max(this.floor[n],i));let s=o+a>>>1;e<=s&&r(2*n,o,s),t>s&&r(2*n+1,s+1,a)};r(1,0,this.size-1)}};function Gx(e,t,i,r,n){let o=e;o.links.forEach(function(e){e.circular&&(e._circularWidth=e.width,e._circularStub=!1)});var a=qx(o.links,function(e){return e.source.y0});o.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=o.links.filter(function(e){return e.circular}),l=new Map,c=new Map;s.forEach(function(e){l.set(e.source,(l.get(e.source)||0)+1),c.set(e.target,(c.get(e.target)||0)+1)});var u=new Set(s.filter(function(e){return wx(e,t)&&1===l.get(e.source)&&1===c.get(e.target)}));return["top","bottom"].forEach(function(e){var t=s.filter(function(t){return t.circularLinkType===e});(function(e,t,i){if(0!==e.length){e.sort(Bx);var r=Array.from(new Set(e.flatMap(function(e){return[e.source.column,e.target.column]}))).sort(function(e,t){return e-t}),n=new Map(r.map(function(e,t){return[e,t]})),o=new Xx(r.length);e.forEach(function(e){var r=n.get(e.source.column),a=n.get(e.target.column),s=Math.min(r,a),l=Math.max(r,a),c=t.has(e)?0:o.query(s,l);e.circularPathData.verticalBuffer=c+e._circularWidth/2,o.reserve(s,l,c+e._circularWidth+i)})}})(t.slice(),u,i),["source","target"].forEach(function(n){var o=new Map;t.forEach(function(e){var t=e[n].column;o.has(t)||o.set(t,[]),o.get(t).push(e)}),o.forEach(function(t){t.sort("source"===n?"bottom"===e?Nx:Rx:"bottom"===e?Fx:Dx);var o=0,a="source"===n?"right":"left";t.forEach(function(e,t){e.circularPathData[a+"SmallArcRadius"]=r+e._circularWidth/2+o,e.circularPathData[a+"LargeArcRadius"]=r+e._circularWidth/2+t*i+o,o+=e._circularWidth})})})}),o.links.forEach(function(e){e.circular&&(e.circularPathData.arcRadius=e._circularWidth+r,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,u.has(e)?(e.circularPathData.rightSmallArcRadius=r+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=r+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=r+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=r+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)):"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(o.y1,e.source.y1,e.target.y1)+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=a-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius),e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer),e.circular?e.path=function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):e.path=function(e){var t=e.source.x1,i=e.y0,r=e.target.x0,n=e.y1,o=(t+r)/2;return"M"+t+","+i+"C"+o+","+i+" "+o+","+n+" "+r+","+n}(e)}),o}import{min as Vx,max as Hx,sum as Ux,mean as Zx,group as Kx,groups as Qx}from"d3-array";function Jx(e){return function(){return e}}function eb(e){return e.index}function tb(e){return e.nodes}function ib(e){return e.links}function rb(e,t,i){var r=Qx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});r.forEach(function(n,o){var a=n.length;if(t)n.sort(t);else if(o>0){var s=new Map;n.forEach(function(e,t){var i=function(e){var t=0,i=0;return e.targetLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=Px(e.source)*r,t+=r}}),e.sourceLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=Px(e.target)*r,t+=r}}),t>0?i/t:NaN}(e);s.set(e,{bc:i,idx:t})}),n.sort(function(e,t){var i=s.get(e),r=s.get(t),n=i.bc,o=r.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(n)||isNaN(o)?isNaN(n)?isNaN(o)?i.idx-r.idx:1:-1:n-o})}else n.sort(function(e,t){return e.circularLinkType==t.circularLinkType?Tx(t,i)-Tx(e,i):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});n.forEach(function(t,n){t.depth==r.length-1&&1==a||0==t.depth&&1==a?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==Tx(t,i)?(t.y0=e.y1/2+n,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+n,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-n,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/a*n,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-a/2+n,t.y1=t.y0+t.value*e.ky)})})}function nb(e,t,i,r,n,o){var a=Qx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var s=1,l=o;l>0;--l)c(s*=.99,i),u();function c(t,i){var r=a.length;a.forEach(function(n){var o=n.length,a=n[0].depth;n.forEach(function(n){var s;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&Tx(n,i)>0){var l=Zx(n.sourceLinks,_x),c=Zx(n.targetLinks,$x),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Px(n))*t*.3;n.y0+=d,n.y1+=d}}else if(0==a&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(a==r-1&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)s=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+s;else{var h=Zx(n.sourceLinks,_x),p=Zx(n.targetLinks,$x),f=((h&&p?(h+p)/2:h||p)-Px(n))*t;n.y0+=f,n.y1+=f}})})}function u(){a.forEach(function(i){var o,a,s,l=e.y0,c=i.length;for(t?i.sort(t):i.sort(zx),s=0;s<c;++s)(a=l-(o=i[s]).y0)>0&&(o.y0+=a,o.y1+=a),l=o.y1+r;if((a=l-r-e.y1)>0)for(l=o.y0-=a,o.y1-=a,s=c-2;s>=0;--s)(a=(o=i[s]).y1+n-l)>0&&(o.y0-=a,o.y1-=a),l=o.y0})}}function ob(e){e.nodes.forEach(function(e){e.sourceLinks.sort(Ox),e.targetLinks.sort(Ex)}),e.nodes.forEach(function(e){var t=e.y0,i=t,r=e.y1,n=r;e.sourceLinks.forEach(function(e){e.circular?(e.y0=r-e.width/2,r-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=n-e.width/2,n-=e.width):(e.y1=i+e.width/2,i+=e.width)})})}function ab(){var e=0,t=0,i=1,r=1,n=24,o=8,a=null,s=eb,l=Cx,c=void 0,u=32,d=2,h=tb,p=ib;function f(){var f={nodes:h.apply(null,arguments),links:p.apply(null,arguments)};return function(h){h.x0=e,h.y0=t,h.x1=i,h.y1=r,h.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var i=function(e,t){var i=new Map;return Kx(e,t).forEach(function(e,t){i.set(t,e[0])}),i}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var r=e.source,n=e.target;"object"!=typeof r&&(r=e.source=bx(i,r)),"object"!=typeof n&&(n=e.target=bx(i,n)),r.sourceLinks.push(e),n.targetLinks.push(e)})}(h,s),function(e,t,i){var r=0,n=null==t?function(e,t,i){let r=e.length,n=Array.from({length:r},()=>[]),o=Array.from({length:r},()=>[]),a=new Int32Array(r),s=new Int32Array(r),l=new Float64Array(r),c=new Float64Array(t.length),u=new Int32Array(r),d=e.map(e=>{let t=i(e);return`${typeof t}:${String(t)}`}),h=0;for(let e of t)e.source.index!==e.target.index&&Number.isFinite(e.value)&&(h=Math.max(h,e.value));let p=(e,t)=>d[e]<d[t]?-1:d[e]>d[t]?1:0;t.map((e,t)=>t).sort((e,i)=>p(t[e].source.index,t[i].source.index)||p(t[e].target.index,t[i].target.index)||t[e].value-t[i].value).forEach(e=>{let i=t[e],r=i.source.index,u=i.target.index;if(r===u)return;let d=Number.isFinite(i.value)&&h>0?Math.max(0,i.value)/h:0;c[e]=d,o[r].push(e),n[u].push(e),s[r]++,a[u]++,l[r]+=d,l[u]-=d});let f=e.map(e=>e.index),g=Int32Array.from(f),m=e=>0===s[e]?2:0===a[e]?1:0,y=(e,t)=>{let i=m(e),r=m(t);return i!==r?i>r:0===i&&l[e]!==l[t]?l[e]>l[t]:d[e]<d[t]||d[e]===d[t]&&e<t},x=(e,t)=>{let i=f[e];f[e]=f[t],f[t]=i,g[f[e]]=e,g[i]=t},b=(e,t=!1)=>{let i=g[e];for(;!t&&i>0;){let t=i-1>>>1;if(!y(e,f[t]))break;x(i,t),i=t}for(;2*i+1<f.length;){let t=2*i+1;if(t+1<f.length&&y(f[t+1],f[t])&&t++,!y(f[t],e))break;x(i,t),i=t}};for(let e=(f.length>>>1)-1;e>=0;e--)b(f[e],!0);let v=0,w=r-1;for(;f.length;){let e=f[0];u[e]=0===s[e]?w--:v++;let i=f.pop();g[e]=-1,f.length&&(f[0]=i,g[i]=0,b(i));for(let i of o[e]){let e=t[i].target.index;g[e]<0||(a[e]--,l[e]+=c[i],b(e))}for(let i of n[e]){let e=t[i].source.index;g[e]<0||(s[e]--,l[e]-=c[i],b(e))}}return u}(e.nodes,e.links,i):null;e.nodes.forEach(function(e){delete e.circularLinkType}),e.links.forEach(function(e){delete e.circularLinkID,delete e.circularLinkType,delete e.circularPathData,delete e._circularWidth,delete e._circularStub,e.circular=n?n[e.source.index]>=n[e.target.index]:!(t(e.source)<t(e.target)),e.circular&&(e.circularLinkID=r++)})}(h,c,s),function(e,t){var i=0,r=0;e.links.forEach(function(e){e.circular&&(e.source.circularLinkType||e.target.circularLinkType?e.circularLinkType=e.source.circularLinkType?e.source.circularLinkType:e.target.circularLinkType:e.circularLinkType=i<r?"top":"bottom","top"==e.circularLinkType?i++:r++,e.source.circularLinkType=e.circularLinkType,e.target.circularLinkType=e.circularLinkType)}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),wx(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(h,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(Ux(e.sourceLinks,Ix),Ux(e.targetLinks,Ix)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(h),function(e,t,i){if(null!=t&&e.nodes.length){e.nodes.sort(function(e,i){return t(e)<t(i)?-1:1});var r=0,n=t(e.nodes[0]);e.nodes.forEach(function(e){r=t(e)==n?r:r+1,n=t(e)==n?n:t(e),e.column=r})}var o=new Int32Array(e.nodes.length),a=[],s=1;e.nodes.forEach(function(e){e.depth=e.height=0,e.targetLinks.forEach(function(t){t.circular||o[e.index]++}),0===o[e.index]&&a.push(e)});for(var l=0;l<a.length;l++){var c=a[l];s=Math.max(s,c.depth+1),c.sourceLinks.forEach(function(e){e.circular||(e.target.depth=Math.max(e.target.depth,c.depth+1),0===--o[e.target.index]&&a.push(e.target))})}for(l=a.length-1;l>=0;l--)(c=a[l]).sourceLinks.forEach(function(e){e.circular||(c.height=Math.max(c.height,e.target.height+1))});e.nodes.forEach(function(e){e.column=null==t?i(e,s):e.column})}(h,c,l);var p=o;if(null!==a){var f=Qx(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=Hx(f,function(e){return e.length});g>1&&(p=Math.max(1,(r-t)*a/(g-1)))}(function(e,t,i){var r=Qx(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var n=Vx(r,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/Ux(t,function(e){return e.value})});e.ky=n,e.links.forEach(function(t){t.width=t.value*e.ky});var o=Hx(e.nodes,function(e){return e.column});o>0?e.nodes.forEach(function(t){t.x0=e.x0+t.column*((e.x1-e.x0-i)/o),t.x1=t.x0+i}):e.nodes.forEach(function(t){t.x0=e.x0,t.x1=t.x0+i})})(h,p,n),rb(h,c,s),nb(h,c,s,p,p,u),ob(h),rb(h,c,s),nb(h,c,s,p,p,u),ob(h),function(e){let t=e;t.nodes.forEach(function(e){e.y+(e.y1-e.y0)>t.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-t.y1));var i=e.sourceLinks.slice().sort(function(e,t){return e.index-t.index});i.length>1&&i.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!Wx(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var i=kx(t,e);return e.y1-i}if(t.target.column>e.target.column)return kx(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var r=e.y0;i.forEach(function(e){e.y0=r+e.width/2,r+=e.width});for(var n=0,o=i.length-1;o>=0;o--){var a=i[o];"bottom"==a.circularLinkType&&(a.y0=e.y1-n-a.width/2),n+=a.width}})}(h),function(e){e.nodes.forEach(function(e){var t=e.targetLinks.slice().sort(function(e,t){return e.index-t.index});t.length>1&&t.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!Wx(e,t))return e.y0-t.y0;if(t.source.column<e.source.column){var i=Ax(t,e);return e.y0-i}if(e.source.column<t.source.column)return Ax(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;t.forEach(function(e){e.y1=i+e.width/2,i+=e.width});for(var r=0,n=t.length-1;n>=0;n--){var o=t[n];"bottom"==o.circularLinkType&&(o.y1=e.y1-r-o.width/2),r+=o.width}})}(h),function(e){var t=e.nodes,i=e.links,r=!1,n=!1;if(i.forEach(function(e){"top"==e.circularLinkType?r=!0:"bottom"==e.circularLinkType&&(n=!0)}),0==r||0==n){let r=function(t){return(t-o)/(a-o)*(e.y1-e.y0)+e.y0};var o=Vx(t,function(e){return e.y0}),a=Hx(t,function(e){return e.y1}),s=a-o,l=(e.y1-e.y0)/s;l<1?(t.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1)}),i.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,i=r(e.y0)-e.y0;e.y0=r(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+i}),e.targetLinks.forEach(function(e){e.y1=e.y1+i})})}}(h),Gx(h,s,d,10,8)}(f),f}return f.update=function(e){return ob(e),Gx(e,s,d,10,8),e},f.nodeWidth=function(e){return arguments.length?(n=+e,f):n},f.nodePadding=function(e){return arguments.length?(o=+e,f):o},f.nodePaddingRatio=function(e){return arguments.length?(a=+e,f):a},f.nodes=function(e){return arguments.length?(h="function"==typeof e?e:Jx(e),f):h},f.links=function(e){return arguments.length?(p="function"==typeof e?e:Jx(e),f):p},f.nodeId=function(e){return arguments.length?(s="function"==typeof e?e:Jx(e),f):s},f.nodeAlign=function(e){return arguments.length?(l="function"==typeof e?e:Jx(e),f):l},f.nodeSort=function(e){return arguments.length?(c=e,f):c},f.iterations=function(e){return arguments.length?(u=+e,f):u},f.circularLinkGap=function(e){return arguments.length?(d=+e,f):d},f.extent=function(n){return arguments.length?(e=+n[0][0],t=+n[0][1],i=+n[1][0],r=+n[1][1],f):[[e,t],[i,r]]},f.size=function(n){return arguments.length?(e=t=0,i=+n[0],r=+n[1],f):[i-e,r-t]},f}import{interpolateNumber as sb}from"d3-interpolate";function lb(e){let{sx:t,sTop:i,sBot:r,tx:n,tTop:o,tBot:a,cp1X:s,cp2X:l}=e,c=(i+r)/2,u=(o+a)/2;return{pathD:[`M${t},${i}`,`C${s},${i} ${l},${o} ${n},${o}`,`L${n},${a}`,`C${l},${a} ${s},${r} ${t},${r}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:s,y:c},{x:l,y:u},{x:n,y:u}],halfWidth:(r-i)/2}}}var cb=e=>{let{source:t,target:i}=e;if("string"==typeof t||"string"==typeof i)return null;if("down"===e.direction){let r=e.y0-e.sankeyWidth/2,n=e.y1-e.sankeyWidth/2,o=e.y1+e.sankeyWidth/2,a=e.y0+e.sankeyWidth/2,s=t.x1,l=i.x0,c=sb(s,l),u=c(.5),d=c(.5);return`M${r},${s}C${r},${u} ${n},${d} ${n},${l}L${o},${l}C${o},${d} ${a},${u} ${a},${s}Z`}let r=e.sankeyWidth/2,n=sb(t.x1,i.x0),{pathD:o}=lb({sx:t.x1,sTop:e.y0-r,sBot:e.y0+r,tx:i.x0,tTop:e.y1-r,tBot:e.y1+r,cp1X:n(.5),cp2X:n(.5)});return o};function ub(e){let t=e.circularPathData;if(!t)return null;let i=e.sankeyWidth/2,r="bottom"===e.circularLinkType?1:-1,n=1===r?1:0,o="down"===e.direction,a=(e,t)=>o?`${t},${e}`:`${e},${t}`,s=(e,t,i,r,n)=>`A${o?t:e},${o?e:t} 0 0 ${o?1-i:i} ${a(r,n)}`,{sourceX:l,sourceY:c,targetX:u,targetY:d,rightInnerExtent:h,leftInnerExtent:p,rightFullExtent:f,leftFullExtent:g,verticalFullExtent:m,verticalRightInnerExtent:y,verticalLeftInnerExtent:x,rightLargeArcRadius:b,rightSmallArcRadius:v,leftLargeArcRadius:w,leftSmallArcRadius:S}=t;return`M${a(l,c-r*i)}L${a(h,c-r*i)}`+s(b+i,v+i,n,f+i,c+r*v)+`L${a(f+i,y)}`+s(b+i,b+i,n,h,m+r*i)+`L${a(p,m+r*i)}`+s(w+i,w+i,n,g-i,x)+`L${a(g-i,d+r*S)}`+s(w+i,S+i,n,p,d-r*i)+`L${a(u,d-r*i)}L${a(u,d+r*i)}L${a(p,d+r*i)}`+s(w-i,S-i,1-n,g+i,d+r*S)+`L${a(g+i,x)}`+s(w-i,w-i,1-n,p,m-r*i)+`L${a(h,m-r*i)}`+s(b-i,b-i,1-n,f-i,y)+`L${a(f-i,c+r*v)}`+s(b-i,v-i,1-n,h,c+r*i)+`L${a(l,c+r*i)}Z`}var db=/*#__PURE__*/new Set,hb=/*#__PURE__*/new WeakMap;function pb(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let i=hb.get(e);if(i){let e=i.get(t);if(e)return e}else i=new Map,hb.set(e,i);let r=new Proxy(e,{get(e,i,r){if("string"==typeof i&&!(i in e)&&e.data&&i in e.data){let e=`${t}:${i}`;db.has(e)||(db.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${i}" on the wrapper object, but it only exists on ".data". Use d.data.${i} (or d.data?.${i}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,i,r)}});return i.set(t,r),r}var fb={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(Lx))-1:0},justify:Cx},gb={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeAlign||"justify",a=i.nodeWidth??15,s=i.nodePaddingRatio??.05,l=i.iterations??300;for(let e of t)e.sankeyWidth=0,e.circular=!1,delete e.circularPathData,delete e._circularWidth,delete e._circularStub;for(let t of e)t.value=0,t.width=t.height=0,t.x0=t.x1=t.y0=t.y1=0,t.sourceLinks=[],t.targetLinks=[];let c=new Set(e.map(e=>e.id)),u=new Set,d=t.filter(e=>{let t=K(e.source),i=K(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!c.has(t)||!c.has(i)||(u.add(t),u.add(i),0))}).map(e=>({...e,source:K(e.source),target:K(e.target)}));if(0===d.length)return;let h,p=e.filter(e=>u.has(e.id)).map(e=>({...e}));h="down"===n?[[0,0],[r[1],r[0]]]:[[0,0],[r[0],r[1]]];let f=ab().extent(h).links(d).nodes(p).nodeAlign(fb[o]||Cx).nodeId(e=>e.id).nodeWidth(a).iterations(l);f.nodePaddingRatio&&f.nodePaddingRatio(s),f();{let e=1/0,t=-1/0,i=1/0,r=-1/0;for(let n of p)n.x0<e&&(e=n.x0),n.x1>t&&(t=n.x1),n.y0<i&&(i=n.y0),n.y1>r&&(r=n.y1);for(let n of d){if(!n.circular||!n.circularPathData)continue;let o=n.circularPathData,a=(n._circularWidth??n.width??0)/2;o.leftFullExtent-a<e&&(e=o.leftFullExtent-a),o.rightFullExtent+a>t&&(t=o.rightFullExtent+a),o.verticalFullExtent-a<i&&(i=o.verticalFullExtent-a),o.verticalFullExtent+a>r&&(r=o.verticalFullExtent+a)}let n=t-e,o=r-i,a=h[1][0],s=h[1][1];if(n>0&&o>0&&(e<0||i<0||t>a||r>s)){let t=a/n,r=s/o,l=Math.min(t,r),c=-e*l+(a-n*l)/2,u=-i*l+(s-o*l)/2;for(let e of p)e.x0=e.x0*l+c,e.x1=e.x1*l+c,e.y0=e.y0*l+u,e.y1=e.y1*l+u;for(let e of d)if(e.y0=e.y0*l+u,e.y1=e.y1*l+u,e.width=(e.width??0)*l,e._circularWidth&&(e._circularWidth*=l),e.circular&&e.circularPathData){let t=e.circularPathData;t.sourceX=t.sourceX*l+c,t.targetX=t.targetX*l+c,t.sourceY=t.sourceY*l+u,t.targetY=t.targetY*l+u,t.rightFullExtent=t.rightFullExtent*l+c,t.leftFullExtent=t.leftFullExtent*l+c,t.verticalFullExtent=t.verticalFullExtent*l+u,t.rightInnerExtent=t.rightInnerExtent*l+c,t.leftInnerExtent=t.leftInnerExtent*l+c,t.verticalRightInnerExtent=t.verticalRightInnerExtent*l+u,t.verticalLeftInnerExtent=t.verticalLeftInnerExtent*l+u,t.rightSmallArcRadius*=l,t.rightLargeArcRadius*=l,t.leftSmallArcRadius*=l,t.leftLargeArcRadius*=l,t.sourceWidth*=l,t.rightNodeBuffer*=l,t.leftNodeBuffer*=l,t.arcRadius*=l}}}let g=new Map;for(let t of e)g.set(t.id,t);for(let e of p){let t=g.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}let m=new Map;for(let e of t)if(e._edgeKey)m.set(e._edgeKey,e);else{let t=K(e.source),i=K(e.target);m.set(`${t}\0${i}`,e)}for(let e of d){let t=K(e.source),i=K(e.target),r=e._edgeKey?m.get(e._edgeKey):m.get(`${t}\0${i}`);if(r){r.y0=e.y0,r.y1=e.y1,r.sankeyWidth=e.width??0,r.circular=!!e.circular,r.circularPathData=e.circularPathData,r._circularWidth=e._circularWidth,r._circularStub=e._circularStub,r.path=e.path,r.circularLinkType=e.circularLinkType,r.direction=n;let o=g.get(t),a=g.get(i);o&&(r.source=o),a&&(r.target=a)}}},buildScene(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeStyle,a=i.edgeStyle,s=i.edgeOpacity??.5,l=i.edgeColorBy||"source",c=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Ct,u=new Map;e.forEach((e,t)=>{u.set(e.id,c[t%c.length])});let d=[],h=[],p=[],f=new Map;for(let t of e){let e=t.x1-t.x0,i=t.y1-t.y0;if(t.value<=0||e<=0||i<=0)continue;let r=o?o(pb(t,"nodeStyle")):{},a={fill:r.fill||u.get(t.id)||"#4d430c",stroke:r.stroke,strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor};f.set(t.id,("string"==typeof a.fill?a.fill:null)||u.get(t.id)||"#4d430c");let s={...t.data,value:t.data?.value??t.value};"down"===n?d.push({type:"rect",x:t.y0,y:t.x0,w:i,h:e,style:a,accessibleDatum:s,datum:t,id:t.id,label:t.id}):d.push({type:"rect",x:t.x0,y:t.y0,w:e,h:i,style:a,accessibleDatum:s,datum:t,id:t.id,label:t.id})}let g=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let e of g){if(!(e.value>0)||!e.sankeyWidth||e.sankeyWidth<=0)continue;let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof l?l(e)||n:"target"===l?f.get(r.id)||u.get(r.id)||n:f.get(t.id)||u.get(t.id)||n;let o,c=a?a(pb(e,"edgeStyle")):{};if(o=e.circular&&e.circularPathData?ub(e):cb(e),!o)continue;let d={fill:c.fill||n,fillOpacity:c.fillOpacity??s,stroke:c.stroke||"none",strokeWidth:c.strokeWidth,strokeOpacity:c.strokeOpacity,opacity:c.opacity,cursor:c.cursor};h.push({type:"bezier",pathD:o,bezierCache:e.bezier,style:d,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=Z(i.nodeLabel);for(let i of e){let e=i.x1-i.x0,o=i.y1-i.y0;if(i.value<=0||e<=0||o<=0)continue;let a,s,l,c=t?t(i):i.id;if(c){if("down"===n)a=i.y0+(i.y1-i.y0)/2,s=i.x1+14,l="start";else{let t=r[0]/2;i.x0+e/2<t?(a=i.x0-6,l="end"):(a=i.x1+6,l="start"),s=i.y0+o/2}p.push({x:a,y:s,text:String(c),anchor:"down"===n?"middle":l,baseline:"middle",fontSize:11})}}}return{sceneNodes:d,sceneEdges:h,labels:p}}};import{forceSimulation as mb,forceCenter as yb,forceX as xb,forceY as bb,forceLink as vb,forceManyBody as wb,forceCollide as Sb}from"d3-force";import{scaleLinear as kb}from"d3-scale";function Ab(e,t,i){if(i.some(e=>null!=e.__forceRadius))return e=>e.__forceRadius??8;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;let r=t||[5,20],n=[];for(let t of i){let i=t.data?.[e];"number"==typeof i&&n.push(i)}if(0===n.length)return()=>r[0];let[o,a]=ue(n);if(o===a)return()=>(r[0]+r[1])/2;let s=kb().domain([o,a]).range(r).clamp(!0);return t=>{let i=t.data?.[e];return null==i||"number"!=typeof i?r[0]:s(i)}}var Mb={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let n=i.forceStrength??.1,o=r[0]/2,a=r[1]/2,s=Math.max(.1,Math.min(1,Math.min(r[0],r[1])/200)),l=Math.min(.5,.06+1.8*(1-s)),c=i.__previousPositions,u=0,d=[];for(let t of e){let e=!1!==t.__hasPosition&&Number.isFinite(t.x)&&Number.isFinite(t.y),i=c?.get(t.id);e?u++:i?(t.x=i.x,t.y=i.y,u++):d.push(t)}let h=e.length>0?d.length/e.length:1,p=u>0&&h<=.3;if(p){let i=new Map;for(let t of e)i.set(t.id,t);for(let e of d){let r=$b(e.id,t,i);if(r.length>0){let t=0,i=0;for(let e of r)t+=e.x,i+=e.y;let n=_b(e.id),o=n%360*(Math.PI/180),a=(10+n%20)*s;e.x=t/r.length+a*Math.cos(o),e.y=i/r.length+a*Math.sin(o)}else{let t=_b(e.id),i=t%360*(Math.PI/180),r=(15+t%30)*s;e.x=o+r*Math.cos(i),e.y=a+r*Math.sin(i)}}}else{let t=Math.PI*(3-Math.sqrt(5));for(let i=0;i<e.length;i++){let r=e[i];if(!1===r.__hasPosition||!Number.isFinite(r.x)||!Number.isFinite(r.y)){let e=10*Math.sqrt(i+.5)*s,n=i*t;r.x=o+e*Math.cos(n),r.y=a+e*Math.sin(n)}}}for(let t of e)t.__hasPosition=!0;let f=e.length,g=i.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(f-30)))),m=i.__skipForceSimulation||0===i.iterations?0:p?40:g,y=Ab(i.nodeSize,i.nodeSizeRange,e);if(m>0){let c=new Map,u=new Map;for(let t of e)c.set(t.id,0),u.set(t.id,t);for(let e of t){let t=K(e.source),i=K(e.target);c.set(t,(c.get(t)??0)+1),c.set(i,(c.get(i)??0)+1)}let d=vb().strength(e=>{let t=function(e){let t=e.data?.weight??e.weight;return"number"==typeof t&&Number.isFinite(t)?t:Number.isFinite(e.value)?e.value:1}(e),i=K(e.source),r=K(e.target),o=Math.max(1,Math.min(c.get(i)??1,c.get(r)??1)),a=t&&t>0?Math.sqrt(t):1;return Math.min(2.5,a*n/(.1*o))}).distance(e=>{let t="string"==typeof e.source?u.get(e.source):e.source,i="string"==typeof e.target?u.get(e.target):e.target,r=(t?y(t):0)+(i?y(i):0)+Math.max(6,12*s);return Math.max(16,40*s,r)}).id(e=>e.id),h=mb();if((void 0!==i.random||void 0!==i.seed)&&h.randomSource(i.random??function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(i.seed)),h.force("charge",wb().strength(e=>{let t=c.get(e.id)??0;return-15*s*y(e)*Math.sqrt(t+1)})).force("collide",Sb(e=>y(e)+3*s).strength(.9).iterations(2)).force("center",yb(o,a).strength(.8)).force("x",xb(o).strength(l)).force("y",bb(a).strength(l)).force("bounds",function(e,t,i=2,r=.6){let n=[],o=o=>{let a=r*Math.max(o,.2);for(let r of n){let n=r.x??e[0]/2,o=r.y??e[1]/2,s=r.vx??0,l=r.vy??0,c=t(r)+i,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),h=Math.min(e[1]/2,c),p=Math.max(e[1]/2,e[1]-c),f=n+s,g=o+l;f<u?r.vx=s+(u-f)*a:f>d&&(r.vx=s+(d-f)*a),g<h?r.vy=l+(h-g)*a:g>p&&(r.vy=l+(p-g)*a)}};return o.initialize=e=>{n=e},o}(r,y)),h.nodes(e),t.length>0){let e=t.map(e=>({...e,source:K(e.source),target:K(e.target)}));d.links(e),h.force("link",d)}p?h.alpha(.3):h.alpha()<.1&&h.alpha(1),h.stop();for(let e=0;e<m;++e)h.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=y(t),i=m>0?2:0,n=Math.min(r[0]/2,e+i),o=Math.min(r[1]/2,e+i);t.x=Math.max(n,Math.min(r[0]-n,t.x)),t.y=Math.max(o,Math.min(r[1]-o,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let x=new Map;for(let t of e)x.set(t.id,t);for(let e of t){if("string"==typeof e.source){let t=x.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=x.get(e.target);t&&(e.target=t)}}},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=Ab(i.nodeSize,i.nodeSizeRange,e),s=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Ct,l=new Map;e.forEach((e,t)=>{l.set(e.id,s[t%s.length])});let c=[],u=[],d=[];for(let t of e){if(null==t.x||null==t.y)continue;let e=a(pb(t,"nodeSize")),r=n?n(pb(t,"nodeStyle")):{},o={fill:r.fill||l.get(t.id)||i.themeSemantic?.primary||"#007bff",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??2,opacity:r.opacity,cursor:r.cursor};c.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,accessibleDatum:t.data,datum:t,id:t.id,label:t.id})}let h=new Map;for(let t of e)h.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:h.get(e.source),r="object"==typeof e.target?e.target:h.get(e.target);if(!t||!r||null==t.x||null==t.y||null==r.x||null==r.y)continue;let n=o?o(pb(e,"edgeStyle")):{},a={stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor};u.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:a,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=Z(i.nodeLabel);for(let i of e){if(null==i.x||null==i.y)continue;let e=t?t(i):i.id;if(!e)continue;let r=a(pb(i,"nodeSize"));d.push({x:i.x,y:i.y-r-4,text:String(e),anchor:"middle",baseline:"auto",fontSize:11,anchorPoint:[i.x,i.y]})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function $b(e,t,i){let r=[];for(let n of t){let t=K(n.source),o=K(n.target),a=null;if(t===e?a=o:o===e&&(a=t),a){let e=i.get(a);e&&(0!==e.x||0!==e.y)&&r.push({x:e.x,y:e.y})}}return r}function _b(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return Math.abs(t)}import{chord as Pb,ribbon as Ib}from"d3-chord";import{arc as Tb}from"d3-shape";var Lb=Ct,Cb={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,i,r){for(let t of e)delete t.__arcData;for(let e of t)delete e.__chordData,delete e.__chordEdges;if(0===e.length)return;let{padAngle:n=.01,groupWidth:o=20,sortGroups:a}=i,s=Math.min(r[0],r[1])/2,l=s-o,c=r[0]/2,u=r[1]/2,d=new Map(e.map(e=>[e.id,e])),h=new Set,p=t.filter(e=>{let t=K(e.source),i=K(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!d.has(t)||!d.has(i)||(h.add(t),h.add(i),0))}),f=e.filter(e=>h.has(e.id)),g=f.length;if(0===g)return;let m=new Map(f.map((e,t)=>[e.id,t])),y=Array.from({length:g},()=>new Array(g).fill(0)),x=new Map;for(let e of p){let t=K(e.source),i=K(e.target),r=m.get(t),n=m.get(i);y[r][n]+=e.value;let o=r<=n?`${r}\0${n}`:`${n}\0${r}`,a=x.get(o);a?a.push(e):x.set(o,[e])}let b=Math.min(Number.isFinite(n)?Math.max(0,n):.01,Math.PI/g),v=Pb().padAngle(b);a&&v.sortGroups(a);let w=v(y),S=w.groups,k=Tb().innerRadius(l).outerRadius(s);for(let e of S){let t=f[e.index],i={innerRadius:l,outerRadius:s,startAngle:e.startAngle,endAngle:e.endAngle},r=k.centroid(i);t.x=r[0]+c,t.y=r[1]+u,t.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}for(let e of t){let t=K(e.source),i=K(e.target),r=d.get(t),n=d.get(i);r&&(e.source=r),n&&(e.target=n)}for(let e of w){let t=e.source.index,i=e.target.index,r=t<=i?`${t}\0${i}`:`${i}\0${t}`,n=x.get(r);for(let t of n)t.__chordData=e,t.__chordEdges=n}},buildScene(e,t,i,r){let{groupWidth:n=20,edgeOpacity:o=.5}=i,a=Math.min(r[0],r[1])/2,s=a-n,l=r[0]/2,c=r[1]/2,u=i.nodeStyle,d=i.edgeStyle,h=i.edgeColorBy||"source",p=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:Lb,f=new Map;e.forEach((e,t)=>{f.set(e.id,p[t%p.length])});let g=Ib().radius(s),m=[],y=[],x=[];for(let t=0;t<e.length;t++){let i=e[t],r=i.__arcData;if(!r)continue;let n=u?u(pb(i,"nodeStyle")):{},o={fill:("string"==typeof n.fill?n.fill:void 0)||f.get(i.id)||p[t%p.length],stroke:n.stroke||"black",strokeWidth:n.strokeWidth??1,opacity:n.opacity,cursor:n.cursor};m.push({type:"arc",cx:l,cy:c,innerR:s,outerR:a,startAngle:r.startAngle-Math.PI/2,endAngle:r.endAngle-Math.PI/2,style:o,accessibleDatum:i.data,datum:i,id:i.id,label:i.id})}let b=new Set,v=e.filter(e=>e.__arcData);for(let e of t){let t=e.__chordData;if(!t||b.has(t))continue;b.add(t);let r=v[t.source.index].id;for(let t of e.__chordEdges||[])K(t.source)===r&&(e=t);let n=g(t);if(!n)continue;let a=Rb(n,l,c),s=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",u=d?d(pb(e,"edgeStyle")):{};if(d)s=("string"==typeof u.fill?u.fill:void 0)||s;else{let t="object"==typeof e.source?e.source:null,i="object"==typeof e.target?e.target:null;"target"===h&&i?s=f.get(i.id)||s:t&&(s=f.get(t.id)||s)}let p={fill:s,fillOpacity:u.fillOpacity??o,stroke:u.stroke||"none",strokeWidth:u.strokeWidth,strokeOpacity:u.strokeOpacity,opacity:u.opacity,cursor:u.cursor};y.push({type:"ribbon",pathD:a,style:p,accessibleDatum:e.data,datum:e})}if(!1!==i.showLabels){let t=Z(i.nodeLabel),r=a+12;for(let i of e){let e=i.__arcData;if(!e)continue;let n=t?t(i):i.id;if(!n)continue;let o=(e.startAngle+e.endAngle)/2,a=o-Math.PI/2,s=l+Math.cos(a)*r,u=c+Math.sin(a)*r,d=o>Math.PI?"end":"start";x.push({x:s,y:u,text:String(n),anchor:d,baseline:"middle",fontSize:11})}}return{sceneNodes:m,sceneEdges:y,labels:x}}};function Rb(e,t,i){let r=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!r)return e;let n=[],o=0;for(;o<r.length;){let e=r[o];if("M"===e||"L"===e||"C"===e||"Q"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(String(Number(r[o])+t)),o++,o<r.length&&!isNaN(Number(r[o]))&&(n.push(String(Number(r[o])+i)),o++);else if("A"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&(n.push(String(Number(r[o])+t)),o++),o<r.length&&(n.push(String(Number(r[o])+i)),o++);else"Z"===e||"z"===e?(n.push(e),o++):(n.push(r[o]),o++)}return n.join(" ")}import{hierarchy as Nb,tree as Db,cluster as Fb,treemap as Eb,pack as Ob,partition as zb,treemapBinary as Bb}from"d3-hierarchy";var jb=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Wb(e){let[t,i,r]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[0,2,4].map(e=>parseInt(t.slice(e,e+2),16))}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*i+.114*r>150?"#222":"#fff"}function Yb(e){if(e)return"function"==typeof e?e:t=>t[e]}function qb(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function Xb(e){let t=new Map(e.map(e=>[e,0]));return e.map(e=>{let i=t.get(e),r=e;for(;i>0&&t.has(r);)r=`${e}__${i++}`;return t.set(e,i||1),t.set(r,1),r})}function Gb(e,t,i){if(t.colorByDepth&&void 0!==e.depth){let i=function(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:jb}(t);return i[e.depth%i.length]}return i||function(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}(t)}function Vb(e,t,i){return{fill:Gb(e,t,i.fill),stroke:i.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity,cursor:i.cursor}}function Hb(e){return!e.__hierarchyNode?.children?.length}function Ub(e,t,i,r,n){let o=(e+i)/2,a=(t+r)/2;return"horizontal"===n?`M ${e},${t} C ${o},${t} ${o},${r} ${i},${r}`:"radial"===n?`M ${e},${t} Q ${o},${t} ${o},${a} T ${i},${r}`:`M ${e},${t} C ${e},${a} ${i},${a} ${i},${r}`}var Zb={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;if(!n)return;let o=i.chartType,a=Yb(i.childrenAccessor),s=Nb(n,a),l=[];s.eachBefore(e=>l.push(e));let c=Xb(l.map((e,t)=>function(e,t,i){let r=t.nodeIDAccessor,n=e.data;return String("function"==typeof r?r(n):"string"==typeof r&&void 0!==n[r]?n[r]:void 0!==n.name?n.name:void 0!==n.id?n.id:`node-${i}`)}(e,i,t)));s.sum(function(e="value"){let t="function"==typeof e?e:t=>t[e];return e=>{let i=t(e),r="string"==typeof i?Number(i):i;return Number.isFinite(r)&&r>0?r:0}}(i.hierarchySum)).sort((e,t)=>t.value-e.value);let[u,d]=r;switch(o){case"tree":case"cluster":!function(e,t,i,r){let n=t.treeOrientation||"vertical",o="cluster"===t.chartType?Fb():Db();if("horizontal"===n)o.size([r,i]);else if("radial"===n){let e=Math.min(i,r)/2;o.size([2*Math.PI,.8*e])}else o.size([i,r]);o(e)}(s,i,u,d);break;case"treemap":case"partition":!function(e,t,i,r){let n="treemap"===t.chartType,o=n?Eb().tile(Bb):zb();o.size([i,r]).padding(t.padding??(n?4:1)),"paddingTop"in o&&t.paddingTop>0&&o.paddingTop(t.paddingTop),o(e)}(s,i,u,d);break;case"circlepack":!function(e,t,i,r){let n=t.padding??4,o=Ob().size([i,r]).padding(n);e.leaves().some(e=>e.value)||o.radius(()=>0).padding(0),o(e)}(s,i,u,d)}let h=s.descendants();e.length=0,t.length=0;let p=new Map(l.map((e,t)=>[e,{id:c[t],x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:e.value,depth:e.depth,data:e.data,createdByFrame:!0}]));for(let t of h){let r=p.get(t);"tree"===o||"cluster"===o?Kb(r,t,i):"treemap"===o||"partition"===o?Qb(r,t):"circlepack"===o&&Jb(r,t),r.__hierarchyNode=t,e.push(r)}if("tree"===o||"cluster"===o)for(let e of h)if(e.parent){let i=p.get(e.parent),r=p.get(e);t.push({source:i,target:r,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,i,r){let n=i.chartType,o=i.nodeStyle||(()=>({})),a=i.edgeStyle||(()=>({}));switch(n){case"tree":case"cluster":return function(e,t,i,r,n,o){let a=[],s=[],l=[],c=i.treeOrientation||"vertical",u="radial"===c,d=r[0]/2,h=r[1]/2,{nodeSize:p}=i,f="number"==typeof p?p:5;for(let t of e){let e=t.x,r=t.y;u&&(e+=d,r+=h);let o=Vb(t,i,n(pb(t,"nodeStyle")));a.push({type:"circle",cx:e,cy:r,r:f,style:o,accessibleDatum:{...t.data,value:t.data?.value??t.value},datum:t,id:t.id,label:t.id,depth:t.depth})}let g=i.edgeOpacity??.5;for(let e of t){let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=t.x,a=t.y,l=r.x,p=r.y;u&&(n+=d,a+=h,l+=d,p+=h);let f=Ub(n,a,l,p,c),m=o(pb(e,"edgeStyle")),y={fill:"none",stroke:m.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:m.strokeWidth??1.5,opacity:m.opacity??g,cursor:m.cursor};s.push({type:"curved",pathD:f,style:y,datum:e})}if(!1!==i.showLabels){let t=qb(i.nodeLabel);for(let i of e){let e=t?t(i):i.id;if(!e)continue;let r,n,o,a=i.x,s=i.y;if(u&&(a+=d,s+=h),u){let e=a-d,t=s-h,i=Math.sqrt(e*e+t*t);i>0?(r=a+e/i*10,n=s+t/i*10,o=e>=0?"start":"end"):(r=a,n=s-12,o="middle")}else"horizontal"===c?(Hb(i)?(r=a+f+6,o="start"):(r=a-f-6,o="end"),n=s):(r=a,n=s+f+14,o="middle");l.push({x:r,y:n,text:String(e),anchor:o,baseline:"middle",fontSize:11,anchorPoint:[a,s]})}}return{sceneNodes:a,sceneEdges:s,labels:l}}(e,t,i,r,o,a);case"treemap":case"partition":return function(e,t,i){let r=[],n=[];for(let n of e){let e=n.x1-n.x0,o=n.y1-n.y0;if(e<=0||o<=0)continue;let a=i(pb(n,"nodeStyle")),s=Vb(n,t,a);s.fillOpacity=a.fillOpacity,s.strokeOpacity=a.strokeOpacity,r.push({type:"rect",x:n.x0,y:n.y0,w:e,h:o,style:s,accessibleDatum:{...n.data,value:n.data?.value??n.value},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=qb(t.nodeLabel),o=t.labelMode||"leaf",a="partition"===t.chartType;for(let s of e){let e=s.x1-s.x0,l=s.y1-s.y0;if(e<=0||l<=0)continue;let c=Hb(s);if(!a&&("leaf"===o&&!c||"parent"===o&&c))continue;let u=r?r(s):s.id;if(!u)continue;if(e<(c?30:40)||l<(c?16:14))continue;let d=Gb(s,t,i(pb(s,"nodeStyle")).fill),h="string"==typeof d?Wb(d):t.themeSemantic?.text??"#000";c?n.push({x:s.x0+e/2,y:s.y0+l/2,text:String(u),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,l)/6)),fill:h}):n.push({x:s.x0+4,y:s.y0+12,text:String(u),anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:r,sceneEdges:[],labels:n}}(e,i,o);case"circlepack":return function(e,t,i){let r=[],n=[];for(let n of e){let e=n.__radius??5;if(e<=0)continue;let o=Vb(n,t,i(pb(n,"nodeStyle")));o.opacity??(o.opacity=.7),r.push({type:"circle",cx:n.x,cy:n.y,r:e,style:o,accessibleDatum:{...n.data,value:n.data?.value??n.value},datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=qb(t.nodeLabel);for(let o of e){let e=o.__radius??5,a=r?r(o):o.id;if(!a||e<15)continue;let s=Hb(o),l=Gb(o,t,i(pb(o,"nodeStyle")).fill);if(s){let i="string"==typeof l?Wb(l):t.themeSemantic?.text??"#000";n.push({x:o.x,y:o.y,text:String(a),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:i})}else n.push({x:o.x,y:o.y-e+14,text:String(a),anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:r,sceneEdges:[],labels:n}}(e,i,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Kb(e,t,i){let r=i.treeOrientation||"vertical";if("radial"===r){let i=t.x,r=t.y;e.x=r*Math.cos(i-Math.PI/2),e.y=r*Math.sin(i-Math.PI/2)}else"horizontal"===r?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);ev(e,5)}function Qb(e,t){e.x0=t.x0,e.y0=t.y0,e.x1=e.value?t.x1:t.x0,e.y1=e.value?t.y1:t.y0,e.x=(e.x0+e.x1)/2,e.y=(e.y0+e.y1)/2,e.width=e.x1-e.x0,e.height=e.y1-e.y0}function Jb(e,t){let i=t.r??0;e.x=t.x,e.y=t.y,ev(e,i),e.__radius=i}function ev(e,t){e.x0=e.x-t,e.x1=e.x+t,e.y0=e.y-t,e.y1=e.y+t,e.width=2*t,e.height=2*t}var tv=/*#__PURE__*/new WeakMap;import{pie as iv}from"d3-shape";function rv(e,t){if(!e)return[];let i=[],r=e=>{i.push(e);let n="function"==typeof t?t(e):e[t];n&&Array.isArray(n)&&n.forEach(r)};return r(e),i}function nv(e,t,i,r){if(e&&e.length>0)return e;let n=new Set;return t.forEach(e=>{let t="function"==typeof i?i(e):e[i],o="function"==typeof r?r(e):e[r];n.add(t),n.add(o)}),Array.from(n).map(e=>({id:e}))}function ov(e){return function(e,t){let i=tv.get(e);return i||(i=new Map,tv.set(e,i)),i.has(t)||i.set(t,{metaMap:new Map,startTime:typeof performance<"u"?performance.now():Date.now()}),i.get(t)}(e,"orbit")}var av={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;n&&function(e,t,i,r,n){let o=Yb(i.childrenAccessor||"children"),a=function(e){if("function"==typeof e)return e;let t=e||"name";return e=>String(e[t]??"")}(i.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(i.orbitMode),l=i.orbitSize??2.95,c=i.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=ov(i);h.metaMap.clear(),r.length=0,n.length=0;let p=Xb(rv(e,o).map(e=>String(a(e)))),f=0,g=t[0]/2,m=t[1]/2,y=Math.min(t[0],t[1])/2*.85,x=p[f++],b={id:x,x:g,y:m,x0:g,x1:g,y0:m,y1:m,width:0,height:0,value:0,depth:0,data:e};r.push(b),h.metaMap.set(x,{ring:y,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,i,a,l,c,g,m){let y=o(t);if(!y?.length)return;let x=y.length,b=0,v=0,w=0;for(;v<x;)v+=s[Math.min(w,s.length-1)],w++,b++;let S=0;for(let x=0;x<b;x++){let v=s[Math.min(x,s.length-1)],w=y.slice(S,S+v);if(!w.length)break;let k=(x+1)/b,A={id:i,depth:g,data:t,parentId:i},M=m?c/u(A)*k:c*k,$=iv().value(e=>o(e)?.length?4:1).sort(null)(w),_=d(A);for(let t=0;t<w.length;t++){let o=($[t].startAngle+$[t].endAngle)/2,s=w[t],c=p[f++],u=a+M*Math.sin(o),d=l+M*Math.cos(o)*_,m={id:c,x:u,y:d,x0:u,x1:u,y0:d,y1:d,width:0,height:0,value:0,depth:g,data:s};r.push(m),h.metaMap.set(c,{ring:M,angle:o,depth:g,parentId:i,eccentricity:_}),n.push({source:i,target:c,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:i,target:c}}),e(s,c,u,d,M,g+1,!0)}S+=v}}(e,x,g,m,y,1,!1)}(n,r,i,e,t)},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=i.nodeSize,s="number"==typeof a?()=>a:"function"==typeof a?a:()=>6,l=[],c=[],u=[];if(!1!==i.orbitShowRings){let t=ov(i),r=new Map;for(let t of e)r.set(t.id,t);let n=new Map;for(let[,e]of t.metaMap){if(!e.parentId)continue;let t=r.get(e.parentId);if(!t)continue;let i=`${e.parentId}:${e.ring}`;n.has(i)||n.set(i,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}let o=48,a={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:i,ecc:r}]of n)for(let n=0;n<o;n++){let s=n/o*Math.PI*2,l=(n+1)/o*Math.PI*2;c.push({type:"line",x1:e+i*Math.sin(s),y1:t+i*Math.cos(s)*r,x2:e+i*Math.sin(l),y2:t+i*Math.cos(l)*r,style:a,interactive:!1,datum:null})}}for(let t of e){if(null==t.x||null==t.y)continue;let e=s(pb(t,"nodeSize")),r=n?n(pb(t,"nodeStyle")):{},o={fill:r.fill||i.themeSemantic?.primary||"#6366f1",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??(0===(t.depth??0)?1:.85),cursor:r.cursor};l.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,accessibleDatum:t.data,datum:t,id:t.id,label:t.id,depth:t.depth})}let d=new Map;for(let t of e)d.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:d.get(e.source),i="object"==typeof e.target?e.target:d.get(e.target);if(!t||!i||null==t.x||null==i.x)continue;let r=o?o(pb(e,"edgeStyle")):{},n={stroke:r.stroke||"rgba(128,128,128,0.35)",strokeWidth:r.strokeWidth??.5,opacity:r.opacity??1,cursor:r.cursor};c.push({type:"line",x1:t.x,y1:t.y,x2:i.x,y2:i.y,style:n,datum:e})}if(i.showLabels){let t=i.nodeLabel;for(let i of e){let e=s(pb(i,"nodeSize"));if(e<=4)continue;let r="function"==typeof t?t(i):t?i.data?.[t]??i.id:i.id;u.push({x:i.x,y:i.y+e+12,text:String(r),anchor:"middle",fontSize:10,fill:"currentColor",anchorPoint:[i.x,i.y]})}}return{sceneNodes:l,sceneEdges:c,labels:u}},tick:(e,t,i,r,n)=>!1!==i.orbitAnimated&&(function(e,t){let i=ov(t),r=t.orbitSpeed??.25,n=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),o=((typeof performance<"u"?performance.now():Date.now())-i.startTime)/1e3,a=r*(Math.PI/6),s=new Map;for(let t of e)s.set(t.id,t);for(let t of e){let e=i.metaMap.get(t.id);if(!e||!e.parentId)continue;let r=s.get(e.parentId);if(!r)continue;let l={id:t.id,depth:e.depth,data:t.data,parentId:e.parentId},c=e.angle+o*a*n(l);t.x=r.x+e.ring*Math.sin(c),t.y=r.y+e.ring*Math.cos(c)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,i),!0)};import*as sv from"react";import{arc as lv}from"d3-shape";import{jsx as cv,jsxs as uv}from"react/jsx-runtime";function dv(e,t,i="slab-face"){let r=e.style.fill;return(e.style.opacity??1)<=0||(e.style.fillOpacity??1)<=0||"string"==typeof r&&/^\s*(none|transparent)\s*$|^rgba\(.*,\s*0(\.0+)?\s*\)$|^#[\da-f]{3}0$|^#[\da-f]{6}00$/i.test(r)?null:e.faces?.map((r,n)=>cv("path",{"data-perspective-part":i,"data-perspective-face":n,d:r.pathD,fill:"string"==typeof e.style.fill?s(e.style.fill,r.shade):t,fillOpacity:e.style.fillOpacity,opacity:e.style.opacity},`face-${n}`))}function hv(e,t){return Qa(function(e,t){switch(e.type){case"line":{let i=e;return cv("line",{"data-perspective-part":i._perspectivePart,x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}case"bezier":{let i=e,r=`net-bezier-${t}-hatch`,n=Aa(i.style.fill)?Ma(i.style.fill,r):void 0;return uv(sv.Fragment,{children:[n&&cv("defs",{children:n}),cv("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:n?`url(#${r})`:Wa(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity??.5,stroke:i.style.stroke||"none",strokeOpacity:.5*(i.style.strokeOpacity??1),strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"ribbon":{let i=e,r=`net-ribbon-${t}-hatch`,n=Aa(i.style.fill)?Ma(i.style.fill,r):void 0;return uv(sv.Fragment,{children:[n&&cv("defs",{children:n}),cv("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:n?`url(#${r})`:Wa(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity??.5,stroke:i.style.stroke||"none",strokeOpacity:.3*(i.style.strokeOpacity??1),strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"curved":{let i=e;return cv("path",{d:i.pathD,"data-perspective-part":i._perspectivePart,fill:Wa(i.style.fill,"none"),fillOpacity:i.style.fill&&"none"!==i.style.fill?i.style.fillOpacity??.1:void 0,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}default:return null}}(e,t),e,`network-edge-cursor-${t}`)}function pv(e){let t=e.id??e.datum?.id??e.datum?.data?.id??e.datum?.data?.name;return null==t?void 0:String(t)}function fv(e){if("glyph"===e.type&&e.glyph&&"number"==typeof e.size){let t=e.cx??e.x,i=e.cy??e.y;if("number"!=typeof t||"number"!=typeof i)return null;let r=m(e.glyph,e.size);return{x:t+r.centerDx,y:i+r.centerDy,r:Math.max(1,r.radius)}}let t=e.cx??(null!=e.x&&null!=e.w?e.x+e.w/2:e.x),i=e.cy??(null!=e.y&&null!=e.h?e.y+e.h/2:e.y);return"number"!=typeof t||"number"!=typeof i?null:{x:t,y:i,r:"number"==typeof e.r?Math.max(1,e.r):"number"==typeof e.outerR?Math.max(1,e.outerR):"number"==typeof e.size?Math.max(1,u(e.size)):Math.max(1,e.w??0,e.h??0)/2}}function gv(e){if(!e)return;let t=[];for(let i of e){let e=fv(i);e&&t.push({pointId:pv(i),...e})}return t}function mv(e,t=!1){return function(e){return e?._semioticCamera}(e)?.transformRef(t)}import{jsx as yv}from"react/jsx-runtime";var xv={x:0,y:0,k:1};function bv({view:e,width:t,height:i,children:r}){if(!e)return r;let{x:n,y:o,k:a}=function(e){return e&&Number.isFinite(e.k)&&e.k>0&&Number.isFinite(e.x)&&Number.isFinite(e.y)?e:xv}(e);return yv("svg",{role:"presentation",width:t,height:i,overflow:"hidden","data-network-view":"",children:yv("g",{ref:mv(e),transform:`translate(${n},${o}) scale(${a})`,children:r})})}function vv(e,t,i){return"function"==typeof t?t(e):e[t??i]}function wv(e){let t=null==e?NaN:Number(e);return Number.isFinite(t)?t:1}function Sv(e,t){return null!=e?String(e):("production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Missing network ${t} ID; skipping this datum.`),null)}import{Fragment as kv,jsx as Av,jsxs as Mv}from"react/jsx-runtime";function $v(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function _v([e,t]){return{id:e,__hasPosition:Number.isFinite(t.x)&&Number.isFinite(t.y),x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t,createdByFrame:!0}}function Pv(e){return{...e,y0:0,y1:0,sankeyWidth:0}}x(l),xx("sankey",gb),xx("force",Mb),xx("chord",Cb),xx("tree",Zb),xx("cluster",Zb),xx("treemap",Zb),xx("circlepack",Zb),xx("partition",Zb),xx("orbit",av);var Iv=/*#__PURE__*/new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function Tv(e){return e.map(e=>{let t=e.datum&&"object"==typeof e.datum?e.datum:{},i=t.data&&"object"==typeof t.data?t.data:t,r="cx"in e?e.cx:e.x+e.w/2,n="cy"in e?e.cy:e.y+e.h/2;return{...i,...null==i.id&&null!=e.id?{id:e.id}:{},x:r,y:n}})}function Lv(t,i){let r=Pi(t.theme),n=t.chartType||"force",o=t.size||[500,500],a=function(e){return Zc.has(e)?Uc:Hc}(n),s=ve({...a,...t.margin},un(t.title)),l=xe(un(t.title)),u=t.showLegend?(()=>{let e="string"==typeof(i=t.colorBy)||"function"==typeof i?t.colorBy:void 0;var i;if(!e)return[];let r=_t(t.nodes||[]);if(r.length>0)return ys(r,e);if(Iv.has(n)&&t.data)return ys(rv(t.data,t.childrenAccessor||"children"),e);let o=Array.isArray(t.edges)?_t(t.edges):[];if(0===o.length)return[];let a=$v(t.sourceAccessor,"source"),s=$v(t.targetAccessor,"target"),l=Array.from(new Set(o.flatMap(e=>[a(e),s(e)]).filter(e=>null!=e).map(String)));return ys(l.map(e=>({id:e})),e)})():[];Ec(s,{props:t,categories:u,theme:r,size:o,hasTitle:l});let d,h=Oc({props:t,categories:u,theme:r,size:o,margin:s,hasTitle:l}),p=Math.max(1,o[0]-s.left-s.right),f=Math.max(1,o[1]-s.top-s.bottom),g=Gc(t.backgroundGraphics,o,s,null),m=Gc(t.foregroundGraphics,o,s,null),x=(e,n=[],a=[])=>(i&&(i.evidence=xa({frameType:"network",width:o[0],height:o[1],marks:[...n.map(({node:e})=>({type:`node:${e.type??"node"}`})),...a.map(({node:e})=>({type:`edge:${e.type??"edge"}`}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:d,nodeCount:n.length,edgeCount:a.length,margin:s})),mx.renderToStaticMarkup(zc(Av(bv,{view:t.viewTransform,width:p,height:f,children:e}),{width:o[0],height:o[1],className:"stream-network-frame"+(t.className?` ${t.className}`:""),title:t.title,description:t.description,background:t.background,theme:r,innerTransform:`translate(${s.left},${s.top})`,innerWidth:p,innerHeight:f,legend:h,markCount:n.length+a.length,idPrefix:t._idPrefix}))),v=e=>{let i=e=>Number(e);return t.annotations?lc({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:i,y:i},layout:{width:p,height:f},theme:r,frameType:"network",annotationData:e&&Tv(e),pointNodes:e&&gv(e),idPrefix:t._idPrefix,onRender:e=>{d=e}}):null},w=()=>{let e=v(),i=g||m||t.annotations?Mv(kv,{children:[g,e,m]}):null;return x(i)},S=function(e){return yx[e]}(n);if(!S&&!t.customNetworkLayout)throw new Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);let k,A,M={chartType:n,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,edgeIdAccessor:t.edgeIdAccessor,edgeIdentity:t.edgeIdentity,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||r.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig,perspective:t.perspective},$=b(t.perspective);if(Iv.has(n)){let e=t.data||t.edges;if(!e||Array.isArray(e))return w();M.__hierarchyRoot=e,k=[],A=[]}else{let e=_t(t.nodes||[]),i=Array.isArray(t.edges)?_t(t.edges):[];if(0===e.length&&0===i.length&&!t.customNetworkLayout)return w();let r=function(e,t,i){let r=new Map;for(let t of e){let e=Sv(vv(t,i.nodeIDAccessor,"id"),"node");null!==e&&(r.has(e)&&"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Duplicate network node ID "${e}"; using the last datum.`),r.set(e,t))}let n=[],o=new Set;return t.forEach((e,t)=>{let a="id"===i.edgeIdentity?function(e,t){let i=vv(e,t.edgeIdAccessor,"id");if("string"!=typeof i||!i)throw new Error("IDENTITY_EDGE_ID: edgeIdentity=id requires nonempty string edge IDs.");return JSON.stringify(["id",i])}(e,i):void 0;if(a&&o.has(a))throw new Error("IDENTITY_DUPLICATE_EDGE: repeated edge ID in bounded graph.");a&&o.add(a);let s=function(e,t){let i=Sv(vv(e,t.sourceAccessor,"source"),"source"),r=Sv(vv(e,t.targetAccessor,"target"),"target");if(null===i||null===r){if("id"===t.edgeIdentity)throw new Error("ENDPOINT_OWNER: explicit-ID edges require both owners.");return null}return{source:i,target:r,value:wv(vv(e,t.valueAccessor,"value")),data:e}}(e,i);if(s){for(let e of[s.source,s.target])r.has(e)||r.set(e,{id:e});n.push({...s,_edgeKey:a??`${s.source}\0${s.target}\0${t}`})}}),{nodes:r,edges:n}}(e,i,M);k=Array.from(r.nodes,_v),A=r.edges.map(Pv)}let P,I,T=[],L=[],C=[],R=null,N=null;if(M.customNetworkLayout){let e=M.colorScheme,i=ig(e,r.colors.categorical,Ct),n=rg(i,e),o={nodes:k,edges:A,dimensions:{width:p,height:f,plot:{x:0,y:0,width:p,height:f}},theme:{sequential:r.colors.sequential,selectionOpacity:r.colors.selectionOpacity,semantic:r.colors,categorical:[...i]},resolveColor:n,config:M.layoutConfig??{},selection:t.layoutSelection??null,perspective:$?.config??null},a=M.customNetworkLayout(o);P=a.perspective,T=a.sceneNodes??[],L=a.sceneEdges??[],function({nodes:e,edges:t,restyle:i,restyleEdge:r,baseStyles:n,selection:o}){if(i)for(let t of e){let e=n.get(t)??t.style,r=i(t,o);t.style=r?{...e,...r}:e}if(r)for(let e of t){let t=n.get(e)??e.style,i=r(e,o);e.style=i?{...t,...i}:t}}({nodes:T,edges:L,restyle:a.restyle,restyleEdge:a.restyleEdge,selection:t.layoutSelection??null,baseStyles:new WeakMap}),C=a.labels??[],R=a.backgrounds??null,N=a.overlays??null,I=a.perspectiveBounds}else if(S){S.computeLayout(k,A,M,[p,f]);let e=S.buildScene(k,A,M,[p,f]);T=e.sceneNodes,L=e.sceneEdges,C=e.labels}let D=[],F=$?(()=>{let e=y({sceneNodes:T,sceneEdges:L,labels:C,bounds:I,size:[p,f],perspective:$,chartType:n,theme:_(r)});return T=e.sceneNodes,L=e.sceneEdges,C=e.labels,D=e.underlay,e.frame})():null,E=os({nodes:L,renderMode:t.renderMode,fallback:(e,t)=>hv(e,t)}),O=os({nodes:T,renderMode:t.renderMode,fallback:(e,t)=>function(e,t){return Qa(function(e,t){switch(e.type){case"circle":case"rect":case"arc":{let i,r=e,n=`net-${r.type}-${t}`,o=`${n}-hatch`,a=Aa(r.style.fill)?Ma(r.style.fill,o):void 0,s={fill:a?`url(#${o})`:Wa(r.style.fill),...ja(r.style)},l="circle"===r.type&&r._perspectiveToken;if(r.pathD)i=cv("path",{"data-perspective-part":l?"token-top":"slab-top",d:r.pathD,...s});else if("circle"===r.type)i=cv("circle",{cx:r.cx,cy:r.cy,r:r.r,...s});else if("rect"===r.type)i=cv("rect",{x:r.x,y:r.y,width:r.w,height:r.h,...s});else{let e=lv().innerRadius(r.innerR).outerRadius(r.outerR).startAngle(r.startAngle+Math.PI/2).endAngle(r.endAngle+Math.PI/2)(Ba)||"";i=cv("path",{d:e,transform:`translate(${r.cx},${r.cy})`,...s})}return uv(sv.Fragment,{children:[a&&cv("defs",{children:a}),r.pathD&&dv(r,s.fill,l?"token-rim":"slab-face"),i]},n)}case"symbol":{let i=e,r=c(i.symbolType,i.size,i.path),n=i.rotation?`translate(${i.cx},${i.cy}) rotate(${180*i.rotation/Math.PI})`:`translate(${i.cx},${i.cy})`,o=cv("path",{"data-perspective-part":i._perspectiveToken?"token-top":void 0,d:r,transform:n,fill:i.style.fill?Wa(i.style.fill):"none",...ja(i.style)},`net-symbol-${t}`);return i.faces?.length?uv(sv.Fragment,{children:[dv(i,i.style.fill?Wa(i.style.fill):void 0,"token-rim"),o]},`net-symbol-${t}`):o}case"glyph":{let i=e;return qa(i,i.cx,i.cy,`net-glyph-${i.id??t}`)}default:return null}}(e,t),e,`network-node-cursor-${t}`)}(e,t)}),z=E.map(e=>e.element),B=O.map(e=>e.element),j=Ii(r),W=C.map((e,t)=>function(e,t,i="middle",r="auto"){return cv("text",{x:e.x,y:e.y,textAnchor:e.anchor||i,dominantBaseline:e.baseline||r,fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,transform:e.rotate?`rotate(${Math.round(180*e.rotate/Math.PI*100)/100} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},`net-label-${t}`)}({...e,fill:e.fill||j.text},t)).filter(Boolean),Y=v(T),q=Mv(kv,{children:[g,e(R,F,P),D.map((e,t)=>hv(e,t)),z,B,W,Y,e(m,F),e(N,F,P)]});return x(q,O,E)}function Cv(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var Rv={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Nv(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}function Dv(e,t,i){let r="function"==typeof t?t(e,i):t;return{...Rv,...r??{}}}function Fv(e,t={},i="settled"){return e.map((e,r)=>function(e,t={},i={index:0,simulationState:"settled"}){let r=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),n={label:t.getBodyLabel?.(e)??Nv(e)},o={style:Dv(e,t.bodyStyle,i),datum:r,accessibleDatum:r,accessibility:n,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}(e,t,{index:r,simulationState:i}))}import{jsx as Ev,jsxs as Ov}from"react/jsx-runtime";function zv(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`physics-${t}`:t}function Bv(e){return`${zv(e)}-svg`}var jv={top:0,right:0,bottom:0,left:0};function Wv(e,t,i){return"function"==typeof e?e({size:t,margin:i}):e}import*as Yv from"react-dom/server.browser";function qv(e,t={}){let{element:i,scene:r,evidence:n}=function(e,t={}){let{decorative:i=!1,width:r=640,height:n=360,title:o,description:a,background:s,backgroundGraphics:l,backgroundGraphicsBackdrop:c,className:u,foregroundGraphics:d,idPrefix:h="physics",margin:p,style:f,renderBodySVG:g,renderChrome:m,...y}=t,x=function(e,t={}){let i=e.settle(t.maxSteps),r=e.readBodies(),n=e.snapshot(),o=Fv(r,t,n.simulationState),a=function(e,t={}){let i=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),r=i.filter(e=>e.sleeping).length,n=e.queue.length,o=e.sediment.reduce((e,t)=>e+t.count,0),a="settled"===e.simulationState&&0===n&&r===i.length,s=[];a||s.push("PHYSICS_NOT_SETTLED"),n>0&&s.push("PHYSICS_QUEUE_UNDRAINED");let l=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,i,r){let n=e-(t+i+r);return{charge:e,live:t,queued:i,sedimented:r,unaccounted:n,balanced:0===n}}(t.charge,i.length,n,o):void 0;return l&&!l.balanced&&s.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:i.length,sleepingCount:r,settled:a,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:Cv(t.projectionRows),queuedCount:n,sedimentedCount:o,...l?{ledger:l}:{},warnings:s}}(n,{bodies:r,projectionRows:t.projectionRows,stepsRun:i,charge:t.charge});return{snapshot:n,bodies:r,sceneNodes:o,evidence:a,stepsRun:i}}(e,y),b={...jv,...p},v=[r,n],w=Wv(l,v,b),S=Wv(d,v,b),k=zv(h),A=o?`${k}-title`:void 0,M=a?`${k}-desc`:void 0,$=[A,M].filter(Boolean).join(" ")||void 0,_=b.left||b.top?`translate(${b.left},${b.top})`:void 0,P=Math.max(1,r-b.left-b.right),I=Math.max(1,n-b.top-b.bottom),T=`${k}-plot-clip`,L=e.viewTransform(),C=_&&null!=w?Ev("g",{transform:_,children:w}):w;return{element:Ov("svg",{xmlns:"http://www.w3.org/2000/svg",id:Bv(k),className:u??"stream-physics-frame",width:r,height:n,viewBox:`0 0 ${r} ${n}`,role:i?"presentation":"img","aria-labelledby":i?void 0:$,"aria-label":i?void 0:a||o||`physics chart, ${x.sceneNodes.length} marks`,style:f,children:[!i&&o&&Ev("title",{id:A,children:o}),!i&&a&&Ev("desc",{id:M,children:a}),Ev("defs",{children:Ev("clipPath",{id:T,children:Ev("rect",{width:P,height:I})})}),c&&"transparent"!==c?Ev("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:r,height:n,fill:c}):null,!l&&s&&"transparent"!==s?Ev("rect",{x:0,y:0,width:r,height:n,fill:s}):null,C,Ev("g",{id:`${k}-data-area`,transform:_,clipPath:`url(#${T})`,children:Ev("g",{transform:L.x||L.y?`translate(${L.x},${L.y})`:void 0,children:x.sceneNodes.map((e,t)=>{let i=x.bodies[t],r=(i&&g?g(i,e.style??{},t,k):void 0)??(i?wh(i,e.style??{},t,k):void 0);return null!=r?Qa(r,e,t):Qa("point"===e.type||"rect"===e.type?Ha(e,t,k):null,e,`xy-cursor-${t}`)})})}),S,m?.(x)]}),scene:x,evidence:x.evidence}}(e,t);return{svg:Yv.renderToStaticMarkup(i),scene:r,evidence:n}}function Xv(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function Gv(e,t){let i="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,Xv(e.thickness)??Xv(i)??Xv(t.thickness)??4)}function Vv(e){return e.sensorId??`stream-region-${e.id}`}function Hv(e){let t=Vv(e),i={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){let r=e.colliderThickness??8,n=e.shape.x-e.shape.width/2,o=e.shape.x+e.shape.width/2,a=e.shape.y-e.shape.height/2,s=e.shape.y+e.shape.height/2;return[{...i,id:`${t}-top`,shape:{type:"segment",x1:n,y1:a,x2:o,y2:a,thickness:r}},{...i,id:`${t}-right`,shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:r}},{...i,id:`${t}-bottom`,shape:{type:"segment",x1:o,y1:s,x2:n,y2:s,thickness:r}},{...i,id:`${t}-left`,shape:{type:"segment",x1:n,y1:s,x2:n,y2:a,thickness:r}}]}return e.collider?[{...i,id:`${t}-collider`,shape:e.shape}]:[]}import{jsx as Uv,jsxs as Zv}from"react/jsx-runtime";import{Fragment as Kv,jsx as Qv,jsxs as Jv}from"react/jsx-runtime";var ew={top:0,right:0,bottom:0,left:0};function tw(e,t){let i=e.size??[e.width??600,e.height??400],r=Pi(e.theme),n=e.physicsTheme?{...r,colors:{...r.colors,...Object.fromEntries(Object.entries(e.physicsTheme).filter(([e,t])=>e in r.colors&&null!=t))}}:r,o=void 0===e.theme||"auto"===r.mode?{}:S(r),a=e.bodyStyle,s=!1,l=e.legendPosition??"right",c=be({...ew,...e.margin},s);if(e.legend){let t={...c};Re(c,{legend:e.legend,position:l,size:i,hasTitle:s,legendLayout:e.legendLayout}),we(c,t,i,l)}let u,d=[Math.max(1,i[0]-c.left-c.right),Math.max(1,i[1]-c.top-c.bottom)],h=function({annotations:e,chartId:t,chartType:i,config:r,onRegionObservation:n,regionEffects:o,seed:a,size:s}){let l=function(e=[],t={}){let i=t.idPrefix?`${t.idPrefix}-`:"",r=[];for(let n of e){if("barrier"!==n.physics&&"sensor"!==n.physics)continue;let e,o=n.axis??t.defaultAxis??"x",a=Gv(n,t),s=n.colliderId??`${i}${n.id}`;if("x"===o){let i=Xv(n.x),r=Xv(n.y1)??Xv(t.plotBounds?.y)??Xv(n.y),o=Xv(n.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??Xv(n.y);if(null==i||null==r||null==o)continue;e={type:"segment",x1:i,y1:r,x2:i,y2:o,thickness:a}}else{let i=Xv(n.y),r=Xv(n.x1)??Xv(t.plotBounds?.x)??Xv(n.x),o=Xv(n.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??Xv(n.x);if(null==i||null==r||null==o)continue;e={type:"segment",x1:r,y1:i,x2:o,y2:i,thickness:a}}r.push({id:s,shape:e,sensor:"sensor"===n.physics,..."barrier"!==n.physics||null==n.restitution&&null==t.barrierRestitution?{}:{restitution:Xv(n.restitution)??Xv(t.barrierRestitution)},..."barrier"!==n.physics||null==n.friction&&null==t.barrierFriction?{}:{friction:Xv(n.friction)??Xv(t.barrierFriction)}})}return r}((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?`${t}-ann`:"physics-ann",plotBounds:{x:0,y:0,width:s[0],height:s[1]}}),c=void 0===a||void 0!==r?.kernel?.seed?r:{...r,kernel:{...r?.kernel,seed:a}},u=o.flatMap(e=>[{id:Vv(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...Hv(e)]),d=Object.fromEntries(o.map(e=>[Vv(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,p=o.length>0,f=u.length>0||l.length>0;return p||f||null!=t||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??i,sensors:{...h?.sensors??{},...d},onObservation:e=>{p&&n(e),h?.onObservation?.(e)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:d}),p=new Nf(h);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);let f=qv(p,{...e,title:un(e.title)||void 0,width:i[0],height:i[1],background:e.background??e.physicsTheme?.background??r.colors.background,bodyStyle:(t,i)=>({fill:e.physicsTheme?.primary??r.colors.primary,stroke:e.physicsTheme?.text??r.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof a?a(t,i):a,..."function"==typeof e.frameBodyStyle?e.frameBodyStyle(t,{selected:!1,simulationState:i.simulationState}):e.frameBodyStyle}),style:{...o,...ph(e.physicsTheme),fontFamily:r.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{let o=function(e,t,i,r,n){let o=Math.max(1,i[0]-r.left-r.right),a=Ii(n),s=void 0===t.theme?14:a.titleFontSize,l=Math.max(1,i[1]-r.top-r.bottom),c=px(t.annotations),u=function(e){let{width:t,height:i,pointNodes:r=[],data:n}=e;return{scales:{x:ux().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:ux().domain([0,Math.max(1,i)]).range([0,Math.max(1,i)])},width:t,height:i,frameType:"network",pointNodes:r,data:n,xAccessor:"x",yAccessor:"y"}}({width:o,height:l,pointNodes:hx(e.bodies)}),d=u.scales?.x,h=u.scales?.y;if(!d||!h)throw new Error("Physics annotation context requires pixel scales");let p,f=lc({annotations:c,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{x:d,y:h},layout:{width:o,height:l},theme:n,frameType:"network",xAccessor:u.xAccessor,yAccessor:u.yAccessor,pointNodes:u.pointNodes,svgAnnotationRules:t.svgAnnotationRules,onRender:e=>{p=e}}),g=t.legend?Fc(t.legend,{theme:n,position:t.legendPosition,size:[i[0],i[1]],margin:r,hasTitle:!!t.title,legendLayout:t.legendLayout})??uc(t.legend,i,r,t.legendPosition,t.legendLayout):null;return{annotationRender:p,node:Zv("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i[0],height:i[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Uv("g",{transform:`translate(${r.left},${r.top})`,children:f}),un(t.title)&&Uv("text",{className:"semiotic-chart-title",x:i[0]/2,y:22,textAnchor:"middle",fill:a.text,fontSize:s,fontFamily:a.titleFontFamily,fontWeight:a.titleFontWeight,children:dn(t.title)}),g]})}}(t,e,i,c,n);u=o.annotationRender;let a=_i(r,`#${Bv(e.idPrefix??e._idPrefix??"physics")}`);return Jv(Kv,{children:[a&&Qv("style",{children:a}),o.node]})}});if(t&&(t.evidence=xa({frameType:"physics",width:i[0],height:i[1],marks:f.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===f.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...f.scene.evidence.warnings]}),e.eventDropMetadata)){let i=e.eventDropMetadata;Object.assign(t.evidence,{watermarkValue:i.watermarkValue,openWindows:i.windowCount-i.closedWindowCount,closedWindows:i.closedWindowCount,lateCount:i.lateCount})}return f.svg}function iw(e,t,i){return{frameType:e.frameType,layout:{...e.layout,...i&&{margin:i}},buildProps:(i,r,n,o,a)=>{let[s,l]=o.size,c=t({...a,...o,width:s,height:l,colorScheme:n});return e.buildProps(c.data,r,n,{...o,...null!=c.annotations&&{annotations:c.annotations},...c.frameProps,title:c.title,description:c.description,summary:c.summary,accessibleTable:c.accessibleTable},{...a,...c})}}}var rw=iw(lh,function({atlas:e,linkedHover:t,...i},r=function(e){let t=e.prefixForest;if(!t)return{atlas:e,groups:[],signatureOrder:[],ribbons:[],capsules:[],profile:Ly(e),differences:[],prefixForest:{kind:"observed-prefix",rootIds:[],nodes:[],order:[]},sceneSeeds:{nodes:[],edges:[]}};let i=(e.source.occurrences??[]).map(Ry).filter(e=>!!e),r=new Map;for(let e of i){let i=t.order.indexOf(e.signature),n=r.get(e.signature),o=-1===i?t.order.length:i;(null==n||o<n)&&r.set(e.signature,o)}let n=[...new Set(i.map(e=>e.signature))].sort((e,t)=>{let i=(r.get(e)??0)-(r.get(t)??0);return 0!==i?i:e.localeCompare(t)}),o=[];for(let e of i)for(let t=0;t<e.nodePath.length-1;t++){let i=Py(e.nodePath,t),r=Py(e.nodePath,t+1);o.push({id:`ribbon:${e.id}:${t}`,groupId:e.id,partition:e.partition,fromPrefixId:i,toPrefixId:r,fromState:e.nodePath[t],toState:e.nodePath[t+1],entityCount:e.stepEntityCounts?.[t]??e.entityCount,...e.stepEntityCounts&&{toEntityCount:e.stepEntityCounts[t+1]}})}let a=function(e,t={}){let i=new Set(t.templates??["repeated-state-episode"]),r=e.filter(e=>i.has(e.template)).map(e=>{let t="string"==typeof e.roles.state?e.roles.state:e.nodePath[0],i=e.nodePath[e.nodePath.length-1];return{id:`capsule:${e.id}`,matchId:e.id,template:e.template,entryState:t,exitState:i,entityCount:e.entityCount,occurrenceIds:My(e),selected:!1}}).sort((e,t)=>t.entityCount!==e.entityCount?t.entityCount-e.entityCount:e.id.localeCompare(t.id)),n=new Set;for(let e of r)if(!e.occurrenceIds.some(e=>n.has(e))){e.selected=!0;for(let t of e.occurrenceIds)n.add(t)}return r}(e.motifs.matches),s=e.comparison??function(e){let t=e.spec.comparison;if(!t)return;let i=t.partitions.map(i=>{let r=Iy(e.ledger,t.denominatorMeasureId,i)?.value??0,n={};return n["repeated-state-episode"]=$y(e.motifs.matches.filter(e=>"repeated-state-episode"===e.template),e.source.occurrences,i),{partition:i,assigned:r,motifUsers:n,outcomes:{purchases:Iy(e.ledger,"purchases",i)?.value??0}}});return{partitions:[...t.partitions],denominatorMeasureId:t.denominatorMeasureId,referencePartition:t.referencePartition,rows:i}}(e),l=[];if(s&&s.partitions.length>=2){let e=s.rows[0],t=s.rows[1],i=Math.min(e.assigned,t.assigned)||e.assigned,r=e.motifUsers["repeated-state-episode"]??0,n=t.motifUsers["repeated-state-episode"]??0;l.push({motif:"repeated-state-episode",leftPartition:e.partition,rightPartition:t.partition,leftCount:r,rightCount:n,deltaCount:n-r,deltaBps:Ty(r,n,i),denominator:i}),l.push({motif:"purchases",leftPartition:e.partition,rightPartition:t.partition,leftCount:e.outcomes.purchases??0,rightCount:t.outcomes.purchases??0,deltaCount:(t.outcomes.purchases??0)-(e.outcomes.purchases??0),deltaBps:Ty(e.outcomes.purchases??0,t.outcomes.purchases??0,i),denominator:i})}let c={nodes:i.map(e=>({id:e.id,partition:e.partition,signature:e.signature})),edges:o.map(e=>({id:e.id,source:e.fromPrefixId,target:e.toPrefixId}))};return{atlas:e,groups:i,signatureOrder:n,ribbons:o,capsules:a,profile:Ly(e),differences:l,prefixForest:t,sceneSeeds:c}}(e)){return{...i,linkedHover:Ay(t),title:i.title??e.spec.dataRevision,description:i.description??"Motif Braid. Labeled squares show successive journey steps; parallel strands split at diverging prefixes and taper with per-step traffic.",summary:i.summary??`${r.groups.length} supported journey groups. Counts use ${e.spec.motifs.countUnit}; overlapping motifs do not partition the population. Source revision: ${e.provenance.sourceRevision}.`,accessibleTable:i.accessibleTable??!0,nodes:r.sceneSeeds.nodes,edges:r.sceneSeeds.edges,layout:Yy,layoutConfig:{braid:r}}}),nw=iw(lh,function({width:e=ut.width,height:t=ut.height,title:i="Dependency X-Ray",description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,linkedSelection:u,annotations:d,frameProps:h,perspective:p,onSelectNode:f,tooltip:g,...m}){return{nodes:m.forest.sceneSeeds.nodes,edges:m.forest.sceneSeeds.edges,layout:Vy,layoutConfig:m,nodeIDAccessor:"id",sourceAccessor:"source",targetAccessor:"target",width:e,height:t,title:i,chartId:a,className:s,onObservation:l,linkedHover:Ay(c),selection:u,annotations:d,frameProps:h,perspective:p,tooltip:g,animate:!1,margin:{top:12,right:24,bottom:12,left:12},description:r??`Sections organize the admitted directed graph. Backbone links organize the drawing; residual links retain other original edges. Brackets describe required paths, separately from transport. Roots: ${m.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Completeness: ${m.forest.atlas.requiredPaths?.status??"not prepared"}.`,summary:n??`Roots: ${m.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Required-path completeness: ${m.forest.atlas.requiredPaths?.status??"not prepared"}. ${m.forest.residual.originalEdgeIds.length} original edges retained.`,accessibleTable:o}},{top:12,right:24,bottom:12,left:12}),ow=iw(ky,gx),aw=iw(lh,function(e){let{key:t,data:i,layout:r,paused:n,frameProps:o,...a}=gx(e);return{...a,annotations:px(a.annotations),nodes:i,edges:e.circuit.atlas.source.edges,layout:lx,perspective:e.perspective,margin:0,frameProps:{...e.frameProps&&{background:e.frameProps.background,backgroundGraphics:e.frameProps.backgroundGraphics,foregroundGraphics:e.frameProps.foregroundGraphics},...e.networkFrameProps}}}),sw={...ow,resolveFrameType:e=>e._projectedCircuit?"network":"physics",buildProps:(...e)=>{let t=b(e[4].perspective);return{...(t?aw:ow).buildProps(...e),_projectedCircuit:!!t}},renderStatic:(e,t)=>e._projectedCircuit?Lv(e,t):tw(e,t)};import{scaleTime as lw}from"d3-scale";var cw={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function uw(e="static"){return cw[e]??cw.static}var dw=/*#__PURE__*/new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function hw(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:dw.has(e.kind)?"fatal":"warn"}function pw(e,t,i="static"){if("strip"!==uw(i).invalidSystemTime)return e;let r=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===r.size?e:e.map(e=>{if(!r.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}function fw(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function gw(e,t){let i=0,r=e.length-1,n=-1;for(;i<=r;){let o=i+r>>>1;e[o].at<=t?(n=o,i=o+1):r=o-1}return n<0?{at:t,before:0,after:0}:e[n]}function mw(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let i=[],r=[0];for(let n=0;n<e.length-1;n++){let o=e[n],a=e[n+1],s=[...new Set([...o.map(e=>e.at),...a.map(e=>e.at)])].sort((e,t)=>e-t),l=0;for(let e of s){let t=gw(o,e),i=gw(a,e);l=Math.max(l,t.after+i.before)}i.push(l),r.push(r[r.length-1]+l+t)}return{adjacentClearance:i,positions:r}}function yw(e,t,i,r={}){let n=[...e];if(n.length<=1)return n;let o=[...n],a=i(n),s=1,l=Math.max(0,r.passes??6),c=Math.max(1,r.maxEvaluations??1/0);for(let e=0;e<l&&s<c;e++){let e=new Map(n.map((e,t)=>[e,t])),l=new Map,c=new Map;for(let i of t){let t=e.get(i.source),r=e.get(i.target);if(null==t||null==r)continue;let n=Number.isFinite(i.weight)&&i.weight>0?i.weight:1;l.set(i.source,(l.get(i.source)??0)+r*n),c.set(i.source,(c.get(i.source)??0)+n),l.set(i.target,(l.get(i.target)??0)+t*n),c.set(i.target,(c.get(i.target)??0)+n)}n=n.map((e,t)=>({item:e,index:t,barycenter:(l.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(r.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let u=i(n);if(s++,u<a)a=u,o=[...n];else if(u===a)break}return o}function xw(e,t,i={}){let r=[...e];if(r.length<=1)return r;let n=t(r),o=1,a=Math.max(0,i.passes??6),s=Math.max(1,i.maxEvaluations??1/0);for(let e=0;e<a&&o<s;e++){let e=!1;for(let i=0;i<r.length-1&&o<s;i++){[r[i],r[i+1]]=[r[i+1],r[i]];let a=t(r);o++,a<n?(n=a,e=!0):[r[i],r[i+1]]=[r[i+1],r[i]]}if(!e)break}return r}function bw(e,t,i={}){let r=[...e],n=r.length;if(n<=1||n>(i.maxItems??8))return r;let o=Math.max(1,i.maxEvaluations??1/0),a=0,s=[...r],l=1/0,c=()=>{if(a>=o)return;let e=t(r);a++,e<l&&(l=e,s=[...r])};c();let u=new Array(n).fill(0),d=0;for(;d<n&&a<o;)if(u[d]<d){let e=d%2==0?0:u[d];[r[e],r[d]]=[r[d],r[e]],c(),u[d]++,d=0}else u[d]=0,d++;return s}function vw(){return Object.create(null)}function ww(e,t){return e<t?-1:e>t?1:0}function Sw(e){return e.occupants.map(e=>e.id).sort(ww).join("\0")}function kw(e,t,i=0){return e.slice(0,-1).map((r,n)=>{let o=e[n+1];return null!=r.group&&r.group===o.group?i:t})}function Aw(e,t){return e.map(e=>{let i=new Map;for(let r of e.occupants){let e=t[r.id];if(e)for(let t of e.samples){let e=i.get(t.t)??{before:0,after:0},r=t.boundaryOffset??0;i.set(t.t,{before:Math.max(e.before,t.topMass-r),after:Math.max(e.after,t.botMass+r)})}}return[...i].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function Mw(e,t,i){if(0===e.length)return[];let{padding:r,plotH:n,valueScale:o}=i,a=i.stackValueScale??o,s=kw(e,r,i.groupPadding??0),l=[r+e[0].peak.topPeak*a];for(let i=1;i<e.length;i++)l.push(l[i-1]+t[i-1]*a+s[i-1]);let c=l[l.length-1]+e[e.length-1].peak.botPeak*a+r;if(c>n&&c>0){let e=n/c;for(let t=0;t<l.length;t++)l[t]*=e}return l}function $w(e,t){let i=(e.boundaryOffset??0)*t,r=e.value*t;if("out"===e.kind){let n=e.sideMassBefore*t;return i+("top"===e.side?r/2-n:n-r/2)}let n=e.sideMassAfter*t;return i+("top"===e.side?r/2-n:n-r/2)}function _w(e,t,i,r,n,o){let a=o.adjacentClearance?[...o.adjacentClearance]:mw(Aw(r,i)).adjacentClearance,s=Mw(r,a,o),l="hug"===o.lanePlacement?function(e,t,i,r,n,o,a){let s=e.length;if(0===s)return[];let{padding:l,plotH:c,valueScale:u}=a,d=kw(e,l,a.groupPadding??0),h=n.map((e,t)=>e*u+d[t]),p=l+e[0].peak.topPeak*u,f=c-l-e[s-1].peak.botPeak*u;if(f-p<=h.reduce((e,t)=>e+t,0)+1e-6)return Mw(e,n,a);let g=1===s?[(p+f)/2]:[...o];for(let e=0;e<12;e++){let e=new Array(s).fill(0),n=new Array(s).fill(0);for(let o of i){let i=t[o.source],a=t[o.target];if(null==i||null==a||i===a)continue;let s=r[o.source]?.localAttachments.get(o.id),l=r[o.target]?.localAttachments.get(o.id);if(!s||!l)continue;let c=o.value>0&&Number.isFinite(o.value)?o.value:1,d=$w(s,u),h=$w(l,u);e[i]+=(g[a]+h-d)*c,n[i]+=c,e[a]+=(g[i]+d-h)*c,n[a]+=c}let o=vs({desired:g.map((t,i)=>0===n[i]?t:.45*t+e[i]/n[i]*.55),minGaps:h,weights:n.map(e=>Math.max(1,e)),min:p,max:f}),a=0;for(let e=0;e<s;e++)a=Math.max(a,Math.abs(o[e]-g[e]));if(g=o,a<.01)break}return g}(r,n,t,i,a,s,o):[...s];if("hug"===o.lanePlacement){let i=t=>{let i=vw();for(let r of e)i[r.id]=t[n[r.id]];return i};Pw(i(l),t)>Pw(i(s),t)+1e-6&&(l=[...s])}let c=vw();for(let t of e)c[t.id]=l[n[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],r=i[t.id];!Number.isFinite(e)||!r||(u=Math.min(u,e-r.topPeak*o.valueScale),d=Math.max(d,e+r.botPeak*o.valueScale))}return{adjacentClearance:a,centerlines:c,slotCenter:l,stackCenter:s,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&o.plotH>0?Math.max(0,Math.min(1,(d-u)/o.plotH)):0}}function Pw(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];Number.isFinite(t)&&Number.isFinite(n)&&(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}function Iw(e,t){let i=e?.samples;if(!i||0===i.length||t<i[0].t)return{top:0,bot:0};let r=0,n=i.length-1,o=0;for(;r<=n;){let e=r+n>>>1;i[e].t<=t?(o=e,r=e+1):n=e-1}let a=i[o].boundaryOffset??0;return{top:i[o].topMass-a,bot:i[o].botMass+a}}function Tw(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function Lw(e,t){let i=0,r=1;for(let n=0;n<28;n++){let n=(i+r)/2;Tw(0,t,t,1,n)<e?i=n:r=n}return(i+r)/2}function Cw(e,t,i){let r=t+$w(e,i),n=e.value*i/2;return[r-n,r+n]}function Rw(e,t,i,r){return Math.max(0,Math.min(t,r)-Math.max(e,i))/Math.max(1e-9,t-e)}function Nw(e,t,i,r,n,o,a){let{valueScale:s,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5,d=0;for(let a of e){let e=r[a.source],h=r[a.target];if(null==e||null==h||Math.abs(e-h)<2)continue;let p=t[a.source]?.localAttachments.get(a.id),f=t[a.target]?.localAttachments.get(a.id);if(!p||!f)continue;let g=Math.max(a.startTime,l?.[0]??-1/0),m=Math.min(a.endTime,l?.[1]??1/0);if(!(m>g))continue;let[y,x]=Cw(p,n[a.source],s),[b,v]=Cw(f,n[a.target],s),w=Math.min(e,h)+1,S=Math.max(e,h)-1;for(let e=w;e<=S;e++){let r=i[e];if(!r)continue;let l=[g,m];if("quality"===c)for(let e of r.occupants)for(let i of t[e.id]?.samples??[])i.t>g&&i.t<m&&l.push(i.t);let h=e=>{let i=Lw((e-g)/(m-g),u),l=Tw(y,y,b,b,i),c=Tw(x,x,v,v,i),d=0;for(let i of r.occupants){if(i.id===a.source||i.id===a.target)continue;let r=o[i.id];if(null!=r?.start&&e<r.start||null!=r?.end&&e>r.end)continue;let u=Iw(t[i.id],e),h=n[i.id];d=Math.max(d,Rw(l,c,h-u.top*s,h+u.bot*s))}return d},p=[...new Set(l)].sort((e,t)=>e-t),f=0;for(let e=0;e<p.length-1;e++){let t=p[e],i=p[e+1]-t;f+=(h(t+.25*i)+h(t+.5*i)+h(t+.75*i))/3*i}d+=f/(m-g)*(a.value>0?a.value:1)}}return d}function Dw(e,t,i,r,n,o,a,s,l,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:Pw(a,i),transitOcclusion:Nw(i,r,n,o,a,s,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Fw(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function Ew(e,t){return e.map(e=>({t:Fw(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function Ow(e,t,i){let r=t+(e.boundaryOffset??0)*i,n=e.value*i;if("out"===e.kind){let t=e.sideMassBefore*i;if("top"===e.side){let e=r-t;return[e,e+n]}let o=r+t;return[o-n,o]}let o=e.sideMassAfter*i;if("top"===e.side){let e=r-o;return[e,e+n]}let a=r+o;return[a-n,a]}function zw(e,t,i,r,n="temporal"){let o=t.incoming[e.id],a=t.outgoing[e.id],s=[];for(let e of o)s.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:i.get(e.id).targetSide});for(let e of a)s.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:i.get(e.id).sourceSide});let l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{s.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(l[e.kind]??99)-(l[t.kind]??99)||((e,t)=>{if(!r||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let i=r.get(e.edge.id)?.target,n=r.get(t.edge.id)?.target;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?i-n:n-i:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let i=r.get(e.edge.id)?.source,n=r.get(t.edge.id)?.source;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?n-i:i-n:0}return 0})(e,t)||ww(e.edge?.id??"",t.edge?.id??"")||ww(e.side,t.side)||e.delta-t.delta)},u=s.length?de(s.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let p=null,f=0;for(let e of s)e.time!==p&&(p=e.time,f=0),e.sequence=f++;let g=e=>({time:e.time,phase:0,sequence:e.sequence??0}),m=[],y=0,x=0;for(let e of s)if("out"===e.kind){let t=Math.abs(e.delta),i=t-("top"===e.side?y:x);if(i>0){let t="top"===e.side?"bot":"top",r=Math.min(i,"top"===t?y:x);if(r>0){let n=g(e);m.push({...n,delta:-r,kind:"transfer-out",side:t}),m.push({...n,delta:+r,kind:"transfer-in",side:e.side}),"top"===t?y-=r:x-=r,"top"===e.side?y+=r:x+=r,i-=r}i>0&&null!==h&&(m.push({time:h,delta:+i,kind:"create",side:e.side}),"top"===e.side?y+=i:x+=i)}"top"===e.side?y-=t:x-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?y+=t:x+=t}s.push(...m),c();let b=0,v=0,w=0,S=0,k=0,A=0,M=[],$=new Map,_=e=>{M.push({t:e,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},P=()=>{S=Math.max(S,b+v),k=Math.max(k,b-w),A=Math.max(A,v+w)};for(let e of s){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&_(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?b:v,i=t+e.delta;$.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:i,kind:e.kind,value:Math.abs(e.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===e.side?b+=e.delta:v+=e.delta,"transfer-in"===e.kind?(w+="top"===e.side?e.delta:-e.delta,P(),_(e.time)):"transfer-out"!==e.kind&&(P(),"out"===e.kind&&b+v<=1e-12&&(w=0),_(e.time))}let I=[],T=0;for(;T<M.length;){let e=T;for(;e+1<M.length&&M[e+1].t===M[T].t;)e++;I.push(M[T]);for(let t=T+1;t<=e;t++){let e=I[I.length-1];(M[t].topMass!==e.topMass||M[t].botMass!==e.botMass||(M[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&I.push(M[t])}T=e+1}let L=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,C=null;for(let e of a)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime&&(null===C||e.systemInTime<C)&&(C=e.systemInTime);let R=null;for(let e of o)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===R||e.systemOutTime>R)&&(R=e.systemOutTime);if(I.length>0){let e=I[I.length-1],t=Math.max(L??-1/0,R??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&I.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let i,r=I[0],n=I.find(e=>e.topMass+e.botMass>0),o=1/0;null!=d&&Number.isFinite(d)&&d<r.t&&r.topMass+r.botMass>0&&(o=d,i=r),n&&null!=C&&Number.isFinite(C)&&C<n.t&&C<o&&(o=C,i=n),i&&Number.isFinite(o)&&I.unshift({t:o,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let N=I;if("max"===n&&null!=d&&null!=L&&L>d){let e,t=0;for(let i of I){let r=i.topMass+i.botMass;r>t&&(t=r,e=i)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};N=[...I.filter(e=>e.t<d),{t:d,...t},{t:L,...t},...I.filter(e=>e.t>L)]}}return{samples:N,peak:S,topPeak:k,botPeak:A,localAttachments:$}}var Bw=(e,t)=>{let i=0,r=e.length;for(;i<r;){let n=i+r>>>1;e[n]<t?i=n+1:r=n}return i},jw=class{constructor(e){this.coordinates=[...new Set(e)].sort((e,t)=>e-t),this.tree=new Int32Array(this.coordinates.length+1)}add(e,t){for(let i=Bw(this.coordinates,e)+1;i<this.tree.length;i+=i&-i)this.tree[i]+=t}below(e){let t=0;for(let i=Bw(this.coordinates,e);i>0;i-=i&-i)t+=this.tree[i];return t}};function Ww(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.max(e.startTime,t.startTime)<Math.min(e.endTime,t.endTime)}var Yw=class{constructor(e,t,i){this.size=i,this.routes=[],this.outgoing=Array.from({length:i},()=>[]),this.incoming=Array.from({length:i},()=>[]);let r=new Map,n=new Map;for(let e of t.keys())n.set(e,n.size);this.nodeCount=n.size;for(let i of e){let e=t.get(i.source),o=t.get(i.target);if(void 0===e||void 0===o||!(i.startTime<i.endTime))continue;let a=n.get(i.source),s=n.get(i.target),l=`${a}:${s}`;r.has(l)||r.set(l,r.size);let c=this.routes.length;this.routes.push({edge:i,source:e,target:o,sourceNode:a,targetNode:s,pair:r.get(l),reverse:-1}),this.outgoing[e].push(c),this.incoming[o].push(c)}for(let e of this.routes)e.reverse=r.get(`${e.targetNode}:${e.sourceNode}`)??-1;if(this.events=this.routes.flatMap((e,t)=>[{time:e.edge.startTime,route:t,delta:1},{time:e.edge.endTime,route:t,delta:-1}]).sort((e,t)=>e.time-t.time||e.delta-t.delta||e.route-t.route),this.smallPairs=this.routes.length<=80?[]:null,this.smallPairs)for(let e=0;e<this.routes.length;e++)for(let t=e+1;t<this.routes.length;t++)Ww(this.routes[e].edge,this.routes[t].edge)&&this.smallPairs.push([e,t]);this.work=this.smallPairs?.length??1/0}crossing(e,t,i){return(i[e.source]-i[t.source])*(i[e.target]-i[t.target])<0?1:0}count(e){if(this.smallPairs){let t=0;for(let[i,r]of this.smallPairs)t+=this.crossing(this.routes[i],this.routes[r],e);return t}let t=Array.from({length:this.size+1},()=>[]);for(let i of this.routes){let r=e[i.source],n=e[i.target];for(let e=r+1;e<=this.size;e+=e&-e)t[e].push(n)}let i=t.map(e=>new jw(e)),r=new Int32Array(4*this.nodeCount),n=new Int32Array(this.routes.length),o=(e,t)=>{let r=0;for(let n=e;n>0;n-=n&-n)r+=i[n].below(t);return r},a=0;for(let t of this.events){let s=this.routes[t.route],l=e[s.source],c=e[s.target];1===t.delta&&(a+=o(l,this.size)-o(l,c+1)+o(this.size,c)-o(l+1,c),l!==c&&(a-=r[4*s.sourceNode+(l<c?1:0)],a-=r[4*s.targetNode+(l<c?2:3)],s.reverse>=0&&(a+=n[s.reverse])));for(let e=l+1;e<=this.size;e+=e&-e)i[e].add(c,t.delta);l!==c&&(r[4*s.sourceNode+(l<c?3:2)]+=t.delta,r[4*s.targetNode+(l<c?0:1)]+=t.delta),n[s.pair]+=t.delta}return a}swapDelta(e,t,i){let r=0,n=0,o=r=>i[r===e?t:r===t?e:r],a=(e,t)=>{let a=this.routes[e],s=this.routes[t];if(!Ww(a.edge,s.edge))return;n++;let l=(o(a.source)-o(s.source))*(o(a.target)-o(s.target))<0?1:0;r+=l-this.crossing(a,s,i)};for(let i of this.outgoing[e])for(let e of this.outgoing[t])a(i,e);for(let i of this.incoming[e])for(let r of this.incoming[t]){let n=this.routes[i],o=this.routes[r];n.source===e&&o.source===t||n.source===t&&o.source===e||a(i,r)}return{delta:r,evaluations:n}}};function qw(e){let t=vw();return e.forEach((e,i)=>{for(let r of e.occupants)t[r.id]=i}),t}function Xw(e,t,i){e.length=i.length;for(let t=0;t<i.length;t++)e[t]=i[t];let r=qw(i);for(let e of Object.keys(t))delete t[e];Object.assign(t,r)}function Gw(e){let t=new Map,i=[];e.forEach((e,r)=>{if(!e.group)return void i.push({anchor:r,stableId:Sw(e),slots:[e]});let n=t.get(e.group)??{indexes:[],slots:[]};n.indexes.push(r),n.slots.push(e),t.set(e.group,n)});for(let[e,r]of t)i.push({anchor:r.indexes.reduce((e,t)=>e+t,0)/r.indexes.length,stableId:`${e}\0${r.slots.map(Sw).join("\0")}`,slots:r.slots});return i.sort((e,t)=>e.anchor-t.anchor||ww(e.stableId,t.stableId))}function Vw(e){return e.some(e=>e.group)?Gw(e).flatMap(e=>e.slots):[...e]}function Hw(e){return e.flatMap(e=>e.slots)}function Uw(e,t,i){let r=new Map;return e.forEach((e,t)=>{for(let i of e.slots)r.set(i,t)}),e.map((e,n)=>{if(e.slots.length<=1)return e;let o=new Map;for(let t of e.slots)o.set(t,0);for(let e of t){let t=r.get(e.source),i=r.get(e.target);if(null==t||null==i)continue;let a=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===n&&i!==n){let t=i>n?1:-1;o.set(e.source,(o.get(e.source)??0)+a*t)}else if(i===n&&t!==n){let i=t>n?1:-1;o.set(e.target,(o.get(e.target)??0)+a*i)}}let a=[...e.slots].sort((e,t)=>(o.get(e)??0)-(o.get(t)??0)||i(e,t));return{...e,slots:a}})}function Zw(e,t){e.some(e=>e.group)&&Xw(e,t,Vw(e))}function Kw(e,t){let i=[...new Set(Object.values(e))].sort((e,t)=>e-t),r=new Map(i.map((e,t)=>[e,t])),n=new Map(Object.entries(e).map(([e,t])=>[e,r.get(t)]));return new Yw(t,n,i.length).count(i.map((e,t)=>t))}function Qw(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];null==t||null==n||(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}var Jw=e=>{let t=1;for(let i=2;i<=e;i++)t*=i;return t},eS=828*Jw(8),tS=3e3;function iS(e){let t=new Array(e.length),i=Math.floor((e.length-1)/2),r=i-1,n=i+1;e.length>0&&(t[i]=e[0]);for(let i=1;i<e.length;i++)i%2==1&&n<e.length?t[n++]=e[i]:r>=0?t[r--]=e[i]:t[n++]=e[i];return t}function rS(e,t,i){let r=i(e),n=r,o=[...e],a=Math.floor((e.length-1)/2);for(let s of t){let t=e.indexOf(s);if(t===a)continue;e.splice(t,1),e.splice(a,0,s);let l=i(e);l<=r?(r=l,l<n&&(o=[...e],n=l)):(e.splice(a,1),e.splice(t,0,s))}return o}function nS(e,t,i,r,n,o,a){let s=[...n],l=new Map(n.map(e=>[e,Sw(e)])),c=new Map;for(let e of n)for(let t of e.occupants)c.set(t.id,e);let u=new Map,d=[];for(let e of t){let t=c.get(e.source),i=c.get(e.target);!t||!i||(u.set(e,[t,i]),t!==i&&d.push({source:t,target:i,weight:e.value}))}let h=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),p=a.plotH/Math.max(1,n.length),f=n.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),g=Math.max(1,h)*(Math.max(1,a.plotH)+p*Math.max(f,n.length)+1e-6*Math.max(1,n.length-1))+1,m=4*p,y={fullCrossing:0,localCrossing:0},x=new Map,b=(e,t)=>{let r=x.get(e);r||(r=new Map,x.set(e,r));let n=r.get(t);if(null!=n)return n;let o=function(e,t,i){return mw(Aw([e,t],i)).adjacentClearance[0]??0}(e,t,i);return r.set(t,o),o},v=new Map(n.map((e,t)=>[e,t])),w=new Yw(t,new Map([...c].map(([e,t])=>[e,v.get(t)])),n.length),S=e=>{let t=new Int32Array(n.length);for(let i=0;i<e.length;i++)t[v.get(e[i])]=i;return t},k=new Map([...u].map(([e,[t,i]])=>[e,{source:v.get(t),target:v.get(i),weight:e.value>0?e.value:1}])),A=[...k.values()],M=new Map,$=new Map,_=new Map,P=(e,t,i)=>{e.has(t)||e.set(t,new Set),e.get(t).add(i)};for(let e of t)P(M,e.source,e.target),P($,e.target,e.source),P(_,e.source,e.target),P(_,e.target,e.source);let I=t.flatMap(e=>{if(!(e=>1===M.get(e.source)?.size&&M.get(e.source).has(e.target)||1===_.get(e.source)?.size||1===_.get(e.target)?.size)(e))return[];let t=k.get(e);return t&&t.source!==t.target?[t]:[]}),T=e=>{let t=0;for(let i of I)t+=Math.max(0,Math.abs(e[i.source]-e[i.target])-1)*i.weight;return t*m},L=e=>T(S(e)),C=new Int32Array(n.length),R=new Float64Array(n.length),N=new Float64Array(n.length+1),D=e=>{for(let t=0;t<e.length;t++)C[v.get(e[t])]=t;let t=w.count(C);if(e.length>0){let t=v.get(e[0]);R[t]=a.padding+e[0].peak.topPeak*a.valueScale;for(let t=1;t<e.length;t++){let i=v.get(e[t-1]),r=v.get(e[t]);R[r]=R[i]+b(e[t-1],e[t])*a.valueScale+a.padding}let i=v.get(e[e.length-1]),r=R[i]+e[e.length-1].peak.botPeak*a.valueScale+a.padding;if(r>a.plotH&&r>0){let e=a.plotH/r;for(let t=0;t<R.length;t++)R[t]*=e}}N[0]=0;for(let t=0;t<e.length;t++)N[t+1]=N[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0,r=0,n=0;for(let e of A){let t=C[e.source],o=C[e.target];if(i+=Math.abs(t-o)*e.weight,r+=Math.abs(R[e.source]-R[e.target])*e.weight,Math.abs(t-o)>=2){let i=Math.min(t,o)+1,r=Math.max(t,o);n+=(N[r]-N[i])*e.weight}}return t*g+r+n*p+T(C)+1e-6*i},F=(n,o,s)=>{let l=o;null==l&&(l=w.count(S(n)),y.fullCrossing++);let{map:c,geometry:u,weightedLength:d,pixelLength:h}=(r=>{let n=qw(r),o=r.slice(0,-1).map((e,t)=>b(e,r[t+1])),s=_w(e,t,i,r,n,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:o});return{map:n,geometry:s,weightedLength:Qw(n,t),pixelLength:Pw(s.centerlines,t)}})(n),f=s?Nw(t,i,n,c,u.centerlines,r,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:s}):((e,i)=>{let r=new Array(e.length+1).fill(0);for(let t=0;t<e.length;t++)r[t+1]=r[t]+e[t].peak.topPeak+e[t].peak.botPeak;let n=0;for(let e of t){let t=i[e.source],o=i[e.target];if(null==t||null==o||Math.abs(t-o)<2)continue;let a=Math.min(t,o)+1;n+=(r[Math.max(t,o)]-r[a])*(e.value>0?e.value:1)}return n})(n,c);return{crossings:l,weightedLength:d,pixelLength:h,transitOcclusion:f,cost:l*g+h+f*p+L(n)+1e-6*d}},E=(e,t,i="quality")=>F(e,t,i),O=[...s],z=(e,t)=>ww(l.get(e),l.get(t)),B=function(e){let t=new Set;for(let i of e)if(i.group){if(t.has(i.group))return!0;t.add(i.group)}return!1}(O),j=(e,t,i,r=tS)=>{let n=t(e);for(let o=0;o<i&&r>0;o++){let i=!1,a=Array.from({length:e.length-1},(e,t)=>t);o%2==1&&a.reverse();for(let o of a){if(r--<=0)break;let a=e[o],s=e[o+1],l=w.swapDelta(v.get(a),v.get(s),S(e));[e[o],e[o+1]]=[s,a],y.localCrossing+=l.evaluations;let c=t(e,n.crossings+l.delta);c.cost<n.cost?(n=c,i=!0):[e[o],e[o+1]]=[a,s]}if(!i)break}return e},W=e=>{let t=(e=>{let t=yw(e,d,e=>F(e).cost,{passes:6,compare:z,maxEvaluations:tS});return j(t,F,6)})(e);if((e.length<=8?Jw(e.length)*(e.length+A.length+w.work):1/0)>eS)return t;let i=bw(e,D,{maxItems:8,maxEvaluations:5e4}),r=E(i),n=E(t);return r.crossings!==n.crossings&&r.crossings<n.crossings?i:t},Y=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),q=(e,t)=>Y(t)-Y(e)||ww(e.stableId,t.stableId),X=(e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||z(e,t),G="geometry-refine"===a.mode;if(G||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder?G||"inside-out"!==a.laneOrder||(O=B?Hw(iS([...Gw(O)].sort(q))):iS([...O].sort(X))):O=B?(e=>{let t=Gw(e);if(t.length<=1)return Hw(t);let i=e=>F(Hw(e)).cost;t=Gw(W(e)),t=Uw(t,d,z);let r=function(e,t){let i=new Map;for(let t of e)for(let e of t.slots)i.set(e,t);let r=new Map;for(let e of t){let t=i.get(e.source),n=i.get(e.target);if(!t||!n||t===n)continue;let o=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,a=t.stableId<n.stableId?`${t.stableId}\0${n.stableId}`:`${n.stableId}\0${t.stableId}`,s=r.get(a);s?s.weight=(s.weight??0)+o:r.set(a,{source:t,target:n,weight:o})}return[...r.values()]}(t,d);if(t=yw(t,r,i,{passes:6,compare:(e,t)=>ww(e.stableId,t.stableId),maxEvaluations:tS}),t=xw(t,i,{passes:8,maxEvaluations:tS}),(t.length<=8?Jw(t.length)*(t.length+A.length+w.work):1/0)<=eS){let e=bw(t,e=>D(Hw(e)),{maxItems:8,maxEvaluations:5e4}),i=Hw(e),r=Hw(t),n=E(i),o=E(r);n.crossings!==o.crossings?t=n.crossings<o.crossings?e:t:n.cost<o.cost&&(t=e)}return t=Uw(t,d,z),Hw(t)})(O):W(O),!G&&"crossing-min+inside-out"===a.laneOrder&&O.length>1)if(B){let e=Gw(O);O=Hw(rS(e,[...e].sort(q),e=>F(Hw(e)).cost))}else O=rS(O,[...O].sort(X),e=>F(e).cost);if((G||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&O.length>1)if(B){let e=xw(Gw(O),e=>E(Hw(e),void 0,"score").cost,{passes:6});e=Uw(e,d,z),O=Hw(e)}else j(O,(e,t)=>E(e,t,"score"),1,1/0);let V=Vw(s);O=Vw(O);let H=E(O),U=E(V);if(G){let e=L(V),t=L(O);(H.crossings>U.crossings||H.crossings===U.crossings&&t>e+1e-9||H.cost>U.cost)&&(O=V,H=U)}else H.cost>U.cost&&(O=V,H=U);let Z=function({order:e,after:t,nodes:i,edges:r,outgoingPartners:n,incomingPartners:o,slotForNode:a,averageGap:s,evaluate:l}){let c=(i,n)=>{let o=[...new Set(n.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),a=e.indexOf(i),c=o[0],u=o[o.length-1];if(o.length<3||!o.includes(a)||u-c+1!==o.length||Math.abs(2*a-c-u)<=1)return;let d=[...e];d.splice(a,1),d.splice(c+u>>1,0,i);let h=Vw(d),p=l(h),f=new Set(i.occupants.map(e=>e.id)),g=new Set(n.flatMap(e=>e.occupants.map(e=>e.id))),m=r.reduce((e,t)=>f.has(t.source)&&g.has(t.target)||f.has(t.target)&&g.has(t.source)?e+(t.value>0?t.value:1):e,0),y=Math.abs(2*a-c-u)*s*Math.max(1,m);(function(e,t,i=0){return e.crossings<t.crossings||e.crossings===t.crossings&&e.cost<=t.cost+i})(p,t,y)&&(e=h,t=p)};for(let[e,t]of n)!o.has(e)&&t.size>=3&&c(a.get(e),[...t].map(e=>a.get(e)));for(let e of i){let t=a.get(e.id);!e.group&&t.group&&(o.get(e.id)?.size??0)>=3&&c(t,[...o.get(e.id)??[]].map(e=>a.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,i)=>i.indexOf(e)===t))}return{order:e,after:t}}({order:O,after:H,nodes:e,edges:t,outgoingPartners:M,incomingPartners:$,slotForNode:c,averageGap:p,evaluate:E});return O=Z.order,H=Z.after,Xw(n,o,O),{before:U,after:H,initialOrder:s.map(e=>l.get(e)),evaluations:y}}function oS(e,t,i){let r=e.map(e=>{let r=e.occupants.map(e=>({id:e.id,end:i[e.id]?.end??e.end})),n=0,o=0;for(let e of r){let i=t[e.id];n=Math.max(n,i?.topPeak||0),o=Math.max(o,i?.botPeak||0)}return{occupants:r,peak:{topPeak:n,botPeak:o},...null!=e.group?{group:e.group}:{}}}),n=vw();return r.forEach((e,t)=>{for(let i of e.occupants)n[i.id]=t}),{slots:r,slotByNode:n}}var aS=/*#__PURE__*/new Map,sS=1e5,lS=1e-9;function cS(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(e.end<=t.start||t.end<=e.start)}function uS(e,t){return ww(e,t)<=0?`${e}\0${t}`:`${t}\0${e}`}function dS(e){let t=new Map,i=new Map;for(let r of e)i.has(r.source)||i.set(r.source,new Set),t.has(r.target)||t.set(r.target,new Set),i.get(r.source).add(r.target),t.get(r.target).add(r.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...i].map(([e,t])=>[e,t.size]))}}function hS(e){let t=new Map,i=new Map,r=(e,t,i,r)=>{let n=e.get(t);n||(n=new Map,e.set(t,n)),n.set(i,(n.get(i)??0)+r)};for(let n of e){let e=n.value>0&&Number.isFinite(n.value)?n.value:1;r(t,n.source,n.target,e),r(i,n.target,n.source,e)}let n=new Map,o=e=>{if(n.has(e))return;let r=t.get(e),o=i.get(e),a=new Map;for(let[e,t]of r??[])a.set(e,(a.get(e)??0)+t);for(let[e,t]of o??[])a.set(e,(a.get(e)??0)+t);if(1===a.size){let[t,i]=[...a][0];n.set(e,{partner:t,weight:i})}};for(let t of e)o(t.source),o(t.target);return n}function pS(e,t,i){let r=i.get(e),n=i.get(t);return!r||!n||r.partner===n.partner||r.partner===t||n.partner===e}function fS(e,t,i){return!!i.has(e)&&t.some(t=>!pS(e,t,i))}function gS(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function mS(e,t,i,r){if(e.length<=12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>new Map),a=dS(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=gS(e,a);o[t].set(i,(o[t].get(i)??0)+r),o[i].set(t,(o[i].get(t)??0)+r)}let s=hS(i),l=e.map(e=>s.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map),u=0;for(let i=0;i<e.length-1&&u<5e4;i++)if(s.has(e[i]))for(let r=i+1;r<e.length;r++){if(!s.has(e[r])||t.conflicts(e[i],e[r]))continue;u++;let n=Math.min(l[i],l[r])||Math.max(l[i],l[r]),o=pS(e[i],e[r],s)?n:-n;if(!(Math.abs(o)<=lS)&&(c[i].set(r,o),c[r].set(i,o),u>=5e4))break}let d=[...r.assignment],h=Array.from({length:r.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));let p=(e,t,i)=>{let r=d[t],n=d[i],o=0,a=new Set;for(let s of[t,i])for(let[l,c]of e[s]){let e=s<l?`${s}:${l}`:`${l}:${s}`;if(a.has(e))continue;a.add(e);let u=d[s]===d[l],h=(s===t?n:r)===(l===t?n:l===i?r:d[l]);u!==h&&(o+=h?c:-c)}return o},f=(e,t,i)=>{let r=0;for(let[n,o]of e[t]){let e=d[t]===d[n],a=i===d[n];e!==a&&(r+=a?o:-o)}return r},g=(e,t)=>e>lS||Math.abs(e)<=lS&&t>lS,m=(e,t,i,r)=>e>i+lS||Math.abs(e-i)<=lS&&t>r+lS,y=0;for(let i=0;i<32&&y<sS;i++){let i=null,r=-1,n=-1,a=-1,s=-1/0,l=-1/0;for(let u=0;u<e.length;u++){for(let p=0;p<h.length&&!(y++>=sS);p++){if(p===d[u]||!h[p].every(i=>!t.conflicts(e[u],e[i])))continue;let y=f(o,u,p),x=f(c,u,p);g(y,x)&&m(y,x,s,l)&&(i="move",r=u,n=-1,a=p,s=y,l=x)}if(y>=sS)break}for(let u=0;u<e.length-1;u++){for(let f=u+1;f<e.length&&!(y++>=sS);f++){let y=d[u],x=d[f];if(y===x||!h[x].every(i=>i===f||!t.conflicts(e[u],e[i]))||!h[y].every(i=>i===u||!t.conflicts(e[f],e[i])))continue;let b=p(o,u,f),v=p(c,u,f);g(b,v)&&m(b,v,s,l)&&(i="swap",r=u,n=f,a=-1,s=b,l=v)}if(y>=sS)break}if(null==i||-1===r)break;if("move"===i){let e=d[r];h[e].splice(h[e].indexOf(r),1),h[a].push(r),d[r]=a;continue}let u=d[r],x=d[n];h[u].splice(h[u].indexOf(r),1,n),h[x].splice(h[x].indexOf(n),1,r),d[r]=x,d[n]=u}return d}function yS(e,t){let i=1/0,r=-1/0;for(let t of e?.samples??[])t.topMass+t.botMass<=1e-9||(i=Math.min(i,t.t),r=Math.max(r,t.t));return Number.isFinite(i)&&Number.isFinite(r)?(null!=t.start&&(i=Math.max(i,t.start)),null!=t.end&&(r=Math.min(r,t.end)),r>=i?{start:i,end:r}:{start:null,end:null}):{start:null,end:null}}function xS(e,t,i,r){let n=function(e,t,i,r){return`${e.map(e=>{let t=i[e.id],n=r[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,n?.start??"",n?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,i,r),o=function(e){return aS.get(e)}(n);if(o)return oS(o.slots,i,r);let a=vw();for(let t of e)a[t.id]=yS(i[t.id],r[t.id]);let s=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,i)=>t[e.id].start-t[i.id].start||t[e.id].end-t[i.id].end||ww(e.id,i.id)).map(e=>e.id)}(e,a),l=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=hS(t),d=function(e,t,i,r,n,o){let a=new Set,s=new Map(e.map(e=>[e,new Set])),l=new Map(e.map(e=>[e,new Set]));for(let e of r)a.add(uS(e.source,e.target)),s.get(e.target)?.add(e.source),l.get(e.source)?.add(e.target);let c=new Map,u=new Set,d=(e,t)=>{for(let i=0;i<e.length;i++)for(let r=i+1;r<e.length;r++){let n=uS(e[i],e[r]);t instanceof Map?t.set(n,[e[i],e[r]]):t.add(n)}};for(let e of l.values())d([...e],c);for(let e of s.values())d([...e],u);let h=new Set;for(let[e,[r,n]]of c)u.has(e)&&(cS(t[r],t[n])||cS(i[r],i[n])&&(h.add(r),h.add(n)));return{conflicts:(e,i)=>{let r=n.get(e),s=n.get(i);return!((null==r||null==s||r===s)&&(null!=r==(null!=s)||a.has(uS(e,i))||o.has(e)&&o.has(i)&&pS(e,i,o))&&!cS(t[e],t[i])&&(!h.has(e)&&!h.has(i)||a.has(uS(e,i))))}}}(s,a,r,t,c,u),h=function(e,t,i=new Map){let r=[],n=[];for(let o of e){let e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e))&&!fS(o,e,i));-1===e&&!i.has(o)&&(e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e)))),-1===e&&(e=r.length,r.push([])),r[e].push(o),n.push(e)}return{assignment:n,slotCount:r.length}}(s,d,u),p=function(e,t,i,r){if(0===e.length||e.length>12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>new Float64Array(e.length)),a=Array.from({length:e.length},()=>new Map),s=Array.from({length:e.length},()=>new Map),l=dS(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=gS(e,l);o[t][i]+=r,o[i][t]+=r,s[t].set(i,(s[t].get(i)??0)+r),a[i].set(t,(a[i].get(t)??0)+r)}let c=hS(i),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++){for(let[e,r]of a[t])d[t][i]+=Math.min(r,a[i].get(e)??0);for(let[e,r]of s[t])d[t][i]+=Math.min(r,s[i].get(e)??0);if(c.has(e[t])&&c.has(e[i])){let r=Math.min(u[t],u[i])||Math.max(u[t],u[i]);d[t][i]+=pS(e[t],e[i],c)?r:-r}d[i][t]=d[t][i]}let h=[...r.assignment],p=(t=>{let i=0,r=0;for(let n=0;n<e.length;n++)for(let a=n+1;a<e.length;a++)t[n]===t[a]&&(i+=o[n][a],r+=d[n][a]);return{flow:i,affinity:r}})(h),f=0,g=new Array(e.length).fill(-1),m=Array.from({length:r.slotCount},()=>[]),y=(i,n,a,s)=>{if(f>=75e3)return;if(i===e.length)return f++,void((a>p.flow||a===p.flow&&s>p.affinity||a===p.flow&&s===p.affinity&&function(e,t){for(let i=0;i<Math.min(e.length,t.length);i++)if(e[i]!==t[i])return e[i]<t[i];return e.length<t.length}(g,h))&&(h=[...g],p={flow:a,affinity:s}));let l=Math.min(n+1,r.slotCount-1);for(let r=0;r<=l;r++){if(m[r].some(r=>t.conflicts(e[i],e[r])))continue;let l=0,c=0;for(let e of m[r])l+=o[i][e],c+=d[i][e];if(g[i]=r,m[r].push(i),y(i+1,Math.max(n,r),a+l,s+c),m[r].pop(),g[i]=-1,f>=75e3)return}};return g[0]=0,m[0].push(0),y(1,0,0,0),h}(s,d,t,{...h,assignment:mS(s,d,t,h)}),f=new Map,g=p.map(e=>(f.has(e)||f.set(e,f.size),f.get(e))),m=Array.from({length:f.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y=vw();s.forEach((e,t)=>{let i=g[t],r=m[i];r.occupants.push({id:e,end:a[e].end??-1/0});let n=l.get(e)?.group;n&&(r.group=n),y[e]=i});for(let t of[...e].sort((e,t)=>ww(e.id,t.id)))null==y[t.id]&&(m[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(let e of m){e.occupants.sort((e,t)=>(a[e.id].start??1/0)-(a[t.id].start??1/0)||ww(e.id,t.id));for(let t of e.occupants){let r=i[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,r?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,r?.botPeak||0)}}let x={slots:m,slotByNode:y};return function(e,t){for(aS.has(e)&&aS.delete(e),aS.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(vw(),t.slotByNode)});aS.size>12;){let e=aS.keys().next().value;if(null==e)break;aS.delete(e)}}(n,x),x}function bS(e){return e.topMass+e.botMass}function vS(e){let t=new Map;for(let i of e.samples){if(Number.isNaN(i.t))continue;let e=t.get(i.t);e||(e=[],t.set(i.t,e)),e.push(i)}let i=0,r=-1/0;return n=>{n>=r||(i=0),r=n;let o=t.get(n);if(o){let e=o.reduce((e,t)=>bS(t)>=bS(e)?t:e,o[0]);return{exact:o,sample:e}}for(;i<e.samples.length&&!(e.samples[i].t>n);)i++;return{exact:o,sample:e.samples[i-1]??null}}}function wS(e,t,i,r,n,o,a=0){let s=new Map;for(let i of e){if(!i.group||!t[i.id])continue;let e=s.get(i.group)??[];e.push(i),s.set(i.group,e)}if(0===s.size||!(o>0))return t;let l=function(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]))}(t);for(let[e,c]of s){let s=i.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===s.length)continue;let u=s[0].slot,d=s.at(-1).slot,h=n[u.occupants[0]?.id],p=n[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;let f=(h-u.peak.topPeak*o+(p+d.peak.botPeak*o))/2,g=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),m=new Map;for(let e of c)m.set(e.id,new Map);let y=new Map(c.map(e=>[e.id,vS(t[e.id])]));for(let e of g){let t=new Map;for(let i of c){let{sample:n}=y.get(i.id)(e);if(!n||bS(n)<=1e-9)continue;let o=r[i.id];if(null==o)continue;let a=t.get(o)??[];a.push({node:i,sample:n}),t.set(o,a)}let i=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:he(t.map(({sample:e})=>bS(e)))}));if(0===i.length)continue;let s=f-(i.reduce((e,t)=>e+t.mass,0)*o+Math.max(0,a)*Math.max(0,i.length-1))/2;for(let t of i){for(let{node:i,sample:r}of t.active){let t=(s-n[i.id])/o+r.topMass-(r.boundaryOffset??0);m.get(i.id).set(e,t)}s+=t.mass*o+Math.max(0,a)}}for(let e of c){let i=t[e.id],r=l[e.id],n=m.get(e.id),o=y.get(e.id),a=[];for(let e of g){let t=n.get(e),{exact:i,sample:r}=o(e);i?a.push(...i.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!r||bS(r)<=1e-9||a.push({...r,t:e,boundaryOffset:(r.boundaryOffset??0)+t})}r.samples=a,r.localAttachments=new Map([...i.localAttachments].map(([e,t])=>{let i=n.get(t.time);return[e,{...t,...null!=i?{boundaryOffset:(t.boundaryOffset??0)+i}:{}}]}))}}return l}function SS(e,t,i,r,n){let{plotH:o,padding:a,valueScale:s,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:f}=n,g=vw(),m=vw();for(let t of e)g[t.id]=i[t.id].topPeak||0,m[t.id]=i[t.id].botPeak||0;let y="half"===u,x=vw();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,i=Array.isArray(t.xExtent)?t.xExtent[1]:null,n=null!=e&&Number.isFinite(e)?e:1/0,o=null!=i&&Number.isFinite(i)?i:-1/0;for(let e of r.outgoing[t.id]){e.startTime<n&&(n=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<n&&(n=e.systemInTime);let t=y?(e.startTime+e.endTime)/2:e.endTime;t>o&&(o=t)}for(let e of r.incoming[t.id]){let t=y?(e.startTime+e.endTime)/2:e.startTime;t<n&&(n=t),e.endTime>o&&(o=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>o&&(o=e.systemOutTime)}x[t.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(o)?o:null}}let b=vw(),v=[],w=[];if(n.frozenSlots){let e=oS(n.frozenSlots,i,x);v=e.slots,b=e.slotByNode,w=v.map(Sw)}else if("reuse"===l){let r=xS(e,t,i,x);v=r.slots,b=r.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:x[e.id]?.end??-1/0}],peak:{topPeak:g[e.id],botPeak:m[e.id]},...e.group?{group:e.group}:{}}),b[e.id]=t});Zw(v,b),0===w.length&&(w=v.map(Sw));let S=null;n.frozenSlots||(n.fixedSlotOrder?function(e,t,i){let r=new Map(i.map((e,t)=>[e,t]));Xw(e,t,[...e].sort((e,t)=>(r.get(Sw(e))??1/0)-(r.get(Sw(t))??1/0)||ww(Sw(e),Sw(t))))}(v,b,n.fixedSlotOrder):n.runOrdering&&c&&"insertion"!==c&&(S=nS(e,t,i,x,v,b,{plotH:o,padding:a,valueScale:s,groupPadding:h,laneOrder:c,ribbonLane:p,domain:f}))),Zw(v,b);let k=_w(e,t,i,v,b,{plotH:o,padding:a,valueScale:s,stackValueScale:n.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+k.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=S?.before.crossings??null,$=S?.after.crossings??null,_=S?.before.weightedLength??null,P=S?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:k.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:k.slotCenter,stackCenter:k.stackCenter,verticalUtilization:k.verticalUtilization,selectedSlotOrder:v.map(Sw),initialSlotOrder:w,ordering:S,crossingsBefore:M,crossingsAfter:$,lengthBefore:_,lengthAfter:P}}function kS(e,t,i){let{plotH:r,pairing:n="temporal",packing:o="reuse",laneOrder:a="crossing-min",lifetimeMode:s="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=i,f=Number.isFinite(d)?Math.max(0,d):0,g=function(e,t){let i=vw(),r=vw();for(let t of e)i[t.id]=[],r[t.id]=[];for(let e of t)r[e.source]&&r[e.source].push(e),i[e.target]&&i[e.target].push(e);return{incoming:i,outgoing:r}}(e,t),m=function(e,t,i,r="temporal"){let n="temporal"===r?(e,t)=>e.endTime-t.endTime||ww(e.id,t.id):(e,t)=>t.value-e.value||ww(e.id,t.id),o="temporal"===r?(e,t)=>e.startTime-t.startTime||ww(e.id,t.id):(e,t)=>t.value-e.value||ww(e.id,t.id),a=new Map;for(let e of t)a.set(e.id,{});let s=(e,t)=>{let i=new Map;for(let r of e){let e=r[t];i.has(e)||i.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let n=i.get(e);n.edges.push(r),n.total+=r.value,n.earliestStart=Math.min(n.earliestStart,r.startTime),n.latestEnd=Math.max(n.latestEnd,r.endTime)}let a=[...i.values()];"temporal"===r?a.sort((e,i)=>"target"===t?e.earliestStart-i.earliestStart||ww(e.partner,i.partner):e.latestEnd-i.latestEnd||ww(e.partner,i.partner)):a.sort((e,t)=>t.total-e.total||ww(e.partner,t.partner));for(let e of a)e.edges.sort("target"===t?o:n);return a};for(let t of e){let e=i.outgoing[t.id],r=i.incoming[t.id];if(0===r.length)s(e,"target").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).sourceSide=i});else if(0===e.length)s(r,"source").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).targetSide=i});else{let t=s(r,"source"),i=s(e,"target"),n=Math.max(t.length,i.length);for(let e=0;e<n;e++){let r=e%2==0?"top":"bot";if(t[e])for(let i of t[e].edges)a.get(i.id).targetSide=r;if(i[e])for(let t of i[e].edges)a.get(t.id).sourceSide=r}}}return a}(e,t,g,n),y=vw();for(let t of e)y[t.id]=zw(t,g,m,void 0,u);let x=SS(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,runOrdering:!0,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),b=x.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=new Set;for(let e of t){let t=x.slotByNode[e.source],i=x.slotByNode[e.target];if(void 0===t||void 0===i)continue;let r=m.get(e.id);t!==i?i<t?(r.sourceSide="top",r.targetSide="bot"):(r.sourceSide="bot",r.targetSide="top"):(v.add(e.id),r.sourceSide="bot",r.targetSide="bot")}for(let t of e){let e=g.outgoing[t.id],i=g.incoming[t.id],r=new Set(e.map(e=>m.get(e.id).sourceSide)),n=new Set(i.map(e=>m.get(e.id).targetSide));if(1===r.size&&i.length>0){let e=[...r][0];for(let t of i)x.slotByNode[t.source]===x.slotByNode[t.target]&&(m.get(t.id).targetSide=e)}if(1===n.size&&e.length>0){let t=[...n][0];for(let i of e)x.slotByNode[i.source]===x.slotByNode[i.target]&&(m.get(i.id).sourceSide=t)}}(function(e,t,i){let r=new Map,n=[];for(let t of e)n.push({time:t.startTime,kind:"out",edge:t}),n.push({time:t.endTime,kind:"in",edge:t});n.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||ww(e.edge.id,t.edge.id));let o=e=>{let t=r.get(e);return t||(t={top:0,bot:0},r.set(e,t)),t},a=(e,t,i)=>{let r="top"===t?"bot":"top",n=Math.min(i,e[t]);e[t]-=n;let o=i-n;o>0&&(e[r]=Math.max(0,e[r]-o))};for(let e of n){let{edge:r}=e;if("in"===e.kind){let e=t.get(r.id)?.targetSide??"bot";o(r.target)[e]+=r.value;continue}let n=o(r.source),s=t.get(r.id),l=s.sourceSide??"bot";if(i[r.source]===i[r.target]){let e=n.top>=r.value,t=n.bot>=r.value;e!==t?l=e?"top":"bot":!e&&!t&&n.top!==n.bot&&(l=n.top>n.bot?"top":"bot"),s.sourceSide=l,s.targetSide=l}a(n,l,r.value)}})(t,m,x.slotByNode),function(e,t,i,r){for(let n of e){let e=t.incoming[n.id],o=t.outgoing[n.id];if(0===e.length||0===o.length)continue;let a=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let r of e)"top"===i.get(r.id).targetSide?t.inTop+=r.value:t.inBot+=r.value;for(let e of o)"top"===i.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},s=(e,t)=>{let n=a(),s="top"===e?n.outTop-n.inTop:n.outBot-n.inBot,l="top"===t?n.inTop-n.outTop:n.inBot-n.outBot;if(s<=0||l<=0)return!1;let c=Math.min(s,l),u=o.filter(t=>!r.has(t.id)&&i.get(t.id).sourceSide===e&&t.value<=c).sort((e,t)=>t.value-e.value||ww(e.id,t.id));return 0!==u.length&&(i.get(u[0].id).sourceSide=t,!0)},l=o.length+1;for(;l-- >0&&(s("top","bot")||s("bot","top")););}}(e,g,m,v),y=vw();for(let t of e)y[t.id]=zw(t,g,m,void 0,u);let w=SS(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),S=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),k=w.slots.slice(0,-1).reduce((e,t,i)=>e+(null!=t.group&&t.group===w.slots[i+1].group?1:0),0),A=Math.max(1,w.slots.length+1-k),M=Math.min(12,Math.max(0,.35*r-k*f)/A),$=2*M+kw(w.slots,M,f).reduce((e,t)=>e+t,0),_=S>0?Math.max(0,(r-$)/S):1,P=Number.isFinite(l)&&l>0?Math.min(_,l):_,I=SS(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_}),T=Number.isFinite(l)&&l>0&&l+1e-12<_;if("insertion"!==a&&("hug"===c||T)&&I.slots.length>1&&(nS(e,t,y,I.laneLifetime,I.slots,I.slotByNode,{plotH:r,padding:M,valueScale:P,groupPadding:f,laneOrder:a,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),I=SS(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:I.slots,fixedSlotOrder:I.slots.map(Sw),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_})),function(e,t){let i=(e,i)=>{for(let r of e){let e=new Map;for(let n of r){let r=`${("out"===i?t.get(n.id)?.sourceSide:t.get(n.id)?.targetSide)??""}\0${"out"===i?n.startTime:n.endTime}`,o="out"===i?`${n.target}\0${n.endTime}`:`${n.source}\0${n.startTime}`,a=e.get(r);if(null!=a&&a!==o)return!0;e.set(r,o)}}return!1};return i(Object.values(e.outgoing),"out")||i(Object.values(e.incoming),"in")}(g,m)){let i=function(e,t,i,r){let n=new Map;for(let o of e){let e=t[o.source]?.localAttachments.get(o.id),a=t[o.target]?.localAttachments.get(o.id),s=i[o.source],l=i[o.target];if(!(e&&a&&Number.isFinite(s)&&Number.isFinite(l)))continue;let c=Ow(e,s,r),u=Ow(a,l,r);n.set(o.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return n}(t,y,I.centerlines,P);y=vw();for(let t of e)y[t.id]=zw(t,g,m,i,u);I=SS(e,t,y,g,{plotH:r,padding:M,valueScale:P,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:I.slots,fixedSlotOrder:I.slots.map(Sw),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:_})}let L=new Map(x.initialSlotOrder.map((e,t)=>[e,t])),C=[...I.slots].sort((e,t)=>(L.get(Sw(e))??1/0)-(L.get(Sw(t))??1/0)||ww(Sw(e),Sw(t))),R=vw();C.forEach((e,t)=>{for(let i of e.occupants)R[i.id]=t});let N=_w(e,t,y,C,R,{plotH:r,padding:M,valueScale:P,stackValueScale:_,lanePlacement:"stack",groupPadding:f}),D=wS(e,y,C,R,N.centerlines,P,f),F=Dw(Kw(R,t),Qw(R,t),t,D,C,R,N.centerlines,I.laneLifetime,P,N.verticalUtilization,h,p);y=wS(e,y,I.slots,I.slotByNode,I.centerlines,P,f);let E=Dw(Kw(I.slotByNode,t),Qw(I.slotByNode,t),t,y,I.slots,I.slotByNode,I.centerlines,I.laneLifetime,P,I.verticalUtilization,h,p);return{nodeData:y,sides:m,valueScale:P,padding:M,compressedPadding:M<12,centerlines:I.centerlines,laneLifetime:I.laneLifetime,slots:I.slots,slotByNode:I.slotByNode,crossingsBefore:"insertion"===a?null:F.crossings,crossingsAfter:"insertion"===a?null:E.crossings,lengthBefore:"insertion"===a?null:F.weightedLength,lengthAfter:"insertion"===a?null:E.weightedLength,layoutQualityBefore:F,layoutQuality:E}}function AS(e){return Y(e)}function MS(e,t,i,r,n,o,a,s,l={}){let c,u,d,h,p=n,f=e=>s?Math.max(s[0],Math.min(s[1],e)):e,g=o(f(e.time)),m=o(f(i.time)),y=e.value*p,x=i.value*p,b=t+(e.boundaryOffset??0)*p,v=r+(i.boundaryOffset??0)*p,w=e.sideMassBefore*p,S=i.sideMassAfter*p;"top"===e.side?(c=b-w,u=c+y):(u=b+w,c=u-y),"top"===i.side?(d=v-S,h=d+x):(h=v+S,d=h-x);let k=l.sourceRunwayStart,A=l.minRun,M=(c+u)/2,$=(d+h)/2,_=Math.abs($-M),P=m-g,I="number"==typeof k&&Number.isFinite(k),T="number"==typeof A&&Number.isFinite(A)&&A>0;if(I&&_>1e-9&&P>0&&("auto"===A||T)){let t="source"===a?.85:"target"===a?.15:.5,i=1.5*Math.min(t*t,(1-t)*(1-t)),r="auto"===A?Math.min(144,Math.sqrt(8*_/i)):A;if(r>P){let t=o(f(Math.min(k,e.time)));if(Number.isFinite(t)){let e=Math.min(g,t);g=Math.min(g,Math.max(e,m-r))}}}let L="source"===a?g+.85*(m-g):"target"===a?g+.15*(m-g):(g+m)/2;return{sx:g,sTop:c,sBot:u,tx:m,tTop:d,tBot:h,cp1X:L,cp2X:L}}function $S(e){return Math.max(18,11*e.length*.58)}function _S(e){let t=1.22*$S(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function PS(e,t){let i=e.labelX-$S(e.labelText),r=t.labelX-$S(t.labelText);return i<=t.labelX+3&&r<=e.labelX+3}var IS=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function TS(e){return e.replace(IS,(e,t,i)=>`${i},${t}`)}function LS(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function CS(e){return{...e,pathD:TS(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function RS(e,t=function(e){let{nodes:t,edges:i,domain:r,usageMode:n="static"}=e,o=function(e,t,i,r={}){let n=uw(r.usageMode??"static"),o=[],a=new Set;for(let t of e)a.has(t.id)&&o.push({kind:"duplicate-node",id:t.id,severity:n.duplicateIds}),a.add(t.id);let s=new Set,l=Array.isArray(i)&&2===i.length,c=l&&Number.isFinite(i[0])&&Number.isFinite(i[1]),u=c&&i[0]<=i[1];(!l||!c||!u)&&o.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[0]<=t.xExtent[1]||o.push({kind:"invalid-node-time",id:t.id}));for(let e of t)s.has(e.id)&&o.push({kind:"duplicate-edge",id:e.id,severity:n.duplicateIds}),s.add(e.id),a.has(e.source)||o.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),a.has(e.target)||o.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&o.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||e.value<=0)&&o.push({kind:"invalid-value",id:e.id}),e.endTime<e.startTime&&o.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):o.push({kind:"invalid-edge-time",id:e.id});return o}(t,i,r,{usageMode:n}),{fatal:a,warnings:s}=function(e){let t=[],i=[];for(let r of e)"fatal"===hw(r)?t.push(r):i.push(r);return{fatal:t,warnings:i}}(o),l=pw(i,o,n);return{layout:a.length?null:kS(t,l,{plotH:"vertical"===e.orientation?e.plotW:e.plotH,...e.layoutOpts,ribbonLane:e.ribbonLane,domain:r}),issues:a,warnings:s}}(e)){let{nodes:i,edges:r,domain:n,plotW:o,plotH:a,ribbonLane:s,ribbonMinRun:l=0,edgeOpacity:c,colorOf:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:p,maxLabels:f,selectionDatum:g="raw",styleRules:m,colorBy:y,valueAccessor:x,usageMode:b="static"}=e,v="vertical"===d?a:o,w="vertical"===d?o:a,{layout:S,issues:k,warnings:A}=t,M=pw(r,[...k,...A],b),$=lw().domain(n).range([0,v]);if(!S)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:k,warnings:A,xScale:$};let{centerlines:_,nodeData:P,valueScale:I}=S,T=ae(y,x),L=[],C=[],R=0===l?new Map:function(e,t,i){let r=new Set(t.map(e=>e.target)),n=new Map(e.map(e=>[e.id,e])),o=new Map;for(let e of t){if(r.has(e.source))continue;let t=o.get(e.source)??[];t.push(e),o.set(e.source,t)}let a=new Map;for(let t of e){if(!t.group)continue;let e=a.get(t.group)??[];e.push(t),a.set(t.group,e)}let s=new Set;for(let[e,t]of a){let i=t.flatMap(e=>o.get(e.id)??[]),n=new Set(i.map(e=>e.startTime));i.length>0&&1===n.size&&t.every(e=>{let t=e.xExtent?.[0],n=i[0].startTime;return!r.has(e.id)&&(o.get(e.id)?.length??0)>0&&Number.isFinite(t)&&t<n})&&s.add(e)}let l=new Map;for(let[e,t]of o){let r=n.get(e);if(r?.group&&!s.has(r.group))continue;let o=r?.xExtent?.[0],a=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=a[0]?.startTime-1,u=null;for(let e=0;e<a.length;){let t=a[e].startTime,r=e+1;for(;r<a.length&&a[r].startTime===t;)r++;for(let t=e;t<r;t++){let e=a[t],r=Number.isFinite(o)&&o<e.startTime,n=Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime;if(!r&&!n)continue;let s=i[0];r&&(s=Math.max(s,o)),n&&(s=Math.max(s,e.systemInTime)),!r&&n&&Number.isFinite(c)&&(s=Math.max(s,c)),null!=u&&(s=Math.max(s,u)),s<e.startTime&&l.set(e.id,s)}u=t,e=r}}for(let[e,t]of a){if(!s.has(e))continue;let i=t.flatMap(e=>o.get(e.id)??[]);if(!i.every(e=>l.has(e.id))){for(let e of i)l.delete(e.id);continue}let r=he(i.map(e=>l.get(e.id)));for(let e of i)l.set(e.id,r)}return l}(i,M,n),N=new Map(i.filter(e=>e.group).map(e=>[e.id,e.group])),D=new Map;for(let e of M){let t=P[e.source]?.localAttachments.get(e.id),i=P[e.target]?.localAttachments.get(e.id);!t||!i||D.set(e.id,MS(t,_[e.source],i,_[e.target],I,$,s,n,{minRun:l,sourceRunwayStart:R.get(e.id)}))}let F=function(e,t,i,r,n,o){let a=new Map(t),s=new Map;for(let t of e){let e=o?.get(t.source),i=null==e?`node:${t.source}`:`group:${e}`,r=s.get(i)??new Map,n=r.get(t.startTime)??[];n.push(t),r.set(t.startTime,n),s.set(i,r)}for(let e of s.values())for(let[o,s]of e){if(!s.some(e=>i.has(e.id)))continue;let e=s.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let l=r(o),c=de(e.map(e=>e.sx));if(!(c<l-1e-9))continue;let u=he(s.map(e=>{let t=i.get(e.id);return null==t?l:Math.min(l,r(t))})),d=Math.min(l,Math.max(c,u));for(let e of s){let i=t.get(e.id),r="source"===n?.85:"target"===n?.15:.5,o=d+(i.tx-d)*r;a.set(e.id,{...i,sx:d,cp1X:o,cp2X:o})}}return a}(M,D,R,$,s,N),E=function(e,t,i,r,n){let o=new Map;for(let a of e){if(!i.has(a.id))continue;let e=t.get(a.id);if(!(e&&e.sx<r(a.startTime)-1e-9))continue;let s=n(e.sx);Number.isFinite(s)&&s<a.startTime&&o.set(a.id,s)}return o}(M,F,R,$,e=>n[0]+e/v*(n[1]-n[0])),O=function(e,t,i){let r=new Map,n=new Map;for(let[e,t]of i??[]){let i=n.get(t)??[];i.push(e),n.set(t,i)}for(let o of e){let e=t.get(o.id);if(!(null!=e&&Number.isFinite(e)&&e<o.startTime))continue;let a=i?.get(o.source),s=null==a?[o.source]:n.get(a)??[o.source];for(let t of s){let i=r.get(t)??new Map,n=i.get(o.startTime);i.set(o.startTime,null==n?e:Math.min(n,e)),r.set(t,i)}}return r}(M,E,N);i.forEach((e,t)=>{let i=P[e.id];if(!i||0===i.samples.length)return;let r=function(e,t){return t&&0!==t.size?e.map(e=>{let i=t.get(e.t);return null==i?e:{...e,t:i}}):e}(i.samples,O.get(e.id)),o=function(e,t,i,r,n){if(0===e.length)return null;let o=Ew(e,n),a=e=>t+(o[e].boundaryOffset??0)*i,s=e=>a(e)-o[e].topMass*i,l=e=>a(e)+o[e].botMass*i,c=`M${r(o[0].t)},${s(0)}`;for(let e=1;e<o.length;e++)c+=` L${r(o[e].t)},${s(e)}`;c+=` L${r(o[o.length-1].t)},${l(o.length-1)}`;for(let e=o.length-2;e>=0;e--)c+=` L${r(o[e].t)},${l(e)}`;return c+" Z"}(r,_[e.id],I,$,n);if(!o)return;let a,s,l=Ew(r,n),c=l.find(e=>e.topMass+e.botMass>0)||l[0],h=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*I/2,p=_[e.id]+h,f=u(e.id,t),g=f,y=.5,x=e.__raw??e;if(m&&m.length>0){let e=se(x,m,T(x));"string"==typeof e.fill?f=e.fill:null!=e.fill&&Aa(e.fill)&&(s=e.fill,f=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:f),"string"==typeof e.stroke&&(g=e.stroke),"number"==typeof e.strokeWidth&&(y=e.strokeWidth),"number"==typeof e.fillOpacity&&(a=e.fillOpacity),"number"==typeof e.opacity&&null==a&&(a=e.opacity)}let b=function(e,t,i,r,n,o){let a=i.nodeData[e];if(!a||0===a.samples.length)return[];let s=i.valueScale,l=i.centerlines[e],c=Ew(a.samples,n),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=r(u.t),p=r(d.t),f=e=>r(Fw(e,n)),g=[],m=(e,t,i,r)=>`M${e},${t} L${i},${t} L${i},${r} L${e},${r} Z`;for(let i of t){if(i.source===e&&null!=i.systemInTime&&Number.isFinite(i.systemInTime)){let e=a.localAttachments.get(i.id),t=o?.get(i.id)??i.startTime;if(e&&"out"===e.kind&&i.systemInTime<t){let r=f(i.systemInTime),o=f(t),a=null!=n&&i.systemInTime<n[0],c=a?r:r-20,u=a?Math.min(o,r+20):r,d=Math.max(h,c);if(o>d){let[t,i]=Ow(e,l,s);g.push({pathD:m(d,t,o,i),x0:c,x1:u,from:0,to:1})}}}if(i.target===e&&null!=i.systemOutTime&&Number.isFinite(i.systemOutTime)){let e=a.localAttachments.get(i.id);if(e&&"in"===e.kind&&i.systemOutTime>i.endTime){let t=f(i.systemOutTime),r=f(i.endTime),n=t+20,o=Math.min(p,n);if(o>r){let[i,a]=Ow(e,l,s);g.push({pathD:m(r,i,o,a),x0:t,x1:n,from:1,to:0})}}}}return g}(e.id,M,S,$,n,E);L.push({id:e.id,pathD:o,fill:f,stroke:g,strokeWidth:y,...null!=a&&{fillOpacity:a},...s&&{hatchFill:s},...b.length>0&&{gradientStubs:b},rawDatum:x,labelX:$("vertical"===d&&e.xExtent?e.xExtent[0]:c.t)-4,labelY:p,labelText:e.label??e.id})});let z=new Map;i.forEach((e,t)=>z.set(e.id,t)),M.forEach(e=>{let t=F.get(e.id);if(!t)return;let i=z.get(e.source)??0,r=u(e.source,i),{pathD:n,bezier:o}=lb(t),a=e.__raw??e,s="function"==typeof c?Number(c(a)):c,l=Number.isFinite(s)?Math.max(0,Math.min(1,s)):.35;C.push({id:e.id,pathD:n,fill:r,opacity:l,rawDatum:a,bezier:o})});let B=function(e,t,i){let r=e.map(e=>({...e})),n=new Map;for(let e of r){let i=t[e.id];if(null==i)continue;let r=n.get(i)??[];r.push(e),n.set(i,r)}let o=e=>{if(e.length<2)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=(e.length-1)/2;e.forEach((e,n)=>{e.labelY=Math.max(8,Math.min(i-8,t+16*(n-r)))})};for(let e of n.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=-1/0;for(let r of e){let e=r.labelX-$S(r.labelText);t.length>0&&e>i+3&&(o(t),t=[],i=-1/0),t.push(r),i=Math.max(i,r.labelX)}o(t)}return function(e,t){let i=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;e<3;e+=1){for(let e=0;e<i.length;e+=1){let t=8;for(let r=0;r<e;r+=1)PS(i[e],i[r])&&(t=Math.max(t,i[r].labelY+16));i[e].labelY=Math.max(i[e].labelY,t)}for(let e=i.length-1;e>=0;e-=1){let r=t-8;for(let t=e+1;t<i.length;t+=1)PS(i[e],i[t])&&(r=Math.min(r,i[t].labelY-16));i[e].labelY=Math.min(i[e].labelY,r)}}}(r,i),r}(L,S.slotByNode,w).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:TS(e.pathD),gradientStubs:e.gradientStubs?.map(CS),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),j="vertical"===d?function(e,t,i){let r=e.map(e=>({...e}));for(let e of r){let i=1.22*$S(e.labelText)+4;e.labelX=i>=t-4?t/2:Math.max(i/2+2,Math.min(t-i/2-2,e.labelX))}let n=[],o=[...r].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of o){let t=n[n.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?n.push([e]):t.push(e)}for(let e of n){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=new Map;for(let i of e){let[e,n]=_S(i),o=t.findIndex(t=>e>t+8);-1===o&&(o=t.length),t[o]=n,r.set(i,o)}let n=e.reduce((e,t)=>e+t.labelY,0)/e.length,o=n<14*t.length+8;for(let t of e){let e=r.get(t)??0;t.labelY=o?Math.min(i-8,12+14*e):Math.max(8,n-14*e)}}return r}(B,o,a):B,W=new Map;if(null!=p)for(let e of i){let t=e.__raw??e,i="function"==typeof p?p(t):Number(t[p]);Number.isFinite(i)&&W.set(e.id,i)}let Y=function(e,t,i,r,n={}){if(!1===r)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===r)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let o=Math.max(1,t*i),a=Math.max(4,Math.min(e.length,Math.floor(o/14e3)));Number.isFinite(n.maxLabels)&&n.maxLabels>=0&&(a=Math.min(a,Math.floor(n.maxLabels)));let s=e.map((e,t)=>{let i=n.priorityById?.get(e.id),r=Math.abs(e.labelY);return{band:e,index:t,score:null!=i&&Number.isFinite(i)?1e6*i+$S(e.labelText):$S(e.labelText)+.01*r}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(s.slice(0,a).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(j,o,a,h,{...W.size>0&&{priorityById:W},...null!=f&&{maxLabels:f}});return{layout:S,layoutConfig:{bands:Y,ribbons:C.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:TS(e.pathD),bezier:LS(e.bezier)}}(e,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:A,xScale:$}}function NS(e,t,i,r="horizontal"){return"vertical"===r?{top:e?38:t?28:16,right:24,bottom:24,left:i?72:24}:{top:e?30:t?24:8,right:80,bottom:i?28:8,left:80}}import{scaleLinear as DS,scaleUtc as FS}from"d3-scale";import{Fragment as ES,jsx as OS,jsxs as zS}from"react/jsx-runtime";var BS="var(--semiotic-grid, #94a3b8)",jS="var(--semiotic-text-secondary, #475569)",WS="var(--semiotic-text-secondary, #94a3b8)";function YS(e,t,i){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,i))}var qS=e=>{let{bands:t=[],ribbons:i=[],showLabels:r=!0,selectionDatum:n="raw"}=e.config,o=e.selection??null,a=[];for(let e of i){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},i=!YS(t,o,n);a.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:i?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!YS({__kind:"band",data:e.rawDatum,id:e.id},o,n);for(let i=0;i<e.gradientStubs.length;i++){let r=e.gradientStubs[i];a.push({type:"bezier",pathD:r.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:r.x0,x1:r.x1,...null!=r.y0&&{y0:r.y0},...null!=r.y1&&{y1:r.y1},from:r.from,to:r.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${i}`}})}}for(let e of t){let t=!!(e.gradientStubs&&e.gradientStubs.length>0),i={__kind:"band",data:e.rawDatum,id:e.id},r=!YS(i,o,n),s=e.fillOpacity??.86,l=e.hatchFill??e.fill;a.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:l,fillOpacity:r?.22:s},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...r&&t?{opacity:.22}:{}},datum:i})}let s=r?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),i=e.labelText.trim().length>0,r=t&&o?.isActive&&YS({__kind:"band",data:e.rawDatum,id:e.id},o,n),a=i?e.labelText:r?e.labelFullText:"";return a.trim()?[{x:e.labelX,y:e.labelY,text:a,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:a,labels:s}},XS=(e,t,i,r,n)=>({data:e,nodeIDAccessor:n.nodeIdAccessor??n.nodeIDAccessor??"name",childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:t,colorByDepth:n.colorByDepth,showLabels:n.showLabels,colorScheme:i,...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}),GS=(e,t,i,r,n)=>{let o=Pi(r.theme).colors.categorical,a=new Map,s=rv(e??null,n.childrenAccessor??"children"),l="function"==typeof t?t:null,c=l?"__hierarchyColor":"string"==typeof t?t:void 0,u=l?s.map(e=>({__hierarchyColor:l(e)})):s,d=t&&c?ni(u,c,i??r.colorScheme??o):void 0;return e=>{if(n.colorByDepth)return ei[Number(e?.depth||0)%ei.length];let r=e?.data||e;return t?ii(l?{__hierarchyColor:l(r)}:r,c,d??void 0):ai(void 0,o,i,void 0,a)}};function VS(e,t,i,r){let n=le(e,r.styleRules,ae(t,r.valueAccessor),e=>e?.data||e),o=i.nodeStyle||r.nodeStyle;return li(o?"function"==typeof o?e=>({...n(e),...o(e)??{}}):e=>({...n(e),...o}):n,wi(r))}var HS={MotifBraidChart:rw,DependencyForestChart:nw,ForceDirectedGraph:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=function(e){if(void 0!==e.edgeStyle)return e.edgeStyle;let{edgeWidth:t,edgeColor:i,edgeOpacity:r}=e,n=e.strokeWidth??1;return void 0!==t||void 0!==i||void 0!==r||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?o=>{let a=o?.data||o,s=n;if("number"==typeof t)s=t;else if("function"==typeof t)s=t(a);else if("string"==typeof t){let e=a?.[t],i="number"==typeof e?e:Number(e);s=Number.isFinite(i)&&i>0?i:n}return{stroke:i??e.stroke??"#999",strokeWidth:s,opacity:r??e.opacity??.6}}:void 0}(n),a=Pi(r.theme).colors.categorical,s=new Map,l=Array.isArray(n.nodes)?n.nodes:[],c="string"==typeof t?t:"__ssrForceColorBy",u=t?ni("function"==typeof t?l.map(e=>({...e,__ssrForceColorBy:t(e)})):l,c,i??r.colorScheme??a):void 0,d=n.nodeStyle??(e=>({fill:t?ii(e?.data||e,t,u):ai(void 0,a,i,void 0,s),..."number"==typeof n.nodeSize&&{r:n.nodeSize}})),h=ce(n.styleRules,t,"number"==typeof n.nodeSize?void 0:n.nodeSize),p=li(h?(e,t)=>({...d(e),...h(e,t)}):d,{stroke:n.nodeStroke??n.stroke,strokeWidth:n.nodeStrokeWidth??n.strokeWidth,opacity:n.opacity});return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:t,colorScheme:i,iterations:n.iterations,forceStrength:n.forceStrength,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize??8,nodeSizeRange:n.nodeSizeRange,nodeStyle:p,edgeStyle:o,...r,showLabels:r.showLabels??n.showLabels??!1,showLegend:(r.showLegend??!!t)&&!!t}}},SankeyDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.nodes)?n.nodes:nv([],Array.isArray(n.edges)?n.edges:[],n.sourceAccessor||"source",n.targetAccessor||"target"),a=Pi(r.theme).colors.categorical,s=new Map,l="string"==typeof t?t:"__ssrSankeyColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrSankeyColorBy:t(e)})):o,u=t?ni(c,l,i??r.colorScheme??a):void 0,d=e=>({fill:t?ii(e?.data||e,t,u):ai(void 0,a,i,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=ce(n.styleRules,t,n.valueAccessor),p=h?(e,t)=>({...d(e),...h(e,t)}):d,f=function({edgeColorBy:e,colorBy:t,colorScale:i,nodeStyleFn:r,edgeOpacity:n,baseStyle:o={}}){return a=>{let s={fillOpacity:n,...o};if("function"==typeof e)s.fill=e(a);else if("source"===e){let e="object"==typeof a.source?a.source:null;t&&e?s.fill=ii(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else if("target"===e){let e="object"==typeof a.target?a.target:null;t&&e?s.fill=ii(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else"gradient"===e&&(s.fill="#999",s.fillOpacity=.7*n);return s}}({edgeColorBy:n.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:p,edgeOpacity:n.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:t,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:li(n.nodeStyle||p,wi(n)),edgeStyle:li(n.edgeStyle||f,wi(n)),colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t}}},ProcessSankey:{frameType:"network",layout:{margin:e=>NS(!!e.title,!!e.showQualityReadout,!Array.isArray(e.axisTicks)||e.axisTicks.length>0,"vertical"===e.orientation?"vertical":"horizontal")},buildProps:(e,t,i,r,n)=>{let o=n.sourceAccessor||"source",a=n.targetAccessor||"target",s=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",c=n.startTimeAccessor||"startTime",u=n.endTimeAccessor||"endTime",d=n.systemInTimeAccessor,h=n.systemOutTimeAccessor,p=n.xExtentAccessor||"xExtent",f=n.groupBy,g=n.edgeIdAccessor||"id",m=(e,t)=>"function"==typeof e?e(t):t[e],y=Array.isArray(n.edges)?n.edges:[],x=Array.isArray(n.nodes)?n.nodes:[],b=x.length>0?x:nv([],y,o,a),v=[AS(n.domain?.[0]),AS(n.domain?.[1])],w=b.map(e=>{let t=String(m(l,e)),i=m(p,e),r=n.nodeLabel?m(n.nodeLabel,e):t,o={id:t,label:null==r?t:String(r),__raw:e},a=f?m(f,e):null;if(null!=a&&""!==String(a)&&(o.group=String(a)),Array.isArray(i)&&2===i.length){let e=AS(i[0]),t=AS(i[1]);Number.isFinite(e)&&Number.isFinite(t)&&(o.xExtent=[e,t])}return o}),S=y.map((e,t)=>{let i=m(g,e),r={id:null!=i?String(i):`${m(o,e)}-${m(a,e)}-${t}`,source:String(m(o,e)),target:String(m(a,e)),value:Number(m(s,e)),startTime:AS(m(c,e)),endTime:AS(m(u,e)),__raw:e};if(d){let t=AS(m(d,e));Number.isFinite(t)&&(r.systemInTime=t)}if(h){let t=AS(m(h,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),[k,A]=r.size??[600,400],M=r.margin,$="vertical"===n.orientation?"vertical":"horizontal",_=!Array.isArray(n.axisTicks)||n.axisTicks.length>0,P={...NS(!!r.title,!!n.showQualityReadout,_,$),...M},I=(r.showLegend??!!t)&&!!t,T=r.legendPosition??"right";if(I){let e="left"===T||"top"===T||"bottom"===T?T:"right",t={...P};"right"===e?P.right=Math.max(P.right,140):"left"===e?P.left=Math.max(P.left,140):"top"===e?P.top=Math.max(P.top,50):P.bottom=Math.max(P.bottom,80),we(P,t,[k,A],e)}let L=P,C=Math.max(1,k-L.left-L.right),R=Math.max(1,A-L.top-L.bottom),N=Qt(i,Pi(r.theme).colors.categorical,Ct),D="function"==typeof t?t:null,F=D?b.map(e=>({_cat:D(e)})):b,E=D?"_cat":"string"==typeof t?t:void 0,O=i??[...N],z=E?ni(F,E,O):null,B=new Map;for(let e of w)B.set(e.id,e.__raw);let j=(e,i)=>{if(t&&B.has(e)){let i=B.get(e);return D?ii({_cat:D(i)},"_cat",z??void 0):ii(i,"string"==typeof t?t:"id",z??void 0)}return N[i%N.length]},W=ge(I&&t?(()=>{let e=new Map;b.forEach((i,r)=>{let n=m(t,i),o=null==n?"":String(n);!o||e.has(o)||e.set(o,{label:o,color:j(String(m(l,i)),r)})});let i=Array.from(e.values());return i.length>0?{legendGroups:[{type:"fill",label:"",items:i,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,r.legend),Y=!1!==n.showLabels&&("auto"!==n.showLabels||"auto"),{layout:X,layoutConfig:G,issues:V,xScale:H}=RS({nodes:w,edges:S,domain:v,plotW:C,plotH:R,orientation:$,ribbonLane:n.ribbonLane||"both",ribbonMinRun:"auto"===n.ribbonMinRun||"number"==typeof n.ribbonMinRun?n.ribbonMinRun:0,edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:j,showLabels:Y,styleRules:n.styleRules,colorBy:t,valueAccessor:s,layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half",maxValueScale:"number"==typeof n.maxValueScale?n.maxValueScale:void 0,lanePlacement:n.lanePlacement||"stack",nodeSizing:n.nodeSizing||"temporal",groupPadding:"number"==typeof n.groupPadding?n.groupPadding:0}});if(V.length>0){let e=V.map(fw).join("; ");throw new Error(`ProcessSankey: data invalid — ${e}`)}let U=X?function(e){let t=e.layout,i=e.nodes,r=e.orientation,n=e.plotW,o=e.plotH,a=e.timelineExtent,s=e.showQualityReadout??!1,l=e.showLaneRails??!1,c=(e.warnings??[]).slice(0,3),u=e.timeFormat,d=e.colorOf,h=e.toTime,p=e.xScale,f=function(e){return q(e)}(e.domain),{centerlines:g,laneLifetime:m,nodeData:y,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:S,layoutQuality:k}=t,A=null,M=null,$=1/0,_=-1/0;for(let e of i){let t=m[e.id];if(!t||null===t.start||null===t.end)continue;let i=p(t.start),r=p(t.end);$=Math.min($,t.start),_=Math.max(_,t.end),(null===A||i<A)&&(A=i),(null===M||r>M)&&(M=r)}let P=e=>Math.max(0,Math.min(a,e)),I=P(A??0),T=Math.max(I,P(M??a)),L=[Math.max(h(e.domain[0]),$),Math.min(h(e.domain[1]),_)],C=Math.max(2,Math.min(8,Math.floor(a/90))),R=FS().domain(L),N=e.axisTicks??(Number.isFinite(L[0])&&Number.isFinite(L[1])?(f?R.ticks(C):DS().domain(L).ticks(C)).map(e=>({date:e})):[]),D=e=>{if(null!=e.label)return e.label;let t=h(e.date),i=f?new Date(t):t;return u?u(i):f?R.tickFormat()(i):String(t)},F=N.map((e,t)=>({tick:e,index:t,coordinate:p(h(e.date))})).filter(({coordinate:e})=>e>=I-.5&&e<=T+.5),E=null!==(w??null)&&null!=S&&null!=k,O=s&&(E||c.length>0)?zS("g",{fill:WS,fontSize:10,textAnchor:"end",children:[E&&zS(ES,{children:[zS("text",{x:n,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(S.pixelLength)," → ",Math.round(k.pixelLength)]}),zS("text",{x:n,y:-3,children:["transit: ",S.transitOcclusion.toFixed(1)," → ",k.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*k.verticalUtilization),"%"]})]}),c.map((e,t)=>zS("text",{x:n,y:E?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},`warn-${t}`))]}):null,z=s&&b?OS("text",{x:n,y:"vertical"===r?-3:2,fontSize:10,fill:WS,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,B=(e,t)=>d?d(e,t):BS;return zS("g","vertical"===r?{children:[O,z,F.map(({index:e,coordinate:t})=>OS("line",{x1:0,y1:t,x2:n,y2:t,stroke:BS,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=p(i.start),l=p(i.end),c=B(e.id,t);return zS("g",{children:[OS("line",{x1:a,y1:s,x2:a,y2:l,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),OS("line",{x1:a-4,y1:s,x2:a+4,y2:s,stroke:c,strokeOpacity:.5}),OS("line",{x1:a-4,y1:l,x2:a+4,y2:l,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),OS("line",{x1:-4,y1:I,x2:-4,y2:T,stroke:BS}),F.map(({tick:e,index:t,coordinate:i})=>{let r=D(e);return zS("g",{transform:`translate(-4,${i})`,children:[OS("line",{x2:-6,stroke:BS}),OS("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:jS,children:r})]},t)})]}:{children:[O,z,F.map(({index:e,coordinate:t})=>OS("line",{x1:t,y1:0,x2:t,y2:o,stroke:BS,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=p(i.start),l=p(i.end),c=B(e.id,t);return zS("g",{children:[OS("line",{x1:s,y1:a,x2:l,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),OS("line",{x1:s,y1:a-4,x2:s,y2:a+4,stroke:c,strokeOpacity:.5}),OS("line",{x1:l,y1:a-4,x2:l,y2:a+4,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),OS("line",{x1:I,y1:o+4,x2:T,y2:o+4,stroke:BS}),F.map(({tick:e,index:t,coordinate:i})=>{let r=D(e);return zS("g",{transform:`translate(${i},${o+4})`,children:[OS("line",{y2:6,stroke:BS}),OS("text",{y:20,textAnchor:"middle",fontSize:11,fill:jS,children:r})]},t)})]})}({layout:X,nodes:w,orientation:$,plotW:C,plotH:R,timelineExtent:"vertical"===$?R:C,domain:n.domain,axisTicks:Array.isArray(n.axisTicks)?n.axisTicks.map(e=>({date:e.date,label:e.label})):void 0,showQualityReadout:!!n.showQualityReadout,showLaneRails:!!n.showLaneRails,timeFormat:"function"==typeof n.timeFormat?e=>n.timeFormat(e):void 0,colorOf:j,toTime:e=>AS(e),xScale:e=>Number(H(e))}):void 0;return{chartType:"force",nodes:b,edges:y,customNetworkLayout:qS,layoutConfig:G,sourceAccessor:o,targetAccessor:a,valueAccessor:s,nodeIDAccessor:l,colorBy:t,colorScheme:i,...U&&{backgroundGraphics:U},...r,showLegend:I,...W&&{legend:W,legendPosition:T},__legendIncludesAutomatic:!0,margin:L}}},ChordDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.styleRules)&&n.styleRules.length>0;if(!(t||o||r.nodeStyle||n.nodeStyle||si(wi(n))))return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t};let a=Array.isArray(n.edges)?n.edges:[],s=Array.isArray(n.nodes)&&n.nodes.length>0?n.nodes:nv([],a,n.sourceAccessor||"source",n.targetAccessor||"target"),l=Pi(r.theme).colors.categorical,c=Qt(i,l),u="string"==typeof t?t:"__ssrChordColorBy",d="function"==typeof t?s.map(e=>({...e,__ssrChordColorBy:t(e)})):s,h=t?ni(d,u,i??r.colorScheme??l):void 0,p=new Map,f=n.nodeIdAccessor||n.nodeIDAccessor||"id",g=(e,i)=>{let r,o=e?.data||e;if(t)r=ii(o,t,h);else{let t=String(e.id??o?.[f]??"");p.has(t)||p.set(t,p.size);let n=e.index??i??p.get(t);r=c[n%c.length]}return{fill:r,stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},m=ce(n.styleRules,t,n.valueAccessor),y=m?(e,t)=>({...g(e,t),...m(e,t)}):g;return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,nodeStyle:li(n.nodeStyle||y,wi(n)),...r,showLegend:(r.showLegend??!!t)&&!!t}}},TreeDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=GS(e,t,i,r,n),a=!1!==n.showLabels;return{chartType:n.layout??"tree",orientation:n.orientation,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...XS(e,t,i,r,n),nodeStyle:VS(e=>({fill:o(e),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),t,r,n)}}},Treemap:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=GS(e,t,i,r,n),a=n.showLabels??r.showLabels,s=n.labelMode,l=void 0!==n.paddingTop?n.paddingTop:r.paddingTop,c=void 0!==l?l:!a||"parent"!==s&&"all"!==s?void 0:18;return{chartType:"treemap",labelMode:s,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...null!=c&&{paddingTop:c},...XS(e,t,i,r,n),nodeStyle:VS(e=>({fill:o(e),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}),t,r,n)}}},CirclePack:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=GS(e,t,i,r,n);return{chartType:"circlepack",nodeLabel:n.showLabels??r.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...XS(e,t,i,r,n),nodeStyle:VS(e=>({fill:o(e),fillOpacity:n.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}),t,r,n)}}},OrbitDiagram:{frameType:"network",buildProps:(e,t,i,r,n)=>{let o=e??n.data,a=n.childrenAccessor||"children",s=n.nodeIdAccessor||n.nodeIDAccessor||"name",l=Pi(r.theme).colors.categorical,c=i??r.colorScheme??l,u=Qt(c,l),d=rv(o,a),h="__ssrOrbitColorBy",p="function"==typeof t?t:null,f=t?ni(p?d.map(e=>({[h]:p(e)})):d,p?h:t,c):void 0,g=le(e=>{let i=e.data||e,r=Number(e.depth??0);return{fill:n.colorByDepth?0===r?u[0]:ei[r%ei.length]:t?p?ii({[h]:p(i)},h,f):ii(i,t,f):u[0],stroke:"#fff",strokeWidth:1,opacity:0===r?1:.85}},n.styleRules,ae(t,"value"),e=>e?.data||e);return{chartType:"orbit",data:o,childrenAccessor:a,nodeIDAccessor:s,colorBy:t,colorScheme:c,colorByDepth:n.colorByDepth??!1,nodeSize:n.nodeRadius??6,nodeLabel:n.showLabels?s:void 0,showLabels:n.showLabels??!1,orbitMode:n.orbitMode??"flat",orbitSize:n.orbitSize??2.95,orbitSpeed:n.speed??.25,orbitRevolution:n.revolution,orbitRevolutionStyle:n.revolutionStyle,orbitEccentricity:n.eccentricity??1,orbitShowRings:n.showRings??!0,orbitAnimated:!1,nodeStyle:li(g,wi(n)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}}}},US={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};function ZS(e,t,i){let[r,n]=i;if(!t)return r;let[o,a]=t,s=a>o?a-o:0,l=Number(e),c=Number.isFinite(l)?l:o,u=s>0?(c-o)/s:0;return r+Math.max(0,Math.min(1,u))*(n-r)}function KS(e){let{valueAccessor:t,valueDomain:i,edgeWidthRange:r,resolveStroke:n,edgeOpacity:o,edgeLinecap:a,styleRules:s}=e,l=ne(t);return le(e=>({stroke:n(e),strokeWidth:ZS(e[t],i,r),strokeLinecap:a,opacity:o,fillOpacity:0}),s,e=>({value:l(e)}))}import{scaleSequential as QS}from"d3-scale";function JS(e,t,i,r){let n,o,a=Array.isArray(e)?e:[];if(t){let e="string"==typeof t?t:"__geoColorBy",r="string"==typeof t?a:a.map(e=>({...e,__geoColorBy:t(e)}));n=ni(r,e,i)}if(r.sizeBy){let e="function"==typeof r.sizeBy?r.sizeBy:e=>e?.[r.sizeBy],t=a.map(e).filter(e=>null!=e&&isFinite(e));t.length>0&&(o=ue(t))}return e=>({fill:t&&n?ii(e,t,n):Kt,fillOpacity:r.fillOpacity,stroke:"#fff",strokeWidth:r.strokeWidth,r:r.sizeBy?oi(e,r.sizeBy,r.sizeRange,o):r.pointRadius??6})}function ek(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}var tk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="string"==typeof i?i:"blues",a=function(e,t,i){if(!Array.isArray(e))return;let r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0,n=1/0,o=-1/0;for(let t of e){let e=r(t);null==e||!isFinite(e)||(e<n&&(n=e),e>o&&(o=e))}let a=[Number.isFinite(n)?n:0,Number.isFinite(o)?o:1],s=QS(jt(i)).domain(a);return{domain:a,colorScale:e=>s(e),valueAccessor:r}}(n.areas,n.valueAccessor,o),s=n.areaStyle??function(e,t){if(e)return i=>{let r=e.valueAccessor(i);return{fill:null!=r&&isFinite(r)?e.colorScale(r):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:t}}}(a,n.areaOpacity??1),l=e=>"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0,c=n.styleRules?le(s,n.styleRules,e=>({value:l(e)}),ek):s,u=!1!==r.showLegend&&a?{gradient:{colorFn:a.colorScale,domain:a.domain,label:"string"==typeof n.valueAccessor?n.valueAccessor:"value"}}:void 0;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:c,valueAccessor:n.valueAccessor,colorScheme:o,graticule:n.graticule,fitPadding:n.fitPadding,...r,...void 0===r.legend&&u?{legend:u}:{}}}},ik={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=n.pointStyle??JS(o,t,i,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),s=n.styleRules?le(a,n.styleRules,ae(t,n.sizeBy)):a;return{points:o,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle||US,pointStyle:s,sizeBy:n.sizeBy,colorBy:t,colorScheme:i,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...r}}},rk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=r.__resolvedMode??n.mode,s="sparkline"===a,l=n.pointStyle??JS(o,t,i,{pointRadius:"number"==typeof n.pointRadius?n.pointRadius:s?1.5:5,fillOpacity:.85,strokeWidth:1}),c=n.nodeIdAccessor||"id",u=n.cartogramLayout||(s?"strip":"radial"),d="strip"===u,h=n.styleRules?le(l,n.styleRules,ae(t)):l;return{points:o,lines:n.lines,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",pointStyle:e=>{let t="function"==typeof h?h(e):h,i="function"==typeof c?c(e):e[c],r=null!=i&&String(i)===String(n.center),o="number"==typeof t.r?t.r:5;return{...t,fillOpacity:r?1:t.fillOpacity??.8,stroke:r?"var(--semiotic-text, #222)":t.stroke??"#fff",strokeWidth:r?1.25:t.strokeWidth??1,r:r?1.35*o:o}},colorBy:t,colorScheme:i,projection:n.projection||"mercator",graticule:n.graticule,fitPadding:n.fitPadding,projectionTransform:{center:n.center,centerAccessor:c,costAccessor:n.costAccessor,strength:n.strength??1,lineMode:n.lineMode||"straight",layout:u},...r,cartogramChrome:{showRings:n.showRings??!0,showNorth:n.showNorth??(!d&&!s),showRingLabels:n.showRingLabels??(!d&&"context"!==a&&!s),costLabel:n.costLabel}}}},nk={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=(Array.isArray(e)?e:null)||n.flows||[],a=n.nodes||[],s=n.nodeIdAccessor||"id",l=n.valueAccessor||"value",c=n.xAccessor||"lon",u=n.yAccessor||"lat",d="function"==typeof c?c:e=>e[c],h="function"==typeof u?u:e=>e[u],p=a.map(e=>({...e,x:d(e),y:h(e)})),f=new Map;for(let e of p)f.set(String(e[s]),e);let g=n.edgeColorBy??t,m="function"==typeof g,y=o.map(e=>{if(!e||null==e.source||null==e.target)return null;let t=f.get(String(e.source)),i=f.get(String(e.target));return t&&i?{...e,coordinates:[{x:t.x,y:t.y},{x:i.x,y:i.y}]}:null}).filter(Boolean),x="__flowMapEdgeColor",b=g?m?ni(y.map(e=>({[x]:g(e)})),x,i||"category10"):ni(y,g,i||"category10"):null,v=y.map(e=>Number(e[l]??0)).filter(e=>Number.isFinite(e)),w=v.length>0?ue(v):void 0,[S,k]=n.edgeWidthRange??[1,8],A=n.edgeOpacity??.6,M=n.edgeLinecap??"round";return{lines:y,points:p,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle||US,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:i,lineStyle:KS({valueAccessor:l,valueDomain:w,edgeWidthRange:[S,k],resolveStroke:e=>g&&b?ii(e,g,b):"#007bff",edgeOpacity:A,edgeLinecap:M,styleRules:n.styleRules}),pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...r}}},ok={FlowCircuitChart:sw,GaltonBoardChart:gy,EventDropChart:my,UnitPileChart:yy,CollisionSwarmChart:xy,PacketFlowChart:Sy,ProcessFlowChart:by,GauntletChart:vy,CrucibleChart:wy,ChainReactionChart:Xu},ak=/*#__PURE__*/Object.assign({Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,i,r,n)=>({chartType:"line",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||t,colorAccessor:t,...r,showAxes:!1,margin:r.margin,showLegend:!1,showGrid:!1,title:void 0})},XYCustomChart:ah,OrdinalCustomChart:sh,ParallelCoordinatesRecipe:ch,CalendarHeatmapRecipe:uh,NetworkCustomChart:lh,ChoroplethMap:tk,ProportionalSymbolMap:ik,FlowMap:nk,DistanceCartogram:rk,GeoCustomChart:{frameType:"geo",buildProps:(e,t,i,r,n)=>({points:n.points||e||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r})},PhysicsCustomChart:ky},
2
+ /*#__PURE__*/Object.assign({},Gu,vd,Gd),
3
+ /*#__PURE__*/Object.assign({},HS,ok));import*as sk from"react";import{jsx as lk}from"react/jsx-runtime";var ck=/*#__PURE__*/new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function uk(e){if(Array.isArray(e))return e.length>0&&e.every(uk);if(!sk.isValidElement(e))return!1;if(e.type===sk.Fragment){let t=sk.Children.toArray(e.props.children);return t.length>0&&t.every(uk)}return"string"==typeof e.type&&ck.has(e.type)}import*as dk from"react-dom/server";import{scaleBand as hk,scaleLinear as pk}from"d3-scale";var fk=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,i){if(t&&"function"==typeof e.pieceStyle){let r=e.pieceStyle(t,i);return r&&!r.fill&&i?{...r,fill:this.getColorFromScheme(e,i)}:r}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&i?{fill:ri(e.barColors,i)??"#007bff"}:{fill:i?this.getColorFromScheme(e,i):"#007bff"}}resolveSummaryStyle(e,t,i){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,i):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){let i=this.colorSchemeMap.get(t);if(i)return i;let r=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||Jt,n=r[this.colorSchemeIndex%r.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,n),n}};function gk(e,t,i){let{scales:r,config:n,getConnector:o,getO:a}=e;if(!o||!r)return[];let s=[],{projection:l}=r,c=new Map;for(let e of t){if("point"!==e.type&&"rect"!==e.type)continue;let t=e.datum;if(!t)continue;let i,r,n=o(t);n&&("point"===e.type?(i=e.x,r=e.y):(i=e.x+e.w/2,r=e.y+("vertical"===l?0:e.h/2)),c.has(n)||c.set(n,[]),c.get(n).push({x:i,y:r,datum:t,category:a(t)}))}let u=new Map(r.o.domain().map((e,t)=>[e,t])),d=n.connectorStyle,h={stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5},p=e=>"function"==typeof d?d(e):d||h,f=(e,t,i)=>{s.push({type:"connector",x1:e.x,y1:e.y,x2:t.x,y2:t.y,style:p(e.datum),datum:e.datum,group:i})};for(let[e,t]of c)if(!(t.length<2)){t.sort((e,t)=>(u.get(e.category)??-1)-(u.get(t.category)??-1));for(let i=0;i<t.length-1;i++)f(t[i],t[i+1],e);"radial"===l&&t.length>=3&&f(t[t.length-1],t[0],e)}return s}function mk(e,t,i,r=!1){let n=new Map;for(let r of e){let e=t(r);if(!Number.isFinite(e))continue;let o=i?i(r):"_default",a=n.get(o);a||(a={total:0,value:0,pieces:[]},n.set(o,a)),a.total+=e,a.pieces.push(r)}let o=0;for(let e of n.values())o+=Math.abs(e.total);for(let e of n.values())e.value=r&&o>0?e.total/o:e.total;return n}function yk(e,t,i,r=!1){let n=new Set;return{steps:e.map(e=>{let o=mk(e.pieceData,t,i,r),a=0;for(let[e,t]of o)n.add(e),a+=t.total;return{col:e,groups:o,stepTotal:a}}),keys:[...n]}}function xk(e,t,i){let r="function"==typeof e?e(i?t.w:t.h):e;return"number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0}function bk(e){let t=e.getSymbol;return t?d(t,e.config.symbolMap):null}function vk(e,t,i,r,n,o,a){t?e.push({type:"symbol",x:r,y:n,size:Math.PI*o*o,symbolType:t(i),style:a,datum:i}):e.push({type:"point",x:r,y:n,r:o,style:a,datum:i})}function wk(e,t){let{scales:i,columns:r,config:n,resolvePieceStyle:o,getR:a}=e,s=[],l=Math.min(t.width,t.height)/2-4,c="donut"===n.chartType?n.innerRadius||60:0,u=-Math.PI/2+(n.startAngle||0)*Math.PI/180,d=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,h=null!=n.sweepAngle&&n.sweepAngle<360,p=Object.values(r),f=p.some(e=>{let t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),g=p.length,m=h&&!f&&g>1&&(n.cornerRadius??0)>0;for(let e=0;e<p.length;e++){let t=p[e],i=t.pieceData[0],r="number"==typeof i?._pctStart?i._pctStart:t.pctStart,h="number"==typeof i?._pct?i._pct:t.pct,f=u+r*d,g=u+(r+h)*d,y=o(t.pieceData[0],t.name),x=0===e,b=e===p.length-1,v={type:"wedge",cx:0,cy:0,innerRadius:c,outerRadius:l,startAngle:f,endAngle:g,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:i?._nonInteractive?null:t.pieceData,accessibleDatum:{...1===t.pieceData.length?t.pieceData[0]:{},category:t.name,value:t.pieceData.reduce((e,t)=>e+a(t),0),percent:100*h,count:t.pieceData.length,...t.pieceData[0]?.__gaugeAccessibleDatum},category:t.name};i?._roundedEnds?v.roundedEnds=i._roundedEnds:m&&(v.roundedEnds={start:x,end:b}),i?._gradientBand&&(v._gradientBand=i._gradientBand),s.push(v)}return s}import{quantileSorted as Sk}from"d3-array";function kk(e,t,i){return{...e[0],...i,category:t,data:e}}function Ak(e){let t=e.length,i=e[0],r=e[t-1];return{n:t,min:i,q1:Sk(e,.25)??i,median:Sk(e,.5)??(i+r)/2,q3:Sk(e,.75)??r,max:r,mean:e.reduce((e,t)=>e+t,0)/t}}function Mk(e,t,i,r,n){let o=new Array(n).fill(0);for(let a of e)a<t||a>i||o[Math.min(Math.floor((a-t)/r),n-1)]++;return o}import{scaleLinear as $k}from"d3-scale";var _k={bar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getStack:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,h="horizontal"===c,p=n.normalize,{steps:f,keys:g}=yk(Object.values(r),o,a,p);for(let{col:e,groups:t}of f){let i=0,r=0;for(let n of g){let o=t.get(n);if(!o)continue;let c=o.value,p=s(o.pieces[0],a?n:e.name),f={...o.pieces[0],__aggregateValue:o.total,__pieceCount:o.pieces.length,category:e.name};if(d){let t=l(c>=0?i+c:r),o=c>=0?l(i)-l(i+c):l(r+c)-l(r);u.push(Un(e.x,t,e.width,Math.abs(o),p,f,n)),c>=0?i+=c:r+=c}else if(h){let t=l(c>=0?i:r+c),o=c>=0?l(i+c)-l(i):l(r)-l(r+c);u.push(Un(t,e.x,Math.abs(o),e.width,p,f,n)),c>=0?i+=c:r+=c}}}let m="vertical"===c;for(let e of u){if("rect"!==e.type)continue;let t=e.datum?.__aggregateValue??0;e.roundedEdge=m?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}if(void 0!==n.roundedTop){let e=new Map;for(let t of u){if("rect"!==t.type)continue;let i=t.datum?.category||"";e.has(i)||e.set(i,[]),e.get(i).push(t)}for(let t of e.values()){if(0===t.length)continue;let e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),i=t.filter(e=>(e.datum?.__aggregateValue??0)<0);if(e.length>0){let t=m?e.reduce((e,t)=>e.y<t.y?e:t):e.reduce((e,t)=>e.x+e.w>t.x+t.w?e:t),i=xk(n.roundedTop,t,m);i>0&&(t.roundedTop=i)}if(i.length>0){let e=m?i.reduce((e,t)=>e.y+e.h>t.y+t.h?e:t):i.reduce((e,t)=>e.x<t.x?e:t),t=xk(n.roundedTop,e,m);t>0&&(e.roundedTop=t)}}}return u},clusterbar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getGroup:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,{steps:h,keys:p}=yk(Object.values(r),o,a),f=p.length||1;for(let{col:e,groups:t}of h){let i=e.width/f,r=.2*i,n=i-r;for(let a=0;a<p.length;a++){let c=t.get(p[a])?.pieces||[];for(let t of c){let c=o(t),h=s(t,p[a]);if(d){let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(Un(o,Math.min(s,d),n,Math.abs(s-d),h,t,p[a]))}else{let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(Un(Math.min(s,d),o,Math.abs(d-s),n,h,t,p[a]))}}}}for(let e of u){if("rect"!==e.type||null==e.datum)continue;let t=o(e.datum),i=xk(n.roundedTop,e,d);i>0&&(e.roundedTop=i),e.roundedEdge=d?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}return u},point:function(e,t){let{scales:i,columns:r,getR:n,multiScales:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d="radial"===l,h=o.length>0,p=bk(e),f=2*Math.PI,g=-Math.PI/2;for(let e of Object.values(r))for(let t of e.pieceData){let i,r,l=t.__rIndex??0,m=t.__rValue??n(t),y=h&&o[l]||s,x=a(t,e.name),b=x.r||5;if(d){let t=g+(e.pctStart+e.pct/2)*f,n=y(m);i=Math.cos(t)*n,r=Math.sin(t)*n}else u?(i=e.middle,r=y(m)):(i=y(m),r=e.middle);vk(c,p,t,i,r,b,x)}return c},swarm:function(e,t){let{scales:i,columns:r,getR:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="vertical"===s,u=bk(e);for(let e of Object.values(r)){let t=e.width/2;for(let i=0;i<e.pieceData.length;i++){let r=e.pieceData[i],s=n(r),d=o(r,e.name),h=d.r||4,p=(7919*i%100/100-.5)*t*.8;vk(l,u,r,c?e.middle+p:a(s),c?a(s):e.middle+p,h,d)}}return l},pie:wk,donut:wk,boxplot:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=!1!==n.showOutliers;for(let t of Object.values(r)){let i=t.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===i.length)continue;let r=Ak(i),{min:n,max:l,q1:h,median:p,q3:f}=r,g=f-h,m=h-1.5*g,y=f+1.5*g,x=i.find(e=>e>=m)??n,b=l;for(let e=i.length-1;e>=0;e--)if(i[e]<=y){b=i[e];break}r.min=x,r.max=b;let v=a(kk(t.pieceData,t.name,r),t.name),w=[];if(d)for(let e of t.pieceData){let i=o(e);if(i<m||i>y){let r=u?t.middle:s(i),n=u?s(i):t.middle;w.push({px:r,py:n,value:i,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:s(x),q1Pos:s(h),medianPos:s(p),q3Pos:s(f),maxPos:s(b),stats:r,style:v,datum:t.pieceData,category:t.name,outliers:w}),d)for(let t of w)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:v.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:v.cursor},datum:t.datum})}return c},violin:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=n.bins||20,h=!1!==n.showIQR;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/d||1,p=Mk(t,r,n,l,d),f=he(p,1),g=e.width/2*.9;if(u){i=`M ${e.middle} ${s(r)}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${e.middle+o} ${n}`}i+=` L ${e.middle} ${s(n)}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${e.middle-o} ${n}`}i+=" Z"}else{i=`M ${s(r)} ${e.middle}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${n} ${e.middle-o}`}i+=` L ${s(n)} ${e.middle}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=p[t]/f*g;i+=` L ${n} ${e.middle+o}`}i+=" Z"}let m,y=Ak(t),x=a(kk(e.pieceData,e.name,y),e.name);h&&t.length>=4&&(m={q1Pos:s(y.q1),medianPos:s(y.median),q3Pos:s(y.q3),centerPos:e.middle,isVertical:u});let b=u?{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))}:{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:y,style:x,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s}=i,l=[],c=n.bins||25,u=n.normalize,d=s.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;let[i,r]=ue(t),n=null!=h&&isFinite(h)?h:i,d=null!=p&&isFinite(p)?p:r,f=(d-n)/c||1,g=Mk(t,n,d,f,c),m=t.length,y=he(g,1);for(let t=0;t<c;t++){if(0===g[t])continue;let i=(u?g[t]/m:g[t]/y)*e.width*.9,r=s(n+t*f),o=s(n+(t+1)*f),c=Math.min(r,o),d=Math.abs(o-r),h=e.x+e.width-i,p={...e.pieceData[0],bin:t,count:g[t],range:[n+t*f,n+(t+1)*f],category:e.name,data:e.pieceData},x=a(p,e.name);l.push(Un(c,h,d,i,x,p,e.name))}}return l},ridgeline:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u=n.bins||20,d="horizontal"===l,h=n.amplitude||1.5;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/u||1,p=Mk(t,r,n,l,u),f=he(p,1),g=Ak(t),m=a(kk(e.pieceData,e.name,g),e.name),y=e.width*h;if(d){let t=e.x+e.width;i=`M ${s(r)} ${t}`;for(let e=0;e<u;e++)i+=` L ${s(r+(e+.5)*l)} ${t-p[e]/f*y}`;i+=` L ${s(n)} ${t} Z`}else{let t=e.x;i=`M ${t} ${s(r)}`;for(let e=0;e<u;e++){let n=s(r+(e+.5)*l);i+=` L ${t+p[e]/f*y} ${n}`}i+=` L ${t} ${s(n)} Z`}let x=d?{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width}:{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:x,stats:g,style:{...m,fillOpacity:m.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){let{scales:i,columns:r,getRawRange:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="horizontal"===s;for(let e of Object.values(r))for(let t of e.pieceData){let i=n(t);if(!i)continue;let[r,s]=i,u=o(t,e.name);if(c){let i=a(Math.min(r,s)),n=a(Math.max(r,s));l.push(Un(i,e.x,n-i,e.width,u,t,e.name))}else{let i=a(Math.max(r,s)),n=a(Math.min(r,s));l.push(Un(e.x,i,e.width,n-i,u,t,e.name))}}return l},funnel:function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o}=e,a=[],s=t.width/2,l=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>i[e]).filter(Boolean);if(0===c.length)return a;let{steps:u,keys:d}=yk(c,r,n),h=d.length>1&&"_default"!==d[0],p=0;if(!h)for(let{stepTotal:e}of u)e>p&&(p=e);if(h)for(let e of u){let t=0,i=0;for(let r=0;r<d.length;r++){let n=e.groups.get(d[r]);n&&(r%2==0?t+=n.total:i+=n.total)}let r=Math.max(t,i);r>p&&(p=r)}if(0===p)return a;let f=u[0].stepTotal,g=h?.95*s:.9*t.width,m=$k().domain([0,p]).range([0,g]),y=e.config.connectorOpacity??.3,x=new Map;for(let t=0;t<u.length;t++){let i=u[t],r=i.col,n=0===t,c=r.x,p=r.width,g=.55*p,b=c+(p-g)/2,v=new Map;if(h){let e=0;for(let t of d){let r=i.groups.get(t);r&&(e+=m(r.total))}let t=s,c=s;for(let h=0;h<d.length;h++){let p=d[h],f=i.groups.get(p);if(!f)continue;let y=m(f.total),x=h%2==0,w=x?t:c-y;x?t+=y:c-=y;let S=o(f.pieces[0],p),k=u[0].groups.get(p)?.total??0,A=k>0?f.total/k*100:0,M={...f.pieces[0],__funnelValue:f.total,__funnelPercent:A,__funnelStep:r.name,__funnelIsFirstStep:n,__aggregateValue:f.total,__pieceCount:f.pieces.length,category:p};l&&(0===h&&(M.__funnelStepLabel=r.name,M.__funnelStepLabelX=s,M.__funnelStepLabelY=b,M.__funnelRowWidth=e),M.__funnelValueLabelX=w+y/2,M.__funnelValueLabelY=b,M.__funnelBarW=y),a.push(Un(w,b,y,g,S,M,p)),v.set(p,{x:w,y:b,w:y,h:g})}}else{let e=i.stepTotal,t=m(e),c=s-t/2,u=d[0],h="_default"!==u,p=i.groups.get(u)?.pieces[0]??r.pieceData[0],y=h?u:r.name,x=o(p,y),w=f>0?e/f*100:0,S={...p,__funnelValue:e,__funnelPercent:w,__funnelStep:r.name,__funnelIsFirstStep:n,category:h?u:r.name};l&&(S.__funnelStepLabel=r.name,S.__funnelStepLabelX=s,S.__funnelStepLabelY=b,S.__funnelRowWidth=t,S.__funnelValueLabelX=s,S.__funnelValueLabelY=b,S.__funnelBarW=t),a.push(Un(c,b,t,g,x,S,y)),v.set(u,{x:c,y:b,w:t,h:g})}if(t>0&&x.size>0){let t=h?d:[d[0]];for(let n of t){let t=x.get(n),s=v.get(n);if(!t||!s)continue;let l=(()=>{let e=i.groups.get(n),t="_default"===n?r.name:n;return o(e?e.pieces[0]:r.pieceData[0],t)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[s.x+s.w,s.y],[s.x,s.y]],style:{fill:l.fill||e.config.themeSemantic?.secondary||"#999",opacity:y,cursor:l.cursor},datum:i.groups.get(n)?.pieces[0]??r.pieceData[0],category:"_default"===n?r.name:n};a.push(c)}}x=v}return a},"bar-funnel":function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o,scales:a}=e,s=[],l=a.o.domain().map(e=>i[e]).filter(Boolean);if(0===l.length)return s;let{steps:c,keys:u}=yk(l,r,n),d=u.length>1&&"_default"!==u[0],h=a.r,p=d?u.length:1,f=d?.15:0;for(let e=0;e<c.length;e++){let t=c[e],i=t.col,r=0===e,n=e>0?c[e-1]:null,a=i.width/p,l=a*f,g=a-l;for(let e=0;e<u.length;e++){let p=u[e],f=t.groups.get(p);if(!f)continue;let m=f.total,y=c[0].groups.get(p)?.total??0,x=y>0?m/y*100:0,b=n?.groups.get(p)?.total??m,v=r?0:Math.max(0,b-m),w=i.x+e*a+l/2,S=h(m),k=h(0),A=k-S,M=o(f.pieces[0],d?p:i.name),$={...f.pieces[0],__barFunnelValue:m,__barFunnelPercent:x,__barFunnelIsFirstStep:r,__barFunnelIsDropoff:!1,__barFunnelStep:i.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===p?void 0:p,category:d?p:i.name,__barFunnelLabelX:w+g/2,__barFunnelLabelY:h(m+v)};if(s.push(Un(w,Math.min(S,k),g,Math.abs(A),M,$,d?p:i.name)),v>0){let e=h(m+v),t=S-e,r={...M},n={...f.pieces[0],__barFunnelValue:v,__barFunnelPercent:y>0?v/y*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:i.name,__barFunnelCategory:"_default"===p?void 0:p,category:d?p:i.name};s.push(Un(w,e,g,t,r,n,d?p:i.name))}}}return s},swimlane:function(e,t){let{scales:i,columns:r,getR:n,getStack:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="horizontal"===l,d=e.config.gradientFill,h=u?"left":"bottom",p=new Map,f=t=>{let i=p.get(t);if(void 0!==i)return i;let r="function"==typeof e.config.roundedTop?e.config.roundedTop(t.width):e.config.roundedTop,n="number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0;return p.set(t,n),n},g=e.config.trackFill;if(g){let e="string"==typeof g?g:g.color,t="string"==typeof g?1:g.opacity??1,[i,n]=s.range(),o=Math.min(i,n),a=Math.abs(n-i);for(let i of Object.values(r)){let r={fill:e,opacity:t},n=u?Un(o,i.x,a,i.width,r,null,"__track__"):Un(i.x,o,i.width,a,r,null,"__track__"),s=f(i);s>0&&(n.cornerRadii={tl:s,tr:s,br:s,bl:s}),c.push(n)}}for(let e of Object.values(r)){let t=0,i=c.length,r=f(e);for(let i of e.pieceData){let r=Math.abs(n(i));if(0===r)continue;let l,p=o?o(i):e.name,f=a(i,p);if(u){let n=s(t),o=s(t+r);l=Un(n,e.x,o-n,e.width,f,i,p)}else{let n=s(t+r),o=s(t);l=Un(e.x,n,e.width,o-n,f,i,p)}d&&(l.fillGradient=d,l.roundedEdge=h),c.push(l),t+=r}if(r>0&&c.length>i){let e=c.slice(i),t=e[0],n=e[e.length-1];1===e.length?t.cornerRadii={tl:r,tr:r,br:r,bl:r}:u?(t.cornerRadii={tl:r,bl:r},n.cornerRadii={tr:r,br:r}):(t.cornerRadii={bl:r,br:r},n.cornerRadii={tl:r,tr:r})}}return c}},Pk=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ik=["scene-style","data-paint","accessibility","evidence"],Tk=(e,t)=>({retainedData:e,invalidations:t}),Lk=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ck=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Rk=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Nk=["scene-geometry","data-paint","accessibility","evidence"],Dk=["scene-style","data-paint","accessibility","evidence"],Fk=[],Ek={chartType:/*#__PURE__*/Tk("rebuild",Lk),runtimeMode:/*#__PURE__*/Tk("rebuild",Lk),categoryAccessor:/*#__PURE__*/Tk("rebuild",Lk),valueAccessor:/*#__PURE__*/Tk("rebuild",Lk),oAccessor:/*#__PURE__*/Tk("rebuild",Lk),rAccessor:/*#__PURE__*/Tk("rebuild",Lk),stackBy:/*#__PURE__*/Tk("rebuild",Lk),groupBy:/*#__PURE__*/Tk("rebuild",Lk),timeAccessor:/*#__PURE__*/Tk("rebuild",Lk),accessorRevision:/*#__PURE__*/Tk("rebuild",Lk),colorAccessor:/*#__PURE__*/Tk("rebuild",Dk),symbolAccessor:/*#__PURE__*/Tk("rebuild",Nk),connectorAccessor:/*#__PURE__*/Tk("rebuild",Nk),dataIdAccessor:/*#__PURE__*/Tk("rebuild",Nk),projection:/*#__PURE__*/Tk("preserve",Ck),extentPadding:/*#__PURE__*/Tk("preserve",Ck),axisExtent:/*#__PURE__*/Tk("preserve",Ck),rExtent:/*#__PURE__*/Tk("preserve",Ck),oExtent:/*#__PURE__*/Tk("preserve",Ck),multiAxis:/*#__PURE__*/Tk("preserve",Ck),normalize:/*#__PURE__*/Tk("preserve",Ck),bins:/*#__PURE__*/Tk("preserve",Ck),oSort:/*#__PURE__*/Tk("preserve",Rk),barPadding:/*#__PURE__*/Tk("preserve",Rk),roundedTop:/*#__PURE__*/Tk("preserve",Rk),baselinePadding:/*#__PURE__*/Tk("preserve",Rk),innerRadius:/*#__PURE__*/Tk("preserve",Rk),cornerRadius:/*#__PURE__*/Tk("preserve",Rk),startAngle:/*#__PURE__*/Tk("preserve",Rk),sweepAngle:/*#__PURE__*/Tk("preserve",Rk),trackFill:/*#__PURE__*/Tk("preserve",Rk),showOutliers:/*#__PURE__*/Tk("preserve",Rk),showIQR:/*#__PURE__*/Tk("preserve",Rk),amplitude:/*#__PURE__*/Tk("preserve",Rk),connectorOpacity:/*#__PURE__*/Tk("preserve",Rk),showLabels:/*#__PURE__*/Tk("preserve",Rk),dynamicColumnWidth:/*#__PURE__*/Tk("rebuild",Rk),customLayout:/*#__PURE__*/Tk("preserve",Rk),layoutConfig:/*#__PURE__*/Tk("preserve",Rk),layoutMargin:/*#__PURE__*/Tk("preserve",Rk),symbolMap:/*#__PURE__*/Tk("preserve",Nk),pieceStyle:/*#__PURE__*/Tk("preserve",Dk),summaryStyle:/*#__PURE__*/Tk("preserve",Dk),connectorStyle:/*#__PURE__*/Tk("preserve",Dk),gradientFill:/*#__PURE__*/Tk("preserve",Dk),colorScheme:/*#__PURE__*/Tk("preserve",Dk),themeCategorical:/*#__PURE__*/Tk("preserve",Dk),themeSemantic:/*#__PURE__*/Tk("preserve",Dk),themeSequential:/*#__PURE__*/Tk("preserve",Dk),themeDiverging:/*#__PURE__*/Tk("preserve",Dk),barColors:/*#__PURE__*/Tk("preserve",Dk),decay:/*#__PURE__*/Tk("preserve",Dk),pulse:/*#__PURE__*/Tk("preserve",Dk),staleness:/*#__PURE__*/Tk("preserve",Dk),layoutSelection:/*#__PURE__*/Tk("preserve",Dk),windowSize:/*#__PURE__*/Tk("preserve",Fk),windowMode:/*#__PURE__*/Tk("preserve",Fk),clock:/*#__PURE__*/Tk("preserve",Fk),transition:/*#__PURE__*/Tk("preserve",Fk),introAnimation:/*#__PURE__*/Tk("preserve",Fk),onLayoutError:/*#__PURE__*/Tk("preserve",Fk)},Ok=/*#__PURE__*/Tk("preserve",Rk),zk=class{constructor(){this.tracker=new go}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Pk)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Ik):this.recordNoop("restyle")}recordConfig(e){let t=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(Ek,r)?Ek[r]:Ok;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as Bk}from"d3-quadtree";var jk=class extends uo{constructor(e){super(),this.rExtent=new xn,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new zk,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new fk,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new yn(e.windowSize),this.getO=U(e.categoryAccessor||e.oAccessor,"category");let t="streaming"===e.runtimeMode,i=e.valueAccessor||e.rAccessor;Array.isArray(i)?(this.rAccessors=i.map(e=>V(e,"value")),this.getR=this.rAccessors[0],this.rExtents=i.map(()=>new xn)):(t&&e.timeAccessor,this.getR=V(i,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=U(e.stackBy),this.getGroup=U(e.groupBy),this.getColor=U(e.colorAccessor),this.getSymbol=U(e.symbolAccessor),this.getConnector=U(e.connectorAccessor),this.getDataId=U(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new yn(e.windowSize))}syncPulseTimestampBuffer(){var e,t,i,r;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,i=this.timestampBuffer,r=this.currentTime(),e?null!=i&&i.capacity===t.capacity&&i.size===t.size?i:ao(t,r):null)}currentTime(){return this.config.clock?.()??o()}ingest(e){let t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear();let i=e.totalSize||e.inserts.length;oo(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)so(this.buffer,i,this.timestampBuffer,t),this.categories.add(this.getO(i)),this.pushValueExtent(i)}else{this._hasStreamingData=!0;for(let i of e.inserts){let e=so(this.buffer,i,this.timestampBuffer,t);this.categories.add(this.getO(i)),this.pushValueExtent(i),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){let t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;let i="function"==typeof t?t(e):e[t];return Array.isArray(i)&&i.length>=2?[+i[0],+i[1]]:null}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.multiScales,o=this.columns;if(0===i.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&("timeline"===t.chartType?(this.rExtent.clear(),i.forEach(e=>this.pushValueExtent(e))):this.rExtent.recalculate(i,this.getR));let a,s,l=this.getBufferArray(),c=t.projection||"vertical",u=t.oExtent||this.resolveCategories(l),d=this.computeValueDomain(l,u),h="vertical"===c,p="horizontal"===c,f="radial"===c,g=null!=t.barPadding?t.barPadding/(h?e.width:e.height):.1,m=Math.min(.9,Math.max(0,g));if(f){a=hk().domain(u).range([0,1]).padding(0);let i=Math.min(e.width,e.height)/2,r=t.innerRadius||0;s=pk().domain(d).range([r,i])}else p?(a=hk().domain(u).range([0,e.height]).padding(m),s=pk().domain(d).range([0,e.width])):(a=hk().domain(u).range([0,e.width]).padding(m),s=pk().domain(d).range([e.height,0]));this.scales={o:a,r:s,projection:c},this.rAccessors.length>1&&t.multiAxis?this.multiScales=this.rAccessors.map((r,n)=>{let o=this.rExtents[n];o.dirty&&o.recalculate(i,r);let[a,s]=o.extent;a===1/0&&(a=0,s=1);let l=t.extentPadding??.05,c=s-a,u=c>0?c*l:1;return a-=u,s+=u,a>0&&(a=0),p?pk().domain([a,s]).range([0,e.width]):pk().domain([a,s]).range([e.height,0])}):this.multiScales=[];let y=l;this.rAccessors.length>1&&(y=l.flatMap(e=>this.rAccessors.map((t,i)=>({...e,__rIndex:i,__rValue:t(e),__rName:this.resolveRAccessorName(i)})))),this.columns=this.buildColumns(y,u,a,c,e),this._customLayoutFailedThisBuild=!1;let x=this.buildSceneNodes(y,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.multiScales=n,this.columns=o):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=x,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,l),this.config.pulse&&this.applyPulse(this.scene,l),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){let t=this.config.valueAccessor||this.config.rAccessor,i=Array.isArray(t)?t[e]:t;return"string"==typeof i?i:`value${e}`}resolveCategories(e){let t=this.config.oSort,i="streaming"===this.config.runtimeMode||this._hasStreamingData,r="auto"===t?void 0:t,n=null;if(i){n=new Set;for(let t of e)n.add(this.getO(t))}let o=n?Array.from(this.categories).filter(e=>n.has(e)):Array.from(this.categories);if(i&&void 0===r){let e=Math.max(50,3*n.size);if(this.categories.size>e){let t=this.categories.size-e;for(let e of this.categories){if(t<=0)break;n.has(e)||(this.categories.delete(e),t--)}}return o}if(!1===r)return o;if("function"==typeof r)return o.sort(r);let a=new Map;for(let t of e){let e=this.getO(t);a.set(e,(a.get(e)||0)+Math.abs(this.getR(t)))}return"asc"===r?o.sort((e,t)=>(a.get(e)||0)-(a.get(t)||0)):o.sort((e,t)=>(a.get(t)||0)-(a.get(e)||0))}computeValueDomain(e,t){return function(e){let{data:t,chartType:i,projection:r,normalize:n,rExtent:o,extentPadding:a=.05,baselinePadding:s,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=e,p=a;if("radial"===r&&("pie"===i||"donut"===i))return[0,1];let f=0,g=0;if("bar"===i||"bar-funnel"===i){let e=new Map;for(let i of t){let t=c(i);e.has(t)||e.set(t,[]),e.get(t).push(i)}for(let t of e.values()){let e=mk(t,u,d,"bar"===i&&n),r=0,o=0;for(let{value:t}of e.values())"bar-funnel"===i?(r=Math.max(r,t),o=Math.min(o,t)):t>=0?r+=t:o+=t;g=Math.max(g,r),f=Math.min(f,o)}}else if("swimlane"===i){let e=new Map;for(let i of t){let t=c(i),r=Math.abs(u(i));e.set(t,(e.get(t)||0)+r)}for(let t of e.values())t>g&&(g=t)}else if("clusterbar"===i)for(let e of t){let t=u(e);Number.isFinite(t)&&(t>g&&(g=t),t<f&&(f=t))}else{let e=h[0],t=h[1];e!==1/0&&(f=e),t!==-1/0&&(g=t)}o&&(null!=o[0]&&(f=o[0]),null!=o[1]&&(g=o[1]));let m="bar"===i||"clusterbar"===i||"bar-funnel"===i||"swimlane"===i;if(m&&(null!=o?.[0]||null!=o?.[1]||(f>0&&(f=0),g<0&&(g=0))),"bar-funnel"!==i&&"exact"!==l){let e=g-f,t=e>0?e*p:1,r=m&&!s&&0===f,n=m&&!s&&0===g||"swimlane"===i;null==o?.[0]&&!r&&(f-=t),null==o?.[1]&&!n&&(g+=t)}return[f,g]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,i,r,n){return function(e){let{data:t,oExtent:i,oScale:r,projection:n,layout:o,dynamicColumnWidth:a,getO:s,getR:l}=e,c=Object.create(null),u=new Map;for(let e of t){let t=s(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===n)for(let e of t)d+=Math.abs(l(e));let h=null;if(a&&"radial"!==n){h=new Map;let e=0;for(let t of i){let i,r=u.get(t)||[];i="string"==typeof a?r.reduce((e,t)=>{let i=Number(t[a]);return e+(Number.isFinite(i)?i:0)},0):a(r);let n=Number.isFinite(i)?Math.max(0,i):0;h.set(t,n),e=Math.max(e,n)}let t="horizontal"===n?o.height:o.width,s=r.padding()*r.step()*Math.max(0,i.length-1),l=Math.max(0,t-s);if(e>0){let t=0;for(let i of h.values())t+=i/e;for(let[i,r]of h)h.set(i,r/e/t*l)}}let p=0,f=0;for(let e of i){let t,i,n=u.get(e)||[],o=n.reduce((e,t)=>e+Math.abs(l(t)),0),a=d>0?o/d:0;h?(t=f,i=h.get(e)??r.bandwidth(),f+=i+r.padding()*r.step()):(t=r(e)??0,i=r.bandwidth()),c[e]={name:e,x:t,y:0,width:i,middle:t+i/2,padding:r.padding()*r.step(),pieceData:n,pct:a,pctStart:p},p+=a}return c}({data:e,oExtent:t,oScale:i,projection:r,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){let i=this.buildLayoutContext(e,t),r=Dn({family:"ordinal",logLabel:"ordinal customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:this.config.onLayoutError,run:()=>this.config.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let n=r.result;this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;let o=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of o)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(o,this.config.layoutSelection??null)}return Cn({label:"ordinal customLayout",nodes:o,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),o}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;let i=this.getSceneContext(),r=_k[this.config.chartType],n=r?r(i,t):[];return this.getConnector&&this.scales&&(n=[...gk(i,n),...n]),n}buildLayoutContext(e,t){let i=this.config,r=i.layoutMargin??{top:0,right:0,bottom:0,left:0},n=ig(i.colorScheme,i.themeCategorical,Jt),o=this.scales,a="radial"===o.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height};return{data:e,scales:{o:o.o,r:o.r,projection:o.projection},dimensions:{width:t.width,height:t.height,margin:r,plot:a},theme:{semantic:i.themeSemantic??{},categorical:[...n]},resolveColor:rg(n,i.colorScheme),config:i.layoutConfig??{},selection:i.layoutSelection??null}}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:vn(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;let t=wn(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;let t=function(e,t){let i="function"==typeof t,r=i?null:t||"category",n=new Map;for(let o=0;o<e.length;o++){let a=e[o],s=i?t(a):a[r],l=n.get(s);l?l.push(o):n.set(s,[o])}return n}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){let e=function(e){let t=0,i=0;for(let r of e)"point"===r.type&&!1!==r.interactive&&(t++,r.r>i&&(i=r.r));if(t<=500)return{quadtree:null,maxRadius:i};let r=new Array(t),n=0;for(let t of e)"point"===t.type&&!1!==t.interactive&&(r[n++]=t);return{maxRadius:i,quadtree:Bk().x(e=>e.x).y(e=>e.y).addAll(r)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;let i=t.length;if(i<=1)return;let r=this.getDatumIndexMap(t);for(let t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type||!t.datum)continue;let e=r.get(t.datum);if(null==e)continue;let n=this.computeDecayOpacity(e,i),o=t.style?.opacity??1;t.style={...t.style,opacity:o*n}}}applyPulse(e,t,i=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,n,o){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1;for(let c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){let t=c.category;if(!t)continue;let r=0;for(let a of n(t)??[]){let t=i.get(a);null!=t&&(r=Math.max(r,Sn(e,t,o)))}l=kn(c,r,a)||l;continue}if(null==c.datum)continue;let t=r.get(c.datum);if(null==t)continue;let u=i.get(t);l=kn(c,null==u?0:Sn(e,u,o),a,s)||l}return l}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),i)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&An(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();let e,t=new Map,i=this.scales?.r(0)??0,r="horizontal"!==this.scales?.projection;for(let n=0;n<this.scene.length;n++){let o=this.scene[n],a=this.getNodeKey(o,t);a&&("rect"===o.type?r?this.prevPositionMap.set(a,{x:o.x,y:i,w:o.w,h:0,opacity:o.style.opacity??1}):this.prevPositionMap.set(a,{x:i,y:o.y,w:0,h:o.h,opacity:o.style.opacity??1}):"point"===o.type?this.prevPositionMap.set(a,{x:o.x,y:o.y,r:0,opacity:0}):"wedge"===o.type&&(void 0===e&&(e=o.startAngle),this.prevPositionMap.set(a,{x:o.cx,y:o.cy,startAngle:e,endAngle:e,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){let i=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,r=t.get(i)||0;return t.set(i,r+1),`${i}:${r}`}if("rect"===e.type){let i=e.datum?null!=e.datum.category&&""!==e.datum.category?String(e.datum.category):String(this.getO(e.datum)??""):"",r=`r:${e.group||""}:${i}`,n=t.get(r)||0;return t.set(r,n+1),0===n?r:`${r}:${n}`}return"wedge"===e.type?`w:${e.category??""}`:null}snapshotPositions(){this.prevPositionMap.clear();let e=new Map;for(let i=0;i<this.scene.length;i++){let r=this.scene[i],n=this.getNodeKey(r,e);n&&("point"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,r:r.r,...t(r.style)}):"rect"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,w:r.w,h:r.h,...t(r.style)}):"wedge"===r.type&&this.prevPositionMap.set(n,{x:r.cx,y:r.cy,startAngle:r.startAngle,endAngle:r.endAngle,innerRadius:r.innerRadius,outerRadius:r.outerRadius,...t(r.style)}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;let e=this.config.transition.duration??300;if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let i=!1,r=new Set,n=new Map;for(let e=0;e<this.scene.length;e++){let t=this.scene[e],o=this.getNodeKey(t,n);if(!o)continue;t._transitionKey=o;let a=this.prevPositionMap.get(o);if("point"===t.type)a?(r.add(o),t._targetOpacity=t.style.opacity??1,(a.x!==t.x||a.y!==t.y||void 0!==a.r&&a.r!==t.r)&&(t._targetX=t.x,t._targetY=t.y,t._targetR=t.r,t.x=a.x,t.y=a.y,void 0!==a.r&&(t.r=a.r),i=!0)):(t._targetOpacity=t.style.opacity??1,t._targetR=t.r,t.r=0,t.style={...t.style,opacity:0},i=!0);else if("rect"===t.type)a?(r.add(o),t._targetOpacity=t.style.opacity??1,(a.x!==t.x||a.y!==t.y||a.w!==t.w||a.h!==t.h)&&(t._targetX=t.x,t._targetY=t.y,t._targetW=t.w,t._targetH=t.h,t.x=a.x,t.y=a.y,t.w=a.w??t.w,t.h=a.h??t.h,i=!0)):(t._targetOpacity=t.style.opacity??1,t.style={...t.style,opacity:0},i=!0);else if("wedge"===t.type)if(a)r.add(o),t._targetOpacity=t.style.opacity??1,(a.startAngle!==t.startAngle||a.endAngle!==t.endAngle)&&(t._targetStartAngle=t.startAngle,t._targetEndAngle=t.endAngle,t.startAngle=a.startAngle,t.endAngle=a.endAngle,i=!0);else{t._targetOpacity=t.style.opacity??1,t._targetStartAngle=t.startAngle,t._targetEndAngle=t.endAngle;let e=t.startAngle;t.startAngle=e,t.endAngle=e,t.style={...t.style,opacity:0},this.prevPositionMap.set(o,{x:t.cx,y:t.cy,startAngle:e,endAngle:e,innerRadius:t.innerRadius,outerRadius:t.outerRadius,opacity:0}),i=!0}}this.exitNodes=[];for(let[e,n]of this.prevPositionMap){if(r.has(e))continue;let o={style:t(n),datum:null,_targetOpacity:0,_transitionKey:e};if(e.startsWith("p:"))this.exitNodes.push({...o,type:"point",x:n.x,y:n.y,r:n.r??3});else if(e.startsWith("r:"))this.exitNodes.push({...o,type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{...o.style,fill:"#999"}});else if(e.startsWith("w:")){let t=((n.startAngle??0)+(n.endAngle??0))/2,i={...o,type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t};this.exitNodes.push(i)}i=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;let t=r(e,this.activeTransition),o="linear"===this.config.transition?.easing?"linear":"ease-out-cubic",a=i(t,o);for(let e of this.scene){let t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),r=i?i.opacity??1:0;e.style.opacity=n(r,e._targetOpacity,a)}let i=this.prevPositionMap.get(t);void 0!==e._targetX&&i&&(e.x=n(i.x,e._targetX,a),e.y=n(i.y,e._targetY,a)),void 0!==e._targetR&&void 0!==i?.r&&(e.r=n(i.r,e._targetR,a))}else if("rect"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),r=i?i.opacity??1:0;e.style.opacity=n(r,e._targetOpacity,a)}if(void 0===e._targetX)continue;let i=this.prevPositionMap.get(t);if(!i)continue;e.x=n(i.x,e._targetX,a),e.y=n(i.y,e._targetY,a),void 0!==i.w&&(e.w=n(i.w,e._targetW,a),e.h=n(i.h,e._targetH,a))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){let i=this.prevPositionMap.get(t),r=i?i.opacity??1:0;e.style={...e.style,opacity:n(r,e._targetOpacity,a)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){let i=this.prevPositionMap.get(t);i&&void 0!==i.startAngle&&(e.startAngle=n(i.startAngle,e._targetStartAngle,a),e.endAngle=n(i.endAngle,e._targetEndAngle,a))}}}if(t>=1){for(let e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}"point"===t.type?void 0!==t._targetX?(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0):void 0!==t._targetR&&(t.r=t._targetR,t._targetR=void 0):"rect"===t.type?void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0):"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw new Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();let t=bn(e),i=this.getDataId,r=e=>t.has(i(e));lo(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getDataId)throw new Error("update() requires dataIdAccessor to be configured");let i=bn(e),r=this.getDataId,n=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),n.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!G(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!G(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!G(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let r=!1;if("categoryAccessor"in e||"oAccessor"in e){let e=this.config.categoryAccessor||this.config.oAccessor,i=t.categoryAccessor||t.oAccessor;G(e,i)||(this.getO=U(this.config.categoryAccessor||this.config.oAccessor,"category"),r=!0)}let n=!1;if("valueAccessor"in e||"rAccessor"in e){let e=this.config.valueAccessor||this.config.rAccessor,i=t.valueAccessor||t.rAccessor,r=Array.isArray(e)?e:[e],o=Array.isArray(i)?i:[i];if(n=r.length!==o.length||r.some((e,t)=>!G(e,o[t])),n){let e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>V(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new xn)):(this.getR=V(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!G(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?U(this.config.stackBy):void 0),"groupBy"in e&&!G(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?U(this.config.groupBy):void 0),"colorAccessor"in e&&!G(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?U(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!G(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?U(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!G(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?U(this.config.connectorAccessor):void 0);let o="accessorRevision"in e&&e.accessorRevision!==t.accessorRevision;(r||n||o)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(i)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function Wk(e,t,i,r){return"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:i,fn:e}:"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:r,fn:t}:{key:void 0,fn:null}}function Yk(e,t,i){return r=>{if(!r||!i||!e.fn&&!t.fn)return r;let n=!1,o=r.map(i=>{let r=e.fn&&e.key&&!(e.key in i),o=t.fn&&t.key&&!(t.key in i);if(!r&&!o)return i;n=!0;let a={...i};return r&&(a[e.key]=e.fn(i)),o&&(a[t.key]=t.fn(i)),a});return n?o:r}}import*as qk from"react";import*as Xk from"react";import{arc as Gk}from"d3-shape";var Vk=(e,t)=>({x:e*Math.cos(t),y:e*Math.sin(t)});function Hk(e){let{innerRadius:t,outerRadius:i,startAngle:r,endAngle:n}=e,o=t<=0;if(!((e.cornerRadius??0)>0&&(e.roundStart||e.roundEnd))){if(o){let e=Vk(i,r),t=Vk(i,n),o=n-r>Math.PI?1:0;return`M0,0 L${e.x},${e.y} A${i},${i} 0 ${o} 1 ${t.x},${t.y} Z`}let e=Vk(i,r),a=Vk(i,n),s=Vk(t,n),l=Vk(t,r),c=n-r>Math.PI?1:0;return`M${e.x},${e.y} A${i},${i} 0 ${c} 1 ${a.x},${a.y} L${s.x},${s.y} A${t},${t} 0 ${c} 0 ${l.x},${l.y} Z`}let a=i-t,s=Math.max(0,Math.min(e.cornerRadius??0,a/2));if(0===s)return Hk({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let l=Math.asin(Math.min(1,s/Math.max(1e-9,i-s))),c=o?0:Math.asin(Math.min(1,s/Math.max(1e-9,t+s))),u=n-r,d=e.roundStart&&e.roundEnd?u/2:u,h=!!e.roundStart&&l<d,p=!!e.roundEnd&&l<d;if(!h&&!p)return Hk({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let f=r+(h?l:0),g=n-(p?l:0),m=r+(h?c:0),y=n-(p?c:0),x=Vk(i,f),b=Vk(i,g),v=(i-s)*Math.cos(l),w=Vk(v,r),S=Vk(v,n),k=o?null:Vk(t,y),A=o?null:Vk(t,m),M=o?0:(t+s)*Math.cos(c),$=o?null:Vk(M,r),_=o?null:Vk(M,n),P=g-f>Math.PI?1:0,I=o?0:y-m>Math.PI?1:0,T="";if(h)T+=`M${w.x},${w.y}`,T+=` A${s},${s} 0 0 1 ${x.x},${x.y}`;else{let e=Vk(i,r);T+=`M${e.x},${e.y}`}if(p)T+=` A${i},${i} 0 ${P} 1 ${b.x},${b.y}`,T+=` A${s},${s} 0 0 1 ${S.x},${S.y}`;else{let e=Vk(i,n);T+=` A${i},${i} 0 ${P} 1 ${e.x},${e.y}`}if(o)T+=" L0,0";else{if(p)T+=` L${_.x},${_.y}`,T+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{let e=Vk(t,n);T+=` L${e.x},${e.y}`}if(h)T+=` A${t},${t} 0 ${I} 0 ${A.x},${A.y}`,T+=` A${s},${s} 0 0 1 ${$.x},${$.y}`;else{let e=Vk(t,r);T+=` A${t},${t} 0 ${I} 0 ${e.x},${e.y}`}}return T+=" Z",T}import{jsx as Uk,jsxs as Zk}from"react/jsx-runtime";function Kk(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${(e/1e3).toFixed(0)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Qk(e,t){let i=e.datum;if(!i)return null;let r=[],n=i.__funnelStepLabel,o=Number(i.__funnelStepLabelX),a=Number(i.__funnelStepLabelY),s=Number(i.__funnelRowWidth);"string"==typeof n&&Number.isFinite(o)&&Number.isFinite(a)&&(!Number.isFinite(s)||8.4*n.length+16<=s)&&r.push(Uk("text",{x:o,y:a+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-step`));let l=Number(i.__funnelValue),c=Number(i.__funnelValueLabelX),u=Number(i.__funnelValueLabelY),d=Number(i.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){let e=Number(i.__funnelPercent),n=!0!==i.__funnelIsFirstStep&&Number.isFinite(e)?`${Kk(l)} (${Math.abs(e-Math.round(e))<.05?Math.round(e):e.toFixed(1)}%)`:Kk(l);7.8*n.length+16>d&&(n=Kk(l)),7.8*n.length+16<=d&&r.push(Uk("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-value`))}return r.length?Uk("g",{children:r},`${t}-funnel-labels`):null}function Jk(e,t,i){return Qa(function(e,t,i){let r=("category"in e?e.category:void 0)||("group"in e?e.group:void 0)||"",n=i=>`ord-${e.type}-${r}-${t}-${i}`,o=`ord-${e.type}-${r}-${t}`;switch(e.type){case"rect":{let t,i,r=e,n=`${Ya(o)}-grad`,a=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=e.x,n=e.y,o=e.x,a=e.y+e.h;"bottom"===e.roundedEdge?(n=e.y+e.h,a=e.y):"right"===e.roundedEdge?(r=e.x+e.w,n=e.y,o=e.x,a=e.y):"left"===e.roundedEdge&&(r=e.x,n=e.y,o=e.x+e.w,a=e.y);let s=Xa(i.stops,Wa(e.style.fill));return s?Oa("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:r,y1:n,x2:o,y2:a,children:s}):null}(r,n);if(a)i=`url(#${n})`;else if(Aa(r.style.fill)){let e=`${Ya(o)}-hatch`;t=Ma(r.style.fill,e),i=`url(#${e})`}else i=Wa(r.style.fill);let s=a||t?Zk("defs",{children:[a,t]}):null;if(r.cornerRadii&&function(e){return(e.tl??0)>0||(e.tr??0)>0||(e.br??0)>0||(e.bl??0)>0}(r.cornerRadii)){let e=function(e){let{x:t,y:i,w:r,h:n}=e,{tl:o,tr:a,br:s,bl:l}=function(e){let t=e.cornerRadii;if(!t)return{tl:0,tr:0,br:0,bl:0};let i=Math.min(e.w,e.h)/2,r=e=>Math.max(0,Math.min(e??0,i));return{tl:r(t.tl),tr:r(t.tr),br:r(t.br),bl:r(t.bl)}}(e),c=`M${t+o},${i}`;return c+=` L${t+r-a},${i}`,a>0&&(c+=` A${a},${a} 0 0 1 ${t+r},${i+a}`),c+=` L${t+r},${i+n-s}`,s>0&&(c+=` A${s},${s} 0 0 1 ${t+r-s},${i+n}`),c+=` L${t+l},${i+n}`,l>0&&(c+=` A${l},${l} 0 0 1 ${t},${i+n-l}`),c+=` L${t},${i+o}`,o>0&&(c+=` A${o},${o} 0 0 1 ${t+o},${i}`),c+=" Z",c}(r);return Zk(Xk.Fragment,{children:[s,Uk("path",{d:e,fill:i,...ja(r.style)})]},o)}if(r.roundedTop&&r.roundedTop>0){let e,t=Math.min(r.roundedTop,r.w/2,r.h/2),{x:n,y:a,w:l,h:c}=r;switch(r.roundedEdge){case"right":e=`M${n},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n},${a+c} Z`;break;case"left":e=`M${n+l},${a} L${n+t},${a} A${t},${t} 0 0 0 ${n},${a+t} L${n},${a+c-t} A${t},${t} 0 0 0 ${n+t},${a+c} L${n+l},${a+c} Z`;break;case"bottom":e=`M${n},${a} L${n+l},${a} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n+t},${a+c} A${t},${t} 0 0 1 ${n},${a+c-t} Z`;break;default:e=`M${n},${a+c} L${n},${a+t} A${t},${t} 0 0 1 ${n+t},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c} Z`}return Zk(Xk.Fragment,{children:[s,Uk("path",{d:e,fill:i,...ja(r.style)})]},o)}return Zk(Xk.Fragment,{children:[s,Uk("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:i,...ja(r.style)}),Qk(r,o)]},o)}case"point":return Va(e,t,i);case"symbol":return Ga(e,t,i);case"glyph":{let r=e;return qa(r,r.x,r.y,`${i??""}ord-glyph-${r.pointId??t}`)}case"wedge":{let r,n=e;if(n._gradientBand&&n._gradientBand.colors.length>0){let e=Ya(`${i?`${i}-`:""}gauge-grad-${n.category||o}-${t}`),{clipPath:r,slices:a}=function(e){let t=Hk({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,cornerRadius:e.cornerRadius,roundStart:e.roundStart,roundEnd:e.roundEnd}),i=[],r=e.colors;if(r.length>0){let t=(e.endAngle-e.startAngle)/r.length;for(let n=0;n<r.length;n++){let o=e.startAngle+n*t;i.push({d:Hk({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:o,endAngle:e.endAngle}),color:r[n]})}}return{clipPath:t,slices:i}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return Zk("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,strokeOpacity:n.style.strokeOpacity,children:[Uk("defs",{children:Uk("clipPath",{id:e,children:Uk("path",{d:r})})}),Uk("g",{clipPath:`url(#${e})`,children:a.map((e,t)=>Uk("path",{d:e.d,fill:Wa(e.color)},t))}),n.style.stroke&&"none"!==n.style.stroke&&Uk("path",{d:r,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},o)}if(n.roundedEnds)r=Hk({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{let e=Gk().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&e.cornerRadius(n.cornerRadius),r=e(Ba)||""}return Uk("path",{d:r,transform:`translate(${n.cx},${n.cy})`,fill:Wa(n.style.fill),...ja(n.style)},o)}case"boxplot":{let t=e,i=t.columnWidth/2,r=t.style.strokeWidth??1;return"vertical"===t.projection?Zk("g",{opacity:t.style.opacity,strokeOpacity:t.style.strokeOpacity,children:[Uk("line",{x1:t.x,y1:t.minPos,x2:t.x,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("rect",{x:t.x-i,y:Math.min(t.q1Pos,t.q3Pos),width:t.columnWidth,height:Math.abs(t.q3Pos-t.q1Pos),fill:Wa(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("line",{x1:t.x-i,y1:t.medianPos,x2:t.x+i,y2:t.medianPos,stroke:t.style.stroke||"#333",strokeWidth:2*r}),Uk("line",{x1:t.x-.5*i,y1:t.minPos,x2:t.x+.5*i,y2:t.minPos,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("line",{x1:t.x-.5*i,y1:t.maxPos,x2:t.x+.5*i,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r})]},o):Zk("g",{opacity:t.style.opacity,strokeOpacity:t.style.strokeOpacity,children:[Uk("line",{x1:t.minPos,y1:t.y,x2:t.maxPos,y2:t.y,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("rect",{x:Math.min(t.q1Pos,t.q3Pos),y:t.y-i,width:Math.abs(t.q3Pos-t.q1Pos),height:t.columnWidth,fill:Wa(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("line",{x1:t.medianPos,y1:t.y-i,x2:t.medianPos,y2:t.y+i,stroke:t.style.stroke||"#333",strokeWidth:2*r}),Uk("line",{x1:t.minPos,y1:t.y-.5*i,x2:t.minPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r}),Uk("line",{x1:t.maxPos,y1:t.y-.5*i,x2:t.maxPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r})]},o)}case"violin":{let t=e,i=[Uk("path",{d:t.pathString,transform:t.translateX||t.translateY?`translate(${t.translateX},${t.translateY})`:void 0,fill:Wa(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:t.style.strokeWidth??1},n("path"))];if(t.iqrLine&&t.bounds){let e=t.bounds,r=e.x+e.width/2,o=e.y+e.height/2;t.iqrLine.isVertical?i.push(Uk("line",{opacity:.8,x1:r,y1:t.iqrLine.q1Pos,x2:r,y2:t.iqrLine.q3Pos,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),Uk("circle",{opacity:.8,cx:r,cy:t.iqrLine.medianPos,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med"))):i.push(Uk("line",{opacity:.8,x1:t.iqrLine.q1Pos,y1:o,x2:t.iqrLine.q3Pos,y2:o,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),Uk("circle",{opacity:.8,cx:t.iqrLine.medianPos,cy:o,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med")))}return Uk("g",{opacity:t.style.opacity,strokeOpacity:t.style.strokeOpacity,children:i},o)}case"connector":{let t=e,i=t.style.fill&&"none"!==t.style.fill?Wa(t.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return Uk("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||i,strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity??.5,strokeOpacity:t.style.strokeOpacity},o)}case"trapezoid":{let t=e,i=t.points.map(e=>`${e[0]},${e[1]}`).join(" ");return Uk("polygon",{points:i,fill:Wa(t.style.fill,"#999"),...ja(t.style)},o)}default:return null}}(e,t,i),e,`ordinal-cursor-${t}`)}import{jsx as eA,jsxs as tA}from"react/jsx-runtime";function iA(e){return"connector"===e.node.type}function rA(e,t,i,r){if(e.length<2)return null;let n=e[0].node,o=n.style.fill;if(!o||"none"===o)return null;let a=Ya(`${t?`${t}-`:""}connector-${i}-${r}-hatch`),s=Aa(o)?Ma(o,a):null,l=[`${n.x1},${n.y1}`,...e.map(({node:e})=>`${e.x2},${e.y2}`)].join(" ");return Qa(tA(qk.Fragment,{children:[s&&eA("defs",{children:s}),eA("polygon",{points:l,fill:s?`url(#${a})`:Wa(o,"#999"),opacity:n.style.opacity,fillOpacity:n.style.fillOpacity??.3,"data-semiotic-connector-fill":n.group||"_default"})]}),n,`ordinal-connector-fill-${i}-${r}`)}function nA(e,t,i){let r=new Map;for(let t of e){if(!iA(t))continue;let e=t.node.group||"_default",i=r.get(e);i?i.push(t):r.set(e,[t])}if(0===r.size)return;let n=Array.from(r.values()).map((e,r)=>tA("g",{children:[rA(e,t,i,r),e.map(e=>e.element)]},`ordinal-connectors-${i}-${r}`)),o=e[0],a=iA(o)?null:o.element;for(let e of r.values())for(let t of e)t.element=null;o.element=tA(qk.Fragment,{children:[n,a]},`ordinal-connector-run-${i}`)}function oA(e){let t=os({nodes:e.nodes,renderMode:e.renderMode,fallback:(t,i)=>Jk(t,i,e.idPrefix)}),i=0;for(let r=0;r<t.length;){if(t[r].renderedByBackend){r++;continue}let n=r+1;for(;n<t.length&&!t[n].renderedByBackend;)n++;nA(t.slice(r,n),e.idPrefix,i++),r=n}return t}var aA={stroke:"rgba(255,255,255,0.5)",lineWidth:1.5,spacing:6,angle:45,lineOpacity:1};import{Fragment as sA,jsx as lA,jsxs as cA}from"react/jsx-runtime";function uA(e,t){let i=Pi(e.theme),r=Vc,n=e.size||[500,400],o=ve({...r,...e.margin},un(e.title)),a=xe(un(e.title)),s=_t(e.data),l=e.showLegend?ys(s,e.colorAccessor||e.stackBy||e.groupBy):[],c=function(e){let t=e.projection??"vertical",i=!1!==e.showAxes&&"radial"!==t;return{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasValueLabel:e.hasCategoryLabel),leftAxis:{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasCategoryLabel:e.hasValueLabel)}}}({showAxes:e.showAxes,projection:e.projection,hasCategoryLabel:!(!e.categoryLabel&&!e.oLabel),hasValueLabel:!(!e.valueLabel&&!e.rLabel)});Ec(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=Oc({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),p=e.projection||"vertical",f="radial"===p,g=e.colorScheme||i.colors.categorical,m={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:p,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:gi(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:g,themeCategorical:i.colors.categorical,themeSemantic:_(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors},y=new jk(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Gc(e.backgroundGraphics,n,o,y.scales),b=Gc(e.foregroundGraphics,n,o,y.scales);if(!y.scales){let r,a=e.annotations?lc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,projection:p,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=xa({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?cA(sA,{children:[x,a,b,y.customLayoutOverlays]}):null;return dk.renderToStaticMarkup(zc(l,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let v=e._idPrefix,w=e.showGrid?function(e,t,i,r,n,o){let a=e.scales;if(!a||"radial"===a.projection)return null;let{grid:s}=Ii(i),l=r?`${r}-`:"",c="vertical"===a.projection,u=o??bc(a.r,5,n);return Pc("g",c?{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);return Pc("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:s,strokeWidth:.5},`gr-${i}`)})}:{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);return Pc("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},`gr-${i}`)})})}(y,{width:d,height:h},i,v,e.axisExtent,e.rTickValues):null,S=null;if(y.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){let t=Lc(e),i=new Set;for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";i.add(t)}S=Array.from(i).map((e,i)=>function(e){let{id:t,...i}=e;return Ma({type:"hatch",...i},t)}({...aA,id:`funnel-hatch-${t}-${i}`,background:e}));let r=new Map;Array.from(i).forEach((e,i)=>r.set(e,`funnel-hatch-${t}-${i}`));for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";e.style={...e.style,fill:`url(#${r.get(t)})`}}}let k,A=oA({nodes:y.scene,renderMode:e.renderMode,idPrefix:v}),M=A.map(e=>e.element),$=!1!==e.showAxes?function(e,t,i,r,n,o,a,s=!1){let l=e.scales;if(!l||"radial"===l.projection)return null;let c=Ii(r),u="vertical"===l.projection,d=e.columns,h=i.categoryFormat||i.oFormat,p=i.valueFormat||i.rFormat,f=i.categoryLabel||i.oLabel,g=i.valueLabel||i.rLabel,m=i.legendPosition??"right",y=Me(i.legendLayout,a?.leftAxis),x=s&&"left"===m&&y>0?y:o?.left??i.margin?.left??40,b=Object.values(d).map((e,t)=>({pixel:e.middle,label:h?h(e.name,t):e.name})),v=i.rTickValues??bc(l.r,5,i.axisExtent),w=p||fe(v),S=v.map(e=>({pixel:l.r(e),label:w(e)}));return cA("g",u?{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[lA("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,i)=>cA("g",{transform:`translate(${e.pixel},${t.height})`,children:[lA("line",{y2:5,stroke:c.border,strokeWidth:1}),wc(e.label)?lA("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):Sc({label:e.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oxtick-${i}`)),f&&lA("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:f}),lA("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),S.map((e,t)=>cA("g",{transform:`translate(0,${e.pixel})`,children:[lA("line",{x2:-5,stroke:c.border,strokeWidth:1}),lA("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oytick-${t}`)),g&&lA("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:g})]}:{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[lA("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),S.map((e,i)=>cA("g",{transform:`translate(${e.pixel},${t.height})`,children:[lA("line",{y2:5,stroke:c.border,strokeWidth:1}),lA("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oxtick-${i}`)),g&&lA("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),lA("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,t)=>cA("g",{transform:`translate(0,${e.pixel})`,children:[lA("line",{x2:-5,stroke:c.border,strokeWidth:1}),wc(e.label)?lA("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):Sc({label:e.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oytick-${t}`)),f&&lA("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:f})]})}(y,{width:d,height:h},e,i,v,o,c,!!u):null,P=e.categoryAccessor??e.oAccessor??"category",I=e.valueAccessor??e.rAccessor??"value",T="horizontal"===p,L=Wk(T?I:P,void 0,"__semiotic_resolvedO",""),C=Wk(T?P:I,void 0,"__semiotic_resolvedR",""),R=e.annotations?lc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:Yk(L,C,e.annotations.length>0)(s),scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:d,height:h},theme:i,projection:p,xAccessor:L.key,yAccessor:C.key,idPrefix:v,onRender:e=>{k=e}}):null;if(t){let i=y.scales.o?.domain?.();t.evidence=xa({frameType:"ordinal",width:n[0],height:n[1],marks:A.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:k,yDomain:ya(y.scales.r?.domain?.()),categories:Array.isArray(i)?i.map(String):void 0,margin:o})}let N=f&&null!=e.centerContent?function(e,t,i,r){if(("string"==typeof e||"number"==typeof e)&&(e=lk("text",{fill:"currentColor",...r,children:e})),!uk(e))return null;if(!sk.isValidElement(e)||e.type===sk.Fragment)return lk("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:e});let n=e,o="text"===n.type?sk.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return lk("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:o})}(e.centerContent,o.left+d/2,o.top+h/2,{fill:i.colors.text,fontFamily:i.typography.fontFamily,fontSize:i.typography.titleSize}):null,D=f&&null!=e.centerContent?N??lA("foreignObject",{x:o.left,y:o.top,width:d,height:h,pointerEvents:"none",children:lA("div",{xmlns:Dl,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null,F=cA(sA,{children:[w,M,$,R,b,y.customLayoutOverlays]}),E=cA(sA,f?{children:[x?lA("g",{transform:`translate(${-d/2},${-h/2})`,children:x}):null,F]}:{children:[x,F]});return dk.renderToStaticMarkup(zc(E,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:f?`translate(${o.left+d/2},${o.top+h/2})`:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,defs:S,outerElements:D,markCount:A.length,idPrefix:e._idPrefix}))}import*as dA from"react-dom/server";import{geoPath as hA}from"d3-geo";var pA=/*#__PURE__*/new WeakMap;function fA(e,t){pA.set(e,t)}function gA(e,t){let i,r=new Map;return e.map(e=>{let n=pA.get(e);if(void 0!==n)return n;if(!i){let e=new Map;i=e,t.forEach((t,i)=>{let r=e.get(t);r?r.push(i):e.set(t,[i])})}let o=r.get(e.datum)??0;return r.set(e.datum,o+1),i.get(e.datum)?.[o]??-1})}import{geoPath as mA}from"d3-geo";function yA(e){return{projection:e,geoPath:mA(e),projectedPoint:(t,i)=>e([t,i]),invertedPoint:(t,i)=>e.invert?.([t,i])??null}}import{geoPath as xA}from"d3-geo";import{quadtree as bA}from"d3-quadtree";import{geoMercator as vA,geoEqualEarth as wA,geoAlbersUsa as SA,geoOrthographic as kA,geoNaturalEarth1 as AA,geoEquirectangular as MA}from"d3-geo";var $A={mercator:vA,equalEarth:wA,albersUsa:SA,orthographic:kA,naturalEarth:AA,equirectangular:MA};function _A(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function PA(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function IA(e,t,i){return e?"function"==typeof e?{...i,...e(t)}:{...i,...e}:{...i}}function TA(e,t){if(e.length<2)return[e];let i=.4*t,r=[],n=[e[0]];for(let t=1;t<e.length;t++){let o=e[t-1],a=e[t];Math.abs(a[0]-o[0])>i?(n.length>=2&&r.push(n),n=[a]):n.push(a)}return n.length>=2&&r.push(n),r}function LA(e,t,i=24){let r=t[0]-e[0],n=t[1]-e[1],o=Math.sqrt(r*r+n*n);if(0===o)return[e,t];let a=-n/o,s=r/o,l=Math.min(.3*o,80),c=(e[0]+t[0])/2+a*l,u=(e[1]+t[1])/2+s*l,d=[];for(let r=0;r<=i;r++){let n=r/i,o=1-n,a=o*o*e[0]+2*o*n*c+n*n*t[0],s=o*o*e[1]+2*o*n*u+n*n*t[1];d.push([a,s])}return d}function CA(e,t){if(e.length<2)return e;let i=t/2+1,r=[];for(let t=0;t<e.length;t++){let n,o,a=e[t];0===t?(n=e[1][0]-a[0],o=e[1][1]-a[1]):t===e.length-1?(n=a[0]-e[t-1][0],o=a[1]-e[t-1][1]):(n=e[t+1][0]-e[t-1][0],o=e[t+1][1]-e[t-1][1]);let s=Math.sqrt(n*n+o*o)||1,l=o/s,c=-n/s;r.push([a[0]+l*i,a[1]+c*i])}return r}function RA(e,t,i,r,n){let o=t[0]-e[0],a=t[1]-e[1],s=Math.sqrt(o*o+a*a);if(0===s)return[e,t];let l=a/s,c=-o/s,u=n/2+1;return[[e[0]+l*u,e[1]+c*u],[t[0]+l*u,t[1]+c*u]]}import{scaleLinear as NA}from"d3-scale";var DA=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],FA=["scene-style","data-paint","accessibility","evidence"],EA=(e,t)=>({retainedData:e,invalidations:t}),OA=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],zA=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],BA=["scene-geometry","data-paint","accessibility","evidence"],jA=["scene-style","data-paint","accessibility","evidence"],WA=["scene-geometry","scene-style","data-paint","accessibility","evidence"],YA=["overlay","accessibility","evidence"],qA=[],XA={xAccessor:/*#__PURE__*/EA("rebuild",OA),yAccessor:/*#__PURE__*/EA("rebuild",OA),lineDataAccessor:/*#__PURE__*/EA("rebuild",OA),pointIdAccessor:/*#__PURE__*/EA("rebuild",BA),lineIdAccessor:/*#__PURE__*/EA("rebuild",BA),windowSize:/*#__PURE__*/EA("rebuild",OA),projection:/*#__PURE__*/EA("preserve",zA),projectionExtent:/*#__PURE__*/EA("preserve",zA),fitPadding:/*#__PURE__*/EA("preserve",zA),lineType:/*#__PURE__*/EA("preserve",zA),flowStyle:/*#__PURE__*/EA("preserve",zA),graticule:/*#__PURE__*/EA("preserve",zA),projectionTransform:/*#__PURE__*/EA("preserve",zA),customLayout:/*#__PURE__*/EA("preserve",zA),layoutConfig:/*#__PURE__*/EA("preserve",zA),layoutMargin:/*#__PURE__*/EA("preserve",zA),areaStyle:/*#__PURE__*/EA("preserve",jA),pointStyle:/*#__PURE__*/EA("preserve",WA),lineStyle:/*#__PURE__*/EA("preserve",jA),colorScheme:/*#__PURE__*/EA("preserve",jA),themeCategorical:/*#__PURE__*/EA("preserve",jA),themeDiverging:/*#__PURE__*/EA("preserve",jA),themeSemantic:/*#__PURE__*/EA("preserve",jA),themeSequential:/*#__PURE__*/EA("preserve",jA),decay:/*#__PURE__*/EA("preserve",jA),pulse:/*#__PURE__*/EA("preserve",jA),layoutSelection:/*#__PURE__*/EA("preserve",jA),annotations:/*#__PURE__*/EA("preserve",YA),autoPlaceAnnotations:/*#__PURE__*/EA("preserve",YA),clock:/*#__PURE__*/EA("preserve",qA),transition:/*#__PURE__*/EA("preserve",qA),introAnimation:/*#__PURE__*/EA("preserve",qA),onLayoutError:/*#__PURE__*/EA("preserve",qA)},GA=/*#__PURE__*/EA("preserve",zA),VA=class{constructor(){this.tracker=new go}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},DA)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},FA):this.recordNoop("restyle")}recordConfig(e,t={}){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=Object.prototype.hasOwnProperty.call(XA,r)?XA[r]:GA;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e),r=new Set(i.invalidations);return t.retainedDataChanged&&r.add("data"),this.tracker.record({kind:"config",keys:e},r)}};import{geoDistance as HA,geoGraticule as UA,geoInterpolate as ZA}from"d3-geo";function KA(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&e<.5)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${String(e)}.`)}var QA=class extends uo{constructor(e){var t;super(),this.updateResults=new VA,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=(t=e,{...t,fitPadding:KA(t.fitPadding)})}currentTime(){return this.config.clock?.()??o()}getConfiguredWindowSize(){let e=this.config.windowSize??500;if(!Number.isInteger(e)||e<1)throw new Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){let t=this.pointBuffer.toArray(),i=this.timestampBuffer?.toArray()??[],r=t.slice(-e),n=i.slice(-r.length),o=this.currentTime();this.pointBuffer=new yn(e),this.timestampBuffer=new yn(e),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(n[t]??o)})}this.retainNewestLines(e)}updateConfig(e){let t="fitPadding"in(o=e)?{...o,fitPadding:KA(o.fitPadding)}:o,i=this.config,r=this.getConfiguredWindowSize(),n=Object.keys(t).filter(e=>t[e]!==i[e]);var o;this.config={...this.config,...t};let a=this.getConfiguredWindowSize(),s=this.streaming&&a!==r;s&&(this.resizeStreamingWindow(a),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});let t=this.getConfiguredWindowSize(),i=this.pointBuffer?this.pointBuffer.toArray():this.pointData,r=this.timestampBuffer?.toArray()??[],n=i.slice(-t),o=r.slice(-n.length),a=this.currentTime();this.pointBuffer=new yn(t),this.timestampBuffer=new yn(t),n.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(o[t]??a)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();so(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();for(let i of e)so(this.pointBuffer,i,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");let t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(let e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){let{lineIdAccessor:t}=this.config;if(!t)throw new Error("removeLine() requires lineIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]),n=[];return this.lineData=this.lineData.filter(e=>!r.has(String(i(e)))||(n.push(e),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(e){let{pointIdAccessor:t}=this.config;if(!t)throw new Error("removePoint() requires pointIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){let e=e=>r.has(String(i(e)));lo(this.pointBuffer,this.timestampBuffer,e);let t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{let e=[];return this.pointData=this.pointData.filter(t=>!r.has(String(i(t)))||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){let t=this._customRestyle;if(t){for(let i of this.scene){let r=this._baseStyles.get(i)??i.style,n=t(i,e);i.style=n?{...r,...n}:r}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}rebuildProjectedScene(e,t){this._customLayoutFailedThisBuild=!1;let i=this.buildSceneNodes(e);return this._customLayoutFailedThisBuild?(this.lastCustomLayoutFailure?.preservedLastGoodScene?t():(this.scene=[],this.rebuildQuadtree()),!1):(this.scene=i,this.rebuildQuadtree(),!0)}computeScene(e){let{config:t}=this,i=this.projection,r=this.geoPath,n=this.scales,o=this.baseScale,a=[...this.baseTranslate],s=[...this.baseRotation],l=this.scene;this.projection=function(e){if(!e)return wA();if("string"==typeof e){let t=$A[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),wA())}if("object"==typeof e&&"type"in e){let t=$A[e.type],i=t?t():wA();return e.rotate&&"rotate"in i&&i.rotate(e.rotate),e.center&&"center"in i&&i.center(e.center),i}return e}(t.projection),this.geoPath=xA(this.projection),this.fitProjection(e),this.geoPath=xA(this.projection);let c=this.projection;if(this.scales=yA(c),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(e,()=>{this.projection=i,this.geoPath=r,this.scales=n,this.baseScale=o,this.baseTranslate=a,this.baseRotation=s})){if(t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){let t=e.width/2,i=e.height/2,r=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:i}));r.length>0&&this.startTransition(r)}this._hasRenderedOnce=!0,t.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(e){let t=this.projection,i=this.config,r=[...this.areas],n=_A(i.xAccessor,"lon"),o=_A(i.yAccessor,"lat"),a=this.getPoints();if(a.length>0){let e=a.map(e=>[n(e),o(e)]).filter(e=>e.every(Number.isFinite));r.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}let s=PA(i.lineDataAccessor);for(let e of this.lineData){let t=s(e);if(t&&t.length>0){let e=t.map(e=>[n(e),o(e)]);r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==r.length){if(i.projectionExtent){let[[r,n],[o,a]]=i.projectionExtent,s={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[r,n],[r,a],[o,a],[o,n],[r,n]]]}};t.fitExtent([[0,0],[e.width,e.height]],s)}else if(t.clipAngle&&(t.clipAngle()??0)>0){let r=i.fitPadding??0,n=Math.min(e.width,e.height),o=n/2-n*r;t.scale(o),t.translate([e.width/2,e.height/2])}else{let n={type:"FeatureCollection",features:r},o=i.fitPadding??0,a=e.width*o,s=e.height*o;t.fitExtent([[a,s],[e.width-a,e.height-s]],n),function(e,t,i){if(Number.isFinite(e.scale())&&e.translate().every(Number.isFinite))return;e.scale(Math.max(1,Math.min(i.width,i.height)/(2*Math.PI))),e.translate([i.width/2,i.height/2]);let r=hA(e).bounds(t);if(!r.flat().every(Number.isFinite))return;let n=e.translate();e.translate([n[0]+i.width/2-(r[0][0]+r[1][0])/2,n[1]+i.height/2-(r[0][1]+r[1][1])/2])}(t,n,e)}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e.k),i.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=xA(i),this.scales=yA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e),i.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=xA(i),this.scales=yA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){let i=this.projection;if(!i||!i.rotate)return;let r=this.geoPath,n=this.scales,o=[...i.rotate()];i.rotate(e),this.geoPath=xA(i),this.scales=yA(i),this.geoPath=this.scales.geoPath,this.rebuildProjectedScene(t,()=>{i.rotate(o),this.geoPath=r,this.scales=n})&&(this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){let t=this.projection;!t||!t.rotate||t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,t=0;for(let i of this.scene)"point"===i.type&&!1!==i.interactive&&(t++,i.r>e&&(e=i.r));if(this._maxPointRadius=e,t<=500)return void(this._quadtree=null);let i=new Array(t),r=0;for(let e of this.scene)"point"===e.type&&!1!==e.interactive&&(i[r++]=e);this._quadtree=bA().x(e=>e.x).y(e=>e.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;let{config:t}=this,i=this.projection,r=this.geoPath;if(t.customLayout&&this.scales){let i=t.layoutMargin??{top:0,right:0,bottom:0,left:0},r=ig(t.colorScheme,t.themeCategorical,Jt),n={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:i,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...r]},resolveColor:rg(r,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null},o=Dn({family:"geo",logLabel:"geo customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:t.onLayoutError,run:()=>t.customLayout(n)});if("failure"===o.kind)return this.lastCustomLayoutFailure=o.diagnostic,this._customLayoutFailedThisBuild=!0,o.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let a=o.result,s=a.nodes??[];if(this.customLayoutOverlays=a.overlays??null,this.lastCustomLayoutResult=a,this.lastCustomLayoutFailure=null,this._customRestyle=a.restyle,this.hasCustomRestyle=!!a.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle)for(let e of s){this._baseStyles.set(e,e.style);let i=a.restyle?.(e,t.layoutSelection??null);i&&(e.style={...e.style,...i})}return Cn({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:i,areas:r,points:n,lines:o,layout:a}){let s=_A(e.xAccessor,"lon"),l=_A(e.yAccessor,"lat"),c=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){let t=!0===e.graticule?{}:e.graticule,r=UA();t.step&&r.step(t.step);let n=i(r())||"";n&&c.push({type:"geoarea",pathData:n,centroid:[a.width/2,a.height/2],bounds:[[0,0],[a.width,a.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth??.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(let t of r){let r=i(t);if(!r)continue;let n=i.centroid(t),o=i.bounds(t),a=i.area(t);c.push({type:"geoarea",pathData:r,centroid:n,bounds:o,screenArea:a,style:IA(e.areaStyle,t,u),datum:t,interactive:!0})}let p=PA(e.lineDataAccessor);for(let i of o){let r=p(i);if(!r||r.length<2)continue;let n=[];if("geo"===e.lineType){let e=new Array(r.length);for(let t=0;t<r.length;t++)e[t]=[s(r[t]),l(r[t])];for(let i=0;i<e.length-1;i++){let r=e[i],o=e[i+1],a=HA(r,o)||0,s=Math.max(2,Math.ceil(a/(Math.PI/180))),l=ZA(r,o);for(let e=0;e<=s;e++){if(i>0&&0===e)continue;let r=t(l(e/s));null!=r&&n.push(r)}}}else for(let e=0;e<r.length;e++){let i=r[e],o=t([s(i),l(i)]);null!=o&&n.push(o)}if(n.length<2)continue;let o=IA(e.lineStyle,i,d),u="number"==typeof o.strokeWidth?o.strokeWidth:1;2===r.length&&n.length>=2&&"arc"===e.flowStyle?n=LA(n[0],n[n.length-1]):2===r.length&&n.length>=2&&"offset"===e.flowStyle&&(n="geo"===e.lineType?CA(n,u):RA(n[0],n[n.length-1],0,0,u));let h=TA(n,a.width);if(h.length<=1)c.push({type:"line",path:n.length>=2?n:h[0]||n,style:o,datum:i});else for(let e of h)e.length<2||c.push({type:"line",path:e,style:{...o,_edgeFade:!0},datum:i})}let f=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,g=t.clipAngle?t.clipAngle()??0:0,m=g>0?g*Math.PI/180:null,y=t.rotate?t.rotate():[0,0,0],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-y[0],(x[1]??0)-y[1]];for(let[i,r]of n.entries()){let n=s(r),o=l(r);if(!Number.isFinite(n)||!Number.isFinite(o)||null!=m&&HA([n,o],b)>m)continue;let a=t([n,o]);if(!a||!Number.isFinite(a[0])||!Number.isFinite(a[1]))continue;let u=e.pointStyle?e.pointStyle(r):{...h},d={type:"point",x:a[0],y:a[1],r:u.r||4,style:u,datum:r,pointId:f?String(f(r)):void 0};fA(d,i),c.push(d)}return c}({config:t,projection:i,path:r,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){let i=function(e,t,i,r){let n=e.filter(e=>"point"===e.type);if(n.length<2)return null;let o=t.strength??1,a=Number.isFinite(o)?Math.max(0,Math.min(1,o)):1,s="strip"===t.layout?"strip":"radial";if("radial"===s&&0===a)return null;let l=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=n.find(e=>e.datum&&String(l(e.datum))===String(t.center));if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;let d=n.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),h=he(d,1);r>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){let i=e[t];"geoarea"===i.type&&i.interactive&&e.splice(t,1)}let p="strip"===s?function(e,t,i,r,n){let o=Math.max(3,Math.min(8,.35*n.height)),a=Math.max(1,n.width-2*o),s=n.height/2,l=NA().domain([0,r]).range([0,a]);t.x=o,t.y=s;let c=[];for(let n of e){if(n===t)continue;if(!n.datum){n.x=o,n.y=s;continue}let e=Number(i(n.datum)),a=o+(isFinite(e)&&e>=0&&r>0?l(e):0);n.x=a,n.y=s,c.push({node:n,x:a})}c.sort((e,t)=>e.x-t.x);let u=Math.max(0,Math.min(n.height/2-1,6)),d=0;for(;d<c.length;){let e=d+1;for(;e<c.length&&Math.abs(c[e].x-c[d].x)<3;)e++;let t=e-d;if(t>1&&u>0)for(let e=0;e<t;e++){let i=e-(t-1)/2,r=Math.min(2.5,2*u/Math.max(1,t-1));c[d+e].node.y=s+i*r}d=e}return{cx:o,cy:s,maxCost:r,availableRadius:a,layout:"strip"}}(n,u,c,h,i):function(e,t,i,r,n,o){let a=t.x,s=t.y,l=o.width/2,c=o.height/2,u=Math.min(o.width,o.height)/2,d=NA().domain([0,r]).range([0,u]);for(let o of e){if(o===t||!o.datum)continue;let e=o.x,u=o.y,h=Math.atan2(u-s,e-a),p=Math.hypot(e-a,u-s),f=Number(i(o.datum)),g=isFinite(f)&&f>=0?r>0?d(f):0:p,m=l+Math.cos(h)*g,y=c+Math.sin(h)*g;o.x=e+(m-e)*n,o.y=u+(y-u)*n}return t.x=a+(l-a)*n,t.y=s+(c-s)*n,{cx:t.x,cy:t.y,maxCost:r,availableRadius:u,layout:"radial"}}(n,u,c,h,a,i),f=e.filter(e=>"line"===e.type);if(f.length>0){let e=new Map;for(let t of n)null!=t.pointId&&e.set(String(t.pointId),[t.x,t.y]);for(let i of f){let r=i.datum?.source,n=i.datum?.target;if(null!=r&&null!=n){let o=e.get(String(r)),a=e.get(String(n));if(o&&a)if("fractional"===t.lineMode&&i.path.length>2){let e=i.path[0],t=i.path[i.path.length-1],r=[o[0]-e[0],o[1]-e[1]],n=[a[0]-t[0],a[1]-t[1]],s=[0];for(let e=1;e<i.path.length;e++)s.push(s[e-1]+Math.hypot(i.path[e][0]-i.path[e-1][0],i.path[e][1]-i.path[e-1][1]));let l=s[s.length-1];i.path=i.path.map((e,t)=>{let o=l>0?s[t]/l:t/(i.path.length-1);return[e[0]+r[0]*(1-o)+n[0]*o,e[1]+r[1]*(1-o)+n[1]*o]})}else i.path=[o,a]}}}return p}(this.scene,e,t,this.areas.length);i&&(this.cartogramLayout=i)}applyDecay(){let e=this.config.decay;if(!e||!this.pointBuffer)return;let t=this.pointBuffer.size;if(0===t)return;let i=this.scene.filter(e=>"point"===e.type),r=gA(i,this.getPoints());for(let n=0;n<i.length;n++){if(r[n]<0)continue;let o=vn(e,r[n],t);i[n]._decayOpacity=o}}applyPulse(e=this.currentTime()){let t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;let i=this.scene.filter(e=>"point"===e.type),r=this.timestampBuffer.toArray(),n=gA(i,this.getPoints()),o=t.color||"rgba(255,255,255,0.6)",a=t.glowRadius??4,s=!1;for(let l=0;l<i.length;l++){let c=r[n[l]];if(void 0===c)continue;let u=Sn(t,c,e);s=kn(i[l],u,o,a)||s}return s}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&An(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){let t=this.config.transition?.duration??300;if(t<=0)return;let i=new Map;for(let t of e)"point"===t.type&&t.pointId&&i.set(t.pointId,[t.x,t.y]);let r=this.scene.filter(e=>"point"===e.type),n=!1;for(let e of r)if(e.pointId){let t=i.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(n=!0))}for(let e of r)e.pointId&&!i.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??1,e.style={...e.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(let e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(e){if(!this.activeTransition)return!1;let t=r(e,this.activeTransition),o=i(t,this.config.transition?.easing),a=this.scene.filter(e=>"point"===e.type);for(let e of a){if(null!=e._targetX&&null!=e._targetY){let t=e.x,i=e.y;e.x=n(t,e._targetX,o),e.y=n(i,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(t>=1){for(let e of a)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};import*as JA from"react";import{jsx as eM,jsxs as tM}from"react/jsx-runtime";function iM(e){if(!e)return;let t=[];for(let i of e)if("point"===i.type)t.push(i);else if("glyph"===i.type){let e=i,r=m(e.glyph,e.size);t.push({pointId:e.pointId,x:e.x+r.centerDx,y:e.y+r.centerDy,r:r.radius})}return t}import{jsx as rM,jsxs as nM}from"react/jsx-runtime";function oM({bottomMargin:e,costLabel:t,layout:{cx:i,cy:r,maxCost:n,availableRadius:o,layout:a},ringStyle:s,ringValues:l,showNorth:c,showRingLabels:u,showRings:d}){let h="strip"===a,p={stroke:h?"var(--semiotic-border, #999)":"#999",strokeWidth:h?1:.8,strokeDasharray:h?"none":"4,3",labelColor:"var(--semiotic-text-secondary, #777)",labelSize:h?8:10,...s};return nM("g",h?{children:[rM("line",{x1:i,y1:r,x2:i+o,y2:r,stroke:p.stroke,strokeWidth:p.strokeWidth,strokeLinecap:"round",opacity:.85}),rM("line",{x1:i,y1:r-3.5,x2:i,y2:r+3.5,stroke:p.stroke,strokeWidth:p.strokeWidth,opacity:.9}),d&&l.map(a=>{let s=i+(n>0?a/n*o:0);return nM("g",{children:[rM("line",{x1:s,y1:r-2.5,x2:s,y2:r+2.5,stroke:p.stroke,strokeWidth:.9,opacity:.65}),u&&nM("text",{x:s,y:r+Math.min(10,(e??2)+8),textAnchor:"middle",fontSize:p.labelSize,fill:p.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[a,t?` ${t}`:""]})]},a)})]}:{children:[l.map(e=>{let a=e/n*o;return nM("g",{children:[rM("circle",{cx:i,cy:r,r:a,fill:"none",stroke:p.stroke,strokeWidth:p.strokeWidth,strokeDasharray:p.strokeDasharray,opacity:.5}),u&&nM("text",{x:i+a+3,y:r-2,fontSize:p.labelSize,fill:p.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[e,t?` ${t}`:""]})]},e)}),c&&nM("g",{transform:"translate(24, 24)",children:[rM("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),rM("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),rM("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),rM("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),rM("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),rM("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}import{Fragment as aM,jsx as sM,jsxs as lM}from"react/jsx-runtime";function cM(e,t){let i=Pi(e.theme),r=e.size||[e.width||600,e.height||400],n=ve({top:10,right:10,bottom:10,left:10,...e.margin},un(e.title)),o=xe(un(e.title)),a=Array.isArray(e.areas)?_t(e.areas):e.areas,s=_t(e.points),l=_t(e.lines),c=e.showLegend?(()=>{let t="string"==typeof(r=e.colorBy)||"function"==typeof r?e.colorBy:void 0,i=s.length>0?s:Array.isArray(a)&&a.length>0?"string"==typeof t?a.map(e=>({...e.properties||{},...e})):a:[];var r;return ys(i,t)})():[];Ec(n,{props:e,categories:c,theme:i,size:r,hasTitle:o});let u=Oc({props:e,categories:c,theme:i,size:r,margin:n,hasTitle:o}),d=Math.max(1,r[0]-n.left-n.right),h=Math.max(1,r[1]-n.top-n.bottom),p={projection:e.projection||"equalEarth",projectionExtent:e.projectionExtent,xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineIdAccessor:e.lineIdAccessor,lineType:e.lineType,flowStyle:e.flowStyle,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,colorScheme:e.colorScheme,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutSelection:e.layoutSelection,layoutMargin:n,onLayoutError:e.onLayoutError,themeCategorical:i.colors.categorical,themeSemantic:_(i),themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging},f=new QA(p);if(a){if("string"==typeof a)throw new Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${a}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${a}')\` before calling renderGeoToStaticSVG.`);f.setAreas(a)}e.points&&f.setPoints(s),e.lines&&f.setLines(l),f.computeScene({width:d,height:h});let g,m=Gc(e.backgroundGraphics,r,n,f.scales),y=Gc(e.foregroundGraphics,r,n,f.scales),x=os({nodes:f.scene,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){return Qa(function(e,t){switch(e.type){case"geoarea":{let i=e;if(!i.pathData)return null;let r=Aa(i.style.fill)?Ma(i.style.fill,`geoarea-${t}-hatch`):void 0;return tM(JA.Fragment,{children:[r&&eM("defs",{children:r}),eM("path",{d:i.pathData,fill:r?`url(#geoarea-${t}-hatch)`:Wa(i.style.fill,"#e0e0e0"),...ja(i.style),stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth??.5,strokeDasharray:i.style.strokeDasharray,opacity:(i.style.opacity??1)*(i._decayOpacity??1)})]},`geoarea-${t}`)}case"point":return Va(e,t,"","geopoint");case"line":{let i=e;if(i.path.length<2)return null;let r="M"+i.path.map(e=>`${e[0]},${e[1]}`).join("L");return eM("path",{d:r,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1.5,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity??1},`line-${t}`)}case"glyph":{let i=e;return qa(i,i.x,i.y,`geo-glyph-${i.pointId??t}`)}default:return null}}(e,t),e,`geo-cursor-${t}`)}(e,t)}),b=x.map(e=>e.element),v=x.length>0&&e.cartogramChrome,w=f.cartogramLayout&&v?sM(oM,{layout:{...f.cartogramLayout,layout:f.cartogramLayout.layout??"radial"},ringValues:uM(f.cartogramLayout.maxCost,v.showRings),showRings:v.showRings??!0,showNorth:v.showNorth??!0,showRingLabels:v.showRingLabels??!0,costLabel:"string"==typeof v.costLabel?v.costLabel:void 0}):null,S=e.annotations?lc({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([e,t])=>f.scales.projectedPoint(e,t):void 0},layout:{width:d,height:h},theme:i,pointNodes:iM(f.scene),idPrefix:e._idPrefix,onRender:e=>{g=e}}):null;t&&(t.evidence=xa({frameType:"geo",width:r[0],height:r[1],marks:x.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:g,legendItems:c.length>0?c.length:null!=e.legend?1:void 0,margin:n}));let k=lM(aM,{children:[m,b,S,w,y,f.customLayoutOverlays]});return dA.renderToStaticMarkup(zc(k,{width:r[0],height:r[1],className:"stream-geo-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,markCount:x.length,idPrefix:e._idPrefix}))}function uM(e,t){if(!1===t||e<=0)return[];if(Array.isArray(t))return t.filter(t=>t>0&&t<=e);let i="number"==typeof t?t:Math.min(5,Math.max(2,Math.ceil(e/5))),r=e/i,n=[];for(let e=1;e<=i;e++)n.push(Math.round(r*e*10)/10);return n}import*as dM from"react-dom/server";function hM(e,t,i,r){return 0===i?`${e}${t}`:`${e}${t} ${i}${r}`}import{jsx as pM,jsxs as fM}from"react/jsx-runtime";var gM={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function mM(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}var yM={BigNumber:function(e,t){let i="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",r=gM[i],n=mM(e.width,r.width),o=mM(e.height,r.height),a="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):r.padding,s="center"===e.align||"end"===e.align||"start"===e.align?e.align:r.align,l="center"===s?"middle":"end"===s?"end":"start",c="center"===s?n/2:"end"===s?n-a:a,u=Pi(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=function(e,t={}){if("function"==typeof e)return e;let i=t.locale??"en-US",r=t.currency??"USD";if("currency"===e){let e=t.precision??2,n=new Intl.NumberFormat(i,{style:"currency",currency:r,maximumFractionDigits:e,minimumFractionDigits:e});return e=>n.format(e)}if("percent"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("compact"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{notation:"compact",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("duration"===e)return e=>function(e){if(!Number.isFinite(e))return String(e);let t=e<0?"-":"",i=Math.abs(e),r=Math.round(i);if(r<1e3)return`${t}${r}ms`;let n=Math.round(i/10)/100;if(n<60)return`${t}${function(e){return String(Math.round(100*e)/100)}(n)}s`;let o=Math.round(i/1e3);if(o<3600)return`${t}${hM(Math.floor(o/60),"m",o%60,"s")}`;let a=Math.round(i/6e4);if(a<1440)return`${t}${hM(Math.floor(a/60),"h",a%60,"m")}`;let s=Math.round(i/36e5);return`${t}${hM(Math.floor(s/24),"d",s%24,"h")}`}(e);let n=t.precision??0,o=new Intl.NumberFormat(i,{notation:t.notation??"standard",maximumFractionDigits:n,minimumFractionDigits:0});return e=>o.format(e)}("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),p=void 0===d?"No value":function(e,t,i){return`${t??""}${e}${i??""}`}(h(d),"string"==typeof e.prefix?e.prefix:void 0,"string"==typeof e.suffix?e.suffix:void 0),f=void 0===d?void 0:function(e,t){if(!t||0===t.length||!Number.isFinite(e))return null;let i=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at),r=null;for(let t of i){if(!(e>=t.at))break;r=t}return r}(d,e.thresholds),g=f?.level??"neutral",m="string"==typeof e.color?e.color:function(e,t,i){return t||("success"===e?i.colors.success??"#2ca02c":"warning"===e?i.colors.warning??"#b26a00":"danger"===e?i.colors.danger??"#d62728":"info"===e?i.colors.info??i.colors.primary:i.colors.text)}(g,f?.color,u),y="string"==typeof e.label?e.label:void 0,x="string"==typeof e.caption?e.caption:void 0,b="string"==typeof e.unit?e.unit:void 0,v=void 0===d?void 0:function(e,t,i){let r=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,n=r&&"number"==typeof r.value&&Number.isFinite(r.value)?r.value:void 0,o=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===n?void 0:t-n);if(void 0!==o)return`${function(e,t){return Number.isFinite(e)?function(e,t){return 0===e||t(Math.abs(e))===t(0)}(e,t)?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}(o,i)}${r&&"string"==typeof r.label?` ${r.label}`:""}`}(e,d,h),w=void 0===d?void 0:function(e,t,i){let r=e.target&&"object"==typeof e.target?e.target:void 0;if(!r||"number"!=typeof r.value||!Number.isFinite(r.value))return;let n="string"==typeof r.label?` ${r.label}`:"";return 0===r.value?`target ${i(r.value)}${n}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/r.value)} of ${i(r.value)}${n}`}(e,d,h),S=[v,w,f?.label].filter(Boolean).join(" · "),k="string"==typeof e.description&&e.description||[y,p,b,S].filter(Boolean).join(", "),A="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,M="string"==typeof e.borderColor?e.borderColor:u.colors.border,$=a+r.labelSize,_=$+r.captionSize+4,P=r.showHeader&&(y||x)?x?_+10:$+14:a,I="presentation"===i?o/2+.32*r.valueSize:"thumbnail"===i?o/2+.34*r.valueSize:Math.min(o-a-(S?26:4),P+r.valueSize),T=c+("start"===l?Math.max(r.valueSize,p.length*r.valueSize*.55):0),L=String(e._idPrefix??"bignumber").replace(/[^A-Za-z0-9_-]/g,"_"),C=_i(u,`[data-semiotic-auto="${L}"]`),R=dM.renderToStaticMarkup(fM("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:o,viewBox:`0 0 ${n} ${o}`,role:"img","aria-label":k,"data-semiotic-component":"BigNumber","data-semiotic-auto":C?L:void 0,children:[C&&pM("style",{children:C}),pM("title",{children:y??p}),"string"==typeof e.description&&pM("desc",{children:e.description}),pM("rect",{x:r.border?.5:0,y:r.border?.5:0,width:r.border?n-1:n,height:r.border?o-1:o,rx:r.border?8:0,fill:A,stroke:r.border?M:"none"}),r.showHeader&&y&&pM("text",{x:c,y:$,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.labelSize,fontWeight:600,fill:u.colors.text,children:y}),r.showHeader&&x&&pM("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.captionSize,fill:u.colors.textSecondary,children:x}),pM("text",{x:c,y:I,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:m,"data-mark-type":"value",children:p}),b&&void 0!==d&&"start"===l&&pM("text",{x:T+6,y:I,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*r.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),r.showDetail&&S&&pM("text",{x:c,y:Math.min(o-a,I+r.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.detailSize,fill:u.colors.textSecondary,children:S})]}));return t&&(t.evidence=xa({frameType:"value",width:n,height:o,marks:void 0===d?[]:[{type:"value"}],title:y,description:k})),R}};function xM(e,t,i){return yM[e](t,i)}import*as bM from"react-dom/server";import{jsx as vM,jsxs as wM}from"react/jsx-runtime";import{Fragment as SM,jsx as kM}from"react/jsx-runtime";function AM(e,t){return Cc(t,i=>function(e,t,i){let r;switch(e){case"xy":r=iu(t);break;case"ordinal":r=uA(t);break;case"network":r=Lv(t);break;case"geo":r=cM(t);break;case"physics":r=tw(t);break;default:throw new Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}return Je(r,i)}(e,{...t,_idPrefix:i},i))}function MM(e){return AM("xy",e)}function $M(e){return AM("ordinal",e)}function _M(e){return AM("network",e)}function PM(e){return AM("geo",e)}var IM=/*#__PURE__*/new Set(["d","transform","gradientTransform","patternTransform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-dasharray","stroke-dashoffset","font-size","letter-spacing"]),TM=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function LM(e,t){let i=Number(e);if(!Number.isFinite(i))return e;let r=10**t,n=Math.round((i+Number.EPSILON)*r)/r;return String(n)}function CM(e,t,i=0,r=!1){let n,o=new RegExp(TM.source,TM.flags),a="",s=0,l=!1,c=0,u=!1,d=0;for(;n=o.exec(e);){let h=e.slice(s,n.index);r&&/[a-df-z]/i.test(h)&&(u=/a[^a-df-z]*$/i.test(h),d=0);let p=n[0],f=d++%7;if(u&&(3===f||4===f)){if(p=p[0],"0"!==p&&"1"!==p)return e;o.lastIndex=n.index+1}l&&0===h.length?a+=" ":a+=h,a+=LM(p,c++<i?Math.max(8,t):t),s=n.index+p.length,l=!0}return a+e.slice(s)}function RM(e,t){let i=function(e){if(Number.isFinite(e))return Math.max(0,Math.min(8,Math.floor(e)))}(t);return void 0===i?e:qe(e,(e,t)=>{if(IM.has(e)&&!/\b(?:var|calc|url)\(/i.test(t))return"transform"===e||"gradientTransform"===e||"patternTransform"===e?t.replace(/(matrix|translate|scale|rotate|skewX|skewY)\(([^)]*)\)/g,(e,t,r)=>`${t}(${CM(r,i,"matrix"===t?4:"scale"===t?2:"translate"===t?0:1)})`):CM(t,e.startsWith("stroke-")?Math.max(2,i):i,0,"d"===e)})}var NM=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations","perspective"],DM=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function FM(e,t){let i={};for(let r of t)void 0!==e[r]&&(i[r]=e[r]);return i}function EM(e,t,i){return zM(e,t,i).svg}function OM(e,t,i){let r={},{svg:n,frameType:o}=zM(e,t,i,r),a=r.evidence??xa({frameType:o,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]}),s=t.theme;if("string"==typeof s&&!w(s)&&a.warnings.push("UNKNOWN_THEME"),a.component=e,a.sceneHashVersion=2,a.sceneHash=function(e,t){let i=new Map;return qe(e,(e,t)=>{"id"===e&&!i.has(t)&&i.set(t,`\0scene-${i.size}`)}),O({kind:"semiotic.rendered-svg-scene",version:2,svg:Qe(e,i),frameType:t.frameType,width:t.width,height:t.height,margin:t.margin,plot:t.plot,xDomain:t.xDomain,yDomain:t.yDomain,categories:t.categories})}(n,a),wt(a,e,t),i?.artifactContract){let r=z(i.artifactContract,{excludeEvidenceSamples:!0});r.contract&&(a.artifactContract=r.contract),a.artifactTransfer=r.transfer,a.artifactBinding="0.1"===r.contract?.contractVersion&&"invalid"!==r.transfer.status?B(r.contract,t,e):{status:"unknown",mismatchPaths:[],unknownPaths:["artifactContract"]}}return{svg:n,evidence:a}}function zM(e,t,i,r){let n="xy";return{svg:Cc(t,o=>{let a=function(e,t,i,r,n){if(Object.prototype.hasOwnProperty.call(yM,e))return{svg:RM(Je(xM(e,t,n),i),r?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(ak,e))throw new Error(`Unknown chart component: "${e}". Run \`npx -p semiotic semiotic-ai --list\` for supported chart types.`);let o,a=ak[e],s=a.layout?.mode??(!pt(e)&&function(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(at,e)}(t.mode)?t.mode:void 0),l=function(e,t,i){let r=at[e||"primary"],n=e&&"primary"!==e||!i?.width?r.width:i.width,o=e&&"primary"!==e||!i?.height?r.height:i.height,a=function(e,t,i=e.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:e,matches:[]};let r=i.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){let{when:i}=e,r=t.width,n=t.height,o=function(e){if(!("number"!=typeof e.height||e.height<=0))return e.width/e.height}(t),a=function(e){if(!("number"!=typeof e.height||e.height<=0))return e.width>=e.height?"landscape":"portrait"}(t);return!("number"==typeof i.minWidth&&r<i.minWidth||"number"==typeof i.maxWidth&&r>i.maxWidth||"number"==typeof i.minHeight&&("number"!=typeof n||n<i.minHeight)||"number"==typeof i.maxHeight&&("number"!=typeof n||n>i.maxHeight)||"number"==typeof i.minAspectRatio&&("number"!=typeof o||o<i.minAspectRatio)||"number"==typeof i.maxAspectRatio&&("number"!=typeof o||o>i.maxAspectRatio)||i.orientation&&a!==i.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:r.reduce((e,t)=>function(e,t){let i={...e,...t};for(let r of["margin","frameProps","mobileSemantics","style"])rt(e[r])&&rt(t[r])&&(i[r]={...e[r],...t[r]});return"string"==typeof e.className&&"string"==typeof t.className&&(i.className=`${e.className} ${t.className}`),i}(e,t.rule.transform),e),matches:r}}({...t,mode:e},{width:t.width??n,height:t.height??o}).props,s=a.mode||e||"primary",l=at[s],c="context"===s||"sparkline"===s,u="primary"===s&&i?.width?i.width:l.width,d="primary"===s&&i?.height?i.height:l.height;return{mode:s,width:a.width??u,height:a.height??d,showAxes:a.showAxes??l.showAxes,showGrid:a.showGrid??l.showGrid,enableHover:a.enableHover??(!!a.linkedHover||l.enableHover),showLegend:a.showLegend??l.showLegend,showLabels:a.showLabels??l.showLabels,title:c?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:c?void 0:a.xLabel,yLabel:c?void 0:a.yLabel,categoryLabel:c?void 0:a.categoryLabel,valueLabel:c?void 0:a.valueLabel,marginDefaults:st(l.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:c,mobileInteraction:ot(a.mobileInteraction,{mode:s,width:a.width??u,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(s,{...a.layout?.modeDefaults,...FM(t,DM),...pt(e)&&{responsiveRules:void 0}},function(e){return Object.prototype.hasOwnProperty.call(ht,e)?ht[e]:void 0}(e)??a.layout?.primarySize),{data:c,theme:u,background:d,className:h,annotations:p,margin:f,colorScheme:g,colorBy:m,legendPosition:y,...x}=t,{width:b,height:v}=l,w=[b,v],S=x.frameProps||{},k=a.layout?.margin,A="function"==typeof k?k(t,l):k??l.marginDefaults,M="xy"===a.frameType?Ee(A,x.axes??S.axes,!!l.title):A,$=void 0!==f?f:S.margin,_=function(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};let t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}($),P="number"==typeof $?{top:$,right:$,bottom:$,left:$}:{...M,..._},I=FM(x,NM),T=e=>S[e]??l[e],L={...S,...I,theme:u,title:l.title,description:l.description,showAxes:T("showAxes"),showLegend:T("showLegend"),showLabels:T("showLabels"),showGrid:T("showGrid"),xLabel:T("xLabel"),yLabel:T("yLabel"),categoryLabel:T("categoryLabel"),valueLabel:T("valueLabel"),background:d??S.background,className:h,annotations:p,size:w,margin:P,__resolvedMode:l.mode,__compactMode:l.compactMode,__explicitMarginSides:"number"==typeof $?["top","right","bottom","left"]:Object.keys(_??{}),__autoLegendMargin:!0,...void 0!==g&&{colorScheme:g},...void 0!==y&&{legendPosition:y},_idPrefix:x._idPrefix},C=a.buildProps(c,m,g,L,x);if(a.renderStatic)o=a.renderStatic(C,n);else switch(a.frameType){case"xy":o=iu(C,n);break;case"ordinal":o=uA(C,n);break;case"network":o=Lv(C,n);break;case"geo":o=cM(C,n);break;case"physics":o=tw({...C,physicsTheme:S.theme,frameBodyStyle:S.bodyStyle},n)}let R=a.renderOverlay?.(C,{theme:Pi(u)});if(null!=R){let e=St.renderToStaticMarkup(kM(SM,{children:R})),t=o.lastIndexOf("</svg>");o=t<0?`${o}${e}`:`${o.slice(0,t)}${e}${o.slice(t)}`}return{svg:RM(Je(o,i),r?.precision),frameType:a.resolveFrameType?.(C)??a.frameType}}(e,{...t,_idPrefix:o},o,i,r);return n=a.frameType,a.svg}),frameType:n}}function BM(e,t={}){return function(e,t,i){return El("dashboard",r=>function(e,t,i,r){let{title:n,subtitle:o,theme:a,width:s,height:l,layout:c={},background:u}=t,d=Ii(Pi(a)),h=et(s,1200),p=Math.max(1,Math.floor(et(c.columns,2))),f=Math.min("number"==typeof c.gap&&Number.isFinite(c.gap)&&c.gap>=0?c.gap:16,h/(p+1)),g=0;n&&(g+=30),o&&(g+=20),g>0&&(g+=10);let m=h-f,y=Math.floor((m-f*(p-1))/p),x=[],b=0,v=g+f,w=0;for(let t of e){let e=Math.min(Math.max(1,Math.floor(et(t.colSpan,1))),p),n=y*e+f*(e-1),o=et(t.props.height,300);b+e>p&&(v+=w+f,b=0,w=0);let s=f/2+b*(y+f),l={...t.props,width:n,height:o,theme:a,_idPrefix:`${r}-chart-${x.length}${t.props._idPrefix?`-${String(t.props._idPrefix).replace(/[^a-zA-Z0-9_-]/g,"_")}`:""}`},c=t.component?i.chart(t.component,l):t.frameType?i.frame(t.frameType,l):bM.renderToStaticMarkup(vM("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:o})),u=tt(c,{width:n,height:o}),d=Math.max(o,u.height);x.push({x:s,y:v,width:n,height:d,svg:c,svgDimensions:u}),w=Math.max(w,d),b+=e}let S=et(l,v+w+f),k=x.map((e,t)=>vM("g",{transform:`translate(${e.x},${e.y})`,dangerouslySetInnerHTML:{__html:Xe(it(e.svg,e.svgDimensions),{width:String(e.width),height:String(e.height),role:"group"})}},`dashboard-chart-${t}`));return bM.renderToStaticMarkup(wM("svg",{xmlns:"http://www.w3.org/2000/svg",width:h,height:S,role:"group","aria-label":n||"Dashboard","aria-describedby":o?`${r}-desc`:void 0,style:{fontFamily:d.fontFamily},children:[n&&vM("title",{children:n}),o&&vM("desc",{id:`${r}-desc`,children:o}),u&&vM("rect",{x:0,y:0,width:h,height:S,fill:u}),n&&vM("text",{x:h/2,y:24,textAnchor:"middle",fontSize:d.titleFontSize+4,fontWeight:d.titleFontWeight,fill:d.text,fontFamily:d.titleFontFamily,children:n}),o&&vM("text",{x:h/2,y:n?46:20,textAnchor:"middle",fontSize:d.labelSize,fill:d.textSecondary,fontFamily:d.fontFamily,children:o}),k]}))}(e,t,i,r))}(e,t,{chart:EM,frame:AM})}var jM=2*Math.PI,WM=e=>(e%jM+jM)%jM;function YM(e,t){let i=1-t;return i**3*e[0]+3*i*i*t*e[1]+3*i*t*t*e[2]+t**3*e[3]}function qM(e,t){let i=e.map(e=>e[0]),r=e.map(e=>e[1]);t(i[0],r[0]),t(i[3],r[3]);for(let e of[i,r]){let n=-e[0]+3*e[1]-3*e[2]+e[3],o=2*(e[0]-2*e[1]+e[2]),a=e[1]-e[0],s=Math.abs(n)<1e-12?0===o?[]:[-a/o]:o*o-4*n*a<0?[]:[(-o+Math.sqrt(o*o-4*n*a))/(2*n),(-o-Math.sqrt(o*o-4*n*a))/(2*n)];for(let e of s)e>0&&e<1&&t(YM(i,e),YM(r,e))}}function XM(e,t,i,r){let[n,o]=i.map(Math.abs);if(r(...e),r(...t),0===n||0===o||e[0]===t[0]&&e[1]===t[1])return;let a=i[2]*Math.PI/180,s=Math.cos(a),l=Math.sin(a),c=(e[0]-t[0])/2,u=(e[1]-t[1])/2,d=s*c+l*u,h=-l*c+s*u,p=Math.hypot(d/n,h/o);p>1&&(n*=p,o*=p);let f=(d/n)**2+(h/o)**2,g=(i[3]===i[4]?-1:1)*Math.sqrt(Math.max(0,(1-f)/f)),m=g*n*h/o,y=-g*o*d/n,x=s*m-l*y+(e[0]+t[0])/2,b=l*m+s*y+(e[1]+t[1])/2,v=Math.atan2((h-y)/o,(d-m)/n),w=Math.atan2((-h-y)/o,(-d-m)/n),S=i[4]?WM(w-v):-WM(v-w),k=Math.atan2(-o*l,n*s),A=Math.atan2(o*s,n*l);for(let e of[k,k+Math.PI,A,A+Math.PI])WM(S>=0?e-v:v-e)<=Math.abs(S)+1e-12&&r(x+n*s*Math.cos(e)-o*l*Math.sin(e),b+n*l*Math.cos(e)+o*s*Math.sin(e))}function GM(e){let t=0,i="",r="",n=[0,0],o=[0,0],a=[0,0],s=1/0,l=1/0,c=-1/0,u=-1/0,d=(e,t)=>{s=Math.min(s,e),l=Math.min(l,t),c=Math.max(c,e),u=Math.max(u,t)},h=()=>{for(;t<e.length&&/[\s,]/.test(e[t]);)t++},p=(i=!1)=>{h();let r=i?/^[01]/.exec(e.slice(t)):/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(t));return r?(t+=r[0].length,Number(r[0])):NaN};for(;t<e.length&&(h(),t!==e.length);){/[a-z]/i.test(e[t])&&(i=e[t++]);let s=i.toUpperCase(),l=i!==s;if(!r&&"M"!==s)return null;if("Z"===s){d(...n),d(...o),n=[...o],r="Z",i="";continue}let c={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7}[s];if(!c)return null;let u=Array.from({length:c},(e,t)=>p("A"===s&&(3===t||4===t)));if(!u.every(Number.isFinite))return null;let h=e=>[u[e]+(l?n[0]:0),u[e+1]+(l?n[1]:0)],f="H"===s?[u[0]+(l?n[0]:0),n[1]]:"V"===s?[n[0],u[0]+(l?n[1]:0)]:h(c-2),g=[2*n[0]-a[0],2*n[1]-a[1]];if("C"===s||"S"===s){let e="C"===s?h(0):/[CS]/.test(r)?g:n;a=h(c-4),qM([n,e,a,f],d)}else"Q"===s||"T"===s?(a="Q"===s?h(0):/[QT]/.test(r)?g:n,qM([n,[n[0]+2*(a[0]-n[0])/3,n[1]+2*(a[1]-n[1])/3],[f[0]+2*(a[0]-f[0])/3,f[1]+2*(a[1]-f[1])/3],f],d)):"A"===s?XM(n,f,u,d):"M"!==s&&(d(...n),d(...f));n=f,"M"===s&&(o=[...f],i=l?"l":"L"),r=s}return[s,l,c,u].every(Number.isFinite)?{x:s,y:l,w:c-s,h:u-l}:null}function VM(e){return[e.x,e.y,e.width,e.height].every(Number.isFinite)&&e.width>0&&e.height>0}function HM(e,t){let i,{width:r,height:n,view:o="fit",padding:a,bounds:s}=t;if(![r,n].every(e=>Number.isFinite(e)&&e>0))throw new Error("exportNetworkViewSVG requires finite positive width and height");if("fit"===o){let t=s??function(e){if(!e)return null;let t=[...e.htmlMarks??[]];for(let i of e.sceneNodes??[]){if("rect"===i.type){t.push({x:i.x,y:i.y,width:i.w,height:i.h});continue}let e;if("glyph"===i.type)e=p(i.glyph,i.size);else if("circle"===i.type)e=i.r;else if("arc"===i.type)e=i.outerR;else if(i.path||i.symbolType&&"circle"!==i.symbolType){let t=GM(c(i.symbolType,i.size,i.path));e=t?Math.hypot(Math.max(Math.abs(t.x),Math.abs(t.x+t.w)),Math.max(Math.abs(t.y),Math.abs(t.y+t.h))):u(i.size)}else e=u(i.size);t.push({x:i.cx-e,y:i.cy-e,width:2*e,height:2*e})}return function(e){let t=1/0,i=1/0,r=-1/0,n=-1/0;for(let o of e)!o||!VM(o)||(t=Math.min(t,o.x),i=Math.min(i,o.y),r=Math.max(r,o.x+o.width),n=Math.max(n,o.y+o.height));return t<1/0?{x:t,y:i,width:r-t,height:n-i}:null}(t)}(e);if(t&&!VM(t))throw new Error("exportNetworkViewSVG bounds must be finite with positive width and height");i=t?function(e,t,i,r=[Number.MIN_VALUE,Number.MAX_VALUE]){if(!VM(e)||t.width<=0||t.height<=0)return null;let{top:n,right:o,bottom:a,left:s}=function(e,t=0){let i=e=>Number.isFinite(e)?Math.max(0,e):t;if("object"!=typeof e||null===e){let t=i(e??void 0);return{top:t,right:t,bottom:t,left:t}}return{top:i(e.top),right:i(e.right),bottom:i(e.bottom),left:i(e.left)}}(i,24),l=Math.max(r[0],Math.min(r[1],Math.max(1,t.width-(s+o))/e.width,Math.max(1,t.height-(n+a))/e.height));return{k:l,x:t.x+(t.width+(s-o))/2-(e.x+e.width/2)*l,y:t.y+(t.height+(n-a))/2-(e.y+e.height/2)*l}}(t,{x:0,y:0,width:r,height:n},a)??void 0:void 0}else"identity"!==o&&(i=o);return Xe(EM("NetworkCustomChart",{width:r,height:n,margin:0,nodes:[],edges:[],layout:()=>({...e,restyle:void 0,restyleEdge:void 0}),frameProps:{viewTransform:i}}),{viewBox:`0 0 ${r} ${n}`})}import*as UM from"react-dom/server";import{jsx as ZM,jsxs as KM}from"react/jsx-runtime";function QM(e,t,i,r={}){let{stepSize:n,windowSize:o,frameCount:a,xExtent:s,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=r,p=i.width||600,f=i.height||400,g=Pi(i.theme),m={...i,...s&&{xExtent:s},...l&&{yExtent:l}};if(!t||0===t.length)return[];let y=a||Math.min(60,Math.max(10,t.length)),x=n||Math.max(1,Math.ceil(t.length/y)),b=[];for(let e=x;e<=t.length;e+=x)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);let v=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),w=ve({top:20,right:20,bottom:30,left:40,...i.margin},i.title),S=Math.max(1,p-w.left-w.right),k=Math.max(1,f-w.top-w.bottom),A=[];if(v)for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,s=t.slice(a,n),l={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:i.projection||"vertical",oAccessor:i.oAccessor||i.categoryAccessor||"category",rAccessor:i.rAccessor||i.valueAccessor||"value",colorAccessor:i.colorAccessor||i.colorBy,stackBy:i.stackBy,groupBy:i.groupBy,connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,barPadding:i.barPadding,innerRadius:i.innerRadius,normalize:i.normalize,bins:i.bins,colorScheme:i.colorScheme||g.colors.categorical,...h&&{decay:h}},c=new jk(l);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:S,height:k}),c.scene.length>0&&A.push(r$(c.scene,"ordinal",p,f,g,m,A.length))}else for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,y=t.slice(a,n),x={chartType:e,windowSize:y.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:i.colorAccessor||i.colorBy,groupAccessor:i.groupAccessor||i.lineBy,lineDataAccessor:i.lineDataAccessor,xExtent:s,yExtent:l,colorScheme:i.colorScheme||g.colors.categorical,lineStyle:i.lineStyle,pointStyle:i.pointStyle,areaStyle:i.areaStyle,sizeAccessor:i.sizeAccessor||i.sizeBy,sizeRange:i.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},v=new Co(x);if(v.ingest({inserts:y,bounded:!0}),v.computeScene({width:S,height:k}),0===v.scene.length)continue;let w=v.scales?.y;if(A.push(r$(v.scene,"xy",p,f,g,m,A.length,w)),c>0&&r>0&&v.activeTransition){let e=c*(1e3/u);for(let t=1;t<=c;t++){let i=t/c,r=v.activeTransition.startTime+i*e;v.advanceTransition(r),A.push(r$(v.scene,"xy",p,f,g,m,A.length,w))}}}return A}function JM(e,t,i={}){return t.map((t,r)=>{try{return EM(e,{...i,...t})}catch(n){return"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Failed to render snapshot ${r} for ${e}.`,n),`<svg xmlns="http://www.w3.org/2000/svg" width="${et(t.width,et(i.width,600))}" height="${et(t.height,et(i.height,400))}"></svg>`}})}function e$(e,t,i,r){let n=dc(`${e}-${t}`),o="string"==typeof i&&i.length>0?i:void 0,a="string"==typeof r&&r.length>0?r:void 0,s=o?n.titleId:void 0,l=a?n.descId:void 0;return{titleText:o,descText:a,titleId:s,descId:l,labelledBy:[s,l].filter(Boolean).join(" ")||void 0}}function t$(e,t,i){let r=t.size??[t.width??600,t.height??400],n=Pi(t.theme),o=Ii(n),a=t.background||n.colors.background,s=t.idPrefix??"physics-gif",l=e$(s,i,t.title,t.description),{titleId:c,descId:u,labelledBy:d}=l,h=e.readBodies(),p=e.viewTransform(),f=Fv(h,{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),g=KM("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,role:"img","aria-labelledby":d,style:{fontFamily:o.fontFamily},children:[t.title&&ZM("title",{id:c,children:t.title}),t.description&&ZM("desc",{id:u,children:t.description}),a&&"transparent"!==a?ZM("rect",{x:0,y:0,width:r[0],height:r[1],fill:a}):null,ZM("g",{id:`${s}-frame-${i}`,transform:p.x||p.y?`translate(${p.x},${p.y})`:void 0,children:f.map((e,t)=>wh(h[t],e.style??{},t,`${s}-${i}`)??is(e,t,`${s}-${i}`))})]});return UM.renderToStaticMarkup(g)}function i$(e,t={}){let{fps:i=12,frameCount:r,durationSeconds:n=2,includeInitialFrame:o=!0,stepDt:a,stepsPerFrame:s,background:l}=t,c=Math.max(.001,a??e.config?.fixedDt??1/120),u=s??Math.max(1,Math.round(1/Math.max(1,i)/c)),d=r??Math.max(1,Math.ceil(n*Math.max(1,i))),h=l?{...e,background:l}:e,p=new Nf(e.config);e.initialSpawns?.length&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);let f=[];for(o&&(p.tick(0),f.push(t$(p,h,0)));f.length<d;){for(let e=0;e<u;e+=1)p.tick(c);f.push(t$(p,h,f.length))}return f}function r$(e,t,i,r,n,o,a,s){let l=Ii(n),c=ve({top:20,right:20,bottom:30,left:40,...o.margin},o.title),u="ordinal"===t&&"radial"===o.projection,d=u?c.left+(i-c.left-c.right)/2:c.left,h=u?c.top+(r-c.top-c.bottom)/2:c.top,p=function(e,t){let i=e.background||t.colors.background;return i&&"transparent"!==i?i:null}(o,n),f=o.renderMode,g="ordinal"===t?oA({nodes:e,renderMode:f,idPrefix:o.idPrefix}).map(e=>e.element):e.map((e,t)=>function(e){return ns(e).element}({node:e,index:t,renderMode:f,fallback:()=>is(e,t)})).filter(Boolean),m="xy"===t?function(e,t,i,r,n,o){if(!e||0===e.length)return null;let a=Ii(r),s=[];for(let r=0;r<e.length;r++){let l=e[r];if("y-threshold"===l.type&&null!=l.value){let e=null;if(o)e=o(l.value);else if(n){let[t,r]=n,o=r-t;if(0===o)continue;e=i-(l.value-t)/o*i}if(null==e)continue;let c=l.color||a.primary,u=l.strokeDasharray||"6,4",d=l.strokeWidth??1.5,h=l.labelPosition||"right";s.push(KM("g",{children:[ZM("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:d,strokeDasharray:u}),l.label&&ZM("text",{x:"left"===h?4:"center"===h?t/2:t-4,y:e<20?Math.min(i-4,e+16):e-5,textAnchor:"left"===h?"start":"center"===h?"middle":"end",fontSize:a.tickSize,fill:l.labelColor??c,fontFamily:a.fontFamily,children:l.label})]},`ann-${r}`))}}return s}(o.annotations,Math.max(1,i-c.left-c.right),Math.max(1,r-c.top-c.bottom),n,o.yExtent,s):null,{titleText:y,descText:x,titleId:b,descId:v,labelledBy:w}=e$(function(e){return"string"==typeof e.idPrefix&&e.idPrefix.length>0?e.idPrefix:Lc(e)}(o),a,o.title,o.description),S=KM("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,role:"img","aria-labelledby":w,style:{fontFamily:l.fontFamily},children:[y&&ZM("title",{id:b,children:y}),x&&ZM("desc",{id:v,children:x}),p&&ZM("rect",{x:0,y:0,width:i,height:r,fill:p}),KM("g",{transform:`translate(${d},${h})`,children:[m,g]}),y&&ZM("text",{x:i/2,y:22,textAnchor:"middle",fontSize:l.titleFontSize,fontWeight:l.titleFontWeight,fill:l.text,fontFamily:l.titleFontFamily,children:y})]});return UM.renderToStaticMarkup(S)}fa(),Mn=a;export{HM as exportNetworkViewSVG,QM as generateFrameSVGs,JM as generateFrameSequence,i$ as generatePhysicsFrameSVGs,EM as renderChart,OM as renderChartWithEvidence,BM as renderDashboard,PM as renderGeoToStaticSVG,_M as renderNetworkToStaticSVG,$M as renderOrdinalToStaticSVG,AM as renderToStaticSVG,MM as renderXYToStaticSVG,Pi as resolveTheme,RM as serializeSvgPrecision,Ii as themeStyles};