@synnaxlabs/pluto 0.34.0 → 0.34.1
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/{LinePlot--yLT9nkT.cjs → LinePlot-44K5K51b.cjs} +8 -8
- package/dist/{LinePlot-6KHKqa-2.js → LinePlot-DN8KOMtR.js} +738 -738
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +2 -2
- package/dist/{external-DcMAC_pY.js → external-B_-ZrYaG.js} +101 -94
- package/dist/external-DVlGiTKE.cjs +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.js +5833 -5065
- package/dist/src/tree/core.d.ts +3 -1
- package/dist/src/tree/core.d.ts.map +1 -1
- package/dist/src/vis/lineplot/aether/YAxis.d.ts.map +1 -1
- package/dist/src/vis/schematic/Forms.d.ts +1 -0
- package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
- package/dist/src/vis/schematic/Symbols.d.ts +45 -0
- package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
- package/dist/src/vis/schematic/primitives/Primitives.d.ts +35 -0
- 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/style.css +1 -1
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +1 -1
- package/package.json +4 -4
- package/dist/external-CsrLjLOh.cjs +0 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var fa=Object.defineProperty;var pa=(n,e,t)=>e in n?fa(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>pa(n,typeof e!="symbol"?e+"":e,t);const d=require("./aggregator-C0Ab25_o.cjs"),p=require("zod"),o=require("./css-Dh7n0EGs.cjs");var ga=Object.defineProperty,ma=(n,e,t)=>e in n?ga(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,qe=(n,e,t)=>ma(n,typeof e!="symbol"?e+"":e,t);class ya{constructor(e,t){qe(this,"handlers"),qe(this,"transform"),qe(this,"closer"),this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[s,r]=this.transform(e);if(!r)return;t=s}this.handlers.forEach((s,r)=>r(t))}setCloser(e){this.closer=e}async close(){var e;return await((e=this.closer)==null?void 0:e.call(this))}}class wa{constructor(e){qe(this,"handlers"),this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,s)=>s(e))}}const Xn=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:wa,Observer:ya},Symbol.toStringTag,{value:"Module"})),xa=p.z.object({props:d.Zf.nullable(),state:d.Lf.connectivity.connectionStateZ.nullable()}),Vn={synnax:null,state:d.Lf.connectivity.DEFAULT};var ot;let Ne=(ot=class extends d.Composite{constructor(){super(...arguments);u(this,"schema",ot.stateZ)}async afterUpdate(){var t;if(this.ctx.has(Kn)||Pn(this.ctx,Vn),this.state.props==null){this.internal.synnax!=null&&(this.setState(s=>({...s,state:d.Lf.connectivity.DEFAULT})),(t=this.internal.synnax)==null||t.close(),this.internal.synnax=null),Pn(this.ctx,this.internal);return}this.prevState.props!=null&&d._.equal(this.state.props,this.prevState.props)&&this.internal.synnax!=null||(this.internal.synnax=new d.Lf(this.state.props),this.internal.synnax.connectivity.onChange(s=>this.setState(r=>({...r,state:s}))),Pn(this.ctx,this.internal))}},u(ot,"TYPE","SynnaxProvider"),u(ot,"stateZ",xa),ot);const Kn="pluto-client-context",Pn=(n,e)=>n.set(Kn,e),Se=n=>n.get(Kn).synnax,fr={[Ne.TYPE]:Ne},ba=Object.freeze(Object.defineProperty({__proto__:null,Provider:Ne,REGISTRY:fr,ZERO_CONTEXT_VALUE:Vn,use:Se},Symbol.toStringTag,{value:"Module"})),pr="pluto-telem-context",bn=n=>n.get(pr),gr=(n,e)=>n.set(pr,e),mr=(n,e)=>bn(n).registerFactory(e);class zs{constructor(e,t,s){u(this,"spec");u(this,"wrapped");u(this,"prevKey");this.wrapped=e,this.spec=s,this.prevKey=t.clusterKey}async value(){return await this.wrapped.value()}async cleanup(){var e,t;await((t=(e=this.wrapped).cleanup)==null?void 0:t.call(e))}onChange(e){return this.wrapped.onChange(e)}shouldUpdate(e,t){return this.prevKey!==e.clusterKey||!d._.equal(this.spec,t)}}class Ms{constructor(e,t,s){u(this,"spec");u(this,"prov");u(this,"prevKey");u(this,"wrapped");this.wrapped=e,this.spec=s,this.prov=t,this.prevKey=t.clusterKey}async set(e){return await this.wrapped.set(e)}async cleanup(){var e,t;await((t=(e=this.wrapped).cleanup)==null?void 0:t.call(e))}shouldUpdate(e,t){return this.prevKey!==e.clusterKey||!d._.equal(this.spec,t)}}const X=async(n,e,t)=>{var r;const s=bn(n);if(t instanceof zs){if(!t.shouldUpdate(s,e))return t;await((r=t.cleanup)==null?void 0:r.call(t))}return new zs(s.create(e),s,e)},Ee=async(n,e,t)=>{var r;const s=bn(n);if(t instanceof Ms){if(!t.shouldUpdate(s,e))return t;await((r=t.cleanup)==null?void 0:r.call(t))}return new Ms(s.create(e),s,e)};class lt extends Xn.Observer{async cleanup(){}}class Ze extends lt{async set(){return await Promise.resolve()}}u(Ze,"TYPE","noop-boolean-sink");const vn={type:Ze.TYPE,props:{},variant:"sink",valueType:"boolean"};class Be extends lt{async set(){return await Promise.resolve()}}u(Be,"TYPE","noop-numeric-sink");const yr={type:Be.TYPE,props:{},variant:"sink",valueType:"number"};class Ue extends lt{async value(){return await Promise.resolve(!1)}}u(Ue,"TYPE","noop-boolean-source");const Jn={type:Ue.TYPE,props:{},variant:"source",valueType:"boolean"};class Fe extends lt{async value(){return 0}}u(Fe,"TYPE","noop-numeric-source");const wr={type:Fe.TYPE,props:{},variant:"source",valueType:"number"};class Ge extends lt{async value(){return""}}u(Ge,"TYPE","noop-string-source");const xr={type:Ge.TYPE,props:{},variant:"source",valueType:"string"};class je extends lt{async value(){return{key:"noop",variant:"disabled",message:"unknown",time:d.m.now()}}}u(je,"TYPE","noop-status-source");const Qn={type:je.TYPE,props:{},variant:"source",valueType:"status"};class He extends lt{async value(){return o.ZERO}}u(He,"TYPE","noop-color-source");const br={type:He.TYPE,props:{},variant:"source",valueType:"color"};class We extends lt{async value(){return[o.G.ZERO,[]]}}u(We,"TYPE","noop-series");const vr={type:We.TYPE,props:{},variant:"source",valueType:"series"},va={[Ze.TYPE]:Ze,[Be.TYPE]:Be,[Ue.TYPE]:Ue,[Fe.TYPE]:Fe,[je.TYPE]:je,[He.TYPE]:He,[Ge.TYPE]:Ge,[We.TYPE]:We};class Tr{constructor(){u(this,"type","noop")}create(e){const t=va[e.type];return t==null?null:new t}}const Ta=p.z.instanceof(ArrayBuffer),Ce=p.z.object({type:p.z.string(),variant:p.z.enum(["source","sink","source-transformer","sink-transformer"]),valueType:p.z.string(),props:p.z.any(),transfer:p.z.array(Ta).optional()}),ct=Ce.extend({variant:p.z.literal("source")}),Tn=Ce.extend({variant:p.z.literal("sink")}),Sr=Ce.extend({variant:p.z.literal("source-transformer")}),Er=Ce.extend({variant:p.z.literal("sink-transformer")}),Xe=ct.extend({valueType:p.z.literal("series")}),ts=ct.extend({valueType:p.z.literal("boolean")}),Sn=Tn.extend({valueType:p.z.literal("boolean")}),Sa=Er.extend({valueType:p.z.literal("boolean")}),Ea=Sr.extend({valueType:p.z.literal("boolean")}),Cr=ct.extend({valueType:p.z.literal("number")}),Rr=Tn.extend({valueType:p.z.literal("number")}),kr=ct.extend({valueType:p.z.literal("color")}),es=ct.extend({valueType:p.z.literal("status")}),Pr=ct.extend({valueType:p.z.literal("string")});class En extends Xn.BaseObserver{constructor(t){super();u(this,"props_");u(this,"uProps_");u(this,"schema");this.uProps_=t}get props(){if(this.props_==null){const t=this._schema.safeParse(this.uProps_);if(t.success)this.props_=t.data;else throw new d.B(`[BaseTelem] - expected props to be valid, but found the following errors:
|
|
2
2
|
${t.error.message}`)}return this.props_}get _schema(){if(this.schema==null)throw new d.B(`[BaseTelem] - expected subclass to define props schema, but none was found.
|
|
3
3
|
Make sure to define a property 'schema' on the class.`);return this.schema}async cleanup(){}}class G extends En{}class Cn extends En{}class Re extends G{constructor(){super(...arguments);u(this,"sources",{})}get source(){const[t]=Object.values(this.sources);if(t==null)throw new d.B("[UnarySourceTransformer] - expected source to exist, but none was found.");return t}async value(){return this.transform(await this.source.value())}onChange(t){return this.source.onChange(()=>{this.source.value().then(s=>{this.shouldNotify(s)&&t()}).catch(console.error)})}setSources(t){this.sources=t}shouldNotify(t){return!0}transform(t){throw new d.B(`[UnarySourceTransformer] - expected subclass to define transform method, but none was found.
|
|
4
|
-
Make sure to define a method 'transform' on the class.`)}}class
|
|
5
|
-
Make sure to define a method 'transform' on the class.`)}}class
|
|
6
|
-
Make sure to define a method 'transform' on the class.`)}}const zr=p.z.object({from:p.z.string(),to:p.z.string()}),ns=p.z.object({connections:p.z.array(zr),outlet:p.z.string(),segments:p.z.record(ct)});class Mr{constructor(e){u(this,"type","pipeline");u(this,"factory");this.factory=e}create(e){switch(e.type){case se.TYPE:return new se(e.props,this.factory);case re.TYPE:return new re(e.props,this.factory);default:return null}}}class se extends G{constructor(t,s){super(t);u(this,"schema",ns);u(this,"sources",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sources[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sources[a],h=this.sources[l];c==null||h==null||"setSources"in h&&h.setSources({[a]:c})})}get outlet(){const{outlet:t}=this.props,s=this.sources[t];if(s==null)throw new d.B(`[SourcePipeline] - expected source to exist at outlet '${t}', but none was found.`);return s}async value(){return await this.outlet.value()}onChange(t){return this.outlet.onChange(t)}async cleanup(){await Promise.all(Object.values(this.sources).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(se,"TYPE","source-pipeline");const Yr=(n,e)=>({variant:"source",props:e,type:se.TYPE,valueType:n}),ss=p.z.object({connections:p.z.array(zr),inlet:p.z.string(),segments:p.z.record(Tn)});class re extends Cn{constructor(t,s){super(t);u(this,"schema",ss);u(this,"sinks",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sinks[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sinks[a],h=this.sinks[l];c==null||h==null||"setSinks"in c&&c.setSinks({[l]:h})})}get inlet(){const{inlet:t}=this.props,s=this.sinks[t];if(s==null)throw new d.B(`[SinkPipeline] - expected source to exist at inlet '${t}', but none was found.`);return s}async set(t){return await this.inlet.set(t)}async cleanup(){await Promise.all(Object.values(this.sinks).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(re,"TYPE","sink-pipeline");const Dr=(n,e)=>({variant:"sink",props:e,type:re.TYPE,valueType:n}),rs=p.z.object({channel:p.z.number().or(p.z.string())});class ie extends G{constructor(t,s){super(s);u(this,"client");u(this,"removeStreamHandler",null);u(this,"channelKey",0);u(this,"schema",rs);u(this,"leadingBuffer",null);u(this,"valid",!1);this.client=t}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}async cleanup(){var t,s;await((t=this.removeStreamHandler)==null?void 0:t.call(this)),this.valid=!1,(s=this.leadingBuffer)==null||s.release(),this.leadingBuffer=null,this.removeStreamHandler=null}async value(){return d.w$1(this.props.channel)||(this.channelKey===0&&(this.channelKey=(await is(this.client,this.props.channel,!1)).key),this.valid||await this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0)?0:this.leadingBuffer.at(-1,!0)}async read(){this.valid=!0,await this.updateStreamHandler()}async updateStreamHandler(){var s;await((s=this.removeStreamHandler)==null?void 0:s.call(this));const t=r=>{var l;const a=r[this.channelKey].data;if(a.length!==0){const c=a[a.length-1];c.acquire(),(l=this.leadingBuffer)==null||l.release(),this.leadingBuffer=c}this.notify()};this.removeStreamHandler=await this.client.stream(t,[this.channelKey])}}u(ie,"TYPE","stream-channel-value");const is=async(n,e,t)=>{const s=await n.retrieveChannel(e);return!t||s.isIndex?{key:s.key,dataType:s.dataType,virtual:s.virtual}:{key:s.index,dataType:d.g.TIMESTAMP,virtual:!1}},Ea=p.z.object({timeRange:d.E.z,channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1)});class ae extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"valid",!1);u(this,"schema",Ea);this.client=t}async cleanup(){this.data.forEach(t=>t.release()),this.valid=!1}async value(){const{timeRange:t,channel:s,useIndexOfChannel:r}=this.props;if(t.isZero||s===0)return[o.G.ZERO,[]];const i=await is(this.client,s,r);this.valid||await this.readFixed(i.key);let a=o.G.max(this.data.map(l=>l.bounds));return i.dataType.equals(d.g.TIMESTAMP)&&(a={upper:Math.min(a.upper,Number(this.props.timeRange.end.valueOf())),lower:Math.max(a.lower,Number(this.props.timeRange.start.valueOf()))}),[a,this.data]}async readFixed(t){const r=(await this.client.read(this.props.timeRange,[t]))[t].data;r.forEach(i=>i.acquire()),this.data=r,this.valid=!0}}u(ae,"TYPE","series-source");const Ca=p.z.object({channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1),timeSpan:d.y.z,keepFor:d.y.z.optional()});class oe extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"stopStreaming");u(this,"valid",!1);u(this,"schema",Ca);this.client=t}async value(){const{channel:t,useIndexOfChannel:s,timeSpan:r}=this.props;if(t===0)return[o.G.ZERO,[]];const i=d.m.now(),a=await is(this.client,t,s);if(this.valid||await this.read(a),a.dataType.isVariable)return[o.G.ZERO,this.data];let l=o.G.max(this.data.filter(c=>c.timeRange.end.after(i.sub(r))).map(c=>c.bounds));return a.dataType.equals(d.g.TIMESTAMP)&&(l={upper:l.upper,lower:Math.max(l.lower,l.upper-Number(r.valueOf()))}),[l,this.data]}async read({key:t,virtual:s}){const r=d.m.now().spanRange(-this.props.timeSpan);if(!s){const a=(await this.client.read(r,[t]))[t].data;a.forEach(l=>l.acquire()),this.data.push(...a)}await this.updateStreamHandler(t),this.valid=!0}async updateStreamHandler(t){this.stopStreaming!=null&&await this.stopStreaming();const s=r=>{const i=r[t].data;i.forEach(a=>a.acquire()),this.data.push(...i),this.gcOutOfRangeData(),this.notify()};this.stopStreaming=await this.client.stream(s,[t])}gcOutOfRangeData(){const t=d.m.now().sub(this.props.keepFor??this.props.timeSpan),s=this.data.findIndex(r=>r.timeRange.end.before(t));s!==-1&&(this.data.splice(s,1).forEach(r=>r.release()),this.gcOutOfRangeData())}async cleanup(){var t;await((t=this.stopStreaming)==null?void 0:t.call(this)),this.stopStreaming=void 0,this.data.forEach(s=>s.release())}}u(oe,"TYPE","dynamic-series-source");const Ra={[ae.TYPE]:ae,[oe.TYPE]:oe,[ie.TYPE]:ie};class Ar{constructor(e){u(this,"type","remote");u(this,"client");this.client=e}create(e){const t=Ra[e.type];return t==null?null:new t(this.client,e.props)}}const Lr=n=>({type:ae.TYPE,props:n,variant:"source",valueType:"series"}),_r=n=>({type:oe.TYPE,props:n,variant:"source",valueType:"series"}),qr=n=>({type:ie.TYPE,props:n,variant:"source",valueType:"number"});class $r{constructor(){u(this,"type","static")}create(e){switch(e.type){case Ve.TYPE:return new Ve(e.props);case le.TYPE:return new le(e.props);case ce.TYPE:return new ce(e.props);case ue.TYPE:return new ue(e.props);default:return null}}}const as=p.z.object({data:p.z.array(d.xt),offsets:p.z.array(p.z.number()).optional().default([])});class Ve extends G{constructor(t){super(t);u(this,"data");u(this,"schema",as);this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){return[o.G.max(this.data.map(s=>s.bounds)),this.data]}}u(Ve,"TYPE","static-series");const Ir=as.extend({rate:d.P.z,yOffset:p.z.number().optional().default(0),scroll:p.z.number().optional().default(0),startPosition:p.z.number().optional().default(0),scrollBounds:p.z.boolean().optional().default(!1)});class le extends G{constructor(t){super(t);u(this,"schema",Ir);u(this,"position");u(this,"interval");u(this,"data");this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){const t=this.data.map(r=>r.slice(0,this.position));if(this.props.scrollBounds){const r=t[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=t[0].data[this.position-1];return[{lower:Number(r),upper:Number(i)},t]}return[o.G.max(t.map(r=>r.bounds)),t]}start(t){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{var s;(s=this.notify)==null||s.call(this),this.position++},t.period.milliseconds)}async cleanup(){clearInterval(this.interval),this.interval=void 0}}u(le,"TYPE","iterative-series");const Nr=p.z.number();class ce extends G{constructor(){super(...arguments);u(this,"schema",Nr)}async value(){return this.props}}u(ce,"TYPE","static-numeric");const Zr=p.z.string();class ue extends G{constructor(){super(...arguments);u(this,"schema",Zr)}async value(){return this.props}}u(ue,"TYPE","static-string");const ka=n=>({type:Ve.TYPE,props:n,variant:"source",valueType:"series"}),Pa=n=>({type:le.TYPE,props:n,variant:"source",valueType:"series"}),Oa=n=>({type:ce.TYPE,props:n,variant:"source",valueType:"number"}),za=n=>({type:ue.TYPE,props:n,variant:"source",valueType:"string"}),Ma=["standard","scientific","engineering"],Br=p.z.enum(Ma),Ya=(n,e,t)=>{if(Number.isNaN(n))return"NaN";if(n===1/0)return"∞";if(n===-1/0)return"-∞";if(t==="standard")return n.toFixed(e);if(n===0)return e===0?"0ᴇ0":`0.${"0".repeat(e)}ᴇ0`;let s;return t==="scientific"?s=Math.floor(Math.log10(Math.abs(n))):s=Math.floor(Math.log10(Math.abs(n))/3)*3,`${(n/10**s).toFixed(e)}ᴇ${s}`};class Ur{constructor(){u(this,"type","transformer")}create(e){switch(e.type){case Pt.TYPE:return new Pt(e.props);case Ot.TYPE:return new Ot(e.props);case zt.TYPE:return new zt(e.props);case Mt.TYPE:return new Mt(e.props);case Yt.TYPE:return new Yt(e.props);case Dt.TYPE:return new Dt(e.props)}return null}}const Da=p.z.object({truthy:p.z.number().optional().default(1),falsy:p.z.number().optional().default(0)}),Fr=n=>({props:n,type:Pt.TYPE,variant:"sink",valueType:"boolean"}),Vt=class Vt extends Or{constructor(){super(...arguments);u(this,"schema",Vt.propsZ)}transform(t){return t?this.props.truthy:this.props.falsy}};u(Vt,"TYPE","boolean-numeric-converter-sink"),u(Vt,"propsZ",Da);let Pt=Vt;const Aa=p.z.object({trueBound:o.G.bounds}),Gr=n=>({props:n,type:Ot.TYPE,variant:"source",valueType:"boolean"}),Kt=class Kt extends Re{constructor(){super(...arguments);u(this,"schema",Kt.propsZ);u(this,"curr",null)}shouldNotify(t){const s=o.G.contains(this.props.trueBound,t)!==this.curr;return this.curr=o.G.contains(this.props.trueBound,t),s}transform(t){return this.curr=o.G.contains(this.props.trueBound,t),this.curr}};u(Kt,"TYPE","boolean-source"),u(Kt,"propsZ",Aa);let Ot=Kt;const jr=p.z.object({}),Jt=class Jt extends Pr{constructor(){super(...arguments);u(this,"schema",Jt.propsZ)}transform(t){return Object.values(t).reduce((s,r)=>s+r,0)/Object.keys(t).length}};u(Jt,"TYPE","mean"),u(Jt,"propsZ",jr);let zt=Jt;const La=n=>({props:n,type:zt.TYPE,variant:"source",valueType:"boolean"}),Hr=p.z.object({trueVariant:d.variantZ.optional().default("success")}),Qt=class Qt extends Re{constructor(){super(...arguments);u(this,"schema",Qt.propsZ)}transform(t){return t.variant===this.props.trueVariant}};u(Qt,"TYPE","boolean-status"),u(Qt,"propsZ",Hr);let Mt=Qt;const _a=n=>({props:n,type:Mt.TYPE,variant:"source",valueType:"boolean"}),os=p.z.object({precision:p.z.number().optional().default(2),prefix:p.z.string().optional().default(""),suffix:p.z.string().optional().default(""),notation:Br.optional().default("standard")}),te=class te extends Re{constructor(){super(...arguments);u(this,"schema",te.propsZ)}transform(t){return`${this.props.prefix}${Ya(t,this.props.precision,this.props.notation)}${this.props.suffix}`}};u(te,"TYPE","stringify-number"),u(te,"propsZ",os);let Yt=te;const Wr=n=>({props:n,type:Yt.TYPE,variant:"source",valueType:"string"}),ls=p.z.object({windowSize:p.z.number().optional().default(5)});class Dt extends Re{constructor(){super(...arguments);u(this,"schema",ls);u(this,"values",[])}transform(t){return this.props.windowSize<2?t:this.values.reduce((s,r)=>s+r,0)/this.values.length}shouldNotify(t){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(t),this.values.length===this.props.windowSize)}}u(Dt,"TYPE","rolling-average"),u(Dt,"propsZ",jr);const Xr=n=>({props:n,type:Dt.TYPE,variant:"source",valueType:"number"});class Vr{constructor(e){u(this,"factories");u(this,"type","compound");this.factories=e}add(e){this.factories=[...this.factories.filter(t=>t.type!==e.type),e]}create(e){for(const t of this.factories){const s=t.create(e);if(s!=null)return s}return null}}const Kr=n=>{const e=[new Ur,new $r,new vr],t=new Vr(e);return n!=null&&t.add(new Ar(n)),t.add(new Mr(t)),t},Jr=p.z.object({include:p.z.string().array().optional(),exclude:p.z.string().array().optional(),level:p.z.enum(d.g$1.LOG_LEVELS).optional().default("info")}),In="alamos-provider";var $n;let Nn=($n=class extends d.Composite{constructor(){super(...arguments);u(this,"schema",Jr)}async afterUpdate(){if(this.ctx.getOptional(In)!=null)return;const s=[],{include:r,exclude:i,level:a}=this.state;(r!=null||i!=null)&&s.push(d.g$1.logLevelKeyFiler({include:r,exclude:i})),a!=null&&s.push(d.g$1.logThresholdFilter(a)),s.length===0&&s.push(()=>!1),this.internal.ins=new d.g$1.Instrumentation({key:"aether",logger:new d.g$1.Logger({filters:s})}),this.ctx.set(In,this.internal.ins)}},u($n,"TYPE","AlamosProvider"),$n);const ke=(n,e)=>{const t=n.get(In);if(t==null)throw new Error("No instrumentation provider");return e==null?t:t.child(e)},qa={[Nn.TYPE]:Nn},Qr=(n,e)=>n.dataType.isVariable?n:(e==null&&n.dataType.equals(d.g.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(d.g.FLOAT32,e)),ti=()=>({purgedSeries:0,purgedBytes:d.x.bytes(0)}),ei={instrumentation:d.g$1.NOOP,staleEntryThreshold:d.y.seconds(20)};class $a{constructor(e){u(this,"data",[]);u(this,"props");this.props={...ei,...e}}write(e){e.length!==0&&(e.forEach(t=>this.writeOne(Qr(t))),this.checkIntegrity(e))}dirtyRead(e){const t=this.data.filter(({data:a})=>a.timeRange.overlapsWith(e)).map(({data:a})=>a);if(t.length===0)return{series:[],gaps:[e]};const s=t.map((a,l)=>l===0?d.E.ZERO:new d.E(t[l-1].timeRange.end,a.timeRange.start)).filter(a=>!a.isZero&&a.isValid),r=new d.E(e.start,t[0].timeRange.start),i=new d.E(t[t.length-1].timeRange.end,e.end);return r.isValid&&!r.isZero&&s.unshift(r),i.isValid&&!i.isZero&&s.push(i),{series:t,gaps:s}}gc(){const{staleEntryThreshold:e}=this.props,t=ti(),s=this.data.filter(r=>{const i=r.data.refCount>0||d.m.since(r.addedAt).lessThan(e);return i||(t.purgedBytes=t.purgedBytes.add(r.data.byteCapacity)),i});return t.purgedSeries=this.data.length-s.length,this.data=s,t}close(){this.data=[]}writeOne(e){const{instrumentation:{L:t}}=this.props;if(e.length===0)return;const s=o.G.buildInsertionPlan(this.data.map(c=>c.data.alignmentBounds),e.alignmentBounds);if(s===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(c=>c.data.digest)});const{removeBefore:r,removeAfter:i,insertInto:a,deleteInBetween:l}=s;e=e.slice(r,e.data.length-Number(i)),e.length!==0&&this.data.splice(a,l,{data:e,addedAt:d.m.now()})}checkIntegrity(e){const{instrumentation:{L:t}}=this.props,s=this.data.map(i=>i.data.alignmentBounds);if(s.some((i,a)=>s.some((l,c)=>a===c?!1:o.G.overlapsWith(i,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const Ia=100,Na=1e6,Za=1e4,Ba=100,Ua=40;class Fa{constructor(e){u(this,"props");u(this,"counter",0);u(this,"curr");u(this,"avgRate",0);u(this,"timeOfLastWrite");u(this,"totalWrites",0);u(this,"now",()=>d.m.now());this.props=e,this.curr=null,e.testingNow!=null&&(this.now=e.testingNow),this.timeOfLastWrite=this.now()}get length(){var e;return((e=this.curr)==null?void 0:e.length)??0}get leadingBuffer(){return this.curr}write(e){const t=e.flatMap(s=>this._write(s));return{flushed:t.flatMap(s=>s.flushed),allocated:t.flatMap(s=>s.allocated)}}allocate(e,t,s){this.counter++;const r=this.props.dataType.isVariable,i=this.props.dataType.equals(d.g.TIMESTAMP);return d.V.alloc({capacity:r?e*Ua:e,dataType:r?this.props.dataType:d.g.FLOAT32,timeRange:s.range(d.m.MAX),sampleOffset:i?BigInt(s.valueOf()):0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),s={flushed:[],allocated:[]};if(this.curr==null)this.curr=this.allocate(t,e.alignment,this.now()),s.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-e.alignment))>1){const c=this.now();this.curr.timeRange.end=c,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,c),s.allocated.push(this.curr)}const r=Qr(e,this.curr.sampleOffset),i=this.curr.write(r);if(i===e.length)return this.updateAvgRate(e),s;const a=this.now();this.curr.timeRange.end=a,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment+BigInt(i),a),s.allocated.push(this.curr);const l=this._write(e.slice(i));return s.flushed.push(...l.flushed),s.allocated.push(...l.allocated),s}updateAvgRate(e){if(typeof this.props.dynamicBufferSize=="number")return;const t=e.length/this.now().span(this.timeOfLastWrite).seconds;this.totalWrites>0&&isFinite(t)&&t>0&&(this.avgRate=(this.avgRate*(this.totalWrites-1)+t)/this.totalWrites),this.totalWrites++,this.timeOfLastWrite=this.now()}nextBufferSize(){const{dynamicBufferSize:e}=this.props;if(typeof e=="number")return e;if(this.totalWrites<Ba)return Za;const t=o.W.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,Na),Ia))}close(){this.curr=null}}class Ga{constructor(e){u(this,"channel");u(this,"closed",!1);u(this,"ins");u(this,"static");u(this,"dynamic");this.channel=e.channel,this.ins=e.instrumentation??d.g$1.NOOP,this.static=new $a(e),this.dynamic=new Fa({dynamicBufferSize:e.dynamicBufferSize,dataType:this.channel.dataType})}writeDynamic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted dynamic write to a closed cache for channel ${this.channel.name}`),[];const{flushed:t,allocated:s}=this.dynamic.write(e);return t.length>0&&this.static.write(t),s}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(e)}read(e){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:[],gaps:[]}):this.static.dirtyRead(e)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:d.x.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const ja=d.k.seconds(60);class Ha{constructor(e){u(this,"props");u(this,"cache",new Map);u(this,"gcInterval");this.props={dynamicBufferSize:ja,gcInterval:d.k.seconds(30),...ei,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:s,dynamicBufferSize:r}=this.props,i=[];for(const l of e)this.cache.has(l)||i.push(l);if(i.length===0)return;const a=await s.retrieve(i);for(const l of a){const c=new Ga({channel:l,dynamicBufferSize:r,instrumentation:t.child(`cache-${l.name}-${l.key}`)});this.cache.has(l.key)||this.cache.set(l.key,c)}}get(e){const t=this.cache.get(e);if(t!=null)return t;throw new d.Ce(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=ti();this.cache.forEach(s=>{const r=s.gc();t.purgedSeries+=r.purgedSeries,t.purgedBytes=t.purgedBytes.add(r.purgedBytes)}),e.info("garbage collection complete",{purgedSeries:t.purgedSeries,purgedBytes:t.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(e=>e.close()),this.cache.clear()}}class Ke{constructor(e,t){u(this,"channel");u(this,"data");this.channel=e,this.data=t}get timeRange(){if(this.data.length===0)return d.V$1.ZERO;const e=this.data[0].timeRange,t=this.data[this.data.length-1].timeRange;return new d.V$1(e.start,t.end)}get digest(){return{channel:this.channel.key,timeRange:this.timeRange.toPrettyString(),series:this.data.map(e=>e.digest)}}}const On=n=>n.map(e=>e.digest);class Wa{constructor(e){u(this,"props");u(this,"debouncedRead");u(this,"guarded",{mu:new d.Mutex,requests:new Map});this.props={instrumentation:d.g$1.NOOP,batchDebounce:d.y.milliseconds(50),...e},this.debouncedRead=d.o(()=>{this.batchRead()},this.props.batchDebounce.milliseconds)}async read(e,t){const{instrumentation:{L:s},cache:r}=this.props;s.debug("starting read",{tr:e.toPrettyString(),channels:t});const i=performance.now(),a=new Map,l={};await r.populateMissing(t);try{for(const f of t){const g=r.get(f),{series:m,gaps:x}=g.read(e);x.length===0&&(l[f]=new Ke(g.channel,m)),x.forEach(b=>{const T=a.get(b.toString());T==null?a.set(b.toString(),[b,new Set([f])]):a.set(b.toString(),[b,new Set([...T[1],f])])})}if(a.size===0)return s.debug("read satisfied by cache",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l;s.debug("read cache miss",()=>({tr:e.toPrettyString(),channels:t,toFetch:Array.from(a.values()).map(([f,g])=>({timeRange:f.toPrettyString(),channels:g})),responses:On(Object.values(l))}));const{mu:c,requests:h}=this.guarded;for(const[,[f,g]]of a)await new Promise((m,x)=>{c.runExclusive(async()=>{h.set([f,g],{resolve:m,reject:x}),this.debouncedRead()})})}catch(c){throw s.error("read failed",{tr:e.toPrettyString(),channels:t,error:c}),c}for(const c of t){const h=r.get(c),{series:f}=h.read(e);l[c]=new Ke(h.channel,f)}return s.debug("read satisfied by fetch",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l}async batchRead(){const{instrumentation:{L:e},readRemote:t,cache:s}=this.props,{mu:r,requests:i}=this.guarded;await r.runExclusive(async()=>{const a=[];try{i.forEach((l,c)=>{const[h,f]=c,g=a.find(([m])=>m.start.span(h.start).lessThan(d.y.milliseconds(5))&&m.end.span(h.end).lessThan(d.y.milliseconds(5)));g==null?a.push([h,f]):g[1]=new Set([...g[1],...f])}),e.debug("batch read",{toFetch:a.map(([l,c])=>({timeRange:l.toPrettyString(),channels:c}))});for(const[l,c]of a){const h=Array.from(c),f=await t(l,h);h.forEach(g=>{const m=s.get(g),x=f.get(g);m.writeStatic(x.series)})}i.forEach(l=>l.resolve())}catch(l){e.error("batch read failed",{error:l},!0),i.forEach(c=>c.reject(l))}finally{i.clear()}})}}class Xa{constructor(e){u(this,"props");u(this,"mu",new d.Mutex);u(this,"listeners",new Map);u(this,"streamerRunLoop",null);u(this,"streamer",null);u(this,"closed",!1);this.props={instrumentation:d.g$1.NOOP,...e}}async stream(e,t){const{cache:s,instrumentation:{L:r}}=this.props;return await s.populateMissing(t),await this.mu.runExclusive(async()=>{r.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:t});const i={};for(const a of t){const l=s.get(a),c=l.leadingBuffer!=null?[l.leadingBuffer]:[];i[a]=new Ke(l.channel,c)}return e(i),await this.updateStreamer(),async()=>await this.removeStreamHandler(e)})}async removeStreamHandler(e){const{instrumentation:{L:t}}=this.props;await this.mu.runExclusive(()=>{const s=this.listeners.get(e);s!=null&&(s.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.debug("removing stream handler"),this.listeners.delete(e))return await this.updateStreamer();t.warn("attempted to remove non-existent stream handler")})},5e3)}async updateStreamer(){var i,a;if(this.closed)return;const{instrumentation:{L:e},core:t}=this.props,s=new Set;if(this.listeners.forEach(l=>l.keys.forEach(c=>s.add(c))),s.size===0){e.info("no keys to stream, closing streamer"),(i=this.streamer)==null||i.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.info("streamer closed successfully");return}const r=Array.from(s);if(d.F.primitiveArrays(r,((a=this.streamer)==null?void 0:a.keys)??[])===d.F.EQUAL){e.debug("streamer keys unchanged",{keys:r});return}this.streamer==null&&(e.info("creating new streamer",{keys:r}),this.streamer=await t.openStreamer(r),this.streamerRunLoop=this.runStreamer(this.streamer)),e.debug("updating streamer",{prev:this.streamer.keys,next:r});try{await this.streamer.update(r)}catch(l){throw e.error("failed to update streamer",{error:l}),l}}async runStreamer(e){const{cache:t,instrumentation:{L:s}}=this.props;try{for await(const r of e){const i=[];for(const a of r.keys){const l=r.get(a),c=t.get(a),h=c.writeDynamic(l.series);i.push(new Ke(c.channel,h))}this.listeners.forEach((a,l)=>{if(!a.valid)return;const c=i.filter(f=>a.keys.includes(f.channel.key));if(c.length===0)return;const h=Object.fromEntries(c.map(f=>[f.channel.key,f]));l(h)})}}catch(r){throw s.error("streamer run loop failed",{error:r},!0),r}}async close(){var e;(e=this.streamer)==null||e.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.closed=!0}}class Va{constructor(){u(this,"key",d.Rt.id());u(this,"_client",null)}async swap(e){var t;this.key=d.Rt.id(),await((t=this._client)==null?void 0:t.close()),this._client=e}async retrieveChannel(e){return await this.client.retrieveChannel(e)}async read(e,t){return await this.client.read(e,t)}async stream(e,t){return await this.client.stream(e,t)}async close(){await this.client.close()}get client(){if(this._client==null)throw new d.re("No cluster has been connected");return this._client}}class Ka{constructor({instrumentation:e,core:t}){u(this,"key",d.Rt.id());u(this,"ins");u(this,"cache");u(this,"reader");u(this,"streamer");u(this,"channelRetriever");this.ins=e??d.g$1.NOOP,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new Ha({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new Wa({cache:this.cache,readRemote:async(s,r)=>await t.read(s,r),instrumentation:this.ins.child("reader")}),this.streamer=new Xa({cache:this.cache,core:t,instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new d.re(`channel ${e} not found`);return t[0]}async read(e,t){return await this.reader.read(e,t)}async stream(e,t){return await this.streamer.stream(e,t)}async close(){this.ins.L.info("closing client",{key:this.key}),await this.streamer.close(),this.cache.close()}}const cs=p.z.object({}),Et=class Et extends d.Composite{constructor(){super(...arguments);u(this,"client",new Va);u(this,"factory",Kr(this.client));u(this,"schema",Et.stateZ);u(this,"prevClient",null)}create(t){const{instrumentation:s}=this.internal;s.L.debug("creating telem",{spec:t});const r=this.factory.create(t);if(r==null)throw new d.Ce(`Telemetry service could not find a source for type ${t.type}`);return r}get clusterKey(){return this.client.key}registerFactory(t){this.factory.add(t)}equals(t){return t instanceof Et?this.client._client===t.client._client:!1}async afterUpdate(){const t=Se(this.ctx),s=ke(this.ctx,"telem");this.internal.instrumentation=s.child("provider"),t!==this.prevClient&&(s.L.info("swapping client",{client:t}),t==null?await this.client.swap(null):await this.client.swap(new Ka({core:t,instrumentation:s})),this.prevClient=t,pr(this.ctx,this))}};u(Et,"TYPE","TelemProvider"),u(Et,"stateZ",cs);let At=Et;const ni={[At.TYPE]:At},Ja=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:Cn,AbstractSource:G,Base:En,BaseProvider:At,BooleanStatus:Mt,ChannelData:ae,CompoundTelemFactory:Vr,FixedNumber:ce,FixedString:ue,IterativeSeries:le,Mean:zt,MultiSourceTransformer:Pr,NoopFactory:vr,PipelineFactory:Mr,REGISTRY:ni,RemoteFactory:Ar,RollingAverage:Dt,SetPoint:Pt,SinkPipeline:re,SourcePipeline:se,StaticFactory:$r,StreamChannelData:oe,StreamChannelValue:ie,StringifyNumber:Yt,TransformerFactory:Ur,UnarySinkTransformer:Or,UnarySourceTransformer:Re,WithinBounds:Ot,booleanSinkSpecZ:Sn,booleanSinkTransformerSpecZ:Ta,booleanSourceSpecZ:ts,booleanSourceTransformerSpecZ:Sa,booleanStatus:_a,booleanStatusProps:Hr,channelData:Lr,colorSourceSpecZ:Rr,factory:Kr,fixedArray:ka,fixedNumber:Oa,fixedNumberPropsZ:Nr,fixedSeriesPropsZ:as,fixedString:za,fixedStringPropsZ:Zr,iterativeArray:Pa,iterativeSeriesPropsZ:Ir,mean:La,noopBooleanSinkSpec:vn,noopBooleanSourceSpec:Jn,noopColorSourceSpec:xr,noopNumericSinkSpec:mr,noopNumericSourceSpec:yr,noopSeriesSourceSpec:br,noopStatusSourceSpec:Qn,noopStringSourceSpec:wr,numberSinkSpecZ:Cr,numberSourceSpecZ:Er,providerStateZ:cs,registerFactory:gr,rollingAverage:Xr,rollingAverageProps:ls,seriesSourceSpecZ:Xe,setProvider:pr,setpoint:Fr,sinkPipeline:Dr,sinkPipelinePropsZ:ss,sinkSpecZ:Tn,sinkTransformerSpecZ:Sr,sourcePipeline:Yr,sourcePipelinePropsZ:ns,sourceSpecZ:ct,sourceTransformerSpecZ:Tr,specZ:Ce,statusSourceSpecZ:es,streamChannelData:_r,streamChannelValue:qr,streamChannelValuePropsZ:rs,stringSourceSpecZ:kr,stringifyNumber:Wr,stringifyNumberProps:os,useProvider:bn,useSink:Ee,useSource:X,withinBounds:Gr},Symbol.toStringTag,{value:"Module"})),si=p.z.object({key:p.z.string(),size:p.z.number(),order:p.z.number(),loc:o.J.outer});p.z.record(si);const dt=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Qa=(n,e,t)=>{const s=e[n];if(s==null)return o.q.ZERO;const r=o.J.construct(s.loc),i=dt(r,e),a=o.J.construct(o.g.swap(o.J.direction(r))),l=dt(a,e),c=i.findIndex(({key:g})=>g===n),h=i.slice(0,c).reduce((g,{size:m})=>g+m,0),f=l.reduce((g,{size:m})=>g+m,0);switch(r){case"left":return o.q.translate(o.Eo.topLeft(t),[h,f]);case"right":return o.q.translate(o.Eo.topRight(t),[h-s.size,f]);case"top":return o.q.translate(o.Eo.topLeft(t),[f,h]);default:return o.q.translate(o.Eo.bottomLeft(t),[f,-h-s.size])}},to=(n,e)=>{const t=dt("left",n),s=dt("right",n),r=dt("top",n),i=dt("bottom",n),a=t.reduce((f,{size:g})=>f+g,0),l=s.reduce((f,{size:g})=>f+g,0),c=r.reduce((f,{size:g})=>f+g,0),h=i.reduce((f,{size:g})=>f+g,0);return o.Eo.construct(o.q.translate(o.Eo.topLeft(e),{x:a,y:c}),o.Eo.width(e)-a-l,o.Eo.height(e)-c-h)};function $e(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function eo(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function us(n){let e,t,s;n.length!==2?(e=$e,t=(l,c)=>$e(n(l),c),s=(l,c)=>n(l)-c):(e=n===$e||n===eo?n:no,t=n,s=n);function r(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<0?h=g+1:f=g}while(h<f)}return h}function i(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<=0?h=g+1:f=g}while(h<f)}return h}function a(l,c,h=0,f=l.length){const g=r(l,c,h,f-1);return g>h&&s(l[g-1],c)>-s(l[g],c)?g-1:g}return{left:r,center:a,right:i}}function no(){return 0}function so(n){return n===null?NaN:+n}const ro=us($e),io=ro.right;us(so).center;const ao=Math.sqrt(50),oo=Math.sqrt(10),lo=Math.sqrt(2);function Je(n,e,t){const s=(e-n)/Math.max(0,t),r=Math.floor(Math.log10(s)),i=s/Math.pow(10,r),a=i>=ao?10:i>=oo?5:i>=lo?2:1;let l,c,h;return r<0?(h=Math.pow(10,-r)/a,l=Math.round(n*h),c=Math.round(e*h),l/h<n&&++l,c/h>e&&--c,h=-h):(h=Math.pow(10,r)*a,l=Math.round(n/h),c=Math.round(e/h),l*h<n&&++l,c*h>e&&--c),c<l&&.5<=t&&t<2?Je(n,e,t*2):[l,c,h]}function co(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[r,i,a]=s?Je(e,n,t):Je(n,e,t);if(!(i>=r))return[];const l=i-r+1,c=new Array(l);if(s)if(a<0)for(let h=0;h<l;++h)c[h]=(i-h)/-a;else for(let h=0;h<l;++h)c[h]=(i-h)*a;else if(a<0)for(let h=0;h<l;++h)c[h]=(r+h)/-a;else for(let h=0;h<l;++h)c[h]=(r+h)*a;return c}function Zn(n,e,t){return e=+e,n=+n,t=+t,Je(n,e,t)[2]}function Bn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,r=s?Zn(e,n,t):Zn(n,e,t);return(s?-1:1)*(r<0?1/-r:r)}function ri(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function hs(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function ii(n,e){var t=Object.create(n.prototype);for(var s in e)t[s]=e[s];return t}function Pe(){}var he=.7,Qe=1/he,kt="\\s*([+-]?\\d+)\\s*",de="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",J="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",uo=/^#([0-9a-f]{3,8})$/,ho=new RegExp(`^rgb\\(${kt},${kt},${kt}\\)$`),fo=new RegExp(`^rgb\\(${J},${J},${J}\\)$`),po=new RegExp(`^rgba\\(${kt},${kt},${kt},${de}\\)$`),go=new RegExp(`^rgba\\(${J},${J},${J},${de}\\)$`),mo=new RegExp(`^hsl\\(${de},${J},${J}\\)$`),yo=new RegExp(`^hsla\\(${de},${J},${J},${de}\\)$`),Ys={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};hs(Pe,Lt,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:Ds,formatHex:Ds,formatHex8:wo,formatHsl:xo,formatRgb:As,toString:As});function Ds(){return this.rgb().formatHex()}function wo(){return this.rgb().formatHex8()}function xo(){return ai(this).formatHsl()}function As(){return this.rgb().formatRgb()}function Lt(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=uo.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?Ls(e):t===3?new Z(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?De(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?De(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=ho.exec(n))?new Z(e[1],e[2],e[3],1):(e=fo.exec(n))?new Z(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=po.exec(n))?De(e[1],e[2],e[3],e[4]):(e=go.exec(n))?De(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=mo.exec(n))?$s(e[1],e[2]/100,e[3]/100,1):(e=yo.exec(n))?$s(e[1],e[2]/100,e[3]/100,e[4]):Ys.hasOwnProperty(n)?Ls(Ys[n]):n==="transparent"?new Z(NaN,NaN,NaN,0):null}function Ls(n){return new Z(n>>16&255,n>>8&255,n&255,1)}function De(n,e,t,s){return s<=0&&(n=e=t=NaN),new Z(n,e,t,s)}function bo(n){return n instanceof Pe||(n=Lt(n)),n?(n=n.rgb(),new Z(n.r,n.g,n.b,n.opacity)):new Z}function Un(n,e,t,s){return arguments.length===1?bo(n):new Z(n,e,t,s??1)}function Z(n,e,t,s){this.r=+n,this.g=+e,this.b=+t,this.opacity=+s}hs(Z,Un,ii(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new Z(pt(this.r),pt(this.g),pt(this.b),tn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:_s,formatHex:_s,formatHex8:vo,formatRgb:qs,toString:qs}));function _s(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}`}function vo(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}${ft((isNaN(this.opacity)?1:this.opacity)*255)}`}function qs(){const n=tn(this.opacity);return`${n===1?"rgb(":"rgba("}${pt(this.r)}, ${pt(this.g)}, ${pt(this.b)}${n===1?")":`, ${n})`}`}function tn(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function pt(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function ft(n){return n=pt(n),(n<16?"0":"")+n.toString(16)}function $s(n,e,t,s){return s<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new H(n,e,t,s)}function ai(n){if(n instanceof H)return new H(n.h,n.s,n.l,n.opacity);if(n instanceof Pe||(n=Lt(n)),!n)return new H;if(n instanceof H)return n;n=n.rgb();var e=n.r/255,t=n.g/255,s=n.b/255,r=Math.min(e,t,s),i=Math.max(e,t,s),a=NaN,l=i-r,c=(i+r)/2;return l?(e===i?a=(t-s)/l+(t<s)*6:t===i?a=(s-e)/l+2:a=(e-t)/l+4,l/=c<.5?i+r:2-i-r,a*=60):l=c>0&&c<1?0:a,new H(a,l,c,n.opacity)}function To(n,e,t,s){return arguments.length===1?ai(n):new H(n,e,t,s??1)}function H(n,e,t,s){this.h=+n,this.s=+e,this.l=+t,this.opacity=+s}hs(H,To,ii(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new H(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new H(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,s=t+(t<.5?t:1-t)*e,r=2*t-s;return new Z(zn(n>=240?n-240:n+120,r,s),zn(n,r,s),zn(n<120?n+240:n-120,r,s),this.opacity)},clamp(){return new H(Is(this.h),Ae(this.s),Ae(this.l),tn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=tn(this.opacity);return`${n===1?"hsl(":"hsla("}${Is(this.h)}, ${Ae(this.s)*100}%, ${Ae(this.l)*100}%${n===1?")":`, ${n})`}`}}));function Is(n){return n=(n||0)%360,n<0?n+360:n}function Ae(n){return Math.max(0,Math.min(1,n||0))}function zn(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const ds=n=>()=>n;function So(n,e){return function(t){return n+t*e}}function Eo(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(s){return Math.pow(n+s*e,t)}}function Co(n){return(n=+n)==1?oi:function(e,t){return t-e?Eo(e,t,n):ds(isNaN(e)?t:e)}}function oi(n,e){var t=e-n;return t?So(n,t):ds(isNaN(n)?e:n)}const Fn=function n(e){var t=Co(e);function s(r,i){var a=t((r=Un(r)).r,(i=Un(i)).r),l=t(r.g,i.g),c=t(r.b,i.b),h=oi(r.opacity,i.opacity);return function(f){return r.r=a(f),r.g=l(f),r.b=c(f),r.opacity=h(f),r+""}}return s.gamma=n,s}(1);function Ro(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,s=e.slice(),r;return function(i){for(r=0;r<t;++r)s[r]=n[r]*(1-i)+e[r]*i;return s}}function ko(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Po(n,e){var t=e?e.length:0,s=n?Math.min(t,n.length):0,r=new Array(s),i=new Array(t),a;for(a=0;a<s;++a)r[a]=fs(n[a],e[a]);for(;a<t;++a)i[a]=e[a];return function(l){for(a=0;a<s;++a)i[a]=r[a](l);return i}}function Oo(n,e){var t=new Date;return n=+n,e=+e,function(s){return t.setTime(n*(1-s)+e*s),t}}function fe(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function zo(n,e){var t={},s={},r;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in n?t[r]=fs(n[r],e[r]):s[r]=e[r];return function(i){for(r in t)s[r]=t[r](i);return s}}var Gn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mn=new RegExp(Gn.source,"g");function Mo(n){return function(){return n}}function Yo(n){return function(e){return n(e)+""}}function li(n,e){var t=Gn.lastIndex=Mn.lastIndex=0,s,r,i,a=-1,l=[],c=[];for(n=n+"",e=e+"";(s=Gn.exec(n))&&(r=Mn.exec(e));)(i=r.index)>t&&(i=e.slice(t,i),l[a]?l[a]+=i:l[++a]=i),(s=s[0])===(r=r[0])?l[a]?l[a]+=r:l[++a]=r:(l[++a]=null,c.push({i:a,x:fe(s,r)})),t=Mn.lastIndex;return t<e.length&&(i=e.slice(t),l[a]?l[a]+=i:l[++a]=i),l.length<2?c[0]?Yo(c[0].x):Mo(e):(e=c.length,function(h){for(var f=0,g;f<e;++f)l[(g=c[f]).i]=g.x(h);return l.join("")})}function fs(n,e){var t=typeof e,s;return e==null||t==="boolean"?ds(e):(t==="number"?fe:t==="string"?(s=Lt(e))?(e=s,Fn):li:e instanceof Lt?Fn:e instanceof Date?Oo:ko(e)?Ro:Array.isArray(e)?Po:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?zo:fe)(n,e)}function Do(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}function Ao(n){return function(){return n}}function Lo(n){return+n}var Ns=[0,1];function Tt(n){return n}function jn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Ao(isNaN(e)?NaN:.5)}function _o(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function qo(n,e,t){var s=n[0],r=n[1],i=e[0],a=e[1];return r<s?(s=jn(r,s),i=t(a,i)):(s=jn(s,r),i=t(i,a)),function(l){return i(s(l))}}function $o(n,e,t){var s=Math.min(n.length,e.length)-1,r=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)r[a]=jn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var c=io(n,l,1,s)-1;return i[c](r[c](l))}}function ci(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function Io(){var n=Ns,e=Ns,t=fs,s,r,i,a=Tt,l,c,h;function f(){var m=Math.min(n.length,e.length);return a!==Tt&&(a=_o(n[0],n[m-1])),l=m>2?$o:qo,c=h=null,g}function g(m){return m==null||isNaN(m=+m)?i:(c||(c=l(n.map(s),e,t)))(s(a(m)))}return g.invert=function(m){return a(r((h||(h=l(e,n.map(s),fe)))(m)))},g.domain=function(m){return arguments.length?(n=Array.from(m,Lo),f()):n.slice()},g.range=function(m){return arguments.length?(e=Array.from(m),f()):e.slice()},g.rangeRound=function(m){return e=Array.from(m),t=Do,f()},g.clamp=function(m){return arguments.length?(a=m?!0:Tt,f()):a!==Tt},g.interpolate=function(m){return arguments.length?(t=m,f()):t},g.unknown=function(m){return arguments.length?(i=m,g):i},function(m,x){return s=m,r=x,f()}}function ui(){return Io()(Tt,Tt)}function No(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function en(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function _t(n){return n=en(Math.abs(n)),n?n[1]:NaN}function Zo(n,e){return function(t,s){for(var r=t.length,i=[],a=0,l=n[0],c=0;r>0&&l>0&&(c+l+1>s&&(l=Math.max(1,s-c)),i.push(t.substring(r-=l,r+l)),!((c+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function Bo(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var Uo=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function nn(n){if(!(e=Uo.exec(n)))throw new Error("invalid format: "+n);var e;return new ps({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}nn.prototype=ps.prototype;function ps(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}ps.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function Fo(n){t:for(var e=n.length,t=1,s=-1,r;t<e;++t)switch(n[t]){case".":s=r=t;break;case"0":s===0&&(s=t),r=t;break;default:if(!+n[t])break t;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(r+1):n}var hi;function Go(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1],i=r-(hi=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+en(n,Math.max(0,e+i-1))[0]}function Zs(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+s:s.length>r+1?s.slice(0,r+1)+"."+s.slice(r+1):s+new Array(r-s.length+2).join("0")}const Bs={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:No,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>Zs(n*100,e),r:Zs,s:Go,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Us(n){return n}var Fs=Array.prototype.map,Gs=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function jo(n){var e=n.grouping===void 0||n.thousands===void 0?Us:Zo(Fs.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",r=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?Us:Bo(Fs.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",c=n.nan===void 0?"NaN":n.nan+"";function h(g){g=nn(g);var m=g.fill,x=g.align,b=g.sign,T=g.symbol,C=g.zero,O=g.width,A=g.comma,P=g.precision,Y=g.trim,L=g.type;L==="n"?(A=!0,L="g"):Bs[L]||(P===void 0&&(P=12),Y=!0,L="g"),(C||m==="0"&&x==="=")&&(C=!0,m="0",x="=");var v=T==="$"?t:T==="#"&&/[boxX]/.test(L)?"0"+L.toLowerCase():"",_=T==="$"?s:/[%p]/.test(L)?a:"",ut=Bs[L],kn=/[defgprs%]/.test(L);P=P===void 0?6:/[gprs]/.test(L)?Math.max(1,Math.min(21,P)):Math.max(0,Math.min(20,P));function Me(E){var tt=v,I=_,at,Ye,wt;if(L==="c")I=ut(E)+I,E="";else{E=+E;var xt=E<0||1/E<0;if(E=isNaN(E)?c:ut(Math.abs(E),P),Y&&(E=Fo(E)),xt&&+E==0&&b!=="+"&&(xt=!1),tt=(xt?b==="("?b:l:b==="-"||b==="("?"":b)+tt,I=(L==="s"?Gs[8+hi/3]:"")+I+(xt&&b==="("?")":""),kn){for(at=-1,Ye=E.length;++at<Ye;)if(wt=E.charCodeAt(at),48>wt||wt>57){I=(wt===46?r+E.slice(at+1):E.slice(at))+I,E=E.slice(0,at);break}}}A&&!C&&(E=e(E,1/0));var bt=tt.length+E.length+I.length,j=bt<O?new Array(O-bt+1).join(m):"";switch(A&&C&&(E=e(j+E,j.length?O-I.length:1/0),j=""),x){case"<":E=tt+E+I+j;break;case"=":E=tt+j+E+I;break;case"^":E=j.slice(0,bt=j.length>>1)+tt+E+I+j.slice(bt);break;default:E=j+tt+E+I;break}return i(E)}return Me.toString=function(){return g+""},Me}function f(g,m){var x=h((g=nn(g),g.type="f",g)),b=Math.max(-8,Math.min(8,Math.floor(_t(m)/3)))*3,T=Math.pow(10,-b),C=Gs[8+b/3];return function(O){return x(T*O)+C}}return{format:h,formatPrefix:f}}var Le,di,fi;Ho({thousands:",",grouping:[3],currency:["$",""]});function Ho(n){return Le=jo(n),di=Le.format,fi=Le.formatPrefix,Le}function Wo(n){return Math.max(0,-_t(Math.abs(n)))}function Xo(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(_t(e)/3)))*3-_t(Math.abs(n)))}function Vo(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,_t(e)-_t(n))+1}function Ko(n,e,t,s){var r=Bn(n,e,t),i;switch(s=nn(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=Xo(r,a))&&(s.precision=i),fi(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=Vo(r,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=Wo(r))&&(s.precision=i-(s.type==="%")*2);break}}return di(s)}function Jo(n){var e=n.domain;return n.ticks=function(t){var s=e();return co(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var r=e();return Ko(r[0],r[r.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),r=0,i=s.length-1,a=s[r],l=s[i],c,h,f=10;for(l<a&&(h=a,a=l,l=h,h=r,r=i,i=h);f-- >0;){if(h=Zn(a,l,t),h===c)return s[r]=a,s[i]=l,e(s);if(h>0)a=Math.floor(a/h)*h,l=Math.ceil(l/h)*h;else if(h<0)a=Math.ceil(a*h)/h,l=Math.floor(l*h)/h;else break;c=h}return n},n}function pi(){var n=ui();return n.copy=function(){return ci(n,pi())},ri.apply(n,arguments),Jo(n)}function Qo(n,e){n=n.slice();var t=0,s=n.length-1,r=n[t],i=n[s],a;return i<r&&(a=t,t=s,s=a,a=r,r=i,i=a),n[t]=e.floor(r),n[s]=e.ceil(i),n}const Yn=new Date,Dn=new Date;function M(n,e,t,s){function r(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return r.floor=i=>(n(i=new Date(+i)),i),r.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),r.round=i=>{const a=r(i),l=r.ceil(i);return i-a<l-i?a:l},r.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),r.range=(i,a,l)=>{const c=[];if(i=r.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return c;let h;do c.push(h=new Date(+i)),e(i,l),n(i);while(h<i&&i<a);return c},r.filter=i=>M(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(r.count=(i,a)=>(Yn.setTime(+i),Dn.setTime(+a),n(Yn),n(Dn),Math.floor(t(Yn,Dn))),r.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?r.filter(s?a=>s(a)%i===0:a=>r.count(0,a)%i===0):r)),r}const sn=M(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);sn.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?M(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):sn);sn.range;const et=1e3,F=et*60,nt=F*60,st=nt*24,gs=st*7,js=st*30,An=st*365,St=M(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*et)},(n,e)=>(e-n)/et,n=>n.getUTCSeconds());St.range;const ms=M(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getMinutes());ms.range;const tl=M(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getUTCMinutes());tl.range;const ys=M(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et-n.getMinutes()*F)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getHours());ys.range;const el=M(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getUTCHours());el.range;const Oe=M(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*F)/st,n=>n.getDate()-1);Oe.range;const ws=M(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>n.getUTCDate()-1);ws.range;const nl=M(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>Math.floor(n/st));nl.range;function mt(n){return M(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*F)/gs)}const Rn=mt(0),rn=mt(1),sl=mt(2),rl=mt(3),qt=mt(4),il=mt(5),al=mt(6);Rn.range;rn.range;sl.range;rl.range;qt.range;il.range;al.range;function yt(n){return M(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/gs)}const gi=yt(0),an=yt(1),ol=yt(2),ll=yt(3),$t=yt(4),cl=yt(5),ul=yt(6);gi.range;an.range;ol.range;ll.range;$t.range;cl.range;ul.range;const xs=M(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());xs.range;const hl=M(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());hl.range;const rt=M(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());rt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:M(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});rt.range;const gt=M(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());gt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:M(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});gt.range;function dl(n,e,t,s,r,i){const a=[[St,1,et],[St,5,5*et],[St,15,15*et],[St,30,30*et],[i,1,F],[i,5,5*F],[i,15,15*F],[i,30,30*F],[r,1,nt],[r,3,3*nt],[r,6,6*nt],[r,12,12*nt],[s,1,st],[s,2,2*st],[t,1,gs],[e,1,js],[e,3,3*js],[n,1,An]];function l(h,f,g){const m=f<h;m&&([h,f]=[f,h]);const x=g&&typeof g.range=="function"?g:c(h,f,g),b=x?x.range(h,+f+1):[];return m?b.reverse():b}function c(h,f,g){const m=Math.abs(f-h)/g,x=us(([,,C])=>C).right(a,m);if(x===a.length)return n.every(Bn(h/An,f/An,g));if(x===0)return sn.every(Math.max(Bn(h,f,g),1));const[b,T]=a[m/a[x-1][2]<a[x][2]/m?x-1:x];return b.every(T)}return[l,c]}const[fl,pl]=dl(rt,xs,Rn,Oe,ys,ms);function Ln(n){if(0<=n.y&&n.y<100){var e=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return e.setFullYear(n.y),e}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function _n(n){if(0<=n.y&&n.y<100){var e=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return e.setUTCFullYear(n.y),e}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function jt(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function gl(n){var e=n.dateTime,t=n.date,s=n.time,r=n.periods,i=n.days,a=n.shortDays,l=n.months,c=n.shortMonths,h=Ht(r),f=Wt(r),g=Ht(i),m=Wt(i),x=Ht(a),b=Wt(a),T=Ht(l),C=Wt(l),O=Ht(c),A=Wt(c),P={a:xt,A:bt,b:j,B:sa,c:null,d:Js,e:Js,f:$l,g:Wl,G:Vl,H:Ll,I:_l,j:ql,L:mi,m:Il,M:Nl,p:ra,q:ia,Q:er,s:nr,S:Zl,u:Bl,U:Ul,V:Fl,w:Gl,W:jl,x:null,X:null,y:Hl,Y:Xl,Z:Kl,"%":tr},Y={a:aa,A:oa,b:la,B:ca,c:null,d:Qs,e:Qs,f:ec,g:hc,G:fc,H:Jl,I:Ql,j:tc,L:wi,m:nc,M:sc,p:ua,q:ha,Q:er,s:nr,S:rc,u:ic,U:ac,V:oc,w:lc,W:cc,x:null,X:null,y:uc,Y:dc,Z:pc,"%":tr},L={a:Me,A:E,b:tt,B:I,c:at,d:Vs,e:Vs,f:Ml,g:Xs,G:Ws,H:Ks,I:Ks,j:kl,L:zl,m:Rl,M:Pl,p:kn,q:Cl,Q:Dl,s:Al,S:Ol,u:bl,U:vl,V:Tl,w:xl,W:Sl,x:Ye,X:wt,y:Xs,Y:Ws,Z:El,"%":Yl};P.x=v(t,P),P.X=v(s,P),P.c=v(e,P),Y.x=v(t,Y),Y.X=v(s,Y),Y.c=v(e,Y);function v(w,S){return function(R){var y=[],N=-1,z=0,B=w.length,U,ht,Os;for(R instanceof Date||(R=new Date(+R));++N<B;)w.charCodeAt(N)===37&&(y.push(w.slice(z,N)),(ht=Hs[U=w.charAt(++N)])!=null?U=w.charAt(++N):ht=U==="e"?" ":"0",(Os=S[U])&&(U=Os(R,ht)),y.push(U),z=N+1);return y.push(w.slice(z,N)),y.join("")}}function _(w,S){return function(R){var y=jt(1900,void 0,1),N=ut(y,w,R+="",0),z,B;if(N!=R.length)return null;if("Q"in y)return new Date(y.Q);if("s"in y)return new Date(y.s*1e3+("L"in y?y.L:0));if(S&&!("Z"in y)&&(y.Z=0),"p"in y&&(y.H=y.H%12+y.p*12),y.m===void 0&&(y.m="q"in y?y.q:0),"V"in y){if(y.V<1||y.V>53)return null;"w"in y||(y.w=1),"Z"in y?(z=_n(jt(y.y,0,1)),B=z.getUTCDay(),z=B>4||B===0?an.ceil(z):an(z),z=ws.offset(z,(y.V-1)*7),y.y=z.getUTCFullYear(),y.m=z.getUTCMonth(),y.d=z.getUTCDate()+(y.w+6)%7):(z=Ln(jt(y.y,0,1)),B=z.getDay(),z=B>4||B===0?rn.ceil(z):rn(z),z=Oe.offset(z,(y.V-1)*7),y.y=z.getFullYear(),y.m=z.getMonth(),y.d=z.getDate()+(y.w+6)%7)}else("W"in y||"U"in y)&&("w"in y||(y.w="u"in y?y.u%7:"W"in y?1:0),B="Z"in y?_n(jt(y.y,0,1)).getUTCDay():Ln(jt(y.y,0,1)).getDay(),y.m=0,y.d="W"in y?(y.w+6)%7+y.W*7-(B+5)%7:y.w+y.U*7-(B+6)%7);return"Z"in y?(y.H+=y.Z/100|0,y.M+=y.Z%100,_n(y)):Ln(y)}}function ut(w,S,R,y){for(var N=0,z=S.length,B=R.length,U,ht;N<z;){if(y>=B)return-1;if(U=S.charCodeAt(N++),U===37){if(U=S.charAt(N++),ht=L[U in Hs?S.charAt(N++):U],!ht||(y=ht(w,R,y))<0)return-1}else if(U!=R.charCodeAt(y++))return-1}return y}function kn(w,S,R){var y=h.exec(S.slice(R));return y?(w.p=f.get(y[0].toLowerCase()),R+y[0].length):-1}function Me(w,S,R){var y=x.exec(S.slice(R));return y?(w.w=b.get(y[0].toLowerCase()),R+y[0].length):-1}function E(w,S,R){var y=g.exec(S.slice(R));return y?(w.w=m.get(y[0].toLowerCase()),R+y[0].length):-1}function tt(w,S,R){var y=O.exec(S.slice(R));return y?(w.m=A.get(y[0].toLowerCase()),R+y[0].length):-1}function I(w,S,R){var y=T.exec(S.slice(R));return y?(w.m=C.get(y[0].toLowerCase()),R+y[0].length):-1}function at(w,S,R){return ut(w,e,S,R)}function Ye(w,S,R){return ut(w,t,S,R)}function wt(w,S,R){return ut(w,s,S,R)}function xt(w){return a[w.getDay()]}function bt(w){return i[w.getDay()]}function j(w){return c[w.getMonth()]}function sa(w){return l[w.getMonth()]}function ra(w){return r[+(w.getHours()>=12)]}function ia(w){return 1+~~(w.getMonth()/3)}function aa(w){return a[w.getUTCDay()]}function oa(w){return i[w.getUTCDay()]}function la(w){return c[w.getUTCMonth()]}function ca(w){return l[w.getUTCMonth()]}function ua(w){return r[+(w.getUTCHours()>=12)]}function ha(w){return 1+~~(w.getUTCMonth()/3)}return{format:function(w){var S=v(w+="",P);return S.toString=function(){return w},S},parse:function(w){var S=_(w+="",!1);return S.toString=function(){return w},S},utcFormat:function(w){var S=v(w+="",Y);return S.toString=function(){return w},S},utcParse:function(w){var S=_(w+="",!0);return S.toString=function(){return w},S}}}var Hs={"-":"",_:" ",0:"0"},D=/^\s*\d+/,ml=/^%/,yl=/[\\^$*+?|[\]().{}]/g;function k(n,e,t){var s=n<0?"-":"",r=(s?-n:n)+"",i=r.length;return s+(i<t?new Array(t-i+1).join(e)+r:r)}function wl(n){return n.replace(yl,"\\$&")}function Ht(n){return new RegExp("^(?:"+n.map(wl).join("|")+")","i")}function Wt(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function xl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function bl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function vl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Tl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function Sl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Ws(n,e,t){var s=D.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Xs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function El(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function Cl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Rl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Vs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function kl(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Ks(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function Pl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Ol(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function zl(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Ml(n,e,t){var s=D.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Yl(n,e,t){var s=ml.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Dl(n,e,t){var s=D.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Al(n,e,t){var s=D.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Js(n,e){return k(n.getDate(),e,2)}function Ll(n,e){return k(n.getHours(),e,2)}function _l(n,e){return k(n.getHours()%12||12,e,2)}function ql(n,e){return k(1+Oe.count(rt(n),n),e,3)}function mi(n,e){return k(n.getMilliseconds(),e,3)}function $l(n,e){return mi(n,e)+"000"}function Il(n,e){return k(n.getMonth()+1,e,2)}function Nl(n,e){return k(n.getMinutes(),e,2)}function Zl(n,e){return k(n.getSeconds(),e,2)}function Bl(n){var e=n.getDay();return e===0?7:e}function Ul(n,e){return k(Rn.count(rt(n)-1,n),e,2)}function yi(n){var e=n.getDay();return e>=4||e===0?qt(n):qt.ceil(n)}function Fl(n,e){return n=yi(n),k(qt.count(rt(n),n)+(rt(n).getDay()===4),e,2)}function Gl(n){return n.getDay()}function jl(n,e){return k(rn.count(rt(n)-1,n),e,2)}function Hl(n,e){return k(n.getFullYear()%100,e,2)}function Wl(n,e){return n=yi(n),k(n.getFullYear()%100,e,2)}function Xl(n,e){return k(n.getFullYear()%1e4,e,4)}function Vl(n,e){var t=n.getDay();return n=t>=4||t===0?qt(n):qt.ceil(n),k(n.getFullYear()%1e4,e,4)}function Kl(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+k(e/60|0,"0",2)+k(e%60,"0",2)}function Qs(n,e){return k(n.getUTCDate(),e,2)}function Jl(n,e){return k(n.getUTCHours(),e,2)}function Ql(n,e){return k(n.getUTCHours()%12||12,e,2)}function tc(n,e){return k(1+ws.count(gt(n),n),e,3)}function wi(n,e){return k(n.getUTCMilliseconds(),e,3)}function ec(n,e){return wi(n,e)+"000"}function nc(n,e){return k(n.getUTCMonth()+1,e,2)}function sc(n,e){return k(n.getUTCMinutes(),e,2)}function rc(n,e){return k(n.getUTCSeconds(),e,2)}function ic(n){var e=n.getUTCDay();return e===0?7:e}function ac(n,e){return k(gi.count(gt(n)-1,n),e,2)}function xi(n){var e=n.getUTCDay();return e>=4||e===0?$t(n):$t.ceil(n)}function oc(n,e){return n=xi(n),k($t.count(gt(n),n)+(gt(n).getUTCDay()===4),e,2)}function lc(n){return n.getUTCDay()}function cc(n,e){return k(an.count(gt(n)-1,n),e,2)}function uc(n,e){return k(n.getUTCFullYear()%100,e,2)}function hc(n,e){return n=xi(n),k(n.getUTCFullYear()%100,e,2)}function dc(n,e){return k(n.getUTCFullYear()%1e4,e,4)}function fc(n,e){var t=n.getUTCDay();return n=t>=4||t===0?$t(n):$t.ceil(n),k(n.getUTCFullYear()%1e4,e,4)}function pc(){return"+0000"}function tr(){return"%"}function er(n){return+n}function nr(n){return Math.floor(+n/1e3)}var vt,bi;gc({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 gc(n){return vt=gl(n),bi=vt.format,vt.parse,vt.utcFormat,vt.utcParse,vt}function mc(n){return new Date(n)}function yc(n){return n instanceof Date?+n:+new Date(+n)}function vi(n,e,t,s,r,i,a,l,c,h){var f=ui(),g=f.invert,m=f.domain,x=h(".%L"),b=h(":%S"),T=h("%I:%M"),C=h("%I %p"),O=h("%a %d"),A=h("%b %d"),P=h("%B"),Y=h("%Y");function L(v){return(c(v)<v?x:l(v)<v?b:a(v)<v?T:i(v)<v?C:s(v)<v?r(v)<v?O:A:t(v)<v?P:Y)(v)}return f.invert=function(v){return new Date(g(v))},f.domain=function(v){return arguments.length?m(Array.from(v,yc)):m().map(mc)},f.ticks=function(v){var _=m();return n(_[0],_[_.length-1],v??10)},f.tickFormat=function(v,_){return _==null?L:h(_)},f.nice=function(v){var _=m();return(!v||typeof v.range!="function")&&(v=e(_[0],_[_.length-1],v??10)),v?m(Qo(_,v)):f},f.copy=function(){return ci(f,vi(n,e,t,s,r,i,a,l,c,h))},f}function wc(){return ri.apply(vi(fl,pl,rt,xs,Rn,Oe,ys,ms,St,bi).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const bs=p.z.enum(["linear","time"]),vs=p.z.object({tickSpacing:p.z.number().default(75),type:bs.optional().default("linear")}),Hn=n=>{const e=vs.parse(n);return vc[e.type](e)};class xc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[new d.m(e.pos(0)).date(),new d.m(e.pos(1)).date()],i=wc().domain(r).range(s);return i.ticks(Ti(t,this.props.tickSpacing)).map(l=>({label:this.tickLabel(l),position:i(l)}))}tickLabel(e){const t=new d.m(e).date();let s=`:${t.getSeconds()}`;if(t.getMilliseconds()!==0){const i=Math.round(t.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");s+=`.${i}`}return t.getSeconds()===0&&t.getMilliseconds()===0&&(s=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`),s}}class bc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[e.pos(0),e.pos(1)],i=pi().domain(r).range(s),a=Ti(t,this.props.tickSpacing);return i.ticks(a).map(c=>({label:this.tickLabel(c),position:i(c)}))}tickLabel(e){return e.toString()}}const Ti=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},vc={linear:n=>new bc(n),time:n=>new xc(n)},Ts=vs.extend({color:o.Color.z,type:bs.optional().default("linear"),font:p.z.string(),showGrid:p.z.boolean().optional().default(!0),location:o.J.outer,gridColor:o.Color.z}),V=4;let Si=class{constructor(e,t){u(this,"ctx");u(this,"state");u(this,"tickFactory");this.ctx=e,this.state=t,this.tickFactory=Hn(this.state)}setState(e){this.state=d.prettyParse(Ts,e),this.tickFactory=Hn(e)}render(e){const{lower2d:t}=this.ctx;switch(t.font=this.state.font,t.fillStyle=this.state.color.hex,t.lineWidth=1,this.state.location){case"left":return this.drawLeft(e);case"right":return this.drawRight(e);case"top":return this.drawTop(e);default:return this.drawBottom(e)}}drawBottom(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:-i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y+V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y+5+h.height)}).height+V+6}}drawTop(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=o.q.translate(e.position,"y",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y-V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y-5-h.height)}).height+V}}drawLeft(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=o.q.translate(e.position,"x",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x-V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x-h.width-V*2,a.y+f.position+h.height/3)}).width+V*2}}drawRight(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:-i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x+V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x+V+2,a.y+f.position+h.height/3)}).width+V*2}}drawLine(e,t){const{lower2d:s}=this.ctx;s.beginPath(),s.moveTo(...o.q.couple(e)),s.lineTo(...o.q.couple(t)),s.stroke()}drawTicks(e,t){let s=o._.ZERO;return e.forEach(r=>{const i=d.dimensions(r.label,this.state.font,this.ctx.lower2d);s=o._.max([s,i]),t(i,r)}),s}maybeDrawGrid(e,t,s){const{showGrid:r,gridColor:i}=this.state;if(r){const a=o.G.construct(-1,1),l=o.G.construct(e-1,e+1);this.ctx.lower2d.strokeStyle=i.hex,t.filter(({position:c})=>!o.G.contains(a,c)&&!o.G.contains(l,c)).forEach(c=>this.drawLine(...s(c)))}}};const Ie=(n,e)=>o.Eo.construct(o.Eo.left(n)-e.x,o.Eo.top(n)-e.y,o.Eo.width(n)+e.x*2,o.Eo.height(n)+e.y*2);class on{constructor(e,t=o.k$2.XY.IDENTITY){u(this,"scale_");u(this,"wrapped");this.wrapped=e,this.scale_=t}get fontStretch(){return this.wrapped.fontStretch}set fontStretch(e){this.wrapped.fontStretch=e}get fontVariantCaps(){return this.wrapped.fontVariantCaps}set fontVariantCaps(e){this.wrapped.fontVariantCaps=e}isContextLost(){return this.wrapped.isContextLost()}get wordSpacing(){return this.wrapped.wordSpacing}set wordSpacing(e){this.wrapped.wordSpacing=e}get letterSpacing(){return this.wrapped.letterSpacing}set letterSpacing(e){this.wrapped.letterSpacing=e}get textRendering(){return this.wrapped.textRendering}set textRendering(e){this.wrapped.textRendering=e}reset(){this.wrapped.reset()}applyScale(e){return new on(this,e)}get canvas(){return this.wrapped.canvas}get miterLimit(){return this.wrapped.miterLimit}set miterLimit(e){this.wrapped.miterLimit=this.scale_.x.dim(e)}get globalAlpha(){return this.wrapped.globalAlpha}set globalAlpha(e){this.wrapped.globalAlpha=e}get globalCompositeOperation(){return this.wrapped.globalCompositeOperation}set globalCompositeOperation(e){this.wrapped.globalCompositeOperation=e}get fillStyle(){return this.wrapped.fillStyle}set fillStyle(e){this.wrapped.fillStyle=e}get strokeStyle(){return this.wrapped.strokeStyle}set strokeStyle(e){this.wrapped.strokeStyle=e}drawImage(e,t,s,r,i,a,l,c,h){this.wrapped.drawImage(e,t,s,r,i,a,l,c,h)}beginPath(){this.wrapped.beginPath()}clip(e,t){this.wrapped.clip(e,t)}fill(e,t){if(e==null)return this.wrapped.fill();this.wrapped.fill(e,t)}isPointInPath(e,t,s,r){return this.wrapped.isPointInPath(e,t,s,r)}isPointInStroke(e,t,s){return this.wrapped.isPointInStroke(e,t,s)}stroke(e){if(e==null)return this.wrapped.stroke();this.wrapped.stroke(e)}createConicGradient(e,t,s){return this.wrapped.createConicGradient(e,t,s)}createLinearGradient(e,t,s,r){return this.wrapped.createLinearGradient(e,t,s,r)}createPattern(e,t){return this.wrapped.createPattern(e,t)}createRadialGradient(e,t,s,r,i,a){return this.wrapped.createRadialGradient(e,t,s,r,i,a)}get filter(){return this.wrapped.filter}set filter(e){this.wrapped.filter=e}createImageData(e,t,s){return this.wrapped.createImageData(e,t,s)}getImageData(e,t,s,r,i){return this.wrapped.getImageData(e,t,s,r,i)}putImageData(e,t,s,r,i,a,l){this.wrapped.putImageData(e,t,s,r,i,a,l)}get imageSmoothingEnabled(){return this.wrapped.imageSmoothingEnabled}set imageSmoothingEnabled(e){this.wrapped.imageSmoothingEnabled=e}get imageSmoothingQuality(){return this.wrapped.imageSmoothingQuality}set imageSmoothingQuality(e){this.wrapped.imageSmoothingQuality=e}arc(e,t,s,r,i,a){this.wrapped.arc(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),r,i,a)}arcTo(e,t,s,r,i){this.wrapped.arcTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.dim(i))}bezierCurveTo(e,t,s,r,i,a){this.wrapped.bezierCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.pos(i),this.scale_.y.pos(a))}closePath(){this.wrapped.closePath()}ellipse(e,t,s,r,i,a,l,c){this.wrapped.ellipse(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),i,a,l,c)}lineTo(e,t){this.wrapped.lineTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}moveTo(e,t){this.wrapped.moveTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}quadraticCurveTo(e,t,s,r){this.wrapped.quadraticCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r))}rect(e,t,s,r){this.wrapped.rect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}roundRect(e,t,s,r,i){this.wrapped.roundRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),typeof i=="number"?this.scale_.x.dim(i):i)}get lineCap(){return this.wrapped.lineCap}set lineCap(e){this.wrapped.lineCap=e}get lineDashOffset(){return this.wrapped.lineDashOffset}set lineDashOffset(e){this.wrapped.lineDashOffset=this.scale_.x.dim(e)}get lineJoin(){return this.wrapped.lineJoin}set lineJoin(e){this.wrapped.lineJoin=e}get lineWidth(){return this.wrapped.lineWidth}set lineWidth(e){this.wrapped.lineWidth=this.scale_.x.dim(e)}getLineDash(){return this.wrapped.getLineDash()}setLineDash(e){const t=Array.from(e).map(s=>this.scale_.x.dim(s));this.wrapped.setLineDash(t)}clearRect(e,t,s,r){this.wrapped.clearRect(e,t,s,r)}fillRect(e,t,s,r){this.wrapped.fillRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}strokeRect(e,t,s,r){this.wrapped.strokeRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}get shadowBlur(){return this.wrapped.shadowBlur}set shadowBlur(e){this.wrapped.shadowBlur=e}get shadowColor(){return this.wrapped.shadowColor}set shadowColor(e){this.wrapped.shadowColor=e}get shadowOffsetX(){return this.wrapped.shadowOffsetX}set shadowOffsetX(e){this.wrapped.shadowOffsetX=e}get shadowOffsetY(){return this.wrapped.shadowOffsetY}restore(){this.wrapped.restore()}save(){this.wrapped.save()}fillText(e,t,s,r){this.wrapped.fillText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}measureText(e){this.wrapped.font=qn(this.wrapped.font,this.scale_.x.reverse());const t=this.wrapped.measureText(e);return this.wrapped.font=qn(this.wrapped.font,this.scale_.x),t}strokeText(e,t,s,r){this.wrapped.strokeText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}get direction(){return this.wrapped.direction}set direction(e){this.wrapped.direction=e}get font(){return this.wrapped.font}set font(e){this.wrapped.font=qn(e,this.scale_.x)}get fontKerning(){return this.wrapped.fontKerning}set fontKerning(e){this.wrapped.fontKerning=e}get textAlign(){return this.wrapped.textAlign}set textAlign(e){this.wrapped.textAlign=e}get textBaseline(){return this.wrapped.textBaseline}set textBaseline(e){this.wrapped.textBaseline=e}getTransform(){return this.wrapped.getTransform()}resetTransform(){this.wrapped.resetTransform()}rotate(e){this.wrapped.rotate(e)}scale(e,t){this.wrapped.scale(e,t)}scissor(e,t=o.q.ZERO){const s=new Path2D;return e=Ie(e,t),s.rect(...o.q.couple(o.Eo.topLeft(e)),...o._.couple(o.Eo.dims(e))),this.save(),this.clip(s),()=>this.restore()}setTransform(e,t,s,r,i,a){this.wrapped.setTransform(e,t,s,r,i,a)}transform(e,t,s,r,i,a){this.wrapped.transform(e,t,s,r,i,a)}translate(e,t){this.wrapped.translate(e,t)}}const sr=/(\d+(\.\d+)?)px/,qn=(n,e)=>{var r;const t=Number((r=n.match(sr))==null?void 0:r[1]);if(t==null)return n;const s=e.dim(t);return n.replace(sr,`${s}px`)},Tc=`precision mediump float;
|
|
4
|
+
Make sure to define a method 'transform' on the class.`)}}class Or extends G{constructor(){super(...arguments);u(this,"sources",{})}async value(){const t=Object.fromEntries(await Promise.all(Object.entries(this.sources).map(async([s,r])=>[s,await r.value()])));return this.transform(t)}setSources(t){this.sources={...this.sources,...t}}transform(t){throw new d.B(`[MultiSourceTransformer] - expected subclass to define transform method, but none was found.
|
|
5
|
+
Make sure to define a method 'transform' on the class.`)}}class zr extends En{constructor(){super(...arguments);u(this,"sinks",{})}get sink(){const[t]=Object.values(this.sinks);if(t==null)throw new d.B("[UnarySinkTransformer] - expected sink to exist, but none was found.");return t}async set(t){return await this.sink.set(this.transform(t))}setSinks(t){this.sinks={...this.sinks,...t}}transform(t){throw new d.B(`[UnarySinkTransformer] - expected subclass to define transform method, but none was found.
|
|
6
|
+
Make sure to define a method 'transform' on the class.`)}}const Mr=p.z.object({from:p.z.string(),to:p.z.string()}),ns=p.z.object({connections:p.z.array(Mr),outlet:p.z.string(),segments:p.z.record(ct)});class Yr{constructor(e){u(this,"type","pipeline");u(this,"factory");this.factory=e}create(e){switch(e.type){case se.TYPE:return new se(e.props,this.factory);case re.TYPE:return new re(e.props,this.factory);default:return null}}}class se extends G{constructor(t,s){super(t);u(this,"schema",ns);u(this,"sources",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sources[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sources[a],h=this.sources[l];c==null||h==null||"setSources"in h&&h.setSources({[a]:c})})}get outlet(){const{outlet:t}=this.props,s=this.sources[t];if(s==null)throw new d.B(`[SourcePipeline] - expected source to exist at outlet '${t}', but none was found.`);return s}async value(){return await this.outlet.value()}onChange(t){return this.outlet.onChange(t)}async cleanup(){await Promise.all(Object.values(this.sources).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(se,"TYPE","source-pipeline");const Dr=(n,e)=>({variant:"source",props:e,type:se.TYPE,valueType:n}),ss=p.z.object({connections:p.z.array(Mr),inlet:p.z.string(),segments:p.z.record(Tn)});class re extends Cn{constructor(t,s){super(t);u(this,"schema",ss);u(this,"sinks",{});const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,l])=>{const c=s.create(l);c!=null&&(this.sinks[a]=c)}),r.forEach(({from:a,to:l})=>{const c=this.sinks[a],h=this.sinks[l];c==null||h==null||"setSinks"in c&&c.setSinks({[l]:h})})}get inlet(){const{inlet:t}=this.props,s=this.sinks[t];if(s==null)throw new d.B(`[SinkPipeline] - expected source to exist at inlet '${t}', but none was found.`);return s}async set(t){return await this.inlet.set(t)}async cleanup(){await Promise.all(Object.values(this.sinks).map(async t=>{var s;return await((s=t.cleanup)==null?void 0:s.call(t))}))}}u(re,"TYPE","sink-pipeline");const Ar=(n,e)=>({variant:"sink",props:e,type:re.TYPE,valueType:n}),rs=p.z.object({channel:p.z.number().or(p.z.string())});class ie extends G{constructor(t,s){super(s);u(this,"client");u(this,"removeStreamHandler",null);u(this,"channelKey",0);u(this,"schema",rs);u(this,"leadingBuffer",null);u(this,"valid",!1);this.client=t}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}async cleanup(){var t,s;await((t=this.removeStreamHandler)==null?void 0:t.call(this)),this.valid=!1,(s=this.leadingBuffer)==null||s.release(),this.leadingBuffer=null,this.removeStreamHandler=null}async value(){return d.w$1(this.props.channel)||(this.channelKey===0&&(this.channelKey=(await is(this.client,this.props.channel,!1)).key),this.valid||await this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0)?0:this.leadingBuffer.at(-1,!0)}async read(){this.valid=!0,await this.updateStreamHandler()}async updateStreamHandler(){var s;await((s=this.removeStreamHandler)==null?void 0:s.call(this));const t=r=>{var l;const a=r[this.channelKey].data;if(a.length!==0){const c=a[a.length-1];c.acquire(),(l=this.leadingBuffer)==null||l.release(),this.leadingBuffer=c}this.notify()};this.removeStreamHandler=await this.client.stream(t,[this.channelKey])}}u(ie,"TYPE","stream-channel-value");const is=async(n,e,t)=>{const s=await n.retrieveChannel(e);return!t||s.isIndex?{key:s.key,dataType:s.dataType,virtual:s.virtual}:{key:s.index,dataType:d.g.TIMESTAMP,virtual:!1}},Ca=p.z.object({timeRange:d.E.z,channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1)});class ae extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"valid",!1);u(this,"schema",Ca);this.client=t}async cleanup(){this.data.forEach(t=>t.release()),this.valid=!1}async value(){const{timeRange:t,channel:s,useIndexOfChannel:r}=this.props;if(t.isZero||s===0)return[o.G.ZERO,[]];const i=await is(this.client,s,r);this.valid||await this.readFixed(i.key);let a=o.G.max(this.data.map(l=>l.bounds));return i.dataType.equals(d.g.TIMESTAMP)&&(a={upper:Math.min(a.upper,Number(this.props.timeRange.end.valueOf())),lower:Math.max(a.lower,Number(this.props.timeRange.start.valueOf()))}),[a,this.data]}async readFixed(t){const r=(await this.client.read(this.props.timeRange,[t]))[t].data;r.forEach(i=>i.acquire()),this.data=r,this.valid=!0}}u(ae,"TYPE","series-source");const Ra=p.z.object({channel:p.z.number().or(p.z.string()),useIndexOfChannel:p.z.boolean().optional().default(!1),timeSpan:d.y.z,keepFor:d.y.z.optional()});class oe extends G{constructor(t,s){super(s);u(this,"client");u(this,"data",[]);u(this,"stopStreaming");u(this,"valid",!1);u(this,"schema",Ra);this.client=t}async value(){const{channel:t,useIndexOfChannel:s,timeSpan:r}=this.props;if(t===0)return[o.G.ZERO,[]];const i=d.m.now(),a=await is(this.client,t,s);if(this.valid||await this.read(a),a.dataType.isVariable)return[o.G.ZERO,this.data];let l=o.G.max(this.data.filter(c=>c.timeRange.end.after(i.sub(r))).map(c=>c.bounds));return a.dataType.equals(d.g.TIMESTAMP)&&(l={upper:l.upper,lower:Math.max(l.lower,l.upper-Number(r.valueOf()))}),[l,this.data]}async read({key:t,virtual:s}){const r=d.m.now().spanRange(-this.props.timeSpan);if(!s){const a=(await this.client.read(r,[t]))[t].data;a.forEach(l=>l.acquire()),this.data.push(...a)}await this.updateStreamHandler(t),this.valid=!0}async updateStreamHandler(t){this.stopStreaming!=null&&await this.stopStreaming();const s=r=>{const i=r[t].data;i.forEach(a=>a.acquire()),this.data.push(...i),this.gcOutOfRangeData(),this.notify()};this.stopStreaming=await this.client.stream(s,[t])}gcOutOfRangeData(){const t=d.m.now().sub(this.props.keepFor??this.props.timeSpan),s=this.data.findIndex(r=>r.timeRange.end.before(t));s!==-1&&(this.data.splice(s,1).forEach(r=>r.release()),this.gcOutOfRangeData())}async cleanup(){var t;await((t=this.stopStreaming)==null?void 0:t.call(this)),this.stopStreaming=void 0,this.data.forEach(s=>s.release())}}u(oe,"TYPE","dynamic-series-source");const ka={[ae.TYPE]:ae,[oe.TYPE]:oe,[ie.TYPE]:ie};class Lr{constructor(e){u(this,"type","remote");u(this,"client");this.client=e}create(e){const t=ka[e.type];return t==null?null:new t(this.client,e.props)}}const _r=n=>({type:ae.TYPE,props:n,variant:"source",valueType:"series"}),qr=n=>({type:oe.TYPE,props:n,variant:"source",valueType:"series"}),$r=n=>({type:ie.TYPE,props:n,variant:"source",valueType:"number"});class Ir{constructor(){u(this,"type","static")}create(e){switch(e.type){case Ve.TYPE:return new Ve(e.props);case le.TYPE:return new le(e.props);case ce.TYPE:return new ce(e.props);case ue.TYPE:return new ue(e.props);default:return null}}}const as=p.z.object({data:p.z.array(d.xt),offsets:p.z.array(p.z.number()).optional().default([])});class Ve extends G{constructor(t){super(t);u(this,"data");u(this,"schema",as);this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){return[o.G.max(this.data.map(s=>s.bounds)),this.data]}}u(Ve,"TYPE","static-series");const Nr=as.extend({rate:d.P.z,yOffset:p.z.number().optional().default(0),scroll:p.z.number().optional().default(0),startPosition:p.z.number().optional().default(0),scrollBounds:p.z.boolean().optional().default(!1)});class le extends G{constructor(t){super(t);u(this,"schema",Nr);u(this,"position");u(this,"interval");u(this,"data");this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((s,r)=>new d.V({data:s,dataType:d.g.FLOAT32,timeRange:d.E.ZERO,sampleOffset:this.props.offsets[r]??0}))}async value(){const t=this.data.map(r=>r.slice(0,this.position));if(this.props.scrollBounds){const r=t[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=t[0].data[this.position-1];return[{lower:Number(r),upper:Number(i)},t]}return[o.G.max(t.map(r=>r.bounds)),t]}start(t){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{var s;(s=this.notify)==null||s.call(this),this.position++},t.period.milliseconds)}async cleanup(){clearInterval(this.interval),this.interval=void 0}}u(le,"TYPE","iterative-series");const Zr=p.z.number();class ce extends G{constructor(){super(...arguments);u(this,"schema",Zr)}async value(){return this.props}}u(ce,"TYPE","static-numeric");const Br=p.z.string();class ue extends G{constructor(){super(...arguments);u(this,"schema",Br)}async value(){return this.props}}u(ue,"TYPE","static-string");const Pa=n=>({type:Ve.TYPE,props:n,variant:"source",valueType:"series"}),Oa=n=>({type:le.TYPE,props:n,variant:"source",valueType:"series"}),za=n=>({type:ce.TYPE,props:n,variant:"source",valueType:"number"}),Ma=n=>({type:ue.TYPE,props:n,variant:"source",valueType:"string"}),Ya=["standard","scientific","engineering"],Ur=p.z.enum(Ya),Da=(n,e,t)=>{if(Number.isNaN(n))return"NaN";if(n===1/0)return"∞";if(n===-1/0)return"-∞";if(t==="standard")return n.toFixed(e);if(n===0)return e===0?"0ᴇ0":`0.${"0".repeat(e)}ᴇ0`;let s;return t==="scientific"?s=Math.floor(Math.log10(Math.abs(n))):s=Math.floor(Math.log10(Math.abs(n))/3)*3,`${(n/10**s).toFixed(e)}ᴇ${s}`};class Fr{constructor(){u(this,"type","transformer")}create(e){switch(e.type){case Pt.TYPE:return new Pt(e.props);case Ot.TYPE:return new Ot(e.props);case zt.TYPE:return new zt(e.props);case Mt.TYPE:return new Mt(e.props);case Yt.TYPE:return new Yt(e.props);case Dt.TYPE:return new Dt(e.props)}return null}}const Aa=p.z.object({truthy:p.z.number().optional().default(1),falsy:p.z.number().optional().default(0)}),Gr=n=>({props:n,type:Pt.TYPE,variant:"sink",valueType:"boolean"}),Vt=class Vt extends zr{constructor(){super(...arguments);u(this,"schema",Vt.propsZ)}transform(t){return t?this.props.truthy:this.props.falsy}};u(Vt,"TYPE","boolean-numeric-converter-sink"),u(Vt,"propsZ",Aa);let Pt=Vt;const La=p.z.object({trueBound:o.G.bounds}),jr=n=>({props:n,type:Ot.TYPE,variant:"source",valueType:"boolean"}),Kt=class Kt extends Re{constructor(){super(...arguments);u(this,"schema",Kt.propsZ);u(this,"curr",null)}shouldNotify(t){const s=o.G.contains(this.props.trueBound,t)!==this.curr;return this.curr=o.G.contains(this.props.trueBound,t),s}transform(t){return this.curr=o.G.contains(this.props.trueBound,t),this.curr}};u(Kt,"TYPE","boolean-source"),u(Kt,"propsZ",La);let Ot=Kt;const Hr=p.z.object({}),Jt=class Jt extends Or{constructor(){super(...arguments);u(this,"schema",Jt.propsZ)}transform(t){return Object.values(t).reduce((s,r)=>s+r,0)/Object.keys(t).length}};u(Jt,"TYPE","mean"),u(Jt,"propsZ",Hr);let zt=Jt;const _a=n=>({props:n,type:zt.TYPE,variant:"source",valueType:"boolean"}),Wr=p.z.object({trueVariant:d.variantZ.optional().default("success")}),Qt=class Qt extends Re{constructor(){super(...arguments);u(this,"schema",Qt.propsZ)}transform(t){return t.variant===this.props.trueVariant}};u(Qt,"TYPE","boolean-status"),u(Qt,"propsZ",Wr);let Mt=Qt;const qa=n=>({props:n,type:Mt.TYPE,variant:"source",valueType:"boolean"}),os=p.z.object({precision:p.z.number().optional().default(2),prefix:p.z.string().optional().default(""),suffix:p.z.string().optional().default(""),notation:Ur.optional().default("standard")}),te=class te extends Re{constructor(){super(...arguments);u(this,"schema",te.propsZ)}transform(t){return`${this.props.prefix}${Da(t,this.props.precision,this.props.notation)}${this.props.suffix}`}};u(te,"TYPE","stringify-number"),u(te,"propsZ",os);let Yt=te;const Xr=n=>({props:n,type:Yt.TYPE,variant:"source",valueType:"string"}),ls=p.z.object({windowSize:p.z.number().optional().default(5)});class Dt extends Re{constructor(){super(...arguments);u(this,"schema",ls);u(this,"values",[])}transform(t){return this.props.windowSize<2?t:this.values.reduce((s,r)=>s+r,0)/this.values.length}shouldNotify(t){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(t),this.values.length===this.props.windowSize)}}u(Dt,"TYPE","rolling-average"),u(Dt,"propsZ",Hr);const Vr=n=>({props:n,type:Dt.TYPE,variant:"source",valueType:"number"});class Kr{constructor(e){u(this,"factories");u(this,"type","compound");this.factories=e}add(e){this.factories=[...this.factories.filter(t=>t.type!==e.type),e]}create(e){for(const t of this.factories){const s=t.create(e);if(s!=null)return s}return null}}const Jr=n=>{const e=[new Fr,new Ir,new Tr],t=new Kr(e);return n!=null&&t.add(new Lr(n)),t.add(new Yr(t)),t},Qr=p.z.object({include:p.z.string().array().optional(),exclude:p.z.string().array().optional(),level:p.z.enum(d.g$1.LOG_LEVELS).optional().default("info")}),In="alamos-provider";var $n;let Nn=($n=class extends d.Composite{constructor(){super(...arguments);u(this,"schema",Qr)}async afterUpdate(){if(this.ctx.getOptional(In)!=null)return;const s=[],{include:r,exclude:i,level:a}=this.state;(r!=null||i!=null)&&s.push(d.g$1.logLevelKeyFiler({include:r,exclude:i})),a!=null&&s.push(d.g$1.logThresholdFilter(a)),s.length===0&&s.push(()=>!1),this.internal.ins=new d.g$1.Instrumentation({key:"aether",logger:new d.g$1.Logger({filters:s})}),this.ctx.set(In,this.internal.ins)}},u($n,"TYPE","AlamosProvider"),$n);const ke=(n,e)=>{const t=n.get(In);if(t==null)throw new Error("No instrumentation provider");return e==null?t:t.child(e)},$a={[Nn.TYPE]:Nn},ti=(n,e)=>n.dataType.isVariable?n:(e==null&&n.dataType.equals(d.g.TIMESTAMP)&&(e=BigInt(n.data[0])),n.convert(d.g.FLOAT32,e)),ei=()=>({purgedSeries:0,purgedBytes:d.x.bytes(0)}),ni={instrumentation:d.g$1.NOOP,staleEntryThreshold:d.y.seconds(20)};class Ia{constructor(e){u(this,"data",[]);u(this,"props");this.props={...ni,...e}}write(e){e.length!==0&&(e.forEach(t=>this.writeOne(ti(t))),this.checkIntegrity(e))}dirtyRead(e){const t=this.data.filter(({data:a})=>a.timeRange.overlapsWith(e)).map(({data:a})=>a);if(t.length===0)return{series:[],gaps:[e]};const s=t.map((a,l)=>l===0?d.E.ZERO:new d.E(t[l-1].timeRange.end,a.timeRange.start)).filter(a=>!a.isZero&&a.isValid),r=new d.E(e.start,t[0].timeRange.start),i=new d.E(t[t.length-1].timeRange.end,e.end);return r.isValid&&!r.isZero&&s.unshift(r),i.isValid&&!i.isZero&&s.push(i),{series:t,gaps:s}}gc(){const{staleEntryThreshold:e}=this.props,t=ei(),s=this.data.filter(r=>{const i=r.data.refCount>0||d.m.since(r.addedAt).lessThan(e);return i||(t.purgedBytes=t.purgedBytes.add(r.data.byteCapacity)),i});return t.purgedSeries=this.data.length-s.length,this.data=s,t}close(){this.data=[]}writeOne(e){const{instrumentation:{L:t}}=this.props;if(e.length===0)return;const s=o.G.buildInsertionPlan(this.data.map(c=>c.data.alignmentBounds),e.alignmentBounds);if(s===null)return t.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(c=>c.data.digest)});const{removeBefore:r,removeAfter:i,insertInto:a,deleteInBetween:l}=s;e=e.slice(r,e.data.length-Number(i)),e.length!==0&&this.data.splice(a,l,{data:e,addedAt:d.m.now()})}checkIntegrity(e){const{instrumentation:{L:t}}=this.props,s=this.data.map(i=>i.data.alignmentBounds);if(s.some((i,a)=>s.some((l,c)=>a===c?!1:o.G.overlapsWith(i,l))))throw t.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.map(i=>i.digest),cacheContents:this.data.map(i=>i.data.digest)})),new Error("Invalid state")}}const Na=100,Za=1e6,Ba=1e4,Ua=100,Fa=40;class Ga{constructor(e){u(this,"props");u(this,"counter",0);u(this,"curr");u(this,"avgRate",0);u(this,"timeOfLastWrite");u(this,"totalWrites",0);u(this,"now",()=>d.m.now());this.props=e,this.curr=null,e.testingNow!=null&&(this.now=e.testingNow),this.timeOfLastWrite=this.now()}get length(){var e;return((e=this.curr)==null?void 0:e.length)??0}get leadingBuffer(){return this.curr}write(e){const t=e.flatMap(s=>this._write(s));return{flushed:t.flatMap(s=>s.flushed),allocated:t.flatMap(s=>s.allocated)}}allocate(e,t,s){this.counter++;const r=this.props.dataType.isVariable,i=this.props.dataType.equals(d.g.TIMESTAMP);return d.V.alloc({capacity:r?e*Fa:e,dataType:r?this.props.dataType:d.g.FLOAT32,timeRange:s.range(d.m.MAX),sampleOffset:i?BigInt(s.valueOf()):0,glBufferUsage:"dynamic",alignment:t,key:`dynamic-${this.counter}`})}_write(e){const t=this.nextBufferSize(),s={flushed:[],allocated:[]};if(this.curr==null)this.curr=this.allocate(t,e.alignment,this.now()),s.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-e.alignment))>1){const c=this.now();this.curr.timeRange.end=c,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment,c),s.allocated.push(this.curr)}const r=ti(e,this.curr.sampleOffset),i=this.curr.write(r);if(i===e.length)return this.updateAvgRate(e),s;const a=this.now();this.curr.timeRange.end=a,s.flushed.push(this.curr),this.curr=this.allocate(t,e.alignment+BigInt(i),a),s.allocated.push(this.curr);const l=this._write(e.slice(i));return s.flushed.push(...l.flushed),s.allocated.push(...l.allocated),s}updateAvgRate(e){if(typeof this.props.dynamicBufferSize=="number")return;const t=e.length/this.now().span(this.timeOfLastWrite).seconds;this.totalWrites>0&&isFinite(t)&&t>0&&(this.avgRate=(this.avgRate*(this.totalWrites-1)+t)/this.totalWrites),this.totalWrites++,this.timeOfLastWrite=this.now()}nextBufferSize(){const{dynamicBufferSize:e}=this.props;if(typeof e=="number")return e;if(this.totalWrites<Ua)return Ba;const t=o.W.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(t,Za),Na))}close(){this.curr=null}}class ja{constructor(e){u(this,"channel");u(this,"closed",!1);u(this,"ins");u(this,"static");u(this,"dynamic");this.channel=e.channel,this.ins=e.instrumentation??d.g$1.NOOP,this.static=new Ia(e),this.dynamic=new Ga({dynamicBufferSize:e.dynamicBufferSize,dataType:this.channel.dataType})}writeDynamic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted dynamic write to a closed cache for channel ${this.channel.name}`),[];const{flushed:t,allocated:s}=this.dynamic.write(e);return t.length>0&&this.static.write(t),s}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(e)}read(e){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:[],gaps:[]}):this.static.dirtyRead(e)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:d.x.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const Ha=d.k.seconds(60);class Wa{constructor(e){u(this,"props");u(this,"cache",new Map);u(this,"gcInterval");this.props={dynamicBufferSize:Ha,gcInterval:d.k.seconds(30),...ni,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:t,channelRetriever:s,dynamicBufferSize:r}=this.props,i=[];for(const l of e)this.cache.has(l)||i.push(l);if(i.length===0)return;const a=await s.retrieve(i);for(const l of a){const c=new ja({channel:l,dynamicBufferSize:r,instrumentation:t.child(`cache-${l.name}-${l.key}`)});this.cache.has(l.key)||this.cache.set(l.key,c)}}get(e){const t=this.cache.get(e);if(t!=null)return t;throw new d.Ce(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const t=ei();this.cache.forEach(s=>{const r=s.gc();t.purgedSeries+=r.purgedSeries,t.purgedBytes=t.purgedBytes.add(r.purgedBytes)}),e.info("garbage collection complete",{purgedSeries:t.purgedSeries,purgedBytes:t.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(e=>e.close()),this.cache.clear()}}class Ke{constructor(e,t){u(this,"channel");u(this,"data");this.channel=e,this.data=t}get timeRange(){if(this.data.length===0)return d.V$1.ZERO;const e=this.data[0].timeRange,t=this.data[this.data.length-1].timeRange;return new d.V$1(e.start,t.end)}get digest(){return{channel:this.channel.key,timeRange:this.timeRange.toPrettyString(),series:this.data.map(e=>e.digest)}}}const On=n=>n.map(e=>e.digest);class Xa{constructor(e){u(this,"props");u(this,"debouncedRead");u(this,"guarded",{mu:new d.Mutex,requests:new Map});this.props={instrumentation:d.g$1.NOOP,batchDebounce:d.y.milliseconds(50),...e},this.debouncedRead=d.o(()=>{this.batchRead()},this.props.batchDebounce.milliseconds)}async read(e,t){const{instrumentation:{L:s},cache:r}=this.props;s.debug("starting read",{tr:e.toPrettyString(),channels:t});const i=performance.now(),a=new Map,l={};await r.populateMissing(t);try{for(const f of t){const g=r.get(f),{series:m,gaps:x}=g.read(e);x.length===0&&(l[f]=new Ke(g.channel,m)),x.forEach(b=>{const T=a.get(b.toString());T==null?a.set(b.toString(),[b,new Set([f])]):a.set(b.toString(),[b,new Set([...T[1],f])])})}if(a.size===0)return s.debug("read satisfied by cache",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l;s.debug("read cache miss",()=>({tr:e.toPrettyString(),channels:t,toFetch:Array.from(a.values()).map(([f,g])=>({timeRange:f.toPrettyString(),channels:g})),responses:On(Object.values(l))}));const{mu:c,requests:h}=this.guarded;for(const[,[f,g]]of a)await new Promise((m,x)=>{c.runExclusive(async()=>{h.set([f,g],{resolve:m,reject:x}),this.debouncedRead()})})}catch(c){throw s.error("read failed",{tr:e.toPrettyString(),channels:t,error:c}),c}for(const c of t){const h=r.get(c),{series:f}=h.read(e);l[c]=new Ke(h.channel,f)}return s.debug("read satisfied by fetch",()=>({tr:e.toPrettyString(),channels:t,responses:On(Object.values(l)),time:d.y.milliseconds(performance.now()-i).toString()})),l}async batchRead(){const{instrumentation:{L:e},readRemote:t,cache:s}=this.props,{mu:r,requests:i}=this.guarded;await r.runExclusive(async()=>{const a=[];try{i.forEach((l,c)=>{const[h,f]=c,g=a.find(([m])=>m.start.span(h.start).lessThan(d.y.milliseconds(5))&&m.end.span(h.end).lessThan(d.y.milliseconds(5)));g==null?a.push([h,f]):g[1]=new Set([...g[1],...f])}),e.debug("batch read",{toFetch:a.map(([l,c])=>({timeRange:l.toPrettyString(),channels:c}))});for(const[l,c]of a){const h=Array.from(c),f=await t(l,h);h.forEach(g=>{const m=s.get(g),x=f.get(g);m.writeStatic(x.series)})}i.forEach(l=>l.resolve())}catch(l){e.error("batch read failed",{error:l},!0),i.forEach(c=>c.reject(l))}finally{i.clear()}})}}class Va{constructor(e){u(this,"props");u(this,"mu",new d.Mutex);u(this,"listeners",new Map);u(this,"streamerRunLoop",null);u(this,"streamer",null);u(this,"closed",!1);this.props={instrumentation:d.g$1.NOOP,...e}}async stream(e,t){const{cache:s,instrumentation:{L:r}}=this.props;return await s.populateMissing(t),await this.mu.runExclusive(async()=>{r.debug("adding stream handler",{keys:t}),this.listeners.set(e,{valid:!0,keys:t});const i={};for(const a of t){const l=s.get(a),c=l.leadingBuffer!=null?[l.leadingBuffer]:[];i[a]=new Ke(l.channel,c)}return e(i),await this.updateStreamer(),async()=>await this.removeStreamHandler(e)})}async removeStreamHandler(e){const{instrumentation:{L:t}}=this.props;await this.mu.runExclusive(()=>{const s=this.listeners.get(e);s!=null&&(s.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(t.debug("removing stream handler"),this.listeners.delete(e))return await this.updateStreamer();t.warn("attempted to remove non-existent stream handler")})},5e3)}async updateStreamer(){var i,a;if(this.closed)return;const{instrumentation:{L:e},core:t}=this.props,s=new Set;if(this.listeners.forEach(l=>l.keys.forEach(c=>s.add(c))),s.size===0){e.info("no keys to stream, closing streamer"),(i=this.streamer)==null||i.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.info("streamer closed successfully");return}const r=Array.from(s);if(d.F.primitiveArrays(r,((a=this.streamer)==null?void 0:a.keys)??[])===d.F.EQUAL){e.debug("streamer keys unchanged",{keys:r});return}this.streamer==null&&(e.info("creating new streamer",{keys:r}),this.streamer=await t.openStreamer(r),this.streamerRunLoop=this.runStreamer(this.streamer)),e.debug("updating streamer",{prev:this.streamer.keys,next:r});try{await this.streamer.update(r)}catch(l){throw e.error("failed to update streamer",{error:l}),l}}async runStreamer(e){const{cache:t,instrumentation:{L:s}}=this.props;try{for await(const r of e){const i=[];for(const a of r.keys){const l=r.get(a),c=t.get(a),h=c.writeDynamic(l.series);i.push(new Ke(c.channel,h))}this.listeners.forEach((a,l)=>{if(!a.valid)return;const c=i.filter(f=>a.keys.includes(f.channel.key));if(c.length===0)return;const h=Object.fromEntries(c.map(f=>[f.channel.key,f]));l(h)})}}catch(r){throw s.error("streamer run loop failed",{error:r},!0),r}}async close(){var e;(e=this.streamer)==null||e.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.closed=!0}}class Ka{constructor(){u(this,"key",d.Rt.id());u(this,"_client",null)}async swap(e){var t;this.key=d.Rt.id(),await((t=this._client)==null?void 0:t.close()),this._client=e}async retrieveChannel(e){return await this.client.retrieveChannel(e)}async read(e,t){return await this.client.read(e,t)}async stream(e,t){return await this.client.stream(e,t)}async close(){await this.client.close()}get client(){if(this._client==null)throw new d.re("No cluster has been connected");return this._client}}class Ja{constructor({instrumentation:e,core:t}){u(this,"key",d.Rt.id());u(this,"ins");u(this,"cache");u(this,"reader");u(this,"streamer");u(this,"channelRetriever");this.ins=e??d.g$1.NOOP,this.channelRetriever=t.channels.createDebouncedBatchRetriever(10),this.cache=new Wa({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new Xa({cache:this.cache,readRemote:async(s,r)=>await t.read(s,r),instrumentation:this.ins.child("reader")}),this.streamer=new Va({cache:this.cache,core:t,instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const t=await this.channelRetriever.retrieve([e]);if(t.length===0)throw new d.re(`channel ${e} not found`);return t[0]}async read(e,t){return await this.reader.read(e,t)}async stream(e,t){return await this.streamer.stream(e,t)}async close(){this.ins.L.info("closing client",{key:this.key}),await this.streamer.close(),this.cache.close()}}const cs=p.z.object({}),Et=class Et extends d.Composite{constructor(){super(...arguments);u(this,"client",new Ka);u(this,"factory",Jr(this.client));u(this,"schema",Et.stateZ);u(this,"prevClient",null)}create(t){const{instrumentation:s}=this.internal;s.L.debug("creating telem",{spec:t});const r=this.factory.create(t);if(r==null)throw new d.Ce(`Telemetry service could not find a source for type ${t.type}`);return r}get clusterKey(){return this.client.key}registerFactory(t){this.factory.add(t)}equals(t){return t instanceof Et?this.client._client===t.client._client:!1}async afterUpdate(){const t=Se(this.ctx),s=ke(this.ctx,"telem");this.internal.instrumentation=s.child("provider"),t!==this.prevClient&&(s.L.info("swapping client",{client:t}),t==null?await this.client.swap(null):await this.client.swap(new Ja({core:t,instrumentation:s})),this.prevClient=t,gr(this.ctx,this))}};u(Et,"TYPE","TelemProvider"),u(Et,"stateZ",cs);let At=Et;const si={[At.TYPE]:At},Qa=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:Cn,AbstractSource:G,Base:En,BaseProvider:At,BooleanStatus:Mt,ChannelData:ae,CompoundTelemFactory:Kr,FixedNumber:ce,FixedString:ue,IterativeSeries:le,Mean:zt,MultiSourceTransformer:Or,NoopFactory:Tr,PipelineFactory:Yr,REGISTRY:si,RemoteFactory:Lr,RollingAverage:Dt,SetPoint:Pt,SinkPipeline:re,SourcePipeline:se,StaticFactory:Ir,StreamChannelData:oe,StreamChannelValue:ie,StringifyNumber:Yt,TransformerFactory:Fr,UnarySinkTransformer:zr,UnarySourceTransformer:Re,WithinBounds:Ot,booleanSinkSpecZ:Sn,booleanSinkTransformerSpecZ:Sa,booleanSourceSpecZ:ts,booleanSourceTransformerSpecZ:Ea,booleanStatus:qa,booleanStatusProps:Wr,channelData:_r,colorSourceSpecZ:kr,factory:Jr,fixedArray:Pa,fixedNumber:za,fixedNumberPropsZ:Zr,fixedSeriesPropsZ:as,fixedString:Ma,fixedStringPropsZ:Br,iterativeArray:Oa,iterativeSeriesPropsZ:Nr,mean:_a,noopBooleanSinkSpec:vn,noopBooleanSourceSpec:Jn,noopColorSourceSpec:br,noopNumericSinkSpec:yr,noopNumericSourceSpec:wr,noopSeriesSourceSpec:vr,noopStatusSourceSpec:Qn,noopStringSourceSpec:xr,numberSinkSpecZ:Rr,numberSourceSpecZ:Cr,providerStateZ:cs,registerFactory:mr,rollingAverage:Vr,rollingAverageProps:ls,seriesSourceSpecZ:Xe,setProvider:gr,setpoint:Gr,sinkPipeline:Ar,sinkPipelinePropsZ:ss,sinkSpecZ:Tn,sinkTransformerSpecZ:Er,sourcePipeline:Dr,sourcePipelinePropsZ:ns,sourceSpecZ:ct,sourceTransformerSpecZ:Sr,specZ:Ce,statusSourceSpecZ:es,streamChannelData:qr,streamChannelValue:$r,streamChannelValuePropsZ:rs,stringSourceSpecZ:Pr,stringifyNumber:Xr,stringifyNumberProps:os,useProvider:bn,useSink:Ee,useSource:X,withinBounds:jr},Symbol.toStringTag,{value:"Module"})),ri=p.z.object({key:p.z.string(),size:p.z.number(),order:p.z.number(),loc:o.J.outer});p.z.record(ri);const dt=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),to=(n,e,t)=>{const s=e[n];if(s==null)return o.q.ZERO;const r=o.J.construct(s.loc),i=dt(r,e),a=o.J.construct(o.g.swap(o.J.direction(r))),l=dt(a,e),c=i.findIndex(({key:g})=>g===n),h=i.slice(0,c).reduce((g,{size:m})=>g+m,0),f=l.reduce((g,{size:m})=>g+m,0);switch(r){case"left":return o.q.translate(o.Eo.topLeft(t),[h,f]);case"right":return o.q.translate(o.Eo.topRight(t),[h-s.size,f]);case"top":return o.q.translate(o.Eo.topLeft(t),[f,h]);default:return o.q.translate(o.Eo.bottomLeft(t),[f,-h-s.size])}},eo=(n,e)=>{const t=dt("left",n),s=dt("right",n),r=dt("top",n),i=dt("bottom",n),a=t.reduce((f,{size:g})=>f+g,0),l=s.reduce((f,{size:g})=>f+g,0),c=r.reduce((f,{size:g})=>f+g,0),h=i.reduce((f,{size:g})=>f+g,0);return o.Eo.construct(o.q.translate(o.Eo.topLeft(e),{x:a,y:c}),o.Eo.width(e)-a-l,o.Eo.height(e)-c-h)};function $e(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function no(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function us(n){let e,t,s;n.length!==2?(e=$e,t=(l,c)=>$e(n(l),c),s=(l,c)=>n(l)-c):(e=n===$e||n===no?n:so,t=n,s=n);function r(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<0?h=g+1:f=g}while(h<f)}return h}function i(l,c,h=0,f=l.length){if(h<f){if(e(c,c)!==0)return f;do{const g=h+f>>>1;t(l[g],c)<=0?h=g+1:f=g}while(h<f)}return h}function a(l,c,h=0,f=l.length){const g=r(l,c,h,f-1);return g>h&&s(l[g-1],c)>-s(l[g],c)?g-1:g}return{left:r,center:a,right:i}}function so(){return 0}function ro(n){return n===null?NaN:+n}const io=us($e),ao=io.right;us(ro).center;const oo=Math.sqrt(50),lo=Math.sqrt(10),co=Math.sqrt(2);function Je(n,e,t){const s=(e-n)/Math.max(0,t),r=Math.floor(Math.log10(s)),i=s/Math.pow(10,r),a=i>=oo?10:i>=lo?5:i>=co?2:1;let l,c,h;return r<0?(h=Math.pow(10,-r)/a,l=Math.round(n*h),c=Math.round(e*h),l/h<n&&++l,c/h>e&&--c,h=-h):(h=Math.pow(10,r)*a,l=Math.round(n/h),c=Math.round(e/h),l*h<n&&++l,c*h>e&&--c),c<l&&.5<=t&&t<2?Je(n,e,t*2):[l,c,h]}function uo(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[r,i,a]=s?Je(e,n,t):Je(n,e,t);if(!(i>=r))return[];const l=i-r+1,c=new Array(l);if(s)if(a<0)for(let h=0;h<l;++h)c[h]=(i-h)/-a;else for(let h=0;h<l;++h)c[h]=(i-h)*a;else if(a<0)for(let h=0;h<l;++h)c[h]=(r+h)/-a;else for(let h=0;h<l;++h)c[h]=(r+h)*a;return c}function Zn(n,e,t){return e=+e,n=+n,t=+t,Je(n,e,t)[2]}function Bn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,r=s?Zn(e,n,t):Zn(n,e,t);return(s?-1:1)*(r<0?1/-r:r)}function ii(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function hs(n,e,t){n.prototype=e.prototype=t,t.constructor=n}function ai(n,e){var t=Object.create(n.prototype);for(var s in e)t[s]=e[s];return t}function Pe(){}var he=.7,Qe=1/he,kt="\\s*([+-]?\\d+)\\s*",de="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",J="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ho=/^#([0-9a-f]{3,8})$/,fo=new RegExp(`^rgb\\(${kt},${kt},${kt}\\)$`),po=new RegExp(`^rgb\\(${J},${J},${J}\\)$`),go=new RegExp(`^rgba\\(${kt},${kt},${kt},${de}\\)$`),mo=new RegExp(`^rgba\\(${J},${J},${J},${de}\\)$`),yo=new RegExp(`^hsl\\(${de},${J},${J}\\)$`),wo=new RegExp(`^hsla\\(${de},${J},${J},${de}\\)$`),Ys={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};hs(Pe,Lt,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:Ds,formatHex:Ds,formatHex8:xo,formatHsl:bo,formatRgb:As,toString:As});function Ds(){return this.rgb().formatHex()}function xo(){return this.rgb().formatHex8()}function bo(){return oi(this).formatHsl()}function As(){return this.rgb().formatRgb()}function Lt(n){var e,t;return n=(n+"").trim().toLowerCase(),(e=ho.exec(n))?(t=e[1].length,e=parseInt(e[1],16),t===6?Ls(e):t===3?new Z(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):t===8?De(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):t===4?De(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=fo.exec(n))?new Z(e[1],e[2],e[3],1):(e=po.exec(n))?new Z(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=go.exec(n))?De(e[1],e[2],e[3],e[4]):(e=mo.exec(n))?De(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=yo.exec(n))?$s(e[1],e[2]/100,e[3]/100,1):(e=wo.exec(n))?$s(e[1],e[2]/100,e[3]/100,e[4]):Ys.hasOwnProperty(n)?Ls(Ys[n]):n==="transparent"?new Z(NaN,NaN,NaN,0):null}function Ls(n){return new Z(n>>16&255,n>>8&255,n&255,1)}function De(n,e,t,s){return s<=0&&(n=e=t=NaN),new Z(n,e,t,s)}function vo(n){return n instanceof Pe||(n=Lt(n)),n?(n=n.rgb(),new Z(n.r,n.g,n.b,n.opacity)):new Z}function Un(n,e,t,s){return arguments.length===1?vo(n):new Z(n,e,t,s??1)}function Z(n,e,t,s){this.r=+n,this.g=+e,this.b=+t,this.opacity=+s}hs(Z,Un,ai(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new Z(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new Z(pt(this.r),pt(this.g),pt(this.b),tn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:_s,formatHex:_s,formatHex8:To,formatRgb:qs,toString:qs}));function _s(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}`}function To(){return`#${ft(this.r)}${ft(this.g)}${ft(this.b)}${ft((isNaN(this.opacity)?1:this.opacity)*255)}`}function qs(){const n=tn(this.opacity);return`${n===1?"rgb(":"rgba("}${pt(this.r)}, ${pt(this.g)}, ${pt(this.b)}${n===1?")":`, ${n})`}`}function tn(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function pt(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function ft(n){return n=pt(n),(n<16?"0":"")+n.toString(16)}function $s(n,e,t,s){return s<=0?n=e=t=NaN:t<=0||t>=1?n=e=NaN:e<=0&&(n=NaN),new H(n,e,t,s)}function oi(n){if(n instanceof H)return new H(n.h,n.s,n.l,n.opacity);if(n instanceof Pe||(n=Lt(n)),!n)return new H;if(n instanceof H)return n;n=n.rgb();var e=n.r/255,t=n.g/255,s=n.b/255,r=Math.min(e,t,s),i=Math.max(e,t,s),a=NaN,l=i-r,c=(i+r)/2;return l?(e===i?a=(t-s)/l+(t<s)*6:t===i?a=(s-e)/l+2:a=(e-t)/l+4,l/=c<.5?i+r:2-i-r,a*=60):l=c>0&&c<1?0:a,new H(a,l,c,n.opacity)}function So(n,e,t,s){return arguments.length===1?oi(n):new H(n,e,t,s??1)}function H(n,e,t,s){this.h=+n,this.s=+e,this.l=+t,this.opacity=+s}hs(H,So,ai(Pe,{brighter(n){return n=n==null?Qe:Math.pow(Qe,n),new H(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?he:Math.pow(he,n),new H(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,e=isNaN(n)||isNaN(this.s)?0:this.s,t=this.l,s=t+(t<.5?t:1-t)*e,r=2*t-s;return new Z(zn(n>=240?n-240:n+120,r,s),zn(n,r,s),zn(n<120?n+240:n-120,r,s),this.opacity)},clamp(){return new H(Is(this.h),Ae(this.s),Ae(this.l),tn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=tn(this.opacity);return`${n===1?"hsl(":"hsla("}${Is(this.h)}, ${Ae(this.s)*100}%, ${Ae(this.l)*100}%${n===1?")":`, ${n})`}`}}));function Is(n){return n=(n||0)%360,n<0?n+360:n}function Ae(n){return Math.max(0,Math.min(1,n||0))}function zn(n,e,t){return(n<60?e+(t-e)*n/60:n<180?t:n<240?e+(t-e)*(240-n)/60:e)*255}const ds=n=>()=>n;function Eo(n,e){return function(t){return n+t*e}}function Co(n,e,t){return n=Math.pow(n,t),e=Math.pow(e,t)-n,t=1/t,function(s){return Math.pow(n+s*e,t)}}function Ro(n){return(n=+n)==1?li:function(e,t){return t-e?Co(e,t,n):ds(isNaN(e)?t:e)}}function li(n,e){var t=e-n;return t?Eo(n,t):ds(isNaN(n)?e:n)}const Fn=function n(e){var t=Ro(e);function s(r,i){var a=t((r=Un(r)).r,(i=Un(i)).r),l=t(r.g,i.g),c=t(r.b,i.b),h=li(r.opacity,i.opacity);return function(f){return r.r=a(f),r.g=l(f),r.b=c(f),r.opacity=h(f),r+""}}return s.gamma=n,s}(1);function ko(n,e){e||(e=[]);var t=n?Math.min(e.length,n.length):0,s=e.slice(),r;return function(i){for(r=0;r<t;++r)s[r]=n[r]*(1-i)+e[r]*i;return s}}function Po(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Oo(n,e){var t=e?e.length:0,s=n?Math.min(t,n.length):0,r=new Array(s),i=new Array(t),a;for(a=0;a<s;++a)r[a]=fs(n[a],e[a]);for(;a<t;++a)i[a]=e[a];return function(l){for(a=0;a<s;++a)i[a]=r[a](l);return i}}function zo(n,e){var t=new Date;return n=+n,e=+e,function(s){return t.setTime(n*(1-s)+e*s),t}}function fe(n,e){return n=+n,e=+e,function(t){return n*(1-t)+e*t}}function Mo(n,e){var t={},s={},r;(n===null||typeof n!="object")&&(n={}),(e===null||typeof e!="object")&&(e={});for(r in e)r in n?t[r]=fs(n[r],e[r]):s[r]=e[r];return function(i){for(r in t)s[r]=t[r](i);return s}}var Gn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mn=new RegExp(Gn.source,"g");function Yo(n){return function(){return n}}function Do(n){return function(e){return n(e)+""}}function ci(n,e){var t=Gn.lastIndex=Mn.lastIndex=0,s,r,i,a=-1,l=[],c=[];for(n=n+"",e=e+"";(s=Gn.exec(n))&&(r=Mn.exec(e));)(i=r.index)>t&&(i=e.slice(t,i),l[a]?l[a]+=i:l[++a]=i),(s=s[0])===(r=r[0])?l[a]?l[a]+=r:l[++a]=r:(l[++a]=null,c.push({i:a,x:fe(s,r)})),t=Mn.lastIndex;return t<e.length&&(i=e.slice(t),l[a]?l[a]+=i:l[++a]=i),l.length<2?c[0]?Do(c[0].x):Yo(e):(e=c.length,function(h){for(var f=0,g;f<e;++f)l[(g=c[f]).i]=g.x(h);return l.join("")})}function fs(n,e){var t=typeof e,s;return e==null||t==="boolean"?ds(e):(t==="number"?fe:t==="string"?(s=Lt(e))?(e=s,Fn):ci:e instanceof Lt?Fn:e instanceof Date?zo:Po(e)?ko:Array.isArray(e)?Oo:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?Mo:fe)(n,e)}function Ao(n,e){return n=+n,e=+e,function(t){return Math.round(n*(1-t)+e*t)}}function Lo(n){return function(){return n}}function _o(n){return+n}var Ns=[0,1];function Tt(n){return n}function jn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Lo(isNaN(e)?NaN:.5)}function qo(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function $o(n,e,t){var s=n[0],r=n[1],i=e[0],a=e[1];return r<s?(s=jn(r,s),i=t(a,i)):(s=jn(s,r),i=t(i,a)),function(l){return i(s(l))}}function Io(n,e,t){var s=Math.min(n.length,e.length)-1,r=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)r[a]=jn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var c=ao(n,l,1,s)-1;return i[c](r[c](l))}}function ui(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function No(){var n=Ns,e=Ns,t=fs,s,r,i,a=Tt,l,c,h;function f(){var m=Math.min(n.length,e.length);return a!==Tt&&(a=qo(n[0],n[m-1])),l=m>2?Io:$o,c=h=null,g}function g(m){return m==null||isNaN(m=+m)?i:(c||(c=l(n.map(s),e,t)))(s(a(m)))}return g.invert=function(m){return a(r((h||(h=l(e,n.map(s),fe)))(m)))},g.domain=function(m){return arguments.length?(n=Array.from(m,_o),f()):n.slice()},g.range=function(m){return arguments.length?(e=Array.from(m),f()):e.slice()},g.rangeRound=function(m){return e=Array.from(m),t=Ao,f()},g.clamp=function(m){return arguments.length?(a=m?!0:Tt,f()):a!==Tt},g.interpolate=function(m){return arguments.length?(t=m,f()):t},g.unknown=function(m){return arguments.length?(i=m,g):i},function(m,x){return s=m,r=x,f()}}function hi(){return No()(Tt,Tt)}function Zo(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function en(n,e){if((t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"))<0)return null;var t,s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function _t(n){return n=en(Math.abs(n)),n?n[1]:NaN}function Bo(n,e){return function(t,s){for(var r=t.length,i=[],a=0,l=n[0],c=0;r>0&&l>0&&(c+l+1>s&&(l=Math.max(1,s-c)),i.push(t.substring(r-=l,r+l)),!((c+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function Uo(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var Fo=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function nn(n){if(!(e=Fo.exec(n)))throw new Error("invalid format: "+n);var e;return new ps({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}nn.prototype=ps.prototype;function ps(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}ps.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function Go(n){t:for(var e=n.length,t=1,s=-1,r;t<e;++t)switch(n[t]){case".":s=r=t;break;case"0":s===0&&(s=t),r=t;break;default:if(!+n[t])break t;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(r+1):n}var di;function jo(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1],i=r-(di=Math.max(-8,Math.min(8,Math.floor(r/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+en(n,Math.max(0,e+i-1))[0]}function Zs(n,e){var t=en(n,e);if(!t)return n+"";var s=t[0],r=t[1];return r<0?"0."+new Array(-r).join("0")+s:s.length>r+1?s.slice(0,r+1)+"."+s.slice(r+1):s+new Array(r-s.length+2).join("0")}const Bs={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:Zo,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>Zs(n*100,e),r:Zs,s:jo,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function Us(n){return n}var Fs=Array.prototype.map,Gs=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Ho(n){var e=n.grouping===void 0||n.thousands===void 0?Us:Bo(Fs.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",r=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?Us:Uo(Fs.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",c=n.nan===void 0?"NaN":n.nan+"";function h(g){g=nn(g);var m=g.fill,x=g.align,b=g.sign,T=g.symbol,C=g.zero,O=g.width,A=g.comma,P=g.precision,Y=g.trim,L=g.type;L==="n"?(A=!0,L="g"):Bs[L]||(P===void 0&&(P=12),Y=!0,L="g"),(C||m==="0"&&x==="=")&&(C=!0,m="0",x="=");var v=T==="$"?t:T==="#"&&/[boxX]/.test(L)?"0"+L.toLowerCase():"",_=T==="$"?s:/[%p]/.test(L)?a:"",ut=Bs[L],kn=/[defgprs%]/.test(L);P=P===void 0?6:/[gprs]/.test(L)?Math.max(1,Math.min(21,P)):Math.max(0,Math.min(20,P));function Me(E){var tt=v,I=_,at,Ye,wt;if(L==="c")I=ut(E)+I,E="";else{E=+E;var xt=E<0||1/E<0;if(E=isNaN(E)?c:ut(Math.abs(E),P),Y&&(E=Go(E)),xt&&+E==0&&b!=="+"&&(xt=!1),tt=(xt?b==="("?b:l:b==="-"||b==="("?"":b)+tt,I=(L==="s"?Gs[8+di/3]:"")+I+(xt&&b==="("?")":""),kn){for(at=-1,Ye=E.length;++at<Ye;)if(wt=E.charCodeAt(at),48>wt||wt>57){I=(wt===46?r+E.slice(at+1):E.slice(at))+I,E=E.slice(0,at);break}}}A&&!C&&(E=e(E,1/0));var bt=tt.length+E.length+I.length,j=bt<O?new Array(O-bt+1).join(m):"";switch(A&&C&&(E=e(j+E,j.length?O-I.length:1/0),j=""),x){case"<":E=tt+E+I+j;break;case"=":E=tt+j+E+I;break;case"^":E=j.slice(0,bt=j.length>>1)+tt+E+I+j.slice(bt);break;default:E=j+tt+E+I;break}return i(E)}return Me.toString=function(){return g+""},Me}function f(g,m){var x=h((g=nn(g),g.type="f",g)),b=Math.max(-8,Math.min(8,Math.floor(_t(m)/3)))*3,T=Math.pow(10,-b),C=Gs[8+b/3];return function(O){return x(T*O)+C}}return{format:h,formatPrefix:f}}var Le,fi,pi;Wo({thousands:",",grouping:[3],currency:["$",""]});function Wo(n){return Le=Ho(n),fi=Le.format,pi=Le.formatPrefix,Le}function Xo(n){return Math.max(0,-_t(Math.abs(n)))}function Vo(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(_t(e)/3)))*3-_t(Math.abs(n)))}function Ko(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,_t(e)-_t(n))+1}function Jo(n,e,t,s){var r=Bn(n,e,t),i;switch(s=nn(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=Vo(r,a))&&(s.precision=i),pi(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=Ko(r,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=Xo(r))&&(s.precision=i-(s.type==="%")*2);break}}return fi(s)}function Qo(n){var e=n.domain;return n.ticks=function(t){var s=e();return uo(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var r=e();return Jo(r[0],r[r.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),r=0,i=s.length-1,a=s[r],l=s[i],c,h,f=10;for(l<a&&(h=a,a=l,l=h,h=r,r=i,i=h);f-- >0;){if(h=Zn(a,l,t),h===c)return s[r]=a,s[i]=l,e(s);if(h>0)a=Math.floor(a/h)*h,l=Math.ceil(l/h)*h;else if(h<0)a=Math.ceil(a*h)/h,l=Math.floor(l*h)/h;else break;c=h}return n},n}function gi(){var n=hi();return n.copy=function(){return ui(n,gi())},ii.apply(n,arguments),Qo(n)}function tl(n,e){n=n.slice();var t=0,s=n.length-1,r=n[t],i=n[s],a;return i<r&&(a=t,t=s,s=a,a=r,r=i,i=a),n[t]=e.floor(r),n[s]=e.ceil(i),n}const Yn=new Date,Dn=new Date;function M(n,e,t,s){function r(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return r.floor=i=>(n(i=new Date(+i)),i),r.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),r.round=i=>{const a=r(i),l=r.ceil(i);return i-a<l-i?a:l},r.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),r.range=(i,a,l)=>{const c=[];if(i=r.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return c;let h;do c.push(h=new Date(+i)),e(i,l),n(i);while(h<i&&i<a);return c},r.filter=i=>M(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(r.count=(i,a)=>(Yn.setTime(+i),Dn.setTime(+a),n(Yn),n(Dn),Math.floor(t(Yn,Dn))),r.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?r.filter(s?a=>s(a)%i===0:a=>r.count(0,a)%i===0):r)),r}const sn=M(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);sn.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?M(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):sn);sn.range;const et=1e3,F=et*60,nt=F*60,st=nt*24,gs=st*7,js=st*30,An=st*365,St=M(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*et)},(n,e)=>(e-n)/et,n=>n.getUTCSeconds());St.range;const ms=M(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getMinutes());ms.range;const el=M(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*F)},(n,e)=>(e-n)/F,n=>n.getUTCMinutes());el.range;const ys=M(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*et-n.getMinutes()*F)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getHours());ys.range;const nl=M(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*nt)},(n,e)=>(e-n)/nt,n=>n.getUTCHours());nl.range;const Oe=M(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*F)/st,n=>n.getDate()-1);Oe.range;const ws=M(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>n.getUTCDate()-1);ws.range;const sl=M(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/st,n=>Math.floor(n/st));sl.range;function mt(n){return M(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*F)/gs)}const Rn=mt(0),rn=mt(1),rl=mt(2),il=mt(3),qt=mt(4),al=mt(5),ol=mt(6);Rn.range;rn.range;rl.range;il.range;qt.range;al.range;ol.range;function yt(n){return M(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/gs)}const mi=yt(0),an=yt(1),ll=yt(2),cl=yt(3),$t=yt(4),ul=yt(5),hl=yt(6);mi.range;an.range;ll.range;cl.range;$t.range;ul.range;hl.range;const xs=M(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());xs.range;const dl=M(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());dl.range;const rt=M(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());rt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:M(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});rt.range;const gt=M(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());gt.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:M(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});gt.range;function fl(n,e,t,s,r,i){const a=[[St,1,et],[St,5,5*et],[St,15,15*et],[St,30,30*et],[i,1,F],[i,5,5*F],[i,15,15*F],[i,30,30*F],[r,1,nt],[r,3,3*nt],[r,6,6*nt],[r,12,12*nt],[s,1,st],[s,2,2*st],[t,1,gs],[e,1,js],[e,3,3*js],[n,1,An]];function l(h,f,g){const m=f<h;m&&([h,f]=[f,h]);const x=g&&typeof g.range=="function"?g:c(h,f,g),b=x?x.range(h,+f+1):[];return m?b.reverse():b}function c(h,f,g){const m=Math.abs(f-h)/g,x=us(([,,C])=>C).right(a,m);if(x===a.length)return n.every(Bn(h/An,f/An,g));if(x===0)return sn.every(Math.max(Bn(h,f,g),1));const[b,T]=a[m/a[x-1][2]<a[x][2]/m?x-1:x];return b.every(T)}return[l,c]}const[pl,gl]=fl(rt,xs,Rn,Oe,ys,ms);function Ln(n){if(0<=n.y&&n.y<100){var e=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return e.setFullYear(n.y),e}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function _n(n){if(0<=n.y&&n.y<100){var e=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return e.setUTCFullYear(n.y),e}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function jt(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function ml(n){var e=n.dateTime,t=n.date,s=n.time,r=n.periods,i=n.days,a=n.shortDays,l=n.months,c=n.shortMonths,h=Ht(r),f=Wt(r),g=Ht(i),m=Wt(i),x=Ht(a),b=Wt(a),T=Ht(l),C=Wt(l),O=Ht(c),A=Wt(c),P={a:xt,A:bt,b:j,B:ra,c:null,d:Js,e:Js,f:Il,g:Xl,G:Kl,H:_l,I:ql,j:$l,L:yi,m:Nl,M:Zl,p:ia,q:aa,Q:er,s:nr,S:Bl,u:Ul,U:Fl,V:Gl,w:jl,W:Hl,x:null,X:null,y:Wl,Y:Vl,Z:Jl,"%":tr},Y={a:oa,A:la,b:ca,B:ua,c:null,d:Qs,e:Qs,f:nc,g:dc,G:pc,H:Ql,I:tc,j:ec,L:xi,m:sc,M:rc,p:ha,q:da,Q:er,s:nr,S:ic,u:ac,U:oc,V:lc,w:cc,W:uc,x:null,X:null,y:hc,Y:fc,Z:gc,"%":tr},L={a:Me,A:E,b:tt,B:I,c:at,d:Vs,e:Vs,f:Yl,g:Xs,G:Ws,H:Ks,I:Ks,j:Pl,L:Ml,m:kl,M:Ol,p:kn,q:Rl,Q:Al,s:Ll,S:zl,u:vl,U:Tl,V:Sl,w:bl,W:El,x:Ye,X:wt,y:Xs,Y:Ws,Z:Cl,"%":Dl};P.x=v(t,P),P.X=v(s,P),P.c=v(e,P),Y.x=v(t,Y),Y.X=v(s,Y),Y.c=v(e,Y);function v(w,S){return function(R){var y=[],N=-1,z=0,B=w.length,U,ht,Os;for(R instanceof Date||(R=new Date(+R));++N<B;)w.charCodeAt(N)===37&&(y.push(w.slice(z,N)),(ht=Hs[U=w.charAt(++N)])!=null?U=w.charAt(++N):ht=U==="e"?" ":"0",(Os=S[U])&&(U=Os(R,ht)),y.push(U),z=N+1);return y.push(w.slice(z,N)),y.join("")}}function _(w,S){return function(R){var y=jt(1900,void 0,1),N=ut(y,w,R+="",0),z,B;if(N!=R.length)return null;if("Q"in y)return new Date(y.Q);if("s"in y)return new Date(y.s*1e3+("L"in y?y.L:0));if(S&&!("Z"in y)&&(y.Z=0),"p"in y&&(y.H=y.H%12+y.p*12),y.m===void 0&&(y.m="q"in y?y.q:0),"V"in y){if(y.V<1||y.V>53)return null;"w"in y||(y.w=1),"Z"in y?(z=_n(jt(y.y,0,1)),B=z.getUTCDay(),z=B>4||B===0?an.ceil(z):an(z),z=ws.offset(z,(y.V-1)*7),y.y=z.getUTCFullYear(),y.m=z.getUTCMonth(),y.d=z.getUTCDate()+(y.w+6)%7):(z=Ln(jt(y.y,0,1)),B=z.getDay(),z=B>4||B===0?rn.ceil(z):rn(z),z=Oe.offset(z,(y.V-1)*7),y.y=z.getFullYear(),y.m=z.getMonth(),y.d=z.getDate()+(y.w+6)%7)}else("W"in y||"U"in y)&&("w"in y||(y.w="u"in y?y.u%7:"W"in y?1:0),B="Z"in y?_n(jt(y.y,0,1)).getUTCDay():Ln(jt(y.y,0,1)).getDay(),y.m=0,y.d="W"in y?(y.w+6)%7+y.W*7-(B+5)%7:y.w+y.U*7-(B+6)%7);return"Z"in y?(y.H+=y.Z/100|0,y.M+=y.Z%100,_n(y)):Ln(y)}}function ut(w,S,R,y){for(var N=0,z=S.length,B=R.length,U,ht;N<z;){if(y>=B)return-1;if(U=S.charCodeAt(N++),U===37){if(U=S.charAt(N++),ht=L[U in Hs?S.charAt(N++):U],!ht||(y=ht(w,R,y))<0)return-1}else if(U!=R.charCodeAt(y++))return-1}return y}function kn(w,S,R){var y=h.exec(S.slice(R));return y?(w.p=f.get(y[0].toLowerCase()),R+y[0].length):-1}function Me(w,S,R){var y=x.exec(S.slice(R));return y?(w.w=b.get(y[0].toLowerCase()),R+y[0].length):-1}function E(w,S,R){var y=g.exec(S.slice(R));return y?(w.w=m.get(y[0].toLowerCase()),R+y[0].length):-1}function tt(w,S,R){var y=O.exec(S.slice(R));return y?(w.m=A.get(y[0].toLowerCase()),R+y[0].length):-1}function I(w,S,R){var y=T.exec(S.slice(R));return y?(w.m=C.get(y[0].toLowerCase()),R+y[0].length):-1}function at(w,S,R){return ut(w,e,S,R)}function Ye(w,S,R){return ut(w,t,S,R)}function wt(w,S,R){return ut(w,s,S,R)}function xt(w){return a[w.getDay()]}function bt(w){return i[w.getDay()]}function j(w){return c[w.getMonth()]}function ra(w){return l[w.getMonth()]}function ia(w){return r[+(w.getHours()>=12)]}function aa(w){return 1+~~(w.getMonth()/3)}function oa(w){return a[w.getUTCDay()]}function la(w){return i[w.getUTCDay()]}function ca(w){return c[w.getUTCMonth()]}function ua(w){return l[w.getUTCMonth()]}function ha(w){return r[+(w.getUTCHours()>=12)]}function da(w){return 1+~~(w.getUTCMonth()/3)}return{format:function(w){var S=v(w+="",P);return S.toString=function(){return w},S},parse:function(w){var S=_(w+="",!1);return S.toString=function(){return w},S},utcFormat:function(w){var S=v(w+="",Y);return S.toString=function(){return w},S},utcParse:function(w){var S=_(w+="",!0);return S.toString=function(){return w},S}}}var Hs={"-":"",_:" ",0:"0"},D=/^\s*\d+/,yl=/^%/,wl=/[\\^$*+?|[\]().{}]/g;function k(n,e,t){var s=n<0?"-":"",r=(s?-n:n)+"",i=r.length;return s+(i<t?new Array(t-i+1).join(e)+r:r)}function xl(n){return n.replace(wl,"\\$&")}function Ht(n){return new RegExp("^(?:"+n.map(xl).join("|")+")","i")}function Wt(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function bl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function vl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function Tl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Sl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function El(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Ws(n,e,t){var s=D.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Xs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function Cl(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function Rl(n,e,t){var s=D.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function kl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Vs(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function Pl(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Ks(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function Ol(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function zl(n,e,t){var s=D.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function Ml(n,e,t){var s=D.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Yl(n,e,t){var s=D.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Dl(n,e,t){var s=yl.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Al(n,e,t){var s=D.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Ll(n,e,t){var s=D.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Js(n,e){return k(n.getDate(),e,2)}function _l(n,e){return k(n.getHours(),e,2)}function ql(n,e){return k(n.getHours()%12||12,e,2)}function $l(n,e){return k(1+Oe.count(rt(n),n),e,3)}function yi(n,e){return k(n.getMilliseconds(),e,3)}function Il(n,e){return yi(n,e)+"000"}function Nl(n,e){return k(n.getMonth()+1,e,2)}function Zl(n,e){return k(n.getMinutes(),e,2)}function Bl(n,e){return k(n.getSeconds(),e,2)}function Ul(n){var e=n.getDay();return e===0?7:e}function Fl(n,e){return k(Rn.count(rt(n)-1,n),e,2)}function wi(n){var e=n.getDay();return e>=4||e===0?qt(n):qt.ceil(n)}function Gl(n,e){return n=wi(n),k(qt.count(rt(n),n)+(rt(n).getDay()===4),e,2)}function jl(n){return n.getDay()}function Hl(n,e){return k(rn.count(rt(n)-1,n),e,2)}function Wl(n,e){return k(n.getFullYear()%100,e,2)}function Xl(n,e){return n=wi(n),k(n.getFullYear()%100,e,2)}function Vl(n,e){return k(n.getFullYear()%1e4,e,4)}function Kl(n,e){var t=n.getDay();return n=t>=4||t===0?qt(n):qt.ceil(n),k(n.getFullYear()%1e4,e,4)}function Jl(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+k(e/60|0,"0",2)+k(e%60,"0",2)}function Qs(n,e){return k(n.getUTCDate(),e,2)}function Ql(n,e){return k(n.getUTCHours(),e,2)}function tc(n,e){return k(n.getUTCHours()%12||12,e,2)}function ec(n,e){return k(1+ws.count(gt(n),n),e,3)}function xi(n,e){return k(n.getUTCMilliseconds(),e,3)}function nc(n,e){return xi(n,e)+"000"}function sc(n,e){return k(n.getUTCMonth()+1,e,2)}function rc(n,e){return k(n.getUTCMinutes(),e,2)}function ic(n,e){return k(n.getUTCSeconds(),e,2)}function ac(n){var e=n.getUTCDay();return e===0?7:e}function oc(n,e){return k(mi.count(gt(n)-1,n),e,2)}function bi(n){var e=n.getUTCDay();return e>=4||e===0?$t(n):$t.ceil(n)}function lc(n,e){return n=bi(n),k($t.count(gt(n),n)+(gt(n).getUTCDay()===4),e,2)}function cc(n){return n.getUTCDay()}function uc(n,e){return k(an.count(gt(n)-1,n),e,2)}function hc(n,e){return k(n.getUTCFullYear()%100,e,2)}function dc(n,e){return n=bi(n),k(n.getUTCFullYear()%100,e,2)}function fc(n,e){return k(n.getUTCFullYear()%1e4,e,4)}function pc(n,e){var t=n.getUTCDay();return n=t>=4||t===0?$t(n):$t.ceil(n),k(n.getUTCFullYear()%1e4,e,4)}function gc(){return"+0000"}function tr(){return"%"}function er(n){return+n}function nr(n){return Math.floor(+n/1e3)}var vt,vi;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(n){return vt=ml(n),vi=vt.format,vt.parse,vt.utcFormat,vt.utcParse,vt}function yc(n){return new Date(n)}function wc(n){return n instanceof Date?+n:+new Date(+n)}function Ti(n,e,t,s,r,i,a,l,c,h){var f=hi(),g=f.invert,m=f.domain,x=h(".%L"),b=h(":%S"),T=h("%I:%M"),C=h("%I %p"),O=h("%a %d"),A=h("%b %d"),P=h("%B"),Y=h("%Y");function L(v){return(c(v)<v?x:l(v)<v?b:a(v)<v?T:i(v)<v?C:s(v)<v?r(v)<v?O:A:t(v)<v?P:Y)(v)}return f.invert=function(v){return new Date(g(v))},f.domain=function(v){return arguments.length?m(Array.from(v,wc)):m().map(yc)},f.ticks=function(v){var _=m();return n(_[0],_[_.length-1],v??10)},f.tickFormat=function(v,_){return _==null?L:h(_)},f.nice=function(v){var _=m();return(!v||typeof v.range!="function")&&(v=e(_[0],_[_.length-1],v??10)),v?m(tl(_,v)):f},f.copy=function(){return ui(f,Ti(n,e,t,s,r,i,a,l,c,h))},f}function xc(){return ii.apply(Ti(pl,gl,rt,xs,Rn,Oe,ys,ms,St,vi).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const bs=p.z.enum(["linear","time"]),vs=p.z.object({tickSpacing:p.z.number().default(75),type:bs.optional().default("linear")}),Hn=n=>{const e=vs.parse(n);return Tc[e.type](e)};class bc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[new d.m(e.pos(0)).date(),new d.m(e.pos(1)).date()],i=xc().domain(r).range(s);return i.ticks(Si(t,this.props.tickSpacing)).map(l=>({label:this.tickLabel(l),position:i(l)}))}tickLabel(e){const t=new d.m(e).date();let s=`:${t.getSeconds()}`;if(t.getMilliseconds()!==0){const i=Math.round(t.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");s+=`.${i}`}return t.getSeconds()===0&&t.getMilliseconds()===0&&(s=`${t.getHours()}:${t.getMinutes().toString().padStart(2,"0")}`),s}}class vc{constructor(e){u(this,"props");this.props=e}generate({decimalToDataScale:e,size:t}){const s=[0,t],r=[e.pos(0),e.pos(1)],i=gi().domain(r).range(s),a=Si(t,this.props.tickSpacing);return i.ticks(a).map(c=>({label:this.tickLabel(c),position:i(c)}))}tickLabel(e){return e.toString()}}const Si=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},Tc={linear:n=>new vc(n),time:n=>new bc(n)},Ts=vs.extend({color:o.Color.z,type:bs.optional().default("linear"),font:p.z.string(),showGrid:p.z.boolean().optional().default(!0),location:o.J.outer,gridColor:o.Color.z}),V=4;let Ei=class{constructor(e,t){u(this,"ctx");u(this,"state");u(this,"tickFactory");this.ctx=e,this.state=t,this.tickFactory=Hn(this.state)}setState(e){this.state=d.prettyParse(Ts,e),this.tickFactory=Hn(e)}render(e){const{lower2d:t}=this.ctx;switch(t.font=this.state.font,t.fillStyle=this.state.color.hex,t.lineWidth=1,this.state.location){case"left":return this.drawLeft(e);case"right":return this.drawRight(e);case"top":return this.drawTop(e);default:return this.drawBottom(e)}}drawBottom(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:-i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y+V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y+5+h.height)}).height+V+6}}drawTop(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.width(s),i=o.Eo.height(s),a=o.q.translate(e.position,"y",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"x",h.position),o.q.translate(a,{x:h.position,y:i})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"x",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x+f.position,a.y),t.lineTo(a.x+f.position,a.y-V),t.stroke(),t.fillText(f.label,a.x+f.position-h.width/2,a.y-5-h.height)}).height+V}}drawLeft(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=o.q.translate(e.position,"x",e.size),l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x-V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x-h.width-V*2,a.y+f.position+h.height/3)}).width+V*2}}drawRight(e){const{lower2d:t}=this.ctx,{plot:s}=e,r=o.Eo.height(s),i=o.Eo.width(s),a=e.position,l=this.tickFactory.generate({...e,size:r});return this.maybeDrawGrid(r,l,h=>[o.q.translate(a,"y",h.position),o.q.translate(a,{x:-i,y:h.position})]),t.strokeStyle=this.state.color.hex,this.drawLine(a,o.q.translate(a,"y",r)),{size:this.drawTicks(l,(h,f)=>{t.moveTo(a.x,a.y+f.position),t.lineTo(a.x+V,a.y+f.position),t.stroke(),t.fillText(f.label,a.x+V+2,a.y+f.position+h.height/3)}).width+V*2}}drawLine(e,t){const{lower2d:s}=this.ctx;s.beginPath(),s.moveTo(...o.q.couple(e)),s.lineTo(...o.q.couple(t)),s.stroke()}drawTicks(e,t){let s=o._.ZERO;return e.forEach(r=>{const i=d.dimensions(r.label,this.state.font,this.ctx.lower2d);s=o._.max([s,i]),t(i,r)}),s}maybeDrawGrid(e,t,s){const{showGrid:r,gridColor:i}=this.state;if(r){const a=o.G.construct(-1,1),l=o.G.construct(e-1,e+1);this.ctx.lower2d.strokeStyle=i.hex,t.filter(({position:c})=>!o.G.contains(a,c)&&!o.G.contains(l,c)).forEach(c=>this.drawLine(...s(c)))}}};const Ie=(n,e)=>o.Eo.construct(o.Eo.left(n)-e.x,o.Eo.top(n)-e.y,o.Eo.width(n)+e.x*2,o.Eo.height(n)+e.y*2);class on{constructor(e,t=o.k$2.XY.IDENTITY){u(this,"scale_");u(this,"wrapped");this.wrapped=e,this.scale_=t}get fontStretch(){return this.wrapped.fontStretch}set fontStretch(e){this.wrapped.fontStretch=e}get fontVariantCaps(){return this.wrapped.fontVariantCaps}set fontVariantCaps(e){this.wrapped.fontVariantCaps=e}isContextLost(){return this.wrapped.isContextLost()}get wordSpacing(){return this.wrapped.wordSpacing}set wordSpacing(e){this.wrapped.wordSpacing=e}get letterSpacing(){return this.wrapped.letterSpacing}set letterSpacing(e){this.wrapped.letterSpacing=e}get textRendering(){return this.wrapped.textRendering}set textRendering(e){this.wrapped.textRendering=e}reset(){this.wrapped.reset()}applyScale(e){return new on(this,e)}get canvas(){return this.wrapped.canvas}get miterLimit(){return this.wrapped.miterLimit}set miterLimit(e){this.wrapped.miterLimit=this.scale_.x.dim(e)}get globalAlpha(){return this.wrapped.globalAlpha}set globalAlpha(e){this.wrapped.globalAlpha=e}get globalCompositeOperation(){return this.wrapped.globalCompositeOperation}set globalCompositeOperation(e){this.wrapped.globalCompositeOperation=e}get fillStyle(){return this.wrapped.fillStyle}set fillStyle(e){this.wrapped.fillStyle=e}get strokeStyle(){return this.wrapped.strokeStyle}set strokeStyle(e){this.wrapped.strokeStyle=e}drawImage(e,t,s,r,i,a,l,c,h){this.wrapped.drawImage(e,t,s,r,i,a,l,c,h)}beginPath(){this.wrapped.beginPath()}clip(e,t){this.wrapped.clip(e,t)}fill(e,t){if(e==null)return this.wrapped.fill();this.wrapped.fill(e,t)}isPointInPath(e,t,s,r){return this.wrapped.isPointInPath(e,t,s,r)}isPointInStroke(e,t,s){return this.wrapped.isPointInStroke(e,t,s)}stroke(e){if(e==null)return this.wrapped.stroke();this.wrapped.stroke(e)}createConicGradient(e,t,s){return this.wrapped.createConicGradient(e,t,s)}createLinearGradient(e,t,s,r){return this.wrapped.createLinearGradient(e,t,s,r)}createPattern(e,t){return this.wrapped.createPattern(e,t)}createRadialGradient(e,t,s,r,i,a){return this.wrapped.createRadialGradient(e,t,s,r,i,a)}get filter(){return this.wrapped.filter}set filter(e){this.wrapped.filter=e}createImageData(e,t,s){return this.wrapped.createImageData(e,t,s)}getImageData(e,t,s,r,i){return this.wrapped.getImageData(e,t,s,r,i)}putImageData(e,t,s,r,i,a,l){this.wrapped.putImageData(e,t,s,r,i,a,l)}get imageSmoothingEnabled(){return this.wrapped.imageSmoothingEnabled}set imageSmoothingEnabled(e){this.wrapped.imageSmoothingEnabled=e}get imageSmoothingQuality(){return this.wrapped.imageSmoothingQuality}set imageSmoothingQuality(e){this.wrapped.imageSmoothingQuality=e}arc(e,t,s,r,i,a){this.wrapped.arc(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),r,i,a)}arcTo(e,t,s,r,i){this.wrapped.arcTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.dim(i))}bezierCurveTo(e,t,s,r,i,a){this.wrapped.bezierCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r),this.scale_.x.pos(i),this.scale_.y.pos(a))}closePath(){this.wrapped.closePath()}ellipse(e,t,s,r,i,a,l,c){this.wrapped.ellipse(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),i,a,l,c)}lineTo(e,t){this.wrapped.lineTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}moveTo(e,t){this.wrapped.moveTo(this.scale_.x.pos(e),this.scale_.y.pos(t))}quadraticCurveTo(e,t,s,r){this.wrapped.quadraticCurveTo(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.pos(s),this.scale_.y.pos(r))}rect(e,t,s,r){this.wrapped.rect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}roundRect(e,t,s,r,i){this.wrapped.roundRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r),typeof i=="number"?this.scale_.x.dim(i):i)}get lineCap(){return this.wrapped.lineCap}set lineCap(e){this.wrapped.lineCap=e}get lineDashOffset(){return this.wrapped.lineDashOffset}set lineDashOffset(e){this.wrapped.lineDashOffset=this.scale_.x.dim(e)}get lineJoin(){return this.wrapped.lineJoin}set lineJoin(e){this.wrapped.lineJoin=e}get lineWidth(){return this.wrapped.lineWidth}set lineWidth(e){this.wrapped.lineWidth=this.scale_.x.dim(e)}getLineDash(){return this.wrapped.getLineDash()}setLineDash(e){const t=Array.from(e).map(s=>this.scale_.x.dim(s));this.wrapped.setLineDash(t)}clearRect(e,t,s,r){this.wrapped.clearRect(e,t,s,r)}fillRect(e,t,s,r){this.wrapped.fillRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}strokeRect(e,t,s,r){this.wrapped.strokeRect(this.scale_.x.pos(e),this.scale_.y.pos(t),this.scale_.x.dim(s),this.scale_.y.dim(r))}get shadowBlur(){return this.wrapped.shadowBlur}set shadowBlur(e){this.wrapped.shadowBlur=e}get shadowColor(){return this.wrapped.shadowColor}set shadowColor(e){this.wrapped.shadowColor=e}get shadowOffsetX(){return this.wrapped.shadowOffsetX}set shadowOffsetX(e){this.wrapped.shadowOffsetX=e}get shadowOffsetY(){return this.wrapped.shadowOffsetY}restore(){this.wrapped.restore()}save(){this.wrapped.save()}fillText(e,t,s,r){this.wrapped.fillText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}measureText(e){this.wrapped.font=qn(this.wrapped.font,this.scale_.x.reverse());const t=this.wrapped.measureText(e);return this.wrapped.font=qn(this.wrapped.font,this.scale_.x),t}strokeText(e,t,s,r){this.wrapped.strokeText(e,this.scale_.x.pos(t),this.scale_.y.pos(s),r!=null?this.scale_.x.dim(r):void 0)}get direction(){return this.wrapped.direction}set direction(e){this.wrapped.direction=e}get font(){return this.wrapped.font}set font(e){this.wrapped.font=qn(e,this.scale_.x)}get fontKerning(){return this.wrapped.fontKerning}set fontKerning(e){this.wrapped.fontKerning=e}get textAlign(){return this.wrapped.textAlign}set textAlign(e){this.wrapped.textAlign=e}get textBaseline(){return this.wrapped.textBaseline}set textBaseline(e){this.wrapped.textBaseline=e}getTransform(){return this.wrapped.getTransform()}resetTransform(){this.wrapped.resetTransform()}rotate(e){this.wrapped.rotate(e)}scale(e,t){this.wrapped.scale(e,t)}scissor(e,t=o.q.ZERO){const s=new Path2D;return e=Ie(e,t),s.rect(...o.q.couple(o.Eo.topLeft(e)),...o._.couple(o.Eo.dims(e))),this.save(),this.clip(s),()=>this.restore()}setTransform(e,t,s,r,i,a){this.wrapped.setTransform(e,t,s,r,i,a)}transform(e,t,s,r,i,a){this.wrapped.transform(e,t,s,r,i,a)}translate(e,t){this.wrapped.translate(e,t)}}const sr=/(\d+(\.\d+)?)px/,qn=(n,e)=>{var r;const t=Number((r=n.match(sr))==null?void 0:r[1]);if(t==null)return n;const s=e.dim(t);return n.replace(sr,`${s}px`)},Sc=`precision mediump float;
|
|
7
7
|
|
|
8
8
|
void main(void) {
|
|
9
9
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
|
10
10
|
}
|
|
11
|
-
`,
|
|
11
|
+
`,Ec=`attribute vec4 a_position;
|
|
12
12
|
|
|
13
13
|
void main(void) {
|
|
14
14
|
gl_Position = a_position;
|
|
15
15
|
}
|
|
16
|
-
`,rr=n=>new Error(`failed to compile webgl program: ${n}`),
|
|
16
|
+
`,rr=n=>new Error(`failed to compile webgl program: ${n}`),Cc=new Error("null shader encountered");class Ss{constructor(e,t,s){u(this,"ctx");u(this,"prog");u(this,"vertShader");u(this,"fragShader");u(this,"uniformLocCache",new Map);this.ctx=e;const r=e.gl.createProgram();if(r==null)throw rr("failed to create program");this.prog=r,this.vertShader=t,this.fragShader=s,this.compile()}setAsActive(){return this.ctx.gl.useProgram(this.prog),()=>this.ctx.gl.useProgram(null)}uniformXY(e,t){this.ctx.gl.uniform2fv(this.getUniformLoc(e),o.q.couple(o.q.construct(t)))}uniformColor(e,t){this.ctx.gl.uniform4fv(this.getUniformLoc(e),t.rgba1)}getUniformLoc(e){const t=this.uniformLocCache.get(e);if(t!=null)return t;const s=this.ctx.gl.getUniformLocation(this.prog,e);if(s==null)throw new Error(`unexpected missing uniform ${e}`);return this.uniformLocCache.set(e,s),s}compile(){const e=this.ctx.gl;this.compileShader(this.vertShader,e.VERTEX_SHADER),this.compileShader(this.fragShader,e.FRAGMENT_SHADER),e.linkProgram(this.prog)}compileShader(e,t){const s=this.ctx.gl,r=s.createShader(t);if(r==null)throw Cc;if(s.shaderSource(r,e),s.compileShader(r),!s.getShaderParameter(r,s.COMPILE_STATUS)){const a=s.getShaderInfoLog(r);throw s.deleteShader(r),rr(a??"unknown")}s.attachShader(this.prog,r)}}const Rc=new Float32Array([0,0,0,0,0,0]);class kc extends Ss{constructor(t){super(t,Ec,Sc);u(this,"positionBuffer");const s=t.gl.createBuffer();if(s==null)throw new d.Ce("webgl: failed to create buffer");this.positionBuffer=s,t.gl.bindBuffer(t.gl.ARRAY_BUFFER,this.positionBuffer),t.gl.bufferData(t.gl.ARRAY_BUFFER,Rc,t.gl.STATIC_DRAW)}exec(){const{gl:t}=this.ctx,s=t.getAttribLocation(this.prog,"a_position");t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer);const r=t.createVertexArray();t.bindVertexArray(r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),this.setAsActive(),t.drawArrays(t.TRIANGLES,0,3)}}const ir={high:1,low:0},ar=d.P.hz(45);class Ci{constructor(e){u(this,"mutex",new d.Mutex);u(this,"requests",new Map);u(this,"cleanup",new Map);u(this,"afterRender");this.start(),this.afterRender=e}async set(e){let t;e.priority==="high"&&(t=await this.mutex.acquire());const s=this.requests.get(e.key);if(s==null)this.requests.set(e.key,e);else{const r=ir[e.priority]>=ir[s.priority],i=e.canvases.length>=s.canvases.length;r&&i&&this.requests.set(e.key,e)}t==null||t()}async render(){await this.mutex.runExclusive(async()=>{var i;const e=performance.now(),{requests:t}=this;if(t.size===0)return;await this.runCleanupsSync(),await this.renderSync();const s=performance.now(),r=d.y.milliseconds(s-e);r.greaterThan(ar.period)&&console.warn(`Render loop for ${this.requests.size} took longer than ${ar.period.toString()} to execute: ${r.milliseconds}`),this.requests.clear(),(i=this.afterRender)==null||i.call(this)})}async runCleanupsSync(){const{cleanup:e,requests:t}=this;for(const[s,r]of e.entries()){const i=t.get(s);i!=null&&(await r(i),e.delete(s))}}async renderSync(){const{requests:e}=this;for(const t of e.values())try{const s=await t.render();s!=null&&this.cleanup.set(t.key,s)}catch(s){console.error(s)}}async start(){do{try{await this.render()}catch(e){console.error(e)}await this.sleep()}while(!0)}async sleep(){return await new Promise(requestAnimationFrame)}}var W;let q=(W=class{constructor(e,t,s,r){u(this,"glCanvas");u(this,"upper2dCanvas");u(this,"lower2dCanvas");u(this,"gl");u(this,"lower2d");u(this,"upper2d");u(this,"region");u(this,"dpr");u(this,"loop");u(this,"clearProgram");u(this,"os");this.upper2dCanvas=s,this.lower2dCanvas=t,this.glCanvas=e,this.os=r;const i=this.lower2dCanvas.getContext("2d");if(i==null)throw new Error("Could not get 2D context");this.lower2d=new on(i);const a=this.upper2dCanvas.getContext("2d");if(a==null)throw new Error("Could not get 2D context");this.upper2d=new on(a);const l={preserveDrawingBuffer:!0,powerPreference:"high-performance",stencil:!1,depth:!1},c=this.glCanvas.getContext("webgl2",l);if(c==null)throw new Error("Could not get WebGL context");c.disable(c.DEPTH_TEST),c.disable(c.STENCIL_TEST),c.disable(c.CULL_FACE),c.disable(c.DITHER),this.gl=c,this.glCanvas.oncontextlost=console.log;const h=()=>{this.gl.flush(),this.gl.finish()};this.loop=new Ci(h),this.region=o.Eo.ZERO,this.dpr=1,this.os==="Windows"&&(this.clearProgram=new kc(this))}static create(e,t,s,r,i){const a=new W(t,s,r,i);return e.set(W.CONTEXT_KEY,a),a}static useOptional(e){return e.getOptional(W.CONTEXT_KEY)}static use(e){return e.get(W.CONTEXT_KEY)}update(e){e.set(W.CONTEXT_KEY,this)}resize(e,t){o.Eo.equals(this.region,e)&&this.dpr===t||(this.region=e,this.dpr=t,this.resizeCanvas(this.glCanvas),this.resizeCanvas(this.upper2dCanvas),this.resizeCanvas(this.lower2dCanvas),this.lower2d.scale(this.dpr,this.dpr),this.upper2d.scale(this.dpr,this.dpr),this.gl.viewport(0,0,o.Eo.width(e)*t,o.Eo.height(e)*t))}resizeCanvas(e){e.width=o.Eo.width(this.region)*this.dpr,e.height=o.Eo.height(this.region)*this.dpr}get aspect(){return o.Eo.aspect(this.region)}scaleRegion(e){return new o.k$2.XY(o.k$2.Scale.scale(0,1).scale(o.Eo.width(e)).translate(o.Eo.left(e)).reBound(o.Eo.width(this.region)).scale(-1,1),o.k$2.Scale.scale(0,1).scale(o.Eo.height(e)).invert().translate(o.Eo.top(e)).reBound(o.Eo.height(this.region)).scale(-1,1).invert())}scissor(e,t=o.q.ZERO,s){const r=[];return s.includes("upper2d")&&r.push(this.upper2d.scissor(e,t)),s.includes("lower2d")&&r.push(this.lower2d.scissor(e,t)),s.includes("gl")&&r.push(this.scissorGL(e,t)),()=>r.forEach(i=>i())}scissorGL(e,t=o.q.ZERO){return this.gl.enable(this.gl.SCISSOR_TEST),e=Ie(e,t),this.gl.scissor(o.Eo.left(e)*this.dpr,(o.Eo.height(this.region)-o.Eo.bottom(e))*this.dpr,o.Eo.width(e)*this.dpr,o.Eo.height(e)*this.dpr),()=>this.gl.disable(this.gl.SCISSOR_TEST)}erase(e,t=o.q.ZERO,...s){t=o.q.construct(t),s.length===0&&(s=["upper2d","lower2d","gl"]),s.includes("upper2d")&&this.eraseCanvas(this.upper2d,e,t),s.includes("lower2d")&&this.eraseCanvas(this.lower2d,e,t),s.includes("gl")&&this.eraseGL(e,t)}eraseGL(e,t=o.q.ZERO){var i;const{gl:s}=this,r=this.scissorGL(Ie(e,t));s.clearColor(...o.ZERO.rgba1),s.clear(s.COLOR_BUFFER_BIT),this.os==="Windows"&&((i=this.clearProgram)==null||i.exec()),r()}eraseCanvas(e,t,s=o.q.ZERO){const r=Ie(t,s);e.clearRect(...o.q.couple(o.Eo.topLeft(r)),...o._.couple(o.Eo.dims(r)))}},u(W,"CONTEXT_KEY",o.CSS.B("render-context")),W);const Q="layout",Wn="data",it="tool";var K;let $=(K=class{constructor(e){u(this,"f");this.f=e}static control(e,t){e.set(K.CONTEXT_KEY,new K(t),!1)}static useRequest(e){return e.get(K.CONTEXT_KEY).f}static useOptionalRequest(e){var t;return((t=e.getOptional(K.CONTEXT_KEY))==null?void 0:t.f)??null}static requestRender(e,t){this.useRequest(e)(t)}},u(K,"CONTEXT_KEY","pluto-vis-renderer"),K),Ri=class{constructor(){u(this,"prevErase",o.Eo.ZERO)}erase(e,t,s,r,i){!o.Eo.equals(s,t)&&!o.Eo.equals(this.prevErase,s)?(e.erase(s,r,...i),this.prevErase=s):e.erase(t,r,...i)}};const ze=Ts.extend({bounds:o.G.bounds.optional(),autoBounds:p.z.object({lower:p.z.boolean().optional().default(!0),upper:p.z.boolean().optional().default(!0)}).or(p.z.boolean().optional().default(!0)),autoBoundPadding:p.z.number().optional(),autoBoundUpdateInterval:d.y.z.optional().default(d.y.seconds(2)),size:p.z.number().optional().default(0),label:p.z.string().optional().default(""),labelSize:p.z.number().optional().default(0)}).partial({color:!0,font:!0,gridColor:!0}),Pc=2,Oc=7,ki=(n,e)=>o.G.contains({lower:n-Oc,upper:n+Pc},e),zc=o.G.DECIMAL,or=d.m.now(),Mc={lower:Number(or.valueOf()),upper:Number(or.add(d.y.HOUR).valueOf())},Pi=n=>n==="linear"?zc:Mc,Yc=(n,e=.1,t)=>{const s=o.G.max(n.filter(o.G.isFinite));if(!o.G.isFinite(s))return Pi(t);const{lower:r,upper:i}=s;if(i===r)return{lower:r-1,upper:i+1};const a=(i-r)*e;return{lower:r-a,upper:i+a}},Dc=.01,Ac=.1;class Oi extends d.Composite{async afterUpdate(){var t,s;this.internal.render=q.use(this.ctx);const e=d.use(this.ctx);(t=this.state).autoBoundPadding??(t.autoBoundPadding=o.g.construct(this.state.location)==="x"?Ac:Dc),this.internal.core=new Ei(this.internal.render,{color:e.colors.gray.l8,font:d.fontString(e,{level:"small"}),gridColor:e.colors.gray.l1,...this.state}),$.requestRender(this.ctx,Q),(s=this.internal).updateBounds??(s.updateBounds=d.r(r=>this.setState(i=>({...i,bounds:r})),this.state.autoBoundUpdateInterval.milliseconds))}async afterDelete(){$.requestRender(this.ctx,Q)}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{core:s}=this.internal,{grid:r,container:i}=e,a=to(`${this.type}-${this.key}`,r,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:c}=s.render(l);ki(this.state.size,c)||this.setState(h=>({...h,size:c}))}async bounds(e,t){var h,f;if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:r}=zi(this.state.autoBounds);if(!s&&!r&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=g=>({upper:r||this.state.bounds==null?g.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?g.lower:this.state.bounds.lower});let a,l=null;try{const g=await t();a=Yc(g,this.state.autoBoundPadding,this.state.type)}catch(g){a=Pi(this.state.type),l=g}const c=i(a);return this.internal.boundSnapshot=c,(this.state.bounds==null||s&&this.state.bounds.lower!==c.lower||r&&this.state.bounds.upper!==c.upper)&&((f=(h=this.internal).updateBounds)==null||f.call(h,c)),[c,l]}async dataToDecimalScale(e,t,s){const[r,i]=await this.bounds(e,t),a=o.g.swap(o.g.construct(this.state.location));return[o.k$2.Scale.scale(r).scale(1).translate(-o.Eo.root(s)[a]).magnify(1/o.Eo.dim(s,a)),i]}}const zi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:(n==null?void 0:n.lower)??!0,upper:(n==null?void 0:n.upper)??!0},Lc=`precision lowp float;
|
|
17
17
|
uniform lowp vec4 u_color;
|
|
18
18
|
|
|
19
19
|
void main(void) {
|
|
20
20
|
gl_FragColor = u_color;
|
|
21
21
|
}
|
|
22
|
-
`,
|
|
22
|
+
`,_c=`attribute float a_x;
|
|
23
23
|
attribute float a_y;
|
|
24
24
|
attribute lowp vec2 a_translate;
|
|
25
25
|
|
|
@@ -31,4 +31,4 @@ void main(void) {
|
|
|
31
31
|
transformed = transformed + a_translate;
|
|
32
32
|
gl_Position = vec4(transformed, 0.0, 1.0);
|
|
33
33
|
}
|
|
34
|
-
`,lr=d.g.FLOAT32.density.valueOf(),zi=p.z.object({x:Xe,y:Xe,label:p.z.string().optional(),color:o.Color.z,strokeWidth:p.z.number().default(1),downsample:p.z.number().min(1).max(50).optional().default(1)}),_c=(n,e,t)=>n===-1||e===-1||n>=t.length?NaN:Number(t[n].at(e)),qc=d.y.milliseconds(2);o.q.NAN,o.q.NAN,o.ZERO;const Ct=class Ct extends Ss{constructor(t){super(t,Lc,Ac);u(this,"translationBufferCache",new Map);this.translationBufferCache=new Map}bindState({strokeWidth:t,color:s}){return this.uniformColor("u_color",s),this.attrStrokeWidth(t)}bindScale(t,s){const r=o.q.scale(t.scale,s.scale),i=o.q.translate(o.q.scale(s.scale,t.offset),s.offset);this.uniformXY("u_scale_aggregate",r),this.uniformXY("u_offset_aggregate",i)}draw({x:t,y:s,count:r,downsample:i,xOffset:a,yOffset:l},c){const{gl:h}=this.ctx;this.bindAttrBuffer("x",t.glBuffer,i,a),this.bindAttrBuffer("y",s.glBuffer,i,l),h.drawArraysInstanced(h.LINE_STRIP,0,r/i,c)}static create(t){const s=q.use(t),r=new Ct(s);return t.set(Ct.CONTEXT_KEY,r),r}static use(t){return t.get(Ct.CONTEXT_KEY)}bindAttrBuffer(t,s,r,i=0){const{gl:a}=this.ctx;a.bindBuffer(a.ARRAY_BUFFER,s);const l=a.getAttribLocation(this.prog,`a_${t}`);a.vertexAttribPointer(l,1,a.FLOAT,!1,lr*r,lr*i),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(t){const{gl:s}=this.ctx,r=`${this.ctx.aspect}:${t}`,i=this.translationBufferCache.get(r);if(i!=null)return s.bindBuffer(s.ARRAY_BUFFER,i.glBuffer),i;const a=s.createBuffer();if(a==null)throw new d.Ce("Failed to create buffer from WebGL context");const l=Ic(this.ctx.aspect,t);s.bindBuffer(s.ARRAY_BUFFER,a),s.bufferData(s.ARRAY_BUFFER,l,s.DYNAMIC_DRAW);const c={glBuffer:a,jsBuffer:l};return this.translationBufferCache.set(r,c),c}attrStrokeWidth(t){const{gl:s}=this.ctx,{jsBuffer:r}=this.getAndBindTranslationBuffer(t),i=s.getAttribLocation(this.prog,"a_translate");return s.vertexAttribPointer(i,2,s.FLOAT,!1,0,0),s.enableVertexAttribArray(i),s.vertexAttribDivisor(i,1),r.length/2}};u(Ct,"CONTEXT_KEY","pluto-line-gl-program");let ln=Ct;class pe extends d.Leaf{constructor(){super(...arguments);u(this,"schema",zi)}async afterUpdate(){var s,r;if(this.deleted)return;const{internal:t}=this;t.xTelem=await X(this.ctx,this.state.x,t.xTelem),t.yTelem=await X(this.ctx,this.state.y,t.yTelem),t.instrumentation=ke(this.ctx,"line"),t.prog=ln.use(this.ctx),t.requestRender=$.useRequest(this.ctx),(s=t.stopListeningXTelem)==null||s.call(t),(r=t.stopListeningYTelem)==null||r.call(t),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender(Wn)),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender(Wn)),t.requestRender(Q)}async afterDelete(){var s,r,i,a;const{internal:t}=this;await((r=(s=t.xTelem).cleanup)==null?void 0:r.call(s)),await((a=(i=t.yTelem).cleanup)==null?void 0:a.call(i)),t.requestRender(Q)}async xBounds(){return(await this.internal.xTelem.value())[0]}async yBounds(){return(await this.internal.yTelem.value())[0]}async findByXValue(t,s){const{xTelem:r,yTelem:i}=this.internal,[,a]=await r.value();let[l,c]=[-1,-1];a.find((O,A)=>{const P=O.binarySearch(s),Y=P>=0&&P<O.length;return Y&&([l,c]=[P,A]),Y});const{key:h}=this,{color:f,label:g}=this.state,m={key:h,color:f,label:g,position:{x:0,y:0},value:{x:NaN,y:NaN}};if(l===-1||c===-1)return m;const x=a[c];m.value.x=_c(c,l,a);const[,b]=await i.value(),T=b.find(O=>o.G.contains(O.alignmentBounds,x.alignment+BigInt(l)));if(T==null)return m;const C=Number(T.alignment-x.alignment);return m.value.y=Number(T.at(l-C)),m.position={x:t.dataToDecimalScale.x.pos(m.value.x),y:t.dataToDecimalScale.y.pos(m.value.y)},m}async render(t){if(this.deleted)return;const{downsample:s}=this.state,{xTelem:r,yTelem:i,prog:a}=this.internal,{dataToDecimalScale:l,exposure:c}=t,[[,h],[,f]]=await Promise.all([r.value(),i.value()]);h.forEach(T=>T.updateGLBuffer(a.ctx.gl)),f.forEach(T=>T.updateGLBuffer(a.ctx.gl));const g=Gc(h,f,c,s,qc);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:s,scale:o.k$2.xyScaleToTransform(l),props:t.region,ops:jc(g)}));const m=a.setAsActive(),x=a.bindState(this.state),b=o.k$2.xyScaleToTransform(a.ctx.scaleRegion(t.region));g.forEach(T=>{const C=o.k$2.xyScaleToTransform(Uc(l,T));a.bindScale(C,b),a.draw(T,x)}),m()}}u(pe,"TYPE","line");const $c=5e3,Ic=(n,e)=>Bc(Zc(n),e).map((t,s)=>Math.floor(s/Nc)*(1/($c*n))*t),Nc=5,Zc=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Bc=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},Uc=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Fc={[pe.TYPE]:pe},Gc=(n,e,t,s,r)=>{if(n.length===0||e.length===0)return[];const i=[];return n.forEach(a=>e.forEach(l=>{if(!Hc(a,l,r))return;let c=0,h=0;a.alignment<l.alignment?c=Number(l.alignment-a.alignment):l.alignment<a.alignment&&(h=Number(a.alignment-l.alignment));const f=Math.min(a.length-c,l.length-h);if(f===0)return;const g=o.j(Math.round(t*4*f),s,51);i.push({x:a,y:l,xOffset:c,yOffset:h,count:f,downsample:g})})),i},jc=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Hc=(n,e,t)=>{if(!(n._timeRange!=null&&e._timeRange!=null))throw new d.Ce(`Encountered series without time range in buildDrawOperations. X series present: ${n._timeRange!=null}, Y series present: ${e._timeRange!=null}`);const r=n.timeRange.overlapsWith(e.timeRange,t),i=o.G.overlapsWith(n.alignmentBounds,e.alignmentBounds);return r&&i};class Gt{constructor(e,t){u(this,"canvas");u(this,"theme");this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...r}){return e==="x"?this.line({start:o.q.construct(o.Eo.left(t),s),end:o.q.construct(o.Eo.right(t),s),...r}):this.line({start:o.q.construct(s,o.Eo.top(t)),end:o.q.construct(s,o.Eo.bottom(t)),...r})}line({stroke:e,lineWidth:t,lineDash:s,start:r,end:i}){const a=this.canvas;a.strokeStyle=e.hex,a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...o.q.couple(r)),a.lineTo(...o.q.couple(i)),a.stroke()}circle({fill:e,radius:t,position:s}){const r=this.canvas;r.fillStyle=e.hex,r.beginPath(),r.arc(...o.q.couple(s),t,0,2*Math.PI),r.fill()}resolveColor(e,t){return e==null?this.resolveColor(t):typeof e=="function"?e(this.theme):new o.Color(e)}border({region:e,color:t,width:s,radius:r,location:i}){const a=this.canvas;a.strokeStyle=this.resolveColor(t,this.theme.colors.border).hex,a.lineWidth=s??this.theme.sizes.border.width,r??(r=this.theme.sizes.border.radius),i==null||i===!0?r>0?(a.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),r),a.stroke()):(a.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),a.stroke()):d.A(i).forEach(l=>{const[c,h]=o.Eo.edgePoints(e,l);a.beginPath(),a.moveTo(...o.q.couple(c)),a.lineTo(...o.q.couple(h)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:r,borderRadius:i,borderWidth:a,backgroundColor:l}){i??(i=this.theme.sizes.border.radius),a??(a=1);const c=this.canvas;c.fillStyle=this.resolveColor(l,this.theme.colors.gray.l1).hex,c.strokeStyle=this.resolveColor(r,this.theme.colors.border).hex,c.setLineDash([]),c.lineWidth=1,c.beginPath(),s?c.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),i):c.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),c.fill(),t&&this.border({region:e,color:r,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:r=o.J.TOP_LEFT,offset:i=o.q.ZERO}=e,a={...e.position};r.x==="right"?a.x-=t.width+i.x:a.x+=i.x,r.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:o.Eo.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(o.q.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:r="p"}){const i=d.fontString(this.theme,{level:r}),a=e.map(h=>d.dimensions(h,i,this.canvas)),l=this.theme.sizes.base*s,c=Math.max(...a.map(h=>h[o.g.dimension(t)]))+l;return[{[o.g.dimension(o.g.swap(t))]:Math.max(...a.map(h=>h[o.g.dimension(o.g.swap(t))])),[o.g.dimension(t)]:c*e.length-l},h=>{const f=d.fontString(this.theme,{level:r});this.canvas.font=f,this.canvas.fillStyle=this.theme.colors.text.hex,this.canvas.textBaseline="top",e.forEach((g,m)=>{this.canvas.fillText(g,h.x,h.y+c*m)})}]}drawTextInCenter({box:e,text:t,level:s}){const r=d.dimensions(t,this.canvas.font,this.canvas),i=o.Eo.positionInCenter(o.Eo.construct(o.q.ZERO,r),e);return this.text({text:t,position:o.Eo.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:r,shade:i,maxWidth:a,code:l}){this.canvas.font=d.fontString(this.theme,{level:s,weight:r,code:l}),i==null?this.canvas.fillStyle=this.theme.colors.text.hex:this.canvas.fillStyle=this.theme.colors.gray[`l${i}`].hex,this.canvas.textBaseline="top";let c;a!=null&&(c=this.canvas.scissor(o.Eo.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y),c==null||c()}}const Es=p.z.object({position:p.z.number().optional(),pixelPosition:p.z.number().optional(),dragging:p.z.boolean(),lineWidth:p.z.number().optional().default(1),lineDash:p.z.number().optional().default(20),color:o.Color.z});class It extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Es)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx);const t=d.use(this.ctx);this.internal.draw=new Gt(this.internal.renderCtx.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}updatePositions({decimalToDataScale:t,plot:s,container:r}){if(this.state.dragging&&this.state.pixelPosition!=null){const a=t.pos((this.state.pixelPosition-o.Eo.top(s)+o.Eo.top(r))/o.Eo.height(s));return this.setState(l=>({...l,position:a})),this.state.pixelPosition}if(this.state.position==null){const a=t.pos(.5);this.setState(l=>({...l,position:a}))}const i=t.reverse().pos(this.state.position)*o.Eo.height(s)+o.Eo.top(s)-o.Eo.top(r);return isNaN(i)||this.setState(a=>({...a,pixelPosition:i})),i}async render(t){if(this.deleted)return;const{renderCtx:s}=this.internal,{location:r,plot:i}=t,a=o.J.direction(r),{upper2d:l}=s,c=this.internal.draw;let h=this.updatePositions(t);h+=o.Eo.top(t.container),c.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:h}),l.fillStyle=this.state.color.hex,l.beginPath(),r==="left"?(l.moveTo(o.Eo.left(i),h),l.lineTo(o.Eo.left(i)-5,h-5),l.lineTo(o.Eo.left(i)-5,h+5)):r==="right"&&(l.moveTo(o.Eo.right(i),h),l.lineTo(o.Eo.right(i)+5,h-5),l.lineTo(o.Eo.right(i)+5,h+5)),l.closePath(),l.fill()}}u(It,"TYPE","Rule");const Mi={[It.TYPE]:It},Wc=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Mi,Rule:It,ruleStateZ:Es},Symbol.toStringTag,{value:"Module"})),Xc=ze.extend({location:o.J.x.optional().default("left")});class ge extends Pi{constructor(){super(...arguments);u(this,"schema",ze)}async xBounds(){return o.G.max(await Promise.all(this.lines.map(async t=>await t.xBounds())))}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport),i=s.invert().reverse();if(this.renderAxis(t,i),await this.renderLines(t,s),await this.renderRules(t,i),r!=null)throw r}async renderLines({xDataToDecimalScale:t,plot:s,canvases:r,exposure:i},a){if(!r.includes("gl"))return;const l={region:s,dataToDecimalScale:new o.k$2.XY(t,a),exposure:i};await Promise.all(this.lines.map(async c=>await c.render(l)))}async renderRules({container:t,plot:s,canvases:r},i){if(!r.includes("upper2d"))return;const{location:a}=this.state,{render:l}=this.internal,c=o.Eo.construct(o.Eo.left(t),o.Eo.top(s),o.Eo.width(t),o.Eo.height(s)),h=l.scissor(c,o.q.ZERO,["upper2d"]),f={container:t,plot:s,decimalToDataScale:i,location:a};await Promise.all(this.rules.map(async g=>await g.render(f))),h()}async findByXValue({xDataToDecimalScale:t,plot:s,viewport:r,hold:i,exposure:a},l){const[c,h]=await this.dataToDecimalScale(i,this.dataBounds.bind(this),r);if(h!=null)throw h;const f=new o.k$2.XY(t,c),g={region:s,dataToDecimalScale:f,exposure:a};return(await Promise.all(this.lines.map(async m=>await m.findByXValue(g,l)))).map(m=>({...m,units:this.state.label}))}async dataBounds(){return await Promise.all(this.lines.map(async t=>await t.yBounds()))}get lines(){return this.childrenOfType(pe.TYPE)}get rules(){return this.childrenOfType(It.TYPE)}}u(ge,"TYPE","YAxis");const Yi=p.z.object({start:d.m.z,end:d.m.z});class cn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Yi)}async afterUpdate(){this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,d.use(this.ctx))}async render(){}}u(cn,"TYPE","range-annotation");const Di=p.z.object({triggered:p.z.boolean(),status:d.specZ$1,sink:Sn.optional().default(vn),source:es.optional().default(Qn)});class un extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Di)}async afterUpdate(){var r,i,a;const{sink:t,source:s}=this.state;this.internal.source=await X(this.ctx,s,this.internal.source),this.internal.sink=await Ee(this.ctx,t,this.internal.sink),this.state.triggered&&!this.prevState.triggered&&this.internal.sink.set(((r=this.state.status.data)==null?void 0:r.authority)!==d.Kg.Absolute.valueOf()).catch(console.error),await this.updateEnabledState(),(a=(i=this.internal).stopListening)==null||a.call(i),this.internal.stopListening=this.internal.source.onChange(()=>{this.updateEnabledState()})}async updateEnabledState(){const t=await this.internal.source.value();t.time.equals(this.state.status.time)||this.setState(s=>({...s,status:t,triggered:!1}))}async afterDelete(){this.asyncAfterDelete().catch(console.error)}async asyncAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}render(){}}u(un,"TYPE","Chip");const Ai=p.z.object({}),cr="control-state-provider",Li=d.Og.stateZ.extend({subjectColor:o.Color.z});class Nt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Ai);u(this,"colors",new Map);u(this,"tracker");u(this,"disconnectTrackerChange");u(this,"obs",new Xn.Observer)}static use(t){return t.get(cr)}async afterUpdate(){const{internal:t}=this;t.instrumentation=ke(this.ctx,"control-state");const s=d.use(this.ctx);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l6;const r=Se(this.ctx);t.client!=null&&r===t.client||(t.client=r,this.ctx.set(cr,this),await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client)))}async maybeCloseTracker(){var t;this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),(t=this.disconnectTrackerChange)==null||t.call(this),await this.tracker.close(),this.tracker=void 0)}async afterDelete(){await this.maybeCloseTracker()}onChange(t){return this.obs.onChange(t)}get(t){return Array.isArray(t)?d.n(t).map(s=>this.getOne(s)).filter(s=>s!=null):this.getOne(t)}getOne(t){if(this.tracker==null)return;const s=this.tracker.states.get(t);if(s!=null)return{...s,subjectColor:this.colors.get(s.subject.key)??this.internal.defaultColor}}async openTracker(t){var i;const{internal:s}=this,{instrumentation:r}=s;try{this.tracker=await t.control.openStateTracker()}catch{r.L.error("failed to open state tracker");return}(i=this.disconnectTrackerChange)==null||i.call(this),this.disconnectTrackerChange=this.tracker.onChange(a=>{if(r.L.debug("transfer",{transfers:a.map(l=>d.Og.transferString(l))}),this.tracker==null)throw new d.Ce("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(a)})}updateColors(t){const s=t.subjects(),r=s.map(l=>l.key),i=Array.from(this.colors.values());this.colors.forEach((l,c)=>!r.includes(c)&&this.colors.delete(c));const{palette:a}=this.internal;s.forEach(l=>{if(this.colors.has(l.key))return;const c=a.find(h=>!i.includes(h))??a[0];this.colors.set(l.key,c),i.push(c)})}}u(Nt,"TYPE","StateProvider");const _i=["acquired","released","overridden","failed"],qi=p.z.enum(_i),$i=p.z.object({name:p.z.string(),authority:p.z.number().default(0),acquireTrigger:p.z.number(),status:qi.optional(),needsControlOf:d.dg.keyZ.array().optional().default([])});class hn extends d.Composite{constructor(){super(...arguments);u(this,"schema",$i);u(this,"registry",new Map);u(this,"writer")}async afterUpdate(){this.internal.instrumentation=ke(this.ctx),(this.internal.prevTrigger==null||Math.abs(this.state.acquireTrigger-this.internal.prevTrigger)>1)&&(this.internal.prevTrigger=this.state.acquireTrigger);const t=Se(this.ctx),s=Nt.use(this.ctx);this.internal.client=t,this.internal.client==null&&await this.release(),this.internal.stateProv=s,gr(this.ctx,this),this.internal.addStatus=d.useAggregate(this.ctx),this.state.acquireTrigger>this.internal.prevTrigger?(this.acquire(),this.internal.prevTrigger=this.state.acquireTrigger):this.state.acquireTrigger<this.internal.prevTrigger&&(this.release(),this.internal.prevTrigger=this.state.acquireTrigger)}async afterDelete(){await this.release()}async updateNeedsControlOf(){if(this.internal.client==null)throw new d.Ce("No cluster connected but channelKeys were requested");const t=new Set([]);for(const r of this.registry.keys())(await r.needsControlOf(this.internal.client)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);d.F.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==d.F.EQUAL&&this.setState(r=>({...r,needsControlOf:s}))}async acquire(){const{client:t,addStatus:s}=this.internal;if(t==null)return s({message:`Cannot acquire control on ${this.state.name} because no cluster has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const r=this.state.needsControlOf;if(r.length===0)return s({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});this.writer=await t.openWriter({start:d.I.now(),channels:r,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(r){this.setState(i=>({...i,status:"failed"})),s({message:`${this.state.name} failed to acquire control: ${r.message}`,variant:"error"})}}async release(){var t;try{await((t=this.writer)==null?void 0:t.close()),this.setState(s=>({...s,status:"released"}))}catch(s){this.internal.addStatus({message:`${this.state.name} failed to release control: ${s.message}`,variant:"error"})}finally{this.writer=void 0}}async set(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.write(t))}async setAuthority(t,s){var r;this.writer==null&&await this.acquire(),await((r=this.writer)==null?void 0:r.setAuthority(Object.fromEntries(t.map(i=>[i,s]))))}async releaseAuthority(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.setAuthority(Object.fromEntries(t.map(r=>[r,this.state.authority]))))}deleteTelem(t){this.registry.delete(t),this.updateNeedsControlOf()}create(t){const r=(()=>{switch(t.type){case me.TYPE:{const i=new me(this,t.props);return this.registry.set(i,null),i}case we.TYPE:{const i=new we(this,this.internal.stateProv,t.props);return this.registry.set(i,null),i}case ye.TYPE:return new ye(this,t.props);default:return null}})();return r!=null&&this.updateNeedsControlOf(),r}}u(hn,"TYPE","Controller");const Ii=p.z.object({channel:p.z.number()});class me extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",Ii);this.controller=t}invalidate(){}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){if(this.props.channel===0)return[];const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{client:s}=this.controller.internal;if(s==null)return;const r=await s.channels.retrieve(this.props.channel),i={[r.key]:t};if(r.index!==0){const a=await s.channels.retrieve(r.index);i[a.key]=d.I.now()}await this.controller.set(i)}}u(me,"TYPE","controlled-numeric-telem-sink");const Vc=n=>({type:me.TYPE,props:n,variant:"sink",valueType:"number"}),Ni=p.z.object({authority:p.z.number().default(d.Og.Authority.Absolute.valueOf()),channel:p.z.number()});class ye extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",Ni);this.controller=t}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{controller:s}=this,{client:r}=s.internal;if(r==null)return;const i=await r.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),t?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)}}u(ye,"TYPE","acquire-channel-control");const Kc=n=>({type:ye.TYPE,props:n,variant:"sink",valueType:"boolean"}),Zi=p.z.object({channel:p.z.number()});class we extends G{constructor(t,s,r){super(r);u(this,"prov");u(this,"valid",!1);u(this,"stopListening");u(this,"controller");u(this,"schema",Zi);this.prov=s,this.controller=t}async needsControlOf(){return[]}maybeRevalidate(){var r;if(this.valid)return;const{channel:t}=this.props;(r=this.stopListening)==null||r.call(this);const s=d.W.filterTransfersByChannelKey(t);this.stopListening=this.prov.onChange(i=>{var a;s(i).length!==0&&((a=this.notify)==null||a.call(this))}),this.valid=!0}async value(){this.maybeRevalidate();const t=d.I.now();if(this.props.channel===0)return{key:this.controller.key,variant:"disabled",message:"No Channel",time:t,data:{valid:!1,authority:0}};const s=this.prov.get(this.props.channel);return s==null?{key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:t,data:{valid:!0,color:void 0,authority:0}}:{key:s.subject.key,variant:s.subject.key===this.controller.key?"success":"error",message:`Controlled by ${s.subject.name}`,time:t,data:{valid:!0,color:s.subjectColor,authority:s.authority}}}async cleanup(){var t;this.controller.deleteTelem(this),(t=this.stopListening)==null||t.call(this)}}u(we,"TYPE","controlled-status-source");const Jc=n=>({type:we.TYPE,props:n,variant:"source",valueType:"status"}),Bi=p.z.object({statusSource:es.optional().default(Qn),colorSource:Rr.optional().default(xr),status:d.specZ$1,color:o.Color.z.optional()});class dn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Bi);u(this,"stopListeningStatus");u(this,"stopListeningColor")}async afterUpdate(){var s,r;const{internal:t}=this;t.statusSource=await X(this.ctx,this.state.statusSource,t.statusSource),t.colorSource=await X(this.ctx,this.state.colorSource,t.colorSource),await this.updateState(),(s=this.stopListeningStatus)==null||s.call(this),this.stopListeningStatus=t.statusSource.onChange(()=>{this.updateState()}),(r=this.stopListeningColor)==null||r.call(this),this.stopListeningColor=t.colorSource.onChange(()=>{this.updateState()})}async afterDelete(){this.internalAfterDelete().catch(console.error)}async internalAfterDelete(){var t,s,r,i;await((s=(t=this.internal.statusSource).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.colorSource).cleanup)==null?void 0:i.call(r))}async render(){}async updateState(){const t=await this.internal.colorSource.value(),s=await this.internal.statusSource.value();t.equals(this.state.color)&&s.message===this.state.status.message||this.setState(r=>({...r,color:t,status:s}))}}u(dn,"TYPE","Indicator");const Ui=p.z.object({needsControlOf:d.dg.keyZ.array(),states:Li.array()});class fn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ui)}async afterUpdate(){var a;const{internal:t}=this;t.stateProv=Nt.use(this.ctx);const s=this.state.needsControlOf;(a=t.disconnectStateProv)==null||a.call(t);const r=d.W.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(l=>({...l,states:i})),t.disconnectStateProv=t.stateProv.onChange(l=>{if(r(l).length===0)return;const c=t.stateProv.get(s);this.setState(h=>({...h,states:c}))})}async afterDelete(){var s;const{internal:t}=this;(s=t.disconnectStateProv)==null||s.call(t)}async render(){}}u(fn,"TYPE","Legend");const Qc={[hn.TYPE]:hn,[Nt.TYPE]:Nt,[dn.TYPE]:dn,[un.TYPE]:un,[fn.TYPE]:fn},Fi=p.z.object({trigger:p.z.number(),sink:Sn.optional().default(vn)});class pn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Fi)}async afterUpdate(){var r;const{sink:t}=this.state;(r=this.internal).prevTrigger??(r.prevTrigger=this.state.trigger),this.internal.sink=await Ee(this.ctx,t,this.internal.sink);const s=this.internal.prevTrigger;this.internal.prevTrigger=this.state.trigger,!(this.state.trigger<=s)&&this.internal.sink.set(!0).catch(console.error)}render(){}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var s,r;const{internal:t}=this;await((r=(s=t.sink).cleanup)==null?void 0:r.call(s))}}u(pn,"TYPE","Button");const tu={[pn.TYPE]:pn},Cs=p.z.object({dpr:p.z.number(),region:o.Eo.box,bootstrap:p.z.boolean().optional().default(!1),bootstrapped:p.z.boolean().optional().default(!1),glCanvas:p.z.any().optional(),upper2dCanvas:p.z.any().optional(),lower2dCanvas:p.z.any().optional(),os:d.w.osZ});class xe extends d.Composite{constructor(){super(...arguments);u(this,"schema",Cs);u(this,"renderContextSet",!1)}async afterUpdate(){let t=q.useOptional(this.ctx);if(t==null){if(this.renderContextSet)throw new d.Ce("[vis.worker.Canvas] - expected render context to be set");if(!this.state.bootstrap)return;const{glCanvas:s,lower2dCanvas:r,upper2dCanvas:i,os:a}=this.state;if(s==null||r==null||i==null)throw new d.Ce("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");t=q.create(this.ctx,s,r,i,a),ln.create(this.ctx),this.setState(l=>({...l,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else t.update(this.ctx);t.resize(this.state.region,this.state.dpr)}}u(xe,"TYPE","Canvas");const Gi={[xe.TYPE]:xe},eu=Object.freeze(Object.defineProperty({__proto__:null,Canvas:xe,REGISTRY:Gi,canvasStateZ:Cs},Symbol.toStringTag,{value:"Module"})),Rs=p.z.object({position:o.q.xy,zoom:p.z.number(),region:o.Eo.box,clearOverScan:o.q.crudeZ.optional().default(10),visible:p.z.boolean().optional().default(!0)}),_e=["upper2d","lower2d"],Rt=class Rt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Rt.stateZ)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx),this.internal.addStatus=d.useAggregate(this.ctx),$.control(this.ctx,()=>this.requestRender("low")),this.requestRender("high")}async afterDelete(){this.requestRender("high")}async render(){if(this.deleted)return;const{renderCtx:t,addStatus:s}=this.internal,{zoom:r,position:i}=this.state,a=o.Eo.construct(this.state.region);if(!this.state.visible)return async()=>t.erase(a,this.state.clearOverScan,..._e);const l=t.scissor(a,o.q.ZERO,_e),c=o.k$2.XY.magnify(o.q.construct(r)).translate(o.Eo.topLeft(a)).translate(i);try{await Promise.all(this.children.map(async f=>await f.render({viewportScale:c})))}catch(f){s({variant:"error",message:f.message})}finally{l()}const h=o.Eo.copy(this.state.region);return async()=>{this.internal.renderCtx.erase(h,this.state.clearOverScan,..._e)}}requestRender(t){const{renderCtx:s}=this.internal;s.loop.set({key:`${Rt.TYPE}-${this.key}`,render:this.render.bind(this),priority:t,canvases:_e})}};u(Rt,"TYPE","Diagram"),u(Rt,"stateZ",Rs);let Zt=Rt;const ji={[Zt.TYPE]:Zt},nu=Object.freeze(Object.defineProperty({__proto__:null,Diagram:Zt,REGISTRY:ji,diagramStateZ:Rs},Symbol.toStringTag,{value:"Module"})),Hi=p.z.object({region:o.Eo.box,enabled:p.z.boolean().optional().default(!1)});class gn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Hi);u(this,"eraser",new Ci)}async afterUpdate(){this.deleted||(this.internal.render=q.use(this.ctx),await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]}))}async afterDelete(){await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]})}async render(){this.deleted||!this.state.enabled||this.internal.render.erase(this.state.region,o.q.construct(0),"gl","lower2d","upper2d")}}u(gn,"TYPE","eraser");const su={[gn.TYPE]:gn},Wi=p.z.object({enabled:p.z.boolean(),source:ts.optional().default(Jn)});class mn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Wi)}async afterUpdate(){var r;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{source:t}=this.state,{internal:s}=this;this.internal.source=await X(this.ctx,t,this.internal.source),await this.updateEnabledState(),(r=s.stopListening)==null||r.call(s),s.stopListening=s.source.onChange(()=>this.updateEnabledState().catch(this.reportError.bind(this)))}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Light: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t))}async render(){}}u(mn,"TYPE","Light");const ru={[mn.TYPE]:mn},ks=p.z.object({position:o.q.xy.or(p.z.null()),textColor:o.Color.z.optional().default(o.ZERO),backgroundColor:o.Color.z.optional().default(o.ZERO),borderColor:o.Color.z.optional().default(o.ZERO),ruleColor:o.Color.z.optional().default(o.ZERO),ruleStrokeWidth:p.z.number().optional().default(1),ruleStrokeDash:p.z.number().default(0)});class Bt extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ks)}async afterUpdate(){const t=d.use(this.ctx);this.state.textColor.isZero&&(this.state.textColor=t.colors.text),this.state.backgroundColor.isZero&&(this.state.backgroundColor=t.colors.gray.l1),this.state.borderColor.isZero&&(this.state.borderColor=t.colors.border),this.state.ruleColor.isZero&&(this.state.ruleColor=t.colors.gray.l5),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}async render(t){if(this.deleted||this.state.position==null)return;const{region:s}=t,r=o.k$2.XY.scale(o.Eo.DECIMAL).scale(s),i=o.k$2.XY.scale(s).scale(o.Eo.DECIMAL),a=await t.findByXDecimal(i.x.pos(this.state.position.x)),l=a.filter(b=>o.q.isFinite(b.value)),{draw:c}=this.internal,h=l.reduce((b,T)=>b+T.position.x,0)/l.length,f=new d.m(l.reduce((b,T)=>b+T.value.x,0)/l.length),g=r.x.pos(h);if(!o.G.contains(o.Eo.xBounds(s),g))return;c.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:s,position:g}),l.forEach(b=>{const T=r.pos(b.position);c.circle({fill:b.color.setAlpha(.5),radius:8,position:T}),c.circle({fill:b.color.setAlpha(.8),radius:5,position:T}),c.circle({fill:b.color.pickByContrast(this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:T})});const m=a.map(b=>`${b.label??""}: ${b.value.y.toFixed(2)}`);m.unshift(`Time: ${f.fString("preciseDate","local")}`);const x=i.pos(this.state.position);c.textContainer({text:m,backgroundColor:this.state.backgroundColor,borderColor:this.state.borderColor,position:this.state.position,direction:"y",level:"small",spacing:.5,offset:{x:12,y:12},root:{x:x.x>.8?"right":"left",y:x.y>.8?"top":"bottom"}})}}u(Bt,"TYPE","tooltip");const Xi={[Bt.TYPE]:Bt},iu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Xi,Tooltip:Bt,tooltipStateZ:ks},Symbol.toStringTag,{value:"Module"})),Vi=p.z.object({region:o.Eo.box,wheelPos:p.z.number(),scrolling:p.z.boolean(),empty:p.z.boolean(),visible:p.z.boolean(),telem:Xe.optional().default(br),font:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),overshoot:o.q.xy.optional().default({x:0,y:0})}),au=.98,Xt="lower2d",ou={offset:0n,offsetRef:0n,scrollRef:0},ee=class ee extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ee.z);u(this,"values",new d.Ct([]));u(this,"scrollState",ou)}async afterUpdate(){var c;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem);const{scrolling:s,wheelPos:r}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const h=this.values.alignmentBounds.upper-1n;this.scrollState={offset:h,offsetRef:h,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:h,values:f}=this,g=Math.ceil((r-this.scrollState.scrollRef)/this.lineHeight);h.offset=this.values.traverseAlignment(h.offsetRef,-BigInt(g)),h.offset<f.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(h.offset=f.alignmentBounds.lower,this.setState(m=>({...m,wheelPos:this.prevState.wheelPos}))),h.offset>=f.alignmentBounds.upper&&this.setState(m=>({...m,scrolling:!1}))}const[a,l]=await this.internal.telem.value();this.values=new d.Ct(l),this.checkEmpty(),(c=t.stopListeningTelem)==null||c.call(t),t.stopListeningTelem=t.telem.onChange(()=>this.internal.telem.value().then(([h,f])=>{this.checkEmpty(),this.values=new d.Ct(f),this.requestRender()})),this.requestRender()}checkEmpty(){const t=this.values.length===0;t!==this.state.empty&&this.setState(s=>({...s,empty:t}))}async afterDelete(){var r;const{telem:t,render:s}=this.internal;await((r=t.cleanup)==null?void 0:r.call(t)),s.erase(o.Eo.construct(this.state.region),o.q.ZERO,Xt)}requestRender(){const{render:t}=this.internal;t.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(),priority:"high",canvases:[Xt]})}get lineHeight(){return this.internal.theme.typography[this.state.font].size*this.internal.theme.sizes.base}get totalHeight(){return Math.ceil(this.values.length*this.lineHeight)}get visibleLineCount(){return Math.min(Math.floor((o.Eo.height(this.state.region)-12)/this.lineHeight),this.values.length)}async render(){const{render:t}=this.internal,s=this.state.region;if(o.Eo.areaIsZero(s))return;if(!this.state.visible)return async()=>t.erase(s,o.q.ZERO,Xt);let r;if(!this.state.scrolling)r=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const f=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));r=this.values.subAlignmentSpanIterator(f,this.visibleLineCount)}const i=this.state.region,a=t[Xt],l=new Gt(a,this.internal.theme),c=t.scissor(i,o.q.ZERO,[Xt]);this.renderElements(l,r),this.renderScrollbar(l),c();const h=o.Eo.copy(this.state.region);return async({canvases:f})=>t.erase(h,this.state.overshoot,...f)}renderScrollbar(t){const s=this.state.region,r=o.Eo.height(s)/this.totalHeight*o.Eo.height(s);if(r>=o.Eo.height(s)*au)return;let i=o.Eo.bottom(s)-r;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*o.Eo.height(s)),i<0&&(i=o.Eo.top(s)),t.container({region:o.Eo.construct({x:o.Eo.right(s)-6,y:i},{width:6,height:r}),bordered:!1,backgroundColor:a=>a.colors.gray.l4})}renderElements(t,s){const r=this.state.region;let i=0;for(const a of s){const l=this.values.dataType.equals(d.g.JSON)?JSON.stringify(a):a.toString();t.text({text:l,level:this.state.font,shade:9,position:o.q.translate(o.Eo.topLeft(r),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}};u(ee,"TYPE","log"),u(ee,"z",Vi);let be=ee;const lu={[be.TYPE]:be},Ps=p.z.object({one:o.q.xy.nullable(),two:o.q.xy.nullable(),hover:o.q.xy.nullable(),color:p.z.union([o.Color.z,p.z.object({verticalLine:o.Color.z.optional().default(o.ZERO),horizontalLine:o.Color.z.optional().default(o.ZERO),obliqueLine:o.Color.z.optional().default(o.ZERO)})]).optional().default(o.ZERO),strokeWidth:p.z.number().optional().default(1),strokeDash:p.z.number().optional().default(2)});class Ut extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ps)}async afterUpdate(){const t=q.use(this.ctx);this.internal.theme=d.use(this.ctx),this.internal.render=t,this.internal.draw=new Gt(t.upper2d,this.internal.theme),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,Q)}get verticalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.verticalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.verticalLine}get horizontalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.horizontalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.horizontalLine}get obliqueLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.obliqueLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.obliqueLine}async find(t){const{one:s,two:r}=this.state;if(s==null||r==null)return null;const{one:i,two:a}=this.prevState,{dataOne:l,dataTwo:c}=this.internal;if(i!=null&&o.q.equals(s,i)&&a!=null&&o.q.equals(r,a)&&l!=null&&c!=null){const[C,O]=[await t.findByXValue(l.x),await t.findByXValue(c.x)];return C.length===0||O.length===0?null:[C.sort((A,P)=>o.q.distance(l,A.value)-o.q.distance(l,P.value))[0],O.sort((A,P)=>o.q.distance(c,A.value)-o.q.distance(c,P.value))[0]]}const h=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),[f,g]=[h.pos(s),h.pos(r)],[m,x]=[await t.findByXDecimal(f.x),await t.findByXDecimal(g.x)];if(m.length===0||x.length===0)return null;const[b,T]=[m.sort((C,O)=>o.q.distance(f,C.position)-o.q.distance(f,O.position))[0],x.sort((C,O)=>o.q.distance(g,C.position)-o.q.distance(g,O.position))[0]];return this.internal.dataOne=b.value,this.internal.dataTwo=T.value,[b,T]}async renderHover(t){if(this.state.hover==null)return;const s=this.state.hover,r=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),i=r.pos(s),a=await t.findByXDecimal(r.pos(s).x);if(a.length===0)return;const l=a.sort((h,f)=>o.q.distance(i,h.position)-o.q.distance(i,f.position))[0],{draw:c}=this.internal;c.circle({fill:l.color.setAlpha(.5),radius:9,position:r.reverse().pos(l.position)})}async render(t){if(this.deleted)return;await this.renderHover(t);const s=await this.find(t);if(s==null)return;const[r,i]=s,{draw:a}=this.internal,{strokeDash:l,strokeWidth:c}=this.state,h=o.k$2.XY.scale(o.Eo.DECIMAL).scale(t.region),f=h.pos(r.position),g=h.pos(i.position),m=new d.y(Math.abs(r.value.x-i.value.x)),x=Math.abs(r.value.y-i.value.y),b=x/m.seconds;a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(f.x,g.y),stroke:this.verticalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${x.toFixed(2)} ${r.units??""}`],direction:"x",position:o.q.construct(f.x,(f.y+g.y)/2),level:"small"}),a.line({start:o.q.construct(f.x,g.y),end:o.q.construct(g.x,g.y),stroke:this.horizontalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[m.truncate(d.y.MILLISECOND).toString()],direction:"x",position:o.q.construct((f.x+g.x)/2,g.y),level:"small"}),a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(g.x,g.y),stroke:this.obliqueLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${b.toFixed(2)} ${r.units??""} / S`],direction:"x",position:o.q.construct((f.x+g.x)/2,(f.y+g.y)/2),level:"small"}),a.circle({fill:r.color.setAlpha(.5),radius:8,position:f}),a.circle({fill:r.color.setAlpha(.8),radius:5,position:f}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:f}),a.circle({fill:i.color.setAlpha(.5),radius:8,position:g}),a.circle({fill:i.color.setAlpha(.8),radius:5,position:g}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:g})}}u(Ut,"TYPE","measure");const Ki={[Ut.TYPE]:Ut},cu=Object.freeze(Object.defineProperty({__proto__:null,Measure:Ut,REGISTRY:Ki,measureStateZ:Ps},Symbol.toStringTag,{value:"Module"})),Ji=p.z.object({trigger:p.z.number(),command:p.z.number().optional(),value:p.z.number(),sink:Cr.optional().default(mr),source:Er.optional().default(yr)});class yn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ji)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,trigger:r,command:i}=this.state,{trigger:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r!==a&&i!=null&&this.internal.sink.set(i),await this.updateValue(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateValue().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Setpoint: ${t.message}`})}async updateValue(){const t=await this.internal.source.value();t!==this.state.value&&this.setState(s=>({...s,value:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(yn,"TYPE","Setpoint");const uu={[yn.TYPE]:yn},Qi=p.z.object({triggered:p.z.boolean(),enabled:p.z.boolean(),sink:Sn.optional().default(vn),source:ts.optional().default(Jn)});class wn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Qi)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,triggered:r,enabled:i}=this.state,{triggered:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r&&!a&&await l.sink.set(!i),await this.updateEnabledState(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateEnabledState().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Toggle: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(wn,"TYPE","Toggle");const hu={[wn.TYPE]:wn},du=p.z.object({box:o.Eo.box,telem:kr.optional().default(wr),level:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),precision:p.z.number().optional().default(2),minWidth:p.z.number().optional().default(60),width:p.z.number().optional(),notation:Br.optional().default("standard")}),ur="upper2d",ne=class ne extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ne.z)}async afterUpdate(){var s;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem),(s=t.stopListening)==null||s.call(t),t.stopListening=this.internal.telem.onChange(()=>this.requestRender()),this.internal.requestRender=$.useOptionalRequest(this.ctx),this.requestRender()}async afterDelete(){var i;const{requestRender:t,telem:s,render:r}=this.internal;await((i=s.cleanup)==null?void 0:i.call(s)),t==null?r.erase(o.Eo.construct(this.state.box),o.q.ZERO,ur):t(Q)}requestRender(){const{requestRender:t}=this.internal;t!=null?t(Q):this.render({})}get fontHeight(){const{theme:t}=this.internal;return t.typography[this.state.level].size*t.sizes.base}maybeUpdateWidth(t){const{theme:s}=this.internal,r=t+s.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<r||this.state.minWidth>r&&this.state.width!==this.state.minWidth?this.setState(i=>({...i,width:Math.max(r,i.minWidth)})):this.state.width-this.fontHeight>r&&this.setState(i=>({...i,width:Math.max(r,i.minWidth)}))}async render({viewportScale:t=o.k$2.XY.IDENTITY}){const{render:s,telem:r}=this.internal,i=o.Eo.construct(this.state.box);if(o.Eo.areaIsZero(i))return;const a=s[ur].applyScale(t);let l=await r.value();const c=d.fontString(this.internal.theme,{level:this.state.level,code:!0});a.font=c;const h=this.fontHeight,f=l[0]=="-";f&&(l=l.slice(1));const{theme:g}=this.internal,m=d.dimensions(l,c,a).width+g.sizes.base;this.internal.requestRender==null&&s.erase(o.Eo.construct(this.prevState.box)),this.maybeUpdateWidth(m);const x=o.q.translate(o.Eo.topLeft(i),{x:6+h*.75,y:o.Eo.height(i)/2});a.textBaseline="middle",a.fillStyle=this.internal.textColor.hex,f&&a.fillText("-",...o.q.couple(o.q.translateX(x,-h*.6))),a.fillText(l,...o.q.couple(x))}};u(ne,"TYPE","value"),u(ne,"z",du);let Ft=ne;const ta={[Ft.TYPE]:Ft},fu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ta,Value:Ft},Symbol.toStringTag,{value:"Module"})),pu=d.Bg.payloadZ.extend({viewport:o.G.bounds}),hr=n=>o.Color.z.safeParse(n).success,ea=p.z.object({cursor:o.q.xy.or(p.z.null()),hovered:pu.or(p.z.null()),count:p.z.number()});class ve extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ea);u(this,"fetchedInitial",d.E.ZERO)}async afterUpdate(){const{internal:t}=this;t.render=q.use(this.ctx),t.draw=new Gt(t.render.upper2d,d.use(this.ctx)),t.ranges??(t.ranges=new Map);const s=Se(this.ctx);s!=null&&(t.client=s,t.tracker==null&&(t.tracker=await t.client.ranges.openTracker(),t.tracker.onChange(async r=>{r.forEach(async i=>{i.variant==="delete"?t.ranges.delete(i.key):hr(i.value.color)&&t.ranges.set(i.key,i.value)}),$.requestRender(this.ctx,it),this.setState(i=>({...i,count:t.ranges.size}))}),$.requestRender(this.ctx,it)))}async fetchInitial(t){const{internal:s}=this;if(s.client==null||this.fetchedInitial.roughlyEquals(t,d.y.minutes(1)))return;this.fetchedInitial=t,(await s.client.ranges.retrieve(t)).forEach(i=>{hr(i.color)&&s.ranges.set(i.key,i)}),this.setState(i=>({...i,count:s.ranges.size}))}async render(t){const{dataToDecimalScale:s,region:r,viewport:i,timeRange:a}=t;await this.fetchInitial(a);const{draw:l,ranges:c}=this.internal,h=s.scale(o.Eo.xBounds(r)),f=this.state.cursor==null?null:this.state.cursor.x;let g=null;const m=l.canvas.scissor(o.Eo.construct({x:o.Eo.left(r),y:o.Eo.top(r)-35},{x:o.Eo.right(r),y:o.Eo.bottom(r)}));c.forEach(x=>{const b=o.Color.z.safeParse(x.color);if(!b.success)return;const T=b.data;let C=h.pos(Number(x.timeRange.start.valueOf()));const O=h.pos(Number(x.timeRange.end.valueOf()));if(O<o.Eo.left(r)||C>o.Eo.right(r))return;C=o.j(C,o.Eo.left(r)-2,o.Eo.right(r)-1);let A=!1;f!=null&&(A=o.G.contains({lower:C,upper:O},f)),A&&(g={key:x.key,name:x.name,color:x.color,timeRange:x.timeRange,viewport:{lower:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.start.valueOf())),upper:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.end.valueOf()))}}),l.container({region:o.Eo.construct({x:C,y:o.Eo.top(r)-1},{x:O,y:o.Eo.bottom(r)-1}),backgroundColor:T.setAlpha(.2),bordered:!1});const P=o.Eo.construct({x:C+1,y:o.Eo.top(r)-34},{x:O-1,y:o.Eo.top(r)-12});l.container({region:P,backgroundColor:o.Eo.width(P)<20?T.setAlpha(.4):Y=>A?Y.colors.gray.l2:Y.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:T.setAlpha(.8)}),l.text({text:x.name,position:{x:C+8,y:o.Eo.top(r)-30},level:"small",shade:8,weight:500,maxWidth:O-C-16})}),m(),g!=null?this.setState(x=>({...x,hovered:g})):this.state.hovered&&this.setState(x=>({...x,hovered:null}))}}u(ve,"TYPE","range-provider");const gu={[cn.TYPE]:cn,[ve.TYPE]:ve},mu=ze;class Te extends Pi{constructor(){super(...arguments);u(this,"schema",ze)}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(this.renderAxis(t,s.reverse()),await this.renderYAxes(t,s),await this.renderRangeAnnotations(t,s),r!=null)throw r}async findByXDecimal(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;return await this.findByXValue(t,r.reverse().pos(s))}async findByXValue(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;const a={...t,xDataToDecimalScale:r},l=this.yAxes.map(async c=>await c.findByXValue(a,s));return(await Promise.all(l)).flat()}async renderYAxes(t,s){const r={...t,xDataToDecimalScale:s};await Promise.all(this.yAxes.map(async i=>await i.render(r)))}get yAxes(){return this.childrenOfType(ge.TYPE)}get rangeAnnotations(){return this.childrenOfType(ve.TYPE)}async renderRangeAnnotations(t,s){const[r,i]=await this.bounds(t.hold,this.dataBounds.bind(this));if(i!=null)throw i;await Promise.all(this.rangeAnnotations.map(async a=>await a.render({dataToDecimalScale:s,region:t.plot,viewport:t.viewport,timeRange:new d.E(r.lower,r.upper)})))}async dataBounds(){return await Promise.all(this.yAxes.map(async t=>await t.xBounds()))}}u(Te,"TYPE","XAxis");const na=p.z.object({container:o.Eo.box,viewport:o.Eo.box,hold:p.z.boolean().optional().default(!1),grid:p.z.record(si),visible:p.z.boolean().optional().default(!0),clearOverScan:o.q.crudeZ.optional().default(o.q.ZERO)}),yu=(n,e)=>{const t=o.Eo.width(n)*Math.sqrt(o.Eo.height(n)),s=o.Eo.width(e)*Math.sqrt(o.Eo.height(e));return t/s};class xn extends d.Composite{constructor(){super(...arguments);u(this,"schema",na)}async afterUpdate(){this.internal.instrumentation=ke(this.ctx,"lineplot"),this.internal.aggregate=d.useAggregate(this.ctx),this.internal.renderCtx=q.use(this.ctx),$.control(this.ctx,t=>this.requestRender("low",t)),this.requestRender("high",Q)}async afterDelete(){this.internal.renderCtx=q.use(this.ctx),this.requestRender("high",Q)}async findByXDecimal(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXDecimal(s,t));return(await Promise.all(r)).flat()}async findByXValue(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXValue(s,t));return(await Promise.all(r)).flat()}get axes(){return this.childrenOfType(Te.TYPE)}get tooltips(){return this.childrenOfType(Bt.TYPE)}get measures(){return this.childrenOfType(Ut.TYPE)}get exposure(){return yu(this.state.viewport,this.state.container)}async renderAxes(t,s){const r={...this.state,plot:t,canvases:s,exposure:this.exposure};await Promise.all(this.axes.map(async i=>await i.render(r)))}async renderTooltips(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),region:t,canvases:s};await Promise.all(this.tooltips.map(async i=>await i.render(r)))}async renderMeasures(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:t,canvases:s};await Promise.all(this.measures.map(async i=>await i.render(r)))}calculatePlot(){return to(this.state.grid,this.state.container)}async render(t){const{renderCtx:s}=this.internal,{instrumentation:r}=this.internal;if(this.deleted){r.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return r.L.debug("not visible, skipping render",{key:this.key}),async({canvases:f})=>s.erase(this.state.container,this.state.clearOverScan,...f);const i=this.calculatePlot();r.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:t});const a=o.q.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,t.filter(f=>f!=="gl")),c=s.scissor(i,o.q.ZERO,t.filter(f=>f==="gl"));try{await this.renderAxes(i,t),await this.renderTooltips(i,t),await this.renderMeasures(i,t),s.gl.finish(),s.gl.flush(),s.gl.finish()}catch(f){if(f.message.toLowerCase().includes("bigint"))return;this.internal.aggregate({key:`${this.type}-${this.key}`,variant:"error",message:f.message})}finally{l(),c()}r.L.debug("rendered",{key:this.key});const h=o.Eo.copy(this.state.container);return async({canvases:f})=>s.erase(h,this.state.clearOverScan,...f)}requestRender(t,s){const{renderCtx:r}=this.internal;let i=["upper2d","lower2d","gl"];s===it&&(i=["upper2d"]),r.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(i),priority:t,canvases:i})}}u(xn,"TYPE","LinePlot");const wu={[xn.TYPE]:xn,[Te.TYPE]:Te,[ge.TYPE]:ge};exports.AcquireChannelControl=ye;exports.Annotation=cn;exports.AuthoritySource=we;exports.BaseProvider=At;exports.Button=pn;exports.Canvas=Si;exports.Canvas$1=xe;exports.Chip=un;exports.Context=q;exports.Controller=$;exports.Controller$1=hn;exports.Diagram=nu;exports.Diagram$1=Zt;exports.Eraser=Ci;exports.Eraser$1=gn;exports.GLProgram=Ss;exports.Indicator=dn;exports.Legend=fn;exports.Light=mn;exports.Line=pe;exports.LinePlot=xn;exports.Log=be;exports.Loop=Ei;exports.Measure=Ut;exports.Provider=Ne;exports.Provider$1=ve;exports.Provider$2=Nn;exports.REASON_DATA=Wn;exports.REASON_LAYOUT=Q;exports.REASON_TOOL=it;exports.REGISTRY=qa;exports.REGISTRY$1=tu;exports.REGISTRY$10=gu;exports.REGISTRY$11=Mi;exports.REGISTRY$12=uu;exports.REGISTRY$13=dr;exports.REGISTRY$14=ni;exports.REGISTRY$15=hu;exports.REGISTRY$16=Xi;exports.REGISTRY$17=ta;exports.REGISTRY$18=lu;exports.REGISTRY$2=Gi;exports.REGISTRY$3=Qc;exports.REGISTRY$4=ji;exports.REGISTRY$5=su;exports.REGISTRY$6=ru;exports.REGISTRY$7=Fc;exports.REGISTRY$8=wu;exports.REGISTRY$9=Ki;exports.Rule=It;exports.STATUSES=_i;exports.SetChannelValue=me;exports.Setpoint=yn;exports.StateProvider=Nt;exports.Toggle=wn;exports.Tooltip=Bt;exports.Value=Ft;exports.XAxis=Te;exports.YAxis=ge;exports.ZERO_CONTEXT_VALUE=Vn;exports.acquireChannelControl=Kc;exports.acquireChannelControlPropsZ=Ni;exports.aether=Wc;exports.annotationStateZ=Yi;exports.authoritySource=Jc;exports.authoritySourceProps=Zi;exports.axisStateZ=Ts;exports.buttonStateZ=Fi;exports.canvas=eu;exports.canvasStateZ=Cs;exports.channelData=Lr;exports.chipStateZ=Di;exports.color=Lt;exports.controllerStateZ=$i;exports.coreAxisStateZ=ze;exports.diagramStateZ=Rs;exports.eraserStateZ=Hi;exports.external=Ja;exports.indicatorStateZ=Bi;exports.interpolateNumber=fe;exports.interpolateRgb=Fn;exports.interpolateString=li;exports.legendStateZ=Ui;exports.lightStateZ=Wi;exports.linePlotStateZ=na;exports.logState=Vi;exports.measure=cu;exports.measureStateZ=Ps;exports.newTickFactory=Hn;exports.parseAutoBounds=Oi;exports.provider=xa;exports.providerStateZ=ea;exports.providerStateZ$1=Jr;exports.providerStateZ$2=cs;exports.regions=dt;exports.rollingAverage=Xr;exports.rollingAverageProps=ls;exports.ruleStateZ=Es;exports.setChannelValue=Vc;exports.setChannelValuePropsZ=Ii;exports.setpoint=Fr;exports.setpointStateZ=Ji;exports.sinkPipeline=Dr;exports.sinkPipelinePropsZ=ss;exports.sourcePipeline=Yr;exports.sourcePipelinePropsZ=ns;exports.stateProviderStateZ=Ai;exports.stateZ=zi;exports.statusZ=qi;exports.streamChannelData=_r;exports.streamChannelValue=qr;exports.streamChannelValuePropsZ=rs;exports.stringifyNumber=Wr;exports.stringifyNumberProps=os;exports.sugaredStateZ=Li;exports.tickFactoryProps=vs;exports.tickType=bs;exports.toggleStateZ=Qi;exports.tooltip=iu;exports.tooltipStateZ=ks;exports.value=fu;exports.withinBounds=Gr;exports.withinSizeThreshold=Ri;exports.xAxisStateZ=mu;exports.yAxisStateZ=Xc;
|
|
34
|
+
`,lr=d.g.FLOAT32.density.valueOf(),Mi=p.z.object({x:Xe,y:Xe,label:p.z.string().optional(),color:o.Color.z,strokeWidth:p.z.number().default(1),downsample:p.z.number().min(1).max(50).optional().default(1)}),qc=(n,e,t)=>n===-1||e===-1||n>=t.length?NaN:Number(t[n].at(e)),$c=d.y.milliseconds(2);o.q.NAN,o.q.NAN,o.ZERO;const Ct=class Ct extends Ss{constructor(t){super(t,_c,Lc);u(this,"translationBufferCache",new Map);this.translationBufferCache=new Map}bindState({strokeWidth:t,color:s}){return this.uniformColor("u_color",s),this.attrStrokeWidth(t)}bindScale(t,s){const r=o.q.scale(t.scale,s.scale),i=o.q.translate(o.q.scale(s.scale,t.offset),s.offset);this.uniformXY("u_scale_aggregate",r),this.uniformXY("u_offset_aggregate",i)}draw({x:t,y:s,count:r,downsample:i,xOffset:a,yOffset:l},c){const{gl:h}=this.ctx;this.bindAttrBuffer("x",t.glBuffer,i,a),this.bindAttrBuffer("y",s.glBuffer,i,l),h.drawArraysInstanced(h.LINE_STRIP,0,r/i,c)}static create(t){const s=q.use(t),r=new Ct(s);return t.set(Ct.CONTEXT_KEY,r),r}static use(t){return t.get(Ct.CONTEXT_KEY)}bindAttrBuffer(t,s,r,i=0){const{gl:a}=this.ctx;a.bindBuffer(a.ARRAY_BUFFER,s);const l=a.getAttribLocation(this.prog,`a_${t}`);a.vertexAttribPointer(l,1,a.FLOAT,!1,lr*r,lr*i),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(t){const{gl:s}=this.ctx,r=`${this.ctx.aspect}:${t}`,i=this.translationBufferCache.get(r);if(i!=null)return s.bindBuffer(s.ARRAY_BUFFER,i.glBuffer),i;const a=s.createBuffer();if(a==null)throw new d.Ce("Failed to create buffer from WebGL context");const l=Nc(this.ctx.aspect,t);s.bindBuffer(s.ARRAY_BUFFER,a),s.bufferData(s.ARRAY_BUFFER,l,s.DYNAMIC_DRAW);const c={glBuffer:a,jsBuffer:l};return this.translationBufferCache.set(r,c),c}attrStrokeWidth(t){const{gl:s}=this.ctx,{jsBuffer:r}=this.getAndBindTranslationBuffer(t),i=s.getAttribLocation(this.prog,"a_translate");return s.vertexAttribPointer(i,2,s.FLOAT,!1,0,0),s.enableVertexAttribArray(i),s.vertexAttribDivisor(i,1),r.length/2}};u(Ct,"CONTEXT_KEY","pluto-line-gl-program");let ln=Ct;class pe extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Mi)}async afterUpdate(){var s,r;if(this.deleted)return;const{internal:t}=this;t.xTelem=await X(this.ctx,this.state.x,t.xTelem),t.yTelem=await X(this.ctx,this.state.y,t.yTelem),t.instrumentation=ke(this.ctx,"line"),t.prog=ln.use(this.ctx),t.requestRender=$.useRequest(this.ctx),(s=t.stopListeningXTelem)==null||s.call(t),(r=t.stopListeningYTelem)==null||r.call(t),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender(Wn)),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender(Wn)),t.requestRender(Q)}async afterDelete(){var s,r,i,a;const{internal:t}=this;await((r=(s=t.xTelem).cleanup)==null?void 0:r.call(s)),await((a=(i=t.yTelem).cleanup)==null?void 0:a.call(i)),t.requestRender(Q)}async xBounds(){return(await this.internal.xTelem.value())[0]}async yBounds(){return(await this.internal.yTelem.value())[0]}async findByXValue(t,s){const{xTelem:r,yTelem:i}=this.internal,[,a]=await r.value();let[l,c]=[-1,-1];a.find((O,A)=>{const P=O.binarySearch(s),Y=P>=0&&P<O.length;return Y&&([l,c]=[P,A]),Y});const{key:h}=this,{color:f,label:g}=this.state,m={key:h,color:f,label:g,position:{x:0,y:0},value:{x:NaN,y:NaN}};if(l===-1||c===-1)return m;const x=a[c];m.value.x=qc(c,l,a);const[,b]=await i.value(),T=b.find(O=>o.G.contains(O.alignmentBounds,x.alignment+BigInt(l)));if(T==null)return m;const C=Number(T.alignment-x.alignment);return m.value.y=Number(T.at(l-C)),m.position={x:t.dataToDecimalScale.x.pos(m.value.x),y:t.dataToDecimalScale.y.pos(m.value.y)},m}async render(t){if(this.deleted)return;const{downsample:s}=this.state,{xTelem:r,yTelem:i,prog:a}=this.internal,{dataToDecimalScale:l,exposure:c}=t,[[,h],[,f]]=await Promise.all([r.value(),i.value()]);h.forEach(T=>T.updateGLBuffer(a.ctx.gl)),f.forEach(T=>T.updateGLBuffer(a.ctx.gl));const g=jc(h,f,c,s,$c);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:s,scale:o.k$2.xyScaleToTransform(l),props:t.region,ops:Hc(g)}));const m=a.setAsActive(),x=a.bindState(this.state),b=o.k$2.xyScaleToTransform(a.ctx.scaleRegion(t.region));g.forEach(T=>{const C=o.k$2.xyScaleToTransform(Fc(l,T));a.bindScale(C,b),a.draw(T,x)}),m()}}u(pe,"TYPE","line");const Ic=5e3,Nc=(n,e)=>Uc(Bc(n),e).map((t,s)=>Math.floor(s/Zc)*(1/(Ic*n))*t),Zc=5,Bc=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Uc=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},Fc=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Gc={[pe.TYPE]:pe},jc=(n,e,t,s,r)=>{if(n.length===0||e.length===0)return[];const i=[];return n.forEach(a=>e.forEach(l=>{if(!Wc(a,l,r))return;let c=0,h=0;a.alignment<l.alignment?c=Number(l.alignment-a.alignment):l.alignment<a.alignment&&(h=Number(a.alignment-l.alignment));const f=Math.min(a.length-c,l.length-h);if(f===0)return;const g=o.j(Math.round(t*4*f),s,51);i.push({x:a,y:l,xOffset:c,yOffset:h,count:f,downsample:g})})),i},Hc=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Wc=(n,e,t)=>{if(!(n._timeRange!=null&&e._timeRange!=null))throw new d.Ce(`Encountered series without time range in buildDrawOperations. X series present: ${n._timeRange!=null}, Y series present: ${e._timeRange!=null}`);const r=n.timeRange.overlapsWith(e.timeRange,t),i=o.G.overlapsWith(n.alignmentBounds,e.alignmentBounds);return r&&i};class Gt{constructor(e,t){u(this,"canvas");u(this,"theme");this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...r}){return e==="x"?this.line({start:o.q.construct(o.Eo.left(t),s),end:o.q.construct(o.Eo.right(t),s),...r}):this.line({start:o.q.construct(s,o.Eo.top(t)),end:o.q.construct(s,o.Eo.bottom(t)),...r})}line({stroke:e,lineWidth:t,lineDash:s,start:r,end:i}){const a=this.canvas;a.strokeStyle=e.hex,a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...o.q.couple(r)),a.lineTo(...o.q.couple(i)),a.stroke()}circle({fill:e,radius:t,position:s}){const r=this.canvas;r.fillStyle=e.hex,r.beginPath(),r.arc(...o.q.couple(s),t,0,2*Math.PI),r.fill()}resolveColor(e,t){return e==null?this.resolveColor(t):typeof e=="function"?e(this.theme):new o.Color(e)}border({region:e,color:t,width:s,radius:r,location:i}){const a=this.canvas;a.strokeStyle=this.resolveColor(t,this.theme.colors.border).hex,a.lineWidth=s??this.theme.sizes.border.width,r??(r=this.theme.sizes.border.radius),i==null||i===!0?r>0?(a.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),r),a.stroke()):(a.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),a.stroke()):d.A(i).forEach(l=>{const[c,h]=o.Eo.edgePoints(e,l);a.beginPath(),a.moveTo(...o.q.couple(c)),a.lineTo(...o.q.couple(h)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:r,borderRadius:i,borderWidth:a,backgroundColor:l}){i??(i=this.theme.sizes.border.radius),a??(a=1);const c=this.canvas;c.fillStyle=this.resolveColor(l,this.theme.colors.gray.l1).hex,c.strokeStyle=this.resolveColor(r,this.theme.colors.border).hex,c.setLineDash([]),c.lineWidth=1,c.beginPath(),s?c.roundRect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e)),i):c.rect(...o.q.couple(o.Eo.topLeft(e)),...o.q.couple(o.Eo.dims(e))),c.fill(),t&&this.border({region:e,color:r,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:r=o.J.TOP_LEFT,offset:i=o.q.ZERO}=e,a={...e.position};r.x==="right"?a.x-=t.width+i.x:a.x+=i.x,r.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:o.Eo.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(o.q.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:r="p"}){const i=d.fontString(this.theme,{level:r}),a=e.map(h=>d.dimensions(h,i,this.canvas)),l=this.theme.sizes.base*s,c=Math.max(...a.map(h=>h[o.g.dimension(t)]))+l;return[{[o.g.dimension(o.g.swap(t))]:Math.max(...a.map(h=>h[o.g.dimension(o.g.swap(t))])),[o.g.dimension(t)]:c*e.length-l},h=>{const f=d.fontString(this.theme,{level:r});this.canvas.font=f,this.canvas.fillStyle=this.theme.colors.text.hex,this.canvas.textBaseline="top",e.forEach((g,m)=>{this.canvas.fillText(g,h.x,h.y+c*m)})}]}drawTextInCenter({box:e,text:t,level:s}){const r=d.dimensions(t,this.canvas.font,this.canvas),i=o.Eo.positionInCenter(o.Eo.construct(o.q.ZERO,r),e);return this.text({text:t,position:o.Eo.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:r,shade:i,maxWidth:a,code:l}){this.canvas.font=d.fontString(this.theme,{level:s,weight:r,code:l}),i==null?this.canvas.fillStyle=this.theme.colors.text.hex:this.canvas.fillStyle=this.theme.colors.gray[`l${i}`].hex,this.canvas.textBaseline="top";let c;a!=null&&(c=this.canvas.scissor(o.Eo.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y),c==null||c()}}const Es=p.z.object({position:p.z.number().optional(),pixelPosition:p.z.number().optional(),dragging:p.z.boolean(),lineWidth:p.z.number().optional().default(1),lineDash:p.z.number().optional().default(20),color:o.Color.z});class It extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Es)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx);const t=d.use(this.ctx);this.internal.draw=new Gt(this.internal.renderCtx.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}updatePositions({decimalToDataScale:t,plot:s,container:r}){if(this.state.dragging&&this.state.pixelPosition!=null){const a=t.pos((this.state.pixelPosition-o.Eo.top(s)+o.Eo.top(r))/o.Eo.height(s));return this.setState(l=>({...l,position:a})),this.state.pixelPosition}if(this.state.position==null){const a=t.pos(.5);this.setState(l=>({...l,position:a}))}const i=t.reverse().pos(this.state.position)*o.Eo.height(s)+o.Eo.top(s)-o.Eo.top(r);return isNaN(i)||this.setState(a=>({...a,pixelPosition:i})),i}async render(t){if(this.deleted)return;const{renderCtx:s}=this.internal,{location:r,plot:i}=t,a=o.J.direction(r),{upper2d:l}=s,c=this.internal.draw;let h=this.updatePositions(t);h+=o.Eo.top(t.container),c.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:h}),l.fillStyle=this.state.color.hex,l.beginPath(),r==="left"?(l.moveTo(o.Eo.left(i),h),l.lineTo(o.Eo.left(i)-5,h-5),l.lineTo(o.Eo.left(i)-5,h+5)):r==="right"&&(l.moveTo(o.Eo.right(i),h),l.lineTo(o.Eo.right(i)+5,h-5),l.lineTo(o.Eo.right(i)+5,h+5)),l.closePath(),l.fill()}}u(It,"TYPE","Rule");const Yi={[It.TYPE]:It},Xc=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Yi,Rule:It,ruleStateZ:Es},Symbol.toStringTag,{value:"Module"})),Vc=ze.extend({location:o.J.x.optional().default("left")}),cr=2,Kc=n=>o.Eo.signedWidth(n)<cr||o.Eo.signedHeight(n)<cr;class ge extends Oi{constructor(){super(...arguments);u(this,"schema",ze)}async xBounds(){return o.G.max(await Promise.all(this.lines.map(async t=>await t.xBounds())))}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport),i=s.invert().reverse();if(this.renderAxis(t,i),await this.renderLines(t,s),await this.renderRules(t,i),r!=null)throw r}async renderLines({xDataToDecimalScale:t,plot:s,canvases:r,exposure:i},a){if(!r.includes("gl")||Kc(s))return;const l={region:s,dataToDecimalScale:new o.k$2.XY(t,a),exposure:i};await Promise.all(this.lines.map(async c=>await c.render(l)))}async renderRules({container:t,plot:s,canvases:r},i){if(!r.includes("upper2d"))return;const{location:a}=this.state,{render:l}=this.internal,c=o.Eo.construct(o.Eo.left(t),o.Eo.top(s),o.Eo.width(t),o.Eo.height(s)),h=l.scissor(c,o.q.ZERO,["upper2d"]),f={container:t,plot:s,decimalToDataScale:i,location:a};await Promise.all(this.rules.map(async g=>await g.render(f))),h()}async findByXValue({xDataToDecimalScale:t,plot:s,viewport:r,hold:i,exposure:a},l){const[c,h]=await this.dataToDecimalScale(i,this.dataBounds.bind(this),r);if(h!=null)throw h;const f=new o.k$2.XY(t,c),g={region:s,dataToDecimalScale:f,exposure:a};return(await Promise.all(this.lines.map(async m=>await m.findByXValue(g,l)))).map(m=>({...m,units:this.state.label}))}async dataBounds(){return await Promise.all(this.lines.map(async t=>await t.yBounds()))}get lines(){return this.childrenOfType(pe.TYPE)}get rules(){return this.childrenOfType(It.TYPE)}}u(ge,"TYPE","YAxis");const Di=p.z.object({start:d.m.z,end:d.m.z});class cn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Di)}async afterUpdate(){this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,d.use(this.ctx))}async render(){}}u(cn,"TYPE","range-annotation");const Ai=p.z.object({triggered:p.z.boolean(),status:d.specZ$1,sink:Sn.optional().default(vn),source:es.optional().default(Qn)});class un extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ai)}async afterUpdate(){var r,i,a;const{sink:t,source:s}=this.state;this.internal.source=await X(this.ctx,s,this.internal.source),this.internal.sink=await Ee(this.ctx,t,this.internal.sink),this.state.triggered&&!this.prevState.triggered&&this.internal.sink.set(((r=this.state.status.data)==null?void 0:r.authority)!==d.Kg.Absolute.valueOf()).catch(console.error),await this.updateEnabledState(),(a=(i=this.internal).stopListening)==null||a.call(i),this.internal.stopListening=this.internal.source.onChange(()=>{this.updateEnabledState()})}async updateEnabledState(){const t=await this.internal.source.value();t.time.equals(this.state.status.time)||this.setState(s=>({...s,status:t,triggered:!1}))}async afterDelete(){this.asyncAfterDelete().catch(console.error)}async asyncAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}render(){}}u(un,"TYPE","Chip");const Li=p.z.object({}),ur="control-state-provider",_i=d.Og.stateZ.extend({subjectColor:o.Color.z});class Nt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Li);u(this,"colors",new Map);u(this,"tracker");u(this,"disconnectTrackerChange");u(this,"obs",new Xn.Observer)}static use(t){return t.get(ur)}async afterUpdate(){const{internal:t}=this;t.instrumentation=ke(this.ctx,"control-state");const s=d.use(this.ctx);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l6;const r=Se(this.ctx);t.client!=null&&r===t.client||(t.client=r,this.ctx.set(ur,this),await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client)))}async maybeCloseTracker(){var t;this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),(t=this.disconnectTrackerChange)==null||t.call(this),await this.tracker.close(),this.tracker=void 0)}async afterDelete(){await this.maybeCloseTracker()}onChange(t){return this.obs.onChange(t)}get(t){return Array.isArray(t)?d.n(t).map(s=>this.getOne(s)).filter(s=>s!=null):this.getOne(t)}getOne(t){if(this.tracker==null)return;const s=this.tracker.states.get(t);if(s!=null)return{...s,subjectColor:this.colors.get(s.subject.key)??this.internal.defaultColor}}async openTracker(t){var i;const{internal:s}=this,{instrumentation:r}=s;try{this.tracker=await t.control.openStateTracker()}catch{r.L.error("failed to open state tracker");return}(i=this.disconnectTrackerChange)==null||i.call(this),this.disconnectTrackerChange=this.tracker.onChange(a=>{if(r.L.debug("transfer",{transfers:a.map(l=>d.Og.transferString(l))}),this.tracker==null)throw new d.Ce("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(a)})}updateColors(t){const s=t.subjects(),r=s.map(l=>l.key),i=Array.from(this.colors.values());this.colors.forEach((l,c)=>!r.includes(c)&&this.colors.delete(c));const{palette:a}=this.internal;s.forEach(l=>{if(this.colors.has(l.key))return;const c=a.find(h=>!i.includes(h))??a[0];this.colors.set(l.key,c),i.push(c)})}}u(Nt,"TYPE","StateProvider");const qi=["acquired","released","overridden","failed"],$i=p.z.enum(qi),Ii=p.z.object({name:p.z.string(),authority:p.z.number().default(0),acquireTrigger:p.z.number(),status:$i.optional(),needsControlOf:d.dg.keyZ.array().optional().default([])});class hn extends d.Composite{constructor(){super(...arguments);u(this,"schema",Ii);u(this,"registry",new Map);u(this,"writer")}async afterUpdate(){this.internal.instrumentation=ke(this.ctx),(this.internal.prevTrigger==null||Math.abs(this.state.acquireTrigger-this.internal.prevTrigger)>1)&&(this.internal.prevTrigger=this.state.acquireTrigger);const t=Se(this.ctx),s=Nt.use(this.ctx);this.internal.client=t,this.internal.client==null&&await this.release(),this.internal.stateProv=s,mr(this.ctx,this),this.internal.addStatus=d.useAggregate(this.ctx),this.state.acquireTrigger>this.internal.prevTrigger?(this.acquire(),this.internal.prevTrigger=this.state.acquireTrigger):this.state.acquireTrigger<this.internal.prevTrigger&&(this.release(),this.internal.prevTrigger=this.state.acquireTrigger)}async afterDelete(){await this.release()}async updateNeedsControlOf(){if(this.internal.client==null)throw new d.Ce("No cluster connected but channelKeys were requested");const t=new Set([]);for(const r of this.registry.keys())(await r.needsControlOf(this.internal.client)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);d.F.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==d.F.EQUAL&&this.setState(r=>({...r,needsControlOf:s}))}async acquire(){const{client:t,addStatus:s}=this.internal;if(t==null)return s({message:`Cannot acquire control on ${this.state.name} because no cluster has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const r=this.state.needsControlOf;if(r.length===0)return s({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});this.writer=await t.openWriter({start:d.I.now(),channels:r,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(r){this.setState(i=>({...i,status:"failed"})),s({message:`${this.state.name} failed to acquire control: ${r.message}`,variant:"error"})}}async release(){var t;try{await((t=this.writer)==null?void 0:t.close()),this.setState(s=>({...s,status:"released"}))}catch(s){this.internal.addStatus({message:`${this.state.name} failed to release control: ${s.message}`,variant:"error"})}finally{this.writer=void 0}}async set(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.write(t))}async setAuthority(t,s){var r;this.writer==null&&await this.acquire(),await((r=this.writer)==null?void 0:r.setAuthority(Object.fromEntries(t.map(i=>[i,s]))))}async releaseAuthority(t){var s;this.writer==null&&await this.acquire(),await((s=this.writer)==null?void 0:s.setAuthority(Object.fromEntries(t.map(r=>[r,this.state.authority]))))}deleteTelem(t){this.registry.delete(t),this.updateNeedsControlOf()}create(t){const r=(()=>{switch(t.type){case me.TYPE:{const i=new me(this,t.props);return this.registry.set(i,null),i}case we.TYPE:{const i=new we(this,this.internal.stateProv,t.props);return this.registry.set(i,null),i}case ye.TYPE:return new ye(this,t.props);default:return null}})();return r!=null&&this.updateNeedsControlOf(),r}}u(hn,"TYPE","Controller");const Ni=p.z.object({channel:p.z.number()});class me extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",Ni);this.controller=t}invalidate(){}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){if(this.props.channel===0)return[];const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{client:s}=this.controller.internal;if(s==null)return;const r=await s.channels.retrieve(this.props.channel),i={[r.key]:t};if(r.index!==0){const a=await s.channels.retrieve(r.index);i[a.key]=d.I.now()}await this.controller.set(i)}}u(me,"TYPE","controlled-numeric-telem-sink");const Jc=n=>({type:me.TYPE,props:n,variant:"sink",valueType:"number"}),Zi=p.z.object({authority:p.z.number().default(d.Og.Authority.Absolute.valueOf()),channel:p.z.number()});class ye extends Cn{constructor(t,s){super(s);u(this,"controller");u(this,"schema",Zi);this.controller=t}async cleanup(){this.controller.deleteTelem(this)}async needsControlOf(t){const s=await t.channels.retrieve(this.props.channel),r=[s.key];return s.index!==0&&r.push(s.index),r}async set(t){const{controller:s}=this,{client:r}=s.internal;if(r==null)return;const i=await r.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),t?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)}}u(ye,"TYPE","acquire-channel-control");const Qc=n=>({type:ye.TYPE,props:n,variant:"sink",valueType:"boolean"}),Bi=p.z.object({channel:p.z.number()});class we extends G{constructor(t,s,r){super(r);u(this,"prov");u(this,"valid",!1);u(this,"stopListening");u(this,"controller");u(this,"schema",Bi);this.prov=s,this.controller=t}async needsControlOf(){return[]}maybeRevalidate(){var r;if(this.valid)return;const{channel:t}=this.props;(r=this.stopListening)==null||r.call(this);const s=d.W.filterTransfersByChannelKey(t);this.stopListening=this.prov.onChange(i=>{var a;s(i).length!==0&&((a=this.notify)==null||a.call(this))}),this.valid=!0}async value(){this.maybeRevalidate();const t=d.I.now();if(this.props.channel===0)return{key:this.controller.key,variant:"disabled",message:"No Channel",time:t,data:{valid:!1,authority:0}};const s=this.prov.get(this.props.channel);return s==null?{key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:t,data:{valid:!0,color:void 0,authority:0}}:{key:s.subject.key,variant:s.subject.key===this.controller.key?"success":"error",message:`Controlled by ${s.subject.name}`,time:t,data:{valid:!0,color:s.subjectColor,authority:s.authority}}}async cleanup(){var t;this.controller.deleteTelem(this),(t=this.stopListening)==null||t.call(this)}}u(we,"TYPE","controlled-status-source");const tu=n=>({type:we.TYPE,props:n,variant:"source",valueType:"status"}),Ui=p.z.object({statusSource:es.optional().default(Qn),colorSource:kr.optional().default(br),status:d.specZ$1,color:o.Color.z.optional()});class dn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ui);u(this,"stopListeningStatus");u(this,"stopListeningColor")}async afterUpdate(){var s,r;const{internal:t}=this;t.statusSource=await X(this.ctx,this.state.statusSource,t.statusSource),t.colorSource=await X(this.ctx,this.state.colorSource,t.colorSource),await this.updateState(),(s=this.stopListeningStatus)==null||s.call(this),this.stopListeningStatus=t.statusSource.onChange(()=>{this.updateState()}),(r=this.stopListeningColor)==null||r.call(this),this.stopListeningColor=t.colorSource.onChange(()=>{this.updateState()})}async afterDelete(){this.internalAfterDelete().catch(console.error)}async internalAfterDelete(){var t,s,r,i;await((s=(t=this.internal.statusSource).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.colorSource).cleanup)==null?void 0:i.call(r))}async render(){}async updateState(){const t=await this.internal.colorSource.value(),s=await this.internal.statusSource.value();t.equals(this.state.color)&&s.message===this.state.status.message||this.setState(r=>({...r,color:t,status:s}))}}u(dn,"TYPE","Indicator");const Fi=p.z.object({needsControlOf:d.dg.keyZ.array(),states:_i.array()});class fn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Fi)}async afterUpdate(){var a;const{internal:t}=this;t.stateProv=Nt.use(this.ctx);const s=this.state.needsControlOf;(a=t.disconnectStateProv)==null||a.call(t);const r=d.W.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(l=>({...l,states:i})),t.disconnectStateProv=t.stateProv.onChange(l=>{if(r(l).length===0)return;const c=t.stateProv.get(s);this.setState(h=>({...h,states:c}))})}async afterDelete(){var s;const{internal:t}=this;(s=t.disconnectStateProv)==null||s.call(t)}async render(){}}u(fn,"TYPE","Legend");const eu={[hn.TYPE]:hn,[Nt.TYPE]:Nt,[dn.TYPE]:dn,[un.TYPE]:un,[fn.TYPE]:fn},Gi=p.z.object({trigger:p.z.number(),sink:Sn.optional().default(vn)});class pn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Gi)}async afterUpdate(){var r;const{sink:t}=this.state;(r=this.internal).prevTrigger??(r.prevTrigger=this.state.trigger),this.internal.sink=await Ee(this.ctx,t,this.internal.sink);const s=this.internal.prevTrigger;this.internal.prevTrigger=this.state.trigger,!(this.state.trigger<=s)&&this.internal.sink.set(!0).catch(console.error)}render(){}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var s,r;const{internal:t}=this;await((r=(s=t.sink).cleanup)==null?void 0:r.call(s))}}u(pn,"TYPE","Button");const nu={[pn.TYPE]:pn},Cs=p.z.object({dpr:p.z.number(),region:o.Eo.box,bootstrap:p.z.boolean().optional().default(!1),bootstrapped:p.z.boolean().optional().default(!1),glCanvas:p.z.any().optional(),upper2dCanvas:p.z.any().optional(),lower2dCanvas:p.z.any().optional(),os:d.w.osZ});class xe extends d.Composite{constructor(){super(...arguments);u(this,"schema",Cs);u(this,"renderContextSet",!1)}async afterUpdate(){let t=q.useOptional(this.ctx);if(t==null){if(this.renderContextSet)throw new d.Ce("[vis.worker.Canvas] - expected render context to be set");if(!this.state.bootstrap)return;const{glCanvas:s,lower2dCanvas:r,upper2dCanvas:i,os:a}=this.state;if(s==null||r==null||i==null)throw new d.Ce("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");t=q.create(this.ctx,s,r,i,a),ln.create(this.ctx),this.setState(l=>({...l,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else t.update(this.ctx);t.resize(this.state.region,this.state.dpr)}}u(xe,"TYPE","Canvas");const ji={[xe.TYPE]:xe},su=Object.freeze(Object.defineProperty({__proto__:null,Canvas:xe,REGISTRY:ji,canvasStateZ:Cs},Symbol.toStringTag,{value:"Module"})),Rs=p.z.object({position:o.q.xy,zoom:p.z.number(),region:o.Eo.box,clearOverScan:o.q.crudeZ.optional().default(10),visible:p.z.boolean().optional().default(!0)}),_e=["upper2d","lower2d"],Rt=class Rt extends d.Composite{constructor(){super(...arguments);u(this,"schema",Rt.stateZ)}async afterUpdate(){this.internal.renderCtx=q.use(this.ctx),this.internal.addStatus=d.useAggregate(this.ctx),$.control(this.ctx,()=>this.requestRender("low")),this.requestRender("high")}async afterDelete(){this.requestRender("high")}async render(){if(this.deleted)return;const{renderCtx:t,addStatus:s}=this.internal,{zoom:r,position:i}=this.state,a=o.Eo.construct(this.state.region);if(!this.state.visible)return async()=>t.erase(a,this.state.clearOverScan,..._e);const l=t.scissor(a,o.q.ZERO,_e),c=o.k$2.XY.magnify(o.q.construct(r)).translate(o.Eo.topLeft(a)).translate(i);try{await Promise.all(this.children.map(async f=>await f.render({viewportScale:c})))}catch(f){s({variant:"error",message:f.message})}finally{l()}const h=o.Eo.copy(this.state.region);return async()=>{this.internal.renderCtx.erase(h,this.state.clearOverScan,..._e)}}requestRender(t){const{renderCtx:s}=this.internal;s.loop.set({key:`${Rt.TYPE}-${this.key}`,render:this.render.bind(this),priority:t,canvases:_e})}};u(Rt,"TYPE","Diagram"),u(Rt,"stateZ",Rs);let Zt=Rt;const Hi={[Zt.TYPE]:Zt},ru=Object.freeze(Object.defineProperty({__proto__:null,Diagram:Zt,REGISTRY:Hi,diagramStateZ:Rs},Symbol.toStringTag,{value:"Module"})),Wi=p.z.object({region:o.Eo.box,enabled:p.z.boolean().optional().default(!1)});class gn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Wi);u(this,"eraser",new Ri)}async afterUpdate(){this.deleted||(this.internal.render=q.use(this.ctx),await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]}))}async afterDelete(){await this.internal.render.loop.set({key:`${this.type}-${this.key}`,render:this.render.bind(this),priority:"high",canvases:["gl","lower2d","upper2d"]})}async render(){this.deleted||!this.state.enabled||this.internal.render.erase(this.state.region,o.q.construct(0),"gl","lower2d","upper2d")}}u(gn,"TYPE","eraser");const iu={[gn.TYPE]:gn},Xi=p.z.object({enabled:p.z.boolean(),source:ts.optional().default(Jn)});class mn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Xi)}async afterUpdate(){var r;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{source:t}=this.state,{internal:s}=this;this.internal.source=await X(this.ctx,t,this.internal.source),await this.updateEnabledState(),(r=s.stopListening)==null||r.call(s),s.stopListening=s.source.onChange(()=>this.updateEnabledState().catch(this.reportError.bind(this)))}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Light: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t))}async render(){}}u(mn,"TYPE","Light");const au={[mn.TYPE]:mn},ks=p.z.object({position:o.q.xy.or(p.z.null()),textColor:o.Color.z.optional().default(o.ZERO),backgroundColor:o.Color.z.optional().default(o.ZERO),borderColor:o.Color.z.optional().default(o.ZERO),ruleColor:o.Color.z.optional().default(o.ZERO),ruleStrokeWidth:p.z.number().optional().default(1),ruleStrokeDash:p.z.number().default(0)});class Bt extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ks)}async afterUpdate(){const t=d.use(this.ctx);this.state.textColor.isZero&&(this.state.textColor=t.colors.text),this.state.backgroundColor.isZero&&(this.state.backgroundColor=t.colors.gray.l1),this.state.borderColor.isZero&&(this.state.borderColor=t.colors.border),this.state.ruleColor.isZero&&(this.state.ruleColor=t.colors.gray.l5),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=q.use(this.ctx),this.internal.draw=new Gt(this.internal.render.upper2d,t),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,it)}async render(t){if(this.deleted||this.state.position==null)return;const{region:s}=t,r=o.k$2.XY.scale(o.Eo.DECIMAL).scale(s),i=o.k$2.XY.scale(s).scale(o.Eo.DECIMAL),a=await t.findByXDecimal(i.x.pos(this.state.position.x)),l=a.filter(b=>o.q.isFinite(b.value)),{draw:c}=this.internal,h=l.reduce((b,T)=>b+T.position.x,0)/l.length,f=new d.m(l.reduce((b,T)=>b+T.value.x,0)/l.length),g=r.x.pos(h);if(!o.G.contains(o.Eo.xBounds(s),g))return;c.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:s,position:g}),l.forEach(b=>{const T=r.pos(b.position);c.circle({fill:b.color.setAlpha(.5),radius:8,position:T}),c.circle({fill:b.color.setAlpha(.8),radius:5,position:T}),c.circle({fill:b.color.pickByContrast(this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:T})});const m=a.map(b=>`${b.label??""}: ${b.value.y.toFixed(2)}`);m.unshift(`Time: ${f.fString("preciseDate","local")}`);const x=i.pos(this.state.position);c.textContainer({text:m,backgroundColor:this.state.backgroundColor,borderColor:this.state.borderColor,position:this.state.position,direction:"y",level:"small",spacing:.5,offset:{x:12,y:12},root:{x:x.x>.8?"right":"left",y:x.y>.8?"top":"bottom"}})}}u(Bt,"TYPE","tooltip");const Vi={[Bt.TYPE]:Bt},ou=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Vi,Tooltip:Bt,tooltipStateZ:ks},Symbol.toStringTag,{value:"Module"})),Ki=p.z.object({region:o.Eo.box,wheelPos:p.z.number(),scrolling:p.z.boolean(),empty:p.z.boolean(),visible:p.z.boolean(),telem:Xe.optional().default(vr),font:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),overshoot:o.q.xy.optional().default({x:0,y:0})}),lu=.98,Xt="lower2d",cu={offset:0n,offsetRef:0n,scrollRef:0},ee=class ee extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ee.z);u(this,"values",new d.Ct([]));u(this,"scrollState",cu)}async afterUpdate(){var c;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem);const{scrolling:s,wheelPos:r}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const h=this.values.alignmentBounds.upper-1n;this.scrollState={offset:h,offsetRef:h,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:h,values:f}=this,g=Math.ceil((r-this.scrollState.scrollRef)/this.lineHeight);h.offset=this.values.traverseAlignment(h.offsetRef,-BigInt(g)),h.offset<f.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(h.offset=f.alignmentBounds.lower,this.setState(m=>({...m,wheelPos:this.prevState.wheelPos}))),h.offset>=f.alignmentBounds.upper&&this.setState(m=>({...m,scrolling:!1}))}const[a,l]=await this.internal.telem.value();this.values=new d.Ct(l),this.checkEmpty(),(c=t.stopListeningTelem)==null||c.call(t),t.stopListeningTelem=t.telem.onChange(()=>this.internal.telem.value().then(([h,f])=>{this.checkEmpty(),this.values=new d.Ct(f),this.requestRender()})),this.requestRender()}checkEmpty(){const t=this.values.length===0;t!==this.state.empty&&this.setState(s=>({...s,empty:t}))}async afterDelete(){var r;const{telem:t,render:s}=this.internal;await((r=t.cleanup)==null?void 0:r.call(t)),s.erase(o.Eo.construct(this.state.region),o.q.ZERO,Xt)}requestRender(){const{render:t}=this.internal;t.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(),priority:"high",canvases:[Xt]})}get lineHeight(){return this.internal.theme.typography[this.state.font].size*this.internal.theme.sizes.base}get totalHeight(){return Math.ceil(this.values.length*this.lineHeight)}get visibleLineCount(){return Math.min(Math.floor((o.Eo.height(this.state.region)-12)/this.lineHeight),this.values.length)}async render(){const{render:t}=this.internal,s=this.state.region;if(o.Eo.areaIsZero(s))return;if(!this.state.visible)return async()=>t.erase(s,o.q.ZERO,Xt);let r;if(!this.state.scrolling)r=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const f=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));r=this.values.subAlignmentSpanIterator(f,this.visibleLineCount)}const i=this.state.region,a=t[Xt],l=new Gt(a,this.internal.theme),c=t.scissor(i,o.q.ZERO,[Xt]);this.renderElements(l,r),this.renderScrollbar(l),c();const h=o.Eo.copy(this.state.region);return async({canvases:f})=>t.erase(h,this.state.overshoot,...f)}renderScrollbar(t){const s=this.state.region,r=o.Eo.height(s)/this.totalHeight*o.Eo.height(s);if(r>=o.Eo.height(s)*lu)return;let i=o.Eo.bottom(s)-r;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*o.Eo.height(s)),i<0&&(i=o.Eo.top(s)),t.container({region:o.Eo.construct({x:o.Eo.right(s)-6,y:i},{width:6,height:r}),bordered:!1,backgroundColor:a=>a.colors.gray.l4})}renderElements(t,s){const r=this.state.region;let i=0;for(const a of s){const l=this.values.dataType.equals(d.g.JSON)?JSON.stringify(a):a.toString();t.text({text:l,level:this.state.font,shade:9,position:o.q.translate(o.Eo.topLeft(r),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}};u(ee,"TYPE","log"),u(ee,"z",Ki);let be=ee;const uu={[be.TYPE]:be},Ps=p.z.object({one:o.q.xy.nullable(),two:o.q.xy.nullable(),hover:o.q.xy.nullable(),color:p.z.union([o.Color.z,p.z.object({verticalLine:o.Color.z.optional().default(o.ZERO),horizontalLine:o.Color.z.optional().default(o.ZERO),obliqueLine:o.Color.z.optional().default(o.ZERO)})]).optional().default(o.ZERO),strokeWidth:p.z.number().optional().default(1),strokeDash:p.z.number().optional().default(2)});class Ut extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Ps)}async afterUpdate(){const t=q.use(this.ctx);this.internal.theme=d.use(this.ctx),this.internal.render=t,this.internal.draw=new Gt(t.upper2d,this.internal.theme),$.requestRender(this.ctx,it)}async afterDelete(){$.requestRender(this.ctx,Q)}get verticalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.verticalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.verticalLine}get horizontalLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.horizontalLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.horizontalLine}get obliqueLineColor(){return this.state.color instanceof o.Color?this.state.color.isZero?this.internal.theme.colors.gray.l6:this.state.color:this.state.color.obliqueLine.isZero?this.internal.theme.colors.gray.l6:this.state.color.obliqueLine}async find(t){const{one:s,two:r}=this.state;if(s==null||r==null)return null;const{one:i,two:a}=this.prevState,{dataOne:l,dataTwo:c}=this.internal;if(i!=null&&o.q.equals(s,i)&&a!=null&&o.q.equals(r,a)&&l!=null&&c!=null){const[C,O]=[await t.findByXValue(l.x),await t.findByXValue(c.x)];return C.length===0||O.length===0?null:[C.sort((A,P)=>o.q.distance(l,A.value)-o.q.distance(l,P.value))[0],O.sort((A,P)=>o.q.distance(c,A.value)-o.q.distance(c,P.value))[0]]}const h=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),[f,g]=[h.pos(s),h.pos(r)],[m,x]=[await t.findByXDecimal(f.x),await t.findByXDecimal(g.x)];if(m.length===0||x.length===0)return null;const[b,T]=[m.sort((C,O)=>o.q.distance(f,C.position)-o.q.distance(f,O.position))[0],x.sort((C,O)=>o.q.distance(g,C.position)-o.q.distance(g,O.position))[0]];return this.internal.dataOne=b.value,this.internal.dataTwo=T.value,[b,T]}async renderHover(t){if(this.state.hover==null)return;const s=this.state.hover,r=o.k$2.XY.scale(t.region).scale(o.Eo.DECIMAL),i=r.pos(s),a=await t.findByXDecimal(r.pos(s).x);if(a.length===0)return;const l=a.sort((h,f)=>o.q.distance(i,h.position)-o.q.distance(i,f.position))[0],{draw:c}=this.internal;c.circle({fill:l.color.setAlpha(.5),radius:9,position:r.reverse().pos(l.position)})}async render(t){if(this.deleted)return;await this.renderHover(t);const s=await this.find(t);if(s==null)return;const[r,i]=s,{draw:a}=this.internal,{strokeDash:l,strokeWidth:c}=this.state,h=o.k$2.XY.scale(o.Eo.DECIMAL).scale(t.region),f=h.pos(r.position),g=h.pos(i.position),m=new d.y(Math.abs(r.value.x-i.value.x)),x=Math.abs(r.value.y-i.value.y),b=x/m.seconds;a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(f.x,g.y),stroke:this.verticalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${x.toFixed(2)} ${r.units??""}`],direction:"x",position:o.q.construct(f.x,(f.y+g.y)/2),level:"small"}),a.line({start:o.q.construct(f.x,g.y),end:o.q.construct(g.x,g.y),stroke:this.horizontalLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[m.truncate(d.y.MILLISECOND).toString()],direction:"x",position:o.q.construct((f.x+g.x)/2,g.y),level:"small"}),a.line({start:o.q.construct(f.x,f.y),end:o.q.construct(g.x,g.y),stroke:this.obliqueLineColor,lineDash:l,lineWidth:c}),a.textContainer({text:[`${b.toFixed(2)} ${r.units??""} / S`],direction:"x",position:o.q.construct((f.x+g.x)/2,(f.y+g.y)/2),level:"small"}),a.circle({fill:r.color.setAlpha(.5),radius:8,position:f}),a.circle({fill:r.color.setAlpha(.8),radius:5,position:f}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:f}),a.circle({fill:i.color.setAlpha(.5),radius:8,position:g}),a.circle({fill:i.color.setAlpha(.8),radius:5,position:g}),a.circle({fill:new o.Color("#ffffff"),radius:2,position:g})}}u(Ut,"TYPE","measure");const Ji={[Ut.TYPE]:Ut},hu=Object.freeze(Object.defineProperty({__proto__:null,Measure:Ut,REGISTRY:Ji,measureStateZ:Ps},Symbol.toStringTag,{value:"Module"})),Qi=p.z.object({trigger:p.z.number(),command:p.z.number().optional(),value:p.z.number(),sink:Rr.optional().default(yr),source:Cr.optional().default(wr)});class yn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",Qi)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,trigger:r,command:i}=this.state,{trigger:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r!==a&&i!=null&&this.internal.sink.set(i),await this.updateValue(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateValue().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Setpoint: ${t.message}`})}async updateValue(){const t=await this.internal.source.value();t!==this.state.value&&this.setState(s=>({...s,value:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(yn,"TYPE","Setpoint");const du={[yn.TYPE]:yn},ta=p.z.object({triggered:p.z.boolean(),enabled:p.z.boolean(),sink:Sn.optional().default(vn),source:ts.optional().default(Jn)});class wn extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ta)}async afterUpdate(){var c;this.internal.addStatus=d.useOptionalAggregate(this.ctx);const{sink:t,source:s,triggered:r,enabled:i}=this.state,{triggered:a}=this.prevState,{internal:l}=this;this.internal.source=await X(this.ctx,s,this.internal.source),l.sink=await Ee(this.ctx,t,l.sink),r&&!a&&await l.sink.set(!i),await this.updateEnabledState(),(c=l.stopListening)==null||c.call(l),l.stopListening=l.source.onChange(()=>{this.updateEnabledState().catch(this.reportError.bind(this))})}reportError(t){this.internal.addStatus({key:this.key,variant:"error",message:`Failed to update Toggle: ${t.message}`})}async updateEnabledState(){const t=await this.internal.source.value();t!==this.state.enabled&&this.setState(s=>({...s,enabled:t,triggered:!1}))}async afterDelete(){await this.internalAfterDelete()}async internalAfterDelete(){var t,s,r,i;this.internal.stopListening(),await((s=(t=this.internal.source).cleanup)==null?void 0:s.call(t)),await((i=(r=this.internal.sink).cleanup)==null?void 0:i.call(r))}async render(){}}u(wn,"TYPE","Toggle");const fu={[wn.TYPE]:wn},pu=p.z.object({box:o.Eo.box,telem:Pr.optional().default(xr),level:d.levelZ.optional().default("p"),color:o.Color.z.optional().default(o.ZERO),precision:p.z.number().optional().default(2),minWidth:p.z.number().optional().default(60),width:p.z.number().optional(),notation:Ur.optional().default("standard")}),hr="upper2d",ne=class ne extends d.Leaf{constructor(){super(...arguments);u(this,"schema",ne.z)}async afterUpdate(){var s;const{internal:t}=this;t.render=q.use(this.ctx),t.theme=d.use(this.ctx),this.state.color.isZero?this.internal.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=await X(this.ctx,this.state.telem,t.telem),(s=t.stopListening)==null||s.call(t),t.stopListening=this.internal.telem.onChange(()=>this.requestRender()),this.internal.requestRender=$.useOptionalRequest(this.ctx),this.requestRender()}async afterDelete(){var i;const{requestRender:t,telem:s,render:r}=this.internal;await((i=s.cleanup)==null?void 0:i.call(s)),t==null?r.erase(o.Eo.construct(this.state.box),o.q.ZERO,hr):t(Q)}requestRender(){const{requestRender:t}=this.internal;t!=null?t(Q):this.render({})}get fontHeight(){const{theme:t}=this.internal;return t.typography[this.state.level].size*t.sizes.base}maybeUpdateWidth(t){const{theme:s}=this.internal,r=t+s.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<r||this.state.minWidth>r&&this.state.width!==this.state.minWidth?this.setState(i=>({...i,width:Math.max(r,i.minWidth)})):this.state.width-this.fontHeight>r&&this.setState(i=>({...i,width:Math.max(r,i.minWidth)}))}async render({viewportScale:t=o.k$2.XY.IDENTITY}){const{render:s,telem:r}=this.internal,i=o.Eo.construct(this.state.box);if(o.Eo.areaIsZero(i))return;const a=s[hr].applyScale(t);let l=await r.value();const c=d.fontString(this.internal.theme,{level:this.state.level,code:!0});a.font=c;const h=this.fontHeight,f=l[0]=="-";f&&(l=l.slice(1));const{theme:g}=this.internal,m=d.dimensions(l,c,a).width+g.sizes.base;this.internal.requestRender==null&&s.erase(o.Eo.construct(this.prevState.box)),this.maybeUpdateWidth(m);const x=o.q.translate(o.Eo.topLeft(i),{x:6+h*.75,y:o.Eo.height(i)/2});a.textBaseline="middle",a.fillStyle=this.internal.textColor.hex,f&&a.fillText("-",...o.q.couple(o.q.translateX(x,-h*.6))),a.fillText(l,...o.q.couple(x))}};u(ne,"TYPE","value"),u(ne,"z",pu);let Ft=ne;const ea={[Ft.TYPE]:Ft},gu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ea,Value:Ft},Symbol.toStringTag,{value:"Module"})),mu=d.Bg.payloadZ.extend({viewport:o.G.bounds}),dr=n=>o.Color.z.safeParse(n).success,na=p.z.object({cursor:o.q.xy.or(p.z.null()),hovered:mu.or(p.z.null()),count:p.z.number()});class ve extends d.Leaf{constructor(){super(...arguments);u(this,"schema",na);u(this,"fetchedInitial",d.E.ZERO)}async afterUpdate(){const{internal:t}=this;t.render=q.use(this.ctx),t.draw=new Gt(t.render.upper2d,d.use(this.ctx)),t.ranges??(t.ranges=new Map);const s=Se(this.ctx);s!=null&&(t.client=s,t.tracker==null&&(t.tracker=await t.client.ranges.openTracker(),t.tracker.onChange(async r=>{r.forEach(async i=>{i.variant==="delete"?t.ranges.delete(i.key):dr(i.value.color)&&t.ranges.set(i.key,i.value)}),$.requestRender(this.ctx,it),this.setState(i=>({...i,count:t.ranges.size}))}),$.requestRender(this.ctx,it)))}async fetchInitial(t){const{internal:s}=this;if(s.client==null||this.fetchedInitial.roughlyEquals(t,d.y.minutes(1)))return;this.fetchedInitial=t,(await s.client.ranges.retrieve(t)).forEach(i=>{dr(i.color)&&s.ranges.set(i.key,i)}),this.setState(i=>({...i,count:s.ranges.size}))}async render(t){const{dataToDecimalScale:s,region:r,viewport:i,timeRange:a}=t;await this.fetchInitial(a);const{draw:l,ranges:c}=this.internal,h=s.scale(o.Eo.xBounds(r)),f=this.state.cursor==null?null:this.state.cursor.x;let g=null;const m=l.canvas.scissor(o.Eo.construct({x:o.Eo.left(r),y:o.Eo.top(r)-35},{x:o.Eo.right(r),y:o.Eo.bottom(r)}));c.forEach(x=>{const b=o.Color.z.safeParse(x.color);if(!b.success)return;const T=b.data;let C=h.pos(Number(x.timeRange.start.valueOf()));const O=h.pos(Number(x.timeRange.end.valueOf()));if(O<o.Eo.left(r)||C>o.Eo.right(r))return;C=o.j(C,o.Eo.left(r)-2,o.Eo.right(r)-1);let A=!1;f!=null&&(A=o.G.contains({lower:C,upper:O},f)),A&&(g={key:x.key,name:x.name,color:x.color,timeRange:x.timeRange,viewport:{lower:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.start.valueOf())),upper:s.scale(o.Eo.xBounds(i)).pos(Number(x.timeRange.end.valueOf()))}}),l.container({region:o.Eo.construct({x:C,y:o.Eo.top(r)-1},{x:O,y:o.Eo.bottom(r)-1}),backgroundColor:T.setAlpha(.2),bordered:!1});const P=o.Eo.construct({x:C+1,y:o.Eo.top(r)-34},{x:O-1,y:o.Eo.top(r)-12});l.container({region:P,backgroundColor:o.Eo.width(P)<20?T.setAlpha(.4):Y=>A?Y.colors.gray.l2:Y.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:T.setAlpha(.8)}),l.text({text:x.name,position:{x:C+8,y:o.Eo.top(r)-30},level:"small",shade:8,weight:500,maxWidth:O-C-16})}),m(),g!=null?this.setState(x=>({...x,hovered:g})):this.state.hovered&&this.setState(x=>({...x,hovered:null}))}}u(ve,"TYPE","range-provider");const yu={[cn.TYPE]:cn,[ve.TYPE]:ve},wu=ze;class Te extends Oi{constructor(){super(...arguments);u(this,"schema",ze)}async render(t){if(this.deleted)return;const[s,r]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(this.renderAxis(t,s.reverse()),await this.renderYAxes(t,s),await this.renderRangeAnnotations(t,s),r!=null)throw r}async findByXDecimal(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;return await this.findByXValue(t,r.reverse().pos(s))}async findByXValue(t,s){const[r,i]=await this.dataToDecimalScale(t.hold,this.dataBounds.bind(this),t.viewport);if(i!=null)throw i;const a={...t,xDataToDecimalScale:r},l=this.yAxes.map(async c=>await c.findByXValue(a,s));return(await Promise.all(l)).flat()}async renderYAxes(t,s){const r={...t,xDataToDecimalScale:s};await Promise.all(this.yAxes.map(async i=>await i.render(r)))}get yAxes(){return this.childrenOfType(ge.TYPE)}get rangeAnnotations(){return this.childrenOfType(ve.TYPE)}async renderRangeAnnotations(t,s){const[r,i]=await this.bounds(t.hold,this.dataBounds.bind(this));if(i!=null)throw i;await Promise.all(this.rangeAnnotations.map(async a=>await a.render({dataToDecimalScale:s,region:t.plot,viewport:t.viewport,timeRange:new d.E(r.lower,r.upper)})))}async dataBounds(){return await Promise.all(this.yAxes.map(async t=>await t.xBounds()))}}u(Te,"TYPE","XAxis");const sa=p.z.object({container:o.Eo.box,viewport:o.Eo.box,hold:p.z.boolean().optional().default(!1),grid:p.z.record(ri),visible:p.z.boolean().optional().default(!0),clearOverScan:o.q.crudeZ.optional().default(o.q.ZERO)}),xu=(n,e)=>{const t=o.Eo.width(n)*Math.sqrt(o.Eo.height(n)),s=o.Eo.width(e)*Math.sqrt(o.Eo.height(e));return t/s};class xn extends d.Composite{constructor(){super(...arguments);u(this,"schema",sa)}async afterUpdate(){this.internal.instrumentation=ke(this.ctx,"lineplot"),this.internal.aggregate=d.useAggregate(this.ctx),this.internal.renderCtx=q.use(this.ctx),$.control(this.ctx,t=>this.requestRender("low",t)),this.requestRender("high",Q)}async afterDelete(){this.internal.renderCtx=q.use(this.ctx),this.requestRender("high",Q)}async findByXDecimal(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXDecimal(s,t));return(await Promise.all(r)).flat()}async findByXValue(t){const s={...this.state,plot:this.calculatePlot(),exposure:this.exposure},r=this.axes.flatMap(async i=>await i.findByXValue(s,t));return(await Promise.all(r)).flat()}get axes(){return this.childrenOfType(Te.TYPE)}get tooltips(){return this.childrenOfType(Bt.TYPE)}get measures(){return this.childrenOfType(Ut.TYPE)}get exposure(){return xu(this.state.viewport,this.state.container)}async renderAxes(t,s){const r={...this.state,plot:t,canvases:s,exposure:this.exposure};await Promise.all(this.axes.map(async i=>await i.render(r)))}async renderTooltips(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),region:t,canvases:s};await Promise.all(this.tooltips.map(async i=>await i.render(r)))}async renderMeasures(t,s){const r={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:t,canvases:s};await Promise.all(this.measures.map(async i=>await i.render(r)))}calculatePlot(){return eo(this.state.grid,this.state.container)}async render(t){const{renderCtx:s}=this.internal,{instrumentation:r}=this.internal;if(this.deleted){r.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return r.L.debug("not visible, skipping render",{key:this.key}),async({canvases:f})=>s.erase(this.state.container,this.state.clearOverScan,...f);const i=this.calculatePlot();r.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:t});const a=o.q.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,t.filter(f=>f!=="gl")),c=s.scissor(i,o.q.ZERO,t.filter(f=>f==="gl"));try{await this.renderAxes(i,t),await this.renderTooltips(i,t),await this.renderMeasures(i,t),s.gl.finish(),s.gl.flush(),s.gl.finish()}catch(f){if(f.message.toLowerCase().includes("bigint"))return;this.internal.aggregate({key:`${this.type}-${this.key}`,variant:"error",message:f.message})}finally{l(),c()}r.L.debug("rendered",{key:this.key});const h=o.Eo.copy(this.state.container);return async({canvases:f})=>s.erase(h,this.state.clearOverScan,...f)}requestRender(t,s){const{renderCtx:r}=this.internal;let i=["upper2d","lower2d","gl"];s===it&&(i=["upper2d"]),r.loop.set({key:`${this.type}-${this.key}`,render:async()=>await this.render(i),priority:t,canvases:i})}}u(xn,"TYPE","LinePlot");const bu={[xn.TYPE]:xn,[Te.TYPE]:Te,[ge.TYPE]:ge};exports.AcquireChannelControl=ye;exports.Annotation=cn;exports.AuthoritySource=we;exports.BaseProvider=At;exports.Button=pn;exports.Canvas=Ei;exports.Canvas$1=xe;exports.Chip=un;exports.Context=q;exports.Controller=$;exports.Controller$1=hn;exports.Diagram=ru;exports.Diagram$1=Zt;exports.Eraser=Ri;exports.Eraser$1=gn;exports.GLProgram=Ss;exports.Indicator=dn;exports.Legend=fn;exports.Light=mn;exports.Line=pe;exports.LinePlot=xn;exports.Log=be;exports.Loop=Ci;exports.Measure=Ut;exports.Provider=Ne;exports.Provider$1=ve;exports.Provider$2=Nn;exports.REASON_DATA=Wn;exports.REASON_LAYOUT=Q;exports.REASON_TOOL=it;exports.REGISTRY=$a;exports.REGISTRY$1=nu;exports.REGISTRY$10=yu;exports.REGISTRY$11=Yi;exports.REGISTRY$12=du;exports.REGISTRY$13=fr;exports.REGISTRY$14=si;exports.REGISTRY$15=fu;exports.REGISTRY$16=Vi;exports.REGISTRY$17=ea;exports.REGISTRY$18=uu;exports.REGISTRY$2=ji;exports.REGISTRY$3=eu;exports.REGISTRY$4=Hi;exports.REGISTRY$5=iu;exports.REGISTRY$6=au;exports.REGISTRY$7=Gc;exports.REGISTRY$8=bu;exports.REGISTRY$9=Ji;exports.Rule=It;exports.STATUSES=qi;exports.SetChannelValue=me;exports.Setpoint=yn;exports.StateProvider=Nt;exports.Toggle=wn;exports.Tooltip=Bt;exports.Value=Ft;exports.XAxis=Te;exports.YAxis=ge;exports.ZERO_CONTEXT_VALUE=Vn;exports.acquireChannelControl=Qc;exports.acquireChannelControlPropsZ=Zi;exports.aether=Xc;exports.annotationStateZ=Di;exports.authoritySource=tu;exports.authoritySourceProps=Bi;exports.axisStateZ=Ts;exports.buttonStateZ=Gi;exports.canvas=su;exports.canvasStateZ=Cs;exports.channelData=_r;exports.chipStateZ=Ai;exports.color=Lt;exports.controllerStateZ=Ii;exports.coreAxisStateZ=ze;exports.diagramStateZ=Rs;exports.eraserStateZ=Wi;exports.external=Qa;exports.indicatorStateZ=Ui;exports.interpolateNumber=fe;exports.interpolateRgb=Fn;exports.interpolateString=ci;exports.legendStateZ=Fi;exports.lightStateZ=Xi;exports.linePlotStateZ=sa;exports.logState=Ki;exports.measure=hu;exports.measureStateZ=Ps;exports.newTickFactory=Hn;exports.parseAutoBounds=zi;exports.provider=ba;exports.providerStateZ=na;exports.providerStateZ$1=Qr;exports.providerStateZ$2=cs;exports.regions=dt;exports.rollingAverage=Vr;exports.rollingAverageProps=ls;exports.ruleStateZ=Es;exports.setChannelValue=Jc;exports.setChannelValuePropsZ=Ni;exports.setpoint=Gr;exports.setpointStateZ=Qi;exports.sinkPipeline=Ar;exports.sinkPipelinePropsZ=ss;exports.sourcePipeline=Dr;exports.sourcePipelinePropsZ=ns;exports.stateProviderStateZ=Li;exports.stateZ=Mi;exports.statusZ=$i;exports.streamChannelData=qr;exports.streamChannelValue=$r;exports.streamChannelValuePropsZ=rs;exports.stringifyNumber=Xr;exports.stringifyNumberProps=os;exports.sugaredStateZ=_i;exports.tickFactoryProps=vs;exports.tickType=bs;exports.toggleStateZ=ta;exports.tooltip=ou;exports.tooltipStateZ=ks;exports.value=gu;exports.withinBounds=jr;exports.withinSizeThreshold=ki;exports.xAxisStateZ=wu;exports.yAxisStateZ=Vc;
|