@synnaxlabs/pluto 0.53.1 → 0.54.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/aether-BBeeeA1z.cjs +10 -0
- package/dist/aether-Bl3vMZO3.js +716 -0
- package/dist/aether-DmSenWd4.js +704 -0
- package/dist/aether-VeYJQDcf.cjs +11 -0
- package/dist/button-DBdzH6Ky.cjs +1 -0
- package/dist/button-KtgabnXL.js +251 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +2 -4
- package/dist/chunk-DeC0fbbY.js +23 -0
- package/dist/chunk-FeXHwk1_.cjs +1 -0
- package/dist/color-Cspp5cKp.js +7904 -0
- package/dist/color-DCCr0Z1b.cjs +29 -0
- package/dist/color.cjs +1 -1
- package/dist/color.js +2 -4
- package/dist/css-Ce-x3HcK.cjs +1 -0
- package/dist/css-UEo6g0SR.js +69 -0
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -8
- package/dist/dialog-BTCrp5Yv.cjs +1 -0
- package/dist/dialog-ClQI4sHo.js +331 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +2 -4
- package/dist/divider-BYRH8-5K.js +13 -0
- package/dist/divider-CEyntx31.cjs +1 -0
- package/dist/ether-CZlE80D0.cjs +53 -0
- package/dist/ether-KMGPzrZR.js +6222 -0
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +4 -104
- package/dist/event-Btz3eWg1.cjs +1 -0
- package/dist/event-Z4V8c501.js +4 -0
- package/dist/flex-Bgtu0DK6.js +62 -0
- package/dist/flex-D_GoD3ed.cjs +1 -0
- package/dist/flex.cjs +1 -1
- package/dist/flex.js +2 -4
- package/dist/haul-BdMc4rLJ.js +171 -0
- package/dist/haul-ZdSHqhp6.cjs +1 -0
- package/dist/header-CNx3pAkx.js +64 -0
- package/dist/header-lD0sRjCR.cjs +1 -0
- package/dist/header.cjs +1 -1
- package/dist/header.js +2 -4
- package/dist/input-CdL1OPDU.cjs +74 -0
- package/dist/input-h-4axMs7.js +47772 -0
- package/dist/input.cjs +1 -1
- package/dist/input.js +2 -4
- package/dist/list-DacuSBB3.cjs +4 -0
- package/dist/list-dZDsxTzd.js +1756 -0
- package/dist/list.cjs +1 -1
- package/dist/list.js +2 -4
- package/dist/menu-eeXfR_zT.js +170 -0
- package/dist/menu-yADx33I8.cjs +1 -0
- package/dist/menu.cjs +1 -1
- package/dist/menu.js +2 -4
- package/dist/pluto.cjs +52 -0
- package/dist/pluto.css +2 -1
- package/dist/pluto.js +36474 -0
- package/dist/select-B93mFqvf.js +1328 -0
- package/dist/select-gt7wGGO4.cjs +1 -0
- package/dist/src/access/policy/queries.d.ts +34 -34
- package/dist/src/access/policy/queries.d.ts.map +1 -1
- package/dist/src/access/queries.d.ts +1 -1
- package/dist/src/access/queries.d.ts.map +1 -1
- package/dist/src/access/role/queries.d.ts +2 -12
- package/dist/src/access/role/queries.d.ts.map +1 -1
- package/dist/src/arc/queries.d.ts +1167 -29
- package/dist/src/arc/queries.d.ts.map +1 -1
- package/dist/src/channel/LinePlot.d.ts +2 -2
- package/dist/src/channel/LinePlot.d.ts.map +1 -1
- package/dist/src/channel/queries.d.ts +108 -60
- package/dist/src/channel/queries.d.ts.map +1 -1
- package/dist/src/color/Provider.d.ts +8 -8
- package/dist/src/device/queries.d.ts +148 -363
- package/dist/src/device/queries.d.ts.map +1 -1
- package/dist/src/flux/result.d.ts +5 -5
- package/dist/src/flux/result.d.ts.map +1 -1
- package/dist/src/flux/update.d.ts +1 -1
- package/dist/src/flux/update.d.ts.map +1 -1
- package/dist/src/icon/Icon.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/label/queries.d.ts +21 -21
- package/dist/src/label/queries.d.ts.map +1 -1
- package/dist/src/lineplot/aether/XAxis.d.ts +28 -28
- package/dist/src/lineplot/aether/YAxis.d.ts +28 -28
- package/dist/src/lineplot/aether/axis.d.ts +14 -14
- package/dist/src/lineplot/queries.d.ts +2 -2
- package/dist/src/lineplot/queries.d.ts.map +1 -1
- package/dist/src/lineplot/range/aether/provider.d.ts +126 -102
- package/dist/src/lineplot/range/aether/provider.d.ts.map +1 -1
- package/dist/src/lineplot/tooltip/aether/tooltip.d.ts +56 -56
- package/dist/src/log/aether/Log.d.ts +21 -21
- package/dist/src/log/queries.d.ts +2 -2
- package/dist/src/log/queries.d.ts.map +1 -1
- package/dist/src/memo/index.d.ts +0 -1
- package/dist/src/memo/index.d.ts.map +1 -1
- package/dist/src/memo/useMemoCompare.d.ts +0 -1
- package/dist/src/memo/useMemoCompare.d.ts.map +1 -1
- package/dist/src/rack/queries.d.ts.map +1 -1
- package/dist/src/ranger/aether/queries.d.ts.map +1 -1
- package/dist/src/ranger/queries.d.ts +19 -19
- package/dist/src/ranger/queries.d.ts.map +1 -1
- package/dist/src/schematic/queries.d.ts +2 -2
- package/dist/src/schematic/queries.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Forms.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Primitives.d.ts +2 -1
- package/dist/src/schematic/symbol/Primitives.d.ts.map +1 -1
- package/dist/src/schematic/symbol/SelectOrientation.d.ts.map +1 -1
- package/dist/src/schematic/symbol/Symbols.d.ts +35 -34
- package/dist/src/schematic/symbol/Symbols.d.ts.map +1 -1
- package/dist/src/schematic/symbol/queries.d.ts +96 -50
- package/dist/src/schematic/symbol/queries.d.ts.map +1 -1
- package/dist/src/schematic/symbol/registry.d.ts.map +1 -1
- package/dist/src/select/Dialog.d.ts +2 -1
- package/dist/src/select/Dialog.d.ts.map +1 -1
- package/dist/src/status/Select.d.ts.map +1 -1
- package/dist/src/status/SelectMulipleVariants.spec.d.ts +2 -0
- package/dist/src/status/SelectMulipleVariants.spec.d.ts.map +1 -0
- package/dist/src/status/SelectMultipleVariants.d.ts +9 -0
- package/dist/src/status/SelectMultipleVariants.d.ts.map +1 -0
- package/dist/src/status/SelectVariant.d.ts +2 -2
- package/dist/src/status/SelectVariant.d.ts.map +1 -1
- package/dist/src/status/SelectVariant.spec.d.ts +2 -0
- package/dist/src/status/SelectVariant.spec.d.ts.map +1 -0
- package/dist/src/status/aether/aggregator.d.ts +16 -2
- package/dist/src/status/aether/aggregator.d.ts.map +1 -1
- package/dist/src/status/aether/errorHandler.d.ts +2 -1
- package/dist/src/status/aether/errorHandler.d.ts.map +1 -1
- package/dist/src/status/base/Aggregator.d.ts +3 -2
- package/dist/src/status/base/Aggregator.d.ts.map +1 -1
- package/dist/src/status/external.d.ts +1 -0
- package/dist/src/status/external.d.ts.map +1 -1
- package/dist/src/status/queries.d.ts +25 -9
- package/dist/src/status/queries.d.ts.map +1 -1
- package/dist/src/status/variantData.d.ts +4 -0
- package/dist/src/status/variantData.d.ts.map +1 -0
- package/dist/src/table/cells/Cells.d.ts +17 -17
- package/dist/src/table/queries.d.ts +2 -2
- package/dist/src/table/queries.d.ts.map +1 -1
- package/dist/src/task/queries.d.ts +3 -3
- package/dist/src/task/queries.d.ts.map +1 -1
- package/dist/src/telem/aether/noop.d.ts.map +1 -1
- package/dist/src/telem/aether/static.d.ts +10 -10
- package/dist/src/telem/aether/telem.d.ts +1 -1
- package/dist/src/telem/aether/telem.d.ts.map +1 -1
- package/dist/src/telem/aether/transformers.d.ts +15 -15
- package/dist/src/telem/aether/transformers.d.ts.map +1 -1
- package/dist/src/telem/client/cache/cache.d.ts +1 -1
- package/dist/src/telem/client/cache/cache.d.ts.map +1 -1
- package/dist/src/telem/client/client.d.ts +4 -4
- package/dist/src/telem/client/client.d.ts.map +1 -1
- package/dist/src/telem/client/reader.d.ts +1 -1
- package/dist/src/telem/client/reader.d.ts.map +1 -1
- package/dist/src/telem/client/streamer.d.ts +1 -1
- package/dist/src/telem/client/streamer.d.ts.map +1 -1
- package/dist/src/telem/control/Controller.d.ts +1 -1
- package/dist/src/telem/control/Controller.d.ts.map +1 -1
- package/dist/src/telem/control/aether/chip.d.ts +16 -2
- package/dist/src/telem/control/aether/chip.d.ts.map +1 -1
- package/dist/src/telem/control/aether/controller.d.ts +16 -16
- package/dist/src/telem/control/aether/controller.d.ts.map +1 -1
- package/dist/src/telem/control/aether/indicator.d.ts +51 -37
- package/dist/src/telem/control/aether/indicator.d.ts.map +1 -1
- package/dist/src/telem/control/aether/legend.d.ts +18 -16
- package/dist/src/telem/control/aether/legend.d.ts.map +1 -1
- package/dist/src/telem/control/aether/state.d.ts +9 -8
- package/dist/src/telem/control/aether/state.d.ts.map +1 -1
- package/dist/src/theming/aether/provider.d.ts +990 -990
- package/dist/src/theming/base/theme.d.ts +330 -330
- package/dist/src/user/queries.d.ts +2 -2
- package/dist/src/view/queries.d.ts +2 -2
- package/dist/src/vis/axis/axis.d.ts +14 -14
- package/dist/src/vis/gauge/aether/gauge.d.ts +21 -21
- package/dist/src/vis/gauge/use.d.ts +7 -7
- package/dist/src/vis/line/aether/line.d.ts +7 -7
- package/dist/src/vis/measure/aether/measure.d.ts +56 -56
- package/dist/src/vis/rule/aether/aether.d.ts +14 -14
- package/dist/src/vis/value/aether/value.d.ts +42 -42
- package/dist/src/vis/value/redline.d.ts +5 -5
- package/dist/src/vis/value/redline.d.ts.map +1 -1
- package/dist/src/vis/value/use.d.ts +14 -14
- package/dist/src/workspace/queries.d.ts +6 -4
- package/dist/src/workspace/queries.d.ts.map +1 -1
- package/dist/tabs-CB7d2_0h.cjs +1 -0
- package/dist/tabs-DEXXNOZA.js +253 -0
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +2 -4
- package/dist/text-Dd6wYgQM.js +142 -0
- package/dist/text-n3Fetdk6.cjs +1 -0
- package/dist/text.cjs +1 -1
- package/dist/text.js +2 -5
- package/dist/theming-Blgv4Cvi.js +591 -0
- package/dist/theming-KFfFjsRJ.cjs +1 -0
- package/dist/theming.cjs +1 -1
- package/dist/theming.js +2 -5
- package/dist/tree-B4jJAzS1.js +294 -0
- package/dist/tree-CsgSEpgy.cjs +1 -0
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +2 -4
- package/dist/triggers-AqBSAR_T.cjs +1 -0
- package/dist/triggers-DDlalLoO.js +4748 -0
- package/dist/triggers.cjs +1 -1
- package/dist/triggers.js +2 -4
- package/dist/types-BGbd8pRh.js +73 -0
- package/dist/types-ByXvRm2h.cjs +1 -0
- package/dist/video-Bnr-2W9p.cjs +1 -0
- package/dist/video-ByMlaeKI.js +15 -0
- package/dist/video.cjs +1 -1
- package/dist/video.js +2 -4
- package/package.json +27 -28
- package/dist/Animated-B_N04fe6.cjs +0 -1
- package/dist/Animated-BsbNkFLg.cjs +0 -1
- package/dist/Animated-CLo1CLgn.js +0 -29
- package/dist/Animated-CO--9HPM.js +0 -354
- package/dist/Box-Bi280MYh.js +0 -96
- package/dist/Box-CNUz5BsV.cjs +0 -1
- package/dist/Copy-BgRUUzWz.cjs +0 -1
- package/dist/Copy-COWBkO_v.js +0 -337
- package/dist/Dialog-Bj7FiHJD.js +0 -59
- package/dist/Dialog-DBm6Fap1.cjs +0 -1
- package/dist/Editable-C17ILP50.js +0 -202
- package/dist/Editable-HUPqTaui.cjs +0 -1
- package/dist/Haul-CnZK3e-n.js +0 -132
- package/dist/Haul-DlwI4b25.cjs +0 -1
- package/dist/Items-CXBBG9Ip.cjs +0 -4
- package/dist/Items-DQba1BFQ.js +0 -842
- package/dist/Menu-BZ6ZGIv3.cjs +0 -1
- package/dist/Menu-CniMpPmC.js +0 -139
- package/dist/Provider-cSwm-2e_.cjs +0 -1
- package/dist/Provider-jFWpR0CX.js +0 -520
- package/dist/Tags-CxzMdPpm.cjs +0 -1
- package/dist/Tags-DvfGhiWv.js +0 -925
- package/dist/Text-2MISZsc5.js +0 -1712
- package/dist/Text-XHBXXDRS.cjs +0 -1
- package/dist/Video-Bew5_j16.js +0 -10
- package/dist/Video-BryrVNlH.cjs +0 -1
- package/dist/css-CloSmhZB.cjs +0 -1
- package/dist/css-D90kZTM8.js +0 -63
- package/dist/dimensions-CdFEW3oU.cjs +0 -1
- package/dist/dimensions-DbMN4145.js +0 -19
- package/dist/eraser-BShvqlBE.js +0 -958
- package/dist/eraser-rFMFKqsg.cjs +0 -11
- package/dist/event-BxvV3arE.cjs +0 -1
- package/dist/event-nNH_pXSr.js +0 -36
- package/dist/external-4jf1Bv96.cjs +0 -1
- package/dist/external-B2YeNEwd.cjs +0 -1
- package/dist/external-B9PnwQOL.js +0 -29
- package/dist/external-BBbkXXN0.js +0 -47
- package/dist/external-BByOkVID.cjs +0 -1
- package/dist/external-BrEnYrZV.js +0 -32
- package/dist/external-BwbypKCk.cjs +0 -1
- package/dist/external-C65vBow6.cjs +0 -1
- package/dist/external-CCcIJ20u.cjs +0 -1
- package/dist/external-CF4uh-dm.js +0 -51423
- package/dist/external-Cn6EfkLd.cjs +0 -1
- package/dist/external-CovFw1fv.cjs +0 -1
- package/dist/external-D2Zb9O5J.js +0 -93
- package/dist/external-D6aLGjMg.js +0 -8969
- package/dist/external-DDvmnE2k.js +0 -341
- package/dist/external-DTi9a-iK.cjs +0 -1
- package/dist/external-DYP1_xpd.js +0 -80
- package/dist/external-DxsuBuKe.js +0 -392
- package/dist/external-DysGdnTb.js +0 -130
- package/dist/external-N2L8ffzi.js +0 -71
- package/dist/external-UzXlHlr9.js +0 -24
- package/dist/external-_Ht_yCRf.cjs +0 -1
- package/dist/external-igNfmRSB.cjs +0 -28
- package/dist/external-uUEGzmui.cjs +0 -84
- package/dist/fontString-76R2eWDd.js +0 -29
- package/dist/fontString-BNnhiwug.cjs +0 -1
- package/dist/hooks-Co6IVYNw.cjs +0 -1
- package/dist/hooks-QNj6PdUo.js +0 -73
- package/dist/index.cjs +0 -60
- package/dist/index.js +0 -36908
- package/dist/jsx-runtime-nZSsnGb7.cjs +0 -6
- package/dist/jsx-runtime-tc70JA_2.js +0 -264
- package/dist/provider-Bt-E2O6g.js +0 -810
- package/dist/provider-DQkVj3tA.cjs +0 -10
- package/dist/src/memo/proxyMemo.d.ts +0 -3
- package/dist/src/memo/proxyMemo.d.ts.map +0 -1
- package/dist/types-CGRCBVD4.js +0 -82
- package/dist/types-DI2vtOGs.cjs +0 -1
- package/dist/units-Bu36uC6z.cjs +0 -1
- package/dist/units-DMip-eZH.js +0 -14
- package/dist/useStaticData-BTwIe0Il.cjs +0 -1
- package/dist/useStaticData-p8sk2VCJ.js +0 -1051
- package/dist/value-BkUH03tl.cjs +0 -53
- package/dist/value-D0vfKEY3.js +0 -6821
package/dist/value-BkUH03tl.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";const x=require("@synnaxlabs/client"),r=require("@synnaxlabs/x"),h=require("zod"),w=require("./provider-DQkVj3tA.cjs"),I=require("./eraser-rFMFKqsg.cjs"),on=require("@synnaxlabs/alamos"),et=require("./fontString-BNnhiwug.cjs"),ge=require("./types-DI2vtOGs.cjs");require("react");const sr=require("@synnaxlabs/freighter"),rr=require("./dimensions-CdFEW3oU.cjs");class Br{entries=new Map;setListeners=new Map;deleteListeners=new Map;handleError;equal;constructor(e,t=()=>!1){this.handleError=e,this.equal=t}setOne(e,t,s,o){const i=this.entries.get(t),a=ge.executeSetter(s,i);if(!(a==null||i!=null&&this.equal(a,i,t)))return this.entries.set(t,a),this.notifySet(e,t,a,o),()=>{i===void 0?(this.entries.delete(t),this.notifyDelete(e,t)):(this.entries.set(t,i),this.notifySet(e,t,i,o))}}set(e,t,s,o){const i=[];if(Array.isArray(t))t.forEach(a=>{const l=this.setOne(e,a.key,a,s);l!=null&&i.push(l)});else if(typeof t=="object"&&"key"in t){const a=t,l=this.setOne(e,a.key,a,s);l!=null&&i.push(l)}else{const a=this.setOne(e,t,s,o);a!=null&&i.push(a)}return()=>i.reverse().forEach(a=>a())}get(e){return typeof e=="function"?Array.from(this.entries.values()).filter(e):Array.isArray(e)?e.map(t=>this.entries.get(t)).filter(t=>t!=null):this.entries.get(e)}list(){return Array.from(this.entries.values())}has(e){return Array.isArray(e)?e.every(t=>this.entries.has(t)):this.entries.has(e)}delete(e,t,s){const o=[];return typeof t=="function"?this.entries.forEach((i,a)=>{t(i,a)&&o.push({key:a,value:i})}):r.array.toArray(t).forEach(i=>{const a=this.entries.get(i);o.push({key:i,value:a})}),o.forEach(({key:i})=>{this.entries.delete(i),this.notifyDelete(e,i)}),()=>o.forEach(({key:i,value:a})=>{a!=null&&(this.entries.set(i,a),this.notifySet(e,i,a,s))})}clear(){this.entries.clear()}onSet(e,t,s){return this.setListeners.set(t,{scope:e,key:s}),()=>this.setListeners.delete(t)}onDelete(e,t,s){return this.deleteListeners.set(t,{scope:e,key:s}),()=>this.deleteListeners.delete(t)}notifySet(e,t,s,o){this.setListeners.forEach((i,a)=>{const l=i.key==null||i.key===t,u=i.scope!==e;l&&u&&this.handleError(async()=>await a(s,o),"Failed to notify set listener")})}notifyDelete(e,t){this.deleteListeners.forEach((s,o)=>{const i=s.key==null||s.key===t,a=s.scope!==e;i&&a&&this.handleError(async()=>await o(t),"Failed to notify delete listener")})}scope(e){return{set:(t,s,o)=>this.set(e,t,s,o),get:(t=>this.get(t)),list:()=>this.list(),has:t=>this.has(t),delete:(t,s)=>this.delete(e,t,s),onSet:(t,s)=>this.onSet(e,t,s),onDelete:(t,s)=>this.onDelete(e,t,s)}}}const Fr=(n,e)=>Object.fromEntries(Object.entries(n).map(([t,{equal:s}])=>[t,new Br(e,s)])),Dn=(n,e)=>Object.fromEntries(Object.entries(n).map(([t])=>[t,n[t].scope(e)])),Wi=(n,e,t)=>n.set(e,s=>s==null?void 0:{...s,...t}),Vi=(n,e)=>{const t=n.includes("delete"),s=e.includes("delete");return t&&!s?-1:!t&&s?1:0},Xi=async({openStreamer:n,storeConfig:e,handleError:t,client:s,store:o})=>{const i=Object.values(e),a=r.unique.unique(i.flatMap(({listeners:f})=>f.map(({channel:p})=>p))),l={};i.forEach(({listeners:f})=>f.forEach(p=>{const{channel:g}=p;l[g]=[...l[g]||[],p]}));const u=await x.framer.HardenedStreamer.open(n,a),c=new x.framer.ObservableStreamer(u),d=f=>{const p=[...f.uniqueNames];p.sort(Vi),t(async()=>{for(const g of p){const T=f.get(g),y=l[g];if(y!=null)for(const{onChange:v,schema:R}of y)await t(async()=>{let L;T.dataType.equals(r.DataType.JSON)?L=T.parseJSON(R):L=Array.from(T).map(k=>R.parse(k));for(const k of L)await t(()=>v({changed:k,client:s,store:o}),`Failed to handle streamer change for ${g}`,x.NotFoundError)},`Failed to parse streamer change for ${g}`)}},`Failed to handle streamer change for ${r.strings.naturalLanguageJoin(p)}`)};return c.onChange(d),c.close.bind(c)};class $r{store;streamCloser=null;client;constructor({client:e,openStreamer:t,storeConfig:s,handleError:o,handleAsyncError:i}){this.store=Fr(s,o),this.client=e,e!=null&&(t??=e?.openStreamer.bind(e),this.streamCloser=Xi({client:e,storeConfig:s,handleError:i,store:Dn(this.store,""),openStreamer:t}))}async awaitInitialized(){this.streamCloser!=null&&await this.streamCloser}scopedStore(e){return Dn(this.store,e)}async close(){if(this.streamCloser==null)return;await(await this.streamCloser)()}}const Gi=h.z.object({props:x.synnaxParamsZ.nullable(),state:x.Synnax.connectivity.connectionStateZ.nullable()}),ms={client:null};let _t=class qr extends w.Composite{static TYPE="synnax.Provider";static stateZ=Gi;schema=qr.stateZ;afterUpdate(e){if(e.wasSetPreviously(gs)||Cn(e,ms),this.state.props==null){this.internal.client!=null&&(this.internal.client?.close(),this.internal.client=null),Cn(e,this.internal);return}this.prevState.props!=null&&r.deep.equal(this.state.props,this.prevState.props)&&this.internal.client!=null||(this.internal.client=new x.Synnax(this.state.props),Cn(e,this.internal))}};const gs="pluto-client-context",Cn=(n,e)=>n.set(gs,e),He=n=>n.get(gs)?.client??null,Hr={[_t.TYPE]:_t},Ki=Object.freeze(Object.defineProperty({__proto__:null,Provider:_t,REGISTRY:Hr,ZERO_CONTEXT_VALUE:ms,use:He},Symbol.toStringTag,{value:"Module"})),jr=h.object({}),In="flux-context",ys="flux.Provider",Qi=(n,e)=>n.get(In).scopedStore(e),Ji=n=>{const e=(t,s)=>{if("client"in n)return n.client;const o=He(t);return s!=null&&s?.client?.key===o?.key?s:new $r({client:o,storeConfig:n.storeConfig,handleError:w.useErrorHandler(t),handleAsyncError:w.useAsyncErrorHandler(t)})};return class Wr extends w.Composite{static TYPE=ys;static stateZ=jr;schema=Wr.stateZ;afterUpdate(s){const{internal:o}=this;o.store=e(s,o.store),s.wasSetPreviously(In)||s.set(In,o.store)}}},ea=n=>({[ys]:Ji(n)}),xs="pluto-vis-renderer",an=(n,e)=>{n.set(xs,e,!1)},ln=n=>n.get(xs),bs=n=>n.getOptional(xs),ie=(n,e)=>ln(n)(e),ta="relationships",na="resources",sa={channel:x.ontology.RELATIONSHIP_SET_CHANNEL_NAME,schema:x.ontology.relationshipZ,onChange:({store:n,changed:e})=>n.relationships.set(x.ontology.relationshipToString(e),e)},ra={channel:x.ontology.RELATIONSHIP_DELETE_CHANNEL_NAME,schema:x.ontology.relationshipZ,onChange:({store:n,changed:e})=>{n.relationships.delete(x.ontology.relationshipToString(e))}},oa={equal:(n,e)=>x.ontology.idsEqual(n.from,e.from)&&x.ontology.idsEqual(n.to,e.to)&&n.type===e.type,listeners:[sa,ra]},ia={channel:x.ontology.RESOURCE_SET_CHANNEL_NAME,schema:x.ontology.resourceZ,onChange:async({store:n,changed:e})=>{n.resources.set(e.key,t=>t==null?e:{...t,...e})}},aa={channel:x.ontology.RESOURCE_DELETE_CHANNEL_NAME,schema:x.ontology.idZ,onChange:({store:n,changed:e})=>n.resources.delete(e.key)},la={equal:(n,e)=>r.deep.equal(n,e),listeners:[ia,aa]},ca="policies",ua={channel:x.access.policy.SET_CHANNEL_NAME,schema:x.access.policy.policyZ,onChange:({store:n,changed:e})=>n.policies.set(e.key,e)},ha={channel:x.access.policy.DELETE_CHANNEL_NAME,schema:x.access.policy.keyZ,onChange:({store:n,changed:e})=>n.policies.delete(e)},da={listeners:[ua,ha]},Vr=(n,e)=>{const t=n.relationships.get(i=>x.ontology.matchRelationship(i,{from:{type:"role"},type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:e})),o=n.relationships.get(i=>t.some(a=>x.ontology.matchRelationship(i,{from:a.from,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:{type:"policy"}}))).map(i=>i.to.key);return n.policies.get(o)},fa=async({client:n,store:e,subject:t})=>{let s=Vr(e,t);if(s.length>0)return s;s=await n.access.policies.retrieve({for:t}),e.policies.set(s);for(const o of s)(await n.ontology.retrieveParents([x.access.policy.ontologyID(o.key)],{types:["role"]})).forEach(a=>{const l={from:a.id,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:x.access.policy.ontologyID(o.key)};e.relationships.set(x.ontology.relationshipToString(l),l);const u={from:a.id,type:x.ontology.PARENT_OF_RELATIONSHIP_TYPE,to:t};e.relationships.set(x.ontology.relationshipToString(u),u)});return s};function Ss(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function Xr(n,e){var t=Object.create(n.prototype);for(var s in e)t[s]=e[s];return t}function dt(){}var tt=.7,Ot=1/tt,ke="\\s*([+-]?\\d+)\\s*",nt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",te="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",pa=/^#([0-9a-f]{3,8})$/,ma=new RegExp(`^rgb\\(${ke},${ke},${ke}\\)$`),ga=new RegExp(`^rgb\\(${te},${te},${te}\\)$`),ya=new RegExp(`^rgba\\(${ke},${ke},${ke},${nt}\\)$`),xa=new RegExp(`^rgba\\(${te},${te},${te},${nt}\\)$`),ba=new RegExp(`^hsl\\(${nt},${te},${te}\\)$`),Sa=new RegExp(`^hsla\\(${nt},${te},${te},${nt}\\)$`),or={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Ss(dt,Oe,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:ir,formatHex:ir,formatHex8:Ta,formatHsl:va,formatRgb:ar,toString:ar});function ir(){return this.rgb().formatHex()}function Ta(){return this.rgb().formatHex8()}function va(){return Gr(this).formatHsl()}function ar(){return this.rgb().formatRgb()}function Oe(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=pa.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?lr(e):t===3?new F(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?Tt(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?Tt(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 F(e[1],e[2],e[3],1):(e=ga.exec(n))?new F(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=ya.exec(n))?Tt(e[1],e[2],e[3],e[4]):(e=xa.exec(n))?Tt(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=ba.exec(n))?hr(e[1],e[2]/100,e[3]/100,1):(e=Sa.exec(n))?hr(e[1],e[2]/100,e[3]/100,e[4]):or.hasOwnProperty(n)?lr(or[n]):n==="transparent"?new F(NaN,NaN,NaN,0):null}function lr(n){return new F(n>>16&255,n>>8&255,n&255,1)}function Tt(n,e,t,s){return s<=0&&(n=e=t=NaN),new F(n,e,t,s)}function wa(n){return n instanceof dt||(n=Oe(n)),n?(n=n.rgb(),new F(n.r,n.g,n.b,n.opacity)):new F}function zn(n,e,t,s){return arguments.length===1?wa(n):new F(n,e,t,s??1)}function F(n,e,t,s){this.r=+n,this.g=+e,this.b=+t,this.opacity=+s}Ss(F,zn,Xr(dt,{brighter(n){return n=n==null?Ot:Math.pow(Ot,n),new F(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?tt:Math.pow(tt,n),new F(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new F(ye(this.r),ye(this.g),ye(this.b),Mt(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:cr,formatHex:cr,formatHex8:Ea,formatRgb:ur,toString:ur}));function cr(){return`#${pe(this.r)}${pe(this.g)}${pe(this.b)}`}function Ea(){return`#${pe(this.r)}${pe(this.g)}${pe(this.b)}${pe((isNaN(this.opacity)?1:this.opacity)*255)}`}function ur(){const n=Mt(this.opacity);return`${n===1?"rgb(":"rgba("}${ye(this.r)}, ${ye(this.g)}, ${ye(this.b)}${n===1?")":`, ${n})`}`}function Mt(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function ye(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function pe(n){return n=ye(n),(n<16?"0":"")+n.toString(16)}function hr(n,e,t,s){return s<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new ee(n,e,t,s)}function Gr(n){if(n instanceof ee)return new ee(n.h,n.s,n.l,n.opacity);if(n instanceof dt||(n=Oe(n)),!n)return new ee;if(n instanceof ee)return n;n=n.rgb();var e=n.r/255,t=n.g/255,s=n.b/255,o=Math.min(e,t,s),i=Math.max(e,t,s),a=NaN,l=i-o,u=(i+o)/2;return l?(e===i?a=(t-s)/l+(t<s)*6:t===i?a=(s-e)/l+2:a=(e-t)/l+4,l/=u<.5?i+o:2-i-o,a*=60):l=u>0&&u<1?0:a,new ee(a,l,u,n.opacity)}function Ca(n,e,t,s){return arguments.length===1?Gr(n):new ee(n,e,t,s??1)}function ee(n,e,t,s){this.h=+n,this.s=+e,this.l=+t,this.opacity=+s}Ss(ee,Ca,Xr(dt,{brighter(n){return n=n==null?Ot:Math.pow(Ot,n),new ee(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?tt:Math.pow(tt,n),new ee(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,s=t+(t<.5?t:1-t)*e,o=2*t-s;return new F(Rn(n>=240?n-240:n+120,o,s),Rn(n,o,s),Rn(n<120?n+240:n-120,o,s),this.opacity)},clamp(){return new ee(dr(this.h),vt(this.s),vt(this.l),Mt(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=Mt(this.opacity);return`${n===1?"hsl(":"hsla("}${dr(this.h)}, ${vt(this.s)*100}%, ${vt(this.l)*100}%${n===1?")":`, ${n})`}`}}));function dr(n){return n=(n||0)%360,n<0?n+360:n}function vt(n){return Math.max(0,Math.min(1,n||0))}function Rn(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const Ts=n=>()=>n;function Ra(n,e){return function(t){return n+t*e}}function Pa(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(s){return Math.pow(n+s*e,t)}}function La(n){return(n=+n)==1?Kr:function(e,t){return t-e?Pa(e,t,n):Ts(isNaN(e)?t:e)}}function Kr(n,e){var t=e-n;return t?Ra(n,t):Ts(isNaN(n)?e:n)}const Yn=(function n(e){var t=La(e);function s(o,i){var a=t((o=zn(o)).r,(i=zn(i)).r),l=t(o.g,i.g),u=t(o.b,i.b),c=Kr(o.opacity,i.opacity);return function(d){return o.r=a(d),o.g=l(d),o.b=u(d),o.opacity=c(d),o+""}}return s.gamma=n,s})(1);function ka(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,s=e.slice(),o;return function(i){for(o=0;o<t;++o)s[o]=n[o]*(1-i)+e[o]*i;return s}}function _a(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Oa(n,e){var t=e?e.length:0,s=n?Math.min(t,n.length):0,o=new Array(s),i=new Array(t),a;for(a=0;a<s;++a)o[a]=cn(n[a],e[a]);for(;a<t;++a)i[a]=e[a];return function(l){for(a=0;a<s;++a)i[a]=o[a](l);return i}}function Ma(n,e){var t=new Date;return n=+n,e=+e,function(s){return t.setTime(n*(1-s)+e*s),t}}function st(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function Aa(n,e){var t={},s={},o;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(o in e)o in n?t[o]=cn(n[o],e[o]):s[o]=e[o];return function(i){for(o in t)s[o]=t[o](i);return s}}var Nn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Pn=new RegExp(Nn.source,"g");function Da(n){return function(){return n}}function Ia(n){return function(e){return n(e)+""}}function Qr(n,e){var t=Nn.lastIndex=Pn.lastIndex=0,s,o,i,a=-1,l=[],u=[];for(n=n+"",e=e+"";(s=Nn.exec(n))&&(o=Pn.exec(e));)(i=o.index)>t&&(i=e.slice(t,i),l[a]?l[a]+=i:l[++a]=i),(s=s[0])===(o=o[0])?l[a]?l[a]+=o:l[++a]=o:(l[++a]=null,u.push({i:a,x:st(s,o)})),t=Pn.lastIndex;return t<e.length&&(i=e.slice(t),l[a]?l[a]+=i:l[++a]=i),l.length<2?u[0]?Ia(u[0].x):Da(e):(e=u.length,function(c){for(var d=0,f;d<e;++d)l[(f=u[d]).i]=f.x(c);return l.join("")})}function cn(n,e){var t=typeof e,s;return e==null||t==="boolean"?Ts(e):(t==="number"?st:t==="string"?(s=Oe(e))?(e=s,Yn):Qr:e instanceof Oe?Yn:e instanceof Date?Ma:_a(e)?ka:Array.isArray(e)?Oa:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?Aa:st)(n,e)}function za(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}class ce extends r.observe.Observer{cleanup(){}}class Zn extends ce{static TYPE="noop-boolean-sink";set(){}}const un={type:Zn.TYPE,props:{},variant:"sink",valueType:"boolean"};class Un extends ce{static TYPE="noop-numeric-sink";set(){}}const Jr={type:Un.TYPE,props:{},variant:"sink",valueType:"number"};class Bn extends ce{static TYPE="noop-boolean-source";value(){return!1}}const vs={type:Bn.TYPE,props:{},variant:"source",valueType:"boolean"};class Fn extends ce{static TYPE="noop-numeric-source";value(){return 0}}const ws={type:Fn.TYPE,props:{},variant:"source",valueType:"number"};class $n extends ce{static TYPE="noop-string-sink";set(){}}const eo={type:$n.TYPE,props:{},variant:"sink",valueType:"string"};class qn extends ce{static TYPE="noop-string-source";value(){return""}}const Es={type:qn.TYPE,props:{},variant:"source",valueType:"string"};class Hn extends ce{static TYPE="noop-status-source";value(){return{key:"noop",name:"noop",variant:"disabled",message:"unknown",time:r.TimeStamp.now()}}}const Cs={type:Hn.TYPE,props:{},variant:"source",valueType:"status"};class jn extends ce{static TYPE="noop-color-source";value(){return r.color.ZERO}}const ft={type:jn.TYPE,props:{},variant:"source",valueType:"color"};class Wn extends ce{static TYPE="noop-series";value(){return[r.bounds.ZERO,new r.MultiSeries([])]}}const to={type:Wn.TYPE,props:{},variant:"source",valueType:"series"},Ya={[Zn.TYPE]:Zn,[Un.TYPE]:Un,[$n.TYPE]:$n,[Bn.TYPE]:Bn,[Fn.TYPE]:Fn,[Hn.TYPE]:Hn,[jn.TYPE]:jn,[qn.TYPE]:qn,[Wn.TYPE]:Wn};class no{type="noop";create(e){const t=Ya[e.type];return t==null?null:new t}}const Na=h.z.instanceof(ArrayBuffer),pt=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(Na).optional()}),he=pt.extend({variant:h.z.literal("source")}),mt=pt.extend({variant:h.z.literal("sink")}),so=pt.extend({variant:h.z.literal("source-transformer")}),ro=pt.extend({variant:h.z.literal("sink-transformer")}),At=he.extend({valueType:h.z.literal("series")}),Rs=he.extend({valueType:h.z.literal("boolean")}),hn=mt.extend({valueType:h.z.literal("boolean")}),Za=ro.extend({valueType:h.z.literal("boolean")}),Ua=so.extend({valueType:h.z.literal("boolean")}),Ps=he.extend({valueType:h.z.literal("number")}),oo=mt.extend({valueType:h.z.literal("number")}),dn=he.extend({valueType:h.z.literal("color")}),Ls=he.extend({valueType:h.z.literal("status")}),fn=he.extend({valueType:h.z.literal("string")}),io=mt.extend({valueType:h.z.literal("string")});let pn=class extends r.observe.BaseObserver{props_=void 0;uProps_=void 0;constructor(e){super(),this.uProps_=e}get props(){if(this.props_==null){const e=this.schema.safeParse(this.uProps_);if(e.success)this.props_=e.data;else throw new x.ValidationError(`[BaseTelem] - expected props to be valid, but found the following errors:
|
|
2
|
-
${e.error.message}`)}return this.props_}cleanup(){}};class W extends pn{}class mn extends pn{}class Se extends W{source_=void 0;get source(){if(this.source_==null)throw new x.ValidationError("[UnarySourceTransformer] - expected source to exist, but none was found.");return this.source_}value(){return this.transform(this.source.value())}onChange(e){return this.source.onChange(()=>{this.shouldNotify(this.source.value())&&e()})}setSources(e){this.source_=Object.values(e)[0]}shouldNotify(e){return!0}}class ao extends W{sources={};value(){const e=Object.fromEntries(Object.entries(this.sources).map(([t,s])=>[t,s.value()]));return this.transform(e)}setSources(e){this.sources={...this.sources,...e}}}class lo extends pn{sinks={};get sink(){const[e]=Object.values(this.sinks);if(e==null)throw new x.ValidationError("[UnarySinkTransformer] - expected sink to exist, but none was found.");return e}set(...e){return this.sink.set(...this.transform(...e))}setSinks(e){this.sinks={...this.sinks,...e}}}const ks=h.z.object({from:h.z.string(),to:h.z.string()}),_s=h.z.object({connections:h.z.array(ks),outlet:h.z.string(),segments:h.z.record(h.z.string(),he)});class Os{type="pipeline";factory;constructor(e){this.factory=e}create(e){switch(e.type){case Dt.TYPE:return new Dt(e.props,this.factory);case It.TYPE:return new It(e.props,this.factory);default:return null}}}class Dt extends W{static TYPE="source-pipeline";schema=_s;sources={};get outlet(){const{outlet:e}=this.props,t=this.sources[e];if(t==null)throw new x.ValidationError(`[SourcePipeline] - expected source to exist at outlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:s,segments:o}=this.props;Object.entries(o).forEach(([i,a])=>{const l=t.create(a);l!=null&&(this.sources[i]=l)}),s.forEach(({from:i,to:a})=>{const l=this.sources[i],u=this.sources[a];l==null||u==null||"setSources"in u&&u.setSources({[i]:l})})}value(){return this.outlet.value()}onChange(e){return this.outlet.onChange(e)}cleanup(){Object.values(this.sources).forEach(e=>e.cleanup?.())}}const co=(n,e)=>({variant:"source",props:e,type:Dt.TYPE,valueType:n}),Ms=h.z.object({connections:h.z.array(ks),inlet:h.z.string(),segments:h.z.record(h.z.string(),mt)});class It extends mn{static TYPE="sink-pipeline";schema=Ms;sinks={};get inlet(){const{inlet:e}=this.props,t=this.sinks[e];if(t==null)throw new x.ValidationError(`[SinkPipeline] - expected source to exist at inlet '${e}', but none was found.`);return t}constructor(e,t){super(e);const{connections:s,segments:o}=this.props;Object.entries(o).forEach(([i,a])=>{const l=t.create(a);l!=null&&(this.sinks[i]=l)}),s.forEach(({from:i,to:a})=>{const l=this.sinks[i],u=this.sinks[a];l==null||u==null||"setSinks"in l&&l.setSinks({[a]:u})})}set(...e){return this.inlet.set(...e)}cleanup(){Object.values(this.sinks).forEach(e=>e.cleanup?.())}}const uo=(n,e)=>({variant:"sink",props:e,type:It.TYPE,valueType:n}),As=h.z.object({channel:h.z.number().or(h.z.string())});class zt extends W{static TYPE="stream-channel-value";schema=As;client;removeStreamHandler=null;leadingBuffer=null;valid=!1;onStatusChange;constructor(e,t,s){super(t),this.client=e,this.onStatusChange=s?.onStatusChange}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}cleanup(){this.removeStreamHandler?.(),this.valid=!1,this.leadingBuffer?.release(),this.leadingBuffer=null,this.removeStreamHandler=null}value(){return r.primitive.isZero(this.props.channel)?NaN:(this.valid||this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0?NaN:this.leadingBuffer.at(-1,!0))}async read(){try{this.valid=!0,this.removeStreamHandler?.();const e=await this.client.retrieveChannel(this.props.channel),t=s=>{const o=s.get(e.key);if(o==null)return;const i=o.series.at(-1);i!=null&&(i.acquire(),this.leadingBuffer?.release(),this.leadingBuffer=i),this.notify()};this.removeStreamHandler=await this.client.stream(t,[e.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to stream channel value"))}}}const ho=async(n,e,t)=>{const s=await n.retrieveChannel(e),o=x.channel.isCalculated(s);if(!t||s.isIndex)return{key:s.key,dataType:s.dataType,virtual:s.virtual,isCalculated:o};if(s.virtual&&!o)throw new x.NotFoundError("cannot use virtual channels as a data source");return{key:s.index,dataType:r.DataType.TIMESTAMP,virtual:!1,isCalculated:o}},Ba=h.z.object({timeRange:r.TimeRange.z,channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().default(!1)});class Yt extends W{static TYPE="series-source";client;schema=Ba;data=new r.MultiSeries;valid=!1;channel=null;onStatusChange;constructor(e,t,s){super(t),this.client=e,this.onStatusChange=s?.onStatusChange}cleanup(){this.data.release(),this.valid=!1,this.channel=null}value(){const{channel:e,timeRange:t}=this.props;if(t.span.isZero||e===0)return[r.bounds.ZERO,this.data];this.valid||this.read();const{channel:s,data:o}=this;if(s==null)return[r.bounds.ZERO,this.data];let i=o.bounds;return s.dataType.equals(r.DataType.TIMESTAMP)&&(i=r.bounds.min([i,t.numericBounds])),[i,o]}async read(){try{this.valid=!0;const{timeRange:e,channel:t,useIndexOfChannel:s}=this.props;this.channel=await ho(this.client,t,s);const o=await this.client.read(e,this.channel.key);o.acquire(),this.data=o,this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to read channel data"))}}}const Fa=h.z.object({channel:h.z.number().or(h.z.string()),useIndexOfChannel:h.z.boolean().default(!1),timeSpan:r.TimeSpan.z,keepFor:r.TimeSpan.z.optional()});class Nt extends W{static TYPE="dynamic-series-source";client;data=new r.MultiSeries([]);now;onStatusChange;channel=null;stopStreaming;valid=!1;schema=Fa;constructor(e,t,s,o=()=>r.TimeStamp.now()){super(t),this.client=e,this.now=o,this.onStatusChange=s?.onStatusChange}value(){const{channel:e,timeSpan:t}=this.props;if(e===0)return[r.bounds.ZERO,this.data];this.valid||this.read();const{data:s,channel:o}=this,i=this.now();if(o!=null&&o.dataType.isVariable)return[r.bounds.ZERO,this.data];const a=s.series.filter(u=>u.timeRange.end.after(i.sub(t))).map(u=>u.bounds),l=r.bounds.max(a);return o!=null&&o.dataType.equals(r.DataType.TIMESTAMP)&&(l.lower=Math.max(l.lower,l.upper-Number(t.valueOf()))),[l,this.data]}async read(){try{this.valid=!0;const{channel:e,useIndexOfChannel:t,timeSpan:s}=this.props;this.channel=await ho(this.client,e,t);const o=this.now().spanRange(-s);if(!this.channel.virtual||this.channel.isCalculated)try{const a=await this.client.read(o,this.channel.key);a.acquire(),this.data.push(a)}catch(a){if(a instanceof Error&&(a.message.includes("cannot open iterator on virtual channel")||a.message.includes("cannot read from free channel")))console.warn("failed to read calculated channel data",a);else throw a}this.stopStreaming?.();const i=a=>{if(this.channel==null)return;const l=a.get(this.channel.key);l!=null&&(l.acquire(),this.data.push(l),this.notify(),this.gcOutOfRangeData())};this.stopStreaming=await this.client.stream(i,[this.channel.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(r.status.fromException(e,"failed to stream channel data"))}}gcOutOfRangeData(){const e=this.now().sub(this.props.keepFor??this.props.timeSpan),t=this.data.series.findIndex(s=>s.timeRange.end.before(e));t!==-1&&(this.data.series.splice(t,1).forEach(s=>s.release()),this.gcOutOfRangeData())}cleanup(){this.stopStreaming?.(),this.stopStreaming=void 0,this.data.release(),this.valid=!1}}const $a={[Yt.TYPE]:Yt,[Nt.TYPE]:Nt,[zt.TYPE]:zt};class fo{type="remote";client;constructor(e){this.client=e}create(e,t){const s=$a[e.type];return s==null?null:new s(this.client,e.props,t)}}const po=n=>({type:Yt.TYPE,props:n,variant:"source",valueType:"series"}),mo=n=>({type:Nt.TYPE,props:n,variant:"source",valueType:"series"}),go=n=>({type:zt.TYPE,props:n,variant:"source",valueType:"number"});class yo{type="static";create(e){switch(e.type){case Vn.TYPE:return new Vn(e.props);case Zt.TYPE:return new Zt(e.props);case Ut.TYPE:return new Ut(e.props);case Bt.TYPE:return new Bt(e.props);case Ft.TYPE:return new Ft(e.props);default:return null}}}const Ds=h.z.object({data:h.z.array(r.typedArrayZ),offsets:h.z.array(h.z.number()).default([])});class Vn extends W{data;schema=Ds;static TYPE="static-series";constructor(e){super(e),this.data=this.props.data.map((t,s)=>new r.Series({data:t,dataType:r.DataType.FLOAT32,timeRange:r.TimeRange.ZERO,sampleOffset:this.props.offsets[s]??0}))}value(){return[r.bounds.max(this.data.map(t=>t.bounds)),this.data]}}const xo=Ds.extend({rate:r.Rate.z,yOffset:h.z.number().default(0),scroll:h.z.number().default(0),startPosition:h.z.number().default(0),scrollBounds:h.z.boolean().default(!1)});class Zt extends W{static TYPE="iterative-series";schema=xo;position;interval;data;constructor(e){super(e),this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((t,s)=>new r.Series({data:t,dataType:r.DataType.FLOAT32,timeRange:r.TimeRange.ZERO,sampleOffset:this.props.offsets[s]??0}))}value(){const e=this.data.map(s=>s.slice(0,this.position));if(this.props.scrollBounds){const s=e[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],o=e[0].data[this.position-1];return[{lower:Number(s),upper:Number(o)},new r.MultiSeries(e)]}return[r.bounds.max(e.map(s=>s.bounds)),new r.MultiSeries(e)]}start(e){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{this.notify?.(),this.position++},e.period.milliseconds)}cleanup(){clearInterval(this.interval),this.interval=void 0}}const bo=h.z.number();class Ut extends W{static TYPE="static-numeric";schema=bo;value(){return this.props}}const So=h.z.string();class Bt extends W{static TYPE="static-string";schema=So;value(){return this.props}}const To=r.color.crudeZ;class Ft extends W{static TYPE="static-color";schema=To;value(){return r.color.construct(this.props)}}const qa=n=>({type:Vn.TYPE,props:n,variant:"source",valueType:"series"}),Ha=n=>({type:Zt.TYPE,props:n,variant:"source",valueType:"series"}),ja=n=>({type:Ut.TYPE,props:n,variant:"source",valueType:"number"}),Wa=n=>({type:Bt.TYPE,props:n,variant:"source",valueType:"string"}),Va=n=>({type:Ft.TYPE,props:n,variant:"source",valueType:"color"});class vo{type="transformer";create(e){switch(e.type){case Me.TYPE:return new Me(e.props);case Ae.TYPE:return new Ae(e.props);case De.TYPE:return new De(e.props);case Ie.TYPE:return new Ie(e.props);case ze.TYPE:return new ze(e.props);case $t.TYPE:return new $t(e.props);case Ye.TYPE:return new Ye(e.props);case Ne.TYPE:return new Ne(e.props)}return null}}const Xa=h.z.object({truthy:h.z.number().default(1),falsy:h.z.number().default(0)}),wo=n=>({props:n,type:Me.TYPE,variant:"sink",valueType:"boolean"});class Me extends lo{static TYPE="boolean-numeric-converter-sink";static propsZ=Xa;schema=Me.propsZ;transform(...e){return e.map(t=>t?this.props.truthy:this.props.falsy)}}const Is=h.z.object({trueBound:r.bounds.bounds}),Eo=n=>({props:n,type:Ae.TYPE,variant:"source",valueType:"boolean"});class Ae extends Se{static TYPE="boolean-source";static propsZ=Is;schema=Ae.propsZ;curr=null;shouldNotify(e){const t=r.bounds.contains(this.props.trueBound,e)!==this.curr;return this.curr=r.bounds.contains(this.props.trueBound,e),t}transform(e){return this.curr=r.bounds.contains(this.props.trueBound,e),this.curr}}const Co=h.z.object({});class De extends ao{static TYPE="mean";static propsZ=Co;schema=De.propsZ;transform(e){return Object.values(e).reduce((t,s)=>t+s,0)/Object.keys(e).length}}const Ga=n=>({props:n,type:De.TYPE,variant:"source",valueType:"boolean"}),Ro=h.z.object({trueVariant:r.status.variantZ.default("success")});class Ie extends Se{static TYPE="boolean-status";static propsZ=Ro;schema=Ie.propsZ;transform(e){return e.variant===this.props.trueVariant}}const Ka=n=>({props:n,type:Ie.TYPE,variant:"source",valueType:"boolean"}),zs=h.z.object({precision:h.z.number().default(2),prefix:h.z.string().default(""),suffix:h.z.string().default(""),notation:r.notation.notationZ.default("standard")});class ze extends Se{static TYPE="stringify-number";static propsZ=zs;schema=ze.propsZ;transform(e){if(isNaN(e))return"";const{precision:t,prefix:s,suffix:o,notation:i}=this.props;return`${s}${r.notation.stringifyNumber(e,t,i)}${o}`}}const Po=n=>({props:n,type:ze.TYPE,variant:"source",valueType:"string"}),Ys=h.z.object({windowSize:h.z.number().default(5)});class $t extends Se{static TYPE="rolling-average";static propsZ=Co;schema=Ys;values=[];transform(e){return this.props.windowSize<2||isNaN(e)?e:this.values.reduce((t,s)=>t+s,0)/this.values.length}shouldNotify(e){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(e),this.values.length===this.props.windowSize)}}const Lo=n=>({props:n,type:$t.TYPE,variant:"source",valueType:"number"}),ko=h.z.object({gradient:r.color.gradientZ});class Ye extends Se{static TYPE="color-gradient";static propsZ=ko;schema=Ye.propsZ;transform(e){return r.color.fromGradient(this.props.gradient,e)}}const _o=n=>({props:n,type:Ye.TYPE,variant:"source",valueType:"color"}),Oo=h.z.object({scale:r.scale.transform});class Ne extends Se{static TYPE="scale-number";static propsZ=Oo;schema=Ne.propsZ;transform(e){if(isNaN(e))return e;const{offset:t,scale:s}=this.props.scale;return e*s+t}}const Mo=n=>({props:n,type:Ne.TYPE,variant:"source",valueType:"number"}),Ns=h.z.enum(["average","decimate"]),Qa=h.z.object({mode:Ns,windowSize:h.z.number().default(5)}),Ja=n=>({props:n,type:rt.TYPE,variant:"source",valueType:"number"}),Ao=(n,e,t)=>{const s=e.length*t;for(let o=s;o<n.length;o+=t){const i=n.sub(o,o+1);i!==void 0&&e.write(i)}},el=(n,e,t)=>{const s=e.length*t;for(let o=s;o<n.length&&!(o+t>n.length);o+=t){const i=Math.min(o+t,n.length);let a=0,l=0;for(let u=o;u<i;u++){const c=n.at(u);c!==void 0&&typeof c=="number"&&(a+=c,l++)}l>0&&e.write(new r.Series({data:[a/l],dataType:n.dataType}))}},tl={decimate:Ao,average:el};class rt{static TYPE="series-downsampler";_downsample=null;cache=new r.MultiSeries;props;constructor(e){this.props=e}downsample(e){return this._downsample==null&&(e.series[0].sampleOffset!==0?this._downsample=Ao:this._downsample=tl[this.props.mode]),this._downsample}transform(e){if(this.props.mode==="decimate"||this.props.windowSize<=1)return e;if(e.series.length===0)return this.cache;for(;this.cache.series.length>0&&!this.cache.series[0].key.startsWith(e.series[0].key);)this.cache.series.shift();return e.series.forEach((t,s)=>{let o=this.cache.series.at(s);if(o==null){const i=Math.ceil(t.capacity/this.props.windowSize);o=r.Series.alloc({key:t.key+r.id.create(),dataType:t.dataType,capacity:i,alignment:t.alignment,alignmentMultiple:BigInt(this.props.windowSize),sampleOffset:t.sampleOffset,timeRange:t.timeRange}),this.cache.push(o)}else if(!o.key.startsWith(t.key))throw new x.UnexpectedError(`[SeriesDownsampler] - expected series with key ${t.key} to be in cache, but found ${o.key}`);this.downsample(e)(t,o,this.props.windowSize)}),this.cache}}const nl=n=>({props:n,type:rt.TYPE,variant:"source",valueType:"series"});class Zs{factories;type="compound";constructor(e){this.factories=e}add(e){this.factories=[...this.factories.filter(t=>t.type!==e.type),e]}create(e,t){for(const s of this.factories){const o=s.create(e,t);if(o!=null)return o}return null}}const Do=n=>{const e=[new vo,new yo,new no],t=new Zs(e);return n!=null&&t.add(new fo(n)),t.add(new Os(t)),t};let Io=class zo{factory;key;parent;constructor(e,t){this.factory=e,this.key=r.id.create(),this.parent=t}child(e,t){const s=new Zs([...this.factory.factories,...r.array.toArray(e)]);return s.add(new Os(s)),new zo(s,t)}create(e,t){const s=this.factory.create(e,t);if(s==null)throw new x.UnexpectedError(`Telemetry service could not find a source for type ${e.type}`);return s}};const gt="pluto-telem-context",gn=n=>n.get(gt),Yo=(n,e)=>n.set(gt,e),No=(n,e,t)=>{const s=gn(n);if(s!=null&&t!=null&&s.key===t?.parent?.key)return t;const o=s.child(e,s);return n.set(gt,o),o};class Zo{spec;wrapped;prevProv;constructor(e,t,s){this.wrapped=e,this.spec=s,this.prevProv=t}shouldUpdate(e,t){return this.prevProv.key!==e.key||!r.deep.equal(this.spec,t)}}class fr extends Zo{value(){return this.wrapped.value()}cleanup(){this.wrapped.cleanup?.()}onChange(e){return this.wrapped.onChange(e)}}class pr extends Zo{set(...e){this.wrapped.set(...e)}cleanup(){this.wrapped.cleanup?.()}}const U=(n,e,t,s)=>{const o=gn(n);if(t instanceof fr){if(!t.shouldUpdate(o,e))return t;t.cleanup?.()}return new fr(o.create(e,s),o,e)},je=(n,e,t,s)=>{const o=gn(n);if(t instanceof pr){if(!t.shouldUpdate(o,e))return t;t.cleanup?.()}return new pr(o.create(e,s),o,e)},Uo=(n,e)=>n.dataType.isVariable||n.dataType.equals(r.DataType.UINT8)?n:(e==null&&n.dataType.equals(r.DataType.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(r.DataType.FLOAT32,e)),sl=n=>n.isVariable||n.equals(r.DataType.UINT8)?n:r.DataType.FLOAT32,Bo=()=>({purgedSeries:0,purgedBytes:r.Size.bytes(0)}),Fo={instrumentation:on.alamos.NOOP,staleEntryThreshold:r.TimeSpan.seconds(20)};class rl{data=[];props;constructor(e){this.props={...Fo,...e}}write(e){e.length!==0&&(e.series.forEach(t=>this.writeOne(Uo(t))),this.checkIntegrity(e))}dirtyRead(e){const t=this.data.filter(({data:a})=>a.timeRange.overlapsWith(e)).map(({data:a})=>a);if(t.length===0)return{series:new r.MultiSeries([]),gaps:[e]};const s=t.map((a,l)=>l===0?r.TimeRange.ZERO:new r.TimeRange(t[l-1].timeRange.end,a.timeRange.start)).filter(a=>!a.span.isZero&&a.isValid),o=new r.TimeRange(e.start,t[0].timeRange.start),i=new r.TimeRange(t[t.length-1].timeRange.end,e.end);return o.isValid&&!o.span.isZero&&s.unshift(o),i.isValid&&!i.span.isZero&&s.push(i),{series:new r.MultiSeries(t),gaps:s}}gc(){const{staleEntryThreshold:e}=this.props,t=Bo(),s=this.data.filter(o=>{const i=o.data.refCount>0||r.TimeStamp.since(o.addedAt).lessThan(e);return i||(t.purgedBytes=t.purgedBytes.add(o.data.byteCapacity)),i});return t.purgedSeries=this.data.length-s.length,this.data=s,t}close(){this.data=[]}writeOne(e){const{instrumentation:{L:t}}=this.props;if(e.length===0)return;const s=r.bounds.buildInsertionPlan(this.data.map(u=>u.data.alignmentBounds),e.alignmentBounds);if(s===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(u=>u.data.digest)});const{removeBefore:o,removeAfter:i,insertInto:a,deleteInBetween:l}=s;e=e.slice(o,e.data.length-i),e.length!==0&&this.data.splice(a,l,{data:e,addedAt:r.TimeStamp.now()})}checkIntegrity(e){const{instrumentation:{L:t}}=this.props,s=this.data.map(i=>i.data.alignmentBounds);if(s.some((i,a)=>s.some((l,u)=>a===u?!1:r.bounds.overlapsWith(i,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.series.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const ol=100,il=1e6,al=1e4,ll=100,cl=40;class ul{props;counter=0;curr;avgRate=0;timeOfLastWrite;totalWrites=0;now=()=>r.TimeStamp.now();constructor(e){this.props=e,this.curr=null,e.now!=null&&(this.now=e.now),this.timeOfLastWrite=this.now()}get length(){return this.curr?.length??0}get leadingBuffer(){return this.curr}write(e){const t=e.series.flatMap(s=>this._write(s));return{flushed:new r.MultiSeries(t.flatMap(s=>s.flushed.series)),allocated:new r.MultiSeries(t.flatMap(s=>s.allocated.series))}}allocate(e,t,s){this.counter++;const o=this.props.dataType.isVariable,i=this.props.dataType.equals(r.DataType.TIMESTAMP);return r.Series.alloc({capacity:o?e*cl:e,dataType:sl(this.props.dataType),timeRange:s.range(r.TimeStamp.MAX),sampleOffset:i?s.valueOf():0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),s={flushed:new r.MultiSeries([]),allocated:new r.MultiSeries([])};if(this.curr==null)this.curr=this.allocate(t,e.alignment,this.now()),s.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-e.alignment))>1){const u=this.now();this.curr.timeRange.end=u,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,u),s.allocated.push(this.curr)}const o=Uo(e,this.curr.sampleOffset),i=this.curr.write(o);if(i===e.length)return this.updateAvgRate(e),s;const a=this.now();this.curr.timeRange.end=a,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment+BigInt(i),a),s.allocated.push(this.curr);const l=this._write(e.slice(i));return s.flushed.push(l.flushed),s.allocated.push(l.allocated),s}updateAvgRate(e){if(typeof this.props.dynamicBufferSize=="number")return;const t=e.length/this.now().span(this.timeOfLastWrite).seconds;this.totalWrites>0&&isFinite(t)&&t>0&&(this.avgRate=(this.avgRate*(this.totalWrites-1)+t)/this.totalWrites),this.totalWrites++,this.timeOfLastWrite=this.now()}nextBufferSize(){const{dynamicBufferSize:e}=this.props;if(typeof e=="number")return e;if(this.totalWrites<ll)return al;const t=r.math.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,il),ol))}close(){this.curr=null}}class hl{channel;closed=!1;ins;static;dynamic;constructor(e){this.channel=e.channel,this.ins=e.instrumentation??on.alamos.NOOP,this.static=new rl(e),this.dynamic=new ul({dynamicBufferSize:e.dynamicBufferSize,dataType:this.channel.dataType})}writeDynamic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted dynamic write to a closed cache for channel ${this.channel.name}`),new r.MultiSeries([]);const{flushed:t,allocated:s}=this.dynamic.write(e);return t.length>0&&this.static.write(t),s}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(e)}read(e){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:new r.MultiSeries([]),gaps:[e]}):this.static.dirtyRead(e)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:r.Size.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const dl=x.TimeSpan.seconds(60);class fl{props;cache=new Map;gcInterval;constructor(e){this.props={dynamicBufferSize:dl,gcInterval:x.TimeSpan.seconds(30),...Fo,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:s,dynamicBufferSize:o}=this.props,i=[];for(const l of e)this.cache.has(l)||i.push(l);if(i.length===0)return;(await s.retrieve(i)).forEach(l=>{if(this.cache.has(l.key))return;const u=new hl({channel:l,dynamicBufferSize:o,instrumentation:t.child(`cache-${l.name}-${l.key}`)});this.cache.set(l.key,u)})}get(e){const t=this.cache.get(e);if(t!=null)return t;throw new x.UnexpectedError(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=Bo();this.cache.forEach(s=>{const o=s.gc();t.purgedSeries+=o.purgedSeries,t.purgedBytes=t.purgedBytes.add(o.purgedBytes)}),e.info("garbage collection complete",{purgedSeries:t.purgedSeries,purgedBytes:t.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(e=>e.close()),this.cache.clear()}}class pl{args;debouncedRead;mu=r.sync.newMutex({requests:new Set,closed:!1});constructor(e){this.args={...e,instrumentation:e.instrumentation??on.alamos.NOOP,batchDebounce:e.batchDebounce??r.TimeSpan.milliseconds(50),overlapThreshold:e.overlapThreshold??r.TimeSpan.milliseconds(5)};const t=this.args.batchDebounce.milliseconds;this.debouncedRead=r.debounce(()=>{this.batchRead()},t)}async read(e,t){const{cache:s}=this.args;await s.populateMissing([t]);const o=s.get(t),{series:i,gaps:a}=o.read(e);if(a.length===0)return i;const{mu:l}=this;return await new Promise((u,c)=>{l.runExclusive(async()=>{l.closed||l.requests.add({channel:t,gaps:a,resolve:u,reject:c})}),this.debouncedRead()}),o.read(e).series}async batchRead(){const{readRemote:e,cache:t,overlapThreshold:s}=this.args,{mu:o}=this;await o.runExclusive(async()=>{const i=a=>o.requests.forEach(({resolve:l,reject:u})=>a==null?l():u(a));try{if(o.closed)return i();const a=[];o.requests.forEach(({channel:l,gaps:u})=>u.forEach(c=>{const d=a.find(f=>f.gap.equals(c,s));d==null?a.push({gap:c,channels:new Set([l])}):(d.channels.add(l),d.gap=r.TimeRange.max(d.gap,c))})),await Promise.all(a.map(async({gap:l,channels:u})=>{const c=await e(l,Array.from(u));u.forEach(d=>t.get(d).writeStatic(c.get(d)))})),i()}catch(a){i(a)}finally{o.requests.clear()}})}async close(){await this.mu.runExclusive(async()=>{this.mu.closed=!0})}}const ml=new Error("request for lock canceled");var gl=function(n,e,t,s){function o(i){return i instanceof t?i:new t(function(a){a(i)})}return new(t||(t=Promise))(function(i,a){function l(d){try{c(s.next(d))}catch(f){a(f)}}function u(d){try{c(s.throw(d))}catch(f){a(f)}}function c(d){d.done?i(d.value):o(d.value).then(l,u)}c((s=s.apply(n,e||[])).next())})};class yl{constructor(e,t=ml){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,o)=>{const i={resolve:s,reject:o,weight:e,priority:t},a=$o(this._queue,l=>t<=l.priority);a===-1&&e<=this._value?this._dispatchItem(i):this._queue.splice(a+1,0,i)})}runExclusive(e){return gl(this,arguments,void 0,function*(t,s=1,o=0){const[i,a]=yield this.acquire(s,o);try{return yield t(i)}finally{a()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),xl(this._weightedWaiters[e-1],{resolve:s,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(s=>s.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const s=this._weightedWaiters[t-1];if(!s)continue;const o=s.findIndex(i=>i.priority<=e);(o===-1?s:s.splice(0,o)).forEach((i=>i.resolve()))}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function xl(n,e){const t=$o(n,s=>e.priority<=s.priority);n.splice(t+1,0,e)}function $o(n,e){for(let t=n.length-1;t>=0;t--)if(e(n[t]))return t;return-1}var bl=function(n,e,t,s){function o(i){return i instanceof t?i:new t(function(a){a(i)})}return new(t||(t=Promise))(function(i,a){function l(d){try{c(s.next(d))}catch(f){a(f)}}function u(d){try{c(s.throw(d))}catch(f){a(f)}}function c(d){d.done?i(d.value):o(d.value).then(l,u)}c((s=s.apply(n,e||[])).next())})};class Sl{constructor(e){this._semaphore=new yl(1,e)}acquire(){return bl(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 Tl=r.TimeSpan.milliseconds(100).milliseconds,vl=r.Rate.hz(60).valueOf();class wl{props;mu=new Sl;listeners=new Map;debouncedUpdateStreamer;streamerRunLoop=null;streamer=null;closed=!1;constructor(e){this.props={instrumentation:on.alamos.NOOP,...e,streamUpdateDelay:new r.TimeSpan(e.streamUpdateDelay??r.TimeSpan.seconds(5))},this.debouncedUpdateStreamer=r.debounce(()=>{this.updateStreamer()},Tl)}async stream(e,t){const{cache:s,instrumentation:o}=this.props;return this.closed?()=>{}:(await s.populateMissing(t),await this.mu.runExclusive(async()=>{o.L.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:new Set(t)});const i=new Map(t.map(a=>{const l=s.get(a);return[a,new r.MultiSeries(r.array.toArray(l.leadingBuffer))]}));return e(i),this.debouncedUpdateStreamer(),()=>this.removeStreamHandler(e)}))}removeStreamHandler(e){const{instrumentation:t}=this.props;this.mu.runExclusive(()=>{const s=this.listeners.get(e);s!=null&&(s.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.L.debug("removing stream handler"),this.listeners.delete(e))return this.debouncedUpdateStreamer();t.L.warn("attempted to remove non-existent stream handler")})},this.props.streamUpdateDelay.milliseconds)}async updateStreamer(){if(this.closed)return;const{instrumentation:e}=this.props;try{const t=new Set;if(this.listeners.forEach(i=>i.keys.forEach(a=>t.add(a))),t.size===0){e.L.info("no keys to stream, closing streamer"),this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.L.info("streamer closed successfully");return}const s=Array.from(t);if(r.compare.primitiveArrays(s,this.streamer?.keys??[])===r.compare.EQUAL){e.L.debug("streamer keys unchanged",{keys:s});return}this.streamer==null&&(e.L.info("creating new streamer",{keys:s}),this.streamer=await this.props.openStreamer({channels:s,throttleRate:vl}),this.streamerRunLoop=this.runStreamer(this.streamer)),e.L.debug("updating streamer",{prev:this.streamer.keys,next:s}),await this.streamer.update(s)}catch(t){throw e.L.error("failed to update streamer",{error:t}),t}}async runStreamer(e){const{cache:t,instrumentation:s}=this.props;try{for await(const o of e){const i=new Map;for(const a of o.keys){const l=o.get(a),c=t.get(a).writeDynamic(l);i.set(a,c)}i.size!==0&&this.listeners.forEach(({valid:a},l)=>a&&l(i))}}catch(o){throw s.L.error("streamer run loop failed",{error:o},!0),o}}async close(){const{instrumentation:e}=this.props;try{this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop}catch(t){e.L.error("failed to close streamer",{error:t})}this.closed=!0}}class El{async retrieveChannel(){throw new x.NotFoundError("NoopClient does not support retrieving channels")}async read(){return new r.MultiSeries([])}async stream(){return async()=>{}}async close(){}}class Cl{ins;cache;reader;streamer;channelRetriever;constructor({instrumentation:e,core:t}){this.ins=e,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new fl({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new pl({cache:this.cache,readRemote:t.read.bind(t),instrumentation:this.ins.child("reader")}),this.streamer=new wl({cache:this.cache,openStreamer:async s=>x.framer.HardenedStreamer.open(t.openStreamer.bind(t),s),instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new x.QueryError(`channel ${e} not found`);return t[0]}async read(e,t){return await this.reader.read(e,t)}async stream(e,t){return await this.streamer.stream(e,t)}async close(){this.ins.L.info("closing client"),await this.streamer.close(),await this.reader.close(),this.cache.close()}}const Us=h.z.object({}),yn="telem.Provider",qo=n=>{class e extends w.Composite{static TYPE=yn;static stateZ=Us;schema=e.stateZ;prevCore=null;client=null;afterUpdate(s){const{internal:o}=this,i=He(s),a=w.useErrorHandler(s);if(o.instrumentation=I.useInstrumentation(s,"telem").child("provider"),!(i!==this.prevCore||!s.wasSetPreviously(gt)))return;this.prevCore=i,this.client!=null&&a(async()=>{if(this.client==null)throw new Error("no client to close");await this.client.close()},"failed to close client"),this.client=i==null?new El:new Cl({core:i,instrumentation:o.instrumentation});const u=n(this.client),c=new Io(u);Yo(s,c)}}return e},Ho=qo(Do),jo={[yn]:Ho},Rl=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:mn,AbstractSource:W,Base:pn,BooleanStatus:Ie,CONTEXT_KEY:gt,ChannelData:Yt,ColorGradient:Ye,CompoundFactory:Zs,Context:Io,FixedColorSource:Ft,FixedNumber:Ut,FixedString:Bt,IterativeSeries:Zt,Mean:De,MultiSourceTransformer:ao,NoopFactory:no,PROVIDER_TYPE:yn,PipelineFactory:Os,Provider:Ho,REGISTRY:jo,RemoteFactory:fo,RollingAverage:$t,ScaleNumber:Ne,SeriesDownsampler:rt,SetPoint:Me,SinkPipeline:It,SourcePipeline:Dt,StaticFactory:yo,StreamChannelData:Nt,StreamChannelValue:zt,StringifyNumber:ze,TransformerFactory:vo,UnarySinkTransformer:lo,UnarySourceTransformer:Se,WithinBounds:Ae,booleanSinkSpecZ:hn,booleanSinkTransformerSpecZ:Za,booleanSourceSpecZ:Rs,booleanSourceTransformerSpecZ:Ua,booleanStatus:Ka,booleanStatusProps:Ro,channelData:po,colorGradient:_o,colorGradientProps:ko,colorSourceSpecZ:dn,connectionZ:ks,createFactory:Do,createProvider:qo,downsampleMode:Ja,downsampleModeProps:Qa,downsampleModeZ:Ns,fixedArray:qa,fixedColor:Va,fixedColorSourcePropsZ:To,fixedNumber:ja,fixedNumberPropsZ:bo,fixedSeriesPropsZ:Ds,fixedString:Wa,fixedStringPropsZ:So,iterativeArray:Ha,iterativeSeriesPropsZ:xo,mean:Ga,noopBooleanSinkSpec:un,noopBooleanSourceSpec:vs,noopColorSourceSpec:ft,noopNumericSinkSpec:Jr,noopNumericSourceSpec:ws,noopSeriesSourceSpec:to,noopStatusSourceSpec:Cs,noopStringSinkSpec:eo,noopStringSourceSpec:Es,numberSinkSpecZ:oo,numberSourceSpecZ:Ps,providerStateZ:Us,rollingAverage:Lo,rollingAverageProps:Ys,scaleNumber:Mo,scaleNumberProps:Oo,seriesDownsampler:nl,seriesSourceSpecZ:At,setContext:Yo,setpoint:wo,sinkPipeline:uo,sinkPipelinePropsZ:Ms,sinkSpecZ:mt,sinkTransformerSpecZ:ro,sourcePipeline:co,sourcePipelinePropsZ:_s,sourceSpecZ:he,sourceTransformerSpecZ:so,specZ:pt,statusSourceSpecZ:Ls,streamChannelData:mo,streamChannelValue:go,streamChannelValuePropsZ:As,stringSinkSpecZ:io,stringSourceSpecZ:fn,stringifyNumber:Po,stringifyNumberProps:zs,useChildContext:No,useContext:gn,useSink:je,useSource:U,withinBounds:Eo,withinBoundsProps:Is},Symbol.toStringTag,{value:"Module"})),mr=`#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
|
-
`,Pl=`#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
|
-
`,Ll=`#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
|
-
`,Wo=h.z.object({x:At,y:At,label:h.z.string().optional(),color:r.color.colorZ,strokeWidth:h.z.number().default(1),downsample:h.z.number().min(1).max(50).default(1),downsampleMode:Ns.default("decimate"),visible:h.z.boolean().default(!0)}),kl=(n,e,t)=>n===-1||e===-1||n>=t.series.length?NaN:Number(t.series[n].at(e)),_l=r.TimeSpan.milliseconds(2);r.xy.NAN,r.xy.NAN,r.color.ZERO,r.bounds.ZERO;const Ol=(n,e)=>e.equals(r.DataType.UINT8)?n.UNSIGNED_BYTE:n.FLOAT;class gr extends I.GLProgram{translationBufferCache=new Map;constructor(e,t,s){super(e,t,s),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:t}){return this.uniformColor("u_color",t),this.attrStrokeWidth(e)}bindScale(e,t){const s=r.xy.scale(e.scale,t.scale),o=r.xy.translate(r.xy.scale(t.scale,e.offset),t.offset);this.uniformXY("u_scale_aggregate",s),this.uniformXY("u_offset_aggregate",o)}draw({x:e,y:t,count:s,downsample:o,xOffset:i,yOffset:a},l,u,c){const{gl:d}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,o,i,u),this.bindAttrBuffer("y",t.glBuffer,o,a,c),d.drawArraysInstanced(d.LINE_STRIP,0,s/o,l)}bindAttrBuffer(e,t,s,o=0,i){const{gl:a}=this.renderCtx;a.bindBuffer(a.ARRAY_BUFFER,t);const l=a.getAttribLocation(this.prog,`a_${e}`),u=Ol(a,i),c=i.density.valueOf();i.equals(r.DataType.UINT8)?a.vertexAttribIPointer(l,1,u,c*s,c*o):a.vertexAttribPointer(l,1,u,!1,c*s,c*o),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:t}=this.renderCtx,s=`${this.renderCtx.aspect}:${e}`,o=this.translationBufferCache.get(s);if(o!=null)return t.bindBuffer(t.ARRAY_BUFFER,o.glBuffer),o;const i=t.createBuffer();if(i==null)throw new x.UnexpectedError("Failed to create buffer from WebGL context");const a=Al(this.renderCtx.aspect,e);t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,a,t.DYNAMIC_DRAW);const l={glBuffer:i,jsBuffer:a};return this.translationBufferCache.set(s,l),l}attrStrokeWidth(e){const{gl:t}=this.renderCtx,{jsBuffer:s}=this.getAndBindTranslationBuffer(e),o=t.getAttribLocation(this.prog,"a_translate");return t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(o),t.vertexAttribDivisor(o,1),s.length/2}}class _e{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new gr(e,Ll,mr),this.float32Program=new gr(e,Pl,mr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(r.DataType.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,t){const s=new _e(t);return e.set(_e.CONTEXT_KEY,s),s}static use(e){const t=e.get(_e.CONTEXT_KEY);if(t==null)throw new x.UnexpectedError("GLProgram not found");return t}}class qt extends w.Leaf{static TYPE="line";schema=Wo;afterUpdate(e){const{internal:t}=this,s={onStatusChange:w.useAdder(e)};t.xTelem=U(e,this.state.x,t.xTelem,s),t.yTelem=U(e,this.state.y,t.yTelem,s),t.instrumentation=I.useInstrumentation(e,"line"),t.lineCtx=_e.use(e),t.requestRender=ln(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 rt({mode:this.state.downsampleMode,windowSize:this.state.downsample}),t.yDownsampler=new rt({mode:this.state.downsampleMode,windowSize:this.state.downsample}))}afterDelete(){const{internal:e}=this;e.xTelem.cleanup?.(),e.yTelem.cleanup?.(),e.requestRender("layout")}xBounds(){return this.internal.xTelem.value()[0]}yBounds(){return this.internal.yTelem.value()[0]}findByXValue(e,t){const{xTelem:s,yTelem:o}=this.internal;let[,i]=s.value();i=this.internal.xDownsampler.transform(i);let[a,l]=[-1,-1];i.series.find((v,R)=>{const L=v.binarySearch(t),k=L>=0&&L<v.length;return k&&([a,l]=[L,R]),k});const{key:u}=this,{color:c,label:d}=this.state,f={key:u,color:c,label:d,position:{x:0,y:0},value:{x:NaN,y:NaN},bounds:{lower:0,upper:0}};if(a===-1||l===-1||!this.state.visible)return f;const p=i.series[l];f.value.x=kl(l,a,i);let[,g]=o.value();g=this.internal.yDownsampler.transform(g);const T=g.series.find(v=>r.bounds.contains(v.alignmentBounds,p.alignment+BigInt(a)));if(T==null)return f;const y=Number(T.alignment-p.alignment);return f.value.y=Number(T.at(a-y)),f.bounds={...T.bounds},f.position={x:e.dataToDecimalScale.x.pos(f.value.x),y:e.dataToDecimalScale.y.pos(f.value.y)},f}render(e){if(this.deleted||!this.state.visible)return;const{downsample:t}=this.state,{xTelem:s,yTelem:o,lineCtx:i,xDownsampler:a,yDownsampler:l}=this.internal,{dataToDecimalScale:u,exposure:c}=e;let[[,d],[,f]]=[s.value(),o.value()];if(d=a.transform(d),f=l.transform(f),d.updateGLBuffer(i.gl),f.updateGLBuffer(i.gl),d.length===0||f.length===0)return;const p=i.getProgram(f.dataType),g=Zl(d,f,c,t,this.state.downsampleMode,_l);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:t,scale:u.transform,props:e.region,ops:Ul(g)}));const T=p.setAsActive(),y=p.bindState(this.state),v=p.renderCtx.scaleRegion(e.region).transform;g.forEach(R=>{const L=Yl(u,R).transform;p.bindScale(L,v),p.draw(R,y,d.dataType,f.dataType)}),T()}}const Ml=5e3,Al=(n,e)=>zl(Il(n),e).map((t,s)=>Math.floor(s/Dl)*(1/(Ml*n))*t),Dl=5,Il=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),zl=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},Yl=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Nl={[qt.TYPE]:qt},Zl=(n,e,t,s,o,i)=>{if(n.series.length===0||e.series.length===0)return[];const a=[];return n.series.forEach(l=>e.series.forEach(u=>{if(!Bl(l,u,i))return;let c=0n,d=0n;l.alignment<u.alignment?c=u.alignment-l.alignment:u.alignment<l.alignment&&(d=l.alignment-u.alignment);const f=r.math.min(r.bounds.span(l.alignmentBounds)-c,r.bounds.span(u.alignmentBounds)-d);if(f===0n)return;let p=r.clamp(Math.round(t*4*Number(f)),s,51);o!=="decimate"&&(p=1);const g=Number(f/l.alignmentMultiple),T=Number(c/l.alignmentMultiple),y=Number(d/u.alignmentMultiple);a.push({x:l,y:u,xOffset:T,yOffset:y,count:g,downsample:p})})),a},Ul=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Bl=(n,e,t)=>{if(n.alignmentMultiple!==e.alignmentMultiple)return console.warn("encountered two series with different alignment multiples in draw operations",{x:n.digest,y:e.digest}),!1;const s=n.timeRange.overlapsWith(e.timeRange,t),o=r.bounds.overlapsWith(n.alignmentBounds,e.alignmentBounds);return s&&o},Bs=h.z.object({dpr:h.z.number(),region:r.box.box,bootstrap:h.z.boolean().default(!1),bootstrapped:h.z.boolean().default(!1),glCanvas:h.z.any().optional(),upper2dCanvas:h.z.any().optional(),lower2dCanvas:h.z.any().optional(),os:r.runtime.osZ});class Ht extends w.Composite{static TYPE="Canvas";schema=Bs;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:t,lower2dCanvas:s,upper2dCanvas:o,os:i}=this.state;if(t==null||s==null||o==null)throw new x.UnexpectedError("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=I.Context.create(e,t,s,o,i),_e.create(e,this.renderCtx),this.setState(a=>({...a,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else this.renderCtx.update(e);this.renderCtx.resize(this.state.region,this.state.dpr)}}const Vo={[Ht.TYPE]:Ht},Fl=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Ht,REGISTRY:Vo,canvasStateZ:Bs},Symbol.toStringTag,{value:"Module"})),Fs=h.z.object({position:r.xy.xy,zoom:h.z.number(),region:r.box.box,clearOverScan:r.xy.crudeZ.default(5),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().optional()}),wt=["upper2d","lower2d"];class xe extends w.Composite{static TYPE="Diagram";static stateZ=Fs;schema=xe.stateZ;afterUpdate(e){this.internal.renderCtx=I.Context.use(e),this.internal.handleError=w.useErrorHandler(e),r.primitive.isNonZero(this.state.autoRenderInterval)&&(this.internal.autoRenderInterval??=setInterval(()=>{this.state.visible&&this.requestRender("low")},this.state.autoRenderInterval)),an(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=r.scale.XY.magnify(r.xy.construct(this.state.zoom)).translate(r.box.topLeft(this.state.region)).translate(this.state.position),this.requestRender("high"))}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const{renderCtx:e,handleError:t,viewportScale:s}=this.internal,o=r.box.construct(this.state.region);if(!this.state.visible)return()=>e.erase(o,this.state.clearOverScan,...wt);const i=e.scissor(o,r.xy.ZERO,wt);try{this.children.forEach(l=>l.render?.({viewportScale:s}))}catch(l){t(l,"failed to render diagram")}finally{i()}const a=r.box.copy(this.state.region);return()=>{e.lower2d.fillStyle=r.color.hex(r.color.BLACK),e.lower2d.fillRect(...r.xy.couple(r.box.topLeft(a)),r.box.width(a),r.box.height(a)),e.erase(a,this.state.clearOverScan,...wt)}}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${xe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:wt})}}const Xo={[xe.TYPE]:xe},$l=Object.freeze(Object.defineProperty({__proto__:null,Diagram:xe,REGISTRY:Xo,diagramStateZ:Fs},Symbol.toStringTag,{value:"Module"}));function kt(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function ql(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function $s(n){let e,t,s;n.length!==2?(e=kt,t=(l,u)=>kt(n(l),u),s=(l,u)=>n(l)-u):(e=n===kt||n===ql?n:Hl,t=n,s=n);function o(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<0?c=f+1:d=f}while(c<d)}return c}function i(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<=0?c=f+1:d=f}while(c<d)}return c}function a(l,u,c=0,d=l.length){const f=o(l,u,c,d-1);return f>c&&s(l[f-1],u)>-s(l[f],u)?f-1:f}return{left:o,center:a,right:i}}function Hl(){return 0}function jl(n){return n===null?NaN:+n}const Wl=$s(kt),Vl=Wl.right;$s(jl).center;const Xl=Math.sqrt(50),Gl=Math.sqrt(10),Kl=Math.sqrt(2);function jt(n,e,t){const s=(e-n)/Math.max(0,t),o=Math.floor(Math.log10(s)),i=s/Math.pow(10,o),a=i>=Xl?10:i>=Gl?5:i>=Kl?2:1;let l,u,c;return o<0?(c=Math.pow(10,-o)/a,l=Math.round(n*c),u=Math.round(e*c),l/c<n&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,o)*a,l=Math.round(n/c),u=Math.round(e/c),l*c<n&&++l,u*c>e&&--u),u<l&&.5<=t&&t<2?jt(n,e,t*2):[l,u,c]}function Ql(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[o,i,a]=s?jt(e,n,t):jt(n,e,t);if(!(i>=o))return[];const l=i-o+1,u=new Array(l);if(s)if(a<0)for(let c=0;c<l;++c)u[c]=(i-c)/-a;else for(let c=0;c<l;++c)u[c]=(i-c)*a;else if(a<0)for(let c=0;c<l;++c)u[c]=(o+c)/-a;else for(let c=0;c<l;++c)u[c]=(o+c)*a;return u}function Xn(n,e,t){return e=+e,n=+n,t=+t,jt(n,e,t)[2]}function Gn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,o=s?Xn(e,n,t):Xn(n,e,t);return(s?-1:1)*(o<0?1/-o:o)}function Go(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function Jl(n){return function(){return n}}function ec(n){return+n}var yr=[0,1];function Pe(n){return n}function Kn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Jl(isNaN(e)?NaN:.5)}function tc(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function nc(n,e,t){var s=n[0],o=n[1],i=e[0],a=e[1];return o<s?(s=Kn(o,s),i=t(a,i)):(s=Kn(s,o),i=t(i,a)),function(l){return i(s(l))}}function sc(n,e,t){var s=Math.min(n.length,e.length)-1,o=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)o[a]=Kn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var u=Vl(n,l,1,s)-1;return i[u](o[u](l))}}function Ko(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function rc(){var n=yr,e=yr,t=cn,s,o,i,a=Pe,l,u,c;function d(){var p=Math.min(n.length,e.length);return a!==Pe&&(a=tc(n[0],n[p-1])),l=p>2?sc:nc,u=c=null,f}function f(p){return p==null||isNaN(p=+p)?i:(u||(u=l(n.map(s),e,t)))(s(a(p)))}return f.invert=function(p){return a(o((c||(c=l(e,n.map(s),st)))(p)))},f.domain=function(p){return arguments.length?(n=Array.from(p,ec),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=za,d()},f.clamp=function(p){return arguments.length?(a=p?!0:Pe,d()):a!==Pe},f.interpolate=function(p){return arguments.length?(t=p,d()):t},f.unknown=function(p){return arguments.length?(i=p,f):i},function(p,g){return s=p,o=g,d()}}function Qo(){return rc()(Pe,Pe)}function oc(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function Wt(n,e){if(!isFinite(n)||n===0)return null;var t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"),s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function Ze(n){return n=Wt(Math.abs(n)),n?n[1]:NaN}function ic(n,e){return function(t,s){for(var o=t.length,i=[],a=0,l=n[0],u=0;o>0&&l>0&&(u+l+1>s&&(l=Math.max(1,s-u)),i.push(t.substring(o-=l,o+l)),!((u+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function ac(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var lc=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Vt(n){if(!(e=lc.exec(n)))throw new Error("invalid format: "+n);var e;return new qs({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]})}Vt.prototype=qs.prototype;function qs(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+""}qs.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 cc(n){e:for(var e=n.length,t=1,s=-1,o;t<e;++t)switch(n[t]){case".":s=o=t;break;case"0":s===0&&(s=t),o=t;break;default:if(!+n[t])break e;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(o+1):n}var Xt;function uc(n,e){var t=Wt(n,e);if(!t)return Xt=void 0,n.toPrecision(e);var s=t[0],o=t[1],i=o-(Xt=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+Wt(n,Math.max(0,e+i-1))[0]}function xr(n,e){var t=Wt(n,e);if(!t)return n+"";var s=t[0],o=t[1];return o<0?"0."+new Array(-o).join("0")+s:s.length>o+1?s.slice(0,o+1)+"."+s.slice(o+1):s+new Array(o-s.length+2).join("0")}const br={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:oc,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)=>xr(n*100,e),r:xr,s:uc,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Sr(n){return n}var Tr=Array.prototype.map,vr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function hc(n){var e=n.grouping===void 0||n.thousands===void 0?Sr:ic(Tr.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",o=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?Sr:ac(Tr.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",u=n.nan===void 0?"NaN":n.nan+"";function c(f,p){f=Vt(f);var g=f.fill,T=f.align,y=f.sign,v=f.symbol,R=f.zero,L=f.width,k=f.comma,C=f.precision,Z=f.trim,b=f.type;b==="n"?(k=!0,b="g"):br[b]||(C===void 0&&(C=12),Z=!0,b="g"),(R||g==="0"&&T==="=")&&(R=!0,g="0",T="=");var M=(p&&p.prefix!==void 0?p.prefix:"")+(v==="$"?t:v==="#"&&/[boxX]/.test(b)?"0"+b.toLowerCase():""),D=(v==="$"?s:/[%p]/.test(b)?a:"")+(p&&p.suffix!==void 0?p.suffix:""),V=br[b],K=/[defgprs%]/.test(b);C=C===void 0?6:/[gprs]/.test(b)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C));function ue(E){var $=M,N=D,Q,de,ne;if(b==="c")N=V(E)+N,E="";else{E=+E;var J=E<0||1/E<0;if(E=isNaN(E)?u:V(Math.abs(E),C),Z&&(E=cc(E)),J&&+E==0&&y!=="+"&&(J=!1),$=(J?y==="("?y:l:y==="-"||y==="("?"":y)+$,N=(b==="s"&&!isNaN(E)&&Xt!==void 0?vr[8+Xt/3]:"")+N+(J&&y==="("?")":""),K){for(Q=-1,de=E.length;++Q<de;)if(ne=E.charCodeAt(Q),48>ne||ne>57){N=(ne===46?o+E.slice(Q+1):E.slice(Q))+N,E=E.slice(0,Q);break}}}k&&!R&&(E=e(E,1/0));var se=$.length+E.length+N.length,q=se<L?new Array(L-se+1).join(g):"";switch(k&&R&&(E=e(q+E,q.length?L-N.length:1/0),q=""),T){case"<":E=$+E+N+q;break;case"=":E=$+q+E+N;break;case"^":E=q.slice(0,se=q.length>>1)+$+E+N+q.slice(se);break;default:E=q+$+E+N;break}return i(E)}return ue.toString=function(){return f+""},ue}function d(f,p){var g=Math.max(-8,Math.min(8,Math.floor(Ze(p)/3)))*3,T=Math.pow(10,-g),y=c((f=Vt(f),f.type="f",f),{suffix:vr[8+g/3]});return function(v){return y(T*v)}}return{format:c,formatPrefix:d}}var Et,Jo,ei;dc({thousands:",",grouping:[3],currency:["$",""]});function dc(n){return Et=hc(n),Jo=Et.format,ei=Et.formatPrefix,Et}function fc(n){return Math.max(0,-Ze(Math.abs(n)))}function pc(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Ze(e)/3)))*3-Ze(Math.abs(n)))}function mc(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,Ze(e)-Ze(n))+1}function gc(n,e,t,s){var o=Gn(n,e,t),i;switch(s=Vt(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=pc(o,a))&&(s.precision=i),ei(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=mc(o,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=fc(o))&&(s.precision=i-(s.type==="%")*2);break}}return Jo(s)}function yc(n){var e=n.domain;return n.ticks=function(t){var s=e();return Ql(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var o=e();return gc(o[0],o[o.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),o=0,i=s.length-1,a=s[o],l=s[i],u,c,d=10;for(l<a&&(c=a,a=l,l=c,c=o,o=i,i=c);d-- >0;){if(c=Xn(a,l,t),c===u)return s[o]=a,s[i]=l,e(s);if(c>0)a=Math.floor(a/c)*c,l=Math.ceil(l/c)*c;else if(c<0)a=Math.ceil(a*c)/c,l=Math.floor(l*c)/c;else break;u=c}return n},n}function ti(){var n=Qo();return n.copy=function(){return Ko(n,ti())},Go.apply(n,arguments),yc(n)}function xc(n,e){n=n.slice();var t=0,s=n.length-1,o=n[t],i=n[s],a;return i<o&&(a=t,t=s,s=a,a=o,o=i,i=a),n[t]=e.floor(o),n[s]=e.ceil(i),n}const Ln=new Date,kn=new Date;function z(n,e,t,s){function o(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(n(i=new Date(+i)),i),o.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),o.round=i=>{const a=o(i),l=o.ceil(i);return i-a<l-i?a:l},o.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),o.range=(i,a,l)=>{const u=[];if(i=o.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return u;let c;do u.push(c=new Date(+i)),e(i,l),n(i);while(c<i&&i<a);return u},o.filter=i=>z(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(o.count=(i,a)=>(Ln.setTime(+i),kn.setTime(+a),n(Ln),n(kn),Math.floor(t(Ln,kn))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(s?a=>s(a)%i===0:a=>o.count(0,a)%i===0):o)),o}const Gt=z(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);Gt.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?z(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):Gt);Gt.range;const re=1e3,X=re*60,oe=X*60,ae=oe*24,Hs=ae*7,wr=ae*30,_n=ae*365,Le=z(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*re)},(n,e)=>(e-n)/re,n=>n.getUTCSeconds());Le.range;const js=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getMinutes());js.range;const bc=z(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getUTCMinutes());bc.range;const Ws=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re-n.getMinutes()*X)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getHours());Ws.range;const Sc=z(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getUTCHours());Sc.range;const yt=z(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*X)/ae,n=>n.getDate()-1);yt.range;const Vs=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>n.getUTCDate()-1);Vs.range;const Tc=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>Math.floor(n/ae));Tc.range;function Te(n){return z(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*X)/Hs)}const xn=Te(0),Kt=Te(1),vc=Te(2),wc=Te(3),Ue=Te(4),Ec=Te(5),Cc=Te(6);xn.range;Kt.range;vc.range;wc.range;Ue.range;Ec.range;Cc.range;function ve(n){return z(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/Hs)}const ni=ve(0),Qt=ve(1),Rc=ve(2),Pc=ve(3),Be=ve(4),Lc=ve(5),kc=ve(6);ni.range;Qt.range;Rc.range;Pc.range;Be.range;Lc.range;kc.range;const Xs=z(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());Xs.range;const _c=z(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());_c.range;const le=z(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());le.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});le.range;const be=z(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());be.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});be.range;function Oc(n,e,t,s,o,i){const a=[[Le,1,re],[Le,5,5*re],[Le,15,15*re],[Le,30,30*re],[i,1,X],[i,5,5*X],[i,15,15*X],[i,30,30*X],[o,1,oe],[o,3,3*oe],[o,6,6*oe],[o,12,12*oe],[s,1,ae],[s,2,2*ae],[t,1,Hs],[e,1,wr],[e,3,3*wr],[n,1,_n]];function l(c,d,f){const p=d<c;p&&([c,d]=[d,c]);const g=f&&typeof f.range=="function"?f:u(c,d,f),T=g?g.range(c,+d+1):[];return p?T.reverse():T}function u(c,d,f){const p=Math.abs(d-c)/f,g=$s(([,,v])=>v).right(a,p);if(g===a.length)return n.every(Gn(c/_n,d/_n,f));if(g===0)return Gt.every(Math.max(Gn(c,d,f),1));const[T,y]=a[p/a[g-1][2]<a[g][2]/p?g-1:g];return T.every(y)}return[l,u]}const[Mc,Ac]=Oc(le,Xs,xn,yt,Ws,js);function On(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 Mn(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 We(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function Dc(n){var e=n.dateTime,t=n.date,s=n.time,o=n.periods,i=n.days,a=n.shortDays,l=n.months,u=n.shortMonths,c=Ve(o),d=Xe(o),f=Ve(i),p=Xe(i),g=Ve(a),T=Xe(a),y=Ve(l),v=Xe(l),R=Ve(u),L=Xe(u),k={a:ne,A:J,b:se,B:q,c:null,d:kr,e:kr,f:su,g:fu,G:mu,H:eu,I:tu,j:nu,L:si,m:ru,M:ou,p:bn,q:Sn,Q:Mr,s:Ar,S:iu,u:au,U:lu,V:cu,w:uu,W:hu,x:null,X:null,y:du,Y:pu,Z:gu,"%":Or},C={a:Tn,A:vn,b:wn,B:St,c:null,d:_r,e:_r,f:Su,g:_u,G:Mu,H:yu,I:xu,j:bu,L:oi,m:Tu,M:vu,p:En,q:ji,Q:Mr,s:Ar,S:wu,u:Eu,U:Cu,V:Ru,w:Pu,W:Lu,x:null,X:null,y:ku,Y:Ou,Z:Au,"%":Or},Z={a:K,A:ue,b:E,B:$,c:N,d:Pr,e:Pr,f:Gc,g:Rr,G:Cr,H:Lr,I:Lr,j:jc,L:Xc,m:Hc,M:Wc,p:V,q:qc,Q:Qc,s:Jc,S:Vc,u:Zc,U:Uc,V:Bc,w:Nc,W:Fc,x:Q,X:de,y:Rr,Y:Cr,Z:$c,"%":Kc};k.x=b(t,k),k.X=b(s,k),k.c=b(e,k),C.x=b(t,C),C.X=b(s,C),C.c=b(e,C);function b(S,P){return function(_){var m=[],B=-1,A=0,H=S.length,j,fe,nr;for(_ instanceof Date||(_=new Date(+_));++B<H;)S.charCodeAt(B)===37&&(m.push(S.slice(A,B)),(fe=Er[j=S.charAt(++B)])!=null?j=S.charAt(++B):fe=j==="e"?" ":"0",(nr=P[j])&&(j=nr(_,fe)),m.push(j),A=B+1);return m.push(S.slice(A,B)),m.join("")}}function M(S,P){return function(_){var m=We(1900,void 0,1),B=D(m,S,_+="",0),A,H;if(B!=_.length)return null;if("Q"in m)return new Date(m.Q);if("s"in m)return new Date(m.s*1e3+("L"in m?m.L:0));if(P&&!("Z"in m)&&(m.Z=0),"p"in m&&(m.H=m.H%12+m.p*12),m.m===void 0&&(m.m="q"in m?m.q:0),"V"in m){if(m.V<1||m.V>53)return null;"w"in m||(m.w=1),"Z"in m?(A=Mn(We(m.y,0,1)),H=A.getUTCDay(),A=H>4||H===0?Qt.ceil(A):Qt(A),A=Vs.offset(A,(m.V-1)*7),m.y=A.getUTCFullYear(),m.m=A.getUTCMonth(),m.d=A.getUTCDate()+(m.w+6)%7):(A=On(We(m.y,0,1)),H=A.getDay(),A=H>4||H===0?Kt.ceil(A):Kt(A),A=yt.offset(A,(m.V-1)*7),m.y=A.getFullYear(),m.m=A.getMonth(),m.d=A.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),H="Z"in m?Mn(We(m.y,0,1)).getUTCDay():On(We(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-(H+5)%7:m.w+m.U*7-(H+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,Mn(m)):On(m)}}function D(S,P,_,m){for(var B=0,A=P.length,H=_.length,j,fe;B<A;){if(m>=H)return-1;if(j=P.charCodeAt(B++),j===37){if(j=P.charAt(B++),fe=Z[j in Er?P.charAt(B++):j],!fe||(m=fe(S,_,m))<0)return-1}else if(j!=_.charCodeAt(m++))return-1}return m}function V(S,P,_){var m=c.exec(P.slice(_));return m?(S.p=d.get(m[0].toLowerCase()),_+m[0].length):-1}function K(S,P,_){var m=g.exec(P.slice(_));return m?(S.w=T.get(m[0].toLowerCase()),_+m[0].length):-1}function ue(S,P,_){var m=f.exec(P.slice(_));return m?(S.w=p.get(m[0].toLowerCase()),_+m[0].length):-1}function E(S,P,_){var m=R.exec(P.slice(_));return m?(S.m=L.get(m[0].toLowerCase()),_+m[0].length):-1}function $(S,P,_){var m=y.exec(P.slice(_));return m?(S.m=v.get(m[0].toLowerCase()),_+m[0].length):-1}function N(S,P,_){return D(S,e,P,_)}function Q(S,P,_){return D(S,t,P,_)}function de(S,P,_){return D(S,s,P,_)}function ne(S){return a[S.getDay()]}function J(S){return i[S.getDay()]}function se(S){return u[S.getMonth()]}function q(S){return l[S.getMonth()]}function bn(S){return o[+(S.getHours()>=12)]}function Sn(S){return 1+~~(S.getMonth()/3)}function Tn(S){return a[S.getUTCDay()]}function vn(S){return i[S.getUTCDay()]}function wn(S){return u[S.getUTCMonth()]}function St(S){return l[S.getUTCMonth()]}function En(S){return o[+(S.getUTCHours()>=12)]}function ji(S){return 1+~~(S.getUTCMonth()/3)}return{format:function(S){var P=b(S+="",k);return P.toString=function(){return S},P},parse:function(S){var P=M(S+="",!1);return P.toString=function(){return S},P},utcFormat:function(S){var P=b(S+="",C);return P.toString=function(){return S},P},utcParse:function(S){var P=M(S+="",!0);return P.toString=function(){return S},P}}}var Er={"-":"",_:" ",0:"0"},Y=/^\s*\d+/,Ic=/^%/,zc=/[\\^$*+?|[\]().{}]/g;function O(n,e,t){var s=n<0?"-":"",o=(s?-n:n)+"",i=o.length;return s+(i<t?new Array(t-i+1).join(e)+o:o)}function Yc(n){return n.replace(zc,"\\$&")}function Ve(n){return new RegExp("^(?:"+n.map(Yc).join("|")+")","i")}function Xe(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function Nc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function Zc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function Uc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Bc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function Fc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Cr(n,e,t){var s=Y.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Rr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function $c(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function qc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Hc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Pr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function jc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Lr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function Wc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Vc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function Xc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Gc(n,e,t){var s=Y.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Kc(n,e,t){var s=Ic.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Qc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Jc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function kr(n,e){return O(n.getDate(),e,2)}function eu(n,e){return O(n.getHours(),e,2)}function tu(n,e){return O(n.getHours()%12||12,e,2)}function nu(n,e){return O(1+yt.count(le(n),n),e,3)}function si(n,e){return O(n.getMilliseconds(),e,3)}function su(n,e){return si(n,e)+"000"}function ru(n,e){return O(n.getMonth()+1,e,2)}function ou(n,e){return O(n.getMinutes(),e,2)}function iu(n,e){return O(n.getSeconds(),e,2)}function au(n){var e=n.getDay();return e===0?7:e}function lu(n,e){return O(xn.count(le(n)-1,n),e,2)}function ri(n){var e=n.getDay();return e>=4||e===0?Ue(n):Ue.ceil(n)}function cu(n,e){return n=ri(n),O(Ue.count(le(n),n)+(le(n).getDay()===4),e,2)}function uu(n){return n.getDay()}function hu(n,e){return O(Kt.count(le(n)-1,n),e,2)}function du(n,e){return O(n.getFullYear()%100,e,2)}function fu(n,e){return n=ri(n),O(n.getFullYear()%100,e,2)}function pu(n,e){return O(n.getFullYear()%1e4,e,4)}function mu(n,e){var t=n.getDay();return n=t>=4||t===0?Ue(n):Ue.ceil(n),O(n.getFullYear()%1e4,e,4)}function gu(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+O(e/60|0,"0",2)+O(e%60,"0",2)}function _r(n,e){return O(n.getUTCDate(),e,2)}function yu(n,e){return O(n.getUTCHours(),e,2)}function xu(n,e){return O(n.getUTCHours()%12||12,e,2)}function bu(n,e){return O(1+Vs.count(be(n),n),e,3)}function oi(n,e){return O(n.getUTCMilliseconds(),e,3)}function Su(n,e){return oi(n,e)+"000"}function Tu(n,e){return O(n.getUTCMonth()+1,e,2)}function vu(n,e){return O(n.getUTCMinutes(),e,2)}function wu(n,e){return O(n.getUTCSeconds(),e,2)}function Eu(n){var e=n.getUTCDay();return e===0?7:e}function Cu(n,e){return O(ni.count(be(n)-1,n),e,2)}function ii(n){var e=n.getUTCDay();return e>=4||e===0?Be(n):Be.ceil(n)}function Ru(n,e){return n=ii(n),O(Be.count(be(n),n)+(be(n).getUTCDay()===4),e,2)}function Pu(n){return n.getUTCDay()}function Lu(n,e){return O(Qt.count(be(n)-1,n),e,2)}function ku(n,e){return O(n.getUTCFullYear()%100,e,2)}function _u(n,e){return n=ii(n),O(n.getUTCFullYear()%100,e,2)}function Ou(n,e){return O(n.getUTCFullYear()%1e4,e,4)}function Mu(n,e){var t=n.getUTCDay();return n=t>=4||t===0?Be(n):Be.ceil(n),O(n.getUTCFullYear()%1e4,e,4)}function Au(){return"+0000"}function Or(){return"%"}function Mr(n){return+n}function Ar(n){return Math.floor(+n/1e3)}var Ce,ai;Du({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function Du(n){return Ce=Dc(n),ai=Ce.format,Ce.parse,Ce.utcFormat,Ce.utcParse,Ce}function Iu(n){return new Date(n)}function zu(n){return n instanceof Date?+n:+new Date(+n)}function li(n,e,t,s,o,i,a,l,u,c){var d=Qo(),f=d.invert,p=d.domain,g=c(".%L"),T=c(":%S"),y=c("%I:%M"),v=c("%I %p"),R=c("%a %d"),L=c("%b %d"),k=c("%B"),C=c("%Y");function Z(b){return(u(b)<b?g:l(b)<b?T:a(b)<b?y:i(b)<b?v:s(b)<b?o(b)<b?R:L:t(b)<b?k:C)(b)}return d.invert=function(b){return new Date(f(b))},d.domain=function(b){return arguments.length?p(Array.from(b,zu)):p().map(Iu)},d.ticks=function(b){var M=p();return n(M[0],M[M.length-1],b??10)},d.tickFormat=function(b,M){return M==null?Z:c(M)},d.nice=function(b){var M=p();return(!b||typeof b.range!="function")&&(b=e(M[0],M[M.length-1],b??10)),b?p(xc(M,b)):d},d.copy=function(){return Ko(d,li(n,e,t,s,o,i,a,l,u,c))},d}function Yu(){return Go.apply(li(Mc,Ac,le,Xs,xn,yt,Ws,js,Le,ai).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const Dr=[r.TimeSpan.NANOSECOND,r.TimeSpan.nanoseconds(2),r.TimeSpan.nanoseconds(5),r.TimeSpan.nanoseconds(10),r.TimeSpan.nanoseconds(20),r.TimeSpan.nanoseconds(50),r.TimeSpan.nanoseconds(100),r.TimeSpan.nanoseconds(200),r.TimeSpan.nanoseconds(500),r.TimeSpan.MICROSECOND,r.TimeSpan.microseconds(2),r.TimeSpan.microseconds(5),r.TimeSpan.microseconds(10),r.TimeSpan.microseconds(20),r.TimeSpan.microseconds(50),r.TimeSpan.microseconds(100),r.TimeSpan.microseconds(200),r.TimeSpan.microseconds(500),r.TimeSpan.MILLISECOND,r.TimeSpan.milliseconds(2),r.TimeSpan.milliseconds(5),r.TimeSpan.milliseconds(10),r.TimeSpan.milliseconds(20),r.TimeSpan.milliseconds(50),r.TimeSpan.milliseconds(100),r.TimeSpan.milliseconds(200),r.TimeSpan.milliseconds(500),r.TimeSpan.SECOND];class Nu{_domain;_range;_span;constructor(){this._domain=[new r.TimeStamp(0n),new r.TimeStamp(1n)],this._range=[0,1],this._span=this._domain[1].span(this._domain[0])}domain(e){return e===void 0?this._domain:(this._domain=[new r.TimeStamp(e[0]),new r.TimeStamp(e[1])],this._span=this._domain[1].span(this._domain[0]),this)}range(e){return e===void 0?this._range:(this._range=e,this)}scale(e){const s=new r.TimeStamp(e).valueOf(),o=this._domain[0].valueOf(),i=this._domain[1].valueOf()-o,a=this._range[1]-this._range[0];return Number(s-o)/Number(i)*a+this._range[0]}ticks(e){const t=this.calculateOptimalStep(e).valueOf(),s=this._domain[0].valueOf(),o=this._domain[1].valueOf(),i=(s+t-1n)/t*t,a=Number((o-i)/t);return Array.from({length:a+1},(l,u)=>{const c=i+BigInt(u)*t;return new r.TimeStamp(c)}).filter(l=>l.afterEq(this._domain[0])&&l.beforeEq(this._domain[1]))}calculateOptimalStep(e){const t=this._span.valueOf()/BigInt(Math.ceil(e));let s=Dr[0];for(const o of Dr){if(o.valueOf()>t)break;s=o}return s}formatTick(e){return this._span.lessThan(r.TimeSpan.microseconds(50))?`${e.remainder(r.TimeSpan.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(r.TimeSpan.SECOND).milliseconds.toString()}ms`}}const Zu=()=>new Nu,Gs=h.z.enum(["linear","time"]),Ks=h.z.object({tickSpacing:h.z.number().default(75),type:Gs.default("linear")}),Qn=n=>{const e=Ks.parse(n);return Fu[e.type](e)};class Uu{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=Yu(),this.preciseScale=Zu(),this.prevScaleSize=0,this.prevDomain=new r.TimeRange(new r.TimeStamp(0),new r.TimeStamp(0)),this.currTicks=[]}create({decimalToDataScale:e,size:t}){const s=new r.TimeRange(new r.TimeStamp(e.pos(0)),new r.TimeStamp(e.pos(1)));if(this.prevDomain.equals(s)&&this.prevScaleSize===t)return this.currTicks;if(this.prevDomain=s,this.prevScaleSize!==t){const o=[0,t];this.preciseScale.range(o),this.normalScale.range(o),this.prevScaleSize=t}if(s.span.milliseconds<5){this.preciseScale.domain([s.start,s.end]);const o=Jn(t,this.props.tickSpacing)/2,i=this.preciseScale.ticks(o);this.currTicks=i.map(a=>({label:this.preciseScale.formatTick(a),position:this.preciseScale.scale(a)}))}else{this.normalScale.domain([s.start.date(),s.end.date()]);const o=this.normalScale.ticks(Jn(t,this.props.tickSpacing));this.currTicks=o.map(i=>({label:this.normalTickLabel(i),position:this.normalScale(i)}))}return this.currTicks}normalTickLabel(e){let t=`:${e.getSeconds()}`;const s=e.getMilliseconds();if(s!==0){const o=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");t+=`.${o}`}return e.getSeconds()===0&&s===0&&(t=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),t}}class Bu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=r.bounds.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=ti()}create({decimalToDataScale:e,size:t}){const s={lower:e.pos(0),upper:e.pos(1)};if(r.bounds.equals(this.prevDomain,s)&&this.prevScaleSize===t)return this.currTicks;r.bounds.equals(this.prevDomain,s)||(this.d3Scale=this.d3Scale.domain([s.lower,s.upper])),this.prevScaleSize!==t&&(this.d3Scale=this.d3Scale.range([0,t])),this.prevDomain=s,this.prevScaleSize=t;const o=Jn(t,this.props.tickSpacing),i=this.d3Scale.ticks(o);return this.currTicks=i.map(a=>({label:this.tickLabel(a),position:this.d3Scale(a)})),this.currTicks}tickLabel(e){return e.toString()}}const Jn=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},Fu={linear:n=>new Bu(n),time:n=>new Uu(n)},Qs=Ks.extend({color:r.color.colorZ,type:Gs.default("linear"),font:h.z.string(),showGrid:h.z.boolean().default(!0),location:r.location.outer,gridColor:r.color.colorZ}),G=5,ot=6,xt={useAtlas:!0},$u={bottom:(n,e)=>new ui(n,e),top:(n,e)=>new hi(n,e),left:(n,e)=>new qu(n,e),right:(n,e)=>new di(n,e)},ci=(n,e,t)=>$u[n](e,t);class we{renderCtx;state;tickFactory;constructor(e,t){this.renderCtx=e,this.state=t,this.tickFactory=Qn(this.state)}setState(e){this.state=w.prettyParse(Qs,e),this.tickFactory=Qn(e)}drawLine(e,t){const{lower2d:s}=this.renderCtx;s.moveTo(...r.xy.couple(e)),s.lineTo(...r.xy.couple(t))}drawTicks(e,t){let s=r.dimensions.ZERO;return e.forEach(o=>{const i=this.renderCtx.lower2d.textDimensions(o.label,xt);s=r.dimensions.max([s,i]),t(i,o)}),s}static START_BOUND=r.bounds.construct(-1,1);maybeDrawGrid(e,t,s){const{showGrid:o,gridColor:i}=this.state;if(o){const a=we.START_BOUND,l=r.bounds.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=r.color.hex(i),t.forEach(c=>{r.bounds.contains(a,c.position)||r.bounds.contains(l,c.position)||this.drawLine(...s(c))}),u.stroke()}}setColor(e){const t=r.color.hex(e);this.renderCtx.lower2d.strokeStyle=t,this.renderCtx.lower2d.fillStyle=t,this.renderCtx.lower2d.font=this.state.font}}class ui extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{width:i,height:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translate(o,"x",i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(o,d.position),r.xy.translate(o,{x:d.position,y:G})),t.fillText(d.label,o.x+d.position-c.width/2,o.y+G+c.height+ot,void 0,xt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translate(o,"x",c.position),r.xy.translate(o,{x:c.position,y:-a})]),{size:u.height+G+ot}}}class hi extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s}=e,{width:o,height:i}=r.box.dims(s),a=r.xy.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:o});t.beginPath(),this.setColor(this.state.color),this.drawLine(a,r.xy.translate(a,"x",o));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(a,d.position),r.xy.translate(a,{x:d.position,y:-G})),t.fillText(d.label,a.x+d.position-c.width/2,a.y-G-c.height-ot,void 0,xt)});return t.stroke(),this.maybeDrawGrid(o,l,c=>[r.xy.translate(a,"x",c.position),r.xy.translate(a,{x:c.position,y:i})]),{size:u.height+G}}}class qu extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=r.xy.translate(o,"x",e.size),u=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(l,r.xy.translate(l,"y",i));const c=this.drawTicks(u,(d,f)=>{this.drawLine(r.xy.translateY(l,f.position),r.xy.translate(l,{x:-G,y:f.position})),t.fillText(f.label,l.x-d.width-G*2,l.y+f.position+d.height/2,void 0,xt)});return t.stroke(),this.maybeDrawGrid(i,u,d=>[r.xy.translate(l,"y",d.position),r.xy.translate(l,{x:a,y:d.position})]),{size:c.width+G*2}}}class di extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translateY(o,i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateY(o,d.position),r.xy.translate(o,{x:G,y:d.position})),t.fillText(d.label,o.x+G+ot,o.y+d.position+c.height/2,void 0,xt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translateY(o,c.position),r.xy.translate(o,{x:-a,y:c.position})]),{size:u.width+G+ot}}}const fi=h.z.object({key:h.z.string(),size:h.z.number(),order:h.z.number(),loc:r.location.outer});h.z.record(h.z.string(),fi);const me=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Hu=(n,e,t)=>{const s=e[n];if(s==null)return r.xy.ZERO;const o=r.location.construct(s.loc),i=me(o,e),a=r.location.construct(r.direction.swap(r.location.direction(o))),l=me(a,e),u=i.findIndex(({key:f})=>f===n),c=i.slice(0,u).reduce((f,{size:p})=>f+p,0),d=l.reduce((f,{size:p})=>f+p,0);switch(o){case"left":return r.xy.translate(r.box.topLeft(t),[c,d]);case"right":return r.xy.translate(r.box.topRight(t),[c-s.size,d]);case"top":return r.xy.translate(r.box.topLeft(t),[d,c]);default:return r.xy.translate(r.box.bottomLeft(t),[d,-c-s.size])}},ju=(n,e)=>{const t=me("left",n),s=me("right",n),o=me("top",n),i=me("bottom",n),a=t.reduce((d,{size:f})=>d+f,0),l=s.reduce((d,{size:f})=>d+f,0),u=o.reduce((d,{size:f})=>d+f,0),c=i.reduce((d,{size:f})=>d+f,0);return r.box.construct(r.xy.translate(r.box.topLeft(e),{x:a,y:u}),r.box.width(e)-a-l,r.box.height(e)-u-c)},bt=Qs.extend({axisKey:h.z.string().optional(),bounds:r.bounds.bounds.optional(),autoBounds:h.z.object({lower:h.z.boolean().default(!0),upper:h.z.boolean().default(!0)}).or(h.z.boolean().default(!0)),autoBoundPadding:h.z.number().optional(),autoBoundUpdateInterval:r.TimeSpan.z.default(r.TimeSpan.seconds(10)),size:h.z.number().default(0),label:h.z.string().default(""),labelSize:h.z.number().default(0)}).partial({color:!0,font:!0,gridColor:!0}),Wu=2,Vu=7,pi=(n,e)=>r.bounds.contains({lower:n-Vu,upper:n+Wu},e),Xu=r.bounds.DECIMAL,Ir=r.TimeStamp.now(),Gu={lower:Number(Ir.valueOf()),upper:Number(Ir.add(r.TimeSpan.HOUR).valueOf())},mi=n=>n==="linear"?Xu:Gu,Ku=(n,e=.1,t)=>{const s=r.bounds.max(n.filter(r.bounds.isFinite));if(!r.bounds.isFinite(s))return mi(t);const{lower:o,upper:i}=s;if(i===o)return{lower:o-1,upper:i+1};const a=(i-o)*e;return{lower:o-a,upper:i+a}},Qu=.01,Ju=.1;class gi extends w.Composite{afterUpdate(e){const{internal:t}=this,{location:s,autoBoundUpdateInterval:o}=this.state;t.render=I.Context.use(e);const i=w.use(e),a=r.direction.construct(s);this.state.autoBoundPadding??=a==="x"?Ju:Qu,t.base=ci(s,t.render,{color:i.colors.gray.l10,font:et.fontString(i,{level:"small",code:!0}),gridColor:i.colors.gray.l1,...this.state}),ie(e,"layout"),t.updateBounds??=r.throttle(l=>this.setState(u=>({...u,bounds:l})),o.milliseconds)}afterDelete(e){ie(e,"layout")}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{base:s}=this.internal,{grid:o,container:i}=e,a=Hu(`${this.type}-${this.key}`,o,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:u}=s.render(l);pi(this.state.size,u)||this.setState(c=>({...c,size:u}))}iBounds(e,t){if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:o}=yi(this.state.autoBounds);if(!s&&!o&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=c=>({upper:o||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?c.lower:this.state.bounds.lower});let a,l=null;try{const c=t();a=Ku(c,this.state.autoBoundPadding,this.state.type)}catch(c){a=mi(this.state.type),l=c}const u=i(a);return this.internal.boundSnapshot=u,(this.state.bounds==null||s&&this.state.bounds.lower!==u.lower||o&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,t,s){const[o,i]=this.iBounds(e,t),a=r.direction.swap(r.direction.construct(this.state.location));return[r.scale.Scale.scale(o).scale(1).translate(-r.box.root(s)[a]).magnify(1/r.box.dim(s,a)),i]}}const yi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:n?.lower??!0,upper:n?.upper??!0};class Ee{canvas;theme;constructor(e,t){this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...o}){return e==="x"?this.line({start:r.xy.construct(r.box.left(t),s),end:r.xy.construct(r.box.right(t),s),...o}):this.line({start:r.xy.construct(s,r.box.top(t)),end:r.xy.construct(s,r.box.bottom(t)),...o})}line({stroke:e,lineWidth:t,lineDash:s,start:o,end:i}){const a=this.canvas;a.strokeStyle=r.color.hex(e),a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...r.xy.couple(o)),a.lineTo(...r.xy.couple(i)),a.stroke()}circle({fill:e,stroke:t,strokeWidth:s,lineDash:o,radius:i,position:a,angle:l,lineCap:u}){const c=this.canvas;c.beginPath();const d=l?.lower??0,f=l?.upper??2*Math.PI;if(t!=null&&typeof i=="object"){const{inner:p,outer:g}=i,T=(p+g)/2,y=g-p;c.arc(...r.xy.couple(a),T,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??y,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([])}else if(t!=null&&typeof i=="number")c.arc(...r.xy.couple(a),i,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??1,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([]);else if(e!=null)if(c.fillStyle=r.color.hex(e),typeof i=="number")c.arc(...r.xy.couple(a),i,d,f),c.fill();else{const{inner:p,outer:g}=i;c.arc(...r.xy.couple(a),g,d,f,!1);const T=a.x+p*Math.cos(f),y=a.y+p*Math.sin(f);c.lineTo(T,y),c.arc(...r.xy.couple(a),p,f,d,!0),c.closePath(),c.fill()}}resolveColor(e,t){return e==null?t==null?this.theme.colors.text:this.resolveColor(t):typeof e=="function"?e(this.theme):r.color.construct(e)}border({region:e,color:t,width:s,radius:o,location:i}){const a=this.canvas;a.strokeStyle=r.color.hex(this.resolveColor(t,this.theme.colors.border)),a.lineWidth=s??this.theme.sizes.border.width,o??=this.theme.sizes.border.radius,i==null||i===!0?o>0?(a.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),o),a.stroke()):(a.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),a.stroke()):r.array.toArray(i).forEach(l=>{const[u,c]=r.box.edgePoints(e,l);a.beginPath(),a.moveTo(...r.xy.couple(u)),a.lineTo(...r.xy.couple(c)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:o,borderRadius:i,borderWidth:a,backgroundColor:l}){i??=this.theme.sizes.border.radius,a??=1;const u=this.canvas;u.fillStyle=r.color.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=r.color.hex(this.resolveColor(o,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),s?u.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),i):u.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),u.fill(),t&&this.border({region:e,color:o,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:o=r.location.TOP_LEFT,offset:i=r.xy.ZERO}=e,a={...e.position};o.x==="right"?a.x-=t.width+i.x:a.x+=i.x,o.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:r.box.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(r.xy.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:o="p"}){const i=et.fontString(this.theme,{level:o}),a=e.map(c=>rr.dimensions(c,i,this.canvas)),l=this.theme.sizes.base*s,u=Math.max(...a.map(c=>c[r.direction.dimension(t)]))+l;return[{[r.direction.dimension(r.direction.swap(t))]:Math.max(...a.map(c=>c[r.direction.dimension(r.direction.swap(t))])),[r.direction.dimension(t)]:u*e.length-l},c=>{const d=et.fontString(this.theme,{level:o});this.canvas.font=d,this.canvas.fillStyle=r.color.hex(this.theme.colors.text),this.canvas.textBaseline="top",this.canvas.textAlign="start",e.forEach((f,p)=>{this.canvas.fillText(f,c.x,c.y+u*p)})}]}list({length:e,itemHeight:t,width:s,spacing:o=0,position:i,draw:a,root:l=r.location.TOP_LEFT,offset:u=r.xy.ZERO,padding:c=r.xy.ZERO}){const d=e*t+c.y*2+o*(e-1),f=s+c.x*2,p={...i};l.x==="right"?p.x-=s+u.x*2:p.x+=u.x,l.y==="top"?p.y-=d+u.y*2:p.y+=u.y,this.container({region:r.box.construct(p,{width:f,height:d}),backgroundColor:g=>g.colors.gray.l1});for(let g=0;g<e;g++){const T=r.box.construct(r.xy.construct(p.x+c.x,p.y+g*t+c.y+o*g),s,t);a(g,T)}}drawTextInCenter({box:e,text:t,level:s}){const o=rr.dimensions(t,this.canvas.font,this.canvas),i=r.box.positionInCenter(r.box.construct(r.xy.ZERO,o),e);return this.text({text:t,position:r.box.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:o,shade:i,maxWidth:a,code:l,justify:u="left",align:c="top",useAtlas:d,color:f}){this.canvas.font=et.fontString(this.theme,{level:s,weight:o,code:l}),f!=null?this.canvas.fillStyle=r.color.hex(this.resolveColor(f)):i==null?this.canvas.fillStyle=r.color.hex(this.theme.colors.text):this.canvas.fillStyle=r.color.hex(this.theme.colors.gray[`l${i}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let p;a!=null&&(p=this.canvas.scissor(r.box.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y,void 0,{useAtlas:d}),p?.()}}const Js=h.z.object({position:h.z.number().optional(),pixelPosition:h.z.number().optional(),dragging:h.z.boolean(),lineWidth:h.z.number().default(1),lineDash:h.z.number().default(20),color:r.color.colorZ}),eh=3;class it extends w.Leaf{static TYPE="Rule";schema=Js;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=I.Context.use(e);const t=w.use(e);this.internal.draw=new Ee(this.internal.renderCtx.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}updatePositions({decimalToDataScale:e,plot:t}){const s=this.state.dragging,o=this.prevState.dragging&&!s;if((s||o)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<eh&&!o)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/r.box.height(t));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const a=e.pos(.5);this.setState(l=>({...l,position:a}))}const i=e.reverse().pos(this.state.position)*r.box.height(t);if(!isNaN(i)){if(this.state.pixelPosition!=null&&Math.abs(i-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(a=>({...a,pixelPosition:i}))}return i}render(e){if(this.deleted)return;const{renderCtx:t}=this.internal,{location:s,plot:o}=e,i=r.location.direction(s),{upper2d:a}=t,l=this.internal.draw,u=this.updatePositions(e)+r.box.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:i,region:o,position:u}),a.fillStyle=r.color.hex(this.state.color),a.lineJoin="round",a.lineWidth=3.5,a.lineCap="round",a.beginPath();const c=4;if(s==="left"){const d=r.box.left(o)-1;a.moveTo(d,u),a.lineTo(d-c,u-c),a.lineTo(d-c,u+c)}else s==="right"&&(a.moveTo(r.box.right(o),u),a.lineTo(r.box.right(o)+c,u-c),a.lineTo(r.box.right(o)+c,u+c));a.closePath(),a.stroke()}}const xi={[it.TYPE]:it},th=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:xi,Rule:it,ruleStateZ:Js},Symbol.toStringTag,{value:"Module"})),nh=bt.extend({location:r.location.x.default("left")}),zr=2,sh=n=>r.box.signedWidth(n)<zr||r.box.signedHeight(n)<zr;class Jt extends gi{static TYPE="YAxis";schema=bt;xBounds(){return r.bounds.max(this.lines.map(e=>e.xBounds()).filter(e=>r.bounds.isFinite(e)))}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),o=t.invert().reverse();if(this.renderAxis(e,o),this.renderLines(e,t),this.renderRules(e,o),s!=null)throw s}renderLines({xDataToDecimalScale:e,plot:t,canvases:s,exposure:o},i){if(!s.includes("gl")||sh(t))return;const a={region:t,dataToDecimalScale:new r.scale.XY(e,i),exposure:o};this.lines.forEach(l=>l.render(a))}renderRules({container:e,plot:t,canvases:s},o){if(!s.includes("upper2d"))return;const{location:i}=this.state,{render:a}=this.internal,l=r.box.construct(r.box.left(e),r.box.top(t),r.box.width(e),r.box.height(t)),u=a.scissor(l,r.xy.ZERO,["upper2d"]),c={container:e,plot:t,decimalToDataScale:o,location:i};this.rules.map(d=>d.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:t,viewport:s,hold:o,exposure:i},a){const[l,u]=this.dataToDecimalScale(o,this.dataBounds.bind(this),s);if(u!=null)throw u;const c=new r.scale.XY(e,l),d={region:t,dataToDecimalScale:c,exposure:i};return this.lines.map(f=>({...f.findByXValue(d,a),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType(qt.TYPE)}get rules(){return this.childrenOfType(it.TYPE)}}const rh=h.z.object({start:r.TimeStamp.z,end:r.TimeStamp.z});class Yr extends w.Leaf{static TYPE="range-annotation";schema=rh;afterUpdate(e){this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,w.use(e))}}const oh=x.ranger.payloadZ.extend({viewport:r.bounds.bounds}),bi=h.z.object({cursor:r.xy.xy.or(h.z.null()),hovered:oh.or(h.z.null()),count:h.z.number()});class en extends w.Leaf{static TYPE="range-provider";schema=bi;fetchedInitial=r.TimeRange.ZERO;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.draw=new Ee(t.render.upper2d,w.use(e)),t.requestRender=ln(e),t.runAsync=w.useErrorHandler(e),t.ranges??=new Map;const s=He(e);if(t.requestRender("tool"),s==null)return;t.client=s;const o=Qi(e,this.key);t.removeListener?.();const i=o.ranges.onSet(l=>{t.client!=null&&(r.color.isCrude(l.color)&&t.ranges.set(l.key,t.client.ranges.sugarOne(l)),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool"))}),a=o.ranges.onDelete(async l=>{t.ranges.delete(l),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool")});t.removeListener=()=>{i(),a()}}fetchInitial(e){const{internal:t}=this,{client:s,runAsync:o}=t;s==null||this.fetchedInitial.equals(e,r.TimeSpan.minutes(1))||(this.fetchedInitial=e,o(async()=>{(await s.ranges.retrieve(e)).forEach(a=>{r.color.isCrude(a.color)&&t.ranges.set(a.key,a)}),this.setState(a=>({...a,count:t.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:t,region:s,viewport:o,timeRange:i}=e;this.fetchInitial(i);const{draw:a,ranges:l}=this.internal,u=t.scale(r.box.xBounds(s)),c=this.state.cursor==null?null:this.state.cursor.x;let d=null;const f=a.canvas.scissor(r.box.construct({x:r.box.left(s),y:r.box.top(s)-35},{x:r.box.right(s),y:r.box.bottom(s)}));l.forEach(p=>{const g=r.color.colorZ.safeParse(p.color);if(!g.success)return;const T=g.data;let y=u.pos(Number(p.timeRange.start.valueOf()));const v=u.pos(Number(p.timeRange.end.valueOf()));if(v<r.box.left(s)||y>r.box.right(s))return;y=r.clamp(y,r.box.left(s)-2,r.box.right(s)-1);let R=!1;c!=null&&(R=r.bounds.contains({lower:y,upper:v},c)),R&&(d={key:p.key,parent:p.parent,name:p.name,color:p.color,labels:p.labels,timeRange:p.timeRange,viewport:{lower:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.start.valueOf())),upper:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.end.valueOf()))}}),a.container({region:r.box.construct({x:y,y:r.box.top(s)-1},{x:v,y:r.box.bottom(s)-1}),backgroundColor:r.color.setAlpha(T,.2),bordered:!1});const L=r.box.construct({x:y+1,y:r.box.top(s)-34},{x:v-1,y:r.box.top(s)-12});a.container({region:L,backgroundColor:r.box.width(L)<20?r.color.setAlpha(T,.4):k=>R?k.colors.gray.l2:k.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:r.color.setAlpha(T,.8)}),a.text({text:p.name,position:{x:y+8,y:r.box.top(s)-30},level:"small",shade:10,weight:500,maxWidth:v-y-16})}),f(),d!=null?this.setState(p=>({...p,hovered:d})):this.state.hovered&&this.setState(p=>({...p,hovered:null}))}}const ih={[Yr.TYPE]:Yr,[en.TYPE]:en},ah=bt;class tn extends gi{static TYPE="XAxis";schema=bt;render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,t.reverse()),this.renderYAxes(e,t),this.renderRanges(e,t),s!=null)throw s}findByXDecimal(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;return this.findByXValue(e,s.reverse().pos(t))}findByXValue(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;const i={...e,xDataToDecimalScale:s};return this.yAxes.map(a=>a.findByXValue(i,t)).flat()}renderYAxes(e,t){const s={...e,xDataToDecimalScale:t};this.yAxes.forEach(o=>o.render(s))}get yAxes(){return this.childrenOfType(Jt.TYPE)}get ranges(){return this.childrenOfType(en.TYPE)}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}renderRanges(e,t){const s=this.bounds(e.hold),o=r.bounds.min([s,r.TimeRange.MAX.numericBounds]),i=new r.TimeRange(o.lower,o.upper);this.ranges.forEach(a=>a.render({dataToDecimalScale:t,region:e.plot,viewport:e.viewport,timeRange:i}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const lh=r.xy.construct(12),ch=3,uh=14,hh=r.xy.construct(6),er=h.z.object({position:r.xy.xy.or(h.z.null()),textColor:r.color.colorZ.default(r.color.ZERO),backgroundColor:r.color.colorZ.default(r.color.ZERO),borderColor:r.color.colorZ.default(r.color.ZERO),ruleColor:r.color.colorZ.default(r.color.ZERO),ruleStrokeWidth:h.z.number().default(1),ruleStrokeDash:h.z.number().default(0)});class at extends w.Leaf{static TYPE="tooltip";schema=er;afterUpdate(e){const t=w.use(e);r.color.isZero(this.state.textColor)&&(this.state.textColor=t.colors.text),r.color.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=t.colors.gray.l1),r.color.isZero(this.state.borderColor)&&(this.state.borderColor=t.colors.border),r.color.isZero(this.state.ruleColor)&&(this.state.ruleColor=t.colors.gray.l7),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:t}=e,s=r.scale.XY.scale(r.box.DECIMAL).scale(t),o=r.scale.XY.scale(t).scale(r.box.DECIMAL),i=e.findByXDecimal(o.x.pos(this.state.position.x)),a=i.filter(y=>r.xy.isFinite(y.value)),{draw:l}=this.internal,u=a.reduce((y,v)=>y+v.position.x,0)/a.length,c=new r.TimeStamp(a.reduce((y,v)=>y+v.value.x,0)/a.length),d=s.x.pos(u);if(!r.bounds.contains(r.box.xBounds(t),d))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:t,position:d}),a.forEach(y=>{const v=s.pos(y.position);l.circle({fill:r.color.setAlpha(y.color,.5),radius:8,position:v}),l.circle({fill:r.color.setAlpha(y.color,.8),radius:5,position:v}),l.circle({fill:r.color.pickByContrast(y.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:v})});const f=o.pos(this.state.position),p={...r.location.TOP_LEFT};f.x>.6&&(p.x="right"),f.y>.6&&(p.y="bottom");let g=i.reduce((y,v)=>Math.max(y,v.label?.length??0),0);const T=c.toString("preciseDate","local").length;T>g&&(g=T),l.list({root:p,offset:lh,length:a.length+1,padding:hh,itemHeight:uh,spacing:ch,width:g*7+48,position:this.state.position,draw:(y,v)=>{let R="",L="",k=this.state.textColor;if(y===0)R="Time",L=c.toString("preciseDate","local");else{const C=a[y-1];R=C.label??"",L=r.math.smartRound(C.value.y,C.bounds).toString(),k=C.color}l.text({position:r.box.topLeft(v),text:R,level:"small",weight:500,color:k}),l.text({position:r.xy.translateY(r.box.topRight(v),-1),text:L,level:"small",justify:"right",code:!0,shade:10})}})}}const Si={[at.TYPE]:at},dh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Si,Tooltip:at,tooltipStateZ:er},Symbol.toStringTag,{value:"Module"})),Ti=h.z.enum(["one","two"]),tr=h.z.object({one:r.xy.xy.nullable(),two:r.xy.xy.nullable(),hover:r.xy.xy.nullable(),mode:Ti.default("one"),color:h.z.union([r.color.colorZ,h.z.object({verticalLine:r.color.colorZ.default(r.color.ZERO),horizontalLine:r.color.colorZ.default(r.color.ZERO),obliqueLine:r.color.colorZ.default(r.color.ZERO)})]).optional().default(r.color.ZERO),strokeWidth:h.z.number().default(1),strokeDash:h.z.number().default(2)}),fh=n=>n==="one"?"1":"2",ph=n=>n.colors.error.z,mh=n=>n.colors.secondary.z,gh=n=>n.colors.gray.l9,Ge=6,Ke=14,Qe=8,Ct=8,Rt=3,yh=9,xh=8,bh=2,Sh=2,Th=8,vh=5,wh=2,Eh=.5,Ch=.8,Pt=50,Lt=80,Rh=30,Ph=30,Lh=10,kh=40,_h=100,Oh=30,Re=15,Nr=8,Mh=10;class lt extends w.Leaf{static TYPE="measure";schema=tr;afterUpdate(e){const t=I.Context.use(e);this.internal.theme=w.use(e),this.internal.renderCtx=t,this.internal.draw=new Ee(t.upper2d,this.internal.theme),ie(e,"tool"),this.internal.dotColor=this.internal.theme.colors.text,this.internal.dotColorContrast=this.internal.theme.colors.textInverted}afterDelete(e){ie(e,"layout")}get verticalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}findPoint(e,t,s,o,i){const a=o!=null&&!r.xy.equals(t,o);if(s!=null&&!a){const c=e.findByXValue(s.x).filter(d=>Number.isFinite(d.value.x)&&Number.isFinite(d.value.y));return c.length>0?c.sort((d,f)=>r.xy.distance(s,d.value)-r.xy.distance(s,f.value))[0]:null}const l=i.pos(t),u=e.findByXDecimal(l.x).filter(c=>Number.isFinite(c.value.x)&&Number.isFinite(c.value.y));return u.length===0?null:u.sort((c,d)=>r.xy.distance(l,c.position)-r.xy.distance(l,d.position))[0]}find(e){const{one:t,two:s}=this.state;if(t==null||s==null)return null;const{dataOne:o,dataTwo:i,clickOne:a,clickTwo:l}=this.internal,u=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),c=this.findPoint(e,t,o,a,u);if(c==null)return null;(a==null||!r.xy.equals(t,a))&&(this.internal.dataOne={...c.value},this.internal.clickOne={...t});const d=this.findPoint(e,s,i,l,u);return d==null?null:((l==null||!r.xy.equals(s,l))&&(this.internal.dataTwo={...d.value},this.internal.clickTwo={...s}),[c,d])}drawLabelValue(e,t,s,o){const{draw:i}=this.internal,a=r.xy.construct(Ge),l=e.length*Qe,u=t.length*Ct,c=l+u+a.x*Rt,d=Ke+a.y*2,f=r.box.construct(s,c,d);i.container({region:f,backgroundColor:p=>p.colors.gray.l1}),i.text({text:e,position:r.xy.translate(r.box.topLeft(f),a),level:"small",weight:500,color:o(this.internal.theme)}),i.text({text:t,position:r.xy.translate(r.box.topRight(f),[-a.x-1,a.y-1]),level:"small",justify:"right",code:!0,shade:10})}drawCombinedDeltaLabel(e,t,s,o,i,a){const{draw:l,theme:u}=this.internal,c=r.xy.construct(Ge),d=Qe*5,f=Math.max(t.length,s.length,o.length),p=d+f*Ct+c.x*Rt,g=Ke,T=g*3+c.y*2;let y;if(a){const v=r.xy.translate(e,[-p/2,-T/2]);y=r.box.construct(v,p,T)}else if(y=r.box.construct(e,p,T),r.box.right(y)>r.box.right(i)){const v=r.xy.translateX(e,-p-Lt*2);y=r.box.construct(v,p,T)}l.container({region:y,backgroundColor:v=>v.colors.gray.l1}),this.drawPointLabelRow({region:y,label:"ΔX",value:t,labelColor:u.colors.error.z,yOffset:0,leftOffset:0}),this.drawPointLabelRow({region:y,label:"ΔY",value:s,labelColor:u.colors.secondary.z,yOffset:g,leftOffset:0}),this.drawPointLabelRow({region:y,label:"Slope",value:o,labelColor:u.colors.gray.l9,yOffset:g*2,leftOffset:0})}drawPointLabelRow(e){const{region:t,label:s,value:o,labelColor:i,yOffset:a,leftOffset:l}=e,{draw:u}=this.internal,c=r.xy.construct(Ge);u.text({text:s,position:r.xy.translate(r.box.topLeft(t),[c.x+l,c.y+a]),level:"small",weight:500,color:i}),u.text({text:o,position:r.xy.translate(r.box.topRight(t),[-c.x-1,c.y+a-1]),level:"small",justify:"right",code:!0,shade:10})}drawPointLabel(e){const{pointNumber:t,position:s,value:o,units:i,bounds:a,toTop:l,viewRegion:u,xDist:c}=e,{draw:d,theme:f}=this.internal,p=new r.TimeStamp(o.x),g=p.toString(p.formatBySpan(c),"local"),T=`${r.math.smartRound(o.y,a)} ${i??""}`,y=`${t}`,v=y.length*Qe,R=r.xy.construct(Ge),L=Qe,k=Math.max(g.length,T.length),C=v+Nr+L+k*Ct+R.x*Rt,Z=Ke,b=Z*2+R.y*2;let M=l?-(b+Re):Re,D=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b);(l&&r.box.top(D)<r.box.top(u)||!l&&r.box.bottom(D)>r.box.bottom(u))&&(M=l?Re:-(b+Re),D=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b)),d.container({region:D,backgroundColor:K=>K.colors.gray.l1}),d.text({text:y,position:r.xy.translate(r.box.topLeft(D),[R.x,R.y]),level:"small",weight:500,color:f.colors.gray.l9});const V=v+Nr;this.drawPointLabelRow({region:D,label:"X",value:g,labelColor:f.colors.error.z,yOffset:0,leftOffset:V}),this.drawPointLabelRow({region:D,label:"Y",value:T,labelColor:f.colors.secondary.z,yOffset:Z,leftOffset:V})}drawPointMarker(e,t){const{draw:s}=this.internal;s.circle({fill:r.color.setAlpha(t,Eh),radius:Th,position:e}),s.circle({fill:r.color.setAlpha(t,Ch),radius:vh,position:e}),s.circle({fill:r.color.pickByContrast(t,this.internal.dotColor,this.internal.dotColorContrast),radius:wh,position:e})}calculateYLabelPosition(e,t,s){return t?r.xy.translateX(e,Rh):s?r.xy.translateX(e,Ph):e}calculateXLabelPosition(e,t,s){return t?r.xy.translateY(e,kh):s?r.xy.translateY(e,Lh):e}calculateSlopeLabelPosition(e){const{basePos:t,yLabelPos:s,isVeryClose:o,isHorizontal:i,xPixelDist:a,yPixelDist:l}=e;return o?r.xy.translateX(t,Lt):i?r.xy.translateY(t,-35):Math.abs(t.x-s.x)<_h&&Math.abs(t.y-s.y)<Oh?a<l?r.xy.translateY(t,-35):r.xy.translateX(t,Lt):t}renderHover(e){if(this.state.hover==null)return;const t=this.state.hover,s=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),o=s.pos(t),i=e.findByXDecimal(s.pos(t).x);if(i.length===0)return;const a=i.sort((c,d)=>r.xy.distance(o,c.position)-r.xy.distance(o,d.position))[0],{draw:l}=this.internal,u=s.reverse().pos(a.position);l.circle({stroke:r.color.setAlpha(a.color,1),strokeWidth:bh,lineDash:Sh,radius:yh,position:u}),l.circle({fill:this.internal.theme.colors.gray.l3,radius:xh,position:u}),l.text({text:fh(this.state.mode),position:u,level:"small",align:"middle",justify:"center"})}render(e){if(this.deleted)return;this.renderHover(e);const t=this.find(e);if(t==null)return;const[s,o]=t,{draw:i}=this.internal,{strokeDash:a,strokeWidth:l}=this.state,u=r.scale.XY.scale(r.box.DECIMAL).scale(e.region),c=u.pos(s.position),d=u.pos(o.position),f=Math.abs(s.value.x-o.value.x),p=o.value.y-s.value.y,g=Math.abs(p);if(!Number.isFinite(f)||!Number.isFinite(g))return;const T=new r.TimeSpan(f),y=p/T.seconds,v=Math.abs(c.x-d.x),R=Math.abs(c.y-d.y),L=R<Pt,k=v<Pt,C=v<Pt||R<Pt;i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(c.x,d.y),stroke:this.verticalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,d.y),end:r.xy.construct(d.x,d.y),stroke:this.horizontalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(d.x,d.y),stroke:this.obliqueLineColor,lineDash:a,lineWidth:l}),this.drawPointMarker(c,s.color),this.drawPointMarker(d,o.color);const Z=`${r.math.smartRound(g,r.bounds.construct(g))} ${s.units??""}`,b=T.lessThan(r.TimeSpan.milliseconds(Mh))?r.TimeSpan.MICROSECOND:r.TimeSpan.MILLISECOND,M=T.truncate(b).toString();let D=r.math.smartRound(y,r.bounds.construct(Math.abs(y))).toString();if(s.units!=null&&s.units.length>0&&(D+=` ${s.units} / s`),C){const K=r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),ue=Qe*6,E=Math.max(M.length,Z.length,D.length),$=Ge,N=ue+E*Ct+$*Rt,Q=Ke*3+$*2,de=r.box.construct(r.xy.translate(K,[-N/2,-Q/2]),N,Q),ne=c.y<d.y,J=150,se=Ke*2+$*2,q=ne?-55:Re,bn=r.box.construct(r.xy.translate(c,[-J/2,q]),J,se),Sn=ne?Re:-55,Tn=r.box.construct(r.xy.translate(d,[-J/2,Sn]),J,se),vn=r.box.area(r.box.intersection(de,bn))>0,wn=r.box.area(r.box.intersection(de,Tn))>0,St=!vn&&!wn,En=St?K:r.xy.construct(Math.max(c.x,d.x)+Lt,(c.y+d.y)/2);this.drawCombinedDeltaLabel(En,M,Z,D,e.region,St)}else{const K=this.calculateYLabelPosition(r.xy.construct(c.x,(c.y+d.y)/2),C,k);this.drawLabelValue("ΔY",Z,K,mh);const ue=this.calculateXLabelPosition(r.xy.construct((c.x+d.x)/2,d.y),C,L);this.drawLabelValue("ΔX",M,r.xy.translateX(ue,-15),ph);const E=this.calculateSlopeLabelPosition({basePos:r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),yLabelPos:K,isVeryClose:C,isHorizontal:L,xPixelDist:v,yPixelDist:R});this.drawLabelValue("Slope",D,E,gh)}const V=c.y<d.y;this.drawPointLabel({pointNumber:1,position:c,value:s.value,units:s.units??null,bounds:s.bounds,toTop:V,viewRegion:e.region,xDist:T}),this.drawPointLabel({pointNumber:2,position:d,value:o.value,units:o.units??null,bounds:o.bounds,toTop:!V,viewRegion:e.region,xDist:T})}}const vi={[lt.TYPE]:lt},Ah=Object.freeze(Object.defineProperty({__proto__:null,Measure:lt,REGISTRY:vi,measureStateZ:tr,modeZ:Ti},Symbol.toStringTag,{value:"Module"})),wi=h.z.object({container:r.box.box,viewport:r.box.box,hold:h.z.boolean().default(!1),grid:h.z.record(h.z.string(),fi),visible:h.z.boolean().default(!0),clearOverScan:r.xy.crudeZ.default(r.xy.ZERO)}),Dh=h.z.record(h.z.string(),h.z.object({lower:h.z.number(),upper:h.z.number()})),Ei={getBounds:h.z.function({input:h.z.tuple([]),output:Dh})},Ih=(n,e)=>{const t=r.box.width(n)*Math.sqrt(r.box.height(n)),s=r.box.width(e)*Math.sqrt(r.box.height(e));return t/s},zh=["upper2d","lower2d","gl"],Yh=["upper2d"];class es extends w.Composite{static TYPE="LinePlot";schema=wi;methods=Ei;afterUpdate(e){this.internal.instrumentation=I.useInstrumentation(e,"lineplot"),this.internal.handleError=w.useErrorHandler(e),this.internal.renderCtx=I.Context.use(e),an(e,t=>{this.state.visible&&this.requestRender("low",t)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=I.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXDecimal(t,e)).flat()}findByXValue(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXValue(t,e)).flat()}get axes(){return this.childrenOfType(tn.TYPE)}get tooltips(){return this.childrenOfType(at.TYPE)}get measures(){return this.childrenOfType(lt.TYPE)}get exposure(){return Ih(this.state.viewport,this.state.container)}renderAxes(e,t){const s={...this.state,plot:e,canvases:t,exposure:this.exposure};this.axes.forEach(o=>o.render(s))}renderTooltips(e,t){const s={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:t};this.tooltips.forEach(o=>o.render(s))}getBounds(){const e={};return this.axes.forEach(t=>{const s=t.state.axisKey??t.key;e[s]=t.bounds(this.state.hold),t.yAxes.forEach(o=>{const i=o.state.axisKey??o.key;e[i]=o.bounds(this.state.hold)})}),e}renderMeasures(e){const t={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(s=>s.render(t))}calculatePlot(){return ju(this.state.grid,this.state.container)}render(e){const{instrumentation:t,renderCtx:s,handleError:o}=this.internal;if(this.deleted){t.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return t.L.debug("not visible, skipping render",{key:this.key}),({canvases:d})=>s.erase(this.state.container,this.state.clearOverScan,...d);const i=this.calculatePlot();t.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:e});const a=r.xy.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,e.filter(d=>d!=="gl")),u=s.scissor(i,r.xy.ZERO,e.filter(d=>d==="gl"));try{this.renderAxes(i,e),this.renderTooltips(i,e),this.renderMeasures(i)}catch(d){o(d,"failed to render line plot")}finally{l(),u()}t.L.debug("rendered",{key:this.key});const c=r.box.copy(this.state.container);return({canvases:d})=>s.erase(c,this.state.clearOverScan,...d)}requestRender(e,t){const{renderCtx:s}=this.internal;let o=zh;t==="tool"&&(o=Yh),s.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(o),priority:e,canvases:o})}}const Nh={[es.TYPE]:es,[tn.TYPE]:tn,[Jt.TYPE]:Jt},Ci=h.z.object({region:r.box.box,wheelPos:h.z.number(),scrolling:h.z.boolean(),empty:h.z.boolean(),visible:h.z.boolean(),telem:At.default(to),font:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),overshoot:r.xy.xy.default({x:0,y:0})}),Zh=.98,Je="lower2d",Uh={offset:0n,offsetRef:0n,scrollRef:0};class ct extends w.Leaf{static TYPE="log";static z=Ci;schema=ct.z;values=new r.MultiSeries([]);scrollState=Uh;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?this.internal.textColor=t.theme.colors.gray.l11:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem);const{scrolling:s,wheelPos:o}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:u,values:c}=this,d=Math.ceil((o-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(d)),u.offset<c.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=c.alignmentBounds.lower,this.setState(f=>({...f,wheelPos:this.prevState.wheelPos}))),u.offset>=c.alignmentBounds.upper&&this.setState(f=>({...f,scrolling:!1}))}const[a,l]=this.internal.telem.value();this.values=l,this.checkEmpty(),t.stopListeningTelem?.(),t.stopListeningTelem=t.telem.onChange(()=>{const[u,c]=this.internal.telem.value();this.checkEmpty(),this.values=c,this.requestRender()}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender()}checkEmpty(){const e=this.values.length===0;e!==this.state.empty&&this.setState(t=>({...t,empty:e}))}afterDelete(){const{telem:e,render:t}=this.internal;e.cleanup?.(),t.erase(r.box.construct(this.state.region),r.xy.ZERO,Je)}requestRender(){const{render:e}=this.internal;e.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(),priority:"high",canvases:[Je]})}get lineHeight(){return this.internal.theme.typography[this.state.font].size*this.internal.theme.sizes.base}get totalHeight(){return Math.ceil(this.values.length*this.lineHeight)}get visibleLineCount(){return Math.min(Math.floor((r.box.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,t=this.state.region;if(r.box.areaIsZero(t))return;if(!this.state.visible)return()=>e.erase(t,r.xy.ZERO,Je);let s;if(!this.state.scrolling)s=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));s=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const o=this.state.region,i=e[Je],a=new Ee(i,this.internal.theme),l=e.scissor(o,r.xy.ZERO,[Je]);this.renderElements(a,s),this.renderScrollbar(a),l();const u=r.box.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const t=this.state.region,s=r.box.height(t)/this.totalHeight*r.box.height(t);if(s>=r.box.height(t)*Zh)return;let o=r.box.bottom(t)-s;this.state.scrolling&&(o-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*r.box.height(t)),o<0&&(o=r.box.top(t)),e.container({region:r.box.construct({x:r.box.right(t)-6,y:o},{width:6,height:s}),bordered:!1,backgroundColor:i=>i.colors.gray.l6})}renderElements(e,t){const s=this.state.region;let o=0;for(const i of t){const a=this.values.dataType.equals(r.DataType.JSON)?JSON.stringify(i):i.toString();e.text({text:a,level:this.state.font,shade:11,position:r.xy.translate(r.box.topLeft(s),{x:6,y:o*this.lineHeight+6}),code:!0}),o++}}}const Bh={[ct.TYPE]:ct},Fh="roles",$h={channel:x.access.role.SET_CHANNEL_NAME,schema:x.access.role.roleZ,onChange:({store:n,changed:e})=>{n.roles.set(e.key,e)}},qh={channel:x.access.role.DELETE_CHANNEL_NAME,schema:x.access.role.keyZ,onChange:({store:n,changed:e})=>n.roles.delete(e)},Hh={listeners:[$h,qh]},jh="ranges",Wh={channel:x.ranger.SET_CHANNEL_NAME,schema:x.ranger.payloadZ,onChange:async({store:n,changed:e,client:t})=>{const s=t.ranges.sugarOne(e),o=n.ranges.get(e.key);let i;o?.labels==null&&(i=await s.retrieveLabels());let a=null;o?.parent==null&&(a=await s.retrieveParent()),n.ranges.set(e.key,l=>t.ranges.sugarOne({...s.payload,labels:l?.labels??i,parent:l?.parent??a}))}},Vh={channel:x.ranger.DELETE_CHANNEL_NAME,schema:x.ranger.keyZ,onChange:({store:n,changed:e})=>n.ranges.delete(e)},Xh={equal:(n,e)=>r.deep.equal(n.payload,e.payload),listeners:[Wh,Vh]},Ri=h.z.object({authority:r.control.authorityZ.optional(),valid:h.z.boolean().optional()}).default({authority:void 0,valid:!1}),Pi=h.z.object({triggered:h.z.boolean(),status:r.status.statusZ(Ri),sink:hn.default(un),source:Ls.default(Cs)});class ts extends w.Leaf{static TYPE="Chip";schema=Pi;afterUpdate(e){const{internal:t}=this,{sink:s,source:o}=this.state;t.source=U(e,o,t.source),t.sink=je(e,s,t.sink),this.state.triggered&&!this.prevState.triggered&&t.sink.set(this.state.status.details?.authority!==r.control.ABSOLUTE_AUTHORITY),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();r.deep.equal(e,this.state.status)||this.setState(t=>({...t,status:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}render(){}}const Li=h.z.object({}),Zr="control-state-provider",ki=x.control.stateZ.extend({subjectColor:r.color.colorZ});class ut extends w.Composite{static TYPE="StateProvider";schema=Li;colors=new Map;colorOverrides=new Map;tracker;disconnectTrackerChange;obs=new r.observe.Observer;static use(e){return e.get(Zr)}afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e,"control-state");const s=w.use(e);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l8;const o=He(e);if(t.client!=null&&o===t.client)return;t.client=o,e.set(Zr,this),w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client))},"failed to open control state tracker")}async maybeCloseTracker(){this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),this.disconnectTrackerChange?.(),await this.tracker.close(),this.tracker=void 0)}afterDelete(e){w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}setColorOverrides(e){const t=Object.entries(e);if(!(t.length===this.colorOverrides.size&&t.every(([s,o])=>{const i=this.colorOverrides.get(s);return i!=null&&r.color.equals(i,o)}))){this.colorOverrides.clear();for(const[s,o]of t)this.colorOverrides.set(s,r.color.construct(o));this.obs.notify([])}}get(e){return Array.isArray(e)?r.unique.unique(e).map(t=>this.getOne(t)).filter(t=>t!=null):this.getOne(e)}getOne(e){if(this.tracker==null)return;const t=this.tracker.states.get(e);if(t!=null)return{...t,subjectColor:this.colorOverrides.get(t.subject.key)??this.colors.get(t.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:t}=this,{instrumentation:s}=t;try{this.tracker=await e.control.openStateTracker()}catch{s.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(o=>{if(s.L.debug("transfer",{transfers:o.map(i=>x.control.transferString(i))}),this.tracker==null)throw new x.UnexpectedError("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(o)})}updateColors(e){const t=e.subjects(),s=t.map(a=>a.key),o=Array.from(this.colors.values());this.colors.forEach((a,l)=>!s.includes(l)&&this.colors.delete(l));const{palette:i}=this.internal;t.forEach(a=>{if(this.colors.has(a.key))return;const l=i.find(u=>!o.includes(u))??i[0];this.colors.set(a.key,l),o.push(l)})}}const _i=h.z.enum(["acquired","released","overridden","failed"]),Oi=h.z.object({name:h.z.string(),authority:h.z.number().default(0),status:_i.optional(),needsControlOf:x.channel.keyZ.array().default([])}),ns={acquire:h.z.function({input:h.z.tuple([]),output:h.z.void()}),release:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class Fe extends w.Composite{static TYPE="Controller";static METHODS=ns;schema=Oi;methods=ns;registry=new Map;writer;acquirePromise;afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e),t.addStatus=w.useAdder(e),t.runAsync=w.useErrorHandler(e);const s=He(e),o=ut.use(e);t.stateProv=o,t.telemCtx=No(e,this,t.telemCtx),t.client=s}afterDelete(){const{internal:e}=this;e.runAsync(()=>this.doRelease(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const t=new Set([]);for(const o of this.registry.keys())(await o.needsControlOf(e)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);r.compare.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==r.compare.EQUAL&&this.setState(o=>({...o,needsControlOf:s}))}acquire(){this.internal.runAsync(()=>this.doAcquire(),"failed to acquire control")}release(){this.internal.runAsync(()=>this.doRelease(),"failed to release control")}async doAcquire(){if(this.acquirePromise!=null)return await this.acquirePromise;this.acquirePromise=this.doAcquireImpl();try{await this.acquirePromise}finally{this.acquirePromise=void 0}}async doAcquireImpl(){const{client:e,addStatus:t}=this.internal;if(e==null)return t({message:`Cannot acquire control on ${this.state.name} because no Core has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const s=this.state.needsControlOf;if(s.length===0)return t({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const o=x.TimeStamp.now().sub(r.TimeSpan.milliseconds(1));this.writer=await e.openWriter({start:o,channels:s,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(s){if(this.setState(o=>({...o,status:"failed"})),!(s instanceof Error))throw s;t({variant:"error",message:`${this.state.name} failed to acquire control`,description:s.message})}}async doRelease(){try{await this.writer?.close()}catch(e){this.internal.addStatus({message:`${this.state.name} failed to release control: ${e.message}`,variant:"error"})}finally{this.setState(e=>({...e,status:"released"})),this.writer=void 0}}static isRetryable(e){return sr.StreamClosed.matches(e)||sr.Unreachable.matches(e)}async closeWriter(){try{await this.writer?.close()}catch(e){if(!Fe.isRetryable(e))throw e}finally{this.writer=void 0}}async withRetry(e){this.writer==null&&await this.doAcquire();try{await e()}catch(t){if(!Fe.isRetryable(t))throw t;await this.closeWriter(),await this.doAcquire(),await e()}}async set(e){await this.withRetry(async()=>this.writer?.write(await e()))}async setAuthority(e,t){await this.withRetry(async()=>this.writer?.setAuthority(Object.fromEntries(e.map(s=>[s,t]))))}async releaseAuthority(e){await this.withRetry(async()=>this.writer?.setAuthority(Object.fromEntries(e.map(t=>[t,this.state.authority]))))}deleteTelem(e){this.registry.delete(e),this.updateNeedsControlOf()}create(e){const{internal:t}=this,o=(()=>{switch(e.type){case nn.TYPE:{const i=new nn(this,t.runAsync,e.props);return this.registry.set(i,null),i}case rn.TYPE:{const i=new rn(this,this.internal.stateProv,e.props);return this.registry.set(i,null),i}case sn.TYPE:return new sn(this,t.runAsync,e.props);default:return null}})();return o!=null&&this.updateNeedsControlOf(),o}}const Mi=h.z.object({channel:h.z.number()});class nn extends mn{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=Mi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}invalidate(){}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){if(this.props.channel===0)return[];const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(...e){this.runAsync(async()=>{const{client:t}=this.controller.internal;if(t==null)throw new x.DisconnectedError("No Core connected");if(this.props.channel===0)throw new x.ValidationError("No command channel specified for actuator");await this.controller.set(async()=>{const s=await t.channels.retrieve(this.props.channel),o={[s.key]:e};if(s.index!==0){const i=await t.channels.retrieve(s.index),a=x.TimeStamp.now();o[i.key]=Array.from({length:e.length},(l,u)=>a.add(r.TimeSpan.nanoseconds(u)))}return o})},"Failed to command channel")}}const Gh=n=>({type:nn.TYPE,props:n,variant:"sink",valueType:"number"}),Ai=h.z.object({authority:h.z.number().default(x.control.ABSOLUTE_AUTHORITY),channel:h.z.number()});class sn extends mn{static TYPE="acquire-channel-control";controller;runAsync;schema=Ai;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(e){this.runAsync(async()=>{const{controller:t}=this,{client:s}=t.internal;if(s==null)return;const o=await s.channels.retrieve(this.props.channel),i=[o.key];o.index!==0&&i.push(o.index),e?await this.controller.setAuthority(i,this.props.authority):await this.controller.releaseAuthority(i)},"failed to set channel authority")}}const Kh=n=>({type:sn.TYPE,props:n,variant:"sink",valueType:"boolean"}),Di=h.z.object({channel:h.z.number()}),Qh=h.z.object({valid:h.z.boolean(),color:r.color.colorZ.optional(),authority:h.z.number()});class rn extends W{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=Di;constructor(e,t,s){super(s),this.prov=t,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const t=r.control.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(s=>{s.length>0&&t(s).length===0||this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=x.TimeStamp.now();if(this.props.channel===0)return{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"No Channel",time:e,details:{valid:!1,authority:0}};const t=this.prov.get(this.props.channel);return t==null?{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:e,details:{valid:!0,color:void 0,authority:0}}:{name:this.controller.key,key:t.subject.key,variant:t.subject.key===this.controller.key?"success":"error",message:`Controlled by ${t.subject.name}`,time:e,details:{valid:!0,color:t.subjectColor,authority:t.authority}}}cleanup(){this.controller.deleteTelem(this),this.stopListening?.()}}const Jh=n=>({type:rn.TYPE,props:n,variant:"source",valueType:"status"}),Ii=h.z.object({color:r.color.colorZ.optional()}).default({color:void 0}),zi=h.z.object({statusSource:Ls.default(Cs),colorSource:dn.default(ft),status:r.status.statusZ(Ii),color:r.color.colorZ.optional()});class ss extends w.Leaf{static TYPE="Indicator";schema=zi;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:t}=this,{statusSource:s,colorSource:o}=this.state;t.statusSource=U(e,s,t.statusSource),t.colorSource=U(e,o,t.colorSource),this.updateState(),this.stopListeningStatus?.(),this.stopListeningColor?.(),this.stopListeningStatus=t.statusSource.onChange(this.updateState.bind(this)),this.stopListeningColor=t.colorSource.onChange(this.updateState.bind(this))}afterDelete(){this.internal.statusSource.cleanup?.(),this.internal.colorSource.cleanup?.()}render(){}updateState(){const e=this.internal.colorSource.value(),t=this.internal.statusSource.value();r.color.equals(e,this.state.color)&&t.message===this.state.status.message&&r.color.equals(t.details?.color,this.state.status.details?.color)||this.setState(s=>({...s,color:e,status:t}))}}const Yi=h.z.object({needsControlOf:x.channel.keyZ.array(),states:ki.array(),colors:h.z.record(h.z.string(),h.z.string()).default({})});class rs extends w.Leaf{static TYPE="Legend";schema=Yi;afterUpdate(e){const{internal:t}=this;t.stateProv=ut.use(e),t.stateProv.setColorOverrides(this.state.colors);const s=this.state.needsControlOf;t.disconnectStateProv?.();const o=r.control.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(a=>({...a,states:i})),t.disconnectStateProv=t.stateProv.onChange(a=>{if(a.length>0&&o(a).length===0)return;const l=t.stateProv.get(s);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const ed={[Fe.TYPE]:Fe,[ut.TYPE]:ut,[ss.TYPE]:ss,[ts.TYPE]:ts,[rs.TYPE]:rs},Ni=["fire","momentary","pulse"],td=h.z.enum(Ni),Zi=h.z.object({sink:hn.default(un),mode:td.default("fire")}),os={onMouseDown:h.z.function({input:h.z.tuple([]),output:h.z.void()}),onMouseUp:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class is extends w.Leaf{static TYPE="Button";static METHODS=os;schema=Zi;methods=os;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=je(e,t,this.internal.sink)}onMouseDown(){const{mode:e}=this.state;e==="momentary"?this.internal.sink.set(!0):e==="pulse"&&this.internal.sink.set(!0,!1)}onMouseUp(){const{mode:e}=this.state;e==="fire"?this.internal.sink.set(!0):e==="momentary"&&this.internal.sink.set(!1)}afterDelete(){this.internal.sink.cleanup?.()}}const nd={[is.TYPE]:is},sd=h.z.object({region:r.box.box,clearOverScan:r.xy.crudeZ.default(0),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().default(1e3)}),Ur=["upper2d","lower2d"];class $e extends w.Composite{static TYPE="Table";static stateZ=sd;schema=$e.stateZ;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.handleError=w.useErrorHandler(e),t.autoRenderInterval??=setInterval(()=>this.state.visible&&this.requestRender("low"),this.state.autoRenderInterval),an(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high")}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const e=r.box.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:t,handleError:s}=this.internal,o=r.scale.XY.translate(r.box.topLeft(this.state.region)),i=t.scissor(this.state.region,r.xy.construct(this.state.clearOverScan),Ur);try{for(const a of this.children)a.render({viewportScale:o})}catch(a){s(a,"Failed to render table")}finally{i()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${$e.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:Ur})}}const rd={[$e.TYPE]:$e};h.z.enum(["small","medium","large","huge"]);const od=h.z.object({box:r.box.box,telem:fn.default(Es),backgroundTelem:dn.default(ft),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),units:h.z.string().default("RPM"),bounds:r.bounds.bounds.default(r.bounds.construct(0,100)),barWidth:h.z.number().default(12)}),id=["upper2d","lower2d"];class ht extends w.Leaf{static TYPE="gauge";static z=od;schema=ht.z;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?t.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>this.requestRender()),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),t.strokeColor=r.color.isZero(this.state.color)?t.theme.colors.visualization.palettes.default[0]:this.state.color;const s=this.state.box,o=r.box.width(s)/2,{barWidth:i}=this.state;t.outerRadius=o-8,t.innerRadius=t.outerRadius-i;const a=Math.PI/2;t.gaugeStartAngle=3*Math.PI/4,t.gaugeAngleRange=2*Math.PI-a,t.gaugeEndAngle=t.gaugeStartAngle+t.gaugeAngleRange,t.labelRadius=t.outerRadius+12,t.labelInwardShift=12,t.centerPos=r.box.center(s);const l=t.centerPos.y+t.labelRadius*Math.sin(t.gaugeStartAngle)+6;t.minLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeStartAngle)+t.labelInwardShift,l),t.maxLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeEndAngle)-t.labelInwardShift,l),t.valueTextPos=r.xy.translateY(t.centerPos,-6),t.unitsTextPos=r.xy.translateY(t.centerPos,r.box.height(s)/9),t.textLevel=this.state.level,t.labelLevel=ge.downLevel(ge.downLevel(t.textLevel)),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.render.erase(r.box.construct(this.state.box),r.xy.ZERO,...id):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}render({viewportScale:e=r.scale.XY.IDENTITY}){const{internal:t}=this,s=t.render.upper2d.applyScale(e),o=new Ee(s,t.theme),i=t.telem.value(),{lower:a,upper:l}=this.state.bounds,u=Number(i),c=r.bounds.clamp(this.state.bounds,u),d=l-a,f=d===0?0:(c-a)/d,p=t.gaugeStartAngle+f*t.gaugeAngleRange;o.text({text:i,position:t.valueTextPos,shade:10,level:t.textLevel,align:"middle",justify:"center",weight:450,code:!0,useAtlas:!0}),o.text({text:this.state.units,position:t.unitsTextPos,shade:8,level:ge.downLevel(t.textLevel),align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:a.toString(),position:t.minLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:l.toString(),position:t.maxLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.circle({stroke:t.theme.colors.gray.l5,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:t.gaugeEndAngle},lineCap:"round"}),o.circle({stroke:t.strokeColor,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:p},lineCap:"round"})}}const ad={[ht.TYPE]:ht},Ui=h.z.object({sink:io.default(eo)}),as={set:h.z.function({input:h.z.tuple([h.z.string()]),output:h.z.void()})};class ls extends w.Leaf{static TYPE="Input";static METHODS=as;schema=Ui;methods=as;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=je(e,t,this.internal.sink)}set(e){this.internal.sink.set(e)}afterDelete(){this.internal.sink.cleanup?.()}}const ld={[ls.TYPE]:ls},Bi=h.z.object({enabled:h.z.boolean(),source:Rs.default(vs)});class cs extends w.Leaf{static TYPE="Light";schema=Bi;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const cd={[cs.TYPE]:cs},Fi=h.z.object({value:h.z.number(),sink:oo.default(Jr),source:Ps.default(ws)}),us={set:h.z.function({input:h.z.tuple([h.z.number()]),output:h.z.void()})};class hs extends w.Leaf{static TYPE="Setpoint";static METHODS=us;schema=Fi;methods=us;afterUpdate(e){const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=je(e,t,o.sink),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())}set(e){this.internal.sink.set(e)}updateValue(){const e=this.internal.source.value();e===this.state.value||isNaN(e)||this.setState(t=>({...t,value:e}))}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.source.cleanup?.(),e.sink.cleanup?.()}}const ud={[hs.TYPE]:hs},hd=h.z.object({key:h.z.string(),value:h.z.number()}),$i=h.z.object({key:h.z.string().nullable().default(null),options:h.z.array(hd).default([]),source:Ps.default(ws)});class ds extends w.Leaf{static TYPE="StateIndicator";schema=$i;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateMatchedOption(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateMatchedOption())}updateMatchedOption(){const e=this.internal.source.value();if(isNaN(e))return;const s=this.state.options.find(o=>o.value===e)?.key??null;s!==this.state.key&&this.setState(o=>({...o,key:s}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const dd={[ds.TYPE]:ds},qi=h.z.object({enabled:h.z.boolean(),sink:hn.default(un),source:Rs.default(vs)}),fs={toggle:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ps extends w.Leaf{static TYPE="Toggle";static METHODS=fs;schema=qi;methods=fs;afterUpdate(e){this.internal.addStatus=w.useOptionalAdder(e);const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=je(e,t,o.sink),this.updateEnabledState(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateEnabledState())}toggle(){const{enabled:e}=this.state;this.internal.sink.set(!e)}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const fd={[ps.TYPE]:ps},An={useAtlas:!0},pd=h.z.object({box:r.box.box,telem:fn.default(Es),backgroundTelem:dn.default(ft),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),stalenessTimeout:h.z.number().default(5),stalenessColor:r.color.colorZ.default(r.color.ZERO),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),useWidthForBackground:h.z.boolean().default(!1),valueBackgroundShift:r.xy.xy.default(r.xy.ZERO),valueBackgroundOverScan:r.xy.xy.default(r.xy.ZERO)}),md=["upper2d","lower2d"];class qe extends w.Leaf{static TYPE="value";static z=pd;schema=qe.z;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.theme=w.use(e),t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>{t.lastReceived=performance.now(),this.requestRender()}),t.fontString=et.fontString(t.theme,{level:this.state.level,code:!0}),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(r.box.construct(this.state.box),r.xy.ZERO,...md):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}get fontHeight(){const{theme:e}=this.internal;return e.typography[this.state.level].size*e.sizes.base}maybeUpdateWidth(e){const{theme:t}=this.internal,s=e+t.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<s||this.state.minWidth>s&&this.state.width!==this.state.minWidth?this.setState(o=>({...o,width:Math.max(s,o.minWidth)})):this.state.width-this.fontHeight>s&&this.setState(o=>({...o,width:Math.max(s,o.minWidth)}))}getTextColor(){const{theme:e}=this.internal;return performance.now()-this.internal.lastReceived>this.state.stalenessTimeout*1e3?r.color.isZero(this.state.stalenessColor)?e.colors.warning.m1:this.state.stalenessColor:r.color.isZero(this.state.color)?r.color.pickByContrast(e.colors.border,e.colors.gray.l11,e.colors.gray.l0):r.color.pickByContrast(e.colors.border,e.colors.gray.l11,this.state.color)}render({viewportScale:e=r.scale.XY.IDENTITY}){const{renderCtx:t,telem:s,backgroundTelem:o,fontString:i,requestRender:a}=this.internal,{location:l,box:u}=this.state;if(r.box.areaIsZero(u))return;const c=r.box.topLeft(u),d=r.box.width(u),f=r.box.height(u),p=t.lower2d.applyScale(e);let g=s.value();p.font=i;const T=this.fontHeight,y=g[0]=="-";y&&(g=g.slice(1));const{theme:v}=this.internal,R=p.textDimensions(g,An),L=R.width+v.sizes.base,k=R.height;a==null&&t.erase(r.box.construct(this.prevState.box)),this.maybeUpdateWidth(L);const C={...r.xy.ZERO};l.x==="left"?C.x=6+T*.75:l.x==="center"&&(C.x=d/2-L/2),l.y==="center"&&(C.y=f/2+k/2);const Z=r.xy.translate(c,C);if(this.state.backgroundTelem.type!=ft.type){const M=o.value();if(!r.color.isZero(M)){p.fillStyle=r.color.hex(M);const V=this.state.useWidthForBackground?this.state.width??this.state.minWidth:r.box.width(u);p.fillRect(...r.xy.couple(r.xy.translate(c,this.state.valueBackgroundShift)),V+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y)}}const b=this.getTextColor();p.fillStyle=r.color.hex(b),y&&p.fillText("-",...r.xy.couple(r.xy.translateX(Z,-T*.6)),void 0,An),p.fillText(g,...r.xy.couple(Z),void 0,An)}}const Hi={[qe.TYPE]:qe},gd=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Hi,Value:qe},Symbol.toStringTag,{value:"Module"}));exports.AcquireChannelControl=sn;exports.AuthoritySource=rn;exports.Base=we;exports.Bottom=ui;exports.Button=is;exports.Canvas=Ht;exports.Chip=ts;exports.Client=$r;exports.Controller=Fe;exports.Diagram=$l;exports.Diagram$1=xe;exports.FLUX_STORE_CONFIG=Hh;exports.FLUX_STORE_CONFIG$1=da;exports.FLUX_STORE_CONFIG$2=Xh;exports.FLUX_STORE_KEY=Fh;exports.FLUX_STORE_KEY$1=ca;exports.FLUX_STORE_KEY$2=jh;exports.Gauge=ht;exports.Indicator=ss;exports.Input=ls;exports.Legend=rs;exports.Light=cs;exports.Line=qt;exports.LinePlot=es;exports.Log=ct;exports.MODES=Ni;exports.Measure=lt;exports.PROVIDER_TYPE=ys;exports.PROVIDER_TYPE$1=yn;exports.Provider=_t;exports.Provider$1=en;exports.REGISTRY=Nh;exports.REGISTRY$1=ad;exports.REGISTRY$10=ud;exports.REGISTRY$11=xi;exports.REGISTRY$12=ih;exports.REGISTRY$13=vi;exports.REGISTRY$14=Nl;exports.REGISTRY$15=cd;exports.REGISTRY$16=ld;exports.REGISTRY$17=Xo;exports.REGISTRY$18=ed;exports.REGISTRY$19=Vo;exports.REGISTRY$2=rd;exports.REGISTRY$20=nd;exports.REGISTRY$3=Bh;exports.REGISTRY$4=Hi;exports.REGISTRY$5=Si;exports.REGISTRY$6=fd;exports.REGISTRY$7=jo;exports.REGISTRY$8=Hr;exports.REGISTRY$9=dd;exports.RELATIONSHIPS_FLUX_STORE_KEY=ta;exports.RELATIONSHIP_FLUX_STORE_CONFIG=oa;exports.RESOURCES_FLUX_STORE_KEY=na;exports.RESOURCE_FLUX_STORE_CONFIG=la;exports.Right=di;exports.Rule=it;exports.ScopedUnaryStore=Br;exports.SetChannelValue=nn;exports.Setpoint=hs;exports.StateIndicator=ds;exports.StateProvider=ut;exports.Table=$e;exports.Toggle=ps;exports.Tooltip=at;exports.Top=hi;exports.Value=qe;exports.XAxis=tn;exports.YAxis=Jt;exports.ZERO_CONTEXT_VALUE=ms;exports.acquireChannelControl=Kh;exports.acquireChannelControlPropsZ=Ai;exports.aether=th;exports.authoritySource=Jh;exports.authoritySourceDetailsZ=Qh;exports.authoritySourceProps=Di;exports.axisStateZ=Qs;exports.baseAxisStateZ=bt;exports.buttonMethodsZ=os;exports.buttonStateZ=Zi;exports.cachedRetrieveForSubject=Vr;exports.canvas=Fl;exports.canvasStateZ=Bs;exports.channelData=po;exports.chipStateZ=Pi;exports.chipStatusDetailsZ=Ri;exports.color=Oe;exports.colorGradient=_o;exports.control=an;exports.controllerMethodsZ=ns;exports.controllerStateZ=Oi;exports.createRegistry=ea;exports.createStore=Fr;exports.diagramStateZ=Fs;exports.external=Rl;exports.indicatorStateZ=zi;exports.indicatorStatusDetailsZ=Ii;exports.interpolate=cn;exports.interpolateNumber=st;exports.interpolateRgb=Yn;exports.interpolateString=Qr;exports.legendStateZ=Yi;exports.linePlotMethodsZ=Ei;exports.linePlotStateZ=wi;exports.logState=Ci;exports.measure=Ah;exports.measureStateZ=tr;exports.methodsZ=as;exports.methodsZ$1=us;exports.newCanvas=ci;exports.newTickFactory=Qn;exports.parseAutoBounds=yi;exports.partialUpdate=Wi;exports.provider=Ki;exports.providerStateZ=jr;exports.providerStateZ$1=bi;exports.providerStateZ$2=Us;exports.regions=me;exports.request=ie;exports.retrieveForSubject=fa;exports.rollingAverage=Lo;exports.rollingAverageProps=Ys;exports.ruleStateZ=Js;exports.scaleNumber=Mo;exports.scopeStore=Dn;exports.setChannelValue=Gh;exports.setChannelValuePropsZ=Mi;exports.setpoint=wo;exports.sinkPipeline=uo;exports.sinkPipelinePropsZ=Ms;exports.sourcePipeline=co;exports.sourcePipelinePropsZ=_s;exports.stateProviderStateZ=Li;exports.stateZ=Wo;exports.stateZ$1=Ui;exports.stateZ$2=Bi;exports.stateZ$3=Fi;exports.stateZ$4=$i;exports.statusZ=_i;exports.streamChannelData=mo;exports.streamChannelValue=go;exports.streamChannelValuePropsZ=As;exports.stringSourceSpecZ=fn;exports.stringifyNumber=Po;exports.stringifyNumberProps=zs;exports.sugaredStateZ=ki;exports.tickFactoryProps=Ks;exports.tickType=Gs;exports.toggleMethodsZ=fs;exports.toggleStateZ=qi;exports.tooltip=dh;exports.tooltipStateZ=er;exports.useOptionalRequestor=bs;exports.useRequestor=ln;exports.value=gd;exports.withinBounds=Eo;exports.withinBoundsProps=Is;exports.withinSizeThreshold=pi;exports.xAxisStateZ=ah;exports.yAxisStateZ=nh;
|