@synnaxlabs/pluto 0.33.1 → 0.33.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 (114) hide show
  1. package/dist/{Animated-CmYpn592.cjs → Animated-C7iWxEah.cjs} +1 -1
  2. package/dist/{Animated-BJ0Om9zo.js → Animated-VpxahF8t.js} +2 -2
  3. package/dist/{Item-CPt4Umh0.cjs → Item-C1_OE8IF.cjs} +1 -1
  4. package/dist/{Item-JN1-gBEw.js → Item-Dpra-3n6.js} +5 -5
  5. package/dist/{Keyboard-BwzZPKjx.cjs → Keyboard-BBOcinRN.cjs} +1 -1
  6. package/dist/{Keyboard-CBvQle7r.js → Keyboard-CpJQuX-J.js} +2 -2
  7. package/dist/LinePlot-Bwz2fEc0.cjs +34 -0
  8. package/dist/LinePlot-DHy70Cb7.js +6256 -0
  9. package/dist/{Link-my2OWRXu.js → Link-Ctlz9WUQ.js} +1 -1
  10. package/dist/{Link-mthAKDPf.cjs → Link-Cxj-3A6p.cjs} +1 -1
  11. package/dist/{List-C3bjnukf.cjs → List-CcTL6wlO.cjs} +1 -1
  12. package/dist/{List-B1BAwLaq.js → List-DF0kzXpr.js} +2 -2
  13. package/dist/{Pack-CxtceW7N.js → Pack-BAJwD-n2.js} +1 -1
  14. package/dist/{Pack-uflj5a28.cjs → Pack-DBtBeGnj.cjs} +1 -1
  15. package/dist/{Text-SLn1Qwzw.js → Text-D5o4o3OI.js} +5 -5
  16. package/dist/{Text-BvzGtwCB.cjs → Text-GGA7QNwA.cjs} +1 -1
  17. package/dist/{Toggle-CqrGlCW8.js → Toggle-CTjPdq8o.js} +953 -929
  18. package/dist/Toggle-Dim0E2D2.cjs +143 -0
  19. package/dist/{Video-DKosAU7v.cjs → Video-B3geSdOZ.cjs} +1 -1
  20. package/dist/{Video-o34bcpwh.js → Video-CXccd2Jl.js} +1 -1
  21. package/dist/{aggregator-CU9VgdUJ.cjs → aggregator-D6Mmsfj4.cjs} +21 -21
  22. package/dist/{aggregator-B36SA-20.js → aggregator-QFq5XDjf.js} +997 -961
  23. package/dist/align.cjs +1 -1
  24. package/dist/align.js +1 -1
  25. package/dist/button.cjs +1 -1
  26. package/dist/button.js +1 -1
  27. package/dist/color.cjs +1 -1
  28. package/dist/color.js +1 -1
  29. package/dist/{css-4MXuPP5v.cjs → css-CvXvQo39.cjs} +1 -1
  30. package/dist/{css-C8qHWSpT.js → css-DqBChhqm.js} +27 -5
  31. package/dist/css.cjs +1 -1
  32. package/dist/css.js +2 -2
  33. package/dist/dropdown.cjs +1 -1
  34. package/dist/dropdown.js +1 -1
  35. package/dist/ether.cjs +1 -1
  36. package/dist/ether.js +5 -5
  37. package/dist/{external-GxvuofB_.js → external-BNMsCMKL.js} +11 -11
  38. package/dist/{external-BLnPpmeS.cjs → external-BPnNv3RZ.cjs} +1 -1
  39. package/dist/{external-B5jyXhgU.cjs → external-BZpriFW_.cjs} +1 -1
  40. package/dist/{external-BvoBhRW8.cjs → external-Bksh4jhY.cjs} +1 -1
  41. package/dist/{external-euVgbl49.js → external-Bm3VKQxs.js} +4 -4
  42. package/dist/{external-D6YTf7Kx.cjs → external-C2YHV6Dz.cjs} +1 -1
  43. package/dist/{external-BT_oycNI.js → external-CI2s6wrc.js} +90 -88
  44. package/dist/external-CK8msIo3.js +96 -0
  45. package/dist/{external-DYwzKoQ6.js → external-CKp_fJJC.js} +2 -2
  46. package/dist/{external-Cb_NFNiX.cjs → external-CKuO-iHz.cjs} +1 -1
  47. package/dist/{external-Crturtt-.cjs → external-CUwDGrme.cjs} +1 -1
  48. package/dist/{external-B0o5Z8wI.js → external-CfOulkkd.js} +5 -5
  49. package/dist/{external-CPTY4-IY.cjs → external-ClRKAhnQ.cjs} +1 -1
  50. package/dist/{external-BKx-fjB8.js → external-Ct326ec4.js} +2 -2
  51. package/dist/{external-BTFW7AEo.js → external-DT1bMgJw.js} +2 -2
  52. package/dist/{external-C-xh9EwI.cjs → external-DYc6fMZC.cjs} +1 -1
  53. package/dist/external-Dhg4bEfF.cjs +1 -0
  54. package/dist/{external-Cewuz6Gm.js → external-DmLFwKtu.js} +4 -4
  55. package/dist/{external-DqwISR2q.js → external-DyAGPLil.js} +5 -5
  56. package/dist/{external-Cc1Bqjmm.js → external-EHlrAzYc.js} +1 -1
  57. package/dist/external-X9NMQ2Zh.cjs +1 -0
  58. package/dist/{external-CLKqHc4s.cjs → external-aTGyndBd.cjs} +1 -1
  59. package/dist/{external-BBGGwc9H.cjs → external-e143l3cy.cjs} +1 -1
  60. package/dist/{external-DVhxMa2A.js → external-mRJloDDi.js} +7 -7
  61. package/dist/header.cjs +1 -1
  62. package/dist/header.js +1 -1
  63. package/dist/index.cjs +33 -1
  64. package/dist/index.js +9765 -4790
  65. package/dist/input.cjs +1 -1
  66. package/dist/input.js +1 -1
  67. package/dist/list.cjs +1 -1
  68. package/dist/list.js +1 -1
  69. package/dist/menu.cjs +1 -1
  70. package/dist/menu.js +1 -1
  71. package/dist/src/color/Swatch/Swatch.d.ts +2 -1
  72. package/dist/src/color/Swatch/Swatch.d.ts.map +1 -1
  73. package/dist/src/text/core/types.d.ts +2 -0
  74. package/dist/src/text/core/types.d.ts.map +1 -1
  75. package/dist/src/theming/core/fontString.d.ts +7 -1
  76. package/dist/src/theming/core/fontString.d.ts.map +1 -1
  77. package/dist/src/vis/diagram/Diagram.d.ts +1 -0
  78. package/dist/src/vis/diagram/Diagram.d.ts.map +1 -1
  79. package/dist/src/vis/diagram/aether/Diagram.d.ts +0 -2
  80. package/dist/src/vis/diagram/aether/Diagram.d.ts.map +1 -1
  81. package/dist/src/vis/legend/Simple.d.ts.map +1 -1
  82. package/dist/src/vis/lineplot/aether/axis.d.ts.map +1 -1
  83. package/dist/src/vis/render/loop.d.ts +7 -4
  84. package/dist/src/vis/render/loop.d.ts.map +1 -1
  85. package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
  86. package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
  87. package/dist/src/vis/schematic/primitives/Primitives.d.ts +2 -1
  88. package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
  89. package/dist/src/vis/value/aether/value.d.ts +11 -9
  90. package/dist/src/vis/value/aether/value.d.ts.map +1 -1
  91. package/dist/src/vis/value/use.d.ts +1 -0
  92. package/dist/src/vis/value/use.d.ts.map +1 -1
  93. package/dist/style.css +1 -1
  94. package/dist/tabs.cjs +1 -1
  95. package/dist/tabs.js +1 -1
  96. package/dist/text.cjs +1 -1
  97. package/dist/text.js +2 -2
  98. package/dist/theming.cjs +1 -1
  99. package/dist/theming.js +2 -2
  100. package/dist/tree.cjs +1 -1
  101. package/dist/tree.js +1 -1
  102. package/dist/triggers.cjs +1 -1
  103. package/dist/triggers.js +1 -1
  104. package/dist/{units-DbfWaeE2.cjs → units-6W_8ukD-.cjs} +1 -1
  105. package/dist/{units-CmWU_YzJ.js → units-BHSMvrYX.js} +1 -1
  106. package/dist/video.cjs +1 -1
  107. package/dist/video.js +1 -1
  108. package/package.json +3 -3
  109. package/dist/LinePlot-CgkhTRJT.js +0 -11256
  110. package/dist/LinePlot-oIHuM9Jz.cjs +0 -66
  111. package/dist/Toggle-GvJ5CkHq.cjs +0 -143
  112. package/dist/external-B7W7NBGN.cjs +0 -1
  113. package/dist/external-BQMz5fJB.cjs +0 -1
  114. package/dist/external-f7xyI5mJ.js +0 -94
@@ -1 +1 @@
1
- "use strict";const o=require("./jsx-runtime-Cek9Ww4S.cjs"),i=require("./Toggle-GvJ5CkHq.cjs"),e=require("./css-4MXuPP5v.cjs"),t=({enabledLoc:n,disabledLoc:r,enabled:s})=>o.jsxRuntimeExports.jsx(i.Qt.Caret.Up,{className:e.CSS(e.CSS.B("caret-animated"),e.CSS.loc(s?n:r))}),a=Object.freeze(Object.defineProperty({__proto__:null,Animated:t},Symbol.toStringTag,{value:"Module"}));exports.Animated=t;exports.Animated$1=a;
1
+ "use strict";const o=require("./jsx-runtime-Cek9Ww4S.cjs"),i=require("./Toggle-Dim0E2D2.cjs"),e=require("./css-CvXvQo39.cjs"),t=({enabledLoc:n,disabledLoc:r,enabled:s})=>o.jsxRuntimeExports.jsx(i.Qt.Caret.Up,{className:e.CSS(e.CSS.B("caret-animated"),e.CSS.loc(s?n:r))}),a=Object.freeze(Object.defineProperty({__proto__:null,Animated:t},Symbol.toStringTag,{value:"Module"}));exports.Animated=t;exports.Animated$1=a;
@@ -1,6 +1,6 @@
1
1
  import { j as r } from "./jsx-runtime-B6kdoens.js";
2
- import { Q as m } from "./Toggle-CqrGlCW8.js";
3
- import { C as t } from "./css-C8qHWSpT.js";
2
+ import { Q as m } from "./Toggle-CTjPdq8o.js";
3
+ import { C as t } from "./css-DqBChhqm.js";
4
4
  const s = ({ enabledLoc: e, disabledLoc: o, enabled: a }) => /* @__PURE__ */ r.jsx(
5
5
  m.Caret.Up,
6
6
  {
@@ -1 +1 @@
1
- "use strict";const i=require("./jsx-runtime-Cek9Ww4S.cjs"),R=require("./Pack-uflj5a28.cjs"),k=require("./Toggle-GvJ5CkHq.cjs"),q=require("./Link-mthAKDPf.cjs"),s=require("./css-4MXuPP5v.cjs"),d=require("react"),v=require("./Text-BvzGtwCB.cjs"),I=d.createContext({onClick:()=>{},selected:""}),j=()=>d.useContext(I),M=({children:x,onChange:e,level:c,iconSpacing:r,value:t=""})=>{const o=d.useCallback(n=>{typeof e=="function"?e(n):e&&n in e&&e[n](n)},[e]),u=d.useMemo(()=>({onClick:o,selected:t,level:c,iconSpacing:r}),[t,o,c,r]);return i.jsxRuntimeExports.jsx(I.Provider,{value:u,children:x})},B=()=>i.jsxRuntimeExports.jsx(k.Divider,{direction:"x",padded:!0}),g=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,level:l="p",iconSpacing:a}=j(),S=p=>{n(e),t==null||t(p)},C=m===e;return i.jsxRuntimeExports.jsx(k.Button,{level:l,...u,noWrap:!0,onClick:S,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(C),r),size:o??a,endIcon:c&&i.jsxRuntimeExports.jsx(R.Space,{className:s.CSS(s.CSS.BE("menu-item","trigger")),direction:"x",size:.5,children:i.jsxRuntimeExports.jsx(v.Text,{level:l,trigger:c})})})},z=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,iconSpacing:l}=j(),a=C=>{n(e),t==null||t(C)},S=m===e;return i.jsxRuntimeExports.jsx(k.Icon,{...u,onClick:a,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(S),r),size:o??l})},N=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,level:l="p",iconSpacing:a}=j(),S=p=>{n(e),t==null||t(p)},C=m===e;return i.jsxRuntimeExports.jsx(q.Link,{level:l,...u,noWrap:!0,onClick:S,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(C),r),size:o??a,endIcon:c&&i.jsxRuntimeExports.jsx(R.Space,{className:s.CSS(s.CSS.BE("menu-item","trigger")),direction:"x",size:.5,children:i.jsxRuntimeExports.jsx(v.Text,{level:l,trigger:c})})})},E=g;E.Icon=z;E.Link=N;exports.CoreItem=g;exports.Divider=B;exports.Item=E;exports.ItemIcon=z;exports.ItemLink=N;exports.Menu=M;exports.MenuContext=I;exports.useMenuContext=j;
1
+ "use strict";const i=require("./jsx-runtime-Cek9Ww4S.cjs"),R=require("./Pack-DBtBeGnj.cjs"),k=require("./Toggle-Dim0E2D2.cjs"),q=require("./Link-Cxj-3A6p.cjs"),s=require("./css-CvXvQo39.cjs"),d=require("react"),v=require("./Text-GGA7QNwA.cjs"),I=d.createContext({onClick:()=>{},selected:""}),j=()=>d.useContext(I),M=({children:x,onChange:e,level:c,iconSpacing:r,value:t=""})=>{const o=d.useCallback(n=>{typeof e=="function"?e(n):e&&n in e&&e[n](n)},[e]),u=d.useMemo(()=>({onClick:o,selected:t,level:c,iconSpacing:r}),[t,o,c,r]);return i.jsxRuntimeExports.jsx(I.Provider,{value:u,children:x})},B=()=>i.jsxRuntimeExports.jsx(k.Divider,{direction:"x",padded:!0}),g=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,level:l="p",iconSpacing:a}=j(),S=p=>{n(e),t==null||t(p)},C=m===e;return i.jsxRuntimeExports.jsx(k.Button,{level:l,...u,noWrap:!0,onClick:S,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(C),r),size:o??a,endIcon:c&&i.jsxRuntimeExports.jsx(R.Space,{className:s.CSS(s.CSS.BE("menu-item","trigger")),direction:"x",size:.5,children:i.jsxRuntimeExports.jsx(v.Text,{level:l,trigger:c})})})},z=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,iconSpacing:l}=j(),a=C=>{n(e),t==null||t(C)},S=m===e;return i.jsxRuntimeExports.jsx(k.Icon,{...u,onClick:a,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(S),r),size:o??l})},N=x=>{const{itemKey:e,trigger:c,className:r,onClick:t,size:o,...u}=x,{onClick:n,selected:m,level:l="p",iconSpacing:a}=j(),S=p=>{n(e),t==null||t(p)},C=m===e;return i.jsxRuntimeExports.jsx(q.Link,{level:l,...u,noWrap:!0,onClick:S,variant:"text",className:s.CSS(s.CSS.B("menu-item"),s.CSS.selected(C),r),size:o??a,endIcon:c&&i.jsxRuntimeExports.jsx(R.Space,{className:s.CSS(s.CSS.BE("menu-item","trigger")),direction:"x",size:.5,children:i.jsxRuntimeExports.jsx(v.Text,{level:l,trigger:c})})})},E=g;E.Icon=z;E.Link=N;exports.CoreItem=g;exports.Divider=B;exports.Item=E;exports.ItemIcon=z;exports.ItemLink=N;exports.Menu=M;exports.MenuContext=I;exports.useMenuContext=j;
@@ -1,10 +1,10 @@
1
1
  import { j as i } from "./jsx-runtime-B6kdoens.js";
2
- import { S as f } from "./Pack-CxtceW7N.js";
3
- import { m as z, B as N, I as g } from "./Toggle-CqrGlCW8.js";
4
- import { L as B } from "./Link-my2OWRXu.js";
5
- import { C as s } from "./css-C8qHWSpT.js";
2
+ import { S as f } from "./Pack-BAJwD-n2.js";
3
+ import { m as z, B as N, I as g } from "./Toggle-CTjPdq8o.js";
4
+ import { L as B } from "./Link-Ctlz9WUQ.js";
5
+ import { C as s } from "./css-DqBChhqm.js";
6
6
  import { createContext as S, useContext as M, useCallback as L, useMemo as D } from "react";
