@synnaxlabs/pluto 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Animated-BAoBw9cC.cjs → Animated-BOjwPkTJ.cjs} +1 -1
- package/dist/{Animated-DkZIfEYP.js → Animated-ByIJT_wA.js} +2 -2
- package/dist/{Item-BjErngVu.cjs → Item-Bamd13Tl.cjs} +1 -1
- package/dist/{Item-C7Q_zqsK.js → Item-CQ2ZuDfi.js} +8 -8
- package/dist/{LinePlot-rWkRDg70.js → LinePlot-Ci-61YDW.js} +116 -122
- package/dist/LinePlot-D4V1ltNT.cjs +24 -0
- package/dist/{Link-DIP4E5h4.cjs → Link-Cm6yn4zC.cjs} +1 -1
- package/dist/{Link-DkPbZ9Vw.js → Link-ZlOdu4jA.js} +1 -1
- package/dist/{Pack-ClLR2ywa.cjs → Pack-CyaEXvnu.cjs} +1 -1
- package/dist/{Pack-D8EcIVa2.js → Pack-DNCFnyuR.js} +1 -1
- package/dist/{Toggle-CZlnDV1Y.js → Toggle-DlYB4nmh.js} +10838 -10799
- package/dist/{Toggle-Dwz8HiqJ.cjs → Toggle-vgmhy8wZ.cjs} +56 -56
- package/dist/{Video-xr1Ey5qV.cjs → Video-g30B90s-.cjs} +1 -1
- package/dist/{Video-CI9sBV9l.js → Video-jaT7Y97L.js} +1 -1
- package/dist/{aggregator-D6gAHK4j.js → aggregator-CWsCIyed.js} +1276 -1258
- package/dist/aggregator-DX8ts24k.cjs +77 -0
- package/dist/align.cjs +1 -1
- package/dist/align.js +1 -1
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/css-Bo-hsQHb.cjs +1 -0
- package/dist/{css-DnIb4t_E.js → css-Csw1Dn4s.js} +449 -446
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -2
- package/dist/dropdown.cjs +1 -1
- package/dist/dropdown.js +1 -1
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +5 -5
- package/dist/{external-CetHCRLx.js → external-2PznkZYs.js} +36 -36
- package/dist/{external-BxiJID8F.js → external-4ikhWnyq.js} +2 -2
- package/dist/{external-CIm5lpCQ.cjs → external-BS9Bfsj3.cjs} +1 -1
- package/dist/{external-wgG3P6Dp.js → external-BTnFzhMM.js} +1 -1
- package/dist/{external-BeoanEV1.js → external-BpeQ9rNJ.js} +144 -133
- package/dist/external-Bt_kX5KM.cjs +1 -0
- package/dist/{external-C-tizEE4.js → external-CEcxrva2.js} +5 -5
- package/dist/{external-AQutxNrw.cjs → external-CMEDU76u.cjs} +1 -1
- package/dist/{external-Lmd8cJhx.cjs → external-CWincA61.cjs} +1 -1
- package/dist/{external-Czhk9fZS.cjs → external-C_th4MW9.cjs} +1 -1
- package/dist/{external-BX17kwZc.cjs → external-CyPQsB1T.cjs} +1 -1
- package/dist/{external-BpqHq8f8.js → external-CyYaJ5TW.js} +4 -4
- package/dist/{external-6FH5NjXf.js → external-DIwKYTmY.js} +2 -2
- package/dist/{external-feiUnuJI.js → external-DXD4PtTK.js} +2 -2
- package/dist/{external-xPdBJlsz.js → external-Dn4tpDVi.js} +2 -2
- package/dist/{external-CXQMoMS3.cjs → external-DsJYjdNk.cjs} +1 -1
- package/dist/{external-bByVUOOg.cjs → external-Dtr4ZxR6.cjs} +1 -1
- package/dist/{external-8w5Eg-ce.cjs → external-IztUjYjX.cjs} +1 -1
- package/dist/{external-DAn-_GLc.cjs → external-VEFOprRU.cjs} +1 -1
- package/dist/{external-CFaZ_vCi.js → external-WZW4OBZx.js} +4 -4
- package/dist/{external-Cy8UF9vk.cjs → external-kAduhcvp.cjs} +1 -1
- package/dist/{external-BDzzt6lF.js → external-rGv5AzBK.js} +12 -12
- package/dist/{external-DlCfhkx8.cjs → external-vMTeF1dc.cjs} +1 -1
- package/dist/{external-Ckaptp3S.js → external-vYsKqfFS.js} +4 -4
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.js +9819 -7530
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/menu.cjs +1 -1
- package/dist/menu.js +1 -1
- package/dist/pluto.css +1 -1
- package/dist/src/breadcrumb/Breadcrumb.d.ts +2 -1
- package/dist/src/breadcrumb/Breadcrumb.d.ts.map +1 -1
- package/dist/src/breadcrumb/Breadcrumb.spec.d.ts +2 -0
- package/dist/src/breadcrumb/Breadcrumb.spec.d.ts.map +1 -0
- package/dist/src/color/core/color.d.ts +4 -0
- package/dist/src/color/core/color.d.ts.map +1 -1
- package/dist/src/haul/Haul.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/input/DateTime.d.ts.map +1 -1
- package/dist/src/input/Numeric.d.ts.map +1 -1
- package/dist/src/input/Text.d.ts +1 -0
- package/dist/src/input/Text.d.ts.map +1 -1
- package/dist/src/modal/Modal.d.ts.map +1 -1
- package/dist/src/pluto/Pluto.d.ts +1 -4
- package/dist/src/pluto/Pluto.d.ts.map +1 -1
- package/dist/src/select/ComponentSize.d.ts +12 -0
- package/dist/src/select/ComponentSize.d.ts.map +1 -0
- package/dist/src/select/DataType.d.ts +3 -2
- package/dist/src/select/DataType.d.ts.map +1 -1
- package/dist/src/select/external.d.ts +1 -0
- package/dist/src/select/external.d.ts.map +1 -1
- package/dist/src/table/aether/Table.d.ts.map +1 -1
- package/dist/src/table/cells/Cells.d.ts.map +1 -1
- package/dist/src/telem/control/aether/controller.d.ts.map +1 -1
- package/dist/src/text/Editable.d.ts +2 -1
- package/dist/src/text/Editable.d.ts.map +1 -1
- package/dist/src/text/Keyboard.d.ts.map +1 -1
- package/dist/src/theming/Provider.d.ts.map +1 -1
- package/dist/src/tree/Tree.d.ts +2 -2
- package/dist/src/tree/Tree.d.ts.map +1 -1
- package/dist/src/tree/core.d.ts +5 -2
- package/dist/src/tree/core.d.ts.map +1 -1
- package/dist/src/util/canDisable.d.ts +10 -0
- package/dist/src/util/canDisable.d.ts.map +1 -0
- package/dist/src/util/removeProps.d.ts +26 -0
- package/dist/src/util/removeProps.d.ts.map +1 -0
- package/dist/src/util/removeProps.spec.d.ts +2 -0
- package/dist/src/util/removeProps.spec.d.ts.map +1 -0
- package/dist/src/vis/canvas/aether/canvas.d.ts +4 -4
- package/dist/src/vis/lineplot/aether/LinePlot.d.ts.map +1 -1
- package/dist/src/vis/rule/Rule.d.ts +1 -0
- package/dist/src/vis/rule/Rule.d.ts.map +1 -1
- package/dist/src/vis/rule/aether/aether.d.ts.map +1 -1
- package/dist/src/vis/schematic/Forms.d.ts +9 -2
- package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
- package/dist/src/vis/schematic/SelectOrientation.d.ts +3 -3
- package/dist/src/vis/schematic/SelectOrientation.d.ts.map +1 -1
- package/dist/src/vis/schematic/Symbols.d.ts +183 -3
- package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
- package/dist/src/vis/schematic/primitives/Primitives.d.ts +115 -6
- package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
- package/dist/src/vis/schematic/registry.d.ts +1 -1
- package/dist/src/vis/schematic/registry.d.ts.map +1 -1
- package/dist/src/vis/setpoint/aether/setpoint.d.ts +1 -1
- package/dist/src/vis/setpoint/aether/setpoint.d.ts.map +1 -1
- package/dist/src/vis/value/aether/value.d.ts.map +1 -1
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/text.cjs +1 -1
- package/dist/text.js +2 -2
- package/dist/theming.cjs +1 -1
- package/dist/theming.js +2 -2
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +1 -1
- package/dist/triggers.cjs +1 -1
- package/dist/triggers.js +1 -1
- package/dist/{units-CKQQRvyD.js → units-CJ76Jzvw.js} +1 -1
- package/dist/{units-YvMXZR11.cjs → units-CXFC0OLO.cjs} +1 -1
- package/dist/video.cjs +1 -1
- package/dist/video.js +1 -1
- package/package.json +14 -14
- package/dist/LinePlot-CQN3l2Pu.cjs +0 -24
- package/dist/aggregator-q3hNa4qv.cjs +0 -77
- package/dist/css-C3zWKgOb.cjs +0 -1
- package/dist/external-DtsEr2ls.cjs +0 -1
package/dist/triggers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const a=require("./css-
|
|
1
|
+
"use strict";const a=require("./css-Bo-hsQHb.cjs"),c=(t,e,s)=>Object.fromEntries(s.map(r=>[`${t}-${r}`,new a.Color(e).setAlpha(r).hex])),i=(t,e)=>`${t}${e}`;exports.createHexOpacityVariants=c;exports.unitProperty=i;
|
package/dist/video.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Video-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Video-g30B90s-.cjs");exports.Video=e.Video;
|
package/dist/video.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/pluto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@fontsource-variable/inter": "^5.1.0",
|
|
7
7
|
"@fontsource/geist-mono": "^5.1.0",
|
|
8
|
-
"@tanstack/react-virtual": "^3.11.
|
|
8
|
+
"@tanstack/react-virtual": "^3.11.2",
|
|
9
9
|
"@xyflow/react": "^12.3.6",
|
|
10
10
|
"async-mutex": "^0.5.0",
|
|
11
11
|
"clsx": "^2.1.1",
|
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
"react": "^19.0.0",
|
|
19
19
|
"react-color": "^2.19.3",
|
|
20
20
|
"zod": "^3.24.1",
|
|
21
|
-
"@synnaxlabs/
|
|
22
|
-
"@synnaxlabs/client": "0.
|
|
23
|
-
"@synnaxlabs/
|
|
24
|
-
"@synnaxlabs/
|
|
21
|
+
"@synnaxlabs/media": "0.37.0",
|
|
22
|
+
"@synnaxlabs/client": "0.37.0",
|
|
23
|
+
"@synnaxlabs/x": "0.37.0",
|
|
24
|
+
"@synnaxlabs/alamos": "0.37.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@juggle/resize-observer": "^3.4.0",
|
|
28
|
-
"@testing-library/react": "^16.0
|
|
28
|
+
"@testing-library/react": "^16.1.0",
|
|
29
29
|
"@testing-library/user-event": "^14.5.2",
|
|
30
30
|
"@types/d3-scale": "^4.0.8",
|
|
31
31
|
"@types/offscreencanvas": "^2019.7.3",
|
|
32
|
-
"@types/react": "^19.0.
|
|
33
|
-
"@types/react-color": "^3.0.
|
|
34
|
-
"@types/react-dom": "^19.0.
|
|
32
|
+
"@types/react": "^19.0.1",
|
|
33
|
+
"@types/react-color": "^3.0.13",
|
|
34
|
+
"@types/react-dom": "^19.0.2",
|
|
35
35
|
"@types/webgl2": "^0.0.11",
|
|
36
36
|
"@vitejs/plugin-react": "^4.3.4",
|
|
37
37
|
"@vitest/coverage-v8": "^2.1.8",
|
|
38
|
-
"eslint": "^9.
|
|
38
|
+
"eslint": "^9.17.0",
|
|
39
39
|
"jsdom": "^25.0.1",
|
|
40
40
|
"react-dom": "^19.0.0",
|
|
41
|
-
"typescript": "^5.
|
|
41
|
+
"typescript": "^5.7.2",
|
|
42
42
|
"vite": "^6.0.3",
|
|
43
43
|
"vitest": "^2.1.8",
|
|
44
|
-
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
45
|
-
"eslint-config-synnaxlabs": "0.0.1",
|
|
46
44
|
"@synnaxlabs/tsconfig": "0.0.2",
|
|
45
|
+
"eslint-config-synnaxlabs": "0.0.1",
|
|
46
|
+
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
47
47
|
"stylelint-config-synnaxlabs": "0.0.1"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";var fa=Object.defineProperty;var pa=(e,n,t)=>n in e?fa(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var h=(e,n,t)=>pa(e,typeof n!="symbol"?n+"":n,t);const d=require("./aggregator-q3hNa4qv.cjs"),p=require("zod"),l=require("./css-C3zWKgOb.cjs");var ga=Object.defineProperty,ma=(e,n,t)=>n in e?ga(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Be=(e,n,t)=>ma(e,typeof n!="symbol"?n+"":n,t);class ya{constructor(n,t){Be(this,"handlers"),Be(this,"transform"),Be(this,"closer"),this.transform=n,this.handlers=t??new Map}onChange(n){return this.handlers.set(n,null),()=>this.handlers.delete(n)}notify(n){let t=n;if(this.transform!=null){const[r,s]=this.transform(n);if(!s)return;t=r}this.handlers.forEach((r,s)=>s(t))}setCloser(n){this.closer=n}async close(){var n;return await((n=this.closer)==null?void 0:n.call(this))}}class xa{constructor(n){Be(this,"handlers"),this.handlers=n??new Map}onChange(n){return this.handlers.set(n,null),()=>this.handlers.delete(n)}notify(n){this.handlers.forEach((t,r)=>r(n))}}const Qn=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:xa,Observer:ya},Symbol.toStringTag,{value:"Module"})),K="layout",Bn="data",et="tool";var V;let Z=(V=class{constructor(n){h(this,"f");this.f=n}static control(n,t){n.set(V.CONTEXT_KEY,new V(t),!1)}static useRequest(n){return n.get(V.CONTEXT_KEY).f}static useOptionalRequest(n){var t;return((t=n.getOptional(V.CONTEXT_KEY))==null?void 0:t.f)??null}static requestRender(n,t){this.useRequest(n)(t)}},h(V,"CONTEXT_KEY","pluto-vis-renderer"),V);const wa=p.z.object({props:d.cg.nullable(),state:d.lg.connectivity.connectionStateZ.nullable()}),Jn={synnax:null,state:d.lg.connectivity.DEFAULT};var it;let _e=(it=class extends d.Composite{constructor(){super(...arguments);h(this,"schema",it.stateZ)}async afterUpdate(){var t;if(this.ctx.has(tr)||zn(this.ctx,Jn),this.state.props==null){this.internal.synnax!=null&&(this.setState(r=>({...r,state:d.lg.connectivity.DEFAULT})),(t=this.internal.synnax)==null||t.close(),this.internal.synnax=null),zn(this.ctx,this.internal);return}this.prevState.props!=null&&d._.equal(this.state.props,this.prevState.props)&&this.internal.synnax!=null||(this.internal.synnax=new d.lg(this.state.props),this.internal.synnax.connectivity.onChange(r=>this.setState(s=>({...s,state:r}))),zn(this.ctx,this.internal))}},h(it,"TYPE","SynnaxProvider"),h(it,"stateZ",wa),it);const tr="pluto-client-context",zn=(e,n)=>e.set(tr,n),Me=e=>e.get(tr).synnax,gs={[_e.TYPE]:_e},ba=Object.freeze(Object.defineProperty({__proto__:null,Provider:_e,REGISTRY:gs,ZERO_CONTEXT_VALUE:Jn,use:Me},Symbol.toStringTag,{value:"Module"})),ms="pluto-telem-context",Tn=e=>e.get(ms),ys=(e,n)=>e.set(ms,n),xs=(e,n)=>Tn(e).registerFactory(n);class $r{constructor(n,t,r){h(this,"spec");h(this,"wrapped");h(this,"prevKey");this.wrapped=n,this.spec=r,this.prevKey=t.clusterKey}async value(){return await this.wrapped.value()}async cleanup(){var n,t;await((t=(n=this.wrapped).cleanup)==null?void 0:t.call(n))}onChange(n){return this.wrapped.onChange(n)}shouldUpdate(n,t){return this.prevKey!==n.clusterKey||!d._.equal(this.spec,t)}}class Zr{constructor(n,t,r){h(this,"spec");h(this,"prov");h(this,"prevKey");h(this,"wrapped");this.wrapped=n,this.spec=r,this.prov=t,this.prevKey=t.clusterKey}async set(n){return await this.wrapped.set(n)}async cleanup(){var n,t;await((t=(n=this.wrapped).cleanup)==null?void 0:t.call(n))}shouldUpdate(n,t){return this.prevKey!==n.clusterKey||!d._.equal(this.spec,t)}}const H=async(e,n,t)=>{var s;const r=Tn(e);if(t instanceof $r){if(!t.shouldUpdate(r,n))return t;await((s=t.cleanup)==null?void 0:s.call(t))}return new $r(r.create(n),r,n)},Ye=async(e,n,t)=>{var s;const r=Tn(e);if(t instanceof Zr){if(!t.shouldUpdate(r,n))return t;await((s=t.cleanup)==null?void 0:s.call(t))}return new Zr(r.create(n),r,n)};class at extends Qn.Observer{async cleanup(){}}class He extends at{async set(){return await Promise.resolve()}}h(He,"TYPE","noop-boolean-sink");const Sn={type:He.TYPE,props:{},variant:"sink",valueType:"boolean"};class qe extends at{async set(){return await Promise.resolve()}}h(qe,"TYPE","noop-numeric-sink");const ws={type:qe.TYPE,props:{},variant:"sink",valueType:"number"};class je extends at{async value(){return await Promise.resolve(!1)}}h(je,"TYPE","noop-boolean-source");const er={type:je.TYPE,props:{},variant:"source",valueType:"boolean"};class We extends at{async value(){return 0}}h(We,"TYPE","noop-numeric-source");const bs={type:We.TYPE,props:{},variant:"source",valueType:"number"};class Ve extends at{async value(){return""}}h(Ve,"TYPE","noop-string-source");const vs={type:Ve.TYPE,props:{},variant:"source",valueType:"string"};class Xe extends at{async value(){return{key:"noop",variant:"disabled",message:"unknown",time:d.m.now()}}}h(Xe,"TYPE","noop-status-source");const nr={type:Xe.TYPE,props:{},variant:"source",valueType:"status"};class Ke extends at{async value(){return l.ZERO}}h(Ke,"TYPE","noop-color-source");const En={type:Ke.TYPE,props:{},variant:"source",valueType:"color"};class Qe extends at{async value(){return[l.H.ZERO,[]]}}h(Qe,"TYPE","noop-series");const Ts={type:Qe.TYPE,props:{},variant:"source",valueType:"series"},va={[He.TYPE]:He,[qe.TYPE]:qe,[je.TYPE]:je,[We.TYPE]:We,[Xe.TYPE]:Xe,[Ke.TYPE]:Ke,[Ve.TYPE]:Ve,[Qe.TYPE]:Qe};class Ss{constructor(){h(this,"type","noop")}create(n){const t=va[n.type];return t==null?null:new t}}const Ta=p.z.instanceof(ArrayBuffer),ze=p.z.object({type:p.z.string(),variant:p.z.enum(["source","sink","source-transformer","sink-transformer"]),valueType:p.z.string(),props:p.z.any(),transfer:p.z.array(Ta).optional()}),ot=ze.extend({variant:p.z.literal("source")}),Cn=ze.extend({variant:p.z.literal("sink")}),Es=ze.extend({variant:p.z.literal("source-transformer")}),Cs=ze.extend({variant:p.z.literal("sink-transformer")}),Je=ot.extend({valueType:p.z.literal("series")}),rr=ot.extend({valueType:p.z.literal("boolean")}),Pn=Cn.extend({valueType:p.z.literal("boolean")}),Sa=Cs.extend({valueType:p.z.literal("boolean")}),Ea=Es.extend({valueType:p.z.literal("boolean")}),Ps=ot.extend({valueType:p.z.literal("number")}),ks=Cn.extend({valueType:p.z.literal("number")}),sr=ot.extend({valueType:p.z.literal("color")}),ir=ot.extend({valueType:p.z.literal("status")}),ar=ot.extend({valueType:p.z.literal("string")});class kn extends Qn.BaseObserver{constructor(t){super();h(this,"props_");h(this,"uProps_");h(this,"schema");this.uProps_=t}get props(){if(this.props_==null){const t=this._schema.safeParse(this.uProps_);if(t.success)this.props_=t.data;else throw new d.U(`[BaseTelem] - expected props to be valid, but found the following errors:
|
|
2
|
-
${t.error.message}`)}return this.props_}get _schema(){if(this.schema==null)throw new d.U(`[BaseTelem] - expected subclass to define props schema, but none was found.
|
|
3
|
-
Make sure to define a property 'schema' on the class.`);return this.schema}async cleanup(){}}class F extends kn{}class Rn extends kn{}class pt extends F{constructor(){super(...arguments);h(this,"sources",{})}get source(){const[t]=Object.values(this.sources);if(t==null)throw new d.U("[UnarySourceTransformer] - expected source to exist, but none was found.");return t}async value(){return this.transform(await this.source.value())}onChange(t){return this.source.onChange(()=>{this.source.value().then(r=>{this.shouldNotify(r)&&t()}).catch(console.error)})}setSources(t){this.sources=t}shouldNotify(t){return!0}transform(t){throw new d.U(`[UnarySourceTransformer] - expected subclass to define transform method, but none was found.
|
|
4
|
-
Make sure to define a method 'transform' on the class.`)}}class Rs extends F{constructor(){super(...arguments);h(this,"sources",{})}async value(){const t=Object.fromEntries(await Promise.all(Object.entries(this.sources).map(async([r,s])=>[r,await s.value()])));return this.transform(t)}setSources(t){this.sources={...this.sources,...t}}transform(t){throw new d.U(`[MultiSourceTransformer] - expected subclass to define transform method, but none was found.
|
|
5
|
-
Make sure to define a method 'transform' on the class.`)}}class Ms extends kn{constructor(){super(...arguments);h(this,"sinks",{})}get sink(){const[t]=Object.values(this.sinks);if(t==null)throw new d.U("[UnarySinkTransformer] - expected sink to exist, but none was found.");return t}async set(t){return await this.sink.set(this.transform(t))}setSinks(t){this.sinks={...this.sinks,...t}}transform(t){throw new d.U(`[UnarySinkTransformer] - expected subclass to define transform method, but none was found.
|
|
6
|
-
Make sure to define a method 'transform' on the class.`)}}const or=p.z.object({from:p.z.string(),to:p.z.string()}),lr=p.z.object({connections:p.z.array(or),outlet:p.z.string(),segments:p.z.record(ot)});class Ys{constructor(n){h(this,"type","pipeline");h(this,"factory");this.factory=n}create(n){switch(n.type){case oe.TYPE:return new oe(n.props,this.factory);case le.TYPE:return new le(n.props,this.factory);default:return null}}}class oe extends F{constructor(t,r){super(t);h(this,"schema",lr);h(this,"sources",{});const{connections:s,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const c=r.create(o);c!=null&&(this.sources[a]=c)}),s.forEach(({from:a,to:o})=>{const c=this.sources[a],u=this.sources[o];c==null||u==null||"setSources"in u&&u.setSources({[a]:c})})}get outlet(){const{outlet:t}=this.props,r=this.sources[t];if(r==null)throw new d.U(`[SourcePipeline] - expected source to exist at outlet '${t}', but none was found.`);return r}async value(){return await this.outlet.value()}onChange(t){return this.outlet.onChange(t)}async cleanup(){await Promise.all(Object.values(this.sources).map(async t=>{var r;return await((r=t.cleanup)==null?void 0:r.call(t))}))}}h(oe,"TYPE","source-pipeline");const zs=(e,n)=>({variant:"source",props:n,type:oe.TYPE,valueType:e}),cr=p.z.object({connections:p.z.array(or),inlet:p.z.string(),segments:p.z.record(Cn)});class le extends Rn{constructor(t,r){super(t);h(this,"schema",cr);h(this,"sinks",{});const{connections:s,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const c=r.create(o);c!=null&&(this.sinks[a]=c)}),s.forEach(({from:a,to:o})=>{const c=this.sinks[a],u=this.sinks[o];c==null||u==null||"setSinks"in c&&c.setSinks({[o]:u})})}get inlet(){const{inlet:t}=this.props,r=this.sinks[t];if(r==null)throw new d.U(`[SinkPipeline] - expected source to exist at inlet '${t}', but none was found.`);return r}async set(t){return await this.inlet.set(t)}async cleanup(){await Promise.all(Object.values(this.sinks).map(async t=>{var r;return await((r=t.cleanup)==null?void 0:r.call(t))}))}}h(le,"TYPE","sink-pipeline");const Ds=(e,n)=>({variant:"sink",props:n,type:le.TYPE,valueType:e}),ur=p.z.object({channel:p.z.number().or(p.z.string())});class ce extends F{constructor(t,r){super(r);h(this,"client");h(this,"removeStreamHandler",null);h(this,"channelKey",0);h(this,"schema",ur);h(this,"leadingBuffer",null);h(this,"valid",!1);this.client=t}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}async cleanup(){var t,r;await((t=this.removeStreamHandler)==null?void 0:t.call(this)),this.valid=!1,(r=this.leadingBuffer)==null||r.release(),this.leadingBuffer=null,this.removeStreamHandler=null}async value(){return d.w$2(this.props.channel)||(this.channelKey===0&&(this.channelKey=(await hr(this.client,this.props.channel,!1)).key),this.valid||await this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0)?0:this.leadingBuffer.at(-1,!0)}async read(){this.valid=!0,await this.updateStreamHandler()}async updateStreamHandler(){var r;await((r=this.removeStreamHandler)==null?void 0:r.call(this));const t=s=>{var o;const a=s[this.channelKey].data;if(a.length!==0){const c=a[a.length-1];c.acquire(),(o=this.leadingBuffer)==null||o.release(),this.leadingBuffer=c}this.notify()};this.removeStreamHandler=await this.client.stream(t,[this.channelKey])}}h(ce,"TYPE","stream-channel-value");const hr=async(e,n,t)=>{const r=await e.retrieveChannel(n);return!t||r.isIndex?{key:r.key,dataType:r.dataType,virtual:r.virtual}:{key:r.index,dataType:d.g.TIMESTAMP,virtual:!1}},Ca=p.z.object({timeRange:d.E.z,channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1)});class ue extends F{constructor(t,r){super(r);h(this,"client");h(this,"data",[]);h(this,"valid",!1);h(this,"schema",Ca);this.client=t}async cleanup(){this.data.forEach(t=>t.release()),this.valid=!1}async value(){const{timeRange:t,channel:r,useIndexOfChannel:s}=this.props;if(t.isZero||r===0)return[l.H.ZERO,[]];const i=await hr(this.client,r,s);this.valid||await this.readFixed(i.key);let a=l.H.max(this.data.map(o=>o.bounds));return i.dataType.equals(d.g.TIMESTAMP)&&(a={upper:Math.min(a.upper,Number(this.props.timeRange.end.valueOf())),lower:Math.max(a.lower,Number(this.props.timeRange.start.valueOf()))}),[a,this.data]}async readFixed(t){const s=(await this.client.read(this.props.timeRange,[t]))[t].data;s.forEach(i=>i.acquire()),this.data=s,this.valid=!0}}h(ue,"TYPE","series-source");const Pa=p.z.object({channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1),timeSpan:d.w$1.z,keepFor:d.w$1.z.optional()});class he extends F{constructor(t,r){super(r);h(this,"client");h(this,"data",[]);h(this,"stopStreaming");h(this,"valid",!1);h(this,"schema",Pa);this.client=t}async value(){const{channel:t,useIndexOfChannel:r,timeSpan:s}=this.props;if(t===0)return[l.H.ZERO,[]];const i=d.m.now(),a=await hr(this.client,t,r);if(this.valid||await this.read(a),a.dataType.isVariable)return[l.H.ZERO,this.data];let o=l.H.max(this.data.filter(c=>c.timeRange.end.after(i.sub(s))).map(c=>c.bounds));return a.dataType.equals(d.g.TIMESTAMP)&&(o={upper:o.upper,lower:Math.max(o.lower,o.upper-Number(s.valueOf()))}),[o,this.data]}async read({key:t,virtual:r}){const s=d.m.now().spanRange(-this.props.timeSpan);if(!r){const a=(await this.client.read(s,[t]))[t].data;a.forEach(o=>o.acquire()),this.data.push(...a)}await this.updateStreamHandler(t),this.valid=!0}async updateStreamHandler(t){this.stopStreaming!=null&&await this.stopStreaming();const r=s=>{const i=s[t].data;i.forEach(a=>a.acquire()),this.data.push(...i),this.gcOutOfRangeData(),this.notify()};this.stopStreaming=await this.client.stream(r,[t])}gcOutOfRangeData(){const t=d.m.now().sub(this.props.keepFor??this.props.timeSpan),r=this.data.findIndex(s=>s.timeRange.end.before(t));r!==-1&&(this.data.splice(r,1).forEach(s=>s.release()),this.gcOutOfRangeData())}async cleanup(){var t;await((t=this.stopStreaming)==null?void 0:t.call(this)),this.stopStreaming=void 0,this.data.forEach(r=>r.release())}}h(he,"TYPE","dynamic-series-source");const ka={[ue.TYPE]:ue,[he.TYPE]:he,[ce.TYPE]:ce};class Os{constructor(n){h(this,"type","remote");h(this,"client");this.client=n}create(n){const t=ka[n.type];return t==null?null:new t(this.client,n.props)}}const As=e=>({type:ue.TYPE,props:e,variant:"source",valueType:"series"}),Ls=e=>({type:he.TYPE,props:e,variant:"source",valueType:"series"}),$s=e=>({type:ce.TYPE,props:e,variant:"source",valueType:"number"});class Zs{constructor(){h(this,"type","static")}create(n){switch(n.type){case tn.TYPE:return new tn(n.props);case de.TYPE:return new de(n.props);case fe.TYPE:return new fe(n.props);case pe.TYPE:return new pe(n.props);case ge.TYPE:return new ge(n.props);default:return null}}}const dr=p.z.object({data:p.z.array(d.Lt),offsets:p.z.array(p.z.number()).optional().default([])});class tn extends F{constructor(t){super(t);h(this,"data");h(this,"schema",dr);this.data=this.props.data.map((r,s)=>new d.V({data:r,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[s]??0}))}async value(){return[l.H.max(this.data.map(r=>r.bounds)),this.data]}}h(tn,"TYPE","static-series");const Ns=dr.extend({rate:d.F$1.z,yOffset:p.z.number().optional().default(0),scroll:p.z.number().optional().default(0),startPosition:p.z.number().optional().default(0),scrollBounds:p.z.boolean().optional().default(!1)});class de extends F{constructor(t){super(t);h(this,"schema",Ns);h(this,"position");h(this,"interval");h(this,"data");this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((r,s)=>new d.V({data:r,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[s]??0}))}async value(){const t=this.data.map(s=>s.slice(0,this.position));if(this.props.scrollBounds){const s=t[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=t[0].data[this.position-1];return[{lower:Number(s),upper:Number(i)},t]}return[l.H.max(t.map(s=>s.bounds)),t]}start(t){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{var r;(r=this.notify)==null||r.call(this),this.position++},t.period.milliseconds)}async cleanup(){clearInterval(this.interval),this.interval=void 0}}h(de,"TYPE","iterative-series");const Us=p.z.number();class fe extends F{constructor(){super(...arguments);h(this,"schema",Us)}async value(){return this.props}}h(fe,"TYPE","static-numeric");const Is=p.z.string();class pe extends F{constructor(){super(...arguments);h(this,"schema",Is)}async value(){return this.props}}h(pe,"TYPE","static-string");const Gs=l.crudeZ;class ge extends F{constructor(){super(...arguments);h(this,"schema",Gs)}async value(){return new l.Color(this.props)}}h(ge,"TYPE","static-color");const Ra=e=>({type:tn.TYPE,props:e,variant:"source",valueType:"series"}),Ma=e=>({type:de.TYPE,props:e,variant:"source",valueType:"series"}),Ya=e=>({type:fe.TYPE,props:e,variant:"source",valueType:"number"}),za=e=>({type:pe.TYPE,props:e,variant:"source",valueType:"string"}),Da=e=>({type:ge.TYPE,props:e,variant:"source",valueType:"color"}),Oa=["standard","scientific","engineering"],Bs=p.z.enum(Oa),Aa=(e,n,t)=>{if(Number.isNaN(e))return"NaN";if(e===1/0)return"∞";if(e===-1/0)return"-∞";if(t==="standard")return e.toFixed(n);if(e===0)return n===0?"0ᴇ0":`0.${"0".repeat(n)}ᴇ0`;let r;return t==="scientific"?r=Math.floor(Math.log10(Math.abs(e))):r=Math.floor(Math.log10(Math.abs(e))/3)*3,`${(e/10**r).toFixed(n)}ᴇ${r}`};class Fs{constructor(){h(this,"type","transformer")}create(n){switch(n.type){case Rt.TYPE:return new Rt(n.props);case Mt.TYPE:return new Mt(n.props);case Yt.TYPE:return new Yt(n.props);case zt.TYPE:return new zt(n.props);case Dt.TYPE:return new Dt(n.props);case Ot.TYPE:return new Ot(n.props);case At.TYPE:return new At(n.props);case Lt.TYPE:return new Lt(n.props)}return null}}const La=p.z.object({truthy:p.z.number().optional().default(1),falsy:p.z.number().optional().default(0)}),_s=e=>({props:e,type:Rt.TYPE,variant:"sink",valueType:"boolean"}),Qt=class Qt extends Ms{constructor(){super(...arguments);h(this,"schema",Qt.propsZ)}transform(t){return t?this.props.truthy:this.props.falsy}};h(Qt,"TYPE","boolean-numeric-converter-sink"),h(Qt,"propsZ",La);let Rt=Qt;const fr=p.z.object({trueBound:l.H.bounds}),Hs=e=>({props:e,type:Mt.TYPE,variant:"source",valueType:"boolean"}),Jt=class Jt extends pt{constructor(){super(...arguments);h(this,"schema",Jt.propsZ);h(this,"curr",null)}shouldNotify(t){const r=l.H.contains(this.props.trueBound,t)!==this.curr;return this.curr=l.H.contains(this.props.trueBound,t),r}transform(t){return this.curr=l.H.contains(this.props.trueBound,t),this.curr}};h(Jt,"TYPE","boolean-source"),h(Jt,"propsZ",fr);let Mt=Jt;const qs=p.z.object({}),te=class te extends Rs{constructor(){super(...arguments);h(this,"schema",te.propsZ)}transform(t){return Object.values(t).reduce((r,s)=>r+s,0)/Object.keys(t).length}};h(te,"TYPE","mean"),h(te,"propsZ",qs);let Yt=te;const $a=e=>({props:e,type:Yt.TYPE,variant:"source",valueType:"boolean"}),js=p.z.object({trueVariant:d.variantZ.optional().default("success")}),ee=class ee extends pt{constructor(){super(...arguments);h(this,"schema",ee.propsZ)}transform(t){return t.variant===this.props.trueVariant}};h(ee,"TYPE","boolean-status"),h(ee,"propsZ",js);let zt=ee;const Za=e=>({props:e,type:zt.TYPE,variant:"source",valueType:"boolean"}),pr=p.z.object({precision:p.z.number().optional().default(2),prefix:p.z.string().optional().default(""),suffix:p.z.string().optional().default(""),notation:Bs.optional().default("standard")}),ne=class ne extends pt{constructor(){super(...arguments);h(this,"schema",ne.propsZ)}transform(t){return`${this.props.prefix}${Aa(t,this.props.precision,this.props.notation)}${this.props.suffix}`}};h(ne,"TYPE","stringify-number"),h(ne,"propsZ",pr);let Dt=ne;const Ws=e=>({props:e,type:Dt.TYPE,variant:"source",valueType:"string"}),gr=p.z.object({windowSize:p.z.number().optional().default(5)});class Ot extends pt{constructor(){super(...arguments);h(this,"schema",gr);h(this,"values",[])}transform(t){return this.props.windowSize<2?t:this.values.reduce((r,s)=>r+s,0)/this.values.length}shouldNotify(t){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(t),this.values.length===this.props.windowSize)}}h(Ot,"TYPE","rolling-average"),h(Ot,"propsZ",qs);const Vs=e=>({props:e,type:Ot.TYPE,variant:"source",valueType:"number"}),Xs=p.z.object({gradient:l.gradientZ}),re=class re extends pt{constructor(){super(...arguments);h(this,"schema",re.propsZ)}transform(t){return l.fromGradient(this.props.gradient,t)}};h(re,"TYPE","color-gradient"),h(re,"propsZ",Xs);let At=re;const Ks=e=>({props:e,type:At.TYPE,variant:"source",valueType:"color"}),Qs=p.z.object({scale:l.b.transform}),se=class se extends pt{constructor(){super(...arguments);h(this,"schema",se.propsZ)}transform(t){const{offset:r,scale:s}=this.props.scale;return t*s+r}};h(se,"TYPE","scale-number"),h(se,"propsZ",Qs);let Lt=se;const Js=e=>({props:e,type:Lt.TYPE,variant:"source",valueType:"number"});class ti{constructor(n){h(this,"factories");h(this,"type","compound");this.factories=n}add(n){this.factories=[...this.factories.filter(t=>t.type!==n.type),n]}create(n){for(const t of this.factories){const r=t.create(n);if(r!=null)return r}return null}}const ei=e=>{const n=[new Fs,new Zs,new Ss],t=new ti(n);return e!=null&&t.add(new Os(e)),t.add(new Ys(t)),t},ni=p.z.object({include:p.z.string().array().optional(),exclude:p.z.string().array().optional(),level:p.z.enum(d.g$1.LOG_LEVELS).optional().default("info")}),Fn="alamos-provider";var Gn;let _n=(Gn=class extends d.Composite{constructor(){super(...arguments);h(this,"schema",ni)}async afterUpdate(){if(this.ctx.getOptional(Fn)!=null)return;const r=[],{include:s,exclude:i,level:a}=this.state;(s!=null||i!=null)&&r.push(d.g$1.logLevelKeyFiler({include:s,exclude:i})),a!=null&&r.push(d.g$1.logThresholdFilter(a)),r.length===0&&r.push(()=>!1),this.internal.ins=new d.g$1.Instrumentation({key:"aether",logger:new d.g$1.Logger({filters:r})}),this.ctx.set(Fn,this.internal.ins)}},h(Gn,"TYPE","AlamosProvider"),Gn);const De=(e,n)=>{const t=e.get(Fn);if(t==null)throw new Error("No instrumentation provider");return n==null?t:t.child(n)},Na={[_n.TYPE]:_n},ri=(e,n)=>e.dataType.isVariable?e:(n==null&&e.dataType.equals(d.g.TIMESTAMP)&&(n=BigInt(e.data[0])),e.convert(d.g.FLOAT32,n)),si=()=>({purgedSeries:0,purgedBytes:d.x.bytes(0)}),ii={instrumentation:d.g$1.NOOP,staleEntryThreshold:d.w$1.seconds(20)};class Ua{constructor(n){h(this,"data",[]);h(this,"props");this.props={...ii,...n}}write(n){n.length!==0&&(n.forEach(t=>this.writeOne(ri(t))),this.checkIntegrity(n))}dirtyRead(n){const t=this.data.filter(({data:a})=>a.timeRange.overlapsWith(n)).map(({data:a})=>a);if(t.length===0)return{series:[],gaps:[n]};const r=t.map((a,o)=>o===0?d.E.ZERO:new d.E(t[o-1].timeRange.end,a.timeRange.start)).filter(a=>!a.isZero&&a.isValid),s=new d.E(n.start,t[0].timeRange.start),i=new d.E(t[t.length-1].timeRange.end,n.end);return s.isValid&&!s.isZero&&r.unshift(s),i.isValid&&!i.isZero&&r.push(i),{series:t,gaps:r}}gc(){const{staleEntryThreshold:n}=this.props,t=si(),r=this.data.filter(s=>{const i=s.data.refCount>0||d.m.since(s.addedAt).lessThan(n);return i||(t.purgedBytes=t.purgedBytes.add(s.data.byteCapacity)),i});return t.purgedSeries=this.data.length-r.length,this.data=r,t}close(){this.data=[]}writeOne(n){const{instrumentation:{L:t}}=this.props;if(n.length===0)return;const r=l.H.buildInsertionPlan(this.data.map(c=>c.data.alignmentBounds),n.alignmentBounds);if(r===null)return t.debug("Found no viable insertion plan",{inserting:n.digest,cacheContents:this.data.map(c=>c.data.digest)});const{removeBefore:s,removeAfter:i,insertInto:a,deleteInBetween:o}=r;n=n.slice(s,n.data.length-Number(i)),n.length!==0&&this.data.splice(a,o,{data:n,addedAt:d.m.now()})}checkIntegrity(n){const{instrumentation:{L:t}}=this.props,r=this.data.map(i=>i.data.alignmentBounds);if(r.some((i,a)=>r.some((o,c)=>a===c?!1:l.H.overlapsWith(i,o))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:n.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const Ia=100,Ga=1e6,Ba=1e4,Fa=100,_a=40;class Ha{constructor(n){h(this,"props");h(this,"counter",0);h(this,"curr");h(this,"avgRate",0);h(this,"timeOfLastWrite");h(this,"totalWrites",0);h(this,"now",()=>d.m.now());this.props=n,this.curr=null,n.testingNow!=null&&(this.now=n.testingNow),this.timeOfLastWrite=this.now()}get length(){var n;return((n=this.curr)==null?void 0:n.length)??0}get leadingBuffer(){return this.curr}write(n){const t=n.flatMap(r=>this._write(r));return{flushed:t.flatMap(r=>r.flushed),allocated:t.flatMap(r=>r.allocated)}}allocate(n,t,r){this.counter++;const s=this.props.dataType.isVariable,i=this.props.dataType.equals(d.g.TIMESTAMP);return d.V.alloc({capacity:s?n*_a:n,dataType:s?this.props.dataType:d.g.FLOAT32,timeRange:r.range(d.m.MAX),sampleOffset:i?BigInt(r.valueOf()):0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(n){const t=this.nextBufferSize(),r={flushed:[],allocated:[]};if(this.curr==null)this.curr=this.allocate(t,n.alignment,this.now()),r.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-n.alignment))>1){const c=this.now();this.curr.timeRange.end=c,r.flushed.push(this.curr),this.curr=this.allocate(t,n.alignment,c),r.allocated.push(this.curr)}const s=ri(n,this.curr.sampleOffset),i=this.curr.write(s);if(i===n.length)return this.updateAvgRate(n),r;const a=this.now();this.curr.timeRange.end=a,r.flushed.push(this.curr),this.curr=this.allocate(t,n.alignment+BigInt(i),a),r.allocated.push(this.curr);const o=this._write(n.slice(i));return r.flushed.push(...o.flushed),r.allocated.push(...o.allocated),r}updateAvgRate(n){if(typeof this.props.dynamicBufferSize=="number")return;const t=n.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:n}=this.props;if(typeof n=="number")return n;if(this.totalWrites<Fa)return Ba;const t=l.G$1.roundToNearestMagnitude(this.avgRate*n.seconds);return Math.round(Math.max(Math.min(t,Ga),Ia))}close(){this.curr=null}}class qa{constructor(n){h(this,"channel");h(this,"closed",!1);h(this,"ins");h(this,"static");h(this,"dynamic");this.channel=n.channel,this.ins=n.instrumentation??d.g$1.NOOP,this.static=new Ua(n),this.dynamic=new Ha({dynamicBufferSize:n.dynamicBufferSize,dataType:this.channel.dataType})}writeDynamic(n){if(this.closed)return this.ins.L.warn(`Ignoring attempted dynamic write to a closed cache for channel ${this.channel.name}`),[];const{flushed:t,allocated:r}=this.dynamic.write(n);return t.length>0&&this.static.write(t),r}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(n){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(n)}read(n){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:[],gaps:[]}):this.static.dirtyRead(n)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:d.x.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const ja=d.S.seconds(60);class Wa{constructor(n){h(this,"props");h(this,"cache",new Map);h(this,"gcInterval");this.props={dynamicBufferSize:ja,gcInterval:d.S.seconds(30),...ii,...n},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(n){const{instrumentation:t,channelRetriever:r,dynamicBufferSize:s}=this.props,i=[];for(const o of n)this.cache.has(o)||i.push(o);if(i.length===0)return;const a=await r.retrieve(i);for(const o of a){const c=new qa({channel:o,dynamicBufferSize:s,instrumentation:t.child(`cache-${o.name}-${o.key}`)});this.cache.has(o.key)||this.cache.set(o.key,c)}}get(n){const t=this.cache.get(n);if(t!=null)return t;throw new d.Re(`cache entry for ${n} not found`)}gc(){const{instrumentation:{L:n}}=this.props;n.info("starting garbage collection");const t=si();this.cache.forEach(r=>{const s=r.gc();t.purgedSeries+=s.purgedSeries,t.purgedBytes=t.purgedBytes.add(s.purgedBytes)}),n.info("garbage collection complete",{purgedSeries:t.purgedSeries,purgedBytes:t.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(n=>n.close()),this.cache.clear()}}class en{constructor(n,t){h(this,"channel");h(this,"data");this.channel=n,this.data=t}get timeRange(){if(this.data.length===0)return d.V$1.ZERO;const n=this.data[0].timeRange,t=this.data[this.data.length-1].timeRange;return new d.V$1(n.start,t.end)}get digest(){return{channel:this.channel.key,timeRange:this.timeRange.toPrettyString(),series:this.data.map(n=>n.digest)}}}const Dn=e=>e.map(n=>n.digest);class Va{constructor(n){h(this,"props");h(this,"debouncedRead");h(this,"guarded",{mu:new d.Mutex,requests:new Map});this.props={instrumentation:d.g$1.NOOP,batchDebounce:d.w$1.milliseconds(50),...n},this.debouncedRead=d.o(()=>{this.batchRead()},this.props.batchDebounce.milliseconds)}async read(n,t){const{instrumentation:{L:r},cache:s}=this.props;r.debug("starting read",{tr:n.toPrettyString(),channels:t});const i=performance.now(),a=new Map,o={};await s.populateMissing(t);try{for(const f of t){const g=s.get(f),{series:m,gaps:w}=g.read(n);w.length===0&&(o[f]=new en(g.channel,m)),w.forEach(b=>{const v=a.get(b.toString());v==null?a.set(b.toString(),[b,new Set([f])]):a.set(b.toString(),[b,new Set([...v[1],f])])})}if(a.size===0)return r.debug("read satisfied by cache",()=>({tr:n.toPrettyString(),channels:t,responses:Dn(Object.values(o)),time:d.w$1.milliseconds(performance.now()-i).toString()})),o;r.debug("read cache miss",()=>({tr:n.toPrettyString(),channels:t,toFetch:Array.from(a.values()).map(([f,g])=>({timeRange:f.toPrettyString(),channels:g})),responses:Dn(Object.values(o))}));const{mu:c,requests:u}=this.guarded;for(const[,[f,g]]of a)await new Promise((m,w)=>{c.runExclusive(async()=>{u.set([f,g],{resolve:m,reject:w}),this.debouncedRead()})})}catch(c){throw r.error("read failed",{tr:n.toPrettyString(),channels:t,error:c}),c}for(const c of t){const u=s.get(c),{series:f}=u.read(n);o[c]=new en(u.channel,f)}return r.debug("read satisfied by fetch",()=>({tr:n.toPrettyString(),channels:t,responses:Dn(Object.values(o)),time:d.w$1.milliseconds(performance.now()-i).toString()})),o}async batchRead(){const{instrumentation:{L:n},readRemote:t,cache:r}=this.props,{mu:s,requests:i}=this.guarded;await s.runExclusive(async()=>{const a=[];try{i.forEach((o,c)=>{const[u,f]=c,g=a.find(([m])=>m.start.span(u.start).lessThan(d.w$1.milliseconds(5))&&m.end.span(u.end).lessThan(d.w$1.milliseconds(5)));g==null?a.push([u,f]):g[1]=new Set([...g[1],...f])}),n.debug("batch read",{toFetch:a.map(([o,c])=>({timeRange:o.toPrettyString(),channels:c}))});for(const[o,c]of a){const u=Array.from(c),f=await t(o,u);u.forEach(g=>{const m=r.get(g),w=f.get(g);m.writeStatic(w.series)})}i.forEach(o=>o.resolve())}catch(o){n.error("batch read failed",{error:o},!0),i.forEach(c=>c.reject(o))}finally{i.clear()}})}}class Xa{constructor(n){h(this,"props");h(this,"mu",new d.Mutex);h(this,"listeners",new Map);h(this,"streamerRunLoop",null);h(this,"streamer",null);h(this,"closed",!1);this.props={instrumentation:d.g$1.NOOP,...n}}async stream(n,t){const{cache:r,instrumentation:{L:s}}=this.props;return await r.populateMissing(t),await this.mu.runExclusive(async()=>{s.debug("adding stream handler",{keys:t}),this.listeners.set(n,{valid:!0,keys:t});const i={};for(const a of t){const o=r.get(a),c=o.leadingBuffer!=null?[o.leadingBuffer]:[];i[a]=new en(o.channel,c)}return n(i),await this.updateStreamer(),async()=>await this.removeStreamHandler(n)})}async removeStreamHandler(n){const{instrumentation:{L:t}}=this.props;await this.mu.runExclusive(()=>{const r=this.listeners.get(n);r!=null&&(r.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.debug("removing stream handler"),this.listeners.delete(n))return await this.updateStreamer();t.warn("attempted to remove non-existent stream handler")})},5e3)}async updateStreamer(){var i,a;if(this.closed)return;const{instrumentation:{L:n},core:t}=this.props,r=new Set;if(this.listeners.forEach(o=>o.keys.forEach(c=>r.add(c))),r.size===0){n.info("no keys to stream, closing streamer"),(i=this.streamer)==null||i.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,n.info("streamer closed successfully");return}const s=Array.from(r);if(d.F.primitiveArrays(s,((a=this.streamer)==null?void 0:a.keys)??[])===d.F.EQUAL){n.debug("streamer keys unchanged",{keys:s});return}this.streamer==null&&(n.info("creating new streamer",{keys:s}),this.streamer=await t.openStreamer(s),this.streamerRunLoop=this.runStreamer(this.streamer)),n.debug("updating streamer",{prev:this.streamer.keys,next:s});try{await this.streamer.update(s)}catch(o){throw n.error("failed to update streamer",{error:o}),o}}async runStreamer(n){const{cache:t,instrumentation:{L:r}}=this.props;try{for await(const s of n){const i=[];for(const a of s.keys){const o=s.get(a),c=t.get(a),u=c.writeDynamic(o.series);i.push(new en(c.channel,u))}this.listeners.forEach((a,o)=>{if(!a.valid)return;const c=i.filter(f=>a.keys.includes(f.channel.key));if(c.length===0)return;const u=Object.fromEntries(c.map(f=>[f.channel.key,f]));o(u)})}}catch(s){throw r.error("streamer run loop failed",{error:s},!0),s}}async close(){var n;(n=this.streamer)==null||n.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.closed=!0}}class Ka{constructor(){h(this,"key",d.xt.id());h(this,"_client",null)}async swap(n){var t;this.key=d.xt.id(),await((t=this._client)==null?void 0:t.close()),this._client=n}async retrieveChannel(n){return await this.client.retrieveChannel(n)}async read(n,t){return await this.client.read(n,t)}async stream(n,t){return await this.client.stream(n,t)}async close(){await this.client.close()}get client(){if(this._client==null)throw new d.ne("No cluster has been connected");return this._client}}class Qa{constructor({instrumentation:n,core:t}){h(this,"key",d.xt.id());h(this,"ins");h(this,"cache");h(this,"reader");h(this,"streamer");h(this,"channelRetriever");this.ins=n??d.g$1.NOOP,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new Wa({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new Va({cache:this.cache,readRemote:async(r,s)=>await t.read(r,s),instrumentation:this.ins.child("reader")}),this.streamer=new Xa({cache:this.cache,core:t,instrumentation:this.ins.child("streamer")})}async retrieveChannel(n){const t=await this.channelRetriever.retrieve([n]);if(t.length===0)throw new d.ne(`channel ${n} not found`);return t[0]}async read(n,t){return await this.reader.read(n,t)}async stream(n,t){return await this.streamer.stream(n,t)}async close(){this.ins.L.info("closing client",{key:this.key}),await this.streamer.close(),this.cache.close()}}const mr=p.z.object({}),St=class St extends d.Composite{constructor(){super(...arguments);h(this,"client",new Ka);h(this,"factory",ei(this.client));h(this,"schema",St.stateZ);h(this,"prevClient",null)}create(t){const{instrumentation:r}=this.internal;r.L.debug("creating telem",{spec:t});const s=this.factory.create(t);if(s==null)throw new d.Re(`Telemetry service could not find a source for type ${t.type}`);return s}get clusterKey(){return this.client.key}registerFactory(t){this.factory.add(t)}equals(t){return t instanceof St?this.client._client===t.client._client:!1}async afterUpdate(){const t=Me(this.ctx),r=De(this.ctx,"telem");this.internal.instrumentation=r.child("provider"),t!==this.prevClient&&(r.L.info("swapping client",{client:t}),t==null?await this.client.swap(null):await this.client.swap(new Qa({core:t,instrumentation:r})),this.prevClient=t,ys(this.ctx,this))}};h(St,"TYPE","TelemProvider"),h(St,"stateZ",mr);let $t=St;const ai={[$t.TYPE]:$t},Ja=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:Rn,AbstractSource:F,Base:kn,BaseProvider:$t,BooleanStatus:zt,ChannelData:ue,ColorGradient:At,CompoundTelemFactory:ti,FixedColorSource:ge,FixedNumber:fe,FixedString:pe,IterativeSeries:de,Mean:Yt,MultiSourceTransformer:Rs,NoopFactory:Ss,PipelineFactory:Ys,REGISTRY:ai,RemoteFactory:Os,RollingAverage:Ot,ScaleNumber:Lt,SetPoint:Rt,SinkPipeline:le,SourcePipeline:oe,StaticFactory:Zs,StreamChannelData:he,StreamChannelValue:ce,StringifyNumber:Dt,TransformerFactory:Fs,UnarySinkTransformer:Ms,UnarySourceTransformer:pt,WithinBounds:Mt,booleanSinkSpecZ:Pn,booleanSinkTransformerSpecZ:Sa,booleanSourceSpecZ:rr,booleanSourceTransformerSpecZ:Ea,booleanStatus:Za,booleanStatusProps:js,channelData:As,colorGradient:Ks,colorGradientProps:Xs,colorSourceSpecZ:sr,connectionZ:or,factory:ei,fixedArray:Ra,fixedColor:Da,fixedColorSourcePropsZ:Gs,fixedNumber:Ya,fixedNumberPropsZ:Us,fixedSeriesPropsZ:dr,fixedString:za,fixedStringPropsZ:Is,iterativeArray:Ma,iterativeSeriesPropsZ:Ns,mean:$a,noopBooleanSinkSpec:Sn,noopBooleanSourceSpec:er,noopColorSourceSpec:En,noopNumericSinkSpec:ws,noopNumericSourceSpec:bs,noopSeriesSourceSpec:Ts,noopStatusSourceSpec:nr,noopStringSourceSpec:vs,numberSinkSpecZ:ks,numberSourceSpecZ:Ps,providerStateZ:mr,registerFactory:xs,rollingAverage:Vs,rollingAverageProps:gr,scaleNumber:Js,scaleNumberProps:Qs,seriesSourceSpecZ:Je,setProvider:ys,setpoint:_s,sinkPipeline:Ds,sinkPipelinePropsZ:cr,sinkSpecZ:Cn,sinkTransformerSpecZ:Cs,sourcePipeline:zs,sourcePipelinePropsZ:lr,sourceSpecZ:ot,sourceTransformerSpecZ:Es,specZ:ze,statusSourceSpecZ:ir,streamChannelData:Ls,streamChannelValue:$s,streamChannelValuePropsZ:ur,stringSourceSpecZ:ar,stringifyNumber:Ws,stringifyNumberProps:pr,useProvider:Tn,useSink:Ye,useSource:H,withinBounds:Hs,withinBoundsProps:fr},Symbol.toStringTag,{value:"Module"})),oi=p.z.object({key:p.z.string(),size:p.z.number(),order:p.z.number(),loc:l.K.outer});p.z.record(oi);const ut=(e,n)=>Object.values(n).filter(({loc:t})=>t===e).sort((t,r)=>r.order-t.order),to=(e,n,t)=>{const r=n[e];if(r==null)return l.G.ZERO;const s=l.K.construct(r.loc),i=ut(s,n),a=l.K.construct(l.g.swap(l.K.direction(s))),o=ut(a,n),c=i.findIndex(({key:g})=>g===e),u=i.slice(0,c).reduce((g,{size:m})=>g+m,0),f=o.reduce((g,{size:m})=>g+m,0);switch(s){case"left":return l.G.translate(l.Eo.topLeft(t),[u,f]);case"right":return l.G.translate(l.Eo.topRight(t),[u-r.size,f]);case"top":return l.G.translate(l.Eo.topLeft(t),[f,u]);default:return l.G.translate(l.Eo.bottomLeft(t),[f,-u-r.size])}},eo=(e,n)=>{const t=ut("left",e),r=ut("right",e),s=ut("top",e),i=ut("bottom",e),a=t.reduce((f,{size:g})=>f+g,0),o=r.reduce((f,{size:g})=>f+g,0),c=s.reduce((f,{size:g})=>f+g,0),u=i.reduce((f,{size:g})=>f+g,0);return l.Eo.construct(l.G.translate(l.Eo.topLeft(n),{x:a,y:c}),l.Eo.width(n)-a-o,l.Eo.height(n)-c-u)};function Fe(e,n){return e==null||n==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function no(e,n){return e==null||n==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function yr(e){let n,t,r;e.length!==2?(n=Fe,t=(o,c)=>Fe(e(o),c),r=(o,c)=>e(o)-c):(n=e===Fe||e===no?e:ro,t=e,r=e);function s(o,c,u=0,f=o.length){if(u<f){if(n(c,c)!==0)return f;do{const g=u+f>>>1;t(o[g],c)<0?u=g+1:f=g}while(u<f)}return u}function i(o,c,u=0,f=o.length){if(u<f){if(n(c,c)!==0)return f;do{const g=u+f>>>1;t(o[g],c)<=0?u=g+1:f=g}while(u<f)}return u}function a(o,c,u=0,f=o.length){const g=s(o,c,u,f-1);return g>u&&r(o[g-1],c)>-r(o[g],c)?g-1:g}return{left:s,center:a,right:i}}function ro(){return 0}function so(e){return e===null?NaN:+e}const io=yr(Fe),ao=io.right;yr(so).center;const oo=Math.sqrt(50),lo=Math.sqrt(10),co=Math.sqrt(2);function nn(e,n,t){const r=(n-e)/Math.max(0,t),s=Math.floor(Math.log10(r)),i=r/Math.pow(10,s),a=i>=oo?10:i>=lo?5:i>=co?2:1;let o,c,u;return s<0?(u=Math.pow(10,-s)/a,o=Math.round(e*u),c=Math.round(n*u),o/u<e&&++o,c/u>n&&--c,u=-u):(u=Math.pow(10,s)*a,o=Math.round(e/u),c=Math.round(n/u),o*u<e&&++o,c*u>n&&--c),c<o&&.5<=t&&t<2?nn(e,n,t*2):[o,c,u]}function uo(e,n,t){if(n=+n,e=+e,t=+t,!(t>0))return[];if(e===n)return[e];const r=n<e,[s,i,a]=r?nn(n,e,t):nn(e,n,t);if(!(i>=s))return[];const o=i-s+1,c=new Array(o);if(r)if(a<0)for(let u=0;u<o;++u)c[u]=(i-u)/-a;else for(let u=0;u<o;++u)c[u]=(i-u)*a;else if(a<0)for(let u=0;u<o;++u)c[u]=(s+u)/-a;else for(let u=0;u<o;++u)c[u]=(s+u)*a;return c}function Hn(e,n,t){return n=+n,e=+e,t=+t,nn(e,n,t)[2]}function qn(e,n,t){n=+n,e=+e,t=+t;const r=n<e,s=r?Hn(n,e,t):Hn(e,n,t);return(r?-1:1)*(s<0?1/-s:s)}function li(e,n){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(n).domain(e);break}return this}function xr(e,n,t){e.prototype=n.prototype=t,t.constructor=e}function ci(e,n){var t=Object.create(e.prototype);for(var r in n)t[r]=n[r];return t}function Oe(){}var me=.7,rn=1/me,kt="\\s*([+-]?\\d+)\\s*",ye="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",X="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ho=/^#([0-9a-f]{3,8})$/,fo=new RegExp(`^rgb\\(${kt},${kt},${kt}\\)$`),po=new RegExp(`^rgb\\(${X},${X},${X}\\)$`),go=new RegExp(`^rgba\\(${kt},${kt},${kt},${ye}\\)$`),mo=new RegExp(`^rgba\\(${X},${X},${X},${ye}\\)$`),yo=new RegExp(`^hsl\\(${ye},${X},${X}\\)$`),xo=new RegExp(`^hsla\\(${ye},${X},${X},${ye}\\)$`),Nr={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};xr(Oe,Zt,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Ur,formatHex:Ur,formatHex8:wo,formatHsl:bo,formatRgb:Ir,toString:Ir});function Ur(){return this.rgb().formatHex()}function wo(){return this.rgb().formatHex8()}function bo(){return ui(this).formatHsl()}function Ir(){return this.rgb().formatRgb()}function Zt(e){var n,t;return e=(e+"").trim().toLowerCase(),(n=ho.exec(e))?(t=n[1].length,n=parseInt(n[1],16),t===6?Gr(n):t===3?new I(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):t===8?Ne(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):t===4?Ne(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|n&240,((n&15)<<4|n&15)/255):null):(n=fo.exec(e))?new I(n[1],n[2],n[3],1):(n=po.exec(e))?new I(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=go.exec(e))?Ne(n[1],n[2],n[3],n[4]):(n=mo.exec(e))?Ne(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=yo.exec(e))?_r(n[1],n[2]/100,n[3]/100,1):(n=xo.exec(e))?_r(n[1],n[2]/100,n[3]/100,n[4]):Nr.hasOwnProperty(e)?Gr(Nr[e]):e==="transparent"?new I(NaN,NaN,NaN,0):null}function Gr(e){return new I(e>>16&255,e>>8&255,e&255,1)}function Ne(e,n,t,r){return r<=0&&(e=n=t=NaN),new I(e,n,t,r)}function vo(e){return e instanceof Oe||(e=Zt(e)),e?(e=e.rgb(),new I(e.r,e.g,e.b,e.opacity)):new I}function jn(e,n,t,r){return arguments.length===1?vo(e):new I(e,n,t,r??1)}function I(e,n,t,r){this.r=+e,this.g=+n,this.b=+t,this.opacity=+r}xr(I,jn,ci(Oe,{brighter(e){return e=e==null?rn:Math.pow(rn,e),new I(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?me:Math.pow(me,e),new I(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new I(dt(this.r),dt(this.g),dt(this.b),sn(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:Br,formatHex:Br,formatHex8:To,formatRgb:Fr,toString:Fr}));function Br(){return`#${ht(this.r)}${ht(this.g)}${ht(this.b)}`}function To(){return`#${ht(this.r)}${ht(this.g)}${ht(this.b)}${ht((isNaN(this.opacity)?1:this.opacity)*255)}`}function Fr(){const e=sn(this.opacity);return`${e===1?"rgb(":"rgba("}${dt(this.r)}, ${dt(this.g)}, ${dt(this.b)}${e===1?")":`, ${e})`}`}function sn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function dt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function ht(e){return e=dt(e),(e<16?"0":"")+e.toString(16)}function _r(e,n,t,r){return r<=0?e=n=t=NaN:t<=0||t>=1?e=n=NaN:n<=0&&(e=NaN),new j(e,n,t,r)}function ui(e){if(e instanceof j)return new j(e.h,e.s,e.l,e.opacity);if(e instanceof Oe||(e=Zt(e)),!e)return new j;if(e instanceof j)return e;e=e.rgb();var n=e.r/255,t=e.g/255,r=e.b/255,s=Math.min(n,t,r),i=Math.max(n,t,r),a=NaN,o=i-s,c=(i+s)/2;return o?(n===i?a=(t-r)/o+(t<r)*6:t===i?a=(r-n)/o+2:a=(n-t)/o+4,o/=c<.5?i+s:2-i-s,a*=60):o=c>0&&c<1?0:a,new j(a,o,c,e.opacity)}function So(e,n,t,r){return arguments.length===1?ui(e):new j(e,n,t,r??1)}function j(e,n,t,r){this.h=+e,this.s=+n,this.l=+t,this.opacity=+r}xr(j,So,ci(Oe,{brighter(e){return e=e==null?rn:Math.pow(rn,e),new j(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?me:Math.pow(me,e),new j(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,n=isNaN(e)||isNaN(this.s)?0:this.s,t=this.l,r=t+(t<.5?t:1-t)*n,s=2*t-r;return new I(On(e>=240?e-240:e+120,s,r),On(e,s,r),On(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new j(Hr(this.h),Ue(this.s),Ue(this.l),sn(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 e=sn(this.opacity);return`${e===1?"hsl(":"hsla("}${Hr(this.h)}, ${Ue(this.s)*100}%, ${Ue(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Hr(e){return e=(e||0)%360,e<0?e+360:e}function Ue(e){return Math.max(0,Math.min(1,e||0))}function On(e,n,t){return(e<60?n+(t-n)*e/60:e<180?t:e<240?n+(t-n)*(240-e)/60:n)*255}const wr=e=>()=>e;function Eo(e,n){return function(t){return e+t*n}}function Co(e,n,t){return e=Math.pow(e,t),n=Math.pow(n,t)-e,t=1/t,function(r){return Math.pow(e+r*n,t)}}function Po(e){return(e=+e)==1?hi:function(n,t){return t-n?Co(n,t,e):wr(isNaN(n)?t:n)}}function hi(e,n){var t=n-e;return t?Eo(e,t):wr(isNaN(e)?n:e)}const Wn=function e(n){var t=Po(n);function r(s,i){var a=t((s=jn(s)).r,(i=jn(i)).r),o=t(s.g,i.g),c=t(s.b,i.b),u=hi(s.opacity,i.opacity);return function(f){return s.r=a(f),s.g=o(f),s.b=c(f),s.opacity=u(f),s+""}}return r.gamma=e,r}(1);function ko(e,n){n||(n=[]);var t=e?Math.min(n.length,e.length):0,r=n.slice(),s;return function(i){for(s=0;s<t;++s)r[s]=e[s]*(1-i)+n[s]*i;return r}}function Ro(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Mo(e,n){var t=n?n.length:0,r=e?Math.min(t,e.length):0,s=new Array(r),i=new Array(t),a;for(a=0;a<r;++a)s[a]=br(e[a],n[a]);for(;a<t;++a)i[a]=n[a];return function(o){for(a=0;a<r;++a)i[a]=s[a](o);return i}}function Yo(e,n){var t=new Date;return e=+e,n=+n,function(r){return t.setTime(e*(1-r)+n*r),t}}function xe(e,n){return e=+e,n=+n,function(t){return e*(1-t)+n*t}}function zo(e,n){var t={},r={},s;(e===null||typeof e!="object")&&(e={}),(n===null||typeof n!="object")&&(n={});for(s in n)s in e?t[s]=br(e[s],n[s]):r[s]=n[s];return function(i){for(s in t)r[s]=t[s](i);return r}}var Vn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,An=new RegExp(Vn.source,"g");function Do(e){return function(){return e}}function Oo(e){return function(n){return e(n)+""}}function di(e,n){var t=Vn.lastIndex=An.lastIndex=0,r,s,i,a=-1,o=[],c=[];for(e=e+"",n=n+"";(r=Vn.exec(e))&&(s=An.exec(n));)(i=s.index)>t&&(i=n.slice(t,i),o[a]?o[a]+=i:o[++a]=i),(r=r[0])===(s=s[0])?o[a]?o[a]+=s:o[++a]=s:(o[++a]=null,c.push({i:a,x:xe(r,s)})),t=An.lastIndex;return t<n.length&&(i=n.slice(t),o[a]?o[a]+=i:o[++a]=i),o.length<2?c[0]?Oo(c[0].x):Do(n):(n=c.length,function(u){for(var f=0,g;f<n;++f)o[(g=c[f]).i]=g.x(u);return o.join("")})}function br(e,n){var t=typeof n,r;return n==null||t==="boolean"?wr(n):(t==="number"?xe:t==="string"?(r=Zt(n))?(n=r,Wn):di:n instanceof Zt?Wn:n instanceof Date?Yo:Ro(n)?ko:Array.isArray(n)?Mo:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?zo:xe)(e,n)}function Ao(e,n){return e=+e,n=+n,function(t){return Math.round(e*(1-t)+n*t)}}function Lo(e){return function(){return e}}function $o(e){return+e}var qr=[0,1];function vt(e){return e}function Xn(e,n){return(n-=e=+e)?function(t){return(t-e)/n}:Lo(isNaN(n)?NaN:.5)}function Zo(e,n){var t;return e>n&&(t=e,e=n,n=t),function(r){return Math.max(e,Math.min(n,r))}}function No(e,n,t){var r=e[0],s=e[1],i=n[0],a=n[1];return s<r?(r=Xn(s,r),i=t(a,i)):(r=Xn(r,s),i=t(i,a)),function(o){return i(r(o))}}function Uo(e,n,t){var r=Math.min(e.length,n.length)-1,s=new Array(r),i=new Array(r),a=-1;for(e[r]<e[0]&&(e=e.slice().reverse(),n=n.slice().reverse());++a<r;)s[a]=Xn(e[a],e[a+1]),i[a]=t(n[a],n[a+1]);return function(o){var c=ao(e,o,1,r)-1;return i[c](s[c](o))}}function fi(e,n){return n.domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown())}function Io(){var e=qr,n=qr,t=br,r,s,i,a=vt,o,c,u;function f(){var m=Math.min(e.length,n.length);return a!==vt&&(a=Zo(e[0],e[m-1])),o=m>2?Uo:No,c=u=null,g}function g(m){return m==null||isNaN(m=+m)?i:(c||(c=o(e.map(r),n,t)))(r(a(m)))}return g.invert=function(m){return a(s((u||(u=o(n,e.map(r),xe)))(m)))},g.domain=function(m){return arguments.length?(e=Array.from(m,$o),f()):e.slice()},g.range=function(m){return arguments.length?(n=Array.from(m),f()):n.slice()},g.rangeRound=function(m){return n=Array.from(m),t=Ao,f()},g.clamp=function(m){return arguments.length?(a=m?!0:vt,f()):a!==vt},g.interpolate=function(m){return arguments.length?(t=m,f()):t},g.unknown=function(m){return arguments.length?(i=m,g):i},function(m,w){return r=m,s=w,f()}}function pi(){return Io()(vt,vt)}function Go(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function an(e,n){if((t=(e=n?e.toExponential(n-1):e.toExponential()).indexOf("e"))<0)return null;var t,r=e.slice(0,t);return[r.length>1?r[0]+r.slice(2):r,+e.slice(t+1)]}function Nt(e){return e=an(Math.abs(e)),e?e[1]:NaN}function Bo(e,n){return function(t,r){for(var s=t.length,i=[],a=0,o=e[0],c=0;s>0&&o>0&&(c+o+1>r&&(o=Math.max(1,r-c)),i.push(t.substring(s-=o,s+o)),!((c+=o+1)>r));)o=e[a=(a+1)%e.length];return i.reverse().join(n)}}function Fo(e){return function(n){return n.replace(/[0-9]/g,function(t){return e[+t]})}}var _o=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function on(e){if(!(n=_o.exec(e)))throw new Error("invalid format: "+e);var n;return new vr({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}on.prototype=vr.prototype;function vr(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}vr.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 Ho(e){t:for(var n=e.length,t=1,r=-1,s;t<n;++t)switch(e[t]){case".":r=s=t;break;case"0":r===0&&(r=t),s=t;break;default:if(!+e[t])break t;r>0&&(r=0);break}return r>0?e.slice(0,r)+e.slice(s+1):e}var gi;function qo(e,n){var t=an(e,n);if(!t)return e+"";var r=t[0],s=t[1],i=s-(gi=Math.max(-8,Math.min(8,Math.floor(s/3)))*3)+1,a=r.length;return i===a?r:i>a?r+new Array(i-a+1).join("0"):i>0?r.slice(0,i)+"."+r.slice(i):"0."+new Array(1-i).join("0")+an(e,Math.max(0,n+i-1))[0]}function jr(e,n){var t=an(e,n);if(!t)return e+"";var r=t[0],s=t[1];return s<0?"0."+new Array(-s).join("0")+r:r.length>s+1?r.slice(0,s+1)+"."+r.slice(s+1):r+new Array(s-r.length+2).join("0")}const Wr={"%":(e,n)=>(e*100).toFixed(n),b:e=>Math.round(e).toString(2),c:e=>e+"",d:Go,e:(e,n)=>e.toExponential(n),f:(e,n)=>e.toFixed(n),g:(e,n)=>e.toPrecision(n),o:e=>Math.round(e).toString(8),p:(e,n)=>jr(e*100,n),r:jr,s:qo,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Vr(e){return e}var Xr=Array.prototype.map,Kr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function jo(e){var n=e.grouping===void 0||e.thousands===void 0?Vr:Bo(Xr.call(e.grouping,Number),e.thousands+""),t=e.currency===void 0?"":e.currency[0]+"",r=e.currency===void 0?"":e.currency[1]+"",s=e.decimal===void 0?".":e.decimal+"",i=e.numerals===void 0?Vr:Fo(Xr.call(e.numerals,String)),a=e.percent===void 0?"%":e.percent+"",o=e.minus===void 0?"−":e.minus+"",c=e.nan===void 0?"NaN":e.nan+"";function u(g){g=on(g);var m=g.fill,w=g.align,b=g.sign,v=g.symbol,E=g.zero,M=g.width,D=g.comma,P=g.precision,z=g.trim,L=g.type;L==="n"?(D=!0,L="g"):Wr[L]||(P===void 0&&(P=12),z=!0,L="g"),(E||m==="0"&&w==="=")&&(E=!0,m="0",w="=");var T=v==="$"?t:v==="#"&&/[boxX]/.test(L)?"0"+L.toLowerCase():"",$=v==="$"?r:/[%p]/.test(L)?a:"",lt=Wr[L],Yn=/[defgprs%]/.test(L);P=P===void 0?6:/[gprs]/.test(L)?Math.max(1,Math.min(21,P)):Math.max(0,Math.min(20,P));function $e(C){var Q=T,N=$,st,Ze,yt;if(L==="c")N=lt(C)+N,C="";else{C=+C;var xt=C<0||1/C<0;if(C=isNaN(C)?c:lt(Math.abs(C),P),z&&(C=Ho(C)),xt&&+C==0&&b!=="+"&&(xt=!1),Q=(xt?b==="("?b:o:b==="-"||b==="("?"":b)+Q,N=(L==="s"?Kr[8+gi/3]:"")+N+(xt&&b==="("?")":""),Yn){for(st=-1,Ze=C.length;++st<Ze;)if(yt=C.charCodeAt(st),48>yt||yt>57){N=(yt===46?s+C.slice(st+1):C.slice(st))+N,C=C.slice(0,st);break}}}D&&!E&&(C=n(C,1/0));var wt=Q.length+C.length+N.length,q=wt<M?new Array(M-wt+1).join(m):"";switch(D&&E&&(C=n(q+C,q.length?M-N.length:1/0),q=""),w){case"<":C=Q+C+N+q;break;case"=":C=Q+q+C+N;break;case"^":C=q.slice(0,wt=q.length>>1)+Q+C+N+q.slice(wt);break;default:C=q+Q+C+N;break}return i(C)}return $e.toString=function(){return g+""},$e}function f(g,m){var w=u((g=on(g),g.type="f",g)),b=Math.max(-8,Math.min(8,Math.floor(Nt(m)/3)))*3,v=Math.pow(10,-b),E=Kr[8+b/3];return function(M){return w(v*M)+E}}return{format:u,formatPrefix:f}}var Ie,mi,yi;Wo({thousands:",",grouping:[3],currency:["$",""]});function Wo(e){return Ie=jo(e),mi=Ie.format,yi=Ie.formatPrefix,Ie}function Vo(e){return Math.max(0,-Nt(Math.abs(e)))}function Xo(e,n){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Nt(n)/3)))*3-Nt(Math.abs(e)))}function Ko(e,n){return e=Math.abs(e),n=Math.abs(n)-e,Math.max(0,Nt(n)-Nt(e))+1}function Qo(e,n,t,r){var s=qn(e,n,t),i;switch(r=on(r??",f"),r.type){case"s":{var a=Math.max(Math.abs(e),Math.abs(n));return r.precision==null&&!isNaN(i=Xo(s,a))&&(r.precision=i),yi(r,a)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(i=Ko(s,Math.max(Math.abs(e),Math.abs(n))))&&(r.precision=i-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(i=Vo(s))&&(r.precision=i-(r.type==="%")*2);break}}return mi(r)}function Jo(e){var n=e.domain;return e.ticks=function(t){var r=n();return uo(r[0],r[r.length-1],t??10)},e.tickFormat=function(t,r){var s=n();return Qo(s[0],s[s.length-1],t??10,r)},e.nice=function(t){t==null&&(t=10);var r=n(),s=0,i=r.length-1,a=r[s],o=r[i],c,u,f=10;for(o<a&&(u=a,a=o,o=u,u=s,s=i,i=u);f-- >0;){if(u=Hn(a,o,t),u===c)return r[s]=a,r[i]=o,n(r);if(u>0)a=Math.floor(a/u)*u,o=Math.ceil(o/u)*u;else if(u<0)a=Math.ceil(a*u)/u,o=Math.floor(o*u)/u;else break;c=u}return e},e}function xi(){var e=pi();return e.copy=function(){return fi(e,xi())},li.apply(e,arguments),Jo(e)}function tl(e,n){e=e.slice();var t=0,r=e.length-1,s=e[t],i=e[r],a;return i<s&&(a=t,t=r,r=a,a=s,s=i,i=a),e[t]=n.floor(s),e[r]=n.ceil(i),e}const Ln=new Date,$n=new Date;function O(e,n,t,r){function s(i){return e(i=arguments.length===0?new Date:new Date(+i)),i}return s.floor=i=>(e(i=new Date(+i)),i),s.ceil=i=>(e(i=new Date(i-1)),n(i,1),e(i),i),s.round=i=>{const a=s(i),o=s.ceil(i);return i-a<o-i?a:o},s.offset=(i,a)=>(n(i=new Date(+i),a==null?1:Math.floor(a)),i),s.range=(i,a,o)=>{const c=[];if(i=s.ceil(i),o=o==null?1:Math.floor(o),!(i<a)||!(o>0))return c;let u;do c.push(u=new Date(+i)),n(i,o),e(i);while(u<i&&i<a);return c},s.filter=i=>O(a=>{if(a>=a)for(;e(a),!i(a);)a.setTime(a-1)},(a,o)=>{if(a>=a)if(o<0)for(;++o<=0;)for(;n(a,-1),!i(a););else for(;--o>=0;)for(;n(a,1),!i(a););}),t&&(s.count=(i,a)=>(Ln.setTime(+i),$n.setTime(+a),e(Ln),e($n),Math.floor(t(Ln,$n))),s.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?s.filter(r?a=>r(a)%i===0:a=>s.count(0,a)%i===0):s)),s}const ln=O(()=>{},(e,n)=>{e.setTime(+e+n)},(e,n)=>n-e);ln.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?O(n=>{n.setTime(Math.floor(n/e)*e)},(n,t)=>{n.setTime(+n+t*e)},(n,t)=>(t-n)/e):ln);ln.range;const J=1e3,_=J*60,tt=_*60,nt=tt*24,Tr=nt*7,Qr=nt*30,Zn=nt*365,Tt=O(e=>{e.setTime(e-e.getMilliseconds())},(e,n)=>{e.setTime(+e+n*J)},(e,n)=>(n-e)/J,e=>e.getUTCSeconds());Tt.range;const Sr=O(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*J)},(e,n)=>{e.setTime(+e+n*_)},(e,n)=>(n-e)/_,e=>e.getMinutes());Sr.range;const el=O(e=>{e.setUTCSeconds(0,0)},(e,n)=>{e.setTime(+e+n*_)},(e,n)=>(n-e)/_,e=>e.getUTCMinutes());el.range;const Er=O(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*J-e.getMinutes()*_)},(e,n)=>{e.setTime(+e+n*tt)},(e,n)=>(n-e)/tt,e=>e.getHours());Er.range;const nl=O(e=>{e.setUTCMinutes(0,0,0)},(e,n)=>{e.setTime(+e+n*tt)},(e,n)=>(n-e)/tt,e=>e.getUTCHours());nl.range;const Ae=O(e=>e.setHours(0,0,0,0),(e,n)=>e.setDate(e.getDate()+n),(e,n)=>(n-e-(n.getTimezoneOffset()-e.getTimezoneOffset())*_)/nt,e=>e.getDate()-1);Ae.range;const Cr=O(e=>{e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCDate(e.getUTCDate()+n)},(e,n)=>(n-e)/nt,e=>e.getUTCDate()-1);Cr.range;const rl=O(e=>{e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCDate(e.getUTCDate()+n)},(e,n)=>(n-e)/nt,e=>Math.floor(e/nt));rl.range;function gt(e){return O(n=>{n.setDate(n.getDate()-(n.getDay()+7-e)%7),n.setHours(0,0,0,0)},(n,t)=>{n.setDate(n.getDate()+t*7)},(n,t)=>(t-n-(t.getTimezoneOffset()-n.getTimezoneOffset())*_)/Tr)}const Mn=gt(0),cn=gt(1),sl=gt(2),il=gt(3),Ut=gt(4),al=gt(5),ol=gt(6);Mn.range;cn.range;sl.range;il.range;Ut.range;al.range;ol.range;function mt(e){return O(n=>{n.setUTCDate(n.getUTCDate()-(n.getUTCDay()+7-e)%7),n.setUTCHours(0,0,0,0)},(n,t)=>{n.setUTCDate(n.getUTCDate()+t*7)},(n,t)=>(t-n)/Tr)}const wi=mt(0),un=mt(1),ll=mt(2),cl=mt(3),It=mt(4),ul=mt(5),hl=mt(6);wi.range;un.range;ll.range;cl.range;It.range;ul.range;hl.range;const Pr=O(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,n)=>{e.setMonth(e.getMonth()+n)},(e,n)=>n.getMonth()-e.getMonth()+(n.getFullYear()-e.getFullYear())*12,e=>e.getMonth());Pr.range;const dl=O(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCMonth(e.getUTCMonth()+n)},(e,n)=>n.getUTCMonth()-e.getUTCMonth()+(n.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());dl.range;const rt=O(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n)},(e,n)=>n.getFullYear()-e.getFullYear(),e=>e.getFullYear());rt.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:O(n=>{n.setFullYear(Math.floor(n.getFullYear()/e)*e),n.setMonth(0,1),n.setHours(0,0,0,0)},(n,t)=>{n.setFullYear(n.getFullYear()+t*e)});rt.range;const ft=O(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n)},(e,n)=>n.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());ft.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:O(n=>{n.setUTCFullYear(Math.floor(n.getUTCFullYear()/e)*e),n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,t)=>{n.setUTCFullYear(n.getUTCFullYear()+t*e)});ft.range;function fl(e,n,t,r,s,i){const a=[[Tt,1,J],[Tt,5,5*J],[Tt,15,15*J],[Tt,30,30*J],[i,1,_],[i,5,5*_],[i,15,15*_],[i,30,30*_],[s,1,tt],[s,3,3*tt],[s,6,6*tt],[s,12,12*tt],[r,1,nt],[r,2,2*nt],[t,1,Tr],[n,1,Qr],[n,3,3*Qr],[e,1,Zn]];function o(u,f,g){const m=f<u;m&&([u,f]=[f,u]);const w=g&&typeof g.range=="function"?g:c(u,f,g),b=w?w.range(u,+f+1):[];return m?b.reverse():b}function c(u,f,g){const m=Math.abs(f-u)/g,w=yr(([,,E])=>E).right(a,m);if(w===a.length)return e.every(qn(u/Zn,f/Zn,g));if(w===0)return ln.every(Math.max(qn(u,f,g),1));const[b,v]=a[m/a[w-1][2]<a[w][2]/m?w-1:w];return b.every(v)}return[o,c]}const[pl,gl]=fl(rt,Pr,Mn,Ae,Er,Sr);function Nn(e){if(0<=e.y&&e.y<100){var n=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return n.setFullYear(e.y),n}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function Un(e){if(0<=e.y&&e.y<100){var n=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return n.setUTCFullYear(e.y),n}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function Wt(e,n,t){return{y:e,m:n,d:t,H:0,M:0,S:0,L:0}}function ml(e){var n=e.dateTime,t=e.date,r=e.time,s=e.periods,i=e.days,a=e.shortDays,o=e.months,c=e.shortMonths,u=Vt(s),f=Xt(s),g=Vt(i),m=Xt(i),w=Vt(a),b=Xt(a),v=Vt(o),E=Xt(o),M=Vt(c),D=Xt(c),P={a:xt,A:wt,b:q,B:sa,c:null,d:ss,e:ss,f:Ul,g:Vl,G:Kl,H:$l,I:Zl,j:Nl,L:bi,m:Il,M:Gl,p:ia,q:aa,Q:os,s:ls,S:Bl,u:Fl,U:_l,V:Hl,w:ql,W:jl,x:null,X:null,y:Wl,Y:Xl,Z:Ql,"%":as},z={a:oa,A:la,b:ca,B:ua,c:null,d:is,e:is,f:nc,g:dc,G:pc,H:Jl,I:tc,j:ec,L:Ti,m:rc,M:sc,p:ha,q:da,Q:os,s:ls,S:ic,u:ac,U:oc,V:lc,w:cc,W:uc,x:null,X:null,y:hc,Y:fc,Z:gc,"%":as},L={a:$e,A:C,b:Q,B:N,c:st,d:ns,e:ns,f:Dl,g:es,G:ts,H:rs,I:rs,j:Rl,L:zl,m:kl,M:Ml,p:Yn,q:Pl,Q:Al,s:Ll,S:Yl,u:vl,U:Tl,V:Sl,w:bl,W:El,x:Ze,X:yt,y:es,Y:ts,Z:Cl,"%":Ol};P.x=T(t,P),P.X=T(r,P),P.c=T(n,P),z.x=T(t,z),z.X=T(r,z),z.c=T(n,z);function T(x,S){return function(k){var y=[],U=-1,Y=0,G=x.length,B,ct,Lr;for(k instanceof Date||(k=new Date(+k));++U<G;)x.charCodeAt(U)===37&&(y.push(x.slice(Y,U)),(ct=Jr[B=x.charAt(++U)])!=null?B=x.charAt(++U):ct=B==="e"?" ":"0",(Lr=S[B])&&(B=Lr(k,ct)),y.push(B),Y=U+1);return y.push(x.slice(Y,U)),y.join("")}}function $(x,S){return function(k){var y=Wt(1900,void 0,1),U=lt(y,x,k+="",0),Y,G;if(U!=k.length)return null;if("Q"in y)return new Date(y.Q);if("s"in y)return new Date(y.s*1e3+("L"in y?y.L:0));if(S&&!("Z"in y)&&(y.Z=0),"p"in y&&(y.H=y.H%12+y.p*12),y.m===void 0&&(y.m="q"in y?y.q:0),"V"in y){if(y.V<1||y.V>53)return null;"w"in y||(y.w=1),"Z"in y?(Y=Un(Wt(y.y,0,1)),G=Y.getUTCDay(),Y=G>4||G===0?un.ceil(Y):un(Y),Y=Cr.offset(Y,(y.V-1)*7),y.y=Y.getUTCFullYear(),y.m=Y.getUTCMonth(),y.d=Y.getUTCDate()+(y.w+6)%7):(Y=Nn(Wt(y.y,0,1)),G=Y.getDay(),Y=G>4||G===0?cn.ceil(Y):cn(Y),Y=Ae.offset(Y,(y.V-1)*7),y.y=Y.getFullYear(),y.m=Y.getMonth(),y.d=Y.getDate()+(y.w+6)%7)}else("W"in y||"U"in y)&&("w"in y||(y.w="u"in y?y.u%7:"W"in y?1:0),G="Z"in y?Un(Wt(y.y,0,1)).getUTCDay():Nn(Wt(y.y,0,1)).getDay(),y.m=0,y.d="W"in y?(y.w+6)%7+y.W*7-(G+5)%7:y.w+y.U*7-(G+6)%7);return"Z"in y?(y.H+=y.Z/100|0,y.M+=y.Z%100,Un(y)):Nn(y)}}function lt(x,S,k,y){for(var U=0,Y=S.length,G=k.length,B,ct;U<Y;){if(y>=G)return-1;if(B=S.charCodeAt(U++),B===37){if(B=S.charAt(U++),ct=L[B in Jr?S.charAt(U++):B],!ct||(y=ct(x,k,y))<0)return-1}else if(B!=k.charCodeAt(y++))return-1}return y}function Yn(x,S,k){var y=u.exec(S.slice(k));return y?(x.p=f.get(y[0].toLowerCase()),k+y[0].length):-1}function $e(x,S,k){var y=w.exec(S.slice(k));return y?(x.w=b.get(y[0].toLowerCase()),k+y[0].length):-1}function C(x,S,k){var y=g.exec(S.slice(k));return y?(x.w=m.get(y[0].toLowerCase()),k+y[0].length):-1}function Q(x,S,k){var y=M.exec(S.slice(k));return y?(x.m=D.get(y[0].toLowerCase()),k+y[0].length):-1}function N(x,S,k){var y=v.exec(S.slice(k));return y?(x.m=E.get(y[0].toLowerCase()),k+y[0].length):-1}function st(x,S,k){return lt(x,n,S,k)}function Ze(x,S,k){return lt(x,t,S,k)}function yt(x,S,k){return lt(x,r,S,k)}function xt(x){return a[x.getDay()]}function wt(x){return i[x.getDay()]}function q(x){return c[x.getMonth()]}function sa(x){return o[x.getMonth()]}function ia(x){return s[+(x.getHours()>=12)]}function aa(x){return 1+~~(x.getMonth()/3)}function oa(x){return a[x.getUTCDay()]}function la(x){return i[x.getUTCDay()]}function ca(x){return c[x.getUTCMonth()]}function ua(x){return o[x.getUTCMonth()]}function ha(x){return s[+(x.getUTCHours()>=12)]}function da(x){return 1+~~(x.getUTCMonth()/3)}return{format:function(x){var S=T(x+="",P);return S.toString=function(){return x},S},parse:function(x){var S=$(x+="",!1);return S.toString=function(){return x},S},utcFormat:function(x){var S=T(x+="",z);return S.toString=function(){return x},S},utcParse:function(x){var S=$(x+="",!0);return S.toString=function(){return x},S}}}var Jr={"-":"",_:" ",0:"0"},A=/^\s*\d+/,yl=/^%/,xl=/[\\^$*+?|[\]().{}]/g;function R(e,n,t){var r=e<0?"-":"",s=(r?-e:e)+"",i=s.length;return r+(i<t?new Array(t-i+1).join(n)+s:s)}function wl(e){return e.replace(xl,"\\$&")}function Vt(e){return new RegExp("^(?:"+e.map(wl).join("|")+")","i")}function Xt(e){return new Map(e.map((n,t)=>[n.toLowerCase(),t]))}function bl(e,n,t){var r=A.exec(n.slice(t,t+1));return r?(e.w=+r[0],t+r[0].length):-1}function vl(e,n,t){var r=A.exec(n.slice(t,t+1));return r?(e.u=+r[0],t+r[0].length):-1}function Tl(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.U=+r[0],t+r[0].length):-1}function Sl(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.V=+r[0],t+r[0].length):-1}function El(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.W=+r[0],t+r[0].length):-1}function ts(e,n,t){var r=A.exec(n.slice(t,t+4));return r?(e.y=+r[0],t+r[0].length):-1}function es(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),t+r[0].length):-1}function Cl(e,n,t){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(n.slice(t,t+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||"00")),t+r[0].length):-1}function Pl(e,n,t){var r=A.exec(n.slice(t,t+1));return r?(e.q=r[0]*3-3,t+r[0].length):-1}function kl(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.m=r[0]-1,t+r[0].length):-1}function ns(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.d=+r[0],t+r[0].length):-1}function Rl(e,n,t){var r=A.exec(n.slice(t,t+3));return r?(e.m=0,e.d=+r[0],t+r[0].length):-1}function rs(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.H=+r[0],t+r[0].length):-1}function Ml(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.M=+r[0],t+r[0].length):-1}function Yl(e,n,t){var r=A.exec(n.slice(t,t+2));return r?(e.S=+r[0],t+r[0].length):-1}function zl(e,n,t){var r=A.exec(n.slice(t,t+3));return r?(e.L=+r[0],t+r[0].length):-1}function Dl(e,n,t){var r=A.exec(n.slice(t,t+6));return r?(e.L=Math.floor(r[0]/1e3),t+r[0].length):-1}function Ol(e,n,t){var r=yl.exec(n.slice(t,t+1));return r?t+r[0].length:-1}function Al(e,n,t){var r=A.exec(n.slice(t));return r?(e.Q=+r[0],t+r[0].length):-1}function Ll(e,n,t){var r=A.exec(n.slice(t));return r?(e.s=+r[0],t+r[0].length):-1}function ss(e,n){return R(e.getDate(),n,2)}function $l(e,n){return R(e.getHours(),n,2)}function Zl(e,n){return R(e.getHours()%12||12,n,2)}function Nl(e,n){return R(1+Ae.count(rt(e),e),n,3)}function bi(e,n){return R(e.getMilliseconds(),n,3)}function Ul(e,n){return bi(e,n)+"000"}function Il(e,n){return R(e.getMonth()+1,n,2)}function Gl(e,n){return R(e.getMinutes(),n,2)}function Bl(e,n){return R(e.getSeconds(),n,2)}function Fl(e){var n=e.getDay();return n===0?7:n}function _l(e,n){return R(Mn.count(rt(e)-1,e),n,2)}function vi(e){var n=e.getDay();return n>=4||n===0?Ut(e):Ut.ceil(e)}function Hl(e,n){return e=vi(e),R(Ut.count(rt(e),e)+(rt(e).getDay()===4),n,2)}function ql(e){return e.getDay()}function jl(e,n){return R(cn.count(rt(e)-1,e),n,2)}function Wl(e,n){return R(e.getFullYear()%100,n,2)}function Vl(e,n){return e=vi(e),R(e.getFullYear()%100,n,2)}function Xl(e,n){return R(e.getFullYear()%1e4,n,4)}function Kl(e,n){var t=e.getDay();return e=t>=4||t===0?Ut(e):Ut.ceil(e),R(e.getFullYear()%1e4,n,4)}function Ql(e){var n=e.getTimezoneOffset();return(n>0?"-":(n*=-1,"+"))+R(n/60|0,"0",2)+R(n%60,"0",2)}function is(e,n){return R(e.getUTCDate(),n,2)}function Jl(e,n){return R(e.getUTCHours(),n,2)}function tc(e,n){return R(e.getUTCHours()%12||12,n,2)}function ec(e,n){return R(1+Cr.count(ft(e),e),n,3)}function Ti(e,n){return R(e.getUTCMilliseconds(),n,3)}function nc(e,n){return Ti(e,n)+"000"}function rc(e,n){return R(e.getUTCMonth()+1,n,2)}function sc(e,n){return R(e.getUTCMinutes(),n,2)}function ic(e,n){return R(e.getUTCSeconds(),n,2)}function ac(e){var n=e.getUTCDay();return n===0?7:n}function oc(e,n){return R(wi.count(ft(e)-1,e),n,2)}function Si(e){var n=e.getUTCDay();return n>=4||n===0?It(e):It.ceil(e)}function lc(e,n){return e=Si(e),R(It.count(ft(e),e)+(ft(e).getUTCDay()===4),n,2)}function cc(e){return e.getUTCDay()}function uc(e,n){return R(un.count(ft(e)-1,e),n,2)}function hc(e,n){return R(e.getUTCFullYear()%100,n,2)}function dc(e,n){return e=Si(e),R(e.getUTCFullYear()%100,n,2)}function fc(e,n){return R(e.getUTCFullYear()%1e4,n,4)}function pc(e,n){var t=e.getUTCDay();return e=t>=4||t===0?It(e):It.ceil(e),R(e.getUTCFullYear()%1e4,n,4)}function gc(){return"+0000"}function as(){return"%"}function os(e){return+e}function ls(e){return Math.floor(+e/1e3)}var bt,Ei;mc({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 mc(e){return bt=ml(e),Ei=bt.format,bt.parse,bt.utcFormat,bt.utcParse,bt}function yc(e){return new Date(e)}function xc(e){return e instanceof Date?+e:+new Date(+e)}function Ci(e,n,t,r,s,i,a,o,c,u){var f=pi(),g=f.invert,m=f.domain,w=u(".%L"),b=u(":%S"),v=u("%I:%M"),E=u("%I %p"),M=u("%a %d"),D=u("%b %d"),P=u("%B"),z=u("%Y");function L(T){return(c(T)<T?w:o(T)<T?b:a(T)<T?v:i(T)<T?E:r(T)<T?s(T)<T?M:D:t(T)<T?P:z)(T)}return f.invert=function(T){return new Date(g(T))},f.domain=function(T){return arguments.length?m(Array.from(T,xc)):m().map(yc)},f.ticks=function(T){var $=m();return e($[0],$[$.length-1],T??10)},f.tickFormat=function(T,$){return $==null?L:u($)},f.nice=function(T){var $=m();return(!T||typeof T.range!="function")&&(T=n($[0],$[$.length-1],T??10)),T?m(tl($,T)):f},f.copy=function(){return fi(f,Ci(e,n,t,r,s,i,a,o,c,u))},f}function wc(){return li.apply(Ci(pl,gl,rt,Pr,Mn,Ae,Er,Sr,Tt,Ei).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const kr=p.z.enum(["linear","time"]),Rr=p.z.object({tickSpacing:p.z.number().default(75),type:kr.optional().default("linear")}),Kn=e=>{const n=Rr.parse(e);return Tc[n.type](n)};class bc{constructor(n){h(this,"props");this.props=n}generate({decimalToDataScale:n,size:t}){const r=[0,t],s=[new d.m(n.pos(0)).date(),new d.m(n.pos(1)).date()],i=wc().domain(s).range(r);return i.ticks(Pi(t,this.props.tickSpacing)).map(o=>({label:this.tickLabel(o),position:i(o)}))}tickLabel(n){const t=new d.m(n).date();let r=`:${t.getSeconds()}`;if(t.getMilliseconds()!==0){const i=Math.round(t.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");r+=`.${i}`}return t.getSeconds()===0&&t.getMilliseconds()===0&&(r=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`),r}}class vc{constructor(n){h(this,"props");this.props=n}generate({decimalToDataScale:n,size:t}){const r=[0,t],s=[n.pos(0),n.pos(1)],i=xi().domain(s).range(r),a=Pi(t,this.props.tickSpacing);return i.ticks(a).map(c=>({label:this.tickLabel(c),position:i(c)}))}tickLabel(n){return n.toString()}}const Pi=(e,n)=>{const t=Math.floor(e/n);return t>0?t:1},Tc={linear:e=>new vc(e),time:e=>new bc(e)},Mr=Rr.extend({color:l.Color.z,type:kr.optional().default("linear"),font:p.z.string(),showGrid:p.z.boolean().optional().default(!0),location:l.K.outer,gridColor:l.Color.z}),W=4;class cs{constructor(n,t){h(this,"numberDims");h(this,"negativeWidth");h(this,"periodWidth");h(this,"colonWidth");this.numberDims=d.dimensions("0",t,n),this.negativeWidth=d.dimensions("-",t,n).width,this.periodWidth=d.dimensions(".",t,n).width,this.colonWidth=d.dimensions(":",t,n).width}get(n){const t={width:0,height:this.numberDims.height};let r=n.length;return n.includes(".")&&(t.width+=this.periodWidth,r-=1),n.startsWith("-")&&(t.width+=this.negativeWidth,r-=1),n.includes(":")&&(t.width+=this.colonWidth,r-=1),t.width+=r*this.numberDims.width,t}}let ki=class{constructor(n,t){h(this,"ctx");h(this,"state");h(this,"tickFactory");h(this,"dimensions");this.ctx=n,this.state=t,this.tickFactory=Kn(this.state),this.dimensions=new cs(n.lower2d,t.font)}setState(n){this.state=d.prettyParse(Mr,n),this.tickFactory=Kn(n),this.dimensions=new cs(this.ctx.lower2d,this.state.font)}render(n){const{lower2d:t}=this.ctx;switch(t.font=this.state.font,t.fillStyle=this.state.color.hex,t.lineWidth=1,this.state.location){case"left":return this.drawLeft(n);case"right":return this.drawRight(n);case"top":return this.drawTop(n);default:return this.drawBottom(n)}}drawBottom(n){const{lower2d:t}=this.ctx,{plot:r}=n,s=l.Eo.width(r),i=l.Eo.height(r),a=n.position,o=this.tickFactory.generate({...n,size:s});return this.maybeDrawGrid(s,o,u=>[l.G.translate(a,"x",u.position),l.G.translate(a,{x:u.position,y:-i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,l.G.translate(a,"x",s)),{size:this.drawTicks(o,(u,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y+W),t.stroke(),t.fillText(f.label,a.x+f.position-u.width/2,a.y+5+u.height)}).height+W+6}}drawTop(n){const{lower2d:t}=this.ctx,{plot:r}=n,s=l.Eo.width(r),i=l.Eo.height(r),a=l.G.translate(n.position,"y",n.size),o=this.tickFactory.generate({...n,size:s});return this.maybeDrawGrid(s,o,u=>[l.G.translate(a,"x",u.position),l.G.translate(a,{x:u.position,y:i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,l.G.translate(a,"x",s)),{size:this.drawTicks(o,(u,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y-W),t.stroke(),t.fillText(f.label,a.x+f.position-u.width/2,a.y-5-u.height)}).height+W}}drawLeft(n){const{lower2d:t}=this.ctx,{plot:r}=n,s=l.Eo.height(r),i=l.Eo.width(r),a=l.G.translate(n.position,"x",n.size),o=this.tickFactory.generate({...n,size:s});return this.maybeDrawGrid(s,o,u=>[l.G.translate(a,"y",u.position),l.G.translate(a,{x:i,y:u.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,l.G.translate(a,"y",s)),{size:this.drawTicks(o,(u,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x-W,a.y+f.position),t.stroke(),t.fillText(f.label,a.x-u.width-W*2,a.y+f.position+u.height/3)}).width+W*2}}drawRight(n){const{lower2d:t}=this.ctx,{plot:r}=n,s=l.Eo.height(r),i=l.Eo.width(r),a=n.position,o=this.tickFactory.generate({...n,size:s});return this.maybeDrawGrid(s,o,u=>[l.G.translate(a,"y",u.position),l.G.translate(a,{x:-i,y:u.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,l.G.translate(a,"y",s)),{size:this.drawTicks(o,(u,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x+W,a.y+f.position),t.stroke(),t.fillText(f.label,a.x+W+2,a.y+f.position+u.height/3)}).width+W*2}}drawLine(n,t){const{lower2d:r}=this.ctx;r.beginPath(),r.moveTo(...l.G.couple(n)),r.lineTo(...l.G.couple(t)),r.stroke()}drawTicks(n,t){let r=l._.ZERO;return n.forEach(s=>{const i=this.dimensions.get(s.label);r=l._.max([r,i]),t(i,s)}),r}maybeDrawGrid(n,t,r){const{showGrid:s,gridColor:i}=this.state;if(s){const a=l.H.construct(-1,1),o=l.H.construct(n-1,n+1);this.ctx.lower2d.strokeStyle=i.hex,t.filter(({position:c})=>!l.H.contains(a,c)&&!l.H.contains(o,c)).forEach(c=>this.drawLine(...r(c)))}}};const Le=Mr.extend({bounds:l.H.bounds.optional(),autoBounds:p.z.object({lower:p.z.boolean().optional().default(!0),upper:p.z.boolean().optional().default(!0)}).or(p.z.boolean().optional().default(!0)),autoBoundPadding:p.z.number().optional(),autoBoundUpdateInterval:d.w$1.z.optional().default(d.w$1.seconds(2)),size:p.z.number().optional().default(0),label:p.z.string().optional().default(""),labelSize:p.z.number().optional().default(0)}).partial({color:!0,font:!0,gridColor:!0}),Sc=2,Ec=7,Ri=(e,n)=>l.H.contains({lower:e-Ec,upper:e+Sc},n),Cc=l.H.DECIMAL,us=d.m.now(),Pc={lower:Number(us.valueOf()),upper:Number(us.add(d.w$1.HOUR).valueOf())},Mi=e=>e==="linear"?Cc:Pc,kc=(e,n=.1,t)=>{const r=l.H.max(e.filter(l.H.isFinite));if(!l.H.isFinite(r))return Mi(t);const{lower:s,upper:i}=r;if(i===s)return{lower:s-1,upper:i+1};const a=(i-s)*n;return{lower:s-a,upper:i+a}},Rc=.01,Mc=.1;class Yi extends d.Composite{async afterUpdate(){var t,r;this.internal.render=d.Context.use(this.ctx);const n=d.use(this.ctx);(t=this.state).autoBoundPadding??(t.autoBoundPadding=l.g.construct(this.state.location)==="x"?Mc:Rc),this.internal.core=new ki(this.internal.render,{color:n.colors.gray.l8,font:d.fontString(n,{level:"small"}),gridColor:n.colors.gray.l1,...this.state}),Z.requestRender(this.ctx,K),(r=this.internal).updateBounds??(r.updateBounds=d.r(s=>this.setState(i=>({...i,bounds:s})),this.state.autoBoundUpdateInterval.milliseconds))}async afterDelete(){Z.requestRender(this.ctx,K)}renderAxis(n,t){if(!n.canvases.includes("lower2d"))return;const{core:r}=this.internal,{grid:s,container:i}=n,a=to(`${this.type}-${this.key}`,s,i),o={...n,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:c}=r.render(o);Ri(this.state.size,c)||this.setState(u=>({...u,size:c}))}async bounds(n,t){var u,f;if(n&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:r,upper:s}=zi(this.state.autoBounds);if(!r&&!s&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=g=>({upper:s||this.state.bounds==null?g.upper:this.state.bounds.upper,lower:r||this.state.bounds==null?g.lower:this.state.bounds.lower});let a,o=null;try{const g=await t();a=kc(g,this.state.autoBoundPadding,this.state.type)}catch(g){a=Mi(this.state.type),o=g}const c=i(a);return this.internal.boundSnapshot=c,(this.state.bounds==null||r&&this.state.bounds.lower!==c.lower||s&&this.state.bounds.upper!==c.upper)&&((f=(u=this.internal).updateBounds)==null||f.call(u,c)),[c,o]}async dataToDecimalScale(n,t,r){const[s,i]=await this.bounds(n,t),a=l.g.swap(l.g.construct(this.state.location));return[l.b.Scale.scale(s).scale(1).translate(-l.Eo.root(r)[a]).magnify(1/l.Eo.dim(r,a)),i]}}const zi=e=>typeof e=="boolean"?{lower:e,upper:e}:{lower:(e==null?void 0:e.lower)??!0,upper:(e==null?void 0:e.upper)??!0},Yc=`precision lowp float;
|
|
7
|
-
uniform lowp vec4 u_color;
|
|
8
|
-
|
|
9
|
-
void main(void) {
|
|
10
|
-
gl_FragColor = u_color;
|
|
11
|
-
}
|
|
12
|
-
`,zc=`attribute float a_x;
|
|
13
|
-
attribute float a_y;
|
|
14
|
-
attribute lowp vec2 a_translate;
|
|
15
|
-
|
|
16
|
-
uniform lowp vec2 u_scale_aggregate;
|
|
17
|
-
uniform lowp vec2 u_offset_aggregate;
|
|
18
|
-
|
|
19
|
-
void main(void) {
|
|
20
|
-
vec2 transformed = u_scale_aggregate * vec2(a_x,a_y) + u_offset_aggregate;
|
|
21
|
-
transformed = transformed + a_translate;
|
|
22
|
-
gl_Position = vec4(transformed, 0.0, 1.0);
|
|
23
|
-
}
|
|
24
|
-
`,hs=d.g.FLOAT32.density.valueOf(),Di=p.z.object({x:Je,y:Je,label:p.z.string().optional(),color:l.Color.z,strokeWidth:p.z.number().default(1),downsample:p.z.number().min(1).max(50).optional().default(1)}),Dc=(e,n,t)=>e===-1||n===-1||e>=t.length?NaN:Number(t[e].at(n)),Oc=d.w$1.milliseconds(2);l.G.NAN,l.G.NAN,l.ZERO;const Et=class Et extends d.GLProgram{constructor(t){super(t,zc,Yc);h(this,"translationBufferCache",new Map);this.translationBufferCache=new Map}bindState({strokeWidth:t,color:r}){return this.uniformColor("u_color",r),this.attrStrokeWidth(t)}bindScale(t,r){const s=l.G.scale(t.scale,r.scale),i=l.G.translate(l.G.scale(r.scale,t.offset),r.offset);this.uniformXY("u_scale_aggregate",s),this.uniformXY("u_offset_aggregate",i)}draw({x:t,y:r,count:s,downsample:i,xOffset:a,yOffset:o},c){const{gl:u}=this.ctx;this.bindAttrBuffer("x",t.glBuffer,i,a),this.bindAttrBuffer("y",r.glBuffer,i,o),u.drawArraysInstanced(u.LINE_STRIP,0,s/i,c)}static create(t){const r=d.Context.use(t),s=new Et(r);return t.set(Et.CONTEXT_KEY,s),s}static use(t){return t.get(Et.CONTEXT_KEY)}bindAttrBuffer(t,r,s,i=0){const{gl:a}=this.ctx;a.bindBuffer(a.ARRAY_BUFFER,r);const o=a.getAttribLocation(this.prog,`a_${t}`);a.vertexAttribPointer(o,1,a.FLOAT,!1,hs*s,hs*i),a.enableVertexAttribArray(o)}getAndBindTranslationBuffer(t){const{gl:r}=this.ctx,s=`${this.ctx.aspect}:${t}`,i=this.translationBufferCache.get(s);if(i!=null)return r.bindBuffer(r.ARRAY_BUFFER,i.glBuffer),i;const a=r.createBuffer();if(a==null)throw new d.Re("Failed to create buffer from WebGL context");const o=Lc(this.ctx.aspect,t);r.bindBuffer(r.ARRAY_BUFFER,a),r.bufferData(r.ARRAY_BUFFER,o,r.DYNAMIC_DRAW);const c={glBuffer:a,jsBuffer:o};return this.translationBufferCache.set(s,c),c}attrStrokeWidth(t){const{gl:r}=this.ctx,{jsBuffer:s}=this.getAndBindTranslationBuffer(t),i=r.getAttribLocation(this.prog,"a_translate");return r.vertexAttribPointer(i,2,r.FLOAT,!1,0,0),r.enableVertexAttribArray(i),r.vertexAttribDivisor(i,1),s.length/2}};h(Et,"CONTEXT_KEY","pluto-line-gl-program");let hn=Et;class we extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Di)}async afterUpdate(){var r,s;if(this.deleted)return;const{internal:t}=this;t.xTelem=await H(this.ctx,this.state.x,t.xTelem),t.yTelem=await H(this.ctx,this.state.y,t.yTelem),t.instrumentation=De(this.ctx,"line"),t.prog=hn.use(this.ctx),t.requestRender=Z.useRequest(this.ctx),(r=t.stopListeningXTelem)==null||r.call(t),(s=t.stopListeningYTelem)==null||s.call(t),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender(Bn)),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender(Bn)),t.requestRender(K)}async afterDelete(){var r,s,i,a;const{internal:t}=this;await((s=(r=t.xTelem).cleanup)==null?void 0:s.call(r)),await((a=(i=t.yTelem).cleanup)==null?void 0:a.call(i)),t.requestRender(K)}async xBounds(){return(await this.internal.xTelem.value())[0]}async yBounds(){return(await this.internal.yTelem.value())[0]}async findByXValue(t,r){const{xTelem:s,yTelem:i}=this.internal,[,a]=await s.value();let[o,c]=[-1,-1];a.find((M,D)=>{const P=M.binarySearch(r),z=P>=0&&P<M.length;return z&&([o,c]=[P,D]),z});const{key:u}=this,{color:f,label:g}=this.state,m={key:u,color:f,label:g,position:{x:0,y:0},value:{x:NaN,y:NaN}};if(o===-1||c===-1)return m;const w=a[c];m.value.x=Dc(c,o,a);const[,b]=await i.value(),v=b.find(M=>l.H.contains(M.alignmentBounds,w.alignment+BigInt(o)));if(v==null)return m;const E=Number(v.alignment-w.alignment);return m.value.y=Number(v.at(o-E)),m.position={x:t.dataToDecimalScale.x.pos(m.value.x),y:t.dataToDecimalScale.y.pos(m.value.y)},m}async render(t){if(this.deleted)return;const{downsample:r}=this.state,{xTelem:s,yTelem:i,prog:a}=this.internal,{dataToDecimalScale:o,exposure:c}=t,[[,u],[,f]]=await Promise.all([s.value(),i.value()]);u.forEach(v=>v.updateGLBuffer(a.ctx.gl)),f.forEach(v=>v.updateGLBuffer(a.ctx.gl));const g=Gc(u,f,c,r,Oc);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:r,scale:o.transform,props:t.region,ops:Bc(g)}));const m=a.setAsActive(),w=a.bindState(this.state),b=a.ctx.scaleRegion(t.region).transform;g.forEach(v=>{const E=Uc(o,v).transform;a.bindScale(E,b),a.draw(v,w)}),m()}}h(we,"TYPE","line");const Ac=5e3,Lc=(e,n)=>Nc(Zc(e),n).map((t,r)=>Math.floor(r/$c)*(1/(Ac*e))*t),$c=5,Zc=e=>new Float32Array([0,0,0,e,0,-e,1,0,-1,0]),Nc=(e,n)=>{const t=new Float32Array(e.length*n);for(let r=0;r<n;r++)t.set(e,r*e.length);return t},Uc=(e,n)=>e.translate(e.x.dim(Number(n.x.sampleOffset)),e.y.dim(Number(n.y.sampleOffset))),Ic={[we.TYPE]:we},Gc=(e,n,t,r,s)=>{if(e.length===0||n.length===0)return[];const i=[];return e.forEach(a=>n.forEach(o=>{if(!Fc(a,o,s))return;let c=0,u=0;a.alignment<o.alignment?c=Number(o.alignment-a.alignment):o.alignment<a.alignment&&(u=Number(a.alignment-o.alignment));const f=Math.min(a.length-c,o.length-u);if(f===0)return;const g=l.Y(Math.round(t*4*f),r,51);i.push({x:a,y:o,xOffset:c,yOffset:u,count:f,downsample:g})})),i},Bc=e=>e.map(n=>({...n,x:n.x.digest,y:n.y.digest})),Fc=(e,n,t)=>{if(!(e._timeRange!=null&&n._timeRange!=null))throw new d.Re(`Encountered series without time range in buildDrawOperations. X series present: ${e._timeRange!=null}, Y series present: ${n._timeRange!=null}`);const s=e.timeRange.overlapsWith(n.timeRange,t),i=l.H.overlapsWith(e.alignmentBounds,n.alignmentBounds);return s&&i};class jt{constructor(n,t){h(this,"canvas");h(this,"theme");this.canvas=n,this.theme=t}rule({direction:n,region:t,position:r,...s}){return n==="x"?this.line({start:l.G.construct(l.Eo.left(t),r),end:l.G.construct(l.Eo.right(t),r),...s}):this.line({start:l.G.construct(r,l.Eo.top(t)),end:l.G.construct(r,l.Eo.bottom(t)),...s})}line({stroke:n,lineWidth:t,lineDash:r,start:s,end:i}){const a=this.canvas;a.strokeStyle=n.hex,a.lineWidth=t,a.setLineDash([r]),a.beginPath(),a.moveTo(...l.G.couple(s)),a.lineTo(...l.G.couple(i)),a.stroke()}circle({fill:n,radius:t,position:r}){const s=this.canvas;s.fillStyle=n.hex,s.beginPath(),s.arc(...l.G.couple(r),t,0,2*Math.PI),s.fill()}resolveColor(n,t){return n==null?this.resolveColor(t):typeof n=="function"?n(this.theme):new l.Color(n)}border({region:n,color:t,width:r,radius:s,location:i}){const a=this.canvas;a.strokeStyle=this.resolveColor(t,this.theme.colors.border).hex,a.lineWidth=r??this.theme.sizes.border.width,s??(s=this.theme.sizes.border.radius),i==null||i===!0?s>0?(a.roundRect(...l.G.couple(l.Eo.topLeft(n)),...l.G.couple(l.Eo.dims(n)),s),a.stroke()):(a.rect(...l.G.couple(l.Eo.topLeft(n)),...l.G.couple(l.Eo.dims(n))),a.stroke()):d.A(i).forEach(o=>{const[c,u]=l.Eo.edgePoints(n,o);a.beginPath(),a.moveTo(...l.G.couple(c)),a.lineTo(...l.G.couple(u)),a.stroke()})}container({region:n,bordered:t=!0,rounded:r=!0,borderColor:s,borderRadius:i,borderWidth:a,backgroundColor:o}){i??(i=this.theme.sizes.border.radius),a??(a=1);const c=this.canvas;c.fillStyle=this.resolveColor(o,this.theme.colors.gray.l1).hex,c.strokeStyle=this.resolveColor(s,this.theme.colors.border).hex,c.setLineDash([]),c.lineWidth=1,c.beginPath(),r?c.roundRect(...l.G.couple(l.Eo.topLeft(n)),...l.G.couple(l.Eo.dims(n)),i):c.rect(...l.G.couple(l.Eo.topLeft(n)),...l.G.couple(l.Eo.dims(n))),c.fill(),t&&this.border({region:n,color:s,radius:i,width:a,location:t})}textContainer(n){const[t,r]=this.spacedTextDrawF(n);t.width+=12,t.height+=12;const{root:s=l.K.TOP_LEFT,offset:i=l.G.ZERO}=n,a={...n.position};s.x==="right"?a.x-=t.width+i.x:a.x+=i.x,s.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:l.Eo.construct(a,t.width,t.height),...n}),this.canvas.filter="none",r(l.G.translate(a,[6,6]))}spacedTextDrawF({text:n,direction:t,spacing:r=1,level:s="p"}){const i=d.fontString(this.theme,{level:s}),a=n.map(u=>d.dimensions(u,i,this.canvas)),o=this.theme.sizes.base*r,c=Math.max(...a.map(u=>u[l.g.dimension(t)]))+o;return[{[l.g.dimension(l.g.swap(t))]:Math.max(...a.map(u=>u[l.g.dimension(l.g.swap(t))])),[l.g.dimension(t)]:c*n.length-o},u=>{const f=d.fontString(this.theme,{level:s});this.canvas.font=f,this.canvas.fillStyle=this.theme.colors.text.hex,this.canvas.textBaseline="top",n.forEach((g,m)=>{this.canvas.fillText(g,u.x,u.y+c*m)})}]}drawTextInCenter({box:n,text:t,level:r}){const s=d.dimensions(t,this.canvas.font,this.canvas),i=l.Eo.positionInCenter(l.Eo.construct(l.G.ZERO,s),n);return this.text({text:t,position:l.Eo.topLeft(i),level:r})}text({text:n,position:t,level:r="p",weight:s,shade:i,maxWidth:a,code:o}){this.canvas.font=d.fontString(this.theme,{level:r,weight:s,code:o}),i==null?this.canvas.fillStyle=this.theme.colors.text.hex:this.canvas.fillStyle=this.theme.colors.gray[`l${i}`].hex,this.canvas.textBaseline="top";let c;a!=null&&(c=this.canvas.scissor(l.Eo.construct(t,a,1e3))),this.canvas.fillText(n,t.x,t.y),c==null||c()}}const Yr=p.z.object({position:p.z.number().optional(),pixelPosition:p.z.number().optional(),dragging:p.z.boolean(),lineWidth:p.z.number().optional().default(1),lineDash:p.z.number().optional().default(20),color:l.Color.z}),_c=3;class Gt extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Yr);h(this,"lastUpdateRef",null)}async afterUpdate(){this.internal.renderCtx=d.Context.use(this.ctx);const t=d.use(this.ctx);this.internal.draw=new jt(this.internal.renderCtx.upper2d,t),Z.requestRender(this.ctx,et)}async afterDelete(){Z.requestRender(this.ctx,et)}updatePositions({decimalToDataScale:t,plot:r,container:s}){const i=this.state.dragging,a=this.prevState.dragging&&!i;if((i||a)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??(this.lastUpdateRef=this.state.pixelPosition),Math.abs(this.state.pixelPosition-this.lastUpdateRef)<_c&&!a)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const u=t.pos((this.state.pixelPosition-l.Eo.top(r)+l.Eo.top(s))/l.Eo.height(r));return this.setState(f=>({...f,position:u})),this.state.pixelPosition}if(this.state.position==null){const c=t.pos(.5);this.setState(u=>({...u,position:c}))}const o=t.reverse().pos(this.state.position)*l.Eo.height(r)+l.Eo.top(r)-l.Eo.top(s);if(!isNaN(o)){if(this.state.pixelPosition!=null&&Math.abs(o-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(c=>({...c,pixelPosition:o}))}return o}async render(t){if(this.deleted)return;const{renderCtx:r}=this.internal,{location:s,plot:i}=t,a=l.K.direction(s),{upper2d:o}=r,c=this.internal.draw;let u=this.updatePositions(t);u+=l.Eo.top(t.container),c.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:u}),o.fillStyle=this.state.color.hex,o.lineJoin="round",o.lineWidth=3.5,o.lineCap="round",o.beginPath();const f=4;if(s==="left"){const g=l.Eo.left(i)-1;o.moveTo(g,u),o.lineTo(g-f,u-f),o.lineTo(g-f,u+f)}else s==="right"&&(o.moveTo(l.Eo.right(i),u),o.lineTo(l.Eo.right(i)+f,u-f),o.lineTo(l.Eo.right(i)+f,u+f));o.closePath(),o.stroke()}}h(Gt,"TYPE","Rule");const Oi={[Gt.TYPE]:Gt},Hc=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Oi,Rule:Gt,ruleStateZ:Yr},Symbol.toStringTag,{value:"Module"})),qc=Le.extend({location:l.K.x.optional().default("left")}),ds=2,jc=e=>l.Eo.signedWidth(e)<ds||l.Eo.signedHeight(e)<ds;class be extends Yi{constructor(){super(...arguments);h(this,"schema",Le)}async xBounds(){return l.H.max((await Promise.all(this.lines.map(async t=>await t.xBounds()))).filter(t=>l.H.isFinite(t)))}async render(t){if(this.deleted)return;const[r,s]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport),i=r.invert().reverse();if(this.renderAxis(t,i),await this.renderLines(t,r),await this.renderRules(t,i),s!=null)throw s}async renderLines({xDataToDecimalScale:t,plot:r,canvases:s,exposure:i},a){if(!s.includes("gl")||jc(r))return;const o={region:r,dataToDecimalScale:new l.b.XY(t,a),exposure:i};await Promise.all(this.lines.map(async c=>await c.render(o)))}async renderRules({container:t,plot:r,canvases:s},i){if(!s.includes("upper2d"))return;const{location:a}=this.state,{render:o}=this.internal,c=l.Eo.construct(l.Eo.left(t),l.Eo.top(r),l.Eo.width(t),l.Eo.height(r)),u=o.scissor(c,l.G.ZERO,["upper2d"]),f={container:t,plot:r,decimalToDataScale:i,location:a};await Promise.all(this.rules.map(async g=>await g.render(f))),u()}async findByXValue({xDataToDecimalScale:t,plot:r,viewport:s,hold:i,exposure:a},o){const[c,u]=await this.dataToDecimalScale(i,this.dataBounds.bind(this),s);if(u!=null)throw u;const f=new l.b.XY(t,c),g={region:r,dataToDecimalScale:f,exposure:a};return(await Promise.all(this.lines.map(async m=>await m.findByXValue(g,o)))).map(m=>({...m,units:this.state.label}))}async dataBounds(){return await Promise.all(this.lines.map(async t=>await t.yBounds()))}get lines(){return this.childrenOfType(we.TYPE)}get rules(){return this.childrenOfType(Gt.TYPE)}}h(be,"TYPE","YAxis");const Ai=p.z.object({start:d.m.z,end:d.m.z});class dn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Ai)}async afterUpdate(){this.internal.render=d.Context.use(this.ctx),this.internal.draw=new jt(this.internal.render.upper2d,d.use(this.ctx))}async render(){}}h(dn,"TYPE","range-annotation");const Wc=p.z.object({region:l.Eo.box,clearOverScan:l.G.crudeZ.optional().default(0),visible:p.z.boolean().optional().default(!0)}),In=["upper2d","lower2d"],Ct=class Ct extends d.Composite{constructor(){super(...arguments);h(this,"schema",Ct.stateZ)}async afterUpdate(){const{internal:t}=this;t.renderCtx=d.Context.use(this.ctx),Z.control(this.ctx,()=>this.requestRender("low")),this.requestRender("high")}async afterDelete(){this.requestRender("high")}async render(){const t=l.Eo.copy(this.state.region);if(!this.state.visible)return async()=>this.internal.renderCtx.erase(this.state.region,this.state.clearOverScan,...In);const{renderCtx:r}=this.internal,s=l.b.XY.translate(l.Eo.topLeft(this.state.region)),i=r.scissor(this.state.region,l.G.construct(this.state.clearOverScan),In);try{for(const a of this.children)await a.render({viewportScale:s})}catch(a){console.error(a)}finally{i()}return async()=>{this.internal.renderCtx.erase(t,this.state.clearOverScan)}}requestRender(t){const{renderCtx:r}=this.internal;r.loop.set({key:`${Ct.TYPE}-${this.key}`,render:this.render.bind(this),priority:t,canvases:In})}};h(Ct,"TYPE","Table"),h(Ct,"stateZ",Wc);let ve=Ct;const Vc={[ve.TYPE]:ve},Li=p.z.object({triggered:p.z.boolean(),status:d.specZ$1,sink:Pn.optional().default(Sn),source:ir.optional().default(nr)});class fn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Li)}async afterUpdate(){var s,i,a;const{sink:t,source:r}=this.state;this.internal.source=await H(this.ctx,r,this.internal.source),this.internal.sink=await Ye(this.ctx,t,this.internal.sink),this.state.triggered&&!this.prevState.triggered&&this.internal.sink.set(((s=this.state.status.data)==null?void 0:s.authority)!==d.wp.Absolute.valueOf()).catch(console.error),await this.updateEnabledState(),(a=(i=this.internal).stopListening)==null||a.call(i),this.internal.stopListening=this.internal.source.onChange(()=>{this.updateEnabledState()})}async updateEnabledState(){const t=await this.internal.source.value();t.time.equals(this.state.status.time)||this.setState(r=>({...r,status:t,triggered:!1}))}async afterDelete(){this.asyncAfterDelete().catch(console.error)}async asyncAfterDelete(){var t,r,s,i;this.internal.stopListening(),await((r=(t=this.internal.source).cleanup)==null?void 0:r.call(t)),await((i=(s=this.internal.sink).cleanup)==null?void 0:i.call(s))}render(){}}h(fn,"TYPE","Chip");const $i=p.z.object({}),fs="control-state-provider",Zi=d.Fg.stateZ.extend({subjectColor:l.Color.z});class Bt extends d.Composite{constructor(){super(...arguments);h(this,"schema",$i);h(this,"colors",new Map);h(this,"tracker");h(this,"disconnectTrackerChange");h(this,"obs",new Qn.Observer)}static use(t){return t.get(fs)}async afterUpdate(){const{internal:t}=this;t.instrumentation=De(this.ctx,"control-state");const r=d.use(this.ctx);t.palette=r.colors.visualization.palettes.default,t.defaultColor=r.colors.gray.l6;const s=Me(this.ctx);t.client!=null&&s===t.client||(t.client=s,this.ctx.set(fs,this),await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client)))}async maybeCloseTracker(){var t;this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),(t=this.disconnectTrackerChange)==null||t.call(this),await this.tracker.close(),this.tracker=void 0)}async afterDelete(){await this.maybeCloseTracker()}onChange(t){return this.obs.onChange(t)}get(t){return Array.isArray(t)?d.n(t).map(r=>this.getOne(r)).filter(r=>r!=null):this.getOne(t)}getOne(t){if(this.tracker==null)return;const r=this.tracker.states.get(t);if(r!=null)return{...r,subjectColor:this.colors.get(r.subject.key)??this.internal.defaultColor}}async openTracker(t){var i;const{internal:r}=this,{instrumentation:s}=r;try{this.tracker=await t.control.openStateTracker()}catch{s.L.error("failed to open state tracker");return}(i=this.disconnectTrackerChange)==null||i.call(this),this.disconnectTrackerChange=this.tracker.onChange(a=>{if(s.L.debug("transfer",{transfers:a.map(o=>d.Fg.transferString(o))}),this.tracker==null)throw new d.Re("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(a)})}updateColors(t){const r=t.subjects(),s=r.map(o=>o.key),i=Array.from(this.colors.values());this.colors.forEach((o,c)=>!s.includes(c)&&this.colors.delete(c));const{palette:a}=this.internal;r.forEach(o=>{if(this.colors.has(o.key))return;const c=a.find(u=>!i.includes(u))??a[0];this.colors.set(o.key,c),i.push(c)})}}h(Bt,"TYPE","StateProvider");const Ni=["acquired","released","overridden","failed"],Ui=p.z.enum(Ni),Ii=p.z.object({name:p.z.string(),authority:p.z.number().default(0),acquireTrigger:p.z.number(),status:Ui.optional(),needsControlOf:d.Ug.keyZ.array().optional().default([])});class pn extends d.Composite{constructor(){super(...arguments);h(this,"schema",Ii);h(this,"registry",new Map);h(this,"writer")}async afterUpdate(){this.internal.instrumentation=De(this.ctx),(this.internal.prevTrigger==null||Math.abs(this.state.acquireTrigger-this.internal.prevTrigger)>1)&&(this.internal.prevTrigger=this.state.acquireTrigger);const t=Me(this.ctx),r=Bt.use(this.ctx);this.internal.client=t,this.internal.client==null&&await this.release(),this.internal.stateProv=r,xs(this.ctx,this),this.internal.addStatus=d.useAggregate(this.ctx),this.state.acquireTrigger>this.internal.prevTrigger?(this.acquire(),this.internal.prevTrigger=this.state.acquireTrigger):this.state.acquireTrigger<this.internal.prevTrigger&&(this.release(),this.internal.prevTrigger=this.state.acquireTrigger)}async afterDelete(){await this.release()}async updateNeedsControlOf(){const{client:t}=this.internal;if(t==null)return;const r=new Set([]);for(const i of this.registry.keys())(await i.needsControlOf(t)).forEach(o=>o!==0&&r.add(o));const s=Array.from(r);d.F.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==d.F.EQUAL&&this.setState(i=>({...i,needsControlOf:s}))}async acquire(){const{client:t,addStatus:r}=this.internal;if(t==null)return r({message:`Cannot acquire control on ${this.state.name} because no cluster has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const s=this.state.needsControlOf;if(s.length===0)return r({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});this.writer=await t.openWriter({start:d.k.now(),channels:s,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority,enableAutoCommit:!0}),this.setState(i=>({...i,status:"acquired"}))}catch(s){this.setState(i=>({...i,status:"failed"})),r({message:`${this.state.name} failed to acquire control: ${s.message}`,variant:"error"})}}async release(){var t;try{await((t=this.writer)==null?void 0:t.close()),this.setState(r=>({...r,status:"released"}))}catch(r){this.internal.addStatus({message:`${this.state.name} failed to release control: ${r.message}`,variant:"error"})}finally{this.writer=void 0}}async set(t){var r;this.writer==null&&await this.acquire(),await((r=this.writer)==null?void 0:r.write(t))}async setAuthority(t,r){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.setAuthority(Object.fromEntries(t.map(i=>[i,r]))))}async releaseAuthority(t){var r;this.writer==null&&await this.acquire(),await((r=this.writer)==null?void 0:r.setAuthority(Object.fromEntries(t.map(s=>[s,this.state.authority]))))}deleteTelem(t){this.registry.delete(t),this.updateNeedsControlOf()}create(t){const s=(()=>{switch(t.type){case Te.TYPE:{const i=new Te(this,t.props);return this.registry.set(i,null),i}case Ee.TYPE:{const i=new Ee(this,this.internal.stateProv,t.props);return this.registry.set(i,null),i}case Se.TYPE:return new Se(this,t.props);default:return null}})();return s!=null&&this.updateNeedsControlOf(),s}}h(pn,"TYPE","Controller");const Gi=p.z.object({channel:p.z.number()});class Te extends Rn{constructor(t,r){super(r);h(this,"controller");h(this,"schema",Gi);this.controller=t}invalidate(){}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){if(this.props.channel===0)return[];const r=await t.channels.retrieve(this.props.channel),s=[r.key];return r.index!==0&&s.push(r.index),s}async set(t){const{client:r}=this.controller.internal;if(r==null)return;const s=await r.channels.retrieve(this.props.channel),i={[s.key]:t};if(s.index!==0){const a=await r.channels.retrieve(s.index);i[a.key]=d.k.now()}await this.controller.set(i)}}h(Te,"TYPE","controlled-numeric-telem-sink");const Xc=e=>({type:Te.TYPE,props:e,variant:"sink",valueType:"number"}),Bi=p.z.object({authority:p.z.number().default(d.Fg.Authority.Absolute.valueOf()),channel:p.z.number()});class Se extends Rn{constructor(t,r){super(r);h(this,"controller");h(this,"schema",Bi);this.controller=t}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){const r=await t.channels.retrieve(this.props.channel),s=[r.key];return r.index!==0&&s.push(r.index),s}async set(t){const{controller:r}=this,{client:s}=r.internal;if(s==null)return;const i=await s.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),t?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)}}h(Se,"TYPE","acquire-channel-control");const Kc=e=>({type:Se.TYPE,props:e,variant:"sink",valueType:"boolean"}),Fi=p.z.object({channel:p.z.number()});class Ee extends F{constructor(t,r,s){super(s);h(this,"prov");h(this,"valid",!1);h(this,"stopListening");h(this,"controller");h(this,"schema",Fi);this.prov=r,this.controller=t}async needsControlOf(){return[]}maybeRevalidate(){var s;if(this.valid)return;const{channel:t}=this.props;(s=this.stopListening)==null||s.call(this);const r=d.Q.filterTransfersByChannelKey(t);this.stopListening=this.prov.onChange(i=>{var a;r(i).length!==0&&((a=this.notify)==null||a.call(this))}),this.valid=!0}async value(){this.maybeRevalidate();const t=d.k.now();if(this.props.channel===0)return{key:this.controller.key,variant:"disabled",message:"No Channel",time:t,data:{valid:!1,authority:0}};const r=this.prov.get(this.props.channel);return r==null?{key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:t,data:{valid:!0,color:void 0,authority:0}}:{key:r.subject.key,variant:r.subject.key===this.controller.key?"success":"error",message:`Controlled by ${r.subject.name}`,time:t,data:{valid:!0,color:r.subjectColor,authority:r.authority}}}async cleanup(){var t;this.controller.deleteTelem(this),(t=this.stopListening)==null||t.call(this)}}h(Ee,"TYPE","controlled-status-source");const Qc=e=>({type:Ee.TYPE,props:e,variant:"source",valueType:"status"}),_i=p.z.object({statusSource:ir.optional().default(nr),colorSource:sr.optional().default(En),status:d.specZ$1,color:l.Color.z.optional()});class gn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",_i);h(this,"stopListeningStatus");h(this,"stopListeningColor")}async afterUpdate(){var r,s;const{internal:t}=this;t.statusSource=await H(this.ctx,this.state.statusSource,t.statusSource),t.colorSource=await H(this.ctx,this.state.colorSource,t.colorSource),await this.updateState(),(r=this.stopListeningStatus)==null||r.call(this),this.stopListeningStatus=t.statusSource.onChange(()=>{this.updateState()}),(s=this.stopListeningColor)==null||s.call(this),this.stopListeningColor=t.colorSource.onChange(()=>{this.updateState()})}async afterDelete(){this.internalAfterDelete().catch(console.error)}async internalAfterDelete(){var t,r,s,i;await((r=(t=this.internal.statusSource).cleanup)==null?void 0:r.call(t)),await((i=(s=this.internal.colorSource).cleanup)==null?void 0:i.call(s))}async render(){}async updateState(){const t=await this.internal.colorSource.value(),r=await this.internal.statusSource.value();t.equals(this.state.color)&&r.message===this.state.status.message||this.setState(s=>({...s,color:t,status:r}))}}h(gn,"TYPE","Indicator");const Hi=p.z.object({needsControlOf:d.Ug.keyZ.array(),states:Zi.array()});class mn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Hi)}async afterUpdate(){var a;const{internal:t}=this;t.stateProv=Bt.use(this.ctx);const r=this.state.needsControlOf;(a=t.disconnectStateProv)==null||a.call(t);const s=d.Q.filterTransfersByChannelKey(...r),i=t.stateProv.get(r);this.setState(o=>({...o,states:i})),t.disconnectStateProv=t.stateProv.onChange(o=>{if(s(o).length===0)return;const c=t.stateProv.get(r);this.setState(u=>({...u,states:c}))})}async afterDelete(){var r;const{internal:t}=this;(r=t.disconnectStateProv)==null||r.call(t)}async render(){}}h(mn,"TYPE","Legend");const Jc={[pn.TYPE]:pn,[Bt.TYPE]:Bt,[gn.TYPE]:gn,[fn.TYPE]:fn,[mn.TYPE]:mn},qi=p.z.object({trigger:p.z.number(),sink:Pn.optional().default(Sn)});class yn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",qi)}async afterUpdate(){var s;const{sink:t}=this.state;(s=this.internal).prevTrigger??(s.prevTrigger=this.state.trigger),this.internal.sink=await Ye(this.ctx,t,this.internal.sink);const r=this.internal.prevTrigger;this.internal.prevTrigger=this.state.trigger,!(this.state.trigger<=r)&&this.internal.sink.set(!0).catch(console.error)}render(){}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var r,s;const{internal:t}=this;await((s=(r=t.sink).cleanup)==null?void 0:s.call(r))}}h(yn,"TYPE","Button");const tu={[yn.TYPE]:yn},zr=p.z.object({dpr:p.z.number(),region:l.Eo.box,bootstrap:p.z.boolean().optional().default(!1),bootstrapped:p.z.boolean().optional().default(!1),glCanvas:p.z.any().optional(),upper2dCanvas:p.z.any().optional(),lower2dCanvas:p.z.any().optional(),os:d.w.osZ});class Ce extends d.Composite{constructor(){super(...arguments);h(this,"schema",zr);h(this,"renderContextSet",!1)}async afterUpdate(){let t=d.Context.useOptional(this.ctx);if(t==null){if(this.renderContextSet)throw new d.Re("[vis.worker.Canvas] - expected render context to be set");if(!this.state.bootstrap)return;const{glCanvas:r,lower2dCanvas:s,upper2dCanvas:i,os:a}=this.state;if(r==null||s==null||i==null)throw new d.Re("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");t=d.Context.create(this.ctx,r,s,i,a),hn.create(this.ctx),this.setState(o=>({...o,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else t.update(this.ctx);t.resize(this.state.region,this.state.dpr)}}h(Ce,"TYPE","Canvas");const ji={[Ce.TYPE]:Ce},eu=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Ce,REGISTRY:ji,canvasStateZ:zr},Symbol.toStringTag,{value:"Module"})),Dr=p.z.object({position:l.G.xy,zoom:p.z.number(),region:l.Eo.box,clearOverScan:l.G.crudeZ.optional().default(10),visible:p.z.boolean().optional().default(!0)}),Ge=["upper2d","lower2d"],Pt=class Pt extends d.Composite{constructor(){super(...arguments);h(this,"schema",Pt.stateZ)}async afterUpdate(){this.internal.renderCtx=d.Context.use(this.ctx),this.internal.addStatus=d.useAggregate(this.ctx),Z.control(this.ctx,()=>this.requestRender("low")),this.requestRender("high")}async afterDelete(){this.requestRender("high")}async render(){if(this.deleted)return;const{renderCtx:t,addStatus:r}=this.internal,{zoom:s,position:i}=this.state,a=l.Eo.construct(this.state.region);if(!this.state.visible)return async()=>t.erase(a,this.state.clearOverScan,...Ge);const o=t.scissor(a,l.G.ZERO,Ge),c=l.b.XY.magnify(l.G.construct(s)).translate(l.Eo.topLeft(a)).translate(i);try{await Promise.all(this.children.map(async f=>await f.render({viewportScale:c})))}catch(f){r({variant:"error",message:f.message})}finally{o()}const u=l.Eo.copy(this.state.region);return async()=>{this.internal.renderCtx.erase(u,this.state.clearOverScan,...Ge)}}requestRender(t){const{renderCtx:r}=this.internal;r.loop.set({key:`${Pt.TYPE}-${this.key}`,render:this.render.bind(this),priority:t,canvases:Ge})}};h(Pt,"TYPE","Diagram"),h(Pt,"stateZ",Dr);let Ft=Pt;const Wi={[Ft.TYPE]:Ft},nu=Object.freeze(Object.defineProperty({__proto__:null,Diagram:Ft,REGISTRY:Wi,diagramStateZ:Dr},Symbol.toStringTag,{value:"Module"})),Vi=p.z.object({enabled:p.z.boolean(),source:rr.optional().default(er)});class xn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Vi)}async afterUpdate(){var s;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{source:t}=this.state,{internal:r}=this;this.internal.source=await H(this.ctx,t,this.internal.source),await this.updateEnabledState(),(s=r.stopListening)==null||s.call(r),r.stopListening=r.source.onChange(()=>this.updateEnabledState().catch(this.reportError.bind(this)))}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Light: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(r=>({...r,enabled:t}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,r;this.internal.stopListening(),await((r=(t=this.internal.source).cleanup)==null?void 0:r.call(t))}async render(){}}h(xn,"TYPE","Light");const ru={[xn.TYPE]:xn},Or=p.z.object({position:l.G.xy.or(p.z.null()),textColor:l.Color.z.optional().default(l.ZERO),backgroundColor:l.Color.z.optional().default(l.ZERO),borderColor:l.Color.z.optional().default(l.ZERO),ruleColor:l.Color.z.optional().default(l.ZERO),ruleStrokeWidth:p.z.number().optional().default(1),ruleStrokeDash:p.z.number().default(0)});class _t extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Or)}async afterUpdate(){const t=d.use(this.ctx);this.state.textColor.isZero&&(this.state.textColor=t.colors.text),this.state.backgroundColor.isZero&&(this.state.backgroundColor=t.colors.gray.l1),this.state.borderColor.isZero&&(this.state.borderColor=t.colors.border),this.state.ruleColor.isZero&&(this.state.ruleColor=t.colors.gray.l5),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=d.Context.use(this.ctx),this.internal.draw=new jt(this.internal.render.upper2d,t),Z.requestRender(this.ctx,et)}async afterDelete(){Z.requestRender(this.ctx,et)}async render(t){if(this.deleted||this.state.position==null)return;const{region:r}=t,s=l.b.XY.scale(l.Eo.DECIMAL).scale(r),i=l.b.XY.scale(r).scale(l.Eo.DECIMAL),a=await t.findByXDecimal(i.x.pos(this.state.position.x)),o=a.filter(b=>l.G.isFinite(b.value)),{draw:c}=this.internal,u=o.reduce((b,v)=>b+v.position.x,0)/o.length,f=new d.m(o.reduce((b,v)=>b+v.value.x,0)/o.length),g=s.x.pos(u);if(!l.H.contains(l.Eo.xBounds(r),g))return;c.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:r,position:g}),o.forEach(b=>{const v=s.pos(b.position);c.circle({fill:b.color.setAlpha(.5),radius:8,position:v}),c.circle({fill:b.color.setAlpha(.8),radius:5,position:v}),c.circle({fill:b.color.pickByContrast(this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:v})});const m=a.map(b=>`${b.label??""}: ${b.value.y.toFixed(2)}`);m.unshift(`Time: ${f.fString("preciseDate","local")}`);const w=i.pos(this.state.position);c.textContainer({text:m,backgroundColor:this.state.backgroundColor,borderColor:this.state.borderColor,position:this.state.position,direction:"y",level:"small",spacing:.5,offset:{x:12,y:12},root:{x:w.x>.8?"right":"left",y:w.y>.8?"top":"bottom"}})}}h(_t,"TYPE","tooltip");const Xi={[_t.TYPE]:_t},su=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Xi,Tooltip:_t,tooltipStateZ:Or},Symbol.toStringTag,{value:"Module"})),Ki=p.z.object({region:l.Eo.box,wheelPos:p.z.number(),scrolling:p.z.boolean(),empty:p.z.boolean(),visible:p.z.boolean(),telem:Je.optional().default(Ts),font:d.levelZ.optional().default("p"),color:l.Color.z.optional().default(l.ZERO),overshoot:l.G.xy.optional().default({x:0,y:0})}),iu=.98,Kt="lower2d",au={offset:0n,offsetRef:0n,scrollRef:0},ie=class ie extends d.Leaf{constructor(){super(...arguments);h(this,"schema",ie.z);h(this,"values",new d.Dt([]));h(this,"scrollState",au)}async afterUpdate(){var c;const{internal:t}=this;t.render=d.Context.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await H(this.ctx,this.state.telem,t.telem);const{scrolling:r,wheelPos:s}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(r){const{scrollState:u,values:f}=this,g=Math.ceil((s-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(g)),u.offset<f.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=f.alignmentBounds.lower,this.setState(m=>({...m,wheelPos:this.prevState.wheelPos}))),u.offset>=f.alignmentBounds.upper&&this.setState(m=>({...m,scrolling:!1}))}const[a,o]=await this.internal.telem.value();this.values=new d.Dt(o),this.checkEmpty(),(c=t.stopListeningTelem)==null||c.call(t),t.stopListeningTelem=t.telem.onChange(()=>this.internal.telem.value().then(([u,f])=>{this.checkEmpty(),this.values=new d.Dt(f),this.requestRender()})),this.requestRender()}checkEmpty(){const t=this.values.length===0;t!==this.state.empty&&this.setState(r=>({...r,empty:t}))}async afterDelete(){var s;const{telem:t,render:r}=this.internal;await((s=t.cleanup)==null?void 0:s.call(t)),r.erase(l.Eo.construct(this.state.region),l.G.ZERO,Kt)}requestRender(){const{render:t}=this.internal;t.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(),priority:"high",canvases:[Kt]})}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((l.Eo.height(this.state.region)-12)/this.lineHeight),this.values.length)}async render(){const{render:t}=this.internal,r=this.state.region;if(l.Eo.areaIsZero(r))return;if(!this.state.visible)return async()=>t.erase(r,l.G.ZERO,Kt);let s;if(!this.state.scrolling)s=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const f=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));s=this.values.subAlignmentSpanIterator(f,this.visibleLineCount)}const i=this.state.region,a=t[Kt],o=new jt(a,this.internal.theme),c=t.scissor(i,l.G.ZERO,[Kt]);this.renderElements(o,s),this.renderScrollbar(o),c();const u=l.Eo.copy(this.state.region);return async({canvases:f})=>t.erase(u,this.state.overshoot,...f)}renderScrollbar(t){const r=this.state.region,s=l.Eo.height(r)/this.totalHeight*l.Eo.height(r);if(s>=l.Eo.height(r)*iu)return;let i=l.Eo.bottom(r)-s;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*l.Eo.height(r)),i<0&&(i=l.Eo.top(r)),t.container({region:l.Eo.construct({x:l.Eo.right(r)-6,y:i},{width:6,height:s}),bordered:!1,backgroundColor:a=>a.colors.gray.l4})}renderElements(t,r){const s=this.state.region;let i=0;for(const a of r){const o=this.values.dataType.equals(d.g.JSON)?JSON.stringify(a):a.toString();t.text({text:o,level:this.state.font,shade:9,position:l.G.translate(l.Eo.topLeft(s),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}};h(ie,"TYPE","log"),h(ie,"z",Ki);let Pe=ie;const ou={[Pe.TYPE]:Pe},Ar=p.z.object({one:l.G.xy.nullable(),two:l.G.xy.nullable(),hover:l.G.xy.nullable(),color:p.z.union([l.Color.z,p.z.object({verticalLine:l.Color.z.optional().default(l.ZERO),horizontalLine:l.Color.z.optional().default(l.ZERO),obliqueLine:l.Color.z.optional().default(l.ZERO)})]).optional().default(l.ZERO),strokeWidth:p.z.number().optional().default(1),strokeDash:p.z.number().optional().default(2)});class Ht extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Ar)}async afterUpdate(){const t=d.Context.use(this.ctx);this.internal.theme=d.use(this.ctx),this.internal.render=t,this.internal.draw=new jt(t.upper2d,this.internal.theme),Z.requestRender(this.ctx,et)}async afterDelete(){Z.requestRender(this.ctx,K)}get verticalLineColor(){return this.state.color instanceof l.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.verticalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.verticalLine}get horizontalLineColor(){return this.state.color instanceof l.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.horizontalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.horizontalLine}get obliqueLineColor(){return this.state.color instanceof l.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.obliqueLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.obliqueLine}async find(t){const{one:r,two:s}=this.state;if(r==null||s==null)return null;const{one:i,two:a}=this.prevState,{dataOne:o,dataTwo:c}=this.internal;if(i!=null&&l.G.equals(r,i)&&a!=null&&l.G.equals(s,a)&&o!=null&&c!=null){const[E,M]=[await t.findByXValue(o.x),await t.findByXValue(c.x)];return E.length===0||M.length===0?null:[E.sort((D,P)=>l.G.distance(o,D.value)-l.G.distance(o,P.value))[0],M.sort((D,P)=>l.G.distance(c,D.value)-l.G.distance(c,P.value))[0]]}const u=l.b.XY.scale(t.region).scale(l.Eo.DECIMAL),[f,g]=[u.pos(r),u.pos(s)],[m,w]=[await t.findByXDecimal(f.x),await t.findByXDecimal(g.x)];if(m.length===0||w.length===0)return null;const[b,v]=[m.sort((E,M)=>l.G.distance(f,E.position)-l.G.distance(f,M.position))[0],w.sort((E,M)=>l.G.distance(g,E.position)-l.G.distance(g,M.position))[0]];return this.internal.dataOne=b.value,this.internal.dataTwo=v.value,[b,v]}async renderHover(t){if(this.state.hover==null)return;const r=this.state.hover,s=l.b.XY.scale(t.region).scale(l.Eo.DECIMAL),i=s.pos(r),a=await t.findByXDecimal(s.pos(r).x);if(a.length===0)return;const o=a.sort((u,f)=>l.G.distance(i,u.position)-l.G.distance(i,f.position))[0],{draw:c}=this.internal;c.circle({fill:o.color.setAlpha(.5),radius:9,position:s.reverse().pos(o.position)})}async render(t){if(this.deleted)return;await this.renderHover(t);const r=await this.find(t);if(r==null)return;const[s,i]=r,{draw:a}=this.internal,{strokeDash:o,strokeWidth:c}=this.state,u=l.b.XY.scale(l.Eo.DECIMAL).scale(t.region),f=u.pos(s.position),g=u.pos(i.position),m=new d.w$1(Math.abs(s.value.x-i.value.x)),w=Math.abs(s.value.y-i.value.y),b=w/m.seconds;a.line({start:l.G.construct(f.x,f.y),end:l.G.construct(f.x,g.y),stroke:this.verticalLineColor,lineDash:o,lineWidth:c}),a.textContainer({text:[`${w.toFixed(2)} ${s.units??""}`],direction:"x",position:l.G.construct(f.x,(f.y+g.y)/2),level:"small"}),a.line({start:l.G.construct(f.x,g.y),end:l.G.construct(g.x,g.y),stroke:this.horizontalLineColor,lineDash:o,lineWidth:c}),a.textContainer({text:[m.truncate(d.w$1.MILLISECOND).toString()],direction:"x",position:l.G.construct((f.x+g.x)/2,g.y),level:"small"}),a.line({start:l.G.construct(f.x,f.y),end:l.G.construct(g.x,g.y),stroke:this.obliqueLineColor,lineDash:o,lineWidth:c}),a.textContainer({text:[`${b.toFixed(2)} ${s.units??""} / S`],direction:"x",position:l.G.construct((f.x+g.x)/2,(f.y+g.y)/2),level:"small"}),a.circle({fill:s.color.setAlpha(.5),radius:8,position:f}),a.circle({fill:s.color.setAlpha(.8),radius:5,position:f}),a.circle({fill:new l.Color("#ffffff"),radius:2,position:f}),a.circle({fill:i.color.setAlpha(.5),radius:8,position:g}),a.circle({fill:i.color.setAlpha(.8),radius:5,position:g}),a.circle({fill:new l.Color("#ffffff"),radius:2,position:g})}}h(Ht,"TYPE","measure");const Qi={[Ht.TYPE]:Ht},lu=Object.freeze(Object.defineProperty({__proto__:null,Measure:Ht,REGISTRY:Qi,measureStateZ:Ar},Symbol.toStringTag,{value:"Module"})),Ji=p.z.object({trigger:p.z.number(),command:p.z.number().optional(),value:p.z.number(),sink:ks.optional().default(ws),source:Ps.optional().default(bs)});class wn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",Ji)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:r,trigger:s,command:i}=this.state,{trigger:a}=this.prevState,{internal:o}=this;this.internal.source=await H(this.ctx,r,this.internal.source),o.sink=await Ye(this.ctx,t,o.sink),s!==a&&i!=null&&this.internal.sink.set(i),await this.updateValue(),(c=o.stopListening)==null||c.call(o),o.stopListening=o.source.onChange(()=>{this.updateValue().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Setpoint: ${t.message}`})}async updateValue(){const t=await this.internal.source.value();t!==this.state.value&&this.setState(r=>({...r,value:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,r,s,i;this.internal.stopListening(),await((r=(t=this.internal.source).cleanup)==null?void 0:r.call(t)),await((i=(s=this.internal.sink).cleanup)==null?void 0:i.call(s))}async render(){}}h(wn,"TYPE","Setpoint");const cu={[wn.TYPE]:wn},ta=p.z.object({triggered:p.z.boolean(),enabled:p.z.boolean(),sink:Pn.optional().default(Sn),source:rr.optional().default(er)});class bn extends d.Leaf{constructor(){super(...arguments);h(this,"schema",ta)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:r,triggered:s,enabled:i}=this.state,{triggered:a}=this.prevState,{internal:o}=this;this.internal.source=await H(this.ctx,r,this.internal.source),o.sink=await Ye(this.ctx,t,o.sink),s&&!a&&await o.sink.set(!i),await this.updateEnabledState(),(c=o.stopListening)==null||c.call(o),o.stopListening=o.source.onChange(()=>{this.updateEnabledState().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Toggle: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(r=>({...r,enabled:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,r,s,i;this.internal.stopListening(),await((r=(t=this.internal.source).cleanup)==null?void 0:r.call(t)),await((i=(s=this.internal.sink).cleanup)==null?void 0:i.call(s))}async render(){}}h(bn,"TYPE","Toggle");const uu={[bn.TYPE]:bn},hu=p.z.object({box:l.Eo.box,telem:ar.optional().default(vs),backgroundTelem:sr.optional().default(En),level:d.levelZ.optional().default("p"),color:l.Color.z.optional().default(l.ZERO),precision:p.z.number().optional().default(2),minWidth:p.z.number().optional().default(60),width:p.z.number().optional(),notation:Bs.optional().default("standard"),location:l.K.xy.optional().default({x:"left",y:"center"})}),du=["upper2d","lower2d"],ae=class ae extends d.Leaf{constructor(){super(...arguments);h(this,"schema",ae.z)}async afterUpdate(){var r,s;const{internal:t}=this;t.render=d.Context.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await H(this.ctx,this.state.telem,t.telem),(r=t.stopListening)==null||r.call(t),t.stopListening=this.internal.telem.onChange(()=>this.requestRender()),t.backgroundTelem=await H(this.ctx,this.state.backgroundTelem,t.backgroundTelem),(s=t.stopListeningBackground)==null||s.call(t),t.stopListeningBackground=this.internal.backgroundTelem.onChange(()=>this.requestRender()),this.internal.requestRender=Z.useOptionalRequest(this.ctx),this.requestRender()}async afterDelete(){var i;const{requestRender:t,telem:r,render:s}=this.internal;await((i=r.cleanup)==null?void 0:i.call(r)),t==null?s.erase(l.Eo.construct(this.state.box),l.G.ZERO,...du):t(K)}requestRender(){const{requestRender:t}=this.internal;t!=null?t(K):this.render({})}get fontHeight(){const{theme:t}=this.internal;return t.typography[this.state.level].size*t.sizes.base}maybeUpdateWidth(t){const{theme:r}=this.internal,s=t+r.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(i=>({...i,width:Math.max(s,i.minWidth)})):this.state.width-this.fontHeight>s&&this.setState(i=>({...i,width:Math.max(s,i.minWidth)}))}async render({viewportScale:t=l.b.XY.IDENTITY}){const{render:r,telem:s,backgroundTelem:i}=this.internal,a=l.Eo.construct(this.state.box);if(l.Eo.areaIsZero(a))return;const{location:o}=this.state,c=r.lower2d.applyScale(t);let u=await s.value();const f=d.fontString(this.internal.theme,{level:this.state.level,code:!0});c.font=f;const g=this.fontHeight,m=u[0]=="-";m&&(u=u.slice(1));const{theme:w}=this.internal,b=d.dimensions(u,f,c).width+w.sizes.base;this.internal.requestRender==null&&r.erase(l.Eo.construct(this.prevState.box)),this.maybeUpdateWidth(b);const v={...l.G.ZERO};o.x==="left"&&(v.x=6+g*.75),o.x==="center"&&(v.x=l.Eo.width(a)/2-b/2),o.y==="center"&&(v.y=l.Eo.height(a)/2);const E=l.G.translate(l.Eo.topLeft(a),v),M=c.scissor(a,void 0);let D=!0;if(this.state.backgroundTelem.type!=En.type){const P=r.lower2d.applyScale(t),z=await i.value();D=z.isZero,z.isZero||(P.fillStyle=z.hex,P.rect(...l.G.couple(l.Eo.topLeft(a)),l.Eo.width(a),l.Eo.height(a)),P.fill(),c.fillStyle=z.pickByContrast(w.colors.gray.l0,w.colors.gray.l9).hex)}D&&(c.fillStyle=this.internal.textColor.hex),c.textBaseline="middle",m&&c.fillText("-",...l.G.couple(l.G.translateX(E,-g*.6))),c.fillText(u,...l.G.couple(E)),M()}};h(ae,"TYPE","value"),h(ae,"z",hu);let qt=ae;const ea={[qt.TYPE]:qt},fu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ea,Value:qt},Symbol.toStringTag,{value:"Module"})),pu=d.cp.payloadZ.extend({viewport:l.H.bounds}),ps=e=>l.Color.z.safeParse(e).success,na=p.z.object({cursor:l.G.xy.or(p.z.null()),hovered:pu.or(p.z.null()),count:p.z.number()});class ke extends d.Leaf{constructor(){super(...arguments);h(this,"schema",na);h(this,"fetchedInitial",d.E.ZERO)}async afterUpdate(){const{internal:t}=this;t.render=d.Context.use(this.ctx),t.draw=new jt(t.render.upper2d,d.use(this.ctx)),t.ranges??(t.ranges=new Map);const r=Me(this.ctx);r!=null&&(t.client=r,t.tracker==null&&(t.tracker=await t.client.ranges.openTracker(),t.tracker.onChange(async s=>{s.forEach(async i=>{i.variant==="delete"?t.ranges.delete(i.key):ps(i.value.color)&&t.ranges.set(i.key,i.value)}),Z.requestRender(this.ctx,et),this.setState(i=>({...i,count:t.ranges.size}))}),Z.requestRender(this.ctx,et)))}async fetchInitial(t){const{internal:r}=this;if(r.client==null||this.fetchedInitial.roughlyEquals(t,d.w$1.minutes(1)))return;this.fetchedInitial=t,(await r.client.ranges.retrieve(t)).forEach(i=>{ps(i.color)&&r.ranges.set(i.key,i)}),this.setState(i=>({...i,count:r.ranges.size}))}async render(t){const{dataToDecimalScale:r,region:s,viewport:i,timeRange:a}=t;await this.fetchInitial(a);const{draw:o,ranges:c}=this.internal,u=r.scale(l.Eo.xBounds(s)),f=this.state.cursor==null?null:this.state.cursor.x;let g=null;const m=o.canvas.scissor(l.Eo.construct({x:l.Eo.left(s),y:l.Eo.top(s)-35},{x:l.Eo.right(s),y:l.Eo.bottom(s)}));c.forEach(w=>{const b=l.Color.z.safeParse(w.color);if(!b.success)return;const v=b.data;let E=u.pos(Number(w.timeRange.start.valueOf()));const M=u.pos(Number(w.timeRange.end.valueOf()));if(M<l.Eo.left(s)||E>l.Eo.right(s))return;E=l.Y(E,l.Eo.left(s)-2,l.Eo.right(s)-1);let D=!1;f!=null&&(D=l.H.contains({lower:E,upper:M},f)),D&&(g={key:w.key,name:w.name,color:w.color,timeRange:w.timeRange,viewport:{lower:r.scale(l.Eo.xBounds(i)).pos(Number(w.timeRange.start.valueOf())),upper:r.scale(l.Eo.xBounds(i)).pos(Number(w.timeRange.end.valueOf()))}}),o.container({region:l.Eo.construct({x:E,y:l.Eo.top(s)-1},{x:M,y:l.Eo.bottom(s)-1}),backgroundColor:v.setAlpha(.2),bordered:!1});const P=l.Eo.construct({x:E+1,y:l.Eo.top(s)-34},{x:M-1,y:l.Eo.top(s)-12});o.container({region:P,backgroundColor:l.Eo.width(P)<20?v.setAlpha(.4):z=>D?z.colors.gray.l2:z.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:v.setAlpha(.8)}),o.text({text:w.name,position:{x:E+8,y:l.Eo.top(s)-30},level:"small",shade:8,weight:500,maxWidth:M-E-16})}),m(),g!=null?this.setState(w=>({...w,hovered:g})):this.state.hovered&&this.setState(w=>({...w,hovered:null}))}}h(ke,"TYPE","range-provider");const gu={[dn.TYPE]:dn,[ke.TYPE]:ke},mu=Le;class Re extends Yi{constructor(){super(...arguments);h(this,"schema",Le)}async render(t){if(this.deleted)return;const[r,s]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(this.renderAxis(t,r.reverse()),await this.renderYAxes(t,r),await this.renderRangeAnnotations(t,r),s!=null)throw s}async findByXDecimal(t,r){const[s,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;return await this.findByXValue(t,s.reverse().pos(r))}async findByXValue(t,r){const[s,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;const a={...t,xDataToDecimalScale:s},o=this.yAxes.map(async c=>await c.findByXValue(a,r));return(await Promise.all(o)).flat()}async renderYAxes(t,r){const s={...t,xDataToDecimalScale:r};await Promise.all(this.yAxes.map(async i=>await i.render(s)))}get yAxes(){return this.childrenOfType(be.TYPE)}get rangeAnnotations(){return this.childrenOfType(ke.TYPE)}async renderRangeAnnotations(t,r){const[s,i]=await this.bounds(t.hold,this.dataBounds.bind(this));if(i!=null)throw i;await Promise.all(this.rangeAnnotations.map(async a=>await a.render({dataToDecimalScale:r,region:t.plot,viewport:t.viewport,timeRange:new d.E(s.lower,s.upper)})))}async dataBounds(){return await Promise.all(this.yAxes.map(async t=>await t.xBounds()))}}h(Re,"TYPE","XAxis");const ra=p.z.object({container:l.Eo.box,viewport:l.Eo.box,hold:p.z.boolean().optional().default(!1),grid:p.z.record(oi),visible:p.z.boolean().optional().default(!0),clearOverScan:l.G.crudeZ.optional().default(l.G.ZERO)}),yu=(e,n)=>{const t=l.Eo.width(e)*Math.sqrt(l.Eo.height(e)),r=l.Eo.width(n)*Math.sqrt(l.Eo.height(n));return t/r};class vn extends d.Composite{constructor(){super(...arguments);h(this,"schema",ra)}async afterUpdate(){this.internal.instrumentation=De(this.ctx,"lineplot"),this.internal.aggregate=d.useAggregate(this.ctx),this.internal.renderCtx=d.Context.use(this.ctx),Z.control(this.ctx,t=>this.requestRender("low",t)),this.requestRender("high",K)}async afterDelete(){this.internal.renderCtx=d.Context.use(this.ctx),this.requestRender("high",K)}async findByXDecimal(t){const r={...this.state,plot:this.calculatePlot(),exposure:this.exposure},s=this.axes.flatMap(async i=>await i.findByXDecimal(r,t));return(await Promise.all(s)).flat()}async findByXValue(t){const r={...this.state,plot:this.calculatePlot(),exposure:this.exposure},s=this.axes.flatMap(async i=>await i.findByXValue(r,t));return(await Promise.all(s)).flat()}get axes(){return this.childrenOfType(Re.TYPE)}get tooltips(){return this.childrenOfType(_t.TYPE)}get measures(){return this.childrenOfType(Ht.TYPE)}get exposure(){return yu(this.state.viewport,this.state.container)}async renderAxes(t,r){const s={...this.state,plot:t,canvases:r,exposure:this.exposure};await Promise.all(this.axes.map(async i=>await i.render(s)))}async renderTooltips(t,r){const s={findByXDecimal:this.findByXDecimal.bind(this),region:t,canvases:r};await Promise.all(this.tooltips.map(async i=>await i.render(s)))}async renderMeasures(t,r){const s={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:t,canvases:r};await Promise.all(this.measures.map(async i=>await i.render(s)))}calculatePlot(){return eo(this.state.grid,this.state.container)}async render(t){const{renderCtx:r}=this.internal,{instrumentation:s}=this.internal;if(this.deleted){s.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return s.L.debug("not visible, skipping render",{key:this.key}),async({canvases:f})=>r.erase(this.state.container,this.state.clearOverScan,...f);const i=this.calculatePlot();s.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:t});const a=l.G.construct(this.state.clearOverScan),o=r.scissor(this.state.container,a,t.filter(f=>f!=="gl")),c=r.scissor(i,l.G.ZERO,t.filter(f=>f==="gl"));try{await this.renderAxes(i,t),await this.renderTooltips(i,t),await this.renderMeasures(i,t),r.gl.finish(),r.gl.flush(),r.gl.finish()}catch(f){if(f.message.toLowerCase().includes("bigint"))return;this.internal.aggregate({key:`${this.type}-${this.key}`,variant:"error",message:f.message})}finally{o(),c()}s.L.debug("rendered",{key:this.key});const u=l.Eo.copy(this.state.container);return async({canvases:f})=>r.erase(u,this.state.clearOverScan,...f)}requestRender(t,r){const{renderCtx:s}=this.internal;let i=["upper2d","lower2d","gl"];r===et&&(i=["upper2d"]),s.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(i),priority:t,canvases:i})}}h(vn,"TYPE","LinePlot");const xu={[vn.TYPE]:vn,[Re.TYPE]:Re,[be.TYPE]:be};exports.AcquireChannelControl=Se;exports.Annotation=dn;exports.AuthoritySource=Ee;exports.BaseProvider=$t;exports.Button=yn;exports.Canvas=ki;exports.Canvas$1=Ce;exports.Chip=fn;exports.Controller=Z;exports.Controller$1=pn;exports.Diagram=nu;exports.Diagram$1=Ft;exports.Indicator=gn;exports.Legend=mn;exports.Light=xn;exports.Line=we;exports.LinePlot=vn;exports.Log=Pe;exports.Measure=Ht;exports.Provider=_e;exports.Provider$1=ke;exports.Provider$2=_n;exports.REASON_DATA=Bn;exports.REASON_LAYOUT=K;exports.REASON_TOOL=et;exports.REGISTRY=Na;exports.REGISTRY$1=tu;exports.REGISTRY$10=Oi;exports.REGISTRY$11=cu;exports.REGISTRY$12=gs;exports.REGISTRY$13=ai;exports.REGISTRY$14=uu;exports.REGISTRY$15=Xi;exports.REGISTRY$16=ea;exports.REGISTRY$17=ou;exports.REGISTRY$18=Vc;exports.REGISTRY$2=ji;exports.REGISTRY$3=Jc;exports.REGISTRY$4=Wi;exports.REGISTRY$5=ru;exports.REGISTRY$6=Ic;exports.REGISTRY$7=xu;exports.REGISTRY$8=Qi;exports.REGISTRY$9=gu;exports.Rule=Gt;exports.STATUSES=Ni;exports.SetChannelValue=Te;exports.Setpoint=wn;exports.StateProvider=Bt;exports.Table=ve;exports.Toggle=bn;exports.Tooltip=_t;exports.Value=qt;exports.XAxis=Re;exports.YAxis=be;exports.ZERO_CONTEXT_VALUE=Jn;exports.acquireChannelControl=Kc;exports.acquireChannelControlPropsZ=Bi;exports.aether=Hc;exports.annotationStateZ=Ai;exports.authoritySource=Qc;exports.authoritySourceProps=Fi;exports.axisStateZ=Mr;exports.buttonStateZ=qi;exports.canvas=eu;exports.canvasStateZ=zr;exports.channelData=As;exports.chipStateZ=Li;exports.color=Zt;exports.colorGradient=Ks;exports.controllerStateZ=Ii;exports.coreAxisStateZ=Le;exports.diagramStateZ=Dr;exports.external=Ja;exports.indicatorStateZ=_i;exports.interpolateNumber=xe;exports.interpolateRgb=Wn;exports.interpolateString=di;exports.legendStateZ=Hi;exports.lightStateZ=Vi;exports.linePlotStateZ=ra;exports.logState=Ki;exports.measure=lu;exports.measureStateZ=Ar;exports.newTickFactory=Kn;exports.parseAutoBounds=zi;exports.provider=ba;exports.providerStateZ=na;exports.providerStateZ$1=ni;exports.providerStateZ$2=mr;exports.regions=ut;exports.rollingAverage=Vs;exports.rollingAverageProps=gr;exports.ruleStateZ=Yr;exports.scaleNumber=Js;exports.setChannelValue=Xc;exports.setChannelValuePropsZ=Gi;exports.setpoint=_s;exports.setpointStateZ=Ji;exports.sinkPipeline=Ds;exports.sinkPipelinePropsZ=cr;exports.sourcePipeline=zs;exports.sourcePipelinePropsZ=lr;exports.stateProviderStateZ=$i;exports.stateZ=Di;exports.statusZ=Ui;exports.streamChannelData=Ls;exports.streamChannelValue=$s;exports.streamChannelValuePropsZ=ur;exports.stringSourceSpecZ=ar;exports.stringifyNumber=Ws;exports.stringifyNumberProps=pr;exports.sugaredStateZ=Zi;exports.tickFactoryProps=Rr;exports.tickType=kr;exports.toggleStateZ=ta;exports.tooltip=su;exports.tooltipStateZ=Or;exports.value=fu;exports.withinBounds=Hs;exports.withinBoundsProps=fr;exports.withinSizeThreshold=Ri;exports.xAxisStateZ=mu;exports.yAxisStateZ=qc;
|