@synnaxlabs/pluto 0.47.1 → 0.48.0
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-NfnNvlbz.cjs → Animated--SNIwznU.cjs} +1 -1
- package/dist/{Animated-CUFx-eAB.js → Animated-CC7iS0zH.js} +21 -21
- package/dist/{Animated-CEx4LoLs.js → Animated-DfDp0-ep.js} +4 -4
- package/dist/{Animated-Bq6z2XkH.cjs → Animated-TMpTdCqK.cjs} +1 -1
- package/dist/{Box-D5Qv__kr.js → Box-CoQUaJk2.js} +2 -2
- package/dist/{Box-BvqALodh.cjs → Box-Ds_D3xR_.cjs} +1 -1
- package/dist/Button-BaMa3eGI.cjs +1 -0
- package/dist/Button-NgDHbsf8.js +306 -0
- package/dist/{Dialog-BnPvG5WQ.cjs → Dialog-BL8T9CVw.cjs} +1 -1
- package/dist/{Dialog-Bi1Sf3oc.js → Dialog-CBDFqieV.js} +4 -4
- package/dist/{Editable-CxgdRDPb.js → Editable-C7KPD0hC.js} +3 -3
- package/dist/{Editable-BXFY3-UW.cjs → Editable-CWt3zqDm.cjs} +1 -1
- package/dist/{Haul-BuI0PZpo.js → Haul-Be1j5BU3.js} +2 -2
- package/dist/{Haul-2Xa_nMgc.cjs → Haul-D1WaI_xE.cjs} +1 -1
- package/dist/{Items-CHAbP2ZL.cjs → Items-BYlg9bb-.cjs} +1 -1
- package/dist/{Items-Cmc6otoS.js → Items-mikdEpyC.js} +8 -8
- package/dist/{Menu-CQ_GMgB9.js → Menu-CcWs0t21.js} +9 -9
- package/dist/{Menu-BImhHf24.cjs → Menu-DJoh8bH7.cjs} +1 -1
- package/dist/{Provider-D0P_lzCo.js → Provider-DScd3hYf.js} +26 -26
- package/dist/{Provider-BV7nN39a.cjs → Provider-fx1wTnXk.cjs} +2 -2
- package/dist/Tags-DvPUmH2r.js +908 -0
- package/dist/Tags-KHafaGjR.cjs +1 -0
- package/dist/{Text-BnUGzpJq.js → Text-BbbqH88W.js} +491 -486
- package/dist/Text-CZrjPRjJ.cjs +1 -0
- package/dist/{Video-VlT7jSYk.cjs → Video-DRSEX8t7.cjs} +1 -1
- package/dist/{Video-CITi2j07.js → Video-_DrutSeT.js} +2 -2
- 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-C_YE-5Xa.cjs +8 -0
- package/dist/{css-D6ZBcSwh.js → css-Cn63X_Yv.js} +1161 -1111
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -2
- package/dist/{deep-DtdcJG4q.cjs → deep-7SxmCL0x.cjs} +1 -1
- package/dist/{deep-DRVLw7iw.js → deep-szN5DCOH.js} +1 -1
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +1 -1
- package/dist/{dimensions-CGLhBwVq.cjs → dimensions-DFDTcQRG.cjs} +1 -1
- package/dist/{dimensions-BFCMI7yN.js → dimensions-Dclfavlh.js} +1 -1
- package/dist/{eraser-DvzR9kLf.js → eraser-Bpl4bpBx.js} +13 -13
- package/dist/{eraser-Dm5Du4PL.cjs → eraser-Bqibt23a.cjs} +2 -2
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +7 -7
- package/dist/{_commonjsHelpers-BH3jXuIh.cjs → event-BxvV3arE.cjs} +1 -1
- package/dist/{_commonjsHelpers-ByX85dGu.js → event-nNH_pXSr.js} +17 -14
- package/dist/{external-CMBnwYR4.cjs → external-19BIaQc6.cjs} +1 -1
- package/dist/{external-Daiy-vZ3.js → external-1uZLLxz-.js} +771 -792
- package/dist/{external-DGNBXSAj.js → external-6rS2YiWR.js} +16066 -15782
- package/dist/{external-CAcL3DJP.js → external-8H4eB7TN.js} +8 -8
- package/dist/{external-Eaj0hgzm.cjs → external-AInsIJp-.cjs} +1 -1
- package/dist/{external-CTsR6bs9.cjs → external-B3jTkhc4.cjs} +4 -22
- package/dist/external-B8hxM_jw.cjs +79 -0
- package/dist/{external-BTlfU938.js → external-BOWnCKIe.js} +3 -3
- package/dist/{external-D7EEjQaR.js → external-Bi-OQCBH.js} +19 -18
- package/dist/{external-6vmyay3h.js → external-Bq4gfE5e.js} +6 -6
- package/dist/{external-6RyUkYAB.js → external-C0_sN1J0.js} +2 -2
- package/dist/{external-CSntN1is.cjs → external-CFZ33YbY.cjs} +1 -1
- package/dist/{external-CTrkvlmd.cjs → external-CFdDgpzj.cjs} +1 -1
- package/dist/{external-BcZE443U.cjs → external-CJFfVl_u.cjs} +1 -1
- package/dist/{external-BrQU-ZN8.cjs → external-CN15E8ls.cjs} +1 -1
- package/dist/{external-Bo9Dyf8v.js → external-Caetm5fI.js} +5 -5
- package/dist/external-CfEVFfhL.cjs +1 -0
- package/dist/{external-CtiE4JLk.js → external-D6TsHpoG.js} +10 -10
- package/dist/{external-Clec0nDH.cjs → external-D7WE6Leo.cjs} +1 -1
- package/dist/{external-OLyg-4Ab.cjs → external-DUGcSVbJ.cjs} +1 -1
- package/dist/{external-BSjAne2q.js → external-DwhfVdFp.js} +5 -5
- package/dist/{external-BhOvtmPt.js → external-X_eFMRtE.js} +2 -2
- package/dist/{external-Dl0l3iHN.cjs → external-pRQzznIG.cjs} +1 -1
- package/dist/{external-OzDazbiJ.js → external-y1Apm7j1.js} +14 -14
- package/dist/flex.cjs +1 -1
- package/dist/flex.js +1 -1
- package/dist/{fontString-yPlq8smc.cjs → fontString-BcSXNOgW.cjs} +1 -1
- package/dist/{fontString-CGd4NYXa.js → fontString-D7EMGjIw.js} +2 -2
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/{hooks-Bvv-S6WC.js → hooks-BmUn8s1r.js} +4 -4
- package/dist/{hooks-CoF3Fkrn.cjs → hooks-CutQY1o9.cjs} +1 -1
- package/dist/index.cjs +8 -40
- package/dist/index.js +9333 -9141
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/{jsx-runtime-OVHDjVDe.js → jsx-runtime-BbD0H88J.js} +108 -128
- package/dist/jsx-runtime-nZSsnGb7.cjs +6 -0
- 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-C8In649C.js → provider-B6SgG_sT.js} +4910 -4821
- package/dist/provider-C9Beoajx.cjs +72 -0
- package/dist/src/button/Button.d.ts +2 -1
- package/dist/src/button/Button.d.ts.map +1 -1
- package/dist/src/channel/LinePlot.d.ts +4 -1
- package/dist/src/channel/LinePlot.d.ts.map +1 -1
- package/dist/src/channel/Select.d.ts +2 -2
- package/dist/src/channel/Select.d.ts.map +1 -1
- package/dist/src/cluster/index.d.ts +2 -0
- package/dist/src/cluster/index.d.ts.map +1 -0
- package/dist/src/cluster/queries.d.ts +6 -0
- package/dist/src/cluster/queries.d.ts.map +1 -0
- package/dist/src/cluster/queries.spec.d.ts +2 -0
- package/dist/src/cluster/queries.spec.d.ts.map +1 -0
- package/dist/src/color/GradientPicker.d.ts.map +1 -1
- package/dist/src/flux/retrieve.d.ts +9 -8
- package/dist/src/flux/retrieve.d.ts.map +1 -1
- package/dist/src/hardware/device/Select.d.ts +1 -1
- package/dist/src/hardware/device/Select.d.ts.map +1 -1
- package/dist/src/hardware/rack/Select.d.ts +1 -1
- package/dist/src/hardware/rack/Select.d.ts.map +1 -1
- package/dist/src/icon/registry.d.ts +1 -0
- package/dist/src/icon/registry.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/input/DateTime.d.ts.map +1 -1
- package/dist/src/input/DateTime.spec.d.ts +2 -0
- package/dist/src/input/DateTime.spec.d.ts.map +1 -0
- package/dist/src/label/Select.d.ts +3 -3
- package/dist/src/label/Select.d.ts.map +1 -1
- package/dist/src/menu/Item.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Primitives.d.ts.map +1 -1
- package/dist/src/select/Dialog.d.ts +2 -3
- package/dist/src/select/Dialog.d.ts.map +1 -1
- package/dist/src/select/Multiple.d.ts.map +1 -1
- package/dist/src/select/MultipleTrigger.d.ts.map +1 -1
- package/dist/src/status/Select.d.ts +1 -1
- package/dist/src/status/Select.d.ts.map +1 -1
- package/dist/src/status/queries.d.ts +13 -0
- package/dist/src/status/queries.d.ts.map +1 -1
- package/dist/src/synnax/Provider.d.ts +2 -2
- package/dist/src/synnax/Provider.d.ts.map +1 -1
- package/dist/src/synnax/aether/provider.d.ts.map +1 -1
- package/dist/src/table/Table.d.ts.map +1 -1
- package/dist/src/tag/Tag.d.ts.map +1 -1
- package/dist/src/user/Avatar.d.ts +7 -0
- package/dist/src/user/Avatar.d.ts.map +1 -0
- package/dist/src/user/external.d.ts +3 -0
- package/dist/src/user/external.d.ts.map +1 -0
- package/dist/src/user/index.d.ts +1 -1
- package/dist/src/user/index.d.ts.map +1 -1
- package/dist/src/user/queries.d.ts +1 -0
- package/dist/src/user/queries.d.ts.map +1 -1
- package/dist/src/vis/draw2d/index.d.ts +2 -1
- package/dist/src/vis/draw2d/index.d.ts.map +1 -1
- package/dist/src/vis/measure/Measure.d.ts +4 -1
- package/dist/src/vis/measure/Measure.d.ts.map +1 -1
- package/dist/src/vis/measure/aether/measure.d.ts +27 -1
- package/dist/src/vis/measure/aether/measure.d.ts.map +1 -1
- 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/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/{units-BqIfn6VX.js → units-cBd5OJg4.js} +1 -1
- package/dist/units-zxke9Ng2.cjs +1 -0
- package/dist/value-Ce4T858D.cjs +53 -0
- package/dist/{value-ChGMEPP3.js → value-UJNdARAu.js} +2715 -2512
- package/dist/video.cjs +1 -1
- package/dist/video.js +1 -1
- package/package.json +23 -21
- package/dist/Button-BMeq9Z2I.cjs +0 -1
- package/dist/Button-CMRdj9Ti.js +0 -305
- package/dist/Tags-6IUFBvU-.js +0 -604
- package/dist/Tags-DtnStTuF.cjs +0 -1
- package/dist/Text-DY08sSZe.cjs +0 -1
- package/dist/css-HnNQMUzV.cjs +0 -8
- package/dist/external-DDzR-j7b.cjs +0 -1
- package/dist/external-Ddn3rc_Q.cjs +0 -85
- package/dist/jsx-runtime-Dszzpdy0.cjs +0 -22
- package/dist/provider-lNhTlIWj.cjs +0 -72
- package/dist/units-DCifOxd9.cjs +0 -1
- package/dist/value-B3LTg1lE.cjs +0 -53
package/dist/units-DCifOxd9.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const c=require("./css-HnNQMUzV.cjs"),n=(r,e,s)=>Object.fromEntries(s.map(t=>[`${r}-${t}`,c.Lr.hex(c.Lr.setAlpha(c.Lr.construct(e),t))])),a=(r,e,s=!1)=>{const t=`${r}${e}`;return s?`round(${t}, 1px)`:t};exports.createHexOpacityVariants=n;exports.unitProperty=a;
|
package/dist/value-B3LTg1lE.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";const g=require("./provider-lNhTlIWj.cjs"),s=require("./css-HnNQMUzV.cjs"),h=require("zod"),M=require("./eraser-Dm5Du4PL.cjs"),K=require("./deep-DtdcJG4q.cjs"),Qe=require("./fontString-yPlq8smc.cjs"),Qn=require("./debounce-heEWeOqL.cjs"),ce=require("./types-D-yz1qsT.cjs");require("react");const Dr=require("./dimensions-CGLhBwVq.cjs");class ka{handlers;transform;closer;constructor(e,t){this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[r,i]=this.transform(e);if(!i)return;t=r}this.handlers.forEach((r,i)=>i(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}}class Oa{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,r)=>r(e))}}const Gt=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Oa,Observer:ka},Symbol.toStringTag,{value:"Module"}));function Wn(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function ms(n,e){var t=Object.create(n.prototype);for(var r in e)t[r]=e[r];return t}function it(){}var We=.7,St=1/We,Ee="\\s*([+-]?\\d+)\\s*",Ge="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",W="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",_a=/^#([0-9a-f]{3,8})$/,Ma=new RegExp(`^rgb\\(${Ee},${Ee},${Ee}\\)$`),Aa=new RegExp(`^rgb\\(${W},${W},${W}\\)$`),Da=new RegExp(`^rgba\\(${Ee},${Ee},${Ee},${Ge}\\)$`),Ya=new RegExp(`^rgba\\(${W},${W},${W},${Ge}\\)$`),Ia=new RegExp(`^hsl\\(${Ge},${W},${W}\\)$`),za=new RegExp(`^hsla\\(${Ge},${W},${W},${Ge}\\)$`),Yr={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};Wn(it,Re,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:Ir,formatHex:Ir,formatHex8:Na,formatHsl:Za,formatRgb:zr,toString:zr});function Ir(){return this.rgb().formatHex()}function Na(){return this.rgb().formatHex8()}function Za(){return ys(this).formatHsl()}function zr(){return this.rgb().formatRgb()}function Re(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=_a.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?Nr(e):t===3?new Z(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?gt(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?gt(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=Ma.exec(n))?new Z(e[1],e[2],e[3],1):(e=Aa.exec(n))?new Z(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=Da.exec(n))?gt(e[1],e[2],e[3],e[4]):(e=Ya.exec(n))?gt(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Ia.exec(n))?$r(e[1],e[2]/100,e[3]/100,1):(e=za.exec(n))?$r(e[1],e[2]/100,e[3]/100,e[4]):Yr.hasOwnProperty(n)?Nr(Yr[n]):n==="transparent"?new Z(NaN,NaN,NaN,0):null}function Nr(n){return new Z(n>>16&255,n>>8&255,n&255,1)}function gt(n,e,t,r){return r<=0&&(n=e=t=NaN),new Z(n,e,t,r)}function ja(n){return n instanceof it||(n=Re(n)),n?(n=n.rgb(),new Z(n.r,n.g,n.b,n.opacity)):new Z}function yn(n,e,t,r){return arguments.length===1?ja(n):new Z(n,e,t,r??1)}function Z(n,e,t,r){this.r=+n,this.g=+e,this.b=+t,this.opacity=+r}Wn(Z,yn,ms(it,{brighter(n){return n=n==null?St:Math.pow(St,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?We:Math.pow(We,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new Z(ue(this.r),ue(this.g),ue(this.b),Tt(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:Zr,formatHex:Zr,formatHex8:$a,formatRgb:jr,toString:jr}));function Zr(){return`#${oe(this.r)}${oe(this.g)}${oe(this.b)}`}function $a(){return`#${oe(this.r)}${oe(this.g)}${oe(this.b)}${oe((isNaN(this.opacity)?1:this.opacity)*255)}`}function jr(){const n=Tt(this.opacity);return`${n===1?"rgb(":"rgba("}${ue(this.r)}, ${ue(this.g)}, ${ue(this.b)}${n===1?")":`, ${n})`}`}function Tt(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function ue(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function oe(n){return n=ue(n),(n<16?"0":"")+n.toString(16)}function $r(n,e,t,r){return r<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new Q(n,e,t,r)}function ys(n){if(n instanceof Q)return new Q(n.h,n.s,n.l,n.opacity);if(n instanceof it||(n=Re(n)),!n)return new Q;if(n instanceof Q)return n;n=n.rgb();var e=n.r/255,t=n.g/255,r=n.b/255,i=Math.min(e,t,r),a=Math.max(e,t,r),o=NaN,l=a-i,u=(a+i)/2;return l?(e===a?o=(t-r)/l+(t<r)*6:t===a?o=(r-e)/l+2:o=(e-t)/l+4,l/=u<.5?a+i:2-a-i,o*=60):l=u>0&&u<1?0:o,new Q(o,l,u,n.opacity)}function Ba(n,e,t,r){return arguments.length===1?ys(n):new Q(n,e,t,r??1)}function Q(n,e,t,r){this.h=+n,this.s=+e,this.l=+t,this.opacity=+r}Wn(Q,Ba,ms(it,{brighter(n){return n=n==null?St:Math.pow(St,n),new Q(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?We:Math.pow(We,n),new Q(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,r=t+(t<.5?t:1-t)*e,i=2*t-r;return new Z(ln(n>=240?n-240:n+120,i,r),ln(n,i,r),ln(n<120?n+240:n-120,i,r),this.opacity)},clamp(){return new Q(Br(this.h),mt(this.s),mt(this.l),Tt(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=Tt(this.opacity);return`${n===1?"hsl(":"hsla("}${Br(this.h)}, ${mt(this.s)*100}%, ${mt(this.l)*100}%${n===1?")":`, ${n})`}`}}));function Br(n){return n=(n||0)%360,n<0?n+360:n}function mt(n){return Math.max(0,Math.min(1,n||0))}function ln(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 Gn=n=>()=>n;function Ua(n,e){return function(t){return n+t*e}}function qa(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(r){return Math.pow(n+r*e,t)}}function Ha(n){return(n=+n)==1?vs:function(e,t){return t-e?qa(e,t,n):Gn(isNaN(e)?t:e)}}function vs(n,e){var t=e-n;return t?Ua(n,t):Gn(isNaN(n)?e:n)}const vn=(function n(e){var t=Ha(e);function r(i,a){var o=t((i=yn(i)).r,(a=yn(a)).r),l=t(i.g,a.g),u=t(i.b,a.b),c=vs(i.opacity,a.opacity);return function(d){return i.r=o(d),i.g=l(d),i.b=u(d),i.opacity=c(d),i+""}}return r.gamma=n,r})(1);function Fa(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,r=e.slice(),i;return function(a){for(i=0;i<t;++i)r[i]=n[i]*(1-a)+e[i]*a;return r}}function Qa(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Wa(n,e){var t=e?e.length:0,r=n?Math.min(t,n.length):0,i=new Array(r),a=new Array(t),o;for(o=0;o<r;++o)i[o]=Vt(n[o],e[o]);for(;o<t;++o)a[o]=e[o];return function(l){for(o=0;o<r;++o)a[o]=i[o](l);return a}}function Ga(n,e){var t=new Date;return n=+n,e=+e,function(r){return t.setTime(n*(1-r)+e*r),t}}function Ve(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function Va(n,e){var t={},r={},i;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(i in e)i in n?t[i]=Vt(n[i],e[i]):r[i]=e[i];return function(a){for(i in t)r[i]=t[i](a);return r}}var bn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,cn=new RegExp(bn.source,"g");function Xa(n){return function(){return n}}function Ka(n){return function(e){return n(e)+""}}function bs(n,e){var t=bn.lastIndex=cn.lastIndex=0,r,i,a,o=-1,l=[],u=[];for(n=n+"",e=e+"";(r=bn.exec(n))&&(i=cn.exec(e));)(a=i.index)>t&&(a=e.slice(t,a),l[o]?l[o]+=a:l[++o]=a),(r=r[0])===(i=i[0])?l[o]?l[o]+=i:l[++o]=i:(l[++o]=null,u.push({i:o,x:Ve(r,i)})),t=cn.lastIndex;return t<e.length&&(a=e.slice(t),l[o]?l[o]+=a:l[++o]=a),l.length<2?u[0]?Ka(u[0].x):Xa(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 Vt(n,e){var t=typeof e,r;return e==null||t==="boolean"?Gn(e):(t==="number"?Ve:t==="string"?(r=Re(e))?(e=r,vn):bs:e instanceof Re?vn:e instanceof Date?Ga:Qa(e)?Fa:Array.isArray(e)?Wa:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?Va:Ve)(n,e)}function Ja(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}class ne extends Gt.Observer{cleanup(){}}class Sn extends ne{static TYPE="noop-boolean-sink";set(){}}const Xt={type:Sn.TYPE,props:{},variant:"sink",valueType:"boolean"};class Tn extends ne{static TYPE="noop-numeric-sink";set(){}}const Ss={type:Tn.TYPE,props:{},variant:"sink",valueType:"number"};class xn extends ne{static TYPE="noop-boolean-source";value(){return!1}}const Vn={type:xn.TYPE,props:{},variant:"source",valueType:"boolean"};class wn extends ne{static TYPE="noop-numeric-source";value(){return 0}}const Ts={type:wn.TYPE,props:{},variant:"source",valueType:"number"};class En extends ne{static TYPE="noop-string-sink";set(){}}const xs={type:En.TYPE,props:{},variant:"sink",valueType:"string"};class Cn extends ne{static TYPE="noop-string-source";value(){return""}}const Xn={type:Cn.TYPE,props:{},variant:"source",valueType:"string"};class Rn extends ne{static TYPE="noop-status-source";value(){return{key:"noop",name:"noop",variant:"disabled",message:"unknown",time:s.r.now()}}}const Kn={type:Rn.TYPE,props:{},variant:"source",valueType:"status"};class Ln extends ne{static TYPE="noop-color-source";value(){return s.Lr.ZERO}}const at={type:Ln.TYPE,props:{},variant:"source",valueType:"color"};class Pn extends ne{static TYPE="noop-series";value(){return[s.H.ZERO,new s.Oe([])]}}const ws={type:Pn.TYPE,props:{},variant:"source",valueType:"series"},eo={[Sn.TYPE]:Sn,[Tn.TYPE]:Tn,[En.TYPE]:En,[xn.TYPE]:xn,[wn.TYPE]:wn,[Rn.TYPE]:Rn,[Ln.TYPE]:Ln,[Cn.TYPE]:Cn,[Pn.TYPE]:Pn};class Es{type="noop";create(e){const t=eo[e.type];return t==null?null:new t}}const to=h.z.instanceof(ArrayBuffer),ot=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(to).optional()}),ie=ot.extend({variant:h.z.literal("source")}),lt=ot.extend({variant:h.z.literal("sink")}),Cs=ot.extend({variant:h.z.literal("source-transformer")}),Rs=ot.extend({variant:h.z.literal("sink-transformer")}),xt=ie.extend({valueType:h.z.literal("series")}),Jn=ie.extend({valueType:h.z.literal("boolean")}),Kt=lt.extend({valueType:h.z.literal("boolean")}),no=Rs.extend({valueType:h.z.literal("boolean")}),ro=Cs.extend({valueType:h.z.literal("boolean")}),Ls=ie.extend({valueType:h.z.literal("number")}),Ps=lt.extend({valueType:h.z.literal("number")}),Jt=ie.extend({valueType:h.z.literal("color")}),er=ie.extend({valueType:h.z.literal("status")}),en=ie.extend({valueType:h.z.literal("string")}),ks=lt.extend({valueType:h.z.literal("string")});let tn=class extends Gt.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 g.W(`[BaseTelem] - expected props to be valid, but found the following errors:
|
|
2
|
-
${e.error.message}`)}return this.props_}cleanup(){}};class U extends tn{}class nn extends tn{}class fe extends U{source_=void 0;get source(){if(this.source_==null)throw new g.W("[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 Os extends U{sources={};value(){const e=Object.fromEntries(Object.entries(this.sources).map(([t,r])=>[t,r.value()]));return this.transform(e)}setSources(e){this.sources={...this.sources,...e}}}class _s extends tn{sinks={};get sink(){const[e]=Object.values(this.sinks);if(e==null)throw new g.W("[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 tr=h.z.object({from:h.z.string(),to:h.z.string()}),nr=h.z.object({connections:h.z.array(tr),outlet:h.z.string(),segments:h.z.record(h.z.string(),ie)});class rr{type="pipeline";factory;constructor(e){this.factory=e}create(e){switch(e.type){case wt.TYPE:return new wt(e.props,this.factory);case Et.TYPE:return new Et(e.props,this.factory);default:return null}}}class wt extends U{static TYPE="source-pipeline";schema=nr;sources={};get outlet(){const{outlet:e}=this.props,t=this.sources[e];if(t==null)throw new g.W(`[SourcePipeline] - expected source to exist at outlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const l=t.create(o);l!=null&&(this.sources[a]=l)}),r.forEach(({from:a,to:o})=>{const l=this.sources[a],u=this.sources[o];l==null||u==null||"setSources"in u&&u.setSources({[a]:l})})}value(){return this.outlet.value()}onChange(e){return this.outlet.onChange(e)}cleanup(){Object.values(this.sources).forEach(e=>e.cleanup?.())}}const Ms=(n,e)=>({variant:"source",props:e,type:wt.TYPE,valueType:n}),sr=h.z.object({connections:h.z.array(tr),inlet:h.z.string(),segments:h.z.record(h.z.string(),lt)});class Et extends nn{static TYPE="sink-pipeline";schema=sr;sinks={};get inlet(){const{inlet:e}=this.props,t=this.sinks[e];if(t==null)throw new g.W(`[SinkPipeline] - expected source to exist at inlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const l=t.create(o);l!=null&&(this.sinks[a]=l)}),r.forEach(({from:a,to:o})=>{const l=this.sinks[a],u=this.sinks[o];l==null||u==null||"setSinks"in l&&l.setSinks({[o]:u})})}set(...e){return this.inlet.set(...e)}cleanup(){Object.values(this.sinks).forEach(e=>e.cleanup?.())}}const As=(n,e)=>({variant:"sink",props:e,type:Et.TYPE,valueType:n}),ir=h.z.object({channel:h.z.number().or(h.z.string())});class Ct extends U{static TYPE="stream-channel-value";schema=ir;client;removeStreamHandler=null;leadingBuffer=null;valid=!1;onStatusChange;constructor(e,t,r){super(t),this.client=e,this.onStatusChange=r?.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 s.y.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=r=>{const i=r.get(e.key);if(i==null)return;const a=i.series.at(-1);a!=null&&(a.acquire(),this.leadingBuffer?.release(),this.leadingBuffer=a),this.notify()};this.removeStreamHandler=await this.client.stream(t,[e.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s.Yr.fromException(e,"failed to stream channel value"))}}}const Ds=async(n,e,t)=>{const r=await n.retrieveChannel(e),i=g.DI.isCalculated(r),a=g.DI.isLegacyCalculated(r);if(!t||r.isIndex)return{key:r.key,dataType:r.dataType,virtual:r.virtual,isCalculated:i};if(a){const o=await g.DI.resolveLegacyCalculatedIndex(n.retrieveChannel.bind(n),r);if(o==null)throw new g.Pr("Failed to resolve calculated index");return{key:(await n.retrieveChannel(o)).key,dataType:s.n.TIMESTAMP,virtual:!1,isCalculated:i}}if(r.virtual&&!i)throw new g.Pr("cannot use virtual channels as a data source");return{key:r.index,dataType:s.n.TIMESTAMP,virtual:!1,isCalculated:i}},so=h.z.object({timeRange:s.m.z,channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().optional().default(!1)});class Rt extends U{static TYPE="series-source";client;schema=so;data=new s.Oe;valid=!1;channel=null;onStatusChange;constructor(e,t,r){super(t),this.client=e,this.onStatusChange=r?.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[s.H.ZERO,this.data];this.valid||this.read();const{channel:r,data:i}=this;if(r==null)return[s.H.ZERO,this.data];let a=i.bounds;return r.dataType.equals(s.n.TIMESTAMP)&&(a=s.H.min([a,t.numericBounds])),[a,i]}async read(){try{this.valid=!0;const{timeRange:e,channel:t,useIndexOfChannel:r}=this.props;this.channel=await Ds(this.client,t,r);const i=await this.client.read(e,this.channel.key);i.acquire(),this.data=i,this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s.Yr.fromException(e,"failed to read channel data"))}}}const io=h.z.object({channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().optional().default(!1),timeSpan:s.a$1.z,keepFor:s.a$1.z.optional()});class Lt extends U{static TYPE="dynamic-series-source";client;data=new s.Oe([]);now;onStatusChange;channel=null;stopStreaming;valid=!1;schema=io;constructor(e,t,r,i=()=>s.r.now()){super(t),this.client=e,this.now=i,this.onStatusChange=r?.onStatusChange}value(){const{channel:e,timeSpan:t}=this.props;if(e===0)return[s.H.ZERO,this.data];this.valid||this.read();const{data:r,channel:i}=this,a=this.now();if(i!=null&&i.dataType.isVariable)return[s.H.ZERO,this.data];const o=r.series.filter(u=>u.timeRange.end.after(a.sub(t))).map(u=>u.bounds),l=s.H.max(o);return i!=null&&i.dataType.equals(s.n.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:r}=this.props;this.channel=await Ds(this.client,e,t);const i=this.now().spanRange(-r);if(!this.channel.virtual||this.channel.isCalculated)try{const o=await this.client.read(i,this.channel.key);o.acquire(),this.data.push(o)}catch(o){if(o instanceof Error&&(o.message.includes("cannot open iterator on virtual channel")||o.message.includes("cannot read from free channel")))console.warn("failed to read calculated channel data",o);else throw o}this.stopStreaming?.();const a=o=>{if(this.channel==null)return;const l=o.get(this.channel.key);l!=null&&(l.acquire(),this.data.push(l),this.notify(),this.gcOutOfRangeData())};this.stopStreaming=await this.client.stream(a,[this.channel.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s.Yr.fromException(e,"failed to stream channel data"))}}gcOutOfRangeData(){const e=this.now().sub(this.props.keepFor??this.props.timeSpan),t=this.data.series.findIndex(r=>r.timeRange.end.before(e));t!==-1&&(this.data.series.splice(t,1).forEach(r=>r.release()),this.gcOutOfRangeData())}cleanup(){this.stopStreaming?.(),this.stopStreaming=void 0,this.data.release(),this.valid=!1}}const ao={[Rt.TYPE]:Rt,[Lt.TYPE]:Lt,[Ct.TYPE]:Ct};class Ys{type="remote";client;constructor(e){this.client=e}create(e,t){const r=ao[e.type];return r==null?null:new r(this.client,e.props,t)}}const Is=n=>({type:Rt.TYPE,props:n,variant:"source",valueType:"series"}),zs=n=>({type:Lt.TYPE,props:n,variant:"source",valueType:"series"}),Ns=n=>({type:Ct.TYPE,props:n,variant:"source",valueType:"number"});class Zs{type="static";create(e){switch(e.type){case kn.TYPE:return new kn(e.props);case Pt.TYPE:return new Pt(e.props);case kt.TYPE:return new kt(e.props);case Ot.TYPE:return new Ot(e.props);case _t.TYPE:return new _t(e.props);default:return null}}}const ar=h.z.object({data:h.z.array(s.de),offsets:h.z.array(h.z.number()).optional().default([])});class kn extends U{data;schema=ar;static TYPE="static-series";constructor(e){super(e),this.data=this.props.data.map((t,r)=>new s.x({data:t,dataType:s.n.FLOAT32,timeRange:s.m.ZERO,sampleOffset:this.props.offsets[r]??0}))}value(){return[s.H.max(this.data.map(t=>t.bounds)),this.data]}}const js=ar.extend({rate:s.v.z,yOffset:h.z.number().optional().default(0),scroll:h.z.number().optional().default(0),startPosition:h.z.number().optional().default(0),scrollBounds:h.z.boolean().optional().default(!1)});class Pt extends U{static TYPE="iterative-series";schema=js;position;interval;data;constructor(e){super(e),this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((t,r)=>new s.x({data:t,dataType:s.n.FLOAT32,timeRange:s.m.ZERO,sampleOffset:this.props.offsets[r]??0}))}value(){const e=this.data.map(r=>r.slice(0,this.position));if(this.props.scrollBounds){const r=e[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=e[0].data[this.position-1];return[{lower:Number(r),upper:Number(i)},new s.Oe(e)]}return[s.H.max(e.map(r=>r.bounds)),new s.Oe(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 $s=h.z.number();class kt extends U{static TYPE="static-numeric";schema=$s;value(){return this.props}}const Bs=h.z.string();class Ot extends U{static TYPE="static-string";schema=Bs;value(){return this.props}}const Us=s.Lr.crudeZ;class _t extends U{static TYPE="static-color";schema=Us;value(){return s.Lr.construct(this.props)}}const oo=n=>({type:kn.TYPE,props:n,variant:"source",valueType:"series"}),lo=n=>({type:Pt.TYPE,props:n,variant:"source",valueType:"series"}),co=n=>({type:kt.TYPE,props:n,variant:"source",valueType:"number"}),uo=n=>({type:Ot.TYPE,props:n,variant:"source",valueType:"string"}),ho=n=>({type:_t.TYPE,props:n,variant:"source",valueType:"color"});class qs{type="transformer";create(e){switch(e.type){case Le.TYPE:return new Le(e.props);case Pe.TYPE:return new Pe(e.props);case ke.TYPE:return new ke(e.props);case Oe.TYPE:return new Oe(e.props);case _e.TYPE:return new _e(e.props);case Mt.TYPE:return new Mt(e.props);case Me.TYPE:return new Me(e.props);case Ae.TYPE:return new Ae(e.props)}return null}}const fo=h.z.object({truthy:h.z.number().optional().default(1),falsy:h.z.number().optional().default(0)}),Hs=n=>({props:n,type:Le.TYPE,variant:"sink",valueType:"boolean"});class Le extends _s{static TYPE="boolean-numeric-converter-sink";static propsZ=fo;schema=Le.propsZ;transform(...e){return e.map(t=>t?this.props.truthy:this.props.falsy)}}const or=h.z.object({trueBound:s.H.bounds}),Fs=n=>({props:n,type:Pe.TYPE,variant:"source",valueType:"boolean"});class Pe extends fe{static TYPE="boolean-source";static propsZ=or;schema=Pe.propsZ;curr=null;shouldNotify(e){const t=s.H.contains(this.props.trueBound,e)!==this.curr;return this.curr=s.H.contains(this.props.trueBound,e),t}transform(e){return this.curr=s.H.contains(this.props.trueBound,e),this.curr}}const Qs=h.z.object({});class ke extends Os{static TYPE="mean";static propsZ=Qs;schema=ke.propsZ;transform(e){return Object.values(e).reduce((t,r)=>t+r,0)/Object.keys(e).length}}const po=n=>({props:n,type:ke.TYPE,variant:"source",valueType:"boolean"}),Ws=h.z.object({trueVariant:s.Yr.variantZ.optional().default("success")});class Oe extends fe{static TYPE="boolean-status";static propsZ=Ws;schema=Oe.propsZ;transform(e){return e.variant===this.props.trueVariant}}const go=n=>({props:n,type:Oe.TYPE,variant:"source",valueType:"boolean"}),lr=h.z.object({precision:h.z.number().optional().default(2),prefix:h.z.string().optional().default(""),suffix:h.z.string().optional().default(""),notation:s.Gr.notationZ.optional().default("standard")});class _e extends fe{static TYPE="stringify-number";static propsZ=lr;schema=_e.propsZ;transform(e){if(isNaN(e))return"";const{precision:t,prefix:r,suffix:i,notation:a}=this.props;return`${r}${s.Gr.stringifyNumber(e,t,a)}${i}`}}const Gs=n=>({props:n,type:_e.TYPE,variant:"source",valueType:"string"}),cr=h.z.object({windowSize:h.z.number().optional().default(5)});class Mt extends fe{static TYPE="rolling-average";static propsZ=Qs;schema=cr;values=[];transform(e){return this.props.windowSize<2||isNaN(e)?e:this.values.reduce((t,r)=>t+r,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 Vs=n=>({props:n,type:Mt.TYPE,variant:"source",valueType:"number"}),Xs=h.z.object({gradient:s.Lr.gradientZ});class Me extends fe{static TYPE="color-gradient";static propsZ=Xs;schema=Me.propsZ;transform(e){return s.Lr.fromGradient(this.props.gradient,e)}}const Ks=n=>({props:n,type:Me.TYPE,variant:"source",valueType:"color"}),Js=h.z.object({scale:s.C$1.transform});class Ae extends fe{static TYPE="scale-number";static propsZ=Js;schema=Ae.propsZ;transform(e){if(isNaN(e))return e;const{offset:t,scale:r}=this.props.scale;return e*r+t}}const ei=n=>({props:n,type:Ae.TYPE,variant:"source",valueType:"number"}),ur=h.z.enum(["average","decimate"]),mo=h.z.object({mode:ur,windowSize:h.z.number().optional().default(5)}),yo=n=>({props:n,type:Xe.TYPE,variant:"source",valueType:"number"}),ti=(n,e,t)=>{const r=e.length*t;for(let i=r;i<n.length;i+=t){const a=n.sub(i,i+1);a!==void 0&&e.write(a)}},vo=(n,e,t)=>{const r=e.length*t;for(let i=r;i<n.length&&!(i+t>n.length);i+=t){const a=Math.min(i+t,n.length);let o=0,l=0;for(let u=i;u<a;u++){const c=n.at(u);c!==void 0&&typeof c=="number"&&(o+=c,l++)}l>0&&e.write(new s.x({data:[o/l],dataType:n.dataType}))}},bo={decimate:ti,average:vo};class Xe{static TYPE="series-downsampler";_downsample=null;cache=new s.Oe;props;constructor(e){this.props=e}downsample(e){return this._downsample==null&&(e.series[0].sampleOffset!==0?this._downsample=ti:this._downsample=bo[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,r)=>{let i=this.cache.series.at(r);if(i==null){const a=Math.ceil(t.capacity/this.props.windowSize);i=s.x.alloc({key:t.key+s.Dt.create(),dataType:t.dataType,capacity:a,alignment:t.alignment,alignmentMultiple:BigInt(this.props.windowSize),sampleOffset:t.sampleOffset,timeRange:t.timeRange}),this.cache.push(i)}else if(!i.key.startsWith(t.key))throw new g.Bt(`[SeriesDownsampler] - expected series with key ${t.key} to be in cache, but found ${i.key}`);this.downsample(e)(t,i,this.props.windowSize)}),this.cache}}const So=n=>({props:n,type:Xe.TYPE,variant:"source",valueType:"series"});class hr{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 r of this.factories){const i=r.create(e,t);if(i!=null)return i}return null}}const ni=n=>{const e=[new qs,new Zs,new Es],t=new hr(e);return n!=null&&t.add(new Ys(n)),t.add(new rr(t)),t};let ri=class si{factory;key;parent;constructor(e,t){this.factory=e,this.key=s.Dt.create(),this.parent=t}child(e,t){const r=new hr([...this.factory.factories,...s.a.toArray(e)]);return r.add(new rr(r)),new si(r,t)}create(e,t){const r=this.factory.create(e,t);if(r==null)throw new g.Bt(`Telemetry service could not find a source for type ${e.type}`);return r}};const ct="pluto-telem-context",rn=n=>n.get(ct),ii=(n,e)=>n.set(ct,e),ai=(n,e,t)=>{const r=rn(n);if(r!=null&&t!=null&&r.key===t?.parent?.key)return t;const i=r.child(e,r);return n.set(ct,i),i};class oi{spec;wrapped;prevProv;constructor(e,t,r){this.wrapped=e,this.spec=r,this.prevProv=t}shouldUpdate(e,t){return this.prevProv.key!==e.key||!K.T.equal(this.spec,t)}}class Ur extends oi{value(){return this.wrapped.value()}cleanup(){this.wrapped.cleanup?.()}onChange(e){return this.wrapped.onChange(e)}}class qr extends oi{set(...e){this.wrapped.set(...e)}cleanup(){this.wrapped.cleanup?.()}}const j=(n,e,t,r)=>{const i=rn(n);if(t instanceof Ur){if(!t.shouldUpdate(i,e))return t;t.cleanup?.()}return new Ur(i.create(e,r),i,e)},je=(n,e,t,r)=>{const i=rn(n);if(t instanceof qr){if(!t.shouldUpdate(i,e))return t;t.cleanup?.()}return new qr(i.create(e,r),i,e)},To=h.z.object({props:g.JS.nullable(),state:g.XS.connectivity.connectionStateZ.nullable()}),dr={client:null};let At=class li extends g.Composite{static TYPE="synnax.Provider";static stateZ=To;schema=li.stateZ;afterUpdate(e){if(e.wasSetPreviously(fr)||un(e,dr),this.state.props==null){this.internal.client!=null&&(this.internal.client?.close(),this.internal.client=null),un(e,this.internal);return}this.prevState.props!=null&&K.T.equal(this.state.props,this.prevState.props)&&this.internal.client!=null||(this.internal.client=new g.XS(this.state.props),un(e,this.internal))}};const fr="pluto-client-context",un=(n,e)=>n.set(fr,e),$e=n=>n.get(fr)?.client??null,ci={[At.TYPE]:At},xo=Object.freeze(Object.defineProperty({__proto__:null,Provider:At,REGISTRY:ci,ZERO_CONTEXT_VALUE:dr,use:$e},Symbol.toStringTag,{value:"Module"})),ui=(n,e)=>n.dataType.isVariable||n.dataType.equals(s.n.UINT8)?n:(e==null&&n.dataType.equals(s.n.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(s.n.FLOAT32,e)),wo=n=>n.isVariable||n.equals(s.n.UINT8)?n:s.n.FLOAT32,hi=()=>({purgedSeries:0,purgedBytes:s.c$2.bytes(0)}),di={instrumentation:g.g.NOOP,staleEntryThreshold:s.a$1.seconds(20)};class Eo{data=[];props;constructor(e){this.props={...di,...e}}write(e){e.length!==0&&(e.series.forEach(t=>this.writeOne(ui(t))),this.checkIntegrity(e))}dirtyRead(e){const t=this.data.filter(({data:o})=>o.timeRange.overlapsWith(e)).map(({data:o})=>o);if(t.length===0)return{series:new s.Oe([]),gaps:[e]};const r=t.map((o,l)=>l===0?s.m.ZERO:new s.m(t[l-1].timeRange.end,o.timeRange.start)).filter(o=>!o.span.isZero&&o.isValid),i=new s.m(e.start,t[0].timeRange.start),a=new s.m(t[t.length-1].timeRange.end,e.end);return i.isValid&&!i.span.isZero&&r.unshift(i),a.isValid&&!a.span.isZero&&r.push(a),{series:new s.Oe(t),gaps:r}}gc(){const{staleEntryThreshold:e}=this.props,t=hi(),r=this.data.filter(i=>{const a=i.data.refCount>0||s.r.since(i.addedAt).lessThan(e);return a||(t.purgedBytes=t.purgedBytes.add(i.data.byteCapacity)),a});return t.purgedSeries=this.data.length-r.length,this.data=r,t}close(){this.data=[]}writeOne(e){const{instrumentation:{L:t}}=this.props;if(e.length===0)return;const r=s.H.buildInsertionPlan(this.data.map(u=>u.data.alignmentBounds),e.alignmentBounds);if(r===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(u=>u.data.digest)});const{removeBefore:i,removeAfter:a,insertInto:o,deleteInBetween:l}=r;e=e.slice(i,e.data.length-a),e.length!==0&&this.data.splice(o,l,{data:e,addedAt:s.r.now()})}checkIntegrity(e){const{instrumentation:{L:t}}=this.props,r=this.data.map(a=>a.data.alignmentBounds);if(r.some((a,o)=>r.some((l,u)=>o===u?!1:s.H.overlapsWith(a,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.series.map(a=>a.digest),cacheContents:this.data.map(a=>a.data.digest)})),new Error("Invalid state")}}const Co=100,Ro=1e6,Lo=1e4,Po=100,ko=40;class Oo{props;counter=0;curr;avgRate=0;timeOfLastWrite;totalWrites=0;now=()=>s.r.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(r=>this._write(r));return{flushed:new s.Oe(t.flatMap(r=>r.flushed.series)),allocated:new s.Oe(t.flatMap(r=>r.allocated.series))}}allocate(e,t,r){this.counter++;const i=this.props.dataType.isVariable,a=this.props.dataType.equals(s.n.TIMESTAMP);return s.x.alloc({capacity:i?e*ko:e,dataType:wo(this.props.dataType),timeRange:r.range(s.r.MAX),sampleOffset:a?r.valueOf():0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),r={flushed:new s.Oe([]),allocated:new s.Oe([])};if(this.curr==null)this.curr=this.allocate(t,e.alignment,this.now()),r.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,r.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,u),r.allocated.push(this.curr)}const i=ui(e,this.curr.sampleOffset),a=this.curr.write(i);if(a===e.length)return this.updateAvgRate(e),r;const o=this.now();this.curr.timeRange.end=o,r.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment+BigInt(a),o),r.allocated.push(this.curr);const l=this._write(e.slice(a));return r.flushed.push(l.flushed),r.allocated.push(l.allocated),r}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<Po)return Lo;const t=s.Rr.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,Ro),Co))}close(){this.curr=null}}class _o{channel;closed=!1;ins;static;dynamic;constructor(e){this.channel=e.channel,this.ins=e.instrumentation??g.g.NOOP,this.static=new Eo(e),this.dynamic=new Oo({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 s.Oe([]);const{flushed:t,allocated:r}=this.dynamic.write(e);return t.length>0&&this.static.write(t),r}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 s.Oe([]),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:s.c$2.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const Mo=g.k.seconds(60);class Ao{props;cache=new Map;gcInterval;constructor(e){this.props={dynamicBufferSize:Mo,gcInterval:g.k.seconds(30),...di,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:r,dynamicBufferSize:i}=this.props,a=[];for(const l of e)this.cache.has(l)||a.push(l);if(a.length===0)return;(await r.retrieve(a)).forEach(l=>{if(this.cache.has(l.key))return;const u=new _o({channel:l,dynamicBufferSize:i,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 g.Bt(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=hi();this.cache.forEach(r=>{const i=r.gc();t.purgedSeries+=i.purgedSeries,t.purgedBytes=t.purgedBytes.add(i.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 Do{args;debouncedRead;mu=s.en.newMutex({requests:new Set,closed:!1});constructor(e){this.args={...e,instrumentation:e.instrumentation??g.g.NOOP,batchDebounce:e.batchDebounce??s.a$1.milliseconds(50),overlapThreshold:e.overlapThreshold??s.a$1.milliseconds(5)};const t=this.args.batchDebounce.milliseconds;this.debouncedRead=Qn.o(()=>void this.batchRead(),t)}async read(e,t){const{cache:r}=this.args;await r.populateMissing([t]);const i=r.get(t),{series:a,gaps:o}=i.read(e);if(o.length===0)return a;const{mu:l}=this;return await new Promise((u,c)=>{l.runExclusive(async()=>{l.closed||l.requests.add({channel:t,gaps:o,resolve:u,reject:c})}),this.debouncedRead()}),i.read(e).series}async batchRead(){const{readRemote:e,cache:t,overlapThreshold:r}=this.args,{mu:i}=this;await i.runExclusive(async()=>{const a=o=>i.requests.forEach(({resolve:l,reject:u})=>o==null?l():u(o));try{if(i.closed)return a();const o=[];i.requests.forEach(({channel:l,gaps:u})=>u.forEach(c=>{const d=o.find(f=>f.gap.equals(c,r));d==null?o.push({gap:c,channels:new Set([l])}):(d.channels.add(l),d.gap=s.m.max(d.gap,c))})),await Promise.all(o.map(async({gap:l,channels:u})=>{const c=await e(l,Array.from(u));u.forEach(d=>t.get(d).writeStatic(c.get(d)))})),a()}catch(o){a(o)}finally{i.requests.clear()}})}async close(){await this.mu.runExclusive(async()=>{this.mu.closed=!0})}}const Yo=new Error("request for lock canceled");var Io=function(n,e,t,r){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(d){try{c(r.next(d))}catch(f){o(f)}}function u(d){try{c(r.throw(d))}catch(f){o(f)}}function c(d){d.done?a(d.value):i(d.value).then(l,u)}c((r=r.apply(n,e||[])).next())})};class zo{constructor(e,t=Yo){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((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:t},o=fi(this._queue,l=>t<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Io(this,arguments,void 0,function*(t,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield t(a)}finally{o()}})}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(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),No(this._weightedWaiters[e-1],{resolve:r,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(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const r=this._weightedWaiters[t-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function No(n,e){const t=fi(n,r=>e.priority<=r.priority);n.splice(t+1,0,e)}function fi(n,e){for(let t=n.length-1;t>=0;t--)if(e(n[t]))return t;return-1}var Zo=function(n,e,t,r){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(d){try{c(r.next(d))}catch(f){o(f)}}function u(d){try{c(r.throw(d))}catch(f){o(f)}}function c(d){d.done?a(d.value):i(d.value).then(l,u)}c((r=r.apply(n,e||[])).next())})};class jo{constructor(e){this._semaphore=new zo(1,e)}acquire(){return Zo(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 $o=s.a$1.milliseconds(100).milliseconds;class Bo{props;mu=new jo;listeners=new Map;debouncedUpdateStreamer;streamerRunLoop=null;streamer=null;closed=!1;constructor(e){this.props={instrumentation:g.g.NOOP,...e,streamUpdateDelay:new s.a$1(e.streamUpdateDelay??s.a$1.seconds(5))},this.debouncedUpdateStreamer=Qn.o(()=>void this.updateStreamer(),$o)}async stream(e,t){const{cache:r,instrumentation:i}=this.props;return this.closed?()=>{}:(await r.populateMissing(t),await this.mu.runExclusive(async()=>{i.L.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:new Set(t)});const a=new Map(t.map(o=>{const l=r.get(o);return[o,new s.Oe(s.a.toArray(l.leadingBuffer))]}));return e(a),this.debouncedUpdateStreamer(),()=>this.removeStreamHandler(e)}))}removeStreamHandler(e){const{instrumentation:t}=this.props;this.mu.runExclusive(()=>{const r=this.listeners.get(e);r!=null&&(r.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(a=>a.keys.forEach(o=>t.add(o))),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 r=Array.from(t);if(K.q.primitiveArrays(r,this.streamer?.keys??[])===K.q.EQUAL){e.L.debug("streamer keys unchanged",{keys:r});return}this.streamer==null&&(e.L.info("creating new streamer",{keys:r}),this.streamer=await this.props.openStreamer({channels:r}),this.streamerRunLoop=this.runStreamer(this.streamer)),e.L.debug("updating streamer",{prev:this.streamer.keys,next:r}),await this.streamer.update(r)}catch(t){throw e.L.error("failed to update streamer",{error:t}),t}}async runStreamer(e){const{cache:t,instrumentation:r}=this.props;try{for await(const i of e){const a=new Map;for(const o of i.keys){const l=i.get(o),c=t.get(o).writeDynamic(l);a.set(o,c)}a.size!==0&&this.listeners.forEach(({valid:o},l)=>o&&l(a))}}catch(i){throw r.L.error("streamer run loop failed",{error:i},!0),i}}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 Uo{async retrieveChannel(){throw new g.Pr("NoopClient does not support retrieving channels")}async read(){return new s.Oe([])}async stream(){return async()=>{}}async close(){}}class qo{ins;cache;reader;streamer;channelRetriever;constructor({instrumentation:e,core:t}){this.ins=e,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new Ao({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new Do({cache:this.cache,readRemote:t.read.bind(t),instrumentation:this.ins.child("reader")}),this.streamer=new Bo({cache:this.cache,openStreamer:async r=>g.qI.HardenedStreamer.open(t.openStreamer.bind(t),r),instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new g.nt(`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 pr=h.z.object({});class De extends g.Composite{static TYPE="telem.Provider";static stateZ=pr;schema=De.stateZ;prevCore=null;client=null;afterUpdate(e){const{internal:t}=this,r=$e(e),i=g.useErrorHandler(e);if(t.instrumentation=M.useInstrumentation(e,"telem").child("provider"),!(r!==this.prevCore||!e.wasSetPreviously(ct)))return;this.prevCore=r,this.client!=null&&i(async()=>{if(this.client==null)throw new Error("no client to close");await this.client.close()},"failed to close client"),this.client=r==null?new Uo:new qo({core:r,instrumentation:t.instrumentation});const o=ni(this.client),l=new ri(o);ii(e,l)}}const pi={[De.TYPE]:De},Ho=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:nn,AbstractSource:U,Base:tn,BaseProvider:De,BooleanStatus:Oe,CONTEXT_KEY:ct,ChannelData:Rt,ColorGradient:Me,CompoundTelemFactory:hr,Context:ri,FixedColorSource:_t,FixedNumber:kt,FixedString:Ot,IterativeSeries:Pt,Mean:ke,MultiSourceTransformer:Os,NoopFactory:Es,PipelineFactory:rr,REGISTRY:pi,RemoteFactory:Ys,RollingAverage:Mt,ScaleNumber:Ae,SeriesDownsampler:Xe,SetPoint:Le,SinkPipeline:Et,SourcePipeline:wt,StaticFactory:Zs,StreamChannelData:Lt,StreamChannelValue:Ct,StringifyNumber:_e,TransformerFactory:qs,UnarySinkTransformer:_s,UnarySourceTransformer:fe,WithinBounds:Pe,booleanSinkSpecZ:Kt,booleanSinkTransformerSpecZ:no,booleanSourceSpecZ:Jn,booleanSourceTransformerSpecZ:ro,booleanStatus:go,booleanStatusProps:Ws,channelData:Is,colorGradient:Ks,colorGradientProps:Xs,colorSourceSpecZ:Jt,connectionZ:tr,createFactory:ni,downsampleMode:yo,downsampleModeProps:mo,downsampleModeZ:ur,fixedArray:oo,fixedColor:ho,fixedColorSourcePropsZ:Us,fixedNumber:co,fixedNumberPropsZ:$s,fixedSeriesPropsZ:ar,fixedString:uo,fixedStringPropsZ:Bs,iterativeArray:lo,iterativeSeriesPropsZ:js,mean:po,noopBooleanSinkSpec:Xt,noopBooleanSourceSpec:Vn,noopColorSourceSpec:at,noopNumericSinkSpec:Ss,noopNumericSourceSpec:Ts,noopSeriesSourceSpec:ws,noopStatusSourceSpec:Kn,noopStringSinkSpec:xs,noopStringSourceSpec:Xn,numberSinkSpecZ:Ps,numberSourceSpecZ:Ls,providerStateZ:pr,rollingAverage:Vs,rollingAverageProps:cr,scaleNumber:ei,scaleNumberProps:Js,seriesDownsampler:So,seriesSourceSpecZ:xt,setContext:ii,setpoint:Hs,sinkPipeline:As,sinkPipelinePropsZ:sr,sinkSpecZ:lt,sinkTransformerSpecZ:Rs,sourcePipeline:Ms,sourcePipelinePropsZ:nr,sourceSpecZ:ie,sourceTransformerSpecZ:Cs,specZ:ot,statusSourceSpecZ:er,streamChannelData:zs,streamChannelValue:Ns,streamChannelValuePropsZ:ir,stringSinkSpecZ:ks,stringSourceSpecZ:en,stringifyNumber:Gs,stringifyNumberProps:lr,useChildContext:ai,useContext:rn,useSink:je,useSource:j,withinBounds:Fs,withinBoundsProps:or},Symbol.toStringTag,{value:"Module"})),Hr=`#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
|
-
`,Fo=`#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
|
-
`,Qo=`#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
|
-
`,gr="pluto-vis-renderer",sn=(n,e)=>{n.set(gr,e,!1)},an=n=>n.get(gr),mr=n=>n.getOptional(gr),J=(n,e)=>an(n)(e),gi=h.z.object({x:xt,y:xt,label:h.z.string().optional(),color:s.Lr.colorZ,strokeWidth:h.z.number().default(1),downsample:h.z.number().min(1).max(50).default(1),downsampleMode:ur.default("decimate"),visible:h.z.boolean().optional().default(!0)}),Wo=(n,e,t)=>n===-1||e===-1||n>=t.series.length?NaN:Number(t.series[n].at(e)),Go=s.a$1.milliseconds(2);s.Q.NAN,s.Q.NAN,s.Lr.ZERO,s.H.ZERO;const Vo=(n,e)=>e.equals(s.n.UINT8)?n.UNSIGNED_BYTE:n.FLOAT;class Fr extends M.GLProgram{translationBufferCache=new Map;constructor(e,t,r){super(e,t,r),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:t}){return this.uniformColor("u_color",t),this.attrStrokeWidth(e)}bindScale(e,t){const r=s.Q.scale(e.scale,t.scale),i=s.Q.translate(s.Q.scale(t.scale,e.offset),t.offset);this.uniformXY("u_scale_aggregate",r),this.uniformXY("u_offset_aggregate",i)}draw({x:e,y:t,count:r,downsample:i,xOffset:a,yOffset:o},l,u,c){const{gl:d}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,i,a,u),this.bindAttrBuffer("y",t.glBuffer,i,o,c),d.drawArraysInstanced(d.LINE_STRIP,0,r/i,l)}bindAttrBuffer(e,t,r,i=0,a){const{gl:o}=this.renderCtx;o.bindBuffer(o.ARRAY_BUFFER,t);const l=o.getAttribLocation(this.prog,`a_${e}`),u=Vo(o,a),c=a.density.valueOf();a.equals(s.n.UINT8)?o.vertexAttribIPointer(l,1,u,c*r,c*i):o.vertexAttribPointer(l,1,u,!1,c*r,c*i),o.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:t}=this.renderCtx,r=`${this.renderCtx.aspect}:${e}`,i=this.translationBufferCache.get(r);if(i!=null)return t.bindBuffer(t.ARRAY_BUFFER,i.glBuffer),i;const a=t.createBuffer();if(a==null)throw new g.Bt("Failed to create buffer from WebGL context");const o=Ko(this.renderCtx.aspect,e);t.bindBuffer(t.ARRAY_BUFFER,a),t.bufferData(t.ARRAY_BUFFER,o,t.DYNAMIC_DRAW);const l={glBuffer:a,jsBuffer:o};return this.translationBufferCache.set(r,l),l}attrStrokeWidth(e){const{gl:t}=this.renderCtx,{jsBuffer:r}=this.getAndBindTranslationBuffer(e),i=t.getAttribLocation(this.prog,"a_translate");return t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(i),t.vertexAttribDivisor(i,1),r.length/2}}class Ce{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new Fr(e,Qo,Hr),this.float32Program=new Fr(e,Fo,Hr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(s.n.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,t){const r=new Ce(t);return e.set(Ce.CONTEXT_KEY,r),r}static use(e){const t=e.get(Ce.CONTEXT_KEY);if(t==null)throw new g.Bt("GLProgram not found");return t}}class Dt extends g.Leaf{static TYPE="line";schema=gi;afterUpdate(e){const{internal:t}=this,r={onStatusChange:g.useAdder(e)};t.xTelem=j(e,this.state.x,t.xTelem,r),t.yTelem=j(e,this.state.y,t.yTelem,r),t.instrumentation=M.useInstrumentation(e,"line"),t.lineCtx=Ce.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 Xe({mode:this.state.downsampleMode,windowSize:this.state.downsample}),t.yDownsampler=new Xe({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:r,yTelem:i}=this.internal;let[,a]=r.value();a=this.internal.xDownsampler.transform(a);let[o,l]=[-1,-1];a.series.find((T,C)=>{const k=T.binarySearch(t),R=k>=0&&k<T.length;return R&&([o,l]=[k,C]),R});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(o===-1||l===-1||!this.state.visible)return f;const p=a.series[l];f.value.x=Wo(l,o,a);let[,y]=i.value();y=this.internal.yDownsampler.transform(y);const S=y.series.find(T=>s.H.contains(T.alignmentBounds,p.alignment+BigInt(o)));if(S==null)return f;const b=Number(S.alignment-p.alignment);return f.value.y=Number(S.at(o-b)),f.bounds={...S.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:r,yTelem:i,lineCtx:a,xDownsampler:o,yDownsampler:l}=this.internal,{dataToDecimalScale:u,exposure:c}=e;let[[,d],[,f]]=[r.value(),i.value()];if(d=o.transform(d),f=l.transform(f),d.updateGLBuffer(a.gl),f.updateGLBuffer(a.gl),d.length===0||f.length===0)return;const p=a.getProgram(f.dataType),y=sl(d,f,c,t,this.state.downsampleMode,Go);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:t,scale:u.transform,props:e.region,ops:il(y)}));const S=p.setAsActive(),b=p.bindState(this.state),T=p.renderCtx.scaleRegion(e.region).transform;y.forEach(C=>{const k=nl(u,C).transform;p.bindScale(k,T),p.draw(C,b,d.dataType,f.dataType)}),S()}}const Xo=5e3,Ko=(n,e)=>tl(el(n),e).map((t,r)=>Math.floor(r/Jo)*(1/(Xo*n))*t),Jo=5,el=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),tl=(n,e)=>{const t=new Float32Array(n.length*e);for(let r=0;r<e;r++)t.set(n,r*n.length);return t},nl=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),rl={[Dt.TYPE]:Dt},sl=(n,e,t,r,i,a)=>{if(n.series.length===0||e.series.length===0)return[];const o=[];return n.series.forEach(l=>e.series.forEach(u=>{if(!al(l,u,a))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=s.Rr.min(s.H.span(l.alignmentBounds)-c,s.H.span(u.alignmentBounds)-d);if(f===0n)return;let p=s.R(Math.round(t*4*Number(f)),r,51);i!=="decimate"&&(p=1);const y=Number(f/l.alignmentMultiple),S=Number(c/l.alignmentMultiple),b=Number(d/u.alignmentMultiple);o.push({x:l,y:u,xOffset:S,yOffset:b,count:y,downsample:p})})),o},il=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),al=(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 r=n.timeRange.overlapsWith(e.timeRange,t),i=s.H.overlapsWith(n.alignmentBounds,e.alignmentBounds);return r&&i},yr=h.z.object({dpr:h.z.number(),region:s.jt.box,bootstrap:h.z.boolean().optional().default(!1),bootstrapped:h.z.boolean().optional().default(!1),glCanvas:h.z.any().optional(),upper2dCanvas:h.z.any().optional(),lower2dCanvas:h.z.any().optional(),os:s.S.osZ});class Yt extends g.Composite{static TYPE="Canvas";schema=yr;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:t,lower2dCanvas:r,upper2dCanvas:i,os:a}=this.state;if(t==null||r==null||i==null)throw new g.Bt("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=M.Context.create(e,t,r,i,a),Ce.create(e,this.renderCtx),this.setState(o=>({...o,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 mi={[Yt.TYPE]:Yt},ol=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Yt,REGISTRY:mi,canvasStateZ:yr},Symbol.toStringTag,{value:"Module"})),vr=h.z.object({position:s.Q.xy,zoom:h.z.number(),region:s.jt.box,clearOverScan:s.Q.crudeZ.optional().default(5),visible:h.z.boolean().optional().default(!0),autoRenderInterval:h.z.number().optional()}),yt=["upper2d","lower2d"];class he extends g.Composite{static TYPE="Diagram";static stateZ=vr;schema=he.stateZ;afterUpdate(e){this.internal.renderCtx=M.Context.use(e),this.internal.handleError=g.useErrorHandler(e),s.y.isNonZero(this.state.autoRenderInterval)&&(this.internal.autoRenderInterval??=setInterval(()=>{this.state.visible&&this.requestRender("low")},this.state.autoRenderInterval)),sn(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=s.C$1.XY.magnify(s.Q.construct(this.state.zoom)).translate(s.jt.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:r}=this.internal,i=s.jt.construct(this.state.region);if(!this.state.visible)return()=>e.erase(i,this.state.clearOverScan,...yt);const a=e.scissor(i,s.Q.ZERO,yt);try{this.children.forEach(l=>l.render?.({viewportScale:r}))}catch(l){t(l,"failed to render diagram")}finally{a()}const o=s.jt.copy(this.state.region);return()=>{e.lower2d.fillStyle=s.Lr.hex(s.Lr.BLACK),e.lower2d.fillRect(...s.Q.couple(s.jt.topLeft(o)),s.jt.width(o),s.jt.height(o)),e.erase(o,this.state.clearOverScan,...yt)}}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${he.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:yt})}}const yi={[he.TYPE]:he},ll=Object.freeze(Object.defineProperty({__proto__:null,Diagram:he,REGISTRY:yi,diagramStateZ:vr},Symbol.toStringTag,{value:"Module"}));class vi{entries=new Map;setListeners=new Map;deleteListeners=new Map;handleError;equal;constructor(e,t=()=>!1){this.handleError=e,this.equal=t}setOne(e,t,r,i){const a=this.entries.get(t),o=ce.executeSetter(r,a);if(!(o==null||a!=null&&this.equal(o,a,t)))return this.entries.set(t,o),this.notifySet(e,t,o,i),()=>{a===void 0?(this.entries.delete(t),this.notifyDelete(e,t)):(this.entries.set(t,a),this.notifySet(e,t,a,i))}}set(e,t,r,i){const a=[];if(Array.isArray(t))t.forEach(o=>{const l=this.setOne(e,o.key,o,r);l!=null&&a.push(l)});else if(typeof t=="object"&&"key"in t){const o=t,l=this.setOne(e,o.key,o,r);l!=null&&a.push(l)}else{const o=this.setOne(e,t,r,i);o!=null&&a.push(o)}return()=>a.reverse().forEach(o=>o())}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,r){const i=[];return typeof t=="function"?this.entries.forEach((a,o)=>{t(a,o)&&i.push({key:o,value:a})}):s.a.toArray(t).forEach(a=>{const o=this.entries.get(a);i.push({key:a,value:o})}),i.forEach(({key:a})=>{this.entries.delete(a),this.notifyDelete(e,a)}),()=>i.forEach(({key:a,value:o})=>{o!=null&&(this.entries.set(a,o),this.notifySet(e,a,o,r))})}clear(){this.entries.clear()}onSet(e,t,r){return this.setListeners.set(t,{scope:e,key:r}),()=>this.setListeners.delete(t)}onDelete(e,t,r){return this.deleteListeners.set(t,{scope:e,key:r}),()=>this.deleteListeners.delete(t)}notifySet(e,t,r,i){this.setListeners.forEach((a,o)=>{const l=a.key==null||a.key===t,u=a.scope!==e;l&&u&&this.handleError(async()=>await o(r,i),"Failed to notify set listener")})}notifyDelete(e,t){this.deleteListeners.forEach((r,i)=>{const a=r.key==null||r.key===t,o=r.scope!==e;a&&o&&this.handleError(async()=>await i(t),"Failed to notify delete listener")})}scope(e){return{set:(t,r,i)=>this.set(e,t,r,i),get:(t=>this.get(t)),list:()=>this.list(),has:t=>this.has(t),delete:(t,r)=>this.delete(e,t,r),onSet:(t,r)=>this.onSet(e,t,r),onDelete:(t,r)=>this.onDelete(e,t,r)}}}const bi=(n,e)=>Object.fromEntries(Object.entries(n).map(([t,{equal:r}])=>[t,new vi(e,r)])),On=(n,e)=>Object.fromEntries(Object.entries(n).map(([t])=>[t,n[t].scope(e)])),cl=(n,e,t)=>n.set(e,r=>r==null?void 0:{...r,...t}),ul=(n,e)=>{const t=n.includes("delete"),r=e.includes("delete");return t&&!r?-1:!t&&r?1:0},hl=async({openStreamer:n,storeConfig:e,handleError:t,client:r,store:i})=>{const a=Object.values(e),o=s.c.unique(a.flatMap(({listeners:f})=>f.map(({channel:p})=>p))),l={};a.forEach(({listeners:f})=>f.forEach(p=>{const{channel:y}=p;l[y]=[...l[y]||[],p]}));const u=await g.qI.HardenedStreamer.open(n,o),c=new g.qI.ObservableStreamer(u),d=f=>{const p=[...f.uniqueNames];p.sort(ul),t(async()=>{for(const y of p){const S=f.get(y),b=l[y];if(b!=null)for(const{onChange:T,schema:C}of b)await t(async()=>{let k;S.dataType.equals(s.n.JSON)?k=S.parseJSON(C):k=Array.from(S).map(R=>C.parse(R));for(const R of k)await t(()=>T({changed:R,client:r,store:i}),`Failed to handle streamer change for ${y}`,g.Pr)},`Failed to parse streamer change for ${y}`)}},`Failed to handle streamer change for ${s.Kr.naturalLanguageJoin(p)}`)};return c.onChange(d),c.close.bind(c)};class Si{store;streamCloser=null;client;constructor({client:e,openStreamer:t,storeConfig:r,handleError:i,handleAsyncError:a}){this.store=bi(r,i),this.client=e,e!=null&&(t??=e?.openStreamer.bind(e),this.streamCloser=hl({client:e,storeConfig:r,handleError:a,store:On(this.store,""),openStreamer:t}))}async awaitInitialized(){this.streamCloser!=null&&await this.streamCloser}scopedStore(e){return On(this.store,e)}async close(){if(this.streamCloser==null)return;await(await this.streamCloser)()}}const Ti=h.object({}),_n="flux-context",br="flux.Provider",dl=(n,e)=>n.get(_n).scopedStore(e),fl=n=>{const e=(t,r)=>{if("client"in n)return n.client;const i=$e(t);return r!=null&&r?.client?.key===i?.key?r:new Si({client:i,storeConfig:n.storeConfig,handleError:g.useErrorHandler(t),handleAsyncError:g.useAsyncErrorHandler(t)})};return class xi extends g.Composite{static TYPE=br;static stateZ=Ti;schema=xi.stateZ;afterUpdate(r){const{internal:i}=this;i.store=e(r,i.store),r.wasSetPreviously(_n)||r.set(_n,i.store)}}},pl=n=>({[br]:fl(n)}),gl="relationships",ml="resources",yl={channel:g.AI.RELATIONSHIP_SET_CHANNEL_NAME,schema:g.AI.relationshipZ,onChange:({store:n,changed:e})=>n.relationships.set(g.AI.relationshipToString(e),e)},vl={channel:g.AI.RELATIONSHIP_DELETE_CHANNEL_NAME,schema:g.AI.relationshipZ,onChange:({store:n,changed:e})=>{n.relationships.delete(g.AI.relationshipToString(e))}},bl={equal:(n,e)=>g.AI.idsEqual(n.from,e.from)&&g.AI.idsEqual(n.to,e.to)&&n.type===e.type,listeners:[yl,vl]},Sl={channel:g.AI.RESOURCE_SET_CHANNEL_NAME,schema:g.AI.resourceZ,onChange:async({store:n,changed:e})=>{n.resources.set(e.key,t=>t==null?e:{...t,...e})}},Tl={channel:g.AI.RESOURCE_DELETE_CHANNEL_NAME,schema:g.AI.idZ,onChange:({store:n,changed:e})=>n.resources.delete(e.key)},xl={equal:(n,e)=>K.T.equal(n,e),listeners:[Sl,Tl]},wl=h.object({request:h.string(),bounds:h.record(h.string(),s.H.bounds)}),wi=h.object({request:h.string(),response:wl});class It extends g.Leaf{static TYPE="Bounds";schema=wi;afterUpdate(e){this.state.request!==this.prevState.request&&this.setState(t=>({...t,response:{request:t.request,bounds:this.internal.getBounds()}}))}render(e){this.internal.getBounds=e.getBounds}}function bt(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function El(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function Sr(n){let e,t,r;n.length!==2?(e=bt,t=(l,u)=>bt(n(l),u),r=(l,u)=>n(l)-u):(e=n===bt||n===El?n:Cl,t=n,r=n);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){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 o(l,u,c=0,d=l.length){const f=i(l,u,c,d-1);return f>c&&r(l[f-1],u)>-r(l[f],u)?f-1:f}return{left:i,center:o,right:a}}function Cl(){return 0}function Rl(n){return n===null?NaN:+n}const Ll=Sr(bt),Pl=Ll.right;Sr(Rl).center;const kl=Math.sqrt(50),Ol=Math.sqrt(10),_l=Math.sqrt(2);function zt(n,e,t){const r=(e-n)/Math.max(0,t),i=Math.floor(Math.log10(r)),a=r/Math.pow(10,i),o=a>=kl?10:a>=Ol?5:a>=_l?2:1;let l,u,c;return i<0?(c=Math.pow(10,-i)/o,l=Math.round(n*c),u=Math.round(e*c),l/c<n&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,i)*o,l=Math.round(n/c),u=Math.round(e/c),l*c<n&&++l,u*c>e&&--u),u<l&&.5<=t&&t<2?zt(n,e,t*2):[l,u,c]}function Ml(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const r=e<n,[i,a,o]=r?zt(e,n,t):zt(n,e,t);if(!(a>=i))return[];const l=a-i+1,u=new Array(l);if(r)if(o<0)for(let c=0;c<l;++c)u[c]=(a-c)/-o;else for(let c=0;c<l;++c)u[c]=(a-c)*o;else if(o<0)for(let c=0;c<l;++c)u[c]=(i+c)/-o;else for(let c=0;c<l;++c)u[c]=(i+c)*o;return u}function Mn(n,e,t){return e=+e,n=+n,t=+t,zt(n,e,t)[2]}function An(n,e,t){e=+e,n=+n,t=+t;const r=e<n,i=r?Mn(e,n,t):Mn(n,e,t);return(r?-1:1)*(i<0?1/-i:i)}function Ei(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function Al(n){return function(){return n}}function Dl(n){return+n}var Qr=[0,1];function xe(n){return n}function Dn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Al(isNaN(e)?NaN:.5)}function Yl(n,e){var t;return n>e&&(t=n,n=e,e=t),function(r){return Math.max(n,Math.min(e,r))}}function Il(n,e,t){var r=n[0],i=n[1],a=e[0],o=e[1];return i<r?(r=Dn(i,r),a=t(o,a)):(r=Dn(r,i),a=t(a,o)),function(l){return a(r(l))}}function zl(n,e,t){var r=Math.min(n.length,e.length)-1,i=new Array(r),a=new Array(r),o=-1;for(n[r]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++o<r;)i[o]=Dn(n[o],n[o+1]),a[o]=t(e[o],e[o+1]);return function(l){var u=Pl(n,l,1,r)-1;return a[u](i[u](l))}}function Ci(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function Nl(){var n=Qr,e=Qr,t=Vt,r,i,a,o=xe,l,u,c;function d(){var p=Math.min(n.length,e.length);return o!==xe&&(o=Yl(n[0],n[p-1])),l=p>2?zl:Il,u=c=null,f}function f(p){return p==null||isNaN(p=+p)?a:(u||(u=l(n.map(r),e,t)))(r(o(p)))}return f.invert=function(p){return o(i((c||(c=l(e,n.map(r),Ve)))(p)))},f.domain=function(p){return arguments.length?(n=Array.from(p,Dl),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=Ja,d()},f.clamp=function(p){return arguments.length?(o=p?!0:xe,d()):o!==xe},f.interpolate=function(p){return arguments.length?(t=p,d()):t},f.unknown=function(p){return arguments.length?(a=p,f):a},function(p,y){return r=p,i=y,d()}}function Ri(){return Nl()(xe,xe)}function Zl(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function Nt(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,r=n.slice(0,t);return[r.length>1?r[0]+r.slice(2):r,+n.slice(t+1)]}function Ye(n){return n=Nt(Math.abs(n)),n?n[1]:NaN}function jl(n,e){return function(t,r){for(var i=t.length,a=[],o=0,l=n[0],u=0;i>0&&l>0&&(u+l+1>r&&(l=Math.max(1,r-u)),a.push(t.substring(i-=l,i+l)),!((u+=l+1)>r));)l=n[o=(o+1)%n.length];return a.reverse().join(e)}}function $l(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var Bl=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Zt(n){if(!(e=Bl.exec(n)))throw new Error("invalid format: "+n);var e;return new Tr({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]})}Zt.prototype=Tr.prototype;function Tr(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+""}Tr.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 Ul(n){e:for(var e=n.length,t=1,r=-1,i;t<e;++t)switch(n[t]){case".":r=i=t;break;case"0":r===0&&(r=t),i=t;break;default:if(!+n[t])break e;r>0&&(r=0);break}return r>0?n.slice(0,r)+n.slice(i+1):n}var Li;function ql(n,e){var t=Nt(n,e);if(!t)return n+"";var r=t[0],i=t[1],a=i-(Li=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+Nt(n,Math.max(0,e+a-1))[0]}function Wr(n,e){var t=Nt(n,e);if(!t)return n+"";var r=t[0],i=t[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}const Gr={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:Zl,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)=>Wr(n*100,e),r:Wr,s:ql,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Vr(n){return n}var Xr=Array.prototype.map,Kr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Hl(n){var e=n.grouping===void 0||n.thousands===void 0?Vr:jl(Xr.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",r=n.currency===void 0?"":n.currency[1]+"",i=n.decimal===void 0?".":n.decimal+"",a=n.numerals===void 0?Vr:$l(Xr.call(n.numerals,String)),o=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",u=n.nan===void 0?"NaN":n.nan+"";function c(f){f=Zt(f);var p=f.fill,y=f.align,S=f.sign,b=f.symbol,T=f.zero,C=f.width,k=f.comma,R=f.precision,_=f.trim,A=f.type;A==="n"?(k=!0,A="g"):Gr[A]||(R===void 0&&(R=12),_=!0,A="g"),(T||p==="0"&&y==="=")&&(T=!0,p="0",y="=");var x=b==="$"?t:b==="#"&&/[boxX]/.test(A)?"0"+A.toLowerCase():"",D=b==="$"?r:/[%p]/.test(A)?o:"",re=Gr[A],Be=/[defgprs%]/.test(A);R=R===void 0?6:/[gprs]/.test(A)?Math.max(1,Math.min(21,R)):Math.max(0,Math.min(20,R));function ft(E){var G=x,z=D,se,pt,ve;if(A==="c")z=re(E)+z,E="";else{E=+E;var be=E<0||1/E<0;if(E=isNaN(E)?u:re(Math.abs(E),R),_&&(E=Ul(E)),be&&+E==0&&S!=="+"&&(be=!1),G=(be?S==="("?S:l:S==="-"||S==="("?"":S)+G,z=(A==="s"?Kr[8+Li/3]:"")+z+(be&&S==="("?")":""),Be){for(se=-1,pt=E.length;++se<pt;)if(ve=E.charCodeAt(se),48>ve||ve>57){z=(ve===46?i+E.slice(se+1):E.slice(se))+z,E=E.slice(0,se);break}}}k&&!T&&(E=e(E,1/0));var Se=G.length+E.length+z.length,F=Se<C?new Array(C-Se+1).join(p):"";switch(k&&T&&(E=e(F+E,F.length?C-z.length:1/0),F=""),y){case"<":E=G+E+z+F;break;case"=":E=G+F+E+z;break;case"^":E=F.slice(0,Se=F.length>>1)+G+E+z+F.slice(Se);break;default:E=F+G+E+z;break}return a(E)}return ft.toString=function(){return f+""},ft}function d(f,p){var y=c((f=Zt(f),f.type="f",f)),S=Math.max(-8,Math.min(8,Math.floor(Ye(p)/3)))*3,b=Math.pow(10,-S),T=Kr[8+S/3];return function(C){return y(b*C)+T}}return{format:c,formatPrefix:d}}var vt,Pi,ki;Fl({thousands:",",grouping:[3],currency:["$",""]});function Fl(n){return vt=Hl(n),Pi=vt.format,ki=vt.formatPrefix,vt}function Ql(n){return Math.max(0,-Ye(Math.abs(n)))}function Wl(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Ye(e)/3)))*3-Ye(Math.abs(n)))}function Gl(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,Ye(e)-Ye(n))+1}function Vl(n,e,t,r){var i=An(n,e,t),a;switch(r=Zt(r??",f"),r.type){case"s":{var o=Math.max(Math.abs(n),Math.abs(e));return r.precision==null&&!isNaN(a=Wl(i,o))&&(r.precision=a),ki(r,o)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(a=Gl(i,Math.max(Math.abs(n),Math.abs(e))))&&(r.precision=a-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(a=Ql(i))&&(r.precision=a-(r.type==="%")*2);break}}return Pi(r)}function Xl(n){var e=n.domain;return n.ticks=function(t){var r=e();return Ml(r[0],r[r.length-1],t??10)},n.tickFormat=function(t,r){var i=e();return Vl(i[0],i[i.length-1],t??10,r)},n.nice=function(t){t==null&&(t=10);var r=e(),i=0,a=r.length-1,o=r[i],l=r[a],u,c,d=10;for(l<o&&(c=o,o=l,l=c,c=i,i=a,a=c);d-- >0;){if(c=Mn(o,l,t),c===u)return r[i]=o,r[a]=l,e(r);if(c>0)o=Math.floor(o/c)*c,l=Math.ceil(l/c)*c;else if(c<0)o=Math.ceil(o*c)/c,l=Math.floor(l*c)/c;else break;u=c}return n},n}function Oi(){var n=Ri();return n.copy=function(){return Ci(n,Oi())},Ei.apply(n,arguments),Xl(n)}function Kl(n,e){n=n.slice();var t=0,r=n.length-1,i=n[t],a=n[r],o;return a<i&&(o=t,t=r,r=o,o=i,i=a,a=o),n[t]=e.floor(i),n[r]=e.ceil(a),n}const hn=new Date,dn=new Date;function Y(n,e,t,r){function i(a){return n(a=arguments.length===0?new Date:new Date(+a)),a}return i.floor=a=>(n(a=new Date(+a)),a),i.ceil=a=>(n(a=new Date(a-1)),e(a,1),n(a),a),i.round=a=>{const o=i(a),l=i.ceil(a);return a-o<l-a?o:l},i.offset=(a,o)=>(e(a=new Date(+a),o==null?1:Math.floor(o)),a),i.range=(a,o,l)=>{const u=[];if(a=i.ceil(a),l=l==null?1:Math.floor(l),!(a<o)||!(l>0))return u;let c;do u.push(c=new Date(+a)),e(a,l),n(a);while(c<a&&a<o);return u},i.filter=a=>Y(o=>{if(o>=o)for(;n(o),!a(o);)o.setTime(o-1)},(o,l)=>{if(o>=o)if(l<0)for(;++l<=0;)for(;e(o,-1),!a(o););else for(;--l>=0;)for(;e(o,1),!a(o););}),t&&(i.count=(a,o)=>(hn.setTime(+a),dn.setTime(+o),n(hn),n(dn),Math.floor(t(hn,dn))),i.every=a=>(a=Math.floor(a),!isFinite(a)||!(a>0)?null:a>1?i.filter(r?o=>r(o)%a===0:o=>i.count(0,o)%a===0):i)),i}const jt=Y(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);jt.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?Y(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):jt);jt.range;const V=1e3,q=V*60,X=q*60,ee=X*24,xr=ee*7,Jr=ee*30,fn=ee*365,we=Y(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*V)},(n,e)=>(e-n)/V,n=>n.getUTCSeconds());we.range;const wr=Y(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*V)},(n,e)=>{n.setTime(+n+e*q)},(n,e)=>(e-n)/q,n=>n.getMinutes());wr.range;const Jl=Y(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*q)},(n,e)=>(e-n)/q,n=>n.getUTCMinutes());Jl.range;const Er=Y(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*V-n.getMinutes()*q)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getHours());Er.range;const ec=Y(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getUTCHours());ec.range;const ut=Y(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*q)/ee,n=>n.getDate()-1);ut.range;const Cr=Y(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ee,n=>n.getUTCDate()-1);Cr.range;const tc=Y(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ee,n=>Math.floor(n/ee));tc.range;function pe(n){return Y(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*q)/xr)}const on=pe(0),$t=pe(1),nc=pe(2),rc=pe(3),Ie=pe(4),sc=pe(5),ic=pe(6);on.range;$t.range;nc.range;rc.range;Ie.range;sc.range;ic.range;function ge(n){return Y(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/xr)}const _i=ge(0),Bt=ge(1),ac=ge(2),oc=ge(3),ze=ge(4),lc=ge(5),cc=ge(6);_i.range;Bt.range;ac.range;oc.range;ze.range;lc.range;cc.range;const Rr=Y(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());Rr.range;const uc=Y(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());uc.range;const te=Y(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());te.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:Y(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});te.range;const de=Y(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());de.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:Y(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});de.range;function hc(n,e,t,r,i,a){const o=[[we,1,V],[we,5,5*V],[we,15,15*V],[we,30,30*V],[a,1,q],[a,5,5*q],[a,15,15*q],[a,30,30*q],[i,1,X],[i,3,3*X],[i,6,6*X],[i,12,12*X],[r,1,ee],[r,2,2*ee],[t,1,xr],[e,1,Jr],[e,3,3*Jr],[n,1,fn]];function l(c,d,f){const p=d<c;p&&([c,d]=[d,c]);const y=f&&typeof f.range=="function"?f:u(c,d,f),S=y?y.range(c,+d+1):[];return p?S.reverse():S}function u(c,d,f){const p=Math.abs(d-c)/f,y=Sr(([,,T])=>T).right(o,p);if(y===o.length)return n.every(An(c/fn,d/fn,f));if(y===0)return jt.every(Math.max(An(c,d,f),1));const[S,b]=o[p/o[y-1][2]<o[y][2]/p?y-1:y];return S.every(b)}return[l,u]}const[dc,fc]=hc(te,Rr,on,ut,Er,wr);function pn(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 gn(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 Ue(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function pc(n){var e=n.dateTime,t=n.date,r=n.time,i=n.periods,a=n.days,o=n.shortDays,l=n.months,u=n.shortMonths,c=qe(i),d=He(i),f=qe(a),p=He(a),y=qe(o),S=He(o),b=qe(l),T=He(l),C=qe(u),k=He(u),R={a:be,A:Se,b:F,B:Sa,c:null,d:is,e:is,f:zc,g:Qc,G:Gc,H:Dc,I:Yc,j:Ic,L:Mi,m:Nc,M:Zc,p:Ta,q:xa,Q:ls,s:cs,S:jc,u:$c,U:Bc,V:Uc,w:qc,W:Hc,x:null,X:null,y:Fc,Y:Wc,Z:Vc,"%":os},_={a:wa,A:Ea,b:Ca,B:Ra,c:null,d:as,e:as,f:eu,g:uu,G:du,H:Xc,I:Kc,j:Jc,L:Di,m:tu,M:nu,p:La,q:Pa,Q:ls,s:cs,S:ru,u:su,U:iu,V:au,w:ou,W:lu,x:null,X:null,y:cu,Y:hu,Z:fu,"%":os},A={a:ft,A:E,b:G,B:z,c:se,d:rs,e:rs,f:Oc,g:ns,G:ts,H:ss,I:ss,j:Rc,L:kc,m:Cc,M:Lc,p:Be,q:Ec,Q:Mc,s:Ac,S:Pc,u:bc,U:Sc,V:Tc,w:vc,W:xc,x:pt,X:ve,y:ns,Y:ts,Z:wc,"%":_c};R.x=x(t,R),R.X=x(r,R),R.c=x(e,R),_.x=x(t,_),_.X=x(r,_),_.c=x(e,_);function x(v,w){return function(L){var m=[],N=-1,O=0,$=v.length,B,ae,Ar;for(L instanceof Date||(L=new Date(+L));++N<$;)v.charCodeAt(N)===37&&(m.push(v.slice(O,N)),(ae=es[B=v.charAt(++N)])!=null?B=v.charAt(++N):ae=B==="e"?" ":"0",(Ar=w[B])&&(B=Ar(L,ae)),m.push(B),O=N+1);return m.push(v.slice(O,N)),m.join("")}}function D(v,w){return function(L){var m=Ue(1900,void 0,1),N=re(m,v,L+="",0),O,$;if(N!=L.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(w&&!("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?(O=gn(Ue(m.y,0,1)),$=O.getUTCDay(),O=$>4||$===0?Bt.ceil(O):Bt(O),O=Cr.offset(O,(m.V-1)*7),m.y=O.getUTCFullYear(),m.m=O.getUTCMonth(),m.d=O.getUTCDate()+(m.w+6)%7):(O=pn(Ue(m.y,0,1)),$=O.getDay(),O=$>4||$===0?$t.ceil(O):$t(O),O=ut.offset(O,(m.V-1)*7),m.y=O.getFullYear(),m.m=O.getMonth(),m.d=O.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),$="Z"in m?gn(Ue(m.y,0,1)).getUTCDay():pn(Ue(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-($+5)%7:m.w+m.U*7-($+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,gn(m)):pn(m)}}function re(v,w,L,m){for(var N=0,O=w.length,$=L.length,B,ae;N<O;){if(m>=$)return-1;if(B=w.charCodeAt(N++),B===37){if(B=w.charAt(N++),ae=A[B in es?w.charAt(N++):B],!ae||(m=ae(v,L,m))<0)return-1}else if(B!=L.charCodeAt(m++))return-1}return m}function Be(v,w,L){var m=c.exec(w.slice(L));return m?(v.p=d.get(m[0].toLowerCase()),L+m[0].length):-1}function ft(v,w,L){var m=y.exec(w.slice(L));return m?(v.w=S.get(m[0].toLowerCase()),L+m[0].length):-1}function E(v,w,L){var m=f.exec(w.slice(L));return m?(v.w=p.get(m[0].toLowerCase()),L+m[0].length):-1}function G(v,w,L){var m=C.exec(w.slice(L));return m?(v.m=k.get(m[0].toLowerCase()),L+m[0].length):-1}function z(v,w,L){var m=b.exec(w.slice(L));return m?(v.m=T.get(m[0].toLowerCase()),L+m[0].length):-1}function se(v,w,L){return re(v,e,w,L)}function pt(v,w,L){return re(v,t,w,L)}function ve(v,w,L){return re(v,r,w,L)}function be(v){return o[v.getDay()]}function Se(v){return a[v.getDay()]}function F(v){return u[v.getMonth()]}function Sa(v){return l[v.getMonth()]}function Ta(v){return i[+(v.getHours()>=12)]}function xa(v){return 1+~~(v.getMonth()/3)}function wa(v){return o[v.getUTCDay()]}function Ea(v){return a[v.getUTCDay()]}function Ca(v){return u[v.getUTCMonth()]}function Ra(v){return l[v.getUTCMonth()]}function La(v){return i[+(v.getUTCHours()>=12)]}function Pa(v){return 1+~~(v.getUTCMonth()/3)}return{format:function(v){var w=x(v+="",R);return w.toString=function(){return v},w},parse:function(v){var w=D(v+="",!1);return w.toString=function(){return v},w},utcFormat:function(v){var w=x(v+="",_);return w.toString=function(){return v},w},utcParse:function(v){var w=D(v+="",!0);return w.toString=function(){return v},w}}}var es={"-":"",_:" ",0:"0"},I=/^\s*\d+/,gc=/^%/,mc=/[\\^$*+?|[\]().{}]/g;function P(n,e,t){var r=n<0?"-":"",i=(r?-n:n)+"",a=i.length;return r+(a<t?new Array(t-a+1).join(e)+i:i)}function yc(n){return n.replace(mc,"\\$&")}function qe(n){return new RegExp("^(?:"+n.map(yc).join("|")+")","i")}function He(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function vc(n,e,t){var r=I.exec(e.slice(t,t+1));return r?(n.w=+r[0],t+r[0].length):-1}function bc(n,e,t){var r=I.exec(e.slice(t,t+1));return r?(n.u=+r[0],t+r[0].length):-1}function Sc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.U=+r[0],t+r[0].length):-1}function Tc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.V=+r[0],t+r[0].length):-1}function xc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.W=+r[0],t+r[0].length):-1}function ts(n,e,t){var r=I.exec(e.slice(t,t+4));return r?(n.y=+r[0],t+r[0].length):-1}function ns(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.y=+r[0]+(+r[0]>68?1900:2e3),t+r[0].length):-1}function wc(n,e,t){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return r?(n.Z=r[1]?0:-(r[2]+(r[3]||"00")),t+r[0].length):-1}function Ec(n,e,t){var r=I.exec(e.slice(t,t+1));return r?(n.q=r[0]*3-3,t+r[0].length):-1}function Cc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.m=r[0]-1,t+r[0].length):-1}function rs(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.d=+r[0],t+r[0].length):-1}function Rc(n,e,t){var r=I.exec(e.slice(t,t+3));return r?(n.m=0,n.d=+r[0],t+r[0].length):-1}function ss(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.H=+r[0],t+r[0].length):-1}function Lc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.M=+r[0],t+r[0].length):-1}function Pc(n,e,t){var r=I.exec(e.slice(t,t+2));return r?(n.S=+r[0],t+r[0].length):-1}function kc(n,e,t){var r=I.exec(e.slice(t,t+3));return r?(n.L=+r[0],t+r[0].length):-1}function Oc(n,e,t){var r=I.exec(e.slice(t,t+6));return r?(n.L=Math.floor(r[0]/1e3),t+r[0].length):-1}function _c(n,e,t){var r=gc.exec(e.slice(t,t+1));return r?t+r[0].length:-1}function Mc(n,e,t){var r=I.exec(e.slice(t));return r?(n.Q=+r[0],t+r[0].length):-1}function Ac(n,e,t){var r=I.exec(e.slice(t));return r?(n.s=+r[0],t+r[0].length):-1}function is(n,e){return P(n.getDate(),e,2)}function Dc(n,e){return P(n.getHours(),e,2)}function Yc(n,e){return P(n.getHours()%12||12,e,2)}function Ic(n,e){return P(1+ut.count(te(n),n),e,3)}function Mi(n,e){return P(n.getMilliseconds(),e,3)}function zc(n,e){return Mi(n,e)+"000"}function Nc(n,e){return P(n.getMonth()+1,e,2)}function Zc(n,e){return P(n.getMinutes(),e,2)}function jc(n,e){return P(n.getSeconds(),e,2)}function $c(n){var e=n.getDay();return e===0?7:e}function Bc(n,e){return P(on.count(te(n)-1,n),e,2)}function Ai(n){var e=n.getDay();return e>=4||e===0?Ie(n):Ie.ceil(n)}function Uc(n,e){return n=Ai(n),P(Ie.count(te(n),n)+(te(n).getDay()===4),e,2)}function qc(n){return n.getDay()}function Hc(n,e){return P($t.count(te(n)-1,n),e,2)}function Fc(n,e){return P(n.getFullYear()%100,e,2)}function Qc(n,e){return n=Ai(n),P(n.getFullYear()%100,e,2)}function Wc(n,e){return P(n.getFullYear()%1e4,e,4)}function Gc(n,e){var t=n.getDay();return n=t>=4||t===0?Ie(n):Ie.ceil(n),P(n.getFullYear()%1e4,e,4)}function Vc(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+P(e/60|0,"0",2)+P(e%60,"0",2)}function as(n,e){return P(n.getUTCDate(),e,2)}function Xc(n,e){return P(n.getUTCHours(),e,2)}function Kc(n,e){return P(n.getUTCHours()%12||12,e,2)}function Jc(n,e){return P(1+Cr.count(de(n),n),e,3)}function Di(n,e){return P(n.getUTCMilliseconds(),e,3)}function eu(n,e){return Di(n,e)+"000"}function tu(n,e){return P(n.getUTCMonth()+1,e,2)}function nu(n,e){return P(n.getUTCMinutes(),e,2)}function ru(n,e){return P(n.getUTCSeconds(),e,2)}function su(n){var e=n.getUTCDay();return e===0?7:e}function iu(n,e){return P(_i.count(de(n)-1,n),e,2)}function Yi(n){var e=n.getUTCDay();return e>=4||e===0?ze(n):ze.ceil(n)}function au(n,e){return n=Yi(n),P(ze.count(de(n),n)+(de(n).getUTCDay()===4),e,2)}function ou(n){return n.getUTCDay()}function lu(n,e){return P(Bt.count(de(n)-1,n),e,2)}function cu(n,e){return P(n.getUTCFullYear()%100,e,2)}function uu(n,e){return n=Yi(n),P(n.getUTCFullYear()%100,e,2)}function hu(n,e){return P(n.getUTCFullYear()%1e4,e,4)}function du(n,e){var t=n.getUTCDay();return n=t>=4||t===0?ze(n):ze.ceil(n),P(n.getUTCFullYear()%1e4,e,4)}function fu(){return"+0000"}function os(){return"%"}function ls(n){return+n}function cs(n){return Math.floor(+n/1e3)}var Te,Ii;pu({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 pu(n){return Te=pc(n),Ii=Te.format,Te.parse,Te.utcFormat,Te.utcParse,Te}function gu(n){return new Date(n)}function mu(n){return n instanceof Date?+n:+new Date(+n)}function zi(n,e,t,r,i,a,o,l,u,c){var d=Ri(),f=d.invert,p=d.domain,y=c(".%L"),S=c(":%S"),b=c("%I:%M"),T=c("%I %p"),C=c("%a %d"),k=c("%b %d"),R=c("%B"),_=c("%Y");function A(x){return(u(x)<x?y:l(x)<x?S:o(x)<x?b:a(x)<x?T:r(x)<x?i(x)<x?C:k:t(x)<x?R:_)(x)}return d.invert=function(x){return new Date(f(x))},d.domain=function(x){return arguments.length?p(Array.from(x,mu)):p().map(gu)},d.ticks=function(x){var D=p();return n(D[0],D[D.length-1],x??10)},d.tickFormat=function(x,D){return D==null?A:c(D)},d.nice=function(x){var D=p();return(!x||typeof x.range!="function")&&(x=e(D[0],D[D.length-1],x??10)),x?p(Kl(D,x)):d},d.copy=function(){return Ci(d,zi(n,e,t,r,i,a,o,l,u,c))},d}function yu(){return Ei.apply(zi(dc,fc,te,Rr,on,ut,Er,wr,we,Ii).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const us=[s.a$1.NANOSECOND,s.a$1.nanoseconds(2),s.a$1.nanoseconds(5),s.a$1.nanoseconds(10),s.a$1.nanoseconds(20),s.a$1.nanoseconds(50),s.a$1.nanoseconds(100),s.a$1.nanoseconds(200),s.a$1.nanoseconds(500),s.a$1.MICROSECOND,s.a$1.microseconds(2),s.a$1.microseconds(5),s.a$1.microseconds(10),s.a$1.microseconds(20),s.a$1.microseconds(50),s.a$1.microseconds(100),s.a$1.microseconds(200),s.a$1.microseconds(500),s.a$1.MILLISECOND,s.a$1.milliseconds(2),s.a$1.milliseconds(5),s.a$1.milliseconds(10),s.a$1.milliseconds(20),s.a$1.milliseconds(50),s.a$1.milliseconds(100),s.a$1.milliseconds(200),s.a$1.milliseconds(500),s.a$1.SECOND];class vu{_domain;_range;_span;constructor(){this._domain=[new s.r(0n),new s.r(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 s.r(e[0]),new s.r(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 r=new s.r(e).valueOf(),i=this._domain[0].valueOf(),a=this._domain[1].valueOf()-i,o=this._range[1]-this._range[0];return Number(r-i)/Number(a)*o+this._range[0]}ticks(e){const t=this.calculateOptimalStep(e).valueOf(),r=this._domain[0].valueOf(),i=this._domain[1].valueOf(),a=(r+t-1n)/t*t,o=Number((i-a)/t);return Array.from({length:o+1},(l,u)=>{const c=a+BigInt(u)*t;return new s.r(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 r=us[0];for(const i of us){if(i.valueOf()>t)break;r=i}return r}formatTick(e){return this._span.lessThan(s.a$1.microseconds(50))?`${e.remainder(s.a$1.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(s.a$1.SECOND).milliseconds.toString()}ms`}}const bu=()=>new vu,Lr=h.z.enum(["linear","time"]),Pr=h.z.object({tickSpacing:h.z.number().default(75),type:Lr.optional().default("linear")}),Yn=n=>{const e=Pr.parse(n);return xu[e.type](e)};class Su{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=yu(),this.preciseScale=bu(),this.prevScaleSize=0,this.prevDomain=new s.m(new s.r(0),new s.r(0)),this.currTicks=[]}create({decimalToDataScale:e,size:t}){const r=new s.m(new s.r(e.pos(0)),new s.r(e.pos(1)));if(this.prevDomain.equals(r)&&this.prevScaleSize===t)return this.currTicks;if(this.prevDomain=r,this.prevScaleSize!==t){const i=[0,t];this.preciseScale.range(i),this.normalScale.range(i),this.prevScaleSize=t}if(r.span.milliseconds<5){this.preciseScale.domain([r.start,r.end]);const i=In(t,this.props.tickSpacing)/2,a=this.preciseScale.ticks(i);this.currTicks=a.map(o=>({label:this.preciseScale.formatTick(o),position:this.preciseScale.scale(o)}))}else{this.normalScale.domain([r.start.date(),r.end.date()]);const i=this.normalScale.ticks(In(t,this.props.tickSpacing));this.currTicks=i.map(a=>({label:this.normalTickLabel(a),position:this.normalScale(a)}))}return this.currTicks}normalTickLabel(e){let t=`:${e.getSeconds()}`;const r=e.getMilliseconds();if(r!==0){const i=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");t+=`.${i}`}return e.getSeconds()===0&&r===0&&(t=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),t}}class Tu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=s.H.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=Oi()}create({decimalToDataScale:e,size:t}){const r={lower:e.pos(0),upper:e.pos(1)};if(s.H.equals(this.prevDomain,r)&&this.prevScaleSize===t)return this.currTicks;s.H.equals(this.prevDomain,r)||(this.d3Scale=this.d3Scale.domain([r.lower,r.upper])),this.prevScaleSize!==t&&(this.d3Scale=this.d3Scale.range([0,t])),this.prevDomain=r,this.prevScaleSize=t;const i=In(t,this.props.tickSpacing),a=this.d3Scale.ticks(i);return this.currTicks=a.map(o=>({label:this.tickLabel(o),position:this.d3Scale(o)})),this.currTicks}tickLabel(e){return e.toString()}}const In=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},xu={linear:n=>new Tu(n),time:n=>new Su(n)},kr=Pr.extend({color:s.Lr.colorZ,type:Lr.optional().default("linear"),font:h.z.string(),showGrid:h.z.boolean().optional().default(!0),location:s.K.outer,gridColor:s.Lr.colorZ}),H=5,Ke=6,ht={useAtlas:!0},wu={bottom:(n,e)=>new Zi(n,e),top:(n,e)=>new ji(n,e),left:(n,e)=>new Eu(n,e),right:(n,e)=>new $i(n,e)},Ni=(n,e,t)=>wu[n](e,t);class me{renderCtx;state;tickFactory;constructor(e,t){this.renderCtx=e,this.state=t,this.tickFactory=Yn(this.state)}setState(e){this.state=g.prettyParse(kr,e),this.tickFactory=Yn(e)}drawLine(e,t){const{lower2d:r}=this.renderCtx;r.moveTo(...s.Q.couple(e)),r.lineTo(...s.Q.couple(t))}drawTicks(e,t){let r=s._$1.ZERO;return e.forEach(i=>{const a=this.renderCtx.lower2d.textDimensions(i.label,ht);r=s._$1.max([r,a]),t(a,i)}),r}static START_BOUND=s.H.construct(-1,1);maybeDrawGrid(e,t,r){const{showGrid:i,gridColor:a}=this.state;if(i){const o=me.START_BOUND,l=s.H.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=s.Lr.hex(a),t.forEach(c=>{s.H.contains(o,c.position)||s.H.contains(l,c.position)||this.drawLine(...r(c))}),u.stroke()}}setColor(e){const t=s.Lr.hex(e);this.renderCtx.lower2d.strokeStyle=t,this.renderCtx.lower2d.fillStyle=t,this.renderCtx.lower2d.font=this.state.font}}class Zi extends me{render(e){const{lower2d:t}=this.renderCtx,{plot:r,position:i}=e,{width:a,height:o}=s.jt.dims(r),l=this.tickFactory.create({...e,size:a});t.beginPath(),this.setColor(this.state.color),this.drawLine(i,s.Q.translate(i,"x",a));const u=this.drawTicks(l,(c,d)=>{this.drawLine(s.Q.translateX(i,d.position),s.Q.translate(i,{x:d.position,y:H})),t.fillText(d.label,i.x+d.position-c.width/2,i.y+H+c.height+Ke,void 0,ht)});return t.stroke(),this.maybeDrawGrid(a,l,c=>[s.Q.translate(i,"x",c.position),s.Q.translate(i,{x:c.position,y:-o})]),{size:u.height+H+Ke}}}class ji extends me{render(e){const{lower2d:t}=this.renderCtx,{plot:r}=e,{width:i,height:a}=s.jt.dims(r),o=s.Q.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,s.Q.translate(o,"x",i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(s.Q.translateX(o,d.position),s.Q.translate(o,{x:d.position,y:-H})),t.fillText(d.label,o.x+d.position-c.width/2,o.y-H-c.height-Ke,void 0,ht)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[s.Q.translate(o,"x",c.position),s.Q.translate(o,{x:c.position,y:a})]),{size:u.height+H}}}class Eu extends me{render(e){const{lower2d:t}=this.renderCtx,{plot:r,position:i}=e,{height:a,width:o}=s.jt.dims(r),l=s.Q.translate(i,"x",e.size),u=this.tickFactory.create({...e,size:a});t.beginPath(),this.setColor(this.state.color),this.drawLine(l,s.Q.translate(l,"y",a));const c=this.drawTicks(u,(d,f)=>{this.drawLine(s.Q.translateY(l,f.position),s.Q.translate(l,{x:-H,y:f.position})),t.fillText(f.label,l.x-d.width-H*2,l.y+f.position+d.height/2,void 0,ht)});return t.stroke(),this.maybeDrawGrid(a,u,d=>[s.Q.translate(l,"y",d.position),s.Q.translate(l,{x:o,y:d.position})]),{size:c.width+H*2}}}class $i extends me{render(e){const{lower2d:t}=this.renderCtx,{plot:r,position:i}=e,{height:a,width:o}=s.jt.dims(r),l=this.tickFactory.create({...e,size:a});t.beginPath(),this.setColor(this.state.color),this.drawLine(i,s.Q.translateY(i,a));const u=this.drawTicks(l,(c,d)=>{this.drawLine(s.Q.translateY(i,d.position),s.Q.translate(i,{x:H,y:d.position})),t.fillText(d.label,i.x+H+Ke,i.y+d.position+c.height/2,void 0,ht)});return t.stroke(),this.maybeDrawGrid(a,l,c=>[s.Q.translateY(i,c.position),s.Q.translate(i,{x:-o,y:c.position})]),{size:u.width+H+Ke}}}const Bi=h.z.object({key:h.z.string(),size:h.z.number(),order:h.z.number(),loc:s.K.outer});h.z.record(h.z.string(),Bi);const le=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,r)=>r.order-t.order),Cu=(n,e,t)=>{const r=e[n];if(r==null)return s.Q.ZERO;const i=s.K.construct(r.loc),a=le(i,e),o=s.K.construct(s.p.swap(s.K.direction(i))),l=le(o,e),u=a.findIndex(({key:f})=>f===n),c=a.slice(0,u).reduce((f,{size:p})=>f+p,0),d=l.reduce((f,{size:p})=>f+p,0);switch(i){case"left":return s.Q.translate(s.jt.topLeft(t),[c,d]);case"right":return s.Q.translate(s.jt.topRight(t),[c-r.size,d]);case"top":return s.Q.translate(s.jt.topLeft(t),[d,c]);default:return s.Q.translate(s.jt.bottomLeft(t),[d,-c-r.size])}},Ru=(n,e)=>{const t=le("left",n),r=le("right",n),i=le("top",n),a=le("bottom",n),o=t.reduce((d,{size:f})=>d+f,0),l=r.reduce((d,{size:f})=>d+f,0),u=i.reduce((d,{size:f})=>d+f,0),c=a.reduce((d,{size:f})=>d+f,0);return s.jt.construct(s.Q.translate(s.jt.topLeft(e),{x:o,y:u}),s.jt.width(e)-o-l,s.jt.height(e)-u-c)},dt=kr.extend({axisKey:h.z.string().optional(),bounds:s.H.bounds.optional(),autoBounds:h.z.object({lower:h.z.boolean().optional().default(!0),upper:h.z.boolean().optional().default(!0)}).or(h.z.boolean().optional().default(!0)),autoBoundPadding:h.z.number().optional(),autoBoundUpdateInterval:s.a$1.z.optional().default(s.a$1.seconds(10)),size:h.z.number().optional().default(0),label:h.z.string().optional().default(""),labelSize:h.z.number().optional().default(0)}).partial({color:!0,font:!0,gridColor:!0}),Lu=2,Pu=7,Ui=(n,e)=>s.H.contains({lower:n-Pu,upper:n+Lu},e),ku=s.H.DECIMAL,hs=s.r.now(),Ou={lower:Number(hs.valueOf()),upper:Number(hs.add(s.a$1.HOUR).valueOf())},qi=n=>n==="linear"?ku:Ou,_u=(n,e=.1,t)=>{const r=s.H.max(n.filter(s.H.isFinite));if(!s.H.isFinite(r))return qi(t);const{lower:i,upper:a}=r;if(a===i)return{lower:i-1,upper:a+1};const o=(a-i)*e;return{lower:i-o,upper:a+o}},Mu=.01,Au=.1;class Hi extends g.Composite{afterUpdate(e){const{internal:t}=this,{location:r,autoBoundUpdateInterval:i}=this.state;t.render=M.Context.use(e);const a=g.use(e),o=s.p.construct(r);this.state.autoBoundPadding??=o==="x"?Au:Mu,t.core=Ni(r,t.render,{color:a.colors.gray.l10,font:Qe.fontString(a,{level:"small",code:!0}),gridColor:a.colors.gray.l1,...this.state}),J(e,"layout"),t.updateBounds??=Qn.r(l=>this.setState(u=>({...u,bounds:l})),i.milliseconds)}afterDelete(e){J(e,"layout")}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{core:r}=this.internal,{grid:i,container:a}=e,o=Cu(`${this.type}-${this.key}`,i,a),l={...e,position:o,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:u}=r.render(l);Ui(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:r,upper:i}=Fi(this.state.autoBounds);if(!r&&!i&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const a=c=>({upper:i||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:r||this.state.bounds==null?c.lower:this.state.bounds.lower});let o,l=null;try{const c=t();o=_u(c,this.state.autoBoundPadding,this.state.type)}catch(c){o=qi(this.state.type),l=c}const u=a(o);return this.internal.boundSnapshot=u,(this.state.bounds==null||r&&this.state.bounds.lower!==u.lower||i&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,t,r){const[i,a]=this.iBounds(e,t),o=s.p.swap(s.p.construct(this.state.location));return[s.C$1.Scale.scale(i).scale(1).translate(-s.jt.root(r)[o]).magnify(1/s.jt.dim(r,o)),a]}}const Fi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:n?.lower??!0,upper:n?.upper??!0};class ye{canvas;theme;constructor(e,t){this.canvas=e,this.theme=t}rule({direction:e,region:t,position:r,...i}){return e==="x"?this.line({start:s.Q.construct(s.jt.left(t),r),end:s.Q.construct(s.jt.right(t),r),...i}):this.line({start:s.Q.construct(r,s.jt.top(t)),end:s.Q.construct(r,s.jt.bottom(t)),...i})}line({stroke:e,lineWidth:t,lineDash:r,start:i,end:a}){const o=this.canvas;o.strokeStyle=s.Lr.hex(e),o.lineWidth=t,o.setLineDash([r]),o.beginPath(),o.moveTo(...s.Q.couple(i)),o.lineTo(...s.Q.couple(a)),o.stroke()}circle({fill:e,stroke:t,strokeWidth:r,radius:i,position:a,angle:o,lineCap:l}){const u=this.canvas;u.beginPath();const c=o?.lower??0,d=o?.upper??2*Math.PI;if(t!=null&&typeof i=="object"){const{inner:f,outer:p}=i,y=(f+p)/2,S=p-f;u.arc(...s.Q.couple(a),y,c,d,!1),u.strokeStyle=s.Lr.hex(t),u.lineWidth=r??S,l&&(u.lineCap=l),u.stroke()}else if(e!=null)if(u.fillStyle=s.Lr.hex(e),typeof i=="number")u.arc(...s.Q.couple(a),i,c,d),u.fill();else{const{inner:f,outer:p}=i;u.arc(...s.Q.couple(a),p,c,d,!1);const y=a.x+f*Math.cos(d),S=a.y+f*Math.sin(d);u.lineTo(y,S),u.arc(...s.Q.couple(a),f,d,c,!0),u.closePath(),u.fill()}}resolveColor(e,t){return e==null?t==null?this.theme.colors.text:this.resolveColor(t):typeof e=="function"?e(this.theme):s.Lr.construct(e)}border({region:e,color:t,width:r,radius:i,location:a}){const o=this.canvas;o.strokeStyle=s.Lr.hex(this.resolveColor(t,this.theme.colors.border)),o.lineWidth=r??this.theme.sizes.border.width,i??=this.theme.sizes.border.radius,a==null||a===!0?i>0?(o.roundRect(...s.Q.couple(s.jt.topLeft(e)),...s.Q.couple(s.jt.dims(e)),i),o.stroke()):(o.rect(...s.Q.couple(s.jt.topLeft(e)),...s.Q.couple(s.jt.dims(e))),o.stroke()):s.a.toArray(a).forEach(l=>{const[u,c]=s.jt.edgePoints(e,l);o.beginPath(),o.moveTo(...s.Q.couple(u)),o.lineTo(...s.Q.couple(c)),o.stroke()})}container({region:e,bordered:t=!0,rounded:r=!0,borderColor:i,borderRadius:a,borderWidth:o,backgroundColor:l}){a??=this.theme.sizes.border.radius,o??=1;const u=this.canvas;u.fillStyle=s.Lr.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=s.Lr.hex(this.resolveColor(i,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),r?u.roundRect(...s.Q.couple(s.jt.topLeft(e)),...s.Q.couple(s.jt.dims(e)),a):u.rect(...s.Q.couple(s.jt.topLeft(e)),...s.Q.couple(s.jt.dims(e))),u.fill(),t&&this.border({region:e,color:i,radius:a,width:o,location:t})}textContainer(e){const[t,r]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:i=s.K.TOP_LEFT,offset:a=s.Q.ZERO}=e,o={...e.position};i.x==="right"?o.x-=t.width+a.x:o.x+=a.x,i.y==="bottom"?o.y-=t.height+a.y:o.y+=a.y,this.container({region:s.jt.construct(o,t.width,t.height),...e}),this.canvas.filter="none",r(s.Q.translate(o,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:r=1,level:i="p"}){const a=Qe.fontString(this.theme,{level:i}),o=e.map(c=>Dr.dimensions(c,a,this.canvas)),l=this.theme.sizes.base*r,u=Math.max(...o.map(c=>c[s.p.dimension(t)]))+l;return[{[s.p.dimension(s.p.swap(t))]:Math.max(...o.map(c=>c[s.p.dimension(s.p.swap(t))])),[s.p.dimension(t)]:u*e.length-l},c=>{const d=Qe.fontString(this.theme,{level:i});this.canvas.font=d,this.canvas.fillStyle=s.Lr.hex(this.theme.colors.text),this.canvas.textBaseline="top",e.forEach((f,p)=>{this.canvas.fillText(f,c.x,c.y+u*p)})}]}list({length:e,itemHeight:t,width:r,spacing:i=0,position:a,draw:o,root:l=s.K.TOP_LEFT,offset:u=s.Q.ZERO,padding:c=s.Q.ZERO}){const d=e*t+c.y*2+i*(e-1),f=r+c.x*2,p={...a};l.x==="right"?p.x-=r+u.x*2:p.x+=u.x,l.y==="top"?p.y-=d+u.y*2:p.y+=u.y,this.container({region:s.jt.construct(p,{width:f,height:d}),backgroundColor:y=>y.colors.gray.l1});for(let y=0;y<e;y++){const S=s.jt.construct(s.Q.construct(p.x+c.x,p.y+y*t+c.y+i*y),r,t);o(y,S)}}drawTextInCenter({box:e,text:t,level:r}){const i=Dr.dimensions(t,this.canvas.font,this.canvas),a=s.jt.positionInCenter(s.jt.construct(s.Q.ZERO,i),e);return this.text({text:t,position:s.jt.topLeft(a),level:r})}text({text:e,position:t,level:r="p",weight:i,shade:a,maxWidth:o,code:l,justify:u="left",align:c="top",useAtlas:d,color:f}){this.canvas.font=Qe.fontString(this.theme,{level:r,weight:i,code:l}),f!=null?this.canvas.fillStyle=s.Lr.hex(this.resolveColor(f)):a==null?this.canvas.fillStyle=s.Lr.hex(this.theme.colors.text):this.canvas.fillStyle=s.Lr.hex(this.theme.colors.gray[`l${a}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let p;o!=null&&(p=this.canvas.scissor(s.jt.construct(t,o,1e3))),this.canvas.fillText(e,t.x,t.y,void 0,{useAtlas:d}),p?.()}}const Or=h.z.object({position:h.z.number().optional(),pixelPosition:h.z.number().optional(),dragging:h.z.boolean(),lineWidth:h.z.number().optional().default(1),lineDash:h.z.number().optional().default(20),color:s.Lr.colorZ}),Du=3;class Je extends g.Leaf{static TYPE="Rule";schema=Or;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=M.Context.use(e);const t=g.use(e);this.internal.draw=new ye(this.internal.renderCtx.upper2d,t),J(e,"tool")}afterDelete(e){J(e,"tool")}updatePositions({decimalToDataScale:e,plot:t}){const r=this.state.dragging,i=this.prevState.dragging&&!r;if((r||i)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<Du&&!i)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/s.jt.height(t));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const o=e.pos(.5);this.setState(l=>({...l,position:o}))}const a=e.reverse().pos(this.state.position)*s.jt.height(t);if(!isNaN(a)){if(this.state.pixelPosition!=null&&Math.abs(a-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(o=>({...o,pixelPosition:a}))}return a}render(e){if(this.deleted)return;const{renderCtx:t}=this.internal,{location:r,plot:i}=e,a=s.K.direction(r),{upper2d:o}=t,l=this.internal.draw,u=this.updatePositions(e)+s.jt.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:u}),o.fillStyle=s.Lr.hex(this.state.color),o.lineJoin="round",o.lineWidth=3.5,o.lineCap="round",o.beginPath();const c=4;if(r==="left"){const d=s.jt.left(i)-1;o.moveTo(d,u),o.lineTo(d-c,u-c),o.lineTo(d-c,u+c)}else r==="right"&&(o.moveTo(s.jt.right(i),u),o.lineTo(s.jt.right(i)+c,u-c),o.lineTo(s.jt.right(i)+c,u+c));o.closePath(),o.stroke()}}const Qi={[Je.TYPE]:Je},Yu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Qi,Rule:Je,ruleStateZ:Or},Symbol.toStringTag,{value:"Module"})),Iu=dt.extend({location:s.K.x.optional().default("left")}),ds=2,zu=n=>s.jt.signedWidth(n)<ds||s.jt.signedHeight(n)<ds;class Ut extends Hi{static TYPE="YAxis";schema=dt;xBounds(){return s.H.max(this.lines.map(e=>e.xBounds()).filter(e=>s.H.isFinite(e)))}bounds(e){const[t,r]=this.iBounds(e,this.dataBounds.bind(this));if(r!=null)throw r;return t}render(e){if(this.deleted)return;const[t,r]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),i=t.invert().reverse();if(this.renderAxis(e,i),this.renderLines(e,t),this.renderRules(e,i),r!=null)throw r}renderLines({xDataToDecimalScale:e,plot:t,canvases:r,exposure:i},a){if(!r.includes("gl")||zu(t))return;const o={region:t,dataToDecimalScale:new s.C$1.XY(e,a),exposure:i};this.lines.forEach(l=>l.render(o))}renderRules({container:e,plot:t,canvases:r},i){if(!r.includes("upper2d"))return;const{location:a}=this.state,{render:o}=this.internal,l=s.jt.construct(s.jt.left(e),s.jt.top(t),s.jt.width(e),s.jt.height(t)),u=o.scissor(l,s.Q.ZERO,["upper2d"]),c={container:e,plot:t,decimalToDataScale:i,location:a};this.rules.map(d=>d.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:t,viewport:r,hold:i,exposure:a},o){const[l,u]=this.dataToDecimalScale(i,this.dataBounds.bind(this),r);if(u!=null)throw u;const c=new s.C$1.XY(e,l),d={region:t,dataToDecimalScale:c,exposure:a};return this.lines.map(f=>({...f.findByXValue(d,o),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType(Dt.TYPE)}get rules(){return this.childrenOfType(Je.TYPE)}}const Nu=h.z.object({start:s.r.z,end:s.r.z});class fs extends g.Leaf{static TYPE="range-annotation";schema=Nu;afterUpdate(e){this.internal.render=M.Context.use(e),this.internal.draw=new ye(this.internal.render.upper2d,g.use(e))}}const Zu=g.nA.payloadZ.extend({viewport:s.H.bounds}),Wi=h.z.object({cursor:s.Q.xy.or(h.z.null()),hovered:Zu.or(h.z.null()),count:h.z.number()});class qt extends g.Leaf{static TYPE="range-provider";schema=Wi;fetchedInitial=s.m.ZERO;afterUpdate(e){const{internal:t}=this;t.render=M.Context.use(e),t.draw=new ye(t.render.upper2d,g.use(e)),t.requestRender=an(e),t.runAsync=g.useErrorHandler(e),t.ranges??=new Map;const r=$e(e);if(t.requestRender("tool"),r==null)return;t.client=r;const i=dl(e,this.key);t.removeListener?.();const a=i.ranges.onSet(l=>{t.client!=null&&(s.Lr.isCrude(l.color)&&t.ranges.set(l.key,t.client.ranges.sugarOne(l)),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool"))}),o=i.ranges.onDelete(async l=>{t.ranges.delete(l),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool")});t.removeListener=()=>{a(),o()}}fetchInitial(e){const{internal:t}=this,{client:r,runAsync:i}=t;r==null||this.fetchedInitial.equals(e,s.a$1.minutes(1))||(this.fetchedInitial=e,i(async()=>{(await r.ranges.retrieve(e)).forEach(o=>{s.Lr.isCrude(o.color)&&t.ranges.set(o.key,o)}),this.setState(o=>({...o,count:t.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:t,region:r,viewport:i,timeRange:a}=e;this.fetchInitial(a);const{draw:o,ranges:l}=this.internal,u=t.scale(s.jt.xBounds(r)),c=this.state.cursor==null?null:this.state.cursor.x;let d=null;const f=o.canvas.scissor(s.jt.construct({x:s.jt.left(r),y:s.jt.top(r)-35},{x:s.jt.right(r),y:s.jt.bottom(r)}));l.forEach(p=>{const y=s.Lr.colorZ.safeParse(p.color);if(!y.success)return;const S=y.data;let b=u.pos(Number(p.timeRange.start.valueOf()));const T=u.pos(Number(p.timeRange.end.valueOf()));if(T<s.jt.left(r)||b>s.jt.right(r))return;b=s.R(b,s.jt.left(r)-2,s.jt.right(r)-1);let C=!1;c!=null&&(C=s.H.contains({lower:b,upper:T},c)),C&&(d={key:p.key,parent:p.parent,name:p.name,color:p.color,labels:p.labels,timeRange:p.timeRange,viewport:{lower:t.scale(s.jt.xBounds(i)).pos(Number(p.timeRange.start.valueOf())),upper:t.scale(s.jt.xBounds(i)).pos(Number(p.timeRange.end.valueOf()))}}),o.container({region:s.jt.construct({x:b,y:s.jt.top(r)-1},{x:T,y:s.jt.bottom(r)-1}),backgroundColor:s.Lr.setAlpha(S,.2),bordered:!1});const k=s.jt.construct({x:b+1,y:s.jt.top(r)-34},{x:T-1,y:s.jt.top(r)-12});o.container({region:k,backgroundColor:s.jt.width(k)<20?s.Lr.setAlpha(S,.4):R=>C?R.colors.gray.l2:R.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:s.Lr.setAlpha(S,.8)}),o.text({text:p.name,position:{x:b+8,y:s.jt.top(r)-30},level:"small",shade:10,weight:500,maxWidth:T-b-16})}),f(),d!=null?this.setState(p=>({...p,hovered:d})):this.state.hovered&&this.setState(p=>({...p,hovered:null}))}}const ju={[fs.TYPE]:fs,[qt.TYPE]:qt},$u=dt;class Ht extends Hi{static TYPE="XAxis";schema=dt;render(e){if(this.deleted)return;const[t,r]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,t.reverse()),this.renderYAxes(e,t),this.renderRanges(e,t),r!=null)throw r}findByXDecimal(e,t){const[r,i]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(i!=null)throw i;return this.findByXValue(e,r.reverse().pos(t))}findByXValue(e,t){const[r,i]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(i!=null)throw i;const a={...e,xDataToDecimalScale:r};return this.yAxes.map(o=>o.findByXValue(a,t)).flat()}renderYAxes(e,t){const r={...e,xDataToDecimalScale:t};this.yAxes.forEach(i=>i.render(r))}get yAxes(){return this.childrenOfType(Ut.TYPE)}get ranges(){return this.childrenOfType(qt.TYPE)}bounds(e){const[t,r]=this.iBounds(e,this.dataBounds.bind(this));if(r!=null)throw r;return t}renderRanges(e,t){const r=this.bounds(e.hold),i=s.H.min([r,s.m.MAX.numericBounds]),a=new s.m(i.lower,i.upper);this.ranges.forEach(o=>o.render({dataToDecimalScale:t,region:e.plot,viewport:e.viewport,timeRange:a}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const Bu=s.Q.construct(12),Uu=3,qu=14,Hu=s.Q.construct(6),_r=h.z.object({position:s.Q.xy.or(h.z.null()),textColor:s.Lr.colorZ.optional().default(s.Lr.ZERO),backgroundColor:s.Lr.colorZ.optional().default(s.Lr.ZERO),borderColor:s.Lr.colorZ.optional().default(s.Lr.ZERO),ruleColor:s.Lr.colorZ.optional().default(s.Lr.ZERO),ruleStrokeWidth:h.z.number().optional().default(1),ruleStrokeDash:h.z.number().default(0)});class et extends g.Leaf{static TYPE="tooltip";schema=_r;afterUpdate(e){const t=g.use(e);s.Lr.isZero(this.state.textColor)&&(this.state.textColor=t.colors.text),s.Lr.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=t.colors.gray.l1),s.Lr.isZero(this.state.borderColor)&&(this.state.borderColor=t.colors.border),s.Lr.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=M.Context.use(e),this.internal.draw=new ye(this.internal.render.upper2d,t),J(e,"tool")}afterDelete(e){J(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:t}=e,r=s.C$1.XY.scale(s.jt.DECIMAL).scale(t),i=s.C$1.XY.scale(t).scale(s.jt.DECIMAL),a=e.findByXDecimal(i.x.pos(this.state.position.x)),o=a.filter(b=>s.Q.isFinite(b.value)),{draw:l}=this.internal,u=o.reduce((b,T)=>b+T.position.x,0)/o.length,c=new s.r(o.reduce((b,T)=>b+T.value.x,0)/o.length),d=r.x.pos(u);if(!s.H.contains(s.jt.xBounds(t),d))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:t,position:d}),o.forEach(b=>{const T=r.pos(b.position);l.circle({fill:s.Lr.setAlpha(b.color,.5),radius:8,position:T}),l.circle({fill:s.Lr.setAlpha(b.color,.8),radius:5,position:T}),l.circle({fill:s.Lr.pickByContrast(b.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:T})});const f=i.pos(this.state.position),p={...s.K.TOP_LEFT};f.x>.6&&(p.x="right"),f.y>.6&&(p.y="bottom");let y=a.reduce((b,T)=>Math.max(b,T.label?.length??0),0);const S=c.toString("preciseDate","local").length;S>y&&(y=S),l.list({root:p,offset:Bu,length:o.length+1,padding:Hu,itemHeight:qu,spacing:Uu,width:y*7+48,position:this.state.position,draw:(b,T)=>{let C="",k="",R=this.state.textColor;if(b===0)C="Time",k=c.toString("preciseDate","local");else{const _=o[b-1];C=_.label??"",k=s.Rr.roundBySpan(_.value.y,_.bounds).toString(),R=_.color}l.text({position:s.jt.topLeft(T),text:C,level:"small",weight:500,color:R}),l.text({position:s.Q.translateY(s.jt.topRight(T),-1),text:k,level:"small",justify:"right",code:!0,shade:10})}})}}const Gi={[et.TYPE]:et},Fu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Gi,Tooltip:et,tooltipStateZ:_r},Symbol.toStringTag,{value:"Module"})),Mr=h.z.object({one:s.Q.xy.nullable(),two:s.Q.xy.nullable(),hover:s.Q.xy.nullable(),color:h.z.union([s.Lr.colorZ,h.z.object({verticalLine:s.Lr.colorZ.optional().default(s.Lr.ZERO),horizontalLine:s.Lr.colorZ.optional().default(s.Lr.ZERO),obliqueLine:s.Lr.colorZ.optional().default(s.Lr.ZERO)})]).optional().default(s.Lr.ZERO),strokeWidth:h.z.number().optional().default(1),strokeDash:h.z.number().optional().default(2)});class tt extends g.Leaf{static TYPE="measure";schema=Mr;afterUpdate(e){const t=M.Context.use(e);this.internal.theme=g.use(e),this.internal.renderCtx=t,this.internal.draw=new ye(t.upper2d,this.internal.theme),J(e,"tool")}afterDelete(e){J(e,"layout")}get verticalLineColor(){return s.Lr.isColor(this.state.color)?s.Lr.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.Lr.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return s.Lr.isColor(this.state.color)?s.Lr.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.Lr.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return s.Lr.isColor(this.state.color)?s.Lr.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.Lr.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}find(e){const{one:t,two:r}=this.state;if(t==null||r==null)return null;const{one:i,two:a}=this.prevState,{dataOne:o,dataTwo:l}=this.internal;if(i!=null&&s.Q.equals(t,i)&&a!=null&&s.Q.equals(r,a)&&o!=null&&l!=null){const[b,T]=[e.findByXValue(o.x),e.findByXValue(l.x)];return b.length===0||T.length===0?null:[b.sort((C,k)=>s.Q.distance(o,C.value)-s.Q.distance(o,k.value))[0],T.sort((C,k)=>s.Q.distance(l,C.value)-s.Q.distance(l,k.value))[0]]}const u=s.C$1.XY.scale(e.region).scale(s.jt.DECIMAL),[c,d]=[u.pos(t),u.pos(r)],[f,p]=[e.findByXDecimal(c.x),e.findByXDecimal(d.x)];if(f.length===0||p.length===0)return null;const[y,S]=[f.sort((b,T)=>s.Q.distance(c,b.position)-s.Q.distance(c,T.position))[0],p.sort((b,T)=>s.Q.distance(d,b.position)-s.Q.distance(d,T.position))[0]];return this.internal.dataOne=y.value,this.internal.dataTwo=S.value,[y,S]}renderHover(e){if(this.state.hover==null)return;const t=this.state.hover,r=s.C$1.XY.scale(e.region).scale(s.jt.DECIMAL),i=r.pos(t),a=e.findByXDecimal(r.pos(t).x);if(a.length===0)return;const o=a.sort((u,c)=>s.Q.distance(i,u.position)-s.Q.distance(i,c.position))[0],{draw:l}=this.internal;l.circle({fill:s.Lr.setAlpha(o.color,.5),radius:9,position:r.reverse().pos(o.position)})}render(e){if(this.deleted)return;this.renderHover(e);const t=this.find(e);if(t==null)return;const[r,i]=t,{draw:a}=this.internal,{strokeDash:o,strokeWidth:l}=this.state,u=s.C$1.XY.scale(s.jt.DECIMAL).scale(e.region),c=u.pos(r.position),d=u.pos(i.position),f=new s.a$1(Math.abs(r.value.x-i.value.x)),p=Math.abs(r.value.y-i.value.y),y=p/f.seconds;a.line({start:s.Q.construct(c.x,c.y),end:s.Q.construct(c.x,d.y),stroke:this.verticalLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[`${p.toFixed(2)} ${r.units??""}`],direction:"x",position:s.Q.construct(c.x,(c.y+d.y)/2),level:"small"}),a.line({start:s.Q.construct(c.x,d.y),end:s.Q.construct(d.x,d.y),stroke:this.horizontalLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[f.truncate(s.a$1.MILLISECOND).toString()],direction:"x",position:s.Q.construct((c.x+d.x)/2,d.y),level:"small"}),a.line({start:s.Q.construct(c.x,c.y),end:s.Q.construct(d.x,d.y),stroke:this.obliqueLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[`${y.toFixed(2)} ${r.units??""} / S`],direction:"x",position:s.Q.construct((c.x+d.x)/2,(c.y+d.y)/2),level:"small"}),a.circle({fill:s.Lr.setAlpha(r.color,.5),radius:8,position:c}),a.circle({fill:s.Lr.setAlpha(r.color,.8),radius:5,position:c}),a.circle({fill:s.Lr.WHITE,radius:2,position:c}),a.circle({fill:s.Lr.setAlpha(i.color,.5),radius:8,position:d}),a.circle({fill:s.Lr.setAlpha(i.color,.8),radius:5,position:d}),a.circle({fill:s.Lr.WHITE,radius:2,position:d})}}const Vi={[tt.TYPE]:tt},Qu=Object.freeze(Object.defineProperty({__proto__:null,Measure:tt,REGISTRY:Vi,measureStateZ:Mr},Symbol.toStringTag,{value:"Module"})),Xi=h.z.object({container:s.jt.box,viewport:s.jt.box,hold:h.z.boolean().optional().default(!1),grid:h.z.record(h.z.string(),Bi),visible:h.z.boolean().optional().default(!0),clearOverScan:s.Q.crudeZ.optional().default(s.Q.ZERO)}),Wu=(n,e)=>{const t=s.jt.width(n)*Math.sqrt(s.jt.height(n)),r=s.jt.width(e)*Math.sqrt(s.jt.height(e));return t/r},Gu=["upper2d","lower2d","gl"],Vu=["upper2d"];class zn extends g.Composite{static TYPE="LinePlot";schema=Xi;afterUpdate(e){this.internal.instrumentation=M.useInstrumentation(e,"lineplot"),this.internal.handleError=g.useErrorHandler(e),this.internal.renderCtx=M.Context.use(e),sn(e,t=>{this.state.visible&&this.requestRender("low",t)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=M.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(r=>r.findByXDecimal(t,e)).flat()}findByXValue(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(r=>r.findByXValue(t,e)).flat()}get axes(){return this.childrenOfType(Ht.TYPE)}get tooltips(){return this.childrenOfType(et.TYPE)}get measures(){return this.childrenOfType(tt.TYPE)}get bounds(){return this.childrenOfType(It.TYPE)}get exposure(){return Wu(this.state.viewport,this.state.container)}renderAxes(e,t){const r={...this.state,plot:e,canvases:t,exposure:this.exposure};this.axes.forEach(i=>i.render(r))}renderTooltips(e,t){const r={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:t};this.tooltips.forEach(i=>i.render(r))}renderBounds(){this.bounds.forEach(e=>e.render({getBounds:()=>{const t={};return this.axes.forEach(r=>{const i=r.state.axisKey??r.key;t[i]=r.bounds(this.state.hold),r.yAxes.forEach(a=>{const o=a.state.axisKey??a.key;t[o]=a.bounds(this.state.hold)})}),t}}))}renderMeasures(e){const t={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(r=>r.render(t))}calculatePlot(){return Ru(this.state.grid,this.state.container)}render(e){const{instrumentation:t,renderCtx:r,handleError:i}=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})=>r.erase(this.state.container,this.state.clearOverScan,...d);const a=this.calculatePlot();t.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:a,canvases:e});const o=s.Q.construct(this.state.clearOverScan),l=r.scissor(this.state.container,o,e.filter(d=>d!=="gl")),u=r.scissor(a,s.Q.ZERO,e.filter(d=>d==="gl"));try{this.renderAxes(a,e),this.renderTooltips(a,e),this.renderMeasures(a),this.renderBounds()}catch(d){i(d,"failed to render line plot")}finally{l(),u()}t.L.debug("rendered",{key:this.key});const c=s.jt.copy(this.state.container);return({canvases:d})=>r.erase(c,this.state.clearOverScan,...d)}requestRender(e,t){const{renderCtx:r}=this.internal;let i=Gu;t==="tool"&&(i=Vu),r.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(i),priority:e,canvases:i})}}const Xu={[zn.TYPE]:zn,[Ht.TYPE]:Ht,[Ut.TYPE]:Ut,[It.TYPE]:It},Ki=h.z.object({region:s.jt.box,wheelPos:h.z.number(),scrolling:h.z.boolean(),empty:h.z.boolean(),visible:h.z.boolean(),telem:xt.optional().default(ws),font:ce.levelZ.optional().default("p"),color:s.Lr.colorZ.optional().default(s.Lr.ZERO),overshoot:s.Q.xy.optional().default({x:0,y:0})}),Ku=.98,Fe="lower2d",Ju={offset:0n,offsetRef:0n,scrollRef:0};class nt extends g.Leaf{static TYPE="log";static z=Ki;schema=nt.z;values=new s.Oe([]);scrollState=Ju;afterUpdate(e){const{internal:t}=this;t.render=M.Context.use(e),t.theme=g.use(e),s.Lr.isZero(this.state.color)?this.internal.textColor=t.theme.colors.gray.l11:t.textColor=this.state.color,t.telem=j(e,this.state.telem,t.telem);const{scrolling:r,wheelPos:i}=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(r){const{scrollState:u,values:c}=this,d=Math.ceil((i-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[o,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(s.jt.construct(this.state.region),s.Q.ZERO,Fe)}requestRender(){const{render:e}=this.internal;e.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(),priority:"high",canvases:[Fe]})}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((s.jt.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,t=this.state.region;if(s.jt.areaIsZero(t))return;if(!this.state.visible)return()=>e.erase(t,s.Q.ZERO,Fe);let r;if(!this.state.scrolling)r=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));r=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const i=this.state.region,a=e[Fe],o=new ye(a,this.internal.theme),l=e.scissor(i,s.Q.ZERO,[Fe]);this.renderElements(o,r),this.renderScrollbar(o),l();const u=s.jt.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const t=this.state.region,r=s.jt.height(t)/this.totalHeight*s.jt.height(t);if(r>=s.jt.height(t)*Ku)return;let i=s.jt.bottom(t)-r;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*s.jt.height(t)),i<0&&(i=s.jt.top(t)),e.container({region:s.jt.construct({x:s.jt.right(t)-6,y:i},{width:6,height:r}),bordered:!1,backgroundColor:a=>a.colors.gray.l6})}renderElements(e,t){const r=this.state.region;let i=0;for(const a of t){const o=this.values.dataType.equals(s.n.JSON)?JSON.stringify(a):a.toString();e.text({text:o,level:this.state.font,shade:11,position:s.Q.translate(s.jt.topLeft(r),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}}const eh={[nt.TYPE]:nt},th="ranges",nh={channel:g.nA.SET_CHANNEL_NAME,schema:g.nA.payloadZ,onChange:async({store:n,changed:e,client:t})=>{const r=t.ranges.sugarOne(e),i=n.ranges.get(e.key);let a;i?.labels==null&&(a=await r.retrieveLabels());let o=null;i?.parent==null&&(o=await r.retrieveParent()),n.ranges.set(e.key,l=>t.ranges.sugarOne({...r.payload,labels:l?.labels??a,parent:l?.parent??o}))}},rh={channel:g.nA.DELETE_CHANNEL_NAME,schema:g.nA.keyZ,onChange:({store:n,changed:e})=>n.ranges.delete(e)},sh={equal:(n,e)=>K.T.equal(n.payload,e.payload),listeners:[nh,rh]},Ji=h.z.object({authority:s.Ur.authorityZ.optional(),valid:h.z.boolean().optional()}).default({authority:void 0,valid:!1}),ea=h.z.object({triggered:h.z.boolean(),status:s.Yr.statusZ(Ji),sink:Kt.optional().default(Xt),source:er.optional().default(Kn)});class Nn extends g.Leaf{static TYPE="Chip";schema=ea;afterUpdate(e){const{internal:t}=this,{sink:r,source:i}=this.state;t.source=j(e,i,t.source),t.sink=je(e,r,t.sink),this.state.triggered&&!this.prevState.triggered&&t.sink.set(this.state.status.details?.authority!==s.Ur.ABSOLUTE_AUTHORITY),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();K.T.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 ta=h.z.object({}),ps="control-state-provider",na=g.VI.stateZ.extend({subjectColor:s.Lr.colorZ});class rt extends g.Composite{static TYPE="StateProvider";schema=ta;colors=new Map;tracker;disconnectTrackerChange;obs=new Gt.Observer;static use(e){return e.get(ps)}afterUpdate(e){const{internal:t}=this;t.instrumentation=M.useInstrumentation(e,"control-state");const r=g.use(e);t.palette=r.colors.visualization.palettes.default,t.defaultColor=r.colors.gray.l8;const i=$e(e);if(t.client!=null&&i===t.client)return;t.client=i,e.set(ps,this),g.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){g.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}get(e){return Array.isArray(e)?s.c.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.colors.get(t.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:t}=this,{instrumentation:r}=t;try{this.tracker=await e.control.openStateTracker()}catch{r.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(i=>{if(r.L.debug("transfer",{transfers:i.map(a=>g.VI.transferString(a))}),this.tracker==null)throw new g.Bt("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(i)})}updateColors(e){const t=e.subjects(),r=t.map(o=>o.key),i=Array.from(this.colors.values());this.colors.forEach((o,l)=>!r.includes(l)&&this.colors.delete(l));const{palette:a}=this.internal;t.forEach(o=>{if(this.colors.has(o.key))return;const l=a.find(u=>!i.includes(u))??a[0];this.colors.set(o.key,l),i.push(l)})}}const ra=h.z.enum(["acquired","released","overridden","failed"]),sa=h.z.object({name:h.z.string(),authority:h.z.number().default(0),acquireTrigger:h.z.number(),status:ra.optional(),needsControlOf:g.DI.keyZ.array().optional().default([])});class Zn extends g.Composite{static TYPE="Controller";schema=sa;registry=new Map;writer;afterUpdate(e){const{internal:t}=this;t.instrumentation=M.useInstrumentation(e),t.addStatus=g.useAdder(e),t.runAsync=g.useErrorHandler(e),(t.prevTrigger==null||Math.abs(this.state.acquireTrigger-t.prevTrigger)>1)&&(t.prevTrigger=this.state.acquireTrigger);const r=$e(e),i=rt.use(e);t.stateProv=i,t.telemCtx=ai(e,this,t.telemCtx),t.client=r,t.runAsync(async()=>{t.client==null&&await this.release(),this.state.acquireTrigger>t.prevTrigger?await this.acquire():this.state.acquireTrigger<t.prevTrigger&&await this.release()},"failed to acquire control")}afterDelete(){const{internal:e}=this;e.runAsync(async()=>await this.release(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const t=new Set([]);for(const i of this.registry.keys())(await i.needsControlOf(e)).forEach(o=>o!==0&&t.add(o));const r=Array.from(t);K.q.unorderedPrimitiveArrays(this.state.needsControlOf,r)!==K.q.EQUAL&&this.setState(i=>({...i,needsControlOf:r}))}async acquire(){this.internal.prevTrigger=this.state.acquireTrigger;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 r=this.state.needsControlOf;if(r.length===0)return t({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const i=g.y.now().sub(s.a$1.milliseconds(1));this.writer=await e.openWriter({start:i,channels:r,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(a=>({...a,status:"acquired"}))}catch(r){if(this.setState(i=>({...i,status:"failed"})),!(r instanceof Error))throw r;t({variant:"error",message:`${this.state.name} failed to acquire control`,description:r.message})}}async release(){this.internal.prevTrigger=this.state.acquireTrigger;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.acquire(),await this.writer?.write(e)}async setAuthority(e,t){this.writer==null&&await this.acquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(r=>[r,t])))}async releaseAuthority(e){this.writer==null&&await this.acquire(),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,i=(()=>{switch(e.type){case Ft.TYPE:{const a=new Ft(this,t.runAsync,e.props);return this.registry.set(a,null),a}case Wt.TYPE:{const a=new Wt(this,this.internal.stateProv,e.props);return this.registry.set(a,null),a}case Qt.TYPE:return new Qt(this,t.runAsync,e.props);default:return null}})();return i!=null&&this.updateNeedsControlOf(),i}}const ia=h.z.object({channel:h.z.number()});class Ft extends nn{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=ia;constructor(e,t,r){super(r),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),r=[t.key];return t.index!==0&&r.push(t.index),r}set(...e){this.runAsync(async()=>{const{client:t}=this.controller.internal;if(t==null)throw new g.EI("No Core connected");if(this.props.channel===0)throw new g.W("No command channel specified for actuator");const r=await t.channels.retrieve(this.props.channel),i={[r.key]:e};if(r.index!==0){const a=await t.channels.retrieve(r.index),o=g.y.now();i[a.key]=Array.from({length:e.length},(l,u)=>o.add(s.a$1.nanoseconds(u)))}await this.controller.set(i)},"Failed to command channel")}}const ih=n=>({type:Ft.TYPE,props:n,variant:"sink",valueType:"number"}),aa=h.z.object({authority:h.z.number().default(g.VI.ABSOLUTE_AUTHORITY),channel:h.z.number()});class Qt extends nn{static TYPE="acquire-channel-control";controller;runAsync;schema=aa;constructor(e,t,r){super(r),this.controller=e,this.runAsync=t}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const t=await e.channels.retrieve(this.props.channel),r=[t.key];return t.index!==0&&r.push(t.index),r}set(e){this.runAsync(async()=>{const{controller:t}=this,{client:r}=t.internal;if(r==null)return;const i=await r.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),e?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)},"failed to set channel authority")}}const ah=n=>({type:Qt.TYPE,props:n,variant:"sink",valueType:"boolean"}),oa=h.z.object({channel:h.z.number()}),oh=h.z.object({valid:h.z.boolean(),color:s.Lr.colorZ.optional(),authority:h.z.number()});class Wt extends U{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=oa;constructor(e,t,r){super(r),this.prov=t,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const t=s.Ur.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(r=>{t(r).length!==0&&this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=g.y.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 lh=n=>({type:Wt.TYPE,props:n,variant:"source",valueType:"status"}),la=h.z.object({color:s.Lr.colorZ.optional()}).default({color:void 0}),ca=h.z.object({statusSource:er.optional().default(Kn),colorSource:Jt.optional().default(at),status:s.Yr.statusZ(la),color:s.Lr.colorZ.optional()});class jn extends g.Leaf{static TYPE="Indicator";schema=ca;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:t}=this,{statusSource:r,colorSource:i}=this.state;t.statusSource=j(e,r,t.statusSource),t.colorSource=j(e,i,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();s.Lr.equals(e,this.state.color)&&t.message===this.state.status.message||this.setState(r=>({...r,color:e,status:t}))}}const ua=h.z.object({needsControlOf:g.DI.keyZ.array(),states:na.array()});class $n extends g.Leaf{static TYPE="Legend";schema=ua;afterUpdate(e){const{internal:t}=this;t.stateProv=rt.use(e);const r=this.state.needsControlOf;t.disconnectStateProv?.();const i=s.Ur.filterTransfersByChannelKey(...r),a=t.stateProv.get(r);this.setState(o=>({...o,states:a})),t.disconnectStateProv=t.stateProv.onChange(o=>{if(i(o).length===0)return;const l=t.stateProv.get(r);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const ch={[Zn.TYPE]:Zn,[rt.TYPE]:rt,[jn.TYPE]:jn,[Nn.TYPE]:Nn,[$n.TYPE]:$n},ha=["fire","momentary","pulse"],uh=h.z.enum(ha),da=h.z.object({trigger:h.z.number(),sink:Kt.optional().default(Xt),mode:uh.optional().default("fire")}),fa=2,pa=1;class Bn extends g.Leaf{static TYPE="Button";schema=da;afterUpdate(e){const{sink:t,mode:r,trigger:i}=this.state,{internal:a}=this;a.prevTrigger??=i,a.sink=je(e,t,a.sink);const o=a.prevTrigger;a.prevTrigger=i;const l=i===o+fa;i===o+pa?r=="fire"?this.internal.sink.set(!0):r=="momentary"&&this.internal.sink.set(!1):l&&(r=="momentary"?this.internal.sink.set(!0):r=="pulse"&&this.internal.sink.set(!0,!1))}afterDelete(){this.internal.sink.cleanup?.()}}const hh={[Bn.TYPE]:Bn},dh=h.z.object({region:s.jt.box,clearOverScan:s.Q.crudeZ.optional().default(0),visible:h.z.boolean().optional().default(!0),autoRenderInterval:h.z.number().optional().default(1e3)}),gs=["upper2d","lower2d"];class Ne extends g.Composite{static TYPE="Table";static stateZ=dh;schema=Ne.stateZ;afterUpdate(e){const{internal:t}=this;t.renderCtx=M.Context.use(e),t.handleError=g.useErrorHandler(e),t.autoRenderInterval??=setInterval(()=>this.state.visible&&this.requestRender("low"),this.state.autoRenderInterval),sn(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=s.jt.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:t,handleError:r}=this.internal,i=s.C$1.XY.translate(s.jt.topLeft(this.state.region)),a=t.scissor(this.state.region,s.Q.construct(this.state.clearOverScan),gs);try{for(const o of this.children)o.render({viewportScale:i})}catch(o){r(o,"Failed to render table")}finally{a()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${Ne.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:gs})}}const fh={[Ne.TYPE]:Ne};h.z.enum(["small","medium","large","huge"]);const ph=h.z.object({box:s.jt.box,telem:en.optional().default(Xn),backgroundTelem:Jt.optional().default(at),level:ce.levelZ.optional().default("p"),color:s.Lr.colorZ.optional().default(s.Lr.ZERO),precision:h.z.number().optional().default(2),minWidth:h.z.number().optional().default(60),width:h.z.number().optional(),notation:s.Gr.notationZ.optional().default("standard"),location:s.K.xy.optional().default({x:"left",y:"center"}),units:h.z.string().optional().default("RPM"),bounds:s.H.bounds.optional().default(s.H.construct(0,100)),barWidth:h.z.number().optional().default(12)}),gh=["upper2d","lower2d"];class st extends g.Leaf{static TYPE="gauge";static z=ph;schema=st.z;afterUpdate(e){const{internal:t}=this;t.render=M.Context.use(e),t.theme=g.use(e),s.Lr.isZero(this.state.color)?t.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=j(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>this.requestRender()),t.backgroundTelem=j(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=mr(e),t.strokeColor=s.Lr.isZero(this.state.color)?t.theme.colors.visualization.palettes.default[0]:this.state.color;const r=this.state.box,i=s.jt.width(r)/2,{barWidth:a}=this.state;t.outerRadius=i-8,t.innerRadius=t.outerRadius-a;const o=Math.PI/2;t.gaugeStartAngle=3*Math.PI/4,t.gaugeAngleRange=2*Math.PI-o,t.gaugeEndAngle=t.gaugeStartAngle+t.gaugeAngleRange,t.labelRadius=t.outerRadius+12,t.labelInwardShift=12,t.centerPos=s.jt.center(r);const l=t.centerPos.y+t.labelRadius*Math.sin(t.gaugeStartAngle)+6;t.minLabelPos=s.Q.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeStartAngle)+t.labelInwardShift,l),t.maxLabelPos=s.Q.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeEndAngle)-t.labelInwardShift,l),t.valueTextPos=s.Q.translateY(t.centerPos,-6),t.unitsTextPos=s.Q.translateY(t.centerPos,s.jt.height(r)/9),t.textLevel=this.state.level,t.labelLevel=ce.downLevel(ce.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(s.jt.construct(this.state.box),s.Q.ZERO,...gh):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}render({viewportScale:e=s.C$1.XY.IDENTITY}){const{internal:t}=this,r=t.render.upper2d.applyScale(e),i=new ye(r,t.theme),a=t.telem.value(),{lower:o,upper:l}=this.state.bounds,u=Number(a),c=s.H.clamp(this.state.bounds,u),d=l-o,f=d===0?0:(c-o)/d,p=t.gaugeStartAngle+f*t.gaugeAngleRange;i.text({text:a,position:t.valueTextPos,shade:10,level:t.textLevel,align:"middle",justify:"center",weight:450,code:!0,useAtlas:!0}),i.text({text:this.state.units,position:t.unitsTextPos,shade:8,level:ce.downLevel(t.textLevel),align:"middle",justify:"center",code:!0,useAtlas:!0}),i.text({text:o.toString(),position:t.minLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),i.text({text:l.toString(),position:t.maxLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),i.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"}),i.circle({stroke:t.strokeColor,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:p},lineCap:"round"})}}const mh={[st.TYPE]:st},ga=h.z.object({trigger:h.z.number(),command:h.z.string().optional(),sink:ks.default(xs)});class Un extends g.Leaf{static TYPE="Input";schema=ga;afterUpdate(e){const{sink:t,trigger:r,command:i}=this.state,{internal:a}=this;a.sink=je(e,t,a.sink);const o=a.prevTrigger??r;r>o&&i!=null&&this.internal.sink.set(i),a.prevTrigger=r}afterDelete(){this.internal.sink.cleanup?.()}}const yh={[Un.TYPE]:Un},ma=h.z.object({enabled:h.z.boolean(),source:Jn.optional().default(Vn)});class qn extends g.Leaf{static TYPE="Light";schema=ma;afterUpdate(e){const{internal:t}=this;this.internal.source=j(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 vh={[qn.TYPE]:qn},ya=h.z.object({trigger:h.z.number(),command:h.z.number().optional(),value:h.z.number(),sink:Ps.optional().default(Ss),source:Ls.optional().default(Ts)});class Hn extends g.Leaf{static TYPE="Setpoint";schema=ya;afterUpdate(e){const{sink:t,source:r,trigger:i,command:a}=this.state,{internal:o}=this;o.prevTrigger??=i,this.internal.source=j(e,r,this.internal.source),o.sink=je(e,t,o.sink);const l=o.prevTrigger;o.prevTrigger=i,i>l&&a!=null&&this.internal.sink.set(a),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())}updateValue(){const e=this.internal.source.value();e===this.state.value||isNaN(e)||this.setState(t=>({...t,value:e,triggered:!1}))}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.source.cleanup?.(),e.sink.cleanup?.()}}const bh={[Hn.TYPE]:Hn},va=h.z.object({triggered:h.z.boolean(),enabled:h.z.boolean(),sink:Kt.optional().default(Xt),source:Jn.optional().default(Vn)});class Fn extends g.Leaf{static TYPE="Toggle";schema=va;afterUpdate(e){this.internal.addStatus=g.useOptionalAdder(e);const{sink:t,source:r,triggered:i,enabled:a}=this.state,{triggered:o}=this.prevState,{internal:l}=this;l.source=j(e,r,l.source),l.sink=je(e,t,l.sink),i&&!o&&l.sink.set(!a),this.updateEnabledState(),l.stopListening?.(),l.stopListening=l.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e,triggered:!1}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const Sh={[Fn.TYPE]:Fn},mn={useAtlas:!0},Th=h.z.object({box:s.jt.box,telem:en.optional().default(Xn),backgroundTelem:Jt.optional().default(at),level:ce.levelZ.optional().default("p"),color:s.Lr.colorZ.optional().default(s.Lr.ZERO),precision:h.z.number().optional().default(2),stalenessTimeout:h.z.number().optional().default(5),stalenessColor:s.Lr.colorZ.optional().default(s.Lr.ZERO),minWidth:h.z.number().optional().default(60),width:h.z.number().optional(),notation:s.Gr.notationZ.optional().default("standard"),location:s.K.xy.optional().default({x:"left",y:"center"}),useWidthForBackground:h.z.boolean().optional().default(!1),valueBackgroundShift:s.Q.xy.optional().default(s.Q.ZERO),valueBackgroundOverScan:s.Q.xy.optional().default(s.Q.ZERO)}),xh=["upper2d","lower2d"];class Ze extends g.Leaf{static TYPE="value";static z=Th;schema=Ze.z;afterUpdate(e){const{internal:t}=this;t.renderCtx=M.Context.use(e),t.theme=g.use(e),t.telem=j(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>{t.lastReceived=performance.now(),this.requestRender()}),t.fontString=Qe.fontString(t.theme,{level:this.state.level,code:!0}),t.backgroundTelem=j(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=mr(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(s.jt.construct(this.state.box),s.Q.ZERO,...xh):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,r=e+t.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<r||this.state.minWidth>r&&this.state.width!==this.state.minWidth?this.setState(i=>({...i,width:Math.max(r,i.minWidth)})):this.state.width-this.fontHeight>r&&this.setState(i=>({...i,width:Math.max(r,i.minWidth)}))}getTextColor(){const{theme:e}=this.internal;return performance.now()-this.internal.lastReceived>this.state.stalenessTimeout*1e3?s.Lr.isZero(this.state.stalenessColor)?e.colors.warning.m1:this.state.stalenessColor:s.Lr.isZero(this.state.color)?s.Lr.pickByContrast(e.colors.border,e.colors.gray.l11,e.colors.gray.l0):s.Lr.pickByContrast(e.colors.border,e.colors.gray.l11,this.state.color)}render({viewportScale:e=s.C$1.XY.IDENTITY}){const{renderCtx:t,telem:r,backgroundTelem:i,fontString:a,requestRender:o}=this.internal,{location:l,box:u}=this.state;if(s.jt.areaIsZero(u))return;const c=s.jt.topLeft(u),d=s.jt.width(u),f=s.jt.height(u),p=t.lower2d.applyScale(e);let y=r.value();p.font=a;const S=this.fontHeight,b=y[0]=="-";b&&(y=y.slice(1));const{theme:T}=this.internal,C=p.textDimensions(y,mn),k=C.width+T.sizes.base,R=C.height;o==null&&t.erase(s.jt.construct(this.prevState.box)),this.maybeUpdateWidth(k);const _={...s.Q.ZERO};l.x==="left"?_.x=6+S*.75:l.x==="center"&&(_.x=d/2-k/2),l.y==="center"&&(_.y=f/2+R/2);const A=s.Q.translate(c,_);if(this.state.backgroundTelem.type!=at.type){const D=i.value();if(!s.Lr.isZero(D)){p.fillStyle=s.Lr.hex(D);const Be=this.state.useWidthForBackground?this.state.width??this.state.minWidth:s.jt.width(u);p.fillRect(...s.Q.couple(s.Q.translate(c,this.state.valueBackgroundShift)),Be+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y)}}const x=this.getTextColor();p.fillStyle=s.Lr.hex(x),b&&p.fillText("-",...s.Q.couple(s.Q.translateX(A,-S*.6)),void 0,mn),p.fillText(y,...s.Q.couple(A),void 0,mn)}}const ba={[Ze.TYPE]:Ze},wh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ba,Value:Ze},Symbol.toStringTag,{value:"Module"}));exports.AcquireChannelControl=Qt;exports.AuthoritySource=Wt;exports.Base=me;exports.BaseProvider=De;exports.Bottom=Zi;exports.BoundQuerier=It;exports.Button=Bn;exports.Canvas=Yt;exports.Chip=Nn;exports.Client=Si;exports.Controller=Zn;exports.Diagram=ll;exports.Diagram$1=he;exports.FLUX_STORE_CONFIG=sh;exports.FLUX_STORE_KEY=th;exports.Gauge=st;exports.Indicator=jn;exports.Input=Un;exports.Legend=$n;exports.Light=qn;exports.Line=Dt;exports.LinePlot=zn;exports.Log=nt;exports.MODES=ha;exports.MOUSE_DOWN_INCREMENT=fa;exports.MOUSE_UP_INCREMENT=pa;exports.Measure=tt;exports.PROVIDER_TYPE=br;exports.Provider=At;exports.Provider$1=qt;exports.REGISTRY=Xu;exports.REGISTRY$1=mh;exports.REGISTRY$10=Qi;exports.REGISTRY$11=ju;exports.REGISTRY$12=Vi;exports.REGISTRY$13=rl;exports.REGISTRY$14=vh;exports.REGISTRY$15=yh;exports.REGISTRY$16=yi;exports.REGISTRY$17=ch;exports.REGISTRY$18=mi;exports.REGISTRY$19=hh;exports.REGISTRY$2=fh;exports.REGISTRY$3=eh;exports.REGISTRY$4=ba;exports.REGISTRY$5=Gi;exports.REGISTRY$6=Sh;exports.REGISTRY$7=pi;exports.REGISTRY$8=ci;exports.REGISTRY$9=bh;exports.RELATIONSHIPS_FLUX_STORE_KEY=gl;exports.RELATIONSHIP_FLUX_STORE_CONFIG=bl;exports.RESOURCES_FLUX_STORE_KEY=ml;exports.RESOURCE_FLUX_STORE_CONFIG=xl;exports.Right=$i;exports.Rule=Je;exports.ScopedUnaryStore=vi;exports.SetChannelValue=Ft;exports.Setpoint=Hn;exports.StateProvider=rt;exports.Table=Ne;exports.Toggle=Fn;exports.Tooltip=et;exports.Top=ji;exports.Value=Ze;exports.XAxis=Ht;exports.YAxis=Ut;exports.ZERO_CONTEXT_VALUE=dr;exports.a=Gt;exports.acquireChannelControl=ah;exports.acquireChannelControlPropsZ=aa;exports.aether=Yu;exports.authoritySource=lh;exports.authoritySourceDetailsZ=oh;exports.authoritySourceProps=oa;exports.axisStateZ=kr;exports.boundQuerierStateZ=wi;exports.buttonStateZ=da;exports.canvas=ol;exports.canvasStateZ=yr;exports.channelData=Is;exports.chipStateZ=ea;exports.chipStatusDetailsZ=Ji;exports.color=Re;exports.colorGradient=Ks;exports.control=sn;exports.controllerStateZ=sa;exports.coreAxisStateZ=dt;exports.createRegistry=pl;exports.createStore=bi;exports.diagramStateZ=vr;exports.external=Ho;exports.indicatorStateZ=ca;exports.indicatorStatusDetailsZ=la;exports.interpolate=Vt;exports.interpolateNumber=Ve;exports.interpolateRgb=vn;exports.interpolateString=bs;exports.legendStateZ=ua;exports.linePlotStateZ=Xi;exports.logState=Ki;exports.measure=Qu;exports.measureStateZ=Mr;exports.newCanvas=Ni;exports.newTickFactory=Yn;exports.parseAutoBounds=Fi;exports.partialUpdate=cl;exports.provider=xo;exports.providerStateZ=Ti;exports.providerStateZ$1=Wi;exports.providerStateZ$2=pr;exports.regions=le;exports.request=J;exports.rollingAverage=Vs;exports.rollingAverageProps=cr;exports.ruleStateZ=Or;exports.scaleNumber=ei;exports.scopeStore=On;exports.setChannelValue=ih;exports.setChannelValuePropsZ=ia;exports.setpoint=Hs;exports.sinkPipeline=As;exports.sinkPipelinePropsZ=sr;exports.sourcePipeline=Ms;exports.sourcePipelinePropsZ=nr;exports.stateProviderStateZ=ta;exports.stateZ=gi;exports.stateZ$1=ga;exports.stateZ$2=ma;exports.stateZ$3=ya;exports.statusZ=ra;exports.streamChannelData=zs;exports.streamChannelValue=Ns;exports.streamChannelValuePropsZ=ir;exports.stringSourceSpecZ=en;exports.stringifyNumber=Gs;exports.stringifyNumberProps=lr;exports.sugaredStateZ=na;exports.tickFactoryProps=Pr;exports.tickType=Lr;exports.toggleStateZ=va;exports.tooltip=Fu;exports.tooltipStateZ=_r;exports.useOptionalRequestor=mr;exports.useRequestor=an;exports.value=wh;exports.withinBounds=Fs;exports.withinBoundsProps=or;exports.withinSizeThreshold=Ui;exports.xAxisStateZ=$u;exports.yAxisStateZ=Iu;
|