7
- import { T as j } from "./Text-SLn1Qwzw.js";
7
+ import { T as j } from "./Text-D5o4o3OI.js";
8
8
  const I = S({
9
9
  onClick: () => {
10
10
  },
@@ -1 +1 @@
1
- "use strict";const c=require("./jsx-runtime-Cek9Ww4S.cjs"),o=require("./Toggle-GvJ5CkHq.cjs"),t=require("./css-4MXuPP5v.cjs"),i=({className:e,level:s,...r})=>c.jsxRuntimeExports.jsx(o.Text,{className:t.CSS(e,t.CSS.BM("text","keyboard")),level:s,style:{width:`calc(var(--pluto-${s}-size) * 1.7)`,height:`calc(var(--pluto-${s}-size) * 1.7)`},...r});exports.Keyboard=i;
1
+ "use strict";const c=require("./jsx-runtime-Cek9Ww4S.cjs"),o=require("./Toggle-Dim0E2D2.cjs"),t=require("./css-CvXvQo39.cjs"),i=({className:e,level:s,...r})=>c.jsxRuntimeExports.jsx(o.Text,{className:t.CSS(e,t.CSS.BM("text","keyboard")),level:s,style:{width:`calc(var(--pluto-${s}-size) * 1.7)`,height:`calc(var(--pluto-${s}-size) * 1.7)`},...r});exports.Keyboard=i;
@@ -1,6 +1,6 @@
1
1
  import { j as r } from "./jsx-runtime-B6kdoens.js";
2
- import { i } from "./Toggle-CqrGlCW8.js";
3
- import { C as o } from "./css-C8qHWSpT.js";
2
+ import { i } from "./Toggle-CTjPdq8o.js";
3
+ import { C as o } from "./css-DqBChhqm.js";
4
4
  const c = ({
5
5
  className: s,
6
6
  level: t,
@@ -0,0 +1,34 @@
1
+ "use strict";var ha=Object.defineProperty;var da=(n,e,t)=>e in n?ha(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>da(n,typeof e!="symbol"?e+"":e,t);const d=require("./aggregator-D6Mmsfj4.cjs"),p=require("zod"),o=require("./css-CvXvQo39.cjs");var fa=Object.defineProperty,pa=(n,e,t)=>e in n?fa(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,qe=(n,e,t)=>pa(n,typeof e!="symbol"?e+"":e,t);class ga{constructor(e,t){qe(this,"handlers"),qe(this,"transform"),qe(this,"closer"),this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[s,r]=this.transform(e);if(!r)return;t=s}this.handlers.forEach((s,r)=>r(t))}setCloser(e){this.closer=e}async close(){var e;return await((e=this.closer)==null?void 0:e.call(this))}}class ma{constructor(e){qe(this,"handlers"),this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,s)=>s(e))}}const Xn=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:ma,Observer:ga},Symbol.toStringTag,{value:"Module"})),ya=p.z.object({props:d.Zf.nullable(),state:d.Lf.connectivity.connectionStateZ.nullable()}),Vn={synnax:null,state:d.Lf.connectivity.DEFAULT};var ot;let Ze=(ot=class extends d.Composite{constructor(){super(...arguments);u(this,"schema",ot.stateZ)}async afterUpdate(){var t;if(this.ctx.has(Kn)||Pn(this.ctx,Vn),this.state.props==null){this.internal.synnax!=null&&(this.setState(s=>({...s,state:d.Lf.connectivity.DEFAULT})),(t=this.internal.synnax)==null||t.close(),this.internal.synnax=null),Pn(this.ctx,this.internal);return}this.prevState.props!=null&&d._.equal(this.state.props,this.prevState.props)&&this.internal.synnax!=null||(this.internal.synnax=new d.Lf(this.state.props),this.internal.synnax.connectivity.onChange(s=>this.setState(r=>({...r,state:s}))),Pn(this.ctx,this.internal))}},u(ot,"TYPE","SynnaxProvider"),u(ot,"stateZ",ya),ot);const Kn="pluto-client-context",Pn=(n,e)=>n.set(Kn,e),Se=n=>n.get(Kn).synnax,dr={[Ze.TYPE]:Ze},wa=Object.freeze(Object.defineProperty({__proto__:null,Provider:Ze,REGISTRY:dr,ZERO_CONTEXT_VALUE:Vn,use:Se},Symbol.toStringTag,{value:"Module"})),fr="pluto-telem-context",vn=n=>n.get(fr),pr=(n,e)=>n.set(fr,e),gr=(n,e)=>vn(n).registerFactory(e);class zs{constructor(e,t,s){u(this,"spec");u(this,"wrapped");u(this,"prevKey");this.wrapped=e,this.spec=s,this.prevKey=t.clusterKey}async value(){return await this.wrapped.value()}async cleanup(){var e,t;await((t=(e=this.wrapped).cleanup)==null?void 0:t.call(e))}onChange(e){return this.wrapped.onChange(e)}shouldUpdate(e,t){return this.prevKey!==e.clusterKey||!d._.equal(this.spec,t)}}class Ys{constructor(e,t,s){u(this,"spec");u(this,"prov");u(this,"prevKey");u(this,"wrapped");this.wrapped=e,this.spec=s,this.prov=t,this.prevKey=t.clusterKey}async set(e){return await this.wrapped.set(e)}async cleanup(){var e,t;await((t=(e=this.wrapped).cleanup)==null?void 0:t.call(e))}shouldUpdate(e,t){return this.prevKey!==e.clusterKey||!d._.equal(this.spec,t)}}const X=async(n,e,t)=>{var r;const s=vn(n);if(t instanceof zs){if(!t.shouldUpdate(s,e))return t;await((r=t.cleanup)==null?void 0:r.call(t))}return new zs(s.create(e),s,e)},Ee=async(n,e,t)=>{var r;const s=vn(n);if(t instanceof Ys){if(!t.shouldUpdate(s,e))return t;await((r=t.cleanup)==null?void 0:r.call(t))}return new Ys(s.create(e),s,e)};class lt extends Xn.Observer{async cleanup(){}}class Be extends lt{async set(){return await Promise.resolve()}}u(Be,"TYPE","noop-boolean-sink");const bn={type:Be.TYPE,props:{},variant:"sink",valueType:"boolean"};class Ne extends lt{async set(){return await Promise.resolve()}}u(Ne,"TYPE","noop-numeric-sink");const mr={type:Ne.TYPE,props:{},variant:"sink",valueType:"number"};class Ue extends lt{async value(){return await Promise.resolve(!1)}}u(Ue,"TYPE","noop-boolean-source");const Jn={type:Ue.TYPE,props:{},variant:"source",valueType:"boolean"};class Fe extends lt{async value(){return 0}}u(Fe,"TYPE","noop-numeric-source");const yr={type:Fe.TYPE,props:{},variant:"source",valueType:"number"};class Ge extends lt{async value(){return""}}u(Ge,"TYPE","noop-string-source");const wr={type:Ge.TYPE,props:{},variant:"source",valueType:"string"};class je extends lt{async value(){return{key:"noop",variant:"disabled",message:"unknown",time:d.m.now()}}}u(je,"TYPE","noop-status-source");const Qn={type:je.TYPE,props:{},variant:"source",valueType:"status"};class He extends lt{async value(){return o.ZERO}}u(He,"TYPE","noop-color-source");const xr={type:He.TYPE,props:{},variant:"source",valueType:"color"};class We extends lt{async value(){return[o.G.ZERO,[]]}}u(We,"TYPE","noop-series");const vr={type:We.TYPE,props:{},variant:"source",valueType:"series"},xa={[Be.TYPE]:Be,[Ne.TYPE]:Ne,[Ue.TYPE]:Ue,[Fe.TYPE]:Fe,[je.TYPE]:je,[He.TYPE]:He,[Ge.TYPE]:Ge,[We.TYPE]:We};class br{constructor(){u(this,"type","noop")}create(e){const t=xa[e.type];return t==null?null:new t}}const va=p.z.instanceof(ArrayBuffer),Ce=p.z.object({type:p.z.string(),variant:p.z.enum(["source","sink","source-transformer","sink-transformer"]),valueType:p.z.string(),props:p.z.any(),transfer:p.z.array(va).optional()}),ct=Ce.extend({variant:p.z.literal("source")}),Tn=Ce.extend({variant:p.z.literal("sink")}),Tr=Ce.extend({variant:p.z.literal("source-transformer")}),Sr=Ce.extend({variant:p.z.literal("sink-transformer")}),Xe=ct.extend({valueType:p.z.literal("series")}),ts=ct.extend({valueType:p.z.literal("boolean")}),Sn=Tn.extend({valueType:p.z.literal("boolean")}),ba=Sr.extend({valueType:p.z.literal("boolean")}),Ta=Tr.extend({valueType:p.z.literal("boolean")}),Er=ct.extend({valueType:p.z.literal("number")}),Cr=Tn.extend({valueType:p.z.literal("number")}),Rr=ct.extend({valueType:p.z.literal("color")}),es=ct.extend({valueType:p.z.literal("status")}),kr=ct.extend({valueType:p.z.literal("string")});class En extends Xn.BaseObserver{constructor(t){super();u(this,"props_");u(this,"uProps_");u(this,"schema");this.uProps_=t}get props(){if(this.props_==null){const t=this._schema.safeParse(this.uProps_);if(t.success)this.props_=t.data;else throw new d.B(`[BaseTelem] - expected props to be valid, but found the following errors:
2
+ ${t.error.message}`)}return this.props_}get _schema(){if(this.schema==null)throw new d.B(`[BaseTelem] - expected subclass to define props schema, but none was found.
3
+ Make sure to define a property 'schema' on the class.`);return this.schema}async cleanup(){}}class G extends En{}class Cn extends En{}class Re extends G{constructor(){super(...arguments);u(this,"sources",{})}get source(){const[t]=Object.values(this.sources);if(t==null)throw new d.B("[UnarySourceTransformer] - expected source to exist, but none was found.");return t}async value(){return this.transform(await this.source.value())}onChange(t){return this.source.onChange(()=>{this.source.value().then(s=>{this.shouldNotify(s)&&t()}).catch(console.error)})}setSources(t){this.sources=t}shouldNotify(t){return!0}transform(t){throw new d.B(`[UnarySourceTransformer] - expected subclass to define transform method, but none was found.
4
+ Make sure to define a method 'transform' on the class.`)}}class Pr extends G{constructor(){super(...arguments);u(this,"sources",{})}async value(){const t=Object.fromEntries(await Promise.all(Object.entries(this.sources).map(async([s,r])=>[s,await r.value()])));return this.transform(t)}setSources(t){this.sources={...this.sources,...t}}transform(t){throw new d.B(`[MultiSourceTransformer] - expected subclass to define transform method, but none was found.
5
+ Make sure to define a method 'transform' on the class.`)}}class Or extends En{constructor(){super(...arguments);u(this,"sinks",{})}get sink(){const[t]=Object.values(this.sinks);if(t==null)throw new d.B("[UnarySinkTransformer] - expected sink to exist, but none was found.");return t}async set(t){return await this.sink.set(this.transform(t))}setSinks(t){this.sinks={...this.sinks,...t}}transform(t){throw new d.B(`[UnarySinkTransformer] - expected subclass to define transform method, but none was found.
6
+ Make sure to define a method 'transform' on the class.`)}}const zr=p.z.object({from:p.z.string(),to:p.z.string()}),ns=p.z.object({connections:p.z.array(zr),outlet:p.z.string(),segments:p.z.record(ct)});class Yr{constructor(e){u(this,"type","pipeline");u(this,"factory");this.factory=e}create(e){switch(e.type){case se.TYPE:return new se(e.props,this.factory);case re.TYPE:return new re(e.props,this.factory);default:return null}}}class se extends G{constructor(t,s){super(t);u(this,"schema",ns);u(this,"sources",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sources[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sources[a],h=this.sources[l];c==null||h==null||"setSources"in h&&h.setSources({[a]:c})})}get outlet(){const{outlet:t}=this.props,s=this.sources[t];if(s==null)throw new d.B(`[SourcePipeline] - expected source to exist at outlet '${t}', but none was found.`);return s}async value(){return await this.outlet.value()}onChange(t){return this.outlet.onChange(t)}async cleanup(){await Promise.all(Object.values(this.sources).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(se,"TYPE","source-pipeline");const Mr=(n,e)=>({variant:"source",props:e,type:se.TYPE,valueType:n}),ss=p.z.object({connections:p.z.array(zr),inlet:p.z.string(),segments:p.z.record(Tn)});class re extends Cn{constructor(t,s){super(t);u(this,"schema",ss);u(this,"sinks",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sinks[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sinks[a],h=this.sinks[l];c==null||h==null||"setSinks"in c&&c.setSinks({[l]:h})})}get inlet(){const{inlet:t}=this.props,s=this.sinks[t];if(s==null)throw new d.B(`[SinkPipeline] - expected source to exist at inlet '${t}', but none was found.`);return s}async set(t){return await this.inlet.set(t)}async cleanup(){await Promise.all(Object.values(this.sinks).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(re,"TYPE","sink-pipeline");const Dr=(n,e)=>({variant:"sink",props:e,type:re.TYPE,valueType:n}),rs=p.z.object({channel:p.z.number().or(p.z.string())});class ie extends G{constructor(t,s){super(s);u(this,"client");u(this,"removeStreamHandler",null);u(this,"channelKey",0);u(this,"schema",rs);u(this,"leadingBuffer",null);u(this,"valid",!1);this.client=t}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}async cleanup(){var t,s;await((t=this.removeStreamHandler)==null?void 0:t.call(this)),this.valid=!1,(s=this.leadingBuffer)==null||s.release(),this.leadingBuffer=null,this.removeStreamHandler=null}async value(){return d.w$1(this.props.channel)||(this.channelKey===0&&(this.channelKey=(await is(this.client,this.props.channel,!1)).key),this.valid||await this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0)?0:this.leadingBuffer.at(-1,!0)}async read(){this.valid=!0,await this.updateStreamHandler()}async updateStreamHandler(){var s;await((s=this.removeStreamHandler)==null?void 0:s.call(this));const t=r=>{var l;const a=r[this.channelKey].data;if(a.length!==0){const c=a[a.length-1];c.acquire(),(l=this.leadingBuffer)==null||l.release(),this.leadingBuffer=c}this.notify()};this.removeStreamHandler=await this.client.stream(t,[this.channelKey])}}u(ie,"TYPE","stream-channel-value");const is=async(n,e,t)=>{const s=await n.retrieveChannel(e);return!t||s.isIndex?{key:s.key,dataType:s.dataType,virtual:s.virtual}:{key:s.index,dataType:d.g.TIMESTAMP,virtual:!1}},Sa=p.z.object({timeRange:d.E.z,channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1)});class ae extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"valid",!1);u(this,"schema",Sa);this.client=t}async cleanup(){this.data.forEach(t=>t.release()),this.valid=!1}async value(){const{timeRange:t,channel:s,useIndexOfChannel:r}=this.props;if(t.isZero||s===0)return[o.G.ZERO,[]];const i=await is(this.client,s,r);this.valid||await this.readFixed(i.key);let a=o.G.max(this.data.map(l=>l.bounds));return i.dataType.equals(d.g.TIMESTAMP)&&(a={upper:Math.min(a.upper,Number(this.props.timeRange.end.valueOf())),lower:Math.max(a.lower,Number(this.props.timeRange.start.valueOf()))}),[a,this.data]}async readFixed(t){const r=(await this.client.read(this.props.timeRange,[t]))[t].data;r.forEach(i=>i.acquire()),this.data=r,this.valid=!0}}u(ae,"TYPE","series-source");const Ea=p.z.object({channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1),timeSpan:d.y.z,keepFor:d.y.z.optional()});class oe extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"stopStreaming");u(this,"valid",!1);u(this,"schema",Ea);this.client=t}async value(){const{channel:t,useIndexOfChannel:s,timeSpan:r}=this.props;if(t===0)return[o.G.ZERO,[]];const i=d.m.now(),a=await is(this.client,t,s);if(this.valid||await this.read(a),a.dataType.isVariable)return[o.G.ZERO,this.data];let l=o.G.max(this.data.filter(c=>c.timeRange.end.after(i.sub(r))).map(c=>c.bounds));return a.dataType.equals(d.g.TIMESTAMP)&&(l={upper:l.upper,lower:Math.max(l.lower,l.upper-Number(r.valueOf()))}),[l,this.data]}async read({key:t,virtual:s}){const r=d.m.now().spanRange(-this.props.timeSpan);if(!s){const a=(await this.client.read(r,[t]))[t].data;a.forEach(l=>l.acquire()),this.data.push(...a)}await this.updateStreamHandler(t),this.valid=!0}async updateStreamHandler(t){this.stopStreaming!=null&&await this.stopStreaming();const s=r=>{const i=r[t].data;i.forEach(a=>a.acquire()),this.data.push(...i),this.gcOutOfRangeData(),this.notify()};this.stopStreaming=await this.client.stream(s,[t])}gcOutOfRangeData(){const t=d.m.now().sub(this.props.keepFor??this.props.timeSpan),s=this.data.findIndex(r=>r.timeRange.end.before(t));s!==-1&&(this.data.splice(s,1).forEach(r=>r.release()),this.gcOutOfRangeData())}async cleanup(){var t;await((t=this.stopStreaming)==null?void 0:t.call(this)),this.stopStreaming=void 0,this.data.forEach(s=>s.release())}}u(oe,"TYPE","dynamic-series-source");const Ca={[ae.TYPE]:ae,[oe.TYPE]:oe,[ie.TYPE]:ie};class Ar{constructor(e){u(this,"type","remote");u(this,"client");this.client=e}create(e){const t=Ca[e.type];return t==null?null:new t(this.client,e.props)}}const Lr=n=>({type:ae.TYPE,props:n,variant:"source",valueType:"series"}),_r=n=>({type:oe.TYPE,props:n,variant:"source",valueType:"series"}),qr=n=>({type:ie.TYPE,props:n,variant:"source",valueType:"number"});class $r{constructor(){u(this,"type","static")}create(e){switch(e.type){case Ve.TYPE:return new Ve(e.props);case le.TYPE:return new le(e.props);case ce.TYPE:return new ce(e.props);case ue.TYPE:return new ue(e.props);default:return null}}}const as=p.z.object({data:p.z.array(d.xt),offsets:p.z.array(p.z.number()).optional().default([])});class Ve extends G{constructor(t){super(t);u(this,"data");u(this,"schema",as);this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){return[o.G.max(this.data.map(s=>s.bounds)),this.data]}}u(Ve,"TYPE","static-series");const Ir=as.extend({rate:d.P.z,yOffset:p.z.number().optional().default(0),scroll:p.z.number().optional().default(0),startPosition:p.z.number().optional().default(0),scrollBounds:p.z.boolean().optional().default(!1)});class le extends G{constructor(t){super(t);u(this,"schema",Ir);u(this,"position");u(this,"interval");u(this,"data");this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){const t=this.data.map(r=>r.slice(0,this.position));if(this.props.scrollBounds){const r=t[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=t[0].data[this.position-1];return[{lower:Number(r),upper:Number(i)},t]}return[o.G.max(t.map(r=>r.bounds)),t]}start(t){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{var s;(s=this.notify)==null||s.call(this),this.position++},t.period.milliseconds)}async cleanup(){clearInterval(this.interval),this.interval=void 0}}u(le,"TYPE","iterative-series");const Zr=p.z.number();class ce extends G{constructor(){super(...arguments);u(this,"schema",Zr)}async value(){return this.props}}u(ce,"TYPE","static-numeric");const Br=p.z.string();class ue extends G{constructor(){super(...arguments);u(this,"schema",Br)}async value(){return this.props}}u(ue,"TYPE","static-string");const Ra=n=>({type:Ve.TYPE,props:n,variant:"source",valueType:"series"}),ka=n=>({type:le.TYPE,props:n,variant:"source",valueType:"series"}),Pa=n=>({type:ce.TYPE,props:n,variant:"source",valueType:"number"}),Oa=n=>({type:ue.TYPE,props:n,variant:"source",valueType:"string"});class Nr{constructor(){u(this,"type","transformer")}create(e){switch(e.type){case Pt.TYPE:return new Pt(e.props);case Ot.TYPE:return new Ot(e.props);case zt.TYPE:return new zt(e.props);case Yt.TYPE:return new Yt(e.props);case Mt.TYPE:return new Mt(e.props);case Dt.TYPE:return new Dt(e.props)}return null}}const za=p.z.object({truthy:p.z.number().optional().default(1),falsy:p.z.number().optional().default(0)}),Ur=n=>({props:n,type:Pt.TYPE,variant:"sink",valueType:"boolean"}),Vt=class Vt extends Or{constructor(){super(...arguments);u(this,"schema",Vt.propsZ)}transform(t){return t?this.props.truthy:this.props.falsy}};u(Vt,"TYPE","boolean-numeric-converter-sink"),u(Vt,"propsZ",za);let Pt=Vt;const Ya=p.z.object({trueBound:o.G.bounds}),Fr=n=>({props:n,type:Ot.TYPE,variant:"source",valueType:"boolean"}),Kt=class Kt extends Re{constructor(){super(...arguments);u(this,"schema",Kt.propsZ);u(this,"curr",null)}shouldNotify(t){const s=o.G.contains(this.props.trueBound,t)!==this.curr;return this.curr=o.G.contains(this.props.trueBound,t),s}transform(t){return this.curr=o.G.contains(this.props.trueBound,t),this.curr}};u(Kt,"TYPE","boolean-source"),u(Kt,"propsZ",Ya);let Ot=Kt;const Gr=p.z.object({}),Jt=class Jt extends Pr{constructor(){super(...arguments);u(this,"schema",Jt.propsZ)}transform(t){return Object.values(t).reduce((s,r)=>s+r,0)/Object.keys(t).length}};u(Jt,"TYPE","mean"),u(Jt,"propsZ",Gr);let zt=Jt;const Ma=n=>({props:n,type:zt.TYPE,variant:"source",valueType:"boolean"}),jr=p.z.object({trueVariant:d.variantZ.optional().default("success")}),Qt=class Qt extends Re{constructor(){super(...arguments);u(this,"schema",Qt.propsZ)}transform(t){return t.variant===this.props.trueVariant}};u(Qt,"TYPE","boolean-status"),u(Qt,"propsZ",jr);let Yt=Qt;const Da=n=>({props:n,type:Yt.TYPE,variant:"source",valueType:"boolean"}),os=p.z.object({precision:p.z.number().optional().default(2),prefix:p.z.string().optional().default(""),suffix:p.z.string().optional().default("")}),te=class te extends Re{constructor(){super(...arguments);u(this,"schema",te.propsZ)}transform(t){return`${this.props.prefix}${t.toFixed(this.props.precision)}${this.props.suffix}`}};u(te,"TYPE","stringify-number"),u(te,"propsZ",os);let Mt=te;const Hr=n=>({props:n,type:Mt.TYPE,variant:"source",valueType:"string"}),ls=p.z.object({windowSize:p.z.number().optional().default(5)});class Dt extends Re{constructor(){super(...arguments);u(this,"schema",ls);u(this,"values",[])}transform(t){return this.props.windowSize<2?t:this.values.reduce((s,r)=>s+r,0)/this.values.length}shouldNotify(t){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(t),this.values.length===this.props.windowSize)}}u(Dt,"TYPE","rolling-average"),u(Dt,"propsZ",Gr);const Wr=n=>({props:n,type:Dt.TYPE,variant:"source",valueType:"number"});class Xr{constructor(e){u(this,"factories");u(this,"type","compound");this.factories=e}add(e){this.factories=[...this.factories.filter(t=>t.type!==e.type),e]}create(e){for(const t of this.factories){const s=t.create(e);if(s!=null)return s}return null}}const Vr=n=>{const e=[new Nr,new $r,new br],t=new Xr(e);return n!=null&&t.add(new Ar(n)),t.add(new Yr(t)),t},Kr=p.z.object({include:p.z.string().array().optional(),exclude:p.z.string().array().optional(),level:p.z.enum(d.g$1.LOG_LEVELS).optional().default("info")}),In="alamos-provider";var $n;let Zn=($n=class extends d.Composite{constructor(){super(...arguments);u(this,"schema",Kr)}async afterUpdate(){if(this.ctx.getOptional(In)!=null)return;const s=[],{include:r,exclude:i,level:a}=this.state;(r!=null||i!=null)&&s.push(d.g$1.logLevelKeyFiler({include:r,exclude:i})),a!=null&&s.push(d.g$1.logThresholdFilter(a)),s.length===0&&s.push(()=>!1),this.internal.ins=new d.g$1.Instrumentation({key:"aether",logger:new d.g$1.Logger({filters:s})}),this.ctx.set(In,this.internal.ins)}},u($n,"TYPE","AlamosProvider"),$n);const ke=(n,e)=>{const t=n.get(In);if(t==null)throw new Error("No instrumentation provider");return e==null?t:t.child(e)},Aa={[Zn.TYPE]:Zn},Jr=(n,e)=>n.dataType.isVariable?n:(e==null&&n.dataType.equals(d.g.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(d.g.FLOAT32,e)),Qr=()=>({purgedSeries:0,purgedBytes:d.x.bytes(0)}),ti={instrumentation:d.g$1.NOOP,staleEntryThreshold:d.y.seconds(20)};class La{constructor(e){u(this,"data",[]);u(this,"props");this.props={...ti,...e}}write(e){e.length!==0&&(e.forEach(t=>this.writeOne(Jr(t))),this.checkIntegrity(e))}dirtyRead(e){const t=this.data.filter(({data:a})=>a.timeRange.overlapsWith(e)).map(({data:a})=>a);if(t.length===0)return{series:[],gaps:[e]};const s=t.map((a,l)=>l===0?d.E.ZERO:new d.E(t[l-1].timeRange.end,a.timeRange.start)).filter(a=>!a.isZero&&a.isValid),r=new d.E(e.start,t[0].timeRange.start),i=new d.E(t[t.length-1].timeRange.end,e.end);return r.isValid&&!r.isZero&&s.unshift(r),i.isValid&&!i.isZero&&s.push(i),{series:t,gaps:s}}gc(){const{staleEntryThreshold:e}=this.props,t=Qr(),s=this.data.filter(r=>{const i=r.data.refCount>0||d.m.since(r.addedAt).lessThan(e);return i||(t.purgedBytes=t.purgedBytes.add(r.data.byteCapacity)),i});return t.purgedSeries=this.data.length-s.length,this.data=s,t}close(){this.data=[]}writeOne(e){const{instrumentation:{L:t}}=this.props;if(e.length===0)return;const s=o.G.buildInsertionPlan(this.data.map(c=>c.data.alignmentBounds),e.alignmentBounds);if(s===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(c=>c.data.digest)});const{removeBefore:r,removeAfter:i,insertInto:a,deleteInBetween:l}=s;e=e.slice(r,e.data.length-Number(i)),e.length!==0&&this.data.splice(a,l,{data:e,addedAt:d.m.now()})}checkIntegrity(e){const{instrumentation:{L:t}}=this.props,s=this.data.map(i=>i.data.alignmentBounds);if(s.some((i,a)=>s.some((l,c)=>a===c?!1:o.G.overlapsWith(i,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const _a=100,qa=1e6,$a=1e4,Ia=100,Za=40;class Ba{constructor(e){u(this,"props");u(this,"counter",0);u(this,"curr");u(this,"avgRate",0);u(this,"timeOfLastWrite");u(this,"totalWrites",0);u(this,"now",()=>d.m.now());this.props=e,this.curr=null,e.testingNow!=null&&(this.now=e.testingNow),this.timeOfLastWrite=this.now()}get length(){var e;return((e=this.curr)==null?void 0:e.length)??0}get leadingBuffer(){return this.curr}write(e){const t=e.flatMap(s=>this._write(s));return{flushed:t.flatMap(s=>s.flushed),allocated:t.flatMap(s=>s.allocated)}}allocate(e,t,s){this.counter++;const r=this.props.dataType.isVariable,i=this.props.dataType.equals(d.g.TIMESTAMP);return d.V.alloc({capacity:r?e*Za:e,dataType:r?this.props.dataType:d.g.FLOAT32,timeRange:s.range(d.m.MAX),sampleOffset:i?BigInt(s.valueOf()):0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),s={flushed:[],allocated:[]};if(this.curr==null)this.curr=this.allocate(t,e.alignment,this.now()),s.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-e.alignment))>1){const c=this.now();this.curr.timeRange.end=c,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,c),s.allocated.push(this.curr)}const r=Jr(e,this.curr.sampleOffset),i=this.curr.write(r);if(i===e.length)return this.updateAvgRate(e),s;const a=this.now();this.curr.timeRange.end=a,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment+BigInt(i),a),s.allocated.push(this.curr);const l=this._write(e.slice(i));return s.flushed.push(...l.flushed),s.allocated.push(...l.allocated),s}updateAvgRate(e){if(typeof this.props.dynamicBufferSize=="number")return;const t=e.length/this.now().span(this.timeOfLastWrite).seconds;this.totalWrites>0&&isFinite(t)&&t>0&&(this.avgRate=(this.avgRate*(this.totalWrites-1)+t)/this.totalWrites),this.totalWrites++,this.timeOfLastWrite=this.now()}nextBufferSize(){const{dynamicBufferSize:e}=this.props;if(typeof e=="number")return e;if(this.totalWrites<Ia)return $a;const t=o.W.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,qa),_a))}close(){this.curr=null}}class Na{constructor(e){u(this,"channel");u(this,"closed",!1);u(this,"ins");u(this,"static");u(this,"dynamic");this.channel=e.channel,this.ins=e.instrumentation??d.g$1.NOOP,this.static=new La(e),this.dynamic=new Ba({dynamicBufferSize:e.dynamicBufferSize,dataType:this.channel.dataType})}writeDynamic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted dynamic write to a closed cache for channel ${this.channel.name}`),[];const{flushed:t,allocated:s}=this.dynamic.write(e);return t.length>0&&this.static.write(t),s}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(e)}read(e){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:[],gaps:[]}):this.static.dirtyRead(e)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:d.x.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const Ua=d.k.seconds(60);class Fa{constructor(e){u(this,"props");u(this,"cache",new Map);u(this,"gcInterval");this.props={dynamicBufferSize:Ua,gcInterval:d.k.seconds(30),...ti,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:s,dynamicBufferSize:r}=this.props,i=[];for(const l of e)this.cache.has(l)||i.push(l);if(i.length===0)return;const a=await s.retrieve(i);for(const l of a){const c=new Na({channel:l,dynamicBufferSize:r,instrumentation:t.child(`cache-${l.name}-${l.key}`)});this.cache.has(l.key)||this.cache.set(l.key,c)}}get(e){const t=this.cache.get(e);if(t!=null)return t;throw new d.Ce(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=Qr();this.cache.forEach(s=>{const r=s.gc();t.purgedSeries+=r.purgedSeries,t.purgedBytes=t.purgedBytes.add(r.purgedBytes)}),e.info("garbage collection complete",{purgedSeries:t.purgedSeries,purgedBytes:t.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(e=>e.close()),this.cache.clear()}}class Ke{constructor(e,t){u(this,"channel");u(this,"data");this.channel=e,this.data=t}get timeRange(){if(this.data.length===0)return d.V$1.ZERO;const e=this.data[0].timeRange,t=this.data[this.data.length-1].timeRange;return new d.V$1(e.start,t.end)}get digest(){return{channel:this.channel.key,timeRange:this.timeRange.toPrettyString(),series:this.data.map(e=>e.digest)}}}const On=n=>n.map(e=>e.digest);class Ga{constructor(e){u(this,"props");u(this,"debouncedRead");u(this,"guarded",{mu:new d.Mutex,requests:new Map});this.props={instrumentation:d.g$1.NOOP,batchDebounce:d.y.milliseconds(50),...e},this.debouncedRead=d.o(()=>{this.batchRead()},this.props.batchDebounce.milliseconds)}async read(e,t){const{instrumentation:{L:s},cache:r}=this.props;s.debug("starting read",{tr:e.toPrettyString(),channels:t});const i=performance.now(),a=new Map,l={};await r.populateMissing(t);try{for(const f of t){const g=r.get(f),{series:m,gaps:x}=g.read(e);x.length===0&&(l[f]=new Ke(g.channel,m)),x.forEach(v=>{const T=a.get(v.toString());T==null?a.set(v.toString(),[v,new Set([f])]):a.set(v.toString(),[v,new Set([...T[1],f])])})}if(a.size===0)return s.debug("read satisfied by cache",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l;s.debug("read cache miss",()=>({tr:e.toPrettyString(),channels:t,toFetch:Array.from(a.values()).map(([f,g])=>({timeRange:f.toPrettyString(),channels:g})),responses:On(Object.values(l))}));const{mu:c,requests:h}=this.guarded;for(const[,[f,g]]of a)await new Promise((m,x)=>{c.runExclusive(async()=>{h.set([f,g],{resolve:m,reject:x}),this.debouncedRead()})})}catch(c){throw s.error("read failed",{tr:e.toPrettyString(),channels:t,error:c}),c}for(const c of t){const h=r.get(c),{series:f}=h.read(e);l[c]=new Ke(h.channel,f)}return s.debug("read satisfied by fetch",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l}async batchRead(){const{instrumentation:{L:e},readRemote:t,cache:s}=this.props,{mu:r,requests:i}=this.guarded;await r.runExclusive(async()=>{const a=[];try{i.forEach((l,c)=>{const[h,f]=c,g=a.find(([m])=>m.start.span(h.start).lessThan(d.y.milliseconds(5))&&m.end.span(h.end).lessThan(d.y.milliseconds(5)));g==null?a.push([h,f]):g[1]=new Set([...g[1],...f])}),e.debug("batch read",{toFetch:a.map(([l,c])=>({timeRange:l.toPrettyString(),channels:c}))});for(const[l,c]of a){const h=Array.from(c),f=await t(l,h);h.forEach(g=>{const m=s.get(g),x=f.get(g);m.writeStatic(x.series)})}i.forEach(l=>l.resolve())}catch(l){e.error("batch read failed",{error:l},!0),i.forEach(c=>c.reject(l))}finally{i.clear()}})}}class ja{constructor(e){u(this,"props");u(this,"mu",new d.Mutex);u(this,"listeners",new Map);u(this,"streamerRunLoop",null);u(this,"streamer",null);u(this,"closed",!1);this.props={instrumentation:d.g$1.NOOP,...e}}async stream(e,t){const{cache:s,instrumentation:{L:r}}=this.props;return await s.populateMissing(t),await this.mu.runExclusive(async()=>{r.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:t});const i={};for(const a of t){const l=s.get(a),c=l.leadingBuffer!=null?[l.leadingBuffer]:[];i[a]=new Ke(l.channel,c)}return e(i),await this.updateStreamer(),async()=>await this.removeStreamHandler(e)})}async removeStreamHandler(e){const{instrumentation:{L:t}}=this.props;await this.mu.runExclusive(()=>{const s=this.listeners.get(e);s!=null&&(s.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.debug("removing stream handler"),this.listeners.delete(e))return await this.updateStreamer();t.warn("attempted to remove non-existent stream handler")})},5e3)}async updateStreamer(){var i,a;if(this.closed)return;const{instrumentation:{L:e},core:t}=this.props,s=new Set;if(this.listeners.forEach(l=>l.keys.forEach(c=>s.add(c))),s.size===0){e.info("no keys to stream, closing streamer"),(i=this.streamer)==null||i.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.info("streamer closed successfully");return}const r=Array.from(s);if(d.F.primitiveArrays(r,((a=this.streamer)==null?void 0:a.keys)??[])===d.F.EQUAL){e.debug("streamer keys unchanged",{keys:r});return}this.streamer==null&&(e.info("creating new streamer",{keys:r}),this.streamer=await t.openStreamer(r),this.streamerRunLoop=this.runStreamer(this.streamer)),e.debug("updating streamer",{prev:this.streamer.keys,next:r});try{await this.streamer.update(r)}catch(l){throw e.error("failed to update streamer",{error:l}),l}}async runStreamer(e){const{cache:t,instrumentation:{L:s}}=this.props;try{for await(const r of e){const i=[];for(const a of r.keys){const l=r.get(a),c=t.get(a),h=c.writeDynamic(l.series);i.push(new Ke(c.channel,h))}this.listeners.forEach((a,l)=>{if(!a.valid)return;const c=i.filter(f=>a.keys.includes(f.channel.key));if(c.length===0)return;const h=Object.fromEntries(c.map(f=>[f.channel.key,f]));l(h)})}}catch(r){throw s.error("streamer run loop failed",{error:r},!0),r}}async close(){var e;(e=this.streamer)==null||e.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.closed=!0}}class Ha{constructor(){u(this,"key",d.Rt.id());u(this,"_client",null)}async swap(e){var t;this.key=d.Rt.id(),await((t=this._client)==null?void 0:t.close()),this._client=e}async retrieveChannel(e){return await this.client.retrieveChannel(e)}async read(e,t){return await this.client.read(e,t)}async stream(e,t){return await this.client.stream(e,t)}async close(){await this.client.close()}get client(){if(this._client==null)throw new d.re("No cluster has been connected");return this._client}}class Wa{constructor({instrumentation:e,core:t}){u(this,"key",d.Rt.id());u(this,"ins");u(this,"cache");u(this,"reader");u(this,"streamer");u(this,"channelRetriever");this.ins=e??d.g$1.NOOP,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new Fa({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new Ga({cache:this.cache,readRemote:async(s,r)=>await t.read(s,r),instrumentation:this.ins.child("reader")}),this.streamer=new ja({cache:this.cache,core:t,instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new d.re(`channel ${e} not found`);return t[0]}async read(e,t){return await this.reader.read(e,t)}async stream(e,t){return await this.streamer.stream(e,t)}async close(){this.ins.L.info("closing client",{key:this.key}),await this.streamer.close(),this.cache.close()}}const cs=p.z.object({}),Et=class Et extends d.Composite{constructor(){super(...arguments);u(this,"client",new Ha);u(this,"factory",Vr(this.client));u(this,"schema",Et.stateZ);u(this,"prevClient",null)}create(t){const{instrumentation:s}=this.internal;s.L.debug("creating telem",{spec:t});const r=this.factory.create(t);if(r==null)throw new d.Ce(`Telemetry service could not find a source for type ${t.type}`);return r}get clusterKey(){return this.client.key}registerFactory(t){this.factory.add(t)}equals(t){return t instanceof Et?this.client._client===t.client._client:!1}async afterUpdate(){const t=Se(this.ctx),s=ke(this.ctx,"telem");this.internal.instrumentation=s.child("provider"),t!==this.prevClient&&(s.L.info("swapping client",{client:t}),t==null?await this.client.swap(null):await this.client.swap(new Wa({core:t,instrumentation:s})),this.prevClient=t,pr(this.ctx,this))}};u(Et,"TYPE","TelemProvider"),u(Et,"stateZ",cs);let At=Et;const ei={[At.TYPE]:At},Xa=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:Cn,AbstractSource:G,Base:En,BaseProvider:At,BooleanStatus:Yt,ChannelData:ae,CompoundTelemFactory:Xr,FixedNumber:ce,FixedString:ue,IterativeSeries:le,Mean:zt,MultiSourceTransformer:Pr,NoopFactory:br,PipelineFactory:Yr,REGISTRY:ei,RemoteFactory:Ar,RollingAverage:Dt,SetPoint:Pt,SinkPipeline:re,SourcePipeline:se,StaticFactory:$r,StreamChannelData:oe,StreamChannelValue:ie,StringifyNumber:Mt,TransformerFactory:Nr,UnarySinkTransformer:Or,UnarySourceTransformer:Re,WithinBounds:Ot,booleanSinkSpecZ:Sn,booleanSinkTransformerSpecZ:ba,booleanSourceSpecZ:ts,booleanSourceTransformerSpecZ:Ta,booleanStatus:Da,booleanStatusProps:jr,channelData:Lr,colorSourceSpecZ:Rr,factory:Vr,fixedArray:Ra,fixedNumber:Pa,fixedNumberPropsZ:Zr,fixedSeriesPropsZ:as,fixedString:Oa,fixedStringPropsZ:Br,iterativeArray:ka,iterativeSeriesPropsZ:Ir,mean:Ma,noopBooleanSinkSpec:bn,noopBooleanSourceSpec:Jn,noopColorSourceSpec:xr,noopNumericSinkSpec:mr,noopNumericSourceSpec:yr,noopSeriesSourceSpec:vr,noopStatusSourceSpec:Qn,noopStringSourceSpec:wr,numberSinkSpecZ:Cr,numberSourceSpecZ:Er,providerStateZ:cs,registerFactory:gr,rollingAverage:Wr,rollingAverageProps:ls,seriesSourceSpecZ:Xe,setProvider:pr,setpoint:Ur,sinkPipeline:Dr,sinkPipelinePropsZ:ss,sinkSpecZ:Tn,sinkTransformerSpecZ:Sr,sourcePipeline:Mr,sourcePipelinePropsZ:ns,sourceSpecZ:ct,sourceTransformerSpecZ:Tr,specZ:Ce,statusSourceSpecZ:es,streamChannelData:_r,streamChannelValue:qr,streamChannelValuePropsZ:rs,stringSourceSpecZ:kr,stringifyNumber:Hr,stringifyNumberProps:os,useProvider:vn,useSink:Ee,useSource:X,withinBounds:Fr},Symbol.toStringTag,{value:"Module"})),ni=p.z.object({key:p.z.string(),size:p.z.number(),order:p.z.number(),loc:o.J.outer});p.z.record(ni);const dt=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Va=(n,e,t)=>{const s=e[n];if(s==null)return o.q.ZERO;const r=o.J.construct(s.loc),i=dt(r,e),a=o.J.construct(o.g.swap(o.J.direction(r))),l=dt(a,e),c=i.findIndex(({key:g})=>g===n),h=i.slice(0,c).reduce((g,{size:m})=>g+m,0),f=l.reduce((g,{size:m})=>g+m,0);switch(r){case"left":return o.q.translate(o.Eo.topLeft(t),[h,f]);case"right":return o.q.translate(o.Eo.topRight(t),[h-s.size,f]);case"top":return o.q.translate(o.Eo.topLeft(t),[f,h]);default:return o.q.translate(o.Eo.bottomLeft(t),[f,-h-s.size])}},Ka=(n,e)=>{const t=dt("left",n),s=dt("right",n),r=dt("top",n),i=dt("bottom",n),a=t.reduce((f,{size:g})=>f+g,0),l=s.reduce((f,{size:g})=>f+g,0),c=r.reduce((f,{size:g})=>f+g,0),h=i.reduce((f,{size:g})=>f+g,0);return o.Eo.construct(o.q.translate(o.Eo.topLeft(e),{x:a,y:c}),o.Eo.width(e)-a-l,o.Eo.height(e)-c-h)};function $e(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function Ja(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function us(n){let e,t,s;n.length!==2?(e=$e,t=(l,c)=>$e(n(l),c),s=(l,c)=>n(l)-c):(e=n===$e||n===Ja?n:Qa,t=n,s=n);function r(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<0?h=g+1:f=g}while(h<f)}return h}function i(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<=0?h=g+1:f=g}while(h<f)}return h}function a(l,c,h=0,f=l.length){const g=r(l,c,h,f-1);return g>h&&s(l[g-1],c)>-s(l[g],c)?g-1:g}return{left:r,center:a,right:i}}function Qa(){return 0}function to(n){return n===null?NaN:+n}const eo=us($e),no=eo.right;us(to).center;const so=Math.sqrt(50),ro=Math.sqrt(10),io=Math.sqrt(2);function Je(n,e,t){const s=(e-n)/Math.max(0,t),r=Math.floor(Math.log10(s)),i=s/Math.pow(10,r),a=i>=so?10:i>=ro?5:i>=io?2:1;let l,c,h;return r<0?(h=Math.pow(10,-r)/a,l=Math.round(n*h),c=Math.round(e*h),l/h<n&&++l,c/h>e&&--c,h=-h):(h=Math.pow(10,r)*a,l=Math.round(n/h),c=Math.round(e/h),l*h<n&&++l,c*h>e&&--c),c<l&&.5<=t&&t<2?Je(n,e,t*2):[l,c,h]}function ao(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[r,i,a]=s?Je(e,n,t):Je(n,e,t);if(!(i>=r))return[];const l=i-r+1,c=new Array(l);if(s)if(a<0)for(let h=0;h<l;++h)c[h]=(i-h)/-a;else for(let h=0;h<l;++h)c[h]=(i-h)*a;else if(a<0)for(let h=0;h<l;++h)c[h]=(r+h)/-a;else for(let h=0;h<l;++h)c[h]=(r+h)*a;return c}function Bn(n,e,t){return e=+e,n=+n,t=+t,Je(n,e,t)[2]}function Nn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,r=s?Bn(e,n,t):Bn(n,e,t);return(s?-1:1)*(r<0?1/-r:r)}function si(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function hs(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function ri(n,e){var t=Object.create(n.prototype);for(var s in e)t[s]=e[s];return t}function Pe(){}var he=.7,Qe=1/he,kt="\\s*([+-]?\\d+)\\s*",de="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",J="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",oo=/^#([0-9a-f]{3,8})$/,lo=new RegExp(`^rgb\\(${kt},${kt},${kt}\\)$`),co=new RegExp(`^rgb\\(${J},${J},${J}\\)$`),uo=new RegExp(`^rgba\\(${kt},${kt},${kt},${de}\\)$`),ho=new RegExp(`^rgba\\(${J},${J},${J},${de}\\)$`),fo=new RegExp(`^hsl\\(${de},${J},${J}\\)$`),po=new RegExp(`^hsla\\(${de},${J},${J},${de}\\)$`),Ms={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};hs(Pe,Lt,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:Ds,formatHex:Ds,formatHex8:go,formatHsl:mo,formatRgb:As,toString:As});function Ds(){return this.rgb().formatHex()}function go(){return this.rgb().formatHex8()}function mo(){return ii(this).formatHsl()}function As(){return this.rgb().formatRgb()}function Lt(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=oo.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?Ls(e):t===3?new B(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?De(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?De(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=lo.exec(n))?new B(e[1],e[2],e[3],1):(e=co.exec(n))?new B(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=uo.exec(n))?De(e[1],e[2],e[3],e[4]):(e=ho.exec(n))?De(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=fo.exec(n))?$s(e[1],e[2]/100,e[3]/100,1):(e=po.exec(n))?$s(e[1],e[2]/100,e[3]/100,e[4]):Ms.hasOwnProperty(n)?Ls(Ms[n]):n==="transparent"?new B(NaN,NaN,NaN,0):null}function Ls(n){return new B(n>>16&255,n>>8&255,n&255,1)}function De(n,e,t,s){return s<=0&&(n=e=t=NaN),new B(n,e,t,s)}function yo(n){return n instanceof Pe||(n=Lt(n)),n?(n=n.rgb(),new B(n.r,n.g,n.b,n.opacity)):new B}function Un(n,e,t,s){return arguments.length===1?yo(n):new B(n,e,t,s??1)}function B(n,e,t,s){this.r=+n,this.g=+e,this.b=+t,this.opacity=+s}hs(B,Un,ri(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new B(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new B(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new B(pt(this.r),pt(this.g),pt(this.b),tn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:_s,formatHex:_s,formatHex8:wo,formatRgb:qs,toString:qs}));function _s(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}`}function wo(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}${ft((isNaN(this.opacity)?1:this.opacity)*255)}`}function qs(){const n=tn(this.opacity);return`${n===1?"rgb(":"rgba("}${pt(this.r)}, ${pt(this.g)}, ${pt(this.b)}${n===1?")":`, ${n})`}`}function tn(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function pt(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function ft(n){return n=pt(n),(n<16?"0":"")+n.toString(16)}function $s(n,e,t,s){return s<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new H(n,e,t,s)}function ii(n){if(n instanceof H)return new H(n.h,n.s,n.l,n.opacity);if(n instanceof Pe||(n=Lt(n)),!n)return new H;if(n instanceof H)return n;n=n.rgb();var e=n.r/255,t=n.g/255,s=n.b/255,r=Math.min(e,t,s),i=Math.max(e,t,s),a=NaN,l=i-r,c=(i+r)/2;return l?(e===i?a=(t-s)/l+(t<s)*6:t===i?a=(s-e)/l+2:a=(e-t)/l+4,l/=c<.5?i+r:2-i-r,a*=60):l=c>0&&c<1?0:a,new H(a,l,c,n.opacity)}function xo(n,e,t,s){return arguments.length===1?ii(n):new H(n,e,t,s??1)}function H(n,e,t,s){this.h=+n,this.s=+e,this.l=+t,this.opacity=+s}hs(H,xo,ri(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new H(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new H(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,s=t+(t<.5?t:1-t)*e,r=2*t-s;return new B(zn(n>=240?n-240:n+120,r,s),zn(n,r,s),zn(n<120?n+240:n-120,r,s),this.opacity)},clamp(){return new H(Is(this.h),Ae(this.s),Ae(this.l),tn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=tn(this.opacity);return`${n===1?"hsl(":"hsla("}${Is(this.h)}, ${Ae(this.s)*100}%, ${Ae(this.l)*100}%${n===1?")":`, ${n})`}`}}));function Is(n){return n=(n||0)%360,n<0?n+360:n}function Ae(n){return Math.max(0,Math.min(1,n||0))}function zn(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const ds=n=>()=>n;function vo(n,e){return function(t){return n+t*e}}function bo(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(s){return Math.pow(n+s*e,t)}}function To(n){return(n=+n)==1?ai:function(e,t){return t-e?bo(e,t,n):ds(isNaN(e)?t:e)}}function ai(n,e){var t=e-n;return t?vo(n,t):ds(isNaN(n)?e:n)}const Fn=function n(e){var t=To(e);function s(r,i){var a=t((r=Un(r)).r,(i=Un(i)).r),l=t(r.g,i.g),c=t(r.b,i.b),h=ai(r.opacity,i.opacity);return function(f){return r.r=a(f),r.g=l(f),r.b=c(f),r.opacity=h(f),r+""}}return s.gamma=n,s}(1);function So(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,s=e.slice(),r;return function(i){for(r=0;r<t;++r)s[r]=n[r]*(1-i)+e[r]*i;return s}}function Eo(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Co(n,e){var t=e?e.length:0,s=n?Math.min(t,n.length):0,r=new Array(s),i=new Array(t),a;for(a=0;a<s;++a)r[a]=fs(n[a],e[a]);for(;a<t;++a)i[a]=e[a];return function(l){for(a=0;a<s;++a)i[a]=r[a](l);return i}}function Ro(n,e){var t=new Date;return n=+n,e=+e,function(s){return t.setTime(n*(1-s)+e*s),t}}function fe(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function ko(n,e){var t={},s={},r;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in n?t[r]=fs(n[r],e[r]):s[r]=e[r];return function(i){for(r in t)s[r]=t[r](i);return s}}var Gn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Yn=new RegExp(Gn.source,"g");function Po(n){return function(){return n}}function Oo(n){return function(e){return n(e)+""}}function oi(n,e){var t=Gn.lastIndex=Yn.lastIndex=0,s,r,i,a=-1,l=[],c=[];for(n=n+"",e=e+"";(s=Gn.exec(n))&&(r=Yn.exec(e));)(i=r.index)>t&&(i=e.slice(t,i),l[a]?l[a]+=i:l[++a]=i),(s=s[0])===(r=r[0])?l[a]?l[a]+=r:l[++a]=r:(l[++a]=null,c.push({i:a,x:fe(s,r)})),t=Yn.lastIndex;return t<e.length&&(i=e.slice(t),l[a]?l[a]+=i:l[++a]=i),l.length<2?c[0]?Oo(c[0].x):Po(e):(e=c.length,function(h){for(var f=0,g;f<e;++f)l[(g=c[f]).i]=g.x(h);return l.join("")})}function fs(n,e){var t=typeof e,s;return e==null||t==="boolean"?ds(e):(t==="number"?fe:t==="string"?(s=Lt(e))?(e=s,Fn):oi:e instanceof Lt?Fn:e instanceof Date?Ro:Eo(e)?So:Array.isArray(e)?Co:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?ko:fe)(n,e)}function zo(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}function Yo(n){return function(){return n}}function Mo(n){return+n}var Zs=[0,1];function Tt(n){return n}function jn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Yo(isNaN(e)?NaN:.5)}function Do(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function Ao(n,e,t){var s=n[0],r=n[1],i=e[0],a=e[1];return r<s?(s=jn(r,s),i=t(a,i)):(s=jn(s,r),i=t(i,a)),function(l){return i(s(l))}}function Lo(n,e,t){var s=Math.min(n.length,e.length)-1,r=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)r[a]=jn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var c=no(n,l,1,s)-1;return i[c](r[c](l))}}function li(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function _o(){var n=Zs,e=Zs,t=fs,s,r,i,a=Tt,l,c,h;function f(){var m=Math.min(n.length,e.length);return a!==Tt&&(a=Do(n[0],n[m-1])),l=m>2?Lo:Ao,c=h=null,g}function g(m){return m==null||isNaN(m=+m)?i:(c||(c=l(n.map(s),e,t)))(s(a(m)))}return g.invert=function(m){return a(r((h||(h=l(e,n.map(s),fe)))(m)))},g.domain=function(m){return arguments.length?(n=Array.from(m,Mo),f()):n.slice()},g.range=function(m){return arguments.length?(e=Array.from(m),f()):e.slice()},g.rangeRound=function(m){return e=Array.from(m),t=zo,f()},g.clamp=function(m){return arguments.length?(a=m?!0:Tt,f()):a!==Tt},g.interpolate=function(m){return arguments.length?(t=m,f()):t},g.unknown=function(m){return arguments.length?(i=m,g):i},function(m,x){return s=m,r=x,f()}}function ci(){return _o()(Tt,Tt)}function qo(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function en(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function _t(n){return n=en(Math.abs(n)),n?n[1]:NaN}function $o(n,e){return function(t,s){for(var r=t.length,i=[],a=0,l=n[0],c=0;r>0&&l>0&&(c+l+1>s&&(l=Math.max(1,s-c)),i.push(t.substring(r-=l,r+l)),!((c+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function Io(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var Zo=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function nn(n){if(!(e=Zo.exec(n)))throw new Error("invalid format: "+n);var e;return new ps({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}nn.prototype=ps.prototype;function ps(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}ps.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function Bo(n){t:for(var e=n.length,t=1,s=-1,r;t<e;++t)switch(n[t]){case".":s=r=t;break;case"0":s===0&&(s=t),r=t;break;default:if(!+n[t])break t;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(r+1):n}var ui;function No(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1],i=r-(ui=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+en(n,Math.max(0,e+i-1))[0]}function Bs(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+s:s.length>r+1?s.slice(0,r+1)+"."+s.slice(r+1):s+new Array(r-s.length+2).join("0")}const Ns={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:qo,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>Bs(n*100,e),r:Bs,s:No,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Us(n){return n}var Fs=Array.prototype.map,Gs=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Uo(n){var e=n.grouping===void 0||n.thousands===void 0?Us:$o(Fs.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",r=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?Us:Io(Fs.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",c=n.nan===void 0?"NaN":n.nan+"";function h(g){g=nn(g);var m=g.fill,x=g.align,v=g.sign,T=g.symbol,C=g.zero,O=g.width,A=g.comma,P=g.precision,M=g.trim,L=g.type;L==="n"?(A=!0,L="g"):Ns[L]||(P===void 0&&(P=12),M=!0,L="g"),(C||m==="0"&&x==="=")&&(C=!0,m="0",x="=");var b=T==="$"?t:T==="#"&&/[boxX]/.test(L)?"0"+L.toLowerCase():"",_=T==="$"?s:/[%p]/.test(L)?a:"",ut=Ns[L],kn=/[defgprs%]/.test(L);P=P===void 0?6:/[gprs]/.test(L)?Math.max(1,Math.min(21,P)):Math.max(0,Math.min(20,P));function Ye(E){var tt=b,I=_,at,Me,wt;if(L==="c")I=ut(E)+I,E="";else{E=+E;var xt=E<0||1/E<0;if(E=isNaN(E)?c:ut(Math.abs(E),P),M&&(E=Bo(E)),xt&&+E==0&&v!=="+"&&(xt=!1),tt=(xt?v==="("?v:l:v==="-"||v==="("?"":v)+tt,I=(L==="s"?Gs[8+ui/3]:"")+I+(xt&&v==="("?")":""),kn){for(at=-1,Me=E.length;++at<Me;)if(wt=E.charCodeAt(at),48>wt||wt>57){I=(wt===46?r+E.slice(at+1):E.slice(at))+I,E=E.slice(0,at);break}}}A&&!C&&(E=e(E,1/0));var vt=tt.length+E.length+I.length,j=vt<O?new Array(O-vt+1).join(m):"";switch(A&&C&&(E=e(j+E,j.length?O-I.length:1/0),j=""),x){case"<":E=tt+E+I+j;break;case"=":E=tt+j+E+I;break;case"^":E=j.slice(0,vt=j.length>>1)+tt+E+I+j.slice(vt);break;default:E=j+tt+E+I;break}return i(E)}return Ye.toString=function(){return g+""},Ye}function f(g,m){var x=h((g=nn(g),g.type="f",g)),v=Math.max(-8,Math.min(8,Math.floor(_t(m)/3)))*3,T=Math.pow(10,-v),C=Gs[8+v/3];return function(O){return x(T*O)+C}}return{format:h,formatPrefix:f}}var Le,hi,di;Fo({thousands:",",grouping:[3],currency:["$",""]});function Fo(n){return Le=Uo(n),hi=Le.format,di=Le.formatPrefix,Le}function Go(n){return Math.max(0,-_t(Math.abs(n)))}function jo(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(_t(e)/3)))*3-_t(Math.abs(n)))}function Ho(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,_t(e)-_t(n))+1}function Wo(n,e,t,s){var r=Nn(n,e,t),i;switch(s=nn(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=jo(r,a))&&(s.precision=i),di(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=Ho(r,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=Go(r))&&(s.precision=i-(s.type==="%")*2);break}}return hi(s)}function Xo(n){var e=n.domain;return n.ticks=function(t){var s=e();return ao(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var r=e();return Wo(r[0],r[r.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),r=0,i=s.length-1,a=s[r],l=s[i],c,h,f=10;for(l<a&&(h=a,a=l,l=h,h=r,r=i,i=h);f-- >0;){if(h=Bn(a,l,t),h===c)return s[r]=a,s[i]=l,e(s);if(h>0)a=Math.floor(a/h)*h,l=Math.ceil(l/h)*h;else if(h<0)a=Math.ceil(a*h)/h,l=Math.floor(l*h)/h;else break;c=h}return n},n}function fi(){var n=ci();return n.copy=function(){return li(n,fi())},si.apply(n,arguments),Xo(n)}function Vo(n,e){n=n.slice();var t=0,s=n.length-1,r=n[t],i=n[s],a;return i<r&&(a=t,t=s,s=a,a=r,r=i,i=a),n[t]=e.floor(r),n[s]=e.ceil(i),n}const Mn=new Date,Dn=new Date;function Y(n,e,t,s){function r(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return r.floor=i=>(n(i=new Date(+i)),i),r.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),r.round=i=>{const a=r(i),l=r.ceil(i);return i-a<l-i?a:l},r.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),r.range=(i,a,l)=>{const c=[];if(i=r.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return c;let h;do c.push(h=new Date(+i)),e(i,l),n(i);while(h<i&&i<a);return c},r.filter=i=>Y(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(r.count=(i,a)=>(Mn.setTime(+i),Dn.setTime(+a),n(Mn),n(Dn),Math.floor(t(Mn,Dn))),r.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?r.filter(s?a=>s(a)%i===0:a=>r.count(0,a)%i===0):r)),r}const sn=Y(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);sn.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?Y(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):sn);sn.range;const et=1e3,F=et*60,nt=F*60,st=nt*24,gs=st*7,js=st*30,An=st*365,St=Y(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*et)},(n,e)=>(e-n)/et,n=>n.getUTCSeconds());St.range;const ms=Y(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getMinutes());ms.range;const Ko=Y(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getUTCMinutes());Ko.range;const ys=Y(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et-n.getMinutes()*F)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getHours());ys.range;const Jo=Y(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getUTCHours());Jo.range;const Oe=Y(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*F)/st,n=>n.getDate()-1);Oe.range;const ws=Y(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>n.getUTCDate()-1);ws.range;const Qo=Y(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>Math.floor(n/st));Qo.range;function mt(n){return Y(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*F)/gs)}const Rn=mt(0),rn=mt(1),tl=mt(2),el=mt(3),qt=mt(4),nl=mt(5),sl=mt(6);Rn.range;rn.range;tl.range;el.range;qt.range;nl.range;sl.range;function yt(n){return Y(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/gs)}const pi=yt(0),an=yt(1),rl=yt(2),il=yt(3),$t=yt(4),al=yt(5),ol=yt(6);pi.range;an.range;rl.range;il.range;$t.range;al.range;ol.range;const xs=Y(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());xs.range;const ll=Y(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());ll.range;const rt=Y(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());rt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:Y(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});rt.range;const gt=Y(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());gt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:Y(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});gt.range;function cl(n,e,t,s,r,i){const a=[[St,1,et],[St,5,5*et],[St,15,15*et],[St,30,30*et],[i,1,F],[i,5,5*F],[i,15,15*F],[i,30,30*F],[r,1,nt],[r,3,3*nt],[r,6,6*nt],[r,12,12*nt],[s,1,st],[s,2,2*st],[t,1,gs],[e,1,js],[e,3,3*js],[n,1,An]];function l(h,f,g){const m=f<h;m&&([h,f]=[f,h]);const x=g&&typeof g.range=="function"?g:c(h,f,g),v=x?x.range(h,+f+1):[];return m?v.reverse():v}function c(h,f,g){const m=Math.abs(f-h)/g,x=us(([,,C])=>C).right(a,m);if(x===a.length)return n.every(Nn(h/An,f/An,g));if(x===0)return sn.every(Math.max(Nn(h,f,g),1));const[v,T]=a[m/a[x-1][2]<a[x][2]/m?x-1:x];return v.every(T)}return[l,c]}const[ul,hl]=cl(rt,xs,Rn,Oe,ys,ms);function Ln(n){if(0<=n.y&&n.y<100){var e=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return e.setFullYear(n.y),e}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function _n(n){if(0<=n.y&&n.y<100){var e=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return e.setUTCFullYear(n.y),e}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function jt(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function dl(n){var e=n.dateTime,t=n.date,s=n.time,r=n.periods,i=n.days,a=n.shortDays,l=n.months,c=n.shortMonths,h=Ht(r),f=Wt(r),g=Ht(i),m=Wt(i),x=Ht(a),v=Wt(a),T=Ht(l),C=Wt(l),O=Ht(c),A=Wt(c),P={a:xt,A:vt,b:j,B:na,c:null,d:Js,e:Js,f:Ll,g:Gl,G:Hl,H:Ml,I:Dl,j:Al,L:gi,m:_l,M:ql,p:sa,q:ra,Q:er,s:nr,S:$l,u:Il,U:Zl,V:Bl,w:Nl,W:Ul,x:null,X:null,y:Fl,Y:jl,Z:Wl,"%":tr},M={a:ia,A:aa,b:oa,B:la,c:null,d:Qs,e:Qs,f:Jl,g:lc,G:uc,H:Xl,I:Vl,j:Kl,L:yi,m:Ql,M:tc,p:ca,q:ua,Q:er,s:nr,S:ec,u:nc,U:sc,V:rc,w:ic,W:ac,x:null,X:null,y:oc,Y:cc,Z:hc,"%":tr},L={a:Ye,A:E,b:tt,B:I,c:at,d:Vs,e:Vs,f:Pl,g:Xs,G:Ws,H:Ks,I:Ks,j:El,L:kl,m:Sl,M:Cl,p:kn,q:Tl,Q:zl,s:Yl,S:Rl,u:yl,U:wl,V:xl,w:ml,W:vl,x:Me,X:wt,y:Xs,Y:Ws,Z:bl,"%":Ol};P.x=b(t,P),P.X=b(s,P),P.c=b(e,P),M.x=b(t,M),M.X=b(s,M),M.c=b(e,M);function b(w,S){return function(R){var y=[],Z=-1,z=0,N=w.length,U,ht,Os;for(R instanceof Date||(R=new Date(+R));++Z<N;)w.charCodeAt(Z)===37&&(y.push(w.slice(z,Z)),(ht=Hs[U=w.charAt(++Z)])!=null?U=w.charAt(++Z):ht=U==="e"?" ":"0",(Os=S[U])&&(U=Os(R,ht)),y.push(U),z=Z+1);return y.push(w.slice(z,Z)),y.join("")}}function _(w,S){return function(R){var y=jt(1900,void 0,1),Z=ut(y,w,R+="",0),z,N;if(Z!=R.length)return null;if("Q"in y)return new Date(y.Q);if("s"in y)return new Date(y.s*1e3+("L"in y?y.L:0));if(S&&!("Z"in y)&&(y.Z=0),"p"in y&&(y.H=y.H%12+y.p*12),y.m===void 0&&(y.m="q"in y?y.q:0),"V"in y){if(y.V<1||y.V>53)return null;"w"in y||(y.w=1),"Z"in y?(z=_n(jt(y.y,0,1)),N=z.getUTCDay(),z=N>4||N===0?an.ceil(z):an(z),z=ws.offset(z,(y.V-1)*7),y.y=z.getUTCFullYear(),y.m=z.getUTCMonth(),y.d=z.getUTCDate()+(y.w+6)%7):(z=Ln(jt(y.y,0,1)),N=z.getDay(),z=N>4||N===0?rn.ceil(z):rn(z),z=Oe.offset(z,(y.V-1)*7),y.y=z.getFullYear(),y.m=z.getMonth(),y.d=z.getDate()+(y.w+6)%7)}else("W"in y||"U"in y)&&("w"in y||(y.w="u"in y?y.u%7:"W"in y?1:0),N="Z"in y?_n(jt(y.y,0,1)).getUTCDay():Ln(jt(y.y,0,1)).getDay(),y.m=0,y.d="W"in y?(y.w+6)%7+y.W*7-(N+5)%7:y.w+y.U*7-(N+6)%7);return"Z"in y?(y.H+=y.Z/100|0,y.M+=y.Z%100,_n(y)):Ln(y)}}function ut(w,S,R,y){for(var Z=0,z=S.length,N=R.length,U,ht;Z<z;){if(y>=N)return-1;if(U=S.charCodeAt(Z++),U===37){if(U=S.charAt(Z++),ht=L[U in Hs?S.charAt(Z++):U],!ht||(y=ht(w,R,y))<0)return-1}else if(U!=R.charCodeAt(y++))return-1}return y}function kn(w,S,R){var y=h.exec(S.slice(R));return y?(w.p=f.get(y[0].toLowerCase()),R+y[0].length):-1}function Ye(w,S,R){var y=x.exec(S.slice(R));return y?(w.w=v.get(y[0].toLowerCase()),R+y[0].length):-1}function E(w,S,R){var y=g.exec(S.slice(R));return y?(w.w=m.get(y[0].toLowerCase()),R+y[0].length):-1}function tt(w,S,R){var y=O.exec(S.slice(R));return y?(w.m=A.get(y[0].toLowerCase()),R+y[0].length):-1}function I(w,S,R){var y=T.exec(S.slice(R));return y?(w.m=C.get(y[0].toLowerCase()),R+y[0].length):-1}function at(w,S,R){return ut(w,e,S,R)}function Me(w,S,R){return ut(w,t,S,R)}function wt(w,S,R){return ut(w,s,S,R)}function xt(w){return a[w.getDay()]}function vt(w){return i[w.getDay()]}function j(w){return c[w.getMonth()]}function na(w){return l[w.getMonth()]}function sa(w){return r[+(w.getHours()>=12)]}function ra(w){return 1+~~(w.getMonth()/3)}function ia(w){return a[w.getUTCDay()]}function aa(w){return i[w.getUTCDay()]}function oa(w){return c[w.getUTCMonth()]}function la(w){return l[w.getUTCMonth()]}function ca(w){return r[+(w.getUTCHours()>=12)]}function ua(w){return 1+~~(w.getUTCMonth()/3)}return{format:function(w){var S=b(w+="",P);return S.toString=function(){return w},S},parse:function(w){var S=_(w+="",!1);return S.toString=function(){return w},S},utcFormat:function(w){var S=b(w+="",M);return S.toString=function(){return w},S},utcParse:function(w){var S=_(w+="",!0);return S.toString=function(){return w},S}}}var Hs={"-":"",_:" ",0:"0"},D=/^\s*\d+/,fl=/^%/,pl=/[\\^$*+?|[\]().{}]/g;function k(n,e,t){var s=n<0?"-":"",r=(s?-n:n)+"",i=r.length;return s+(i<t?new Array(t-i+1).join(e)+r:r)}function gl(n){return n.replace(pl,"\\$&")}function Ht(n){return new RegExp("^(?:"+n.map(gl).join("|")+")","i")}function Wt(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function ml(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function yl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function wl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function xl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function vl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Ws(n,e,t){var s=D.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Xs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function bl(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function Tl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Sl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Vs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function El(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Ks(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function Cl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Rl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function kl(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Pl(n,e,t){var s=D.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Ol(n,e,t){var s=fl.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function zl(n,e,t){var s=D.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Yl(n,e,t){var s=D.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Js(n,e){return k(n.getDate(),e,2)}function Ml(n,e){return k(n.getHours(),e,2)}function Dl(n,e){return k(n.getHours()%12||12,e,2)}function Al(n,e){return k(1+Oe.count(rt(n),n),e,3)}function gi(n,e){return k(n.getMilliseconds(),e,3)}function Ll(n,e){return gi(n,e)+"000"}function _l(n,e){return k(n.getMonth()+1,e,2)}function ql(n,e){return k(n.getMinutes(),e,2)}function $l(n,e){return k(n.getSeconds(),e,2)}function Il(n){var e=n.getDay();return e===0?7:e}function Zl(n,e){return k(Rn.count(rt(n)-1,n),e,2)}function mi(n){var e=n.getDay();return e>=4||e===0?qt(n):qt.ceil(n)}function Bl(n,e){return n=mi(n),k(qt.count(rt(n),n)+(rt(n).getDay()===4),e,2)}function Nl(n){return n.getDay()}function Ul(n,e){return k(rn.count(rt(n)-1,n),e,2)}function Fl(n,e){return k(n.getFullYear()%100,e,2)}function Gl(n,e){return n=mi(n),k(n.getFullYear()%100,e,2)}function jl(n,e){return k(n.getFullYear()%1e4,e,4)}function Hl(n,e){var t=n.getDay();return n=t>=4||t===0?qt(n):qt.ceil(n),k(n.getFullYear()%1e4,e,4)}function Wl(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+k(e/60|0,"0",2)+k(e%60,"0",2)}function Qs(n,e){return k(n.getUTCDate(),e,2)}function Xl(n,e){return k(n.getUTCHours(),e,2)}function Vl(n,e){return k(n.getUTCHours()%12||12,e,2)}function Kl(n,e){return k(1+ws.count(gt(n),n),e,3)}function yi(n,e){return k(n.getUTCMilliseconds(),e,3)}function Jl(n,e){return yi(n,e)+"000"}function Ql(n,e){return k(n.getUTCMonth()+1,e,2)}function tc(n,e){return k(n.getUTCMinutes(),e,2)}function ec(n,e){return k(n.getUTCSeconds(),e,2)}function nc(n){var e=n.getUTCDay();return e===0?7:e}function sc(n,e){return k(pi.count(gt(n)-1,n),e,2)}function wi(n){var e=n.getUTCDay();return e>=4||e===0?$t(n):$t.ceil(n)}function rc(n,e){return n=wi(n),k($t.count(gt(n),n)+(gt(n).getUTCDay()===4),e,2)}function ic(n){return n.getUTCDay()}function ac(n,e){return k(an.count(gt(n)-1,n),e,2)}function oc(n,e){return k(n.getUTCFullYear()%100,e,2)}function lc(n,e){return n=wi(n),k(n.getUTCFullYear()%100,e,2)}function cc(n,e){return k(n.getUTCFullYear()%1e4,e,4)}function uc(n,e){var t=n.getUTCDay();return n=t>=4||t===0?$t(n):$t.ceil(n),k(n.getUTCFullYear()%1e4,e,4)}function hc(){return"+0000"}function tr(){return"%"}function er(n){return+n}function nr(n){return Math.floor(+n/1e3)}var bt,xi;dc({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function dc(n){return bt=dl(n),xi=bt.format,bt.parse,bt.utcFormat,bt.utcParse,bt}function fc(n){return new Date(n)}function pc(n){return n instanceof Date?+n:+new Date(+n)}function vi(n,e,t,s,r,i,a,l,c,h){var f=ci(),g=f.invert,m=f.domain,x=h(".%L"),v=h(":%S"),T=h("%I:%M"),C=h("%I %p"),O=h("%a %d"),A=h("%b %d"),P=h("%B"),M=h("%Y");function L(b){return(c(b)<b?x:l(b)<b?v:a(b)<b?T:i(b)<b?C:s(b)<b?r(b)<b?O:A:t(b)<b?P:M)(b)}return f.invert=function(b){return new Date(g(b))},f.domain=function(b){return arguments.length?m(Array.from(b,pc)):m().map(fc)},f.ticks=function(b){var _=m();return n(_[0],_[_.length-1],b??10)},f.tickFormat=function(b,_){return _==null?L:h(_)},f.nice=function(b){var _=m();return(!b||typeof b.range!="function")&&(b=e(_[0],_[_.length-1],b??10)),b?m(Vo(_,b)):f},f.copy=function(){return li(f,vi(n,e,t,s,r,i,a,l,c,h))},f}function gc(){return si.apply(vi(ul,hl,rt,xs,Rn,Oe,ys,ms,St,xi).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const vs=p.z.enum(["linear","time"]),bs=p.z.object({tickSpacing:p.z.number().default(75),type:vs.optional().default("linear")}),Hn=n=>{const e=bs.parse(n);return wc[e.type](e)};class mc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[new d.m(e.pos(0)).date(),new d.m(e.pos(1)).date()],i=gc().domain(r).range(s);return i.ticks(bi(t,this.props.tickSpacing)).map(l=>({label:this.tickLabel(l),position:i(l)}))}tickLabel(e){const t=new d.m(e).date();let s=`:${t.getSeconds()}`;if(t.getMilliseconds()!==0){const i=Math.round(t.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");s+=`.${i}`}return t.getSeconds()===0&&t.getMilliseconds()===0&&(s=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`),s}}class yc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[e.pos(0),e.pos(1)],i=fi().domain(r).range(s),a=bi(t,this.props.tickSpacing);return i.ticks(a).map(c=>({label:this.tickLabel(c),position:i(c)}))}tickLabel(e){return e.toString()}}const bi=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},wc={linear:n=>new yc(n),time:n=>new mc(n)},Ts=bs.extend({color:o.Color.z,type:vs.optional().default("linear"),font:p.z.string(),showGrid:p.z.boolean().optional().default(!0),location:o.J.outer,gridColor:o.Color.z}),V=4;let Ti=class{constructor(e,t){u(this,"ctx");u(this,"state");u(this,"tickFactory");this.ctx=e,this.state=t,this.tickFactory=Hn(this.state)}setState(e){this.state=d.prettyParse(Ts,e),this.tickFactory=Hn(e)}render(e){const{lower2d:t}=this.ctx;switch(t.font=this.state.font,t.fillStyle=this.state.color.hex,t.lineWidth=1,this.state.location){case"left":return this.drawLeft(e);case"right":return this.drawRight(e);case"top":return this.drawTop(e);default:return this.drawBottom(e)}}drawBottom(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:-i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y+V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y+5+h.height)}).height+V+6}}drawTop(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=o.q.translate(e.position,"y",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y-V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y-5-h.height)}).height+V}}drawLeft(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=o.q.translate(e.position,"x",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x-V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x-h.width-V*2,a.y+f.position+h.height/3)}).width+V*2}}drawRight(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:-i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x+V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x+V+2,a.y+f.position+h.height/3)}).width+V*2}}drawLine(e,t){const{lower2d:s}=this.ctx;s.beginPath(),s.moveTo(...o.q.couple(e)),s.lineTo(...o.q.couple(t)),s.stroke()}drawTicks(e,t){let s=o._.ZERO;return e.forEach(r=>{const i=d.dimensions(r.label,this.state.font,this.ctx.lower2d);s=o._.max([s,i]),t(i,r)}),s}maybeDrawGrid(e,t,s){const{showGrid:r,gridColor:i}=this.state;if(r){const a=o.G.construct(-1,1),l=o.G.construct(e-1,e+1);this.ctx.lower2d.strokeStyle=i.hex,t.filter(({position:c})=>!o.G.contains(a,c)&&!o.G.contains(l,c)).forEach(c=>this.drawLine(...s(c)))}}};const Ie=(n,e)=>o.Eo.construct(o.Eo.left(n)-e.x,o.Eo.top(n)-e.y,o.Eo.width(n)+e.x*2,o.Eo.height(n)+e.y*2);class on{constructor(e,t=o.k$2.XY.IDENTITY){u(this,"scale_");u(this,"wrapped");this.wrapped=e,this.scale_=t}get fontStretch(){return this.wrapped.fontStretch}set fontStretch(e){this.wrapped.fontStretch=e}get fontVariantCaps(){return this.wrapped.fontVariantCaps}set fontVariantCaps(e){this.wrapped.fontVariantCaps=e}isContextLost(){return this.wrapped.isContextLost()}get wordSpacing(){return this.wrapped.wordSpacing}set wordSpacing(e){this.wrapped.wordSpacing=e}get letterSpacing(){return this.wrapped.letterSpacing}set letterSpacing(e){this.wrapped.letterSpacing=e}get textRendering(){return this.wrapped.textRendering}set textRendering(e){this.wrapped.textRendering=e}reset(){this.wrapped.reset()}applyScale(e){return new on(this,e)}get canvas(){return this.wrapped.canvas}get miterLimit(){return this.wrapped.miterLimit}set miterLimit(e){this.wrapped.miterLimit=this.scale_.x.dim(e)}get globalAlpha(){return this.wrapped.globalAlpha}set globalAlpha(e){this.wrapped.globalAlpha=e}get globalCompositeOperation(){return this.wrapped.globalCompositeOperation}set globalCompositeOperation(e){this.wrapped.globalCompositeOperation=e}get fillStyle(){return this.wrapped.fillStyle}set fillStyle(e){this.wrapped.fillStyle=e}get strokeStyle(){return this.wrapped.strokeStyle}set strokeStyle(e){this.wrapped.strokeStyle=e}drawImage(e,t,s,r,i,a,l,c,h){this.wrapped.drawImage(e,t,s,r,i,a,l,c,h)}beginPath(){this.wrapped.beginPath()}clip(e,t){this.wrapped.clip(e,t)}fill(e,t){if(e==null)return this.wrapped.fill();this.wrapped.fill(e,t)}isPointInPath(e,t,s,r){return this.wrapped.isPointInPath(e,t,s,r)}isPointInStroke(e,t,s){return this.wrapped.isPointInStroke(e,t,s)}stroke(e){if(e==null)return this.wrapped.stroke();this.wrapped.stroke(e)}createConicGradient(e,t,s){return this.wrapped.createConicGradient(e,t,s)}createLinearGradient(e,t,s,r){return this.wrapped.createLinearGradient(e,t,s,r)}createPattern(e,t){return this.wrapped.createPattern(e,t)}createRadialGradient(e,t,s,r,i,a){return this.wrapped.createRadialGradient(e,t,s,r,i,a)}get filter(){return this.wrapped.filter}set filter(e){this.wrapped.filter=e}createImageData(e,t,s){return this.wrapped.createImageData(e,t,s)}getImageData(e,t,s,r,i){return this.wrapped.getImageData(e,t,s,r,i)}putImageData(e,t,s,r,i,a,l){this.wrapped.putImageData(e,t,s,r,i,a,l)}get imageSmoothingEnabled(){return this.wrapped.imageSmoothingEnabled}set imageSmoothingEnabled(e){this.wrapped.imageSmoothingEnabled=e}get imageSmoothingQuality(){return this.wrapped.imageSmoothingQuality}set imageSmoothingQuality(e){this.wrapped.imageSmoothingQuality=e}arc(e,t,s,r,i,a){this.wrapped.arc(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),r,i,a)}arcTo(e,t,s,r,i){this.wrapped.arcTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.dim(i))}bezierCurveTo(e,t,s,r,i,a){this.wrapped.bezierCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.pos(i),this.scale_.y.pos(a))}closePath(){this.wrapped.closePath()}ellipse(e,t,s,r,i,a,l,c){this.wrapped.ellipse(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),i,a,l,c)}lineTo(e,t){this.wrapped.lineTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}moveTo(e,t){this.wrapped.moveTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}quadraticCurveTo(e,t,s,r){this.wrapped.quadraticCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r))}rect(e,t,s,r){this.wrapped.rect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}roundRect(e,t,s,r,i){this.wrapped.roundRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),typeof i=="number"?this.scale_.x.dim(i):i)}get lineCap(){return this.wrapped.lineCap}set lineCap(e){this.wrapped.lineCap=e}get lineDashOffset(){return this.wrapped.lineDashOffset}set lineDashOffset(e){this.wrapped.lineDashOffset=this.scale_.x.dim(e)}get lineJoin(){return this.wrapped.lineJoin}set lineJoin(e){this.wrapped.lineJoin=e}get lineWidth(){return this.wrapped.lineWidth}set lineWidth(e){this.wrapped.lineWidth=this.scale_.x.dim(e)}getLineDash(){return this.wrapped.getLineDash()}setLineDash(e){const t=Array.from(e).map(s=>this.scale_.x.dim(s));this.wrapped.setLineDash(t)}clearRect(e,t,s,r){this.wrapped.clearRect(e,t,s,r)}fillRect(e,t,s,r){this.wrapped.fillRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}strokeRect(e,t,s,r){this.wrapped.strokeRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}get shadowBlur(){return this.wrapped.shadowBlur}set shadowBlur(e){this.wrapped.shadowBlur=e}get shadowColor(){return this.wrapped.shadowColor}set shadowColor(e){this.wrapped.shadowColor=e}get shadowOffsetX(){return this.wrapped.shadowOffsetX}set shadowOffsetX(e){this.wrapped.shadowOffsetX=e}get shadowOffsetY(){return this.wrapped.shadowOffsetY}restore(){this.wrapped.restore()}save(){this.wrapped.save()}fillText(e,t,s,r){this.wrapped.fillText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}measureText(e){this.wrapped.font=qn(this.wrapped.font,this.scale_.x.reverse());const t=this.wrapped.measureText(e);return this.wrapped.font=qn(this.wrapped.font,this.scale_.x),t}strokeText(e,t,s,r){this.wrapped.strokeText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}get direction(){return this.wrapped.direction}set direction(e){this.wrapped.direction=e}get font(){return this.wrapped.font}set font(e){this.wrapped.font=qn(e,this.scale_.x)}get fontKerning(){return this.wrapped.fontKerning}set fontKerning(e){this.wrapped.fontKerning=e}get textAlign(){return this.wrapped.textAlign}set textAlign(e){this.wrapped.textAlign=e}get textBaseline(){return this.wrapped.textBaseline}set textBaseline(e){this.wrapped.textBaseline=e}getTransform(){return this.wrapped.getTransform()}resetTransform(){this.wrapped.resetTransform()}rotate(e){this.wrapped.rotate(e)}scale(e,t){this.wrapped.scale(e,t)}scissor(e,t=o.q.ZERO){const s=new Path2D;return e=Ie(e,t),s.rect(...o.q.couple(o.Eo.topLeft(e)),...o._.couple(o.Eo.dims(e))),this.save(),this.clip(s),()=>this.restore()}setTransform(e,t,s,r,i,a){this.wrapped.setTransform(e,t,s,r,i,a)}transform(e,t,s,r,i,a){this.wrapped.transform(e,t,s,r,i,a)}translate(e,t){this.wrapped.translate(e,t)}}const sr=/(\d+(\.\d+)?)px/,qn=(n,e)=>{var r;const t=Number((r=n.match(sr))==null?void 0:r[1]);if(t==null)return n;const s=e.dim(t);return n.replace(sr,`${s}px`)},xc=`precision mediump float;
7
+
8
+ void main(void) {
9
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
10
+ }
11
+ `,vc=`attribute vec4 a_position;
12
+
13
+ void main(void) {
14
+ gl_Position = a_position;
15
+ }
16
+ `,rr=n=>new Error(`failed to compile webgl program: ${n}`),bc=new Error("null shader encountered");class Ss{constructor(e,t,s){u(this,"ctx");u(this,"prog");u(this,"vertShader");u(this,"fragShader");u(this,"uniformLocCache",new Map);this.ctx=e;const r=e.gl.createProgram();if(r==null)throw rr("failed to create program");this.prog=r,this.vertShader=t,this.fragShader=s,this.compile()}setAsActive(){return this.ctx.gl.useProgram(this.prog),()=>this.ctx.gl.useProgram(null)}uniformXY(e,t){this.ctx.gl.uniform2fv(this.getUniformLoc(e),o.q.couple(o.q.construct(t)))}uniformColor(e,t){this.ctx.gl.uniform4fv(this.getUniformLoc(e),t.rgba1)}getUniformLoc(e){const t=this.uniformLocCache.get(e);if(t!=null)return t;const s=this.ctx.gl.getUniformLocation(this.prog,e);if(s==null)throw new Error(`unexpected missing uniform ${e}`);return this.uniformLocCache.set(e,s),s}compile(){const e=this.ctx.gl;this.compileShader(this.vertShader,e.VERTEX_SHADER),this.compileShader(this.fragShader,e.FRAGMENT_SHADER),e.linkProgram(this.prog)}compileShader(e,t){const s=this.ctx.gl,r=s.createShader(t);if(r==null)throw bc;if(s.shaderSource(r,e),s.compileShader(r),!s.getShaderParameter(r,s.COMPILE_STATUS)){const a=s.getShaderInfoLog(r);throw s.deleteShader(r),rr(a??"unknown")}s.attachShader(this.prog,r)}}const Tc=new Float32Array([0,0,0,0,0,0]);class Sc extends Ss{constructor(t){super(t,vc,xc);u(this,"positionBuffer");const s=t.gl.createBuffer();if(s==null)throw new d.Ce("webgl: failed to create buffer");this.positionBuffer=s,t.gl.bindBuffer(t.gl.ARRAY_BUFFER,this.positionBuffer),t.gl.bufferData(t.gl.ARRAY_BUFFER,Tc,t.gl.STATIC_DRAW)}exec(){const{gl:t}=this.ctx,s=t.getAttribLocation(this.prog,"a_position");t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer);const r=t.createVertexArray();t.bindVertexArray(r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),this.setAsActive(),t.drawArrays(t.TRIANGLES,0,3)}}const ir={high:1,low:0},ar=d.P.hz(45);class Si{constructor(e){u(this,"mutex",new d.Mutex);u(this,"requests",new Map);u(this,"cleanup",new Map);u(this,"afterRender");this.start(),this.afterRender=e}async set(e){let t;e.priority==="high"&&(t=await this.mutex.acquire());const s=this.requests.get(e.key);if(s==null)this.requests.set(e.key,e);else{const r=ir[e.priority]>=ir[s.priority],i=e.canvases.length>=s.canvases.length;r&&i&&this.requests.set(e.key,e)}t==null||t()}async render(){await this.mutex.runExclusive(async()=>{var i;const e=performance.now(),{requests:t}=this;if(t.size===0)return;await this.runCleanupsSync(),await this.renderSync();const s=performance.now(),r=d.y.milliseconds(s-e);r.greaterThan(ar.period)&&console.warn(`Render loop for ${this.requests.size} took longer than ${ar.period.toString()} to execute: ${r.milliseconds}`),this.requests.clear(),(i=this.afterRender)==null||i.call(this)})}async runCleanupsSync(){const{cleanup:e,requests:t}=this;for(const[s,r]of e.entries()){const i=t.get(s);i!=null&&(await r(i),e.delete(s))}}async renderSync(){const{requests:e}=this;for(const t of e.values())try{const s=await t.render();s!=null&&this.cleanup.set(t.key,s)}catch(s){console.error(s)}}async start(){do{try{await this.render()}catch(e){console.error(e)}await this.sleep()}while(!0)}async sleep(){return await new Promise(requestAnimationFrame)}}var W;let q=(W=class{constructor(e,t,s,r){u(this,"glCanvas");u(this,"upper2dCanvas");u(this,"lower2dCanvas");u(this,"gl");u(this,"lower2d");u(this,"upper2d");u(this,"region");u(this,"dpr");u(this,"loop");u(this,"clearProgram");u(this,"os");this.upper2dCanvas=s,this.lower2dCanvas=t,this.glCanvas=e,this.os=r;const i=this.lower2dCanvas.getContext("2d");if(i==null)throw new Error("Could not get 2D context");this.lower2d=new on(i);const a=this.upper2dCanvas.getContext("2d");if(a==null)throw new Error("Could not get 2D context");this.upper2d=new on(a);const l={preserveDrawingBuffer:!0,powerPreference:"high-performance",stencil:!1,depth:!1},c=this.glCanvas.getContext("webgl2",l);if(c==null)throw new Error("Could not get WebGL context");c.disable(c.DEPTH_TEST),c.disable(c.STENCIL_TEST),c.disable(c.CULL_FACE),c.disable(c.DITHER),this.gl=c,this.glCanvas.oncontextlost=console.log;const h=()=>{this.gl.flush(),this.gl.finish()};this.loop=new Si(h),this.region=o.Eo.ZERO,this.dpr=1,this.os==="Windows"&&(this.clearProgram=new Sc(this))}static create(e,t,s,r,i){const a=new W(t,s,r,i);return e.set(W.CONTEXT_KEY,a),a}static useOptional(e){return e.getOptional(W.CONTEXT_KEY)}static use(e){return e.get(W.CONTEXT_KEY)}update(e){e.set(W.CONTEXT_KEY,this)}resize(e,t){o.Eo.equals(this.region,e)&&this.dpr===t||(this.region=e,this.dpr=t,this.resizeCanvas(this.glCanvas),this.resizeCanvas(this.upper2dCanvas),this.resizeCanvas(this.lower2dCanvas),this.lower2d.scale(this.dpr,this.dpr),this.upper2d.scale(this.dpr,this.dpr),this.gl.viewport(0,0,o.Eo.width(e)*t,o.Eo.height(e)*t))}resizeCanvas(e){e.width=o.Eo.width(this.region)*this.dpr,e.height=o.Eo.height(this.region)*this.dpr}get aspect(){return o.Eo.aspect(this.region)}scaleRegion(e){return new o.k$2.XY(o.k$2.Scale.scale(0,1).scale(o.Eo.width(e)).translate(o.Eo.left(e)).reBound(o.Eo.width(this.region)).scale(-1,1),o.k$2.Scale.scale(0,1).scale(o.Eo.height(e)).invert().translate(o.Eo.top(e)).reBound(o.Eo.height(this.region)).scale(-1,1).invert())}scissor(e,t=o.q.ZERO,s){const r=[];return s.includes("upper2d")&&r.push(this.upper2d.scissor(e,t)),s.includes("lower2d")&&r.push(this.lower2d.scissor(e,t)),s.includes("gl")&&r.push(this.scissorGL(e,t)),()=>r.forEach(i=>i())}scissorGL(e,t=o.q.ZERO){return this.gl.enable(this.gl.SCISSOR_TEST),e=Ie(e,t),this.gl.scissor(o.Eo.left(e)*this.dpr,(o.Eo.height(this.region)-o.Eo.bottom(e))*this.dpr,o.Eo.width(e)*this.dpr,o.Eo.height(e)*this.dpr),()=>this.gl.disable(this.gl.SCISSOR_TEST)}erase(e,t=o.q.ZERO,...s){t=o.q.construct(t),s.length===0&&(s=["upper2d","lower2d","gl"]),s.includes("upper2d")&&this.eraseCanvas(this.upper2d,e,t),s.includes("lower2d")&&this.eraseCanvas(this.lower2d,e,t),s.includes("gl")&&this.eraseGL(e,t)}eraseGL(e,t=o.q.ZERO){var i;const{gl:s}=this,r=this.scissorGL(Ie(e,t));s.clearColor(...o.ZERO.rgba1),s.clear(s.COLOR_BUFFER_BIT),this.os==="Windows"&&((i=this.clearProgram)==null||i.exec()),r()}eraseCanvas(e,t,s=o.q.ZERO){const r=Ie(t,s);e.clearRect(...o.q.couple(o.Eo.topLeft(r)),...o._.couple(o.Eo.dims(r)))}},u(W,"CONTEXT_KEY",o.CSS.B("render-context")),W);const Q="layout",Wn="data",it="tool";var K;let $=(K=class{constructor(e){u(this,"f");this.f=e}static control(e,t){e.set(K.CONTEXT_KEY,new K(t),!1)}static useRequest(e){return e.get(K.CONTEXT_KEY).f}static useOptionalRequest(e){var t;return((t=e.getOptional(K.CONTEXT_KEY))==null?void 0:t.f)??null}static requestRender(e,t){this.useRequest(e)(t)}},u(K,"CONTEXT_KEY","pluto-vis-renderer"),K),Ei=class{constructor(){u(this,"prevErase",o.Eo.ZERO)}erase(e,t,s,r,i){!o.Eo.equals(s,t)&&!o.Eo.equals(this.prevErase,s)?(e.erase(s,r,...i),this.prevErase=s):e.erase(t,r,...i)}};const ze=Ts.extend({bounds:o.G.bounds.optional(),autoBounds:p.z.object({lower:p.z.boolean().optional().default(!0),upper:p.z.boolean().optional().default(!0)}).or(p.z.boolean().optional().default(!0)),autoBoundPadding:p.z.number().optional(),autoBoundUpdateInterval:d.y.z.optional().default(d.y.seconds(2)),size:p.z.number().optional().default(0),label:p.z.string().optional().default(""),labelSize:p.z.number().optional().default(0)}).partial({color:!0,font:!0,gridColor:!0}),Ec=2,Cc=7,Ci=(n,e)=>o.G.contains({lower:n-Cc,upper:n+Ec},e),Rc=o.G.DECIMAL,or=d.m.now(),kc={lower:Number(or.valueOf()),upper:Number(or.add(d.y.HOUR).valueOf())},Ri=n=>n==="linear"?Rc:kc,Pc=(n,e=.1,t)=>{const s=o.G.max(n.filter(o.G.isFinite));if(!o.G.isFinite(s))return Ri(t);const{lower:r,upper:i}=s;if(i===r)return{lower:r-1,upper:i+1};const a=(i-r)*e;return{lower:r-a,upper:i+a}},Oc=.01,zc=.1;class ki extends d.Composite{async afterUpdate(){var t;this.internal.render=q.use(this.ctx);const e=d.use(this.ctx);(t=this.state).autoBoundPadding??(t.autoBoundPadding=o.g.construct(this.state.location)==="x"?zc:Oc),this.internal.core=new Ti(this.internal.render,{color:e.colors.gray.l8,font:d.fontString(e,{level:"small"}),gridColor:e.colors.gray.l1,...this.state}),$.requestRender(this.ctx,Q),this.internal.updateBounds==null&&(this.internal.updateBounds=d.r(s=>this.setState(r=>({...r,bounds:s})),this.state.autoBoundUpdateInterval.milliseconds))}async afterDelete(){$.requestRender(this.ctx,Q)}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{core:s}=this.internal,{grid:r,container:i}=e,a=Va(`${this.type}-${this.key}`,r,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:c}=s.render(l);Ci(this.state.size,c)||this.setState(h=>({...h,size:c}))}async bounds(e,t){var h,f;if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:r}=Pi(this.state.autoBounds);if(!s&&!r&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=g=>({upper:r||this.state.bounds==null?g.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?g.lower:this.state.bounds.lower});let a,l=null;try{const g=await t();a=Pc(g,this.state.autoBoundPadding,this.state.type)}catch(g){a=Ri(this.state.type),l=g}const c=i(a);return this.internal.boundSnapshot=c,(this.state.bounds==null||s&&this.state.bounds.lower!==c.lower||r&&this.state.bounds.upper!==c.upper)&&((f=(h=this.internal).updateBounds)==null||f.call(h,c)),[c,l]}async dataToDecimalScale(e,t,s){const[r,i]=await this.bounds(e,t),a=o.g.swap(o.g.construct(this.state.location));return[o.k$2.Scale.scale(r).scale(1).translate(-o.Eo.root(s)[a]).magnify(1/o.Eo.dim(s,a)),i]}}const Pi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:(n==null?void 0:n.lower)??!0,upper:(n==null?void 0:n.upper)??!0},Yc=`precision lowp float;
17
+ uniform lowp vec4 u_color;
18
+
19
+ void main(void) {
20
+ gl_FragColor = u_color;
21
+ }
22
+ `,Mc=`attribute float a_x;
23
+ attribute float a_y;
24
+ attribute lowp vec2 a_translate;
25
+
26
+ uniform lowp vec2 u_scale_aggregate;
27
+ uniform lowp vec2 u_offset_aggregate;
28
+
29
+ void main(void) {
30
+ vec2 transformed = u_scale_aggregate * vec2(a_x,a_y) + u_offset_aggregate;
31
+ transformed = transformed + a_translate;
32
+ gl_Position = vec4(transformed, 0.0, 1.0);
33
+ }
34
+ `,lr=d.g.FLOAT32.density.valueOf(),Oi=p.z.object({x:Xe,y:Xe,label:p.z.string().optional(),color:o.Color.z,strokeWidth:p.z.number().default(1),downsample:p.z.number().min(1).max(50).optional().default(1)}),Dc=(n,e,t)=>n===-1||e===-1||n>=t.length?NaN:Number(t[n].at(e)),Ac=d.y.milliseconds(2);o.q.NAN,o.q.NAN,o.ZERO;const Ct=class Ct extends Ss{constructor(t){super(t,Mc,Yc);u(this,"translationBufferCache",new Map);this.translationBufferCache=new Map}bindState({strokeWidth:t,color:s}){return this.uniformColor("u_color",s),this.attrStrokeWidth(t)}bindScale(t,s){const r=o.q.scale(t.scale,s.scale),i=o.q.translate(o.q.scale(s.scale,t.offset),s.offset);this.uniformXY("u_scale_aggregate",r),this.uniformXY("u_offset_aggregate",i)}draw({x:t,y:s,count:r,downsample:i,xOffset:a,yOffset:l},c){const{gl:h}=this.ctx;this.bindAttrBuffer("x",t.glBuffer,i,a),this.bindAttrBuffer("y",s.glBuffer,i,l),h.drawArraysInstanced(h.LINE_STRIP,0,r/i,c)}static create(t){const s=q.use(t),r=new Ct(s);return t.set(Ct.CONTEXT_KEY,r),r}static use(t){return t.get(Ct.CONTEXT_KEY)}bindAttrBuffer(t,s,r,i=0){const{gl:a}=this.ctx;a.bindBuffer(a.ARRAY_BUFFER,s);const l=a.getAttribLocation(this.prog,`a_${t}`);a.vertexAttribPointer(l,1,a.FLOAT,!1,lr*r,lr*i),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(t){const{gl:s}=this.ctx,r=`${this.ctx.aspect}:${t}`,i=this.translationBufferCache.get(r);if(i!=null)return s.bindBuffer(s.ARRAY_BUFFER,i.glBuffer),i;const a=s.createBuffer();if(a==null)throw new d.Ce("Failed to create buffer from WebGL context");const l=_c(this.ctx.aspect,t);s.bindBuffer(s.ARRAY_BUFFER,a),s.bufferData(s.ARRAY_BUFFER,l,s.DYNAMIC_DRAW);const c={glBuffer:a,jsBuffer:l};return this.translationBufferCache.set(r,c),c}attrStrokeWidth(t){const{gl:s}=this.ctx,{jsBuffer:r}=this.getAndBindTranslationBuffer(t),i=s.getAttribLocation(this.prog,"a_translate");return s.vertexAttribPointer(i,2,s.FLOAT,!1,0,0),s.enableVertexAttribArray(i),s.vertexAttribDivisor(i,1),r.length/2}};u(Ct,"CONTEXT_KEY","pluto-line-gl-program");let ln=Ct;class pe extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Oi)}async afterUpdate(){var s,r;if(this.deleted)return;const{internal:t}=this;t.xTelem=await X(this.ctx,this.state.x,t.xTelem),t.yTelem=await X(this.ctx,this.state.y,t.yTelem),t.instrumentation=ke(this.ctx,"line"),t.prog=ln.use(this.ctx),t.requestRender=$.useRequest(this.ctx),(s=t.stopListeningXTelem)==null||s.call(t),(r=t.stopListeningYTelem)==null||r.call(t),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender(Wn)),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender(Wn)),t.requestRender(Q)}async afterDelete(){var s,r,i,a;const{internal:t}=this;await((r=(s=t.xTelem).cleanup)==null?void 0:r.call(s)),await((a=(i=t.yTelem).cleanup)==null?void 0:a.call(i)),t.requestRender(Q)}async xBounds(){return(await this.internal.xTelem.value())[0]}async yBounds(){return(await this.internal.yTelem.value())[0]}async findByXValue(t,s){const{xTelem:r,yTelem:i}=this.internal,[,a]=await r.value();let[l,c]=[-1,-1];a.find((O,A)=>{const P=O.binarySearch(s),M=P>=0&&P<O.length;return M&&([l,c]=[P,A]),M});const{key:h}=this,{color:f,label:g}=this.state,m={key:h,color:f,label:g,position:{x:0,y:0},value:{x:NaN,y:NaN}};if(l===-1||c===-1)return m;const x=a[c];m.value.x=Dc(c,l,a);const[,v]=await i.value(),T=v.find(O=>o.G.contains(O.alignmentBounds,x.alignment+BigInt(l)));if(T==null)return m;const C=Number(T.alignment-x.alignment);return m.value.y=Number(T.at(l-C)),m.position={x:t.dataToDecimalScale.x.pos(m.value.x),y:t.dataToDecimalScale.y.pos(m.value.y)},m}async render(t){if(this.deleted)return;const{downsample:s}=this.state,{xTelem:r,yTelem:i,prog:a}=this.internal,{dataToDecimalScale:l,exposure:c}=t,[[,h],[,f]]=await Promise.all([r.value(),i.value()]);h.forEach(T=>T.updateGLBuffer(a.ctx.gl)),f.forEach(T=>T.updateGLBuffer(a.ctx.gl));const g=Nc(h,f,c,s,Ac);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:s,scale:o.k$2.xyScaleToTransform(l),props:t.region,ops:Uc(g)}));const m=a.setAsActive(),x=a.bindState(this.state),v=o.k$2.xyScaleToTransform(a.ctx.scaleRegion(t.region));g.forEach(T=>{const C=o.k$2.xyScaleToTransform(Zc(l,T));a.bindScale(C,v),a.draw(T,x)}),m()}}u(pe,"TYPE","line");const Lc=5e3,_c=(n,e)=>Ic($c(n),e).map((t,s)=>Math.floor(s/qc)*(1/(Lc*n))*t),qc=5,$c=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Ic=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},Zc=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Bc={[pe.TYPE]:pe},Nc=(n,e,t,s,r)=>{if(n.length===0||e.length===0)return[];const i=[];return n.forEach(a=>e.forEach(l=>{if(!Fc(a,l,r))return;let c=0,h=0;a.alignment<l.alignment?c=Number(l.alignment-a.alignment):l.alignment<a.alignment&&(h=Number(a.alignment-l.alignment));const f=Math.min(a.length-c,l.length-h);if(f===0)return;const g=o.j(Math.round(t*4*f),s,51);i.push({x:a,y:l,xOffset:c,yOffset:h,count:f,downsample:g})})),i},Uc=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Fc=(n,e,t)=>{if(!(n._timeRange!=null&&e._timeRange!=null))throw new d.Ce(`Encountered series without time range in buildDrawOperations. X series present: ${n._timeRange!=null}, Y series present: ${e._timeRange!=null}`);const r=n.timeRange.overlapsWith(e.timeRange,t),i=o.G.overlapsWith(n.alignmentBounds,e.alignmentBounds);return r&&i};class Gt{constructor(e,t){u(this,"canvas");u(this,"theme");this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...r}){return e==="x"?this.line({start:o.q.construct(o.Eo.left(t),s),end:o.q.construct(o.Eo.right(t),s),...r}):this.line({start:o.q.construct(s,o.Eo.top(t)),end:o.q.construct(s,o.Eo.bottom(t)),...r})}line({stroke:e,lineWidth:t,lineDash:s,start:r,end:i}){const a=this.canvas;a.strokeStyle=e.hex,a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...o.q.couple(r)),a.lineTo(...o.q.couple(i)),a.stroke()}circle({fill:e,radius:t,position:s}){const r=this.canvas;r.fillStyle=e.hex,r.beginPath(),r.arc(...o.q.couple(s),t,0,2*Math.PI),r.fill()}resolveColor(e,t){return e==null?this.resolveColor(t):typeof e=="function"?e(this.theme):new o.Color(e)}border({region:e,color:t,width:s,radius:r,location:i}){const a=this.canvas;a.strokeStyle=this.resolveColor(t,this.theme.colors.border).hex,a.lineWidth=s??this.theme.sizes.border.width,r??(r=this.theme.sizes.border.radius),i==null||i===!0?r>0?(a.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),r),a.stroke()):(a.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),a.stroke()):d.A(i).forEach(l=>{const[c,h]=o.Eo.edgePoints(e,l);a.beginPath(),a.moveTo(...o.q.couple(c)),a.lineTo(...o.q.couple(h)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:r,borderRadius:i,borderWidth:a,backgroundColor:l}){i==null&&(i=this.theme.sizes.border.radius),a==null&&(a=1);const c=this.canvas;c.fillStyle=this.resolveColor(l,this.theme.colors.gray.l1).hex,c.strokeStyle=this.resolveColor(r,this.theme.colors.border).hex,c.setLineDash([]),c.lineWidth=1,c.beginPath(),s?c.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),i):c.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),c.fill(),t&&this.border({region:e,color:r,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:r=o.J.TOP_LEFT,offset:i=o.q.ZERO}=e,a={...e.position};r.x==="right"?a.x-=t.width+i.x:a.x+=i.x,r.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:o.Eo.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(o.q.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:r="p"}){const i=d.fontString(this.theme,{level:r}),a=e.map(h=>d.dimensions(h,i,this.canvas)),l=this.theme.sizes.base*s,c=Math.max(...a.map(h=>h[o.g.dimension(t)]))+l;return[{[o.g.dimension(o.g.swap(t))]:Math.max(...a.map(h=>h[o.g.dimension(o.g.swap(t))])),[o.g.dimension(t)]:c*e.length-l},h=>{const f=d.fontString(this.theme,{level:r});this.canvas.font=f,this.canvas.fillStyle=this.theme.colors.text.hex,this.canvas.textBaseline="top",e.forEach((g,m)=>{this.canvas.fillText(g,h.x,h.y+c*m)})}]}drawTextInCenter({box:e,text:t,level:s}){const r=d.dimensions(t,this.canvas.font,this.canvas),i=o.Eo.positionInCenter(o.Eo.construct(o.q.ZERO,r),e);return this.text({text:t,position:o.Eo.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:r,shade:i,maxWidth:a,code:l}){this.canvas.font=d.fontString(this.theme,{level:s,weight:r,code:l}),i==null?this.canvas.fillStyle=this.theme.colors.text.hex:this.canvas.fillStyle=this.theme.colors.gray[`l${i}`].hex,this.canvas.textBaseline="top";let c;a!=null&&(c=this.canvas.scissor(o.Eo.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y),c==null||c()}}const Es=p.z.object({position:p.z.number().optional(),pixelPosition:p.z.number().optional(),dragging:p.z.boolean(),lineWidth:p.z.number().optional().default(1),lineDash:p.z.number().optional().default(20),color:o.Color.z});class It extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Es)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx);const t=d.use(this.ctx);this.internal.draw=new Gt(this.internal.renderCtx.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}updatePositions({decimalToDataScale:t,plot:s,container:r}){if(this.state.dragging&&this.state.pixelPosition!=null){const a=t.pos((this.state.pixelPosition-o.Eo.top(s)+o.Eo.top(r))/o.Eo.height(s));return this.setState(l=>({...l,position:a})),this.state.pixelPosition}if(this.state.position==null){const a=t.pos(.5);this.setState(l=>({...l,position:a}))}const i=t.reverse().pos(this.state.position)*o.Eo.height(s)+o.Eo.top(s)-o.Eo.top(r);return isNaN(i)||this.setState(a=>({...a,pixelPosition:i})),i}async render(t){if(this.deleted)return;const{renderCtx:s}=this.internal,{location:r,plot:i}=t,a=o.J.direction(r),{upper2d:l}=s,c=this.internal.draw;let h=this.updatePositions(t);h+=o.Eo.top(t.container),c.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:h}),l.fillStyle=this.state.color.hex,l.beginPath(),r==="left"?(l.moveTo(o.Eo.left(i),h),l.lineTo(o.Eo.left(i)-5,h-5),l.lineTo(o.Eo.left(i)-5,h+5)):r==="right"&&(l.moveTo(o.Eo.right(i),h),l.lineTo(o.Eo.right(i)+5,h-5),l.lineTo(o.Eo.right(i)+5,h+5)),l.closePath(),l.fill()}}u(It,"TYPE","Rule");const zi={[It.TYPE]:It},Gc=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:zi,Rule:It,ruleStateZ:Es},Symbol.toStringTag,{value:"Module"})),jc=ze.extend({location:o.J.x.optional().default("left")});class ge extends ki{constructor(){super(...arguments);u(this,"schema",ze)}async xBounds(){return o.G.max(await Promise.all(this.lines.map(async t=>await t.xBounds())))}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport),i=s.invert().reverse();if(this.renderAxis(t,i),await this.renderLines(t,s),await this.renderRules(t,i),r!=null)throw r}async renderLines({xDataToDecimalScale:t,plot:s,canvases:r,exposure:i},a){if(!r.includes("gl"))return;const l={region:s,dataToDecimalScale:new o.k$2.XY(t,a),exposure:i};await Promise.all(this.lines.map(async c=>await c.render(l)))}async renderRules({container:t,plot:s,canvases:r},i){if(!r.includes("upper2d"))return;const{location:a}=this.state,{render:l}=this.internal,c=o.Eo.construct(o.Eo.left(t),o.Eo.top(s),o.Eo.width(t),o.Eo.height(s)),h=l.scissor(c,o.q.ZERO,["upper2d"]),f={container:t,plot:s,decimalToDataScale:i,location:a};await Promise.all(this.rules.map(async g=>await g.render(f))),h()}async findByXValue({xDataToDecimalScale:t,plot:s,viewport:r,hold:i,exposure:a},l){const[c,h]=await this.dataToDecimalScale(i,this.dataBounds.bind(this),r);if(h!=null)throw h;const f=new o.k$2.XY(t,c),g={region:s,dataToDecimalScale:f,exposure:a};return(await Promise.all(this.lines.map(async m=>await m.findByXValue(g,l)))).map(m=>({...m,units:this.state.label}))}async dataBounds(){return await Promise.all(this.lines.map(async t=>await t.yBounds()))}get lines(){return this.childrenOfType(pe.TYPE)}get rules(){return this.childrenOfType(It.TYPE)}}u(ge,"TYPE","YAxis");const Yi=p.z.object({start:d.m.z,end:d.m.z});class cn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Yi)}async afterUpdate(){this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,d.use(this.ctx))}async render(){}}u(cn,"TYPE","range-annotation");const Mi=p.z.object({triggered:p.z.boolean(),status:d.specZ$1,sink:Sn.optional().default(bn),source:es.optional().default(Qn)});class un extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Mi)}async afterUpdate(){var r,i,a;const{sink:t,source:s}=this.state;this.internal.source=await X(this.ctx,s,this.internal.source),this.internal.sink=await Ee(this.ctx,t,this.internal.sink),this.state.triggered&&!this.prevState.triggered&&this.internal.sink.set(((r=this.state.status.data)==null?void 0:r.authority)!==d.Kg.Absolute.valueOf()).catch(console.error),await this.updateEnabledState(),(a=(i=this.internal).stopListening)==null||a.call(i),this.internal.stopListening=this.internal.source.onChange(()=>{this.updateEnabledState()})}async updateEnabledState(){const t=await this.internal.source.value();t.time.equals(this.state.status.time)||this.setState(s=>({...s,status:t,triggered:!1}))}async afterDelete(){this.asyncAfterDelete().catch(console.error)}async asyncAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}render(){}}u(un,"TYPE","Chip");const Di=p.z.object({}),cr="control-state-provider",Ai=d.Og.stateZ.extend({subjectColor:o.Color.z});class Zt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Di);u(this,"colors",new Map);u(this,"tracker");u(this,"disconnectTrackerChange");u(this,"obs",new Xn.Observer)}static use(t){return t.get(cr)}async afterUpdate(){const{internal:t}=this;t.instrumentation=ke(this.ctx,"control-state");const s=d.use(this.ctx);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l6;const r=Se(this.ctx);t.client!=null&&r===t.client||(t.client=r,this.ctx.set(cr,this),await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client)))}async maybeCloseTracker(){var t;this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),(t=this.disconnectTrackerChange)==null||t.call(this),await this.tracker.close(),this.tracker=void 0)}async afterDelete(){await this.maybeCloseTracker()}onChange(t){return this.obs.onChange(t)}get(t){return Array.isArray(t)?d.n(t).map(s=>this.getOne(s)).filter(s=>s!=null):this.getOne(t)}getOne(t){if(this.tracker==null)return;const s=this.tracker.states.get(t);if(s!=null)return{...s,subjectColor:this.colors.get(s.subject.key)??this.internal.defaultColor}}async openTracker(t){var i;const{internal:s}=this,{instrumentation:r}=s;try{this.tracker=await t.control.openStateTracker()}catch{r.L.error("failed to open state tracker");return}(i=this.disconnectTrackerChange)==null||i.call(this),this.disconnectTrackerChange=this.tracker.onChange(a=>{if(r.L.debug("transfer",{transfers:a.map(l=>d.Og.transferString(l))}),this.tracker==null)throw new d.Ce("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(a)})}updateColors(t){const s=t.subjects(),r=s.map(l=>l.key),i=Array.from(this.colors.values());this.colors.forEach((l,c)=>!r.includes(c)&&this.colors.delete(c));const{palette:a}=this.internal;s.forEach(l=>{if(this.colors.has(l.key))return;const c=a.find(h=>!i.includes(h))??a[0];this.colors.set(l.key,c),i.push(c)})}}u(Zt,"TYPE","StateProvider");const Li=["acquired","released","overridden","failed"],_i=p.z.enum(Li),qi=p.z.object({name:p.z.string(),authority:p.z.number().default(0),acquireTrigger:p.z.number(),status:_i.optional(),needsControlOf:d.dg.keyZ.array().optional().default([])});class hn extends d.Composite{constructor(){super(...arguments);u(this,"schema",qi);u(this,"registry",new Map);u(this,"writer")}async afterUpdate(){this.internal.instrumentation=ke(this.ctx),(this.internal.prevTrigger==null||Math.abs(this.state.acquireTrigger-this.internal.prevTrigger)>1)&&(this.internal.prevTrigger=this.state.acquireTrigger);const t=Se(this.ctx),s=Zt.use(this.ctx);this.internal.client=t,this.internal.client==null&&await this.release(),this.internal.stateProv=s,gr(this.ctx,this),this.internal.addStatus=d.useAggregate(this.ctx),this.state.acquireTrigger>this.internal.prevTrigger?(this.acquire(),this.internal.prevTrigger=this.state.acquireTrigger):this.state.acquireTrigger<this.internal.prevTrigger&&(this.release(),this.internal.prevTrigger=this.state.acquireTrigger)}async afterDelete(){await this.release()}async updateNeedsControlOf(){if(this.internal.client==null)throw new d.Ce("No cluster connected but channelKeys were requested");const t=new Set([]);for(const r of this.registry.keys())(await r.needsControlOf(this.internal.client)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);d.F.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==d.F.EQUAL&&this.setState(r=>({...r,needsControlOf:s}))}async acquire(){const{client:t,addStatus:s}=this.internal;if(t==null)return s({message:`Cannot acquire control on ${this.state.name} because no cluster has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const r=this.state.needsControlOf;if(r.length===0)return s({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});this.writer=await t.openWriter({start:d.I.now(),channels:r,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(r){this.setState(i=>({...i,status:"failed"})),s({message:`${this.state.name} failed to acquire control: ${r.message}`,variant:"error"})}}async release(){var t;try{await((t=this.writer)==null?void 0:t.close()),this.setState(s=>({...s,status:"released"}))}catch(s){this.internal.addStatus({message:`${this.state.name} failed to release control: ${s.message}`,variant:"error"})}finally{this.writer=void 0}}async set(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.write(t))}async setAuthority(t,s){var r;this.writer==null&&await this.acquire(),await((r=this.writer)==null?void 0:r.setAuthority(Object.fromEntries(t.map(i=>[i,s]))))}async releaseAuthority(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.setAuthority(Object.fromEntries(t.map(r=>[r,this.state.authority]))))}deleteTelem(t){this.registry.delete(t),this.updateNeedsControlOf()}create(t){const r=(()=>{switch(t.type){case me.TYPE:{const i=new me(this,t.props);return this.registry.set(i,null),i}case we.TYPE:{const i=new we(this,this.internal.stateProv,t.props);return this.registry.set(i,null),i}case ye.TYPE:return new ye(this,t.props);default:return null}})();return r!=null&&this.updateNeedsControlOf(),r}}u(hn,"TYPE","Controller");const $i=p.z.object({channel:p.z.number()});class me extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",$i);this.controller=t}invalidate(){}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){if(this.props.channel===0)return[];const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{client:s}=this.controller.internal;if(s==null)return;const r=await s.channels.retrieve(this.props.channel),i={[r.key]:t};if(r.index!==0){const a=await s.channels.retrieve(r.index);i[a.key]=d.I.now()}await this.controller.set(i)}}u(me,"TYPE","controlled-numeric-telem-sink");const Hc=n=>({type:me.TYPE,props:n,variant:"sink",valueType:"number"}),Ii=p.z.object({authority:p.z.number().default(d.Og.Authority.Absolute.valueOf()),channel:p.z.number()});class ye extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",Ii);this.controller=t}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{controller:s}=this,{client:r}=s.internal;if(r==null)return;const i=await r.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),t?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)}}u(ye,"TYPE","acquire-channel-control");const Wc=n=>({type:ye.TYPE,props:n,variant:"sink",valueType:"boolean"}),Zi=p.z.object({channel:p.z.number()});class we extends G{constructor(t,s,r){super(r);u(this,"prov");u(this,"valid",!1);u(this,"stopListening");u(this,"controller");u(this,"schema",Zi);this.prov=s,this.controller=t}async needsControlOf(){return[]}maybeRevalidate(){var r;if(this.valid)return;const{channel:t}=this.props;(r=this.stopListening)==null||r.call(this);const s=d.W.filterTransfersByChannelKey(t);this.stopListening=this.prov.onChange(i=>{var a;s(i).length!==0&&((a=this.notify)==null||a.call(this))}),this.valid=!0}async value(){this.maybeRevalidate();const t=d.I.now();if(this.props.channel===0)return{key:this.controller.key,variant:"disabled",message:"No Channel",time:t,data:{valid:!1,authority:0}};const s=this.prov.get(this.props.channel);return s==null?{key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:t,data:{valid:!0,color:void 0,authority:0}}:{key:s.subject.key,variant:s.subject.key===this.controller.key?"success":"error",message:`Controlled by ${s.subject.name}`,time:t,data:{valid:!0,color:s.subjectColor,authority:s.authority}}}async cleanup(){var t;this.controller.deleteTelem(this),(t=this.stopListening)==null||t.call(this)}}u(we,"TYPE","controlled-status-source");const Xc=n=>({type:we.TYPE,props:n,variant:"source",valueType:"status"}),Bi=p.z.object({statusSource:es.optional().default(Qn),colorSource:Rr.optional().default(xr),status:d.specZ$1,color:o.Color.z.optional()});class dn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Bi);u(this,"stopListeningStatus");u(this,"stopListeningColor")}async afterUpdate(){var s,r;const{internal:t}=this;t.statusSource=await X(this.ctx,this.state.statusSource,t.statusSource),t.colorSource=await X(this.ctx,this.state.colorSource,t.colorSource),await this.updateState(),(s=this.stopListeningStatus)==null||s.call(this),this.stopListeningStatus=t.statusSource.onChange(()=>{this.updateState()}),(r=this.stopListeningColor)==null||r.call(this),this.stopListeningColor=t.colorSource.onChange(()=>{this.updateState()})}async afterDelete(){this.internalAfterDelete().catch(console.error)}async internalAfterDelete(){var t,s,r,i;await((s=(t=this.internal.statusSource).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.colorSource).cleanup)==null?void 0:i.call(r))}async render(){}async updateState(){const t=await this.internal.colorSource.value(),s=await this.internal.statusSource.value();t.equals(this.state.color)&&s.message===this.state.status.message||this.setState(r=>({...r,color:t,status:s}))}}u(dn,"TYPE","Indicator");const Ni=p.z.object({needsControlOf:d.dg.keyZ.array(),states:Ai.array()});class fn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ni)}async afterUpdate(){var a;const{internal:t}=this;t.stateProv=Zt.use(this.ctx);const s=this.state.needsControlOf;(a=t.disconnectStateProv)==null||a.call(t);const r=d.W.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(l=>({...l,states:i})),t.disconnectStateProv=t.stateProv.onChange(l=>{if(r(l).length===0)return;const c=t.stateProv.get(s);this.setState(h=>({...h,states:c}))})}async afterDelete(){var s;const{internal:t}=this;(s=t.disconnectStateProv)==null||s.call(t)}async render(){}}u(fn,"TYPE","Legend");const Vc={[hn.TYPE]:hn,[Zt.TYPE]:Zt,[dn.TYPE]:dn,[un.TYPE]:un,[fn.TYPE]:fn},Ui=p.z.object({trigger:p.z.number(),sink:Sn.optional().default(bn)});class pn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ui)}async afterUpdate(){const{sink:t}=this.state;this.internal.prevTrigger==null&&(this.internal.prevTrigger=this.state.trigger),this.internal.sink=await Ee(this.ctx,t,this.internal.sink);const s=this.internal.prevTrigger;this.internal.prevTrigger=this.state.trigger,!(this.state.trigger<=s)&&this.internal.sink.set(!0).catch(console.error)}render(){}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var s,r;const{internal:t}=this;await((r=(s=t.sink).cleanup)==null?void 0:r.call(s))}}u(pn,"TYPE","Button");const Kc={[pn.TYPE]:pn},Cs=p.z.object({dpr:p.z.number(),region:o.Eo.box,bootstrap:p.z.boolean().optional().default(!1),bootstrapped:p.z.boolean().optional().default(!1),glCanvas:p.z.any().optional(),upper2dCanvas:p.z.any().optional(),lower2dCanvas:p.z.any().optional(),os:d.w.osZ});class xe extends d.Composite{constructor(){super(...arguments);u(this,"schema",Cs);u(this,"renderContextSet",!1)}async afterUpdate(){let t=q.useOptional(this.ctx);if(t==null){if(this.renderContextSet)throw new d.Ce("[vis.worker.Canvas] - expected render context to be set");if(!this.state.bootstrap)return;const{glCanvas:s,lower2dCanvas:r,upper2dCanvas:i,os:a}=this.state;if(s==null||r==null||i==null)throw new d.Ce("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");t=q.create(this.ctx,s,r,i,a),ln.create(this.ctx),this.setState(l=>({...l,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else t.update(this.ctx);t.resize(this.state.region,this.state.dpr)}}u(xe,"TYPE","Canvas");const Fi={[xe.TYPE]:xe},Jc=Object.freeze(Object.defineProperty({__proto__:null,Canvas:xe,REGISTRY:Fi,canvasStateZ:Cs},Symbol.toStringTag,{value:"Module"})),Rs=p.z.object({position:o.q.xy,zoom:p.z.number(),region:o.Eo.box,clearOverScan:o.q.crudeZ.optional().default(10),visible:p.z.boolean().optional().default(!0)}),_e=["upper2d","lower2d"],Rt=class Rt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Rt.stateZ)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx),this.internal.addStatus=d.useAggregate(this.ctx),$.control(this.ctx,()=>this.requestRender("low")),this.requestRender("high")}async afterDelete(){this.requestRender("high")}async render(){if(this.deleted)return;const{renderCtx:t,addStatus:s}=this.internal,{zoom:r,position:i}=this.state,a=o.Eo.construct(this.state.region);if(!this.state.visible)return async()=>t.erase(a,this.state.clearOverScan,..._e);const l=t.scissor(a,o.q.ZERO,_e),c=o.k$2.XY.magnify(o.q.construct(r)).translate(o.Eo.topLeft(a)).translate(i);try{await Promise.all(this.children.map(async f=>await f.render({viewportScale:c})))}catch(f){s({variant:"error",message:f.message})}finally{l()}const h=o.Eo.copy(this.state.region);return async()=>{this.internal.renderCtx.erase(h,this.state.clearOverScan,..._e)}}requestRender(t){const{renderCtx:s}=this.internal;s.loop.set({key:`${Rt.TYPE}-${this.key}`,render:this.render.bind(this),priority:t,canvases:_e})}};u(Rt,"TYPE","Diagram"),u(Rt,"stateZ",Rs);let Bt=Rt;const Gi={[Bt.TYPE]:Bt},Qc=Object.freeze(Object.defineProperty({__proto__:null,Diagram:Bt,REGISTRY:Gi,diagramStateZ:Rs},Symbol.toStringTag,{value:"Module"})),ji=p.z.object({region:o.Eo.box,enabled:p.z.boolean().optional().default(!1)});class gn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ji);u(this,"eraser",new Ei)}async afterUpdate(){this.deleted||(this.internal.render=q.use(this.ctx),await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]}))}async afterDelete(){await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]})}async render(){this.deleted||!this.state.enabled||this.internal.render.erase(this.state.region,o.q.construct(0),"gl","lower2d","upper2d")}}u(gn,"TYPE","eraser");const tu={[gn.TYPE]:gn},Hi=p.z.object({enabled:p.z.boolean(),source:ts.optional().default(Jn)});class mn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Hi)}async afterUpdate(){var r;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{source:t}=this.state,{internal:s}=this;this.internal.source=await X(this.ctx,t,this.internal.source),await this.updateEnabledState(),(r=s.stopListening)==null||r.call(s),s.stopListening=s.source.onChange(()=>this.updateEnabledState().catch(this.reportError.bind(this)))}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Light: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t))}async render(){}}u(mn,"TYPE","Light");const eu={[mn.TYPE]:mn},ks=p.z.object({position:o.q.xy.or(p.z.null()),textColor:o.Color.z.optional().default(o.ZERO),backgroundColor:o.Color.z.optional().default(o.ZERO),borderColor:o.Color.z.optional().default(o.ZERO),ruleColor:o.Color.z.optional().default(o.ZERO),ruleStrokeWidth:p.z.number().optional().default(1),ruleStrokeDash:p.z.number().default(0)});class Nt extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ks)}async afterUpdate(){const t=d.use(this.ctx);this.state.textColor.isZero&&(this.state.textColor=t.colors.text),this.state.backgroundColor.isZero&&(this.state.backgroundColor=t.colors.gray.l1),this.state.borderColor.isZero&&(this.state.borderColor=t.colors.border),this.state.ruleColor.isZero&&(this.state.ruleColor=t.colors.gray.l5),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}async render(t){if(this.deleted||this.state.position==null)return;const{region:s}=t,r=o.k$2.XY.scale(o.Eo.DECIMAL).scale(s),i=o.k$2.XY.scale(s).scale(o.Eo.DECIMAL),a=await t.findByXDecimal(i.x.pos(this.state.position.x)),l=a.filter(v=>o.q.isFinite(v.value)),{draw:c}=this.internal,h=l.reduce((v,T)=>v+T.position.x,0)/l.length,f=new d.m(l.reduce((v,T)=>v+T.value.x,0)/l.length),g=r.x.pos(h);if(!o.G.contains(o.Eo.xBounds(s),g))return;c.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:s,position:g}),l.forEach(v=>{const T=r.pos(v.position);c.circle({fill:v.color.setAlpha(.5),radius:8,position:T}),c.circle({fill:v.color.setAlpha(.8),radius:5,position:T}),c.circle({fill:v.color.pickByContrast(this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:T})});const m=a.map(v=>`${v.label??""}: ${v.value.y.toFixed(2)}`);m.unshift(`Time: ${f.fString("preciseDate","local")}`);const x=i.pos(this.state.position);c.textContainer({text:m,backgroundColor:this.state.backgroundColor,borderColor:this.state.borderColor,position:this.state.position,direction:"y",level:"small",spacing:.5,offset:{x:12,y:12},root:{x:x.x>.8?"right":"left",y:x.y>.8?"top":"bottom"}})}}u(Nt,"TYPE","tooltip");const Wi={[Nt.TYPE]:Nt},nu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Wi,Tooltip:Nt,tooltipStateZ:ks},Symbol.toStringTag,{value:"Module"})),Xi=p.z.object({region:o.Eo.box,wheelPos:p.z.number(),scrolling:p.z.boolean(),empty:p.z.boolean(),visible:p.z.boolean(),telem:Xe.optional().default(vr),font:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),overshoot:o.q.xy.optional().default({x:0,y:0})}),su=.98,Xt="lower2d",ru={offset:0n,offsetRef:0n,scrollRef:0},ee=class ee extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ee.z);u(this,"values",new d.Ct([]));u(this,"scrollState",ru)}async afterUpdate(){var c;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem);const{scrolling:s,wheelPos:r}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const h=this.values.alignmentBounds.upper-1n;this.scrollState={offset:h,offsetRef:h,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:h,values:f}=this,g=Math.ceil((r-this.scrollState.scrollRef)/this.lineHeight);h.offset=this.values.traverseAlignment(h.offsetRef,-BigInt(g)),h.offset<f.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(h.offset=f.alignmentBounds.lower,this.setState(m=>({...m,wheelPos:this.prevState.wheelPos}))),h.offset>=f.alignmentBounds.upper&&this.setState(m=>({...m,scrolling:!1}))}const[a,l]=await this.internal.telem.value();this.values=new d.Ct(l),this.checkEmpty(),(c=t.stopListeningTelem)==null||c.call(t),t.stopListeningTelem=t.telem.onChange(()=>this.internal.telem.value().then(([h,f])=>{this.checkEmpty(),this.values=new d.Ct(f),this.requestRender()})),this.requestRender()}checkEmpty(){const t=this.values.length===0;t!==this.state.empty&&this.setState(s=>({...s,empty:t}))}async afterDelete(){var r;const{telem:t,render:s}=this.internal;await((r=t.cleanup)==null?void 0:r.call(t)),s.erase(o.Eo.construct(this.state.region),o.q.ZERO,Xt)}requestRender(){const{render:t}=this.internal;t.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(),priority:"high",canvases:[Xt]})}get lineHeight(){return this.internal.theme.typography[this.state.font].size*this.internal.theme.sizes.base}get totalHeight(){return Math.ceil(this.values.length*this.lineHeight)}get visibleLineCount(){return Math.min(Math.floor((o.Eo.height(this.state.region)-12)/this.lineHeight),this.values.length)}async render(){const{render:t}=this.internal,s=this.state.region;if(o.Eo.areaIsZero(s))return;if(!this.state.visible)return async()=>t.erase(s,o.q.ZERO,Xt);let r;if(!this.state.scrolling)r=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const f=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));r=this.values.subAlignmentSpanIterator(f,this.visibleLineCount)}const i=this.state.region,a=t[Xt],l=new Gt(a,this.internal.theme),c=t.scissor(i,o.q.ZERO,[Xt]);this.renderElements(l,r),this.renderScrollbar(l),c();const h=o.Eo.copy(this.state.region);return async({canvases:f})=>t.erase(h,this.state.overshoot,...f)}renderScrollbar(t){const s=this.state.region,r=o.Eo.height(s)/this.totalHeight*o.Eo.height(s);if(r>=o.Eo.height(s)*su)return;let i=o.Eo.bottom(s)-r;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*o.Eo.height(s)),i<0&&(i=o.Eo.top(s)),t.container({region:o.Eo.construct({x:o.Eo.right(s)-6,y:i},{width:6,height:r}),bordered:!1,backgroundColor:a=>a.colors.gray.l4})}renderElements(t,s){const r=this.state.region;let i=0;for(const a of s){const l=this.values.dataType.equals(d.g.JSON)?JSON.stringify(a):a.toString();t.text({text:l,level:this.state.font,shade:9,position:o.q.translate(o.Eo.topLeft(r),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}};u(ee,"TYPE","log"),u(ee,"z",Xi);let ve=ee;const iu={[ve.TYPE]:ve},Ps=p.z.object({one:o.q.xy.nullable(),two:o.q.xy.nullable(),hover:o.q.xy.nullable(),color:p.z.union([o.Color.z,p.z.object({verticalLine:o.Color.z.optional().default(o.ZERO),horizontalLine:o.Color.z.optional().default(o.ZERO),obliqueLine:o.Color.z.optional().default(o.ZERO)})]).optional().default(o.ZERO),strokeWidth:p.z.number().optional().default(1),strokeDash:p.z.number().optional().default(2)});class Ut extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ps)}async afterUpdate(){const t=q.use(this.ctx);this.internal.theme=d.use(this.ctx),this.internal.render=t,this.internal.draw=new Gt(t.upper2d,this.internal.theme),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,Q)}get verticalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.verticalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.verticalLine}get horizontalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.horizontalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.horizontalLine}get obliqueLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.obliqueLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.obliqueLine}async find(t){const{one:s,two:r}=this.state;if(s==null||r==null)return null;const{one:i,two:a}=this.prevState,{dataOne:l,dataTwo:c}=this.internal;if(i!=null&&o.q.equals(s,i)&&a!=null&&o.q.equals(r,a)&&l!=null&&c!=null){const[C,O]=[await t.findByXValue(l.x),await t.findByXValue(c.x)];return C.length===0||O.length===0?null:[C.sort((A,P)=>o.q.distance(l,A.value)-o.q.distance(l,P.value))[0],O.sort((A,P)=>o.q.distance(c,A.value)-o.q.distance(c,P.value))[0]]}const h=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),[f,g]=[h.pos(s),h.pos(r)],[m,x]=[await t.findByXDecimal(f.x),await t.findByXDecimal(g.x)];if(m.length===0||x.length===0)return null;const[v,T]=[m.sort((C,O)=>o.q.distance(f,C.position)-o.q.distance(f,O.position))[0],x.sort((C,O)=>o.q.distance(g,C.position)-o.q.distance(g,O.position))[0]];return this.internal.dataOne=v.value,this.internal.dataTwo=T.value,[v,T]}async renderHover(t){if(this.state.hover==null)return;const s=this.state.hover,r=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),i=r.pos(s),a=await t.findByXDecimal(r.pos(s).x);if(a.length===0)return;const l=a.sort((h,f)=>o.q.distance(i,h.position)-o.q.distance(i,f.position))[0],{draw:c}=this.internal;c.circle({fill:l.color.setAlpha(.5),radius:9,position:r.reverse().pos(l.position)})}async render(t){if(this.deleted)return;await this.renderHover(t);const s=await this.find(t);if(s==null)return;const[r,i]=s,{draw:a}=this.internal,{strokeDash:l,strokeWidth:c}=this.state,h=o.k$2.XY.scale(o.Eo.DECIMAL).scale(t.region),f=h.pos(r.position),g=h.pos(i.position),m=new d.y(Math.abs(r.value.x-i.value.x)),x=Math.abs(r.value.y-i.value.y),v=x/m.seconds;a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(f.x,g.y),stroke:this.verticalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${x.toFixed(2)} ${r.units??""}`],direction:"x",position:o.q.construct(f.x,(f.y+g.y)/2),level:"small"}),a.line({start:o.q.construct(f.x,g.y),end:o.q.construct(g.x,g.y),stroke:this.horizontalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[m.truncate(d.y.MILLISECOND).toString()],direction:"x",position:o.q.construct((f.x+g.x)/2,g.y),level:"small"}),a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(g.x,g.y),stroke:this.obliqueLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${v.toFixed(2)} ${r.units??""} / S`],direction:"x",position:o.q.construct((f.x+g.x)/2,(f.y+g.y)/2),level:"small"}),a.circle({fill:r.color.setAlpha(.5),radius:8,position:f}),a.circle({fill:r.color.setAlpha(.8),radius:5,position:f}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:f}),a.circle({fill:i.color.setAlpha(.5),radius:8,position:g}),a.circle({fill:i.color.setAlpha(.8),radius:5,position:g}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:g})}}u(Ut,"TYPE","measure");const Vi={[Ut.TYPE]:Ut},au=Object.freeze(Object.defineProperty({__proto__:null,Measure:Ut,REGISTRY:Vi,measureStateZ:Ps},Symbol.toStringTag,{value:"Module"})),Ki=p.z.object({trigger:p.z.number(),command:p.z.number().optional(),value:p.z.number(),sink:Cr.optional().default(mr),source:Er.optional().default(yr)});class yn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ki)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,trigger:r,command:i}=this.state,{trigger:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r!==a&&i!=null&&this.internal.sink.set(i),await this.updateValue(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateValue().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Setpoint: ${t.message}`})}async updateValue(){const t=await this.internal.source.value();t!==this.state.value&&this.setState(s=>({...s,value:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(yn,"TYPE","Setpoint");const ou={[yn.TYPE]:yn},Ji=p.z.object({triggered:p.z.boolean(),enabled:p.z.boolean(),sink:Sn.optional().default(bn),source:ts.optional().default(Jn)});class wn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ji)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,triggered:r,enabled:i}=this.state,{triggered:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r&&!a&&await l.sink.set(!i),await this.updateEnabledState(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateEnabledState().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Toggle: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(wn,"TYPE","Toggle");const lu={[wn.TYPE]:wn},cu=p.z.object({box:o.Eo.box,telem:kr.optional().default(wr),level:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),precision:p.z.number().optional().default(2),minWidth:p.z.number().optional().default(60),width:p.z.number().optional()}),ur="upper2d",ne=class ne extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ne.z)}async afterUpdate(){var s;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem),(s=t.stopListening)==null||s.call(t),t.stopListening=this.internal.telem.onChange(()=>this.requestRender()),this.internal.requestRender=$.useOptionalRequest(this.ctx),this.requestRender()}async afterDelete(){var i;const{requestRender:t,telem:s,render:r}=this.internal;await((i=s.cleanup)==null?void 0:i.call(s)),t==null?r.erase(o.Eo.construct(this.state.box),o.q.ZERO,ur):t(Q)}requestRender(){const{requestRender:t}=this.internal;t!=null?t(Q):this.render({})}get fontHeight(){const{theme:t}=this.internal;return t.typography[this.state.level].size*t.sizes.base}maybeUpdateWidth(t){const{theme:s}=this.internal,r=t+s.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<r||this.state.minWidth>r&&this.state.width!==this.state.minWidth?this.setState(i=>({...i,width:Math.max(r,i.minWidth)})):this.state.width-this.fontHeight>r&&this.setState(i=>({...i,width:Math.max(r,i.minWidth)}))}async render({viewportScale:t=o.k$2.XY.IDENTITY}){const{render:s,telem:r}=this.internal,i=o.Eo.construct(this.state.box);if(o.Eo.areaIsZero(i))return;const a=s[ur].applyScale(t);let l=await r.value();const c=d.fontString(this.internal.theme,{level:this.state.level,code:!0});a.font=c;const h=this.fontHeight,f=l[0]=="-";f&&(l=l.slice(1));const{theme:g}=this.internal,m=d.dimensions(l,c,a).width+g.sizes.base;this.internal.requestRender==null&&s.erase(o.Eo.construct(this.prevState.box)),this.maybeUpdateWidth(m);const x=o.q.translate(o.Eo.topLeft(i),{x:6+h*.75,y:o.Eo.height(i)/2});a.textBaseline="middle",a.fillStyle=this.internal.textColor.hex,f&&a.fillText("-",...o.q.couple(o.q.translateX(x,-h*.6))),a.fillText(l,...o.q.couple(x))}};u(ne,"TYPE","value"),u(ne,"z",cu);let Ft=ne;const Qi={[Ft.TYPE]:Ft},uu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Qi,Value:Ft},Symbol.toStringTag,{value:"Module"})),hu=d.Bg.payloadZ.extend({viewport:o.G.bounds}),hr=n=>o.Color.z.safeParse(n).success,ta=p.z.object({cursor:o.q.xy.or(p.z.null()),hovered:hu.or(p.z.null()),count:p.z.number()});class be extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ta);u(this,"fetchedInitial",d.E.ZERO)}async afterUpdate(){const{internal:t}=this;t.render=q.use(this.ctx),t.draw=new Gt(t.render.upper2d,d.use(this.ctx)),t.ranges==null&&(t.ranges=new Map);const s=Se(this.ctx);s!=null&&(t.client=s,t.tracker==null&&(t.tracker=await t.client.ranges.openTracker(),t.tracker.onChange(async r=>{r.forEach(async i=>{i.variant==="delete"?t.ranges.delete(i.key):hr(i.value.color)&&t.ranges.set(i.key,i.value)}),$.requestRender(this.ctx,it),this.setState(i=>({...i,count:t.ranges.size}))}),$.requestRender(this.ctx,it)))}async fetchInitial(t){const{internal:s}=this;if(s.client==null||this.fetchedInitial.roughlyEquals(t,d.y.minutes(1)))return;this.fetchedInitial=t,(await s.client.ranges.retrieve(t)).forEach(i=>{hr(i.color)&&s.ranges.set(i.key,i)}),this.setState(i=>({...i,count:s.ranges.size}))}async render(t){const{dataToDecimalScale:s,region:r,viewport:i,timeRange:a}=t;await this.fetchInitial(a);const{draw:l,ranges:c}=this.internal,h=s.scale(o.Eo.xBounds(r)),f=this.state.cursor==null?null:this.state.cursor.x;let g=null;const m=l.canvas.scissor(o.Eo.construct({x:o.Eo.left(r),y:o.Eo.top(r)-35},{x:o.Eo.right(r),y:o.Eo.bottom(r)}));c.forEach(x=>{const v=o.Color.z.safeParse(x.color);if(!v.success)return;const T=v.data;let C=h.pos(Number(x.timeRange.start.valueOf()));const O=h.pos(Number(x.timeRange.end.valueOf()));if(O<o.Eo.left(r)||C>o.Eo.right(r))return;C=o.j(C,o.Eo.left(r)-2,o.Eo.right(r)-1);let A=!1;f!=null&&(A=o.G.contains({lower:C,upper:O},f)),A&&(g={key:x.key,name:x.name,color:x.color,timeRange:x.timeRange,viewport:{lower:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.start.valueOf())),upper:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.end.valueOf()))}}),l.container({region:o.Eo.construct({x:C,y:o.Eo.top(r)-1},{x:O,y:o.Eo.bottom(r)-1}),backgroundColor:T.setAlpha(.2),bordered:!1});const P=o.Eo.construct({x:C+1,y:o.Eo.top(r)-34},{x:O-1,y:o.Eo.top(r)-12});l.container({region:P,backgroundColor:o.Eo.width(P)<20?T.setAlpha(.4):M=>A?M.colors.gray.l2:M.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:T.setAlpha(.8)}),l.text({text:x.name,position:{x:C+8,y:o.Eo.top(r)-30},level:"small",shade:8,weight:500,maxWidth:O-C-16})}),m(),g!=null?this.setState(x=>({...x,hovered:g})):this.state.hovered&&this.setState(x=>({...x,hovered:null}))}}u(be,"TYPE","range-provider");const du={[cn.TYPE]:cn,[be.TYPE]:be},fu=ze;class Te extends ki{constructor(){super(...arguments);u(this,"schema",ze)}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(this.renderAxis(t,s.reverse()),await this.renderYAxes(t,s),await this.renderRangeAnnotations(t,s),r!=null)throw r}async findByXDecimal(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;return await this.findByXValue(t,r.reverse().pos(s))}async findByXValue(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;const a={...t,xDataToDecimalScale:r},l=this.yAxes.map(async c=>await c.findByXValue(a,s));return(await Promise.all(l)).flat()}async renderYAxes(t,s){const r={...t,xDataToDecimalScale:s};await Promise.all(this.yAxes.map(async i=>await i.render(r)))}get yAxes(){return this.childrenOfType(ge.TYPE)}get rangeAnnotations(){return this.childrenOfType(be.TYPE)}async renderRangeAnnotations(t,s){const[r,i]=await this.bounds(t.hold,this.dataBounds.bind(this));if(i!=null)throw i;await Promise.all(this.rangeAnnotations.map(async a=>await a.render({dataToDecimalScale:s,region:t.plot,viewport:t.viewport,timeRange:new d.E(r.lower,r.upper)})))}async dataBounds(){return await Promise.all(this.yAxes.map(async t=>await t.xBounds()))}}u(Te,"TYPE","XAxis");const ea=p.z.object({container:o.Eo.box,viewport:o.Eo.box,hold:p.z.boolean().optional().default(!1),grid:p.z.record(ni),visible:p.z.boolean().optional().default(!0),clearOverScan:o.q.crudeZ.optional().default(o.q.ZERO)}),pu=(n,e)=>{const t=o.Eo.width(n)*Math.sqrt(o.Eo.height(n)),s=o.Eo.width(e)*Math.sqrt(o.Eo.height(e));return t/s};class xn extends d.Composite{constructor(){super(...arguments);u(this,"schema",ea)}async afterUpdate(){this.internal.instrumentation=ke(this.ctx,"lineplot"),this.internal.aggregate=d.useAggregate(this.ctx),this.internal.renderCtx=q.use(this.ctx),$.control(this.ctx,t=>this.requestRender("low",t)),this.requestRender("high",Q)}async afterDelete(){this.internal.renderCtx=q.use(this.ctx),this.requestRender("high",Q)}async findByXDecimal(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXDecimal(s,t));return(await Promise.all(r)).flat()}async findByXValue(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXValue(s,t));return(await Promise.all(r)).flat()}get axes(){return this.childrenOfType(Te.TYPE)}get tooltips(){return this.childrenOfType(Nt.TYPE)}get measures(){return this.childrenOfType(Ut.TYPE)}get exposure(){return pu(this.state.viewport,this.state.container)}async renderAxes(t,s){const r={...this.state,plot:t,canvases:s,exposure:this.exposure};await Promise.all(this.axes.map(async i=>await i.render(r)))}async renderTooltips(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),region:t,canvases:s};await Promise.all(this.tooltips.map(async i=>await i.render(r)))}async renderMeasures(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:t,canvases:s};await Promise.all(this.measures.map(async i=>await i.render(r)))}calculatePlot(){return Ka(this.state.grid,this.state.container)}async render(t){const{renderCtx:s}=this.internal,{instrumentation:r}=this.internal;if(this.deleted){r.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return r.L.debug("not visible, skipping render",{key:this.key}),async({canvases:f})=>s.erase(this.state.container,this.state.clearOverScan,...f);const i=this.calculatePlot();r.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:t});const a=o.q.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,t.filter(f=>f!=="gl")),c=s.scissor(i,o.q.ZERO,t.filter(f=>f==="gl"));try{await this.renderAxes(i,t),await this.renderTooltips(i,t),await this.renderMeasures(i,t),s.gl.finish(),s.gl.flush(),s.gl.finish()}catch(f){if(f.message.toLowerCase().includes("bigint"))return;this.internal.aggregate({key:`${this.type}-${this.key}`,variant:"error",message:f.message})}finally{l(),c()}r.L.debug("rendered",{key:this.key});const h=o.Eo.copy(this.state.container);return async({canvases:f})=>s.erase(h,this.state.clearOverScan,...f)}requestRender(t,s){const{renderCtx:r}=this.internal;let i=["upper2d","lower2d","gl"];s===it&&(i=["upper2d"]),r.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(i),priority:t,canvases:i})}}u(xn,"TYPE","LinePlot");const gu={[xn.TYPE]:xn,[Te.TYPE]:Te,[ge.TYPE]:ge};exports.AcquireChannelControl=ye;exports.Annotation=cn;exports.AuthoritySource=we;exports.BaseProvider=At;exports.Button=pn;exports.Canvas=Ti;exports.Canvas$1=xe;exports.Chip=un;exports.Context=q;exports.Controller=$;exports.Controller$1=hn;exports.Diagram=Qc;exports.Diagram$1=Bt;exports.Eraser=Ei;exports.Eraser$1=gn;exports.GLProgram=Ss;exports.Indicator=dn;exports.Legend=fn;exports.Light=mn;exports.Line=pe;exports.LinePlot=xn;exports.Log=ve;exports.Loop=Si;exports.Measure=Ut;exports.Provider=Ze;exports.Provider$1=be;exports.Provider$2=Zn;exports.REASON_DATA=Wn;exports.REASON_LAYOUT=Q;exports.REASON_TOOL=it;exports.REGISTRY=Aa;exports.REGISTRY$1=Kc;exports.REGISTRY$10=du;exports.REGISTRY$11=zi;exports.REGISTRY$12=ou;exports.REGISTRY$13=dr;exports.REGISTRY$14=ei;exports.REGISTRY$15=lu;exports.REGISTRY$16=Wi;exports.REGISTRY$17=Qi;exports.REGISTRY$18=iu;exports.REGISTRY$2=Fi;exports.REGISTRY$3=Vc;exports.REGISTRY$4=Gi;exports.REGISTRY$5=tu;exports.REGISTRY$6=eu;exports.REGISTRY$7=Bc;exports.REGISTRY$8=gu;exports.REGISTRY$9=Vi;exports.Rule=It;exports.STATUSES=Li;exports.SetChannelValue=me;exports.Setpoint=yn;exports.StateProvider=Zt;exports.Toggle=wn;exports.Tooltip=Nt;exports.Value=Ft;exports.XAxis=Te;exports.YAxis=ge;exports.ZERO_CONTEXT_VALUE=Vn;exports.acquireChannelControl=Wc;exports.acquireChannelControlPropsZ=Ii;exports.aether=Gc;exports.annotationStateZ=Yi;exports.authoritySource=Xc;exports.authoritySourceProps=Zi;exports.axisStateZ=Ts;exports.buttonStateZ=Ui;exports.canvas=Jc;exports.canvasStateZ=Cs;exports.channelData=Lr;exports.chipStateZ=Mi;exports.color=Lt;exports.controllerStateZ=qi;exports.coreAxisStateZ=ze;exports.diagramStateZ=Rs;exports.eraserStateZ=ji;exports.external=Xa;exports.indicatorStateZ=Bi;exports.interpolateNumber=fe;exports.interpolateRgb=Fn;exports.interpolateString=oi;exports.legendStateZ=Ni;exports.lightStateZ=Hi;exports.linePlotStateZ=ea;exports.logState=Xi;exports.measure=au;exports.measureStateZ=Ps;exports.newTickFactory=Hn;exports.parseAutoBounds=Pi;exports.provider=wa;exports.providerStateZ=ta;exports.providerStateZ$1=Kr;exports.providerStateZ$2=cs;exports.regions=dt;exports.rollingAverage=Wr;exports.rollingAverageProps=ls;exports.ruleStateZ=Es;exports.setChannelValue=Hc;exports.setChannelValuePropsZ=$i;exports.setpoint=Ur;exports.setpointStateZ=Ki;exports.sinkPipeline=Dr;exports.sinkPipelinePropsZ=ss;exports.sourcePipeline=Mr;exports.sourcePipelinePropsZ=ns;exports.stateProviderStateZ=Di;exports.stateZ=Oi;exports.statusZ=_i;exports.streamChannelData=_r;exports.streamChannelValue=qr;exports.streamChannelValuePropsZ=rs;exports.stringifyNumber=Hr;exports.stringifyNumberProps=os;exports.sugaredStateZ=Ai;exports.tickFactoryProps=bs;exports.tickType=vs;exports.toggleStateZ=Ji;exports.tooltip=nu;exports.tooltipStateZ=ks;exports.value=uu;exports.withinBounds=Fr;exports.withinSizeThreshold=Ci;exports.xAxisStateZ=fu;exports.yAxisStateZ=jc;