@synnaxlabs/pluto 0.50.1 → 0.52.4
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.
- package/dist/{Animated-C4xrEVd-.js → Animated-6qL1fRZx.js} +61 -60
- package/dist/Animated-Bn4jMc7c.js +29 -0
- package/dist/Animated-vGAs0qOH.cjs +1 -0
- package/dist/Animated-xK__WUQp.cjs +1 -0
- package/dist/{Box-DLO7l9hM.js → Box-Bi280MYh.js} +28 -27
- package/dist/Box-CNUz5BsV.cjs +1 -0
- package/dist/Copy-CzkBKGca.js +337 -0
- package/dist/Copy-DuC8dTK7.cjs +1 -0
- package/dist/Dialog-DNrgykEv.cjs +1 -0
- package/dist/{Dialog-BspO7uo8.js → Dialog-Dos5l3K2.js} +13 -12
- package/dist/{Editable-DjQORuR1.js → Editable-4ZwvICC4.js} +46 -45
- package/dist/Editable-HUPqTaui.cjs +1 -0
- package/dist/{Haul-DBy-2ds_.js → Haul-CxbMtSY4.js} +18 -18
- package/dist/Haul-V5NQI3MY.cjs +1 -0
- package/dist/{Items-CX11yLMf.js → Items-CNPUoiob.js} +22 -21
- package/dist/Items-DYYNNIjr.cjs +4 -0
- package/dist/Menu-C0scum-k.cjs +1 -0
- package/dist/{Menu-GBo3ayoP.js → Menu-CTuOX5DR.js} +42 -41
- package/dist/Provider-DSMJjyuY.cjs +1 -0
- package/dist/{Provider-BkxUzTWS.js → Provider-ZIy-UlnE.js} +95 -93
- package/dist/Tags-6OV0_eBz.cjs +1 -0
- package/dist/{Tags-V7sNuGZv.js → Tags-BUDnOqms.js} +223 -222
- package/dist/{Text-XeD58Fq8.js → Text-BSTMZRuo.js} +717 -675
- package/dist/Text-C2_VsLzw.cjs +1 -0
- package/dist/Video-Bew5_j16.js +10 -0
- package/dist/Video-BryrVNlH.cjs +1 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/css-CloSmhZB.cjs +1 -0
- package/dist/css-D90kZTM8.js +63 -0
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -2
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +1 -1
- package/dist/dimensions-CdFEW3oU.cjs +1 -0
- package/dist/{dimensions-qj2CkPTy.js → dimensions-DbMN4145.js} +8 -8
- package/dist/{eraser-DuAfpO0P.js → eraser-BShvqlBE.js} +52 -49
- package/dist/eraser-rFMFKqsg.cjs +11 -0
- package/dist/eslint.config.d.ts +2 -2
- package/dist/eslint.config.d.ts.map +1 -1
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +65 -62
- package/dist/external--liXQuyF.cjs +1 -0
- package/dist/external-B3ipr7m2.cjs +1 -0
- package/dist/{external-Ct1k30Nd.js → external-B7UnU0MW.js} +27 -26
- package/dist/{external-PXU0gc_j.cjs → external-BRxBwBtj.cjs} +44 -44
- package/dist/{external-MvcifV4O.js → external-Ba2qQp_c.js} +3 -3
- package/dist/{external-g_vt4Lku.js → external-Bjd-DyWx.js} +22 -30
- package/dist/{external-B3o5P8Yw.cjs → external-BwbypKCk.cjs} +1 -1
- package/dist/external-C0rrTDhu.cjs +1 -0
- package/dist/{external-Dp5OkGYV.js → external-CG70NZqY.js} +97 -96
- package/dist/external-Ci1Iy9ku.js +32 -0
- package/dist/external-CmYpRWry.cjs +1 -0
- package/dist/{external-B-JsNciM.js → external-CoCI_tg5.js} +9 -8
- package/dist/{external-CLQdSLv0.js → external-Ctnukdzx.js} +10 -9
- package/dist/{external-DXWEyk9d.js → external-CvYxFUrc.js} +17 -17
- package/dist/{external-DNbIzfVy.js → external-Czkrdv2A.js} +55 -54
- package/dist/external-Czv2P05t.cjs +1 -0
- package/dist/{external-DxmgAHkn.js → external-DAotNquC.js} +3 -3
- package/dist/external-DFvPOUIQ.cjs +1 -0
- package/dist/{external-DojNoICL.cjs → external-DWEpl5aM.cjs} +1 -1
- package/dist/{external-xfkS0zGI.js → external-JwicH0Yv.js} +18 -17
- package/dist/external-N5bKB8Zx.cjs +1 -0
- package/dist/external-ZtJmVgiY.cjs +1 -0
- package/dist/external-ieDANY3X.cjs +28 -0
- package/dist/{external-sYHm9OG8.js → external-s6DOSL29.js} +16 -15
- package/dist/flex.cjs +1 -1
- package/dist/flex.js +1 -1
- package/dist/{fontString-CSWLcJcC.js → fontString-76R2eWDd.js} +3 -3
- package/dist/fontString-BNnhiwug.cjs +1 -0
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/hooks-C4ji1BSZ.cjs +1 -0
- package/dist/{hooks-BeSuo_di.js → hooks-CWEfATTF.js} +16 -16
- package/dist/index.cjs +35 -18
- package/dist/index.js +15379 -14087
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/{jsx-runtime-BbD0H88J.js → jsx-runtime-tc70JA_2.js} +2 -2
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/menu.cjs +1 -1
- package/dist/menu.js +1 -1
- package/dist/pluto.css +1 -1
- package/dist/provider-Bt-E2O6g.js +810 -0
- package/dist/provider-DQkVj3tA.cjs +10 -0
- package/dist/src/access/policy/queries.d.ts +6 -6
- package/dist/src/button/Copy.d.ts +28 -0
- package/dist/src/button/Copy.d.ts.map +1 -0
- package/dist/src/button/Copy.spec.d.ts +2 -0
- package/dist/src/button/Copy.spec.d.ts.map +1 -0
- package/dist/src/button/external.d.ts +1 -0
- package/dist/src/button/external.d.ts.map +1 -1
- package/dist/src/channel/queries.d.ts +1 -1
- package/dist/src/channel/queries.d.ts.map +1 -1
- package/dist/src/color/Provider.d.ts +11 -1
- package/dist/src/color/Provider.d.ts.map +1 -1
- package/dist/src/device/queries.d.ts +122 -72
- package/dist/src/device/queries.d.ts.map +1 -1
- package/dist/src/errors/Fallback.d.ts.map +1 -1
- package/dist/src/flux/base/store.d.ts +2 -2
- package/dist/src/flux/base/store.d.ts.map +1 -1
- package/dist/src/flux/retrieve.d.ts +1 -1
- package/dist/src/flux/retrieve.d.ts.map +1 -1
- package/dist/src/icon/EtherCAT.d.ts +2 -0
- package/dist/src/icon/EtherCAT.d.ts.map +1 -0
- package/dist/src/icon/registry.d.ts +3 -0
- package/dist/src/icon/registry.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/input/Numeric.d.ts.map +1 -1
- package/dist/src/json/SelectType.d.ts +8 -0
- package/dist/src/json/SelectType.d.ts.map +1 -0
- package/dist/src/json/external.d.ts +3 -0
- package/dist/src/json/external.d.ts.map +1 -0
- package/dist/src/json/index.d.ts +2 -0
- package/dist/src/json/index.d.ts.map +1 -0
- package/dist/src/json/primitive.d.ts +7 -0
- package/dist/src/json/primitive.d.ts.map +1 -0
- package/dist/src/json/primitive.spec.d.ts +2 -0
- package/dist/src/json/primitive.spec.d.ts.map +1 -0
- package/dist/src/label/queries.d.ts +30 -2
- package/dist/src/label/queries.d.ts.map +1 -1
- package/dist/src/lineplot/aether/XAxis.d.ts +40 -0
- package/dist/src/lineplot/aether/XAxis.d.ts.map +1 -1
- package/dist/src/lineplot/aether/YAxis.d.ts +40 -0
- package/dist/src/lineplot/aether/YAxis.d.ts.map +1 -1
- package/dist/src/lineplot/aether/axis.d.ts +20 -0
- package/dist/src/lineplot/aether/axis.d.ts.map +1 -1
- package/dist/src/lineplot/range/aether/provider.d.ts +90 -6
- package/dist/src/lineplot/range/aether/provider.d.ts.map +1 -1
- package/dist/src/lineplot/tooltip/aether/tooltip.d.ts +80 -0
- package/dist/src/lineplot/tooltip/aether/tooltip.d.ts.map +1 -1
- package/dist/src/log/aether/Log.d.ts +30 -0
- package/dist/src/log/aether/Log.d.ts.map +1 -1
- package/dist/src/pluto/aether/pluto.d.ts.map +1 -1
- package/dist/src/ranger/queries.d.ts +33 -5
- package/dist/src/ranger/queries.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Forms.d.ts +2 -0
- package/dist/src/schematic/symbol/Forms.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Primitives.d.ts +23 -0
- package/dist/src/schematic/symbol/Primitives.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Symbols.d.ts +14 -0
- package/dist/src/schematic/symbol/Symbols.d.ts.map +1 -1
- package/dist/src/schematic/symbol/queries.d.ts +6 -6
- package/dist/src/schematic/symbol/registry.d.ts +2 -0
- package/dist/src/schematic/symbol/registry.d.ts.map +1 -1
- package/dist/src/status/aether/errorHandler.d.ts.map +1 -1
- package/dist/src/status/queries.d.ts +3 -2
- package/dist/src/status/queries.d.ts.map +1 -1
- package/dist/src/table/cells/Cells.d.ts +20 -0
- package/dist/src/table/cells/Cells.d.ts.map +1 -1
- package/dist/src/telem/aether/static.d.ts +10 -0
- package/dist/src/telem/aether/static.d.ts.map +1 -1
- package/dist/src/telem/aether/transformers.d.ts +15 -0
- package/dist/src/telem/aether/transformers.d.ts.map +1 -1
- package/dist/src/telem/control/Controller.d.ts +1 -0
- package/dist/src/telem/control/Controller.d.ts.map +1 -1
- package/dist/src/telem/control/Legend.d.ts +4 -2
- package/dist/src/telem/control/Legend.d.ts.map +1 -1
- package/dist/src/telem/control/aether/controller.d.ts +10 -0
- package/dist/src/telem/control/aether/controller.d.ts.map +1 -1
- package/dist/src/telem/control/aether/indicator.d.ts +50 -0
- package/dist/src/telem/control/aether/indicator.d.ts.map +1 -1
- package/dist/src/telem/control/aether/legend.d.ts +22 -0
- package/dist/src/telem/control/aether/legend.d.ts.map +1 -1
- package/dist/src/telem/control/aether/state.d.ts +13 -0
- package/dist/src/telem/control/aether/state.d.ts.map +1 -1
- package/dist/src/theming/aether/provider.d.ts +1413 -3
- package/dist/src/theming/aether/provider.d.ts.map +1 -1
- package/dist/src/theming/base/theme.d.ts +941 -1
- package/dist/src/theming/base/theme.d.ts.map +1 -1
- package/dist/src/user/queries.d.ts +1 -1
- package/dist/src/vis/axis/axis.d.ts +20 -0
- package/dist/src/vis/axis/axis.d.ts.map +1 -1
- package/dist/src/vis/gauge/aether/gauge.d.ts +30 -0
- package/dist/src/vis/gauge/aether/gauge.d.ts.map +1 -1
- package/dist/src/vis/gauge/use.d.ts +10 -0
- package/dist/src/vis/gauge/use.d.ts.map +1 -1
- package/dist/src/vis/line/aether/line.d.ts +10 -0
- package/dist/src/vis/line/aether/line.d.ts.map +1 -1
- package/dist/src/vis/measure/aether/measure.d.ts +80 -0
- package/dist/src/vis/measure/aether/measure.d.ts.map +1 -1
- package/dist/src/vis/rule/aether/aether.d.ts +20 -0
- package/dist/src/vis/rule/aether/aether.d.ts.map +1 -1
- package/dist/src/vis/stateIndicator/aether/index.d.ts +2 -0
- package/dist/src/vis/stateIndicator/aether/index.d.ts.map +1 -0
- package/dist/src/vis/stateIndicator/aether/stateIndicator.d.ts +48 -0
- package/dist/src/vis/stateIndicator/aether/stateIndicator.d.ts.map +1 -0
- package/dist/src/vis/stateIndicator/index.d.ts +2 -0
- package/dist/src/vis/stateIndicator/index.d.ts.map +1 -0
- package/dist/src/vis/stateIndicator/use.d.ts +9 -0
- package/dist/src/vis/stateIndicator/use.d.ts.map +1 -0
- package/dist/src/vis/value/aether/value.d.ts +60 -0
- package/dist/src/vis/value/aether/value.d.ts.map +1 -1
- package/dist/src/vis/value/redline.d.ts +5 -0
- package/dist/src/vis/value/redline.d.ts.map +1 -1
- package/dist/src/vis/value/use.d.ts +20 -0
- package/dist/src/vis/value/use.d.ts.map +1 -1
- package/dist/src/workspace/queries.d.ts +1 -1
- package/dist/stylelint.config.d.ts +3 -0
- package/dist/stylelint.config.d.ts.map +1 -0
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/text.cjs +1 -1
- package/dist/text.js +2 -2
- package/dist/theme-dark.css +815 -0
- package/dist/theme-light.css +815 -0
- package/dist/theme.css +680 -680
- package/dist/theming.cjs +1 -1
- package/dist/theming.js +2 -2
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +1 -1
- package/dist/triggers.cjs +1 -1
- package/dist/triggers.js +1 -1
- package/dist/{types-B5-Tni3G.js → types-CGRCBVD4.js} +2 -2
- package/dist/{types-C0tUDfsz.cjs → types-DI2vtOGs.cjs} +1 -1
- package/dist/units-Bu36uC6z.cjs +1 -0
- package/dist/units-DMip-eZH.js +14 -0
- package/dist/value-Bfn0uQuG.cjs +53 -0
- package/dist/{value-BmuhX6zs.js → value-DimszMFu.js} +2108 -2057
- package/dist/video.cjs +1 -1
- package/dist/video.js +1 -1
- package/package.json +25 -21
- package/dist/Animated-BbeJdao0.js +0 -28
- package/dist/Animated-Dvm2k_z_.cjs +0 -1
- package/dist/Animated-umWjgTzy.cjs +0 -1
- package/dist/Box-D27bV7QJ.cjs +0 -1
- package/dist/Button-BSek5HG5.cjs +0 -1
- package/dist/Button-DLtxKGH5.js +0 -308
- package/dist/Dialog-BpjxXSmw.cjs +0 -1
- package/dist/Editable-C-z-stcD.cjs +0 -1
- package/dist/Haul-WgPKptr9.cjs +0 -1
- package/dist/Items-07R286kW.cjs +0 -4
- package/dist/Menu-58O-OOPJ.cjs +0 -1
- package/dist/Provider-BA3zQVbv.cjs +0 -1
- package/dist/Tags-DWsEZD9t.cjs +0 -1
- package/dist/Text-DW5FpCk9.cjs +0 -1
- package/dist/Video-C56z7qvH.js +0 -9
- package/dist/Video-CBPTBLTB.cjs +0 -1
- package/dist/css-BkBrZtKZ.js +0 -5328
- package/dist/css-D3NdC2sx.cjs +0 -8
- package/dist/dimensions-C7b02rFi.cjs +0 -1
- package/dist/eraser-Bocga8Eb.cjs +0 -11
- package/dist/external-5_uHky7w.cjs +0 -28
- package/dist/external-B9omdiDK.cjs +0 -1
- package/dist/external-BIbdeWQE.cjs +0 -1
- package/dist/external-BRA_zA83.cjs +0 -1
- package/dist/external-Bjh6lsVm.cjs +0 -1
- package/dist/external-BwRkgEyo.cjs +0 -1
- package/dist/external-CdHyPhLI.js +0 -31
- package/dist/external-Ct2A_YCT.cjs +0 -1
- package/dist/external-DT82RBon.cjs +0 -1
- package/dist/external-DyTk_hS7.cjs +0 -1
- package/dist/fontString-TocVNWmy.cjs +0 -1
- package/dist/hooks-Eb94kuDd.cjs +0 -1
- package/dist/provider-D0K9E52u.js +0 -16236
- package/dist/provider-DksyuJua.cjs +0 -78
- package/dist/units-Bd_mf9Ye.cjs +0 -1
- package/dist/units-CEfK1L7C.js +0 -14
- package/dist/value-CZfzRi_x.cjs +0 -53
package/dist/theming.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./Provider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./Provider-DSMJjyuY.cjs");const e=require("./external-DWEpl5aM.cjs");exports.Theming=e.external;
|
package/dist/theming.js
CHANGED
package/dist/tree.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./external-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./external-B3ipr7m2.cjs");exports.Tree=e.external;
|
package/dist/tree.js
CHANGED
package/dist/triggers.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./external-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./external-C0rrTDhu.cjs");exports.Triggers=e.external;
|
package/dist/triggers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const i=require("react"),n=require("zod"),a=e=>typeof e=="function",h=(e,t)=>a(e)?e(t):e,S=e=>t=>t==null?void 0:e(t),g=e=>t=>t==null?null:e(t),c=e=>m(e)?e():e,m=e=>typeof e=="function",E=({initial:e,value:t,onChange:s})=>{const[l,r]=i.useState(t??e);return t!=null&&s!=null?[t,s]:[l,r]},d=({initial:e,value:t,onChange:s})=>{const[l,r]=i.useState(c(t??e));return t!=null&&s!=null?[t,s]:[l,r]},f=(e,t)=>{const[s,l]=i.useState(()=>{const u=localStorage.getItem(t);return u==null?c(e):JSON.parse(u)}),r=i.useCallback(u=>{l(u),localStorage.setItem(t,JSON.stringify(u))},[l,t]);return[s,r]},p=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:c,executeSetter:h,isInitialSetter:m,isSetter:a,skipNull:g,skipUndefined:S,usePassthrough:E,usePersisted:f,usePurePassthrough:d},Symbol.toStringTag,{value:"Module"})),o=["h1","h2","h3","h4","h5","p","small"],
|
|
1
|
+
"use strict";const i=require("react"),n=require("zod"),a=e=>typeof e=="function",h=(e,t)=>a(e)?e(t):e,S=e=>t=>t==null?void 0:e(t),g=e=>t=>t==null?null:e(t),c=e=>m(e)?e():e,m=e=>typeof e=="function",E=({initial:e,value:t,onChange:s})=>{const[l,r]=i.useState(t??e);return t!=null&&s!=null?[t,s]:[l,r]},d=({initial:e,value:t,onChange:s})=>{const[l,r]=i.useState(c(t??e));return t!=null&&s!=null?[t,s]:[l,r]},f=(e,t)=>{const[s,l]=i.useState(()=>{const u=localStorage.getItem(t);return u==null?c(e):JSON.parse(u)}),r=i.useCallback(u=>{l(u),localStorage.setItem(t,JSON.stringify(u))},[l,t]);return[s,r]},p=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:c,executeSetter:h,isInitialSetter:m,isSetter:a,skipNull:g,skipUndefined:S,usePassthrough:E,usePersisted:f,usePurePassthrough:d},Symbol.toStringTag,{value:"Module"})),o=["h1","h2","h3","h4","h5","p","small"],z=n.z.enum(o),L=e=>{const t=o.indexOf(e);return t===-1||t===o.length-1?e:o[t+1]},O=n.z.union([n.z.number(),n.z.enum(["normal","bold","bolder","lighter"])]),I=n.z.object({size:n.z.number(),weight:n.z.union([n.z.number(),n.z.string()]),lineHeight:n.z.number(),textTransform:n.z.string().optional()}),N={tiny:"small",small:"small",medium:"p",large:"h5",huge:"h2"},P={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};exports.COMPONENT_SIZE_LEVELS=N;exports.LEVELS=o;exports.LEVEL_COMPONENT_SIZES=P;exports.downLevel=L;exports.executeInitialSetter=c;exports.executeSetter=h;exports.levelZ=z;exports.skipNull=g;exports.skipUndefined=S;exports.specZ=I;exports.state=p;exports.usePassthrough=E;exports.usePurePassthrough=d;exports.weightZ=O;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("@synnaxlabs/x"),n=(r,e,c)=>Object.fromEntries(c.map(t=>[`${r}-${t}`,o.color.hex(o.color.setAlpha(o.color.construct(e),t))])),s=(r,e,c=!1)=>{const t=`${r}${e}`;return c?`round(${t}, 1px)`:t};exports.createHexOpacityVariants=n;exports.unitProperty=s;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { color as s } from "@synnaxlabs/x";
|
|
2
|
+
const c = (r, e, o) => Object.fromEntries(
|
|
3
|
+
o.map((t) => [
|
|
4
|
+
`${r}-${t}`,
|
|
5
|
+
s.hex(s.setAlpha(s.construct(e), t))
|
|
6
|
+
])
|
|
7
|
+
), n = (r, e, o = !1) => {
|
|
8
|
+
const t = `${r}${e}`;
|
|
9
|
+
return o ? `round(${t}, 1px)` : t;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
c,
|
|
13
|
+
n as u
|
|
14
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";const x=require("@synnaxlabs/client"),r=require("@synnaxlabs/x"),h=require("zod"),w=require("./provider-DQkVj3tA.cjs"),I=require("./eraser-rFMFKqsg.cjs"),rn=require("@synnaxlabs/alamos"),Je=require("./fontString-BNnhiwug.cjs"),ge=require("./types-DI2vtOGs.cjs");require("react");const sr=require("./dimensions-CdFEW3oU.cjs");class Ur{entries=new Map;setListeners=new Map;deleteListeners=new Map;handleError;equal;constructor(e,t=()=>!1){this.handleError=e,this.equal=t}setOne(e,t,s,o){const i=this.entries.get(t),a=ge.executeSetter(s,i);if(!(a==null||i!=null&&this.equal(a,i,t)))return this.entries.set(t,a),this.notifySet(e,t,a,o),()=>{i===void 0?(this.entries.delete(t),this.notifyDelete(e,t)):(this.entries.set(t,i),this.notifySet(e,t,i,o))}}set(e,t,s,o){const i=[];if(Array.isArray(t))t.forEach(a=>{const l=this.setOne(e,a.key,a,s);l!=null&&i.push(l)});else if(typeof t=="object"&&"key"in t){const a=t,l=this.setOne(e,a.key,a,s);l!=null&&i.push(l)}else{const a=this.setOne(e,t,s,o);a!=null&&i.push(a)}return()=>i.reverse().forEach(a=>a())}get(e){return typeof e=="function"?Array.from(this.entries.values()).filter(e):Array.isArray(e)?e.map(t=>this.entries.get(t)).filter(t=>t!=null):this.entries.get(e)}list(){return Array.from(this.entries.values())}has(e){return Array.isArray(e)?e.every(t=>this.entries.has(t)):this.entries.has(e)}delete(e,t,s){const o=[];return typeof t=="function"?this.entries.forEach((i,a)=>{t(i,a)&&o.push({key:a,value:i})}):r.array.toArray(t).forEach(i=>{const a=this.entries.get(i);o.push({key:i,value:a})}),o.forEach(({key:i})=>{this.entries.delete(i),this.notifyDelete(e,i)}),()=>o.forEach(({key:i,value:a})=>{a!=null&&(this.entries.set(i,a),this.notifySet(e,i,a,s))})}clear(){this.entries.clear()}onSet(e,t,s){return this.setListeners.set(t,{scope:e,key:s}),()=>this.setListeners.delete(t)}onDelete(e,t,s){return this.deleteListeners.set(t,{scope:e,key:s}),()=>this.deleteListeners.delete(t)}notifySet(e,t,s,o){this.setListeners.forEach((i,a)=>{const l=i.key==null||i.key===t,u=i.scope!==e;l&&u&&this.handleError(async()=>await a(s,o),"Failed to notify set listener")})}notifyDelete(e,t){this.deleteListeners.forEach((s,o)=>{const i=s.key==null||s.key===t,a=s.scope!==e;i&&a&&this.handleError(async()=>await o(t),"Failed to notify delete listener")})}scope(e){return{set:(t,s,o)=>this.set(e,t,s,o),get:(t=>this.get(t)),list:()=>this.list(),has:t=>this.has(t),delete:(t,s)=>this.delete(e,t,s),onSet:(t,s)=>this.onSet(e,t,s),onDelete:(t,s)=>this.onDelete(e,t,s)}}}const Br=(n,e)=>Object.fromEntries(Object.entries(n).map(([t,{equal:s}])=>[t,new Ur(e,s)])),Dn=(n,e)=>Object.fromEntries(Object.entries(n).map(([t])=>[t,n[t].scope(e)])),ji=(n,e,t)=>n.set(e,s=>s==null?void 0:{...s,...t}),Wi=(n,e)=>{const t=n.includes("delete"),s=e.includes("delete");return t&&!s?-1:!t&&s?1:0},Vi=async({openStreamer:n,storeConfig:e,handleError:t,client:s,store:o})=>{const i=Object.values(e),a=r.unique.unique(i.flatMap(({listeners:f})=>f.map(({channel:p})=>p))),l={};i.forEach(({listeners:f})=>f.forEach(p=>{const{channel:g}=p;l[g]=[...l[g]||[],p]}));const u=await x.framer.HardenedStreamer.open(n,a),c=new x.framer.ObservableStreamer(u),d=f=>{const p=[...f.uniqueNames];p.sort(Wi),t(async()=>{for(const g of p){const T=f.get(g),y=l[g];if(y!=null)for(const{onChange:v,schema:R}of y)await t(async()=>{let L;T.dataType.equals(r.DataType.JSON)?L=T.parseJSON(R):L=Array.from(T).map(k=>R.parse(k));for(const k of L)await t(()=>v({changed:k,client:s,store:o}),`Failed to handle streamer change for ${g}`,x.NotFoundError)},`Failed to parse streamer change for ${g}`)}},`Failed to handle streamer change for ${r.strings.naturalLanguageJoin(p)}`)};return c.onChange(d),c.close.bind(c)};class Fr{store;streamCloser=null;client;constructor({client:e,openStreamer:t,storeConfig:s,handleError:o,handleAsyncError:i}){this.store=Br(s,o),this.client=e,e!=null&&(t??=e?.openStreamer.bind(e),this.streamCloser=Vi({client:e,storeConfig:s,handleError:i,store:Dn(this.store,""),openStreamer:t}))}async awaitInitialized(){this.streamCloser!=null&&await this.streamCloser}scopedStore(e){return Dn(this.store,e)}async close(){if(this.streamCloser==null)return;await(await this.streamCloser)()}}const Xi=h.z.object({props:x.synnaxParamsZ.nullable(),state:x.Synnax.connectivity.connectionStateZ.nullable()}),ms={client:null};let kt=class $r extends w.Composite{static TYPE="synnax.Provider";static stateZ=Xi;schema=$r.stateZ;afterUpdate(e){if(e.wasSetPreviously(gs)||En(e,ms),this.state.props==null){this.internal.client!=null&&(this.internal.client?.close(),this.internal.client=null),En(e,this.internal);return}this.prevState.props!=null&&r.deep.equal(this.state.props,this.prevState.props)&&this.internal.client!=null||(this.internal.client=new x.Synnax(this.state.props),En(e,this.internal))}};const gs="pluto-client-context",En=(n,e)=>n.set(gs,e),He=n=>n.get(gs)?.client??null,Hr={[kt.TYPE]:kt},Gi=Object.freeze(Object.defineProperty({__proto__:null,Provider:kt,REGISTRY:Hr,ZERO_CONTEXT_VALUE:ms,use:He},Symbol.toStringTag,{value:"Module"})),qr=h.object({}),An="flux-context",ys="flux.Provider",Ki=(n,e)=>n.get(An).scopedStore(e),Qi=n=>{const e=(t,s)=>{if("client"in n)return n.client;const o=He(t);return s!=null&&s?.client?.key===o?.key?s:new Fr({client:o,storeConfig:n.storeConfig,handleError:w.useErrorHandler(t),handleAsyncError:w.useAsyncErrorHandler(t)})};return class jr extends w.Composite{static TYPE=ys;static stateZ=qr;schema=jr.stateZ;afterUpdate(s){const{internal:o}=this;o.store=e(s,o.store),s.wasSetPreviously(An)||s.set(An,o.store)}}},Ji=n=>({[ys]:Qi(n)}),xs="pluto-vis-renderer",on=(n,e)=>{n.set(xs,e,!1)},an=n=>n.get(xs),bs=n=>n.getOptional(xs),ie=(n,e)=>an(n)(e),ea="relationships",ta="resources",na={channel:x.ontology.RELATIONSHIP_SET_CHANNEL_NAME,schema:x.ontology.relationshipZ,onChange:({store:n,changed:e})=>n.relationships.set(x.ontology.relationshipToString(e),e)},sa={channel:x.ontology.RELATIONSHIP_DELETE_CHANNEL_NAME,schema:x.ontology.relationshipZ,onChange:({store:n,changed:e})=>{n.relationships.delete(x.ontology.relationshipToString(e))}},ra={equal:(n,e)=>x.ontology.idsEqual(n.from,e.from)&&x.ontology.idsEqual(n.to,e.to)&&n.type===e.type,listeners:[na,sa]},oa={channel:x.ontology.RESOURCE_SET_CHANNEL_NAME,schema:x.ontology.resourceZ,onChange:async({store:n,changed:e})=>{n.resources.set(e.key,t=>t==null?e:{...t,...e})}},ia={channel:x.ontology.RESOURCE_DELETE_CHANNEL_NAME,schema:x.ontology.idZ,onChange:({store:n,changed:e})=>n.resources.delete(e.key)},aa={equal:(n,e)=>r.deep.equal(n,e),listeners:[oa,ia]},la="policies",ca={channel:x.access.policy.SET_CHANNEL_NAME,schema:x.access.policy.policyZ,onChange:({store:n,changed:e})=>n.policies.set(e.key,e)},ua={channel:x.access.policy.DELETE_CHANNEL_NAME,schema:x.access.policy.keyZ,onChange:({store:n,changed:e})=>n.policies.delete(e)},ha={listeners:[ca,ua]},Wr=(n,e)=>{const t=n.relationships.get(i=>x.ontology.matchRelationship(i,{from:{type:"role"},type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:e})),o=n.relationships.get(i=>t.some(a=>x.ontology.matchRelationship(i,{from:a.from,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:{type:"policy"}}))).map(i=>i.to.key);return n.policies.get(o)},da=async({client:n,store:e,subject:t})=>{let s=Wr(e,t);if(s.length>0)return s;s=await n.access.policies.retrieve({for:t}),e.policies.set(s);for(const o of s)(await n.ontology.retrieveParents([x.access.policy.ontologyID(o.key)],{types:["role"]})).forEach(a=>{const l={from:a.id,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:x.access.policy.ontologyID(o.key)};e.relationships.set(x.ontology.relationshipToString(l),l);const u={from:a.id,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:t};e.relationships.set(x.ontology.relationshipToString(u),u)});return s};function Ss(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function Vr(n,e){var t=Object.create(n.prototype);for(var s in e)t[s]=e[s];return t}function ht(){}var et=.7,_t=1/et,ke="\\s*([+-]?\\d+)\\s*",tt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",te="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",fa=/^#([0-9a-f]{3,8})$/,pa=new RegExp(`^rgb\\(${ke},${ke},${ke}\\)$`),ma=new RegExp(`^rgb\\(${te},${te},${te}\\)$`),ga=new RegExp(`^rgba\\(${ke},${ke},${ke},${tt}\\)$`),ya=new RegExp(`^rgba\\(${te},${te},${te},${tt}\\)$`),xa=new RegExp(`^hsl\\(${tt},${te},${te}\\)$`),ba=new RegExp(`^hsla\\(${tt},${te},${te},${tt}\\)$`),rr={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};Ss(ht,Oe,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:or,formatHex:or,formatHex8:Sa,formatHsl:Ta,formatRgb:ir,toString:ir});function or(){return this.rgb().formatHex()}function Sa(){return this.rgb().formatHex8()}function Ta(){return Xr(this).formatHsl()}function ir(){return this.rgb().formatRgb()}function Oe(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=fa.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?ar(e):t===3?new F(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?St(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?St(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=pa.exec(n))?new F(e[1],e[2],e[3],1):(e=ma.exec(n))?new F(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=ga.exec(n))?St(e[1],e[2],e[3],e[4]):(e=ya.exec(n))?St(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=xa.exec(n))?ur(e[1],e[2]/100,e[3]/100,1):(e=ba.exec(n))?ur(e[1],e[2]/100,e[3]/100,e[4]):rr.hasOwnProperty(n)?ar(rr[n]):n==="transparent"?new F(NaN,NaN,NaN,0):null}function ar(n){return new F(n>>16&255,n>>8&255,n&255,1)}function St(n,e,t,s){return s<=0&&(n=e=t=NaN),new F(n,e,t,s)}function va(n){return n instanceof ht||(n=Oe(n)),n?(n=n.rgb(),new F(n.r,n.g,n.b,n.opacity)):new F}function In(n,e,t,s){return arguments.length===1?va(n):new F(n,e,t,s??1)}function F(n,e,t,s){this.r=+n,this.g=+e,this.b=+t,this.opacity=+s}Ss(F,In,Vr(ht,{brighter(n){return n=n==null?_t:Math.pow(_t,n),new F(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?et:Math.pow(et,n),new F(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new F(ye(this.r),ye(this.g),ye(this.b),Ot(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:lr,formatHex:lr,formatHex8:wa,formatRgb:cr,toString:cr}));function lr(){return`#${pe(this.r)}${pe(this.g)}${pe(this.b)}`}function wa(){return`#${pe(this.r)}${pe(this.g)}${pe(this.b)}${pe((isNaN(this.opacity)?1:this.opacity)*255)}`}function cr(){const n=Ot(this.opacity);return`${n===1?"rgb(":"rgba("}${ye(this.r)}, ${ye(this.g)}, ${ye(this.b)}${n===1?")":`, ${n})`}`}function Ot(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function ye(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function pe(n){return n=ye(n),(n<16?"0":"")+n.toString(16)}function ur(n,e,t,s){return s<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new ee(n,e,t,s)}function Xr(n){if(n instanceof ee)return new ee(n.h,n.s,n.l,n.opacity);if(n instanceof ht||(n=Oe(n)),!n)return new ee;if(n instanceof ee)return n;n=n.rgb();var e=n.r/255,t=n.g/255,s=n.b/255,o=Math.min(e,t,s),i=Math.max(e,t,s),a=NaN,l=i-o,u=(i+o)/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/=u<.5?i+o:2-i-o,a*=60):l=u>0&&u<1?0:a,new ee(a,l,u,n.opacity)}function Ea(n,e,t,s){return arguments.length===1?Xr(n):new ee(n,e,t,s??1)}function ee(n,e,t,s){this.h=+n,this.s=+e,this.l=+t,this.opacity=+s}Ss(ee,Ea,Vr(ht,{brighter(n){return n=n==null?_t:Math.pow(_t,n),new ee(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?et:Math.pow(et,n),new ee(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,o=2*t-s;return new F(Cn(n>=240?n-240:n+120,o,s),Cn(n,o,s),Cn(n<120?n+240:n-120,o,s),this.opacity)},clamp(){return new ee(hr(this.h),Tt(this.s),Tt(this.l),Ot(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=Ot(this.opacity);return`${n===1?"hsl(":"hsla("}${hr(this.h)}, ${Tt(this.s)*100}%, ${Tt(this.l)*100}%${n===1?")":`, ${n})`}`}}));function hr(n){return n=(n||0)%360,n<0?n+360:n}function Tt(n){return Math.max(0,Math.min(1,n||0))}function Cn(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 Ts=n=>()=>n;function Ca(n,e){return function(t){return n+t*e}}function Ra(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 Pa(n){return(n=+n)==1?Gr:function(e,t){return t-e?Ra(e,t,n):Ts(isNaN(e)?t:e)}}function Gr(n,e){var t=e-n;return t?Ca(n,t):Ts(isNaN(n)?e:n)}const zn=(function n(e){var t=Pa(e);function s(o,i){var a=t((o=In(o)).r,(i=In(i)).r),l=t(o.g,i.g),u=t(o.b,i.b),c=Gr(o.opacity,i.opacity);return function(d){return o.r=a(d),o.g=l(d),o.b=u(d),o.opacity=c(d),o+""}}return s.gamma=n,s})(1);function La(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,s=e.slice(),o;return function(i){for(o=0;o<t;++o)s[o]=n[o]*(1-i)+e[o]*i;return s}}function ka(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function _a(n,e){var t=e?e.length:0,s=n?Math.min(t,n.length):0,o=new Array(s),i=new Array(t),a;for(a=0;a<s;++a)o[a]=ln(n[a],e[a]);for(;a<t;++a)i[a]=e[a];return function(l){for(a=0;a<s;++a)i[a]=o[a](l);return i}}function Oa(n,e){var t=new Date;return n=+n,e=+e,function(s){return t.setTime(n*(1-s)+e*s),t}}function nt(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function Ma(n,e){var t={},s={},o;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(o in e)o in n?t[o]=ln(n[o],e[o]):s[o]=e[o];return function(i){for(o in t)s[o]=t[o](i);return s}}var Yn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Rn=new RegExp(Yn.source,"g");function Da(n){return function(){return n}}function Aa(n){return function(e){return n(e)+""}}function Kr(n,e){var t=Yn.lastIndex=Rn.lastIndex=0,s,o,i,a=-1,l=[],u=[];for(n=n+"",e=e+"";(s=Yn.exec(n))&&(o=Rn.exec(e));)(i=o.index)>t&&(i=e.slice(t,i),l[a]?l[a]+=i:l[++a]=i),(s=s[0])===(o=o[0])?l[a]?l[a]+=o:l[++a]=o:(l[++a]=null,u.push({i:a,x:nt(s,o)})),t=Rn.lastIndex;return t<e.length&&(i=e.slice(t),l[a]?l[a]+=i:l[++a]=i),l.length<2?u[0]?Aa(u[0].x):Da(e):(e=u.length,function(c){for(var d=0,f;d<e;++d)l[(f=u[d]).i]=f.x(c);return l.join("")})}function ln(n,e){var t=typeof e,s;return e==null||t==="boolean"?Ts(e):(t==="number"?nt:t==="string"?(s=Oe(e))?(e=s,zn):Kr:e instanceof Oe?zn:e instanceof Date?Oa:ka(e)?La:Array.isArray(e)?_a:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?Ma:nt)(n,e)}function Ia(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}class ce extends r.observe.Observer{cleanup(){}}class Nn extends ce{static TYPE="noop-boolean-sink";set(){}}const cn={type:Nn.TYPE,props:{},variant:"sink",valueType:"boolean"};class Zn extends ce{static TYPE="noop-numeric-sink";set(){}}const Qr={type:Zn.TYPE,props:{},variant:"sink",valueType:"number"};class Un extends ce{static TYPE="noop-boolean-source";value(){return!1}}const vs={type:Un.TYPE,props:{},variant:"source",valueType:"boolean"};class Bn extends ce{static TYPE="noop-numeric-source";value(){return 0}}const ws={type:Bn.TYPE,props:{},variant:"source",valueType:"number"};class Fn extends ce{static TYPE="noop-string-sink";set(){}}const Jr={type:Fn.TYPE,props:{},variant:"sink",valueType:"string"};class $n extends ce{static TYPE="noop-string-source";value(){return""}}const Es={type:$n.TYPE,props:{},variant:"source",valueType:"string"};class Hn extends ce{static TYPE="noop-status-source";value(){return{key:"noop",name:"noop",variant:"disabled",message:"unknown",time:r.TimeStamp.now()}}}const Cs={type:Hn.TYPE,props:{},variant:"source",valueType:"status"};class qn extends ce{static TYPE="noop-color-source";value(){return r.color.ZERO}}const dt={type:qn.TYPE,props:{},variant:"source",valueType:"color"};class jn extends ce{static TYPE="noop-series";value(){return[r.bounds.ZERO,new r.MultiSeries([])]}}const eo={type:jn.TYPE,props:{},variant:"source",valueType:"series"},za={[Nn.TYPE]:Nn,[Zn.TYPE]:Zn,[Fn.TYPE]:Fn,[Un.TYPE]:Un,[Bn.TYPE]:Bn,[Hn.TYPE]:Hn,[qn.TYPE]:qn,[$n.TYPE]:$n,[jn.TYPE]:jn};class to{type="noop";create(e){const t=za[e.type];return t==null?null:new t}}const Ya=h.z.instanceof(ArrayBuffer),ft=h.z.object({type:h.z.string(),variant:h.z.enum(["source","sink","source-transformer","sink-transformer"]),valueType:h.z.string(),props:h.z.any(),transfer:h.z.array(Ya).optional()}),he=ft.extend({variant:h.z.literal("source")}),pt=ft.extend({variant:h.z.literal("sink")}),no=ft.extend({variant:h.z.literal("source-transformer")}),so=ft.extend({variant:h.z.literal("sink-transformer")}),Mt=he.extend({valueType:h.z.literal("series")}),Rs=he.extend({valueType:h.z.literal("boolean")}),un=pt.extend({valueType:h.z.literal("boolean")}),Na=so.extend({valueType:h.z.literal("boolean")}),Za=no.extend({valueType:h.z.literal("boolean")}),Ps=he.extend({valueType:h.z.literal("number")}),ro=pt.extend({valueType:h.z.literal("number")}),hn=he.extend({valueType:h.z.literal("color")}),Ls=he.extend({valueType:h.z.literal("status")}),dn=he.extend({valueType:h.z.literal("string")}),oo=pt.extend({valueType:h.z.literal("string")});let fn=class extends r.observe.BaseObserver{props_=void 0;uProps_=void 0;constructor(e){super(),this.uProps_=e}get props(){if(this.props_==null){const e=this.schema.safeParse(this.uProps_);if(e.success)this.props_=e.data;else throw new x.ValidationError(`[BaseTelem] - expected props to be valid, but found the following errors:
|
|
2
|
+
${e.error.message}`)}return this.props_}cleanup(){}};class W extends fn{}class pn extends fn{}class Se extends W{source_=void 0;get source(){if(this.source_==null)throw new x.ValidationError("[UnarySourceTransformer] - expected source to exist, but none was found.");return this.source_}value(){return this.transform(this.source.value())}onChange(e){return this.source.onChange(()=>{this.shouldNotify(this.source.value())&&e()})}setSources(e){this.source_=Object.values(e)[0]}shouldNotify(e){return!0}}class io extends W{sources={};value(){const e=Object.fromEntries(Object.entries(this.sources).map(([t,s])=>[t,s.value()]));return this.transform(e)}setSources(e){this.sources={...this.sources,...e}}}class ao extends fn{sinks={};get sink(){const[e]=Object.values(this.sinks);if(e==null)throw new x.ValidationError("[UnarySinkTransformer] - expected sink to exist, but none was found.");return e}set(...e){return this.sink.set(...this.transform(...e))}setSinks(e){this.sinks={...this.sinks,...e}}}const ks=h.z.object({from:h.z.string(),to:h.z.string()}),_s=h.z.object({connections:h.z.array(ks),outlet:h.z.string(),segments:h.z.record(h.z.string(),he)});class Os{type="pipeline";factory;constructor(e){this.factory=e}create(e){switch(e.type){case Dt.TYPE:return new Dt(e.props,this.factory);case At.TYPE:return new At(e.props,this.factory);default:return null}}}class Dt extends W{static TYPE="source-pipeline";schema=_s;sources={};get outlet(){const{outlet:e}=this.props,t=this.sources[e];if(t==null)throw new x.ValidationError(`[SourcePipeline] - expected source to exist at outlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:s,segments:o}=this.props;Object.entries(o).forEach(([i,a])=>{const l=t.create(a);l!=null&&(this.sources[i]=l)}),s.forEach(({from:i,to:a})=>{const l=this.sources[i],u=this.sources[a];l==null||u==null||"setSources"in u&&u.setSources({[i]:l})})}value(){return this.outlet.value()}onChange(e){return this.outlet.onChange(e)}cleanup(){Object.values(this.sources).forEach(e=>e.cleanup?.())}}const lo=(n,e)=>({variant:"source",props:e,type:Dt.TYPE,valueType:n}),Ms=h.z.object({connections:h.z.array(ks),inlet:h.z.string(),segments:h.z.record(h.z.string(),pt)});class At extends pn{static TYPE="sink-pipeline";schema=Ms;sinks={};get inlet(){const{inlet:e}=this.props,t=this.sinks[e];if(t==null)throw new x.ValidationError(`[SinkPipeline] - expected source to exist at inlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:s,segments:o}=this.props;Object.entries(o).forEach(([i,a])=>{const l=t.create(a);l!=null&&(this.sinks[i]=l)}),s.forEach(({from:i,to:a})=>{const l=this.sinks[i],u=this.sinks[a];l==null||u==null||"setSinks"in l&&l.setSinks({[a]:u})})}set(...e){return this.inlet.set(...e)}cleanup(){Object.values(this.sinks).forEach(e=>e.cleanup?.())}}const co=(n,e)=>({variant:"sink",props:e,type:At.TYPE,valueType:n}),Ds=h.z.object({channel:h.z.number().or(h.z.string())});class It extends W{static TYPE="stream-channel-value";schema=Ds;client;removeStreamHandler=null;leadingBuffer=null;valid=!1;onStatusChange;constructor(e,t,s){super(t),this.client=e,this.onStatusChange=s?.onStatusChange}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}cleanup(){this.removeStreamHandler?.(),this.valid=!1,this.leadingBuffer?.release(),this.leadingBuffer=null,this.removeStreamHandler=null}value(){return r.primitive.isZero(this.props.channel)?NaN:(this.valid||this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0?NaN:this.leadingBuffer.at(-1,!0))}async read(){try{this.valid=!0,this.removeStreamHandler?.();const e=await this.client.retrieveChannel(this.props.channel),t=s=>{const o=s.get(e.key);if(o==null)return;const i=o.series.at(-1);i!=null&&(i.acquire(),this.leadingBuffer?.release(),this.leadingBuffer=i),this.notify()};this.removeStreamHandler=await this.client.stream(t,[e.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to stream channel value"))}}}const uo=async(n,e,t)=>{const s=await n.retrieveChannel(e),o=x.channel.isCalculated(s);if(!t||s.isIndex)return{key:s.key,dataType:s.dataType,virtual:s.virtual,isCalculated:o};if(s.virtual&&!o)throw new x.NotFoundError("cannot use virtual channels as a data source");return{key:s.index,dataType:r.DataType.TIMESTAMP,virtual:!1,isCalculated:o}},Ua=h.z.object({timeRange:r.TimeRange.z,channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().default(!1)});class zt extends W{static TYPE="series-source";client;schema=Ua;data=new r.MultiSeries;valid=!1;channel=null;onStatusChange;constructor(e,t,s){super(t),this.client=e,this.onStatusChange=s?.onStatusChange}cleanup(){this.data.release(),this.valid=!1,this.channel=null}value(){const{channel:e,timeRange:t}=this.props;if(t.span.isZero||e===0)return[r.bounds.ZERO,this.data];this.valid||this.read();const{channel:s,data:o}=this;if(s==null)return[r.bounds.ZERO,this.data];let i=o.bounds;return s.dataType.equals(r.DataType.TIMESTAMP)&&(i=r.bounds.min([i,t.numericBounds])),[i,o]}async read(){try{this.valid=!0;const{timeRange:e,channel:t,useIndexOfChannel:s}=this.props;this.channel=await uo(this.client,t,s);const o=await this.client.read(e,this.channel.key);o.acquire(),this.data=o,this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to read channel data"))}}}const Ba=h.z.object({channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().default(!1),timeSpan:r.TimeSpan.z,keepFor:r.TimeSpan.z.optional()});class Yt extends W{static TYPE="dynamic-series-source";client;data=new r.MultiSeries([]);now;onStatusChange;channel=null;stopStreaming;valid=!1;schema=Ba;constructor(e,t,s,o=()=>r.TimeStamp.now()){super(t),this.client=e,this.now=o,this.onStatusChange=s?.onStatusChange}value(){const{channel:e,timeSpan:t}=this.props;if(e===0)return[r.bounds.ZERO,this.data];this.valid||this.read();const{data:s,channel:o}=this,i=this.now();if(o!=null&&o.dataType.isVariable)return[r.bounds.ZERO,this.data];const a=s.series.filter(u=>u.timeRange.end.after(i.sub(t))).map(u=>u.bounds),l=r.bounds.max(a);return o!=null&&o.dataType.equals(r.DataType.TIMESTAMP)&&(l.lower=Math.max(l.lower,l.upper-Number(t.valueOf()))),[l,this.data]}async read(){try{this.valid=!0;const{channel:e,useIndexOfChannel:t,timeSpan:s}=this.props;this.channel=await uo(this.client,e,t);const o=this.now().spanRange(-s);if(!this.channel.virtual||this.channel.isCalculated)try{const a=await this.client.read(o,this.channel.key);a.acquire(),this.data.push(a)}catch(a){if(a instanceof Error&&(a.message.includes("cannot open iterator on virtual channel")||a.message.includes("cannot read from free channel")))console.warn("failed to read calculated channel data",a);else throw a}this.stopStreaming?.();const i=a=>{if(this.channel==null)return;const l=a.get(this.channel.key);l!=null&&(l.acquire(),this.data.push(l),this.notify(),this.gcOutOfRangeData())};this.stopStreaming=await this.client.stream(i,[this.channel.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to stream channel data"))}}gcOutOfRangeData(){const e=this.now().sub(this.props.keepFor??this.props.timeSpan),t=this.data.series.findIndex(s=>s.timeRange.end.before(e));t!==-1&&(this.data.series.splice(t,1).forEach(s=>s.release()),this.gcOutOfRangeData())}cleanup(){this.stopStreaming?.(),this.stopStreaming=void 0,this.data.release(),this.valid=!1}}const Fa={[zt.TYPE]:zt,[Yt.TYPE]:Yt,[It.TYPE]:It};class ho{type="remote";client;constructor(e){this.client=e}create(e,t){const s=Fa[e.type];return s==null?null:new s(this.client,e.props,t)}}const fo=n=>({type:zt.TYPE,props:n,variant:"source",valueType:"series"}),po=n=>({type:Yt.TYPE,props:n,variant:"source",valueType:"series"}),mo=n=>({type:It.TYPE,props:n,variant:"source",valueType:"number"});class go{type="static";create(e){switch(e.type){case Wn.TYPE:return new Wn(e.props);case Nt.TYPE:return new Nt(e.props);case Zt.TYPE:return new Zt(e.props);case Ut.TYPE:return new Ut(e.props);case Bt.TYPE:return new Bt(e.props);default:return null}}}const As=h.z.object({data:h.z.array(r.typedArrayZ),offsets:h.z.array(h.z.number()).default([])});class Wn extends W{data;schema=As;static TYPE="static-series";constructor(e){super(e),this.data=this.props.data.map((t,s)=>new r.Series({data:t,dataType:r.DataType.FLOAT32,timeRange:r.TimeRange.ZERO,sampleOffset:this.props.offsets[s]??0}))}value(){return[r.bounds.max(this.data.map(t=>t.bounds)),this.data]}}const yo=As.extend({rate:r.Rate.z,yOffset:h.z.number().default(0),scroll:h.z.number().default(0),startPosition:h.z.number().default(0),scrollBounds:h.z.boolean().default(!1)});class Nt extends W{static TYPE="iterative-series";schema=yo;position;interval;data;constructor(e){super(e),this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((t,s)=>new r.Series({data:t,dataType:r.DataType.FLOAT32,timeRange:r.TimeRange.ZERO,sampleOffset:this.props.offsets[s]??0}))}value(){const e=this.data.map(s=>s.slice(0,this.position));if(this.props.scrollBounds){const s=e[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],o=e[0].data[this.position-1];return[{lower:Number(s),upper:Number(o)},new r.MultiSeries(e)]}return[r.bounds.max(e.map(s=>s.bounds)),new r.MultiSeries(e)]}start(e){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{this.notify?.(),this.position++},e.period.milliseconds)}cleanup(){clearInterval(this.interval),this.interval=void 0}}const xo=h.z.number();class Zt extends W{static TYPE="static-numeric";schema=xo;value(){return this.props}}const bo=h.z.string();class Ut extends W{static TYPE="static-string";schema=bo;value(){return this.props}}const So=r.color.crudeZ;class Bt extends W{static TYPE="static-color";schema=So;value(){return r.color.construct(this.props)}}const $a=n=>({type:Wn.TYPE,props:n,variant:"source",valueType:"series"}),Ha=n=>({type:Nt.TYPE,props:n,variant:"source",valueType:"series"}),qa=n=>({type:Zt.TYPE,props:n,variant:"source",valueType:"number"}),ja=n=>({type:Ut.TYPE,props:n,variant:"source",valueType:"string"}),Wa=n=>({type:Bt.TYPE,props:n,variant:"source",valueType:"color"});class To{type="transformer";create(e){switch(e.type){case Me.TYPE:return new Me(e.props);case De.TYPE:return new De(e.props);case Ae.TYPE:return new Ae(e.props);case Ie.TYPE:return new Ie(e.props);case ze.TYPE:return new ze(e.props);case Ft.TYPE:return new Ft(e.props);case Ye.TYPE:return new Ye(e.props);case Ne.TYPE:return new Ne(e.props)}return null}}const Va=h.z.object({truthy:h.z.number().default(1),falsy:h.z.number().default(0)}),vo=n=>({props:n,type:Me.TYPE,variant:"sink",valueType:"boolean"});class Me extends ao{static TYPE="boolean-numeric-converter-sink";static propsZ=Va;schema=Me.propsZ;transform(...e){return e.map(t=>t?this.props.truthy:this.props.falsy)}}const Is=h.z.object({trueBound:r.bounds.bounds}),wo=n=>({props:n,type:De.TYPE,variant:"source",valueType:"boolean"});class De extends Se{static TYPE="boolean-source";static propsZ=Is;schema=De.propsZ;curr=null;shouldNotify(e){const t=r.bounds.contains(this.props.trueBound,e)!==this.curr;return this.curr=r.bounds.contains(this.props.trueBound,e),t}transform(e){return this.curr=r.bounds.contains(this.props.trueBound,e),this.curr}}const Eo=h.z.object({});class Ae extends io{static TYPE="mean";static propsZ=Eo;schema=Ae.propsZ;transform(e){return Object.values(e).reduce((t,s)=>t+s,0)/Object.keys(e).length}}const Xa=n=>({props:n,type:Ae.TYPE,variant:"source",valueType:"boolean"}),Co=h.z.object({trueVariant:r.status.variantZ.default("success")});class Ie extends Se{static TYPE="boolean-status";static propsZ=Co;schema=Ie.propsZ;transform(e){return e.variant===this.props.trueVariant}}const Ga=n=>({props:n,type:Ie.TYPE,variant:"source",valueType:"boolean"}),zs=h.z.object({precision:h.z.number().default(2),prefix:h.z.string().default(""),suffix:h.z.string().default(""),notation:r.notation.notationZ.default("standard")});class ze extends Se{static TYPE="stringify-number";static propsZ=zs;schema=ze.propsZ;transform(e){if(isNaN(e))return"";const{precision:t,prefix:s,suffix:o,notation:i}=this.props;return`${s}${r.notation.stringifyNumber(e,t,i)}${o}`}}const Ro=n=>({props:n,type:ze.TYPE,variant:"source",valueType:"string"}),Ys=h.z.object({windowSize:h.z.number().default(5)});class Ft extends Se{static TYPE="rolling-average";static propsZ=Eo;schema=Ys;values=[];transform(e){return this.props.windowSize<2||isNaN(e)?e:this.values.reduce((t,s)=>t+s,0)/this.values.length}shouldNotify(e){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(e),this.values.length===this.props.windowSize)}}const Po=n=>({props:n,type:Ft.TYPE,variant:"source",valueType:"number"}),Lo=h.z.object({gradient:r.color.gradientZ});class Ye extends Se{static TYPE="color-gradient";static propsZ=Lo;schema=Ye.propsZ;transform(e){return r.color.fromGradient(this.props.gradient,e)}}const ko=n=>({props:n,type:Ye.TYPE,variant:"source",valueType:"color"}),_o=h.z.object({scale:r.scale.transform});class Ne extends Se{static TYPE="scale-number";static propsZ=_o;schema=Ne.propsZ;transform(e){if(isNaN(e))return e;const{offset:t,scale:s}=this.props.scale;return e*s+t}}const Oo=n=>({props:n,type:Ne.TYPE,variant:"source",valueType:"number"}),Ns=h.z.enum(["average","decimate"]),Ka=h.z.object({mode:Ns,windowSize:h.z.number().default(5)}),Qa=n=>({props:n,type:st.TYPE,variant:"source",valueType:"number"}),Mo=(n,e,t)=>{const s=e.length*t;for(let o=s;o<n.length;o+=t){const i=n.sub(o,o+1);i!==void 0&&e.write(i)}},Ja=(n,e,t)=>{const s=e.length*t;for(let o=s;o<n.length&&!(o+t>n.length);o+=t){const i=Math.min(o+t,n.length);let a=0,l=0;for(let u=o;u<i;u++){const c=n.at(u);c!==void 0&&typeof c=="number"&&(a+=c,l++)}l>0&&e.write(new r.Series({data:[a/l],dataType:n.dataType}))}},el={decimate:Mo,average:Ja};class st{static TYPE="series-downsampler";_downsample=null;cache=new r.MultiSeries;props;constructor(e){this.props=e}downsample(e){return this._downsample==null&&(e.series[0].sampleOffset!==0?this._downsample=Mo:this._downsample=el[this.props.mode]),this._downsample}transform(e){if(this.props.mode==="decimate"||this.props.windowSize<=1)return e;if(e.series.length===0)return this.cache;for(;this.cache.series.length>0&&!this.cache.series[0].key.startsWith(e.series[0].key);)this.cache.series.shift();return e.series.forEach((t,s)=>{let o=this.cache.series.at(s);if(o==null){const i=Math.ceil(t.capacity/this.props.windowSize);o=r.Series.alloc({key:t.key+r.id.create(),dataType:t.dataType,capacity:i,alignment:t.alignment,alignmentMultiple:BigInt(this.props.windowSize),sampleOffset:t.sampleOffset,timeRange:t.timeRange}),this.cache.push(o)}else if(!o.key.startsWith(t.key))throw new x.UnexpectedError(`[SeriesDownsampler] - expected series with key ${t.key} to be in cache, but found ${o.key}`);this.downsample(e)(t,o,this.props.windowSize)}),this.cache}}const tl=n=>({props:n,type:st.TYPE,variant:"source",valueType:"series"});class Zs{factories;type="compound";constructor(e){this.factories=e}add(e){this.factories=[...this.factories.filter(t=>t.type!==e.type),e]}create(e,t){for(const s of this.factories){const o=s.create(e,t);if(o!=null)return o}return null}}const Do=n=>{const e=[new To,new go,new to],t=new Zs(e);return n!=null&&t.add(new ho(n)),t.add(new Os(t)),t};let Ao=class Io{factory;key;parent;constructor(e,t){this.factory=e,this.key=r.id.create(),this.parent=t}child(e,t){const s=new Zs([...this.factory.factories,...r.array.toArray(e)]);return s.add(new Os(s)),new Io(s,t)}create(e,t){const s=this.factory.create(e,t);if(s==null)throw new x.UnexpectedError(`Telemetry service could not find a source for type ${e.type}`);return s}};const mt="pluto-telem-context",mn=n=>n.get(mt),zo=(n,e)=>n.set(mt,e),Yo=(n,e,t)=>{const s=mn(n);if(s!=null&&t!=null&&s.key===t?.parent?.key)return t;const o=s.child(e,s);return n.set(mt,o),o};class No{spec;wrapped;prevProv;constructor(e,t,s){this.wrapped=e,this.spec=s,this.prevProv=t}shouldUpdate(e,t){return this.prevProv.key!==e.key||!r.deep.equal(this.spec,t)}}class dr extends No{value(){return this.wrapped.value()}cleanup(){this.wrapped.cleanup?.()}onChange(e){return this.wrapped.onChange(e)}}class fr extends No{set(...e){this.wrapped.set(...e)}cleanup(){this.wrapped.cleanup?.()}}const U=(n,e,t,s)=>{const o=mn(n);if(t instanceof dr){if(!t.shouldUpdate(o,e))return t;t.cleanup?.()}return new dr(o.create(e,s),o,e)},qe=(n,e,t,s)=>{const o=mn(n);if(t instanceof fr){if(!t.shouldUpdate(o,e))return t;t.cleanup?.()}return new fr(o.create(e,s),o,e)},Zo=(n,e)=>n.dataType.isVariable||n.dataType.equals(r.DataType.UINT8)?n:(e==null&&n.dataType.equals(r.DataType.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(r.DataType.FLOAT32,e)),nl=n=>n.isVariable||n.equals(r.DataType.UINT8)?n:r.DataType.FLOAT32,Uo=()=>({purgedSeries:0,purgedBytes:r.Size.bytes(0)}),Bo={instrumentation:rn.alamos.NOOP,staleEntryThreshold:r.TimeSpan.seconds(20)};class sl{data=[];props;constructor(e){this.props={...Bo,...e}}write(e){e.length!==0&&(e.series.forEach(t=>this.writeOne(Zo(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:new r.MultiSeries([]),gaps:[e]};const s=t.map((a,l)=>l===0?r.TimeRange.ZERO:new r.TimeRange(t[l-1].timeRange.end,a.timeRange.start)).filter(a=>!a.span.isZero&&a.isValid),o=new r.TimeRange(e.start,t[0].timeRange.start),i=new r.TimeRange(t[t.length-1].timeRange.end,e.end);return o.isValid&&!o.span.isZero&&s.unshift(o),i.isValid&&!i.span.isZero&&s.push(i),{series:new r.MultiSeries(t),gaps:s}}gc(){const{staleEntryThreshold:e}=this.props,t=Uo(),s=this.data.filter(o=>{const i=o.data.refCount>0||r.TimeStamp.since(o.addedAt).lessThan(e);return i||(t.purgedBytes=t.purgedBytes.add(o.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=r.bounds.buildInsertionPlan(this.data.map(u=>u.data.alignmentBounds),e.alignmentBounds);if(s===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(u=>u.data.digest)});const{removeBefore:o,removeAfter:i,insertInto:a,deleteInBetween:l}=s;e=e.slice(o,e.data.length-i),e.length!==0&&this.data.splice(a,l,{data:e,addedAt:r.TimeStamp.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,u)=>a===u?!1:r.bounds.overlapsWith(i,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.series.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const rl=100,ol=1e6,il=1e4,al=100,ll=40;class cl{props;counter=0;curr;avgRate=0;timeOfLastWrite;totalWrites=0;now=()=>r.TimeStamp.now();constructor(e){this.props=e,this.curr=null,e.now!=null&&(this.now=e.now),this.timeOfLastWrite=this.now()}get length(){return this.curr?.length??0}get leadingBuffer(){return this.curr}write(e){const t=e.series.flatMap(s=>this._write(s));return{flushed:new r.MultiSeries(t.flatMap(s=>s.flushed.series)),allocated:new r.MultiSeries(t.flatMap(s=>s.allocated.series))}}allocate(e,t,s){this.counter++;const o=this.props.dataType.isVariable,i=this.props.dataType.equals(r.DataType.TIMESTAMP);return r.Series.alloc({capacity:o?e*ll:e,dataType:nl(this.props.dataType),timeRange:s.range(r.TimeStamp.MAX),sampleOffset:i?s.valueOf():0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),s={flushed:new r.MultiSeries([]),allocated:new r.MultiSeries([])};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 u=this.now();this.curr.timeRange.end=u,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,u),s.allocated.push(this.curr)}const o=Zo(e,this.curr.sampleOffset),i=this.curr.write(o);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<al)return il;const t=r.math.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,ol),rl))}close(){this.curr=null}}class ul{channel;closed=!1;ins;static;dynamic;constructor(e){this.channel=e.channel,this.ins=e.instrumentation??rn.alamos.NOOP,this.static=new sl(e),this.dynamic=new cl({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}`),new r.MultiSeries([]);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:new r.MultiSeries([]),gaps:[e]}):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:r.Size.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const hl=x.TimeSpan.seconds(60);class dl{props;cache=new Map;gcInterval;constructor(e){this.props={dynamicBufferSize:hl,gcInterval:x.TimeSpan.seconds(30),...Bo,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:s,dynamicBufferSize:o}=this.props,i=[];for(const l of e)this.cache.has(l)||i.push(l);if(i.length===0)return;(await s.retrieve(i)).forEach(l=>{if(this.cache.has(l.key))return;const u=new ul({channel:l,dynamicBufferSize:o,instrumentation:t.child(`cache-${l.name}-${l.key}`)});this.cache.set(l.key,u)})}get(e){const t=this.cache.get(e);if(t!=null)return t;throw new x.UnexpectedError(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=Uo();this.cache.forEach(s=>{const o=s.gc();t.purgedSeries+=o.purgedSeries,t.purgedBytes=t.purgedBytes.add(o.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 fl{args;debouncedRead;mu=r.sync.newMutex({requests:new Set,closed:!1});constructor(e){this.args={...e,instrumentation:e.instrumentation??rn.alamos.NOOP,batchDebounce:e.batchDebounce??r.TimeSpan.milliseconds(50),overlapThreshold:e.overlapThreshold??r.TimeSpan.milliseconds(5)};const t=this.args.batchDebounce.milliseconds;this.debouncedRead=r.debounce(()=>{this.batchRead()},t)}async read(e,t){const{cache:s}=this.args;await s.populateMissing([t]);const o=s.get(t),{series:i,gaps:a}=o.read(e);if(a.length===0)return i;const{mu:l}=this;return await new Promise((u,c)=>{l.runExclusive(async()=>{l.closed||l.requests.add({channel:t,gaps:a,resolve:u,reject:c})}),this.debouncedRead()}),o.read(e).series}async batchRead(){const{readRemote:e,cache:t,overlapThreshold:s}=this.args,{mu:o}=this;await o.runExclusive(async()=>{const i=a=>o.requests.forEach(({resolve:l,reject:u})=>a==null?l():u(a));try{if(o.closed)return i();const a=[];o.requests.forEach(({channel:l,gaps:u})=>u.forEach(c=>{const d=a.find(f=>f.gap.equals(c,s));d==null?a.push({gap:c,channels:new Set([l])}):(d.channels.add(l),d.gap=r.TimeRange.max(d.gap,c))})),await Promise.all(a.map(async({gap:l,channels:u})=>{const c=await e(l,Array.from(u));u.forEach(d=>t.get(d).writeStatic(c.get(d)))})),i()}catch(a){i(a)}finally{o.requests.clear()}})}async close(){await this.mu.runExclusive(async()=>{this.mu.closed=!0})}}const pl=new Error("request for lock canceled");var ml=function(n,e,t,s){function o(i){return i instanceof t?i:new t(function(a){a(i)})}return new(t||(t=Promise))(function(i,a){function l(d){try{c(s.next(d))}catch(f){a(f)}}function u(d){try{c(s.throw(d))}catch(f){a(f)}}function c(d){d.done?i(d.value):o(d.value).then(l,u)}c((s=s.apply(n,e||[])).next())})};class gl{constructor(e,t=pl){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,o)=>{const i={resolve:s,reject:o,weight:e,priority:t},a=Fo(this._queue,l=>t<=l.priority);a===-1&&e<=this._value?this._dispatchItem(i):this._queue.splice(a+1,0,i)})}runExclusive(e){return ml(this,arguments,void 0,function*(t,s=1,o=0){const[i,a]=yield this.acquire(s,o);try{return yield t(i)}finally{a()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),yl(this._weightedWaiters[e-1],{resolve:s,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(s=>s.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const s=this._weightedWaiters[t-1];if(!s)continue;const o=s.findIndex(i=>i.priority<=e);(o===-1?s:s.splice(0,o)).forEach((i=>i.resolve()))}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function yl(n,e){const t=Fo(n,s=>e.priority<=s.priority);n.splice(t+1,0,e)}function Fo(n,e){for(let t=n.length-1;t>=0;t--)if(e(n[t]))return t;return-1}var xl=function(n,e,t,s){function o(i){return i instanceof t?i:new t(function(a){a(i)})}return new(t||(t=Promise))(function(i,a){function l(d){try{c(s.next(d))}catch(f){a(f)}}function u(d){try{c(s.throw(d))}catch(f){a(f)}}function c(d){d.done?i(d.value):o(d.value).then(l,u)}c((s=s.apply(n,e||[])).next())})};class bl{constructor(e){this._semaphore=new gl(1,e)}acquire(){return xl(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Sl=r.TimeSpan.milliseconds(100).milliseconds,Tl=r.Rate.hz(60).valueOf();class vl{props;mu=new bl;listeners=new Map;debouncedUpdateStreamer;streamerRunLoop=null;streamer=null;closed=!1;constructor(e){this.props={instrumentation:rn.alamos.NOOP,...e,streamUpdateDelay:new r.TimeSpan(e.streamUpdateDelay??r.TimeSpan.seconds(5))},this.debouncedUpdateStreamer=r.debounce(()=>{this.updateStreamer()},Sl)}async stream(e,t){const{cache:s,instrumentation:o}=this.props;return this.closed?()=>{}:(await s.populateMissing(t),await this.mu.runExclusive(async()=>{o.L.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:new Set(t)});const i=new Map(t.map(a=>{const l=s.get(a);return[a,new r.MultiSeries(r.array.toArray(l.leadingBuffer))]}));return e(i),this.debouncedUpdateStreamer(),()=>this.removeStreamHandler(e)}))}removeStreamHandler(e){const{instrumentation:t}=this.props;this.mu.runExclusive(()=>{const s=this.listeners.get(e);s!=null&&(s.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.L.debug("removing stream handler"),this.listeners.delete(e))return this.debouncedUpdateStreamer();t.L.warn("attempted to remove non-existent stream handler")})},this.props.streamUpdateDelay.milliseconds)}async updateStreamer(){if(this.closed)return;const{instrumentation:e}=this.props;try{const t=new Set;if(this.listeners.forEach(i=>i.keys.forEach(a=>t.add(a))),t.size===0){e.L.info("no keys to stream, closing streamer"),this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.L.info("streamer closed successfully");return}const s=Array.from(t);if(r.compare.primitiveArrays(s,this.streamer?.keys??[])===r.compare.EQUAL){e.L.debug("streamer keys unchanged",{keys:s});return}this.streamer==null&&(e.L.info("creating new streamer",{keys:s}),this.streamer=await this.props.openStreamer({channels:s,throttleRate:Tl}),this.streamerRunLoop=this.runStreamer(this.streamer)),e.L.debug("updating streamer",{prev:this.streamer.keys,next:s}),await this.streamer.update(s)}catch(t){throw e.L.error("failed to update streamer",{error:t}),t}}async runStreamer(e){const{cache:t,instrumentation:s}=this.props;try{for await(const o of e){const i=new Map;for(const a of o.keys){const l=o.get(a),c=t.get(a).writeDynamic(l);i.set(a,c)}i.size!==0&&this.listeners.forEach(({valid:a},l)=>a&&l(i))}}catch(o){throw s.L.error("streamer run loop failed",{error:o},!0),o}}async close(){const{instrumentation:e}=this.props;try{this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop}catch(t){e.L.error("failed to close streamer",{error:t})}this.closed=!0}}class wl{async retrieveChannel(){throw new x.NotFoundError("NoopClient does not support retrieving channels")}async read(){return new r.MultiSeries([])}async stream(){return async()=>{}}async close(){}}class El{ins;cache;reader;streamer;channelRetriever;constructor({instrumentation:e,core:t}){this.ins=e,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new dl({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new fl({cache:this.cache,readRemote:t.read.bind(t),instrumentation:this.ins.child("reader")}),this.streamer=new vl({cache:this.cache,openStreamer:async s=>x.framer.HardenedStreamer.open(t.openStreamer.bind(t),s),instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new x.QueryError(`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"),await this.streamer.close(),await this.reader.close(),this.cache.close()}}const Us=h.z.object({}),gn="telem.Provider",$o=n=>{class e extends w.Composite{static TYPE=gn;static stateZ=Us;schema=e.stateZ;prevCore=null;client=null;afterUpdate(s){const{internal:o}=this,i=He(s),a=w.useErrorHandler(s);if(o.instrumentation=I.useInstrumentation(s,"telem").child("provider"),!(i!==this.prevCore||!s.wasSetPreviously(mt)))return;this.prevCore=i,this.client!=null&&a(async()=>{if(this.client==null)throw new Error("no client to close");await this.client.close()},"failed to close client"),this.client=i==null?new wl:new El({core:i,instrumentation:o.instrumentation});const u=n(this.client),c=new Ao(u);zo(s,c)}}return e},Ho=$o(Do),qo={[gn]:Ho},Cl=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:pn,AbstractSource:W,Base:fn,BooleanStatus:Ie,CONTEXT_KEY:mt,ChannelData:zt,ColorGradient:Ye,CompoundFactory:Zs,Context:Ao,FixedColorSource:Bt,FixedNumber:Zt,FixedString:Ut,IterativeSeries:Nt,Mean:Ae,MultiSourceTransformer:io,NoopFactory:to,PROVIDER_TYPE:gn,PipelineFactory:Os,Provider:Ho,REGISTRY:qo,RemoteFactory:ho,RollingAverage:Ft,ScaleNumber:Ne,SeriesDownsampler:st,SetPoint:Me,SinkPipeline:At,SourcePipeline:Dt,StaticFactory:go,StreamChannelData:Yt,StreamChannelValue:It,StringifyNumber:ze,TransformerFactory:To,UnarySinkTransformer:ao,UnarySourceTransformer:Se,WithinBounds:De,booleanSinkSpecZ:un,booleanSinkTransformerSpecZ:Na,booleanSourceSpecZ:Rs,booleanSourceTransformerSpecZ:Za,booleanStatus:Ga,booleanStatusProps:Co,channelData:fo,colorGradient:ko,colorGradientProps:Lo,colorSourceSpecZ:hn,connectionZ:ks,createFactory:Do,createProvider:$o,downsampleMode:Qa,downsampleModeProps:Ka,downsampleModeZ:Ns,fixedArray:$a,fixedColor:Wa,fixedColorSourcePropsZ:So,fixedNumber:qa,fixedNumberPropsZ:xo,fixedSeriesPropsZ:As,fixedString:ja,fixedStringPropsZ:bo,iterativeArray:Ha,iterativeSeriesPropsZ:yo,mean:Xa,noopBooleanSinkSpec:cn,noopBooleanSourceSpec:vs,noopColorSourceSpec:dt,noopNumericSinkSpec:Qr,noopNumericSourceSpec:ws,noopSeriesSourceSpec:eo,noopStatusSourceSpec:Cs,noopStringSinkSpec:Jr,noopStringSourceSpec:Es,numberSinkSpecZ:ro,numberSourceSpecZ:Ps,providerStateZ:Us,rollingAverage:Po,rollingAverageProps:Ys,scaleNumber:Oo,scaleNumberProps:_o,seriesDownsampler:tl,seriesSourceSpecZ:Mt,setContext:zo,setpoint:vo,sinkPipeline:co,sinkPipelinePropsZ:Ms,sinkSpecZ:pt,sinkTransformerSpecZ:so,sourcePipeline:lo,sourcePipelinePropsZ:_s,sourceSpecZ:he,sourceTransformerSpecZ:no,specZ:ft,statusSourceSpecZ:Ls,streamChannelData:po,streamChannelValue:mo,streamChannelValuePropsZ:Ds,stringSinkSpecZ:oo,stringSourceSpecZ:dn,stringifyNumber:Ro,stringifyNumberProps:zs,useChildContext:Yo,useContext:mn,useSink:qe,useSource:U,withinBounds:wo,withinBoundsProps:Is},Symbol.toStringTag,{value:"Module"})),pr=`#version 300 es
|
|
3
|
+
precision lowp float;
|
|
4
|
+
|
|
5
|
+
uniform lowp vec4 u_color;
|
|
6
|
+
out vec4 fragColor;
|
|
7
|
+
|
|
8
|
+
void main(void) {
|
|
9
|
+
fragColor = u_color;
|
|
10
|
+
}
|
|
11
|
+
`,Rl=`#version 300 es
|
|
12
|
+
|
|
13
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
14
|
+
//
|
|
15
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
16
|
+
// licenses/BSL.txt.
|
|
17
|
+
//
|
|
18
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
19
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
20
|
+
// included in the file licenses/APL.txt.
|
|
21
|
+
|
|
22
|
+
in mediump float a_x;
|
|
23
|
+
in mediump float a_y;
|
|
24
|
+
in mediump vec2 a_translate;
|
|
25
|
+
|
|
26
|
+
uniform mediump vec2 u_scale_aggregate;
|
|
27
|
+
uniform mediump vec2 u_offset_aggregate;
|
|
28
|
+
|
|
29
|
+
void main(void) {
|
|
30
|
+
gl_Position = vec4((u_scale_aggregate * vec2(a_x, a_y) + u_offset_aggregate) + a_translate, 0.0, 1.0);
|
|
31
|
+
}
|
|
32
|
+
`,Pl=`#version 300 es
|
|
33
|
+
|
|
34
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
35
|
+
//
|
|
36
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
37
|
+
// licenses/BSL.txt.
|
|
38
|
+
//
|
|
39
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
40
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
41
|
+
// included in the file licenses/APL.txt.
|
|
42
|
+
|
|
43
|
+
in mediump float a_x;
|
|
44
|
+
in mediump uint a_y;
|
|
45
|
+
in mediump vec2 a_translate;
|
|
46
|
+
|
|
47
|
+
uniform mediump vec2 u_scale_aggregate;
|
|
48
|
+
uniform mediump vec2 u_offset_aggregate;
|
|
49
|
+
|
|
50
|
+
void main(void) {
|
|
51
|
+
gl_Position = vec4((u_scale_aggregate * vec2(a_x, float(a_y)) + u_offset_aggregate) + a_translate, 0.0, 1.0);
|
|
52
|
+
}
|
|
53
|
+
`,jo=h.z.object({x:Mt,y:Mt,label:h.z.string().optional(),color:r.color.colorZ,strokeWidth:h.z.number().default(1),downsample:h.z.number().min(1).max(50).default(1),downsampleMode:Ns.default("decimate"),visible:h.z.boolean().default(!0)}),Ll=(n,e,t)=>n===-1||e===-1||n>=t.series.length?NaN:Number(t.series[n].at(e)),kl=r.TimeSpan.milliseconds(2);r.xy.NAN,r.xy.NAN,r.color.ZERO,r.bounds.ZERO;const _l=(n,e)=>e.equals(r.DataType.UINT8)?n.UNSIGNED_BYTE:n.FLOAT;class mr extends I.GLProgram{translationBufferCache=new Map;constructor(e,t,s){super(e,t,s),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:t}){return this.uniformColor("u_color",t),this.attrStrokeWidth(e)}bindScale(e,t){const s=r.xy.scale(e.scale,t.scale),o=r.xy.translate(r.xy.scale(t.scale,e.offset),t.offset);this.uniformXY("u_scale_aggregate",s),this.uniformXY("u_offset_aggregate",o)}draw({x:e,y:t,count:s,downsample:o,xOffset:i,yOffset:a},l,u,c){const{gl:d}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,o,i,u),this.bindAttrBuffer("y",t.glBuffer,o,a,c),d.drawArraysInstanced(d.LINE_STRIP,0,s/o,l)}bindAttrBuffer(e,t,s,o=0,i){const{gl:a}=this.renderCtx;a.bindBuffer(a.ARRAY_BUFFER,t);const l=a.getAttribLocation(this.prog,`a_${e}`),u=_l(a,i),c=i.density.valueOf();i.equals(r.DataType.UINT8)?a.vertexAttribIPointer(l,1,u,c*s,c*o):a.vertexAttribPointer(l,1,u,!1,c*s,c*o),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:t}=this.renderCtx,s=`${this.renderCtx.aspect}:${e}`,o=this.translationBufferCache.get(s);if(o!=null)return t.bindBuffer(t.ARRAY_BUFFER,o.glBuffer),o;const i=t.createBuffer();if(i==null)throw new x.UnexpectedError("Failed to create buffer from WebGL context");const a=Ml(this.renderCtx.aspect,e);t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,a,t.DYNAMIC_DRAW);const l={glBuffer:i,jsBuffer:a};return this.translationBufferCache.set(s,l),l}attrStrokeWidth(e){const{gl:t}=this.renderCtx,{jsBuffer:s}=this.getAndBindTranslationBuffer(e),o=t.getAttribLocation(this.prog,"a_translate");return t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(o),t.vertexAttribDivisor(o,1),s.length/2}}class _e{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new mr(e,Pl,pr),this.float32Program=new mr(e,Rl,pr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(r.DataType.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,t){const s=new _e(t);return e.set(_e.CONTEXT_KEY,s),s}static use(e){const t=e.get(_e.CONTEXT_KEY);if(t==null)throw new x.UnexpectedError("GLProgram not found");return t}}class $t extends w.Leaf{static TYPE="line";schema=jo;afterUpdate(e){const{internal:t}=this,s={onStatusChange:w.useAdder(e)};t.xTelem=U(e,this.state.x,t.xTelem,s),t.yTelem=U(e,this.state.y,t.yTelem,s),t.instrumentation=I.useInstrumentation(e,"line"),t.lineCtx=_e.use(e),t.requestRender=an(e),t.stopListeningXTelem?.(),t.stopListeningYTelem?.(),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender("data")),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender("data")),t.requestRender("layout"),(t.xDownsampler?.props.mode!==this.state.downsampleMode||t.xDownsampler?.props.windowSize!==this.state.downsample)&&(t.xDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}),t.yDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}))}afterDelete(){const{internal:e}=this;e.xTelem.cleanup?.(),e.yTelem.cleanup?.(),e.requestRender("layout")}xBounds(){return this.internal.xTelem.value()[0]}yBounds(){return this.internal.yTelem.value()[0]}findByXValue(e,t){const{xTelem:s,yTelem:o}=this.internal;let[,i]=s.value();i=this.internal.xDownsampler.transform(i);let[a,l]=[-1,-1];i.series.find((v,R)=>{const L=v.binarySearch(t),k=L>=0&&L<v.length;return k&&([a,l]=[L,R]),k});const{key:u}=this,{color:c,label:d}=this.state,f={key:u,color:c,label:d,position:{x:0,y:0},value:{x:NaN,y:NaN},bounds:{lower:0,upper:0}};if(a===-1||l===-1||!this.state.visible)return f;const p=i.series[l];f.value.x=Ll(l,a,i);let[,g]=o.value();g=this.internal.yDownsampler.transform(g);const T=g.series.find(v=>r.bounds.contains(v.alignmentBounds,p.alignment+BigInt(a)));if(T==null)return f;const y=Number(T.alignment-p.alignment);return f.value.y=Number(T.at(a-y)),f.bounds={...T.bounds},f.position={x:e.dataToDecimalScale.x.pos(f.value.x),y:e.dataToDecimalScale.y.pos(f.value.y)},f}render(e){if(this.deleted||!this.state.visible)return;const{downsample:t}=this.state,{xTelem:s,yTelem:o,lineCtx:i,xDownsampler:a,yDownsampler:l}=this.internal,{dataToDecimalScale:u,exposure:c}=e;let[[,d],[,f]]=[s.value(),o.value()];if(d=a.transform(d),f=l.transform(f),d.updateGLBuffer(i.gl),f.updateGLBuffer(i.gl),d.length===0||f.length===0)return;const p=i.getProgram(f.dataType),g=Nl(d,f,c,t,this.state.downsampleMode,kl);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:t,scale:u.transform,props:e.region,ops:Zl(g)}));const T=p.setAsActive(),y=p.bindState(this.state),v=p.renderCtx.scaleRegion(e.region).transform;g.forEach(R=>{const L=zl(u,R).transform;p.bindScale(L,v),p.draw(R,y,d.dataType,f.dataType)}),T()}}const Ol=5e3,Ml=(n,e)=>Il(Al(n),e).map((t,s)=>Math.floor(s/Dl)*(1/(Ol*n))*t),Dl=5,Al=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Il=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},zl=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Yl={[$t.TYPE]:$t},Nl=(n,e,t,s,o,i)=>{if(n.series.length===0||e.series.length===0)return[];const a=[];return n.series.forEach(l=>e.series.forEach(u=>{if(!Ul(l,u,i))return;let c=0n,d=0n;l.alignment<u.alignment?c=u.alignment-l.alignment:u.alignment<l.alignment&&(d=l.alignment-u.alignment);const f=r.math.min(r.bounds.span(l.alignmentBounds)-c,r.bounds.span(u.alignmentBounds)-d);if(f===0n)return;let p=r.clamp(Math.round(t*4*Number(f)),s,51);o!=="decimate"&&(p=1);const g=Number(f/l.alignmentMultiple),T=Number(c/l.alignmentMultiple),y=Number(d/u.alignmentMultiple);a.push({x:l,y:u,xOffset:T,yOffset:y,count:g,downsample:p})})),a},Zl=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Ul=(n,e,t)=>{if(n.alignmentMultiple!==e.alignmentMultiple)return console.warn("encountered two series with different alignment multiples in draw operations",{x:n.digest,y:e.digest}),!1;const s=n.timeRange.overlapsWith(e.timeRange,t),o=r.bounds.overlapsWith(n.alignmentBounds,e.alignmentBounds);return s&&o},Bs=h.z.object({dpr:h.z.number(),region:r.box.box,bootstrap:h.z.boolean().default(!1),bootstrapped:h.z.boolean().default(!1),glCanvas:h.z.any().optional(),upper2dCanvas:h.z.any().optional(),lower2dCanvas:h.z.any().optional(),os:r.runtime.osZ});class Ht extends w.Composite{static TYPE="Canvas";schema=Bs;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:t,lower2dCanvas:s,upper2dCanvas:o,os:i}=this.state;if(t==null||s==null||o==null)throw new x.UnexpectedError("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=I.Context.create(e,t,s,o,i),_e.create(e,this.renderCtx),this.setState(a=>({...a,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else this.renderCtx.update(e);this.renderCtx.resize(this.state.region,this.state.dpr)}}const Wo={[Ht.TYPE]:Ht},Bl=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Ht,REGISTRY:Wo,canvasStateZ:Bs},Symbol.toStringTag,{value:"Module"})),Fs=h.z.object({position:r.xy.xy,zoom:h.z.number(),region:r.box.box,clearOverScan:r.xy.crudeZ.default(5),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().optional()}),vt=["upper2d","lower2d"];class xe extends w.Composite{static TYPE="Diagram";static stateZ=Fs;schema=xe.stateZ;afterUpdate(e){this.internal.renderCtx=I.Context.use(e),this.internal.handleError=w.useErrorHandler(e),r.primitive.isNonZero(this.state.autoRenderInterval)&&(this.internal.autoRenderInterval??=setInterval(()=>{this.state.visible&&this.requestRender("low")},this.state.autoRenderInterval)),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=r.scale.XY.magnify(r.xy.construct(this.state.zoom)).translate(r.box.topLeft(this.state.region)).translate(this.state.position),this.requestRender("high"))}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const{renderCtx:e,handleError:t,viewportScale:s}=this.internal,o=r.box.construct(this.state.region);if(!this.state.visible)return()=>e.erase(o,this.state.clearOverScan,...vt);const i=e.scissor(o,r.xy.ZERO,vt);try{this.children.forEach(l=>l.render?.({viewportScale:s}))}catch(l){t(l,"failed to render diagram")}finally{i()}const a=r.box.copy(this.state.region);return()=>{e.lower2d.fillStyle=r.color.hex(r.color.BLACK),e.lower2d.fillRect(...r.xy.couple(r.box.topLeft(a)),r.box.width(a),r.box.height(a)),e.erase(a,this.state.clearOverScan,...vt)}}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${xe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:vt})}}const Vo={[xe.TYPE]:xe},Fl=Object.freeze(Object.defineProperty({__proto__:null,Diagram:xe,REGISTRY:Vo,diagramStateZ:Fs},Symbol.toStringTag,{value:"Module"}));function Lt(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function $l(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function $s(n){let e,t,s;n.length!==2?(e=Lt,t=(l,u)=>Lt(n(l),u),s=(l,u)=>n(l)-u):(e=n===Lt||n===$l?n:Hl,t=n,s=n);function o(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<0?c=f+1:d=f}while(c<d)}return c}function i(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<=0?c=f+1:d=f}while(c<d)}return c}function a(l,u,c=0,d=l.length){const f=o(l,u,c,d-1);return f>c&&s(l[f-1],u)>-s(l[f],u)?f-1:f}return{left:o,center:a,right:i}}function Hl(){return 0}function ql(n){return n===null?NaN:+n}const jl=$s(Lt),Wl=jl.right;$s(ql).center;const Vl=Math.sqrt(50),Xl=Math.sqrt(10),Gl=Math.sqrt(2);function qt(n,e,t){const s=(e-n)/Math.max(0,t),o=Math.floor(Math.log10(s)),i=s/Math.pow(10,o),a=i>=Vl?10:i>=Xl?5:i>=Gl?2:1;let l,u,c;return o<0?(c=Math.pow(10,-o)/a,l=Math.round(n*c),u=Math.round(e*c),l/c<n&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,o)*a,l=Math.round(n/c),u=Math.round(e/c),l*c<n&&++l,u*c>e&&--u),u<l&&.5<=t&&t<2?qt(n,e,t*2):[l,u,c]}function Kl(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[o,i,a]=s?qt(e,n,t):qt(n,e,t);if(!(i>=o))return[];const l=i-o+1,u=new Array(l);if(s)if(a<0)for(let c=0;c<l;++c)u[c]=(i-c)/-a;else for(let c=0;c<l;++c)u[c]=(i-c)*a;else if(a<0)for(let c=0;c<l;++c)u[c]=(o+c)/-a;else for(let c=0;c<l;++c)u[c]=(o+c)*a;return u}function Vn(n,e,t){return e=+e,n=+n,t=+t,qt(n,e,t)[2]}function Xn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,o=s?Vn(e,n,t):Vn(n,e,t);return(s?-1:1)*(o<0?1/-o:o)}function Xo(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function Ql(n){return function(){return n}}function Jl(n){return+n}var gr=[0,1];function Pe(n){return n}function Gn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Ql(isNaN(e)?NaN:.5)}function ec(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function tc(n,e,t){var s=n[0],o=n[1],i=e[0],a=e[1];return o<s?(s=Gn(o,s),i=t(a,i)):(s=Gn(s,o),i=t(i,a)),function(l){return i(s(l))}}function nc(n,e,t){var s=Math.min(n.length,e.length)-1,o=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)o[a]=Gn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var u=Wl(n,l,1,s)-1;return i[u](o[u](l))}}function Go(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function sc(){var n=gr,e=gr,t=ln,s,o,i,a=Pe,l,u,c;function d(){var p=Math.min(n.length,e.length);return a!==Pe&&(a=ec(n[0],n[p-1])),l=p>2?nc:tc,u=c=null,f}function f(p){return p==null||isNaN(p=+p)?i:(u||(u=l(n.map(s),e,t)))(s(a(p)))}return f.invert=function(p){return a(o((c||(c=l(e,n.map(s),nt)))(p)))},f.domain=function(p){return arguments.length?(n=Array.from(p,Jl),d()):n.slice()},f.range=function(p){return arguments.length?(e=Array.from(p),d()):e.slice()},f.rangeRound=function(p){return e=Array.from(p),t=Ia,d()},f.clamp=function(p){return arguments.length?(a=p?!0:Pe,d()):a!==Pe},f.interpolate=function(p){return arguments.length?(t=p,d()):t},f.unknown=function(p){return arguments.length?(i=p,f):i},function(p,g){return s=p,o=g,d()}}function Ko(){return sc()(Pe,Pe)}function rc(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function jt(n,e){if(!isFinite(n)||n===0)return null;var t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"),s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function Ze(n){return n=jt(Math.abs(n)),n?n[1]:NaN}function oc(n,e){return function(t,s){for(var o=t.length,i=[],a=0,l=n[0],u=0;o>0&&l>0&&(u+l+1>s&&(l=Math.max(1,s-u)),i.push(t.substring(o-=l,o+l)),!((u+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function ic(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var ac=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Wt(n){if(!(e=ac.exec(n)))throw new Error("invalid format: "+n);var e;return new Hs({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]})}Wt.prototype=Hs.prototype;function Hs(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+""}Hs.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 lc(n){e:for(var e=n.length,t=1,s=-1,o;t<e;++t)switch(n[t]){case".":s=o=t;break;case"0":s===0&&(s=t),o=t;break;default:if(!+n[t])break e;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(o+1):n}var Vt;function cc(n,e){var t=jt(n,e);if(!t)return Vt=void 0,n.toPrecision(e);var s=t[0],o=t[1],i=o-(Vt=Math.max(-8,Math.min(8,Math.floor(o/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")+jt(n,Math.max(0,e+i-1))[0]}function yr(n,e){var t=jt(n,e);if(!t)return n+"";var s=t[0],o=t[1];return o<0?"0."+new Array(-o).join("0")+s:s.length>o+1?s.slice(0,o+1)+"."+s.slice(o+1):s+new Array(o-s.length+2).join("0")}const xr={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:rc,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)=>yr(n*100,e),r:yr,s:cc,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function br(n){return n}var Sr=Array.prototype.map,Tr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function uc(n){var e=n.grouping===void 0||n.thousands===void 0?br:oc(Sr.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",o=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?br:ic(Sr.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",u=n.nan===void 0?"NaN":n.nan+"";function c(f,p){f=Wt(f);var g=f.fill,T=f.align,y=f.sign,v=f.symbol,R=f.zero,L=f.width,k=f.comma,C=f.precision,Z=f.trim,b=f.type;b==="n"?(k=!0,b="g"):xr[b]||(C===void 0&&(C=12),Z=!0,b="g"),(R||g==="0"&&T==="=")&&(R=!0,g="0",T="=");var M=(p&&p.prefix!==void 0?p.prefix:"")+(v==="$"?t:v==="#"&&/[boxX]/.test(b)?"0"+b.toLowerCase():""),A=(v==="$"?s:/[%p]/.test(b)?a:"")+(p&&p.suffix!==void 0?p.suffix:""),V=xr[b],K=/[defgprs%]/.test(b);C=C===void 0?6:/[gprs]/.test(b)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C));function ue(E){var $=M,N=A,Q,de,ne;if(b==="c")N=V(E)+N,E="";else{E=+E;var J=E<0||1/E<0;if(E=isNaN(E)?u:V(Math.abs(E),C),Z&&(E=lc(E)),J&&+E==0&&y!=="+"&&(J=!1),$=(J?y==="("?y:l:y==="-"||y==="("?"":y)+$,N=(b==="s"&&!isNaN(E)&&Vt!==void 0?Tr[8+Vt/3]:"")+N+(J&&y==="("?")":""),K){for(Q=-1,de=E.length;++Q<de;)if(ne=E.charCodeAt(Q),48>ne||ne>57){N=(ne===46?o+E.slice(Q+1):E.slice(Q))+N,E=E.slice(0,Q);break}}}k&&!R&&(E=e(E,1/0));var se=$.length+E.length+N.length,H=se<L?new Array(L-se+1).join(g):"";switch(k&&R&&(E=e(H+E,H.length?L-N.length:1/0),H=""),T){case"<":E=$+E+N+H;break;case"=":E=$+H+E+N;break;case"^":E=H.slice(0,se=H.length>>1)+$+E+N+H.slice(se);break;default:E=H+$+E+N;break}return i(E)}return ue.toString=function(){return f+""},ue}function d(f,p){var g=Math.max(-8,Math.min(8,Math.floor(Ze(p)/3)))*3,T=Math.pow(10,-g),y=c((f=Wt(f),f.type="f",f),{suffix:Tr[8+g/3]});return function(v){return y(T*v)}}return{format:c,formatPrefix:d}}var wt,Qo,Jo;hc({thousands:",",grouping:[3],currency:["$",""]});function hc(n){return wt=uc(n),Qo=wt.format,Jo=wt.formatPrefix,wt}function dc(n){return Math.max(0,-Ze(Math.abs(n)))}function fc(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Ze(e)/3)))*3-Ze(Math.abs(n)))}function pc(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,Ze(e)-Ze(n))+1}function mc(n,e,t,s){var o=Xn(n,e,t),i;switch(s=Wt(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=fc(o,a))&&(s.precision=i),Jo(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=pc(o,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=dc(o))&&(s.precision=i-(s.type==="%")*2);break}}return Qo(s)}function gc(n){var e=n.domain;return n.ticks=function(t){var s=e();return Kl(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var o=e();return mc(o[0],o[o.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),o=0,i=s.length-1,a=s[o],l=s[i],u,c,d=10;for(l<a&&(c=a,a=l,l=c,c=o,o=i,i=c);d-- >0;){if(c=Vn(a,l,t),c===u)return s[o]=a,s[i]=l,e(s);if(c>0)a=Math.floor(a/c)*c,l=Math.ceil(l/c)*c;else if(c<0)a=Math.ceil(a*c)/c,l=Math.floor(l*c)/c;else break;u=c}return n},n}function ei(){var n=Ko();return n.copy=function(){return Go(n,ei())},Xo.apply(n,arguments),gc(n)}function yc(n,e){n=n.slice();var t=0,s=n.length-1,o=n[t],i=n[s],a;return i<o&&(a=t,t=s,s=a,a=o,o=i,i=a),n[t]=e.floor(o),n[s]=e.ceil(i),n}const Pn=new Date,Ln=new Date;function z(n,e,t,s){function o(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(n(i=new Date(+i)),i),o.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),o.round=i=>{const a=o(i),l=o.ceil(i);return i-a<l-i?a:l},o.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),o.range=(i,a,l)=>{const u=[];if(i=o.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return u;let c;do u.push(c=new Date(+i)),e(i,l),n(i);while(c<i&&i<a);return u},o.filter=i=>z(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&&(o.count=(i,a)=>(Pn.setTime(+i),Ln.setTime(+a),n(Pn),n(Ln),Math.floor(t(Pn,Ln))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(s?a=>s(a)%i===0:a=>o.count(0,a)%i===0):o)),o}const Xt=z(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);Xt.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?z(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):Xt);Xt.range;const re=1e3,X=re*60,oe=X*60,ae=oe*24,qs=ae*7,vr=ae*30,kn=ae*365,Le=z(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*re)},(n,e)=>(e-n)/re,n=>n.getUTCSeconds());Le.range;const js=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getMinutes());js.range;const xc=z(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getUTCMinutes());xc.range;const Ws=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re-n.getMinutes()*X)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getHours());Ws.range;const bc=z(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getUTCHours());bc.range;const gt=z(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*X)/ae,n=>n.getDate()-1);gt.range;const Vs=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>n.getUTCDate()-1);Vs.range;const Sc=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>Math.floor(n/ae));Sc.range;function Te(n){return z(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())*X)/qs)}const yn=Te(0),Gt=Te(1),Tc=Te(2),vc=Te(3),Ue=Te(4),wc=Te(5),Ec=Te(6);yn.range;Gt.range;Tc.range;vc.range;Ue.range;wc.range;Ec.range;function ve(n){return z(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)/qs)}const ti=ve(0),Kt=ve(1),Cc=ve(2),Rc=ve(3),Be=ve(4),Pc=ve(5),Lc=ve(6);ti.range;Kt.range;Cc.range;Rc.range;Be.range;Pc.range;Lc.range;const Xs=z(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 kc=z(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());kc.range;const le=z(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());le.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(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)});le.range;const be=z(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());be.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(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)});be.range;function _c(n,e,t,s,o,i){const a=[[Le,1,re],[Le,5,5*re],[Le,15,15*re],[Le,30,30*re],[i,1,X],[i,5,5*X],[i,15,15*X],[i,30,30*X],[o,1,oe],[o,3,3*oe],[o,6,6*oe],[o,12,12*oe],[s,1,ae],[s,2,2*ae],[t,1,qs],[e,1,vr],[e,3,3*vr],[n,1,kn]];function l(c,d,f){const p=d<c;p&&([c,d]=[d,c]);const g=f&&typeof f.range=="function"?f:u(c,d,f),T=g?g.range(c,+d+1):[];return p?T.reverse():T}function u(c,d,f){const p=Math.abs(d-c)/f,g=$s(([,,v])=>v).right(a,p);if(g===a.length)return n.every(Xn(c/kn,d/kn,f));if(g===0)return Xt.every(Math.max(Xn(c,d,f),1));const[T,y]=a[p/a[g-1][2]<a[g][2]/p?g-1:g];return T.every(y)}return[l,u]}const[Oc,Mc]=_c(le,Xs,yn,gt,Ws,js);function _n(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 On(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 je(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function Dc(n){var e=n.dateTime,t=n.date,s=n.time,o=n.periods,i=n.days,a=n.shortDays,l=n.months,u=n.shortMonths,c=We(o),d=Ve(o),f=We(i),p=Ve(i),g=We(a),T=Ve(a),y=We(l),v=Ve(l),R=We(u),L=Ve(u),k={a:ne,A:J,b:se,B:H,c:null,d:Lr,e:Lr,f:nu,g:du,G:pu,H:Jc,I:eu,j:tu,L:ni,m:su,M:ru,p:xn,q:bn,Q:Or,s:Mr,S:ou,u:iu,U:au,V:lu,w:cu,W:uu,x:null,X:null,y:hu,Y:fu,Z:mu,"%":_r},C={a:Sn,A:Tn,b:vn,B:bt,c:null,d:kr,e:kr,f:bu,g:ku,G:Ou,H:gu,I:yu,j:xu,L:ri,m:Su,M:Tu,p:wn,q:qi,Q:Or,s:Mr,S:vu,u:wu,U:Eu,V:Cu,w:Ru,W:Pu,x:null,X:null,y:Lu,Y:_u,Z:Mu,"%":_r},Z={a:K,A:ue,b:E,B:$,c:N,d:Rr,e:Rr,f:Xc,g:Cr,G:Er,H:Pr,I:Pr,j:qc,L:Vc,m:Hc,M:jc,p:V,q:$c,Q:Kc,s:Qc,S:Wc,u:Nc,U:Zc,V:Uc,w:Yc,W:Bc,x:Q,X:de,y:Cr,Y:Er,Z:Fc,"%":Gc};k.x=b(t,k),k.X=b(s,k),k.c=b(e,k),C.x=b(t,C),C.X=b(s,C),C.c=b(e,C);function b(S,P){return function(_){var m=[],B=-1,D=0,q=S.length,j,fe,nr;for(_ instanceof Date||(_=new Date(+_));++B<q;)S.charCodeAt(B)===37&&(m.push(S.slice(D,B)),(fe=wr[j=S.charAt(++B)])!=null?j=S.charAt(++B):fe=j==="e"?" ":"0",(nr=P[j])&&(j=nr(_,fe)),m.push(j),D=B+1);return m.push(S.slice(D,B)),m.join("")}}function M(S,P){return function(_){var m=je(1900,void 0,1),B=A(m,S,_+="",0),D,q;if(B!=_.length)return null;if("Q"in m)return new Date(m.Q);if("s"in m)return new Date(m.s*1e3+("L"in m?m.L:0));if(P&&!("Z"in m)&&(m.Z=0),"p"in m&&(m.H=m.H%12+m.p*12),m.m===void 0&&(m.m="q"in m?m.q:0),"V"in m){if(m.V<1||m.V>53)return null;"w"in m||(m.w=1),"Z"in m?(D=On(je(m.y,0,1)),q=D.getUTCDay(),D=q>4||q===0?Kt.ceil(D):Kt(D),D=Vs.offset(D,(m.V-1)*7),m.y=D.getUTCFullYear(),m.m=D.getUTCMonth(),m.d=D.getUTCDate()+(m.w+6)%7):(D=_n(je(m.y,0,1)),q=D.getDay(),D=q>4||q===0?Gt.ceil(D):Gt(D),D=gt.offset(D,(m.V-1)*7),m.y=D.getFullYear(),m.m=D.getMonth(),m.d=D.getDate()+(m.w+6)%7)}else("W"in m||"U"in m)&&("w"in m||(m.w="u"in m?m.u%7:"W"in m?1:0),q="Z"in m?On(je(m.y,0,1)).getUTCDay():_n(je(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-(q+5)%7:m.w+m.U*7-(q+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,On(m)):_n(m)}}function A(S,P,_,m){for(var B=0,D=P.length,q=_.length,j,fe;B<D;){if(m>=q)return-1;if(j=P.charCodeAt(B++),j===37){if(j=P.charAt(B++),fe=Z[j in wr?P.charAt(B++):j],!fe||(m=fe(S,_,m))<0)return-1}else if(j!=_.charCodeAt(m++))return-1}return m}function V(S,P,_){var m=c.exec(P.slice(_));return m?(S.p=d.get(m[0].toLowerCase()),_+m[0].length):-1}function K(S,P,_){var m=g.exec(P.slice(_));return m?(S.w=T.get(m[0].toLowerCase()),_+m[0].length):-1}function ue(S,P,_){var m=f.exec(P.slice(_));return m?(S.w=p.get(m[0].toLowerCase()),_+m[0].length):-1}function E(S,P,_){var m=R.exec(P.slice(_));return m?(S.m=L.get(m[0].toLowerCase()),_+m[0].length):-1}function $(S,P,_){var m=y.exec(P.slice(_));return m?(S.m=v.get(m[0].toLowerCase()),_+m[0].length):-1}function N(S,P,_){return A(S,e,P,_)}function Q(S,P,_){return A(S,t,P,_)}function de(S,P,_){return A(S,s,P,_)}function ne(S){return a[S.getDay()]}function J(S){return i[S.getDay()]}function se(S){return u[S.getMonth()]}function H(S){return l[S.getMonth()]}function xn(S){return o[+(S.getHours()>=12)]}function bn(S){return 1+~~(S.getMonth()/3)}function Sn(S){return a[S.getUTCDay()]}function Tn(S){return i[S.getUTCDay()]}function vn(S){return u[S.getUTCMonth()]}function bt(S){return l[S.getUTCMonth()]}function wn(S){return o[+(S.getUTCHours()>=12)]}function qi(S){return 1+~~(S.getUTCMonth()/3)}return{format:function(S){var P=b(S+="",k);return P.toString=function(){return S},P},parse:function(S){var P=M(S+="",!1);return P.toString=function(){return S},P},utcFormat:function(S){var P=b(S+="",C);return P.toString=function(){return S},P},utcParse:function(S){var P=M(S+="",!0);return P.toString=function(){return S},P}}}var wr={"-":"",_:" ",0:"0"},Y=/^\s*\d+/,Ac=/^%/,Ic=/[\\^$*+?|[\]().{}]/g;function O(n,e,t){var s=n<0?"-":"",o=(s?-n:n)+"",i=o.length;return s+(i<t?new Array(t-i+1).join(e)+o:o)}function zc(n){return n.replace(Ic,"\\$&")}function We(n){return new RegExp("^(?:"+n.map(zc).join("|")+")","i")}function Ve(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function Yc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function Nc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function Zc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Uc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function Bc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Er(n,e,t){var s=Y.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Cr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function Fc(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 $c(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Hc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Rr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function qc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Pr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function jc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Wc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function Vc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Xc(n,e,t){var s=Y.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Gc(n,e,t){var s=Ac.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Kc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Qc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Lr(n,e){return O(n.getDate(),e,2)}function Jc(n,e){return O(n.getHours(),e,2)}function eu(n,e){return O(n.getHours()%12||12,e,2)}function tu(n,e){return O(1+gt.count(le(n),n),e,3)}function ni(n,e){return O(n.getMilliseconds(),e,3)}function nu(n,e){return ni(n,e)+"000"}function su(n,e){return O(n.getMonth()+1,e,2)}function ru(n,e){return O(n.getMinutes(),e,2)}function ou(n,e){return O(n.getSeconds(),e,2)}function iu(n){var e=n.getDay();return e===0?7:e}function au(n,e){return O(yn.count(le(n)-1,n),e,2)}function si(n){var e=n.getDay();return e>=4||e===0?Ue(n):Ue.ceil(n)}function lu(n,e){return n=si(n),O(Ue.count(le(n),n)+(le(n).getDay()===4),e,2)}function cu(n){return n.getDay()}function uu(n,e){return O(Gt.count(le(n)-1,n),e,2)}function hu(n,e){return O(n.getFullYear()%100,e,2)}function du(n,e){return n=si(n),O(n.getFullYear()%100,e,2)}function fu(n,e){return O(n.getFullYear()%1e4,e,4)}function pu(n,e){var t=n.getDay();return n=t>=4||t===0?Ue(n):Ue.ceil(n),O(n.getFullYear()%1e4,e,4)}function mu(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+O(e/60|0,"0",2)+O(e%60,"0",2)}function kr(n,e){return O(n.getUTCDate(),e,2)}function gu(n,e){return O(n.getUTCHours(),e,2)}function yu(n,e){return O(n.getUTCHours()%12||12,e,2)}function xu(n,e){return O(1+Vs.count(be(n),n),e,3)}function ri(n,e){return O(n.getUTCMilliseconds(),e,3)}function bu(n,e){return ri(n,e)+"000"}function Su(n,e){return O(n.getUTCMonth()+1,e,2)}function Tu(n,e){return O(n.getUTCMinutes(),e,2)}function vu(n,e){return O(n.getUTCSeconds(),e,2)}function wu(n){var e=n.getUTCDay();return e===0?7:e}function Eu(n,e){return O(ti.count(be(n)-1,n),e,2)}function oi(n){var e=n.getUTCDay();return e>=4||e===0?Be(n):Be.ceil(n)}function Cu(n,e){return n=oi(n),O(Be.count(be(n),n)+(be(n).getUTCDay()===4),e,2)}function Ru(n){return n.getUTCDay()}function Pu(n,e){return O(Kt.count(be(n)-1,n),e,2)}function Lu(n,e){return O(n.getUTCFullYear()%100,e,2)}function ku(n,e){return n=oi(n),O(n.getUTCFullYear()%100,e,2)}function _u(n,e){return O(n.getUTCFullYear()%1e4,e,4)}function Ou(n,e){var t=n.getUTCDay();return n=t>=4||t===0?Be(n):Be.ceil(n),O(n.getUTCFullYear()%1e4,e,4)}function Mu(){return"+0000"}function _r(){return"%"}function Or(n){return+n}function Mr(n){return Math.floor(+n/1e3)}var Ce,ii;Du({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 Du(n){return Ce=Dc(n),ii=Ce.format,Ce.parse,Ce.utcFormat,Ce.utcParse,Ce}function Au(n){return new Date(n)}function Iu(n){return n instanceof Date?+n:+new Date(+n)}function ai(n,e,t,s,o,i,a,l,u,c){var d=Ko(),f=d.invert,p=d.domain,g=c(".%L"),T=c(":%S"),y=c("%I:%M"),v=c("%I %p"),R=c("%a %d"),L=c("%b %d"),k=c("%B"),C=c("%Y");function Z(b){return(u(b)<b?g:l(b)<b?T:a(b)<b?y:i(b)<b?v:s(b)<b?o(b)<b?R:L:t(b)<b?k:C)(b)}return d.invert=function(b){return new Date(f(b))},d.domain=function(b){return arguments.length?p(Array.from(b,Iu)):p().map(Au)},d.ticks=function(b){var M=p();return n(M[0],M[M.length-1],b??10)},d.tickFormat=function(b,M){return M==null?Z:c(M)},d.nice=function(b){var M=p();return(!b||typeof b.range!="function")&&(b=e(M[0],M[M.length-1],b??10)),b?p(yc(M,b)):d},d.copy=function(){return Go(d,ai(n,e,t,s,o,i,a,l,u,c))},d}function zu(){return Xo.apply(ai(Oc,Mc,le,Xs,yn,gt,Ws,js,Le,ii).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const Dr=[r.TimeSpan.NANOSECOND,r.TimeSpan.nanoseconds(2),r.TimeSpan.nanoseconds(5),r.TimeSpan.nanoseconds(10),r.TimeSpan.nanoseconds(20),r.TimeSpan.nanoseconds(50),r.TimeSpan.nanoseconds(100),r.TimeSpan.nanoseconds(200),r.TimeSpan.nanoseconds(500),r.TimeSpan.MICROSECOND,r.TimeSpan.microseconds(2),r.TimeSpan.microseconds(5),r.TimeSpan.microseconds(10),r.TimeSpan.microseconds(20),r.TimeSpan.microseconds(50),r.TimeSpan.microseconds(100),r.TimeSpan.microseconds(200),r.TimeSpan.microseconds(500),r.TimeSpan.MILLISECOND,r.TimeSpan.milliseconds(2),r.TimeSpan.milliseconds(5),r.TimeSpan.milliseconds(10),r.TimeSpan.milliseconds(20),r.TimeSpan.milliseconds(50),r.TimeSpan.milliseconds(100),r.TimeSpan.milliseconds(200),r.TimeSpan.milliseconds(500),r.TimeSpan.SECOND];class Yu{_domain;_range;_span;constructor(){this._domain=[new r.TimeStamp(0n),new r.TimeStamp(1n)],this._range=[0,1],this._span=this._domain[1].span(this._domain[0])}domain(e){return e===void 0?this._domain:(this._domain=[new r.TimeStamp(e[0]),new r.TimeStamp(e[1])],this._span=this._domain[1].span(this._domain[0]),this)}range(e){return e===void 0?this._range:(this._range=e,this)}scale(e){const s=new r.TimeStamp(e).valueOf(),o=this._domain[0].valueOf(),i=this._domain[1].valueOf()-o,a=this._range[1]-this._range[0];return Number(s-o)/Number(i)*a+this._range[0]}ticks(e){const t=this.calculateOptimalStep(e).valueOf(),s=this._domain[0].valueOf(),o=this._domain[1].valueOf(),i=(s+t-1n)/t*t,a=Number((o-i)/t);return Array.from({length:a+1},(l,u)=>{const c=i+BigInt(u)*t;return new r.TimeStamp(c)}).filter(l=>l.afterEq(this._domain[0])&&l.beforeEq(this._domain[1]))}calculateOptimalStep(e){const t=this._span.valueOf()/BigInt(Math.ceil(e));let s=Dr[0];for(const o of Dr){if(o.valueOf()>t)break;s=o}return s}formatTick(e){return this._span.lessThan(r.TimeSpan.microseconds(50))?`${e.remainder(r.TimeSpan.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(r.TimeSpan.SECOND).milliseconds.toString()}ms`}}const Nu=()=>new Yu,Gs=h.z.enum(["linear","time"]),Ks=h.z.object({tickSpacing:h.z.number().default(75),type:Gs.default("linear")}),Kn=n=>{const e=Ks.parse(n);return Bu[e.type](e)};class Zu{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=zu(),this.preciseScale=Nu(),this.prevScaleSize=0,this.prevDomain=new r.TimeRange(new r.TimeStamp(0),new r.TimeStamp(0)),this.currTicks=[]}create({decimalToDataScale:e,size:t}){const s=new r.TimeRange(new r.TimeStamp(e.pos(0)),new r.TimeStamp(e.pos(1)));if(this.prevDomain.equals(s)&&this.prevScaleSize===t)return this.currTicks;if(this.prevDomain=s,this.prevScaleSize!==t){const o=[0,t];this.preciseScale.range(o),this.normalScale.range(o),this.prevScaleSize=t}if(s.span.milliseconds<5){this.preciseScale.domain([s.start,s.end]);const o=Qn(t,this.props.tickSpacing)/2,i=this.preciseScale.ticks(o);this.currTicks=i.map(a=>({label:this.preciseScale.formatTick(a),position:this.preciseScale.scale(a)}))}else{this.normalScale.domain([s.start.date(),s.end.date()]);const o=this.normalScale.ticks(Qn(t,this.props.tickSpacing));this.currTicks=o.map(i=>({label:this.normalTickLabel(i),position:this.normalScale(i)}))}return this.currTicks}normalTickLabel(e){let t=`:${e.getSeconds()}`;const s=e.getMilliseconds();if(s!==0){const o=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");t+=`.${o}`}return e.getSeconds()===0&&s===0&&(t=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),t}}class Uu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=r.bounds.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=ei()}create({decimalToDataScale:e,size:t}){const s={lower:e.pos(0),upper:e.pos(1)};if(r.bounds.equals(this.prevDomain,s)&&this.prevScaleSize===t)return this.currTicks;r.bounds.equals(this.prevDomain,s)||(this.d3Scale=this.d3Scale.domain([s.lower,s.upper])),this.prevScaleSize!==t&&(this.d3Scale=this.d3Scale.range([0,t])),this.prevDomain=s,this.prevScaleSize=t;const o=Qn(t,this.props.tickSpacing),i=this.d3Scale.ticks(o);return this.currTicks=i.map(a=>({label:this.tickLabel(a),position:this.d3Scale(a)})),this.currTicks}tickLabel(e){return e.toString()}}const Qn=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},Bu={linear:n=>new Uu(n),time:n=>new Zu(n)},Qs=Ks.extend({color:r.color.colorZ,type:Gs.default("linear"),font:h.z.string(),showGrid:h.z.boolean().default(!0),location:r.location.outer,gridColor:r.color.colorZ}),G=5,rt=6,yt={useAtlas:!0},Fu={bottom:(n,e)=>new ci(n,e),top:(n,e)=>new ui(n,e),left:(n,e)=>new $u(n,e),right:(n,e)=>new hi(n,e)},li=(n,e,t)=>Fu[n](e,t);class we{renderCtx;state;tickFactory;constructor(e,t){this.renderCtx=e,this.state=t,this.tickFactory=Kn(this.state)}setState(e){this.state=w.prettyParse(Qs,e),this.tickFactory=Kn(e)}drawLine(e,t){const{lower2d:s}=this.renderCtx;s.moveTo(...r.xy.couple(e)),s.lineTo(...r.xy.couple(t))}drawTicks(e,t){let s=r.dimensions.ZERO;return e.forEach(o=>{const i=this.renderCtx.lower2d.textDimensions(o.label,yt);s=r.dimensions.max([s,i]),t(i,o)}),s}static START_BOUND=r.bounds.construct(-1,1);maybeDrawGrid(e,t,s){const{showGrid:o,gridColor:i}=this.state;if(o){const a=we.START_BOUND,l=r.bounds.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=r.color.hex(i),t.forEach(c=>{r.bounds.contains(a,c.position)||r.bounds.contains(l,c.position)||this.drawLine(...s(c))}),u.stroke()}}setColor(e){const t=r.color.hex(e);this.renderCtx.lower2d.strokeStyle=t,this.renderCtx.lower2d.fillStyle=t,this.renderCtx.lower2d.font=this.state.font}}class ci extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{width:i,height:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translate(o,"x",i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(o,d.position),r.xy.translate(o,{x:d.position,y:G})),t.fillText(d.label,o.x+d.position-c.width/2,o.y+G+c.height+rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translate(o,"x",c.position),r.xy.translate(o,{x:c.position,y:-a})]),{size:u.height+G+rt}}}class ui extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s}=e,{width:o,height:i}=r.box.dims(s),a=r.xy.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:o});t.beginPath(),this.setColor(this.state.color),this.drawLine(a,r.xy.translate(a,"x",o));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(a,d.position),r.xy.translate(a,{x:d.position,y:-G})),t.fillText(d.label,a.x+d.position-c.width/2,a.y-G-c.height-rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(o,l,c=>[r.xy.translate(a,"x",c.position),r.xy.translate(a,{x:c.position,y:i})]),{size:u.height+G}}}class $u extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=r.xy.translate(o,"x",e.size),u=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(l,r.xy.translate(l,"y",i));const c=this.drawTicks(u,(d,f)=>{this.drawLine(r.xy.translateY(l,f.position),r.xy.translate(l,{x:-G,y:f.position})),t.fillText(f.label,l.x-d.width-G*2,l.y+f.position+d.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,u,d=>[r.xy.translate(l,"y",d.position),r.xy.translate(l,{x:a,y:d.position})]),{size:c.width+G*2}}}class hi extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translateY(o,i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateY(o,d.position),r.xy.translate(o,{x:G,y:d.position})),t.fillText(d.label,o.x+G+rt,o.y+d.position+c.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translateY(o,c.position),r.xy.translate(o,{x:-a,y:c.position})]),{size:u.width+G+rt}}}const di=h.z.object({key:h.z.string(),size:h.z.number(),order:h.z.number(),loc:r.location.outer});h.z.record(h.z.string(),di);const me=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Hu=(n,e,t)=>{const s=e[n];if(s==null)return r.xy.ZERO;const o=r.location.construct(s.loc),i=me(o,e),a=r.location.construct(r.direction.swap(r.location.direction(o))),l=me(a,e),u=i.findIndex(({key:f})=>f===n),c=i.slice(0,u).reduce((f,{size:p})=>f+p,0),d=l.reduce((f,{size:p})=>f+p,0);switch(o){case"left":return r.xy.translate(r.box.topLeft(t),[c,d]);case"right":return r.xy.translate(r.box.topRight(t),[c-s.size,d]);case"top":return r.xy.translate(r.box.topLeft(t),[d,c]);default:return r.xy.translate(r.box.bottomLeft(t),[d,-c-s.size])}},qu=(n,e)=>{const t=me("left",n),s=me("right",n),o=me("top",n),i=me("bottom",n),a=t.reduce((d,{size:f})=>d+f,0),l=s.reduce((d,{size:f})=>d+f,0),u=o.reduce((d,{size:f})=>d+f,0),c=i.reduce((d,{size:f})=>d+f,0);return r.box.construct(r.xy.translate(r.box.topLeft(e),{x:a,y:u}),r.box.width(e)-a-l,r.box.height(e)-u-c)},xt=Qs.extend({axisKey:h.z.string().optional(),bounds:r.bounds.bounds.optional(),autoBounds:h.z.object({lower:h.z.boolean().default(!0),upper:h.z.boolean().default(!0)}).or(h.z.boolean().default(!0)),autoBoundPadding:h.z.number().optional(),autoBoundUpdateInterval:r.TimeSpan.z.default(r.TimeSpan.seconds(10)),size:h.z.number().default(0),label:h.z.string().default(""),labelSize:h.z.number().default(0)}).partial({color:!0,font:!0,gridColor:!0}),ju=2,Wu=7,fi=(n,e)=>r.bounds.contains({lower:n-Wu,upper:n+ju},e),Vu=r.bounds.DECIMAL,Ar=r.TimeStamp.now(),Xu={lower:Number(Ar.valueOf()),upper:Number(Ar.add(r.TimeSpan.HOUR).valueOf())},pi=n=>n==="linear"?Vu:Xu,Gu=(n,e=.1,t)=>{const s=r.bounds.max(n.filter(r.bounds.isFinite));if(!r.bounds.isFinite(s))return pi(t);const{lower:o,upper:i}=s;if(i===o)return{lower:o-1,upper:i+1};const a=(i-o)*e;return{lower:o-a,upper:i+a}},Ku=.01,Qu=.1;class mi extends w.Composite{afterUpdate(e){const{internal:t}=this,{location:s,autoBoundUpdateInterval:o}=this.state;t.render=I.Context.use(e);const i=w.use(e),a=r.direction.construct(s);this.state.autoBoundPadding??=a==="x"?Qu:Ku,t.base=li(s,t.render,{color:i.colors.gray.l10,font:Je.fontString(i,{level:"small",code:!0}),gridColor:i.colors.gray.l1,...this.state}),ie(e,"layout"),t.updateBounds??=r.throttle(l=>this.setState(u=>({...u,bounds:l})),o.milliseconds)}afterDelete(e){ie(e,"layout")}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{base:s}=this.internal,{grid:o,container:i}=e,a=Hu(`${this.type}-${this.key}`,o,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:u}=s.render(l);fi(this.state.size,u)||this.setState(c=>({...c,size:u}))}iBounds(e,t){if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:o}=gi(this.state.autoBounds);if(!s&&!o&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=c=>({upper:o||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?c.lower:this.state.bounds.lower});let a,l=null;try{const c=t();a=Gu(c,this.state.autoBoundPadding,this.state.type)}catch(c){a=pi(this.state.type),l=c}const u=i(a);return this.internal.boundSnapshot=u,(this.state.bounds==null||s&&this.state.bounds.lower!==u.lower||o&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,t,s){const[o,i]=this.iBounds(e,t),a=r.direction.swap(r.direction.construct(this.state.location));return[r.scale.Scale.scale(o).scale(1).translate(-r.box.root(s)[a]).magnify(1/r.box.dim(s,a)),i]}}const gi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:n?.lower??!0,upper:n?.upper??!0};class Ee{canvas;theme;constructor(e,t){this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...o}){return e==="x"?this.line({start:r.xy.construct(r.box.left(t),s),end:r.xy.construct(r.box.right(t),s),...o}):this.line({start:r.xy.construct(s,r.box.top(t)),end:r.xy.construct(s,r.box.bottom(t)),...o})}line({stroke:e,lineWidth:t,lineDash:s,start:o,end:i}){const a=this.canvas;a.strokeStyle=r.color.hex(e),a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...r.xy.couple(o)),a.lineTo(...r.xy.couple(i)),a.stroke()}circle({fill:e,stroke:t,strokeWidth:s,lineDash:o,radius:i,position:a,angle:l,lineCap:u}){const c=this.canvas;c.beginPath();const d=l?.lower??0,f=l?.upper??2*Math.PI;if(t!=null&&typeof i=="object"){const{inner:p,outer:g}=i,T=(p+g)/2,y=g-p;c.arc(...r.xy.couple(a),T,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??y,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([])}else if(t!=null&&typeof i=="number")c.arc(...r.xy.couple(a),i,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??1,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([]);else if(e!=null)if(c.fillStyle=r.color.hex(e),typeof i=="number")c.arc(...r.xy.couple(a),i,d,f),c.fill();else{const{inner:p,outer:g}=i;c.arc(...r.xy.couple(a),g,d,f,!1);const T=a.x+p*Math.cos(f),y=a.y+p*Math.sin(f);c.lineTo(T,y),c.arc(...r.xy.couple(a),p,f,d,!0),c.closePath(),c.fill()}}resolveColor(e,t){return e==null?t==null?this.theme.colors.text:this.resolveColor(t):typeof e=="function"?e(this.theme):r.color.construct(e)}border({region:e,color:t,width:s,radius:o,location:i}){const a=this.canvas;a.strokeStyle=r.color.hex(this.resolveColor(t,this.theme.colors.border)),a.lineWidth=s??this.theme.sizes.border.width,o??=this.theme.sizes.border.radius,i==null||i===!0?o>0?(a.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),o),a.stroke()):(a.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),a.stroke()):r.array.toArray(i).forEach(l=>{const[u,c]=r.box.edgePoints(e,l);a.beginPath(),a.moveTo(...r.xy.couple(u)),a.lineTo(...r.xy.couple(c)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:o,borderRadius:i,borderWidth:a,backgroundColor:l}){i??=this.theme.sizes.border.radius,a??=1;const u=this.canvas;u.fillStyle=r.color.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=r.color.hex(this.resolveColor(o,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),s?u.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),i):u.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),u.fill(),t&&this.border({region:e,color:o,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:o=r.location.TOP_LEFT,offset:i=r.xy.ZERO}=e,a={...e.position};o.x==="right"?a.x-=t.width+i.x:a.x+=i.x,o.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:r.box.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(r.xy.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:o="p"}){const i=Je.fontString(this.theme,{level:o}),a=e.map(c=>sr.dimensions(c,i,this.canvas)),l=this.theme.sizes.base*s,u=Math.max(...a.map(c=>c[r.direction.dimension(t)]))+l;return[{[r.direction.dimension(r.direction.swap(t))]:Math.max(...a.map(c=>c[r.direction.dimension(r.direction.swap(t))])),[r.direction.dimension(t)]:u*e.length-l},c=>{const d=Je.fontString(this.theme,{level:o});this.canvas.font=d,this.canvas.fillStyle=r.color.hex(this.theme.colors.text),this.canvas.textBaseline="top",this.canvas.textAlign="start",e.forEach((f,p)=>{this.canvas.fillText(f,c.x,c.y+u*p)})}]}list({length:e,itemHeight:t,width:s,spacing:o=0,position:i,draw:a,root:l=r.location.TOP_LEFT,offset:u=r.xy.ZERO,padding:c=r.xy.ZERO}){const d=e*t+c.y*2+o*(e-1),f=s+c.x*2,p={...i};l.x==="right"?p.x-=s+u.x*2:p.x+=u.x,l.y==="top"?p.y-=d+u.y*2:p.y+=u.y,this.container({region:r.box.construct(p,{width:f,height:d}),backgroundColor:g=>g.colors.gray.l1});for(let g=0;g<e;g++){const T=r.box.construct(r.xy.construct(p.x+c.x,p.y+g*t+c.y+o*g),s,t);a(g,T)}}drawTextInCenter({box:e,text:t,level:s}){const o=sr.dimensions(t,this.canvas.font,this.canvas),i=r.box.positionInCenter(r.box.construct(r.xy.ZERO,o),e);return this.text({text:t,position:r.box.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:o,shade:i,maxWidth:a,code:l,justify:u="left",align:c="top",useAtlas:d,color:f}){this.canvas.font=Je.fontString(this.theme,{level:s,weight:o,code:l}),f!=null?this.canvas.fillStyle=r.color.hex(this.resolveColor(f)):i==null?this.canvas.fillStyle=r.color.hex(this.theme.colors.text):this.canvas.fillStyle=r.color.hex(this.theme.colors.gray[`l${i}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let p;a!=null&&(p=this.canvas.scissor(r.box.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y,void 0,{useAtlas:d}),p?.()}}const Js=h.z.object({position:h.z.number().optional(),pixelPosition:h.z.number().optional(),dragging:h.z.boolean(),lineWidth:h.z.number().default(1),lineDash:h.z.number().default(20),color:r.color.colorZ}),Ju=3;class ot extends w.Leaf{static TYPE="Rule";schema=Js;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=I.Context.use(e);const t=w.use(e);this.internal.draw=new Ee(this.internal.renderCtx.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}updatePositions({decimalToDataScale:e,plot:t}){const s=this.state.dragging,o=this.prevState.dragging&&!s;if((s||o)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<Ju&&!o)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/r.box.height(t));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const a=e.pos(.5);this.setState(l=>({...l,position:a}))}const i=e.reverse().pos(this.state.position)*r.box.height(t);if(!isNaN(i)){if(this.state.pixelPosition!=null&&Math.abs(i-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(a=>({...a,pixelPosition:i}))}return i}render(e){if(this.deleted)return;const{renderCtx:t}=this.internal,{location:s,plot:o}=e,i=r.location.direction(s),{upper2d:a}=t,l=this.internal.draw,u=this.updatePositions(e)+r.box.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:i,region:o,position:u}),a.fillStyle=r.color.hex(this.state.color),a.lineJoin="round",a.lineWidth=3.5,a.lineCap="round",a.beginPath();const c=4;if(s==="left"){const d=r.box.left(o)-1;a.moveTo(d,u),a.lineTo(d-c,u-c),a.lineTo(d-c,u+c)}else s==="right"&&(a.moveTo(r.box.right(o),u),a.lineTo(r.box.right(o)+c,u-c),a.lineTo(r.box.right(o)+c,u+c));a.closePath(),a.stroke()}}const yi={[ot.TYPE]:ot},eh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:yi,Rule:ot,ruleStateZ:Js},Symbol.toStringTag,{value:"Module"})),th=xt.extend({location:r.location.x.default("left")}),Ir=2,nh=n=>r.box.signedWidth(n)<Ir||r.box.signedHeight(n)<Ir;class Qt extends mi{static TYPE="YAxis";schema=xt;xBounds(){return r.bounds.max(this.lines.map(e=>e.xBounds()).filter(e=>r.bounds.isFinite(e)))}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),o=t.invert().reverse();if(this.renderAxis(e,o),this.renderLines(e,t),this.renderRules(e,o),s!=null)throw s}renderLines({xDataToDecimalScale:e,plot:t,canvases:s,exposure:o},i){if(!s.includes("gl")||nh(t))return;const a={region:t,dataToDecimalScale:new r.scale.XY(e,i),exposure:o};this.lines.forEach(l=>l.render(a))}renderRules({container:e,plot:t,canvases:s},o){if(!s.includes("upper2d"))return;const{location:i}=this.state,{render:a}=this.internal,l=r.box.construct(r.box.left(e),r.box.top(t),r.box.width(e),r.box.height(t)),u=a.scissor(l,r.xy.ZERO,["upper2d"]),c={container:e,plot:t,decimalToDataScale:o,location:i};this.rules.map(d=>d.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:t,viewport:s,hold:o,exposure:i},a){const[l,u]=this.dataToDecimalScale(o,this.dataBounds.bind(this),s);if(u!=null)throw u;const c=new r.scale.XY(e,l),d={region:t,dataToDecimalScale:c,exposure:i};return this.lines.map(f=>({...f.findByXValue(d,a),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType($t.TYPE)}get rules(){return this.childrenOfType(ot.TYPE)}}const sh=h.z.object({start:r.TimeStamp.z,end:r.TimeStamp.z});class zr extends w.Leaf{static TYPE="range-annotation";schema=sh;afterUpdate(e){this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,w.use(e))}}const rh=x.ranger.payloadZ.extend({viewport:r.bounds.bounds}),xi=h.z.object({cursor:r.xy.xy.or(h.z.null()),hovered:rh.or(h.z.null()),count:h.z.number()});class Jt extends w.Leaf{static TYPE="range-provider";schema=xi;fetchedInitial=r.TimeRange.ZERO;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.draw=new Ee(t.render.upper2d,w.use(e)),t.requestRender=an(e),t.runAsync=w.useErrorHandler(e),t.ranges??=new Map;const s=He(e);if(t.requestRender("tool"),s==null)return;t.client=s;const o=Ki(e,this.key);t.removeListener?.();const i=o.ranges.onSet(l=>{t.client!=null&&(r.color.isCrude(l.color)&&t.ranges.set(l.key,t.client.ranges.sugarOne(l)),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool"))}),a=o.ranges.onDelete(async l=>{t.ranges.delete(l),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool")});t.removeListener=()=>{i(),a()}}fetchInitial(e){const{internal:t}=this,{client:s,runAsync:o}=t;s==null||this.fetchedInitial.equals(e,r.TimeSpan.minutes(1))||(this.fetchedInitial=e,o(async()=>{(await s.ranges.retrieve(e)).forEach(a=>{r.color.isCrude(a.color)&&t.ranges.set(a.key,a)}),this.setState(a=>({...a,count:t.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:t,region:s,viewport:o,timeRange:i}=e;this.fetchInitial(i);const{draw:a,ranges:l}=this.internal,u=t.scale(r.box.xBounds(s)),c=this.state.cursor==null?null:this.state.cursor.x;let d=null;const f=a.canvas.scissor(r.box.construct({x:r.box.left(s),y:r.box.top(s)-35},{x:r.box.right(s),y:r.box.bottom(s)}));l.forEach(p=>{const g=r.color.colorZ.safeParse(p.color);if(!g.success)return;const T=g.data;let y=u.pos(Number(p.timeRange.start.valueOf()));const v=u.pos(Number(p.timeRange.end.valueOf()));if(v<r.box.left(s)||y>r.box.right(s))return;y=r.clamp(y,r.box.left(s)-2,r.box.right(s)-1);let R=!1;c!=null&&(R=r.bounds.contains({lower:y,upper:v},c)),R&&(d={key:p.key,parent:p.parent,name:p.name,color:p.color,labels:p.labels,timeRange:p.timeRange,viewport:{lower:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.start.valueOf())),upper:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.end.valueOf()))}}),a.container({region:r.box.construct({x:y,y:r.box.top(s)-1},{x:v,y:r.box.bottom(s)-1}),backgroundColor:r.color.setAlpha(T,.2),bordered:!1});const L=r.box.construct({x:y+1,y:r.box.top(s)-34},{x:v-1,y:r.box.top(s)-12});a.container({region:L,backgroundColor:r.box.width(L)<20?r.color.setAlpha(T,.4):k=>R?k.colors.gray.l2:k.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:r.color.setAlpha(T,.8)}),a.text({text:p.name,position:{x:y+8,y:r.box.top(s)-30},level:"small",shade:10,weight:500,maxWidth:v-y-16})}),f(),d!=null?this.setState(p=>({...p,hovered:d})):this.state.hovered&&this.setState(p=>({...p,hovered:null}))}}const oh={[zr.TYPE]:zr,[Jt.TYPE]:Jt},ih=xt;class en extends mi{static TYPE="XAxis";schema=xt;render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,t.reverse()),this.renderYAxes(e,t),this.renderRanges(e,t),s!=null)throw s}findByXDecimal(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;return this.findByXValue(e,s.reverse().pos(t))}findByXValue(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;const i={...e,xDataToDecimalScale:s};return this.yAxes.map(a=>a.findByXValue(i,t)).flat()}renderYAxes(e,t){const s={...e,xDataToDecimalScale:t};this.yAxes.forEach(o=>o.render(s))}get yAxes(){return this.childrenOfType(Qt.TYPE)}get ranges(){return this.childrenOfType(Jt.TYPE)}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}renderRanges(e,t){const s=this.bounds(e.hold),o=r.bounds.min([s,r.TimeRange.MAX.numericBounds]),i=new r.TimeRange(o.lower,o.upper);this.ranges.forEach(a=>a.render({dataToDecimalScale:t,region:e.plot,viewport:e.viewport,timeRange:i}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const ah=r.xy.construct(12),lh=3,ch=14,uh=r.xy.construct(6),er=h.z.object({position:r.xy.xy.or(h.z.null()),textColor:r.color.colorZ.default(r.color.ZERO),backgroundColor:r.color.colorZ.default(r.color.ZERO),borderColor:r.color.colorZ.default(r.color.ZERO),ruleColor:r.color.colorZ.default(r.color.ZERO),ruleStrokeWidth:h.z.number().default(1),ruleStrokeDash:h.z.number().default(0)});class it extends w.Leaf{static TYPE="tooltip";schema=er;afterUpdate(e){const t=w.use(e);r.color.isZero(this.state.textColor)&&(this.state.textColor=t.colors.text),r.color.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=t.colors.gray.l1),r.color.isZero(this.state.borderColor)&&(this.state.borderColor=t.colors.border),r.color.isZero(this.state.ruleColor)&&(this.state.ruleColor=t.colors.gray.l7),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:t}=e,s=r.scale.XY.scale(r.box.DECIMAL).scale(t),o=r.scale.XY.scale(t).scale(r.box.DECIMAL),i=e.findByXDecimal(o.x.pos(this.state.position.x)),a=i.filter(y=>r.xy.isFinite(y.value)),{draw:l}=this.internal,u=a.reduce((y,v)=>y+v.position.x,0)/a.length,c=new r.TimeStamp(a.reduce((y,v)=>y+v.value.x,0)/a.length),d=s.x.pos(u);if(!r.bounds.contains(r.box.xBounds(t),d))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:t,position:d}),a.forEach(y=>{const v=s.pos(y.position);l.circle({fill:r.color.setAlpha(y.color,.5),radius:8,position:v}),l.circle({fill:r.color.setAlpha(y.color,.8),radius:5,position:v}),l.circle({fill:r.color.pickByContrast(y.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:v})});const f=o.pos(this.state.position),p={...r.location.TOP_LEFT};f.x>.6&&(p.x="right"),f.y>.6&&(p.y="bottom");let g=i.reduce((y,v)=>Math.max(y,v.label?.length??0),0);const T=c.toString("preciseDate","local").length;T>g&&(g=T),l.list({root:p,offset:ah,length:a.length+1,padding:uh,itemHeight:ch,spacing:lh,width:g*7+48,position:this.state.position,draw:(y,v)=>{let R="",L="",k=this.state.textColor;if(y===0)R="Time",L=c.toString("preciseDate","local");else{const C=a[y-1];R=C.label??"",L=r.math.roundBySpan(C.value.y,C.bounds).toString(),k=C.color}l.text({position:r.box.topLeft(v),text:R,level:"small",weight:500,color:k}),l.text({position:r.xy.translateY(r.box.topRight(v),-1),text:L,level:"small",justify:"right",code:!0,shade:10})}})}}const bi={[it.TYPE]:it},hh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:bi,Tooltip:it,tooltipStateZ:er},Symbol.toStringTag,{value:"Module"})),Si=h.z.enum(["one","two"]),tr=h.z.object({one:r.xy.xy.nullable(),two:r.xy.xy.nullable(),hover:r.xy.xy.nullable(),mode:Si.default("one"),color:h.z.union([r.color.colorZ,h.z.object({verticalLine:r.color.colorZ.default(r.color.ZERO),horizontalLine:r.color.colorZ.default(r.color.ZERO),obliqueLine:r.color.colorZ.default(r.color.ZERO)})]).optional().default(r.color.ZERO),strokeWidth:h.z.number().default(1),strokeDash:h.z.number().default(2)}),dh=n=>n==="one"?"1":"2",fh=n=>n.colors.error.z,ph=n=>n.colors.secondary.z,mh=n=>n.colors.gray.l9,Xe=6,Ge=14,Ke=8,Et=8,Ct=3,gh=9,yh=8,xh=2,bh=2,Sh=8,Th=5,vh=2,wh=.5,Eh=.8,Rt=50,Pt=80,Ch=30,Rh=30,Ph=10,Lh=40,kh=100,_h=30,Re=15,Yr=8,Oh=10;class at extends w.Leaf{static TYPE="measure";schema=tr;afterUpdate(e){const t=I.Context.use(e);this.internal.theme=w.use(e),this.internal.renderCtx=t,this.internal.draw=new Ee(t.upper2d,this.internal.theme),ie(e,"tool"),this.internal.dotColor=this.internal.theme.colors.text,this.internal.dotColorContrast=this.internal.theme.colors.textInverted}afterDelete(e){ie(e,"layout")}get verticalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}findPoint(e,t,s,o,i){const a=o!=null&&!r.xy.equals(t,o);if(s!=null&&!a){const c=e.findByXValue(s.x).filter(d=>Number.isFinite(d.value.x)&&Number.isFinite(d.value.y));return c.length>0?c.sort((d,f)=>r.xy.distance(s,d.value)-r.xy.distance(s,f.value))[0]:null}const l=i.pos(t),u=e.findByXDecimal(l.x).filter(c=>Number.isFinite(c.value.x)&&Number.isFinite(c.value.y));return u.length===0?null:u.sort((c,d)=>r.xy.distance(l,c.position)-r.xy.distance(l,d.position))[0]}find(e){const{one:t,two:s}=this.state;if(t==null||s==null)return null;const{dataOne:o,dataTwo:i,clickOne:a,clickTwo:l}=this.internal,u=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),c=this.findPoint(e,t,o,a,u);if(c==null)return null;(a==null||!r.xy.equals(t,a))&&(this.internal.dataOne={...c.value},this.internal.clickOne={...t});const d=this.findPoint(e,s,i,l,u);return d==null?null:((l==null||!r.xy.equals(s,l))&&(this.internal.dataTwo={...d.value},this.internal.clickTwo={...s}),[c,d])}drawLabelValue(e,t,s,o){const{draw:i}=this.internal,a=r.xy.construct(Xe),l=e.length*Ke,u=t.length*Et,c=l+u+a.x*Ct,d=Ge+a.y*2,f=r.box.construct(s,c,d);i.container({region:f,backgroundColor:p=>p.colors.gray.l1}),i.text({text:e,position:r.xy.translate(r.box.topLeft(f),a),level:"small",weight:500,color:o(this.internal.theme)}),i.text({text:t,position:r.xy.translate(r.box.topRight(f),[-a.x-1,a.y-1]),level:"small",justify:"right",code:!0,shade:10})}drawCombinedDeltaLabel(e,t,s,o,i,a){const{draw:l,theme:u}=this.internal,c=r.xy.construct(Xe),d=Ke*5,f=Math.max(t.length,s.length,o.length),p=d+f*Et+c.x*Ct,g=Ge,T=g*3+c.y*2;let y;if(a){const v=r.xy.translate(e,[-p/2,-T/2]);y=r.box.construct(v,p,T)}else if(y=r.box.construct(e,p,T),r.box.right(y)>r.box.right(i)){const v=r.xy.translateX(e,-p-Pt*2);y=r.box.construct(v,p,T)}l.container({region:y,backgroundColor:v=>v.colors.gray.l1}),this.drawPointLabelRow({region:y,label:"ΔX",value:t,labelColor:u.colors.error.z,yOffset:0,leftOffset:0}),this.drawPointLabelRow({region:y,label:"ΔY",value:s,labelColor:u.colors.secondary.z,yOffset:g,leftOffset:0}),this.drawPointLabelRow({region:y,label:"Slope",value:o,labelColor:u.colors.gray.l9,yOffset:g*2,leftOffset:0})}drawPointLabelRow(e){const{region:t,label:s,value:o,labelColor:i,yOffset:a,leftOffset:l}=e,{draw:u}=this.internal,c=r.xy.construct(Xe);u.text({text:s,position:r.xy.translate(r.box.topLeft(t),[c.x+l,c.y+a]),level:"small",weight:500,color:i}),u.text({text:o,position:r.xy.translate(r.box.topRight(t),[-c.x-1,c.y+a-1]),level:"small",justify:"right",code:!0,shade:10})}drawPointLabel(e){const{pointNumber:t,position:s,value:o,units:i,bounds:a,toTop:l,viewRegion:u,xDist:c}=e,{draw:d,theme:f}=this.internal,p=new r.TimeStamp(o.x),g=p.toString(p.formatBySpan(c),"local"),T=`${r.math.roundBySpan(o.y,a)} ${i??""}`,y=`${t}`,v=y.length*Ke,R=r.xy.construct(Xe),L=Ke,k=Math.max(g.length,T.length),C=v+Yr+L+k*Et+R.x*Ct,Z=Ge,b=Z*2+R.y*2;let M=l?-(b+Re):Re,A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b);(l&&r.box.top(A)<r.box.top(u)||!l&&r.box.bottom(A)>r.box.bottom(u))&&(M=l?Re:-(b+Re),A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b)),d.container({region:A,backgroundColor:K=>K.colors.gray.l1}),d.text({text:y,position:r.xy.translate(r.box.topLeft(A),[R.x,R.y]),level:"small",weight:500,color:f.colors.gray.l9});const V=v+Yr;this.drawPointLabelRow({region:A,label:"X",value:g,labelColor:f.colors.error.z,yOffset:0,leftOffset:V}),this.drawPointLabelRow({region:A,label:"Y",value:T,labelColor:f.colors.secondary.z,yOffset:Z,leftOffset:V})}drawPointMarker(e,t){const{draw:s}=this.internal;s.circle({fill:r.color.setAlpha(t,wh),radius:Sh,position:e}),s.circle({fill:r.color.setAlpha(t,Eh),radius:Th,position:e}),s.circle({fill:r.color.pickByContrast(t,this.internal.dotColor,this.internal.dotColorContrast),radius:vh,position:e})}calculateYLabelPosition(e,t,s){return t?r.xy.translateX(e,Ch):s?r.xy.translateX(e,Rh):e}calculateXLabelPosition(e,t,s){return t?r.xy.translateY(e,Lh):s?r.xy.translateY(e,Ph):e}calculateSlopeLabelPosition(e){const{basePos:t,yLabelPos:s,isVeryClose:o,isHorizontal:i,xPixelDist:a,yPixelDist:l}=e;return o?r.xy.translateX(t,Pt):i?r.xy.translateY(t,-35):Math.abs(t.x-s.x)<kh&&Math.abs(t.y-s.y)<_h?a<l?r.xy.translateY(t,-35):r.xy.translateX(t,Pt):t}renderHover(e){if(this.state.hover==null)return;const t=this.state.hover,s=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),o=s.pos(t),i=e.findByXDecimal(s.pos(t).x);if(i.length===0)return;const a=i.sort((c,d)=>r.xy.distance(o,c.position)-r.xy.distance(o,d.position))[0],{draw:l}=this.internal,u=s.reverse().pos(a.position);l.circle({stroke:r.color.setAlpha(a.color,1),strokeWidth:xh,lineDash:bh,radius:gh,position:u}),l.circle({fill:this.internal.theme.colors.gray.l3,radius:yh,position:u}),l.text({text:dh(this.state.mode),position:u,level:"small",align:"middle",justify:"center"})}render(e){if(this.deleted)return;this.renderHover(e);const t=this.find(e);if(t==null)return;const[s,o]=t,{draw:i}=this.internal,{strokeDash:a,strokeWidth:l}=this.state,u=r.scale.XY.scale(r.box.DECIMAL).scale(e.region),c=u.pos(s.position),d=u.pos(o.position),f=Math.abs(s.value.x-o.value.x),p=o.value.y-s.value.y,g=Math.abs(p);if(!Number.isFinite(f)||!Number.isFinite(g))return;const T=new r.TimeSpan(f),y=p/T.seconds,v=Math.abs(c.x-d.x),R=Math.abs(c.y-d.y),L=R<Rt,k=v<Rt,C=v<Rt||R<Rt;i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(c.x,d.y),stroke:this.verticalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,d.y),end:r.xy.construct(d.x,d.y),stroke:this.horizontalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(d.x,d.y),stroke:this.obliqueLineColor,lineDash:a,lineWidth:l}),this.drawPointMarker(c,s.color),this.drawPointMarker(d,o.color);const Z=`${r.math.roundBySpan(g,r.bounds.construct(g))} ${s.units??""}`,b=T.lessThan(r.TimeSpan.milliseconds(Oh))?r.TimeSpan.MICROSECOND:r.TimeSpan.MILLISECOND,M=T.truncate(b).toString();let A=r.math.roundBySpan(y,r.bounds.construct(Math.abs(y))).toString();if(s.units!=null&&s.units.length>0&&(A+=` ${s.units} / s`),C){const K=r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),ue=Ke*6,E=Math.max(M.length,Z.length,A.length),$=Xe,N=ue+E*Et+$*Ct,Q=Ge*3+$*2,de=r.box.construct(r.xy.translate(K,[-N/2,-Q/2]),N,Q),ne=c.y<d.y,J=150,se=Ge*2+$*2,H=ne?-55:Re,xn=r.box.construct(r.xy.translate(c,[-J/2,H]),J,se),bn=ne?Re:-55,Sn=r.box.construct(r.xy.translate(d,[-J/2,bn]),J,se),Tn=r.box.area(r.box.intersection(de,xn))>0,vn=r.box.area(r.box.intersection(de,Sn))>0,bt=!Tn&&!vn,wn=bt?K:r.xy.construct(Math.max(c.x,d.x)+Pt,(c.y+d.y)/2);this.drawCombinedDeltaLabel(wn,M,Z,A,e.region,bt)}else{const K=this.calculateYLabelPosition(r.xy.construct(c.x,(c.y+d.y)/2),C,k);this.drawLabelValue("ΔY",Z,K,ph);const ue=this.calculateXLabelPosition(r.xy.construct((c.x+d.x)/2,d.y),C,L);this.drawLabelValue("ΔX",M,r.xy.translateX(ue,-15),fh);const E=this.calculateSlopeLabelPosition({basePos:r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),yLabelPos:K,isVeryClose:C,isHorizontal:L,xPixelDist:v,yPixelDist:R});this.drawLabelValue("Slope",A,E,mh)}const V=c.y<d.y;this.drawPointLabel({pointNumber:1,position:c,value:s.value,units:s.units??null,bounds:s.bounds,toTop:V,viewRegion:e.region,xDist:T}),this.drawPointLabel({pointNumber:2,position:d,value:o.value,units:o.units??null,bounds:o.bounds,toTop:!V,viewRegion:e.region,xDist:T})}}const Ti={[at.TYPE]:at},Mh=Object.freeze(Object.defineProperty({__proto__:null,Measure:at,REGISTRY:Ti,measureStateZ:tr,modeZ:Si},Symbol.toStringTag,{value:"Module"})),vi=h.z.object({container:r.box.box,viewport:r.box.box,hold:h.z.boolean().default(!1),grid:h.z.record(h.z.string(),di),visible:h.z.boolean().default(!0),clearOverScan:r.xy.crudeZ.default(r.xy.ZERO)}),Dh=h.z.record(h.z.string(),h.z.object({lower:h.z.number(),upper:h.z.number()})),wi={getBounds:h.z.function({input:h.z.tuple([]),output:Dh})},Ah=(n,e)=>{const t=r.box.width(n)*Math.sqrt(r.box.height(n)),s=r.box.width(e)*Math.sqrt(r.box.height(e));return t/s},Ih=["upper2d","lower2d","gl"],zh=["upper2d"];class Jn extends w.Composite{static TYPE="LinePlot";schema=vi;methods=wi;afterUpdate(e){this.internal.instrumentation=I.useInstrumentation(e,"lineplot"),this.internal.handleError=w.useErrorHandler(e),this.internal.renderCtx=I.Context.use(e),on(e,t=>{this.state.visible&&this.requestRender("low",t)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=I.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXDecimal(t,e)).flat()}findByXValue(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXValue(t,e)).flat()}get axes(){return this.childrenOfType(en.TYPE)}get tooltips(){return this.childrenOfType(it.TYPE)}get measures(){return this.childrenOfType(at.TYPE)}get exposure(){return Ah(this.state.viewport,this.state.container)}renderAxes(e,t){const s={...this.state,plot:e,canvases:t,exposure:this.exposure};this.axes.forEach(o=>o.render(s))}renderTooltips(e,t){const s={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:t};this.tooltips.forEach(o=>o.render(s))}getBounds(){const e={};return this.axes.forEach(t=>{const s=t.state.axisKey??t.key;e[s]=t.bounds(this.state.hold),t.yAxes.forEach(o=>{const i=o.state.axisKey??o.key;e[i]=o.bounds(this.state.hold)})}),e}renderMeasures(e){const t={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(s=>s.render(t))}calculatePlot(){return qu(this.state.grid,this.state.container)}render(e){const{instrumentation:t,renderCtx:s,handleError:o}=this.internal;if(this.deleted){t.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return t.L.debug("not visible, skipping render",{key:this.key}),({canvases:d})=>s.erase(this.state.container,this.state.clearOverScan,...d);const i=this.calculatePlot();t.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:e});const a=r.xy.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,e.filter(d=>d!=="gl")),u=s.scissor(i,r.xy.ZERO,e.filter(d=>d==="gl"));try{this.renderAxes(i,e),this.renderTooltips(i,e),this.renderMeasures(i)}catch(d){o(d,"failed to render line plot")}finally{l(),u()}t.L.debug("rendered",{key:this.key});const c=r.box.copy(this.state.container);return({canvases:d})=>s.erase(c,this.state.clearOverScan,...d)}requestRender(e,t){const{renderCtx:s}=this.internal;let o=Ih;t==="tool"&&(o=zh),s.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(o),priority:e,canvases:o})}}const Yh={[Jn.TYPE]:Jn,[en.TYPE]:en,[Qt.TYPE]:Qt},Ei=h.z.object({region:r.box.box,wheelPos:h.z.number(),scrolling:h.z.boolean(),empty:h.z.boolean(),visible:h.z.boolean(),telem:Mt.default(eo),font:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),overshoot:r.xy.xy.default({x:0,y:0})}),Nh=.98,Qe="lower2d",Zh={offset:0n,offsetRef:0n,scrollRef:0};class lt extends w.Leaf{static TYPE="log";static z=Ei;schema=lt.z;values=new r.MultiSeries([]);scrollState=Zh;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?this.internal.textColor=t.theme.colors.gray.l11:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem);const{scrolling:s,wheelPos:o}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:u,values:c}=this,d=Math.ceil((o-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(d)),u.offset<c.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=c.alignmentBounds.lower,this.setState(f=>({...f,wheelPos:this.prevState.wheelPos}))),u.offset>=c.alignmentBounds.upper&&this.setState(f=>({...f,scrolling:!1}))}const[a,l]=this.internal.telem.value();this.values=l,this.checkEmpty(),t.stopListeningTelem?.(),t.stopListeningTelem=t.telem.onChange(()=>{const[u,c]=this.internal.telem.value();this.checkEmpty(),this.values=c,this.requestRender()}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender()}checkEmpty(){const e=this.values.length===0;e!==this.state.empty&&this.setState(t=>({...t,empty:e}))}afterDelete(){const{telem:e,render:t}=this.internal;e.cleanup?.(),t.erase(r.box.construct(this.state.region),r.xy.ZERO,Qe)}requestRender(){const{render:e}=this.internal;e.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(),priority:"high",canvases:[Qe]})}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((r.box.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,t=this.state.region;if(r.box.areaIsZero(t))return;if(!this.state.visible)return()=>e.erase(t,r.xy.ZERO,Qe);let s;if(!this.state.scrolling)s=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));s=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const o=this.state.region,i=e[Qe],a=new Ee(i,this.internal.theme),l=e.scissor(o,r.xy.ZERO,[Qe]);this.renderElements(a,s),this.renderScrollbar(a),l();const u=r.box.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const t=this.state.region,s=r.box.height(t)/this.totalHeight*r.box.height(t);if(s>=r.box.height(t)*Nh)return;let o=r.box.bottom(t)-s;this.state.scrolling&&(o-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*r.box.height(t)),o<0&&(o=r.box.top(t)),e.container({region:r.box.construct({x:r.box.right(t)-6,y:o},{width:6,height:s}),bordered:!1,backgroundColor:i=>i.colors.gray.l6})}renderElements(e,t){const s=this.state.region;let o=0;for(const i of t){const a=this.values.dataType.equals(r.DataType.JSON)?JSON.stringify(i):i.toString();e.text({text:a,level:this.state.font,shade:11,position:r.xy.translate(r.box.topLeft(s),{x:6,y:o*this.lineHeight+6}),code:!0}),o++}}}const Uh={[lt.TYPE]:lt},Bh="roles",Fh={channel:x.access.role.SET_CHANNEL_NAME,schema:x.access.role.roleZ,onChange:({store:n,changed:e})=>{n.roles.set(e.key,e)}},$h={channel:x.access.role.DELETE_CHANNEL_NAME,schema:x.access.role.keyZ,onChange:({store:n,changed:e})=>n.roles.delete(e)},Hh={listeners:[Fh,$h]},qh="ranges",jh={channel:x.ranger.SET_CHANNEL_NAME,schema:x.ranger.payloadZ,onChange:async({store:n,changed:e,client:t})=>{const s=t.ranges.sugarOne(e),o=n.ranges.get(e.key);let i;o?.labels==null&&(i=await s.retrieveLabels());let a=null;o?.parent==null&&(a=await s.retrieveParent()),n.ranges.set(e.key,l=>t.ranges.sugarOne({...s.payload,labels:l?.labels??i,parent:l?.parent??a}))}},Wh={channel:x.ranger.DELETE_CHANNEL_NAME,schema:x.ranger.keyZ,onChange:({store:n,changed:e})=>n.ranges.delete(e)},Vh={equal:(n,e)=>r.deep.equal(n.payload,e.payload),listeners:[jh,Wh]},Ci=h.z.object({authority:r.control.authorityZ.optional(),valid:h.z.boolean().optional()}).default({authority:void 0,valid:!1}),Ri=h.z.object({triggered:h.z.boolean(),status:r.status.statusZ(Ci),sink:un.default(cn),source:Ls.default(Cs)});class es extends w.Leaf{static TYPE="Chip";schema=Ri;afterUpdate(e){const{internal:t}=this,{sink:s,source:o}=this.state;t.source=U(e,o,t.source),t.sink=qe(e,s,t.sink),this.state.triggered&&!this.prevState.triggered&&t.sink.set(this.state.status.details?.authority!==r.control.ABSOLUTE_AUTHORITY),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();r.deep.equal(e,this.state.status)||this.setState(t=>({...t,status:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}render(){}}const Pi=h.z.object({}),Nr="control-state-provider",Li=x.control.stateZ.extend({subjectColor:r.color.colorZ});class ct extends w.Composite{static TYPE="StateProvider";schema=Pi;colors=new Map;colorOverrides=new Map;tracker;disconnectTrackerChange;obs=new r.observe.Observer;static use(e){return e.get(Nr)}afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e,"control-state");const s=w.use(e);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l8;const o=He(e);if(t.client!=null&&o===t.client)return;t.client=o,e.set(Nr,this),w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client))},"failed to open control state tracker")}async maybeCloseTracker(){this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),this.disconnectTrackerChange?.(),await this.tracker.close(),this.tracker=void 0)}afterDelete(e){w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}setColorOverrides(e){const t=Object.entries(e);if(!(t.length===this.colorOverrides.size&&t.every(([s,o])=>{const i=this.colorOverrides.get(s);return i!=null&&r.color.equals(i,o)}))){this.colorOverrides.clear();for(const[s,o]of t)this.colorOverrides.set(s,r.color.construct(o));this.obs.notify([])}}get(e){return Array.isArray(e)?r.unique.unique(e).map(t=>this.getOne(t)).filter(t=>t!=null):this.getOne(e)}getOne(e){if(this.tracker==null)return;const t=this.tracker.states.get(e);if(t!=null)return{...t,subjectColor:this.colorOverrides.get(t.subject.key)??this.colors.get(t.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:t}=this,{instrumentation:s}=t;try{this.tracker=await e.control.openStateTracker()}catch{s.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(o=>{if(s.L.debug("transfer",{transfers:o.map(i=>x.control.transferString(i))}),this.tracker==null)throw new x.UnexpectedError("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(o)})}updateColors(e){const t=e.subjects(),s=t.map(a=>a.key),o=Array.from(this.colors.values());this.colors.forEach((a,l)=>!s.includes(l)&&this.colors.delete(l));const{palette:i}=this.internal;t.forEach(a=>{if(this.colors.has(a.key))return;const l=i.find(u=>!o.includes(u))??i[0];this.colors.set(a.key,l),o.push(l)})}}const ki=h.z.enum(["acquired","released","overridden","failed"]),_i=h.z.object({name:h.z.string(),authority:h.z.number().default(0),status:ki.optional(),needsControlOf:x.channel.keyZ.array().default([])}),ts={acquire:h.z.function({input:h.z.tuple([]),output:h.z.void()}),release:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ns extends w.Composite{static TYPE="Controller";static METHODS=ts;schema=_i;methods=ts;registry=new Map;writer;afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e),t.addStatus=w.useAdder(e),t.runAsync=w.useErrorHandler(e);const s=He(e),o=ct.use(e);t.stateProv=o,t.telemCtx=Yo(e,this,t.telemCtx),t.client=s}afterDelete(){const{internal:e}=this;e.runAsync(()=>this.doRelease(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const t=new Set([]);for(const o of this.registry.keys())(await o.needsControlOf(e)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);r.compare.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==r.compare.EQUAL&&this.setState(o=>({...o,needsControlOf:s}))}acquire(){this.internal.runAsync(()=>this.doAcquire(),"failed to acquire control")}release(){this.internal.runAsync(()=>this.doRelease(),"failed to release control")}async doAcquire(){const{client:e,addStatus:t}=this.internal;if(e==null)return t({message:`Cannot acquire control on ${this.state.name} because no Core has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const s=this.state.needsControlOf;if(s.length===0)return t({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const o=x.TimeStamp.now().sub(r.TimeSpan.milliseconds(1));this.writer=await e.openWriter({start:o,channels:s,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(s){if(this.setState(o=>({...o,status:"failed"})),!(s instanceof Error))throw s;t({variant:"error",message:`${this.state.name} failed to acquire control`,description:s.message})}}async doRelease(){try{await this.writer?.close()}catch(e){this.internal.addStatus({message:`${this.state.name} failed to release control: ${e.message}`,variant:"error"})}finally{this.setState(e=>({...e,status:"released"})),this.writer=void 0}}async set(e){this.writer==null&&await this.doAcquire(),await this.writer?.write(e)}async setAuthority(e,t){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(s=>[s,t])))}async releaseAuthority(e){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(t=>[t,this.state.authority])))}deleteTelem(e){this.registry.delete(e),this.updateNeedsControlOf()}create(e){const{internal:t}=this,o=(()=>{switch(e.type){case tn.TYPE:{const i=new tn(this,t.runAsync,e.props);return this.registry.set(i,null),i}case sn.TYPE:{const i=new sn(this,this.internal.stateProv,e.props);return this.registry.set(i,null),i}case nn.TYPE:return new nn(this,t.runAsync,e.props);default:return null}})();return o!=null&&this.updateNeedsControlOf(),o}}const Oi=h.z.object({channel:h.z.number()});class tn extends pn{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=Oi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}invalidate(){}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){if(this.props.channel===0)return[];const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(...e){this.runAsync(async()=>{const{client:t}=this.controller.internal;if(t==null)throw new x.DisconnectedError("No Core connected");if(this.props.channel===0)throw new x.ValidationError("No command channel specified for actuator");const s=await t.channels.retrieve(this.props.channel),o={[s.key]:e};if(s.index!==0){const i=await t.channels.retrieve(s.index),a=x.TimeStamp.now();o[i.key]=Array.from({length:e.length},(l,u)=>a.add(r.TimeSpan.nanoseconds(u)))}await this.controller.set(o)},"Failed to command channel")}}const Xh=n=>({type:tn.TYPE,props:n,variant:"sink",valueType:"number"}),Mi=h.z.object({authority:h.z.number().default(x.control.ABSOLUTE_AUTHORITY),channel:h.z.number()});class nn extends pn{static TYPE="acquire-channel-control";controller;runAsync;schema=Mi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(e){this.runAsync(async()=>{const{controller:t}=this,{client:s}=t.internal;if(s==null)return;const o=await s.channels.retrieve(this.props.channel),i=[o.key];o.index!==0&&i.push(o.index),e?await this.controller.setAuthority(i,this.props.authority):await this.controller.releaseAuthority(i)},"failed to set channel authority")}}const Gh=n=>({type:nn.TYPE,props:n,variant:"sink",valueType:"boolean"}),Di=h.z.object({channel:h.z.number()}),Kh=h.z.object({valid:h.z.boolean(),color:r.color.colorZ.optional(),authority:h.z.number()});class sn extends W{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=Di;constructor(e,t,s){super(s),this.prov=t,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const t=r.control.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(s=>{s.length>0&&t(s).length===0||this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=x.TimeStamp.now();if(this.props.channel===0)return{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"No Channel",time:e,details:{valid:!1,authority:0}};const t=this.prov.get(this.props.channel);return t==null?{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:e,details:{valid:!0,color:void 0,authority:0}}:{name:this.controller.key,key:t.subject.key,variant:t.subject.key===this.controller.key?"success":"error",message:`Controlled by ${t.subject.name}`,time:e,details:{valid:!0,color:t.subjectColor,authority:t.authority}}}cleanup(){this.controller.deleteTelem(this),this.stopListening?.()}}const Qh=n=>({type:sn.TYPE,props:n,variant:"source",valueType:"status"}),Ai=h.z.object({color:r.color.colorZ.optional()}).default({color:void 0}),Ii=h.z.object({statusSource:Ls.default(Cs),colorSource:hn.default(dt),status:r.status.statusZ(Ai),color:r.color.colorZ.optional()});class ss extends w.Leaf{static TYPE="Indicator";schema=Ii;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:t}=this,{statusSource:s,colorSource:o}=this.state;t.statusSource=U(e,s,t.statusSource),t.colorSource=U(e,o,t.colorSource),this.updateState(),this.stopListeningStatus?.(),this.stopListeningColor?.(),this.stopListeningStatus=t.statusSource.onChange(this.updateState.bind(this)),this.stopListeningColor=t.colorSource.onChange(this.updateState.bind(this))}afterDelete(){this.internal.statusSource.cleanup?.(),this.internal.colorSource.cleanup?.()}render(){}updateState(){const e=this.internal.colorSource.value(),t=this.internal.statusSource.value();r.color.equals(e,this.state.color)&&t.message===this.state.status.message&&r.color.equals(t.details?.color,this.state.status.details?.color)||this.setState(s=>({...s,color:e,status:t}))}}const zi=h.z.object({needsControlOf:x.channel.keyZ.array(),states:Li.array(),colors:h.z.record(h.z.string(),h.z.string()).default({})});class rs extends w.Leaf{static TYPE="Legend";schema=zi;afterUpdate(e){const{internal:t}=this;t.stateProv=ct.use(e),t.stateProv.setColorOverrides(this.state.colors);const s=this.state.needsControlOf;t.disconnectStateProv?.();const o=r.control.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(a=>({...a,states:i})),t.disconnectStateProv=t.stateProv.onChange(a=>{if(a.length>0&&o(a).length===0)return;const l=t.stateProv.get(s);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const Jh={[ns.TYPE]:ns,[ct.TYPE]:ct,[ss.TYPE]:ss,[es.TYPE]:es,[rs.TYPE]:rs},Yi=["fire","momentary","pulse"],ed=h.z.enum(Yi),Ni=h.z.object({sink:un.default(cn),mode:ed.default("fire")}),os={onMouseDown:h.z.function({input:h.z.tuple([]),output:h.z.void()}),onMouseUp:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class is extends w.Leaf{static TYPE="Button";static METHODS=os;schema=Ni;methods=os;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}onMouseDown(){const{mode:e}=this.state;e==="momentary"?this.internal.sink.set(!0):e==="pulse"&&this.internal.sink.set(!0,!1)}onMouseUp(){const{mode:e}=this.state;e==="fire"?this.internal.sink.set(!0):e==="momentary"&&this.internal.sink.set(!1)}afterDelete(){this.internal.sink.cleanup?.()}}const td={[is.TYPE]:is},nd=h.z.object({region:r.box.box,clearOverScan:r.xy.crudeZ.default(0),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().default(1e3)}),Zr=["upper2d","lower2d"];class Fe extends w.Composite{static TYPE="Table";static stateZ=nd;schema=Fe.stateZ;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.handleError=w.useErrorHandler(e),t.autoRenderInterval??=setInterval(()=>this.state.visible&&this.requestRender("low"),this.state.autoRenderInterval),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high")}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const e=r.box.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:t,handleError:s}=this.internal,o=r.scale.XY.translate(r.box.topLeft(this.state.region)),i=t.scissor(this.state.region,r.xy.construct(this.state.clearOverScan),Zr);try{for(const a of this.children)a.render({viewportScale:o})}catch(a){s(a,"Failed to render table")}finally{i()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${Fe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:Zr})}}const sd={[Fe.TYPE]:Fe};h.z.enum(["small","medium","large","huge"]);const rd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),units:h.z.string().default("RPM"),bounds:r.bounds.bounds.default(r.bounds.construct(0,100)),barWidth:h.z.number().default(12)}),od=["upper2d","lower2d"];class ut extends w.Leaf{static TYPE="gauge";static z=rd;schema=ut.z;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?t.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>this.requestRender()),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),t.strokeColor=r.color.isZero(this.state.color)?t.theme.colors.visualization.palettes.default[0]:this.state.color;const s=this.state.box,o=r.box.width(s)/2,{barWidth:i}=this.state;t.outerRadius=o-8,t.innerRadius=t.outerRadius-i;const a=Math.PI/2;t.gaugeStartAngle=3*Math.PI/4,t.gaugeAngleRange=2*Math.PI-a,t.gaugeEndAngle=t.gaugeStartAngle+t.gaugeAngleRange,t.labelRadius=t.outerRadius+12,t.labelInwardShift=12,t.centerPos=r.box.center(s);const l=t.centerPos.y+t.labelRadius*Math.sin(t.gaugeStartAngle)+6;t.minLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeStartAngle)+t.labelInwardShift,l),t.maxLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeEndAngle)-t.labelInwardShift,l),t.valueTextPos=r.xy.translateY(t.centerPos,-6),t.unitsTextPos=r.xy.translateY(t.centerPos,r.box.height(s)/9),t.textLevel=this.state.level,t.labelLevel=ge.downLevel(ge.downLevel(t.textLevel)),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.render.erase(r.box.construct(this.state.box),r.xy.ZERO,...od):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}render({viewportScale:e=r.scale.XY.IDENTITY}){const{internal:t}=this,s=t.render.upper2d.applyScale(e),o=new Ee(s,t.theme),i=t.telem.value(),{lower:a,upper:l}=this.state.bounds,u=Number(i),c=r.bounds.clamp(this.state.bounds,u),d=l-a,f=d===0?0:(c-a)/d,p=t.gaugeStartAngle+f*t.gaugeAngleRange;o.text({text:i,position:t.valueTextPos,shade:10,level:t.textLevel,align:"middle",justify:"center",weight:450,code:!0,useAtlas:!0}),o.text({text:this.state.units,position:t.unitsTextPos,shade:8,level:ge.downLevel(t.textLevel),align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:a.toString(),position:t.minLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:l.toString(),position:t.maxLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.circle({stroke:t.theme.colors.gray.l5,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:t.gaugeEndAngle},lineCap:"round"}),o.circle({stroke:t.strokeColor,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:p},lineCap:"round"})}}const id={[ut.TYPE]:ut},Zi=h.z.object({sink:oo.default(Jr)}),as={set:h.z.function({input:h.z.tuple([h.z.string()]),output:h.z.void()})};class ls extends w.Leaf{static TYPE="Input";static METHODS=as;schema=Zi;methods=as;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}set(e){this.internal.sink.set(e)}afterDelete(){this.internal.sink.cleanup?.()}}const ad={[ls.TYPE]:ls},Ui=h.z.object({enabled:h.z.boolean(),source:Rs.default(vs)});class cs extends w.Leaf{static TYPE="Light";schema=Ui;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const ld={[cs.TYPE]:cs},Bi=h.z.object({value:h.z.number(),sink:ro.default(Qr),source:Ps.default(ws)}),us={set:h.z.function({input:h.z.tuple([h.z.number()]),output:h.z.void()})};class hs extends w.Leaf{static TYPE="Setpoint";static METHODS=us;schema=Bi;methods=us;afterUpdate(e){const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())}set(e){this.internal.sink.set(e)}updateValue(){const e=this.internal.source.value();e===this.state.value||isNaN(e)||this.setState(t=>({...t,value:e}))}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.source.cleanup?.(),e.sink.cleanup?.()}}const cd={[hs.TYPE]:hs},ud=h.z.object({key:h.z.string(),value:h.z.number()}),Fi=h.z.object({key:h.z.string().nullable().default(null),options:h.z.array(ud).default([]),source:Ps.default(ws)});class ds extends w.Leaf{static TYPE="StateIndicator";schema=Fi;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateMatchedOption(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateMatchedOption())}updateMatchedOption(){const e=this.internal.source.value();if(isNaN(e))return;const s=this.state.options.find(o=>o.value===e)?.key??null;s!==this.state.key&&this.setState(o=>({...o,key:s}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const hd={[ds.TYPE]:ds},$i=h.z.object({enabled:h.z.boolean(),sink:un.default(cn),source:Rs.default(vs)}),fs={toggle:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ps extends w.Leaf{static TYPE="Toggle";static METHODS=fs;schema=$i;methods=fs;afterUpdate(e){this.internal.addStatus=w.useOptionalAdder(e);const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateEnabledState(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateEnabledState())}toggle(){const{enabled:e}=this.state;this.internal.sink.set(!e)}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const dd={[ps.TYPE]:ps},Mn={useAtlas:!0},fd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),stalenessTimeout:h.z.number().default(5),stalenessColor:r.color.colorZ.default(r.color.ZERO),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),useWidthForBackground:h.z.boolean().default(!1),valueBackgroundShift:r.xy.xy.default(r.xy.ZERO),valueBackgroundOverScan:r.xy.xy.default(r.xy.ZERO)}),pd=["upper2d","lower2d"];class $e extends w.Leaf{static TYPE="value";static z=fd;schema=$e.z;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.theme=w.use(e),t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>{t.lastReceived=performance.now(),this.requestRender()}),t.fontString=Je.fontString(t.theme,{level:this.state.level,code:!0}),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(r.box.construct(this.state.box),r.xy.ZERO,...pd):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}get fontHeight(){const{theme:e}=this.internal;return e.typography[this.state.level].size*e.sizes.base}maybeUpdateWidth(e){const{theme:t}=this.internal,s=e+t.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<s||this.state.minWidth>s&&this.state.width!==this.state.minWidth?this.setState(o=>({...o,width:Math.max(s,o.minWidth)})):this.state.width-this.fontHeight>s&&this.setState(o=>({...o,width:Math.max(s,o.minWidth)}))}getTextColor(){const{theme:e}=this.internal;return performance.now()-this.internal.lastReceived>this.state.stalenessTimeout*1e3?r.color.isZero(this.state.stalenessColor)?e.colors.warning.m1:this.state.stalenessColor:r.color.isZero(this.state.color)?r.color.pickByContrast(e.colors.border,e.colors.gray.l11,e.colors.gray.l0):r.color.pickByContrast(e.colors.border,e.colors.gray.l11,this.state.color)}render({viewportScale:e=r.scale.XY.IDENTITY}){const{renderCtx:t,telem:s,backgroundTelem:o,fontString:i,requestRender:a}=this.internal,{location:l,box:u}=this.state;if(r.box.areaIsZero(u))return;const c=r.box.topLeft(u),d=r.box.width(u),f=r.box.height(u),p=t.lower2d.applyScale(e);let g=s.value();p.font=i;const T=this.fontHeight,y=g[0]=="-";y&&(g=g.slice(1));const{theme:v}=this.internal,R=p.textDimensions(g,Mn),L=R.width+v.sizes.base,k=R.height;a==null&&t.erase(r.box.construct(this.prevState.box)),this.maybeUpdateWidth(L);const C={...r.xy.ZERO};l.x==="left"?C.x=6+T*.75:l.x==="center"&&(C.x=d/2-L/2),l.y==="center"&&(C.y=f/2+k/2);const Z=r.xy.translate(c,C);if(this.state.backgroundTelem.type!=dt.type){const M=o.value();if(!r.color.isZero(M)){p.fillStyle=r.color.hex(M);const V=this.state.useWidthForBackground?this.state.width??this.state.minWidth:r.box.width(u);p.fillRect(...r.xy.couple(r.xy.translate(c,this.state.valueBackgroundShift)),V+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y)}}const b=this.getTextColor();p.fillStyle=r.color.hex(b),y&&p.fillText("-",...r.xy.couple(r.xy.translateX(Z,-T*.6)),void 0,Mn),p.fillText(g,...r.xy.couple(Z),void 0,Mn)}}const Hi={[$e.TYPE]:$e},md=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Hi,Value:$e},Symbol.toStringTag,{value:"Module"}));exports.AcquireChannelControl=nn;exports.AuthoritySource=sn;exports.Base=we;exports.Bottom=ci;exports.Button=is;exports.Canvas=Ht;exports.Chip=es;exports.Client=Fr;exports.Controller=ns;exports.Diagram=Fl;exports.Diagram$1=xe;exports.FLUX_STORE_CONFIG=Hh;exports.FLUX_STORE_CONFIG$1=ha;exports.FLUX_STORE_CONFIG$2=Vh;exports.FLUX_STORE_KEY=Bh;exports.FLUX_STORE_KEY$1=la;exports.FLUX_STORE_KEY$2=qh;exports.Gauge=ut;exports.Indicator=ss;exports.Input=ls;exports.Legend=rs;exports.Light=cs;exports.Line=$t;exports.LinePlot=Jn;exports.Log=lt;exports.MODES=Yi;exports.Measure=at;exports.PROVIDER_TYPE=ys;exports.PROVIDER_TYPE$1=gn;exports.Provider=kt;exports.Provider$1=Jt;exports.REGISTRY=Yh;exports.REGISTRY$1=id;exports.REGISTRY$10=cd;exports.REGISTRY$11=yi;exports.REGISTRY$12=oh;exports.REGISTRY$13=Ti;exports.REGISTRY$14=Yl;exports.REGISTRY$15=ld;exports.REGISTRY$16=ad;exports.REGISTRY$17=Vo;exports.REGISTRY$18=Jh;exports.REGISTRY$19=Wo;exports.REGISTRY$2=sd;exports.REGISTRY$20=td;exports.REGISTRY$3=Uh;exports.REGISTRY$4=Hi;exports.REGISTRY$5=bi;exports.REGISTRY$6=dd;exports.REGISTRY$7=qo;exports.REGISTRY$8=Hr;exports.REGISTRY$9=hd;exports.RELATIONSHIPS_FLUX_STORE_KEY=ea;exports.RELATIONSHIP_FLUX_STORE_CONFIG=ra;exports.RESOURCES_FLUX_STORE_KEY=ta;exports.RESOURCE_FLUX_STORE_CONFIG=aa;exports.Right=hi;exports.Rule=ot;exports.ScopedUnaryStore=Ur;exports.SetChannelValue=tn;exports.Setpoint=hs;exports.StateIndicator=ds;exports.StateProvider=ct;exports.Table=Fe;exports.Toggle=ps;exports.Tooltip=it;exports.Top=ui;exports.Value=$e;exports.XAxis=en;exports.YAxis=Qt;exports.ZERO_CONTEXT_VALUE=ms;exports.acquireChannelControl=Gh;exports.acquireChannelControlPropsZ=Mi;exports.aether=eh;exports.authoritySource=Qh;exports.authoritySourceDetailsZ=Kh;exports.authoritySourceProps=Di;exports.axisStateZ=Qs;exports.baseAxisStateZ=xt;exports.buttonMethodsZ=os;exports.buttonStateZ=Ni;exports.cachedRetrieveForSubject=Wr;exports.canvas=Bl;exports.canvasStateZ=Bs;exports.channelData=fo;exports.chipStateZ=Ri;exports.chipStatusDetailsZ=Ci;exports.color=Oe;exports.colorGradient=ko;exports.control=on;exports.controllerMethodsZ=ts;exports.controllerStateZ=_i;exports.createRegistry=Ji;exports.createStore=Br;exports.diagramStateZ=Fs;exports.external=Cl;exports.indicatorStateZ=Ii;exports.indicatorStatusDetailsZ=Ai;exports.interpolate=ln;exports.interpolateNumber=nt;exports.interpolateRgb=zn;exports.interpolateString=Kr;exports.legendStateZ=zi;exports.linePlotMethodsZ=wi;exports.linePlotStateZ=vi;exports.logState=Ei;exports.measure=Mh;exports.measureStateZ=tr;exports.methodsZ=as;exports.methodsZ$1=us;exports.newCanvas=li;exports.newTickFactory=Kn;exports.parseAutoBounds=gi;exports.partialUpdate=ji;exports.provider=Gi;exports.providerStateZ=qr;exports.providerStateZ$1=xi;exports.providerStateZ$2=Us;exports.regions=me;exports.request=ie;exports.retrieveForSubject=da;exports.rollingAverage=Po;exports.rollingAverageProps=Ys;exports.ruleStateZ=Js;exports.scaleNumber=Oo;exports.scopeStore=Dn;exports.setChannelValue=Xh;exports.setChannelValuePropsZ=Oi;exports.setpoint=vo;exports.sinkPipeline=co;exports.sinkPipelinePropsZ=Ms;exports.sourcePipeline=lo;exports.sourcePipelinePropsZ=_s;exports.stateProviderStateZ=Pi;exports.stateZ=jo;exports.stateZ$1=Zi;exports.stateZ$2=Ui;exports.stateZ$3=Bi;exports.stateZ$4=Fi;exports.statusZ=ki;exports.streamChannelData=po;exports.streamChannelValue=mo;exports.streamChannelValuePropsZ=Ds;exports.stringSourceSpecZ=dn;exports.stringifyNumber=Ro;exports.stringifyNumberProps=zs;exports.sugaredStateZ=Li;exports.tickFactoryProps=Ks;exports.tickType=Gs;exports.toggleMethodsZ=fs;exports.toggleStateZ=$i;exports.tooltip=hh;exports.tooltipStateZ=er;exports.useOptionalRequestor=bs;exports.useRequestor=an;exports.value=md;exports.withinBounds=wo;exports.withinBoundsProps=Is;exports.withinSizeThreshold=fi;exports.xAxisStateZ=ih;exports.yAxisStateZ=th;
|